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
|
|---|---|---|---|---|---|---|---|---|
r39132/airflow
|
tests/utils/test_timezone.py
|
4
|
3023
|
# -*- coding: utf-8 -*-
#
# 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 datetime
import pendulum
import unittest
from airflow.utils import timezone
CET = pendulum.timezone("Europe/Paris")
EAT = pendulum.timezone('Africa/Nairobi') # Africa/Nairobi
ICT = pendulum.timezone('Asia/Bangkok') # Asia/Bangkok
UTC = timezone.utc
class TimezoneTest(unittest.TestCase):
def test_is_aware(self):
self.assertTrue(timezone.is_localized(datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT)))
self.assertFalse(timezone.is_localized(datetime.datetime(2011, 9, 1, 13, 20, 30)))
def test_is_naive(self):
self.assertFalse(timezone.is_naive(datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT)))
self.assertTrue(timezone.is_naive(datetime.datetime(2011, 9, 1, 13, 20, 30)))
def test_utcnow(self):
now = timezone.utcnow()
self.assertTrue(timezone.is_localized(now))
self.assertEqual(now.replace(tzinfo=None), now.astimezone(UTC).replace(tzinfo=None))
def test_convert_to_utc(self):
naive = datetime.datetime(2011, 9, 1, 13, 20, 30)
utc = datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=UTC)
self.assertEqual(utc, timezone.convert_to_utc(naive))
eat = datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT)
utc = datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC)
self.assertEqual(utc, timezone.convert_to_utc(eat))
def test_make_naive(self):
self.assertEqual(
timezone.make_naive(datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT), EAT),
datetime.datetime(2011, 9, 1, 13, 20, 30))
self.assertEqual(
timezone.make_naive(datetime.datetime(2011, 9, 1, 17, 20, 30, tzinfo=ICT), EAT),
datetime.datetime(2011, 9, 1, 13, 20, 30))
with self.assertRaises(ValueError):
timezone.make_naive(datetime.datetime(2011, 9, 1, 13, 20, 30), EAT)
def test_make_aware(self):
self.assertEqual(
timezone.make_aware(datetime.datetime(2011, 9, 1, 13, 20, 30), EAT),
datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT))
with self.assertRaises(ValueError):
timezone.make_aware(datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT), EAT)
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
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,
646,
2197,
199,
646,
299,
500,
348,
453,
199,
646,
2882,
199,
199,
504,
16321,
14,
1208,
492,
7137,
199,
199,
35,
775,
275,
299,
500,
348,
453,
14,
7145,
480,
15201,
15,
1262,
374,
531,
199,
37,
619,
275,
299,
500,
348,
453,
14,
7145,
360,
19289,
15,
46,
5789,
293,
4492,
358,
221,
327,
437,
70,
7127,
15,
46,
5789,
293,
4492,
199,
6196,
275,
299,
500,
348,
453,
14,
7145,
360,
13878,
15,
34,
621,
75,
745,
358,
221,
327,
437,
10971,
15,
34,
621,
75,
745,
199,
11288,
275,
7137,
14,
5834,
421,
199,
533,
4703,
2619,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
374,
63,
14600,
8,
277,
304,
267,
291,
14,
1815,
8,
7145,
14,
374,
63,
22729,
8,
2083,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
12,
10313,
29,
37,
619,
1724,
267,
291,
14,
3334,
8,
7145,
14,
374,
63,
22729,
8,
2083,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
1724,
339,
347,
511,
63,
374,
63,
21578,
8,
277,
304,
267,
291,
14,
3334,
8,
7145,
14,
374,
63,
21578,
8,
2083,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
12,
10313,
29,
37,
619,
1724,
267,
291,
14,
1815,
8,
7145,
14,
374,
63,
21578,
8,
2083,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
1724,
339,
347,
511,
63,
10779,
8,
277,
304,
267,
3063,
275,
7137,
14,
10779,
342,
267,
291,
14,
1815,
8,
7145,
14,
374,
63,
22729,
8,
2131,
430,
267,
291,
14,
629,
8,
2131,
14,
1814,
8,
9374,
29,
403,
395,
3063,
14,
29648,
8,
11288,
680,
1814,
8,
9374,
29,
403,
430,
339,
347,
511,
63,
3916,
63,
475,
63,
5834,
8,
277,
304,
267,
19995,
275,
2197,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
9,
267,
19314,
275,
2197,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
12,
10313,
29,
11288,
9,
267,
291,
14,
629,
8,
5834,
12,
7137,
14,
3916,
63,
475,
63,
5834,
8,
21578,
430,
398,
325,
292,
275,
2197,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
12,
10313,
29,
37,
619,
9,
267,
19314,
275,
2197,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
1616,
12,
3388,
12,
4233,
12,
10313,
29,
11288,
9,
267,
291,
14,
629,
8,
5834,
12,
7137,
14,
3916,
63,
475,
63,
5834,
8,
69,
292,
430,
339,
347,
511,
63,
1875,
63,
21578,
8,
277,
304,
267,
291,
14,
629,
8,
288,
7137,
14,
1875,
63,
21578,
8,
2083,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
12,
10313,
29,
37,
619,
395,
662,
619,
395,
288,
2197,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
430,
267,
291,
14,
629,
8,
288,
7137,
14,
1875,
63,
21578,
8,
2083,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
5557,
12,
3388,
12,
4233,
12,
10313,
29,
6196,
395,
662,
619,
395,
288,
2197,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
430,
398,
543,
291,
14,
1855,
8,
3393,
304,
288,
7137,
14,
1875,
63,
21578,
8,
2083,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
395,
662,
619,
9,
339,
347,
511,
63,
1875,
63,
14600,
8,
277,
304,
267,
291,
14,
629,
8,
288,
7137,
14,
1875,
63,
14600,
8,
2083,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
395,
662,
619,
395,
288,
2197,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
12,
10313,
29,
37,
619,
430,
267,
543,
291,
14,
1855,
8,
3393,
304,
288,
7137,
14,
1875,
63,
14600,
8,
2083,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
12,
10313,
29,
37,
619,
395,
662,
619,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
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,
646,
2197,
199,
646,
299,
500,
348,
453,
199,
646,
2882,
199,
199,
504,
16321,
14,
1208,
492,
7137,
199,
199,
35,
775,
275,
299,
500,
348,
453,
14,
7145,
480,
15201,
15,
1262,
374,
531,
199,
37,
619,
275,
299,
500,
348,
453,
14,
7145,
360,
19289,
15,
46,
5789,
293,
4492,
358,
221,
327,
437,
70,
7127,
15,
46,
5789,
293,
4492,
199,
6196,
275,
299,
500,
348,
453,
14,
7145,
360,
13878,
15,
34,
621,
75,
745,
358,
221,
327,
437,
10971,
15,
34,
621,
75,
745,
199,
11288,
275,
7137,
14,
5834,
421,
199,
533,
4703,
2619,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
374,
63,
14600,
8,
277,
304,
267,
291,
14,
1815,
8,
7145,
14,
374,
63,
22729,
8,
2083,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
12,
10313,
29,
37,
619,
1724,
267,
291,
14,
3334,
8,
7145,
14,
374,
63,
22729,
8,
2083,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
1724,
339,
347,
511,
63,
374,
63,
21578,
8,
277,
304,
267,
291,
14,
3334,
8,
7145,
14,
374,
63,
21578,
8,
2083,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
12,
10313,
29,
37,
619,
1724,
267,
291,
14,
1815,
8,
7145,
14,
374,
63,
21578,
8,
2083,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
1724,
339,
347,
511,
63,
10779,
8,
277,
304,
267,
3063,
275,
7137,
14,
10779,
342,
267,
291,
14,
1815,
8,
7145,
14,
374,
63,
22729,
8,
2131,
430,
267,
291,
14,
629,
8,
2131,
14,
1814,
8,
9374,
29,
403,
395,
3063,
14,
29648,
8,
11288,
680,
1814,
8,
9374,
29,
403,
430,
339,
347,
511,
63,
3916,
63,
475,
63,
5834,
8,
277,
304,
267,
19995,
275,
2197,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
9,
267,
19314,
275,
2197,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
12,
10313,
29,
11288,
9,
267,
291,
14,
629,
8,
5834,
12,
7137,
14,
3916,
63,
475,
63,
5834,
8,
21578,
430,
398,
325,
292,
275,
2197,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
12,
10313,
29,
37,
619,
9,
267,
19314,
275,
2197,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
1616,
12,
3388,
12,
4233,
12,
10313,
29,
11288,
9,
267,
291,
14,
629,
8,
5834,
12,
7137,
14,
3916,
63,
475,
63,
5834,
8,
69,
292,
430,
339,
347,
511,
63,
1875,
63,
21578,
8,
277,
304,
267,
291,
14,
629,
8,
288,
7137,
14,
1875,
63,
21578,
8,
2083,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
12,
10313,
29,
37,
619,
395,
662,
619,
395,
288,
2197,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
430,
267,
291,
14,
629,
8,
288,
7137,
14,
1875,
63,
21578,
8,
2083,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
5557,
12,
3388,
12,
4233,
12,
10313,
29,
6196,
395,
662,
619,
395,
288,
2197,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
430,
398,
543,
291,
14,
1855,
8,
3393,
304,
288,
7137,
14,
1875,
63,
21578,
8,
2083,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
395,
662,
619,
9,
339,
347,
511,
63,
1875,
63,
14600,
8,
277,
304,
267,
291,
14,
629,
8,
288,
7137,
14,
1875,
63,
14600,
8,
2083,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
395,
662,
619,
395,
288,
2197,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
12,
10313,
29,
37,
619,
430,
267,
543,
291,
14,
1855,
8,
3393,
304,
288,
7137,
14,
1875,
63,
14600,
8,
2083,
14,
2083,
8,
8128,
12,
1749,
12,
413,
12,
4944,
12,
3388,
12,
4233,
12,
10313,
29,
37,
619,
395,
662,
619,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
rust-lang/gyp
|
pylib/gyp/MSVSNew.py
|
601
|
12116
|
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""New implementation of Visual Studio project generation."""
import os
import random
import gyp.common
# hashlib is supplied as of Python 2.5 as the replacement interface for md5
# and other secure hashes. In 2.6, md5 is deprecated. Import hashlib if
# available, avoiding a deprecation warning under 2.6. Import md5 otherwise,
# preserving 2.4 compatibility.
try:
import hashlib
_new_md5 = hashlib.md5
except ImportError:
import md5
_new_md5 = md5.new
# Initialize random number generator
random.seed()
# GUIDs for project types
ENTRY_TYPE_GUIDS = {
'project': '{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}',
'folder': '{2150E333-8FDC-42A3-9474-1A3956D46DE8}',
}
#------------------------------------------------------------------------------
# Helper functions
def MakeGuid(name, seed='msvs_new'):
"""Returns a GUID for the specified target name.
Args:
name: Target name.
seed: Seed for MD5 hash.
Returns:
A GUID-line string calculated from the name and seed.
This generates something which looks like a GUID, but depends only on the
name and seed. This means the same name/seed will always generate the same
GUID, so that projects and solutions which refer to each other can explicitly
determine the GUID to refer to explicitly. It also means that the GUID will
not change when the project for a target is rebuilt.
"""
# Calculate a MD5 signature for the seed and name.
d = _new_md5(str(seed) + str(name)).hexdigest().upper()
# Convert most of the signature to GUID form (discard the rest)
guid = ('{' + d[:8] + '-' + d[8:12] + '-' + d[12:16] + '-' + d[16:20]
+ '-' + d[20:32] + '}')
return guid
#------------------------------------------------------------------------------
class MSVSSolutionEntry(object):
def __cmp__(self, other):
# Sort by name then guid (so things are in order on vs2008).
return cmp((self.name, self.get_guid()), (other.name, other.get_guid()))
class MSVSFolder(MSVSSolutionEntry):
"""Folder in a Visual Studio project or solution."""
def __init__(self, path, name = None, entries = None,
guid = None, items = None):
"""Initializes the folder.
Args:
path: Full path to the folder.
name: Name of the folder.
entries: List of folder entries to nest inside this folder. May contain
Folder or Project objects. May be None, if the folder is empty.
guid: GUID to use for folder, if not None.
items: List of solution items to include in the folder project. May be
None, if the folder does not directly contain items.
"""
if name:
self.name = name
else:
# Use last layer.
self.name = os.path.basename(path)
self.path = path
self.guid = guid
# Copy passed lists (or set to empty lists)
self.entries = sorted(list(entries or []))
self.items = list(items or [])
self.entry_type_guid = ENTRY_TYPE_GUIDS['folder']
def get_guid(self):
if self.guid is None:
# Use consistent guids for folders (so things don't regenerate).
self.guid = MakeGuid(self.path, seed='msvs_folder')
return self.guid
#------------------------------------------------------------------------------
class MSVSProject(MSVSSolutionEntry):
"""Visual Studio project."""
def __init__(self, path, name = None, dependencies = None, guid = None,
spec = None, build_file = None, config_platform_overrides = None,
fixpath_prefix = None):
"""Initializes the project.
Args:
path: Absolute path to the project file.
name: Name of project. If None, the name will be the same as the base
name of the project file.
dependencies: List of other Project objects this project is dependent
upon, if not None.
guid: GUID to use for project, if not None.
spec: Dictionary specifying how to build this project.
build_file: Filename of the .gyp file that the vcproj file comes from.
config_platform_overrides: optional dict of configuration platforms to
used in place of the default for this target.
fixpath_prefix: the path used to adjust the behavior of _fixpath
"""
self.path = path
self.guid = guid
self.spec = spec
self.build_file = build_file
# Use project filename if name not specified
self.name = name or os.path.splitext(os.path.basename(path))[0]
# Copy passed lists (or set to empty lists)
self.dependencies = list(dependencies or [])
self.entry_type_guid = ENTRY_TYPE_GUIDS['project']
if config_platform_overrides:
self.config_platform_overrides = config_platform_overrides
else:
self.config_platform_overrides = {}
self.fixpath_prefix = fixpath_prefix
self.msbuild_toolset = None
def set_dependencies(self, dependencies):
self.dependencies = list(dependencies or [])
def get_guid(self):
if self.guid is None:
# Set GUID from path
# TODO(rspangler): This is fragile.
# 1. We can't just use the project filename sans path, since there could
# be multiple projects with the same base name (for example,
# foo/unittest.vcproj and bar/unittest.vcproj).
# 2. The path needs to be relative to $SOURCE_ROOT, so that the project
# GUID is the same whether it's included from base/base.sln or
# foo/bar/baz/baz.sln.
# 3. The GUID needs to be the same each time this builder is invoked, so
# that we don't need to rebuild the solution when the project changes.
# 4. We should be able to handle pre-built project files by reading the
# GUID from the files.
self.guid = MakeGuid(self.name)
return self.guid
def set_msbuild_toolset(self, msbuild_toolset):
self.msbuild_toolset = msbuild_toolset
#------------------------------------------------------------------------------
class MSVSSolution:
"""Visual Studio solution."""
def __init__(self, path, version, entries=None, variants=None,
websiteProperties=True):
"""Initializes the solution.
Args:
path: Path to solution file.
version: Format version to emit.
entries: List of entries in solution. May contain Folder or Project
objects. May be None, if the folder is empty.
variants: List of build variant strings. If none, a default list will
be used.
websiteProperties: Flag to decide if the website properties section
is generated.
"""
self.path = path
self.websiteProperties = websiteProperties
self.version = version
# Copy passed lists (or set to empty lists)
self.entries = list(entries or [])
if variants:
# Copy passed list
self.variants = variants[:]
else:
# Use default
self.variants = ['Debug|Win32', 'Release|Win32']
# TODO(rspangler): Need to be able to handle a mapping of solution config
# to project config. Should we be able to handle variants being a dict,
# or add a separate variant_map variable? If it's a dict, we can't
# guarantee the order of variants since dict keys aren't ordered.
# TODO(rspangler): Automatically write to disk for now; should delay until
# node-evaluation time.
self.Write()
def Write(self, writer=gyp.common.WriteOnDiff):
"""Writes the solution file to disk.
Raises:
IndexError: An entry appears multiple times.
"""
# Walk the entry tree and collect all the folders and projects.
all_entries = set()
entries_to_check = self.entries[:]
while entries_to_check:
e = entries_to_check.pop(0)
# If this entry has been visited, nothing to do.
if e in all_entries:
continue
all_entries.add(e)
# If this is a folder, check its entries too.
if isinstance(e, MSVSFolder):
entries_to_check += e.entries
all_entries = sorted(all_entries)
# Open file and print header
f = writer(self.path)
f.write('Microsoft Visual Studio Solution File, '
'Format Version %s\r\n' % self.version.SolutionVersion())
f.write('# %s\r\n' % self.version.Description())
# Project entries
sln_root = os.path.split(self.path)[0]
for e in all_entries:
relative_path = gyp.common.RelativePath(e.path, sln_root)
# msbuild does not accept an empty folder_name.
# use '.' in case relative_path is empty.
folder_name = relative_path.replace('/', '\\') or '.'
f.write('Project("%s") = "%s", "%s", "%s"\r\n' % (
e.entry_type_guid, # Entry type GUID
e.name, # Folder name
folder_name, # Folder name (again)
e.get_guid(), # Entry GUID
))
# TODO(rspangler): Need a way to configure this stuff
if self.websiteProperties:
f.write('\tProjectSection(WebsiteProperties) = preProject\r\n'
'\t\tDebug.AspNetCompiler.Debug = "True"\r\n'
'\t\tRelease.AspNetCompiler.Debug = "False"\r\n'
'\tEndProjectSection\r\n')
if isinstance(e, MSVSFolder):
if e.items:
f.write('\tProjectSection(SolutionItems) = preProject\r\n')
for i in e.items:
f.write('\t\t%s = %s\r\n' % (i, i))
f.write('\tEndProjectSection\r\n')
if isinstance(e, MSVSProject):
if e.dependencies:
f.write('\tProjectSection(ProjectDependencies) = postProject\r\n')
for d in e.dependencies:
f.write('\t\t%s = %s\r\n' % (d.get_guid(), d.get_guid()))
f.write('\tEndProjectSection\r\n')
f.write('EndProject\r\n')
# Global section
f.write('Global\r\n')
# Configurations (variants)
f.write('\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\r\n')
for v in self.variants:
f.write('\t\t%s = %s\r\n' % (v, v))
f.write('\tEndGlobalSection\r\n')
# Sort config guids for easier diffing of solution changes.
config_guids = []
config_guids_overrides = {}
for e in all_entries:
if isinstance(e, MSVSProject):
config_guids.append(e.get_guid())
config_guids_overrides[e.get_guid()] = e.config_platform_overrides
config_guids.sort()
f.write('\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n')
for g in config_guids:
for v in self.variants:
nv = config_guids_overrides[g].get(v, v)
# Pick which project configuration to build for this solution
# configuration.
f.write('\t\t%s.%s.ActiveCfg = %s\r\n' % (
g, # Project GUID
v, # Solution build configuration
nv, # Project build config for that solution config
))
# Enable project in this solution configuration.
f.write('\t\t%s.%s.Build.0 = %s\r\n' % (
g, # Project GUID
v, # Solution build configuration
nv, # Project build config for that solution config
))
f.write('\tEndGlobalSection\r\n')
# TODO(rspangler): Should be able to configure this stuff too (though I've
# never seen this be any different)
f.write('\tGlobalSection(SolutionProperties) = preSolution\r\n')
f.write('\t\tHideSolutionNode = FALSE\r\n')
f.write('\tEndGlobalSection\r\n')
# Folder mappings
# Omit this section if there are no folders
if any([e.entries for e in all_entries if isinstance(e, MSVSFolder)]):
f.write('\tGlobalSection(NestedProjects) = preSolution\r\n')
for e in all_entries:
if not isinstance(e, MSVSFolder):
continue # Does not apply to projects, only folders
for subentry in e.entries:
f.write('\t\t%s = %s\r\n' % (subentry.get_guid(), e.get_guid()))
f.write('\tEndGlobalSection\r\n')
f.write('EndGlobal\r\n')
f.close()
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
4665,
4514,
402,
14702,
13225,
2199,
10152,
1041,
199,
199,
646,
747,
199,
646,
2196,
199,
199,
646,
4902,
14,
2330,
199,
199,
3,
8337,
365,
6841,
465,
402,
2018,
499,
14,
21,
465,
314,
8343,
3217,
367,
6128,
21,
199,
3,
436,
1163,
11153,
14647,
14,
221,
1010,
499,
14,
22,
12,
6128,
21,
365,
5906,
14,
221,
3161,
8337,
340,
199,
3,
2808,
12,
5126,
316,
282,
17831,
5721,
1334,
499,
14,
22,
14,
221,
3161,
6128,
21,
4257,
12,
199,
3,
876,
14717,
499,
14,
20,
7163,
14,
199,
893,
26,
523,
492,
8337,
523,
485,
1222,
63,
1064,
21,
275,
8337,
14,
1064,
21,
199,
2590,
3545,
26,
523,
492,
6128,
21,
523,
485,
1222,
63,
1064,
21,
275,
6128,
21,
14,
1222,
421,
199,
3,
11578,
2196,
1329,
4306,
199,
2355,
14,
5176,
342,
199,
199,
3,
21645,
83,
367,
2199,
2943,
199,
7285,
63,
2711,
63,
17856,
51,
275,
469,
272,
283,
1715,
356,
5041,
24,
6265,
25,
2089,
34,
24,
13,
24,
34,
20,
33,
13,
845,
36,
16,
13,
24,
36,
845,
13,
383,
33,
16,
35,
3328,
6265,
25,
2260,
7293,
272,
283,
3741,
356,
5041,
7842,
16,
37,
11769,
13,
24,
38,
5196,
13,
2260,
33,
19,
13,
2635,
1342,
13,
17,
33,
1355,
1367,
36,
2466,
1093,
24,
7293,
199,
93,
199,
199,
20974,
199,
3,
11642,
3423,
421,
199,
318,
4155,
18834,
8,
354,
12,
6347,
534,
8338,
63,
1222,
735,
523,
408,
3407,
282,
21645,
367,
314,
2013,
1347,
536,
14,
819,
3033,
26,
272,
536,
26,
10256,
536,
14,
272,
6347,
26,
3240,
379,
367,
15830,
21,
2631,
14,
523,
1803,
26,
272,
437,
21645,
13,
604,
1059,
12950,
687,
314,
536,
436,
6347,
14,
819,
961,
12821,
6020,
1314,
10734,
2839,
282,
21645,
12,
1325,
8350,
1454,
641,
314,
523,
536,
436,
6347,
14,
221,
961,
4910,
314,
2011,
536,
15,
5176,
911,
3544,
3550,
314,
2011,
523,
21645,
12,
880,
626,
11336,
436,
24886,
1314,
10618,
370,
1924,
1163,
883,
7662,
523,
6705,
314,
21645,
370,
10618,
370,
7662,
14,
221,
2779,
2597,
4910,
626,
314,
21645,
911,
523,
440,
1570,
1380,
314,
2199,
367,
282,
1347,
365,
295,
11730,
14,
523,
408,
523,
327,
12707,
282,
15830,
21,
4955,
367,
314,
6347,
436,
536,
14,
523,
366,
275,
485,
1222,
63,
1064,
21,
8,
495,
8,
5176,
9,
435,
620,
8,
354,
4992,
11453,
1252,
4142,
342,
523,
327,
7905,
4750,
402,
314,
4955,
370,
21645,
1824,
334,
14394,
314,
4618,
9,
523,
15593,
275,
661,
1445,
435,
366,
1491,
24,
61,
435,
10791,
435,
366,
59,
24,
26,
713,
61,
435,
10791,
435,
366,
59,
713,
26,
975,
61,
435,
10791,
435,
366,
59,
975,
26,
1165,
61,
881,
435,
10791,
435,
366,
59,
1165,
26,
708,
61,
435,
283,
12216,
523,
372,
15593,
199,
199,
20974,
421,
199,
533,
11694,
2300,
3347,
3900,
8,
785,
304,
523,
347,
636,
5730,
721,
277,
12,
1163,
304,
272,
327,
16722,
701,
536,
2066,
15593,
334,
1152,
7645,
787,
315,
1865,
641,
8118,
9300,
680,
272,
372,
10467,
1332,
277,
14,
354,
12,
291,
14,
362,
63,
9473,
4000,
334,
1848,
14,
354,
12,
1163,
14,
362,
63,
9473,
4059,
421,
199,
533,
13828,
7850,
8,
3053,
54,
2300,
3347,
3900,
304,
523,
408,
7850,
315,
282,
14702,
13225,
2199,
503,
8744,
1041,
819,
347,
636,
826,
721,
277,
12,
931,
12,
536,
275,
488,
12,
4811,
275,
488,
12,
2049,
15593,
275,
488,
12,
2974,
275,
488,
304,
272,
408,
23489,
314,
4922,
14,
339,
3033,
26,
489,
931,
26,
16579,
931,
370,
314,
4922,
14,
489,
536,
26,
2812,
402,
314,
4922,
14,
489,
4811,
26,
3820,
402,
4922,
4811,
370,
10715,
6272,
642,
4922,
14,
221,
10162,
1395,
881,
29121,
503,
7290,
2251,
14,
221,
10162,
506,
488,
12,
340,
314,
4922,
365,
2701,
14,
489,
15593,
26,
21645,
370,
675,
367,
4922,
12,
340,
440,
488,
14,
489,
2974,
26,
3820,
402,
8744,
2974,
370,
2387,
315,
314,
4922,
2199,
14,
221,
10162,
506,
881,
488,
12,
340,
314,
4922,
1630,
440,
5370,
1395,
2974,
14,
272,
408,
272,
340,
536,
26,
489,
291,
14,
354,
275,
536,
272,
587,
26,
489,
327,
3645,
2061,
4045,
14,
489,
291,
14,
354,
275,
747,
14,
515,
14,
4846,
8,
515,
9,
339,
291,
14,
515,
275,
931,
272,
291,
14,
9473,
275,
15593,
339,
327,
11247,
3032,
5548,
334,
269,
663,
370,
2701,
5548,
9,
272,
291,
14,
3189,
275,
3355,
8,
513,
8,
3189,
503,
15927,
272,
291,
14,
1744,
275,
769,
8,
1744,
503,
3073,
339,
291,
14,
2373,
63,
466,
63,
9473,
275,
5070,
21177,
63,
2711,
63,
17856,
51,
459,
3741,
418,
819,
347,
664,
63,
9473,
8,
277,
304,
272,
340,
291,
14,
9473,
365,
488,
26,
489,
327,
3645,
12137,
15593,
83,
367,
16533,
334,
1152,
7645,
2793,
1133,
30943,
680,
489,
291,
14,
9473,
275,
4155,
18834,
8,
277,
14,
515,
12,
6347,
534,
8338,
63,
3741,
358,
272,
372,
291,
14,
9473,
421,
199,
20974,
421,
199,
533,
13828,
4761,
8,
3053,
54,
2300,
3347,
3900,
304,
523,
408,
15039,
13225,
2199,
1041,
819,
347,
636,
826,
721,
277,
12,
931,
12,
536,
275,
488,
12,
5124,
275,
488,
12,
15593,
275,
488,
12,
2049,
3158,
275,
488,
12,
1900,
63,
493,
275,
488,
12,
1101,
63,
3246,
63,
12867,
275,
488,
12,
2049,
5325,
515,
63,
1861,
275,
488,
304,
272,
408,
23489,
314,
2199,
14,
339,
3033,
26,
489,
931,
26,
24964,
931,
370,
314,
2199,
570,
14,
489,
536,
26,
2812,
402,
2199,
14,
221,
982,
488,
12,
314,
536,
911,
506,
314,
2011,
465,
314,
1300,
881,
536,
402,
314,
2199,
570,
14,
489,
5124,
26,
3820,
402,
1163,
7290,
2251,
642,
2199,
365,
11410,
881,
12188,
12,
340,
440,
488,
14,
489,
15593,
26,
21645,
370,
675,
367,
2199,
12
] |
[
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
4665,
4514,
402,
14702,
13225,
2199,
10152,
1041,
199,
199,
646,
747,
199,
646,
2196,
199,
199,
646,
4902,
14,
2330,
199,
199,
3,
8337,
365,
6841,
465,
402,
2018,
499,
14,
21,
465,
314,
8343,
3217,
367,
6128,
21,
199,
3,
436,
1163,
11153,
14647,
14,
221,
1010,
499,
14,
22,
12,
6128,
21,
365,
5906,
14,
221,
3161,
8337,
340,
199,
3,
2808,
12,
5126,
316,
282,
17831,
5721,
1334,
499,
14,
22,
14,
221,
3161,
6128,
21,
4257,
12,
199,
3,
876,
14717,
499,
14,
20,
7163,
14,
199,
893,
26,
523,
492,
8337,
523,
485,
1222,
63,
1064,
21,
275,
8337,
14,
1064,
21,
199,
2590,
3545,
26,
523,
492,
6128,
21,
523,
485,
1222,
63,
1064,
21,
275,
6128,
21,
14,
1222,
421,
199,
3,
11578,
2196,
1329,
4306,
199,
2355,
14,
5176,
342,
199,
199,
3,
21645,
83,
367,
2199,
2943,
199,
7285,
63,
2711,
63,
17856,
51,
275,
469,
272,
283,
1715,
356,
5041,
24,
6265,
25,
2089,
34,
24,
13,
24,
34,
20,
33,
13,
845,
36,
16,
13,
24,
36,
845,
13,
383,
33,
16,
35,
3328,
6265,
25,
2260,
7293,
272,
283,
3741,
356,
5041,
7842,
16,
37,
11769,
13,
24,
38,
5196,
13,
2260,
33,
19,
13,
2635,
1342,
13,
17,
33,
1355,
1367,
36,
2466,
1093,
24,
7293,
199,
93,
199,
199,
20974,
199,
3,
11642,
3423,
421,
199,
318,
4155,
18834,
8,
354,
12,
6347,
534,
8338,
63,
1222,
735,
523,
408,
3407,
282,
21645,
367,
314,
2013,
1347,
536,
14,
819,
3033,
26,
272,
536,
26,
10256,
536,
14,
272,
6347,
26,
3240,
379,
367,
15830,
21,
2631,
14,
523,
1803,
26,
272,
437,
21645,
13,
604,
1059,
12950,
687,
314,
536,
436,
6347,
14,
819,
961,
12821,
6020,
1314,
10734,
2839,
282,
21645,
12,
1325,
8350,
1454,
641,
314,
523,
536,
436,
6347,
14,
221,
961,
4910,
314,
2011,
536,
15,
5176,
911,
3544,
3550,
314,
2011,
523,
21645,
12,
880,
626,
11336,
436,
24886,
1314,
10618,
370,
1924,
1163,
883,
7662,
523,
6705,
314,
21645,
370,
10618,
370,
7662,
14,
221,
2779,
2597,
4910,
626,
314,
21645,
911,
523,
440,
1570,
1380,
314,
2199,
367,
282,
1347,
365,
295,
11730,
14,
523,
408,
523,
327,
12707,
282,
15830,
21,
4955,
367,
314,
6347,
436,
536,
14,
523,
366,
275,
485,
1222,
63,
1064,
21,
8,
495,
8,
5176,
9,
435,
620,
8,
354,
4992,
11453,
1252,
4142,
342,
523,
327,
7905,
4750,
402,
314,
4955,
370,
21645,
1824,
334,
14394,
314,
4618,
9,
523,
15593,
275,
661,
1445,
435,
366,
1491,
24,
61,
435,
10791,
435,
366,
59,
24,
26,
713,
61,
435,
10791,
435,
366,
59,
713,
26,
975,
61,
435,
10791,
435,
366,
59,
975,
26,
1165,
61,
881,
435,
10791,
435,
366,
59,
1165,
26,
708,
61,
435,
283,
12216,
523,
372,
15593,
199,
199,
20974,
421,
199,
533,
11694,
2300,
3347,
3900,
8,
785,
304,
523,
347,
636,
5730,
721,
277,
12,
1163,
304,
272,
327,
16722,
701,
536,
2066,
15593,
334,
1152,
7645,
787,
315,
1865,
641,
8118,
9300,
680,
272,
372,
10467,
1332,
277,
14,
354,
12,
291,
14,
362,
63,
9473,
4000,
334,
1848,
14,
354,
12,
1163,
14,
362,
63,
9473,
4059,
421,
199,
533,
13828,
7850,
8,
3053,
54,
2300,
3347,
3900,
304,
523,
408,
7850,
315,
282,
14702,
13225,
2199,
503,
8744,
1041,
819,
347,
636,
826,
721,
277,
12,
931,
12,
536,
275,
488,
12,
4811,
275,
488,
12,
2049,
15593,
275,
488,
12,
2974,
275,
488,
304,
272,
408,
23489,
314,
4922,
14,
339,
3033,
26,
489,
931,
26,
16579,
931,
370,
314,
4922,
14,
489,
536,
26,
2812,
402,
314,
4922,
14,
489,
4811,
26,
3820,
402,
4922,
4811,
370,
10715,
6272,
642,
4922,
14,
221,
10162,
1395,
881,
29121,
503,
7290,
2251,
14,
221,
10162,
506,
488,
12,
340,
314,
4922,
365,
2701,
14,
489,
15593,
26,
21645,
370,
675,
367,
4922,
12,
340,
440,
488,
14,
489,
2974,
26,
3820,
402,
8744,
2974,
370,
2387,
315,
314,
4922,
2199,
14,
221,
10162,
506,
881,
488,
12,
340,
314,
4922,
1630,
440,
5370,
1395,
2974,
14,
272,
408,
272,
340,
536,
26,
489,
291,
14,
354,
275,
536,
272,
587,
26,
489,
327,
3645,
2061,
4045,
14,
489,
291,
14,
354,
275,
747,
14,
515,
14,
4846,
8,
515,
9,
339,
291,
14,
515,
275,
931,
272,
291,
14,
9473,
275,
15593,
339,
327,
11247,
3032,
5548,
334,
269,
663,
370,
2701,
5548,
9,
272,
291,
14,
3189,
275,
3355,
8,
513,
8,
3189,
503,
15927,
272,
291,
14,
1744,
275,
769,
8,
1744,
503,
3073,
339,
291,
14,
2373,
63,
466,
63,
9473,
275,
5070,
21177,
63,
2711,
63,
17856,
51,
459,
3741,
418,
819,
347,
664,
63,
9473,
8,
277,
304,
272,
340,
291,
14,
9473,
365,
488,
26,
489,
327,
3645,
12137,
15593,
83,
367,
16533,
334,
1152,
7645,
2793,
1133,
30943,
680,
489,
291,
14,
9473,
275,
4155,
18834,
8,
277,
14,
515,
12,
6347,
534,
8338,
63,
3741,
358,
272,
372,
291,
14,
9473,
421,
199,
20974,
421,
199,
533,
13828,
4761,
8,
3053,
54,
2300,
3347,
3900,
304,
523,
408,
15039,
13225,
2199,
1041,
819,
347,
636,
826,
721,
277,
12,
931,
12,
536,
275,
488,
12,
5124,
275,
488,
12,
15593,
275,
488,
12,
2049,
3158,
275,
488,
12,
1900,
63,
493,
275,
488,
12,
1101,
63,
3246,
63,
12867,
275,
488,
12,
2049,
5325,
515,
63,
1861,
275,
488,
304,
272,
408,
23489,
314,
2199,
14,
339,
3033,
26,
489,
931,
26,
24964,
931,
370,
314,
2199,
570,
14,
489,
536,
26,
2812,
402,
2199,
14,
221,
982,
488,
12,
314,
536,
911,
506,
314,
2011,
465,
314,
1300,
881,
536,
402,
314,
2199,
570,
14,
489,
5124,
26,
3820,
402,
1163,
7290,
2251,
642,
2199,
365,
11410,
881,
12188,
12,
340,
440,
488,
14,
489,
15593,
26,
21645,
370,
675,
367,
2199,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
BenLangmead/qtip-experiments
|
experiments/real_data/perf_tabulate.py
|
1
|
3305
|
"""
Creates a table with efficiency metrics (running time, peak memory
footprint) from SLURM output generated from sbatch_align.sh.
"""
from __future__ import print_function
import glob
import sys
from collections import defaultdict
nslurm, nsam = 0, 0
sam_names = defaultdict(int)
tab_wrapped = defaultdict(lambda: defaultdict(int))
to_slurm_wrapped = {}
for fn in glob.glob('slurm-*.out'):
with open(fn) as fh:
ln = fh.readline()
if 'is up to date' in ln:
continue # skip trivial job target was already up to date
if ln.split()[0] != 'python':
continue
nsam += 1
name, t_tandal, t_tandpa, wrappeak, childpeak, t_overall, t_inp = None, 0, 0, 0, 0, 0, 0
while True:
ln = fh.readline()
if len(ln) == 0:
break
ln = ln.rstrip()
if '--vanilla-out' in ln:
assert name is None
name = ln.split()[1]
if 'INFO:Overall' in ln:
t_overall = float(ln.split()[-1])
if 'INFO:Aligning input reads' in ln:
t_inp = float(ln.split()[-1])
if 'INFO:Aligning tandem reads' in ln and 'paired' not in ln:
t_tandal = float(ln.split()[-1])
if 'INFO:Parsing tandem alignments' in ln:
t_tandpa = float(ln.split()[-1])
if 'INFO:Peak memory usage (RSS) of Python wrapper' in ln:
wrappeak = ln.split()[-1]
assert wrappeak[-2:] == 'GB'
wrappeak = float(wrappeak[:-2]) * 1024 * 1024 * 1024
if 'INFO:Peak memory usage (RSS) of children' in ln:
childpeak = ln.split()[-1]
assert childpeak[-2:] == 'GB'
childpeak = float(childpeak[:-2]) * 1024 * 1024 * 1024
sam_names[name] += 1
tab_wrapped[name]['wrappeak'] = wrappeak
tab_wrapped[name]['childpeak'] = childpeak
tab_wrapped[name]['t_overall'] = t_overall
tab_wrapped[name]['t_inp'] = t_inp
tab_wrapped[name]['t_tandal'] = t_tandal
tab_wrapped[name]['t_tandpa'] = t_tandpa
to_slurm_wrapped[name] = fn
nslurm += 1
print('# slurm files: %d' % nslurm, file=sys.stderr)
print('# sam files: %d' % nsam, file=sys.stderr)
for k, v in sorted(sam_names.items()):
print(' %s: %d' % (k, v), file=sys.stderr)
aln_map = {'bt2': 'Bowtie 2', 'bwa': 'BWA-MEM', 'snap': 'SNAP'}
print('data,aligner,paired,align_time,overall_time,pct_increase_a_to_o,peak_wrapper,peak_children,pct_increase_peak')
for k in sorted(sam_names.keys()):
wrappeak = tab_wrapped[k]['wrappeak']
childpeak = tab_wrapped[k]['childpeak']
wrappct = 0 if childpeak == 0 else (wrappeak * 100.0 / childpeak)
wrappct = ('+' if wrappct >= 0 else '') + ('%0.3f' % wrappct)
t_o, t_a = tab_wrapped[k]['t_overall'], tab_wrapped[k]['t_inp']
t_pct = 0 if t_a == 0 else ((t_o - t_a) * 100.0/t_a)
t_pct = ('+' if t_pct >= 0 else '') + ('%0.3f' % t_pct)
srr, aligner, paired, _ = k.split('.')
srr = srr[:-2] # chop off trailing _1
aligner = aln_map[aligner]
paired = 'T' if paired == 'pair' else 'F'
print('%s,%s,%s,%.0f,%.0f,%s,%.0f,%.0f,%s' % (srr, aligner, paired, t_a, t_o, t_pct, wrappeak, childpeak, wrappct))
|
mit
|
[
624,
199,
10607,
282,
1817,
543,
25978,
7186,
334,
5720,
900,
12,
21441,
4402,
199,
11407,
1361,
9,
687,
428,
44,
1230,
45,
1072,
4046,
687,
308,
2912,
63,
5743,
14,
609,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
5739,
199,
646,
984,
199,
504,
5055,
492,
10018,
199,
199,
561,
76,
12410,
12,
700,
455,
275,
378,
12,
378,
199,
21660,
63,
1247,
275,
10018,
8,
442,
9,
199,
2902,
63,
9130,
275,
10018,
8,
2734,
26,
10018,
8,
442,
430,
199,
475,
63,
2482,
12410,
63,
9130,
275,
1052,
199,
199,
509,
4325,
315,
5739,
14,
6463,
360,
2482,
12410,
13,
4856,
548,
735,
272,
543,
1551,
8,
2324,
9,
465,
11155,
26,
267,
10359,
275,
11155,
14,
6407,
342,
267,
340,
283,
374,
1536,
370,
1434,
7,
315,
10359,
26,
288,
1980,
221,
327,
3372,
28586,
3906,
1347,
1990,
2575,
1536,
370,
1434,
267,
340,
10359,
14,
1294,
3430,
16,
61,
1137,
283,
1548,
356,
288,
1980,
398,
700,
455,
847,
413,
267,
536,
12,
307,
63,
84,
460,
279,
12,
307,
63,
84,
460,
387,
12,
4816,
8556,
12,
1982,
8556,
12,
307,
63,
1883,
452,
12,
307,
63,
11416,
275,
488,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
267,
1830,
715,
26,
288,
10359,
275,
11155,
14,
6407,
342,
288,
340,
822,
8,
6066,
9,
508,
378,
26,
355,
2059,
288,
10359,
275,
10359,
14,
6735,
342,
288,
340,
2850,
20662,
6165,
13,
548,
7,
315,
10359,
26,
355,
702,
536,
365,
488,
355,
536,
275,
10359,
14,
1294,
3430,
17,
61,
288,
340,
283,
4531,
26,
5674,
452,
7,
315,
10359,
26,
355,
307,
63,
1883,
452,
275,
2069,
8,
6066,
14,
1294,
19105,
17,
566,
288,
340,
283,
4531,
26,
9497,
316,
1324,
11597,
7,
315,
10359,
26,
355,
307,
63,
11416,
275,
2069,
8,
6066,
14,
1294,
19105,
17,
566,
288,
340,
283,
4531,
26,
9497,
316,
20162,
23522,
11597,
7,
315,
10359,
436,
283,
29796,
7,
440,
315,
10359,
26,
355,
307,
63,
84,
460,
279,
275,
2069,
8,
6066,
14,
1294,
19105,
17,
566,
288,
340,
283,
4531,
26,
17412,
20162,
23522,
6998,
1470,
7,
315,
10359,
26,
355,
307,
63,
84,
460,
387,
275,
2069,
8,
6066,
14,
1294,
19105,
17,
566,
288,
340,
283,
4531,
26,
32448,
4402,
4503,
334,
22786,
9,
402,
2018,
4975,
7,
315,
10359,
26,
355,
4816,
8556,
275,
10359,
14,
1294,
19105,
17,
61,
355,
702,
4816,
8556,
1988,
18,
2938,
508,
283,
6487,
7,
355,
4816,
8556,
275,
2069,
8,
3823,
8556,
4439,
18,
566,
627,
6619,
627,
6619,
627,
6619,
288,
340,
283,
4531,
26,
32448,
4402,
4503,
334,
22786,
9,
402,
4978,
7,
315,
10359,
26,
355,
1982,
8556,
275,
10359,
14,
1294,
19105,
17,
61,
355,
702,
1982,
8556,
1988,
18,
2938,
508,
283,
6487,
7,
355,
1982,
8556,
275,
2069,
8,
1739,
8556,
4439,
18,
566,
627,
6619,
627,
6619,
627,
6619,
398,
31626,
63,
1247,
59,
354,
61,
847,
413,
267,
5174,
63,
9130,
59,
354,
2733,
3823,
8556,
418,
275,
4816,
8556,
267,
5174,
63,
9130,
59,
354,
2733,
1739,
8556,
418,
275,
1982,
8556,
267,
5174,
63,
9130,
59,
354,
2733,
84,
63,
1883,
452,
418,
275,
307,
63,
1883,
452,
267,
5174,
63,
9130,
59,
354,
2733,
84,
63,
11416,
418,
275,
307,
63,
11416,
267,
5174,
63,
9130,
59,
354,
2733,
84,
63,
84,
460,
279,
418,
275,
307,
63,
84,
460,
279,
267,
5174,
63,
9130,
59,
354,
2733,
84,
63,
84,
460,
387,
418,
275,
307,
63,
84,
460,
387,
267,
370,
63,
2482,
12410,
63,
9130,
59,
354,
61,
275,
4325,
339,
700,
76,
12410,
847,
413,
199,
199,
1361,
7863,
5340,
12410,
1584,
26,
450,
68,
7,
450,
700,
76,
12410,
12,
570,
29,
1274,
14,
3083,
9,
199,
1361,
7863,
31626,
1584,
26,
450,
68,
7,
450,
700,
455,
12,
570,
29,
1274,
14,
3083,
9,
199,
509,
1022,
12,
373,
315,
3355,
8,
21660,
63,
1247,
14,
1744,
5109,
272,
870,
360,
221,
450,
83,
26,
450,
68,
7,
450,
334,
75,
12,
373,
395,
570,
29,
1274,
14,
3083,
9,
199,
199,
279,
78,
63,
1130,
275,
791,
13061,
18,
356,
283,
34,
583,
23958,
499,
297,
283,
66,
758,
356,
283,
34,
9004,
13,
10293,
297,
283,
10002,
356,
283,
22616,
936,
199,
1361,
360,
576,
12,
5743,
281,
12,
29796,
12,
5743,
63,
521,
12,
1883,
452,
63,
521,
12,
20778,
63,
31687,
63,
65,
63,
475,
63,
79,
12,
8556,
63,
5029,
12,
8556,
63,
3223,
12,
20778,
63,
31687,
63,
8556,
358,
199,
509,
1022,
315,
3355,
8,
21660,
63,
1247,
14,
1612,
5109,
272,
4816,
8556,
275,
5174,
63,
9130,
59,
75,
2733,
3823,
8556,
418,
272,
1982,
8556,
275,
5174,
63,
9130,
59,
75,
2733,
1739,
8556,
418,
272,
336,
345,
802,
319,
275,
378,
340,
1982,
8556,
508,
378,
587,
334,
3823,
8556,
627,
2948,
14,
16,
1182,
1982,
8556,
9,
272,
336,
345,
802,
319,
275,
661,
4786,
340,
336,
345,
802,
319,
2356,
378,
587,
4074,
435,
16651,
16,
14,
19,
70,
7,
450,
336,
345,
802,
319,
9,
272,
307,
63,
79,
12,
307,
63,
65,
275,
5174,
63,
9130,
59,
75,
2733,
84,
63,
1883,
452,
995,
5174,
63,
9130,
59,
75,
2733,
84,
63,
11416,
418,
272,
307,
63,
20778,
275,
378,
340,
307,
63,
65,
508,
378,
587,
3666,
84,
63,
79,
446,
307,
63,
65,
9,
627,
2948,
14,
16,
15,
84,
63,
65,
9,
272,
307,
63,
20778,
275,
661,
4786,
340,
307,
63,
20778,
2356,
378,
587,
4074,
435,
16651,
16,
14,
19,
70,
7,
450,
307,
63,
20778,
9,
272,
308,
9734,
12,
6998,
281,
12,
30177,
12,
485,
275,
1022,
14,
1294,
7563,
272,
308,
9734,
275,
308,
9734,
4439,
18,
61,
221,
327,
32401,
2331,
8520,
485,
17,
272,
6998,
281,
275,
741,
78,
63,
1130,
59,
5743,
281,
61,
272,
30177,
275,
283,
52,
7,
340,
30177,
508,
283,
3852,
7,
587,
283,
38,
7,
272,
870,
3508,
83,
8719,
83,
8719,
83,
8719,
14,
16
] |
[
199,
10607,
282,
1817,
543,
25978,
7186,
334,
5720,
900,
12,
21441,
4402,
199,
11407,
1361,
9,
687,
428,
44,
1230,
45,
1072,
4046,
687,
308,
2912,
63,
5743,
14,
609,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
5739,
199,
646,
984,
199,
504,
5055,
492,
10018,
199,
199,
561,
76,
12410,
12,
700,
455,
275,
378,
12,
378,
199,
21660,
63,
1247,
275,
10018,
8,
442,
9,
199,
2902,
63,
9130,
275,
10018,
8,
2734,
26,
10018,
8,
442,
430,
199,
475,
63,
2482,
12410,
63,
9130,
275,
1052,
199,
199,
509,
4325,
315,
5739,
14,
6463,
360,
2482,
12410,
13,
4856,
548,
735,
272,
543,
1551,
8,
2324,
9,
465,
11155,
26,
267,
10359,
275,
11155,
14,
6407,
342,
267,
340,
283,
374,
1536,
370,
1434,
7,
315,
10359,
26,
288,
1980,
221,
327,
3372,
28586,
3906,
1347,
1990,
2575,
1536,
370,
1434,
267,
340,
10359,
14,
1294,
3430,
16,
61,
1137,
283,
1548,
356,
288,
1980,
398,
700,
455,
847,
413,
267,
536,
12,
307,
63,
84,
460,
279,
12,
307,
63,
84,
460,
387,
12,
4816,
8556,
12,
1982,
8556,
12,
307,
63,
1883,
452,
12,
307,
63,
11416,
275,
488,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
267,
1830,
715,
26,
288,
10359,
275,
11155,
14,
6407,
342,
288,
340,
822,
8,
6066,
9,
508,
378,
26,
355,
2059,
288,
10359,
275,
10359,
14,
6735,
342,
288,
340,
2850,
20662,
6165,
13,
548,
7,
315,
10359,
26,
355,
702,
536,
365,
488,
355,
536,
275,
10359,
14,
1294,
3430,
17,
61,
288,
340,
283,
4531,
26,
5674,
452,
7,
315,
10359,
26,
355,
307,
63,
1883,
452,
275,
2069,
8,
6066,
14,
1294,
19105,
17,
566,
288,
340,
283,
4531,
26,
9497,
316,
1324,
11597,
7,
315,
10359,
26,
355,
307,
63,
11416,
275,
2069,
8,
6066,
14,
1294,
19105,
17,
566,
288,
340,
283,
4531,
26,
9497,
316,
20162,
23522,
11597,
7,
315,
10359,
436,
283,
29796,
7,
440,
315,
10359,
26,
355,
307,
63,
84,
460,
279,
275,
2069,
8,
6066,
14,
1294,
19105,
17,
566,
288,
340,
283,
4531,
26,
17412,
20162,
23522,
6998,
1470,
7,
315,
10359,
26,
355,
307,
63,
84,
460,
387,
275,
2069,
8,
6066,
14,
1294,
19105,
17,
566,
288,
340,
283,
4531,
26,
32448,
4402,
4503,
334,
22786,
9,
402,
2018,
4975,
7,
315,
10359,
26,
355,
4816,
8556,
275,
10359,
14,
1294,
19105,
17,
61,
355,
702,
4816,
8556,
1988,
18,
2938,
508,
283,
6487,
7,
355,
4816,
8556,
275,
2069,
8,
3823,
8556,
4439,
18,
566,
627,
6619,
627,
6619,
627,
6619,
288,
340,
283,
4531,
26,
32448,
4402,
4503,
334,
22786,
9,
402,
4978,
7,
315,
10359,
26,
355,
1982,
8556,
275,
10359,
14,
1294,
19105,
17,
61,
355,
702,
1982,
8556,
1988,
18,
2938,
508,
283,
6487,
7,
355,
1982,
8556,
275,
2069,
8,
1739,
8556,
4439,
18,
566,
627,
6619,
627,
6619,
627,
6619,
398,
31626,
63,
1247,
59,
354,
61,
847,
413,
267,
5174,
63,
9130,
59,
354,
2733,
3823,
8556,
418,
275,
4816,
8556,
267,
5174,
63,
9130,
59,
354,
2733,
1739,
8556,
418,
275,
1982,
8556,
267,
5174,
63,
9130,
59,
354,
2733,
84,
63,
1883,
452,
418,
275,
307,
63,
1883,
452,
267,
5174,
63,
9130,
59,
354,
2733,
84,
63,
11416,
418,
275,
307,
63,
11416,
267,
5174,
63,
9130,
59,
354,
2733,
84,
63,
84,
460,
279,
418,
275,
307,
63,
84,
460,
279,
267,
5174,
63,
9130,
59,
354,
2733,
84,
63,
84,
460,
387,
418,
275,
307,
63,
84,
460,
387,
267,
370,
63,
2482,
12410,
63,
9130,
59,
354,
61,
275,
4325,
339,
700,
76,
12410,
847,
413,
199,
199,
1361,
7863,
5340,
12410,
1584,
26,
450,
68,
7,
450,
700,
76,
12410,
12,
570,
29,
1274,
14,
3083,
9,
199,
1361,
7863,
31626,
1584,
26,
450,
68,
7,
450,
700,
455,
12,
570,
29,
1274,
14,
3083,
9,
199,
509,
1022,
12,
373,
315,
3355,
8,
21660,
63,
1247,
14,
1744,
5109,
272,
870,
360,
221,
450,
83,
26,
450,
68,
7,
450,
334,
75,
12,
373,
395,
570,
29,
1274,
14,
3083,
9,
199,
199,
279,
78,
63,
1130,
275,
791,
13061,
18,
356,
283,
34,
583,
23958,
499,
297,
283,
66,
758,
356,
283,
34,
9004,
13,
10293,
297,
283,
10002,
356,
283,
22616,
936,
199,
1361,
360,
576,
12,
5743,
281,
12,
29796,
12,
5743,
63,
521,
12,
1883,
452,
63,
521,
12,
20778,
63,
31687,
63,
65,
63,
475,
63,
79,
12,
8556,
63,
5029,
12,
8556,
63,
3223,
12,
20778,
63,
31687,
63,
8556,
358,
199,
509,
1022,
315,
3355,
8,
21660,
63,
1247,
14,
1612,
5109,
272,
4816,
8556,
275,
5174,
63,
9130,
59,
75,
2733,
3823,
8556,
418,
272,
1982,
8556,
275,
5174,
63,
9130,
59,
75,
2733,
1739,
8556,
418,
272,
336,
345,
802,
319,
275,
378,
340,
1982,
8556,
508,
378,
587,
334,
3823,
8556,
627,
2948,
14,
16,
1182,
1982,
8556,
9,
272,
336,
345,
802,
319,
275,
661,
4786,
340,
336,
345,
802,
319,
2356,
378,
587,
4074,
435,
16651,
16,
14,
19,
70,
7,
450,
336,
345,
802,
319,
9,
272,
307,
63,
79,
12,
307,
63,
65,
275,
5174,
63,
9130,
59,
75,
2733,
84,
63,
1883,
452,
995,
5174,
63,
9130,
59,
75,
2733,
84,
63,
11416,
418,
272,
307,
63,
20778,
275,
378,
340,
307,
63,
65,
508,
378,
587,
3666,
84,
63,
79,
446,
307,
63,
65,
9,
627,
2948,
14,
16,
15,
84,
63,
65,
9,
272,
307,
63,
20778,
275,
661,
4786,
340,
307,
63,
20778,
2356,
378,
587,
4074,
435,
16651,
16,
14,
19,
70,
7,
450,
307,
63,
20778,
9,
272,
308,
9734,
12,
6998,
281,
12,
30177,
12,
485,
275,
1022,
14,
1294,
7563,
272,
308,
9734,
275,
308,
9734,
4439,
18,
61,
221,
327,
32401,
2331,
8520,
485,
17,
272,
6998,
281,
275,
741,
78,
63,
1130,
59,
5743,
281,
61,
272,
30177,
275,
283,
52,
7,
340,
30177,
508,
283,
3852,
7,
587,
283,
38,
7,
272,
870,
3508,
83,
8719,
83,
8719,
83,
8719,
14,
16,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
adw0rd/lettuce
|
tests/integration/lib/Django-1.3/django/db/models/sql/compiler.py
|
52
|
43006
|
from django.core.exceptions import FieldError
from django.db import connections
from django.db.backends.util import truncate_name
from django.db.models.sql.constants import *
from django.db.models.sql.datastructures import EmptyResultSet
from django.db.models.sql.expressions import SQLEvaluator
from django.db.models.sql.query import get_proxied_model, get_order_dir, \
select_related_descend, Query
class SQLCompiler(object):
def __init__(self, query, connection, using):
self.query = query
self.connection = connection
self.using = using
self.quote_cache = {}
def pre_sql_setup(self):
"""
Does any necessary class setup immediately prior to producing SQL. This
is for things that can't necessarily be done in __init__ because we
might not have all the pieces in place at that time.
"""
if not self.query.tables:
self.query.join((None, self.query.model._meta.db_table, None, None))
if (not self.query.select and self.query.default_cols and not
self.query.included_inherited_models):
self.query.setup_inherited_models()
if self.query.select_related and not self.query.related_select_cols:
self.fill_related_selections()
def quote_name_unless_alias(self, name):
"""
A wrapper around connection.ops.quote_name that doesn't quote aliases
for table names. This avoids problems with some SQL dialects that treat
quoted strings specially (e.g. PostgreSQL).
"""
if name in self.quote_cache:
return self.quote_cache[name]
if ((name in self.query.alias_map and name not in self.query.table_map) or
name in self.query.extra_select):
self.quote_cache[name] = name
return name
r = self.connection.ops.quote_name(name)
self.quote_cache[name] = r
return r
def as_sql(self, with_limits=True, with_col_aliases=False):
"""
Creates the SQL for this query. Returns the SQL string and list of
parameters.
If 'with_limits' is False, any limit/offset information is not included
in the query.
"""
if with_limits and self.query.low_mark == self.query.high_mark:
return '', ()
self.pre_sql_setup()
out_cols = self.get_columns(with_col_aliases)
ordering, ordering_group_by = self.get_ordering()
# This must come after 'select' and 'ordering' -- see docstring of
# get_from_clause() for details.
from_, f_params = self.get_from_clause()
qn = self.quote_name_unless_alias
where, w_params = self.query.where.as_sql(qn=qn, connection=self.connection)
having, h_params = self.query.having.as_sql(qn=qn, connection=self.connection)
params = []
for val in self.query.extra_select.itervalues():
params.extend(val[1])
result = ['SELECT']
if self.query.distinct:
result.append('DISTINCT')
result.append(', '.join(out_cols + self.query.ordering_aliases))
result.append('FROM')
result.extend(from_)
params.extend(f_params)
if where:
result.append('WHERE %s' % where)
params.extend(w_params)
grouping, gb_params = self.get_grouping()
if grouping:
if ordering:
# If the backend can't group by PK (i.e., any database
# other than MySQL), then any fields mentioned in the
# ordering clause needs to be in the group by clause.
if not self.connection.features.allows_group_by_pk:
for col, col_params in ordering_group_by:
if col not in grouping:
grouping.append(str(col))
gb_params.extend(col_params)
else:
ordering = self.connection.ops.force_no_ordering()
result.append('GROUP BY %s' % ', '.join(grouping))
params.extend(gb_params)
if having:
result.append('HAVING %s' % having)
params.extend(h_params)
if ordering:
result.append('ORDER BY %s' % ', '.join(ordering))
if with_limits:
if self.query.high_mark is not None:
result.append('LIMIT %d' % (self.query.high_mark - self.query.low_mark))
if self.query.low_mark:
if self.query.high_mark is None:
val = self.connection.ops.no_limit_value()
if val:
result.append('LIMIT %d' % val)
result.append('OFFSET %d' % self.query.low_mark)
return ' '.join(result), tuple(params)
def as_nested_sql(self):
"""
Perform the same functionality as the as_sql() method, returning an
SQL string and parameters. However, the alias prefixes are bumped
beforehand (in a copy -- the current query isn't changed), and any
ordering is removed if the query is unsliced.
Used when nesting this query inside another.
"""
obj = self.query.clone()
if obj.low_mark == 0 and obj.high_mark is None:
# If there is no slicing in use, then we can safely drop all ordering
obj.clear_ordering(True)
obj.bump_prefix()
return obj.get_compiler(connection=self.connection).as_sql()
def get_columns(self, with_aliases=False):
"""
Returns the list of columns to use in the select statement. If no
columns have been specified, returns all columns relating to fields in
the model.
If 'with_aliases' is true, any column names that are duplicated
(without the table names) are given unique aliases. This is needed in
some cases to avoid ambiguity with nested queries.
"""
qn = self.quote_name_unless_alias
qn2 = self.connection.ops.quote_name
result = ['(%s) AS %s' % (col[0], qn2(alias)) for alias, col in self.query.extra_select.iteritems()]
aliases = set(self.query.extra_select.keys())
if with_aliases:
col_aliases = aliases.copy()
else:
col_aliases = set()
if self.query.select:
only_load = self.deferred_to_columns()
for col in self.query.select:
if isinstance(col, (list, tuple)):
alias, column = col
table = self.query.alias_map[alias][TABLE_NAME]
if table in only_load and col not in only_load[table]:
continue
r = '%s.%s' % (qn(alias), qn(column))
if with_aliases:
if col[1] in col_aliases:
c_alias = 'Col%d' % len(col_aliases)
result.append('%s AS %s' % (r, c_alias))
aliases.add(c_alias)
col_aliases.add(c_alias)
else:
result.append('%s AS %s' % (r, qn2(col[1])))
aliases.add(r)
col_aliases.add(col[1])
else:
result.append(r)
aliases.add(r)
col_aliases.add(col[1])
else:
result.append(col.as_sql(qn, self.connection))
if hasattr(col, 'alias'):
aliases.add(col.alias)
col_aliases.add(col.alias)
elif self.query.default_cols:
cols, new_aliases = self.get_default_columns(with_aliases,
col_aliases)
result.extend(cols)
aliases.update(new_aliases)
max_name_length = self.connection.ops.max_name_length()
result.extend([
'%s%s' % (
aggregate.as_sql(qn, self.connection),
alias is not None
and ' AS %s' % qn(truncate_name(alias, max_name_length))
or ''
)
for alias, aggregate in self.query.aggregate_select.items()
])
for table, col in self.query.related_select_cols:
r = '%s.%s' % (qn(table), qn(col))
if with_aliases and col in col_aliases:
c_alias = 'Col%d' % len(col_aliases)
result.append('%s AS %s' % (r, c_alias))
aliases.add(c_alias)
col_aliases.add(c_alias)
else:
result.append(r)
aliases.add(r)
col_aliases.add(col)
self._select_aliases = aliases
return result
def get_default_columns(self, with_aliases=False, col_aliases=None,
start_alias=None, opts=None, as_pairs=False, local_only=False):
"""
Computes the default columns for selecting every field in the base
model. Will sometimes be called to pull in related models (e.g. via
select_related), in which case "opts" and "start_alias" will be given
to provide a starting point for the traversal.
Returns a list of strings, quoted appropriately for use in SQL
directly, as well as a set of aliases used in the select statement (if
'as_pairs' is True, returns a list of (alias, col_name) pairs instead
of strings as the first component and None as the second component).
"""
result = []
if opts is None:
opts = self.query.model._meta
qn = self.quote_name_unless_alias
qn2 = self.connection.ops.quote_name
aliases = set()
only_load = self.deferred_to_columns()
# Skip all proxy to the root proxied model
proxied_model = get_proxied_model(opts)
if start_alias:
seen = {None: start_alias}
for field, model in opts.get_fields_with_model():
if local_only and model is not None:
continue
if start_alias:
try:
alias = seen[model]
except KeyError:
if model is proxied_model:
alias = start_alias
else:
link_field = opts.get_ancestor_link(model)
alias = self.query.join((start_alias, model._meta.db_table,
link_field.column, model._meta.pk.column))
seen[model] = alias
else:
# If we're starting from the base model of the queryset, the
# aliases will have already been set up in pre_sql_setup(), so
# we can save time here.
alias = self.query.included_inherited_models[model]
table = self.query.alias_map[alias][TABLE_NAME]
if table in only_load and field.column not in only_load[table]:
continue
if as_pairs:
result.append((alias, field.column))
aliases.add(alias)
continue
if with_aliases and field.column in col_aliases:
c_alias = 'Col%d' % len(col_aliases)
result.append('%s.%s AS %s' % (qn(alias),
qn2(field.column), c_alias))
col_aliases.add(c_alias)
aliases.add(c_alias)
else:
r = '%s.%s' % (qn(alias), qn2(field.column))
result.append(r)
aliases.add(r)
if with_aliases:
col_aliases.add(field.column)
return result, aliases
def get_ordering(self):
"""
Returns a tuple containing a list representing the SQL elements in the
"order by" clause, and the list of SQL elements that need to be added
to the GROUP BY clause as a result of the ordering.
Also sets the ordering_aliases attribute on this instance to a list of
extra aliases needed in the select.
Determining the ordering SQL can change the tables we need to include,
so this should be run *before* get_from_clause().
"""
if self.query.extra_order_by:
ordering = self.query.extra_order_by
elif not self.query.default_ordering:
ordering = self.query.order_by
else:
ordering = self.query.order_by or self.query.model._meta.ordering
qn = self.quote_name_unless_alias
qn2 = self.connection.ops.quote_name
distinct = self.query.distinct
select_aliases = self._select_aliases
result = []
group_by = []
ordering_aliases = []
if self.query.standard_ordering:
asc, desc = ORDER_DIR['ASC']
else:
asc, desc = ORDER_DIR['DESC']
# It's possible, due to model inheritance, that normal usage might try
# to include the same field more than once in the ordering. We track
# the table/column pairs we use and discard any after the first use.
processed_pairs = set()
for field in ordering:
if field == '?':
result.append(self.connection.ops.random_function_sql())
continue
if isinstance(field, int):
if field < 0:
order = desc
field = -field
else:
order = asc
result.append('%s %s' % (field, order))
group_by.append((field, []))
continue
col, order = get_order_dir(field, asc)
if col in self.query.aggregate_select:
result.append('%s %s' % (qn(col), order))
continue
if '.' in field:
# This came in through an extra(order_by=...) addition. Pass it
# on verbatim.
table, col = col.split('.', 1)
if (table, col) not in processed_pairs:
elt = '%s.%s' % (qn(table), col)
processed_pairs.add((table, col))
if not distinct or elt in select_aliases:
result.append('%s %s' % (elt, order))
group_by.append((elt, []))
elif get_order_dir(field)[0] not in self.query.extra_select:
# 'col' is of the form 'field' or 'field1__field2' or
# '-field1__field2__field', etc.
for table, col, order in self.find_ordering_name(field,
self.query.model._meta, default_order=asc):
if (table, col) not in processed_pairs:
elt = '%s.%s' % (qn(table), qn2(col))
processed_pairs.add((table, col))
if distinct and elt not in select_aliases:
ordering_aliases.append(elt)
result.append('%s %s' % (elt, order))
group_by.append((elt, []))
else:
elt = qn2(col)
if distinct and col not in select_aliases:
ordering_aliases.append(elt)
result.append('%s %s' % (elt, order))
group_by.append(self.query.extra_select[col])
self.query.ordering_aliases = ordering_aliases
return result, group_by
def find_ordering_name(self, name, opts, alias=None, default_order='ASC',
already_seen=None):
"""
Returns the table alias (the name might be ambiguous, the alias will
not be) and column name for ordering by the given 'name' parameter.
The 'name' is of the form 'field1__field2__...__fieldN'.
"""
name, order = get_order_dir(name, default_order)
pieces = name.split(LOOKUP_SEP)
if not alias:
alias = self.query.get_initial_alias()
field, target, opts, joins, last, extra = self.query.setup_joins(pieces,
opts, alias, False)
alias = joins[-1]
col = target.column
if not field.rel:
# To avoid inadvertent trimming of a necessary alias, use the
# refcount to show that we are referencing a non-relation field on
# the model.
self.query.ref_alias(alias)
# Must use left outer joins for nullable fields and their relations.
self.query.promote_alias_chain(joins,
self.query.alias_map[joins[0]][JOIN_TYPE] == self.query.LOUTER)
# If we get to this point and the field is a relation to another model,
# append the default ordering for that model.
if field.rel and len(joins) > 1 and opts.ordering:
# Firstly, avoid infinite loops.
if not already_seen:
already_seen = set()
join_tuple = tuple([self.query.alias_map[j][TABLE_NAME] for j in joins])
if join_tuple in already_seen:
raise FieldError('Infinite loop caused by ordering.')
already_seen.add(join_tuple)
results = []
for item in opts.ordering:
results.extend(self.find_ordering_name(item, opts, alias,
order, already_seen))
return results
if alias:
# We have to do the same "final join" optimisation as in
# add_filter, since the final column might not otherwise be part of
# the select set (so we can't order on it).
while 1:
join = self.query.alias_map[alias]
if col != join[RHS_JOIN_COL]:
break
self.query.unref_alias(alias)
alias = join[LHS_ALIAS]
col = join[LHS_JOIN_COL]
return [(alias, col, order)]
def get_from_clause(self):
"""
Returns a list of strings that are joined together to go after the
"FROM" part of the query, as well as a list any extra parameters that
need to be included. Sub-classes, can override this to create a
from-clause via a "select".
This should only be called after any SQL construction methods that
might change the tables we need. This means the select columns and
ordering must be done first.
"""
result = []
qn = self.quote_name_unless_alias
qn2 = self.connection.ops.quote_name
first = True
for alias in self.query.tables:
if not self.query.alias_refcount[alias]:
continue
try:
name, alias, join_type, lhs, lhs_col, col, nullable = self.query.alias_map[alias]
except KeyError:
# Extra tables can end up in self.tables, but not in the
# alias_map if they aren't in a join. That's OK. We skip them.
continue
alias_str = (alias != name and ' %s' % alias or '')
if join_type and not first:
result.append('%s %s%s ON (%s.%s = %s.%s)'
% (join_type, qn(name), alias_str, qn(lhs),
qn2(lhs_col), qn(alias), qn2(col)))
else:
connector = not first and ', ' or ''
result.append('%s%s%s' % (connector, qn(name), alias_str))
first = False
for t in self.query.extra_tables:
alias, unused = self.query.table_alias(t)
# Only add the alias if it's not already present (the table_alias()
# calls increments the refcount, so an alias refcount of one means
# this is the only reference.
if alias not in self.query.alias_map or self.query.alias_refcount[alias] == 1:
connector = not first and ', ' or ''
result.append('%s%s' % (connector, qn(alias)))
first = False
return result, []
def get_grouping(self):
"""
Returns a tuple representing the SQL elements in the "group by" clause.
"""
qn = self.quote_name_unless_alias
result, params = [], []
if self.query.group_by is not None:
if (len(self.query.model._meta.fields) == len(self.query.select) and
self.connection.features.allows_group_by_pk):
self.query.group_by = [
(self.query.model._meta.db_table, self.query.model._meta.pk.column)
]
group_by = self.query.group_by or []
extra_selects = []
for extra_select, extra_params in self.query.extra_select.itervalues():
extra_selects.append(extra_select)
params.extend(extra_params)
cols = (group_by + self.query.select +
self.query.related_select_cols + extra_selects)
for col in cols:
if isinstance(col, (list, tuple)):
result.append('%s.%s' % (qn(col[0]), qn(col[1])))
elif hasattr(col, 'as_sql'):
result.append(col.as_sql(qn, self.connection))
else:
result.append('(%s)' % str(col))
return result, params
def fill_related_selections(self, opts=None, root_alias=None, cur_depth=1,
used=None, requested=None, restricted=None, nullable=None,
dupe_set=None, avoid_set=None):
"""
Fill in the information needed for a select_related query. The current
depth is measured as the number of connections away from the root model
(for example, cur_depth=1 means we are looking at models with direct
connections to the root model).
"""
if not restricted and self.query.max_depth and cur_depth > self.query.max_depth:
# We've recursed far enough; bail out.
return
if not opts:
opts = self.query.get_meta()
root_alias = self.query.get_initial_alias()
self.query.related_select_cols = []
self.query.related_select_fields = []
if not used:
used = set()
if dupe_set is None:
dupe_set = set()
if avoid_set is None:
avoid_set = set()
orig_dupe_set = dupe_set
# Setup for the case when only particular related fields should be
# included in the related selection.
if requested is None:
if isinstance(self.query.select_related, dict):
requested = self.query.select_related
restricted = True
else:
restricted = False
for f, model in opts.get_fields_with_model():
if not select_related_descend(f, restricted, requested):
continue
# The "avoid" set is aliases we want to avoid just for this
# particular branch of the recursion. They aren't permanently
# forbidden from reuse in the related selection tables (which is
# what "used" specifies).
avoid = avoid_set.copy()
dupe_set = orig_dupe_set.copy()
table = f.rel.to._meta.db_table
promote = nullable or f.null
if model:
int_opts = opts
alias = root_alias
alias_chain = []
for int_model in opts.get_base_chain(model):
# Proxy model have elements in base chain
# with no parents, assign the new options
# object and skip to the next base in that
# case
if not int_opts.parents[int_model]:
int_opts = int_model._meta
continue
lhs_col = int_opts.parents[int_model].column
dedupe = lhs_col in opts.duplicate_targets
if dedupe:
avoid.update(self.query.dupe_avoidance.get((id(opts), lhs_col),
()))
dupe_set.add((opts, lhs_col))
int_opts = int_model._meta
alias = self.query.join((alias, int_opts.db_table, lhs_col,
int_opts.pk.column), exclusions=used,
promote=promote)
alias_chain.append(alias)
for (dupe_opts, dupe_col) in dupe_set:
self.query.update_dupe_avoidance(dupe_opts, dupe_col, alias)
if self.query.alias_map[root_alias][JOIN_TYPE] == self.query.LOUTER:
self.query.promote_alias_chain(alias_chain, True)
else:
alias = root_alias
dedupe = f.column in opts.duplicate_targets
if dupe_set or dedupe:
avoid.update(self.query.dupe_avoidance.get((id(opts), f.column), ()))
if dedupe:
dupe_set.add((opts, f.column))
alias = self.query.join((alias, table, f.column,
f.rel.get_related_field().column),
exclusions=used.union(avoid), promote=promote)
used.add(alias)
columns, aliases = self.get_default_columns(start_alias=alias,
opts=f.rel.to._meta, as_pairs=True)
self.query.related_select_cols.extend(columns)
if self.query.alias_map[alias][JOIN_TYPE] == self.query.LOUTER:
self.query.promote_alias_chain(aliases, True)
self.query.related_select_fields.extend(f.rel.to._meta.fields)
if restricted:
next = requested.get(f.name, {})
else:
next = False
new_nullable = f.null or promote
for dupe_opts, dupe_col in dupe_set:
self.query.update_dupe_avoidance(dupe_opts, dupe_col, alias)
self.fill_related_selections(f.rel.to._meta, alias, cur_depth + 1,
used, next, restricted, new_nullable, dupe_set, avoid)
if restricted:
related_fields = [
(o.field, o.model)
for o in opts.get_all_related_objects()
if o.field.unique
]
for f, model in related_fields:
if not select_related_descend(f, restricted, requested, reverse=True):
continue
# The "avoid" set is aliases we want to avoid just for this
# particular branch of the recursion. They aren't permanently
# forbidden from reuse in the related selection tables (which is
# what "used" specifies).
avoid = avoid_set.copy()
dupe_set = orig_dupe_set.copy()
table = model._meta.db_table
int_opts = opts
alias = root_alias
alias_chain = []
chain = opts.get_base_chain(f.rel.to)
if chain is not None:
for int_model in chain:
# Proxy model have elements in base chain
# with no parents, assign the new options
# object and skip to the next base in that
# case
if not int_opts.parents[int_model]:
int_opts = int_model._meta
continue
lhs_col = int_opts.parents[int_model].column
dedupe = lhs_col in opts.duplicate_targets
if dedupe:
avoid.update((self.query.dupe_avoidance.get(id(opts), lhs_col),
()))
dupe_set.add((opts, lhs_col))
int_opts = int_model._meta
alias = self.query.join(
(alias, int_opts.db_table, lhs_col, int_opts.pk.column),
exclusions=used, promote=True, reuse=used
)
alias_chain.append(alias)
for dupe_opts, dupe_col in dupe_set:
self.query.update_dupe_avoidance(dupe_opts, dupe_col, alias)
dedupe = f.column in opts.duplicate_targets
if dupe_set or dedupe:
avoid.update(self.query.dupe_avoidance.get((id(opts), f.column), ()))
if dedupe:
dupe_set.add((opts, f.column))
alias = self.query.join(
(alias, table, f.rel.get_related_field().column, f.column),
exclusions=used.union(avoid),
promote=True
)
used.add(alias)
columns, aliases = self.get_default_columns(start_alias=alias,
opts=model._meta, as_pairs=True, local_only=True)
self.query.related_select_cols.extend(columns)
self.query.related_select_fields.extend(model._meta.fields)
next = requested.get(f.related_query_name(), {})
new_nullable = f.null or None
self.fill_related_selections(model._meta, table, cur_depth+1,
used, next, restricted, new_nullable)
def deferred_to_columns(self):
"""
Converts the self.deferred_loading data structure to mapping of table
names to sets of column names which are to be loaded. Returns the
dictionary.
"""
columns = {}
self.query.deferred_to_data(columns, self.query.deferred_to_columns_cb)
return columns
def results_iter(self):
"""
Returns an iterator over the results from executing this query.
"""
resolve_columns = hasattr(self, 'resolve_columns')
fields = None
has_aggregate_select = bool(self.query.aggregate_select)
for rows in self.execute_sql(MULTI):
for row in rows:
if resolve_columns:
if fields is None:
# We only set this up here because
# related_select_fields isn't populated until
# execute_sql() has been called.
if self.query.select_fields:
fields = self.query.select_fields + self.query.related_select_fields
else:
fields = self.query.model._meta.fields
# If the field was deferred, exclude it from being passed
# into `resolve_columns` because it wasn't selected.
only_load = self.deferred_to_columns()
if only_load:
db_table = self.query.model._meta.db_table
fields = [f for f in fields if db_table in only_load and
f.column in only_load[db_table]]
row = self.resolve_columns(row, fields)
if has_aggregate_select:
aggregate_start = len(self.query.extra_select.keys()) + len(self.query.select)
aggregate_end = aggregate_start + len(self.query.aggregate_select)
row = tuple(row[:aggregate_start]) + tuple([
self.query.resolve_aggregate(value, aggregate, self.connection)
for (alias, aggregate), value
in zip(self.query.aggregate_select.items(), row[aggregate_start:aggregate_end])
]) + tuple(row[aggregate_end:])
yield row
def execute_sql(self, result_type=MULTI):
"""
Run the query against the database and returns the result(s). The
return value is a single data item if result_type is SINGLE, or an
iterator over the results if the result_type is MULTI.
result_type is either MULTI (use fetchmany() to retrieve all rows),
SINGLE (only retrieve a single row), or None. In this last case, the
cursor is returned if any query is executed, since it's used by
subclasses such as InsertQuery). It's possible, however, that no query
is needed, as the filters describe an empty set. In that case, None is
returned, to avoid any unnecessary database interaction.
"""
try:
sql, params = self.as_sql()
if not sql:
raise EmptyResultSet
except EmptyResultSet:
if result_type == MULTI:
return empty_iter()
else:
return
cursor = self.connection.cursor()
cursor.execute(sql, params)
if not result_type:
return cursor
if result_type == SINGLE:
if self.query.ordering_aliases:
return cursor.fetchone()[:-len(self.query.ordering_aliases)]
return cursor.fetchone()
# The MULTI case.
if self.query.ordering_aliases:
result = order_modified_iter(cursor, len(self.query.ordering_aliases),
self.connection.features.empty_fetchmany_value)
else:
result = iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)),
self.connection.features.empty_fetchmany_value)
if not self.connection.features.can_use_chunked_reads:
# If we are using non-chunked reads, we return the same data
# structure as normally, but ensure it is all read into memory
# before going any further.
return list(result)
return result
class SQLInsertCompiler(SQLCompiler):
def placeholder(self, field, val):
if field is None:
# A field value of None means the value is raw.
return val
elif hasattr(field, 'get_placeholder'):
# Some fields (e.g. geo fields) need special munging before
# they can be inserted.
return field.get_placeholder(val, self.connection)
else:
# Return the common case for the placeholder
return '%s'
def as_sql(self):
# We don't need quote_name_unless_alias() here, since these are all
# going to be column names (so we can avoid the extra overhead).
qn = self.connection.ops.quote_name
opts = self.query.model._meta
result = ['INSERT INTO %s' % qn(opts.db_table)]
result.append('(%s)' % ', '.join([qn(c) for c in self.query.columns]))
values = [self.placeholder(*v) for v in self.query.values]
result.append('VALUES (%s)' % ', '.join(values))
params = self.query.params
if self.return_id and self.connection.features.can_return_id_from_insert:
col = "%s.%s" % (qn(opts.db_table), qn(opts.pk.column))
r_fmt, r_params = self.connection.ops.return_insert_id()
result.append(r_fmt % col)
params = params + r_params
return ' '.join(result), params
def execute_sql(self, return_id=False):
self.return_id = return_id
cursor = super(SQLInsertCompiler, self).execute_sql(None)
if not (return_id and cursor):
return
if self.connection.features.can_return_id_from_insert:
return self.connection.ops.fetch_returned_insert_id(cursor)
return self.connection.ops.last_insert_id(cursor,
self.query.model._meta.db_table, self.query.model._meta.pk.column)
class SQLDeleteCompiler(SQLCompiler):
def as_sql(self):
"""
Creates the SQL for this query. Returns the SQL string and list of
parameters.
"""
assert len(self.query.tables) == 1, \
"Can only delete from one table at a time."
qn = self.quote_name_unless_alias
result = ['DELETE FROM %s' % qn(self.query.tables[0])]
where, params = self.query.where.as_sql(qn=qn, connection=self.connection)
result.append('WHERE %s' % where)
return ' '.join(result), tuple(params)
class SQLUpdateCompiler(SQLCompiler):
def as_sql(self):
"""
Creates the SQL for this query. Returns the SQL string and list of
parameters.
"""
from django.db.models.base import Model
self.pre_sql_setup()
if not self.query.values:
return '', ()
table = self.query.tables[0]
qn = self.quote_name_unless_alias
result = ['UPDATE %s' % qn(table)]
result.append('SET')
values, update_params = [], []
for field, model, val in self.query.values:
if hasattr(val, 'prepare_database_save'):
val = val.prepare_database_save(field)
else:
val = field.get_db_prep_save(val, connection=self.connection)
# Getting the placeholder for the field.
if hasattr(field, 'get_placeholder'):
placeholder = field.get_placeholder(val, self.connection)
else:
placeholder = '%s'
if hasattr(val, 'evaluate'):
val = SQLEvaluator(val, self.query, allow_joins=False)
name = field.column
if hasattr(val, 'as_sql'):
sql, params = val.as_sql(qn, self.connection)
values.append('%s = %s' % (qn(name), sql))
update_params.extend(params)
elif val is not None:
values.append('%s = %s' % (qn(name), placeholder))
update_params.append(val)
else:
values.append('%s = NULL' % qn(name))
if not values:
return '', ()
result.append(', '.join(values))
where, params = self.query.where.as_sql(qn=qn, connection=self.connection)
if where:
result.append('WHERE %s' % where)
return ' '.join(result), tuple(update_params + params)
def execute_sql(self, result_type):
"""
Execute the specified update. Returns the number of rows affected by
the primary update query. The "primary update query" is the first
non-empty query that is executed. Row counts for any subsequent,
related queries are not available.
"""
cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
rows = cursor and cursor.rowcount or 0
is_empty = cursor is None
del cursor
for query in self.query.get_related_updates():
aux_rows = query.get_compiler(self.using).execute_sql(result_type)
if is_empty:
rows = aux_rows
is_empty = False
return rows
def pre_sql_setup(self):
"""
If the update depends on results from other tables, we need to do some
munging of the "where" conditions to match the format required for
(portable) SQL updates. That is done here.
Further, if we are going to be running multiple updates, we pull out
the id values to update at this point so that they don't change as a
result of the progressive updates.
"""
self.query.select_related = False
self.query.clear_ordering(True)
super(SQLUpdateCompiler, self).pre_sql_setup()
count = self.query.count_active_tables()
if not self.query.related_updates and count == 1:
return
# We need to use a sub-select in the where clause to filter on things
# from other tables.
query = self.query.clone(klass=Query)
query.bump_prefix()
query.extra = {}
query.select = []
query.add_fields([query.model._meta.pk.name])
must_pre_select = count > 1 and not self.connection.features.update_can_self_select
# Now we adjust the current query: reset the where clause and get rid
# of all the tables we don't need (since they're in the sub-select).
self.query.where = self.query.where_class()
if self.query.related_updates or must_pre_select:
# Either we're using the idents in multiple update queries (so
# don't want them to change), or the db backend doesn't support
# selecting from the updating table (e.g. MySQL).
idents = []
for rows in query.get_compiler(self.using).execute_sql(MULTI):
idents.extend([r[0] for r in rows])
self.query.add_filter(('pk__in', idents))
self.query.related_ids = idents
else:
# The fast path. Filters and updates in one query.
self.query.add_filter(('pk__in', query))
for alias in self.query.tables[1:]:
self.query.alias_refcount[alias] = 0
class SQLAggregateCompiler(SQLCompiler):
def as_sql(self, qn=None):
"""
Creates the SQL for this query. Returns the SQL string and list of
parameters.
"""
if qn is None:
qn = self.quote_name_unless_alias
sql = ('SELECT %s FROM (%s) subquery' % (
', '.join([
aggregate.as_sql(qn, self.connection)
for aggregate in self.query.aggregate_select.values()
]),
self.query.subquery)
)
params = self.query.sub_params
return (sql, params)
class SQLDateCompiler(SQLCompiler):
def results_iter(self):
"""
Returns an iterator over the results from executing this query.
"""
resolve_columns = hasattr(self, 'resolve_columns')
if resolve_columns:
from django.db.models.fields import DateTimeField
fields = [DateTimeField()]
else:
from django.db.backends.util import typecast_timestamp
needs_string_cast = self.connection.features.needs_datetime_string_cast
offset = len(self.query.extra_select)
for rows in self.execute_sql(MULTI):
for row in rows:
date = row[offset]
if resolve_columns:
date = self.resolve_columns(row, fields)[offset]
elif needs_string_cast:
date = typecast_timestamp(str(date))
yield date
def empty_iter():
"""
Returns an iterator containing no results.
"""
yield iter([]).next()
def order_modified_iter(cursor, trim, sentinel):
"""
Yields blocks of rows from a cursor. We use this iterator in the special
case when extra output columns have been added to support ordering
requirements. We must trim those extra columns before anything else can use
the results, since they're only needed to make the SQL valid.
"""
for rows in iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)),
sentinel):
yield [r[:-trim] for r in rows]
|
gpl-3.0
|
[
504,
1639,
14,
1018,
14,
3924,
492,
27691,
199,
504,
1639,
14,
697,
492,
6947,
199,
504,
1639,
14,
697,
14,
7765,
14,
1974,
492,
14547,
63,
354,
199,
504,
1639,
14,
697,
14,
992,
14,
3009,
14,
5559,
492,
627,
199,
504,
1639,
14,
697,
14,
992,
14,
3009,
14,
23004,
492,
9630,
21722,
199,
504,
1639,
14,
697,
14,
992,
14,
3009,
14,
15264,
492,
428,
49,
906,
637,
16530,
199,
504,
1639,
14,
697,
14,
992,
14,
3009,
14,
1131,
492,
664,
63,
8221,
5299,
63,
1238,
12,
664,
63,
1648,
63,
694,
12,
971,
1362,
3504,
63,
2407,
63,
18180,
12,
8133,
199,
199,
533,
5385,
9131,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1827,
12,
1950,
12,
1808,
304,
267,
291,
14,
1131,
275,
1827,
267,
291,
14,
2105,
275,
1950,
267,
291,
14,
4941,
275,
1808,
267,
291,
14,
3513,
63,
1637,
275,
1052,
339,
347,
876,
63,
3009,
63,
2758,
8,
277,
304,
267,
408,
267,
12078,
1263,
5784,
1021,
3272,
9939,
6791,
370,
27955,
5385,
14,
961,
267,
365,
367,
7645,
626,
883,
1133,
20513,
506,
4224,
315,
636,
826,
363,
2952,
781,
267,
5594,
440,
1172,
1006,
314,
10338,
315,
4192,
737,
626,
900,
14,
267,
408,
267,
340,
440,
291,
14,
1131,
14,
5987,
26,
288,
291,
14,
1131,
14,
904,
1332,
403,
12,
291,
14,
1131,
14,
1238,
423,
2024,
14,
697,
63,
1224,
12,
488,
12,
488,
430,
267,
340,
334,
1397,
291,
14,
1131,
14,
2416,
436,
291,
14,
1131,
14,
885,
63,
4574,
436,
440,
355,
291,
14,
1131,
14,
12409,
63,
17571,
63,
992,
304,
288,
291,
14,
1131,
14,
2758,
63,
17571,
63,
992,
342,
267,
340,
291,
14,
1131,
14,
2416,
63,
2407,
436,
440,
291,
14,
1131,
14,
2407,
63,
2416,
63,
4574,
26,
288,
291,
14,
4498,
63,
2407,
63,
5592,
83,
342,
339,
347,
6313,
63,
354,
63,
18447,
63,
3620,
8,
277,
12,
536,
304,
267,
408,
267,
437,
4975,
6818,
1950,
14,
1483,
14,
3513,
63,
354,
626,
3181,
1133,
6313,
5481,
267,
367,
1817,
1561,
14,
961,
23674,
8826,
543,
2005,
5385,
10982,
83,
626,
14312,
267,
10999,
3326,
1106,
1183,
334,
69,
14,
71,
14,
20175,
680,
267,
408,
267,
340,
536,
315,
291,
14,
3513,
63,
1637,
26,
288,
372,
291,
14,
3513,
63,
1637,
59,
354,
61,
267,
340,
3666,
354,
315,
291,
14,
1131,
14,
3620,
63,
1130,
436,
536,
440,
315,
291,
14,
1131,
14,
1224,
63,
1130,
9,
503,
355,
536,
315,
291,
14,
1131,
14,
2911,
63,
2416,
304,
288,
291,
14,
3513,
63,
1637,
59,
354,
61,
275,
536,
288,
372,
536,
267,
519,
275,
291,
14,
2105,
14,
1483,
14,
3513,
63,
354,
8,
354,
9,
267,
291,
14,
3513,
63,
1637,
59,
354,
61,
275,
519,
267,
372,
519,
339,
347,
465,
63,
3009,
8,
277,
12,
543,
63,
9368,
29,
549,
12,
543,
63,
761,
63,
8602,
29,
797,
304,
267,
408,
267,
10560,
314,
5385,
367,
642,
1827,
14,
1803,
314,
5385,
1059,
436,
769,
402,
267,
2633,
14,
398,
982,
283,
1045,
63,
9368,
7,
365,
756,
12,
1263,
2304,
15,
2743,
2556,
365,
440,
5120,
267,
315,
314,
1827,
14,
267,
408,
267,
340,
543,
63,
9368,
436,
291,
14,
1131,
14,
674,
63,
1657,
508,
291,
14,
1131,
14,
6260,
63,
1657,
26,
288,
372,
3260,
6248,
398,
291,
14,
657,
63,
3009,
63,
2758,
342,
267,
734,
63,
4574,
275,
291,
14,
362,
63,
3406,
8,
1045,
63,
761,
63,
8602,
9,
267,
7794,
12,
7794,
63,
923,
63,
991,
275,
291,
14,
362,
63,
7128,
342,
398,
327,
961,
1471,
11492,
2410,
283,
2416,
7,
436,
283,
7128,
7,
1553,
1937,
9214,
402,
267,
327,
664,
63,
504,
63,
8501,
342,
367,
2436,
14,
267,
687,
3131,
289,
63,
1162,
275,
291,
14,
362,
63,
504,
63,
8501,
342,
398,
18293,
275,
291,
14,
3513,
63,
354,
63,
18447,
63,
3620,
398,
2382,
12,
336,
63,
1162,
275,
291,
14,
1131,
14,
4509,
14,
305,
63,
3009,
8,
15156,
29,
15156,
12,
1950,
29,
277,
14,
2105,
9,
267,
9445,
12,
394,
63,
1162,
275,
291,
14,
1131,
14,
31569,
14,
305,
63,
3009,
8,
15156,
29,
15156,
12,
1950,
29,
277,
14,
2105,
9,
267,
1862,
275,
942,
267,
367,
1139,
315,
291,
14,
1131,
14,
2911,
63,
2416,
14,
13012,
837,
288,
1862,
14,
2880,
8,
637,
59,
17,
566,
398,
754,
275,
788,
4859,
418,
267,
340,
291,
14,
1131,
14,
12926,
26,
288,
754,
14,
740,
360,
13783,
28437,
358,
267,
754,
14,
740,
5102,
1987,
904,
8,
548,
63,
4574,
435,
291,
14,
1131,
14,
7128,
63,
8602,
430,
398,
754,
14,
740,
360,
12491,
358,
267,
754,
14,
2880,
8,
504,
4602,
267,
1862,
14,
2880,
8,
70,
63,
1162,
9,
398,
340,
2382,
26,
288,
754,
14,
740,
360,
17688,
450,
83,
7,
450,
2382,
9,
288,
1862,
14,
2880,
8,
87,
63,
1162,
9,
398,
17786,
12,
25411,
63,
1162,
275,
291,
14,
362,
63,
22390,
342,
267,
340,
17786,
26,
288,
340,
7794,
26,
355,
327,
982,
314,
4865,
883,
1133,
1572,
701,
18368,
334,
73,
14,
69,
2020,
1263,
3050,
355,
327,
1163,
2419,
11200,
395,
2066,
1263,
1504,
26239,
315,
314,
355,
327,
7794,
8502,
4839,
370,
506,
315,
314,
1572,
701,
8502,
14,
355,
340,
440,
291,
14,
2105,
14,
3179,
14,
24077,
63,
923,
63,
991,
63,
2051,
26,
490,
367,
1048,
12,
1048,
63,
1162,
315,
7794,
63,
923,
63,
991,
26,
717,
340,
1048,
440,
315,
17786,
26,
1169,
17786,
14,
740,
8,
495,
8,
761,
430,
1169,
25411,
63,
1162,
14,
2880,
8,
761,
63,
1162,
9,
288,
587,
26,
355,
7794,
275,
291,
14,
2105,
14,
1483,
14,
3990,
63,
889,
63,
7128,
342,
288,
754,
14,
740,
360,
7823,
6515,
450,
83,
7,
450,
1656,
1987,
904,
8,
22390,
430,
288,
1862,
14,
2880,
8,
4908,
63,
1162,
9,
398,
340,
9445,
26,
288,
754,
14,
740,
360,
40,
6087,
1206,
450,
83,
7,
450,
9445,
9,
288,
1862,
14,
2880,
8,
72
] |
[
1639,
14,
1018,
14,
3924,
492,
27691,
199,
504,
1639,
14,
697,
492,
6947,
199,
504,
1639,
14,
697,
14,
7765,
14,
1974,
492,
14547,
63,
354,
199,
504,
1639,
14,
697,
14,
992,
14,
3009,
14,
5559,
492,
627,
199,
504,
1639,
14,
697,
14,
992,
14,
3009,
14,
23004,
492,
9630,
21722,
199,
504,
1639,
14,
697,
14,
992,
14,
3009,
14,
15264,
492,
428,
49,
906,
637,
16530,
199,
504,
1639,
14,
697,
14,
992,
14,
3009,
14,
1131,
492,
664,
63,
8221,
5299,
63,
1238,
12,
664,
63,
1648,
63,
694,
12,
971,
1362,
3504,
63,
2407,
63,
18180,
12,
8133,
199,
199,
533,
5385,
9131,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1827,
12,
1950,
12,
1808,
304,
267,
291,
14,
1131,
275,
1827,
267,
291,
14,
2105,
275,
1950,
267,
291,
14,
4941,
275,
1808,
267,
291,
14,
3513,
63,
1637,
275,
1052,
339,
347,
876,
63,
3009,
63,
2758,
8,
277,
304,
267,
408,
267,
12078,
1263,
5784,
1021,
3272,
9939,
6791,
370,
27955,
5385,
14,
961,
267,
365,
367,
7645,
626,
883,
1133,
20513,
506,
4224,
315,
636,
826,
363,
2952,
781,
267,
5594,
440,
1172,
1006,
314,
10338,
315,
4192,
737,
626,
900,
14,
267,
408,
267,
340,
440,
291,
14,
1131,
14,
5987,
26,
288,
291,
14,
1131,
14,
904,
1332,
403,
12,
291,
14,
1131,
14,
1238,
423,
2024,
14,
697,
63,
1224,
12,
488,
12,
488,
430,
267,
340,
334,
1397,
291,
14,
1131,
14,
2416,
436,
291,
14,
1131,
14,
885,
63,
4574,
436,
440,
355,
291,
14,
1131,
14,
12409,
63,
17571,
63,
992,
304,
288,
291,
14,
1131,
14,
2758,
63,
17571,
63,
992,
342,
267,
340,
291,
14,
1131,
14,
2416,
63,
2407,
436,
440,
291,
14,
1131,
14,
2407,
63,
2416,
63,
4574,
26,
288,
291,
14,
4498,
63,
2407,
63,
5592,
83,
342,
339,
347,
6313,
63,
354,
63,
18447,
63,
3620,
8,
277,
12,
536,
304,
267,
408,
267,
437,
4975,
6818,
1950,
14,
1483,
14,
3513,
63,
354,
626,
3181,
1133,
6313,
5481,
267,
367,
1817,
1561,
14,
961,
23674,
8826,
543,
2005,
5385,
10982,
83,
626,
14312,
267,
10999,
3326,
1106,
1183,
334,
69,
14,
71,
14,
20175,
680,
267,
408,
267,
340,
536,
315,
291,
14,
3513,
63,
1637,
26,
288,
372,
291,
14,
3513,
63,
1637,
59,
354,
61,
267,
340,
3666,
354,
315,
291,
14,
1131,
14,
3620,
63,
1130,
436,
536,
440,
315,
291,
14,
1131,
14,
1224,
63,
1130,
9,
503,
355,
536,
315,
291,
14,
1131,
14,
2911,
63,
2416,
304,
288,
291,
14,
3513,
63,
1637,
59,
354,
61,
275,
536,
288,
372,
536,
267,
519,
275,
291,
14,
2105,
14,
1483,
14,
3513,
63,
354,
8,
354,
9,
267,
291,
14,
3513,
63,
1637,
59,
354,
61,
275,
519,
267,
372,
519,
339,
347,
465,
63,
3009,
8,
277,
12,
543,
63,
9368,
29,
549,
12,
543,
63,
761,
63,
8602,
29,
797,
304,
267,
408,
267,
10560,
314,
5385,
367,
642,
1827,
14,
1803,
314,
5385,
1059,
436,
769,
402,
267,
2633,
14,
398,
982,
283,
1045,
63,
9368,
7,
365,
756,
12,
1263,
2304,
15,
2743,
2556,
365,
440,
5120,
267,
315,
314,
1827,
14,
267,
408,
267,
340,
543,
63,
9368,
436,
291,
14,
1131,
14,
674,
63,
1657,
508,
291,
14,
1131,
14,
6260,
63,
1657,
26,
288,
372,
3260,
6248,
398,
291,
14,
657,
63,
3009,
63,
2758,
342,
267,
734,
63,
4574,
275,
291,
14,
362,
63,
3406,
8,
1045,
63,
761,
63,
8602,
9,
267,
7794,
12,
7794,
63,
923,
63,
991,
275,
291,
14,
362,
63,
7128,
342,
398,
327,
961,
1471,
11492,
2410,
283,
2416,
7,
436,
283,
7128,
7,
1553,
1937,
9214,
402,
267,
327,
664,
63,
504,
63,
8501,
342,
367,
2436,
14,
267,
687,
3131,
289,
63,
1162,
275,
291,
14,
362,
63,
504,
63,
8501,
342,
398,
18293,
275,
291,
14,
3513,
63,
354,
63,
18447,
63,
3620,
398,
2382,
12,
336,
63,
1162,
275,
291,
14,
1131,
14,
4509,
14,
305,
63,
3009,
8,
15156,
29,
15156,
12,
1950,
29,
277,
14,
2105,
9,
267,
9445,
12,
394,
63,
1162,
275,
291,
14,
1131,
14,
31569,
14,
305,
63,
3009,
8,
15156,
29,
15156,
12,
1950,
29,
277,
14,
2105,
9,
267,
1862,
275,
942,
267,
367,
1139,
315,
291,
14,
1131,
14,
2911,
63,
2416,
14,
13012,
837,
288,
1862,
14,
2880,
8,
637,
59,
17,
566,
398,
754,
275,
788,
4859,
418,
267,
340,
291,
14,
1131,
14,
12926,
26,
288,
754,
14,
740,
360,
13783,
28437,
358,
267,
754,
14,
740,
5102,
1987,
904,
8,
548,
63,
4574,
435,
291,
14,
1131,
14,
7128,
63,
8602,
430,
398,
754,
14,
740,
360,
12491,
358,
267,
754,
14,
2880,
8,
504,
4602,
267,
1862,
14,
2880,
8,
70,
63,
1162,
9,
398,
340,
2382,
26,
288,
754,
14,
740,
360,
17688,
450,
83,
7,
450,
2382,
9,
288,
1862,
14,
2880,
8,
87,
63,
1162,
9,
398,
17786,
12,
25411,
63,
1162,
275,
291,
14,
362,
63,
22390,
342,
267,
340,
17786,
26,
288,
340,
7794,
26,
355,
327,
982,
314,
4865,
883,
1133,
1572,
701,
18368,
334,
73,
14,
69,
2020,
1263,
3050,
355,
327,
1163,
2419,
11200,
395,
2066,
1263,
1504,
26239,
315,
314,
355,
327,
7794,
8502,
4839,
370,
506,
315,
314,
1572,
701,
8502,
14,
355,
340,
440,
291,
14,
2105,
14,
3179,
14,
24077,
63,
923,
63,
991,
63,
2051,
26,
490,
367,
1048,
12,
1048,
63,
1162,
315,
7794,
63,
923,
63,
991,
26,
717,
340,
1048,
440,
315,
17786,
26,
1169,
17786,
14,
740,
8,
495,
8,
761,
430,
1169,
25411,
63,
1162,
14,
2880,
8,
761,
63,
1162,
9,
288,
587,
26,
355,
7794,
275,
291,
14,
2105,
14,
1483,
14,
3990,
63,
889,
63,
7128,
342,
288,
754,
14,
740,
360,
7823,
6515,
450,
83,
7,
450,
1656,
1987,
904,
8,
22390,
430,
288,
1862,
14,
2880,
8,
4908,
63,
1162,
9,
398,
340,
9445,
26,
288,
754,
14,
740,
360,
40,
6087,
1206,
450,
83,
7,
450,
9445,
9,
288,
1862,
14,
2880,
8,
72,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wisechengyi/pants
|
contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_compile_integration.py
|
2
|
2798
|
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
import os
from pants.testutil.file_test_util import contains_exact_files
from pants.testutil.pants_run_integration_test import PantsRunIntegrationTest
from pants.testutil.subsystem.util import global_subsystem_instance
from pants.contrib.go.subsystems.go_distribution import GoDistribution
class GoCompileIntegrationTest(PantsRunIntegrationTest):
def test_go_compile_simple(self):
with self.temporary_workdir() as workdir:
args = ["compile", "contrib/go/examples/src/go/libA"]
pants_run = self.run_pants_with_workdir(args, workdir)
self.assert_success(pants_run)
go_dist = global_subsystem_instance(GoDistribution)
goos = go_dist.create_go_cmd("env", args=["GOOS"]).check_output().decode().strip()
goarch = go_dist.create_go_cmd("env", args=["GOARCH"]).check_output().decode().strip()
expected_files = set(
"contrib.go.examples.src.go.{libname}.{libname}/"
"pkg/{goos}_{goarch}/{libname}.a".format(libname=libname, goos=goos, goarch=goarch)
for libname in ("libA", "libB", "libC", "libD", "libE")
)
self.assertTrue(
contains_exact_files(
os.path.join(workdir, "compile", "go"), expected_files, ignore_links=True
)
)
def test_go_compile_cgo(self):
args = ["compile", "contrib/go/examples/src/go/cgo"]
pants_run = self.run_pants(args)
self.assert_success(pants_run)
def test_go_compile_with_remote_deps(self):
args = ["compile", "contrib/go/examples/src/go/server"]
pants_run = self.run_pants(args)
self.assert_success(pants_run)
def test_go_compile_double_quoted_build_flags(self):
args = [
"compile",
"contrib/go/examples/src/go/server",
'--compile-go-build-flags="--ldflags \'-extldflags "-static"\'"',
]
pants_run = self.run_pants(args)
self.assert_success(pants_run)
def test_go_compile_single_quoted_build_flags(self):
args = [
"compile",
"contrib/go/examples/src/go/server",
"--compile-go-build-flags='--ldflags '-extldflags \"-static\"''",
]
pants_run = self.run_pants(args)
self.assert_success(pants_run)
def test_go_compile_adjacent_single_double_quotes_build_flags(self):
args = [
"compile",
"contrib/go/examples/src/go/server",
"--compile-go-build-flags='-v -tags \"netgo\"'",
]
pants_run = self.run_pants(args)
self.assert_success(pants_run)
|
apache-2.0
|
[
3,
1898,
6900,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
646,
747,
199,
199,
504,
18081,
14,
396,
1974,
14,
493,
63,
396,
63,
1974,
492,
3509,
63,
7327,
63,
1725,
199,
504,
18081,
14,
396,
1974,
14,
21970,
63,
1065,
63,
15092,
63,
396,
492,
510,
2285,
2540,
20405,
774,
199,
504,
18081,
14,
396,
1974,
14,
954,
2253,
14,
1974,
492,
2288,
63,
954,
2253,
63,
842,
199,
199,
504,
18081,
14,
2828,
14,
1939,
14,
954,
19135,
14,
1939,
63,
4972,
492,
3971,
8580,
421,
199,
533,
3971,
12626,
20405,
774,
8,
27565,
2540,
20405,
774,
304,
272,
347,
511,
63,
1939,
63,
2014,
63,
4129,
8,
277,
304,
267,
543,
291,
14,
13555,
63,
19132,
342,
465,
1736,
694,
26,
288,
1249,
275,
2097,
2014,
401,
298,
2828,
15,
1939,
15,
8589,
15,
2164,
15,
1939,
15,
773,
33,
937,
288,
18081,
63,
1065,
275,
291,
14,
1065,
63,
21970,
63,
1045,
63,
19132,
8,
589,
12,
1736,
694,
9,
288,
291,
14,
479,
63,
3742,
8,
21970,
63,
1065,
9,
288,
2621,
63,
2686,
275,
2288,
63,
954,
2253,
63,
842,
8,
7250,
8580,
9,
288,
2621,
736,
275,
2621,
63,
2686,
14,
981,
63,
1939,
63,
1760,
480,
1813,
401,
1249,
6270,
13160,
3100,
29126,
1074,
63,
1199,
1252,
2708,
1252,
1913,
342,
288,
2621,
1047,
275,
2621,
63,
2686,
14,
981,
63,
1939,
63,
1760,
480,
1813,
401,
1249,
6270,
13160,
7762,
29126,
1074,
63,
1199,
1252,
2708,
1252,
1913,
342,
288,
1420,
63,
1725,
275,
663,
8,
355,
298,
2828,
14,
1939,
14,
8589,
14,
2164,
14,
1939,
23379,
773,
354,
26944,
773,
354,
5995,
2,
355,
298,
4600,
5321,
1939,
736,
26738,
1939,
1047,
16152,
773,
354,
5565,
65,
1674,
908,
8,
773,
354,
29,
773,
354,
12,
2621,
736,
29,
1939,
736,
12,
2621,
1047,
29,
1939,
1047,
9,
355,
367,
1973,
354,
315,
1689,
773,
33,
401,
298,
773,
34,
401,
298,
773,
35,
401,
298,
773,
36,
401,
298,
773,
37,
531,
288,
776,
288,
291,
14,
1815,
8,
355,
3509,
63,
7327,
63,
1725,
8,
490,
747,
14,
515,
14,
904,
8,
19132,
12,
298,
2014,
401,
298,
1939,
1288,
1420,
63,
1725,
12,
3686,
63,
4614,
29,
549,
355,
776,
288,
776,
339,
347,
511,
63,
1939,
63,
2014,
63,
67,
1939,
8,
277,
304,
267,
1249,
275,
2097,
2014,
401,
298,
2828,
15,
1939,
15,
8589,
15,
2164,
15,
1939,
15,
67,
1939,
937,
267,
18081,
63,
1065,
275,
291,
14,
1065,
63,
21970,
8,
589,
9,
267,
291,
14,
479,
63,
3742,
8,
21970,
63,
1065,
9,
339,
347,
511,
63,
1939,
63,
2014,
63,
1045,
63,
3846,
63,
5846,
8,
277,
304,
267,
1249,
275,
2097,
2014,
401,
298,
2828,
15,
1939,
15,
8589,
15,
2164,
15,
1939,
15,
1000,
937,
267,
18081,
63,
1065,
275,
291,
14,
1065,
63,
21970,
8,
589,
9,
267,
291,
14,
479,
63,
3742,
8,
21970,
63,
1065,
9,
339,
347,
511,
63,
1939,
63,
2014,
63,
3157,
63,
9888,
63,
1506,
63,
2469,
8,
277,
304,
267,
1249,
275,
359,
288,
298,
2014,
401,
288,
298,
2828,
15,
1939,
15,
8589,
15,
2164,
15,
1939,
15,
1000,
401,
288,
2850,
2014,
13,
1939,
13,
1506,
13,
2469,
28953,
25601,
8891,
13,
832,
25601,
3905,
1986,
3212,
24487,
267,
1622,
267,
18081,
63,
1065,
275,
291,
14,
1065,
63,
21970,
8,
589,
9,
267,
291,
14,
479,
63,
3742,
8,
21970,
63,
1065,
9,
339,
347,
511,
63,
1939,
63,
2014,
63,
4780,
63,
9888,
63,
1506,
63,
2469,
8,
277,
304,
267,
1249,
275,
359,
288,
298,
2014,
401,
288,
298,
2828,
15,
1939,
15,
8589,
15,
2164,
15,
1939,
15,
1000,
401,
288,
4320,
2014,
13,
1939,
13,
1506,
13,
2469,
23791,
25601,
2475,
832,
25601,
8441,
13,
1986,
4451,
891,
401,
267,
1622,
267,
18081,
63,
1065,
275,
291,
14,
1065,
63,
21970,
8,
589,
9,
267,
291,
14,
479,
63,
3742,
8,
21970,
63,
1065,
9,
339,
347,
511,
63,
1939,
63,
2014,
63,
350,
17235,
63,
4780,
63,
3157,
63,
14005,
63,
1506,
63,
2469,
8,
277,
304,
267,
1249,
275,
359,
288,
298,
2014,
401,
288,
298,
2828,
15,
1939,
15,
8589,
15,
2164,
15,
1939,
15,
1000,
401,
288,
4320,
2014,
13,
1939,
13,
1506,
13,
2469,
18274,
86,
446,
2969,
8441,
846,
1939,
4451,
4662,
267,
1622,
267,
18081,
63,
1065,
275,
291,
14,
1065,
63,
21970,
8,
589,
9,
267,
291,
14,
479,
63,
3742,
8,
21970,
63,
1065,
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
] |
[
1898,
6900,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
646,
747,
199,
199,
504,
18081,
14,
396,
1974,
14,
493,
63,
396,
63,
1974,
492,
3509,
63,
7327,
63,
1725,
199,
504,
18081,
14,
396,
1974,
14,
21970,
63,
1065,
63,
15092,
63,
396,
492,
510,
2285,
2540,
20405,
774,
199,
504,
18081,
14,
396,
1974,
14,
954,
2253,
14,
1974,
492,
2288,
63,
954,
2253,
63,
842,
199,
199,
504,
18081,
14,
2828,
14,
1939,
14,
954,
19135,
14,
1939,
63,
4972,
492,
3971,
8580,
421,
199,
533,
3971,
12626,
20405,
774,
8,
27565,
2540,
20405,
774,
304,
272,
347,
511,
63,
1939,
63,
2014,
63,
4129,
8,
277,
304,
267,
543,
291,
14,
13555,
63,
19132,
342,
465,
1736,
694,
26,
288,
1249,
275,
2097,
2014,
401,
298,
2828,
15,
1939,
15,
8589,
15,
2164,
15,
1939,
15,
773,
33,
937,
288,
18081,
63,
1065,
275,
291,
14,
1065,
63,
21970,
63,
1045,
63,
19132,
8,
589,
12,
1736,
694,
9,
288,
291,
14,
479,
63,
3742,
8,
21970,
63,
1065,
9,
288,
2621,
63,
2686,
275,
2288,
63,
954,
2253,
63,
842,
8,
7250,
8580,
9,
288,
2621,
736,
275,
2621,
63,
2686,
14,
981,
63,
1939,
63,
1760,
480,
1813,
401,
1249,
6270,
13160,
3100,
29126,
1074,
63,
1199,
1252,
2708,
1252,
1913,
342,
288,
2621,
1047,
275,
2621,
63,
2686,
14,
981,
63,
1939,
63,
1760,
480,
1813,
401,
1249,
6270,
13160,
7762,
29126,
1074,
63,
1199,
1252,
2708,
1252,
1913,
342,
288,
1420,
63,
1725,
275,
663,
8,
355,
298,
2828,
14,
1939,
14,
8589,
14,
2164,
14,
1939,
23379,
773,
354,
26944,
773,
354,
5995,
2,
355,
298,
4600,
5321,
1939,
736,
26738,
1939,
1047,
16152,
773,
354,
5565,
65,
1674,
908,
8,
773,
354,
29,
773,
354,
12,
2621,
736,
29,
1939,
736,
12,
2621,
1047,
29,
1939,
1047,
9,
355,
367,
1973,
354,
315,
1689,
773,
33,
401,
298,
773,
34,
401,
298,
773,
35,
401,
298,
773,
36,
401,
298,
773,
37,
531,
288,
776,
288,
291,
14,
1815,
8,
355,
3509,
63,
7327,
63,
1725,
8,
490,
747,
14,
515,
14,
904,
8,
19132,
12,
298,
2014,
401,
298,
1939,
1288,
1420,
63,
1725,
12,
3686,
63,
4614,
29,
549,
355,
776,
288,
776,
339,
347,
511,
63,
1939,
63,
2014,
63,
67,
1939,
8,
277,
304,
267,
1249,
275,
2097,
2014,
401,
298,
2828,
15,
1939,
15,
8589,
15,
2164,
15,
1939,
15,
67,
1939,
937,
267,
18081,
63,
1065,
275,
291,
14,
1065,
63,
21970,
8,
589,
9,
267,
291,
14,
479,
63,
3742,
8,
21970,
63,
1065,
9,
339,
347,
511,
63,
1939,
63,
2014,
63,
1045,
63,
3846,
63,
5846,
8,
277,
304,
267,
1249,
275,
2097,
2014,
401,
298,
2828,
15,
1939,
15,
8589,
15,
2164,
15,
1939,
15,
1000,
937,
267,
18081,
63,
1065,
275,
291,
14,
1065,
63,
21970,
8,
589,
9,
267,
291,
14,
479,
63,
3742,
8,
21970,
63,
1065,
9,
339,
347,
511,
63,
1939,
63,
2014,
63,
3157,
63,
9888,
63,
1506,
63,
2469,
8,
277,
304,
267,
1249,
275,
359,
288,
298,
2014,
401,
288,
298,
2828,
15,
1939,
15,
8589,
15,
2164,
15,
1939,
15,
1000,
401,
288,
2850,
2014,
13,
1939,
13,
1506,
13,
2469,
28953,
25601,
8891,
13,
832,
25601,
3905,
1986,
3212,
24487,
267,
1622,
267,
18081,
63,
1065,
275,
291,
14,
1065,
63,
21970,
8,
589,
9,
267,
291,
14,
479,
63,
3742,
8,
21970,
63,
1065,
9,
339,
347,
511,
63,
1939,
63,
2014,
63,
4780,
63,
9888,
63,
1506,
63,
2469,
8,
277,
304,
267,
1249,
275,
359,
288,
298,
2014,
401,
288,
298,
2828,
15,
1939,
15,
8589,
15,
2164,
15,
1939,
15,
1000,
401,
288,
4320,
2014,
13,
1939,
13,
1506,
13,
2469,
23791,
25601,
2475,
832,
25601,
8441,
13,
1986,
4451,
891,
401,
267,
1622,
267,
18081,
63,
1065,
275,
291,
14,
1065,
63,
21970,
8,
589,
9,
267,
291,
14,
479,
63,
3742,
8,
21970,
63,
1065,
9,
339,
347,
511,
63,
1939,
63,
2014,
63,
350,
17235,
63,
4780,
63,
3157,
63,
14005,
63,
1506,
63,
2469,
8,
277,
304,
267,
1249,
275,
359,
288,
298,
2014,
401,
288,
298,
2828,
15,
1939,
15,
8589,
15,
2164,
15,
1939,
15,
1000,
401,
288,
4320,
2014,
13,
1939,
13,
1506,
13,
2469,
18274,
86,
446,
2969,
8441,
846,
1939,
4451,
4662,
267,
1622,
267,
18081,
63,
1065,
275,
291,
14,
1065,
63,
21970,
8,
589,
9,
267,
291,
14,
479,
63,
3742,
8,
21970,
63,
1065,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ojengwa/oh-mainline
|
vendor/packages/PyYaml/tests/lib/test_resolver.py
|
60
|
3300
|
import yaml
import pprint
def test_implicit_resolver(data_filename, detect_filename, verbose=False):
correct_tag = None
node = None
try:
correct_tag = open(detect_filename, 'rb').read().strip()
node = yaml.compose(open(data_filename, 'rb'))
assert isinstance(node, yaml.SequenceNode), node
for scalar in node.value:
assert isinstance(scalar, yaml.ScalarNode), scalar
assert scalar.tag == correct_tag, (scalar.tag, correct_tag)
finally:
if verbose:
print "CORRECT TAG:", correct_tag
if hasattr(node, 'value'):
print "CHILDREN:"
pprint.pprint(node.value)
test_implicit_resolver.unittest = ['.data', '.detect']
def _make_path_loader_and_dumper():
global MyLoader, MyDumper
class MyLoader(yaml.Loader):
pass
class MyDumper(yaml.Dumper):
pass
yaml.add_path_resolver(u'!root', [],
Loader=MyLoader, Dumper=MyDumper)
yaml.add_path_resolver(u'!root/scalar', [], str,
Loader=MyLoader, Dumper=MyDumper)
yaml.add_path_resolver(u'!root/key11/key12/*', ['key11', 'key12'],
Loader=MyLoader, Dumper=MyDumper)
yaml.add_path_resolver(u'!root/key21/1/*', ['key21', 1],
Loader=MyLoader, Dumper=MyDumper)
yaml.add_path_resolver(u'!root/key31/*/*/key14/map', ['key31', None, None, 'key14'], dict,
Loader=MyLoader, Dumper=MyDumper)
return MyLoader, MyDumper
def _convert_node(node):
if isinstance(node, yaml.ScalarNode):
return (node.tag, node.value)
elif isinstance(node, yaml.SequenceNode):
value = []
for item in node.value:
value.append(_convert_node(item))
return (node.tag, value)
elif isinstance(node, yaml.MappingNode):
value = []
for key, item in node.value:
value.append((_convert_node(key), _convert_node(item)))
return (node.tag, value)
def test_path_resolver_loader(data_filename, path_filename, verbose=False):
_make_path_loader_and_dumper()
nodes1 = list(yaml.compose_all(open(data_filename, 'rb').read(), Loader=MyLoader))
nodes2 = list(yaml.compose_all(open(path_filename, 'rb').read()))
try:
for node1, node2 in zip(nodes1, nodes2):
data1 = _convert_node(node1)
data2 = _convert_node(node2)
assert data1 == data2, (data1, data2)
finally:
if verbose:
print yaml.serialize_all(nodes1)
test_path_resolver_loader.unittest = ['.data', '.path']
def test_path_resolver_dumper(data_filename, path_filename, verbose=False):
_make_path_loader_and_dumper()
for filename in [data_filename, path_filename]:
output = yaml.serialize_all(yaml.compose_all(open(filename, 'rb')), Dumper=MyDumper)
if verbose:
print output
nodes1 = yaml.compose_all(output)
nodes2 = yaml.compose_all(open(data_filename, 'rb'))
for node1, node2 in zip(nodes1, nodes2):
data1 = _convert_node(node1)
data2 = _convert_node(node2)
assert data1 == data2, (data1, data2)
test_path_resolver_dumper.unittest = ['.data', '.path']
if __name__ == '__main__':
import test_appliance
test_appliance.run(globals())
|
agpl-3.0
|
[
199,
646,
8864,
199,
646,
10933,
199,
199,
318,
511,
63,
11886,
63,
7717,
8,
576,
63,
1501,
12,
9696,
63,
1501,
12,
3376,
29,
797,
304,
272,
3211,
63,
1450,
275,
488,
272,
1031,
275,
488,
272,
862,
26,
267,
3211,
63,
1450,
275,
1551,
8,
13552,
63,
1501,
12,
283,
4848,
1959,
739,
1252,
1913,
342,
267,
1031,
275,
8864,
14,
12607,
8,
1490,
8,
576,
63,
1501,
12,
283,
4848,
1333,
267,
702,
1228,
8,
932,
12,
8864,
14,
5826,
1716,
395,
1031,
267,
367,
6917,
315,
1031,
14,
585,
26,
288,
702,
1228,
8,
7033,
12,
8864,
14,
13090,
1716,
395,
6917,
288,
702,
6917,
14,
1450,
508,
3211,
63,
1450,
12,
334,
7033,
14,
1450,
12,
3211,
63,
1450,
9,
272,
3753,
26,
267,
340,
3376,
26,
288,
870,
298,
31704,
18395,
6783,
3211,
63,
1450,
288,
340,
2688,
8,
932,
12,
283,
585,
735,
355,
870,
298,
1244,
1193,
4564,
742,
5424,
355,
10933,
14,
15380,
8,
932,
14,
585,
9,
199,
199,
396,
63,
11886,
63,
7717,
14,
2796,
275,
18953,
576,
297,
1987,
13552,
418,
199,
199,
318,
485,
1875,
63,
515,
63,
3422,
63,
460,
63,
2724,
281,
837,
272,
2288,
4932,
5455,
12,
4932,
28593,
339,
1021,
4932,
5455,
8,
5963,
14,
5455,
304,
267,
986,
272,
1021,
4932,
28593,
8,
5963,
14,
28593,
304,
267,
986,
339,
8864,
14,
525,
63,
515,
63,
7717,
8,
85,
7,
1,
1231,
297,
990,
288,
22865,
29,
5713,
5455,
12,
19460,
281,
29,
5713,
28593,
9,
272,
8864,
14,
525,
63,
515,
63,
7717,
8,
85,
7,
1,
1231,
15,
7033,
297,
990,
620,
12,
288,
22865,
29,
5713,
5455,
12,
19460,
281,
29,
5713,
28593,
9,
272,
8864,
14,
525,
63,
515,
63,
7717,
8,
85,
7,
1,
1231,
15,
498,
845,
15,
498,
713,
6331,
297,
788,
498,
845,
297,
283,
498,
713,
995,
288,
22865,
29,
5713,
5455,
12,
19460,
281,
29,
5713,
28593,
9,
272,
8864,
14,
525,
63,
515,
63,
7717,
8,
85,
7,
1,
1231,
15,
498,
2025,
15,
17,
6331,
297,
788,
498,
2025,
297,
413,
467,
288,
22865,
29,
5713,
5455,
12,
19460,
281,
29,
5713,
28593,
9,
272,
8864,
14,
525,
63,
515,
63,
7717,
8,
85,
7,
1,
1231,
15,
498,
2192,
6331,
6331,
15,
498,
1079,
15,
1130,
297,
788,
498,
2192,
297,
488,
12,
488,
12,
283,
498,
1079,
995,
1211,
12,
288,
22865,
29,
5713,
5455,
12,
19460,
281,
29,
5713,
28593,
9,
339,
372,
4932,
5455,
12,
4932,
28593,
199,
199,
318,
485,
3916,
63,
932,
8,
932,
304,
272,
340,
1228,
8,
932,
12,
8864,
14,
13090,
1716,
304,
267,
372,
334,
932,
14,
1450,
12,
1031,
14,
585,
9,
272,
916,
1228,
8,
932,
12,
8864,
14,
5826,
1716,
304,
267,
574,
275,
942,
267,
367,
1242,
315,
1031,
14,
585,
26,
288,
574,
14,
740,
1547,
3916,
63,
932,
8,
1053,
430,
267,
372,
334,
932,
14,
1450,
12,
574,
9,
272,
916,
1228,
8,
932,
12,
8864,
14,
7674,
1716,
304,
267,
574,
275,
942,
267,
367,
790,
12,
1242,
315,
1031,
14,
585,
26,
288,
574,
14,
740,
1332,
63,
3916,
63,
932,
8,
498,
395,
485,
3916,
63,
932,
8,
1053,
1724,
267,
372,
334,
932,
14,
1450,
12,
574,
9,
199,
199,
318,
511,
63,
515,
63,
7717,
63,
3422,
8,
576,
63,
1501,
12,
931,
63,
1501,
12,
3376,
29,
797,
304,
272,
485,
1875,
63,
515,
63,
3422,
63,
460,
63,
2724,
281,
342,
272,
3380,
17,
275,
769,
8,
5963,
14,
12607,
63,
452,
8,
1490,
8,
576,
63,
1501,
12,
283,
4848,
1959,
739,
1062,
22865,
29,
5713,
5455,
430,
272,
3380,
18,
275,
769,
8,
5963,
14,
12607,
63,
452,
8,
1490,
8,
515,
63,
1501,
12,
283,
4848,
1959,
739,
4059,
272,
862,
26,
267,
367,
1031,
17,
12,
1031,
18,
315,
3482,
8,
2415,
17,
12,
3380,
18,
304,
288,
666,
17,
275,
485,
3916,
63,
932,
8,
932,
17,
9,
288,
666,
18,
275,
485,
3916,
63,
932,
8,
932,
18,
9,
288,
702,
666,
17,
508,
666,
18,
12,
334,
576,
17,
12,
666,
18,
9,
272,
3753,
26,
267,
340,
3376,
26,
288,
870,
8864,
14,
3549,
63,
452,
8,
2415,
17,
9,
199,
199,
396,
63,
515,
63,
7717,
63,
3422,
14,
2796,
275,
18953,
576,
297,
1987,
515,
418,
199,
199,
318,
511,
63,
515,
63,
7717,
63,
2724,
281,
8,
576,
63,
1501,
12,
931,
63,
1501,
12,
3376,
29,
797,
304,
272,
485,
1875,
63,
515,
63,
3422,
63,
460,
63,
2724,
281,
342,
272,
367,
1788,
315,
359,
576,
63,
1501,
12,
931,
63,
1501,
2189,
267,
1072,
275,
8864,
14,
3549,
63,
452,
8,
5963,
14,
12607,
63,
452,
8,
1490,
8,
1501,
12,
283,
4848,
3855,
19460,
281,
29,
5713,
28593,
9,
267,
340,
3376,
26,
288,
870,
1072,
267,
3380,
17,
275,
8864,
14,
12607,
63,
452,
8,
1199,
9,
267,
3380,
18,
275,
8864,
14,
12607,
63,
452,
8,
1490,
8,
576,
63,
1501,
12,
283,
4848,
1333,
267,
367,
1031,
17,
12,
1031,
18,
315,
3482,
8,
2415,
17,
12,
3380,
18,
304,
288,
666,
17,
275,
485,
3916,
63,
932,
8,
932,
17,
9,
288,
666,
18,
275,
485,
3916,
63,
932,
8,
932,
18,
9,
288,
702,
666,
17,
508,
666,
18,
12,
334,
576,
17,
12,
666,
18,
9,
199,
199,
396,
63,
515,
63,
7717,
63,
2724,
281,
14,
2796,
275,
18953,
576,
297,
1987,
515,
418,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
511,
63,
19858,
272,
511,
63,
19858,
14,
1065,
8,
8473,
1012,
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
] |
[
646,
8864,
199,
646,
10933,
199,
199,
318,
511,
63,
11886,
63,
7717,
8,
576,
63,
1501,
12,
9696,
63,
1501,
12,
3376,
29,
797,
304,
272,
3211,
63,
1450,
275,
488,
272,
1031,
275,
488,
272,
862,
26,
267,
3211,
63,
1450,
275,
1551,
8,
13552,
63,
1501,
12,
283,
4848,
1959,
739,
1252,
1913,
342,
267,
1031,
275,
8864,
14,
12607,
8,
1490,
8,
576,
63,
1501,
12,
283,
4848,
1333,
267,
702,
1228,
8,
932,
12,
8864,
14,
5826,
1716,
395,
1031,
267,
367,
6917,
315,
1031,
14,
585,
26,
288,
702,
1228,
8,
7033,
12,
8864,
14,
13090,
1716,
395,
6917,
288,
702,
6917,
14,
1450,
508,
3211,
63,
1450,
12,
334,
7033,
14,
1450,
12,
3211,
63,
1450,
9,
272,
3753,
26,
267,
340,
3376,
26,
288,
870,
298,
31704,
18395,
6783,
3211,
63,
1450,
288,
340,
2688,
8,
932,
12,
283,
585,
735,
355,
870,
298,
1244,
1193,
4564,
742,
5424,
355,
10933,
14,
15380,
8,
932,
14,
585,
9,
199,
199,
396,
63,
11886,
63,
7717,
14,
2796,
275,
18953,
576,
297,
1987,
13552,
418,
199,
199,
318,
485,
1875,
63,
515,
63,
3422,
63,
460,
63,
2724,
281,
837,
272,
2288,
4932,
5455,
12,
4932,
28593,
339,
1021,
4932,
5455,
8,
5963,
14,
5455,
304,
267,
986,
272,
1021,
4932,
28593,
8,
5963,
14,
28593,
304,
267,
986,
339,
8864,
14,
525,
63,
515,
63,
7717,
8,
85,
7,
1,
1231,
297,
990,
288,
22865,
29,
5713,
5455,
12,
19460,
281,
29,
5713,
28593,
9,
272,
8864,
14,
525,
63,
515,
63,
7717,
8,
85,
7,
1,
1231,
15,
7033,
297,
990,
620,
12,
288,
22865,
29,
5713,
5455,
12,
19460,
281,
29,
5713,
28593,
9,
272,
8864,
14,
525,
63,
515,
63,
7717,
8,
85,
7,
1,
1231,
15,
498,
845,
15,
498,
713,
6331,
297,
788,
498,
845,
297,
283,
498,
713,
995,
288,
22865,
29,
5713,
5455,
12,
19460,
281,
29,
5713,
28593,
9,
272,
8864,
14,
525,
63,
515,
63,
7717,
8,
85,
7,
1,
1231,
15,
498,
2025,
15,
17,
6331,
297,
788,
498,
2025,
297,
413,
467,
288,
22865,
29,
5713,
5455,
12,
19460,
281,
29,
5713,
28593,
9,
272,
8864,
14,
525,
63,
515,
63,
7717,
8,
85,
7,
1,
1231,
15,
498,
2192,
6331,
6331,
15,
498,
1079,
15,
1130,
297,
788,
498,
2192,
297,
488,
12,
488,
12,
283,
498,
1079,
995,
1211,
12,
288,
22865,
29,
5713,
5455,
12,
19460,
281,
29,
5713,
28593,
9,
339,
372,
4932,
5455,
12,
4932,
28593,
199,
199,
318,
485,
3916,
63,
932,
8,
932,
304,
272,
340,
1228,
8,
932,
12,
8864,
14,
13090,
1716,
304,
267,
372,
334,
932,
14,
1450,
12,
1031,
14,
585,
9,
272,
916,
1228,
8,
932,
12,
8864,
14,
5826,
1716,
304,
267,
574,
275,
942,
267,
367,
1242,
315,
1031,
14,
585,
26,
288,
574,
14,
740,
1547,
3916,
63,
932,
8,
1053,
430,
267,
372,
334,
932,
14,
1450,
12,
574,
9,
272,
916,
1228,
8,
932,
12,
8864,
14,
7674,
1716,
304,
267,
574,
275,
942,
267,
367,
790,
12,
1242,
315,
1031,
14,
585,
26,
288,
574,
14,
740,
1332,
63,
3916,
63,
932,
8,
498,
395,
485,
3916,
63,
932,
8,
1053,
1724,
267,
372,
334,
932,
14,
1450,
12,
574,
9,
199,
199,
318,
511,
63,
515,
63,
7717,
63,
3422,
8,
576,
63,
1501,
12,
931,
63,
1501,
12,
3376,
29,
797,
304,
272,
485,
1875,
63,
515,
63,
3422,
63,
460,
63,
2724,
281,
342,
272,
3380,
17,
275,
769,
8,
5963,
14,
12607,
63,
452,
8,
1490,
8,
576,
63,
1501,
12,
283,
4848,
1959,
739,
1062,
22865,
29,
5713,
5455,
430,
272,
3380,
18,
275,
769,
8,
5963,
14,
12607,
63,
452,
8,
1490,
8,
515,
63,
1501,
12,
283,
4848,
1959,
739,
4059,
272,
862,
26,
267,
367,
1031,
17,
12,
1031,
18,
315,
3482,
8,
2415,
17,
12,
3380,
18,
304,
288,
666,
17,
275,
485,
3916,
63,
932,
8,
932,
17,
9,
288,
666,
18,
275,
485,
3916,
63,
932,
8,
932,
18,
9,
288,
702,
666,
17,
508,
666,
18,
12,
334,
576,
17,
12,
666,
18,
9,
272,
3753,
26,
267,
340,
3376,
26,
288,
870,
8864,
14,
3549,
63,
452,
8,
2415,
17,
9,
199,
199,
396,
63,
515,
63,
7717,
63,
3422,
14,
2796,
275,
18953,
576,
297,
1987,
515,
418,
199,
199,
318,
511,
63,
515,
63,
7717,
63,
2724,
281,
8,
576,
63,
1501,
12,
931,
63,
1501,
12,
3376,
29,
797,
304,
272,
485,
1875,
63,
515,
63,
3422,
63,
460,
63,
2724,
281,
342,
272,
367,
1788,
315,
359,
576,
63,
1501,
12,
931,
63,
1501,
2189,
267,
1072,
275,
8864,
14,
3549,
63,
452,
8,
5963,
14,
12607,
63,
452,
8,
1490,
8,
1501,
12,
283,
4848,
3855,
19460,
281,
29,
5713,
28593,
9,
267,
340,
3376,
26,
288,
870,
1072,
267,
3380,
17,
275,
8864,
14,
12607,
63,
452,
8,
1199,
9,
267,
3380,
18,
275,
8864,
14,
12607,
63,
452,
8,
1490,
8,
576,
63,
1501,
12,
283,
4848,
1333,
267,
367,
1031,
17,
12,
1031,
18,
315,
3482,
8,
2415,
17,
12,
3380,
18,
304,
288,
666,
17,
275,
485,
3916,
63,
932,
8,
932,
17,
9,
288,
666,
18,
275,
485,
3916,
63,
932,
8,
932,
18,
9,
288,
702,
666,
17,
508,
666,
18,
12,
334,
576,
17,
12,
666,
18,
9,
199,
199,
396,
63,
515,
63,
7717,
63,
2724,
281,
14,
2796,
275,
18953,
576,
297,
1987,
515,
418,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
511,
63,
19858,
272,
511,
63,
19858,
14,
1065,
8,
8473,
1012,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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
|
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
# Copyright (c) 2017 Mozilla Corporation
from .positive_alert_test_case import PositiveAlertTestCase
from .negative_alert_test_case import NegativeAlertTestCase
from .alert_test_suite import AlertTestSuite
class TestWriteAudit(AlertTestSuite):
alert_filename = "write_audit"
alert_classname = 'WriteAudit'
# This event is the default positive event that will cause the
# alert to trigger
default_event = {
"_source": {
"category": "write",
"summary": "Write: /etc/audit/plugins.d/temp-file.conf",
"hostname": "exhostname",
"tags": [
"audisp-json",
"2.1.0",
"audit"
],
"details": {
"processname": "vi",
"originaluser": "randomjoe",
"user": "root",
"auditkey": "audit",
}
}
}
# This alert is the expected result from running this task
default_alert = {
"category": "write",
"severity": "WARNING",
"summary": "5 Filesystem write(s) to an auditd path (/etc/audit/plugins.d/temp-file.conf) by root (randomjoe)",
"tags": ['audit'],
}
test_cases = []
test_cases.append(
PositiveAlertTestCase(
description="Positive test with default event and default alert expected",
events=AlertTestSuite.create_events(default_event, 5),
expected_alert=default_alert
)
)
events = AlertTestSuite.create_events(default_event, 5)
for event in events:
event['_source']['details']['originaluser'] = 'user1'
expected_alert = AlertTestSuite.create_alert(default_alert)
expected_alert['severity'] = 'NOTICE'
expected_alert['summary'] = "5 Filesystem write(s) to an auditd path (/etc/audit/plugins.d/temp-file.conf) by root (user1)"
test_cases.append(
PositiveAlertTestCase(
description="Positive test with expected downgraded severity",
events=events,
expected_alert=expected_alert
)
)
events = AlertTestSuite.create_events(default_event, 5)
for event in events:
event['_source']['utctimestamp'] = AlertTestSuite.subtract_from_timestamp_lambda(date_timedelta={'minutes': 1})
event['_source']['receivedtimestamp'] = AlertTestSuite.subtract_from_timestamp_lambda(date_timedelta={'minutes': 1})
test_cases.append(
PositiveAlertTestCase(
description="Positive test with events a minute earlier",
events=events,
expected_alert=default_alert
)
)
events = AlertTestSuite.create_events(default_event, 5)
for event in events:
event['_source']['details']['auditkey'] = 'exec'
test_cases.append(
NegativeAlertTestCase(
description="Negative test case with events with auditkey without 'audit'",
events=events,
)
)
events = AlertTestSuite.create_events(default_event, 5)
for event in events:
event['_source']['details']['processname'] = 'process1'
test_cases.append(
NegativeAlertTestCase(
description="Negative test case with events with processname that matches exclusion of 'process1'",
events=events,
)
)
events = AlertTestSuite.create_events(default_event, 5)
for event in events:
event['_source']['details']['originaluser'] = None
test_cases.append(
NegativeAlertTestCase(
description="Negative test case aggregation key excluded",
events=events,
)
)
events = AlertTestSuite.create_events(default_event, 5)
for event in events:
event['_source']['utctimestamp'] = AlertTestSuite.subtract_from_timestamp_lambda({'minutes': 20})
event['_source']['receivedtimestamp'] = AlertTestSuite.subtract_from_timestamp_lambda({'minutes': 20})
test_cases.append(
NegativeAlertTestCase(
description="Negative test case with old timestamp",
events=events,
)
)
|
mpl-2.0
|
[
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
199,
3,
570,
12,
2047,
883,
3332,
1373,
737,
4178,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
3,
1898,
334,
67,
9,
9708,
17728,
11098,
199,
199,
504,
1275,
8965,
63,
9241,
63,
396,
63,
2546,
492,
30245,
18758,
1746,
199,
504,
1275,
7371,
63,
9241,
63,
396,
63,
2546,
492,
32548,
18758,
1746,
199,
199,
504,
1275,
9241,
63,
396,
63,
5768,
492,
25762,
10591,
421,
199,
533,
1379,
3534,
23601,
8,
18758,
10591,
304,
272,
10459,
63,
1501,
275,
298,
952,
63,
14274,
2,
272,
10459,
63,
19851,
275,
283,
3534,
23601,
7,
339,
327,
961,
1566,
365,
314,
849,
7317,
1566,
626,
911,
7675,
314,
272,
327,
10459,
370,
6804,
272,
849,
63,
1430,
275,
469,
267,
2668,
1365,
582,
469,
288,
298,
3710,
582,
298,
952,
401,
288,
298,
4705,
582,
298,
3534,
26,
1182,
6839,
15,
14274,
15,
5265,
14,
68,
15,
808,
13,
493,
14,
2190,
401,
288,
298,
4269,
582,
298,
476,
4269,
401,
288,
298,
2969,
582,
359,
355,
298,
3844,
13654,
13,
1001,
401,
355,
298,
18,
14,
17,
14,
16,
401,
355,
298,
14274,
2,
288,
2156,
288,
298,
5087,
582,
469,
355,
298,
1412,
354,
582,
298,
433,
401,
355,
298,
5043,
751,
582,
298,
2355,
20241,
401,
355,
298,
751,
582,
298,
1231,
401,
355,
298,
14274,
498,
582,
298,
14274,
401,
288,
789,
267,
789,
272,
789,
339,
327,
961,
10459,
365,
314,
1420,
754,
687,
3879,
642,
2120,
272,
849,
63,
9241,
275,
469,
267,
298,
3710,
582,
298,
952,
401,
267,
298,
20394,
582,
298,
9171,
401,
267,
298,
4705,
582,
298,
21,
3814,
2253,
2218,
8,
83,
9,
370,
376,
13968,
68,
931,
334,
15,
6839,
15,
14274,
15,
5265,
14,
68,
15,
808,
13,
493,
14,
2190,
9,
701,
1738,
334,
2355,
20241,
4186,
267,
298,
2969,
582,
788,
14274,
995,
272,
789,
339,
511,
63,
9403,
275,
942,
339,
511,
63,
9403,
14,
740,
8,
267,
30245,
18758,
1746,
8,
288,
1369,
628,
6951,
511,
543,
849,
1566,
436,
849,
10459,
1420,
401,
288,
4474,
29,
18758,
10591,
14,
981,
63,
4368,
8,
885,
63,
1430,
12,
959,
395,
288,
1420,
63,
9241,
29,
885,
63,
9241,
267,
776,
272,
776,
339,
4474,
275,
25762,
10591,
14,
981,
63,
4368,
8,
885,
63,
1430,
12,
959,
9,
272,
367,
1566,
315,
4474,
26,
267,
1566,
8680,
1365,
2545,
5087,
2545,
5043,
751,
418,
275,
283,
751,
17,
7,
272,
1420,
63,
9241,
275,
25762,
10591,
14,
981,
63,
9241,
8,
885,
63,
9241,
9,
272,
1420,
63,
9241,
459,
20394,
418,
275,
283,
4609,
4047,
7,
272,
1420,
63,
9241,
459,
4705,
418,
275,
298,
21,
3814,
2253,
2218,
8,
83,
9,
370,
376,
13968,
68,
931,
334,
15,
6839,
15,
14274,
15,
5265,
14,
68,
15,
808,
13,
493,
14,
2190,
9,
701,
1738,
334,
751,
17,
2924,
272,
511,
63,
9403,
14,
740,
8,
267,
30245,
18758,
1746,
8,
288,
1369,
628,
6951,
511,
543,
1420,
3224,
13688,
25574,
401,
288,
4474,
29,
4368,
12,
288,
1420,
63,
9241,
29,
2062,
63,
9241,
267,
776,
272,
776,
339,
4474,
275,
25762,
10591,
14,
981,
63,
4368,
8,
885,
63,
1430,
12,
959,
9,
272,
367,
1566,
315,
4474,
26,
267,
1566,
8680,
1365,
2545,
5834,
3954,
418,
275,
25762,
10591,
14,
25719,
63,
504,
63,
3954,
63,
2734,
8,
602,
63,
7473,
3713,
10430,
356,
413,
1552,
267,
1566,
8680,
1365,
2545,
9226,
3954,
418,
275,
25762,
10591,
14,
25719,
63,
504,
63,
3954,
63,
2734,
8,
602,
63,
7473,
3713,
10430,
356,
413,
1552,
272,
511,
63,
9403,
14,
740,
8,
267,
30245,
18758,
1746,
8,
288,
1369,
628,
6951,
511,
543,
4474,
282,
12709,
14119,
401,
288,
4474,
29,
4368,
12,
288,
1420,
63,
9241,
29,
885,
63,
9241,
267,
776,
272,
776,
339,
4474,
275,
25762,
10591,
14,
981,
63,
4368,
8,
885,
63,
1430,
12,
959,
9,
272,
367,
1566,
315,
4474,
26,
267,
1566,
8680,
1365,
2545,
5087,
2545,
14274,
498,
418,
275,
283,
1628,
7,
272,
511,
63,
9403,
14,
740,
8,
267,
32548,
18758,
1746,
8,
288,
1369,
628,
15562,
511,
1930,
543,
4474,
543,
13968,
498,
1928,
283,
14274,
4662,
288,
4474,
29,
4368,
12,
267,
776,
272,
776,
339,
4474,
275,
25762,
10591,
14,
981,
63,
4368,
8,
885,
63,
1430,
12,
959,
9,
272,
367,
1566,
315,
4474,
26,
267,
1566,
8680,
1365,
2545,
5087,
2545,
1412,
354,
418,
275,
283,
1412,
17,
7,
272,
511,
63,
9403,
14,
740,
8,
267,
32548,
18758,
1746,
8,
288,
1369,
628,
15562,
511,
1930,
543,
4474,
543,
2112,
354,
626,
4450,
27551,
402,
283,
1412,
17,
4662,
288,
4474,
29,
4368,
12,
267,
776,
272,
776,
339,
4474,
275,
25762,
10591,
14,
981,
63,
4368,
8,
885,
63,
1430,
12,
959,
9,
272,
367,
1566,
315,
4474,
26,
267,
1566,
8680,
1365,
2545,
5087,
2545,
5043,
751,
418,
275,
488,
272,
511,
63,
9403,
14,
740,
8,
267,
32548,
18758,
1746,
8,
288,
1369,
628,
15562,
511,
1930,
18384,
790,
8789,
401,
288,
4474,
29,
4368,
12,
267,
776,
272,
776,
339,
4474,
275,
25762,
10591,
14,
981,
63,
4368,
8,
885,
63,
1430,
12,
959,
9,
272,
367,
1566,
315,
4474,
26,
267,
1566,
8680,
1365,
2545,
5834,
3954,
418,
275,
25762,
10591,
14,
25719,
63,
504,
63,
3954,
63,
2734,
3252,
10430,
356,
3388,
1552,
267,
1566,
8680,
1365,
2545,
9226,
3954,
418,
275,
25762,
10591,
14,
25719,
63,
504,
63,
3954,
63,
2734,
3252,
10430,
356,
3388,
1552,
272,
511,
63,
9403,
14,
740,
8,
267,
32548,
18758,
1746,
8,
288,
1369,
628,
15562,
511,
1930,
543,
2269,
4913,
401,
288,
4474,
29,
4368,
12,
267,
776,
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
] |
[
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
199,
3,
570,
12,
2047,
883,
3332,
1373,
737,
4178,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
3,
1898,
334,
67,
9,
9708,
17728,
11098,
199,
199,
504,
1275,
8965,
63,
9241,
63,
396,
63,
2546,
492,
30245,
18758,
1746,
199,
504,
1275,
7371,
63,
9241,
63,
396,
63,
2546,
492,
32548,
18758,
1746,
199,
199,
504,
1275,
9241,
63,
396,
63,
5768,
492,
25762,
10591,
421,
199,
533,
1379,
3534,
23601,
8,
18758,
10591,
304,
272,
10459,
63,
1501,
275,
298,
952,
63,
14274,
2,
272,
10459,
63,
19851,
275,
283,
3534,
23601,
7,
339,
327,
961,
1566,
365,
314,
849,
7317,
1566,
626,
911,
7675,
314,
272,
327,
10459,
370,
6804,
272,
849,
63,
1430,
275,
469,
267,
2668,
1365,
582,
469,
288,
298,
3710,
582,
298,
952,
401,
288,
298,
4705,
582,
298,
3534,
26,
1182,
6839,
15,
14274,
15,
5265,
14,
68,
15,
808,
13,
493,
14,
2190,
401,
288,
298,
4269,
582,
298,
476,
4269,
401,
288,
298,
2969,
582,
359,
355,
298,
3844,
13654,
13,
1001,
401,
355,
298,
18,
14,
17,
14,
16,
401,
355,
298,
14274,
2,
288,
2156,
288,
298,
5087,
582,
469,
355,
298,
1412,
354,
582,
298,
433,
401,
355,
298,
5043,
751,
582,
298,
2355,
20241,
401,
355,
298,
751,
582,
298,
1231,
401,
355,
298,
14274,
498,
582,
298,
14274,
401,
288,
789,
267,
789,
272,
789,
339,
327,
961,
10459,
365,
314,
1420,
754,
687,
3879,
642,
2120,
272,
849,
63,
9241,
275,
469,
267,
298,
3710,
582,
298,
952,
401,
267,
298,
20394,
582,
298,
9171,
401,
267,
298,
4705,
582,
298,
21,
3814,
2253,
2218,
8,
83,
9,
370,
376,
13968,
68,
931,
334,
15,
6839,
15,
14274,
15,
5265,
14,
68,
15,
808,
13,
493,
14,
2190,
9,
701,
1738,
334,
2355,
20241,
4186,
267,
298,
2969,
582,
788,
14274,
995,
272,
789,
339,
511,
63,
9403,
275,
942,
339,
511,
63,
9403,
14,
740,
8,
267,
30245,
18758,
1746,
8,
288,
1369,
628,
6951,
511,
543,
849,
1566,
436,
849,
10459,
1420,
401,
288,
4474,
29,
18758,
10591,
14,
981,
63,
4368,
8,
885,
63,
1430,
12,
959,
395,
288,
1420,
63,
9241,
29,
885,
63,
9241,
267,
776,
272,
776,
339,
4474,
275,
25762,
10591,
14,
981,
63,
4368,
8,
885,
63,
1430,
12,
959,
9,
272,
367,
1566,
315,
4474,
26,
267,
1566,
8680,
1365,
2545,
5087,
2545,
5043,
751,
418,
275,
283,
751,
17,
7,
272,
1420,
63,
9241,
275,
25762,
10591,
14,
981,
63,
9241,
8,
885,
63,
9241,
9,
272,
1420,
63,
9241,
459,
20394,
418,
275,
283,
4609,
4047,
7,
272,
1420,
63,
9241,
459,
4705,
418,
275,
298,
21,
3814,
2253,
2218,
8,
83,
9,
370,
376,
13968,
68,
931,
334,
15,
6839,
15,
14274,
15,
5265,
14,
68,
15,
808,
13,
493,
14,
2190,
9,
701,
1738,
334,
751,
17,
2924,
272,
511,
63,
9403,
14,
740,
8,
267,
30245,
18758,
1746,
8,
288,
1369,
628,
6951,
511,
543,
1420,
3224,
13688,
25574,
401,
288,
4474,
29,
4368,
12,
288,
1420,
63,
9241,
29,
2062,
63,
9241,
267,
776,
272,
776,
339,
4474,
275,
25762,
10591,
14,
981,
63,
4368,
8,
885,
63,
1430,
12,
959,
9,
272,
367,
1566,
315,
4474,
26,
267,
1566,
8680,
1365,
2545,
5834,
3954,
418,
275,
25762,
10591,
14,
25719,
63,
504,
63,
3954,
63,
2734,
8,
602,
63,
7473,
3713,
10430,
356,
413,
1552,
267,
1566,
8680,
1365,
2545,
9226,
3954,
418,
275,
25762,
10591,
14,
25719,
63,
504,
63,
3954,
63,
2734,
8,
602,
63,
7473,
3713,
10430,
356,
413,
1552,
272,
511,
63,
9403,
14,
740,
8,
267,
30245,
18758,
1746,
8,
288,
1369,
628,
6951,
511,
543,
4474,
282,
12709,
14119,
401,
288,
4474,
29,
4368,
12,
288,
1420,
63,
9241,
29,
885,
63,
9241,
267,
776,
272,
776,
339,
4474,
275,
25762,
10591,
14,
981,
63,
4368,
8,
885,
63,
1430,
12,
959,
9,
272,
367,
1566,
315,
4474,
26,
267,
1566,
8680,
1365,
2545,
5087,
2545,
14274,
498,
418,
275,
283,
1628,
7,
272,
511,
63,
9403,
14,
740,
8,
267,
32548,
18758,
1746,
8,
288,
1369,
628,
15562,
511,
1930,
543,
4474,
543,
13968,
498,
1928,
283,
14274,
4662,
288,
4474,
29,
4368,
12,
267,
776,
272,
776,
339,
4474,
275,
25762,
10591,
14,
981,
63,
4368,
8,
885,
63,
1430,
12,
959,
9,
272,
367,
1566,
315,
4474,
26,
267,
1566,
8680,
1365,
2545,
5087,
2545,
1412,
354,
418,
275,
283,
1412,
17,
7,
272,
511,
63,
9403,
14,
740,
8,
267,
32548,
18758,
1746,
8,
288,
1369,
628,
15562,
511,
1930,
543,
4474,
543,
2112,
354,
626,
4450,
27551,
402,
283,
1412,
17,
4662,
288,
4474,
29,
4368,
12,
267,
776,
272,
776,
339,
4474,
275,
25762,
10591,
14,
981,
63,
4368,
8,
885,
63,
1430,
12,
959,
9,
272,
367,
1566,
315,
4474,
26,
267,
1566,
8680,
1365,
2545,
5087,
2545,
5043,
751,
418,
275,
488,
272,
511,
63,
9403,
14,
740,
8,
267,
32548,
18758,
1746,
8,
288,
1369,
628,
15562,
511,
1930,
18384,
790,
8789,
401,
288,
4474,
29,
4368,
12,
267,
776,
272,
776,
339,
4474,
275,
25762,
10591,
14,
981,
63,
4368,
8,
885,
63,
1430,
12,
959,
9,
272,
367,
1566,
315,
4474,
26,
267,
1566,
8680,
1365,
2545,
5834,
3954,
418,
275,
25762,
10591,
14,
25719,
63,
504,
63,
3954,
63,
2734,
3252,
10430,
356,
3388,
1552,
267,
1566,
8680,
1365,
2545,
9226,
3954,
418,
275,
25762,
10591,
14,
25719,
63,
504,
63,
3954,
63,
2734,
3252,
10430,
356,
3388,
1552,
272,
511,
63,
9403,
14,
740,
8,
267,
32548,
18758,
1746,
8,
288,
1369,
628,
15562,
511,
1930,
543,
2269,
4913,
401,
288,
4474,
29,
4368,
12,
267,
776,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
loongson-community/EFI-MIPS
|
ToolKit/cmds/python/Lib/test/skipped/test_imgfile.py
|
43
|
4214
|
#! /usr/bin/env python
"""Simple test script for imgfile.c
Roger E. Masse
"""
from test.test_support import verbose, unlink, findfile
import imgfile, uu, os
def main():
uu.decode(findfile('testrgb.uue'), 'test.rgb')
uu.decode(findfile('greyrgb.uue'), 'greytest.rgb')
# Test a 3 byte color image
testimage('test.rgb')
# Test a 1 byte greyscale image
testimage('greytest.rgb')
unlink('test.rgb')
unlink('greytest.rgb')
def testimage(name):
"""Run through the imgfile's battery of possible methods
on the image passed in name.
"""
import sys
import os
outputfile = '/tmp/deleteme'
# try opening the name directly
try:
# This function returns a tuple (x, y, z) where x and y are the size
# of the image in pixels and z is the number of bytes per pixel. Only
# 3 byte RGB pixels and 1 byte greyscale pixels are supported.
sizes = imgfile.getsizes(name)
except imgfile.error:
# get a more qualified path component of the script...
if __name__ == '__main__':
ourname = sys.argv[0]
else: # ...or the full path of the module
ourname = sys.modules[__name__].__file__
parts = ourname.split(os.sep)
parts[-1] = name
name = os.sep.join(parts)
sizes = imgfile.getsizes(name)
if verbose:
print 'Opening test image: %s, sizes: %s' % (name, str(sizes))
# This function reads and decodes the image on the specified file,
# and returns it as a python string. The string has either 1 byte
# greyscale pixels or 4 byte RGBA pixels. The bottom left pixel
# is the first in the string. This format is suitable to pass
# to gl.lrectwrite, for instance.
image = imgfile.read(name)
# This function writes the RGB or greyscale data in data to
# image file file. x and y give the size of the image, z is
# 1 for 1 byte greyscale images or 3 for RGB images (which
# are stored as 4 byte values of which only the lower three
# bytes are used). These are the formats returned by gl.lrectread.
if verbose:
print 'Writing output file'
imgfile.write (outputfile, image, sizes[0], sizes[1], sizes[2])
if verbose:
print 'Opening scaled test image: %s, sizes: %s' % (name, str(sizes))
# This function is identical to read but it returns an image that
# is scaled to the given x and y sizes. If the filter and blur
# parameters are omitted scaling is done by simply dropping
# or duplicating pixels, so the result will be less than perfect,
# especially for computer-generated images. Alternatively,
# you can specify a filter to use to smoothen the image after
# scaling. The filter forms supported are 'impulse', 'box',
# 'triangle', 'quadratic' and 'gaussian'. If a filter is
# specified blur is an optional parameter specifying the
# blurriness of the filter. It defaults to 1.0. readscaled
# makes no attempt to keep the aspect ratio correct, so that
# is the users' responsibility.
if verbose:
print 'Filtering with "impulse"'
simage = imgfile.readscaled (name, sizes[0]/2, sizes[1]/2, 'impulse', 2.0)
# This function sets a global flag which defines whether the
# scan lines of the image are read or written from bottom to
# top (flag is zero, compatible with SGI GL) or from top to
# bottom(flag is one, compatible with X). The default is zero.
if verbose:
print 'Switching to X compatibility'
imgfile.ttob (1)
if verbose:
print 'Filtering with "triangle"'
simage = imgfile.readscaled (name, sizes[0]/2, sizes[1]/2, 'triangle', 3.0)
if verbose:
print 'Switching back to SGI compatibility'
imgfile.ttob (0)
if verbose: print 'Filtering with "quadratic"'
simage = imgfile.readscaled (name, sizes[0]/2, sizes[1]/2, 'quadratic')
if verbose: print 'Filtering with "gaussian"'
simage = imgfile.readscaled (name, sizes[0]/2, sizes[1]/2, 'gaussian', 1.0)
if verbose:
print 'Writing output file'
imgfile.write (outputfile, simage, sizes[0]/2, sizes[1]/2, sizes[2])
os.unlink(outputfile)
main()
|
bsd-3-clause
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
3184,
511,
2884,
367,
6050,
493,
14,
67,
2043,
6848,
836,
662,
14,
603,
305,
261,
199,
624,
199,
199,
504,
511,
14,
396,
63,
4058,
492,
3376,
12,
17002,
12,
2342,
493,
199,
199,
646,
6050,
493,
12,
399,
85,
12,
747,
421,
199,
318,
2446,
837,
339,
399,
85,
14,
2708,
8,
1623,
493,
360,
396,
10090,
14,
85,
310,
659,
283,
396,
14,
10090,
358,
272,
399,
85,
14,
2708,
8,
1623,
493,
360,
16708,
10090,
14,
85,
310,
659,
283,
16708,
396,
14,
10090,
358,
339,
327,
1379,
282,
650,
3696,
3164,
1834,
272,
511,
1569,
360,
396,
14,
10090,
358,
339,
327,
1379,
282,
413,
3696,
30357,
3467,
1834,
272,
511,
1569,
360,
16708,
396,
14,
10090,
358,
339,
17002,
360,
396,
14,
10090,
358,
272,
17002,
360,
16708,
396,
14,
10090,
358,
199,
199,
318,
511,
1569,
8,
354,
304,
272,
408,
2540,
4012,
314,
6050,
493,
1159,
330,
13891,
402,
3962,
3102,
2126,
641,
314,
1834,
3032,
315,
536,
14,
272,
408,
339,
492,
984,
272,
492,
747,
339,
32513,
275,
1994,
2791,
15,
1807,
278,
7,
339,
327,
862,
13618,
314,
536,
5370,
272,
862,
26,
267,
327,
961,
805,
2529,
282,
2008,
334,
88,
12,
612,
12,
1315,
9,
2382,
671,
436,
612,
787,
314,
1568,
267,
327,
402,
314,
1834,
315,
11094,
436,
1315,
365,
314,
1329,
402,
2783,
1126,
7148,
14,
5972,
267,
327,
650,
3696,
19013,
11094,
436,
413,
3696,
30357,
3467,
11094,
787,
3748,
14,
267,
10627,
275,
6050,
493,
14,
362,
7723,
8,
354,
9,
272,
871,
6050,
493,
14,
705,
26,
267,
327,
664,
282,
1655,
12313,
931,
3931,
402,
314,
2884,
1396,
267,
340,
636,
354,
363,
508,
2560,
973,
3706,
288,
312,
21121,
275,
984,
14,
3020,
59,
16,
61,
267,
587,
26,
327,
2263,
269,
314,
2615,
931,
402,
314,
859,
288,
312,
21121,
275,
984,
14,
3112,
28894,
354,
363,
17979,
493,
363,
398,
4184,
275,
312,
21121,
14,
1294,
8,
736,
14,
4127,
9,
267,
4184,
1988,
17,
61,
275,
536,
267,
536,
275,
747,
14,
4127,
14,
904,
8,
4181,
9,
267,
10627,
275,
6050,
493,
14,
362,
7723,
8,
354,
9,
272,
340,
3376,
26,
267,
870,
283,
4299,
316,
511,
1834,
26,
450,
83,
12,
10627,
26,
450,
83,
7,
450,
334,
354,
12,
620,
8,
7723,
430,
272,
327,
961,
805,
11597,
436,
4849,
83,
314,
1834,
641,
314,
2013,
570,
12,
272,
327,
436,
2529,
652,
465,
282,
2366,
1059,
14,
710,
1059,
965,
1902,
413,
3696,
272,
327,
30357,
3467,
11094,
503,
841,
3696,
820,
39,
4134,
11094,
14,
710,
9048,
3602,
7148,
272,
327,
365,
314,
1642,
315,
314,
1059,
14,
961,
1475,
365,
11233,
370,
986,
272,
327,
370,
6482,
14,
76,
1201,
952,
12,
367,
1256,
14,
272,
1834,
275,
6050,
493,
14,
739,
8,
354,
9,
339,
327,
961,
805,
14511,
314,
19013,
503,
30357,
3467,
666,
315,
666,
370,
272,
327,
1834,
570,
570,
14,
671,
436,
612,
8120,
314,
1568,
402,
314,
1834,
12,
1315,
365,
272,
327,
413,
367,
413,
3696,
30357,
3467,
5935,
503,
650,
367,
19013,
5935,
334,
6777,
272,
327,
787,
5489,
465,
841,
3696,
1338,
402,
1314,
1454,
314,
5117,
7795,
272,
327,
2783,
787,
1202,
680,
5723,
787,
314,
6752,
2138,
701,
6482,
14,
76,
1201,
739,
14,
272,
340,
3376,
26,
267,
870,
283,
16646,
1072,
570,
7,
272,
6050,
493,
14,
952,
334,
1199,
493,
12,
1834,
12,
10627,
59,
16,
467,
10627,
59,
17,
467,
10627,
59,
18,
566,
2378,
340,
3376,
26,
267,
870,
283,
4299,
316,
17923,
511,
1834,
26,
450,
83,
12,
10627,
26,
450,
83,
7,
450,
334,
354,
12,
620,
8,
7723,
430,
272,
327,
961,
805,
365,
13130,
370,
1586,
1325,
652,
2529,
376,
1834,
626,
272,
327,
365,
17923,
370,
314,
1627,
671,
436,
612,
10627,
14,
982,
314,
2457,
436,
6826,
300,
272,
327,
2633,
787,
11684,
13690,
365,
4224,
701,
9329,
366,
20148,
272,
327,
503,
366,
4230,
1958,
11094,
12,
880,
314,
754,
911,
506,
6656,
2419,
23668,
12,
272,
327,
24002,
367,
24189,
13,
10176,
5935,
14,
221,
26776,
12,
272,
327,
1265,
883,
4165,
282,
2457,
370,
675,
370,
19608,
287,
314,
1834,
2410,
272,
327,
13690,
14,
710,
2457,
4513,
3748,
787,
283,
3236,
13055,
297,
283,
1977,
297,
272,
327,
283,
21584,
297,
283,
14567,
19826,
7,
436,
283,
22911,
1370,
982,
282,
2457,
365,
272,
327,
2013,
6826,
300,
365,
376,
2716,
2725,
9176,
314,
272,
327,
6826,
300,
82,
9585,
402,
314,
2457,
14,
2779,
4243,
370,
413,
14,
16,
14,
221,
1586,
15120,
272,
327,
7704,
949,
7427,
370,
4215,
314,
17435,
10463,
3211,
12,
880,
626,
272,
327,
365,
314,
4390,
7,
9163,
4783,
14,
272,
340,
3376,
26,
267,
870,
283,
4131,
316,
543,
298,
3236,
13055,
4507,
272,
308,
1569,
275,
6050,
493,
14,
739,
15120,
334,
354,
12,
10627,
59,
16,
12978,
18,
12,
10627,
59,
17,
12978,
18,
12,
283,
3236,
13055,
297,
499,
14,
16,
9,
339,
327,
961,
805,
5951,
282,
2288,
3305,
1314,
7890,
3775,
314,
272,
327,
8000,
2385,
402,
314,
1834,
787,
1586,
503,
5313,
687,
9048,
370,
272,
327,
2746,
334,
4173,
365,
4697,
12,
9025,
543,
18868,
41,
3563,
9,
503,
687,
2746,
370,
272,
327,
9048,
8,
4173,
365,
1373,
12,
9025,
543,
1323,
680,
710,
849,
365,
4697,
14,
272,
340,
3376,
26,
267,
870,
283,
10167,
316,
370,
1323,
7163,
7,
272,
6050,
493,
14,
84,
475,
66,
334,
17,
9,
339,
340,
3376,
26,
267,
870,
283,
4131,
316,
543,
298,
21584,
4507,
272,
308,
1569,
275,
6050,
493,
14,
739,
15120,
334,
354,
12,
10627,
59,
16,
12978,
18,
12,
10627,
59,
17,
12978,
18,
12,
283,
21584,
297,
650,
14,
16,
9,
272,
340,
3376,
26,
267,
870,
283,
10167,
316,
1771,
370,
18868,
41,
7163,
7,
272,
6050,
493,
14,
84,
475,
66,
334,
16,
9,
339,
340,
3376,
26,
870,
283,
4131,
316,
543,
298,
14567,
19826,
4507,
272,
308,
1569,
275,
6050,
493,
14
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
3184,
511,
2884,
367,
6050,
493,
14,
67,
2043,
6848,
836,
662,
14,
603,
305,
261,
199,
624,
199,
199,
504,
511,
14,
396,
63,
4058,
492,
3376,
12,
17002,
12,
2342,
493,
199,
199,
646,
6050,
493,
12,
399,
85,
12,
747,
421,
199,
318,
2446,
837,
339,
399,
85,
14,
2708,
8,
1623,
493,
360,
396,
10090,
14,
85,
310,
659,
283,
396,
14,
10090,
358,
272,
399,
85,
14,
2708,
8,
1623,
493,
360,
16708,
10090,
14,
85,
310,
659,
283,
16708,
396,
14,
10090,
358,
339,
327,
1379,
282,
650,
3696,
3164,
1834,
272,
511,
1569,
360,
396,
14,
10090,
358,
339,
327,
1379,
282,
413,
3696,
30357,
3467,
1834,
272,
511,
1569,
360,
16708,
396,
14,
10090,
358,
339,
17002,
360,
396,
14,
10090,
358,
272,
17002,
360,
16708,
396,
14,
10090,
358,
199,
199,
318,
511,
1569,
8,
354,
304,
272,
408,
2540,
4012,
314,
6050,
493,
1159,
330,
13891,
402,
3962,
3102,
2126,
641,
314,
1834,
3032,
315,
536,
14,
272,
408,
339,
492,
984,
272,
492,
747,
339,
32513,
275,
1994,
2791,
15,
1807,
278,
7,
339,
327,
862,
13618,
314,
536,
5370,
272,
862,
26,
267,
327,
961,
805,
2529,
282,
2008,
334,
88,
12,
612,
12,
1315,
9,
2382,
671,
436,
612,
787,
314,
1568,
267,
327,
402,
314,
1834,
315,
11094,
436,
1315,
365,
314,
1329,
402,
2783,
1126,
7148,
14,
5972,
267,
327,
650,
3696,
19013,
11094,
436,
413,
3696,
30357,
3467,
11094,
787,
3748,
14,
267,
10627,
275,
6050,
493,
14,
362,
7723,
8,
354,
9,
272,
871,
6050,
493,
14,
705,
26,
267,
327,
664,
282,
1655,
12313,
931,
3931,
402,
314,
2884,
1396,
267,
340,
636,
354,
363,
508,
2560,
973,
3706,
288,
312,
21121,
275,
984,
14,
3020,
59,
16,
61,
267,
587,
26,
327,
2263,
269,
314,
2615,
931,
402,
314,
859,
288,
312,
21121,
275,
984,
14,
3112,
28894,
354,
363,
17979,
493,
363,
398,
4184,
275,
312,
21121,
14,
1294,
8,
736,
14,
4127,
9,
267,
4184,
1988,
17,
61,
275,
536,
267,
536,
275,
747,
14,
4127,
14,
904,
8,
4181,
9,
267,
10627,
275,
6050,
493,
14,
362,
7723,
8,
354,
9,
272,
340,
3376,
26,
267,
870,
283,
4299,
316,
511,
1834,
26,
450,
83,
12,
10627,
26,
450,
83,
7,
450,
334,
354,
12,
620,
8,
7723,
430,
272,
327,
961,
805,
11597,
436,
4849,
83,
314,
1834,
641,
314,
2013,
570,
12,
272,
327,
436,
2529,
652,
465,
282,
2366,
1059,
14,
710,
1059,
965,
1902,
413,
3696,
272,
327,
30357,
3467,
11094,
503,
841,
3696,
820,
39,
4134,
11094,
14,
710,
9048,
3602,
7148,
272,
327,
365,
314,
1642,
315,
314,
1059,
14,
961,
1475,
365,
11233,
370,
986,
272,
327,
370,
6482,
14,
76,
1201,
952,
12,
367,
1256,
14,
272,
1834,
275,
6050,
493,
14,
739,
8,
354,
9,
339,
327,
961,
805,
14511,
314,
19013,
503,
30357,
3467,
666,
315,
666,
370,
272,
327,
1834,
570,
570,
14,
671,
436,
612,
8120,
314,
1568,
402,
314,
1834,
12,
1315,
365,
272,
327,
413,
367,
413,
3696,
30357,
3467,
5935,
503,
650,
367,
19013,
5935,
334,
6777,
272,
327,
787,
5489,
465,
841,
3696,
1338,
402,
1314,
1454,
314,
5117,
7795,
272,
327,
2783,
787,
1202,
680,
5723,
787,
314,
6752,
2138,
701,
6482,
14,
76,
1201,
739,
14,
272,
340,
3376,
26,
267,
870,
283,
16646,
1072,
570,
7,
272,
6050,
493,
14,
952,
334,
1199,
493,
12,
1834,
12,
10627,
59,
16,
467,
10627,
59,
17,
467,
10627,
59,
18,
566,
2378,
340,
3376,
26,
267,
870,
283,
4299,
316,
17923,
511,
1834,
26,
450,
83,
12,
10627,
26,
450,
83,
7,
450,
334,
354,
12,
620,
8,
7723,
430,
272,
327,
961,
805,
365,
13130,
370,
1586,
1325,
652,
2529,
376,
1834,
626,
272,
327,
365,
17923,
370,
314,
1627,
671,
436,
612,
10627,
14,
982,
314,
2457,
436,
6826,
300,
272,
327,
2633,
787,
11684,
13690,
365,
4224,
701,
9329,
366,
20148,
272,
327,
503,
366,
4230,
1958,
11094,
12,
880,
314,
754,
911,
506,
6656,
2419,
23668,
12,
272,
327,
24002,
367,
24189,
13,
10176,
5935,
14,
221,
26776,
12,
272,
327,
1265,
883,
4165,
282,
2457,
370,
675,
370,
19608,
287,
314,
1834,
2410,
272,
327,
13690,
14,
710,
2457,
4513,
3748,
787,
283,
3236,
13055,
297,
283,
1977,
297,
272,
327,
283,
21584,
297,
283,
14567,
19826,
7,
436,
283,
22911,
1370,
982,
282,
2457,
365,
272,
327,
2013,
6826,
300,
365,
376,
2716,
2725,
9176,
314,
272,
327,
6826,
300,
82,
9585,
402,
314,
2457,
14,
2779,
4243,
370,
413,
14,
16,
14,
221,
1586,
15120,
272,
327,
7704,
949,
7427,
370,
4215,
314,
17435,
10463,
3211,
12,
880,
626,
272,
327,
365,
314,
4390,
7,
9163,
4783,
14,
272,
340,
3376,
26,
267,
870,
283,
4131,
316,
543,
298,
3236,
13055,
4507,
272,
308,
1569,
275,
6050,
493,
14,
739,
15120,
334,
354,
12,
10627,
59,
16,
12978,
18,
12,
10627,
59,
17,
12978,
18,
12,
283,
3236,
13055,
297,
499,
14,
16,
9,
339,
327,
961,
805,
5951,
282,
2288,
3305,
1314,
7890,
3775,
314,
272,
327,
8000,
2385,
402,
314,
1834,
787,
1586,
503,
5313,
687,
9048,
370,
272,
327,
2746,
334,
4173,
365,
4697,
12,
9025,
543,
18868,
41,
3563,
9,
503,
687,
2746,
370,
272,
327,
9048,
8,
4173,
365,
1373,
12,
9025,
543,
1323,
680,
710,
849,
365,
4697,
14,
272,
340,
3376,
26,
267,
870,
283,
10167,
316,
370,
1323,
7163,
7,
272,
6050,
493,
14,
84,
475,
66,
334,
17,
9,
339,
340,
3376,
26,
267,
870,
283,
4131,
316,
543,
298,
21584,
4507,
272,
308,
1569,
275,
6050,
493,
14,
739,
15120,
334,
354,
12,
10627,
59,
16,
12978,
18,
12,
10627,
59,
17,
12978,
18,
12,
283,
21584,
297,
650,
14,
16,
9,
272,
340,
3376,
26,
267,
870,
283,
10167,
316,
1771,
370,
18868,
41,
7163,
7,
272,
6050,
493,
14,
84,
475,
66,
334,
16,
9,
339,
340,
3376,
26,
870,
283,
4131,
316,
543,
298,
14567,
19826,
4507,
272,
308,
1569,
275,
6050,
493,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
TechEmpower/FrameworkBenchmarks
|
frameworks/Python/web2py/app/standard/modules/database.py
|
22
|
2110
|
# -*- coding: utf-8 -*-
import os
from operator import itemgetter
from gluon.storage import Storage
from gluon.dal import DAL, Field, Row
DBHOST = 'tfb-database'
DATABASE_URI = 'mysql://benchmarkdbuser:benchmarkdbpass@%s:3306/hello_world' % DBHOST
class Dal(object):
def __init__(self, table=None, pool_size=8):
self.db = DAL(DATABASE_URI, migrate_enabled=False, pool_size=pool_size)
if table == 'World':
self.db.define_table('World', Field('randomNumber', 'integer'))
elif table == 'Fortune':
self.db.define_table('Fortune', Field('message'))
def get_world(self, wid):
# Setting `cacheable=True` improves performance by foregoing the creation
# of some non-essential attributes. It does *not* actually cache the
# database results (it simply produces a Rows object that *could be* cached).
return self.db(self.db.World.id == wid).select(cacheable=True)[0].as_dict()
def update_world(self, wid, randomNumber):
self.db(self.db.World.id == wid).update(randomNumber=randomNumber)
def get_fortunes(self, new_message):
fortunes = self.db(self.db.Fortune).select(cacheable=True)
fortunes.records.append(Row(new_message))
return fortunes.sort(itemgetter('message'))
class RawDal(Dal):
def __init__(self):
super(RawDal, self).__init__()
def get_world(self, wid):
return self.db.executesql('SELECT * FROM World WHERE id = %s',
placeholders=[wid], as_dict=True)[0]
def update_world(self, wid, randomNumber):
self.db.executesql('UPDATE World SET randomNumber=%s WHERE id=%s',
placeholders=[randomNumber, wid])
def get_fortunes(self, new_message):
fortunes = self.db.executesql('SELECT * FROM Fortune', as_dict=True)
fortunes.append(new_message)
return sorted(fortunes, key=itemgetter('message'))
def num_queries(queries):
try:
num = int(queries)
return 1 if num < 1 else 500 if num > 500 else num
except ValueError:
return 1
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
747,
199,
504,
4182,
492,
1242,
7416,
199,
504,
26752,
14,
3494,
492,
10533,
199,
504,
26752,
14,
12390,
492,
577,
748,
12,
5024,
12,
15231,
199,
199,
2846,
5449,
275,
283,
3249,
66,
13,
4659,
7,
199,
17873,
63,
7639,
275,
283,
8644,
921,
11861,
68,
464,
332,
26,
11861,
697,
1529,
19437,
83,
26,
1153,
1690,
15,
5006,
63,
7617,
7,
450,
6249,
5449,
199,
199,
533,
577,
279,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1817,
29,
403,
12,
4203,
63,
890,
29,
24,
304,
267,
291,
14,
697,
275,
577,
748,
8,
17873,
63,
7639,
12,
12810,
63,
3827,
29,
797,
12,
4203,
63,
890,
29,
2293,
63,
890,
9,
267,
340,
1817,
508,
283,
15943,
356,
288,
291,
14,
697,
14,
4640,
63,
1224,
360,
15943,
297,
5024,
360,
2355,
3259,
297,
283,
4115,
1333,
267,
916,
1817,
508,
283,
38,
361,
11474,
356,
288,
291,
14,
697,
14,
4640,
63,
1224,
360,
38,
361,
11474,
297,
5024,
360,
1188,
1333,
339,
347,
664,
63,
7617,
8,
277,
12,
336,
344,
304,
267,
327,
13510,
658,
1637,
461,
29,
549,
64,
1742,
293,
2310,
10238,
701,
11257,
10947,
314,
7143,
267,
327,
402,
2005,
2222,
13,
397,
2464,
1009,
3004,
14,
2779,
1630,
627,
1397,
10,
5965,
2581,
314,
267,
327,
3050,
2058,
334,
390,
9329,
16904,
282,
15231,
83,
909,
626,
627,
15153,
506,
10,
6328,
680,
267,
372,
291,
14,
697,
8,
277,
14,
697,
14,
15943,
14,
344,
508,
336,
344,
680,
2416,
8,
1637,
461,
29,
549,
2788,
16,
1055,
305,
63,
807,
342,
339,
347,
1678,
63,
7617,
8,
277,
12,
336,
344,
12,
2196,
3259,
304,
267,
291,
14,
697,
8,
277,
14,
697,
14,
15943,
14,
344,
508,
336,
344,
680,
873,
8,
2355,
3259,
29,
2355,
3259,
9,
339,
347,
664,
63,
20285,
397,
8,
277,
12,
892,
63,
1188,
304,
267,
289,
361,
324,
397,
275,
291,
14,
697,
8,
277,
14,
697,
14,
38,
361,
11474,
680,
2416,
8,
1637,
461,
29,
549,
9,
267,
289,
361,
324,
397,
14,
6502,
14,
740,
8,
5810,
8,
1222,
63,
1188,
430,
267,
372,
289,
361,
324,
397,
14,
3191,
8,
20832,
360,
1188,
1333,
199,
199,
533,
13480,
36,
279,
8,
36,
279,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
7963,
36,
279,
12,
291,
2843,
826,
4533,
339,
347,
664,
63,
7617,
8,
277,
12,
336,
344,
304,
267,
372,
291,
14,
697,
14,
1628,
3862,
1710,
360,
4859,
627,
4442,
13064,
6038,
1305,
275,
450,
83,
297,
3303,
24987,
1524,
19686,
467,
465,
63,
807,
29,
549,
2788,
16,
61,
339,
347,
1678,
63,
7617,
8,
277,
12,
336,
344,
12,
2196,
3259,
304,
267,
291,
14,
697,
14,
1628,
3862,
1710,
360,
10383,
13064,
11543,
2196,
3259,
2458,
83,
6038,
1305,
2458,
83,
297,
2574,
24987,
1524,
2355,
3259,
12,
336,
344,
566,
339,
347,
664,
63,
20285,
397,
8,
277,
12,
892,
63,
1188,
304,
267,
289,
361,
324,
397,
275,
291,
14,
697,
14,
1628,
3862,
1710,
360,
4859,
627,
4442,
30205,
11474,
297,
465,
63,
807,
29,
549,
9,
267,
289,
361,
324,
397,
14,
740,
8,
1222,
63,
1188,
9,
267,
372,
3355,
8,
20285,
397,
12,
790,
29,
20832,
360,
1188,
1333,
199,
199,
318,
1967,
63,
10590,
8,
10590,
304,
272,
862,
26,
267,
1967,
275,
1109,
8,
10590,
9,
267,
372,
413,
340,
1967,
665,
413,
587,
6891,
340,
1967,
690,
6891,
587,
1967,
272,
871,
1722,
26,
268,
372,
413,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
747,
199,
504,
4182,
492,
1242,
7416,
199,
504,
26752,
14,
3494,
492,
10533,
199,
504,
26752,
14,
12390,
492,
577,
748,
12,
5024,
12,
15231,
199,
199,
2846,
5449,
275,
283,
3249,
66,
13,
4659,
7,
199,
17873,
63,
7639,
275,
283,
8644,
921,
11861,
68,
464,
332,
26,
11861,
697,
1529,
19437,
83,
26,
1153,
1690,
15,
5006,
63,
7617,
7,
450,
6249,
5449,
199,
199,
533,
577,
279,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1817,
29,
403,
12,
4203,
63,
890,
29,
24,
304,
267,
291,
14,
697,
275,
577,
748,
8,
17873,
63,
7639,
12,
12810,
63,
3827,
29,
797,
12,
4203,
63,
890,
29,
2293,
63,
890,
9,
267,
340,
1817,
508,
283,
15943,
356,
288,
291,
14,
697,
14,
4640,
63,
1224,
360,
15943,
297,
5024,
360,
2355,
3259,
297,
283,
4115,
1333,
267,
916,
1817,
508,
283,
38,
361,
11474,
356,
288,
291,
14,
697,
14,
4640,
63,
1224,
360,
38,
361,
11474,
297,
5024,
360,
1188,
1333,
339,
347,
664,
63,
7617,
8,
277,
12,
336,
344,
304,
267,
327,
13510,
658,
1637,
461,
29,
549,
64,
1742,
293,
2310,
10238,
701,
11257,
10947,
314,
7143,
267,
327,
402,
2005,
2222,
13,
397,
2464,
1009,
3004,
14,
2779,
1630,
627,
1397,
10,
5965,
2581,
314,
267,
327,
3050,
2058,
334,
390,
9329,
16904,
282,
15231,
83,
909,
626,
627,
15153,
506,
10,
6328,
680,
267,
372,
291,
14,
697,
8,
277,
14,
697,
14,
15943,
14,
344,
508,
336,
344,
680,
2416,
8,
1637,
461,
29,
549,
2788,
16,
1055,
305,
63,
807,
342,
339,
347,
1678,
63,
7617,
8,
277,
12,
336,
344,
12,
2196,
3259,
304,
267,
291,
14,
697,
8,
277,
14,
697,
14,
15943,
14,
344,
508,
336,
344,
680,
873,
8,
2355,
3259,
29,
2355,
3259,
9,
339,
347,
664,
63,
20285,
397,
8,
277,
12,
892,
63,
1188,
304,
267,
289,
361,
324,
397,
275,
291,
14,
697,
8,
277,
14,
697,
14,
38,
361,
11474,
680,
2416,
8,
1637,
461,
29,
549,
9,
267,
289,
361,
324,
397,
14,
6502,
14,
740,
8,
5810,
8,
1222,
63,
1188,
430,
267,
372,
289,
361,
324,
397,
14,
3191,
8,
20832,
360,
1188,
1333,
199,
199,
533,
13480,
36,
279,
8,
36,
279,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
7963,
36,
279,
12,
291,
2843,
826,
4533,
339,
347,
664,
63,
7617,
8,
277,
12,
336,
344,
304,
267,
372,
291,
14,
697,
14,
1628,
3862,
1710,
360,
4859,
627,
4442,
13064,
6038,
1305,
275,
450,
83,
297,
3303,
24987,
1524,
19686,
467,
465,
63,
807,
29,
549,
2788,
16,
61,
339,
347,
1678,
63,
7617,
8,
277,
12,
336,
344,
12,
2196,
3259,
304,
267,
291,
14,
697,
14,
1628,
3862,
1710,
360,
10383,
13064,
11543,
2196,
3259,
2458,
83,
6038,
1305,
2458,
83,
297,
2574,
24987,
1524,
2355,
3259,
12,
336,
344,
566,
339,
347,
664,
63,
20285,
397,
8,
277,
12,
892,
63,
1188,
304,
267,
289,
361,
324,
397,
275,
291,
14,
697,
14,
1628,
3862,
1710,
360,
4859,
627,
4442,
30205,
11474,
297,
465,
63,
807,
29,
549,
9,
267,
289,
361,
324,
397,
14,
740,
8,
1222,
63,
1188,
9,
267,
372,
3355,
8,
20285,
397,
12,
790,
29,
20832,
360,
1188,
1333,
199,
199,
318,
1967,
63,
10590,
8,
10590,
304,
272,
862,
26,
267,
1967,
275,
1109,
8,
10590,
9,
267,
372,
413,
340,
1967,
665,
413,
587,
6891,
340,
1967,
690,
6891,
587,
1967,
272,
871,
1722,
26,
268,
372,
413,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
josegfv/transfer_sh_track
|
transfer.py
|
1
|
7264
|
#!/usr/bin/python3
"""
Usage: transfer ( -l | -p | -u <file> | -d | -h)
Options:
-h Help.
-d Download file into your local folder
-l List files that have been uploaded to transfer.sh
-p Purge the files from list that have Expired
-u <file> Upload a file from a local folder to transfer.sh
This command requires to be followed by the full path of the
local file
Examples:
transfer -l
transfer -d
transfer -p
transfer -u ~/test.txt
"""
import os
import json
import datetime
import subprocess
from copy import deepcopy
try:
from docopt import docopt
except ImportError:
print("docopt library missing..\nPlease install by executing the following command:")
print("pip3 install docopt")
VERSION = "0.1.0"
HOME = ""
UPLOAD_COMMAND = "curl --upload-file "
DWNLOAD_COMMAND = "curl "
SITE = "https://transfer.sh/"
LOCAL_DB = "files_stored_in_transfer.json"
LOCAL_DB_FULL = ""
FILE_LIST = {}
NO_DAYS_TO_KEEP = 14
def purge_deleted_files_from_Db():
global HOME
global FILE_LIST
#print(FILE_LIST)
#print(LOCAL_DB_FULL)
temp_file_list = deepcopy(FILE_LIST)
for item, fn in temp_file_list.items():
if fn[2] == 'Expired':
print(" {}\t{}\t{} -> has been deleted\n".format(
item, fn[0], fn[1]))
del(FILE_LIST[item])
write_to_file_db(FILE_LIST, LOCAL_DB_FULL)
def read_from_files_db(list=False):
global FILE_LIST
global HOME
global LOCAL_DB_FULL
if os.name == 'posix':
HOME = os.environ['HOME']
LOCAL_DB_FULL = HOME + "/" + LOCAL_DB
else:
#HOME = "C:" + os.environ['HOMEPATH']
#LOCAL_DB_FULL = HOME + "\\" + LOCAL_DB
exit("Only to be used in Unix like machines (Linux, UX, OSX)")
#print(LOCAL_DB_FULL)
if os.path.isfile(LOCAL_DB_FULL):
with open(LOCAL_DB_FULL, 'r') as f:
text = f.read()
if text != "":
FILE_LIST = json.loads(text)
if list:
temp_file_list = deepcopy(FILE_LIST)
print(" ID\tURL\t\t\t\t\t\t\tDate\tStatus")
print("~"*90)
for item, fn in temp_file_list.items():
update_file_status(FILE_LIST, item)
write_to_file_db(FILE_LIST, LOCAL_DB_FULL)
for item, fn in FILE_LIST.items():
print(" {}\t{}\t{}\t{}\n".format(
item, fn[0], fn[1], fn[2]))
else:
print("======================")
print("Files DB is Empty, no files in Transfer.sh")
print("======================")
else:
if list:
print("======================")
print("DB File {} not found".format(LOCAL_DB_FULL))
print("======================")
print("Creating new DB file...")
command = "touch {}".format(LOCAL_DB_FULL)
res = subprocess.Popen(command.split(),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
if res.stdout.readline().decode() == '':
print("File {} created successfuly.".format(LOCAL_DB_FULL))
else:
print("Something happened: {}".format(res.stdout.readline().decode()))
def write_to_file_db(myDb, f_name):
today = datetime.date.today()
myDb = json.dumps(myDb, indent=1)
#print("Writing to {}".format(f_name))
#print(myDb)
with open(f_name, 'w') as f:
f.write(myDb)
def add_resultURL(URL):
global FILE_LIST
#print(URL)
if FILE_LIST == {}:
idx = 1
else:
idx = max(FILE_LIST.keys())
idx = int(idx) + 1
#print("Next Index: {}".format(idx))
FILE_LIST["{}".format(idx)] = [URL, str(datetime.date.today()), "Available"]
#print(FILE_LIST)
def upload_file(f_name):
global FILE_LIST
#print(f_name)
if os.path.isfile(f_name):
f_basename = os.path.basename(f_name)
command = "{}{} {}{}".format(UPLOAD_COMMAND, f_name, SITE, f_basename)
#command = "ls /home/jose/files_stored_in_transfer.json"
print("\nSending Command: " + command)
res = subprocess.Popen(command.split(),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
for i in range(4):
res_URL = res.stdout.readline().decode()
res_URL = res_URL.strip()
print(res_URL)
add_resultURL(res_URL)
else:
print("Check path, file do not exists")
try:
write_to_file_db(FILE_LIST, LOCAL_DB_FULL)
except Exception as e:
print(e)
def update_file_status(myDb, item):
#print("\nupdate DB file status")
today = datetime.date.today()
delta = datetime.timedelta(days=NO_DAYS_TO_KEEP)
expire_date = today - delta
y, m, d = myDb[item][1].split('-')
f_day = datetime.date(int(y), int(m), int(d))
#print("{} < {} ?".format(f_day, expire_date))
if f_day < expire_date:
#print(" Item {}\t Status Changed to Expired\n".format(item))
myDb[item][2] = "Expired"
#print(myDb)
def download_file():
read_from_files_db(list=True)
user_in = 0
try:
user_in = input("Please enter the ID number from the above list: ")
except ValueError as e:
print("Value needs to be an Integer from the ID list Above.")
except KeyboardInterrupt:
print("\nAction Interrupted, Goodbye!")
if user_in != 0:
selected = FILE_LIST[str(user_in)]
url_name = selected[0]
f_basename = url_name.split("/")
f_basename = str(f_basename[-1:])
print(str(f_basename[-1:]))
command = "{}{} -o {}".format(DWNLOAD_COMMAND, url_name, \
f_basename.strip("]['"))
#command = "ls /home/jose/files_stored_in_transfer.json"
print("\nSending Command: " + command)
res = subprocess.Popen(command.split(),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
for i in range(4):
result = res.stdout.readline().decode()
if result != '':
print("Not sure what happend : {}".format(result))
def main():
# Collects the arguments passed to the script from command line
arguments = docopt(__doc__, version=VERSION)
# Start by reading the information already existing in the files DB
read_from_files_db()
# add_resultURL('https://transfer.sh/fsdjifhu/test.json')
# Act upon the arguments passed
if arguments.get('-u') != None:
# Uploads file to transfer.sh and if successful adds the file to the DB
upload_file(arguments.get('-u'))
elif arguments.get("-l"):
# Lists the existing files in transfer.sh based on what is saved in DB
read_from_files_db(list=True)
elif arguments.get("-p"):
purge_deleted_files_from_Db()
elif arguments.get("-d"):
download_file()
else:
print("Something Wrong, we should not be here...")
if __name__ == '__main__':
main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
19,
199,
624,
199,
7692,
26,
9307,
334,
446,
76,
1204,
446,
80,
1204,
446,
85,
665,
493,
30,
1204,
446,
68,
1204,
446,
72,
9,
199,
199,
4558,
26,
523,
446,
72,
4519,
15456,
14,
523,
446,
68,
4519,
17955,
570,
1901,
2195,
2257,
4922,
523,
446,
76,
4519,
3820,
1584,
626,
1172,
2757,
14238,
370,
9307,
14,
609,
523,
446,
80,
4519,
23177,
303,
314,
1584,
687,
769,
626,
1172,
1316,
1038,
581,
523,
446,
85,
665,
493,
30,
755,
19149,
282,
570,
687,
282,
2257,
4922,
370,
9307,
14,
609,
2116,
961,
1414,
5074,
370,
506,
9437,
701,
314,
2615,
931,
402,
314,
2116,
2257,
570,
199,
199,
22787,
26,
272,
9307,
446,
76,
272,
9307,
446,
68,
272,
9307,
446,
80,
272,
9307,
446,
85,
6146,
15,
396,
14,
2424,
199,
199,
624,
199,
646,
747,
199,
646,
2022,
199,
646,
2197,
199,
646,
3873,
199,
504,
1331,
492,
14800,
199,
893,
26,
272,
687,
886,
32626,
492,
886,
32626,
199,
2590,
3545,
26,
272,
870,
480,
1117,
32626,
3555,
4124,
703,
60,
78,
8254,
3907,
701,
14043,
314,
2569,
1414,
9107,
272,
870,
480,
9983,
19,
3907,
886,
32626,
531,
421,
199,
4612,
275,
298,
16,
14,
17,
14,
16,
2,
199,
9524,
275,
3087,
199,
16418,
63,
10761,
275,
298,
17096,
1553,
5064,
13,
493,
298,
199,
36,
3705,
7405,
63,
10761,
275,
298,
17096,
298,
199,
7917,
275,
298,
2859,
921,
9609,
14,
609,
6687,
199,
7486,
63,
2846,
275,
298,
1725,
63,
16431,
63,
262,
63,
9609,
14,
1001,
2,
199,
7486,
63,
2846,
63,
14742,
275,
3087,
199,
3817,
63,
4924,
275,
1052,
199,
2826,
63,
25683,
63,
2566,
63,
32162,
275,
4329,
421,
199,
318,
18503,
63,
6062,
63,
1725,
63,
504,
63,
8882,
837,
272,
2288,
7781,
3635,
272,
2288,
13024,
63,
4924,
339,
327,
1361,
8,
3817,
63,
4924,
9,
339,
327,
1361,
8,
7486,
63,
2846,
63,
14742,
9,
272,
2388,
63,
493,
63,
513,
275,
14800,
8,
3817,
63,
4924,
9,
272,
367,
1242,
12,
4325,
315,
2388,
63,
493,
63,
513,
14,
1744,
837,
267,
340,
4325,
59,
18,
61,
508,
283,
20898,
356,
288,
870,
480,
22902,
84,
24423,
84,
2440,
1035,
965,
2757,
5463,
60,
78,
1674,
908,
8,
490,
1242,
12,
4325,
59,
16,
467,
4325,
59,
17,
2459,
288,
2150,
8,
3817,
63,
4924,
59,
1053,
566,
272,
2218,
63,
475,
63,
493,
63,
697,
8,
3817,
63,
4924,
12,
20639,
63,
2846,
63,
14742,
9,
421,
199,
318,
1586,
63,
504,
63,
1725,
63,
697,
8,
513,
29,
797,
304,
272,
2288,
13024,
63,
4924,
272,
2288,
7781,
3635,
272,
2288,
20639,
63,
2846,
63,
14742,
272,
340,
747,
14,
354,
508,
283,
9228,
356,
267,
7781,
3635,
275,
747,
14,
2314,
459,
9524,
418,
267,
20639,
63,
2846,
63,
14742,
275,
7781,
3635,
435,
10609,
435,
20639,
63,
2846,
272,
587,
26,
267,
327,
9524,
275,
298,
35,
5424,
435,
747,
14,
2314,
459,
9524,
3243,
418,
267,
327,
7486,
63,
2846,
63,
14742,
275,
7781,
3635,
435,
9926,
2,
435,
20639,
63,
2846,
267,
4458,
480,
5903,
370,
506,
1202,
315,
13074,
2839,
20601,
334,
14091,
12,
738,
56,
12,
32144,
6320,
339,
327,
1361,
8,
7486,
63,
2846,
63,
14742,
9,
272,
340,
747,
14,
515,
14,
6292,
8,
7486,
63,
2846,
63,
14742,
304,
267,
543,
1551,
8,
7486,
63,
2846,
63,
14742,
12,
283,
82,
358,
465,
289,
26,
288,
1318,
275,
289,
14,
739,
342,
288,
340,
1318,
1137,
10812,
355,
13024,
63,
4924,
275,
2022,
14,
3640,
8,
505,
9,
355,
340,
769,
26,
490,
2388,
63,
493,
63,
513,
275,
14800,
8,
3817,
63,
4924,
9,
490,
870,
480,
2870,
60,
84,
2632,
60,
84,
60,
84,
60,
84,
60,
84,
60,
84,
60,
84,
60,
84,
2506,
60,
84,
3694,
531,
490,
870,
20793,
31761,
2710,
9,
490,
367,
1242,
12,
4325,
315,
2388,
63,
493,
63,
513,
14,
1744,
837,
717,
1678,
63,
493,
63,
1205,
8,
3817,
63,
4924,
12,
1242,
9,
4951,
2218,
63,
475,
63,
493,
63,
697,
8,
3817,
63,
4924,
12,
20639,
63,
2846,
63,
14742,
9,
4951,
367,
1242,
12,
4325,
315,
13024,
63,
4924,
14,
1744,
837,
717,
870,
480,
22902,
84,
24423,
84,
24423,
84,
24423,
78,
1674,
908,
8,
1169,
1242,
12,
4325,
59,
16,
467,
4325,
59,
17,
467,
4325,
59,
18,
2459,
953,
587,
26,
355,
870,
480,
1280,
23476,
531,
355,
870,
480,
5535,
6249,
365,
9630,
12,
949,
1584,
315,
27507,
14,
609,
531,
355,
870,
480,
1280,
23476,
531,
339,
587,
26,
267,
340,
769,
26,
288,
870,
480,
1280,
23476,
531,
288,
870,
480,
2846,
3814,
1052,
440,
1911,
1674,
908,
8,
7486,
63,
2846,
63,
14742,
430,
288,
870,
480,
1280,
23476,
531,
267,
870,
480,
14380,
892,
6249,
570,
12594,
267,
1414,
275,
298,
12376,
8352,
908,
8,
7486,
63,
2846,
63,
14742,
9,
267,
522,
275,
3873,
14,
7942,
8,
1531,
14,
1294,
1062,
3044,
3839,
29,
5781,
14,
6089,
12,
3044,
4635,
29,
5781,
14,
13850,
9,
267,
340,
522,
14,
2703,
14,
6407,
1252,
2708,
342,
508,
8061,
288,
870,
480,
1173,
1052,
2737,
9512,
89,
15848,
908,
8,
7486,
63,
2846,
63,
14742,
430,
267,
587,
26,
288,
870,
480,
20641,
21056,
26,
8352,
908,
8,
470,
14,
2703,
14,
6407,
1252,
2708,
4059,
421,
199,
318,
2218,
63,
475,
63,
493,
63,
697,
8,
1662,
8882,
12,
289,
63,
354,
304,
272,
11168,
275,
2197,
14,
602,
14,
8136,
342,
272,
3002,
8882,
275,
2022,
14,
4180,
8,
1662,
8882,
12,
4363,
29,
17,
9,
272,
327,
1361,
480,
16646,
370,
8352,
908,
8,
70,
63,
354,
430,
272,
327,
1361,
8,
1662,
8882,
9,
272,
543,
1551,
8,
70,
63,
354,
12,
283,
87,
358,
465,
289,
26,
267,
289,
14,
952,
8,
1662,
8882,
9,
421,
199,
318,
1050,
63,
1099,
2632,
8,
2632,
304,
272,
2288,
13024,
63,
4924,
272,
327,
1361,
8,
2632,
9,
272,
340,
13024,
63,
4924,
508,
24702,
267,
4280,
275,
413,
272,
587,
26,
267,
4280,
275,
1390
] |
[
2647,
15,
1393,
15,
1548,
19,
199,
624,
199,
7692,
26,
9307,
334,
446,
76,
1204,
446,
80,
1204,
446,
85,
665,
493,
30,
1204,
446,
68,
1204,
446,
72,
9,
199,
199,
4558,
26,
523,
446,
72,
4519,
15456,
14,
523,
446,
68,
4519,
17955,
570,
1901,
2195,
2257,
4922,
523,
446,
76,
4519,
3820,
1584,
626,
1172,
2757,
14238,
370,
9307,
14,
609,
523,
446,
80,
4519,
23177,
303,
314,
1584,
687,
769,
626,
1172,
1316,
1038,
581,
523,
446,
85,
665,
493,
30,
755,
19149,
282,
570,
687,
282,
2257,
4922,
370,
9307,
14,
609,
2116,
961,
1414,
5074,
370,
506,
9437,
701,
314,
2615,
931,
402,
314,
2116,
2257,
570,
199,
199,
22787,
26,
272,
9307,
446,
76,
272,
9307,
446,
68,
272,
9307,
446,
80,
272,
9307,
446,
85,
6146,
15,
396,
14,
2424,
199,
199,
624,
199,
646,
747,
199,
646,
2022,
199,
646,
2197,
199,
646,
3873,
199,
504,
1331,
492,
14800,
199,
893,
26,
272,
687,
886,
32626,
492,
886,
32626,
199,
2590,
3545,
26,
272,
870,
480,
1117,
32626,
3555,
4124,
703,
60,
78,
8254,
3907,
701,
14043,
314,
2569,
1414,
9107,
272,
870,
480,
9983,
19,
3907,
886,
32626,
531,
421,
199,
4612,
275,
298,
16,
14,
17,
14,
16,
2,
199,
9524,
275,
3087,
199,
16418,
63,
10761,
275,
298,
17096,
1553,
5064,
13,
493,
298,
199,
36,
3705,
7405,
63,
10761,
275,
298,
17096,
298,
199,
7917,
275,
298,
2859,
921,
9609,
14,
609,
6687,
199,
7486,
63,
2846,
275,
298,
1725,
63,
16431,
63,
262,
63,
9609,
14,
1001,
2,
199,
7486,
63,
2846,
63,
14742,
275,
3087,
199,
3817,
63,
4924,
275,
1052,
199,
2826,
63,
25683,
63,
2566,
63,
32162,
275,
4329,
421,
199,
318,
18503,
63,
6062,
63,
1725,
63,
504,
63,
8882,
837,
272,
2288,
7781,
3635,
272,
2288,
13024,
63,
4924,
339,
327,
1361,
8,
3817,
63,
4924,
9,
339,
327,
1361,
8,
7486,
63,
2846,
63,
14742,
9,
272,
2388,
63,
493,
63,
513,
275,
14800,
8,
3817,
63,
4924,
9,
272,
367,
1242,
12,
4325,
315,
2388,
63,
493,
63,
513,
14,
1744,
837,
267,
340,
4325,
59,
18,
61,
508,
283,
20898,
356,
288,
870,
480,
22902,
84,
24423,
84,
2440,
1035,
965,
2757,
5463,
60,
78,
1674,
908,
8,
490,
1242,
12,
4325,
59,
16,
467,
4325,
59,
17,
2459,
288,
2150,
8,
3817,
63,
4924,
59,
1053,
566,
272,
2218,
63,
475,
63,
493,
63,
697,
8,
3817,
63,
4924,
12,
20639,
63,
2846,
63,
14742,
9,
421,
199,
318,
1586,
63,
504,
63,
1725,
63,
697,
8,
513,
29,
797,
304,
272,
2288,
13024,
63,
4924,
272,
2288,
7781,
3635,
272,
2288,
20639,
63,
2846,
63,
14742,
272,
340,
747,
14,
354,
508,
283,
9228,
356,
267,
7781,
3635,
275,
747,
14,
2314,
459,
9524,
418,
267,
20639,
63,
2846,
63,
14742,
275,
7781,
3635,
435,
10609,
435,
20639,
63,
2846,
272,
587,
26,
267,
327,
9524,
275,
298,
35,
5424,
435,
747,
14,
2314,
459,
9524,
3243,
418,
267,
327,
7486,
63,
2846,
63,
14742,
275,
7781,
3635,
435,
9926,
2,
435,
20639,
63,
2846,
267,
4458,
480,
5903,
370,
506,
1202,
315,
13074,
2839,
20601,
334,
14091,
12,
738,
56,
12,
32144,
6320,
339,
327,
1361,
8,
7486,
63,
2846,
63,
14742,
9,
272,
340,
747,
14,
515,
14,
6292,
8,
7486,
63,
2846,
63,
14742,
304,
267,
543,
1551,
8,
7486,
63,
2846,
63,
14742,
12,
283,
82,
358,
465,
289,
26,
288,
1318,
275,
289,
14,
739,
342,
288,
340,
1318,
1137,
10812,
355,
13024,
63,
4924,
275,
2022,
14,
3640,
8,
505,
9,
355,
340,
769,
26,
490,
2388,
63,
493,
63,
513,
275,
14800,
8,
3817,
63,
4924,
9,
490,
870,
480,
2870,
60,
84,
2632,
60,
84,
60,
84,
60,
84,
60,
84,
60,
84,
60,
84,
60,
84,
2506,
60,
84,
3694,
531,
490,
870,
20793,
31761,
2710,
9,
490,
367,
1242,
12,
4325,
315,
2388,
63,
493,
63,
513,
14,
1744,
837,
717,
1678,
63,
493,
63,
1205,
8,
3817,
63,
4924,
12,
1242,
9,
4951,
2218,
63,
475,
63,
493,
63,
697,
8,
3817,
63,
4924,
12,
20639,
63,
2846,
63,
14742,
9,
4951,
367,
1242,
12,
4325,
315,
13024,
63,
4924,
14,
1744,
837,
717,
870,
480,
22902,
84,
24423,
84,
24423,
84,
24423,
78,
1674,
908,
8,
1169,
1242,
12,
4325,
59,
16,
467,
4325,
59,
17,
467,
4325,
59,
18,
2459,
953,
587,
26,
355,
870,
480,
1280,
23476,
531,
355,
870,
480,
5535,
6249,
365,
9630,
12,
949,
1584,
315,
27507,
14,
609,
531,
355,
870,
480,
1280,
23476,
531,
339,
587,
26,
267,
340,
769,
26,
288,
870,
480,
1280,
23476,
531,
288,
870,
480,
2846,
3814,
1052,
440,
1911,
1674,
908,
8,
7486,
63,
2846,
63,
14742,
430,
288,
870,
480,
1280,
23476,
531,
267,
870,
480,
14380,
892,
6249,
570,
12594,
267,
1414,
275,
298,
12376,
8352,
908,
8,
7486,
63,
2846,
63,
14742,
9,
267,
522,
275,
3873,
14,
7942,
8,
1531,
14,
1294,
1062,
3044,
3839,
29,
5781,
14,
6089,
12,
3044,
4635,
29,
5781,
14,
13850,
9,
267,
340,
522,
14,
2703,
14,
6407,
1252,
2708,
342,
508,
8061,
288,
870,
480,
1173,
1052,
2737,
9512,
89,
15848,
908,
8,
7486,
63,
2846,
63,
14742,
430,
267,
587,
26,
288,
870,
480,
20641,
21056,
26,
8352,
908,
8,
470,
14,
2703,
14,
6407,
1252,
2708,
4059,
421,
199,
318,
2218,
63,
475,
63,
493,
63,
697,
8,
1662,
8882,
12,
289,
63,
354,
304,
272,
11168,
275,
2197,
14,
602,
14,
8136,
342,
272,
3002,
8882,
275,
2022,
14,
4180,
8,
1662,
8882,
12,
4363,
29,
17,
9,
272,
327,
1361,
480,
16646,
370,
8352,
908,
8,
70,
63,
354,
430,
272,
327,
1361,
8,
1662,
8882,
9,
272,
543,
1551,
8,
70,
63,
354,
12,
283,
87,
358,
465,
289,
26,
267,
289,
14,
952,
8,
1662,
8882,
9,
421,
199,
318,
1050,
63,
1099,
2632,
8,
2632,
304,
272,
2288,
13024,
63,
4924,
272,
327,
1361,
8,
2632,
9,
272,
340,
13024,
63,
4924,
508,
24702,
267,
4280,
275,
413,
272,
587,
26,
267,
4280,
275,
1390,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,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python/framework/test_combinations_test.py
|
9
|
5279
|
# 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.
# ==============================================================================
"""Tests generating test combinations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from collections import OrderedDict
from absl.testing import parameterized
from tensorflow.python.framework import test_combinations as combinations
from tensorflow.python.eager import test
class TestingCombinationsTest(test.TestCase):
def test_combine(self):
self.assertEqual([{
"a": 1,
"b": 2
}, {
"a": 1,
"b": 3
}, {
"a": 2,
"b": 2
}, {
"a": 2,
"b": 3
}], combinations.combine(a=[1, 2], b=[2, 3]))
def test_arguments_sorted(self):
self.assertEqual([
OrderedDict([("aa", 1), ("ab", 2)]),
OrderedDict([("aa", 1), ("ab", 3)]),
OrderedDict([("aa", 2), ("ab", 2)]),
OrderedDict([("aa", 2), ("ab", 3)])
], combinations.combine(ab=[2, 3], aa=[1, 2]))
def test_combine_single_parameter(self):
self.assertEqual([{
"a": 1,
"b": 2
}, {
"a": 2,
"b": 2
}], combinations.combine(a=[1, 2], b=2))
def test_add(self):
self.assertEqual(
[{
"a": 1
}, {
"a": 2
}, {
"b": 2
}, {
"b": 3
}],
combinations.combine(a=[1, 2]) + combinations.combine(b=[2, 3]))
def test_times(self):
c1 = combinations.combine(mode=["graph"], loss=["callable", "tensor"])
c2 = combinations.combine(mode=["eager"], loss=["callable"])
c3 = combinations.combine(distribution=["d1", "d2"])
c4 = combinations.times(c3, c1 + c2)
self.assertEqual([
OrderedDict([("distribution", "d1"), ("loss", "callable"),
("mode", "graph")]),
OrderedDict([("distribution", "d1"), ("loss", "tensor"),
("mode", "graph")]),
OrderedDict([("distribution", "d1"), ("loss", "callable"),
("mode", "eager")]),
OrderedDict([("distribution", "d2"), ("loss", "callable"),
("mode", "graph")]),
OrderedDict([("distribution", "d2"), ("loss", "tensor"),
("mode", "graph")]),
OrderedDict([("distribution", "d2"), ("loss", "callable"),
("mode", "eager")])
], c4)
def test_times_variable_arguments(self):
c1 = combinations.combine(mode=["graph", "eager"])
c2 = combinations.combine(optimizer=["adam", "gd"])
c3 = combinations.combine(distribution=["d1", "d2"])
c4 = combinations.times(c3, c1, c2)
self.assertEqual([
OrderedDict([("distribution", "d1"), ("mode", "graph"),
("optimizer", "adam")]),
OrderedDict([("distribution", "d1"), ("mode", "graph"),
("optimizer", "gd")]),
OrderedDict([("distribution", "d1"), ("mode", "eager"),
("optimizer", "adam")]),
OrderedDict([("distribution", "d1"), ("mode", "eager"),
("optimizer", "gd")]),
OrderedDict([("distribution", "d2"), ("mode", "graph"),
("optimizer", "adam")]),
OrderedDict([("distribution", "d2"), ("mode", "graph"),
("optimizer", "gd")]),
OrderedDict([("distribution", "d2"), ("mode", "eager"),
("optimizer", "adam")]),
OrderedDict([("distribution", "d2"), ("mode", "eager"),
("optimizer", "gd")])
], c4)
self.assertEqual(
combinations.combine(
mode=["graph", "eager"],
optimizer=["adam", "gd"],
distribution=["d1", "d2"]), c4)
def test_overlapping_keys(self):
c1 = combinations.combine(mode=["graph"], loss=["callable", "tensor"])
c2 = combinations.combine(mode=["eager"], loss=["callable"])
with self.assertRaisesRegexp(ValueError, ".*Keys.+overlap.+"):
_ = combinations.times(c1, c2)
@combinations.generate(combinations.combine(a=[1, 0], b=[2, 3], c=[1]))
class CombineTheTestSuite(parameterized.TestCase):
def test_add_things(self, a, b, c):
self.assertLessEqual(3, a + b + c)
self.assertLessEqual(a + b + c, 5)
def test_add_things_one_more(self, a, b, c):
self.assertLessEqual(3, a + b + c)
self.assertLessEqual(a + b + c, 5)
def not_a_test(self, a=0, b=0, c=0):
del a, b, c
self.fail()
def _test_but_private(self, a=0, b=0, c=0):
del a, b, c
self.fail()
# Check that nothing funny happens to a non-callable that starts with "_test".
test_member = 0
if __name__ == "__main__":
test.main()
|
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,
624,
2925,
12999,
511,
15821,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
5055,
492,
8773,
199,
199,
504,
2853,
76,
14,
4776,
492,
29526,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
18026,
465,
15821,
199,
504,
3228,
14,
1548,
14,
10283,
492,
511,
421,
199,
533,
11940,
17039,
1298,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
63,
13307,
8,
277,
304,
272,
291,
14,
629,
779,
91,
267,
298,
65,
582,
413,
12,
267,
298,
66,
582,
499,
272,
1660,
469,
267,
298,
65,
582,
413,
12,
267,
298,
66,
582,
650,
272,
1660,
469,
267,
298,
65,
582,
499,
12,
267,
298,
66,
582,
499,
272,
1660,
469,
267,
298,
65,
582,
499,
12,
267,
298,
66,
582,
650,
272,
19971,
15821,
14,
13307,
8,
65,
1524,
17,
12,
499,
467,
330,
1524,
18,
12,
650,
2459,
819,
347,
511,
63,
4958,
63,
5917,
8,
277,
304,
272,
291,
14,
629,
779,
267,
8773,
27187,
2158,
401,
413,
395,
1689,
371,
401,
499,
16636,
267,
8773,
27187,
2158,
401,
413,
395,
1689,
371,
401,
650,
16636,
267,
8773,
27187,
2158,
401,
499,
395,
1689,
371,
401,
499,
16636,
267,
8773,
27187,
2158,
401,
499,
395,
1689,
371,
401,
650,
3948,
272,
2156,
15821,
14,
13307,
8,
371,
1524,
18,
12,
650,
467,
18319,
1524,
17,
12,
499,
2459,
819,
347,
511,
63,
13307,
63,
4780,
63,
5329,
8,
277,
304,
272,
291,
14,
629,
779,
91,
267,
298,
65,
582,
413,
12,
267,
298,
66,
582,
499,
272,
1660,
469,
267,
298,
65,
582,
499,
12,
267,
298,
66,
582,
499,
272,
19971,
15821,
14,
13307,
8,
65,
1524,
17,
12,
499,
467,
330,
29,
18,
430,
819,
347,
511,
63,
525,
8,
277,
304,
272,
291,
14,
629,
8,
267,
8910,
288,
298,
65,
582,
413,
267,
1660,
469,
288,
298,
65,
582,
499,
267,
1660,
469,
288,
298,
66,
582,
499,
267,
1660,
469,
288,
298,
66,
582,
650,
267,
19971,
267,
15821,
14,
13307,
8,
65,
1524,
17,
12,
499,
566,
435,
15821,
14,
13307,
8,
66,
1524,
18,
12,
650,
2459,
819,
347,
511,
63,
4508,
8,
277,
304,
272,
286,
17,
275,
15821,
14,
13307,
8,
632,
6270,
2180,
2255,
5621,
6270,
8296,
401,
298,
3128,
3135,
272,
286,
18,
275,
15821,
14,
13307,
8,
632,
6270,
10283,
2255,
5621,
6270,
8296,
3135,
272,
286,
19,
275,
15821,
14,
13307,
8,
4972,
6270,
68,
17,
401,
298,
68,
18,
3135,
272,
286,
20,
275,
15821,
14,
4508,
8,
67,
19,
12,
286,
17,
435,
286,
18,
9,
272,
291,
14,
629,
779,
267,
8773,
27187,
4972,
401,
298,
68,
17,
1288,
1689,
4358,
401,
298,
8296,
1288,
2151,
1689,
632,
401,
298,
2180,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
17,
1288,
1689,
4358,
401,
298,
3128,
1288,
2151,
1689,
632,
401,
298,
2180,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
17,
1288,
1689,
4358,
401,
298,
8296,
1288,
2151,
1689,
632,
401,
298,
10283,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
18,
1288,
1689,
4358,
401,
298,
8296,
1288,
2151,
1689,
632,
401,
298,
2180,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
18,
1288,
1689,
4358,
401,
298,
3128,
1288,
2151,
1689,
632,
401,
298,
2180,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
18,
1288,
1689,
4358,
401,
298,
8296,
1288,
2151,
1689,
632,
401,
298,
10283,
13403,
272,
2156,
286,
20,
9,
819,
347,
511,
63,
4508,
63,
1975,
63,
4958,
8,
277,
304,
272,
286,
17,
275,
15821,
14,
13307,
8,
632,
6270,
2180,
401,
298,
10283,
3135,
272,
286,
18,
275,
15821,
14,
13307,
8,
12290,
6270,
27679,
401,
298,
7136,
3135,
272,
286,
19,
275,
15821,
14,
13307,
8,
4972,
6270,
68,
17,
401,
298,
68,
18,
3135,
272,
286,
20,
275,
15821,
14,
4508,
8,
67,
19,
12,
286,
17,
12,
286,
18,
9,
272,
291,
14,
629,
779,
267,
8773,
27187,
4972,
401,
298,
68,
17,
1288,
1689,
632,
401,
298,
2180,
1288,
2151,
1689,
12290,
401,
298,
27679,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
17,
1288,
1689,
632,
401,
298,
2180,
1288,
2151,
1689,
12290,
401,
298,
7136,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
17,
1288,
1689,
632,
401,
298,
10283,
1288,
2151,
1689,
12290,
401,
298,
27679,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
17,
1288,
1689,
632,
401,
298,
10283,
1288,
2151,
1689,
12290,
401,
298,
7136,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
18,
1288,
1689,
632,
401,
298,
2180,
1288,
2151,
1689,
12290,
401,
298,
27679,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
18,
1288,
1689,
632,
401,
298,
2180,
1288,
2151,
1689,
12290,
401,
298,
7136,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
18,
1288,
1689,
632,
401,
298,
10283,
1288,
2151,
1689,
12290,
401,
298,
27679,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
18,
1288,
1689,
632,
401,
298,
10283,
1288,
2151,
1689,
12290,
401,
298,
7136,
13403,
272,
2156,
286,
20,
9,
272,
291,
14,
629,
8,
267,
15821,
14,
13307,
8
] |
[
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,
624,
2925,
12999,
511,
15821,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
5055,
492,
8773,
199,
199,
504,
2853,
76,
14,
4776,
492,
29526,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
18026,
465,
15821,
199,
504,
3228,
14,
1548,
14,
10283,
492,
511,
421,
199,
533,
11940,
17039,
1298,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
63,
13307,
8,
277,
304,
272,
291,
14,
629,
779,
91,
267,
298,
65,
582,
413,
12,
267,
298,
66,
582,
499,
272,
1660,
469,
267,
298,
65,
582,
413,
12,
267,
298,
66,
582,
650,
272,
1660,
469,
267,
298,
65,
582,
499,
12,
267,
298,
66,
582,
499,
272,
1660,
469,
267,
298,
65,
582,
499,
12,
267,
298,
66,
582,
650,
272,
19971,
15821,
14,
13307,
8,
65,
1524,
17,
12,
499,
467,
330,
1524,
18,
12,
650,
2459,
819,
347,
511,
63,
4958,
63,
5917,
8,
277,
304,
272,
291,
14,
629,
779,
267,
8773,
27187,
2158,
401,
413,
395,
1689,
371,
401,
499,
16636,
267,
8773,
27187,
2158,
401,
413,
395,
1689,
371,
401,
650,
16636,
267,
8773,
27187,
2158,
401,
499,
395,
1689,
371,
401,
499,
16636,
267,
8773,
27187,
2158,
401,
499,
395,
1689,
371,
401,
650,
3948,
272,
2156,
15821,
14,
13307,
8,
371,
1524,
18,
12,
650,
467,
18319,
1524,
17,
12,
499,
2459,
819,
347,
511,
63,
13307,
63,
4780,
63,
5329,
8,
277,
304,
272,
291,
14,
629,
779,
91,
267,
298,
65,
582,
413,
12,
267,
298,
66,
582,
499,
272,
1660,
469,
267,
298,
65,
582,
499,
12,
267,
298,
66,
582,
499,
272,
19971,
15821,
14,
13307,
8,
65,
1524,
17,
12,
499,
467,
330,
29,
18,
430,
819,
347,
511,
63,
525,
8,
277,
304,
272,
291,
14,
629,
8,
267,
8910,
288,
298,
65,
582,
413,
267,
1660,
469,
288,
298,
65,
582,
499,
267,
1660,
469,
288,
298,
66,
582,
499,
267,
1660,
469,
288,
298,
66,
582,
650,
267,
19971,
267,
15821,
14,
13307,
8,
65,
1524,
17,
12,
499,
566,
435,
15821,
14,
13307,
8,
66,
1524,
18,
12,
650,
2459,
819,
347,
511,
63,
4508,
8,
277,
304,
272,
286,
17,
275,
15821,
14,
13307,
8,
632,
6270,
2180,
2255,
5621,
6270,
8296,
401,
298,
3128,
3135,
272,
286,
18,
275,
15821,
14,
13307,
8,
632,
6270,
10283,
2255,
5621,
6270,
8296,
3135,
272,
286,
19,
275,
15821,
14,
13307,
8,
4972,
6270,
68,
17,
401,
298,
68,
18,
3135,
272,
286,
20,
275,
15821,
14,
4508,
8,
67,
19,
12,
286,
17,
435,
286,
18,
9,
272,
291,
14,
629,
779,
267,
8773,
27187,
4972,
401,
298,
68,
17,
1288,
1689,
4358,
401,
298,
8296,
1288,
2151,
1689,
632,
401,
298,
2180,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
17,
1288,
1689,
4358,
401,
298,
3128,
1288,
2151,
1689,
632,
401,
298,
2180,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
17,
1288,
1689,
4358,
401,
298,
8296,
1288,
2151,
1689,
632,
401,
298,
10283,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
18,
1288,
1689,
4358,
401,
298,
8296,
1288,
2151,
1689,
632,
401,
298,
2180,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
18,
1288,
1689,
4358,
401,
298,
3128,
1288,
2151,
1689,
632,
401,
298,
2180,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
18,
1288,
1689,
4358,
401,
298,
8296,
1288,
2151,
1689,
632,
401,
298,
10283,
13403,
272,
2156,
286,
20,
9,
819,
347,
511,
63,
4508,
63,
1975,
63,
4958,
8,
277,
304,
272,
286,
17,
275,
15821,
14,
13307,
8,
632,
6270,
2180,
401,
298,
10283,
3135,
272,
286,
18,
275,
15821,
14,
13307,
8,
12290,
6270,
27679,
401,
298,
7136,
3135,
272,
286,
19,
275,
15821,
14,
13307,
8,
4972,
6270,
68,
17,
401,
298,
68,
18,
3135,
272,
286,
20,
275,
15821,
14,
4508,
8,
67,
19,
12,
286,
17,
12,
286,
18,
9,
272,
291,
14,
629,
779,
267,
8773,
27187,
4972,
401,
298,
68,
17,
1288,
1689,
632,
401,
298,
2180,
1288,
2151,
1689,
12290,
401,
298,
27679,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
17,
1288,
1689,
632,
401,
298,
2180,
1288,
2151,
1689,
12290,
401,
298,
7136,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
17,
1288,
1689,
632,
401,
298,
10283,
1288,
2151,
1689,
12290,
401,
298,
27679,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
17,
1288,
1689,
632,
401,
298,
10283,
1288,
2151,
1689,
12290,
401,
298,
7136,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
18,
1288,
1689,
632,
401,
298,
2180,
1288,
2151,
1689,
12290,
401,
298,
27679,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
18,
1288,
1689,
632,
401,
298,
2180,
1288,
2151,
1689,
12290,
401,
298,
7136,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
18,
1288,
1689,
632,
401,
298,
10283,
1288,
2151,
1689,
12290,
401,
298,
27679,
531,
2522,
267,
8773,
27187,
4972,
401,
298,
68,
18,
1288,
1689,
632,
401,
298,
10283,
1288,
2151,
1689,
12290,
401,
298,
7136,
13403,
272,
2156,
286,
20,
9,
272,
291,
14,
629,
8,
267,
15821,
14,
13307,
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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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
] |
dotpmrcunha/gnuradio
|
docs/doxygen/doxyxml/generated/index.py
|
344
|
1871
|
#!/usr/bin/env python
"""
Generated Mon Feb 9 19:08:05 2009 by generateDS.py.
"""
from xml.dom import minidom
import os
import sys
import compound
import indexsuper as supermod
class DoxygenTypeSub(supermod.DoxygenType):
def __init__(self, version=None, compound=None):
supermod.DoxygenType.__init__(self, version, compound)
def find_compounds_and_members(self, details):
"""
Returns a list of all compounds and their members which match details
"""
results = []
for compound in self.compound:
members = compound.find_members(details)
if members:
results.append([compound, members])
else:
if details.match(compound):
results.append([compound, []])
return results
supermod.DoxygenType.subclass = DoxygenTypeSub
# end class DoxygenTypeSub
class CompoundTypeSub(supermod.CompoundType):
def __init__(self, kind=None, refid=None, name='', member=None):
supermod.CompoundType.__init__(self, kind, refid, name, member)
def find_members(self, details):
"""
Returns a list of all members which match details
"""
results = []
for member in self.member:
if details.match(member):
results.append(member)
return results
supermod.CompoundType.subclass = CompoundTypeSub
# end class CompoundTypeSub
class MemberTypeSub(supermod.MemberType):
def __init__(self, kind=None, refid=None, name=''):
supermod.MemberType.__init__(self, kind, refid, name)
supermod.MemberType.subclass = MemberTypeSub
# end class MemberTypeSub
def parse(inFilename):
doc = minidom.parse(inFilename)
rootNode = doc.documentElement
rootObj = supermod.DoxygenType.factory()
rootObj.build(rootNode)
return rootObj
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
199,
12706,
10953,
21141,
221,
1749,
5851,
26,
2036,
26,
1717,
8937,
701,
3550,
3177,
14,
647,
14,
199,
624,
199,
199,
504,
2748,
14,
4556,
492,
19165,
199,
199,
646,
747,
199,
646,
984,
199,
646,
16487,
199,
199,
646,
1478,
4792,
465,
1613,
1494,
199,
199,
533,
4226,
20515,
804,
2610,
8,
4792,
1494,
14,
2585,
20515,
804,
304,
272,
347,
636,
826,
721,
277,
12,
1015,
29,
403,
12,
16487,
29,
403,
304,
267,
1613,
1494,
14,
2585,
20515,
804,
855,
826,
721,
277,
12,
1015,
12,
16487,
9,
339,
347,
2342,
63,
15278,
83,
63,
460,
63,
6334,
8,
277,
12,
2436,
304,
267,
408,
267,
1803,
282,
769,
402,
1006,
16487,
83,
436,
3932,
7556,
1314,
1336,
2436,
267,
408,
398,
2058,
275,
942,
267,
367,
16487,
315,
291,
14,
15278,
26,
288,
7556,
275,
16487,
14,
1623,
63,
6334,
8,
5087,
9,
288,
340,
7556,
26,
355,
2058,
14,
740,
779,
15278,
12,
7556,
566,
288,
587,
26,
355,
340,
2436,
14,
1431,
8,
15278,
304,
490,
2058,
14,
740,
779,
15278,
12,
942,
566,
398,
372,
2058,
199,
199,
4792,
1494,
14,
2585,
20515,
804,
14,
6083,
275,
4226,
20515,
804,
2610,
199,
3,
1284,
1021,
4226,
20515,
804,
2610,
421,
199,
533,
3599,
1034,
804,
2610,
8,
4792,
1494,
14,
26552,
804,
304,
272,
347,
636,
826,
721,
277,
12,
4928,
29,
403,
12,
30817,
29,
403,
12,
536,
4581,
3653,
29,
403,
304,
267,
1613,
1494,
14,
26552,
804,
855,
826,
721,
277,
12,
4928,
12,
30817,
12,
536,
12,
3653,
9,
339,
347,
2342,
63,
6334,
8,
277,
12,
2436,
304,
267,
408,
267,
1803,
282,
769,
402,
1006,
7556,
1314,
1336,
2436,
267,
408,
398,
2058,
275,
942,
398,
367,
3653,
315,
291,
14,
1114,
26,
288,
340,
2436,
14,
1431,
8,
1114,
304,
355,
2058,
14,
740,
8,
1114,
9,
398,
372,
2058,
199,
199,
4792,
1494,
14,
26552,
804,
14,
6083,
275,
3599,
1034,
804,
2610,
199,
3,
1284,
1021,
3599,
1034,
804,
2610,
421,
199,
533,
14409,
804,
2610,
8,
4792,
1494,
14,
7021,
804,
304,
339,
347,
636,
826,
721,
277,
12,
4928,
29,
403,
12,
30817,
29,
403,
12,
536,
9280,
267,
1613,
1494,
14,
7021,
804,
855,
826,
721,
277,
12,
4928,
12,
30817,
12,
536,
9,
199,
199,
4792,
1494,
14,
7021,
804,
14,
6083,
275,
14409,
804,
2610,
199,
3,
1284,
1021,
14409,
804,
2610,
421,
199,
318,
2198,
8,
262,
8117,
304,
339,
1382,
275,
19165,
14,
1122,
8,
262,
8117,
9,
272,
1738,
1716,
275,
1382,
14,
22464,
272,
1738,
5665,
275,
1613,
1494,
14,
2585,
20515,
804,
14,
3702,
342,
272,
1738,
5665,
14,
1506,
8,
1231,
1716,
9,
339,
372,
1738,
5665,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
199,
12706,
10953,
21141,
221,
1749,
5851,
26,
2036,
26,
1717,
8937,
701,
3550,
3177,
14,
647,
14,
199,
624,
199,
199,
504,
2748,
14,
4556,
492,
19165,
199,
199,
646,
747,
199,
646,
984,
199,
646,
16487,
199,
199,
646,
1478,
4792,
465,
1613,
1494,
199,
199,
533,
4226,
20515,
804,
2610,
8,
4792,
1494,
14,
2585,
20515,
804,
304,
272,
347,
636,
826,
721,
277,
12,
1015,
29,
403,
12,
16487,
29,
403,
304,
267,
1613,
1494,
14,
2585,
20515,
804,
855,
826,
721,
277,
12,
1015,
12,
16487,
9,
339,
347,
2342,
63,
15278,
83,
63,
460,
63,
6334,
8,
277,
12,
2436,
304,
267,
408,
267,
1803,
282,
769,
402,
1006,
16487,
83,
436,
3932,
7556,
1314,
1336,
2436,
267,
408,
398,
2058,
275,
942,
267,
367,
16487,
315,
291,
14,
15278,
26,
288,
7556,
275,
16487,
14,
1623,
63,
6334,
8,
5087,
9,
288,
340,
7556,
26,
355,
2058,
14,
740,
779,
15278,
12,
7556,
566,
288,
587,
26,
355,
340,
2436,
14,
1431,
8,
15278,
304,
490,
2058,
14,
740,
779,
15278,
12,
942,
566,
398,
372,
2058,
199,
199,
4792,
1494,
14,
2585,
20515,
804,
14,
6083,
275,
4226,
20515,
804,
2610,
199,
3,
1284,
1021,
4226,
20515,
804,
2610,
421,
199,
533,
3599,
1034,
804,
2610,
8,
4792,
1494,
14,
26552,
804,
304,
272,
347,
636,
826,
721,
277,
12,
4928,
29,
403,
12,
30817,
29,
403,
12,
536,
4581,
3653,
29,
403,
304,
267,
1613,
1494,
14,
26552,
804,
855,
826,
721,
277,
12,
4928,
12,
30817,
12,
536,
12,
3653,
9,
339,
347,
2342,
63,
6334,
8,
277,
12,
2436,
304,
267,
408,
267,
1803,
282,
769,
402,
1006,
7556,
1314,
1336,
2436,
267,
408,
398,
2058,
275,
942,
398,
367,
3653,
315,
291,
14,
1114,
26,
288,
340,
2436,
14,
1431,
8,
1114,
304,
355,
2058,
14,
740,
8,
1114,
9,
398,
372,
2058,
199,
199,
4792,
1494,
14,
26552,
804,
14,
6083,
275,
3599,
1034,
804,
2610,
199,
3,
1284,
1021,
3599,
1034,
804,
2610,
421,
199,
533,
14409,
804,
2610,
8,
4792,
1494,
14,
7021,
804,
304,
339,
347,
636,
826,
721,
277,
12,
4928,
29,
403,
12,
30817,
29,
403,
12,
536,
9280,
267,
1613,
1494,
14,
7021,
804,
855,
826,
721,
277,
12,
4928,
12,
30817,
12,
536,
9,
199,
199,
4792,
1494,
14,
7021,
804,
14,
6083,
275,
14409,
804,
2610,
199,
3,
1284,
1021,
14409,
804,
2610,
421,
199,
318,
2198,
8,
262,
8117,
304,
339,
1382,
275,
19165,
14,
1122,
8,
262,
8117,
9,
272,
1738,
1716,
275,
1382,
14,
22464,
272,
1738,
5665,
275,
1613,
1494,
14,
2585,
20515,
804,
14,
3702,
342,
272,
1738,
5665,
14,
1506,
8,
1231,
1716,
9,
339,
372,
1738,
5665,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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regates import *
from django.contrib.gis.db.models.fields import GeometryField
from django.contrib.gis.db.models.sql.conversion import GeomField
class GeoAggregate(Aggregate):
# Default SQL template for spatial aggregates.
sql_template = '%(function)s(%(field)s)'
# Conversion class, if necessary.
conversion_class = None
# Flags for indicating the type of the aggregate.
is_extent = False
def __init__(self, col, source=None, is_summary=False, tolerance=0.05, **extra):
super(GeoAggregate, self).__init__(col, source, is_summary, **extra)
# Required by some Oracle aggregates.
self.tolerance = tolerance
# Can't use geographic aggregates on non-geometry fields.
if not isinstance(self.source, GeometryField):
raise ValueError('Geospatial aggregates only allowed on geometry fields.')
def as_sql(self, qn, connection):
"Return the aggregate, rendered as SQL."
if connection.ops.oracle:
self.extra['tolerance'] = self.tolerance
if hasattr(self.col, 'as_sql'):
field_name = self.col.as_sql(qn, connection)
elif isinstance(self.col, (list, tuple)):
field_name = '.'.join([qn(c) for c in self.col])
else:
field_name = self.col
sql_template, sql_function = connection.ops.spatial_aggregate_sql(self)
params = {
'function': sql_function,
'field': field_name
}
params.update(self.extra)
return sql_template % params
class Collect(GeoAggregate):
pass
class Extent(GeoAggregate):
is_extent = '2D'
class Extent3D(GeoAggregate):
is_extent = '3D'
class MakeLine(GeoAggregate):
pass
class Union(GeoAggregate):
pass
|
bsd-3-clause
|
[
504,
1639,
14,
697,
14,
992,
14,
3009,
14,
21622,
492,
627,
199,
504,
1639,
14,
2828,
14,
5668,
14,
697,
14,
992,
14,
955,
492,
30490,
199,
504,
1639,
14,
2828,
14,
5668,
14,
697,
14,
992,
14,
3009,
14,
15083,
492,
5346,
676,
792,
199,
199,
533,
8875,
10170,
8,
10170,
304,
272,
327,
3758,
5385,
1978,
367,
11469,
27535,
14,
272,
3875,
63,
1160,
275,
9487,
1593,
9,
83,
12473,
698,
9,
83,
3171,
339,
327,
1448,
1023,
1021,
12,
340,
5784,
14,
272,
8603,
63,
533,
275,
488,
339,
327,
24870,
367,
9297,
314,
730,
402,
314,
9531,
14,
272,
365,
63,
11599,
275,
756,
339,
347,
636,
826,
721,
277,
12,
1048,
12,
1350,
29,
403,
12,
365,
63,
4705,
29,
797,
12,
13464,
29,
16,
14,
1717,
12,
1011,
2911,
304,
267,
1613,
8,
10748,
10170,
12,
291,
2843,
826,
721,
761,
12,
1350,
12,
365,
63,
4705,
12,
1011,
2911,
9,
398,
327,
11105,
701,
2005,
15309,
27535,
14,
267,
291,
14,
16312,
275,
13464,
398,
327,
6855,
1133,
675,
25637,
27535,
641,
2222,
13,
7660,
1504,
14,
267,
340,
440,
1228,
8,
277,
14,
1365,
12,
30490,
304,
288,
746,
1722,
360,
4240,
736,
9491,
27535,
1454,
4370,
641,
3400,
1504,
2659,
339,
347,
465,
63,
3009,
8,
277,
12,
18293,
12,
1950,
304,
267,
298,
1767,
314,
9531,
12,
8018,
465,
5385,
2122,
398,
340,
1950,
14,
1483,
14,
16404,
26,
288,
291,
14,
2911,
459,
16312,
418,
275,
291,
14,
16312,
398,
340,
2688,
8,
277,
14,
761,
12,
283,
305,
63,
3009,
735,
288,
901,
63,
354,
275,
291,
14,
761,
14,
305,
63,
3009,
8,
15156,
12,
1950,
9,
267,
916,
1228,
8,
277,
14,
761,
12,
334,
513,
12,
2008,
2298,
288,
901,
63,
354,
275,
15671,
904,
779,
15156,
8,
67,
9,
367,
286,
315,
291,
14,
761,
566,
267,
587,
26,
288,
901,
63,
354,
275,
291,
14,
761,
398,
3875,
63,
1160,
12,
3875,
63,
1593,
275,
1950,
14,
1483,
14,
11679,
63,
7516,
63,
3009,
8,
277,
9,
398,
1862,
275,
469,
288,
283,
1593,
356,
3875,
63,
1593,
12,
288,
283,
698,
356,
901,
63,
354,
267,
789,
267,
1862,
14,
873,
8,
277,
14,
2911,
9,
398,
372,
3875,
63,
1160,
450,
1862,
199,
199,
533,
19649,
8,
10748,
10170,
304,
272,
986,
199,
199,
533,
1316,
767,
8,
10748,
10170,
304,
272,
365,
63,
11599,
275,
283,
18,
36,
7,
199,
199,
533,
1316,
767,
19,
36,
8,
10748,
10170,
304,
272,
365,
63,
11599,
275,
283,
19,
36,
7,
199,
199,
533,
4155,
3049,
8,
10748,
10170,
304,
272,
986,
199,
199,
533,
15961,
8,
10748,
10170,
304,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
697,
14,
992,
14,
3009,
14,
21622,
492,
627,
199,
504,
1639,
14,
2828,
14,
5668,
14,
697,
14,
992,
14,
955,
492,
30490,
199,
504,
1639,
14,
2828,
14,
5668,
14,
697,
14,
992,
14,
3009,
14,
15083,
492,
5346,
676,
792,
199,
199,
533,
8875,
10170,
8,
10170,
304,
272,
327,
3758,
5385,
1978,
367,
11469,
27535,
14,
272,
3875,
63,
1160,
275,
9487,
1593,
9,
83,
12473,
698,
9,
83,
3171,
339,
327,
1448,
1023,
1021,
12,
340,
5784,
14,
272,
8603,
63,
533,
275,
488,
339,
327,
24870,
367,
9297,
314,
730,
402,
314,
9531,
14,
272,
365,
63,
11599,
275,
756,
339,
347,
636,
826,
721,
277,
12,
1048,
12,
1350,
29,
403,
12,
365,
63,
4705,
29,
797,
12,
13464,
29,
16,
14,
1717,
12,
1011,
2911,
304,
267,
1613,
8,
10748,
10170,
12,
291,
2843,
826,
721,
761,
12,
1350,
12,
365,
63,
4705,
12,
1011,
2911,
9,
398,
327,
11105,
701,
2005,
15309,
27535,
14,
267,
291,
14,
16312,
275,
13464,
398,
327,
6855,
1133,
675,
25637,
27535,
641,
2222,
13,
7660,
1504,
14,
267,
340,
440,
1228,
8,
277,
14,
1365,
12,
30490,
304,
288,
746,
1722,
360,
4240,
736,
9491,
27535,
1454,
4370,
641,
3400,
1504,
2659,
339,
347,
465,
63,
3009,
8,
277,
12,
18293,
12,
1950,
304,
267,
298,
1767,
314,
9531,
12,
8018,
465,
5385,
2122,
398,
340,
1950,
14,
1483,
14,
16404,
26,
288,
291,
14,
2911,
459,
16312,
418,
275,
291,
14,
16312,
398,
340,
2688,
8,
277,
14,
761,
12,
283,
305,
63,
3009,
735,
288,
901,
63,
354,
275,
291,
14,
761,
14,
305,
63,
3009,
8,
15156,
12,
1950,
9,
267,
916,
1228,
8,
277,
14,
761,
12,
334,
513,
12,
2008,
2298,
288,
901,
63,
354,
275,
15671,
904,
779,
15156,
8,
67,
9,
367,
286,
315,
291,
14,
761,
566,
267,
587,
26,
288,
901,
63,
354,
275,
291,
14,
761,
398,
3875,
63,
1160,
12,
3875,
63,
1593,
275,
1950,
14,
1483,
14,
11679,
63,
7516,
63,
3009,
8,
277,
9,
398,
1862,
275,
469,
288,
283,
1593,
356,
3875,
63,
1593,
12,
288,
283,
698,
356,
901,
63,
354,
267,
789,
267,
1862,
14,
873,
8,
277,
14,
2911,
9,
398,
372,
3875,
63,
1160,
450,
1862,
199,
199,
533,
19649,
8,
10748,
10170,
304,
272,
986,
199,
199,
533,
1316,
767,
8,
10748,
10170,
304,
272,
365,
63,
11599,
275,
283,
18,
36,
7,
199,
199,
533,
1316,
767,
19,
36,
8,
10748,
10170,
304,
272,
365,
63,
11599,
275,
283,
19,
36,
7,
199,
199,
533,
4155,
3049,
8,
10748,
10170,
304,
272,
986,
199,
199,
533,
15961,
8,
10748,
10170,
304,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
Red-M/CloudBot-legacy
|
plugins/cryptocoins.py
|
6
|
2418
|
from util import http, hook
## CONSTANTS
exchanges = {
"blockchain": {
"api_url": "https://blockchain.info/ticker",
"func": lambda data: u"Blockchain // Buy: \x0307${:,.2f}\x0f -"
u" Sell: \x0307${:,.2f}\x0f".format(data["USD"]["buy"], data["USD"]["sell"])
},
"coinbase": {
"api_url": "https://coinbase.com/api/v1/prices/spot_rate",
"func": lambda data: u"Coinbase // Current: \x0307${:,.2f}\x0f".format(float(data['amount']))
},
"bitpay": {
"api_url": "https://bitpay.com/api/rates",
"func": lambda data: u"Bitpay // Current: \x0307${:,.2f}\x0f".format(data[0]['rate'])
},
"bitstamp": {
"api_url": "https://www.bitstamp.net/api/ticker/",
"func": lambda data: u"BitStamp // Current: \x0307${:,.2f}\x0f - High: \x0307${:,.2f}\x0f -"
u" Low: \x0307${:,.2f}\x0f - Volume: {:,.2f} BTC".format(float(data['last']),
float(data['high']),
float(data['low']),
float(data['volume']))
}
}
## HOOK FUNCTIONS
@hook.command("btc", autohelp=False)
@hook.command(autohelp=False)
def bitcoin(inp):
"""bitcoin <exchange> -- Gets current exchange rate for bitcoins from several exchanges, default is Blockchain.
Supports MtGox, Bitpay, Coinbase and BitStamp."""
inp = inp.lower()
if inp:
if inp in exchanges:
exchange = exchanges[inp]
else:
return "Invalid Exchange"
else:
exchange = exchanges["blockchain"]
data = http.get_json(exchange["api_url"])
func = exchange["func"]
return func(data)
@hook.command("ltc", autohelp=False)
@hook.command(autohelp=False)
def litecoin(inp, message=None):
"""litecoin -- gets current exchange rate for litecoins from BTC-E"""
data = http.get_json("https://btc-e.com/api/2/ltc_usd/ticker")
ticker = data['ticker']
message("Current: \x0307${:,.2f}\x0f - High: \x0307${:,.2f}\x0f"
" - Low: \x0307${:,.2f}\x0f - Volume: {:,.2f} LTC".format(ticker['buy'], ticker['high'], ticker['low'],
ticker['vol_cur']))
|
gpl-3.0
|
[
504,
4884,
492,
1455,
12,
5759,
199,
199,
309,
21803,
1441,
51,
199,
199,
476,
6627,
275,
469,
272,
298,
1457,
4429,
582,
469,
267,
298,
1246,
63,
633,
582,
298,
2859,
921,
1457,
4429,
14,
815,
15,
28572,
401,
267,
298,
1532,
582,
2400,
666,
26,
399,
2,
3142,
4429,
5001,
4779,
89,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
446,
2,
2490,
399,
2,
428,
1697,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
1674,
908,
8,
576,
905,
1668,
36,
6611,
31240,
2255,
666,
905,
1668,
36,
6611,
23235,
3135,
272,
1660,
272,
298,
30488,
582,
469,
267,
298,
1246,
63,
633,
582,
298,
2859,
921,
30488,
14,
957,
15,
1246,
15,
86,
17,
15,
32434,
15,
15185,
63,
1866,
401,
267,
298,
1532,
582,
2400,
666,
26,
399,
2,
967,
262,
1095,
5001,
9338,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
1674,
908,
8,
1609,
8,
576,
459,
4606,
5156,
272,
1660,
272,
298,
2075,
5989,
582,
469,
267,
298,
1246,
63,
633,
582,
298,
2859,
921,
2075,
5989,
14,
957,
15,
1246,
15,
17153,
401,
267,
298,
1532,
582,
2400,
666,
26,
399,
2,
4734,
5989,
5001,
9338,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
1674,
908,
8,
576,
59,
16,
2733,
1866,
1105,
272,
1660,
272,
298,
2075,
2359,
582,
469,
267,
298,
1246,
63,
633,
582,
298,
2859,
921,
1544,
14,
2075,
2359,
14,
846,
15,
1246,
15,
28572,
10665,
267,
298,
1532,
582,
2400,
666,
26,
399,
2,
4734,
16649,
5001,
9338,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
446,
16332,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
446,
2,
2490,
399,
2,
21766,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
446,
15018,
26,
469,
11941,
14,
18,
70,
93,
699,
5708,
1674,
908,
8,
1609,
8,
576,
459,
2019,
3815,
12268,
420,
2069,
8,
576,
459,
6260,
3815,
12268,
420,
2069,
8,
576,
459,
674,
3815,
12268,
420,
2069,
8,
576,
459,
2405,
5156,
272,
789,
199,
93,
421,
199,
309,
7781,
3593,
21498,
19560,
199,
199,
32,
3664,
14,
1531,
480,
66,
3641,
401,
2599,
3437,
29,
797,
9,
199,
32,
3664,
14,
1531,
8,
2495,
3437,
29,
797,
9,
199,
318,
27214,
8,
11416,
304,
272,
408,
22816,
665,
14197,
30,
1553,
14509,
1453,
15343,
6634,
367,
4546,
331,
3617,
687,
9978,
444,
6627,
12,
849,
365,
8651,
4429,
14,
272,
32090,
603,
84,
7250,
88,
12,
10199,
5989,
12,
1849,
262,
1095,
436,
10199,
16649,
1041,
272,
10702,
275,
10702,
14,
2325,
342,
339,
340,
10702,
26,
267,
340,
10702,
315,
444,
6627,
26,
288,
15343,
275,
444,
6627,
59,
11416,
61,
267,
587,
26,
288,
372,
298,
3364,
25655,
2,
272,
587,
26,
267,
15343,
275,
444,
6627,
905,
1457,
4429,
937,
339,
666,
275,
1455,
14,
362,
63,
1001,
8,
14197,
905,
1246,
63,
633,
3135,
272,
2562,
275,
15343,
905,
1532,
937,
272,
372,
2562,
8,
576,
9,
421,
199,
32,
3664,
14,
1531,
480,
76,
3641,
401,
2599,
3437,
29,
797,
9,
199,
32,
3664,
14,
1531,
8,
2495,
3437,
29,
797,
9,
199,
318,
1212,
266,
9061,
8,
11416,
12,
1245,
29,
403,
304,
272,
408,
5333,
9061,
1553,
7545,
1453,
15343,
6634,
367,
1212,
266,
331,
3617,
687,
699,
5708,
13,
37,
624,
272,
666,
275,
1455,
14,
362,
63,
1001,
480,
2859,
921,
66,
3641,
13,
69,
14,
957,
15,
1246,
15,
18,
15,
76,
3641,
63,
31597,
15,
28572,
531,
272,
32721,
275,
666,
459,
28572,
418,
272,
1245,
480,
5639,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
446,
16332,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
2,
288,
298,
446,
21766,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
446,
15018,
26,
469,
11941,
14,
18,
70,
93,
491,
5708,
1674,
908,
8,
28572,
459,
31240,
995,
32721,
459,
6260,
995,
32721,
459,
674,
995,
6684,
420,
32721,
459,
5650,
63,
895,
5156,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4884,
492,
1455,
12,
5759,
199,
199,
309,
21803,
1441,
51,
199,
199,
476,
6627,
275,
469,
272,
298,
1457,
4429,
582,
469,
267,
298,
1246,
63,
633,
582,
298,
2859,
921,
1457,
4429,
14,
815,
15,
28572,
401,
267,
298,
1532,
582,
2400,
666,
26,
399,
2,
3142,
4429,
5001,
4779,
89,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
446,
2,
2490,
399,
2,
428,
1697,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
1674,
908,
8,
576,
905,
1668,
36,
6611,
31240,
2255,
666,
905,
1668,
36,
6611,
23235,
3135,
272,
1660,
272,
298,
30488,
582,
469,
267,
298,
1246,
63,
633,
582,
298,
2859,
921,
30488,
14,
957,
15,
1246,
15,
86,
17,
15,
32434,
15,
15185,
63,
1866,
401,
267,
298,
1532,
582,
2400,
666,
26,
399,
2,
967,
262,
1095,
5001,
9338,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
1674,
908,
8,
1609,
8,
576,
459,
4606,
5156,
272,
1660,
272,
298,
2075,
5989,
582,
469,
267,
298,
1246,
63,
633,
582,
298,
2859,
921,
2075,
5989,
14,
957,
15,
1246,
15,
17153,
401,
267,
298,
1532,
582,
2400,
666,
26,
399,
2,
4734,
5989,
5001,
9338,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
1674,
908,
8,
576,
59,
16,
2733,
1866,
1105,
272,
1660,
272,
298,
2075,
2359,
582,
469,
267,
298,
1246,
63,
633,
582,
298,
2859,
921,
1544,
14,
2075,
2359,
14,
846,
15,
1246,
15,
28572,
10665,
267,
298,
1532,
582,
2400,
666,
26,
399,
2,
4734,
16649,
5001,
9338,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
446,
16332,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
446,
2,
2490,
399,
2,
21766,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
446,
15018,
26,
469,
11941,
14,
18,
70,
93,
699,
5708,
1674,
908,
8,
1609,
8,
576,
459,
2019,
3815,
12268,
420,
2069,
8,
576,
459,
6260,
3815,
12268,
420,
2069,
8,
576,
459,
674,
3815,
12268,
420,
2069,
8,
576,
459,
2405,
5156,
272,
789,
199,
93,
421,
199,
309,
7781,
3593,
21498,
19560,
199,
199,
32,
3664,
14,
1531,
480,
66,
3641,
401,
2599,
3437,
29,
797,
9,
199,
32,
3664,
14,
1531,
8,
2495,
3437,
29,
797,
9,
199,
318,
27214,
8,
11416,
304,
272,
408,
22816,
665,
14197,
30,
1553,
14509,
1453,
15343,
6634,
367,
4546,
331,
3617,
687,
9978,
444,
6627,
12,
849,
365,
8651,
4429,
14,
272,
32090,
603,
84,
7250,
88,
12,
10199,
5989,
12,
1849,
262,
1095,
436,
10199,
16649,
1041,
272,
10702,
275,
10702,
14,
2325,
342,
339,
340,
10702,
26,
267,
340,
10702,
315,
444,
6627,
26,
288,
15343,
275,
444,
6627,
59,
11416,
61,
267,
587,
26,
288,
372,
298,
3364,
25655,
2,
272,
587,
26,
267,
15343,
275,
444,
6627,
905,
1457,
4429,
937,
339,
666,
275,
1455,
14,
362,
63,
1001,
8,
14197,
905,
1246,
63,
633,
3135,
272,
2562,
275,
15343,
905,
1532,
937,
272,
372,
2562,
8,
576,
9,
421,
199,
32,
3664,
14,
1531,
480,
76,
3641,
401,
2599,
3437,
29,
797,
9,
199,
32,
3664,
14,
1531,
8,
2495,
3437,
29,
797,
9,
199,
318,
1212,
266,
9061,
8,
11416,
12,
1245,
29,
403,
304,
272,
408,
5333,
9061,
1553,
7545,
1453,
15343,
6634,
367,
1212,
266,
331,
3617,
687,
699,
5708,
13,
37,
624,
272,
666,
275,
1455,
14,
362,
63,
1001,
480,
2859,
921,
66,
3641,
13,
69,
14,
957,
15,
1246,
15,
18,
15,
76,
3641,
63,
31597,
15,
28572,
531,
272,
32721,
275,
666,
459,
28572,
418,
272,
1245,
480,
5639,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
446,
16332,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
2,
288,
298,
446,
21766,
26,
971,
88,
16,
11516,
10545,
11941,
14,
18,
70,
4988,
88,
16,
70,
446,
15018,
26,
469,
11941,
14,
18,
70,
93,
491,
5708,
1674,
908,
8,
28572,
459,
31240,
995,
32721,
459,
6260,
995,
32721,
459,
674,
995,
6684,
420,
32721,
459,
5650,
63,
895,
5156,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
alisidd/tensorflow
|
tensorflow/contrib/learn/python/learn/preprocessing/categorical.py
|
153
|
4269
|
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Implements preprocessing transformers for categorical variables."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import math
import numpy as np
# pylint: disable=g-bad-import-order
from . import categorical_vocabulary
from ..learn_io.data_feeder import setup_processor_data_feeder
# pylint: enable=g-bad-import-order
class CategoricalProcessor(object):
"""Maps documents to sequences of word ids.
As a common convention, Nan values are handled as unknown tokens.
Both float('nan') and np.nan are accepted.
"""
def __init__(self, min_frequency=0, share=False, vocabularies=None):
"""Initializes a CategoricalProcessor instance.
Args:
min_frequency: Minimum frequency of categories in the vocabulary.
share: Share vocabulary between variables.
vocabularies: list of CategoricalVocabulary objects for each variable in
the input dataset.
Attributes:
vocabularies_: list of CategoricalVocabulary objects.
"""
self.min_frequency = min_frequency
self.share = share
self.vocabularies_ = vocabularies
def freeze(self, freeze=True):
"""Freeze or unfreeze all vocabularies.
Args:
freeze: Boolean, indicate if vocabularies should be frozen.
"""
for vocab in self.vocabularies_:
vocab.freeze(freeze)
def fit(self, x, unused_y=None):
"""Learn a vocabulary dictionary of all categories in `x`.
Args:
x: numpy matrix or iterable of lists/numpy arrays.
unused_y: to match fit format signature of estimators.
Returns:
self
"""
x = setup_processor_data_feeder(x)
for row in x:
# Create vocabularies if not given.
if self.vocabularies_ is None:
# If not share, one per column, else one shared across.
if not self.share:
self.vocabularies_ = [
categorical_vocabulary.CategoricalVocabulary() for _ in row
]
else:
vocab = categorical_vocabulary.CategoricalVocabulary()
self.vocabularies_ = [vocab for _ in row]
for idx, value in enumerate(row):
# Nans are handled as unknowns.
if (isinstance(value, float) and math.isnan(value)) or value == np.nan:
continue
self.vocabularies_[idx].add(value)
if self.min_frequency > 0:
for vocab in self.vocabularies_:
vocab.trim(self.min_frequency)
self.freeze()
return self
def fit_transform(self, x, unused_y=None):
"""Learn the vocabulary dictionary and return indexies of categories.
Args:
x: numpy matrix or iterable of lists/numpy arrays.
unused_y: to match fit_transform signature of estimators.
Returns:
x: iterable, [n_samples]. Category-id matrix.
"""
self.fit(x)
return self.transform(x)
def transform(self, x):
"""Transform documents to category-id matrix.
Converts categories to ids give fitted vocabulary from `fit` or
one provided in the constructor.
Args:
x: numpy matrix or iterable of lists/numpy arrays.
Yields:
x: iterable, [n_samples]. Category-id matrix.
"""
self.freeze()
x = setup_processor_data_feeder(x)
for row in x:
output_row = []
for idx, value in enumerate(row):
# Return <UNK> when it's Nan.
if (isinstance(value, float) and math.isnan(value)) or value == np.nan:
output_row.append(0)
continue
output_row.append(self.vocabularies_[idx].get(value))
yield np.array(output_row, dtype=np.int64)
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
199,
624,
29452,
26471,
1752,
22932,
367,
22138,
2860,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
3473,
199,
646,
2680,
465,
980,
199,
199,
3,
4287,
26,
3507,
29,
71,
13,
4087,
13,
646,
13,
1648,
199,
504,
1275,
492,
22138,
63,
18681,
199,
504,
2508,
4643,
63,
2308,
14,
576,
63,
11195,
424,
492,
3272,
63,
6459,
63,
576,
63,
11195,
424,
199,
3,
4287,
26,
4756,
29,
71,
13,
4087,
13,
646,
13,
1648,
421,
199,
533,
31227,
10438,
8,
785,
304,
523,
408,
24995,
8247,
370,
8013,
402,
4349,
2762,
14,
819,
3709,
282,
2863,
16129,
12,
653,
290,
1338,
787,
8860,
465,
5809,
4645,
14,
523,
17650,
2069,
360,
4304,
358,
436,
980,
14,
4304,
787,
10226,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
1748,
63,
11132,
29,
16,
12,
8663,
29,
797,
12,
11181,
348,
3433,
29,
403,
304,
272,
408,
23489,
282,
31227,
10438,
1256,
14,
339,
3033,
26,
489,
1748,
63,
11132,
26,
22466,
9857,
402,
9695,
315,
314,
17515,
14,
489,
8663,
26,
5244,
1530,
17515,
3382,
2860,
14,
489,
11181,
348,
3433,
26,
769,
402,
31227,
54,
6607,
11439,
2251,
367,
1924,
1750,
315,
267,
314,
1324,
4789,
14,
339,
9382,
26,
489,
11181,
348,
3433,
10388,
769,
402,
31227,
54,
6607,
11439,
2251,
14,
272,
408,
272,
291,
14,
827,
63,
11132,
275,
1748,
63,
11132,
272,
291,
14,
6251,
275,
8663,
272,
291,
14,
9953,
348,
3433,
63,
275,
11181,
348,
3433,
819,
347,
22778,
8,
277,
12,
22778,
29,
549,
304,
272,
408,
10146,
806,
503,
625,
18459,
1006,
11181,
348,
3433,
14,
339,
3033,
26,
489,
22778,
26,
9411,
12,
6623,
340,
11181,
348,
3433,
1077,
506,
8101,
14,
272,
408,
272,
367,
11181,
315,
291,
14,
9953,
348,
3433,
10388,
489,
11181,
14,
18459,
8,
18459,
9,
819,
347,
5542,
8,
277,
12,
671,
12,
9563,
63,
89,
29,
403,
304,
272,
408,
21424,
282,
17515,
2600,
402,
1006,
9695,
315,
658,
88,
2313,
339,
3033,
26,
489,
671,
26,
2680,
3634,
503,
6076,
402,
5548,
15,
4714,
6572,
14,
489,
9563,
63,
89,
26,
370,
1336,
5542,
1475,
4955,
402,
23155,
14,
339,
1803,
26,
489,
291,
272,
408,
272,
671,
275,
3272,
63,
6459,
63,
576,
63,
11195,
424,
8,
88,
9,
272,
367,
1962,
315,
671,
26,
489,
327,
2790,
11181,
348,
3433,
340,
440,
1627,
14,
489,
340,
291,
14,
9953,
348,
3433,
63,
365,
488,
26,
267,
327,
982,
440,
8663,
12,
1373,
1126,
2763,
12,
587,
1373,
5709,
9371,
14,
267,
340,
440,
291,
14,
6251,
26,
881,
291,
14,
9953,
348,
3433,
63,
275,
359,
1598,
22138,
63,
18681,
14,
23306,
54,
6607,
11439,
342,
367,
485,
315,
1962,
881,
1622,
267,
587,
26,
881,
11181,
275,
22138,
63,
18681,
14,
23306,
54,
6607,
11439,
342,
881,
291,
14,
9953,
348,
3433,
63,
275,
359,
9953,
367,
485,
315,
1962,
61,
489,
367,
4280,
12,
574,
315,
3874,
8,
1143,
304,
267,
327,
653,
796,
787,
8860,
465,
625,
14996,
561,
14,
267,
340,
334,
6074,
8,
585,
12,
2069,
9,
436,
3473,
14,
12936,
8,
585,
430,
503,
574,
508,
980,
14,
4304,
26,
881,
1980,
267,
291,
14,
9953,
348,
3433,
9925,
2996,
1055,
525,
8,
585,
9,
272,
340,
291,
14,
827,
63,
11132,
690,
378,
26,
489,
367,
11181,
315,
291,
14,
9953,
348,
3433,
10388,
267,
11181,
14,
12263,
8,
277,
14,
827,
63,
11132,
9,
272,
291,
14,
18459,
342,
272,
372,
291,
819,
347,
5542,
63,
4711,
8,
277,
12,
671,
12,
9563,
63,
89,
29,
403,
304,
272,
408,
21424,
314,
17515,
2600,
436,
372,
1478,
1500,
402,
9695,
14,
339,
3033,
26,
489,
671,
26,
2680,
3634,
503,
6076,
402,
5548,
15,
4714,
6572,
14,
489,
9563,
63,
89,
26,
370,
1336,
5542,
63,
4711,
4955,
402,
23155,
14,
339,
1803,
26,
489,
671,
26,
6076,
12,
359,
78,
63,
3356,
1055,
13573,
13,
344,
3634,
14,
272,
408,
272,
291,
14,
3269,
8,
88,
9,
272,
372,
291,
14,
4711,
8,
88,
9,
819,
347,
5793,
8,
277,
12,
671,
304,
272,
408,
6939,
8247,
370,
4637,
13,
344,
3634,
14,
339,
19107,
9695,
370,
2762,
8120,
26093,
17515,
687,
658,
3269,
64,
503,
272,
1373,
2741,
315,
314,
3787,
14,
339,
3033,
26,
489,
671,
26,
2680,
3634,
503,
6076,
402,
5548,
15,
4714,
6572,
14,
339,
23771,
83,
26,
489,
671,
26,
6076,
12,
359,
78,
63,
3356,
1055,
13573,
13,
344,
3634,
14,
272,
408,
272,
291,
14,
18459,
342,
272,
671,
275,
3272,
63,
6459,
63,
576,
63,
11195,
424,
8,
88,
9,
272,
367,
1962,
315,
671,
26,
489,
1072,
63,
1143,
275,
942,
489,
367,
4280,
12,
574,
315,
3874,
8,
1143,
304,
267,
327,
1432,
665,
8019,
30,
1380,
652,
1159,
653,
290,
14,
267,
340,
334,
6074,
8,
585,
12,
2069,
9,
436,
3473,
14,
12936,
8,
585,
430,
503,
574,
508,
980,
14,
4304,
26,
881,
1072,
63,
1143,
14,
740,
8,
16,
9,
881,
1980,
267,
1072,
63,
1143,
14,
740,
8,
277,
14,
9953,
348,
3433,
9925,
2996,
1055,
362
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
199,
624,
29452,
26471,
1752,
22932,
367,
22138,
2860,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
3473,
199,
646,
2680,
465,
980,
199,
199,
3,
4287,
26,
3507,
29,
71,
13,
4087,
13,
646,
13,
1648,
199,
504,
1275,
492,
22138,
63,
18681,
199,
504,
2508,
4643,
63,
2308,
14,
576,
63,
11195,
424,
492,
3272,
63,
6459,
63,
576,
63,
11195,
424,
199,
3,
4287,
26,
4756,
29,
71,
13,
4087,
13,
646,
13,
1648,
421,
199,
533,
31227,
10438,
8,
785,
304,
523,
408,
24995,
8247,
370,
8013,
402,
4349,
2762,
14,
819,
3709,
282,
2863,
16129,
12,
653,
290,
1338,
787,
8860,
465,
5809,
4645,
14,
523,
17650,
2069,
360,
4304,
358,
436,
980,
14,
4304,
787,
10226,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
1748,
63,
11132,
29,
16,
12,
8663,
29,
797,
12,
11181,
348,
3433,
29,
403,
304,
272,
408,
23489,
282,
31227,
10438,
1256,
14,
339,
3033,
26,
489,
1748,
63,
11132,
26,
22466,
9857,
402,
9695,
315,
314,
17515,
14,
489,
8663,
26,
5244,
1530,
17515,
3382,
2860,
14,
489,
11181,
348,
3433,
26,
769,
402,
31227,
54,
6607,
11439,
2251,
367,
1924,
1750,
315,
267,
314,
1324,
4789,
14,
339,
9382,
26,
489,
11181,
348,
3433,
10388,
769,
402,
31227,
54,
6607,
11439,
2251,
14,
272,
408,
272,
291,
14,
827,
63,
11132,
275,
1748,
63,
11132,
272,
291,
14,
6251,
275,
8663,
272,
291,
14,
9953,
348,
3433,
63,
275,
11181,
348,
3433,
819,
347,
22778,
8,
277,
12,
22778,
29,
549,
304,
272,
408,
10146,
806,
503,
625,
18459,
1006,
11181,
348,
3433,
14,
339,
3033,
26,
489,
22778,
26,
9411,
12,
6623,
340,
11181,
348,
3433,
1077,
506,
8101,
14,
272,
408,
272,
367,
11181,
315,
291,
14,
9953,
348,
3433,
10388,
489,
11181,
14,
18459,
8,
18459,
9,
819,
347,
5542,
8,
277,
12,
671,
12,
9563,
63,
89,
29,
403,
304,
272,
408,
21424,
282,
17515,
2600,
402,
1006,
9695,
315,
658,
88,
2313,
339,
3033,
26,
489,
671,
26,
2680,
3634,
503,
6076,
402,
5548,
15,
4714,
6572,
14,
489,
9563,
63,
89,
26,
370,
1336,
5542,
1475,
4955,
402,
23155,
14,
339,
1803,
26,
489,
291,
272,
408,
272,
671,
275,
3272,
63,
6459,
63,
576,
63,
11195,
424,
8,
88,
9,
272,
367,
1962,
315,
671,
26,
489,
327,
2790,
11181,
348,
3433,
340,
440,
1627,
14,
489,
340,
291,
14,
9953,
348,
3433,
63,
365,
488,
26,
267,
327,
982,
440,
8663,
12,
1373,
1126,
2763,
12,
587,
1373,
5709,
9371,
14,
267,
340,
440,
291,
14,
6251,
26,
881,
291,
14,
9953,
348,
3433,
63,
275,
359,
1598,
22138,
63,
18681,
14,
23306,
54,
6607,
11439,
342,
367,
485,
315,
1962,
881,
1622,
267,
587,
26,
881,
11181,
275,
22138,
63,
18681,
14,
23306,
54,
6607,
11439,
342,
881,
291,
14,
9953,
348,
3433,
63,
275,
359,
9953,
367,
485,
315,
1962,
61,
489,
367,
4280,
12,
574,
315,
3874,
8,
1143,
304,
267,
327,
653,
796,
787,
8860,
465,
625,
14996,
561,
14,
267,
340,
334,
6074,
8,
585,
12,
2069,
9,
436,
3473,
14,
12936,
8,
585,
430,
503,
574,
508,
980,
14,
4304,
26,
881,
1980,
267,
291,
14,
9953,
348,
3433,
9925,
2996,
1055,
525,
8,
585,
9,
272,
340,
291,
14,
827,
63,
11132,
690,
378,
26,
489,
367,
11181,
315,
291,
14,
9953,
348,
3433,
10388,
267,
11181,
14,
12263,
8,
277,
14,
827,
63,
11132,
9,
272,
291,
14,
18459,
342,
272,
372,
291,
819,
347,
5542,
63,
4711,
8,
277,
12,
671,
12,
9563,
63,
89,
29,
403,
304,
272,
408,
21424,
314,
17515,
2600,
436,
372,
1478,
1500,
402,
9695,
14,
339,
3033,
26,
489,
671,
26,
2680,
3634,
503,
6076,
402,
5548,
15,
4714,
6572,
14,
489,
9563,
63,
89,
26,
370,
1336,
5542,
63,
4711,
4955,
402,
23155,
14,
339,
1803,
26,
489,
671,
26,
6076,
12,
359,
78,
63,
3356,
1055,
13573,
13,
344,
3634,
14,
272,
408,
272,
291,
14,
3269,
8,
88,
9,
272,
372,
291,
14,
4711,
8,
88,
9,
819,
347,
5793,
8,
277,
12,
671,
304,
272,
408,
6939,
8247,
370,
4637,
13,
344,
3634,
14,
339,
19107,
9695,
370,
2762,
8120,
26093,
17515,
687,
658,
3269,
64,
503,
272,
1373,
2741,
315,
314,
3787,
14,
339,
3033,
26,
489,
671,
26,
2680,
3634,
503,
6076,
402,
5548,
15,
4714,
6572,
14,
339,
23771,
83,
26,
489,
671,
26,
6076,
12,
359,
78,
63,
3356,
1055,
13573,
13,
344,
3634,
14,
272,
408,
272,
291,
14,
18459,
342,
272,
671,
275,
3272,
63,
6459,
63,
576,
63,
11195,
424,
8,
88,
9,
272,
367,
1962,
315,
671,
26,
489,
1072,
63,
1143,
275,
942,
489,
367,
4280,
12,
574,
315,
3874,
8,
1143,
304,
267,
327,
1432,
665,
8019,
30,
1380,
652,
1159,
653,
290,
14,
267,
340,
334,
6074,
8,
585,
12,
2069,
9,
436,
3473,
14,
12936,
8,
585,
430,
503,
574,
508,
980,
14,
4304,
26,
881,
1072,
63,
1143,
14,
740,
8,
16,
9,
881,
1980,
267,
1072,
63,
1143,
14,
740,
8,
277,
14,
9953,
348,
3433,
9925,
2996,
1055,
362,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
giubil/trackit
|
api/files/api/app/views/aws/account_management.py
|
1
|
9304
|
from datetime import datetime
from app import app
from app.authentication import with_login
from app.tasks import import_aws_client_bills, import_aws_elb_infos, process_aws_key
from flask import Blueprint, jsonify
from app.request_schema import with_request_schema
from app.models import db, AWSKey, AWSKeyS3Bucket
from app.es.awsdetailedlineitem import AWSDetailedLineitem
from app.aws_keys import with_aws_account, with_multiple_aws_accounts
from app.aws.utils import check_if_valid_key
from . import aws_key_schema, aws_key_edit_schema
from app.generate_csv import get_csv_links
import calendar
aws_account_management_bp = Blueprint('aws_account_management_bp', __name__)
@app.route('/aws/accounts', methods=['POST'])
@with_request_schema(aws_key_schema)
@with_login(True)
def post_aws_account(data, user):
"""---
post:
tags:
- aws
description: &desc Create AWS account
summary: *desc
produces:
- application/json
consumes:
- application/json
parameters:
- in: body
name: body
schema:
$ref: "#/definitions/AWSAccount"
responses:
200:
description: Registered account
schema:
$ref: "#/definitions/AWSAccount"
403:
description: Not logged in
409:
description: AWS account already registered for user
"""
if user:
if AWSKey.query.filter_by(id_user=user.id, key=data['key']).count():
return jsonify(error="Already registered"), 409
else:
key = AWSKey()
key.id_user = user.id
for data_key, data_value in data.iteritems():
setattr(key, data_key, data_value)
key.is_valid_key = check_if_valid_key(key.key, key.secret)
db.session.add(key)
db.session.commit()
import_aws_elb_infos.delay(key.id)
import_aws_client_bills.delay(key.id)
process_aws_key.delay(key.id)
return jsonify(aws_key_schema.dump(key)[0]), 200
else:
return jsonify(error="Forbidden"), 403
@app.route('/aws/accounts/<int:account_id>', methods=['PUT'])
@with_request_schema(aws_key_edit_schema)
@with_login(True)
def put_aws_account(data, user, account_id):
"""---
post:
tags:
- aws
description: &desc Modify an AWS account.
summary: *desc
produces:
- application/json
consumes:
- application/json
parameters:
- in: body
name: body
schema:
$ref: "#/definitions/AWSAccount"
responses:
200:
description: Registered account
schema:
$ref: "#/definitions/AWSAccount"
403:
description: Not logged in
"""
assert user
key = AWSKey.query.get(account_id)
if key and key.id_user == user.id:
for k, v in data.iteritems():
setattr(key, k, v)
key.is_valid_key = check_if_valid_key(key.key, key.secret)
db.session.commit()
db.session.refresh(key)
return jsonify(aws_key_schema.dump(key)[0]), 200
elif key:
return jsonify(error='Forbidden.'), 403
else:
return jsonify(error='Not found.'), 404
@app.route('/aws/accounts', methods=['GET'])
@with_login(True)
def get_aws_accounts(user):
"""---
get:
tags:
- aws
produces:
- application/json
description: &desc Get AWS accounts
summary: *desc
responses:
200:
description: List of AWS accounts
schema:
properties:
accounts:
type: array
items:
$ref: "#/definitions/AWSAccount"
403:
description: Not logged in
"""
if user:
now = datetime.utcnow()
date_from = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
date_to = now.replace(day=calendar.monthrange(date_from.year, date_from.month)[1], hour=23, minute=59,
second=59, microsecond=999999)
if user.admin:
res = []
keys = AWSKey.query.all()
for key in keys:
user_id = key.get_aws_user_id()
key_infos = aws_key_schema.dump(key)[0]
full = False if not user_id else AWSDetailedLineitem.keys_has_data(key.get_aws_user_id())
month = False if not full else AWSDetailedLineitem.keys_has_data(key.get_aws_user_id(), date_from=date_from, date_to=date_to)
key_infos['has_data_full'] = full
key_infos['has_data_month'] = month
if key.id_user != user.id:
if not key_infos['pretty']:
key_infos['pretty'] = key.user.email
else:
key_infos['pretty'] = key_infos['pretty'] + ' (' + key.user.email + ')'
res.append(key_infos)
return jsonify(accounts=res), 200
keys = []
for key in user.aws_keys:
user_id = key.get_aws_user_id()
key_infos = aws_key_schema.dump(key)[0]
full = False if not user_id else AWSDetailedLineitem.keys_has_data(key.get_aws_user_id())
month = False if not full else AWSDetailedLineitem.keys_has_data(key.get_aws_user_id(), date_from=date_from, date_to=date_to)
key_infos['has_data_full'] = full
key_infos['has_data_month'] = month
keys.append(key_infos)
return jsonify(accounts=keys), 200
else:
return jsonify(error="Forbidden"), 403
@app.route('/aws/accounts/m/<aws_key_ids:account_ids>', methods=['GET'])
@with_login(True)
@with_multiple_aws_accounts()
def aws_test_accounts_test(accounts):
"""---
get:
tags:
- aws
produces:
- application/json
description &desc Get multiple AWS accounts.
summary: *desc
responses:
200:
description: AWS accounts.
schema:
- $ref: "#/definitions/AWSAccount"
403:
description: Forbidden.
"""
return jsonify({
'accounts': [
aws_key_schema.dump(a)[0] for a in accounts
]
})
@app.route('/aws/accounts/<int:account_id>', methods=['GET'])
@with_login(True)
@with_aws_account()
def get_aws_account(user, account, account_id):
"""---
get:
tags:
- aws
produces:
- application/json
description: &desc Get AWS account
summary: *desc
responses:
200:
description: AWS account
schema:
$ref: "#/definitions/AWSAccount"
403:
description: Not logged in
404:
description: AWS account not registered
"""
if user:
return jsonify(aws_key_schema.dump(account)[0]), 200
else:
return jsonify(error="Forbidden"), 403
@app.route('/aws/accounts/<int:account_id>', methods=['DELETE'])
@with_login(True)
@with_aws_account()
def delete_aws_account(user, account, account_id):
"""---
delete:
tags:
- aws
description: &desc Delete AWS account
summary: *desc
responses:
200:
description: AWS account removed
403:
description: Not logged in
404:
description: AWS account not registered
"""
if user and account.id_user == user.id:
buckets = AWSKeyS3Bucket.query.filter_by(id_aws_key=account_id)
for bucket in buckets:
db.session.delete(bucket)
db.session.delete(account)
db.session.commit()
return jsonify({}), 200
else:
return jsonify(error="Forbidden"), 403
@app.route('/aws/accounts/<aws_key_ids:account_ids>/csv/export')
@with_login()
@with_multiple_aws_accounts()
def aws_accounts_m_csv_export(accounts):
"""---
get:
tags:
- aws
produces:
- application/json
description: &desc Get links where CSV Export is available
summary: *desc
responses:
200:
description: List links for CSV Export
schema:
properties:
csvs:
type: array
items:
properties:
name:
type: string
description:
type: string
link:
type: string
403:
description: Not logged in
404:
description: AWS account not registered
"""
return jsonify(csvs=get_csv_links())
|
apache-2.0
|
[
504,
2197,
492,
2197,
199,
504,
1145,
492,
1145,
199,
504,
1145,
14,
11725,
492,
543,
63,
2886,
199,
504,
1145,
14,
5054,
492,
492,
63,
7231,
63,
1258,
63,
66,
15350,
12,
492,
63,
7231,
63,
17778,
63,
14195,
12,
2112,
63,
7231,
63,
498,
199,
504,
7209,
492,
22447,
1361,
12,
23819,
199,
504,
1145,
14,
1069,
63,
3629,
492,
543,
63,
1069,
63,
3629,
199,
504,
1145,
14,
992,
492,
1592,
12,
10168,
1197,
12,
10168,
1197,
51,
19,
12311,
199,
504,
1145,
14,
397,
14,
7231,
19170,
604,
1053,
492,
437,
55,
3693,
1841,
1672,
3049,
1053,
199,
504,
1145,
14,
7231,
63,
1612,
492,
543,
63,
7231,
63,
2048,
12,
543,
63,
6048,
63,
7231,
63,
8370,
199,
504,
1145,
14,
7231,
14,
1208,
492,
1104,
63,
692,
63,
1078,
63,
498,
199,
504,
1275,
492,
11488,
63,
498,
63,
3629,
12,
11488,
63,
498,
63,
3773,
63,
3629,
199,
504,
1145,
14,
4208,
63,
4737,
492,
664,
63,
4737,
63,
4614,
199,
646,
11234,
199,
199,
7231,
63,
2048,
63,
8110,
63,
10913,
275,
22447,
1361,
360,
7231,
63,
2048,
63,
8110,
63,
10913,
297,
636,
354,
3368,
421,
199,
32,
571,
14,
4449,
2336,
7231,
15,
8370,
297,
3102,
2968,
4030,
1105,
199,
32,
1045,
63,
1069,
63,
3629,
8,
7231,
63,
498,
63,
3629,
9,
199,
32,
1045,
63,
2886,
8,
549,
9,
199,
318,
2963,
63,
7231,
63,
2048,
8,
576,
12,
922,
304,
272,
408,
2595,
272,
2963,
26,
267,
3762,
26,
288,
446,
11488,
267,
1369,
26,
1253,
3257,
2790,
10168,
2933,
267,
6212,
26,
627,
3257,
267,
16904,
26,
288,
446,
4223,
15,
1001,
267,
9451,
83,
26,
288,
446,
4223,
15,
1001,
267,
2633,
26,
288,
446,
315,
26,
2396,
1598,
536,
26,
2396,
1598,
4177,
26,
355,
2672,
1121,
26,
5426,
15,
15388,
15,
13226,
6009,
2,
267,
9320,
26,
288,
1926,
26,
355,
1369,
26,
5044,
5338,
2933,
355,
4177,
26,
490,
2672,
1121,
26,
5426,
15,
15388,
15,
13226,
6009,
2,
288,
13269,
26,
355,
1369,
26,
2832,
10367,
315,
288,
21292,
26,
355,
1369,
26,
10168,
2933,
2575,
7264,
367,
922,
272,
408,
272,
340,
922,
26,
267,
340,
10168,
1197,
14,
1131,
14,
1541,
63,
991,
8,
344,
63,
751,
29,
751,
14,
344,
12,
790,
29,
576,
459,
498,
13227,
835,
837,
288,
372,
23819,
8,
705,
628,
16760,
7264,
1288,
21292,
267,
587,
26,
288,
790,
275,
10168,
1197,
342,
288,
790,
14,
344,
63,
751,
275,
922,
14,
344,
288,
367,
666,
63,
498,
12,
666,
63,
585,
315,
666,
14,
4611,
837,
355,
5371,
8,
498,
12,
666,
63,
498,
12,
666,
63,
585,
9,
288,
790,
14,
374,
63,
1078,
63,
498,
275,
1104,
63,
692,
63,
1078,
63,
498,
8,
498,
14,
498,
12,
790,
14,
4731,
9,
288,
1592,
14,
1730,
14,
525,
8,
498,
9,
288,
1592,
14,
1730,
14,
3543,
342,
288,
492,
63,
7231,
63,
17778,
63,
14195,
14,
5814,
8,
498,
14,
344,
9,
288,
492,
63,
7231,
63,
1258,
63,
66,
15350,
14,
5814,
8,
498,
14,
344,
9,
288,
2112,
63,
7231,
63,
498,
14,
5814,
8,
498,
14,
344,
9,
288,
372,
23819,
8,
7231,
63,
498,
63,
3629,
14,
2724,
8,
498,
2788,
16,
2522,
1926,
272,
587,
26,
267,
372,
23819,
8,
705,
628,
17454,
1288,
13269,
421,
199,
32,
571,
14,
4449,
2336,
7231,
15,
8370,
8316,
442,
26,
2048,
63,
344,
4206,
3102,
2968,
4013,
1105,
199,
32,
1045,
63,
1069,
63,
3629,
8,
7231,
63,
498,
63,
3773,
63,
3629,
9,
199,
32,
1045,
63,
2886,
8,
549,
9,
199,
318,
5324,
63,
7231,
63,
2048,
8,
576,
12,
922,
12,
2933,
63,
344,
304,
272,
408,
2595,
272,
2963,
26,
267,
3762,
26,
288,
446,
11488,
267,
1369,
26,
1253,
3257,
22520,
376,
10168,
2933,
14,
267,
6212,
26,
627,
3257,
267,
16904,
26,
288,
446,
4223,
15,
1001,
267,
9451,
83,
26,
288,
446,
4223,
15,
1001,
267,
2633,
26,
288,
446,
315,
26,
2396,
1598,
536,
26,
2396,
1598,
4177,
26,
2116,
2672,
1121,
26,
5426,
15,
15388,
15,
13226,
6009,
2,
267,
9320,
26,
288,
1926,
26,
355,
1369,
26,
5044,
5338,
2933,
355,
4177,
26,
490,
2672,
1121,
26,
5426,
15,
15388,
15,
13226,
6009,
2,
288,
13269,
26,
355,
1369,
26,
2832,
10367,
315,
272,
408,
272,
702,
922,
272,
790,
275,
10168,
1197,
14,
1131,
14,
362,
8,
2048,
63,
344,
9,
272,
340,
790,
436,
790,
14,
344,
63,
751,
508,
922,
14,
344,
26,
267,
367,
1022,
12,
373,
315,
666,
14,
4611,
837,
288,
5371,
8,
498,
12,
1022,
12,
373,
9,
267,
790,
14,
374,
63,
1078,
63,
498,
275,
1104,
63,
692,
63,
1078,
63,
498,
8,
498,
14,
498,
12,
790,
14,
4731,
9,
267,
1592,
14,
1730,
14,
3543,
342,
267,
1592,
14,
1730,
14,
6635,
8,
498,
9,
267,
372,
23819,
8,
7231,
63,
498,
63,
3629,
14,
2724,
8,
498,
2788,
16,
2522,
1926,
272,
916,
790,
26,
267,
372,
23819,
8,
705,
534,
17454,
8038,
13269,
272,
587,
26,
267,
372,
23819,
8,
705,
534,
1763,
1911,
8038,
7901,
421,
199,
32,
571,
14,
4449,
2336,
7231,
15,
8370,
297,
3102,
2968,
2970,
1105,
199,
32,
1045,
63,
2886,
8,
549,
9,
199,
318,
664,
63,
7231,
63,
8370,
8,
751,
304,
272,
408,
2595,
272,
664,
26,
267,
3762,
26,
288,
446,
11488,
267,
16904,
26,
288,
446,
4223,
15,
1001,
267,
1369,
26,
1253,
3257,
2372,
10168,
12639,
267,
6212,
26,
627,
3257,
267,
9320,
26,
288,
1926,
26,
355,
1369,
26,
3820,
402,
10168,
12639,
355,
4177,
26,
490,
4382,
26,
717,
12639,
26,
1169,
730,
26,
1625,
1169,
2974,
26,
1816,
2672,
1121,
26,
5426,
15,
15388,
15,
13226,
6009,
2,
288,
13269,
26,
355,
1369,
26,
2832,
10367,
315,
272,
408,
272,
340,
922,
26,
267,
3063,
275,
2197,
14,
10779,
342,
267,
1434,
63,
504,
275,
3063,
14,
1814,
8,
2977,
29,
17,
12,
6925,
29,
16,
12,
12709,
29,
16,
12,
3499,
29,
16,
12,
25824,
29,
16,
9,
267,
1434,
63,
475
] |
[
2197,
492,
2197,
199,
504,
1145,
492,
1145,
199,
504,
1145,
14,
11725,
492,
543,
63,
2886,
199,
504,
1145,
14,
5054,
492,
492,
63,
7231,
63,
1258,
63,
66,
15350,
12,
492,
63,
7231,
63,
17778,
63,
14195,
12,
2112,
63,
7231,
63,
498,
199,
504,
7209,
492,
22447,
1361,
12,
23819,
199,
504,
1145,
14,
1069,
63,
3629,
492,
543,
63,
1069,
63,
3629,
199,
504,
1145,
14,
992,
492,
1592,
12,
10168,
1197,
12,
10168,
1197,
51,
19,
12311,
199,
504,
1145,
14,
397,
14,
7231,
19170,
604,
1053,
492,
437,
55,
3693,
1841,
1672,
3049,
1053,
199,
504,
1145,
14,
7231,
63,
1612,
492,
543,
63,
7231,
63,
2048,
12,
543,
63,
6048,
63,
7231,
63,
8370,
199,
504,
1145,
14,
7231,
14,
1208,
492,
1104,
63,
692,
63,
1078,
63,
498,
199,
504,
1275,
492,
11488,
63,
498,
63,
3629,
12,
11488,
63,
498,
63,
3773,
63,
3629,
199,
504,
1145,
14,
4208,
63,
4737,
492,
664,
63,
4737,
63,
4614,
199,
646,
11234,
199,
199,
7231,
63,
2048,
63,
8110,
63,
10913,
275,
22447,
1361,
360,
7231,
63,
2048,
63,
8110,
63,
10913,
297,
636,
354,
3368,
421,
199,
32,
571,
14,
4449,
2336,
7231,
15,
8370,
297,
3102,
2968,
4030,
1105,
199,
32,
1045,
63,
1069,
63,
3629,
8,
7231,
63,
498,
63,
3629,
9,
199,
32,
1045,
63,
2886,
8,
549,
9,
199,
318,
2963,
63,
7231,
63,
2048,
8,
576,
12,
922,
304,
272,
408,
2595,
272,
2963,
26,
267,
3762,
26,
288,
446,
11488,
267,
1369,
26,
1253,
3257,
2790,
10168,
2933,
267,
6212,
26,
627,
3257,
267,
16904,
26,
288,
446,
4223,
15,
1001,
267,
9451,
83,
26,
288,
446,
4223,
15,
1001,
267,
2633,
26,
288,
446,
315,
26,
2396,
1598,
536,
26,
2396,
1598,
4177,
26,
355,
2672,
1121,
26,
5426,
15,
15388,
15,
13226,
6009,
2,
267,
9320,
26,
288,
1926,
26,
355,
1369,
26,
5044,
5338,
2933,
355,
4177,
26,
490,
2672,
1121,
26,
5426,
15,
15388,
15,
13226,
6009,
2,
288,
13269,
26,
355,
1369,
26,
2832,
10367,
315,
288,
21292,
26,
355,
1369,
26,
10168,
2933,
2575,
7264,
367,
922,
272,
408,
272,
340,
922,
26,
267,
340,
10168,
1197,
14,
1131,
14,
1541,
63,
991,
8,
344,
63,
751,
29,
751,
14,
344,
12,
790,
29,
576,
459,
498,
13227,
835,
837,
288,
372,
23819,
8,
705,
628,
16760,
7264,
1288,
21292,
267,
587,
26,
288,
790,
275,
10168,
1197,
342,
288,
790,
14,
344,
63,
751,
275,
922,
14,
344,
288,
367,
666,
63,
498,
12,
666,
63,
585,
315,
666,
14,
4611,
837,
355,
5371,
8,
498,
12,
666,
63,
498,
12,
666,
63,
585,
9,
288,
790,
14,
374,
63,
1078,
63,
498,
275,
1104,
63,
692,
63,
1078,
63,
498,
8,
498,
14,
498,
12,
790,
14,
4731,
9,
288,
1592,
14,
1730,
14,
525,
8,
498,
9,
288,
1592,
14,
1730,
14,
3543,
342,
288,
492,
63,
7231,
63,
17778,
63,
14195,
14,
5814,
8,
498,
14,
344,
9,
288,
492,
63,
7231,
63,
1258,
63,
66,
15350,
14,
5814,
8,
498,
14,
344,
9,
288,
2112,
63,
7231,
63,
498,
14,
5814,
8,
498,
14,
344,
9,
288,
372,
23819,
8,
7231,
63,
498,
63,
3629,
14,
2724,
8,
498,
2788,
16,
2522,
1926,
272,
587,
26,
267,
372,
23819,
8,
705,
628,
17454,
1288,
13269,
421,
199,
32,
571,
14,
4449,
2336,
7231,
15,
8370,
8316,
442,
26,
2048,
63,
344,
4206,
3102,
2968,
4013,
1105,
199,
32,
1045,
63,
1069,
63,
3629,
8,
7231,
63,
498,
63,
3773,
63,
3629,
9,
199,
32,
1045,
63,
2886,
8,
549,
9,
199,
318,
5324,
63,
7231,
63,
2048,
8,
576,
12,
922,
12,
2933,
63,
344,
304,
272,
408,
2595,
272,
2963,
26,
267,
3762,
26,
288,
446,
11488,
267,
1369,
26,
1253,
3257,
22520,
376,
10168,
2933,
14,
267,
6212,
26,
627,
3257,
267,
16904,
26,
288,
446,
4223,
15,
1001,
267,
9451,
83,
26,
288,
446,
4223,
15,
1001,
267,
2633,
26,
288,
446,
315,
26,
2396,
1598,
536,
26,
2396,
1598,
4177,
26,
2116,
2672,
1121,
26,
5426,
15,
15388,
15,
13226,
6009,
2,
267,
9320,
26,
288,
1926,
26,
355,
1369,
26,
5044,
5338,
2933,
355,
4177,
26,
490,
2672,
1121,
26,
5426,
15,
15388,
15,
13226,
6009,
2,
288,
13269,
26,
355,
1369,
26,
2832,
10367,
315,
272,
408,
272,
702,
922,
272,
790,
275,
10168,
1197,
14,
1131,
14,
362,
8,
2048,
63,
344,
9,
272,
340,
790,
436,
790,
14,
344,
63,
751,
508,
922,
14,
344,
26,
267,
367,
1022,
12,
373,
315,
666,
14,
4611,
837,
288,
5371,
8,
498,
12,
1022,
12,
373,
9,
267,
790,
14,
374,
63,
1078,
63,
498,
275,
1104,
63,
692,
63,
1078,
63,
498,
8,
498,
14,
498,
12,
790,
14,
4731,
9,
267,
1592,
14,
1730,
14,
3543,
342,
267,
1592,
14,
1730,
14,
6635,
8,
498,
9,
267,
372,
23819,
8,
7231,
63,
498,
63,
3629,
14,
2724,
8,
498,
2788,
16,
2522,
1926,
272,
916,
790,
26,
267,
372,
23819,
8,
705,
534,
17454,
8038,
13269,
272,
587,
26,
267,
372,
23819,
8,
705,
534,
1763,
1911,
8038,
7901,
421,
199,
32,
571,
14,
4449,
2336,
7231,
15,
8370,
297,
3102,
2968,
2970,
1105,
199,
32,
1045,
63,
2886,
8,
549,
9,
199,
318,
664,
63,
7231,
63,
8370,
8,
751,
304,
272,
408,
2595,
272,
664,
26,
267,
3762,
26,
288,
446,
11488,
267,
16904,
26,
288,
446,
4223,
15,
1001,
267,
1369,
26,
1253,
3257,
2372,
10168,
12639,
267,
6212,
26,
627,
3257,
267,
9320,
26,
288,
1926,
26,
355,
1369,
26,
3820,
402,
10168,
12639,
355,
4177,
26,
490,
4382,
26,
717,
12639,
26,
1169,
730,
26,
1625,
1169,
2974,
26,
1816,
2672,
1121,
26,
5426,
15,
15388,
15,
13226,
6009,
2,
288,
13269,
26,
355,
1369,
26,
2832,
10367,
315,
272,
408,
272,
340,
922,
26,
267,
3063,
275,
2197,
14,
10779,
342,
267,
1434,
63,
504,
275,
3063,
14,
1814,
8,
2977,
29,
17,
12,
6925,
29,
16,
12,
12709,
29,
16,
12,
3499,
29,
16,
12,
25824,
29,
16,
9,
267,
1434,
63,
475,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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
4171
|
# Copyright (C) 2005 John Arbash-Meinel <john@arbash-meinel.com>
# Modified up by: Todd Whiteman <ToddW@ActiveState.com>
#
# This file is part of paramiko.
#
# Paramiko is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# Paramiko is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Paramiko; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
"""
Functions for communicating with Pageant, the basic windows ssh agent program.
"""
import array
import ctypes.wintypes
import platform
import struct
from paramiko.util import *
try:
import _thread as thread # Python 3.x
except ImportError:
import thread # Python 2.5-2.7
from . import _winapi
_AGENT_COPYDATA_ID = 0x804e50ba
_AGENT_MAX_MSGLEN = 8192
# Note: The WM_COPYDATA value is pulled from win32con, as a workaround
# so we do not have to import this huge library just for this one variable.
win32con_WM_COPYDATA = 74
def _get_pageant_window_object():
return ctypes.windll.user32.FindWindowA('Pageant', 'Pageant')
def can_talk_to_agent():
"""
Check to see if there is a "Pageant" agent we can talk to.
This checks both if we have the required libraries (win32all or ctypes)
and if there is a Pageant currently running.
"""
return bool(_get_pageant_window_object())
ULONG_PTR = ctypes.c_uint64 if platform.architecture()[0] == '64bit' else ctypes.c_uint32
class COPYDATASTRUCT(ctypes.Structure):
"""
ctypes implementation of
http://msdn.microsoft.com/en-us/library/windows/desktop/ms649010%28v=vs.85%29.aspx
"""
_fields_ = [
('num_data', ULONG_PTR),
('data_size', ctypes.wintypes.DWORD),
('data_loc', ctypes.c_void_p),
]
def _query_pageant(msg):
"""
Communication with the Pageant process is done through a shared
memory-mapped file.
"""
hwnd = _get_pageant_window_object()
if not hwnd:
# Raise a failure to connect exception, pageant isn't running anymore!
return None
# create a name for the mmap
map_name = 'PageantRequest%08x' % thread.get_ident()
pymap = _winapi.MemoryMap(map_name, _AGENT_MAX_MSGLEN,
_winapi.get_security_attributes_for_user(),
)
with pymap:
pymap.write(msg)
# Create an array buffer containing the mapped filename
char_buffer = array.array("c", b(map_name) + zero_byte)
char_buffer_address, char_buffer_size = char_buffer.buffer_info()
# Create a string to use for the SendMessage function call
cds = COPYDATASTRUCT(_AGENT_COPYDATA_ID, char_buffer_size,
char_buffer_address)
response = ctypes.windll.user32.SendMessageA(hwnd,
win32con_WM_COPYDATA, ctypes.sizeof(cds), ctypes.byref(cds))
if response > 0:
pymap.seek(0)
datalen = pymap.read(4)
retlen = struct.unpack('>I', datalen)[0]
return datalen + pymap.read(retlen)
return None
class PageantConnection(object):
"""
Mock "connection" to an agent which roughly approximates the behavior of
a unix local-domain socket (as used by Agent). Requests are sent to the
pageant daemon via special Windows magick, and responses are buffered back
for subsequent reads.
"""
def __init__(self):
self._response = None
def send(self, data):
self._response = _query_pageant(data)
def recv(self, n):
if self._response is None:
return ''
ret = self._response[:n]
self._response = self._response[n:]
if self._response == '':
self._response = None
return ret
def close(self):
pass
|
mit
|
[
3,
1898,
334,
35,
9,
11811,
17815,
1952,
16408,
13,
1352,
8395,
665,
20216,
32,
10325,
1119,
13,
278,
8395,
14,
957,
30,
199,
3,
22016,
1536,
701,
26,
377,
16216,
2816,
1053,
290,
665,
52,
16216,
55,
32,
7472,
2223,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
26162,
14,
199,
3,
199,
3,
12608,
16625,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
199,
3,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
199,
3,
2290,
2752,
27,
1902,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12608,
16625,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
1821,
199,
3,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
2381,
199,
3,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
199,
3,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
12608,
16625,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
14,
199,
199,
624,
199,
13967,
367,
13882,
1958,
543,
10331,
867,
12,
314,
5678,
10061,
8635,
6631,
2240,
14,
199,
624,
199,
199,
646,
1625,
199,
646,
5577,
14,
27171,
199,
646,
4298,
199,
646,
2702,
199,
504,
26162,
14,
1974,
492,
627,
199,
199,
893,
26,
272,
492,
485,
2671,
465,
2462,
327,
2018,
650,
14,
88,
199,
2590,
3545,
26,
272,
492,
2462,
327,
2018,
499,
14,
21,
13,
18,
14,
23,
199,
199,
504,
1275,
492,
485,
2676,
1246,
421,
199,
63,
14565,
63,
16188,
3998,
63,
998,
275,
378,
88,
26073,
69,
1400,
2470,
199,
63,
14565,
63,
4283,
63,
3053,
2226,
742,
275,
28828,
199,
3,
3390,
26,
710,
644,
45,
63,
16188,
3998,
574,
365,
25239,
1146,
687,
4747,
708,
388,
12,
465,
282,
18092,
199,
3,
880,
781,
886,
440,
1172,
370,
492,
642,
27791,
3555,
2951,
367,
642,
1373,
1750,
14,
199,
2676,
708,
388,
63,
13073,
63,
16188,
3998,
275,
9720,
421,
199,
318,
485,
362,
63,
1606,
867,
63,
3806,
63,
785,
837,
272,
372,
5577,
14,
25522,
14,
751,
708,
14,
6591,
4301,
33,
360,
3276,
867,
297,
283,
3276,
867,
358,
421,
199,
318,
883,
63,
21890,
63,
475,
63,
4054,
837,
272,
408,
272,
2670,
370,
1937,
340,
2337,
365,
282,
298,
3276,
867,
2,
6631,
781,
883,
22811,
370,
14,
339,
961,
5920,
3865,
340,
781,
1172,
314,
1415,
8363,
334,
2676,
708,
452,
503,
5577,
9,
272,
436,
340,
2337,
365,
282,
10331,
867,
5544,
3879,
14,
272,
408,
272,
372,
2155,
1547,
362,
63,
1606,
867,
63,
3806,
63,
785,
1012,
421,
199,
1293,
7770,
63,
14528,
275,
5577,
14,
67,
63,
1635,
772,
340,
4298,
14,
19134,
3430,
16,
61,
508,
283,
772,
2075,
7,
587,
5577,
14,
67,
63,
1635,
708,
421,
199,
533,
9357,
3998,
8893,
8,
9798,
14,
10766,
304,
272,
408,
272,
5577,
4514,
402,
272,
1455,
921,
706,
4272,
14,
17040,
14,
957,
15,
287,
13,
527,
15,
4342,
15,
8258,
15,
14487,
15,
706,
11228,
9523,
5,
1651,
86,
29,
3122,
14,
2426,
5,
1398,
14,
26146,
272,
408,
272,
485,
955,
63,
275,
359,
267,
661,
1507,
63,
576,
297,
738,
12375,
63,
14528,
395,
267,
661,
576,
63,
890,
297,
5577,
14,
27171,
14,
24754,
395,
267,
661,
576,
63,
2102,
297,
5577,
14,
67,
63,
1647,
63,
80,
395,
272,
1622,
421,
199,
318,
485,
1131,
63,
1606,
867,
8,
1328,
304,
272,
408,
272,
29585,
543,
314,
10331,
867,
2112,
365,
4224,
4012,
282,
5709,
272,
4402,
13,
11663,
570,
14,
272,
408,
272,
12073,
977,
275,
485,
362,
63,
1606,
867,
63,
3806,
63,
785,
342,
272,
340,
440,
12073,
977,
26,
267,
327,
14771,
282,
5988,
370,
4907,
1919,
12,
2034,
867,
5712,
1133,
3879,
20827,
1,
267,
372,
488,
339,
327,
1218,
282,
536,
367,
314,
21991,
272,
2341,
63,
354,
275,
283,
3276,
867,
2017,
5,
2036,
88,
7,
450,
2462,
14,
362,
63,
5425,
342,
339,
1134,
1130,
275,
485,
2676,
1246,
14,
8628,
2956,
8,
1130,
63,
354,
12,
485,
14565,
63,
4283,
63,
3053,
2226,
742,
12,
267,
485,
2676,
1246,
14,
362,
63,
4416,
63,
2987,
63,
509,
63,
751,
1062,
267,
776,
272,
543,
1134,
1130,
26,
267,
1134,
1130,
14,
952,
8,
1328,
9,
267,
327,
2790,
376,
1625,
3335,
3035,
314,
9994,
1788,
267,
1495,
63,
2738,
275,
1625,
14,
1144,
480,
67,
401,
330,
8,
1130,
63,
354,
9,
435,
4697,
63,
4414,
9,
267,
1495,
63,
2738,
63,
1562,
12,
1495,
63,
2738,
63,
890,
275,
1495,
63,
2738,
14,
2738,
63,
815,
342,
267,
327,
2790,
282,
1059,
370,
675,
367,
314,
10217,
2209,
805,
1240,
267,
286,
795,
275,
9357,
3998,
8893,
1547,
14565,
63,
16188,
3998,
63,
998,
12,
1495,
63,
2738,
63,
890,
12,
288,
1495,
63,
2738,
63,
1562,
9,
398,
1177,
275,
5577,
14,
25522,
14,
751,
708,
14,
6795,
2209,
33,
8,
8090,
977,
12,
288,
4747,
708,
388,
63,
13073,
63,
16188,
3998,
12,
5577,
14,
12590,
8,
32366,
395,
5577,
14,
20447,
8,
32366,
430,
398,
340,
1177,
690,
378,
26,
288,
1134,
1130,
14,
5507,
8,
16,
9,
288,
666,
552,
275,
1134,
1130,
14,
739,
8,
20,
9,
288,
2203,
552,
275,
2702,
14,
5301,
16099,
41,
297,
666,
552,
2788,
16,
61,
288,
372,
666,
552,
435,
1134,
1130,
14,
739,
8,
3292,
552,
9,
267,
372,
488,
421,
199,
533,
10331,
867,
3225,
8,
785,
304,
272,
408,
272,
4420,
298,
2105,
2,
370,
376,
6631,
1314,
28568,
590,
14106,
18187,
314,
5953,
402,
272,
282,
16572,
2257,
13,
2261,
2838,
334,
305,
1202,
701,
19866,
680,
221,
20260,
787,
4847,
370,
314,
272,
2034,
867,
11128,
4799,
4539,
5417,
8127,
2000,
12,
436,
9320
] |
[
1898,
334,
35,
9,
11811,
17815,
1952,
16408,
13,
1352,
8395,
665,
20216,
32,
10325,
1119,
13,
278,
8395,
14,
957,
30,
199,
3,
22016,
1536,
701,
26,
377,
16216,
2816,
1053,
290,
665,
52,
16216,
55,
32,
7472,
2223,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
26162,
14,
199,
3,
199,
3,
12608,
16625,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
199,
3,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
199,
3,
2290,
2752,
27,
1902,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12608,
16625,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
1821,
199,
3,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
2381,
199,
3,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
199,
3,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
12608,
16625,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
14,
199,
199,
624,
199,
13967,
367,
13882,
1958,
543,
10331,
867,
12,
314,
5678,
10061,
8635,
6631,
2240,
14,
199,
624,
199,
199,
646,
1625,
199,
646,
5577,
14,
27171,
199,
646,
4298,
199,
646,
2702,
199,
504,
26162,
14,
1974,
492,
627,
199,
199,
893,
26,
272,
492,
485,
2671,
465,
2462,
327,
2018,
650,
14,
88,
199,
2590,
3545,
26,
272,
492,
2462,
327,
2018,
499,
14,
21,
13,
18,
14,
23,
199,
199,
504,
1275,
492,
485,
2676,
1246,
421,
199,
63,
14565,
63,
16188,
3998,
63,
998,
275,
378,
88,
26073,
69,
1400,
2470,
199,
63,
14565,
63,
4283,
63,
3053,
2226,
742,
275,
28828,
199,
3,
3390,
26,
710,
644,
45,
63,
16188,
3998,
574,
365,
25239,
1146,
687,
4747,
708,
388,
12,
465,
282,
18092,
199,
3,
880,
781,
886,
440,
1172,
370,
492,
642,
27791,
3555,
2951,
367,
642,
1373,
1750,
14,
199,
2676,
708,
388,
63,
13073,
63,
16188,
3998,
275,
9720,
421,
199,
318,
485,
362,
63,
1606,
867,
63,
3806,
63,
785,
837,
272,
372,
5577,
14,
25522,
14,
751,
708,
14,
6591,
4301,
33,
360,
3276,
867,
297,
283,
3276,
867,
358,
421,
199,
318,
883,
63,
21890,
63,
475,
63,
4054,
837,
272,
408,
272,
2670,
370,
1937,
340,
2337,
365,
282,
298,
3276,
867,
2,
6631,
781,
883,
22811,
370,
14,
339,
961,
5920,
3865,
340,
781,
1172,
314,
1415,
8363,
334,
2676,
708,
452,
503,
5577,
9,
272,
436,
340,
2337,
365,
282,
10331,
867,
5544,
3879,
14,
272,
408,
272,
372,
2155,
1547,
362,
63,
1606,
867,
63,
3806,
63,
785,
1012,
421,
199,
1293,
7770,
63,
14528,
275,
5577,
14,
67,
63,
1635,
772,
340,
4298,
14,
19134,
3430,
16,
61,
508,
283,
772,
2075,
7,
587,
5577,
14,
67,
63,
1635,
708,
421,
199,
533,
9357,
3998,
8893,
8,
9798,
14,
10766,
304,
272,
408,
272,
5577,
4514,
402,
272,
1455,
921,
706,
4272,
14,
17040,
14,
957,
15,
287,
13,
527,
15,
4342,
15,
8258,
15,
14487,
15,
706,
11228,
9523,
5,
1651,
86,
29,
3122,
14,
2426,
5,
1398,
14,
26146,
272,
408,
272,
485,
955,
63,
275,
359,
267,
661,
1507,
63,
576,
297,
738,
12375,
63,
14528,
395,
267,
661,
576,
63,
890,
297,
5577,
14,
27171,
14,
24754,
395,
267,
661,
576,
63,
2102,
297,
5577,
14,
67,
63,
1647,
63,
80,
395,
272,
1622,
421,
199,
318,
485,
1131,
63,
1606,
867,
8,
1328,
304,
272,
408,
272,
29585,
543,
314,
10331,
867,
2112,
365,
4224,
4012,
282,
5709,
272,
4402,
13,
11663,
570,
14,
272,
408,
272,
12073,
977,
275,
485,
362,
63,
1606,
867,
63,
3806,
63,
785,
342,
272,
340,
440,
12073,
977,
26,
267,
327,
14771,
282,
5988,
370,
4907,
1919,
12,
2034,
867,
5712,
1133,
3879,
20827,
1,
267,
372,
488,
339,
327,
1218,
282,
536,
367,
314,
21991,
272,
2341,
63,
354,
275,
283,
3276,
867,
2017,
5,
2036,
88,
7,
450,
2462,
14,
362,
63,
5425,
342,
339,
1134,
1130,
275,
485,
2676,
1246,
14,
8628,
2956,
8,
1130,
63,
354,
12,
485,
14565,
63,
4283,
63,
3053,
2226,
742,
12,
267,
485,
2676,
1246,
14,
362,
63,
4416,
63,
2987,
63,
509,
63,
751,
1062,
267,
776,
272,
543,
1134,
1130,
26,
267,
1134,
1130,
14,
952,
8,
1328,
9,
267,
327,
2790,
376,
1625,
3335,
3035,
314,
9994,
1788,
267,
1495,
63,
2738,
275,
1625,
14,
1144,
480,
67,
401,
330,
8,
1130,
63,
354,
9,
435,
4697,
63,
4414,
9,
267,
1495,
63,
2738,
63,
1562,
12,
1495,
63,
2738,
63,
890,
275,
1495,
63,
2738,
14,
2738,
63,
815,
342,
267,
327,
2790,
282,
1059,
370,
675,
367,
314,
10217,
2209,
805,
1240,
267,
286,
795,
275,
9357,
3998,
8893,
1547,
14565,
63,
16188,
3998,
63,
998,
12,
1495,
63,
2738,
63,
890,
12,
288,
1495,
63,
2738,
63,
1562,
9,
398,
1177,
275,
5577,
14,
25522,
14,
751,
708,
14,
6795,
2209,
33,
8,
8090,
977,
12,
288,
4747,
708,
388,
63,
13073,
63,
16188,
3998,
12,
5577,
14,
12590,
8,
32366,
395,
5577,
14,
20447,
8,
32366,
430,
398,
340,
1177,
690,
378,
26,
288,
1134,
1130,
14,
5507,
8,
16,
9,
288,
666,
552,
275,
1134,
1130,
14,
739,
8,
20,
9,
288,
2203,
552,
275,
2702,
14,
5301,
16099,
41,
297,
666,
552,
2788,
16,
61,
288,
372,
666,
552,
435,
1134,
1130,
14,
739,
8,
3292,
552,
9,
267,
372,
488,
421,
199,
533,
10331,
867,
3225,
8,
785,
304,
272,
408,
272,
4420,
298,
2105,
2,
370,
376,
6631,
1314,
28568,
590,
14106,
18187,
314,
5953,
402,
272,
282,
16572,
2257,
13,
2261,
2838,
334,
305,
1202,
701,
19866,
680,
221,
20260,
787,
4847,
370,
314,
272,
2034,
867,
11128,
4799,
4539,
5417,
8127,
2000,
12,
436,
9320,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nupic-community/nostradamIQ
|
nostradamIQ-landingpage/webapp/proxy/tornado-proxy.py
|
6
|
5573
|
import logging
import os
import sys
import socket
from urlparse import urlparse
import tornado.httpserver
import tornado.ioloop
import tornado.iostream
import tornado.web
import tornado.httpclient
logger = logging.getLogger('tornado_proxy')
__all__ = ['ProxyHandler', 'run_proxy']
def get_proxy(url):
url_parsed = urlparse(url, scheme='http')
proxy_key = '%s_proxy' % url_parsed.scheme
return os.environ.get(proxy_key)
def parse_proxy(proxy):
proxy_parsed = urlparse(proxy, scheme='http')
return proxy_parsed.hostname, proxy_parsed.port
def fetch_request(url, callback, **kwargs):
proxy = get_proxy(url)
if proxy:
logger.debug('Forward request via upstream proxy %s', proxy)
tornado.httpclient.AsyncHTTPClient.configure(
'tornado.curl_httpclient.CurlAsyncHTTPClient')
host, port = parse_proxy(proxy)
kwargs['proxy_host'] = host
kwargs['proxy_port'] = port
req = tornado.httpclient.HTTPRequest(url, **kwargs)
client = tornado.httpclient.AsyncHTTPClient()
client.fetch(req, callback)
class ProxyHandler(tornado.web.RequestHandler):
SUPPORTED_METHODS = ['GET', 'POST', 'CONNECT']
@tornado.web.asynchronous
def get(self):
logger.debug('Handle %s request to %s', self.request.method,
self.request.uri)
def handle_response(response):
if (response.error and not
isinstance(response.error, tornado.httpclient.HTTPError)):
self.set_status(500)
self.write('Internal server error:\n' + str(response.error))
else:
self.set_status(response.code)
for header in ('Date', 'Cache-Control', 'Server','Content-Type', 'Location'):
v = response.headers.get(header)
if v:
self.set_header(header, v)
v = response.headers.get_list('Set-Cookie')
if v:
for i in v:
self.add_header('Set-Cookie', i)
if response.body:
self.write(response.body)
self.finish()
body = self.request.body
if not body:
body = None
try:
fetch_request(
self.request.uri, handle_response,
method=self.request.method, body=body,
headers=self.request.headers, follow_redirects=False,
allow_nonstandard_methods=True)
except tornado.httpclient.HTTPError as e:
if hasattr(e, 'response') and e.response:
handle_response(e.response)
else:
self.set_status(500)
self.write('Internal server error:\n' + str(e))
self.finish()
@tornado.web.asynchronous
def post(self):
return self.get()
@tornado.web.asynchronous
def connect(self):
logger.debug('Start CONNECT to %s', self.request.uri)
host, port = self.request.uri.split(':')
client = self.request.connection.stream
def read_from_client(data):
upstream.write(data)
def read_from_upstream(data):
client.write(data)
def client_close(data=None):
if upstream.closed():
return
if data:
upstream.write(data)
upstream.close()
def upstream_close(data=None):
if client.closed():
return
if data:
client.write(data)
client.close()
def start_tunnel():
logger.debug('CONNECT tunnel established to %s', self.request.uri)
client.read_until_close(client_close, read_from_client)
upstream.read_until_close(upstream_close, read_from_upstream)
client.write(b'HTTP/1.0 200 Connection established\r\n\r\n')
def on_proxy_response(data=None):
if data:
first_line = data.splitlines()[0]
http_v, status, text = first_line.split(None, 2)
if int(status) == 200:
logger.debug('Connected to upstream proxy %s', proxy)
start_tunnel()
return
self.set_status(500)
self.finish()
def start_proxy_tunnel():
upstream.write('CONNECT %s HTTP/1.1\r\n' % self.request.uri)
upstream.write('Host: %s\r\n' % self.request.uri)
upstream.write('Proxy-Connection: Keep-Alive\r\n\r\n')
upstream.read_until('\r\n\r\n', on_proxy_response)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
upstream = tornado.iostream.IOStream(s)
proxy = get_proxy(self.request.uri)
if proxy:
proxy_host, proxy_port = parse_proxy(proxy)
upstream.connect((proxy_host, proxy_port), start_proxy_tunnel)
else:
upstream.connect((host, int(port)), start_tunnel)
def run_proxy(port, start_ioloop=True):
"""
Run proxy on the specified port. If start_ioloop is True (default),
the tornado IOLoop will be started immediately.
"""
app = tornado.web.Application([
(r'.*', ProxyHandler),
])
app.listen(port)
ioloop = tornado.ioloop.IOLoop.instance()
if start_ioloop:
ioloop.start()
if __name__ == '__main__':
port = 8888
if len(sys.argv) > 1:
port = int(sys.argv[1])
print ("Starting HTTP proxy on port %d" % port)
run_proxy(port)
|
gpl-3.0
|
[
646,
2050,
199,
646,
747,
199,
646,
984,
199,
646,
2838,
199,
504,
7097,
492,
7097,
199,
199,
646,
12148,
14,
1014,
1000,
199,
646,
12148,
14,
27212,
199,
646,
12148,
14,
73,
9015,
199,
646,
12148,
14,
2520,
199,
646,
12148,
14,
1014,
1258,
199,
199,
2921,
275,
2050,
14,
5572,
360,
18443,
63,
3280,
358,
199,
199,
363,
452,
363,
275,
788,
4936,
2461,
297,
283,
1065,
63,
3280,
418,
421,
199,
318,
664,
63,
3280,
8,
633,
304,
272,
1166,
63,
6751,
275,
7097,
8,
633,
12,
5687,
534,
1014,
358,
272,
4566,
63,
498,
275,
1543,
83,
63,
3280,
7,
450,
1166,
63,
6751,
14,
5512,
272,
372,
747,
14,
2314,
14,
362,
8,
3280,
63,
498,
9,
421,
199,
318,
2198,
63,
3280,
8,
3280,
304,
272,
4566,
63,
6751,
275,
7097,
8,
3280,
12,
5687,
534,
1014,
358,
272,
372,
4566,
63,
6751,
14,
4269,
12,
4566,
63,
6751,
14,
719,
421,
199,
318,
5267,
63,
1069,
8,
633,
12,
3233,
12,
1011,
958,
304,
272,
4566,
275,
664,
63,
3280,
8,
633,
9,
272,
340,
4566,
26,
267,
2512,
14,
1757,
360,
12984,
1056,
4799,
18932,
4566,
450,
83,
297,
4566,
9,
267,
12148,
14,
1014,
1258,
14,
12807,
27757,
14,
6472,
8,
288,
283,
18443,
14,
17096,
63,
1014,
1258,
14,
35,
633,
12807,
27757,
358,
267,
1591,
12,
1844,
275,
2198,
63,
3280,
8,
3280,
9,
267,
2074,
459,
3280,
63,
1102,
418,
275,
1591,
267,
2074,
459,
3280,
63,
719,
418,
275,
1844,
339,
2648,
275,
12148,
14,
1014,
1258,
14,
21053,
8,
633,
12,
1011,
958,
9,
272,
1890,
275,
12148,
14,
1014,
1258,
14,
12807,
27757,
342,
272,
1890,
14,
3535,
8,
2103,
12,
3233,
9,
421,
199,
533,
12373,
2461,
8,
18443,
14,
2520,
14,
11149,
304,
272,
32501,
63,
18383,
275,
788,
2970,
297,
283,
4030,
297,
283,
14657,
418,
339,
768,
18443,
14,
2520,
14,
305,
9865,
272,
347,
664,
8,
277,
304,
267,
2512,
14,
1757,
360,
5940,
450,
83,
1056,
370,
450,
83,
297,
291,
14,
1069,
14,
765,
12,
2151,
291,
14,
1069,
14,
2302,
9,
398,
347,
2429,
63,
1310,
8,
1310,
304,
288,
340,
334,
1310,
14,
705,
436,
440,
490,
1228,
8,
1310,
14,
705,
12,
12148,
14,
1014,
1258,
14,
12815,
2298,
355,
291,
14,
409,
63,
1205,
8,
5783,
9,
355,
291,
14,
952,
360,
8405,
1654,
1125,
3427,
78,
7,
435,
620,
8,
1310,
14,
705,
430,
288,
587,
26,
355,
291,
14,
409,
63,
1205,
8,
1310,
14,
600,
9,
355,
367,
1406,
315,
661,
2506,
297,
283,
4437,
13,
3717,
297,
283,
3120,
1673,
2714,
13,
804,
297,
283,
6592,
735,
490,
373,
275,
1177,
14,
2139,
14,
362,
8,
1291,
9,
490,
340,
373,
26,
717,
291,
14,
409,
63,
1291,
8,
1291,
12,
373,
9,
355,
373,
275,
1177,
14,
2139,
14,
362,
63,
513,
360,
1084,
13,
7810,
358,
355,
340,
373,
26,
490,
367,
284,
315,
373,
26,
717,
291,
14,
525,
63,
1291,
360,
1084,
13,
7810,
297,
284,
9,
355,
340,
1177,
14,
2030,
26,
490,
291,
14,
952,
8,
1310,
14,
2030,
9,
288,
291,
14,
8192,
342,
398,
2396,
275,
291,
14,
1069,
14,
2030,
267,
340,
440,
2396,
26,
288,
2396,
275,
488,
267,
862,
26,
288,
5267,
63,
1069,
8,
355,
291,
14,
1069,
14,
2302,
12,
2429,
63,
1310,
12,
355,
1083,
29,
277,
14,
1069,
14,
765,
12,
2396,
29,
2030,
12,
355,
2323,
29,
277,
14,
1069,
14,
2139,
12,
2035,
63,
13607,
29,
797,
12,
355,
2040,
63,
2865,
6807,
63,
2474,
29,
549,
9,
267,
871,
12148,
14,
1014,
1258,
14,
12815,
465,
325,
26,
288,
340,
2688,
8,
69,
12,
283,
1310,
358,
436,
325,
14,
1310,
26,
355,
2429,
63,
1310,
8,
69,
14,
1310,
9,
288,
587,
26,
355,
291,
14,
409,
63,
1205,
8,
5783,
9,
355,
291,
14,
952,
360,
8405,
1654,
1125,
3427,
78,
7,
435,
620,
8,
69,
430,
355,
291,
14,
8192,
342,
339,
768,
18443,
14,
2520,
14,
305,
9865,
272,
347,
2963,
8,
277,
304,
267,
372,
291,
14,
362,
342,
339,
768,
18443,
14,
2520,
14,
305,
9865,
272,
347,
4907,
8,
277,
304,
267,
2512,
14,
1757,
360,
3162,
1868,
6930,
370,
450,
83,
297,
291,
14,
1069,
14,
2302,
9,
267,
1591,
12,
1844,
275,
291,
14,
1069,
14,
2302,
14,
1294,
11633,
267,
1890,
275,
291,
14,
1069,
14,
2105,
14,
1745,
398,
347,
1586,
63,
504,
63,
1258,
8,
576,
304,
288,
18932,
14,
952,
8,
576,
9,
398,
347,
1586,
63,
504,
63,
20099,
8,
576,
304,
288,
1890,
14,
952,
8,
576,
9,
398,
347,
1890,
63,
1600,
8,
576,
29,
403,
304,
288,
340,
18932,
14,
5938,
837,
355,
372,
288,
340,
666,
26,
355,
18932,
14,
952,
8,
576,
9,
288,
18932,
14,
1600,
342,
398,
347,
18932,
63,
1600,
8,
576,
29,
403,
304,
288,
340,
1890,
14,
5938,
837,
355,
372,
288,
340,
666,
26,
355,
1890,
14,
952,
8,
576,
9,
288,
1890,
14,
1600,
342,
398,
347,
1343,
63,
15360,
837,
288,
2512,
14,
1757,
360,
14657,
21496,
23594,
370,
450,
83,
297,
291,
14,
1069,
14,
2302,
9,
288,
1890,
14,
739,
63,
8111,
63,
1600,
8,
1258,
63,
1600,
12,
1586,
63,
504,
63,
1258,
9,
288,
18932,
14,
739,
63,
8111,
63,
1600,
8,
20099,
63,
1600,
12,
1586,
63,
504,
63,
20099,
9,
288,
1890,
14,
952,
8,
66,
7,
2856,
15,
17,
14,
16,
1926,
8113,
23594,
60,
82,
60,
78,
60,
82,
60,
78,
358,
398,
347,
641,
63,
3280,
63,
1310,
8,
576,
29,
403,
304,
288,
340,
666,
26,
355,
1642,
63,
604,
275,
666,
14,
7644,
3430,
16,
61,
355,
1455,
63,
86,
12,
2004,
12,
1318,
275,
1642,
63,
604,
14,
1294,
8,
403,
12,
499,
9,
355,
340,
1109,
8,
1205,
9,
508,
1926,
26,
490,
2512,
14,
1757,
360,
16382,
370,
18932,
4566,
450,
83,
297,
4566,
9,
490,
1343,
63,
15360,
342,
490,
372,
953,
291,
14,
409,
63,
1205,
8,
5783,
9,
288,
291,
14,
8192
] |
[
2050,
199,
646,
747,
199,
646,
984,
199,
646,
2838,
199,
504,
7097,
492,
7097,
199,
199,
646,
12148,
14,
1014,
1000,
199,
646,
12148,
14,
27212,
199,
646,
12148,
14,
73,
9015,
199,
646,
12148,
14,
2520,
199,
646,
12148,
14,
1014,
1258,
199,
199,
2921,
275,
2050,
14,
5572,
360,
18443,
63,
3280,
358,
199,
199,
363,
452,
363,
275,
788,
4936,
2461,
297,
283,
1065,
63,
3280,
418,
421,
199,
318,
664,
63,
3280,
8,
633,
304,
272,
1166,
63,
6751,
275,
7097,
8,
633,
12,
5687,
534,
1014,
358,
272,
4566,
63,
498,
275,
1543,
83,
63,
3280,
7,
450,
1166,
63,
6751,
14,
5512,
272,
372,
747,
14,
2314,
14,
362,
8,
3280,
63,
498,
9,
421,
199,
318,
2198,
63,
3280,
8,
3280,
304,
272,
4566,
63,
6751,
275,
7097,
8,
3280,
12,
5687,
534,
1014,
358,
272,
372,
4566,
63,
6751,
14,
4269,
12,
4566,
63,
6751,
14,
719,
421,
199,
318,
5267,
63,
1069,
8,
633,
12,
3233,
12,
1011,
958,
304,
272,
4566,
275,
664,
63,
3280,
8,
633,
9,
272,
340,
4566,
26,
267,
2512,
14,
1757,
360,
12984,
1056,
4799,
18932,
4566,
450,
83,
297,
4566,
9,
267,
12148,
14,
1014,
1258,
14,
12807,
27757,
14,
6472,
8,
288,
283,
18443,
14,
17096,
63,
1014,
1258,
14,
35,
633,
12807,
27757,
358,
267,
1591,
12,
1844,
275,
2198,
63,
3280,
8,
3280,
9,
267,
2074,
459,
3280,
63,
1102,
418,
275,
1591,
267,
2074,
459,
3280,
63,
719,
418,
275,
1844,
339,
2648,
275,
12148,
14,
1014,
1258,
14,
21053,
8,
633,
12,
1011,
958,
9,
272,
1890,
275,
12148,
14,
1014,
1258,
14,
12807,
27757,
342,
272,
1890,
14,
3535,
8,
2103,
12,
3233,
9,
421,
199,
533,
12373,
2461,
8,
18443,
14,
2520,
14,
11149,
304,
272,
32501,
63,
18383,
275,
788,
2970,
297,
283,
4030,
297,
283,
14657,
418,
339,
768,
18443,
14,
2520,
14,
305,
9865,
272,
347,
664,
8,
277,
304,
267,
2512,
14,
1757,
360,
5940,
450,
83,
1056,
370,
450,
83,
297,
291,
14,
1069,
14,
765,
12,
2151,
291,
14,
1069,
14,
2302,
9,
398,
347,
2429,
63,
1310,
8,
1310,
304,
288,
340,
334,
1310,
14,
705,
436,
440,
490,
1228,
8,
1310,
14,
705,
12,
12148,
14,
1014,
1258,
14,
12815,
2298,
355,
291,
14,
409,
63,
1205,
8,
5783,
9,
355,
291,
14,
952,
360,
8405,
1654,
1125,
3427,
78,
7,
435,
620,
8,
1310,
14,
705,
430,
288,
587,
26,
355,
291,
14,
409,
63,
1205,
8,
1310,
14,
600,
9,
355,
367,
1406,
315,
661,
2506,
297,
283,
4437,
13,
3717,
297,
283,
3120,
1673,
2714,
13,
804,
297,
283,
6592,
735,
490,
373,
275,
1177,
14,
2139,
14,
362,
8,
1291,
9,
490,
340,
373,
26,
717,
291,
14,
409,
63,
1291,
8,
1291,
12,
373,
9,
355,
373,
275,
1177,
14,
2139,
14,
362,
63,
513,
360,
1084,
13,
7810,
358,
355,
340,
373,
26,
490,
367,
284,
315,
373,
26,
717,
291,
14,
525,
63,
1291,
360,
1084,
13,
7810,
297,
284,
9,
355,
340,
1177,
14,
2030,
26,
490,
291,
14,
952,
8,
1310,
14,
2030,
9,
288,
291,
14,
8192,
342,
398,
2396,
275,
291,
14,
1069,
14,
2030,
267,
340,
440,
2396,
26,
288,
2396,
275,
488,
267,
862,
26,
288,
5267,
63,
1069,
8,
355,
291,
14,
1069,
14,
2302,
12,
2429,
63,
1310,
12,
355,
1083,
29,
277,
14,
1069,
14,
765,
12,
2396,
29,
2030,
12,
355,
2323,
29,
277,
14,
1069,
14,
2139,
12,
2035,
63,
13607,
29,
797,
12,
355,
2040,
63,
2865,
6807,
63,
2474,
29,
549,
9,
267,
871,
12148,
14,
1014,
1258,
14,
12815,
465,
325,
26,
288,
340,
2688,
8,
69,
12,
283,
1310,
358,
436,
325,
14,
1310,
26,
355,
2429,
63,
1310,
8,
69,
14,
1310,
9,
288,
587,
26,
355,
291,
14,
409,
63,
1205,
8,
5783,
9,
355,
291,
14,
952,
360,
8405,
1654,
1125,
3427,
78,
7,
435,
620,
8,
69,
430,
355,
291,
14,
8192,
342,
339,
768,
18443,
14,
2520,
14,
305,
9865,
272,
347,
2963,
8,
277,
304,
267,
372,
291,
14,
362,
342,
339,
768,
18443,
14,
2520,
14,
305,
9865,
272,
347,
4907,
8,
277,
304,
267,
2512,
14,
1757,
360,
3162,
1868,
6930,
370,
450,
83,
297,
291,
14,
1069,
14,
2302,
9,
267,
1591,
12,
1844,
275,
291,
14,
1069,
14,
2302,
14,
1294,
11633,
267,
1890,
275,
291,
14,
1069,
14,
2105,
14,
1745,
398,
347,
1586,
63,
504,
63,
1258,
8,
576,
304,
288,
18932,
14,
952,
8,
576,
9,
398,
347,
1586,
63,
504,
63,
20099,
8,
576,
304,
288,
1890,
14,
952,
8,
576,
9,
398,
347,
1890,
63,
1600,
8,
576,
29,
403,
304,
288,
340,
18932,
14,
5938,
837,
355,
372,
288,
340,
666,
26,
355,
18932,
14,
952,
8,
576,
9,
288,
18932,
14,
1600,
342,
398,
347,
18932,
63,
1600,
8,
576,
29,
403,
304,
288,
340,
1890,
14,
5938,
837,
355,
372,
288,
340,
666,
26,
355,
1890,
14,
952,
8,
576,
9,
288,
1890,
14,
1600,
342,
398,
347,
1343,
63,
15360,
837,
288,
2512,
14,
1757,
360,
14657,
21496,
23594,
370,
450,
83,
297,
291,
14,
1069,
14,
2302,
9,
288,
1890,
14,
739,
63,
8111,
63,
1600,
8,
1258,
63,
1600,
12,
1586,
63,
504,
63,
1258,
9,
288,
18932,
14,
739,
63,
8111,
63,
1600,
8,
20099,
63,
1600,
12,
1586,
63,
504,
63,
20099,
9,
288,
1890,
14,
952,
8,
66,
7,
2856,
15,
17,
14,
16,
1926,
8113,
23594,
60,
82,
60,
78,
60,
82,
60,
78,
358,
398,
347,
641,
63,
3280,
63,
1310,
8,
576,
29,
403,
304,
288,
340,
666,
26,
355,
1642,
63,
604,
275,
666,
14,
7644,
3430,
16,
61,
355,
1455,
63,
86,
12,
2004,
12,
1318,
275,
1642,
63,
604,
14,
1294,
8,
403,
12,
499,
9,
355,
340,
1109,
8,
1205,
9,
508,
1926,
26,
490,
2512,
14,
1757,
360,
16382,
370,
18932,
4566,
450,
83,
297,
4566,
9,
490,
1343,
63,
15360,
342,
490,
372,
953,
291,
14,
409,
63,
1205,
8,
5783,
9,
288,
291,
14,
8192,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
rush-skills/ZeroNet
|
src/util/Event.py
|
13
|
1519
|
# Based on http://stackoverflow.com/a/2022629
class Event(list):
def __call__(self, *args, **kwargs):
for f in self[:]:
if "once" in dir(f) and f in self:
self.remove(f)
f(*args, **kwargs)
def __repr__(self):
return "Event(%s)" % list.__repr__(self)
def once(self, func, name=None):
func.once = True
func.name = None
if name: # Dont function with same name twice
names = [f.name for f in self if "once" in dir(f)]
if name not in names:
func.name = name
self.append(func)
else:
self.append(func)
return self
def testBenchmark():
def say(pre, text):
print "%s Say: %s" % (pre, text)
import time
s = time.time()
on_changed = Event()
for i in range(1000):
on_changed.once(lambda pre: say(pre, "once"), "once")
print "Created 1000 once in %.3fs" % (time.time() - s)
on_changed("#1")
def testUsage():
def say(pre, text):
print "%s Say: %s" % (pre, text)
on_changed = Event()
on_changed.once(lambda pre: say(pre, "once"))
on_changed.once(lambda pre: say(pre, "once"))
on_changed.once(lambda pre: say(pre, "namedonce"), "namedonce")
on_changed.once(lambda pre: say(pre, "namedonce"), "namedonce")
on_changed.append(lambda pre: say(pre, "always"))
on_changed("#1")
on_changed("#2")
on_changed("#3")
if __name__ == "__main__":
testBenchmark()
|
gpl-2.0
|
[
3,
21311,
641,
1455,
921,
23153,
14,
957,
15,
65,
15,
4999,
1479,
1398,
421,
199,
533,
6763,
8,
513,
304,
339,
347,
636,
1250,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
367,
289,
315,
291,
32734,
288,
340,
298,
5089,
2,
315,
2935,
8,
70,
9,
436,
289,
315,
291,
26,
355,
291,
14,
2168,
8,
70,
9,
288,
289,
2031,
589,
12,
1011,
958,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
298,
2390,
4042,
83,
2924,
450,
769,
855,
2722,
721,
277,
9,
339,
347,
5403,
8,
277,
12,
2562,
12,
536,
29,
403,
304,
267,
2562,
14,
5089,
275,
715,
267,
2562,
14,
354,
275,
488,
267,
340,
536,
26,
221,
327,
577,
1888,
805,
543,
2011,
536,
13373,
288,
1561,
275,
359,
70,
14,
354,
367,
289,
315,
291,
340,
298,
5089,
2,
315,
2935,
8,
70,
1874,
288,
340,
536,
440,
315,
1561,
26,
355,
2562,
14,
354,
275,
536,
355,
291,
14,
740,
8,
1532,
9,
267,
587,
26,
288,
291,
14,
740,
8,
1532,
9,
267,
372,
291,
421,
199,
318,
511,
18644,
837,
272,
347,
14722,
8,
657,
12,
1318,
304,
267,
870,
2071,
83,
428,
1187,
26,
450,
83,
2,
450,
334,
657,
12,
1318,
9,
339,
492,
900,
272,
308,
275,
900,
14,
521,
342,
272,
641,
63,
2489,
275,
6763,
342,
272,
367,
284,
315,
1425,
8,
5279,
304,
267,
641,
63,
2489,
14,
5089,
8,
2734,
876,
26,
14722,
8,
657,
12,
298,
5089,
1288,
298,
5089,
531,
272,
870,
298,
10502,
5198,
5403,
315,
10536,
19,
2319,
2,
450,
334,
521,
14,
521,
342,
446,
308,
9,
272,
641,
63,
2489,
10064,
17,
531,
421,
199,
318,
511,
7692,
837,
272,
347,
14722,
8,
657,
12,
1318,
304,
267,
870,
2071,
83,
428,
1187,
26,
450,
83,
2,
450,
334,
657,
12,
1318,
9,
339,
641,
63,
2489,
275,
6763,
342,
272,
641,
63,
2489,
14,
5089,
8,
2734,
876,
26,
14722,
8,
657,
12,
298,
5089,
2237,
272,
641,
63,
2489,
14,
5089,
8,
2734,
876,
26,
14722,
8,
657,
12,
298,
5089,
2237,
272,
641,
63,
2489,
14,
5089,
8,
2734,
876,
26,
14722,
8,
657,
12,
298,
4579,
5089,
1288,
298,
4579,
5089,
531,
272,
641,
63,
2489,
14,
5089,
8,
2734,
876,
26,
14722,
8,
657,
12,
298,
4579,
5089,
1288,
298,
4579,
5089,
531,
272,
641,
63,
2489,
14,
740,
8,
2734,
876,
26,
14722,
8,
657,
12,
298,
9223,
2237,
272,
641,
63,
2489,
10064,
17,
531,
272,
641,
63,
2489,
10064,
18,
531,
272,
641,
63,
2489,
10064,
19,
531,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
511,
18644,
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
] |
[
21311,
641,
1455,
921,
23153,
14,
957,
15,
65,
15,
4999,
1479,
1398,
421,
199,
533,
6763,
8,
513,
304,
339,
347,
636,
1250,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
367,
289,
315,
291,
32734,
288,
340,
298,
5089,
2,
315,
2935,
8,
70,
9,
436,
289,
315,
291,
26,
355,
291,
14,
2168,
8,
70,
9,
288,
289,
2031,
589,
12,
1011,
958,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
298,
2390,
4042,
83,
2924,
450,
769,
855,
2722,
721,
277,
9,
339,
347,
5403,
8,
277,
12,
2562,
12,
536,
29,
403,
304,
267,
2562,
14,
5089,
275,
715,
267,
2562,
14,
354,
275,
488,
267,
340,
536,
26,
221,
327,
577,
1888,
805,
543,
2011,
536,
13373,
288,
1561,
275,
359,
70,
14,
354,
367,
289,
315,
291,
340,
298,
5089,
2,
315,
2935,
8,
70,
1874,
288,
340,
536,
440,
315,
1561,
26,
355,
2562,
14,
354,
275,
536,
355,
291,
14,
740,
8,
1532,
9,
267,
587,
26,
288,
291,
14,
740,
8,
1532,
9,
267,
372,
291,
421,
199,
318,
511,
18644,
837,
272,
347,
14722,
8,
657,
12,
1318,
304,
267,
870,
2071,
83,
428,
1187,
26,
450,
83,
2,
450,
334,
657,
12,
1318,
9,
339,
492,
900,
272,
308,
275,
900,
14,
521,
342,
272,
641,
63,
2489,
275,
6763,
342,
272,
367,
284,
315,
1425,
8,
5279,
304,
267,
641,
63,
2489,
14,
5089,
8,
2734,
876,
26,
14722,
8,
657,
12,
298,
5089,
1288,
298,
5089,
531,
272,
870,
298,
10502,
5198,
5403,
315,
10536,
19,
2319,
2,
450,
334,
521,
14,
521,
342,
446,
308,
9,
272,
641,
63,
2489,
10064,
17,
531,
421,
199,
318,
511,
7692,
837,
272,
347,
14722,
8,
657,
12,
1318,
304,
267,
870,
2071,
83,
428,
1187,
26,
450,
83,
2,
450,
334,
657,
12,
1318,
9,
339,
641,
63,
2489,
275,
6763,
342,
272,
641,
63,
2489,
14,
5089,
8,
2734,
876,
26,
14722,
8,
657,
12,
298,
5089,
2237,
272,
641,
63,
2489,
14,
5089,
8,
2734,
876,
26,
14722,
8,
657,
12,
298,
5089,
2237,
272,
641,
63,
2489,
14,
5089,
8,
2734,
876,
26,
14722,
8,
657,
12,
298,
4579,
5089,
1288,
298,
4579,
5089,
531,
272,
641,
63,
2489,
14,
5089,
8,
2734,
876,
26,
14722,
8,
657,
12,
298,
4579,
5089,
1288,
298,
4579,
5089,
531,
272,
641,
63,
2489,
14,
740,
8,
2734,
876,
26,
14722,
8,
657,
12,
298,
9223,
2237,
272,
641,
63,
2489,
10064,
17,
531,
272,
641,
63,
2489,
10064,
18,
531,
272,
641,
63,
2489,
10064,
19,
531,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
511,
18644,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
marcel-dancak/QGIS
|
python/PyQt/PyQt5/QtCore.py
|
17
|
2132
|
# -*- coding: utf-8 -*-
"""
***************************************************************************
QtCore.py
---------------------
Date : November 2015
Copyright : (C) 2015 by Matthias Kuhn
Email : matthias at opengis dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = 'Matthias Kuhn'
__date__ = 'November 2015'
__copyright__ = '(C) 2015, Matthias Kuhn'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
from PyQt5.QtCore import *
from types import MethodType
_QVariant__repr__ = QVariant.__repr__
_QVariant__eq__ = QVariant.__eq__
_QVariant__ne__ = QVariant.__ne__
_QVariant__hash__ = QVariant.__hash__
def __bool__(self):
return not self.isNull()
def __repr__(self):
if self.isNull():
return 'NULL'
else:
return _QVariant__repr__(self)
def __eq__(self, other):
if self.isNull():
return (isinstance(other, QVariant) and other.isNull())or other is None
else:
return _QVariant__eq__(self, other)
def __ne__(self, other):
if self.isNull():
return not (isinstance(other, QVariant) and other.isNull()) and other is not None
else:
return _QVariant__ne__(self, other)
def __hash__(self):
if self.isNull():
return 2178309
else:
return _QVariant__hash__(self)
QVariant.__bool__ = __bool__
QVariant.__repr__ = __repr__
QVariant.__eq__ = __eq__
QVariant.__ne__ = __ne__
QVariant.__hash__ = __hash__
NULL = QVariant(QVariant.Int)
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
10565,
14,
647,
272,
10652,
9858,
272,
6148,
463,
520,
3091,
432,
976,
6900,
272,
1898,
3322,
520,
334,
35,
9,
6900,
701,
18619,
273,
2241,
1804,
85,
6164,
272,
11426,
4483,
520,
2530,
273,
2241,
737,
1551,
5668,
6308,
682,
199,
17623,
199,
10,
17997,
627,
199,
10,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
10,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
10,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
10,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
10,
17997,
627,
199,
17623,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
14817,
273,
2241,
1804,
85,
6164,
7,
199,
363,
602,
363,
275,
283,
1944,
432,
976,
6900,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
6900,
12,
18619,
273,
2241,
1804,
85,
6164,
7,
199,
3,
961,
911,
664,
8717,
543,
282,
6135,
12002,
17,
1380,
1265,
886,
282,
6135,
6359,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
199,
504,
14084,
21,
14,
10901,
492,
627,
199,
199,
504,
2943,
492,
9075,
804,
421,
199,
63,
49,
12935,
363,
2722,
363,
275,
27875,
855,
2722,
363,
199,
63,
49,
12935,
363,
4077,
363,
275,
27875,
855,
4077,
363,
199,
63,
49,
12935,
363,
685,
363,
275,
27875,
855,
685,
363,
199,
63,
49,
12935,
363,
2227,
363,
275,
27875,
855,
2227,
363,
421,
199,
318,
636,
2245,
721,
277,
304,
272,
372,
440,
291,
14,
374,
8849,
342,
421,
199,
318,
636,
2722,
721,
277,
304,
272,
340,
291,
14,
374,
8849,
837,
267,
372,
283,
8084,
7,
272,
587,
26,
267,
372,
485,
49,
12935,
363,
2722,
721,
277,
9,
421,
199,
318,
636,
4077,
721,
277,
12,
1163,
304,
272,
340,
291,
14,
374,
8849,
837,
267,
372,
334,
6074,
8,
1848,
12,
27875,
9,
436,
1163,
14,
374,
8849,
1012,
269,
1163,
365,
488,
272,
587,
26,
267,
372,
485,
49,
12935,
363,
4077,
721,
277,
12,
1163,
9,
421,
199,
318,
636,
685,
721,
277,
12,
1163,
304,
272,
340,
291,
14,
374,
8849,
837,
267,
372,
440,
334,
6074,
8,
1848,
12,
27875,
9,
436,
1163,
14,
374,
8849,
1012,
436,
1163,
365,
440,
488,
272,
587,
26,
267,
372,
485,
49,
12935,
363,
685,
721,
277,
12,
1163,
9,
421,
199,
318,
636,
2227,
721,
277,
304,
272,
340,
291,
14,
374,
8849,
837,
267,
372,
499,
11175,
10556,
272,
587,
26,
267,
372,
485,
49,
12935,
363,
2227,
721,
277,
9,
421,
199,
49,
12935,
855,
2245,
363,
275,
636,
2245,
363,
199,
49,
12935,
855,
2722,
363,
275,
636,
2722,
363,
199,
49,
12935,
855,
4077,
363,
275,
636,
4077,
363,
199,
49,
12935,
855,
685,
363,
275,
636,
685,
363,
199,
49,
12935,
855,
2227,
363,
275,
636,
2227,
363,
199,
199,
8084,
275,
27875,
8,
49,
12935,
14,
3241,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
10565,
14,
647,
272,
10652,
9858,
272,
6148,
463,
520,
3091,
432,
976,
6900,
272,
1898,
3322,
520,
334,
35,
9,
6900,
701,
18619,
273,
2241,
1804,
85,
6164,
272,
11426,
4483,
520,
2530,
273,
2241,
737,
1551,
5668,
6308,
682,
199,
17623,
199,
10,
17997,
627,
199,
10,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
10,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
10,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
10,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
10,
17997,
627,
199,
17623,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
14817,
273,
2241,
1804,
85,
6164,
7,
199,
363,
602,
363,
275,
283,
1944,
432,
976,
6900,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
6900,
12,
18619,
273,
2241,
1804,
85,
6164,
7,
199,
3,
961,
911,
664,
8717,
543,
282,
6135,
12002,
17,
1380,
1265,
886,
282,
6135,
6359,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
199,
504,
14084,
21,
14,
10901,
492,
627,
199,
199,
504,
2943,
492,
9075,
804,
421,
199,
63,
49,
12935,
363,
2722,
363,
275,
27875,
855,
2722,
363,
199,
63,
49,
12935,
363,
4077,
363,
275,
27875,
855,
4077,
363,
199,
63,
49,
12935,
363,
685,
363,
275,
27875,
855,
685,
363,
199,
63,
49,
12935,
363,
2227,
363,
275,
27875,
855,
2227,
363,
421,
199,
318,
636,
2245,
721,
277,
304,
272,
372,
440,
291,
14,
374,
8849,
342,
421,
199,
318,
636,
2722,
721,
277,
304,
272,
340,
291,
14,
374,
8849,
837,
267,
372,
283,
8084,
7,
272,
587,
26,
267,
372,
485,
49,
12935,
363,
2722,
721,
277,
9,
421,
199,
318,
636,
4077,
721,
277,
12,
1163,
304,
272,
340,
291,
14,
374,
8849,
837,
267,
372,
334,
6074,
8,
1848,
12,
27875,
9,
436,
1163,
14,
374,
8849,
1012,
269,
1163,
365,
488,
272,
587,
26,
267,
372,
485,
49,
12935,
363,
4077,
721,
277,
12,
1163,
9,
421,
199,
318,
636,
685,
721,
277,
12,
1163,
304,
272,
340,
291,
14,
374,
8849,
837,
267,
372,
440,
334,
6074,
8,
1848,
12,
27875,
9,
436,
1163,
14,
374,
8849,
1012,
436,
1163,
365,
440,
488,
272,
587,
26,
267,
372,
485,
49,
12935,
363,
685,
721,
277,
12,
1163,
9,
421,
199,
318,
636,
2227,
721,
277,
304,
272,
340,
291,
14,
374,
8849,
837,
267,
372,
499,
11175,
10556,
272,
587,
26,
267,
372,
485,
49,
12935,
363,
2227,
721,
277,
9,
421,
199,
49,
12935,
855,
2245,
363,
275,
636,
2245,
363,
199,
49,
12935,
855,
2722,
363,
275,
636,
2722,
363,
199,
49,
12935,
855,
4077,
363,
275,
636,
4077,
363,
199,
49,
12935,
855,
685,
363,
275,
636,
685,
363,
199,
49,
12935,
855,
2227,
363,
275,
636,
2227,
363,
199,
199,
8084,
275,
27875,
8,
49,
12935,
14,
3241,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kynikos/lib.py.console-colors
|
src/consolecolors.py
|
1
|
5913
|
# Functions for applying console ANSI text effect and color codes.
# Copyright (C) 2011-2014 Dario Giovannetti <dev@dariogiovannetti.net>
#
# 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/>.
"""
Functions for applying console ANSI text effect and color codes.
@author: Dario Giovannetti <dev@dariogiovannetti.net>
@license: GPLv3
@version: 1.0
"""
import sys
colors = {
# SGR (Select Graphic Rendition) parameters
't': {
'R': '0', # Normal / Regular
'B': '1', # Bright (increased intensity) or Bold
'F': '2', # Faint (decreased intensity)
'I': '3', # Italic
'U': '4', # Underline
'S': '5', # Blink (slow)
'K': '6', # Blink (rapid)
#'N': '7', # Negative (swap foreground and background)
#'C': '8', # Conceal
'L': '9' # Line-through
},
# Foreground colors
'f': {
'K': '30', # Black
'R': '31', # Red
'G': '32', # Green
'Y': '33', # Yellow
'B': '34', # Blue
'P': '35', # Purple
'C': '36', # Cyan
'W': '37' # White
},
# Background colors
'b': {
'K': '40', # Black
'R': '41', # Red
'G': '42', # Green
'Y': '43', # Yellow
'B': '44', # Blue
'P': '45', # Purple
'C': '46', # Cyan
'W': '47' # White
}
}
# Reset colors to default
reset = '\033[0m'
# Negative (swap foreground and background)
swap = '\033[7m'
def code(string):
"""Return the escape code corresponding to a string
Example: code('tBfG')
"""
code = []
for k, g in enumerate(string[0:len(string) - 1:2]):
code.append(colors[g][string[1:len(string):2][k]])
return(''.join(('\033[', ';'.join(code), 'm')))
def table(x=True):
"""Display an effects and colors table
x: if False continue script execution (default: True, print the table and
exit the script)
"""
print('The following list of parameter combinations is {}not{} '
'exhaustive.'.format(code('tBfR'), reset))
print('To reset the effects, use {}[instance].reset{}.'
''.format(code('tBfC'), reset))
print('To swap foreground and background colors, use '
'{}[instance].swap{}.'.format(code('tBfC'), reset))
print('{}Remember{} that the various codes are displayed differently '
'depending on the terminal used, and some may even '
'not be supported at all.'.format(code('tBfR'), reset))
print()
print('{}One-parameter examples:{}'.format(code('tU'), reset))
print()
for g in colors:
for e in colors[g]:
string = ''.join((g, e))
print(code(string), string, reset, end='')
print()
print()
print('{}One-parameter, swapped-color examples:'.format(code('tU'), reset))
print()
for g in colors:
for e in colors[g]:
string = ''.join((g, e))
print(code(string) + swap, string, reset, end='')
print()
print()
print('{}Two-parameter examples:'.format(code('tU'), reset))
print()
for t in ('R', 'B', 'F'):
for f in colors['f']:
string = ''.join(('t', t, 'f', f))
print(code(string), string, reset, end='')
print()
for t in ('R', 'B', 'F'):
for b in colors['b']:
string = ''.join(('t', t, 'b', b))
print(code(string), string, reset, end='')
print()
for f in colors['f']:
for b in colors['b']:
string = ''.join(('f', f, 'b', b))
print(code(string), string, reset, end='')
print()
print()
print('{}Two-parameter, swapped-color examples:'.format(code('tU'), reset))
print()
for t in ('R', 'B', 'F'):
for b in colors['b']:
string = ''.join(('t', t, 'b', b))
print(code(string) + swap, string, reset, end='')
print()
for t in ('R', 'B', 'F'):
for f in colors['f']:
string = ''.join(('t', t, 'f', f))
print(code(string) + swap, string, reset, end='')
print()
for b in colors['b']:
for f in colors['f']:
string = ''.join(('f', f, 'b', b))
print(code(string) + swap, string, reset, end='')
print()
print()
print('{}Three-parameter examples:'.format(code('tU'), reset))
print()
for f in colors['f']:
for t in ('R', 'B', 'F'):
for b in colors['b']:
string = ''.join(('t', t, 'f', f, 'b', b))
print(code(string), string, reset, end='')
print()
print()
print('{}Three-parameter, swapped-color examples:'.format(code('tU'),
reset))
print()
for b in colors['b']:
for t in ('R', 'B', 'F'):
for f in colors['f']:
string = ''.join(('t', t, 'f', f, 'b', b))
print(code(string) + swap, string, reset, end='')
print()
# By default, terminate the script
if x:
sys.exit()
|
gpl-3.0
|
[
3,
17471,
367,
18876,
8559,
25600,
1318,
7763,
436,
3164,
9479,
14,
199,
3,
1898,
334,
35,
9,
7760,
13,
7280,
577,
6936,
598,
2308,
20662,
846,
280,
665,
2374,
32,
68,
759,
974,
2308,
20662,
846,
280,
14,
846,
30,
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,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
199,
13967,
367,
18876,
8559,
25600,
1318,
7763,
436,
3164,
9479,
14,
199,
199,
32,
2502,
26,
577,
6936,
598,
2308,
20662,
846,
280,
665,
2374,
32,
68,
759,
974,
2308,
20662,
846,
280,
14,
846,
30,
199,
32,
1682,
26,
14629,
86,
19,
199,
32,
1023,
26,
413,
14,
16,
199,
624,
199,
199,
646,
984,
199,
199,
7120,
275,
469,
272,
327,
428,
3975,
334,
5446,
11513,
530,
10055,
1671,
9,
2633,
272,
283,
84,
356,
469,
288,
283,
50,
356,
283,
16,
297,
221,
327,
11514,
1182,
18528,
288,
283,
34,
356,
283,
17,
297,
221,
327,
699,
1019,
334,
262,
1353,
11185,
28873,
9,
503,
699,
1753,
288,
283,
38,
356,
283,
18,
297,
221,
327,
10859,
442,
334,
271,
1353,
11185,
28873,
9,
288,
283,
41,
356,
283,
19,
297,
221,
327,
2779,
17999,
288,
283,
53,
356,
283,
20,
297,
221,
327,
25010,
604,
288,
283,
51,
356,
283,
21,
297,
221,
327,
699,
1073,
334,
14362,
9,
288,
283,
43,
356,
283,
22,
297,
221,
327,
699,
1073,
334,
1330,
344,
9,
288,
17384,
46,
356,
283,
23,
297,
221,
327,
32548,
334,
9286,
24470,
436,
8020,
9,
288,
17384,
35,
356,
283,
24,
297,
221,
327,
1448,
301,
279,
288,
283,
44,
356,
283,
25,
7,
221,
327,
7030,
13,
8304,
267,
1660,
2286,
327,
21684,
3928,
9229,
272,
283,
70,
356,
469,
288,
283,
43,
356,
283,
1216,
297,
221,
327,
30593,
288,
283,
50,
356,
283,
2192,
297,
221,
327,
9572,
288,
283,
39,
356,
283,
708,
297,
221,
327,
32585,
288,
283,
57,
356,
283,
1153,
297,
221,
327,
1488,
10723,
288,
283,
34,
356,
283,
1082,
297,
221,
327,
22447,
288,
283,
48,
356,
283,
1276,
297,
221,
327,
23177,
11045,
288,
283,
35,
356,
283,
1344,
297,
221,
327,
18461,
290,
288,
283,
55,
356,
283,
1401,
7,
221,
327,
2816,
1175,
267,
1660,
2286,
327,
10257,
3928,
9229,
272,
283,
66,
356,
469,
288,
283,
43,
356,
283,
2167,
297,
221,
327,
30593,
288,
283,
50,
356,
283,
2953,
297,
221,
327,
9572,
288,
283,
39,
356,
283,
2260,
297,
221,
327,
32585,
288,
283,
57,
356,
283,
2824,
297,
221,
327,
1488,
10723,
288,
283,
34,
356,
283,
1602,
297,
221,
327,
22447,
288,
283,
48,
356,
283,
2322,
297,
221,
327,
23177,
11045,
288,
283,
35,
356,
283,
2466,
297,
221,
327,
18461,
290,
288,
283,
55,
356,
283,
2417,
7,
221,
327,
2816,
1175,
267,
789,
199,
93,
199,
199,
3,
15510,
9229,
370,
849,
199,
3958,
275,
1557,
8762,
59,
16,
77,
7,
199,
199,
3,
32548,
334,
9286,
24470,
436,
8020,
9,
199,
9286,
275,
1557,
8762,
59,
23,
77,
7,
421,
199,
318,
1233,
8,
875,
304,
272,
408,
1767,
314,
4772,
1233,
5226,
370,
282,
1059,
2286,
5679,
26,
1233,
360,
84,
31735,
39,
358,
272,
408,
272,
1233,
275,
942,
272,
367,
1022,
12,
486,
315,
3874,
8,
875,
59,
16,
26,
552,
8,
875,
9,
446,
413,
26,
18,
4682,
267,
1233,
14,
740,
8,
7120,
59,
71,
1527,
875,
59,
17,
26,
552,
8,
875,
304,
18,
1527,
75,
3934,
272,
372,
17840,
904,
8,
2258,
8762,
59,
297,
30955,
904,
8,
600,
395,
283,
77,
7058,
421,
199,
318,
1817,
8,
88,
29,
549,
304,
272,
408,
7687,
376,
22414,
436,
9229,
1817,
2286,
671,
26,
340,
756,
1980,
2884,
6451,
334,
885,
26,
715,
12,
870,
314,
1817,
436,
272,
4458,
314,
2884,
9,
272,
408,
272,
870,
360,
1918,
2569,
769,
402,
2725,
15821,
365,
1052,
1397,
2440,
283,
3660,
283,
476,
2411,
833,
1912,
17374,
908,
8,
600,
360,
84,
31735,
50,
659,
5305,
430,
272,
870,
360,
1378,
5305,
314,
22414,
12,
675,
1052,
59,
842,
1055,
3958,
2440,
3530,
6059,
6522,
908,
8,
600,
360,
84,
31735,
35,
659,
5305,
430,
272,
870,
360,
1378,
11413,
24470,
436,
8020,
9229,
12,
675,
283,
1169,
9005,
59,
842,
1055,
9286,
2440,
17374,
908,
8,
600,
360,
84,
31735,
35,
659,
5305,
430,
272,
870,
17519,
497,
1114,
2440,
626,
314,
7750,
9479,
787,
9080,
23142,
283,
717,
283,
2601,
3219,
641,
314,
11167,
1202,
12,
436,
2005,
1443,
2755,
283,
717,
283,
1397,
506,
3748,
737,
1006,
17374,
908,
8,
600,
360,
84,
31735,
50,
659,
5305,
430,
272,
870,
342,
272,
870,
17519,
4395,
13,
5329,
7251,
26,
11123,
908,
8,
600,
360,
84,
53,
659,
5305,
430,
272,
870,
342,
272,
367,
486,
315,
9229,
26,
267,
367,
325,
315,
9229,
59,
71,
2189,
288,
1059,
275,
6522,
904,
1332,
71,
12,
325,
430,
288,
870,
8,
600,
8,
875,
395,
1059,
12,
5305,
12,
1284,
13275,
267,
870,
342,
272,
870,
342,
272,
870,
17519,
4395,
13,
5329,
12,
25072,
13,
2326,
7251,
26,
1370,
908,
8,
600,
360,
84,
53,
659,
5305,
430,
272,
870,
342,
272,
367,
486,
315,
9229,
26,
267,
367,
325,
315,
9229,
59,
71,
2189,
288,
1059,
275,
6522,
904,
1332
] |
[
17471,
367,
18876,
8559,
25600,
1318,
7763,
436,
3164,
9479,
14,
199,
3,
1898,
334,
35,
9,
7760,
13,
7280,
577,
6936,
598,
2308,
20662,
846,
280,
665,
2374,
32,
68,
759,
974,
2308,
20662,
846,
280,
14,
846,
30,
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,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
199,
13967,
367,
18876,
8559,
25600,
1318,
7763,
436,
3164,
9479,
14,
199,
199,
32,
2502,
26,
577,
6936,
598,
2308,
20662,
846,
280,
665,
2374,
32,
68,
759,
974,
2308,
20662,
846,
280,
14,
846,
30,
199,
32,
1682,
26,
14629,
86,
19,
199,
32,
1023,
26,
413,
14,
16,
199,
624,
199,
199,
646,
984,
199,
199,
7120,
275,
469,
272,
327,
428,
3975,
334,
5446,
11513,
530,
10055,
1671,
9,
2633,
272,
283,
84,
356,
469,
288,
283,
50,
356,
283,
16,
297,
221,
327,
11514,
1182,
18528,
288,
283,
34,
356,
283,
17,
297,
221,
327,
699,
1019,
334,
262,
1353,
11185,
28873,
9,
503,
699,
1753,
288,
283,
38,
356,
283,
18,
297,
221,
327,
10859,
442,
334,
271,
1353,
11185,
28873,
9,
288,
283,
41,
356,
283,
19,
297,
221,
327,
2779,
17999,
288,
283,
53,
356,
283,
20,
297,
221,
327,
25010,
604,
288,
283,
51,
356,
283,
21,
297,
221,
327,
699,
1073,
334,
14362,
9,
288,
283,
43,
356,
283,
22,
297,
221,
327,
699,
1073,
334,
1330,
344,
9,
288,
17384,
46,
356,
283,
23,
297,
221,
327,
32548,
334,
9286,
24470,
436,
8020,
9,
288,
17384,
35,
356,
283,
24,
297,
221,
327,
1448,
301,
279,
288,
283,
44,
356,
283,
25,
7,
221,
327,
7030,
13,
8304,
267,
1660,
2286,
327,
21684,
3928,
9229,
272,
283,
70,
356,
469,
288,
283,
43,
356,
283,
1216,
297,
221,
327,
30593,
288,
283,
50,
356,
283,
2192,
297,
221,
327,
9572,
288,
283,
39,
356,
283,
708,
297,
221,
327,
32585,
288,
283,
57,
356,
283,
1153,
297,
221,
327,
1488,
10723,
288,
283,
34,
356,
283,
1082,
297,
221,
327,
22447,
288,
283,
48,
356,
283,
1276,
297,
221,
327,
23177,
11045,
288,
283,
35,
356,
283,
1344,
297,
221,
327,
18461,
290,
288,
283,
55,
356,
283,
1401,
7,
221,
327,
2816,
1175,
267,
1660,
2286,
327,
10257,
3928,
9229,
272,
283,
66,
356,
469,
288,
283,
43,
356,
283,
2167,
297,
221,
327,
30593,
288,
283,
50,
356,
283,
2953,
297,
221,
327,
9572,
288,
283,
39,
356,
283,
2260,
297,
221,
327,
32585,
288,
283,
57,
356,
283,
2824,
297,
221,
327,
1488,
10723,
288,
283,
34,
356,
283,
1602,
297,
221,
327,
22447,
288,
283,
48,
356,
283,
2322,
297,
221,
327,
23177,
11045,
288,
283,
35,
356,
283,
2466,
297,
221,
327,
18461,
290,
288,
283,
55,
356,
283,
2417,
7,
221,
327,
2816,
1175,
267,
789,
199,
93,
199,
199,
3,
15510,
9229,
370,
849,
199,
3958,
275,
1557,
8762,
59,
16,
77,
7,
199,
199,
3,
32548,
334,
9286,
24470,
436,
8020,
9,
199,
9286,
275,
1557,
8762,
59,
23,
77,
7,
421,
199,
318,
1233,
8,
875,
304,
272,
408,
1767,
314,
4772,
1233,
5226,
370,
282,
1059,
2286,
5679,
26,
1233,
360,
84,
31735,
39,
358,
272,
408,
272,
1233,
275,
942,
272,
367,
1022,
12,
486,
315,
3874,
8,
875,
59,
16,
26,
552,
8,
875,
9,
446,
413,
26,
18,
4682,
267,
1233,
14,
740,
8,
7120,
59,
71,
1527,
875,
59,
17,
26,
552,
8,
875,
304,
18,
1527,
75,
3934,
272,
372,
17840,
904,
8,
2258,
8762,
59,
297,
30955,
904,
8,
600,
395,
283,
77,
7058,
421,
199,
318,
1817,
8,
88,
29,
549,
304,
272,
408,
7687,
376,
22414,
436,
9229,
1817,
2286,
671,
26,
340,
756,
1980,
2884,
6451,
334,
885,
26,
715,
12,
870,
314,
1817,
436,
272,
4458,
314,
2884,
9,
272,
408,
272,
870,
360,
1918,
2569,
769,
402,
2725,
15821,
365,
1052,
1397,
2440,
283,
3660,
283,
476,
2411,
833,
1912,
17374,
908,
8,
600,
360,
84,
31735,
50,
659,
5305,
430,
272,
870,
360,
1378,
5305,
314,
22414,
12,
675,
1052,
59,
842,
1055,
3958,
2440,
3530,
6059,
6522,
908,
8,
600,
360,
84,
31735,
35,
659,
5305,
430,
272,
870,
360,
1378,
11413,
24470,
436,
8020,
9229,
12,
675,
283,
1169,
9005,
59,
842,
1055,
9286,
2440,
17374,
908,
8,
600,
360,
84,
31735,
35,
659,
5305,
430,
272,
870,
17519,
497,
1114,
2440,
626,
314,
7750,
9479,
787,
9080,
23142,
283,
717,
283,
2601,
3219,
641,
314,
11167,
1202,
12,
436,
2005,
1443,
2755,
283,
717,
283,
1397,
506,
3748,
737,
1006,
17374,
908,
8,
600,
360,
84,
31735,
50,
659,
5305,
430,
272,
870,
342,
272,
870,
17519,
4395,
13,
5329,
7251,
26,
11123,
908,
8,
600,
360,
84,
53,
659,
5305,
430,
272,
870,
342,
272,
367,
486,
315,
9229,
26,
267,
367,
325,
315,
9229,
59,
71,
2189,
288,
1059,
275,
6522,
904,
1332,
71,
12,
325,
430,
288,
870,
8,
600,
8,
875,
395,
1059,
12,
5305,
12,
1284,
13275,
267,
870,
342,
272,
870,
342,
272,
870,
17519,
4395,
13,
5329,
12,
25072,
13,
2326,
7251,
26,
1370,
908,
8,
600,
360,
84,
53,
659,
5305,
430,
272,
870,
342,
272,
367,
486,
315,
9229,
26,
267,
367,
325,
315,
9229,
59,
71,
2189,
288,
1059,
275,
6522,
904,
1332,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
laryamamoto/PyCellChemistry
|
src/RD/DichotomousBranching.py
|
1
|
4555
|
#---------------------------------------------------------------------------
#
# DichotomousBranching.py: dichotomous branching pattern based on the
# combination of an activator-depleted substrate model and a vein
# formation substance Y.
#
# Y formation is triggered by the activator A. The vascular system to
# be formed drains the substrate S, such that the catalysis of
# activator is inhibited due to depletion of S, thus inhibiting
# further vein formation in this area.
#
# from p. 170-172 of:
# Hans Meinhardt, "Models of Biological Pattern Formation",
# Academic Press, London, UK, 1982
#
# originally implemented on top of the breve simulator, www.spiderland.org
# by Lidia Yamamoto, Univ. Basel, Switzerland, February 2010
# 20150914: removed breve dependencies to run within PyCellChemistry
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
# Copyright (C) 2015 Lidia A. R. Yamamoto
# Contact: http://www.artificial-chemistries.org/
#
# This file is part of PyCellChemistry.
#
# PyCellChemistry 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.
#
# PyCellChemistry 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 PyCellChemistry, see file LICENSE. If not, see
# http://www.gnu.org/licenses/
#
from ReactionDiffusion import *
class DichotomousBranchingDemo( ):
def __init__( self ):
self.gsize = 64
reactionstrs = [ "S + 2 A --> 3 A" ,
"S + 2 A --> 2 A" ,
#" --> A " , # k=0
" --> S " ,
" A --> " ,
" S --> " ,
" S + Y --> Y " , # vein drains substrate
"E + 2 Y --> Z " , # vein signal is produced
" Z --> E + 3 Y" , # by enzyme E
" A + Y --> A + 2 Y" , # act. produces vein sig.
#" A --> A + Y" , # act. produces vein sig.
" Y --> " # vein sig. decays
]
self.rsys = ReactionDiffusionSystem(self.gsize, self.gsize)
self.rsys.parse(reactionstrs)
# parameters from ActivatorSubstrate.py:
DS = 0.2
DA = 0.005
self.rsys.set_coefficient(0, 0.01) # rho_a
self.rsys.set_coefficient(1, 0.01) # k = rho_s - rho_a, rho_s=0.02
self.rsys.set_coefficient(2, 0.02) # sigma_s
self.rsys.set_coefficient(3, 0.01) # mu_a
self.rsys.set_coefficient(4, 0.001) # mu_s
self.rsys.set_coefficient(5, 0.03) # epsilon
self.rsys.set_coefficient(6, 0.02) # k1
self.rsys.set_coefficient(7, 0.01) # k2 << k1
self.rsys.set_coefficient(8, 0.02) # d (differentiation rate)
self.rsys.set_coefficient(9, 0.01) # e (decay of y)
self.rsys.resetAll("A", 1.0)
#self.rsys.deposit("E", 0.01, self.gsize-1, self.gsize-1)
#self.rsys.deposit("Y", 0.01, self.gsize-1, self.gsize-1)
self.rsys.resetAll("E", 0.01)
self.rsys.resetAll("Y", 0.01)
self.rsys.set_diffcoef("S", DS)
self.rsys.set_diffcoef("A", DA)
self.rsys.perturbAll("A", 0.333, 0.2)
#self.rsys.set_patch_at("A", 1.0, self.gsize/2, self.gsize/2)
#self.rsys.set_patch_at("A", 1.0, self.gsize/2-3, self.gsize/2-3)
#self.rsys.set_patch_at("A", 1.0, self.gsize/2-3, self.gsize/2+3)
#self.rsys.set_patch_at("A", 1.0, self.gsize/2+3, self.gsize/2-3)
#self.rsys.set_patch_at("A", 1.0, self.gsize/2+3, self.gsize/2+3)
self.rsys.set_color( "A", (1, 0, 0) )
self.rsys.set_color( "S", (0, 0, 1) )
self.rsys.set_color( "Y", (0, 1, 0) )
def run( self, finalvt=3000.0, dt=0.1 ):
i = 0
self.rsys.animate(sleeptime=0.01, transparent=False, blur=True)
while (self.rsys.vtime() <= finalvt):
self.rsys.integrate(dt)
i += 1
if (i % 50 == 0):
self.rsys.animate(sleeptime=0.01, transparent=False, blur=True)
if __name__ == '__main__':
dicbranch = DichotomousBranchingDemo()
dicbranch.run()
|
gpl-3.0
|
[
7656,
13715,
199,
3,
199,
3,
577,
1158,
3459,
7376,
12526,
316,
14,
647,
26,
487,
335,
3459,
7376,
5246,
316,
3851,
4079,
641,
314,
199,
3,
14665,
402,
376,
6633,
86,
707,
13,
2601,
3496,
25379,
1402,
436,
282,
11199,
262,
199,
3,
367,
1615,
1007,
611,
1488,
14,
199,
3,
199,
3,
1488,
367,
1615,
365,
15572,
701,
314,
6633,
86,
707,
437,
14,
710,
373,
10125,
2238,
2656,
370,
199,
3,
506,
28917,
366,
345,
3617,
314,
25379,
428,
12,
4066,
626,
314,
6230,
2618,
2316,
402,
199,
3,
6633,
86,
707,
365,
315,
20215,
5703,
7037,
370,
2657,
274,
296,
402,
428,
12,
12850,
315,
20215,
390,
316,
199,
3,
9848,
11199,
262,
367,
1615,
315,
642,
9150,
14,
199,
3,
199,
3,
687,
299,
14,
27209,
13,
10419,
402,
26,
199,
3,
869,
796,
3194,
262,
8726,
84,
12,
298,
20474,
402,
699,
2308,
7954,
27019,
2104,
1615,
401,
221,
199,
3,
437,
9490,
15003,
23583,
12,
491,
7835,
265,
12,
738,
43,
12,
5851,
2564,
199,
3,
199,
3,
20657,
6366,
641,
2746,
402,
314,
330,
30496,
15797,
12,
20732,
14,
12856,
9688,
14,
1308,
199,
3,
701,
24157,
2391,
1488,
14541,
77,
3459,
12,
1910,
1003,
14,
3523,
76,
12,
428,
2503,
2282,
9688,
12,
21141,
26709,
7129,
199,
3,
1784,
6576,
1079,
26,
4829,
330,
30496,
5124,
370,
1255,
4453,
1611,
8108,
20335,
2664,
27723,
199,
3,
199,
3,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
199,
3,
199,
3,
257,
1898,
334,
35,
9,
6900,
24157,
2391,
437,
14,
820,
14,
1488,
14541,
77,
3459,
199,
3,
257,
18684,
26,
1455,
921,
1544,
14,
285,
32033,
13,
24448,
631,
1996,
14,
1308,
15,
199,
3,
199,
3,
257,
961,
570,
365,
1777,
402,
1611,
8108,
20335,
2664,
27723,
14,
199,
3,
199,
3,
257,
1611,
8108,
20335,
2664,
27723,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
257,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
257,
1015,
650,
12,
465,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
257,
1611,
8108,
20335,
2664,
27723,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
257,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
257,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
257,
3180,
543,
1611,
8108,
20335,
2664,
27723,
12,
1937,
570,
5113,
14,
982,
440,
12,
1937,
199,
3,
257,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
199,
3,
199,
199,
504,
799,
1287,
10746,
12444,
492,
627,
199,
199,
533,
577,
1158,
3459,
7376,
12526,
316,
21493,
8,
3461,
272,
347,
636,
826,
721,
291,
3461,
267,
291,
14,
71,
890,
275,
5049,
398,
26909,
16144,
275,
359,
298,
51,
435,
499,
437,
10541,
650,
437,
2,
2360,
586,
298,
51,
435,
499,
437,
10541,
499,
437,
2,
2360,
717,
20383,
263,
10541,
437,
221,
298,
2360,
327,
1022,
29,
16,
586,
298,
263,
10541,
428,
221,
298,
2360,
586,
298,
420,
437,
10541,
259,
298,
2360,
586,
298,
420,
428,
10541,
259,
298,
2360,
199,
586,
298,
221,
428,
435,
1488,
10541,
1488,
221,
298,
2360,
258,
327,
11199,
262,
366,
345,
3617,
25379,
586,
298,
37,
435,
499,
1488,
10541,
3107,
221,
298,
2360,
258,
327,
11199,
262,
4673,
365,
13584,
586,
298,
420,
3107,
10541,
662,
435,
650,
1488,
2,
2360,
327,
701,
655,
3605,
278,
662,
586,
298,
221,
437,
435,
1488,
10541,
437,
435,
499,
1488,
2,
2360,
327,
2454,
14,
16904,
11199,
262,
5259,
14,
586,
20383,
221,
437,
10541,
437,
435,
1488,
2,
2360,
327,
2454,
14,
16904,
11199,
262,
5259,
14,
586,
298,
420,
1488,
10541,
263,
298,
257,
327,
11199,
262,
5259,
14,
477,
696,
588,
2432,
1622,
7318,
291,
14,
82,
1274,
275,
799,
1287,
10746,
12444,
3989,
8,
277,
14,
71,
890,
12,
291,
14,
71,
890,
9,
267,
291,
14,
82,
1274,
14,
1122,
8,
29834,
16144,
9,
398,
327,
2633,
687,
21904,
86,
707,
2610,
18161,
14,
647,
26,
4960,
577,
51,
275,
378,
14,
18,
267,
577,
33,
275,
378,
14,
7972,
267,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
16,
12,
378,
14,
614,
9,
221,
327,
17908,
63,
65,
267,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
17,
12,
378,
14,
614,
9,
221,
327,
1022,
275,
17908,
63,
83,
446,
17908,
63,
65,
12,
17908,
63,
83,
29,
16,
14,
996,
267,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
18,
12,
378,
14,
996,
9,
221,
327,
10819,
63,
83,
267,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
19,
12,
378,
14,
614,
9,
221,
327,
8504,
63,
65,
267,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
20,
12,
378,
14,
4587,
9,
327,
8504,
63,
83,
398,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
21,
12,
378,
14,
1644,
9,
221,
327,
14030,
267,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
22,
12,
378,
14,
996,
9,
221,
327,
1022,
17,
267,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
23,
12,
378,
14,
614,
9,
221,
327,
1022,
18,
5213,
1022,
17,
267,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
24,
12,
378,
14,
996,
9,
221,
327,
366,
334,
6870,
30906,
425,
6634,
9,
267,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
25,
12,
378,
14,
614,
9,
221,
327,
325,
334,
16889,
402,
612,
9,
398,
291,
14,
82,
1274,
14,
3958,
2422,
480,
33,
401,
413,
14,
16,
9,
267,
327,
277,
14,
82,
1274,
14,
271,
21759,
480,
37,
401,
378,
14,
614,
12,
291,
14,
71,
890,
13,
17,
12
] |
[
13715,
199,
3,
199,
3,
577,
1158,
3459,
7376,
12526,
316,
14,
647,
26,
487,
335,
3459,
7376,
5246,
316,
3851,
4079,
641,
314,
199,
3,
14665,
402,
376,
6633,
86,
707,
13,
2601,
3496,
25379,
1402,
436,
282,
11199,
262,
199,
3,
367,
1615,
1007,
611,
1488,
14,
199,
3,
199,
3,
1488,
367,
1615,
365,
15572,
701,
314,
6633,
86,
707,
437,
14,
710,
373,
10125,
2238,
2656,
370,
199,
3,
506,
28917,
366,
345,
3617,
314,
25379,
428,
12,
4066,
626,
314,
6230,
2618,
2316,
402,
199,
3,
6633,
86,
707,
365,
315,
20215,
5703,
7037,
370,
2657,
274,
296,
402,
428,
12,
12850,
315,
20215,
390,
316,
199,
3,
9848,
11199,
262,
367,
1615,
315,
642,
9150,
14,
199,
3,
199,
3,
687,
299,
14,
27209,
13,
10419,
402,
26,
199,
3,
869,
796,
3194,
262,
8726,
84,
12,
298,
20474,
402,
699,
2308,
7954,
27019,
2104,
1615,
401,
221,
199,
3,
437,
9490,
15003,
23583,
12,
491,
7835,
265,
12,
738,
43,
12,
5851,
2564,
199,
3,
199,
3,
20657,
6366,
641,
2746,
402,
314,
330,
30496,
15797,
12,
20732,
14,
12856,
9688,
14,
1308,
199,
3,
701,
24157,
2391,
1488,
14541,
77,
3459,
12,
1910,
1003,
14,
3523,
76,
12,
428,
2503,
2282,
9688,
12,
21141,
26709,
7129,
199,
3,
1784,
6576,
1079,
26,
4829,
330,
30496,
5124,
370,
1255,
4453,
1611,
8108,
20335,
2664,
27723,
199,
3,
199,
3,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
446,
199,
3,
199,
3,
257,
1898,
334,
35,
9,
6900,
24157,
2391,
437,
14,
820,
14,
1488,
14541,
77,
3459,
199,
3,
257,
18684,
26,
1455,
921,
1544,
14,
285,
32033,
13,
24448,
631,
1996,
14,
1308,
15,
199,
3,
199,
3,
257,
961,
570,
365,
1777,
402,
1611,
8108,
20335,
2664,
27723,
14,
199,
3,
199,
3,
257,
1611,
8108,
20335,
2664,
27723,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
257,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
257,
1015,
650,
12,
465,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
257,
1611,
8108,
20335,
2664,
27723,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
257,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
257,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
257,
3180,
543,
1611,
8108,
20335,
2664,
27723,
12,
1937,
570,
5113,
14,
982,
440,
12,
1937,
199,
3,
257,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
199,
3,
199,
199,
504,
799,
1287,
10746,
12444,
492,
627,
199,
199,
533,
577,
1158,
3459,
7376,
12526,
316,
21493,
8,
3461,
272,
347,
636,
826,
721,
291,
3461,
267,
291,
14,
71,
890,
275,
5049,
398,
26909,
16144,
275,
359,
298,
51,
435,
499,
437,
10541,
650,
437,
2,
2360,
586,
298,
51,
435,
499,
437,
10541,
499,
437,
2,
2360,
717,
20383,
263,
10541,
437,
221,
298,
2360,
327,
1022,
29,
16,
586,
298,
263,
10541,
428,
221,
298,
2360,
586,
298,
420,
437,
10541,
259,
298,
2360,
586,
298,
420,
428,
10541,
259,
298,
2360,
199,
586,
298,
221,
428,
435,
1488,
10541,
1488,
221,
298,
2360,
258,
327,
11199,
262,
366,
345,
3617,
25379,
586,
298,
37,
435,
499,
1488,
10541,
3107,
221,
298,
2360,
258,
327,
11199,
262,
4673,
365,
13584,
586,
298,
420,
3107,
10541,
662,
435,
650,
1488,
2,
2360,
327,
701,
655,
3605,
278,
662,
586,
298,
221,
437,
435,
1488,
10541,
437,
435,
499,
1488,
2,
2360,
327,
2454,
14,
16904,
11199,
262,
5259,
14,
586,
20383,
221,
437,
10541,
437,
435,
1488,
2,
2360,
327,
2454,
14,
16904,
11199,
262,
5259,
14,
586,
298,
420,
1488,
10541,
263,
298,
257,
327,
11199,
262,
5259,
14,
477,
696,
588,
2432,
1622,
7318,
291,
14,
82,
1274,
275,
799,
1287,
10746,
12444,
3989,
8,
277,
14,
71,
890,
12,
291,
14,
71,
890,
9,
267,
291,
14,
82,
1274,
14,
1122,
8,
29834,
16144,
9,
398,
327,
2633,
687,
21904,
86,
707,
2610,
18161,
14,
647,
26,
4960,
577,
51,
275,
378,
14,
18,
267,
577,
33,
275,
378,
14,
7972,
267,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
16,
12,
378,
14,
614,
9,
221,
327,
17908,
63,
65,
267,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
17,
12,
378,
14,
614,
9,
221,
327,
1022,
275,
17908,
63,
83,
446,
17908,
63,
65,
12,
17908,
63,
83,
29,
16,
14,
996,
267,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
18,
12,
378,
14,
996,
9,
221,
327,
10819,
63,
83,
267,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
19,
12,
378,
14,
614,
9,
221,
327,
8504,
63,
65,
267,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
20,
12,
378,
14,
4587,
9,
327,
8504,
63,
83,
398,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
21,
12,
378,
14,
1644,
9,
221,
327,
14030,
267,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
22,
12,
378,
14,
996,
9,
221,
327,
1022,
17,
267,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
23,
12,
378,
14,
614,
9,
221,
327,
1022,
18,
5213,
1022,
17,
267,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
24,
12,
378,
14,
996,
9,
221,
327,
366,
334,
6870,
30906,
425,
6634,
9,
267,
291,
14,
82,
1274,
14,
409,
63,
21329,
8,
25,
12,
378,
14,
614,
9,
221,
327,
325,
334,
16889,
402,
612,
9,
398,
291,
14,
82,
1274,
14,
3958,
2422,
480,
33,
401,
413,
14,
16,
9,
267,
327,
277,
14,
82,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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
] |
Kinggerm/GetOrganelle
|
Utilities/slim_graph.py
|
1
|
66252
|
#!/usr/bin/env python
# coding: utf8
import time
import os
import sys
import subprocess
try:
# python2
import commands
except:
pass
inf = float("inf")
from argparse import ArgumentParser
PATH_OF_THIS_SCRIPT = os.path.split(os.path.realpath(__file__))[0]
sys.path.insert(0, os.path.join(PATH_OF_THIS_SCRIPT, ".."))
import GetOrganelleLib
from GetOrganelleLib.versions import get_versions
from GetOrganelleLib.pipe_control_func import *
import math
import copy
PATH_OF_THIS_SCRIPT = os.path.split(os.path.realpath(__file__))[0]
import platform
SYSTEM_NAME = ""
if platform.system() == "Linux":
SYSTEM_NAME = "linux"
elif platform.system() == "Darwin":
SYSTEM_NAME = "macOS"
else:
sys.stdout.write("Error: currently GetOrganelle is not supported for " + platform.system() + "! ")
exit()
GO_LIB_PATH = os.path.split(GetOrganelleLib.__file__)[0]
GO_DEP_PATH = os.path.realpath(os.path.join(GO_LIB_PATH, "..", "GetOrganelleDep", SYSTEM_NAME))
VALID_PATH_CHARS = set("1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM,./ _-+")
_GO_PATH = GO_PATH
_LBL_DB_PATH = LBL_DB_PATH
_SEQ_DB_PATH = SEQ_DB_PATH
def check_path_chars(path_or_file_name):
for this_char in path_or_file_name:
if this_char not in VALID_PATH_CHARS:
raise Exception("Invalid char \"" + this_char + "\" from the input file/path " + path_or_file_name + "!")
def get_options(print_title):
usage = "python "+str(os.path.basename(__file__)+" assembly_graph_files -F embplant_pt -E embplant_mt")
parser = ArgumentParser(description=print_title, usage=usage)
# parser.add_argument("-o", dest="out_fastg_file", help="Output file")
# filters
parser.add_argument("assemblies", metavar="assemblies", type=str, nargs="+",
help="Input assembly (graph) files (.fasta or .gfa or .fastg). Please split the files by spaces.")
parser.add_argument("-F", dest="organelle_types",
help="followed with mode embplant_pt, other_pt, embplant_mt, embplant_nr, "
"animal_mt, fungus_mt, fungus_nr "
"(which means embryophyta plastome, non-embryophyta plastome, "
"plant mitochondrion, plant nuclear ribosomal RNA, animal mitochondrion, "
"fungus mitochondrion, fungus nuclear ribosomal RNA separately), "
"or a combination of above split by comma(s) "
"(corresponds to certain arguments as following listed). "
"\t"
" ------------------------------------------------------ "
"\nembplant_pt \t \" --include-priority " + os.path.join(LBL_DB_PATH, "embplant_pt.fasta") + "\""
" ------------------------------------------------------ "
"\nother_pt \t \" --include-priority " + os.path.join(LBL_DB_PATH, "other_pt.fasta") + "\""
" ------------------------------------------------------ "
"\nembplant_mt \t \" --include-priority " + os.path.join(LBL_DB_PATH, "embplant_mt.fasta") + "\""
" ------------------------------------------------------ "
"\nembplant_nr \t \" --include-priority " + os.path.join(LBL_DB_PATH, "embplant_nr.fasta") + "\""
" ------------------------------------------------------ "
"\nanimal_mt \t \" --include-priority " + os.path.join(LBL_DB_PATH, "animal_mt.fasta") + "\""
" ------------------------------------------------------ "
"\nfungus_mt \t \" --include-priority " + os.path.join(LBL_DB_PATH, "fungus_mt.fasta") + "\""
" ------------------------------------------------------ "
"\nfungus_nr \t \" --include-priority " + os.path.join(LBL_DB_PATH, "fungus_nr.fasta") + "\""
" ------------------------------------------------------ "
"\nother_pt,embplant_mt,fungus_mt \t \" --include-priority " + os.path.join(LBL_DB_PATH, "other_pt.fasta") + "," + os.path.join(LBL_DB_PATH, "embplant_mt.fasta") + "," + os.path.join(LBL_DB_PATH, "fungus_mt.fasta") + "\""
" ------------------------------------------------------ "
"For easy usage and compatibility of old versions, following redirection "
"would be automatically fulfilled without warning:\t"
"\nplant_cp->embplant_pt; plant_pt->embplant_pt; "
"\nplant_mt->embplant_mt; plant_nr->embplant_nr"
)
parser.add_argument("-E", dest="exclude_organelle_types",
help="followed with mode embplant_pt, other_pt, embplant_mt, embplant_nr, animal_mt, fungus_mt,"
"fungus_nr "
"(which means embryophyta plastome, non-embryophyta plastome, "
"plant mitochondrion, plant nuclear ribosomal RNA, animal mitochondrion, "
"fungus mitochondrion, fungus nuclear ribosomal RNA separately), "
"or a combination of above split by comma(s) "
"(be similar to -F and corresponds to certain arguments as following listed). "
"\t"
" ------------------------------------------------------ "
"\nembplant_pt \t \" --exclude " + os.path.join(LBL_DB_PATH, "embplant_pt.fasta") + "\""
" ------------------------------------------------------ "
"\nembplant_mt \t \" --exclude " + os.path.join(LBL_DB_PATH, "embplant_mt.fasta") + "\""
" ------------------------------------------------------ "
"\nembplant_nr \t \" --exclude " + os.path.join(LBL_DB_PATH, "embplant_nr.fasta") + "\""
" ------------------------------------------------------ "
"\nanimal_mt \t \" --exclude " + os.path.join(LBL_DB_PATH, "animal_mt.fasta") + "\""
" ------------------------------------------------------ "
"\nfungus_mt \t \" --exclude " + os.path.join(LBL_DB_PATH, "fungus_mt.fasta") + "\""
" ------------------------------------------------------ "
"\nfungus_nr \t \" --exclude " + os.path.join(LBL_DB_PATH, "fungus_nr.fasta") + "\""
" ------------------------------------------------------ "
"\nembplant_mt,embplant_nr \t \" --exclude " + os.path.join(LBL_DB_PATH, "embplant_mt.fasta") + "," + os.path.join(LBL_DB_PATH, "embplant_nr.fasta") + "\""
" ------------------------------------------------------ "
"For easy usage and compatibility of old versions, following redirection "
"would be automatically fulfilled without warning:\t"
"\nplant_cp->embplant_pt; plant_pt->embplant_pt; "
"\nplant_mt->embplant_mt; plant_nr->embplant_nr")
parser.add_argument("--no-hits", dest="treat_no_hits", default="ex_no_con",
help="Provide treatment for non-hitting contigs.\t"
" ------------------------------------------------------ "
"\nex_no_con \t keep those connect with hitting-include contigs. (Default)"
" ------------------------------------------------------ "
"\nex_no_hit \t exclude all."
" ------------------------------------------------------ "
"\nkeep_all \t keep all"
" ------------------------------------------------------ ")
parser.add_argument("--max-slim-extending-len", dest="max_slim_extending_len",
default=MAX_SLIM_EXTENDING_LENS["anonym"],
type=float,
help="This is used to limit the extending length, below which a \"non-hit contig\" is allowed "
"to be distant from a \"hit contig\" to be kept. This distance is measured by the shortest "
"distance connecting those two contigs, weighted by the depth of the \"hit contig\". "
"This is used only when \"--no-hits ex_no_con\" was chosen. "
"Should be a single INTEGER number or inf (meaning infinite). "
"It is supposed to be half of the maximum expected "
"genome size to be safe, but could be much smaller if the LabelDatabse is closely related. "
"Default: " +
str(MAX_SLIM_EXTENDING_LENS["embplant_pt"]) + " (-F embplant_pt), " +
str(MAX_SLIM_EXTENDING_LENS["embplant_mt"]) + " (-F embplant_mt/fungus_mt/other_pt), " +
str(MAX_SLIM_EXTENDING_LENS["embplant_nr"]) + " (-F embplant_nr/fungus_nr/animal_mt), "
"maximum_of_type1_type2 (-F type1,type2), %(default)s (cases without using -F)")
parser.add_argument("--significant", dest="significant", default=3.0, type=float,
help="Within a contig, if the query-score of hitting A is more than given times (Default: 3.0) "
"of the query-score of hitting B, this contig would be treated as only A related, "
"rather than both.")
parser.add_argument("--depth-cutoff", dest="depth_cutoff", default=10000.0, type=float,
help="After detection for target coverage, those beyond certain times (depth cutoff) of the"
" detected coverage would be excluded. Default: %(default)s")
parser.add_argument("--min-depth", dest="min_depth", default=0., type=float,
help="Input a float or integer number. Filter fastg file by a minimum depth. Default: %(default)s.")
parser.add_argument("--max-depth", dest="max_depth", default=inf, type=float,
help="Input a float or integer number. filter fastg file by a maximum depth. Default: %(default)s.")
parser.add_argument("--merge", dest="merge_contigs", default=False, action="store_true",
help="Merge all possible contigs. ")
parser.add_argument("--include", dest="include",
help="followed by Blastn database(s)")
parser.add_argument("--include-priority", dest="include_priority",
help="followed by Blastn database(s).")
parser.add_argument("--exclude", dest="exclude",
help="followed by Blastn database(s).")
parser.add_argument("--exclude-priority", dest="exclude_priority",
help="followed by Blastn database(s)")
parser.add_argument("--no-hits-labeled-tab", dest="no_tab", default=False, action="store_true",
help="Choose to disable producing tab file")
parser.add_argument("--keep-temp", dest="keep_temp", default=False, action="store_true",
help="Choose to disable deleting temp files produced by blast and this script")
parser.add_argument("-o", "--out-dir", dest="out_dir",
help="By default the output would be along with the input fastg file. "
"But you could assign a new directory with this option.")
parser.add_argument("-e", "--evalue", dest="evalue", default=1e-25, type=float,
help="blastn evalue threshold. Default: %(default)s")
parser.add_argument("--prefix", dest="prefix", default="",
help="Add prefix to the output basename. Conflict with \"--out-base\".")
parser.add_argument("--out-base", dest="out_base", default="",
help="By default the output basename would be modified based on the input fastg file. "
"But you could assign a new basename with this option. Conflict with \"--prefix\". "
"Conflict with multiple input files!")
parser.add_argument("--log", dest="generate_log", default=False, action="store_true",
help="Generate log file.")
parser.add_argument("--wrapper", dest="wrapper_mode", default=False, action="store_true",
help="Wrapper mode logging when called by get_organelle*.py. Default: %(default)s")
parser.add_argument("--verbose", dest="verbose_log", default=False, action="store_true",
help="For debug usage.")
parser.add_argument("--continue", dest="resume", default=False, action="store_true",
help="Specified for calling from get_organelle_from_reads.py")
parser.add_argument("--no-overwrite", dest="overwrite", default=True, action="store_false",
help="Overwrite existing output result.")
parser.add_argument("--which-blast", dest="which_blast", default="",
help="Assign the path to BLAST binary files if not added to the path. "
"Default: try \"" + os.path.realpath("GetOrganelleDep") + "/" + SYSTEM_NAME +
"/ncbi-blast\" first, then $PATH")
parser.add_argument("--config-dir", dest="get_organelle_path", default=None,
help="The directory where the default databases were placed. "
"The default value also can be changed by adding 'export GETORG_PATH=your_favor' "
"to the shell script (e.g. ~/.bash_profile or ~/.bashrc) "
"Default: " + GO_PATH)
parser.add_argument("-t", "--threads", dest="threads", default=4, type=int,
help="Threads for blastn.")
parser.add_argument("-v", "--version", action="version",
version="GetOrganelle v{version}".format(version=get_versions()))
# redirect organelle types before parsing arguments
redirect_organelle_types = {"plant_cp": "embplant_pt",
"plant_pt": "embplant_pt",
"plant_mt": "embplant_mt",
"plant_nr": "embplant_nr"}
for go_arg, candidate_arg in enumerate(sys.argv):
if go_arg > 1 and sys.argv[go_arg - 1] in {"-F", "-E"}:
if candidate_arg in redirect_organelle_types:
sys.argv[go_arg] = redirect_organelle_types[candidate_arg]
elif "," in candidate_arg:
new_arg = []
for sub_arg in candidate_arg.split(","):
if sub_arg in redirect_organelle_types:
new_arg.append(redirect_organelle_types[sub_arg])
else:
new_arg.append(sub_arg)
sys.argv[go_arg] = ",".join(new_arg)
#
try:
options = parser.parse_args()
except Exception as e: #
sys.stdout.write('\n\n######################################'+str(e))
sys.stdout.write('\n\n"-h" for more usage\n')
exit()
else:
if not options.which_blast:
try_this_bin = os.path.join(GO_DEP_PATH, "ncbi-blast", "blastn")
if os.path.isfile(try_this_bin) and executable(try_this_bin):
output, err = subprocess.Popen(
try_this_bin + " -version", stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, shell=True).communicate()
if "not found" in output.decode("utf8"):
sys.stdout.write(output.decode("utf8") + "\n")
else:
options.which_blast = os.path.split(try_this_bin)[0]
if not executable(os.path.join(options.which_blast, "blastn")):
sys.stdout.write(os.path.join(options.which_blast, "blastn") + " not accessible!")
exit()
if not executable(os.path.join(options.which_blast, "makeblastdb")):
sys.stdout.write(os.path.join(options.which_blast, "makeblastdb") + " not accessible!")
exit()
if options.treat_no_hits not in ["ex_no_con", "ex_no_hit", "keep_all"]:
sys.stdout.write('\n\nOption Error: you should choose assign one of "ex_no_con", "ex_no_hit"'
' and "keep_all" to variable treat_no_hits\n')
exit()
priority_chosen = int(bool(options.include_priority)) + int(bool(options.exclude_priority))
secondary_chosen = int(bool(options.include)) + int(bool(options.exclude))
if priority_chosen + secondary_chosen > 0:
# sys.stdout.write("\norganelle_types is disabled since you assign the customized index/indices.\n")
if priority_chosen > 1:
sys.stdout.write('\n\nLogical Error: only one option with "-priority" allowed!\n')
exit()
in_chosen = int(bool(options.include_priority)) + int(bool(options.include))
if in_chosen > 1:
sys.stdout.write('\n\nOption Error: you can not simultaneously choose two "--include-*" options!\n')
exit()
ex_chosen = int(bool(options.exclude_priority)) + int(bool(options.exclude))
if ex_chosen > 1:
sys.stdout.write('\n\nOption Error: you can not simultaneously choose two "--exclude-*" options!\n')
exit()
if in_chosen == 1 and ex_chosen == 1 and priority_chosen == 0:
sys.stdout.write('\n\nOption Error: since you have include and exclude chosen, '
'one of them should be assigned priority!\n')
exit()
if ex_chosen == 1 and in_chosen == 0 and (options.treat_no_hits in ["ex_no_con", "ex_no_hit"]):
sys.stdout.write('\n\nOption Error: no contigs survive according to you choice!\n')
exit()
if options.include_priority:
include_priority_str = str(options.include_priority)
options.include_priority = []
for sub_i_p in include_priority_str.split(","):
if not os.path.exists(sub_i_p):
sys.stdout.write("Error: " + sub_i_p + " not found!\n")
exit()
# elif not os.path.exists(remove_db_postfix(sub_i_p) + ".nhr"):
# sys.stdout.write("Error: " + remove_db_postfix(sub_i_p) + ".nhr not found!\n")
# exit()
else:
options.include_priority.append(sub_i_p)
else:
options.include_priority = []
if options.exclude_priority:
exclude_priority_str = str(options.exclude_priority)
options.exclude_priority = []
for sub_e_p in exclude_priority_str.split(","):
if not os.path.exists(sub_e_p):
sys.stdout.write("Error: " + sub_e_p + " not found!\n")
exit()
# elif not os.path.exists(remove_db_postfix(sub_e_p) + ".nhr"):
# sys.stdout.write("Error: " + remove_db_postfix(sub_e_p) + ".nhr not found!\n")
# exit()
else:
options.exclude_priority.append(sub_e_p)
else:
options.exclude_priority = []
if options.include:
include_str = str(options.include)
options.include = []
for sub_i in include_str.split(","):
if not os.path.exists(sub_i):
sys.stdout.write("Error: " + sub_i + " not found!\n")
exit()
# elif not os.path.exists(remove_db_postfix(sub_i) + ".nhr"):
# sys.stdout.write("Error: " + remove_db_postfix(sub_i) + ".nhr not found!\n")
# exit()
else:
options.include.append(sub_i)
else:
options.include = []
if options.exclude:
exclude_str = str(options.exclude)
options.exclude = []
for sub_e in exclude_str.split(","):
if not os.path.exists(sub_e):
sys.stdout.write("Error: " + sub_e + " not found!\n")
exit()
# elif not os.path.exists(remove_db_postfix(sub_e) + ".nhr"):
# sys.stdout.write("Error: " + remove_db_postfix(sub_e) + ".nhr not found!\n")
# exit()
else:
options.exclude.append(sub_e)
else:
options.exclude = []
# elif options.organelle_types == 'embplant_pt':
# options.include_priority = [os.path.join(LBL_DB_PATH, 'embplant_pt.fasta')]
# options.exclude = [os.path.join(LBL_DB_PATH, 'embplant_mt.fasta')]
# elif options.organelle_types == 'embplant_mt':
# options.include_priority = [os.path.join(LBL_DB_PATH, 'embplant_mt.fasta')]
# options.exclude = [os.path.join(LBL_DB_PATH, 'embplant_pt.fasta')]
else:
global _GO_PATH, _LBL_DB_PATH, _SEQ_DB_PATH
if options.get_organelle_path:
_GO_PATH = os.path.expanduser(options.get_organelle_path)
if os.path.isdir(_GO_PATH):
_LBL_DB_PATH = os.path.join(_GO_PATH, LBL_NAME)
_SEQ_DB_PATH = os.path.join(_GO_PATH, SEQ_NAME)
else:
sys.stdout.write(
"\n############################################################################"
"\nERROR: path " + _GO_PATH + " invalid!\n")
exit()
if options.organelle_types:
def _check_default_db(this_sub_organelle, extra_type=""):
if not ((os.path.isfile(os.path.join(_LBL_DB_PATH, this_sub_organelle + ".fasta")) and
os.path.isfile(os.path.join(_SEQ_DB_PATH, this_sub_organelle + ".fasta")))):
sys.stdout.write(
"\n############################################################################"
"\nERROR: default " + this_sub_organelle + "," * int(bool(extra_type)) + extra_type +
" database has not been added yet!\n"
"\nInstall it by: get_organelle_config.py -a " + this_sub_organelle +
"," * int(bool(extra_type)) + extra_type +
"\nor\nInstall all types by: get_organelle_config.py -a all\n")
exit()
options.include_priority = []
options.organelle_types = options.organelle_types.split(",")
for sub_organelle_t in options.organelle_types:
if sub_organelle_t not in \
("embplant_pt", "other_pt", "embplant_mt", "embplant_nr",
"animal_mt", "fungus_mt", "fungus_nr"):
sys.stdout.write(
"\n############################################################################"
"\nERROR: \"-F\" MUST be one of 'embplant_pt', 'other_pt', 'embplant_mt', 'embplant_nr', "
"'animal_mt', 'fungus_mt', 'fungus_nr', or a combination of above split by comma(s)!\n\n")
exit()
else:
if not (os.path.isfile(os.path.join(_LBL_DB_PATH, sub_organelle_t + ".fasta")) and
os.path.isfile(os.path.join(_SEQ_DB_PATH, sub_organelle_t + ".fasta"))):
if sub_organelle_t in ("embplant_pt", "embplant_mt"):
for go_t, check_sub in enumerate(["embplant_pt", "embplant_mt"]):
_check_default_db(check_sub, ["embplant_pt", "embplant_mt"][not go_t])
else:
_check_default_db(sub_organelle_t)
else:
options.include_priority.append(os.path.join(_LBL_DB_PATH, sub_organelle_t + ".fasta"))
else:
options.organelle_types = []
if options.exclude_organelle_types:
options.exclude = []
options.exclude_organelle_types = options.exclude_organelle_types.split(",")
for sub_organelle_t in options.exclude_organelle_types:
if sub_organelle_t not in \
("embplant_pt", "other_pt", "embplant_mt", "embplant_nr",
"animal_mt", "fungus_mt", "fungus_nr"):
sys.stdout.write(
"\n############################################################################"
"\nERROR: \"-E\" MUST be one of 'embplant_pt', 'other_pt', 'embplant_mt', 'embplant_nr', "
"'animal_mt', 'fungus_mt', 'fungus_nr', or a combination of above split by comma(s)!\n\n")
exit()
else:
if not (os.path.isfile(os.path.join(_LBL_DB_PATH, sub_organelle_t + ".fasta")) and
os.path.isfile(os.path.join(_SEQ_DB_PATH, sub_organelle_t + ".fasta"))):
sys.stdout.write(
"\n############################################################################"
"\nERROR: default " + sub_organelle_t + " database has not been added yet!"
"\nInstall it by: get_organelle_config.py -a " + sub_organelle_t +
"\nor install all types by: get_organelle_config.py -a all\n")
exit()
else:
options.exclude.append(os.path.join(_LBL_DB_PATH, sub_organelle_t + ".fasta"))
if "--max-slim-extending-len" not in sys.argv:
default = options.max_slim_extending_len
if options.organelle_types:
options.max_slim_extending_len = 0
for sub_organelle_t in options.organelle_types:
if sub_organelle_t in ("embplant_mt", "other_pt", "fungus_mt"):
options.max_slim_extending_len = max(MAX_SLIM_EXTENDING_LENS["embplant_mt"], options.max_slim_extending_len)
elif sub_organelle_t == "embplant_pt":
options.max_slim_extending_len = max(MAX_SLIM_EXTENDING_LENS["embplant_pt"], options.max_slim_extending_len)
elif sub_organelle_t in ("embplant_nr", "fungus_nr", "animal_mt"):
options.max_slim_extending_len = max(MAX_SLIM_EXTENDING_LENS["embplant_nr"], options.max_slim_extending_len)
else:
options.max_slim_extending_len = default
else:
if options.max_slim_extending_len != inf:
options.max_slim_extending_len = int(options.max_slim_extending_len)
if not len(options.assemblies):
sys.stdout.write('\n\nInput Error: you must choose one input fasta or fastg file!\n')
exit()
if options.out_dir:
check_path_chars(options.out_dir)
log_output_dir = options.out_dir if options.out_dir else os.path.realpath(os.path.split(options.assemblies[0])[0])
if not os.path.isdir(log_output_dir):
os.mkdir(log_output_dir)
assert not (options.out_base and options.prefix), "\"--out-base\" conflicts with \"--prefix\"!"
assert not (options.out_base and len(options.assemblies) > 1), "\"--out-base\" conflicts with multiple input files!"
if options.out_base:
# Replace illegal characters for blastn
options.out_base = os.path.basename(options.out_base.replace("'", "_"))
if options.prefix:
# Replace illegal characters for blastn
options.prefix = os.path.basename(options.prefix.replace("'", "_"))
if options.generate_log:
log_handler = simple_log(logging.getLogger(), log_output_dir,
str((options.prefix + options.out_base + ".") * int(
bool(options.out_base))) + "slim.")
if not options.wrapper_mode:
log_handler.info(print_title)
log_handler.info(" ".join(["\"" + arg + "\"" if " " in arg else arg for arg in sys.argv]) + "\n")
log_handler = timed_log(log_handler, log_output_dir,
str((options.prefix + options.out_base + ".") * int(
bool(options.out_base))) + "slim.")
else:
log_handler = None
sys.stdout.write(print_title + "\n")
sys.stdout.write("\n" + " ".join(["\"" + arg + "\"" if " " in arg else arg for arg in sys.argv]) + "\n\n")
return options, options.assemblies, log_handler
def check_db(include_priority_f, include_f, exclude_priority_f, exclude_f, new_db_dir,
which_blast="", log_handler=None, verbose_log=False):
databases_made_for_this_run = []
in_index = []
ex_index = []
if include_priority_f:
in_index = include_priority_f
elif include_f:
in_index = include_f
if exclude_priority_f:
ex_index = exclude_priority_f
elif exclude_f:
ex_index = exclude_f
for check_blast_databases in [in_index, ex_index]:
for go_db, check_blast_db in enumerate(check_blast_databases):
if sum([os.path.exists(remove_db_postfix(check_blast_db) + postfix)
for postfix in (".nsq", ".nin", ".nhr")]) != 3:
if log_handler:
log_handler.info("Making BLAST database ... ")
else:
sys.stdout.write("\nMaking BLAST database ... \n")
# make output name
output_file_base = os.path.join(new_db_dir, os.path.basename(check_blast_db))
output_file_base = remove_db_postfix(output_file_base)
# make blast
make_blast_db(input_file=check_blast_db, output_base=output_file_base, which_blast=which_blast,
log_handler=log_handler, verbose_log=verbose_log)
databases_made_for_this_run.extend([output_file_base + postfix for postfix in (".nsq", ".nin", ".nhr")])
# modifiy the in_index and ex_index
check_blast_databases[go_db] = output_file_base
if log_handler:
log_handler.info("Making BLAST database finished.")
else:
sys.stdout.write("Making BLAST database finished.")
else:
check_blast_databases[go_db] = remove_db_postfix(check_blast_db)
return in_index, ex_index, databases_made_for_this_run
def make_new_matrix_with_names(names, old_matrix):
i = 0
while i < len(old_matrix[0]):
if old_matrix[0][i] in names:
i += 1
else:
del old_matrix[0][i]
del old_matrix[1][i]
return old_matrix
def blast_and_call_names(fasta_file, index_files, out_file, threads, e_value=1e-25, which_blast="", log_handler=None):
names = {}
if index_files:
time0 = time.time()
for index_f in index_files:
if log_handler:
log_handler.info('Executing BLAST to ' + index_f + ' ...')
else:
sys.stdout.write('\nExecuting BLAST to ' + index_f + '...')
execute_blast(query=fasta_file, blast_db=index_f, output=out_file, threads=threads,
outfmt=6, e_value=e_value, which_blast=which_blast, log_handler=log_handler)
time1 = time.time()
if log_handler:
log_handler.info('Executing BLAST to ' + index_f + ' finished.')
else:
sys.stdout.write('\nExecuting BLAST to '+os.path.split(index_f)[-1]+
' cost: '+str(round(time1-time0, 2)) + "\n")
try:
blast_out_lines = open(out_file, 'r')
except IOError:
if log_handler:
log_handler.error(os.path.join(which_blast, "blastn") + " was not properly configured.")
else:
sys.stdout.write("\n" + os.path.join(which_blast, "blastn") + " was not properly configured.")
raise EnvironmentError
this_database = os.path.split(index_f)[-1].split(" ")[0]
for line in blast_out_lines:
line_split = line.strip().split('\t')
query, hit = line_split[0], line_split[1]
q_start, q_end, q_score = int(line_split[6]), int(line_split[7]), float(line_split[2])
q_min, q_max = min(q_start, q_end), max(q_start, q_end)
# q_score = abs(q_max - q_min + 1)*q_score
if query in names:
if this_database not in names[query]:
names[query][this_database] = {}
if hit not in names[query][this_database]:
names[query][this_database][hit] = [(q_min, q_max, q_score)]
else:
# if overlap, then merge
i = 0
while i < len(names[query][this_database][hit]):
this_min, this_max, previous_q_score = names[query][this_database][hit][i]
if q_max < this_min:
break
elif q_min > this_max:
i += 1
continue
else:
q_min = min(q_min, this_min)
q_max = max(q_max, this_max)
q_score = max(previous_q_score, q_score)
del names[query][this_database][hit][i]
names[query][this_database][hit].insert(i, (q_min, q_max, q_score))
else:
names[query] = {this_database: {}}
names[query][this_database][hit] = [(q_min, q_max, q_score)]
if log_handler:
log_handler.info("Parsing blast result finished.")
else:
sys.stdout.write('Parsing blast result cost: '+str(round(time.time()-time1, 2)) + "\n")
return names
def summarize_q_score(info_of_a_query):
all_loci = []
for this_db in info_of_a_query:
for hits in info_of_a_query[this_db].values():
for locus in hits:
all_loci.append(list(locus))
all_loci.sort(key=lambda x: (x[0], x[1]))
i = 0
while i < len(all_loci) - 1:
if all_loci[i][1] >= all_loci[i+1][0]:
if all_loci[i][2] > all_loci[i+1][2]:
all_loci[i+1][0] = all_loci[i][1] + 1
if all_loci[i+1][0] > all_loci[i+1][1]:
del all_loci[i+1]
else:
i += 1
else:
all_loci[i][1] = all_loci[i+1][0] - 1
if all_loci[i][0] > all_loci[i][1]:
del all_loci[i]
else:
i += 1
else:
i += 1
return sum([this_locus[2]*(this_locus[1]-this_locus[0]+1) for this_locus in all_loci])
def modify_in_ex_according_to_depth(in_names, ex_names, significant, assembly_graph, depth_cutoff, log_handler=None):
here_in_names, here_ex_names = copy.deepcopy(in_names), copy.deepcopy(ex_names)
if assembly_graph:
training_in = set()
for query_name in list(in_names):
if query_name not in ex_names:
training_in.add(query_name)
training_ex = set()
for query_name in list(ex_names):
if query_name not in in_names:
training_ex.add(query_name)
for query_name in list(in_names):
if query_name in ex_names:
in_name_score = summarize_q_score(in_names[query_name])
ex_name_score = summarize_q_score(ex_names[query_name])
if in_name_score / float(ex_name_score) > significant:
training_in.add(query_name)
elif ex_name_score / float(in_name_score) > significant:
training_ex.add(query_name)
def get_average_coverage(here_q_list, here_info):
total_in_base = 0
total_in_len = 0
for here_q_name in here_q_list:
this_coverage = assembly_graph.vertex_info[here_q_name].cov
for here_db in here_info[here_q_name]:
for hits in here_info[here_q_name][here_db].values():
for q_min, q_max, q_score in hits:
this_len = abs(q_max - q_min) + 1
total_in_len += this_len
total_in_base += this_len * this_coverage
return total_in_base / float(total_in_len)
def combine_coverage_to_check():
aver_in_coverage = get_average_coverage(training_in, in_names)
aver_ex_coverage = get_average_coverage(training_ex, ex_names)
if log_handler:
log_handler.info("average in coverage: " + str(aver_in_coverage))
log_handler.info("average ex coverage: " + str(aver_ex_coverage))
else:
sys.stdout.write("\naverage in coverage: " + str(aver_in_coverage))
sys.stdout.write("\naverage ex coverage: " + str(aver_ex_coverage))
for q_name in list(here_in_names):
if q_name in here_ex_names:
in_score = summarize_q_score(here_in_names[q_name]) / \
(1 + abs(math.log(assembly_graph.vertex_info[q_name].cov / aver_in_coverage)))
ex_score = summarize_q_score(here_ex_names[q_name]) / \
(1 + abs(math.log(assembly_graph.vertex_info[q_name].cov / aver_ex_coverage)))
if in_score / float(ex_score) > significant:
del here_ex_names[q_name]
training_in.add(q_name)
training_ex.discard(q_name)
# sys.stdout.write('\n' + ' ' * 4 + q_name + ' included: '
# + str(round(in_name_score, 2)) + '~' + str(round(ex_name_score, 2)))
elif ex_score / float(in_score) > significant:
del here_in_names[q_name]
training_in.discard(q_name)
training_ex.add(q_name)
if 2 ** abs(math.log(assembly_graph.vertex_info[q_name].cov / aver_in_coverage, 2)) <= 5:
if log_handler:
log_handler.info(" " * 4 + q_name + " excluded: "
+ str(round(in_score, 2)) + '~' + str(round(ex_score, 2)))
else:
sys.stdout.write('\n' + ' ' * 4 + q_name + ' excluded: '
+ str(round(in_score, 2)) + '~' + str(round(ex_score, 2)) + "\n")
else:
pass
# sys.stdout.write('\n' + ' ' * 4 + query_name + ' with both hits: '
# + str(round(in_name_score, 2)) + '~' + str(round(ex_name_score, 2)))
aver_in_coverage = get_average_coverage(training_in, in_names)
aver_ex_coverage = get_average_coverage(training_ex, ex_names)
if log_handler:
log_handler.info("average in coverage: " + str(aver_in_coverage))
log_handler.info("average ex coverage: " + str(aver_ex_coverage))
else:
sys.stdout.write("\naverage in coverage: " + str(aver_in_coverage))
sys.stdout.write("\naverage ex coverage: " + str(aver_ex_coverage))
for q_name in list(here_in_names):
if 2 ** abs(math.log(assembly_graph.vertex_info[q_name].cov / aver_in_coverage, 2)) >= depth_cutoff:
del here_in_names[q_name]
return here_in_names, here_ex_names, aver_in_coverage
if training_in and training_ex:
combine_coverage_to_check()
else:
for query_name in list(here_in_names):
if query_name in here_ex_names:
in_name_score = summarize_q_score(here_in_names[query_name])
ex_name_score = summarize_q_score(here_ex_names[query_name])
if in_name_score / float(ex_name_score) > significant:
training_in.add(query_name)
training_ex.discard(query_name)
elif ex_name_score / float(in_name_score) > significant:
training_in.discard(query_name)
training_ex.add(query_name)
if training_in and training_ex:
combine_coverage_to_check()
else:
if log_handler:
log_handler.info("No enough coverage information found.")
else:
sys.stdout.write("No enough coverage information found.\n")
else:
if log_handler:
log_handler.info("No coverage information found.")
else:
sys.stdout.write("No coverage information found.\n")
for query_name in list(here_in_names):
if query_name in here_ex_names:
in_name_score = summarize_q_score(here_in_names[query_name])
ex_name_score = summarize_q_score(here_ex_names[query_name])
if in_name_score/float(ex_name_score) > significant:
del here_ex_names[query_name]
# sys.stdout.write('\n'+' ' * 4 + query_name + ' included: '
# + str(round(in_name_score, 2))+'~'+str(round(ex_name_score, 2)))
elif ex_name_score/float(in_name_score) > significant:
del here_in_names[query_name]
# sys.stdout.write('\n'+' '*4+query_name+' excluded: '
# + str(round(in_name_score, 2))+'~'+str(round(ex_name_score, 2)))
else:
pass
# sys.stdout.write('\n'+' '*4+query_name+' with both hits: '
# + str(round(in_name_score, 2))+'~'+str(round(ex_name_score, 2)))
return here_in_names, here_ex_names, None
def generate_baits_offsets(in_names, databases, assembly_graph):
vertex_trimming = {}
# structure: names[query][this_database][label] = [(q_min, q_max, q_score)]
for vertex_name in in_names:
these_hit_list = []
for include_db_file in databases:
include_db_file = os.path.split(include_db_file)[-1].split(" ")[0]
if include_db_file in in_names[vertex_name]:
for hit_info_list in in_names[vertex_name][include_db_file].values():
these_hit_list.extend(hit_info_list)
all_loc_values = [x[0] for x in these_hit_list] + [x[1] for x in these_hit_list]
min_loc = min(all_loc_values)
max_loc = min(all_loc_values)
vertex_trimming[(vertex_name, False)] = min_loc - 1
vertex_trimming[(vertex_name, True)] = assembly_graph.vertex_info[vertex_name].len - max_loc
return vertex_trimming
def reduce_matrix(in_names, ex_names, seq_matrix, assembly_graph, max_slim_extending_len, bait_offsets,
aver_in_dep, depth_cutoff, treat_no_hits,
include_priority_assigned, include_assigned, exclude_priority_assigned, exclude_assigned,
log_handler=None):
if log_handler:
log_handler.info("Mapping names ...")
time0 = time.time()
# candidate_short_to_2fulls = {}
if assembly_graph:
if aver_in_dep:
rm_contigs = [this_v.v_name
for this_v in assembly_graph
if 2 ** abs(math.log(this_v.cov / aver_in_dep, 2)) < depth_cutoff]
assembly_graph.remove_vertex(rm_contigs)
if exclude_priority_assigned:
assembly_graph.remove_vertex(ex_names)
if treat_no_hits == "ex_no_con":
assembly_graph.reduce_to_subgraph(bait_vertices=in_names,
bait_offsets=bait_offsets,
limit_extending_len=max_slim_extending_len,
extending_len_weighted_by_depth=True)
elif treat_no_hits == "ex_no_hit":
assembly_graph.remove_vertex([rm_c for rm_c in assembly_graph.vertex_info if rm_c not in in_names])
else:
pass
elif include_priority_assigned or include_assigned:
if treat_no_hits == "ex_no_con":
assembly_graph.remove_vertex([rm_c for rm_c in ex_names if rm_c not in in_names])
assembly_graph.reduce_to_subgraph(bait_vertices=in_names,
bait_offsets=bait_offsets,
limit_extending_len=max_slim_extending_len,
extending_len_weighted_by_depth=True)
elif treat_no_hits == "ex_no_hit":
assembly_graph.remove_vertex([rm_c for rm_c in assembly_graph.vertex_info if rm_c not in in_names])
else:
pass
elif exclude_assigned:
assembly_graph.remove_vertex(ex_names)
else:
pass
else:
# accepted = set()
if exclude_priority_assigned:
seq_matrix.remove(ex_names)
if treat_no_hits in ("ex_no_con", "ex_no_hit"):
seq_matrix.remove([rm_c.label for rm_c in seq_matrix if rm_c.label not in in_names])
else:
pass
elif include_priority_assigned or include_assigned:
if treat_no_hits in ["ex_no_con", "ex_no_hit"]:
seq_matrix.remove([rm_c.label for rm_c in seq_matrix if rm_c.label not in in_names])
else:
seq_matrix.remove(ex_names)
elif exclude_assigned:
seq_matrix.remove(ex_names)
else:
pass
if log_handler:
log_handler.info("Mapping names finished.")
else:
sys.stdout.write('\nMapping names cost: '+str(round(time.time()-time0, 2)) + "\n")
return assembly_graph, seq_matrix
def write_hits_tab_for_bandage(in_names, ex_names, out_file, overwrite, assembly_graph, log_handler=None):
if not overwrite:
while os.path.exists(out_file+'.csv'):
out_file += '_'
out_file += '.csv'
out_lines = []
# if include_file:
# in_database = os.path.split(include_file)[-1]
# if exclude_file:
# ex_database = os.path.split(exclude_file)[-1]
edges_set = set(in_names)
for edge in ex_names:
edges_set.add(edge)
edges = list(edges_set)
for edge in edges:
this_string = edge
if edge in in_names and edge in ex_names:
databases = sorted(set(in_names[edge]) | set(ex_names[edge]))
this_string += '\t' + ";".join(databases)
this_db_hits = {db_name: set() for db_name in databases}
for this_db in in_names[edge]:
for hit_n in in_names[edge][this_db]:
this_db_hits[this_db].add(hit_n)
for this_db in ex_names[edge]:
for hit_n in ex_names[edge][this_db]:
this_db_hits[this_db].add(hit_n)
this_string += "\t" + ";".join([",".join(sorted(this_db_hits[in_db])) for in_db in databases])
# this_string += '\t' + ','.join(
# [hit_n for this_db in in_names[edge] for hit_n in in_names[edge][this_db]]) + ';' + ','.join(
# [hit_n for this_db in ex_names[edge] for hit_n in ex_names[edge][this_db]])
loci = []
for in_database in in_names[edge]:
for locus in in_names[edge][in_database]:
for region in in_names[edge][in_database][locus]:
loci.append([region[0], region[1], locus, in_database])
for ex_database in ex_names[edge]:
for locus in ex_names[edge][ex_database]:
for region in ex_names[edge][ex_database][locus]:
loci.append([region[0], region[1], locus, ex_database])
elif edge in in_names:
databases = sorted(set(in_names[edge]))
this_string += '\t' + ";".join(databases)
this_db_hits = {db_name: set() for db_name in databases}
for this_db in in_names[edge]:
for hit_n in in_names[edge][this_db]:
this_db_hits[this_db].add(hit_n)
this_string += "\t" + ";".join([",".join(sorted(this_db_hits[in_db])) for in_db in databases])
# this_string += '\t' + ','.join(
# [hit_n for this_db in in_names[edge] for hit_n in in_names[edge][this_db]])
loci = []
for in_database in in_names[edge]:
for locus in in_names[edge][in_database]:
for region in in_names[edge][in_database][locus]:
loci.append([region[0], region[1], locus, in_database])
else:
databases = sorted(set(ex_names[edge]))
this_string += '\t' + ";".join(databases)
this_db_hits = {db_name: set() for db_name in databases}
for this_db in ex_names[edge]:
for hit_n in ex_names[edge][this_db]:
this_db_hits[this_db].add(hit_n)
this_string += "\t" + ";".join([",".join(sorted(this_db_hits[in_db])) for in_db in databases])
# this_string += '\t' + ','.join(
# [hit_n for this_db in ex_names[edge] for hit_n in ex_names[edge][this_db]])
loci = []
for ex_database in ex_names[edge]:
for locus in ex_names[edge][ex_database]:
for region in ex_names[edge][ex_database][locus]:
loci.append([region[0], region[1], locus, ex_database])
loci.sort(key=lambda x: x[0])
i = 1
while i < len(loci):
if loci[i-1][2] == loci[i][2]:
loci[i-1][1] = loci[i][1]
del loci[i]
else:
i += 1
postfix = ''
if assembly_graph:
if edge in assembly_graph.vertex_info:
next_edges = [next_v
for next_v, next_e in assembly_graph.vertex_info[edge].connections[True]
if next_v in assembly_graph.vertex_info]
if next_edges:
next_edges.sort(
key=lambda x: (x not in in_names, x not in ex_names, -assembly_graph.vertex_info[x].cov))
postfix = ">>" + next_edges[0]
this_string += '\t'+'>>'.join([x[2] for x in loci if x[2] != 'noncoding'])+postfix
this_string += '\t'+'>>'.join([x[2] for x in loci])+postfix
this_string += '\t'+'>>'.join([x[2]+'('+str(x[0])+'-'+str(x[1])+','+x[3]+')' for x in loci])+postfix
this_string += '\n'
out_lines.append(this_string)
out_lines.sort()
out_lines = ['EDGE\tdatabase\tloci\tloci_gene_sequential\tloci_sequential\tdetails\n'] + out_lines
open(out_file, 'w').writelines(out_lines)
if log_handler:
log_handler.info("Generating notation table to " + out_file)
else:
sys.stdout.write("Generating notation table to " + out_file + "\n")
def remove_temp_files(fastg_base, keep_temp, other_files_to_remove):
if not keep_temp:
try:
os.remove(fastg_base + '.blast_in')
except OSError:
pass
try:
os.remove(fastg_base + '.blast_ex')
except OSError:
pass
for rm_f in other_files_to_remove:
try:
os.remove(rm_f)
except OSError:
pass
def main():
time0 = time.time()
print_title = "GetOrganelle v" + str(get_versions()) + \
"\n" \
"\nslim_graph.py is a script for excluding certain contigs " \
"from assembly graph file (*.fastg/*.fasta) by blast\n" \
"By jinjianjun@mail.kib.ac.cn\n"
options, assemblies, log_handler = get_options(print_title)
from GetOrganelleLib.assembly_parser import Assembly
from GetOrganelleLib.seq_parser import SequenceList
log_output_dir = options.out_dir if options.out_dir else os.path.split(assemblies[0])[0]
log_output_name = str((options.prefix + options.out_base + ".") * int(bool(options.out_base))) + "slim."
try:
if not log_handler:
sys.stdout.write('\n' + '=' * 100)
if options.out_dir and not os.path.exists(options.out_dir):
os.mkdir(options.out_dir)
# make blast database if not made
other_files_to_remove = []
include_indices, exclude_indices, database_made = \
check_db(options.include_priority, options.include,
options.exclude_priority, options.exclude,
new_db_dir=options.out_dir if options.out_dir else os.path.split(assemblies[0])[0],
which_blast=options.which_blast, log_handler=log_handler, verbose_log=options.verbose_log)
other_files_to_remove.extend(database_made)
for i in range(len(assemblies)):
fas_file = assemblies[i]
if log_handler:
log_handler.info('Slimming file '+str(i+1)+'/'+str(len(assemblies))+': '+fas_file)
else:
sys.stdout.write('\nSlimming file '+str(i+1)+'/'+str(len(assemblies))+': '+fas_file+'\n')
#######################################
# 0. initialization: define variables #
#######################################
is_fastg = fas_file.endswith('.fastg')
is_gfa = fas_file.endswith('.gfa')
is_graph = is_fastg or is_gfa
output_dir = options.out_dir if options.out_dir else os.path.split(os.path.realpath(fas_file))[0]
check_path_chars(output_dir)
if options.out_base:
# ignore other modifications
constrained_full_out_base = os.path.join(output_dir, options.out_base)
full_out_fasta = constrained_full_out_base
else:
constrained_full_out_base = ""
# Replace illegal characters for blastn
full_out_fasta = os.path.join(output_dir,
options.prefix + os.path.basename(fas_file.replace("'", "_")))
check_path_chars(full_out_fasta)
blast_fas = full_out_fasta + ".Temp"
if constrained_full_out_base:
out_fas = constrained_full_out_base + '.' + str(fas_file).split('.')[-1]
out_csv = constrained_full_out_base
else: # if there's no out_base requirements, add modifications to the name
in_ex_info = generate_in_ex_info_name(include_indices=include_indices,
exclude_indices=exclude_indices,
exclude_no_con=options.treat_no_hits == 'ex_no_con',
exclude_no_hit=options.treat_no_hits == 'ex_no_hit')
out_fas = full_out_fasta + in_ex_info + '.' + str(fas_file).split('.')[-1]
out_csv = full_out_fasta + in_ex_info
#######################
# 1. parsing sequence #
#######################
time_r0 = time.time()
this_assembly = Assembly()
this_matrix = None
if is_graph:
this_assembly = Assembly(graph_file=fas_file, min_cov=options.min_depth, max_cov=options.max_depth)
# merge contigs
if options.merge_contigs:
this_assembly.merge_all_possible_vertices()
else:
this_matrix = SequenceList(fas_file)
if log_handler:
log_handler.info("Parsing input finished.")
else:
sys.stdout.write("\nParsing input cost: " + str(round(time.time() - time_r0, 2)) + "\n")
###################################
# 2. prepare fasta file for blast #
###################################
if bool(include_indices) or bool(exclude_indices):
t_dc = time.time()
if is_graph:
# del complementary to avoid using both the forward and reverse sequence for blast
this_assembly.write_to_fasta(blast_fas, interleaved=70, check_postfix=False)
else:
# remove space or other characters from the seq names
changed_name_dict = {}
for seq_record in this_matrix:
new_name = seq_record.label.replace(" ", "_").replace("&", "_").replace("#", "_")
if new_name in changed_name_dict:
raise Exception("Conflict names:\n" + changed_name_dict[new_name] + " -> " + new_name +
"\n" + seq_record.label + " -> " + new_name)
else:
changed_name_dict[new_name] = seq_record.label
seq_record.label = new_name
this_matrix.write_fasta(blast_fas, interleaved=70)
other_files_to_remove.append(blast_fas)
if log_handler:
log_handler.info("Preparing fasta file finished.")
else:
sys.stdout.write('\nPreparing fasta file cost: %.2f\n' % (time.time() - t_dc))
############
# 3. BLAST #
############
try:
# structure: names[query][this_database][label] = [(q_min, q_max, q_score)]
in_names = blast_and_call_names(fasta_file=blast_fas, index_files=include_indices,
out_file=blast_fas+'.blast_in', threads=options.threads,
e_value=options.evalue,
which_blast=options.which_blast, log_handler=log_handler)
ex_names = blast_and_call_names(fasta_file=blast_fas, index_files=exclude_indices,
out_file=blast_fas+'.blast_ex', threads=options.threads,
e_value=options.evalue,
which_blast=options.which_blast, log_handler=log_handler)
if bool(include_indices) or bool(exclude_indices):
in_names_r, ex_names_r, aver_dep = modify_in_ex_according_to_depth(
in_names=in_names, ex_names=ex_names, significant=options.significant,
assembly_graph=this_assembly, depth_cutoff=options.depth_cutoff, log_handler=log_handler)
else:
in_names_r, ex_names_r, aver_dep = in_names, ex_names, None
# prepare bait_offsets: trim unlabeled terminal regions from bait vertices, for more accurate
# control of "maximum slimming extending length"
if this_assembly and options.treat_no_hits == "ex_no_con" and \
options.max_slim_extending_len not in (None, inf):
bait_offsets = generate_baits_offsets(
in_names=in_names, databases=include_indices, assembly_graph=this_assembly)
else:
bait_offsets = {}
new_assembly, new_matrix = \
reduce_matrix(in_names=in_names_r, ex_names=ex_names_r, seq_matrix=this_matrix,
assembly_graph=this_assembly, max_slim_extending_len=options.max_slim_extending_len,
bait_offsets=bait_offsets, aver_in_dep=aver_dep,
depth_cutoff=options.depth_cutoff, treat_no_hits=options.treat_no_hits,
include_priority_assigned=options.include_priority,
include_assigned=options.include,
exclude_priority_assigned=options.exclude_priority,
exclude_assigned=options.exclude, log_handler=log_handler)
if log_handler:
log_handler.info("Generating slimmed file to " + out_fas)
else:
sys.stdout.write("Generating slimmed file to " + out_fas + "\n")
if new_assembly:
if is_fastg:
new_assembly.write_to_fastg(out_fas, check_postfix=False)
else:
new_assembly.write_to_gfa(out_fas, check_postfix=False)
else:
new_matrix.write_fasta(out_fas, overwrite=options.overwrite)
# write out hits tab according to blast
if not options.no_tab:
write_hits_tab_for_bandage(
in_names=in_names, ex_names=ex_names, out_file=out_csv, overwrite=options.overwrite,
assembly_graph=this_assembly, log_handler=log_handler)
except Exception as e:
if log_handler:
log_handler.error("\n" + str(e).strip())
log_handler.error(
'Slimming file ' + str(i + 1) + '/' + str(len(assemblies)) + ': ' + assemblies[i] + ' failed!\n')
if options.verbose_log:
raise e
else:
sys.stdout.write("\n" + str(e).strip() + "\n")
sys.stdout.write(
'\nSlimming file ' + str(i + 1) + '/' + str(len(assemblies)) + ': ' + assemblies[i] + ' failed!'
'\n' + '=' * 100 + "\n")
if options.verbose_log:
raise e
else:
if log_handler:
log_handler.info('Slimming file ' + str(i+1) + '/' + str(len(assemblies)) + ': ' + assemblies[i] + ' finished!\n')
else:
sys.stdout.write('\nSlimming file ' + str(i+1) + '/' + str(len(assemblies)) + ': ' + assemblies[i] + ' finished!'
'\n' + '=' * 100 + "\n")
#######################
# 4. clean temp files #
#######################
if i == len(assemblies) - 1:
remove_temp_files(
fastg_base=blast_fas, keep_temp=options.keep_temp, other_files_to_remove=other_files_to_remove)
else:
remove_temp_files(
fastg_base=blast_fas, keep_temp=options.keep_temp, other_files_to_remove=[])
if not options.wrapper_mode:
if log_handler:
log_handler = simple_log(log_handler, log_output_dir, log_output_name)
log_handler.info("\nTotal cost " + "%.2f" % (time.time() - time0) + " s")
log_handler.info("Thank you!")
else:
sys.stdout.write('\nTotal cost: ' + str(round(time.time() - time0, 2)) + '\nThank you!\n')
except Exception as e:
if log_handler:
log_handler.exception("")
if not options.wrapper_mode:
log_handler = simple_log(log_handler, log_output_dir, log_output_name)
log_handler.info("\nTotal cost " + "%.2f" % (time.time() - time0) + " s")
log_handler.info("Thank you!")
else:
raise e
if log_handler:
logging.shutdown()
if __name__ == '__main__':
main()
"""Copyright 2016 Jianjun Jin
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."""
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2803,
26,
2774,
24,
199,
646,
900,
199,
646,
747,
199,
646,
984,
199,
646,
3873,
199,
893,
26,
272,
327,
2366,
18,
272,
492,
3718,
199,
2590,
26,
272,
986,
199,
4904,
275,
2069,
480,
4904,
531,
199,
504,
7534,
492,
27615,
199,
3243,
63,
3359,
63,
24571,
63,
10484,
275,
747,
14,
515,
14,
1294,
8,
736,
14,
515,
14,
11091,
3460,
493,
8964,
59,
16,
61,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
904,
8,
3243,
63,
3359,
63,
24571,
63,
10484,
12,
21777,
2237,
199,
646,
2372,
11014,
4822,
274,
4728,
199,
504,
2372,
11014,
4822,
274,
4728,
14,
6234,
492,
664,
63,
6234,
199,
504,
2372,
11014,
4822,
274,
4728,
14,
4990,
63,
2785,
63,
1532,
492,
627,
199,
646,
3473,
199,
646,
1331,
199,
3243,
63,
3359,
63,
24571,
63,
10484,
275,
747,
14,
515,
14,
1294,
8,
736,
14,
515,
14,
11091,
3460,
493,
8964,
59,
16,
61,
199,
646,
4298,
199,
12711,
63,
2339,
275,
3087,
199,
692,
4298,
14,
2253,
342,
508,
298,
14091,
582,
272,
20859,
63,
2339,
275,
298,
5135,
2,
199,
4164,
4298,
14,
2253,
342,
508,
298,
31065,
582,
272,
20859,
63,
2339,
275,
298,
3088,
3100,
2,
199,
2836,
26,
272,
984,
14,
2703,
14,
952,
480,
547,
26,
5544,
2372,
11014,
4822,
274,
365,
440,
3748,
367,
298,
435,
4298,
14,
2253,
342,
435,
19724,
6099,
272,
4458,
342,
199,
13160,
63,
5617,
63,
3243,
275,
747,
14,
515,
14,
1294,
8,
1002,
11014,
4822,
274,
4728,
855,
493,
363,
2788,
16,
61,
199,
13160,
63,
10814,
63,
3243,
275,
747,
14,
515,
14,
11091,
8,
736,
14,
515,
14,
904,
8,
13160,
63,
5617,
63,
3243,
12,
21777,
401,
298,
1002,
11014,
4822,
274,
8598,
401,
20859,
63,
2339,
430,
199,
5600,
63,
3243,
63,
16326,
275,
663,
480,
21515,
81,
2135,
369,
1907,
411,
18196,
3561,
74,
9503,
90,
1812,
86,
10472,
77,
49,
12018,
2099,
6379,
1938,
1179,
3888,
39,
22313,
14307,
15473,
12847,
18273,
45,
12,
13186,
485,
6793,
531,
199,
199,
63,
13160,
63,
3243,
275,
598,
47,
63,
3243,
199,
63,
44,
7847,
63,
2846,
63,
3243,
275,
491,
7847,
63,
2846,
63,
3243,
199,
63,
28674,
63,
2846,
63,
3243,
275,
5795,
49,
63,
2846,
63,
3243,
421,
199,
318,
1104,
63,
515,
63,
6574,
8,
515,
63,
269,
63,
493,
63,
354,
304,
272,
367,
642,
63,
1560,
315,
931,
63,
269,
63,
493,
63,
354,
26,
267,
340,
642,
63,
1560,
440,
315,
22049,
63,
3243,
63,
16326,
26,
288,
746,
2186,
480,
3364,
1495,
19669,
435,
642,
63,
1560,
435,
30768,
687,
314,
1324,
570,
15,
515,
298,
435,
931,
63,
269,
63,
493,
63,
354,
435,
298,
9124,
421,
199,
318,
664,
63,
1419,
8,
1361,
63,
1213,
304,
272,
4503,
275,
298,
1548,
7210,
495,
8,
736,
14,
515,
14,
4846,
3460,
493,
3368,
5207,
24869,
63,
2180,
63,
1725,
446,
38,
25316,
31655,
63,
541,
446,
37,
25316,
31655,
63,
2037,
531,
272,
1798,
275,
27615,
8,
1802,
29,
1361,
63,
1213,
12,
4503,
29,
3807,
9,
272,
327,
1798,
14,
525,
63,
2094,
6096,
79,
401,
2053,
628,
548,
63,
7015,
71,
63,
493,
401,
1720,
628,
2959,
570,
531,
272,
327,
4766,
272,
1798,
14,
525,
63,
2094,
480,
305,
8946,
6528,
401,
8214,
628,
305,
8946,
6528,
401,
730,
29,
495,
12,
9237,
16368,
401,
717,
1720,
628,
3205,
24869,
334,
2180,
9,
1584,
17048,
20309,
503,
1275,
71,
667,
503,
1275,
7015,
71,
680,
7754,
3715,
314,
1584,
701,
7883,
2685,
272,
1798,
14,
525,
63,
2094,
6096,
38,
401,
2053,
628,
1308,
4822,
274,
63,
1313,
401,
717,
1720,
628,
7207,
379,
543,
818,
25316,
31655,
63,
541,
12,
1163,
63,
541,
12,
25316,
31655,
63,
2037,
12,
25316,
31655,
63,
7865,
12,
298,
2490,
298,
290,
7265,
63,
2037,
12,
9627,
17360,
63,
2037,
12,
9627,
17360,
63,
7865,
298,
2490,
7340,
6777,
4910,
25316,
651,
411,
3577,
502,
299,
2019,
1377,
12,
2222,
13,
18847,
651,
411,
3577,
502,
299,
2019,
1377,
12,
298,
2490,
298,
31655,
333,
24308,
335,
7835,
322,
265,
12,
1620,
867,
302,
947,
4025,
8012,
656,
83,
676,
279,
820,
7170,
12,
376,
7265,
333,
24308,
335,
7835,
322,
265,
12,
298,
2490,
298,
7036,
17360,
333,
24308,
335,
7835,
322,
265,
12,
9627,
17360,
302,
947,
4025,
8012,
656,
83,
676,
279,
820,
7170,
18159,
395,
298,
2490,
298,
269,
282,
14665,
402,
3432,
3715,
701,
10029,
8,
83,
9,
298,
2490,
7340,
989,
3853,
795,
370,
9842,
2368,
465,
2569,
10532,
680,
298,
2490,
1867,
84,
2,
2490,
298,
9527,
8648,
298,
2490,
1867,
685,
887,
31655,
63,
541,
971,
84,
8441,
1553,
2613,
13,
6693,
298,
435,
747,
14,
515,
14,
904,
8,
44,
7847,
63,
2846,
63,
3243,
12,
298,
18847,
31655,
63,
541,
14,
20309,
531,
435,
1867,
341,
2490,
298,
9527,
8648,
298,
2490,
1867,
15336,
63,
541,
971,
84,
8441,
1553,
2613,
13,
6693,
298,
435,
747,
14,
515,
14,
904,
8,
44,
7847,
63,
2846,
63,
3243,
12,
298,
1848,
63,
541,
14,
20309,
531,
435,
1867,
341,
2490,
298,
9527,
8648,
298,
14924,
260,
2490,
1867,
685,
887,
31655,
63,
2037,
971,
84,
8441,
1553,
2613,
13,
6693,
298,
435,
747,
14,
515,
14,
904,
8,
44,
7847,
63,
2846,
63,
3243,
12,
298,
18847,
31655,
63,
2037,
14,
20309,
531,
435,
1867,
341,
2490,
298,
9527,
8648,
298,
2490,
1867,
685,
887,
31655,
63,
7865,
971,
84,
8441,
1553,
2613,
13,
6693,
298,
435,
747,
14,
515,
14,
904,
8,
44,
7847,
63,
2846,
63,
3243,
12,
298,
18847,
31655,
63,
7865,
14,
20309,
531,
435,
1867,
341,
2490,
298,
9527,
8648,
298,
2490,
1867,
4304,
7265,
63,
2037,
971,
84,
8441,
1553,
2613,
13,
6693,
298,
435,
747,
14,
515,
14,
904,
8,
44,
7847,
63,
2846,
63,
3243,
12,
298,
290,
7265,
63,
2037,
14,
20309,
531,
435,
1867,
341,
2490,
298,
9527,
8648,
298,
2490,
1867,
78,
7036,
17360,
63,
2037,
971,
84,
8441,
1553,
2613
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2803,
26,
2774,
24,
199,
646,
900,
199,
646,
747,
199,
646,
984,
199,
646,
3873,
199,
893,
26,
272,
327,
2366,
18,
272,
492,
3718,
199,
2590,
26,
272,
986,
199,
4904,
275,
2069,
480,
4904,
531,
199,
504,
7534,
492,
27615,
199,
3243,
63,
3359,
63,
24571,
63,
10484,
275,
747,
14,
515,
14,
1294,
8,
736,
14,
515,
14,
11091,
3460,
493,
8964,
59,
16,
61,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
904,
8,
3243,
63,
3359,
63,
24571,
63,
10484,
12,
21777,
2237,
199,
646,
2372,
11014,
4822,
274,
4728,
199,
504,
2372,
11014,
4822,
274,
4728,
14,
6234,
492,
664,
63,
6234,
199,
504,
2372,
11014,
4822,
274,
4728,
14,
4990,
63,
2785,
63,
1532,
492,
627,
199,
646,
3473,
199,
646,
1331,
199,
3243,
63,
3359,
63,
24571,
63,
10484,
275,
747,
14,
515,
14,
1294,
8,
736,
14,
515,
14,
11091,
3460,
493,
8964,
59,
16,
61,
199,
646,
4298,
199,
12711,
63,
2339,
275,
3087,
199,
692,
4298,
14,
2253,
342,
508,
298,
14091,
582,
272,
20859,
63,
2339,
275,
298,
5135,
2,
199,
4164,
4298,
14,
2253,
342,
508,
298,
31065,
582,
272,
20859,
63,
2339,
275,
298,
3088,
3100,
2,
199,
2836,
26,
272,
984,
14,
2703,
14,
952,
480,
547,
26,
5544,
2372,
11014,
4822,
274,
365,
440,
3748,
367,
298,
435,
4298,
14,
2253,
342,
435,
19724,
6099,
272,
4458,
342,
199,
13160,
63,
5617,
63,
3243,
275,
747,
14,
515,
14,
1294,
8,
1002,
11014,
4822,
274,
4728,
855,
493,
363,
2788,
16,
61,
199,
13160,
63,
10814,
63,
3243,
275,
747,
14,
515,
14,
11091,
8,
736,
14,
515,
14,
904,
8,
13160,
63,
5617,
63,
3243,
12,
21777,
401,
298,
1002,
11014,
4822,
274,
8598,
401,
20859,
63,
2339,
430,
199,
5600,
63,
3243,
63,
16326,
275,
663,
480,
21515,
81,
2135,
369,
1907,
411,
18196,
3561,
74,
9503,
90,
1812,
86,
10472,
77,
49,
12018,
2099,
6379,
1938,
1179,
3888,
39,
22313,
14307,
15473,
12847,
18273,
45,
12,
13186,
485,
6793,
531,
199,
199,
63,
13160,
63,
3243,
275,
598,
47,
63,
3243,
199,
63,
44,
7847,
63,
2846,
63,
3243,
275,
491,
7847,
63,
2846,
63,
3243,
199,
63,
28674,
63,
2846,
63,
3243,
275,
5795,
49,
63,
2846,
63,
3243,
421,
199,
318,
1104,
63,
515,
63,
6574,
8,
515,
63,
269,
63,
493,
63,
354,
304,
272,
367,
642,
63,
1560,
315,
931,
63,
269,
63,
493,
63,
354,
26,
267,
340,
642,
63,
1560,
440,
315,
22049,
63,
3243,
63,
16326,
26,
288,
746,
2186,
480,
3364,
1495,
19669,
435,
642,
63,
1560,
435,
30768,
687,
314,
1324,
570,
15,
515,
298,
435,
931,
63,
269,
63,
493,
63,
354,
435,
298,
9124,
421,
199,
318,
664,
63,
1419,
8,
1361,
63,
1213,
304,
272,
4503,
275,
298,
1548,
7210,
495,
8,
736,
14,
515,
14,
4846,
3460,
493,
3368,
5207,
24869,
63,
2180,
63,
1725,
446,
38,
25316,
31655,
63,
541,
446,
37,
25316,
31655,
63,
2037,
531,
272,
1798,
275,
27615,
8,
1802,
29,
1361,
63,
1213,
12,
4503,
29,
3807,
9,
272,
327,
1798,
14,
525,
63,
2094,
6096,
79,
401,
2053,
628,
548,
63,
7015,
71,
63,
493,
401,
1720,
628,
2959,
570,
531,
272,
327,
4766,
272,
1798,
14,
525,
63,
2094,
480,
305,
8946,
6528,
401,
8214,
628,
305,
8946,
6528,
401,
730,
29,
495,
12,
9237,
16368,
401,
717,
1720,
628,
3205,
24869,
334,
2180,
9,
1584,
17048,
20309,
503,
1275,
71,
667,
503,
1275,
7015,
71,
680,
7754,
3715,
314,
1584,
701,
7883,
2685,
272,
1798,
14,
525,
63,
2094,
6096,
38,
401,
2053,
628,
1308,
4822,
274,
63,
1313,
401,
717,
1720,
628,
7207,
379,
543,
818,
25316,
31655,
63,
541,
12,
1163,
63,
541,
12,
25316,
31655,
63,
2037,
12,
25316,
31655,
63,
7865,
12,
298,
2490,
298,
290,
7265,
63,
2037,
12,
9627,
17360,
63,
2037,
12,
9627,
17360,
63,
7865,
298,
2490,
7340,
6777,
4910,
25316,
651,
411,
3577,
502,
299,
2019,
1377,
12,
2222,
13,
18847,
651,
411,
3577,
502,
299,
2019,
1377,
12,
298,
2490,
298,
31655,
333,
24308,
335,
7835,
322,
265,
12,
1620,
867,
302,
947,
4025,
8012,
656,
83,
676,
279,
820,
7170,
12,
376,
7265,
333,
24308,
335,
7835,
322,
265,
12,
298,
2490,
298,
7036,
17360,
333,
24308,
335,
7835,
322,
265,
12,
9627,
17360,
302,
947,
4025,
8012,
656,
83,
676,
279,
820,
7170,
18159,
395,
298,
2490,
298,
269,
282,
14665,
402,
3432,
3715,
701,
10029,
8,
83,
9,
298,
2490,
7340,
989,
3853,
795,
370,
9842,
2368,
465,
2569,
10532,
680,
298,
2490,
1867,
84,
2,
2490,
298,
9527,
8648,
298,
2490,
1867,
685,
887,
31655,
63,
541,
971,
84,
8441,
1553,
2613,
13,
6693,
298,
435,
747,
14,
515,
14,
904,
8,
44,
7847,
63,
2846,
63,
3243,
12,
298,
18847,
31655,
63,
541,
14,
20309,
531,
435,
1867,
341,
2490,
298,
9527,
8648,
298,
2490,
1867,
15336,
63,
541,
971,
84,
8441,
1553,
2613,
13,
6693,
298,
435,
747,
14,
515,
14,
904,
8,
44,
7847,
63,
2846,
63,
3243,
12,
298,
1848,
63,
541,
14,
20309,
531,
435,
1867,
341,
2490,
298,
9527,
8648,
298,
14924,
260,
2490,
1867,
685,
887,
31655,
63,
2037,
971,
84,
8441,
1553,
2613,
13,
6693,
298,
435,
747,
14,
515,
14,
904,
8,
44,
7847,
63,
2846,
63,
3243,
12,
298,
18847,
31655,
63,
2037,
14,
20309,
531,
435,
1867,
341,
2490,
298,
9527,
8648,
298,
2490,
1867,
685,
887,
31655,
63,
7865,
971,
84,
8441,
1553,
2613,
13,
6693,
298,
435,
747,
14,
515,
14,
904,
8,
44,
7847,
63,
2846,
63,
3243,
12,
298,
18847,
31655,
63,
7865,
14,
20309,
531,
435,
1867,
341,
2490,
298,
9527,
8648,
298,
2490,
1867,
4304,
7265,
63,
2037,
971,
84,
8441,
1553,
2613,
13,
6693,
298,
435,
747,
14,
515,
14,
904,
8,
44,
7847,
63,
2846,
63,
3243,
12,
298,
290,
7265,
63,
2037,
14,
20309,
531,
435,
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
] |
TridevGuha/django
|
tests/model_package/tests.py
|
380
|
2668
|
from __future__ import unicode_literals
from django.db import connection, models
from django.db.backends.utils import truncate_name
from django.test import TestCase
from .models.article import Article, Site
from .models.publication import Publication
class Advertisement(models.Model):
customer = models.CharField(max_length=100)
publications = models.ManyToManyField("model_package.Publication", blank=True)
class ModelPackageTests(TestCase):
def test_m2m_tables_in_subpackage_models(self):
"""
Regression for #12168: models split into subpackages still get M2M
tables.
"""
p = Publication.objects.create(title="FooBar")
site = Site.objects.create(name="example.com")
a = Article.objects.create(headline="a foo headline")
a.publications.add(p)
a.sites.add(site)
a = Article.objects.get(id=a.pk)
self.assertEqual(a.id, a.pk)
self.assertEqual(a.sites.count(), 1)
def test_models_in_the_test_package(self):
"""
Regression for #12245 - Models can exist in the test package, too.
"""
p = Publication.objects.create(title="FooBar")
ad = Advertisement.objects.create(customer="Lawrence Journal-World")
ad.publications.add(p)
ad = Advertisement.objects.get(id=ad.pk)
self.assertEqual(ad.publications.count(), 1)
def test_automatic_m2m_column_names(self):
"""
Regression for #12386 - field names on the autogenerated intermediate
class that are specified as dotted strings don't retain any path
component for the field or column name.
"""
self.assertEqual(
Article.publications.through._meta.fields[1].name, 'article'
)
self.assertEqual(
Article.publications.through._meta.fields[1].get_attname_column(),
('article_id', 'article_id')
)
self.assertEqual(
Article.publications.through._meta.fields[2].name, 'publication'
)
self.assertEqual(
Article.publications.through._meta.fields[2].get_attname_column(),
('publication_id', 'publication_id')
)
self.assertEqual(
Article._meta.get_field('publications').m2m_db_table(),
truncate_name('model_package_article_publications', connection.ops.max_name_length()),
)
self.assertEqual(
Article._meta.get_field('publications').m2m_column_name(), 'article_id'
)
self.assertEqual(
Article._meta.get_field('publications').m2m_reverse_name(),
'publication_id'
)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1950,
12,
1709,
199,
504,
1639,
14,
697,
14,
7765,
14,
1208,
492,
14547,
63,
354,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1275,
992,
14,
6934,
492,
8281,
12,
11666,
199,
504,
1275,
992,
14,
22678,
492,
1684,
425,
421,
199,
533,
4431,
12101,
261,
434,
8,
992,
14,
1685,
304,
272,
15229,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
4575,
1298,
275,
1709,
14,
7624,
480,
1238,
63,
2491,
14,
27283,
401,
4596,
29,
549,
9,
421,
199,
533,
5822,
8599,
2925,
8,
1746,
304,
339,
347,
511,
63,
77,
18,
77,
63,
5987,
63,
262,
63,
954,
2491,
63,
992,
8,
277,
304,
267,
408,
267,
13262,
367,
327,
713,
6568,
26,
1709,
3715,
1901,
1007,
5154,
5139,
664,
603,
18,
45,
267,
6716,
14,
267,
408,
267,
299,
275,
1684,
425,
14,
1462,
14,
981,
8,
1213,
628,
5686,
5281,
531,
398,
4770,
275,
11666,
14,
1462,
14,
981,
8,
354,
628,
2694,
14,
957,
531,
398,
282,
275,
8281,
14,
1462,
14,
981,
8,
11268,
628,
65,
3925,
21250,
531,
267,
282,
14,
27190,
14,
525,
8,
80,
9,
267,
282,
14,
8619,
14,
525,
8,
2124,
9,
398,
282,
275,
8281,
14,
1462,
14,
362,
8,
344,
29,
65,
14,
2051,
9,
267,
291,
14,
629,
8,
65,
14,
344,
12,
282,
14,
2051,
9,
267,
291,
14,
629,
8,
65,
14,
8619,
14,
835,
1062,
413,
9,
339,
347,
511,
63,
992,
63,
262,
63,
1589,
63,
396,
63,
2491,
8,
277,
304,
267,
408,
267,
13262,
367,
327,
713,
11677,
446,
29941,
883,
2187,
315,
314,
511,
2559,
12,
4634,
14,
267,
408,
267,
299,
275,
1684,
425,
14,
1462,
14,
981,
8,
1213,
628,
5686,
5281,
531,
267,
1503,
275,
4431,
12101,
261,
434,
14,
1462,
14,
981,
8,
10178,
628,
7833,
29590,
22142,
13,
15943,
531,
267,
1503,
14,
27190,
14,
525,
8,
80,
9,
398,
1503,
275,
4431,
12101,
261,
434,
14,
1462,
14,
362,
8,
344,
29,
350,
14,
2051,
9,
267,
291,
14,
629,
8,
350,
14,
27190,
14,
835,
1062,
413,
9,
339,
347,
511,
63,
23292,
63,
77,
18,
77,
63,
2301,
63,
1247,
8,
277,
304,
267,
408,
267,
13262,
367,
327,
4288,
1184,
446,
901,
1561,
641,
314,
18392,
13197,
267,
1021,
626,
787,
2013,
465,
18947,
3326,
2793,
1133,
8074,
1263,
931,
267,
3931,
367,
314,
901,
503,
2763,
536,
14,
267,
408,
267,
291,
14,
629,
8,
288,
8281,
14,
27190,
14,
8304,
423,
2024,
14,
955,
59,
17,
1055,
354,
12,
283,
6934,
7,
267,
776,
267,
291,
14,
629,
8,
288,
8281,
14,
27190,
14,
8304,
423,
2024,
14,
955,
59,
17,
1055,
362,
63,
13651,
63,
2301,
1062,
288,
661,
6934,
63,
344,
297,
283,
6934,
63,
344,
358,
267,
776,
267,
291,
14,
629,
8,
288,
8281,
14,
27190,
14,
8304,
423,
2024,
14,
955,
59,
18,
1055,
354,
12,
283,
22678,
7,
267,
776,
267,
291,
14,
629,
8,
288,
8281,
14,
27190,
14,
8304,
423,
2024,
14,
955,
59,
18,
1055,
362,
63,
13651,
63,
2301,
1062,
288,
661,
22678,
63,
344,
297,
283,
22678,
63,
344,
358,
267,
776,
398,
291,
14,
629,
8,
288,
8281,
423,
2024,
14,
362,
63,
698,
360,
27190,
1959,
77,
18,
77,
63,
697,
63,
1224,
1062,
288,
14547,
63,
354,
360,
1238,
63,
2491,
63,
6934,
63,
27190,
297,
1950,
14,
1483,
14,
988,
63,
354,
63,
1267,
4000,
267,
776,
398,
291,
14,
629,
8,
288,
8281,
423,
2024,
14,
362,
63,
698,
360,
27190,
1959,
77,
18,
77,
63,
2301,
63,
354,
1062,
283,
6934,
63,
344,
7,
267,
776,
267,
291,
14,
629,
8,
288,
8281,
423,
2024,
14,
362,
63,
698,
360,
27190,
1959,
77,
18,
77,
63,
4471,
63,
354,
1062,
288,
283,
22678,
63,
344,
7,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1950,
12,
1709,
199,
504,
1639,
14,
697,
14,
7765,
14,
1208,
492,
14547,
63,
354,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1275,
992,
14,
6934,
492,
8281,
12,
11666,
199,
504,
1275,
992,
14,
22678,
492,
1684,
425,
421,
199,
533,
4431,
12101,
261,
434,
8,
992,
14,
1685,
304,
272,
15229,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
4575,
1298,
275,
1709,
14,
7624,
480,
1238,
63,
2491,
14,
27283,
401,
4596,
29,
549,
9,
421,
199,
533,
5822,
8599,
2925,
8,
1746,
304,
339,
347,
511,
63,
77,
18,
77,
63,
5987,
63,
262,
63,
954,
2491,
63,
992,
8,
277,
304,
267,
408,
267,
13262,
367,
327,
713,
6568,
26,
1709,
3715,
1901,
1007,
5154,
5139,
664,
603,
18,
45,
267,
6716,
14,
267,
408,
267,
299,
275,
1684,
425,
14,
1462,
14,
981,
8,
1213,
628,
5686,
5281,
531,
398,
4770,
275,
11666,
14,
1462,
14,
981,
8,
354,
628,
2694,
14,
957,
531,
398,
282,
275,
8281,
14,
1462,
14,
981,
8,
11268,
628,
65,
3925,
21250,
531,
267,
282,
14,
27190,
14,
525,
8,
80,
9,
267,
282,
14,
8619,
14,
525,
8,
2124,
9,
398,
282,
275,
8281,
14,
1462,
14,
362,
8,
344,
29,
65,
14,
2051,
9,
267,
291,
14,
629,
8,
65,
14,
344,
12,
282,
14,
2051,
9,
267,
291,
14,
629,
8,
65,
14,
8619,
14,
835,
1062,
413,
9,
339,
347,
511,
63,
992,
63,
262,
63,
1589,
63,
396,
63,
2491,
8,
277,
304,
267,
408,
267,
13262,
367,
327,
713,
11677,
446,
29941,
883,
2187,
315,
314,
511,
2559,
12,
4634,
14,
267,
408,
267,
299,
275,
1684,
425,
14,
1462,
14,
981,
8,
1213,
628,
5686,
5281,
531,
267,
1503,
275,
4431,
12101,
261,
434,
14,
1462,
14,
981,
8,
10178,
628,
7833,
29590,
22142,
13,
15943,
531,
267,
1503,
14,
27190,
14,
525,
8,
80,
9,
398,
1503,
275,
4431,
12101,
261,
434,
14,
1462,
14,
362,
8,
344,
29,
350,
14,
2051,
9,
267,
291,
14,
629,
8,
350,
14,
27190,
14,
835,
1062,
413,
9,
339,
347,
511,
63,
23292,
63,
77,
18,
77,
63,
2301,
63,
1247,
8,
277,
304,
267,
408,
267,
13262,
367,
327,
4288,
1184,
446,
901,
1561,
641,
314,
18392,
13197,
267,
1021,
626,
787,
2013,
465,
18947,
3326,
2793,
1133,
8074,
1263,
931,
267,
3931,
367,
314,
901,
503,
2763,
536,
14,
267,
408,
267,
291,
14,
629,
8,
288,
8281,
14,
27190,
14,
8304,
423,
2024,
14,
955,
59,
17,
1055,
354,
12,
283,
6934,
7,
267,
776,
267,
291,
14,
629,
8,
288,
8281,
14,
27190,
14,
8304,
423,
2024,
14,
955,
59,
17,
1055,
362,
63,
13651,
63,
2301,
1062,
288,
661,
6934,
63,
344,
297,
283,
6934,
63,
344,
358,
267,
776,
267,
291,
14,
629,
8,
288,
8281,
14,
27190,
14,
8304,
423,
2024,
14,
955,
59,
18,
1055,
354,
12,
283,
22678,
7,
267,
776,
267,
291,
14,
629,
8,
288,
8281,
14,
27190,
14,
8304,
423,
2024,
14,
955,
59,
18,
1055,
362,
63,
13651,
63,
2301,
1062,
288,
661,
22678,
63,
344,
297,
283,
22678,
63,
344,
358,
267,
776,
398,
291,
14,
629,
8,
288,
8281,
423,
2024,
14,
362,
63,
698,
360,
27190,
1959,
77,
18,
77,
63,
697,
63,
1224,
1062,
288,
14547,
63,
354,
360,
1238,
63,
2491,
63,
6934,
63,
27190,
297,
1950,
14,
1483,
14,
988,
63,
354,
63,
1267,
4000,
267,
776,
398,
291,
14,
629,
8,
288,
8281,
423,
2024,
14,
362,
63,
698,
360,
27190,
1959,
77,
18,
77,
63,
2301,
63,
354,
1062,
283,
6934,
63,
344,
7,
267,
776,
267,
291,
14,
629,
8,
288,
8281,
423,
2024,
14,
362,
63,
698,
360,
27190,
1959,
77,
18,
77,
63,
4471,
63,
354,
1062,
288,
283,
22678,
63,
344,
7,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
SamYaple/neutron
|
neutron/tests/unit/quota/test_resource_registry.py
|
15
|
7717
|
# Copyright (c) 2015 OpenStack Foundation. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from oslo_config import cfg
from neutron import context
from neutron.quota import resource
from neutron.quota import resource_registry
from neutron.tests import base
from neutron.tests.unit import quota as test_quota
class TestResourceRegistry(base.DietTestCase):
def setUp(self):
super(TestResourceRegistry, self).setUp()
self.registry = resource_registry.ResourceRegistry.get_instance()
# clean up the registry at every test
self.registry.unregister_resources()
def test_set_tracked_resource_new_resource(self):
self.registry.set_tracked_resource('meh', test_quota.MehModel)
self.assertEqual(test_quota.MehModel,
self.registry._tracked_resource_mappings['meh'])
def test_set_tracked_resource_existing_with_override(self):
self.test_set_tracked_resource_new_resource()
self.registry.set_tracked_resource('meh', test_quota.OtherMehModel,
override=True)
# Override is set to True, the model class should change
self.assertEqual(test_quota.OtherMehModel,
self.registry._tracked_resource_mappings['meh'])
def test_set_tracked_resource_existing_no_override(self):
self.test_set_tracked_resource_new_resource()
self.registry.set_tracked_resource('meh', test_quota.OtherMehModel)
# Override is set to false, the model class should not change
self.assertEqual(test_quota.MehModel,
self.registry._tracked_resource_mappings['meh'])
def _test_register_resource_by_name(self, resource_name, expected_type):
self.assertNotIn(resource_name, self.registry._resources)
self.registry.register_resource_by_name(resource_name)
self.assertIn(resource_name, self.registry._resources)
self.assertIsInstance(self.registry.get_resource(resource_name),
expected_type)
def test_register_resource_by_name_tracked(self):
self.test_set_tracked_resource_new_resource()
self._test_register_resource_by_name('meh', resource.TrackedResource)
def test_register_resource_by_name_not_tracked(self):
self._test_register_resource_by_name('meh', resource.CountableResource)
def test_register_resource_by_name_with_tracking_disabled_by_config(self):
cfg.CONF.set_override('track_quota_usage', False,
group='QUOTAS')
# DietTestCase does not automatically cleans configuration overrides
self.addCleanup(cfg.CONF.reset)
self.registry.set_tracked_resource('meh', test_quota.MehModel)
self.assertNotIn(
'meh', self.registry._tracked_resource_mappings)
self._test_register_resource_by_name('meh', resource.CountableResource)
class TestAuxiliaryFunctions(base.DietTestCase):
def setUp(self):
super(TestAuxiliaryFunctions, self).setUp()
self.registry = resource_registry.ResourceRegistry.get_instance()
# clean up the registry at every test
self.registry.unregister_resources()
def test_resync_tracking_disabled(self):
cfg.CONF.set_override('track_quota_usage', False,
group='QUOTAS')
# DietTestCase does not automatically cleans configuration overrides
self.addCleanup(cfg.CONF.reset)
with mock.patch('neutron.quota.resource.'
'TrackedResource.resync') as mock_resync:
self.registry.set_tracked_resource('meh', test_quota.MehModel)
self.registry.register_resource_by_name('meh')
resource_registry.resync_resource(mock.ANY, 'meh', 'tenant_id')
self.assertEqual(0, mock_resync.call_count)
def test_resync_tracked_resource(self):
with mock.patch('neutron.quota.resource.'
'TrackedResource.resync') as mock_resync:
self.registry.set_tracked_resource('meh', test_quota.MehModel)
self.registry.register_resource_by_name('meh')
resource_registry.resync_resource(mock.ANY, 'meh', 'tenant_id')
mock_resync.assert_called_once_with(mock.ANY, 'tenant_id')
def test_resync_non_tracked_resource(self):
with mock.patch('neutron.quota.resource.'
'TrackedResource.resync') as mock_resync:
self.registry.register_resource_by_name('meh')
resource_registry.resync_resource(mock.ANY, 'meh', 'tenant_id')
self.assertEqual(0, mock_resync.call_count)
def test_set_resources_dirty_invoked_with_tracking_disabled(self):
cfg.CONF.set_override('track_quota_usage', False,
group='QUOTAS')
# DietTestCase does not automatically cleans configuration overrides
self.addCleanup(cfg.CONF.reset)
with mock.patch('neutron.quota.resource.'
'TrackedResource.mark_dirty') as mock_mark_dirty:
self.registry.set_tracked_resource('meh', test_quota.MehModel)
self.registry.register_resource_by_name('meh')
resource_registry.set_resources_dirty(mock.ANY)
self.assertEqual(0, mock_mark_dirty.call_count)
def test_set_resources_dirty_no_dirty_resource(self):
ctx = context.Context('user_id', 'tenant_id',
is_admin=False, is_advsvc=False)
with mock.patch('neutron.quota.resource.'
'TrackedResource.mark_dirty') as mock_mark_dirty:
self.registry.set_tracked_resource('meh', test_quota.MehModel)
self.registry.register_resource_by_name('meh')
res = self.registry.get_resource('meh')
# This ensures dirty is false
res._dirty_tenants.clear()
resource_registry.set_resources_dirty(ctx)
self.assertEqual(0, mock_mark_dirty.call_count)
def test_set_resources_dirty_no_tracked_resource(self):
ctx = context.Context('user_id', 'tenant_id',
is_admin=False, is_advsvc=False)
with mock.patch('neutron.quota.resource.'
'TrackedResource.mark_dirty') as mock_mark_dirty:
self.registry.register_resource_by_name('meh')
resource_registry.set_resources_dirty(ctx)
self.assertEqual(0, mock_mark_dirty.call_count)
def test_set_resources_dirty(self):
ctx = context.Context('user_id', 'tenant_id',
is_admin=False, is_advsvc=False)
with mock.patch('neutron.quota.resource.'
'TrackedResource.mark_dirty') as mock_mark_dirty:
self.registry.set_tracked_resource('meh', test_quota.MehModel)
self.registry.register_resource_by_name('meh')
res = self.registry.get_resource('meh')
# This ensures dirty is true
res._dirty_tenants.add('tenant_id')
resource_registry.set_resources_dirty(ctx)
mock_mark_dirty.assert_called_once_with(ctx)
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6900,
14260,
2752,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1683,
199,
199,
504,
11258,
63,
888,
492,
4810,
199,
199,
504,
8224,
492,
1067,
199,
504,
8224,
14,
8848,
492,
2073,
199,
504,
8224,
14,
8848,
492,
2073,
63,
5189,
199,
504,
8224,
14,
2219,
492,
1300,
199,
504,
8224,
14,
2219,
14,
3248,
492,
12132,
465,
511,
63,
8848,
421,
199,
533,
1379,
4031,
10899,
8,
1095,
14,
1341,
386,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
4031,
10899,
12,
291,
680,
5996,
342,
267,
291,
14,
5189,
275,
2073,
63,
5189,
14,
4031,
10899,
14,
362,
63,
842,
342,
267,
327,
3633,
1536,
314,
7086,
737,
4036,
511,
267,
291,
14,
5189,
14,
18408,
63,
4435,
342,
339,
347,
511,
63,
409,
63,
22586,
63,
1927,
63,
1222,
63,
1927,
8,
277,
304,
267,
291,
14,
5189,
14,
409,
63,
22586,
63,
1927,
360,
278,
72,
297,
511,
63,
8848,
14,
1352,
72,
1685,
9,
267,
291,
14,
629,
8,
396,
63,
8848,
14,
1352,
72,
1685,
12,
586,
291,
14,
5189,
423,
22586,
63,
1927,
63,
14632,
459,
278,
72,
1105,
339,
347,
511,
63,
409,
63,
22586,
63,
1927,
63,
5952,
63,
1045,
63,
4415,
8,
277,
304,
267,
291,
14,
396,
63,
409,
63,
22586,
63,
1927,
63,
1222,
63,
1927,
342,
267,
291,
14,
5189,
14,
409,
63,
22586,
63,
1927,
360,
278,
72,
297,
511,
63,
8848,
14,
8632,
1352,
72,
1685,
12,
5644,
4278,
29,
549,
9,
267,
327,
11041,
365,
663,
370,
715,
12,
314,
1402,
1021,
1077,
1570,
267,
291,
14,
629,
8,
396,
63,
8848,
14,
8632,
1352,
72,
1685,
12,
586,
291,
14,
5189,
423,
22586,
63,
1927,
63,
14632,
459,
278,
72,
1105,
339,
347,
511,
63,
409,
63,
22586,
63,
1927,
63,
5952,
63,
889,
63,
4415,
8,
277,
304,
267,
291,
14,
396,
63,
409,
63,
22586,
63,
1927,
63,
1222,
63,
1927,
342,
267,
291,
14,
5189,
14,
409,
63,
22586,
63,
1927,
360,
278,
72,
297,
511,
63,
8848,
14,
8632,
1352,
72,
1685,
9,
267,
327,
11041,
365,
663,
370,
3055,
12,
314,
1402,
1021,
1077,
440,
1570,
267,
291,
14,
629,
8,
396,
63,
8848,
14,
1352,
72,
1685,
12,
586,
291,
14,
5189,
423,
22586,
63,
1927,
63,
14632,
459,
278,
72,
1105,
339,
347,
485,
396,
63,
2683,
63,
1927,
63,
991,
63,
354,
8,
277,
12,
2073,
63,
354,
12,
1420,
63,
466,
304,
267,
291,
14,
8795,
8,
1927,
63,
354,
12,
291,
14,
5189,
423,
4435,
9,
267,
291,
14,
5189,
14,
2683,
63,
1927,
63,
991,
63,
354,
8,
1927,
63,
354,
9,
267,
291,
14,
4080,
8,
1927,
63,
354,
12,
291,
14,
5189,
423,
4435,
9,
267,
291,
14,
6926,
8,
277,
14,
5189,
14,
362,
63,
1927,
8,
1927,
63,
354,
395,
2892,
1420,
63,
466,
9,
339,
347,
511,
63,
2683,
63,
1927,
63,
991,
63,
354,
63,
22586,
8,
277,
304,
267,
291,
14,
396,
63,
409,
63,
22586,
63,
1927,
63,
1222,
63,
1927,
342,
267,
291,
423,
396,
63,
2683,
63,
1927,
63,
991,
63,
354,
360,
278,
72,
297,
2073,
14,
7927,
379,
4031,
9,
339,
347,
511,
63,
2683,
63,
1927,
63,
991,
63,
354,
63,
1397,
63,
22586,
8,
277,
304,
267,
291,
423,
396,
63,
2683,
63,
1927,
63,
991,
63,
354,
360,
278,
72,
297,
2073,
14,
2353,
461,
4031,
9,
339,
347,
511,
63,
2683,
63,
1927,
63,
991,
63,
354,
63,
1045,
63,
14428,
63,
7011,
63,
991,
63,
888,
8,
277,
304,
267,
4810,
14,
3103,
14,
409,
63,
4415,
360,
3885,
63,
8848,
63,
3807,
297,
756,
12,
2892,
1572,
534,
18654,
1179,
358,
267,
327,
3757,
386,
1746,
1630,
440,
5847,
15158,
796,
2897,
10580,
267,
291,
14,
12808,
8,
4128,
14,
3103,
14,
3958,
9,
267,
291,
14,
5189,
14,
409,
63,
22586,
63,
1927,
360,
278,
72,
297,
511,
63,
8848,
14,
1352,
72,
1685,
9,
267,
291,
14,
8795,
8,
288,
283,
278,
72,
297,
291,
14,
5189,
423,
22586,
63,
1927,
63,
14632,
9,
267,
291,
423,
396,
63,
2683,
63,
1927,
63,
991,
63,
354,
360,
278,
72,
297,
2073,
14,
2353,
461,
4031,
9,
421,
199,
533,
1379,
30731,
20524,
13967,
8,
1095,
14,
1341,
386,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
30731,
20524,
13967,
12,
291,
680,
5996,
342,
267,
291,
14,
5189,
275,
2073,
63,
5189,
14,
4031,
10899,
14,
362,
63,
842,
342,
267,
327,
3633,
1536,
314,
7086,
737,
4036,
511,
267,
291,
14,
5189,
14,
18408,
63,
4435,
342,
339,
347,
511,
63,
470,
1870,
63,
14428,
63,
7011,
8,
277,
304,
267,
4810,
14,
3103,
14,
409,
63,
4415,
360,
3885,
63,
8848,
63,
3807,
297,
756,
12,
2892,
1572,
534,
18654,
1179,
358,
267,
327,
3757,
386,
1746,
1630,
440,
5847,
15158,
796,
2897,
10580,
267,
291,
14,
12808,
8,
4128,
14,
3103,
14,
3958,
9,
267,
543,
1683,
14,
2068,
360,
10271,
14,
8848,
14,
1927,
3530,
717,
283,
7927,
379,
4031,
14,
470,
1870,
358,
465,
1683,
63,
470,
1870,
26,
288,
291,
14,
5189,
14,
409,
63,
22586,
63,
1927,
360,
278,
72,
297,
511,
63,
8848,
14
] |
[
1898,
334,
67,
9,
6900,
14260,
2752,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1683,
199,
199,
504,
11258,
63,
888,
492,
4810,
199,
199,
504,
8224,
492,
1067,
199,
504,
8224,
14,
8848,
492,
2073,
199,
504,
8224,
14,
8848,
492,
2073,
63,
5189,
199,
504,
8224,
14,
2219,
492,
1300,
199,
504,
8224,
14,
2219,
14,
3248,
492,
12132,
465,
511,
63,
8848,
421,
199,
533,
1379,
4031,
10899,
8,
1095,
14,
1341,
386,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
4031,
10899,
12,
291,
680,
5996,
342,
267,
291,
14,
5189,
275,
2073,
63,
5189,
14,
4031,
10899,
14,
362,
63,
842,
342,
267,
327,
3633,
1536,
314,
7086,
737,
4036,
511,
267,
291,
14,
5189,
14,
18408,
63,
4435,
342,
339,
347,
511,
63,
409,
63,
22586,
63,
1927,
63,
1222,
63,
1927,
8,
277,
304,
267,
291,
14,
5189,
14,
409,
63,
22586,
63,
1927,
360,
278,
72,
297,
511,
63,
8848,
14,
1352,
72,
1685,
9,
267,
291,
14,
629,
8,
396,
63,
8848,
14,
1352,
72,
1685,
12,
586,
291,
14,
5189,
423,
22586,
63,
1927,
63,
14632,
459,
278,
72,
1105,
339,
347,
511,
63,
409,
63,
22586,
63,
1927,
63,
5952,
63,
1045,
63,
4415,
8,
277,
304,
267,
291,
14,
396,
63,
409,
63,
22586,
63,
1927,
63,
1222,
63,
1927,
342,
267,
291,
14,
5189,
14,
409,
63,
22586,
63,
1927,
360,
278,
72,
297,
511,
63,
8848,
14,
8632,
1352,
72,
1685,
12,
5644,
4278,
29,
549,
9,
267,
327,
11041,
365,
663,
370,
715,
12,
314,
1402,
1021,
1077,
1570,
267,
291,
14,
629,
8,
396,
63,
8848,
14,
8632,
1352,
72,
1685,
12,
586,
291,
14,
5189,
423,
22586,
63,
1927,
63,
14632,
459,
278,
72,
1105,
339,
347,
511,
63,
409,
63,
22586,
63,
1927,
63,
5952,
63,
889,
63,
4415,
8,
277,
304,
267,
291,
14,
396,
63,
409,
63,
22586,
63,
1927,
63,
1222,
63,
1927,
342,
267,
291,
14,
5189,
14,
409,
63,
22586,
63,
1927,
360,
278,
72,
297,
511,
63,
8848,
14,
8632,
1352,
72,
1685,
9,
267,
327,
11041,
365,
663,
370,
3055,
12,
314,
1402,
1021,
1077,
440,
1570,
267,
291,
14,
629,
8,
396,
63,
8848,
14,
1352,
72,
1685,
12,
586,
291,
14,
5189,
423,
22586,
63,
1927,
63,
14632,
459,
278,
72,
1105,
339,
347,
485,
396,
63,
2683,
63,
1927,
63,
991,
63,
354,
8,
277,
12,
2073,
63,
354,
12,
1420,
63,
466,
304,
267,
291,
14,
8795,
8,
1927,
63,
354,
12,
291,
14,
5189,
423,
4435,
9,
267,
291,
14,
5189,
14,
2683,
63,
1927,
63,
991,
63,
354,
8,
1927,
63,
354,
9,
267,
291,
14,
4080,
8,
1927,
63,
354,
12,
291,
14,
5189,
423,
4435,
9,
267,
291,
14,
6926,
8,
277,
14,
5189,
14,
362,
63,
1927,
8,
1927,
63,
354,
395,
2892,
1420,
63,
466,
9,
339,
347,
511,
63,
2683,
63,
1927,
63,
991,
63,
354,
63,
22586,
8,
277,
304,
267,
291,
14,
396,
63,
409,
63,
22586,
63,
1927,
63,
1222,
63,
1927,
342,
267,
291,
423,
396,
63,
2683,
63,
1927,
63,
991,
63,
354,
360,
278,
72,
297,
2073,
14,
7927,
379,
4031,
9,
339,
347,
511,
63,
2683,
63,
1927,
63,
991,
63,
354,
63,
1397,
63,
22586,
8,
277,
304,
267,
291,
423,
396,
63,
2683,
63,
1927,
63,
991,
63,
354,
360,
278,
72,
297,
2073,
14,
2353,
461,
4031,
9,
339,
347,
511,
63,
2683,
63,
1927,
63,
991,
63,
354,
63,
1045,
63,
14428,
63,
7011,
63,
991,
63,
888,
8,
277,
304,
267,
4810,
14,
3103,
14,
409,
63,
4415,
360,
3885,
63,
8848,
63,
3807,
297,
756,
12,
2892,
1572,
534,
18654,
1179,
358,
267,
327,
3757,
386,
1746,
1630,
440,
5847,
15158,
796,
2897,
10580,
267,
291,
14,
12808,
8,
4128,
14,
3103,
14,
3958,
9,
267,
291,
14,
5189,
14,
409,
63,
22586,
63,
1927,
360,
278,
72,
297,
511,
63,
8848,
14,
1352,
72,
1685,
9,
267,
291,
14,
8795,
8,
288,
283,
278,
72,
297,
291,
14,
5189,
423,
22586,
63,
1927,
63,
14632,
9,
267,
291,
423,
396,
63,
2683,
63,
1927,
63,
991,
63,
354,
360,
278,
72,
297,
2073,
14,
2353,
461,
4031,
9,
421,
199,
533,
1379,
30731,
20524,
13967,
8,
1095,
14,
1341,
386,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
30731,
20524,
13967,
12,
291,
680,
5996,
342,
267,
291,
14,
5189,
275,
2073,
63,
5189,
14,
4031,
10899,
14,
362,
63,
842,
342,
267,
327,
3633,
1536,
314,
7086,
737,
4036,
511,
267,
291,
14,
5189,
14,
18408,
63,
4435,
342,
339,
347,
511,
63,
470,
1870,
63,
14428,
63,
7011,
8,
277,
304,
267,
4810,
14,
3103,
14,
409,
63,
4415,
360,
3885,
63,
8848,
63,
3807,
297,
756,
12,
2892,
1572,
534,
18654,
1179,
358,
267,
327,
3757,
386,
1746,
1630,
440,
5847,
15158,
796,
2897,
10580,
267,
291,
14,
12808,
8,
4128,
14,
3103,
14,
3958,
9,
267,
543,
1683,
14,
2068,
360,
10271,
14,
8848,
14,
1927,
3530,
717,
283,
7927,
379,
4031,
14,
470,
1870,
358,
465,
1683,
63,
470,
1870,
26,
288,
291,
14,
5189,
14,
409,
63,
22586,
63,
1927,
360,
278,
72,
297,
511,
63,
8848,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
Starkiller4011/astroSF
|
m2_convert.py
|
1
|
1131
|
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
#####################################
# ╔╗ ┬ ┬ ┬┌─┐ ╔╦╗┌─┐┌┬┐ #
# ╠╩╗│ │ │├┤ ║║│ │ │ #
# ╚═╝┴─┘└─┘└─┘ ═╩╝└─┘ ┴ #
# ╔═╗┌─┐┌─┐┌┬┐┬ ┬┌─┐┬─┐┌─┐ #
# ╚═╗│ │├┤ │ │││├─┤├┬┘├┤ #
# ╚═╝└─┘└ ┴ └┴┘┴ ┴┴└─└─┘ #
#####################################
Author: Derek Blue
"""
# Imports
from __future__ import division
import pandas as pd
from dfgui import show as pdui
import sf_methods as sfm
from tqdm import tqdm as pbar
VEGA_MAG = 16.85
ctf = float('8.489e-16')
M335LC = sfm.load_data('./RAW/mkn335_xrt_uvot_lc.dat', headers=True)
x_col = M335LC['MJD'].tolist()
y_col = M335LC['M2_MAG'].tolist()
e_col = M335LC['M2_MG_ERR'].tolist()
M2_DATA = pd.DataFrame({'Time':x_col,
'Flux':y_col,
'Error':e_col})
M2_DATA = M2_DATA[M2_DATA['Flux'] > 0]
pdui(M2_DATA)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
18,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
1371,
8776,
199,
3,
258,
221,
19298,
243,
19298,
246,
221,
15038,
106,
221,
221,
15038,
106,
221,
15038,
106,
15038,
235,
19961,
15038,
239,
221,
221,
19298,
243,
19298,
100,
19298,
246,
15038,
235,
19961,
15038,
239,
15038,
235,
15038,
106,
15038,
239,
755,
327,
199,
3,
258,
221,
19298,
255,
19298,
103,
19298,
246,
15038,
225,
221,
221,
15038,
225,
221,
15038,
225,
15038,
251,
15038,
98,
259,
221,
19298,
240,
19298,
240,
15038,
225,
221,
15038,
225,
221,
15038,
225,
263,
327,
199,
3,
258,
221,
19298,
249,
23345,
19298,
252,
15038,
113,
19961,
15038,
247,
15038,
243,
19961,
15038,
247,
15038,
243,
19961,
15038,
247,
221,
221,
23345,
19298,
103,
19298,
252,
15038,
243,
19961,
15038,
247,
221,
15038,
113,
263,
327,
199,
3,
258,
221,
19298,
243,
23345,
19298,
246,
15038,
235,
19961,
15038,
239,
15038,
235,
19961,
15038,
239,
15038,
235,
15038,
106,
15038,
239,
15038,
106,
221,
15038,
106,
15038,
235,
19961,
15038,
239,
15038,
106,
19961,
15038,
239,
15038,
235,
19961,
15038,
239,
420,
327,
199,
3,
258,
221,
19298,
249,
23345,
19298,
246,
15038,
225,
221,
15038,
225,
15038,
251,
15038,
98,
221,
221,
15038,
225,
221,
15038,
225,
15038,
225,
15038,
225,
15038,
251,
19961,
15038,
98,
15038,
251,
15038,
106,
15038,
247,
15038,
251,
15038,
98,
755,
327,
199,
3,
258,
221,
19298,
249,
23345,
19298,
252,
15038,
243,
19961,
15038,
247,
15038,
243,
257,
221,
15038,
113,
221,
15038,
243,
15038,
113,
15038,
247,
15038,
113,
221,
15038,
113,
15038,
113,
15038,
243,
19961,
15038,
243,
19961,
15038,
247,
420,
327,
199,
1371,
8776,
199,
5949,
26,
1487,
264,
75,
22447,
199,
624,
199,
199,
3,
24339,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
10634,
465,
6454,
199,
504,
4051,
5885,
492,
2498,
465,
6454,
1907,
199,
646,
13330,
63,
2474,
465,
308,
10886,
199,
504,
307,
81,
6428,
492,
307,
81,
6428,
465,
299,
1700,
199,
199,
2524,
9741,
63,
45,
1254,
275,
3193,
14,
2426,
199,
319,
70,
275,
2069,
360,
24,
14,
29743,
69,
13,
975,
358,
199,
45,
13793,
7027,
275,
308,
10886,
14,
912,
63,
576,
17371,
4307,
15,
3880,
78,
13793,
63,
88,
2591,
63,
9154,
357,
63,
10181,
14,
4616,
297,
2323,
29,
549,
9,
199,
88,
63,
761,
275,
603,
13793,
7027,
459,
30495,
36,
2278,
13633,
342,
199,
89,
63,
761,
275,
603,
13793,
7027,
459,
45,
18,
63,
45,
1254,
2278,
13633,
342,
199,
69,
63,
761,
275,
603,
13793,
7027,
459,
45,
18,
63,
26255,
63,
2666,
2278,
13633,
342,
199,
45,
18,
63,
3998,
275,
6454,
14,
9205,
3252,
1366,
356,
88,
63,
761,
12,
717,
283,
29996,
356,
89,
63,
761,
12,
717,
283,
547,
356,
69,
63,
761,
1552,
199,
45,
18,
63,
3998,
275,
603,
18,
63,
3998,
59,
45,
18,
63,
3998,
459,
29996,
418,
690,
378,
61,
199,
8961,
1907,
8,
45,
18,
63,
3998,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
18,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
1371,
8776,
199,
3,
258,
221,
19298,
243,
19298,
246,
221,
15038,
106,
221,
221,
15038,
106,
221,
15038,
106,
15038,
235,
19961,
15038,
239,
221,
221,
19298,
243,
19298,
100,
19298,
246,
15038,
235,
19961,
15038,
239,
15038,
235,
15038,
106,
15038,
239,
755,
327,
199,
3,
258,
221,
19298,
255,
19298,
103,
19298,
246,
15038,
225,
221,
221,
15038,
225,
221,
15038,
225,
15038,
251,
15038,
98,
259,
221,
19298,
240,
19298,
240,
15038,
225,
221,
15038,
225,
221,
15038,
225,
263,
327,
199,
3,
258,
221,
19298,
249,
23345,
19298,
252,
15038,
113,
19961,
15038,
247,
15038,
243,
19961,
15038,
247,
15038,
243,
19961,
15038,
247,
221,
221,
23345,
19298,
103,
19298,
252,
15038,
243,
19961,
15038,
247,
221,
15038,
113,
263,
327,
199,
3,
258,
221,
19298,
243,
23345,
19298,
246,
15038,
235,
19961,
15038,
239,
15038,
235,
19961,
15038,
239,
15038,
235,
15038,
106,
15038,
239,
15038,
106,
221,
15038,
106,
15038,
235,
19961,
15038,
239,
15038,
106,
19961,
15038,
239,
15038,
235,
19961,
15038,
239,
420,
327,
199,
3,
258,
221,
19298,
249,
23345,
19298,
246,
15038,
225,
221,
15038,
225,
15038,
251,
15038,
98,
221,
221,
15038,
225,
221,
15038,
225,
15038,
225,
15038,
225,
15038,
251,
19961,
15038,
98,
15038,
251,
15038,
106,
15038,
247,
15038,
251,
15038,
98,
755,
327,
199,
3,
258,
221,
19298,
249,
23345,
19298,
252,
15038,
243,
19961,
15038,
247,
15038,
243,
257,
221,
15038,
113,
221,
15038,
243,
15038,
113,
15038,
247,
15038,
113,
221,
15038,
113,
15038,
113,
15038,
243,
19961,
15038,
243,
19961,
15038,
247,
420,
327,
199,
1371,
8776,
199,
5949,
26,
1487,
264,
75,
22447,
199,
624,
199,
199,
3,
24339,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
10634,
465,
6454,
199,
504,
4051,
5885,
492,
2498,
465,
6454,
1907,
199,
646,
13330,
63,
2474,
465,
308,
10886,
199,
504,
307,
81,
6428,
492,
307,
81,
6428,
465,
299,
1700,
199,
199,
2524,
9741,
63,
45,
1254,
275,
3193,
14,
2426,
199,
319,
70,
275,
2069,
360,
24,
14,
29743,
69,
13,
975,
358,
199,
45,
13793,
7027,
275,
308,
10886,
14,
912,
63,
576,
17371,
4307,
15,
3880,
78,
13793,
63,
88,
2591,
63,
9154,
357,
63,
10181,
14,
4616,
297,
2323,
29,
549,
9,
199,
88,
63,
761,
275,
603,
13793,
7027,
459,
30495,
36,
2278,
13633,
342,
199,
89,
63,
761,
275,
603,
13793,
7027,
459,
45,
18,
63,
45,
1254,
2278,
13633,
342,
199,
69,
63,
761,
275,
603,
13793,
7027,
459,
45,
18,
63,
26255,
63,
2666,
2278,
13633,
342,
199,
45,
18,
63,
3998,
275,
6454,
14,
9205,
3252,
1366,
356,
88,
63,
761,
12,
717,
283,
29996,
356,
89,
63,
761,
12,
717,
283,
547,
356,
69,
63,
761,
1552,
199,
45,
18,
63,
3998,
275,
603,
18,
63,
3998,
59,
45,
18,
63,
3998,
459,
29996,
418,
690,
378,
61,
199,
8961,
1907,
8,
45,
18,
63,
3998,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jcollado/datagrid-gtk3
|
datagrid_gtk3/tests/utils/test_transformations.py
|
2
|
1682
|
"""Data transformation utilities test cases."""
import unittest
from datagrid_gtk3.utils.transformations import degree_decimal_str_transform
class DegreeDecimalStrTransformTest(unittest.TestCase):
"""Degree decimal string transformation test case."""
def test_no_basestring(self):
"""AssertionError raised when no basestring value is passed."""
self.assertRaises(AssertionError, degree_decimal_str_transform, 0)
self.assertRaises(AssertionError, degree_decimal_str_transform, 1.23)
self.assertRaises(AssertionError, degree_decimal_str_transform, True)
def test_no_digit(self):
"""AssertionError raised when other characters than digits."""
self.assertRaises(AssertionError, degree_decimal_str_transform, '.')
self.assertRaises(AssertionError, degree_decimal_str_transform, '+')
self.assertRaises(AssertionError, degree_decimal_str_transform, '-')
def test_length(self):
"""AssertionError when more characters than expected passed."""
self.assertRaises(
AssertionError, degree_decimal_str_transform, '123456789')
def test_point_insertion(self):
"""Decimal point is inserted in the expected location."""
self.assertEqual(
degree_decimal_str_transform('12345678'),
'12.345678',
)
self.assertEqual(
degree_decimal_str_transform('1234567'),
'1.234567',
)
self.assertEqual(
degree_decimal_str_transform('123456'),
'0.123456',
)
self.assertEqual(
degree_decimal_str_transform('12345'),
'0.012345',
)
|
mit
|
[
624,
1451,
13315,
15841,
511,
5560,
1041,
199,
199,
646,
2882,
199,
199,
504,
666,
3825,
63,
12275,
19,
14,
1208,
14,
1515,
17308,
492,
13666,
63,
6355,
63,
495,
63,
4711,
421,
199,
533,
1487,
71,
850,
6745,
2848,
6939,
774,
8,
2796,
14,
1746,
304,
339,
408,
26135,
850,
6107,
1059,
13315,
511,
1930,
1041,
339,
347,
511,
63,
889,
63,
17628,
8,
277,
304,
267,
408,
14844,
4915,
1380,
949,
7116,
574,
365,
3032,
1041,
267,
291,
14,
1855,
8,
14844,
12,
13666,
63,
6355,
63,
495,
63,
4711,
12,
378,
9,
267,
291,
14,
1855,
8,
14844,
12,
13666,
63,
6355,
63,
495,
63,
4711,
12,
413,
14,
1789,
9,
267,
291,
14,
1855,
8,
14844,
12,
13666,
63,
6355,
63,
495,
63,
4711,
12,
715,
9,
339,
347,
511,
63,
889,
63,
8573,
8,
277,
304,
267,
408,
14844,
4915,
1380,
1163,
4110,
2419,
7576,
1041,
267,
291,
14,
1855,
8,
14844,
12,
13666,
63,
6355,
63,
495,
63,
4711,
12,
20093,
267,
291,
14,
1855,
8,
14844,
12,
13666,
63,
6355,
63,
495,
63,
4711,
12,
6681,
358,
267,
291,
14,
1855,
8,
14844,
12,
13666,
63,
6355,
63,
495,
63,
4711,
12,
26942,
339,
347,
511,
63,
1267,
8,
277,
304,
267,
408,
14844,
1380,
1655,
4110,
2419,
1420,
3032,
1041,
267,
291,
14,
1855,
8,
288,
9070,
12,
13666,
63,
6355,
63,
495,
63,
4711,
12,
283,
11272,
358,
339,
347,
511,
63,
1403,
63,
14739,
8,
277,
304,
267,
408,
6745,
2376,
365,
11788,
315,
314,
1420,
2909,
1041,
267,
291,
14,
629,
8,
288,
13666,
63,
6355,
63,
495,
63,
4711,
360,
19542,
659,
288,
283,
713,
14,
1082,
12970,
297,
267,
776,
267,
291,
14,
629,
8,
288,
13666,
63,
6355,
63,
495,
63,
4711,
360,
30217,
659,
288,
283,
17,
14,
5533,
5308,
297,
267,
776,
267,
291,
14,
629,
8,
288,
13666,
63,
6355,
63,
495,
63,
4711,
360,
19060,
659,
288,
283,
16,
14,
19060,
297,
267,
776,
267,
291,
14,
629,
8,
288,
13666,
63,
6355,
63,
495,
63,
4711,
360,
13261,
659,
288,
283,
16,
14,
9461,
21,
297,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1451,
13315,
15841,
511,
5560,
1041,
199,
199,
646,
2882,
199,
199,
504,
666,
3825,
63,
12275,
19,
14,
1208,
14,
1515,
17308,
492,
13666,
63,
6355,
63,
495,
63,
4711,
421,
199,
533,
1487,
71,
850,
6745,
2848,
6939,
774,
8,
2796,
14,
1746,
304,
339,
408,
26135,
850,
6107,
1059,
13315,
511,
1930,
1041,
339,
347,
511,
63,
889,
63,
17628,
8,
277,
304,
267,
408,
14844,
4915,
1380,
949,
7116,
574,
365,
3032,
1041,
267,
291,
14,
1855,
8,
14844,
12,
13666,
63,
6355,
63,
495,
63,
4711,
12,
378,
9,
267,
291,
14,
1855,
8,
14844,
12,
13666,
63,
6355,
63,
495,
63,
4711,
12,
413,
14,
1789,
9,
267,
291,
14,
1855,
8,
14844,
12,
13666,
63,
6355,
63,
495,
63,
4711,
12,
715,
9,
339,
347,
511,
63,
889,
63,
8573,
8,
277,
304,
267,
408,
14844,
4915,
1380,
1163,
4110,
2419,
7576,
1041,
267,
291,
14,
1855,
8,
14844,
12,
13666,
63,
6355,
63,
495,
63,
4711,
12,
20093,
267,
291,
14,
1855,
8,
14844,
12,
13666,
63,
6355,
63,
495,
63,
4711,
12,
6681,
358,
267,
291,
14,
1855,
8,
14844,
12,
13666,
63,
6355,
63,
495,
63,
4711,
12,
26942,
339,
347,
511,
63,
1267,
8,
277,
304,
267,
408,
14844,
1380,
1655,
4110,
2419,
1420,
3032,
1041,
267,
291,
14,
1855,
8,
288,
9070,
12,
13666,
63,
6355,
63,
495,
63,
4711,
12,
283,
11272,
358,
339,
347,
511,
63,
1403,
63,
14739,
8,
277,
304,
267,
408,
6745,
2376,
365,
11788,
315,
314,
1420,
2909,
1041,
267,
291,
14,
629,
8,
288,
13666,
63,
6355,
63,
495,
63,
4711,
360,
19542,
659,
288,
283,
713,
14,
1082,
12970,
297,
267,
776,
267,
291,
14,
629,
8,
288,
13666,
63,
6355,
63,
495,
63,
4711,
360,
30217,
659,
288,
283,
17,
14,
5533,
5308,
297,
267,
776,
267,
291,
14,
629,
8,
288,
13666,
63,
6355,
63,
495,
63,
4711,
360,
19060,
659,
288,
283,
16,
14,
19060,
297,
267,
776,
267,
291,
14,
629,
8,
288,
13666,
63,
6355,
63,
495,
63,
4711,
360,
13261,
659,
288,
283,
16,
14,
9461,
21,
297,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
laperry1/android_external_chromium_org
|
testing/generate_gmock_mutant.py
|
110
|
14946
|
#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import string
import sys
HEADER = """\
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file automatically generated by testing/generate_gmock_mutant.py.
// DO NOT EDIT.
#ifndef TESTING_GMOCK_MUTANT_H_
#define TESTING_GMOCK_MUTANT_H_
// The intention of this file is to make possible using GMock actions in
// all of its syntactic beauty. Classes and helper functions can be used as
// more generic variants of Task and Callback classes (see base/task.h)
// Mutant supports both pre-bound arguments (like Task) and call-time
// arguments (like Callback) - hence the name. :-)
//
// DispatchToMethod/Function supports two sets of arguments: pre-bound (P) and
// call-time (C). The arguments as well as the return type are templatized.
// DispatchToMethod/Function will also try to call the selected method or
// function even if provided pre-bound arguments does not match exactly with
// the function signature hence the X1, X2 ... XN parameters in CreateFunctor.
// DispatchToMethod will try to invoke method that may not belong to the
// object's class itself but to the object's class base class.
//
// Additionally you can bind the object at calltime by binding a pointer to
// pointer to the object at creation time - before including this file you
// have to #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING.
//
// TODO(stoyan): It's yet not clear to me should we use T& and T&* instead
// of T* and T** when we invoke CreateFunctor to match the EXPECT_CALL style.
//
//
// Sample usage with gMock:
//
// struct Mock : public ObjectDelegate {
// MOCK_METHOD2(string, OnRequest(int n, const string& request));
// MOCK_METHOD1(void, OnQuit(int exit_code));
// MOCK_METHOD2(void, LogMessage(int level, const string& message));
//
// string HandleFlowers(const string& reply, int n, const string& request) {
// string result = SStringPrintf("In request of %d %s ", n, request);
// for (int i = 0; i < n; ++i) result.append(reply)
// return result;
// }
//
// void DoLogMessage(int level, const string& message) {
// }
//
// void QuitMessageLoop(int seconds) {
// MessageLoop* loop = MessageLoop::current();
// loop->PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(),
// 1000 * seconds);
// }
// };
//
// Mock mock;
// // Will invoke mock.HandleFlowers("orchids", n, request)
// // "orchids" is a pre-bound argument, and <n> and <request> are call-time
// // arguments - they are not known until the OnRequest mock is invoked.
// EXPECT_CALL(mock, OnRequest(Ge(5), StartsWith("flower"))
// .Times(1)
// .WillOnce(Invoke(CreateFunctor(&mock, &Mock::HandleFlowers,
// string("orchids"))));
//
//
// // No pre-bound arguments, two call-time arguments passed
// // directly to DoLogMessage
// EXPECT_CALL(mock, OnLogMessage(_, _))
// .Times(AnyNumber())
// .WillAlways(Invoke(CreateFunctor, &mock, &Mock::DoLogMessage));
//
//
// // In this case we have a single pre-bound argument - 3. We ignore
// // all of the arguments of OnQuit.
// EXCEPT_CALL(mock, OnQuit(_))
// .Times(1)
// .WillOnce(InvokeWithoutArgs(CreateFunctor(
// &mock, &Mock::QuitMessageLoop, 3)));
//
// MessageLoop loop;
// loop.Run();
//
//
// // Here is another example of how we can set an action that invokes
// // method of an object that is not yet created.
// struct Mock : public ObjectDelegate {
// MOCK_METHOD1(void, DemiurgeCreated(Demiurge*));
// MOCK_METHOD2(void, OnRequest(int count, const string&));
//
// void StoreDemiurge(Demiurge* w) {
// demiurge_ = w;
// }
//
// Demiurge* demiurge;
// }
//
// EXPECT_CALL(mock, DemiurgeCreated(_)).Times(1)
// .WillOnce(Invoke(CreateFunctor(&mock, &Mock::StoreDemiurge)));
//
// EXPECT_CALL(mock, OnRequest(_, StrEq("Moby Dick")))
// .Times(AnyNumber())
// .WillAlways(WithArgs<0>(Invoke(
// CreateFunctor(&mock->demiurge_, &Demiurge::DecreaseMonsters))));
//
#include "base/memory/linked_ptr.h"
#include "base/tuple.h" // for Tuple
namespace testing {"""
MUTANT = """\
// Interface that is exposed to the consumer, that does the actual calling
// of the method.
template <typename R, typename Params>
class MutantRunner {
public:
virtual R RunWithParams(const Params& params) = 0;
virtual ~MutantRunner() {}
};
// Mutant holds pre-bound arguments (like Task). Like Callback
// allows call-time arguments. You bind a pointer to the object
// at creation time.
template <typename R, typename T, typename Method,
typename PreBound, typename Params>
class Mutant : public MutantRunner<R, Params> {
public:
Mutant(T* obj, Method method, const PreBound& pb)
: obj_(obj), method_(method), pb_(pb) {
}
// MutantRunner implementation
virtual R RunWithParams(const Params& params) {
return DispatchToMethod<R>(this->obj_, this->method_, pb_, params);
}
T* obj_;
Method method_;
PreBound pb_;
};
template <typename R, typename Function, typename PreBound, typename Params>
class MutantFunction : public MutantRunner<R, Params> {
public:
MutantFunction(Function function, const PreBound& pb)
: function_(function), pb_(pb) {
}
// MutantRunner implementation
virtual R RunWithParams(const Params& params) {
return DispatchToFunction<R>(function_, pb_, params);
}
Function function_;
PreBound pb_;
};
#ifdef GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING
// MutantLateBind is like Mutant, but you bind a pointer to a pointer
// to the object. This way you can create actions for an object
// that is not yet created (has only storage for a pointer to it).
template <typename R, typename T, typename Method,
typename PreBound, typename Params>
class MutantLateObjectBind : public MutantRunner<R, Params> {
public:
MutantLateObjectBind(T** obj, Method method, const PreBound& pb)
: obj_(obj), method_(method), pb_(pb) {
}
// MutantRunner implementation.
virtual R RunWithParams(const Params& params) {
EXPECT_THAT(*this->obj_, testing::NotNull());
if (NULL == *this->obj_)
return R();
return DispatchToMethod<R>( *this->obj_, this->method_, pb_, params);
}
T** obj_;
Method method_;
PreBound pb_;
};
#endif
// Simple MutantRunner<> wrapper acting as a functor.
// Redirects operator() to MutantRunner<Params>::Run()
template <typename R, typename Params>
struct MutantFunctor {
explicit MutantFunctor(MutantRunner<R, Params>* cb) : impl_(cb) {
}
~MutantFunctor() {
}
inline R operator()() {
return impl_->RunWithParams(Tuple0());
}
template <typename Arg1>
inline R operator()(const Arg1& a) {
return impl_->RunWithParams(Params(a));
}
template <typename Arg1, typename Arg2>
inline R operator()(const Arg1& a, const Arg2& b) {
return impl_->RunWithParams(Params(a, b));
}
template <typename Arg1, typename Arg2, typename Arg3>
inline R operator()(const Arg1& a, const Arg2& b, const Arg3& c) {
return impl_->RunWithParams(Params(a, b, c));
}
template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
inline R operator()(const Arg1& a, const Arg2& b, const Arg3& c,
const Arg4& d) {
return impl_->RunWithParams(Params(a, b, c, d));
}
private:
// We need copy constructor since MutantFunctor is copied few times
// inside GMock machinery, hence no DISALLOW_EVIL_CONTRUCTORS
MutantFunctor();
linked_ptr<MutantRunner<R, Params> > impl_;
};
"""
FOOTER = """\
} // namespace testing
#endif // TESTING_GMOCK_MUTANT_H_"""
# Templates for DispatchToMethod/DispatchToFunction functions.
# template_params - typename P1, typename P2.. typename C1..
# prebound - TupleN<P1, .. PN>
# calltime - TupleN<C1, .. CN>
# args - p.a, p.b.., c.a, c.b..
DISPATCH_TO_METHOD_TEMPLATE = """\
template <typename R, typename T, typename Method, %(template_params)s>
inline R DispatchToMethod(T* obj, Method method,
const %(prebound)s& p,
const %(calltime)s& c) {
return (obj->*method)(%(args)s);
}
"""
DISPATCH_TO_FUNCTION_TEMPLATE = """\
template <typename R, typename Function, %(template_params)s>
inline R DispatchToFunction(Function function,
const %(prebound)s& p,
const %(calltime)s& c) {
return (*function)(%(args)s);
}
"""
# Templates for CreateFunctor functions.
# template_params - typename P1, typename P2.. typename C1.. typename X1..
# prebound - TupleN<P1, .. PN>
# calltime - TupleN<A1, .. AN>
# params - X1,.. , A1, ..
# args - const P1& p1 ..
# call_args - p1, p2, p3..
CREATE_METHOD_FUNCTOR_TEMPLATE = """\
template <typename R, typename T, typename U, %(template_params)s>
inline MutantFunctor<R, %(calltime)s>
CreateFunctor(T* obj, R (U::*method)(%(params)s), %(args)s) {
MutantRunner<R, %(calltime)s>* t =
new Mutant<R, T, R (U::*)(%(params)s),
%(prebound)s, %(calltime)s>
(obj, method, MakeTuple(%(call_args)s));
return MutantFunctor<R, %(calltime)s>(t);
}
"""
CREATE_FUNCTION_FUNCTOR_TEMPLATE = """\
template <typename R, %(template_params)s>
inline MutantFunctor<R, %(calltime)s>
CreateFunctor(R (*function)(%(params)s), %(args)s) {
MutantRunner<R, %(calltime)s>* t =
new MutantFunction<R, R (*)(%(params)s),
%(prebound)s, %(calltime)s>
(function, MakeTuple(%(call_args)s));
return MutantFunctor<R, %(calltime)s>(t);
}
"""
def SplitLine(line, width):
"""Splits a single line at comma, at most |width| characters long."""
if len(line) < width:
return (line, None)
n = 1 + line[:width].rfind(",")
if n == 0: # If comma cannot be found give up and return the entire line.
return (line, None)
# Assume there is a space after the comma
assert line[n] == " "
return (line[:n], line[n + 1:])
def Wrap(s, width, subsequent_offset=4):
"""Wraps a single line |s| at commas so every line is at most |width|
characters long.
"""
w = []
spaces = " " * subsequent_offset
while s:
(f, s) = SplitLine(s, width)
w.append(f)
if s:
s = spaces + s
return "\n".join(w)
def Clean(s):
"""Cleans artifacts from generated C++ code.
Our simple string formatting/concatenation may introduce extra commas.
"""
s = s.replace("<>", "")
s = s.replace(", >", ">")
s = s.replace(", )", ")")
s = s.replace(">>", "> >")
return s
def ExpandPattern(pattern, it):
"""Return list of expanded pattern strings.
Each string is created by replacing all '%' in |pattern| with element of |it|.
"""
return [pattern.replace("%", x) for x in it]
def Gen(pattern, n):
"""Expands pattern replacing '%' with sequential integers.
Expanded patterns will be joined with comma separator.
GenAlphs("X%", 3) will return "X1, X2, X3".
"""
it = string.hexdigits[1:n + 1]
return ", ".join(ExpandPattern(pattern, it))
def GenAlpha(pattern, n):
"""Expands pattern replacing '%' with sequential small ASCII letters.
Expanded patterns will be joined with comma separator.
GenAlphs("X%", 3) will return "Xa, Xb, Xc".
"""
it = string.ascii_lowercase[0:n]
return ", ".join(ExpandPattern(pattern, it))
def Merge(a):
return ", ".join(filter(len, a))
def GenTuple(pattern, n):
return Clean("Tuple%d<%s>" % (n, Gen(pattern, n)))
def FixCode(s):
lines = Clean(s).splitlines()
# Wrap sometimes very long 1st and 3rd line at 80th column.
lines[0] = Wrap(lines[0], 80, 10)
lines[2] = Wrap(lines[2], 80, 4)
return "\n".join(lines)
def GenerateDispatch(prebound, calltime):
print "\n// %d - %d" % (prebound, calltime)
args = {
"template_params": Merge([Gen("typename P%", prebound),
Gen("typename C%", calltime)]),
"prebound": GenTuple("P%", prebound),
"calltime": GenTuple("C%", calltime),
"args": Merge([GenAlpha("p.%", prebound), GenAlpha("c.%", calltime)]),
}
print FixCode(DISPATCH_TO_METHOD_TEMPLATE % args)
print FixCode(DISPATCH_TO_FUNCTION_TEMPLATE % args)
def GenerateCreateFunctor(prebound, calltime):
print "// %d - %d" % (prebound, calltime)
args = {
"calltime": GenTuple("A%", calltime),
"prebound": GenTuple("P%", prebound),
"params": Merge([Gen("X%", prebound), Gen("A%", calltime)]),
"args": Gen("const P%& p%", prebound),
"call_args": Gen("p%", prebound),
"template_params": Merge([Gen("typename P%", prebound),
Gen("typename A%", calltime),
Gen("typename X%", prebound)])
}
mutant = FixCode(CREATE_METHOD_FUNCTOR_TEMPLATE % args)
print mutant
# Slightly different version for free function call.
print "\n", FixCode(CREATE_FUNCTION_FUNCTOR_TEMPLATE % args)
# Functor with pointer to a pointer of the object.
print "\n#ifdef GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING"
mutant2 = mutant.replace("CreateFunctor(T* obj,", "CreateFunctor(T** obj,")
mutant2 = mutant2.replace("new Mutant", "new MutantLateObjectBind")
mutant2 = mutant2.replace(" " * 17 + "Tuple", " " * 31 + "Tuple")
print mutant2
print "#endif // GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING\n"
# OS_WIN specific. Same functors but with stdcall calling conventions.
# These are not for WIN64 (x86_64) because there is only one calling
# convention in WIN64.
# Functor for method with __stdcall calling conventions.
print "#if defined (OS_WIN) && !defined (ARCH_CPU_X86_64)"
stdcall_method = CREATE_METHOD_FUNCTOR_TEMPLATE
stdcall_method = stdcall_method.replace("U::", "__stdcall U::")
stdcall_method = FixCode(stdcall_method % args)
print stdcall_method
# Functor for free function with __stdcall calling conventions.
stdcall_function = CREATE_FUNCTION_FUNCTOR_TEMPLATE
stdcall_function = stdcall_function.replace("R (*", "R (__stdcall *")
print "\n", FixCode(stdcall_function % args)
print "#ifdef GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING"
stdcall2 = stdcall_method
stdcall2 = stdcall2.replace("CreateFunctor(T* obj,", "CreateFunctor(T** obj,")
stdcall2 = stdcall2.replace("new Mutant", "new MutantLateObjectBind")
stdcall2 = stdcall2.replace(" " * 17 + "Tuple", " " * 31 + "Tuple")
print stdcall2
print "#endif // GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING"
print "#endif // defined (OS_WIN) && !defined (ARCH_CPU_X86_64)\n"
def main():
print HEADER
for prebound in xrange(0, 6 + 1):
for args in xrange(0, 6 + 1):
GenerateDispatch(prebound, args)
print MUTANT
for prebound in xrange(0, 6 + 1):
for args in xrange(0, 6 + 1):
GenerateCreateFunctor(prebound, args)
print FOOTER
return 0
if __name__ == "__main__":
sys.exit(main())
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
1059,
199,
646,
984,
199,
199,
7311,
275,
9638,
199,
501,
1898,
334,
67,
9,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
501,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
501,
1911,
315,
314,
5113,
570,
14,
199,
199,
501,
961,
570,
5847,
4046,
701,
5343,
15,
4208,
63,
71,
1805,
63,
6552,
867,
14,
647,
14,
199,
501,
3506,
2845,
24981,
14,
199,
199,
3,
27708,
7393,
1206,
63,
39,
17749,
63,
25890,
1441,
63,
40,
63,
199,
3,
4640,
7393,
1206,
63,
39,
17749,
63,
25890,
1441,
63,
40,
63,
199,
199,
501,
710,
25343,
402,
642,
570,
365,
370,
1852,
3962,
1808,
598,
3346,
5445,
315,
199,
501,
1006,
402,
2399,
1847,
343,
27296,
506,
6898,
89,
14,
27939,
436,
5922,
3423,
883,
506,
1202,
465,
199,
501,
1655,
7809,
21169,
402,
8495,
436,
17555,
3992,
334,
3239,
1300,
15,
1765,
14,
72,
9,
199,
501,
26550,
867,
5171,
3865,
876,
13,
3556,
2368,
334,
2930,
8495,
9,
436,
1240,
13,
521,
199,
501,
2368,
334,
2930,
17555,
9,
446,
19407,
314,
536,
14,
22901,
9,
199,
501,
199,
501,
28626,
1378,
3767,
15,
3481,
5171,
2877,
5951,
402,
2368,
26,
876,
13,
3556,
334,
48,
9,
436,
199,
501,
1240,
13,
521,
334,
35,
680,
710,
2368,
465,
5521,
465,
314,
372,
730,
787,
2388,
416,
22927,
14,
199,
501,
28626,
1378,
3767,
15,
3481,
911,
2597,
862,
370,
1240,
314,
4895,
1083,
503,
199,
501,
805,
2755,
340,
2741,
876,
13,
3556,
2368,
1630,
440,
1336,
8840,
543,
199,
501,
314,
805,
4955,
19407,
314,
1323,
17,
12,
1323,
18,
2263,
1323,
46,
2633,
315,
2790,
19941,
630,
14,
199,
501,
28626,
1378,
3767,
911,
862,
370,
12677,
1083,
626,
1443,
440,
13511,
370,
314,
199,
501,
909,
1159,
1021,
6337,
1325,
370,
314,
909,
1159,
1021,
1300,
1021,
14,
199,
501,
199,
501,
25448,
1265,
883,
5398,
314,
909,
737,
1240,
521,
701,
11696,
282,
7849,
370,
199,
501,
7849,
370,
314,
909,
737,
7143,
900,
446,
2544,
5893,
642,
570,
1265,
199,
501,
1172,
370,
327,
4640,
598,
17749,
63,
25890,
1441,
63,
18171,
63,
30064,
63,
9868,
63,
28347,
14,
199,
501,
199,
501,
3254,
8,
14308,
89,
290,
304,
2779,
1159,
5966,
440,
5436,
370,
562,
1077,
781,
675,
377,
6,
436,
377,
6,
10,
3140,
199,
501,
402,
377,
10,
436,
377,
538,
1380,
781,
12677,
2790,
19941,
630,
370,
1336,
314,
20464,
63,
11978,
3449,
14,
199,
501,
199,
501,
199,
501,
15227,
4503,
543,
486,
3346,
26,
199,
501,
199,
501,
2702,
4420,
520,
4575,
6935,
21553,
469,
199,
501,
257,
10362,
2504,
63,
9977,
18,
8,
875,
12,
4068,
2017,
8,
442,
302,
12,
950,
1059,
6,
1056,
16674,
199,
501,
257,
10362,
2504,
63,
9977,
17,
8,
1647,
12,
4068,
24145,
8,
442,
4458,
63,
600,
16674,
199,
501,
257,
10362,
2504,
63,
9977,
18,
8,
1647,
12,
5297,
2209,
8,
442,
2166,
12,
950,
1059,
6,
1245,
16674,
199,
501,
199,
501,
257,
1059,
8690,
5060,
1192,
8,
1297,
1059,
6,
9351,
12,
1109,
302,
12,
950,
1059,
6,
1056,
9,
469,
199,
501,
258,
1059,
754,
275,
428,
1558,
5375,
70,
480,
607,
1056,
402,
450,
68,
450,
83,
3872,
302,
12,
1056,
2736,
199,
501,
258,
367,
334,
442,
284,
275,
378,
27,
284,
665,
302,
27,
32629,
73,
9,
754,
14,
740,
8,
8102,
9,
199,
501,
258,
372,
754,
27,
199,
501,
257,
789,
199,
501,
199,
501,
257,
2309,
4226,
2445,
2209,
8,
442,
2166,
12,
950,
1059,
6,
1245,
9,
469,
199,
501,
257,
789,
199,
501,
199,
501,
257,
2309,
1413,
4993,
2209,
7382,
8,
442,
4696,
9,
469,
199,
501,
258,
6430,
7382,
10,
4438,
275,
6430,
7382,
447,
1818,
7303,
199,
501,
258,
4438,
5118,
6564,
10796,
379,
4476,
8,
12491,
63,
5293,
12,
6430,
7382,
447,
24145,
3337,
3253,
1062,
199,
501,
13235,
5198,
627,
4696,
2736,
199,
501,
257,
789,
199,
501,
16735,
199,
501,
199,
501,
4420,
1683,
27,
199,
501,
5001,
12823,
12677,
1683,
14,
5940,
5060,
1192,
480,
269,
335,
1580,
401,
302,
12,
1056,
9,
199,
501,
5001,
298,
269,
335,
1580,
2,
365,
282,
876,
13,
3556,
1423,
12,
436,
665,
78,
30,
436,
665,
1069,
30,
787,
1240,
13,
521,
199,
501,
5001,
2368,
446,
2985,
787,
440,
6040,
5133,
314,
4068,
2017,
1683,
365,
10302,
14,
199,
501,
20464,
63,
11978,
8,
1805,
12,
4068,
2017,
8,
4240,
8,
21,
395,
7707,
83,
3007,
480,
1659,
281,
2237,
199,
501,
257,
1275,
17687,
8,
17,
9,
199,
501,
257,
1275,
20326,
25690,
8,
27736,
8,
2499,
19941,
630,
24168,
1805,
12,
1253,
3346,
447,
5940,
5060,
1192,
12,
199,
501,
755,
1059,
480,
269,
335,
1580,
2237,
16674,
199,
501,
199,
501,
199,
501,
5001,
3091,
876,
13,
3556,
2368,
12,
2877,
1240,
13,
521,
2368,
3032,
199,
501,
5001,
5370,
370,
4226,
2445,
2209,
199,
501,
20464,
63,
11978,
8,
1805,
12,
4068,
2445,
2209,
1547,
12,
485,
430,
199,
501,
257,
1275,
17687,
8,
9874,
3259,
1012,
199,
501,
257,
1275,
20326,
2439,
2885,
8,
27736,
8,
2499,
19941,
630,
12,
1253,
1805,
12,
1253,
3346,
447,
2585,
2445,
2209,
16674,
199,
501,
199,
501,
199,
501,
5001,
1010,
642,
1930,
781,
1172,
282,
2849,
876,
13,
3556,
1423,
446,
650,
14,
2136,
3686,
199,
501,
5001,
1006,
402,
314,
2368,
402,
4068,
24145,
14,
199,
501,
3651,
7177,
63,
11978,
8,
1805,
12,
4068,
24145,
1547,
430,
199,
501,
257,
1275,
17687,
8,
17,
9,
199,
501,
257,
1275,
20326,
25690,
8,
27736,
12450,
6213,
8,
2499,
19941,
630,
8,
199,
501,
755,
1253,
1805,
12,
1253,
3346,
447,
24145,
2209,
7382,
12,
650,
1724,
27,
199,
501,
199,
501,
6430,
7382,
4438,
27
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
1059,
199,
646,
984,
199,
199,
7311,
275,
9638,
199,
501,
1898,
334,
67,
9,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
501,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
501,
1911,
315,
314,
5113,
570,
14,
199,
199,
501,
961,
570,
5847,
4046,
701,
5343,
15,
4208,
63,
71,
1805,
63,
6552,
867,
14,
647,
14,
199,
501,
3506,
2845,
24981,
14,
199,
199,
3,
27708,
7393,
1206,
63,
39,
17749,
63,
25890,
1441,
63,
40,
63,
199,
3,
4640,
7393,
1206,
63,
39,
17749,
63,
25890,
1441,
63,
40,
63,
199,
199,
501,
710,
25343,
402,
642,
570,
365,
370,
1852,
3962,
1808,
598,
3346,
5445,
315,
199,
501,
1006,
402,
2399,
1847,
343,
27296,
506,
6898,
89,
14,
27939,
436,
5922,
3423,
883,
506,
1202,
465,
199,
501,
1655,
7809,
21169,
402,
8495,
436,
17555,
3992,
334,
3239,
1300,
15,
1765,
14,
72,
9,
199,
501,
26550,
867,
5171,
3865,
876,
13,
3556,
2368,
334,
2930,
8495,
9,
436,
1240,
13,
521,
199,
501,
2368,
334,
2930,
17555,
9,
446,
19407,
314,
536,
14,
22901,
9,
199,
501,
199,
501,
28626,
1378,
3767,
15,
3481,
5171,
2877,
5951,
402,
2368,
26,
876,
13,
3556,
334,
48,
9,
436,
199,
501,
1240,
13,
521,
334,
35,
680,
710,
2368,
465,
5521,
465,
314,
372,
730,
787,
2388,
416,
22927,
14,
199,
501,
28626,
1378,
3767,
15,
3481,
911,
2597,
862,
370,
1240,
314,
4895,
1083,
503,
199,
501,
805,
2755,
340,
2741,
876,
13,
3556,
2368,
1630,
440,
1336,
8840,
543,
199,
501,
314,
805,
4955,
19407,
314,
1323,
17,
12,
1323,
18,
2263,
1323,
46,
2633,
315,
2790,
19941,
630,
14,
199,
501,
28626,
1378,
3767,
911,
862,
370,
12677,
1083,
626,
1443,
440,
13511,
370,
314,
199,
501,
909,
1159,
1021,
6337,
1325,
370,
314,
909,
1159,
1021,
1300,
1021,
14,
199,
501,
199,
501,
25448,
1265,
883,
5398,
314,
909,
737,
1240,
521,
701,
11696,
282,
7849,
370,
199,
501,
7849,
370,
314,
909,
737,
7143,
900,
446,
2544,
5893,
642,
570,
1265,
199,
501,
1172,
370,
327,
4640,
598,
17749,
63,
25890,
1441,
63,
18171,
63,
30064,
63,
9868,
63,
28347,
14,
199,
501,
199,
501,
3254,
8,
14308,
89,
290,
304,
2779,
1159,
5966,
440,
5436,
370,
562,
1077,
781,
675,
377,
6,
436,
377,
6,
10,
3140,
199,
501,
402,
377,
10,
436,
377,
538,
1380,
781,
12677,
2790,
19941,
630,
370,
1336,
314,
20464,
63,
11978,
3449,
14,
199,
501,
199,
501,
199,
501,
15227,
4503,
543,
486,
3346,
26,
199,
501,
199,
501,
2702,
4420,
520,
4575,
6935,
21553,
469,
199,
501,
257,
10362,
2504,
63,
9977,
18,
8,
875,
12,
4068,
2017,
8,
442,
302,
12,
950,
1059,
6,
1056,
16674,
199,
501,
257,
10362,
2504,
63,
9977,
17,
8,
1647,
12,
4068,
24145,
8,
442,
4458,
63,
600,
16674,
199,
501,
257,
10362,
2504,
63,
9977,
18,
8,
1647,
12,
5297,
2209,
8,
442,
2166,
12,
950,
1059,
6,
1245,
16674,
199,
501,
199,
501,
257,
1059,
8690,
5060,
1192,
8,
1297,
1059,
6,
9351,
12,
1109,
302,
12,
950,
1059,
6,
1056,
9,
469,
199,
501,
258,
1059,
754,
275,
428,
1558,
5375,
70,
480,
607,
1056,
402,
450,
68,
450,
83,
3872,
302,
12,
1056,
2736,
199,
501,
258,
367,
334,
442,
284,
275,
378,
27,
284,
665,
302,
27,
32629,
73,
9,
754,
14,
740,
8,
8102,
9,
199,
501,
258,
372,
754,
27,
199,
501,
257,
789,
199,
501,
199,
501,
257,
2309,
4226,
2445,
2209,
8,
442,
2166,
12,
950,
1059,
6,
1245,
9,
469,
199,
501,
257,
789,
199,
501,
199,
501,
257,
2309,
1413,
4993,
2209,
7382,
8,
442,
4696,
9,
469,
199,
501,
258,
6430,
7382,
10,
4438,
275,
6430,
7382,
447,
1818,
7303,
199,
501,
258,
4438,
5118,
6564,
10796,
379,
4476,
8,
12491,
63,
5293,
12,
6430,
7382,
447,
24145,
3337,
3253,
1062,
199,
501,
13235,
5198,
627,
4696,
2736,
199,
501,
257,
789,
199,
501,
16735,
199,
501,
199,
501,
4420,
1683,
27,
199,
501,
5001,
12823,
12677,
1683,
14,
5940,
5060,
1192,
480,
269,
335,
1580,
401,
302,
12,
1056,
9,
199,
501,
5001,
298,
269,
335,
1580,
2,
365,
282,
876,
13,
3556,
1423,
12,
436,
665,
78,
30,
436,
665,
1069,
30,
787,
1240,
13,
521,
199,
501,
5001,
2368,
446,
2985,
787,
440,
6040,
5133,
314,
4068,
2017,
1683,
365,
10302,
14,
199,
501,
20464,
63,
11978,
8,
1805,
12,
4068,
2017,
8,
4240,
8,
21,
395,
7707,
83,
3007,
480,
1659,
281,
2237,
199,
501,
257,
1275,
17687,
8,
17,
9,
199,
501,
257,
1275,
20326,
25690,
8,
27736,
8,
2499,
19941,
630,
24168,
1805,
12,
1253,
3346,
447,
5940,
5060,
1192,
12,
199,
501,
755,
1059,
480,
269,
335,
1580,
2237,
16674,
199,
501,
199,
501,
199,
501,
5001,
3091,
876,
13,
3556,
2368,
12,
2877,
1240,
13,
521,
2368,
3032,
199,
501,
5001,
5370,
370,
4226,
2445,
2209,
199,
501,
20464,
63,
11978,
8,
1805,
12,
4068,
2445,
2209,
1547,
12,
485,
430,
199,
501,
257,
1275,
17687,
8,
9874,
3259,
1012,
199,
501,
257,
1275,
20326,
2439,
2885,
8,
27736,
8,
2499,
19941,
630,
12,
1253,
1805,
12,
1253,
3346,
447,
2585,
2445,
2209,
16674,
199,
501,
199,
501,
199,
501,
5001,
1010,
642,
1930,
781,
1172,
282,
2849,
876,
13,
3556,
1423,
446,
650,
14,
2136,
3686,
199,
501,
5001,
1006,
402,
314,
2368,
402,
4068,
24145,
14,
199,
501,
3651,
7177,
63,
11978,
8,
1805,
12,
4068,
24145,
1547,
430,
199,
501,
257,
1275,
17687,
8,
17,
9,
199,
501,
257,
1275,
20326,
25690,
8,
27736,
12450,
6213,
8,
2499,
19941,
630,
8,
199,
501,
755,
1253,
1805,
12,
1253,
3346,
447,
24145,
2209,
7382,
12,
650,
1724,
27,
199,
501,
199,
501,
6430,
7382,
4438,
27,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
rixrix/servo
|
tests/wpt/css-tests/tools/pywebsocket/src/example/abort_handshake_wsh.py
|
465
|
1781
|
# Copyright 2012, 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.
from mod_pywebsocket import handshake
def web_socket_do_extra_handshake(request):
raise handshake.AbortedByUserException(
"Aborted in web_socket_do_extra_handshake")
def web_socket_transfer_data(request):
pass
# vi:sts=4 sw=4 et
|
mpl-2.0
|
[
3,
1898,
6029,
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,
421,
199,
504,
3413,
63,
21387,
492,
14305,
421,
199,
318,
3330,
63,
3450,
63,
1117,
63,
2911,
63,
11913,
8,
1069,
304,
272,
746,
14305,
14,
5583,
1376,
2175,
1899,
1726,
8,
267,
298,
5583,
1376,
315,
3330,
63,
3450,
63,
1117,
63,
2911,
63,
11913,
531,
421,
199,
318,
3330,
63,
3450,
63,
9609,
63,
576,
8,
1069,
304,
272,
986,
421,
199,
3,
1321,
26,
10329,
29,
20,
5584,
29,
20,
10844,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6029,
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,
421,
199,
504,
3413,
63,
21387,
492,
14305,
421,
199,
318,
3330,
63,
3450,
63,
1117,
63,
2911,
63,
11913,
8,
1069,
304,
272,
746,
14305,
14,
5583,
1376,
2175,
1899,
1726,
8,
267,
298,
5583,
1376,
315,
3330,
63,
3450,
63,
1117,
63,
2911,
63,
11913,
531,
421,
199,
318,
3330,
63,
3450,
63,
9609,
63,
576,
8,
1069,
304,
272,
986,
421,
199,
3,
1321,
26,
10329,
29,
20,
5584,
29,
20,
10844,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
camon/Flexget
|
pavement.py
|
4
|
10182
|
"""
FlexGet build and development utilities - unfortunately this file is somewhat messy
"""
import os
import sys
from paver.easy import *
import paver.virtual
import paver.setuputils
from paver.setuputils import setup, find_package_data, find_packages
sphinxcontrib = False
try:
from sphinxcontrib import paverutils
sphinxcontrib = True
except ImportError:
pass
sys.path.insert(0, '')
options = environment.options
# There is a bug in sqlalchemy 0.9.0, see gh#127
# There is a bug in beautifulsoup 4.2.0 that breaks imdb parsing, see http://flexget.com/ticket/2091
# There is a bug in requests 2.4.0 where it leaks urllib3 exceptions
install_requires = ['FeedParser>=5.1.3', 'SQLAlchemy >=0.7.5, !=0.9.0, <0.9.99', 'PyYAML',
'beautifulsoup4>=4.1, !=4.2.0, <4.4', 'html5lib>=0.11', 'PyRSS2Gen', 'pynzb', 'progressbar', 'rpyc',
'jinja2', 'requests>=1.0, !=2.4.0, <2.99', 'python-dateutil!=2.0, !=2.2', 'jsonschema>=2.0',
'python-tvrage', 'tmdb3', 'path.py', 'guessit>=0.9.3', 'apscheduler']
if sys.version_info < (2, 7):
# argparse is part of the standard library in python 2.7+
install_requires.append('argparse')
entry_points = {'console_scripts': ['flexget = flexget:main']}
# Provide an alternate exe on windows which does not cause a pop-up when scheduled
if sys.platform.startswith('win'):
entry_points.setdefault('gui_scripts', []).append('flexget-headless = flexget:main')
with open("README.rst") as readme:
long_description = readme.read()
# Populates __version__ without importing the package
__version__ = None
execfile('flexget/_version.py')
if not __version__:
print 'Could not find __version__ from flexget/_version.py'
sys.exit(1)
setup(
name='FlexGet',
version=__version__, # release task may edit this
description='FlexGet is a program aimed to automate downloading or processing content (torrents, podcasts, etc.) '
'from different sources like RSS-feeds, html-pages, various sites and more.',
long_description=long_description,
author='Marko Koivusalo',
author_email='marko.koivusalo@gmail.com',
license='MIT',
url='http://flexget.com',
download_url='http://download.flexget.com',
install_requires=install_requires,
packages=find_packages(exclude=['tests']),
package_data=find_package_data('flexget', package='flexget',
exclude=['FlexGet.egg-info', '*.pyc'],
only_in_packages=False), # NOTE: the exclude does not seem to work
zip_safe=False,
test_suite='nose.collector',
extras_require={
'memusage': ['guppy'],
'NZB': ['pynzb'],
'TaskTray': ['pywin32'],
'webui': ['flask>=0.7', 'cherrypy']
},
entry_points=entry_points,
classifiers=[
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
)
options(
minilib=Bunch(
# 'version' is included as workaround to https://github.com/paver/paver/issues/112, TODO: remove
extra_files=['virtual', 'svn', 'version']
),
virtualenv=Bunch(
paver_command_line='develop'
),
# sphinxcontrib.paverutils
sphinx=Bunch(
docroot='docs',
builddir='build',
builder='html',
confdir='docs'
),
)
def set_init_version(ver):
"""Replaces the version with ``ver`` in _version.py"""
import fileinput
for line in fileinput.FileInput('flexget/_version.py', inplace=1):
if line.startswith('__version__ = '):
line = "__version__ = '%s'\n" % ver
print line,
@task
def version():
"""Prints the version number of the source"""
print __version__
@task
@cmdopts([('dev', None, 'Bumps to new development version instead of release version.')])
def increment_version(options):
"""Increments either release or dev version by 1"""
print 'current version: %s' % __version__
ver_split = __version__.split('.')
dev = options.increment_version.get('dev')
if 'dev' in ver_split[-1]:
if dev:
# If this is already a development version, increment the dev count by 1
ver_split[-1] = 'dev%d' % (int(ver_split[-1].strip('dev') or 0) + 1)
else:
# Just strip off dev tag for next release version
ver_split = ver_split[:-1]
else:
# Increment the revision number by one
if len(ver_split) == 2:
# We don't have a revision number, assume 0
ver_split.append('1')
else:
ver_split[-1] = str(int(ver_split[-1]) + 1)
if dev:
ver_split.append('dev')
new_version = '.'.join(ver_split)
print 'new version: %s' % new_version
set_init_version(new_version)
@task
@cmdopts([
('online', None, 'Run online tests')
])
def test(options):
"""Run FlexGet unit tests"""
options.setdefault('test', Bunch())
import nose
from nose.plugins.manager import DefaultPluginManager
cfg = nose.config.Config(plugins=DefaultPluginManager(), verbosity=2)
args = []
# Adding the -v flag makes the tests fail in python 2.7
#args.append('-v')
args.append('--processes=4')
args.append('-x')
if not options.test.get('online'):
args.append('--attr=!online')
args.append('--where=tests')
# Store current path since --where changes it, restore when leaving
cwd = os.getcwd()
try:
return nose.run(argv=args, config=cfg)
finally:
os.chdir(cwd)
@task
def clean():
"""Cleans up the virtualenv"""
import os
import glob
for p in ('bin', 'Scripts', 'build', 'dist', 'include', 'lib', 'man',
'share', 'FlexGet.egg-info', 'paver-minilib.zip', 'setup.py'):
pth = path(p)
if pth.isdir():
pth.rmtree()
elif pth.isfile():
pth.remove()
for pkg in set(options.setup.packages) | set(('tests',)):
for filename in glob.glob(pkg.replace('.', os.sep) + "/*.py[oc~]"):
path(filename).remove()
@task
@cmdopts([
('dist-dir=', 'd', 'directory to put final built distributions in'),
('revision=', 'r', 'minor revision number of this build')
])
def sdist(options):
"""Build tar.gz distribution package"""
print 'sdist version: %s' % __version__
# clean previous build
print 'Cleaning build...'
for p in ['build']:
pth = path(p)
if pth.isdir():
pth.rmtree()
elif pth.isfile():
pth.remove()
else:
print 'Unable to remove %s' % pth
# remove pre-compiled pycs from tests, I don't know why paver even tries to include them ...
# seems to happen only with sdist though
for pyc in path('tests/').files('*.pyc'):
pyc.remove()
for t in ['minilib', 'generate_setup', 'setuptools.command.sdist']:
call_task(t)
@task
def coverage():
"""Make coverage.flexget.com"""
# --with-coverage --cover-package=flexget --cover-html --cover-html-dir /var/www/flexget_coverage/
import nose
from nose.plugins.manager import DefaultPluginManager
cfg = nose.config.Config(plugins=DefaultPluginManager(), verbosity=2)
argv = ['bin/paver']
argv.extend(['--attr=!online'])
argv.append('--with-coverage')
argv.append('--cover-html')
argv.extend(['--cover-package', 'flexget'])
argv.extend(['--cover-html-dir', '/var/www/flexget_coverage/'])
nose.run(argv=argv, config=cfg)
print 'Coverage generated'
@task
@cmdopts([
('docs-dir=', 'd', 'directory to put the documetation in')
])
def docs():
if not sphinxcontrib:
print 'ERROR: requires sphinxcontrib-paverutils'
sys.exit(1)
from paver import tasks
if not os.path.exists('build'):
os.mkdir('build')
if not os.path.exists(os.path.join('build', 'sphinx')):
os.mkdir(os.path.join('build', 'sphinx'))
setup_section = tasks.environment.options.setdefault("sphinx", Bunch())
setup_section.update(outdir=options.docs.get('docs_dir', 'build/sphinx'))
call_task('html')
@task
@might_call('test', 'sdist')
@cmdopts([('no-tests', None, 'skips unit tests')])
def release(options):
"""Run tests then make an sdist if successful."""
if not options.release.get('no_tests'):
if not test():
print 'Unit tests did not pass'
sys.exit(1)
print 'Making src release'
sdist()
@task
def install_tools():
"""Install development / jenkins tools and dependencies"""
try:
import pip
except ImportError:
print 'FATAL: Unable to import pip, please install it and run this again!'
sys.exit(1)
try:
import sphinxcontrib
print 'sphinxcontrib INSTALLED'
except ImportError:
pip.main(['install', 'sphinxcontrib-paverutils'])
pip.main(['install', '-r', 'jenkins-requirements.txt'])
@task
def clean_compiled():
for root, dirs, files in os.walk('flexget'):
for name in files:
fqn = os.path.join(root, name)
if fqn[-3:] == 'pyc' or fqn[-3:] == 'pyo' or fqn[-5:] == 'cover':
print 'Deleting %s' % fqn
os.remove(fqn)
@task
@consume_args
def pep8(args):
try:
import pep8
except:
print 'Run bin/paver install_tools'
sys.exit(1)
# Ignoring certain errors
ignore = [
'E711', 'E712', # These are comparisons to singletons i.e. == False, and == None. We need these for sqlalchemy.
'W291', 'W293', 'E261',
'E128' # E128 continuation line under-indented for visual indent
]
styleguide = pep8.StyleGuide(show_source=True, ignore=ignore, repeat=1, max_line_length=120,
parse_argv=args)
styleguide.input_dir('flexget')
|
mit
|
[
624,
199,
38,
3113,
1002,
1900,
436,
16367,
15841,
446,
625,
21839,
642,
570,
365,
30362,
15634,
89,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
504,
691,
422,
14,
13581,
492,
627,
199,
646,
691,
422,
14,
2065,
199,
646,
691,
422,
14,
2758,
1208,
199,
504,
691,
422,
14,
2758,
1208,
492,
3272,
12,
2342,
63,
2491,
63,
576,
12,
2342,
63,
5154,
199,
199,
8008,
2828,
275,
756,
199,
893,
26,
272,
687,
15882,
2828,
492,
691,
422,
1208,
272,
15882,
2828,
275,
715,
199,
2590,
3545,
26,
272,
986,
199,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
4074,
199,
199,
1419,
275,
3734,
14,
1419,
199,
3,
6006,
365,
282,
6519,
315,
8335,
378,
14,
25,
14,
16,
12,
1937,
23310,
3,
4195,
199,
3,
6006,
365,
282,
6519,
315,
506,
25146,
9317,
841,
14,
18,
14,
16,
626,
18277,
18232,
6057,
12,
1937,
1455,
921,
14759,
362,
14,
957,
15,
9201,
15,
1165,
3328,
199,
3,
6006,
365,
282,
6519,
315,
4145,
499,
14,
20,
14,
16,
2382,
652,
1026,
14631,
4011,
19,
4967,
199,
3174,
63,
6537,
275,
788,
7658,
2842,
8119,
21,
14,
17,
14,
19,
297,
283,
4657,
12800,
2356,
16,
14,
23,
14,
21,
12,
1137,
16,
14,
25,
14,
16,
12,
665,
16,
14,
25,
14,
1020,
297,
283,
2713,
23103,
297,
490,
283,
1235,
25146,
9317,
20,
8119,
20,
14,
17,
12,
1137,
20,
14,
18,
14,
16,
12,
665,
20,
14,
20,
297,
283,
1360,
21,
773,
8119,
16,
14,
845,
297,
283,
2713,
22786,
18,
8168,
297,
283,
647,
15291,
66,
297,
283,
5734,
1700,
297,
283,
82,
11357,
297,
490,
283,
12264,
18,
297,
283,
6615,
8119,
17,
14,
16,
12,
1137,
18,
14,
20,
14,
16,
12,
665,
18,
14,
1020,
297,
283,
1548,
13,
602,
1974,
1111,
18,
14,
16,
12,
1137,
18,
14,
18,
297,
283,
1001,
3629,
8119,
18,
14,
16,
297,
490,
283,
1548,
13,
6993,
28812,
297,
283,
7574,
697,
19,
297,
283,
515,
14,
647,
297,
283,
71,
10138,
2221,
8119,
16,
14,
25,
14,
19,
297,
283,
7461,
5085,
418,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
18,
12,
1520,
304,
272,
327,
7534,
365,
1777,
402,
314,
4465,
3555,
315,
2366,
499,
14,
23,
11,
272,
3907,
63,
6537,
14,
740,
360,
18978,
358,
199,
199,
2373,
63,
3438,
275,
791,
6614,
63,
6429,
356,
788,
14759,
362,
275,
20758,
362,
26,
973,
12074,
199,
199,
3,
22896,
376,
18034,
14778,
641,
10061,
1314,
1630,
440,
7675,
282,
4560,
13,
384,
1380,
18416,
199,
692,
984,
14,
3246,
14,
2460,
360,
2676,
735,
272,
2397,
63,
3438,
14,
5486,
360,
5885,
63,
6429,
297,
15364,
740,
360,
14759,
362,
13,
2993,
2003,
275,
20758,
362,
26,
973,
358,
199,
199,
1045,
1551,
480,
18195,
14,
8332,
531,
465,
1586,
278,
26,
272,
1846,
63,
1802,
275,
1586,
278,
14,
739,
342,
199,
199,
3,
13244,
15409,
636,
1023,
363,
1928,
16306,
314,
2559,
199,
363,
1023,
363,
275,
488,
199,
1628,
493,
360,
14759,
362,
15607,
1023,
14,
647,
358,
199,
692,
440,
636,
1023,
10651,
272,
870,
283,
6531,
440,
2342,
636,
1023,
363,
687,
20758,
362,
15607,
1023,
14,
647,
7,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
2758,
8,
272,
536,
534,
38,
3113,
1002,
297,
272,
1015,
18971,
1023,
3108,
221,
327,
4683,
2120,
1443,
5283,
642,
272,
1369,
534,
38,
3113,
1002,
365,
282,
2240,
282,
21538,
370,
6384,
676,
323,
25937,
503,
6661,
1564,
334,
14101,
83,
12,
15329,
2931,
83,
12,
5423,
4959,
283,
355,
283,
504,
3365,
5274,
2839,
30331,
13,
11522,
12,
3517,
13,
5856,
12,
7750,
15424,
436,
1655,
3130,
272,
1846,
63,
1802,
29,
2809,
63,
1802,
12,
272,
4132,
534,
6470,
79,
1804,
79,
1003,
527,
12201,
297,
272,
4132,
63,
2123,
534,
1657,
79,
14,
7697,
1003,
527,
12201,
32,
6799,
14,
957,
297,
272,
4190,
534,
13965,
297,
272,
1166,
534,
1014,
921,
14759,
362,
14,
957,
297,
272,
5235,
63,
633,
534,
1014,
921,
4249,
14,
14759,
362,
14,
957,
297,
272,
3907,
63,
6537,
29,
3174,
63,
6537,
12,
272,
6117,
29,
1623,
63,
5154,
8,
5473,
2968,
2219,
3815,
272,
2559,
63,
576,
29,
1623,
63,
2491,
63,
576,
360,
14759,
362,
297,
2559,
534,
14759,
362,
297,
267,
5760,
2968,
38,
3113,
1002,
14,
5799,
13,
815,
297,
11937,
11357,
995,
267,
1454,
63,
262,
63,
5154,
29,
797,
395,
221,
327,
6944,
26,
314,
5760,
1630,
440,
17021,
370,
1736,
272,
3482,
63,
3489,
29,
797,
12,
272,
511,
63,
5768,
534,
21085,
14,
10946,
297,
272,
13751,
63,
4365,
3126,
267,
283,
5286,
3807,
356,
788,
71,
384,
647,
995,
267,
283,
19011,
34,
356,
788,
647,
15291,
66,
995,
267,
283,
4476,
52,
803,
356,
788,
647,
2676,
708,
995,
267,
283,
31991,
73,
356,
788,
15720,
8119,
16,
14,
23,
297,
283,
23438,
418,
272,
1660,
272,
2397,
63,
3438,
29,
2373,
63,
3438,
12,
272,
19137,
1524,
267,
298,
23753,
9795,
3800,
959,
446,
24114,
15,
933,
461,
401,
267,
298,
3761,
3800,
25718,
26330,
3800,
10697,
844,
401,
267,
298,
23699,
6187,
3800,
4403,
1010,
7106,
401,
267,
298,
11411,
8466,
3800,
2018,
401,
267,
298,
11411,
8466,
3800,
2018,
3800,
499,
401,
267,
298,
11411,
8466,
3800,
2018,
3800,
499,
14,
22,
401,
267,
298,
11411,
8466,
3800,
2018,
3800,
499,
14,
23,
401,
267,
298,
11411,
8466,
3800,
2018,
3800,
24425,
3800,
25654,
401,
267,
298,
11411,
8466,
3800,
2018,
3800,
24425,
3800,
1611,
2713,
401,
272,
1622,
199,
199,
9,
199,
199,
1419,
8,
272,
20536,
773,
29,
34,
4689,
8,
267,
327,
283,
1023,
7,
365,
5120,
465,
18092,
370,
4178,
921,
5031,
14,
957,
15,
387,
422,
15,
387,
422,
15,
10115,
15,
6094,
12,
3254,
26,
2813,
267,
2402,
63,
1725,
2968,
2065,
297,
283,
6836,
297,
283,
1023,
418,
272,
2318,
272,
19128,
29,
34,
4689,
8,
267,
691,
422,
63,
1531,
63,
604,
534,
32176,
7,
272,
2318,
272,
327,
15882,
2828,
14,
387,
422,
1208,
272,
15882,
29,
34,
4689
] |
[
199,
38,
3113,
1002,
1900,
436,
16367,
15841,
446,
625,
21839,
642,
570,
365,
30362,
15634,
89,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
504,
691,
422,
14,
13581,
492,
627,
199,
646,
691,
422,
14,
2065,
199,
646,
691,
422,
14,
2758,
1208,
199,
504,
691,
422,
14,
2758,
1208,
492,
3272,
12,
2342,
63,
2491,
63,
576,
12,
2342,
63,
5154,
199,
199,
8008,
2828,
275,
756,
199,
893,
26,
272,
687,
15882,
2828,
492,
691,
422,
1208,
272,
15882,
2828,
275,
715,
199,
2590,
3545,
26,
272,
986,
199,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
4074,
199,
199,
1419,
275,
3734,
14,
1419,
199,
3,
6006,
365,
282,
6519,
315,
8335,
378,
14,
25,
14,
16,
12,
1937,
23310,
3,
4195,
199,
3,
6006,
365,
282,
6519,
315,
506,
25146,
9317,
841,
14,
18,
14,
16,
626,
18277,
18232,
6057,
12,
1937,
1455,
921,
14759,
362,
14,
957,
15,
9201,
15,
1165,
3328,
199,
3,
6006,
365,
282,
6519,
315,
4145,
499,
14,
20,
14,
16,
2382,
652,
1026,
14631,
4011,
19,
4967,
199,
3174,
63,
6537,
275,
788,
7658,
2842,
8119,
21,
14,
17,
14,
19,
297,
283,
4657,
12800,
2356,
16,
14,
23,
14,
21,
12,
1137,
16,
14,
25,
14,
16,
12,
665,
16,
14,
25,
14,
1020,
297,
283,
2713,
23103,
297,
490,
283,
1235,
25146,
9317,
20,
8119,
20,
14,
17,
12,
1137,
20,
14,
18,
14,
16,
12,
665,
20,
14,
20,
297,
283,
1360,
21,
773,
8119,
16,
14,
845,
297,
283,
2713,
22786,
18,
8168,
297,
283,
647,
15291,
66,
297,
283,
5734,
1700,
297,
283,
82,
11357,
297,
490,
283,
12264,
18,
297,
283,
6615,
8119,
17,
14,
16,
12,
1137,
18,
14,
20,
14,
16,
12,
665,
18,
14,
1020,
297,
283,
1548,
13,
602,
1974,
1111,
18,
14,
16,
12,
1137,
18,
14,
18,
297,
283,
1001,
3629,
8119,
18,
14,
16,
297,
490,
283,
1548,
13,
6993,
28812,
297,
283,
7574,
697,
19,
297,
283,
515,
14,
647,
297,
283,
71,
10138,
2221,
8119,
16,
14,
25,
14,
19,
297,
283,
7461,
5085,
418,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
18,
12,
1520,
304,
272,
327,
7534,
365,
1777,
402,
314,
4465,
3555,
315,
2366,
499,
14,
23,
11,
272,
3907,
63,
6537,
14,
740,
360,
18978,
358,
199,
199,
2373,
63,
3438,
275,
791,
6614,
63,
6429,
356,
788,
14759,
362,
275,
20758,
362,
26,
973,
12074,
199,
199,
3,
22896,
376,
18034,
14778,
641,
10061,
1314,
1630,
440,
7675,
282,
4560,
13,
384,
1380,
18416,
199,
692,
984,
14,
3246,
14,
2460,
360,
2676,
735,
272,
2397,
63,
3438,
14,
5486,
360,
5885,
63,
6429,
297,
15364,
740,
360,
14759,
362,
13,
2993,
2003,
275,
20758,
362,
26,
973,
358,
199,
199,
1045,
1551,
480,
18195,
14,
8332,
531,
465,
1586,
278,
26,
272,
1846,
63,
1802,
275,
1586,
278,
14,
739,
342,
199,
199,
3,
13244,
15409,
636,
1023,
363,
1928,
16306,
314,
2559,
199,
363,
1023,
363,
275,
488,
199,
1628,
493,
360,
14759,
362,
15607,
1023,
14,
647,
358,
199,
692,
440,
636,
1023,
10651,
272,
870,
283,
6531,
440,
2342,
636,
1023,
363,
687,
20758,
362,
15607,
1023,
14,
647,
7,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
2758,
8,
272,
536,
534,
38,
3113,
1002,
297,
272,
1015,
18971,
1023,
3108,
221,
327,
4683,
2120,
1443,
5283,
642,
272,
1369,
534,
38,
3113,
1002,
365,
282,
2240,
282,
21538,
370,
6384,
676,
323,
25937,
503,
6661,
1564,
334,
14101,
83,
12,
15329,
2931,
83,
12,
5423,
4959,
283,
355,
283,
504,
3365,
5274,
2839,
30331,
13,
11522,
12,
3517,
13,
5856,
12,
7750,
15424,
436,
1655,
3130,
272,
1846,
63,
1802,
29,
2809,
63,
1802,
12,
272,
4132,
534,
6470,
79,
1804,
79,
1003,
527,
12201,
297,
272,
4132,
63,
2123,
534,
1657,
79,
14,
7697,
1003,
527,
12201,
32,
6799,
14,
957,
297,
272,
4190,
534,
13965,
297,
272,
1166,
534,
1014,
921,
14759,
362,
14,
957,
297,
272,
5235,
63,
633,
534,
1014,
921,
4249,
14,
14759,
362,
14,
957,
297,
272,
3907,
63,
6537,
29,
3174,
63,
6537,
12,
272,
6117,
29,
1623,
63,
5154,
8,
5473,
2968,
2219,
3815,
272,
2559,
63,
576,
29,
1623,
63,
2491,
63,
576,
360,
14759,
362,
297,
2559,
534,
14759,
362,
297,
267,
5760,
2968,
38,
3113,
1002,
14,
5799,
13,
815,
297,
11937,
11357,
995,
267,
1454,
63,
262,
63,
5154,
29,
797,
395,
221,
327,
6944,
26,
314,
5760,
1630,
440,
17021,
370,
1736,
272,
3482,
63,
3489,
29,
797,
12,
272,
511,
63,
5768,
534,
21085,
14,
10946,
297,
272,
13751,
63,
4365,
3126,
267,
283,
5286,
3807,
356,
788,
71,
384,
647,
995,
267,
283,
19011,
34,
356,
788,
647,
15291,
66,
995,
267,
283,
4476,
52,
803,
356,
788,
647,
2676,
708,
995,
267,
283,
31991,
73,
356,
788,
15720,
8119,
16,
14,
23,
297,
283,
23438,
418,
272,
1660,
272,
2397,
63,
3438,
29,
2373,
63,
3438,
12,
272,
19137,
1524,
267,
298,
23753,
9795,
3800,
959,
446,
24114,
15,
933,
461,
401,
267,
298,
3761,
3800,
25718,
26330,
3800,
10697,
844,
401,
267,
298,
23699,
6187,
3800,
4403,
1010,
7106,
401,
267,
298,
11411,
8466,
3800,
2018,
401,
267,
298,
11411,
8466,
3800,
2018,
3800,
499,
401,
267,
298,
11411,
8466,
3800,
2018,
3800,
499,
14,
22,
401,
267,
298,
11411,
8466,
3800,
2018,
3800,
499,
14,
23,
401,
267,
298,
11411,
8466,
3800,
2018,
3800,
24425,
3800,
25654,
401,
267,
298,
11411,
8466,
3800,
2018,
3800,
24425,
3800,
1611,
2713,
401,
272,
1622,
199,
199,
9,
199,
199,
1419,
8,
272,
20536,
773,
29,
34,
4689,
8,
267,
327,
283,
1023,
7,
365,
5120,
465,
18092,
370,
4178,
921,
5031,
14,
957,
15,
387,
422,
15,
387,
422,
15,
10115,
15,
6094,
12,
3254,
26,
2813,
267,
2402,
63,
1725,
2968,
2065,
297,
283,
6836,
297,
283,
1023,
418,
272,
2318,
272,
19128,
29,
34,
4689,
8,
267,
691,
422,
63,
1531,
63,
604,
534,
32176,
7,
272,
2318,
272,
327,
15882,
2828,
14,
387,
422,
1208,
272,
15882,
29,
34,
4689,
0
] |
[
1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
cxxgtxy/tensorflow
|
tensorflow/python/kernel_tests/attention_ops_test.py
|
85
|
7316
|
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for image.extract_glimpse()."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
from tensorflow.python.framework import constant_op
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import image_ops
from tensorflow.python.platform import test
class ExtractGlimpseTest(test.TestCase):
def _VerifyValues(self, tensor_in_sizes, glimpse_sizes, offsets,
expected_rows, expected_cols):
"""Verifies the output values of the glimpse extraction kernel.
Args:
tensor_in_sizes: Input tensor dimensions in [input_rows, input_cols].
glimpse_sizes: Dimensions of the glimpse in [glimpse_rows, glimpse_cols].
offsets: Relative location of the center of the glimpse in the input
image expressed as [row_offset, col_offset].
expected_rows: A list containing the expected row numbers (None for
out of bound entries that are expected to be replaced by uniform
random entries in [0,1) ).
expected_cols: Same as expected_rows, but for column numbers.
"""
rows = tensor_in_sizes[0]
cols = tensor_in_sizes[1]
# Row Tensor with entries by row.
# [[ 1 1 1 ... ]
# [ 2 2 2 ... ]
# [ 3 3 3 ... ]
# [ ...
# ]
t_rows = array_ops.tile(
[[1.0 * r] for r in range(1, rows + 1)], [1, cols], name='tile_rows')
# Shuffle to switch to a convention of (batch_size, height, width, depth).
t_rows_4d = array_ops.transpose(
array_ops.expand_dims(array_ops.expand_dims(t_rows, 0), 3),
[0, 2, 1, 3])
# Column Tensor with entries by column.
# [[ 1 2 3 4 ... ]
# [ 1 2 3 4 ... ]
# [ 1 2 3 4 ... ]
# [ ... ]
# ]
t_cols = array_ops.tile(
[[1.0 * r for r in range(1, cols + 1)]], [rows, 1], name='tile_cols')
# Shuffle to switch to a convention of (batch_size, height, width, depth).
t_cols_4d = array_ops.transpose(
array_ops.expand_dims(array_ops.expand_dims(t_cols, 0), 3),
[0, 2, 1, 3])
# extract_glimpses from Row and Column Tensor, respectively.
# Switch order for glimpse_sizes and offsets to switch from (row, col)
# convention to tensorflows (height, width) convention.
t1 = constant_op.constant([glimpse_sizes[1], glimpse_sizes[0]], shape=[2])
t2 = constant_op.constant([offsets[1], offsets[0]], shape=[1, 2])
glimpse_rows = (array_ops.transpose(
image_ops.extract_glimpse(t_rows_4d, t1, t2), [0, 2, 1, 3]))
glimpse_cols = (array_ops.transpose(
image_ops.extract_glimpse(t_cols_4d, t1, t2), [0, 2, 1, 3]))
# Evaluate the TensorFlow Graph.
with self.test_session() as sess:
value_rows, value_cols = sess.run([glimpse_rows, glimpse_cols])
# Check dimensions of returned glimpse.
self.assertEqual(value_rows.shape[1], glimpse_sizes[0])
self.assertEqual(value_rows.shape[2], glimpse_sizes[1])
self.assertEqual(value_cols.shape[1], glimpse_sizes[0])
self.assertEqual(value_cols.shape[2], glimpse_sizes[1])
# Check entries.
min_random_val = 0
max_random_val = max(rows, cols)
for i in range(glimpse_sizes[0]):
for j in range(glimpse_sizes[1]):
if expected_rows[i] is None or expected_cols[j] is None:
self.assertGreaterEqual(value_rows[0][i][j][0], min_random_val)
self.assertLessEqual(value_rows[0][i][j][0], max_random_val)
self.assertGreaterEqual(value_cols[0][i][j][0], min_random_val)
self.assertLessEqual(value_cols[0][i][j][0], max_random_val)
else:
self.assertEqual(value_rows[0][i][j][0], expected_rows[i])
self.assertEqual(value_cols[0][i][j][0], expected_cols[j])
def testCenterGlimpse(self):
self._VerifyValues(
tensor_in_sizes=[41, 61],
glimpse_sizes=[3, 5],
offsets=[0.0, 0.0],
expected_rows=[20, 21, 22],
expected_cols=[29, 30, 31, 32, 33])
def testEmptyTensor(self):
empty_image = np.zeros((0, 4, 3, 0))
offsets = np.zeros((0, 2))
with self.test_session():
result = image_ops.extract_glimpse(empty_image, [1, 1], offsets)
self.assertAllEqual(
np.zeros(
(0, 1, 1, 0), dtype=np.float32), result.eval())
def testLargeCenterGlimpse(self):
self._VerifyValues(
tensor_in_sizes=[41, 61],
glimpse_sizes=[41, 61],
offsets=[0.0, 0.0],
expected_rows=list(range(1, 42)),
expected_cols=list(range(1, 62)))
def testTooLargeCenterGlimpse(self):
self._VerifyValues(
tensor_in_sizes=[41, 61],
glimpse_sizes=[43, 63],
offsets=[0.0, 0.0],
expected_rows=[None] + list(range(1, 42)) + [None],
expected_cols=[None] + list(range(1, 62)) + [None])
def testGlimpseFullOverlap(self):
self._VerifyValues(
tensor_in_sizes=[41, 61],
glimpse_sizes=[3, 5],
offsets=[0.1, 0.3],
expected_rows=[22, 23, 24],
expected_cols=[38, 39, 40, 41, 42])
def testGlimpseFullOverlap2(self):
self._VerifyValues(
tensor_in_sizes=[41, 61],
glimpse_sizes=[11, 3],
offsets=[-0.7, -0.7],
expected_rows=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
expected_cols=[8, 9, 10])
def testGlimpseBeforeLeftMargin(self):
self._VerifyValues(
tensor_in_sizes=[41, 61],
glimpse_sizes=[11, 5],
offsets=[-0.7, -0.9],
expected_rows=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
expected_cols=[1, 2, 3, 4, 5])
def testGlimpseLowerRightCorner(self):
self._VerifyValues(
tensor_in_sizes=[41, 61],
glimpse_sizes=[7, 5],
offsets=[1.0, 1.0],
expected_rows=[38, 39, 40, 41, None, None, None],
expected_cols=[59, 60, 61, None, None])
def testGlimpseNoOverlap(self):
self._VerifyValues(
tensor_in_sizes=[20, 30],
glimpse_sizes=[3, 3],
offsets=[-2.0, 2.0],
expected_rows=[None, None, None],
expected_cols=[None, None, None])
def testGlimpseOnLeftMargin(self):
self._VerifyValues(
tensor_in_sizes=[41, 61],
glimpse_sizes=[11, 7],
offsets=[-0.7, -1.0],
expected_rows=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
expected_cols=[None, None, None, 1, 2, 3, 4])
def testGlimpseUpperMargin(self):
self._VerifyValues(
tensor_in_sizes=[41, 61],
glimpse_sizes=[7, 5],
offsets=[-1, 0.9],
expected_rows=[None, None, None, 1, 2, 3, 4],
expected_cols=[56, 57, 58, 59, 60])
if __name__ == '__main__':
test.main()
|
apache-2.0
|
[
3,
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
1834,
14,
5005,
63,
71,
317,
311,
261,
20693,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1834,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
12892,
39,
317,
311,
261,
774,
8,
396,
14,
1746,
304,
819,
347,
485,
7496,
6550,
8,
277,
12,
2345,
63,
262,
63,
7723,
12,
486,
317,
311,
261,
63,
7723,
12,
15340,
12,
490,
1420,
63,
3838,
12,
1420,
63,
4574,
304,
272,
408,
21168,
314,
1072,
1338,
402,
314,
486,
317,
311,
261,
19967,
5114,
14,
339,
3033,
26,
489,
2345,
63,
262,
63,
7723,
26,
6924,
2345,
7365,
315,
359,
1210,
63,
3838,
12,
1324,
63,
4574,
1055,
489,
486,
317,
311,
261,
63,
7723,
26,
22089,
1356,
402,
314,
486,
317,
311,
261,
315,
359,
71,
317,
311,
261,
63,
3838,
12,
486,
317,
311,
261,
63,
4574,
1055,
489,
15340,
26,
22419,
2909,
402,
314,
8126,
402,
314,
486,
317,
311,
261,
315,
314,
1324,
267,
1834,
19147,
465,
359,
1143,
63,
2743,
12,
1048,
63,
2743,
1055,
489,
1420,
63,
3838,
26,
437,
769,
3035,
314,
1420,
1962,
5579,
334,
403,
367,
268,
734,
402,
3914,
4811,
626,
787,
1420,
370,
506,
8717,
701,
14818,
268,
2196,
4811,
315,
359,
16,
12,
17,
9,
7092,
489,
1420,
63,
4574,
26,
14766,
465,
1420,
63,
3838,
12,
1325,
367,
2763,
5579,
14,
272,
408,
339,
4730,
275,
2345,
63,
262,
63,
7723,
59,
16,
61,
272,
8850,
275,
2345,
63,
262,
63,
7723,
59,
17,
61,
272,
327,
15231,
5878,
543,
4811,
701,
1962,
14,
272,
327,
3474,
413,
413,
413,
2263,
1622,
272,
327,
221,
359,
499,
499,
499,
2263,
1622,
272,
327,
221,
359,
650,
650,
650,
2263,
1622,
272,
327,
221,
359,
2263,
272,
327,
1622,
272,
307,
63,
3838,
275,
1625,
63,
1483,
14,
7172,
8,
267,
3474,
17,
14,
16,
627,
519,
61,
367,
519,
315,
1425,
8,
17,
12,
4730,
435,
413,
4360,
359,
17,
12,
8850,
467,
536,
534,
7172,
63,
3838,
358,
339,
327,
5244,
6817,
370,
6258,
370,
282,
16129,
402,
334,
2912,
63,
890,
12,
4569,
12,
3462,
12,
5818,
680,
272,
307,
63,
3838,
63,
20,
68,
275,
1625,
63,
1483,
14,
10483,
8,
267,
1625,
63,
1483,
14,
4441,
63,
5380,
8,
1144,
63,
1483,
14,
4441,
63,
5380,
8,
84,
63,
3838,
12,
378,
395,
650,
395,
267,
359,
16,
12,
499,
12,
413,
12,
650,
566,
339,
327,
4996,
5878,
543,
4811,
701,
2763,
14,
272,
327,
3474,
413,
499,
650,
841,
2263,
1622,
272,
327,
221,
359,
413,
499,
650,
841,
2263,
1622,
272,
327,
221,
359,
413,
499,
650,
841,
2263,
1622,
272,
327,
221,
359,
2263,
260,
1622,
272,
327,
1622,
272,
307,
63,
4574,
275,
1625,
63,
1483,
14,
7172,
8,
267,
3474,
17,
14,
16,
627,
519,
367,
519,
315,
1425,
8,
17,
12,
8850,
435,
413,
18037,
359,
3838,
12,
413,
467,
536,
534,
7172,
63,
4574,
358,
339,
327,
5244,
6817,
370,
6258,
370,
282,
16129,
402,
334,
2912,
63,
890,
12,
4569,
12,
3462,
12,
5818,
680,
272,
307,
63,
4574,
63,
20,
68,
275,
1625,
63,
1483,
14,
10483,
8,
267,
1625,
63,
1483,
14,
4441,
63,
5380,
8,
1144,
63,
1483,
14,
4441,
63,
5380,
8,
84,
63,
4574,
12,
378,
395,
650,
395,
267,
359,
16,
12,
499,
12,
413,
12,
650,
566,
339,
327,
5536,
63,
71,
317,
311,
874,
687,
15231,
436,
4996,
5878,
12,
17342,
14,
272,
327,
17711,
1865,
367,
486,
317,
311,
261,
63,
7723,
436,
15340,
370,
6258,
687,
334,
1143,
12,
1048,
9,
272,
327,
16129,
370,
3228,
83,
334,
3333,
12,
3462,
9,
16129,
14,
272,
307,
17,
275,
4413,
63,
411,
14,
4083,
779,
71,
317,
311,
261,
63,
7723,
59,
17,
467,
486,
317,
311,
261,
63,
7723,
59,
16,
2365,
2215,
1524,
18,
566,
272,
307,
18,
275,
4413,
63,
411,
14,
4083,
779,
14253,
59,
17,
467,
15340,
59,
16,
2365,
2215,
1524,
17,
12,
499,
566,
272,
486,
317,
311,
261,
63,
3838,
275,
334,
1144,
63,
1483,
14,
10483,
8,
267,
1834,
63,
1483,
14,
5005,
63,
71,
317,
311,
261,
8,
84,
63,
3838,
63,
20,
68,
12,
307,
17,
12,
307,
18,
395,
359,
16,
12,
499,
12,
413,
12,
650,
2459,
272,
486,
317,
311,
261,
63,
4574,
275,
334,
1144,
63,
1483,
14,
10483,
8,
267,
1834,
63,
1483,
14,
5005,
63,
71,
317,
311,
261,
8,
84,
63,
4574,
63,
20,
68,
12,
307,
17,
12,
307,
18,
395,
359,
16,
12,
499,
12,
413,
12,
650,
2459,
339,
327,
27450,
314,
9134,
11513,
14,
272,
543,
291,
14,
396,
63,
1730,
342,
465,
4043,
26,
489,
574,
63,
3838,
12,
574,
63,
4574,
275,
4043,
14,
1065,
779,
71,
317,
311,
261,
63,
3838,
12,
486,
317,
311,
261,
63,
4574,
566,
339,
327,
2670,
7365,
402,
2138
] |
[
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
1834,
14,
5005,
63,
71,
317,
311,
261,
20693,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1834,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
12892,
39,
317,
311,
261,
774,
8,
396,
14,
1746,
304,
819,
347,
485,
7496,
6550,
8,
277,
12,
2345,
63,
262,
63,
7723,
12,
486,
317,
311,
261,
63,
7723,
12,
15340,
12,
490,
1420,
63,
3838,
12,
1420,
63,
4574,
304,
272,
408,
21168,
314,
1072,
1338,
402,
314,
486,
317,
311,
261,
19967,
5114,
14,
339,
3033,
26,
489,
2345,
63,
262,
63,
7723,
26,
6924,
2345,
7365,
315,
359,
1210,
63,
3838,
12,
1324,
63,
4574,
1055,
489,
486,
317,
311,
261,
63,
7723,
26,
22089,
1356,
402,
314,
486,
317,
311,
261,
315,
359,
71,
317,
311,
261,
63,
3838,
12,
486,
317,
311,
261,
63,
4574,
1055,
489,
15340,
26,
22419,
2909,
402,
314,
8126,
402,
314,
486,
317,
311,
261,
315,
314,
1324,
267,
1834,
19147,
465,
359,
1143,
63,
2743,
12,
1048,
63,
2743,
1055,
489,
1420,
63,
3838,
26,
437,
769,
3035,
314,
1420,
1962,
5579,
334,
403,
367,
268,
734,
402,
3914,
4811,
626,
787,
1420,
370,
506,
8717,
701,
14818,
268,
2196,
4811,
315,
359,
16,
12,
17,
9,
7092,
489,
1420,
63,
4574,
26,
14766,
465,
1420,
63,
3838,
12,
1325,
367,
2763,
5579,
14,
272,
408,
339,
4730,
275,
2345,
63,
262,
63,
7723,
59,
16,
61,
272,
8850,
275,
2345,
63,
262,
63,
7723,
59,
17,
61,
272,
327,
15231,
5878,
543,
4811,
701,
1962,
14,
272,
327,
3474,
413,
413,
413,
2263,
1622,
272,
327,
221,
359,
499,
499,
499,
2263,
1622,
272,
327,
221,
359,
650,
650,
650,
2263,
1622,
272,
327,
221,
359,
2263,
272,
327,
1622,
272,
307,
63,
3838,
275,
1625,
63,
1483,
14,
7172,
8,
267,
3474,
17,
14,
16,
627,
519,
61,
367,
519,
315,
1425,
8,
17,
12,
4730,
435,
413,
4360,
359,
17,
12,
8850,
467,
536,
534,
7172,
63,
3838,
358,
339,
327,
5244,
6817,
370,
6258,
370,
282,
16129,
402,
334,
2912,
63,
890,
12,
4569,
12,
3462,
12,
5818,
680,
272,
307,
63,
3838,
63,
20,
68,
275,
1625,
63,
1483,
14,
10483,
8,
267,
1625,
63,
1483,
14,
4441,
63,
5380,
8,
1144,
63,
1483,
14,
4441,
63,
5380,
8,
84,
63,
3838,
12,
378,
395,
650,
395,
267,
359,
16,
12,
499,
12,
413,
12,
650,
566,
339,
327,
4996,
5878,
543,
4811,
701,
2763,
14,
272,
327,
3474,
413,
499,
650,
841,
2263,
1622,
272,
327,
221,
359,
413,
499,
650,
841,
2263,
1622,
272,
327,
221,
359,
413,
499,
650,
841,
2263,
1622,
272,
327,
221,
359,
2263,
260,
1622,
272,
327,
1622,
272,
307,
63,
4574,
275,
1625,
63,
1483,
14,
7172,
8,
267,
3474,
17,
14,
16,
627,
519,
367,
519,
315,
1425,
8,
17,
12,
8850,
435,
413,
18037,
359,
3838,
12,
413,
467,
536,
534,
7172,
63,
4574,
358,
339,
327,
5244,
6817,
370,
6258,
370,
282,
16129,
402,
334,
2912,
63,
890,
12,
4569,
12,
3462,
12,
5818,
680,
272,
307,
63,
4574,
63,
20,
68,
275,
1625,
63,
1483,
14,
10483,
8,
267,
1625,
63,
1483,
14,
4441,
63,
5380,
8,
1144,
63,
1483,
14,
4441,
63,
5380,
8,
84,
63,
4574,
12,
378,
395,
650,
395,
267,
359,
16,
12,
499,
12,
413,
12,
650,
566,
339,
327,
5536,
63,
71,
317,
311,
874,
687,
15231,
436,
4996,
5878,
12,
17342,
14,
272,
327,
17711,
1865,
367,
486,
317,
311,
261,
63,
7723,
436,
15340,
370,
6258,
687,
334,
1143,
12,
1048,
9,
272,
327,
16129,
370,
3228,
83,
334,
3333,
12,
3462,
9,
16129,
14,
272,
307,
17,
275,
4413,
63,
411,
14,
4083,
779,
71,
317,
311,
261,
63,
7723,
59,
17,
467,
486,
317,
311,
261,
63,
7723,
59,
16,
2365,
2215,
1524,
18,
566,
272,
307,
18,
275,
4413,
63,
411,
14,
4083,
779,
14253,
59,
17,
467,
15340,
59,
16,
2365,
2215,
1524,
17,
12,
499,
566,
272,
486,
317,
311,
261,
63,
3838,
275,
334,
1144,
63,
1483,
14,
10483,
8,
267,
1834,
63,
1483,
14,
5005,
63,
71,
317,
311,
261,
8,
84,
63,
3838,
63,
20,
68,
12,
307,
17,
12,
307,
18,
395,
359,
16,
12,
499,
12,
413,
12,
650,
2459,
272,
486,
317,
311,
261,
63,
4574,
275,
334,
1144,
63,
1483,
14,
10483,
8,
267,
1834,
63,
1483,
14,
5005,
63,
71,
317,
311,
261,
8,
84,
63,
4574,
63,
20,
68,
12,
307,
17,
12,
307,
18,
395,
359,
16,
12,
499,
12,
413,
12,
650,
2459,
339,
327,
27450,
314,
9134,
11513,
14,
272,
543,
291,
14,
396,
63,
1730,
342,
465,
4043,
26,
489,
574,
63,
3838,
12,
574,
63,
4574,
275,
4043,
14,
1065,
779,
71,
317,
311,
261,
63,
3838,
12,
486,
317,
311,
261,
63,
4574,
566,
339,
327,
2670,
7365,
402,
2138,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
DougBurke/astropy
|
astropy/convolution/tests/test_kernel_class.py
|
2
|
19662
|
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import itertools
import pytest
import numpy as np
from numpy.testing import assert_almost_equal, assert_allclose
from ..convolve import convolve, convolve_fft
from ..kernels import (
Gaussian1DKernel, Gaussian2DKernel, Box1DKernel, Box2DKernel,
Trapezoid1DKernel, TrapezoidDisk2DKernel, MexicanHat1DKernel,
Tophat2DKernel, MexicanHat2DKernel, AiryDisk2DKernel, Ring2DKernel,
CustomKernel, Model1DKernel, Model2DKernel, Kernel1D, Kernel2D)
from ..utils import KernelSizeError
from ...modeling.models import Box2D, Gaussian1D, Gaussian2D
from ...utils.exceptions import AstropyDeprecationWarning
from ...tests.helper import catch_warnings
try:
from scipy.ndimage import filters
HAS_SCIPY = True
except ImportError:
HAS_SCIPY = False
WIDTHS_ODD = [3, 5, 7, 9]
WIDTHS_EVEN = [2, 4, 8, 16]
MODES = ['center', 'linear_interp', 'oversample', 'integrate']
KERNEL_TYPES = [Gaussian1DKernel, Gaussian2DKernel,
Box1DKernel, Box2DKernel,
Trapezoid1DKernel, TrapezoidDisk2DKernel,
MexicanHat1DKernel, Tophat2DKernel, AiryDisk2DKernel, Ring2DKernel]
NUMS = [1, 1., np.float32(1.), np.float64(1.)]
# Test data
delta_pulse_1D = np.zeros(81)
delta_pulse_1D[40] = 1
delta_pulse_2D = np.zeros((81, 81))
delta_pulse_2D[40, 40] = 1
random_data_1D = np.random.rand(61)
random_data_2D = np.random.rand(61, 61)
class TestKernels:
"""
Test class for the built-in convolution kernels.
"""
@pytest.mark.skipif('not HAS_SCIPY')
@pytest.mark.parametrize(('width'), WIDTHS_ODD)
def test_scipy_filter_gaussian(self, width):
"""
Test GaussianKernel against SciPy ndimage gaussian filter.
"""
gauss_kernel_1D = Gaussian1DKernel(width)
gauss_kernel_1D.normalize()
gauss_kernel_2D = Gaussian2DKernel(width)
gauss_kernel_2D.normalize()
astropy_1D = convolve(delta_pulse_1D, gauss_kernel_1D, boundary='fill')
astropy_2D = convolve(delta_pulse_2D, gauss_kernel_2D, boundary='fill')
scipy_1D = filters.gaussian_filter(delta_pulse_1D, width)
scipy_2D = filters.gaussian_filter(delta_pulse_2D, width)
assert_almost_equal(astropy_1D, scipy_1D, decimal=12)
assert_almost_equal(astropy_2D, scipy_2D, decimal=12)
@pytest.mark.skipif('not HAS_SCIPY')
@pytest.mark.parametrize(('width'), WIDTHS_ODD)
def test_scipy_filter_gaussian_laplace(self, width):
"""
Test MexicanHat kernels against SciPy ndimage gaussian laplace filters.
"""
mexican_kernel_1D = MexicanHat1DKernel(width)
mexican_kernel_2D = MexicanHat2DKernel(width)
astropy_1D = convolve(delta_pulse_1D, mexican_kernel_1D, boundary='fill', normalize_kernel=False)
astropy_2D = convolve(delta_pulse_2D, mexican_kernel_2D, boundary='fill', normalize_kernel=False)
with pytest.raises(Exception) as exc:
astropy_1D = convolve(delta_pulse_1D, mexican_kernel_1D, boundary='fill', normalize_kernel=True)
assert 'sum is close to zero' in exc.value.args[0]
with pytest.raises(Exception) as exc:
astropy_2D = convolve(delta_pulse_2D, mexican_kernel_2D, boundary='fill', normalize_kernel=True)
assert 'sum is close to zero' in exc.value.args[0]
# The Laplace of Gaussian filter is an inverted Mexican Hat
# filter.
scipy_1D = -filters.gaussian_laplace(delta_pulse_1D, width)
scipy_2D = -filters.gaussian_laplace(delta_pulse_2D, width)
# There is a slight deviation in the normalization. They differ by a
# factor of ~1.0000284132604045. The reason is not known.
assert_almost_equal(astropy_1D, scipy_1D, decimal=5)
assert_almost_equal(astropy_2D, scipy_2D, decimal=5)
@pytest.mark.parametrize(('kernel_type', 'width'), list(itertools.product(KERNEL_TYPES, WIDTHS_ODD)))
def test_delta_data(self, kernel_type, width):
"""
Test smoothing of an image with a single positive pixel
"""
if kernel_type == AiryDisk2DKernel and not HAS_SCIPY:
pytest.skip("Omitting AiryDisk2DKernel, which requires SciPy")
if not kernel_type == Ring2DKernel:
kernel = kernel_type(width)
else:
kernel = kernel_type(width, width * 0.2)
if kernel.dimension == 1:
c1 = convolve_fft(delta_pulse_1D, kernel, boundary='fill', normalize_kernel=False)
c2 = convolve(delta_pulse_1D, kernel, boundary='fill', normalize_kernel=False)
assert_almost_equal(c1, c2, decimal=12)
else:
c1 = convolve_fft(delta_pulse_2D, kernel, boundary='fill', normalize_kernel=False)
c2 = convolve(delta_pulse_2D, kernel, boundary='fill', normalize_kernel=False)
assert_almost_equal(c1, c2, decimal=12)
@pytest.mark.parametrize(('kernel_type', 'width'), list(itertools.product(KERNEL_TYPES, WIDTHS_ODD)))
def test_random_data(self, kernel_type, width):
"""
Test smoothing of an image made of random noise
"""
if kernel_type == AiryDisk2DKernel and not HAS_SCIPY:
pytest.skip("Omitting AiryDisk2DKernel, which requires SciPy")
if not kernel_type == Ring2DKernel:
kernel = kernel_type(width)
else:
kernel = kernel_type(width, width * 0.2)
if kernel.dimension == 1:
c1 = convolve_fft(random_data_1D, kernel, boundary='fill', normalize_kernel=False)
c2 = convolve(random_data_1D, kernel, boundary='fill', normalize_kernel=False)
assert_almost_equal(c1, c2, decimal=12)
else:
c1 = convolve_fft(random_data_2D, kernel, boundary='fill', normalize_kernel=False)
c2 = convolve(random_data_2D, kernel, boundary='fill', normalize_kernel=False)
assert_almost_equal(c1, c2, decimal=12)
@pytest.mark.parametrize(('width'), WIDTHS_ODD)
def test_uniform_smallkernel(self, width):
"""
Test smoothing of an image with a single positive pixel
Instead of using kernel class, uses a simple, small kernel
"""
kernel = np.ones([width, width])
c2 = convolve_fft(delta_pulse_2D, kernel, boundary='fill')
c1 = convolve(delta_pulse_2D, kernel, boundary='fill')
assert_almost_equal(c1, c2, decimal=12)
@pytest.mark.parametrize(('width'), WIDTHS_ODD)
def test_smallkernel_vs_Box2DKernel(self, width):
"""
Test smoothing of an image with a single positive pixel
"""
kernel1 = np.ones([width, width]) / width ** 2
kernel2 = Box2DKernel(width)
c2 = convolve_fft(delta_pulse_2D, kernel2, boundary='fill')
c1 = convolve_fft(delta_pulse_2D, kernel1, boundary='fill')
assert_almost_equal(c1, c2, decimal=12)
def test_convolve_1D_kernels(self):
"""
Check if convolving two kernels with each other works correctly.
"""
gauss_1 = Gaussian1DKernel(3)
gauss_2 = Gaussian1DKernel(4)
test_gauss_3 = Gaussian1DKernel(5)
gauss_3 = convolve(gauss_1, gauss_2)
assert np.all(np.abs((gauss_3 - test_gauss_3).array) < 0.01)
def test_convolve_2D_kernels(self):
"""
Check if convolving two kernels with each other works correctly.
"""
gauss_1 = Gaussian2DKernel(3)
gauss_2 = Gaussian2DKernel(4)
test_gauss_3 = Gaussian2DKernel(5)
gauss_3 = convolve(gauss_1, gauss_2)
assert np.all(np.abs((gauss_3 - test_gauss_3).array) < 0.01)
@pytest.mark.parametrize(('number'), NUMS)
def test_multiply_scalar(self, number):
"""
Check if multiplying a kernel with a scalar works correctly.
"""
gauss = Gaussian1DKernel(3)
gauss_new = number * gauss
assert_almost_equal(gauss_new.array, gauss.array * number, decimal=12)
@pytest.mark.parametrize(('number'), NUMS)
def test_multiply_scalar_type(self, number):
"""
Check if multiplying a kernel with a scalar works correctly.
"""
gauss = Gaussian1DKernel(3)
gauss_new = number * gauss
assert type(gauss_new) is Gaussian1DKernel
@pytest.mark.parametrize(('number'), NUMS)
def test_rmultiply_scalar_type(self, number):
"""
Check if multiplying a kernel with a scalar works correctly.
"""
gauss = Gaussian1DKernel(3)
gauss_new = gauss * number
assert type(gauss_new) is Gaussian1DKernel
def test_multiply_kernel1d(self):
"""Test that multiplying two 1D kernels raises an exception."""
gauss = Gaussian1DKernel(3)
with pytest.raises(Exception):
gauss * gauss
def test_multiply_kernel2d(self):
"""Test that multiplying two 2D kernels raises an exception."""
gauss = Gaussian2DKernel(3)
with pytest.raises(Exception):
gauss * gauss
def test_multiply_kernel1d_kernel2d(self):
"""
Test that multiplying a 1D kernel with a 2D kernel raises an
exception.
"""
with pytest.raises(Exception):
Gaussian1DKernel(3) * Gaussian2DKernel(3)
def test_add_kernel_scalar(self):
"""Test that adding a scalar to a kernel raises an exception."""
with pytest.raises(Exception):
Gaussian1DKernel(3) + 1
def test_model_1D_kernel(self):
"""
Check Model1DKernel against Gaussian1Dkernel
"""
stddev = 5.
gauss = Gaussian1D(1. / np.sqrt(2 * np.pi * stddev**2), 0, stddev)
model_gauss_kernel = Model1DKernel(gauss, x_size=21)
gauss_kernel = Gaussian1DKernel(stddev, x_size=21)
assert_almost_equal(model_gauss_kernel.array, gauss_kernel.array,
decimal=12)
def test_model_2D_kernel(self):
"""
Check Model2DKernel against Gaussian2Dkernel
"""
stddev = 5.
gauss = Gaussian2D(1. / (2 * np.pi * stddev**2), 0, 0, stddev, stddev)
model_gauss_kernel = Model2DKernel(gauss, x_size=21)
gauss_kernel = Gaussian2DKernel(stddev, x_size=21)
assert_almost_equal(model_gauss_kernel.array, gauss_kernel.array,
decimal=12)
def test_custom_1D_kernel(self):
"""
Check CustomKernel against Box1DKernel.
"""
# Define one dimensional array:
array = np.ones(5)
custom = CustomKernel(array)
custom.normalize()
box = Box1DKernel(5)
c2 = convolve(delta_pulse_1D, custom, boundary='fill')
c1 = convolve(delta_pulse_1D, box, boundary='fill')
assert_almost_equal(c1, c2, decimal=12)
def test_custom_2D_kernel(self):
"""
Check CustomKernel against Box2DKernel.
"""
# Define one dimensional array:
array = np.ones((5, 5))
custom = CustomKernel(array)
custom.normalize()
box = Box2DKernel(5)
c2 = convolve(delta_pulse_2D, custom, boundary='fill')
c1 = convolve(delta_pulse_2D, box, boundary='fill')
assert_almost_equal(c1, c2, decimal=12)
def test_custom_1D_kernel_list(self):
"""
Check if CustomKernel works with lists.
"""
custom = CustomKernel([1, 1, 1, 1, 1])
assert custom.is_bool is True
def test_custom_2D_kernel_list(self):
"""
Check if CustomKernel works with lists.
"""
custom = CustomKernel([[1, 1, 1],
[1, 1, 1],
[1, 1, 1]])
assert custom.is_bool is True
def test_custom_1D_kernel_zerosum(self):
"""
Check if CustomKernel works when the input array/list
sums to zero.
"""
array = [-2, -1, 0, 1, 2]
custom = CustomKernel(array)
custom.normalize()
assert custom.truncation == 0.
assert custom._kernel_sum == 0.
def test_custom_2D_kernel_zerosum(self):
"""
Check if CustomKernel works when the input array/list
sums to zero.
"""
array = [[0, -1, 0], [-1, 4, -1], [0, -1, 0]]
custom = CustomKernel(array)
custom.normalize()
assert custom.truncation == 0.
assert custom._kernel_sum == 0.
def test_custom_kernel_odd_error(self):
"""
Check if CustomKernel raises if the array size is odd.
"""
with pytest.raises(KernelSizeError):
CustomKernel([1, 1, 1, 1])
def test_add_1D_kernels(self):
"""
Check if adding of two 1D kernels works.
"""
box_1 = Box1DKernel(5)
box_2 = Box1DKernel(3)
box_3 = Box1DKernel(1)
box_sum_1 = box_1 + box_2 + box_3
box_sum_2 = box_2 + box_3 + box_1
box_sum_3 = box_3 + box_1 + box_2
ref = [1/5., 1/5. + 1/3., 1 + 1/3. + 1/5., 1/5. + 1/3., 1/5.]
assert_almost_equal(box_sum_1.array, ref, decimal=12)
assert_almost_equal(box_sum_2.array, ref, decimal=12)
assert_almost_equal(box_sum_3.array, ref, decimal=12)
# Assert that the kernels haven't changed
assert_almost_equal(box_1.array, [0.2, 0.2, 0.2, 0.2, 0.2], decimal=12)
assert_almost_equal(box_2.array, [1/3., 1/3., 1/3.], decimal=12)
assert_almost_equal(box_3.array, [1], decimal=12)
def test_add_2D_kernels(self):
"""
Check if adding of two 1D kernels works.
"""
box_1 = Box2DKernel(3)
box_2 = Box2DKernel(1)
box_sum_1 = box_1 + box_2
box_sum_2 = box_2 + box_1
ref = [[1 / 9., 1 / 9., 1 / 9.],
[1 / 9., 1 + 1 / 9., 1 / 9.],
[1 / 9., 1 / 9., 1 / 9.]]
ref_1 = [[1 / 9., 1 / 9., 1 / 9.],
[1 / 9., 1 / 9., 1 / 9.],
[1 / 9., 1 / 9., 1 / 9.]]
assert_almost_equal(box_2.array, [[1]], decimal=12)
assert_almost_equal(box_1.array, ref_1, decimal=12)
assert_almost_equal(box_sum_1.array, ref, decimal=12)
assert_almost_equal(box_sum_2.array, ref, decimal=12)
def test_Gaussian1DKernel_even_size(self):
"""
Check if even size for GaussianKernel works.
"""
gauss = Gaussian1DKernel(3, x_size=10)
assert gauss.array.size == 10
def test_Gaussian2DKernel_even_size(self):
"""
Check if even size for GaussianKernel works.
"""
gauss = Gaussian2DKernel(3, x_size=10, y_size=10)
assert gauss.array.shape == (10, 10)
# https://github.com/astropy/astropy/issues/3605
def test_Gaussian2DKernel_rotated(self):
with catch_warnings(AstropyDeprecationWarning) as w:
Gaussian2DKernel(stddev=10)
assert len(w) == 1
gauss = Gaussian2DKernel(
x_stddev=3, y_stddev=1.5, theta=0.7853981633974483,
x_size=5, y_size=5) # rotated 45 deg ccw
ans = [[0.02267712, 0.02464785, 0.02029238, 0.01265463, 0.00597762],
[0.02464785, 0.03164847, 0.03078144, 0.02267712, 0.01265463],
[0.02029238, 0.03078144, 0.03536777, 0.03078144, 0.02029238],
[0.01265463, 0.02267712, 0.03078144, 0.03164847, 0.02464785],
[0.00597762, 0.01265463, 0.02029238, 0.02464785, 0.02267712]]
assert_allclose(gauss, ans, rtol=0.001) # Rough comparison at 0.1 %
def test_normalize_peak(self):
"""
Check if normalize works with peak mode.
"""
custom = CustomKernel([1, 2, 3, 2, 1])
custom.normalize(mode='peak')
assert custom.array.max() == 1
def test_check_kernel_attributes(self):
"""
Check if kernel attributes are correct.
"""
box = Box2DKernel(5)
# Check truncation
assert box.truncation == 0
# Check model
assert isinstance(box.model, Box2D)
# Check center
assert box.center == [2, 2]
# Check normalization
box.normalize()
assert_almost_equal(box._kernel_sum, 1., decimal=12)
# Check separability
assert box.separable
@pytest.mark.parametrize(('kernel_type', 'mode'), list(itertools.product(KERNEL_TYPES, MODES)))
def test_discretize_modes(self, kernel_type, mode):
"""
Check if the different modes result in kernels that work with convolve.
Use only small kernel width, to make the test pass quickly.
"""
if kernel_type == AiryDisk2DKernel and not HAS_SCIPY:
pytest.skip("Omitting AiryDisk2DKernel, which requires SciPy")
if not kernel_type == Ring2DKernel:
kernel = kernel_type(3)
else:
kernel = kernel_type(3, 3 * 0.2)
if kernel.dimension == 1:
c1 = convolve_fft(delta_pulse_1D, kernel, boundary='fill', normalize_kernel=False)
c2 = convolve(delta_pulse_1D, kernel, boundary='fill', normalize_kernel=False)
assert_almost_equal(c1, c2, decimal=12)
else:
c1 = convolve_fft(delta_pulse_2D, kernel, boundary='fill', normalize_kernel=False)
c2 = convolve(delta_pulse_2D, kernel, boundary='fill', normalize_kernel=False)
assert_almost_equal(c1, c2, decimal=12)
@pytest.mark.parametrize(('width'), WIDTHS_EVEN)
def test_box_kernels_even_size(self, width):
"""
Check if BoxKernel work properly with even sizes.
"""
kernel_1D = Box1DKernel(width)
assert kernel_1D.shape[0] % 2 != 0
assert kernel_1D.array.sum() == 1.
kernel_2D = Box2DKernel(width)
assert np.all([_ % 2 != 0 for _ in kernel_2D.shape])
assert kernel_2D.array.sum() == 1.
def test_kernel_normalization(self):
"""
Test that repeated normalizations do not change the kernel [#3747].
"""
kernel = CustomKernel(np.ones(5))
kernel.normalize()
data = np.copy(kernel.array)
kernel.normalize()
assert_allclose(data, kernel.array)
kernel.normalize()
assert_allclose(data, kernel.array)
def test_kernel_normalization_mode(self):
"""
Test that an error is raised if mode is invalid.
"""
with pytest.raises(ValueError):
kernel = CustomKernel(np.ones(3))
kernel.normalize(mode='invalid')
def test_kernel1d_int_size(self):
"""
Test that an error is raised if ``Kernel1D`` ``x_size`` is not
an integer.
"""
with pytest.raises(TypeError):
Gaussian1DKernel(3, x_size=1.2)
def test_kernel2d_int_xsize(self):
"""
Test that an error is raised if ``Kernel2D`` ``x_size`` is not
an integer.
"""
with pytest.raises(TypeError):
Gaussian2DKernel(3, x_size=1.2)
def test_kernel2d_int_ysize(self):
"""
Test that an error is raised if ``Kernel2D`` ``y_size`` is not
an integer.
"""
with pytest.raises(TypeError):
Gaussian2DKernel(3, x_size=5, y_size=1.2)
def test_kernel1d_initialization(self):
"""
Test that an error is raised if an array or model is not
specified for ``Kernel1D``.
"""
with pytest.raises(TypeError):
Kernel1D()
def test_kernel2d_initialization(self):
"""
Test that an error is raised if an array or model is not
specified for ``Kernel2D``.
"""
with pytest.raises(TypeError):
Kernel2D()
|
bsd-3-clause
|
[
3,
3909,
1334,
282,
650,
13,
8501,
6289,
3449,
4190,
446,
1937,
5113,
14,
8332,
199,
199,
646,
7975,
199,
199,
646,
4613,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
702,
63,
4398,
63,
1452,
12,
702,
63,
7520,
199,
199,
504,
2508,
5598,
3344,
492,
8260,
3344,
12,
8260,
3344,
63,
9996,
199,
504,
2508,
29824,
492,
334,
272,
17131,
17,
10892,
11526,
12,
17131,
18,
10892,
11526,
12,
20783,
17,
10892,
11526,
12,
20783,
18,
10892,
11526,
12,
272,
12643,
321,
90,
1170,
17,
10892,
11526,
12,
12643,
321,
90,
1170,
10690,
18,
10892,
11526,
12,
603,
476,
530,
290,
40,
292,
17,
10892,
11526,
12,
272,
14132,
8554,
18,
10892,
11526,
12,
603,
476,
530,
290,
40,
292,
18,
10892,
11526,
12,
437,
73,
651,
10690,
18,
10892,
11526,
12,
820,
316,
18,
10892,
11526,
12,
272,
8388,
14127,
12,
5822,
17,
10892,
11526,
12,
5822,
18,
10892,
11526,
12,
24901,
17,
36,
12,
24901,
18,
36,
9,
199,
199,
504,
2508,
1208,
492,
24901,
2320,
547,
199,
504,
2263,
1238,
316,
14,
992,
492,
20783,
18,
36,
12,
17131,
17,
36,
12,
17131,
18,
36,
199,
504,
2263,
1208,
14,
3924,
492,
31986,
7537,
15561,
199,
504,
2263,
2219,
14,
3676,
492,
8579,
63,
5451,
199,
199,
893,
26,
272,
687,
7026,
14,
78,
23335,
492,
4766,
272,
7509,
63,
5153,
1772,
57,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
5153,
1772,
57,
275,
756,
199,
199,
11139,
51,
63,
47,
5745,
275,
359,
19,
12,
959,
12,
1520,
12,
1749,
61,
199,
11139,
51,
63,
37,
8253,
275,
359,
18,
12,
841,
12,
1695,
12,
3193,
61,
199,
31095,
275,
788,
4218,
297,
283,
6676,
63,
14252,
297,
283,
1883,
3271,
297,
283,
26248,
418,
199,
30142,
63,
7893,
275,
359,
26756,
17,
10892,
11526,
12,
17131,
18,
10892,
11526,
12,
355,
20783,
17,
10892,
11526,
12,
20783,
18,
10892,
11526,
12,
355,
12643,
321,
90,
1170,
17,
10892,
11526,
12,
12643,
321,
90,
1170,
10690,
18,
10892,
11526,
12,
355,
603,
476,
530,
290,
40,
292,
17,
10892,
11526,
12,
14132,
8554,
18,
10892,
11526,
12,
437,
73,
651,
10690,
18,
10892,
11526,
12,
820,
316,
18,
10892,
11526,
61,
421,
199,
1440,
3053,
275,
359,
17,
12,
413,
2020,
980,
14,
1609,
708,
8,
17,
15631,
980,
14,
1609,
772,
8,
17,
14,
1874,
421,
199,
3,
1379,
666,
199,
3136,
63,
19538,
63,
17,
36,
275,
980,
14,
4250,
8,
2835,
9,
199,
3136,
63,
19538,
63,
17,
36,
59,
2167,
61,
275,
413,
199,
199,
3136,
63,
19538,
63,
18,
36,
275,
980,
14,
4250,
1332,
2835,
12,
19071,
430,
199,
3136,
63,
19538,
63,
18,
36,
59,
2167,
12,
6335,
61,
275,
413,
199,
199,
2355,
63,
576,
63,
17,
36,
275,
980,
14,
2355,
14,
3759,
8,
2976,
9,
199,
2355,
63,
576,
63,
18,
36,
275,
980,
14,
2355,
14,
3759,
8,
2976,
12,
17017,
9,
421,
199,
533,
1379,
14127,
83,
26,
272,
408,
272,
1379,
1021,
367,
314,
6137,
13,
262,
17461,
26091,
14,
272,
408,
339,
768,
4462,
14,
1657,
14,
22696,
360,
1397,
7509,
63,
5153,
1772,
57,
358,
272,
768,
4462,
14,
1657,
14,
10396,
4725,
2063,
659,
644,
998,
2080,
51,
63,
47,
5745,
9,
272,
347,
511,
63,
14248,
63,
1541,
63,
22911,
8,
277,
12,
3462,
304,
267,
408,
267,
1379,
17131,
14127,
6169,
16578,
2713,
302,
23335,
28912,
2457,
14,
267,
408,
267,
486,
23822,
63,
4989,
63,
17,
36,
275,
17131,
17,
10892,
11526,
8,
2063,
9,
267,
486,
23822,
63,
4989,
63,
17,
36,
14,
7721,
342,
267,
486,
23822,
63,
4989,
63,
18,
36,
275,
17131,
18,
10892,
11526,
8,
2063,
9,
267,
486,
23822,
63,
4989,
63,
18,
36,
14,
7721,
342,
398,
28753,
63,
17,
36,
275,
8260,
3344,
8,
3136,
63,
19538,
63,
17,
36,
12,
486,
23822,
63,
4989,
63,
17,
36,
12,
8424,
534,
4498,
358,
267,
28753,
63,
18,
36,
275,
8260,
3344,
8,
3136,
63,
19538,
63,
18,
36,
12,
486,
23822,
63,
4989,
63,
18,
36,
12,
8424,
534,
4498,
358,
398,
7026,
63,
17,
36,
275,
4766,
14,
22911,
63,
1541,
8,
3136,
63,
19538,
63,
17,
36,
12,
3462,
9,
267,
7026,
63,
18,
36,
275,
4766,
14,
22911,
63,
1541,
8,
3136,
63,
19538,
63,
18,
36,
12,
3462,
9,
398,
702,
63,
4398,
63,
1452,
8,
1810,
7537,
63,
17,
36,
12,
7026,
63,
17,
36,
12,
6107,
29,
713,
9,
267,
702,
63,
4398,
63,
1452,
8,
1810,
7537,
63,
18,
36,
12,
7026,
63,
18,
36,
12,
6107,
29,
713,
9,
339,
768,
4462,
14,
1657,
14,
22696,
360,
1397,
7509,
63,
5153,
1772,
57,
358,
272,
768,
4462,
14,
1657,
14,
10396,
4725,
2063,
659,
644,
998,
2080,
51,
63,
47,
5745,
9,
272,
347,
511,
63,
14248,
63,
1541,
63,
22911,
63,
416,
2778,
8,
277,
12,
3462,
304,
267,
408,
267,
1379,
603,
476,
530,
290,
40,
292,
26091,
6169,
16578,
2713,
302,
23335,
28912,
1127,
2778,
4766,
14,
267,
408,
267,
562,
88,
530,
290,
63,
4989,
63,
17,
36,
275,
603,
476,
530,
290,
40,
292,
17,
10892,
11526,
8,
2063,
9,
267,
562,
88,
530,
290,
63,
4989,
63,
18,
36,
275,
603,
476,
530,
290,
40,
292,
18,
10892,
11526,
8,
2063,
9,
398,
28753,
63,
17,
36,
275,
8260,
3344,
8,
3136,
63,
19538,
63,
17,
36,
12,
562,
88,
530,
290,
63,
4989,
63,
17,
36,
12,
8424,
534,
4498,
297,
7666,
63,
4989,
29,
797,
9,
267,
28753,
63,
18,
36,
275,
8260,
3344,
8,
3136,
63,
19538,
63,
18,
36,
12,
562,
88,
530,
290,
63,
4989,
63,
18,
36,
12,
8424,
534,
4498,
297,
7666,
63,
4989,
29,
797,
9,
398,
543,
4613,
14,
3536,
8,
1726,
9,
465,
3178,
26,
288,
28753,
63,
17,
36,
275,
8260,
3344,
8,
3136,
63,
19538,
63,
17,
36,
12,
562,
88,
530,
290,
63,
4989,
63,
17,
36,
12,
8424,
534,
4498,
297,
7666,
63,
4989,
29,
549,
9,
267,
702,
283,
1838,
365,
4002,
370,
4697,
7,
315,
3178
] |
[
3909,
1334,
282,
650,
13,
8501,
6289,
3449,
4190,
446,
1937,
5113,
14,
8332,
199,
199,
646,
7975,
199,
199,
646,
4613,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
702,
63,
4398,
63,
1452,
12,
702,
63,
7520,
199,
199,
504,
2508,
5598,
3344,
492,
8260,
3344,
12,
8260,
3344,
63,
9996,
199,
504,
2508,
29824,
492,
334,
272,
17131,
17,
10892,
11526,
12,
17131,
18,
10892,
11526,
12,
20783,
17,
10892,
11526,
12,
20783,
18,
10892,
11526,
12,
272,
12643,
321,
90,
1170,
17,
10892,
11526,
12,
12643,
321,
90,
1170,
10690,
18,
10892,
11526,
12,
603,
476,
530,
290,
40,
292,
17,
10892,
11526,
12,
272,
14132,
8554,
18,
10892,
11526,
12,
603,
476,
530,
290,
40,
292,
18,
10892,
11526,
12,
437,
73,
651,
10690,
18,
10892,
11526,
12,
820,
316,
18,
10892,
11526,
12,
272,
8388,
14127,
12,
5822,
17,
10892,
11526,
12,
5822,
18,
10892,
11526,
12,
24901,
17,
36,
12,
24901,
18,
36,
9,
199,
199,
504,
2508,
1208,
492,
24901,
2320,
547,
199,
504,
2263,
1238,
316,
14,
992,
492,
20783,
18,
36,
12,
17131,
17,
36,
12,
17131,
18,
36,
199,
504,
2263,
1208,
14,
3924,
492,
31986,
7537,
15561,
199,
504,
2263,
2219,
14,
3676,
492,
8579,
63,
5451,
199,
199,
893,
26,
272,
687,
7026,
14,
78,
23335,
492,
4766,
272,
7509,
63,
5153,
1772,
57,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
5153,
1772,
57,
275,
756,
199,
199,
11139,
51,
63,
47,
5745,
275,
359,
19,
12,
959,
12,
1520,
12,
1749,
61,
199,
11139,
51,
63,
37,
8253,
275,
359,
18,
12,
841,
12,
1695,
12,
3193,
61,
199,
31095,
275,
788,
4218,
297,
283,
6676,
63,
14252,
297,
283,
1883,
3271,
297,
283,
26248,
418,
199,
30142,
63,
7893,
275,
359,
26756,
17,
10892,
11526,
12,
17131,
18,
10892,
11526,
12,
355,
20783,
17,
10892,
11526,
12,
20783,
18,
10892,
11526,
12,
355,
12643,
321,
90,
1170,
17,
10892,
11526,
12,
12643,
321,
90,
1170,
10690,
18,
10892,
11526,
12,
355,
603,
476,
530,
290,
40,
292,
17,
10892,
11526,
12,
14132,
8554,
18,
10892,
11526,
12,
437,
73,
651,
10690,
18,
10892,
11526,
12,
820,
316,
18,
10892,
11526,
61,
421,
199,
1440,
3053,
275,
359,
17,
12,
413,
2020,
980,
14,
1609,
708,
8,
17,
15631,
980,
14,
1609,
772,
8,
17,
14,
1874,
421,
199,
3,
1379,
666,
199,
3136,
63,
19538,
63,
17,
36,
275,
980,
14,
4250,
8,
2835,
9,
199,
3136,
63,
19538,
63,
17,
36,
59,
2167,
61,
275,
413,
199,
199,
3136,
63,
19538,
63,
18,
36,
275,
980,
14,
4250,
1332,
2835,
12,
19071,
430,
199,
3136,
63,
19538,
63,
18,
36,
59,
2167,
12,
6335,
61,
275,
413,
199,
199,
2355,
63,
576,
63,
17,
36,
275,
980,
14,
2355,
14,
3759,
8,
2976,
9,
199,
2355,
63,
576,
63,
18,
36,
275,
980,
14,
2355,
14,
3759,
8,
2976,
12,
17017,
9,
421,
199,
533,
1379,
14127,
83,
26,
272,
408,
272,
1379,
1021,
367,
314,
6137,
13,
262,
17461,
26091,
14,
272,
408,
339,
768,
4462,
14,
1657,
14,
22696,
360,
1397,
7509,
63,
5153,
1772,
57,
358,
272,
768,
4462,
14,
1657,
14,
10396,
4725,
2063,
659,
644,
998,
2080,
51,
63,
47,
5745,
9,
272,
347,
511,
63,
14248,
63,
1541,
63,
22911,
8,
277,
12,
3462,
304,
267,
408,
267,
1379,
17131,
14127,
6169,
16578,
2713,
302,
23335,
28912,
2457,
14,
267,
408,
267,
486,
23822,
63,
4989,
63,
17,
36,
275,
17131,
17,
10892,
11526,
8,
2063,
9,
267,
486,
23822,
63,
4989,
63,
17,
36,
14,
7721,
342,
267,
486,
23822,
63,
4989,
63,
18,
36,
275,
17131,
18,
10892,
11526,
8,
2063,
9,
267,
486,
23822,
63,
4989,
63,
18,
36,
14,
7721,
342,
398,
28753,
63,
17,
36,
275,
8260,
3344,
8,
3136,
63,
19538,
63,
17,
36,
12,
486,
23822,
63,
4989,
63,
17,
36,
12,
8424,
534,
4498,
358,
267,
28753,
63,
18,
36,
275,
8260,
3344,
8,
3136,
63,
19538,
63,
18,
36,
12,
486,
23822,
63,
4989,
63,
18,
36,
12,
8424,
534,
4498,
358,
398,
7026,
63,
17,
36,
275,
4766,
14,
22911,
63,
1541,
8,
3136,
63,
19538,
63,
17,
36,
12,
3462,
9,
267,
7026,
63,
18,
36,
275,
4766,
14,
22911,
63,
1541,
8,
3136,
63,
19538,
63,
18,
36,
12,
3462,
9,
398,
702,
63,
4398,
63,
1452,
8,
1810,
7537,
63,
17,
36,
12,
7026,
63,
17,
36,
12,
6107,
29,
713,
9,
267,
702,
63,
4398,
63,
1452,
8,
1810,
7537,
63,
18,
36,
12,
7026,
63,
18,
36,
12,
6107,
29,
713,
9,
339,
768,
4462,
14,
1657,
14,
22696,
360,
1397,
7509,
63,
5153,
1772,
57,
358,
272,
768,
4462,
14,
1657,
14,
10396,
4725,
2063,
659,
644,
998,
2080,
51,
63,
47,
5745,
9,
272,
347,
511,
63,
14248,
63,
1541,
63,
22911,
63,
416,
2778,
8,
277,
12,
3462,
304,
267,
408,
267,
1379,
603,
476,
530,
290,
40,
292,
26091,
6169,
16578,
2713,
302,
23335,
28912,
1127,
2778,
4766,
14,
267,
408,
267,
562,
88,
530,
290,
63,
4989,
63,
17,
36,
275,
603,
476,
530,
290,
40,
292,
17,
10892,
11526,
8,
2063,
9,
267,
562,
88,
530,
290,
63,
4989,
63,
18,
36,
275,
603,
476,
530,
290,
40,
292,
18,
10892,
11526,
8,
2063,
9,
398,
28753,
63,
17,
36,
275,
8260,
3344,
8,
3136,
63,
19538,
63,
17,
36,
12,
562,
88,
530,
290,
63,
4989,
63,
17,
36,
12,
8424,
534,
4498,
297,
7666,
63,
4989,
29,
797,
9,
267,
28753,
63,
18,
36,
275,
8260,
3344,
8,
3136,
63,
19538,
63,
18,
36,
12,
562,
88,
530,
290,
63,
4989,
63,
18,
36,
12,
8424,
534,
4498,
297,
7666,
63,
4989,
29,
797,
9,
398,
543,
4613,
14,
3536,
8,
1726,
9,
465,
3178,
26,
288,
28753,
63,
17,
36,
275,
8260,
3344,
8,
3136,
63,
19538,
63,
17,
36,
12,
562,
88,
530,
290,
63,
4989,
63,
17,
36,
12,
8424,
534,
4498,
297,
7666,
63,
4989,
29,
549,
9,
267,
702,
283,
1838,
365,
4002,
370,
4697,
7,
315,
3178,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
indictranstech/reciphergroup-erpnext
|
erpnext/patches/v5_0/update_item_desc_in_invoice.py
|
96
|
1641
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
import frappe
from frappe.website.utils import find_first_image
from frappe.utils import cstr
import re
def execute():
item_details = frappe._dict()
for d in frappe.db.sql("select name, description, image from `tabItem`", as_dict=1):
description = cstr(d.description).strip()
item_details.setdefault(d.name, frappe._dict({
"description": description,
"image": d.image
}))
dt_list= ["Sales Invoice Item","Purchase Invoice Item"]
for dt in dt_list:
frappe.reload_doctype(dt)
records = frappe.db.sql("""select name, item_code, description from `tab{0}`
where ifnull(item_code, '') != '' and description is not null """.format(dt), as_dict=1)
count = 1
for d in records:
if item_details.get(d.item_code) and cstr(d.description) == item_details.get(d.item_code).description:
desc = item_details.get(d.item_code).description
image = item_details.get(d.item_code).image
else:
desc, image = extract_image_and_description(cstr(d.description))
if not image:
item_detail = item_details.get(d.item_code)
if item_detail:
image = item_detail.image
frappe.db.sql("""update `tab{0}` set description = %s, image = %s
where name = %s """.format(dt), (desc, image, d.name))
count += 1
if count % 500 == 0:
frappe.db.commit()
def extract_image_and_description(data):
image_url = find_first_image(data)
desc = data
for tag in ("img", "table", "tr", "td"):
desc = re.sub("\</*{0}[^>]*\>".format(tag), "", desc)
return desc, image_url
|
agpl-3.0
|
[
3,
1898,
334,
67,
9,
6900,
12,
481,
5034,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
844,
26,
1664,
1696,
1684,
844,
373,
19,
14,
1666,
4190,
14,
2424,
199,
199,
646,
6950,
199,
504,
6950,
14,
7360,
14,
1208,
492,
2342,
63,
2246,
63,
1569,
199,
504,
6950,
14,
1208,
492,
286,
495,
199,
646,
295,
199,
199,
318,
5341,
837,
199,
198,
1053,
63,
5087,
275,
6950,
423,
807,
342,
199,
198,
509,
366,
315,
6950,
14,
697,
14,
3009,
480,
2416,
536,
12,
1369,
12,
1834,
687,
658,
2902,
2081,
64,
401,
465,
63,
807,
29,
17,
304,
507,
198,
1802,
275,
286,
495,
8,
68,
14,
1802,
680,
1913,
342,
507,
198,
1053,
63,
5087,
14,
5486,
8,
68,
14,
354,
12,
6950,
423,
807,
2561,
686,
198,
2,
1802,
582,
1369,
12,
686,
198,
2,
1569,
582,
366,
14,
1569,
507,
198,
12466,
4388,
198,
3583,
63,
513,
29,
2097,
18220,
19868,
7020,
2266,
20486,
19868,
7020,
937,
199,
198,
509,
4487,
315,
4487,
63,
513,
26,
507,
198,
9098,
14,
9233,
63,
6356,
8,
3583,
9,
507,
198,
6502,
275,
6950,
14,
697,
14,
3009,
4852,
2416,
536,
12,
1242,
63,
600,
12,
1369,
687,
658,
2902,
91,
16,
23485,
686,
198,
4509,
340,
2307,
8,
1053,
63,
600,
12,
4074,
1137,
2125,
436,
1369,
365,
440,
2973,
30512,
908,
8,
3583,
395,
465,
63,
807,
29,
17,
9,
2742,
198,
835,
275,
413,
507,
198,
509,
366,
315,
5767,
26,
686,
198,
692,
1242,
63,
5087,
14,
362,
8,
68,
14,
1053,
63,
600,
9,
436,
286,
495,
8,
68,
14,
1802,
9,
508,
1242,
63,
5087,
14,
362,
8,
68,
14,
1053,
63,
600,
680,
1802,
26,
1585,
198,
3257,
275,
1242,
63,
5087,
14,
362,
8,
68,
14,
1053,
63,
600,
680,
1802,
1585,
198,
1569,
275,
1242,
63,
5087,
14,
362,
8,
68,
14,
1053,
63,
600,
680,
1569,
686,
198,
2836,
26,
1585,
198,
3257,
12,
1834,
275,
5536,
63,
1569,
63,
460,
63,
1802,
8,
67,
495,
8,
68,
14,
1802,
430,
1871,
1585,
198,
692,
440,
1834,
26,
1871,
198,
1053,
63,
5506,
275,
1242,
63,
5087,
14,
362,
8,
68,
14,
1053,
63,
600,
9,
1871,
198,
692,
1242,
63,
5506,
26,
4671,
198,
1569,
275,
1242,
63,
5506,
14,
1569,
6319,
198,
9098,
14,
697,
14,
3009,
4852,
873,
658,
2902,
91,
16,
23485,
663,
1369,
275,
450,
83,
12,
1834,
275,
450,
83,
1585,
198,
4509,
536,
275,
450,
83,
30512,
908,
8,
3583,
395,
334,
3257,
12,
1834,
12,
366,
14,
354,
430,
6319,
198,
835,
847,
413,
686,
198,
692,
2338,
450,
6891,
508,
378,
26,
1585,
198,
9098,
14,
697,
14,
3543,
342,
421,
199,
318,
5536,
63,
1569,
63,
460,
63,
1802,
8,
576,
304,
199,
198,
1569,
63,
633,
275,
2342,
63,
2246,
63,
1569,
8,
576,
9,
199,
198,
3257,
275,
666,
199,
198,
509,
1947,
315,
1689,
4060,
401,
298,
1224,
401,
298,
454,
401,
298,
2076,
2349,
507,
198,
3257,
275,
221,
295,
14,
954,
4582,
1108,
10,
91,
16,
93,
17478,
25739,
23167,
908,
8,
1450,
395,
4873,
4328,
9,
199,
198,
1107,
4328,
12,
1834,
63,
633,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
6900,
12,
481,
5034,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
844,
26,
1664,
1696,
1684,
844,
373,
19,
14,
1666,
4190,
14,
2424,
199,
199,
646,
6950,
199,
504,
6950,
14,
7360,
14,
1208,
492,
2342,
63,
2246,
63,
1569,
199,
504,
6950,
14,
1208,
492,
286,
495,
199,
646,
295,
199,
199,
318,
5341,
837,
199,
198,
1053,
63,
5087,
275,
6950,
423,
807,
342,
199,
198,
509,
366,
315,
6950,
14,
697,
14,
3009,
480,
2416,
536,
12,
1369,
12,
1834,
687,
658,
2902,
2081,
64,
401,
465,
63,
807,
29,
17,
304,
507,
198,
1802,
275,
286,
495,
8,
68,
14,
1802,
680,
1913,
342,
507,
198,
1053,
63,
5087,
14,
5486,
8,
68,
14,
354,
12,
6950,
423,
807,
2561,
686,
198,
2,
1802,
582,
1369,
12,
686,
198,
2,
1569,
582,
366,
14,
1569,
507,
198,
12466,
4388,
198,
3583,
63,
513,
29,
2097,
18220,
19868,
7020,
2266,
20486,
19868,
7020,
937,
199,
198,
509,
4487,
315,
4487,
63,
513,
26,
507,
198,
9098,
14,
9233,
63,
6356,
8,
3583,
9,
507,
198,
6502,
275,
6950,
14,
697,
14,
3009,
4852,
2416,
536,
12,
1242,
63,
600,
12,
1369,
687,
658,
2902,
91,
16,
23485,
686,
198,
4509,
340,
2307,
8,
1053,
63,
600,
12,
4074,
1137,
2125,
436,
1369,
365,
440,
2973,
30512,
908,
8,
3583,
395,
465,
63,
807,
29,
17,
9,
2742,
198,
835,
275,
413,
507,
198,
509,
366,
315,
5767,
26,
686,
198,
692,
1242,
63,
5087,
14,
362,
8,
68,
14,
1053,
63,
600,
9,
436,
286,
495,
8,
68,
14,
1802,
9,
508,
1242,
63,
5087,
14,
362,
8,
68,
14,
1053,
63,
600,
680,
1802,
26,
1585,
198,
3257,
275,
1242,
63,
5087,
14,
362,
8,
68,
14,
1053,
63,
600,
680,
1802,
1585,
198,
1569,
275,
1242,
63,
5087,
14,
362,
8,
68,
14,
1053,
63,
600,
680,
1569,
686,
198,
2836,
26,
1585,
198,
3257,
12,
1834,
275,
5536,
63,
1569,
63,
460,
63,
1802,
8,
67,
495,
8,
68,
14,
1802,
430,
1871,
1585,
198,
692,
440,
1834,
26,
1871,
198,
1053,
63,
5506,
275,
1242,
63,
5087,
14,
362,
8,
68,
14,
1053,
63,
600,
9,
1871,
198,
692,
1242,
63,
5506,
26,
4671,
198,
1569,
275,
1242,
63,
5506,
14,
1569,
6319,
198,
9098,
14,
697,
14,
3009,
4852,
873,
658,
2902,
91,
16,
23485,
663,
1369,
275,
450,
83,
12,
1834,
275,
450,
83,
1585,
198,
4509,
536,
275,
450,
83,
30512,
908,
8,
3583,
395,
334,
3257,
12,
1834,
12,
366,
14,
354,
430,
6319,
198,
835,
847,
413,
686,
198,
692,
2338,
450,
6891,
508,
378,
26,
1585,
198,
9098,
14,
697,
14,
3543,
342,
421,
199,
318,
5536,
63,
1569,
63,
460,
63,
1802,
8,
576,
304,
199,
198,
1569,
63,
633,
275,
2342,
63,
2246,
63,
1569,
8,
576,
9,
199,
198,
3257,
275,
666,
199,
198,
509,
1947,
315,
1689,
4060,
401,
298,
1224,
401,
298,
454,
401,
298,
2076,
2349,
507,
198,
3257,
275,
221,
295,
14,
954,
4582,
1108,
10,
91,
16,
93,
17478,
25739,
23167,
908,
8,
1450,
395,
4873,
4328,
9,
199,
198,
1107,
4328,
12,
1834,
63,
633,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
pmav99/FloodMapsWorkshop
|
python/config.py
|
2
|
6005
|
import os
#
# Directories setup
#
DATA_DIR = os.environ['WORKSHOP_DIR'] + "/data"
PYTHON_DIR = os.environ['WORKSHOP_DIR'] + "/python"
#
# Height Above NEarest Drainage (HAND)
#
HANDS_DIR = os.path.join(DATA_DIR, "HAND")
HYDROSHEDS_DIR = os.path.join(DATA_DIR, "HydroSHEDS")
# HAND regional area.
#HANDS_AREA = "haiti"
#HANDS_ZONE = "CA" # Central America
HANDS_AREA = "namibia"
HANDS_ZONE = "AF" # Africa
# Pick 9m or 15m but <= 18m
HANDS_HEIGHT = 9
# S3 bucket to store data and publish it
BUCKET = "ojo-workshop"
regions = {
'd02': {
'name': "Central America",
'bbox': [-92.6833333, 6.1666667, -75.8500000, 19.0833333],
'bucket': "ojo-d2",
'thn_zoom': 5
},
'd03': {
'name': "Hispaniola",
'bbox': [-74.9416667, 16.3500000, -64.9750000, 21.4250000],
'bucket': "ojo-d3",
'thn_zoom': 6
},
'd04': {
'name': "Namibia",
'bbox': [18, -21, 26, -17 ],
'bucket': "ojo-d4",
'thn_zoom': 6
},
'd05': {
'name': "Malawi",
'bbox': [32.717, -17.150, 37.0, -5 ],
'bucket': "ojo-d5",
'thn_zoom': 6
},
'd06': {
'name': "Pakistan",
'bbox': [60, 20, 80, 40 ],
'bucket': "ojo-d6",
'thn_zoom': 6
},
'd07': {
'name': "East Africa",
'bbox': [21.77, -12.27, 51.09, 23.95 ],
'bucket': "ojo-d7",
'thn_zoom': 5
}
}
#
# Data Directories
#
LANDSAT8_DIR = os.path.join(DATA_DIR, "l8")
RADARSAT2_DIR = os.path.join(DATA_DIR, "radarsat2")
MODIS_DIR = os.path.join(DATA_DIR, "modis")
MODIS_ACTIVE_FIRES_DIR = os.path.join(DATA_DIR, "modis_af")
MODIS_BURNEDAREAS_DIR = os.path.join(DATA_DIR, "modis_burnedareas")
EO1_DIR = os.path.join(DATA_DIR, "eo1_ali")
DFO_DIR = os.path.join(DATA_DIR, "dfo")
PALSAR2_DIR = os.path.join(DATA_DIR, "palsar2")
FROST_DIR = os.path.join(DATA_DIR, "frost")
DIGIGLOBE_DIR = os.path.join(DATA_DIR, "digiglobe")
VIIRS_DIR = os.path.join(DATA_DIR, "viirs")
CSV_DIR = os.path.join(DATA_DIR, "csv")
EF5_DIR = os.path.join(DATA_DIR, "ef5")
MAXQ_DIR = os.path.join(DATA_DIR, "maxq")
MAXSWE_DIR = os.path.join(DATA_DIR, "maxswe")
SM_DIR = os.path.join(DATA_DIR, "sm")
TRMM_DIR = os.path.join(DATA_DIR, "trmm_24")
GPM_DIR = os.path.join(DATA_DIR, "gpm_24")
LS_DIR = os.path.join(DATA_DIR, "ls")
QUAKES_DIR = os.path.join(DATA_DIR, "quakes")
VIIRS_CHLA_DIR = os.path.join(DATA_DIR, "viirs_chla")
CHIRPS_PRELIM_DIR = os.path.join(DATA_DIR, "chirps2_prelim")
SRTM2_DIR = "/shared/production/proddata/srtm2"
version = "1.0 alpha3"
profile = 'mercator'
files = []
nodata = None
srs = ""
customsrs = ""
srsformat = 0
tminz = 0
tmaxz = 0
resume = False
kml = False
outputdir = ""
url = "http://" # TODO: Do not submit this to the command-line
viewer_google = False
viewer_openlayers = False
title = ""
copyright = "©"
googlekey = ""
yahookey = ""
documentsdir = ""
bboxgeoref = False
# Placeholder for GetText
def _(str):
return str
# WellKnownGeogCS
wellknowngeogcs = ['WGS84','WGS72','NAD27','NAD83']
# Subset of the GDAL supported file formats...
supportedfiles = "Supported raster files|*.tif;*.tiff;*.kap;*.img;*.sid;*.ecw;*.jp2;*.j2k;*.nitf;*.h1;*.h2;*.hd;*.hdr;*.cit;*.rgb;*.raw;*.blx;*.jpg;*.jpeg;*.png;*.gif;*.bmp;*.wms;*.vrt|" \
"TIFF / BigTIFF / GeoTIFF (.tif)|*.tif;*.tiff|" \
"BSB Nautical Chart Format (.kap)|*.kap|" \
"JPEG2000 - JPEG 2000 (.jp2, .j2k)|*.jp2;*.j2k|" \
"MrSID - Multi-resolution Seamless Image Database (.sid)|*.sid|" \
"ECW - ERMapper Compressed Wavelets (.ecw)|*.ecw|" \
"HFA - Erdas Imagine Images (.img)|*.img|" \
"NITF - National Imagery Transmission Format (.nitf)|*.nitf|" \
"NDF - NLAPS Data Format (.h1,.h2,.hd)|*.h1;*.h2;*.hd|" \
"MFF - Vexcel MFF Raster (.hdr)|*.hdr|" \
"INGR - Intergraph Raster Format (.cit,.rgb,..)|*.cit;*.rgb|" \
"EIR -- Erdas Imagine Raw (.raw)|*.raw|" \
"BLX -- Magellan BLX Topo File Format (.blx)|*.blx|" \
"JPEG - Joint Photographic Experts Group JFIF (.jpg)|*.jpg;*.jpeg|" \
"PNG - Portable Network Graphics (.png)|*.png|" \
"GIF - Graphics Interchange Format (.gif)|*.gif|" \
"BMP - Microsoft Windows Device Independent Bitmap (.bmp)|*.bmp|" \
"WMS - GDAL driver for OGC Web Map Server (.wms)|*.wms|" \
"VRT - GDAL Virtual Raster (.vrt)|*.vrt|" \
"All files (*.*)|*.*"
s = """
srsFormatList = ['format automatically detected',
'WKT - Well Known Text definition',
'ESRI WKT - Well Known Text definition',
'EPSG number',
'EPSGA number',
'Proj.4 definition'
]
"""
srsFormatList = [
'Custom definition of the system (WKT, Proj.4,..)',
'WGS84 - Latitude and longitude (geodetic)',
'Universal Transverse Mercator - UTM (projected)',
'Specify the id-number from the EPSG/ESRI database',
'Search the coordinate system by name',
]
srsFormatListLocal = [
'SRSCustom0',"SRSDefinition0",
'SRSCustom1',"SRSDefinition1",
'SRSCustom2',"SRSDefinition2",
'SRSCustom3',"SRSDefinition3",
'SRSCustom4',"SRSDefinition4",
'SRSCustom5',"SRSDefinition5",
'SRSCustom6',"SRSDefinition6",
'SRSCustom7',"SRSDefinition7",
'SRSCustom8',"SRSDefinition8",
'SRSCustom9',"SRSDefinition9"
]
#English-speaking coordinate systems defaults:
# 'OSGB 1936 / British National Grid (projected)'
# 'NZMG - New Zealand Map Grid'
# ''
#French-speaking coordinate systems defaults:
# Lambert
#German-speaking coordinate systems defaults:
# ...
s = """
#A = wx.PySimpleApp()
#A.SetAppName(VENDOR_NAME)
datadir = wx.StandardPaths.Get().GetUserLocalDataDir()
if not os.path.isdir(datadir):
os.mkdir(datadir)
f = wx.FileConfig(localFilename=os.path.join(datadir,'MapTiler.cfg'))
f.SetPath("APath")
print f.Read("Key")
f.Write("Key", "Value")
f.Flush()
"""
epsg4326 = """GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.01745329251994328,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]]"""
|
apache-2.0
|
[
646,
747,
199,
3,
199,
3,
25596,
4253,
3272,
199,
3,
199,
3998,
63,
3022,
1057,
198,
29,
747,
14,
2314,
459,
8406,
3234,
1938,
63,
3022,
418,
435,
3286,
576,
2,
199,
11720,
63,
3022,
1057,
198,
29,
747,
14,
2314,
459,
8406,
3234,
1938,
63,
3022,
418,
435,
3286,
1548,
2,
199,
3,
199,
3,
5311,
1070,
437,
3395,
7110,
9540,
577,
6322,
474,
334,
10854,
9,
199,
3,
199,
40,
20033,
63,
3022,
1057,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
10854,
531,
199,
16255,
36,
1092,
3234,
1149,
51,
63,
3022,
198,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
21568,
17264,
3234,
1149,
51,
531,
199,
199,
3,
23276,
4897,
279,
9150,
14,
199,
3,
40,
20033,
63,
28591,
1057,
198,
29,
298,
2411,
5277,
2,
199,
3,
40,
20033,
63,
15353,
1057,
198,
29,
298,
3263,
2,
198,
198,
3,
32267,
9117,
437,
8534,
199,
40,
20033,
63,
28591,
1057,
198,
29,
298,
17811,
1892,
4674,
2,
199,
40,
20033,
63,
15353,
1057,
198,
29,
298,
5699,
2,
198,
198,
3,
437,
70,
7127,
199,
199,
3,
16568,
1749,
77,
503,
4114,
77,
1325,
2695,
6155,
77,
199,
40,
20033,
63,
13509,
198,
198,
29,
1749,
199,
199,
3,
428,
19,
5315,
370,
3877,
666,
436,
2780,
652,
199,
20156,
9622,
198,
29,
298,
79,
743,
13,
800,
10568,
2,
199,
199,
11963,
198,
198,
29,
469,
199,
198,
5121,
996,
356,
469,
507,
198,
7,
354,
356,
1057,
198,
2,
25290,
437,
8534,
401,
507,
198,
7,
11246,
356,
22427,
198,
1988,
2942,
14,
2333,
6772,
19,
12,
257,
1227,
14,
975,
6997,
23,
12,
446,
2194,
14,
2426,
5345,
12,
221,
5851,
14,
2036,
6772,
19,
467,
507,
198,
7,
4623,
356,
198,
198,
2,
79,
743,
13,
68,
18,
401,
507,
198,
1133,
6164,
63,
10598,
356,
221,
198,
21,
199,
198,
1386,
199,
198,
5121,
1644,
356,
469,
507,
198,
7,
354,
356,
1057,
198,
2,
40,
374,
10384,
73,
22205,
401,
507,
198,
7,
11246,
356,
22427,
198,
1988,
1342,
14,
2635,
975,
14916,
12,
3193,
14,
1276,
5345,
12,
446,
772,
14,
28947,
993,
12,
221,
7829,
14,
24398,
993,
467,
507,
198,
7,
4623,
356,
198,
198,
2,
79,
743,
13,
68,
19,
401,
507,
198,
1133,
6164,
63,
10598,
356,
221,
198,
22,
199,
198,
1386,
199,
198,
5121,
966,
356,
469,
507,
198,
7,
354,
356,
1057,
198,
2,
46,
455,
1892,
4674,
401,
507,
198,
7,
11246,
356,
22427,
198,
59,
1085,
12,
446,
2025,
12,
7875,
12,
446,
1196,
2156,
507,
198,
7,
4623,
356,
198,
198,
2,
79,
743,
13,
68,
20,
401,
507,
198,
1133,
6164,
63,
10598,
356,
221,
198,
22,
199,
198,
1386,
199,
198,
5121,
1717,
356,
469,
507,
198,
7,
354,
356,
1057,
198,
2,
31147,
10084,
73,
401,
507,
198,
7,
11246,
356,
22427,
198,
59,
708,
14,
31462,
12,
446,
1196,
14,
8251,
12,
6877,
14,
16,
12,
446,
21,
2156,
507,
198,
7,
4623,
356,
198,
198,
2,
79,
743,
13,
68,
21,
401,
507,
198,
1133,
6164,
63,
10598,
356,
221,
198,
22,
199,
198,
1386,
199,
198,
5121,
1690,
356,
469,
507,
198,
7,
354,
356,
1057,
198,
2,
48,
1151,
631,
290,
401,
507,
198,
7,
11246,
356,
22427,
198,
59,
2259,
12,
3388,
12,
5939,
12,
6335,
2156,
507,
198,
7,
4623,
356,
198,
198,
2,
79,
743,
13,
68,
22,
401,
507,
198,
1133,
6164,
63,
10598,
356,
221,
198,
22,
199,
198,
1386,
199,
198,
5121,
1780,
356,
469,
507,
198,
7,
354,
356,
1057,
198,
2,
37,
1810,
437,
70,
7127,
401,
507,
198,
7,
11246,
356,
22427,
198,
59,
2025,
14,
1138,
12,
446,
713,
14,
1465,
12,
8026,
14,
1643,
12,
6546,
14,
2720,
2156,
507,
198,
7,
4623,
356,
198,
198,
2,
79,
743,
13,
68,
23,
401,
507,
198,
1133,
6164,
63,
10598,
356,
221,
198,
21,
18118,
198,
93,
199,
93,
507,
199,
3,
199,
3,
3918,
25596,
4253,
199,
3,
199,
10825,
3177,
619,
24,
63,
3022,
9622,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
76,
24,
531,
199,
19662,
689,
51,
619,
18,
63,
3022,
9622,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
9525,
4291,
292,
18,
531,
199,
2679,
6178,
63,
3022,
7542,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
573,
2297,
531,
199,
2679,
6178,
63,
10401,
63,
1976,
3830,
63,
3022,
198,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
573,
2297,
63,
2756,
531,
199,
2679,
6178,
63,
34,
7648,
1149,
8693,
1179,
63,
3022,
198,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
573,
2297,
63,
30736,
379,
32354,
531,
199,
15471,
17,
63,
3022,
27997,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
20805,
17,
63,
10874,
531,
199,
36,
3230,
63,
3022,
27997,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
68,
545,
531,
199,
20990,
51,
689,
18,
63,
3022,
7542,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
80,
2551,
285,
18,
531,
199,
38,
1092,
840,
63,
3022,
7542,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
21775,
270,
531,
199,
22855,
1277,
1484,
6773,
63,
3022,
9622,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
18367,
528,
1191,
69,
531,
199,
17655,
3927,
51,
63,
3022,
7542,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
433,
32030,
531,
199,
19018,
63,
3022,
27997,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
4737,
531,
199,
14153,
21,
63,
3022,
27997,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
2829,
21,
531,
199,
4283,
49,
63,
3022,
7542,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
988,
81,
531,
199,
4283
] |
[
747,
199,
3,
199,
3,
25596,
4253,
3272,
199,
3,
199,
3998,
63,
3022,
1057,
198,
29,
747,
14,
2314,
459,
8406,
3234,
1938,
63,
3022,
418,
435,
3286,
576,
2,
199,
11720,
63,
3022,
1057,
198,
29,
747,
14,
2314,
459,
8406,
3234,
1938,
63,
3022,
418,
435,
3286,
1548,
2,
199,
3,
199,
3,
5311,
1070,
437,
3395,
7110,
9540,
577,
6322,
474,
334,
10854,
9,
199,
3,
199,
40,
20033,
63,
3022,
1057,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
10854,
531,
199,
16255,
36,
1092,
3234,
1149,
51,
63,
3022,
198,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
21568,
17264,
3234,
1149,
51,
531,
199,
199,
3,
23276,
4897,
279,
9150,
14,
199,
3,
40,
20033,
63,
28591,
1057,
198,
29,
298,
2411,
5277,
2,
199,
3,
40,
20033,
63,
15353,
1057,
198,
29,
298,
3263,
2,
198,
198,
3,
32267,
9117,
437,
8534,
199,
40,
20033,
63,
28591,
1057,
198,
29,
298,
17811,
1892,
4674,
2,
199,
40,
20033,
63,
15353,
1057,
198,
29,
298,
5699,
2,
198,
198,
3,
437,
70,
7127,
199,
199,
3,
16568,
1749,
77,
503,
4114,
77,
1325,
2695,
6155,
77,
199,
40,
20033,
63,
13509,
198,
198,
29,
1749,
199,
199,
3,
428,
19,
5315,
370,
3877,
666,
436,
2780,
652,
199,
20156,
9622,
198,
29,
298,
79,
743,
13,
800,
10568,
2,
199,
199,
11963,
198,
198,
29,
469,
199,
198,
5121,
996,
356,
469,
507,
198,
7,
354,
356,
1057,
198,
2,
25290,
437,
8534,
401,
507,
198,
7,
11246,
356,
22427,
198,
1988,
2942,
14,
2333,
6772,
19,
12,
257,
1227,
14,
975,
6997,
23,
12,
446,
2194,
14,
2426,
5345,
12,
221,
5851,
14,
2036,
6772,
19,
467,
507,
198,
7,
4623,
356,
198,
198,
2,
79,
743,
13,
68,
18,
401,
507,
198,
1133,
6164,
63,
10598,
356,
221,
198,
21,
199,
198,
1386,
199,
198,
5121,
1644,
356,
469,
507,
198,
7,
354,
356,
1057,
198,
2,
40,
374,
10384,
73,
22205,
401,
507,
198,
7,
11246,
356,
22427,
198,
1988,
1342,
14,
2635,
975,
14916,
12,
3193,
14,
1276,
5345,
12,
446,
772,
14,
28947,
993,
12,
221,
7829,
14,
24398,
993,
467,
507,
198,
7,
4623,
356,
198,
198,
2,
79,
743,
13,
68,
19,
401,
507,
198,
1133,
6164,
63,
10598,
356,
221,
198,
22,
199,
198,
1386,
199,
198,
5121,
966,
356,
469,
507,
198,
7,
354,
356,
1057,
198,
2,
46,
455,
1892,
4674,
401,
507,
198,
7,
11246,
356,
22427,
198,
59,
1085,
12,
446,
2025,
12,
7875,
12,
446,
1196,
2156,
507,
198,
7,
4623,
356,
198,
198,
2,
79,
743,
13,
68,
20,
401,
507,
198,
1133,
6164,
63,
10598,
356,
221,
198,
22,
199,
198,
1386,
199,
198,
5121,
1717,
356,
469,
507,
198,
7,
354,
356,
1057,
198,
2,
31147,
10084,
73,
401,
507,
198,
7,
11246,
356,
22427,
198,
59,
708,
14,
31462,
12,
446,
1196,
14,
8251,
12,
6877,
14,
16,
12,
446,
21,
2156,
507,
198,
7,
4623,
356,
198,
198,
2,
79,
743,
13,
68,
21,
401,
507,
198,
1133,
6164,
63,
10598,
356,
221,
198,
22,
199,
198,
1386,
199,
198,
5121,
1690,
356,
469,
507,
198,
7,
354,
356,
1057,
198,
2,
48,
1151,
631,
290,
401,
507,
198,
7,
11246,
356,
22427,
198,
59,
2259,
12,
3388,
12,
5939,
12,
6335,
2156,
507,
198,
7,
4623,
356,
198,
198,
2,
79,
743,
13,
68,
22,
401,
507,
198,
1133,
6164,
63,
10598,
356,
221,
198,
22,
199,
198,
1386,
199,
198,
5121,
1780,
356,
469,
507,
198,
7,
354,
356,
1057,
198,
2,
37,
1810,
437,
70,
7127,
401,
507,
198,
7,
11246,
356,
22427,
198,
59,
2025,
14,
1138,
12,
446,
713,
14,
1465,
12,
8026,
14,
1643,
12,
6546,
14,
2720,
2156,
507,
198,
7,
4623,
356,
198,
198,
2,
79,
743,
13,
68,
23,
401,
507,
198,
1133,
6164,
63,
10598,
356,
221,
198,
21,
18118,
198,
93,
199,
93,
507,
199,
3,
199,
3,
3918,
25596,
4253,
199,
3,
199,
10825,
3177,
619,
24,
63,
3022,
9622,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
76,
24,
531,
199,
19662,
689,
51,
619,
18,
63,
3022,
9622,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
9525,
4291,
292,
18,
531,
199,
2679,
6178,
63,
3022,
7542,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
573,
2297,
531,
199,
2679,
6178,
63,
10401,
63,
1976,
3830,
63,
3022,
198,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
573,
2297,
63,
2756,
531,
199,
2679,
6178,
63,
34,
7648,
1149,
8693,
1179,
63,
3022,
198,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
573,
2297,
63,
30736,
379,
32354,
531,
199,
15471,
17,
63,
3022,
27997,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
20805,
17,
63,
10874,
531,
199,
36,
3230,
63,
3022,
27997,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
68,
545,
531,
199,
20990,
51,
689,
18,
63,
3022,
7542,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
80,
2551,
285,
18,
531,
199,
38,
1092,
840,
63,
3022,
7542,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
21775,
270,
531,
199,
22855,
1277,
1484,
6773,
63,
3022,
9622,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
18367,
528,
1191,
69,
531,
199,
17655,
3927,
51,
63,
3022,
7542,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
433,
32030,
531,
199,
19018,
63,
3022,
27997,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
4737,
531,
199,
14153,
21,
63,
3022,
27997,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
2829,
21,
531,
199,
4283,
49,
63,
3022,
7542,
198,
29,
747,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
298,
988,
81,
531,
199,
4283,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
rooi/CouchPotatoServer
|
couchpotato/core/plugins/browser/main.py
|
10
|
3390
|
from couchpotato.api import addApiView
from couchpotato.core.helpers.variable import getUserDir
from couchpotato.core.plugins.base import Plugin
import ctypes
import os
import string
if os.name == 'nt':
import imp
try:
imp.find_module('win32file')
except:
# todo:: subclass ImportError for missing dependencies, vs. broken plugins?
raise ImportError("Missing the win32file module, which is a part of the prerequisite \
pywin32 package. You can get it from http://sourceforge.net/projects/pywin32/files/pywin32/")
else:
import win32file #@UnresolvedImport
class FileBrowser(Plugin):
def __init__(self):
addApiView('directory.list', self.view, docs = {
'desc': 'Return the directory list of a given directory',
'params': {
'path': {'desc': 'The directory to scan'},
'show_hidden': {'desc': 'Also show hidden files'}
},
'return': {'type': 'object', 'example': """{
'is_root': bool, //is top most folder
'parent': string, //parent folder of requested path
'home': string, //user home folder
'empty': bool, //directory is empty
'dirs': array, //directory names
}"""}
})
def getDirectories(self, path = '/', show_hidden = True):
# Return driveletters or root if path is empty
if path == '/' or not path or path == '\\':
if os.name == 'nt':
return self.getDriveLetters()
path = '/'
dirs = []
for f in os.listdir(path):
p = os.path.join(path, f)
if os.path.isdir(p) and ((self.is_hidden(p) and bool(int(show_hidden))) or not self.is_hidden(p)):
dirs.append(p + os.path.sep)
return sorted(dirs)
def getFiles(self):
pass
def getDriveLetters(self):
driveletters = []
for drive in string.ascii_uppercase:
if win32file.GetDriveType(drive + ":") in [win32file.DRIVE_FIXED, win32file.DRIVE_REMOTE, win32file.DRIVE_RAMDISK, win32file.DRIVE_REMOVABLE]:
driveletters.append(drive + ":\\")
return driveletters
def view(self, path = '/', show_hidden = True, **kwargs):
home = getUserDir()
if not path:
path = home
try:
dirs = self.getDirectories(path = path, show_hidden = show_hidden)
except:
dirs = []
parent = os.path.dirname(path.rstrip(os.path.sep))
if parent == path.rstrip(os.path.sep):
parent = '/'
elif parent != '/' and parent[-2:] != ':\\':
parent += os.path.sep
return {
'is_root': path == '/',
'empty': len(dirs) == 0,
'parent': parent,
'home': home + os.path.sep,
'platform': os.name,
'dirs': dirs,
}
def is_hidden(self, filepath):
name = os.path.basename(os.path.abspath(filepath))
return name.startswith('.') or self.has_hidden_attribute(filepath)
def has_hidden_attribute(self, filepath):
try:
attrs = ctypes.windll.kernel32.GetFileAttributesW(unicode(filepath)) #@UndefinedVariable
assert attrs != -1
result = bool(attrs & 2)
except (AttributeError, AssertionError):
result = False
return result
|
gpl-3.0
|
[
504,
28877,
30780,
14,
1246,
492,
1050,
7394,
2768,
199,
504,
28877,
30780,
14,
1018,
14,
7546,
14,
1975,
492,
664,
1899,
3567,
199,
504,
28877,
30780,
14,
1018,
14,
5265,
14,
1095,
492,
11349,
199,
646,
5577,
199,
646,
747,
199,
646,
1059,
199,
199,
692,
747,
14,
354,
508,
283,
343,
356,
272,
492,
1742,
272,
862,
26,
267,
1742,
14,
1623,
63,
578,
360,
2676,
708,
493,
358,
272,
871,
26,
267,
327,
11386,
447,
5516,
3545,
367,
4124,
5124,
12,
8118,
14,
10529,
8963,
31,
267,
746,
3545,
480,
7718,
314,
4747,
708,
493,
859,
12,
1314,
365,
282,
1777,
402,
314,
876,
21763,
971,
288,
1134,
2676,
708,
2559,
14,
2047,
883,
664,
652,
687,
1455,
921,
22943,
14,
846,
15,
6776,
15,
647,
2676,
708,
15,
1725,
15,
647,
2676,
708,
13589,
272,
587,
26,
267,
492,
4747,
708,
493,
9213,
1358,
13697,
6295,
199,
199,
533,
3814,
11930,
8,
5061,
304,
339,
347,
636,
826,
721,
277,
304,
267,
1050,
7394,
2768,
360,
3619,
14,
513,
297,
291,
14,
1345,
12,
9149,
275,
469,
288,
283,
3257,
356,
283,
1767,
314,
2082,
769,
402,
282,
1627,
2082,
297,
288,
283,
1162,
356,
469,
355,
283,
515,
356,
791,
3257,
356,
283,
1918,
2082,
370,
8000,
2267,
355,
283,
2384,
63,
5642,
356,
791,
3257,
356,
283,
31892,
2498,
8752,
1584,
936,
288,
1660,
288,
283,
1107,
356,
791,
466,
356,
283,
785,
297,
283,
2694,
356,
408,
91,
272,
283,
374,
63,
1231,
356,
2155,
12,
5001,
374,
2746,
4750,
4922,
272,
283,
1708,
356,
1059,
12,
5001,
1708,
4922,
402,
5839,
931,
272,
283,
4219,
356,
1059,
12,
5001,
751,
5629,
4922,
272,
283,
1667,
356,
2155,
12,
5001,
3619,
365,
2701,
272,
283,
3220,
356,
1625,
12,
5001,
3619,
1561,
199,
30437,
93,
267,
3828,
339,
347,
664,
13752,
8,
277,
12,
931,
275,
17220,
2498,
63,
5642,
275,
715,
304,
398,
327,
1432,
12912,
16415,
503,
1738,
340,
931,
365,
2701,
267,
340,
931,
508,
7324,
503,
440,
931,
503,
931,
508,
29082,
288,
340,
747,
14,
354,
508,
283,
343,
356,
355,
372,
291,
14,
362,
24276,
28760,
342,
288,
931,
275,
7324,
398,
7606,
275,
942,
267,
367,
289,
315,
747,
14,
7374,
8,
515,
304,
288,
299,
275,
747,
14,
515,
14,
904,
8,
515,
12,
289,
9,
288,
340,
747,
14,
515,
14,
6027,
8,
80,
9,
436,
3666,
277,
14,
374,
63,
5642,
8,
80,
9,
436,
2155,
8,
442,
8,
2384,
63,
5642,
1724,
503,
440,
291,
14,
374,
63,
5642,
8,
80,
2298,
355,
7606,
14,
740,
8,
80,
435,
747,
14,
515,
14,
4127,
9,
398,
372,
3355,
8,
3220,
9,
339,
347,
664,
5535,
8,
277,
304,
267,
986,
339,
347,
664,
24276,
28760,
8,
277,
304,
398,
12912,
16415,
275,
942,
267,
367,
12912,
315,
1059,
14,
4371,
63,
26831,
26,
288,
340,
4747,
708,
493,
14,
1002,
24276,
804,
8,
9541,
435,
7244,
531,
315,
359,
2676,
708,
493,
14,
4564,
5399,
63,
23837,
12,
4747,
708,
493,
14,
4564,
5399,
63,
16058,
12,
4747,
708,
493,
14,
4564,
5399,
63,
30839,
20492,
12,
4747,
708,
493,
14,
4564,
5399,
63,
907,
24321,
2617,
2189,
355,
12912,
16415,
14,
740,
8,
9541,
435,
7244,
1103,
531,
398,
372,
12912,
16415,
339,
347,
2455,
8,
277,
12,
931,
275,
17220,
2498,
63,
5642,
275,
715,
12,
1011,
958,
304,
398,
5629,
275,
664,
1899,
3567,
342,
398,
340,
440,
931,
26,
288,
931,
275,
5629,
398,
862,
26,
288,
7606,
275,
291,
14,
362,
13752,
8,
515,
275,
931,
12,
2498,
63,
5642,
275,
2498,
63,
5642,
9,
267,
871,
26,
288,
7606,
275,
942,
398,
1676,
275,
747,
14,
515,
14,
3475,
8,
515,
14,
6735,
8,
736,
14,
515,
14,
4127,
430,
267,
340,
1676,
508,
931,
14,
6735,
8,
736,
14,
515,
14,
4127,
304,
288,
1676,
275,
7324,
267,
916,
1676,
1137,
7324,
436,
1676,
1988,
18,
2938,
1137,
7596,
1103,
356,
288,
1676,
847,
747,
14,
515,
14,
4127,
398,
372,
469,
288,
283,
374,
63,
1231,
356,
931,
508,
17220,
288,
283,
1667,
356,
822,
8,
3220,
9,
508,
378,
12,
288,
283,
1708,
356,
1676,
12,
288,
283,
4219,
356,
5629,
435,
747,
14,
515,
14,
4127,
12,
288,
283,
3246,
356,
747,
14,
354,
12,
288,
283,
3220,
356,
7606,
12,
267,
789,
2378,
347,
365,
63,
5642,
8,
277,
12,
9911,
304,
267,
536,
275,
747,
14,
515,
14,
4846,
8,
736,
14,
515,
14,
4832,
8,
7218,
430,
267,
372,
536,
14,
2460,
7563,
503,
291,
14,
1989,
63,
5642,
63,
3215,
8,
7218,
9,
339,
347,
965,
63,
5642,
63,
3215,
8,
277,
12,
9911,
304,
267,
862,
26,
288,
3290,
275,
5577,
14,
25522,
14,
4989,
708,
14,
26535,
5379,
55,
8,
2975,
8,
7218,
430,
9213,
16283,
2773,
288,
702,
3290,
1137,
446,
17,
288,
754,
275,
2155,
8,
3288,
1253,
499,
9,
267,
871,
334,
10227,
12,
9070,
304,
288,
754,
275,
756,
267,
372,
754,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
28877,
30780,
14,
1246,
492,
1050,
7394,
2768,
199,
504,
28877,
30780,
14,
1018,
14,
7546,
14,
1975,
492,
664,
1899,
3567,
199,
504,
28877,
30780,
14,
1018,
14,
5265,
14,
1095,
492,
11349,
199,
646,
5577,
199,
646,
747,
199,
646,
1059,
199,
199,
692,
747,
14,
354,
508,
283,
343,
356,
272,
492,
1742,
272,
862,
26,
267,
1742,
14,
1623,
63,
578,
360,
2676,
708,
493,
358,
272,
871,
26,
267,
327,
11386,
447,
5516,
3545,
367,
4124,
5124,
12,
8118,
14,
10529,
8963,
31,
267,
746,
3545,
480,
7718,
314,
4747,
708,
493,
859,
12,
1314,
365,
282,
1777,
402,
314,
876,
21763,
971,
288,
1134,
2676,
708,
2559,
14,
2047,
883,
664,
652,
687,
1455,
921,
22943,
14,
846,
15,
6776,
15,
647,
2676,
708,
15,
1725,
15,
647,
2676,
708,
13589,
272,
587,
26,
267,
492,
4747,
708,
493,
9213,
1358,
13697,
6295,
199,
199,
533,
3814,
11930,
8,
5061,
304,
339,
347,
636,
826,
721,
277,
304,
267,
1050,
7394,
2768,
360,
3619,
14,
513,
297,
291,
14,
1345,
12,
9149,
275,
469,
288,
283,
3257,
356,
283,
1767,
314,
2082,
769,
402,
282,
1627,
2082,
297,
288,
283,
1162,
356,
469,
355,
283,
515,
356,
791,
3257,
356,
283,
1918,
2082,
370,
8000,
2267,
355,
283,
2384,
63,
5642,
356,
791,
3257,
356,
283,
31892,
2498,
8752,
1584,
936,
288,
1660,
288,
283,
1107,
356,
791,
466,
356,
283,
785,
297,
283,
2694,
356,
408,
91,
272,
283,
374,
63,
1231,
356,
2155,
12,
5001,
374,
2746,
4750,
4922,
272,
283,
1708,
356,
1059,
12,
5001,
1708,
4922,
402,
5839,
931,
272,
283,
4219,
356,
1059,
12,
5001,
751,
5629,
4922,
272,
283,
1667,
356,
2155,
12,
5001,
3619,
365,
2701,
272,
283,
3220,
356,
1625,
12,
5001,
3619,
1561,
199,
30437,
93,
267,
3828,
339,
347,
664,
13752,
8,
277,
12,
931,
275,
17220,
2498,
63,
5642,
275,
715,
304,
398,
327,
1432,
12912,
16415,
503,
1738,
340,
931,
365,
2701,
267,
340,
931,
508,
7324,
503,
440,
931,
503,
931,
508,
29082,
288,
340,
747,
14,
354,
508,
283,
343,
356,
355,
372,
291,
14,
362,
24276,
28760,
342,
288,
931,
275,
7324,
398,
7606,
275,
942,
267,
367,
289,
315,
747,
14,
7374,
8,
515,
304,
288,
299,
275,
747,
14,
515,
14,
904,
8,
515,
12,
289,
9,
288,
340,
747,
14,
515,
14,
6027,
8,
80,
9,
436,
3666,
277,
14,
374,
63,
5642,
8,
80,
9,
436,
2155,
8,
442,
8,
2384,
63,
5642,
1724,
503,
440,
291,
14,
374,
63,
5642,
8,
80,
2298,
355,
7606,
14,
740,
8,
80,
435,
747,
14,
515,
14,
4127,
9,
398,
372,
3355,
8,
3220,
9,
339,
347,
664,
5535,
8,
277,
304,
267,
986,
339,
347,
664,
24276,
28760,
8,
277,
304,
398,
12912,
16415,
275,
942,
267,
367,
12912,
315,
1059,
14,
4371,
63,
26831,
26,
288,
340,
4747,
708,
493,
14,
1002,
24276,
804,
8,
9541,
435,
7244,
531,
315,
359,
2676,
708,
493,
14,
4564,
5399,
63,
23837,
12,
4747,
708,
493,
14,
4564,
5399,
63,
16058,
12,
4747,
708,
493,
14,
4564,
5399,
63,
30839,
20492,
12,
4747,
708,
493,
14,
4564,
5399,
63,
907,
24321,
2617,
2189,
355,
12912,
16415,
14,
740,
8,
9541,
435,
7244,
1103,
531,
398,
372,
12912,
16415,
339,
347,
2455,
8,
277,
12,
931,
275,
17220,
2498,
63,
5642,
275,
715,
12,
1011,
958,
304,
398,
5629,
275,
664,
1899,
3567,
342,
398,
340,
440,
931,
26,
288,
931,
275,
5629,
398,
862,
26,
288,
7606,
275,
291,
14,
362,
13752,
8,
515,
275,
931,
12,
2498,
63,
5642,
275,
2498,
63,
5642,
9,
267,
871,
26,
288,
7606,
275,
942,
398,
1676,
275,
747,
14,
515,
14,
3475,
8,
515,
14,
6735,
8,
736,
14,
515,
14,
4127,
430,
267,
340,
1676,
508,
931,
14,
6735,
8,
736,
14,
515,
14,
4127,
304,
288,
1676,
275,
7324,
267,
916,
1676,
1137,
7324,
436,
1676,
1988,
18,
2938,
1137,
7596,
1103,
356,
288,
1676,
847,
747,
14,
515,
14,
4127,
398,
372,
469,
288,
283,
374,
63,
1231,
356,
931,
508,
17220,
288,
283,
1667,
356,
822,
8,
3220,
9,
508,
378,
12,
288,
283,
1708,
356,
1676,
12,
288,
283,
4219,
356,
5629,
435,
747,
14,
515,
14,
4127,
12,
288,
283,
3246,
356,
747,
14,
354,
12,
288,
283,
3220,
356,
7606,
12,
267,
789,
2378,
347,
365,
63,
5642,
8,
277,
12,
9911,
304,
267,
536,
275,
747,
14,
515,
14,
4846,
8,
736,
14,
515,
14,
4832,
8,
7218,
430,
267,
372,
536,
14,
2460,
7563,
503,
291,
14,
1989,
63,
5642,
63,
3215,
8,
7218,
9,
339,
347,
965,
63,
5642,
63,
3215,
8,
277,
12,
9911,
304,
267,
862,
26,
288,
3290,
275,
5577,
14,
25522,
14,
4989,
708,
14,
26535,
5379,
55,
8,
2975,
8,
7218,
430,
9213,
16283,
2773,
288,
702,
3290,
1137,
446,
17,
288,
754,
275,
2155,
8,
3288,
1253,
499,
9,
267,
871,
334,
10227,
12,
9070,
304,
288,
754,
275,
756,
267,
372,
754,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
krisys/django
|
django/contrib/auth/views.py
|
47
|
12477
|
import functools
import warnings
from django.conf import settings
# Avoid shadowing the login() and logout() views below.
from django.contrib.auth import (
REDIRECT_FIELD_NAME, get_user_model, login as auth_login,
logout as auth_logout, update_session_auth_hash,
)
from django.contrib.auth.decorators import login_required
from django.contrib.auth.forms import (
AuthenticationForm, PasswordChangeForm, PasswordResetForm, SetPasswordForm,
)
from django.contrib.auth.tokens import default_token_generator
from django.contrib.sites.shortcuts import get_current_site
from django.http import HttpResponseRedirect, QueryDict
from django.shortcuts import resolve_url
from django.template.response import TemplateResponse
from django.urls import reverse
from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.encoding import force_text
from django.utils.http import is_safe_url, urlsafe_base64_decode
from django.utils.six.moves.urllib.parse import urlparse, urlunparse
from django.utils.translation import ugettext as _
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_protect
from django.views.decorators.debug import sensitive_post_parameters
def deprecate_current_app(func):
"""
Handle deprecation of the current_app parameter of the views.
"""
@functools.wraps(func)
def inner(*args, **kwargs):
if 'current_app' in kwargs:
warnings.warn(
"Passing `current_app` as a keyword argument is deprecated. "
"Instead the caller of `{0}` should set "
"`request.current_app`.".format(func.__name__),
RemovedInDjango20Warning
)
current_app = kwargs.pop('current_app')
request = kwargs.get('request', None)
if request and current_app is not None:
request.current_app = current_app
return func(*args, **kwargs)
return inner
def _get_login_redirect_url(request, redirect_to):
# Ensure the user-originating redirection URL is safe.
if not is_safe_url(url=redirect_to, host=request.get_host()):
return resolve_url(settings.LOGIN_REDIRECT_URL)
return redirect_to
@deprecate_current_app
@sensitive_post_parameters()
@csrf_protect
@never_cache
def login(request, template_name='registration/login.html',
redirect_field_name=REDIRECT_FIELD_NAME,
authentication_form=AuthenticationForm,
extra_context=None, redirect_authenticated_user=False):
"""
Displays the login form and handles the login action.
"""
redirect_to = request.POST.get(redirect_field_name, request.GET.get(redirect_field_name, ''))
if redirect_authenticated_user and request.user.is_authenticated:
redirect_to = _get_login_redirect_url(request, redirect_to)
if redirect_to == request.path:
raise ValueError(
"Redirection loop for authenticated user detected. Check that "
"your LOGIN_REDIRECT_URL doesn't point to a login page."
)
return HttpResponseRedirect(redirect_to)
elif request.method == "POST":
form = authentication_form(request, data=request.POST)
if form.is_valid():
auth_login(request, form.get_user())
return HttpResponseRedirect(_get_login_redirect_url(request, redirect_to))
else:
form = authentication_form(request)
current_site = get_current_site(request)
context = {
'form': form,
redirect_field_name: redirect_to,
'site': current_site,
'site_name': current_site.name,
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context)
@deprecate_current_app
@never_cache
def logout(request, next_page=None,
template_name='registration/logged_out.html',
redirect_field_name=REDIRECT_FIELD_NAME,
extra_context=None):
"""
Logs out the user and displays 'You are logged out' message.
"""
auth_logout(request)
if next_page is not None:
next_page = resolve_url(next_page)
elif settings.LOGOUT_REDIRECT_URL:
next_page = resolve_url(settings.LOGOUT_REDIRECT_URL)
if (redirect_field_name in request.POST or
redirect_field_name in request.GET):
next_page = request.POST.get(redirect_field_name,
request.GET.get(redirect_field_name))
# Security check -- don't allow redirection to a different host.
if not is_safe_url(url=next_page, host=request.get_host()):
next_page = request.path
if next_page:
# Redirect to this page until the session has been cleared.
return HttpResponseRedirect(next_page)
current_site = get_current_site(request)
context = {
'site': current_site,
'site_name': current_site.name,
'title': _('Logged out')
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context)
@deprecate_current_app
def logout_then_login(request, login_url=None, extra_context=None):
"""
Logs out the user if they are logged in. Then redirects to the log-in page.
"""
if not login_url:
login_url = settings.LOGIN_URL
login_url = resolve_url(login_url)
return logout(request, login_url, extra_context=extra_context)
def redirect_to_login(next, login_url=None,
redirect_field_name=REDIRECT_FIELD_NAME):
"""
Redirects the user to the login page, passing the given 'next' page
"""
resolved_url = resolve_url(login_url or settings.LOGIN_URL)
login_url_parts = list(urlparse(resolved_url))
if redirect_field_name:
querystring = QueryDict(login_url_parts[4], mutable=True)
querystring[redirect_field_name] = next
login_url_parts[4] = querystring.urlencode(safe='/')
return HttpResponseRedirect(urlunparse(login_url_parts))
# 4 views for password reset:
# - password_reset sends the mail
# - password_reset_done shows a success message for the above
# - password_reset_confirm checks the link the user clicked and
# prompts for a new password
# - password_reset_complete shows a success message for the above
@deprecate_current_app
@csrf_protect
def password_reset(request,
template_name='registration/password_reset_form.html',
email_template_name='registration/password_reset_email.html',
subject_template_name='registration/password_reset_subject.txt',
password_reset_form=PasswordResetForm,
token_generator=default_token_generator,
post_reset_redirect=None,
from_email=None,
extra_context=None,
html_email_template_name=None,
extra_email_context=None):
if post_reset_redirect is None:
post_reset_redirect = reverse('password_reset_done')
else:
post_reset_redirect = resolve_url(post_reset_redirect)
if request.method == "POST":
form = password_reset_form(request.POST)
if form.is_valid():
opts = {
'use_https': request.is_secure(),
'token_generator': token_generator,
'from_email': from_email,
'email_template_name': email_template_name,
'subject_template_name': subject_template_name,
'request': request,
'html_email_template_name': html_email_template_name,
'extra_email_context': extra_email_context,
}
form.save(**opts)
return HttpResponseRedirect(post_reset_redirect)
else:
form = password_reset_form()
context = {
'form': form,
'title': _('Password reset'),
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context)
@deprecate_current_app
def password_reset_done(request,
template_name='registration/password_reset_done.html',
extra_context=None):
context = {
'title': _('Password reset sent'),
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context)
# Doesn't need csrf_protect since no-one can guess the URL
@sensitive_post_parameters()
@never_cache
@deprecate_current_app
def password_reset_confirm(request, uidb64=None, token=None,
template_name='registration/password_reset_confirm.html',
token_generator=default_token_generator,
set_password_form=SetPasswordForm,
post_reset_redirect=None,
extra_context=None):
"""
View that checks the hash in a password reset link and presents a
form for entering a new password.
"""
UserModel = get_user_model()
assert uidb64 is not None and token is not None # checked by URLconf
if post_reset_redirect is None:
post_reset_redirect = reverse('password_reset_complete')
else:
post_reset_redirect = resolve_url(post_reset_redirect)
try:
# urlsafe_base64_decode() decodes to bytestring on Python 3
uid = force_text(urlsafe_base64_decode(uidb64))
user = UserModel._default_manager.get(pk=uid)
except (TypeError, ValueError, OverflowError, UserModel.DoesNotExist):
user = None
if user is not None and token_generator.check_token(user, token):
validlink = True
title = _('Enter new password')
if request.method == 'POST':
form = set_password_form(user, request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(post_reset_redirect)
else:
form = set_password_form(user)
else:
validlink = False
form = None
title = _('Password reset unsuccessful')
context = {
'form': form,
'title': title,
'validlink': validlink,
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context)
@deprecate_current_app
def password_reset_complete(request,
template_name='registration/password_reset_complete.html',
extra_context=None):
context = {
'login_url': resolve_url(settings.LOGIN_URL),
'title': _('Password reset complete'),
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context)
@sensitive_post_parameters()
@csrf_protect
@login_required
@deprecate_current_app
def password_change(request,
template_name='registration/password_change_form.html',
post_change_redirect=None,
password_change_form=PasswordChangeForm,
extra_context=None):
if post_change_redirect is None:
post_change_redirect = reverse('password_change_done')
else:
post_change_redirect = resolve_url(post_change_redirect)
if request.method == "POST":
form = password_change_form(user=request.user, data=request.POST)
if form.is_valid():
form.save()
# Updating the password logs out all other sessions for the user
# except the current one.
update_session_auth_hash(request, form.user)
return HttpResponseRedirect(post_change_redirect)
else:
form = password_change_form(user=request.user)
context = {
'form': form,
'title': _('Password change'),
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context)
@login_required
@deprecate_current_app
def password_change_done(request,
template_name='registration/password_change_done.html',
extra_context=None):
context = {
'title': _('Password change successful'),
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context)
|
bsd-3-clause
|
[
646,
9143,
199,
646,
3598,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
3,
19503,
15084,
316,
314,
4676,
342,
436,
22079,
342,
6858,
5084,
14,
199,
504,
1639,
14,
2828,
14,
1178,
492,
334,
272,
820,
7458,
4168,
63,
8609,
63,
2339,
12,
664,
63,
751,
63,
1238,
12,
4676,
465,
1790,
63,
2886,
12,
272,
22079,
465,
1790,
63,
11646,
12,
1678,
63,
1730,
63,
1178,
63,
2227,
12,
199,
9,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
2828,
14,
1178,
14,
3351,
492,
334,
272,
15995,
2821,
12,
13635,
32523,
12,
13635,
9637,
2821,
12,
2494,
6139,
2821,
12,
199,
9,
199,
504,
1639,
14,
2828,
14,
1178,
14,
4504,
492,
849,
63,
1418,
63,
4679,
199,
504,
1639,
14,
2828,
14,
8619,
14,
17469,
492,
664,
63,
1818,
63,
2124,
199,
504,
1639,
14,
1014,
492,
14935,
12,
8133,
2141,
199,
504,
1639,
14,
17469,
492,
7512,
63,
633,
199,
504,
1639,
14,
1160,
14,
1310,
492,
29264,
199,
504,
1639,
14,
3603,
492,
3837,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
1165,
3849,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
1014,
492,
365,
63,
3489,
63,
633,
12,
8187,
6504,
63,
1095,
772,
63,
2708,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
1122,
492,
7097,
12,
30111,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1637,
492,
7078,
63,
1637,
199,
504,
1639,
14,
4196,
14,
11582,
14,
10088,
492,
19213,
63,
18292,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1757,
492,
18423,
63,
1932,
63,
3214,
421,
199,
318,
477,
21826,
63,
1818,
63,
571,
8,
1532,
304,
272,
408,
272,
8690,
17831,
402,
314,
1453,
63,
571,
2725,
402,
314,
6858,
14,
272,
408,
272,
768,
17869,
14,
13582,
8,
1532,
9,
272,
347,
6506,
2031,
589,
12,
1011,
958,
304,
267,
340,
283,
1818,
63,
571,
7,
315,
2074,
26,
288,
3598,
14,
4050,
8,
355,
298,
4986,
316,
658,
1818,
63,
571,
64,
465,
282,
4252,
1423,
365,
5906,
14,
298,
355,
298,
13962,
13558,
314,
8025,
402,
658,
91,
16,
23485,
1077,
663,
298,
355,
24505,
1069,
14,
1818,
63,
571,
2313,
1674,
908,
8,
1532,
855,
354,
10139,
355,
23687,
1165,
3849,
288,
776,
288,
1453,
63,
571,
275,
2074,
14,
1935,
360,
1818,
63,
571,
358,
288,
1056,
275,
2074,
14,
362,
360,
1069,
297,
488,
9,
288,
340,
1056,
436,
1453,
63,
571,
365,
440,
488,
26,
355,
1056,
14,
1818,
63,
571,
275,
1453,
63,
571,
267,
372,
2562,
2031,
589,
12,
1011,
958,
9,
272,
372,
6506,
421,
199,
318,
485,
362,
63,
2886,
63,
4876,
63,
633,
8,
1069,
12,
4660,
63,
475,
304,
272,
327,
7523,
314,
922,
13,
6493,
1958,
23713,
2851,
365,
5048,
14,
272,
340,
440,
365,
63,
3489,
63,
633,
8,
633,
29,
4876,
63,
475,
12,
1591,
29,
1069,
14,
362,
63,
1102,
5109,
267,
372,
7512,
63,
633,
8,
1751,
14,
17208,
63,
19747,
63,
2632,
9,
272,
372,
4660,
63,
475,
421,
199,
32,
27891,
63,
1818,
63,
571,
199,
32,
7361,
63,
1932,
63,
3214,
342,
199,
32,
10088,
63,
18292,
199,
32,
18178,
63,
1637,
199,
318,
4676,
8,
1069,
12,
1978,
63,
354,
534,
8054,
15,
2886,
14,
1360,
297,
881,
4660,
63,
698,
63,
354,
29,
19747,
63,
8609,
63,
2339,
12,
881,
6299,
63,
964,
29,
10348,
2821,
12,
881,
2402,
63,
1100,
29,
403,
12,
4660,
63,
12177,
63,
751,
29,
797,
304,
272,
408,
272,
28750,
314,
4676,
1824,
436,
10022,
314,
4676,
1595,
14,
272,
408,
272,
4660,
63,
475,
275,
1056,
14,
4030,
14,
362,
8,
4876,
63,
698,
63,
354,
12,
1056,
14,
2970,
14,
362,
8,
4876,
63,
698,
63,
354,
12,
12381,
339,
340,
4660,
63,
12177,
63,
751,
436,
1056,
14,
751,
14,
374,
63,
12177,
26,
267,
4660,
63,
475,
275,
485,
362,
63,
2886,
63,
4876,
63,
633,
8,
1069,
12,
4660,
63,
475,
9,
267,
340,
4660,
63,
475,
508,
1056,
14,
515,
26,
288,
746,
1722,
8,
355,
298,
497,
6874,
4438,
367,
15082,
922,
10501,
14,
2670,
626,
298,
355,
298,
12695,
5051,
568,
63,
19747,
63,
2632,
3181,
1133,
2376,
370,
282,
4676,
2034,
2122,
288,
776,
267,
372,
14935,
8,
4876,
63,
475,
9,
272,
916,
1056,
14,
765,
508,
298,
4030,
582,
267,
1824,
275,
6299,
63,
964,
8,
1069,
12,
666,
29,
1069,
14,
4030,
9,
267,
340,
1824,
14,
374,
63,
1078,
837,
288,
1790,
63,
2886,
8,
1069,
12,
1824,
14,
362,
63,
751,
1012,
288,
372,
14935,
1547,
362,
63,
2886,
63,
4876,
63,
633,
8,
1069,
12,
4660,
63,
475,
430,
272,
587,
26,
267,
1824,
275,
6299,
63,
964,
8,
1069,
9,
339,
1453,
63,
2124,
275,
664,
63,
1818,
63,
2124,
8,
1069,
9,
339,
1067,
275,
469,
267,
283,
964,
356,
1824,
12,
267,
4660,
63,
698,
63,
354,
26,
4660,
63,
475,
12,
267,
283,
2124,
356,
1453,
63,
2124,
12,
267,
283,
2124,
63,
354,
356,
1453,
63,
2124,
14,
354,
12,
272,
789,
272,
340,
2402,
63,
1100,
365,
440,
488,
26,
267,
1067,
14,
873,
8,
2911,
63,
1100,
9,
339,
372,
29264,
8,
1069,
12,
1978,
63,
354,
12,
1067,
9,
421,
199,
32,
27891,
63,
1818,
63,
571,
199,
32,
18178,
63,
1637,
199,
318,
22079,
8,
1069,
12,
2163,
63,
1606,
29,
403,
12,
1779,
1978,
63,
354,
534,
8054,
15,
12419,
63,
548,
14,
1360,
297,
1779,
4660,
63,
698,
63,
354,
29,
19747,
63,
8609,
63,
2339,
12,
1779,
2402,
63,
1100,
29,
403,
304,
272,
408,
272,
3835,
458,
734,
314,
922,
436,
17561,
283,
5556,
787,
10367,
734,
7,
1245,
14,
272,
408,
272,
1790,
63,
11646,
8,
1069,
9,
339,
340,
2163,
63,
1606,
365,
440,
488,
26,
267,
2163,
63,
1606,
275,
7512,
63,
633,
8,
2184,
63,
1606,
9,
272,
916,
2202,
14,
4947,
1877,
63,
19747
] |
[
9143,
199,
646,
3598,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
3,
19503,
15084,
316,
314,
4676,
342,
436,
22079,
342,
6858,
5084,
14,
199,
504,
1639,
14,
2828,
14,
1178,
492,
334,
272,
820,
7458,
4168,
63,
8609,
63,
2339,
12,
664,
63,
751,
63,
1238,
12,
4676,
465,
1790,
63,
2886,
12,
272,
22079,
465,
1790,
63,
11646,
12,
1678,
63,
1730,
63,
1178,
63,
2227,
12,
199,
9,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
2828,
14,
1178,
14,
3351,
492,
334,
272,
15995,
2821,
12,
13635,
32523,
12,
13635,
9637,
2821,
12,
2494,
6139,
2821,
12,
199,
9,
199,
504,
1639,
14,
2828,
14,
1178,
14,
4504,
492,
849,
63,
1418,
63,
4679,
199,
504,
1639,
14,
2828,
14,
8619,
14,
17469,
492,
664,
63,
1818,
63,
2124,
199,
504,
1639,
14,
1014,
492,
14935,
12,
8133,
2141,
199,
504,
1639,
14,
17469,
492,
7512,
63,
633,
199,
504,
1639,
14,
1160,
14,
1310,
492,
29264,
199,
504,
1639,
14,
3603,
492,
3837,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
1165,
3849,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
1014,
492,
365,
63,
3489,
63,
633,
12,
8187,
6504,
63,
1095,
772,
63,
2708,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
1122,
492,
7097,
12,
30111,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1637,
492,
7078,
63,
1637,
199,
504,
1639,
14,
4196,
14,
11582,
14,
10088,
492,
19213,
63,
18292,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1757,
492,
18423,
63,
1932,
63,
3214,
421,
199,
318,
477,
21826,
63,
1818,
63,
571,
8,
1532,
304,
272,
408,
272,
8690,
17831,
402,
314,
1453,
63,
571,
2725,
402,
314,
6858,
14,
272,
408,
272,
768,
17869,
14,
13582,
8,
1532,
9,
272,
347,
6506,
2031,
589,
12,
1011,
958,
304,
267,
340,
283,
1818,
63,
571,
7,
315,
2074,
26,
288,
3598,
14,
4050,
8,
355,
298,
4986,
316,
658,
1818,
63,
571,
64,
465,
282,
4252,
1423,
365,
5906,
14,
298,
355,
298,
13962,
13558,
314,
8025,
402,
658,
91,
16,
23485,
1077,
663,
298,
355,
24505,
1069,
14,
1818,
63,
571,
2313,
1674,
908,
8,
1532,
855,
354,
10139,
355,
23687,
1165,
3849,
288,
776,
288,
1453,
63,
571,
275,
2074,
14,
1935,
360,
1818,
63,
571,
358,
288,
1056,
275,
2074,
14,
362,
360,
1069,
297,
488,
9,
288,
340,
1056,
436,
1453,
63,
571,
365,
440,
488,
26,
355,
1056,
14,
1818,
63,
571,
275,
1453,
63,
571,
267,
372,
2562,
2031,
589,
12,
1011,
958,
9,
272,
372,
6506,
421,
199,
318,
485,
362,
63,
2886,
63,
4876,
63,
633,
8,
1069,
12,
4660,
63,
475,
304,
272,
327,
7523,
314,
922,
13,
6493,
1958,
23713,
2851,
365,
5048,
14,
272,
340,
440,
365,
63,
3489,
63,
633,
8,
633,
29,
4876,
63,
475,
12,
1591,
29,
1069,
14,
362,
63,
1102,
5109,
267,
372,
7512,
63,
633,
8,
1751,
14,
17208,
63,
19747,
63,
2632,
9,
272,
372,
4660,
63,
475,
421,
199,
32,
27891,
63,
1818,
63,
571,
199,
32,
7361,
63,
1932,
63,
3214,
342,
199,
32,
10088,
63,
18292,
199,
32,
18178,
63,
1637,
199,
318,
4676,
8,
1069,
12,
1978,
63,
354,
534,
8054,
15,
2886,
14,
1360,
297,
881,
4660,
63,
698,
63,
354,
29,
19747,
63,
8609,
63,
2339,
12,
881,
6299,
63,
964,
29,
10348,
2821,
12,
881,
2402,
63,
1100,
29,
403,
12,
4660,
63,
12177,
63,
751,
29,
797,
304,
272,
408,
272,
28750,
314,
4676,
1824,
436,
10022,
314,
4676,
1595,
14,
272,
408,
272,
4660,
63,
475,
275,
1056,
14,
4030,
14,
362,
8,
4876,
63,
698,
63,
354,
12,
1056,
14,
2970,
14,
362,
8,
4876,
63,
698,
63,
354,
12,
12381,
339,
340,
4660,
63,
12177,
63,
751,
436,
1056,
14,
751,
14,
374,
63,
12177,
26,
267,
4660,
63,
475,
275,
485,
362,
63,
2886,
63,
4876,
63,
633,
8,
1069,
12,
4660,
63,
475,
9,
267,
340,
4660,
63,
475,
508,
1056,
14,
515,
26,
288,
746,
1722,
8,
355,
298,
497,
6874,
4438,
367,
15082,
922,
10501,
14,
2670,
626,
298,
355,
298,
12695,
5051,
568,
63,
19747,
63,
2632,
3181,
1133,
2376,
370,
282,
4676,
2034,
2122,
288,
776,
267,
372,
14935,
8,
4876,
63,
475,
9,
272,
916,
1056,
14,
765,
508,
298,
4030,
582,
267,
1824,
275,
6299,
63,
964,
8,
1069,
12,
666,
29,
1069,
14,
4030,
9,
267,
340,
1824,
14,
374,
63,
1078,
837,
288,
1790,
63,
2886,
8,
1069,
12,
1824,
14,
362,
63,
751,
1012,
288,
372,
14935,
1547,
362,
63,
2886,
63,
4876,
63,
633,
8,
1069,
12,
4660,
63,
475,
430,
272,
587,
26,
267,
1824,
275,
6299,
63,
964,
8,
1069,
9,
339,
1453,
63,
2124,
275,
664,
63,
1818,
63,
2124,
8,
1069,
9,
339,
1067,
275,
469,
267,
283,
964,
356,
1824,
12,
267,
4660,
63,
698,
63,
354,
26,
4660,
63,
475,
12,
267,
283,
2124,
356,
1453,
63,
2124,
12,
267,
283,
2124,
63,
354,
356,
1453,
63,
2124,
14,
354,
12,
272,
789,
272,
340,
2402,
63,
1100,
365,
440,
488,
26,
267,
1067,
14,
873,
8,
2911,
63,
1100,
9,
339,
372,
29264,
8,
1069,
12,
1978,
63,
354,
12,
1067,
9,
421,
199,
32,
27891,
63,
1818,
63,
571,
199,
32,
18178,
63,
1637,
199,
318,
22079,
8,
1069,
12,
2163,
63,
1606,
29,
403,
12,
1779,
1978,
63,
354,
534,
8054,
15,
12419,
63,
548,
14,
1360,
297,
1779,
4660,
63,
698,
63,
354,
29,
19747,
63,
8609,
63,
2339,
12,
1779,
2402,
63,
1100,
29,
403,
304,
272,
408,
272,
3835,
458,
734,
314,
922,
436,
17561,
283,
5556,
787,
10367,
734,
7,
1245,
14,
272,
408,
272,
1790,
63,
11646,
8,
1069,
9,
339,
340,
2163,
63,
1606,
365,
440,
488,
26,
267,
2163,
63,
1606,
275,
7512,
63,
633,
8,
2184,
63,
1606,
9,
272,
916,
2202,
14,
4947,
1877,
63,
19747,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bpsinc-native/src_third_party_chromite
|
cros/commands/cros_chrome_sdk_unittest.py
|
1
|
18425
|
#!/usr/bin/python
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""This module tests the cros image command."""
import copy
import mock
import os
import shutil
import sys
sys.path.insert(0, os.path.abspath('%s/../../..' % os.path.dirname(__file__)))
from chromite.cbuildbot import constants
from chromite.cros.commands import cros_chrome_sdk
from chromite.cros.commands import init_unittest
from chromite.lib import cache
from chromite.lib import chrome_util
from chromite.lib import cros_build_lib_unittest
from chromite.lib import cros_test_lib
from chromite.lib import gs
from chromite.lib import gs_unittest
from chromite.lib import osutils
from chromite.lib import partial_mock
# pylint: disable=W0212
class MockChromeSDKCommand(init_unittest.MockCommand):
"""Mock out the build command."""
TARGET = 'chromite.cros.commands.cros_chrome_sdk.ChromeSDKCommand'
TARGET_CLASS = cros_chrome_sdk.ChromeSDKCommand
COMMAND = 'chrome-sdk'
ATTRS = ('_GOMA_URL', '_SetupEnvironment') + init_unittest.MockCommand.ATTRS
_GOMA_URL = 'Invalid URL'
def __init__(self, *args, **kwargs):
init_unittest.MockCommand.__init__(self, *args, **kwargs)
self.env = None
def _SetupEnvironment(self, *args, **kwargs):
env = self.backup['_SetupEnvironment'](*args, **kwargs)
self.env = copy.deepcopy(env)
return env
class ParserTest(cros_test_lib.MockTempDirTestCase):
"""Test the parser."""
def testNormal(self):
"""Tests that our example parser works normally."""
with MockChromeSDKCommand(
['--board', SDKFetcherMock.BOARD],
base_args=['--cache-dir', self.tempdir]) as bootstrap:
self.assertEquals(bootstrap.inst.options.board, SDKFetcherMock.BOARD)
self.assertEquals(bootstrap.inst.options.cache_dir, self.tempdir)
def _GSCopyMock(_self, path, dest, **_kwargs):
"""Used to simulate a GS Copy operation."""
with osutils.TempDir() as tempdir:
local_path = os.path.join(tempdir, os.path.basename(path))
osutils.Touch(local_path)
shutil.move(local_path, dest)
def _DependencyMockCtx(f):
"""Attribute that ensures dependency PartialMocks are started.
Since PartialMock does not support nested mocking, we need to first call
stop() on the outer level PartialMock (which is passed in to us). We then
re-start() the outer level upon exiting the context.
"""
def new_f(self, *args, **kwargs):
if not self.entered:
try:
self.entered = True
# Temporarily disable outer GSContext mock before starting our mock.
# TODO(rcui): Generalize this attribute and include in partial_mock.py.
for emock in self.external_mocks:
emock.stop()
with self.gs_mock:
return f(self, *args, **kwargs)
finally:
self.entered = False
for emock in self.external_mocks:
emock.start()
else:
return f(self, *args, **kwargs)
return new_f
class SDKFetcherMock(partial_mock.PartialMock):
"""Provides mocking functionality for SDKFetcher."""
TARGET = 'chromite.cros.commands.cros_chrome_sdk.SDKFetcher'
ATTRS = ('__init__', 'GetFullVersion', '_GetMetadata', '_UpdateTarball',
'UpdateDefaultVersion')
FAKE_METADATA = """
{
"boards": ["x86-alex"],
"cros-version": "25.3543.2",
"metadata-version": "1",
"bot-hostname": "build82-m2.golo.chromium.org",
"bot-config": "x86-alex-release",
"toolchain-tuple": ["i686-pc-linux-gnu"],
"toolchain-url": "2013/01/%(target)s-2013.01.23.003823.tar.xz",
"sdk-version": "2013.01.23.003823"
}"""
BOARD = 'x86-alex'
VERSION = 'XXXX.X.X'
def __init__(self, external_mocks=None):
"""Initializes the mock.
Args:
external_mocks: A list of already started PartialMock/patcher instances.
stop() will be called on each element every time execution enters one of
our the mocked out methods, and start() called on it once execution
leaves the mocked out method.
"""
partial_mock.PartialMock.__init__(self)
self.external_mocks = external_mocks or []
self.entered = False
self.gs_mock = gs_unittest.GSContextMock()
self.gs_mock.SetDefaultCmdResult()
self.env = None
@_DependencyMockCtx
def _target__init__(self, inst, *args, **kwargs):
self.backup['__init__'](inst, *args, **kwargs)
if not inst.cache_base.startswith('/tmp'):
raise AssertionError('For testing, SDKFetcher cache_dir needs to be a '
'dir under /tmp')
@_DependencyMockCtx
def UpdateDefaultVersion(self, inst, *_args, **_kwargs):
inst._SetDefaultVersion(self.VERSION)
return self.VERSION, True
@_DependencyMockCtx
def _UpdateTarball(self, inst, *args, **kwargs):
with mock.patch.object(gs.GSContext, 'Copy', autospec=True,
side_effect=_GSCopyMock):
with mock.patch.object(cache, 'Untar'):
return self.backup['_UpdateTarball'](inst, *args, **kwargs)
@_DependencyMockCtx
def GetFullVersion(self, _inst, version):
return 'R26-%s' % version
@_DependencyMockCtx
def _GetMetadata(self, inst, *args, **kwargs):
self.gs_mock.SetDefaultCmdResult()
self.gs_mock.AddCmdResult(
partial_mock.ListRegex('cat .*/%s' % constants.METADATA_JSON),
output=self.FAKE_METADATA)
return self.backup['_GetMetadata'](inst, *args, **kwargs)
class RunThroughTest(cros_test_lib.MockTempDirTestCase,
cros_test_lib.LoggingTestCase):
"""Run the script with most things mocked out."""
VERSION_KEY = (SDKFetcherMock.BOARD, SDKFetcherMock.VERSION,
constants.CHROME_SYSROOT_TAR)
FAKE_ENV = {
'GYP_DEFINES': "sysroot='/path/to/sysroot'",
'CXX': 'x86_64-cros-linux-gnu-g++ -B /path/to/gold',
'CC': 'x86_64-cros-linux-gnu-gcc -B /path/to/gold',
'LD': 'x86_64-cros-linux-gnu-g++ -B /path/to/gold',
}
def SetupCommandMock(self, extra_args=None):
cmd_args = ['--board', SDKFetcherMock.BOARD, '--chrome-src',
self.chrome_src_dir, 'true']
if extra_args:
cmd_args.extend(extra_args)
self.cmd_mock = MockChromeSDKCommand(
cmd_args, base_args=['--cache-dir', self.tempdir])
self.StartPatcher(self.cmd_mock)
self.cmd_mock.UnMockAttr('Run')
def SourceEnvironmentMock(self, path, *_args, **_kwargs):
if path.endswith('environment'):
return copy.deepcopy(self.FAKE_ENV)
return {}
def setUp(self):
self.rc_mock = cros_build_lib_unittest.RunCommandMock()
self.rc_mock.SetDefaultCmdResult()
self.StartPatcher(self.rc_mock)
self.sdk_mock = self.StartPatcher(SDKFetcherMock(
external_mocks=[self.rc_mock]))
# This needs to occur before initializing MockChromeSDKCommand.
self.bashrc = os.path.join(self.tempdir, 'bashrc')
self.PatchObject(constants, 'CHROME_SDK_BASHRC', new=self.bashrc)
self.PatchObject(osutils, 'SourceEnvironment',
autospec=True, side_effect=self.SourceEnvironmentMock)
self.rc_mock.AddCmdResult(cros_chrome_sdk.ChromeSDKCommand.GOMACC_PORT_CMD,
output='8088')
# Initialized by SetupCommandMock.
self.cmd_mock = None
# Set up a fake Chrome src/ directory
self.chrome_root = os.path.join(self.tempdir, 'chrome_root')
self.chrome_src_dir = os.path.join(self.chrome_root, 'src')
osutils.SafeMakedirs(self.chrome_src_dir)
osutils.Touch(os.path.join(self.chrome_root, '.gclient'))
@property
def cache(self):
return self.cmd_mock.inst.sdk.tarball_cache
def testIt(self):
"""Test a runthrough of the script."""
self.SetupCommandMock()
with cros_test_lib.LoggingCapturer() as logs:
self.cmd_mock.inst.Run()
self.AssertLogsContain(logs, 'Goma:', inverted=True)
with self.cache.Lookup(self.VERSION_KEY) as r:
self.assertTrue(r.Exists())
def testErrorCodePassthrough(self):
"""Test that error codes are passed through."""
self.SetupCommandMock()
with cros_test_lib.LoggingCapturer():
self.rc_mock.AddCmdResult(partial_mock.ListRegex('-- true'),
returncode=5)
returncode = self.cmd_mock.inst.Run()
self.assertEquals(returncode, 5)
def testLocalSDKPath(self):
"""Fetch components from a local --sdk-path."""
sdk_dir = os.path.join(self.tempdir, 'sdk_dir')
osutils.SafeMakedirs(sdk_dir)
osutils.WriteFile(os.path.join(sdk_dir, constants.METADATA_JSON),
SDKFetcherMock.FAKE_METADATA)
self.SetupCommandMock(extra_args=['--sdk-path', sdk_dir])
with cros_test_lib.LoggingCapturer():
self.cmd_mock.inst.Run()
def testGomaError(self):
"""We print an error message when GomaError is raised."""
self.SetupCommandMock()
with cros_test_lib.LoggingCapturer() as logs:
self.PatchObject(cros_chrome_sdk.ChromeSDKCommand, '_FetchGoma',
side_effect=cros_chrome_sdk.GomaError())
self.cmd_mock.inst.Run()
self.AssertLogsContain(logs, 'Goma:')
def testSpecificComponent(self):
"""Tests that SDKFetcher.Prepare() handles |components| param properly."""
sdk = cros_chrome_sdk.SDKFetcher(os.path.join(self.tempdir),
SDKFetcherMock.BOARD)
components = [constants.BASE_IMAGE_TAR, constants.CHROME_SYSROOT_TAR]
with sdk.Prepare(components=components) as ctx:
for c in components:
self.assertTrue(os.path.exists(ctx.key_map[c].path))
for c in [constants.IMAGE_SCRIPTS_TAR, constants.CHROME_ENV_TAR]:
self.assertFalse(c in ctx.key_map)
@staticmethod
def FindInPath(paths, endswith):
for path in paths.split(':'):
if path.endswith(endswith):
return True
return False
def testGomaInPath(self, inverted=False):
"""Verify that we do indeed add Goma to the PATH."""
extra_args = ['--nogoma'] if inverted else None
self.SetupCommandMock(extra_args)
self.cmd_mock.inst.Run()
assert_fn = self.assertNotIn if inverted else self.assertIn
gyp_defines_str = self.cmd_mock.env['GYP_DEFINES']
gyp_defines = chrome_util.ProcessGypDefines(gyp_defines_str)
assert_fn('gomadir', gyp_defines)
assert_fn('use_goma', gyp_defines)
def testNoGoma(self):
"""Verify that we do not add Goma to the PATH."""
self.testGomaInPath(inverted=True)
def testClang(self):
"""Verifies clang codepath."""
with cros_test_lib.LoggingCapturer() as logs:
cmd_cls = cros_chrome_sdk.ChromeSDKCommand
self.SetupCommandMock(extra_args=['--clang'])
self.cmd_mock.inst.Run()
class GomaTest(cros_test_lib.MockTempDirTestCase,
cros_test_lib.LoggingTestCase):
"""Test Goma setup functionality."""
def setUp(self):
self.rc_mock = cros_build_lib_unittest.RunCommandMock()
self.rc_mock.SetDefaultCmdResult()
self.StartPatcher(self.rc_mock)
self.cmd_mock = MockChromeSDKCommand(
['--board', SDKFetcherMock.BOARD, 'true'],
base_args=['--cache-dir', self.tempdir])
self.StartPatcher(self.cmd_mock)
def VerifyGomaError(self):
self.assertRaises(cros_chrome_sdk.GomaError, self.cmd_mock.inst._FetchGoma)
def testNoGomaPort(self):
"""We print an error when gomacc is not returning a port."""
self.rc_mock.AddCmdResult(
cros_chrome_sdk.ChromeSDKCommand.GOMACC_PORT_CMD)
self.VerifyGomaError()
def testGomaccError(self):
"""We print an error when gomacc exits with nonzero returncode."""
self.rc_mock.AddCmdResult(
cros_chrome_sdk.ChromeSDKCommand.GOMACC_PORT_CMD, returncode=1)
self.VerifyGomaError()
def testFetchError(self):
"""We print an error when we can't fetch Goma."""
self.rc_mock.AddCmdResult(
cros_chrome_sdk.ChromeSDKCommand.GOMACC_PORT_CMD, returncode=1)
self.VerifyGomaError()
def testGomaStart(self):
"""Test that we start Goma if it's not already started."""
# Duplicate return values.
self.PatchObject(cros_chrome_sdk.ChromeSDKCommand, '_GomaPort',
side_effect=['XXXX', 'XXXX'])
# Run it twice to exercise caching.
for _ in range(2):
goma_dir, goma_port = self.cmd_mock.inst._FetchGoma()
self.assertEquals(goma_port, 'XXXX')
self.assertTrue(bool(goma_dir))
class VersionTest(cros_test_lib.MockTempDirTestCase):
"""Tests the determination of which SDK version to use."""
VERSION = '3543.2.0'
FULL_VERSION = 'R55-%s' % VERSION
BOARD = 'lumpy'
VERSION_BASE = ('gs://chromeos-image-archive/%s-release/LATEST-%s'
% (BOARD, VERSION))
CAT_ERROR = ('InvalidUriError: Attempt to get key for '
'%s failed.' % VERSION_BASE)
LS_ERROR = 'CommandException: One or more URIs matched no objects.'
def setUp(self):
self.gs_mock = self.StartPatcher(gs_unittest.GSContextMock())
self.gs_mock.SetDefaultCmdResult()
self.sdk_mock = self.StartPatcher(SDKFetcherMock(
external_mocks=[self.gs_mock]))
os.environ.pop(cros_chrome_sdk.SDKFetcher.SDK_VERSION_ENV, None)
self.sdk = cros_chrome_sdk.SDKFetcher(
os.path.join(self.tempdir, 'cache'), self.BOARD)
def SetUpDefaultVersion(self, current, target, newest):
self.PatchObject(cros_chrome_sdk.SDKFetcher, 'GetDefaultVersion',
return_value=current)
self.PatchObject(cros_chrome_sdk.SDKFetcher, '_GetRepoCheckoutVersion',
return_value=target)
self.PatchObject(cros_chrome_sdk.SDKFetcher, '_GetNewestManifestVersion',
return_value=newest)
return self.sdk.UpdateDefaultVersion()
def testUpdateDefaultVersionNormal(self):
"""Updating default version with no cached default version."""
self.sdk_mock.UnMockAttr('UpdateDefaultVersion')
target, updated = self.SetUpDefaultVersion(None, self.VERSION, '3544.0.0')
self.assertEquals(target, self.VERSION)
self.assertEquals(updated, True)
def testUpdateDefaultVersionTooNew(self):
"""Version in chromeos_version.sh isn't uploaded yet."""
self.sdk_mock.UnMockAttr('UpdateDefaultVersion')
target, updated = self.SetUpDefaultVersion(None, '3543.10.0', self.VERSION)
self.assertEquals(target, self.VERSION)
self.assertEquals(updated, True)
def testUpdateDefaultVersionNoUpdate(self):
"""Nothing to update because the target version did not change."""
self.sdk_mock.UnMockAttr('UpdateDefaultVersion')
target, updated = self.SetUpDefaultVersion(self.VERSION, self.VERSION,
None)
self.assertEquals(target, self.VERSION)
self.assertEquals(updated, False)
def testUpdateDefaultChromeVersion(self):
"""We pick up the right LKGM version from the Chrome tree."""
dir_struct = [
'gclient_root/.gclient'
]
cros_test_lib.CreateOnDiskHierarchy(self.tempdir, dir_struct)
gclient_root = os.path.join(self.tempdir, 'gclient_root')
self.PatchObject(os, 'getcwd', return_value=gclient_root)
lkgm_file = os.path.join(gclient_root, 'src', constants.PATH_TO_CHROME_LKGM)
osutils.Touch(lkgm_file, makedirs=True)
osutils.WriteFile(lkgm_file, self.VERSION)
self.sdk_mock.UnMockAttr('UpdateDefaultVersion')
self.sdk.UpdateDefaultVersion()
self.assertEquals(self.sdk.GetDefaultVersion(),
self.VERSION)
def testFullVersion(self):
"""Test full version calculation."""
def RaiseException(*_args, **_kwargs):
raise Exception('boom')
self.sdk_mock.UnMockAttr('GetFullVersion')
self.gs_mock.AddCmdResult(
partial_mock.ListRegex('cat .*/LATEST-%s' % self.VERSION),
output=self.FULL_VERSION)
self.assertEquals(
self.FULL_VERSION,
self.sdk.GetFullVersion(self.VERSION))
# Test that we access the cache on the next call, rather than checking GS.
self.gs_mock.AddCmdResult(
partial_mock.ListRegex('cat .*/LATEST-%s' % self.VERSION),
side_effect=RaiseException)
self.assertEquals(
self.FULL_VERSION,
self.sdk.GetFullVersion(self.VERSION))
def testBadVersion(self):
"""We raise an exception for a bad version."""
self.sdk_mock.UnMockAttr('GetFullVersion')
self.gs_mock.AddCmdResult(
partial_mock.ListRegex('cat .*/LATEST-%s' % self.VERSION),
output='', error=self.CAT_ERROR, returncode=1)
self.gs_mock.AddCmdResult(
partial_mock.ListRegex('ls .*%s' % self.VERSION),
output='', error=self.LS_ERROR, returncode=1)
self.assertRaises(cros_chrome_sdk.MissingSDK, self.sdk.GetFullVersion,
self.VERSION)
def testDefaultEnvBadBoard(self):
"""We don't use the version in the environment if board doesn't match."""
os.environ[cros_chrome_sdk.SDKFetcher.SDK_VERSION_ENV] = self.VERSION
self.assertNotEquals(self.VERSION, self.sdk_mock.VERSION)
self.assertEquals(self.sdk.GetDefaultVersion(), None)
def testDefaultEnvGoodBoard(self):
"""We use the version in the environment if board matches."""
sdk_version_env = cros_chrome_sdk.SDKFetcher.SDK_VERSION_ENV
os.environ[sdk_version_env] = self.VERSION
os.environ[cros_chrome_sdk.SDKFetcher.SDK_BOARD_ENV] = self.BOARD
self.assertEquals(self.sdk.GetDefaultVersion(), self.VERSION)
class PathVerifyTest(cros_test_lib.MockTempDirTestCase,
cros_test_lib.LoggingTestCase):
"""Tests user_rc PATH validation and warnings."""
def testPathVerifyWarnings(self):
"""Test the user rc PATH verification codepath."""
def SourceEnvironmentMock(*_args, **_kwargs):
return {
'PATH': ':'.join([os.path.dirname(p) for p in abs_paths]),
}
self.PatchObject(osutils, 'SourceEnvironment',
side_effect=SourceEnvironmentMock)
file_list = (
'goma/goma_ctl.py',
'clang/clang',
'chromite/parallel_emerge',
)
abs_paths = [os.path.join(self.tempdir, relpath) for relpath in file_list]
for p in abs_paths:
osutils.Touch(p, makedirs=True, mode=0o755)
with cros_test_lib.LoggingCapturer() as logs:
cros_chrome_sdk.ChromeSDKCommand._VerifyGoma(None)
cros_chrome_sdk.ChromeSDKCommand._VerifyChromiteBin(None)
for msg in ['managed Goma', 'default Chromite']:
self.AssertLogsMatch(logs, msg)
if __name__ == '__main__':
cros_test_lib.main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
1898,
334,
67,
9,
6029,
710,
12051,
4403,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
2765,
859,
2295,
314,
25532,
1834,
1414,
1041,
199,
199,
646,
1331,
199,
646,
1683,
199,
646,
747,
199,
646,
5145,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
3508,
83,
15,
9707,
703,
7,
450,
747,
14,
515,
14,
3475,
3460,
493,
29658,
199,
504,
20074,
1175,
14,
67,
25497,
492,
5262,
199,
504,
20074,
1175,
14,
20363,
14,
4405,
492,
25532,
63,
9887,
63,
9277,
199,
504,
20074,
1175,
14,
20363,
14,
4405,
492,
4205,
63,
2796,
199,
504,
20074,
1175,
14,
773,
492,
2581,
199,
504,
20074,
1175,
14,
773,
492,
18221,
63,
1974,
199,
504,
20074,
1175,
14,
773,
492,
25532,
63,
1506,
63,
773,
63,
2796,
199,
504,
20074,
1175,
14,
773,
492,
25532,
63,
396,
63,
773,
199,
504,
20074,
1175,
14,
773,
492,
8763,
199,
504,
20074,
1175,
14,
773,
492,
8763,
63,
2796,
199,
504,
20074,
1175,
14,
773,
492,
747,
1208,
199,
504,
20074,
1175,
14,
773,
492,
7417,
63,
1805,
199,
199,
3,
4287,
26,
3507,
29,
55,
996,
713,
199,
199,
533,
4420,
18083,
14939,
3110,
8,
826,
63,
2796,
14,
3346,
3110,
304,
523,
408,
3346,
734,
314,
1900,
1414,
1041,
523,
26134,
275,
283,
23473,
1175,
14,
20363,
14,
4405,
14,
20363,
63,
9887,
63,
9277,
14,
18083,
14939,
3110,
7,
523,
26134,
63,
6885,
275,
25532,
63,
9887,
63,
9277,
14,
18083,
14939,
3110,
523,
25965,
275,
283,
9887,
13,
9277,
7,
523,
10762,
51,
275,
12331,
13160,
2054,
63,
2632,
297,
2513,
8555,
8263,
358,
435,
4205,
63,
2796,
14,
3346,
3110,
14,
27356,
819,
485,
13160,
2054,
63,
2632,
275,
283,
3364,
2851,
7,
819,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
4205,
63,
2796,
14,
3346,
3110,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
9,
272,
291,
14,
1813,
275,
488,
819,
347,
485,
8555,
8263,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
2589,
275,
291,
14,
5751,
8680,
8555,
8263,
418,
2031,
589,
12,
1011,
958,
9,
272,
291,
14,
1813,
275,
1331,
14,
8293,
8,
1813,
9,
272,
372,
2589,
421,
199,
533,
10191,
774,
8,
20363,
63,
396,
63,
773,
14,
3346,
29008,
1746,
304,
523,
408,
774,
314,
1798,
1041,
523,
347,
511,
6241,
8,
277,
304,
272,
408,
2925,
626,
4154,
2893,
1798,
5419,
12252,
1041,
272,
543,
4420,
18083,
14939,
3110,
8,
267,
14574,
3576,
297,
15610,
11135,
281,
3346,
14,
23368,
467,
267,
1300,
63,
589,
2968,
306,
1637,
13,
694,
297,
291,
14,
11567,
566,
465,
15865,
26,
489,
291,
14,
2947,
8,
11146,
14,
3615,
14,
1419,
14,
3576,
12,
15610,
11135,
281,
3346,
14,
23368,
9,
489,
291,
14,
2947,
8,
11146,
14,
3615,
14,
1419,
14,
1637,
63,
694,
12,
291,
14,
11567,
9,
421,
199,
318,
485,
8021,
5116,
3346,
1547,
277,
12,
931,
12,
2053,
12,
29666,
958,
304,
523,
408,
9167,
370,
20577,
282,
598,
51,
11247,
3439,
1041,
523,
543,
747,
1208,
14,
29008,
342,
465,
21628,
26,
272,
2257,
63,
515,
275,
747,
14,
515,
14,
904,
8,
11567,
12,
747,
14,
515,
14,
4846,
8,
515,
430,
272,
747,
1208,
14,
52,
13087,
8,
1832,
63,
515,
9,
272,
5145,
14,
1185,
8,
1832,
63,
515,
12,
2053,
9,
421,
199,
318,
485,
14403,
3346,
35,
2347,
8,
70,
304,
523,
408,
1646,
626,
15620,
5936,
2235,
1009,
3346,
83,
787,
8239,
14,
819,
9336,
2235,
1009,
3346,
1630,
440,
2291,
6032,
1683,
316,
12,
781,
1929,
370,
1642,
1240,
523,
3631,
342,
641,
314,
6890,
2166,
2235,
1009,
3346,
334,
6777,
365,
3032,
315,
370,
2739,
680,
221,
2136,
2066,
523,
295,
13,
928,
342,
314,
6890,
2166,
12188,
24234,
314,
1067,
14,
523,
408,
523,
347,
892,
63,
70,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
340,
440,
291,
14,
287,
3014,
26,
489,
862,
26,
267,
291,
14,
287,
3014,
275,
715,
267,
327,
12540,
269,
11406,
3507,
6890,
598,
51,
2998,
1683,
2544,
6617,
4154,
1683,
14,
267,
327,
3254,
8,
1195,
1907,
304,
1696,
794,
642,
2225,
436,
2387,
315,
7417,
63,
1805,
14,
647,
14,
267,
367,
325,
1805,
315,
291,
14,
5159,
63,
25191,
26,
881,
325,
1805,
14,
2379,
342,
398,
543,
291,
14,
458,
63,
1805,
26,
881,
372,
289,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
489,
3753,
26,
267,
291,
14,
287,
3014,
275,
756,
267,
367,
325,
1805,
315,
291,
14,
5159,
63,
25191,
26,
881,
325,
1805,
14,
928,
342,
272,
587,
26,
489,
372,
289,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
523,
372,
892,
63,
70,
421,
199,
533,
15610,
11135,
281,
3346,
8,
6672,
63,
1805,
14,
18192,
3346,
304,
523,
408,
17473,
1683,
316,
9330,
367,
15610,
11135,
281,
1041,
819,
26134,
275,
283,
23473,
1175,
14,
20363,
14,
4405,
14,
20363,
63,
9887,
63,
9277,
14,
14939,
11135,
281,
7,
523,
10762,
51,
275,
25038,
826,
7500,
283,
1002,
9042,
3353,
297,
2513,
1002,
5142,
297,
2513,
4152,
24818,
8571,
297,
1779,
283,
4152,
2698,
3353,
358,
819,
25699,
63,
8314,
275,
408,
199,
91,
523,
298,
19267,
582,
2097,
88,
1184,
13,
24421,
2255,
523,
298,
20363,
13,
1023,
582,
298,
821,
14,
1276,
2824,
14,
18,
401,
523,
298,
2343,
13,
1023,
582,
298,
17,
401,
523,
298,
3018,
13,
4269,
582,
298,
1506,
2564,
13,
77,
18,
14,
1939,
320,
14,
13211,
14,
1308,
401,
523,
298,
3018,
13,
888,
582,
298,
88,
1184,
13,
24421,
13,
3221,
401,
523,
298,
22572,
13,
2960,
582,
2097,
73,
10253,
13,
2352,
13,
5135,
13,
3689,
2255,
523,
298,
22572,
13,
633,
582,
298,
6965,
15,
614,
21275,
1375,
9,
83,
13,
6965,
14,
614,
14,
1789,
14,
383,
1703
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
1898,
334,
67,
9,
6029,
710,
12051,
4403,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
2765,
859,
2295,
314,
25532,
1834,
1414,
1041,
199,
199,
646,
1331,
199,
646,
1683,
199,
646,
747,
199,
646,
5145,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
3508,
83,
15,
9707,
703,
7,
450,
747,
14,
515,
14,
3475,
3460,
493,
29658,
199,
504,
20074,
1175,
14,
67,
25497,
492,
5262,
199,
504,
20074,
1175,
14,
20363,
14,
4405,
492,
25532,
63,
9887,
63,
9277,
199,
504,
20074,
1175,
14,
20363,
14,
4405,
492,
4205,
63,
2796,
199,
504,
20074,
1175,
14,
773,
492,
2581,
199,
504,
20074,
1175,
14,
773,
492,
18221,
63,
1974,
199,
504,
20074,
1175,
14,
773,
492,
25532,
63,
1506,
63,
773,
63,
2796,
199,
504,
20074,
1175,
14,
773,
492,
25532,
63,
396,
63,
773,
199,
504,
20074,
1175,
14,
773,
492,
8763,
199,
504,
20074,
1175,
14,
773,
492,
8763,
63,
2796,
199,
504,
20074,
1175,
14,
773,
492,
747,
1208,
199,
504,
20074,
1175,
14,
773,
492,
7417,
63,
1805,
199,
199,
3,
4287,
26,
3507,
29,
55,
996,
713,
199,
199,
533,
4420,
18083,
14939,
3110,
8,
826,
63,
2796,
14,
3346,
3110,
304,
523,
408,
3346,
734,
314,
1900,
1414,
1041,
523,
26134,
275,
283,
23473,
1175,
14,
20363,
14,
4405,
14,
20363,
63,
9887,
63,
9277,
14,
18083,
14939,
3110,
7,
523,
26134,
63,
6885,
275,
25532,
63,
9887,
63,
9277,
14,
18083,
14939,
3110,
523,
25965,
275,
283,
9887,
13,
9277,
7,
523,
10762,
51,
275,
12331,
13160,
2054,
63,
2632,
297,
2513,
8555,
8263,
358,
435,
4205,
63,
2796,
14,
3346,
3110,
14,
27356,
819,
485,
13160,
2054,
63,
2632,
275,
283,
3364,
2851,
7,
819,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
4205,
63,
2796,
14,
3346,
3110,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
9,
272,
291,
14,
1813,
275,
488,
819,
347,
485,
8555,
8263,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
2589,
275,
291,
14,
5751,
8680,
8555,
8263,
418,
2031,
589,
12,
1011,
958,
9,
272,
291,
14,
1813,
275,
1331,
14,
8293,
8,
1813,
9,
272,
372,
2589,
421,
199,
533,
10191,
774,
8,
20363,
63,
396,
63,
773,
14,
3346,
29008,
1746,
304,
523,
408,
774,
314,
1798,
1041,
523,
347,
511,
6241,
8,
277,
304,
272,
408,
2925,
626,
4154,
2893,
1798,
5419,
12252,
1041,
272,
543,
4420,
18083,
14939,
3110,
8,
267,
14574,
3576,
297,
15610,
11135,
281,
3346,
14,
23368,
467,
267,
1300,
63,
589,
2968,
306,
1637,
13,
694,
297,
291,
14,
11567,
566,
465,
15865,
26,
489,
291,
14,
2947,
8,
11146,
14,
3615,
14,
1419,
14,
3576,
12,
15610,
11135,
281,
3346,
14,
23368,
9,
489,
291,
14,
2947,
8,
11146,
14,
3615,
14,
1419,
14,
1637,
63,
694,
12,
291,
14,
11567,
9,
421,
199,
318,
485,
8021,
5116,
3346,
1547,
277,
12,
931,
12,
2053,
12,
29666,
958,
304,
523,
408,
9167,
370,
20577,
282,
598,
51,
11247,
3439,
1041,
523,
543,
747,
1208,
14,
29008,
342,
465,
21628,
26,
272,
2257,
63,
515,
275,
747,
14,
515,
14,
904,
8,
11567,
12,
747,
14,
515,
14,
4846,
8,
515,
430,
272,
747,
1208,
14,
52,
13087,
8,
1832,
63,
515,
9,
272,
5145,
14,
1185,
8,
1832,
63,
515,
12,
2053,
9,
421,
199,
318,
485,
14403,
3346,
35,
2347,
8,
70,
304,
523,
408,
1646,
626,
15620,
5936,
2235,
1009,
3346,
83,
787,
8239,
14,
819,
9336,
2235,
1009,
3346,
1630,
440,
2291,
6032,
1683,
316,
12,
781,
1929,
370,
1642,
1240,
523,
3631,
342,
641,
314,
6890,
2166,
2235,
1009,
3346,
334,
6777,
365,
3032,
315,
370,
2739,
680,
221,
2136,
2066,
523,
295,
13,
928,
342,
314,
6890,
2166,
12188,
24234,
314,
1067,
14,
523,
408,
523,
347,
892,
63,
70,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
340,
440,
291,
14,
287,
3014,
26,
489,
862,
26,
267,
291,
14,
287,
3014,
275,
715,
267,
327,
12540,
269,
11406,
3507,
6890,
598,
51,
2998,
1683,
2544,
6617,
4154,
1683,
14,
267,
327,
3254,
8,
1195,
1907,
304,
1696,
794,
642,
2225,
436,
2387,
315,
7417,
63,
1805,
14,
647,
14,
267,
367,
325,
1805,
315,
291,
14,
5159,
63,
25191,
26,
881,
325,
1805,
14,
2379,
342,
398,
543,
291,
14,
458,
63,
1805,
26,
881,
372,
289,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
489,
3753,
26,
267,
291,
14,
287,
3014,
275,
756,
267,
367,
325,
1805,
315,
291,
14,
5159,
63,
25191,
26,
881,
325,
1805,
14,
928,
342,
272,
587,
26,
489,
372,
289,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
523,
372,
892,
63,
70,
421,
199,
533,
15610,
11135,
281,
3346,
8,
6672,
63,
1805,
14,
18192,
3346,
304,
523,
408,
17473,
1683,
316,
9330,
367,
15610,
11135,
281,
1041,
819,
26134,
275,
283,
23473,
1175,
14,
20363,
14,
4405,
14,
20363,
63,
9887,
63,
9277,
14,
14939,
11135,
281,
7,
523,
10762,
51,
275,
25038,
826,
7500,
283,
1002,
9042,
3353,
297,
2513,
1002,
5142,
297,
2513,
4152,
24818,
8571,
297,
1779,
283,
4152,
2698,
3353,
358,
819,
25699,
63,
8314,
275,
408,
199,
91,
523,
298,
19267,
582,
2097,
88,
1184,
13,
24421,
2255,
523,
298,
20363,
13,
1023,
582,
298,
821,
14,
1276,
2824,
14,
18,
401,
523,
298,
2343,
13,
1023,
582,
298,
17,
401,
523,
298,
3018,
13,
4269,
582,
298,
1506,
2564,
13,
77,
18,
14,
1939,
320,
14,
13211,
14,
1308,
401,
523,
298,
3018,
13,
888,
582,
298,
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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
] |
adamtiger/tensorflow
|
tensorflow/contrib/distributions/python/ops/bijectors/inline_impl.py
|
82
|
5595
|
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Inline bijector."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.python.ops.distributions import bijector
__all__ = [
"Inline",
]
class Inline(bijector.Bijector):
"""Bijector constructed from custom callables.
Example Use:
```python
exp = Inline(
forward_fn=tf.exp,
inverse_fn=tf.log,
inverse_log_det_jacobian_fn=(
lambda y: -tf.reduce_sum(tf.log(y), axis=-1)),
name="exp")
```
The above example is equivalent to the `Bijector` `Exp(event_ndims=1)`.
"""
def __init__(self,
forward_fn=None,
inverse_fn=None,
inverse_log_det_jacobian_fn=None,
forward_log_det_jacobian_fn=None,
forward_event_shape_fn=None,
forward_event_shape_tensor_fn=None,
inverse_event_shape_fn=None,
inverse_event_shape_tensor_fn=None,
is_constant_jacobian=False,
validate_args=False,
name="inline"):
"""Creates a `Bijector` from callables.
Args:
forward_fn: Python callable implementing the forward transformation.
inverse_fn: Python callable implementing the inverse transformation.
inverse_log_det_jacobian_fn: Python callable implementing the
log o det o jacobian of the inverse transformation.
forward_log_det_jacobian_fn: Python callable implementing the
log o det o jacobian of the forward transformation.
forward_event_shape_fn: Python callable implementing non-identical
static event shape changes. Default: shape is assumed unchanged.
forward_event_shape_tensor_fn: Python callable implementing non-identical
event shape changes. Default: shape is assumed unchanged.
inverse_event_shape_fn: Python callable implementing non-identical
static event shape changes. Default: shape is assumed unchanged.
inverse_event_shape_tensor_fn: Python callable implementing non-identical
event shape changes. Default: shape is assumed unchanged.
is_constant_jacobian: Python `bool` indicating that the Jacobian is
constant for all input arguments.
validate_args: Python `bool` indicating whether arguments should be
checked for correctness.
name: Python `str`, name given to ops managed by this object.
"""
super(Inline, self).__init__(
event_ndims=0,
is_constant_jacobian=is_constant_jacobian,
validate_args=validate_args,
name=name)
self._forward_fn = forward_fn
self._inverse_fn = inverse_fn
self._inverse_log_det_jacobian_fn = inverse_log_det_jacobian_fn
self._forward_log_det_jacobian_fn = forward_log_det_jacobian_fn
self._forward_event_shape_fn = forward_event_shape_fn
self._forward_event_shape_tensor_fn = forward_event_shape_tensor_fn
self._inverse_event_shape_fn = inverse_event_shape_fn
self._inverse_event_shape_tensor_fn = inverse_event_shape_tensor_fn
def _forward_event_shape(self, input_shape):
if self._forward_event_shape_fn is None:
# By default assume shape doesn't change.
return input_shape
return self._forward_event_shape_fn(input_shape)
def _forward_event_shape_tensor(self, input_shape):
if self._forward_event_shape_tensor_fn is None:
# By default assume shape doesn't change.
return input_shape
return self._forward_event_shape_tensor_fn(input_shape)
def _inverse_event_shape(self, output_shape):
if self._inverse_event_shape_fn is None:
# By default assume shape doesn't change.
return output_shape
return self._inverse_event_shape_fn(output_shape)
def _inverse_event_shape_tensor(self, output_shape):
if self._inverse_event_shape_tensor_fn is None:
# By default assume shape doesn't change.
return output_shape
return self._inverse_event_shape_tensor_fn(output_shape)
def _forward(self, x, **kwargs):
if not callable(self._forward_fn):
raise NotImplementedError(
"forward_fn is not a callable function.")
return self._forward_fn(x, **kwargs)
def _inverse(self, y, **kwargs):
if not callable(self._inverse_fn):
raise NotImplementedError(
"inverse_fn is not a callable function.")
return self._inverse_fn(y, **kwargs)
def _inverse_log_det_jacobian(self, y, **kwargs):
if not callable(self._inverse_log_det_jacobian_fn):
raise NotImplementedError(
"inverse_log_det_jacobian_fn is not a callable function.")
return self._inverse_log_det_jacobian_fn(y, **kwargs)
def _forward_log_det_jacobian(self, y, **kwargs):
if not callable(self._forward_log_det_jacobian_fn):
raise NotImplementedError(
"forward_log_det_jacobian_fn is not a callable function.")
return self._forward_log_det_jacobian_fn(y, **kwargs)
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
10307,
12111,
19625,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
492,
12111,
19625,
421,
199,
363,
452,
363,
275,
359,
272,
298,
10307,
401,
199,
61,
421,
199,
533,
24789,
8,
4492,
19625,
14,
17975,
19625,
304,
523,
408,
17975,
19625,
14701,
687,
3537,
28041,
14,
819,
5679,
3645,
26,
819,
10841,
1548,
523,
1437,
275,
24789,
8,
272,
7568,
63,
2324,
29,
3249,
14,
1474,
12,
272,
11484,
63,
2324,
29,
3249,
14,
793,
12,
272,
11484,
63,
793,
63,
9886,
63,
27342,
63,
2324,
2687,
489,
2400,
612,
26,
446,
3249,
14,
5270,
63,
1838,
8,
3249,
14,
793,
8,
89,
395,
3114,
4022,
17,
1826,
272,
536,
628,
1474,
531,
523,
10841,
819,
710,
3432,
2893,
365,
7353,
370,
314,
658,
17975,
19625,
64,
658,
4527,
8,
1430,
63,
13575,
29,
17,
20414,
523,
408,
819,
347,
636,
826,
721,
277,
12,
2049,
7568,
63,
2324,
29,
403,
12,
2049,
11484,
63,
2324,
29,
403,
12,
2049,
11484,
63,
793,
63,
9886,
63,
27342,
63,
2324,
29,
403,
12,
2049,
7568,
63,
793,
63,
9886,
63,
27342,
63,
2324,
29,
403,
12,
2049,
7568,
63,
1430,
63,
1392,
63,
2324,
29,
403,
12,
2049,
7568,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
29,
403,
12,
2049,
11484,
63,
1430,
63,
1392,
63,
2324,
29,
403,
12,
2049,
11484,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
29,
403,
12,
2049,
365,
63,
4083,
63,
27342,
29,
797,
12,
2049,
4107,
63,
589,
29,
797,
12,
2049,
536,
628,
6460,
2349,
272,
408,
10607,
282,
658,
17975,
19625,
64,
687,
28041,
14,
339,
3033,
26,
489,
7568,
63,
2324,
26,
2018,
4550,
18234,
314,
7568,
13315,
14,
489,
11484,
63,
2324,
26,
2018,
4550,
18234,
314,
11484,
13315,
14,
489,
11484,
63,
793,
63,
9886,
63,
27342,
63,
2324,
26,
2018,
4550,
18234,
314,
267,
943,
312,
20894,
312,
1335,
22065,
402,
314,
11484,
13315,
14,
489,
7568,
63,
793,
63,
9886,
63,
27342,
63,
2324,
26,
2018,
4550,
18234,
314,
267,
943,
312,
20894,
312,
1335,
22065,
402,
314,
7568,
13315,
14,
489,
7568,
63,
1430,
63,
1392,
63,
2324,
26,
2018,
4550,
18234,
2222,
13,
14576,
267,
2955,
1566,
2215,
4493,
14,
3758,
26,
2215,
365,
10826,
14874,
14,
489,
7568,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
26,
2018,
4550,
18234,
2222,
13,
14576,
267,
1566,
2215,
4493,
14,
3758,
26,
2215,
365,
10826,
14874,
14,
489,
11484,
63,
1430,
63,
1392,
63,
2324,
26,
2018,
4550,
18234,
2222,
13,
14576,
267,
2955,
1566,
2215,
4493,
14,
3758,
26,
2215,
365,
10826,
14874,
14,
489,
11484,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
26,
2018,
4550,
18234,
2222,
13,
14576,
267,
1566,
2215,
4493,
14,
3758,
26,
2215,
365,
10826,
14874,
14,
489,
365,
63,
4083,
63,
27342,
26,
2018,
658,
2245,
64,
9297,
626,
314,
30633,
365,
267,
4413,
367,
1006,
1324,
2368,
14,
489,
4107,
63,
589,
26,
2018,
658,
2245,
64,
9297,
3775,
2368,
1077,
506,
267,
7923,
367,
29102,
14,
489,
536,
26,
2018,
658,
495,
3559,
536,
1627,
370,
4156,
12883,
701,
642,
909,
14,
272,
408,
272,
1613,
8,
10307,
12,
291,
2843,
826,
721,
267,
1566,
63,
13575,
29,
16,
12,
267,
365,
63,
4083,
63,
27342,
29,
374,
63,
4083,
63,
27342,
12,
267,
4107,
63,
589,
29,
3502,
63,
589,
12,
267,
536,
29,
354,
9,
272,
291,
423,
6688,
63,
2324,
275,
7568,
63,
2324,
272,
291,
423,
11668,
63,
2324,
275,
11484,
63,
2324,
272,
291,
423,
11668,
63,
793,
63,
9886,
63,
27342,
63,
2324,
275,
11484,
63,
793,
63,
9886,
63,
27342,
63,
2324,
272,
291,
423,
6688,
63,
793,
63,
9886,
63,
27342,
63,
2324,
275,
7568,
63,
793,
63,
9886,
63,
27342,
63,
2324,
272,
291,
423,
6688,
63,
1430,
63,
1392,
63,
2324,
275,
7568,
63,
1430,
63,
1392,
63,
2324,
272,
291,
423,
6688,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
275,
7568,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
272,
291,
423,
11668,
63,
1430,
63,
1392,
63,
2324,
275,
11484,
63,
1430,
63,
1392,
63,
2324,
272,
291,
423,
11668,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
275,
11484,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
819,
347,
485,
6688,
63,
1430,
63,
1392,
8,
277,
12,
1324,
63,
1392,
304,
272,
340,
291,
423,
6688,
63,
1430,
63,
1392,
63,
2324,
365,
488,
26,
489,
327,
4885,
849,
5534,
2215,
3181,
1133,
1570,
14,
489,
372,
1324,
63,
1392,
272,
372,
291,
423,
6688,
63,
1430,
63,
1392,
63,
2324,
8,
1210,
63,
1392,
9,
819,
347,
485,
6688,
63,
1430,
63,
1392,
63,
3128,
8,
277,
12,
1324,
63,
1392,
304,
272,
340,
291,
423,
6688,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
365,
488,
26,
489,
327,
4885,
849,
5534,
2215,
3181,
1133,
1570,
14,
489,
372,
1324,
63,
1392,
272,
372,
291,
423,
6688,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
8,
1210,
63,
1392,
9,
819,
347,
485,
11668,
63,
1430,
63,
1392,
8,
277,
12,
1072,
63,
1392
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
10307,
12111,
19625,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
492,
12111,
19625,
421,
199,
363,
452,
363,
275,
359,
272,
298,
10307,
401,
199,
61,
421,
199,
533,
24789,
8,
4492,
19625,
14,
17975,
19625,
304,
523,
408,
17975,
19625,
14701,
687,
3537,
28041,
14,
819,
5679,
3645,
26,
819,
10841,
1548,
523,
1437,
275,
24789,
8,
272,
7568,
63,
2324,
29,
3249,
14,
1474,
12,
272,
11484,
63,
2324,
29,
3249,
14,
793,
12,
272,
11484,
63,
793,
63,
9886,
63,
27342,
63,
2324,
2687,
489,
2400,
612,
26,
446,
3249,
14,
5270,
63,
1838,
8,
3249,
14,
793,
8,
89,
395,
3114,
4022,
17,
1826,
272,
536,
628,
1474,
531,
523,
10841,
819,
710,
3432,
2893,
365,
7353,
370,
314,
658,
17975,
19625,
64,
658,
4527,
8,
1430,
63,
13575,
29,
17,
20414,
523,
408,
819,
347,
636,
826,
721,
277,
12,
2049,
7568,
63,
2324,
29,
403,
12,
2049,
11484,
63,
2324,
29,
403,
12,
2049,
11484,
63,
793,
63,
9886,
63,
27342,
63,
2324,
29,
403,
12,
2049,
7568,
63,
793,
63,
9886,
63,
27342,
63,
2324,
29,
403,
12,
2049,
7568,
63,
1430,
63,
1392,
63,
2324,
29,
403,
12,
2049,
7568,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
29,
403,
12,
2049,
11484,
63,
1430,
63,
1392,
63,
2324,
29,
403,
12,
2049,
11484,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
29,
403,
12,
2049,
365,
63,
4083,
63,
27342,
29,
797,
12,
2049,
4107,
63,
589,
29,
797,
12,
2049,
536,
628,
6460,
2349,
272,
408,
10607,
282,
658,
17975,
19625,
64,
687,
28041,
14,
339,
3033,
26,
489,
7568,
63,
2324,
26,
2018,
4550,
18234,
314,
7568,
13315,
14,
489,
11484,
63,
2324,
26,
2018,
4550,
18234,
314,
11484,
13315,
14,
489,
11484,
63,
793,
63,
9886,
63,
27342,
63,
2324,
26,
2018,
4550,
18234,
314,
267,
943,
312,
20894,
312,
1335,
22065,
402,
314,
11484,
13315,
14,
489,
7568,
63,
793,
63,
9886,
63,
27342,
63,
2324,
26,
2018,
4550,
18234,
314,
267,
943,
312,
20894,
312,
1335,
22065,
402,
314,
7568,
13315,
14,
489,
7568,
63,
1430,
63,
1392,
63,
2324,
26,
2018,
4550,
18234,
2222,
13,
14576,
267,
2955,
1566,
2215,
4493,
14,
3758,
26,
2215,
365,
10826,
14874,
14,
489,
7568,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
26,
2018,
4550,
18234,
2222,
13,
14576,
267,
1566,
2215,
4493,
14,
3758,
26,
2215,
365,
10826,
14874,
14,
489,
11484,
63,
1430,
63,
1392,
63,
2324,
26,
2018,
4550,
18234,
2222,
13,
14576,
267,
2955,
1566,
2215,
4493,
14,
3758,
26,
2215,
365,
10826,
14874,
14,
489,
11484,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
26,
2018,
4550,
18234,
2222,
13,
14576,
267,
1566,
2215,
4493,
14,
3758,
26,
2215,
365,
10826,
14874,
14,
489,
365,
63,
4083,
63,
27342,
26,
2018,
658,
2245,
64,
9297,
626,
314,
30633,
365,
267,
4413,
367,
1006,
1324,
2368,
14,
489,
4107,
63,
589,
26,
2018,
658,
2245,
64,
9297,
3775,
2368,
1077,
506,
267,
7923,
367,
29102,
14,
489,
536,
26,
2018,
658,
495,
3559,
536,
1627,
370,
4156,
12883,
701,
642,
909,
14,
272,
408,
272,
1613,
8,
10307,
12,
291,
2843,
826,
721,
267,
1566,
63,
13575,
29,
16,
12,
267,
365,
63,
4083,
63,
27342,
29,
374,
63,
4083,
63,
27342,
12,
267,
4107,
63,
589,
29,
3502,
63,
589,
12,
267,
536,
29,
354,
9,
272,
291,
423,
6688,
63,
2324,
275,
7568,
63,
2324,
272,
291,
423,
11668,
63,
2324,
275,
11484,
63,
2324,
272,
291,
423,
11668,
63,
793,
63,
9886,
63,
27342,
63,
2324,
275,
11484,
63,
793,
63,
9886,
63,
27342,
63,
2324,
272,
291,
423,
6688,
63,
793,
63,
9886,
63,
27342,
63,
2324,
275,
7568,
63,
793,
63,
9886,
63,
27342,
63,
2324,
272,
291,
423,
6688,
63,
1430,
63,
1392,
63,
2324,
275,
7568,
63,
1430,
63,
1392,
63,
2324,
272,
291,
423,
6688,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
275,
7568,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
272,
291,
423,
11668,
63,
1430,
63,
1392,
63,
2324,
275,
11484,
63,
1430,
63,
1392,
63,
2324,
272,
291,
423,
11668,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
275,
11484,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
819,
347,
485,
6688,
63,
1430,
63,
1392,
8,
277,
12,
1324,
63,
1392,
304,
272,
340,
291,
423,
6688,
63,
1430,
63,
1392,
63,
2324,
365,
488,
26,
489,
327,
4885,
849,
5534,
2215,
3181,
1133,
1570,
14,
489,
372,
1324,
63,
1392,
272,
372,
291,
423,
6688,
63,
1430,
63,
1392,
63,
2324,
8,
1210,
63,
1392,
9,
819,
347,
485,
6688,
63,
1430,
63,
1392,
63,
3128,
8,
277,
12,
1324,
63,
1392,
304,
272,
340,
291,
423,
6688,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
365,
488,
26,
489,
327,
4885,
849,
5534,
2215,
3181,
1133,
1570,
14,
489,
372,
1324,
63,
1392,
272,
372,
291,
423,
6688,
63,
1430,
63,
1392,
63,
3128,
63,
2324,
8,
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
] |
robbiet480/home-assistant
|
tests/components/counter/common.py
|
24
|
1035
|
"""Collection of helper methods.
All containing methods are legacy helpers that should not be used by new
components. Instead call the service directly.
"""
from homeassistant.components.counter import (
DOMAIN,
SERVICE_DECREMENT,
SERVICE_INCREMENT,
SERVICE_RESET,
)
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.core import callback
from homeassistant.loader import bind_hass
@callback
@bind_hass
def async_increment(hass, entity_id):
"""Increment a counter."""
hass.async_add_job(
hass.services.async_call(DOMAIN, SERVICE_INCREMENT, {ATTR_ENTITY_ID: entity_id})
)
@callback
@bind_hass
def async_decrement(hass, entity_id):
"""Decrement a counter."""
hass.async_add_job(
hass.services.async_call(DOMAIN, SERVICE_DECREMENT, {ATTR_ENTITY_ID: entity_id})
)
@callback
@bind_hass
def async_reset(hass, entity_id):
"""Reset a counter."""
hass.async_add_job(
hass.services.async_call(DOMAIN, SERVICE_RESET, {ATTR_ENTITY_ID: entity_id})
)
|
apache-2.0
|
[
624,
7768,
402,
5922,
3102,
14,
199,
199,
2422,
3035,
3102,
787,
12139,
10897,
626,
1077,
440,
506,
1202,
701,
892,
199,
4608,
14,
15345,
1240,
314,
2435,
5370,
14,
199,
624,
199,
504,
8846,
14,
4608,
14,
5337,
492,
334,
272,
15265,
12,
272,
16655,
63,
1093,
31431,
12,
272,
16655,
63,
568,
31431,
12,
272,
16655,
63,
18066,
12,
199,
9,
199,
504,
8846,
14,
1297,
492,
10762,
63,
13630,
63,
998,
199,
504,
8846,
14,
1018,
492,
3233,
199,
504,
8846,
14,
3422,
492,
5398,
63,
5387,
421,
199,
32,
3058,
199,
32,
3409,
63,
5387,
199,
318,
5316,
63,
9728,
8,
5387,
12,
4642,
63,
344,
304,
272,
408,
29485,
282,
7055,
1041,
272,
6298,
14,
4146,
63,
525,
63,
2423,
8,
267,
6298,
14,
5950,
14,
4146,
63,
1250,
8,
7378,
12,
16655,
63,
568,
31431,
12,
469,
5280,
63,
13630,
63,
998,
26,
4642,
63,
344,
1552,
272,
776,
421,
199,
32,
3058,
199,
32,
3409,
63,
5387,
199,
318,
5316,
63,
271,
4062,
8,
5387,
12,
4642,
63,
344,
304,
272,
408,
8584,
264,
434,
282,
7055,
1041,
272,
6298,
14,
4146,
63,
525,
63,
2423,
8,
267,
6298,
14,
5950,
14,
4146,
63,
1250,
8,
7378,
12,
16655,
63,
1093,
31431,
12,
469,
5280,
63,
13630,
63,
998,
26,
4642,
63,
344,
1552,
272,
776,
421,
199,
32,
3058,
199,
32,
3409,
63,
5387,
199,
318,
5316,
63,
3958,
8,
5387,
12,
4642,
63,
344,
304,
272,
408,
9637,
282,
7055,
1041,
272,
6298,
14,
4146,
63,
525,
63,
2423,
8,
267,
6298,
14,
5950,
14,
4146,
63,
1250,
8,
7378,
12,
16655,
63,
18066,
12,
469,
5280,
63,
13630,
63,
998,
26,
4642,
63,
344,
1552,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
7768,
402,
5922,
3102,
14,
199,
199,
2422,
3035,
3102,
787,
12139,
10897,
626,
1077,
440,
506,
1202,
701,
892,
199,
4608,
14,
15345,
1240,
314,
2435,
5370,
14,
199,
624,
199,
504,
8846,
14,
4608,
14,
5337,
492,
334,
272,
15265,
12,
272,
16655,
63,
1093,
31431,
12,
272,
16655,
63,
568,
31431,
12,
272,
16655,
63,
18066,
12,
199,
9,
199,
504,
8846,
14,
1297,
492,
10762,
63,
13630,
63,
998,
199,
504,
8846,
14,
1018,
492,
3233,
199,
504,
8846,
14,
3422,
492,
5398,
63,
5387,
421,
199,
32,
3058,
199,
32,
3409,
63,
5387,
199,
318,
5316,
63,
9728,
8,
5387,
12,
4642,
63,
344,
304,
272,
408,
29485,
282,
7055,
1041,
272,
6298,
14,
4146,
63,
525,
63,
2423,
8,
267,
6298,
14,
5950,
14,
4146,
63,
1250,
8,
7378,
12,
16655,
63,
568,
31431,
12,
469,
5280,
63,
13630,
63,
998,
26,
4642,
63,
344,
1552,
272,
776,
421,
199,
32,
3058,
199,
32,
3409,
63,
5387,
199,
318,
5316,
63,
271,
4062,
8,
5387,
12,
4642,
63,
344,
304,
272,
408,
8584,
264,
434,
282,
7055,
1041,
272,
6298,
14,
4146,
63,
525,
63,
2423,
8,
267,
6298,
14,
5950,
14,
4146,
63,
1250,
8,
7378,
12,
16655,
63,
1093,
31431,
12,
469,
5280,
63,
13630,
63,
998,
26,
4642,
63,
344,
1552,
272,
776,
421,
199,
32,
3058,
199,
32,
3409,
63,
5387,
199,
318,
5316,
63,
3958,
8,
5387,
12,
4642,
63,
344,
304,
272,
408,
9637,
282,
7055,
1041,
272,
6298,
14,
4146,
63,
525,
63,
2423,
8,
267,
6298,
14,
5950,
14,
4146,
63,
1250,
8,
7378,
12,
16655,
63,
18066,
12,
469,
5280,
63,
13630,
63,
998,
26,
4642,
63,
344,
1552,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
yfried/ansible
|
lib/ansible/modules/network/radware/vdirect_file.py
|
27
|
9278
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright 2017 Radware LTD.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'status': ['preview'],
'supported_by': 'community',
'metadata_version': '1.1'}
DOCUMENTATION = '''
module: vdirect_file
author: Evgeny Fedoruk @ Radware LTD (@evgenyfedoruk)
short_description: Uploads a new or updates an existing runnable file into Radware vDirect server
description:
- Uploads a new or updates an existing configuration template or workflow template into the Radware vDirect server.
All parameters may be set as environment variables.
notes:
- Requires the Radware vdirect-client Python package on the host. This is as easy as
C(pip install vdirect-client)
version_added: "2.4"
options:
vdirect_ip:
description:
- Primary vDirect server IP address, may be set as VDIRECT_IP environment variable.
required: true
vdirect_user:
description:
- vDirect server username, may be set as VDIRECT_USER environment variable.
required: true
vdirect_password:
description:
- vDirect server password, may be set as VDIRECT_PASSWORD environment variable.
required: true
vdirect_secondary_ip:
description:
- Secondary vDirect server IP address, may be set as VDIRECT_SECONDARY_IP environment variable.
vdirect_wait:
description:
- Wait for async operation to complete, may be set as VDIRECT_WAIT environment variable.
type: bool
default: 'yes'
vdirect_https_port:
description:
- vDirect server HTTPS port number, may be set as VDIRECT_HTTPS_PORT environment variable.
default: 2189
vdirect_http_port:
description:
- vDirect server HTTP port number, may be set as VDIRECT_HTTP_PORT environment variable.
default: 2188
vdirect_timeout:
description:
- Amount of time to wait for async operation completion [seconds],
- may be set as VDIRECT_TIMEOUT environment variable.
default: 60
vdirect_use_ssl:
description:
- If C(no), an HTTP connection will be used instead of the default HTTPS connection,
- may be set as VDIRECT_HTTPS or VDIRECT_USE_SSL environment variable.
type: bool
default: 'yes'
vdirect_validate_certs:
description:
- If C(no), SSL certificates will not be validated,
- may be set as VDIRECT_VALIDATE_CERTS or VDIRECT_VERIFY environment variable.
- This should only set to C(no) used on personally controlled sites using self-signed certificates.
type: bool
default: 'yes'
file_name:
description:
- vDirect runnable file name to be uploaded.
- May be velocity configuration template (.vm) or workflow template zip file (.zip).
required: true
requirements:
- "vdirect-client >= 4.1.1"
'''
EXAMPLES = '''
- name: vdirect_file
vdirect_file:
vdirect_ip: 10.10.10.10
vdirect_user: vDirect
vdirect_password: radware
file_name: /tmp/get_vlans.vm
'''
RETURN = '''
result:
description: Message detailing upload result
returned: success
type: string
sample: "Workflow template created"
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import env_fallback
import os
import os.path
try:
from vdirect_client import rest_client
HAS_REST_CLIENT = True
except ImportError:
HAS_REST_CLIENT = False
TEMPLATE_EXTENSION = '.vm'
WORKFLOW_EXTENSION = '.zip'
WRONG_EXTENSION_ERROR = 'The file_name parameter must have ' \
'velocity script (.vm) extension or ZIP archive (.zip) extension'
CONFIGURATION_TEMPLATE_CREATED_SUCCESS = 'Configuration template created'
CONFIGURATION_TEMPLATE_UPDATED_SUCCESS = 'Configuration template updated'
WORKFLOW_TEMPLATE_CREATED_SUCCESS = 'Workflow template created'
WORKFLOW_TEMPLATE_UPDATED_SUCCESS = 'Workflow template updated'
meta_args = dict(
vdirect_ip=dict(required=True, fallback=(env_fallback, ['VDIRECT_IP'])),
vdirect_user=dict(required=True, fallback=(env_fallback, ['VDIRECT_USER'])),
vdirect_password=dict(
required=True, fallback=(env_fallback, ['VDIRECT_PASSWORD']),
no_log=True, type='str'),
vdirect_secondary_ip=dict(
required=False, fallback=(env_fallback, ['VDIRECT_SECONDARY_IP']),
default=None),
vdirect_use_ssl=dict(
required=False, fallback=(env_fallback, ['VDIRECT_HTTPS', 'VDIRECT_USE_SSL']),
default=True, type='bool'),
vdirect_wait=dict(
required=False, fallback=(env_fallback, ['VDIRECT_WAIT']),
default=True, type='bool'),
vdirect_timeout=dict(
required=False, fallback=(env_fallback, ['VDIRECT_TIMEOUT']),
default=60, type='int'),
vdirect_validate_certs=dict(
required=False, fallback=(env_fallback, ['VDIRECT_VERIFY', 'VDIRECT_VALIDATE_CERTS']),
default=True, type='bool'),
vdirect_https_port=dict(
required=False, fallback=(env_fallback, ['VDIRECT_HTTPS_PORT']),
default=2189, type='int'),
vdirect_http_port=dict(
required=False, fallback=(env_fallback, ['VDIRECT_HTTP_PORT']),
default=2188, type='int'),
file_name=dict(required=True)
)
class FileException(Exception):
def __init__(self, reason, details):
self.reason = reason
self.details = details
def __str__(self):
return 'Reason: {0}. Details:{1}.'.format(self.reason, self.details)
class InvalidSourceException(FileException):
def __init__(self, message):
super(InvalidSourceException, self).__init__(
'Error parsing file', repr(message))
class VdirectFile(object):
def __init__(self, params):
self.client = rest_client.RestClient(params['vdirect_ip'],
params['vdirect_user'],
params['vdirect_password'],
wait=params['vdirect_wait'],
secondary_vdirect_ip=params['vdirect_secondary_ip'],
https_port=params['vdirect_https_port'],
http_port=params['vdirect_http_port'],
timeout=params['vdirect_timeout'],
https=params['vdirect_use_ssl'],
verify=params['vdirect_validate_certs'])
def upload(self, fqn):
if fqn.endswith(TEMPLATE_EXTENSION):
template_name = os.path.basename(fqn)
template = rest_client.Template(self.client)
runnable_file = open(fqn, 'r')
file_content = runnable_file.read()
result_to_return = CONFIGURATION_TEMPLATE_CREATED_SUCCESS
result = template.create_from_source(file_content, template_name, fail_if_invalid=True)
if result[rest_client.RESP_STATUS] == 409:
result_to_return = CONFIGURATION_TEMPLATE_UPDATED_SUCCESS
result = template.upload_source(file_content, template_name, fail_if_invalid=True)
if result[rest_client.RESP_STATUS] == 400:
raise InvalidSourceException(str(result[rest_client.RESP_STR]))
elif fqn.endswith(WORKFLOW_EXTENSION):
workflow = rest_client.WorkflowTemplate(self.client)
runnable_file = open(fqn, 'rb')
file_content = runnable_file.read()
result_to_return = WORKFLOW_TEMPLATE_CREATED_SUCCESS
result = workflow.create_template_from_archive(file_content, fail_if_invalid=True)
if result[rest_client.RESP_STATUS] == 409:
result_to_return = WORKFLOW_TEMPLATE_UPDATED_SUCCESS
result = workflow.update_archive(file_content, os.path.splitext(os.path.basename(fqn))[0])
if result[rest_client.RESP_STATUS] == 400:
raise InvalidSourceException(str(result[rest_client.RESP_STR]))
else:
result_to_return = WRONG_EXTENSION_ERROR
return result_to_return
def main():
module = AnsibleModule(argument_spec=meta_args)
if not HAS_REST_CLIENT:
module.fail_json(msg="The python vdirect-client module is required")
try:
vdirect_file = VdirectFile(module.params)
result = vdirect_file.upload(module.params['file_name'])
result = dict(result=result)
module.exit_json(**result)
except Exception as e:
module.fail_json(msg=str(e))
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
221,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
9708,
820,
350,
1068,
24368,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
199,
199,
8490,
63,
8314,
275,
791,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
2343,
63,
1023,
356,
283,
17,
14,
17,
936,
199,
199,
8948,
275,
1449,
199,
578,
26,
373,
2275,
63,
493,
199,
2502,
26,
662,
86,
2268,
89,
481,
379,
269,
3210,
768,
820,
350,
1068,
24368,
8593,
6857,
2268,
89,
15800,
269,
3210,
9,
199,
3612,
63,
1802,
26,
4949,
3640,
282,
892,
503,
7029,
376,
3411,
1255,
25757,
570,
1901,
820,
350,
1068,
373,
16281,
1654,
199,
1802,
26,
272,
446,
4949,
3640,
282,
892,
503,
7029,
376,
3411,
2897,
1978,
503,
10431,
1978,
1901,
314,
820,
350,
1068,
373,
16281,
1654,
14,
489,
2900,
2633,
1443,
506,
663,
465,
3734,
2860,
14,
199,
5983,
26,
272,
446,
15127,
314,
820,
350,
1068,
373,
2275,
13,
1258,
2018,
2559,
641,
314,
1591,
14,
961,
365,
465,
8837,
465,
489,
445,
8,
9983,
3907,
373,
2275,
13,
1258,
9,
199,
1023,
63,
3270,
26,
298,
18,
14,
20,
2,
199,
1419,
26,
523,
373,
2275,
63,
711,
26,
272,
1369,
26,
1362,
446,
26710,
373,
16281,
1654,
3531,
2287,
12,
1443,
506,
663,
465,
812,
6098,
63,
1772,
3734,
1750,
14,
272,
1415,
26,
2549,
523,
373,
2275,
63,
751,
26,
272,
1369,
26,
1362,
446,
373,
16281,
1654,
3434,
12,
1443,
506,
663,
465,
812,
6098,
63,
3791,
3734,
1750,
14,
272,
1415,
26,
2549,
523,
373,
2275,
63,
2060,
26,
272,
1369,
26,
1362,
446,
373,
16281,
1654,
2505,
12,
1443,
506,
663,
465,
812,
6098,
63,
9032,
3734,
1750,
14,
272,
1415,
26,
2549,
523,
373,
2275,
63,
12371,
63,
711,
26,
272,
1369,
26,
1362,
446,
16707,
695,
373,
16281,
1654,
3531,
2287,
12,
1443,
506,
663,
465,
812,
6098,
63,
24236,
4392,
63,
1772,
3734,
1750,
14,
523,
373,
2275,
63,
2573,
26,
272,
1369,
26,
1362,
446,
13144,
367,
5316,
3439,
370,
4890,
12,
1443,
506,
663,
465,
812,
6098,
63,
12458,
3734,
1750,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
5066,
7,
523,
373,
2275,
63,
2859,
63,
719,
26,
272,
1369,
26,
1362,
446,
373,
16281,
1654,
14147,
1844,
1329,
12,
1443,
506,
663,
465,
812,
6098,
63,
14921,
63,
3657,
3734,
1750,
14,
272,
849,
26,
499,
11370,
523,
373,
2275,
63,
1014,
63,
719,
26,
272,
1369,
26,
1362,
446,
373,
16281,
1654,
3101,
1844,
1329,
12,
1443,
506,
663,
465,
812,
6098,
63,
2856,
63,
3657,
3734,
1750,
14,
272,
849,
26,
499,
11501,
523,
373,
2275,
63,
2593,
26,
272,
1369,
26,
1362,
446,
26701,
402,
900,
370,
3618,
367,
5316,
3439,
13659,
359,
4515,
467,
1362,
446,
1443,
506,
663,
465,
812,
6098,
63,
8899,
3734,
1750,
14,
272,
849,
26,
5212,
523,
373,
2275,
63,
1180,
63,
4266,
26,
272,
1369,
26,
1362,
446,
982,
445,
8,
889,
395,
376,
3101,
1950,
911,
506,
1202,
3140,
402,
314,
849,
14147,
1950,
12,
1362,
446,
1443,
506,
663,
465,
812,
6098,
63,
14921,
503,
812,
6098,
63,
4701,
63,
5413,
3734,
1750,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
5066,
7,
523,
373,
2275,
63,
3502,
63,
8356,
26,
272,
1369,
26,
1362,
446,
982,
445,
8,
889,
395,
7799,
14512,
911,
440,
506,
16468,
12,
1362,
446,
1443,
506,
663,
465,
812,
6098,
63,
5600,
1951,
63,
11163,
51,
503,
812,
6098,
63,
22443,
3734,
1750,
14,
1362,
446,
961,
1077,
1454,
663,
370,
445,
8,
889,
9,
1202,
641,
4954,
1183,
22284,
15424,
1808,
291,
13,
1737,
14512,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
5066,
7,
523,
570,
63,
354,
26,
272,
1369,
26,
1362,
446,
373,
16281,
1255,
25757,
570,
536,
370,
506,
14238,
14,
1362,
446,
10162,
506,
20508,
2897,
1978,
17048,
2611,
9,
503,
10431,
1978,
3482,
570,
17048,
3065,
680,
272,
1415,
26,
2549,
199,
199,
7538,
26,
523,
446,
298,
86,
2275,
13,
1258,
2356,
841,
14,
17,
14,
17,
2,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
373,
2275,
63,
493,
523,
373,
2275,
63,
493,
26,
489,
373,
2275,
63,
711,
26,
1616,
14,
709,
14,
709,
14,
709,
489,
373,
2275,
63,
751,
26,
373,
16281,
489,
373,
2275,
63,
2060,
26,
28880,
1068,
489,
570,
63,
354,
26,
1182,
2791,
15,
362,
63,
18424,
14,
2611,
199,
2344,
199,
199,
9677,
275,
1449,
199,
1099,
26,
272,
1369,
26,
6430,
10093,
316,
5802,
754,
272,
2138,
26,
3182,
272,
730,
26,
1059,
272,
2690,
26,
298,
17527,
1978,
2737,
2,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
2589,
63,
10538,
199,
646,
747,
199,
646,
747,
14,
515,
199,
199,
893,
26,
272,
687,
373,
2275,
63,
1258,
492,
4618,
63,
1258,
272,
7509,
63,
15740,
63,
9901,
275,
715,
199
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
221,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
9708,
820,
350,
1068,
24368,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
199,
199,
8490,
63,
8314,
275,
791,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
2343,
63,
1023,
356,
283,
17,
14,
17,
936,
199,
199,
8948,
275,
1449,
199,
578,
26,
373,
2275,
63,
493,
199,
2502,
26,
662,
86,
2268,
89,
481,
379,
269,
3210,
768,
820,
350,
1068,
24368,
8593,
6857,
2268,
89,
15800,
269,
3210,
9,
199,
3612,
63,
1802,
26,
4949,
3640,
282,
892,
503,
7029,
376,
3411,
1255,
25757,
570,
1901,
820,
350,
1068,
373,
16281,
1654,
199,
1802,
26,
272,
446,
4949,
3640,
282,
892,
503,
7029,
376,
3411,
2897,
1978,
503,
10431,
1978,
1901,
314,
820,
350,
1068,
373,
16281,
1654,
14,
489,
2900,
2633,
1443,
506,
663,
465,
3734,
2860,
14,
199,
5983,
26,
272,
446,
15127,
314,
820,
350,
1068,
373,
2275,
13,
1258,
2018,
2559,
641,
314,
1591,
14,
961,
365,
465,
8837,
465,
489,
445,
8,
9983,
3907,
373,
2275,
13,
1258,
9,
199,
1023,
63,
3270,
26,
298,
18,
14,
20,
2,
199,
1419,
26,
523,
373,
2275,
63,
711,
26,
272,
1369,
26,
1362,
446,
26710,
373,
16281,
1654,
3531,
2287,
12,
1443,
506,
663,
465,
812,
6098,
63,
1772,
3734,
1750,
14,
272,
1415,
26,
2549,
523,
373,
2275,
63,
751,
26,
272,
1369,
26,
1362,
446,
373,
16281,
1654,
3434,
12,
1443,
506,
663,
465,
812,
6098,
63,
3791,
3734,
1750,
14,
272,
1415,
26,
2549,
523,
373,
2275,
63,
2060,
26,
272,
1369,
26,
1362,
446,
373,
16281,
1654,
2505,
12,
1443,
506,
663,
465,
812,
6098,
63,
9032,
3734,
1750,
14,
272,
1415,
26,
2549,
523,
373,
2275,
63,
12371,
63,
711,
26,
272,
1369,
26,
1362,
446,
16707,
695,
373,
16281,
1654,
3531,
2287,
12,
1443,
506,
663,
465,
812,
6098,
63,
24236,
4392,
63,
1772,
3734,
1750,
14,
523,
373,
2275,
63,
2573,
26,
272,
1369,
26,
1362,
446,
13144,
367,
5316,
3439,
370,
4890,
12,
1443,
506,
663,
465,
812,
6098,
63,
12458,
3734,
1750,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
5066,
7,
523,
373,
2275,
63,
2859,
63,
719,
26,
272,
1369,
26,
1362,
446,
373,
16281,
1654,
14147,
1844,
1329,
12,
1443,
506,
663,
465,
812,
6098,
63,
14921,
63,
3657,
3734,
1750,
14,
272,
849,
26,
499,
11370,
523,
373,
2275,
63,
1014,
63,
719,
26,
272,
1369,
26,
1362,
446,
373,
16281,
1654,
3101,
1844,
1329,
12,
1443,
506,
663,
465,
812,
6098,
63,
2856,
63,
3657,
3734,
1750,
14,
272,
849,
26,
499,
11501,
523,
373,
2275,
63,
2593,
26,
272,
1369,
26,
1362,
446,
26701,
402,
900,
370,
3618,
367,
5316,
3439,
13659,
359,
4515,
467,
1362,
446,
1443,
506,
663,
465,
812,
6098,
63,
8899,
3734,
1750,
14,
272,
849,
26,
5212,
523,
373,
2275,
63,
1180,
63,
4266,
26,
272,
1369,
26,
1362,
446,
982,
445,
8,
889,
395,
376,
3101,
1950,
911,
506,
1202,
3140,
402,
314,
849,
14147,
1950,
12,
1362,
446,
1443,
506,
663,
465,
812,
6098,
63,
14921,
503,
812,
6098,
63,
4701,
63,
5413,
3734,
1750,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
5066,
7,
523,
373,
2275,
63,
3502,
63,
8356,
26,
272,
1369,
26,
1362,
446,
982,
445,
8,
889,
395,
7799,
14512,
911,
440,
506,
16468,
12,
1362,
446,
1443,
506,
663,
465,
812,
6098,
63,
5600,
1951,
63,
11163,
51,
503,
812,
6098,
63,
22443,
3734,
1750,
14,
1362,
446,
961,
1077,
1454,
663,
370,
445,
8,
889,
9,
1202,
641,
4954,
1183,
22284,
15424,
1808,
291,
13,
1737,
14512,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
5066,
7,
523,
570,
63,
354,
26,
272,
1369,
26,
1362,
446,
373,
16281,
1255,
25757,
570,
536,
370,
506,
14238,
14,
1362,
446,
10162,
506,
20508,
2897,
1978,
17048,
2611,
9,
503,
10431,
1978,
3482,
570,
17048,
3065,
680,
272,
1415,
26,
2549,
199,
199,
7538,
26,
523,
446,
298,
86,
2275,
13,
1258,
2356,
841,
14,
17,
14,
17,
2,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
373,
2275,
63,
493,
523,
373,
2275,
63,
493,
26,
489,
373,
2275,
63,
711,
26,
1616,
14,
709,
14,
709,
14,
709,
489,
373,
2275,
63,
751,
26,
373,
16281,
489,
373,
2275,
63,
2060,
26,
28880,
1068,
489,
570,
63,
354,
26,
1182,
2791,
15,
362,
63,
18424,
14,
2611,
199,
2344,
199,
199,
9677,
275,
1449,
199,
1099,
26,
272,
1369,
26,
6430,
10093,
316,
5802,
754,
272,
2138,
26,
3182,
272,
730,
26,
1059,
272,
2690,
26,
298,
17527,
1978,
2737,
2,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
2589,
63,
10538,
199,
646,
747,
199,
646,
747,
14,
515,
199,
199,
893,
26,
272,
687,
373,
2275,
63,
1258,
492,
4618,
63,
1258,
272,
7509,
63,
15740,
63,
9901,
275,
715,
199,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
40423245/2017springcd_hw
|
plugin/liquid_tags/vimeo.py
|
288
|
1808
|
"""
Vimeo Tag
---------
This implements a Liquid-style vimeo tag for Pelican,
based on the youtube tag which is in turn based on
the jekyll / octopress youtube tag [1]_
Syntax
------
{% vimeo id [width height] %}
Example
-------
{% vimeo 10739054 640 480 %}
Output
------
<div style="width:640px; height:480px;">
<iframe
src="//player.vimeo.com/video/10739054?title=0&byline=0&portrait=0"
width="640" height="480" frameborder="0"
webkitallowfullscreen mozallowfullscreen allowfullscreen>
</iframe>
</div>
[1] https://gist.github.com/jamieowen/2063748
"""
import re
from .mdx_liquid_tags import LiquidTags
SYNTAX = "{% vimeo id [width height] %}"
VIMEO = re.compile(r'(\S+)(\s+(\d+)\s(\d+))?')
@LiquidTags.register('vimeo')
def vimeo(preprocessor, tag, markup):
width = 640
height = 390
vimeo_id = None
match = VIMEO.search(markup)
if match:
groups = match.groups()
vimeo_id = groups[0]
width = groups[2] or width
height = groups[3] or height
if vimeo_id:
vimeo_out = """
<div class="videobox">
<iframe
src="//player.vimeo.com/video/{vimeo_id}?title=0&byline=0&portrait=0"
width="{width}" height="{height}" frameborder="0"
webkitAllowFullScreen mozallowfullscreen allowFullScreen>
</iframe>
</div>
""".format(width=width, height=height, vimeo_id=vimeo_id).strip()
else:
raise ValueError("Error processing input, "
"expected syntax: {0}".format(SYNTAX))
return vimeo_out
# ---------------------------------------------------
# This import allows vimeo tag to be a Pelican plugin
from liquid_tags import register # noqa
|
agpl-3.0
|
[
624,
199,
54,
1036,
79,
8053,
199,
9960,
199,
2765,
9031,
282,
24157,
28398,
13,
2487,
373,
1036,
79,
1947,
367,
11379,
28091,
12,
199,
6788,
641,
314,
22378,
1947,
1314,
365,
315,
7485,
4079,
641,
199,
1589,
1335,
5711,
89,
914,
1182,
17162,
411,
753,
22378,
1947,
359,
17,
25276,
199,
199,
16626,
199,
8648,
199,
3996,
373,
1036,
79,
1305,
359,
2063,
4569,
61,
3674,
199,
199,
9846,
199,
12797,
199,
3996,
373,
1036,
79,
23543,
12302,
1477,
5049,
16,
29504,
3674,
199,
199,
2959,
199,
8648,
199,
28,
3015,
3449,
628,
2063,
26,
12021,
5326,
27,
4569,
26,
21853,
5326,
31328,
272,
665,
20052,
267,
2928,
628,
501,
6147,
14,
433,
278,
79,
14,
957,
15,
3722,
15,
7555,
12302,
1477,
31,
1213,
29,
16,
6,
5282,
27,
991,
604,
29,
16,
6,
5282,
27,
719,
29179,
29,
16,
2,
267,
3462,
628,
12021,
2,
4569,
628,
21853,
2,
2787,
8665,
628,
16,
2,
267,
15804,
3306,
28418,
4463,
1303,
90,
3306,
28418,
4463,
2040,
28418,
4463,
30,
272,
3068,
20052,
30,
199,
1108,
3015,
30,
199,
199,
59,
17,
61,
4178,
921,
71,
631,
14,
5031,
14,
957,
15,
16997,
1873,
583,
287,
15,
1165,
2766,
18770,
199,
624,
199,
646,
295,
199,
504,
1275,
1064,
88,
63,
317,
28398,
63,
2969,
492,
24157,
28398,
9440,
199,
199,
20763,
275,
22704,
373,
1036,
79,
1305,
359,
2063,
4569,
61,
3674,
2,
199,
199,
54,
3465,
47,
275,
295,
14,
2014,
8,
82,
13445,
51,
27860,
83,
20900,
68,
13439,
83,
2961,
68,
11,
430,
18478,
421,
199,
32,
13009,
28398,
9440,
14,
2683,
360,
433,
278,
79,
358,
199,
318,
373,
1036,
79,
8,
657,
6459,
12,
1947,
12,
9189,
304,
272,
3462,
275,
5049,
16,
272,
4569,
275,
650,
2710,
272,
373,
1036,
79,
63,
344,
275,
488,
339,
1336,
275,
812,
3465,
47,
14,
1733,
8,
10131,
9,
272,
340,
1336,
26,
267,
4652,
275,
1336,
14,
2634,
342,
267,
373,
1036,
79,
63,
344,
275,
4652,
59,
16,
61,
267,
3462,
275,
4652,
59,
18,
61,
503,
3462,
267,
4569,
275,
4652,
59,
19,
61,
503,
4569,
339,
340,
373,
1036,
79,
63,
344,
26,
267,
373,
1036,
79,
63,
548,
275,
408,
288,
665,
3015,
1021,
628,
3722,
1977,
1743,
355,
665,
20052,
490,
2928,
628,
501,
6147,
14,
433,
278,
79,
14,
957,
15,
3722,
5321,
433,
278,
79,
63,
344,
93,
31,
1213,
29,
16,
6,
5282,
27,
991,
604,
29,
16,
6,
5282,
27,
719,
29179,
29,
16,
2,
490,
3462,
18448,
2063,
7063,
4569,
18448,
3333,
7063,
2787,
8665,
628,
16,
2,
490,
15804,
7852,
9042,
9616,
1303,
90,
3306,
28418,
4463,
2040,
9042,
9616,
30,
355,
3068,
20052,
30,
288,
3068,
3015,
30,
267,
30512,
908,
8,
2063,
29,
2063,
12,
4569,
29,
3333,
12,
373,
1036,
79,
63,
344,
29,
433,
278,
79,
63,
344,
680,
1913,
342,
272,
587,
26,
267,
746,
1722,
480,
547,
6661,
1324,
12,
298,
586,
298,
2062,
6302,
26,
469,
16,
5469,
908,
8,
20763,
430,
339,
372,
373,
1036,
79,
63,
548,
421,
199,
3,
9527,
2595,
199,
3,
961,
492,
6127,
373,
1036,
79,
1947,
370,
506,
282,
11379,
28091,
3589,
199,
504,
1212,
28398,
63,
2969,
492,
2274,
221,
327,
8151,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
54,
1036,
79,
8053,
199,
9960,
199,
2765,
9031,
282,
24157,
28398,
13,
2487,
373,
1036,
79,
1947,
367,
11379,
28091,
12,
199,
6788,
641,
314,
22378,
1947,
1314,
365,
315,
7485,
4079,
641,
199,
1589,
1335,
5711,
89,
914,
1182,
17162,
411,
753,
22378,
1947,
359,
17,
25276,
199,
199,
16626,
199,
8648,
199,
3996,
373,
1036,
79,
1305,
359,
2063,
4569,
61,
3674,
199,
199,
9846,
199,
12797,
199,
3996,
373,
1036,
79,
23543,
12302,
1477,
5049,
16,
29504,
3674,
199,
199,
2959,
199,
8648,
199,
28,
3015,
3449,
628,
2063,
26,
12021,
5326,
27,
4569,
26,
21853,
5326,
31328,
272,
665,
20052,
267,
2928,
628,
501,
6147,
14,
433,
278,
79,
14,
957,
15,
3722,
15,
7555,
12302,
1477,
31,
1213,
29,
16,
6,
5282,
27,
991,
604,
29,
16,
6,
5282,
27,
719,
29179,
29,
16,
2,
267,
3462,
628,
12021,
2,
4569,
628,
21853,
2,
2787,
8665,
628,
16,
2,
267,
15804,
3306,
28418,
4463,
1303,
90,
3306,
28418,
4463,
2040,
28418,
4463,
30,
272,
3068,
20052,
30,
199,
1108,
3015,
30,
199,
199,
59,
17,
61,
4178,
921,
71,
631,
14,
5031,
14,
957,
15,
16997,
1873,
583,
287,
15,
1165,
2766,
18770,
199,
624,
199,
646,
295,
199,
504,
1275,
1064,
88,
63,
317,
28398,
63,
2969,
492,
24157,
28398,
9440,
199,
199,
20763,
275,
22704,
373,
1036,
79,
1305,
359,
2063,
4569,
61,
3674,
2,
199,
199,
54,
3465,
47,
275,
295,
14,
2014,
8,
82,
13445,
51,
27860,
83,
20900,
68,
13439,
83,
2961,
68,
11,
430,
18478,
421,
199,
32,
13009,
28398,
9440,
14,
2683,
360,
433,
278,
79,
358,
199,
318,
373,
1036,
79,
8,
657,
6459,
12,
1947,
12,
9189,
304,
272,
3462,
275,
5049,
16,
272,
4569,
275,
650,
2710,
272,
373,
1036,
79,
63,
344,
275,
488,
339,
1336,
275,
812,
3465,
47,
14,
1733,
8,
10131,
9,
272,
340,
1336,
26,
267,
4652,
275,
1336,
14,
2634,
342,
267,
373,
1036,
79,
63,
344,
275,
4652,
59,
16,
61,
267,
3462,
275,
4652,
59,
18,
61,
503,
3462,
267,
4569,
275,
4652,
59,
19,
61,
503,
4569,
339,
340,
373,
1036,
79,
63,
344,
26,
267,
373,
1036,
79,
63,
548,
275,
408,
288,
665,
3015,
1021,
628,
3722,
1977,
1743,
355,
665,
20052,
490,
2928,
628,
501,
6147,
14,
433,
278,
79,
14,
957,
15,
3722,
5321,
433,
278,
79,
63,
344,
93,
31,
1213,
29,
16,
6,
5282,
27,
991,
604,
29,
16,
6,
5282,
27,
719,
29179,
29,
16,
2,
490,
3462,
18448,
2063,
7063,
4569,
18448,
3333,
7063,
2787,
8665,
628,
16,
2,
490,
15804,
7852,
9042,
9616,
1303,
90,
3306,
28418,
4463,
2040,
9042,
9616,
30,
355,
3068,
20052,
30,
288,
3068,
3015,
30,
267,
30512,
908,
8,
2063,
29,
2063,
12,
4569,
29,
3333,
12,
373,
1036,
79,
63,
344,
29,
433,
278,
79,
63,
344,
680,
1913,
342,
272,
587,
26,
267,
746,
1722,
480,
547,
6661,
1324,
12,
298,
586,
298,
2062,
6302,
26,
469,
16,
5469,
908,
8,
20763,
430,
339,
372,
373,
1036,
79,
63,
548,
421,
199,
3,
9527,
2595,
199,
3,
961,
492,
6127,
373,
1036,
79,
1947,
370,
506,
282,
11379,
28091,
3589,
199,
504,
1212,
28398,
63,
2969,
492,
2274,
221,
327,
8151,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
jelly/calibre
|
src/calibre/ebooks/metadata/sources/covers.py
|
2
|
6230
|
#!/usr/bin/env python2
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
from __future__ import (unicode_literals, division, absolute_import,
print_function)
__license__ = 'GPL v3'
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import time
from Queue import Queue, Empty
from threading import Thread, Event
from io import BytesIO
from calibre.customize.ui import metadata_plugins
from calibre.ebooks.metadata.sources.base import create_log
from calibre.ebooks.metadata.sources.prefs import msprefs
from calibre.utils.img import save_cover_data_to, remove_borders_from_image, image_to_data, image_from_data
from calibre.utils.imghdr import identify
class Worker(Thread):
def __init__(self, plugin, abort, title, authors, identifiers, timeout, rq, get_best_cover=False):
Thread.__init__(self)
self.daemon = True
self.plugin = plugin
self.abort = abort
self.get_best_cover = get_best_cover
self.buf = BytesIO()
self.log = create_log(self.buf)
self.title, self.authors, self.identifiers = (title, authors,
identifiers)
self.timeout, self.rq = timeout, rq
self.time_spent = None
def run(self):
start_time = time.time()
if not self.abort.is_set():
try:
if self.plugin.can_get_multiple_covers:
self.plugin.download_cover(self.log, self.rq, self.abort,
title=self.title, authors=self.authors, get_best_cover=self.get_best_cover,
identifiers=self.identifiers, timeout=self.timeout)
else:
self.plugin.download_cover(self.log, self.rq, self.abort,
title=self.title, authors=self.authors,
identifiers=self.identifiers, timeout=self.timeout)
except:
self.log.exception('Failed to download cover from',
self.plugin.name)
self.time_spent = time.time() - start_time
def is_worker_alive(workers):
for w in workers:
if w.is_alive():
return True
return False
def process_result(log, result):
plugin, data = result
try:
if getattr(plugin, 'auto_trim_covers', False):
img = image_from_data(data)
nimg = remove_borders_from_image(img)
if nimg is not img:
data = image_to_data(nimg)
fmt, width, height = identify(data)
if width < 0 or height < 0:
raise ValueError('Could not read cover image dimensions')
if width < 50 or height < 50:
raise ValueError('Image too small')
data = save_cover_data_to(data)
except Exception:
log.exception('Invalid cover from', plugin.name)
return None
return (plugin, width, height, fmt, data)
def run_download(log, results, abort,
title=None, authors=None, identifiers={}, timeout=30, get_best_cover=False):
'''
Run the cover download, putting results into the queue :param:`results`.
Each result is a tuple of the form:
(plugin, width, height, fmt, bytes)
'''
if title == _('Unknown'):
title = None
if authors == [_('Unknown')]:
authors = None
plugins = [p for p in metadata_plugins(['cover']) if p.is_configured()]
rq = Queue()
workers = [Worker(p, abort, title, authors, identifiers, timeout, rq, get_best_cover=get_best_cover) for p
in plugins]
for w in workers:
w.start()
first_result_at = None
wait_time = msprefs['wait_after_first_cover_result']
found_results = {}
start_time = time.time() # Use a global timeout to workaround misbehaving plugins that hang
while time.time() - start_time < 301:
time.sleep(0.1)
try:
x = rq.get_nowait()
result = process_result(log, x)
if result is not None:
results.put(result)
found_results[result[0]] = result
if first_result_at is not None:
first_result_at = time.time()
except Empty:
pass
if not is_worker_alive(workers):
break
if first_result_at is not None and time.time() - first_result_at > wait_time:
log('Not waiting for any more results')
abort.set()
if abort.is_set():
break
while True:
try:
x = rq.get_nowait()
result = process_result(log, x)
if result is not None:
results.put(result)
found_results[result[0]] = result
except Empty:
break
for w in workers:
wlog = w.buf.getvalue().strip()
log('\n'+'*'*30, w.plugin.name, 'Covers', '*'*30)
log('Request extra headers:', w.plugin.browser.addheaders)
if w.plugin in found_results:
result = found_results[w.plugin]
log('Downloaded cover:', '%dx%d'%(result[1], result[2]))
else:
log('Failed to download valid cover')
if w.time_spent is None:
log('Download aborted')
else:
log('Took', w.time_spent, 'seconds')
if wlog:
log(wlog)
log('\n'+'*'*80)
def download_cover(log,
title=None, authors=None, identifiers={}, timeout=30):
'''
Synchronous cover download. Returns the "best" cover as per user
prefs/cover resolution.
Returned cover is a tuple: (plugin, width, height, fmt, data)
Returns None if no cover is found.
'''
rq = Queue()
abort = Event()
run_download(log, rq, abort, title=title, authors=authors,
identifiers=identifiers, timeout=timeout, get_best_cover=True)
results = []
while True:
try:
results.append(rq.get_nowait())
except Empty:
break
cp = msprefs['cover_priorities']
def keygen(result):
plugin, width, height, fmt, data = result
return (cp.get(plugin.name, 1), 1/(width*height))
results.sort(key=keygen)
return results[0] if results else None
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
18,
199,
3,
6695,
26,
493,
2991,
29,
6610,
13,
24,
26,
1086,
29,
20,
26,
3519,
29,
20,
26,
1207,
26,
386,
26,
10329,
29,
20,
26,
5789,
199,
504,
636,
2443,
363,
492,
334,
2975,
63,
5955,
12,
4629,
12,
3679,
63,
646,
12,
717,
870,
63,
1593,
9,
199,
199,
363,
1682,
363,
257,
275,
283,
12006,
373,
19,
7,
199,
363,
7307,
363,
275,
283,
8128,
12,
1804,
79,
5017,
3971,
31876,
665,
7697,
5017,
32,
7697,
5017,
1939,
31876,
14,
846,
3524,
199,
363,
21841,
363,
275,
283,
26854,
655,
7,
199,
199,
646,
900,
199,
504,
10703,
492,
10703,
12,
9630,
199,
504,
5796,
492,
11086,
12,
6763,
199,
504,
5890,
492,
11808,
199,
199,
504,
19238,
14,
26660,
14,
1907,
492,
3341,
63,
5265,
199,
504,
19238,
14,
69,
8858,
14,
2343,
14,
4553,
14,
1095,
492,
1218,
63,
793,
199,
504,
19238,
14,
69,
8858,
14,
2343,
14,
4553,
14,
17253,
492,
6605,
17253,
199,
504,
19238,
14,
1208,
14,
4060,
492,
3354,
63,
5899,
63,
576,
63,
475,
12,
2813,
63,
8665,
83,
63,
504,
63,
1569,
12,
1834,
63,
475,
63,
576,
12,
1834,
63,
504,
63,
576,
199,
504,
19238,
14,
1208,
14,
1017,
3561,
5012,
492,
10405,
421,
199,
533,
23886,
8,
4436,
304,
339,
347,
636,
826,
721,
277,
12,
3589,
12,
12004,
12,
2538,
12,
11462,
12,
14154,
12,
2653,
12,
24659,
12,
664,
63,
7010,
63,
5899,
29,
797,
304,
267,
11086,
855,
826,
721,
277,
9,
267,
291,
14,
10824,
275,
715,
398,
291,
14,
2718,
275,
3589,
267,
291,
14,
13845,
275,
12004,
267,
291,
14,
362,
63,
7010,
63,
5899,
275,
664,
63,
7010,
63,
5899,
267,
291,
14,
1436,
275,
11808,
342,
267,
291,
14,
793,
275,
1218,
63,
793,
8,
277,
14,
1436,
9,
267,
291,
14,
1213,
12,
291,
14,
8149,
12,
291,
14,
14227,
275,
334,
1213,
12,
11462,
12,
355,
14154,
9,
267,
291,
14,
2593,
12,
291,
14,
5098,
275,
2653,
12,
24659,
267,
291,
14,
521,
63,
19435,
275,
488,
339,
347,
1255,
8,
277,
304,
267,
1343,
63,
521,
275,
900,
14,
521,
342,
267,
340,
440,
291,
14,
13845,
14,
374,
63,
409,
837,
288,
862,
26,
355,
340,
291,
14,
2718,
14,
2425,
63,
362,
63,
6048,
63,
5899,
83,
26,
490,
291,
14,
2718,
14,
4249,
63,
5899,
8,
277,
14,
793,
12,
291,
14,
5098,
12,
291,
14,
13845,
12,
717,
2538,
29,
277,
14,
1213,
12,
11462,
29,
277,
14,
8149,
12,
664,
63,
7010,
63,
5899,
29,
277,
14,
362,
63,
7010,
63,
5899,
12,
717,
14154,
29,
277,
14,
14227,
12,
2653,
29,
277,
14,
2593,
9,
355,
587,
26,
490,
291,
14,
2718,
14,
4249,
63,
5899,
8,
277,
14,
793,
12,
291,
14,
5098,
12,
291,
14,
13845,
12,
717,
2538,
29,
277,
14,
1213,
12,
11462,
29,
277,
14,
8149,
12,
717,
14154,
29,
277,
14,
14227,
12,
2653,
29,
277,
14,
2593,
9,
288,
871,
26,
355,
291,
14,
793,
14,
1971,
360,
4276,
370,
5235,
8486,
687,
297,
717,
291,
14,
2718,
14,
354,
9,
267,
291,
14,
521,
63,
19435,
275,
900,
14,
521,
342,
446,
1343,
63,
521,
421,
199,
318,
365,
63,
6599,
63,
9631,
8,
11009,
304,
272,
367,
336,
315,
14123,
26,
267,
340,
336,
14,
374,
63,
9631,
837,
288,
372,
715,
272,
372,
756,
421,
199,
318,
2112,
63,
1099,
8,
793,
12,
754,
304,
272,
3589,
12,
666,
275,
754,
272,
862,
26,
267,
340,
2519,
8,
2718,
12,
283,
2495,
63,
12263,
63,
5899,
83,
297,
756,
304,
288,
6050,
275,
1834,
63,
504,
63,
576,
8,
576,
9,
288,
302,
4060,
275,
2813,
63,
8665,
83,
63,
504,
63,
1569,
8,
4060,
9,
288,
340,
302,
4060,
365,
440,
6050,
26,
355,
666,
275,
1834,
63,
475,
63,
576,
8,
78,
4060,
9,
267,
7104,
12,
3462,
12,
4569,
275,
10405,
8,
576,
9,
267,
340,
3462,
665,
378,
503,
4569,
665,
378,
26,
288,
746,
1722,
360,
6531,
440,
1586,
8486,
1834,
7365,
358,
267,
340,
3462,
665,
5238,
503,
4569,
665,
5238,
26,
288,
746,
1722,
360,
3491,
4634,
7425,
358,
267,
666,
275,
3354,
63,
5899,
63,
576,
63,
475,
8,
576,
9,
272,
871,
2186,
26,
267,
943,
14,
1971,
360,
3364,
8486,
687,
297,
3589,
14,
354,
9,
267,
372,
488,
272,
372,
334,
2718,
12,
3462,
12,
4569,
12,
7104,
12,
666,
9,
421,
199,
318,
1255,
63,
4249,
8,
793,
12,
2058,
12,
12004,
12,
267,
2538,
29,
403,
12,
11462,
29,
403,
12,
14154,
10324,
2653,
29,
1216,
12,
664,
63,
7010,
63,
5899,
29,
797,
304,
272,
1449,
272,
3378,
314,
8486,
5235,
12,
32670,
2058,
1901,
314,
4126,
520,
635,
1705,
2604,
2313,
339,
7048,
754,
365,
282,
2008,
402,
314,
1824,
26,
398,
334,
2718,
12,
3462,
12,
4569,
12,
7104,
12,
2783,
9,
339,
1449,
272,
340,
2538,
508,
4018,
5912,
735,
267,
2538,
275,
488,
272,
340,
11462,
508,
359,
11252,
5912,
358,
2189,
267,
11462,
275,
488,
339,
8963,
275,
359,
80,
367,
299,
315,
3341,
63,
5265,
2941,
5899,
1105,
340,
299,
14,
374,
63,
11786,
5106,
339,
24659,
275,
10703,
342,
272,
14123,
275,
359,
12678,
8,
80,
12,
12004,
12,
2538,
12,
11462,
12,
14154,
12,
2653,
12,
24659,
12,
664,
63,
7010,
63,
5899,
29,
362,
63,
7010,
63,
5899,
9,
367,
299,
288,
315,
8963,
61,
272,
367,
336,
315,
14123,
26,
267,
336,
14,
928,
342,
339,
1642,
63,
1099,
63,
292,
275,
488,
272,
3618,
63,
521,
275,
6605,
17253,
459,
2573,
63,
4399,
63,
2246,
63,
5899,
63,
1099,
418,
272,
1911,
63,
2604,
275,
1052,
339,
1343,
63,
521,
275,
900,
14,
521,
342,
221,
327,
3645,
282,
2288,
2653,
370,
18092,
3201,
25599,
5519,
8963,
626,
30084,
272,
1830,
900,
14,
521,
342,
446,
1343,
63,
521,
665,
19660,
26,
267,
900,
14,
4532,
8,
16,
14,
17,
9,
267,
862,
26,
288,
671,
275,
24659,
14,
362,
63,
20870,
342,
288,
754,
275,
2112
] |
[
2647,
15,
1393,
15,
1813,
2366,
18,
199,
3,
6695,
26,
493,
2991,
29,
6610,
13,
24,
26,
1086,
29,
20,
26,
3519,
29,
20,
26,
1207,
26,
386,
26,
10329,
29,
20,
26,
5789,
199,
504,
636,
2443,
363,
492,
334,
2975,
63,
5955,
12,
4629,
12,
3679,
63,
646,
12,
717,
870,
63,
1593,
9,
199,
199,
363,
1682,
363,
257,
275,
283,
12006,
373,
19,
7,
199,
363,
7307,
363,
275,
283,
8128,
12,
1804,
79,
5017,
3971,
31876,
665,
7697,
5017,
32,
7697,
5017,
1939,
31876,
14,
846,
3524,
199,
363,
21841,
363,
275,
283,
26854,
655,
7,
199,
199,
646,
900,
199,
504,
10703,
492,
10703,
12,
9630,
199,
504,
5796,
492,
11086,
12,
6763,
199,
504,
5890,
492,
11808,
199,
199,
504,
19238,
14,
26660,
14,
1907,
492,
3341,
63,
5265,
199,
504,
19238,
14,
69,
8858,
14,
2343,
14,
4553,
14,
1095,
492,
1218,
63,
793,
199,
504,
19238,
14,
69,
8858,
14,
2343,
14,
4553,
14,
17253,
492,
6605,
17253,
199,
504,
19238,
14,
1208,
14,
4060,
492,
3354,
63,
5899,
63,
576,
63,
475,
12,
2813,
63,
8665,
83,
63,
504,
63,
1569,
12,
1834,
63,
475,
63,
576,
12,
1834,
63,
504,
63,
576,
199,
504,
19238,
14,
1208,
14,
1017,
3561,
5012,
492,
10405,
421,
199,
533,
23886,
8,
4436,
304,
339,
347,
636,
826,
721,
277,
12,
3589,
12,
12004,
12,
2538,
12,
11462,
12,
14154,
12,
2653,
12,
24659,
12,
664,
63,
7010,
63,
5899,
29,
797,
304,
267,
11086,
855,
826,
721,
277,
9,
267,
291,
14,
10824,
275,
715,
398,
291,
14,
2718,
275,
3589,
267,
291,
14,
13845,
275,
12004,
267,
291,
14,
362,
63,
7010,
63,
5899,
275,
664,
63,
7010,
63,
5899,
267,
291,
14,
1436,
275,
11808,
342,
267,
291,
14,
793,
275,
1218,
63,
793,
8,
277,
14,
1436,
9,
267,
291,
14,
1213,
12,
291,
14,
8149,
12,
291,
14,
14227,
275,
334,
1213,
12,
11462,
12,
355,
14154,
9,
267,
291,
14,
2593,
12,
291,
14,
5098,
275,
2653,
12,
24659,
267,
291,
14,
521,
63,
19435,
275,
488,
339,
347,
1255,
8,
277,
304,
267,
1343,
63,
521,
275,
900,
14,
521,
342,
267,
340,
440,
291,
14,
13845,
14,
374,
63,
409,
837,
288,
862,
26,
355,
340,
291,
14,
2718,
14,
2425,
63,
362,
63,
6048,
63,
5899,
83,
26,
490,
291,
14,
2718,
14,
4249,
63,
5899,
8,
277,
14,
793,
12,
291,
14,
5098,
12,
291,
14,
13845,
12,
717,
2538,
29,
277,
14,
1213,
12,
11462,
29,
277,
14,
8149,
12,
664,
63,
7010,
63,
5899,
29,
277,
14,
362,
63,
7010,
63,
5899,
12,
717,
14154,
29,
277,
14,
14227,
12,
2653,
29,
277,
14,
2593,
9,
355,
587,
26,
490,
291,
14,
2718,
14,
4249,
63,
5899,
8,
277,
14,
793,
12,
291,
14,
5098,
12,
291,
14,
13845,
12,
717,
2538,
29,
277,
14,
1213,
12,
11462,
29,
277,
14,
8149,
12,
717,
14154,
29,
277,
14,
14227,
12,
2653,
29,
277,
14,
2593,
9,
288,
871,
26,
355,
291,
14,
793,
14,
1971,
360,
4276,
370,
5235,
8486,
687,
297,
717,
291,
14,
2718,
14,
354,
9,
267,
291,
14,
521,
63,
19435,
275,
900,
14,
521,
342,
446,
1343,
63,
521,
421,
199,
318,
365,
63,
6599,
63,
9631,
8,
11009,
304,
272,
367,
336,
315,
14123,
26,
267,
340,
336,
14,
374,
63,
9631,
837,
288,
372,
715,
272,
372,
756,
421,
199,
318,
2112,
63,
1099,
8,
793,
12,
754,
304,
272,
3589,
12,
666,
275,
754,
272,
862,
26,
267,
340,
2519,
8,
2718,
12,
283,
2495,
63,
12263,
63,
5899,
83,
297,
756,
304,
288,
6050,
275,
1834,
63,
504,
63,
576,
8,
576,
9,
288,
302,
4060,
275,
2813,
63,
8665,
83,
63,
504,
63,
1569,
8,
4060,
9,
288,
340,
302,
4060,
365,
440,
6050,
26,
355,
666,
275,
1834,
63,
475,
63,
576,
8,
78,
4060,
9,
267,
7104,
12,
3462,
12,
4569,
275,
10405,
8,
576,
9,
267,
340,
3462,
665,
378,
503,
4569,
665,
378,
26,
288,
746,
1722,
360,
6531,
440,
1586,
8486,
1834,
7365,
358,
267,
340,
3462,
665,
5238,
503,
4569,
665,
5238,
26,
288,
746,
1722,
360,
3491,
4634,
7425,
358,
267,
666,
275,
3354,
63,
5899,
63,
576,
63,
475,
8,
576,
9,
272,
871,
2186,
26,
267,
943,
14,
1971,
360,
3364,
8486,
687,
297,
3589,
14,
354,
9,
267,
372,
488,
272,
372,
334,
2718,
12,
3462,
12,
4569,
12,
7104,
12,
666,
9,
421,
199,
318,
1255,
63,
4249,
8,
793,
12,
2058,
12,
12004,
12,
267,
2538,
29,
403,
12,
11462,
29,
403,
12,
14154,
10324,
2653,
29,
1216,
12,
664,
63,
7010,
63,
5899,
29,
797,
304,
272,
1449,
272,
3378,
314,
8486,
5235,
12,
32670,
2058,
1901,
314,
4126,
520,
635,
1705,
2604,
2313,
339,
7048,
754,
365,
282,
2008,
402,
314,
1824,
26,
398,
334,
2718,
12,
3462,
12,
4569,
12,
7104,
12,
2783,
9,
339,
1449,
272,
340,
2538,
508,
4018,
5912,
735,
267,
2538,
275,
488,
272,
340,
11462,
508,
359,
11252,
5912,
358,
2189,
267,
11462,
275,
488,
339,
8963,
275,
359,
80,
367,
299,
315,
3341,
63,
5265,
2941,
5899,
1105,
340,
299,
14,
374,
63,
11786,
5106,
339,
24659,
275,
10703,
342,
272,
14123,
275,
359,
12678,
8,
80,
12,
12004,
12,
2538,
12,
11462,
12,
14154,
12,
2653,
12,
24659,
12,
664,
63,
7010,
63,
5899,
29,
362,
63,
7010,
63,
5899,
9,
367,
299,
288,
315,
8963,
61,
272,
367,
336,
315,
14123,
26,
267,
336,
14,
928,
342,
339,
1642,
63,
1099,
63,
292,
275,
488,
272,
3618,
63,
521,
275,
6605,
17253,
459,
2573,
63,
4399,
63,
2246,
63,
5899,
63,
1099,
418,
272,
1911,
63,
2604,
275,
1052,
339,
1343,
63,
521,
275,
900,
14,
521,
342,
221,
327,
3645,
282,
2288,
2653,
370,
18092,
3201,
25599,
5519,
8963,
626,
30084,
272,
1830,
900,
14,
521,
342,
446,
1343,
63,
521,
665,
19660,
26,
267,
900,
14,
4532,
8,
16,
14,
17,
9,
267,
862,
26,
288,
671,
275,
24659,
14,
362,
63,
20870,
342,
288,
754,
275,
2112,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
adityahase/frappe
|
frappe/config/customization.py
|
1
|
1286
|
from __future__ import unicode_literals
from frappe import _
def get_data():
return [
{
"label": _("Form Customization"),
"icon": "fa fa-glass",
"items": [
{
"type": "doctype",
"name": "Customize Form",
"description": _("Change field properties (hide, readonly, permission etc.)")
},
{
"type": "doctype",
"name": "Custom Field",
"description": _("Add fields to forms.")
},
{
"type": "doctype",
"name": "Custom Script",
"description": _("Add custom javascript to forms.")
},
{
"type": "doctype",
"name": "DocType",
"description": _("Add custom forms.")
},
]
},
{
"label": _("Dashboards"),
"items": [
{
"type": "doctype",
"name": "Dashboard",
},
{
"type": "doctype",
"name": "Dashboard Chart",
},
{
"type": "doctype",
"name": "Dashboard Chart Source",
},
]
},
{
"label": _("Other"),
"items": [
{
"type": "doctype",
"label": _("Custom Translations"),
"name": "Translation",
"description": _("Add your own translations")
},
{
"type": "doctype",
"label": _("Package"),
"name": "Package",
"description": _("Import and Export Packages.")
}
]
}
]
|
mit
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
6950,
492,
485,
199,
199,
318,
664,
63,
576,
837,
199,
198,
1107,
359,
507,
198,
91,
686,
198,
2,
1302,
582,
3824,
2821,
8388,
2072,
1288,
686,
198,
2,
4677,
582,
298,
667,
1433,
13,
3528,
405,
401,
686,
198,
2,
1744,
582,
359,
1585,
198,
91,
1871,
198,
2,
466,
582,
298,
6356,
401,
1871,
198,
2,
354,
582,
298,
7223,
794,
8204,
401,
1871,
198,
2,
1802,
582,
3824,
4001,
901,
4382,
334,
8191,
12,
6863,
12,
4983,
5423,
4959,
531,
1585,
198,
1386,
1585,
198,
91,
1871,
198,
2,
466,
582,
298,
6356,
401,
1871,
198,
2,
354,
582,
298,
7223,
5024,
401,
1871,
198,
2,
1802,
582,
3824,
1123,
1504,
370,
4513,
2685,
1585,
198,
1386,
1585,
198,
91,
1871,
198,
2,
466,
582,
298,
6356,
401,
1871,
198,
2,
354,
582,
298,
7223,
14914,
401,
1871,
198,
2,
1802,
582,
3824,
1123,
3537,
18910,
370,
4513,
2685,
1585,
198,
1386,
1585,
198,
91,
1871,
198,
2,
466,
582,
298,
6356,
401,
1871,
198,
2,
354,
582,
298,
3768,
804,
401,
1871,
198,
2,
1802,
582,
3824,
1123,
3537,
4513,
2685,
1585,
198,
1386,
686,
198,
61,
507,
198,
1386,
507,
198,
91,
686,
198,
2,
1302,
582,
3824,
16659,
19267,
1288,
686,
198,
2,
1744,
582,
359,
1585,
198,
91,
1871,
198,
2,
466,
582,
298,
6356,
401,
1871,
198,
2,
354,
582,
298,
30122,
401,
1585,
198,
1386,
1585,
198,
91,
1871,
198,
2,
466,
582,
298,
6356,
401,
1871,
198,
2,
354,
582,
298,
30122,
24874,
401,
1585,
198,
1386,
1585,
198,
91,
1871,
198,
2,
466,
582,
298,
6356,
401,
1871,
198,
2,
354,
582,
298,
30122,
24874,
5800,
401,
1585,
198,
1386,
686,
198,
61,
507,
198,
1386,
507,
198,
91,
686,
198,
2,
1302,
582,
3824,
8632,
1288,
686,
198,
2,
1744,
582,
359,
1585,
198,
91,
1871,
198,
2,
466,
582,
298,
6356,
401,
1871,
198,
2,
1302,
582,
3824,
7223,
6266,
6011,
1288,
1871,
198,
2,
354,
582,
298,
18483,
401,
1871,
198,
2,
1802,
582,
3824,
1123,
2195,
5705,
15547,
531,
1585,
198,
1386,
1585,
198,
91,
1871,
198,
2,
466,
582,
298,
6356,
401,
1871,
198,
2,
1302,
582,
3824,
8599,
1288,
1871,
198,
2,
354,
582,
298,
8599,
401,
1871,
198,
2,
1802,
582,
3824,
6295,
436,
20220,
9954,
7441,
2685,
1585,
198,
93,
686,
198,
61,
507,
198,
93,
199,
198,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
6950,
492,
485,
199,
199,
318,
664,
63,
576,
837,
199,
198,
1107,
359,
507,
198,
91,
686,
198,
2,
1302,
582,
3824,
2821,
8388,
2072,
1288,
686,
198,
2,
4677,
582,
298,
667,
1433,
13,
3528,
405,
401,
686,
198,
2,
1744,
582,
359,
1585,
198,
91,
1871,
198,
2,
466,
582,
298,
6356,
401,
1871,
198,
2,
354,
582,
298,
7223,
794,
8204,
401,
1871,
198,
2,
1802,
582,
3824,
4001,
901,
4382,
334,
8191,
12,
6863,
12,
4983,
5423,
4959,
531,
1585,
198,
1386,
1585,
198,
91,
1871,
198,
2,
466,
582,
298,
6356,
401,
1871,
198,
2,
354,
582,
298,
7223,
5024,
401,
1871,
198,
2,
1802,
582,
3824,
1123,
1504,
370,
4513,
2685,
1585,
198,
1386,
1585,
198,
91,
1871,
198,
2,
466,
582,
298,
6356,
401,
1871,
198,
2,
354,
582,
298,
7223,
14914,
401,
1871,
198,
2,
1802,
582,
3824,
1123,
3537,
18910,
370,
4513,
2685,
1585,
198,
1386,
1585,
198,
91,
1871,
198,
2,
466,
582,
298,
6356,
401,
1871,
198,
2,
354,
582,
298,
3768,
804,
401,
1871,
198,
2,
1802,
582,
3824,
1123,
3537,
4513,
2685,
1585,
198,
1386,
686,
198,
61,
507,
198,
1386,
507,
198,
91,
686,
198,
2,
1302,
582,
3824,
16659,
19267,
1288,
686,
198,
2,
1744,
582,
359,
1585,
198,
91,
1871,
198,
2,
466,
582,
298,
6356,
401,
1871,
198,
2,
354,
582,
298,
30122,
401,
1585,
198,
1386,
1585,
198,
91,
1871,
198,
2,
466,
582,
298,
6356,
401,
1871,
198,
2,
354,
582,
298,
30122,
24874,
401,
1585,
198,
1386,
1585,
198,
91,
1871,
198,
2,
466,
582,
298,
6356,
401,
1871,
198,
2,
354,
582,
298,
30122,
24874,
5800,
401,
1585,
198,
1386,
686,
198,
61,
507,
198,
1386,
507,
198,
91,
686,
198,
2,
1302,
582,
3824,
8632,
1288,
686,
198,
2,
1744,
582,
359,
1585,
198,
91,
1871,
198,
2,
466,
582,
298,
6356,
401,
1871,
198,
2,
1302,
582,
3824,
7223,
6266,
6011,
1288,
1871,
198,
2,
354,
582,
298,
18483,
401,
1871,
198,
2,
1802,
582,
3824,
1123,
2195,
5705,
15547,
531,
1585,
198,
1386,
1585,
198,
91,
1871,
198,
2,
466,
582,
298,
6356,
401,
1871,
198,
2,
1302,
582,
3824,
8599,
1288,
1871,
198,
2,
354,
582,
298,
8599,
401,
1871,
198,
2,
1802,
582,
3824,
6295,
436,
20220,
9954,
7441,
2685,
1585,
198,
93,
686,
198,
61,
507,
198,
93,
199,
198,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
yotchang4s/cafebabepy
|
src/main/python/test/test_symtable.py
|
5
|
6951
|
"""
Test the API of the symtable module.
"""
import symtable
import unittest
TEST_CODE = """
import sys
glob = 42
class Mine:
instance_var = 24
def a_method(p1, p2):
pass
def spam(a, b, *var, **kw):
global bar
bar = 47
x = 23
glob
def internal():
return x
return internal
def foo():
pass
def namespace_test(): pass
def namespace_test(): pass
"""
def find_block(block, name):
for ch in block.get_children():
if ch.get_name() == name:
return ch
class SymtableTest(unittest.TestCase):
top = symtable.symtable(TEST_CODE, "?", "exec")
# These correspond to scopes in TEST_CODE
Mine = find_block(top, "Mine")
a_method = find_block(Mine, "a_method")
spam = find_block(top, "spam")
internal = find_block(spam, "internal")
foo = find_block(top, "foo")
def test_type(self):
self.assertEqual(self.top.get_type(), "module")
self.assertEqual(self.Mine.get_type(), "class")
self.assertEqual(self.a_method.get_type(), "function")
self.assertEqual(self.spam.get_type(), "function")
self.assertEqual(self.internal.get_type(), "function")
def test_optimized(self):
self.assertFalse(self.top.is_optimized())
self.assertFalse(self.top.has_exec())
self.assertTrue(self.spam.is_optimized())
def test_nested(self):
self.assertFalse(self.top.is_nested())
self.assertFalse(self.Mine.is_nested())
self.assertFalse(self.spam.is_nested())
self.assertTrue(self.internal.is_nested())
def test_children(self):
self.assertTrue(self.top.has_children())
self.assertTrue(self.Mine.has_children())
self.assertFalse(self.foo.has_children())
def test_lineno(self):
self.assertEqual(self.top.get_lineno(), 0)
self.assertEqual(self.spam.get_lineno(), 11)
def test_function_info(self):
func = self.spam
self.assertEqual(sorted(func.get_parameters()), ["a", "b", "kw", "var"])
expected = ["a", "b", "internal", "kw", "var", "x"]
self.assertEqual(sorted(func.get_locals()), expected)
self.assertEqual(sorted(func.get_globals()), ["bar", "glob"])
self.assertEqual(self.internal.get_frees(), ("x",))
def test_globals(self):
self.assertTrue(self.spam.lookup("glob").is_global())
self.assertFalse(self.spam.lookup("glob").is_declared_global())
self.assertTrue(self.spam.lookup("bar").is_global())
self.assertTrue(self.spam.lookup("bar").is_declared_global())
self.assertFalse(self.internal.lookup("x").is_global())
self.assertFalse(self.Mine.lookup("instance_var").is_global())
def test_local(self):
self.assertTrue(self.spam.lookup("x").is_local())
self.assertFalse(self.internal.lookup("x").is_local())
def test_referenced(self):
self.assertTrue(self.internal.lookup("x").is_referenced())
self.assertTrue(self.spam.lookup("internal").is_referenced())
self.assertFalse(self.spam.lookup("x").is_referenced())
def test_parameters(self):
for sym in ("a", "var", "kw"):
self.assertTrue(self.spam.lookup(sym).is_parameter())
self.assertFalse(self.spam.lookup("x").is_parameter())
def test_symbol_lookup(self):
self.assertEqual(len(self.top.get_identifiers()),
len(self.top.get_symbols()))
self.assertRaises(KeyError, self.top.lookup, "not_here")
def test_namespaces(self):
self.assertTrue(self.top.lookup("Mine").is_namespace())
self.assertTrue(self.Mine.lookup("a_method").is_namespace())
self.assertTrue(self.top.lookup("spam").is_namespace())
self.assertTrue(self.spam.lookup("internal").is_namespace())
self.assertTrue(self.top.lookup("namespace_test").is_namespace())
self.assertFalse(self.spam.lookup("x").is_namespace())
self.assertTrue(self.top.lookup("spam").get_namespace() is self.spam)
ns_test = self.top.lookup("namespace_test")
self.assertEqual(len(ns_test.get_namespaces()), 2)
self.assertRaises(ValueError, ns_test.get_namespace)
def test_assigned(self):
self.assertTrue(self.spam.lookup("x").is_assigned())
self.assertTrue(self.spam.lookup("bar").is_assigned())
self.assertTrue(self.top.lookup("spam").is_assigned())
self.assertTrue(self.Mine.lookup("a_method").is_assigned())
self.assertFalse(self.internal.lookup("x").is_assigned())
def test_annotated(self):
st1 = symtable.symtable('def f():\n x: int\n', 'test', 'exec')
st2 = st1.get_children()[0]
self.assertTrue(st2.lookup('x').is_local())
self.assertTrue(st2.lookup('x').is_annotated())
self.assertFalse(st2.lookup('x').is_global())
st3 = symtable.symtable('def f():\n x = 1\n', 'test', 'exec')
st4 = st3.get_children()[0]
self.assertTrue(st4.lookup('x').is_local())
self.assertFalse(st4.lookup('x').is_annotated())
def test_imported(self):
self.assertTrue(self.top.lookup("sys").is_imported())
def test_name(self):
self.assertEqual(self.top.get_name(), "top")
self.assertEqual(self.spam.get_name(), "spam")
self.assertEqual(self.spam.lookup("x").get_name(), "x")
self.assertEqual(self.Mine.get_name(), "Mine")
def test_class_info(self):
self.assertEqual(self.Mine.get_methods(), ('a_method',))
def test_filename_correct(self):
### Bug tickler: SyntaxError file name correct whether error raised
### while parsing or building symbol table.
def checkfilename(brokencode, offset):
try:
symtable.symtable(brokencode, "spam", "exec")
except SyntaxError as e:
self.assertEqual(e.filename, "spam")
self.assertEqual(e.lineno, 1)
self.assertEqual(e.offset, offset)
else:
self.fail("no SyntaxError for %r" % (brokencode,))
checkfilename("def f(x): foo)(", 14) # parse-time
checkfilename("def f(x): global x", 10) # symtable-build-time
symtable.symtable("pass", b"spam", "exec")
with self.assertWarns(DeprecationWarning), \
self.assertRaises(TypeError):
symtable.symtable("pass", bytearray(b"spam"), "exec")
with self.assertWarns(DeprecationWarning):
symtable.symtable("pass", memoryview(b"spam"), "exec")
with self.assertRaises(TypeError):
symtable.symtable("pass", list(b"spam"), "exec")
def test_eval(self):
symbols = symtable.symtable("42", "?", "eval")
def test_single(self):
symbols = symtable.symtable("42", "?", "single")
def test_exec(self):
symbols = symtable.symtable("def f(x): return x", "?", "exec")
if __name__ == '__main__':
unittest.main()
|
bsd-3-clause
|
[
624,
199,
774,
314,
3261,
402,
314,
4678,
1224,
859,
14,
199,
624,
199,
646,
4678,
1224,
199,
646,
2882,
4388,
199,
2864,
63,
6012,
275,
408,
199,
646,
984,
199,
199,
6463,
275,
5685,
199,
199,
533,
603,
1132,
26,
272,
1256,
63,
1391,
275,
5504,
272,
347,
282,
63,
765,
8,
80,
17,
12,
299,
18,
304,
267,
986,
199,
199,
318,
14909,
8,
65,
12,
330,
12,
627,
1391,
12,
1011,
829,
304,
272,
2288,
4681,
272,
4681,
275,
10954,
272,
671,
275,
6546,
272,
5739,
272,
347,
5007,
837,
267,
372,
671,
272,
372,
5007,
199,
199,
318,
3925,
837,
272,
986,
199,
199,
318,
3231,
63,
396,
837,
986,
199,
318,
3231,
63,
396,
837,
986,
199,
624,
421,
199,
318,
2342,
63,
1457,
8,
1457,
12,
536,
304,
272,
367,
682,
315,
1853,
14,
362,
63,
3223,
837,
267,
340,
682,
14,
362,
63,
354,
342,
508,
536,
26,
288,
372,
682,
421,
199,
533,
21478,
1224,
774,
8,
2796,
14,
1746,
304,
339,
2746,
275,
4678,
1224,
14,
3840,
1224,
8,
2864,
63,
6012,
12,
298,
15583,
298,
1628,
531,
272,
327,
5723,
17118,
370,
14570,
315,
7393,
63,
6012,
272,
603,
1132,
275,
2342,
63,
1457,
8,
2119,
12,
298,
45,
1132,
531,
272,
282,
63,
765,
275,
2342,
63,
1457,
8,
45,
1132,
12,
298,
65,
63,
765,
531,
272,
14909,
275,
2342,
63,
1457,
8,
2119,
12,
298,
8283,
531,
272,
5007,
275,
2342,
63,
1457,
8,
8283,
12,
298,
4672,
531,
272,
3925,
275,
2342,
63,
1457,
8,
2119,
12,
298,
1421,
531,
339,
347,
511,
63,
466,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
2119,
14,
362,
63,
466,
1062,
298,
578,
531,
267,
291,
14,
629,
8,
277,
14,
45,
1132,
14,
362,
63,
466,
1062,
298,
533,
531,
267,
291,
14,
629,
8,
277,
14,
65,
63,
765,
14,
362,
63,
466,
1062,
298,
1593,
531,
267,
291,
14,
629,
8,
277,
14,
8283,
14,
362,
63,
466,
1062,
298,
1593,
531,
267,
291,
14,
629,
8,
277,
14,
4672,
14,
362,
63,
466,
1062,
298,
1593,
531,
339,
347,
511,
63,
25499,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
2119,
14,
374,
63,
25499,
1012,
267,
291,
14,
3334,
8,
277,
14,
2119,
14,
1989,
63,
1628,
1012,
398,
291,
14,
1815,
8,
277,
14,
8283,
14,
374,
63,
25499,
1012,
339,
347,
511,
63,
6376,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
2119,
14,
374,
63,
6376,
1012,
267,
291,
14,
3334,
8,
277,
14,
45,
1132,
14,
374,
63,
6376,
1012,
267,
291,
14,
3334,
8,
277,
14,
8283,
14,
374,
63,
6376,
1012,
267,
291,
14,
1815,
8,
277,
14,
4672,
14,
374,
63,
6376,
1012,
339,
347,
511,
63,
3223,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
2119,
14,
1989,
63,
3223,
1012,
267,
291,
14,
1815,
8,
277,
14,
45,
1132,
14,
1989,
63,
3223,
1012,
267,
291,
14,
3334,
8,
277,
14,
1421,
14,
1989,
63,
3223,
1012,
339,
347,
511,
63,
3469,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
2119,
14,
362,
63,
3469,
1062,
378,
9,
267,
291,
14,
629,
8,
277,
14,
8283,
14,
362,
63,
3469,
1062,
4119,
9,
339,
347,
511,
63,
1593,
63,
815,
8,
277,
304,
267,
2562,
275,
291,
14,
8283,
267,
291,
14,
629,
8,
5917,
8,
1532,
14,
362,
63,
3214,
4000,
2097,
65,
401,
298,
66,
401,
298,
829,
401,
298,
1391,
3135,
267,
1420,
275,
2097,
65,
401,
298,
66,
401,
298,
4672,
401,
298,
829,
401,
298,
1391,
401,
298,
88,
937,
267,
291,
14,
629,
8,
5917,
8,
1532,
14,
362,
63,
9350,
4000,
1420,
9,
267,
291,
14,
629,
8,
5917,
8,
1532,
14,
362,
63,
8473,
4000,
2097,
1700,
401,
298,
6463,
3135,
267,
291,
14,
629,
8,
277,
14,
4672,
14,
362,
63,
70,
5710,
1062,
1689,
88,
401,
430,
339,
347,
511,
63,
8473,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
8283,
14,
3892,
480,
6463,
3471,
374,
63,
2966,
1012,
267,
291,
14,
3334,
8,
277,
14,
8283,
14,
3892,
480,
6463,
3471,
374,
63,
13545,
63,
2966,
1012,
267,
291,
14,
1815,
8,
277,
14,
8283,
14,
3892,
480,
1700,
3471,
374,
63,
2966,
1012,
267,
291,
14,
1815,
8,
277,
14,
8283,
14,
3892,
480,
1700,
3471,
374,
63,
13545,
63,
2966,
1012,
267,
291,
14,
3334,
8,
277,
14,
4672,
14,
3892,
480,
88,
3471,
374,
63,
2966,
1012,
267,
291,
14,
3334,
8,
277,
14,
45,
1132,
14,
3892,
480,
842,
63,
1391,
3471,
374,
63,
2966,
1012,
339,
347,
511,
63,
1832,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
8283,
14,
3892,
480,
88,
3471,
374,
63,
1832,
1012,
267,
291,
14,
3334,
8,
277,
14,
4672,
14,
3892,
480,
88,
3471,
374,
63,
1832,
1012,
339,
347,
511,
63,
22355,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
4672,
14,
3892,
480,
88,
3471,
374,
63,
22355,
1012,
267,
291,
14,
1815,
8,
277,
14,
8283,
14,
3892,
480,
4672,
3471,
374,
63,
22355,
1012,
267,
291,
14,
3334,
8,
277,
14,
8283,
14,
3892,
480,
88,
3471,
374,
63,
22355,
1012,
339,
347,
511,
63,
3214,
8,
277,
304,
267,
367,
4678,
315,
1689,
65,
401,
298,
1391,
401,
298,
829,
2349,
288,
291,
14,
1815,
8,
277,
14,
8283,
14,
3892,
8,
3840,
680,
374,
63,
5329,
1012,
267,
291,
14,
3334,
8,
277,
14,
8283,
14,
3892,
480,
88,
3471,
374,
63,
5329,
1012,
339,
347,
511,
63,
5155,
63,
3892,
8,
277,
304,
267,
291,
14,
629,
8,
552,
8,
277,
14,
2119,
14,
362,
63,
14227,
4000,
586,
822,
8,
277,
14,
2119,
14,
362,
63,
7450,
4059,
398,
291,
14,
1855,
8,
10230,
12,
291,
14,
2119,
14,
3892,
12,
298,
1397,
63,
1681,
531,
339,
347,
511,
63,
9247,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
2119,
14,
3892,
480,
45,
1132,
3471,
374,
63,
3251,
1012,
267,
291,
14,
1815,
8,
277,
14,
45
] |
[
199,
774,
314,
3261,
402,
314,
4678,
1224,
859,
14,
199,
624,
199,
646,
4678,
1224,
199,
646,
2882,
4388,
199,
2864,
63,
6012,
275,
408,
199,
646,
984,
199,
199,
6463,
275,
5685,
199,
199,
533,
603,
1132,
26,
272,
1256,
63,
1391,
275,
5504,
272,
347,
282,
63,
765,
8,
80,
17,
12,
299,
18,
304,
267,
986,
199,
199,
318,
14909,
8,
65,
12,
330,
12,
627,
1391,
12,
1011,
829,
304,
272,
2288,
4681,
272,
4681,
275,
10954,
272,
671,
275,
6546,
272,
5739,
272,
347,
5007,
837,
267,
372,
671,
272,
372,
5007,
199,
199,
318,
3925,
837,
272,
986,
199,
199,
318,
3231,
63,
396,
837,
986,
199,
318,
3231,
63,
396,
837,
986,
199,
624,
421,
199,
318,
2342,
63,
1457,
8,
1457,
12,
536,
304,
272,
367,
682,
315,
1853,
14,
362,
63,
3223,
837,
267,
340,
682,
14,
362,
63,
354,
342,
508,
536,
26,
288,
372,
682,
421,
199,
533,
21478,
1224,
774,
8,
2796,
14,
1746,
304,
339,
2746,
275,
4678,
1224,
14,
3840,
1224,
8,
2864,
63,
6012,
12,
298,
15583,
298,
1628,
531,
272,
327,
5723,
17118,
370,
14570,
315,
7393,
63,
6012,
272,
603,
1132,
275,
2342,
63,
1457,
8,
2119,
12,
298,
45,
1132,
531,
272,
282,
63,
765,
275,
2342,
63,
1457,
8,
45,
1132,
12,
298,
65,
63,
765,
531,
272,
14909,
275,
2342,
63,
1457,
8,
2119,
12,
298,
8283,
531,
272,
5007,
275,
2342,
63,
1457,
8,
8283,
12,
298,
4672,
531,
272,
3925,
275,
2342,
63,
1457,
8,
2119,
12,
298,
1421,
531,
339,
347,
511,
63,
466,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
2119,
14,
362,
63,
466,
1062,
298,
578,
531,
267,
291,
14,
629,
8,
277,
14,
45,
1132,
14,
362,
63,
466,
1062,
298,
533,
531,
267,
291,
14,
629,
8,
277,
14,
65,
63,
765,
14,
362,
63,
466,
1062,
298,
1593,
531,
267,
291,
14,
629,
8,
277,
14,
8283,
14,
362,
63,
466,
1062,
298,
1593,
531,
267,
291,
14,
629,
8,
277,
14,
4672,
14,
362,
63,
466,
1062,
298,
1593,
531,
339,
347,
511,
63,
25499,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
2119,
14,
374,
63,
25499,
1012,
267,
291,
14,
3334,
8,
277,
14,
2119,
14,
1989,
63,
1628,
1012,
398,
291,
14,
1815,
8,
277,
14,
8283,
14,
374,
63,
25499,
1012,
339,
347,
511,
63,
6376,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
2119,
14,
374,
63,
6376,
1012,
267,
291,
14,
3334,
8,
277,
14,
45,
1132,
14,
374,
63,
6376,
1012,
267,
291,
14,
3334,
8,
277,
14,
8283,
14,
374,
63,
6376,
1012,
267,
291,
14,
1815,
8,
277,
14,
4672,
14,
374,
63,
6376,
1012,
339,
347,
511,
63,
3223,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
2119,
14,
1989,
63,
3223,
1012,
267,
291,
14,
1815,
8,
277,
14,
45,
1132,
14,
1989,
63,
3223,
1012,
267,
291,
14,
3334,
8,
277,
14,
1421,
14,
1989,
63,
3223,
1012,
339,
347,
511,
63,
3469,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
2119,
14,
362,
63,
3469,
1062,
378,
9,
267,
291,
14,
629,
8,
277,
14,
8283,
14,
362,
63,
3469,
1062,
4119,
9,
339,
347,
511,
63,
1593,
63,
815,
8,
277,
304,
267,
2562,
275,
291,
14,
8283,
267,
291,
14,
629,
8,
5917,
8,
1532,
14,
362,
63,
3214,
4000,
2097,
65,
401,
298,
66,
401,
298,
829,
401,
298,
1391,
3135,
267,
1420,
275,
2097,
65,
401,
298,
66,
401,
298,
4672,
401,
298,
829,
401,
298,
1391,
401,
298,
88,
937,
267,
291,
14,
629,
8,
5917,
8,
1532,
14,
362,
63,
9350,
4000,
1420,
9,
267,
291,
14,
629,
8,
5917,
8,
1532,
14,
362,
63,
8473,
4000,
2097,
1700,
401,
298,
6463,
3135,
267,
291,
14,
629,
8,
277,
14,
4672,
14,
362,
63,
70,
5710,
1062,
1689,
88,
401,
430,
339,
347,
511,
63,
8473,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
8283,
14,
3892,
480,
6463,
3471,
374,
63,
2966,
1012,
267,
291,
14,
3334,
8,
277,
14,
8283,
14,
3892,
480,
6463,
3471,
374,
63,
13545,
63,
2966,
1012,
267,
291,
14,
1815,
8,
277,
14,
8283,
14,
3892,
480,
1700,
3471,
374,
63,
2966,
1012,
267,
291,
14,
1815,
8,
277,
14,
8283,
14,
3892,
480,
1700,
3471,
374,
63,
13545,
63,
2966,
1012,
267,
291,
14,
3334,
8,
277,
14,
4672,
14,
3892,
480,
88,
3471,
374,
63,
2966,
1012,
267,
291,
14,
3334,
8,
277,
14,
45,
1132,
14,
3892,
480,
842,
63,
1391,
3471,
374,
63,
2966,
1012,
339,
347,
511,
63,
1832,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
8283,
14,
3892,
480,
88,
3471,
374,
63,
1832,
1012,
267,
291,
14,
3334,
8,
277,
14,
4672,
14,
3892,
480,
88,
3471,
374,
63,
1832,
1012,
339,
347,
511,
63,
22355,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
4672,
14,
3892,
480,
88,
3471,
374,
63,
22355,
1012,
267,
291,
14,
1815,
8,
277,
14,
8283,
14,
3892,
480,
4672,
3471,
374,
63,
22355,
1012,
267,
291,
14,
3334,
8,
277,
14,
8283,
14,
3892,
480,
88,
3471,
374,
63,
22355,
1012,
339,
347,
511,
63,
3214,
8,
277,
304,
267,
367,
4678,
315,
1689,
65,
401,
298,
1391,
401,
298,
829,
2349,
288,
291,
14,
1815,
8,
277,
14,
8283,
14,
3892,
8,
3840,
680,
374,
63,
5329,
1012,
267,
291,
14,
3334,
8,
277,
14,
8283,
14,
3892,
480,
88,
3471,
374,
63,
5329,
1012,
339,
347,
511,
63,
5155,
63,
3892,
8,
277,
304,
267,
291,
14,
629,
8,
552,
8,
277,
14,
2119,
14,
362,
63,
14227,
4000,
586,
822,
8,
277,
14,
2119,
14,
362,
63,
7450,
4059,
398,
291,
14,
1855,
8,
10230,
12,
291,
14,
2119,
14,
3892,
12,
298,
1397,
63,
1681,
531,
339,
347,
511,
63,
9247,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
2119,
14,
3892,
480,
45,
1132,
3471,
374,
63,
3251,
1012,
267,
291,
14,
1815,
8,
277,
14,
45,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nesdis/djongo
|
tests/django_tests/tests/v22/tests/postgres_tests/migrations/0002_create_test_models.py
|
11
|
10552
|
from django.core.serializers.json import DjangoJSONEncoder
from django.db import migrations, models
from ..fields import (
ArrayField, BigIntegerRangeField, CICharField, CIEmailField, CITextField,
DateRangeField, DateTimeRangeField, DecimalRangeField, HStoreField,
IntegerRangeField, JSONField, SearchVectorField,
)
from ..models import TagField
class Migration(migrations.Migration):
dependencies = [
('postgres_tests', '0001_setup_extensions'),
]
operations = [
migrations.CreateModel(
name='CharArrayModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', ArrayField(models.CharField(max_length=10), size=None)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='DateTimeArrayModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('datetimes', ArrayField(models.DateTimeField(), size=None)),
('dates', ArrayField(models.DateField(), size=None)),
('times', ArrayField(models.TimeField(), size=None)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='HStoreModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', HStoreField(blank=True, null=True)),
('array_field', ArrayField(HStoreField(), null=True)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='OtherTypesArrayModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('ips', ArrayField(models.GenericIPAddressField(), size=None, default=list)),
('uuids', ArrayField(models.UUIDField(), size=None, default=list)),
('decimals', ArrayField(models.DecimalField(max_digits=5, decimal_places=2), size=None, default=list)),
('tags', ArrayField(TagField(), blank=True, null=True, size=None)),
('json', ArrayField(JSONField(default={}), default=[])),
('int_ranges', ArrayField(IntegerRangeField(), null=True, blank=True)),
('bigint_ranges', ArrayField(BigIntegerRangeField(), null=True, blank=True)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='IntegerArrayModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', ArrayField(models.IntegerField(), size=None)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='NestedIntegerArrayModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', ArrayField(ArrayField(models.IntegerField(), size=None), size=None)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='NullableIntegerArrayModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', ArrayField(models.IntegerField(), size=None, null=True, blank=True)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='CharFieldModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', models.CharField(max_length=16)),
],
options=None,
bases=None,
),
migrations.CreateModel(
name='TextFieldModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', models.TextField()),
],
options=None,
bases=None,
),
migrations.CreateModel(
name='Scene',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('scene', models.CharField(max_length=255)),
('setting', models.CharField(max_length=255)),
],
options=None,
bases=None,
),
migrations.CreateModel(
name='Character',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=255)),
],
options=None,
bases=None,
),
migrations.CreateModel(
name='CITestModel',
fields=[
('name', CICharField(primary_key=True, max_length=255)),
('email', CIEmailField()),
('description', CITextField()),
('array_field', ArrayField(CITextField(), null=True)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=None,
),
migrations.CreateModel(
name='Line',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('scene', models.ForeignKey('postgres_tests.Scene', on_delete=models.SET_NULL)),
('character', models.ForeignKey('postgres_tests.Character', on_delete=models.SET_NULL)),
('dialogue', models.TextField(blank=True, null=True)),
('dialogue_search_vector', SearchVectorField(blank=True, null=True)),
('dialogue_config', models.CharField(max_length=100, blank=True, null=True)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=None,
),
migrations.CreateModel(
name='AggregateTestModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('boolean_field', models.BooleanField(null=True)),
('char_field', models.CharField(max_length=30, blank=True)),
('integer_field', models.IntegerField(null=True)),
]
),
migrations.CreateModel(
name='StatTestModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('int1', models.IntegerField()),
('int2', models.IntegerField()),
('related_field', models.ForeignKey(
'postgres_tests.AggregateTestModel',
models.SET_NULL,
null=True,
)),
]
),
migrations.CreateModel(
name='NowTestModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('when', models.DateTimeField(null=True, default=None)),
]
),
migrations.CreateModel(
name='UUIDTestModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('uuid', models.UUIDField(default=None, null=True)),
]
),
migrations.CreateModel(
name='RangesModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('ints', IntegerRangeField(null=True, blank=True)),
('bigints', BigIntegerRangeField(null=True, blank=True)),
('decimals', DecimalRangeField(null=True, blank=True)),
('timestamps', DateTimeRangeField(null=True, blank=True)),
('dates', DateRangeField(null=True, blank=True)),
],
options={
'required_db_vendor': 'postgresql'
},
bases=(models.Model,)
),
migrations.CreateModel(
name='RangeLookupsModel',
fields=[
('parent', models.ForeignKey(
'postgres_tests.RangesModel',
models.SET_NULL,
blank=True, null=True,
)),
('integer', models.IntegerField(blank=True, null=True)),
('big_integer', models.BigIntegerField(blank=True, null=True)),
('float', models.FloatField(blank=True, null=True)),
('timestamp', models.DateTimeField(blank=True, null=True)),
('date', models.DateField(blank=True, null=True)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='JSONModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', JSONField(null=True, blank=True)),
('field_custom', JSONField(null=True, blank=True, encoder=DjangoJSONEncoder)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
]
|
agpl-3.0
|
[
504,
1639,
14,
1018,
14,
12844,
14,
1001,
492,
5634,
23069,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
199,
504,
2508,
955,
492,
334,
272,
8725,
792,
12,
13123,
2674,
28707,
12,
445,
948,
8210,
792,
12,
445,
4332,
1198,
792,
12,
445,
649,
832,
792,
12,
272,
6148,
28707,
12,
13686,
28707,
12,
6345,
28707,
12,
869,
5502,
792,
12,
272,
7225,
28707,
12,
4840,
792,
12,
8730,
3646,
792,
12,
199,
9,
199,
504,
2508,
992,
492,
8053,
792,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
10675,
63,
2219,
297,
283,
4183,
63,
2758,
63,
5359,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
1610,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
8725,
792,
8,
992,
14,
2183,
8,
988,
63,
1267,
29,
709,
395,
1568,
29,
403,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
3926,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
31601,
297,
8725,
792,
8,
992,
14,
4626,
1062,
1568,
29,
403,
1826,
355,
661,
9356,
297,
8725,
792,
8,
992,
14,
14071,
1062,
1568,
29,
403,
1826,
355,
661,
4508,
297,
8725,
792,
8,
992,
14,
27115,
1062,
1568,
29,
403,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
40,
5502,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
869,
5502,
792,
8,
2500,
29,
549,
12,
2973,
29,
549,
1826,
355,
661,
1144,
63,
698,
297,
8725,
792,
8,
40,
5502,
792,
1062,
2973,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
8632,
4100,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
6142,
297,
8725,
792,
8,
992,
14,
9417,
26969,
1062,
1568,
29,
403,
12,
849,
29,
513,
1826,
355,
661,
18401,
297,
8725,
792,
8,
992,
14,
8757,
792,
1062,
1568,
29,
403,
12,
849,
29,
513,
1826,
355,
661,
6355,
83,
297,
8725,
792,
8,
992,
14,
15975,
8,
988,
63,
7022,
29,
21,
12,
6107,
63,
10696,
29,
18,
395,
1568,
29,
403,
12,
849,
29,
513,
1826,
355,
661,
2969,
297,
8725,
792,
8,
1931,
792,
1062,
4596,
29,
549,
12,
2973,
29,
549,
12,
1568,
29,
403,
1826,
355,
661,
1001,
297,
8725,
792,
8,
30796,
8,
885,
7622,
395,
849,
1524,
12884,
355,
661,
442,
63,
8404,
297,
8725,
792,
8,
2674,
28707,
1062,
2973,
29,
549,
12,
4596,
29,
549,
1826,
355,
661,
24884,
63,
8404,
297,
8725,
792,
8,
7279,
2674,
28707,
1062,
2973,
29,
549,
12,
4596,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
2674,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
8725,
792,
8,
992,
14,
3901,
1062,
1568,
29,
403,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
13029,
2674,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
8725,
792,
8,
3836,
792,
8,
992,
14,
3901,
1062,
1568,
29,
403,
395,
1568,
29,
403,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
8849,
461,
2674,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
8725,
792,
8,
992,
14,
3901,
1062,
1568,
29,
403,
12,
2973,
29,
549,
12,
4596,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
2183,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
975,
1826,
288,
2156,
288,
1511,
29,
403,
12,
288,
9768,
29,
403,
12,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
6254,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709
] |
[
1639,
14,
1018,
14,
12844,
14,
1001,
492,
5634,
23069,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
199,
504,
2508,
955,
492,
334,
272,
8725,
792,
12,
13123,
2674,
28707,
12,
445,
948,
8210,
792,
12,
445,
4332,
1198,
792,
12,
445,
649,
832,
792,
12,
272,
6148,
28707,
12,
13686,
28707,
12,
6345,
28707,
12,
869,
5502,
792,
12,
272,
7225,
28707,
12,
4840,
792,
12,
8730,
3646,
792,
12,
199,
9,
199,
504,
2508,
992,
492,
8053,
792,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
10675,
63,
2219,
297,
283,
4183,
63,
2758,
63,
5359,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
1610,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
8725,
792,
8,
992,
14,
2183,
8,
988,
63,
1267,
29,
709,
395,
1568,
29,
403,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
3926,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
31601,
297,
8725,
792,
8,
992,
14,
4626,
1062,
1568,
29,
403,
1826,
355,
661,
9356,
297,
8725,
792,
8,
992,
14,
14071,
1062,
1568,
29,
403,
1826,
355,
661,
4508,
297,
8725,
792,
8,
992,
14,
27115,
1062,
1568,
29,
403,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
40,
5502,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
869,
5502,
792,
8,
2500,
29,
549,
12,
2973,
29,
549,
1826,
355,
661,
1144,
63,
698,
297,
8725,
792,
8,
40,
5502,
792,
1062,
2973,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
8632,
4100,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
6142,
297,
8725,
792,
8,
992,
14,
9417,
26969,
1062,
1568,
29,
403,
12,
849,
29,
513,
1826,
355,
661,
18401,
297,
8725,
792,
8,
992,
14,
8757,
792,
1062,
1568,
29,
403,
12,
849,
29,
513,
1826,
355,
661,
6355,
83,
297,
8725,
792,
8,
992,
14,
15975,
8,
988,
63,
7022,
29,
21,
12,
6107,
63,
10696,
29,
18,
395,
1568,
29,
403,
12,
849,
29,
513,
1826,
355,
661,
2969,
297,
8725,
792,
8,
1931,
792,
1062,
4596,
29,
549,
12,
2973,
29,
549,
12,
1568,
29,
403,
1826,
355,
661,
1001,
297,
8725,
792,
8,
30796,
8,
885,
7622,
395,
849,
1524,
12884,
355,
661,
442,
63,
8404,
297,
8725,
792,
8,
2674,
28707,
1062,
2973,
29,
549,
12,
4596,
29,
549,
1826,
355,
661,
24884,
63,
8404,
297,
8725,
792,
8,
7279,
2674,
28707,
1062,
2973,
29,
549,
12,
4596,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
2674,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
8725,
792,
8,
992,
14,
3901,
1062,
1568,
29,
403,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
13029,
2674,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
8725,
792,
8,
3836,
792,
8,
992,
14,
3901,
1062,
1568,
29,
403,
395,
1568,
29,
403,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
8849,
461,
2674,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
8725,
792,
8,
992,
14,
3901,
1062,
1568,
29,
403,
12,
2973,
29,
549,
12,
4596,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
2183,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
975,
1826,
288,
2156,
288,
1511,
29,
403,
12,
288,
9768,
29,
403,
12,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
6254,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
theimaginaire/dayone
|
node_modules/node-gyp/gyp/pylib/gyp/win_tool.py
|
1417
|
12751
|
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Utility functions for Windows builds.
These functions are executed via gyp-win-tool when using the ninja generator.
"""
import os
import re
import shutil
import subprocess
import stat
import string
import sys
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# A regex matching an argument corresponding to the output filename passed to
# link.exe.
_LINK_EXE_OUT_ARG = re.compile('/OUT:(?P<out>.+)$', re.IGNORECASE)
def main(args):
executor = WinTool()
exit_code = executor.Dispatch(args)
if exit_code is not None:
sys.exit(exit_code)
class WinTool(object):
"""This class performs all the Windows tooling steps. The methods can either
be executed directly, or dispatched from an argument list."""
def _UseSeparateMspdbsrv(self, env, args):
"""Allows to use a unique instance of mspdbsrv.exe per linker instead of a
shared one."""
if len(args) < 1:
raise Exception("Not enough arguments")
if args[0] != 'link.exe':
return
# Use the output filename passed to the linker to generate an endpoint name
# for mspdbsrv.exe.
endpoint_name = None
for arg in args:
m = _LINK_EXE_OUT_ARG.match(arg)
if m:
endpoint_name = re.sub(r'\W+', '',
'%s_%d' % (m.group('out'), os.getpid()))
break
if endpoint_name is None:
return
# Adds the appropriate environment variable. This will be read by link.exe
# to know which instance of mspdbsrv.exe it should connect to (if it's
# not set then the default endpoint is used).
env['_MSPDBSRV_ENDPOINT_'] = endpoint_name
def Dispatch(self, args):
"""Dispatches a string command to a method."""
if len(args) < 1:
raise Exception("Not enough arguments")
method = "Exec%s" % self._CommandifyName(args[0])
return getattr(self, method)(*args[1:])
def _CommandifyName(self, name_string):
"""Transforms a tool name like recursive-mirror to RecursiveMirror."""
return name_string.title().replace('-', '')
def _GetEnv(self, arch):
"""Gets the saved environment from a file for a given architecture."""
# The environment is saved as an "environment block" (see CreateProcess
# and msvs_emulation for details). We convert to a dict here.
# Drop last 2 NULs, one for list terminator, one for trailing vs. separator.
pairs = open(arch).read()[:-2].split('\0')
kvs = [item.split('=', 1) for item in pairs]
return dict(kvs)
def ExecStamp(self, path):
"""Simple stamp command."""
open(path, 'w').close()
def ExecRecursiveMirror(self, source, dest):
"""Emulation of rm -rf out && cp -af in out."""
if os.path.exists(dest):
if os.path.isdir(dest):
def _on_error(fn, path, excinfo):
# The operation failed, possibly because the file is set to
# read-only. If that's why, make it writable and try the op again.
if not os.access(path, os.W_OK):
os.chmod(path, stat.S_IWRITE)
fn(path)
shutil.rmtree(dest, onerror=_on_error)
else:
if not os.access(dest, os.W_OK):
# Attempt to make the file writable before deleting it.
os.chmod(dest, stat.S_IWRITE)
os.unlink(dest)
if os.path.isdir(source):
shutil.copytree(source, dest)
else:
shutil.copy2(source, dest)
def ExecLinkWrapper(self, arch, use_separate_mspdbsrv, *args):
"""Filter diagnostic output from link that looks like:
' Creating library ui.dll.lib and object ui.dll.exp'
This happens when there are exports from the dll or exe.
"""
env = self._GetEnv(arch)
if use_separate_mspdbsrv == 'True':
self._UseSeparateMspdbsrv(env, args)
link = subprocess.Popen([args[0].replace('/', '\\')] + list(args[1:]),
shell=True,
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
out, _ = link.communicate()
for line in out.splitlines():
if (not line.startswith(' Creating library ') and
not line.startswith('Generating code') and
not line.startswith('Finished generating code')):
print line
return link.returncode
def ExecLinkWithManifests(self, arch, embed_manifest, out, ldcmd, resname,
mt, rc, intermediate_manifest, *manifests):
"""A wrapper for handling creating a manifest resource and then executing
a link command."""
# The 'normal' way to do manifests is to have link generate a manifest
# based on gathering dependencies from the object files, then merge that
# manifest with other manifests supplied as sources, convert the merged
# manifest to a resource, and then *relink*, including the compiled
# version of the manifest resource. This breaks incremental linking, and
# is generally overly complicated. Instead, we merge all the manifests
# provided (along with one that includes what would normally be in the
# linker-generated one, see msvs_emulation.py), and include that into the
# first and only link. We still tell link to generate a manifest, but we
# only use that to assert that our simpler process did not miss anything.
variables = {
'python': sys.executable,
'arch': arch,
'out': out,
'ldcmd': ldcmd,
'resname': resname,
'mt': mt,
'rc': rc,
'intermediate_manifest': intermediate_manifest,
'manifests': ' '.join(manifests),
}
add_to_ld = ''
if manifests:
subprocess.check_call(
'%(python)s gyp-win-tool manifest-wrapper %(arch)s %(mt)s -nologo '
'-manifest %(manifests)s -out:%(out)s.manifest' % variables)
if embed_manifest == 'True':
subprocess.check_call(
'%(python)s gyp-win-tool manifest-to-rc %(arch)s %(out)s.manifest'
' %(out)s.manifest.rc %(resname)s' % variables)
subprocess.check_call(
'%(python)s gyp-win-tool rc-wrapper %(arch)s %(rc)s '
'%(out)s.manifest.rc' % variables)
add_to_ld = ' %(out)s.manifest.res' % variables
subprocess.check_call(ldcmd + add_to_ld)
# Run mt.exe on the theoretically complete manifest we generated, merging
# it with the one the linker generated to confirm that the linker
# generated one does not add anything. This is strictly unnecessary for
# correctness, it's only to verify that e.g. /MANIFESTDEPENDENCY was not
# used in a #pragma comment.
if manifests:
# Merge the intermediate one with ours to .assert.manifest, then check
# that .assert.manifest is identical to ours.
subprocess.check_call(
'%(python)s gyp-win-tool manifest-wrapper %(arch)s %(mt)s -nologo '
'-manifest %(out)s.manifest %(intermediate_manifest)s '
'-out:%(out)s.assert.manifest' % variables)
assert_manifest = '%(out)s.assert.manifest' % variables
our_manifest = '%(out)s.manifest' % variables
# Load and normalize the manifests. mt.exe sometimes removes whitespace,
# and sometimes doesn't unfortunately.
with open(our_manifest, 'rb') as our_f:
with open(assert_manifest, 'rb') as assert_f:
our_data = our_f.read().translate(None, string.whitespace)
assert_data = assert_f.read().translate(None, string.whitespace)
if our_data != assert_data:
os.unlink(out)
def dump(filename):
sys.stderr.write('%s\n-----\n' % filename)
with open(filename, 'rb') as f:
sys.stderr.write(f.read() + '\n-----\n')
dump(intermediate_manifest)
dump(our_manifest)
dump(assert_manifest)
sys.stderr.write(
'Linker generated manifest "%s" added to final manifest "%s" '
'(result in "%s"). '
'Were /MANIFEST switches used in #pragma statements? ' % (
intermediate_manifest, our_manifest, assert_manifest))
return 1
def ExecManifestWrapper(self, arch, *args):
"""Run manifest tool with environment set. Strip out undesirable warning
(some XML blocks are recognized by the OS loader, but not the manifest
tool)."""
env = self._GetEnv(arch)
popen = subprocess.Popen(args, shell=True, env=env,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out, _ = popen.communicate()
for line in out.splitlines():
if line and 'manifest authoring warning 81010002' not in line:
print line
return popen.returncode
def ExecManifestToRc(self, arch, *args):
"""Creates a resource file pointing a SxS assembly manifest.
|args| is tuple containing path to resource file, path to manifest file
and resource name which can be "1" (for executables) or "2" (for DLLs)."""
manifest_path, resource_path, resource_name = args
with open(resource_path, 'wb') as output:
output.write('#include <windows.h>\n%s RT_MANIFEST "%s"' % (
resource_name,
os.path.abspath(manifest_path).replace('\\', '/')))
def ExecMidlWrapper(self, arch, outdir, tlb, h, dlldata, iid, proxy, idl,
*flags):
"""Filter noisy filenames output from MIDL compile step that isn't
quietable via command line flags.
"""
args = ['midl', '/nologo'] + list(flags) + [
'/out', outdir,
'/tlb', tlb,
'/h', h,
'/dlldata', dlldata,
'/iid', iid,
'/proxy', proxy,
idl]
env = self._GetEnv(arch)
popen = subprocess.Popen(args, shell=True, env=env,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out, _ = popen.communicate()
# Filter junk out of stdout, and write filtered versions. Output we want
# to filter is pairs of lines that look like this:
# Processing C:\Program Files (x86)\Microsoft SDKs\...\include\objidl.idl
# objidl.idl
lines = out.splitlines()
prefixes = ('Processing ', '64 bit Processing ')
processing = set(os.path.basename(x)
for x in lines if x.startswith(prefixes))
for line in lines:
if not line.startswith(prefixes) and line not in processing:
print line
return popen.returncode
def ExecAsmWrapper(self, arch, *args):
"""Filter logo banner from invocations of asm.exe."""
env = self._GetEnv(arch)
popen = subprocess.Popen(args, shell=True, env=env,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out, _ = popen.communicate()
for line in out.splitlines():
if (not line.startswith('Copyright (C) Microsoft Corporation') and
not line.startswith('Microsoft (R) Macro Assembler') and
not line.startswith(' Assembling: ') and
line):
print line
return popen.returncode
def ExecRcWrapper(self, arch, *args):
"""Filter logo banner from invocations of rc.exe. Older versions of RC
don't support the /nologo flag."""
env = self._GetEnv(arch)
popen = subprocess.Popen(args, shell=True, env=env,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out, _ = popen.communicate()
for line in out.splitlines():
if (not line.startswith('Microsoft (R) Windows (R) Resource Compiler') and
not line.startswith('Copyright (C) Microsoft Corporation') and
line):
print line
return popen.returncode
def ExecActionWrapper(self, arch, rspfile, *dir):
"""Runs an action command line from a response file using the environment
for |arch|. If |dir| is supplied, use that as the working directory."""
env = self._GetEnv(arch)
# TODO(scottmg): This is a temporary hack to get some specific variables
# through to actions that are set after gyp-time. http://crbug.com/333738.
for k, v in os.environ.iteritems():
if k not in env:
env[k] = v
args = open(rspfile).read()
dir = dir[0] if dir else None
return subprocess.call(args, shell=True, env=env, cwd=dir)
def ExecClCompile(self, project_dir, selected_files):
"""Executed by msvs-ninja projects when the 'ClCompile' target is used to
build selected C/C++ files."""
project_dir = os.path.relpath(project_dir, BASE_DIR)
selected_files = selected_files.split(';')
ninja_targets = [os.path.join(project_dir, filename) + '^^'
for filename in selected_files]
cmd = ['ninja.exe']
cmd.extend(ninja_targets)
return subprocess.call(cmd, shell=True, cwd=BASE_DIR)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
17505,
3423,
367,
5417,
14723,
14,
199,
199,
20676,
3423,
787,
7934,
4799,
4902,
13,
2676,
13,
3557,
1380,
1808,
314,
14822,
4306,
14,
199,
624,
199,
199,
646,
747,
199,
646,
295,
199,
646,
5145,
199,
646,
3873,
199,
646,
5672,
199,
646,
1059,
199,
646,
984,
199,
199,
5825,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
199,
3,
437,
5163,
4877,
376,
1423,
5226,
370,
314,
1072,
1788,
3032,
370,
199,
3,
2142,
14,
5803,
14,
199,
63,
7916,
63,
23017,
63,
1877,
63,
11611,
275,
295,
14,
2014,
2336,
1877,
26,
2229,
48,
28,
548,
31411,
29150,
295,
14,
15434,
9,
199,
199,
318,
2446,
8,
589,
304,
523,
13270,
275,
13036,
5157,
342,
523,
4458,
63,
600,
275,
13270,
14,
20628,
8,
589,
9,
523,
340,
4458,
63,
600,
365,
440,
488,
26,
272,
984,
14,
2224,
8,
2224,
63,
600,
9,
421,
199,
533,
13036,
5157,
8,
785,
304,
523,
408,
2765,
1021,
18628,
1006,
314,
5417,
4744,
316,
7124,
14,
710,
3102,
883,
1902,
523,
506,
7934,
5370,
12,
503,
7634,
379,
687,
376,
1423,
769,
1041,
819,
347,
485,
6119,
12653,
323,
45,
681,
697,
15165,
8,
277,
12,
2589,
12,
1249,
304,
272,
408,
19780,
370,
675,
282,
3747,
1256,
402,
333,
681,
697,
15165,
14,
5803,
1126,
17261,
3140,
402,
282,
272,
5709,
1373,
1041,
272,
340,
822,
8,
589,
9,
665,
413,
26,
489,
746,
2186,
480,
1763,
8321,
2368,
531,
339,
340,
1249,
59,
16,
61,
1137,
283,
1073,
14,
5803,
356,
489,
372,
339,
327,
3645,
314,
1072,
1788,
3032,
370,
314,
17261,
370,
3550,
376,
6037,
536,
272,
327,
367,
333,
681,
697,
15165,
14,
5803,
14,
272,
6037,
63,
354,
275,
488,
272,
367,
1680,
315,
1249,
26,
489,
333,
275,
485,
7916,
63,
23017,
63,
1877,
63,
11611,
14,
1431,
8,
1273,
9,
489,
340,
333,
26,
267,
6037,
63,
354,
275,
295,
14,
954,
8,
82,
1154,
55,
7386,
3260,
288,
1543,
83,
4970,
68,
7,
450,
334,
77,
14,
923,
360,
548,
659,
747,
14,
17829,
4059,
267,
2059,
339,
340,
6037,
63,
354,
365,
488,
26,
489,
372,
339,
327,
15747,
314,
5827,
3734,
1750,
14,
961,
911,
506,
1586,
701,
2142,
14,
5803,
272,
327,
370,
5715,
1314,
1256,
402,
333,
681,
697,
15165,
14,
5803,
652,
1077,
4907,
370,
334,
692,
652,
1159,
272,
327,
440,
663,
2066,
314,
849,
6037,
365,
1202,
680,
272,
2589,
8680,
3053,
32641,
31546,
63,
21054,
63,
418,
275,
6037,
63,
354,
819,
347,
28626,
8,
277,
12,
1249,
304,
272,
408,
2825,
11350,
282,
1059,
1414,
370,
282,
1083,
1041,
272,
340,
822,
8,
589,
9,
665,
413,
26,
489,
746,
2186,
480,
1763,
8321,
2368,
531,
339,
1083,
275,
298,
4858,
5,
83,
2,
450,
291,
423,
5150,
290,
29552,
985,
8,
589,
59,
16,
566,
272,
372,
2519,
8,
277,
12,
1083,
25967,
589,
59,
17,
5728,
819,
347,
485,
5150,
290,
29552,
985,
8,
277,
12,
536,
63,
875,
304,
272,
408,
3188,
3351,
282,
4744,
536,
2839,
9133,
13,
12324,
370,
18306,
3398,
28034,
1041,
272,
372,
536,
63,
875,
14,
1213,
1252,
1814,
13858,
4074,
819,
347,
485,
1002,
7744,
8,
277,
12,
3819,
304,
272,
408,
14426,
314,
6290,
3734,
687,
282,
570,
367,
282,
1627,
15931,
1041,
272,
327,
710,
3734,
365,
6290,
465,
376,
298,
5418,
1853,
2,
334,
3239,
2790,
3498,
272,
327,
436,
13795,
63,
20526,
367,
2436,
680,
2136,
3957,
370,
282,
1211,
2348,
14,
272,
327,
18110,
2061,
499,
653,
1293,
83,
12,
1373,
367,
769,
31298,
12,
1373,
367,
8520,
8118,
14,
9432,
14,
272,
6342,
275,
1551,
8,
1047,
680,
739,
342,
4439,
18,
1055,
1294,
2258,
16,
358,
272,
1022,
3122,
275,
359,
1053,
14,
1294,
25283,
413,
9,
367,
1242,
315,
6342,
61,
272,
372,
1211,
8,
30862,
9,
819,
347,
9434,
16649,
8,
277,
12,
931,
304,
272,
408,
3184,
16206,
1414,
1041,
272,
1551,
8,
515,
12,
283,
87,
1959,
1600,
342,
819,
347,
9434,
25122,
28034,
8,
277,
12,
1350,
12,
2053,
304,
272,
408,
15754,
402,
14267,
446,
3941,
734,
10883,
7667,
446,
2756,
315,
734,
1041,
272,
340,
747,
14,
515,
14,
2444,
8,
2614,
304,
489,
340,
747,
14,
515,
14,
6027,
8,
2614,
304,
267,
347,
485,
265,
63,
705,
8,
2324,
12,
931,
12,
21596,
304,
881,
327,
710,
3439,
3405,
12,
12570,
2952,
314,
570,
365,
663,
370,
881,
327,
1586,
13,
2118,
14,
982,
626,
1159,
10842,
12,
1852,
652,
17267,
436,
862,
314,
1687,
4020,
14,
881,
340,
440,
747,
14,
2732,
8,
515,
12,
747,
14,
55,
63,
3593,
304,
288,
747,
14,
11693,
8,
515,
12,
5672,
14,
51,
63,
41,
10387,
9,
881,
4325,
8,
515,
9,
267,
5145,
14,
9242,
8,
2614,
12,
22852,
3699,
265,
63,
705,
9,
489,
587,
26,
267,
340,
440,
747,
14,
2732,
8,
2614,
12,
747,
14,
55,
63,
3593,
304,
881,
327,
23115,
370,
1852,
314,
570,
17267,
2544,
13794,
652,
14,
881,
747,
14,
11693,
8,
2614,
12,
5672,
14,
51,
63,
41,
10387,
9,
267,
747,
14,
7162,
8,
2614,
9,
339,
340,
747,
14,
515,
14,
6027,
8,
1365,
304,
489,
5145,
14,
29296,
8,
1365,
12,
2053,
9,
272,
587,
26,
489,
5145,
14,
1574,
18,
8,
1365,
12,
2053,
9,
819,
347,
9434,
3834,
4590,
8,
277,
12,
3819,
12,
675,
63,
24904,
63,
77,
681,
697,
15165,
12,
627,
589,
304,
272,
408,
4131,
8348,
19075,
1072,
687,
2142,
626,
10734,
2839,
26,
272,
283,
257,
20507,
3555,
8574,
14,
9259,
14,
773,
436,
909,
8574,
14,
9259,
14,
1474,
7,
272,
961,
10986,
1380,
2337,
787,
22609,
687,
314,
17112,
503,
14778,
14,
272,
408,
272,
2589,
275,
291,
423
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
17505,
3423,
367,
5417,
14723,
14,
199,
199,
20676,
3423,
787,
7934,
4799,
4902,
13,
2676,
13,
3557,
1380,
1808,
314,
14822,
4306,
14,
199,
624,
199,
199,
646,
747,
199,
646,
295,
199,
646,
5145,
199,
646,
3873,
199,
646,
5672,
199,
646,
1059,
199,
646,
984,
199,
199,
5825,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
199,
3,
437,
5163,
4877,
376,
1423,
5226,
370,
314,
1072,
1788,
3032,
370,
199,
3,
2142,
14,
5803,
14,
199,
63,
7916,
63,
23017,
63,
1877,
63,
11611,
275,
295,
14,
2014,
2336,
1877,
26,
2229,
48,
28,
548,
31411,
29150,
295,
14,
15434,
9,
199,
199,
318,
2446,
8,
589,
304,
523,
13270,
275,
13036,
5157,
342,
523,
4458,
63,
600,
275,
13270,
14,
20628,
8,
589,
9,
523,
340,
4458,
63,
600,
365,
440,
488,
26,
272,
984,
14,
2224,
8,
2224,
63,
600,
9,
421,
199,
533,
13036,
5157,
8,
785,
304,
523,
408,
2765,
1021,
18628,
1006,
314,
5417,
4744,
316,
7124,
14,
710,
3102,
883,
1902,
523,
506,
7934,
5370,
12,
503,
7634,
379,
687,
376,
1423,
769,
1041,
819,
347,
485,
6119,
12653,
323,
45,
681,
697,
15165,
8,
277,
12,
2589,
12,
1249,
304,
272,
408,
19780,
370,
675,
282,
3747,
1256,
402,
333,
681,
697,
15165,
14,
5803,
1126,
17261,
3140,
402,
282,
272,
5709,
1373,
1041,
272,
340,
822,
8,
589,
9,
665,
413,
26,
489,
746,
2186,
480,
1763,
8321,
2368,
531,
339,
340,
1249,
59,
16,
61,
1137,
283,
1073,
14,
5803,
356,
489,
372,
339,
327,
3645,
314,
1072,
1788,
3032,
370,
314,
17261,
370,
3550,
376,
6037,
536,
272,
327,
367,
333,
681,
697,
15165,
14,
5803,
14,
272,
6037,
63,
354,
275,
488,
272,
367,
1680,
315,
1249,
26,
489,
333,
275,
485,
7916,
63,
23017,
63,
1877,
63,
11611,
14,
1431,
8,
1273,
9,
489,
340,
333,
26,
267,
6037,
63,
354,
275,
295,
14,
954,
8,
82,
1154,
55,
7386,
3260,
288,
1543,
83,
4970,
68,
7,
450,
334,
77,
14,
923,
360,
548,
659,
747,
14,
17829,
4059,
267,
2059,
339,
340,
6037,
63,
354,
365,
488,
26,
489,
372,
339,
327,
15747,
314,
5827,
3734,
1750,
14,
961,
911,
506,
1586,
701,
2142,
14,
5803,
272,
327,
370,
5715,
1314,
1256,
402,
333,
681,
697,
15165,
14,
5803,
652,
1077,
4907,
370,
334,
692,
652,
1159,
272,
327,
440,
663,
2066,
314,
849,
6037,
365,
1202,
680,
272,
2589,
8680,
3053,
32641,
31546,
63,
21054,
63,
418,
275,
6037,
63,
354,
819,
347,
28626,
8,
277,
12,
1249,
304,
272,
408,
2825,
11350,
282,
1059,
1414,
370,
282,
1083,
1041,
272,
340,
822,
8,
589,
9,
665,
413,
26,
489,
746,
2186,
480,
1763,
8321,
2368,
531,
339,
1083,
275,
298,
4858,
5,
83,
2,
450,
291,
423,
5150,
290,
29552,
985,
8,
589,
59,
16,
566,
272,
372,
2519,
8,
277,
12,
1083,
25967,
589,
59,
17,
5728,
819,
347,
485,
5150,
290,
29552,
985,
8,
277,
12,
536,
63,
875,
304,
272,
408,
3188,
3351,
282,
4744,
536,
2839,
9133,
13,
12324,
370,
18306,
3398,
28034,
1041,
272,
372,
536,
63,
875,
14,
1213,
1252,
1814,
13858,
4074,
819,
347,
485,
1002,
7744,
8,
277,
12,
3819,
304,
272,
408,
14426,
314,
6290,
3734,
687,
282,
570,
367,
282,
1627,
15931,
1041,
272,
327,
710,
3734,
365,
6290,
465,
376,
298,
5418,
1853,
2,
334,
3239,
2790,
3498,
272,
327,
436,
13795,
63,
20526,
367,
2436,
680,
2136,
3957,
370,
282,
1211,
2348,
14,
272,
327,
18110,
2061,
499,
653,
1293,
83,
12,
1373,
367,
769,
31298,
12,
1373,
367,
8520,
8118,
14,
9432,
14,
272,
6342,
275,
1551,
8,
1047,
680,
739,
342,
4439,
18,
1055,
1294,
2258,
16,
358,
272,
1022,
3122,
275,
359,
1053,
14,
1294,
25283,
413,
9,
367,
1242,
315,
6342,
61,
272,
372,
1211,
8,
30862,
9,
819,
347,
9434,
16649,
8,
277,
12,
931,
304,
272,
408,
3184,
16206,
1414,
1041,
272,
1551,
8,
515,
12,
283,
87,
1959,
1600,
342,
819,
347,
9434,
25122,
28034,
8,
277,
12,
1350,
12,
2053,
304,
272,
408,
15754,
402,
14267,
446,
3941,
734,
10883,
7667,
446,
2756,
315,
734,
1041,
272,
340,
747,
14,
515,
14,
2444,
8,
2614,
304,
489,
340,
747,
14,
515,
14,
6027,
8,
2614,
304,
267,
347,
485,
265,
63,
705,
8,
2324,
12,
931,
12,
21596,
304,
881,
327,
710,
3439,
3405,
12,
12570,
2952,
314,
570,
365,
663,
370,
881,
327,
1586,
13,
2118,
14,
982,
626,
1159,
10842,
12,
1852,
652,
17267,
436,
862,
314,
1687,
4020,
14,
881,
340,
440,
747,
14,
2732,
8,
515,
12,
747,
14,
55,
63,
3593,
304,
288,
747,
14,
11693,
8,
515,
12,
5672,
14,
51,
63,
41,
10387,
9,
881,
4325,
8,
515,
9,
267,
5145,
14,
9242,
8,
2614,
12,
22852,
3699,
265,
63,
705,
9,
489,
587,
26,
267,
340,
440,
747,
14,
2732,
8,
2614,
12,
747,
14,
55,
63,
3593,
304,
881,
327,
23115,
370,
1852,
314,
570,
17267,
2544,
13794,
652,
14,
881,
747,
14,
11693,
8,
2614,
12,
5672,
14,
51,
63,
41,
10387,
9,
267,
747,
14,
7162,
8,
2614,
9,
339,
340,
747,
14,
515,
14,
6027,
8,
1365,
304,
489,
5145,
14,
29296,
8,
1365,
12,
2053,
9,
272,
587,
26,
489,
5145,
14,
1574,
18,
8,
1365,
12,
2053,
9,
819,
347,
9434,
3834,
4590,
8,
277,
12,
3819,
12,
675,
63,
24904,
63,
77,
681,
697,
15165,
12,
627,
589,
304,
272,
408,
4131,
8348,
19075,
1072,
687,
2142,
626,
10734,
2839,
26,
272,
283,
257,
20507,
3555,
8574,
14,
9259,
14,
773,
436,
909,
8574,
14,
9259,
14,
1474,
7,
272,
961,
10986,
1380,
2337,
787,
22609,
687,
314,
17112,
503,
14778,
14,
272,
408,
272,
2589,
275,
291,
423,
0
] |
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
] |
bdeluca/oiio
|
testsuite/oiiotool/run.py
|
1
|
15510
|
#!/usr/bin/env python
# Create some test images we need
command += oiiotool ("--create 320x240 3 -d uint8 -o black.tif")
command += oiiotool ("--pattern constant:color=0.5,0.5,0.5 128x128 3 -d half -o grey128.exr")
command += oiiotool ("--pattern constant:color=0.5,0.5,0.5 64x64 3 -d half -o grey64.exr")
command += oiiotool ("--create 256x256 3 --fill:color=1,.5,.5 256x256 --fill:color=0,1,0 80x80+100+100 -d uint8 -o filled.tif")
# test --autotrim
command += oiiotool ("black.tif --fill:color=0,1,0 80x80+100+100 --autotrim -d uint8 -o autotrim.tif")
# test --colorcount (using the results of the --fill test)
command += oiiotool ("filled.tif --colorcount:eps=.1,.1,.1 0,0,0:1,.5,.5:0,1,0")
# test --rangecheck (using the results of the --fill test)
command += oiiotool ("filled.tif --rangecheck 0,0,0 1,0.9,1")
# test --rangecompress & --rangeexpand
command += oiiotool ("src/tahoe-small.tif --rangecompress -d uint8 -o rangecompress.tif")
command += oiiotool ("rangecompress.tif --rangeexpand -d uint8 -o rangeexpand.tif")
command += oiiotool ("src/tahoe-small.tif --rangecompress:luma=1 -d uint8 -o rangecompress-luma.tif")
command += oiiotool ("rangecompress-luma.tif --rangeexpand:luma=1 -d uint8 -o rangeexpand-luma.tif")
# test resample
command += oiiotool (parent + "/oiio-images/grid.tif --resample 128x128 -o resample.tif")
# test resize
command += oiiotool (parent + "/oiio-images/grid.tif --resize 256x256 -o resize.tif")
command += oiiotool (parent + "/oiio-images/grid.tif --resize 25% -o resize2.tif")
# test extreme resize
command += oiiotool (parent + "/oiio-images/grid.tif --resize 64x64 -o resize64.tif")
command += oiiotool ("resize64.tif --resize 512x512 -o resize512.tif")
# test fit
command += oiiotool (parent + "/oiio-images/grid.tif --fit 360x240 -d uint8 -o fit.tif")
command += oiiotool (parent + "/oiio-images/grid.tif --fit 240x360 -d uint8 -o fit2.tif")
# regression test: --fit without needing resize used to be problematic
command += oiiotool ("src/tahoe-tiny.tif --fit 128x128 -d uint8 -o fit3.tif")
# test --pixelaspect
command += oiiotool ("src/tahoe-small.tif -resize 256x192 --pixelaspect 2.0 -d uint8 -o pixelaspect.tif")
# test rotate
command += oiiotool ("resize.tif --rotate 45 -o rotated.tif")
command += oiiotool ("resize.tif --rotate:center=50,50 45 -o rotated-offcenter.tif")
command += oiiotool ("resize.tif --rotate 45 --rotate 90 --rotate 90 --rotate 90 --rotate 45 -o rotated360.tif")
# test warp
command += oiiotool ("resize.tif --warp 0.7071068,0.7071068,0,-0.7071068,0.7071068,0,128,-53.01933,1 -o warped.tif")
# Test --add
command += oiiotool ("--pattern constant:color=.1,.2,.3 64x64+0+0 3 "
+ " --pattern constant:color=.1,.1,.1 64x64+20+20 3 "
+ " --add -d half -o add.exr")
# Test --addc val (add to all channels the same scalar)
command += oiiotool ("grey128.exr --addc 0.25 -o cadd1.exr")
# Test --addc val,val,val... (add per-channel scalars)
command += oiiotool ("grey128.exr --addc 0,0.25,-0.25 -o cadd2.exr")
# Test --sub, subc
command += oiiotool ("--pattern constant:color=.1,.2,.3 64x64+0+0 3 "
+ " --pattern constant:color=.1,.1,.1 64x64+20+20 3 "
+ " --sub -d half -o sub.exr")
command += oiiotool ("--pattern constant:color=.1,.2,.3 64x64+0+0 3 "
+ " --subc 0.1,0.1,0.1 -d half -o subc.exr")
# test --mul of images
command += oiiotool ("grey64.exr -pattern constant:color=1.5,1,0.5 64x64 3 --mul -o mul.exr")
# Test --mulc val (multiply all channels by the same scalar)
command += oiiotool ("grey128.exr --mulc 1.5 -o cmul1.exr")
# Test --mulc val,val,val... (multiply per-channel scalars)
command += oiiotool ("grey128.exr --mulc 1.5,1,0.5 -o cmul2.exr")
# Test --divc val (divide all channels by the same scalar)
command += oiiotool ("grey64.exr --divc 2.0 -d half -o divc1.exr")
# Test --divc val,val,val... (divide per-channel scalars)
command += oiiotool ("grey64.exr --divc 2.0,1,0.5 -d half -o divc2.exr")
# Test --div of images
command += oiiotool ("grey64.exr --pattern constant:color=2.0,1,0.5 64x64 3 "
+ "--div -d half -o div.exr")
# test --mad of images
command += oiiotool ("grey64.exr -pattern constant:color=1.5,1,0.5 64x64 3 "
+ "-pattern constant:color=.1,.1,.1 64x64 3 --mad -o mad.exr")
# test --invert
command += oiiotool ("src/tahoe-small.tif --invert -o invert.tif")
# Test --powc val (raise all channels by the same power)
command += oiiotool ("grey128.exr --powc 2 -o cpow1.exr")
# Test --powc val,val,val... (per-channel powers)
command += oiiotool ("grey128.exr --powc 2,2,1 -o cpow2.exr")
# Test --abs, --absdiff, --absdiffc
# First, make a test image that's 0.5 on the left, -0.5 on the right
command += oiiotool ("-pattern constant:color=-0.25,-0.25,-0.25 64x128 3 "
+ "-pattern constant:color=0.5,0.5,0.5 64x128 3 "
+ "-mosaic 2x1 -d half -o negpos.exr")
command += oiiotool ("negpos.exr -abs -o abs.exr")
command += oiiotool ("negpos.exr -pattern constant:color=0.2,0.2,0.2 128x128 3 "
+ "-absdiff -d half -o absdiff.exr")
command += oiiotool ("negpos.exr -absdiffc 0.2,0.2,0.2 -d half -o absdiffc.exr")
# test --chsum
command += oiiotool ("src/tahoe-small.tif --chsum:weight=.2126,.7152,.0722 "
+ "-d uint8 -o chsum.tif")
# test histogram generation
command += oiiotool ("ref/histogram_input.png --histogram 256x256 0 "
+ "-o histogram_regular.tif")
command += oiiotool ("ref/histogram_input.png --histogram:cumulative=1 256x256 0 "
+ "-o histogram_cumulative.tif")
# test --crop
command += oiiotool (parent + "/oiio-images/grid.tif --crop 100x400+50+200 -o crop.tif")
# test --cut
command += oiiotool (parent + "/oiio-images/grid.tif --cut 100x400+50+200 -o cut.tif")
# test paste
command += oiiotool (parent + "/oiio-images/grid.tif "
+ "--pattern checker 256x256 3 --paste +150+75 -o pasted.tif")
# test --trim
command += oiiotool ("--create 320x240 3 -fill:color=.1,.5,.1 120x80+50+70 "
+ " -rotate 30 -trim -origin +0+0 -fullpixels -d uint8 -o trim.tif")
# test --trim, tricky case of multiple subimages
command += oiiotool ( "-a --create 320x240 3 -fill:color=.1,.5,.1 120x80+50+70 -rotate 30 "
+ "--create 320x240 3 -fill:color=.5,.5,.1 100x10+70+70 -rotate 140 "
+ "--siappend -trim -origin +0+0 -fullpixels -d uint8 -o trimsubimages.tif")
# test mosaic
command += oiiotool ("--pattern constant:color=1,0,0 50x50 3 "
+ "--pattern constant:color=0,1,0 50x50 3 "
+ "--pattern constant:color=0,0,1 50x50 3 "
+ "--pattern constant:color=1,1,1 50x50 3 "
+ "--mosaic:pad=10 2x2 -d uint8 -o mosaic.tif")
# test flip
command += oiiotool ("src/image.tif --flip -o flip.tif")
command += oiiotool ("src/image.tif --crop 180x140+30+30 --flip -o flip-crop.tif")
# test flop
command += oiiotool ("src/image.tif --flop -o flop.tif")
command += oiiotool ("src/image.tif --crop 180x140+30+30 --flop -o flop-crop.tif")
# test rotate90
command += oiiotool ("src/image.tif --rotate90 -o rotate90.tif")
command += oiiotool ("src/image.tif --crop 180x140+30+30 --rotate90 -o rotate90-crop.tif")
# test rotate270
command += oiiotool ("src/image.tif --rotate270 -o rotate270.tif")
command += oiiotool ("src/image.tif --crop 180x140+30+30 --rotate270 -o rotate270-crop.tif")
# test rotate180
command += oiiotool ("src/image.tif --rotate180 -o flipflop.tif")
command += oiiotool ("src/image.tif --crop 160x120+30+30 --rotate180 -o flipflop-crop.tif")
# Tricky: make image, rotate, set Orientation, and then re-orient.
# Make it half size so it can't accidentally match to another test image
# for the rotation tests.
command += oiiotool ("src/image.tif --resample 160x120 --rotate90 --orientccw --reorient -o reorient1.tif")
command += oiiotool ("src/image.tif --resample 160x120 --rotate180 --orient180 --reorient -o reorient2.tif")
command += oiiotool ("src/image.tif --resample 160x120 --rotate270 --orientcw --reorient -o reorient3.tif")
# test transpose
command += oiiotool ("src/image.tif --transpose -o transpose.tif")
command += oiiotool ("src/image.tif --crop 160x120+30+30 --transpose -o transpose-crop.tif")
# test cshift
command += oiiotool ("src/image.tif --cshift +100+50 -o cshift.tif")
# test channel shuffling
command += oiiotool (parent + "/oiio-images/grid.tif"
+ " --ch =0.25,B,G -o chanshuffle.tif")
# test --ch to separate RGBA from an RGBAZ file
command += oiiotool ("src/rgbaz.exr --ch R,G,B,A -o ch-rgba.exr")
command += oiiotool ("src/rgbaz.exr --ch Z -o ch-z.exr")
# test --chappend to merge RGBA and Z
command += oiiotool ("ch-rgba.exr ch-z.exr --chappend -o chappend-rgbaz.exr")
# test --chnames to rename channels
command += oiiotool ("src/rgbaz.exr --chnames Red,,,,Depth -o chname.exr")
command += info_command ("chname.exr", safematch=1)
# test -d to change data formats
command += oiiotool ("src/rgbaz.exr -d half -o allhalf.exr")
command += info_command ("allhalf.exr", safematch=1)
# test -d NAME=fmt to change data format of one channel, and to make
# sure oiiotool will output per-channel formats.
command += oiiotool ("src/rgbaz.exr -d half -d Z=float -o rgbahalf-zfloat.exr")
command += info_command ("rgbahalf-zfloat.exr", safematch=1)
# test hole filling
command += oiiotool ("ref/hole.tif --fillholes -o tahoe-filled.tif")
# test clamping
command += oiiotool (parent + "/oiio-images/grid.tif --resize 50%"
+ " --clamp:min=0.2:max=,,0.5,1 -o grid-clamped.tif")
# test unpremult/premult
command += oiiotool ("--pattern constant:color=.1,.1,.1,1 100x100 4 "
+ " --fill:color=.2,.2,.2,.5 30x30+50+50 "
+ " -d half -o premulttarget.exr")
command += oiiotool ("premulttarget.exr --unpremult -o unpremult.exr")
command += oiiotool ("unpremult.exr --premult -o premult.exr")
# test kernel
command += oiiotool ("--kernel bspline 15x15 -o bsplinekernel.exr")
# test convolve
command += oiiotool ("src/tahoe-small.tif --kernel bspline 15x15 --convolve "
+ "-d uint8 -o bspline-blur.tif")
# test blur
command += oiiotool ("src/tahoe-small.tif --blur 5x5 -d uint8 -o gauss5x5-blur.tif")
# test median filter
command += oiiotool ("src/tahoe-small.tif --median 5x5 -d uint8 -o tahoe-median.tif")
# test unsharp mask
command += oiiotool ("src/tahoe-small.tif --unsharp -d uint8 -o unsharp.tif")
# test unsharp mask with median filter
command += oiiotool ("src/tahoe-small.tif --unsharp:kernel=median -d uint8 -o unsharp-median.tif")
# test laplacian
command += oiiotool ("src/tahoe-tiny.tif --laplacian -d uint8 -o tahoe-laplacian.tif")
# test fft, ifft
command += oiiotool ("src/tahoe-tiny.tif --ch 2 --fft -d float -o fft.exr")
command += oiiotool ("fft.exr --ifft --ch 0 -d float -o ifft.exr")
# test --polar, --unpolar
# note that fft.exr that we built above is in complex form
command += oiiotool ("fft.exr --polar -d float -o polar.exr")
command += oiiotool ("polar.exr --unpolar -d float -o unpolar.exr")
# test labels
command += oiiotool (
" --pattern constant:color=0.5,0.0,0.0 128x128 3 --label R " +
" --pattern constant:color=0.0,0.5,0.0 128x128 3 --label G " +
" --pattern constant:color=0.5,0.0,0.0 128x128 3 --label B " +
" --pop --pop --pop " +
" R G --add -d half -o labeladd.exr")
# test subimages
command += oiiotool ("--pattern constant:color=0.5,0.0,0.0 64x64 3 " +
"--pattern constant:color=0.0,0.5,0.0 64x64 3 " +
"--siappend -d half -o subimages-2.exr")
command += oiiotool ("--pattern constant:color=0.5,0.0,0.0 64x64 3 --text A -attrib oiio:subimagename layerA " +
"--pattern constant:color=0.0,0.5,0.0 64x64 3 --text B -attrib oiio:subimagename layerB " +
"--pattern constant:color=0.0,0.0,0.5 64x64 3 --text C -attrib oiio:subimagename layerC " +
"--pattern constant:color=0.5,0.5,0.0 64x64 3 --text D -attrib oiio:subimagename layerD " +
"--siappendall -d half -o subimages-4.exr")
command += oiiotool ("subimages-4.exr --subimage 3 -o subimageD3.exr")
command += oiiotool ("subimages-4.exr --subimage layerB -o subimageB1.exr")
command += oiiotool ("subimages-2.exr --sisplit -o subimage2.exr " +
"--pop -o subimage1.exr")
# test sequences
command += oiiotool ("fit.tif -o copyA.1-10#.jpg");
command += oiiotool (" --info " + " ".join(["copyA.{0:04}.jpg".format(x) for x in range(1,11)]))
# test expression substitution
command += oiiotool ("src/tahoe-small.tif --pattern fill:top=0,0,0,0:bottom=0,0,1,1 " +
"{TOP.geom} {TOP.nchannels} -d uint8 -o exprgradient.tif")
command += oiiotool ("src/tahoe-small.tif -cut '{TOP.width-20* 2}x{TOP.height-40+(4*2- 2 ) /6-1}+{TOP.x+100.5-80.5 }+{TOP.y+20}' -d uint8 -o exprcropped.tif")
command += oiiotool ("src/tahoe-small.tif -o exprstrcat{TOP.compression}.tif")
# test --no-autopremult on a TGA file thet needs it.
command += oiiotool ("--no-autopremult src/rgba.tga --ch R,G,B -o rgbfromtga.png")
# test --iconfig
command += oiiotool ("--info -v -metamatch Debug --iconfig oiio:DebugOpenConfig! 1 black.tif")
# To add more tests, just append more lines like the above and also add
# the new 'feature.tif' (or whatever you call it) to the outputs list,
# below.
# Outputs to check against references
outputs = [
"filled.tif",
"autotrim.tif",
"resample.tif", "resize.tif", "resize2.tif",
"resize64.tif", "resize512.tif",
"fit.tif", "fit2.tif", "fit3.tif",
"pixelaspect.tif",
"warped.tif",
"rotated.tif", "rotated-offcenter.tif", "rotated360.tif",
"histogram_regular.tif", "histogram_cumulative.tif",
"crop.tif", "cut.tif", "pasted.tif", "mosaic.tif",
"trim.tif", "trimsubimages.tif",
"flip.tif", "flip-crop.tif",
"flop.tif", "flop-crop.tif",
"flipflop.tif", "flipflop-crop.tif",
"rotate90.tif", "rotate90-crop.tif",
"rotate270.tif", "rotate270-crop.tif",
"reorient1.tif", "reorient2.tif", "reorient3.tif",
"transpose.tif", "transpose-crop.tif",
"cshift.tif",
"chanshuffle.tif", "ch-rgba.exr", "ch-z.exr",
"chappend-rgbaz.exr", "chname.exr",
"add.exr", "cadd1.exr", "cadd2.exr",
"sub.exr", "subc.exr",
"mul.exr", "cmul1.exr", "cmul2.exr",
"div.exr", "divc1.exr", "divc2.exr",
"mad.exr", "invert.tif",
"cpow1.exr", "cpow2.exr",
"abs.exr", "absdiff.exr", "absdiffc.exr",
"chsum.tif",
"rgbahalf-zfloat.exr",
"tahoe-filled.tif",
"rangecompress.tif", "rangeexpand.tif",
"rangecompress-luma.tif", "rangeexpand-luma.tif",
"grid-clamped.tif",
"unpremult.exr", "premult.exr",
"bsplinekernel.exr", "bspline-blur.tif",
"gauss5x5-blur.tif", "tahoe-median.tif",
"unsharp.tif", "unsharp-median.tif", "tahoe-laplacian.tif",
"fft.exr", "ifft.exr",
"polar.exr", "unpolar.exr",
"labeladd.exr",
"exprgradient.tif", "exprcropped.tif", "exprstrcatlzw.tif",
"rgbfromtga.png",
"out.txt" ]
#print "Running this command:\n" + command + "\n"
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
9948,
199,
3,
2790,
2005,
511,
5935,
781,
1929,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
306,
981,
25611,
88,
9873,
650,
446,
68,
3152,
24,
446,
79,
12136,
14,
9142,
531,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
306,
3401,
4413,
26,
2326,
29,
16,
14,
21,
12,
16,
14,
21,
12,
16,
14,
21,
7960,
88,
3933,
650,
446,
68,
12995,
446,
79,
30357,
3933,
14,
476,
82,
531,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
306,
3401,
4413,
26,
2326,
29,
16,
14,
21,
12,
16,
14,
21,
12,
16,
14,
21,
5049,
88,
772,
650,
446,
68,
12995,
446,
79,
30357,
772,
14,
476,
82,
531,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
306,
981,
7633,
88,
3912,
650,
1553,
4498,
26,
2326,
29,
17,
18485,
21,
18485,
21,
7633,
88,
3912,
1553,
4498,
26,
2326,
29,
16,
12,
17,
12,
16,
5939,
88,
1257,
11,
1960,
11,
1960,
446,
68,
3152,
24,
446,
79,
13457,
14,
9142,
531,
421,
199,
3,
511,
1553,
6898,
357,
31898,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
8399,
14,
9142,
1553,
4498,
26,
2326,
29,
16,
12,
17,
12,
16,
5939,
88,
1257,
11,
1960,
11,
1960,
1553,
6898,
357,
31898,
446,
68,
3152,
24,
446,
79,
6384,
357,
31898,
14,
9142,
531,
199,
199,
3,
511,
1553,
2326,
835,
221,
334,
4941,
314,
2058,
402,
314,
1553,
4498,
511,
9,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
17647,
14,
9142,
1553,
2326,
835,
26,
8277,
15856,
17,
18485,
17,
18485,
17,
378,
12,
16,
12,
16,
26,
17,
18485,
21,
18485,
21,
26,
16,
12,
17,
12,
16,
531,
199,
199,
3,
511,
1553,
1842,
1074,
221,
334,
4941,
314,
2058,
402,
314,
1553,
4498,
511,
9,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
17647,
14,
9142,
1553,
1842,
1074,
378,
12,
16,
12,
16,
413,
12,
16,
14,
25,
12,
17,
531,
199,
199,
3,
511,
1553,
1842,
6447,
1253,
1553,
1842,
4441,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
2164,
15,
502,
526,
69,
13,
7241,
14,
9142,
1553,
1842,
6447,
446,
68,
3152,
24,
446,
79,
1425,
6447,
14,
9142,
531,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
1842,
6447,
14,
9142,
1553,
1842,
4441,
446,
68,
3152,
24,
446,
79,
1425,
4441,
14,
9142,
531,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
2164,
15,
502,
526,
69,
13,
7241,
14,
9142,
1553,
1842,
6447,
26,
10836,
391,
29,
17,
446,
68,
3152,
24,
446,
79,
1425,
6447,
13,
10836,
391,
14,
9142,
531,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
1842,
6447,
13,
10836,
391,
14,
9142,
1553,
1842,
4441,
26,
10836,
391,
29,
17,
446,
68,
3152,
24,
446,
79,
1425,
4441,
13,
10836,
391,
14,
9142,
531,
199,
199,
3,
511,
31744,
199,
1531,
847,
312,
5908,
3459,
393,
334,
1708,
435,
3286,
16142,
2308,
13,
4782,
15,
3825,
14,
9142,
1553,
22882,
7960,
88,
3933,
446,
79,
31744,
14,
9142,
531,
199,
199,
3,
511,
15210,
199,
1531,
847,
312,
5908,
3459,
393,
334,
1708,
435,
3286,
16142,
2308,
13,
4782,
15,
3825,
14,
9142,
1553,
8709,
7633,
88,
3912,
446,
79,
15210,
14,
9142,
531,
199,
1531,
847,
312,
5908,
3459,
393,
334,
1708,
435,
3286,
16142,
2308,
13,
4782,
15,
3825,
14,
9142,
1553,
8709,
5661,
5,
446,
79,
15210,
18,
14,
9142,
531,
199,
199,
3,
511,
30503,
15210,
199,
1531,
847,
312,
5908,
3459,
393,
334,
1708,
435,
3286,
16142,
2308,
13,
4782,
15,
3825,
14,
9142,
1553,
8709,
5049,
88,
772,
446,
79,
15210,
772,
14,
9142,
531,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
8709,
772,
14,
9142,
1553,
8709,
10574,
88,
7736,
446,
79,
15210,
7736,
14,
9142,
531,
199,
199,
3,
511,
5542,
199,
1531,
847,
312,
5908,
3459,
393,
334,
1708,
435,
3286,
16142,
2308,
13,
4782,
15,
3825,
14,
9142,
1553,
3269,
19434,
88,
9873,
446,
68,
3152,
24,
446,
79,
5542,
14,
9142,
531,
199,
1531,
847,
312,
5908,
3459,
393,
334,
1708,
435,
3286,
16142,
2308,
13,
4782,
15,
3825,
14,
9142,
1553,
3269,
21883,
88,
11197,
446,
68,
3152,
24,
446,
79,
5542,
18,
14,
9142,
531,
199,
3,
10864,
511,
26,
1553,
3269,
1928,
1929,
316,
15210,
1202,
370,
506,
557,
31197,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
2164,
15,
502,
526,
69,
13,
9864,
14,
9142,
1553,
3269,
7960,
88,
3933,
446,
68,
3152,
24,
446,
79,
5542,
19,
14,
9142,
531,
199,
199,
3,
511,
1553,
8435,
18658,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
2164,
15,
502,
526,
69,
13,
7241,
14,
9142,
446,
8709,
7633,
88,
5756,
1553,
8435,
18658,
499,
14,
16,
446,
68,
3152,
24,
446,
79,
7148,
18658,
14,
9142,
531,
199,
199,
3,
511,
20071,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
8709,
14,
9142,
1553,
12873,
10416,
446,
79,
7513,
972,
14,
9142,
531,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
8709,
14,
9142,
1553,
12873,
26,
4218,
29,
1400,
12,
1400,
10416,
446,
79,
7513,
972,
13,
1997,
4218,
14,
9142,
531,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
8709,
14,
9142,
1553,
12873,
10416,
1553,
12873,
9137,
1553,
12873,
9137,
1553,
12873,
9137,
1553,
12873,
10416,
446,
79,
7513,
972,
11197,
14,
9142,
531,
199,
199,
3,
511,
29412,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
8709,
14,
9142,
1553,
26692,
378,
14,
15378,
709,
2333,
12,
16,
14,
15378,
709,
2333,
12,
16,
3057,
16,
14,
15378,
709,
2333,
12,
16,
14,
15378,
709,
2333,
12,
16,
12,
3933,
3057,
2481,
14,
12512,
1153,
12,
17,
446,
79,
3429,
1915,
14,
9142,
531,
199,
199,
3,
1379,
1553,
525,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
306,
3401,
4413,
26,
2326,
15856,
17,
18485,
18,
18485,
19,
5049,
88,
772,
11,
16,
11,
16,
650,
298,
288,
435,
298,
1553,
3401,
4413,
26,
2326,
15856,
17,
18485,
17,
18485,
17,
5049,
88,
772,
11,
1165,
11,
1165,
650,
298,
288,
435,
298,
1553,
525,
446,
68,
12995,
446,
79,
1050,
14,
476
] |
[
2647,
15,
1393,
15,
1813,
2366,
9948,
199,
3,
2790,
2005,
511,
5935,
781,
1929,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
306,
981,
25611,
88,
9873,
650,
446,
68,
3152,
24,
446,
79,
12136,
14,
9142,
531,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
306,
3401,
4413,
26,
2326,
29,
16,
14,
21,
12,
16,
14,
21,
12,
16,
14,
21,
7960,
88,
3933,
650,
446,
68,
12995,
446,
79,
30357,
3933,
14,
476,
82,
531,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
306,
3401,
4413,
26,
2326,
29,
16,
14,
21,
12,
16,
14,
21,
12,
16,
14,
21,
5049,
88,
772,
650,
446,
68,
12995,
446,
79,
30357,
772,
14,
476,
82,
531,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
306,
981,
7633,
88,
3912,
650,
1553,
4498,
26,
2326,
29,
17,
18485,
21,
18485,
21,
7633,
88,
3912,
1553,
4498,
26,
2326,
29,
16,
12,
17,
12,
16,
5939,
88,
1257,
11,
1960,
11,
1960,
446,
68,
3152,
24,
446,
79,
13457,
14,
9142,
531,
421,
199,
3,
511,
1553,
6898,
357,
31898,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
8399,
14,
9142,
1553,
4498,
26,
2326,
29,
16,
12,
17,
12,
16,
5939,
88,
1257,
11,
1960,
11,
1960,
1553,
6898,
357,
31898,
446,
68,
3152,
24,
446,
79,
6384,
357,
31898,
14,
9142,
531,
199,
199,
3,
511,
1553,
2326,
835,
221,
334,
4941,
314,
2058,
402,
314,
1553,
4498,
511,
9,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
17647,
14,
9142,
1553,
2326,
835,
26,
8277,
15856,
17,
18485,
17,
18485,
17,
378,
12,
16,
12,
16,
26,
17,
18485,
21,
18485,
21,
26,
16,
12,
17,
12,
16,
531,
199,
199,
3,
511,
1553,
1842,
1074,
221,
334,
4941,
314,
2058,
402,
314,
1553,
4498,
511,
9,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
17647,
14,
9142,
1553,
1842,
1074,
378,
12,
16,
12,
16,
413,
12,
16,
14,
25,
12,
17,
531,
199,
199,
3,
511,
1553,
1842,
6447,
1253,
1553,
1842,
4441,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
2164,
15,
502,
526,
69,
13,
7241,
14,
9142,
1553,
1842,
6447,
446,
68,
3152,
24,
446,
79,
1425,
6447,
14,
9142,
531,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
1842,
6447,
14,
9142,
1553,
1842,
4441,
446,
68,
3152,
24,
446,
79,
1425,
4441,
14,
9142,
531,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
2164,
15,
502,
526,
69,
13,
7241,
14,
9142,
1553,
1842,
6447,
26,
10836,
391,
29,
17,
446,
68,
3152,
24,
446,
79,
1425,
6447,
13,
10836,
391,
14,
9142,
531,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
1842,
6447,
13,
10836,
391,
14,
9142,
1553,
1842,
4441,
26,
10836,
391,
29,
17,
446,
68,
3152,
24,
446,
79,
1425,
4441,
13,
10836,
391,
14,
9142,
531,
199,
199,
3,
511,
31744,
199,
1531,
847,
312,
5908,
3459,
393,
334,
1708,
435,
3286,
16142,
2308,
13,
4782,
15,
3825,
14,
9142,
1553,
22882,
7960,
88,
3933,
446,
79,
31744,
14,
9142,
531,
199,
199,
3,
511,
15210,
199,
1531,
847,
312,
5908,
3459,
393,
334,
1708,
435,
3286,
16142,
2308,
13,
4782,
15,
3825,
14,
9142,
1553,
8709,
7633,
88,
3912,
446,
79,
15210,
14,
9142,
531,
199,
1531,
847,
312,
5908,
3459,
393,
334,
1708,
435,
3286,
16142,
2308,
13,
4782,
15,
3825,
14,
9142,
1553,
8709,
5661,
5,
446,
79,
15210,
18,
14,
9142,
531,
199,
199,
3,
511,
30503,
15210,
199,
1531,
847,
312,
5908,
3459,
393,
334,
1708,
435,
3286,
16142,
2308,
13,
4782,
15,
3825,
14,
9142,
1553,
8709,
5049,
88,
772,
446,
79,
15210,
772,
14,
9142,
531,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
8709,
772,
14,
9142,
1553,
8709,
10574,
88,
7736,
446,
79,
15210,
7736,
14,
9142,
531,
199,
199,
3,
511,
5542,
199,
1531,
847,
312,
5908,
3459,
393,
334,
1708,
435,
3286,
16142,
2308,
13,
4782,
15,
3825,
14,
9142,
1553,
3269,
19434,
88,
9873,
446,
68,
3152,
24,
446,
79,
5542,
14,
9142,
531,
199,
1531,
847,
312,
5908,
3459,
393,
334,
1708,
435,
3286,
16142,
2308,
13,
4782,
15,
3825,
14,
9142,
1553,
3269,
21883,
88,
11197,
446,
68,
3152,
24,
446,
79,
5542,
18,
14,
9142,
531,
199,
3,
10864,
511,
26,
1553,
3269,
1928,
1929,
316,
15210,
1202,
370,
506,
557,
31197,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
2164,
15,
502,
526,
69,
13,
9864,
14,
9142,
1553,
3269,
7960,
88,
3933,
446,
68,
3152,
24,
446,
79,
5542,
19,
14,
9142,
531,
199,
199,
3,
511,
1553,
8435,
18658,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
2164,
15,
502,
526,
69,
13,
7241,
14,
9142,
446,
8709,
7633,
88,
5756,
1553,
8435,
18658,
499,
14,
16,
446,
68,
3152,
24,
446,
79,
7148,
18658,
14,
9142,
531,
199,
199,
3,
511,
20071,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
8709,
14,
9142,
1553,
12873,
10416,
446,
79,
7513,
972,
14,
9142,
531,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
8709,
14,
9142,
1553,
12873,
26,
4218,
29,
1400,
12,
1400,
10416,
446,
79,
7513,
972,
13,
1997,
4218,
14,
9142,
531,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
8709,
14,
9142,
1553,
12873,
10416,
1553,
12873,
9137,
1553,
12873,
9137,
1553,
12873,
9137,
1553,
12873,
10416,
446,
79,
7513,
972,
11197,
14,
9142,
531,
199,
199,
3,
511,
29412,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
8709,
14,
9142,
1553,
26692,
378,
14,
15378,
709,
2333,
12,
16,
14,
15378,
709,
2333,
12,
16,
3057,
16,
14,
15378,
709,
2333,
12,
16,
14,
15378,
709,
2333,
12,
16,
12,
3933,
3057,
2481,
14,
12512,
1153,
12,
17,
446,
79,
3429,
1915,
14,
9142,
531,
199,
199,
3,
1379,
1553,
525,
199,
1531,
847,
312,
5908,
3459,
393,
1689,
306,
3401,
4413,
26,
2326,
15856,
17,
18485,
18,
18485,
19,
5049,
88,
772,
11,
16,
11,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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
] |
matthiasdiener/spack
|
var/spack/repos/builtin/packages/resourceproto/package.py
|
5
|
1755
|
##############################################################################
# Copyright (c) 2013-2018, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://github.com/spack/spack
# Please also see the NOTICE and LICENSE files for our notice and the LGPL.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License (as
# published by the Free Software Foundation) version 2.1, February 1999.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
# conditions of the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
from spack import *
class Resourceproto(AutotoolsPackage):
"""X Resource Extension.
This extension defines a protocol that allows a client to query the
X server about its usage of various resources."""
homepage = "http://cgit.freedesktop.org/xorg/proto/resourceproto"
url = "https://www.x.org/archive/individual/proto/resourceproto-1.2.0.tar.gz"
version('1.2.0', '33091d5358ec32dd7562a1aa225a70aa')
depends_on('pkgconfig', type='build')
depends_on('util-macros', type='build')
|
lgpl-2.1
|
[
4605,
199,
3,
1898,
334,
67,
9,
6171,
13,
12682,
12,
7964,
29590,
491,
4380,
6878,
20548,
13863,
12,
20376,
14,
199,
3,
2165,
16584,
737,
314,
7964,
29590,
491,
4380,
6878,
20548,
16871,
31671,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
428,
1389,
14,
199,
3,
18208,
701,
377,
16216,
598,
11020,
472,
12,
22387,
11020,
472,
32,
914,
7530,
14,
16294,
12,
2900,
4481,
4644,
14,
199,
3,
491,
44,
14176,
13,
6012,
13,
8557,
11501,
199,
3,
199,
3,
2104,
2436,
12,
1937,
4178,
921,
5031,
14,
957,
15,
83,
1389,
15,
83,
1389,
199,
3,
7754,
2597,
1937,
314,
12840,
436,
5113,
1584,
367,
4154,
4245,
436,
314,
32426,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
334,
305,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
9,
1015,
499,
14,
17,
12,
21141,
26709,
21300,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
5292,
3408,
1634,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
2895,
436,
199,
3,
3704,
402,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
8217,
199,
4605,
199,
504,
308,
1389,
492,
627,
421,
199,
533,
7337,
2625,
8,
23570,
3459,
1446,
8599,
304,
272,
408,
56,
7337,
13282,
14,
339,
961,
3329,
7890,
282,
4113,
626,
6127,
282,
1890,
370,
1827,
314,
272,
1323,
1654,
3595,
2399,
4503,
402,
7750,
5944,
1041,
339,
26586,
275,
298,
1014,
921,
67,
3187,
14,
4624,
14487,
14,
1308,
15,
88,
1308,
15,
2625,
15,
1927,
2625,
2,
272,
1166,
420,
275,
298,
2859,
921,
1544,
14,
88,
14,
1308,
15,
6404,
15,
23001,
15,
2625,
15,
1927,
2625,
13,
17,
14,
18,
14,
16,
14,
5369,
14,
6838,
2,
339,
1015,
360,
17,
14,
18,
14,
16,
297,
283,
1153,
21013,
68,
7920,
24,
825,
708,
617,
23,
18836,
65,
17,
2158,
10932,
65,
2760,
2158,
358,
339,
8350,
63,
265,
360,
4600,
888,
297,
730,
534,
1506,
358,
272,
8350,
63,
265,
360,
1974,
13,
16358,
297,
730,
534,
1506,
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
] |
[
199,
3,
1898,
334,
67,
9,
6171,
13,
12682,
12,
7964,
29590,
491,
4380,
6878,
20548,
13863,
12,
20376,
14,
199,
3,
2165,
16584,
737,
314,
7964,
29590,
491,
4380,
6878,
20548,
16871,
31671,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
428,
1389,
14,
199,
3,
18208,
701,
377,
16216,
598,
11020,
472,
12,
22387,
11020,
472,
32,
914,
7530,
14,
16294,
12,
2900,
4481,
4644,
14,
199,
3,
491,
44,
14176,
13,
6012,
13,
8557,
11501,
199,
3,
199,
3,
2104,
2436,
12,
1937,
4178,
921,
5031,
14,
957,
15,
83,
1389,
15,
83,
1389,
199,
3,
7754,
2597,
1937,
314,
12840,
436,
5113,
1584,
367,
4154,
4245,
436,
314,
32426,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
334,
305,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
9,
1015,
499,
14,
17,
12,
21141,
26709,
21300,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
5292,
3408,
1634,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
2895,
436,
199,
3,
3704,
402,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
8217,
199,
4605,
199,
504,
308,
1389,
492,
627,
421,
199,
533,
7337,
2625,
8,
23570,
3459,
1446,
8599,
304,
272,
408,
56,
7337,
13282,
14,
339,
961,
3329,
7890,
282,
4113,
626,
6127,
282,
1890,
370,
1827,
314,
272,
1323,
1654,
3595,
2399,
4503,
402,
7750,
5944,
1041,
339,
26586,
275,
298,
1014,
921,
67,
3187,
14,
4624,
14487,
14,
1308,
15,
88,
1308,
15,
2625,
15,
1927,
2625,
2,
272,
1166,
420,
275,
298,
2859,
921,
1544,
14,
88,
14,
1308,
15,
6404,
15,
23001,
15,
2625,
15,
1927,
2625,
13,
17,
14,
18,
14,
16,
14,
5369,
14,
6838,
2,
339,
1015,
360,
17,
14,
18,
14,
16,
297,
283,
1153,
21013,
68,
7920,
24,
825,
708,
617,
23,
18836,
65,
17,
2158,
10932,
65,
2760,
2158,
358,
339,
8350,
63,
265,
360,
4600,
888,
297,
730,
534,
1506,
358,
272,
8350,
63,
265,
360,
1974,
13,
16358,
297,
730,
534,
1506,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Nowheresly/odoo
|
addons/account/ir_sequence.py
|
336
|
2454
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import api
from openerp.osv import fields, osv
class ir_sequence_fiscalyear(osv.osv):
_name = 'account.sequence.fiscalyear'
_rec_name = "sequence_main_id"
_columns = {
"sequence_id": fields.many2one("ir.sequence", 'Sequence', required=True,
ondelete='cascade'),
"sequence_main_id": fields.many2one("ir.sequence", 'Main Sequence',
required=True, ondelete='cascade'),
"fiscalyear_id": fields.many2one('account.fiscalyear', 'Fiscal Year',
required=True, ondelete='cascade')
}
_sql_constraints = [
('main_id', 'CHECK (sequence_main_id != sequence_id)',
'Main Sequence must be different from current !'),
]
class ir_sequence(osv.osv):
_inherit = 'ir.sequence'
_columns = {
'fiscal_ids': fields.one2many('account.sequence.fiscalyear',
'sequence_main_id', 'Sequences', copy=True)
}
@api.cr_uid_ids_context
def _next(self, cr, uid, seq_ids, context=None):
if context is None:
context = {}
for seq in self.browse(cr, uid, seq_ids, context):
for line in seq.fiscal_ids:
if line.fiscalyear_id.id == context.get('fiscalyear_id'):
return super(ir_sequence, self)._next(cr, uid, [line.sequence_id.id], context)
return super(ir_sequence, self)._next(cr, uid, seq_ids, context)
# 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,
504,
5166,
492,
2986,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
199,
533,
8190,
63,
4041,
63,
21260,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
283,
2048,
14,
4041,
14,
21260,
7,
272,
485,
2761,
63,
354,
275,
298,
4041,
63,
973,
63,
344,
2,
272,
485,
3406,
275,
469,
267,
298,
4041,
63,
344,
582,
1504,
14,
3479,
18,
368,
480,
723,
14,
4041,
401,
283,
5826,
297,
1415,
29,
549,
12,
288,
16549,
534,
15377,
659,
267,
298,
4041,
63,
973,
63,
344,
582,
1504,
14,
3479,
18,
368,
480,
723,
14,
4041,
401,
283,
6756,
10975,
297,
288,
1415,
29,
549,
12,
16549,
534,
15377,
659,
267,
298,
21260,
63,
344,
582,
1504,
14,
3479,
18,
368,
360,
2048,
14,
21260,
297,
283,
38,
15734,
28497,
297,
288,
1415,
29,
549,
12,
16549,
534,
15377,
358,
272,
789,
339,
485,
3009,
63,
9882,
275,
359,
267,
661,
973,
63,
344,
297,
283,
8936,
334,
4041,
63,
973,
63,
344,
1137,
3414,
63,
344,
3196,
288,
283,
6756,
10975,
1471,
506,
3365,
687,
1453,
8546,
659,
272,
1622,
421,
199,
533,
8190,
63,
4041,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
723,
14,
4041,
7,
272,
485,
3406,
275,
469,
267,
283,
18646,
63,
1580,
356,
1504,
14,
368,
18,
3479,
360,
2048,
14,
4041,
14,
21260,
297,
288,
283,
4041,
63,
973,
63,
344,
297,
283,
1513,
6227,
297,
1331,
29,
549,
9,
272,
789,
339,
768,
1246,
14,
1556,
63,
1535,
63,
1580,
63,
1100,
272,
347,
485,
2184,
8,
277,
12,
2467,
12,
1747,
12,
5412,
63,
1580,
12,
1067,
29,
403,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
367,
5412,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
5412,
63,
1580,
12,
1067,
304,
288,
367,
1004,
315,
5412,
14,
18646,
63,
1580,
26,
355,
340,
1004,
14,
21260,
63,
344,
14,
344,
508,
1067,
14,
362,
360,
21260,
63,
344,
735,
490,
372,
1613,
8,
723,
63,
4041,
12,
291,
10445,
2184,
8,
1556,
12,
1747,
12,
359,
604,
14,
4041,
63,
344,
14,
344,
467,
1067,
9,
267,
372,
1613,
8,
723,
63,
4041,
12,
291,
10445,
2184,
8,
1556,
12,
1747,
12,
5412,
63,
1580,
12,
1067,
9,
421,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
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,
504,
5166,
492,
2986,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
199,
533,
8190,
63,
4041,
63,
21260,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
283,
2048,
14,
4041,
14,
21260,
7,
272,
485,
2761,
63,
354,
275,
298,
4041,
63,
973,
63,
344,
2,
272,
485,
3406,
275,
469,
267,
298,
4041,
63,
344,
582,
1504,
14,
3479,
18,
368,
480,
723,
14,
4041,
401,
283,
5826,
297,
1415,
29,
549,
12,
288,
16549,
534,
15377,
659,
267,
298,
4041,
63,
973,
63,
344,
582,
1504,
14,
3479,
18,
368,
480,
723,
14,
4041,
401,
283,
6756,
10975,
297,
288,
1415,
29,
549,
12,
16549,
534,
15377,
659,
267,
298,
21260,
63,
344,
582,
1504,
14,
3479,
18,
368,
360,
2048,
14,
21260,
297,
283,
38,
15734,
28497,
297,
288,
1415,
29,
549,
12,
16549,
534,
15377,
358,
272,
789,
339,
485,
3009,
63,
9882,
275,
359,
267,
661,
973,
63,
344,
297,
283,
8936,
334,
4041,
63,
973,
63,
344,
1137,
3414,
63,
344,
3196,
288,
283,
6756,
10975,
1471,
506,
3365,
687,
1453,
8546,
659,
272,
1622,
421,
199,
533,
8190,
63,
4041,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
723,
14,
4041,
7,
272,
485,
3406,
275,
469,
267,
283,
18646,
63,
1580,
356,
1504,
14,
368,
18,
3479,
360,
2048,
14,
4041,
14,
21260,
297,
288,
283,
4041,
63,
973,
63,
344,
297,
283,
1513,
6227,
297,
1331,
29,
549,
9,
272,
789,
339,
768,
1246,
14,
1556,
63,
1535,
63,
1580,
63,
1100,
272,
347,
485,
2184,
8,
277,
12,
2467,
12,
1747,
12,
5412,
63,
1580,
12,
1067,
29,
403,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
367,
5412,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
5412,
63,
1580,
12,
1067,
304,
288,
367,
1004,
315,
5412,
14,
18646,
63,
1580,
26,
355,
340,
1004,
14,
21260,
63,
344,
14,
344,
508,
1067,
14,
362,
360,
21260,
63,
344,
735,
490,
372,
1613,
8,
723,
63,
4041,
12,
291,
10445,
2184,
8,
1556,
12,
1747,
12,
359,
604,
14,
4041,
63,
344,
14,
344,
467,
1067,
9,
267,
372,
1613,
8,
723,
63,
4041,
12,
291,
10445,
2184,
8,
1556,
12,
1747,
12,
5412,
63,
1580,
12,
1067,
9,
421,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sofianehaddad/ot-svn
|
python/test/t_Graph_mix.py
|
2
|
2474
|
#! /usr/bin/env python
from openturns import *
TESTPREAMBLE()
RandomGenerator.SetSeed(0)
try:
# Instanciate one distribution object
dim = 2
meanPoint = NumericalPoint(dim, 1.0)
meanPoint[0] = 12.0
meanPoint[1] = 5.0
sigma = NumericalPoint(dim, 1.0)
sigma[0] = 3.0
sigma[1] = 1.0
R = CorrelationMatrix(dim)
for i in range(1, dim):
R[i, i - 1] = 0.75
distribution = Normal(meanPoint, sigma, R)
# Test for sampling
size = 200
sample = distribution.getSample(size)
tmp = NumericalSample(2, NumericalPoint(2))
tmp[0, 0] = sample.getMin()[0]
tmp[0, 1] = meanPoint[1] - sigma[1] / sigma[0] * (meanPoint[0] - tmp[0, 0])
tmp[1, 0] = sample.getMax()[0]
tmp[1, 1] = meanPoint[1] - sigma[1] / sigma[0] * (meanPoint[0] - tmp[1, 0])
# Create the cloud
myCloud = Cloud(sample, "blue", "fsquare", "Normal Cloud")
# Create the line
myLine = Curve(tmp, "red", "solid", 2, "Line")
data = NumericalPoint(0)
palette = Description()
labels = Description()
data.add(5665855)
labels.add("Candidate1")
palette.add("blue")
data.add(4804713)
labels.add("Candidate2")
palette.add("white")
data.add(4610113)
labels.add("Candidate3")
palette.add("pink")
data.add(1949170)
labels.add("Candidate4")
palette.add("yellow")
data.add(1630045)
labels.add("Candidate5")
palette.add("red")
data.add(1518528)
labels.add("Candidate6")
palette.add("ivory")
data.add(1495724)
labels.add("Candidate7")
palette.add("green")
data.add(1210562)
labels.add("Candidate8")
palette.add("orange")
data.add(1204689)
labels.add("Candidate9")
palette.add("maroon")
data.add(1113484)
labels.add("Candidate10")
palette.add("violet")
data.add(3295588)
labels.add("cumul candidates < 3.5% ")
palette.add("purple")
centre = NumericalPoint(2)
centre[0] = 7.0
centre[1] = 10.0
# Create the piechart
myPie = Pie(data, labels, centre, 4, palette)
# Create an empty graph
myGraph = Graph("Cloud/line/pie", "x1", "x2", True, "topright", 1.0)
# Then, draw it
myGraph.add(myCloud)
myGraph.add(myLine)
myGraph.add(myPie)
myGraph.draw("Graph_mix_OT", 640, 480)
# Check that the correct files have been generated by computing their
# checksum
except:
import sys
print "t_Graph_mix.py", sys.exc_type, sys.exc_value
|
mit
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
1551,
353,
83,
492,
627,
199,
199,
2864,
4225,
1156,
34,
906,
342,
199,
3883,
7599,
14,
1084,
19554,
8,
16,
9,
199,
199,
893,
26,
272,
327,
1010,
9746,
559,
323,
1373,
4084,
909,
272,
8134,
275,
499,
272,
4615,
3428,
275,
653,
27685,
3428,
8,
3572,
12,
413,
14,
16,
9,
272,
4615,
3428,
59,
16,
61,
275,
3144,
14,
16,
272,
4615,
3428,
59,
17,
61,
275,
959,
14,
16,
272,
10819,
275,
653,
27685,
3428,
8,
3572,
12,
413,
14,
16,
9,
272,
10819,
59,
16,
61,
275,
650,
14,
16,
272,
10819,
59,
17,
61,
275,
413,
14,
16,
272,
820,
275,
7499,
5690,
6443,
8,
3572,
9,
272,
367,
284,
315,
1425,
8,
17,
12,
8134,
304,
267,
820,
59,
73,
12,
284,
446,
413,
61,
275,
378,
14,
2194,
339,
4084,
275,
11514,
8,
3670,
3428,
12,
10819,
12,
820,
9,
339,
327,
1379,
367,
15877,
272,
1568,
275,
1926,
272,
2690,
275,
4084,
14,
362,
8176,
8,
890,
9,
272,
3529,
275,
653,
27685,
8176,
8,
18,
12,
653,
27685,
3428,
8,
18,
430,
272,
3529,
59,
16,
12,
378,
61,
275,
2690,
14,
362,
4649,
3430,
16,
61,
272,
3529,
59,
16,
12,
413,
61,
275,
4615,
3428,
59,
17,
61,
446,
10819,
59,
17,
61,
1182,
10819,
59,
16,
61,
627,
334,
3670,
3428,
59,
16,
61,
446,
3529,
59,
16,
12,
378,
566,
272,
3529,
59,
17,
12,
378,
61,
275,
2690,
14,
362,
4261,
3430,
16,
61,
272,
3529,
59,
17,
12,
413,
61,
275,
4615,
3428,
59,
17,
61,
446,
10819,
59,
17,
61,
1182,
10819,
59,
16,
61,
627,
334,
3670,
3428,
59,
16,
61,
446,
3529,
59,
17,
12,
378,
566,
339,
327,
2790,
314,
8002,
272,
3002,
9089,
275,
8142,
8,
3271,
12,
298,
6304,
401,
298,
2319,
5937,
401,
298,
6241,
8142,
531,
339,
327,
2790,
314,
1004,
272,
3002,
3049,
275,
7319,
432,
8,
2791,
12,
298,
581,
401,
298,
18533,
401,
499,
12,
298,
3049,
531,
339,
666,
275,
653,
27685,
3428,
8,
16,
9,
339,
17986,
275,
11994,
342,
272,
3628,
275,
11994,
342,
339,
666,
14,
525,
8,
29982,
2010,
1229,
9,
272,
3628,
14,
525,
480,
26925,
17,
531,
272,
17986,
14,
525,
480,
6304,
531,
339,
666,
14,
525,
8,
2006,
12931,
969,
9,
272,
3628,
14,
525,
480,
26925,
18,
531,
272,
17986,
14,
525,
480,
7510,
531,
339,
666,
14,
525,
8,
2466,
4893,
969,
9,
272,
3628,
14,
525,
480,
26925,
19,
531,
272,
17986,
14,
525,
480,
26591,
531,
339,
666,
14,
525,
8,
1167,
1887,
11010,
9,
272,
3628,
14,
525,
480,
26925,
20,
531,
272,
17986,
14,
525,
480,
14514,
531,
339,
666,
14,
525,
8,
975,
5863,
2322,
9,
272,
3628,
14,
525,
480,
26925,
21,
531,
272,
17986,
14,
525,
480,
581,
531,
339,
666,
14,
525,
8,
1046,
10233,
1651,
9,
272,
3628,
14,
525,
480,
26925,
22,
531,
272,
17986,
14,
525,
480,
1003,
1089,
531,
339,
666,
14,
525,
8,
10721,
1641,
1194,
9,
272,
3628,
14,
525,
480,
26925,
23,
531,
272,
17986,
14,
525,
480,
7731,
531,
339,
666,
14,
525,
8,
713,
709,
18836,
9,
272,
3628,
14,
525,
480,
26925,
24,
531,
272,
17986,
14,
525,
480,
22683,
531,
339,
666,
14,
525,
8,
713,
13702,
1407,
9,
272,
3628,
14,
525,
480,
26925,
25,
531,
272,
17986,
14,
525,
480,
4584,
79,
265,
531,
339,
666,
14,
525,
8,
845,
7582,
1349,
9,
272,
3628,
14,
525,
480,
26925,
709,
531,
272,
17986,
14,
525,
480,
32052,
2723,
531,
339,
666,
14,
525,
8,
11685,
1229,
1299,
9,
272,
3628,
14,
525,
480,
11898,
348,
15101,
665,
650,
14,
21,
5,
6099,
272,
17986,
14,
525,
480,
6653,
11045,
531,
339,
13345,
264,
275,
653,
27685,
3428,
8,
18,
9,
272,
13345,
264,
59,
16,
61,
275,
1520,
14,
16,
272,
13345,
264,
59,
17,
61,
275,
1616,
14,
16,
339,
327,
2790,
314,
7708,
9019,
272,
3002,
48,
1873,
275,
510,
1873,
8,
576,
12,
3628,
12,
13345,
264,
12,
841,
12,
17986,
9,
339,
327,
2790,
376,
2701,
3343,
272,
3002,
4578,
275,
11513,
480,
9089,
15,
604,
15,
9890,
401,
298,
88,
17,
401,
298,
88,
18,
401,
715,
12,
298,
2119,
1019,
401,
413,
14,
16,
9,
339,
327,
9442,
12,
5954,
652,
272,
3002,
4578,
14,
525,
8,
1662,
9089,
9,
272,
3002,
4578,
14,
525,
8,
1662,
3049,
9,
272,
3002,
4578,
14,
525,
8,
1662,
48,
1873,
9,
272,
3002,
4578,
14,
5485,
480,
4578,
63,
13979,
63,
1387,
401,
5049,
16,
12,
29504,
9,
8410,
327,
2670,
626,
314,
3211,
1584,
1172,
2757,
4046,
701,
17226,
3932,
2043,
327,
9040,
199,
199,
2590,
26,
272,
492,
984,
272,
870,
298,
84,
63,
4578,
63,
13979,
14,
647,
401,
984,
14,
2804,
63,
466,
12,
984,
14,
2804,
63,
585,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
1551,
353,
83,
492,
627,
199,
199,
2864,
4225,
1156,
34,
906,
342,
199,
3883,
7599,
14,
1084,
19554,
8,
16,
9,
199,
199,
893,
26,
272,
327,
1010,
9746,
559,
323,
1373,
4084,
909,
272,
8134,
275,
499,
272,
4615,
3428,
275,
653,
27685,
3428,
8,
3572,
12,
413,
14,
16,
9,
272,
4615,
3428,
59,
16,
61,
275,
3144,
14,
16,
272,
4615,
3428,
59,
17,
61,
275,
959,
14,
16,
272,
10819,
275,
653,
27685,
3428,
8,
3572,
12,
413,
14,
16,
9,
272,
10819,
59,
16,
61,
275,
650,
14,
16,
272,
10819,
59,
17,
61,
275,
413,
14,
16,
272,
820,
275,
7499,
5690,
6443,
8,
3572,
9,
272,
367,
284,
315,
1425,
8,
17,
12,
8134,
304,
267,
820,
59,
73,
12,
284,
446,
413,
61,
275,
378,
14,
2194,
339,
4084,
275,
11514,
8,
3670,
3428,
12,
10819,
12,
820,
9,
339,
327,
1379,
367,
15877,
272,
1568,
275,
1926,
272,
2690,
275,
4084,
14,
362,
8176,
8,
890,
9,
272,
3529,
275,
653,
27685,
8176,
8,
18,
12,
653,
27685,
3428,
8,
18,
430,
272,
3529,
59,
16,
12,
378,
61,
275,
2690,
14,
362,
4649,
3430,
16,
61,
272,
3529,
59,
16,
12,
413,
61,
275,
4615,
3428,
59,
17,
61,
446,
10819,
59,
17,
61,
1182,
10819,
59,
16,
61,
627,
334,
3670,
3428,
59,
16,
61,
446,
3529,
59,
16,
12,
378,
566,
272,
3529,
59,
17,
12,
378,
61,
275,
2690,
14,
362,
4261,
3430,
16,
61,
272,
3529,
59,
17,
12,
413,
61,
275,
4615,
3428,
59,
17,
61,
446,
10819,
59,
17,
61,
1182,
10819,
59,
16,
61,
627,
334,
3670,
3428,
59,
16,
61,
446,
3529,
59,
17,
12,
378,
566,
339,
327,
2790,
314,
8002,
272,
3002,
9089,
275,
8142,
8,
3271,
12,
298,
6304,
401,
298,
2319,
5937,
401,
298,
6241,
8142,
531,
339,
327,
2790,
314,
1004,
272,
3002,
3049,
275,
7319,
432,
8,
2791,
12,
298,
581,
401,
298,
18533,
401,
499,
12,
298,
3049,
531,
339,
666,
275,
653,
27685,
3428,
8,
16,
9,
339,
17986,
275,
11994,
342,
272,
3628,
275,
11994,
342,
339,
666,
14,
525,
8,
29982,
2010,
1229,
9,
272,
3628,
14,
525,
480,
26925,
17,
531,
272,
17986,
14,
525,
480,
6304,
531,
339,
666,
14,
525,
8,
2006,
12931,
969,
9,
272,
3628,
14,
525,
480,
26925,
18,
531,
272,
17986,
14,
525,
480,
7510,
531,
339,
666,
14,
525,
8,
2466,
4893,
969,
9,
272,
3628,
14,
525,
480,
26925,
19,
531,
272,
17986,
14,
525,
480,
26591,
531,
339,
666,
14,
525,
8,
1167,
1887,
11010,
9,
272,
3628,
14,
525,
480,
26925,
20,
531,
272,
17986,
14,
525,
480,
14514,
531,
339,
666,
14,
525,
8,
975,
5863,
2322,
9,
272,
3628,
14,
525,
480,
26925,
21,
531,
272,
17986,
14,
525,
480,
581,
531,
339,
666,
14,
525,
8,
1046,
10233,
1651,
9,
272,
3628,
14,
525,
480,
26925,
22,
531,
272,
17986,
14,
525,
480,
1003,
1089,
531,
339,
666,
14,
525,
8,
10721,
1641,
1194,
9,
272,
3628,
14,
525,
480,
26925,
23,
531,
272,
17986,
14,
525,
480,
7731,
531,
339,
666,
14,
525,
8,
713,
709,
18836,
9,
272,
3628,
14,
525,
480,
26925,
24,
531,
272,
17986,
14,
525,
480,
22683,
531,
339,
666,
14,
525,
8,
713,
13702,
1407,
9,
272,
3628,
14,
525,
480,
26925,
25,
531,
272,
17986,
14,
525,
480,
4584,
79,
265,
531,
339,
666,
14,
525,
8,
845,
7582,
1349,
9,
272,
3628,
14,
525,
480,
26925,
709,
531,
272,
17986,
14,
525,
480,
32052,
2723,
531,
339,
666,
14,
525,
8,
11685,
1229,
1299,
9,
272,
3628,
14,
525,
480,
11898,
348,
15101,
665,
650,
14,
21,
5,
6099,
272,
17986,
14,
525,
480,
6653,
11045,
531,
339,
13345,
264,
275,
653,
27685,
3428,
8,
18,
9,
272,
13345,
264,
59,
16,
61,
275,
1520,
14,
16,
272,
13345,
264,
59,
17,
61,
275,
1616,
14,
16,
339,
327,
2790,
314,
7708,
9019,
272,
3002,
48,
1873,
275,
510,
1873,
8,
576,
12,
3628,
12,
13345,
264,
12,
841,
12,
17986,
9,
339,
327,
2790,
376,
2701,
3343,
272,
3002,
4578,
275,
11513,
480,
9089,
15,
604,
15,
9890,
401,
298,
88,
17,
401,
298,
88,
18,
401,
715,
12,
298,
2119,
1019,
401,
413,
14,
16,
9,
339,
327,
9442,
12,
5954,
652,
272,
3002,
4578,
14,
525,
8,
1662,
9089,
9,
272,
3002,
4578,
14,
525,
8,
1662,
3049,
9,
272,
3002,
4578,
14,
525,
8,
1662,
48,
1873,
9,
272,
3002,
4578,
14,
5485,
480,
4578,
63,
13979,
63,
1387,
401,
5049,
16,
12,
29504,
9,
8410,
327,
2670,
626,
314,
3211,
1584,
1172,
2757,
4046,
701,
17226,
3932,
2043,
327,
9040,
199,
199,
2590,
26,
272,
492,
984,
272,
870,
298,
84,
63,
4578,
63,
13979,
14,
647,
401,
984,
14,
2804,
63,
466,
12,
984,
14,
2804,
63,
585,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
broesamle/servo
|
components/script/dom/bindings/codegen/parser/tests/test_duplicate_qualifiers.py
|
241
|
1893
|
def WebIDLTest(parser, harness):
threw = False
try:
parser.parse("""
interface DuplicateQualifiers1 {
getter getter byte foo(unsigned long index);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface DuplicateQualifiers2 {
setter setter byte foo(unsigned long index, byte value);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface DuplicateQualifiers3 {
creator creator byte foo(unsigned long index, byte value);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface DuplicateQualifiers4 {
deleter deleter byte foo(unsigned long index);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface DuplicateQualifiers5 {
getter deleter getter byte foo(unsigned long index);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
results = parser.parse("""
interface DuplicateQualifiers6 {
creator setter creator byte foo(unsigned long index, byte value);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
|
mpl-2.0
|
[
318,
22817,
774,
8,
2087,
12,
20458,
304,
272,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
23942,
12621,
26765,
17,
469,
1598,
15917,
15917,
3696,
3925,
8,
2244,
1846,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
23942,
12621,
26765,
18,
469,
1598,
18743,
18743,
3696,
3925,
8,
2244,
1846,
1478,
12,
3696,
574,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
23942,
12621,
26765,
19,
469,
1598,
14875,
14875,
3696,
3925,
8,
2244,
1846,
1478,
12,
3696,
574,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
23942,
12621,
26765,
20,
469,
1598,
6070,
351,
6070,
351,
3696,
3925,
8,
2244,
1846,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
23942,
12621,
26765,
21,
469,
1598,
15917,
6070,
351,
15917,
3696,
3925,
8,
2244,
1846,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
2058,
275,
1798,
14,
1122,
4852,
288,
3217,
23942,
12621,
26765,
22,
469,
1598,
14875,
18743,
14875,
3696,
3925,
8,
2244,
1846,
1478,
12,
3696,
574,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
22817,
774,
8,
2087,
12,
20458,
304,
272,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
23942,
12621,
26765,
17,
469,
1598,
15917,
15917,
3696,
3925,
8,
2244,
1846,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
23942,
12621,
26765,
18,
469,
1598,
18743,
18743,
3696,
3925,
8,
2244,
1846,
1478,
12,
3696,
574,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
23942,
12621,
26765,
19,
469,
1598,
14875,
14875,
3696,
3925,
8,
2244,
1846,
1478,
12,
3696,
574,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
23942,
12621,
26765,
20,
469,
1598,
6070,
351,
6070,
351,
3696,
3925,
8,
2244,
1846,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
23942,
12621,
26765,
21,
469,
1598,
15917,
6070,
351,
15917,
3696,
3925,
8,
2244,
1846,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
2058,
275,
1798,
14,
1122,
4852,
288,
3217,
23942,
12621,
26765,
22,
469,
1598,
14875,
18743,
14875,
3696,
3925,
8,
2244,
1846,
1478,
12,
3696,
574,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mikewiebe-ansible/ansible
|
lib/ansible/modules/network/aci/mso_schema_site_vrf_region.py
|
13
|
6407
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: (c) 2019, Dag Wieers (@dagwieers) <dag@wieers.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: mso_schema_site_vrf_region
short_description: Manage site-local VRF regions in schema template
description:
- Manage site-local VRF regions in schema template on Cisco ACI Multi-Site.
author:
- Dag Wieers (@dagwieers)
version_added: '2.8'
options:
schema:
description:
- The name of the schema.
type: str
required: yes
site:
description:
- The name of the site.
type: str
required: yes
template:
description:
- The name of the template.
type: str
required: yes
vrf:
description:
- The name of the VRF.
type: str
region:
description:
- The name of the region to manage.
type: str
aliases: [ name ]
state:
description:
- Use C(present) or C(absent) for adding or removing.
- Use C(query) for listing an object or multiple objects.
type: str
choices: [ absent, present, query ]
default: present
seealso:
- module: mso_schema_site_vrf
- module: mso_schema_template_vrf
extends_documentation_fragment: mso
'''
EXAMPLES = r'''
- name: Add a new site VRF region
mso_schema_template_vrf_region:
host: mso_host
username: admin
password: SomeSecretPassword
schema: Schema1
site: Site1
template: Template1
vrf: VRF1
region: us-west-1
state: present
delegate_to: localhost
- name: Remove a site VRF region
mso_schema_template_vrf_region:
host: mso_host
username: admin
password: SomeSecretPassword
schema: Schema1
site: Site1
template: Template1
vrf: VRF1
region: us-west-1
state: absent
delegate_to: localhost
- name: Query a specific site VRF region
mso_schema_template_vrf_region:
host: mso_host
username: admin
password: SomeSecretPassword
schema: Schema1
site: Site1
template: Template1
vrf: VRF1
region: us-west-1
state: query
delegate_to: localhost
register: query_result
- name: Query all site VRF regions
mso_schema_template_vrf_region:
host: mso_host
username: admin
password: SomeSecretPassword
schema: Schema1
site: Site1
template: Template1
vrf: VRF1
state: query
delegate_to: localhost
register: query_result
'''
RETURN = r'''
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec
def main():
argument_spec = mso_argument_spec()
argument_spec.update(
schema=dict(type='str', required=True),
site=dict(type='str', required=True),
template=dict(type='str', required=True),
vrf=dict(type='str', required=True),
region=dict(type='str', aliases=['name']), # This parameter is not required for querying all objects
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[
['state', 'absent', ['region']],
['state', 'present', ['region']],
],
)
schema = module.params.get('schema')
site = module.params.get('site')
template = module.params.get('template')
vrf = module.params.get('vrf')
region = module.params.get('region')
state = module.params.get('state')
mso = MSOModule(module)
# Get schema_id
schema_obj = mso.get_obj('schemas', displayName=schema)
if not schema_obj:
mso.fail_json(msg="Provided schema '{0}' does not exist".format(schema))
schema_path = 'schemas/{id}'.format(**schema_obj)
schema_id = schema_obj.get('id')
# Get site
site_id = mso.lookup_site(site)
# Get site_idx
sites = [(s.get('siteId'), s.get('templateName')) for s in schema_obj.get('sites')]
if (site_id, template) not in sites:
mso.fail_json(msg="Provided site/template '{0}-{1}' does not exist. Existing sites/templates: {2}".format(site, template, ', '.join(sites)))
# Schema-access uses indexes
site_idx = sites.index((site_id, template))
# Path-based access uses site_id-template
site_template = '{0}-{1}'.format(site_id, template)
# Get VRF
vrf_ref = mso.vrf_ref(schema_id=schema_id, template=template, vrf=vrf)
vrfs = [v.get('vrfRef') for v in schema_obj.get('sites')[site_idx]['vrfs']]
if vrf_ref not in vrfs:
mso.fail_json(msg="Provided vrf '{0}' does not exist. Existing vrfs: {1}".format(vrf, ', '.join(vrfs)))
vrf_idx = vrfs.index(vrf_ref)
# Get Region
regions = [r.get('name') for r in schema_obj.get('sites')[site_idx]['vrfs'][vrf_idx]['regions']]
if region is not None and region in regions:
region_idx = regions.index(region)
region_path = '/sites/{0}/vrfs/{1}/regions/{2}'.format(site_template, vrf, region)
mso.existing = schema_obj.get('sites')[site_idx]['vrfs'][vrf_idx]['regions'][region_idx]
if state == 'query':
if region is None:
mso.existing = schema_obj.get('sites')[site_idx]['vrfs'][vrf_idx]['regions']
elif not mso.existing:
mso.fail_json(msg="Region '{region}' not found".format(region=region))
mso.exit_json()
regions_path = '/sites/{0}/vrfs/{1}/regions'.format(site_template, vrf)
ops = []
mso.previous = mso.existing
if state == 'absent':
if mso.existing:
mso.sent = mso.existing = {}
ops.append(dict(op='remove', path=region_path))
elif state == 'present':
payload = dict(
name=region,
)
mso.sanitize(payload, collate=True)
if mso.existing:
ops.append(dict(op='replace', path=region_path, value=mso.sent))
else:
ops.append(dict(op='add', path=regions_path + '/-', value=mso.sent))
mso.existing = mso.proposed
if not module.check_mode:
mso.request(schema_path, method='PATCH', data=ops)
mso.exit_json()
if __name__ == "__main__":
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
26,
334,
67,
9,
20312,
12,
26110,
644,
1873,
1192,
8593,
7406,
87,
1873,
1192,
9,
665,
7406,
32,
87,
1873,
1192,
14,
957,
30,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
519,
2344,
199,
2595,
199,
578,
26,
333,
1152,
63,
3629,
63,
2124,
63,
11863,
63,
4551,
199,
3612,
63,
1802,
26,
14944,
4770,
13,
1832,
812,
11778,
16150,
315,
4177,
1978,
199,
1802,
26,
199,
13,
14944,
4770,
13,
1832,
812,
11778,
16150,
315,
4177,
1978,
641,
28356,
437,
3553,
6879,
13,
8972,
14,
199,
2502,
26,
199,
13,
26110,
644,
1873,
1192,
8593,
7406,
87,
1873,
1192,
9,
199,
1023,
63,
3270,
26,
283,
18,
14,
24,
7,
199,
1419,
26,
523,
4177,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
4177,
14,
272,
730,
26,
620,
272,
1415,
26,
9456,
523,
4770,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
4770,
14,
272,
730,
26,
620,
272,
1415,
26,
9456,
523,
1978,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
1978,
14,
272,
730,
26,
620,
272,
1415,
26,
9456,
523,
15209,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
812,
11778,
14,
272,
730,
26,
620,
523,
4897,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
4897,
370,
9635,
14,
272,
730,
26,
620,
272,
5481,
26,
359,
536,
1622,
523,
1174,
26,
272,
1369,
26,
272,
446,
3645,
445,
8,
1881,
9,
503,
445,
8,
5575,
9,
367,
7791,
503,
12881,
14,
272,
446,
3645,
445,
8,
1131,
9,
367,
13778,
376,
909,
503,
3663,
2251,
14,
272,
730,
26,
620,
272,
3415,
26,
359,
9552,
12,
3451,
12,
1827,
1622,
272,
849,
26,
3451,
199,
3239,
12344,
26,
199,
13,
859,
26,
333,
1152,
63,
3629,
63,
2124,
63,
11863,
199,
13,
859,
26,
333,
1152,
63,
3629,
63,
1160,
63,
11863,
199,
11036,
63,
9970,
63,
7677,
26,
333,
1152,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
2654,
282,
892,
4770,
812,
11778,
4897,
523,
333,
1152,
63,
3629,
63,
1160,
63,
11863,
63,
4551,
26,
272,
1591,
26,
333,
1152,
63,
1102,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
4177,
26,
13268,
17,
272,
4770,
26,
11666,
17,
272,
1978,
26,
5458,
17,
272,
15209,
26,
812,
11778,
17,
272,
4897,
26,
2739,
13,
19082,
13,
17,
272,
1174,
26,
3451,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
5852,
282,
4770,
812,
11778,
4897,
523,
333,
1152,
63,
3629,
63,
1160,
63,
11863,
63,
4551,
26,
272,
1591,
26,
333,
1152,
63,
1102,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
4177,
26,
13268,
17,
272,
4770,
26,
11666,
17,
272,
1978,
26,
5458,
17,
272,
15209,
26,
812,
11778,
17,
272,
4897,
26,
2739,
13,
19082,
13,
17,
272,
1174,
26,
9552,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
8133,
282,
2488,
4770,
812,
11778,
4897,
523,
333,
1152,
63,
3629,
63,
1160,
63,
11863,
63,
4551,
26,
272,
1591,
26,
333,
1152,
63,
1102,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
4177,
26,
13268,
17,
272,
4770,
26,
11666,
17,
272,
1978,
26,
5458,
17,
272,
15209,
26,
812,
11778,
17,
272,
4897,
26,
2739,
13,
19082,
13,
17,
272,
1174,
26,
1827,
523,
13080,
63,
475,
26,
11667,
523,
2274,
26,
1827,
63,
1099,
199,
199,
13,
536,
26,
8133,
1006,
4770,
812,
11778,
16150,
523,
333,
1152,
63,
3629,
63,
1160,
63,
11863,
63,
4551,
26,
272,
1591,
26,
333,
1152,
63,
1102,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
4177,
26,
13268,
17,
272,
4770,
26,
11666,
17,
272,
1978,
26,
5458,
17,
272,
15209,
26,
812,
11778,
17,
272,
1174,
26,
1827,
523,
13080,
63,
475,
26,
11667,
523,
2274,
26,
1827,
63,
1099,
199,
2344,
199,
199,
9677,
275,
519,
2344,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
22832,
14,
706,
79,
492,
603,
4118,
2377,
12,
333,
1152,
63,
2094,
63,
1650,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
333,
1152,
63,
2094,
63,
1650,
342,
272,
1423,
63,
1650,
14,
873,
8,
267,
4177,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
549,
395,
267,
4770,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
549,
395,
267,
1978,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
549,
395,
267,
15209,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
549,
395,
267,
4897,
29,
807,
8,
466,
534,
495,
297,
5481,
2968,
354,
3815,
221,
327,
961,
2725,
365,
440,
1415,
367,
27405,
1006,
2251,
267,
1174,
29,
807,
8,
466,
534,
495,
297,
849,
534,
1881,
297,
3415,
2968,
5575,
297,
283,
1881,
297,
283,
1131,
3815,
272,
776,
339,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
2094,
63,
1650,
12,
267,
5171,
63,
1074,
63,
632,
29,
549,
12,
267,
1415,
63,
692,
1524,
288,
788,
929,
297,
283,
5575,
297,
788,
4551,
2157,
288,
788,
929,
297,
283,
1881,
297,
788,
4551,
2157,
267,
2156,
272,
776,
339,
4177,
275,
859,
14,
1162,
14,
362,
360,
3629,
358,
272,
4770,
275,
859,
14,
1162,
14,
362,
360,
2124,
358,
272,
1978,
275,
859,
14,
1162,
14,
362,
360,
1160,
358,
272,
15209,
275,
859,
14,
1162,
14,
362,
360,
11863,
358,
272,
4897,
275,
859,
14
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
26,
334,
67,
9,
20312,
12,
26110,
644,
1873,
1192,
8593,
7406,
87,
1873,
1192,
9,
665,
7406,
32,
87,
1873,
1192,
14,
957,
30,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
519,
2344,
199,
2595,
199,
578,
26,
333,
1152,
63,
3629,
63,
2124,
63,
11863,
63,
4551,
199,
3612,
63,
1802,
26,
14944,
4770,
13,
1832,
812,
11778,
16150,
315,
4177,
1978,
199,
1802,
26,
199,
13,
14944,
4770,
13,
1832,
812,
11778,
16150,
315,
4177,
1978,
641,
28356,
437,
3553,
6879,
13,
8972,
14,
199,
2502,
26,
199,
13,
26110,
644,
1873,
1192,
8593,
7406,
87,
1873,
1192,
9,
199,
1023,
63,
3270,
26,
283,
18,
14,
24,
7,
199,
1419,
26,
523,
4177,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
4177,
14,
272,
730,
26,
620,
272,
1415,
26,
9456,
523,
4770,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
4770,
14,
272,
730,
26,
620,
272,
1415,
26,
9456,
523,
1978,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
1978,
14,
272,
730,
26,
620,
272,
1415,
26,
9456,
523,
15209,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
812,
11778,
14,
272,
730,
26,
620,
523,
4897,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
4897,
370,
9635,
14,
272,
730,
26,
620,
272,
5481,
26,
359,
536,
1622,
523,
1174,
26,
272,
1369,
26,
272,
446,
3645,
445,
8,
1881,
9,
503,
445,
8,
5575,
9,
367,
7791,
503,
12881,
14,
272,
446,
3645,
445,
8,
1131,
9,
367,
13778,
376,
909,
503,
3663,
2251,
14,
272,
730,
26,
620,
272,
3415,
26,
359,
9552,
12,
3451,
12,
1827,
1622,
272,
849,
26,
3451,
199,
3239,
12344,
26,
199,
13,
859,
26,
333,
1152,
63,
3629,
63,
2124,
63,
11863,
199,
13,
859,
26,
333,
1152,
63,
3629,
63,
1160,
63,
11863,
199,
11036,
63,
9970,
63,
7677,
26,
333,
1152,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
2654,
282,
892,
4770,
812,
11778,
4897,
523,
333,
1152,
63,
3629,
63,
1160,
63,
11863,
63,
4551,
26,
272,
1591,
26,
333,
1152,
63,
1102,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
4177,
26,
13268,
17,
272,
4770,
26,
11666,
17,
272,
1978,
26,
5458,
17,
272,
15209,
26,
812,
11778,
17,
272,
4897,
26,
2739,
13,
19082,
13,
17,
272,
1174,
26,
3451,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
5852,
282,
4770,
812,
11778,
4897,
523,
333,
1152,
63,
3629,
63,
1160,
63,
11863,
63,
4551,
26,
272,
1591,
26,
333,
1152,
63,
1102,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
4177,
26,
13268,
17,
272,
4770,
26,
11666,
17,
272,
1978,
26,
5458,
17,
272,
15209,
26,
812,
11778,
17,
272,
4897,
26,
2739,
13,
19082,
13,
17,
272,
1174,
26,
9552,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
8133,
282,
2488,
4770,
812,
11778,
4897,
523,
333,
1152,
63,
3629,
63,
1160,
63,
11863,
63,
4551,
26,
272,
1591,
26,
333,
1152,
63,
1102,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
4177,
26,
13268,
17,
272,
4770,
26,
11666,
17,
272,
1978,
26,
5458,
17,
272,
15209,
26,
812,
11778,
17,
272,
4897,
26,
2739,
13,
19082,
13,
17,
272,
1174,
26,
1827,
523,
13080,
63,
475,
26,
11667,
523,
2274,
26,
1827,
63,
1099,
199,
199,
13,
536,
26,
8133,
1006,
4770,
812,
11778,
16150,
523,
333,
1152,
63,
3629,
63,
1160,
63,
11863,
63,
4551,
26,
272,
1591,
26,
333,
1152,
63,
1102,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
4177,
26,
13268,
17,
272,
4770,
26,
11666,
17,
272,
1978,
26,
5458,
17,
272,
15209,
26,
812,
11778,
17,
272,
1174,
26,
1827,
523,
13080,
63,
475,
26,
11667,
523,
2274,
26,
1827,
63,
1099,
199,
2344,
199,
199,
9677,
275,
519,
2344,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
22832,
14,
706,
79,
492,
603,
4118,
2377,
12,
333,
1152,
63,
2094,
63,
1650,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
333,
1152,
63,
2094,
63,
1650,
342,
272,
1423,
63,
1650,
14,
873,
8,
267,
4177,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
549,
395,
267,
4770,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
549,
395,
267,
1978,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
549,
395,
267,
15209,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
549,
395,
267,
4897,
29,
807,
8,
466,
534,
495,
297,
5481,
2968,
354,
3815,
221,
327,
961,
2725,
365,
440,
1415,
367,
27405,
1006,
2251,
267,
1174,
29,
807,
8,
466,
534,
495,
297,
849,
534,
1881,
297,
3415,
2968,
5575,
297,
283,
1881,
297,
283,
1131,
3815,
272,
776,
339,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
2094,
63,
1650,
12,
267,
5171,
63,
1074,
63,
632,
29,
549,
12,
267,
1415,
63,
692,
1524,
288,
788,
929,
297,
283,
5575,
297,
788,
4551,
2157,
288,
788,
929,
297,
283,
1881,
297,
788,
4551,
2157,
267,
2156,
272,
776,
339,
4177,
275,
859,
14,
1162,
14,
362,
360,
3629,
358,
272,
4770,
275,
859,
14,
1162,
14,
362,
360,
2124,
358,
272,
1978,
275,
859,
14,
1162,
14,
362,
360,
1160,
358,
272,
15209,
275,
859,
14,
1162,
14,
362,
360,
11863,
358,
272,
4897,
275,
859,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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ignKey
from .pubsub_providers.base_provider import PUBACTIONS
from .model_tools import get_property
from .pubsub_providers.model_publisher import publish_model
from .serializers.serializer_importer import get_serializer
from django.db.models.signals import pre_delete, m2m_changed
from django.dispatch.dispatcher import receiver
class SelfPublishModel(object):
serializer_class = None
def __init__(self, *args, **kwargs):
if isinstance(self.serializer_class, str):
self.serializer_class = get_serializer(self.serializer_class, self)
self._pre_save_state = dict()
super(SelfPublishModel, self).__init__(*args, **kwargs)
self._serializer = self.serializer_class(instance=self)
self._set_pre_save_state()
def _set_pre_save_state(self):
"""
Set the state of the model before any changes are done,
so it's possible to determine what fields have changed.
"""
relevant_fields = self._get_relevant_fields()
for field in relevant_fields:
val = get_property(self, field)
if hasattr(self._serializer, field):
continue
if val is None:
self._pre_save_state[field] = None
continue
self._pre_save_state[field] = val
def _get_relevant_fields(self):
"""
Get all fields that will affect the state.
This is used to save the state of the model before it's updated,
to be able to get changes used when publishing an update (so not all fields are published)
"""
relevant_fields = self._serializer.base_fields
if 'id' in relevant_fields:
relevant_fields.remove('id')
relevant_fields_copy = []
# check for any foreign keys and include the key to the object instead of the object itself
# This is to avoid triggering queries to retrieve the foreign object
for field in self._meta.fields:
if field.name in relevant_fields:
if type(field) in (ForeignKey, ):
# typically field.attname is field.name + "_id" ie field_id
relevant_fields_copy.append(field.attname)
else:
relevant_fields_copy.append(field.name)
return relevant_fields_copy
# for field_name in relevant_fields:
# field = self._meta.get_field_by_name(field_name)[0]
# if isinstance(field, ForeignKey):
# relevant_fields.remove(field_name)
#
# return relevant_fields
def get_changed_fields(self):
changed_fields = []
for k, v in self._pre_save_state.items():
val = get_property(self, k)
if val != v:
changed_fields.append(k)
return changed_fields
def serialize(self):
return self._serializer.serialize()
def _publish(self, action, changed_fields=None):
publish_model(self, self._serializer, action, changed_fields)
def save(self, *args, **kwargs):
if not self.pk:
self.action = PUBACTIONS.created
self.changed_fields = None
else:
self.action = PUBACTIONS.updated
self.changed_fields = self.get_changed_fields()
super(SelfPublishModel, self).save(*args, **kwargs)
self._publish(self.action, self.changed_fields)
# Set the pre-save state to the current state
# in case the model is changed again before retrieval
self._set_pre_save_state()
@receiver(m2m_changed)
def _self_publish_model_m2m_change(sender, instance, action, model, pk_set, **kwargs):
if not isinstance(instance, SelfPublishModel):
return
instance.action = PUBACTIONS.updated
if action in ['post_add', 'post_clear', 'post_remove']:
instance._publish(instance.action, instance._serializer.opts.publish_fields)
@receiver(pre_delete)
def _self_publish_model_delete(sender, instance, **kwargs):
if isinstance(instance, SelfPublishModel):
instance._publish(PUBACTIONS.deleted)
|
bsd-3-clause
|
[
504,
1639,
14,
697,
14,
992,
492,
12718,
199,
504,
1275,
20213,
63,
9710,
14,
1095,
63,
3780,
492,
18787,
25194,
199,
504,
1275,
1238,
63,
2537,
492,
664,
63,
1829,
199,
504,
1275,
20213,
63,
9710,
14,
1238,
63,
12789,
492,
2780,
63,
1238,
199,
504,
1275,
12844,
14,
8349,
63,
12138,
492,
664,
63,
8349,
199,
504,
1639,
14,
697,
14,
992,
14,
10458,
492,
876,
63,
1807,
12,
333,
18,
77,
63,
2489,
199,
504,
1639,
14,
6052,
14,
14913,
492,
13035,
421,
199,
533,
23820,
13956,
1685,
8,
785,
304,
272,
9146,
63,
533,
275,
488,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
1228,
8,
277,
14,
8349,
63,
533,
12,
620,
304,
288,
291,
14,
8349,
63,
533,
275,
664,
63,
8349,
8,
277,
14,
8349,
63,
533,
12,
291,
9,
267,
291,
423,
657,
63,
2117,
63,
929,
275,
1211,
342,
267,
1613,
8,
12887,
13956,
1685,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
423,
8349,
275,
291,
14,
8349,
63,
533,
8,
842,
29,
277,
9,
267,
291,
423,
409,
63,
657,
63,
2117,
63,
929,
342,
339,
347,
485,
409,
63,
657,
63,
2117,
63,
929,
8,
277,
304,
267,
408,
267,
2494,
314,
1174,
402,
314,
1402,
2544,
1263,
4493,
787,
4224,
12,
267,
880,
652,
1159,
3962,
370,
6705,
4052,
1504,
1172,
2896,
14,
267,
408,
267,
12082,
63,
955,
275,
291,
423,
362,
63,
21906,
63,
955,
342,
267,
367,
901,
315,
12082,
63,
955,
26,
288,
1139,
275,
664,
63,
1829,
8,
277,
12,
901,
9,
288,
340,
2688,
8,
277,
423,
8349,
12,
901,
304,
355,
1980,
288,
340,
1139,
365,
488,
26,
355,
291,
423,
657,
63,
2117,
63,
929,
59,
698,
61,
275,
488,
355,
1980,
288,
291,
423,
657,
63,
2117,
63,
929,
59,
698,
61,
275,
1139,
339,
347,
485,
362,
63,
21906,
63,
955,
8,
277,
304,
267,
408,
267,
2372,
1006,
1504,
626,
911,
12787,
314,
1174,
14,
267,
961,
365,
1202,
370,
3354,
314,
1174,
402,
314,
1402,
2544,
652,
1159,
4588,
12,
267,
370,
506,
7688,
370,
664,
4493,
1202,
1380,
2780,
316,
376,
1678,
334,
1152,
440,
1006,
1504,
787,
3267,
9,
267,
408,
267,
12082,
63,
955,
275,
291,
423,
8349,
14,
1095,
63,
955,
398,
340,
283,
344,
7,
315,
12082,
63,
955,
26,
288,
12082,
63,
955,
14,
2168,
360,
344,
358,
398,
12082,
63,
955,
63,
1574,
275,
942,
398,
327,
1104,
367,
1263,
11608,
2883,
436,
2387,
314,
790,
370,
314,
909,
3140,
402,
314,
909,
6337,
267,
327,
961,
365,
370,
5126,
6804,
316,
9212,
370,
8044,
314,
11608,
909,
267,
367,
901,
315,
291,
423,
2024,
14,
955,
26,
288,
340,
901,
14,
354,
315,
12082,
63,
955,
26,
355,
340,
730,
8,
698,
9,
315,
334,
3190,
12,
3461,
490,
327,
13609,
901,
14,
13651,
365,
901,
14,
354,
435,
2668,
344,
2,
13446,
901,
63,
344,
490,
12082,
63,
955,
63,
1574,
14,
740,
8,
698,
14,
13651,
9,
355,
587,
26,
490,
12082,
63,
955,
63,
1574,
14,
740,
8,
698,
14,
354,
9,
398,
372,
12082,
63,
955,
63,
1574,
398,
327,
367,
901,
63,
354,
315,
12082,
63,
955,
26,
267,
327,
258,
901,
275,
291,
423,
2024,
14,
362,
63,
698,
63,
991,
63,
354,
8,
698,
63,
354,
2788,
16,
61,
267,
327,
258,
340,
1228,
8,
698,
12,
12718,
304,
267,
327,
260,
12082,
63,
955,
14,
2168,
8,
698,
63,
354,
9,
267,
327,
267,
327,
372,
12082,
63,
955,
339,
347,
664,
63,
2489,
63,
955,
8,
277,
304,
267,
2896,
63,
955,
275,
942,
267,
367,
1022,
12,
373,
315,
291,
423,
657,
63,
2117,
63,
929,
14,
1744,
837,
288,
1139,
275,
664,
63,
1829,
8,
277,
12,
1022,
9,
288,
340,
1139,
1137,
373,
26,
355,
2896,
63,
955,
14,
740,
8,
75,
9,
267,
372,
2896,
63,
955,
339,
347,
8437,
8,
277,
304,
267,
372,
291,
423,
8349,
14,
3549,
342,
339,
347,
485,
4763,
8,
277,
12,
1595,
12,
2896,
63,
955,
29,
403,
304,
267,
2780,
63,
1238,
8,
277,
12,
291,
423,
8349,
12,
1595,
12,
2896,
63,
955,
9,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
291,
14,
2051,
26,
288,
291,
14,
1287,
275,
18787,
25194,
14,
3966,
288,
291,
14,
2489,
63,
955,
275,
488,
267,
587,
26,
288,
291,
14,
1287,
275,
18787,
25194,
14,
5334,
288,
291,
14,
2489,
63,
955,
275,
291,
14,
362,
63,
2489,
63,
955,
342,
267,
1613,
8,
12887,
13956,
1685,
12,
291,
680,
2117,
2031,
589,
12,
1011,
958,
9,
267,
291,
423,
4763,
8,
277,
14,
1287,
12,
291,
14,
2489,
63,
955,
9,
398,
327,
2494,
314,
876,
13,
2117,
1174,
370,
314,
1453,
1174,
267,
327,
315,
1930,
314,
1402,
365,
2896,
4020,
2544,
27157,
267,
291,
423,
409,
63,
657,
63,
2117,
63,
929,
342,
421,
199,
32,
10244,
8,
77,
18,
77,
63,
2489,
9,
199,
318,
485,
277,
63,
4763,
63,
1238,
63,
77,
18,
77,
63,
1461,
8,
8114,
12,
1256,
12,
1595,
12,
1402,
12,
3803,
63,
409,
12,
1011,
958,
304,
272,
340,
440,
1228,
8,
842,
12,
23820,
13956,
1685,
304,
267,
372,
272,
1256,
14,
1287,
275,
18787,
25194,
14,
5334,
272,
340,
1595,
315,
788,
1932,
63,
525,
297,
283,
1932,
63,
3584,
297,
283,
1932,
63,
2168,
2565,
267,
1256,
423,
4763,
8,
842,
14,
1287,
12,
1256,
423,
8349,
14,
3291,
14,
4763,
63,
955,
9,
421,
199,
32,
10244,
8,
657,
63,
1807,
9,
199,
318,
485,
277,
63,
4763,
63,
1238,
63,
1807,
8,
8114,
12,
1256,
12,
1011,
958,
304,
272,
340,
1228,
8,
842,
12,
23820,
13956,
1685,
304,
267,
1256,
423,
4763,
8,
13047,
25194,
14,
6062,
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
] |
[
1639,
14,
697,
14,
992,
492,
12718,
199,
504,
1275,
20213,
63,
9710,
14,
1095,
63,
3780,
492,
18787,
25194,
199,
504,
1275,
1238,
63,
2537,
492,
664,
63,
1829,
199,
504,
1275,
20213,
63,
9710,
14,
1238,
63,
12789,
492,
2780,
63,
1238,
199,
504,
1275,
12844,
14,
8349,
63,
12138,
492,
664,
63,
8349,
199,
504,
1639,
14,
697,
14,
992,
14,
10458,
492,
876,
63,
1807,
12,
333,
18,
77,
63,
2489,
199,
504,
1639,
14,
6052,
14,
14913,
492,
13035,
421,
199,
533,
23820,
13956,
1685,
8,
785,
304,
272,
9146,
63,
533,
275,
488,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
1228,
8,
277,
14,
8349,
63,
533,
12,
620,
304,
288,
291,
14,
8349,
63,
533,
275,
664,
63,
8349,
8,
277,
14,
8349,
63,
533,
12,
291,
9,
267,
291,
423,
657,
63,
2117,
63,
929,
275,
1211,
342,
267,
1613,
8,
12887,
13956,
1685,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
423,
8349,
275,
291,
14,
8349,
63,
533,
8,
842,
29,
277,
9,
267,
291,
423,
409,
63,
657,
63,
2117,
63,
929,
342,
339,
347,
485,
409,
63,
657,
63,
2117,
63,
929,
8,
277,
304,
267,
408,
267,
2494,
314,
1174,
402,
314,
1402,
2544,
1263,
4493,
787,
4224,
12,
267,
880,
652,
1159,
3962,
370,
6705,
4052,
1504,
1172,
2896,
14,
267,
408,
267,
12082,
63,
955,
275,
291,
423,
362,
63,
21906,
63,
955,
342,
267,
367,
901,
315,
12082,
63,
955,
26,
288,
1139,
275,
664,
63,
1829,
8,
277,
12,
901,
9,
288,
340,
2688,
8,
277,
423,
8349,
12,
901,
304,
355,
1980,
288,
340,
1139,
365,
488,
26,
355,
291,
423,
657,
63,
2117,
63,
929,
59,
698,
61,
275,
488,
355,
1980,
288,
291,
423,
657,
63,
2117,
63,
929,
59,
698,
61,
275,
1139,
339,
347,
485,
362,
63,
21906,
63,
955,
8,
277,
304,
267,
408,
267,
2372,
1006,
1504,
626,
911,
12787,
314,
1174,
14,
267,
961,
365,
1202,
370,
3354,
314,
1174,
402,
314,
1402,
2544,
652,
1159,
4588,
12,
267,
370,
506,
7688,
370,
664,
4493,
1202,
1380,
2780,
316,
376,
1678,
334,
1152,
440,
1006,
1504,
787,
3267,
9,
267,
408,
267,
12082,
63,
955,
275,
291,
423,
8349,
14,
1095,
63,
955,
398,
340,
283,
344,
7,
315,
12082,
63,
955,
26,
288,
12082,
63,
955,
14,
2168,
360,
344,
358,
398,
12082,
63,
955,
63,
1574,
275,
942,
398,
327,
1104,
367,
1263,
11608,
2883,
436,
2387,
314,
790,
370,
314,
909,
3140,
402,
314,
909,
6337,
267,
327,
961,
365,
370,
5126,
6804,
316,
9212,
370,
8044,
314,
11608,
909,
267,
367,
901,
315,
291,
423,
2024,
14,
955,
26,
288,
340,
901,
14,
354,
315,
12082,
63,
955,
26,
355,
340,
730,
8,
698,
9,
315,
334,
3190,
12,
3461,
490,
327,
13609,
901,
14,
13651,
365,
901,
14,
354,
435,
2668,
344,
2,
13446,
901,
63,
344,
490,
12082,
63,
955,
63,
1574,
14,
740,
8,
698,
14,
13651,
9,
355,
587,
26,
490,
12082,
63,
955,
63,
1574,
14,
740,
8,
698,
14,
354,
9,
398,
372,
12082,
63,
955,
63,
1574,
398,
327,
367,
901,
63,
354,
315,
12082,
63,
955,
26,
267,
327,
258,
901,
275,
291,
423,
2024,
14,
362,
63,
698,
63,
991,
63,
354,
8,
698,
63,
354,
2788,
16,
61,
267,
327,
258,
340,
1228,
8,
698,
12,
12718,
304,
267,
327,
260,
12082,
63,
955,
14,
2168,
8,
698,
63,
354,
9,
267,
327,
267,
327,
372,
12082,
63,
955,
339,
347,
664,
63,
2489,
63,
955,
8,
277,
304,
267,
2896,
63,
955,
275,
942,
267,
367,
1022,
12,
373,
315,
291,
423,
657,
63,
2117,
63,
929,
14,
1744,
837,
288,
1139,
275,
664,
63,
1829,
8,
277,
12,
1022,
9,
288,
340,
1139,
1137,
373,
26,
355,
2896,
63,
955,
14,
740,
8,
75,
9,
267,
372,
2896,
63,
955,
339,
347,
8437,
8,
277,
304,
267,
372,
291,
423,
8349,
14,
3549,
342,
339,
347,
485,
4763,
8,
277,
12,
1595,
12,
2896,
63,
955,
29,
403,
304,
267,
2780,
63,
1238,
8,
277,
12,
291,
423,
8349,
12,
1595,
12,
2896,
63,
955,
9,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
291,
14,
2051,
26,
288,
291,
14,
1287,
275,
18787,
25194,
14,
3966,
288,
291,
14,
2489,
63,
955,
275,
488,
267,
587,
26,
288,
291,
14,
1287,
275,
18787,
25194,
14,
5334,
288,
291,
14,
2489,
63,
955,
275,
291,
14,
362,
63,
2489,
63,
955,
342,
267,
1613,
8,
12887,
13956,
1685,
12,
291,
680,
2117,
2031,
589,
12,
1011,
958,
9,
267,
291,
423,
4763,
8,
277,
14,
1287,
12,
291,
14,
2489,
63,
955,
9,
398,
327,
2494,
314,
876,
13,
2117,
1174,
370,
314,
1453,
1174,
267,
327,
315,
1930,
314,
1402,
365,
2896,
4020,
2544,
27157,
267,
291,
423,
409,
63,
657,
63,
2117,
63,
929,
342,
421,
199,
32,
10244,
8,
77,
18,
77,
63,
2489,
9,
199,
318,
485,
277,
63,
4763,
63,
1238,
63,
77,
18,
77,
63,
1461,
8,
8114,
12,
1256,
12,
1595,
12,
1402,
12,
3803,
63,
409,
12,
1011,
958,
304,
272,
340,
440,
1228,
8,
842,
12,
23820,
13956,
1685,
304,
267,
372,
272,
1256,
14,
1287,
275,
18787,
25194,
14,
5334,
272,
340,
1595,
315,
788,
1932,
63,
525,
297,
283,
1932,
63,
3584,
297,
283,
1932,
63,
2168,
2565,
267,
1256,
423,
4763,
8,
842,
14,
1287,
12,
1256,
423,
8349,
14,
3291,
14,
4763,
63,
955,
9,
421,
199,
32,
10244,
8,
657,
63,
1807,
9,
199,
318,
485,
277,
63,
4763,
63,
1238,
63,
1807,
8,
8114,
12,
1256,
12,
1011,
958,
304,
272,
340,
1228,
8,
842,
12,
23820,
13956,
1685,
304,
267,
1256,
423,
4763,
8,
13047,
25194,
14,
6062,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
cihaterdal/limbo-android
|
jni/qemu/scripts/tracetool/format/__init__.py
|
205
|
3012
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Format management.
Creating new formats
--------------------
A new format named 'foo-bar' corresponds to Python module
'tracetool/format/foo_bar.py'.
A format module should provide a docstring, whose first non-empty line will be
considered its short description.
All formats must generate their contents through the 'tracetool.out' routine.
Format functions
----------------
All the following functions are optional, and no output will be generated if
they do not exist.
======== =======================================================================
Function Description
======== =======================================================================
begin Called to generate the format-specific file header.
end Called to generate the format-specific file footer.
nop Called to generate the per-event contents when the event is disabled or
the selected backend is 'nop'.
======== =======================================================================
"""
__author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
__copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
__license__ = "GPL version 2 or (at your option) any later version"
__maintainer__ = "Stefan Hajnoczi"
__email__ = "stefanha@linux.vnet.ibm.com"
import os
import tracetool
def get_list():
"""Get a list of (name, description) pairs."""
res = []
modnames = []
for filename in os.listdir(tracetool.format.__path__[0]):
if filename.endswith('.py') and filename != '__init__.py':
modnames.append(filename.rsplit('.', 1)[0])
for modname in modnames:
module = tracetool.try_import("tracetool.format." + modname)
# just in case; should never fail unless non-module files are put there
if not module[0]:
continue
module = module[1]
doc = module.__doc__
if doc is None:
doc = ""
doc = doc.strip().split("\n")[0]
name = modname.replace("_", "-")
res.append((name, doc))
return res
def exists(name):
"""Return whether the given format exists."""
if len(name) == 0:
return False
name = name.replace("-", "_")
return tracetool.try_import("tracetool.format." + name)[1]
def _empty(events):
pass
def generate_begin(name, events):
"""Generate the header of the format-specific file."""
if not exists(name):
raise ValueError("unknown format: %s" % name)
name = name.replace("-", "_")
func = tracetool.try_import("tracetool.format." + name,
"begin", _empty)[1]
func(events)
def generate_end(name, events):
"""Generate the footer of the format-specific file."""
if not exists(name):
raise ValueError("unknown format: %s" % name)
name = name.replace("-", "_")
func = tracetool.try_import("tracetool.format." + name,
"end", _empty)[1]
func(events)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
3484,
10041,
14,
421,
199,
14380,
892,
6752,
199,
777,
375,
199,
199,
33,
892,
1475,
4310,
283,
1421,
13,
1700,
7,
13718,
370,
2018,
859,
199,
1133,
5986,
3557,
15,
908,
15,
1421,
63,
1700,
14,
647,
1370,
199,
199,
33,
1475,
859,
1077,
5647,
282,
9214,
12,
7447,
1642,
2222,
13,
1667,
1004,
911,
506,
199,
388,
2441,
581,
2399,
3974,
1369,
14,
199,
199,
2422,
6752,
1471,
3550,
3932,
4072,
4012,
314,
283,
3446,
3557,
14,
548,
7,
12981,
14,
421,
199,
3484,
3423,
199,
777,
199,
199,
2422,
314,
2569,
3423,
787,
2716,
12,
436,
949,
1072,
911,
506,
4046,
340,
199,
29002,
886,
440,
2187,
14,
199,
199,
763,
7819,
23476,
199,
3481,
11994,
199,
763,
7819,
23476,
199,
5037,
259,
12295,
370,
3550,
314,
1475,
13,
6100,
570,
1406,
14,
199,
500,
420,
12295,
370,
3550,
314,
1475,
13,
6100,
570,
14178,
14,
199,
20443,
420,
12295,
370,
3550,
314,
1126,
13,
1430,
4072,
1380,
314,
1566,
365,
6980,
503,
268,
314,
4895,
4865,
365,
283,
20443,
1370,
199,
763,
7819,
23476,
199,
624,
199,
199,
363,
2502,
363,
258,
275,
298,
44,
10836,
13676,
83,
812,
382,
8143,
3042,
665,
29792,
8143,
3042,
32,
645,
14,
384,
67,
14,
8654,
4335,
199,
363,
7307,
363,
221,
275,
298,
7384,
6029,
12,
491,
10836,
13676,
83,
812,
382,
8143,
3042,
665,
29792,
8143,
3042,
32,
645,
14,
384,
67,
14,
8654,
4335,
199,
363,
1682,
363,
259,
275,
298,
12006,
1015,
499,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
2,
199,
199,
363,
26665,
363,
275,
298,
26696,
12269,
869,
9091,
23507,
16079,
2,
199,
363,
2123,
363,
420,
275,
298,
1597,
12269,
2411,
32,
5135,
14,
86,
846,
14,
19870,
14,
957,
2,
421,
199,
646,
747,
199,
199,
646,
3307,
3557,
421,
199,
318,
664,
63,
513,
837,
272,
408,
1002,
282,
769,
402,
334,
354,
12,
1369,
9,
6342,
1041,
272,
522,
275,
942,
272,
3413,
1247,
275,
942,
272,
367,
1788,
315,
747,
14,
7374,
8,
3446,
3557,
14,
908,
855,
515,
12298,
16,
4682,
267,
340,
1788,
14,
4130,
5175,
647,
358,
436,
1788,
1137,
2560,
826,
4343,
647,
356,
288,
3413,
1247,
14,
740,
8,
1501,
14,
13490,
14078,
413,
2788,
16,
566,
272,
367,
13526,
315,
3413,
1247,
26,
267,
859,
275,
3307,
3557,
14,
893,
63,
646,
480,
3446,
3557,
14,
908,
2122,
435,
13526,
9,
398,
327,
2951,
315,
1930,
27,
1077,
7078,
2449,
7444,
2222,
13,
578,
1584,
787,
5324,
2337,
267,
340,
440,
859,
59,
16,
2189,
288,
1980,
267,
859,
275,
859,
59,
17,
61,
398,
1382,
275,
859,
855,
1301,
363,
267,
340,
1382,
365,
488,
26,
288,
1382,
275,
3087,
267,
1382,
275,
1382,
14,
1913,
1252,
1294,
4582,
78,
9981,
16,
61,
398,
536,
275,
13526,
14,
1814,
11008,
401,
3905,
531,
267,
522,
14,
740,
1332,
354,
12,
1382,
430,
272,
372,
522,
421,
199,
318,
3495,
8,
354,
304,
272,
408,
1767,
3775,
314,
1627,
1475,
3495,
1041,
272,
340,
822,
8,
354,
9,
508,
378,
26,
267,
372,
756,
272,
536,
275,
536,
14,
1814,
6096,
401,
2668,
531,
272,
372,
3307,
3557,
14,
893,
63,
646,
480,
3446,
3557,
14,
908,
2122,
435,
536,
2788,
17,
61,
421,
199,
318,
485,
1667,
8,
4368,
304,
272,
986,
199,
199,
318,
3550,
63,
5037,
8,
354,
12,
4474,
304,
272,
408,
6864,
314,
1406,
402,
314,
1475,
13,
6100,
570,
1041,
272,
340,
440,
3495,
8,
354,
304,
267,
746,
1722,
480,
5187,
1475,
26,
450,
83,
2,
450,
536,
9,
339,
536,
275,
536,
14,
1814,
6096,
401,
2668,
531,
272,
2562,
275,
3307,
3557,
14,
893,
63,
646,
480,
3446,
3557,
14,
908,
2122,
435,
536,
12,
1816,
298,
5037,
401,
485,
1667,
2788,
17,
61,
272,
2562,
8,
4368,
9,
199,
199,
318,
3550,
63,
500,
8,
354,
12,
4474,
304,
272,
408,
6864,
314,
14178,
402,
314,
1475,
13,
6100,
570,
1041,
272,
340,
440,
3495,
8,
354,
304,
267,
746,
1722,
480,
5187,
1475,
26,
450,
83,
2,
450,
536,
9,
339,
536,
275,
536,
14,
1814,
6096,
401,
2668,
531,
272,
2562,
275,
3307,
3557,
14,
893,
63,
646,
480,
3446,
3557,
14,
908,
2122,
435,
536,
12,
1816,
298,
500,
401,
485,
1667,
2788,
17,
61,
272,
2562,
8,
4368,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
3484,
10041,
14,
421,
199,
14380,
892,
6752,
199,
777,
375,
199,
199,
33,
892,
1475,
4310,
283,
1421,
13,
1700,
7,
13718,
370,
2018,
859,
199,
1133,
5986,
3557,
15,
908,
15,
1421,
63,
1700,
14,
647,
1370,
199,
199,
33,
1475,
859,
1077,
5647,
282,
9214,
12,
7447,
1642,
2222,
13,
1667,
1004,
911,
506,
199,
388,
2441,
581,
2399,
3974,
1369,
14,
199,
199,
2422,
6752,
1471,
3550,
3932,
4072,
4012,
314,
283,
3446,
3557,
14,
548,
7,
12981,
14,
421,
199,
3484,
3423,
199,
777,
199,
199,
2422,
314,
2569,
3423,
787,
2716,
12,
436,
949,
1072,
911,
506,
4046,
340,
199,
29002,
886,
440,
2187,
14,
199,
199,
763,
7819,
23476,
199,
3481,
11994,
199,
763,
7819,
23476,
199,
5037,
259,
12295,
370,
3550,
314,
1475,
13,
6100,
570,
1406,
14,
199,
500,
420,
12295,
370,
3550,
314,
1475,
13,
6100,
570,
14178,
14,
199,
20443,
420,
12295,
370,
3550,
314,
1126,
13,
1430,
4072,
1380,
314,
1566,
365,
6980,
503,
268,
314,
4895,
4865,
365,
283,
20443,
1370,
199,
763,
7819,
23476,
199,
624,
199,
199,
363,
2502,
363,
258,
275,
298,
44,
10836,
13676,
83,
812,
382,
8143,
3042,
665,
29792,
8143,
3042,
32,
645,
14,
384,
67,
14,
8654,
4335,
199,
363,
7307,
363,
221,
275,
298,
7384,
6029,
12,
491,
10836,
13676,
83,
812,
382,
8143,
3042,
665,
29792,
8143,
3042,
32,
645,
14,
384,
67,
14,
8654,
4335,
199,
363,
1682,
363,
259,
275,
298,
12006,
1015,
499,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
2,
199,
199,
363,
26665,
363,
275,
298,
26696,
12269,
869,
9091,
23507,
16079,
2,
199,
363,
2123,
363,
420,
275,
298,
1597,
12269,
2411,
32,
5135,
14,
86,
846,
14,
19870,
14,
957,
2,
421,
199,
646,
747,
199,
199,
646,
3307,
3557,
421,
199,
318,
664,
63,
513,
837,
272,
408,
1002,
282,
769,
402,
334,
354,
12,
1369,
9,
6342,
1041,
272,
522,
275,
942,
272,
3413,
1247,
275,
942,
272,
367,
1788,
315,
747,
14,
7374,
8,
3446,
3557,
14,
908,
855,
515,
12298,
16,
4682,
267,
340,
1788,
14,
4130,
5175,
647,
358,
436,
1788,
1137,
2560,
826,
4343,
647,
356,
288,
3413,
1247,
14,
740,
8,
1501,
14,
13490,
14078,
413,
2788,
16,
566,
272,
367,
13526,
315,
3413,
1247,
26,
267,
859,
275,
3307,
3557,
14,
893,
63,
646,
480,
3446,
3557,
14,
908,
2122,
435,
13526,
9,
398,
327,
2951,
315,
1930,
27,
1077,
7078,
2449,
7444,
2222,
13,
578,
1584,
787,
5324,
2337,
267,
340,
440,
859,
59,
16,
2189,
288,
1980,
267,
859,
275,
859,
59,
17,
61,
398,
1382,
275,
859,
855,
1301,
363,
267,
340,
1382,
365,
488,
26,
288,
1382,
275,
3087,
267,
1382,
275,
1382,
14,
1913,
1252,
1294,
4582,
78,
9981,
16,
61,
398,
536,
275,
13526,
14,
1814,
11008,
401,
3905,
531,
267,
522,
14,
740,
1332,
354,
12,
1382,
430,
272,
372,
522,
421,
199,
318,
3495,
8,
354,
304,
272,
408,
1767,
3775,
314,
1627,
1475,
3495,
1041,
272,
340,
822,
8,
354,
9,
508,
378,
26,
267,
372,
756,
272,
536,
275,
536,
14,
1814,
6096,
401,
2668,
531,
272,
372,
3307,
3557,
14,
893,
63,
646,
480,
3446,
3557,
14,
908,
2122,
435,
536,
2788,
17,
61,
421,
199,
318,
485,
1667,
8,
4368,
304,
272,
986,
199,
199,
318,
3550,
63,
5037,
8,
354,
12,
4474,
304,
272,
408,
6864,
314,
1406,
402,
314,
1475,
13,
6100,
570,
1041,
272,
340,
440,
3495,
8,
354,
304,
267,
746,
1722,
480,
5187,
1475,
26,
450,
83,
2,
450,
536,
9,
339,
536,
275,
536,
14,
1814,
6096,
401,
2668,
531,
272,
2562,
275,
3307,
3557,
14,
893,
63,
646,
480,
3446,
3557,
14,
908,
2122,
435,
536,
12,
1816,
298,
5037,
401,
485,
1667,
2788,
17,
61,
272,
2562,
8,
4368,
9,
199,
199,
318,
3550,
63,
500,
8,
354,
12,
4474,
304,
272,
408,
6864,
314,
14178,
402,
314,
1475,
13,
6100,
570,
1041,
272,
340,
440,
3495,
8,
354,
304,
267,
746,
1722,
480,
5187,
1475,
26,
450,
83,
2,
450,
536,
9,
339,
536,
275,
536,
14,
1814,
6096,
401,
2668,
531,
272,
2562,
275,
3307,
3557,
14,
893,
63,
646,
480,
3446,
3557,
14,
908,
2122,
435,
536,
12,
1816,
298,
500,
401,
485,
1667,
2788,
17,
61,
272,
2562,
8,
4368,
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,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
import time, sys, collections, os
from textwrap import dedent
import psycopg2
# NOTE: instead of using the python csv writer, this directly writes tables to
# file in the pyomo .tab format. This uses tabs between columns and the standard
# line break for the system it is run on. This does the following translations (only):
# - If a value contains double quotes, they get doubled.
# - If a value contains a single quote, tab or space character, the value gets enclosed in double quotes.
# (Note that pyomo doesn't allow quoting (and therefore spaces) in column headers.)
# - null values are converted to . (the pyomo/ampl standard for missing data)
# - any other values are simply passed to str().
# NOTE: this does not use the python csv writer because it doesn't support the quoting
# or null behaviors described above.
# NOTE: ANSI SQL specifies single quotes for literal strings, and postgres conforms
# to this, so all the queries below should use single quotes around strings.
# NOTE: write_table() will automatically convert null values to '.',
# so pyomo will recognize them as missing data
# NOTE: the code below could be made more generic, e.g., a list of
# table names and queries, which are then processed at the end.
# But that would be harder to debug, and wouldn't allow for ad hoc
# calculations or writing .dat files (which are used for a few parameters)
def write_tables(**args):
#########################
# timescales
write_table('periods.tab', """
WITH period_length as (
SELECT
CASE WHEN max(period) = min(period)
THEN
-- one-period model; assume length = number of days provided
sum(ts_scale_to_period) / 365
ELSE
-- multi-period model; count number of years between periods
(max(period)-min(period)) / (count(distinct period)-1)
END as length
FROM study_date WHERE time_sample = %(time_sample)s
)
SELECT period AS "INVESTMENT_PERIOD",
period as period_start,
period + length - 1 as period_end
FROM study_periods, period_length
WHERE time_sample = %(time_sample)s
ORDER by 1;
""", args)
write_table('timeseries.tab', """
SELECT study_date as "TIMESERIES", period as ts_period,
ts_duration_of_tp, ts_num_tps, ts_scale_to_period
FROM study_date
WHERE time_sample = %(time_sample)s
ORDER BY 1;
""", args)
write_table('timepoints.tab', """
SELECT h.study_hour as timepoint_id,
to_char(date_time + (period - extract(year from date_time)) * interval '1 year',
'YYYY-MM-DD-HH24:MI') as timestamp,
h.study_date as timeseries
FROM study_hour h JOIN study_date d USING (study_date, time_sample)
WHERE h.time_sample = %(time_sample)s
ORDER BY period, extract(doy from date), study_hour;
""", args)
#########################
# financials
# this just uses a dat file, not a table (and the values are not in a database for now)
write_dat_file(
'financials.dat',
['base_financial_year', 'interest_rate', 'discount_rate'],
args
)
#########################
# load_zones
# note: we don't provide the following fields in this version:
# lz_cost_multipliers, lz_ccs_distance_km, lz_dbid,
# existing_local_td, local_td_annual_cost_per_mw
write_table('load_zones.tab', """
SELECT load_zone as "LOAD_ZONE"
FROM load_zone
WHERE load_zone in %(load_zones)s
""", args)
# NOTE: we don't provide lz_peak_loads.tab (sometimes used by local_td.py) in this version.
# get system loads, scaled from the historical years to the model years
# note: 'offset' is a keyword in postgresql, so we use double-quotes to specify the column name
write_table('loads.tab', """
SELECT
l.load_zone AS "LOAD_ZONE",
study_hour AS "TIMEPOINT",
system_load * scale + "offset" AS lz_demand_mw
FROM study_date d
JOIN study_hour h USING (time_sample, study_date)
JOIN system_load l USING (date_time)
JOIN system_load_scale s ON (
s.load_zone = l.load_zone
AND s.year_hist = extract(year from l.date_time)
AND s.year_fore = d.period)
WHERE l.load_zone in %(load_zones)s
AND d.time_sample = %(time_sample)s
AND load_scen_id = %(load_scen_id)s;
""", args)
#########################
# fuels
write_table('non_fuel_energy_sources.tab', """
SELECT DISTINCT fuel AS "NON_FUEL_ENERGY_SOURCES"
FROM generator_costs
WHERE fuel NOT IN (SELECT fuel_type FROM fuel_costs)
AND min_vintage_year <= (SELECT MAX(period) FROM study_periods WHERE time_sample = %(time_sample)s)
UNION DISTINCT
SELECT aer_fuel_code AS "NON_FUEL_ENERGY_SOURCES"
FROM existing_plants
WHERE aer_fuel_code NOT IN (SELECT fuel_type FROM fuel_costs)
AND load_zone in %(load_zones)s
AND insvyear <= (SELECT MAX(period) FROM study_periods WHERE time_sample = %(time_sample)s)
AND technology NOT IN %(exclude_technologies)s;
""", args)
# gather info on fuels
write_table('fuels.tab', """
SELECT DISTINCT c.fuel_type AS fuel, co2_intensity, 0.0 AS upstream_co2_intensity, rps_eligible
FROM fuel_costs c JOIN energy_source_properties p on (p.energy_source = c.fuel_type)
WHERE load_zone in %(load_zones)s AND fuel_scen_id=%(fuel_scen_id)s;
""", args)
#########################
# rps targets
write_tab_file(
'rps_targets.tab',
headers=('year', 'rps_target'),
data=[(y, args['rps_targets'][y]) for y in sorted(args['rps_targets'].keys())],
arguments=args
)
#########################
# fuel_markets
# deflate HECO fuel scenarios to base year, and inflate EIA-based scenarios
# from 2013 (forecast base year) to model base year. (ugh)
# TODO: add a flag to fuel_costs indicating whether forecasts are real or nominal,
# and base year, and possibly inflation rate.
if args['fuel_scen_id'] in ('1', '2', '3'):
inflator = 'power(1.0+%(inflation_rate)s, %(base_financial_year)s-c.year)'
elif args['fuel_scen_id'].startswith('EIA'):
inflator = 'power(1.0+%(inflation_rate)s, %(base_financial_year)s-2013)'
else:
inflator = '1.0'
if args.get("use_simple_fuel_costs", False):
# simple fuel markets with no bulk LNG expansion option
# (use fuel_cost module)
# TODO: get monthly fuel costs from Karl Jandoc spreadsheet
write_table('fuel_cost.tab', """
SELECT load_zone, fuel_type as fuel, period,
price_mmbtu * {inflator} as fuel_cost
FROM fuel_costs c JOIN study_periods p ON (c.year=p.period)
WHERE load_zone in %(load_zones)s
AND fuel_scen_id = %(fuel_scen_id)s
AND p.time_sample = %(time_sample)s
AND NOT (fuel_type='LNG' AND tier='bulk')
ORDER BY 1, 2, 3;
""".format(inflator=inflator), args)
else:
# advanced fuel markets with LNG expansion options (used by forward-looking models)
# (use fuel_markets module)
write_table('regional_fuel_markets.tab', """
SELECT DISTINCT concat('Hawaii_', fuel_type) AS regional_fuel_market, fuel_type AS fuel
FROM fuel_costs
WHERE load_zone in %(load_zones)s AND fuel_scen_id = %(fuel_scen_id)s;
""", args)
write_table('fuel_supply_curves.tab', """
SELECT concat('Hawaii_', fuel_type) as regional_fuel_market, fuel_type as fuel,
period, tier, price_mmbtu * {inflator} as unit_cost,
%(bulk_lng_limit)s AS max_avail_at_cost,
CASE WHEN fuel_type='LNG' AND tier='bulk' THEN %(bulk_lng_fixed_cost)s ELSE 0.0 END
AS fixed_cost
FROM fuel_costs c JOIN study_periods p ON (c.year=p.period)
WHERE load_zone in %(load_zones)s
AND fuel_scen_id = %(fuel_scen_id)s
AND p.time_sample = %(time_sample)s
ORDER BY 1, 2, 3;
""".format(inflator=inflator), args)
write_table('lz_to_regional_fuel_market.tab', """
SELECT DISTINCT load_zone, concat('Hawaii_', fuel_type) AS regional_fuel_market
FROM fuel_costs
WHERE load_zone in %(load_zones)s AND fuel_scen_id = %(fuel_scen_id)s;
""", args)
# TODO: (when multi-island) add fuel_cost_adders for each zone
#########################
# gen_tech
# TODO: provide reasonable retirement ages for existing plants (not 100+base age)
# note: this zeroes out variable_o_m for renewable projects
# TODO: find out where variable_o_m came from for renewable projects and put it in the right place
# TODO: fix baseload flag in the database
# TODO: account for multiple fuel sources for a single plant in the upstream database
# and propagate that to this table.
# TODO: make sure the heat rates are null for non-fuel projects in the upstream database,
# and remove the correction code from here
# TODO: create heat_rate and fuel columns in the existing_plants_gen_tech table and simplify the query below.
# TODO: add unit sizes for new projects to the generator_costs table (new projects) from
# Switch-Hawaii/data/HECO\ IRP\ Report/IRP-2013-App-K-Supply-Side-Resource-Assessment-062813-Filed.pdf
# and then incorporate those into unit_sizes.tab below.
# NOTE: this converts variable o&m from $/kWh to $/MWh
# NOTE: we don't provide the following in this version:
# g_min_build_capacity
# g_ccs_capture_efficiency, g_ccs_energy_load,
# g_storage_efficiency, g_store_to_release_ratio
# NOTE: for all energy sources other than 'SUN' and 'WND' (i.e., all fuels),
# We report the fuel as 'multiple' and then provide data in a multi-fuel table.
# Some of these are actually single-fuel, but this approach is simpler than sorting
# them out within each query, and it doesn't add any complexity to the model.
# TODO: maybe replace "fuel IN ('SUN', 'WND', 'MSW')" with "fuel not in (SELECT fuel FROM fuel_cost)"
# TODO: convert 'MSW' to a proper fuel, possibly with a negative cost, instead of ignoring it
write_table('generator_info.tab', """
SELECT technology as generation_technology,
technology as g_dbid,
max_age_years as g_max_age,
scheduled_outage_rate as g_scheduled_outage_rate,
forced_outage_rate as g_forced_outage_rate,
intermittent as g_is_variable,
0 as g_is_baseload,
0 as g_is_flexible_baseload,
0 as g_is_cogen,
0 as g_competes_for_space,
CASE WHEN fuel IN ('SUN', 'WND') THEN 0 ELSE variable_o_m * 1000.0 END AS g_variable_o_m,
CASE WHEN fuel IN ('SUN', 'WND', 'MSW') THEN fuel ELSE 'multiple' END AS g_energy_source,
CASE WHEN fuel IN ('SUN', 'WND', 'MSW') THEN null ELSE 0.001*heat_rate END AS g_full_load_heat_rate,
null AS g_unit_size
FROM generator_costs
WHERE technology NOT IN %(exclude_technologies)s
AND min_vintage_year <= (SELECT MAX(period) FROM study_periods WHERE time_sample = %(time_sample)s)
UNION SELECT
g.technology as generation_technology,
g.technology as g_dbid,
-- formerly g.max_age + 100 as g_max_age,
g.max_age as g_max_age,
g.scheduled_outage_rate as g_scheduled_outage_rate,
g.forced_outage_rate as g_forced_outage_rate,
g.variable as g_is_variable,
g.baseload as g_is_baseload,
0 as g_is_flexible_baseload,
g.cogen as g_is_cogen,
g.competes_for_space as g_competes_for_space,
CASE WHEN MIN(p.aer_fuel_code) IN ('SUN', 'WND') THEN 0.0 ELSE AVG(g.variable_o_m) * 1000.0 END
AS g_variable_o_m,
CASE WHEN MIN(p.aer_fuel_code) IN ('SUN', 'WND', 'MSW') THEN MIN(p.aer_fuel_code) ELSE 'multiple' END AS g_energy_source,
CASE WHEN MIN(p.aer_fuel_code) IN ('SUN', 'WND', 'MSW') THEN null
ELSE 0.001*SUM(p.heat_rate*p.avg_mw)/SUM(p.avg_mw)
END AS g_full_load_heat_rate,
AVG(peak_mw) AS g_unit_size -- minimum block size for unit commitment
FROM existing_plants_gen_tech g JOIN existing_plants p USING (technology)
WHERE p.load_zone in %(load_zones)s
AND p.insvyear <= (SELECT MAX(period) FROM study_periods WHERE time_sample = %(time_sample)s)
AND g.technology NOT IN %(exclude_technologies)s
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
ORDER BY 1;
""", args)
# This gets a list of all the fueled projects (listed as "multiple" energy sources above),
# and lists them as accepting any equivalent or lighter fuel. (However, cogen plants and plants
# using fuels with rank 0 are not changed.) Fuels are also filtered against the list of fuels with
# costs reported for the current scenario, so this can end up re-mapping one fuel in the database
# (e.g., LSFO) to a similar fuel in the scenario (e.g., LSFO-Diesel-Blend), even if the original fuel
# doesn't exist in the fuel_costs table. This can also be used to remap different names for the same
# fuel (e.g., "COL" in the plant definition and "Coal" in the fuel_costs table, both with the same
# fuel_rank).
write_indexed_set_dat_file('gen_multiple_fuels.dat', 'G_MULTI_FUELS', """
WITH all_techs AS (
SELECT
technology as generation_technology,
fuel as orig_fuel,
0 as cogen
FROM generator_costs c
WHERE min_vintage_year <= (SELECT MAX(period) FROM study_periods WHERE time_sample = %(time_sample)s)
AND technology NOT IN %(exclude_technologies)s
UNION DISTINCT
SELECT DISTINCT
g.technology as generation_technology,
p.aer_fuel_code as orig_fuel,
g.cogen
FROM existing_plants_gen_tech g JOIN existing_plants p USING (technology)
WHERE p.load_zone in %(load_zones)s
AND p.insvyear <= (SELECT MAX(period) FROM study_periods WHERE time_sample = %(time_sample)s)
AND g.technology NOT IN %(exclude_technologies)s
), all_fueled_techs AS (
SELECT * from all_techs WHERE orig_fuel NOT IN ('SUN', 'WND', 'MSW')
)
SELECT DISTINCT generation_technology, b.energy_source as fuel
FROM all_fueled_techs t
JOIN energy_source_properties a ON a.energy_source = t.orig_fuel
JOIN energy_source_properties b ON b.fuel_rank >= a.fuel_rank AND
(a.fuel_rank > 0 OR a.energy_source = b.energy_source) -- 0-rank can't change fuels
WHERE b.energy_source IN (SELECT fuel_type FROM fuel_costs WHERE fuel_scen_id = %(fuel_scen_id)s);
""", args)
# TODO: write code in project.unitcommit.commit to load part-load heat rates
# TODO: get part-load heat rates for new plant technologies and report them in
# project.unit.commit instead of full-load heat rates here.
# TODO: report part-load heat rates for existing plants in project.unitcommit.commit
# (maybe on a project-specific basis instead of generalized for each technology)
# NOTE: we divide heat rate by 1000 to convert from Btu/kWh to MBtu/MWh
inflator = "power(1.0 + CASE fuel"
if 'wind_capital_cost_escalator' in args or 'pv_capital_cost_escalator' in args:
if 'wind_capital_cost_escalator' in args:
inflator += " WHEN 'WND' THEN %(wind_capital_cost_escalator)s"
if 'pv_capital_cost_escalator' in args:
inflator += " WHEN 'SUN' THEN %(pv_capital_cost_escalator)s"
inflator += ' ELSE 0.0 END, period - %(base_financial_year)s)'
else:
inflator = "1.0"
# note: this table can only hold costs for technologies with future build years,
# so costs for existing technologies are specified in project_specific_costs.tab
# NOTE: costs in this version of switch are expressed in $/MW, $/MW-year, etc., not per kW.
write_table('gen_new_build_costs.tab', """
SELECT
technology as generation_technology,
period AS investment_period,
capital_cost_per_kw * 1000.0 * {inflator} AS g_overnight_cost,
fixed_o_m*1000.0 AS g_fixed_o_m
FROM generator_costs, study_periods
WHERE technology NOT IN %(exclude_technologies)s
AND time_sample = %(time_sample)s
AND min_vintage_year <= (SELECT MAX(period) FROM study_periods WHERE time_sample = %(time_sample)s)
ORDER BY 1, 2;
""".format(inflator=inflator), args)
#########################
# project.build
# TODO: find connection costs and add them to the switch database (currently all zeroes)
# TODO: find out why exissting wind and solar projects have non-zero variable O&M in the switch
# database, and zero them out there instead of here.
# NOTE: if a generator technology in the generator_costs table doesn't have a match in the connect_cost
# table, we use the generic_cost_per_kw from the generator_costs table. If that is also null,
# then the connection cost will be given whatever default value is specified in the SWITCH code
# (probably zero).
# If individual projects are identified in connect_cost or max_capacity, we use those;
# then we also add generic projects in each load_zone for any technologies that are not
# marked as resource_limited in generator_costs.
# NOTE: if a technology ever appears in either max_capacity or connect_cost, then
# every possible project of that type should be recorded in that table.
# Technologies that don't appear in these tables are deemed generic projects,
# which can be added once in each load zone.
# NOTE: the queries below will not detect if a technology is attached to different
# sets of project definitions in the max_capacity and connect_cost tables;
# we leave it to the user to ensure this doesn't happen.
# NOTE: we don't provide the following, because they are specified in generator_info.tab instead
# proj_full_load_heat_rate, proj_forced_outage_rate, proj_scheduled_outage_rate
# (the project-specific data would only be for otherwise-similar projects that have degraded and
# now have different heat rates)
# NOTE: variable costs for existing plants could alternatively be added to the generator_info.tab
# table (aggregated by technology instead of project). That is where we put the variable costs for new projects.
# NOTE: we convert costs from $/kWh to $/MWh
write_table('project_info.tab', """
-- make a list of all projects with detailed definitions (and gather the available data)
DROP TABLE IF EXISTS t_specific_projects;
CREATE TEMPORARY TABLE t_specific_projects AS
SELECT
concat_ws('_',
COALESCE(m.load_zone, c.load_zone),
COALESCE(m.technology, c.technology),
COALESCE(m.site, c.site),
COALESCE(m.orientation, c.orientation)
) AS "PROJECT",
COALESCE(m.load_zone, c.load_zone) as proj_load_zone,
COALESCE(m.technology, c.technology) AS proj_gen_tech,
%(connect_cost_per_mw_km)s*connect_length_km + 1000.0*connect_cost_per_kw as proj_connect_cost_per_mw,
max_capacity as proj_capacity_limit_mw
FROM connect_cost c FULL JOIN max_capacity m USING (load_zone, technology, site, orientation);
-- make a list of generic projects (for which no detailed definitions are available)
DROP TABLE IF EXISTS t_generic_projects;
CREATE TEMPORARY TABLE t_generic_projects AS
SELECT
concat_ws('_', load_zone, technology) AS "PROJECT",
load_zone as proj_load_zone,
technology AS proj_gen_tech,
cast(null as float) AS proj_connect_cost_per_mw,
cast(null as float) AS proj_capacity_limit_mw
FROM generator_costs g
CROSS JOIN (SELECT DISTINCT load_zone FROM system_load) z
WHERE g.technology NOT IN (SELECT proj_gen_tech FROM t_specific_projects);
-- merge the specific and generic projects
DROP TABLE IF EXISTS t_all_projects;
CREATE TEMPORARY TABLE t_all_projects AS
SELECT * FROM t_specific_projects UNION SELECT * from t_generic_projects;
-- collect extra data from the generator_costs table and filter out disallowed projects
SELECT
a."PROJECT",
null as proj_dbid,
a.proj_gen_tech,
a.proj_load_zone,
COALESCE(a.proj_connect_cost_per_mw, 1000.0*g.connect_cost_per_kw_generic, 0.0) AS proj_connect_cost_per_mw,
a.proj_capacity_limit_mw,
cast(null as float) AS proj_variable_om -- this is supplied in generator_info.tab for new projects
FROM t_all_projects a JOIN generator_costs g on g.technology=a.proj_gen_tech
WHERE a.proj_load_zone IN %(load_zones)s
AND g.min_vintage_year <= (SELECT MAX(period) FROM study_periods WHERE time_sample = %(time_sample)s)
AND g.technology NOT IN %(exclude_technologies)s
UNION
-- collect data on existing projects
SELECT DISTINCT
project_id AS "PROJECT",
null AS dbid,
technology AS proj_gen_tech,
load_zone AS proj_load_zone,
0.0 AS proj_connect_cost_per_mw,
cast(null as float) AS proj_capacity_limit_mw,
sum(CASE WHEN aer_fuel_code IN ('SUN', 'WND') THEN 0.0 ELSE variable_o_m END * 1000.0 * avg_mw)
/ sum(avg_mw) AS proj_variable_om
FROM existing_plants
WHERE load_zone IN %(load_zones)s
AND insvyear <= (SELECT MAX(period) FROM study_periods WHERE time_sample = %(time_sample)s)
AND technology NOT IN %(exclude_technologies)s
GROUP BY 1, 2, 3, 4, 5, 6
ORDER BY 4, 3, 1;
""", args)
write_table('proj_existing_builds.tab', """
SELECT project_id AS "PROJECT",
insvyear AS build_year,
sum(peak_mw) as proj_existing_cap
FROM existing_plants
WHERE load_zone in %(load_zones)s
AND insvyear <= (SELECT MAX(period) FROM study_periods WHERE time_sample = %(time_sample)s)
AND technology NOT IN %(exclude_technologies)s
GROUP BY 1, 2;
""", args)
# note: we have to put cost data for existing projects in proj_build_costs.tab
# because gen_new_build_costs only covers future investment periods.
# NOTE: these costs must be expressed per MW, not per kW
write_table('proj_build_costs.tab', """
SELECT project_id AS "PROJECT",
insvyear AS build_year,
sum(overnight_cost * 1000.0 * peak_mw) / sum(peak_mw) as proj_overnight_cost,
sum(fixed_o_m * 1000.0 * peak_mw) / sum(peak_mw) as proj_fixed_om
FROM existing_plants
WHERE load_zone in %(load_zones)s
AND insvyear <= (SELECT MAX(period) FROM study_periods WHERE time_sample = %(time_sample)s)
AND technology NOT IN %(exclude_technologies)s
GROUP BY 1, 2;
""", args)
#########################
# project.dispatch
# skip this step if the user specifies "skip_cf" in the arguments (to speed up execution)
if args.get("skip_cf", False):
print "SKIPPING variable_capacity_factors.tab"
else:
write_table('variable_capacity_factors.tab', """
SELECT
concat_ws('_', load_zone, technology, site, orientation) as "PROJECT",
study_hour as timepoint,
cap_factor as proj_max_capacity_factor
FROM generator_costs g JOIN cap_factor c USING (technology)
JOIN study_hour h using (date_time)
WHERE load_zone in %(load_zones)s and time_sample = %(time_sample)s
AND min_vintage_year <= (SELECT MAX(period) FROM study_periods WHERE time_sample = %(time_sample)s)
AND g.technology NOT IN %(exclude_technologies)s
UNION
SELECT
c.project_id as "PROJECT",
study_hour as timepoint,
cap_factor as proj_max_capacity_factor
FROM existing_plants p JOIN existing_plants_cap_factor c USING (project_id)
JOIN study_hour h USING (date_time)
WHERE h.date_time = c.date_time
AND c.load_zone in %(load_zones)s
AND h.time_sample = %(time_sample)s
AND insvyear <= (SELECT MAX(period) FROM study_periods WHERE time_sample = %(time_sample)s)
AND p.technology NOT IN %(exclude_technologies)s
ORDER BY 1, 2
""", args)
#########################
# project.discrete_build
# include this module, but it doesn't need any additional data.
#########################
# project.unitcommit.commit
# minimum commitment levels for existing projects
# TODO: set proj_max_commit_fraction based on maintenance outage schedules
# (needed for comparing switch marginal costs to FERC 715 data in 2007-08)
# TODO: eventually add code to only provide these values for the timepoints before
# each project retires (providing them after retirement will cause an error).
write_table('proj_commit_bounds_timeseries.tab', """
SELECT * FROM (
SELECT project_id as "PROJECT",
study_hour AS "TIMEPOINT",
case when %(enable_must_run)s = 1 and must_run = 1 then 1.0 else null end as proj_min_commit_fraction,
null as proj_max_commit_fraction,
null as proj_min_load_fraction
FROM existing_plants, study_hour
WHERE load_zone in %(load_zones)s
AND time_sample = %(time_sample)s
AND insvyear <= (SELECT MAX(period) FROM study_periods WHERE time_sample = %(time_sample)s)
AND technology NOT IN %(exclude_technologies)s
) AS the_data
WHERE proj_min_commit_fraction IS NOT NULL OR proj_max_commit_fraction IS NOT NULL OR proj_min_load_fraction IS NOT NULL;
""", args)
# TODO: get minimum loads for new and existing power plants and then activate the query below
# write_table('gen_unit_commit.tab', """
# SELECT
# technology AS generation_technology,
# min_load / unit_size AS g_min_load_fraction,
# null AS g_startup_fuel,
# null AS g_startup_om
# FROM generator_costs
# UNION SELECT DISTINCT
# technology AS generation_technology,
# sum(min_load) / sum(peak_mw) AS g_min_load_fraction,
# null AS g_startup_fuel,
# null AS g_startup_om
# FROM existing_plants
# WHERE load_zone in %(load_zones)s
# AND insvyear <= (SELECT MAX(period) FROM study_periods WHERE time_sample = %(time_sample)s)
# AND technology NOT IN %(exclude_technologies)s
# GROUP BY 1
# ORDER by 1;
# """, args)
#########################
# project.unitcommit.fuel_use
# TODO: heat rate curves for new projects
# TODO: heat rate curves for existing plants
#########################
# project.unitcommit.discrete
# include this module, but it doesn't need any additional data.
# TODO: write reserves code
# TODO: create data files showing reserve rules
#########################
# trans_build
# --- Not used ---
#
# write_table('trans_lines.tab', """
# SELECT load_area_start AS load_zone_start, load_area_end AS load_zone_end,
# tid, length_km AS transmission_length_km, efficiency AS transmission_efficiency,
# existing_mw_from AS existing_transmission_from,
# existing_mw_to AS existing_transmission_to
# FROM trans_line
# WHERE load_area_start IN %(load_zones)s OR load_area_end IN %(load_zones)s
# """, args)
#
#
#
#########################
# trans_dispatch
# --- Not used ---
#########################
# batteries
# TODO: put these data in a database and write a .tab file instead
write_dat_file(
'batteries.dat',
[k for k in args if k.startswith('battery_')],
args
)
#########################
# EV annual energy consumption
if args.get('ev_scen_id', None) is not None:
write_table('ev_energy.tab', """
SELECT load_zone as "LOAD_ZONE", period, ev_gwh AS ev_gwh_annual
FROM ev_adoption a JOIN study_periods p on a.year = p.period
WHERE load_zone in %(load_zones)s
AND time_sample = %(time_sample)s
AND ev_scen_id = %(ev_scen_id)s
""", args)
#########################
# pumped hydro
# TODO: put these data in a database with hydro_scen_id's and pull them from there
if "pumped_hydro_headers" in args:
write_tab_file(
'pumped_hydro.tab',
headers=args["pumped_hydro_headers"],
data=args["pumped_hydro_projects"],
arguments=args
)
# write_dat_file(
# 'pumped_hydro.dat',
# [k for k in args if k.startswith('pumped_hydro_')],
# args
# )
#########################
# hydrogen
# TODO: put these data in a database and write a .tab file instead
write_dat_file(
'hydrogen.dat',
[k for k in args if k.startswith('hydrogen_') or k.startswith('liquid_hydrogen_')],
args
)
# the two functions below could be used as the start of a system
# to write placeholder files for any files in the current scenario
# that match the base files. This could be used to avoid creating large
# files (variable_cap_factor.tab) for alternative scenarios that are
# otherwise very similar. i.e., placeholder .tab or .dat files could
# be written with just the line 'include ../variable_cap_factor.tab' or
# 'include ../financial.dat'.
def any_alt_args_in_list(args, l):
"""Report whether any arguments in the args list appear in the list l."""
for a in args.get('alt_args', {}):
if a in l:
return True
return False
def any_alt_args_in_query(args, query):
"""Report whether any arguments in the args list appear in the list l."""
for a in args.get('alt_args', {}):
if '%(' + a + ')s' in query:
return True
return False
def make_file_path(file, args):
"""Create any directories and subdirectories needed to store data in the specified file,
based on inputs_dir and inputs_subdir arguments. Return a pathname to the file."""
# extract extra path information from args (if available)
# and build a path to the specified file.
path = os.path.join(args.get('inputs_dir', ''), args.get('inputs_subdir', ''))
if path != '' and not os.path.exists(path):
os.makedirs(path)
path = os.path.join(path, file)
return path
con = None
def db_cursor():
global con
if con is None:
try:
pghost='redr.eng.hawaii.edu'
# note: the connection gets created when the module loads and never gets closed (until presumably python exits)
con = psycopg2.connect(database='switch', host=pghost) #, user='switch_user')
except psycopg2.OperationalError:
print dedent("""
############################################################################################
Error while connecting to switch database on postgres server {server}.
Please ensure that the PGUSER environment variable is set with your postgres username
and there is a line like "*:*:*:<user>:<password>" in ~/.pgpass (which should be chmod 0600)
or in %APPDATA%\postgresql\pgpass.conf (Windows).
See http://www.postgresql.org/docs/9.1/static/libpq-pgpass.html for more details.
############################################################################################
""".format(server=pghost))
raise
return con.cursor()
def write_dat_file(output_file, args_to_write, arguments):
""" write a simple .dat file with the arguments specified in args_to_write,
drawn from the arguments dictionary"""
if any(arg in arguments for arg in args_to_write):
output_file = make_file_path(output_file, arguments)
print "Writing {file} ...".format(file=output_file),
sys.stdout.flush() # display the part line to the user
start=time.time()
with open(output_file, 'w') as f:
f.writelines([
'param ' + name + ' := ' + str(arguments[name]) + ';\n'
for name in args_to_write if name in arguments
])
print "time taken: {dur:.2f}s".format(dur=time.time()-start)
def write_table(output_file, query, arguments):
output_file = make_file_path(output_file, arguments)
cur = db_cursor()
print "Writing {file} ...".format(file=output_file),
sys.stdout.flush() # display the part line to the user
start=time.time()
cur.execute(dedent(query), arguments)
with open(output_file, 'w') as f:
# write header row
writerow(f, [d[0] for d in cur.description])
# write the query results (cur is used as an iterator here to get all the rows one by one)
writerows(f, cur)
print "time taken: {dur:.2f}s".format(dur=time.time()-start)
def write_tab_file(output_file, headers, data, arguments={}):
"Write a tab file using the headers and data supplied."
output_file = make_file_path(output_file, arguments)
print "Writing {file} ...".format(file=output_file),
sys.stdout.flush() # display the part line to the user
start=time.time()
with open(output_file, 'w') as f:
writerow(f, headers)
writerows(f, data)
print "time taken: {dur:.2f}s".format(dur=time.time()-start)
def write_indexed_set_dat_file(output_file, set_name, query, arguments):
"""Write a .dat file defining an indexed set, based on the query provided.
Note: the query should produce a table with index values in all columns except
the last, and then set members for each index in the last column. (There should
be multiple rows with the same values in the index columns.)"""
output_file = make_file_path(output_file, arguments)
print "Writing {file} ...".format(file=output_file),
sys.stdout.flush() # display the part line to the user
start=time.time()
cur = db_cursor()
cur.execute(dedent(query), arguments)
# build a dictionary grouping all values (last column) according to their index keys (earlier columns)
data_dict = collections.defaultdict(list)
for r in cur:
# note: data_dict[(index vals)] is created as an empty list on first reference,
# then gets data from all matching rows appended to it
data_dict[tuple(r[:-1])].append(r[-1])
# .dat file format based on p. 161 of http://ampl.com/BOOK/CHAPTERS/12-data.pdf
with open(output_file, 'w') as f:
f.writelines([
'set {sn}[{idx}] := {items} ;\n'.format(
sn=set_name,
idx=', '.join(k),
items=' '.join(v))
for k, v in data_dict.iteritems()
])
print "time taken: {dur:.2f}s".format(dur=time.time()-start)
def stringify(val):
if val is None:
out = '.'
elif type(val) is str:
out = val.replace('"', '""')
if any(char in out for char in [' ', '\t', '"', "'"]):
out = '"' + out + '"'
else:
out = str(val)
return out
def writerow(f, row):
f.write('\t'.join(stringify(c) for c in row) + '\n')
def writerows(f, rows):
for r in rows:
writerow(f, r)
def tuple_dict(keys, vals):
"Create a tuple of dictionaries, one for each row in vals, using the specified keys."
return tuple(zip(keys, row) for row in vals)
|
apache-2.0
|
[
646,
900,
12,
984,
12,
5055,
12,
747,
199,
504,
13390,
492,
22622,
199,
646,
15492,
18,
199,
199,
3,
6944,
26,
3140,
402,
1808,
314,
2366,
7392,
7060,
12,
642,
5370,
14511,
6716,
370,
221,
199,
3,
570,
315,
314,
1134,
79,
573,
1275,
2902,
1475,
14,
961,
4440,
12187,
3382,
4362,
436,
314,
4465,
199,
3,
1004,
2059,
367,
314,
2656,
652,
365,
1255,
641,
14,
961,
1630,
314,
2569,
15547,
334,
2118,
304,
199,
3,
446,
982,
282,
574,
3509,
4270,
9344,
12,
2985,
664,
28584,
1146,
14,
199,
3,
446,
982,
282,
574,
3509,
282,
2849,
6313,
12,
5174,
503,
4601,
4528,
12,
314,
574,
7545,
27828,
315,
4270,
9344,
14,
221,
199,
3,
257,
334,
7443,
626,
1134,
79,
573,
3181,
1133,
2040,
18593,
334,
460,
16119,
7883,
9,
315,
2763,
2323,
4959,
199,
3,
446,
2973,
1338,
787,
6702,
370,
1275,
334,
1589,
1134,
79,
573,
15,
65,
2421,
4465,
367,
4124,
666,
9,
199,
3,
446,
1263,
1163,
1338,
787,
9329,
3032,
370,
620,
1252,
199,
199,
3,
6944,
26,
642,
1630,
440,
675,
314,
2366,
7392,
7060,
2952,
652,
3181,
1133,
2291,
314,
18593,
199,
3,
503,
2973,
5112,
1384,
11736,
3432,
14,
421,
199,
3,
6944,
26,
25600,
5385,
9314,
2849,
9344,
367,
8785,
3326,
12,
436,
19533,
406,
3351,
199,
3,
370,
642,
12,
880,
1006,
314,
9212,
5084,
1077,
675,
2849,
9344,
6818,
3326,
14,
199,
199,
3,
6944,
26,
2218,
63,
1224,
342,
911,
5847,
3957,
2973,
1338,
370,
22608,
221,
199,
3,
880,
1134,
79,
573,
911,
27159,
3062,
465,
4124,
666,
199,
199,
3,
6944,
26,
314,
1233,
5084,
4293,
506,
6326,
1655,
7809,
12,
325,
14,
71,
2020,
282,
769,
402,
199,
3,
1817,
1561,
436,
9212,
12,
1314,
787,
2066,
7686,
737,
314,
1284,
14,
199,
3,
11017,
626,
3955,
506,
12159,
424,
370,
3105,
12,
436,
3955,
78,
1133,
2040,
367,
1503,
394,
679,
221,
199,
3,
24258,
503,
3575,
1275,
4616,
1584,
334,
6777,
787,
1202,
367,
282,
9284,
2633,
9,
199,
199,
318,
2218,
63,
5987,
3682,
589,
304,
339,
21186,
272,
327,
900,
30832,
2286,
2218,
63,
1224,
360,
20441,
14,
2902,
297,
408,
267,
1663,
6247,
63,
1267,
465,
334,
288,
10468,
8892,
7240,
899,
27802,
1390,
8,
5191,
9,
275,
1748,
8,
5191,
9,
15324,
27299,
717,
1553,
1373,
13,
5191,
1402,
27,
5534,
2582,
275,
1329,
402,
7609,
2741,
717,
3089,
8,
1086,
63,
3467,
63,
475,
63,
5191,
9,
1182,
28046,
490,
22325,
899,
717,
1553,
3510,
13,
5191,
1402,
27,
2338,
1329,
402,
17399,
3382,
17382,
717,
334,
988,
8,
5191,
7216,
827,
8,
5191,
430,
1182,
334,
835,
8,
12926,
6247,
7216,
17,
9,
355,
7729,
465,
2582,
8892,
4442,
25932,
63,
602,
6038,
900,
63,
3271,
275,
2818,
521,
63,
3271,
9,
83,
267,
776,
267,
10468,
6247,
4319,
298,
568,
54,
1719,
4479,
63,
27081,
401,
355,
6247,
465,
6247,
63,
928,
12,
355,
6247,
435,
2582,
446,
413,
465,
6247,
63,
500,
288,
4442,
25932,
63,
20441,
12,
6247,
63,
1267,
288,
6038,
900,
63,
3271,
275,
2818,
521,
63,
3271,
9,
83,
288,
16044,
701,
413,
27,
272,
10327,
1249,
9,
339,
2218,
63,
1224,
360,
28551,
14,
2902,
297,
408,
267,
10468,
25932,
63,
602,
465,
298,
11342,
654,
540,
2563,
401,
6247,
465,
6714,
63,
5191,
12,
7205,
6714,
63,
5553,
63,
1618,
63,
683,
12,
6714,
63,
1507,
63,
30543,
12,
6714,
63,
3467,
63,
475,
63,
5191,
267,
4442,
25932,
63,
602,
267,
6038,
900,
63,
3271,
275,
2818,
521,
63,
3271,
9,
83,
267,
16044,
6515,
413,
27,
272,
10327,
1249,
9,
339,
2218,
63,
1224,
360,
521,
3438,
14,
2902,
297,
408,
267,
10468,
394,
14,
22851,
63,
5180,
465,
900,
1403,
63,
344,
12,
8892,
370,
63,
1560,
8,
602,
63,
521,
435,
334,
5191,
446,
5536,
8,
3403,
687,
1434,
63,
521,
430,
627,
6252,
283,
17,
5361,
297,
490,
283,
15703,
13,
3218,
13,
5745,
13,
10213,
1194,
26,
10709,
358,
465,
4913,
12,
355,
394,
14,
22851,
63,
602,
465,
900,
5602,
7205,
4442,
25932,
63,
5180,
394,
10593,
25932,
63,
602,
366,
32210,
334,
22851,
63,
602,
12,
900,
63,
3271,
9,
288,
6038,
394,
14,
521,
63,
3271,
275,
2818,
521,
63,
3271,
9,
83,
288,
16044,
6515,
6247,
12,
5536,
8,
1117,
89,
687,
1434,
395,
25932,
63,
5180,
27,
272,
10327,
1249,
9,
339,
21186,
272,
327,
2583,
290,
559,
2551,
339,
327,
642,
2951,
4440,
282,
6394,
570,
12,
440,
282,
1817,
334,
460,
314,
1338,
787,
440,
315,
282,
3050,
367,
3063,
9,
272,
2218,
63,
4616,
63,
493,
8,
267,
283,
2408,
290,
559,
2551,
14,
4616,
297,
267,
788,
1095,
63,
2408,
24409,
63,
3403,
297,
283,
18700,
63,
1866,
297,
283,
15446,
63,
1866,
995,
267,
1249,
272,
776,
339,
21186,
272,
327,
2248,
63,
13325,
339,
327,
5317,
26,
781,
2793,
1133,
5647,
314,
2569,
1504,
315,
642,
1015,
26,
272,
327,
634,
90,
63,
6336,
63,
8016,
14035,
12,
634,
90,
63,
67,
1259,
63,
5590,
63,
14595,
12,
634,
90,
63,
697,
344,
12,
5591,
327,
3411,
63,
1832,
63,
2076,
12,
2257,
63,
2076,
63,
1189,
1061,
63,
6336,
63,
529,
63,
14716,
272,
2218,
63,
1224,
360,
912,
63,
13325,
14,
2902,
297,
408,
267,
10468,
2248,
63,
2619,
465,
298,
7405,
63,
15353,
2,
267,
4442,
2248,
63,
2619,
4960,
6038,
2248,
63,
2619,
315,
2818,
912,
63,
13325,
9,
83,
272,
10327,
1249,
9,
339,
327,
6944,
26,
781,
2793,
1133,
5647,
634,
90,
63,
8556,
63,
3640,
14,
2902,
334,
3972,
4508,
1202,
701,
2257,
63,
2076,
14,
647,
9,
315,
642,
1015,
14,
339,
327,
664,
2656,
14404,
12,
17923,
687,
314,
32530,
17399,
370,
314,
1402,
17399,
272,
327,
5317,
26,
283,
2743,
7,
365,
282,
4252,
315,
25951,
12,
880,
781,
675,
4270,
13,
14005,
370,
4165,
314,
2763,
536,
272,
2218,
63,
1224,
360,
3640,
14,
2902,
297,
408,
267,
10468,
7205,
634,
14,
912,
63,
2619,
4319,
298,
7405,
63,
15353,
401,
7205,
25932,
63,
5180,
4319,
298,
4961,
7217,
401,
288
] |
[
900,
12,
984,
12,
5055,
12,
747,
199,
504,
13390,
492,
22622,
199,
646,
15492,
18,
199,
199,
3,
6944,
26,
3140,
402,
1808,
314,
2366,
7392,
7060,
12,
642,
5370,
14511,
6716,
370,
221,
199,
3,
570,
315,
314,
1134,
79,
573,
1275,
2902,
1475,
14,
961,
4440,
12187,
3382,
4362,
436,
314,
4465,
199,
3,
1004,
2059,
367,
314,
2656,
652,
365,
1255,
641,
14,
961,
1630,
314,
2569,
15547,
334,
2118,
304,
199,
3,
446,
982,
282,
574,
3509,
4270,
9344,
12,
2985,
664,
28584,
1146,
14,
199,
3,
446,
982,
282,
574,
3509,
282,
2849,
6313,
12,
5174,
503,
4601,
4528,
12,
314,
574,
7545,
27828,
315,
4270,
9344,
14,
221,
199,
3,
257,
334,
7443,
626,
1134,
79,
573,
3181,
1133,
2040,
18593,
334,
460,
16119,
7883,
9,
315,
2763,
2323,
4959,
199,
3,
446,
2973,
1338,
787,
6702,
370,
1275,
334,
1589,
1134,
79,
573,
15,
65,
2421,
4465,
367,
4124,
666,
9,
199,
3,
446,
1263,
1163,
1338,
787,
9329,
3032,
370,
620,
1252,
199,
199,
3,
6944,
26,
642,
1630,
440,
675,
314,
2366,
7392,
7060,
2952,
652,
3181,
1133,
2291,
314,
18593,
199,
3,
503,
2973,
5112,
1384,
11736,
3432,
14,
421,
199,
3,
6944,
26,
25600,
5385,
9314,
2849,
9344,
367,
8785,
3326,
12,
436,
19533,
406,
3351,
199,
3,
370,
642,
12,
880,
1006,
314,
9212,
5084,
1077,
675,
2849,
9344,
6818,
3326,
14,
199,
199,
3,
6944,
26,
2218,
63,
1224,
342,
911,
5847,
3957,
2973,
1338,
370,
22608,
221,
199,
3,
880,
1134,
79,
573,
911,
27159,
3062,
465,
4124,
666,
199,
199,
3,
6944,
26,
314,
1233,
5084,
4293,
506,
6326,
1655,
7809,
12,
325,
14,
71,
2020,
282,
769,
402,
199,
3,
1817,
1561,
436,
9212,
12,
1314,
787,
2066,
7686,
737,
314,
1284,
14,
199,
3,
11017,
626,
3955,
506,
12159,
424,
370,
3105,
12,
436,
3955,
78,
1133,
2040,
367,
1503,
394,
679,
221,
199,
3,
24258,
503,
3575,
1275,
4616,
1584,
334,
6777,
787,
1202,
367,
282,
9284,
2633,
9,
199,
199,
318,
2218,
63,
5987,
3682,
589,
304,
339,
21186,
272,
327,
900,
30832,
2286,
2218,
63,
1224,
360,
20441,
14,
2902,
297,
408,
267,
1663,
6247,
63,
1267,
465,
334,
288,
10468,
8892,
7240,
899,
27802,
1390,
8,
5191,
9,
275,
1748,
8,
5191,
9,
15324,
27299,
717,
1553,
1373,
13,
5191,
1402,
27,
5534,
2582,
275,
1329,
402,
7609,
2741,
717,
3089,
8,
1086,
63,
3467,
63,
475,
63,
5191,
9,
1182,
28046,
490,
22325,
899,
717,
1553,
3510,
13,
5191,
1402,
27,
2338,
1329,
402,
17399,
3382,
17382,
717,
334,
988,
8,
5191,
7216,
827,
8,
5191,
430,
1182,
334,
835,
8,
12926,
6247,
7216,
17,
9,
355,
7729,
465,
2582,
8892,
4442,
25932,
63,
602,
6038,
900,
63,
3271,
275,
2818,
521,
63,
3271,
9,
83,
267,
776,
267,
10468,
6247,
4319,
298,
568,
54,
1719,
4479,
63,
27081,
401,
355,
6247,
465,
6247,
63,
928,
12,
355,
6247,
435,
2582,
446,
413,
465,
6247,
63,
500,
288,
4442,
25932,
63,
20441,
12,
6247,
63,
1267,
288,
6038,
900,
63,
3271,
275,
2818,
521,
63,
3271,
9,
83,
288,
16044,
701,
413,
27,
272,
10327,
1249,
9,
339,
2218,
63,
1224,
360,
28551,
14,
2902,
297,
408,
267,
10468,
25932,
63,
602,
465,
298,
11342,
654,
540,
2563,
401,
6247,
465,
6714,
63,
5191,
12,
7205,
6714,
63,
5553,
63,
1618,
63,
683,
12,
6714,
63,
1507,
63,
30543,
12,
6714,
63,
3467,
63,
475,
63,
5191,
267,
4442,
25932,
63,
602,
267,
6038,
900,
63,
3271,
275,
2818,
521,
63,
3271,
9,
83,
267,
16044,
6515,
413,
27,
272,
10327,
1249,
9,
339,
2218,
63,
1224,
360,
521,
3438,
14,
2902,
297,
408,
267,
10468,
394,
14,
22851,
63,
5180,
465,
900,
1403,
63,
344,
12,
8892,
370,
63,
1560,
8,
602,
63,
521,
435,
334,
5191,
446,
5536,
8,
3403,
687,
1434,
63,
521,
430,
627,
6252,
283,
17,
5361,
297,
490,
283,
15703,
13,
3218,
13,
5745,
13,
10213,
1194,
26,
10709,
358,
465,
4913,
12,
355,
394,
14,
22851,
63,
602,
465,
900,
5602,
7205,
4442,
25932,
63,
5180,
394,
10593,
25932,
63,
602,
366,
32210,
334,
22851,
63,
602,
12,
900,
63,
3271,
9,
288,
6038,
394,
14,
521,
63,
3271,
275,
2818,
521,
63,
3271,
9,
83,
288,
16044,
6515,
6247,
12,
5536,
8,
1117,
89,
687,
1434,
395,
25932,
63,
5180,
27,
272,
10327,
1249,
9,
339,
21186,
272,
327,
2583,
290,
559,
2551,
339,
327,
642,
2951,
4440,
282,
6394,
570,
12,
440,
282,
1817,
334,
460,
314,
1338,
787,
440,
315,
282,
3050,
367,
3063,
9,
272,
2218,
63,
4616,
63,
493,
8,
267,
283,
2408,
290,
559,
2551,
14,
4616,
297,
267,
788,
1095,
63,
2408,
24409,
63,
3403,
297,
283,
18700,
63,
1866,
297,
283,
15446,
63,
1866,
995,
267,
1249,
272,
776,
339,
21186,
272,
327,
2248,
63,
13325,
339,
327,
5317,
26,
781,
2793,
1133,
5647,
314,
2569,
1504,
315,
642,
1015,
26,
272,
327,
634,
90,
63,
6336,
63,
8016,
14035,
12,
634,
90,
63,
67,
1259,
63,
5590,
63,
14595,
12,
634,
90,
63,
697,
344,
12,
5591,
327,
3411,
63,
1832,
63,
2076,
12,
2257,
63,
2076,
63,
1189,
1061,
63,
6336,
63,
529,
63,
14716,
272,
2218,
63,
1224,
360,
912,
63,
13325,
14,
2902,
297,
408,
267,
10468,
2248,
63,
2619,
465,
298,
7405,
63,
15353,
2,
267,
4442,
2248,
63,
2619,
4960,
6038,
2248,
63,
2619,
315,
2818,
912,
63,
13325,
9,
83,
272,
10327,
1249,
9,
339,
327,
6944,
26,
781,
2793,
1133,
5647,
634,
90,
63,
8556,
63,
3640,
14,
2902,
334,
3972,
4508,
1202,
701,
2257,
63,
2076,
14,
647,
9,
315,
642,
1015,
14,
339,
327,
664,
2656,
14404,
12,
17923,
687,
314,
32530,
17399,
370,
314,
1402,
17399,
272,
327,
5317,
26,
283,
2743,
7,
365,
282,
4252,
315,
25951,
12,
880,
781,
675,
4270,
13,
14005,
370,
4165,
314,
2763,
536,
272,
2218,
63,
1224,
360,
3640,
14,
2902,
297,
408,
267,
10468,
7205,
634,
14,
912,
63,
2619,
4319,
298,
7405,
63,
15353,
401,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
andmos/ansible
|
lib/ansible/modules/cloud/rackspace/rax_meta.py
|
102
|
4782
|
#!/usr/bin/python
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: rax_meta
short_description: Manipulate metadata for Rackspace Cloud Servers
description:
- Manipulate metadata for Rackspace Cloud Servers
version_added: 1.7
options:
address:
description:
- Server IP address to modify metadata for, will match any IP assigned to
the server
id:
description:
- Server ID to modify metadata for
name:
description:
- Server name to modify metadata for
meta:
description:
- A hash of metadata to associate with the instance
author: "Matt Martz (@sivel)"
extends_documentation_fragment: rackspace.openstack
'''
EXAMPLES = '''
- name: Set metadata for a server
hosts: all
gather_facts: False
tasks:
- name: Set metadata
local_action:
module: rax_meta
credentials: ~/.raxpub
name: "{{ inventory_hostname }}"
region: DFW
meta:
group: primary_group
groups:
- group_two
- group_three
app: my_app
- name: Clear metadata
local_action:
module: rax_meta
credentials: ~/.raxpub
name: "{{ inventory_hostname }}"
region: DFW
'''
import json
try:
import pyrax
HAS_PYRAX = True
except ImportError:
HAS_PYRAX = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.rax import rax_argument_spec, rax_required_together, setup_rax_module
from ansible.module_utils.six import string_types
def rax_meta(module, address, name, server_id, meta):
changed = False
cs = pyrax.cloudservers
if cs is None:
module.fail_json(msg='Failed to instantiate client. This '
'typically indicates an invalid region or an '
'incorrectly capitalized region name.')
search_opts = {}
if name:
search_opts = dict(name='^%s$' % name)
try:
servers = cs.servers.list(search_opts=search_opts)
except Exception as e:
module.fail_json(msg='%s' % e.message)
elif address:
servers = []
try:
for server in cs.servers.list():
for addresses in server.networks.values():
if address in addresses:
servers.append(server)
break
except Exception as e:
module.fail_json(msg='%s' % e.message)
elif server_id:
servers = []
try:
servers.append(cs.servers.get(server_id))
except Exception as e:
pass
if len(servers) > 1:
module.fail_json(msg='Multiple servers found matching provided '
'search parameters')
elif not servers:
module.fail_json(msg='Failed to find a server matching provided '
'search parameters')
# Normalize and ensure all metadata values are strings
for k, v in meta.items():
if isinstance(v, list):
meta[k] = ','.join(['%s' % i for i in v])
elif isinstance(v, dict):
meta[k] = json.dumps(v)
elif not isinstance(v, string_types):
meta[k] = '%s' % v
server = servers[0]
if server.metadata == meta:
changed = False
else:
changed = True
removed = set(server.metadata.keys()).difference(meta.keys())
cs.servers.delete_meta(server, list(removed))
cs.servers.set_meta(server, meta)
server.get()
module.exit_json(changed=changed, meta=server.metadata)
def main():
argument_spec = rax_argument_spec()
argument_spec.update(
dict(
address=dict(),
id=dict(),
name=dict(),
meta=dict(type='dict', default=dict()),
)
)
module = AnsibleModule(
argument_spec=argument_spec,
required_together=rax_required_together(),
mutually_exclusive=[['address', 'id', 'name']],
required_one_of=[['address', 'id', 'name']],
)
if not HAS_PYRAX:
module.fail_json(msg='pyrax is required for this module')
address = module.params.get('address')
server_id = module.params.get('id')
name = module.params.get('name')
meta = module.params.get('meta')
setup_rax_module(module, pyrax)
rax_meta(module, address, name, server_id, meta)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1898,
26,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
16937,
63,
2024,
199,
3612,
63,
1802,
26,
4688,
711,
5434,
3341,
367,
32679,
8142,
7146,
83,
199,
1802,
26,
1362,
446,
4688,
711,
5434,
3341,
367,
32679,
8142,
7146,
83,
199,
1023,
63,
3270,
26,
413,
14,
23,
199,
1419,
26,
523,
2287,
26,
272,
1369,
26,
489,
446,
7146,
3531,
2287,
370,
2811,
3341,
367,
12,
911,
1336,
1263,
3531,
7943,
370,
267,
314,
1654,
523,
1305,
26,
272,
1369,
26,
489,
446,
7146,
2870,
370,
2811,
3341,
367,
523,
536,
26,
272,
1369,
26,
489,
446,
7146,
536,
370,
2811,
3341,
367,
523,
3404,
26,
272,
1369,
26,
489,
446,
437,
2631,
402,
3341,
370,
20133,
543,
314,
1256,
199,
2502,
26,
298,
45,
6796,
603,
28124,
8593,
338,
1090,
2924,
199,
11036,
63,
9970,
63,
7677,
26,
660,
346,
2638,
14,
8512,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
2494,
3341,
367,
282,
1654,
523,
7057,
26,
1006,
523,
13082,
63,
5047,
26,
756,
523,
6527,
26,
272,
446,
536,
26,
2494,
3341,
489,
2257,
63,
1287,
26,
267,
859,
26,
16937,
63,
2024,
267,
6235,
26,
25975,
14495,
5645,
267,
536,
26,
7370,
8200,
63,
4269,
7820,
267,
4897,
26,
577,
19445,
267,
3404,
26,
881,
1572,
26,
5062,
63,
923,
881,
4652,
26,
288,
446,
1572,
63,
5601,
288,
446,
1572,
63,
10480,
881,
1145,
26,
3002,
63,
571,
339,
446,
536,
26,
14836,
3341,
489,
2257,
63,
1287,
26,
267,
859,
26,
16937,
63,
2024,
267,
6235,
26,
25975,
14495,
5645,
267,
536,
26,
7370,
8200,
63,
4269,
7820,
267,
4897,
26,
577,
19445,
199,
2344,
199,
199,
646,
2022,
199,
199,
893,
26,
272,
492,
23944,
272,
7509,
63,
4521,
2847,
56,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
4521,
2847,
56,
275,
756,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
14495,
492,
16937,
63,
2094,
63,
1650,
12,
16937,
63,
2427,
63,
6314,
12,
3272,
63,
14495,
63,
578,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
1059,
63,
1313,
421,
199,
318,
16937,
63,
2024,
8,
578,
12,
2287,
12,
536,
12,
1654,
63,
344,
12,
3404,
304,
272,
2896,
275,
756,
339,
7117,
275,
23944,
14,
4091,
5871,
339,
340,
7117,
365,
488,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
4276,
370,
17321,
1890,
14,
961,
283,
2490,
283,
32251,
9126,
376,
3866,
4897,
503,
376,
283,
2490,
283,
15448,
590,
17094,
1759,
4897,
536,
2659,
339,
2754,
63,
3291,
275,
1052,
272,
340,
536,
26,
267,
2754,
63,
3291,
275,
1211,
8,
354,
534,
62,
5,
83,
12913,
450,
536,
9,
267,
862,
26,
288,
8037,
275,
7117,
14,
5871,
14,
513,
8,
1733,
63,
3291,
29,
1733,
63,
3291,
9,
267,
871,
2186,
465,
325,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
9569,
83,
7,
450,
325,
14,
1188,
9,
272,
916,
2287,
26,
267,
8037,
275,
942,
267,
862,
26,
288,
367,
1654,
315,
7117,
14,
5871,
14,
513,
837,
355,
367,
7149,
315,
1654,
14,
7642,
14,
1459,
837,
490,
340,
2287,
315,
7149,
26,
717,
8037,
14,
740,
8,
1000,
9,
717,
2059,
267,
871,
2186,
465,
325,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
9569,
83,
7,
450,
325,
14,
1188,
9,
272,
916,
1654,
63,
344,
26,
267,
8037,
275,
942,
267,
862,
26,
288,
8037,
14,
740,
8,
1259,
14,
5871,
14,
362,
8,
1000,
63,
344,
430,
267,
871,
2186,
465,
325,
26,
288,
986,
339,
340,
822,
8,
5871,
9,
690,
413,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
8433,
8037,
1911,
4877,
2741,
283,
2490,
283,
1733,
2633,
358,
272,
916,
440,
8037,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
4276,
370,
2342,
282,
1654,
4877,
2741,
283,
2490,
283,
1733,
2633,
358,
339,
327,
21017,
436,
4868,
1006,
3341,
1338,
787,
3326,
272,
367,
1022,
12,
373,
315,
3404,
14,
1744,
837,
267,
340,
1228,
8,
86,
12,
769,
304,
288,
3404,
59,
75,
61,
275,
12814,
904,
26861,
83,
7,
450,
284,
367,
284,
315,
373,
566,
267,
916,
1228,
8,
86,
12,
1211,
304,
288,
3404,
59,
75,
61,
275,
2022,
14,
4180,
8,
86,
9,
267,
916,
440,
1228,
8,
86,
12,
1059,
63,
1313,
304,
288,
3404,
59,
75,
61,
275,
1543,
83,
7,
450,
373,
339,
1654,
275,
8037,
59,
16,
61,
272,
340,
1654,
14,
2343,
508,
3404,
26,
267,
2896,
275,
756,
272,
587,
26,
267,
2896,
275,
715,
267,
4829,
275,
663,
8,
1000,
14,
2343,
14,
1612,
8801,
9196,
8,
2024,
14,
1612,
1012,
267,
7117,
14,
5871,
14,
1807,
63,
2024,
8,
1000,
12,
769,
8,
10649,
430,
267,
7117,
14,
5871,
14,
409,
63,
2024,
8,
1000,
12,
3404,
9,
267,
1654,
14,
362,
342,
339,
859,
14,
2224,
63,
1001,
8,
2489,
29,
2489,
12,
3404,
29,
1000,
14,
2343,
9,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
16937,
63,
2094,
63,
1650,
342,
272,
1423,
63,
1650,
14,
873,
8,
267,
1211,
8,
288,
2287,
29,
807,
1062,
288,
1305,
29,
807,
1062,
288,
536,
29,
807,
1062,
288,
3404,
29,
807,
8,
466,
534,
807,
297,
849,
29,
807,
4000,
267,
776,
272,
776,
339,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
2094,
63,
1650,
12,
267,
1415,
63,
6314,
29,
14495,
63,
2427,
63,
6314,
1062,
267,
16108
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1898,
26,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
16937,
63,
2024,
199,
3612,
63,
1802,
26,
4688,
711,
5434,
3341,
367,
32679,
8142,
7146,
83,
199,
1802,
26,
1362,
446,
4688,
711,
5434,
3341,
367,
32679,
8142,
7146,
83,
199,
1023,
63,
3270,
26,
413,
14,
23,
199,
1419,
26,
523,
2287,
26,
272,
1369,
26,
489,
446,
7146,
3531,
2287,
370,
2811,
3341,
367,
12,
911,
1336,
1263,
3531,
7943,
370,
267,
314,
1654,
523,
1305,
26,
272,
1369,
26,
489,
446,
7146,
2870,
370,
2811,
3341,
367,
523,
536,
26,
272,
1369,
26,
489,
446,
7146,
536,
370,
2811,
3341,
367,
523,
3404,
26,
272,
1369,
26,
489,
446,
437,
2631,
402,
3341,
370,
20133,
543,
314,
1256,
199,
2502,
26,
298,
45,
6796,
603,
28124,
8593,
338,
1090,
2924,
199,
11036,
63,
9970,
63,
7677,
26,
660,
346,
2638,
14,
8512,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
2494,
3341,
367,
282,
1654,
523,
7057,
26,
1006,
523,
13082,
63,
5047,
26,
756,
523,
6527,
26,
272,
446,
536,
26,
2494,
3341,
489,
2257,
63,
1287,
26,
267,
859,
26,
16937,
63,
2024,
267,
6235,
26,
25975,
14495,
5645,
267,
536,
26,
7370,
8200,
63,
4269,
7820,
267,
4897,
26,
577,
19445,
267,
3404,
26,
881,
1572,
26,
5062,
63,
923,
881,
4652,
26,
288,
446,
1572,
63,
5601,
288,
446,
1572,
63,
10480,
881,
1145,
26,
3002,
63,
571,
339,
446,
536,
26,
14836,
3341,
489,
2257,
63,
1287,
26,
267,
859,
26,
16937,
63,
2024,
267,
6235,
26,
25975,
14495,
5645,
267,
536,
26,
7370,
8200,
63,
4269,
7820,
267,
4897,
26,
577,
19445,
199,
2344,
199,
199,
646,
2022,
199,
199,
893,
26,
272,
492,
23944,
272,
7509,
63,
4521,
2847,
56,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
4521,
2847,
56,
275,
756,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
14495,
492,
16937,
63,
2094,
63,
1650,
12,
16937,
63,
2427,
63,
6314,
12,
3272,
63,
14495,
63,
578,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
1059,
63,
1313,
421,
199,
318,
16937,
63,
2024,
8,
578,
12,
2287,
12,
536,
12,
1654,
63,
344,
12,
3404,
304,
272,
2896,
275,
756,
339,
7117,
275,
23944,
14,
4091,
5871,
339,
340,
7117,
365,
488,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
4276,
370,
17321,
1890,
14,
961,
283,
2490,
283,
32251,
9126,
376,
3866,
4897,
503,
376,
283,
2490,
283,
15448,
590,
17094,
1759,
4897,
536,
2659,
339,
2754,
63,
3291,
275,
1052,
272,
340,
536,
26,
267,
2754,
63,
3291,
275,
1211,
8,
354,
534,
62,
5,
83,
12913,
450,
536,
9,
267,
862,
26,
288,
8037,
275,
7117,
14,
5871,
14,
513,
8,
1733,
63,
3291,
29,
1733,
63,
3291,
9,
267,
871,
2186,
465,
325,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
9569,
83,
7,
450,
325,
14,
1188,
9,
272,
916,
2287,
26,
267,
8037,
275,
942,
267,
862,
26,
288,
367,
1654,
315,
7117,
14,
5871,
14,
513,
837,
355,
367,
7149,
315,
1654,
14,
7642,
14,
1459,
837,
490,
340,
2287,
315,
7149,
26,
717,
8037,
14,
740,
8,
1000,
9,
717,
2059,
267,
871,
2186,
465,
325,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
9569,
83,
7,
450,
325,
14,
1188,
9,
272,
916,
1654,
63,
344,
26,
267,
8037,
275,
942,
267,
862,
26,
288,
8037,
14,
740,
8,
1259,
14,
5871,
14,
362,
8,
1000,
63,
344,
430,
267,
871,
2186,
465,
325,
26,
288,
986,
339,
340,
822,
8,
5871,
9,
690,
413,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
8433,
8037,
1911,
4877,
2741,
283,
2490,
283,
1733,
2633,
358,
272,
916,
440,
8037,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
4276,
370,
2342,
282,
1654,
4877,
2741,
283,
2490,
283,
1733,
2633,
358,
339,
327,
21017,
436,
4868,
1006,
3341,
1338,
787,
3326,
272,
367,
1022,
12,
373,
315,
3404,
14,
1744,
837,
267,
340,
1228,
8,
86,
12,
769,
304,
288,
3404,
59,
75,
61,
275,
12814,
904,
26861,
83,
7,
450,
284,
367,
284,
315,
373,
566,
267,
916,
1228,
8,
86,
12,
1211,
304,
288,
3404,
59,
75,
61,
275,
2022,
14,
4180,
8,
86,
9,
267,
916,
440,
1228,
8,
86,
12,
1059,
63,
1313,
304,
288,
3404,
59,
75,
61,
275,
1543,
83,
7,
450,
373,
339,
1654,
275,
8037,
59,
16,
61,
272,
340,
1654,
14,
2343,
508,
3404,
26,
267,
2896,
275,
756,
272,
587,
26,
267,
2896,
275,
715,
267,
4829,
275,
663,
8,
1000,
14,
2343,
14,
1612,
8801,
9196,
8,
2024,
14,
1612,
1012,
267,
7117,
14,
5871,
14,
1807,
63,
2024,
8,
1000,
12,
769,
8,
10649,
430,
267,
7117,
14,
5871,
14,
409,
63,
2024,
8,
1000,
12,
3404,
9,
267,
1654,
14,
362,
342,
339,
859,
14,
2224,
63,
1001,
8,
2489,
29,
2489,
12,
3404,
29,
1000,
14,
2343,
9,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
16937,
63,
2094,
63,
1650,
342,
272,
1423,
63,
1650,
14,
873,
8,
267,
1211,
8,
288,
2287,
29,
807,
1062,
288,
1305,
29,
807,
1062,
288,
536,
29,
807,
1062,
288,
3404,
29,
807,
8,
466,
534,
807,
297,
849,
29,
807,
4000,
267,
776,
272,
776,
339,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
2094,
63,
1650,
12,
267,
1415,
63,
6314,
29,
14495,
63,
2427,
63,
6314,
1062,
267,
16108,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
suxinde2009/zulip
|
confirmation/models.py
|
116
|
4206
|
# -*- coding: utf-8 -*-
# Copyright: (c) 2008, Jarek Zgoda <jarek.zgoda@gmail.com>
__revision__ = '$Id: models.py 28 2009-10-22 15:03:02Z jarek.zgoda $'
import re
from django.db import models
from django.core.urlresolvers import reverse
from django.core.mail import send_mail
from django.conf import settings
from django.template import loader, Context
from django.contrib.sites.models import Site
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.utils.translation import ugettext_lazy as _
from django.utils.timezone import now
from confirmation.util import get_status_field
from zerver.lib.utils import generate_random_token
try:
import mailer
send_mail = mailer.send_mail
except ImportError:
# no mailer app present, stick with default
pass
B16_RE = re.compile('^[a-f0-9]{40}$')
def generate_key():
return generate_random_token(40)
def generate_activation_url(key):
return u'%s%s%s' % (settings.EXTERNAL_URI_SCHEME,
settings.EXTERNAL_HOST,
reverse('confirmation.views.confirm',
kwargs={'confirmation_key': key}))
class ConfirmationManager(models.Manager):
def confirm(self, confirmation_key):
if B16_RE.search(confirmation_key):
try:
confirmation = self.get(confirmation_key=confirmation_key)
except self.model.DoesNotExist:
return False
obj = confirmation.content_object
status_field = get_status_field(obj._meta.app_label, obj._meta.model_name)
setattr(obj, status_field, getattr(settings, 'STATUS_ACTIVE', 1))
obj.save()
return obj
return False
def get_link_for_object(self, obj):
key = generate_key()
self.create(content_object=obj, date_sent=now(), confirmation_key=key)
return generate_activation_url(key)
def send_confirmation(self, obj, email_address, additional_context=None,
subject_template_path=None, body_template_path=None):
confirmation_key = generate_key()
current_site = Site.objects.get_current()
activate_url = generate_activation_url(confirmation_key)
context = Context({
'activate_url': activate_url,
'current_site': current_site,
'confirmation_key': confirmation_key,
'target': obj,
'days': getattr(settings, 'EMAIL_CONFIRMATION_DAYS', 10),
})
if additional_context is not None:
context.update(additional_context)
templates = [
'confirmation/%s_confirmation_email_subject.txt' % obj._meta.model_name,
'confirmation/confirmation_email_subject.txt',
]
if subject_template_path:
template = loader.get_template(subject_template_path)
else:
template = loader.select_template(templates)
subject = template.render(context).strip().replace(u'\n', u' ') # no newlines, please
templates = [
'confirmation/%s_confirmation_email_body.txt' % obj._meta.model_name,
'confirmation/confirmation_email_body.txt',
]
if body_template_path:
template = loader.get_template(body_template_path)
else:
template = loader.select_template(templates)
body = template.render(context)
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [email_address])
return self.create(content_object=obj, date_sent=now(), confirmation_key=confirmation_key)
class Confirmation(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
date_sent = models.DateTimeField(_('sent'))
confirmation_key = models.CharField(_('activation key'), max_length=40)
objects = ConfirmationManager()
class Meta:
verbose_name = _('confirmation email')
verbose_name_plural = _('confirmation emails')
def __unicode__(self):
return _('confirmation email for %s') % self.content_object
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
26,
334,
67,
9,
9079,
12,
1603,
1530,
75,
3107,
71,
364,
65,
665,
74,
1530,
75,
14,
90,
71,
364,
65,
32,
6799,
14,
957,
30,
199,
199,
363,
5792,
363,
275,
4505,
1304,
26,
1709,
14,
647,
7294,
8937,
13,
709,
13,
1081,
4114,
26,
1644,
26,
996,
58,
1335,
1530,
75,
14,
90,
71,
364,
65,
2672,
7,
199,
199,
646,
295,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1018,
14,
1198,
492,
3222,
63,
1198,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1160,
492,
5077,
12,
9470,
199,
504,
1639,
14,
2828,
14,
8619,
14,
992,
492,
11666,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
504,
1639,
14,
2828,
14,
10778,
492,
7809,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
1208,
14,
7145,
492,
3063,
199,
199,
504,
18791,
14,
1974,
492,
664,
63,
1205,
63,
698,
199,
504,
19959,
14,
773,
14,
1208,
492,
3550,
63,
2355,
63,
1418,
199,
199,
893,
26,
272,
492,
610,
3566,
272,
3222,
63,
1198,
275,
610,
3566,
14,
2254,
63,
1198,
199,
2590,
3545,
26,
272,
327,
949,
610,
3566,
1145,
3451,
12,
29404,
543,
849,
272,
986,
421,
199,
34,
975,
63,
907,
275,
295,
14,
2014,
9097,
59,
65,
13,
70,
16,
13,
25,
8194,
2167,
93,
9988,
199,
199,
318,
3550,
63,
498,
837,
272,
372,
3550,
63,
2355,
63,
1418,
8,
2167,
9,
199,
199,
318,
3550,
63,
12312,
63,
633,
8,
498,
304,
272,
372,
399,
5956,
83,
5,
83,
5,
83,
7,
450,
334,
1751,
14,
21043,
63,
7639,
63,
30430,
12,
717,
2202,
14,
21043,
63,
5449,
12,
717,
3837,
360,
20903,
14,
4196,
14,
9548,
297,
1816,
2074,
3713,
20903,
63,
498,
356,
790,
12466,
421,
199,
533,
1448,
11701,
2988,
8,
992,
14,
2988,
304,
339,
347,
12679,
8,
277,
12,
18791,
63,
498,
304,
267,
340,
699,
975,
63,
907,
14,
1733,
8,
20903,
63,
498,
304,
288,
862,
26,
355,
18791,
275,
291,
14,
362,
8,
20903,
63,
498,
29,
20903,
63,
498,
9,
288,
871,
291,
14,
1238,
14,
7400,
26,
355,
372,
756,
288,
1559,
275,
18791,
14,
1317,
63,
785,
288,
2004,
63,
698,
275,
664,
63,
1205,
63,
698,
8,
1113,
423,
2024,
14,
571,
63,
1302,
12,
1559,
423,
2024,
14,
1238,
63,
354,
9,
288,
5371,
8,
1113,
12,
2004,
63,
698,
12,
2519,
8,
1751,
12,
283,
6305,
63,
10401,
297,
413,
430,
288,
1559,
14,
2117,
342,
288,
372,
1559,
267,
372,
756,
339,
347,
664,
63,
1073,
63,
509,
63,
785,
8,
277,
12,
1559,
304,
267,
790,
275,
3550,
63,
498,
342,
267,
291,
14,
981,
8,
1317,
63,
785,
29,
1113,
12,
1434,
63,
1150,
29,
2131,
1062,
18791,
63,
498,
29,
498,
9,
267,
372,
3550,
63,
12312,
63,
633,
8,
498,
9,
339,
347,
3222,
63,
20903,
8,
277,
12,
1559,
12,
3031,
63,
1562,
12,
4722,
63,
1100,
29,
403,
12,
288,
5420,
63,
1160,
63,
515,
29,
403,
12,
2396,
63,
1160,
63,
515,
29,
403,
304,
267,
18791,
63,
498,
275,
3550,
63,
498,
342,
267,
1453,
63,
2124,
275,
11666,
14,
1462,
14,
362,
63,
1818,
342,
267,
15422,
63,
633,
275,
3550,
63,
12312,
63,
633,
8,
20903,
63,
498,
9,
267,
1067,
275,
9470,
2561,
288,
283,
8222,
63,
633,
356,
15422,
63,
633,
12,
288,
283,
1818,
63,
2124,
356,
1453,
63,
2124,
12,
288,
283,
20903,
63,
498,
356,
18791,
63,
498,
12,
288,
283,
1375,
356,
1559,
12,
288,
283,
4899,
356,
2519,
8,
1751,
12,
283,
10089,
63,
1864,
28830,
2594,
63,
25683,
297,
1616,
395,
267,
3828,
267,
340,
4722,
63,
1100,
365,
440,
488,
26,
288,
1067,
14,
873,
8,
8460,
63,
1100,
9,
267,
7009,
275,
359,
288,
283,
20903,
3149,
83,
63,
20903,
63,
2123,
63,
5875,
14,
2424,
7,
450,
1559,
423,
2024,
14,
1238,
63,
354,
12,
288,
283,
20903,
15,
20903,
63,
2123,
63,
5875,
14,
2424,
297,
267,
1622,
267,
340,
5420,
63,
1160,
63,
515,
26,
288,
1978,
275,
5077,
14,
362,
63,
1160,
8,
5875,
63,
1160,
63,
515,
9,
267,
587,
26,
288,
1978,
275,
5077,
14,
2416,
63,
1160,
8,
5876,
9,
267,
5420,
275,
1978,
14,
3352,
8,
1100,
680,
1913,
1252,
1814,
8,
85,
1154,
78,
297,
399,
7,
5320,
327,
949,
14930,
12,
8749,
267,
7009,
275,
359,
288,
283,
20903,
3149,
83,
63,
20903,
63,
2123,
63,
2030,
14,
2424,
7,
450,
1559,
423,
2024,
14,
1238,
63,
354,
12,
288,
283,
20903,
15,
20903,
63,
2123,
63,
2030,
14,
2424,
297,
267,
1622,
267,
340,
2396,
63,
1160,
63,
515,
26,
288,
1978,
275,
5077,
14,
362,
63,
1160,
8,
2030,
63,
1160,
63,
515,
9,
267,
587,
26,
288,
1978,
275,
5077,
14,
2416,
63,
1160,
8,
5876,
9,
267,
2396,
275,
1978,
14,
3352,
8,
1100,
9,
267,
3222,
63,
1198,
8,
5875,
12,
2396,
12,
2202,
14,
3472,
63,
12491,
63,
10089,
12,
359,
2123,
63,
1562,
566,
267,
372,
291,
14,
981,
8,
1317,
63,
785,
29,
1113,
12,
1434,
63,
1150,
29,
2131,
1062,
18791,
63,
498,
29,
20903,
63,
498,
9,
421,
199,
533,
1448,
11701,
8,
992,
14,
1685,
304,
272,
1564,
63,
466,
275,
1709,
14,
3190,
8,
11282,
9,
272,
909,
63,
344,
275,
1709,
14,
8591,
342,
272,
1564,
63,
785,
275,
7809,
14,
9417,
3190,
360,
1317,
63,
466,
297,
283,
785,
63,
344,
358,
272,
1434,
63,
1150,
275,
1709,
14,
4626,
6723,
1150,
1333,
272,
18791,
63,
498,
275,
1709,
14,
2183,
6723,
12312,
790,
659,
1390,
63,
1267,
29,
2167,
9,
339,
2251,
275,
1448,
11701,
2988,
342,
339,
1021,
6288,
26,
267,
3376,
63,
354,
275,
4018,
20903,
3031,
358,
267,
3376,
63,
354,
63,
10019,
275,
4018,
20903,
14931,
358,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
4018
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
26,
334,
67,
9,
9079,
12,
1603,
1530,
75,
3107,
71,
364,
65,
665,
74,
1530,
75,
14,
90,
71,
364,
65,
32,
6799,
14,
957,
30,
199,
199,
363,
5792,
363,
275,
4505,
1304,
26,
1709,
14,
647,
7294,
8937,
13,
709,
13,
1081,
4114,
26,
1644,
26,
996,
58,
1335,
1530,
75,
14,
90,
71,
364,
65,
2672,
7,
199,
199,
646,
295,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1018,
14,
1198,
492,
3222,
63,
1198,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1160,
492,
5077,
12,
9470,
199,
504,
1639,
14,
2828,
14,
8619,
14,
992,
492,
11666,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
504,
1639,
14,
2828,
14,
10778,
492,
7809,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
1208,
14,
7145,
492,
3063,
199,
199,
504,
18791,
14,
1974,
492,
664,
63,
1205,
63,
698,
199,
504,
19959,
14,
773,
14,
1208,
492,
3550,
63,
2355,
63,
1418,
199,
199,
893,
26,
272,
492,
610,
3566,
272,
3222,
63,
1198,
275,
610,
3566,
14,
2254,
63,
1198,
199,
2590,
3545,
26,
272,
327,
949,
610,
3566,
1145,
3451,
12,
29404,
543,
849,
272,
986,
421,
199,
34,
975,
63,
907,
275,
295,
14,
2014,
9097,
59,
65,
13,
70,
16,
13,
25,
8194,
2167,
93,
9988,
199,
199,
318,
3550,
63,
498,
837,
272,
372,
3550,
63,
2355,
63,
1418,
8,
2167,
9,
199,
199,
318,
3550,
63,
12312,
63,
633,
8,
498,
304,
272,
372,
399,
5956,
83,
5,
83,
5,
83,
7,
450,
334,
1751,
14,
21043,
63,
7639,
63,
30430,
12,
717,
2202,
14,
21043,
63,
5449,
12,
717,
3837,
360,
20903,
14,
4196,
14,
9548,
297,
1816,
2074,
3713,
20903,
63,
498,
356,
790,
12466,
421,
199,
533,
1448,
11701,
2988,
8,
992,
14,
2988,
304,
339,
347,
12679,
8,
277,
12,
18791,
63,
498,
304,
267,
340,
699,
975,
63,
907,
14,
1733,
8,
20903,
63,
498,
304,
288,
862,
26,
355,
18791,
275,
291,
14,
362,
8,
20903,
63,
498,
29,
20903,
63,
498,
9,
288,
871,
291,
14,
1238,
14,
7400,
26,
355,
372,
756,
288,
1559,
275,
18791,
14,
1317,
63,
785,
288,
2004,
63,
698,
275,
664,
63,
1205,
63,
698,
8,
1113,
423,
2024,
14,
571,
63,
1302,
12,
1559,
423,
2024,
14,
1238,
63,
354,
9,
288,
5371,
8,
1113,
12,
2004,
63,
698,
12,
2519,
8,
1751,
12,
283,
6305,
63,
10401,
297,
413,
430,
288,
1559,
14,
2117,
342,
288,
372,
1559,
267,
372,
756,
339,
347,
664,
63,
1073,
63,
509,
63,
785,
8,
277,
12,
1559,
304,
267,
790,
275,
3550,
63,
498,
342,
267,
291,
14,
981,
8,
1317,
63,
785,
29,
1113,
12,
1434,
63,
1150,
29,
2131,
1062,
18791,
63,
498,
29,
498,
9,
267,
372,
3550,
63,
12312,
63,
633,
8,
498,
9,
339,
347,
3222,
63,
20903,
8,
277,
12,
1559,
12,
3031,
63,
1562,
12,
4722,
63,
1100,
29,
403,
12,
288,
5420,
63,
1160,
63,
515,
29,
403,
12,
2396,
63,
1160,
63,
515,
29,
403,
304,
267,
18791,
63,
498,
275,
3550,
63,
498,
342,
267,
1453,
63,
2124,
275,
11666,
14,
1462,
14,
362,
63,
1818,
342,
267,
15422,
63,
633,
275,
3550,
63,
12312,
63,
633,
8,
20903,
63,
498,
9,
267,
1067,
275,
9470,
2561,
288,
283,
8222,
63,
633,
356,
15422,
63,
633,
12,
288,
283,
1818,
63,
2124,
356,
1453,
63,
2124,
12,
288,
283,
20903,
63,
498,
356,
18791,
63,
498,
12,
288,
283,
1375,
356,
1559,
12,
288,
283,
4899,
356,
2519,
8,
1751,
12,
283,
10089,
63,
1864,
28830,
2594,
63,
25683,
297,
1616,
395,
267,
3828,
267,
340,
4722,
63,
1100,
365,
440,
488,
26,
288,
1067,
14,
873,
8,
8460,
63,
1100,
9,
267,
7009,
275,
359,
288,
283,
20903,
3149,
83,
63,
20903,
63,
2123,
63,
5875,
14,
2424,
7,
450,
1559,
423,
2024,
14,
1238,
63,
354,
12,
288,
283,
20903,
15,
20903,
63,
2123,
63,
5875,
14,
2424,
297,
267,
1622,
267,
340,
5420,
63,
1160,
63,
515,
26,
288,
1978,
275,
5077,
14,
362,
63,
1160,
8,
5875,
63,
1160,
63,
515,
9,
267,
587,
26,
288,
1978,
275,
5077,
14,
2416,
63,
1160,
8,
5876,
9,
267,
5420,
275,
1978,
14,
3352,
8,
1100,
680,
1913,
1252,
1814,
8,
85,
1154,
78,
297,
399,
7,
5320,
327,
949,
14930,
12,
8749,
267,
7009,
275,
359,
288,
283,
20903,
3149,
83,
63,
20903,
63,
2123,
63,
2030,
14,
2424,
7,
450,
1559,
423,
2024,
14,
1238,
63,
354,
12,
288,
283,
20903,
15,
20903,
63,
2123,
63,
2030,
14,
2424,
297,
267,
1622,
267,
340,
2396,
63,
1160,
63,
515,
26,
288,
1978,
275,
5077,
14,
362,
63,
1160,
8,
2030,
63,
1160,
63,
515,
9,
267,
587,
26,
288,
1978,
275,
5077,
14,
2416,
63,
1160,
8,
5876,
9,
267,
2396,
275,
1978,
14,
3352,
8,
1100,
9,
267,
3222,
63,
1198,
8,
5875,
12,
2396,
12,
2202,
14,
3472,
63,
12491,
63,
10089,
12,
359,
2123,
63,
1562,
566,
267,
372,
291,
14,
981,
8,
1317,
63,
785,
29,
1113,
12,
1434,
63,
1150,
29,
2131,
1062,
18791,
63,
498,
29,
20903,
63,
498,
9,
421,
199,
533,
1448,
11701,
8,
992,
14,
1685,
304,
272,
1564,
63,
466,
275,
1709,
14,
3190,
8,
11282,
9,
272,
909,
63,
344,
275,
1709,
14,
8591,
342,
272,
1564,
63,
785,
275,
7809,
14,
9417,
3190,
360,
1317,
63,
466,
297,
283,
785,
63,
344,
358,
272,
1434,
63,
1150,
275,
1709,
14,
4626,
6723,
1150,
1333,
272,
18791,
63,
498,
275,
1709,
14,
2183,
6723,
12312,
790,
659,
1390,
63,
1267,
29,
2167,
9,
339,
2251,
275,
1448,
11701,
2988,
342,
339,
1021,
6288,
26,
267,
3376,
63,
354,
275,
4018,
20903,
3031,
358,
267,
3376,
63,
354,
63,
10019,
275,
4018,
20903,
14931,
358,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
4018,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
gangadhar-kadam/laganfrappe
|
frappe/website/permissions.py
|
28
|
2434
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
from __future__ import unicode_literals
import frappe
def remove_empty_permissions():
permissions_cache_to_be_cleared = frappe.db.sql_list("""select distinct user
from `tabWebsite Route Permission`
where ifnull(`read`, 0)=0 and ifnull(`write`, 0)=0 and ifnull(`admin`, 0)=0""")
frappe.db.sql("""delete from `tabWebsite Route Permission`
where ifnull(`read`, 0)=0 and ifnull(`write`, 0)=0 and ifnull(`admin`, 0)=0""")
clear_permissions(permissions_cache_to_be_cleared)
def get_access(doc, pathname, user=None):
user = user or frappe.session.user
key = "website_route_permissions:{}".format(user)
cache = frappe.cache()
permissions = cache.get_value(key) or {}
if not permissions.get(doc.name):
permissions[doc.name] = _get_access(doc, pathname, user)
cache.set_value(key, permissions)
return permissions.get(doc.name)
def _get_access(doc, pathname, user):
read = write = admin = private_read = 0
if user == "Guest":
return { "read": doc.public_read, "write": 0, "admin": 0 }
if doc.public_write:
read = write = 1
elif doc.public_read:
read = 1
for perm in frappe.db.sql("""select
`tabWebsite Route Permission`.`read`,
`tabWebsite Route Permission`.`write`,
`tabWebsite Route Permission`.`admin`,
`tabWebsite Group`.lft,
`tabWebsite Group`.rgt
from
`tabWebsite Route Permission`, `tabWebsite Group`
where
`tabWebsite Route Permission`.website_route = %s and
`tabWebsite Route Permission`.user = %s and
`tabWebsite Route Permission`.reference = `tabWebsite Group`.name
order by `tabWebsite Group`.lft asc""", (user, pathname), as_dict=True):
if perm.lft <= doc.lft and perm.rgt >= doc.rgt:
if not (doc.public_read or private_read):
private_read = perm.read
if not read: read = perm.read
if not write: write = perm.write
if not admin: admin = perm.admin
if write: read = write
if read and write and admin:
break
else:
read = write = admin = private_read = 1
return { "read": read, "write": write, "admin": admin, "private_read": private_read }
def clear_permissions(users=None):
if isinstance(users, basestring):
users = [users]
elif users is None:
users = frappe.db.sql_list("""select name from `tabUser`""")
cache = frappe.cache()
for user in users:
cache.delete_value("website_route_permissions:{}".format(user))
|
mit
|
[
3,
1898,
334,
67,
9,
6171,
12,
6001,
8144,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
10697,
844,
14,
1666,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
199,
318,
2813,
63,
1667,
63,
6060,
837,
199,
198,
6060,
63,
1637,
63,
475,
63,
1235,
63,
2265,
2899,
275,
6950,
14,
697,
14,
3009,
63,
513,
4852,
2416,
15392,
922,
507,
198,
504,
658,
2902,
26354,
24244,
8779,
64,
507,
198,
4509,
340,
2307,
8,
64,
739,
3559,
378,
23397,
16,
436,
340,
2307,
8,
64,
952,
3559,
378,
23397,
16,
436,
340,
2307,
8,
64,
2113,
3559,
378,
23397,
16,
6141,
421,
198,
9098,
14,
697,
14,
3009,
4852,
1807,
687,
658,
2902,
26354,
24244,
8779,
64,
507,
198,
4509,
340,
2307,
8,
64,
739,
3559,
378,
23397,
16,
436,
340,
2307,
8,
64,
952,
3559,
378,
23397,
16,
436,
340,
2307,
8,
64,
2113,
3559,
378,
23397,
16,
6141,
421,
198,
3584,
63,
6060,
8,
6060,
63,
1637,
63,
475,
63,
1235,
63,
2265,
2899,
9,
199,
199,
318,
664,
63,
2732,
8,
1301,
12,
11776,
12,
922,
29,
403,
304,
199,
198,
751,
275,
922,
503,
6950,
14,
1730,
14,
751,
199,
198,
498,
275,
298,
7360,
63,
4449,
63,
6060,
26,
13536,
908,
8,
751,
9,
421,
198,
1637,
275,
6950,
14,
1637,
342,
199,
198,
6060,
275,
2581,
14,
362,
63,
585,
8,
498,
9,
503,
1052,
199,
198,
692,
440,
3443,
14,
362,
8,
1301,
14,
354,
304,
507,
198,
6060,
59,
1301,
14,
354,
61,
275,
485,
362,
63,
2732,
8,
1301,
12,
11776,
12,
922,
9,
507,
198,
1637,
14,
409,
63,
585,
8,
498,
12,
3443,
9,
421,
198,
1107,
3443,
14,
362,
8,
1301,
14,
354,
9,
199,
199,
318,
485,
362,
63,
2732,
8,
1301,
12,
11776,
12,
922,
304,
199,
198,
739,
275,
2218,
275,
4628,
275,
5726,
63,
739,
275,
378,
421,
198,
692,
922,
508,
298,
16022,
582,
507,
198,
1107,
469,
298,
739,
582,
1382,
14,
3455,
63,
739,
12,
298,
952,
582,
378,
12,
298,
2113,
582,
378,
789,
421,
198,
692,
1382,
14,
3455,
63,
952,
26,
507,
198,
739,
275,
2218,
275,
413,
199,
198,
4164,
1382,
14,
3455,
63,
739,
26,
507,
198,
739,
275,
413,
421,
198,
509,
10869,
315,
6950,
14,
697,
14,
3009,
4852,
2416,
686,
198,
64,
2902,
26354,
24244,
8779,
2313,
64,
739,
3559,
686,
198,
64,
2902,
26354,
24244,
8779,
2313,
64,
952,
3559,
686,
198,
64,
2902,
26354,
24244,
8779,
2313,
64,
2113,
3559,
686,
198,
64,
2902,
26354,
5611,
2313,
32462,
12,
686,
198,
64,
2902,
26354,
5611,
2313,
82,
3308,
507,
198,
504,
686,
198,
64,
2902,
26354,
24244,
8779,
3559,
658,
2902,
26354,
5611,
64,
507,
198,
4509,
686,
198,
64,
2902,
26354,
24244,
8779,
2313,
7360,
63,
4449,
275,
450,
83,
436,
686,
198,
64,
2902,
26354,
24244,
8779,
2313,
751,
275,
450,
83,
436,
686,
198,
64,
2902,
26354,
24244,
8779,
2313,
4443,
275,
658,
2902,
26354,
5611,
2313,
354,
507,
198,
1648,
701,
658,
2902,
26354,
5611,
2313,
32462,
16635,
7208,
334,
751,
12,
11776,
395,
465,
63,
807,
29,
549,
304,
507,
198,
692,
10869,
14,
32462,
2695,
1382,
14,
32462,
436,
10869,
14,
82,
3308,
2356,
1382,
14,
82,
3308,
26,
686,
198,
692,
440,
334,
1301,
14,
3455,
63,
739,
503,
5726,
63,
739,
304,
1585,
198,
4239,
63,
739,
275,
10869,
14,
739,
686,
198,
692,
440,
1586,
26,
1586,
275,
10869,
14,
739,
686,
198,
692,
440,
2218,
26,
2218,
275,
10869,
14,
952,
686,
198,
692,
440,
4628,
26,
4628,
275,
10869,
14,
2113,
686,
198,
692,
2218,
26,
1586,
275,
2218,
2742,
198,
692,
1586,
436,
2218,
436,
4628,
26,
686,
198,
4785,
421,
198,
2836,
26,
507,
198,
739,
275,
2218,
275,
4628,
275,
5726,
63,
739,
275,
413,
421,
198,
1107,
469,
298,
739,
582,
1586,
12,
298,
952,
582,
2218,
12,
298,
2113,
582,
4628,
12,
298,
4239,
63,
739,
582,
5726,
63,
739,
789,
199,
199,
318,
5436,
63,
6060,
8,
3707,
29,
403,
304,
199,
198,
692,
1228,
8,
3707,
12,
7116,
304,
507,
198,
3707,
275,
359,
3707,
61,
199,
198,
4164,
4390,
365,
488,
26,
507,
198,
3707,
275,
6950,
14,
697,
14,
3009,
63,
513,
4852,
2416,
536,
687,
658,
2902,
1899,
64,
6141,
421,
198,
1637,
275,
6950,
14,
1637,
342,
199,
198,
509,
922,
315,
4390,
26,
507,
198,
1637,
14,
1807,
63,
585,
480,
7360,
63,
4449,
63,
6060,
26,
13536,
908,
8,
751,
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
] |
[
1898,
334,
67,
9,
6171,
12,
6001,
8144,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
10697,
844,
14,
1666,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
199,
318,
2813,
63,
1667,
63,
6060,
837,
199,
198,
6060,
63,
1637,
63,
475,
63,
1235,
63,
2265,
2899,
275,
6950,
14,
697,
14,
3009,
63,
513,
4852,
2416,
15392,
922,
507,
198,
504,
658,
2902,
26354,
24244,
8779,
64,
507,
198,
4509,
340,
2307,
8,
64,
739,
3559,
378,
23397,
16,
436,
340,
2307,
8,
64,
952,
3559,
378,
23397,
16,
436,
340,
2307,
8,
64,
2113,
3559,
378,
23397,
16,
6141,
421,
198,
9098,
14,
697,
14,
3009,
4852,
1807,
687,
658,
2902,
26354,
24244,
8779,
64,
507,
198,
4509,
340,
2307,
8,
64,
739,
3559,
378,
23397,
16,
436,
340,
2307,
8,
64,
952,
3559,
378,
23397,
16,
436,
340,
2307,
8,
64,
2113,
3559,
378,
23397,
16,
6141,
421,
198,
3584,
63,
6060,
8,
6060,
63,
1637,
63,
475,
63,
1235,
63,
2265,
2899,
9,
199,
199,
318,
664,
63,
2732,
8,
1301,
12,
11776,
12,
922,
29,
403,
304,
199,
198,
751,
275,
922,
503,
6950,
14,
1730,
14,
751,
199,
198,
498,
275,
298,
7360,
63,
4449,
63,
6060,
26,
13536,
908,
8,
751,
9,
421,
198,
1637,
275,
6950,
14,
1637,
342,
199,
198,
6060,
275,
2581,
14,
362,
63,
585,
8,
498,
9,
503,
1052,
199,
198,
692,
440,
3443,
14,
362,
8,
1301,
14,
354,
304,
507,
198,
6060,
59,
1301,
14,
354,
61,
275,
485,
362,
63,
2732,
8,
1301,
12,
11776,
12,
922,
9,
507,
198,
1637,
14,
409,
63,
585,
8,
498,
12,
3443,
9,
421,
198,
1107,
3443,
14,
362,
8,
1301,
14,
354,
9,
199,
199,
318,
485,
362,
63,
2732,
8,
1301,
12,
11776,
12,
922,
304,
199,
198,
739,
275,
2218,
275,
4628,
275,
5726,
63,
739,
275,
378,
421,
198,
692,
922,
508,
298,
16022,
582,
507,
198,
1107,
469,
298,
739,
582,
1382,
14,
3455,
63,
739,
12,
298,
952,
582,
378,
12,
298,
2113,
582,
378,
789,
421,
198,
692,
1382,
14,
3455,
63,
952,
26,
507,
198,
739,
275,
2218,
275,
413,
199,
198,
4164,
1382,
14,
3455,
63,
739,
26,
507,
198,
739,
275,
413,
421,
198,
509,
10869,
315,
6950,
14,
697,
14,
3009,
4852,
2416,
686,
198,
64,
2902,
26354,
24244,
8779,
2313,
64,
739,
3559,
686,
198,
64,
2902,
26354,
24244,
8779,
2313,
64,
952,
3559,
686,
198,
64,
2902,
26354,
24244,
8779,
2313,
64,
2113,
3559,
686,
198,
64,
2902,
26354,
5611,
2313,
32462,
12,
686,
198,
64,
2902,
26354,
5611,
2313,
82,
3308,
507,
198,
504,
686,
198,
64,
2902,
26354,
24244,
8779,
3559,
658,
2902,
26354,
5611,
64,
507,
198,
4509,
686,
198,
64,
2902,
26354,
24244,
8779,
2313,
7360,
63,
4449,
275,
450,
83,
436,
686,
198,
64,
2902,
26354,
24244,
8779,
2313,
751,
275,
450,
83,
436,
686,
198,
64,
2902,
26354,
24244,
8779,
2313,
4443,
275,
658,
2902,
26354,
5611,
2313,
354,
507,
198,
1648,
701,
658,
2902,
26354,
5611,
2313,
32462,
16635,
7208,
334,
751,
12,
11776,
395,
465,
63,
807,
29,
549,
304,
507,
198,
692,
10869,
14,
32462,
2695,
1382,
14,
32462,
436,
10869,
14,
82,
3308,
2356,
1382,
14,
82,
3308,
26,
686,
198,
692,
440,
334,
1301,
14,
3455,
63,
739,
503,
5726,
63,
739,
304,
1585,
198,
4239,
63,
739,
275,
10869,
14,
739,
686,
198,
692,
440,
1586,
26,
1586,
275,
10869,
14,
739,
686,
198,
692,
440,
2218,
26,
2218,
275,
10869,
14,
952,
686,
198,
692,
440,
4628,
26,
4628,
275,
10869,
14,
2113,
686,
198,
692,
2218,
26,
1586,
275,
2218,
2742,
198,
692,
1586,
436,
2218,
436,
4628,
26,
686,
198,
4785,
421,
198,
2836,
26,
507,
198,
739,
275,
2218,
275,
4628,
275,
5726,
63,
739,
275,
413,
421,
198,
1107,
469,
298,
739,
582,
1586,
12,
298,
952,
582,
2218,
12,
298,
2113,
582,
4628,
12,
298,
4239,
63,
739,
582,
5726,
63,
739,
789,
199,
199,
318,
5436,
63,
6060,
8,
3707,
29,
403,
304,
199,
198,
692,
1228,
8,
3707,
12,
7116,
304,
507,
198,
3707,
275,
359,
3707,
61,
199,
198,
4164,
4390,
365,
488,
26,
507,
198,
3707,
275,
6950,
14,
697,
14,
3009,
63,
513,
4852,
2416,
536,
687,
658,
2902,
1899,
64,
6141,
421,
198,
1637,
275,
6950,
14,
1637,
342,
199,
198,
509,
922,
315,
4390,
26,
507,
198,
1637,
14,
1807,
63,
585,
480,
7360,
63,
4449,
63,
6060,
26,
13536,
908,
8,
751,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
h3llrais3r/Auto-Subliminal
|
lib/babelfish/data/get_files.py
|
68
|
1554
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2013 the BabelFish authors. All rights reserved.
# Use of this source code is governed by the 3-clause BSD license
# that can be found in the LICENSE file.
#
from __future__ import unicode_literals
import os.path
import tempfile
import zipfile
import requests
DATA_DIR = os.path.dirname(__file__)
# iso-3166-1.txt
print('Downloading ISO-3166-1 standard (ISO country codes)...')
with open(os.path.join(DATA_DIR, 'iso-3166-1.txt'), 'w') as f:
r = requests.get('http://www.iso.org/iso/home/standards/country_codes/country_names_and_code_elements_txt.htm')
f.write(r.content.strip())
# iso-639-3.tab
print('Downloading ISO-639-3 standard (ISO language codes)...')
with tempfile.TemporaryFile() as f:
r = requests.get('http://www-01.sil.org/iso639-3/iso-639-3_Code_Tables_20130531.zip')
f.write(r.content)
with zipfile.ZipFile(f) as z:
z.extract('iso-639-3.tab', DATA_DIR)
# iso-15924
print('Downloading ISO-15924 standard (ISO script codes)...')
with tempfile.TemporaryFile() as f:
r = requests.get('http://www.unicode.org/iso15924/iso15924.txt.zip')
f.write(r.content)
with zipfile.ZipFile(f) as z:
z.extract('iso15924-utf8-20131012.txt', DATA_DIR)
# opensubtitles supported languages
print('Downloading OpenSubtitles supported languages...')
with open(os.path.join(DATA_DIR, 'opensubtitles_languages.txt'), 'w') as f:
r = requests.get('http://www.opensubtitles.org/addons/export_languages.php')
f.write(r.content)
print('Done!')
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
6171,
314,
699,
902,
38,
2453,
11462,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
314,
650,
13,
8501,
6289,
4190,
199,
3,
626,
883,
506,
1911,
315,
314,
5113,
570,
14,
199,
3,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
747,
14,
515,
199,
646,
5549,
199,
646,
10392,
199,
646,
4145,
421,
199,
3998,
63,
3022,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
199,
3,
11601,
13,
19,
10642,
13,
17,
14,
2424,
199,
1361,
360,
18085,
9055,
13,
19,
10642,
13,
17,
4465,
334,
7336,
9023,
9479,
680,
703,
358,
199,
1045,
1551,
8,
736,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
283,
4595,
13,
19,
10642,
13,
17,
14,
2424,
659,
283,
87,
358,
465,
289,
26,
272,
519,
275,
4145,
14,
362,
360,
1014,
921,
1544,
14,
4595,
14,
1308,
15,
4595,
15,
4219,
15,
7935,
5596,
15,
6063,
63,
6021,
15,
6063,
63,
1247,
63,
460,
63,
600,
63,
5527,
63,
2424,
14,
15575,
358,
272,
289,
14,
952,
8,
82,
14,
1317,
14,
1913,
1012,
199,
199,
3,
11601,
13,
26723,
13,
19,
14,
2902,
199,
1361,
360,
18085,
9055,
13,
26723,
13,
19,
4465,
334,
7336,
2637,
9479,
680,
703,
358,
199,
1045,
5549,
14,
13271,
342,
465,
289,
26,
272,
519,
275,
4145,
14,
362,
360,
1014,
921,
1544,
13,
614,
14,
20329,
14,
1308,
15,
4595,
26723,
13,
19,
15,
4595,
13,
26723,
13,
19,
63,
3034,
63,
18845,
63,
1797,
11565,
2192,
14,
3065,
358,
272,
289,
14,
952,
8,
82,
14,
1317,
9,
272,
543,
10392,
14,
15016,
8,
70,
9,
465,
1315,
26,
267,
1315,
14,
5005,
360,
4595,
13,
26723,
13,
19,
14,
2902,
297,
7126,
63,
3022,
9,
199,
199,
3,
11601,
13,
9327,
1194,
199,
1361,
360,
18085,
9055,
13,
9327,
1194,
4465,
334,
7336,
2884,
9479,
680,
703,
358,
199,
1045,
5549,
14,
13271,
342,
465,
289,
26,
272,
519,
275,
4145,
14,
362,
360,
1014,
921,
1544,
14,
2975,
14,
1308,
15,
4595,
9327,
1194,
15,
4595,
9327,
1194,
14,
2424,
14,
3065,
358,
272,
289,
14,
952,
8,
82,
14,
1317,
9,
272,
543,
10392,
14,
15016,
8,
70,
9,
465,
1315,
26,
267,
1315,
14,
5005,
360,
4595,
9327,
1194,
13,
1624,
24,
13,
1797,
2192,
11533,
14,
2424,
297,
7126,
63,
3022,
9,
199,
199,
3,
1551,
16858,
3748,
10815,
199,
1361,
360,
18085,
3232,
2610,
8916,
3748,
10815,
15103,
199,
1045,
1551,
8,
736,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
283,
1490,
16858,
63,
13209,
14,
2424,
659,
283,
87,
358,
465,
289,
26,
272,
519,
275,
4145,
14,
362,
360,
1014,
921,
1544,
14,
1490,
16858,
14,
1308,
15,
10788,
15,
3790,
63,
13209,
14,
8624,
358,
272,
289,
14,
952,
8,
82,
14,
1317,
9,
199,
199,
1361,
360,
10759,
10916,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
334,
67,
9,
6171,
314,
699,
902,
38,
2453,
11462,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
314,
650,
13,
8501,
6289,
4190,
199,
3,
626,
883,
506,
1911,
315,
314,
5113,
570,
14,
199,
3,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
747,
14,
515,
199,
646,
5549,
199,
646,
10392,
199,
646,
4145,
421,
199,
3998,
63,
3022,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
199,
3,
11601,
13,
19,
10642,
13,
17,
14,
2424,
199,
1361,
360,
18085,
9055,
13,
19,
10642,
13,
17,
4465,
334,
7336,
9023,
9479,
680,
703,
358,
199,
1045,
1551,
8,
736,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
283,
4595,
13,
19,
10642,
13,
17,
14,
2424,
659,
283,
87,
358,
465,
289,
26,
272,
519,
275,
4145,
14,
362,
360,
1014,
921,
1544,
14,
4595,
14,
1308,
15,
4595,
15,
4219,
15,
7935,
5596,
15,
6063,
63,
6021,
15,
6063,
63,
1247,
63,
460,
63,
600,
63,
5527,
63,
2424,
14,
15575,
358,
272,
289,
14,
952,
8,
82,
14,
1317,
14,
1913,
1012,
199,
199,
3,
11601,
13,
26723,
13,
19,
14,
2902,
199,
1361,
360,
18085,
9055,
13,
26723,
13,
19,
4465,
334,
7336,
2637,
9479,
680,
703,
358,
199,
1045,
5549,
14,
13271,
342,
465,
289,
26,
272,
519,
275,
4145,
14,
362,
360,
1014,
921,
1544,
13,
614,
14,
20329,
14,
1308,
15,
4595,
26723,
13,
19,
15,
4595,
13,
26723,
13,
19,
63,
3034,
63,
18845,
63,
1797,
11565,
2192,
14,
3065,
358,
272,
289,
14,
952,
8,
82,
14,
1317,
9,
272,
543,
10392,
14,
15016,
8,
70,
9,
465,
1315,
26,
267,
1315,
14,
5005,
360,
4595,
13,
26723,
13,
19,
14,
2902,
297,
7126,
63,
3022,
9,
199,
199,
3,
11601,
13,
9327,
1194,
199,
1361,
360,
18085,
9055,
13,
9327,
1194,
4465,
334,
7336,
2884,
9479,
680,
703,
358,
199,
1045,
5549,
14,
13271,
342,
465,
289,
26,
272,
519,
275,
4145,
14,
362,
360,
1014,
921,
1544,
14,
2975,
14,
1308,
15,
4595,
9327,
1194,
15,
4595,
9327,
1194,
14,
2424,
14,
3065,
358,
272,
289,
14,
952,
8,
82,
14,
1317,
9,
272,
543,
10392,
14,
15016,
8,
70,
9,
465,
1315,
26,
267,
1315,
14,
5005,
360,
4595,
9327,
1194,
13,
1624,
24,
13,
1797,
2192,
11533,
14,
2424,
297,
7126,
63,
3022,
9,
199,
199,
3,
1551,
16858,
3748,
10815,
199,
1361,
360,
18085,
3232,
2610,
8916,
3748,
10815,
15103,
199,
1045,
1551,
8,
736,
14,
515,
14,
904,
8,
3998,
63,
3022,
12,
283,
1490,
16858,
63,
13209,
14,
2424,
659,
283,
87,
358,
465,
289,
26,
272,
519,
275,
4145,
14,
362,
360,
1014,
921,
1544,
14,
1490,
16858,
14,
1308,
15,
10788,
15,
3790,
63,
13209,
14,
8624,
358,
272,
289,
14,
952,
8,
82,
14,
1317,
9,
199,
199,
1361,
360,
10759,
10916,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
tcwicklund/django
|
tests/aggregation_regress/tests.py
|
102
|
55724
|
from __future__ import unicode_literals
import datetime
import pickle
from decimal import Decimal
from operator import attrgetter
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import FieldError
from django.db import connection
from django.db.models import (
F, Q, Avg, Count, Max, StdDev, Sum, Value, Variance,
)
from django.test import TestCase, skipUnlessAnyDBFeature, skipUnlessDBFeature
from django.test.utils import Approximate
from django.utils import six
from .models import (
Alfa, Author, Book, Bravo, Charlie, Clues, Entries, HardbackBook, ItemTag,
Publisher, SelfRefFK, Store, WithManualPK,
)
class AggregationTests(TestCase):
@classmethod
def setUpTestData(cls):
cls.a1 = Author.objects.create(name='Adrian Holovaty', age=34)
cls.a2 = Author.objects.create(name='Jacob Kaplan-Moss', age=35)
cls.a3 = Author.objects.create(name='Brad Dayley', age=45)
cls.a4 = Author.objects.create(name='James Bennett', age=29)
cls.a5 = Author.objects.create(name='Jeffrey Forcier', age=37)
cls.a6 = Author.objects.create(name='Paul Bissex', age=29)
cls.a7 = Author.objects.create(name='Wesley J. Chun', age=25)
cls.a8 = Author.objects.create(name='Peter Norvig', age=57)
cls.a9 = Author.objects.create(name='Stuart Russell', age=46)
cls.a1.friends.add(cls.a2, cls.a4)
cls.a2.friends.add(cls.a1, cls.a7)
cls.a4.friends.add(cls.a1)
cls.a5.friends.add(cls.a6, cls.a7)
cls.a6.friends.add(cls.a5, cls.a7)
cls.a7.friends.add(cls.a2, cls.a5, cls.a6)
cls.a8.friends.add(cls.a9)
cls.a9.friends.add(cls.a8)
cls.p1 = Publisher.objects.create(name='Apress', num_awards=3)
cls.p2 = Publisher.objects.create(name='Sams', num_awards=1)
cls.p3 = Publisher.objects.create(name='Prentice Hall', num_awards=7)
cls.p4 = Publisher.objects.create(name='Morgan Kaufmann', num_awards=9)
cls.p5 = Publisher.objects.create(name="Jonno's House of Books", num_awards=0)
cls.b1 = Book.objects.create(
isbn='159059725', name='The Definitive Guide to Django: Web Development Done Right',
pages=447, rating=4.5, price=Decimal('30.00'), contact=cls.a1, publisher=cls.p1,
pubdate=datetime.date(2007, 12, 6)
)
cls.b2 = Book.objects.create(
isbn='067232959', name='Sams Teach Yourself Django in 24 Hours',
pages=528, rating=3.0, price=Decimal('23.09'), contact=cls.a3, publisher=cls.p2,
pubdate=datetime.date(2008, 3, 3)
)
cls.b3 = Book.objects.create(
isbn='159059996', name='Practical Django Projects',
pages=300, rating=4.0, price=Decimal('29.69'), contact=cls.a4, publisher=cls.p1,
pubdate=datetime.date(2008, 6, 23)
)
cls.b4 = Book.objects.create(
isbn='013235613', name='Python Web Development with Django',
pages=350, rating=4.0, price=Decimal('29.69'), contact=cls.a5, publisher=cls.p3,
pubdate=datetime.date(2008, 11, 3)
)
cls.b5 = HardbackBook.objects.create(
isbn='013790395', name='Artificial Intelligence: A Modern Approach',
pages=1132, rating=4.0, price=Decimal('82.80'), contact=cls.a8, publisher=cls.p3,
pubdate=datetime.date(1995, 1, 15), weight=4.5)
cls.b6 = HardbackBook.objects.create(
isbn='155860191', name='Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp',
pages=946, rating=5.0, price=Decimal('75.00'), contact=cls.a8, publisher=cls.p4,
pubdate=datetime.date(1991, 10, 15), weight=3.7)
cls.b1.authors.add(cls.a1, cls.a2)
cls.b2.authors.add(cls.a3)
cls.b3.authors.add(cls.a4)
cls.b4.authors.add(cls.a5, cls.a6, cls.a7)
cls.b5.authors.add(cls.a8, cls.a9)
cls.b6.authors.add(cls.a8)
s1 = Store.objects.create(
name='Amazon.com',
original_opening=datetime.datetime(1994, 4, 23, 9, 17, 42),
friday_night_closing=datetime.time(23, 59, 59)
)
s2 = Store.objects.create(
name='Books.com',
original_opening=datetime.datetime(2001, 3, 15, 11, 23, 37),
friday_night_closing=datetime.time(23, 59, 59)
)
s3 = Store.objects.create(
name="Mamma and Pappa's Books",
original_opening=datetime.datetime(1945, 4, 25, 16, 24, 14),
friday_night_closing=datetime.time(21, 30)
)
s1.books.add(cls.b1, cls.b2, cls.b3, cls.b4, cls.b5, cls.b6)
s2.books.add(cls.b1, cls.b3, cls.b5, cls.b6)
s3.books.add(cls.b3, cls.b4, cls.b6)
def assertObjectAttrs(self, obj, **kwargs):
for attr, value in six.iteritems(kwargs):
self.assertEqual(getattr(obj, attr), value)
def test_aggregates_in_where_clause(self):
"""
Regression test for #12822: DatabaseError: aggregates not allowed in
WHERE clause
Tests that the subselect works and returns results equivalent to a
query with the IDs listed.
Before the corresponding fix for this bug, this test passed in 1.1 and
failed in 1.2-beta (trunk).
"""
qs = Book.objects.values('contact').annotate(Max('id'))
qs = qs.order_by('contact').values_list('id__max', flat=True)
# don't do anything with the queryset (qs) before including it as a
# subquery
books = Book.objects.order_by('id')
qs1 = books.filter(id__in=qs)
qs2 = books.filter(id__in=list(qs))
self.assertEqual(list(qs1), list(qs2))
def test_aggregates_in_where_clause_pre_eval(self):
"""
Regression test for #12822: DatabaseError: aggregates not allowed in
WHERE clause
Same as the above test, but evaluates the queryset for the subquery
before it's used as a subquery.
Before the corresponding fix for this bug, this test failed in both
1.1 and 1.2-beta (trunk).
"""
qs = Book.objects.values('contact').annotate(Max('id'))
qs = qs.order_by('contact').values_list('id__max', flat=True)
# force the queryset (qs) for the subquery to be evaluated in its
# current state
list(qs)
books = Book.objects.order_by('id')
qs1 = books.filter(id__in=qs)
qs2 = books.filter(id__in=list(qs))
self.assertEqual(list(qs1), list(qs2))
@skipUnlessDBFeature('supports_subqueries_in_group_by')
def test_annotate_with_extra(self):
"""
Regression test for #11916: Extra params + aggregation creates
incorrect SQL.
"""
# Oracle doesn't support subqueries in group by clause
shortest_book_sql = """
SELECT name
FROM aggregation_regress_book b
WHERE b.publisher_id = aggregation_regress_publisher.id
ORDER BY b.pages
LIMIT 1
"""
# tests that this query does not raise a DatabaseError due to the full
# subselect being (erroneously) added to the GROUP BY parameters
qs = Publisher.objects.extra(select={
'name_of_shortest_book': shortest_book_sql,
}).annotate(total_books=Count('book'))
# force execution of the query
list(qs)
def test_aggregate(self):
# Ordering requests are ignored
self.assertEqual(
Author.objects.order_by("name").aggregate(Avg("age")),
{"age__avg": Approximate(37.444, places=1)}
)
# Implicit ordering is also ignored
self.assertEqual(
Book.objects.aggregate(Sum("pages")),
{"pages__sum": 3703},
)
# Baseline results
self.assertEqual(
Book.objects.aggregate(Sum('pages'), Avg('pages')),
{'pages__sum': 3703, 'pages__avg': Approximate(617.166, places=2)}
)
# Empty values query doesn't affect grouping or results
self.assertEqual(
Book.objects.values().aggregate(Sum('pages'), Avg('pages')),
{'pages__sum': 3703, 'pages__avg': Approximate(617.166, places=2)}
)
# Aggregate overrides extra selected column
self.assertEqual(
Book.objects.extra(select={'price_per_page': 'price / pages'}).aggregate(Sum('pages')),
{'pages__sum': 3703}
)
def test_annotation(self):
# Annotations get combined with extra select clauses
obj = Book.objects.annotate(mean_auth_age=Avg("authors__age")).extra(
select={"manufacture_cost": "price * .5"}).get(pk=self.b2.pk)
self.assertObjectAttrs(
obj,
contact_id=self.a3.id,
isbn='067232959',
mean_auth_age=45.0,
name='Sams Teach Yourself Django in 24 Hours',
pages=528,
price=Decimal("23.09"),
pubdate=datetime.date(2008, 3, 3),
publisher_id=self.p2.id,
rating=3.0
)
# Different DB backends return different types for the extra select computation
self.assertIn(obj.manufacture_cost, (11.545, Decimal('11.545')))
# Order of the annotate/extra in the query doesn't matter
obj = Book.objects.extra(select={'manufacture_cost': 'price * .5'}).annotate(
mean_auth_age=Avg('authors__age')).get(pk=self.b2.pk)
self.assertObjectAttrs(
obj,
contact_id=self.a3.id,
isbn='067232959',
mean_auth_age=45.0,
name='Sams Teach Yourself Django in 24 Hours',
pages=528,
price=Decimal("23.09"),
pubdate=datetime.date(2008, 3, 3),
publisher_id=self.p2.id,
rating=3.0
)
# Different DB backends return different types for the extra select computation
self.assertIn(obj.manufacture_cost, (11.545, Decimal('11.545')))
# Values queries can be combined with annotate and extra
obj = Book.objects.annotate(mean_auth_age=Avg('authors__age')).extra(
select={'manufacture_cost': 'price * .5'}).values().get(pk=self.b2.pk)
manufacture_cost = obj['manufacture_cost']
self.assertIn(manufacture_cost, (11.545, Decimal('11.545')))
del obj['manufacture_cost']
self.assertEqual(obj, {
'id': self.b2.id,
'contact_id': self.a3.id,
'isbn': '067232959',
'mean_auth_age': 45.0,
'name': 'Sams Teach Yourself Django in 24 Hours',
'pages': 528,
'price': Decimal('23.09'),
'pubdate': datetime.date(2008, 3, 3),
'publisher_id': self.p2.id,
'rating': 3.0,
})
# The order of the (empty) values, annotate and extra clauses doesn't
# matter
obj = Book.objects.values().annotate(mean_auth_age=Avg('authors__age')).extra(
select={'manufacture_cost': 'price * .5'}).get(pk=self.b2.pk)
manufacture_cost = obj['manufacture_cost']
self.assertIn(manufacture_cost, (11.545, Decimal('11.545')))
del obj['manufacture_cost']
self.assertEqual(obj, {
'id': self.b2.id,
'contact_id': self.a3.id,
'isbn': '067232959',
'mean_auth_age': 45.0,
'name': 'Sams Teach Yourself Django in 24 Hours',
'pages': 528,
'price': Decimal('23.09'),
'pubdate': datetime.date(2008, 3, 3),
'publisher_id': self.p2.id,
'rating': 3.0
})
# If the annotation precedes the values clause, it won't be included
# unless it is explicitly named
obj = Book.objects.annotate(mean_auth_age=Avg('authors__age')).extra(
select={'price_per_page': 'price / pages'}).values('name').get(pk=self.b1.pk)
self.assertEqual(obj, {
"name": 'The Definitive Guide to Django: Web Development Done Right',
})
obj = Book.objects.annotate(mean_auth_age=Avg('authors__age')).extra(
select={'price_per_page': 'price / pages'}).values('name', 'mean_auth_age').get(pk=self.b1.pk)
self.assertEqual(obj, {
'mean_auth_age': 34.5,
'name': 'The Definitive Guide to Django: Web Development Done Right',
})
# If an annotation isn't included in the values, it can still be used
# in a filter
qs = Book.objects.annotate(n_authors=Count('authors')).values('name').filter(n_authors__gt=2)
self.assertQuerysetEqual(
qs, [
{"name": 'Python Web Development with Django'}
],
lambda b: b,
)
# The annotations are added to values output if values() precedes
# annotate()
obj = Book.objects.values('name').annotate(mean_auth_age=Avg('authors__age')).extra(
select={'price_per_page': 'price / pages'}).get(pk=self.b1.pk)
self.assertEqual(obj, {
'mean_auth_age': 34.5,
'name': 'The Definitive Guide to Django: Web Development Done Right',
})
# Check that all of the objects are getting counted (allow_nulls) and
# that values respects the amount of objects
self.assertEqual(
len(Author.objects.annotate(Avg('friends__age')).values()),
9
)
# Check that consecutive calls to annotate accumulate in the query
qs = (
Book.objects
.values('price')
.annotate(oldest=Max('authors__age'))
.order_by('oldest', 'price')
.annotate(Max('publisher__num_awards'))
)
self.assertQuerysetEqual(
qs, [
{'price': Decimal("30"), 'oldest': 35, 'publisher__num_awards__max': 3},
{'price': Decimal("29.69"), 'oldest': 37, 'publisher__num_awards__max': 7},
{'price': Decimal("23.09"), 'oldest': 45, 'publisher__num_awards__max': 1},
{'price': Decimal("75"), 'oldest': 57, 'publisher__num_awards__max': 9},
{'price': Decimal("82.8"), 'oldest': 57, 'publisher__num_awards__max': 7}
],
lambda b: b,
)
def test_aggrate_annotation(self):
# Aggregates can be composed over annotations.
# The return type is derived from the composed aggregate
vals = (
Book.objects
.all()
.annotate(num_authors=Count('authors__id'))
.aggregate(Max('pages'), Max('price'), Sum('num_authors'), Avg('num_authors'))
)
self.assertEqual(vals, {
'num_authors__sum': 10,
'num_authors__avg': Approximate(1.666, places=2),
'pages__max': 1132,
'price__max': Decimal("82.80")
})
# Regression for #15624 - Missing SELECT columns when using values, annotate
# and aggregate in a single query
self.assertEqual(
Book.objects.annotate(c=Count('authors')).values('c').aggregate(Max('c')),
{'c__max': 3}
)
def test_decimal_aggregate_annotation_filter(self):
"""
Filtering on an aggregate annotation with Decimal values should work.
Requires special handling on SQLite (#18247).
"""
self.assertEqual(
len(Author.objects.annotate(sum=Sum('book_contact_set__price')).filter(sum__gt=Decimal(40))),
1
)
self.assertEqual(
len(Author.objects.annotate(sum=Sum('book_contact_set__price')).filter(sum__lte=Decimal(40))),
4
)
def test_field_error(self):
# Bad field requests in aggregates are caught and reported
self.assertRaises(
FieldError,
lambda: Book.objects.all().aggregate(num_authors=Count('foo'))
)
self.assertRaises(
FieldError,
lambda: Book.objects.all().annotate(num_authors=Count('foo'))
)
self.assertRaises(
FieldError,
lambda: Book.objects.all().annotate(num_authors=Count('authors__id')).aggregate(Max('foo'))
)
def test_more(self):
# Old-style count aggregations can be mixed with new-style
self.assertEqual(
Book.objects.annotate(num_authors=Count('authors')).count(),
6
)
# Non-ordinal, non-computed Aggregates over annotations correctly
# inherit the annotation's internal type if the annotation is ordinal
# or computed
vals = Book.objects.annotate(num_authors=Count('authors')).aggregate(Max('num_authors'))
self.assertEqual(
vals,
{'num_authors__max': 3}
)
vals = Publisher.objects.annotate(avg_price=Avg('book__price')).aggregate(Max('avg_price'))
self.assertEqual(
vals,
{'avg_price__max': 75.0}
)
# Aliases are quoted to protected aliases that might be reserved names
vals = Book.objects.aggregate(number=Max('pages'), select=Max('pages'))
self.assertEqual(
vals,
{'number': 1132, 'select': 1132}
)
# Regression for #10064: select_related() plays nice with aggregates
obj = Book.objects.select_related('publisher').annotate(
num_authors=Count('authors')).values().get(isbn='013790395')
self.assertEqual(obj, {
'contact_id': self.a8.id,
'id': self.b5.id,
'isbn': '013790395',
'name': 'Artificial Intelligence: A Modern Approach',
'num_authors': 2,
'pages': 1132,
'price': Decimal("82.8"),
'pubdate': datetime.date(1995, 1, 15),
'publisher_id': self.p3.id,
'rating': 4.0,
})
# Regression for #10010: exclude on an aggregate field is correctly
# negated
self.assertEqual(
len(Book.objects.annotate(num_authors=Count('authors'))),
6
)
self.assertEqual(
len(Book.objects.annotate(num_authors=Count('authors')).filter(num_authors__gt=2)),
1
)
self.assertEqual(
len(Book.objects.annotate(num_authors=Count('authors')).exclude(num_authors__gt=2)),
5
)
self.assertEqual(
len(
Book.objects
.annotate(num_authors=Count('authors'))
.filter(num_authors__lt=3)
.exclude(num_authors__lt=2)
),
2
)
self.assertEqual(
len(
Book.objects
.annotate(num_authors=Count('authors'))
.exclude(num_authors__lt=2)
.filter(num_authors__lt=3)
),
2
)
def test_aggregate_fexpr(self):
# Aggregates can be used with F() expressions
# ... where the F() is pushed into the HAVING clause
qs = (
Publisher.objects
.annotate(num_books=Count('book'))
.filter(num_books__lt=F('num_awards') / 2)
.order_by('name')
.values('name', 'num_books', 'num_awards')
)
self.assertQuerysetEqual(
qs, [
{'num_books': 1, 'name': 'Morgan Kaufmann', 'num_awards': 9},
{'num_books': 2, 'name': 'Prentice Hall', 'num_awards': 7}
],
lambda p: p,
)
qs = (
Publisher.objects
.annotate(num_books=Count('book'))
.exclude(num_books__lt=F('num_awards') / 2)
.order_by('name')
.values('name', 'num_books', 'num_awards')
)
self.assertQuerysetEqual(
qs, [
{'num_books': 2, 'name': 'Apress', 'num_awards': 3},
{'num_books': 0, 'name': "Jonno's House of Books", 'num_awards': 0},
{'num_books': 1, 'name': 'Sams', 'num_awards': 1}
],
lambda p: p,
)
# ... and where the F() references an aggregate
qs = (
Publisher.objects
.annotate(num_books=Count('book'))
.filter(num_awards__gt=2 * F('num_books'))
.order_by('name')
.values('name', 'num_books', 'num_awards')
)
self.assertQuerysetEqual(
qs, [
{'num_books': 1, 'name': 'Morgan Kaufmann', 'num_awards': 9},
{'num_books': 2, 'name': 'Prentice Hall', 'num_awards': 7}
],
lambda p: p,
)
qs = (
Publisher.objects
.annotate(num_books=Count('book'))
.exclude(num_books__lt=F('num_awards') / 2)
.order_by('name')
.values('name', 'num_books', 'num_awards')
)
self.assertQuerysetEqual(
qs, [
{'num_books': 2, 'name': 'Apress', 'num_awards': 3},
{'num_books': 0, 'name': "Jonno's House of Books", 'num_awards': 0},
{'num_books': 1, 'name': 'Sams', 'num_awards': 1}
],
lambda p: p,
)
def test_db_col_table(self):
# Tests on fields with non-default table and column names.
qs = (
Clues.objects
.values('EntryID__Entry')
.annotate(Appearances=Count('EntryID'), Distinct_Clues=Count('Clue', distinct=True))
)
self.assertQuerysetEqual(qs, [])
qs = Entries.objects.annotate(clue_count=Count('clues__ID'))
self.assertQuerysetEqual(qs, [])
def test_boolean_conversion(self):
# Aggregates mixed up ordering of columns for backend's convert_values
# method. Refs #21126.
e = Entries.objects.create(Entry='foo')
c = Clues.objects.create(EntryID=e, Clue='bar')
qs = Clues.objects.select_related('EntryID').annotate(Count('ID'))
self.assertQuerysetEqual(
qs, [c], lambda x: x)
self.assertEqual(qs[0].EntryID, e)
self.assertIs(qs[0].EntryID.Exclude, False)
def test_empty(self):
# Regression for #10089: Check handling of empty result sets with
# aggregates
self.assertEqual(
Book.objects.filter(id__in=[]).count(),
0
)
vals = (
Book.objects
.filter(id__in=[])
.aggregate(
num_authors=Count('authors'),
avg_authors=Avg('authors'),
max_authors=Max('authors'),
max_price=Max('price'),
max_rating=Max('rating'),
)
)
self.assertEqual(
vals,
{'max_authors': None, 'max_rating': None, 'num_authors': 0, 'avg_authors': None, 'max_price': None}
)
qs = (
Publisher.objects
.filter(name="Jonno's House of Books")
.annotate(
num_authors=Count('book__authors'),
avg_authors=Avg('book__authors'),
max_authors=Max('book__authors'),
max_price=Max('book__price'),
max_rating=Max('book__rating'),
).values()
)
self.assertQuerysetEqual(
qs,
[{
'max_authors': None,
'name': "Jonno's House of Books",
'num_awards': 0,
'max_price': None,
'num_authors': 0,
'max_rating': None,
'id': self.p5.id,
'avg_authors': None,
}],
lambda p: p
)
def test_more_more(self):
# Regression for #10113 - Fields mentioned in order_by() must be
# included in the GROUP BY. This only becomes a problem when the
# order_by introduces a new join.
self.assertQuerysetEqual(
Book.objects.annotate(num_authors=Count('authors')).order_by('publisher__name', 'name'), [
"Practical Django Projects",
"The Definitive Guide to Django: Web Development Done Right",
"Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp",
"Artificial Intelligence: A Modern Approach",
"Python Web Development with Django",
"Sams Teach Yourself Django in 24 Hours",
],
lambda b: b.name
)
# Regression for #10127 - Empty select_related() works with annotate
qs = Book.objects.filter(rating__lt=4.5).select_related().annotate(Avg('authors__age'))
self.assertQuerysetEqual(
qs,
[
('Artificial Intelligence: A Modern Approach', 51.5, 'Prentice Hall', 'Peter Norvig'),
('Practical Django Projects', 29.0, 'Apress', 'James Bennett'),
(
'Python Web Development with Django',
Approximate(30.333, places=2),
'Prentice Hall',
'Jeffrey Forcier',
),
('Sams Teach Yourself Django in 24 Hours', 45.0, 'Sams', 'Brad Dayley')
],
lambda b: (b.name, b.authors__age__avg, b.publisher.name, b.contact.name)
)
# Regression for #10132 - If the values() clause only mentioned extra
# (select=) columns, those columns are used for grouping
qs = Book.objects.extra(select={'pub': 'publisher_id'}).values('pub').annotate(Count('id')).order_by('pub')
self.assertQuerysetEqual(
qs, [
{'pub': self.b1.id, 'id__count': 2},
{'pub': self.b2.id, 'id__count': 1},
{'pub': self.b3.id, 'id__count': 2},
{'pub': self.b4.id, 'id__count': 1}
],
lambda b: b
)
qs = (
Book.objects
.extra(select={'pub': 'publisher_id', 'foo': 'pages'})
.values('pub')
.annotate(Count('id'))
.order_by('pub')
)
self.assertQuerysetEqual(
qs, [
{'pub': self.p1.id, 'id__count': 2},
{'pub': self.p2.id, 'id__count': 1},
{'pub': self.p3.id, 'id__count': 2},
{'pub': self.p4.id, 'id__count': 1}
],
lambda b: b
)
# Regression for #10182 - Queries with aggregate calls are correctly
# realiased when used in a subquery
ids = (
Book.objects
.filter(pages__gt=100)
.annotate(n_authors=Count('authors'))
.filter(n_authors__gt=2)
.order_by('n_authors')
)
self.assertQuerysetEqual(
Book.objects.filter(id__in=ids), [
"Python Web Development with Django",
],
lambda b: b.name
)
# Regression for #15709 - Ensure each group_by field only exists once
# per query
qstr = str(Book.objects.values('publisher').annotate(max_pages=Max('pages')).order_by().query)
# Check that there is just one GROUP BY clause (zero commas means at
# most one clause)
self.assertEqual(qstr[qstr.index('GROUP BY'):].count(', '), 0)
def test_duplicate_alias(self):
# Regression for #11256 - duplicating a default alias raises ValueError.
self.assertRaises(
ValueError,
Book.objects.all().annotate,
Avg('authors__age'), authors__age__avg=Avg('authors__age')
)
def test_field_name_conflict(self):
# Regression for #11256 - providing an aggregate name
# that conflicts with a field name on the model raises ValueError
self.assertRaises(ValueError, Author.objects.annotate, age=Avg('friends__age'))
def test_m2m_name_conflict(self):
# Regression for #11256 - providing an aggregate name
# that conflicts with an m2m name on the model raises ValueError
self.assertRaises(ValueError, Author.objects.annotate, friends=Count('friends'))
def test_values_queryset_non_conflict(self):
# Regression for #14707 -- If you're using a values query set, some potential conflicts are avoided.
# age is a field on Author, so it shouldn't be allowed as an aggregate.
# But age isn't included in values(), so it is.
results = Author.objects.values('name').annotate(age=Count('book_contact_set')).order_by('name')
self.assertEqual(len(results), 9)
self.assertEqual(results[0]['name'], 'Adrian Holovaty')
self.assertEqual(results[0]['age'], 1)
# Same problem, but aggregating over m2m fields
results = Author.objects.values('name').annotate(age=Avg('friends__age')).order_by('name')
self.assertEqual(len(results), 9)
self.assertEqual(results[0]['name'], 'Adrian Holovaty')
self.assertEqual(results[0]['age'], 32.0)
# Same problem, but colliding with an m2m field
results = Author.objects.values('name').annotate(friends=Count('friends')).order_by('name')
self.assertEqual(len(results), 9)
self.assertEqual(results[0]['name'], 'Adrian Holovaty')
self.assertEqual(results[0]['friends'], 2)
def test_reverse_relation_name_conflict(self):
# Regression for #11256 - providing an aggregate name
# that conflicts with a reverse-related name on the model raises ValueError
self.assertRaises(ValueError, Author.objects.annotate, book_contact_set=Avg('friends__age'))
def test_pickle(self):
# Regression for #10197 -- Queries with aggregates can be pickled.
# First check that pickling is possible at all. No crash = success
qs = Book.objects.annotate(num_authors=Count('authors'))
pickle.dumps(qs)
# Then check that the round trip works.
query = qs.query.get_compiler(qs.db).as_sql()[0]
qs2 = pickle.loads(pickle.dumps(qs))
self.assertEqual(
qs2.query.get_compiler(qs2.db).as_sql()[0],
query,
)
def test_more_more_more(self):
# Regression for #10199 - Aggregate calls clone the original query so
# the original query can still be used
books = Book.objects.all()
books.aggregate(Avg("authors__age"))
self.assertQuerysetEqual(
books.all(), [
'Artificial Intelligence: A Modern Approach',
'Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp',
'Practical Django Projects',
'Python Web Development with Django',
'Sams Teach Yourself Django in 24 Hours',
'The Definitive Guide to Django: Web Development Done Right'
],
lambda b: b.name
)
# Regression for #10248 - Annotations work with dates()
qs = Book.objects.annotate(num_authors=Count('authors')).filter(num_authors=2).dates('pubdate', 'day')
self.assertQuerysetEqual(
qs, [
datetime.date(1995, 1, 15),
datetime.date(2007, 12, 6),
],
lambda b: b
)
# Regression for #10290 - extra selects with parameters can be used for
# grouping.
qs = (
Book.objects
.annotate(mean_auth_age=Avg('authors__age'))
.extra(select={'sheets': '(pages + %s) / %s'}, select_params=[1, 2])
.order_by('sheets')
.values('sheets')
)
self.assertQuerysetEqual(
qs, [
150,
175,
224,
264,
473,
566
],
lambda b: int(b["sheets"])
)
# Regression for 10425 - annotations don't get in the way of a count()
# clause
self.assertEqual(
Book.objects.values('publisher').annotate(Count('publisher')).count(),
4
)
self.assertEqual(
Book.objects.annotate(Count('publisher')).values('publisher').count(),
6
)
# Note: intentionally no order_by(), that case needs tests, too.
publishers = Publisher.objects.filter(id__in=[1, 2])
self.assertEqual(
sorted(p.name for p in publishers),
[
"Apress",
"Sams"
]
)
publishers = publishers.annotate(n_books=Count("book"))
sorted_publishers = sorted(publishers, key=lambda x: x.name)
self.assertEqual(
sorted_publishers[0].n_books,
2
)
self.assertEqual(
sorted_publishers[1].n_books,
1
)
self.assertEqual(
sorted(p.name for p in publishers),
[
"Apress",
"Sams"
]
)
books = Book.objects.filter(publisher__in=publishers)
self.assertQuerysetEqual(
books, [
"Practical Django Projects",
"Sams Teach Yourself Django in 24 Hours",
"The Definitive Guide to Django: Web Development Done Right",
],
lambda b: b.name
)
self.assertEqual(
sorted(p.name for p in publishers),
[
"Apress",
"Sams"
]
)
# Regression for 10666 - inherited fields work with annotations and
# aggregations
self.assertEqual(
HardbackBook.objects.aggregate(n_pages=Sum('book_ptr__pages')),
{'n_pages': 2078}
)
self.assertEqual(
HardbackBook.objects.aggregate(n_pages=Sum('pages')),
{'n_pages': 2078},
)
qs = HardbackBook.objects.annotate(n_authors=Count('book_ptr__authors')).values('name', 'n_authors')
self.assertQuerysetEqual(
qs,
[
{'n_authors': 2, 'name': 'Artificial Intelligence: A Modern Approach'},
{
'n_authors': 1,
'name': 'Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp'
}
],
lambda h: h
)
qs = HardbackBook.objects.annotate(n_authors=Count('authors')).values('name', 'n_authors')
self.assertQuerysetEqual(
qs,
[
{'n_authors': 2, 'name': 'Artificial Intelligence: A Modern Approach'},
{
'n_authors': 1,
'name': 'Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp'
}
],
lambda h: h,
)
# Regression for #10766 - Shouldn't be able to reference an aggregate
# fields in an aggregate() call.
self.assertRaises(
FieldError,
lambda: Book.objects.annotate(mean_age=Avg('authors__age')).annotate(Avg('mean_age'))
)
def test_empty_filter_count(self):
self.assertEqual(
Author.objects.filter(id__in=[]).annotate(Count("friends")).count(),
0
)
def test_empty_filter_aggregate(self):
self.assertEqual(
Author.objects.filter(id__in=[]).annotate(Count("friends")).aggregate(Count("pk")),
{"pk__count": None}
)
def test_none_call_before_aggregate(self):
# Regression for #11789
self.assertEqual(
Author.objects.none().aggregate(Avg('age')),
{'age__avg': None}
)
def test_annotate_and_join(self):
self.assertEqual(
Author.objects.annotate(c=Count("friends__name")).exclude(friends__name="Joe").count(),
Author.objects.count()
)
def test_f_expression_annotation(self):
# Books with less than 200 pages per author.
qs = Book.objects.values("name").annotate(
n_authors=Count("authors")
).filter(
pages__lt=F("n_authors") * 200
).values_list("pk")
self.assertQuerysetEqual(
Book.objects.filter(pk__in=qs), [
"Python Web Development with Django"
],
attrgetter("name")
)
def test_values_annotate_values(self):
qs = Book.objects.values("name").annotate(
n_authors=Count("authors")
).values_list("pk", flat=True)
self.assertEqual(list(qs), list(Book.objects.values_list("pk", flat=True)))
def test_having_group_by(self):
# Test that when a field occurs on the LHS of a HAVING clause that it
# appears correctly in the GROUP BY clause
qs = Book.objects.values_list("name").annotate(
n_authors=Count("authors")
).filter(
pages__gt=F("n_authors")
).values_list("name", flat=True)
# Results should be the same, all Books have more pages than authors
self.assertEqual(
list(qs), list(Book.objects.values_list("name", flat=True))
)
def test_values_list_annotation_args_ordering(self):
"""
Annotate *args ordering should be preserved in values_list results.
**kwargs comes after *args.
Regression test for #23659.
"""
books = Book.objects.values_list("publisher__name").annotate(
Count("id"), Avg("price"), Avg("authors__age"), avg_pgs=Avg("pages")
).order_by("-publisher__name")
self.assertEqual(books[0], ('Sams', 1, 23.09, 45.0, 528.0))
def test_annotation_disjunction(self):
qs = Book.objects.annotate(n_authors=Count("authors")).filter(
Q(n_authors=2) | Q(name="Python Web Development with Django")
)
self.assertQuerysetEqual(
qs, [
"Artificial Intelligence: A Modern Approach",
"Python Web Development with Django",
"The Definitive Guide to Django: Web Development Done Right",
],
attrgetter("name")
)
qs = (
Book.objects
.annotate(n_authors=Count("authors"))
.filter(
Q(name="The Definitive Guide to Django: Web Development Done Right")
| (Q(name="Artificial Intelligence: A Modern Approach") & Q(n_authors=3))
)
)
self.assertQuerysetEqual(
qs,
[
"The Definitive Guide to Django: Web Development Done Right",
],
attrgetter("name")
)
qs = Publisher.objects.annotate(
rating_sum=Sum("book__rating"),
book_count=Count("book")
).filter(
Q(rating_sum__gt=5.5) | Q(rating_sum__isnull=True)
).order_by('pk')
self.assertQuerysetEqual(
qs, [
"Apress",
"Prentice Hall",
"Jonno's House of Books",
],
attrgetter("name")
)
qs = Publisher.objects.annotate(
rating_sum=Sum("book__rating"),
book_count=Count("book")
).filter(
Q(rating_sum__gt=F("book_count")) | Q(rating_sum=None)
).order_by("num_awards")
self.assertQuerysetEqual(
qs, [
"Jonno's House of Books",
"Sams",
"Apress",
"Prentice Hall",
"Morgan Kaufmann"
],
attrgetter("name")
)
def test_quoting_aggregate_order_by(self):
qs = Book.objects.filter(
name="Python Web Development with Django"
).annotate(
authorCount=Count("authors")
).order_by("authorCount")
self.assertQuerysetEqual(
qs, [
("Python Web Development with Django", 3),
],
lambda b: (b.name, b.authorCount)
)
@skipUnlessDBFeature('supports_stddev')
def test_stddev(self):
self.assertEqual(
Book.objects.aggregate(StdDev('pages')),
{'pages__stddev': Approximate(311.46, 1)}
)
self.assertEqual(
Book.objects.aggregate(StdDev('rating')),
{'rating__stddev': Approximate(0.60, 1)}
)
self.assertEqual(
Book.objects.aggregate(StdDev('price')),
{'price__stddev': Approximate(24.16, 2)}
)
self.assertEqual(
Book.objects.aggregate(StdDev('pages', sample=True)),
{'pages__stddev': Approximate(341.19, 2)}
)
self.assertEqual(
Book.objects.aggregate(StdDev('rating', sample=True)),
{'rating__stddev': Approximate(0.66, 2)}
)
self.assertEqual(
Book.objects.aggregate(StdDev('price', sample=True)),
{'price__stddev': Approximate(26.46, 1)}
)
self.assertEqual(
Book.objects.aggregate(Variance('pages')),
{'pages__variance': Approximate(97010.80, 1)}
)
self.assertEqual(
Book.objects.aggregate(Variance('rating')),
{'rating__variance': Approximate(0.36, 1)}
)
self.assertEqual(
Book.objects.aggregate(Variance('price')),
{'price__variance': Approximate(583.77, 1)}
)
self.assertEqual(
Book.objects.aggregate(Variance('pages', sample=True)),
{'pages__variance': Approximate(116412.96, 1)}
)
self.assertEqual(
Book.objects.aggregate(Variance('rating', sample=True)),
{'rating__variance': Approximate(0.44, 2)}
)
self.assertEqual(
Book.objects.aggregate(Variance('price', sample=True)),
{'price__variance': Approximate(700.53, 2)}
)
def test_filtering_by_annotation_name(self):
# Regression test for #14476
# The name of the explicitly provided annotation name in this case
# poses no problem
qs = Author.objects.annotate(book_cnt=Count('book')).filter(book_cnt=2).order_by('name')
self.assertQuerysetEqual(
qs,
['Peter Norvig'],
lambda b: b.name
)
# Neither in this case
qs = Author.objects.annotate(book_count=Count('book')).filter(book_count=2).order_by('name')
self.assertQuerysetEqual(
qs,
['Peter Norvig'],
lambda b: b.name
)
# This case used to fail because the ORM couldn't resolve the
# automatically generated annotation name `book__count`
qs = Author.objects.annotate(Count('book')).filter(book__count=2).order_by('name')
self.assertQuerysetEqual(
qs,
['Peter Norvig'],
lambda b: b.name
)
# Referencing the auto-generated name in an aggregate() also works.
self.assertEqual(
Author.objects.annotate(Count('book')).aggregate(Max('book__count')),
{'book__count__max': 2}
)
def test_annotate_joins(self):
"""
Test that the base table's join isn't promoted to LOUTER. This could
cause the query generation to fail if there is an exclude() for fk-field
in the query, too. Refs #19087.
"""
qs = Book.objects.annotate(n=Count('pk'))
self.assertIs(qs.query.alias_map['aggregation_regress_book'].join_type, None)
# Check that the query executes without problems.
self.assertEqual(len(qs.exclude(publisher=-1)), 6)
@skipUnlessAnyDBFeature('allows_group_by_pk', 'allows_group_by_selected_pks')
def test_aggregate_duplicate_columns(self):
# Regression test for #17144
results = Author.objects.annotate(num_contacts=Count('book_contact_set'))
# There should only be one GROUP BY clause, for the `id` column.
# `name` and `age` should not be grouped on.
_, _, group_by = results.query.get_compiler(using='default').pre_sql_setup()
self.assertEqual(len(group_by), 1)
self.assertIn('id', group_by[0][0])
self.assertNotIn('name', group_by[0][0])
self.assertNotIn('age', group_by[0][0])
# Ensure that we get correct results.
self.assertEqual(
[(a.name, a.num_contacts) for a in results.order_by('name')],
[
('Adrian Holovaty', 1),
('Brad Dayley', 1),
('Jacob Kaplan-Moss', 0),
('James Bennett', 1),
('Jeffrey Forcier', 1),
('Paul Bissex', 0),
('Peter Norvig', 2),
('Stuart Russell', 0),
('Wesley J. Chun', 0),
]
)
@skipUnlessAnyDBFeature('allows_group_by_pk', 'allows_group_by_selected_pks')
def test_aggregate_duplicate_columns_only(self):
# Works with only() too.
results = Author.objects.only('id', 'name').annotate(num_contacts=Count('book_contact_set'))
_, _, grouping = results.query.get_compiler(using='default').pre_sql_setup()
self.assertEqual(len(grouping), 1)
self.assertIn('id', grouping[0][0])
self.assertNotIn('name', grouping[0][0])
self.assertNotIn('age', grouping[0][0])
# Ensure that we get correct results.
self.assertEqual(
[(a.name, a.num_contacts) for a in results.order_by('name')],
[
('Adrian Holovaty', 1),
('Brad Dayley', 1),
('Jacob Kaplan-Moss', 0),
('James Bennett', 1),
('Jeffrey Forcier', 1),
('Paul Bissex', 0),
('Peter Norvig', 2),
('Stuart Russell', 0),
('Wesley J. Chun', 0),
]
)
@skipUnlessAnyDBFeature('allows_group_by_pk', 'allows_group_by_selected_pks')
def test_aggregate_duplicate_columns_select_related(self):
# And select_related()
results = Book.objects.select_related('contact').annotate(
num_authors=Count('authors'))
_, _, grouping = results.query.get_compiler(using='default').pre_sql_setup()
# In the case of `group_by_selected_pks` we also group by contact.id because of the select_related.
self.assertEqual(len(grouping), 1 if connection.features.allows_group_by_pk else 2)
self.assertIn('id', grouping[0][0])
self.assertNotIn('name', grouping[0][0])
self.assertNotIn('contact', grouping[0][0])
# Ensure that we get correct results.
self.assertEqual(
[(b.name, b.num_authors) for b in results.order_by('name')],
[
('Artificial Intelligence: A Modern Approach', 2),
('Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp', 1),
('Practical Django Projects', 1),
('Python Web Development with Django', 3),
('Sams Teach Yourself Django in 24 Hours', 1),
('The Definitive Guide to Django: Web Development Done Right', 2)
]
)
def test_reverse_join_trimming(self):
qs = Author.objects.annotate(Count('book_contact_set__contact'))
self.assertIn(' JOIN ', str(qs.query))
def test_aggregation_with_generic_reverse_relation(self):
"""
Regression test for #10870: Aggregates with joins ignore extra
filters provided by setup_joins
tests aggregations with generic reverse relations
"""
django_book = Book.objects.get(name='Practical Django Projects')
ItemTag.objects.create(object_id=django_book.id, tag='intermediate',
content_type=ContentType.objects.get_for_model(django_book))
ItemTag.objects.create(object_id=django_book.id, tag='django',
content_type=ContentType.objects.get_for_model(django_book))
# Assign a tag to model with same PK as the book above. If the JOIN
# used in aggregation doesn't have content type as part of the
# condition the annotation will also count the 'hi mom' tag for b.
wmpk = WithManualPK.objects.create(id=django_book.pk)
ItemTag.objects.create(object_id=wmpk.id, tag='hi mom',
content_type=ContentType.objects.get_for_model(wmpk))
ai_book = Book.objects.get(name__startswith='Paradigms of Artificial Intelligence')
ItemTag.objects.create(object_id=ai_book.id, tag='intermediate',
content_type=ContentType.objects.get_for_model(ai_book))
self.assertEqual(Book.objects.aggregate(Count('tags')), {'tags__count': 3})
results = Book.objects.annotate(Count('tags')).order_by('-tags__count', 'name')
self.assertEqual(
[(b.name, b.tags__count) for b in results],
[
('Practical Django Projects', 2),
('Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp', 1),
('Artificial Intelligence: A Modern Approach', 0),
('Python Web Development with Django', 0),
('Sams Teach Yourself Django in 24 Hours', 0),
('The Definitive Guide to Django: Web Development Done Right', 0)
]
)
def test_negated_aggregation(self):
expected_results = Author.objects.exclude(
pk__in=Author.objects.annotate(book_cnt=Count('book')).filter(book_cnt=2)
).order_by('name')
expected_results = [a.name for a in expected_results]
qs = Author.objects.annotate(book_cnt=Count('book')).exclude(
Q(book_cnt=2), Q(book_cnt=2)).order_by('name')
self.assertQuerysetEqual(
qs,
expected_results,
lambda b: b.name
)
expected_results = Author.objects.exclude(
pk__in=Author.objects.annotate(book_cnt=Count('book')).filter(book_cnt=2)
).order_by('name')
expected_results = [a.name for a in expected_results]
qs = Author.objects.annotate(book_cnt=Count('book')).exclude(Q(book_cnt=2) | Q(book_cnt=2)).order_by('name')
self.assertQuerysetEqual(
qs,
expected_results,
lambda b: b.name
)
def test_name_filters(self):
qs = Author.objects.annotate(Count('book')).filter(
Q(book__count__exact=2) | Q(name='Adrian Holovaty')
).order_by('name')
self.assertQuerysetEqual(
qs,
['Adrian Holovaty', 'Peter Norvig'],
lambda b: b.name
)
def test_name_expressions(self):
# Test that aggregates are spotted correctly from F objects.
# Note that Adrian's age is 34 in the fixtures, and he has one book
# so both conditions match one author.
qs = Author.objects.annotate(Count('book')).filter(
Q(name='Peter Norvig') | Q(age=F('book__count') + 33)
).order_by('name')
self.assertQuerysetEqual(
qs,
['Adrian Holovaty', 'Peter Norvig'],
lambda b: b.name
)
def test_ticket_11293(self):
q1 = Q(price__gt=50)
q2 = Q(authors__count__gt=1)
query = Book.objects.annotate(Count('authors')).filter(
q1 | q2).order_by('pk')
self.assertQuerysetEqual(
query, [1, 4, 5, 6],
lambda b: b.pk)
def test_ticket_11293_q_immutable(self):
"""
Check that splitting a q object to parts for where/having doesn't alter
the original q-object.
"""
q1 = Q(isbn='')
q2 = Q(authors__count__gt=1)
query = Book.objects.annotate(Count('authors'))
query.filter(q1 | q2)
self.assertEqual(len(q2.children), 1)
def test_fobj_group_by(self):
"""
Check that an F() object referring to related column works correctly
in group by.
"""
qs = Book.objects.annotate(
acount=Count('authors')
).filter(
acount=F('publisher__num_awards')
)
self.assertQuerysetEqual(
qs, ['Sams Teach Yourself Django in 24 Hours'],
lambda b: b.name)
def test_annotate_reserved_word(self):
"""
Regression #18333 - Ensure annotated column name is properly quoted.
"""
vals = Book.objects.annotate(select=Count('authors__id')).aggregate(Sum('select'), Avg('select'))
self.assertEqual(vals, {
'select__sum': 10,
'select__avg': Approximate(1.666, places=2),
})
def test_annotate_on_relation(self):
book = Book.objects.annotate(avg_price=Avg('price'), publisher_name=F('publisher__name')).get(pk=self.b1.pk)
self.assertEqual(book.avg_price, 30.00)
self.assertEqual(book.publisher_name, "Apress")
def test_aggregate_on_relation(self):
# A query with an existing annotation aggregation on a relation should
# succeed.
qs = Book.objects.annotate(avg_price=Avg('price')).aggregate(
publisher_awards=Sum('publisher__num_awards')
)
self.assertEqual(qs['publisher_awards'], 30)
def test_annotate_distinct_aggregate(self):
# There are three books with rating of 4.0 and two of the books have
# the same price. Hence, the distinct removes one rating of 4.0
# from the results.
vals1 = Book.objects.values('rating', 'price').distinct().aggregate(result=Sum('rating'))
vals2 = Book.objects.aggregate(result=Sum('rating') - Value(4.0))
self.assertEqual(vals1, vals2)
class JoinPromotionTests(TestCase):
def test_ticket_21150(self):
b = Bravo.objects.create()
c = Charlie.objects.create(bravo=b)
qs = Charlie.objects.select_related('alfa').annotate(Count('bravo__charlie'))
self.assertQuerysetEqual(
qs, [c], lambda x: x)
self.assertIs(qs[0].alfa, None)
a = Alfa.objects.create()
c.alfa = a
c.save()
# Force re-evaluation
qs = qs.all()
self.assertQuerysetEqual(
qs, [c], lambda x: x)
self.assertEqual(qs[0].alfa, a)
def test_existing_join_not_promoted(self):
# No promotion for existing joins
qs = Charlie.objects.filter(alfa__name__isnull=False).annotate(Count('alfa__name'))
self.assertIn(' INNER JOIN ', str(qs.query))
# Also, the existing join is unpromoted when doing filtering for already
# promoted join.
qs = Charlie.objects.annotate(Count('alfa__name')).filter(alfa__name__isnull=False)
self.assertIn(' INNER JOIN ', str(qs.query))
# But, as the join is nullable first use by annotate will be LOUTER
qs = Charlie.objects.annotate(Count('alfa__name'))
self.assertIn(' LEFT OUTER JOIN ', str(qs.query))
def test_non_nullable_fk_not_promoted(self):
qs = Book.objects.annotate(Count('contact__name'))
self.assertIn(' INNER JOIN ', str(qs.query))
class SelfReferentialFKTests(TestCase):
def test_ticket_24748(self):
t1 = SelfRefFK.objects.create(name='t1')
SelfRefFK.objects.create(name='t2', parent=t1)
SelfRefFK.objects.create(name='t3', parent=t1)
self.assertQuerysetEqual(
SelfRefFK.objects.annotate(num_children=Count('children')).order_by('name'),
[('t1', 2), ('t2', 0), ('t3', 0)],
lambda x: (x.name, x.num_children)
)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2197,
199,
646,
5927,
199,
504,
6107,
492,
6345,
199,
504,
4182,
492,
21829,
199,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
504,
1639,
14,
1018,
14,
3924,
492,
27691,
199,
504,
1639,
14,
697,
492,
1950,
199,
504,
1639,
14,
697,
14,
992,
492,
334,
272,
481,
12,
1413,
12,
437,
10929,
12,
14826,
12,
8228,
12,
20992,
12680,
12,
12094,
12,
1594,
12,
21107,
554,
12,
199,
9,
199,
504,
1639,
14,
396,
492,
7640,
12,
3372,
5524,
9874,
18093,
12,
3372,
5524,
18093,
199,
504,
1639,
14,
396,
14,
1208,
492,
13450,
8221,
6897,
199,
504,
1639,
14,
1208,
492,
3816,
199,
199,
504,
1275,
992,
492,
334,
272,
437,
276,
65,
12,
6529,
12,
8944,
12,
32377,
2392,
12,
6659,
21530,
12,
8465,
10138,
12,
23450,
1996,
12,
25378,
697,
564,
8696,
12,
7020,
1931,
12,
272,
19952,
281,
12,
23820,
2891,
21490,
12,
13874,
12,
8777,
22382,
8884,
12,
199,
9,
421,
199,
533,
21369,
425,
2925,
8,
1746,
304,
339,
768,
3744,
272,
347,
3613,
16550,
8,
1886,
304,
267,
843,
14,
65,
17,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
2767,
18429,
28673,
320,
16305,
89,
297,
11437,
29,
1082,
9,
267,
843,
14,
65,
18,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
42,
13286,
66,
1804,
439,
1502,
13,
3716,
385,
297,
11437,
29,
1276,
9,
267,
843,
14,
65,
19,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
34,
9525,
28358,
15515,
297,
11437,
29,
2322,
9,
267,
843,
14,
65,
20,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
42,
14015,
26844,
846,
84,
297,
11437,
29,
1398,
9,
267,
843,
14,
65,
21,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
42,
3609,
17885,
2104,
559,
281,
297,
11437,
29,
1401,
9,
267,
843,
14,
65,
22,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
28282,
699,
374,
20160,
297,
11437,
29,
1398,
9,
267,
843,
14,
65,
23,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
55,
397,
15515,
1603,
14,
2799,
324,
297,
11437,
29,
821,
9,
267,
843,
14,
65,
24,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
8070,
351,
653,
269,
433,
71,
297,
11437,
29,
1641,
9,
267,
843,
14,
65,
25,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
933,
85,
580,
820,
527,
23235,
297,
11437,
29,
2466,
9,
267,
843,
14,
65,
17,
14,
18024,
14,
525,
8,
1886,
14,
65,
18,
12,
843,
14,
65,
20,
9,
267,
843,
14,
65,
18,
14,
18024,
14,
525,
8,
1886,
14,
65,
17,
12,
843,
14,
65,
23,
9,
267,
843,
14,
65,
20,
14,
18024,
14,
525,
8,
1886,
14,
65,
17,
9,
267,
843,
14,
65,
21,
14,
18024,
14,
525,
8,
1886,
14,
65,
22,
12,
843,
14,
65,
23,
9,
267,
843,
14,
65,
22,
14,
18024,
14,
525,
8,
1886,
14,
65,
21,
12,
843,
14,
65,
23,
9,
267,
843,
14,
65,
23,
14,
18024,
14,
525,
8,
1886,
14,
65,
18,
12,
843,
14,
65,
21,
12,
843,
14,
65,
22,
9,
267,
843,
14,
65,
24,
14,
18024,
14,
525,
8,
1886,
14,
65,
25,
9,
267,
843,
14,
65,
25,
14,
18024,
14,
525,
8,
1886,
14,
65,
24,
9,
398,
843,
14,
80,
17,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
534,
33,
2915,
297,
1967,
63,
31255,
29,
19,
9,
267,
843,
14,
80,
18,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
534,
51,
19470,
297,
1967,
63,
31255,
29,
17,
9,
267,
843,
14,
80,
19,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
534,
48,
828,
3548,
869,
452,
297,
1967,
63,
31255,
29,
23,
9,
267,
843,
14,
80,
20,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
534,
45,
19916,
1804,
65,
1286,
20059,
297,
1967,
63,
31255,
29,
25,
9,
267,
843,
14,
80,
21,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
628,
42,
265,
889,
1159,
869,
7130,
402,
8944,
83,
401,
1967,
63,
31255,
29,
16,
9,
398,
843,
14,
66,
17,
275,
8944,
14,
1462,
14,
981,
8,
288,
365,
10472,
534,
1046,
2710,
15459,
821,
297,
536,
534,
1918,
22659,
857,
15423,
370,
5634,
26,
6001,
15290,
23541,
20854,
297,
288,
6497,
29,
20773,
12,
18360,
29,
20,
14,
21,
12,
8033,
29,
6745,
360,
1216,
14,
383,
659,
8966,
29,
1886,
14,
65,
17,
12,
19704,
29,
1886,
14,
80,
17,
12,
288,
7974,
602,
29,
2083,
14,
602,
8,
9488,
12,
3144,
12,
1227,
9,
267,
776,
267,
843,
14,
66,
18,
275,
8944,
14,
1462,
14,
981,
8,
288,
365,
10472,
534,
1690,
2819,
11685,
1427,
297,
536,
534,
51,
19470,
5773,
1225,
19519,
277,
5634,
315,
5504,
869,
16363,
297,
288,
6497,
29,
28032,
12,
18360,
29,
19,
14,
16,
12,
8033,
29,
6745,
360,
1789,
14,
1643,
659,
8966,
29,
1886,
14,
65,
19,
12,
19704,
29,
1886,
14,
80,
18,
12,
288,
7974,
602,
29,
2083,
14,
602,
8,
9300,
12,
650,
12,
650,
9,
267,
776,
267,
843,
14,
66,
19,
275,
8944,
14,
1462,
14,
981,
8,
288,
365,
10472,
534,
9327,
1717,
1020,
2534,
297,
536,
534,
48,
6457,
3294,
5634,
7290,
83,
297,
288,
6497,
29,
5863,
12,
18360,
29,
20,
14,
16,
12,
8033,
29,
6745,
360,
1398,
14,
1876,
659,
8966,
29,
1886,
14,
65,
20,
12,
19704,
29,
1886,
14,
80,
17,
12,
288,
7974,
602,
29,
2083,
14,
602,
8,
9300,
12,
1227,
12,
6546,
9,
267,
776,
267,
843,
14,
66,
20,
275,
8944,
14,
1462,
14,
981,
8,
288,
365,
10472,
534,
614,
708,
13251,
969,
297,
536,
534,
4718,
6001,
15290,
543,
5634,
297,
288,
6497,
29,
13595,
12,
18360,
29,
20,
14,
16,
12,
8033,
29,
6745,
360,
1398,
14,
1876,
659,
8966,
29,
1886,
14,
65,
21,
12,
19704,
29,
1886,
14,
80,
19,
12,
288,
7974,
602,
29,
2083,
14,
602,
8,
9300,
12,
4119,
12,
650,
9,
267,
776
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2197,
199,
646,
5927,
199,
504,
6107,
492,
6345,
199,
504,
4182,
492,
21829,
199,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
504,
1639,
14,
1018,
14,
3924,
492,
27691,
199,
504,
1639,
14,
697,
492,
1950,
199,
504,
1639,
14,
697,
14,
992,
492,
334,
272,
481,
12,
1413,
12,
437,
10929,
12,
14826,
12,
8228,
12,
20992,
12680,
12,
12094,
12,
1594,
12,
21107,
554,
12,
199,
9,
199,
504,
1639,
14,
396,
492,
7640,
12,
3372,
5524,
9874,
18093,
12,
3372,
5524,
18093,
199,
504,
1639,
14,
396,
14,
1208,
492,
13450,
8221,
6897,
199,
504,
1639,
14,
1208,
492,
3816,
199,
199,
504,
1275,
992,
492,
334,
272,
437,
276,
65,
12,
6529,
12,
8944,
12,
32377,
2392,
12,
6659,
21530,
12,
8465,
10138,
12,
23450,
1996,
12,
25378,
697,
564,
8696,
12,
7020,
1931,
12,
272,
19952,
281,
12,
23820,
2891,
21490,
12,
13874,
12,
8777,
22382,
8884,
12,
199,
9,
421,
199,
533,
21369,
425,
2925,
8,
1746,
304,
339,
768,
3744,
272,
347,
3613,
16550,
8,
1886,
304,
267,
843,
14,
65,
17,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
2767,
18429,
28673,
320,
16305,
89,
297,
11437,
29,
1082,
9,
267,
843,
14,
65,
18,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
42,
13286,
66,
1804,
439,
1502,
13,
3716,
385,
297,
11437,
29,
1276,
9,
267,
843,
14,
65,
19,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
34,
9525,
28358,
15515,
297,
11437,
29,
2322,
9,
267,
843,
14,
65,
20,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
42,
14015,
26844,
846,
84,
297,
11437,
29,
1398,
9,
267,
843,
14,
65,
21,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
42,
3609,
17885,
2104,
559,
281,
297,
11437,
29,
1401,
9,
267,
843,
14,
65,
22,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
28282,
699,
374,
20160,
297,
11437,
29,
1398,
9,
267,
843,
14,
65,
23,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
55,
397,
15515,
1603,
14,
2799,
324,
297,
11437,
29,
821,
9,
267,
843,
14,
65,
24,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
8070,
351,
653,
269,
433,
71,
297,
11437,
29,
1641,
9,
267,
843,
14,
65,
25,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
933,
85,
580,
820,
527,
23235,
297,
11437,
29,
2466,
9,
267,
843,
14,
65,
17,
14,
18024,
14,
525,
8,
1886,
14,
65,
18,
12,
843,
14,
65,
20,
9,
267,
843,
14,
65,
18,
14,
18024,
14,
525,
8,
1886,
14,
65,
17,
12,
843,
14,
65,
23,
9,
267,
843,
14,
65,
20,
14,
18024,
14,
525,
8,
1886,
14,
65,
17,
9,
267,
843,
14,
65,
21,
14,
18024,
14,
525,
8,
1886,
14,
65,
22,
12,
843,
14,
65,
23,
9,
267,
843,
14,
65,
22,
14,
18024,
14,
525,
8,
1886,
14,
65,
21,
12,
843,
14,
65,
23,
9,
267,
843,
14,
65,
23,
14,
18024,
14,
525,
8,
1886,
14,
65,
18,
12,
843,
14,
65,
21,
12,
843,
14,
65,
22,
9,
267,
843,
14,
65,
24,
14,
18024,
14,
525,
8,
1886,
14,
65,
25,
9,
267,
843,
14,
65,
25,
14,
18024,
14,
525,
8,
1886,
14,
65,
24,
9,
398,
843,
14,
80,
17,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
534,
33,
2915,
297,
1967,
63,
31255,
29,
19,
9,
267,
843,
14,
80,
18,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
534,
51,
19470,
297,
1967,
63,
31255,
29,
17,
9,
267,
843,
14,
80,
19,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
534,
48,
828,
3548,
869,
452,
297,
1967,
63,
31255,
29,
23,
9,
267,
843,
14,
80,
20,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
534,
45,
19916,
1804,
65,
1286,
20059,
297,
1967,
63,
31255,
29,
25,
9,
267,
843,
14,
80,
21,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
628,
42,
265,
889,
1159,
869,
7130,
402,
8944,
83,
401,
1967,
63,
31255,
29,
16,
9,
398,
843,
14,
66,
17,
275,
8944,
14,
1462,
14,
981,
8,
288,
365,
10472,
534,
1046,
2710,
15459,
821,
297,
536,
534,
1918,
22659,
857,
15423,
370,
5634,
26,
6001,
15290,
23541,
20854,
297,
288,
6497,
29,
20773,
12,
18360,
29,
20,
14,
21,
12,
8033,
29,
6745,
360,
1216,
14,
383,
659,
8966,
29,
1886,
14,
65,
17,
12,
19704,
29,
1886,
14,
80,
17,
12,
288,
7974,
602,
29,
2083,
14,
602,
8,
9488,
12,
3144,
12,
1227,
9,
267,
776,
267,
843,
14,
66,
18,
275,
8944,
14,
1462,
14,
981,
8,
288,
365,
10472,
534,
1690,
2819,
11685,
1427,
297,
536,
534,
51,
19470,
5773,
1225,
19519,
277,
5634,
315,
5504,
869,
16363,
297,
288,
6497,
29,
28032,
12,
18360,
29,
19,
14,
16,
12,
8033,
29,
6745,
360,
1789,
14,
1643,
659,
8966,
29,
1886,
14,
65,
19,
12,
19704,
29,
1886,
14,
80,
18,
12,
288,
7974,
602,
29,
2083,
14,
602,
8,
9300,
12,
650,
12,
650,
9,
267,
776,
267,
843,
14,
66,
19,
275,
8944,
14,
1462,
14,
981,
8,
288,
365,
10472,
534,
9327,
1717,
1020,
2534,
297,
536,
534,
48,
6457,
3294,
5634,
7290,
83,
297,
288,
6497,
29,
5863,
12,
18360,
29,
20,
14,
16,
12,
8033,
29,
6745,
360,
1398,
14,
1876,
659,
8966,
29,
1886,
14,
65,
20,
12,
19704,
29,
1886,
14,
80,
17,
12,
288,
7974,
602,
29,
2083,
14,
602,
8,
9300,
12,
1227,
12,
6546,
9,
267,
776,
267,
843,
14,
66,
20,
275,
8944,
14,
1462,
14,
981,
8,
288,
365,
10472,
534,
614,
708,
13251,
969,
297,
536,
534,
4718,
6001,
15290,
543,
5634,
297,
288,
6497,
29,
13595,
12,
18360,
29,
20,
14,
16,
12,
8033,
29,
6745,
360,
1398,
14,
1876,
659,
8966,
29,
1886,
14,
65,
21,
12,
19704,
29,
1886,
14,
80,
19,
12,
288,
7974,
602,
29,
2083,
14,
602,
8,
9300,
12,
4119,
12,
650,
9,
267,
776,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
rkashapov/buildbot
|
master/buildbot/monkeypatches/python14653.py
|
5
|
1254
|
# This file is part of Buildbot. Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This 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.
#
# Copyright Buildbot Team Members
from __future__ import absolute_import
from __future__ import print_function
import calendar
import time
def fixed_mktime_tz(data):
if data[9] is None:
# No zone info, so localtime is better assumption than GMT
return time.mktime(data[:8] + (-1,))
t = calendar.timegm(data)
return t - data[9]
def patch():
# Fix for http://bugs.python.org/issue14653 for Python 2.7.3 and below.
# Required to fix http://trac.buildbot.net/ticket/2522 issue
import email.utils
email.utils.mktime_tz = fixed_mktime_tz
|
gpl-2.0
|
[
3,
961,
570,
365,
1777,
402,
6516,
3018,
14,
221,
6516,
3018,
365,
2867,
2032,
26,
1265,
883,
199,
3,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
12,
1015,
499,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
199,
3,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
199,
3,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
199,
3,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
3,
199,
3,
1898,
6516,
3018,
11682,
14409,
83,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
11234,
199,
646,
900,
421,
199,
318,
6317,
63,
23456,
63,
3903,
8,
576,
304,
272,
340,
666,
59,
25,
61,
365,
488,
26,
267,
327,
3091,
5718,
2256,
12,
880,
2257,
521,
365,
8034,
30075,
2419,
19152,
267,
372,
900,
14,
23456,
8,
576,
1491,
24,
61,
435,
5868,
17,
4641,
272,
307,
275,
11234,
14,
521,
13844,
8,
576,
9,
272,
372,
307,
446,
666,
59,
25,
61,
421,
199,
318,
3371,
837,
272,
327,
14811,
367,
1455,
921,
13017,
14,
1548,
14,
1308,
15,
5237,
1079,
25401,
367,
2018,
499,
14,
23,
14,
19,
436,
5084,
14,
272,
327,
11105,
370,
5325,
1455,
921,
23047,
14,
25497,
14,
846,
15,
9201,
15,
821,
1081,
4976,
339,
492,
3031,
14,
1208,
272,
3031,
14,
1208,
14,
23456,
63,
3903,
275,
6317,
63,
23456,
63,
3903,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
961,
570,
365,
1777,
402,
6516,
3018,
14,
221,
6516,
3018,
365,
2867,
2032,
26,
1265,
883,
199,
3,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
12,
1015,
499,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
199,
3,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
199,
3,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
199,
3,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
3,
199,
3,
1898,
6516,
3018,
11682,
14409,
83,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
11234,
199,
646,
900,
421,
199,
318,
6317,
63,
23456,
63,
3903,
8,
576,
304,
272,
340,
666,
59,
25,
61,
365,
488,
26,
267,
327,
3091,
5718,
2256,
12,
880,
2257,
521,
365,
8034,
30075,
2419,
19152,
267,
372,
900,
14,
23456,
8,
576,
1491,
24,
61,
435,
5868,
17,
4641,
272,
307,
275,
11234,
14,
521,
13844,
8,
576,
9,
272,
372,
307,
446,
666,
59,
25,
61,
421,
199,
318,
3371,
837,
272,
327,
14811,
367,
1455,
921,
13017,
14,
1548,
14,
1308,
15,
5237,
1079,
25401,
367,
2018,
499,
14,
23,
14,
19,
436,
5084,
14,
272,
327,
11105,
370,
5325,
1455,
921,
23047,
14,
25497,
14,
846,
15,
9201,
15,
821,
1081,
4976,
339,
492,
3031,
14,
1208,
272,
3031,
14,
1208,
14,
23456,
63,
3903,
275,
6317,
63,
23456,
63,
3903,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
z00223295/kubernetes
|
hack/verify-flags-underscore.py
|
83
|
8826
|
#!/usr/bin/env python
# Copyright 2015 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import json
import mmap
import os
import re
import sys
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("filenames", help="list of files to check, all files if unspecified", nargs='*')
parser.add_argument("-e", "--skip-exceptions", help="ignore hack/verify-flags/exceptions.txt and print all output", action="store_true")
args = parser.parse_args()
# Cargo culted from http://stackoverflow.com/questions/898669/how-can-i-detect-if-a-file-is-binary-non-text-in-python
def is_binary(pathname):
"""Return true if the given filename is binary.
@raise EnvironmentError: if the file does not exist or cannot be accessed.
@attention: found @ http://bytes.com/topic/python/answers/21222-determine-file-type-binary-text on 6/08/2010
@author: Trent Mick <TrentM@ActiveState.com>
@author: Jorge Orpinel <jorge@orpinel.com>"""
try:
with open(pathname, 'r') as f:
CHUNKSIZE = 1024
while 1:
chunk = f.read(CHUNKSIZE)
if '\0' in chunk: # found null byte
return True
if len(chunk) < CHUNKSIZE:
break # done
except:
return True
return False
def get_all_files(rootdir):
all_files = []
for root, dirs, files in os.walk(rootdir):
# don't visit certain dirs
if 'Godeps' in dirs:
dirs.remove('Godeps')
if '_gopath' in dirs:
dirs.remove('_gopath')
if 'third_party' in dirs:
dirs.remove('third_party')
if '.git' in dirs:
dirs.remove('.git')
if 'exceptions.txt' in files:
files.remove('exceptions.txt')
if 'known-flags.txt' in files:
files.remove('known-flags.txt')
for name in files:
pathname = os.path.join(root, name)
if is_binary(pathname):
continue
all_files.append(pathname)
return all_files
def normalize_files(rootdir, files):
newfiles = []
a = ['Godeps', '_gopath', 'third_party', '.git', 'exceptions.txt', 'known-flags.txt']
for f in files:
if any(x in f for x in a):
continue
if f.endswith(".svg"):
continue
if f.endswith(".gliffy"):
continue
if f.endswith(".md"):
continue
if f.endswith(".yaml"):
continue
newfiles.append(f)
for i, f in enumerate(newfiles):
if not os.path.isabs(f):
newfiles[i] = os.path.join(rootdir, f)
return newfiles
def line_has_bad_flag(line, flagre):
results = flagre.findall(line)
for result in results:
if not "_" in result:
return False
# this should exclude many cases where jinja2 templates use kube flags
# as variables, except it uses _ for the variable name
if "{% set" + result + "= \"" in line:
return False
if "pillar[" + result + "]" in line:
return False
if "grains" + result in line:
return False
# something common in juju variables...
if "template_data[" + result + "]" in line:
return False
return True
return False
# The list of files might not be the whole repo. If someone only changed a
# couple of files we don't want to run all of the golang files looking for
# flags. Instead load the list of flags from hack/verify-flags/known-flags.txt
# If running the golang files finds a new flag not in that file, return an
# error and tell the user to add the flag to the flag list.
def get_flags(rootdir, files):
# preload the 'known' flags
pathname = os.path.join(rootdir, "hack/verify-flags/known-flags.txt")
f = open(pathname, 'r')
flags = set(f.read().splitlines())
f.close()
# preload the 'known' flags which don't follow the - standard
pathname = os.path.join(rootdir, "hack/verify-flags/excluded-flags.txt")
f = open(pathname, 'r')
excluded_flags = set(f.read().splitlines())
f.close()
regexs = [ re.compile('Var[P]?\([^,]*, "([^"]*)"'),
re.compile('.String[P]?\("([^"]*)",[^,]+,[^)]+\)'),
re.compile('.Int[P]?\("([^"]*)",[^,]+,[^)]+\)'),
re.compile('.Bool[P]?\("([^"]*)",[^,]+,[^)]+\)'),
re.compile('.Duration[P]?\("([^"]*)",[^,]+,[^)]+\)'),
re.compile('.StringSlice[P]?\("([^"]*)",[^,]+,[^)]+\)') ]
new_flags = set()
new_excluded_flags = set()
# walk all the files looking for any flags being declared
for pathname in files:
if not pathname.endswith(".go"):
continue
f = open(pathname, 'r')
data = f.read()
f.close()
matches = []
for regex in regexs:
matches = matches + regex.findall(data)
for flag in matches:
if any(x in flag for x in excluded_flags):
continue
if "_" in flag:
new_excluded_flags.add(flag)
if not "-" in flag:
continue
if flag not in flags:
new_flags.add(flag)
if len(new_excluded_flags) != 0:
print("Found a flag declared with an _ but which is not explicitly listed as a valid flag name in hack/verify-flags/excluded-flags.txt")
print("Are you certain this flag should not have been declared with an - instead?")
l = list(new_excluded_flags)
l.sort()
print("%s" % "\n".join(l))
sys.exit(1)
if len(new_flags) != 0:
print("Found flags in golang files not in the list of known flags. Please add these to hack/verify-flags/known-flags.txt")
l = list(new_flags)
l.sort()
print("%s" % "\n".join(l))
sys.exit(1)
return list(flags)
def flags_to_re(flags):
"""turn the list of all flags we found into a regex find both - and _ versions"""
dashRE = re.compile('[-_]')
flagREs = []
for flag in flags:
# turn all flag names into regexs which will find both types
newre = dashRE.sub('[-_]', flag)
# only match if there is not a leading or trailing alphanumeric character
flagREs.append("[^\w${]" + newre + "[^\w]")
# turn that list of regex strings into a single large RE
flagRE = "|".join(flagREs)
flagRE = re.compile(flagRE)
return flagRE
def load_exceptions(rootdir):
exceptions = set()
if args.skip_exceptions:
return exceptions
exception_filename = os.path.join(rootdir, "hack/verify-flags/exceptions.txt")
exception_file = open(exception_filename, 'r')
for exception in exception_file.read().splitlines():
out = exception.split(":", 1)
if len(out) != 2:
print("Invalid line in exceptions file: %s" % exception)
continue
filename = out[0]
line = out[1]
exceptions.add((filename, line))
return exceptions
def main():
rootdir = os.path.dirname(__file__) + "/../"
rootdir = os.path.abspath(rootdir)
exceptions = load_exceptions(rootdir)
if len(args.filenames) > 0:
files = args.filenames
else:
files = get_all_files(rootdir)
files = normalize_files(rootdir, files)
flags = get_flags(rootdir, files)
flagRE = flags_to_re(flags)
bad_lines = []
# walk all the file looking for any flag that was declared and now has an _
for pathname in files:
relname = os.path.relpath(pathname, rootdir)
f = open(pathname, 'r')
for line in f.read().splitlines():
if line_has_bad_flag(line, flagRE):
if (relname, line) not in exceptions:
bad_lines.append((relname, line))
f.close()
if len(bad_lines) != 0:
if not args.skip_exceptions:
print("Found illegal 'flag' usage. If these are false positives you should run `hack/verify-flags-underscore.py -e > hack/verify-flags/exceptions.txt` to update the list.")
bad_lines.sort()
for (relname, line) in bad_lines:
print("%s:%s" % (relname, line))
return 1
if __name__ == "__main__":
sys.exit(main())
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6900,
710,
28723,
6642,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2022,
199,
646,
21991,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
646,
7534,
199,
199,
2087,
275,
7534,
14,
10730,
342,
199,
2087,
14,
525,
63,
2094,
480,
10309,
401,
1720,
628,
513,
402,
1584,
370,
1104,
12,
1006,
1584,
340,
21994,
401,
9237,
534,
13418,
199,
2087,
14,
525,
63,
2094,
6096,
69,
401,
4320,
2759,
13,
3924,
401,
1720,
628,
4247,
11176,
15,
4712,
13,
2469,
15,
3924,
14,
2424,
436,
870,
1006,
1072,
401,
1595,
628,
1617,
63,
2052,
531,
199,
589,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
3,
445,
16308,
286,
30355,
687,
1455,
921,
23153,
14,
957,
15,
16069,
15,
1407,
1184,
1876,
15,
1917,
13,
2425,
13,
73,
13,
13552,
13,
692,
13,
65,
13,
493,
13,
374,
13,
3008,
13,
2865,
13,
505,
13,
262,
13,
1548,
199,
318,
365,
63,
3008,
8,
12445,
304,
272,
408,
1767,
2549,
340,
314,
1627,
1788,
365,
3366,
14,
272,
768,
3730,
25139,
26,
340,
314,
570,
1630,
440,
2187,
503,
3913,
506,
13810,
14,
272,
768,
22393,
26,
1911,
768,
1455,
921,
2394,
14,
957,
15,
5746,
15,
1548,
15,
13379,
15,
11722,
1081,
13,
22189,
13,
493,
13,
466,
13,
3008,
13,
505,
641,
1227,
15,
2036,
15,
6542,
272,
768,
2502,
26,
377,
640,
603,
2000,
665,
52,
640,
45,
32,
7472,
2223,
14,
957,
30,
272,
768,
2502,
26,
1603,
24591,
4236,
7751,
352,
665,
5857,
303,
32,
269,
7751,
352,
14,
957,
11193,
272,
862,
26,
267,
543,
1551,
8,
12445,
12,
283,
82,
358,
465,
289,
26,
288,
6624,
8019,
4305,
275,
6619,
288,
1830,
413,
26,
355,
3728,
275,
289,
14,
739,
8,
20512,
4305,
9,
355,
340,
1557,
16,
7,
315,
3728,
26,
327,
1911,
2973,
3696,
490,
372,
715,
355,
340,
822,
8,
4604,
9,
665,
6624,
8019,
4305,
26,
490,
2059,
327,
4224,
272,
871,
26,
267,
372,
715,
339,
372,
756,
199,
199,
318,
664,
63,
452,
63,
1725,
8,
1231,
694,
304,
272,
1006,
63,
1725,
275,
942,
272,
367,
1738,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
1231,
694,
304,
267,
327,
2793,
1133,
5684,
9842,
7606,
267,
340,
283,
39,
380,
1190,
7,
315,
7606,
26,
288,
7606,
14,
2168,
360,
39,
380,
1190,
358,
267,
340,
2513,
1939,
515,
7,
315,
7606,
26,
288,
7606,
14,
2168,
6412,
1939,
515,
358,
267,
340,
283,
11470,
63,
7522,
7,
315,
7606,
26,
288,
7606,
14,
2168,
360,
11470,
63,
7522,
358,
267,
340,
1987,
3187,
7,
315,
7606,
26,
288,
7606,
14,
2168,
5175,
3187,
358,
267,
340,
283,
3924,
14,
2424,
7,
315,
1584,
26,
288,
1584,
14,
2168,
360,
3924,
14,
2424,
358,
267,
340,
283,
3159,
13,
2469,
14,
2424,
7,
315,
1584,
26,
288,
1584,
14,
2168,
360,
3159,
13,
2469,
14,
2424,
358,
398,
367,
536,
315,
1584,
26,
288,
11776,
275,
747,
14,
515,
14,
904,
8,
1231,
12,
536,
9,
288,
340,
365,
63,
3008,
8,
12445,
304,
355,
1980,
288,
1006,
63,
1725,
14,
740,
8,
12445,
9,
272,
372,
1006,
63,
1725,
199,
199,
318,
7666,
63,
1725,
8,
1231,
694,
12,
1584,
304,
272,
892,
1725,
275,
942,
272,
282,
275,
788,
39,
380,
1190,
297,
2513,
1939,
515,
297,
283,
11470,
63,
7522,
297,
1987,
3187,
297,
283,
3924,
14,
2424,
297,
283,
3159,
13,
2469,
14,
2424,
418,
272,
367,
289,
315,
1584,
26,
267,
340,
1263,
8,
88,
315,
289,
367,
671,
315,
282,
304,
288,
1980,
267,
340,
289,
14,
4130,
9520,
10273,
2349,
288,
1980,
267,
340,
289,
14,
4130,
9520,
71,
317,
556,
89,
2349,
288,
1980,
267,
340,
289,
14,
4130,
9520,
1064,
2349,
288,
1980,
267,
340,
289,
14,
4130,
9520,
5963,
2349,
288,
1980,
267,
892,
1725,
14,
740,
8,
70,
9,
272,
367,
284,
12,
289,
315,
3874,
8,
1222,
1725,
304,
267,
340,
440,
747,
14,
515,
14,
17896,
8,
70,
304,
288,
892,
1725,
59,
73,
61,
275,
747,
14,
515,
14,
904,
8,
1231,
694,
12,
289,
9,
272,
372,
892,
1725,
199,
199,
318,
1004,
63,
1989,
63,
4087,
63,
4173,
8,
604,
12,
3305,
264,
304,
272,
2058,
221,
275,
3305,
264,
14,
6452,
8,
604,
9,
272,
367,
754,
315,
2058,
26,
267,
340,
440,
14220,
315,
754,
26,
288,
372,
756,
267,
327,
642,
1077,
5760,
5002,
5560,
2382,
10321,
18,
7009,
675,
23091,
3285,
267,
327,
465,
2860,
12,
871,
652,
4440,
485,
367,
314,
1750,
536,
267,
340,
22704,
663,
2,
435,
754,
435,
298,
29,
19669,
315,
1004,
26,
288,
372,
756,
267,
340,
298,
80,
778,
285,
905,
435,
754,
435,
298,
8480,
315,
1004,
26,
288,
372,
756,
267,
340,
298,
926,
3617,
2,
435,
754,
315,
1004,
26,
288,
372,
756,
268,
327,
6020,
2863,
315,
1335,
17189,
85,
2860,
1396,
267,
340,
298,
1160,
63,
576,
905,
435,
754,
435,
298,
8480,
315,
1004,
26,
288,
372,
756,
267,
372,
715,
272,
372,
756,
199,
199,
3,
710,
769,
402,
1584,
5594,
440,
506,
314,
8852,
3831,
14,
982,
17122,
1454,
2896,
282,
199,
3,
17535,
402,
1584,
781,
2793,
1133
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6900,
710,
28723,
6642,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2022,
199,
646,
21991,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
646,
7534,
199,
199,
2087,
275,
7534,
14,
10730,
342,
199,
2087,
14,
525,
63,
2094,
480,
10309,
401,
1720,
628,
513,
402,
1584,
370,
1104,
12,
1006,
1584,
340,
21994,
401,
9237,
534,
13418,
199,
2087,
14,
525,
63,
2094,
6096,
69,
401,
4320,
2759,
13,
3924,
401,
1720,
628,
4247,
11176,
15,
4712,
13,
2469,
15,
3924,
14,
2424,
436,
870,
1006,
1072,
401,
1595,
628,
1617,
63,
2052,
531,
199,
589,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
3,
445,
16308,
286,
30355,
687,
1455,
921,
23153,
14,
957,
15,
16069,
15,
1407,
1184,
1876,
15,
1917,
13,
2425,
13,
73,
13,
13552,
13,
692,
13,
65,
13,
493,
13,
374,
13,
3008,
13,
2865,
13,
505,
13,
262,
13,
1548,
199,
318,
365,
63,
3008,
8,
12445,
304,
272,
408,
1767,
2549,
340,
314,
1627,
1788,
365,
3366,
14,
272,
768,
3730,
25139,
26,
340,
314,
570,
1630,
440,
2187,
503,
3913,
506,
13810,
14,
272,
768,
22393,
26,
1911,
768,
1455,
921,
2394,
14,
957,
15,
5746,
15,
1548,
15,
13379,
15,
11722,
1081,
13,
22189,
13,
493,
13,
466,
13,
3008,
13,
505,
641,
1227,
15,
2036,
15,
6542,
272,
768,
2502,
26,
377,
640,
603,
2000,
665,
52,
640,
45,
32,
7472,
2223,
14,
957,
30,
272,
768,
2502,
26,
1603,
24591,
4236,
7751,
352,
665,
5857,
303,
32,
269,
7751,
352,
14,
957,
11193,
272,
862,
26,
267,
543,
1551,
8,
12445,
12,
283,
82,
358,
465,
289,
26,
288,
6624,
8019,
4305,
275,
6619,
288,
1830,
413,
26,
355,
3728,
275,
289,
14,
739,
8,
20512,
4305,
9,
355,
340,
1557,
16,
7,
315,
3728,
26,
327,
1911,
2973,
3696,
490,
372,
715,
355,
340,
822,
8,
4604,
9,
665,
6624,
8019,
4305,
26,
490,
2059,
327,
4224,
272,
871,
26,
267,
372,
715,
339,
372,
756,
199,
199,
318,
664,
63,
452,
63,
1725,
8,
1231,
694,
304,
272,
1006,
63,
1725,
275,
942,
272,
367,
1738,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
1231,
694,
304,
267,
327,
2793,
1133,
5684,
9842,
7606,
267,
340,
283,
39,
380,
1190,
7,
315,
7606,
26,
288,
7606,
14,
2168,
360,
39,
380,
1190,
358,
267,
340,
2513,
1939,
515,
7,
315,
7606,
26,
288,
7606,
14,
2168,
6412,
1939,
515,
358,
267,
340,
283,
11470,
63,
7522,
7,
315,
7606,
26,
288,
7606,
14,
2168,
360,
11470,
63,
7522,
358,
267,
340,
1987,
3187,
7,
315,
7606,
26,
288,
7606,
14,
2168,
5175,
3187,
358,
267,
340,
283,
3924,
14,
2424,
7,
315,
1584,
26,
288,
1584,
14,
2168,
360,
3924,
14,
2424,
358,
267,
340,
283,
3159,
13,
2469,
14,
2424,
7,
315,
1584,
26,
288,
1584,
14,
2168,
360,
3159,
13,
2469,
14,
2424,
358,
398,
367,
536,
315,
1584,
26,
288,
11776,
275,
747,
14,
515,
14,
904,
8,
1231,
12,
536,
9,
288,
340,
365,
63,
3008,
8,
12445,
304,
355,
1980,
288,
1006,
63,
1725,
14,
740,
8,
12445,
9,
272,
372,
1006,
63,
1725,
199,
199,
318,
7666,
63,
1725,
8,
1231,
694,
12,
1584,
304,
272,
892,
1725,
275,
942,
272,
282,
275,
788,
39,
380,
1190,
297,
2513,
1939,
515,
297,
283,
11470,
63,
7522,
297,
1987,
3187,
297,
283,
3924,
14,
2424,
297,
283,
3159,
13,
2469,
14,
2424,
418,
272,
367,
289,
315,
1584,
26,
267,
340,
1263,
8,
88,
315,
289,
367,
671,
315,
282,
304,
288,
1980,
267,
340,
289,
14,
4130,
9520,
10273,
2349,
288,
1980,
267,
340,
289,
14,
4130,
9520,
71,
317,
556,
89,
2349,
288,
1980,
267,
340,
289,
14,
4130,
9520,
1064,
2349,
288,
1980,
267,
340,
289,
14,
4130,
9520,
5963,
2349,
288,
1980,
267,
892,
1725,
14,
740,
8,
70,
9,
272,
367,
284,
12,
289,
315,
3874,
8,
1222,
1725,
304,
267,
340,
440,
747,
14,
515,
14,
17896,
8,
70,
304,
288,
892,
1725,
59,
73,
61,
275,
747,
14,
515,
14,
904,
8,
1231,
694,
12,
289,
9,
272,
372,
892,
1725,
199,
199,
318,
1004,
63,
1989,
63,
4087,
63,
4173,
8,
604,
12,
3305,
264,
304,
272,
2058,
221,
275,
3305,
264,
14,
6452,
8,
604,
9,
272,
367,
754,
315,
2058,
26,
267,
340,
440,
14220,
315,
754,
26,
288,
372,
756,
267,
327,
642,
1077,
5760,
5002,
5560,
2382,
10321,
18,
7009,
675,
23091,
3285,
267,
327,
465,
2860,
12,
871,
652,
4440,
485,
367,
314,
1750,
536,
267,
340,
22704,
663,
2,
435,
754,
435,
298,
29,
19669,
315,
1004,
26,
288,
372,
756,
267,
340,
298,
80,
778,
285,
905,
435,
754,
435,
298,
8480,
315,
1004,
26,
288,
372,
756,
267,
340,
298,
926,
3617,
2,
435,
754,
315,
1004,
26,
288,
372,
756,
268,
327,
6020,
2863,
315,
1335,
17189,
85,
2860,
1396,
267,
340,
298,
1160,
63,
576,
905,
435,
754,
435,
298,
8480,
315,
1004,
26,
288,
372,
756,
267,
372,
715,
272,
372,
756,
199,
199,
3,
710,
769,
402,
1584,
5594,
440,
506,
314,
8852,
3831,
14,
982,
17122,
1454,
2896,
282,
199,
3,
17535,
402,
1584,
781,
2793,
1133,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ibazzi/xbmc
|
addons/script.module.requests/lib/requests/packages/urllib3/_collections.py
|
666
|
10553
|
from __future__ import absolute_import
from collections import Mapping, MutableMapping
try:
from threading import RLock
except ImportError: # Platform-specific: No threads available
class RLock:
def __enter__(self):
pass
def __exit__(self, exc_type, exc_value, traceback):
pass
try: # Python 2.7+
from collections import OrderedDict
except ImportError:
from .packages.ordered_dict import OrderedDict
from .packages.six import iterkeys, itervalues, PY3
__all__ = ['RecentlyUsedContainer', 'HTTPHeaderDict']
_Null = object()
class RecentlyUsedContainer(MutableMapping):
"""
Provides a thread-safe dict-like container which maintains up to
``maxsize`` keys while throwing away the least-recently-used keys beyond
``maxsize``.
:param maxsize:
Maximum number of recent elements to retain.
:param dispose_func:
Every time an item is evicted from the container,
``dispose_func(value)`` is called. Callback which will get called
"""
ContainerCls = OrderedDict
def __init__(self, maxsize=10, dispose_func=None):
self._maxsize = maxsize
self.dispose_func = dispose_func
self._container = self.ContainerCls()
self.lock = RLock()
def __getitem__(self, key):
# Re-insert the item, moving it to the end of the eviction line.
with self.lock:
item = self._container.pop(key)
self._container[key] = item
return item
def __setitem__(self, key, value):
evicted_value = _Null
with self.lock:
# Possibly evict the existing value of 'key'
evicted_value = self._container.get(key, _Null)
self._container[key] = value
# If we didn't evict an existing value, we might have to evict the
# least recently used item from the beginning of the container.
if len(self._container) > self._maxsize:
_key, evicted_value = self._container.popitem(last=False)
if self.dispose_func and evicted_value is not _Null:
self.dispose_func(evicted_value)
def __delitem__(self, key):
with self.lock:
value = self._container.pop(key)
if self.dispose_func:
self.dispose_func(value)
def __len__(self):
with self.lock:
return len(self._container)
def __iter__(self):
raise NotImplementedError('Iteration over this class is unlikely to be threadsafe.')
def clear(self):
with self.lock:
# Copy pointers to all values, then wipe the mapping
values = list(itervalues(self._container))
self._container.clear()
if self.dispose_func:
for value in values:
self.dispose_func(value)
def keys(self):
with self.lock:
return list(iterkeys(self._container))
class HTTPHeaderDict(MutableMapping):
"""
:param headers:
An iterable of field-value pairs. Must not contain multiple field names
when compared case-insensitively.
:param kwargs:
Additional field-value pairs to pass in to ``dict.update``.
A ``dict`` like container for storing HTTP Headers.
Field names are stored and compared case-insensitively in compliance with
RFC 7230. Iteration provides the first case-sensitive key seen for each
case-insensitive pair.
Using ``__setitem__`` syntax overwrites fields that compare equal
case-insensitively in order to maintain ``dict``'s api. For fields that
compare equal, instead create a new ``HTTPHeaderDict`` and use ``.add``
in a loop.
If multiple fields that are equal case-insensitively are passed to the
constructor or ``.update``, the behavior is undefined and some will be
lost.
>>> headers = HTTPHeaderDict()
>>> headers.add('Set-Cookie', 'foo=bar')
>>> headers.add('set-cookie', 'baz=quxx')
>>> headers['content-length'] = '7'
>>> headers['SET-cookie']
'foo=bar, baz=quxx'
>>> headers['Content-Length']
'7'
"""
def __init__(self, headers=None, **kwargs):
super(HTTPHeaderDict, self).__init__()
self._container = OrderedDict()
if headers is not None:
if isinstance(headers, HTTPHeaderDict):
self._copy_from(headers)
else:
self.extend(headers)
if kwargs:
self.extend(kwargs)
def __setitem__(self, key, val):
self._container[key.lower()] = (key, val)
return self._container[key.lower()]
def __getitem__(self, key):
val = self._container[key.lower()]
return ', '.join(val[1:])
def __delitem__(self, key):
del self._container[key.lower()]
def __contains__(self, key):
return key.lower() in self._container
def __eq__(self, other):
if not isinstance(other, Mapping) and not hasattr(other, 'keys'):
return False
if not isinstance(other, type(self)):
other = type(self)(other)
return (dict((k.lower(), v) for k, v in self.itermerged()) ==
dict((k.lower(), v) for k, v in other.itermerged()))
def __ne__(self, other):
return not self.__eq__(other)
if not PY3: # Python 2
iterkeys = MutableMapping.iterkeys
itervalues = MutableMapping.itervalues
__marker = object()
def __len__(self):
return len(self._container)
def __iter__(self):
# Only provide the originally cased names
for vals in self._container.values():
yield vals[0]
def pop(self, key, default=__marker):
'''D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised.
'''
# Using the MutableMapping function directly fails due to the private marker.
# Using ordinary dict.pop would expose the internal structures.
# So let's reinvent the wheel.
try:
value = self[key]
except KeyError:
if default is self.__marker:
raise
return default
else:
del self[key]
return value
def discard(self, key):
try:
del self[key]
except KeyError:
pass
def add(self, key, val):
"""Adds a (name, value) pair, doesn't overwrite the value if it already
exists.
>>> headers = HTTPHeaderDict(foo='bar')
>>> headers.add('Foo', 'baz')
>>> headers['foo']
'bar, baz'
"""
key_lower = key.lower()
new_vals = key, val
# Keep the common case aka no item present as fast as possible
vals = self._container.setdefault(key_lower, new_vals)
if new_vals is not vals:
# new_vals was not inserted, as there was a previous one
if isinstance(vals, list):
# If already several items got inserted, we have a list
vals.append(val)
else:
# vals should be a tuple then, i.e. only one item so far
# Need to convert the tuple to list for further extension
self._container[key_lower] = [vals[0], vals[1], val]
def extend(self, *args, **kwargs):
"""Generic import function for any type of header-like object.
Adapted version of MutableMapping.update in order to insert items
with self.add instead of self.__setitem__
"""
if len(args) > 1:
raise TypeError("extend() takes at most 1 positional "
"arguments ({0} given)".format(len(args)))
other = args[0] if len(args) >= 1 else ()
if isinstance(other, HTTPHeaderDict):
for key, val in other.iteritems():
self.add(key, val)
elif isinstance(other, Mapping):
for key in other:
self.add(key, other[key])
elif hasattr(other, "keys"):
for key in other.keys():
self.add(key, other[key])
else:
for key, value in other:
self.add(key, value)
for key, value in kwargs.items():
self.add(key, value)
def getlist(self, key):
"""Returns a list of all the values for the named field. Returns an
empty list if the key doesn't exist."""
try:
vals = self._container[key.lower()]
except KeyError:
return []
else:
if isinstance(vals, tuple):
return [vals[1]]
else:
return vals[1:]
# Backwards compatibility for httplib
getheaders = getlist
getallmatchingheaders = getlist
iget = getlist
def __repr__(self):
return "%s(%s)" % (type(self).__name__, dict(self.itermerged()))
def _copy_from(self, other):
for key in other:
val = other.getlist(key)
if isinstance(val, list):
# Don't need to convert tuples
val = list(val)
self._container[key.lower()] = [key] + val
def copy(self):
clone = type(self)()
clone._copy_from(self)
return clone
def iteritems(self):
"""Iterate over all header lines, including duplicate ones."""
for key in self:
vals = self._container[key.lower()]
for val in vals[1:]:
yield vals[0], val
def itermerged(self):
"""Iterate over all headers, merging duplicate ones together."""
for key in self:
val = self._container[key.lower()]
yield val[0], ', '.join(val[1:])
def items(self):
return list(self.iteritems())
@classmethod
def from_httplib(cls, message): # Python 2
"""Read headers from a Python 2 httplib message object."""
# python2.7 does not expose a proper API for exporting multiheaders
# efficiently. This function re-reads raw lines from the message
# object and extracts the multiheaders properly.
headers = []
for line in message.headers:
if line.startswith((' ', '\t')):
key, value = headers[-1]
headers[-1] = (key, value + '\r\n' + line.rstrip())
continue
key, value = line.split(':', 1)
headers.append((key, value.strip()))
return cls(headers)
|
gpl-2.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
5055,
492,
12340,
12,
29396,
199,
893,
26,
272,
687,
5796,
492,
820,
6432,
199,
2590,
3545,
26,
221,
327,
16078,
13,
6100,
26,
3091,
7183,
2808,
272,
1021,
820,
6432,
26,
267,
347,
636,
4200,
721,
277,
304,
288,
986,
398,
347,
636,
2224,
721,
277,
12,
3178,
63,
466,
12,
3178,
63,
585,
12,
5190,
304,
288,
986,
421,
199,
893,
26,
221,
327,
2018,
499,
14,
23,
11,
272,
687,
5055,
492,
8773,
199,
2590,
3545,
26,
272,
687,
1275,
5154,
14,
8235,
63,
807,
492,
8773,
199,
504,
1275,
5154,
14,
4174,
492,
25706,
12,
24451,
12,
7843,
19,
421,
199,
363,
452,
363,
275,
788,
29574,
590,
9167,
4076,
297,
283,
2856,
2567,
2141,
418,
421,
199,
63,
8849,
275,
909,
342,
421,
199,
533,
799,
2946,
590,
9167,
4076,
8,
17707,
7674,
304,
272,
408,
272,
21552,
282,
2462,
13,
3489,
1211,
13,
2930,
3970,
1314,
11075,
83,
1536,
370,
272,
1124,
13634,
1040,
2883,
1830,
7978,
316,
13437,
314,
5210,
13,
14951,
590,
13,
2972,
2883,
20561,
272,
1124,
13634,
4345,
339,
520,
635,
19791,
26,
267,
14212,
1329,
402,
8058,
4008,
370,
8074,
14,
339,
520,
635,
2153,
4070,
63,
1532,
26,
267,
18414,
900,
376,
1242,
365,
24656,
1522,
687,
314,
3970,
12,
267,
1124,
29842,
63,
1532,
8,
585,
9719,
365,
2797,
14,
221,
17555,
1314,
911,
664,
2797,
272,
408,
339,
15395,
24342,
275,
8773,
339,
347,
636,
826,
721,
277,
12,
19791,
29,
709,
12,
2153,
4070,
63,
1532,
29,
403,
304,
267,
291,
423,
13634,
275,
19791,
267,
291,
14,
29842,
63,
1532,
275,
2153,
4070,
63,
1532,
398,
291,
423,
3600,
275,
291,
14,
4076,
24342,
342,
267,
291,
14,
831,
275,
820,
6432,
342,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
327,
799,
13,
3176,
314,
1242,
12,
12876,
652,
370,
314,
1284,
402,
314,
24656,
414,
1004,
14,
267,
543,
291,
14,
831,
26,
288,
1242,
275,
291,
423,
3600,
14,
1935,
8,
498,
9,
288,
291,
423,
3600,
59,
498,
61,
275,
1242,
288,
372,
1242,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
24656,
1522,
63,
585,
275,
485,
8849,
267,
543,
291,
14,
831,
26,
288,
327,
25987,
9312,
24656,
319,
314,
3411,
574,
402,
283,
498,
7,
288,
24656,
1522,
63,
585,
275,
291,
423,
3600,
14,
362,
8,
498,
12,
485,
8849,
9,
288,
291,
423,
3600,
59,
498,
61,
275,
574,
953,
327,
982,
781,
9980,
1133,
24656,
319,
376,
3411,
574,
12,
781,
5594,
1172,
370,
24656,
319,
314,
288,
327,
5210,
23568,
1202,
1242,
687,
314,
9608,
402,
314,
3970,
14,
288,
340,
822,
8,
277,
423,
3600,
9,
690,
291,
423,
13634,
26,
355,
485,
498,
12,
24656,
1522,
63,
585,
275,
291,
423,
3600,
14,
24882,
8,
2019,
29,
797,
9,
398,
340,
291,
14,
29842,
63,
1532,
436,
24656,
1522,
63,
585,
365,
440,
485,
8849,
26,
288,
291,
14,
29842,
63,
1532,
8,
69,
433,
1522,
63,
585,
9,
339,
347,
636,
13228,
721,
277,
12,
790,
304,
267,
543,
291,
14,
831,
26,
288,
574,
275,
291,
423,
3600,
14,
1935,
8,
498,
9,
398,
340,
291,
14,
29842,
63,
1532,
26,
288,
291,
14,
29842,
63,
1532,
8,
585,
9,
339,
347,
636,
552,
721,
277,
304,
267,
543,
291,
14,
831,
26,
288,
372,
822,
8,
277,
423,
3600,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
746,
4279,
360,
8666,
1806,
642,
1021,
365,
625,
24227,
370,
506,
2462,
3489,
2659,
339,
347,
5436,
8,
277,
304,
267,
543,
291,
14,
831,
26,
288,
327,
11247,
21116,
370,
1006,
1338,
12,
2066,
336,
3662,
314,
4412,
288,
1338,
275,
769,
8,
13012,
8,
277,
423,
3600,
430,
288,
291,
423,
3600,
14,
3584,
342,
398,
340,
291,
14,
29842,
63,
1532,
26,
288,
367,
574,
315,
1338,
26,
355,
291,
14,
29842,
63,
1532,
8,
585,
9,
339,
347,
2883,
8,
277,
304,
267,
543,
291,
14,
831,
26,
288,
372,
769,
8,
16007,
8,
277,
423,
3600,
430,
421,
199,
533,
3101,
2567,
2141,
8,
17707,
7674,
304,
272,
408,
272,
520,
635,
2323,
26,
267,
1626,
6076,
402,
901,
13,
585,
6342,
14,
9498,
440,
1395,
3663,
901,
1561,
267,
1380,
13524,
1930,
13,
262,
2464,
338,
9462,
14,
339,
520,
635,
2074,
26,
267,
10961,
901,
13,
585,
6342,
370,
986,
315,
370,
1124,
807,
14,
873,
4345,
339,
437,
1124,
807,
1040,
2839,
3970,
367,
16915,
3101,
21391,
14,
339,
5024,
1561,
787,
5489,
436,
13524,
1930,
13,
262,
2464,
338,
9462,
315,
4151,
543,
272,
7329,
1520,
9687,
14,
473,
5388,
6571,
314,
1642,
1930,
13,
7361,
790,
6775,
367,
1924,
272,
1930,
13,
15851,
4092,
14,
339,
11719,
9035,
8617,
18762,
6302,
1806,
16334,
1504,
626,
6540,
4472,
272,
1930,
13,
262,
2464,
338,
9462,
315,
1865,
370,
11075,
1124,
807,
1040,
7,
83,
2986,
14,
2104,
1504,
626,
272,
6540,
4472,
12,
3140,
1218,
282,
892,
1124,
2856,
2567,
2141,
1040,
436,
675,
21502,
525,
1040,
272,
315,
282,
4438,
14,
339,
982,
3663,
1504,
626,
787,
4472,
1930,
13,
262,
2464,
338,
9462,
787,
3032,
370,
314,
272,
3787,
503,
21502,
873,
4542,
314,
5953,
365,
10942,
436,
2005,
911,
506,
272,
14669,
14,
339,
1306,
2323,
275,
3101,
2567,
2141,
342,
272,
1306,
2323,
14,
525,
360,
1084,
13,
7810,
297,
283,
1421,
29,
1700,
358,
272,
1306,
2323,
14,
525,
360,
409,
13,
5306,
297,
283,
6185,
29,
392,
2154,
358,
272,
1306,
2323,
459,
1317,
13,
1267,
418,
275,
283,
23,
7,
272,
1306,
2323,
459,
3597,
13,
5306,
418,
272,
283,
1421,
29,
1700,
12,
15507,
29,
392,
2154,
7,
272,
1306,
2323,
459,
2714,
13,
4625,
418,
272,
283,
23,
7,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2323,
29,
403,
12,
1011,
958,
304,
267,
1613,
8,
2856,
2567,
2141,
12,
291,
2843,
826,
4533,
267,
291,
423,
3600,
275,
8773,
342,
267,
340,
2323,
365,
440,
488,
26,
288,
340,
1228,
8,
2139,
12,
3101,
2567,
2141
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
5055,
492,
12340,
12,
29396,
199,
893,
26,
272,
687,
5796,
492,
820,
6432,
199,
2590,
3545,
26,
221,
327,
16078,
13,
6100,
26,
3091,
7183,
2808,
272,
1021,
820,
6432,
26,
267,
347,
636,
4200,
721,
277,
304,
288,
986,
398,
347,
636,
2224,
721,
277,
12,
3178,
63,
466,
12,
3178,
63,
585,
12,
5190,
304,
288,
986,
421,
199,
893,
26,
221,
327,
2018,
499,
14,
23,
11,
272,
687,
5055,
492,
8773,
199,
2590,
3545,
26,
272,
687,
1275,
5154,
14,
8235,
63,
807,
492,
8773,
199,
504,
1275,
5154,
14,
4174,
492,
25706,
12,
24451,
12,
7843,
19,
421,
199,
363,
452,
363,
275,
788,
29574,
590,
9167,
4076,
297,
283,
2856,
2567,
2141,
418,
421,
199,
63,
8849,
275,
909,
342,
421,
199,
533,
799,
2946,
590,
9167,
4076,
8,
17707,
7674,
304,
272,
408,
272,
21552,
282,
2462,
13,
3489,
1211,
13,
2930,
3970,
1314,
11075,
83,
1536,
370,
272,
1124,
13634,
1040,
2883,
1830,
7978,
316,
13437,
314,
5210,
13,
14951,
590,
13,
2972,
2883,
20561,
272,
1124,
13634,
4345,
339,
520,
635,
19791,
26,
267,
14212,
1329,
402,
8058,
4008,
370,
8074,
14,
339,
520,
635,
2153,
4070,
63,
1532,
26,
267,
18414,
900,
376,
1242,
365,
24656,
1522,
687,
314,
3970,
12,
267,
1124,
29842,
63,
1532,
8,
585,
9719,
365,
2797,
14,
221,
17555,
1314,
911,
664,
2797,
272,
408,
339,
15395,
24342,
275,
8773,
339,
347,
636,
826,
721,
277,
12,
19791,
29,
709,
12,
2153,
4070,
63,
1532,
29,
403,
304,
267,
291,
423,
13634,
275,
19791,
267,
291,
14,
29842,
63,
1532,
275,
2153,
4070,
63,
1532,
398,
291,
423,
3600,
275,
291,
14,
4076,
24342,
342,
267,
291,
14,
831,
275,
820,
6432,
342,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
327,
799,
13,
3176,
314,
1242,
12,
12876,
652,
370,
314,
1284,
402,
314,
24656,
414,
1004,
14,
267,
543,
291,
14,
831,
26,
288,
1242,
275,
291,
423,
3600,
14,
1935,
8,
498,
9,
288,
291,
423,
3600,
59,
498,
61,
275,
1242,
288,
372,
1242,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
24656,
1522,
63,
585,
275,
485,
8849,
267,
543,
291,
14,
831,
26,
288,
327,
25987,
9312,
24656,
319,
314,
3411,
574,
402,
283,
498,
7,
288,
24656,
1522,
63,
585,
275,
291,
423,
3600,
14,
362,
8,
498,
12,
485,
8849,
9,
288,
291,
423,
3600,
59,
498,
61,
275,
574,
953,
327,
982,
781,
9980,
1133,
24656,
319,
376,
3411,
574,
12,
781,
5594,
1172,
370,
24656,
319,
314,
288,
327,
5210,
23568,
1202,
1242,
687,
314,
9608,
402,
314,
3970,
14,
288,
340,
822,
8,
277,
423,
3600,
9,
690,
291,
423,
13634,
26,
355,
485,
498,
12,
24656,
1522,
63,
585,
275,
291,
423,
3600,
14,
24882,
8,
2019,
29,
797,
9,
398,
340,
291,
14,
29842,
63,
1532,
436,
24656,
1522,
63,
585,
365,
440,
485,
8849,
26,
288,
291,
14,
29842,
63,
1532,
8,
69,
433,
1522,
63,
585,
9,
339,
347,
636,
13228,
721,
277,
12,
790,
304,
267,
543,
291,
14,
831,
26,
288,
574,
275,
291,
423,
3600,
14,
1935,
8,
498,
9,
398,
340,
291,
14,
29842,
63,
1532,
26,
288,
291,
14,
29842,
63,
1532,
8,
585,
9,
339,
347,
636,
552,
721,
277,
304,
267,
543,
291,
14,
831,
26,
288,
372,
822,
8,
277,
423,
3600,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
746,
4279,
360,
8666,
1806,
642,
1021,
365,
625,
24227,
370,
506,
2462,
3489,
2659,
339,
347,
5436,
8,
277,
304,
267,
543,
291,
14,
831,
26,
288,
327,
11247,
21116,
370,
1006,
1338,
12,
2066,
336,
3662,
314,
4412,
288,
1338,
275,
769,
8,
13012,
8,
277,
423,
3600,
430,
288,
291,
423,
3600,
14,
3584,
342,
398,
340,
291,
14,
29842,
63,
1532,
26,
288,
367,
574,
315,
1338,
26,
355,
291,
14,
29842,
63,
1532,
8,
585,
9,
339,
347,
2883,
8,
277,
304,
267,
543,
291,
14,
831,
26,
288,
372,
769,
8,
16007,
8,
277,
423,
3600,
430,
421,
199,
533,
3101,
2567,
2141,
8,
17707,
7674,
304,
272,
408,
272,
520,
635,
2323,
26,
267,
1626,
6076,
402,
901,
13,
585,
6342,
14,
9498,
440,
1395,
3663,
901,
1561,
267,
1380,
13524,
1930,
13,
262,
2464,
338,
9462,
14,
339,
520,
635,
2074,
26,
267,
10961,
901,
13,
585,
6342,
370,
986,
315,
370,
1124,
807,
14,
873,
4345,
339,
437,
1124,
807,
1040,
2839,
3970,
367,
16915,
3101,
21391,
14,
339,
5024,
1561,
787,
5489,
436,
13524,
1930,
13,
262,
2464,
338,
9462,
315,
4151,
543,
272,
7329,
1520,
9687,
14,
473,
5388,
6571,
314,
1642,
1930,
13,
7361,
790,
6775,
367,
1924,
272,
1930,
13,
15851,
4092,
14,
339,
11719,
9035,
8617,
18762,
6302,
1806,
16334,
1504,
626,
6540,
4472,
272,
1930,
13,
262,
2464,
338,
9462,
315,
1865,
370,
11075,
1124,
807,
1040,
7,
83,
2986,
14,
2104,
1504,
626,
272,
6540,
4472,
12,
3140,
1218,
282,
892,
1124,
2856,
2567,
2141,
1040,
436,
675,
21502,
525,
1040,
272,
315,
282,
4438,
14,
339,
982,
3663,
1504,
626,
787,
4472,
1930,
13,
262,
2464,
338,
9462,
787,
3032,
370,
314,
272,
3787,
503,
21502,
873,
4542,
314,
5953,
365,
10942,
436,
2005,
911,
506,
272,
14669,
14,
339,
1306,
2323,
275,
3101,
2567,
2141,
342,
272,
1306,
2323,
14,
525,
360,
1084,
13,
7810,
297,
283,
1421,
29,
1700,
358,
272,
1306,
2323,
14,
525,
360,
409,
13,
5306,
297,
283,
6185,
29,
392,
2154,
358,
272,
1306,
2323,
459,
1317,
13,
1267,
418,
275,
283,
23,
7,
272,
1306,
2323,
459,
3597,
13,
5306,
418,
272,
283,
1421,
29,
1700,
12,
15507,
29,
392,
2154,
7,
272,
1306,
2323,
459,
2714,
13,
4625,
418,
272,
283,
23,
7,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2323,
29,
403,
12,
1011,
958,
304,
267,
1613,
8,
2856,
2567,
2141,
12,
291,
2843,
826,
4533,
267,
291,
423,
3600,
275,
8773,
342,
267,
340,
2323,
365,
440,
488,
26,
288,
340,
1228,
8,
2139,
12,
3101,
2567,
2141,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
akamel001/Sick-Beard
|
sickbeard/properFinder.py
|
5
|
12379
|
# Author: Nic Wolfe <nic@wolfeden.ca>
# URL: http://code.google.com/p/sickbeard/
#
# This file is part of Sick Beard.
#
# Sick Beard 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.
#
# Sick Beard 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 Sick Beard. If not, see <http://www.gnu.org/licenses/>.
import datetime
import operator
import sickbeard
from sickbeard import db
from sickbeard import exceptions
from sickbeard.exceptions import ex
from sickbeard import helpers, logger, show_name_helpers
from sickbeard import providers
from sickbeard import search
from sickbeard import history
from sickbeard.common import DOWNLOADED, SNATCHED, SNATCHED_PROPER, Quality
from lib.tvdb_api import tvdb_api, tvdb_exceptions
from name_parser.parser import NameParser, InvalidNameException
class ProperFinder():
def __init__(self):
self.updateInterval = datetime.timedelta(hours=1)
def run(self):
if not sickbeard.DOWNLOAD_PROPERS:
return
# look for propers every night at 1 AM
updateTime = datetime.time(hour=1)
logger.log(u"Checking proper time", logger.DEBUG)
hourDiff = datetime.datetime.today().time().hour - updateTime.hour
dayDiff = (datetime.date.today() - self._get_lastProperSearch()).days
# if it's less than an interval after the update time then do an update
if hourDiff >= 0 and hourDiff < self.updateInterval.seconds / 3600 or dayDiff >=1:
logger.log(u"Beginning the search for new propers")
else:
return
propers = self._getProperList()
self._downloadPropers(propers)
self._set_lastProperSearch(datetime.datetime.today().toordinal())
def _getProperList(self):
propers = {}
# for each provider get a list of the propers
for curProvider in providers.sortedProviderList():
if not curProvider.isActive():
continue
search_date = datetime.datetime.today() - datetime.timedelta(days=2)
logger.log(u"Searching for any new PROPER releases from " + curProvider.name)
try:
curPropers = curProvider.findPropers(search_date)
except exceptions.AuthException, e:
logger.log(u"Authentication error: " + ex(e), logger.ERROR)
continue
# if they haven't been added by a different provider than add the proper to the list
for x in curPropers:
name = self._genericName(x.name)
if not name in propers:
logger.log(u"Found new proper: " + x.name, logger.DEBUG)
x.provider = curProvider
propers[name] = x
# take the list of unique propers and get it sorted by
sortedPropers = sorted(propers.values(), key=operator.attrgetter('date'), reverse=True)
finalPropers = []
for curProper in sortedPropers:
# parse the file name
try:
myParser = NameParser(False)
parse_result = myParser.parse(curProper.name)
except InvalidNameException:
logger.log(u"Unable to parse the filename " + curProper.name + " into a valid episode", logger.DEBUG)
continue
if not parse_result.episode_numbers:
logger.log(u"Ignoring " + curProper.name + " because it's for a full season rather than specific episode", logger.DEBUG)
continue
# populate our Proper instance
if parse_result.air_by_date:
curProper.season = -1
curProper.episode = parse_result.air_date
else:
curProper.season = parse_result.season_number if parse_result.season_number != None else 1
curProper.episode = parse_result.episode_numbers[0]
curProper.quality = Quality.nameQuality(curProper.name)
# for each show in our list
for curShow in sickbeard.showList:
if not parse_result.series_name:
continue
genericName = self._genericName(parse_result.series_name)
# get the scene name masks
sceneNames = set(show_name_helpers.makeSceneShowSearchStrings(curShow))
# for each scene name mask
for curSceneName in sceneNames:
# if it matches
if genericName == self._genericName(curSceneName):
logger.log(u"Successful match! Result " + parse_result.series_name + " matched to show " + curShow.name, logger.DEBUG)
# set the tvdbid in the db to the show's tvdbid
curProper.tvdbid = curShow.tvdbid
# since we found it, break out
break
# if we found something in the inner for loop break out of this one
if curProper.tvdbid != -1:
break
if curProper.tvdbid == -1:
continue
if not show_name_helpers.filterBadReleases(curProper.name):
logger.log(u"Proper " + curProper.name + " isn't a valid scene release that we want, ignoring it", logger.DEBUG)
continue
show = helpers.findCertainShow(sickbeard.showList, curProper.tvdbid)
if not show:
logger.log(u"Unable to find the show with tvdbid " + str(curProper.tvdbid), logger.ERROR)
continue
if show.rls_ignore_words and search.filter_release_name(curProper.name, show.rls_ignore_words):
logger.log(u"Ignoring " + curProper.name + " based on ignored words filter: " + show.rls_ignore_words, logger.MESSAGE)
continue
if show.rls_require_words and not search.filter_release_name(curProper.name, show.rls_require_words):
logger.log(u"Ignoring " + curProper.name + " based on required words filter: " + show.rls_require_words, logger.MESSAGE)
continue
# if we have an air-by-date show then get the real season/episode numbers
if curProper.season == -1 and curProper.tvdbid:
tvdb_lang = show.lang
# There's gotta be a better way of doing this but we don't wanna
# change the language value elsewhere
ltvdb_api_parms = sickbeard.TVDB_API_PARMS.copy()
if tvdb_lang and not tvdb_lang == 'en':
ltvdb_api_parms['language'] = tvdb_lang
try:
t = tvdb_api.Tvdb(**ltvdb_api_parms)
epObj = t[curProper.tvdbid].airedOn(curProper.episode)[0]
curProper.season = int(epObj["seasonnumber"])
curProper.episodes = [int(epObj["episodenumber"])]
except tvdb_exceptions.tvdb_episodenotfound:
logger.log(u"Unable to find episode with date " + str(curProper.episode) + " for show " + parse_result.series_name + ", skipping", logger.WARNING)
continue
# check if we actually want this proper (if it's the right quality)
sqlResults = db.DBConnection().select("SELECT status FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?", [curProper.tvdbid, curProper.season, curProper.episode])
if not sqlResults:
continue
oldStatus, oldQuality = Quality.splitCompositeStatus(int(sqlResults[0]["status"]))
# only keep the proper if we have already retrieved the same quality ep (don't get better/worse ones)
if oldStatus not in (DOWNLOADED, SNATCHED) or oldQuality != curProper.quality:
continue
# if the show is in our list and there hasn't been a proper already added for that particular episode then add it to our list of propers
if curProper.tvdbid != -1 and (curProper.tvdbid, curProper.season, curProper.episode) not in map(operator.attrgetter('tvdbid', 'season', 'episode'), finalPropers):
logger.log(u"Found a proper that we need: " + str(curProper.name))
finalPropers.append(curProper)
return finalPropers
def _downloadPropers(self, properList):
for curProper in properList:
historyLimit = datetime.datetime.today() - datetime.timedelta(days=30)
# make sure the episode has been downloaded before
myDB = db.DBConnection()
historyResults = myDB.select(
"SELECT resource FROM history "
"WHERE showid = ? AND season = ? AND episode = ? AND quality = ? AND date >= ? "
"AND action IN (" + ",".join([str(x) for x in Quality.SNATCHED]) + ")",
[curProper.tvdbid, curProper.season, curProper.episode, curProper.quality, historyLimit.strftime(history.dateFormat)])
# if we didn't download this episode in the first place we don't know what quality to use for the proper so we can't do it
if len(historyResults) == 0:
logger.log(u"Unable to find an original history entry for proper " + curProper.name + " so I'm not downloading it.")
continue
else:
# make sure that none of the existing history downloads are the same proper we're trying to download
isSame = False
for curResult in historyResults:
# if the result exists in history already we need to skip it
if self._genericName(curResult["resource"]) == self._genericName(curProper.name):
isSame = True
break
if isSame:
logger.log(u"This proper is already in history, skipping it", logger.DEBUG)
continue
# get the episode object
showObj = helpers.findCertainShow(sickbeard.showList, curProper.tvdbid)
if showObj == None:
logger.log(u"Unable to find the show with tvdbid " + str(curProper.tvdbid) + " so unable to download the proper", logger.ERROR)
continue
epObj = showObj.getEpisode(curProper.season, curProper.episode)
# make the result object
result = curProper.provider.getResult([epObj])
result.url = curProper.url
result.name = curProper.name
result.quality = curProper.quality
# snatch it
search.snatchEpisode(result, SNATCHED_PROPER)
def _genericName(self, name):
return name.replace(".", " ").replace("-", " ").replace("_", " ").lower()
def _set_lastProperSearch(self, when):
logger.log(u"Setting the last Proper search in the DB to " + str(when), logger.DEBUG)
myDB = db.DBConnection()
sqlResults = myDB.select("SELECT * FROM info")
if len(sqlResults) == 0:
myDB.action("INSERT INTO info (last_backlog, last_TVDB, last_proper_search) VALUES (?,?,?)", [0, 0, str(when)])
else:
myDB.action("UPDATE info SET last_proper_search=" + str(when))
def _get_lastProperSearch(self):
myDB = db.DBConnection()
sqlResults = myDB.select("SELECT * FROM info")
try:
last_proper_search = datetime.date.fromordinal(int(sqlResults[0]["last_proper_search"]))
except:
return datetime.date.fromordinal(1)
return last_proper_search
|
gpl-3.0
|
[
3,
6529,
26,
653,
530,
644,
79,
276,
69,
665,
12165,
32,
28070,
69,
848,
14,
696,
30,
202,
199,
3,
2851,
26,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
32370,
15283,
15,
202,
199,
3,
202,
199,
3,
961,
570,
365,
1777,
402,
28964,
6423,
1005,
14,
202,
199,
3,
202,
199,
3,
28964,
6423,
1005,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
202,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
202,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
202,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
202,
199,
3,
202,
199,
3,
28964,
6423,
1005,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
202,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
202,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
202,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
202,
199,
3,
202,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
202,
199,
3,
3180,
543,
28964,
6423,
1005,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
2999,
199,
646,
2197,
202,
199,
646,
4182,
2999,
199,
646,
17898,
2999,
199,
504,
17898,
492,
1592,
202,
199,
504,
17898,
492,
4967,
202,
199,
504,
17898,
14,
3924,
492,
444,
202,
199,
504,
17898,
492,
10897,
12,
2512,
12,
2498,
63,
354,
63,
7546,
202,
199,
504,
17898,
492,
18032,
202,
199,
504,
17898,
492,
2754,
202,
199,
504,
17898,
492,
7994,
2999,
199,
504,
17898,
14,
2330,
492,
10163,
1484,
33,
8280,
12,
428,
46,
8078,
1149,
12,
428,
46,
8078,
1149,
63,
18858,
12,
24108,
2999,
199,
504,
1973,
14,
23625,
63,
1246,
492,
26905,
63,
1246,
12,
26905,
63,
3924,
2999,
199,
504,
536,
63,
2087,
14,
2087,
492,
2812,
2842,
12,
6378,
985,
1726,
8065,
199,
533,
2165,
529,
11791,
837,
2958,
347,
636,
826,
721,
277,
304,
1039,
291,
14,
873,
8227,
275,
2197,
14,
7473,
8,
8419,
29,
17,
9,
2958,
347,
1255,
8,
277,
304,
4341,
340,
440,
17898,
14,
24930,
63,
19926,
3960,
26,
1675,
372,
4341,
327,
3648,
367,
5576,
83,
4036,
302,
1070,
737,
413,
24343,
1039,
1678,
1366,
275,
2197,
14,
521,
8,
5180,
29,
17,
9,
4341,
2512,
14,
793,
8,
85,
2,
14740,
5576,
900,
401,
2512,
14,
5287,
9,
4341,
6925,
10746,
275,
2197,
14,
2083,
14,
8136,
1252,
521,
1252,
5180,
446,
1678,
1366,
14,
5180,
1039,
5382,
10746,
275,
334,
2083,
14,
602,
14,
8136,
342,
446,
291,
423,
362,
63,
2019,
919,
529,
5278,
8801,
4899,
4341,
327,
340,
652,
1159,
6656,
2419,
376,
6252,
2410,
314,
1678,
900,
2066,
886,
376,
1678,
1039,
340,
6925,
10746,
2356,
378,
436,
6925,
10746,
665,
291,
14,
873,
8227,
14,
4515,
1182,
15751,
503,
5382,
10746,
2356,
17,
26,
1675,
2512,
14,
793,
8,
85,
2,
5595,
1835,
314,
2754,
367,
892,
5576,
83,
531,
1039,
587,
26,
1675,
372,
4341,
5576,
83,
275,
291,
423,
362,
919,
529,
1296,
342,
4341,
291,
423,
4249,
919,
32206,
8,
28314,
83,
9,
13594,
291,
423,
409,
63,
2019,
919,
529,
5278,
8,
2083,
14,
2083,
14,
8136,
1252,
475,
17460,
1012,
2958,
347,
485,
362,
919,
529,
1296,
8,
277,
304,
4341,
5576,
83,
275,
1052,
4341,
327,
367,
1924,
5022,
664,
282,
769,
402,
314,
5576,
83,
1039,
367,
1094,
6663,
315,
18032,
14,
5917,
6663,
1296,
837,
11556,
340,
440,
1094,
6663,
14,
374,
7472,
837,
2628,
1980,
11556,
2754,
63,
602,
275,
2197,
14,
2083,
14,
8136,
342,
446,
2197,
14,
7473,
8,
4899,
29,
18,
9,
11556,
2512,
14,
793,
8,
85,
2,
5278,
316,
367,
1263,
892,
3611,
4227,
19015,
687,
298,
435,
1094,
6663,
14,
354,
9,
1675,
862,
26,
2628,
1094,
919,
32206,
275,
1094,
6663,
14,
1623,
919,
32206,
8,
1733,
63,
602,
9,
1675,
871,
4967,
14,
2817,
1726,
12,
325,
26,
2628,
2512,
14,
793,
8,
85,
2,
10348,
1125,
26,
298,
435,
444,
8,
69,
395,
2512,
14,
3170,
9,
2628,
1980,
11556,
327,
340,
2985,
19051,
1133,
2757,
3483,
701,
282,
3365,
5022,
2419,
1050,
314,
5576,
370,
314,
769,
1675,
367,
671,
315,
1094,
919,
32206,
26,
2628,
536,
275,
291,
423,
6767,
985,
8,
88,
14,
354,
9,
24216,
340,
440,
536,
315,
5576,
83,
26,
4906,
2512,
14,
793,
8,
85,
2,
3601,
892,
5576,
26,
298,
435,
671,
14,
354,
12,
2512,
14,
5287,
9,
4906,
671,
14,
3780,
275,
1094,
6663,
4906,
5576,
83,
59,
354,
61,
275,
671,
4341,
327,
5452,
314,
769,
402,
3747,
5576,
83,
436,
664,
652,
3355,
701,
1039,
3355,
919,
32206,
275,
3355,
8,
28314,
83,
14,
1459,
1062,
790,
29,
3856,
14,
18600,
360,
602,
659,
3837,
29,
549,
9,
1039,
4242,
919,
32206,
275,
942,
4341,
367,
1094,
919,
529,
315,
3355,
919,
32206,
26,
11556,
327,
2198,
314,
570,
536,
1675,
862,
26,
2628,
3002,
2842,
275,
2812,
2842,
8,
797,
9,
2628,
2198,
63,
1099,
275,
3002,
2842,
14,
1122,
8,
895,
919,
529,
14,
354,
9,
1675,
871,
6378,
985,
1726,
26,
2628,
2512,
14,
793,
8,
85,
2,
6005,
370,
2198,
314,
1788,
298,
435,
1094,
919,
529,
14,
354,
435,
298,
1901,
282,
1686,
11052,
401,
2512,
14,
5287,
9,
2628,
1980,
11556,
340,
440,
2198,
63,
1099,
14,
9544,
63,
10548,
26,
2628,
2512,
14,
793,
8,
85,
2,
32390,
298,
435,
1094,
919,
529,
14,
354,
435,
298,
2952,
652,
1159,
367,
282,
2615,
14718,
7830,
2419,
2488,
11052,
401,
2512,
14,
5287,
9,
2628,
1980,
11556,
327,
13904,
4154,
2165,
529,
1256,
1675,
340,
2198,
63,
1099,
14,
8387,
63,
991,
63,
602,
26,
2628,
1094,
919,
529,
14,
12605,
275,
446,
17,
2628,
1094,
919,
529,
14,
9544,
275,
2198,
63,
1099,
14,
8387,
63,
602,
1675,
587,
26,
2628,
1094,
919,
529,
14,
12605,
275,
2198,
63,
1099,
14,
12605,
63,
1955,
340,
2198,
63
] |
[
6529,
26,
653,
530,
644,
79,
276,
69,
665,
12165,
32,
28070,
69,
848,
14,
696,
30,
202,
199,
3,
2851,
26,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
32370,
15283,
15,
202,
199,
3,
202,
199,
3,
961,
570,
365,
1777,
402,
28964,
6423,
1005,
14,
202,
199,
3,
202,
199,
3,
28964,
6423,
1005,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
202,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
202,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
202,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
202,
199,
3,
202,
199,
3,
28964,
6423,
1005,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
202,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
202,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
202,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
202,
199,
3,
202,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
202,
199,
3,
3180,
543,
28964,
6423,
1005,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
2999,
199,
646,
2197,
202,
199,
646,
4182,
2999,
199,
646,
17898,
2999,
199,
504,
17898,
492,
1592,
202,
199,
504,
17898,
492,
4967,
202,
199,
504,
17898,
14,
3924,
492,
444,
202,
199,
504,
17898,
492,
10897,
12,
2512,
12,
2498,
63,
354,
63,
7546,
202,
199,
504,
17898,
492,
18032,
202,
199,
504,
17898,
492,
2754,
202,
199,
504,
17898,
492,
7994,
2999,
199,
504,
17898,
14,
2330,
492,
10163,
1484,
33,
8280,
12,
428,
46,
8078,
1149,
12,
428,
46,
8078,
1149,
63,
18858,
12,
24108,
2999,
199,
504,
1973,
14,
23625,
63,
1246,
492,
26905,
63,
1246,
12,
26905,
63,
3924,
2999,
199,
504,
536,
63,
2087,
14,
2087,
492,
2812,
2842,
12,
6378,
985,
1726,
8065,
199,
533,
2165,
529,
11791,
837,
2958,
347,
636,
826,
721,
277,
304,
1039,
291,
14,
873,
8227,
275,
2197,
14,
7473,
8,
8419,
29,
17,
9,
2958,
347,
1255,
8,
277,
304,
4341,
340,
440,
17898,
14,
24930,
63,
19926,
3960,
26,
1675,
372,
4341,
327,
3648,
367,
5576,
83,
4036,
302,
1070,
737,
413,
24343,
1039,
1678,
1366,
275,
2197,
14,
521,
8,
5180,
29,
17,
9,
4341,
2512,
14,
793,
8,
85,
2,
14740,
5576,
900,
401,
2512,
14,
5287,
9,
4341,
6925,
10746,
275,
2197,
14,
2083,
14,
8136,
1252,
521,
1252,
5180,
446,
1678,
1366,
14,
5180,
1039,
5382,
10746,
275,
334,
2083,
14,
602,
14,
8136,
342,
446,
291,
423,
362,
63,
2019,
919,
529,
5278,
8801,
4899,
4341,
327,
340,
652,
1159,
6656,
2419,
376,
6252,
2410,
314,
1678,
900,
2066,
886,
376,
1678,
1039,
340,
6925,
10746,
2356,
378,
436,
6925,
10746,
665,
291,
14,
873,
8227,
14,
4515,
1182,
15751,
503,
5382,
10746,
2356,
17,
26,
1675,
2512,
14,
793,
8,
85,
2,
5595,
1835,
314,
2754,
367,
892,
5576,
83,
531,
1039,
587,
26,
1675,
372,
4341,
5576,
83,
275,
291,
423,
362,
919,
529,
1296,
342,
4341,
291,
423,
4249,
919,
32206,
8,
28314,
83,
9,
13594,
291,
423,
409,
63,
2019,
919,
529,
5278,
8,
2083,
14,
2083,
14,
8136,
1252,
475,
17460,
1012,
2958,
347,
485,
362,
919,
529,
1296,
8,
277,
304,
4341,
5576,
83,
275,
1052,
4341,
327,
367,
1924,
5022,
664,
282,
769,
402,
314,
5576,
83,
1039,
367,
1094,
6663,
315,
18032,
14,
5917,
6663,
1296,
837,
11556,
340,
440,
1094,
6663,
14,
374,
7472,
837,
2628,
1980,
11556,
2754,
63,
602,
275,
2197,
14,
2083,
14,
8136,
342,
446,
2197,
14,
7473,
8,
4899,
29,
18,
9,
11556,
2512,
14,
793,
8,
85,
2,
5278,
316,
367,
1263,
892,
3611,
4227,
19015,
687,
298,
435,
1094,
6663,
14,
354,
9,
1675,
862,
26,
2628,
1094,
919,
32206,
275,
1094,
6663,
14,
1623,
919,
32206,
8,
1733,
63,
602,
9,
1675,
871,
4967,
14,
2817,
1726,
12,
325,
26,
2628,
2512,
14,
793,
8,
85,
2,
10348,
1125,
26,
298,
435,
444,
8,
69,
395,
2512,
14,
3170,
9,
2628,
1980,
11556,
327,
340,
2985,
19051,
1133,
2757,
3483,
701,
282,
3365,
5022,
2419,
1050,
314,
5576,
370,
314,
769,
1675,
367,
671,
315,
1094,
919,
32206,
26,
2628,
536,
275,
291,
423,
6767,
985,
8,
88,
14,
354,
9,
24216,
340,
440,
536,
315,
5576,
83,
26,
4906,
2512,
14,
793,
8,
85,
2,
3601,
892,
5576,
26,
298,
435,
671,
14,
354,
12,
2512,
14,
5287,
9,
4906,
671,
14,
3780,
275,
1094,
6663,
4906,
5576,
83,
59,
354,
61,
275,
671,
4341,
327,
5452,
314,
769,
402,
3747,
5576,
83,
436,
664,
652,
3355,
701,
1039,
3355,
919,
32206,
275,
3355,
8,
28314,
83,
14,
1459,
1062,
790,
29,
3856,
14,
18600,
360,
602,
659,
3837,
29,
549,
9,
1039,
4242,
919,
32206,
275,
942,
4341,
367,
1094,
919,
529,
315,
3355,
919,
32206,
26,
11556,
327,
2198,
314,
570,
536,
1675,
862,
26,
2628,
3002,
2842,
275,
2812,
2842,
8,
797,
9,
2628,
2198,
63,
1099,
275,
3002,
2842,
14,
1122,
8,
895,
919,
529,
14,
354,
9,
1675,
871,
6378,
985,
1726,
26,
2628,
2512,
14,
793,
8,
85,
2,
6005,
370,
2198,
314,
1788,
298,
435,
1094,
919,
529,
14,
354,
435,
298,
1901,
282,
1686,
11052,
401,
2512,
14,
5287,
9,
2628,
1980,
11556,
340,
440,
2198,
63,
1099,
14,
9544,
63,
10548,
26,
2628,
2512,
14,
793,
8,
85,
2,
32390,
298,
435,
1094,
919,
529,
14,
354,
435,
298,
2952,
652,
1159,
367,
282,
2615,
14718,
7830,
2419,
2488,
11052,
401,
2512,
14,
5287,
9,
2628,
1980,
11556,
327,
13904,
4154,
2165,
529,
1256,
1675,
340,
2198,
63,
1099,
14,
8387,
63,
991,
63,
602,
26,
2628,
1094,
919,
529,
14,
12605,
275,
446,
17,
2628,
1094,
919,
529,
14,
9544,
275,
2198,
63,
1099,
14,
8387,
63,
602,
1675,
587,
26,
2628,
1094,
919,
529,
14,
12605,
275,
2198,
63,
1099,
14,
12605,
63,
1955,
340,
2198,
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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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
] |
tboyce021/home-assistant
|
homeassistant/components/apple_tv/media_player.py
|
2
|
8084
|
"""Support for Apple TV media player."""
import logging
from pyatv.const import DeviceState, FeatureName, FeatureState, MediaType
from homeassistant.components.media_player import MediaPlayerEntity
from homeassistant.components.media_player.const import (
MEDIA_TYPE_MUSIC,
MEDIA_TYPE_TVSHOW,
MEDIA_TYPE_VIDEO,
SUPPORT_NEXT_TRACK,
SUPPORT_PAUSE,
SUPPORT_PLAY,
SUPPORT_PLAY_MEDIA,
SUPPORT_PREVIOUS_TRACK,
SUPPORT_SEEK,
SUPPORT_STOP,
SUPPORT_TURN_OFF,
SUPPORT_TURN_ON,
)
from homeassistant.const import (
CONF_NAME,
STATE_IDLE,
STATE_OFF,
STATE_PAUSED,
STATE_PLAYING,
STATE_STANDBY,
)
from homeassistant.core import callback
import homeassistant.util.dt as dt_util
from . import AppleTVEntity
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
PARALLEL_UPDATES = 0
SUPPORT_APPLE_TV = (
SUPPORT_TURN_ON
| SUPPORT_TURN_OFF
| SUPPORT_PLAY_MEDIA
| SUPPORT_PAUSE
| SUPPORT_PLAY
| SUPPORT_SEEK
| SUPPORT_STOP
| SUPPORT_NEXT_TRACK
| SUPPORT_PREVIOUS_TRACK
)
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Load Apple TV media player based on a config entry."""
name = config_entry.data[CONF_NAME]
manager = hass.data[DOMAIN][config_entry.unique_id]
async_add_entities([AppleTvMediaPlayer(name, config_entry.unique_id, manager)])
class AppleTvMediaPlayer(AppleTVEntity, MediaPlayerEntity):
"""Representation of an Apple TV media player."""
def __init__(self, name, identifier, manager, **kwargs):
"""Initialize the Apple TV media player."""
super().__init__(name, identifier, manager, **kwargs)
self._playing = None
@callback
def async_device_connected(self, atv):
"""Handle when connection is made to device."""
self.atv.push_updater.listener = self
self.atv.push_updater.start()
@callback
def async_device_disconnected(self):
"""Handle when connection was lost to device."""
self.atv.push_updater.stop()
self.atv.push_updater.listener = None
@property
def state(self):
"""Return the state of the device."""
if self.manager.is_connecting:
return None
if self.atv is None:
return STATE_OFF
if self._playing:
state = self._playing.device_state
if state in (DeviceState.Idle, DeviceState.Loading):
return STATE_IDLE
if state == DeviceState.Playing:
return STATE_PLAYING
if state in (DeviceState.Paused, DeviceState.Seeking, DeviceState.Stopped):
return STATE_PAUSED
return STATE_STANDBY # Bad or unknown state?
return None
@callback
def playstatus_update(self, _, playing):
"""Print what is currently playing when it changes."""
self._playing = playing
self.async_write_ha_state()
@callback
def playstatus_error(self, _, exception):
"""Inform about an error and restart push updates."""
_LOGGER.warning("A %s error occurred: %s", exception.__class__, exception)
self._playing = None
self.async_write_ha_state()
@property
def app_id(self):
"""ID of the current running app."""
if self.atv:
if self.atv.features.in_state(FeatureState.Available, FeatureName.App):
return self.atv.metadata.app.identifier
return None
@property
def app_name(self):
"""Name of the current running app."""
if self.atv:
if self.atv.features.in_state(FeatureState.Available, FeatureName.App):
return self.atv.metadata.app.name
return None
@property
def media_content_type(self):
"""Content type of current playing media."""
if self._playing:
return {
MediaType.Video: MEDIA_TYPE_VIDEO,
MediaType.Music: MEDIA_TYPE_MUSIC,
MediaType.TV: MEDIA_TYPE_TVSHOW,
}.get(self._playing.media_type)
return None
@property
def media_duration(self):
"""Duration of current playing media in seconds."""
if self._playing:
return self._playing.total_time
return None
@property
def media_position(self):
"""Position of current playing media in seconds."""
if self._playing:
return self._playing.position
return None
@property
def media_position_updated_at(self):
"""Last valid time of media position."""
if self.state in (STATE_PLAYING, STATE_PAUSED):
return dt_util.utcnow()
return None
async def async_play_media(self, media_type, media_id, **kwargs):
"""Send the play_media command to the media player."""
await self.atv.stream.play_url(media_id)
@property
def media_image_hash(self):
"""Hash value for media image."""
state = self.state
if self._playing and state not in [None, STATE_OFF, STATE_IDLE]:
return self.atv.metadata.artwork_id
return None
async def async_get_media_image(self):
"""Fetch media image of current playing image."""
state = self.state
if self._playing and state not in [STATE_OFF, STATE_IDLE]:
artwork = await self.atv.metadata.artwork()
if artwork:
return artwork.bytes, artwork.mimetype
return None, None
@property
def media_title(self):
"""Title of current playing media."""
if self._playing:
return self._playing.title
return None
@property
def media_artist(self):
"""Artist of current playing media, music track only."""
if self._is_feature_available(FeatureName.Artist):
return self._playing.artist
return None
@property
def media_album_name(self):
"""Album name of current playing media, music track only."""
if self._is_feature_available(FeatureName.Album):
return self._playing.album
return None
@property
def supported_features(self):
"""Flag media player features that are supported."""
return SUPPORT_APPLE_TV
def _is_feature_available(self, feature):
"""Return if a feature is available."""
if self.atv and self._playing:
return self.atv.features.in_state(FeatureState.Available, feature)
return False
async def async_turn_on(self):
"""Turn the media player on."""
await self.manager.connect()
async def async_turn_off(self):
"""Turn the media player off."""
self._playing = None
await self.manager.disconnect()
async def async_media_play_pause(self):
"""Pause media on media player."""
if self._playing:
state = self.state
if state == STATE_PAUSED:
await self.atv.remote_control.play()
elif state == STATE_PLAYING:
await self.atv.remote_control.pause()
return None
async def async_media_play(self):
"""Play media."""
if self._playing:
await self.atv.remote_control.play()
async def async_media_stop(self):
"""Stop the media player."""
if self._playing:
await self.atv.remote_control.stop()
async def async_media_pause(self):
"""Pause the media player."""
if self._playing:
await self.atv.remote_control.pause()
async def async_media_next_track(self):
"""Send next track command."""
if self._playing:
await self.atv.remote_control.next()
async def async_media_previous_track(self):
"""Send previous track command."""
if self._playing:
await self.atv.remote_control.previous()
async def async_media_seek(self, position):
"""Send seek command."""
if self._playing:
await self.atv.remote_control.set_position(position)
|
apache-2.0
|
[
624,
11532,
367,
21257,
26990,
5898,
7748,
1041,
199,
646,
2050,
199,
199,
504,
1134,
292,
86,
14,
1297,
492,
12272,
2223,
12,
13407,
985,
12,
13407,
2223,
12,
12300,
804,
199,
199,
504,
8846,
14,
4608,
14,
4603,
63,
6147,
492,
12300,
10921,
7302,
199,
504,
8846,
14,
4608,
14,
4603,
63,
6147,
14,
1297,
492,
334,
272,
31460,
63,
2711,
63,
45,
1668,
948,
12,
272,
31460,
63,
2711,
63,
52,
7428,
16210,
12,
272,
31460,
63,
2711,
63,
20142,
12,
272,
13756,
63,
21917,
63,
19755,
12,
272,
13756,
63,
8470,
4701,
12,
272,
13756,
63,
11625,
12,
272,
13756,
63,
11625,
63,
13669,
12,
272,
13756,
63,
28422,
25657,
63,
19755,
12,
272,
13756,
63,
18439,
12,
272,
13756,
63,
11632,
12,
272,
13756,
63,
52,
7648,
63,
7517,
12,
272,
13756,
63,
52,
7648,
63,
615,
12,
199,
9,
199,
504,
8846,
14,
1297,
492,
334,
272,
6392,
63,
2339,
12,
272,
11377,
63,
23715,
12,
272,
11377,
63,
7517,
12,
272,
11377,
63,
8470,
8558,
12,
272,
11377,
63,
11625,
1206,
12,
272,
11377,
63,
840,
879,
2846,
57,
12,
199,
9,
199,
504,
8846,
14,
1018,
492,
3233,
199,
646,
8846,
14,
1974,
14,
3583,
465,
4487,
63,
1974,
199,
199,
504,
1275,
492,
21257,
12764,
7302,
199,
504,
1275,
1297,
492,
15265,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
4014,
748,
906,
44,
63,
23612,
654,
275,
378,
199,
199,
10640,
63,
31683,
63,
12764,
275,
334,
272,
13756,
63,
52,
7648,
63,
615,
272,
1204,
13756,
63,
52,
7648,
63,
7517,
272,
1204,
13756,
63,
11625,
63,
13669,
272,
1204,
13756,
63,
8470,
4701,
272,
1204,
13756,
63,
11625,
272,
1204,
13756,
63,
18439,
272,
1204,
13756,
63,
11632,
272,
1204,
13756,
63,
21917,
63,
19755,
272,
1204,
13756,
63,
28422,
25657,
63,
19755,
199,
9,
421,
199,
4146,
347,
5316,
63,
2758,
63,
2373,
8,
5387,
12,
1101,
63,
2373,
12,
5316,
63,
525,
63,
8327,
304,
272,
408,
6200,
21257,
26990,
5898,
7748,
4079,
641,
282,
1101,
2397,
1041,
272,
536,
275,
1101,
63,
2373,
14,
576,
59,
3103,
63,
2339,
61,
272,
5256,
275,
6298,
14,
576,
59,
7378,
1527,
888,
63,
2373,
14,
3235,
63,
344,
61,
272,
5316,
63,
525,
63,
8327,
779,
25051,
52,
86,
11398,
10921,
8,
354,
12,
1101,
63,
2373,
14,
3235,
63,
344,
12,
5256,
3948,
421,
199,
533,
21257,
52,
86,
11398,
10921,
8,
25051,
12764,
7302,
12,
12300,
10921,
7302,
304,
272,
408,
20609,
402,
376,
21257,
26990,
5898,
7748,
1041,
339,
347,
636,
826,
721,
277,
12,
536,
12,
5148,
12,
5256,
12,
1011,
958,
304,
267,
408,
9345,
314,
21257,
26990,
5898,
7748,
1041,
267,
1613,
11027,
826,
721,
354,
12,
5148,
12,
5256,
12,
1011,
958,
9,
267,
291,
423,
22224,
275,
488,
339,
768,
3058,
272,
347,
5316,
63,
1782,
63,
7113,
8,
277,
12,
737,
86,
304,
267,
408,
5940,
1380,
1950,
365,
6326,
370,
2243,
1041,
267,
291,
14,
292,
86,
14,
5335,
63,
29645,
14,
9799,
275,
291,
267,
291,
14,
292,
86,
14,
5335,
63,
29645,
14,
928,
342,
339,
768,
3058,
272,
347,
5316,
63,
1782,
63,
27476,
8,
277,
304,
267,
408,
5940,
1380,
1950,
1990,
14669,
370,
2243,
1041,
267,
291,
14,
292,
86,
14,
5335,
63,
29645,
14,
2379,
342,
267,
291,
14,
292,
86,
14,
5335,
63,
29645,
14,
9799,
275,
488,
339,
768,
1829,
272,
347,
1174,
8,
277,
304,
267,
408,
1767,
314,
1174,
402,
314,
2243,
1041,
267,
340,
291,
14,
2609,
14,
374,
63,
2242,
316,
26,
288,
372,
488,
267,
340,
291,
14,
292,
86,
365,
488,
26,
288,
372,
11377,
63,
7517,
267,
340,
291,
423,
22224,
26,
288,
1174,
275,
291,
423,
22224,
14,
1782,
63,
929,
288,
340,
1174,
315,
334,
2510,
2223,
14,
21068,
12,
12272,
2223,
14,
19236,
304,
355,
372,
11377,
63,
23715,
288,
340,
1174,
508,
12272,
2223,
14,
29975,
26,
355,
372,
11377,
63,
11625,
1206,
288,
340,
1174,
315,
334,
2510,
2223,
14,
4232,
2972,
12,
12272,
2223,
14,
19168,
316,
12,
12272,
2223,
14,
28500,
304,
355,
372,
11377,
63,
8470,
8558,
288,
372,
11377,
63,
840,
879,
2846,
57,
221,
327,
8857,
503,
5809,
1174,
31,
267,
372,
488,
339,
768,
3058,
272,
347,
5232,
1205,
63,
873,
8,
277,
12,
5501,
25692,
304,
267,
408,
5375,
4052,
365,
5544,
25692,
1380,
652,
4493,
1041,
267,
291,
423,
22224,
275,
25692,
267,
291,
14,
4146,
63,
952,
63,
2411,
63,
929,
342,
339,
768,
3058,
272,
347,
5232,
1205,
63,
705,
8,
277,
12,
5501,
1919,
304,
267,
408,
607,
964,
3595,
376,
1125,
436,
11004,
6675,
7029,
1041,
267,
485,
10186,
14,
3764,
480,
33,
450,
83,
1125,
8920,
26,
450,
83,
401,
1919,
855,
533,
3108,
1919,
9,
267,
291,
423,
22224,
275,
488,
267,
291,
14,
4146,
63,
952,
63,
2411,
63,
929,
342,
339,
768,
1829,
272,
347,
1145,
63,
344,
8,
277,
304,
267,
408,
998,
402,
314,
1453,
3879,
1145,
1041,
267,
340,
291,
14,
292,
86,
26,
288,
340,
291,
14,
292,
86,
14,
3179,
14,
262,
63,
929,
8,
5968,
2223,
14,
11464,
12,
13407,
985,
14,
2640,
304,
355,
372,
291,
14,
292,
86,
14,
2343,
14,
571,
14,
5364,
267,
372,
488,
339,
768,
1829,
272,
347,
1145,
63,
354,
8,
277,
304,
267,
408,
985,
402,
314,
1453,
3879,
1145,
1041,
267,
340,
291,
14,
292,
86,
26,
288,
340,
291,
14,
292,
86,
14,
3179,
14,
262,
63,
929,
8,
5968,
2223,
14,
11464,
12,
13407,
985,
14,
2640,
304,
355,
372,
291,
14,
292,
86,
14,
2343,
14,
571,
14,
354,
267,
372,
488,
339,
768,
1829,
272,
347,
5898,
63,
1317,
63,
466,
8,
277,
304,
267,
408,
2714,
730,
402,
1453,
25692,
5898,
1041,
267,
340,
291,
423,
22224,
26,
288,
372,
469,
355,
12300,
804,
14,
9166,
26,
31460,
63,
2711,
63,
20142,
12,
355,
12300,
804,
14,
29869,
26,
31460,
63,
2711,
63,
45,
1668,
948,
12,
355,
12300,
804,
14,
12764,
26,
31460,
63,
2711,
63,
52,
7428,
16210,
12
] |
[
11532,
367,
21257,
26990,
5898,
7748,
1041,
199,
646,
2050,
199,
199,
504,
1134,
292,
86,
14,
1297,
492,
12272,
2223,
12,
13407,
985,
12,
13407,
2223,
12,
12300,
804,
199,
199,
504,
8846,
14,
4608,
14,
4603,
63,
6147,
492,
12300,
10921,
7302,
199,
504,
8846,
14,
4608,
14,
4603,
63,
6147,
14,
1297,
492,
334,
272,
31460,
63,
2711,
63,
45,
1668,
948,
12,
272,
31460,
63,
2711,
63,
52,
7428,
16210,
12,
272,
31460,
63,
2711,
63,
20142,
12,
272,
13756,
63,
21917,
63,
19755,
12,
272,
13756,
63,
8470,
4701,
12,
272,
13756,
63,
11625,
12,
272,
13756,
63,
11625,
63,
13669,
12,
272,
13756,
63,
28422,
25657,
63,
19755,
12,
272,
13756,
63,
18439,
12,
272,
13756,
63,
11632,
12,
272,
13756,
63,
52,
7648,
63,
7517,
12,
272,
13756,
63,
52,
7648,
63,
615,
12,
199,
9,
199,
504,
8846,
14,
1297,
492,
334,
272,
6392,
63,
2339,
12,
272,
11377,
63,
23715,
12,
272,
11377,
63,
7517,
12,
272,
11377,
63,
8470,
8558,
12,
272,
11377,
63,
11625,
1206,
12,
272,
11377,
63,
840,
879,
2846,
57,
12,
199,
9,
199,
504,
8846,
14,
1018,
492,
3233,
199,
646,
8846,
14,
1974,
14,
3583,
465,
4487,
63,
1974,
199,
199,
504,
1275,
492,
21257,
12764,
7302,
199,
504,
1275,
1297,
492,
15265,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
4014,
748,
906,
44,
63,
23612,
654,
275,
378,
199,
199,
10640,
63,
31683,
63,
12764,
275,
334,
272,
13756,
63,
52,
7648,
63,
615,
272,
1204,
13756,
63,
52,
7648,
63,
7517,
272,
1204,
13756,
63,
11625,
63,
13669,
272,
1204,
13756,
63,
8470,
4701,
272,
1204,
13756,
63,
11625,
272,
1204,
13756,
63,
18439,
272,
1204,
13756,
63,
11632,
272,
1204,
13756,
63,
21917,
63,
19755,
272,
1204,
13756,
63,
28422,
25657,
63,
19755,
199,
9,
421,
199,
4146,
347,
5316,
63,
2758,
63,
2373,
8,
5387,
12,
1101,
63,
2373,
12,
5316,
63,
525,
63,
8327,
304,
272,
408,
6200,
21257,
26990,
5898,
7748,
4079,
641,
282,
1101,
2397,
1041,
272,
536,
275,
1101,
63,
2373,
14,
576,
59,
3103,
63,
2339,
61,
272,
5256,
275,
6298,
14,
576,
59,
7378,
1527,
888,
63,
2373,
14,
3235,
63,
344,
61,
272,
5316,
63,
525,
63,
8327,
779,
25051,
52,
86,
11398,
10921,
8,
354,
12,
1101,
63,
2373,
14,
3235,
63,
344,
12,
5256,
3948,
421,
199,
533,
21257,
52,
86,
11398,
10921,
8,
25051,
12764,
7302,
12,
12300,
10921,
7302,
304,
272,
408,
20609,
402,
376,
21257,
26990,
5898,
7748,
1041,
339,
347,
636,
826,
721,
277,
12,
536,
12,
5148,
12,
5256,
12,
1011,
958,
304,
267,
408,
9345,
314,
21257,
26990,
5898,
7748,
1041,
267,
1613,
11027,
826,
721,
354,
12,
5148,
12,
5256,
12,
1011,
958,
9,
267,
291,
423,
22224,
275,
488,
339,
768,
3058,
272,
347,
5316,
63,
1782,
63,
7113,
8,
277,
12,
737,
86,
304,
267,
408,
5940,
1380,
1950,
365,
6326,
370,
2243,
1041,
267,
291,
14,
292,
86,
14,
5335,
63,
29645,
14,
9799,
275,
291,
267,
291,
14,
292,
86,
14,
5335,
63,
29645,
14,
928,
342,
339,
768,
3058,
272,
347,
5316,
63,
1782,
63,
27476,
8,
277,
304,
267,
408,
5940,
1380,
1950,
1990,
14669,
370,
2243,
1041,
267,
291,
14,
292,
86,
14,
5335,
63,
29645,
14,
2379,
342,
267,
291,
14,
292,
86,
14,
5335,
63,
29645,
14,
9799,
275,
488,
339,
768,
1829,
272,
347,
1174,
8,
277,
304,
267,
408,
1767,
314,
1174,
402,
314,
2243,
1041,
267,
340,
291,
14,
2609,
14,
374,
63,
2242,
316,
26,
288,
372,
488,
267,
340,
291,
14,
292,
86,
365,
488,
26,
288,
372,
11377,
63,
7517,
267,
340,
291,
423,
22224,
26,
288,
1174,
275,
291,
423,
22224,
14,
1782,
63,
929,
288,
340,
1174,
315,
334,
2510,
2223,
14,
21068,
12,
12272,
2223,
14,
19236,
304,
355,
372,
11377,
63,
23715,
288,
340,
1174,
508,
12272,
2223,
14,
29975,
26,
355,
372,
11377,
63,
11625,
1206,
288,
340,
1174,
315,
334,
2510,
2223,
14,
4232,
2972,
12,
12272,
2223,
14,
19168,
316,
12,
12272,
2223,
14,
28500,
304,
355,
372,
11377,
63,
8470,
8558,
288,
372,
11377,
63,
840,
879,
2846,
57,
221,
327,
8857,
503,
5809,
1174,
31,
267,
372,
488,
339,
768,
3058,
272,
347,
5232,
1205,
63,
873,
8,
277,
12,
5501,
25692,
304,
267,
408,
5375,
4052,
365,
5544,
25692,
1380,
652,
4493,
1041,
267,
291,
423,
22224,
275,
25692,
267,
291,
14,
4146,
63,
952,
63,
2411,
63,
929,
342,
339,
768,
3058,
272,
347,
5232,
1205,
63,
705,
8,
277,
12,
5501,
1919,
304,
267,
408,
607,
964,
3595,
376,
1125,
436,
11004,
6675,
7029,
1041,
267,
485,
10186,
14,
3764,
480,
33,
450,
83,
1125,
8920,
26,
450,
83,
401,
1919,
855,
533,
3108,
1919,
9,
267,
291,
423,
22224,
275,
488,
267,
291,
14,
4146,
63,
952,
63,
2411,
63,
929,
342,
339,
768,
1829,
272,
347,
1145,
63,
344,
8,
277,
304,
267,
408,
998,
402,
314,
1453,
3879,
1145,
1041,
267,
340,
291,
14,
292,
86,
26,
288,
340,
291,
14,
292,
86,
14,
3179,
14,
262,
63,
929,
8,
5968,
2223,
14,
11464,
12,
13407,
985,
14,
2640,
304,
355,
372,
291,
14,
292,
86,
14,
2343,
14,
571,
14,
5364,
267,
372,
488,
339,
768,
1829,
272,
347,
1145,
63,
354,
8,
277,
304,
267,
408,
985,
402,
314,
1453,
3879,
1145,
1041,
267,
340,
291,
14,
292,
86,
26,
288,
340,
291,
14,
292,
86,
14,
3179,
14,
262,
63,
929,
8,
5968,
2223,
14,
11464,
12,
13407,
985,
14,
2640,
304,
355,
372,
291,
14,
292,
86,
14,
2343,
14,
571,
14,
354,
267,
372,
488,
339,
768,
1829,
272,
347,
5898,
63,
1317,
63,
466,
8,
277,
304,
267,
408,
2714,
730,
402,
1453,
25692,
5898,
1041,
267,
340,
291,
423,
22224,
26,
288,
372,
469,
355,
12300,
804,
14,
9166,
26,
31460,
63,
2711,
63,
20142,
12,
355,
12300,
804,
14,
29869,
26,
31460,
63,
2711,
63,
45,
1668,
948,
12,
355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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
mKeRix/home-assistant
|
homeassistant/components/fritz/device_tracker.py
|
10
|
3266
|
"""Support for FRITZ!Box routers."""
import logging
from fritzconnection.lib.fritzhosts import FritzHosts
import voluptuous as vol
from homeassistant.components.device_tracker import (
DOMAIN,
PLATFORM_SCHEMA,
DeviceScanner,
)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
CONF_DEFAULT_IP = "169.254.1.1" # This IP is valid for all FRITZ!Box routers.
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Optional(CONF_HOST, default=CONF_DEFAULT_IP): cv.string,
vol.Optional(CONF_PASSWORD, default="admin"): cv.string,
vol.Optional(CONF_USERNAME, default=""): cv.string,
}
)
def get_scanner(hass, config):
"""Validate the configuration and return FritzBoxScanner."""
scanner = FritzBoxScanner(config[DOMAIN])
return scanner if scanner.success_init else None
class FritzBoxScanner(DeviceScanner):
"""This class queries a FRITZ!Box router."""
def __init__(self, config):
"""Initialize the scanner."""
self.last_results = []
self.host = config[CONF_HOST]
self.username = config[CONF_USERNAME]
self.password = config[CONF_PASSWORD]
self.success_init = True
# Establish a connection to the FRITZ!Box.
try:
self.fritz_box = FritzHosts(
address=self.host, user=self.username, password=self.password
)
except (ValueError, TypeError):
self.fritz_box = None
# At this point it is difficult to tell if a connection is established.
# So just check for null objects.
if self.fritz_box is None or not self.fritz_box.modelname:
self.success_init = False
if self.success_init:
_LOGGER.info("Successfully connected to %s", self.fritz_box.modelname)
self._update_info()
else:
_LOGGER.error(
"Failed to establish connection to FRITZ!Box with IP: %s", self.host
)
def scan_devices(self):
"""Scan for new devices and return a list of found device ids."""
self._update_info()
active_hosts = []
for known_host in self.last_results:
if known_host["status"] and known_host.get("mac"):
active_hosts.append(known_host["mac"])
return active_hosts
def get_device_name(self, device):
"""Return the name of the given device or None if is not known."""
ret = self.fritz_box.get_specific_host_entry(device).get("NewHostName")
if ret == {}:
return None
return ret
def get_extra_attributes(self, device):
"""Return the attributes (ip, mac) of the given device or None if is not known."""
ip_device = self.fritz_box.get_specific_host_entry(device).get("NewIPAddress")
if not ip_device:
return {}
return {"ip": ip_device, "mac": device}
def _update_info(self):
"""Retrieve latest information from the FRITZ!Box."""
if not self.success_init:
return False
_LOGGER.debug("Scanning")
self.last_results = self.fritz_box.get_hosts_info()
return True
|
mit
|
[
624,
11532,
367,
28671,
649,
58,
1,
3532,
24464,
1041,
199,
646,
2050,
199,
199,
504,
289,
322,
3903,
2105,
14,
773,
14,
25876,
3903,
5146,
492,
31712,
3903,
19620,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
14,
4608,
14,
1782,
63,
8877,
492,
334,
272,
15265,
12,
272,
21966,
63,
10926,
12,
272,
12272,
20843,
12,
199,
9,
199,
504,
8846,
14,
1297,
492,
6392,
63,
5449,
12,
6392,
63,
9032,
12,
6392,
63,
11958,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
3103,
63,
3472,
63,
1772,
275,
298,
10143,
14,
8306,
14,
17,
14,
17,
2,
221,
327,
961,
3531,
365,
1686,
367,
1006,
28671,
649,
58,
1,
3532,
24464,
14,
199,
199,
17805,
63,
10926,
275,
21966,
63,
10926,
14,
2880,
8,
272,
469,
267,
5236,
14,
7012,
8,
3103,
63,
5449,
12,
849,
29,
3103,
63,
3472,
63,
1772,
304,
6277,
14,
875,
12,
267,
5236,
14,
7012,
8,
3103,
63,
9032,
12,
849,
628,
2113,
2349,
6277,
14,
875,
12,
267,
5236,
14,
7012,
8,
3103,
63,
11958,
12,
849,
17364,
6277,
14,
875,
12,
272,
789,
199,
9,
421,
199,
318,
664,
63,
16378,
8,
5387,
12,
1101,
304,
272,
408,
12584,
314,
2897,
436,
372,
31712,
3903,
3532,
20843,
1041,
272,
19121,
275,
31712,
3903,
3532,
20843,
8,
888,
59,
7378,
566,
272,
372,
19121,
340,
19121,
14,
3742,
63,
826,
587,
488,
421,
199,
533,
31712,
3903,
3532,
20843,
8,
2510,
20843,
304,
272,
408,
2765,
1021,
9212,
282,
28671,
649,
58,
1,
3532,
6197,
1041,
339,
347,
636,
826,
721,
277,
12,
1101,
304,
267,
408,
9345,
314,
19121,
1041,
267,
291,
14,
2019,
63,
2604,
275,
942,
267,
291,
14,
1102,
275,
1101,
59,
3103,
63,
5449,
61,
267,
291,
14,
2473,
275,
1101,
59,
3103,
63,
11958,
61,
267,
291,
14,
2060,
275,
1101,
59,
3103,
63,
9032,
61,
267,
291,
14,
3742,
63,
826,
275,
715,
398,
327,
15896,
13306,
282,
1950,
370,
314,
28671,
649,
58,
1,
3532,
14,
267,
862,
26,
288,
291,
14,
25876,
3903,
63,
1977,
275,
31712,
3903,
19620,
8,
355,
2287,
29,
277,
14,
1102,
12,
922,
29,
277,
14,
2473,
12,
2505,
29,
277,
14,
2060,
288,
776,
267,
871,
334,
3393,
12,
3146,
304,
288,
291,
14,
25876,
3903,
63,
1977,
275,
488,
398,
327,
2854,
642,
2376,
652,
365,
29870,
370,
11480,
340,
282,
1950,
365,
23594,
14,
267,
327,
2002,
2951,
1104,
367,
2973,
2251,
14,
267,
340,
291,
14,
25876,
3903,
63,
1977,
365,
488,
503,
440,
291,
14,
25876,
3903,
63,
1977,
14,
1238,
354,
26,
288,
291,
14,
3742,
63,
826,
275,
756,
398,
340,
291,
14,
3742,
63,
826,
26,
288,
485,
10186,
14,
815,
480,
25001,
8539,
370,
450,
83,
401,
291,
14,
25876,
3903,
63,
1977,
14,
1238,
354,
9,
288,
291,
423,
873,
63,
815,
342,
267,
587,
26,
288,
485,
10186,
14,
705,
8,
355,
298,
4276,
370,
16873,
1950,
370,
28671,
649,
58,
1,
3532,
543,
3531,
26,
450,
83,
401,
291,
14,
1102,
288,
776,
339,
347,
8000,
63,
6410,
8,
277,
304,
267,
408,
15936,
367,
892,
7256,
436,
372,
282,
769,
402,
1911,
2243,
2762,
1041,
267,
291,
423,
873,
63,
815,
342,
267,
4702,
63,
5146,
275,
942,
267,
367,
6040,
63,
1102,
315,
291,
14,
2019,
63,
2604,
26,
288,
340,
6040,
63,
1102,
905,
1205,
937,
436,
6040,
63,
1102,
14,
362,
480,
3088,
2349,
355,
4702,
63,
5146,
14,
740,
8,
3159,
63,
1102,
905,
3088,
3135,
267,
372,
4702,
63,
5146,
339,
347,
664,
63,
1782,
63,
354,
8,
277,
12,
2243,
304,
267,
408,
1767,
314,
536,
402,
314,
1627,
2243,
503,
488,
340,
365,
440,
6040,
1041,
267,
2203,
275,
291,
14,
25876,
3903,
63,
1977,
14,
362,
63,
6100,
63,
1102,
63,
2373,
8,
1782,
680,
362,
480,
4665,
4965,
985,
531,
267,
340,
2203,
508,
24702,
288,
372,
488,
267,
372,
2203,
339,
347,
664,
63,
2911,
63,
2987,
8,
277,
12,
2243,
304,
267,
408,
1767,
314,
3004,
334,
711,
12,
4497,
9,
402,
314,
1627,
2243,
503,
488,
340,
365,
440,
6040,
1041,
267,
3384,
63,
1782,
275,
291,
14,
25876,
3903,
63,
1977,
14,
362,
63,
6100,
63,
1102,
63,
2373,
8,
1782,
680,
362,
480,
4665,
14955,
531,
398,
340,
440,
3384,
63,
1782,
26,
288,
372,
1052,
267,
372,
2420,
711,
582,
3384,
63,
1782,
12,
298,
3088,
582,
2243,
93,
339,
347,
485,
873,
63,
815,
8,
277,
304,
267,
408,
15310,
8839,
2556,
687,
314,
28671,
649,
58,
1,
3532,
1041,
267,
340,
440,
291,
14,
3742,
63,
826,
26,
288,
372,
756,
398,
485,
10186,
14,
1757,
480,
7181,
11495,
531,
267,
291,
14,
2019,
63,
2604,
275,
291,
14,
25876,
3903,
63,
1977,
14,
362,
63,
5146,
63,
815,
342,
267,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
11532,
367,
28671,
649,
58,
1,
3532,
24464,
1041,
199,
646,
2050,
199,
199,
504,
289,
322,
3903,
2105,
14,
773,
14,
25876,
3903,
5146,
492,
31712,
3903,
19620,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
14,
4608,
14,
1782,
63,
8877,
492,
334,
272,
15265,
12,
272,
21966,
63,
10926,
12,
272,
12272,
20843,
12,
199,
9,
199,
504,
8846,
14,
1297,
492,
6392,
63,
5449,
12,
6392,
63,
9032,
12,
6392,
63,
11958,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
3103,
63,
3472,
63,
1772,
275,
298,
10143,
14,
8306,
14,
17,
14,
17,
2,
221,
327,
961,
3531,
365,
1686,
367,
1006,
28671,
649,
58,
1,
3532,
24464,
14,
199,
199,
17805,
63,
10926,
275,
21966,
63,
10926,
14,
2880,
8,
272,
469,
267,
5236,
14,
7012,
8,
3103,
63,
5449,
12,
849,
29,
3103,
63,
3472,
63,
1772,
304,
6277,
14,
875,
12,
267,
5236,
14,
7012,
8,
3103,
63,
9032,
12,
849,
628,
2113,
2349,
6277,
14,
875,
12,
267,
5236,
14,
7012,
8,
3103,
63,
11958,
12,
849,
17364,
6277,
14,
875,
12,
272,
789,
199,
9,
421,
199,
318,
664,
63,
16378,
8,
5387,
12,
1101,
304,
272,
408,
12584,
314,
2897,
436,
372,
31712,
3903,
3532,
20843,
1041,
272,
19121,
275,
31712,
3903,
3532,
20843,
8,
888,
59,
7378,
566,
272,
372,
19121,
340,
19121,
14,
3742,
63,
826,
587,
488,
421,
199,
533,
31712,
3903,
3532,
20843,
8,
2510,
20843,
304,
272,
408,
2765,
1021,
9212,
282,
28671,
649,
58,
1,
3532,
6197,
1041,
339,
347,
636,
826,
721,
277,
12,
1101,
304,
267,
408,
9345,
314,
19121,
1041,
267,
291,
14,
2019,
63,
2604,
275,
942,
267,
291,
14,
1102,
275,
1101,
59,
3103,
63,
5449,
61,
267,
291,
14,
2473,
275,
1101,
59,
3103,
63,
11958,
61,
267,
291,
14,
2060,
275,
1101,
59,
3103,
63,
9032,
61,
267,
291,
14,
3742,
63,
826,
275,
715,
398,
327,
15896,
13306,
282,
1950,
370,
314,
28671,
649,
58,
1,
3532,
14,
267,
862,
26,
288,
291,
14,
25876,
3903,
63,
1977,
275,
31712,
3903,
19620,
8,
355,
2287,
29,
277,
14,
1102,
12,
922,
29,
277,
14,
2473,
12,
2505,
29,
277,
14,
2060,
288,
776,
267,
871,
334,
3393,
12,
3146,
304,
288,
291,
14,
25876,
3903,
63,
1977,
275,
488,
398,
327,
2854,
642,
2376,
652,
365,
29870,
370,
11480,
340,
282,
1950,
365,
23594,
14,
267,
327,
2002,
2951,
1104,
367,
2973,
2251,
14,
267,
340,
291,
14,
25876,
3903,
63,
1977,
365,
488,
503,
440,
291,
14,
25876,
3903,
63,
1977,
14,
1238,
354,
26,
288,
291,
14,
3742,
63,
826,
275,
756,
398,
340,
291,
14,
3742,
63,
826,
26,
288,
485,
10186,
14,
815,
480,
25001,
8539,
370,
450,
83,
401,
291,
14,
25876,
3903,
63,
1977,
14,
1238,
354,
9,
288,
291,
423,
873,
63,
815,
342,
267,
587,
26,
288,
485,
10186,
14,
705,
8,
355,
298,
4276,
370,
16873,
1950,
370,
28671,
649,
58,
1,
3532,
543,
3531,
26,
450,
83,
401,
291,
14,
1102,
288,
776,
339,
347,
8000,
63,
6410,
8,
277,
304,
267,
408,
15936,
367,
892,
7256,
436,
372,
282,
769,
402,
1911,
2243,
2762,
1041,
267,
291,
423,
873,
63,
815,
342,
267,
4702,
63,
5146,
275,
942,
267,
367,
6040,
63,
1102,
315,
291,
14,
2019,
63,
2604,
26,
288,
340,
6040,
63,
1102,
905,
1205,
937,
436,
6040,
63,
1102,
14,
362,
480,
3088,
2349,
355,
4702,
63,
5146,
14,
740,
8,
3159,
63,
1102,
905,
3088,
3135,
267,
372,
4702,
63,
5146,
339,
347,
664,
63,
1782,
63,
354,
8,
277,
12,
2243,
304,
267,
408,
1767,
314,
536,
402,
314,
1627,
2243,
503,
488,
340,
365,
440,
6040,
1041,
267,
2203,
275,
291,
14,
25876,
3903,
63,
1977,
14,
362,
63,
6100,
63,
1102,
63,
2373,
8,
1782,
680,
362,
480,
4665,
4965,
985,
531,
267,
340,
2203,
508,
24702,
288,
372,
488,
267,
372,
2203,
339,
347,
664,
63,
2911,
63,
2987,
8,
277,
12,
2243,
304,
267,
408,
1767,
314,
3004,
334,
711,
12,
4497,
9,
402,
314,
1627,
2243,
503,
488,
340,
365,
440,
6040,
1041,
267,
3384,
63,
1782,
275,
291,
14,
25876,
3903,
63,
1977,
14,
362,
63,
6100,
63,
1102,
63,
2373,
8,
1782,
680,
362,
480,
4665,
14955,
531,
398,
340,
440,
3384,
63,
1782,
26,
288,
372,
1052,
267,
372,
2420,
711,
582,
3384,
63,
1782,
12,
298,
3088,
582,
2243,
93,
339,
347,
485,
873,
63,
815,
8,
277,
304,
267,
408,
15310,
8839,
2556,
687,
314,
28671,
649,
58,
1,
3532,
1041,
267,
340,
440,
291,
14,
3742,
63,
826,
26,
288,
372,
756,
398,
485,
10186,
14,
1757,
480,
7181,
11495,
531,
267,
291,
14,
2019,
63,
2604,
275,
291,
14,
25876,
3903,
63,
1977,
14,
362,
63,
5146,
63,
815,
342,
267,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dahiro/shotgun-replica
|
shotgun_replica/python/src/shotgun_replica/thumbnails.py
|
1
|
2787
|
# -*- coding: utf-8 -*-
'''
handling thumbnailing
'''
from shotgun_replica import config as srconfig
import shotgun_api3
import os
from shotgun_api3.lib.httplib2 import Http
from shotgun_replica.utilities import debug
from elefant.utilities import config
import uuid
import shutil
def getUrlAndStoreLocally( entity_type, entity_id, attribute_name ):
sg = shotgun_api3.Shotgun( srconfig.SHOTGUN_URL,
srconfig.SHOTGUN_SYNC_SKRIPT,
srconfig.SHOTGUN_SYNC_KEY )
val = sg.find_one( entity_type,
filters = [['id', 'is', entity_id]],
fields = [attribute_name] )
imageUrl = val[attribute_name]
if imageUrl != None:
saveShotgunImageLocally( imageUrl )
return imageUrl.split("?")[0]
def __getPathFromImageUrl( url ):
"""return path from image url"""
url = url.replace( "https://", "" )
url = url.replace( "http://", "" )
pathElements = url.split( "/" )
server = pathElements[0]
filename = pathElements[len( pathElements ) - 1]
filename = filename.split( "?" )[0]
path = os.sep.join( pathElements[1:( len( pathElements ) - 1 )] )
return [path, filename]
def __getAbsShotgunImagePath( path, filename ):
"""get shotgun image path locally"""
thepath = os.path.join( srconfig.SHOTGUN_LOCAL_THUMBFOLDER, path )
if not ( os.path.isdir( thepath ) ):
oldumask = os.umask(0o002)
os.makedirs( thepath, 0o775 )
os.umask(oldumask)
return os.path.join( thepath, filename )
def createTestThumbnailPath( srcImage ):
""" store image in local thumbpath and return shotgun-url
"""
url = config.Configuration().get( config.CONF_SHOTGUN_URL )
url += "/files/testfiles/" + str( uuid.uuid1() ) + "/"
url += os.path.basename( srcImage )
localPath = getLocalThumbPath( url )
shutil.copy( srcImage, localPath )
return url
def getLocalThumbPath( url ):
""" translate thumbnail url to local path """
if url == None:
return None
[path, filename] = __getPathFromImageUrl( url )
return __getAbsShotgunImagePath( path, filename )
def saveShotgunImageLocally( url ):
"""save shotgun image locally"""
if type( url ) not in [str, unicode]:
return None
debug.debug( "loading: " + url )
http = Http()
[response, content] = http.request( url, "GET" )
debug.debug( response )
[path, filename] = __getPathFromImageUrl( url )
savedAt = __getAbsShotgunImagePath( path, filename )
debug.debug( savedAt )
oldumask = os.umask( 0o002 )
imagefile = open( savedAt, "w" )
imagefile.write( content )
imagefile.close()
os.umask( oldumask )
os.chmod( savedAt, 0o664 )
return savedAt
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
2344,
199,
22273,
10062,
316,
199,
2344,
199,
199,
504,
1033,
357,
17924,
63,
12317,
492,
1101,
465,
11483,
888,
199,
646,
1033,
357,
17924,
63,
1246,
19,
199,
646,
747,
199,
504,
1033,
357,
17924,
63,
1246,
19,
14,
773,
14,
12942,
18,
492,
4760,
199,
504,
1033,
357,
17924,
63,
12317,
14,
16355,
492,
3105,
199,
504,
12993,
70,
867,
14,
16355,
492,
1101,
199,
646,
5377,
199,
646,
5145,
199,
199,
318,
29937,
3325,
5502,
3040,
1183,
8,
4642,
63,
466,
12,
4642,
63,
344,
12,
2225,
63,
354,
3461,
339,
12578,
275,
1033,
357,
17924,
63,
1246,
19,
14,
2662,
357,
17924,
8,
11483,
888,
14,
25041,
39,
1734,
63,
2632,
12,
3044,
11483,
888,
14,
25041,
39,
1734,
63,
22012,
63,
8656,
50,
4385,
12,
3044,
11483,
888,
14,
25041,
39,
1734,
63,
22012,
63,
3078,
776,
272,
1139,
275,
12578,
14,
1623,
63,
368,
8,
4642,
63,
466,
12,
2432,
4766,
275,
11194,
344,
297,
283,
374,
297,
4642,
63,
344,
2365,
2432,
1504,
275,
359,
3215,
63,
354,
61,
776,
272,
1834,
6417,
275,
1139,
59,
3215,
63,
354,
61,
339,
340,
1834,
6417,
1137,
488,
26,
267,
3354,
2662,
357,
17924,
3491,
3040,
1183,
8,
1834,
6417,
776,
5493,
372,
1834,
6417,
14,
1294,
480,
31,
9981,
16,
61,
199,
199,
318,
636,
362,
2042,
2532,
3491,
6417,
8,
1166,
3461,
272,
408,
1107,
931,
687,
1834,
1166,
624,
272,
1166,
275,
1166,
14,
1814,
8,
298,
2859,
921,
401,
3087,
776,
272,
1166,
275,
1166,
14,
1814,
8,
298,
1014,
921,
401,
3087,
776,
272,
931,
6255,
275,
1166,
14,
1294,
8,
10609,
776,
272,
1654,
275,
931,
6255,
59,
16,
61,
272,
1788,
275,
931,
6255,
59,
552,
8,
931,
6255,
776,
446,
413,
61,
272,
1788,
275,
1788,
14,
1294,
8,
29325,
29688,
16,
61,
339,
931,
275,
747,
14,
4127,
14,
904,
8,
931,
6255,
59,
17,
20334,
822,
8,
931,
6255,
776,
446,
413,
776,
61,
776,
272,
372,
359,
515,
12,
1788,
61,
199,
199,
318,
636,
362,
15447,
2662,
357,
17924,
3491,
2042,
8,
931,
12,
1788,
3461,
272,
408,
362,
1033,
357,
17924,
1834,
931,
17738,
624,
272,
314,
515,
275,
747,
14,
515,
14,
904,
8,
11483,
888,
14,
25041,
39,
1734,
63,
7486,
63,
2080,
2639,
12659,
15744,
12,
931,
776,
272,
340,
440,
334,
747,
14,
515,
14,
6027,
8,
314,
515,
776,
3461,
267,
2269,
18315,
275,
747,
14,
18315,
8,
16,
79,
7432,
9,
267,
747,
14,
8347,
8,
314,
515,
12,
378,
79,
12710,
776,
267,
747,
14,
18315,
8,
1753,
18315,
9,
272,
372,
747,
14,
515,
14,
904,
8,
314,
515,
12,
1788,
776,
199,
199,
318,
1218,
774,
2719,
5820,
2042,
8,
2928,
3491,
3461,
272,
408,
3877,
1834,
315,
2257,
21541,
515,
436,
372,
1033,
357,
17924,
13,
633,
272,
408,
339,
1166,
275,
1101,
14,
5688,
1252,
362,
8,
1101,
14,
3103,
63,
25041,
39,
1734,
63,
2632,
776,
272,
1166,
847,
3286,
1725,
15,
396,
1725,
6687,
435,
620,
8,
5377,
14,
2580,
17,
342,
776,
435,
10609,
272,
1166,
847,
747,
14,
515,
14,
4846,
8,
2928,
3491,
776,
339,
2257,
2042,
275,
664,
5339,
2719,
4295,
2042,
8,
1166,
776,
272,
5145,
14,
1574,
8,
2928,
3491,
12,
2257,
2042,
776,
339,
372,
1166,
199,
199,
318,
664,
5339,
2719,
4295,
2042,
8,
1166,
3461,
272,
408,
9028,
10062,
1166,
370,
2257,
931,
408,
339,
340,
1166,
508,
488,
26,
267,
372,
488,
272,
359,
515,
12,
1788,
61,
275,
636,
362,
2042,
2532,
3491,
6417,
8,
1166,
776,
272,
372,
636,
362,
15447,
2662,
357,
17924,
3491,
2042,
8,
931,
12,
1788,
776,
199,
199,
318,
3354,
2662,
357,
17924,
3491,
3040,
1183,
8,
1166,
3461,
272,
408,
2117,
1033,
357,
17924,
1834,
17738,
624,
272,
340,
730,
8,
1166,
776,
440,
315,
359,
495,
12,
2649,
2189,
267,
372,
488,
272,
3105,
14,
1757,
8,
298,
8786,
26,
298,
435,
1166,
776,
339,
1455,
275,
4760,
342,
272,
359,
1310,
12,
1564,
61,
275,
1455,
14,
1069,
8,
1166,
12,
298,
2970,
2,
776,
272,
3105,
14,
1757,
8,
1177,
776,
272,
359,
515,
12,
1788,
61,
275,
636,
362,
2042,
2532,
3491,
6417,
8,
1166,
776,
339,
6290,
1271,
275,
636,
362,
15447,
2662,
357,
17924,
3491,
2042,
8,
931,
12,
1788,
776,
272,
3105,
14,
1757,
8,
6290,
1271,
776,
272,
2269,
18315,
275,
747,
14,
18315,
8,
378,
79,
7432,
776,
272,
1834,
493,
275,
1551,
8,
6290,
1271,
12,
298,
87,
2,
776,
272,
1834,
493,
14,
952,
8,
1564,
776,
272,
1834,
493,
14,
1600,
342,
272,
747,
14,
18315,
8,
2269,
18315,
776,
272,
747,
14,
11693,
8,
6290,
1271,
12,
378,
79,
28169,
776,
339,
372,
6290,
1271,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
2344,
199,
22273,
10062,
316,
199,
2344,
199,
199,
504,
1033,
357,
17924,
63,
12317,
492,
1101,
465,
11483,
888,
199,
646,
1033,
357,
17924,
63,
1246,
19,
199,
646,
747,
199,
504,
1033,
357,
17924,
63,
1246,
19,
14,
773,
14,
12942,
18,
492,
4760,
199,
504,
1033,
357,
17924,
63,
12317,
14,
16355,
492,
3105,
199,
504,
12993,
70,
867,
14,
16355,
492,
1101,
199,
646,
5377,
199,
646,
5145,
199,
199,
318,
29937,
3325,
5502,
3040,
1183,
8,
4642,
63,
466,
12,
4642,
63,
344,
12,
2225,
63,
354,
3461,
339,
12578,
275,
1033,
357,
17924,
63,
1246,
19,
14,
2662,
357,
17924,
8,
11483,
888,
14,
25041,
39,
1734,
63,
2632,
12,
3044,
11483,
888,
14,
25041,
39,
1734,
63,
22012,
63,
8656,
50,
4385,
12,
3044,
11483,
888,
14,
25041,
39,
1734,
63,
22012,
63,
3078,
776,
272,
1139,
275,
12578,
14,
1623,
63,
368,
8,
4642,
63,
466,
12,
2432,
4766,
275,
11194,
344,
297,
283,
374,
297,
4642,
63,
344,
2365,
2432,
1504,
275,
359,
3215,
63,
354,
61,
776,
272,
1834,
6417,
275,
1139,
59,
3215,
63,
354,
61,
339,
340,
1834,
6417,
1137,
488,
26,
267,
3354,
2662,
357,
17924,
3491,
3040,
1183,
8,
1834,
6417,
776,
5493,
372,
1834,
6417,
14,
1294,
480,
31,
9981,
16,
61,
199,
199,
318,
636,
362,
2042,
2532,
3491,
6417,
8,
1166,
3461,
272,
408,
1107,
931,
687,
1834,
1166,
624,
272,
1166,
275,
1166,
14,
1814,
8,
298,
2859,
921,
401,
3087,
776,
272,
1166,
275,
1166,
14,
1814,
8,
298,
1014,
921,
401,
3087,
776,
272,
931,
6255,
275,
1166,
14,
1294,
8,
10609,
776,
272,
1654,
275,
931,
6255,
59,
16,
61,
272,
1788,
275,
931,
6255,
59,
552,
8,
931,
6255,
776,
446,
413,
61,
272,
1788,
275,
1788,
14,
1294,
8,
29325,
29688,
16,
61,
339,
931,
275,
747,
14,
4127,
14,
904,
8,
931,
6255,
59,
17,
20334,
822,
8,
931,
6255,
776,
446,
413,
776,
61,
776,
272,
372,
359,
515,
12,
1788,
61,
199,
199,
318,
636,
362,
15447,
2662,
357,
17924,
3491,
2042,
8,
931,
12,
1788,
3461,
272,
408,
362,
1033,
357,
17924,
1834,
931,
17738,
624,
272,
314,
515,
275,
747,
14,
515,
14,
904,
8,
11483,
888,
14,
25041,
39,
1734,
63,
7486,
63,
2080,
2639,
12659,
15744,
12,
931,
776,
272,
340,
440,
334,
747,
14,
515,
14,
6027,
8,
314,
515,
776,
3461,
267,
2269,
18315,
275,
747,
14,
18315,
8,
16,
79,
7432,
9,
267,
747,
14,
8347,
8,
314,
515,
12,
378,
79,
12710,
776,
267,
747,
14,
18315,
8,
1753,
18315,
9,
272,
372,
747,
14,
515,
14,
904,
8,
314,
515,
12,
1788,
776,
199,
199,
318,
1218,
774,
2719,
5820,
2042,
8,
2928,
3491,
3461,
272,
408,
3877,
1834,
315,
2257,
21541,
515,
436,
372,
1033,
357,
17924,
13,
633,
272,
408,
339,
1166,
275,
1101,
14,
5688,
1252,
362,
8,
1101,
14,
3103,
63,
25041,
39,
1734,
63,
2632,
776,
272,
1166,
847,
3286,
1725,
15,
396,
1725,
6687,
435,
620,
8,
5377,
14,
2580,
17,
342,
776,
435,
10609,
272,
1166,
847,
747,
14,
515,
14,
4846,
8,
2928,
3491,
776,
339,
2257,
2042,
275,
664,
5339,
2719,
4295,
2042,
8,
1166,
776,
272,
5145,
14,
1574,
8,
2928,
3491,
12,
2257,
2042,
776,
339,
372,
1166,
199,
199,
318,
664,
5339,
2719,
4295,
2042,
8,
1166,
3461,
272,
408,
9028,
10062,
1166,
370,
2257,
931,
408,
339,
340,
1166,
508,
488,
26,
267,
372,
488,
272,
359,
515,
12,
1788,
61,
275,
636,
362,
2042,
2532,
3491,
6417,
8,
1166,
776,
272,
372,
636,
362,
15447,
2662,
357,
17924,
3491,
2042,
8,
931,
12,
1788,
776,
199,
199,
318,
3354,
2662,
357,
17924,
3491,
3040,
1183,
8,
1166,
3461,
272,
408,
2117,
1033,
357,
17924,
1834,
17738,
624,
272,
340,
730,
8,
1166,
776,
440,
315,
359,
495,
12,
2649,
2189,
267,
372,
488,
272,
3105,
14,
1757,
8,
298,
8786,
26,
298,
435,
1166,
776,
339,
1455,
275,
4760,
342,
272,
359,
1310,
12,
1564,
61,
275,
1455,
14,
1069,
8,
1166,
12,
298,
2970,
2,
776,
272,
3105,
14,
1757,
8,
1177,
776,
272,
359,
515,
12,
1788,
61,
275,
636,
362,
2042,
2532,
3491,
6417,
8,
1166,
776,
339,
6290,
1271,
275,
636,
362,
15447,
2662,
357,
17924,
3491,
2042,
8,
931,
12,
1788,
776,
272,
3105,
14,
1757,
8,
6290,
1271,
776,
272,
2269,
18315,
275,
747,
14,
18315,
8,
378,
79,
7432,
776,
272,
1834,
493,
275,
1551,
8,
6290,
1271,
12,
298,
87,
2,
776,
272,
1834,
493,
14,
952,
8,
1564,
776,
272,
1834,
493,
14,
1600,
342,
272,
747,
14,
18315,
8,
2269,
18315,
776,
272,
747,
14,
11693,
8,
6290,
1271,
12,
378,
79,
28169,
776,
339,
372,
6290,
1271,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
wuhengzhi/chromium-crosswalk
|
third_party/cython/src/Cython/Build/BuildExecutable.py
|
98
|
4286
|
"""
Compile a Python script into an executable that embeds CPython and run it.
Requires CPython to be built as a shared library ('libpythonX.Y').
Basic usage:
python cythonrun somefile.py [ARGS]
"""
DEBUG = True
import sys
import os
from distutils import sysconfig
def get_config_var(name, default=''):
return sysconfig.get_config_var(name) or default
INCDIR = sysconfig.get_python_inc()
LIBDIR1 = get_config_var('LIBDIR')
LIBDIR2 = get_config_var('LIBPL')
PYLIB = get_config_var('LIBRARY')
PYLIB_DYN = get_config_var('LDLIBRARY')
if PYLIB_DYN == PYLIB:
# no shared library
PYLIB_DYN = ''
else:
PYLIB_DYN = os.path.splitext(PYLIB_DYN[3:])[0] # 'lib(XYZ).so' -> XYZ
CC = get_config_var('CC', os.environ.get('CC', ''))
CFLAGS = get_config_var('CFLAGS') + ' ' + os.environ.get('CFLAGS', '')
LINKCC = get_config_var('LINKCC', os.environ.get('LINKCC', CC))
LINKFORSHARED = get_config_var('LINKFORSHARED')
LIBS = get_config_var('LIBS')
SYSLIBS = get_config_var('SYSLIBS')
EXE_EXT = sysconfig.get_config_var('EXE')
def _debug(msg, *args):
if DEBUG:
if args:
msg = msg % args
sys.stderr.write(msg + '\n')
def dump_config():
_debug('INCDIR: %s', INCDIR)
_debug('LIBDIR1: %s', LIBDIR1)
_debug('LIBDIR2: %s', LIBDIR2)
_debug('PYLIB: %s', PYLIB)
_debug('PYLIB_DYN: %s', PYLIB_DYN)
_debug('CC: %s', CC)
_debug('CFLAGS: %s', CFLAGS)
_debug('LINKCC: %s', LINKCC)
_debug('LINKFORSHARED: %s', LINKFORSHARED)
_debug('LIBS: %s', LIBS)
_debug('SYSLIBS: %s', SYSLIBS)
_debug('EXE_EXT: %s', EXE_EXT)
def runcmd(cmd, shell=True):
if shell:
cmd = ' '.join(cmd)
_debug(cmd)
else:
_debug(' '.join(cmd))
try:
import subprocess
except ImportError: # Python 2.3 ...
returncode = os.system(cmd)
else:
returncode = subprocess.call(cmd, shell=shell)
if returncode:
sys.exit(returncode)
def clink(basename):
runcmd([LINKCC, '-o', basename + EXE_EXT, basename+'.o', '-L'+LIBDIR1, '-L'+LIBDIR2]
+ [PYLIB_DYN and ('-l'+PYLIB_DYN) or os.path.join(LIBDIR1, PYLIB)]
+ LIBS.split() + SYSLIBS.split() + LINKFORSHARED.split())
def ccompile(basename):
runcmd([CC, '-c', '-o', basename+'.o', basename+'.c', '-I' + INCDIR] + CFLAGS.split())
def cycompile(input_file, options=()):
from Cython.Compiler import Version, CmdLine, Main
options, sources = CmdLine.parse_command_line(list(options or ()) + ['--embed', input_file])
_debug('Using Cython %s to compile %s', Version.version, input_file)
result = Main.compile(sources, options)
if result.num_errors > 0:
sys.exit(1)
def exec_file(program_name, args=()):
runcmd([os.path.abspath(program_name)] + list(args), shell=False)
def build(input_file, compiler_args=(), force=False):
"""
Build an executable program from a Cython module.
Returns the name of the executable file.
"""
basename = os.path.splitext(input_file)[0]
exe_file = basename + EXE_EXT
if not force and os.path.abspath(exe_file) == os.path.abspath(input_file):
raise ValueError("Input and output file names are the same, refusing to overwrite")
if (not force and os.path.exists(exe_file) and os.path.exists(input_file)
and os.path.getmtime(input_file) <= os.path.getmtime(exe_file)):
_debug("File is up to date, not regenerating %s", exe_file)
return exe_file
cycompile(input_file, compiler_args)
ccompile(basename)
clink(basename)
return exe_file
def build_and_run(args):
"""
Build an executable program from a Cython module and runs it.
Arguments after the module name will be passed verbatimely to the
program.
"""
cy_args = []
last_arg = None
for i, arg in enumerate(args):
if arg.startswith('-'):
cy_args.append(arg)
elif last_arg in ('-X', '--directive'):
cy_args.append(arg)
else:
input_file = arg
args = args[i+1:]
break
last_arg = arg
else:
raise ValueError('no input file provided')
program_name = build(input_file, cy_args)
exec_file(program_name, args)
if __name__ == '__main__':
build_and_run(sys.argv[1:])
|
bsd-3-clause
|
[
624,
199,
12626,
282,
2018,
2884,
1901,
376,
7286,
626,
6441,
83,
25654,
436,
1255,
652,
14,
199,
18153,
25654,
370,
506,
6137,
465,
282,
5709,
3555,
661,
773,
1548,
56,
14,
57,
1959,
199,
199,
6845,
4503,
26,
339,
2366,
29348,
1065,
2005,
493,
14,
647,
359,
13990,
61,
199,
624,
199,
199,
5287,
275,
715,
199,
199,
646,
984,
199,
646,
747,
199,
504,
7065,
492,
22381,
199,
199,
318,
664,
63,
888,
63,
1391,
8,
354,
12,
849,
9280,
272,
372,
22381,
14,
362,
63,
888,
63,
1391,
8,
354,
9,
503,
849,
199,
199,
25205,
3022,
275,
22381,
14,
362,
63,
1548,
63,
6559,
342,
199,
5617,
3022,
17,
275,
664,
63,
888,
63,
1391,
360,
5617,
3022,
358,
199,
5617,
3022,
18,
275,
664,
63,
888,
63,
1391,
360,
5617,
2749,
358,
199,
4521,
5617,
275,
664,
63,
888,
63,
1391,
360,
16983,
358,
199,
4521,
5617,
63,
11446,
46,
275,
664,
63,
888,
63,
1391,
360,
6533,
16983,
358,
199,
692,
7843,
5617,
63,
11446,
46,
508,
7843,
5617,
26,
272,
327,
949,
5709,
3555,
272,
7843,
5617,
63,
11446,
46,
275,
2125,
199,
2836,
26,
272,
7843,
5617,
63,
11446,
46,
275,
747,
14,
515,
14,
7973,
8,
4521,
5617,
63,
11446,
46,
59,
19,
5728,
59,
16,
61,
327,
283,
773,
8,
16694,
680,
1152,
7,
1035,
1323,
26184,
199,
199,
2571,
275,
664,
63,
888,
63,
1391,
360,
2571,
297,
747,
14,
2314,
14,
362,
360,
2571,
297,
12381,
199,
14804,
275,
664,
63,
888,
63,
1391,
360,
14804,
358,
435,
283,
283,
435,
747,
14,
2314,
14,
362,
360,
14804,
297,
4074,
199,
7916,
2571,
275,
664,
63,
888,
63,
1391,
360,
7916,
2571,
297,
747,
14,
2314,
14,
362,
360,
7916,
2571,
297,
17586,
430,
199,
7916,
2707,
13772,
275,
664,
63,
888,
63,
1391,
360,
7916,
2707,
13772,
358,
199,
25161,
275,
664,
63,
888,
63,
1391,
360,
25161,
358,
199,
4669,
4929,
2100,
51,
275,
664,
63,
888,
63,
1391,
360,
4669,
4929,
2100,
51,
358,
199,
23017,
63,
2472,
275,
22381,
14,
362,
63,
888,
63,
1391,
360,
23017,
358,
199,
199,
318,
485,
1757,
8,
1328,
12,
627,
589,
304,
272,
340,
10990,
26,
267,
340,
1249,
26,
288,
1499,
275,
1499,
450,
1249,
267,
984,
14,
3083,
14,
952,
8,
1328,
435,
1557,
78,
358,
199,
199,
318,
5461,
63,
888,
837,
272,
485,
1757,
360,
25205,
3022,
26,
450,
83,
297,
7839,
3022,
9,
272,
485,
1757,
360,
5617,
3022,
17,
26,
450,
83,
297,
25764,
3022,
17,
9,
272,
485,
1757,
360,
5617,
3022,
18,
26,
450,
83,
297,
25764,
3022,
18,
9,
272,
485,
1757,
360,
4521,
5617,
26,
450,
83,
297,
7843,
5617,
9,
272,
485,
1757,
360,
4521,
5617,
63,
11446,
46,
26,
450,
83,
297,
7843,
5617,
63,
11446,
46,
9,
272,
485,
1757,
360,
2571,
26,
450,
83,
297,
17586,
9,
272,
485,
1757,
360,
14804,
26,
450,
83,
297,
25149,
9,
272,
485,
1757,
360,
7916,
2571,
26,
450,
83,
297,
19774,
2571,
9,
272,
485,
1757,
360,
7916,
2707,
13772,
26,
450,
83,
297,
19774,
2707,
13772,
9,
272,
485,
1757,
360,
25161,
26,
450,
83,
297,
25764,
51,
9,
272,
485,
1757,
360,
4669,
4929,
2100,
51,
26,
450,
83,
297,
10046,
4929,
2100,
51,
9,
272,
485,
1757,
360,
23017,
63,
2472,
26,
450,
83,
297,
3651,
37,
63,
2472,
9,
199,
199,
318,
519,
1097,
1064,
8,
1760,
12,
5218,
29,
549,
304,
272,
340,
5218,
26,
267,
2088,
275,
283,
1987,
904,
8,
1760,
9,
267,
485,
1757,
8,
1760,
9,
272,
587,
26,
267,
485,
1757,
360,
1987,
904,
8,
1760,
430,
339,
862,
26,
267,
492,
3873,
272,
871,
3545,
26,
327,
2018,
499,
14,
19,
2263,
267,
17630,
275,
747,
14,
2253,
8,
1760,
9,
272,
587,
26,
267,
17630,
275,
3873,
14,
1250,
8,
1760,
12,
5218,
29,
5641,
9,
2286,
340,
17630,
26,
267,
984,
14,
2224,
8,
9913,
9,
199,
199,
318,
286,
1073,
8,
4846,
304,
272,
519,
1097,
1064,
779,
7916,
2571,
12,
2475,
79,
297,
9593,
435,
3651,
37,
63,
2472,
12,
9593,
18098,
79,
297,
2475,
44,
6828,
5617,
3022,
17,
12,
2475,
44,
6828,
5617,
3022,
18,
61,
1779,
435,
359,
4521,
5617,
63,
11446,
46,
436,
12291,
76,
6828,
4521,
5617,
63,
11446,
46,
9,
503,
747,
14,
515,
14,
904,
8,
5617,
3022,
17,
12,
7843,
5617,
1874,
1779,
435,
25764,
51,
14,
1294,
342,
435,
10046,
4929,
2100,
51,
14,
1294,
342,
435,
19774,
2707,
13772,
14,
1294,
1012,
199,
199,
318,
286,
2014,
8,
4846,
304,
272,
519,
1097,
1064,
779,
2571,
12,
2475,
67,
297,
2475,
79,
297,
9593,
18098,
79,
297,
9593,
18098,
67,
297,
2475,
41,
7,
435,
7839,
3022,
61,
435,
25149,
14,
1294,
1012,
199,
199,
318,
6325,
2014,
8,
1210,
63,
493,
12,
1511,
23603,
272,
687,
26741,
14,
9131,
492,
3394,
12,
26005,
3049,
12,
11298,
272,
1511,
12,
5274,
275,
26005,
3049,
14,
1122,
63,
1531,
63,
604,
8,
513,
8,
1419,
503,
14515,
435,
14574,
6427,
297,
1324,
63,
493,
566,
272,
485,
1757,
360,
10369,
26741,
450,
83,
370,
6555,
450,
83,
297,
3394,
14,
1023,
12,
1324,
63,
493,
9,
272,
754,
275,
11298,
14,
2014,
8,
4553,
12,
1511,
9,
272,
340,
754,
14,
1507,
63,
2550,
690,
378,
26,
267,
984,
14,
2224,
8,
17,
9,
199,
199,
318,
2146,
63,
493,
8,
6815,
63,
354,
12,
1249,
23603,
272,
519,
1097,
1064,
779,
736,
14,
515,
14,
4832,
8,
6815,
63,
354,
1874,
435,
769,
8,
589,
395,
5218,
29,
797,
9,
199,
199,
318,
1900,
8,
1210,
63,
493,
12,
6365,
63,
589,
16729,
3542,
29,
797,
304,
272,
408,
272,
6516,
376,
7286,
2240,
687,
282,
26741,
859,
14,
339,
1803,
314,
536,
402,
314,
7286,
570,
14,
272,
408,
272,
9593,
275,
747,
14,
515,
14,
7973,
8,
1210,
63,
493,
2788,
16,
61,
272,
14778,
63,
493,
275,
9593,
435,
3651,
37,
63,
2472,
272,
340,
440,
3542,
436,
747,
14,
515,
14,
4832,
8,
5803,
63,
493,
9,
508,
747,
14
] |
[
199,
12626,
282,
2018,
2884,
1901,
376,
7286,
626,
6441,
83,
25654,
436,
1255,
652,
14,
199,
18153,
25654,
370,
506,
6137,
465,
282,
5709,
3555,
661,
773,
1548,
56,
14,
57,
1959,
199,
199,
6845,
4503,
26,
339,
2366,
29348,
1065,
2005,
493,
14,
647,
359,
13990,
61,
199,
624,
199,
199,
5287,
275,
715,
199,
199,
646,
984,
199,
646,
747,
199,
504,
7065,
492,
22381,
199,
199,
318,
664,
63,
888,
63,
1391,
8,
354,
12,
849,
9280,
272,
372,
22381,
14,
362,
63,
888,
63,
1391,
8,
354,
9,
503,
849,
199,
199,
25205,
3022,
275,
22381,
14,
362,
63,
1548,
63,
6559,
342,
199,
5617,
3022,
17,
275,
664,
63,
888,
63,
1391,
360,
5617,
3022,
358,
199,
5617,
3022,
18,
275,
664,
63,
888,
63,
1391,
360,
5617,
2749,
358,
199,
4521,
5617,
275,
664,
63,
888,
63,
1391,
360,
16983,
358,
199,
4521,
5617,
63,
11446,
46,
275,
664,
63,
888,
63,
1391,
360,
6533,
16983,
358,
199,
692,
7843,
5617,
63,
11446,
46,
508,
7843,
5617,
26,
272,
327,
949,
5709,
3555,
272,
7843,
5617,
63,
11446,
46,
275,
2125,
199,
2836,
26,
272,
7843,
5617,
63,
11446,
46,
275,
747,
14,
515,
14,
7973,
8,
4521,
5617,
63,
11446,
46,
59,
19,
5728,
59,
16,
61,
327,
283,
773,
8,
16694,
680,
1152,
7,
1035,
1323,
26184,
199,
199,
2571,
275,
664,
63,
888,
63,
1391,
360,
2571,
297,
747,
14,
2314,
14,
362,
360,
2571,
297,
12381,
199,
14804,
275,
664,
63,
888,
63,
1391,
360,
14804,
358,
435,
283,
283,
435,
747,
14,
2314,
14,
362,
360,
14804,
297,
4074,
199,
7916,
2571,
275,
664,
63,
888,
63,
1391,
360,
7916,
2571,
297,
747,
14,
2314,
14,
362,
360,
7916,
2571,
297,
17586,
430,
199,
7916,
2707,
13772,
275,
664,
63,
888,
63,
1391,
360,
7916,
2707,
13772,
358,
199,
25161,
275,
664,
63,
888,
63,
1391,
360,
25161,
358,
199,
4669,
4929,
2100,
51,
275,
664,
63,
888,
63,
1391,
360,
4669,
4929,
2100,
51,
358,
199,
23017,
63,
2472,
275,
22381,
14,
362,
63,
888,
63,
1391,
360,
23017,
358,
199,
199,
318,
485,
1757,
8,
1328,
12,
627,
589,
304,
272,
340,
10990,
26,
267,
340,
1249,
26,
288,
1499,
275,
1499,
450,
1249,
267,
984,
14,
3083,
14,
952,
8,
1328,
435,
1557,
78,
358,
199,
199,
318,
5461,
63,
888,
837,
272,
485,
1757,
360,
25205,
3022,
26,
450,
83,
297,
7839,
3022,
9,
272,
485,
1757,
360,
5617,
3022,
17,
26,
450,
83,
297,
25764,
3022,
17,
9,
272,
485,
1757,
360,
5617,
3022,
18,
26,
450,
83,
297,
25764,
3022,
18,
9,
272,
485,
1757,
360,
4521,
5617,
26,
450,
83,
297,
7843,
5617,
9,
272,
485,
1757,
360,
4521,
5617,
63,
11446,
46,
26,
450,
83,
297,
7843,
5617,
63,
11446,
46,
9,
272,
485,
1757,
360,
2571,
26,
450,
83,
297,
17586,
9,
272,
485,
1757,
360,
14804,
26,
450,
83,
297,
25149,
9,
272,
485,
1757,
360,
7916,
2571,
26,
450,
83,
297,
19774,
2571,
9,
272,
485,
1757,
360,
7916,
2707,
13772,
26,
450,
83,
297,
19774,
2707,
13772,
9,
272,
485,
1757,
360,
25161,
26,
450,
83,
297,
25764,
51,
9,
272,
485,
1757,
360,
4669,
4929,
2100,
51,
26,
450,
83,
297,
10046,
4929,
2100,
51,
9,
272,
485,
1757,
360,
23017,
63,
2472,
26,
450,
83,
297,
3651,
37,
63,
2472,
9,
199,
199,
318,
519,
1097,
1064,
8,
1760,
12,
5218,
29,
549,
304,
272,
340,
5218,
26,
267,
2088,
275,
283,
1987,
904,
8,
1760,
9,
267,
485,
1757,
8,
1760,
9,
272,
587,
26,
267,
485,
1757,
360,
1987,
904,
8,
1760,
430,
339,
862,
26,
267,
492,
3873,
272,
871,
3545,
26,
327,
2018,
499,
14,
19,
2263,
267,
17630,
275,
747,
14,
2253,
8,
1760,
9,
272,
587,
26,
267,
17630,
275,
3873,
14,
1250,
8,
1760,
12,
5218,
29,
5641,
9,
2286,
340,
17630,
26,
267,
984,
14,
2224,
8,
9913,
9,
199,
199,
318,
286,
1073,
8,
4846,
304,
272,
519,
1097,
1064,
779,
7916,
2571,
12,
2475,
79,
297,
9593,
435,
3651,
37,
63,
2472,
12,
9593,
18098,
79,
297,
2475,
44,
6828,
5617,
3022,
17,
12,
2475,
44,
6828,
5617,
3022,
18,
61,
1779,
435,
359,
4521,
5617,
63,
11446,
46,
436,
12291,
76,
6828,
4521,
5617,
63,
11446,
46,
9,
503,
747,
14,
515,
14,
904,
8,
5617,
3022,
17,
12,
7843,
5617,
1874,
1779,
435,
25764,
51,
14,
1294,
342,
435,
10046,
4929,
2100,
51,
14,
1294,
342,
435,
19774,
2707,
13772,
14,
1294,
1012,
199,
199,
318,
286,
2014,
8,
4846,
304,
272,
519,
1097,
1064,
779,
2571,
12,
2475,
67,
297,
2475,
79,
297,
9593,
18098,
79,
297,
9593,
18098,
67,
297,
2475,
41,
7,
435,
7839,
3022,
61,
435,
25149,
14,
1294,
1012,
199,
199,
318,
6325,
2014,
8,
1210,
63,
493,
12,
1511,
23603,
272,
687,
26741,
14,
9131,
492,
3394,
12,
26005,
3049,
12,
11298,
272,
1511,
12,
5274,
275,
26005,
3049,
14,
1122,
63,
1531,
63,
604,
8,
513,
8,
1419,
503,
14515,
435,
14574,
6427,
297,
1324,
63,
493,
566,
272,
485,
1757,
360,
10369,
26741,
450,
83,
370,
6555,
450,
83,
297,
3394,
14,
1023,
12,
1324,
63,
493,
9,
272,
754,
275,
11298,
14,
2014,
8,
4553,
12,
1511,
9,
272,
340,
754,
14,
1507,
63,
2550,
690,
378,
26,
267,
984,
14,
2224,
8,
17,
9,
199,
199,
318,
2146,
63,
493,
8,
6815,
63,
354,
12,
1249,
23603,
272,
519,
1097,
1064,
779,
736,
14,
515,
14,
4832,
8,
6815,
63,
354,
1874,
435,
769,
8,
589,
395,
5218,
29,
797,
9,
199,
199,
318,
1900,
8,
1210,
63,
493,
12,
6365,
63,
589,
16729,
3542,
29,
797,
304,
272,
408,
272,
6516,
376,
7286,
2240,
687,
282,
26741,
859,
14,
339,
1803,
314,
536,
402,
314,
7286,
570,
14,
272,
408,
272,
9593,
275,
747,
14,
515,
14,
7973,
8,
1210,
63,
493,
2788,
16,
61,
272,
14778,
63,
493,
275,
9593,
435,
3651,
37,
63,
2472,
272,
340,
440,
3542,
436,
747,
14,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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
kiennquit2011/androguard
|
androguard/decompiler/decompiler.py
|
14
|
16697
|
# This file is part of Androguard.
#
# Copyright (C) 2013, Anthony Desnos <desnos at t0t0.fr>
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from subprocess import Popen, PIPE, STDOUT
import tempfile
import os
from androguard.core.androconf import rrmdir
from androguard.decompiler.dad import decompile
from androguard.util import read
PYGMENTS = True
try:
from pygments.filter import Filter
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import TerminalFormatter
from pygments.token import Token
except ImportError:
PYGMENTS = False
class Filter(object):
pass
class Dex2Jar(object):
def __init__(self, vm, path_dex2jar="./decompiler/dex2jar/", bin_dex2jar="dex2jar.sh", tmp_dir="/tmp/"):
pathtmp = tmp_dir
if not os.path.exists(pathtmp):
os.makedirs(pathtmp)
fd, fdname = tempfile.mkstemp(dir=pathtmp)
with os.fdopen(fd, "w+b") as fd:
fd.write(vm.get_buff())
fd.flush()
compile = Popen([path_dex2jar + bin_dex2jar, fdname], stdout=PIPE, stderr=STDOUT)
stdout, stderr = compile.communicate()
os.unlink(fdname)
self.jarfile = fdname + "_dex2jar.jar"
def get_jar(self):
return self.jarfile
class DecompilerDex2Jad(object):
def __init__(self, vm, path_dex2jar="./decompiler/dex2jar/", bin_dex2jar="dex2jar.sh", path_jad="./decompiler/jad/", bin_jad="jad", tmp_dir="/tmp/"):
self.classes = {}
self.classes_failed = []
pathtmp = tmp_dir
if not os.path.exists(pathtmp):
os.makedirs(pathtmp)
fd, fdname = tempfile.mkstemp(dir=pathtmp)
with os.fdopen(fd, "w+b") as fd:
fd.write(vm.get_buff())
fd.flush()
compile = Popen([path_dex2jar + bin_dex2jar, fdname], stdout=PIPE, stderr=STDOUT)
stdout, stderr = compile.communicate()
os.unlink(fdname)
pathclasses = fdname + "dex2jar/"
compile = Popen(["unzip", fdname + "_dex2jar.jar", "-d", pathclasses], stdout=PIPE, stderr=STDOUT)
stdout, stderr = compile.communicate()
os.unlink(fdname + "_dex2jar.jar")
for root, dirs, files in os.walk(pathclasses, followlinks=True):
if files != []:
for f in files:
real_filename = root
if real_filename[-1] != "/":
real_filename += "/"
real_filename += f
compile = Popen([path_jad + bin_jad, "-o", "-d", root, real_filename], stdout=PIPE, stderr=STDOUT)
stdout, stderr = compile.communicate()
for i in vm.get_classes():
fname = pathclasses + "/" + i.get_name()[1:-1] + ".jad"
if os.path.isfile(fname) == True:
self.classes[i.get_name()] = read(fname, binary=False)
else:
self.classes_failed.append(i.get_name())
rrmdir(pathclasses)
def get_source_method(self, method):
class_name = method.get_class_name()
method_name = method.get_name()
if class_name not in self.classes:
return ""
if PYGMENTS:
lexer = get_lexer_by_name("java", stripall=True)
lexer.add_filter(MethodFilter(method_name=method_name))
formatter = TerminalFormatter()
result = highlight(self.classes[class_name], lexer, formatter)
return result
return self.classes[class_name]
def display_source(self, method):
print self.get_source_method(method)
def get_source_class(self, _class):
return self.classes[_class.get_name()]
def get_all(self, class_name):
if class_name not in self.classes:
return ""
if PYGMENTS:
lexer = get_lexer_by_name("java", stripall=True)
formatter = TerminalFormatter()
result = highlight(self.classes[class_name], lexer, formatter)
return result
return self.classes[class_name]
def display_all(self, _class):
print self.get_all(_class.get_name())
class DecompilerDex2WineJad(object):
def __init__(self, vm, path_dex2jar="./decompiler/dex2jar/", bin_dex2jar="dex2jar.sh", path_jad="./decompiler/jad/", bin_jad="jad", tmp_dir="/tmp/"):
self.classes = {}
self.classes_failed = []
pathtmp = tmp_dir
if not os.path.exists(pathtmp):
os.makedirs(pathtmp)
fd, fdname = tempfile.mkstemp(dir=pathtmp)
with os.fdopen(fd, "w+b") as fd:
fd.write(vm.get_buff())
fd.flush()
compile = Popen([path_dex2jar + bin_dex2jar, fdname], stdout=PIPE, stderr=STDOUT)
stdout, stderr = compile.communicate()
os.unlink(fdname)
pathclasses = fdname + "dex2jar/"
compile = Popen(["unzip", fdname + "_dex2jar.jar", "-d", pathclasses], stdout=PIPE, stderr=STDOUT)
stdout, stderr = compile.communicate()
os.unlink(fdname + "_dex2jar.jar")
for root, dirs, files in os.walk(pathclasses, followlinks=True):
if files != []:
for f in files:
real_filename = root
if real_filename[-1] != "/":
real_filename += "/"
real_filename += f
compile = Popen(["wine", path_jad + bin_jad, "-o", "-d", root, real_filename], stdout=PIPE, stderr=STDOUT)
stdout, stderr = compile.communicate()
for i in vm.get_classes():
fname = pathclasses + "/" + i.get_name()[1:-1] + ".jad"
if os.path.isfile(fname) == True:
self.classes[i.get_name()] = read(fname, binary=False)
else:
self.classes_failed.append(i.get_name())
rrmdir(pathclasses)
def get_source_method(self, method):
class_name = method.get_class_name()
method_name = method.get_name()
if class_name not in self.classes:
return ""
if PYGMENTS:
lexer = get_lexer_by_name("java", stripall=True)
lexer.add_filter(MethodFilter(method_name=method_name))
formatter = TerminalFormatter()
result = highlight(self.classes[class_name], lexer, formatter)
return result
return self.classes[class_name]
def display_source(self, method):
print self.get_source_method(method)
def get_source_class(self, _class):
return self.classes[_class.get_name()]
def get_all(self, class_name):
if class_name not in self.classes:
return ""
if PYGMENTS:
lexer = get_lexer_by_name("java", stripall=True)
formatter = TerminalFormatter()
result = highlight(self.classes[class_name], lexer, formatter)
return result
return self.classes[class_name]
def display_all(self, _class):
print self.get_all(_class.get_name())
class DecompilerDed(object):
def __init__(self, vm, path="./decompiler/ded/", bin_ded="ded.sh", tmp_dir="/tmp/"):
self.classes = {}
self.classes_failed = []
pathtmp = tmp_dir
if not os.path.exists(pathtmp):
os.makedirs( pathtmp )
fd, fdname = tempfile.mkstemp( dir=pathtmp )
with os.fdopen(fd, "w+b") as fd:
fd.write( vm.get_buff() )
fd.flush()
dirname = tempfile.mkdtemp(prefix=fdname + "-src")
compile = Popen([ path + bin_ded, "-c", "-o", "-d", dirname, fdname ], stdout=PIPE, stderr=STDOUT)
stdout, stderr = compile.communicate()
os.unlink( fdname )
findsrc = None
for root, dirs, files in os.walk( dirname + "/optimized-decompiled/" ):
if dirs != []:
for f in dirs:
if f == "src":
findsrc = root
if findsrc[-1] != "/":
findsrc += "/"
findsrc += f
break
if findsrc != None:
break
for i in vm.get_classes():
fname = findsrc + "/" + i.get_name()[1:-1] + ".java"
#print fname
if os.path.isfile(fname) == True:
self.classes[ i.get_name() ] = read(fname, binary=False)
else:
self.classes_failed.append( i.get_name() )
rrmdir( dirname )
def get_source_method(self, method):
class_name = method.get_class_name()
method_name = method.get_name()
if class_name not in self.classes:
return ""
lexer = get_lexer_by_name("java", stripall=True)
lexer.add_filter(MethodFilter(method_name=method_name))
formatter = TerminalFormatter()
result = highlight(self.classes[class_name], lexer, formatter)
return result
def display_source(self, method):
print self.get_source_method(method)
def get_all(self, class_name):
if class_name not in self.classes:
return ""
lexer = get_lexer_by_name("java", stripall=True)
formatter = TerminalFormatter()
result = highlight(self.classes[class_name], lexer, formatter)
return result
def get_source_class(self, _class):
return self.classes[_class.get_name()]
def display_all(self, _class):
print self.get_all(_class.get_name())
class DecompilerDex2Fernflower(object):
def __init__(self,
vm,
path_dex2jar="./decompiler/dex2jar/",
bin_dex2jar="dex2jar.sh",
path_fernflower="./decompiler/fernflower/",
bin_fernflower="fernflower.jar",
options_fernflower={"dgs": '1', "asc": '1'},
tmp_dir="/tmp/"):
self.classes = {}
self.classes_failed = []
pathtmp = tmp_dir
if not os.path.exists(pathtmp):
os.makedirs(pathtmp)
fd, fdname = tempfile.mkstemp(dir=pathtmp)
with os.fdopen(fd, "w+b") as fd:
fd.write(vm.get_buff())
fd.flush()
compile = Popen([path_dex2jar + bin_dex2jar, fdname], stdout=PIPE, stderr=STDOUT)
stdout, stderr = compile.communicate()
os.unlink(fdname)
pathclasses = fdname + "dex2jar/"
compile = Popen(["unzip", fdname + "_dex2jar.jar", "-d", pathclasses], stdout=PIPE, stderr=STDOUT)
stdout, stderr = compile.communicate()
os.unlink(fdname + "_dex2jar.jar")
for root, dirs, files in os.walk(pathclasses, followlinks=True):
if files != []:
for f in files:
real_filename = root
if real_filename[-1] != "/":
real_filename += "/"
real_filename += f
l = ["java", "-jar", path_fernflower + bin_fernflower]
for option in options_fernflower:
l.append("-%s:%s" % (option, options_fernflower[option]))
l.append(real_filename)
l.append(root)
compile = Popen(l, stdout=PIPE, stderr=STDOUT)
stdout, stderr = compile.communicate()
for i in vm.get_classes():
fname = pathclasses + "/" + i.get_name()[1:-1] + ".java"
if os.path.isfile(fname) == True:
self.classes[i.get_name()] = read(fname, binary=False)
else:
self.classes_failed.append(i.get_name())
rrmdir(pathclasses)
def get_source_method(self, method):
class_name = method.get_class_name()
method_name = method.get_name()
if class_name not in self.classes:
return ""
if PYGMENTS:
lexer = get_lexer_by_name("java", stripall=True)
lexer.add_filter(MethodFilter(method_name=method_name))
formatter = TerminalFormatter()
result = highlight(self.classes[class_name], lexer, formatter)
return result
return self.classes[class_name]
def display_source(self, method):
print self.get_source_method(method)
def get_source_class(self, _class):
return self.classes[_class.get_name()]
def get_all(self, class_name):
if class_name not in self.classes:
return ""
if PYGMENTS:
lexer = get_lexer_by_name("java", stripall=True)
formatter = TerminalFormatter()
result = highlight(self.classes[class_name], lexer, formatter)
return result
return self.classes[class_name]
def display_all(self, _class):
print self.get_all(_class.get_name())
class MethodFilter(Filter):
def __init__(self, **options):
Filter.__init__(self, **options)
self.method_name = options["method_name"]
#self.descriptor = options["descriptor"]
self.present = False
self.get_desc = True #False
def filter(self, lexer, stream):
a = []
l = []
rep = []
for ttype, value in stream:
if self.method_name == value and (ttype is Token.Name.Function or ttype is Token.Name):
#print ttype, value
item_decl = -1
for i in range(len(a)-1, 0, -1):
if a[i][0] is Token.Keyword.Declaration:
if a[i][1] != "class":
item_decl = i
break
if item_decl != -1:
self.present = True
l.extend( a[item_decl:] )
if self.present and ttype is Token.Keyword.Declaration:
item_end = -1
for i in range(len(l)-1, 0, -1):
if l[i][0] is Token.Operator and l[i][1] == "}":
item_end = i
break
if item_end != -1:
rep.extend( l[:item_end+1] )
l = []
self.present = False
if self.present:
l.append( (ttype, value) )
a.append( (ttype, value) )
if self.present:
nb = 0
item_end = -1
for i in range(len(l)-1, 0, -1):
if l[i][0] is Token.Operator and l[i][1] == "}":
nb += 1
if nb == 2:
item_end = i
break
rep.extend( l[:item_end+1] )
return rep
class DecompilerDAD(object):
def __init__(self, vm, vmx):
self.vm = vm
self.vmx = vmx
def get_source_method(self, m):
mx = self.vmx.get_method(m)
z = decompile.DvMethod(mx)
z.process()
return z.get_source()
def get_ast_method(self, m):
mx = self.vmx.get_method(m)
z = decompile.DvMethod(mx)
z.process(doAST=True)
return z.get_ast()
def display_source(self, m):
result = self.get_source_method(m)
if PYGMENTS:
lexer = get_lexer_by_name("java", stripall=True)
formatter = TerminalFormatter()
result = highlight(result, lexer, formatter)
print result
def get_source_class(self, _class):
c = decompile.DvClass(_class, self.vmx)
c.process()
return c.get_source()
def get_ast_class(self, _class):
c = decompile.DvClass(_class, self.vmx)
c.process(doAST=True)
return c.get_ast()
def get_source_class_ext(self, _class):
c = decompile.DvClass(_class, self.vmx)
c.process()
result = c.get_source_ext()
return result
def display_all(self, _class):
result = self.get_source_class(_class)
if PYGMENTS:
lexer = get_lexer_by_name("java", stripall=True)
formatter = TerminalFormatter()
result = highlight(result, lexer, formatter)
print result
def get_all(self, class_name):
pass
|
apache-2.0
|
[
3,
961,
570,
365,
1777,
402,
6061,
293,
15606,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
6171,
12,
1626,
898,
89,
8055,
12712,
665,
3424,
12712,
737,
307,
16,
84,
16,
14,
4391,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
13,
1311,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
3873,
492,
13995,
12,
22773,
12,
4384,
12619,
199,
199,
646,
5549,
199,
646,
747,
199,
199,
504,
436,
293,
15606,
14,
1018,
14,
460,
293,
2190,
492,
519,
19405,
199,
504,
436,
293,
15606,
14,
271,
5772,
14,
25805,
492,
477,
2014,
199,
504,
436,
293,
15606,
14,
1974,
492,
1586,
199,
199,
4521,
39,
20967,
275,
715,
199,
893,
26,
272,
687,
13277,
14,
1541,
492,
9388,
272,
687,
13277,
492,
11850,
272,
687,
13277,
14,
12245,
492,
664,
63,
11729,
63,
991,
63,
354,
272,
687,
13277,
14,
24270,
492,
20429,
279,
7772,
272,
687,
13277,
14,
1418,
492,
8767,
199,
2590,
3545,
26,
272,
7843,
39,
20967,
275,
756,
272,
1021,
9388,
8,
785,
304,
267,
986,
421,
199,
533,
577,
476,
18,
12977,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
4169,
12,
931,
63,
731,
18,
7338,
628,
13186,
271,
5772,
15,
731,
18,
7338,
10665,
2517,
63,
731,
18,
7338,
628,
731,
18,
7338,
14,
609,
401,
3529,
63,
694,
9555,
2791,
15,
2349,
267,
931,
2791,
275,
3529,
63,
694,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
2791,
304,
288,
747,
14,
8347,
8,
515,
2791,
9,
398,
6111,
12,
6111,
354,
275,
5549,
14,
17721,
8,
694,
29,
515,
2791,
9,
267,
543,
747,
14,
23140,
8,
2592,
12,
298,
87,
11,
66,
531,
465,
6111,
26,
288,
6111,
14,
952,
8,
2611,
14,
362,
63,
16830,
1012,
288,
6111,
14,
4939,
342,
398,
6555,
275,
13995,
779,
515,
63,
731,
18,
7338,
435,
2517,
63,
731,
18,
7338,
12,
6111,
354,
467,
3839,
29,
6089,
12,
4635,
29,
13850,
9,
267,
3839,
12,
4635,
275,
6555,
14,
10664,
342,
267,
747,
14,
7162,
8,
2592,
354,
9,
398,
291,
14,
7338,
493,
275,
6111,
354,
435,
2668,
731,
18,
7338,
14,
7338,
2,
339,
347,
664,
63,
7338,
8,
277,
304,
267,
372,
291,
14,
7338,
493,
421,
199,
533,
1487,
5772,
36,
476,
18,
42,
350,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
4169,
12,
931,
63,
731,
18,
7338,
628,
13186,
271,
5772,
15,
731,
18,
7338,
10665,
2517,
63,
731,
18,
7338,
628,
731,
18,
7338,
14,
609,
401,
931,
63,
74,
350,
628,
13186,
271,
5772,
15,
74,
350,
10665,
2517,
63,
74,
350,
628,
74,
350,
401,
3529,
63,
694,
9555,
2791,
15,
2349,
267,
291,
14,
2888,
275,
1052,
267,
291,
14,
2888,
63,
4892,
275,
942,
398,
931,
2791,
275,
3529,
63,
694,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
2791,
304,
288,
747,
14,
8347,
8,
515,
2791,
9,
398,
6111,
12,
6111,
354,
275,
5549,
14,
17721,
8,
694,
29,
515,
2791,
9,
267,
543,
747,
14,
23140,
8,
2592,
12,
298,
87,
11,
66,
531,
465,
6111,
26,
288,
6111,
14,
952,
8,
2611,
14,
362,
63,
16830,
1012,
288,
6111,
14,
4939,
342,
398,
6555,
275,
13995,
779,
515,
63,
731,
18,
7338,
435,
2517,
63,
731,
18,
7338,
12,
6111,
354,
467,
3839,
29,
6089,
12,
4635,
29,
13850,
9,
267,
3839,
12,
4635,
275,
6555,
14,
10664,
342,
267,
747,
14,
7162,
8,
2592,
354,
9,
398,
931,
2888,
275,
6111,
354,
435,
298,
731,
18,
7338,
6687,
267,
6555,
275,
13995,
5234,
26700,
401,
6111,
354,
435,
2668,
731,
18,
7338,
14,
7338,
401,
3905,
68,
401,
931,
2888,
467,
3839,
29,
6089,
12,
4635,
29,
13850,
9,
267,
3839,
12,
4635,
275,
6555,
14,
10664,
342,
267,
747,
14,
7162,
8,
2592,
354,
435,
2668,
731,
18,
7338,
14,
7338,
531,
398,
367,
1738,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
515,
2888,
12,
2035,
4614,
29,
549,
304,
288,
340,
1584,
1137,
18410,
355,
367,
289,
315,
1584,
26,
490,
3363,
63,
1501,
275,
1738,
490,
340,
3363,
63,
1501,
1988,
17,
61,
1137,
30681,
717,
3363,
63,
1501,
847,
10609,
490,
3363,
63,
1501,
847,
289,
4951,
6555,
275,
13995,
779,
515,
63,
74,
350,
435,
2517,
63,
74,
350,
12,
3905,
79,
401,
3905,
68,
401,
1738,
12,
3363,
63,
1501,
467,
3839,
29,
6089,
12,
4635,
29,
13850,
9,
490,
3839,
12,
4635,
275,
6555,
14,
10664,
342,
398,
367,
284,
315,
4169,
14,
362,
63,
2888,
837,
288,
6748,
275,
931,
2888,
435,
10609,
435,
284,
14,
362,
63,
354,
3430,
17,
6809,
17,
61,
435,
3680,
74,
350,
2,
288,
340,
747,
14,
515,
14,
6292,
8,
5252,
9,
508,
715,
26,
355,
291,
14,
2888,
59,
73,
14,
362,
63,
354,
5106,
275,
1586,
8,
5252,
12,
3366,
29,
797,
9,
288,
587,
26,
355,
291,
14,
2888,
63,
4892,
14,
740,
8,
73,
14,
362,
63,
354,
1012,
398,
519,
19405,
8,
515,
2888,
9,
339,
347,
664,
63,
1365,
63,
765,
8,
277,
12,
1083,
304,
267,
1021,
63,
354,
275,
1083,
14,
362,
63,
533,
63,
354,
342,
267,
1083,
63,
354,
275,
1083,
14,
362,
63,
354,
342,
398,
340,
1021,
63,
354,
440,
315,
291,
14,
2888,
26,
288,
372,
3087,
398,
340,
7843,
39,
20967,
26
] |
[
961,
570,
365,
1777,
402,
6061,
293,
15606,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
6171,
12,
1626,
898,
89,
8055,
12712,
665,
3424,
12712,
737,
307,
16,
84,
16,
14,
4391,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
13,
1311,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
3873,
492,
13995,
12,
22773,
12,
4384,
12619,
199,
199,
646,
5549,
199,
646,
747,
199,
199,
504,
436,
293,
15606,
14,
1018,
14,
460,
293,
2190,
492,
519,
19405,
199,
504,
436,
293,
15606,
14,
271,
5772,
14,
25805,
492,
477,
2014,
199,
504,
436,
293,
15606,
14,
1974,
492,
1586,
199,
199,
4521,
39,
20967,
275,
715,
199,
893,
26,
272,
687,
13277,
14,
1541,
492,
9388,
272,
687,
13277,
492,
11850,
272,
687,
13277,
14,
12245,
492,
664,
63,
11729,
63,
991,
63,
354,
272,
687,
13277,
14,
24270,
492,
20429,
279,
7772,
272,
687,
13277,
14,
1418,
492,
8767,
199,
2590,
3545,
26,
272,
7843,
39,
20967,
275,
756,
272,
1021,
9388,
8,
785,
304,
267,
986,
421,
199,
533,
577,
476,
18,
12977,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
4169,
12,
931,
63,
731,
18,
7338,
628,
13186,
271,
5772,
15,
731,
18,
7338,
10665,
2517,
63,
731,
18,
7338,
628,
731,
18,
7338,
14,
609,
401,
3529,
63,
694,
9555,
2791,
15,
2349,
267,
931,
2791,
275,
3529,
63,
694,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
2791,
304,
288,
747,
14,
8347,
8,
515,
2791,
9,
398,
6111,
12,
6111,
354,
275,
5549,
14,
17721,
8,
694,
29,
515,
2791,
9,
267,
543,
747,
14,
23140,
8,
2592,
12,
298,
87,
11,
66,
531,
465,
6111,
26,
288,
6111,
14,
952,
8,
2611,
14,
362,
63,
16830,
1012,
288,
6111,
14,
4939,
342,
398,
6555,
275,
13995,
779,
515,
63,
731,
18,
7338,
435,
2517,
63,
731,
18,
7338,
12,
6111,
354,
467,
3839,
29,
6089,
12,
4635,
29,
13850,
9,
267,
3839,
12,
4635,
275,
6555,
14,
10664,
342,
267,
747,
14,
7162,
8,
2592,
354,
9,
398,
291,
14,
7338,
493,
275,
6111,
354,
435,
2668,
731,
18,
7338,
14,
7338,
2,
339,
347,
664,
63,
7338,
8,
277,
304,
267,
372,
291,
14,
7338,
493,
421,
199,
533,
1487,
5772,
36,
476,
18,
42,
350,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
4169,
12,
931,
63,
731,
18,
7338,
628,
13186,
271,
5772,
15,
731,
18,
7338,
10665,
2517,
63,
731,
18,
7338,
628,
731,
18,
7338,
14,
609,
401,
931,
63,
74,
350,
628,
13186,
271,
5772,
15,
74,
350,
10665,
2517,
63,
74,
350,
628,
74,
350,
401,
3529,
63,
694,
9555,
2791,
15,
2349,
267,
291,
14,
2888,
275,
1052,
267,
291,
14,
2888,
63,
4892,
275,
942,
398,
931,
2791,
275,
3529,
63,
694,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
2791,
304,
288,
747,
14,
8347,
8,
515,
2791,
9,
398,
6111,
12,
6111,
354,
275,
5549,
14,
17721,
8,
694,
29,
515,
2791,
9,
267,
543,
747,
14,
23140,
8,
2592,
12,
298,
87,
11,
66,
531,
465,
6111,
26,
288,
6111,
14,
952,
8,
2611,
14,
362,
63,
16830,
1012,
288,
6111,
14,
4939,
342,
398,
6555,
275,
13995,
779,
515,
63,
731,
18,
7338,
435,
2517,
63,
731,
18,
7338,
12,
6111,
354,
467,
3839,
29,
6089,
12,
4635,
29,
13850,
9,
267,
3839,
12,
4635,
275,
6555,
14,
10664,
342,
267,
747,
14,
7162,
8,
2592,
354,
9,
398,
931,
2888,
275,
6111,
354,
435,
298,
731,
18,
7338,
6687,
267,
6555,
275,
13995,
5234,
26700,
401,
6111,
354,
435,
2668,
731,
18,
7338,
14,
7338,
401,
3905,
68,
401,
931,
2888,
467,
3839,
29,
6089,
12,
4635,
29,
13850,
9,
267,
3839,
12,
4635,
275,
6555,
14,
10664,
342,
267,
747,
14,
7162,
8,
2592,
354,
435,
2668,
731,
18,
7338,
14,
7338,
531,
398,
367,
1738,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
515,
2888,
12,
2035,
4614,
29,
549,
304,
288,
340,
1584,
1137,
18410,
355,
367,
289,
315,
1584,
26,
490,
3363,
63,
1501,
275,
1738,
490,
340,
3363,
63,
1501,
1988,
17,
61,
1137,
30681,
717,
3363,
63,
1501,
847,
10609,
490,
3363,
63,
1501,
847,
289,
4951,
6555,
275,
13995,
779,
515,
63,
74,
350,
435,
2517,
63,
74,
350,
12,
3905,
79,
401,
3905,
68,
401,
1738,
12,
3363,
63,
1501,
467,
3839,
29,
6089,
12,
4635,
29,
13850,
9,
490,
3839,
12,
4635,
275,
6555,
14,
10664,
342,
398,
367,
284,
315,
4169,
14,
362,
63,
2888,
837,
288,
6748,
275,
931,
2888,
435,
10609,
435,
284,
14,
362,
63,
354,
3430,
17,
6809,
17,
61,
435,
3680,
74,
350,
2,
288,
340,
747,
14,
515,
14,
6292,
8,
5252,
9,
508,
715,
26,
355,
291,
14,
2888,
59,
73,
14,
362,
63,
354,
5106,
275,
1586,
8,
5252,
12,
3366,
29,
797,
9,
288,
587,
26,
355,
291,
14,
2888,
63,
4892,
14,
740,
8,
73,
14,
362,
63,
354,
1012,
398,
519,
19405,
8,
515,
2888,
9,
339,
347,
664,
63,
1365,
63,
765,
8,
277,
12,
1083,
304,
267,
1021,
63,
354,
275,
1083,
14,
362,
63,
533,
63,
354,
342,
267,
1083,
63,
354,
275,
1083,
14,
362,
63,
354,
342,
398,
340,
1021,
63,
354,
440,
315,
291,
14,
2888,
26,
288,
372,
3087,
398,
340,
7843,
39,
20967,
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,
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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
] |
benrudolph/commcare-hq
|
corehq/apps/reports/forms.py
|
1
|
5262
|
from django import forms
from django.core.validators import MinLengthValidator
from django.template.loader import render_to_string
from corehq.apps.style.forms.fields import MultiEmailField
from corehq.apps.userreports.reports.view import ConfigurableReport
from crispy_forms import layout as crispy
from crispy_forms.helper import FormHelper
from .models import (
ReportConfig,
ReportNotification,
)
class SavedReportConfigForm(forms.Form):
name = forms.CharField()
description = forms.CharField(
required=False,
widget=forms.Textarea(),
)
start_date = forms.DateField(
required=False,
)
end_date = forms.DateField(
required=False,
)
date_range = forms.CharField(
required=False,
widget=forms.HiddenInput(),
)
days = forms.IntegerField(
required=False,
widget=forms.HiddenInput(),
)
_id = forms.CharField(
required=False,
widget=forms.HiddenInput(),
)
report_slug = forms.CharField(
required=False,
widget=forms.HiddenInput(),
)
report_type = forms.CharField(
required=False,
widget=forms.HiddenInput(),
)
subreport_slug = forms.CharField(
required=False,
widget=forms.HiddenInput(),
)
def __init__(self, domain, user_id, *args, **kwargs):
self.domain = domain
self.user_id = user_id
super(SavedReportConfigForm, self).__init__(*args, **kwargs)
def clean(self):
name = self.cleaned_data['name']
_id = self.cleaned_data['_id']
user_configs = ReportConfig.by_domain_and_owner(self.domain, self.user_id)
if not _id and name in [c.name for c in user_configs]:
raise forms.ValidationError(
"A saved report with the name '%(name)s' already exists." % {
'name': name,
}
)
date_range = self.cleaned_data['date_range']
if date_range == 'last7':
self.cleaned_data['days'] = 7
elif date_range == 'last30':
self.cleaned_data['days'] = 30
elif (date_range == 'lastn' and self.cleaned_data['days'] is None
and self.cleaned_data['report_type'] != ConfigurableReport.prefix):
raise forms.ValidationError(
"Field 'days' was expected but not provided."
)
return self.cleaned_data
class ScheduledReportForm(forms.Form):
config_ids = forms.MultipleChoiceField(
label="Saved report(s)",
validators=[MinLengthValidator(1)],
help_text='Note: not all built-in reports support email delivery, so'
' some of your saved reports may not appear in this list')
interval = forms.TypedChoiceField(
label='Interval',
choices=[("daily", "Daily"), ("weekly", "Weekly"), ("monthly", "Monthly")])
day = forms.TypedChoiceField(
label="Day",
coerce=int,
required=False,
choices=[(i, i) for i in range(0, 32)])
hour = forms.TypedChoiceField(
label='Time',
coerce=int,
choices=ReportNotification.hour_choices())
send_to_owner = forms.BooleanField(
label='Send to me',
required=False)
attach_excel = forms.BooleanField(
label='Attach Excel Report',
required=False)
recipient_emails = MultiEmailField(
label='Other recipients',
required=False)
def __init__(self, display_privacy_disclaimer, *args, **kwargs):
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.form_id = 'id-scheduledReportForm'
self.helper.add_layout(
crispy.Layout(
'config_ids',
'interval',
'day',
'hour',
'send_to_owner',
'attach_excel',
'recipient_emails',
crispy.HTML(
render_to_string('reports/partials/privacy_disclaimer.html')
) if display_privacy_disclaimer else None
)
)
self.helper.add_input(crispy.Submit('submit_btn', 'Submit'))
super(ScheduledReportForm, self).__init__(*args, **kwargs)
def clean(self):
cleaned_data = super(ScheduledReportForm, self).clean()
if cleaned_data["interval"] == "daily":
del cleaned_data["day"]
_verify_email(cleaned_data)
return cleaned_data
class EmailReportForm(forms.Form):
subject = forms.CharField(required=False)
send_to_owner = forms.BooleanField(required=False)
attach_excel = forms.BooleanField(required=False)
recipient_emails = MultiEmailField(required=False)
notes = forms.CharField(required=False)
def clean(self):
cleaned_data = super(EmailReportForm, self).clean()
_verify_email(cleaned_data)
return cleaned_data
def _verify_email(cleaned_data):
if ('recipient_emails' in cleaned_data
and not (cleaned_data['recipient_emails'] or
cleaned_data['send_to_owner'])):
raise forms.ValidationError("You must specify at least one "
"valid recipient")
|
bsd-3-clause
|
[
504,
1639,
492,
4513,
199,
504,
1639,
14,
1018,
14,
11346,
492,
10195,
4625,
8640,
199,
504,
1639,
14,
1160,
14,
3422,
492,
3795,
63,
475,
63,
875,
199,
504,
6170,
21550,
14,
5181,
14,
2487,
14,
3351,
14,
955,
492,
6879,
16577,
199,
504,
6170,
21550,
14,
5181,
14,
751,
15629,
14,
15629,
14,
1345,
492,
4094,
15684,
7457,
199,
504,
286,
5719,
647,
63,
3351,
492,
7054,
465,
286,
5719,
647,
199,
504,
286,
5719,
647,
63,
3351,
14,
3676,
492,
8204,
4433,
199,
504,
1275,
992,
492,
334,
272,
11774,
2028,
12,
272,
11774,
11598,
12,
199,
9,
421,
199,
533,
29026,
7457,
2028,
2821,
8,
3351,
14,
2821,
304,
272,
536,
275,
4513,
14,
2183,
342,
272,
1369,
275,
4513,
14,
2183,
8,
267,
1415,
29,
797,
12,
267,
3938,
29,
3351,
14,
1872,
6789,
1062,
272,
776,
272,
1343,
63,
602,
275,
4513,
14,
14071,
8,
267,
1415,
29,
797,
12,
272,
776,
272,
1284,
63,
602,
275,
4513,
14,
14071,
8,
267,
1415,
29,
797,
12,
272,
776,
272,
1434,
63,
1842,
275,
4513,
14,
2183,
8,
267,
1415,
29,
797,
12,
267,
3938,
29,
3351,
14,
25419,
1062,
272,
776,
272,
7609,
275,
4513,
14,
3901,
8,
267,
1415,
29,
797,
12,
267,
3938,
29,
3351,
14,
25419,
1062,
272,
776,
272,
485,
344,
275,
4513,
14,
2183,
8,
267,
1415,
29,
797,
12,
267,
3938,
29,
3351,
14,
25419,
1062,
272,
776,
272,
3622,
63,
5464,
275,
4513,
14,
2183,
8,
267,
1415,
29,
797,
12,
267,
3938,
29,
3351,
14,
25419,
1062,
272,
776,
272,
3622,
63,
466,
275,
4513,
14,
2183,
8,
267,
1415,
29,
797,
12,
267,
3938,
29,
3351,
14,
25419,
1062,
272,
776,
272,
1007,
3070,
63,
5464,
275,
4513,
14,
2183,
8,
267,
1415,
29,
797,
12,
267,
3938,
29,
3351,
14,
25419,
1062,
272,
776,
339,
347,
636,
826,
721,
277,
12,
2881,
12,
922,
63,
344,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
2261,
275,
2881,
267,
291,
14,
751,
63,
344,
275,
922,
63,
344,
267,
1613,
8,
21969,
7457,
2028,
2821,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
3633,
8,
277,
304,
267,
536,
275,
291,
14,
8275,
63,
576,
459,
354,
418,
267,
485,
344,
275,
291,
14,
8275,
63,
576,
8680,
344,
418,
398,
922,
63,
7532,
275,
11774,
2028,
14,
991,
63,
2261,
63,
460,
63,
4597,
8,
277,
14,
2261,
12,
291,
14,
751,
63,
344,
9,
267,
340,
440,
485,
344,
436,
536,
315,
359,
67,
14,
354,
367,
286,
315,
922,
63,
7532,
2189,
288,
746,
4513,
14,
8172,
8,
355,
298,
33,
6290,
3622,
543,
314,
536,
9487,
354,
9,
83,
7,
2575,
3495,
2122,
450,
469,
490,
283,
354,
356,
536,
12,
355,
789,
288,
776,
398,
1434,
63,
1842,
275,
291,
14,
8275,
63,
576,
459,
602,
63,
1842,
418,
267,
340,
1434,
63,
1842,
508,
283,
2019,
23,
356,
288,
291,
14,
8275,
63,
576,
459,
4899,
418,
275,
1520,
267,
916,
1434,
63,
1842,
508,
283,
2019,
1216,
356,
288,
291,
14,
8275,
63,
576,
459,
4899,
418,
275,
4233,
267,
916,
334,
602,
63,
1842,
508,
283,
2019,
78,
7,
436,
291,
14,
8275,
63,
576,
459,
4899,
418,
365,
488,
1598,
436,
291,
14,
8275,
63,
576,
459,
3070,
63,
466,
418,
1137,
4094,
15684,
7457,
14,
1861,
304,
288,
746,
4513,
14,
8172,
8,
355,
298,
792,
283,
4899,
7,
1990,
1420,
1325,
440,
2741,
2122,
288,
776,
398,
372,
291,
14,
8275,
63,
576,
421,
199,
533,
24317,
68,
7457,
2821,
8,
3351,
14,
2821,
304,
272,
1101,
63,
1580,
275,
4513,
14,
8433,
15792,
8,
267,
1768,
628,
21969,
3622,
8,
83,
4186,
267,
14370,
1524,
4649,
4625,
8640,
8,
17,
4360,
267,
1720,
63,
505,
534,
7443,
26,
440,
1006,
6137,
13,
262,
13924,
2291,
3031,
18719,
12,
880,
7,
2116,
283,
2005,
402,
2195,
6290,
13924,
1443,
440,
7468,
315,
642,
769,
358,
339,
6252,
275,
4513,
14,
22193,
15792,
8,
267,
1768,
534,
8227,
297,
267,
3415,
1524,
480,
18621,
401,
298,
36,
17550,
1288,
1689,
6419,
590,
401,
298,
20995,
590,
1288,
1689,
30517,
401,
298,
14306,
590,
13403,
339,
5382,
275,
4513,
14,
22193,
15792,
8,
267,
1768,
628,
12631,
401,
267,
19874,
29,
442,
12,
267,
1415,
29,
797,
12,
267,
3415,
17497,
73,
12,
284,
9,
367,
284,
315,
1425,
8,
16,
12,
4337,
3948,
339,
6925,
275,
4513,
14,
22193,
15792,
8,
267,
1768,
534,
1366,
297,
267,
19874,
29,
442,
12,
267,
3415,
29,
7457,
11598,
14,
5180,
63,
4577,
1012,
339,
3222,
63,
475,
63,
4597,
275,
4513,
14,
5036,
8,
267,
1768,
534,
6795,
370,
562,
297,
267,
1415,
29,
797,
9,
339,
6554,
63,
28330,
275,
4513,
14,
5036,
8,
267,
1768,
534,
13240,
27832,
11774,
297,
267,
1415,
29,
797,
9,
339,
10318,
63,
14170,
275,
6879,
16577,
8,
267,
1768,
534,
8632,
19255,
297,
267,
1415,
29,
797,
9,
339,
347,
636,
826,
721,
277,
12,
2929,
63,
17258,
63,
6409,
6400,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
3676,
275,
8204,
4433,
342,
267,
291,
14,
3676,
14,
964,
63,
533,
275,
283,
964,
13,
11392,
7,
267,
291,
14,
3676,
14,
964,
63,
344,
275,
283,
344,
13,
19274,
7457,
2821,
7,
267,
291,
14,
3676,
14,
525,
63,
4209,
8,
288,
286,
5719,
647,
14,
4798,
8,
355,
283,
888,
63,
1580,
297,
355,
283,
4284,
297,
355,
283,
2977,
297,
355,
283,
5180,
297,
355,
283,
2254,
63,
475,
63,
4597,
297,
355,
283,
5040,
63,
28330,
297,
355,
283,
10043,
63,
14170,
297,
355,
286,
5719,
647,
14,
4943,
8,
490,
3795,
63,
475,
63,
875,
360,
15629,
15,
6672,
83,
15,
17258,
63,
6409,
6400,
14,
1360,
358,
355,
776,
340,
2929,
63,
17258,
63,
6409,
6400,
587,
488,
288,
776,
267,
776,
267,
291,
14,
3676,
14,
525,
63,
1210,
8,
1408,
15252,
14,
17187,
360,
7275,
63,
9633,
297,
283,
17187,
1333,
398,
1613,
8,
15535,
68,
7457,
2821,
12,
291,
2843,
826,
9308,
589,
12,
1011
] |
[
1639,
492,
4513,
199,
504,
1639,
14,
1018,
14,
11346,
492,
10195,
4625,
8640,
199,
504,
1639,
14,
1160,
14,
3422,
492,
3795,
63,
475,
63,
875,
199,
504,
6170,
21550,
14,
5181,
14,
2487,
14,
3351,
14,
955,
492,
6879,
16577,
199,
504,
6170,
21550,
14,
5181,
14,
751,
15629,
14,
15629,
14,
1345,
492,
4094,
15684,
7457,
199,
504,
286,
5719,
647,
63,
3351,
492,
7054,
465,
286,
5719,
647,
199,
504,
286,
5719,
647,
63,
3351,
14,
3676,
492,
8204,
4433,
199,
504,
1275,
992,
492,
334,
272,
11774,
2028,
12,
272,
11774,
11598,
12,
199,
9,
421,
199,
533,
29026,
7457,
2028,
2821,
8,
3351,
14,
2821,
304,
272,
536,
275,
4513,
14,
2183,
342,
272,
1369,
275,
4513,
14,
2183,
8,
267,
1415,
29,
797,
12,
267,
3938,
29,
3351,
14,
1872,
6789,
1062,
272,
776,
272,
1343,
63,
602,
275,
4513,
14,
14071,
8,
267,
1415,
29,
797,
12,
272,
776,
272,
1284,
63,
602,
275,
4513,
14,
14071,
8,
267,
1415,
29,
797,
12,
272,
776,
272,
1434,
63,
1842,
275,
4513,
14,
2183,
8,
267,
1415,
29,
797,
12,
267,
3938,
29,
3351,
14,
25419,
1062,
272,
776,
272,
7609,
275,
4513,
14,
3901,
8,
267,
1415,
29,
797,
12,
267,
3938,
29,
3351,
14,
25419,
1062,
272,
776,
272,
485,
344,
275,
4513,
14,
2183,
8,
267,
1415,
29,
797,
12,
267,
3938,
29,
3351,
14,
25419,
1062,
272,
776,
272,
3622,
63,
5464,
275,
4513,
14,
2183,
8,
267,
1415,
29,
797,
12,
267,
3938,
29,
3351,
14,
25419,
1062,
272,
776,
272,
3622,
63,
466,
275,
4513,
14,
2183,
8,
267,
1415,
29,
797,
12,
267,
3938,
29,
3351,
14,
25419,
1062,
272,
776,
272,
1007,
3070,
63,
5464,
275,
4513,
14,
2183,
8,
267,
1415,
29,
797,
12,
267,
3938,
29,
3351,
14,
25419,
1062,
272,
776,
339,
347,
636,
826,
721,
277,
12,
2881,
12,
922,
63,
344,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
2261,
275,
2881,
267,
291,
14,
751,
63,
344,
275,
922,
63,
344,
267,
1613,
8,
21969,
7457,
2028,
2821,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
3633,
8,
277,
304,
267,
536,
275,
291,
14,
8275,
63,
576,
459,
354,
418,
267,
485,
344,
275,
291,
14,
8275,
63,
576,
8680,
344,
418,
398,
922,
63,
7532,
275,
11774,
2028,
14,
991,
63,
2261,
63,
460,
63,
4597,
8,
277,
14,
2261,
12,
291,
14,
751,
63,
344,
9,
267,
340,
440,
485,
344,
436,
536,
315,
359,
67,
14,
354,
367,
286,
315,
922,
63,
7532,
2189,
288,
746,
4513,
14,
8172,
8,
355,
298,
33,
6290,
3622,
543,
314,
536,
9487,
354,
9,
83,
7,
2575,
3495,
2122,
450,
469,
490,
283,
354,
356,
536,
12,
355,
789,
288,
776,
398,
1434,
63,
1842,
275,
291,
14,
8275,
63,
576,
459,
602,
63,
1842,
418,
267,
340,
1434,
63,
1842,
508,
283,
2019,
23,
356,
288,
291,
14,
8275,
63,
576,
459,
4899,
418,
275,
1520,
267,
916,
1434,
63,
1842,
508,
283,
2019,
1216,
356,
288,
291,
14,
8275,
63,
576,
459,
4899,
418,
275,
4233,
267,
916,
334,
602,
63,
1842,
508,
283,
2019,
78,
7,
436,
291,
14,
8275,
63,
576,
459,
4899,
418,
365,
488,
1598,
436,
291,
14,
8275,
63,
576,
459,
3070,
63,
466,
418,
1137,
4094,
15684,
7457,
14,
1861,
304,
288,
746,
4513,
14,
8172,
8,
355,
298,
792,
283,
4899,
7,
1990,
1420,
1325,
440,
2741,
2122,
288,
776,
398,
372,
291,
14,
8275,
63,
576,
421,
199,
533,
24317,
68,
7457,
2821,
8,
3351,
14,
2821,
304,
272,
1101,
63,
1580,
275,
4513,
14,
8433,
15792,
8,
267,
1768,
628,
21969,
3622,
8,
83,
4186,
267,
14370,
1524,
4649,
4625,
8640,
8,
17,
4360,
267,
1720,
63,
505,
534,
7443,
26,
440,
1006,
6137,
13,
262,
13924,
2291,
3031,
18719,
12,
880,
7,
2116,
283,
2005,
402,
2195,
6290,
13924,
1443,
440,
7468,
315,
642,
769,
358,
339,
6252,
275,
4513,
14,
22193,
15792,
8,
267,
1768,
534,
8227,
297,
267,
3415,
1524,
480,
18621,
401,
298,
36,
17550,
1288,
1689,
6419,
590,
401,
298,
20995,
590,
1288,
1689,
30517,
401,
298,
14306,
590,
13403,
339,
5382,
275,
4513,
14,
22193,
15792,
8,
267,
1768,
628,
12631,
401,
267,
19874,
29,
442,
12,
267,
1415,
29,
797,
12,
267,
3415,
17497,
73,
12,
284,
9,
367,
284,
315,
1425,
8,
16,
12,
4337,
3948,
339,
6925,
275,
4513,
14,
22193,
15792,
8,
267,
1768,
534,
1366,
297,
267,
19874,
29,
442,
12,
267,
3415,
29,
7457,
11598,
14,
5180,
63,
4577,
1012,
339,
3222,
63,
475,
63,
4597,
275,
4513,
14,
5036,
8,
267,
1768,
534,
6795,
370,
562,
297,
267,
1415,
29,
797,
9,
339,
6554,
63,
28330,
275,
4513,
14,
5036,
8,
267,
1768,
534,
13240,
27832,
11774,
297,
267,
1415,
29,
797,
9,
339,
10318,
63,
14170,
275,
6879,
16577,
8,
267,
1768,
534,
8632,
19255,
297,
267,
1415,
29,
797,
9,
339,
347,
636,
826,
721,
277,
12,
2929,
63,
17258,
63,
6409,
6400,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
3676,
275,
8204,
4433,
342,
267,
291,
14,
3676,
14,
964,
63,
533,
275,
283,
964,
13,
11392,
7,
267,
291,
14,
3676,
14,
964,
63,
344,
275,
283,
344,
13,
19274,
7457,
2821,
7,
267,
291,
14,
3676,
14,
525,
63,
4209,
8,
288,
286,
5719,
647,
14,
4798,
8,
355,
283,
888,
63,
1580,
297,
355,
283,
4284,
297,
355,
283,
2977,
297,
355,
283,
5180,
297,
355,
283,
2254,
63,
475,
63,
4597,
297,
355,
283,
5040,
63,
28330,
297,
355,
283,
10043,
63,
14170,
297,
355,
286,
5719,
647,
14,
4943,
8,
490,
3795,
63,
475,
63,
875,
360,
15629,
15,
6672,
83,
15,
17258,
63,
6409,
6400,
14,
1360,
358,
355,
776,
340,
2929,
63,
17258,
63,
6409,
6400,
587,
488,
288,
776,
267,
776,
267,
291,
14,
3676,
14,
525,
63,
1210,
8,
1408,
15252,
14,
17187,
360,
7275,
63,
9633,
297,
283,
17187,
1333,
398,
1613,
8,
15535,
68,
7457,
2821,
12,
291,
2843,
826,
9308,
589,
12,
1011,
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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queue
import unittest
import logging
from bears.general.KeywordBear import KeywordBear
from coalib.results.HiddenResult import HiddenResult
from coalib.results.SourceRange import SourceRange
from coalib.settings.Section import Section
from coalib.settings.Setting import Setting
from coalib.testing.LocalBearTestHelper import verify_local_bear, execute_bear
test_file = """
test line fix me
to do
error fixme
"""
KeywordBearTest = verify_local_bear(
KeywordBear,
valid_files=(test_file,),
invalid_files=('test line todo',
'test line warNING'),
settings={'keywords': 'todo, warning',
'language': 'c'})
class KeywordBearDiffTest(unittest.TestCase):
def setUp(self):
self.section = Section('')
self.section.append(Setting('language', 'python3'))
self.section.append(Setting('keywords', 'TODO'))
self.uut = KeywordBear(self.section, Queue())
self.annotation_bear_result_type = namedtuple('result', ['contents'])
self.dep_results = {'AnnotationBear': HiddenResult(
'AnnotationBear', {'comments': ()})}
def test_empty_keyword(self):
text = ['a == b']
with execute_bear(self.uut, filename='F', file=text,
dependency_results=self.dep_results) as result:
self.assertEqual(result, [])
def test_keyword_in_comment(self):
dep_results = {
'AnnotationBear': {}
}
text = ['# todo 123']
with execute_bear(self.uut, filename='F', file=text,
dependency_results=dep_results) as result:
self.assertEqual(result[0].diffs, {})
self.assertEqual(result[0].affected_code[0].start.line, 1)
self.assertEqual(len(result), 1)
dep_results = {'AnnotationBear': HiddenResult(
'AnnotationBear', {'comments': 123})}
with execute_bear(self.uut, filename='F', file=text,
dependency_results=dep_results) as result:
self.assertEqual(result[0].diffs, {})
self.assertEqual(result[0].affected_code[0].start.line, 1)
self.assertEqual(len(result), 1)
dep_results = {'AnnotationBear': HiddenResult(
'AnnotationBear', 123)}
with execute_bear(self.uut, filename='F', file=text,
dependency_results=dep_results) as result:
self.assertEqual(result[0].diffs, {})
self.assertEqual(result[0].affected_code[0].start.line, 1)
self.assertEqual(len(result), 1)
def test_keyword_not_in_comment(self):
text = ['# comment 123\n', 'a = "TODO"\n']
comments = [SourceRange.from_values('F', 1, 1, 1, 40)]
dep_results = {
'AnnotationBear': [
self.annotation_bear_result_type({'comments': comments})
]
}
with execute_bear(self.uut, filename='F', file=text,
dependency_results=dep_results) as result:
self.assertEqual(len(result[0].diffs), 0)
def test_keyword_diff(self):
text = ['# todo 123\n']
comments = [SourceRange.from_values('F', 1, 1, 1, 10)]
dep_results = {
'AnnotationBear': [
self.annotation_bear_result_type({'comments': comments})
]
}
with execute_bear(self.uut, filename='F', file=text,
dependency_results=dep_results) as result:
self.assertEqual(result[0].diffs['F'].unified_diff,
'--- \n'
'+++ \n'
'@@ -1 +0,0 @@\n'
'-# todo 123\n')
text = ['test = 55 # todo 123\n']
comments = [SourceRange.from_values('F', 1, 11, 1, 23)]
dep_results = {
'AnnotationBear': [
self.annotation_bear_result_type({'comments': comments})
]
}
with execute_bear(self.uut, filename='F', file=text,
dependency_results=dep_results) as result:
self.assertEqual(result[0].diffs['F'].unified_diff,
'--- \n'
'+++ \n'
'@@ -1 +1 @@\n'
'-test = 55 # todo 123\n'
'+test = 55\n')
def test_keyword_outside_of_comment(self):
text = ['todo = 123\n']
with execute_bear(self.uut, filename='F', file=text,
dependency_results=self.dep_results) as result:
self.assertEquals(result[0].diffs, {})
def test_keyword_between_code(self):
self.section.append(Setting('language', 'c'))
self.section.append(Setting('keywords', 'todo'))
text = ['int a=0; /* TODO: Test */ int b=1;\n']
comments = [SourceRange.from_values('F', 1, 10, 1, 25)]
dep_results = {
'AnnotationBear': [
self.annotation_bear_result_type({'comments': comments})
]
}
with execute_bear(self.uut, filename='F', file=text,
dependency_results=dep_results) as result:
self.assertEqual(result[0].diffs['F'].unified_diff,
'--- \n'
'+++ \n'
'@@ -1 +1 @@\n'
'-int a=0; /* TODO: Test */ int b=1;\n'
'+int a=0; int b=1;\n')
text = ['int a = 0; /* TODO test\n',
'another test\n',
'*/\n']
comments = [SourceRange.from_values('F', 1, 12, 3, 2)]
dep_results = {
'AnnotationBear': [
self.annotation_bear_result_type({'comments': comments})
]
}
with execute_bear(self.uut, filename='F', file=text,
dependency_results=dep_results) as result:
self.assertEqual(result[0].diffs['F'].unified_diff,
'--- \n'
'+++ \n'
'@@ -1,3 +1,3 @@\n'
'-int a = 0; /* TODO test\n'
'+int a = 0; /*\n'
' another test\n'
' */\n')
text = ['/* TODO\n',
'test\n',
'*/\n']
comments = [SourceRange.from_values('F', 1, 1, 3, 2)]
dep_results = {
'AnnotationBear': [
self.annotation_bear_result_type({'comments': comments})
]
}
with execute_bear(self.uut, filename='F', file=text,
dependency_results=dep_results) as result:
self.assertEqual(result[0].diffs['F'].unified_diff,
'--- \n'
'+++ \n'
'@@ -1,3 +1,3 @@\n'
'-/* TODO\n'
'+/*\n'
' test\n'
' */\n')
def test_keyword_regex(self):
text = ['# add two given values and result the result\n',
'def add(a, b):',
' return a+b\n',
' \n',
'print(add(2, 3))\n']
regex_keyword = 'r.s.l.'
with execute_bear(self.uut, filename='F', file=text,
regex_keyword=regex_keyword,
dependency_results=self.dep_results) as result:
self.assertEqual(result[0].message, 'The line contains the keyword'
" 'result' which resulted in a"
' match with given regex.')
text = ['# bla bla bla',
'Issue #123',
'bla bla bla']
regex_keyword = '[iI]ssue #[1-9][0-9]*'
with execute_bear(self.uut, filename='F', file=text,
regex_keyword=regex_keyword,
dependency_results=self.dep_results) as result:
self.assertEqual(result[0].message, 'The line contains the keyword'
" 'Issue #123' which resulted "
'in a match with given regex.')
def test_wrong_language(self):
self.section.append(Setting('language', 'anything'))
logger = logging.getLogger()
annotation_bear_result_type = namedtuple('result', 'contents')
dep_results = {
'AnnotationBear': [
annotation_bear_result_type(
'coalang specification for anything not found.')
]
}
text = ['# todo 123']
with self.assertLogs(logger, 'ERROR') as log:
with execute_bear(self.uut, filename='F', file=text,
dependency_results=dep_results) as result:
self.assertEqual(len(result), 1)
self.assertEqual(result[0].diffs, {})
self.assertEqual(result[0].affected_code[0].start.line, 1)
self.assertEqual(len(log.output), 1)
self.assertIn(log.output[0],
'ERROR:root:coalang specification'
' for anything not found.')
def test_empty_keywords_list(self):
self.section.append(Setting('keywords', ''))
text = ['bears = KeywordBear\n']
with execute_bear(self.uut, filename='F', file=text,
dependency_results=self.dep_results) as result:
self.assertEqual(len(result), 0)
|
agpl-3.0
|
[
504,
5055,
492,
12863,
199,
504,
4126,
492,
10703,
199,
646,
2882,
199,
646,
2050,
199,
199,
504,
506,
4291,
14,
10706,
14,
10650,
30860,
492,
6431,
30860,
199,
504,
512,
25530,
14,
2604,
14,
14983,
2889,
492,
26401,
2889,
199,
504,
512,
25530,
14,
2604,
14,
2980,
4709,
492,
5800,
4709,
199,
504,
512,
25530,
14,
1751,
14,
8660,
492,
15247,
199,
504,
512,
25530,
14,
1751,
14,
7776,
492,
13510,
199,
504,
512,
25530,
14,
4776,
14,
5339,
30860,
774,
4433,
492,
4911,
63,
1832,
63,
31796,
12,
5341,
63,
31796,
199,
199,
396,
63,
493,
275,
408,
199,
396,
1004,
5325,
562,
199,
475,
886,
199,
705,
5325,
278,
199,
624,
421,
199,
10650,
30860,
774,
275,
4911,
63,
1832,
63,
31796,
8,
272,
6431,
30860,
12,
272,
1686,
63,
1725,
2687,
396,
63,
493,
4706,
272,
3866,
63,
1725,
7782,
396,
1004,
11386,
297,
673,
283,
396,
1004,
3429,
6024,
659,
272,
2202,
3713,
7511,
356,
283,
11396,
12,
5721,
297,
1598,
283,
3671,
356,
283,
67,
3071,
421,
199,
533,
6431,
30860,
10746,
774,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
2792,
275,
15247,
8355,
267,
291,
14,
2792,
14,
740,
8,
7776,
360,
3671,
297,
283,
1548,
19,
1333,
267,
291,
14,
2792,
14,
740,
8,
7776,
360,
7511,
297,
283,
11768,
1333,
267,
291,
14,
85,
337,
275,
6431,
30860,
8,
277,
14,
2792,
12,
10703,
1012,
398,
291,
14,
9340,
63,
31796,
63,
1099,
63,
466,
275,
12863,
360,
1099,
297,
788,
4407,
1105,
267,
291,
14,
2601,
63,
2604,
275,
791,
16768,
30860,
356,
26401,
2889,
8,
288,
283,
16768,
30860,
297,
791,
6223,
356,
6248,
1552,
93,
339,
347,
511,
63,
1667,
63,
6691,
8,
277,
304,
267,
1318,
275,
788,
65,
508,
330,
418,
398,
543,
5341,
63,
31796,
8,
277,
14,
85,
337,
12,
1788,
534,
38,
297,
570,
29,
505,
12,
2079,
5936,
63,
2604,
29,
277,
14,
2601,
63,
2604,
9,
465,
754,
26,
288,
291,
14,
629,
8,
1099,
12,
3073,
339,
347,
511,
63,
6691,
63,
262,
63,
3349,
8,
277,
304,
267,
2657,
63,
2604,
275,
469,
288,
283,
16768,
30860,
356,
1052,
267,
789,
267,
1318,
275,
788,
3,
11386,
11869,
418,
267,
543,
5341,
63,
31796,
8,
277,
14,
85,
337,
12,
1788,
534,
38,
297,
570,
29,
505,
12,
2079,
5936,
63,
2604,
29,
2601,
63,
2604,
9,
465,
754,
26,
288,
291,
14,
629,
8,
1099,
59,
16,
1055,
17418,
12,
5009,
288,
291,
14,
629,
8,
1099,
59,
16,
1055,
26653,
63,
600,
59,
16,
1055,
928,
14,
604,
12,
413,
9,
288,
291,
14,
629,
8,
552,
8,
1099,
395,
413,
9,
398,
2657,
63,
2604,
275,
791,
16768,
30860,
356,
26401,
2889,
8,
288,
283,
16768,
30860,
297,
791,
6223,
356,
11869,
1552,
93,
267,
543,
5341,
63,
31796,
8,
277,
14,
85,
337,
12,
1788,
534,
38,
297,
570,
29,
505,
12,
2079,
5936,
63,
2604,
29,
2601,
63,
2604,
9,
465,
754,
26,
288,
291,
14,
629,
8,
1099,
59,
16,
1055,
17418,
12,
5009,
288,
291,
14,
629,
8,
1099,
59,
16,
1055,
26653,
63,
600,
59,
16,
1055,
928,
14,
604,
12,
413,
9,
288,
291,
14,
629,
8,
552,
8,
1099,
395,
413,
9,
398,
2657,
63,
2604,
275,
791,
16768,
30860,
356,
26401,
2889,
8,
288,
283,
16768,
30860,
297,
11869,
6769,
267,
543,
5341,
63,
31796,
8,
277,
14,
85,
337,
12,
1788,
534,
38,
297,
570,
29,
505,
12,
2079,
5936,
63,
2604,
29,
2601,
63,
2604,
9,
465,
754,
26,
288,
291,
14,
629,
8,
1099,
59,
16,
1055,
17418,
12,
5009,
288,
291,
14,
629,
8,
1099,
59,
16,
1055,
26653,
63,
600,
59,
16,
1055,
928,
14,
604,
12,
413,
9,
288,
291,
14,
629,
8,
552,
8,
1099,
395,
413,
9,
339,
347,
511,
63,
6691,
63,
1397,
63,
262,
63,
3349,
8,
277,
304,
267,
1318,
275,
788,
3,
3721,
11869,
60,
78,
297,
283,
65,
275,
298,
11768,
3212,
78,
418,
267,
6786,
275,
359,
2980,
4709,
14,
504,
63,
1459,
360,
38,
297,
413,
12,
413,
12,
413,
12,
6335,
1874,
267,
2657,
63,
2604,
275,
469,
288,
283,
16768,
30860,
356,
359,
355,
291,
14,
9340,
63,
31796,
63,
1099,
63,
466,
3252,
6223,
356,
6786,
1552,
288,
1622,
267,
789,
398,
543,
5341,
63,
31796,
8,
277,
14,
85,
337,
12,
1788,
534,
38,
297,
570,
29,
505,
12,
2079,
5936,
63,
2604,
29,
2601,
63,
2604,
9,
465,
754,
26,
288,
291,
14,
629,
8,
552,
8,
1099,
59,
16,
1055,
17418,
395,
378,
9,
339,
347,
511,
63,
6691,
63,
3028,
8,
277,
304,
267,
1318,
275,
788,
3,
11386,
11869,
60,
78,
418,
267,
6786,
275,
359,
2980,
4709,
14,
504,
63,
1459,
360,
38,
297,
413,
12,
413,
12,
413,
12,
1616,
1874,
267,
2657,
63,
2604,
275,
469,
288,
283,
16768,
30860,
356,
359,
355,
291,
14,
9340,
63,
31796,
63,
1099,
63,
466,
3252,
6223,
356,
6786,
1552,
288,
1622,
267,
789,
398,
543,
5341,
63,
31796,
8,
277,
14,
85,
337,
12,
1788,
534,
38,
297,
570,
29,
505,
12,
2079,
5936,
63,
2604,
29,
2601,
63,
2604,
9,
465,
754,
26,
288,
291,
14,
629,
8,
1099,
59,
16,
1055,
17418,
459,
38,
2278,
32180,
63,
3028,
12,
2490,
283,
2595,
971,
78,
7,
2490,
283,
4176,
11,
971,
78,
7,
2490,
283,
7492,
446,
17,
435,
16,
12,
16,
13365,
60,
78,
7,
2490,
2475,
3,
11386,
11869,
60,
78,
358,
398,
1318,
275,
788,
396,
275,
12766,
327,
11386,
11869,
60,
78,
418,
267,
6786,
275,
359,
2980,
4709,
14,
504,
63,
1459,
360,
38,
297,
413,
12,
4119,
12,
413,
12,
6546,
1874,
267,
2657,
63,
2604,
275,
469,
288,
283,
16768,
30860,
356,
359,
355,
291,
14,
9340,
63,
31796,
63,
1099,
63,
466,
3252,
6223,
356,
6786,
1552,
288,
1622,
267,
789,
267,
543,
5341,
63,
31796,
8,
277,
14,
85,
337,
12,
1788,
534,
38,
297,
570,
29,
505,
12,
2079,
5936,
63,
2604,
29,
2601,
63,
2604,
9,
465,
754,
26
] |
[
5055,
492,
12863,
199,
504,
4126,
492,
10703,
199,
646,
2882,
199,
646,
2050,
199,
199,
504,
506,
4291,
14,
10706,
14,
10650,
30860,
492,
6431,
30860,
199,
504,
512,
25530,
14,
2604,
14,
14983,
2889,
492,
26401,
2889,
199,
504,
512,
25530,
14,
2604,
14,
2980,
4709,
492,
5800,
4709,
199,
504,
512,
25530,
14,
1751,
14,
8660,
492,
15247,
199,
504,
512,
25530,
14,
1751,
14,
7776,
492,
13510,
199,
504,
512,
25530,
14,
4776,
14,
5339,
30860,
774,
4433,
492,
4911,
63,
1832,
63,
31796,
12,
5341,
63,
31796,
199,
199,
396,
63,
493,
275,
408,
199,
396,
1004,
5325,
562,
199,
475,
886,
199,
705,
5325,
278,
199,
624,
421,
199,
10650,
30860,
774,
275,
4911,
63,
1832,
63,
31796,
8,
272,
6431,
30860,
12,
272,
1686,
63,
1725,
2687,
396,
63,
493,
4706,
272,
3866,
63,
1725,
7782,
396,
1004,
11386,
297,
673,
283,
396,
1004,
3429,
6024,
659,
272,
2202,
3713,
7511,
356,
283,
11396,
12,
5721,
297,
1598,
283,
3671,
356,
283,
67,
3071,
421,
199,
533,
6431,
30860,
10746,
774,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
2792,
275,
15247,
8355,
267,
291,
14,
2792,
14,
740,
8,
7776,
360,
3671,
297,
283,
1548,
19,
1333,
267,
291,
14,
2792,
14,
740,
8,
7776,
360,
7511,
297,
283,
11768,
1333,
267,
291,
14,
85,
337,
275,
6431,
30860,
8,
277,
14,
2792,
12,
10703,
1012,
398,
291,
14,
9340,
63,
31796,
63,
1099,
63,
466,
275,
12863,
360,
1099,
297,
788,
4407,
1105,
267,
291,
14,
2601,
63,
2604,
275,
791,
16768,
30860,
356,
26401,
2889,
8,
288,
283,
16768,
30860,
297,
791,
6223,
356,
6248,
1552,
93,
339,
347,
511,
63,
1667,
63,
6691,
8,
277,
304,
267,
1318,
275,
788,
65,
508,
330,
418,
398,
543,
5341,
63,
31796,
8,
277,
14,
85,
337,
12,
1788,
534,
38,
297,
570,
29,
505,
12,
2079,
5936,
63,
2604,
29,
277,
14,
2601,
63,
2604,
9,
465,
754,
26,
288,
291,
14,
629,
8,
1099,
12,
3073,
339,
347,
511,
63,
6691,
63,
262,
63,
3349,
8,
277,
304,
267,
2657,
63,
2604,
275,
469,
288,
283,
16768,
30860,
356,
1052,
267,
789,
267,
1318,
275,
788,
3,
11386,
11869,
418,
267,
543,
5341,
63,
31796,
8,
277,
14,
85,
337,
12,
1788,
534,
38,
297,
570,
29,
505,
12,
2079,
5936,
63,
2604,
29,
2601,
63,
2604,
9,
465,
754,
26,
288,
291,
14,
629,
8,
1099,
59,
16,
1055,
17418,
12,
5009,
288,
291,
14,
629,
8,
1099,
59,
16,
1055,
26653,
63,
600,
59,
16,
1055,
928,
14,
604,
12,
413,
9,
288,
291,
14,
629,
8,
552,
8,
1099,
395,
413,
9,
398,
2657,
63,
2604,
275,
791,
16768,
30860,
356,
26401,
2889,
8,
288,
283,
16768,
30860,
297,
791,
6223,
356,
11869,
1552,
93,
267,
543,
5341,
63,
31796,
8,
277,
14,
85,
337,
12,
1788,
534,
38,
297,
570,
29,
505,
12,
2079,
5936,
63,
2604,
29,
2601,
63,
2604,
9,
465,
754,
26,
288,
291,
14,
629,
8,
1099,
59,
16,
1055,
17418,
12,
5009,
288,
291,
14,
629,
8,
1099,
59,
16,
1055,
26653,
63,
600,
59,
16,
1055,
928,
14,
604,
12,
413,
9,
288,
291,
14,
629,
8,
552,
8,
1099,
395,
413,
9,
398,
2657,
63,
2604,
275,
791,
16768,
30860,
356,
26401,
2889,
8,
288,
283,
16768,
30860,
297,
11869,
6769,
267,
543,
5341,
63,
31796,
8,
277,
14,
85,
337,
12,
1788,
534,
38,
297,
570,
29,
505,
12,
2079,
5936,
63,
2604,
29,
2601,
63,
2604,
9,
465,
754,
26,
288,
291,
14,
629,
8,
1099,
59,
16,
1055,
17418,
12,
5009,
288,
291,
14,
629,
8,
1099,
59,
16,
1055,
26653,
63,
600,
59,
16,
1055,
928,
14,
604,
12,
413,
9,
288,
291,
14,
629,
8,
552,
8,
1099,
395,
413,
9,
339,
347,
511,
63,
6691,
63,
1397,
63,
262,
63,
3349,
8,
277,
304,
267,
1318,
275,
788,
3,
3721,
11869,
60,
78,
297,
283,
65,
275,
298,
11768,
3212,
78,
418,
267,
6786,
275,
359,
2980,
4709,
14,
504,
63,
1459,
360,
38,
297,
413,
12,
413,
12,
413,
12,
6335,
1874,
267,
2657,
63,
2604,
275,
469,
288,
283,
16768,
30860,
356,
359,
355,
291,
14,
9340,
63,
31796,
63,
1099,
63,
466,
3252,
6223,
356,
6786,
1552,
288,
1622,
267,
789,
398,
543,
5341,
63,
31796,
8,
277,
14,
85,
337,
12,
1788,
534,
38,
297,
570,
29,
505,
12,
2079,
5936,
63,
2604,
29,
2601,
63,
2604,
9,
465,
754,
26,
288,
291,
14,
629,
8,
552,
8,
1099,
59,
16,
1055,
17418,
395,
378,
9,
339,
347,
511,
63,
6691,
63,
3028,
8,
277,
304,
267,
1318,
275,
788,
3,
11386,
11869,
60,
78,
418,
267,
6786,
275,
359,
2980,
4709,
14,
504,
63,
1459,
360,
38,
297,
413,
12,
413,
12,
413,
12,
1616,
1874,
267,
2657,
63,
2604,
275,
469,
288,
283,
16768,
30860,
356,
359,
355,
291,
14,
9340,
63,
31796,
63,
1099,
63,
466,
3252,
6223,
356,
6786,
1552,
288,
1622,
267,
789,
398,
543,
5341,
63,
31796,
8,
277,
14,
85,
337,
12,
1788,
534,
38,
297,
570,
29,
505,
12,
2079,
5936,
63,
2604,
29,
2601,
63,
2604,
9,
465,
754,
26,
288,
291,
14,
629,
8,
1099,
59,
16,
1055,
17418,
459,
38,
2278,
32180,
63,
3028,
12,
2490,
283,
2595,
971,
78,
7,
2490,
283,
4176,
11,
971,
78,
7,
2490,
283,
7492,
446,
17,
435,
16,
12,
16,
13365,
60,
78,
7,
2490,
2475,
3,
11386,
11869,
60,
78,
358,
398,
1318,
275,
788,
396,
275,
12766,
327,
11386,
11869,
60,
78,
418,
267,
6786,
275,
359,
2980,
4709,
14,
504,
63,
1459,
360,
38,
297,
413,
12,
4119,
12,
413,
12,
6546,
1874,
267,
2657,
63,
2604,
275,
469,
288,
283,
16768,
30860,
356,
359,
355,
291,
14,
9340,
63,
31796,
63,
1099,
63,
466,
3252,
6223,
356,
6786,
1552,
288,
1622,
267,
789,
267,
543,
5341,
63,
31796,
8,
277,
14,
85,
337,
12,
1788,
534,
38,
297,
570,
29,
505,
12,
2079,
5936,
63,
2604,
29,
2601,
63,
2604,
9,
465,
754,
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,
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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
] |
andrewnsk/dorokhin.moscow
|
blog/models.py
|
1
|
2578
|
import os
import uuid
from django.db import models
from django.urls import reverse
from ckeditor.fields import RichTextField
from extended_profile.models import Profile
from taggit.managers import TaggableManager
def get_file_name(instance, filename):
ext = filename.split('.')[-1]
filename = "%s.%s" % (uuid.uuid4(), ext)
return os.path.join('images/blog/', filename)
class Category(models.Model):
name = models.CharField(max_length=200, db_index=True)
slug = models.SlugField(max_length=200, db_index=True, unique=True)
image = models.ImageField(upload_to=get_file_name, blank=True, verbose_name="Картинка для категории")
def get_absolute_url(self):
return reverse('blog:ArticleListByCategory', args=[self.slug])
class Meta:
ordering = ['name']
verbose_name = 'Категория'
verbose_name_plural = 'Категории'
managed = True
def __str__(self):
return self.name
class Article(models.Model):
category = models.ForeignKey(Category, related_name='articles', verbose_name="Категория", on_delete=models.CASCADE)
name = models.CharField(max_length=200, db_index=True, verbose_name="Название")
slug = models.SlugField(max_length=200, db_index=True)
sourceref = models.CharField(max_length=200, verbose_name="Cсылка на первоисточник", default='', blank=True)
image = models.ImageField(upload_to='article/%Y/%m/%d/', blank=True, verbose_name="КДПВ")
description = RichTextField(blank=True, verbose_name="Описание")
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
author = models.ForeignKey(Profile, null=True, blank=True, on_delete=models.CASCADE)
body = RichTextField(blank=True, verbose_name="Текст статьи")
visible = models.BooleanField(default=True)
tags = TaggableManager()
time_to_read = models.CharField(max_length=5, null=True, blank=True)
featured = models.BooleanField(default=False)
def get_absolute_url(self):
return reverse('blog:ArticleDetail', args=[self.slug])
def get_author_profile_url(self):
return reverse('extended_profile:profile', args=[self.author_id])
def get_admin_change_page(self):
return reverse('admin:blog_article_change', args=(self.id,))
class Meta:
ordering = ['created']
index_together = [
['id', 'slug']
]
managed = True
def __str__(self):
return self.name
|
mit
|
[
646,
747,
199,
646,
5377,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
3603,
492,
3837,
199,
504,
286,
415,
27050,
14,
955,
492,
30846,
6254,
199,
504,
9243,
63,
2913,
14,
992,
492,
14386,
199,
504,
1947,
3187,
14,
16259,
492,
8053,
16725,
2988,
421,
199,
318,
664,
63,
493,
63,
354,
8,
842,
12,
1788,
304,
272,
1599,
275,
1788,
14,
1294,
29084,
17,
61,
272,
1788,
275,
2071,
83,
4111,
83,
2,
450,
334,
2580,
14,
2580,
20,
1062,
1599,
9,
272,
372,
747,
14,
515,
14,
904,
360,
4782,
15,
11486,
3678,
1788,
9,
421,
199,
533,
13573,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
12,
1592,
63,
1080,
29,
549,
9,
272,
8889,
275,
1709,
14,
17315,
8,
988,
63,
1267,
29,
1840,
12,
1592,
63,
1080,
29,
549,
12,
3747,
29,
549,
9,
272,
1834,
275,
1709,
14,
21910,
8,
5064,
63,
475,
29,
362,
63,
493,
63,
354,
12,
4596,
29,
549,
12,
3376,
63,
354,
628,
141,
249,
27559,
7413,
27859,
29352,
29562,
10356,
14978,
31999,
24219,
15578,
112,
26438,
6500,
6500,
531,
339,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
267,
372,
3837,
360,
11486,
26,
7221,
1296,
2175,
7841,
297,
1249,
1524,
277,
14,
5464,
566,
339,
1021,
6288,
26,
267,
7794,
275,
788,
354,
418,
267,
3376,
63,
354,
275,
283,
141,
249,
24219,
15578,
112,
26438,
6500,
14978,
7,
267,
3376,
63,
354,
63,
10019,
275,
283,
141,
249,
24219,
15578,
112,
26438,
6500,
6500,
7,
267,
12883,
275,
715,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
533,
8281,
8,
992,
14,
1685,
304,
339,
4637,
275,
1709,
14,
3190,
8,
7841,
12,
4048,
63,
354,
534,
19813,
297,
3376,
63,
354,
628,
141,
249,
24219,
15578,
112,
26438,
6500,
14978,
401,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
12,
1592,
63,
1080,
29,
549,
12,
3376,
63,
354,
628,
141,
252,
13111,
116,
19630,
21674,
6500,
6286,
531,
272,
8889,
275,
1709,
14,
17315,
8,
988,
63,
1267,
29,
1840,
12,
1592,
63,
1080,
29,
549,
9,
272,
1350,
1121,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
12,
3376,
63,
354,
628,
35,
8474,
17445,
10356,
29352,
24917,
5657,
19820,
21273,
19630,
5806,
6500,
18261,
5806,
19277,
7592,
6500,
11487,
401,
849,
4581,
4596,
29,
549,
9,
272,
1834,
275,
1709,
14,
21910,
8,
5064,
63,
475,
534,
6934,
3149,
57,
3149,
77,
3149,
68,
3678,
4596,
29,
549,
12,
3376,
63,
354,
628,
141,
249,
141,
243,
141,
254,
141,
241,
531,
272,
1369,
275,
30846,
6254,
8,
2500,
29,
549,
12,
3376,
63,
354,
628,
141,
253,
23645,
6500,
8474,
21674,
6500,
6286,
531,
272,
2737,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
9,
272,
4588,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
9,
272,
4132,
275,
1709,
14,
3190,
8,
5736,
12,
2973,
29,
549,
12,
4596,
29,
549,
12,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
2396,
275,
30846,
6254,
8,
2500,
29,
549,
12,
3376,
63,
354,
628,
141,
96,
6286,
11487,
18261,
221,
18261,
24219,
16961,
6500,
531,
272,
8917,
275,
1709,
14,
5036,
8,
885,
29,
549,
9,
272,
3762,
275,
8053,
16725,
2988,
342,
272,
900,
63,
475,
63,
739,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
21,
12,
2973,
29,
549,
12,
4596,
29,
549,
9,
272,
13953,
3297,
275,
1709,
14,
5036,
8,
885,
29,
797,
9,
339,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
267,
372,
3837,
360,
11486,
26,
7221,
8064,
297,
1249,
1524,
277,
14,
5464,
566,
339,
347,
664,
63,
2502,
63,
2913,
63,
633,
8,
277,
304,
267,
372,
3837,
360,
10525,
63,
2913,
26,
2913,
297,
1249,
1524,
277,
14,
2502,
63,
344,
566,
339,
347,
664,
63,
2113,
63,
1461,
63,
1606,
8,
277,
304,
267,
372,
3837,
360,
2113,
26,
11486,
63,
6934,
63,
1461,
297,
1249,
2687,
277,
14,
344,
4641,
339,
1021,
6288,
26,
267,
7794,
275,
788,
3966,
418,
267,
1478,
63,
6314,
275,
359,
288,
788,
344,
297,
283,
5464,
418,
267,
1622,
267,
12883,
275,
715,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
747,
199,
646,
5377,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
3603,
492,
3837,
199,
504,
286,
415,
27050,
14,
955,
492,
30846,
6254,
199,
504,
9243,
63,
2913,
14,
992,
492,
14386,
199,
504,
1947,
3187,
14,
16259,
492,
8053,
16725,
2988,
421,
199,
318,
664,
63,
493,
63,
354,
8,
842,
12,
1788,
304,
272,
1599,
275,
1788,
14,
1294,
29084,
17,
61,
272,
1788,
275,
2071,
83,
4111,
83,
2,
450,
334,
2580,
14,
2580,
20,
1062,
1599,
9,
272,
372,
747,
14,
515,
14,
904,
360,
4782,
15,
11486,
3678,
1788,
9,
421,
199,
533,
13573,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
12,
1592,
63,
1080,
29,
549,
9,
272,
8889,
275,
1709,
14,
17315,
8,
988,
63,
1267,
29,
1840,
12,
1592,
63,
1080,
29,
549,
12,
3747,
29,
549,
9,
272,
1834,
275,
1709,
14,
21910,
8,
5064,
63,
475,
29,
362,
63,
493,
63,
354,
12,
4596,
29,
549,
12,
3376,
63,
354,
628,
141,
249,
27559,
7413,
27859,
29352,
29562,
10356,
14978,
31999,
24219,
15578,
112,
26438,
6500,
6500,
531,
339,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
267,
372,
3837,
360,
11486,
26,
7221,
1296,
2175,
7841,
297,
1249,
1524,
277,
14,
5464,
566,
339,
1021,
6288,
26,
267,
7794,
275,
788,
354,
418,
267,
3376,
63,
354,
275,
283,
141,
249,
24219,
15578,
112,
26438,
6500,
14978,
7,
267,
3376,
63,
354,
63,
10019,
275,
283,
141,
249,
24219,
15578,
112,
26438,
6500,
6500,
7,
267,
12883,
275,
715,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
533,
8281,
8,
992,
14,
1685,
304,
339,
4637,
275,
1709,
14,
3190,
8,
7841,
12,
4048,
63,
354,
534,
19813,
297,
3376,
63,
354,
628,
141,
249,
24219,
15578,
112,
26438,
6500,
14978,
401,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
12,
1592,
63,
1080,
29,
549,
12,
3376,
63,
354,
628,
141,
252,
13111,
116,
19630,
21674,
6500,
6286,
531,
272,
8889,
275,
1709,
14,
17315,
8,
988,
63,
1267,
29,
1840,
12,
1592,
63,
1080,
29,
549,
9,
272,
1350,
1121,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
12,
3376,
63,
354,
628,
35,
8474,
17445,
10356,
29352,
24917,
5657,
19820,
21273,
19630,
5806,
6500,
18261,
5806,
19277,
7592,
6500,
11487,
401,
849,
4581,
4596,
29,
549,
9,
272,
1834,
275,
1709,
14,
21910,
8,
5064,
63,
475,
534,
6934,
3149,
57,
3149,
77,
3149,
68,
3678,
4596,
29,
549,
12,
3376,
63,
354,
628,
141,
249,
141,
243,
141,
254,
141,
241,
531,
272,
1369,
275,
30846,
6254,
8,
2500,
29,
549,
12,
3376,
63,
354,
628,
141,
253,
23645,
6500,
8474,
21674,
6500,
6286,
531,
272,
2737,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
9,
272,
4588,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
9,
272,
4132,
275,
1709,
14,
3190,
8,
5736,
12,
2973,
29,
549,
12,
4596,
29,
549,
12,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
2396,
275,
30846,
6254,
8,
2500,
29,
549,
12,
3376,
63,
354,
628,
141,
96,
6286,
11487,
18261,
221,
18261,
24219,
16961,
6500,
531,
272,
8917,
275,
1709,
14,
5036,
8,
885,
29,
549,
9,
272,
3762,
275,
8053,
16725,
2988,
342,
272,
900,
63,
475,
63,
739,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
21,
12,
2973,
29,
549,
12,
4596,
29,
549,
9,
272,
13953,
3297,
275,
1709,
14,
5036,
8,
885,
29,
797,
9,
339,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
267,
372,
3837,
360,
11486,
26,
7221,
8064,
297,
1249,
1524,
277,
14,
5464,
566,
339,
347,
664,
63,
2502,
63,
2913,
63,
633,
8,
277,
304,
267,
372,
3837,
360,
10525,
63,
2913,
26,
2913,
297,
1249,
1524,
277,
14,
2502,
63,
344,
566,
339,
347,
664,
63,
2113,
63,
1461,
63,
1606,
8,
277,
304,
267,
372,
3837,
360,
2113,
26,
11486,
63,
6934,
63,
1461,
297,
1249,
2687,
277,
14,
344,
4641,
339,
1021,
6288,
26,
267,
7794,
275,
788,
3966,
418,
267,
1478,
63,
6314,
275,
359,
288,
788,
344,
297,
283,
5464,
418,
267,
1622,
267,
12883,
275,
715,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
indashnet/InDashNet.Open.UN2000
|
android/external/chromium_org/tools/gyp/test/configurations/inheritance/gyptest-inheritance.py
|
430
|
1047
|
#!/usr/bin/env python
# Copyright (c) 2009 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 build of an executable in three different configurations.
"""
import TestGyp
test = TestGyp.TestGyp()
test.run_gyp('configurations.gyp')
test.set_configuration('Release')
test.build('configurations.gyp')
test.run_built_executable('configurations',
stdout=('Base configuration\n'
'Common configuration\n'
'Common2 configuration\n'
'Release configuration\n'))
test.set_configuration('Debug')
test.build('configurations.gyp')
test.run_built_executable('configurations',
stdout=('Base configuration\n'
'Common configuration\n'
'Common2 configuration\n'
'Debug configuration\n'))
test.pass_test()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
8937,
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,
1900,
402,
376,
7286,
315,
7795,
3365,
13422,
14,
199,
624,
199,
199,
646,
25688,
199,
199,
396,
275,
25688,
14,
774,
13899,
342,
199,
199,
396,
14,
1065,
63,
6179,
360,
10057,
14,
6179,
358,
199,
199,
396,
14,
409,
63,
4758,
360,
9625,
358,
199,
396,
14,
1506,
360,
10057,
14,
6179,
358,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
10057,
297,
2079,
3839,
7782,
1563,
2897,
60,
78,
7,
3303,
283,
7844,
2897,
60,
78,
7,
3303,
283,
7844,
18,
2897,
60,
78,
7,
3303,
283,
9625,
2897,
60,
78,
1333,
199,
199,
396,
14,
409,
63,
4758,
360,
7084,
358,
199,
396,
14,
1506,
360,
10057,
14,
6179,
358,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
10057,
297,
2079,
3839,
7782,
1563,
2897,
60,
78,
7,
3303,
283,
7844,
2897,
60,
78,
7,
3303,
283,
7844,
18,
2897,
60,
78,
7,
3303,
283,
7084,
2897,
60,
78,
1333,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
8937,
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,
1900,
402,
376,
7286,
315,
7795,
3365,
13422,
14,
199,
624,
199,
199,
646,
25688,
199,
199,
396,
275,
25688,
14,
774,
13899,
342,
199,
199,
396,
14,
1065,
63,
6179,
360,
10057,
14,
6179,
358,
199,
199,
396,
14,
409,
63,
4758,
360,
9625,
358,
199,
396,
14,
1506,
360,
10057,
14,
6179,
358,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
10057,
297,
2079,
3839,
7782,
1563,
2897,
60,
78,
7,
3303,
283,
7844,
2897,
60,
78,
7,
3303,
283,
7844,
18,
2897,
60,
78,
7,
3303,
283,
9625,
2897,
60,
78,
1333,
199,
199,
396,
14,
409,
63,
4758,
360,
7084,
358,
199,
396,
14,
1506,
360,
10057,
14,
6179,
358,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
10057,
297,
2079,
3839,
7782,
1563,
2897,
60,
78,
7,
3303,
283,
7844,
2897,
60,
78,
7,
3303,
283,
7844,
18,
2897,
60,
78,
7,
3303,
283,
7084,
2897,
60,
78,
1333,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
AlbertoPeon/invenio
|
modules/websubmit/lib/functions/Set_RN_From_Sysno.py
|
24
|
8173
|
## This file is part of Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2013 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""WebSubmit function - Set the global variable 'rn' to the report
number of the record identified by sysno
"""
import os, cgi
from invenio.config import CFG_SITE_SUPPORT_EMAIL
from invenio.search_engine import get_fieldvalues, record_exists
from invenio.websubmit_functions.Shared_Functions import ParamFromFile
from invenio.websubmit_functions.Get_Recid import is_record_matching_pattern
## JavaScript action and message to be passed to "InvenioWebSubmitFunctionStop"
## when a record does not exist or has been deleted.
CFG_ALERT_DOCUMENT_NOT_FOUND = """\n<script type="text/javascript">
document.forms[0].action="/submit";
document.forms[0].curpage.value=1;
document.forms[0].step.value=0;
user_must_confirm_before_leaving_page = false;
alert('The document with record ID [%s] cannot be found in our """ \
"""database.\\nPerhaps it has been deleted or has not yet been integrated? """ \
"""You can choose another record ID or retry this action in a few minutes.');\n
document.forms[0].submit();
</script>"""
## JavaScript action and message to be passed to "InvenioWebSubmitFunctionStop"
## when it seems that we try to access an invalid path.
CFG_ALERT_INVALID_EDSRN_PATH = """\n<script type="text/javascript">
document.forms[0].action="/submit";
document.forms[0].curpage.value=1;
document.forms[0].step.value=0;
user_must_confirm_before_leaving_page = false;
alert('It is not possible to access path [%s]. Please contact %s');\n
document.forms[0].submit();
</script>"""
## JavaScript action and message to be passed to "InvenioWebSubmitFunctionStop"
## when the recid found doesn't match the type of document that should be
## handled by this submission
CFG_ALERT_WRONG_RECORD_FOR_THIS_SUBMISSION = """
<script type="text/javascript">
document.forms[0].action="/submit";
document.forms[0].curpage.value=1;
document.forms[0].step.value=0;
user_must_confirm_before_leaving_page = false;
alert('This document can not be handled using this submission interface.\\n""" \
"""You can choose another record ID or retry this action in a few """ \
"""minutes.');\n
document.forms[0].submit();
</script>"""
## JavaScript action and message to be passed to "InvenioWebSubmitFunctionStop"
## when the recid found is not an integer
CFG_ALERT_RECORD_ID_MUST_BE_INT = """
<script type="text/javascript">
document.forms[0].action="/submit";
document.forms[0].curpage.value=1;
document.forms[0].step.value=0;
user_must_confirm_before_leaving_page = false;
alert('The provided record ID [%s] must be an integer.');\n
document.forms[0].submit();
</script>"""
# Where to look for report numbers (in this order)
CFG_DEFAULT_RN_TAGS = ['037__a', '088__a', '021__a']
def Set_RN_From_Sysno(parameters, curdir, form, user_info=None):
"""
Set the global variable 'rn' to the report number of the record
identified by 'sysno' (recid) global variable.
Useful at MBI step when the user specifies the record to modify
using the recid instead of the report number. Since most
WebSubmit functions relies on the global 'rn' variable, it is
necessary in these cases to include this function.
This function MUST be preceded by 'Get_Recid' function.
To identify the record to update via 'recid' instead of report
number, one MUST on the MBI form request the recid/sysno using a
form element named 'SN'.
Parameters:
edsrn - file where to write the report number if found
rep_tags - comma-separater list of tags where the report number
can be found. Default is '037__a', '088__a', '021__a'
if no value is specified.
record_search_pattern - this enforces restrictions on which type of
documents can be modified via a certain submission
interface. If the record_search_pattern is not
defined, no restriction will be enforced. The
record_search_pattern can be anything that can be
used by search_pattern to search for. Also, one can
use variables stored locally, like
<comboDEMOJRN> to denote the category or
subcategory.
Ex:
reportnumber:DEMO-<comboDEMOJRN>-*
collection:ATLANTISTIMESNEWS
reportnumber:DEMO-<comboDEMOJRN>-* | collection:ATLANTISTIMESNEWS
As a note, you can test your pattern, using the
search engine and see if it retrieves the expected
results.
WARNING: this check is not applied if the report
number has already been written to 'edsrn' file.
Exceptions raised:
+ InvenioWebSubmitFunctionStop
- if trying to access unauthorized path to read/write report number;
- if accessing a recid that does not exist or is deleted;
- if recid should not be handled by the current submission;
"""
global rn, sysno
if not sysno:
return
try:
sysno = int(sysno)
except:
raise InvenioWebSubmitFunctionStop(CFG_ALERT_RECORD_ID_MUST_BE_INT % \
cgi.escape((sysno)))
edsrn = parameters['edsrn']
path_to_repnum_file = os.path.join(curdir, edsrn)
if not os.path.abspath(path_to_repnum_file).startswith(curdir):
# Trying to access invalid path...
raise InvenioWebSubmitFunctionStop(CFG_ALERT_INVALID_EDSRN_PATH % \
(cgi.escape(path_to_repnum_file),
cgi.escape(CFG_SITE_SUPPORT_EMAIL)))
if os.path.exists(path_to_repnum_file):
# Have we already written RN to disk? If so, read from there
possible_rn = ParamFromFile(path_to_repnum_file)
if possible_rn.strip():
# No empty
rn = possible_rn
return
if record_exists(sysno) != 1:
# Record does not exist
raise InvenioWebSubmitFunctionStop(CFG_ALERT_DOCUMENT_NOT_FOUND % sysno)
## Check if the record needs to comply to any restriction.
## Basically checks if this record can/should be handled by this submission
if parameters['record_search_pattern']:
if not is_record_matching_pattern(parameters['record_search_pattern'], sysno, curdir):
# delete the SN file and reset the sysno,
# because this record is not the good record to be hadled by this submission
os.rename("%s/SN" % curdir, "%s/SN_WRONG" % curdir)
sysno = ""
raise InvenioWebSubmitFunctionStop(CFG_ALERT_WRONG_RECORD_FOR_THIS_SUBMISSION)
rn_tags = [tag.strip() for tag in parameters['rep_tags'].split(',') \
if tag.strip()]
if not rn_tags:
rn_tags = CFG_DEFAULT_RN_TAGS
# Retrieve report number in metadata
for rn_tag in rn_tags:
possible_report_numbers = get_fieldvalues(sysno, rn_tag)
if possible_report_numbers:
rn = possible_report_numbers[0].strip()
break
edsrn = parameters['edsrn']
path_to_repnum_file = os.path.join(curdir, edsrn)
if rn and not os.path.exists(path_to_repnum_file):
# Write report number to specified file
fp = open(path_to_repnum_file, 'w')
fp.write(rn)
fp.close()
|
gpl-2.0
|
[
309,
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
6171,
24354,
14,
199,
309,
199,
309,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
309,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
309,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
624,
5926,
17187,
805,
446,
2494,
314,
2288,
1750,
283,
11641,
7,
370,
314,
3622,
717,
1329,
402,
314,
2777,
15836,
701,
984,
889,
199,
624,
199,
646,
747,
12,
16004,
199,
504,
13640,
14,
888,
492,
10974,
63,
7917,
63,
10640,
63,
10089,
199,
504,
13640,
14,
1733,
63,
3908,
492,
664,
63,
698,
1459,
12,
2777,
63,
2444,
199,
504,
13640,
14,
2520,
7275,
63,
5777,
14,
12197,
63,
13967,
492,
12608,
26637,
199,
504,
13640,
14,
2520,
7275,
63,
5777,
14,
1002,
63,
497,
7504,
492,
365,
63,
3059,
63,
9467,
63,
3401,
199,
199,
309,
15250,
1595,
436,
1245,
370,
506,
3032,
370,
298,
607,
7597,
5926,
17187,
3481,
6293,
2,
199,
309,
1380,
282,
2777,
1630,
440,
2187,
503,
965,
2757,
5463,
14,
199,
10118,
63,
748,
5397,
63,
7884,
63,
4609,
63,
13945,
275,
9638,
78,
28,
1579,
730,
628,
505,
15,
9554,
1743,
199,
3554,
14,
3351,
59,
16,
1055,
1287,
9555,
7275,
11436,
199,
3554,
14,
3351,
59,
16,
1055,
895,
1606,
14,
585,
29,
17,
27,
199,
3554,
14,
3351,
59,
16,
1055,
2926,
14,
585,
29,
16,
27,
199,
751,
63,
7790,
63,
9548,
63,
5182,
63,
274,
5519,
63,
1606,
275,
3055,
27,
199,
9241,
360,
1918,
2213,
543,
2777,
2870,
8978,
83,
61,
3913,
506,
1911,
315,
4154,
408,
971,
199,
624,
4659,
14,
1103,
78,
2623,
17396,
652,
965,
2757,
5463,
503,
965,
440,
5966,
2757,
17806,
972,
31,
408,
971,
199,
624,
5556,
883,
11496,
4573,
2777,
2870,
503,
7269,
642,
1595,
315,
282,
9284,
9395,
2659,
3779,
78,
199,
3554,
14,
3351,
59,
16,
1055,
7275,
7303,
199,
1108,
1579,
11193,
199,
199,
309,
15250,
1595,
436,
1245,
370,
506,
3032,
370,
298,
607,
7597,
5926,
17187,
3481,
6293,
2,
199,
309,
1380,
652,
12237,
626,
781,
862,
370,
2879,
376,
3866,
931,
14,
199,
10118,
63,
748,
5397,
63,
9692,
63,
1149,
5943,
46,
63,
3243,
275,
9638,
78,
28,
1579,
730,
628,
505,
15,
9554,
1743,
199,
3554,
14,
3351,
59,
16,
1055,
1287,
9555,
7275,
11436,
199,
3554,
14,
3351,
59,
16,
1055,
895,
1606,
14,
585,
29,
17,
27,
199,
3554,
14,
3351,
59,
16,
1055,
2926,
14,
585,
29,
16,
27,
199,
751,
63,
7790,
63,
9548,
63,
5182,
63,
274,
5519,
63,
1606,
275,
3055,
27,
199,
9241,
360,
7940,
365,
440,
3962,
370,
2879,
931,
8978,
83,
1055,
7754,
8966,
450,
83,
358,
3779,
78,
199,
3554,
14,
3351,
59,
16,
1055,
7275,
7303,
199,
1108,
1579,
11193,
199,
199,
309,
15250,
1595,
436,
1245,
370,
506,
3032,
370,
298,
607,
7597,
5926,
17187,
3481,
6293,
2,
199,
309,
1380,
314,
25305,
1911,
3181,
1133,
1336,
314,
730,
402,
2213,
626,
1077,
506,
199,
309,
8860,
701,
642,
13071,
199,
10118,
63,
748,
5397,
63,
6524,
7770,
63,
15060,
63,
2707,
63,
24571,
63,
6348,
22320,
275,
408,
199,
28,
1579,
730,
628,
505,
15,
9554,
1743,
199,
3554,
14,
3351,
59,
16,
1055,
1287,
9555,
7275,
11436,
199,
3554,
14,
3351,
59,
16,
1055,
895,
1606,
14,
585,
29,
17,
27,
199,
3554,
14,
3351,
59,
16,
1055,
2926,
14,
585,
29,
16,
27,
199,
751,
63,
7790,
63,
9548,
63,
5182,
63,
274,
5519,
63,
1606,
275,
3055,
27,
199,
9241,
360,
2765,
2213,
883,
440,
506,
8860,
1808,
642,
13071,
3217,
14,
1103,
78,
624,
971,
199,
624,
5556,
883,
11496,
4573,
2777,
2870,
503,
7269,
642,
1595,
315,
282,
9284,
408,
971,
199,
624,
10430,
2659,
3779,
78,
199,
3554,
14,
3351,
59,
16,
1055,
7275,
7303,
199,
1108,
1579,
11193,
199,
199,
309,
15250,
1595,
436,
1245,
370,
506,
3032,
370,
298,
607,
7597,
5926,
17187,
3481,
6293,
2,
199,
309,
1380,
314,
25305,
1911,
365,
440,
376,
3000,
199,
10118,
63,
748,
5397,
63,
15060,
63,
998,
63,
45,
7698,
63,
6773,
63,
2919,
275,
408,
199,
28,
1579,
730,
628,
505,
15,
9554,
1743,
199,
3554,
14,
3351,
59,
16,
1055,
1287,
9555,
7275,
11436,
199,
3554,
14,
3351,
59,
16,
1055,
895,
1606,
14,
585,
29,
17,
27,
199,
3554,
14,
3351,
59,
16,
1055,
2926,
14,
585,
29,
16,
27,
199,
751,
63,
7790,
63,
9548,
63,
5182,
63,
274,
5519,
63,
1606,
275,
3055,
27,
199,
9241,
360,
1918,
2741,
2777,
2870,
8978,
83,
61,
1471,
506,
376,
3000,
2659,
3779,
78,
199,
3554,
14,
3351,
59,
16,
1055,
7275,
7303,
199,
1108,
1579,
11193,
199,
199,
3,
17685,
370,
3648,
367,
3622,
5579,
334,
262,
642,
1865,
9,
199,
10118,
63,
3472,
63,
15303,
63,
17626,
275,
788,
18325,
363,
65,
297,
283,
27930,
363,
65,
297,
283,
15385,
363,
65,
418,
199,
199,
318,
2494,
63,
15303,
63,
2532,
63,
11319,
889,
8,
3214,
12,
1094,
694,
12,
1824,
12,
922,
63,
815,
29,
403,
304,
272,
408,
272,
2494,
314,
2288,
1750,
283,
11641,
7,
370,
314,
3622,
1329,
402,
314,
2777,
272,
15836,
701,
283,
1274,
889,
7,
334,
17532,
9,
2288,
1750
] |
[
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
6171,
24354,
14,
199,
309,
199,
309,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
309,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
309,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
624,
5926,
17187,
805,
446,
2494,
314,
2288,
1750,
283,
11641,
7,
370,
314,
3622,
717,
1329,
402,
314,
2777,
15836,
701,
984,
889,
199,
624,
199,
646,
747,
12,
16004,
199,
504,
13640,
14,
888,
492,
10974,
63,
7917,
63,
10640,
63,
10089,
199,
504,
13640,
14,
1733,
63,
3908,
492,
664,
63,
698,
1459,
12,
2777,
63,
2444,
199,
504,
13640,
14,
2520,
7275,
63,
5777,
14,
12197,
63,
13967,
492,
12608,
26637,
199,
504,
13640,
14,
2520,
7275,
63,
5777,
14,
1002,
63,
497,
7504,
492,
365,
63,
3059,
63,
9467,
63,
3401,
199,
199,
309,
15250,
1595,
436,
1245,
370,
506,
3032,
370,
298,
607,
7597,
5926,
17187,
3481,
6293,
2,
199,
309,
1380,
282,
2777,
1630,
440,
2187,
503,
965,
2757,
5463,
14,
199,
10118,
63,
748,
5397,
63,
7884,
63,
4609,
63,
13945,
275,
9638,
78,
28,
1579,
730,
628,
505,
15,
9554,
1743,
199,
3554,
14,
3351,
59,
16,
1055,
1287,
9555,
7275,
11436,
199,
3554,
14,
3351,
59,
16,
1055,
895,
1606,
14,
585,
29,
17,
27,
199,
3554,
14,
3351,
59,
16,
1055,
2926,
14,
585,
29,
16,
27,
199,
751,
63,
7790,
63,
9548,
63,
5182,
63,
274,
5519,
63,
1606,
275,
3055,
27,
199,
9241,
360,
1918,
2213,
543,
2777,
2870,
8978,
83,
61,
3913,
506,
1911,
315,
4154,
408,
971,
199,
624,
4659,
14,
1103,
78,
2623,
17396,
652,
965,
2757,
5463,
503,
965,
440,
5966,
2757,
17806,
972,
31,
408,
971,
199,
624,
5556,
883,
11496,
4573,
2777,
2870,
503,
7269,
642,
1595,
315,
282,
9284,
9395,
2659,
3779,
78,
199,
3554,
14,
3351,
59,
16,
1055,
7275,
7303,
199,
1108,
1579,
11193,
199,
199,
309,
15250,
1595,
436,
1245,
370,
506,
3032,
370,
298,
607,
7597,
5926,
17187,
3481,
6293,
2,
199,
309,
1380,
652,
12237,
626,
781,
862,
370,
2879,
376,
3866,
931,
14,
199,
10118,
63,
748,
5397,
63,
9692,
63,
1149,
5943,
46,
63,
3243,
275,
9638,
78,
28,
1579,
730,
628,
505,
15,
9554,
1743,
199,
3554,
14,
3351,
59,
16,
1055,
1287,
9555,
7275,
11436,
199,
3554,
14,
3351,
59,
16,
1055,
895,
1606,
14,
585,
29,
17,
27,
199,
3554,
14,
3351,
59,
16,
1055,
2926,
14,
585,
29,
16,
27,
199,
751,
63,
7790,
63,
9548,
63,
5182,
63,
274,
5519,
63,
1606,
275,
3055,
27,
199,
9241,
360,
7940,
365,
440,
3962,
370,
2879,
931,
8978,
83,
1055,
7754,
8966,
450,
83,
358,
3779,
78,
199,
3554,
14,
3351,
59,
16,
1055,
7275,
7303,
199,
1108,
1579,
11193,
199,
199,
309,
15250,
1595,
436,
1245,
370,
506,
3032,
370,
298,
607,
7597,
5926,
17187,
3481,
6293,
2,
199,
309,
1380,
314,
25305,
1911,
3181,
1133,
1336,
314,
730,
402,
2213,
626,
1077,
506,
199,
309,
8860,
701,
642,
13071,
199,
10118,
63,
748,
5397,
63,
6524,
7770,
63,
15060,
63,
2707,
63,
24571,
63,
6348,
22320,
275,
408,
199,
28,
1579,
730,
628,
505,
15,
9554,
1743,
199,
3554,
14,
3351,
59,
16,
1055,
1287,
9555,
7275,
11436,
199,
3554,
14,
3351,
59,
16,
1055,
895,
1606,
14,
585,
29,
17,
27,
199,
3554,
14,
3351,
59,
16,
1055,
2926,
14,
585,
29,
16,
27,
199,
751,
63,
7790,
63,
9548,
63,
5182,
63,
274,
5519,
63,
1606,
275,
3055,
27,
199,
9241,
360,
2765,
2213,
883,
440,
506,
8860,
1808,
642,
13071,
3217,
14,
1103,
78,
624,
971,
199,
624,
5556,
883,
11496,
4573,
2777,
2870,
503,
7269,
642,
1595,
315,
282,
9284,
408,
971,
199,
624,
10430,
2659,
3779,
78,
199,
3554,
14,
3351,
59,
16,
1055,
7275,
7303,
199,
1108,
1579,
11193,
199,
199,
309,
15250,
1595,
436,
1245,
370,
506,
3032,
370,
298,
607,
7597,
5926,
17187,
3481,
6293,
2,
199,
309,
1380,
314,
25305,
1911,
365,
440,
376,
3000,
199,
10118,
63,
748,
5397,
63,
15060,
63,
998,
63,
45,
7698,
63,
6773,
63,
2919,
275,
408,
199,
28,
1579,
730,
628,
505,
15,
9554,
1743,
199,
3554,
14,
3351,
59,
16,
1055,
1287,
9555,
7275,
11436,
199,
3554,
14,
3351,
59,
16,
1055,
895,
1606,
14,
585,
29,
17,
27,
199,
3554,
14,
3351,
59,
16,
1055,
2926,
14,
585,
29,
16,
27,
199,
751,
63,
7790,
63,
9548,
63,
5182,
63,
274,
5519,
63,
1606,
275,
3055,
27,
199,
9241,
360,
1918,
2741,
2777,
2870,
8978,
83,
61,
1471,
506,
376,
3000,
2659,
3779,
78,
199,
3554,
14,
3351,
59,
16,
1055,
7275,
7303,
199,
1108,
1579,
11193,
199,
199,
3,
17685,
370,
3648,
367,
3622,
5579,
334,
262,
642,
1865,
9,
199,
10118,
63,
3472,
63,
15303,
63,
17626,
275,
788,
18325,
363,
65,
297,
283,
27930,
363,
65,
297,
283,
15385,
363,
65,
418,
199,
199,
318,
2494,
63,
15303,
63,
2532,
63,
11319,
889,
8,
3214,
12,
1094,
694,
12,
1824,
12,
922,
63,
815,
29,
403,
304,
272,
408,
272,
2494,
314,
2288,
1750,
283,
11641,
7,
370,
314,
3622,
1329,
402,
314,
2777,
272,
15836,
701,
283,
1274,
889,
7,
334,
17532,
9,
2288,
1750,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
timlinux/inasafe
|
safe/definitions/layer_modes.py
|
11
|
2921
|
# coding=utf-8
"""
Definitions relating to layer modes (continuous or classified data).
"""
from safe.utilities.i18n import tr
__copyright__ = "Copyright 2016, The InaSAFE Project"
__license__ = "GPL version 3"
__email__ = "info@inasafe.org"
__revision__ = '$Format:%H$'
layer_mode_continuous = {
'key': 'continuous',
'name': tr('Continuous'),
'description': tr(
'<b>Continuous</b> data can be used in raster hazard or exposure data '
'where the values in the data are either integers or decimal values '
'representing a continuously varying phenomenon. For example flood '
'depth is a continuous value from 0 to the maximum reported depth '
'during a flood. <p>Raster exposure data such as population data are '
'also continuous. In this example the cell values represent the '
'number of people in cell.</p>'
'<p>Raster data is considered to be continuous by default and you '
'should explicitly indicate that it is classified if each cell in the '
'raster represents a discrete class (e.g. low depth = 1, medium depth '
'= 2, high depth = 3).</p>'
),
'citations': [
{
'text': None,
'link': None
}
],
}
layer_mode_classified = {
'key': 'classified',
'name': tr('Classified'),
'description': tr(
'<b>Classified</b> data can be used for either hazard or exposure '
'data and can be used for both raster and vector layer types where '
'the attribute values represent a classified or coded value.'
'<p>For example, classified values in a flood raster data set might '
'represent discrete classes where a value of 1 might represent the '
'low inundation class, a value of 2 might represent the medium '
'inundation class and a value of 3 might represent the '
'high inundation class.</p>'
'<p>Classified values in a vector (polygon) volcano data set might '
'represent discrete classes where a value of I might represent low '
'volcanic hazard, a value of II might represent medium volcanic '
'hazard and a value of III might represent a high volcanic hazard.'
'</p>'
'<p>Classified values in a vector exposure data set might include '
'building type or road type.</p>'
),
'citations': [
{
'text': None,
'link': None
}
],
}
layer_mode = {
'key': 'layer_mode',
'name': tr('Data type'),
'description': tr(
'The data type describes the values in the layer. Values can be '
'continuous or classified'),
'types': [
layer_mode_continuous,
layer_mode_classified
],
'citations': [
{
'text': None,
'link': None
}
]
}
layer_mode_all = [
layer_mode_classified,
layer_mode_continuous
]
|
gpl-3.0
|
[
3,
2803,
29,
1624,
13,
24,
199,
624,
199,
16738,
4668,
1958,
370,
4045,
12404,
334,
23458,
503,
11534,
1290,
666,
680,
199,
624,
199,
199,
504,
5048,
14,
16355,
14,
73,
1085,
78,
492,
5651,
199,
199,
363,
7307,
363,
275,
298,
7384,
7800,
12,
710,
1010,
65,
27657,
7290,
2,
199,
363,
1682,
363,
275,
298,
12006,
1015,
650,
2,
199,
363,
2123,
363,
275,
298,
815,
32,
262,
305,
6504,
14,
1308,
2,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
421,
199,
1897,
63,
632,
63,
23458,
275,
469,
272,
283,
498,
356,
283,
23458,
297,
272,
283,
354,
356,
5651,
360,
24593,
7514,
659,
272,
283,
1802,
356,
5651,
8,
267,
2650,
66,
30,
24593,
7514,
1108,
66,
30,
666,
883,
506,
1202,
315,
19775,
394,
32145,
503,
30105,
666,
283,
267,
283,
4509,
314,
1338,
315,
314,
666,
787,
1902,
9446,
503,
6107,
1338,
283,
267,
283,
13063,
316,
282,
19922,
590,
17083,
316,
3945,
287,
1377,
2865,
14,
2104,
2893,
289,
21703,
283,
267,
283,
4631,
365,
282,
19922,
574,
687,
378,
370,
314,
5696,
14581,
5818,
283,
267,
283,
27868,
282,
289,
21703,
14,
665,
80,
30,
13284,
30105,
666,
4066,
465,
16423,
666,
787,
283,
267,
283,
12344,
19922,
14,
1010,
642,
2893,
314,
4917,
1338,
2954,
314,
283,
267,
283,
1955,
402,
13135,
315,
4917,
9758,
80,
3524,
267,
2650,
80,
30,
13284,
666,
365,
8652,
370,
506,
19922,
701,
849,
436,
1265,
283,
267,
283,
5626,
7662,
6623,
626,
652,
365,
11534,
1290,
340,
1924,
4917,
315,
314,
283,
267,
283,
20876,
8469,
282,
24635,
1021,
334,
69,
14,
71,
14,
6465,
5818,
275,
413,
12,
21576,
5818,
283,
267,
26143,
499,
12,
4721,
5818,
275,
650,
680,
1108,
80,
3524,
272,
2318,
272,
283,
14422,
1298,
356,
359,
267,
469,
288,
283,
505,
356,
488,
12,
288,
283,
1073,
356,
488,
267,
789,
272,
2156,
199,
93,
199,
1897,
63,
632,
63,
12334,
1290,
275,
469,
272,
283,
498,
356,
283,
12334,
1290,
297,
272,
283,
354,
356,
5651,
360,
30722,
1290,
659,
272,
283,
1802,
356,
5651,
8,
267,
2650,
66,
30,
30722,
1290,
1108,
66,
30,
666,
883,
506,
1202,
367,
1902,
394,
32145,
503,
30105,
283,
267,
283,
576,
436,
883,
506,
1202,
367,
3865,
19775,
436,
5477,
4045,
2943,
2382,
283,
267,
283,
1589,
2225,
1338,
2954,
282,
11534,
1290,
503,
1233,
68,
574,
3530,
267,
2650,
80,
30,
1858,
2893,
12,
11534,
1290,
1338,
315,
282,
289,
21703,
19775,
666,
663,
5594,
283,
267,
283,
13063,
24635,
3992,
2382,
282,
574,
402,
413,
5594,
2954,
314,
283,
267,
283,
674,
315,
725,
425,
1021,
12,
282,
574,
402,
499,
5594,
2954,
314,
21576,
283,
267,
283,
262,
725,
425,
1021,
436,
282,
574,
402,
650,
5594,
2954,
314,
283,
267,
283,
6260,
315,
725,
425,
1021,
9758,
80,
3524,
267,
2650,
80,
30,
30722,
1290,
1338,
315,
282,
5477,
334,
16295,
9,
5236,
2425,
79,
666,
663,
5594,
283,
267,
283,
13063,
24635,
3992,
2382,
282,
574,
402,
473,
5594,
2954,
6465,
283,
267,
283,
5650,
2425,
530,
394,
32145,
12,
282,
574,
402,
473,
41,
5594,
2954,
21576,
5236,
2425,
530,
283,
267,
283,
22133,
1005,
436,
282,
574,
402,
473,
8921,
221,
5594,
2954,
282,
4721,
5236,
2425,
530,
394,
32145,
3530,
267,
11936,
80,
3524,
267,
2650,
80,
30,
30722,
1290,
1338,
315,
282,
5477,
30105,
666,
663,
5594,
2387,
283,
267,
283,
17952,
730,
503,
882,
350,
730,
9758,
80,
3524,
272,
2318,
272,
283,
14422,
1298,
356,
359,
267,
469,
288,
283,
505,
356,
488,
12,
288,
283,
1073,
356,
488,
267,
789,
272,
2156,
199,
93,
199,
1897,
63,
632,
275,
469,
272,
283,
498,
356,
283,
1897,
63,
632,
297,
272,
283,
354,
356,
5651,
360,
1451,
730,
659,
272,
283,
1802,
356,
5651,
8,
267,
283,
1918,
666,
730,
23369,
314,
1338,
315,
314,
4045,
14,
13468,
883,
506,
283,
267,
283,
23458,
503,
11534,
1290,
659,
272,
283,
1313,
356,
359,
267,
4045,
63,
632,
63,
23458,
12,
267,
4045,
63,
632,
63,
12334,
1290,
272,
2156,
272,
283,
14422,
1298,
356,
359,
267,
469,
288,
283,
505,
356,
488,
12,
288,
283,
1073,
356,
488,
267,
789,
272,
1622,
199,
93,
199,
199,
1897,
63,
632,
63,
452,
275,
359,
272,
4045,
63,
632,
63,
12334,
1290,
12,
272,
4045,
63,
632,
63,
23458,
199,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2803,
29,
1624,
13,
24,
199,
624,
199,
16738,
4668,
1958,
370,
4045,
12404,
334,
23458,
503,
11534,
1290,
666,
680,
199,
624,
199,
199,
504,
5048,
14,
16355,
14,
73,
1085,
78,
492,
5651,
199,
199,
363,
7307,
363,
275,
298,
7384,
7800,
12,
710,
1010,
65,
27657,
7290,
2,
199,
363,
1682,
363,
275,
298,
12006,
1015,
650,
2,
199,
363,
2123,
363,
275,
298,
815,
32,
262,
305,
6504,
14,
1308,
2,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
421,
199,
1897,
63,
632,
63,
23458,
275,
469,
272,
283,
498,
356,
283,
23458,
297,
272,
283,
354,
356,
5651,
360,
24593,
7514,
659,
272,
283,
1802,
356,
5651,
8,
267,
2650,
66,
30,
24593,
7514,
1108,
66,
30,
666,
883,
506,
1202,
315,
19775,
394,
32145,
503,
30105,
666,
283,
267,
283,
4509,
314,
1338,
315,
314,
666,
787,
1902,
9446,
503,
6107,
1338,
283,
267,
283,
13063,
316,
282,
19922,
590,
17083,
316,
3945,
287,
1377,
2865,
14,
2104,
2893,
289,
21703,
283,
267,
283,
4631,
365,
282,
19922,
574,
687,
378,
370,
314,
5696,
14581,
5818,
283,
267,
283,
27868,
282,
289,
21703,
14,
665,
80,
30,
13284,
30105,
666,
4066,
465,
16423,
666,
787,
283,
267,
283,
12344,
19922,
14,
1010,
642,
2893,
314,
4917,
1338,
2954,
314,
283,
267,
283,
1955,
402,
13135,
315,
4917,
9758,
80,
3524,
267,
2650,
80,
30,
13284,
666,
365,
8652,
370,
506,
19922,
701,
849,
436,
1265,
283,
267,
283,
5626,
7662,
6623,
626,
652,
365,
11534,
1290,
340,
1924,
4917,
315,
314,
283,
267,
283,
20876,
8469,
282,
24635,
1021,
334,
69,
14,
71,
14,
6465,
5818,
275,
413,
12,
21576,
5818,
283,
267,
26143,
499,
12,
4721,
5818,
275,
650,
680,
1108,
80,
3524,
272,
2318,
272,
283,
14422,
1298,
356,
359,
267,
469,
288,
283,
505,
356,
488,
12,
288,
283,
1073,
356,
488,
267,
789,
272,
2156,
199,
93,
199,
1897,
63,
632,
63,
12334,
1290,
275,
469,
272,
283,
498,
356,
283,
12334,
1290,
297,
272,
283,
354,
356,
5651,
360,
30722,
1290,
659,
272,
283,
1802,
356,
5651,
8,
267,
2650,
66,
30,
30722,
1290,
1108,
66,
30,
666,
883,
506,
1202,
367,
1902,
394,
32145,
503,
30105,
283,
267,
283,
576,
436,
883,
506,
1202,
367,
3865,
19775,
436,
5477,
4045,
2943,
2382,
283,
267,
283,
1589,
2225,
1338,
2954,
282,
11534,
1290,
503,
1233,
68,
574,
3530,
267,
2650,
80,
30,
1858,
2893,
12,
11534,
1290,
1338,
315,
282,
289,
21703,
19775,
666,
663,
5594,
283,
267,
283,
13063,
24635,
3992,
2382,
282,
574,
402,
413,
5594,
2954,
314,
283,
267,
283,
674,
315,
725,
425,
1021,
12,
282,
574,
402,
499,
5594,
2954,
314,
21576,
283,
267,
283,
262,
725,
425,
1021,
436,
282,
574,
402,
650,
5594,
2954,
314,
283,
267,
283,
6260,
315,
725,
425,
1021,
9758,
80,
3524,
267,
2650,
80,
30,
30722,
1290,
1338,
315,
282,
5477,
334,
16295,
9,
5236,
2425,
79,
666,
663,
5594,
283,
267,
283,
13063,
24635,
3992,
2382,
282,
574,
402,
473,
5594,
2954,
6465,
283,
267,
283,
5650,
2425,
530,
394,
32145,
12,
282,
574,
402,
473,
41,
5594,
2954,
21576,
5236,
2425,
530,
283,
267,
283,
22133,
1005,
436,
282,
574,
402,
473,
8921,
221,
5594,
2954,
282,
4721,
5236,
2425,
530,
394,
32145,
3530,
267,
11936,
80,
3524,
267,
2650,
80,
30,
30722,
1290,
1338,
315,
282,
5477,
30105,
666,
663,
5594,
2387,
283,
267,
283,
17952,
730,
503,
882,
350,
730,
9758,
80,
3524,
272,
2318,
272,
283,
14422,
1298,
356,
359,
267,
469,
288,
283,
505,
356,
488,
12,
288,
283,
1073,
356,
488,
267,
789,
272,
2156,
199,
93,
199,
1897,
63,
632,
275,
469,
272,
283,
498,
356,
283,
1897,
63,
632,
297,
272,
283,
354,
356,
5651,
360,
1451,
730,
659,
272,
283,
1802,
356,
5651,
8,
267,
283,
1918,
666,
730,
23369,
314,
1338,
315,
314,
4045,
14,
13468,
883,
506,
283,
267,
283,
23458,
503,
11534,
1290,
659,
272,
283,
1313,
356,
359,
267,
4045,
63,
632,
63,
23458,
12,
267,
4045,
63,
632,
63,
12334,
1290,
272,
2156,
272,
283,
14422,
1298,
356,
359,
267,
469,
288,
283,
505,
356,
488,
12,
288,
283,
1073,
356,
488,
267,
789,
272,
1622,
199,
93,
199,
199,
1897,
63,
632,
63,
452,
275,
359,
272,
4045,
63,
632,
63,
12334,
1290,
12,
272,
4045,
63,
632,
63,
23458,
199,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mano3m/CouchPotatoServer
|
libs/sqlalchemy/dialects/postgresql/pg8000.py
|
18
|
3801
|
# postgresql/pg8000.py
# Copyright (C) 2005-2013 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
"""Support for the PostgreSQL database via the pg8000 driver.
Connecting
----------
URLs are of the form
``postgresql+pg8000://user:password@host:port/dbname[?key=value&key=value...]``.
Unicode
-------
pg8000 requires that the postgresql client encoding be
configured in the postgresql.conf file in order to use encodings
other than ascii. Set this value to the same value as the
"encoding" parameter on create_engine(), usually "utf-8".
Interval
--------
Passing data from/to the Interval type is not supported as of
yet.
"""
from sqlalchemy import util, exc
from sqlalchemy.util.compat import decimal
from sqlalchemy import processors
from sqlalchemy import types as sqltypes
from sqlalchemy.dialects.postgresql.base import PGDialect, \
PGCompiler, PGIdentifierPreparer, PGExecutionContext,\
_DECIMAL_TYPES, _FLOAT_TYPES, _INT_TYPES
class _PGNumeric(sqltypes.Numeric):
def result_processor(self, dialect, coltype):
if self.asdecimal:
if coltype in _FLOAT_TYPES:
return processors.to_decimal_processor_factory(decimal.Decimal)
elif coltype in _DECIMAL_TYPES or coltype in _INT_TYPES:
# pg8000 returns Decimal natively for 1700
return None
else:
raise exc.InvalidRequestError(
"Unknown PG numeric type: %d" % coltype)
else:
if coltype in _FLOAT_TYPES:
# pg8000 returns float natively for 701
return None
elif coltype in _DECIMAL_TYPES or coltype in _INT_TYPES:
return processors.to_float
else:
raise exc.InvalidRequestError(
"Unknown PG numeric type: %d" % coltype)
class _PGNumericNoBind(_PGNumeric):
def bind_processor(self, dialect):
return None
class PGExecutionContext_pg8000(PGExecutionContext):
pass
class PGCompiler_pg8000(PGCompiler):
def visit_mod(self, binary, **kw):
return self.process(binary.left) + " %% " + self.process(binary.right)
def post_process_text(self, text):
if '%%' in text:
util.warn("The SQLAlchemy postgresql dialect now automatically escapes '%' in text() "
"expressions to '%%'.")
return text.replace('%', '%%')
class PGIdentifierPreparer_pg8000(PGIdentifierPreparer):
def _escape_identifier(self, value):
value = value.replace(self.escape_quote, self.escape_to_quote)
return value.replace('%', '%%')
class PGDialect_pg8000(PGDialect):
driver = 'pg8000'
supports_unicode_statements = True
supports_unicode_binds = True
default_paramstyle = 'format'
supports_sane_multi_rowcount = False
execution_ctx_cls = PGExecutionContext_pg8000
statement_compiler = PGCompiler_pg8000
preparer = PGIdentifierPreparer_pg8000
description_encoding = 'use_encoding'
colspecs = util.update_copy(
PGDialect.colspecs,
{
sqltypes.Numeric : _PGNumericNoBind,
sqltypes.Float : _PGNumeric
}
)
@classmethod
def dbapi(cls):
return __import__('pg8000').dbapi
def create_connect_args(self, url):
opts = url.translate_connect_args(username='user')
if 'port' in opts:
opts['port'] = int(opts['port'])
opts.update(url.query)
return ([], opts)
def is_disconnect(self, e, connection, cursor):
return "connection is closed" in str(e)
dialect = PGDialect_pg8000
|
gpl-3.0
|
[
3,
25951,
15,
4198,
15214,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
13,
6965,
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,
11532,
367,
314,
20175,
3050,
4799,
314,
10275,
15214,
5253,
14,
199,
199,
32000,
199,
9460,
199,
199,
2632,
83,
787,
402,
314,
1824,
199,
1040,
15437,
11,
4198,
15214,
921,
751,
26,
2060,
32,
1102,
26,
719,
15,
13238,
59,
31,
498,
29,
585,
6,
498,
29,
585,
18737,
4345,
199,
199,
7087,
199,
12797,
199,
199,
4198,
15214,
5074,
626,
314,
25951,
1890,
2644,
506,
199,
11786,
315,
314,
25951,
14,
2190,
570,
315,
1865,
370,
675,
14134,
199,
1848,
2419,
13294,
14,
2494,
642,
574,
370,
314,
2011,
574,
465,
314,
199,
2,
2991,
2,
2725,
641,
1218,
63,
3908,
1062,
9987,
298,
1624,
13,
24,
1674,
199,
199,
8227,
199,
518,
199,
199,
4986,
316,
666,
687,
15,
475,
314,
18766,
730,
365,
440,
3748,
465,
402,
199,
28064,
14,
199,
199,
624,
199,
504,
8335,
492,
4884,
12,
3178,
199,
504,
8335,
14,
1974,
14,
5819,
492,
6107,
199,
504,
8335,
492,
21620,
199,
504,
8335,
492,
2943,
465,
23111,
199,
504,
8335,
14,
11072,
83,
14,
15437,
14,
1095,
492,
26595,
22080,
12,
971,
355,
26595,
9131,
12,
26595,
7544,
2398,
24939,
12,
26595,
11310,
2998,
4202,
355,
485,
23925,
63,
7893,
12,
485,
11783,
63,
7893,
12,
485,
2919,
63,
7893,
199,
199,
533,
485,
11115,
14687,
8,
3009,
1313,
14,
14687,
304,
272,
347,
754,
63,
6459,
8,
277,
12,
10982,
12,
29623,
304,
267,
340,
291,
14,
305,
6355,
26,
288,
340,
29623,
315,
485,
11783,
63,
7893,
26,
355,
372,
21620,
14,
475,
63,
6355,
63,
6459,
63,
3702,
8,
6355,
14,
6745,
9,
288,
916,
29623,
315,
485,
23925,
63,
7893,
503,
29623,
315,
485,
2919,
63,
7893,
26,
355,
327,
10275,
15214,
2529,
6345,
302,
17330,
367,
5557,
383,
355,
372,
488,
288,
587,
26,
355,
746,
3178,
14,
26585,
8,
1169,
298,
5912,
26595,
8950,
730,
26,
450,
68,
2,
450,
29623,
9,
267,
587,
26,
288,
340,
29623,
315,
485,
11783,
63,
7893,
26,
355,
327,
10275,
15214,
2529,
2069,
302,
17330,
367,
1520,
614,
355,
372,
488,
288,
916,
29623,
315,
485,
23925,
63,
7893,
503,
29623,
315,
485,
2919,
63,
7893,
26,
355,
372,
21620,
14,
475,
63,
1609,
288,
587,
26,
355,
746,
3178,
14,
26585,
8,
1169,
298,
5912,
26595,
8950,
730,
26,
450,
68,
2,
450,
29623,
9,
421,
199,
533,
485,
11115,
14687,
1944,
8198,
1547,
11115,
14687,
304,
272,
347,
5398,
63,
6459,
8,
277,
12,
10982,
304,
267,
372,
488,
199,
199,
533,
26595,
11310,
2998,
63,
4198,
15214,
8,
11115,
11310,
2998,
304,
272,
986,
421,
199,
533,
26595,
9131,
63,
4198,
15214,
8,
11115,
9131,
304,
272,
347,
5684,
63,
1494,
8,
277,
12,
3366,
12,
1011,
829,
304,
267,
372,
291,
14,
1412,
8,
3008,
14,
3039,
9,
435,
298,
11539,
298,
435,
291,
14,
1412,
8,
3008,
14,
1019,
9,
339,
347,
2963,
63,
1412,
63,
505,
8,
277,
12,
1318,
304,
267,
340,
23100,
7,
315,
1318,
26,
288,
4884,
14,
4050,
480,
1918,
14303,
25951,
10982,
3063,
5847,
24644,
26386,
315,
1318,
342,
298,
1993,
298,
15264,
370,
23100,
29435,
267,
372,
1318,
14,
1814,
3508,
297,
23100,
358,
421,
199,
533,
26595,
7544,
2398,
24939,
63,
4198,
15214,
8,
11115,
7544,
2398,
24939,
304,
272,
347,
485,
3765,
63,
5364,
8,
277,
12,
574,
304,
267,
574,
275,
574,
14,
1814,
8,
277,
14,
3765,
63,
3513,
12,
291,
14,
3765,
63,
475,
63,
3513,
9,
267,
372,
574,
14,
1814,
3508,
297,
23100,
358,
421,
199,
533,
26595,
22080,
63,
4198,
15214,
8,
11115,
22080,
304,
272,
5253,
275,
283,
4198,
15214,
7,
339,
5171,
63,
2975,
63,
15384,
275,
715,
339,
5171,
63,
2975,
63,
27080,
275,
715,
339,
849,
63,
635,
2487,
275,
283,
908,
7,
272,
5171,
63,
83,
5865,
63,
3029,
63,
24007,
275,
756,
272,
6451,
63,
3799,
63,
1886,
275,
26595,
11310,
2998,
63,
4198,
15214,
272,
5164,
63,
5772,
275,
26595,
9131,
63,
4198,
15214,
272,
876,
24939,
275,
26595,
7544,
2398,
24939,
63,
4198,
15214,
272,
1369,
63,
2991,
275,
283,
1180,
63,
2991,
7,
339,
1048,
7273,
275,
4884,
14,
873,
63,
1574,
8,
267,
26595,
22080,
14,
4574,
733,
83,
12,
267,
469,
288,
23111,
14,
14687,
520,
485,
11115,
14687,
1944,
8198,
12,
288,
23111,
14,
5136,
520,
485,
11115,
14687,
267,
789,
272,
776,
339,
768,
3744,
272,
347,
29333,
8,
1886,
304,
267,
372,
636,
646,
19734,
4198,
15214,
1959,
22103,
339,
347,
1218,
63,
2242,
63,
589,
8,
277,
12,
1166,
304,
267,
3999,
275,
1166,
14,
5275,
63,
2242,
63,
589,
8,
2473,
534,
751,
358,
267,
340,
283,
719,
7,
315,
3999,
26,
288,
3999,
459,
719,
418,
275,
1109,
8,
3291,
459,
719,
1105,
267,
3999,
14,
873,
8,
633,
14,
1131,
9,
267,
372,
23293,
3999,
9,
339,
347,
365,
63,
10673,
8,
277,
12,
325,
12,
1950,
12,
3920,
304,
267,
372,
298,
2105,
365,
6876,
2,
315,
620,
8,
69,
9,
199,
199,
11072,
275,
26595,
22080,
63,
4198,
15214,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
25951,
15,
4198,
15214,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
13,
6965,
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,
11532,
367,
314,
20175,
3050,
4799,
314,
10275,
15214,
5253,
14,
199,
199,
32000,
199,
9460,
199,
199,
2632,
83,
787,
402,
314,
1824,
199,
1040,
15437,
11,
4198,
15214,
921,
751,
26,
2060,
32,
1102,
26,
719,
15,
13238,
59,
31,
498,
29,
585,
6,
498,
29,
585,
18737,
4345,
199,
199,
7087,
199,
12797,
199,
199,
4198,
15214,
5074,
626,
314,
25951,
1890,
2644,
506,
199,
11786,
315,
314,
25951,
14,
2190,
570,
315,
1865,
370,
675,
14134,
199,
1848,
2419,
13294,
14,
2494,
642,
574,
370,
314,
2011,
574,
465,
314,
199,
2,
2991,
2,
2725,
641,
1218,
63,
3908,
1062,
9987,
298,
1624,
13,
24,
1674,
199,
199,
8227,
199,
518,
199,
199,
4986,
316,
666,
687,
15,
475,
314,
18766,
730,
365,
440,
3748,
465,
402,
199,
28064,
14,
199,
199,
624,
199,
504,
8335,
492,
4884,
12,
3178,
199,
504,
8335,
14,
1974,
14,
5819,
492,
6107,
199,
504,
8335,
492,
21620,
199,
504,
8335,
492,
2943,
465,
23111,
199,
504,
8335,
14,
11072,
83,
14,
15437,
14,
1095,
492,
26595,
22080,
12,
971,
355,
26595,
9131,
12,
26595,
7544,
2398,
24939,
12,
26595,
11310,
2998,
4202,
355,
485,
23925,
63,
7893,
12,
485,
11783,
63,
7893,
12,
485,
2919,
63,
7893,
199,
199,
533,
485,
11115,
14687,
8,
3009,
1313,
14,
14687,
304,
272,
347,
754,
63,
6459,
8,
277,
12,
10982,
12,
29623,
304,
267,
340,
291,
14,
305,
6355,
26,
288,
340,
29623,
315,
485,
11783,
63,
7893,
26,
355,
372,
21620,
14,
475,
63,
6355,
63,
6459,
63,
3702,
8,
6355,
14,
6745,
9,
288,
916,
29623,
315,
485,
23925,
63,
7893,
503,
29623,
315,
485,
2919,
63,
7893,
26,
355,
327,
10275,
15214,
2529,
6345,
302,
17330,
367,
5557,
383,
355,
372,
488,
288,
587,
26,
355,
746,
3178,
14,
26585,
8,
1169,
298,
5912,
26595,
8950,
730,
26,
450,
68,
2,
450,
29623,
9,
267,
587,
26,
288,
340,
29623,
315,
485,
11783,
63,
7893,
26,
355,
327,
10275,
15214,
2529,
2069,
302,
17330,
367,
1520,
614,
355,
372,
488,
288,
916,
29623,
315,
485,
23925,
63,
7893,
503,
29623,
315,
485,
2919,
63,
7893,
26,
355,
372,
21620,
14,
475,
63,
1609,
288,
587,
26,
355,
746,
3178,
14,
26585,
8,
1169,
298,
5912,
26595,
8950,
730,
26,
450,
68,
2,
450,
29623,
9,
421,
199,
533,
485,
11115,
14687,
1944,
8198,
1547,
11115,
14687,
304,
272,
347,
5398,
63,
6459,
8,
277,
12,
10982,
304,
267,
372,
488,
199,
199,
533,
26595,
11310,
2998,
63,
4198,
15214,
8,
11115,
11310,
2998,
304,
272,
986,
421,
199,
533,
26595,
9131,
63,
4198,
15214,
8,
11115,
9131,
304,
272,
347,
5684,
63,
1494,
8,
277,
12,
3366,
12,
1011,
829,
304,
267,
372,
291,
14,
1412,
8,
3008,
14,
3039,
9,
435,
298,
11539,
298,
435,
291,
14,
1412,
8,
3008,
14,
1019,
9,
339,
347,
2963,
63,
1412,
63,
505,
8,
277,
12,
1318,
304,
267,
340,
23100,
7,
315,
1318,
26,
288,
4884,
14,
4050,
480,
1918,
14303,
25951,
10982,
3063,
5847,
24644,
26386,
315,
1318,
342,
298,
1993,
298,
15264,
370,
23100,
29435,
267,
372,
1318,
14,
1814,
3508,
297,
23100,
358,
421,
199,
533,
26595,
7544,
2398,
24939,
63,
4198,
15214,
8,
11115,
7544,
2398,
24939,
304,
272,
347,
485,
3765,
63,
5364,
8,
277,
12,
574,
304,
267,
574,
275,
574,
14,
1814,
8,
277,
14,
3765,
63,
3513,
12,
291,
14,
3765,
63,
475,
63,
3513,
9,
267,
372,
574,
14,
1814,
3508,
297,
23100,
358,
421,
199,
533,
26595,
22080,
63,
4198,
15214,
8,
11115,
22080,
304,
272,
5253,
275,
283,
4198,
15214,
7,
339,
5171,
63,
2975,
63,
15384,
275,
715,
339,
5171,
63,
2975,
63,
27080,
275,
715,
339,
849,
63,
635,
2487,
275,
283,
908,
7,
272,
5171,
63,
83,
5865,
63,
3029,
63,
24007,
275,
756,
272,
6451,
63,
3799,
63,
1886,
275,
26595,
11310,
2998,
63,
4198,
15214,
272,
5164,
63,
5772,
275,
26595,
9131,
63,
4198,
15214,
272,
876,
24939,
275,
26595,
7544,
2398,
24939,
63,
4198,
15214,
272,
1369,
63,
2991,
275,
283,
1180,
63,
2991,
7,
339,
1048,
7273,
275,
4884,
14,
873,
63,
1574,
8,
267,
26595,
22080,
14,
4574,
733,
83,
12,
267,
469,
288,
23111,
14,
14687,
520,
485,
11115,
14687,
1944,
8198,
12,
288,
23111,
14,
5136,
520,
485,
11115,
14687,
267,
789,
272,
776,
339,
768,
3744,
272,
347,
29333,
8,
1886,
304,
267,
372,
636,
646,
19734,
4198,
15214,
1959,
22103,
339,
347,
1218,
63,
2242,
63,
589,
8,
277,
12,
1166,
304,
267,
3999,
275,
1166,
14,
5275,
63,
2242,
63,
589,
8,
2473,
534,
751,
358,
267,
340,
283,
719,
7,
315,
3999,
26,
288,
3999,
459,
719,
418,
275,
1109,
8,
3291,
459,
719,
1105,
267,
3999,
14,
873,
8,
633,
14,
1131,
9,
267,
372,
23293,
3999,
9,
339,
347,
365,
63,
10673,
8,
277,
12,
325,
12,
1950,
12,
3920,
304,
267,
372,
298,
2105,
365,
6876,
2,
315,
620,
8,
69,
9,
199,
199,
11072,
275,
26595,
22080,
63,
4198,
15214,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
amontefusco/gnuradio-amontefusco
|
gnuradio-core/src/python/gnuradio/gr/qa_interp_fir_filter.py
|
6
|
1794
|
#!/usr/bin/env python
#
# Copyright 2004,2007 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
from gnuradio import gr, gr_unittest
import math
class test_interp_fir_filter (gr_unittest.TestCase):
def setUp (self):
self.tb = gr.top_block ()
def tearDown (self):
self.tb = None
def test_fff (self):
taps = [1, 10, 100, 1000, 10000]
src_data = (0, 2, 3, 5, 7, 11, 13, 17)
interpolation = 3
xr = (0,0,0,0,2,20,200,2003,20030,300,3005,30050,500,5007,50070,700,7011,70110,1100,11013,110130,1300,13017,130170)
expected_result = tuple ([float (x) for x in xr])
src = gr.vector_source_f (src_data)
op = gr.interp_fir_filter_fff (interpolation, taps)
dst = gr.vector_sink_f ()
self.tb.connect (src, op)
self.tb.connect (op, dst)
self.tb.run ()
result_data = dst.data ()
L = min(len(result_data), len(expected_result))
self.assertEqual (expected_result[0:L], result_data[0:L])
if __name__ == '__main__':
gr_unittest.main ()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8353,
12,
9488,
2868,
2290,
2752,
12,
3277,
14,
199,
3,
221,
199,
3,
961,
570,
365,
1777,
402,
1664,
13514,
199,
3,
221,
199,
3,
1664,
13514,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
1664,
13514,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
1664,
13514,
27,
1937,
314,
570,
9685,
14,
221,
982,
440,
12,
2218,
370,
199,
3,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
199,
3,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
9948,
199,
504,
24526,
492,
7192,
12,
7192,
63,
2796,
199,
646,
3473,
199,
199,
533,
511,
63,
14252,
63,
1795,
63,
1541,
334,
2587,
63,
2796,
14,
1746,
304,
339,
347,
3613,
334,
277,
304,
267,
291,
14,
5842,
275,
7192,
14,
2119,
63,
1457,
6248,
339,
347,
6766,
334,
277,
304,
267,
291,
14,
5842,
275,
488,
339,
347,
511,
63,
18190,
334,
277,
304,
267,
307,
7461,
275,
359,
17,
12,
1616,
12,
2948,
12,
5198,
12,
11630,
61,
267,
2928,
63,
576,
275,
334,
16,
12,
499,
12,
650,
12,
959,
12,
1520,
12,
4119,
12,
4944,
12,
5557,
9,
267,
14046,
275,
650,
267,
671,
82,
275,
334,
16,
12,
16,
12,
16,
12,
16,
12,
18,
12,
1165,
12,
1840,
12,
17919,
12,
1840,
1216,
12,
5863,
12,
5863,
21,
12,
5863,
1400,
12,
5783,
12,
5783,
23,
12,
5783,
2760,
12,
15946,
12,
23,
13059,
12,
28852,
709,
12,
26451,
12,
845,
13264,
12,
24827,
1216,
12,
969,
383,
12,
969,
9570,
12,
10067,
2760,
9,
267,
1420,
63,
1099,
275,
2008,
7287,
1609,
334,
88,
9,
367,
671,
315,
671,
82,
566,
398,
2928,
275,
7192,
14,
4106,
63,
1365,
63,
70,
334,
2164,
63,
576,
9,
267,
1687,
275,
7192,
14,
14252,
63,
1795,
63,
1541,
63,
18190,
334,
21080,
12,
307,
7461,
9,
267,
5042,
275,
7192,
14,
4106,
63,
11279,
63,
70,
6248,
267,
291,
14,
5842,
14,
2242,
334,
2164,
12,
1687,
9,
267,
291,
14,
5842,
14,
2242,
334,
411,
12,
5042,
9,
267,
291,
14,
5842,
14,
1065,
6248,
267,
754,
63,
576,
275,
5042,
14,
576,
6248,
267,
491,
275,
1748,
8,
552,
8,
1099,
63,
576,
395,
822,
8,
2062,
63,
1099,
430,
267,
291,
14,
629,
334,
2062,
63,
1099,
59,
16,
26,
44,
467,
754,
63,
576,
59,
16,
26,
44,
566,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
7192,
63,
2796,
14,
973,
6248,
27844,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
8353,
12,
9488,
2868,
2290,
2752,
12,
3277,
14,
199,
3,
221,
199,
3,
961,
570,
365,
1777,
402,
1664,
13514,
199,
3,
221,
199,
3,
1664,
13514,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
1664,
13514,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
1664,
13514,
27,
1937,
314,
570,
9685,
14,
221,
982,
440,
12,
2218,
370,
199,
3,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
199,
3,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
9948,
199,
504,
24526,
492,
7192,
12,
7192,
63,
2796,
199,
646,
3473,
199,
199,
533,
511,
63,
14252,
63,
1795,
63,
1541,
334,
2587,
63,
2796,
14,
1746,
304,
339,
347,
3613,
334,
277,
304,
267,
291,
14,
5842,
275,
7192,
14,
2119,
63,
1457,
6248,
339,
347,
6766,
334,
277,
304,
267,
291,
14,
5842,
275,
488,
339,
347,
511,
63,
18190,
334,
277,
304,
267,
307,
7461,
275,
359,
17,
12,
1616,
12,
2948,
12,
5198,
12,
11630,
61,
267,
2928,
63,
576,
275,
334,
16,
12,
499,
12,
650,
12,
959,
12,
1520,
12,
4119,
12,
4944,
12,
5557,
9,
267,
14046,
275,
650,
267,
671,
82,
275,
334,
16,
12,
16,
12,
16,
12,
16,
12,
18,
12,
1165,
12,
1840,
12,
17919,
12,
1840,
1216,
12,
5863,
12,
5863,
21,
12,
5863,
1400,
12,
5783,
12,
5783,
23,
12,
5783,
2760,
12,
15946,
12,
23,
13059,
12,
28852,
709,
12,
26451,
12,
845,
13264,
12,
24827,
1216,
12,
969,
383,
12,
969,
9570,
12,
10067,
2760,
9,
267,
1420,
63,
1099,
275,
2008,
7287,
1609,
334,
88,
9,
367,
671,
315,
671,
82,
566,
398,
2928,
275,
7192,
14,
4106,
63,
1365,
63,
70,
334,
2164,
63,
576,
9,
267,
1687,
275,
7192,
14,
14252,
63,
1795,
63,
1541,
63,
18190,
334,
21080,
12,
307,
7461,
9,
267,
5042,
275,
7192,
14,
4106,
63,
11279,
63,
70,
6248,
267,
291,
14,
5842,
14,
2242,
334,
2164,
12,
1687,
9,
267,
291,
14,
5842,
14,
2242,
334,
411,
12,
5042,
9,
267,
291,
14,
5842,
14,
1065,
6248,
267,
754,
63,
576,
275,
5042,
14,
576,
6248,
267,
491,
275,
1748,
8,
552,
8,
1099,
63,
576,
395,
822,
8,
2062,
63,
1099,
430,
267,
291,
14,
629,
334,
2062,
63,
1099,
59,
16,
26,
44,
467,
754,
63,
576,
59,
16,
26,
44,
566,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
7192,
63,
2796,
14,
973,
6248,
27844,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Brahimbaz/venom-xbmc-addons-beta
|
plugin.video.vstream/resources/sites/trash/anime_no_paradise_com.py
|
4
|
7104
|
#-*- coding: utf-8 -*-
#Venom.
from resources.lib.gui.hoster import cHosterGui
from resources.lib.handler.hosterHandler import cHosterHandler
from resources.lib.gui.gui import cGui
from resources.lib.gui.guiElement import cGuiElement
from resources.lib.handler.inputParameterHandler import cInputParameterHandler
from resources.lib.handler.outputParameterHandler import cOutputParameterHandler
from resources.lib.handler.requestHandler import cRequestHandler
from resources.lib.parser import cParser
from resources.lib.util import cUtil
import string
SITE_IDENTIFIER = 'anime_no_paradise_com'
SITE_NAME = 'Anime-no-Paradise.com'
SITE_DESC = 'Anime no Paradise : Streaming Anime Manga - Www.anime-no-paradise.com'
URL_MAIN = 'http://www.anime-no-paradise.com/'
ANIM_VOSTFRS = 'http://www.anime-no-paradise.com/page-7751108.html'
ANIM_MOVIES = 'http://www.anime-no-paradise.com/page-7947543.html'
def load():
oGui = cGui()
oOutputParameterHandler = cOutputParameterHandler()
oOutputParameterHandler.addParameter('siteUrl', ANIM_VOSTFRS)
oGui.addDir(SITE_IDENTIFIER, 'showMovies', 'Animes', 'animes.png', oOutputParameterHandler)
oOutputParameterHandler = cOutputParameterHandler()
oOutputParameterHandler.addParameter('siteUrl', ANIM_VOSTFRS)
oGui.addDir(SITE_IDENTIFIER, 'showAZ', 'Animes A-Z', 'az.png', oOutputParameterHandler)
oOutputParameterHandler = cOutputParameterHandler()
oOutputParameterHandler.addParameter('siteUrl', ANIM_MOVIES)
oGui.addDir(SITE_IDENTIFIER, 'showMovies', 'Animes Films & OAVS', 'animes.png', oOutputParameterHandler)
oOutputParameterHandler = cOutputParameterHandler()
oOutputParameterHandler.addParameter('siteUrl', ANIM_MOVIES)
oGui.addDir(SITE_IDENTIFIER, 'showAZ', 'Animes Films & OAVS A-Z', 'az.png', oOutputParameterHandler)
oGui.setEndOfDirectory()
def showAZ():
oGui = cGui()
oInputParameterHandler = cInputParameterHandler()
sUrl = oInputParameterHandler.getValue('siteUrl')
oOutputParameterHandler = cOutputParameterHandler()
oOutputParameterHandler.addParameter('siteUrl', sUrl)
oOutputParameterHandler.addParameter('AZ', '.')
oGui.addDir(SITE_IDENTIFIER, 'showMoviesAZ', '.', 'az.png', oOutputParameterHandler)
for i in string.ascii_uppercase:
oOutputParameterHandler = cOutputParameterHandler()
oOutputParameterHandler.addParameter('siteUrl', sUrl)
oOutputParameterHandler.addParameter('AZ', i)
oGui.addDir(SITE_IDENTIFIER, 'showMoviesAZ', i, 'az.png', oOutputParameterHandler)
oGui.setEndOfDirectory()
def showMoviesAZ():
oGui = cGui()
oInputParameterHandler = cInputParameterHandler()
sUrl = oInputParameterHandler.getValue('siteUrl')
sAZ = oInputParameterHandler.getValue('AZ')
oRequestHandler = cRequestHandler(sUrl)
sHtmlContent = oRequestHandler.request();
sPattern = '<a href="([^<]+)" style=".*?line-height: 21px;"><font color="#234656">([^<]+)</font></a>'
oParser = cParser()
aResult = oParser.parse(sHtmlContent, sPattern)
if (aResult[0] == True):
for aEntry in aResult[1]:
if len(sAZ)>0 and aEntry[1].upper()[0] == sAZ :
oOutputParameterHandler = cOutputParameterHandler()
oOutputParameterHandler.addParameter('siteUrl', str(aEntry[0]))
oOutputParameterHandler.addParameter('sMovieTitle', str(aEntry[1]))
oGui.addTV(SITE_IDENTIFIER, 'showHosters', aEntry[1], 'animes.png', '', '', oOutputParameterHandler)
oGui.setEndOfDirectory()
def showMovies():
oGui = cGui()
oInputParameterHandler = cInputParameterHandler()
sUrl = oInputParameterHandler.getValue('siteUrl')
oRequestHandler = cRequestHandler(sUrl)
sHtmlContent = oRequestHandler.request();
sPattern = '<a href="([^<]+)" style=".*?line-height: 21px;"><font color="#234656">([^<]+)</font></a>'
oParser = cParser()
aResult = oParser.parse(sHtmlContent, sPattern)
if (aResult[0] == True):
for aEntry in aResult[1]:
sTitle = aEntry[1].decode('latin-1').encode("utf-8")
sUrl = aEntry[0].replace(' ', '%20').lower()
oOutputParameterHandler = cOutputParameterHandler()
oOutputParameterHandler.addParameter('siteUrl', str(sUrl))
oOutputParameterHandler.addParameter('sMovieTitle', str(sTitle))
oGui.addTV(SITE_IDENTIFIER, 'showHosters', sTitle, 'animes.png', '', '', oOutputParameterHandler)
oGui.setEndOfDirectory()
def showHosters():
oGui = cGui()
oInputParameterHandler = cInputParameterHandler()
sUrl = oInputParameterHandler.getValue('siteUrl')
sMovieTitle = oInputParameterHandler.getValue('sMovieTitle')
sUrl = sUrl.replace(' ', '%20').lower()
iPage = 1
if (oInputParameterHandler.exist('page')):
iPage = oInputParameterHandler.getValue('page')
mUrl = sUrl + str(iPage)
oRequestHandler = cRequestHandler(mUrl)
sHtmlContent = oRequestHandler.request();
sHtmlContent = sHtmlContent.replace('<param name="src" value="http://anme-no-paradise.chatango.com/group">', '')
sPattern = '<a href=".+?" class="titreArticle" title=".+?">([^<]+)</a>.+?<span style="font-size: 12pt; color: #ff6600;">([^<]+)</span>|<param name="src" value="(.+?)"'
oParser = cParser()
aResult = oParser.parse(sHtmlContent, sPattern)
if (aResult[0] == True):
for aEntry in aResult[1]:
sHosterUrl = str(aEntry[2])
#oHoster = __checkHoster(sHosterUrl)
oHoster = cHosterGui().checkHoster(sHosterUrl)
if aEntry[0]:
oOutputParameterHandler = cOutputParameterHandler()
oOutputParameterHandler.addParameter('siteUrl', str(sUrl))
oOutputParameterHandler.addParameter('sMovieTitle', str(sMovieTitle))
oGui.addDir(SITE_IDENTIFIER, 'showHosters', '[COLOR red]'+str(aEntry[0])+'[/COLOR]', 'host.png', oOutputParameterHandler)
if (oHoster != False):
sTitle = str(aEntry[0]) + ' - ' + str(aEntry[1])
oHoster.setDisplayName(sTitle)
oHoster.setFileName(sTitle)
cHosterGui().showHoster(oGui, oHoster, sHosterUrl, '')
sNextPage = True
if (sNextPage != False):
iNextPage = int(iPage) + 1
oOutputParameterHandler = cOutputParameterHandler()
oOutputParameterHandler.addParameter('siteUrl', sUrl)
oOutputParameterHandler.addParameter('page', iNextPage)
oGui.addDir(SITE_IDENTIFIER, 'showHosters', '[COLOR teal]Next >>>[/COLOR]', 'next.png', oOutputParameterHandler)
oGui.setEndOfDirectory()
def __checkForNextPage(ipage, sUrl):
sPattern = 'anime-no-paradise.com/tag/.+?/(.{1,2})'
oParser = cParser()
aResult = oParser.parse(sUrl, sPattern)
if (aResult[0] == True):
return True
return False
|
gpl-2.0
|
[
3,
13,
1837,
2803,
26,
2774,
13,
24,
1882,
199,
3,
54,
287,
676,
14,
199,
504,
5944,
14,
773,
14,
5885,
14,
526,
11652,
492,
286,
40,
29895,
4324,
199,
504,
5944,
14,
773,
14,
2232,
14,
526,
11652,
2461,
492,
286,
40,
29895,
2461,
199,
504,
5944,
14,
773,
14,
5885,
14,
5885,
492,
286,
4324,
199,
504,
5944,
14,
773,
14,
5885,
14,
5885,
2162,
492,
286,
4324,
2162,
199,
504,
5944,
14,
773,
14,
2232,
14,
1210,
4720,
2461,
492,
286,
3205,
4720,
2461,
199,
504,
5944,
14,
773,
14,
2232,
14,
1199,
4720,
2461,
492,
286,
2959,
4720,
2461,
199,
504,
5944,
14,
773,
14,
2232,
14,
1069,
2461,
492,
286,
11149,
199,
504,
5944,
14,
773,
14,
2087,
492,
286,
2842,
199,
504,
5944,
14,
773,
14,
1974,
492,
286,
9562,
199,
646,
1059,
199,
199,
7917,
63,
22698,
275,
283,
290,
1036,
63,
889,
63,
12227,
328,
261,
63,
957,
7,
199,
7917,
63,
2339,
275,
283,
2493,
1036,
13,
889,
13,
28360,
328,
261,
14,
957,
7,
199,
7917,
63,
15119,
275,
283,
2493,
1036,
949,
2235,
65,
328,
261,
520,
28167,
1626,
1036,
603,
621,
65,
446,
644,
978,
14,
290,
1036,
13,
889,
13,
12227,
328,
261,
14,
957,
7,
199,
199,
2632,
63,
5848,
275,
283,
1014,
921,
1544,
14,
290,
1036,
13,
889,
13,
12227,
328,
261,
14,
957,
4805,
199,
32560,
63,
10662,
840,
5372,
51,
275,
283,
1014,
921,
1544,
14,
290,
1036,
13,
889,
13,
12227,
328,
261,
14,
957,
15,
1606,
13,
1138,
2869,
8079,
14,
1360,
7,
199,
32560,
63,
24321,
2563,
275,
283,
1014,
921,
1544,
14,
290,
1036,
13,
889,
13,
12227,
328,
261,
14,
957,
15,
1606,
13,
1965,
2417,
20103,
14,
1360,
7,
199,
199,
318,
2248,
837,
272,
312,
4324,
275,
286,
4324,
342,
2286,
312,
2959,
4720,
2461,
275,
286,
2959,
4720,
2461,
342,
272,
312,
2959,
4720,
2461,
14,
26895,
360,
2124,
6417,
297,
1261,
1469,
63,
10662,
840,
5372,
51,
9,
272,
312,
4324,
14,
525,
3567,
8,
7917,
63,
22698,
12,
283,
2384,
3716,
14484,
297,
283,
2493,
29778,
297,
283,
290,
29778,
14,
4524,
297,
312,
2959,
4720,
2461,
9,
2286,
312,
2959,
4720,
2461,
275,
286,
2959,
4720,
2461,
342,
272,
312,
2959,
4720,
2461,
14,
26895,
360,
2124,
6417,
297,
1261,
1469,
63,
10662,
840,
5372,
51,
9,
272,
312,
4324,
14,
525,
3567,
8,
7917,
63,
22698,
12,
283,
2384,
17613,
297,
283,
2493,
29778,
437,
13,
58,
297,
283,
4651,
14,
4524,
297,
312,
2959,
4720,
2461,
9,
2286,
312,
2959,
4720,
2461,
275,
286,
2959,
4720,
2461,
342,
272,
312,
2959,
4720,
2461,
14,
26895,
360,
2124,
6417,
297,
1261,
1469,
63,
24321,
2563,
9,
272,
312,
4324,
14,
525,
3567,
8,
7917,
63,
22698,
12,
283,
2384,
3716,
14484,
297,
283,
2493,
29778,
17887,
706,
1253,
593,
6087,
51,
297,
283,
290,
29778,
14,
4524,
297,
312,
2959,
4720,
2461,
9,
2286,
312,
2959,
4720,
2461,
275,
286,
2959,
4720,
2461,
342,
272,
312,
2959,
4720,
2461,
14,
26895,
360,
2124,
6417,
297,
1261,
1469,
63,
24321,
2563,
9,
272,
312,
4324,
14,
525,
3567,
8,
7917,
63,
22698,
12,
283,
2384,
17613,
297,
283,
2493,
29778,
17887,
706,
1253,
593,
6087,
51,
437,
13,
58,
297,
283,
4651,
14,
4524,
297,
312,
2959,
4720,
2461,
9,
15567,
312,
4324,
14,
409,
3005,
3466,
6231,
342,
523,
199,
318,
2498,
17613,
837,
272,
312,
4324,
275,
286,
4324,
342,
272,
312,
3205,
4720,
2461,
275,
286,
3205,
4720,
2461,
342,
272,
308,
6417,
275,
312,
3205,
4720,
2461,
14,
17186,
360,
2124,
6417,
358,
2286,
312,
2959,
4720,
2461,
275,
286,
2959,
4720,
2461,
342,
272,
312,
2959,
4720,
2461,
14,
26895,
360,
2124,
6417,
297,
308,
6417,
9,
272,
312,
2959,
4720,
2461,
14,
26895,
360,
17613,
297,
20093,
272,
312,
4324,
14,
525,
3567,
8,
7917,
63,
22698,
12,
283,
2384,
3716,
14484,
17613,
297,
22608,
283,
4651,
14,
4524,
297,
312,
2959,
4720,
2461,
9,
3698,
272,
367,
284,
315,
1059,
14,
4371,
63,
26831,
26,
267,
312,
2959,
4720,
2461,
275,
286,
2959,
4720,
2461,
342,
267,
312,
2959,
4720,
2461,
14,
26895,
360,
2124,
6417,
297,
308,
6417,
9,
267,
312,
2959,
4720,
2461,
14,
26895,
360,
17613,
297,
284,
9,
267,
312,
4324,
14,
525,
3567,
8,
7917,
63,
22698,
12,
283,
2384,
3716,
14484,
17613,
297,
284,
12,
283,
4651,
14,
4524,
297,
312,
2959,
4720,
2461,
9,
267,
272,
312,
4324,
14,
409,
3005,
3466,
6231,
342,
9948,
199,
318,
2498,
3716,
14484,
17613,
837,
272,
312,
4324,
275,
286,
4324,
342,
272,
312,
3205,
4720,
2461,
275,
286,
3205,
4720,
2461,
342,
272,
308,
6417,
275,
312,
3205,
4720,
2461,
14,
17186,
360,
2124,
6417,
358,
272,
308,
17613,
275,
312,
3205,
4720,
2461,
14,
17186,
360,
17613,
358,
2286,
312,
11149,
275,
286,
11149,
8,
83,
6417,
9,
272,
308,
12957,
2714,
275,
312,
11149,
14,
1069,
7303,
272,
308,
9959,
275,
2650,
65,
4369,
628,
31204,
2807,
2924,
3449,
628,
6697,
604,
13,
3333,
26,
7829,
5326,
27,
8186,
4246,
3164,
13476,
5533,
31441,
1743,
31204,
11896,
1108,
4246,
2957,
65,
3524,
272,
312,
2842,
275,
286,
2842,
342,
272,
282,
2889,
275,
312,
2842,
14,
1122,
8,
83,
12957,
2714,
12,
308,
9959,
9,
272,
340,
334,
65,
2889,
59,
16,
61,
508,
715,
304,
267,
367,
282,
3900,
315,
282,
2889,
59,
17,
2189,
288,
340,
822,
8,
83,
17613,
13032,
16,
436,
282,
3900,
59,
17,
1055,
4142,
3430,
16,
61,
508,
308,
17613,
520,
2234,
312,
2959,
4720,
2461,
275,
286,
2959,
4720,
2461,
342,
355,
312,
2959,
4720,
2461,
14,
26895,
360,
2124,
6417,
297,
620,
8,
65,
3900,
59,
16,
2459,
355,
312,
2959,
4720,
2461,
14,
26895,
360,
83,
19088,
6888,
297,
620,
8,
65,
3900,
59,
17,
2459,
355,
312,
4324,
14,
525,
12764,
8,
7917,
63,
22698,
12,
283,
2384,
40,
736,
878,
297,
282,
3900,
59,
17,
467,
283,
290,
29778,
14,
4524,
297,
3260,
3260,
312,
2959,
4720,
2461,
9,
1467,
339,
312,
4324,
14,
409,
3005,
3466,
6231
] |
[
13,
1837,
2803,
26,
2774,
13,
24,
1882,
199,
3,
54,
287,
676,
14,
199,
504,
5944,
14,
773,
14,
5885,
14,
526,
11652,
492,
286,
40,
29895,
4324,
199,
504,
5944,
14,
773,
14,
2232,
14,
526,
11652,
2461,
492,
286,
40,
29895,
2461,
199,
504,
5944,
14,
773,
14,
5885,
14,
5885,
492,
286,
4324,
199,
504,
5944,
14,
773,
14,
5885,
14,
5885,
2162,
492,
286,
4324,
2162,
199,
504,
5944,
14,
773,
14,
2232,
14,
1210,
4720,
2461,
492,
286,
3205,
4720,
2461,
199,
504,
5944,
14,
773,
14,
2232,
14,
1199,
4720,
2461,
492,
286,
2959,
4720,
2461,
199,
504,
5944,
14,
773,
14,
2232,
14,
1069,
2461,
492,
286,
11149,
199,
504,
5944,
14,
773,
14,
2087,
492,
286,
2842,
199,
504,
5944,
14,
773,
14,
1974,
492,
286,
9562,
199,
646,
1059,
199,
199,
7917,
63,
22698,
275,
283,
290,
1036,
63,
889,
63,
12227,
328,
261,
63,
957,
7,
199,
7917,
63,
2339,
275,
283,
2493,
1036,
13,
889,
13,
28360,
328,
261,
14,
957,
7,
199,
7917,
63,
15119,
275,
283,
2493,
1036,
949,
2235,
65,
328,
261,
520,
28167,
1626,
1036,
603,
621,
65,
446,
644,
978,
14,
290,
1036,
13,
889,
13,
12227,
328,
261,
14,
957,
7,
199,
199,
2632,
63,
5848,
275,
283,
1014,
921,
1544,
14,
290,
1036,
13,
889,
13,
12227,
328,
261,
14,
957,
4805,
199,
32560,
63,
10662,
840,
5372,
51,
275,
283,
1014,
921,
1544,
14,
290,
1036,
13,
889,
13,
12227,
328,
261,
14,
957,
15,
1606,
13,
1138,
2869,
8079,
14,
1360,
7,
199,
32560,
63,
24321,
2563,
275,
283,
1014,
921,
1544,
14,
290,
1036,
13,
889,
13,
12227,
328,
261,
14,
957,
15,
1606,
13,
1965,
2417,
20103,
14,
1360,
7,
199,
199,
318,
2248,
837,
272,
312,
4324,
275,
286,
4324,
342,
2286,
312,
2959,
4720,
2461,
275,
286,
2959,
4720,
2461,
342,
272,
312,
2959,
4720,
2461,
14,
26895,
360,
2124,
6417,
297,
1261,
1469,
63,
10662,
840,
5372,
51,
9,
272,
312,
4324,
14,
525,
3567,
8,
7917,
63,
22698,
12,
283,
2384,
3716,
14484,
297,
283,
2493,
29778,
297,
283,
290,
29778,
14,
4524,
297,
312,
2959,
4720,
2461,
9,
2286,
312,
2959,
4720,
2461,
275,
286,
2959,
4720,
2461,
342,
272,
312,
2959,
4720,
2461,
14,
26895,
360,
2124,
6417,
297,
1261,
1469,
63,
10662,
840,
5372,
51,
9,
272,
312,
4324,
14,
525,
3567,
8,
7917,
63,
22698,
12,
283,
2384,
17613,
297,
283,
2493,
29778,
437,
13,
58,
297,
283,
4651,
14,
4524,
297,
312,
2959,
4720,
2461,
9,
2286,
312,
2959,
4720,
2461,
275,
286,
2959,
4720,
2461,
342,
272,
312,
2959,
4720,
2461,
14,
26895,
360,
2124,
6417,
297,
1261,
1469,
63,
24321,
2563,
9,
272,
312,
4324,
14,
525,
3567,
8,
7917,
63,
22698,
12,
283,
2384,
3716,
14484,
297,
283,
2493,
29778,
17887,
706,
1253,
593,
6087,
51,
297,
283,
290,
29778,
14,
4524,
297,
312,
2959,
4720,
2461,
9,
2286,
312,
2959,
4720,
2461,
275,
286,
2959,
4720,
2461,
342,
272,
312,
2959,
4720,
2461,
14,
26895,
360,
2124,
6417,
297,
1261,
1469,
63,
24321,
2563,
9,
272,
312,
4324,
14,
525,
3567,
8,
7917,
63,
22698,
12,
283,
2384,
17613,
297,
283,
2493,
29778,
17887,
706,
1253,
593,
6087,
51,
437,
13,
58,
297,
283,
4651,
14,
4524,
297,
312,
2959,
4720,
2461,
9,
15567,
312,
4324,
14,
409,
3005,
3466,
6231,
342,
523,
199,
318,
2498,
17613,
837,
272,
312,
4324,
275,
286,
4324,
342,
272,
312,
3205,
4720,
2461,
275,
286,
3205,
4720,
2461,
342,
272,
308,
6417,
275,
312,
3205,
4720,
2461,
14,
17186,
360,
2124,
6417,
358,
2286,
312,
2959,
4720,
2461,
275,
286,
2959,
4720,
2461,
342,
272,
312,
2959,
4720,
2461,
14,
26895,
360,
2124,
6417,
297,
308,
6417,
9,
272,
312,
2959,
4720,
2461,
14,
26895,
360,
17613,
297,
20093,
272,
312,
4324,
14,
525,
3567,
8,
7917,
63,
22698,
12,
283,
2384,
3716,
14484,
17613,
297,
22608,
283,
4651,
14,
4524,
297,
312,
2959,
4720,
2461,
9,
3698,
272,
367,
284,
315,
1059,
14,
4371,
63,
26831,
26,
267,
312,
2959,
4720,
2461,
275,
286,
2959,
4720,
2461,
342,
267,
312,
2959,
4720,
2461,
14,
26895,
360,
2124,
6417,
297,
308,
6417,
9,
267,
312,
2959,
4720,
2461,
14,
26895,
360,
17613,
297,
284,
9,
267,
312,
4324,
14,
525,
3567,
8,
7917,
63,
22698,
12,
283,
2384,
3716,
14484,
17613,
297,
284,
12,
283,
4651,
14,
4524,
297,
312,
2959,
4720,
2461,
9,
267,
272,
312,
4324,
14,
409,
3005,
3466,
6231,
342,
9948,
199,
318,
2498,
3716,
14484,
17613,
837,
272,
312,
4324,
275,
286,
4324,
342,
272,
312,
3205,
4720,
2461,
275,
286,
3205,
4720,
2461,
342,
272,
308,
6417,
275,
312,
3205,
4720,
2461,
14,
17186,
360,
2124,
6417,
358,
272,
308,
17613,
275,
312,
3205,
4720,
2461,
14,
17186,
360,
17613,
358,
2286,
312,
11149,
275,
286,
11149,
8,
83,
6417,
9,
272,
308,
12957,
2714,
275,
312,
11149,
14,
1069,
7303,
272,
308,
9959,
275,
2650,
65,
4369,
628,
31204,
2807,
2924,
3449,
628,
6697,
604,
13,
3333,
26,
7829,
5326,
27,
8186,
4246,
3164,
13476,
5533,
31441,
1743,
31204,
11896,
1108,
4246,
2957,
65,
3524,
272,
312,
2842,
275,
286,
2842,
342,
272,
282,
2889,
275,
312,
2842,
14,
1122,
8,
83,
12957,
2714,
12,
308,
9959,
9,
272,
340,
334,
65,
2889,
59,
16,
61,
508,
715,
304,
267,
367,
282,
3900,
315,
282,
2889,
59,
17,
2189,
288,
340,
822,
8,
83,
17613,
13032,
16,
436,
282,
3900,
59,
17,
1055,
4142,
3430,
16,
61,
508,
308,
17613,
520,
2234,
312,
2959,
4720,
2461,
275,
286,
2959,
4720,
2461,
342,
355,
312,
2959,
4720,
2461,
14,
26895,
360,
2124,
6417,
297,
620,
8,
65,
3900,
59,
16,
2459,
355,
312,
2959,
4720,
2461,
14,
26895,
360,
83,
19088,
6888,
297,
620,
8,
65,
3900,
59,
17,
2459,
355,
312,
4324,
14,
525,
12764,
8,
7917,
63,
22698,
12,
283,
2384,
40,
736,
878,
297,
282,
3900,
59,
17,
467,
283,
290,
29778,
14,
4524,
297,
3260,
3260,
312,
2959,
4720,
2461,
9,
1467,
339,
312,
4324,
14,
409,
3005,
3466,
6231,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
project-chip/connectedhomeip
|
scripts/helpers/upload_release_asset.py
|
1
|
3692
|
#!/usr/bin/env python3
#
# Copyright (c) 2021 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import argparse
import coloredlogs
import logging
import tarfile
import github
import os
class BundleBuilder:
def __init__(self, outputName, outputPrefix, workingDirectory):
self.outputName = outputName + '.tar.xz'
self.outputPrefix = outputPrefix
self.workingDirectory = workingDirectory
logging.info('Creating bundle "%s":', self.outputName)
self.output = tarfile.open(self.outputName, 'w:xz')
def appendFile(self, name):
"""Appends the specified file in the working directory to the bundle."""
logging.info(' Appending %s to the bundle', name)
current_directory = os.path.realpath(os.curdir)
try:
os.chdir(self.workingDirectory)
self.output.add(name, os.path.join(self.outputPrefix, name))
finally:
os.chdir(current_directory)
def close(self):
"""Closes the bundle and returns the file name of the bundle."""
logging.info(' Bundle creation complete.')
self.output.close()
return self.outputName
def main():
"""Main task if executed standalone."""
parser = argparse.ArgumentParser(
description='Uploads an asset bundle file to a github release .')
parser.add_argument(
'--github-api-token',
type=str,
help='Github API token to upload the report as a comment')
parser.add_argument(
'--github-repository', type=str, help='Repository to use for PR comments')
parser.add_argument(
'--release-tag', type=str, help='Release tag to upload asset to')
parser.add_argument(
'--bundle-files',
type=str,
help='A file containing what assets to include')
parser.add_argument(
'--working-directory',
type=str,
help='What directory to use as the current directory for uploading')
parser.add_argument(
'--bundle-name', type=str, help='Prefix to use in the archive file')
parser.add_argument(
'--log-level',
default=logging.INFO,
type=lambda x: getattr(logging, x),
help='Configure the logging level.')
args = parser.parse_args()
# Ensures somewhat pretty logging of what is going on
logging.basicConfig(
level=args.log_level,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
coloredlogs.install()
if not args.github_api_token:
logging.error('Required arguments missing: github api token is required')
return
bundle = BundleBuilder(args.bundle_name, args.bundle_name,
args.working_directory)
with open(args.bundle_files, 'rt') as bundleInputs:
for fileName in bundleInputs.readlines():
bundle.appendFile(fileName.strip())
assetPath = bundle.close()
api = github.Github(args.github_api_token)
repo = api.get_repo(args.github_repository)
logging.info('Connected to github repository')
release = repo.get_release(args.release_tag)
logging.info('Release "%s" found.' % args.release_tag)
logging.info('Uploading %s', assetPath)
release.upload_asset(assetPath)
logging.info('Asset upload complete')
if __name__ == '__main__':
# execute only if run as a script
main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
3,
199,
3,
1898,
334,
67,
9,
499,
15385,
7290,
6624,
1772,
6642,
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,
199,
199,
646,
7534,
199,
646,
32076,
7270,
199,
646,
2050,
199,
646,
13608,
199,
646,
12869,
199,
646,
747,
421,
199,
533,
29311,
6437,
26,
819,
347,
636,
826,
721,
277,
12,
1072,
985,
12,
1072,
4793,
12,
6449,
6231,
304,
272,
291,
14,
1199,
985,
275,
1072,
985,
435,
1987,
5369,
14,
19196,
7,
272,
291,
14,
1199,
4793,
275,
1072,
4793,
272,
291,
14,
9818,
6231,
275,
6449,
6231,
339,
2050,
14,
815,
360,
14380,
8844,
2071,
83,
582,
297,
291,
14,
1199,
985,
9,
339,
291,
14,
1199,
275,
13608,
14,
1490,
8,
277,
14,
1199,
985,
12,
283,
87,
26,
19196,
358,
819,
347,
5666,
1173,
8,
277,
12,
536,
304,
272,
408,
2640,
3198,
314,
2013,
570,
315,
314,
6449,
2082,
370,
314,
8844,
1041,
272,
2050,
14,
815,
360,
257,
4693,
3219,
450,
83,
370,
314,
8844,
297,
536,
9,
339,
1453,
63,
3619,
275,
747,
14,
515,
14,
11091,
8,
736,
14,
15594,
9,
272,
862,
26,
489,
747,
14,
8563,
8,
277,
14,
9818,
6231,
9,
489,
291,
14,
1199,
14,
525,
8,
354,
12,
747,
14,
515,
14,
904,
8,
277,
14,
1199,
4793,
12,
536,
430,
272,
3753,
26,
489,
747,
14,
8563,
8,
1818,
63,
3619,
9,
819,
347,
4002,
8,
277,
304,
272,
408,
3337,
874,
314,
8844,
436,
2529,
314,
570,
536,
402,
314,
8844,
1041,
272,
2050,
14,
815,
360,
257,
29311,
7143,
4890,
2659,
272,
291,
14,
1199,
14,
1600,
342,
272,
372,
291,
14,
1199,
985,
421,
199,
318,
2446,
837,
523,
408,
6756,
2120,
340,
7934,
18042,
1041,
523,
1798,
275,
7534,
14,
10730,
8,
489,
1369,
534,
1721,
3640,
376,
8977,
8844,
570,
370,
282,
12869,
4683,
1275,
358,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
5031,
13,
1246,
13,
1418,
297,
489,
730,
29,
495,
12,
489,
1720,
534,
14772,
3261,
1526,
370,
5802,
314,
3622,
465,
282,
3721,
358,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
5031,
13,
8421,
297,
730,
29,
495,
12,
1720,
534,
15614,
370,
675,
367,
12218,
6786,
358,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
3221,
13,
1450,
297,
730,
29,
495,
12,
1720,
534,
9625,
1947,
370,
5802,
8977,
370,
358,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
6469,
13,
1725,
297,
489,
730,
29,
495,
12,
489,
1720,
534,
33,
570,
3035,
4052,
17202,
370,
2387,
358,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
9818,
13,
3619,
297,
489,
730,
29,
495,
12,
489,
1720,
534,
21015,
2082,
370,
675,
465,
314,
1453,
2082,
367,
24349,
358,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
6469,
13,
354,
297,
730,
29,
495,
12,
1720,
534,
4793,
370,
675,
315,
314,
6359,
570,
358,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
793,
13,
1896,
297,
489,
849,
29,
4806,
14,
4531,
12,
489,
730,
29,
2734,
671,
26,
2519,
8,
4806,
12,
671,
395,
489,
1720,
534,
17324,
314,
2050,
2166,
2659,
523,
1249,
275,
1798,
14,
1122,
63,
589,
342,
819,
327,
29652,
30362,
7268,
2050,
402,
4052,
365,
9995,
641,
523,
2050,
14,
19602,
8,
489,
2166,
29,
589,
14,
793,
63,
1896,
12,
489,
1475,
29342,
18331,
9,
83,
446,
2818,
354,
9,
83,
446,
2818,
20056,
9,
83,
446,
2818,
1188,
9,
83,
358,
523,
32076,
7270,
14,
3174,
342,
819,
340,
440,
1249,
14,
5031,
63,
1246,
63,
1418,
26,
272,
2050,
14,
705,
360,
8030,
2368,
4124,
26,
12869,
2986,
1526,
365,
1415,
358,
272,
372,
819,
8844,
275,
29311,
6437,
8,
589,
14,
6469,
63,
354,
12,
1249,
14,
6469,
63,
354,
12,
586,
1249,
14,
9818,
63,
3619,
9,
819,
543,
1551,
8,
589,
14,
6469,
63,
1725,
12,
283,
2591,
358,
465,
8844,
15124,
26,
272,
367,
18305,
315,
8844,
15124,
14,
9684,
837,
489,
8844,
14,
740,
1173,
8,
15450,
14,
1913,
1012,
819,
8977,
2042,
275,
8844,
14,
1600,
342,
819,
2986,
275,
12869,
14,
14772,
8,
589,
14,
5031,
63,
1246,
63,
1418,
9,
523,
3831,
275,
2986,
14,
362,
63,
3417,
8,
589,
14,
5031,
63,
8421,
9,
819,
2050,
14,
815,
360,
16382,
370,
12869,
7611,
358,
819,
4683,
275,
3831,
14,
362,
63,
3221,
8,
589,
14,
3221,
63,
1450,
9,
523,
2050,
14,
815,
360,
9625,
2071,
83,
2,
1911,
3530,
450,
1249,
14,
3221,
63,
1450,
9,
819,
2050,
14,
815,
360,
1721,
8786,
450,
83,
297,
8977,
2042,
9,
523,
4683,
14,
5064,
63,
6562,
8,
6562,
2042,
9,
523,
2050,
14,
815,
360,
19979,
5802,
4890,
358,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
327,
5341,
1454,
340,
1255,
465,
282,
2884,
523,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
3,
199,
3,
1898,
334,
67,
9,
499,
15385,
7290,
6624,
1772,
6642,
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,
199,
199,
646,
7534,
199,
646,
32076,
7270,
199,
646,
2050,
199,
646,
13608,
199,
646,
12869,
199,
646,
747,
421,
199,
533,
29311,
6437,
26,
819,
347,
636,
826,
721,
277,
12,
1072,
985,
12,
1072,
4793,
12,
6449,
6231,
304,
272,
291,
14,
1199,
985,
275,
1072,
985,
435,
1987,
5369,
14,
19196,
7,
272,
291,
14,
1199,
4793,
275,
1072,
4793,
272,
291,
14,
9818,
6231,
275,
6449,
6231,
339,
2050,
14,
815,
360,
14380,
8844,
2071,
83,
582,
297,
291,
14,
1199,
985,
9,
339,
291,
14,
1199,
275,
13608,
14,
1490,
8,
277,
14,
1199,
985,
12,
283,
87,
26,
19196,
358,
819,
347,
5666,
1173,
8,
277,
12,
536,
304,
272,
408,
2640,
3198,
314,
2013,
570,
315,
314,
6449,
2082,
370,
314,
8844,
1041,
272,
2050,
14,
815,
360,
257,
4693,
3219,
450,
83,
370,
314,
8844,
297,
536,
9,
339,
1453,
63,
3619,
275,
747,
14,
515,
14,
11091,
8,
736,
14,
15594,
9,
272,
862,
26,
489,
747,
14,
8563,
8,
277,
14,
9818,
6231,
9,
489,
291,
14,
1199,
14,
525,
8,
354,
12,
747,
14,
515,
14,
904,
8,
277,
14,
1199,
4793,
12,
536,
430,
272,
3753,
26,
489,
747,
14,
8563,
8,
1818,
63,
3619,
9,
819,
347,
4002,
8,
277,
304,
272,
408,
3337,
874,
314,
8844,
436,
2529,
314,
570,
536,
402,
314,
8844,
1041,
272,
2050,
14,
815,
360,
257,
29311,
7143,
4890,
2659,
272,
291,
14,
1199,
14,
1600,
342,
272,
372,
291,
14,
1199,
985,
421,
199,
318,
2446,
837,
523,
408,
6756,
2120,
340,
7934,
18042,
1041,
523,
1798,
275,
7534,
14,
10730,
8,
489,
1369,
534,
1721,
3640,
376,
8977,
8844,
570,
370,
282,
12869,
4683,
1275,
358,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
5031,
13,
1246,
13,
1418,
297,
489,
730,
29,
495,
12,
489,
1720,
534,
14772,
3261,
1526,
370,
5802,
314,
3622,
465,
282,
3721,
358,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
5031,
13,
8421,
297,
730,
29,
495,
12,
1720,
534,
15614,
370,
675,
367,
12218,
6786,
358,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
3221,
13,
1450,
297,
730,
29,
495,
12,
1720,
534,
9625,
1947,
370,
5802,
8977,
370,
358,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
6469,
13,
1725,
297,
489,
730,
29,
495,
12,
489,
1720,
534,
33,
570,
3035,
4052,
17202,
370,
2387,
358,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
9818,
13,
3619,
297,
489,
730,
29,
495,
12,
489,
1720,
534,
21015,
2082,
370,
675,
465,
314,
1453,
2082,
367,
24349,
358,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
6469,
13,
354,
297,
730,
29,
495,
12,
1720,
534,
4793,
370,
675,
315,
314,
6359,
570,
358,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
793,
13,
1896,
297,
489,
849,
29,
4806,
14,
4531,
12,
489,
730,
29,
2734,
671,
26,
2519,
8,
4806,
12,
671,
395,
489,
1720,
534,
17324,
314,
2050,
2166,
2659,
523,
1249,
275,
1798,
14,
1122,
63,
589,
342,
819,
327,
29652,
30362,
7268,
2050,
402,
4052,
365,
9995,
641,
523,
2050,
14,
19602,
8,
489,
2166,
29,
589,
14,
793,
63,
1896,
12,
489,
1475,
29342,
18331,
9,
83,
446,
2818,
354,
9,
83,
446,
2818,
20056,
9,
83,
446,
2818,
1188,
9,
83,
358,
523,
32076,
7270,
14,
3174,
342,
819,
340,
440,
1249,
14,
5031,
63,
1246,
63,
1418,
26,
272,
2050,
14,
705,
360,
8030,
2368,
4124,
26,
12869,
2986,
1526,
365,
1415,
358,
272,
372,
819,
8844,
275,
29311,
6437,
8,
589,
14,
6469,
63,
354,
12,
1249,
14,
6469,
63,
354,
12,
586,
1249,
14,
9818,
63,
3619,
9,
819,
543,
1551,
8,
589,
14,
6469,
63,
1725,
12,
283,
2591,
358,
465,
8844,
15124,
26,
272,
367,
18305,
315,
8844,
15124,
14,
9684,
837,
489,
8844,
14,
740,
1173,
8,
15450,
14,
1913,
1012,
819,
8977,
2042,
275,
8844,
14,
1600,
342,
819,
2986,
275,
12869,
14,
14772,
8,
589,
14,
5031,
63,
1246,
63,
1418,
9,
523,
3831,
275,
2986,
14,
362,
63,
3417,
8,
589,
14,
5031,
63,
8421,
9,
819,
2050,
14,
815,
360,
16382,
370,
12869,
7611,
358,
819,
4683,
275,
3831,
14,
362,
63,
3221,
8,
589,
14,
3221,
63,
1450,
9,
523,
2050,
14,
815,
360,
9625,
2071,
83,
2,
1911,
3530,
450,
1249,
14,
3221,
63,
1450,
9,
819,
2050,
14,
815,
360,
1721,
8786,
450,
83,
297,
8977,
2042,
9,
523,
4683,
14,
5064,
63,
6562,
8,
6562,
2042,
9,
523,
2050,
14,
815,
360,
19979,
5802,
4890,
358,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
327,
5341,
1454,
340,
1255,
465,
282,
2884,
523,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
overtherain/scriptfile
|
software/googleAppEngine/lib/django_1_2/django/core/cache/backends/db.py
|
46
|
5954
|
"Database cache backend."
from django.core.cache.backends.base import BaseCache
from django.db import connections, router, transaction, DatabaseError
import base64, time
from datetime import datetime
try:
import cPickle as pickle
except ImportError:
import pickle
class Options(object):
"""A class that will quack like a Django model _meta class.
This allows cache operations to be controlled by the router
"""
def __init__(self, table):
self.db_table = table
self.app_label = 'django_cache'
self.module_name = 'cacheentry'
self.verbose_name = 'cache entry'
self.verbose_name_plural = 'cache entries'
self.object_name = 'CacheEntry'
self.abstract = False
self.managed = True
self.proxy = False
class CacheClass(BaseCache):
def __init__(self, table, params):
BaseCache.__init__(self, params)
self._table = table
class CacheEntry(object):
_meta = Options(table)
self.cache_model_class = CacheEntry
max_entries = params.get('max_entries', 300)
try:
self._max_entries = int(max_entries)
except (ValueError, TypeError):
self._max_entries = 300
cull_frequency = params.get('cull_frequency', 3)
try:
self._cull_frequency = int(cull_frequency)
except (ValueError, TypeError):
self._cull_frequency = 3
def get(self, key, default=None):
self.validate_key(key)
db = router.db_for_read(self.cache_model_class)
table = connections[db].ops.quote_name(self._table)
cursor = connections[db].cursor()
cursor.execute("SELECT cache_key, value, expires FROM %s WHERE cache_key = %%s" % table, [key])
row = cursor.fetchone()
if row is None:
return default
now = datetime.now()
if row[2] < now:
db = router.db_for_write(self.cache_model_class)
cursor = connections[db].cursor()
cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key])
transaction.commit_unless_managed(using=db)
return default
value = connections[db].ops.process_clob(row[1])
return pickle.loads(base64.decodestring(value))
def set(self, key, value, timeout=None):
self.validate_key(key)
self._base_set('set', key, value, timeout)
def add(self, key, value, timeout=None):
self.validate_key(key)
return self._base_set('add', key, value, timeout)
def _base_set(self, mode, key, value, timeout=None):
if timeout is None:
timeout = self.default_timeout
db = router.db_for_write(self.cache_model_class)
table = connections[db].ops.quote_name(self._table)
cursor = connections[db].cursor()
cursor.execute("SELECT COUNT(*) FROM %s" % table)
num = cursor.fetchone()[0]
now = datetime.now().replace(microsecond=0)
exp = datetime.fromtimestamp(time.time() + timeout).replace(microsecond=0)
if num > self._max_entries:
self._cull(db, cursor, now)
encoded = base64.encodestring(pickle.dumps(value, 2)).strip()
cursor.execute("SELECT cache_key, expires FROM %s WHERE cache_key = %%s" % table, [key])
try:
result = cursor.fetchone()
if result and (mode == 'set' or
(mode == 'add' and result[1] < now)):
cursor.execute("UPDATE %s SET value = %%s, expires = %%s WHERE cache_key = %%s" % table,
[encoded, connections[db].ops.value_to_db_datetime(exp), key])
else:
cursor.execute("INSERT INTO %s (cache_key, value, expires) VALUES (%%s, %%s, %%s)" % table,
[key, encoded, connections[db].ops.value_to_db_datetime(exp)])
except DatabaseError:
# To be threadsafe, updates/inserts are allowed to fail silently
transaction.rollback_unless_managed(using=db)
return False
else:
transaction.commit_unless_managed(using=db)
return True
def delete(self, key):
self.validate_key(key)
db = router.db_for_write(self.cache_model_class)
table = connections[db].ops.quote_name(self._table)
cursor = connections[db].cursor()
cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key])
transaction.commit_unless_managed(using=db)
def has_key(self, key):
self.validate_key(key)
db = router.db_for_read(self.cache_model_class)
table = connections[db].ops.quote_name(self._table)
cursor = connections[db].cursor()
now = datetime.now().replace(microsecond=0)
cursor.execute("SELECT cache_key FROM %s WHERE cache_key = %%s and expires > %%s" % table,
[key, connections[db].ops.value_to_db_datetime(now)])
return cursor.fetchone() is not None
def _cull(self, db, cursor, now):
if self._cull_frequency == 0:
self.clear()
else:
table = connections[db].ops.quote_name(self._table)
cursor.execute("DELETE FROM %s WHERE expires < %%s" % table,
[connections[db].ops.value_to_db_datetime(now)])
cursor.execute("SELECT COUNT(*) FROM %s" % table)
num = cursor.fetchone()[0]
if num > self._max_entries:
cursor.execute("SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s" % table, [num / self._cull_frequency])
cursor.execute("DELETE FROM %s WHERE cache_key < %%s" % table, [cursor.fetchone()[0]])
def clear(self):
db = router.db_for_write(self.cache_model_class)
table = connections[db].ops.quote_name(self._table)
cursor = connections[db].cursor()
cursor.execute('DELETE FROM %s' % table)
|
mit
|
[
2,
7243,
2581,
4865,
2122,
199,
199,
504,
1639,
14,
1018,
14,
1637,
14,
7765,
14,
1095,
492,
3523,
4437,
199,
504,
1639,
14,
697,
492,
6947,
12,
6197,
12,
6008,
12,
27728,
199,
646,
1300,
772,
12,
900,
199,
504,
2197,
492,
2197,
199,
893,
26,
272,
492,
17572,
465,
5927,
199,
2590,
3545,
26,
272,
492,
5927,
199,
199,
533,
8394,
8,
785,
304,
272,
408,
33,
1021,
626,
911,
2173,
564,
2839,
282,
5634,
1402,
485,
2024,
1021,
14,
339,
961,
6127,
2581,
5331,
370,
506,
22284,
701,
314,
6197,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1817,
304,
267,
291,
14,
697,
63,
1224,
275,
1817,
267,
291,
14,
571,
63,
1302,
275,
283,
1176,
63,
1637,
7,
267,
291,
14,
578,
63,
354,
275,
283,
1637,
2373,
7,
267,
291,
14,
3832,
63,
354,
275,
283,
1637,
2397,
7,
267,
291,
14,
3832,
63,
354,
63,
10019,
275,
283,
1637,
4811,
7,
267,
291,
14,
785,
63,
354,
275,
221,
283,
4437,
3900,
7,
267,
291,
14,
6198,
275,
756,
267,
291,
14,
11122,
275,
715,
267,
291,
14,
3280,
275,
756,
199,
199,
533,
11977,
2543,
8,
1563,
4437,
304,
272,
347,
636,
826,
721,
277,
12,
1817,
12,
1862,
304,
267,
3523,
4437,
855,
826,
721,
277,
12,
1862,
9,
267,
291,
423,
1224,
275,
1817,
398,
1021,
11977,
3900,
8,
785,
304,
288,
485,
2024,
275,
8394,
8,
1224,
9,
267,
291,
14,
1637,
63,
1238,
63,
533,
275,
11977,
3900,
398,
1390,
63,
3189,
275,
1862,
14,
362,
360,
988,
63,
3189,
297,
9601,
9,
267,
862,
26,
288,
291,
423,
988,
63,
3189,
275,
1109,
8,
988,
63,
3189,
9,
267,
871,
334,
3393,
12,
3146,
304,
288,
291,
423,
988,
63,
3189,
275,
9601,
267,
286,
979,
63,
11132,
275,
1862,
14,
362,
360,
67,
979,
63,
11132,
297,
650,
9,
267,
862,
26,
288,
291,
423,
67,
979,
63,
11132,
275,
1109,
8,
67,
979,
63,
11132,
9,
267,
871,
334,
3393,
12,
3146,
304,
288,
291,
423,
67,
979,
63,
11132,
275,
650,
339,
347,
664,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
291,
14,
3502,
63,
498,
8,
498,
9,
267,
1592,
275,
6197,
14,
697,
63,
509,
63,
739,
8,
277,
14,
1637,
63,
1238,
63,
533,
9,
267,
1817,
275,
6947,
59,
697,
1055,
1483,
14,
3513,
63,
354,
8,
277,
423,
1224,
9,
267,
3920,
275,
6947,
59,
697,
1055,
3937,
342,
398,
3920,
14,
2526,
480,
4859,
2581,
63,
498,
12,
574,
12,
12261,
4442,
450,
83,
6038,
2581,
63,
498,
275,
11539,
83,
2,
450,
1817,
12,
359,
498,
566,
267,
1962,
275,
3920,
14,
11591,
342,
267,
340,
1962,
365,
488,
26,
288,
372,
849,
267,
3063,
275,
2197,
14,
2131,
342,
267,
340,
1962,
59,
18,
61,
665,
3063,
26,
288,
1592,
275,
6197,
14,
697,
63,
509,
63,
952,
8,
277,
14,
1637,
63,
1238,
63,
533,
9,
288,
3920,
275,
6947,
59,
697,
1055,
3937,
342,
288,
3920,
14,
2526,
480,
7014,
4442,
450,
83,
6038,
2581,
63,
498,
275,
11539,
83,
2,
450,
1817,
12,
359,
498,
566,
288,
6008,
14,
3543,
63,
18447,
63,
11122,
8,
4941,
29,
697,
9,
288,
372,
849,
267,
574,
275,
6947,
59,
697,
1055,
1483,
14,
1412,
63,
67,
1191,
8,
1143,
59,
17,
566,
267,
372,
5927,
14,
3640,
8,
1095,
772,
14,
2708,
875,
8,
585,
430,
339,
347,
663,
8,
277,
12,
790,
12,
574,
12,
2653,
29,
403,
304,
267,
291,
14,
3502,
63,
498,
8,
498,
9,
267,
291,
423,
1095,
63,
409,
360,
409,
297,
790,
12,
574,
12,
2653,
9,
339,
347,
1050,
8,
277,
12,
790,
12,
574,
12,
2653,
29,
403,
304,
267,
291,
14,
3502,
63,
498,
8,
498,
9,
267,
372,
291,
423,
1095,
63,
409,
360,
525,
297,
790,
12,
574,
12,
2653,
9,
339,
347,
485,
1095,
63,
409,
8,
277,
12,
818,
12,
790,
12,
574,
12,
2653,
29,
403,
304,
267,
340,
2653,
365,
488,
26,
288,
2653,
275,
291,
14,
885,
63,
2593,
267,
1592,
275,
6197,
14,
697,
63,
509,
63,
952,
8,
277,
14,
1637,
63,
1238,
63,
533,
9,
267,
1817,
275,
6947,
59,
697,
1055,
1483,
14,
3513,
63,
354,
8,
277,
423,
1224,
9,
267,
3920,
275,
6947,
59,
697,
1055,
3937,
342,
398,
3920,
14,
2526,
480,
4859,
24903,
21565,
4442,
450,
83,
2,
450,
1817,
9,
267,
1967,
275,
3920,
14,
11591,
3430,
16,
61,
267,
3063,
275,
2197,
14,
2131,
1252,
1814,
8,
16627,
29,
16,
9,
267,
1437,
275,
2197,
14,
18531,
8,
521,
14,
521,
342,
435,
2653,
680,
1814,
8,
16627,
29,
16,
9,
267,
340,
1967,
690,
291,
423,
988,
63,
3189,
26,
288,
291,
423,
67,
979,
8,
697,
12,
3920,
12,
3063,
9,
267,
5737,
275,
1300,
772,
14,
2143,
875,
8,
8092,
14,
4180,
8,
585,
12,
499,
4992,
1913,
342,
267,
3920,
14,
2526,
480,
4859,
2581,
63,
498,
12,
12261,
4442,
450,
83,
6038,
2581,
63,
498,
275,
11539,
83,
2,
450,
1817,
12,
359,
498,
566,
267,
862,
26,
288,
754,
275,
3920,
14,
11591,
342,
288,
340,
754,
436,
334,
632,
508,
283,
409,
7,
503,
490,
334,
632,
508,
283,
525,
7,
436,
754,
59,
17,
61,
665,
3063,
2298,
355,
3920,
14,
2526,
480,
10383,
450,
83,
11543,
574,
275,
11539,
83,
12,
12261,
275,
11539,
83,
6038,
2581,
63,
498,
275,
11539,
83,
2,
450,
1817,
12,
3044,
359,
8167,
12,
6947,
59,
697,
1055,
1483,
14,
585,
63,
475,
63,
697,
63,
2083,
8,
1474,
395,
790,
566,
288,
587,
26,
355,
3920,
14,
2526,
480,
10258,
12872,
450,
83,
334,
1637,
63,
498,
12,
574,
12,
12261,
9,
13992,
4366,
5,
83,
12,
11539,
83,
12,
11539,
83,
2924,
450,
1817,
12,
3044,
359,
498,
12,
5737,
12,
6947,
59,
697,
1055,
1483,
14,
585,
63,
475,
63,
697,
63,
2083,
8,
1474,
3948,
267,
871,
27728,
26,
288,
327,
4005,
506,
2462,
3489,
12,
7029,
15,
3176,
83,
787,
4370,
370,
2449,
18030,
288,
6008,
14,
10437
] |
[
7243,
2581,
4865,
2122,
199,
199,
504,
1639,
14,
1018,
14,
1637,
14,
7765,
14,
1095,
492,
3523,
4437,
199,
504,
1639,
14,
697,
492,
6947,
12,
6197,
12,
6008,
12,
27728,
199,
646,
1300,
772,
12,
900,
199,
504,
2197,
492,
2197,
199,
893,
26,
272,
492,
17572,
465,
5927,
199,
2590,
3545,
26,
272,
492,
5927,
199,
199,
533,
8394,
8,
785,
304,
272,
408,
33,
1021,
626,
911,
2173,
564,
2839,
282,
5634,
1402,
485,
2024,
1021,
14,
339,
961,
6127,
2581,
5331,
370,
506,
22284,
701,
314,
6197,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1817,
304,
267,
291,
14,
697,
63,
1224,
275,
1817,
267,
291,
14,
571,
63,
1302,
275,
283,
1176,
63,
1637,
7,
267,
291,
14,
578,
63,
354,
275,
283,
1637,
2373,
7,
267,
291,
14,
3832,
63,
354,
275,
283,
1637,
2397,
7,
267,
291,
14,
3832,
63,
354,
63,
10019,
275,
283,
1637,
4811,
7,
267,
291,
14,
785,
63,
354,
275,
221,
283,
4437,
3900,
7,
267,
291,
14,
6198,
275,
756,
267,
291,
14,
11122,
275,
715,
267,
291,
14,
3280,
275,
756,
199,
199,
533,
11977,
2543,
8,
1563,
4437,
304,
272,
347,
636,
826,
721,
277,
12,
1817,
12,
1862,
304,
267,
3523,
4437,
855,
826,
721,
277,
12,
1862,
9,
267,
291,
423,
1224,
275,
1817,
398,
1021,
11977,
3900,
8,
785,
304,
288,
485,
2024,
275,
8394,
8,
1224,
9,
267,
291,
14,
1637,
63,
1238,
63,
533,
275,
11977,
3900,
398,
1390,
63,
3189,
275,
1862,
14,
362,
360,
988,
63,
3189,
297,
9601,
9,
267,
862,
26,
288,
291,
423,
988,
63,
3189,
275,
1109,
8,
988,
63,
3189,
9,
267,
871,
334,
3393,
12,
3146,
304,
288,
291,
423,
988,
63,
3189,
275,
9601,
267,
286,
979,
63,
11132,
275,
1862,
14,
362,
360,
67,
979,
63,
11132,
297,
650,
9,
267,
862,
26,
288,
291,
423,
67,
979,
63,
11132,
275,
1109,
8,
67,
979,
63,
11132,
9,
267,
871,
334,
3393,
12,
3146,
304,
288,
291,
423,
67,
979,
63,
11132,
275,
650,
339,
347,
664,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
291,
14,
3502,
63,
498,
8,
498,
9,
267,
1592,
275,
6197,
14,
697,
63,
509,
63,
739,
8,
277,
14,
1637,
63,
1238,
63,
533,
9,
267,
1817,
275,
6947,
59,
697,
1055,
1483,
14,
3513,
63,
354,
8,
277,
423,
1224,
9,
267,
3920,
275,
6947,
59,
697,
1055,
3937,
342,
398,
3920,
14,
2526,
480,
4859,
2581,
63,
498,
12,
574,
12,
12261,
4442,
450,
83,
6038,
2581,
63,
498,
275,
11539,
83,
2,
450,
1817,
12,
359,
498,
566,
267,
1962,
275,
3920,
14,
11591,
342,
267,
340,
1962,
365,
488,
26,
288,
372,
849,
267,
3063,
275,
2197,
14,
2131,
342,
267,
340,
1962,
59,
18,
61,
665,
3063,
26,
288,
1592,
275,
6197,
14,
697,
63,
509,
63,
952,
8,
277,
14,
1637,
63,
1238,
63,
533,
9,
288,
3920,
275,
6947,
59,
697,
1055,
3937,
342,
288,
3920,
14,
2526,
480,
7014,
4442,
450,
83,
6038,
2581,
63,
498,
275,
11539,
83,
2,
450,
1817,
12,
359,
498,
566,
288,
6008,
14,
3543,
63,
18447,
63,
11122,
8,
4941,
29,
697,
9,
288,
372,
849,
267,
574,
275,
6947,
59,
697,
1055,
1483,
14,
1412,
63,
67,
1191,
8,
1143,
59,
17,
566,
267,
372,
5927,
14,
3640,
8,
1095,
772,
14,
2708,
875,
8,
585,
430,
339,
347,
663,
8,
277,
12,
790,
12,
574,
12,
2653,
29,
403,
304,
267,
291,
14,
3502,
63,
498,
8,
498,
9,
267,
291,
423,
1095,
63,
409,
360,
409,
297,
790,
12,
574,
12,
2653,
9,
339,
347,
1050,
8,
277,
12,
790,
12,
574,
12,
2653,
29,
403,
304,
267,
291,
14,
3502,
63,
498,
8,
498,
9,
267,
372,
291,
423,
1095,
63,
409,
360,
525,
297,
790,
12,
574,
12,
2653,
9,
339,
347,
485,
1095,
63,
409,
8,
277,
12,
818,
12,
790,
12,
574,
12,
2653,
29,
403,
304,
267,
340,
2653,
365,
488,
26,
288,
2653,
275,
291,
14,
885,
63,
2593,
267,
1592,
275,
6197,
14,
697,
63,
509,
63,
952,
8,
277,
14,
1637,
63,
1238,
63,
533,
9,
267,
1817,
275,
6947,
59,
697,
1055,
1483,
14,
3513,
63,
354,
8,
277,
423,
1224,
9,
267,
3920,
275,
6947,
59,
697,
1055,
3937,
342,
398,
3920,
14,
2526,
480,
4859,
24903,
21565,
4442,
450,
83,
2,
450,
1817,
9,
267,
1967,
275,
3920,
14,
11591,
3430,
16,
61,
267,
3063,
275,
2197,
14,
2131,
1252,
1814,
8,
16627,
29,
16,
9,
267,
1437,
275,
2197,
14,
18531,
8,
521,
14,
521,
342,
435,
2653,
680,
1814,
8,
16627,
29,
16,
9,
267,
340,
1967,
690,
291,
423,
988,
63,
3189,
26,
288,
291,
423,
67,
979,
8,
697,
12,
3920,
12,
3063,
9,
267,
5737,
275,
1300,
772,
14,
2143,
875,
8,
8092,
14,
4180,
8,
585,
12,
499,
4992,
1913,
342,
267,
3920,
14,
2526,
480,
4859,
2581,
63,
498,
12,
12261,
4442,
450,
83,
6038,
2581,
63,
498,
275,
11539,
83,
2,
450,
1817,
12,
359,
498,
566,
267,
862,
26,
288,
754,
275,
3920,
14,
11591,
342,
288,
340,
754,
436,
334,
632,
508,
283,
409,
7,
503,
490,
334,
632,
508,
283,
525,
7,
436,
754,
59,
17,
61,
665,
3063,
2298,
355,
3920,
14,
2526,
480,
10383,
450,
83,
11543,
574,
275,
11539,
83,
12,
12261,
275,
11539,
83,
6038,
2581,
63,
498,
275,
11539,
83,
2,
450,
1817,
12,
3044,
359,
8167,
12,
6947,
59,
697,
1055,
1483,
14,
585,
63,
475,
63,
697,
63,
2083,
8,
1474,
395,
790,
566,
288,
587,
26,
355,
3920,
14,
2526,
480,
10258,
12872,
450,
83,
334,
1637,
63,
498,
12,
574,
12,
12261,
9,
13992,
4366,
5,
83,
12,
11539,
83,
12,
11539,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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
] |
eahneahn/free
|
lib/python2.7/site-packages/setuptools-2.1-py2.7.egg/setuptools/tests/test_test.py
|
286
|
3710
|
# -*- coding: UTF-8 -*-
"""develop tests
"""
import sys
import os, shutil, tempfile, unittest
import tempfile
import site
from distutils.errors import DistutilsError
from setuptools.compat import StringIO
from setuptools.command.test import test
from setuptools.command import easy_install as easy_install_pkg
from setuptools.dist import Distribution
SETUP_PY = """\
from setuptools import setup
setup(name='foo',
packages=['name', 'name.space', 'name.space.tests'],
namespace_packages=['name'],
test_suite='name.space.tests.test_suite',
)
"""
NS_INIT = """# -*- coding: Latin-1 -*-
# Söme Arbiträry Ünicode to test Issüé 310
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
"""
# Make sure this is Latin-1 binary, before writing:
if sys.version_info < (3,):
NS_INIT = NS_INIT.decode('UTF-8')
NS_INIT = NS_INIT.encode('Latin-1')
TEST_PY = """import unittest
class TestTest(unittest.TestCase):
def test_test(self):
print "Foo" # Should fail under Python 3 unless 2to3 is used
test_suite = unittest.makeSuite(TestTest)
"""
class TestTestTest(unittest.TestCase):
def setUp(self):
if sys.version < "2.6" or hasattr(sys, 'real_prefix'):
return
# Directory structure
self.dir = tempfile.mkdtemp()
os.mkdir(os.path.join(self.dir, 'name'))
os.mkdir(os.path.join(self.dir, 'name', 'space'))
os.mkdir(os.path.join(self.dir, 'name', 'space', 'tests'))
# setup.py
setup = os.path.join(self.dir, 'setup.py')
f = open(setup, 'wt')
f.write(SETUP_PY)
f.close()
self.old_cwd = os.getcwd()
# name/__init__.py
init = os.path.join(self.dir, 'name', '__init__.py')
f = open(init, 'wb')
f.write(NS_INIT)
f.close()
# name/space/__init__.py
init = os.path.join(self.dir, 'name', 'space', '__init__.py')
f = open(init, 'wt')
f.write('#empty\n')
f.close()
# name/space/tests/__init__.py
init = os.path.join(self.dir, 'name', 'space', 'tests', '__init__.py')
f = open(init, 'wt')
f.write(TEST_PY)
f.close()
os.chdir(self.dir)
self.old_base = site.USER_BASE
site.USER_BASE = tempfile.mkdtemp()
self.old_site = site.USER_SITE
site.USER_SITE = tempfile.mkdtemp()
def tearDown(self):
if sys.version < "2.6" or hasattr(sys, 'real_prefix'):
return
os.chdir(self.old_cwd)
shutil.rmtree(self.dir)
shutil.rmtree(site.USER_BASE)
shutil.rmtree(site.USER_SITE)
site.USER_BASE = self.old_base
site.USER_SITE = self.old_site
def test_test(self):
if sys.version < "2.6" or hasattr(sys, 'real_prefix'):
return
dist = Distribution(dict(
name='foo',
packages=['name', 'name.space', 'name.space.tests'],
namespace_packages=['name'],
test_suite='name.space.tests.test_suite',
use_2to3=True,
))
dist.script_name = 'setup.py'
cmd = test(dist)
cmd.user = 1
cmd.ensure_finalized()
cmd.install_dir = site.USER_SITE
cmd.user = 1
old_stdout = sys.stdout
sys.stdout = StringIO()
try:
try: # try/except/finally doesn't work in Python 2.4, so we need nested try-statements.
cmd.run()
except SystemExit: # The test runner calls sys.exit, stop that making an error.
pass
finally:
sys.stdout = old_stdout
|
agpl-3.0
|
[
3,
1882,
2803,
26,
9094,
13,
24,
1882,
199,
199,
624,
32176,
2295,
199,
624,
199,
646,
984,
199,
646,
747,
12,
5145,
12,
5549,
12,
2882,
199,
646,
5549,
199,
646,
4770,
199,
199,
504,
7065,
14,
2550,
492,
12577,
547,
199,
504,
9116,
14,
5819,
492,
5228,
199,
504,
9116,
14,
1531,
14,
396,
492,
511,
199,
504,
9116,
14,
1531,
492,
8837,
63,
3174,
465,
8837,
63,
3174,
63,
4600,
199,
504,
9116,
14,
2686,
492,
11839,
199,
199,
20836,
63,
4521,
275,
9638,
199,
504,
9116,
492,
3272,
199,
199,
2758,
8,
354,
534,
1421,
297,
272,
6117,
2968,
354,
297,
283,
354,
14,
2638,
297,
283,
354,
14,
2638,
14,
2219,
995,
272,
3231,
63,
5154,
2968,
354,
995,
272,
511,
63,
5768,
534,
354,
14,
2638,
14,
2219,
14,
396,
63,
5768,
297,
199,
9,
199,
624,
199,
199,
2709,
63,
8727,
275,
408,
3,
1882,
2803,
26,
23864,
13,
17,
1882,
199,
3,
428,
14614,
278,
1952,
2075,
82,
13733,
651,
13333,
251,
78,
1525,
370,
511,
473,
385,
17709,
5741,
650,
709,
199,
893,
26,
272,
636,
646,
19734,
4600,
63,
4435,
1959,
16536,
63,
3251,
3460,
354,
3368,
199,
2590,
3545,
26,
272,
687,
28728,
492,
12247,
63,
515,
272,
636,
515,
363,
275,
12247,
63,
515,
3460,
515,
3108,
636,
354,
3368,
199,
624,
199,
3,
4155,
3238,
642,
365,
23864,
13,
17,
3366,
12,
2544,
3575,
26,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
19,
16095,
272,
9380,
63,
8727,
275,
9380,
63,
8727,
14,
2708,
360,
6610,
13,
24,
358,
199,
2709,
63,
8727,
275,
9380,
63,
8727,
14,
2143,
360,
27317,
13,
17,
358,
199,
199,
2864,
63,
4521,
275,
408,
646,
2882,
199,
199,
533,
1379,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
396,
8,
277,
304,
267,
870,
298,
5686,
2,
327,
7719,
2449,
1334,
2018,
650,
7444,
499,
475,
19,
365,
1202,
199,
199,
396,
63,
5768,
275,
2882,
14,
18275,
8,
774,
774,
9,
199,
624,
199,
199,
533,
1379,
774,
774,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
340,
984,
14,
1023,
665,
298,
18,
14,
22,
2,
503,
2688,
8,
1274,
12,
283,
3093,
63,
1861,
735,
288,
372,
398,
327,
15191,
5523,
267,
291,
14,
694,
275,
5549,
14,
11983,
342,
267,
747,
14,
8215,
8,
736,
14,
515,
14,
904,
8,
277,
14,
694,
12,
283,
354,
1333,
267,
747,
14,
8215,
8,
736,
14,
515,
14,
904,
8,
277,
14,
694,
12,
283,
354,
297,
283,
2638,
1333,
267,
747,
14,
8215,
8,
736,
14,
515,
14,
904,
8,
277,
14,
694,
12,
283,
354,
297,
283,
2638,
297,
283,
2219,
1333,
267,
327,
3272,
14,
647,
267,
3272,
275,
747,
14,
515,
14,
904,
8,
277,
14,
694,
12,
283,
2758,
14,
647,
358,
267,
289,
275,
1551,
8,
2758,
12,
283,
9115,
358,
267,
289,
14,
952,
8,
20836,
63,
4521,
9,
267,
289,
14,
1600,
342,
267,
291,
14,
1753,
63,
6525,
275,
747,
14,
9458,
342,
267,
327,
536,
22128,
826,
4343,
647,
267,
4205,
275,
747,
14,
515,
14,
904,
8,
277,
14,
694,
12,
283,
354,
297,
2560,
826,
4343,
647,
358,
267,
289,
275,
1551,
8,
826,
12,
283,
6603,
358,
267,
289,
14,
952,
8,
2709,
63,
8727,
9,
267,
289,
14,
1600,
342,
267,
327,
536,
15,
2638,
22128,
826,
4343,
647,
267,
4205,
275,
747,
14,
515,
14,
904,
8,
277,
14,
694,
12,
283,
354,
297,
283,
2638,
297,
2560,
826,
4343,
647,
358,
267,
289,
275,
1551,
8,
826,
12,
283,
9115,
358,
267,
289,
14,
952,
7863,
1667,
60,
78,
358,
267,
289,
14,
1600,
342,
267,
327,
536,
15,
2638,
15,
2219,
22128,
826,
4343,
647,
267,
4205,
275,
747,
14,
515,
14,
904,
8,
277,
14,
694,
12,
283,
354,
297,
283,
2638,
297,
283,
2219,
297,
2560,
826,
4343,
647,
358,
267,
289,
275,
1551,
8,
826,
12,
283,
9115,
358,
267,
289,
14,
952,
8,
2864,
63,
4521,
9,
267,
289,
14,
1600,
342,
398,
747,
14,
8563,
8,
277,
14,
694,
9,
267,
291,
14,
1753,
63,
1095,
275,
4770,
14,
3791,
63,
5825,
267,
4770,
14,
3791,
63,
5825,
275,
5549,
14,
11983,
342,
267,
291,
14,
1753,
63,
2124,
275,
4770,
14,
3791,
63,
7917,
267,
4770,
14,
3791,
63,
7917,
275,
5549,
14,
11983,
342,
339,
347,
6766,
8,
277,
304,
267,
340,
984,
14,
1023,
665,
298,
18,
14,
22,
2,
503,
2688,
8,
1274,
12,
283,
3093,
63,
1861,
735,
288,
372,
398,
747,
14,
8563,
8,
277,
14,
1753,
63,
6525,
9,
267,
5145,
14,
9242,
8,
277,
14,
694,
9,
267,
5145,
14,
9242,
8,
2124,
14,
3791,
63,
5825,
9,
267,
5145,
14,
9242,
8,
2124,
14,
3791,
63,
7917,
9,
267,
4770,
14,
3791,
63,
5825,
275,
291,
14,
1753,
63,
1095,
267,
4770,
14,
3791,
63,
7917,
275,
291,
14,
1753,
63,
2124,
339,
347,
511,
63,
396,
8,
277,
304,
267,
340,
984,
14,
1023,
665,
298,
18,
14,
22,
2,
503,
2688,
8,
1274,
12,
283,
3093,
63,
1861,
735,
288,
372,
398,
2917,
275,
11839,
8,
807,
8,
288,
536,
534,
1421,
297,
288,
6117,
2968,
354,
297,
283,
354,
14,
2638,
297,
283,
354,
14,
2638,
14,
2219,
995,
288,
3231,
63,
5154,
2968,
354,
995,
288,
511,
63,
5768,
534,
354,
14,
2638,
14,
2219,
14,
396,
63,
5768,
297,
288,
675,
63,
18,
475,
19,
29,
549,
12,
288,
5082,
267,
2917,
14,
1579,
63,
354,
275,
283,
2758,
14,
647,
7,
267,
2088,
275,
511,
8,
2686,
9,
267,
2088,
14,
751,
275,
413,
267,
2088,
14,
7505,
63,
19231,
342,
267,
2088,
14,
3174,
63,
694,
275,
4770,
14,
3791,
63,
7917,
267,
2088,
14,
751,
275,
413,
267,
2269,
63,
2703,
275,
984,
14,
2703,
267,
984,
14,
2703,
275,
5228,
342,
267,
862,
26,
288,
862,
26,
327,
862,
15,
2590,
15,
15172,
3181,
1133,
1736,
315,
2018,
499,
14,
20,
12,
880,
781,
1929,
6032,
862,
13,
15384,
14,
355,
2088,
14,
1065
] |
[
1882,
2803,
26,
9094,
13,
24,
1882,
199,
199,
624,
32176,
2295,
199,
624,
199,
646,
984,
199,
646,
747,
12,
5145,
12,
5549,
12,
2882,
199,
646,
5549,
199,
646,
4770,
199,
199,
504,
7065,
14,
2550,
492,
12577,
547,
199,
504,
9116,
14,
5819,
492,
5228,
199,
504,
9116,
14,
1531,
14,
396,
492,
511,
199,
504,
9116,
14,
1531,
492,
8837,
63,
3174,
465,
8837,
63,
3174,
63,
4600,
199,
504,
9116,
14,
2686,
492,
11839,
199,
199,
20836,
63,
4521,
275,
9638,
199,
504,
9116,
492,
3272,
199,
199,
2758,
8,
354,
534,
1421,
297,
272,
6117,
2968,
354,
297,
283,
354,
14,
2638,
297,
283,
354,
14,
2638,
14,
2219,
995,
272,
3231,
63,
5154,
2968,
354,
995,
272,
511,
63,
5768,
534,
354,
14,
2638,
14,
2219,
14,
396,
63,
5768,
297,
199,
9,
199,
624,
199,
199,
2709,
63,
8727,
275,
408,
3,
1882,
2803,
26,
23864,
13,
17,
1882,
199,
3,
428,
14614,
278,
1952,
2075,
82,
13733,
651,
13333,
251,
78,
1525,
370,
511,
473,
385,
17709,
5741,
650,
709,
199,
893,
26,
272,
636,
646,
19734,
4600,
63,
4435,
1959,
16536,
63,
3251,
3460,
354,
3368,
199,
2590,
3545,
26,
272,
687,
28728,
492,
12247,
63,
515,
272,
636,
515,
363,
275,
12247,
63,
515,
3460,
515,
3108,
636,
354,
3368,
199,
624,
199,
3,
4155,
3238,
642,
365,
23864,
13,
17,
3366,
12,
2544,
3575,
26,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
19,
16095,
272,
9380,
63,
8727,
275,
9380,
63,
8727,
14,
2708,
360,
6610,
13,
24,
358,
199,
2709,
63,
8727,
275,
9380,
63,
8727,
14,
2143,
360,
27317,
13,
17,
358,
199,
199,
2864,
63,
4521,
275,
408,
646,
2882,
199,
199,
533,
1379,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
396,
8,
277,
304,
267,
870,
298,
5686,
2,
327,
7719,
2449,
1334,
2018,
650,
7444,
499,
475,
19,
365,
1202,
199,
199,
396,
63,
5768,
275,
2882,
14,
18275,
8,
774,
774,
9,
199,
624,
199,
199,
533,
1379,
774,
774,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
340,
984,
14,
1023,
665,
298,
18,
14,
22,
2,
503,
2688,
8,
1274,
12,
283,
3093,
63,
1861,
735,
288,
372,
398,
327,
15191,
5523,
267,
291,
14,
694,
275,
5549,
14,
11983,
342,
267,
747,
14,
8215,
8,
736,
14,
515,
14,
904,
8,
277,
14,
694,
12,
283,
354,
1333,
267,
747,
14,
8215,
8,
736,
14,
515,
14,
904,
8,
277,
14,
694,
12,
283,
354,
297,
283,
2638,
1333,
267,
747,
14,
8215,
8,
736,
14,
515,
14,
904,
8,
277,
14,
694,
12,
283,
354,
297,
283,
2638,
297,
283,
2219,
1333,
267,
327,
3272,
14,
647,
267,
3272,
275,
747,
14,
515,
14,
904,
8,
277,
14,
694,
12,
283,
2758,
14,
647,
358,
267,
289,
275,
1551,
8,
2758,
12,
283,
9115,
358,
267,
289,
14,
952,
8,
20836,
63,
4521,
9,
267,
289,
14,
1600,
342,
267,
291,
14,
1753,
63,
6525,
275,
747,
14,
9458,
342,
267,
327,
536,
22128,
826,
4343,
647,
267,
4205,
275,
747,
14,
515,
14,
904,
8,
277,
14,
694,
12,
283,
354,
297,
2560,
826,
4343,
647,
358,
267,
289,
275,
1551,
8,
826,
12,
283,
6603,
358,
267,
289,
14,
952,
8,
2709,
63,
8727,
9,
267,
289,
14,
1600,
342,
267,
327,
536,
15,
2638,
22128,
826,
4343,
647,
267,
4205,
275,
747,
14,
515,
14,
904,
8,
277,
14,
694,
12,
283,
354,
297,
283,
2638,
297,
2560,
826,
4343,
647,
358,
267,
289,
275,
1551,
8,
826,
12,
283,
9115,
358,
267,
289,
14,
952,
7863,
1667,
60,
78,
358,
267,
289,
14,
1600,
342,
267,
327,
536,
15,
2638,
15,
2219,
22128,
826,
4343,
647,
267,
4205,
275,
747,
14,
515,
14,
904,
8,
277,
14,
694,
12,
283,
354,
297,
283,
2638,
297,
283,
2219,
297,
2560,
826,
4343,
647,
358,
267,
289,
275,
1551,
8,
826,
12,
283,
9115,
358,
267,
289,
14,
952,
8,
2864,
63,
4521,
9,
267,
289,
14,
1600,
342,
398,
747,
14,
8563,
8,
277,
14,
694,
9,
267,
291,
14,
1753,
63,
1095,
275,
4770,
14,
3791,
63,
5825,
267,
4770,
14,
3791,
63,
5825,
275,
5549,
14,
11983,
342,
267,
291,
14,
1753,
63,
2124,
275,
4770,
14,
3791,
63,
7917,
267,
4770,
14,
3791,
63,
7917,
275,
5549,
14,
11983,
342,
339,
347,
6766,
8,
277,
304,
267,
340,
984,
14,
1023,
665,
298,
18,
14,
22,
2,
503,
2688,
8,
1274,
12,
283,
3093,
63,
1861,
735,
288,
372,
398,
747,
14,
8563,
8,
277,
14,
1753,
63,
6525,
9,
267,
5145,
14,
9242,
8,
277,
14,
694,
9,
267,
5145,
14,
9242,
8,
2124,
14,
3791,
63,
5825,
9,
267,
5145,
14,
9242,
8,
2124,
14,
3791,
63,
7917,
9,
267,
4770,
14,
3791,
63,
5825,
275,
291,
14,
1753,
63,
1095,
267,
4770,
14,
3791,
63,
7917,
275,
291,
14,
1753,
63,
2124,
339,
347,
511,
63,
396,
8,
277,
304,
267,
340,
984,
14,
1023,
665,
298,
18,
14,
22,
2,
503,
2688,
8,
1274,
12,
283,
3093,
63,
1861,
735,
288,
372,
398,
2917,
275,
11839,
8,
807,
8,
288,
536,
534,
1421,
297,
288,
6117,
2968,
354,
297,
283,
354,
14,
2638,
297,
283,
354,
14,
2638,
14,
2219,
995,
288,
3231,
63,
5154,
2968,
354,
995,
288,
511,
63,
5768,
534,
354,
14,
2638,
14,
2219,
14,
396,
63,
5768,
297,
288,
675,
63,
18,
475,
19,
29,
549,
12,
288,
5082,
267,
2917,
14,
1579,
63,
354,
275,
283,
2758,
14,
647,
7,
267,
2088,
275,
511,
8,
2686,
9,
267,
2088,
14,
751,
275,
413,
267,
2088,
14,
7505,
63,
19231,
342,
267,
2088,
14,
3174,
63,
694,
275,
4770,
14,
3791,
63,
7917,
267,
2088,
14,
751,
275,
413,
267,
2269,
63,
2703,
275,
984,
14,
2703,
267,
984,
14,
2703,
275,
5228,
342,
267,
862,
26,
288,
862,
26,
327,
862,
15,
2590,
15,
15172,
3181,
1133,
1736,
315,
2018,
499,
14,
20,
12,
880,
781,
1929,
6032,
862,
13,
15384,
14,
355,
2088,
14,
1065,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mantidproject/mantid
|
qt/python/mantidqt/widgets/memorywidget/memoryinfo.py
|
3
|
1136
|
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2021 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# This file is part of the mantidqt package
#
#
from psutil import virtual_memory
from typing import Tuple
CONVERSION_FACTOR_BYTES_TO_GB = 1.0 / (1024 * 1024 * 1024)
def get_memory_info() -> Tuple[int, float, float]:
"""
Returns following system memory usage information
obtained using psutil.virtual_memory
mem_used_percent : Used system memory in percentage
mem_used_GB : Used system memory in Gigabytes(GB)
mem_total_GB : Total available system memory in GB
"""
mem_used = virtual_memory().used
mem_total = virtual_memory().total
mem_used_percent = min(int(round(mem_used * 100 / mem_total)), 100)
mem_used_GB = mem_used * CONVERSION_FACTOR_BYTES_TO_GB
mem_total_GB = mem_total * CONVERSION_FACTOR_BYTES_TO_GB
return mem_used_percent, mem_used_GB, mem_total_GB
|
gpl-3.0
|
[
3,
603,
4466,
68,
24426,
520,
4178,
921,
5031,
14,
957,
15,
1237,
5700,
1715,
15,
1237,
5700,
199,
3,
199,
3,
1898,
1253,
1574,
27,
499,
15385,
2281,
1311,
820,
85,
728,
18090,
4693,
17589,
16871,
31671,
738,
43,
6129,
12,
199,
3,
257,
653,
7181,
36,
593,
1151,
31196,
20548,
16871,
31671,
12,
31615,
290,
8360,
8408,
5800,
12,
199,
3,
257,
1010,
6329,
337,
7964,
310,
446,
491,
618,
11908,
1253,
17447,
2709,
12,
1010,
25585,
402,
16332,
662,
1372,
4312,
24309,
17378,
12,
27751,
199,
3,
6988,
19596,
446,
844,
446,
23285,
26,
14629,
446,
650,
14,
16,
435,
199,
3,
221,
961,
570,
365,
1777,
402,
314,
2169,
5700,
8440,
2559,
199,
3,
199,
3,
199,
504,
22214,
492,
5791,
63,
4844,
199,
504,
14090,
492,
11634,
199,
199,
1864,
4612,
63,
26393,
63,
20352,
63,
2566,
63,
6487,
275,
413,
14,
16,
1182,
334,
7727,
627,
6619,
627,
6619,
9,
421,
199,
318,
664,
63,
4844,
63,
815,
342,
1035,
11634,
59,
442,
12,
2069,
12,
2069,
2189,
272,
408,
272,
1803,
2569,
2656,
4402,
4503,
2556,
272,
15884,
1808,
22214,
14,
2065,
63,
4844,
272,
7573,
63,
2972,
63,
7045,
520,
8051,
2656,
4402,
315,
16327,
272,
7573,
63,
2972,
63,
6487,
520,
8051,
2656,
4402,
315,
598,
528,
27601,
8,
6487,
9,
272,
7573,
63,
2923,
63,
6487,
520,
19271,
2808,
2656,
4402,
315,
18553,
272,
408,
272,
7573,
63,
2972,
275,
5791,
63,
4844,
1252,
2972,
272,
7573,
63,
2923,
275,
5791,
63,
4844,
1252,
2923,
272,
7573,
63,
2972,
63,
7045,
275,
1748,
8,
442,
8,
2363,
8,
5286,
63,
2972,
627,
2948,
1182,
7573,
63,
2923,
1826,
2948,
9,
272,
7573,
63,
2972,
63,
6487,
275,
7573,
63,
2972,
627,
1868,
4612,
63,
26393,
63,
20352,
63,
2566,
63,
6487,
272,
7573,
63,
2923,
63,
6487,
275,
7573,
63,
2923,
627,
1868,
4612,
63,
26393,
63,
20352,
63,
2566,
63,
6487,
272,
372,
7573,
63,
2972,
63,
7045,
12,
7573,
63,
2972,
63,
6487,
12,
7573,
63,
2923,
63,
6487,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
603,
4466,
68,
24426,
520,
4178,
921,
5031,
14,
957,
15,
1237,
5700,
1715,
15,
1237,
5700,
199,
3,
199,
3,
1898,
1253,
1574,
27,
499,
15385,
2281,
1311,
820,
85,
728,
18090,
4693,
17589,
16871,
31671,
738,
43,
6129,
12,
199,
3,
257,
653,
7181,
36,
593,
1151,
31196,
20548,
16871,
31671,
12,
31615,
290,
8360,
8408,
5800,
12,
199,
3,
257,
1010,
6329,
337,
7964,
310,
446,
491,
618,
11908,
1253,
17447,
2709,
12,
1010,
25585,
402,
16332,
662,
1372,
4312,
24309,
17378,
12,
27751,
199,
3,
6988,
19596,
446,
844,
446,
23285,
26,
14629,
446,
650,
14,
16,
435,
199,
3,
221,
961,
570,
365,
1777,
402,
314,
2169,
5700,
8440,
2559,
199,
3,
199,
3,
199,
504,
22214,
492,
5791,
63,
4844,
199,
504,
14090,
492,
11634,
199,
199,
1864,
4612,
63,
26393,
63,
20352,
63,
2566,
63,
6487,
275,
413,
14,
16,
1182,
334,
7727,
627,
6619,
627,
6619,
9,
421,
199,
318,
664,
63,
4844,
63,
815,
342,
1035,
11634,
59,
442,
12,
2069,
12,
2069,
2189,
272,
408,
272,
1803,
2569,
2656,
4402,
4503,
2556,
272,
15884,
1808,
22214,
14,
2065,
63,
4844,
272,
7573,
63,
2972,
63,
7045,
520,
8051,
2656,
4402,
315,
16327,
272,
7573,
63,
2972,
63,
6487,
520,
8051,
2656,
4402,
315,
598,
528,
27601,
8,
6487,
9,
272,
7573,
63,
2923,
63,
6487,
520,
19271,
2808,
2656,
4402,
315,
18553,
272,
408,
272,
7573,
63,
2972,
275,
5791,
63,
4844,
1252,
2972,
272,
7573,
63,
2923,
275,
5791,
63,
4844,
1252,
2923,
272,
7573,
63,
2972,
63,
7045,
275,
1748,
8,
442,
8,
2363,
8,
5286,
63,
2972,
627,
2948,
1182,
7573,
63,
2923,
1826,
2948,
9,
272,
7573,
63,
2972,
63,
6487,
275,
7573,
63,
2972,
627,
1868,
4612,
63,
26393,
63,
20352,
63,
2566,
63,
6487,
272,
7573,
63,
2923,
63,
6487,
275,
7573,
63,
2923,
627,
1868,
4612,
63,
26393,
63,
20352,
63,
2566,
63,
6487,
272,
372,
7573,
63,
2972,
63,
7045,
12,
7573,
63,
2972,
63,
6487,
12,
7573,
63,
2923,
63,
6487,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
hschilling/pyOpt
|
pyOpt/pyOpt_gradient.py
|
1
|
10818
|
#!/usr/bin/env python
'''
pyOpt_gradient
Holds the Python Design Optimization Gradient Calculation Class.
Copyright (c) 2008-2013 by pyOpt Developers
All rights reserved.
Revision: 1.0 $Date: 20/06/2010 21:00$
Developers:
-----------
- Dr. Ruben E. Perez (RP)
- Mr. Peter W. Jansen (PJ)
History
-------
v. 1.0 - Initial Class Creation (PJ,RP 2010)
'''
__version__ = '$Revision: $'
'''
To Do:
- add calc fail flag
'''
# =============================================================================
# Standard Python modules
# =============================================================================
import os, sys
import copy
import pdb
# =============================================================================
# External Python modules
# =============================================================================
import numpy
# =============================================================================
# Extension modules
# =============================================================================
#import extension
# =============================================================================
# Misc Definitions
# =============================================================================
eps = 1.0 # define a value for machine precision
while ((eps/2.0 + 1.0) > 1.0):
eps = eps/2.0
#end
eps = 2.0*eps
#eps = math.ldexp(1,-52)
# =============================================================================
# Gradient Class
# =============================================================================
class Gradient(object):
'''
Abstract Class for Optimizer Gradient Calculation Object
'''
def __init__(self, opt_problem, sens_type, sens_mode='', sens_step={}, *args, **kwargs):
'''
Optimizer Gradient Calculation Class Initialization
**Arguments:**
- opt_problem -> INST: Optimization instance
- sens_type -> STR/FUNC: Sensitivity type ('FD', 'CS', or function)
**Keyword arguments:**
- sens_mode -> STR: Parallel flag [''-serial,'pgc'-parallel], *Default* = ''
- sens_step -> INT: Step size, *Default* = {} [=1e-6(FD), 1e-20(CS)]
Documentation last updated: Feb. 03, 2011 - Peter W. Jansen
'''
#
self.opt_problem = opt_problem
if isinstance(sens_type,str):
self.sens_type = sens_type.lower()
else:
self.sens_type = sens_type
#end
if (sens_step == {}):
if (self.sens_type == 'fd'):
self.sens_step = 1.0e-6
elif (self.sens_type == 'cs'):
self.sens_step = 1.0e-20
else:
self.sens_step = sens_step
#end
else:
self.sens_step = sens_step
#end
self.sens_mode = sens_mode.lower()
# MPI Setup
if (self.sens_mode.lower() == 'pgc'):
try:
import mpi4py
from mpi4py import MPI
except ImportError:
print 'Error: mpi4py library failed to import'
#end
comm = MPI.COMM_WORLD
self.nproc = comm.Get_size()
self.myrank = comm.Get_rank()
if (mpi4py.__version__[0] == '0'):
self.Send = comm.Send
self.Recv = comm.Recv
self.Bcast = comm.Bcast
elif (mpi4py.__version__[0] == '1'):
self.Send = comm.send
self.Recv = comm.recv
self.Bcast = comm.bcast
#end
self.mydvs = xrange(self.myrank,len(opt_problem._variables.keys()),self.nproc)
else:
self.myrank = 0
self.mydvs = xrange(len(opt_problem._variables.keys()))
#end
def getGrad(self, x, group_ids, f, g, *args, **kwargs):
'''
Get Gradient
**Arguments:**
- x -> ARRAY: Design variables
- group_ids -> DICT: Group identifications
- f -> ARRAY: Objective values
- g -> ARRAY: Constraint values
Documentation last updated: Feb. 07, 2011 - Peter W. Jansen
'''
#
opt_problem = self.opt_problem
sens_type = self.sens_type
sens_mode = self.sens_mode
sens_step = self.sens_step
mydvs = self.mydvs
myrank = self.myrank
#
dfi = numpy.zeros([len(opt_problem._objectives.keys()),len(mydvs)],'d')
dgi = numpy.zeros([len(opt_problem._constraints.keys()),len(mydvs)],'d')
if (sens_type == 'fd'):
# Finite Differences
dh = sens_step
xs = x
k = 0
for i in mydvs:
xh = copy.copy(xs)
xh[i] += dh
# Variables Groups Handling
if opt_problem.use_groups:
xhg = {}
for group in group_ids.keys():
if (group_ids[group][1]-group_ids[group][0] == 1):
xhg[group] = xh[group_ids[group][0]]
else:
xhg[group] = xh[group_ids[group][0]:group_ids[group][1]]
#end
#end
xh = xhg
#end
[fph,gph,fail] = opt_problem.obj_fun(xh, *args, **kwargs)
if isinstance(fph,float):
fph = [fph]
#end
for j in xrange(len(opt_problem._objectives.keys())):
dfi[j,k] = (fph[j] - f[j])/dh
#end
for j in xrange(len(opt_problem._constraints.keys())):
dgi[j,k] = (gph[j] - g[j])/dh
#end
k += 1
#end
elif (sens_type == 'cs'):
# Complex Step
cdh = sens_step
cxs = copy.copy(x)
k = 0
for i in mydvs:
cxh = cxs + numpy.zeros(len(cxs),complex)
cxh[i] = complex(cxh[i],cdh)
# Variables Groups Handling
if opt_problem.use_groups:
cxhg = {}
for group in group_ids.keys():
if (group_ids[group][1]-group_ids[group][0] == 1):
cxhg[group] = cxh[group_ids[group][0]]
else:
cxhg[group] = cxh[group_ids[group][0]:group_ids[group][1]]
#end
#end
cxh = cxhg
#end
[cfph,cgph,fail] = opt_problem.obj_fun(cxh, *args, **kwargs)
if isinstance(cfph,complex):
cfph = [cfph]
#end
for j in xrange(len(opt_problem._objectives.keys())):
dfi[j,k] = cfph[j].imag/cdh
#end
for j in xrange(len(opt_problem._constraints.keys())):
dgi[j,k] = cgph[j].imag/cdh
#end
k += 1
#end
dfi = dfi.astype(float)
dgi = dgi.astype(float)
else:
# Variables Groups Handling
if opt_problem.use_groups:
xg = {}
for group in group_ids.keys():
if (group_ids[group][1]-group_ids[group][0] == 1):
xg[group] = x[group_ids[group][0]]
else:
xg[group] = x[group_ids[group][0]:group_ids[group][1]]
#end
#end
xn = xg
else:
xn = x
#end
# User Provided Sensitivities
[df_user,dg_user,fail] = sens_type(xn, f, g, *args, **kwargs)
if isinstance(df_user,list):
if len(opt_problem._objectives.keys()) == 1:
df_user = [df_user]
#end
df_user = numpy.array(df_user)
#end
if isinstance(dg_user,list):
dg_user = numpy.array(dg_user)
#end
#
for i in xrange(len(opt_problem._variables.keys())):
for j in xrange(len(opt_problem._objectives.keys())):
dfi[j,i] = df_user[j,i]
#end
for j in xrange(len(opt_problem._constraints.keys())):
dgi[j,i] = dg_user[j,i]
#end
#end
#end
# MPI Gradient Assembly
df = numpy.zeros([len(opt_problem._objectives.keys()),len(opt_problem._variables.keys())],'d')
dg = numpy.zeros([len(opt_problem._constraints.keys()),len(opt_problem._variables.keys())],'d')
if (sens_mode == 'pgc'):
if (sens_type == 'fd') or (sens_type == 'cs'):
if myrank != 0:
self.Send([myrank, dfi, dgi],dest=0)
else:
p_results = [[myrank, dfi, dgi]]
for proc in xrange(1,self.nproc):
p_results.append(self.Recv(source=proc))
#end
#end
if myrank == 0:
for proc in xrange(self.nproc):
k = 0
for i in xrange(p_results[proc][0],len(opt_problem._variables.keys()),self.nproc):
df[:,i] = p_results[proc][1][:,k]
dg[:,i] = p_results[proc][2][:,k]
k += 1
#end
#end
#end
[df,dg] = self.Bcast([df,dg],root=0)
#end
else:
df = dfi
dg = dgi
#end
return df,dg
def getHess(self, *args, **kwargs):
'''
Get Hessian
Documentation last updated: June. 20, 2010 - Ruben E. Perez
'''
#
#
return
#==============================================================================
# Optimizer Gradient Calculation Test
#==============================================================================
if __name__ == '__main__':
# Test Optimizer Gradient Calculation
print 'Testing Optimizer Gradient Calculation...'
grd = Gradient()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
2344,
199,
647,
9985,
63,
7490,
199,
199,
40,
8250,
314,
2018,
29410,
19246,
2072,
19603,
19821,
425,
8089,
14,
199,
199,
7384,
334,
67,
9,
9079,
13,
6965,
701,
1134,
9985,
23493,
199,
2422,
4481,
4644,
14,
199,
12714,
26,
413,
14,
16,
257,
2672,
2506,
26,
3388,
15,
1690,
15,
6542,
7829,
26,
383,
4,
421,
199,
31032,
83,
26,
199,
13715,
199,
13,
577,
82,
14,
820,
456,
287,
662,
14,
11379,
25409,
334,
18612,
9,
199,
13,
603,
82,
14,
22912,
644,
14,
17474,
2464,
334,
48,
42,
9,
199,
199,
12114,
199,
12797,
272,
373,
14,
413,
14,
16,
221,
446,
6026,
8089,
9750,
425,
334,
48,
42,
12,
18612,
7129,
9,
199,
2344,
199,
199,
363,
1023,
363,
275,
4505,
12714,
26,
2672,
7,
199,
199,
2344,
199,
1378,
4226,
26,
272,
446,
1050,
12831,
2449,
3305,
199,
2344,
199,
199,
3,
26237,
199,
3,
9739,
2018,
4621,
199,
3,
26237,
199,
646,
747,
12,
984,
199,
646,
1331,
199,
646,
10543,
199,
199,
3,
26237,
199,
3,
18802,
2018,
4621,
199,
3,
26237,
199,
646,
2680,
199,
199,
3,
26237,
199,
3,
13282,
4621,
199,
3,
26237,
199,
3,
646,
3329,
199,
199,
3,
26237,
199,
3,
603,
10840,
22659,
852,
199,
3,
26237,
199,
8277,
275,
413,
14,
16,
198,
3,
5627,
282,
574,
367,
6844,
7151,
199,
6710,
3666,
8277,
15,
18,
14,
16,
435,
413,
14,
16,
9,
690,
413,
14,
16,
304,
272,
10245,
275,
10245,
15,
18,
14,
16,
199,
3,
500,
199,
8277,
275,
499,
14,
16,
10,
8277,
199,
3,
8277,
275,
3473,
14,
76,
31450,
8,
17,
3057,
2528,
9,
421,
199,
3,
26237,
199,
3,
19603,
8089,
199,
3,
26237,
199,
533,
19603,
8,
785,
304,
2286,
1449,
272,
11836,
8089,
367,
19246,
1793,
19603,
19821,
425,
6935,
272,
1449,
2286,
347,
636,
826,
721,
277,
12,
2450,
63,
6462,
12,
542,
561,
63,
466,
12,
542,
561,
63,
632,
4581,
542,
561,
63,
2926,
10324,
627,
589,
12,
1011,
958,
304,
2728,
1449,
267,
19246,
1793,
19603,
19821,
425,
8089,
6026,
2072,
2728,
1011,
14517,
19003,
2728,
446,
2450,
63,
6462,
1035,
20514,
26,
19246,
2072,
1256,
267,
446,
542,
561,
63,
466,
1035,
7553,
15,
19587,
26,
428,
287,
20635,
730,
661,
7902,
297,
283,
3298,
297,
503,
805,
9,
221,
2728,
1011,
10650,
2368,
19003,
2728,
446,
542,
561,
63,
632,
1035,
7553,
26,
27311,
3305,
788,
12418,
2171,
2584,
4198,
67,
12418,
11887,
467,
627,
2698,
10,
275,
2125,
4960,
446,
542,
561,
63,
2926,
1035,
16429,
26,
13382,
1568,
12,
627,
2698,
10,
275,
1052,
359,
29,
17,
69,
13,
22,
8,
7902,
395,
413,
69,
13,
1165,
8,
3298,
1874,
221,
2728,
15249,
2061,
4588,
26,
221,
21141,
14,
30569,
12,
7760,
446,
22912,
644,
14,
17474,
2464,
267,
1449,
2728,
327,
4960,
291,
14,
2992,
63,
6462,
275,
2450,
63,
6462,
267,
340,
1228,
8,
22891,
63,
466,
12,
495,
304,
288,
291,
14,
22891,
63,
466,
275,
542,
561,
63,
466,
14,
2325,
342,
267,
587,
26,
288,
291,
14,
22891,
63,
466,
275,
542,
561,
63,
466,
267,
327,
500,
267,
340,
334,
22891,
63,
2926,
508,
1052,
304,
288,
340,
334,
277,
14,
22891,
63,
466,
508,
283,
2592,
735,
355,
291,
14,
22891,
63,
2926,
275,
413,
14,
16,
69,
13,
22,
288,
916,
334,
277,
14,
22891,
63,
466,
508,
283,
1259,
735,
355,
291,
14,
22891,
63,
2926,
275,
413,
14,
16,
69,
13,
1165,
288,
587,
26,
355,
291,
14,
22891,
63,
2926,
275,
542,
561,
63,
2926,
288,
327,
500,
267,
587,
26,
288,
291,
14,
22891,
63,
2926,
275,
542,
561,
63,
2926,
267,
327,
500,
267,
291,
14,
22891,
63,
632,
275,
542,
561,
63,
632,
14,
2325,
342,
2728,
327,
26024,
12439,
267,
340,
334,
277,
14,
22891,
63,
632,
14,
2325,
342,
508,
283,
4198,
67,
735,
288,
862,
26,
355,
492,
26806,
20,
647,
355,
687,
26806,
20,
647,
492,
26024,
288,
871,
3545,
26,
355,
870,
283,
547,
26,
26806,
20,
647,
3555,
3405,
370,
492,
7,
288,
327,
500,
288,
1923,
275,
26024,
14,
5378,
63,
22125,
288,
291,
14,
78,
4687,
275,
1923,
14,
1002,
63,
890,
342,
288,
291,
14,
1662,
4648,
275,
1923,
14,
1002,
63,
4648,
342,
288,
340,
334,
13213,
20,
647,
855,
1023,
12298,
16,
61,
508,
283,
16,
735,
355,
291,
14,
6795,
275,
1923,
14,
6795,
355,
291,
14,
15838,
275,
1923,
14,
15838,
355,
291,
14,
34,
2931,
275,
1923,
14,
34,
2931,
288,
916,
334,
13213,
20,
647,
855,
1023,
12298,
16,
61,
508,
283,
17,
735,
355,
291,
14,
6795,
275,
1923,
14,
2254,
355,
291,
14,
15838,
275,
1923,
14,
7637,
355,
291,
14,
34,
2931,
275,
1923,
14,
66,
2931,
288,
327,
500,
288,
291,
14,
1662,
68,
3122,
275,
4945,
8,
277,
14,
1662,
4648,
12,
552,
8,
2992,
63,
6462,
423,
3669,
14,
1612,
4000,
277,
14,
78,
4687,
9,
267,
587,
26,
288,
291,
14,
1662,
4648,
275,
378,
288,
291,
14,
1662,
68,
3122,
275,
4945,
8,
552,
8,
2992,
63,
6462,
423,
3669,
14,
1612,
4059,
267,
327,
500,
268,
5493,
347,
664,
14812,
8,
277,
12,
671,
12,
1572,
63,
1580,
12,
289,
12,
486,
12,
627,
589,
12,
1011,
958,
304,
2728,
1449,
267,
2372,
19603,
2728,
1011,
14517,
19003,
2728,
446,
671,
1035,
4160,
2847,
57,
26,
29410,
2860,
267,
446,
1572,
63,
1580,
1035,
577,
6196,
26,
5611,
29193,
83,
267,
446,
289,
1035,
4160,
2847,
57,
26,
24921,
6850,
1338,
267,
446,
486,
1035,
4160,
2847,
57,
26,
25889,
1338,
2728,
15249,
2061,
4588,
26,
221,
21141,
14,
24937,
12,
7760,
446,
22912,
644,
14,
17474,
2464,
267,
1449,
2728,
327,
4960,
2450,
63,
6462,
275,
291,
14,
2992,
63,
6462,
267,
542,
561,
63,
466,
275,
291,
14,
22891,
63,
466,
267,
542,
561,
63,
632,
275,
291,
14,
22891,
63,
632,
267,
542,
561,
63,
2926,
275,
291,
14,
22891,
63,
2926,
267,
3002,
68,
3122,
275,
291,
14,
1662,
68,
3122,
267
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
2344,
199,
647,
9985,
63,
7490,
199,
199,
40,
8250,
314,
2018,
29410,
19246,
2072,
19603,
19821,
425,
8089,
14,
199,
199,
7384,
334,
67,
9,
9079,
13,
6965,
701,
1134,
9985,
23493,
199,
2422,
4481,
4644,
14,
199,
12714,
26,
413,
14,
16,
257,
2672,
2506,
26,
3388,
15,
1690,
15,
6542,
7829,
26,
383,
4,
421,
199,
31032,
83,
26,
199,
13715,
199,
13,
577,
82,
14,
820,
456,
287,
662,
14,
11379,
25409,
334,
18612,
9,
199,
13,
603,
82,
14,
22912,
644,
14,
17474,
2464,
334,
48,
42,
9,
199,
199,
12114,
199,
12797,
272,
373,
14,
413,
14,
16,
221,
446,
6026,
8089,
9750,
425,
334,
48,
42,
12,
18612,
7129,
9,
199,
2344,
199,
199,
363,
1023,
363,
275,
4505,
12714,
26,
2672,
7,
199,
199,
2344,
199,
1378,
4226,
26,
272,
446,
1050,
12831,
2449,
3305,
199,
2344,
199,
199,
3,
26237,
199,
3,
9739,
2018,
4621,
199,
3,
26237,
199,
646,
747,
12,
984,
199,
646,
1331,
199,
646,
10543,
199,
199,
3,
26237,
199,
3,
18802,
2018,
4621,
199,
3,
26237,
199,
646,
2680,
199,
199,
3,
26237,
199,
3,
13282,
4621,
199,
3,
26237,
199,
3,
646,
3329,
199,
199,
3,
26237,
199,
3,
603,
10840,
22659,
852,
199,
3,
26237,
199,
8277,
275,
413,
14,
16,
198,
3,
5627,
282,
574,
367,
6844,
7151,
199,
6710,
3666,
8277,
15,
18,
14,
16,
435,
413,
14,
16,
9,
690,
413,
14,
16,
304,
272,
10245,
275,
10245,
15,
18,
14,
16,
199,
3,
500,
199,
8277,
275,
499,
14,
16,
10,
8277,
199,
3,
8277,
275,
3473,
14,
76,
31450,
8,
17,
3057,
2528,
9,
421,
199,
3,
26237,
199,
3,
19603,
8089,
199,
3,
26237,
199,
533,
19603,
8,
785,
304,
2286,
1449,
272,
11836,
8089,
367,
19246,
1793,
19603,
19821,
425,
6935,
272,
1449,
2286,
347,
636,
826,
721,
277,
12,
2450,
63,
6462,
12,
542,
561,
63,
466,
12,
542,
561,
63,
632,
4581,
542,
561,
63,
2926,
10324,
627,
589,
12,
1011,
958,
304,
2728,
1449,
267,
19246,
1793,
19603,
19821,
425,
8089,
6026,
2072,
2728,
1011,
14517,
19003,
2728,
446,
2450,
63,
6462,
1035,
20514,
26,
19246,
2072,
1256,
267,
446,
542,
561,
63,
466,
1035,
7553,
15,
19587,
26,
428,
287,
20635,
730,
661,
7902,
297,
283,
3298,
297,
503,
805,
9,
221,
2728,
1011,
10650,
2368,
19003,
2728,
446,
542,
561,
63,
632,
1035,
7553,
26,
27311,
3305,
788,
12418,
2171,
2584,
4198,
67,
12418,
11887,
467,
627,
2698,
10,
275,
2125,
4960,
446,
542,
561,
63,
2926,
1035,
16429,
26,
13382,
1568,
12,
627,
2698,
10,
275,
1052,
359,
29,
17,
69,
13,
22,
8,
7902,
395,
413,
69,
13,
1165,
8,
3298,
1874,
221,
2728,
15249,
2061,
4588,
26,
221,
21141,
14,
30569,
12,
7760,
446,
22912,
644,
14,
17474,
2464,
267,
1449,
2728,
327,
4960,
291,
14,
2992,
63,
6462,
275,
2450,
63,
6462,
267,
340,
1228,
8,
22891,
63,
466,
12,
495,
304,
288,
291,
14,
22891,
63,
466,
275,
542,
561,
63,
466,
14,
2325,
342,
267,
587,
26,
288,
291,
14,
22891,
63,
466,
275,
542,
561,
63,
466,
267,
327,
500,
267,
340,
334,
22891,
63,
2926,
508,
1052,
304,
288,
340,
334,
277,
14,
22891,
63,
466,
508,
283,
2592,
735,
355,
291,
14,
22891,
63,
2926,
275,
413,
14,
16,
69,
13,
22,
288,
916,
334,
277,
14,
22891,
63,
466,
508,
283,
1259,
735,
355,
291,
14,
22891,
63,
2926,
275,
413,
14,
16,
69,
13,
1165,
288,
587,
26,
355,
291,
14,
22891,
63,
2926,
275,
542,
561,
63,
2926,
288,
327,
500,
267,
587,
26,
288,
291,
14,
22891,
63,
2926,
275,
542,
561,
63,
2926,
267,
327,
500,
267,
291,
14,
22891,
63,
632,
275,
542,
561,
63,
632,
14,
2325,
342,
2728,
327,
26024,
12439,
267,
340,
334,
277,
14,
22891,
63,
632,
14,
2325,
342,
508,
283,
4198,
67,
735,
288,
862,
26,
355,
492,
26806,
20,
647,
355,
687,
26806,
20,
647,
492,
26024,
288,
871,
3545,
26,
355,
870,
283,
547,
26,
26806,
20,
647,
3555,
3405,
370,
492,
7,
288,
327,
500,
288,
1923,
275,
26024,
14,
5378,
63,
22125,
288,
291,
14,
78,
4687,
275,
1923,
14,
1002,
63,
890,
342,
288,
291,
14,
1662,
4648,
275,
1923,
14,
1002,
63,
4648,
342,
288,
340,
334,
13213,
20,
647,
855,
1023,
12298,
16,
61,
508,
283,
16,
735,
355,
291,
14,
6795,
275,
1923,
14,
6795,
355,
291,
14,
15838,
275,
1923,
14,
15838,
355,
291,
14,
34,
2931,
275,
1923,
14,
34,
2931,
288,
916,
334,
13213,
20,
647,
855,
1023,
12298,
16,
61,
508,
283,
17,
735,
355,
291,
14,
6795,
275,
1923,
14,
2254,
355,
291,
14,
15838,
275,
1923,
14,
7637,
355,
291,
14,
34,
2931,
275,
1923,
14,
66,
2931,
288,
327,
500,
288,
291,
14,
1662,
68,
3122,
275,
4945,
8,
277,
14,
1662,
4648,
12,
552,
8,
2992,
63,
6462,
423,
3669,
14,
1612,
4000,
277,
14,
78,
4687,
9,
267,
587,
26,
288,
291,
14,
1662,
4648,
275,
378,
288,
291,
14,
1662,
68,
3122,
275,
4945,
8,
552,
8,
2992,
63,
6462,
423,
3669,
14,
1612,
4059,
267,
327,
500,
268,
5493,
347,
664,
14812,
8,
277,
12,
671,
12,
1572,
63,
1580,
12,
289,
12,
486,
12,
627,
589,
12,
1011,
958,
304,
2728,
1449,
267,
2372,
19603,
2728,
1011,
14517,
19003,
2728,
446,
671,
1035,
4160,
2847,
57,
26,
29410,
2860,
267,
446,
1572,
63,
1580,
1035,
577,
6196,
26,
5611,
29193,
83,
267,
446,
289,
1035,
4160,
2847,
57,
26,
24921,
6850,
1338,
267,
446,
486,
1035,
4160,
2847,
57,
26,
25889,
1338,
2728,
15249,
2061,
4588,
26,
221,
21141,
14,
24937,
12,
7760,
446,
22912,
644,
14,
17474,
2464,
267,
1449,
2728,
327,
4960,
2450,
63,
6462,
275,
291,
14,
2992,
63,
6462,
267,
542,
561,
63,
466,
275,
291,
14,
22891,
63,
466,
267,
542,
561,
63,
632,
275,
291,
14,
22891,
63,
632,
267,
542,
561,
63,
2926,
275,
291,
14,
22891,
63,
2926,
267,
3002,
68,
3122,
275,
291,
14,
1662,
68,
3122,
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,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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
] |
huyphan/pyyawhois
|
test/record/parser/test_response_whois_nic_it_status_registered.py
|
1
|
6573
|
# This file is autogenerated. Do not edit it manually.
# If you want change the content of this file, edit
#
# spec/fixtures/responses/whois.nic.it/status_registered
#
# and regenerate the tests with the following script
#
# $ scripts/generate_tests.py
#
from nose.tools import *
from dateutil.parser import parse as time_parse
import yawhois
class TestWhoisNicItStatusRegistered(object):
def setUp(self):
fixture_path = "spec/fixtures/responses/whois.nic.it/status_registered.txt"
host = "whois.nic.it"
part = yawhois.record.Part(open(fixture_path, "r").read(), host)
self.record = yawhois.record.Record(None, [part])
def test_status(self):
eq_(self.record.status, 'registered')
def test_available(self):
eq_(self.record.available, False)
def test_domain(self):
eq_(self.record.domain, "google.it")
def test_nameservers(self):
eq_(self.record.nameservers.__class__.__name__, 'list')
eq_(len(self.record.nameservers), 4)
eq_(self.record.nameservers[0].__class__.__name__, 'Nameserver')
eq_(self.record.nameservers[0].name, "ns1.google.com")
eq_(self.record.nameservers[1].__class__.__name__, 'Nameserver')
eq_(self.record.nameservers[1].name, "ns4.google.com")
eq_(self.record.nameservers[2].__class__.__name__, 'Nameserver')
eq_(self.record.nameservers[2].name, "ns2.google.com")
eq_(self.record.nameservers[3].__class__.__name__, 'Nameserver')
eq_(self.record.nameservers[3].name, "ns3.google.com")
def test_admin_contacts(self):
eq_(self.record.admin_contacts.__class__.__name__, 'list')
eq_(len(self.record.admin_contacts), 1)
eq_(self.record.admin_contacts[0].__class__.__name__, 'Contact')
eq_(self.record.admin_contacts[0].type, yawhois.record.Contact.TYPE_ADMINISTRATIVE)
eq_(self.record.admin_contacts[0].id, "DUP142437129")
eq_(self.record.admin_contacts[0].name, "Tsao Tu")
eq_(self.record.admin_contacts[0].organization, "Tu Tsao")
eq_(self.record.admin_contacts[0].address, "70 Sir John Rogersons Quay")
eq_(self.record.admin_contacts[0].city, "Dublin")
eq_(self.record.admin_contacts[0].zip, "2")
eq_(self.record.admin_contacts[0].state, "IE")
eq_(self.record.admin_contacts[0].country, None)
eq_(self.record.admin_contacts[0].country_code, "IE")
eq_(self.record.admin_contacts[0].phone, None)
eq_(self.record.admin_contacts[0].fax, None)
eq_(self.record.admin_contacts[0].email, None)
eq_(self.record.admin_contacts[0].created_on, time_parse('2013-04-21 01:05:35'))
eq_(self.record.admin_contacts[0].updated_on, time_parse('2013-04-21 01:05:35'))
def test_registered(self):
eq_(self.record.registered, True)
def test_created_on(self):
eq_(self.record.created_on.__class__.__name__, 'datetime')
eq_(self.record.created_on, time_parse('1999-12-10 00:00:00'))
def test_registrar(self):
eq_(self.record.registrar.__class__.__name__, 'Registrar')
eq_(self.record.registrar.id, "MARKMONITOR-REG")
eq_(self.record.registrar.name, "MARKMONITOR-REG")
eq_(self.record.registrar.organization, "MarkMonitor International Limited")
eq_(self.record.registrar.url, "https://www.markmonitor.com/")
def test_registrant_contacts(self):
eq_(self.record.registrant_contacts.__class__.__name__, 'list')
eq_(len(self.record.registrant_contacts), 1)
eq_(self.record.registrant_contacts[0].__class__.__name__, 'Contact')
eq_(self.record.registrant_contacts[0].type, yawhois.record.Contact.TYPE_REGISTRANT)
eq_(self.record.registrant_contacts[0].id, "DUP430692088")
eq_(self.record.registrant_contacts[0].name, "Google Ireland Holdings")
eq_(self.record.registrant_contacts[0].organization, "Google Ireland Holdings")
eq_(self.record.registrant_contacts[0].address, "70 Sir John Rogersons Quay")
eq_(self.record.registrant_contacts[0].city, "Dublin")
eq_(self.record.registrant_contacts[0].zip, "2")
eq_(self.record.registrant_contacts[0].state, "IE")
eq_(self.record.registrant_contacts[0].country, None)
eq_(self.record.registrant_contacts[0].country_code, "IE")
eq_(self.record.registrant_contacts[0].phone, None)
eq_(self.record.registrant_contacts[0].fax, None)
eq_(self.record.registrant_contacts[0].email, None)
eq_(self.record.registrant_contacts[0].created_on, time_parse('2013-04-21 01:05:35'))
eq_(self.record.registrant_contacts[0].updated_on, time_parse('2013-04-21 01:05:35'))
def test_technical_contacts(self):
eq_(self.record.technical_contacts[0].id, "DUP430692088")
eq_(self.record.technical_contacts[0].name, "Google Ireland Holdings")
eq_(self.record.technical_contacts[0].organization, "Google Ireland Holdings")
eq_(self.record.technical_contacts[0].address, "70 Sir John Rogersons Quay")
eq_(self.record.technical_contacts[0].city, "Dublin")
eq_(self.record.technical_contacts[0].zip, "2")
eq_(self.record.technical_contacts[0].state, "IE")
eq_(self.record.technical_contacts[0].country, None)
eq_(self.record.technical_contacts[0].country_code, "IE")
eq_(self.record.technical_contacts[0].phone, None)
eq_(self.record.technical_contacts[0].fax, None)
eq_(self.record.technical_contacts[0].email, None)
eq_(self.record.technical_contacts[0].created_on, time_parse('2013-04-21 01:05:35'))
eq_(self.record.technical_contacts[0].updated_on, time_parse('2013-04-21 01:05:35'))
def test_updated_on(self):
eq_(self.record.updated_on.__class__.__name__, 'datetime')
eq_(self.record.updated_on, time_parse('2013-04-21 01:05:35'))
def test_response_unavailable(self):
eq_(self.record.response_unavailable, False)
def test_domain_id(self):
assert_raises(yawhois.exceptions.AttributeNotSupported, self.record.domain_id)
def test_expires_on(self):
eq_(self.record.expires_on.__class__.__name__, 'datetime')
eq_(self.record.expires_on, time_parse('2014-04-21 00:00:00'))
def test_disclaimer(self):
eq_(self.record.disclaimer, "Please note that the following result could be a subgroup of the data contained in the database. Additional information can be visualized at: http://www.nic.it/cgi-bin/Whois/whois.cgi")
|
mit
|
[
199,
3,
961,
570,
365,
18392,
14,
4226,
440,
5283,
652,
10250,
14,
199,
3,
982,
1265,
2934,
1570,
314,
1564,
402,
642,
570,
12,
5283,
199,
3,
199,
3,
257,
3158,
15,
8769,
15,
10360,
15,
11345,
374,
14,
12165,
14,
390,
15,
1205,
63,
11616,
199,
3,
199,
3,
436,
30943,
314,
2295,
543,
314,
2569,
2884,
199,
3,
199,
3,
257,
2672,
10554,
15,
4208,
63,
2219,
14,
647,
199,
3,
199,
199,
504,
11354,
14,
2537,
492,
627,
199,
504,
22208,
14,
2087,
492,
2198,
465,
900,
63,
1122,
199,
646,
612,
10084,
526,
374,
199,
199,
533,
1379,
55,
526,
374,
46,
530,
7940,
3694,
20341,
8,
785,
304,
339,
347,
3613,
8,
277,
304,
267,
10949,
63,
515,
275,
298,
1650,
15,
8769,
15,
10360,
15,
11345,
374,
14,
12165,
14,
390,
15,
1205,
63,
11616,
14,
2424,
2,
267,
1591,
260,
275,
298,
11345,
374,
14,
12165,
14,
390,
2,
267,
1777,
260,
275,
612,
10084,
526,
374,
14,
3059,
14,
8416,
8,
1490,
8,
5997,
63,
515,
12,
298,
82,
3471,
739,
1062,
1591,
9,
267,
291,
14,
3059,
221,
275,
612,
10084,
526,
374,
14,
3059,
14,
5433,
8,
403,
12,
359,
2064,
566,
339,
347,
511,
63,
1205,
8,
277,
304,
267,
3850,
2531,
277,
14,
3059,
14,
1205,
12,
283,
11616,
358,
339,
347,
511,
63,
4561,
8,
277,
304,
267,
3850,
2531,
277,
14,
3059,
14,
4561,
12,
756,
9,
339,
347,
511,
63,
2261,
8,
277,
304,
267,
3850,
2531,
277,
14,
3059,
14,
2261,
12,
298,
3098,
14,
390,
531,
339,
347,
511,
63,
28620,
8,
277,
304,
267,
3850,
2531,
277,
14,
3059,
14,
28620,
855,
533,
4914,
354,
3108,
283,
513,
358,
267,
3850,
2531,
552,
8,
277,
14,
3059,
14,
28620,
395,
841,
9,
267,
3850,
2531,
277,
14,
3059,
14,
28620,
59,
16,
17979,
533,
4914,
354,
3108,
283,
985,
1000,
358,
267,
3850,
2531,
277,
14,
3059,
14,
28620,
59,
16,
1055,
354,
12,
298,
561,
17,
14,
3098,
14,
957,
531,
267,
3850,
2531,
277,
14,
3059,
14,
28620,
59,
17,
17979,
533,
4914,
354,
3108,
283,
985,
1000,
358,
267,
3850,
2531,
277,
14,
3059,
14,
28620,
59,
17,
1055,
354,
12,
298,
561,
20,
14,
3098,
14,
957,
531,
267,
3850,
2531,
277,
14,
3059,
14,
28620,
59,
18,
17979,
533,
4914,
354,
3108,
283,
985,
1000,
358,
267,
3850,
2531,
277,
14,
3059,
14,
28620,
59,
18,
1055,
354,
12,
298,
561,
18,
14,
3098,
14,
957,
531,
267,
3850,
2531,
277,
14,
3059,
14,
28620,
59,
19,
17979,
533,
4914,
354,
3108,
283,
985,
1000,
358,
267,
3850,
2531,
277,
14,
3059,
14,
28620,
59,
19,
1055,
354,
12,
298,
561,
19,
14,
3098,
14,
957,
531,
339,
347,
511,
63,
2113,
63,
18147,
8,
277,
304,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
855,
533,
4914,
354,
3108,
283,
513,
358,
267,
3850,
2531,
552,
8,
277,
14,
3059,
14,
2113,
63,
18147,
395,
413,
9,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
17979,
533,
4914,
354,
3108,
283,
14499,
358,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
466,
12,
612,
10084,
526,
374,
14,
3059,
14,
14499,
14,
2711,
63,
14288,
21340,
14277,
9,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
344,
12,
298,
24099,
1079,
1194,
1401,
7263,
531,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
354,
12,
298,
52,
2231,
79,
377,
85,
531,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
9071,
12,
298,
30669,
377,
2231,
79,
531,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
1562,
12,
298,
2760,
428,
723,
17815,
6848,
836,
834,
83,
5843,
1187,
531,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
3690,
12,
298,
36,
456,
472,
531,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
3065,
12,
298,
18,
531,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
929,
12,
298,
4332,
531,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
6063,
12,
488,
9,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
6063,
63,
600,
12,
298,
4332,
531,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
9339,
12,
488,
9,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
667,
88,
12,
488,
9,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
2123,
12,
488,
9,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
3966,
63,
265,
12,
900,
63,
1122,
360,
6965,
13,
966,
13,
2025,
17163,
26,
1717,
26,
1276,
1333,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
5334,
63,
265,
12,
900,
63,
1122,
360,
6965,
13,
966,
13,
2025,
17163,
26,
1717,
26,
1276,
1333,
339,
347,
511,
63,
11616,
8,
277,
304,
267,
3850,
2531,
277,
14,
3059,
14,
11616,
12,
715,
9,
339,
347,
511,
63,
3966,
63,
265,
8,
277,
304,
267,
3850,
2531,
277,
14,
3059,
14,
3966,
63,
265,
855,
533,
4914,
354,
3108,
283,
2083,
358,
267,
3850,
2531,
277,
14,
3059,
14,
3966,
63,
265,
12,
900,
63,
1122,
360,
16278,
13,
713,
13,
709,
8733,
26,
383,
26,
383,
1333,
339,
347,
511,
63,
1135,
31777,
8,
277,
304,
267,
3850,
2531,
277,
14,
3059,
14,
1135,
31777,
855,
533,
4914,
354,
3108,
283,
2872,
31777,
358,
267,
3850,
2531,
277,
14,
3059,
14,
1135,
31777,
14,
344,
12,
298,
10520,
32387,
726,
13,
5616,
531,
267,
3850,
2531,
277,
14,
3059,
14,
1135,
31777,
14,
354,
12,
298,
10520,
32387,
726,
13,
5616,
531,
267,
3850,
2531,
277,
14,
3059,
14,
1135,
31777,
14,
9071,
12,
298,
6470,
13189,
28220,
23954,
531,
267,
3850,
2531,
277,
14,
3059,
14,
1135,
31777,
14,
633,
12,
298
] |
[
3,
961,
570,
365,
18392,
14,
4226,
440,
5283,
652,
10250,
14,
199,
3,
982,
1265,
2934,
1570,
314,
1564,
402,
642,
570,
12,
5283,
199,
3,
199,
3,
257,
3158,
15,
8769,
15,
10360,
15,
11345,
374,
14,
12165,
14,
390,
15,
1205,
63,
11616,
199,
3,
199,
3,
436,
30943,
314,
2295,
543,
314,
2569,
2884,
199,
3,
199,
3,
257,
2672,
10554,
15,
4208,
63,
2219,
14,
647,
199,
3,
199,
199,
504,
11354,
14,
2537,
492,
627,
199,
504,
22208,
14,
2087,
492,
2198,
465,
900,
63,
1122,
199,
646,
612,
10084,
526,
374,
199,
199,
533,
1379,
55,
526,
374,
46,
530,
7940,
3694,
20341,
8,
785,
304,
339,
347,
3613,
8,
277,
304,
267,
10949,
63,
515,
275,
298,
1650,
15,
8769,
15,
10360,
15,
11345,
374,
14,
12165,
14,
390,
15,
1205,
63,
11616,
14,
2424,
2,
267,
1591,
260,
275,
298,
11345,
374,
14,
12165,
14,
390,
2,
267,
1777,
260,
275,
612,
10084,
526,
374,
14,
3059,
14,
8416,
8,
1490,
8,
5997,
63,
515,
12,
298,
82,
3471,
739,
1062,
1591,
9,
267,
291,
14,
3059,
221,
275,
612,
10084,
526,
374,
14,
3059,
14,
5433,
8,
403,
12,
359,
2064,
566,
339,
347,
511,
63,
1205,
8,
277,
304,
267,
3850,
2531,
277,
14,
3059,
14,
1205,
12,
283,
11616,
358,
339,
347,
511,
63,
4561,
8,
277,
304,
267,
3850,
2531,
277,
14,
3059,
14,
4561,
12,
756,
9,
339,
347,
511,
63,
2261,
8,
277,
304,
267,
3850,
2531,
277,
14,
3059,
14,
2261,
12,
298,
3098,
14,
390,
531,
339,
347,
511,
63,
28620,
8,
277,
304,
267,
3850,
2531,
277,
14,
3059,
14,
28620,
855,
533,
4914,
354,
3108,
283,
513,
358,
267,
3850,
2531,
552,
8,
277,
14,
3059,
14,
28620,
395,
841,
9,
267,
3850,
2531,
277,
14,
3059,
14,
28620,
59,
16,
17979,
533,
4914,
354,
3108,
283,
985,
1000,
358,
267,
3850,
2531,
277,
14,
3059,
14,
28620,
59,
16,
1055,
354,
12,
298,
561,
17,
14,
3098,
14,
957,
531,
267,
3850,
2531,
277,
14,
3059,
14,
28620,
59,
17,
17979,
533,
4914,
354,
3108,
283,
985,
1000,
358,
267,
3850,
2531,
277,
14,
3059,
14,
28620,
59,
17,
1055,
354,
12,
298,
561,
20,
14,
3098,
14,
957,
531,
267,
3850,
2531,
277,
14,
3059,
14,
28620,
59,
18,
17979,
533,
4914,
354,
3108,
283,
985,
1000,
358,
267,
3850,
2531,
277,
14,
3059,
14,
28620,
59,
18,
1055,
354,
12,
298,
561,
18,
14,
3098,
14,
957,
531,
267,
3850,
2531,
277,
14,
3059,
14,
28620,
59,
19,
17979,
533,
4914,
354,
3108,
283,
985,
1000,
358,
267,
3850,
2531,
277,
14,
3059,
14,
28620,
59,
19,
1055,
354,
12,
298,
561,
19,
14,
3098,
14,
957,
531,
339,
347,
511,
63,
2113,
63,
18147,
8,
277,
304,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
855,
533,
4914,
354,
3108,
283,
513,
358,
267,
3850,
2531,
552,
8,
277,
14,
3059,
14,
2113,
63,
18147,
395,
413,
9,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
17979,
533,
4914,
354,
3108,
283,
14499,
358,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
466,
12,
612,
10084,
526,
374,
14,
3059,
14,
14499,
14,
2711,
63,
14288,
21340,
14277,
9,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
344,
12,
298,
24099,
1079,
1194,
1401,
7263,
531,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
354,
12,
298,
52,
2231,
79,
377,
85,
531,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
9071,
12,
298,
30669,
377,
2231,
79,
531,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
1562,
12,
298,
2760,
428,
723,
17815,
6848,
836,
834,
83,
5843,
1187,
531,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
3690,
12,
298,
36,
456,
472,
531,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
3065,
12,
298,
18,
531,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
929,
12,
298,
4332,
531,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
6063,
12,
488,
9,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
6063,
63,
600,
12,
298,
4332,
531,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
9339,
12,
488,
9,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
667,
88,
12,
488,
9,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
2123,
12,
488,
9,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
3966,
63,
265,
12,
900,
63,
1122,
360,
6965,
13,
966,
13,
2025,
17163,
26,
1717,
26,
1276,
1333,
267,
3850,
2531,
277,
14,
3059,
14,
2113,
63,
18147,
59,
16,
1055,
5334,
63,
265,
12,
900,
63,
1122,
360,
6965,
13,
966,
13,
2025,
17163,
26,
1717,
26,
1276,
1333,
339,
347,
511,
63,
11616,
8,
277,
304,
267,
3850,
2531,
277,
14,
3059,
14,
11616,
12,
715,
9,
339,
347,
511,
63,
3966,
63,
265,
8,
277,
304,
267,
3850,
2531,
277,
14,
3059,
14,
3966,
63,
265,
855,
533,
4914,
354,
3108,
283,
2083,
358,
267,
3850,
2531,
277,
14,
3059,
14,
3966,
63,
265,
12,
900,
63,
1122,
360,
16278,
13,
713,
13,
709,
8733,
26,
383,
26,
383,
1333,
339,
347,
511,
63,
1135,
31777,
8,
277,
304,
267,
3850,
2531,
277,
14,
3059,
14,
1135,
31777,
855,
533,
4914,
354,
3108,
283,
2872,
31777,
358,
267,
3850,
2531,
277,
14,
3059,
14,
1135,
31777,
14,
344,
12,
298,
10520,
32387,
726,
13,
5616,
531,
267,
3850,
2531,
277,
14,
3059,
14,
1135,
31777,
14,
354,
12,
298,
10520,
32387,
726,
13,
5616,
531,
267,
3850,
2531,
277,
14,
3059,
14,
1135,
31777,
14,
9071,
12,
298,
6470,
13189,
28220,
23954,
531,
267,
3850,
2531,
277,
14,
3059,
14,
1135,
31777,
14,
633,
12,
298,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,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python2.7/site-packages/tests/panels/test_staticfiles.py
|
30
|
1108
|
# coding: utf-8
from __future__ import absolute_import, unicode_literals
from django.contrib.staticfiles import finders
from ..base import BaseTestCase
class StaticFilesPanelTestCase(BaseTestCase):
def setUp(self):
super(StaticFilesPanelTestCase, self).setUp()
self.panel = self.toolbar.get_panel_by_id('StaticFilesPanel')
def test_default_case(self):
self.panel.process_request(self.request)
self.panel.process_response(self.request, self.response)
self.assertIn('django.contrib.staticfiles.finders.'
'AppDirectoriesFinder', self.panel.content)
self.assertIn('django.contrib.staticfiles.finders.'
'FileSystemFinder (2 files)', self.panel.content)
self.assertEqual(self.panel.num_used, 0)
self.assertNotEqual(self.panel.num_found, 0)
self.assertEqual(self.panel.get_staticfiles_apps(),
['django.contrib.admin', 'debug_toolbar'])
self.assertEqual(self.panel.get_staticfiles_dirs(),
finders.FileSystemFinder().locations)
|
bsd-3-clause
|
[
3,
2803,
26,
2774,
13,
24,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2828,
14,
18373,
492,
2583,
7735,
199,
199,
504,
2508,
1095,
492,
3523,
1746,
421,
199,
533,
13599,
5535,
10185,
1746,
8,
20760,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
9278,
5535,
10185,
1746,
12,
291,
680,
5996,
342,
267,
291,
14,
7885,
275,
291,
14,
13951,
14,
362,
63,
7885,
63,
991,
63,
344,
360,
9278,
5535,
10185,
358,
339,
347,
511,
63,
885,
63,
2546,
8,
277,
304,
267,
291,
14,
7885,
14,
1412,
63,
1069,
8,
277,
14,
1069,
9,
267,
291,
14,
7885,
14,
1412,
63,
1310,
8,
277,
14,
1069,
12,
291,
14,
1310,
9,
267,
291,
14,
4080,
360,
1176,
14,
2828,
14,
18373,
14,
26677,
3530,
1993,
283,
2640,
13752,
11791,
297,
291,
14,
7885,
14,
1317,
9,
267,
291,
14,
4080,
360,
1176,
14,
2828,
14,
18373,
14,
26677,
3530,
1993,
283,
17521,
11791,
334,
18,
1584,
3196,
291,
14,
7885,
14,
1317,
9,
267,
291,
14,
629,
8,
277,
14,
7885,
14,
1507,
63,
2972,
12,
378,
9,
267,
291,
14,
7418,
8,
277,
14,
7885,
14,
1507,
63,
4214,
12,
378,
9,
267,
291,
14,
629,
8,
277,
14,
7885,
14,
362,
63,
18373,
63,
5181,
1062,
586,
788,
1176,
14,
2828,
14,
2113,
297,
283,
1757,
63,
13951,
1105,
267,
291,
14,
629,
8,
277,
14,
7885,
14,
362,
63,
18373,
63,
3220,
1062,
586,
2583,
7735,
14,
17521,
11791,
1252,
8022,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2828,
14,
18373,
492,
2583,
7735,
199,
199,
504,
2508,
1095,
492,
3523,
1746,
421,
199,
533,
13599,
5535,
10185,
1746,
8,
20760,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
9278,
5535,
10185,
1746,
12,
291,
680,
5996,
342,
267,
291,
14,
7885,
275,
291,
14,
13951,
14,
362,
63,
7885,
63,
991,
63,
344,
360,
9278,
5535,
10185,
358,
339,
347,
511,
63,
885,
63,
2546,
8,
277,
304,
267,
291,
14,
7885,
14,
1412,
63,
1069,
8,
277,
14,
1069,
9,
267,
291,
14,
7885,
14,
1412,
63,
1310,
8,
277,
14,
1069,
12,
291,
14,
1310,
9,
267,
291,
14,
4080,
360,
1176,
14,
2828,
14,
18373,
14,
26677,
3530,
1993,
283,
2640,
13752,
11791,
297,
291,
14,
7885,
14,
1317,
9,
267,
291,
14,
4080,
360,
1176,
14,
2828,
14,
18373,
14,
26677,
3530,
1993,
283,
17521,
11791,
334,
18,
1584,
3196,
291,
14,
7885,
14,
1317,
9,
267,
291,
14,
629,
8,
277,
14,
7885,
14,
1507,
63,
2972,
12,
378,
9,
267,
291,
14,
7418,
8,
277,
14,
7885,
14,
1507,
63,
4214,
12,
378,
9,
267,
291,
14,
629,
8,
277,
14,
7885,
14,
362,
63,
18373,
63,
5181,
1062,
586,
788,
1176,
14,
2828,
14,
2113,
297,
283,
1757,
63,
13951,
1105,
267,
291,
14,
629,
8,
277,
14,
7885,
14,
362,
63,
18373,
63,
3220,
1062,
586,
2583,
7735,
14,
17521,
11791,
1252,
8022,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
vbshah1992/microblog
|
flask/lib/python2.7/site-packages/openid/consumer/discover.py
|
142
|
16062
|
# -*- test-case-name: openid.test.test_discover -*-
"""Functions to discover OpenID endpoints from identifiers.
"""
__all__ = [
'DiscoveryFailure',
'OPENID_1_0_NS',
'OPENID_1_0_TYPE',
'OPENID_1_1_TYPE',
'OPENID_2_0_TYPE',
'OPENID_IDP_2_0_TYPE',
'OpenIDServiceEndpoint',
'discover',
]
import urlparse
from openid import oidutil, fetchers, urinorm
from openid import yadis
from openid.yadis.etxrd import nsTag, XRDSError, XRD_NS_2_0
from openid.yadis.services import applyFilter as extractServices
from openid.yadis.discover import discover as yadisDiscover
from openid.yadis.discover import DiscoveryFailure
from openid.yadis import xrires, filters
from openid.yadis import xri
from openid.consumer import html_parse
OPENID_1_0_NS = 'http://openid.net/xmlns/1.0'
OPENID_IDP_2_0_TYPE = 'http://specs.openid.net/auth/2.0/server'
OPENID_2_0_TYPE = 'http://specs.openid.net/auth/2.0/signon'
OPENID_1_1_TYPE = 'http://openid.net/signon/1.1'
OPENID_1_0_TYPE = 'http://openid.net/signon/1.0'
from openid.message import OPENID1_NS as OPENID_1_0_MESSAGE_NS
from openid.message import OPENID2_NS as OPENID_2_0_MESSAGE_NS
class OpenIDServiceEndpoint(object):
"""Object representing an OpenID service endpoint.
@ivar identity_url: the verified identifier.
@ivar canonicalID: For XRI, the persistent identifier.
"""
# OpenID service type URIs, listed in order of preference. The
# ordering of this list affects yadis and XRI service discovery.
openid_type_uris = [
OPENID_IDP_2_0_TYPE,
OPENID_2_0_TYPE,
OPENID_1_1_TYPE,
OPENID_1_0_TYPE,
]
def __init__(self):
self.claimed_id = None
self.server_url = None
self.type_uris = []
self.local_id = None
self.canonicalID = None
self.used_yadis = False # whether this came from an XRDS
self.display_identifier = None
def usesExtension(self, extension_uri):
return extension_uri in self.type_uris
def preferredNamespace(self):
if (OPENID_IDP_2_0_TYPE in self.type_uris or
OPENID_2_0_TYPE in self.type_uris):
return OPENID_2_0_MESSAGE_NS
else:
return OPENID_1_0_MESSAGE_NS
def supportsType(self, type_uri):
"""Does this endpoint support this type?
I consider C{/server} endpoints to implicitly support C{/signon}.
"""
return (
(type_uri in self.type_uris) or
(type_uri == OPENID_2_0_TYPE and self.isOPIdentifier())
)
def getDisplayIdentifier(self):
"""Return the display_identifier if set, else return the claimed_id.
"""
if self.display_identifier is not None:
return self.display_identifier
if self.claimed_id is None:
return None
else:
return urlparse.urldefrag(self.claimed_id)[0]
def compatibilityMode(self):
return self.preferredNamespace() != OPENID_2_0_MESSAGE_NS
def isOPIdentifier(self):
return OPENID_IDP_2_0_TYPE in self.type_uris
def parseService(self, yadis_url, uri, type_uris, service_element):
"""Set the state of this object based on the contents of the
service element."""
self.type_uris = type_uris
self.server_url = uri
self.used_yadis = True
if not self.isOPIdentifier():
# XXX: This has crappy implications for Service elements
# that contain both 'server' and 'signon' Types. But
# that's a pathological configuration anyway, so I don't
# think I care.
self.local_id = findOPLocalIdentifier(service_element,
self.type_uris)
self.claimed_id = yadis_url
def getLocalID(self):
"""Return the identifier that should be sent as the
openid.identity parameter to the server."""
# I looked at this conditional and thought "ah-hah! there's the bug!"
# but Python actually makes that one big expression somehow, i.e.
# "x is x is x" is not the same thing as "(x is x) is x".
# That's pretty weird, dude. -- kmt, 1/07
if (self.local_id is self.canonicalID is None):
return self.claimed_id
else:
return self.local_id or self.canonicalID
def fromBasicServiceEndpoint(cls, endpoint):
"""Create a new instance of this class from the endpoint
object passed in.
@return: None or OpenIDServiceEndpoint for this endpoint object"""
type_uris = endpoint.matchTypes(cls.openid_type_uris)
# If any Type URIs match and there is an endpoint URI
# specified, then this is an OpenID endpoint
if type_uris and endpoint.uri is not None:
openid_endpoint = cls()
openid_endpoint.parseService(
endpoint.yadis_url,
endpoint.uri,
endpoint.type_uris,
endpoint.service_element)
else:
openid_endpoint = None
return openid_endpoint
fromBasicServiceEndpoint = classmethod(fromBasicServiceEndpoint)
def fromHTML(cls, uri, html):
"""Parse the given document as HTML looking for an OpenID <link
rel=...>
@rtype: [OpenIDServiceEndpoint]
"""
discovery_types = [
(OPENID_2_0_TYPE, 'openid2.provider', 'openid2.local_id'),
(OPENID_1_1_TYPE, 'openid.server', 'openid.delegate'),
]
link_attrs = html_parse.parseLinkAttrs(html)
services = []
for type_uri, op_endpoint_rel, local_id_rel in discovery_types:
op_endpoint_url = html_parse.findFirstHref(
link_attrs, op_endpoint_rel)
if op_endpoint_url is None:
continue
service = cls()
service.claimed_id = uri
service.local_id = html_parse.findFirstHref(
link_attrs, local_id_rel)
service.server_url = op_endpoint_url
service.type_uris = [type_uri]
services.append(service)
return services
fromHTML = classmethod(fromHTML)
def fromXRDS(cls, uri, xrds):
"""Parse the given document as XRDS looking for OpenID services.
@rtype: [OpenIDServiceEndpoint]
@raises XRDSError: When the XRDS does not parse.
@since: 2.1.0
"""
return extractServices(uri, xrds, cls)
fromXRDS = classmethod(fromXRDS)
def fromDiscoveryResult(cls, discoveryResult):
"""Create endpoints from a DiscoveryResult.
@type discoveryResult: L{DiscoveryResult}
@rtype: list of L{OpenIDServiceEndpoint}
@raises XRDSError: When the XRDS does not parse.
@since: 2.1.0
"""
if discoveryResult.isXRDS():
method = cls.fromXRDS
else:
method = cls.fromHTML
return method(discoveryResult.normalized_uri,
discoveryResult.response_text)
fromDiscoveryResult = classmethod(fromDiscoveryResult)
def fromOPEndpointURL(cls, op_endpoint_url):
"""Construct an OP-Identifier OpenIDServiceEndpoint object for
a given OP Endpoint URL
@param op_endpoint_url: The URL of the endpoint
@rtype: OpenIDServiceEndpoint
"""
service = cls()
service.server_url = op_endpoint_url
service.type_uris = [OPENID_IDP_2_0_TYPE]
return service
fromOPEndpointURL = classmethod(fromOPEndpointURL)
def __str__(self):
return ("<%s.%s "
"server_url=%r "
"claimed_id=%r "
"local_id=%r "
"canonicalID=%r "
"used_yadis=%s "
">"
% (self.__class__.__module__, self.__class__.__name__,
self.server_url,
self.claimed_id,
self.local_id,
self.canonicalID,
self.used_yadis))
def findOPLocalIdentifier(service_element, type_uris):
"""Find the OP-Local Identifier for this xrd:Service element.
This considers openid:Delegate to be a synonym for xrd:LocalID if
both OpenID 1.X and OpenID 2.0 types are present. If only OpenID
1.X is present, it returns the value of openid:Delegate. If only
OpenID 2.0 is present, it returns the value of xrd:LocalID. If
there is more than one LocalID tag and the values are different,
it raises a DiscoveryFailure. This is also triggered when the
xrd:LocalID and openid:Delegate tags are different.
@param service_element: The xrd:Service element
@type service_element: ElementTree.Node
@param type_uris: The xrd:Type values present in this service
element. This function could extract them, but higher level
code needs to do that anyway.
@type type_uris: [str]
@raises DiscoveryFailure: when discovery fails.
@returns: The OP-Local Identifier for this service element, if one
is present, or None otherwise.
@rtype: str or unicode or NoneType
"""
# XXX: Test this function on its own!
# Build the list of tags that could contain the OP-Local Identifier
local_id_tags = []
if (OPENID_1_1_TYPE in type_uris or
OPENID_1_0_TYPE in type_uris):
local_id_tags.append(nsTag(OPENID_1_0_NS, 'Delegate'))
if OPENID_2_0_TYPE in type_uris:
local_id_tags.append(nsTag(XRD_NS_2_0, 'LocalID'))
# Walk through all the matching tags and make sure that they all
# have the same value
local_id = None
for local_id_tag in local_id_tags:
for local_id_element in service_element.findall(local_id_tag):
if local_id is None:
local_id = local_id_element.text
elif local_id != local_id_element.text:
format = 'More than one %r tag found in one service element'
message = format % (local_id_tag,)
raise DiscoveryFailure(message, None)
return local_id
def normalizeURL(url):
"""Normalize a URL, converting normalization failures to
DiscoveryFailure"""
try:
normalized = urinorm.urinorm(url)
except ValueError, why:
raise DiscoveryFailure('Normalizing identifier: %s' % (why[0],), None)
else:
return urlparse.urldefrag(normalized)[0]
def normalizeXRI(xri):
"""Normalize an XRI, stripping its scheme if present"""
if xri.startswith("xri://"):
xri = xri[6:]
return xri
def arrangeByType(service_list, preferred_types):
"""Rearrange service_list in a new list so services are ordered by
types listed in preferred_types. Return the new list."""
def enumerate(elts):
"""Return an iterable that pairs the index of an element with
that element.
For Python 2.2 compatibility"""
return zip(range(len(elts)), elts)
def bestMatchingService(service):
"""Return the index of the first matching type, or something
higher if no type matches.
This provides an ordering in which service elements that
contain a type that comes earlier in the preferred types list
come before service elements that come later. If a service
element has more than one type, the most preferred one wins.
"""
for i, t in enumerate(preferred_types):
if preferred_types[i] in service.type_uris:
return i
return len(preferred_types)
# Build a list with the service elements in tuples whose
# comparison will prefer the one with the best matching service
prio_services = [(bestMatchingService(s), orig_index, s)
for (orig_index, s) in enumerate(service_list)]
prio_services.sort()
# Now that the services are sorted by priority, remove the sort
# keys from the list.
for i in range(len(prio_services)):
prio_services[i] = prio_services[i][2]
return prio_services
def getOPOrUserServices(openid_services):
"""Extract OP Identifier services. If none found, return the
rest, sorted with most preferred first according to
OpenIDServiceEndpoint.openid_type_uris.
openid_services is a list of OpenIDServiceEndpoint objects.
Returns a list of OpenIDServiceEndpoint objects."""
op_services = arrangeByType(openid_services, [OPENID_IDP_2_0_TYPE])
openid_services = arrangeByType(openid_services,
OpenIDServiceEndpoint.openid_type_uris)
return op_services or openid_services
def discoverYadis(uri):
"""Discover OpenID services for a URI. Tries Yadis and falls back
on old-style <link rel='...'> discovery if Yadis fails.
@param uri: normalized identity URL
@type uri: str
@return: (claimed_id, services)
@rtype: (str, list(OpenIDServiceEndpoint))
@raises DiscoveryFailure: when discovery fails.
"""
# Might raise a yadis.discover.DiscoveryFailure if no document
# came back for that URI at all. I don't think falling back
# to OpenID 1.0 discovery on the same URL will help, so don't
# bother to catch it.
response = yadisDiscover(uri)
yadis_url = response.normalized_uri
body = response.response_text
try:
openid_services = OpenIDServiceEndpoint.fromXRDS(yadis_url, body)
except XRDSError:
# Does not parse as a Yadis XRDS file
openid_services = []
if not openid_services:
# Either not an XRDS or there are no OpenID services.
if response.isXRDS():
# if we got the Yadis content-type or followed the Yadis
# header, re-fetch the document without following the Yadis
# header, with no Accept header.
return discoverNoYadis(uri)
# Try to parse the response as HTML.
# <link rel="...">
openid_services = OpenIDServiceEndpoint.fromHTML(yadis_url, body)
return (yadis_url, getOPOrUserServices(openid_services))
def discoverXRI(iname):
endpoints = []
iname = normalizeXRI(iname)
try:
canonicalID, services = xrires.ProxyResolver().query(
iname, OpenIDServiceEndpoint.openid_type_uris)
if canonicalID is None:
raise XRDSError('No CanonicalID found for XRI %r' % (iname,))
flt = filters.mkFilter(OpenIDServiceEndpoint)
for service_element in services:
endpoints.extend(flt.getServiceEndpoints(iname, service_element))
except XRDSError:
oidutil.log('xrds error on ' + iname)
for endpoint in endpoints:
# Is there a way to pass this through the filter to the endpoint
# constructor instead of tacking it on after?
endpoint.canonicalID = canonicalID
endpoint.claimed_id = canonicalID
endpoint.display_identifier = iname
# FIXME: returned xri should probably be in some normal form
return iname, getOPOrUserServices(endpoints)
def discoverNoYadis(uri):
http_resp = fetchers.fetch(uri)
if http_resp.status not in (200, 206):
raise DiscoveryFailure(
'HTTP Response status from identity URL host is not 200. '
'Got status %r' % (http_resp.status,), http_resp)
claimed_id = http_resp.final_url
openid_services = OpenIDServiceEndpoint.fromHTML(
claimed_id, http_resp.body)
return claimed_id, openid_services
def discoverURI(uri):
parsed = urlparse.urlparse(uri)
if parsed[0] and parsed[1]:
if parsed[0] not in ['http', 'https']:
raise DiscoveryFailure('URI scheme is not HTTP or HTTPS', None)
else:
uri = 'http://' + uri
uri = normalizeURL(uri)
claimed_id, openid_services = discoverYadis(uri)
claimed_id = normalizeURL(claimed_id)
return claimed_id, openid_services
def discover(identifier):
if xri.identifierScheme(identifier) == "XRI":
return discoverXRI(identifier)
else:
return discoverURI(identifier)
|
bsd-3-clause
|
[
3,
1882,
511,
13,
2546,
13,
354,
26,
24494,
14,
396,
14,
396,
63,
18861,
1882,
199,
624,
13967,
370,
20131,
25463,
16173,
687,
14154,
14,
199,
624,
199,
199,
363,
452,
363,
275,
359,
272,
283,
2825,
6913,
6782,
297,
272,
283,
9935,
998,
63,
17,
63,
16,
63,
2709,
297,
272,
283,
9935,
998,
63,
17,
63,
16,
63,
2711,
297,
272,
283,
9935,
998,
63,
17,
63,
17,
63,
2711,
297,
272,
283,
9935,
998,
63,
18,
63,
16,
63,
2711,
297,
272,
283,
9935,
998,
63,
998,
48,
63,
18,
63,
16,
63,
2711,
297,
272,
283,
30244,
3167,
11442,
297,
272,
283,
18861,
297,
272,
1622,
199,
199,
646,
7097,
199,
199,
504,
24494,
492,
20109,
1974,
12,
5267,
1192,
12,
7629,
262,
1025,
199,
199,
504,
24494,
492,
612,
65,
2297,
199,
504,
24494,
14,
11552,
2297,
14,
386,
88,
6883,
492,
700,
1931,
12,
1323,
50,
3177,
547,
12,
1323,
15543,
63,
2709,
63,
18,
63,
16,
199,
504,
24494,
14,
11552,
2297,
14,
5950,
492,
4838,
4131,
465,
5536,
15803,
199,
504,
24494,
14,
11552,
2297,
14,
18861,
492,
20131,
465,
612,
65,
2297,
2825,
5899,
199,
504,
24494,
14,
11552,
2297,
14,
18861,
492,
5289,
6913,
6782,
199,
504,
24494,
14,
11552,
2297,
492,
671,
322,
470,
12,
4766,
199,
504,
24494,
14,
11552,
2297,
492,
671,
322,
199,
199,
504,
24494,
14,
8542,
492,
3517,
63,
1122,
199,
199,
9935,
998,
63,
17,
63,
16,
63,
2709,
275,
283,
1014,
921,
15403,
14,
846,
15,
13991,
15,
17,
14,
16,
7,
199,
9935,
998,
63,
998,
48,
63,
18,
63,
16,
63,
2711,
275,
283,
1014,
921,
7273,
14,
15403,
14,
846,
15,
1178,
15,
18,
14,
16,
15,
1000,
7,
199,
9935,
998,
63,
18,
63,
16,
63,
2711,
275,
283,
1014,
921,
7273,
14,
15403,
14,
846,
15,
1178,
15,
18,
14,
16,
15,
1037,
265,
7,
199,
9935,
998,
63,
17,
63,
17,
63,
2711,
275,
283,
1014,
921,
15403,
14,
846,
15,
1037,
265,
15,
17,
14,
17,
7,
199,
9935,
998,
63,
17,
63,
16,
63,
2711,
275,
283,
1014,
921,
15403,
14,
846,
15,
1037,
265,
15,
17,
14,
16,
7,
199,
199,
504,
24494,
14,
1188,
492,
24164,
998,
17,
63,
2709,
465,
24164,
998,
63,
17,
63,
16,
63,
8272,
63,
2709,
199,
504,
24494,
14,
1188,
492,
24164,
998,
18,
63,
2709,
465,
24164,
998,
63,
18,
63,
16,
63,
8272,
63,
2709,
199,
199,
533,
25463,
3167,
11442,
8,
785,
304,
272,
408,
1692,
6144,
376,
25463,
2435,
6037,
14,
339,
768,
7725,
8503,
63,
633,
26,
314,
16317,
5148,
14,
272,
768,
7725,
11358,
998,
26,
2104,
1323,
6129,
12,
314,
16149,
5148,
14,
272,
408,
339,
327,
25463,
2435,
730,
30143,
12,
10532,
315,
1865,
402,
16705,
14,
221,
710,
272,
327,
7794,
402,
642,
769,
29476,
612,
65,
2297,
436,
1323,
6129,
2435,
13172,
14,
272,
24494,
63,
466,
63,
17656,
275,
359,
267,
24164,
998,
63,
998,
48,
63,
18,
63,
16,
63,
2711,
12,
398,
24164,
998,
63,
18,
63,
16,
63,
2711,
12,
267,
24164,
998,
63,
17,
63,
17,
63,
2711,
12,
267,
24164,
998,
63,
17,
63,
16,
63,
2711,
12,
267,
1622,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
31563,
63,
344,
275,
488,
267,
291,
14,
1000,
63,
633,
275,
488,
267,
291,
14,
466,
63,
17656,
275,
942,
267,
291,
14,
1832,
63,
344,
275,
488,
267,
291,
14,
13109,
998,
275,
488,
267,
291,
14,
2972,
63,
11552,
2297,
275,
756,
327,
3775,
642,
20382,
687,
376,
1323,
50,
3177,
267,
291,
14,
2918,
63,
5364,
275,
488,
339,
347,
4440,
6382,
8,
277,
12,
3329,
63,
2302,
304,
267,
372,
3329,
63,
2302,
315,
291,
14,
466,
63,
17656,
339,
347,
14388,
8814,
8,
277,
304,
267,
340,
334,
9935,
998,
63,
998,
48,
63,
18,
63,
16,
63,
2711,
315,
291,
14,
466,
63,
17656,
503,
288,
24164,
998,
63,
18,
63,
16,
63,
2711,
315,
291,
14,
466,
63,
17656,
304,
288,
372,
24164,
998,
63,
18,
63,
16,
63,
8272,
63,
2709,
267,
587,
26,
288,
372,
24164,
998,
63,
17,
63,
16,
63,
8272,
63,
2709,
339,
347,
5171,
804,
8,
277,
12,
730,
63,
2302,
304,
267,
408,
6586,
642,
6037,
2291,
642,
730,
31,
398,
473,
11201,
445,
91,
15,
1000,
93,
16173,
370,
19796,
2291,
445,
91,
15,
1037,
265,
5565,
267,
408,
267,
372,
334,
288,
334,
466,
63,
2302,
315,
291,
14,
466,
63,
17656,
9,
503,
7205,
334,
466,
63,
2302,
508,
24164,
998,
63,
18,
63,
16,
63,
2711,
436,
291,
14,
374,
1938,
7544,
1012,
288,
776,
339,
347,
664,
7687,
7544,
8,
277,
304,
267,
408,
1767,
314,
2929,
63,
5364,
340,
663,
12,
587,
372,
314,
6108,
21538,
63,
344,
14,
267,
408,
267,
340,
291,
14,
2918,
63,
5364,
365,
440,
488,
26,
288,
372,
291,
14,
2918,
63,
5364,
267,
340,
291,
14,
31563,
63,
344,
365,
488,
26,
288,
372,
488,
267,
587,
26,
288,
372,
7097,
14,
633,
318,
2527,
8,
277,
14,
31563,
63,
344,
2788,
16,
61,
339,
347,
7163,
1385,
8,
277,
304,
267,
372,
291,
14,
17477,
8814,
342,
1137,
24164,
998,
63,
18,
63,
16,
63,
8272,
63,
2709,
339,
347,
365,
1938,
7544,
8,
277,
304,
267,
372,
24164,
998,
63,
998,
48,
63,
18,
63,
16,
63,
2711,
315,
291,
14,
466,
63,
17656,
339,
347,
2198,
3167,
8,
277,
12,
612,
65,
2297,
63,
633,
12,
5108,
12,
730,
63,
17656,
12,
2435,
63,
2108,
304,
267,
408,
1084,
314,
1174,
402,
642,
909,
4079,
641,
314,
4072,
402,
314,
267,
2435,
1819,
1041,
267,
291,
14,
466,
63,
17656,
275,
730,
63,
17656,
267,
291,
14,
1000,
63,
633,
275,
5108,
267,
291,
14,
2972,
63,
11552,
2297,
275,
715,
398,
340,
440,
291,
14,
374,
1938,
7544,
837,
288,
327,
5787,
26,
961,
965,
286,
1330,
647,
1742,
10785,
367,
7591,
4008,
288,
327,
626,
1395,
3865,
283,
1000,
7,
436,
283,
1037,
265,
7,
18851,
14,
221,
11017,
288
] |
[
1882,
511,
13,
2546,
13,
354,
26,
24494,
14,
396,
14,
396,
63,
18861,
1882,
199,
624,
13967,
370,
20131,
25463,
16173,
687,
14154,
14,
199,
624,
199,
199,
363,
452,
363,
275,
359,
272,
283,
2825,
6913,
6782,
297,
272,
283,
9935,
998,
63,
17,
63,
16,
63,
2709,
297,
272,
283,
9935,
998,
63,
17,
63,
16,
63,
2711,
297,
272,
283,
9935,
998,
63,
17,
63,
17,
63,
2711,
297,
272,
283,
9935,
998,
63,
18,
63,
16,
63,
2711,
297,
272,
283,
9935,
998,
63,
998,
48,
63,
18,
63,
16,
63,
2711,
297,
272,
283,
30244,
3167,
11442,
297,
272,
283,
18861,
297,
272,
1622,
199,
199,
646,
7097,
199,
199,
504,
24494,
492,
20109,
1974,
12,
5267,
1192,
12,
7629,
262,
1025,
199,
199,
504,
24494,
492,
612,
65,
2297,
199,
504,
24494,
14,
11552,
2297,
14,
386,
88,
6883,
492,
700,
1931,
12,
1323,
50,
3177,
547,
12,
1323,
15543,
63,
2709,
63,
18,
63,
16,
199,
504,
24494,
14,
11552,
2297,
14,
5950,
492,
4838,
4131,
465,
5536,
15803,
199,
504,
24494,
14,
11552,
2297,
14,
18861,
492,
20131,
465,
612,
65,
2297,
2825,
5899,
199,
504,
24494,
14,
11552,
2297,
14,
18861,
492,
5289,
6913,
6782,
199,
504,
24494,
14,
11552,
2297,
492,
671,
322,
470,
12,
4766,
199,
504,
24494,
14,
11552,
2297,
492,
671,
322,
199,
199,
504,
24494,
14,
8542,
492,
3517,
63,
1122,
199,
199,
9935,
998,
63,
17,
63,
16,
63,
2709,
275,
283,
1014,
921,
15403,
14,
846,
15,
13991,
15,
17,
14,
16,
7,
199,
9935,
998,
63,
998,
48,
63,
18,
63,
16,
63,
2711,
275,
283,
1014,
921,
7273,
14,
15403,
14,
846,
15,
1178,
15,
18,
14,
16,
15,
1000,
7,
199,
9935,
998,
63,
18,
63,
16,
63,
2711,
275,
283,
1014,
921,
7273,
14,
15403,
14,
846,
15,
1178,
15,
18,
14,
16,
15,
1037,
265,
7,
199,
9935,
998,
63,
17,
63,
17,
63,
2711,
275,
283,
1014,
921,
15403,
14,
846,
15,
1037,
265,
15,
17,
14,
17,
7,
199,
9935,
998,
63,
17,
63,
16,
63,
2711,
275,
283,
1014,
921,
15403,
14,
846,
15,
1037,
265,
15,
17,
14,
16,
7,
199,
199,
504,
24494,
14,
1188,
492,
24164,
998,
17,
63,
2709,
465,
24164,
998,
63,
17,
63,
16,
63,
8272,
63,
2709,
199,
504,
24494,
14,
1188,
492,
24164,
998,
18,
63,
2709,
465,
24164,
998,
63,
18,
63,
16,
63,
8272,
63,
2709,
199,
199,
533,
25463,
3167,
11442,
8,
785,
304,
272,
408,
1692,
6144,
376,
25463,
2435,
6037,
14,
339,
768,
7725,
8503,
63,
633,
26,
314,
16317,
5148,
14,
272,
768,
7725,
11358,
998,
26,
2104,
1323,
6129,
12,
314,
16149,
5148,
14,
272,
408,
339,
327,
25463,
2435,
730,
30143,
12,
10532,
315,
1865,
402,
16705,
14,
221,
710,
272,
327,
7794,
402,
642,
769,
29476,
612,
65,
2297,
436,
1323,
6129,
2435,
13172,
14,
272,
24494,
63,
466,
63,
17656,
275,
359,
267,
24164,
998,
63,
998,
48,
63,
18,
63,
16,
63,
2711,
12,
398,
24164,
998,
63,
18,
63,
16,
63,
2711,
12,
267,
24164,
998,
63,
17,
63,
17,
63,
2711,
12,
267,
24164,
998,
63,
17,
63,
16,
63,
2711,
12,
267,
1622,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
31563,
63,
344,
275,
488,
267,
291,
14,
1000,
63,
633,
275,
488,
267,
291,
14,
466,
63,
17656,
275,
942,
267,
291,
14,
1832,
63,
344,
275,
488,
267,
291,
14,
13109,
998,
275,
488,
267,
291,
14,
2972,
63,
11552,
2297,
275,
756,
327,
3775,
642,
20382,
687,
376,
1323,
50,
3177,
267,
291,
14,
2918,
63,
5364,
275,
488,
339,
347,
4440,
6382,
8,
277,
12,
3329,
63,
2302,
304,
267,
372,
3329,
63,
2302,
315,
291,
14,
466,
63,
17656,
339,
347,
14388,
8814,
8,
277,
304,
267,
340,
334,
9935,
998,
63,
998,
48,
63,
18,
63,
16,
63,
2711,
315,
291,
14,
466,
63,
17656,
503,
288,
24164,
998,
63,
18,
63,
16,
63,
2711,
315,
291,
14,
466,
63,
17656,
304,
288,
372,
24164,
998,
63,
18,
63,
16,
63,
8272,
63,
2709,
267,
587,
26,
288,
372,
24164,
998,
63,
17,
63,
16,
63,
8272,
63,
2709,
339,
347,
5171,
804,
8,
277,
12,
730,
63,
2302,
304,
267,
408,
6586,
642,
6037,
2291,
642,
730,
31,
398,
473,
11201,
445,
91,
15,
1000,
93,
16173,
370,
19796,
2291,
445,
91,
15,
1037,
265,
5565,
267,
408,
267,
372,
334,
288,
334,
466,
63,
2302,
315,
291,
14,
466,
63,
17656,
9,
503,
7205,
334,
466,
63,
2302,
508,
24164,
998,
63,
18,
63,
16,
63,
2711,
436,
291,
14,
374,
1938,
7544,
1012,
288,
776,
339,
347,
664,
7687,
7544,
8,
277,
304,
267,
408,
1767,
314,
2929,
63,
5364,
340,
663,
12,
587,
372,
314,
6108,
21538,
63,
344,
14,
267,
408,
267,
340,
291,
14,
2918,
63,
5364,
365,
440,
488,
26,
288,
372,
291,
14,
2918,
63,
5364,
267,
340,
291,
14,
31563,
63,
344,
365,
488,
26,
288,
372,
488,
267,
587,
26,
288,
372,
7097,
14,
633,
318,
2527,
8,
277,
14,
31563,
63,
344,
2788,
16,
61,
339,
347,
7163,
1385,
8,
277,
304,
267,
372,
291,
14,
17477,
8814,
342,
1137,
24164,
998,
63,
18,
63,
16,
63,
8272,
63,
2709,
339,
347,
365,
1938,
7544,
8,
277,
304,
267,
372,
24164,
998,
63,
998,
48,
63,
18,
63,
16,
63,
2711,
315,
291,
14,
466,
63,
17656,
339,
347,
2198,
3167,
8,
277,
12,
612,
65,
2297,
63,
633,
12,
5108,
12,
730,
63,
17656,
12,
2435,
63,
2108,
304,
267,
408,
1084,
314,
1174,
402,
642,
909,
4079,
641,
314,
4072,
402,
314,
267,
2435,
1819,
1041,
267,
291,
14,
466,
63,
17656,
275,
730,
63,
17656,
267,
291,
14,
1000,
63,
633,
275,
5108,
267,
291,
14,
2972,
63,
11552,
2297,
275,
715,
398,
340,
440,
291,
14,
374,
1938,
7544,
837,
288,
327,
5787,
26,
961,
965,
286,
1330,
647,
1742,
10785,
367,
7591,
4008,
288,
327,
626,
1395,
3865,
283,
1000,
7,
436,
283,
1037,
265,
7,
18851,
14,
221,
11017,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
trriplejay/kubernetes
|
cluster/juju/charms/trusty/kubernetes/hooks/lib/registrator.py
|
160
|
3478
|
#!/usr/bin/env python
# Copyright 2015 The Kubernetes 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.
import httplib
import json
import time
class Registrator:
def __init__(self):
self.ds ={
"creationTimestamp": "",
"kind": "Node",
"name": "", # private_address
"metadata": {
"name": "", #private_address,
},
"spec": {
"externalID": "", #private_address
"capacity": {
"mem": "", # mem + ' K',
"cpu": "", # cpus
}
},
"status": {
"conditions": [],
"hostIP": "", #private_address
}
}
@property
def data(self):
''' Returns a data-structure for population to make a request. '''
return self.ds
def register(self, hostname, port, api_path):
''' Contact the API Server for a new registration '''
headers = {"Content-type": "application/json",
"Accept": "application/json"}
connection = httplib.HTTPConnection(hostname, port)
print 'CONN {}'.format(connection)
connection.request("POST", api_path, json.dumps(self.data), headers)
response = connection.getresponse()
body = response.read()
print(body)
result = json.loads(body)
print("Response status:%s reason:%s body:%s" % \
(response.status, response.reason, result))
return response, result
def update(self):
''' Contact the API Server to update a registration '''
# do a get on the API for the node
# repost to the API with any modified data
pass
def save(self):
''' Marshall the registration data '''
# TODO
pass
def command_succeeded(self, response, result):
''' Evaluate response data to determine if the command was successful '''
if response.status in [200, 201]:
print("Registered")
return True
elif response.status in [409,]:
print("Status Conflict")
# Suggested return a PUT instead of a POST with this response
# code, this predicates use of the UPDATE method
# TODO
elif response.status in (500,) and result.get(
'message', '').startswith('The requested resource does not exist'):
# There's something fishy in the kube api here (0.4 dev), first time we
# go to register a new minion, we always seem to get this error.
# http://issue.k8s.io/1995
time.sleep(1)
print("Retrying registration...")
raise ValueError("Registration returned 500, retry")
# return register_machine(apiserver, retry=True)
else:
print("Registration error")
# TODO - get request data
raise RuntimeError("Unable to register machine with")
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6900,
710,
28723,
6642,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
8809,
199,
646,
2022,
199,
646,
900,
421,
199,
533,
5044,
14710,
26,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
795,
275,
91,
881,
298,
8782,
10239,
582,
4873,
881,
298,
5091,
582,
298,
1716,
401,
881,
298,
354,
582,
4873,
327,
5726,
63,
1562,
881,
298,
2343,
582,
469,
288,
298,
354,
582,
4873,
327,
4239,
63,
1562,
12,
881,
1660,
881,
298,
1650,
582,
469,
288,
298,
5159,
998,
582,
4873,
327,
4239,
63,
1562,
288,
298,
10457,
582,
469,
355,
298,
5286,
582,
4873,
221,
327,
7573,
435,
283,
1804,
297,
355,
298,
3541,
582,
4873,
221,
327,
24174,
288,
789,
881,
1660,
881,
298,
1205,
582,
469,
288,
298,
9855,
582,
990,
288,
298,
1102,
1772,
582,
4873,
327,
4239,
63,
1562,
881,
789,
267,
789,
339,
768,
1829,
272,
347,
666,
8,
277,
304,
267,
1449,
1803,
282,
666,
13,
6976,
367,
16423,
370,
1852,
282,
1056,
14,
1449,
267,
372,
291,
14,
795,
339,
347,
2274,
8,
277,
12,
6246,
12,
1844,
12,
2986,
63,
515,
304,
267,
1449,
18684,
314,
3261,
7146,
367,
282,
892,
10991,
1449,
267,
2323,
275,
2420,
2714,
13,
466,
582,
298,
3578,
15,
1001,
401,
673,
298,
8422,
582,
298,
3578,
15,
1001,
3570,
267,
1950,
275,
8809,
14,
19114,
8,
4269,
12,
1844,
9,
267,
870,
283,
17489,
9499,
908,
8,
2105,
9,
267,
1950,
14,
1069,
480,
4030,
401,
2986,
63,
515,
12,
2022,
14,
4180,
8,
277,
14,
576,
395,
2323,
9,
267,
1177,
275,
1950,
14,
25006,
342,
267,
2396,
275,
1177,
14,
739,
342,
267,
870,
8,
2030,
9,
267,
754,
275,
2022,
14,
3640,
8,
2030,
9,
267,
870,
480,
2364,
2004,
2689,
83,
4499,
2689,
83,
2396,
2689,
83,
2,
450,
971,
1467,
334,
1310,
14,
1205,
12,
1177,
14,
5764,
12,
754,
430,
267,
372,
1177,
12,
754,
339,
347,
1678,
8,
277,
304,
267,
1449,
18684,
314,
3261,
7146,
370,
1678,
282,
10991,
1449,
267,
327,
886,
282,
664,
641,
314,
3261,
367,
314,
1031,
267,
327,
295,
1932,
370,
314,
3261,
543,
1263,
6042,
666,
267,
986,
339,
347,
3354,
8,
277,
304,
267,
1449,
16794,
609,
452,
314,
10991,
666,
1449,
267,
327,
3254,
267,
986,
339,
347,
1414,
63,
20003,
8,
277,
12,
1177,
12,
754,
304,
267,
1449,
27450,
1177,
666,
370,
6705,
340,
314,
1414,
1990,
9512,
1449,
267,
340,
1177,
14,
1205,
315,
359,
1840,
12,
1784,
2189,
288,
870,
480,
20341,
531,
288,
372,
715,
267,
916,
1177,
14,
1205,
315,
359,
12443,
12,
2189,
288,
870,
480,
3694,
32539,
6960,
531,
288,
327,
428,
17417,
372,
282,
18337,
3140,
402,
282,
8761,
543,
642,
1177,
288,
327,
1233,
12,
642,
11944,
83,
675,
402,
314,
17148,
1083,
288,
327,
3254,
267,
916,
1177,
14,
1205,
315,
334,
5783,
4258,
436,
754,
14,
362,
8,
288,
283,
1188,
297,
12548,
2460,
360,
1918,
5839,
2073,
1630,
440,
2187,
735,
288,
327,
6006,
1159,
6020,
289,
2453,
89,
315,
314,
23091,
2986,
2348,
334,
16,
14,
20,
4866,
395,
1642,
900,
781,
288,
327,
2621,
370,
2274,
282,
892,
1748,
1636,
12,
781,
3544,
17021,
370,
664,
642,
1125,
14,
288,
327,
1455,
921,
5237,
14,
75,
24,
83,
14,
2308,
15,
7155,
21,
288,
900,
14,
4532,
8,
17,
9,
288,
870,
480,
12989,
316,
10991,
12594,
288,
746,
1722,
480,
11757,
2138,
6891,
12,
7269,
531,
288,
327,
372,
2274,
63,
6744,
8,
1246,
1000,
12,
7269,
29,
549,
9,
267,
587,
26,
288,
870,
480,
11757,
1125,
531,
288,
327,
3254,
446,
664,
1056,
666,
288,
746,
6064,
480,
6005,
370,
2274,
6844,
543,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6900,
710,
28723,
6642,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
8809,
199,
646,
2022,
199,
646,
900,
421,
199,
533,
5044,
14710,
26,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
795,
275,
91,
881,
298,
8782,
10239,
582,
4873,
881,
298,
5091,
582,
298,
1716,
401,
881,
298,
354,
582,
4873,
327,
5726,
63,
1562,
881,
298,
2343,
582,
469,
288,
298,
354,
582,
4873,
327,
4239,
63,
1562,
12,
881,
1660,
881,
298,
1650,
582,
469,
288,
298,
5159,
998,
582,
4873,
327,
4239,
63,
1562,
288,
298,
10457,
582,
469,
355,
298,
5286,
582,
4873,
221,
327,
7573,
435,
283,
1804,
297,
355,
298,
3541,
582,
4873,
221,
327,
24174,
288,
789,
881,
1660,
881,
298,
1205,
582,
469,
288,
298,
9855,
582,
990,
288,
298,
1102,
1772,
582,
4873,
327,
4239,
63,
1562,
881,
789,
267,
789,
339,
768,
1829,
272,
347,
666,
8,
277,
304,
267,
1449,
1803,
282,
666,
13,
6976,
367,
16423,
370,
1852,
282,
1056,
14,
1449,
267,
372,
291,
14,
795,
339,
347,
2274,
8,
277,
12,
6246,
12,
1844,
12,
2986,
63,
515,
304,
267,
1449,
18684,
314,
3261,
7146,
367,
282,
892,
10991,
1449,
267,
2323,
275,
2420,
2714,
13,
466,
582,
298,
3578,
15,
1001,
401,
673,
298,
8422,
582,
298,
3578,
15,
1001,
3570,
267,
1950,
275,
8809,
14,
19114,
8,
4269,
12,
1844,
9,
267,
870,
283,
17489,
9499,
908,
8,
2105,
9,
267,
1950,
14,
1069,
480,
4030,
401,
2986,
63,
515,
12,
2022,
14,
4180,
8,
277,
14,
576,
395,
2323,
9,
267,
1177,
275,
1950,
14,
25006,
342,
267,
2396,
275,
1177,
14,
739,
342,
267,
870,
8,
2030,
9,
267,
754,
275,
2022,
14,
3640,
8,
2030,
9,
267,
870,
480,
2364,
2004,
2689,
83,
4499,
2689,
83,
2396,
2689,
83,
2,
450,
971,
1467,
334,
1310,
14,
1205,
12,
1177,
14,
5764,
12,
754,
430,
267,
372,
1177,
12,
754,
339,
347,
1678,
8,
277,
304,
267,
1449,
18684,
314,
3261,
7146,
370,
1678,
282,
10991,
1449,
267,
327,
886,
282,
664,
641,
314,
3261,
367,
314,
1031,
267,
327,
295,
1932,
370,
314,
3261,
543,
1263,
6042,
666,
267,
986,
339,
347,
3354,
8,
277,
304,
267,
1449,
16794,
609,
452,
314,
10991,
666,
1449,
267,
327,
3254,
267,
986,
339,
347,
1414,
63,
20003,
8,
277,
12,
1177,
12,
754,
304,
267,
1449,
27450,
1177,
666,
370,
6705,
340,
314,
1414,
1990,
9512,
1449,
267,
340,
1177,
14,
1205,
315,
359,
1840,
12,
1784,
2189,
288,
870,
480,
20341,
531,
288,
372,
715,
267,
916,
1177,
14,
1205,
315,
359,
12443,
12,
2189,
288,
870,
480,
3694,
32539,
6960,
531,
288,
327,
428,
17417,
372,
282,
18337,
3140,
402,
282,
8761,
543,
642,
1177,
288,
327,
1233,
12,
642,
11944,
83,
675,
402,
314,
17148,
1083,
288,
327,
3254,
267,
916,
1177,
14,
1205,
315,
334,
5783,
4258,
436,
754,
14,
362,
8,
288,
283,
1188,
297,
12548,
2460,
360,
1918,
5839,
2073,
1630,
440,
2187,
735,
288,
327,
6006,
1159,
6020,
289,
2453,
89,
315,
314,
23091,
2986,
2348,
334,
16,
14,
20,
4866,
395,
1642,
900,
781,
288,
327,
2621,
370,
2274,
282,
892,
1748,
1636,
12,
781,
3544,
17021,
370,
664,
642,
1125,
14,
288,
327,
1455,
921,
5237,
14,
75,
24,
83,
14,
2308,
15,
7155,
21,
288,
900,
14,
4532,
8,
17,
9,
288,
870,
480,
12989,
316,
10991,
12594,
288,
746,
1722,
480,
11757,
2138,
6891,
12,
7269,
531,
288,
327,
372,
2274,
63,
6744,
8,
1246,
1000,
12,
7269,
29,
549,
9,
267,
587,
26,
288,
870,
480,
11757,
1125,
531,
288,
327,
3254,
446,
664,
1056,
666,
288,
746,
6064,
480,
6005,
370,
2274,
6844,
543,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pozetroninc/micropython
|
tests/perf_bench/bm_nqueens.py
|
2
|
1952
|
# Source: https://github.com/python/pyperformance
# License: MIT
# Simple, brute-force N-Queens solver.
# author: collinwinter@google.com (Collin Winter)
# n_queens function: Copyright 2009 Raymond Hettinger
# Pure-Python implementation of itertools.permutations().
def permutations(iterable, r=None):
"""permutations(range(3), 2) --> (0,1) (0,2) (1,0) (1,2) (2,0) (2,1)"""
pool = tuple(iterable)
n = len(pool)
if r is None:
r = n
indices = list(range(n))
cycles = list(range(n - r + 1, n + 1))[::-1]
yield tuple(pool[i] for i in indices[:r])
while n:
for i in reversed(range(r)):
cycles[i] -= 1
if cycles[i] == 0:
indices[i:] = indices[i + 1:] + indices[i:i + 1]
cycles[i] = n - i
else:
j = cycles[i]
indices[i], indices[-j] = indices[-j], indices[i]
yield tuple(pool[i] for i in indices[:r])
break
else:
return
# From http://code.activestate.com/recipes/576647/
def n_queens(queen_count):
"""N-Queens solver.
Args: queen_count: the number of queens to solve for, same as board size.
Yields: Solutions to the problem, each yielded value is a N-tuple.
"""
cols = range(queen_count)
for vec in permutations(cols):
if (queen_count == len(set(vec[i] + i for i in cols))
== len(set(vec[i] - i for i in cols))):
yield vec
###########################################################################
# Benchmark interface
bm_params = {
(50, 25): (1, 5),
(100, 25): (1, 6),
(1000, 100): (1, 7),
(5000, 100): (1, 8),
}
def bm_setup(params):
res = None
def run():
nonlocal res
for _ in range(params[0]):
res = len(list(n_queens(params[1])))
def result():
return params[0] * 10 ** (params[1] - 3), res
return run, result
|
mit
|
[
3,
5800,
26,
4178,
921,
5031,
14,
957,
15,
1548,
15,
647,
20576,
199,
3,
844,
26,
10697,
199,
199,
3,
5870,
12,
11665,
938,
13,
3990,
653,
13,
49,
310,
8764,
10196,
14,
199,
3,
4132,
26,
1048,
472,
87,
1058,
32,
3098,
14,
957,
334,
2001,
472,
644,
1058,
9,
199,
3,
302,
63,
544,
8764,
805,
26,
1898,
8937,
30703,
2106,
68,
869,
386,
1337,
281,
199,
199,
3,
510,
608,
13,
4718,
4514,
402,
7975,
14,
28237,
1252,
199,
318,
26899,
8,
8147,
12,
519,
29,
403,
304,
272,
408,
28237,
8,
1842,
8,
19,
395,
499,
9,
10541,
334,
16,
12,
17,
9,
334,
16,
12,
18,
9,
334,
17,
12,
16,
9,
334,
17,
12,
18,
9,
334,
18,
12,
16,
9,
334,
18,
12,
17,
9471,
272,
4203,
275,
2008,
8,
8147,
9,
272,
302,
275,
822,
8,
2293,
9,
272,
340,
519,
365,
488,
26,
267,
519,
275,
302,
272,
4918,
275,
769,
8,
1842,
8,
78,
430,
272,
19001,
275,
769,
8,
1842,
8,
78,
446,
519,
435,
413,
12,
302,
435,
413,
430,
14172,
17,
61,
272,
1995,
2008,
8,
2293,
59,
73,
61,
367,
284,
315,
4918,
1491,
82,
566,
272,
1830,
302,
26,
267,
367,
284,
315,
10822,
8,
1842,
8,
82,
2298,
288,
19001,
59,
73,
61,
4862,
413,
288,
340,
19001,
59,
73,
61,
508,
378,
26,
355,
4918,
59,
73,
2938,
275,
4918,
59,
73,
435,
413,
2938,
435,
4918,
59,
73,
26,
73,
435,
413,
61,
355,
19001,
59,
73,
61,
275,
302,
446,
284,
288,
587,
26,
355,
1335,
275,
19001,
59,
73,
61,
355,
4918,
59,
73,
467,
4918,
1988,
74,
61,
275,
4918,
1988,
74,
467,
4918,
59,
73,
61,
355,
1995,
2008,
8,
2293,
59,
73,
61,
367,
284,
315,
4918,
1491,
82,
566,
355,
2059,
267,
587,
26,
288,
372,
199,
199,
3,
11606,
1455,
921,
600,
14,
32595,
14,
957,
15,
25200,
15,
12255,
8557,
15,
199,
318,
302,
63,
544,
8764,
8,
544,
287,
63,
835,
304,
272,
408,
46,
13,
49,
310,
8764,
10196,
14,
272,
3033,
26,
17414,
287,
63,
835,
26,
314,
1329,
402,
17414,
8764,
370,
14241,
367,
12,
2011,
465,
13811,
1568,
14,
272,
23771,
83,
26,
17991,
8653,
370,
314,
5160,
12,
1924,
28653,
574,
365,
282,
653,
13,
2960,
14,
272,
408,
272,
8850,
275,
1425,
8,
544,
287,
63,
835,
9,
272,
367,
10782,
315,
26899,
8,
4574,
304,
267,
340,
334,
544,
287,
63,
835,
508,
822,
8,
409,
8,
6046,
59,
73,
61,
435,
284,
367,
284,
315,
8850,
430,
717,
508,
822,
8,
409,
8,
6046,
59,
73,
61,
446,
284,
367,
284,
315,
8850,
15206,
288,
1995,
10782,
199,
199,
3949,
5680,
199,
3,
27067,
3217,
199,
199,
12648,
63,
1162,
275,
469,
272,
334,
1400,
12,
5661,
304,
334,
17,
12,
959,
395,
272,
334,
1960,
12,
5661,
304,
334,
17,
12,
1227,
395,
272,
334,
5279,
12,
2948,
304,
334,
17,
12,
1520,
395,
272,
334,
13128,
12,
2948,
304,
334,
17,
12,
1695,
395,
199,
93,
199,
199,
318,
25425,
63,
2758,
8,
1162,
304,
272,
522,
275,
488,
272,
347,
1255,
837,
267,
2222,
1832,
522,
267,
367,
485,
315,
1425,
8,
1162,
59,
16,
4682,
288,
522,
275,
822,
8,
513,
8,
78,
63,
544,
8764,
8,
1162,
59,
17,
11845,
272,
347,
754,
837,
267,
372,
1862,
59,
16,
61,
627,
1616,
1011,
334,
1162,
59,
17,
61,
446,
650,
395,
522,
272,
372,
1255,
12,
754,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
5800,
26,
4178,
921,
5031,
14,
957,
15,
1548,
15,
647,
20576,
199,
3,
844,
26,
10697,
199,
199,
3,
5870,
12,
11665,
938,
13,
3990,
653,
13,
49,
310,
8764,
10196,
14,
199,
3,
4132,
26,
1048,
472,
87,
1058,
32,
3098,
14,
957,
334,
2001,
472,
644,
1058,
9,
199,
3,
302,
63,
544,
8764,
805,
26,
1898,
8937,
30703,
2106,
68,
869,
386,
1337,
281,
199,
199,
3,
510,
608,
13,
4718,
4514,
402,
7975,
14,
28237,
1252,
199,
318,
26899,
8,
8147,
12,
519,
29,
403,
304,
272,
408,
28237,
8,
1842,
8,
19,
395,
499,
9,
10541,
334,
16,
12,
17,
9,
334,
16,
12,
18,
9,
334,
17,
12,
16,
9,
334,
17,
12,
18,
9,
334,
18,
12,
16,
9,
334,
18,
12,
17,
9471,
272,
4203,
275,
2008,
8,
8147,
9,
272,
302,
275,
822,
8,
2293,
9,
272,
340,
519,
365,
488,
26,
267,
519,
275,
302,
272,
4918,
275,
769,
8,
1842,
8,
78,
430,
272,
19001,
275,
769,
8,
1842,
8,
78,
446,
519,
435,
413,
12,
302,
435,
413,
430,
14172,
17,
61,
272,
1995,
2008,
8,
2293,
59,
73,
61,
367,
284,
315,
4918,
1491,
82,
566,
272,
1830,
302,
26,
267,
367,
284,
315,
10822,
8,
1842,
8,
82,
2298,
288,
19001,
59,
73,
61,
4862,
413,
288,
340,
19001,
59,
73,
61,
508,
378,
26,
355,
4918,
59,
73,
2938,
275,
4918,
59,
73,
435,
413,
2938,
435,
4918,
59,
73,
26,
73,
435,
413,
61,
355,
19001,
59,
73,
61,
275,
302,
446,
284,
288,
587,
26,
355,
1335,
275,
19001,
59,
73,
61,
355,
4918,
59,
73,
467,
4918,
1988,
74,
61,
275,
4918,
1988,
74,
467,
4918,
59,
73,
61,
355,
1995,
2008,
8,
2293,
59,
73,
61,
367,
284,
315,
4918,
1491,
82,
566,
355,
2059,
267,
587,
26,
288,
372,
199,
199,
3,
11606,
1455,
921,
600,
14,
32595,
14,
957,
15,
25200,
15,
12255,
8557,
15,
199,
318,
302,
63,
544,
8764,
8,
544,
287,
63,
835,
304,
272,
408,
46,
13,
49,
310,
8764,
10196,
14,
272,
3033,
26,
17414,
287,
63,
835,
26,
314,
1329,
402,
17414,
8764,
370,
14241,
367,
12,
2011,
465,
13811,
1568,
14,
272,
23771,
83,
26,
17991,
8653,
370,
314,
5160,
12,
1924,
28653,
574,
365,
282,
653,
13,
2960,
14,
272,
408,
272,
8850,
275,
1425,
8,
544,
287,
63,
835,
9,
272,
367,
10782,
315,
26899,
8,
4574,
304,
267,
340,
334,
544,
287,
63,
835,
508,
822,
8,
409,
8,
6046,
59,
73,
61,
435,
284,
367,
284,
315,
8850,
430,
717,
508,
822,
8,
409,
8,
6046,
59,
73,
61,
446,
284,
367,
284,
315,
8850,
15206,
288,
1995,
10782,
199,
199,
3949,
5680,
199,
3,
27067,
3217,
199,
199,
12648,
63,
1162,
275,
469,
272,
334,
1400,
12,
5661,
304,
334,
17,
12,
959,
395,
272,
334,
1960,
12,
5661,
304,
334,
17,
12,
1227,
395,
272,
334,
5279,
12,
2948,
304,
334,
17,
12,
1520,
395,
272,
334,
13128,
12,
2948,
304,
334,
17,
12,
1695,
395,
199,
93,
199,
199,
318,
25425,
63,
2758,
8,
1162,
304,
272,
522,
275,
488,
272,
347,
1255,
837,
267,
2222,
1832,
522,
267,
367,
485,
315,
1425,
8,
1162,
59,
16,
4682,
288,
522,
275,
822,
8,
513,
8,
78,
63,
544,
8764,
8,
1162,
59,
17,
11845,
272,
347,
754,
837,
267,
372,
1862,
59,
16,
61,
627,
1616,
1011,
334,
1162,
59,
17,
61,
446,
650,
395,
522,
272,
372,
1255,
12,
754,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
GdZ/scriptfile
|
software/googleAppEngine/lib/django_1_4/django/contrib/localflavor/id/forms.py
|
87
|
7181
|
"""
ID-specific Form helpers
"""
from __future__ import absolute_import
import re
import time
from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
from django.forms.fields import Field, Select
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_unicode
postcode_re = re.compile(r'^[1-9]\d{4}$')
phone_re = re.compile(r'^(\+62|0)[2-9]\d{7,10}$')
plate_re = re.compile(r'^(?P<prefix>[A-Z]{1,2}) ' + \
r'(?P<number>\d{1,5})( (?P<suffix>([A-Z]{1,3}|[1-9][0-9]{,2})))?$')
nik_re = re.compile(r'^\d{16}$')
class IDPostCodeField(Field):
"""
An Indonesian post code field.
http://id.wikipedia.org/wiki/Kode_pos
"""
default_error_messages = {
'invalid': _('Enter a valid post code'),
}
def clean(self, value):
super(IDPostCodeField, self).clean(value)
if value in EMPTY_VALUES:
return u''
value = value.strip()
if not postcode_re.search(value):
raise ValidationError(self.error_messages['invalid'])
if int(value) < 10110:
raise ValidationError(self.error_messages['invalid'])
# 1xxx0
if value[0] == '1' and value[4] != '0':
raise ValidationError(self.error_messages['invalid'])
return u'%s' % (value, )
class IDProvinceSelect(Select):
"""
A Select widget that uses a list of provinces of Indonesia as its
choices.
"""
def __init__(self, attrs=None):
# Load data in memory only when it is required, see also #17275
from django.contrib.localflavor.id.id_choices import PROVINCE_CHOICES
super(IDProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES)
class IDPhoneNumberField(Field):
"""
An Indonesian telephone number field.
http://id.wikipedia.org/wiki/Daftar_kode_telepon_di_Indonesia
"""
default_error_messages = {
'invalid': _('Enter a valid phone number'),
}
def clean(self, value):
super(IDPhoneNumberField, self).clean(value)
if value in EMPTY_VALUES:
return u''
phone_number = re.sub(r'[\-\s\(\)]', '', smart_unicode(value))
if phone_re.search(phone_number):
return smart_unicode(value)
raise ValidationError(self.error_messages['invalid'])
class IDLicensePlatePrefixSelect(Select):
"""
A Select widget that uses a list of vehicle license plate prefix code
of Indonesia as its choices.
http://id.wikipedia.org/wiki/Tanda_Nomor_Kendaraan_Bermotor
"""
def __init__(self, attrs=None):
# Load data in memory only when it is required, see also #17275
from django.contrib.localflavor.id.id_choices import LICENSE_PLATE_PREFIX_CHOICES
super(IDLicensePlatePrefixSelect, self).__init__(attrs,
choices=LICENSE_PLATE_PREFIX_CHOICES)
class IDLicensePlateField(Field):
"""
An Indonesian vehicle license plate field.
http://id.wikipedia.org/wiki/Tanda_Nomor_Kendaraan_Bermotor
Plus: "B 12345 12"
"""
default_error_messages = {
'invalid': _('Enter a valid vehicle license plate number'),
}
def clean(self, value):
# Load data in memory only when it is required, see also #17275
from django.contrib.localflavor.id.id_choices import LICENSE_PLATE_PREFIX_CHOICES
super(IDLicensePlateField, self).clean(value)
if value in EMPTY_VALUES:
return u''
plate_number = re.sub(r'\s+', ' ',
smart_unicode(value.strip())).upper()
matches = plate_re.search(plate_number)
if matches is None:
raise ValidationError(self.error_messages['invalid'])
# Make sure prefix is in the list of known codes.
prefix = matches.group('prefix')
if prefix not in [choice[0] for choice in LICENSE_PLATE_PREFIX_CHOICES]:
raise ValidationError(self.error_messages['invalid'])
# Only Jakarta (prefix B) can have 3 letter suffix.
suffix = matches.group('suffix')
if suffix is not None and len(suffix) == 3 and prefix != 'B':
raise ValidationError(self.error_messages['invalid'])
# RI plates don't have suffix.
if prefix == 'RI' and suffix is not None and suffix != '':
raise ValidationError(self.error_messages['invalid'])
# Number can't be zero.
number = matches.group('number')
if number == '0':
raise ValidationError(self.error_messages['invalid'])
# CD, CC and B 12345 12
if len(number) == 5 or prefix in ('CD', 'CC'):
# suffix must be numeric and non-empty
if re.match(r'^\d+$', suffix) is None:
raise ValidationError(self.error_messages['invalid'])
# Known codes range is 12-124
if prefix in ('CD', 'CC') and not (12 <= int(number) <= 124):
raise ValidationError(self.error_messages['invalid'])
if len(number) == 5 and not (12 <= int(suffix) <= 124):
raise ValidationError(self.error_messages['invalid'])
else:
# suffix must be non-numeric
if suffix is not None and re.match(r'^[A-Z]{,3}$', suffix) is None:
raise ValidationError(self.error_messages['invalid'])
return plate_number
class IDNationalIdentityNumberField(Field):
"""
An Indonesian national identity number (NIK/KTP#) field.
http://id.wikipedia.org/wiki/Nomor_Induk_Kependudukan
xx.xxxx.ddmmyy.xxxx - 16 digits (excl. dots)
"""
default_error_messages = {
'invalid': _('Enter a valid NIK/KTP number'),
}
def clean(self, value):
super(IDNationalIdentityNumberField, self).clean(value)
if value in EMPTY_VALUES:
return u''
value = re.sub(r'[\s.]', '', smart_unicode(value))
if not nik_re.search(value):
raise ValidationError(self.error_messages['invalid'])
if int(value) == 0:
raise ValidationError(self.error_messages['invalid'])
def valid_nik_date(year, month, day):
try:
t1 = (int(year), int(month), int(day), 0, 0, 0, 0, 0, -1)
d = time.mktime(t1)
t2 = time.localtime(d)
if t1[:3] != t2[:3]:
return False
else:
return True
except (OverflowError, ValueError):
return False
year = int(value[10:12])
month = int(value[8:10])
day = int(value[6:8])
current_year = time.localtime().tm_year
if year < int(str(current_year)[-2:]):
if not valid_nik_date(2000 + int(year), month, day):
raise ValidationError(self.error_messages['invalid'])
elif not valid_nik_date(1900 + int(year), month, day):
raise ValidationError(self.error_messages['invalid'])
if value[:6] == '000000' or value[12:] == '0000':
raise ValidationError(self.error_messages['invalid'])
return '%s.%s.%s.%s' % (value[:2], value[2:6], value[6:12], value[12:])
|
mit
|
[
624,
199,
998,
13,
6100,
8204,
10897,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
295,
199,
646,
900,
199,
199,
504,
1639,
14,
1018,
14,
11346,
492,
16589,
63,
15514,
199,
504,
1639,
14,
3351,
492,
8505,
199,
504,
1639,
14,
3351,
14,
955,
492,
5024,
12,
9496,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
2975,
421,
199,
1932,
600,
63,
264,
275,
295,
14,
2014,
8,
82,
23811,
17,
13,
25,
7272,
68,
91,
20,
93,
9988,
199,
9339,
63,
264,
275,
295,
14,
2014,
8,
82,
31344,
11,
2789,
92,
16,
2788,
18,
13,
25,
7272,
68,
91,
23,
12,
709,
93,
9988,
199,
17673,
63,
264,
275,
295,
14,
2014,
8,
82,
24550,
48,
28,
1861,
9514,
33,
13,
58,
8194,
17,
12,
18,
1552,
283,
435,
971,
288,
519,
10120,
48,
28,
1955,
3072,
68,
91,
17,
12,
21,
1552,
8,
7558,
48,
28,
4511,
30,
779,
33,
13,
58,
8194,
17,
12,
19,
93,
17884,
17,
13,
25,
1527,
16,
13,
25,
8194,
12,
18,
93,
1724,
31,
9988,
199,
22998,
63,
264,
275,
295,
14,
2014,
8,
82,
15542,
68,
91,
975,
93,
9988,
421,
199,
533,
2870,
6564,
3034,
792,
8,
792,
304,
272,
408,
272,
1626,
473,
977,
368,
6214,
2963,
1233,
901,
14,
339,
1455,
921,
344,
14,
13961,
14,
1308,
15,
6797,
15,
43,
380,
63,
1712,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
4018,
8468,
282,
1686,
2963,
1233,
659,
272,
789,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
1613,
8,
998,
6564,
3034,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
398,
574,
275,
574,
14,
1913,
342,
267,
340,
440,
2963,
600,
63,
264,
14,
1733,
8,
585,
304,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
398,
340,
1109,
8,
585,
9,
665,
14313,
709,
26,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
398,
327,
413,
10013,
16,
267,
340,
574,
59,
16,
61,
508,
283,
17,
7,
436,
574,
59,
20,
61,
1137,
283,
16,
356,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
398,
372,
399,
5956,
83,
7,
450,
334,
585,
12,
776,
421,
199,
533,
2870,
919,
86,
2855,
5446,
8,
5446,
304,
272,
408,
272,
437,
9496,
3938,
626,
4440,
282,
769,
402,
557,
11908,
823,
402,
473,
977,
368,
10971,
465,
2399,
272,
3415,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
3290,
29,
403,
304,
267,
327,
7190,
666,
315,
4402,
1454,
1380,
652,
365,
1415,
12,
1937,
2597,
327,
1196,
13643,
267,
687,
1639,
14,
2828,
14,
320,
696,
276,
4271,
14,
344,
14,
344,
63,
4577,
492,
3611,
54,
568,
2089,
63,
16236,
267,
1613,
8,
998,
919,
86,
2855,
5446,
12,
291,
2843,
826,
721,
3288,
12,
3415,
29,
2514,
54,
568,
2089,
63,
16236,
9,
421,
199,
533,
2870,
25640,
792,
8,
792,
304,
272,
408,
272,
1626,
473,
977,
368,
6214,
14001,
9339,
1329,
901,
14,
339,
1455,
921,
344,
14,
13961,
14,
1308,
15,
6797,
15,
25014,
856,
285,
63,
75,
380,
63,
15253,
678,
63,
328,
63,
607,
4456,
10971,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
4018,
8468,
282,
1686,
14617,
1329,
659,
272,
789,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
1613,
8,
998,
25640,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
398,
14617,
63,
1955,
275,
295,
14,
954,
8,
82,
22123,
2696,
83,
29323,
1874,
297,
3260,
11179,
63,
2975,
8,
585,
430,
398,
340,
14617,
63,
264,
14,
1733,
8,
9339,
63,
1955,
304,
288,
372,
11179,
63,
2975,
8,
585,
9,
398,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
421,
199,
533,
2870,
3761,
29020,
4793,
5446,
8,
5446,
304,
272,
408,
272,
437,
9496,
3938,
626,
4440,
282,
769,
402,
27616,
4190,
299,
750,
2403,
1233,
272,
402,
473,
977,
368,
10971,
465,
2399,
3415,
14,
339,
1455,
921,
344,
14,
13961,
14,
1308,
15,
6797,
15,
52,
18328,
63,
46,
676,
269,
63,
43,
500,
17956,
290,
63,
24947,
27840,
272,
408,
339,
347,
636,
826,
721,
277,
12,
3290,
29,
403,
304,
267,
327,
7190,
666,
315,
4402,
1454,
1380,
652,
365,
1415,
12,
1937,
2597,
327,
1196,
13643,
267,
687,
1639,
14,
2828,
14,
320,
696,
276,
4271,
14,
344,
14,
344,
63,
4577,
492,
5113,
63,
2749,
1951,
63,
6351,
63,
16236,
267,
1613,
8,
998,
3761,
29020,
4793,
5446,
12,
291,
2843,
826,
721,
3288,
12,
288,
3415,
29,
3961,
63,
2749,
1951,
63,
6351,
63,
16236,
9,
421,
199,
533,
2870,
3761,
29020,
792,
8,
792,
304,
272,
408,
272,
1626,
473,
977,
368,
6214,
27616,
4190,
299,
750,
901,
14,
339,
1455,
921,
344,
14,
13961,
14,
1308,
15,
6797,
15,
52,
18328,
63,
46,
676,
269,
63,
43,
500,
17956,
290,
63,
24947,
27840,
339,
7497,
527,
26,
298,
34,
25538,
3144,
2,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
4018,
8468,
282,
1686,
27616,
4190,
299,
750,
1329,
659,
272,
789,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
327,
7190,
666,
315,
4402,
1454,
1380,
652,
365,
1415,
12,
1937,
2597,
327,
1196,
13643,
267,
687,
1639,
14,
2828,
14,
320,
696,
276,
4271,
14,
344,
14,
344,
63,
4577,
492,
5113,
63,
2749,
1951,
63,
6351,
63,
16236,
267,
1613,
8,
998,
3761,
29020,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
398,
299,
750,
63,
1955,
275,
295,
14,
954,
8,
82,
1154,
83,
7386,
283,
1656,
288,
11179,
63,
2975,
8,
585,
14,
1913,
4059,
14,
4142,
342,
398,
4450,
275,
299,
750,
63,
264,
14,
1733,
8,
17673,
63
] |
[
199,
998,
13,
6100,
8204,
10897,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
295,
199,
646,
900,
199,
199,
504,
1639,
14,
1018,
14,
11346,
492,
16589,
63,
15514,
199,
504,
1639,
14,
3351,
492,
8505,
199,
504,
1639,
14,
3351,
14,
955,
492,
5024,
12,
9496,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
2975,
421,
199,
1932,
600,
63,
264,
275,
295,
14,
2014,
8,
82,
23811,
17,
13,
25,
7272,
68,
91,
20,
93,
9988,
199,
9339,
63,
264,
275,
295,
14,
2014,
8,
82,
31344,
11,
2789,
92,
16,
2788,
18,
13,
25,
7272,
68,
91,
23,
12,
709,
93,
9988,
199,
17673,
63,
264,
275,
295,
14,
2014,
8,
82,
24550,
48,
28,
1861,
9514,
33,
13,
58,
8194,
17,
12,
18,
1552,
283,
435,
971,
288,
519,
10120,
48,
28,
1955,
3072,
68,
91,
17,
12,
21,
1552,
8,
7558,
48,
28,
4511,
30,
779,
33,
13,
58,
8194,
17,
12,
19,
93,
17884,
17,
13,
25,
1527,
16,
13,
25,
8194,
12,
18,
93,
1724,
31,
9988,
199,
22998,
63,
264,
275,
295,
14,
2014,
8,
82,
15542,
68,
91,
975,
93,
9988,
421,
199,
533,
2870,
6564,
3034,
792,
8,
792,
304,
272,
408,
272,
1626,
473,
977,
368,
6214,
2963,
1233,
901,
14,
339,
1455,
921,
344,
14,
13961,
14,
1308,
15,
6797,
15,
43,
380,
63,
1712,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
4018,
8468,
282,
1686,
2963,
1233,
659,
272,
789,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
1613,
8,
998,
6564,
3034,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
398,
574,
275,
574,
14,
1913,
342,
267,
340,
440,
2963,
600,
63,
264,
14,
1733,
8,
585,
304,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
398,
340,
1109,
8,
585,
9,
665,
14313,
709,
26,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
398,
327,
413,
10013,
16,
267,
340,
574,
59,
16,
61,
508,
283,
17,
7,
436,
574,
59,
20,
61,
1137,
283,
16,
356,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
398,
372,
399,
5956,
83,
7,
450,
334,
585,
12,
776,
421,
199,
533,
2870,
919,
86,
2855,
5446,
8,
5446,
304,
272,
408,
272,
437,
9496,
3938,
626,
4440,
282,
769,
402,
557,
11908,
823,
402,
473,
977,
368,
10971,
465,
2399,
272,
3415,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
3290,
29,
403,
304,
267,
327,
7190,
666,
315,
4402,
1454,
1380,
652,
365,
1415,
12,
1937,
2597,
327,
1196,
13643,
267,
687,
1639,
14,
2828,
14,
320,
696,
276,
4271,
14,
344,
14,
344,
63,
4577,
492,
3611,
54,
568,
2089,
63,
16236,
267,
1613,
8,
998,
919,
86,
2855,
5446,
12,
291,
2843,
826,
721,
3288,
12,
3415,
29,
2514,
54,
568,
2089,
63,
16236,
9,
421,
199,
533,
2870,
25640,
792,
8,
792,
304,
272,
408,
272,
1626,
473,
977,
368,
6214,
14001,
9339,
1329,
901,
14,
339,
1455,
921,
344,
14,
13961,
14,
1308,
15,
6797,
15,
25014,
856,
285,
63,
75,
380,
63,
15253,
678,
63,
328,
63,
607,
4456,
10971,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
4018,
8468,
282,
1686,
14617,
1329,
659,
272,
789,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
1613,
8,
998,
25640,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
398,
14617,
63,
1955,
275,
295,
14,
954,
8,
82,
22123,
2696,
83,
29323,
1874,
297,
3260,
11179,
63,
2975,
8,
585,
430,
398,
340,
14617,
63,
264,
14,
1733,
8,
9339,
63,
1955,
304,
288,
372,
11179,
63,
2975,
8,
585,
9,
398,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
421,
199,
533,
2870,
3761,
29020,
4793,
5446,
8,
5446,
304,
272,
408,
272,
437,
9496,
3938,
626,
4440,
282,
769,
402,
27616,
4190,
299,
750,
2403,
1233,
272,
402,
473,
977,
368,
10971,
465,
2399,
3415,
14,
339,
1455,
921,
344,
14,
13961,
14,
1308,
15,
6797,
15,
52,
18328,
63,
46,
676,
269,
63,
43,
500,
17956,
290,
63,
24947,
27840,
272,
408,
339,
347,
636,
826,
721,
277,
12,
3290,
29,
403,
304,
267,
327,
7190,
666,
315,
4402,
1454,
1380,
652,
365,
1415,
12,
1937,
2597,
327,
1196,
13643,
267,
687,
1639,
14,
2828,
14,
320,
696,
276,
4271,
14,
344,
14,
344,
63,
4577,
492,
5113,
63,
2749,
1951,
63,
6351,
63,
16236,
267,
1613,
8,
998,
3761,
29020,
4793,
5446,
12,
291,
2843,
826,
721,
3288,
12,
288,
3415,
29,
3961,
63,
2749,
1951,
63,
6351,
63,
16236,
9,
421,
199,
533,
2870,
3761,
29020,
792,
8,
792,
304,
272,
408,
272,
1626,
473,
977,
368,
6214,
27616,
4190,
299,
750,
901,
14,
339,
1455,
921,
344,
14,
13961,
14,
1308,
15,
6797,
15,
52,
18328,
63,
46,
676,
269,
63,
43,
500,
17956,
290,
63,
24947,
27840,
339,
7497,
527,
26,
298,
34,
25538,
3144,
2,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
4018,
8468,
282,
1686,
27616,
4190,
299,
750,
1329,
659,
272,
789,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
327,
7190,
666,
315,
4402,
1454,
1380,
652,
365,
1415,
12,
1937,
2597,
327,
1196,
13643,
267,
687,
1639,
14,
2828,
14,
320,
696,
276,
4271,
14,
344,
14,
344,
63,
4577,
492,
5113,
63,
2749,
1951,
63,
6351,
63,
16236,
267,
1613,
8,
998,
3761,
29020,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
398,
299,
750,
63,
1955,
275,
295,
14,
954,
8,
82,
1154,
83,
7386,
283,
1656,
288,
11179,
63,
2975,
8,
585,
14,
1913,
4059,
14,
4142,
342,
398,
4450,
275,
299,
750,
63,
264,
14,
1733,
8,
17673,
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,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S_NOTIFY = 4
DNS_UPDATE = 5
# Flags
DNS_CD = 0x0010 # checking disabled
DNS_AD = 0x0020 # authenticated data
DNS_Z = 0x0040 # unused
DNS_RA = 0x0080 # recursion available
DNS_RD = 0x0100 # recursion desired
DNS_TC = 0x0200 # truncated
DNS_AA = 0x0400 # authoritative answer
# Response codes
DNS_RCODE_NOERR = 0
DNS_RCODE_FORMERR = 1
DNS_RCODE_SERVFAIL = 2
DNS_RCODE_NXDOMAIN = 3
DNS_RCODE_NOTIMP = 4
DNS_RCODE_REFUSED = 5
DNS_RCODE_YXDOMAIN = 6
DNS_RCODE_YXRRSET = 7
DNS_RCODE_NXRRSET = 8
DNS_RCODE_NOTAUTH = 9
DNS_RCODE_NOTZONE = 10
# RR types
DNS_A = 1
DNS_NS = 2
DNS_CNAME = 5
DNS_SOA = 6
DNS_PTR = 12
DNS_HINFO = 13
DNS_MX = 15
DNS_TXT = 16
DNS_AAAA = 28
DNS_SRV = 33
# RR classes
DNS_IN = 1
DNS_CHAOS = 3
DNS_HESIOD = 4
DNS_ANY = 255
def pack_name(name, off, label_ptrs):
if name:
labels = name.split('.')
else:
labels = []
labels.append('')
buf = ''
for i, label in enumerate(labels):
key = '.'.join(labels[i:]).upper()
ptr = label_ptrs.get(key)
if not ptr:
if len(key) > 1:
ptr = off + len(buf)
if ptr < 0xc000:
label_ptrs[key] = ptr
i = len(label)
buf += chr(i) + label
else:
buf += struct.pack('>H', (0xc000 | ptr))
break
return buf
def unpack_name(buf, off):
name = ''
saved_off = 0
for i in range(100): # XXX
n = ord(buf[off])
if n == 0:
off += 1
break
elif (n & 0xc0) == 0xc0:
ptr = struct.unpack('>H', buf[off:off+2])[0] & 0x3fff
off += 2
if not saved_off:
saved_off = off
# XXX - don't use recursion!@#$
name = name + unpack_name(buf, ptr)[0] + '.'
break
else:
off += 1
name = name + buf[off:off+n] + '.'
if len(name) > 255:
raise dpkt.UnpackError('name longer than 255 bytes')
off += n
return name.strip('.'), off
class DNS(dpkt.Packet):
__hdr__ = (
('id', 'H', 0),
('op', 'H', DNS_RD), # recursive query
# XXX - lists of query, RR objects
('qd', 'H', []),
('an', 'H', []),
('ns', 'H', []),
('ar', 'H', [])
)
def get_qr(self):
return int((self.op & 0x8000) == 0x8000)
def set_qr(self, v):
if v: self.op |= 0x8000
else: self.op &= ~0x8000
qr = property(get_qr, set_qr)
def get_opcode(self):
return (self.op >> 11) & 0xf
def set_opcode(self, v):
self.op = (self.op & ~0x7800) | ((v & 0xf) << 11)
opcode = property(get_opcode, set_opcode)
def get_rcode(self):
return self.op & 0xf
def set_rcode(self, v):
self.op = (self.op & ~0xf) | (v & 0xf)
rcode = property(get_rcode, set_rcode)
class Q(dpkt.Packet):
"""DNS question."""
__hdr__ = (
('name', '1025s', ''),
('type', 'H', DNS_A),
('cls', 'H', DNS_IN)
)
# XXX - suk
def __len__(self):
raise NotImplementedError
__str__ = __len__
def unpack(self, buf):
raise NotImplementedError
class RR(Q):
"""DNS resource record."""
__hdr__ = (
('name', '1025s', ''),
('type', 'H', DNS_A),
('cls', 'H', DNS_IN),
('ttl', 'I', 0),
('rlen', 'H', 4),
('rdata', 's', '')
)
def pack_rdata(self, off, label_ptrs):
# XXX - yeah, this sux
if self.rdata:
return self.rdata
if self.type == DNS_A:
return self.ip
elif self.type == DNS_NS:
return pack_name(self.nsname, off, label_ptrs)
elif self.type == DNS_CNAME:
return pack_name(self.cname, off, label_ptrs)
elif self.type == DNS_PTR:
return pack_name(self.ptrname, off, label_ptrs)
elif self.type == DNS_SOA:
l = []
l.append(pack_name(self.mname, off, label_ptrs))
l.append(pack_name(self.rname, off + len(l[0]), label_ptrs))
l.append(struct.pack('>IIIII', self.serial, self.refresh,
self.retry, self.expire, self.minimum))
return ''.join(l)
elif self.type == DNS_MX:
return struct.pack('>H', self.preference) + \
pack_name(self.mxname, off + 2, label_ptrs)
elif self.type == DNS_TXT or self.type == DNS_HINFO:
return ''.join([ '%s%s' % (chr(len(x)), x)
for x in self.text ])
elif self.type == DNS_AAAA:
return self.ip6
elif self.type == DNS_SRV:
return struct.pack('>HHH', self.priority, self.weight, self.port) + \
pack_name(self.srvname, off + 6, label_ptrs)
def unpack_rdata(self, buf, off):
if self.type == DNS_A:
self.ip = self.rdata
elif self.type == DNS_NS:
self.nsname, off = unpack_name(buf, off)
elif self.type == DNS_CNAME:
self.cname, off = unpack_name(buf, off)
elif self.type == DNS_PTR:
self.ptrname, off = unpack_name(buf, off)
elif self.type == DNS_SOA:
self.mname, off = unpack_name(buf, off)
self.rname, off = unpack_name(buf, off)
self.serial, self.refresh, self.retry, self.expire, \
self.minimum = struct.unpack('>IIIII', buf[off:off+20])
elif self.type == DNS_MX:
self.preference = struct.unpack('>H', self.rdata[:2])
self.mxname, off = unpack_name(buf, off+2)
elif self.type == DNS_TXT or self.type == DNS_HINFO:
self.text = []
buf = self.rdata
while buf:
n = ord(buf[0])
self.text.append(buf[1:1+n])
buf = buf[1+n:]
elif self.type == DNS_AAAA:
self.ip6 = self.rdata
elif self.type == DNS_SRV:
self.priority, self.weight, self.port = \
struct.unpack('>HHH', self.rdata[:6])
self.srvname, off = unpack_name(buf, off+6)
def pack_q(self, buf, q):
"""Append packed DNS question and return buf."""
return buf + pack_name(q.name, len(buf), self.label_ptrs) + \
struct.pack('>HH', q.type, q.cls)
def unpack_q(self, buf, off):
"""Return DNS question and new offset."""
q = self.Q()
q.name, off = unpack_name(buf, off)
q.type, q.cls = struct.unpack('>HH', buf[off:off+4])
off += 4
return q, off
def pack_rr(self, buf, rr):
"""Append packed DNS RR and return buf."""
name = pack_name(rr.name, len(buf), self.label_ptrs)
rdata = rr.pack_rdata(len(buf) + len(name) + 10, self.label_ptrs)
return buf + name + struct.pack('>HHIH', rr.type, rr.cls, rr.ttl,
len(rdata)) + rdata
def unpack_rr(self, buf, off):
"""Return DNS RR and new offset."""
rr = self.RR()
rr.name, off = unpack_name(buf, off)
rr.type, rr.cls, rr.ttl, rdlen = struct.unpack('>HHIH', buf[off:off+10])
off += 10
rr.rdata = buf[off:off+rdlen]
rr.unpack_rdata(buf, off)
off += rdlen
return rr, off
def unpack(self, buf):
dpkt.Packet.unpack(self, buf)
off = self.__hdr_len__
cnt = self.qd
self.qd = []
for i in range(cnt):
q, off = self.unpack_q(buf, off)
self.qd.append(q)
for x in ('an', 'ns', 'ar'):
cnt = getattr(self, x, 0)
setattr(self, x, [])
for i in range(cnt):
rr, off = self.unpack_rr(buf, off)
getattr(self, x).append(rr)
self.data = ''
def __len__(self):
# XXX - cop out
return len(str(self))
def __str__(self):
# XXX - compress names on the fly
self.label_ptrs = {}
buf = struct.pack(self.__hdr_fmt__, self.id, self.op, len(self.qd),
len(self.an), len(self.ns), len(self.ar))
for q in self.qd:
buf = self.pack_q(buf, q)
for x in ('an', 'ns', 'ar'):
for rr in getattr(self, x):
buf = self.pack_rr(buf, rr)
del self.label_ptrs
return buf
if __name__ == '__main__':
import unittest
from ip import IP
class DNSTestCase(unittest.TestCase):
def test_basic(self):
s = 'E\x00\x02\x08\xc15\x00\x00\x80\x11\x92aBk0\x01Bk0w\x005\xc07\x01\xf4\xda\xc2d\xd2\x81\x80\x00\x01\x00\x03\x00\x0b\x00\x0b\x03www\x06google\x03com\x00\x00\x01\x00\x01\xc0\x0c\x00\x05\x00\x01\x00\x00\x03V\x00\x17\x03www\x06google\x06akadns\x03net\x00\xc0,\x00\x01\x00\x01\x00\x00\x01\xa3\x00\x04@\xe9\xabh\xc0,\x00\x01\x00\x01\x00\x00\x01\xa3\x00\x04@\xe9\xabc\xc07\x00\x02\x00\x01\x00\x00KG\x00\x0c\x04usw5\x04akam\xc0>\xc07\x00\x02\x00\x01\x00\x00KG\x00\x07\x04usw6\xc0t\xc07\x00\x02\x00\x01\x00\x00KG\x00\x07\x04usw7\xc0t\xc07\x00\x02\x00\x01\x00\x00KG\x00\x08\x05asia3\xc0t\xc07\x00\x02\x00\x01\x00\x00KG\x00\x05\x02za\xc07\xc07\x00\x02\x00\x01\x00\x00KG\x00\x0f\x02zc\x06akadns\x03org\x00\xc07\x00\x02\x00\x01\x00\x00KG\x00\x05\x02zf\xc07\xc07\x00\x02\x00\x01\x00\x00KG\x00\x05\x02zh\xc0\xd5\xc07\x00\x02\x00\x01\x00\x00KG\x00\x07\x04eur3\xc0t\xc07\x00\x02\x00\x01\x00\x00KG\x00\x07\x04use2\xc0t\xc07\x00\x02\x00\x01\x00\x00KG\x00\x07\x04use4\xc0t\xc0\xc1\x00\x01\x00\x01\x00\x00\xfb4\x00\x04\xd0\xb9\x84\xb0\xc0\xd2\x00\x01\x00\x01\x00\x001\x0c\x00\x04?\xf1\xc76\xc0\xed\x00\x01\x00\x01\x00\x00\xfb4\x00\x04?\xd7\xc6S\xc0\xfe\x00\x01\x00\x01\x00\x001\x0c\x00\x04?\xd00.\xc1\x0f\x00\x01\x00\x01\x00\x00\n\xdf\x00\x04\xc1-\x01g\xc1"\x00\x01\x00\x01\x00\x00\x101\x00\x04?\xd1\xaa\x88\xc15\x00\x01\x00\x01\x00\x00\r\x1a\x00\x04PCC\xb6\xc0o\x00\x01\x00\x01\x00\x00\x10\x7f\x00\x04?\xf1I\xd6\xc0\x87\x00\x01\x00\x01\x00\x00\n\xdf\x00\x04\xce\x84dl\xc0\x9a\x00\x01\x00\x01\x00\x00\n\xdf\x00\x04A\xcb\xea\x1b\xc0\xad\x00\x01\x00\x01\x00\x00\x0b)\x00\x04\xc1l\x9a\t'
ip = IP(s)
dns = DNS(ip.udp.data)
self.failUnless(dns.qd[0].name == 'www.google.com' and
dns.an[1].name == 'www.google.akadns.net')
s = '\x05\xf5\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www\x03cnn\x03com\x00\x00\x01\x00\x01'
dns = DNS(s)
self.failUnless(s == str(dns))
def test_PTR(self):
s = 'g\x02\x81\x80\x00\x01\x00\x01\x00\x03\x00\x00\x011\x011\x03211\x03141\x07in-addr\x04arpa\x00\x00\x0c\x00\x01\xc0\x0c\x00\x0c\x00\x01\x00\x00\r6\x00$\x07default\nv-umce-ifs\x05umnet\x05umich\x03edu\x00\xc0\x0e\x00\x02\x00\x01\x00\x00\r6\x00\r\x06shabby\x03ifs\xc0O\xc0\x0e\x00\x02\x00\x01\x00\x00\r6\x00\x0f\x0cfish-license\xc0m\xc0\x0e\x00\x02\x00\x01\x00\x00\r6\x00\x0b\x04dns2\x03itd\xc0O'
dns = DNS(s)
self.failUnless(dns.qd[0].name == '1.1.211.141.in-addr.arpa' and
dns.an[0].ptrname == 'default.v-umce-ifs.umnet.umich.edu' and
dns.ns[0].nsname == 'shabby.ifs.umich.edu' and
dns.ns[1].ttl == 3382L and
dns.ns[2].nsname == 'dns2.itd.umich.edu')
self.failUnless(s == str(dns))
def test_pack_name(self):
# Empty name is \0
x = pack_name('', 0, {})
self.assertEqual(x, '\0')
unittest.main()
|
mit
|
[
3,
2672,
1304,
26,
6715,
14,
647,
8087,
8315,
13,
845,
13,
2025,
17163,
26,
1081,
26,
2528,
58,
366,
11326,
352,
424,
2672,
199,
199,
624,
7705,
2812,
6187,
1041,
199,
199,
646,
2702,
199,
646,
366,
20573,
199,
199,
12323,
63,
49,
275,
378,
199,
12323,
63,
50,
275,
413,
199,
199,
3,
9319,
6021,
199,
12323,
63,
11938,
275,
378,
199,
12323,
63,
41,
11938,
275,
413,
199,
12323,
63,
6305,
275,
499,
199,
12323,
63,
24972,
275,
841,
199,
12323,
63,
10383,
275,
959,
199,
199,
3,
24870,
199,
12323,
63,
7695,
275,
378,
88,
17657,
198,
3,
7907,
6980,
199,
12323,
63,
1554,
275,
378,
88,
20734,
198,
3,
15082,
666,
199,
12323,
63,
58,
275,
221,
378,
88,
25665,
198,
3,
9563,
199,
12323,
63,
2847,
275,
378,
88,
23686,
198,
3,
16189,
2808,
199,
12323,
63,
15543,
275,
378,
88,
16569,
198,
3,
16189,
6387,
199,
12323,
63,
5708,
275,
378,
88,
24215,
198,
3,
17661,
199,
12323,
63,
2276,
275,
378,
88,
27130,
198,
3,
4132,
390,
1905,
6385,
199,
199,
3,
7232,
9479,
199,
12323,
63,
50,
6012,
63,
2826,
2666,
275,
378,
199,
12323,
63,
50,
6012,
63,
3516,
2666,
275,
413,
199,
12323,
63,
50,
6012,
63,
3279,
54,
8784,
275,
499,
199,
12323,
63,
50,
6012,
63,
16764,
7378,
275,
650,
199,
12323,
63,
50,
6012,
63,
4609,
8947,
275,
841,
199,
12323,
63,
50,
6012,
63,
8279,
8558,
275,
959,
199,
12323,
63,
50,
6012,
63,
16936,
7378,
275,
1227,
199,
12323,
63,
50,
6012,
63,
57,
12297,
50,
3597,
275,
1520,
199,
12323,
63,
50,
6012,
63,
46,
12297,
50,
3597,
275,
1695,
199,
12323,
63,
50,
6012,
63,
4609,
5580,
275,
1749,
199,
12323,
63,
50,
6012,
63,
4609,
15353,
275,
1616,
199,
199,
3,
27222,
2943,
199,
12323,
63,
33,
275,
413,
199,
12323,
63,
2709,
275,
499,
199,
12323,
63,
35,
2339,
275,
959,
199,
12323,
63,
4118,
33,
275,
1227,
199,
12323,
63,
14528,
275,
3144,
199,
12323,
63,
40,
4531,
275,
4944,
199,
12323,
63,
17401,
275,
4114,
199,
12323,
63,
17715,
275,
3193,
199,
12323,
63,
6151,
275,
7294,
199,
12323,
63,
31546,
275,
9404,
199,
199,
3,
27222,
3992,
199,
12323,
63,
568,
275,
413,
199,
12323,
63,
26363,
3100,
275,
650,
199,
12323,
63,
40,
654,
25705,
275,
841,
199,
12323,
63,
8974,
275,
5450,
199,
199,
318,
1706,
63,
354,
8,
354,
12,
2331,
12,
1768,
63,
4695,
83,
304,
272,
340,
536,
26,
267,
3628,
275,
536,
14,
1294,
7563,
272,
587,
26,
267,
3628,
275,
942,
272,
3628,
14,
740,
8355,
272,
4123,
275,
2125,
272,
367,
284,
12,
1768,
315,
3874,
8,
3512,
304,
267,
790,
275,
15671,
904,
8,
3512,
59,
73,
5728,
14,
4142,
342,
267,
12448,
275,
1768,
63,
4695,
83,
14,
362,
8,
498,
9,
267,
340,
440,
12448,
26,
288,
340,
822,
8,
498,
9,
690,
413,
26,
355,
12448,
275,
2331,
435,
822,
8,
1436,
9,
355,
340,
12448,
665,
378,
1812,
1493,
26,
490,
1768,
63,
4695,
83,
59,
498,
61,
275,
12448,
288,
284,
275,
822,
8,
1302,
9,
288,
4123,
847,
8678,
8,
73,
9,
435,
1768,
267,
587,
26,
288,
4123,
847,
2702,
14,
1389,
16099,
40,
297,
334,
16,
1812,
1493,
1204,
12448,
430,
288,
2059,
272,
372,
4123,
199,
199,
318,
7787,
63,
354,
8,
1436,
12,
2331,
304,
272,
536,
275,
2125,
272,
6290,
63,
1997,
275,
378,
272,
367,
284,
315,
1425,
8,
1960,
304,
327,
5787,
267,
302,
275,
6206,
8,
1436,
59,
1997,
566,
267,
340,
302,
508,
378,
26,
288,
2331,
847,
413,
288,
2059,
267,
916,
334,
78,
1253,
378,
1812,
16,
9,
508,
378,
1812,
16,
26,
288,
12448,
275,
2702,
14,
5301,
16099,
40,
297,
4123,
59,
1997,
26,
1997,
11,
18,
11057,
16,
61,
1253,
378,
88,
19,
18190,
288,
2331,
847,
499,
288,
340,
440,
6290,
63,
1997,
26,
355,
6290,
63,
1997,
275,
2331,
288,
327,
5787,
446,
2793,
1133,
675,
16189,
1,
32,
3,
4,
288,
536,
275,
536,
435,
7787,
63,
354,
8,
1436,
12,
12448,
2788,
16,
61,
435,
7815,
288,
2059,
267,
587,
26,
288,
2331,
847,
413,
288,
536,
275,
536,
435,
4123,
59,
1997,
26,
1997,
11,
78,
61,
435,
7815,
288,
340,
822,
8,
354,
9,
690,
5450,
26,
355,
746,
366,
20573,
14,
26472,
547,
360,
354,
8088,
2419,
5450,
2783,
358,
288,
2331,
847,
302,
272,
372,
536,
14,
1913,
5175,
659,
2331,
199,
199,
533,
10237,
8,
68,
20573,
14,
2726,
304,
272,
636,
11244,
363,
275,
334,
267,
661,
344,
297,
283,
40,
297,
378,
395,
267,
661,
411,
297,
283,
40,
297,
10237,
63,
15543,
395,
198,
3,
9133,
1827,
267,
327,
5787,
446,
5548,
402,
1827,
12,
27222,
2251,
267,
661,
23097,
297,
283,
40,
297,
14431,
267,
661,
290,
297,
283,
40,
297,
14431,
267,
661,
561,
297,
283,
40,
297,
14431,
267,
661,
285,
297,
283,
40,
297,
3073,
267,
776,
272,
347,
664,
63,
16596,
8,
277,
304,
267,
372,
1109,
1332,
277,
14,
411,
1253,
378,
88,
15214,
9,
508,
378,
88,
15214,
9,
272,
347,
663,
63,
16596,
8,
277,
12,
373,
304,
267,
340,
373,
26,
291,
14,
411,
8901,
378,
88,
15214,
267,
587,
26,
291,
14,
411,
18415,
6146,
16,
88,
15214,
272,
29757,
275,
3324,
8,
362,
63,
16596,
12,
663,
63,
16596,
9,
339,
347,
664,
63,
14325,
8,
277,
304,
267,
372,
334,
277,
14,
411,
4331,
4119,
9,
1253,
378,
1949,
272,
347,
663,
63,
14325,
8,
277,
12,
373,
304,
267,
291,
14,
411,
275,
334,
277,
14,
411,
1253,
6146,
16,
88,
2277,
383,
9,
1204,
3666,
86,
1253,
378,
1949,
9,
5213,
4119,
9,
272,
10508,
275,
3324,
8,
362,
63,
14325,
12,
663,
63,
14325,
9,
339,
347,
664,
63,
82,
600,
8,
277,
304,
267,
372,
291,
14,
411,
1253,
378,
1949,
272,
347,
663,
63,
82,
600,
8,
277,
12,
373,
304,
267,
291,
14,
411,
275,
334,
277,
14,
411,
1253,
6146,
16,
1949,
9,
1204,
334,
86,
1253,
378,
1949,
9,
272
] |
[
2672,
1304,
26,
6715,
14,
647,
8087,
8315,
13,
845,
13,
2025,
17163,
26,
1081,
26,
2528,
58,
366,
11326,
352,
424,
2672,
199,
199,
624,
7705,
2812,
6187,
1041,
199,
199,
646,
2702,
199,
646,
366,
20573,
199,
199,
12323,
63,
49,
275,
378,
199,
12323,
63,
50,
275,
413,
199,
199,
3,
9319,
6021,
199,
12323,
63,
11938,
275,
378,
199,
12323,
63,
41,
11938,
275,
413,
199,
12323,
63,
6305,
275,
499,
199,
12323,
63,
24972,
275,
841,
199,
12323,
63,
10383,
275,
959,
199,
199,
3,
24870,
199,
12323,
63,
7695,
275,
378,
88,
17657,
198,
3,
7907,
6980,
199,
12323,
63,
1554,
275,
378,
88,
20734,
198,
3,
15082,
666,
199,
12323,
63,
58,
275,
221,
378,
88,
25665,
198,
3,
9563,
199,
12323,
63,
2847,
275,
378,
88,
23686,
198,
3,
16189,
2808,
199,
12323,
63,
15543,
275,
378,
88,
16569,
198,
3,
16189,
6387,
199,
12323,
63,
5708,
275,
378,
88,
24215,
198,
3,
17661,
199,
12323,
63,
2276,
275,
378,
88,
27130,
198,
3,
4132,
390,
1905,
6385,
199,
199,
3,
7232,
9479,
199,
12323,
63,
50,
6012,
63,
2826,
2666,
275,
378,
199,
12323,
63,
50,
6012,
63,
3516,
2666,
275,
413,
199,
12323,
63,
50,
6012,
63,
3279,
54,
8784,
275,
499,
199,
12323,
63,
50,
6012,
63,
16764,
7378,
275,
650,
199,
12323,
63,
50,
6012,
63,
4609,
8947,
275,
841,
199,
12323,
63,
50,
6012,
63,
8279,
8558,
275,
959,
199,
12323,
63,
50,
6012,
63,
16936,
7378,
275,
1227,
199,
12323,
63,
50,
6012,
63,
57,
12297,
50,
3597,
275,
1520,
199,
12323,
63,
50,
6012,
63,
46,
12297,
50,
3597,
275,
1695,
199,
12323,
63,
50,
6012,
63,
4609,
5580,
275,
1749,
199,
12323,
63,
50,
6012,
63,
4609,
15353,
275,
1616,
199,
199,
3,
27222,
2943,
199,
12323,
63,
33,
275,
413,
199,
12323,
63,
2709,
275,
499,
199,
12323,
63,
35,
2339,
275,
959,
199,
12323,
63,
4118,
33,
275,
1227,
199,
12323,
63,
14528,
275,
3144,
199,
12323,
63,
40,
4531,
275,
4944,
199,
12323,
63,
17401,
275,
4114,
199,
12323,
63,
17715,
275,
3193,
199,
12323,
63,
6151,
275,
7294,
199,
12323,
63,
31546,
275,
9404,
199,
199,
3,
27222,
3992,
199,
12323,
63,
568,
275,
413,
199,
12323,
63,
26363,
3100,
275,
650,
199,
12323,
63,
40,
654,
25705,
275,
841,
199,
12323,
63,
8974,
275,
5450,
199,
199,
318,
1706,
63,
354,
8,
354,
12,
2331,
12,
1768,
63,
4695,
83,
304,
272,
340,
536,
26,
267,
3628,
275,
536,
14,
1294,
7563,
272,
587,
26,
267,
3628,
275,
942,
272,
3628,
14,
740,
8355,
272,
4123,
275,
2125,
272,
367,
284,
12,
1768,
315,
3874,
8,
3512,
304,
267,
790,
275,
15671,
904,
8,
3512,
59,
73,
5728,
14,
4142,
342,
267,
12448,
275,
1768,
63,
4695,
83,
14,
362,
8,
498,
9,
267,
340,
440,
12448,
26,
288,
340,
822,
8,
498,
9,
690,
413,
26,
355,
12448,
275,
2331,
435,
822,
8,
1436,
9,
355,
340,
12448,
665,
378,
1812,
1493,
26,
490,
1768,
63,
4695,
83,
59,
498,
61,
275,
12448,
288,
284,
275,
822,
8,
1302,
9,
288,
4123,
847,
8678,
8,
73,
9,
435,
1768,
267,
587,
26,
288,
4123,
847,
2702,
14,
1389,
16099,
40,
297,
334,
16,
1812,
1493,
1204,
12448,
430,
288,
2059,
272,
372,
4123,
199,
199,
318,
7787,
63,
354,
8,
1436,
12,
2331,
304,
272,
536,
275,
2125,
272,
6290,
63,
1997,
275,
378,
272,
367,
284,
315,
1425,
8,
1960,
304,
327,
5787,
267,
302,
275,
6206,
8,
1436,
59,
1997,
566,
267,
340,
302,
508,
378,
26,
288,
2331,
847,
413,
288,
2059,
267,
916,
334,
78,
1253,
378,
1812,
16,
9,
508,
378,
1812,
16,
26,
288,
12448,
275,
2702,
14,
5301,
16099,
40,
297,
4123,
59,
1997,
26,
1997,
11,
18,
11057,
16,
61,
1253,
378,
88,
19,
18190,
288,
2331,
847,
499,
288,
340,
440,
6290,
63,
1997,
26,
355,
6290,
63,
1997,
275,
2331,
288,
327,
5787,
446,
2793,
1133,
675,
16189,
1,
32,
3,
4,
288,
536,
275,
536,
435,
7787,
63,
354,
8,
1436,
12,
12448,
2788,
16,
61,
435,
7815,
288,
2059,
267,
587,
26,
288,
2331,
847,
413,
288,
536,
275,
536,
435,
4123,
59,
1997,
26,
1997,
11,
78,
61,
435,
7815,
288,
340,
822,
8,
354,
9,
690,
5450,
26,
355,
746,
366,
20573,
14,
26472,
547,
360,
354,
8088,
2419,
5450,
2783,
358,
288,
2331,
847,
302,
272,
372,
536,
14,
1913,
5175,
659,
2331,
199,
199,
533,
10237,
8,
68,
20573,
14,
2726,
304,
272,
636,
11244,
363,
275,
334,
267,
661,
344,
297,
283,
40,
297,
378,
395,
267,
661,
411,
297,
283,
40,
297,
10237,
63,
15543,
395,
198,
3,
9133,
1827,
267,
327,
5787,
446,
5548,
402,
1827,
12,
27222,
2251,
267,
661,
23097,
297,
283,
40,
297,
14431,
267,
661,
290,
297,
283,
40,
297,
14431,
267,
661,
561,
297,
283,
40,
297,
14431,
267,
661,
285,
297,
283,
40,
297,
3073,
267,
776,
272,
347,
664,
63,
16596,
8,
277,
304,
267,
372,
1109,
1332,
277,
14,
411,
1253,
378,
88,
15214,
9,
508,
378,
88,
15214,
9,
272,
347,
663,
63,
16596,
8,
277,
12,
373,
304,
267,
340,
373,
26,
291,
14,
411,
8901,
378,
88,
15214,
267,
587,
26,
291,
14,
411,
18415,
6146,
16,
88,
15214,
272,
29757,
275,
3324,
8,
362,
63,
16596,
12,
663,
63,
16596,
9,
339,
347,
664,
63,
14325,
8,
277,
304,
267,
372,
334,
277,
14,
411,
4331,
4119,
9,
1253,
378,
1949,
272,
347,
663,
63,
14325,
8,
277,
12,
373,
304,
267,
291,
14,
411,
275,
334,
277,
14,
411,
1253,
6146,
16,
88,
2277,
383,
9,
1204,
3666,
86,
1253,
378,
1949,
9,
5213,
4119,
9,
272,
10508,
275,
3324,
8,
362,
63,
14325,
12,
663,
63,
14325,
9,
339,
347,
664,
63,
82,
600,
8,
277,
304,
267,
372,
291,
14,
411,
1253,
378,
1949,
272,
347,
663,
63,
82,
600,
8,
277,
12,
373,
304,
267,
291,
14,
411,
275,
334,
277,
14,
411,
1253,
6146,
16,
1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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
HeH-Projects/team-agozzino
|
frontend/node_modules/node-gyp/gyp/PRESUBMIT.py
|
1369
|
3662
|
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Top-level presubmit script for GYP.
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details about the presubmit API built into gcl.
"""
PYLINT_BLACKLIST = [
# TODO: fix me.
# From SCons, not done in google style.
'test/lib/TestCmd.py',
'test/lib/TestCommon.py',
'test/lib/TestGyp.py',
]
PYLINT_DISABLED_WARNINGS = [
# TODO: fix me.
# Many tests include modules they don't use.
'W0611',
# Possible unbalanced tuple unpacking with sequence.
'W0632',
# Attempting to unpack a non-sequence.
'W0633',
# Include order doesn't properly include local files?
'F0401',
# Some use of built-in names.
'W0622',
# Some unused variables.
'W0612',
# Operator not preceded/followed by space.
'C0323',
'C0322',
# Unnecessary semicolon.
'W0301',
# Unused argument.
'W0613',
# String has no effect (docstring in wrong place).
'W0105',
# map/filter on lambda could be replaced by comprehension.
'W0110',
# Use of eval.
'W0123',
# Comma not followed by space.
'C0324',
# Access to a protected member.
'W0212',
# Bad indent.
'W0311',
# Line too long.
'C0301',
# Undefined variable.
'E0602',
# Not exception type specified.
'W0702',
# No member of that name.
'E1101',
# Dangerous default {}.
'W0102',
# Cyclic import.
'R0401',
# Others, too many to sort.
'W0201', 'W0232', 'E1103', 'W0621', 'W0108', 'W0223', 'W0231',
'R0201', 'E0101', 'C0321',
# ************* Module copy
# W0104:427,12:_test.odict.__setitem__: Statement seems to have no effect
'W0104',
]
def CheckChangeOnUpload(input_api, output_api):
report = []
report.extend(input_api.canned_checks.PanProjectChecks(
input_api, output_api))
return report
def CheckChangeOnCommit(input_api, output_api):
report = []
# Accept any year number from 2009 to the current year.
current_year = int(input_api.time.strftime('%Y'))
allowed_years = (str(s) for s in reversed(xrange(2009, current_year + 1)))
years_re = '(' + '|'.join(allowed_years) + ')'
# The (c) is deprecated, but tolerate it until it's removed from all files.
license = (
r'.*? Copyright (\(c\) )?%(year)s Google Inc\. All rights reserved\.\n'
r'.*? Use of this source code is governed by a BSD-style license that '
r'can be\n'
r'.*? found in the LICENSE file\.\n'
) % {
'year': years_re,
}
report.extend(input_api.canned_checks.PanProjectChecks(
input_api, output_api, license_header=license))
report.extend(input_api.canned_checks.CheckTreeIsOpen(
input_api, output_api,
'http://gyp-status.appspot.com/status',
'http://gyp-status.appspot.com/current'))
import os
import sys
old_sys_path = sys.path
try:
sys.path = ['pylib', 'test/lib'] + sys.path
blacklist = PYLINT_BLACKLIST
if sys.platform == 'win32':
blacklist = [os.path.normpath(x).replace('\\', '\\\\')
for x in PYLINT_BLACKLIST]
report.extend(input_api.canned_checks.RunPylint(
input_api,
output_api,
black_list=blacklist,
disabled_warnings=PYLINT_DISABLED_WARNINGS))
finally:
sys.path = old_sys_path
return report
TRYBOTS = [
'linux_try',
'mac_try',
'win_try',
]
def GetPreferredTryMasters(_, change):
return {
'client.gyp': { t: set(['defaulttests']) for t in TRYBOTS },
}
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
421,
199,
624,
6105,
13,
1896,
23895,
2884,
367,
25686,
14,
199,
199,
9295,
1455,
921,
2374,
14,
13211,
14,
1308,
15,
23826,
15,
1917,
13,
14543,
15,
27834,
2537,
15,
80,
15527,
13,
6429,
199,
509,
1655,
2436,
3595,
314,
23895,
3261,
6137,
1901,
486,
429,
14,
199,
624,
421,
199,
4521,
44,
2919,
63,
23113,
4924,
275,
359,
272,
327,
3254,
26,
5325,
562,
14,
272,
327,
11606,
8218,
12,
440,
4224,
315,
6233,
3449,
14,
272,
283,
396,
15,
773,
15,
774,
7874,
14,
647,
297,
272,
283,
396,
15,
773,
15,
774,
7844,
14,
647,
297,
272,
283,
396,
15,
773,
15,
774,
13899,
14,
647,
297,
199,
61,
421,
199,
4521,
44,
2919,
63,
16205,
63,
17449,
3881,
275,
359,
272,
327,
3254,
26,
5325,
562,
14,
272,
327,
15517,
2295,
2387,
4621,
2985,
2793,
1133,
675,
14,
272,
283,
55,
1690,
845,
297,
272,
327,
18558,
625,
18923,
2008,
7787,
316,
543,
3414,
14,
272,
283,
55,
1690,
708,
297,
272,
327,
17413,
1337,
370,
7787,
282,
2222,
13,
4041,
14,
272,
283,
55,
1690,
1153,
297,
272,
327,
15783,
1865,
3181,
1133,
7684,
2387,
2257,
1584,
31,
272,
283,
38,
28025,
297,
272,
327,
6601,
675,
402,
6137,
13,
262,
1561,
14,
272,
283,
55,
1690,
1081,
297,
272,
327,
6601,
9563,
2860,
14,
272,
283,
55,
1690,
713,
297,
272,
327,
11013,
440,
9222,
770,
15,
7207,
379,
701,
4601,
14,
272,
283,
35,
16,
13905,
297,
272,
283,
35,
16,
15858,
297,
272,
327,
1910,
17927,
18734,
12167,
14,
272,
283,
55,
1644,
614,
297,
272,
327,
1910,
2972,
1423,
14,
272,
283,
55,
1690,
969,
297,
272,
327,
2624,
965,
949,
7763,
334,
12485,
315,
6835,
4192,
680,
272,
283,
55,
614,
1717,
297,
272,
327,
2341,
15,
1541,
641,
2400,
4293,
506,
8717,
701,
1013,
31379,
14,
272,
283,
55,
614,
709,
297,
272,
327,
3645,
402,
3468,
14,
272,
283,
55,
29555,
297,
272,
327,
5429,
391,
440,
9437,
701,
4601,
14,
272,
283,
35,
16,
12744,
297,
272,
327,
11003,
370,
282,
17819,
3653,
14,
272,
283,
55,
996,
713,
297,
272,
327,
8857,
4363,
14,
272,
283,
55,
1644,
845,
297,
272,
327,
7030,
4634,
1846,
14,
272,
283,
35,
1644,
614,
297,
272,
327,
25868,
1750,
14,
272,
283,
37,
1690,
996,
297,
272,
327,
2832,
1919,
730,
2013,
14,
272,
283,
55,
1780,
996,
297,
272,
327,
3091,
3653,
402,
626,
536,
14,
272,
283,
37,
24827,
297,
272,
327,
577,
21480,
849,
30332,
272,
283,
55,
31715,
297,
272,
327,
18461,
17542,
492,
14,
272,
283,
50,
28025,
297,
272,
327,
5439,
83,
12,
4634,
5002,
370,
4069,
14,
272,
283,
55,
996,
614,
297,
283,
55,
996,
708,
297,
283,
37,
6019,
19,
297,
283,
55,
1690,
2025,
297,
283,
55,
614,
2036,
297,
283,
55,
996,
1789,
297,
283,
55,
996,
2192,
297,
272,
283,
50,
996,
614,
297,
283,
37,
11502,
297,
283,
35,
16,
12638,
297,
272,
327,
1011,
1801,
9153,
5673,
1331,
272,
327,
644,
614,
966,
26,
27358,
12,
713,
22003,
396,
14,
79,
807,
855,
8617,
10651,
29697,
12237,
370,
1172,
949,
7763,
272,
283,
55,
614,
966,
297,
199,
61,
421,
199,
318,
2670,
4001,
3314,
10301,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
3622,
275,
942,
523,
3622,
14,
2880,
8,
1210,
63,
1246,
14,
31126,
63,
8625,
14,
19266,
4761,
11834,
8,
489,
1324,
63,
1246,
12,
1072,
63,
1246,
430,
523,
372,
3622,
421,
199,
318,
2670,
4001,
3314,
11421,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
3622,
275,
942,
819,
327,
15506,
1263,
5361,
1329,
687,
8937,
370,
314,
1453,
5361,
14,
523,
1453,
63,
3403,
275,
1109,
8,
1210,
63,
1246,
14,
521,
14,
6205,
3508,
57,
1333,
523,
4370,
63,
18431,
275,
334,
495,
8,
83,
9,
367,
308,
315,
10822,
8,
21120,
8,
8664,
12,
1453,
63,
3403,
435,
413,
1724,
523,
17399,
63,
264,
275,
16746,
435,
21590,
904,
8,
6541,
63,
18431,
9,
435,
16107,
819,
327,
710,
334,
67,
9,
365,
5906,
12,
1325,
370,
1435,
323,
652,
5133,
652,
1159,
4829,
687,
1006,
1584,
14,
523,
4190,
275,
334,
489,
519,
1370,
15279,
1898,
14749,
8,
67,
31736,
24836,
2840,
3403,
9,
83,
4475,
3277,
4537,
2900,
4481,
4644,
60,
3134,
78,
7,
489,
519,
1370,
15279,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
283,
267,
519,
7,
2425,
506,
60,
78,
7,
489,
519,
1370,
15279,
1911,
315,
314,
5113,
570,
60,
3134,
78,
7,
523,
776,
450,
469,
489,
283,
3403,
356,
17399,
63,
264,
12,
523,
789,
819,
3622,
14,
2880,
8,
1210,
63,
1246,
14,
31126,
63,
8625,
14,
19266,
4761,
11834,
8,
489,
1324,
63,
1246,
12,
1072,
63,
1246,
12,
4190,
63,
1291,
29,
1682,
430,
523,
3622,
14,
2880,
8,
1210,
63,
1246,
14,
31126,
63,
8625,
14,
1799,
3987,
1831,
4299,
8,
489,
1324,
63,
1246,
12,
1072,
63,
1246,
12,
489,
283,
1014,
921,
6179,
13,
1205,
14,
571,
15185,
14,
957,
15,
1205,
297,
489,
283,
1014,
921,
6179,
13,
1205,
14,
571,
15185,
14,
957,
15,
1818,
1333,
819,
492,
747,
523,
492,
984,
523,
2269,
63,
1274,
63,
515,
275,
984,
14,
515,
523,
862,
26,
272,
984,
14,
515,
275,
788,
24111,
297,
283,
396,
15,
773,
418,
435,
984,
14,
515,
272,
23180,
275,
7843,
44,
2919,
63,
23113,
4924,
272,
340,
984,
14,
3246,
508,
283,
2676,
708,
356,
489,
23180,
275,
359,
736,
14,
515,
14,
9267,
8,
88,
680,
1814,
20786,
31375,
358,
673,
367,
671,
315,
7843,
44,
2919,
63,
23113,
4924,
61,
272,
3622,
14,
2880,
8,
1210,
63,
1246,
14,
31126,
63,
8625,
14,
2540,
2713,
3854,
8,
267,
1324,
63,
1246,
12,
267,
1072,
63,
1246,
12,
267,
12136,
63,
513,
29,
22126,
12,
267
] |
[
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
421,
199,
624,
6105,
13,
1896,
23895,
2884,
367,
25686,
14,
199,
199,
9295,
1455,
921,
2374,
14,
13211,
14,
1308,
15,
23826,
15,
1917,
13,
14543,
15,
27834,
2537,
15,
80,
15527,
13,
6429,
199,
509,
1655,
2436,
3595,
314,
23895,
3261,
6137,
1901,
486,
429,
14,
199,
624,
421,
199,
4521,
44,
2919,
63,
23113,
4924,
275,
359,
272,
327,
3254,
26,
5325,
562,
14,
272,
327,
11606,
8218,
12,
440,
4224,
315,
6233,
3449,
14,
272,
283,
396,
15,
773,
15,
774,
7874,
14,
647,
297,
272,
283,
396,
15,
773,
15,
774,
7844,
14,
647,
297,
272,
283,
396,
15,
773,
15,
774,
13899,
14,
647,
297,
199,
61,
421,
199,
4521,
44,
2919,
63,
16205,
63,
17449,
3881,
275,
359,
272,
327,
3254,
26,
5325,
562,
14,
272,
327,
15517,
2295,
2387,
4621,
2985,
2793,
1133,
675,
14,
272,
283,
55,
1690,
845,
297,
272,
327,
18558,
625,
18923,
2008,
7787,
316,
543,
3414,
14,
272,
283,
55,
1690,
708,
297,
272,
327,
17413,
1337,
370,
7787,
282,
2222,
13,
4041,
14,
272,
283,
55,
1690,
1153,
297,
272,
327,
15783,
1865,
3181,
1133,
7684,
2387,
2257,
1584,
31,
272,
283,
38,
28025,
297,
272,
327,
6601,
675,
402,
6137,
13,
262,
1561,
14,
272,
283,
55,
1690,
1081,
297,
272,
327,
6601,
9563,
2860,
14,
272,
283,
55,
1690,
713,
297,
272,
327,
11013,
440,
9222,
770,
15,
7207,
379,
701,
4601,
14,
272,
283,
35,
16,
13905,
297,
272,
283,
35,
16,
15858,
297,
272,
327,
1910,
17927,
18734,
12167,
14,
272,
283,
55,
1644,
614,
297,
272,
327,
1910,
2972,
1423,
14,
272,
283,
55,
1690,
969,
297,
272,
327,
2624,
965,
949,
7763,
334,
12485,
315,
6835,
4192,
680,
272,
283,
55,
614,
1717,
297,
272,
327,
2341,
15,
1541,
641,
2400,
4293,
506,
8717,
701,
1013,
31379,
14,
272,
283,
55,
614,
709,
297,
272,
327,
3645,
402,
3468,
14,
272,
283,
55,
29555,
297,
272,
327,
5429,
391,
440,
9437,
701,
4601,
14,
272,
283,
35,
16,
12744,
297,
272,
327,
11003,
370,
282,
17819,
3653,
14,
272,
283,
55,
996,
713,
297,
272,
327,
8857,
4363,
14,
272,
283,
55,
1644,
845,
297,
272,
327,
7030,
4634,
1846,
14,
272,
283,
35,
1644,
614,
297,
272,
327,
25868,
1750,
14,
272,
283,
37,
1690,
996,
297,
272,
327,
2832,
1919,
730,
2013,
14,
272,
283,
55,
1780,
996,
297,
272,
327,
3091,
3653,
402,
626,
536,
14,
272,
283,
37,
24827,
297,
272,
327,
577,
21480,
849,
30332,
272,
283,
55,
31715,
297,
272,
327,
18461,
17542,
492,
14,
272,
283,
50,
28025,
297,
272,
327,
5439,
83,
12,
4634,
5002,
370,
4069,
14,
272,
283,
55,
996,
614,
297,
283,
55,
996,
708,
297,
283,
37,
6019,
19,
297,
283,
55,
1690,
2025,
297,
283,
55,
614,
2036,
297,
283,
55,
996,
1789,
297,
283,
55,
996,
2192,
297,
272,
283,
50,
996,
614,
297,
283,
37,
11502,
297,
283,
35,
16,
12638,
297,
272,
327,
1011,
1801,
9153,
5673,
1331,
272,
327,
644,
614,
966,
26,
27358,
12,
713,
22003,
396,
14,
79,
807,
855,
8617,
10651,
29697,
12237,
370,
1172,
949,
7763,
272,
283,
55,
614,
966,
297,
199,
61,
421,
199,
318,
2670,
4001,
3314,
10301,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
3622,
275,
942,
523,
3622,
14,
2880,
8,
1210,
63,
1246,
14,
31126,
63,
8625,
14,
19266,
4761,
11834,
8,
489,
1324,
63,
1246,
12,
1072,
63,
1246,
430,
523,
372,
3622,
421,
199,
318,
2670,
4001,
3314,
11421,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
3622,
275,
942,
819,
327,
15506,
1263,
5361,
1329,
687,
8937,
370,
314,
1453,
5361,
14,
523,
1453,
63,
3403,
275,
1109,
8,
1210,
63,
1246,
14,
521,
14,
6205,
3508,
57,
1333,
523,
4370,
63,
18431,
275,
334,
495,
8,
83,
9,
367,
308,
315,
10822,
8,
21120,
8,
8664,
12,
1453,
63,
3403,
435,
413,
1724,
523,
17399,
63,
264,
275,
16746,
435,
21590,
904,
8,
6541,
63,
18431,
9,
435,
16107,
819,
327,
710,
334,
67,
9,
365,
5906,
12,
1325,
370,
1435,
323,
652,
5133,
652,
1159,
4829,
687,
1006,
1584,
14,
523,
4190,
275,
334,
489,
519,
1370,
15279,
1898,
14749,
8,
67,
31736,
24836,
2840,
3403,
9,
83,
4475,
3277,
4537,
2900,
4481,
4644,
60,
3134,
78,
7,
489,
519,
1370,
15279,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
283,
267,
519,
7,
2425,
506,
60,
78,
7,
489,
519,
1370,
15279,
1911,
315,
314,
5113,
570,
60,
3134,
78,
7,
523,
776,
450,
469,
489,
283,
3403,
356,
17399,
63,
264,
12,
523,
789,
819,
3622,
14,
2880,
8,
1210,
63,
1246,
14,
31126,
63,
8625,
14,
19266,
4761,
11834,
8,
489,
1324,
63,
1246,
12,
1072,
63,
1246,
12,
4190,
63,
1291,
29,
1682,
430,
523,
3622,
14,
2880,
8,
1210,
63,
1246,
14,
31126,
63,
8625,
14,
1799,
3987,
1831,
4299,
8,
489,
1324,
63,
1246,
12,
1072,
63,
1246,
12,
489,
283,
1014,
921,
6179,
13,
1205,
14,
571,
15185,
14,
957,
15,
1205,
297,
489,
283,
1014,
921,
6179,
13,
1205,
14,
571,
15185,
14,
957,
15,
1818,
1333,
819,
492,
747,
523,
492,
984,
523,
2269,
63,
1274,
63,
515,
275,
984,
14,
515,
523,
862,
26,
272,
984,
14,
515,
275,
788,
24111,
297,
283,
396,
15,
773,
418,
435,
984,
14,
515,
272,
23180,
275,
7843,
44,
2919,
63,
23113,
4924,
272,
340,
984,
14,
3246,
508,
283,
2676,
708,
356,
489,
23180,
275,
359,
736,
14,
515,
14,
9267,
8,
88,
680,
1814,
20786,
31375,
358,
673,
367,
671,
315,
7843,
44,
2919,
63,
23113,
4924,
61,
272,
3622,
14,
2880,
8,
1210,
63,
1246,
14,
31126,
63,
8625,
14,
2540,
2713,
3854,
8,
267,
1324,
63,
1246,
12,
267,
1072,
63,
1246,
12,
267,
12136,
63,
513,
29,
22126,
12,
267,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wei-Z/Python-Machine-Learning
|
self_practice/CH2A.py
|
1
|
4506
|
import numpy as np
class Perceptron(object):
"""Perceptron classifier.
Parameters
------------
eta : float
Learning rate (between 0.0 and 1.0)
n_iter : int
Passes over the training dataset.
Attributes
-----------
w_ : 1d-array
Weights after fitting.
errors_ : list
Number of misclassifications in every epoch.
"""
def __init__(self, eta=0.01, n_iter=10):
self.eta = eta
self.n_iter = n_iter
def fit(self, X, y):
"""Fit training data.
Parameters
----------
X : {array-like}, shape = [n_samples, n_features]
Training vectors, where n_samples
is the number of samples and
n_features is the number of features.
y : array-like, shape = [n_samples]
Target values.
Returns
-----------
self : object
"""
self.w_ = np.zeros(1 + X.shape[1]) # return zero array, X.shape[1] =2L, return array([0., 0., 0.])
self.errors_ = []
for _ in range(self.n_iter):
errors = 0
for xi, target in zip(X, y):
update = self.eta * (target - self.predict(xi))
self.w_[1:] += update * xi
self.w_[0] += update
errors += int(update != 0.0) # if update = 0.0, errors = 0; if update unequal 0.0, errors =1.
self.errors_.append(errors)
return self
def net_input(self, X):
#"""Calculate net input"""
return np.dot(X, self.w_[1:]) + self.w_[0] # matrix multiplication
def predict(self, X):
#"""Return class label after unit step"""
return np.where(self.net_input(X) >= 0.0, 1, -1) # numpy.where(condition[, x, y])
# Return elements, either from x or y, depending on condition.
# Training a perceptron model on the Iris dataset
import pandas as pd
df = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data', header=None)
df.tail()
import matplotlib.pyplot as plt
y = df.iloc[0:100, 4].values
y = np.where(y == 'Iris-setosa', -1, 1)# if y == 'Iris-setosa', y = -1, otherwise if y == 'Iris-versicolor', y =1.
X = df.iloc[0:100, [0,2]].values
plt.scatter(X[:50, 0], X[:50, 1], color='red', marker='o', label='setosa')
plt.scatter(X[50:100, 0], X[50:100, 1], color='blue', marker='x', label='versicolor')
plt.xlabel('petal length')
plt.ylabel('sepal length')
plt.legend(loc='upper left')
plt.show()
ppn = Perceptron()
ppn.fit(X,y)
plt.plot(range(1, len(ppn.errors_)+1), ppn.errors_, marker='o', color="green")
plt.xlabel('Epochs')
plt.ylabel('Number of misclassifications')
plt.show()
# Implement a small convenience function to visualize the decision boundaries for 2D datasets:
from matplotlib.colors import ListedColormap
def plot_decision_regions(X, y, classifier, resolution=0.02):
# setup marker generator and color map
markers = ('s', 'x', 'o', '^', 'v')
colors = ('red', 'blue', 'lightgreen', 'gray', 'cyan')
cmap = ListedColormap(colors[:len(np.unique(y))])
# plot the decision surface
x1_min, x1_max = X[:, 0].min() - 1, X[:, 0].max() + 1
x2_min, x2_max = X[:, 1].min() - 1, X[:, 1].max() + 1
xx1, xx2 = np.meshgrid(np.arange(x1_min, x1_max, resolution), np.arange(x2_min, x2_max, resolution))
Z = classifier.predict(np.array([xx1.ravel(), xx2.ravel()]).T)
print "xx1: ", xx1
print "xx2: ", xx2
print "Z: ", Z
print "xx1.ravel(): ", xx1.ravel()
print "xx2.ravel(): ", xx2.ravel()
Z = Z.reshape(xx1.shape)
print "Z: ", Z
plt.contourf(xx1, xx2, Z, alpha=0.4, cmap=cmap)
plt.xlim(xx1.min(), xx1.max())
plt.ylim(xx2.min(), xx2.max())
# plot class samples
for idx, cl in enumerate(np.unique(y)):
plt.scatter(x=X[y == cl, 0], y=X[y == cl, 1], alpha=0.8, c=cmap(idx), marker=markers[idx], label=cl)
plot_decision_regions(X, y, classifier=ppn)
plt.xlabel('sepal length [cm]')
plt.ylabel('petal length [cm]')
plt.legend(loc = 'upper left')
plt.show()
# meshgrid, ravel, reshape, contourf, xlim, ylim
# how to use contourf and meshgrid:
x = np.arange(-5, 5, 0.1)
y = np.arange(-5, 5, 0.1)
xx, yy = np.meshgrid(x, y, sparse=True)
z = np.sin(xx**2 + yy**2) / (xx**2 + yy**2)
h = plt.contourf(x,y,z)
|
mit
|
[
646,
2680,
465,
980,
199,
533,
3492,
301,
4695,
265,
8,
785,
304,
272,
408,
2623,
301,
4695,
265,
12429,
14,
13857,
3897,
267,
3001,
375,
267,
20356,
520,
2069,
267,
29127,
6634,
334,
13007,
378,
14,
16,
436,
413,
14,
16,
9,
267,
302,
63,
1661,
520,
1109,
267,
510,
1916,
1806,
314,
6093,
4789,
14,
267,
9382,
267,
3001,
2595,
267,
336,
63,
520,
413,
68,
13,
1144,
267,
2136,
2492,
2410,
21774,
14,
267,
2552,
63,
520,
769,
267,
4860,
402,
3201,
14368,
83,
315,
4036,
9463,
14,
5493,
408,
272,
347,
636,
826,
721,
277,
12,
20356,
29,
16,
14,
614,
12,
302,
63,
1661,
29,
709,
304,
267,
291,
14,
1841,
275,
20356,
267,
291,
14,
78,
63,
1661,
275,
302,
63,
1661,
272,
347,
5542,
8,
277,
12,
1323,
12,
612,
304,
267,
408,
13776,
6093,
666,
14,
27180,
3897,
288,
4143,
288,
1323,
520,
469,
1144,
13,
2930,
1386,
2215,
275,
359,
78,
63,
3356,
12,
302,
63,
3179,
61,
288,
22859,
11102,
12,
2382,
302,
63,
3356,
288,
365,
314,
1329,
402,
5845,
436,
288,
302,
63,
3179,
365,
314,
1329,
402,
4534,
14,
288,
612,
520,
1625,
13,
2930,
12,
2215,
275,
359,
78,
63,
3356,
61,
288,
10256,
1338,
14,
288,
1803,
288,
3001,
2595,
288,
291,
520,
909,
10631,
408,
267,
291,
14,
87,
63,
275,
980,
14,
4250,
8,
17,
435,
1323,
14,
1392,
59,
17,
566,
327,
372,
4697,
1625,
12,
1323,
14,
1392,
59,
17,
61,
275,
18,
44,
12,
372,
1625,
779,
16,
2020,
378,
2020,
378,
14444,
267,
291,
14,
2550,
63,
275,
942,
267,
367,
485,
315,
1425,
8,
277,
14,
78,
63,
1661,
304,
288,
2552,
275,
378,
288,
367,
19905,
12,
1347,
315,
3482,
8,
56,
12,
612,
304,
355,
1678,
275,
291,
14,
1841,
627,
334,
1375,
446,
291,
14,
6892,
8,
6865,
430,
355,
291,
14,
87,
9925,
17,
2938,
847,
1678,
627,
19905,
355,
291,
14,
87,
9925,
16,
61,
847,
1678,
355,
2552,
847,
1109,
8,
873,
1137,
378,
14,
16,
9,
327,
340,
1678,
275,
378,
14,
16,
12,
2552,
275,
378,
27,
340,
1678,
625,
1452,
378,
14,
16,
12,
2552,
275,
17,
14,
7205,
291,
14,
2550,
3754,
740,
8,
2550,
9,
267,
372,
291,
2286,
347,
1851,
63,
1210,
8,
277,
12,
1323,
304,
267,
327,
624,
14860,
1851,
1324,
624,
267,
372,
980,
14,
3287,
8,
56,
12,
291,
14,
87,
9925,
17,
5728,
435,
291,
14,
87,
9925,
16,
61,
327,
3634,
24638,
272,
347,
12610,
8,
277,
12,
1323,
304,
267,
327,
624,
1767,
1021,
1768,
2410,
4137,
3650,
624,
267,
372,
980,
14,
4509,
8,
277,
14,
846,
63,
1210,
8,
56,
9,
2356,
378,
14,
16,
12,
413,
12,
446,
17,
9,
327,
2680,
14,
4509,
8,
5394,
14675,
671,
12,
612,
566,
6684,
3777,
327,
1432,
4008,
12,
1902,
687,
671,
503,
612,
12,
10298,
641,
5558,
14,
4388,
199,
3,
22859,
282,
1126,
301,
4695,
265,
1402,
641,
314,
473,
5719,
4789,
199,
646,
10634,
465,
6454,
199,
1587,
275,
6454,
14,
739,
63,
4737,
360,
2859,
921,
6404,
14,
2932,
14,
85,
559,
14,
8654,
15,
757,
15,
6744,
13,
10546,
13,
17439,
15,
11885,
15,
11885,
14,
576,
297,
1406,
29,
403,
9,
199,
1587,
14,
1521,
342,
199,
199,
646,
8027,
14,
13563,
465,
4488,
199,
199,
89,
275,
4051,
14,
21104,
59,
16,
26,
1960,
12,
841,
1055,
1459,
199,
89,
275,
980,
14,
4509,
8,
89,
508,
283,
41,
5719,
13,
409,
29295,
297,
446,
17,
12,
413,
28017,
340,
612,
508,
283,
41,
5719,
13,
409,
29295,
297,
612,
275,
446,
17,
12,
4257,
340,
612,
508,
283,
41,
5719,
13,
422,
338,
2326,
297,
612,
275,
17,
14,
199,
56,
275,
4051,
14,
21104,
59,
16,
26,
1960,
12,
359,
16,
12,
18,
20230,
1459,
199,
6003,
14,
13512,
8,
56,
1491,
1400,
12,
378,
467,
1323,
1491,
1400,
12,
413,
467,
3164,
534,
581,
297,
3608,
534,
79,
297,
1768,
534,
409,
29295,
358,
199,
6003,
14,
13512,
8,
56,
59,
1400,
26,
1960,
12,
378,
467,
1323,
59,
1400,
26,
1960,
12,
413,
467,
3164,
534,
6304,
297,
3608,
534,
88,
297,
1768,
534,
422,
338,
2326,
358,
199,
6003,
14,
14168,
360,
8096,
279,
2582,
358,
199,
6003,
14,
13849,
360,
4127,
279,
2582,
358,
199,
6003,
14,
10231,
8,
2102,
534,
4142,
3602,
358,
199,
6003,
14,
2384,
342,
199,
199,
802,
78,
275,
3492,
301,
4695,
265,
342,
199,
802,
78,
14,
3269,
8,
56,
12,
89,
9,
199,
6003,
14,
2798,
8,
1842,
8,
17,
12,
822,
8,
802,
78,
14,
2550,
4602,
11,
17,
395,
299,
4812,
14,
2550,
3131,
3608,
534,
79,
297,
3164,
628,
7731,
531,
199,
6003,
14,
14168,
360,
29322,
83,
358,
199,
6003,
14,
13849,
360,
3259,
402,
3201,
14368,
83,
358,
199,
6003,
14,
2384,
342,
199,
199,
3,
22467,
282,
7425,
16777,
805,
370,
13104,
794,
314,
14692,
18135,
367,
499,
36,
13148,
26,
199,
504,
8027,
14,
7120,
492,
491,
4957,
4117,
1130,
199,
199,
318,
5137,
63,
16622,
63,
11963,
8,
56,
12,
612,
12,
12429,
12,
12401,
29,
16,
14,
996,
304,
2286,
327,
3272,
3608,
4306,
436,
3164,
2341,
272,
14327,
275,
661,
83,
297,
283,
88,
297,
283,
79,
297,
14452,
297,
283,
86,
358,
272,
9229,
275,
661,
581,
297,
283,
6304,
297,
283,
4040,
7731,
297,
283,
12150,
297,
283,
28291,
358,
272,
14920,
275,
491,
4957,
4117,
1130,
8,
7120,
1491,
552,
8,
1590,
14,
3235,
8,
89,
18229,
2286,
327,
5137,
314,
14692,
13195,
272,
671,
17,
63,
827,
12,
671,
17,
63,
988,
275,
1323,
3981,
378,
1055,
827,
342,
446,
413,
12,
1323,
3981,
378,
1055,
988,
342,
435,
413,
272,
671,
18,
63,
827,
12,
671,
18,
63,
988,
275,
1323,
3981,
413,
1055,
827,
342,
446,
413,
12,
1323,
3981,
413,
1055,
988,
342,
435,
413,
272,
19379,
17,
12,
19379,
18,
275,
980,
14,
6480,
3825,
8,
1590,
14,
5605,
8,
88,
17,
63,
827,
12,
671,
17,
63,
988,
12,
12401,
395,
980,
14
] |
[
2680,
465,
980,
199,
533,
3492,
301,
4695,
265,
8,
785,
304,
272,
408,
2623,
301,
4695,
265,
12429,
14,
13857,
3897,
267,
3001,
375,
267,
20356,
520,
2069,
267,
29127,
6634,
334,
13007,
378,
14,
16,
436,
413,
14,
16,
9,
267,
302,
63,
1661,
520,
1109,
267,
510,
1916,
1806,
314,
6093,
4789,
14,
267,
9382,
267,
3001,
2595,
267,
336,
63,
520,
413,
68,
13,
1144,
267,
2136,
2492,
2410,
21774,
14,
267,
2552,
63,
520,
769,
267,
4860,
402,
3201,
14368,
83,
315,
4036,
9463,
14,
5493,
408,
272,
347,
636,
826,
721,
277,
12,
20356,
29,
16,
14,
614,
12,
302,
63,
1661,
29,
709,
304,
267,
291,
14,
1841,
275,
20356,
267,
291,
14,
78,
63,
1661,
275,
302,
63,
1661,
272,
347,
5542,
8,
277,
12,
1323,
12,
612,
304,
267,
408,
13776,
6093,
666,
14,
27180,
3897,
288,
4143,
288,
1323,
520,
469,
1144,
13,
2930,
1386,
2215,
275,
359,
78,
63,
3356,
12,
302,
63,
3179,
61,
288,
22859,
11102,
12,
2382,
302,
63,
3356,
288,
365,
314,
1329,
402,
5845,
436,
288,
302,
63,
3179,
365,
314,
1329,
402,
4534,
14,
288,
612,
520,
1625,
13,
2930,
12,
2215,
275,
359,
78,
63,
3356,
61,
288,
10256,
1338,
14,
288,
1803,
288,
3001,
2595,
288,
291,
520,
909,
10631,
408,
267,
291,
14,
87,
63,
275,
980,
14,
4250,
8,
17,
435,
1323,
14,
1392,
59,
17,
566,
327,
372,
4697,
1625,
12,
1323,
14,
1392,
59,
17,
61,
275,
18,
44,
12,
372,
1625,
779,
16,
2020,
378,
2020,
378,
14444,
267,
291,
14,
2550,
63,
275,
942,
267,
367,
485,
315,
1425,
8,
277,
14,
78,
63,
1661,
304,
288,
2552,
275,
378,
288,
367,
19905,
12,
1347,
315,
3482,
8,
56,
12,
612,
304,
355,
1678,
275,
291,
14,
1841,
627,
334,
1375,
446,
291,
14,
6892,
8,
6865,
430,
355,
291,
14,
87,
9925,
17,
2938,
847,
1678,
627,
19905,
355,
291,
14,
87,
9925,
16,
61,
847,
1678,
355,
2552,
847,
1109,
8,
873,
1137,
378,
14,
16,
9,
327,
340,
1678,
275,
378,
14,
16,
12,
2552,
275,
378,
27,
340,
1678,
625,
1452,
378,
14,
16,
12,
2552,
275,
17,
14,
7205,
291,
14,
2550,
3754,
740,
8,
2550,
9,
267,
372,
291,
2286,
347,
1851,
63,
1210,
8,
277,
12,
1323,
304,
267,
327,
624,
14860,
1851,
1324,
624,
267,
372,
980,
14,
3287,
8,
56,
12,
291,
14,
87,
9925,
17,
5728,
435,
291,
14,
87,
9925,
16,
61,
327,
3634,
24638,
272,
347,
12610,
8,
277,
12,
1323,
304,
267,
327,
624,
1767,
1021,
1768,
2410,
4137,
3650,
624,
267,
372,
980,
14,
4509,
8,
277,
14,
846,
63,
1210,
8,
56,
9,
2356,
378,
14,
16,
12,
413,
12,
446,
17,
9,
327,
2680,
14,
4509,
8,
5394,
14675,
671,
12,
612,
566,
6684,
3777,
327,
1432,
4008,
12,
1902,
687,
671,
503,
612,
12,
10298,
641,
5558,
14,
4388,
199,
3,
22859,
282,
1126,
301,
4695,
265,
1402,
641,
314,
473,
5719,
4789,
199,
646,
10634,
465,
6454,
199,
1587,
275,
6454,
14,
739,
63,
4737,
360,
2859,
921,
6404,
14,
2932,
14,
85,
559,
14,
8654,
15,
757,
15,
6744,
13,
10546,
13,
17439,
15,
11885,
15,
11885,
14,
576,
297,
1406,
29,
403,
9,
199,
1587,
14,
1521,
342,
199,
199,
646,
8027,
14,
13563,
465,
4488,
199,
199,
89,
275,
4051,
14,
21104,
59,
16,
26,
1960,
12,
841,
1055,
1459,
199,
89,
275,
980,
14,
4509,
8,
89,
508,
283,
41,
5719,
13,
409,
29295,
297,
446,
17,
12,
413,
28017,
340,
612,
508,
283,
41,
5719,
13,
409,
29295,
297,
612,
275,
446,
17,
12,
4257,
340,
612,
508,
283,
41,
5719,
13,
422,
338,
2326,
297,
612,
275,
17,
14,
199,
56,
275,
4051,
14,
21104,
59,
16,
26,
1960,
12,
359,
16,
12,
18,
20230,
1459,
199,
6003,
14,
13512,
8,
56,
1491,
1400,
12,
378,
467,
1323,
1491,
1400,
12,
413,
467,
3164,
534,
581,
297,
3608,
534,
79,
297,
1768,
534,
409,
29295,
358,
199,
6003,
14,
13512,
8,
56,
59,
1400,
26,
1960,
12,
378,
467,
1323,
59,
1400,
26,
1960,
12,
413,
467,
3164,
534,
6304,
297,
3608,
534,
88,
297,
1768,
534,
422,
338,
2326,
358,
199,
6003,
14,
14168,
360,
8096,
279,
2582,
358,
199,
6003,
14,
13849,
360,
4127,
279,
2582,
358,
199,
6003,
14,
10231,
8,
2102,
534,
4142,
3602,
358,
199,
6003,
14,
2384,
342,
199,
199,
802,
78,
275,
3492,
301,
4695,
265,
342,
199,
802,
78,
14,
3269,
8,
56,
12,
89,
9,
199,
6003,
14,
2798,
8,
1842,
8,
17,
12,
822,
8,
802,
78,
14,
2550,
4602,
11,
17,
395,
299,
4812,
14,
2550,
3131,
3608,
534,
79,
297,
3164,
628,
7731,
531,
199,
6003,
14,
14168,
360,
29322,
83,
358,
199,
6003,
14,
13849,
360,
3259,
402,
3201,
14368,
83,
358,
199,
6003,
14,
2384,
342,
199,
199,
3,
22467,
282,
7425,
16777,
805,
370,
13104,
794,
314,
14692,
18135,
367,
499,
36,
13148,
26,
199,
504,
8027,
14,
7120,
492,
491,
4957,
4117,
1130,
199,
199,
318,
5137,
63,
16622,
63,
11963,
8,
56,
12,
612,
12,
12429,
12,
12401,
29,
16,
14,
996,
304,
2286,
327,
3272,
3608,
4306,
436,
3164,
2341,
272,
14327,
275,
661,
83,
297,
283,
88,
297,
283,
79,
297,
14452,
297,
283,
86,
358,
272,
9229,
275,
661,
581,
297,
283,
6304,
297,
283,
4040,
7731,
297,
283,
12150,
297,
283,
28291,
358,
272,
14920,
275,
491,
4957,
4117,
1130,
8,
7120,
1491,
552,
8,
1590,
14,
3235,
8,
89,
18229,
2286,
327,
5137,
314,
14692,
13195,
272,
671,
17,
63,
827,
12,
671,
17,
63,
988,
275,
1323,
3981,
378,
1055,
827,
342,
446,
413,
12,
1323,
3981,
378,
1055,
988,
342,
435,
413,
272,
671,
18,
63,
827,
12,
671,
18,
63,
988,
275,
1323,
3981,
413,
1055,
827,
342,
446,
413,
12,
1323,
3981,
413,
1055,
988,
342,
435,
413,
272,
19379,
17,
12,
19379,
18,
275,
980,
14,
6480,
3825,
8,
1590,
14,
5605,
8,
88,
17,
63,
827,
12,
671,
17,
63,
988,
12,
12401,
395,
980,
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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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
] |
ksrajkumar/openerp-6.1
|
openerp/addons/sale_layout/__openerp__.py
|
9
|
1948
|
##############################################################################
#
# 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/>.
#
##############################################################################
{
"name" : "Sales Orders Print Layout",
"version" : "1.0",
"images" : ["images/sale_layout.jpeg"],
"depends" : ["sale", "account_invoice_layout"],
"author" : "OpenERP SA",
'complexity': "easy",
"description": """
This module provides features to improve the layout of the Sales Order.
=======================================================================
It gives you the possibility to
* order all the lines of a sales order
* add titles, comment lines, sub total lines
* draw horizontal lines and put page breaks
""",
"website" : "http://www.openerp.com",
"category" : "Sales Management",
"init_xml" : [],
"demo_xml" : [],
"update_xml" : [
"sale_layout_view.xml",
"sale_layout_report.xml",
],
"test" : ['test/sale_layout_report.yml'],
"auto_install": False,
"installable": True,
"certificate" : "00982333536005187677",
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
4605,
199,
3,
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,
199,
3,
199,
4605,
199,
199,
91,
272,
298,
354,
2,
520,
298,
18220,
4236,
7735,
9101,
25604,
401,
272,
298,
1023,
2,
520,
298,
17,
14,
16,
401,
272,
298,
4782,
2,
520,
2097,
4782,
15,
8515,
63,
4209,
14,
14230,
2255,
272,
298,
8912,
2,
520,
2097,
8515,
401,
298,
2048,
63,
5404,
63,
4209,
2255,
272,
298,
2502,
2,
520,
298,
25347,
13950,
401,
272,
283,
5254,
1209,
356,
298,
13581,
401,
272,
298,
1802,
582,
408,
199,
2765,
859,
6571,
4534,
370,
19053,
314,
7054,
402,
314,
428,
7098,
9240,
14,
199,
5695,
18673,
199,
199,
7940,
10557,
1265,
314,
31077,
370,
272,
627,
1865,
1006,
314,
2385,
402,
282,
21702,
1865,
272,
627,
1050,
16194,
12,
3721,
2385,
12,
1007,
3141,
2385,
272,
627,
5954,
17528,
2385,
436,
5324,
2034,
18277,
339,
10327,
272,
298,
7360,
2,
520,
298,
1014,
921,
1544,
14,
11267,
14,
957,
401,
272,
298,
3710,
2,
520,
298,
18220,
8259,
401,
272,
298,
826,
63,
1652,
2,
520,
990,
272,
298,
8768,
63,
1652,
2,
520,
990,
272,
298,
873,
63,
1652,
2,
520,
359,
267,
298,
8515,
63,
4209,
63,
1345,
14,
1652,
401,
267,
298,
8515,
63,
4209,
63,
3070,
14,
1652,
401,
272,
2156,
272,
298,
396,
2,
520,
788,
396,
15,
8515,
63,
4209,
63,
3070,
14,
11714,
995,
272,
298,
2495,
63,
3174,
582,
756,
12,
272,
298,
21762,
582,
715,
12,
272,
298,
6999,
2,
520,
298,
8581,
2564,
1153,
1276,
1344,
7972,
1085,
2114,
1138,
401,
199,
93,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
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,
199,
3,
199,
4605,
199,
199,
91,
272,
298,
354,
2,
520,
298,
18220,
4236,
7735,
9101,
25604,
401,
272,
298,
1023,
2,
520,
298,
17,
14,
16,
401,
272,
298,
4782,
2,
520,
2097,
4782,
15,
8515,
63,
4209,
14,
14230,
2255,
272,
298,
8912,
2,
520,
2097,
8515,
401,
298,
2048,
63,
5404,
63,
4209,
2255,
272,
298,
2502,
2,
520,
298,
25347,
13950,
401,
272,
283,
5254,
1209,
356,
298,
13581,
401,
272,
298,
1802,
582,
408,
199,
2765,
859,
6571,
4534,
370,
19053,
314,
7054,
402,
314,
428,
7098,
9240,
14,
199,
5695,
18673,
199,
199,
7940,
10557,
1265,
314,
31077,
370,
272,
627,
1865,
1006,
314,
2385,
402,
282,
21702,
1865,
272,
627,
1050,
16194,
12,
3721,
2385,
12,
1007,
3141,
2385,
272,
627,
5954,
17528,
2385,
436,
5324,
2034,
18277,
339,
10327,
272,
298,
7360,
2,
520,
298,
1014,
921,
1544,
14,
11267,
14,
957,
401,
272,
298,
3710,
2,
520,
298,
18220,
8259,
401,
272,
298,
826,
63,
1652,
2,
520,
990,
272,
298,
8768,
63,
1652,
2,
520,
990,
272,
298,
873,
63,
1652,
2,
520,
359,
267,
298,
8515,
63,
4209,
63,
1345,
14,
1652,
401,
267,
298,
8515,
63,
4209,
63,
3070,
14,
1652,
401,
272,
2156,
272,
298,
396,
2,
520,
788,
396,
15,
8515,
63,
4209,
63,
3070,
14,
11714,
995,
272,
298,
2495,
63,
3174,
582,
756,
12,
272,
298,
21762,
582,
715,
12,
272,
298,
6999,
2,
520,
298,
8581,
2564,
1153,
1276,
1344,
7972,
1085,
2114,
1138,
401,
199,
93,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,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competitive-programming
|
kattis/bitbybit/bitbybit.py
|
1
|
1211
|
def generate():
return list('?'*32)
def resolveAND(i, j):
if i == '?' and j == '?':
return '?'
if (i == '?' or j == '?') and (i == '0' or j == '0'):
return '0'
if (i == '?' or j == '?') and (i == '1' or j == '1'):
return '?'
b = bool(int(i)) and bool(int(j))
return str(int(b))
def resolveOR(i, j):
if i == '?' and j == '?':
return '?'
if (i == '?' or j == '?') and (i == '1' or j == '1'):
return '1'
if (i == '?' or j == '?') and (i == '0' or j == '0'):
return '?'
b = bool(int(i)) or bool(int(j))
return str(int(b))
instructions = int(input())
while instructions != 0:
bitset = generate()
for k in range(instructions):
op, *index = input().split()
index = [int(x) for x in index]
if op == 'CLEAR':
bitset[index[0]] = '0'
elif op == 'SET':
bitset[index[0]] = '1'
elif op == 'OR':
bitset[index[0]] = resolveOR(bitset[index[0]], bitset[index[1]])
else:
bitset[index[0]] = resolveAND(bitset[index[0]], bitset[index[1]])
bitset.reverse()
print(''.join(bitset))
instructions = int(input())
|
gpl-3.0
|
[
199,
318,
3550,
837,
272,
372,
769,
360,
14069,
10,
708,
9,
199,
199,
318,
7512,
3649,
8,
73,
12,
1335,
304,
272,
340,
284,
508,
15539,
436,
1335,
508,
8720,
356,
267,
372,
15539,
339,
340,
334,
73,
508,
15539,
503,
1335,
508,
8720,
358,
436,
334,
73,
508,
283,
16,
7,
503,
1335,
508,
283,
16,
735,
267,
372,
283,
16,
7,
339,
340,
334,
73,
508,
15539,
503,
1335,
508,
8720,
358,
436,
334,
73,
508,
283,
17,
7,
503,
1335,
508,
283,
17,
735,
267,
372,
15539,
339,
330,
275,
2155,
8,
442,
8,
73,
430,
436,
2155,
8,
442,
8,
74,
430,
272,
372,
620,
8,
442,
8,
66,
430,
199,
199,
318,
7512,
726,
8,
73,
12,
1335,
304,
272,
340,
284,
508,
15539,
436,
1335,
508,
8720,
356,
267,
372,
15539,
339,
340,
334,
73,
508,
15539,
503,
1335,
508,
8720,
358,
436,
334,
73,
508,
283,
17,
7,
503,
1335,
508,
283,
17,
735,
267,
372,
283,
17,
7,
339,
340,
334,
73,
508,
15539,
503,
1335,
508,
8720,
358,
436,
334,
73,
508,
283,
16,
7,
503,
1335,
508,
283,
16,
735,
267,
372,
15539,
339,
330,
275,
2155,
8,
442,
8,
73,
430,
503,
2155,
8,
442,
8,
74,
430,
272,
372,
620,
8,
442,
8,
66,
430,
421,
199,
20718,
275,
1109,
8,
1210,
1012,
199,
199,
6710,
15794,
1137,
378,
26,
272,
4546,
409,
275,
3550,
342,
339,
367,
1022,
315,
1425,
8,
20718,
304,
267,
1687,
12,
627,
1080,
275,
1324,
1252,
1294,
342,
267,
1478,
275,
359,
442,
8,
88,
9,
367,
671,
315,
1478,
61,
398,
340,
1687,
508,
283,
20706,
356,
288,
4546,
409,
59,
1080,
59,
16,
2677,
275,
283,
16,
7,
267,
916,
1687,
508,
283,
3597,
356,
288,
4546,
409,
59,
1080,
59,
16,
2677,
275,
283,
17,
7,
267,
916,
1687,
508,
283,
726,
356,
288,
4546,
409,
59,
1080,
59,
16,
2677,
275,
7512,
726,
8,
2075,
409,
59,
1080,
59,
16,
2365,
4546,
409,
59,
1080,
59,
17,
3934,
267,
587,
26,
288,
4546,
409,
59,
1080,
59,
16,
2677,
275,
7512,
3649,
8,
2075,
409,
59,
1080,
59,
16,
2365,
4546,
409,
59,
1080,
59,
17,
3934,
339,
4546,
409,
14,
4471,
342,
339,
870,
17840,
904,
8,
2075,
409,
430,
339,
15794,
275,
1109,
8,
1210,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
318,
3550,
837,
272,
372,
769,
360,
14069,
10,
708,
9,
199,
199,
318,
7512,
3649,
8,
73,
12,
1335,
304,
272,
340,
284,
508,
15539,
436,
1335,
508,
8720,
356,
267,
372,
15539,
339,
340,
334,
73,
508,
15539,
503,
1335,
508,
8720,
358,
436,
334,
73,
508,
283,
16,
7,
503,
1335,
508,
283,
16,
735,
267,
372,
283,
16,
7,
339,
340,
334,
73,
508,
15539,
503,
1335,
508,
8720,
358,
436,
334,
73,
508,
283,
17,
7,
503,
1335,
508,
283,
17,
735,
267,
372,
15539,
339,
330,
275,
2155,
8,
442,
8,
73,
430,
436,
2155,
8,
442,
8,
74,
430,
272,
372,
620,
8,
442,
8,
66,
430,
199,
199,
318,
7512,
726,
8,
73,
12,
1335,
304,
272,
340,
284,
508,
15539,
436,
1335,
508,
8720,
356,
267,
372,
15539,
339,
340,
334,
73,
508,
15539,
503,
1335,
508,
8720,
358,
436,
334,
73,
508,
283,
17,
7,
503,
1335,
508,
283,
17,
735,
267,
372,
283,
17,
7,
339,
340,
334,
73,
508,
15539,
503,
1335,
508,
8720,
358,
436,
334,
73,
508,
283,
16,
7,
503,
1335,
508,
283,
16,
735,
267,
372,
15539,
339,
330,
275,
2155,
8,
442,
8,
73,
430,
503,
2155,
8,
442,
8,
74,
430,
272,
372,
620,
8,
442,
8,
66,
430,
421,
199,
20718,
275,
1109,
8,
1210,
1012,
199,
199,
6710,
15794,
1137,
378,
26,
272,
4546,
409,
275,
3550,
342,
339,
367,
1022,
315,
1425,
8,
20718,
304,
267,
1687,
12,
627,
1080,
275,
1324,
1252,
1294,
342,
267,
1478,
275,
359,
442,
8,
88,
9,
367,
671,
315,
1478,
61,
398,
340,
1687,
508,
283,
20706,
356,
288,
4546,
409,
59,
1080,
59,
16,
2677,
275,
283,
16,
7,
267,
916,
1687,
508,
283,
3597,
356,
288,
4546,
409,
59,
1080,
59,
16,
2677,
275,
283,
17,
7,
267,
916,
1687,
508,
283,
726,
356,
288,
4546,
409,
59,
1080,
59,
16,
2677,
275,
7512,
726,
8,
2075,
409,
59,
1080,
59,
16,
2365,
4546,
409,
59,
1080,
59,
17,
3934,
267,
587,
26,
288,
4546,
409,
59,
1080,
59,
16,
2677,
275,
7512,
3649,
8,
2075,
409,
59,
1080,
59,
16,
2365,
4546,
409,
59,
1080,
59,
17,
3934,
339,
4546,
409,
14,
4471,
342,
339,
870,
17840,
904,
8,
2075,
409,
430,
339,
15794,
275,
1109,
8,
1210,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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
#!/usr/bin/env python
#
# Copyright 2011-2013 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
from gnuradio import gr, gr_unittest, filter, blocks
class test_dc_blocker(gr_unittest.TestCase):
def setUp (self):
self.tb = gr.top_block ()
def tearDown (self):
self.tb = None
def test_001(self):
''' Test impulse response - long form, cc '''
src_data = [1,] + 100*[0,]
expected_result = ((-0.02072429656982422+0j), (-0.02081298828125+0j),
(0.979156494140625+0j), (-0.02081298828125+0j),
(-0.02072429656982422+0j))
src = blocks.vector_source_c(src_data)
op = filter.dc_blocker_cc(32, True)
dst = blocks.vector_sink_c()
self.tb.connect (src, op, dst)
self.tb.run()
# only test samples around 2D-2
result_data = dst.data()[60:65]
self.assertComplexTuplesAlmostEqual (expected_result, result_data)
def test_002(self):
''' Test impulse response - short form, cc '''
src_data = [1,] + 100*[0,]
expected_result = ((-0.029296875+0j), (-0.0302734375+0j),
(0.96875+0j), (-0.0302734375+0j),
(-0.029296875+0j))
src = blocks.vector_source_c(src_data)
op = filter.dc_blocker_cc(32, False)
dst = blocks.vector_sink_c()
self.tb.connect (src, op, dst)
self.tb.run()
# only test samples around D-1
result_data = dst.data()[29:34]
self.assertComplexTuplesAlmostEqual (expected_result, result_data)
def test_003(self):
''' Test impulse response - long form, ff '''
src_data = [1,] + 100*[0,]
expected_result = ((-0.02072429656982422), (-0.02081298828125),
(0.979156494140625), (-0.02081298828125),
(-0.02072429656982422))
src = blocks.vector_source_f(src_data)
op = filter.dc_blocker_ff(32, True)
dst = blocks.vector_sink_f()
self.tb.connect (src, op, dst)
self.tb.run()
# only test samples around 2D-2
result_data = dst.data()[60:65]
self.assertFloatTuplesAlmostEqual (expected_result, result_data)
def test_004(self):
''' Test impulse response - short form, ff '''
src_data = [1,] + 100*[0,]
expected_result = ((-0.029296875), (-0.0302734375),
(0.96875), (-0.0302734375),
(-0.029296875))
src = blocks.vector_source_f(src_data)
op = filter.dc_blocker_ff(32, False)
dst = blocks.vector_sink_f()
self.tb.connect (src, op, dst)
self.tb.run()
# only test samples around D-1
result_data = dst.data()[29:34]
self.assertFloatTuplesAlmostEqual (expected_result, result_data)
if __name__ == '__main__':
gr_unittest.run(test_dc_blocker, "test_dc_blocker.xml")
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
7760,
13,
6965,
2868,
2290,
2752,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
1664,
13514,
199,
3,
199,
3,
1664,
13514,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
1664,
13514,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
1664,
13514,
27,
1937,
314,
570,
9685,
14,
221,
982,
440,
12,
2218,
370,
199,
3,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
199,
3,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
421,
199,
504,
24526,
492,
7192,
12,
7192,
63,
2796,
12,
2457,
12,
5664,
199,
199,
533,
511,
63,
3833,
63,
1457,
281,
8,
2587,
63,
2796,
14,
1746,
304,
339,
347,
3613,
334,
277,
304,
267,
291,
14,
5842,
275,
7192,
14,
2119,
63,
1457,
6248,
339,
347,
6766,
334,
277,
304,
267,
291,
14,
5842,
275,
488,
339,
347,
511,
63,
4587,
8,
277,
304,
267,
1449,
1379,
1742,
13055,
1177,
446,
1846,
1824,
12,
7429,
1449,
267,
2928,
63,
576,
275,
359,
17,
12,
61,
435,
2948,
23033,
16,
12,
61,
267,
1420,
63,
1099,
275,
334,
2801,
16,
14,
996,
1780,
1194,
11700,
1367,
2905,
1194,
1081,
11,
16,
74,
395,
5868,
16,
14,
996,
2036,
7263,
1299,
1651,
6889,
11,
16,
74,
395,
2574,
334,
16,
14,
31955,
1046,
772,
2635,
1079,
1690,
821,
11,
16,
74,
395,
5868,
16,
14,
996,
2036,
7263,
1299,
1651,
6889,
11,
16,
74,
395,
2574,
5868,
16,
14,
996,
1780,
1194,
11700,
1367,
2905,
1194,
1081,
11,
16,
74,
430,
398,
2928,
275,
5664,
14,
4106,
63,
1365,
63,
67,
8,
2164,
63,
576,
9,
267,
1687,
275,
2457,
14,
3833,
63,
1457,
281,
63,
2055,
8,
708,
12,
715,
9,
267,
5042,
275,
5664,
14,
4106,
63,
11279,
63,
67,
342,
398,
291,
14,
5842,
14,
2242,
334,
2164,
12,
1687,
12,
5042,
9,
267,
291,
14,
5842,
14,
1065,
342,
398,
327,
1454,
511,
5845,
6818,
499,
36,
13,
18,
267,
754,
63,
576,
275,
5042,
14,
576,
3430,
2259,
26,
2182,
61,
267,
291,
14,
479,
14500,
7075,
83,
7331,
334,
2062,
63,
1099,
12,
754,
63,
576,
9,
339,
347,
511,
63,
7432,
8,
277,
304,
267,
1449,
1379,
1742,
13055,
1177,
446,
3974,
1824,
12,
7429,
1449,
267,
2928,
63,
576,
275,
359,
17,
12,
61,
435,
2948,
23033,
16,
12,
61,
267,
1420,
63,
1099,
275,
334,
2801,
16,
14,
13996,
11700,
13357,
11,
16,
74,
395,
5868,
16,
14,
1644,
14218,
1082,
9946,
11,
16,
74,
395,
2574,
334,
16,
14,
2534,
13357,
11,
16,
74,
395,
5868,
16,
14,
1644,
14218,
1082,
9946,
11,
16,
74,
395,
2574,
5868,
16,
14,
13996,
11700,
13357,
11,
16,
74,
430,
398,
2928,
275,
5664,
14,
4106,
63,
1365,
63,
67,
8,
2164,
63,
576,
9,
267,
1687,
275,
2457,
14,
3833,
63,
1457,
281,
63,
2055,
8,
708,
12,
756,
9,
267,
5042,
275,
5664,
14,
4106,
63,
11279,
63,
67,
342,
398,
291,
14,
5842,
14,
2242,
334,
2164,
12,
1687,
12,
5042,
9,
267,
291,
14,
5842,
14,
1065,
342,
398,
327,
1454,
511,
5845,
6818,
577,
13,
17,
267,
754,
63,
576,
275,
5042,
14,
576,
3430,
1398,
26,
1082,
61,
267,
291,
14,
479,
14500,
7075,
83,
7331,
334,
2062,
63,
1099,
12,
754,
63,
576,
9,
2378,
347,
511,
63,
8262,
8,
277,
304,
267,
1449,
1379,
1742,
13055,
1177,
446,
1846,
1824,
12,
16328,
1449,
267,
2928,
63,
576,
275,
359,
17,
12,
61,
435,
2948,
23033,
16,
12,
61,
267,
1420,
63,
1099,
275,
334,
2801,
16,
14,
996,
1780,
1194,
11700,
1367,
2905,
1194,
1081,
395,
5868,
16,
14,
996,
2036,
7263,
1299,
1651,
6889,
395,
2574,
334,
16,
14,
31955,
1046,
772,
2635,
1079,
1690,
821,
395,
5868,
16,
14,
996,
2036,
7263,
1299,
1651,
6889,
395,
2574,
5868,
16,
14,
996,
1780,
1194,
11700,
1367,
2905,
1194,
1081,
430,
398,
2928,
275,
5664,
14,
4106,
63,
1365,
63,
70,
8,
2164,
63,
576,
9,
267,
1687,
275,
2457,
14,
3833,
63,
1457,
281,
63,
556,
8,
708,
12,
715,
9,
267,
5042,
275,
5664,
14,
4106,
63,
11279,
63,
70,
342,
398,
291,
14,
5842,
14,
2242,
334,
2164,
12,
1687,
12,
5042,
9,
267,
291,
14,
5842,
14,
1065,
342,
398,
327,
1454,
511,
5845,
6818,
499,
36,
13,
18,
267,
754,
63,
576,
275,
5042,
14,
576,
3430,
2259,
26,
2182,
61,
267,
291,
14,
479,
5136,
7075,
83,
7331,
334,
2062,
63,
1099,
12,
754,
63,
576,
9,
339,
347,
511,
63,
7979,
8,
277,
304,
267,
1449,
1379,
1742,
13055,
1177,
446,
3974,
1824,
12,
16328,
1449,
267,
2928,
63,
576,
275,
359,
17,
12,
61,
435,
2948,
23033,
16,
12,
61,
267,
1420,
63,
1099,
275,
334,
2801,
16,
14,
13996,
11700,
13357,
395,
5868,
16,
14,
1644,
14218,
1082,
9946,
395,
2574,
334,
16,
14,
2534,
13357,
395,
5868,
16,
14,
1644,
14218,
1082,
9946,
395,
2574,
5868,
16,
14,
13996,
11700,
13357,
430,
398,
2928,
275,
5664,
14,
4106,
63,
1365,
63,
70,
8,
2164,
63,
576,
9,
267,
1687,
275,
2457,
14,
3833,
63,
1457,
281,
63,
556,
8,
708,
12,
756,
9,
267,
5042,
275,
5664,
14,
4106,
63,
11279,
63,
70,
342,
398,
291,
14,
5842,
14,
2242,
334,
2164,
12,
1687,
12,
5042,
9,
267,
291,
14,
5842,
14,
1065,
342,
398,
327,
1454,
511,
5845,
6818,
577,
13,
17,
267,
754,
63,
576
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
7760,
13,
6965,
2868,
2290,
2752,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
1664,
13514,
199,
3,
199,
3,
1664,
13514,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
1664,
13514,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
1664,
13514,
27,
1937,
314,
570,
9685,
14,
221,
982,
440,
12,
2218,
370,
199,
3,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
199,
3,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
421,
199,
504,
24526,
492,
7192,
12,
7192,
63,
2796,
12,
2457,
12,
5664,
199,
199,
533,
511,
63,
3833,
63,
1457,
281,
8,
2587,
63,
2796,
14,
1746,
304,
339,
347,
3613,
334,
277,
304,
267,
291,
14,
5842,
275,
7192,
14,
2119,
63,
1457,
6248,
339,
347,
6766,
334,
277,
304,
267,
291,
14,
5842,
275,
488,
339,
347,
511,
63,
4587,
8,
277,
304,
267,
1449,
1379,
1742,
13055,
1177,
446,
1846,
1824,
12,
7429,
1449,
267,
2928,
63,
576,
275,
359,
17,
12,
61,
435,
2948,
23033,
16,
12,
61,
267,
1420,
63,
1099,
275,
334,
2801,
16,
14,
996,
1780,
1194,
11700,
1367,
2905,
1194,
1081,
11,
16,
74,
395,
5868,
16,
14,
996,
2036,
7263,
1299,
1651,
6889,
11,
16,
74,
395,
2574,
334,
16,
14,
31955,
1046,
772,
2635,
1079,
1690,
821,
11,
16,
74,
395,
5868,
16,
14,
996,
2036,
7263,
1299,
1651,
6889,
11,
16,
74,
395,
2574,
5868,
16,
14,
996,
1780,
1194,
11700,
1367,
2905,
1194,
1081,
11,
16,
74,
430,
398,
2928,
275,
5664,
14,
4106,
63,
1365,
63,
67,
8,
2164,
63,
576,
9,
267,
1687,
275,
2457,
14,
3833,
63,
1457,
281,
63,
2055,
8,
708,
12,
715,
9,
267,
5042,
275,
5664,
14,
4106,
63,
11279,
63,
67,
342,
398,
291,
14,
5842,
14,
2242,
334,
2164,
12,
1687,
12,
5042,
9,
267,
291,
14,
5842,
14,
1065,
342,
398,
327,
1454,
511,
5845,
6818,
499,
36,
13,
18,
267,
754,
63,
576,
275,
5042,
14,
576,
3430,
2259,
26,
2182,
61,
267,
291,
14,
479,
14500,
7075,
83,
7331,
334,
2062,
63,
1099,
12,
754,
63,
576,
9,
339,
347,
511,
63,
7432,
8,
277,
304,
267,
1449,
1379,
1742,
13055,
1177,
446,
3974,
1824,
12,
7429,
1449,
267,
2928,
63,
576,
275,
359,
17,
12,
61,
435,
2948,
23033,
16,
12,
61,
267,
1420,
63,
1099,
275,
334,
2801,
16,
14,
13996,
11700,
13357,
11,
16,
74,
395,
5868,
16,
14,
1644,
14218,
1082,
9946,
11,
16,
74,
395,
2574,
334,
16,
14,
2534,
13357,
11,
16,
74,
395,
5868,
16,
14,
1644,
14218,
1082,
9946,
11,
16,
74,
395,
2574,
5868,
16,
14,
13996,
11700,
13357,
11,
16,
74,
430,
398,
2928,
275,
5664,
14,
4106,
63,
1365,
63,
67,
8,
2164,
63,
576,
9,
267,
1687,
275,
2457,
14,
3833,
63,
1457,
281,
63,
2055,
8,
708,
12,
756,
9,
267,
5042,
275,
5664,
14,
4106,
63,
11279,
63,
67,
342,
398,
291,
14,
5842,
14,
2242,
334,
2164,
12,
1687,
12,
5042,
9,
267,
291,
14,
5842,
14,
1065,
342,
398,
327,
1454,
511,
5845,
6818,
577,
13,
17,
267,
754,
63,
576,
275,
5042,
14,
576,
3430,
1398,
26,
1082,
61,
267,
291,
14,
479,
14500,
7075,
83,
7331,
334,
2062,
63,
1099,
12,
754,
63,
576,
9,
2378,
347,
511,
63,
8262,
8,
277,
304,
267,
1449,
1379,
1742,
13055,
1177,
446,
1846,
1824,
12,
16328,
1449,
267,
2928,
63,
576,
275,
359,
17,
12,
61,
435,
2948,
23033,
16,
12,
61,
267,
1420,
63,
1099,
275,
334,
2801,
16,
14,
996,
1780,
1194,
11700,
1367,
2905,
1194,
1081,
395,
5868,
16,
14,
996,
2036,
7263,
1299,
1651,
6889,
395,
2574,
334,
16,
14,
31955,
1046,
772,
2635,
1079,
1690,
821,
395,
5868,
16,
14,
996,
2036,
7263,
1299,
1651,
6889,
395,
2574,
5868,
16,
14,
996,
1780,
1194,
11700,
1367,
2905,
1194,
1081,
430,
398,
2928,
275,
5664,
14,
4106,
63,
1365,
63,
70,
8,
2164,
63,
576,
9,
267,
1687,
275,
2457,
14,
3833,
63,
1457,
281,
63,
556,
8,
708,
12,
715,
9,
267,
5042,
275,
5664,
14,
4106,
63,
11279,
63,
70,
342,
398,
291,
14,
5842,
14,
2242,
334,
2164,
12,
1687,
12,
5042,
9,
267,
291,
14,
5842,
14,
1065,
342,
398,
327,
1454,
511,
5845,
6818,
499,
36,
13,
18,
267,
754,
63,
576,
275,
5042,
14,
576,
3430,
2259,
26,
2182,
61,
267,
291,
14,
479,
5136,
7075,
83,
7331,
334,
2062,
63,
1099,
12,
754,
63,
576,
9,
339,
347,
511,
63,
7979,
8,
277,
304,
267,
1449,
1379,
1742,
13055,
1177,
446,
3974,
1824,
12,
16328,
1449,
267,
2928,
63,
576,
275,
359,
17,
12,
61,
435,
2948,
23033,
16,
12,
61,
267,
1420,
63,
1099,
275,
334,
2801,
16,
14,
13996,
11700,
13357,
395,
5868,
16,
14,
1644,
14218,
1082,
9946,
395,
2574,
334,
16,
14,
2534,
13357,
395,
5868,
16,
14,
1644,
14218,
1082,
9946,
395,
2574,
5868,
16,
14,
13996,
11700,
13357,
430,
398,
2928,
275,
5664,
14,
4106,
63,
1365,
63,
70,
8,
2164,
63,
576,
9,
267,
1687,
275,
2457,
14,
3833,
63,
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
] |
kichkasch/ioids
|
g4ds/g4dslogging.py
|
1
|
5157
|
"""
Provides Logging facilities.
Grid for Digital Security (G4DS)
Currently, simple logging into files.
@author: Michael Pilgermann
@contact: mailto:mpilgerm@glam.ac.uk
@license: GPL (General Public License)
"""
from time import strftime
import string
import syslog
# "singleton"
_defaultLogger = None
def getDefaultLogger():
"""
Singleton implementation.
"""
global _defaultLogger
if not _defaultLogger:
_defaultLogger = FileLogger()
return _defaultLogger
LOGSERVER_STATUS = 0 # boot up / shutdown of logging
COMMUNICATION_INCOMING_ERROR = 100
COMMUNICATION_INCOMING_NO_ENDPOINT = 101
COMMUNICATION_INCOMING_MSG = 199
COMMUNICATION_INCOMING_MSG_DETAILS = 198
COMMUNICATION_OUTGOING_ERROR = 200
COMMUNICATION_OUTGOING_NO_ENDPOINT = 201
COMMUNICATION_OUTGOING_ERROR_SERVICE = 202
COMMUNICATION_OUTGOING_MSG = 299
COMMUNICATION_OUTGOING_MSG_CTRL = 298
COMMUNICATION_OUTGOING_MSG_ROUTED = 297
COMMUNICATION_OUTGOING_MSG_DETAILS = 296
COMMUNICATION_OUTGOING_MSG_SERVICE_DETAILS = 295
CONTROL_SYSTEM_DETAILS = 399
CONTROL_SYSTEM_ERROR = 300
SERVICES_NEW_INCOMING = 999
SERVICES_CLIENT_CONNECT = 998
SERVICES_CLIENT_DISCONNECT = 997
SERVICES_CLIENT_SENDINGERROR = 900
ROUTING_MESSAGE_PASSED = 899
ROUTING_TABLE_UPDATED = 799
ROUTING_TABLE_UPDATED_MANUALLY = 798
ROUTING_TABLE_UPDATED_PUHSHED = 797
ROUTING_TABLE_UPDATED_ERROR = 700
PERMISSION_MATRIX_RECALCULATED = 699
PERMISSION_MESSAGE_PASSED = 698
PERMISSION_MESSAGE_DROPPED = 601
PERMISSION_POLICY_ERROR = 602
CLASS={}
CLASS[0] = [LOGSERVER_STATUS, COMMUNICATION_INCOMING_ERROR, COMMUNICATION_OUTGOING_ERROR]
CLASS[1] = [COMMUNICATION_INCOMING_NO_ENDPOINT, COMMUNICATION_OUTGOING_NO_ENDPOINT, PERMISSION_MESSAGE_DROPPED]
CLASS[1].extend(CLASS[0])
CLASS[2] = [ROUTING_TABLE_UPDATED, PERMISSION_MATRIX_RECALCULATED, CONTROL_SYSTEM_DETAILS]
CLASS[2].extend(CLASS[1])
CLASS[3] = [PERMISSION_MESSAGE_PASSED]
CLASS[3].extend(CLASS[2])
CLASS[4] = []
CLASS[4].extend(CLASS[3])
CLASS[5] = [] #everything - not used
class FileLogger:
"""
All messages are equipped with a timestamp and line wise written to a log file.
Addtionally, this class supports logging into syslog facilities.
@ivar _logfile: Reference to the file instance
@type _logfile: C{File}
@ivar _level: Log level to be used for the instance (defined in config file)
@type _level: C{int}
"""
def __init__(self):
"""
Open the log file.
Put a log message in the log file for brining up the g4ds log service.
"""
import config
from config import LOGGING_FILENAME, LOGGING_LEVEL, ENABLE_SYSLOG, SYSLOG_IDENTIFIER
self._logfile = open(LOGGING_FILENAME, 'a')
self._level = LOGGING_LEVEL
self._syslogOn = ENABLE_SYSLOG
if ENABLE_SYSLOG:
syslog.openlog(SYSLOG_IDENTIFIER)
self.newMessage(LOGSERVER_STATUS, 'G4DS Logging started (level %d)' %(self._level))
def closedown(self):
"""
Shutdown logging.
Put a log message in the log file for closing down g4ds logging and finally close the log file.
"""
self.newMessage(LOGSERVER_STATUS, 'G4DS Logging shut down')
self._logfile.close()
if self._syslogOn:
syslog.closelog()
def newMessage(self, category, message):
"""
New entry for the log system.
A check is performed, whether the given category is to be logged in the activated log level. If so,
a message is generated, made up by a time stamp, the category value and the message itself.
"""
try:
if self._level != 5:
CLASS[self._level].index(category)
st = strftime('%Y-%m-%d %H:%M:%S').ljust(17) + ' ' + string.zfill(category, 3) + ' ' + str(message) + '\n'
self._logfile.write(st)
self._logfile.flush()
if self._syslogOn:
syslog.syslog(string.zfill(category, 3) + ' ' + str(message))
except KeyError:
pass # this log message is not in the class for the given log level - just ignore it
def getLatestMessages(self, n):
"""
Returns the last 'n' lines of the log file.
@param n: Number of lines requested
@type n: C{int}
@return: The last lines - each line as a string - together in a list
@rtype: C{List} of C{String}
"""
from config import LOGGING_FILENAME, LOGGING_LEVEL
logfile = open(LOGGING_FILENAME, 'r')
lines = []
s = logfile.readline().rstrip()
i = -1
while s != '':
i = (i+1) % n
if len(lines) > i:
lines[i] = s
else:
lines.append(s)
s = logfile.readline().rstrip()
logfile.close()
if len(lines) == i+1:
return lines
# put it in order
back = []
while len(back) < n:
i = (i+1) % n
back.append(lines[i])
return back
|
gpl-3.0
|
[
624,
199,
17473,
19928,
30242,
7999,
14,
199,
199,
7900,
367,
29979,
13863,
334,
39,
20,
3177,
9,
199,
199,
31499,
12,
3486,
2050,
1901,
1584,
14,
199,
199,
32,
2502,
26,
16922,
18130,
836,
20059,
199,
32,
7811,
26,
6016,
475,
26,
311,
382,
836,
77,
32,
71,
17984,
14,
645,
14,
3210,
199,
32,
1682,
26,
14629,
334,
14109,
1684,
844,
9,
199,
624,
199,
199,
504,
900,
492,
14053,
199,
646,
1059,
199,
646,
22112,
199,
199,
3,
298,
24675,
2,
199,
63,
885,
4455,
275,
488,
199,
318,
664,
2698,
4455,
837,
272,
408,
272,
13050,
1860,
4514,
14,
272,
408,
272,
2288,
485,
885,
4455,
272,
340,
440,
485,
885,
4455,
26,
267,
485,
885,
4455,
275,
3814,
4455,
342,
272,
372,
485,
885,
4455,
199,
199,
4947,
6613,
63,
6305,
275,
378,
259,
327,
8498,
1536,
1182,
12842,
402,
2050,
199,
5378,
11580,
2594,
63,
568,
11265,
1206,
63,
3170,
275,
2948,
199,
5378,
11580,
2594,
63,
568,
11265,
1206,
63,
2826,
63,
21054,
275,
14313,
199,
5378,
11580,
2594,
63,
568,
11265,
1206,
63,
9740,
275,
9013,
199,
5378,
11580,
2594,
63,
568,
11265,
1206,
63,
9740,
63,
25081,
51,
275,
413,
2905,
199,
199,
5378,
11580,
2594,
63,
1877,
13160,
1206,
63,
3170,
275,
1926,
199,
5378,
11580,
2594,
63,
1877,
13160,
1206,
63,
2826,
63,
21054,
275,
1784,
199,
5378,
11580,
2594,
63,
1877,
13160,
1206,
63,
3170,
63,
10486,
275,
19328,
199,
5378,
11580,
2594,
63,
1877,
13160,
1206,
63,
9740,
275,
32730,
199,
5378,
11580,
2594,
63,
1877,
13160,
1206,
63,
9740,
63,
22584,
275,
499,
2905,
199,
5378,
11580,
2594,
63,
1877,
13160,
1206,
63,
9740,
63,
14999,
1149,
275,
499,
2576,
199,
5378,
11580,
2594,
63,
1877,
13160,
1206,
63,
9740,
63,
25081,
51,
275,
499,
2534,
199,
5378,
11580,
2594,
63,
1877,
13160,
1206,
63,
9740,
63,
10486,
63,
25081,
51,
275,
499,
2720,
199,
199,
13060,
63,
12711,
63,
25081,
51,
275,
650,
1020,
199,
13060,
63,
12711,
63,
3170,
275,
9601,
199,
199,
3279,
8670,
63,
11365,
63,
568,
11265,
1206,
275,
22291,
199,
3279,
8670,
63,
9901,
63,
14657,
275,
8806,
24,
199,
3279,
8670,
63,
9901,
63,
6178,
14657,
275,
8806,
23,
199,
3279,
8670,
63,
9901,
63,
51,
15219,
3170,
275,
27151,
257,
199,
199,
14999,
1206,
63,
8272,
63,
48,
32032,
275,
1695,
1020,
199,
199,
14999,
1206,
63,
8723,
63,
23612,
1149,
275,
1520,
1020,
199,
14999,
1206,
63,
8723,
63,
23612,
1149,
63,
6588,
53,
28292,
275,
1520,
2905,
199,
14999,
1206,
63,
8723,
63,
23612,
1149,
63,
6903,
40,
3234,
1149,
275,
1520,
2576,
199,
14999,
1206,
63,
8723,
63,
23612,
1149,
63,
3170,
275,
30071,
199,
199,
4227,
22320,
63,
23483,
63,
9481,
748,
35,
1293,
6989,
275,
1227,
1020,
199,
4227,
22320,
63,
8272,
63,
48,
32032,
275,
1227,
2905,
199,
4227,
22320,
63,
8272,
63,
36,
1092,
7701,
1149,
275,
1227,
614,
199,
4227,
22320,
63,
15976,
63,
3170,
275,
1227,
996,
199,
199,
6885,
7622,
199,
6885,
59,
16,
61,
275,
359,
4947,
6613,
63,
6305,
12,
11293,
11580,
2594,
63,
568,
11265,
1206,
63,
3170,
12,
11293,
11580,
2594,
63,
1877,
13160,
1206,
63,
3170,
61,
199,
6885,
59,
17,
61,
275,
359,
5378,
11580,
2594,
63,
568,
11265,
1206,
63,
2826,
63,
21054,
12,
11293,
11580,
2594,
63,
1877,
13160,
1206,
63,
2826,
63,
21054,
12,
13873,
22320,
63,
8272,
63,
36,
1092,
7701,
1149,
61,
199,
6885,
59,
17,
1055,
2880,
8,
6885,
59,
16,
566,
199,
6885,
59,
18,
61,
275,
359,
14999,
1206,
63,
8723,
63,
23612,
1149,
12,
13873,
22320,
63,
23483,
63,
9481,
748,
35,
1293,
6989,
12,
8098,
63,
12711,
63,
25081,
51,
61,
199,
6885,
59,
18,
1055,
2880,
8,
6885,
59,
17,
566,
199,
6885,
59,
19,
61,
275,
359,
4227,
22320,
63,
8272,
63,
48,
32032,
61,
199,
6885,
59,
19,
1055,
2880,
8,
6885,
59,
18,
566,
199,
6885,
59,
20,
61,
275,
942,
199,
6885,
59,
20,
1055,
2880,
8,
6885,
59,
19,
566,
199,
6885,
59,
21,
61,
275,
942,
327,
14287,
2127,
446,
440,
1202,
1362,
199,
533,
3814,
4455,
26,
272,
408,
272,
2900,
3788,
787,
11960,
711,
1915,
543,
282,
4913,
436,
1004,
336,
572,
5313,
370,
282,
943,
570,
14,
2286,
2654,
296,
1183,
12,
642,
1021,
5171,
2050,
1901,
22112,
30242,
7999,
14,
2286,
768,
7725,
485,
12804,
26,
10944,
370,
314,
570,
1256,
272,
768,
466,
485,
12804,
26,
445,
91,
1173,
93,
272,
768,
7725,
485,
1896,
26,
5297,
2166,
370,
506,
1202,
367,
314,
1256,
334,
4037,
315,
1101,
570,
9,
272,
768,
466,
485,
1896,
26,
445,
91,
442,
93,
272,
408,
2286,
347,
636,
826,
721,
277,
304,
267,
408,
267,
3232,
314,
943,
570,
14,
2728,
16280,
282,
943,
1245,
315,
314,
943,
570,
367,
11665,
7969,
1536,
314,
486,
20,
795,
943,
2435,
14,
267,
408,
267,
492,
1101,
267,
687,
1101,
492,
3412,
22790,
63,
15440,
12,
3412,
22790,
63,
11817,
12,
27926,
63,
13326,
4947,
12,
10046,
51,
4947,
63,
22698,
4960,
291,
423,
12804,
275,
1551,
8,
27896,
63,
15440,
12,
283,
65,
358,
267,
291,
423,
1896,
275,
3412,
22790,
63,
11817,
2728,
291,
423,
16878,
3314,
275,
27926,
63,
13326,
4947,
2728,
340,
27926,
63,
13326,
4947,
26,
288,
22112,
14,
1490,
793,
8,
13326,
4947,
63,
22698,
9,
2728,
291,
14,
1222,
2209,
8,
4947,
6613,
63,
6305,
12,
283,
39,
20,
3177,
19928,
8239,
334,
1896,
450,
68,
3171,
2818,
277,
423,
1896,
430,
339,
347,
6876,
944,
8,
277,
304,
267,
408,
267,
5244,
6159,
2050,
14,
2728,
16280,
282,
943,
1245,
315,
314,
943,
570,
367,
11261,
3224,
486,
20,
795,
2050,
436,
3753,
4002,
314,
943,
570,
14,
267,
408,
267,
291,
14,
1222,
2209,
8,
4947,
6613,
63,
6305,
12,
283,
39,
20,
3177,
19928,
24761,
3224,
358,
267,
291,
423,
12804,
14,
1600,
342,
2728,
340,
291,
423,
16878,
3314,
26,
288,
22112,
14,
1600,
793,
342,
5493,
347,
892,
2209,
8,
277,
12,
4637,
12,
1245,
304,
267,
408,
267,
7053,
2397,
367,
314,
943,
2656,
14,
2728
] |
[
199,
17473,
19928,
30242,
7999,
14,
199,
199,
7900,
367,
29979,
13863,
334,
39,
20,
3177,
9,
199,
199,
31499,
12,
3486,
2050,
1901,
1584,
14,
199,
199,
32,
2502,
26,
16922,
18130,
836,
20059,
199,
32,
7811,
26,
6016,
475,
26,
311,
382,
836,
77,
32,
71,
17984,
14,
645,
14,
3210,
199,
32,
1682,
26,
14629,
334,
14109,
1684,
844,
9,
199,
624,
199,
199,
504,
900,
492,
14053,
199,
646,
1059,
199,
646,
22112,
199,
199,
3,
298,
24675,
2,
199,
63,
885,
4455,
275,
488,
199,
318,
664,
2698,
4455,
837,
272,
408,
272,
13050,
1860,
4514,
14,
272,
408,
272,
2288,
485,
885,
4455,
272,
340,
440,
485,
885,
4455,
26,
267,
485,
885,
4455,
275,
3814,
4455,
342,
272,
372,
485,
885,
4455,
199,
199,
4947,
6613,
63,
6305,
275,
378,
259,
327,
8498,
1536,
1182,
12842,
402,
2050,
199,
5378,
11580,
2594,
63,
568,
11265,
1206,
63,
3170,
275,
2948,
199,
5378,
11580,
2594,
63,
568,
11265,
1206,
63,
2826,
63,
21054,
275,
14313,
199,
5378,
11580,
2594,
63,
568,
11265,
1206,
63,
9740,
275,
9013,
199,
5378,
11580,
2594,
63,
568,
11265,
1206,
63,
9740,
63,
25081,
51,
275,
413,
2905,
199,
199,
5378,
11580,
2594,
63,
1877,
13160,
1206,
63,
3170,
275,
1926,
199,
5378,
11580,
2594,
63,
1877,
13160,
1206,
63,
2826,
63,
21054,
275,
1784,
199,
5378,
11580,
2594,
63,
1877,
13160,
1206,
63,
3170,
63,
10486,
275,
19328,
199,
5378,
11580,
2594,
63,
1877,
13160,
1206,
63,
9740,
275,
32730,
199,
5378,
11580,
2594,
63,
1877,
13160,
1206,
63,
9740,
63,
22584,
275,
499,
2905,
199,
5378,
11580,
2594,
63,
1877,
13160,
1206,
63,
9740,
63,
14999,
1149,
275,
499,
2576,
199,
5378,
11580,
2594,
63,
1877,
13160,
1206,
63,
9740,
63,
25081,
51,
275,
499,
2534,
199,
5378,
11580,
2594,
63,
1877,
13160,
1206,
63,
9740,
63,
10486,
63,
25081,
51,
275,
499,
2720,
199,
199,
13060,
63,
12711,
63,
25081,
51,
275,
650,
1020,
199,
13060,
63,
12711,
63,
3170,
275,
9601,
199,
199,
3279,
8670,
63,
11365,
63,
568,
11265,
1206,
275,
22291,
199,
3279,
8670,
63,
9901,
63,
14657,
275,
8806,
24,
199,
3279,
8670,
63,
9901,
63,
6178,
14657,
275,
8806,
23,
199,
3279,
8670,
63,
9901,
63,
51,
15219,
3170,
275,
27151,
257,
199,
199,
14999,
1206,
63,
8272,
63,
48,
32032,
275,
1695,
1020,
199,
199,
14999,
1206,
63,
8723,
63,
23612,
1149,
275,
1520,
1020,
199,
14999,
1206,
63,
8723,
63,
23612,
1149,
63,
6588,
53,
28292,
275,
1520,
2905,
199,
14999,
1206,
63,
8723,
63,
23612,
1149,
63,
6903,
40,
3234,
1149,
275,
1520,
2576,
199,
14999,
1206,
63,
8723,
63,
23612,
1149,
63,
3170,
275,
30071,
199,
199,
4227,
22320,
63,
23483,
63,
9481,
748,
35,
1293,
6989,
275,
1227,
1020,
199,
4227,
22320,
63,
8272,
63,
48,
32032,
275,
1227,
2905,
199,
4227,
22320,
63,
8272,
63,
36,
1092,
7701,
1149,
275,
1227,
614,
199,
4227,
22320,
63,
15976,
63,
3170,
275,
1227,
996,
199,
199,
6885,
7622,
199,
6885,
59,
16,
61,
275,
359,
4947,
6613,
63,
6305,
12,
11293,
11580,
2594,
63,
568,
11265,
1206,
63,
3170,
12,
11293,
11580,
2594,
63,
1877,
13160,
1206,
63,
3170,
61,
199,
6885,
59,
17,
61,
275,
359,
5378,
11580,
2594,
63,
568,
11265,
1206,
63,
2826,
63,
21054,
12,
11293,
11580,
2594,
63,
1877,
13160,
1206,
63,
2826,
63,
21054,
12,
13873,
22320,
63,
8272,
63,
36,
1092,
7701,
1149,
61,
199,
6885,
59,
17,
1055,
2880,
8,
6885,
59,
16,
566,
199,
6885,
59,
18,
61,
275,
359,
14999,
1206,
63,
8723,
63,
23612,
1149,
12,
13873,
22320,
63,
23483,
63,
9481,
748,
35,
1293,
6989,
12,
8098,
63,
12711,
63,
25081,
51,
61,
199,
6885,
59,
18,
1055,
2880,
8,
6885,
59,
17,
566,
199,
6885,
59,
19,
61,
275,
359,
4227,
22320,
63,
8272,
63,
48,
32032,
61,
199,
6885,
59,
19,
1055,
2880,
8,
6885,
59,
18,
566,
199,
6885,
59,
20,
61,
275,
942,
199,
6885,
59,
20,
1055,
2880,
8,
6885,
59,
19,
566,
199,
6885,
59,
21,
61,
275,
942,
327,
14287,
2127,
446,
440,
1202,
1362,
199,
533,
3814,
4455,
26,
272,
408,
272,
2900,
3788,
787,
11960,
711,
1915,
543,
282,
4913,
436,
1004,
336,
572,
5313,
370,
282,
943,
570,
14,
2286,
2654,
296,
1183,
12,
642,
1021,
5171,
2050,
1901,
22112,
30242,
7999,
14,
2286,
768,
7725,
485,
12804,
26,
10944,
370,
314,
570,
1256,
272,
768,
466,
485,
12804,
26,
445,
91,
1173,
93,
272,
768,
7725,
485,
1896,
26,
5297,
2166,
370,
506,
1202,
367,
314,
1256,
334,
4037,
315,
1101,
570,
9,
272,
768,
466,
485,
1896,
26,
445,
91,
442,
93,
272,
408,
2286,
347,
636,
826,
721,
277,
304,
267,
408,
267,
3232,
314,
943,
570,
14,
2728,
16280,
282,
943,
1245,
315,
314,
943,
570,
367,
11665,
7969,
1536,
314,
486,
20,
795,
943,
2435,
14,
267,
408,
267,
492,
1101,
267,
687,
1101,
492,
3412,
22790,
63,
15440,
12,
3412,
22790,
63,
11817,
12,
27926,
63,
13326,
4947,
12,
10046,
51,
4947,
63,
22698,
4960,
291,
423,
12804,
275,
1551,
8,
27896,
63,
15440,
12,
283,
65,
358,
267,
291,
423,
1896,
275,
3412,
22790,
63,
11817,
2728,
291,
423,
16878,
3314,
275,
27926,
63,
13326,
4947,
2728,
340,
27926,
63,
13326,
4947,
26,
288,
22112,
14,
1490,
793,
8,
13326,
4947,
63,
22698,
9,
2728,
291,
14,
1222,
2209,
8,
4947,
6613,
63,
6305,
12,
283,
39,
20,
3177,
19928,
8239,
334,
1896,
450,
68,
3171,
2818,
277,
423,
1896,
430,
339,
347,
6876,
944,
8,
277,
304,
267,
408,
267,
5244,
6159,
2050,
14,
2728,
16280,
282,
943,
1245,
315,
314,
943,
570,
367,
11261,
3224,
486,
20,
795,
2050,
436,
3753,
4002,
314,
943,
570,
14,
267,
408,
267,
291,
14,
1222,
2209,
8,
4947,
6613,
63,
6305,
12,
283,
39,
20,
3177,
19928,
24761,
3224,
358,
267,
291,
423,
12804,
14,
1600,
342,
2728,
340,
291,
423,
16878,
3314,
26,
288,
22112,
14,
1600,
793,
342,
5493,
347,
892,
2209,
8,
277,
12,
4637,
12,
1245,
304,
267,
408,
267,
7053,
2397,
367,
314,
943,
2656,
14,
2728,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ar45/django
|
tests/postgres_tests/migrations/0002_create_test_models.py
|
231
|
8070
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from ..fields import * # NOQA
class Migration(migrations.Migration):
dependencies = [
('postgres_tests', '0001_setup_extensions'),
]
operations = [
migrations.CreateModel(
name='CharArrayModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', ArrayField(models.CharField(max_length=10), size=None)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='DateTimeArrayModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('datetimes', ArrayField(models.DateTimeField(), size=None)),
('dates', ArrayField(models.DateField(), size=None)),
('times', ArrayField(models.TimeField(), size=None)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='HStoreModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', HStoreField(blank=True, null=True)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='OtherTypesArrayModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('ips', ArrayField(models.GenericIPAddressField(), size=None)),
('uuids', ArrayField(models.UUIDField(), size=None)),
('decimals', ArrayField(models.DecimalField(max_digits=5, decimal_places=2), size=None)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='IntegerArrayModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', ArrayField(models.IntegerField(), size=None)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='NestedIntegerArrayModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', ArrayField(ArrayField(models.IntegerField(), size=None), size=None)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='NullableIntegerArrayModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', ArrayField(models.IntegerField(), size=None, null=True, blank=True)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='CharFieldModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', models.CharField(max_length=16)),
],
options=None,
bases=None,
),
migrations.CreateModel(
name='TextFieldModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', models.TextField()),
],
options=None,
bases=None,
),
migrations.CreateModel(
name='AggregateTestModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('boolean_field', models.NullBooleanField()),
('char_field', models.CharField(max_length=30, blank=True)),
('integer_field', models.IntegerField(null=True)),
]
),
migrations.CreateModel(
name='StatTestModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('int1', models.IntegerField()),
('int2', models.IntegerField()),
('related_field', models.ForeignKey(
'postgres_tests.AggregateTestModel',
models.SET_NULL,
null=True,
)),
]
),
migrations.CreateModel(
name='NowTestModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('when', models.DateTimeField(null=True, default=None)),
]
),
]
pg_92_operations = [
migrations.CreateModel(
name='RangesModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('ints', IntegerRangeField(null=True, blank=True)),
('bigints', BigIntegerRangeField(null=True, blank=True)),
('floats', FloatRangeField(null=True, blank=True)),
('timestamps', DateTimeRangeField(null=True, blank=True)),
('dates', DateRangeField(null=True, blank=True)),
],
options={
'required_db_vendor': 'postgresql'
},
bases=(models.Model,)
),
migrations.CreateModel(
name='RangeLookupsModel',
fields=[
('parent', models.ForeignKey(
'postgres_tests.RangesModel',
models.SET_NULL,
blank=True, null=True,
)),
('integer', models.IntegerField(blank=True, null=True)),
('big_integer', models.BigIntegerField(blank=True, null=True)),
('float', models.FloatField(blank=True, null=True)),
('timestamp', models.DateTimeField(blank=True, null=True)),
('date', models.DateField(blank=True, null=True)),
],
options={
'required_db_vendor': 'postgresql',
},
bases=(models.Model,),
),
]
pg_94_operations = [
migrations.CreateModel(
name='JSONModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('field', JSONField(null=True, blank=True)),
],
options={
},
bases=(models.Model,),
),
]
def apply(self, project_state, schema_editor, collect_sql=False):
try:
PG_VERSION = schema_editor.connection.pg_version
except AttributeError:
pass # We are probably not on PostgreSQL
else:
if PG_VERSION >= 90200:
self.operations = self.operations + self.pg_92_operations
if PG_VERSION >= 90400:
self.operations = self.operations + self.pg_94_operations
return super(Migration, self).apply(project_state, schema_editor, collect_sql)
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
199,
504,
2508,
955,
492,
627,
221,
327,
20432,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
10675,
63,
2219,
297,
283,
4183,
63,
2758,
63,
5359,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
1610,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
8725,
792,
8,
992,
14,
2183,
8,
988,
63,
1267,
29,
709,
395,
1568,
29,
403,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
3926,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
31601,
297,
8725,
792,
8,
992,
14,
4626,
1062,
1568,
29,
403,
1826,
355,
661,
9356,
297,
8725,
792,
8,
992,
14,
14071,
1062,
1568,
29,
403,
1826,
355,
661,
4508,
297,
8725,
792,
8,
992,
14,
27115,
1062,
1568,
29,
403,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
40,
5502,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
869,
5502,
792,
8,
2500,
29,
549,
12,
2973,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
8632,
4100,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
6142,
297,
8725,
792,
8,
992,
14,
9417,
26969,
1062,
1568,
29,
403,
1826,
355,
661,
18401,
297,
8725,
792,
8,
992,
14,
8757,
792,
1062,
1568,
29,
403,
1826,
355,
661,
6355,
83,
297,
8725,
792,
8,
992,
14,
15975,
8,
988,
63,
7022,
29,
21,
12,
6107,
63,
10696,
29,
18,
395,
1568,
29,
403,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
2674,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
8725,
792,
8,
992,
14,
3901,
1062,
1568,
29,
403,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
13029,
2674,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
8725,
792,
8,
3836,
792,
8,
992,
14,
3901,
1062,
1568,
29,
403,
395,
1568,
29,
403,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
8849,
461,
2674,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
8725,
792,
8,
992,
14,
3901,
1062,
1568,
29,
403,
12,
2973,
29,
549,
12,
4596,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
2183,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
975,
1826,
288,
2156,
288,
1511,
29,
403,
12,
288,
9768,
29,
403,
12,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
6254,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
1709,
14,
6254,
4000,
288,
2156,
288,
1511,
29,
403,
12,
288,
9768,
29,
403,
12,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
10170,
18282,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
4871,
63,
698,
297,
1709,
14,
29068,
4000,
355,
661,
1560,
63,
698,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1216,
12,
4596,
29,
549,
1826,
355,
661,
4115,
63,
698,
297,
1709,
14,
3901,
8,
2307,
29,
549,
1826,
288,
1622,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
11232,
18282,
297,
288,
1504,
1524,
355
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
199,
504,
2508,
955,
492,
627,
221,
327,
20432,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
10675,
63,
2219,
297,
283,
4183,
63,
2758,
63,
5359,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
1610,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
8725,
792,
8,
992,
14,
2183,
8,
988,
63,
1267,
29,
709,
395,
1568,
29,
403,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
3926,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
31601,
297,
8725,
792,
8,
992,
14,
4626,
1062,
1568,
29,
403,
1826,
355,
661,
9356,
297,
8725,
792,
8,
992,
14,
14071,
1062,
1568,
29,
403,
1826,
355,
661,
4508,
297,
8725,
792,
8,
992,
14,
27115,
1062,
1568,
29,
403,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
40,
5502,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
869,
5502,
792,
8,
2500,
29,
549,
12,
2973,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
8632,
4100,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
6142,
297,
8725,
792,
8,
992,
14,
9417,
26969,
1062,
1568,
29,
403,
1826,
355,
661,
18401,
297,
8725,
792,
8,
992,
14,
8757,
792,
1062,
1568,
29,
403,
1826,
355,
661,
6355,
83,
297,
8725,
792,
8,
992,
14,
15975,
8,
988,
63,
7022,
29,
21,
12,
6107,
63,
10696,
29,
18,
395,
1568,
29,
403,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
2674,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
8725,
792,
8,
992,
14,
3901,
1062,
1568,
29,
403,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
13029,
2674,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
8725,
792,
8,
3836,
792,
8,
992,
14,
3901,
1062,
1568,
29,
403,
395,
1568,
29,
403,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
8849,
461,
2674,
3836,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
8725,
792,
8,
992,
14,
3901,
1062,
1568,
29,
403,
12,
2973,
29,
549,
12,
4596,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
2427,
63,
697,
63,
9884,
356,
283,
15437,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
2183,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
975,
1826,
288,
2156,
288,
1511,
29,
403,
12,
288,
9768,
29,
403,
12,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
6254,
1685,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
698,
297,
1709,
14,
6254,
4000,
288,
2156,
288,
1511,
29,
403,
12,
288,
9768,
29,
403,
12,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
10170,
18282,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
4871,
63,
698,
297,
1709,
14,
29068,
4000,
355,
661,
1560,
63,
698,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1216,
12,
4596,
29,
549,
1826,
355,
661,
4115,
63,
698,
297,
1709,
14,
3901,
8,
2307,
29,
549,
1826,
288,
1622,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
11232,
18282,
297,
288,
1504,
1524,
355,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
eugena/seantis-questionnaire
|
questionnaire/tests.py
|
9
|
8149
|
"""
Basic Test Suite for Questionnaire Application
Unfortunately Django 1.0 only has TestCase and not TransactionTestCase
so we can't test that a submitted page with an error does not have any
answers submitted to the DB.
"""
from django.test import TestCase
from django.test.client import Client
from questionnaire.models import *
from datetime import datetime
import os
class TypeTest(TestCase):
fixtures = ( 'testQuestions.yaml', )
urls = 'questionnaire.test_urls'
def setUp(self):
self.ansdict1 = {
'questionset_id' : '1',
'question_1' : 'Open Answer 1',
'question_2' : 'Open Answer 2\r\nMultiline',
'question_3' : 'yes',
'question_4' : 'dontknow',
'question_5' : 'yes',
'question_5_comment' : 'this comment is required because of required-yes check',
'question_6' : 'no',
'question_6_comment' : 'this comment is required because of required-no check',
'question_7' : '5',
'question_8_unit' : 'week',
'question_8' : '2',
}
self.ansdict2 = {
'questionset_id' : '2',
'question_9' : 'q9_choice1', # choice
'question_10' : '_entry_', # choice-freeform
'question_10_comment' : 'my freeform',
'question_11_multiple_2' : 'q11_choice2', # choice-multiple
'question_11_multiple_4' : 'q11_choice4', # choice-multiple
'question_12_multiple_1' : 'q12_choice1',# choice-multiple-freeform
'question_12_more_1' : 'blah', # choice-multiple-freeform
}
runinfo = self.runinfo = RunInfo.objects.get(runid='test:test')
self.runid = runinfo.runid
self.subject_id = runinfo.subject_id
def test010_redirect(self):
"Check redirection from generic questionnaire to questionset"
response = self.client.get('/q/test:test/')
self.assertEqual(response['Location'], 'http://testserver/q/test:test/1/')
def test020_get_questionset_1(self):
"Get first page of Questions"
response = self.client.get('/q/test:test/1/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.template[0].name, 'questionnaire/questionset.html')
def test030_language_setting(self):
"Set the language and confirm it is set in DB"
response = self.client.get('/q/test:test/1/', {"lang" : "en"})
self.assertEqual(response.status_code, 302)
self.assertEqual(response['Location'], 'http://testserver/q/test:test/1/')
response = self.client.get('/q/test:test/1/')
assert "Don't Know" in response.content
self.assertEqual(response.status_code, 200)
runinfo = RunInfo.objects.get(runid='test:test')
self.assertEqual(runinfo.subject.language, 'en')
response = self.client.get('/q/test:test/1/', {"lang" : "de"})
self.assertEqual(response.status_code, 302)
self.assertEqual(response['Location'], 'http://testserver/q/test:test/1/')
response = self.client.get('/q/test:test/1/')
assert "Weiss nicht" in response.content
self.assertEqual(response.status_code, 200)
runinfo = RunInfo.objects.get(runid='test:test')
self.assertEqual(runinfo.subject.language, 'de')
def test040_missing_question(self):
"Post questions with a mandatory field missing"
c = self.client
ansdict = self.ansdict1.copy()
del ansdict['question_3']
response = c.post('/q/test:test/1/', ansdict)
self.assertEqual(response.status_code, 200)
errors = response.context[-1]['errors']
self.assertEqual(len(errors), 1) and errors.has_key('3')
def test050_missing_question(self):
"Post questions with a mandatory field missing"
c = self.client
ansdict = self.ansdict1.copy()
del ansdict['question_5_comment']
# first set language to english
response = self.client.get('/q/test:test/1/', {"lang" : "en"})
response = c.post('/q/test:test/1/', ansdict)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context[-1]['errors']), 1)
def test060_successful_questionnaire(self):
"POST complete answers for QuestionSet 1"
c = self.client
ansdict1 = self.ansdict1
runinfo = RunInfo.objects.get(runid='test:test')
runid = runinfo.random = runinfo.runid = '1real'
runinfo.save()
response = c.get('/q/1real/1/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.template[0].name, 'questionnaire/questionset.html')
response = c.post('/q/1real/', ansdict1)
self.assertEqual(response.status_code, 302)
self.assertEqual(response['Location'], 'http://testserver/q/1real/2/')
"POST complete answers for QuestionSet 2"
c = self.client
ansdict2 = self.ansdict2
response = c.get('/q/1real/2/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.template[0].name, 'questionnaire/questionset.html')
response = c.post('/q/1real/', ansdict2)
self.assertEqual(response.status_code, 302)
self.assertEqual(response['Location'], 'http://testserver/')
self.assertEqual(RunInfo.objects.filter(runid='1real').count(), 0)
# TODO: The format of these answers seems very strange to me. It was
# simpler before I changed it to get the test to work.
# I'll have to revisit this once I figure out how this is meant to work
# for now it is more important to me that all tests pass
dbvalues = {
'1' : u'["%s"]' % ansdict1['question_1'],
'2' : u'["%s"]' % ansdict1['question_2'],
'3' : u'["%s"]' % ansdict1['question_3'],
'4' : u'["%s"]' % ansdict1['question_4'],
'5' : u'["%s", ["%s"]]' % (ansdict1['question_5'], ansdict1['question_5_comment']),
'6' : u'["%s", ["%s"]]' % (ansdict1['question_6'], ansdict1['question_6_comment']),
'7' : u'[%s]' % ansdict1['question_7'],
'8' : u'%s; %s' % (ansdict1['question_8'], ansdict1['question_8_unit']),
'9' : u'["q9_choice1"]',
'10' : u'[["my freeform"]]',
'11' : u'["q11_choice2", "q11_choice4"]',
'12' : u'["q12_choice1", ["blah"]]',
}
for k, v in dbvalues.items():
ans = Answer.objects.get(runid=runid, subject__id=self.subject_id,
question__number=k)
v = v.replace('\r', '\\r').replace('\n', '\\n')
self.assertEqual(ans.answer, v)
def test070_tags(self):
c = self.client
# the first questionset in questionnaire 2 is always shown,
# but one of its 2 questions is tagged with testtag
with_tags = c.get('/q/test:withtags/1/')
# so we'll get two questions shown if the run is tagged
self.assertEqual(with_tags.status_code, 200)
self.assertEqual(len(with_tags.context['qlist']), 2)
# one question, if the run is not tagged
without_tags = c.get('/q/test:withouttags/1/')
self.assertEqual(without_tags.status_code, 200)
self.assertEqual(len(without_tags.context['qlist']), 1)
# the second questionset is only shown if the run is tagged
with_tags = c.get('/q/test:withtags/2/')
self.assertEqual(with_tags.status_code, 200)
self.assertEqual(len(with_tags.context['qlist']), 1)
# meaning it'll be skipped on the untagged run
without_tags = c.get('/q/test.withouttags/2/')
self.assertEqual(without_tags.status_code, 302) # redirect
# the progress values of the first questionset should reflect
# the fact that in one run there's only one questionset
with_tags = c.get('/q/test:withtags/1/')
without_tags = c.get('/q/test:withouttags/1/')
self.assertEqual(with_tags.context['progress'], 50)
self.assertEqual(without_tags.context['progress'], 100)
|
bsd-3-clause
|
[
624,
199,
6845,
1379,
14453,
367,
21421,
3540,
3621,
13515,
199,
199,
1358,
21839,
5634,
413,
14,
16,
1454,
965,
7640,
436,
440,
18244,
1746,
199,
1152,
781,
883,
1133,
511,
626,
282,
16930,
2034,
543,
376,
1125,
1630,
440,
1172,
1263,
199,
13379,
16930,
370,
314,
6249,
14,
199,
624,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1258,
492,
6810,
199,
504,
7894,
3540,
3621,
14,
992,
492,
627,
199,
504,
2197,
492,
2197,
199,
646,
747,
199,
199,
533,
2434,
774,
8,
1746,
304,
272,
15188,
275,
334,
283,
396,
16778,
83,
14,
5963,
297,
776,
272,
8187,
275,
283,
4790,
3540,
3621,
14,
396,
63,
3603,
7,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
796,
807,
17,
275,
469,
288,
283,
4790,
409,
63,
344,
7,
520,
283,
17,
297,
288,
283,
4790,
63,
17,
7,
520,
283,
4299,
30675,
413,
297,
288,
283,
4790,
63,
18,
7,
520,
283,
4299,
30675,
499,
60,
82,
60,
78,
18933,
297,
288,
283,
4790,
63,
19,
7,
520,
283,
5066,
297,
288,
283,
4790,
63,
20,
7,
520,
283,
18671,
14996,
297,
288,
283,
4790,
63,
21,
7,
520,
283,
5066,
297,
288,
283,
4790,
63,
21,
63,
3349,
7,
520,
283,
3749,
3721,
365,
1415,
2952,
402,
1415,
13,
5066,
1104,
297,
288,
283,
4790,
63,
22,
7,
520,
283,
889,
297,
288,
283,
4790,
63,
22,
63,
3349,
7,
520,
283,
3749,
3721,
365,
1415,
2952,
402,
1415,
13,
889,
1104,
297,
288,
283,
4790,
63,
23,
7,
520,
283,
21,
297,
288,
283,
4790,
63,
24,
63,
3248,
7,
520,
283,
6419,
297,
288,
283,
4790,
63,
24,
7,
520,
283,
18,
297,
267,
789,
267,
291,
14,
796,
807,
18,
275,
469,
288,
283,
4790,
409,
63,
344,
7,
520,
283,
18,
297,
288,
283,
4790,
63,
25,
7,
520,
283,
81,
25,
63,
5095,
17,
297,
221,
327,
7141,
288,
283,
4790,
63,
709,
7,
520,
2513,
2373,
14474,
327,
7141,
13,
4624,
964,
288,
283,
4790,
63,
709,
63,
3349,
7,
520,
283,
1662,
2867,
964,
297,
288,
283,
4790,
63,
845,
63,
6048,
63,
18,
7,
520,
283,
81,
845,
63,
5095,
18,
297,
327,
7141,
13,
6048,
288,
283,
4790,
63,
845,
63,
6048,
63,
20,
7,
520,
283,
81,
845,
63,
5095,
20,
297,
327,
7141,
13,
6048,
288,
283,
4790,
63,
713,
63,
6048,
63,
17,
7,
520,
283,
81,
713,
63,
5095,
17,
297,
3,
7141,
13,
6048,
13,
4624,
964,
288,
283,
4790,
63,
713,
63,
6878,
63,
17,
7,
520,
283,
12702,
297,
327,
7141,
13,
6048,
13,
4624,
964,
267,
789,
267,
1255,
815,
275,
291,
14,
1065,
815,
275,
3378,
2354,
14,
1462,
14,
362,
8,
1065,
344,
534,
396,
26,
396,
358,
267,
291,
14,
1065,
344,
275,
1255,
815,
14,
1065,
344,
267,
291,
14,
5875,
63,
344,
275,
1255,
815,
14,
5875,
63,
344,
2378,
347,
511,
9523,
63,
4876,
8,
277,
304,
267,
298,
1799,
23713,
687,
7809,
7894,
3540,
3621,
370,
7894,
409,
2,
267,
1177,
275,
291,
14,
1258,
14,
362,
2336,
81,
15,
396,
26,
396,
6217,
267,
291,
14,
629,
8,
1310,
459,
6592,
995,
283,
1014,
921,
22471,
15,
81,
15,
396,
26,
396,
15,
17,
6217,
2378,
347,
511,
10173,
63,
362,
63,
4790,
409,
63,
17,
8,
277,
304,
267,
298,
1002,
1642,
2034,
402,
21421,
83,
2,
267,
1177,
275,
291,
14,
1258,
14,
362,
2336,
81,
15,
396,
26,
396,
15,
17,
6217,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
291,
14,
629,
8,
1310,
14,
1160,
59,
16,
1055,
354,
12,
283,
4790,
3540,
3621,
15,
4790,
409,
14,
1360,
358,
2378,
347,
511,
22739,
63,
3671,
63,
6031,
8,
277,
304,
267,
298,
1084,
314,
2637,
436,
12679,
652,
365,
663,
315,
6249,
2,
267,
1177,
275,
291,
14,
1258,
14,
362,
2336,
81,
15,
396,
26,
396,
15,
17,
3678,
2420,
4159,
2,
520,
298,
287,
5984,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
11485,
9,
267,
291,
14,
629,
8,
1310,
459,
6592,
995,
283,
1014,
921,
22471,
15,
81,
15,
396,
26,
396,
15,
17,
6217,
267,
1177,
275,
291,
14,
1258,
14,
362,
2336,
81,
15,
396,
26,
396,
15,
17,
6217,
267,
702,
298,
16932,
1133,
1804,
2131,
2,
315,
1177,
14,
1317,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
1255,
815,
275,
3378,
2354,
14,
1462,
14,
362,
8,
1065,
344,
534,
396,
26,
396,
358,
267,
291,
14,
629,
8,
1065,
815,
14,
5875,
14,
3671,
12,
283,
287,
358,
267,
1177,
275,
291,
14,
1258,
14,
362,
2336,
81,
15,
396,
26,
396,
15,
17,
3678,
2420,
4159,
2,
520,
298,
271,
5984,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
11485,
9,
267,
291,
14,
629,
8,
1310,
459,
6592,
995,
283,
1014,
921,
22471,
15,
81,
15,
396,
26,
396,
15,
17,
6217,
267,
1177,
275,
291,
14,
1258,
14,
362,
2336,
81,
15,
396,
26,
396,
15,
17,
6217,
267,
702,
298,
6004,
19857,
302,
1158,
84,
2,
315,
1177,
14,
1317,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
1255,
815,
275,
3378,
2354,
14,
1462,
14,
362,
8,
1065,
344,
534,
396,
26,
396,
358,
267,
291,
14,
629,
8,
1065,
815,
14,
5875,
14,
3671,
12,
283,
271,
358,
2378,
347,
511,
11189,
63,
4752,
63,
4790,
8,
277,
304,
267,
298,
6564,
23071,
543,
282,
15230,
901,
4124,
2,
267,
286,
275,
291,
14,
1258,
267,
4987,
807,
275,
291,
14,
796,
807,
17,
14,
1574,
342,
267,
2150,
4987,
807,
459,
4790,
63,
19,
418,
267,
1177,
275,
286,
14,
1932,
2336,
81,
15,
396,
26,
396,
15,
17,
3678,
4987,
807,
9,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
2552,
275,
1177,
14,
1100,
1988,
17,
2733,
2550,
418,
267,
291,
14,
629,
8,
552,
8,
2550,
395,
413,
9,
436,
2552,
14,
1989
] |
[
199,
6845,
1379,
14453,
367,
21421,
3540,
3621,
13515,
199,
199,
1358,
21839,
5634,
413,
14,
16,
1454,
965,
7640,
436,
440,
18244,
1746,
199,
1152,
781,
883,
1133,
511,
626,
282,
16930,
2034,
543,
376,
1125,
1630,
440,
1172,
1263,
199,
13379,
16930,
370,
314,
6249,
14,
199,
624,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1258,
492,
6810,
199,
504,
7894,
3540,
3621,
14,
992,
492,
627,
199,
504,
2197,
492,
2197,
199,
646,
747,
199,
199,
533,
2434,
774,
8,
1746,
304,
272,
15188,
275,
334,
283,
396,
16778,
83,
14,
5963,
297,
776,
272,
8187,
275,
283,
4790,
3540,
3621,
14,
396,
63,
3603,
7,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
796,
807,
17,
275,
469,
288,
283,
4790,
409,
63,
344,
7,
520,
283,
17,
297,
288,
283,
4790,
63,
17,
7,
520,
283,
4299,
30675,
413,
297,
288,
283,
4790,
63,
18,
7,
520,
283,
4299,
30675,
499,
60,
82,
60,
78,
18933,
297,
288,
283,
4790,
63,
19,
7,
520,
283,
5066,
297,
288,
283,
4790,
63,
20,
7,
520,
283,
18671,
14996,
297,
288,
283,
4790,
63,
21,
7,
520,
283,
5066,
297,
288,
283,
4790,
63,
21,
63,
3349,
7,
520,
283,
3749,
3721,
365,
1415,
2952,
402,
1415,
13,
5066,
1104,
297,
288,
283,
4790,
63,
22,
7,
520,
283,
889,
297,
288,
283,
4790,
63,
22,
63,
3349,
7,
520,
283,
3749,
3721,
365,
1415,
2952,
402,
1415,
13,
889,
1104,
297,
288,
283,
4790,
63,
23,
7,
520,
283,
21,
297,
288,
283,
4790,
63,
24,
63,
3248,
7,
520,
283,
6419,
297,
288,
283,
4790,
63,
24,
7,
520,
283,
18,
297,
267,
789,
267,
291,
14,
796,
807,
18,
275,
469,
288,
283,
4790,
409,
63,
344,
7,
520,
283,
18,
297,
288,
283,
4790,
63,
25,
7,
520,
283,
81,
25,
63,
5095,
17,
297,
221,
327,
7141,
288,
283,
4790,
63,
709,
7,
520,
2513,
2373,
14474,
327,
7141,
13,
4624,
964,
288,
283,
4790,
63,
709,
63,
3349,
7,
520,
283,
1662,
2867,
964,
297,
288,
283,
4790,
63,
845,
63,
6048,
63,
18,
7,
520,
283,
81,
845,
63,
5095,
18,
297,
327,
7141,
13,
6048,
288,
283,
4790,
63,
845,
63,
6048,
63,
20,
7,
520,
283,
81,
845,
63,
5095,
20,
297,
327,
7141,
13,
6048,
288,
283,
4790,
63,
713,
63,
6048,
63,
17,
7,
520,
283,
81,
713,
63,
5095,
17,
297,
3,
7141,
13,
6048,
13,
4624,
964,
288,
283,
4790,
63,
713,
63,
6878,
63,
17,
7,
520,
283,
12702,
297,
327,
7141,
13,
6048,
13,
4624,
964,
267,
789,
267,
1255,
815,
275,
291,
14,
1065,
815,
275,
3378,
2354,
14,
1462,
14,
362,
8,
1065,
344,
534,
396,
26,
396,
358,
267,
291,
14,
1065,
344,
275,
1255,
815,
14,
1065,
344,
267,
291,
14,
5875,
63,
344,
275,
1255,
815,
14,
5875,
63,
344,
2378,
347,
511,
9523,
63,
4876,
8,
277,
304,
267,
298,
1799,
23713,
687,
7809,
7894,
3540,
3621,
370,
7894,
409,
2,
267,
1177,
275,
291,
14,
1258,
14,
362,
2336,
81,
15,
396,
26,
396,
6217,
267,
291,
14,
629,
8,
1310,
459,
6592,
995,
283,
1014,
921,
22471,
15,
81,
15,
396,
26,
396,
15,
17,
6217,
2378,
347,
511,
10173,
63,
362,
63,
4790,
409,
63,
17,
8,
277,
304,
267,
298,
1002,
1642,
2034,
402,
21421,
83,
2,
267,
1177,
275,
291,
14,
1258,
14,
362,
2336,
81,
15,
396,
26,
396,
15,
17,
6217,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
291,
14,
629,
8,
1310,
14,
1160,
59,
16,
1055,
354,
12,
283,
4790,
3540,
3621,
15,
4790,
409,
14,
1360,
358,
2378,
347,
511,
22739,
63,
3671,
63,
6031,
8,
277,
304,
267,
298,
1084,
314,
2637,
436,
12679,
652,
365,
663,
315,
6249,
2,
267,
1177,
275,
291,
14,
1258,
14,
362,
2336,
81,
15,
396,
26,
396,
15,
17,
3678,
2420,
4159,
2,
520,
298,
287,
5984,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
11485,
9,
267,
291,
14,
629,
8,
1310,
459,
6592,
995,
283,
1014,
921,
22471,
15,
81,
15,
396,
26,
396,
15,
17,
6217,
267,
1177,
275,
291,
14,
1258,
14,
362,
2336,
81,
15,
396,
26,
396,
15,
17,
6217,
267,
702,
298,
16932,
1133,
1804,
2131,
2,
315,
1177,
14,
1317,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
1255,
815,
275,
3378,
2354,
14,
1462,
14,
362,
8,
1065,
344,
534,
396,
26,
396,
358,
267,
291,
14,
629,
8,
1065,
815,
14,
5875,
14,
3671,
12,
283,
287,
358,
267,
1177,
275,
291,
14,
1258,
14,
362,
2336,
81,
15,
396,
26,
396,
15,
17,
3678,
2420,
4159,
2,
520,
298,
271,
5984,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
11485,
9,
267,
291,
14,
629,
8,
1310,
459,
6592,
995,
283,
1014,
921,
22471,
15,
81,
15,
396,
26,
396,
15,
17,
6217,
267,
1177,
275,
291,
14,
1258,
14,
362,
2336,
81,
15,
396,
26,
396,
15,
17,
6217,
267,
702,
298,
6004,
19857,
302,
1158,
84,
2,
315,
1177,
14,
1317,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
1255,
815,
275,
3378,
2354,
14,
1462,
14,
362,
8,
1065,
344,
534,
396,
26,
396,
358,
267,
291,
14,
629,
8,
1065,
815,
14,
5875,
14,
3671,
12,
283,
271,
358,
2378,
347,
511,
11189,
63,
4752,
63,
4790,
8,
277,
304,
267,
298,
6564,
23071,
543,
282,
15230,
901,
4124,
2,
267,
286,
275,
291,
14,
1258,
267,
4987,
807,
275,
291,
14,
796,
807,
17,
14,
1574,
342,
267,
2150,
4987,
807,
459,
4790,
63,
19,
418,
267,
1177,
275,
286,
14,
1932,
2336,
81,
15,
396,
26,
396,
15,
17,
3678,
4987,
807,
9,
267,
291,
14,
629,
8,
1310,
14,
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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
CVML/scikit-learn
|
sklearn/tests/test_multiclass.py
|
72
|
24581
|
import numpy as np
import scipy.sparse as sp
from sklearn.utils.testing import assert_array_equal
from sklearn.utils.testing import assert_equal
from sklearn.utils.testing import assert_almost_equal
from sklearn.utils.testing import assert_true
from sklearn.utils.testing import assert_false
from sklearn.utils.testing import assert_raises
from sklearn.utils.testing import assert_warns
from sklearn.utils.testing import ignore_warnings
from sklearn.utils.testing import assert_greater
from sklearn.multiclass import OneVsRestClassifier
from sklearn.multiclass import OneVsOneClassifier
from sklearn.multiclass import OutputCodeClassifier
from sklearn.multiclass import fit_ovr
from sklearn.multiclass import fit_ovo
from sklearn.multiclass import fit_ecoc
from sklearn.multiclass import predict_ovr
from sklearn.multiclass import predict_ovo
from sklearn.multiclass import predict_ecoc
from sklearn.multiclass import predict_proba_ovr
from sklearn.metrics import precision_score
from sklearn.metrics import recall_score
from sklearn.preprocessing import LabelBinarizer
from sklearn.svm import LinearSVC, SVC
from sklearn.naive_bayes import MultinomialNB
from sklearn.linear_model import (LinearRegression, Lasso, ElasticNet, Ridge,
Perceptron, LogisticRegression)
from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor
from sklearn.grid_search import GridSearchCV
from sklearn.pipeline import Pipeline
from sklearn import svm
from sklearn import datasets
from sklearn.externals.six.moves import zip
iris = datasets.load_iris()
rng = np.random.RandomState(0)
perm = rng.permutation(iris.target.size)
iris.data = iris.data[perm]
iris.target = iris.target[perm]
n_classes = 3
def test_ovr_exceptions():
ovr = OneVsRestClassifier(LinearSVC(random_state=0))
assert_raises(ValueError, ovr.predict, [])
with ignore_warnings():
assert_raises(ValueError, predict_ovr, [LinearSVC(), MultinomialNB()],
LabelBinarizer(), [])
# Fail on multioutput data
assert_raises(ValueError, OneVsRestClassifier(MultinomialNB()).fit,
np.array([[1, 0], [0, 1]]),
np.array([[1, 2], [3, 1]]))
assert_raises(ValueError, OneVsRestClassifier(MultinomialNB()).fit,
np.array([[1, 0], [0, 1]]),
np.array([[1.5, 2.4], [3.1, 0.8]]))
def test_ovr_fit_predict():
# A classifier which implements decision_function.
ovr = OneVsRestClassifier(LinearSVC(random_state=0))
pred = ovr.fit(iris.data, iris.target).predict(iris.data)
assert_equal(len(ovr.estimators_), n_classes)
clf = LinearSVC(random_state=0)
pred2 = clf.fit(iris.data, iris.target).predict(iris.data)
assert_equal(np.mean(iris.target == pred), np.mean(iris.target == pred2))
# A classifier which implements predict_proba.
ovr = OneVsRestClassifier(MultinomialNB())
pred = ovr.fit(iris.data, iris.target).predict(iris.data)
assert_greater(np.mean(iris.target == pred), 0.65)
def test_ovr_ovo_regressor():
# test that ovr and ovo work on regressors which don't have a decision_function
ovr = OneVsRestClassifier(DecisionTreeRegressor())
pred = ovr.fit(iris.data, iris.target).predict(iris.data)
assert_equal(len(ovr.estimators_), n_classes)
assert_array_equal(np.unique(pred), [0, 1, 2])
# we are doing something sensible
assert_greater(np.mean(pred == iris.target), .9)
ovr = OneVsOneClassifier(DecisionTreeRegressor())
pred = ovr.fit(iris.data, iris.target).predict(iris.data)
assert_equal(len(ovr.estimators_), n_classes * (n_classes - 1) / 2)
assert_array_equal(np.unique(pred), [0, 1, 2])
# we are doing something sensible
assert_greater(np.mean(pred == iris.target), .9)
def test_ovr_fit_predict_sparse():
for sparse in [sp.csr_matrix, sp.csc_matrix, sp.coo_matrix, sp.dok_matrix,
sp.lil_matrix]:
base_clf = MultinomialNB(alpha=1)
X, Y = datasets.make_multilabel_classification(n_samples=100,
n_features=20,
n_classes=5,
n_labels=3,
length=50,
allow_unlabeled=True,
return_indicator=True,
random_state=0)
X_train, Y_train = X[:80], Y[:80]
X_test = X[80:]
clf = OneVsRestClassifier(base_clf).fit(X_train, Y_train)
Y_pred = clf.predict(X_test)
clf_sprs = OneVsRestClassifier(base_clf).fit(X_train, sparse(Y_train))
Y_pred_sprs = clf_sprs.predict(X_test)
assert_true(clf.multilabel_)
assert_true(sp.issparse(Y_pred_sprs))
assert_array_equal(Y_pred_sprs.toarray(), Y_pred)
# Test predict_proba
Y_proba = clf_sprs.predict_proba(X_test)
# predict assigns a label if the probability that the
# sample has the label is greater than 0.5.
pred = Y_proba > .5
assert_array_equal(pred, Y_pred_sprs.toarray())
# Test decision_function
clf_sprs = OneVsRestClassifier(svm.SVC()).fit(X_train, sparse(Y_train))
dec_pred = (clf_sprs.decision_function(X_test) > 0).astype(int)
assert_array_equal(dec_pred, clf_sprs.predict(X_test).toarray())
def test_ovr_always_present():
# Test that ovr works with classes that are always present or absent.
# Note: tests is the case where _ConstantPredictor is utilised
X = np.ones((10, 2))
X[:5, :] = 0
# Build an indicator matrix where two features are always on.
# As list of lists, it would be: [[int(i >= 5), 2, 3] for i in range(10)]
y = np.zeros((10, 3))
y[5:, 0] = 1
y[:, 1] = 1
y[:, 2] = 1
ovr = OneVsRestClassifier(LogisticRegression())
assert_warns(UserWarning, ovr.fit, X, y)
y_pred = ovr.predict(X)
assert_array_equal(np.array(y_pred), np.array(y))
y_pred = ovr.decision_function(X)
assert_equal(np.unique(y_pred[:, -2:]), 1)
y_pred = ovr.predict_proba(X)
assert_array_equal(y_pred[:, -1], np.ones(X.shape[0]))
# y has a constantly absent label
y = np.zeros((10, 2))
y[5:, 0] = 1 # variable label
ovr = OneVsRestClassifier(LogisticRegression())
assert_warns(UserWarning, ovr.fit, X, y)
y_pred = ovr.predict_proba(X)
assert_array_equal(y_pred[:, -1], np.zeros(X.shape[0]))
def test_ovr_multiclass():
# Toy dataset where features correspond directly to labels.
X = np.array([[0, 0, 5], [0, 5, 0], [3, 0, 0], [0, 0, 6], [6, 0, 0]])
y = ["eggs", "spam", "ham", "eggs", "ham"]
Y = np.array([[0, 0, 1],
[0, 1, 0],
[1, 0, 0],
[0, 0, 1],
[1, 0, 0]])
classes = set("ham eggs spam".split())
for base_clf in (MultinomialNB(), LinearSVC(random_state=0),
LinearRegression(), Ridge(),
ElasticNet()):
clf = OneVsRestClassifier(base_clf).fit(X, y)
assert_equal(set(clf.classes_), classes)
y_pred = clf.predict(np.array([[0, 0, 4]]))[0]
assert_equal(set(y_pred), set("eggs"))
# test input as label indicator matrix
clf = OneVsRestClassifier(base_clf).fit(X, Y)
y_pred = clf.predict([[0, 0, 4]])[0]
assert_array_equal(y_pred, [0, 0, 1])
def test_ovr_binary():
# Toy dataset where features correspond directly to labels.
X = np.array([[0, 0, 5], [0, 5, 0], [3, 0, 0], [0, 0, 6], [6, 0, 0]])
y = ["eggs", "spam", "spam", "eggs", "spam"]
Y = np.array([[0, 1, 1, 0, 1]]).T
classes = set("eggs spam".split())
def conduct_test(base_clf, test_predict_proba=False):
clf = OneVsRestClassifier(base_clf).fit(X, y)
assert_equal(set(clf.classes_), classes)
y_pred = clf.predict(np.array([[0, 0, 4]]))[0]
assert_equal(set(y_pred), set("eggs"))
if test_predict_proba:
X_test = np.array([[0, 0, 4]])
probabilities = clf.predict_proba(X_test)
assert_equal(2, len(probabilities[0]))
assert_equal(clf.classes_[np.argmax(probabilities, axis=1)],
clf.predict(X_test))
# test input as label indicator matrix
clf = OneVsRestClassifier(base_clf).fit(X, Y)
y_pred = clf.predict([[3, 0, 0]])[0]
assert_equal(y_pred, 1)
for base_clf in (LinearSVC(random_state=0), LinearRegression(),
Ridge(), ElasticNet()):
conduct_test(base_clf)
for base_clf in (MultinomialNB(), SVC(probability=True),
LogisticRegression()):
conduct_test(base_clf, test_predict_proba=True)
@ignore_warnings
def test_ovr_multilabel():
# Toy dataset where features correspond directly to labels.
X = np.array([[0, 4, 5], [0, 5, 0], [3, 3, 3], [4, 0, 6], [6, 0, 0]])
y = [["spam", "eggs"], ["spam"], ["ham", "eggs", "spam"],
["ham", "eggs"], ["ham"]]
# y = [[1, 2], [1], [0, 1, 2], [0, 2], [0]]
Y = np.array([[0, 1, 1],
[0, 1, 0],
[1, 1, 1],
[1, 0, 1],
[1, 0, 0]])
classes = set("ham eggs spam".split())
for base_clf in (MultinomialNB(), LinearSVC(random_state=0),
LinearRegression(), Ridge(),
ElasticNet(), Lasso(alpha=0.5)):
# test input as lists of tuples
clf = assert_warns(DeprecationWarning,
OneVsRestClassifier(base_clf).fit,
X, y)
assert_equal(set(clf.classes_), classes)
y_pred = clf.predict([[0, 4, 4]])[0]
assert_equal(set(y_pred), set(["spam", "eggs"]))
assert_true(clf.multilabel_)
# test input as label indicator matrix
clf = OneVsRestClassifier(base_clf).fit(X, Y)
y_pred = clf.predict([[0, 4, 4]])[0]
assert_array_equal(y_pred, [0, 1, 1])
assert_true(clf.multilabel_)
def test_ovr_fit_predict_svc():
ovr = OneVsRestClassifier(svm.SVC())
ovr.fit(iris.data, iris.target)
assert_equal(len(ovr.estimators_), 3)
assert_greater(ovr.score(iris.data, iris.target), .9)
def test_ovr_multilabel_dataset():
base_clf = MultinomialNB(alpha=1)
for au, prec, recall in zip((True, False), (0.51, 0.66), (0.51, 0.80)):
X, Y = datasets.make_multilabel_classification(n_samples=100,
n_features=20,
n_classes=5,
n_labels=2,
length=50,
allow_unlabeled=au,
return_indicator=True,
random_state=0)
X_train, Y_train = X[:80], Y[:80]
X_test, Y_test = X[80:], Y[80:]
clf = OneVsRestClassifier(base_clf).fit(X_train, Y_train)
Y_pred = clf.predict(X_test)
assert_true(clf.multilabel_)
assert_almost_equal(precision_score(Y_test, Y_pred, average="micro"),
prec,
decimal=2)
assert_almost_equal(recall_score(Y_test, Y_pred, average="micro"),
recall,
decimal=2)
def test_ovr_multilabel_predict_proba():
base_clf = MultinomialNB(alpha=1)
for au in (False, True):
X, Y = datasets.make_multilabel_classification(n_samples=100,
n_features=20,
n_classes=5,
n_labels=3,
length=50,
allow_unlabeled=au,
return_indicator=True,
random_state=0)
X_train, Y_train = X[:80], Y[:80]
X_test = X[80:]
clf = OneVsRestClassifier(base_clf).fit(X_train, Y_train)
# decision function only estimator. Fails in current implementation.
decision_only = OneVsRestClassifier(svm.SVR()).fit(X_train, Y_train)
assert_raises(AttributeError, decision_only.predict_proba, X_test)
# Estimator with predict_proba disabled, depending on parameters.
decision_only = OneVsRestClassifier(svm.SVC(probability=False))
decision_only.fit(X_train, Y_train)
assert_raises(AttributeError, decision_only.predict_proba, X_test)
Y_pred = clf.predict(X_test)
Y_proba = clf.predict_proba(X_test)
# predict assigns a label if the probability that the
# sample has the label is greater than 0.5.
pred = Y_proba > .5
assert_array_equal(pred, Y_pred)
def test_ovr_single_label_predict_proba():
base_clf = MultinomialNB(alpha=1)
X, Y = iris.data, iris.target
X_train, Y_train = X[:80], Y[:80]
X_test = X[80:]
clf = OneVsRestClassifier(base_clf).fit(X_train, Y_train)
# decision function only estimator. Fails in current implementation.
decision_only = OneVsRestClassifier(svm.SVR()).fit(X_train, Y_train)
assert_raises(AttributeError, decision_only.predict_proba, X_test)
Y_pred = clf.predict(X_test)
Y_proba = clf.predict_proba(X_test)
assert_almost_equal(Y_proba.sum(axis=1), 1.0)
# predict assigns a label if the probability that the
# sample has the label is greater than 0.5.
pred = np.array([l.argmax() for l in Y_proba])
assert_false((pred - Y_pred).any())
def test_ovr_multilabel_decision_function():
X, Y = datasets.make_multilabel_classification(n_samples=100,
n_features=20,
n_classes=5,
n_labels=3,
length=50,
allow_unlabeled=True,
return_indicator=True,
random_state=0)
X_train, Y_train = X[:80], Y[:80]
X_test = X[80:]
clf = OneVsRestClassifier(svm.SVC()).fit(X_train, Y_train)
assert_array_equal((clf.decision_function(X_test) > 0).astype(int),
clf.predict(X_test))
def test_ovr_single_label_decision_function():
X, Y = datasets.make_classification(n_samples=100,
n_features=20,
random_state=0)
X_train, Y_train = X[:80], Y[:80]
X_test = X[80:]
clf = OneVsRestClassifier(svm.SVC()).fit(X_train, Y_train)
assert_array_equal(clf.decision_function(X_test).ravel() > 0,
clf.predict(X_test))
def test_ovr_gridsearch():
ovr = OneVsRestClassifier(LinearSVC(random_state=0))
Cs = [0.1, 0.5, 0.8]
cv = GridSearchCV(ovr, {'estimator__C': Cs})
cv.fit(iris.data, iris.target)
best_C = cv.best_estimator_.estimators_[0].C
assert_true(best_C in Cs)
def test_ovr_pipeline():
# Test with pipeline of length one
# This test is needed because the multiclass estimators may fail to detect
# the presence of predict_proba or decision_function.
clf = Pipeline([("tree", DecisionTreeClassifier())])
ovr_pipe = OneVsRestClassifier(clf)
ovr_pipe.fit(iris.data, iris.target)
ovr = OneVsRestClassifier(DecisionTreeClassifier())
ovr.fit(iris.data, iris.target)
assert_array_equal(ovr.predict(iris.data), ovr_pipe.predict(iris.data))
def test_ovr_coef_():
for base_classifier in [SVC(kernel='linear', random_state=0), LinearSVC(random_state=0)]:
# SVC has sparse coef with sparse input data
ovr = OneVsRestClassifier(base_classifier)
for X in [iris.data, sp.csr_matrix(iris.data)]:
# test with dense and sparse coef
ovr.fit(X, iris.target)
shape = ovr.coef_.shape
assert_equal(shape[0], n_classes)
assert_equal(shape[1], iris.data.shape[1])
# don't densify sparse coefficients
assert_equal(sp.issparse(ovr.estimators_[0].coef_), sp.issparse(ovr.coef_))
def test_ovr_coef_exceptions():
# Not fitted exception!
ovr = OneVsRestClassifier(LinearSVC(random_state=0))
# lambda is needed because we don't want coef_ to be evaluated right away
assert_raises(ValueError, lambda x: ovr.coef_, None)
# Doesn't have coef_ exception!
ovr = OneVsRestClassifier(DecisionTreeClassifier())
ovr.fit(iris.data, iris.target)
assert_raises(AttributeError, lambda x: ovr.coef_, None)
def test_ovo_exceptions():
ovo = OneVsOneClassifier(LinearSVC(random_state=0))
assert_raises(ValueError, ovo.predict, [])
def test_ovo_fit_on_list():
# Test that OneVsOne fitting works with a list of targets and yields the
# same output as predict from an array
ovo = OneVsOneClassifier(LinearSVC(random_state=0))
prediction_from_array = ovo.fit(iris.data, iris.target).predict(iris.data)
prediction_from_list = ovo.fit(iris.data,
list(iris.target)).predict(iris.data)
assert_array_equal(prediction_from_array, prediction_from_list)
def test_ovo_fit_predict():
# A classifier which implements decision_function.
ovo = OneVsOneClassifier(LinearSVC(random_state=0))
ovo.fit(iris.data, iris.target).predict(iris.data)
assert_equal(len(ovo.estimators_), n_classes * (n_classes - 1) / 2)
# A classifier which implements predict_proba.
ovo = OneVsOneClassifier(MultinomialNB())
ovo.fit(iris.data, iris.target).predict(iris.data)
assert_equal(len(ovo.estimators_), n_classes * (n_classes - 1) / 2)
def test_ovo_decision_function():
n_samples = iris.data.shape[0]
ovo_clf = OneVsOneClassifier(LinearSVC(random_state=0))
ovo_clf.fit(iris.data, iris.target)
decisions = ovo_clf.decision_function(iris.data)
assert_equal(decisions.shape, (n_samples, n_classes))
assert_array_equal(decisions.argmax(axis=1), ovo_clf.predict(iris.data))
# Compute the votes
votes = np.zeros((n_samples, n_classes))
k = 0
for i in range(n_classes):
for j in range(i + 1, n_classes):
pred = ovo_clf.estimators_[k].predict(iris.data)
votes[pred == 0, i] += 1
votes[pred == 1, j] += 1
k += 1
# Extract votes and verify
assert_array_equal(votes, np.round(decisions))
for class_idx in range(n_classes):
# For each sample and each class, there only 3 possible vote levels
# because they are only 3 distinct class pairs thus 3 distinct
# binary classifiers.
# Therefore, sorting predictions based on votes would yield
# mostly tied predictions:
assert_true(set(votes[:, class_idx]).issubset(set([0., 1., 2.])))
# The OVO decision function on the other hand is able to resolve
# most of the ties on this data as it combines both the vote counts
# and the aggregated confidence levels of the binary classifiers
# to compute the aggregate decision function. The iris dataset
# has 150 samples with a couple of duplicates. The OvO decisions
# can resolve most of the ties:
assert_greater(len(np.unique(decisions[:, class_idx])), 146)
def test_ovo_gridsearch():
ovo = OneVsOneClassifier(LinearSVC(random_state=0))
Cs = [0.1, 0.5, 0.8]
cv = GridSearchCV(ovo, {'estimator__C': Cs})
cv.fit(iris.data, iris.target)
best_C = cv.best_estimator_.estimators_[0].C
assert_true(best_C in Cs)
def test_ovo_ties():
# Test that ties are broken using the decision function,
# not defaulting to the smallest label
X = np.array([[1, 2], [2, 1], [-2, 1], [-2, -1]])
y = np.array([2, 0, 1, 2])
multi_clf = OneVsOneClassifier(Perceptron(shuffle=False))
ovo_prediction = multi_clf.fit(X, y).predict(X)
ovo_decision = multi_clf.decision_function(X)
# Classifiers are in order 0-1, 0-2, 1-2
# Use decision_function to compute the votes and the normalized
# sum_of_confidences, which is used to disambiguate when there is a tie in
# votes.
votes = np.round(ovo_decision)
normalized_confidences = ovo_decision - votes
# For the first point, there is one vote per class
assert_array_equal(votes[0, :], 1)
# For the rest, there is no tie and the prediction is the argmax
assert_array_equal(np.argmax(votes[1:], axis=1), ovo_prediction[1:])
# For the tie, the prediction is the class with the highest score
assert_equal(ovo_prediction[0], normalized_confidences[0].argmax())
def test_ovo_ties2():
# test that ties can not only be won by the first two labels
X = np.array([[1, 2], [2, 1], [-2, 1], [-2, -1]])
y_ref = np.array([2, 0, 1, 2])
# cycle through labels so that each label wins once
for i in range(3):
y = (y_ref + i) % 3
multi_clf = OneVsOneClassifier(Perceptron(shuffle=False))
ovo_prediction = multi_clf.fit(X, y).predict(X)
assert_equal(ovo_prediction[0], i % 3)
def test_ovo_string_y():
# Test that the OvO doesn't mess up the encoding of string labels
X = np.eye(4)
y = np.array(['a', 'b', 'c', 'd'])
ovo = OneVsOneClassifier(LinearSVC())
ovo.fit(X, y)
assert_array_equal(y, ovo.predict(X))
def test_ecoc_exceptions():
ecoc = OutputCodeClassifier(LinearSVC(random_state=0))
assert_raises(ValueError, ecoc.predict, [])
def test_ecoc_fit_predict():
# A classifier which implements decision_function.
ecoc = OutputCodeClassifier(LinearSVC(random_state=0),
code_size=2, random_state=0)
ecoc.fit(iris.data, iris.target).predict(iris.data)
assert_equal(len(ecoc.estimators_), n_classes * 2)
# A classifier which implements predict_proba.
ecoc = OutputCodeClassifier(MultinomialNB(), code_size=2, random_state=0)
ecoc.fit(iris.data, iris.target).predict(iris.data)
assert_equal(len(ecoc.estimators_), n_classes * 2)
def test_ecoc_gridsearch():
ecoc = OutputCodeClassifier(LinearSVC(random_state=0),
random_state=0)
Cs = [0.1, 0.5, 0.8]
cv = GridSearchCV(ecoc, {'estimator__C': Cs})
cv.fit(iris.data, iris.target)
best_C = cv.best_estimator_.estimators_[0].C
assert_true(best_C in Cs)
@ignore_warnings
def test_deprecated():
base_estimator = DecisionTreeClassifier(random_state=0)
X, Y = iris.data, iris.target
X_train, Y_train = X[:80], Y[:80]
X_test = X[80:]
all_metas = [
(OneVsRestClassifier, fit_ovr, predict_ovr, predict_proba_ovr),
(OneVsOneClassifier, fit_ovo, predict_ovo, None),
(OutputCodeClassifier, fit_ecoc, predict_ecoc, None),
]
for MetaEst, fit_func, predict_func, proba_func in all_metas:
try:
meta_est = MetaEst(base_estimator,
random_state=0).fit(X_train, Y_train)
fitted_return = fit_func(base_estimator, X_train, Y_train,
random_state=0)
except TypeError:
meta_est = MetaEst(base_estimator).fit(X_train, Y_train)
fitted_return = fit_func(base_estimator, X_train, Y_train)
if len(fitted_return) == 2:
estimators_, classes_or_lb = fitted_return
assert_almost_equal(predict_func(estimators_, classes_or_lb,
X_test),
meta_est.predict(X_test))
if proba_func is not None:
assert_almost_equal(proba_func(estimators_, X_test,
is_multilabel=False),
meta_est.predict_proba(X_test))
else:
estimators_, classes_or_lb, codebook = fitted_return
assert_almost_equal(predict_func(estimators_, classes_or_lb,
codebook, X_test),
meta_est.predict(X_test))
|
bsd-3-clause
|
[
646,
2680,
465,
980,
199,
646,
7026,
14,
4421,
465,
2249,
199,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
4398,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2052,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3910,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3536,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
19811,
199,
504,
6357,
14,
1208,
14,
4776,
492,
3686,
63,
5451,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
13154,
199,
504,
6357,
14,
30016,
492,
7309,
20343,
13726,
8508,
199,
504,
6357,
14,
30016,
492,
7309,
20343,
4395,
8508,
199,
504,
6357,
14,
30016,
492,
7242,
3034,
8508,
199,
199,
504,
6357,
14,
30016,
492,
5542,
63,
8822,
82,
199,
504,
6357,
14,
30016,
492,
5542,
63,
31445,
199,
504,
6357,
14,
30016,
492,
5542,
63,
69,
331,
67,
199,
504,
6357,
14,
30016,
492,
12610,
63,
8822,
82,
199,
504,
6357,
14,
30016,
492,
12610,
63,
31445,
199,
504,
6357,
14,
30016,
492,
12610,
63,
69,
331,
67,
199,
504,
6357,
14,
30016,
492,
12610,
63,
14417,
63,
8822,
82,
199,
199,
504,
6357,
14,
6759,
492,
7151,
63,
3397,
199,
504,
6357,
14,
6759,
492,
26174,
63,
3397,
199,
199,
504,
6357,
14,
21402,
492,
10354,
13394,
31008,
199,
199,
504,
6357,
14,
16820,
492,
12489,
17675,
12,
428,
9454,
199,
504,
6357,
14,
21578,
63,
19558,
397,
492,
603,
427,
16956,
16170,
199,
504,
6357,
14,
6676,
63,
1238,
492,
334,
10608,
13013,
12,
29029,
12,
19509,
2480,
12,
31196,
12,
3303,
3492,
301,
4695,
265,
12,
27903,
9,
199,
504,
6357,
14,
2350,
492,
1487,
24116,
8508,
12,
1487,
24116,
15155,
199,
504,
6357,
14,
3825,
63,
1733,
492,
32570,
199,
504,
6357,
14,
7379,
492,
19090,
199,
504,
6357,
492,
23044,
199,
504,
6357,
492,
13148,
199,
504,
6357,
14,
24688,
14,
4174,
14,
4912,
492,
3482,
199,
199,
11885,
275,
13148,
14,
912,
63,
11885,
342,
199,
12686,
275,
980,
14,
2355,
14,
15726,
8,
16,
9,
199,
8220,
275,
9038,
14,
23832,
8,
11885,
14,
1375,
14,
890,
9,
199,
11885,
14,
576,
275,
12192,
14,
576,
59,
8220,
61,
199,
11885,
14,
1375,
275,
12192,
14,
1375,
59,
8220,
61,
199,
78,
63,
2888,
275,
650,
421,
199,
318,
511,
63,
8822,
82,
63,
3924,
837,
272,
312,
10922,
275,
7309,
20343,
13726,
8508,
8,
10608,
17675,
8,
2355,
63,
929,
29,
16,
430,
272,
702,
63,
3536,
8,
3393,
12,
312,
10922,
14,
6892,
12,
3073,
339,
543,
3686,
63,
5451,
837,
267,
702,
63,
3536,
8,
3393,
12,
12610,
63,
8822,
82,
12,
359,
10608,
17675,
1062,
603,
427,
16956,
16170,
15618,
1993,
10354,
13394,
31008,
1062,
3073,
339,
327,
12176,
641,
3510,
1199,
666,
272,
702,
63,
3536,
8,
3393,
12,
7309,
20343,
13726,
8508,
8,
30233,
16956,
16170,
8801,
3269,
12,
2116,
980,
14,
1144,
4038,
17,
12,
378,
467,
359,
16,
12,
413,
13925,
2116,
980,
14,
1144,
4038,
17,
12,
499,
467,
359,
19,
12,
413,
17723,
272,
702,
63,
3536,
8,
3393,
12,
7309,
20343,
13726,
8508,
8,
30233,
16956,
16170,
8801,
3269,
12,
2116,
980,
14,
1144,
4038,
17,
12,
378,
467,
359,
16,
12,
413,
13925,
2116,
980,
14,
1144,
4038,
17,
14,
21,
12,
499,
14,
20,
467,
359,
19,
14,
17,
12,
378,
14,
24,
17723,
421,
199,
318,
511,
63,
8822,
82,
63,
3269,
63,
6892,
837,
272,
327,
437,
12429,
1314,
9031,
14692,
63,
1593,
14,
272,
312,
10922,
275,
7309,
20343,
13726,
8508,
8,
10608,
17675,
8,
2355,
63,
929,
29,
16,
430,
272,
8869,
275,
312,
10922,
14,
3269,
8,
11885,
14,
576,
12,
12192,
14,
1375,
680,
6892,
8,
11885,
14,
576,
9,
272,
702,
63,
1452,
8,
552,
8,
8822,
82,
14,
10646,
29425,
302,
63,
2888,
9,
339,
6975,
275,
12489,
17675,
8,
2355,
63,
929,
29,
16,
9,
272,
8869,
18,
275,
6975,
14,
3269,
8,
11885,
14,
576,
12,
12192,
14,
1375,
680,
6892,
8,
11885,
14,
576,
9,
272,
702,
63,
1452,
8,
1590,
14,
3670,
8,
11885,
14,
1375,
508,
8869,
395,
980,
14,
3670,
8,
11885,
14,
1375,
508,
8869,
18,
430,
339,
327,
437,
12429,
1314,
9031,
12610,
63,
14417,
14,
272,
312,
10922,
275,
7309,
20343,
13726,
8508,
8,
30233,
16956,
16170,
1012,
272,
8869,
275,
312,
10922,
14,
3269,
8,
11885,
14,
576,
12,
12192,
14,
1375,
680,
6892,
8,
11885,
14,
576,
9,
272,
702,
63,
13154,
8,
1590,
14,
3670,
8,
11885,
14,
1375,
508,
8869,
395,
378,
14,
2182,
9,
421,
199,
318,
511,
63,
8822,
82,
63,
31445,
63,
1135,
11686,
837,
272,
327,
511,
626,
312,
10922,
436,
312,
2392,
1736,
641,
1295,
753,
1384,
1314,
2793,
1133,
1172,
282,
14692,
63,
1593,
272,
312,
10922,
275,
7309,
20343,
13726,
8508,
8,
872,
24116,
15155,
1012,
272,
8869,
275,
312,
10922,
14,
3269,
8,
11885,
14,
576,
12,
12192,
14,
1375,
680,
6892,
8,
11885,
14,
576,
9,
272,
702,
63,
1452,
8,
552,
8,
8822,
82,
14,
10646,
29425,
302,
63,
2888,
9,
272,
702,
63,
1144,
63,
1452,
8,
1590,
14,
3235,
8,
5991,
395,
359,
16,
12,
413,
12,
499,
566,
272,
327,
781,
787,
9689,
6020,
27962,
272,
702,
63,
13154,
8,
1590,
14,
3670,
8,
5991,
508,
12192,
14,
1375,
395,
1275,
25,
9,
339,
312,
10922,
275,
7309,
20343,
4395,
8508,
8,
872,
24116,
15155,
1012,
272,
8869,
275,
312,
10922,
14,
3269,
8,
11885,
14,
576,
12,
12192,
14,
1375,
680,
6892,
8,
11885,
14,
576,
9,
272,
702,
63,
1452,
8,
552,
8,
8822,
82,
14,
10646,
29425,
302,
63,
2888,
627,
334,
78,
63,
2888,
446,
413,
9,
1182,
499,
9,
272,
702,
63,
1144,
63,
1452,
8,
1590,
14,
3235,
8,
5991,
395,
359,
16,
12,
413,
12,
499,
566,
272,
327,
781,
787,
9689,
6020,
27962,
272,
702,
63,
13154,
8,
1590,
14,
3670,
8,
5991,
508,
12192
] |
[
2680,
465,
980,
199,
646,
7026,
14,
4421,
465,
2249,
199,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
4398,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2052,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3910,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3536,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
19811,
199,
504,
6357,
14,
1208,
14,
4776,
492,
3686,
63,
5451,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
13154,
199,
504,
6357,
14,
30016,
492,
7309,
20343,
13726,
8508,
199,
504,
6357,
14,
30016,
492,
7309,
20343,
4395,
8508,
199,
504,
6357,
14,
30016,
492,
7242,
3034,
8508,
199,
199,
504,
6357,
14,
30016,
492,
5542,
63,
8822,
82,
199,
504,
6357,
14,
30016,
492,
5542,
63,
31445,
199,
504,
6357,
14,
30016,
492,
5542,
63,
69,
331,
67,
199,
504,
6357,
14,
30016,
492,
12610,
63,
8822,
82,
199,
504,
6357,
14,
30016,
492,
12610,
63,
31445,
199,
504,
6357,
14,
30016,
492,
12610,
63,
69,
331,
67,
199,
504,
6357,
14,
30016,
492,
12610,
63,
14417,
63,
8822,
82,
199,
199,
504,
6357,
14,
6759,
492,
7151,
63,
3397,
199,
504,
6357,
14,
6759,
492,
26174,
63,
3397,
199,
199,
504,
6357,
14,
21402,
492,
10354,
13394,
31008,
199,
199,
504,
6357,
14,
16820,
492,
12489,
17675,
12,
428,
9454,
199,
504,
6357,
14,
21578,
63,
19558,
397,
492,
603,
427,
16956,
16170,
199,
504,
6357,
14,
6676,
63,
1238,
492,
334,
10608,
13013,
12,
29029,
12,
19509,
2480,
12,
31196,
12,
3303,
3492,
301,
4695,
265,
12,
27903,
9,
199,
504,
6357,
14,
2350,
492,
1487,
24116,
8508,
12,
1487,
24116,
15155,
199,
504,
6357,
14,
3825,
63,
1733,
492,
32570,
199,
504,
6357,
14,
7379,
492,
19090,
199,
504,
6357,
492,
23044,
199,
504,
6357,
492,
13148,
199,
504,
6357,
14,
24688,
14,
4174,
14,
4912,
492,
3482,
199,
199,
11885,
275,
13148,
14,
912,
63,
11885,
342,
199,
12686,
275,
980,
14,
2355,
14,
15726,
8,
16,
9,
199,
8220,
275,
9038,
14,
23832,
8,
11885,
14,
1375,
14,
890,
9,
199,
11885,
14,
576,
275,
12192,
14,
576,
59,
8220,
61,
199,
11885,
14,
1375,
275,
12192,
14,
1375,
59,
8220,
61,
199,
78,
63,
2888,
275,
650,
421,
199,
318,
511,
63,
8822,
82,
63,
3924,
837,
272,
312,
10922,
275,
7309,
20343,
13726,
8508,
8,
10608,
17675,
8,
2355,
63,
929,
29,
16,
430,
272,
702,
63,
3536,
8,
3393,
12,
312,
10922,
14,
6892,
12,
3073,
339,
543,
3686,
63,
5451,
837,
267,
702,
63,
3536,
8,
3393,
12,
12610,
63,
8822,
82,
12,
359,
10608,
17675,
1062,
603,
427,
16956,
16170,
15618,
1993,
10354,
13394,
31008,
1062,
3073,
339,
327,
12176,
641,
3510,
1199,
666,
272,
702,
63,
3536,
8,
3393,
12,
7309,
20343,
13726,
8508,
8,
30233,
16956,
16170,
8801,
3269,
12,
2116,
980,
14,
1144,
4038,
17,
12,
378,
467,
359,
16,
12,
413,
13925,
2116,
980,
14,
1144,
4038,
17,
12,
499,
467,
359,
19,
12,
413,
17723,
272,
702,
63,
3536,
8,
3393,
12,
7309,
20343,
13726,
8508,
8,
30233,
16956,
16170,
8801,
3269,
12,
2116,
980,
14,
1144,
4038,
17,
12,
378,
467,
359,
16,
12,
413,
13925,
2116,
980,
14,
1144,
4038,
17,
14,
21,
12,
499,
14,
20,
467,
359,
19,
14,
17,
12,
378,
14,
24,
17723,
421,
199,
318,
511,
63,
8822,
82,
63,
3269,
63,
6892,
837,
272,
327,
437,
12429,
1314,
9031,
14692,
63,
1593,
14,
272,
312,
10922,
275,
7309,
20343,
13726,
8508,
8,
10608,
17675,
8,
2355,
63,
929,
29,
16,
430,
272,
8869,
275,
312,
10922,
14,
3269,
8,
11885,
14,
576,
12,
12192,
14,
1375,
680,
6892,
8,
11885,
14,
576,
9,
272,
702,
63,
1452,
8,
552,
8,
8822,
82,
14,
10646,
29425,
302,
63,
2888,
9,
339,
6975,
275,
12489,
17675,
8,
2355,
63,
929,
29,
16,
9,
272,
8869,
18,
275,
6975,
14,
3269,
8,
11885,
14,
576,
12,
12192,
14,
1375,
680,
6892,
8,
11885,
14,
576,
9,
272,
702,
63,
1452,
8,
1590,
14,
3670,
8,
11885,
14,
1375,
508,
8869,
395,
980,
14,
3670,
8,
11885,
14,
1375,
508,
8869,
18,
430,
339,
327,
437,
12429,
1314,
9031,
12610,
63,
14417,
14,
272,
312,
10922,
275,
7309,
20343,
13726,
8508,
8,
30233,
16956,
16170,
1012,
272,
8869,
275,
312,
10922,
14,
3269,
8,
11885,
14,
576,
12,
12192,
14,
1375,
680,
6892,
8,
11885,
14,
576,
9,
272,
702,
63,
13154,
8,
1590,
14,
3670,
8,
11885,
14,
1375,
508,
8869,
395,
378,
14,
2182,
9,
421,
199,
318,
511,
63,
8822,
82,
63,
31445,
63,
1135,
11686,
837,
272,
327,
511,
626,
312,
10922,
436,
312,
2392,
1736,
641,
1295,
753,
1384,
1314,
2793,
1133,
1172,
282,
14692,
63,
1593,
272,
312,
10922,
275,
7309,
20343,
13726,
8508,
8,
872,
24116,
15155,
1012,
272,
8869,
275,
312,
10922,
14,
3269,
8,
11885,
14,
576,
12,
12192,
14,
1375,
680,
6892,
8,
11885,
14,
576,
9,
272,
702,
63,
1452,
8,
552,
8,
8822,
82,
14,
10646,
29425,
302,
63,
2888,
9,
272,
702,
63,
1144,
63,
1452,
8,
1590,
14,
3235,
8,
5991,
395,
359,
16,
12,
413,
12,
499,
566,
272,
327,
781,
787,
9689,
6020,
27962,
272,
702,
63,
13154,
8,
1590,
14,
3670,
8,
5991,
508,
12192,
14,
1375,
395,
1275,
25,
9,
339,
312,
10922,
275,
7309,
20343,
4395,
8508,
8,
872,
24116,
15155,
1012,
272,
8869,
275,
312,
10922,
14,
3269,
8,
11885,
14,
576,
12,
12192,
14,
1375,
680,
6892,
8,
11885,
14,
576,
9,
272,
702,
63,
1452,
8,
552,
8,
8822,
82,
14,
10646,
29425,
302,
63,
2888,
627,
334,
78,
63,
2888,
446,
413,
9,
1182,
499,
9,
272,
702,
63,
1144,
63,
1452,
8,
1590,
14,
3235,
8,
5991,
395,
359,
16,
12,
413,
12,
499,
566,
272,
327,
781,
787,
9689,
6020,
27962,
272,
702,
63,
13154,
8,
1590,
14,
3670,
8,
5991,
508,
12192,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
BeenzSyed/tempest
|
tempest/services/compute/xml/tenant_usages_client.py
|
1
|
1915
|
# Copyright 2013 NEC Corporation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import urllib
from lxml import etree
from tempest.common.rest_client import RestClientXML
from tempest.services.compute.xml.common import xml_to_json
class TenantUsagesClientXML(RestClientXML):
def __init__(self, config, username, password, auth_url, tenant_name=None):
super(TenantUsagesClientXML, self).__init__(config, username,
password, auth_url,
tenant_name)
self.service = self.config.compute.catalog_type
def _parse_array(self, node):
json = xml_to_json(node)
return json
def list_tenant_usages(self, params=None):
url = 'os-simple-tenant-usage'
if params:
url += '?%s' % urllib.urlencode(params)
resp, body = self.get(url, self.headers)
tenant_usage = self._parse_array(etree.fromstring(body))
return resp, tenant_usage['tenant_usage']
def get_tenant_usage(self, tenant_id, params=None):
url = 'os-simple-tenant-usage/%s' % tenant_id
if params:
url += '?%s' % urllib.urlencode(params)
resp, body = self.get(url, self.headers)
tenant_usage = self._parse_array(etree.fromstring(body))
return resp, tenant_usage
|
apache-2.0
|
[
3,
1898,
6171,
653,
4220,
11098,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
4011,
199,
199,
504,
14490,
492,
7559,
199,
199,
504,
24076,
14,
2330,
14,
3911,
63,
1258,
492,
30417,
3041,
4317,
199,
504,
24076,
14,
5950,
14,
3357,
14,
1652,
14,
2330,
492,
2748,
63,
475,
63,
1001,
421,
199,
533,
377,
287,
867,
7692,
83,
3041,
4317,
8,
13726,
3041,
4317,
304,
339,
347,
636,
826,
721,
277,
12,
1101,
12,
3434,
12,
2505,
12,
1790,
63,
633,
12,
8261,
63,
354,
29,
403,
304,
267,
1613,
8,
27807,
7692,
83,
3041,
4317,
12,
291,
2843,
826,
721,
888,
12,
3434,
12,
8105,
2505,
12,
1790,
63,
633,
12,
8105,
8261,
63,
354,
9,
267,
291,
14,
1364,
275,
291,
14,
888,
14,
3357,
14,
7959,
63,
466,
339,
347,
485,
1122,
63,
1144,
8,
277,
12,
1031,
304,
267,
2022,
275,
2748,
63,
475,
63,
1001,
8,
932,
9,
267,
372,
2022,
339,
347,
769,
63,
4647,
63,
21503,
8,
277,
12,
1862,
29,
403,
304,
267,
1166,
275,
283,
736,
13,
4129,
13,
4647,
13,
3807,
7,
267,
340,
1862,
26,
288,
1166,
847,
8720,
5,
83,
7,
450,
4011,
14,
10738,
8,
1162,
9,
398,
3085,
12,
2396,
275,
291,
14,
362,
8,
633,
12,
291,
14,
2139,
9,
267,
8261,
63,
3807,
275,
291,
423,
1122,
63,
1144,
8,
9464,
14,
13521,
8,
2030,
430,
267,
372,
3085,
12,
8261,
63,
3807,
459,
4647,
63,
3807,
418,
339,
347,
664,
63,
4647,
63,
3807,
8,
277,
12,
8261,
63,
344,
12,
1862,
29,
403,
304,
267,
1166,
275,
283,
736,
13,
4129,
13,
4647,
13,
3807,
3149,
83,
7,
450,
8261,
63,
344,
267,
340,
1862,
26,
288,
1166,
847,
8720,
5,
83,
7,
450,
4011,
14,
10738,
8,
1162,
9,
398,
3085,
12,
2396,
275,
291,
14,
362,
8,
633,
12,
291,
14,
2139,
9,
267,
8261,
63,
3807,
275,
291,
423,
1122,
63,
1144,
8,
9464,
14,
13521,
8,
2030,
430,
267,
372,
3085,
12,
8261,
63,
3807,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
653,
4220,
11098,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
4011,
199,
199,
504,
14490,
492,
7559,
199,
199,
504,
24076,
14,
2330,
14,
3911,
63,
1258,
492,
30417,
3041,
4317,
199,
504,
24076,
14,
5950,
14,
3357,
14,
1652,
14,
2330,
492,
2748,
63,
475,
63,
1001,
421,
199,
533,
377,
287,
867,
7692,
83,
3041,
4317,
8,
13726,
3041,
4317,
304,
339,
347,
636,
826,
721,
277,
12,
1101,
12,
3434,
12,
2505,
12,
1790,
63,
633,
12,
8261,
63,
354,
29,
403,
304,
267,
1613,
8,
27807,
7692,
83,
3041,
4317,
12,
291,
2843,
826,
721,
888,
12,
3434,
12,
8105,
2505,
12,
1790,
63,
633,
12,
8105,
8261,
63,
354,
9,
267,
291,
14,
1364,
275,
291,
14,
888,
14,
3357,
14,
7959,
63,
466,
339,
347,
485,
1122,
63,
1144,
8,
277,
12,
1031,
304,
267,
2022,
275,
2748,
63,
475,
63,
1001,
8,
932,
9,
267,
372,
2022,
339,
347,
769,
63,
4647,
63,
21503,
8,
277,
12,
1862,
29,
403,
304,
267,
1166,
275,
283,
736,
13,
4129,
13,
4647,
13,
3807,
7,
267,
340,
1862,
26,
288,
1166,
847,
8720,
5,
83,
7,
450,
4011,
14,
10738,
8,
1162,
9,
398,
3085,
12,
2396,
275,
291,
14,
362,
8,
633,
12,
291,
14,
2139,
9,
267,
8261,
63,
3807,
275,
291,
423,
1122,
63,
1144,
8,
9464,
14,
13521,
8,
2030,
430,
267,
372,
3085,
12,
8261,
63,
3807,
459,
4647,
63,
3807,
418,
339,
347,
664,
63,
4647,
63,
3807,
8,
277,
12,
8261,
63,
344,
12,
1862,
29,
403,
304,
267,
1166,
275,
283,
736,
13,
4129,
13,
4647,
13,
3807,
3149,
83,
7,
450,
8261,
63,
344,
267,
340,
1862,
26,
288,
1166,
847,
8720,
5,
83,
7,
450,
4011,
14,
10738,
8,
1162,
9,
398,
3085,
12,
2396,
275,
291,
14,
362,
8,
633,
12,
291,
14,
2139,
9,
267,
8261,
63,
3807,
275,
291,
423,
1122,
63,
1144,
8,
9464,
14,
13521,
8,
2030,
430,
267,
372,
3085,
12,
8261,
63,
3807,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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