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
|
|---|---|---|---|---|---|---|---|---|
ahmadiga/min_edx
|
openedx/core/djangoapps/content/course_overviews/management/commands/tests/test_generate_course_overview.py
|
29
|
3228
|
# pylint: disable=missing-docstring
from django.core.management.base import CommandError
from mock import patch
from openedx.core.djangoapps.content.course_overviews.management.commands import generate_course_overview
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
class TestGenerateCourseOverview(ModuleStoreTestCase):
"""
Tests course overview management command.
"""
def setUp(self):
"""
Create courses in modulestore.
"""
super(TestGenerateCourseOverview, self).setUp()
self.course_key_1 = CourseFactory.create().id
self.course_key_2 = CourseFactory.create().id
self.command = generate_course_overview.Command()
def _assert_courses_not_in_overview(self, *courses):
"""
Assert that courses doesn't exist in the course overviews.
"""
course_keys = CourseOverview.get_all_course_keys()
for expected_course_key in courses:
self.assertNotIn(expected_course_key, course_keys)
def _assert_courses_in_overview(self, *courses):
"""
Assert courses exists in course overviews.
"""
course_keys = CourseOverview.get_all_course_keys()
for expected_course_key in courses:
self.assertIn(expected_course_key, course_keys)
def test_generate_all(self):
"""
Test that all courses in the modulestore are loaded into course overviews.
"""
# ensure that the newly created courses aren't in course overviews
self._assert_courses_not_in_overview(self.course_key_1, self.course_key_2)
self.command.handle(all=True)
# CourseOverview will be populated with all courses in the modulestore
self._assert_courses_in_overview(self.course_key_1, self.course_key_2)
def test_generate_one(self):
"""
Test that a specified course is loaded into course overviews.
"""
self._assert_courses_not_in_overview(self.course_key_1, self.course_key_2)
self.command.handle(unicode(self.course_key_1), all=False)
self._assert_courses_in_overview(self.course_key_1)
self._assert_courses_not_in_overview(self.course_key_2)
@patch('openedx.core.djangoapps.content.course_overviews.management.commands.generate_course_overview.log')
def test_invalid_key(self, mock_log):
"""
Test that invalid key errors are logged.
"""
self.command.handle('not/found', all=False)
self.assertTrue(mock_log.fatal.called)
@patch('openedx.core.djangoapps.content.course_overviews.management.commands.generate_course_overview.log')
def test_not_found_key(self, mock_log):
"""
Test keys not found are logged.
"""
self.command.handle('fake/course/id', all=False)
self.assertTrue(mock_log.exception.called)
def test_no_params(self):
"""
Test exception raised when no parameters are specified.
"""
with self.assertRaises(CommandError):
self.command.handle(all=False)
|
agpl-3.0
|
[
3,
4287,
26,
3507,
29,
4752,
13,
12485,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
14393,
199,
504,
1683,
492,
3371,
199,
504,
22709,
14,
1018,
14,
16432,
14,
1317,
14,
1972,
63,
1883,
4196,
14,
8110,
14,
4405,
492,
3550,
63,
1972,
63,
21753,
199,
504,
22709,
14,
1018,
14,
16432,
14,
1317,
14,
1972,
63,
1883,
4196,
14,
992,
492,
5531,
28077,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
17996,
1746,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
17862,
421,
199,
533,
1379,
6864,
6979,
28077,
8,
27863,
304,
272,
408,
272,
6496,
2518,
23503,
10041,
1414,
14,
272,
408,
272,
347,
3613,
8,
277,
304,
267,
408,
267,
2790,
13588,
315,
10996,
14,
267,
408,
267,
1613,
8,
774,
6864,
6979,
28077,
12,
291,
680,
5996,
342,
267,
291,
14,
1972,
63,
498,
63,
17,
275,
17862,
14,
981,
1252,
344,
267,
291,
14,
1972,
63,
498,
63,
18,
275,
17862,
14,
981,
1252,
344,
267,
291,
14,
1531,
275,
3550,
63,
1972,
63,
21753,
14,
3110,
342,
339,
347,
485,
479,
63,
11653,
63,
1397,
63,
262,
63,
21753,
8,
277,
12,
627,
11653,
304,
267,
408,
267,
10716,
626,
13588,
3181,
1133,
2187,
315,
314,
2518,
1806,
4196,
14,
267,
408,
267,
2518,
63,
1612,
275,
5531,
28077,
14,
362,
63,
452,
63,
1972,
63,
1612,
342,
267,
367,
1420,
63,
1972,
63,
498,
315,
13588,
26,
288,
291,
14,
8795,
8,
2062,
63,
1972,
63,
498,
12,
2518,
63,
1612,
9,
339,
347,
485,
479,
63,
11653,
63,
262,
63,
21753,
8,
277,
12,
627,
11653,
304,
267,
408,
267,
10716,
13588,
3495,
315,
2518,
1806,
4196,
14,
267,
408,
267,
2518,
63,
1612,
275,
5531,
28077,
14,
362,
63,
452,
63,
1972,
63,
1612,
342,
267,
367,
1420,
63,
1972,
63,
498,
315,
13588,
26,
288,
291,
14,
4080,
8,
2062,
63,
1972,
63,
498,
12,
2518,
63,
1612,
9,
339,
347,
511,
63,
4208,
63,
452,
8,
277,
304,
267,
408,
267,
1379,
626,
1006,
13588,
315,
314,
10996,
787,
6511,
1901,
2518,
1806,
4196,
14,
267,
408,
267,
327,
4868,
626,
314,
13903,
2737,
13588,
10621,
1133,
315,
2518,
1806,
4196,
267,
291,
423,
479,
63,
11653,
63,
1397,
63,
262,
63,
21753,
8,
277,
14,
1972,
63,
498,
63,
17,
12,
291,
14,
1972,
63,
498,
63,
18,
9,
267,
291,
14,
1531,
14,
2479,
8,
452,
29,
549,
9,
398,
327,
5531,
28077,
911,
506,
16460,
543,
1006,
13588,
315,
314,
10996,
267,
291,
423,
479,
63,
11653,
63,
262,
63,
21753,
8,
277,
14,
1972,
63,
498,
63,
17,
12,
291,
14,
1972,
63,
498,
63,
18,
9,
339,
347,
511,
63,
4208,
63,
368,
8,
277,
304,
267,
408,
267,
1379,
626,
282,
2013,
2518,
365,
6511,
1901,
2518,
1806,
4196,
14,
267,
408,
267,
291,
423,
479,
63,
11653,
63,
1397,
63,
262,
63,
21753,
8,
277,
14,
1972,
63,
498,
63,
17,
12,
291,
14,
1972,
63,
498,
63,
18,
9,
267,
291,
14,
1531,
14,
2479,
8,
2975,
8,
277,
14,
1972,
63,
498,
63,
17,
395,
1006,
29,
797,
9,
267,
291,
423,
479,
63,
11653,
63,
262,
63,
21753,
8,
277,
14,
1972,
63,
498,
63,
17,
9,
267,
291,
423,
479,
63,
11653,
63,
1397,
63,
262,
63,
21753,
8,
277,
14,
1972,
63,
498,
63,
18,
9,
339,
768,
2068,
360,
1490,
8268,
14,
1018,
14,
16432,
14,
1317,
14,
1972,
63,
1883,
4196,
14,
8110,
14,
4405,
14,
4208,
63,
1972,
63,
21753,
14,
793,
358,
272,
347,
511,
63,
3197,
63,
498,
8,
277,
12,
1683,
63,
793,
304,
267,
408,
267,
1379,
626,
3866,
790,
2552,
787,
10367,
14,
267,
408,
267,
291,
14,
1531,
14,
2479,
360,
1397,
15,
4214,
297,
1006,
29,
797,
9,
267,
291,
14,
1815,
8,
1805,
63,
793,
14,
16208,
14,
3527,
9,
339,
768,
2068,
360,
1490,
8268,
14,
1018,
14,
16432,
14,
1317,
14,
1972,
63,
1883,
4196,
14,
8110,
14,
4405,
14,
4208,
63,
1972,
63,
21753,
14,
793,
358,
272,
347,
511,
63,
1397,
63,
4214,
63,
498,
8,
277,
12,
1683,
63,
793,
304,
267,
408,
267,
1379,
2883,
440,
1911,
787,
10367,
14,
267,
408,
267,
291,
14,
1531,
14,
2479,
360,
3183,
15,
1972,
15,
344,
297,
1006,
29,
797,
9,
267,
291,
14,
1815,
8,
1805,
63,
793,
14,
1971,
14,
3527,
9,
339,
347,
511,
63,
889,
63,
1162,
8,
277,
304,
267,
408,
267,
1379,
1919,
4915,
1380,
949,
2633,
787,
2013,
14,
267,
408,
267,
543,
291,
14,
1855,
8,
31542,
304,
288,
291,
14,
1531,
14,
2479,
8,
452,
29,
797,
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
] |
[
4287,
26,
3507,
29,
4752,
13,
12485,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
14393,
199,
504,
1683,
492,
3371,
199,
504,
22709,
14,
1018,
14,
16432,
14,
1317,
14,
1972,
63,
1883,
4196,
14,
8110,
14,
4405,
492,
3550,
63,
1972,
63,
21753,
199,
504,
22709,
14,
1018,
14,
16432,
14,
1317,
14,
1972,
63,
1883,
4196,
14,
992,
492,
5531,
28077,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
17996,
1746,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
17862,
421,
199,
533,
1379,
6864,
6979,
28077,
8,
27863,
304,
272,
408,
272,
6496,
2518,
23503,
10041,
1414,
14,
272,
408,
272,
347,
3613,
8,
277,
304,
267,
408,
267,
2790,
13588,
315,
10996,
14,
267,
408,
267,
1613,
8,
774,
6864,
6979,
28077,
12,
291,
680,
5996,
342,
267,
291,
14,
1972,
63,
498,
63,
17,
275,
17862,
14,
981,
1252,
344,
267,
291,
14,
1972,
63,
498,
63,
18,
275,
17862,
14,
981,
1252,
344,
267,
291,
14,
1531,
275,
3550,
63,
1972,
63,
21753,
14,
3110,
342,
339,
347,
485,
479,
63,
11653,
63,
1397,
63,
262,
63,
21753,
8,
277,
12,
627,
11653,
304,
267,
408,
267,
10716,
626,
13588,
3181,
1133,
2187,
315,
314,
2518,
1806,
4196,
14,
267,
408,
267,
2518,
63,
1612,
275,
5531,
28077,
14,
362,
63,
452,
63,
1972,
63,
1612,
342,
267,
367,
1420,
63,
1972,
63,
498,
315,
13588,
26,
288,
291,
14,
8795,
8,
2062,
63,
1972,
63,
498,
12,
2518,
63,
1612,
9,
339,
347,
485,
479,
63,
11653,
63,
262,
63,
21753,
8,
277,
12,
627,
11653,
304,
267,
408,
267,
10716,
13588,
3495,
315,
2518,
1806,
4196,
14,
267,
408,
267,
2518,
63,
1612,
275,
5531,
28077,
14,
362,
63,
452,
63,
1972,
63,
1612,
342,
267,
367,
1420,
63,
1972,
63,
498,
315,
13588,
26,
288,
291,
14,
4080,
8,
2062,
63,
1972,
63,
498,
12,
2518,
63,
1612,
9,
339,
347,
511,
63,
4208,
63,
452,
8,
277,
304,
267,
408,
267,
1379,
626,
1006,
13588,
315,
314,
10996,
787,
6511,
1901,
2518,
1806,
4196,
14,
267,
408,
267,
327,
4868,
626,
314,
13903,
2737,
13588,
10621,
1133,
315,
2518,
1806,
4196,
267,
291,
423,
479,
63,
11653,
63,
1397,
63,
262,
63,
21753,
8,
277,
14,
1972,
63,
498,
63,
17,
12,
291,
14,
1972,
63,
498,
63,
18,
9,
267,
291,
14,
1531,
14,
2479,
8,
452,
29,
549,
9,
398,
327,
5531,
28077,
911,
506,
16460,
543,
1006,
13588,
315,
314,
10996,
267,
291,
423,
479,
63,
11653,
63,
262,
63,
21753,
8,
277,
14,
1972,
63,
498,
63,
17,
12,
291,
14,
1972,
63,
498,
63,
18,
9,
339,
347,
511,
63,
4208,
63,
368,
8,
277,
304,
267,
408,
267,
1379,
626,
282,
2013,
2518,
365,
6511,
1901,
2518,
1806,
4196,
14,
267,
408,
267,
291,
423,
479,
63,
11653,
63,
1397,
63,
262,
63,
21753,
8,
277,
14,
1972,
63,
498,
63,
17,
12,
291,
14,
1972,
63,
498,
63,
18,
9,
267,
291,
14,
1531,
14,
2479,
8,
2975,
8,
277,
14,
1972,
63,
498,
63,
17,
395,
1006,
29,
797,
9,
267,
291,
423,
479,
63,
11653,
63,
262,
63,
21753,
8,
277,
14,
1972,
63,
498,
63,
17,
9,
267,
291,
423,
479,
63,
11653,
63,
1397,
63,
262,
63,
21753,
8,
277,
14,
1972,
63,
498,
63,
18,
9,
339,
768,
2068,
360,
1490,
8268,
14,
1018,
14,
16432,
14,
1317,
14,
1972,
63,
1883,
4196,
14,
8110,
14,
4405,
14,
4208,
63,
1972,
63,
21753,
14,
793,
358,
272,
347,
511,
63,
3197,
63,
498,
8,
277,
12,
1683,
63,
793,
304,
267,
408,
267,
1379,
626,
3866,
790,
2552,
787,
10367,
14,
267,
408,
267,
291,
14,
1531,
14,
2479,
360,
1397,
15,
4214,
297,
1006,
29,
797,
9,
267,
291,
14,
1815,
8,
1805,
63,
793,
14,
16208,
14,
3527,
9,
339,
768,
2068,
360,
1490,
8268,
14,
1018,
14,
16432,
14,
1317,
14,
1972,
63,
1883,
4196,
14,
8110,
14,
4405,
14,
4208,
63,
1972,
63,
21753,
14,
793,
358,
272,
347,
511,
63,
1397,
63,
4214,
63,
498,
8,
277,
12,
1683,
63,
793,
304,
267,
408,
267,
1379,
2883,
440,
1911,
787,
10367,
14,
267,
408,
267,
291,
14,
1531,
14,
2479,
360,
3183,
15,
1972,
15,
344,
297,
1006,
29,
797,
9,
267,
291,
14,
1815,
8,
1805,
63,
793,
14,
1971,
14,
3527,
9,
339,
347,
511,
63,
889,
63,
1162,
8,
277,
304,
267,
408,
267,
1379,
1919,
4915,
1380,
949,
2633,
787,
2013,
14,
267,
408,
267,
543,
291,
14,
1855,
8,
31542,
304,
288,
291,
14,
1531,
14,
2479,
8,
452,
29,
797,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
webmakin/scrapy
|
tests/test_crawler.py
|
127
|
5138
|
import warnings
import unittest
import scrapy
from scrapy.crawler import Crawler, CrawlerRunner, CrawlerProcess
from scrapy.settings import Settings, default_settings
from scrapy.spiderloader import SpiderLoader
from scrapy.utils.spider import DefaultSpider
from scrapy.utils.misc import load_object
from scrapy.extensions.throttle import AutoThrottle
class BaseCrawlerTest(unittest.TestCase):
def assertOptionIsDefault(self, settings, key):
self.assertIsInstance(settings, Settings)
self.assertEqual(settings[key], getattr(default_settings, key))
class CrawlerTestCase(BaseCrawlerTest):
def setUp(self):
self.crawler = Crawler(DefaultSpider, Settings())
def test_deprecated_attribute_spiders(self):
with warnings.catch_warnings(record=True) as w:
spiders = self.crawler.spiders
self.assertEqual(len(w), 1)
self.assertIn("Crawler.spiders", str(w[0].message))
sl_cls = load_object(self.crawler.settings['SPIDER_LOADER_CLASS'])
self.assertIsInstance(spiders, sl_cls)
self.crawler.spiders
self.assertEqual(len(w), 1, "Warn deprecated access only once")
def test_populate_spidercls_settings(self):
spider_settings = {'TEST1': 'spider', 'TEST2': 'spider'}
project_settings = {'TEST1': 'project', 'TEST3': 'project'}
class CustomSettingsSpider(DefaultSpider):
custom_settings = spider_settings
settings = Settings()
settings.setdict(project_settings, priority='project')
crawler = Crawler(CustomSettingsSpider, settings)
self.assertEqual(crawler.settings.get('TEST1'), 'spider')
self.assertEqual(crawler.settings.get('TEST2'), 'spider')
self.assertEqual(crawler.settings.get('TEST3'), 'project')
self.assertFalse(settings.frozen)
self.assertTrue(crawler.settings.frozen)
def test_crawler_accepts_dict(self):
crawler = Crawler(DefaultSpider, {'foo': 'bar'})
self.assertEqual(crawler.settings['foo'], 'bar')
self.assertOptionIsDefault(crawler.settings, 'RETRY_ENABLED')
def test_crawler_accepts_None(self):
crawler = Crawler(DefaultSpider)
self.assertOptionIsDefault(crawler.settings, 'RETRY_ENABLED')
class SpiderSettingsTestCase(unittest.TestCase):
def test_spider_custom_settings(self):
class MySpider(scrapy.Spider):
name = 'spider'
custom_settings = {
'AUTOTHROTTLE_ENABLED': True
}
crawler = Crawler(MySpider, {})
enabled_exts = [e.__class__ for e in crawler.extensions.middlewares]
self.assertIn(AutoThrottle, enabled_exts)
class SpiderLoaderWithWrongInterface(object):
def unneeded_method(self):
pass
class CustomSpiderLoader(SpiderLoader):
pass
class CrawlerRunnerTestCase(BaseCrawlerTest):
def test_spider_manager_verify_interface(self):
settings = Settings({
'SPIDER_LOADER_CLASS': 'tests.test_crawler.SpiderLoaderWithWrongInterface'
})
with warnings.catch_warnings(record=True) as w, \
self.assertRaises(AttributeError):
CrawlerRunner(settings)
self.assertEqual(len(w), 1)
self.assertIn("SPIDER_LOADER_CLASS", str(w[0].message))
self.assertIn("scrapy.interfaces.ISpiderLoader", str(w[0].message))
def test_crawler_runner_accepts_dict(self):
runner = CrawlerRunner({'foo': 'bar'})
self.assertEqual(runner.settings['foo'], 'bar')
self.assertOptionIsDefault(runner.settings, 'RETRY_ENABLED')
def test_crawler_runner_accepts_None(self):
runner = CrawlerRunner()
self.assertOptionIsDefault(runner.settings, 'RETRY_ENABLED')
def test_deprecated_attribute_spiders(self):
with warnings.catch_warnings(record=True) as w:
runner = CrawlerRunner(Settings())
spiders = runner.spiders
self.assertEqual(len(w), 1)
self.assertIn("CrawlerRunner.spiders", str(w[0].message))
self.assertIn("CrawlerRunner.spider_loader", str(w[0].message))
sl_cls = load_object(runner.settings['SPIDER_LOADER_CLASS'])
self.assertIsInstance(spiders, sl_cls)
def test_spidermanager_deprecation(self):
with warnings.catch_warnings(record=True) as w:
runner = CrawlerRunner({
'SPIDER_MANAGER_CLASS': 'tests.test_crawler.CustomSpiderLoader'
})
self.assertIsInstance(runner.spider_loader, CustomSpiderLoader)
self.assertEqual(len(w), 1)
self.assertIn('Please use SPIDER_LOADER_CLASS', str(w[0].message))
class CrawlerProcessTest(BaseCrawlerTest):
def test_crawler_process_accepts_dict(self):
runner = CrawlerProcess({'foo': 'bar'})
self.assertEqual(runner.settings['foo'], 'bar')
self.assertOptionIsDefault(runner.settings, 'RETRY_ENABLED')
def test_crawler_process_accepts_None(self):
runner = CrawlerProcess()
self.assertOptionIsDefault(runner.settings, 'RETRY_ENABLED')
|
bsd-3-clause
|
[
646,
3598,
199,
646,
2882,
199,
199,
646,
18918,
199,
504,
18918,
14,
23972,
492,
445,
16057,
12,
445,
16057,
7446,
12,
445,
16057,
3498,
199,
504,
18918,
14,
1751,
492,
13303,
12,
849,
63,
1751,
199,
504,
18918,
14,
12856,
3422,
492,
428,
12508,
5455,
199,
504,
18918,
14,
1208,
14,
12856,
492,
3758,
25157,
199,
504,
18918,
14,
1208,
14,
9923,
492,
2248,
63,
785,
199,
504,
18918,
14,
5359,
14,
20086,
492,
9195,
26192,
421,
199,
533,
3523,
35,
16057,
774,
8,
2796,
14,
1746,
304,
339,
347,
702,
2602,
1831,
2698,
8,
277,
12,
2202,
12,
790,
304,
267,
291,
14,
6926,
8,
1751,
12,
13303,
9,
267,
291,
14,
629,
8,
1751,
59,
498,
467,
2519,
8,
885,
63,
1751,
12,
790,
430,
421,
199,
533,
445,
16057,
1746,
8,
1563,
35,
16057,
774,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
23972,
275,
445,
16057,
8,
2698,
25157,
12,
13303,
1012,
339,
347,
511,
63,
6667,
63,
3215,
63,
8721,
7735,
8,
277,
304,
267,
543,
3598,
14,
9341,
63,
5451,
8,
3059,
29,
549,
9,
465,
336,
26,
288,
19441,
7735,
275,
291,
14,
23972,
14,
8721,
7735,
288,
291,
14,
629,
8,
552,
8,
87,
395,
413,
9,
288,
291,
14,
4080,
480,
35,
16057,
14,
8721,
7735,
401,
620,
8,
87,
59,
16,
1055,
1188,
430,
288,
5340,
63,
1886,
275,
2248,
63,
785,
8,
277,
14,
23972,
14,
1751,
459,
5763,
998,
540,
63,
7405,
540,
63,
6885,
1105,
288,
291,
14,
6926,
8,
8721,
7735,
12,
5340,
63,
1886,
9,
953,
291,
14,
23972,
14,
8721,
7735,
288,
291,
14,
629,
8,
552,
8,
87,
395,
413,
12,
298,
22673,
5906,
2879,
1454,
5403,
531,
339,
347,
511,
63,
13817,
63,
12856,
1886,
63,
1751,
8,
277,
304,
267,
18094,
63,
1751,
275,
791,
2864,
17,
356,
283,
12856,
297,
283,
2864,
18,
356,
283,
12856,
936,
267,
2199,
63,
1751,
275,
791,
2864,
17,
356,
283,
1715,
297,
283,
2864,
19,
356,
283,
1715,
936,
398,
1021,
8388,
5268,
25157,
8,
2698,
25157,
304,
288,
3537,
63,
1751,
275,
18094,
63,
1751,
398,
2202,
275,
13303,
342,
267,
2202,
14,
409,
807,
8,
1715,
63,
1751,
12,
7464,
534,
1715,
358,
267,
29550,
275,
445,
16057,
8,
7223,
5268,
25157,
12,
2202,
9,
398,
291,
14,
629,
8,
23972,
14,
1751,
14,
362,
360,
2864,
17,
659,
283,
12856,
358,
267,
291,
14,
629,
8,
23972,
14,
1751,
14,
362,
360,
2864,
18,
659,
283,
12856,
358,
267,
291,
14,
629,
8,
23972,
14,
1751,
14,
362,
360,
2864,
19,
659,
283,
1715,
358,
398,
291,
14,
3334,
8,
1751,
14,
11202,
9,
267,
291,
14,
1815,
8,
23972,
14,
1751,
14,
11202,
9,
339,
347,
511,
63,
23972,
63,
27692,
63,
807,
8,
277,
304,
267,
29550,
275,
445,
16057,
8,
2698,
25157,
12,
791,
1421,
356,
283,
1700,
3071,
267,
291,
14,
629,
8,
23972,
14,
1751,
459,
1421,
995,
283,
1700,
358,
267,
291,
14,
479,
2602,
1831,
2698,
8,
23972,
14,
1751,
12,
283,
27778,
63,
15704,
358,
339,
347,
511,
63,
23972,
63,
27692,
63,
403,
8,
277,
304,
267,
29550,
275,
445,
16057,
8,
2698,
25157,
9,
267,
291,
14,
479,
2602,
1831,
2698,
8,
23972,
14,
1751,
12,
283,
27778,
63,
15704,
358,
421,
199,
533,
428,
12508,
5268,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
12856,
63,
4229,
63,
1751,
8,
277,
304,
267,
1021,
4932,
25157,
8,
26442,
14,
25157,
304,
288,
536,
275,
283,
12856,
7,
288,
3537,
63,
1751,
275,
469,
355,
283,
10774,
22949,
1092,
1481,
906,
63,
15704,
356,
715,
288,
789,
398,
29550,
275,
445,
16057,
8,
5713,
25157,
12,
5009,
267,
5223,
63,
25752,
275,
359,
69,
855,
533,
363,
367,
325,
315,
29550,
14,
5359,
14,
14885,
758,
470,
61,
267,
291,
14,
4080,
8,
3358,
26192,
12,
5223,
63,
25752,
9,
421,
199,
533,
428,
12508,
5455,
3007,
14858,
4267,
8,
785,
304,
339,
347,
625,
11368,
63,
765,
8,
277,
304,
267,
986,
421,
199,
533,
8388,
25157,
5455,
8,
25157,
5455,
304,
272,
986,
421,
199,
533,
445,
16057,
7446,
1746,
8,
1563,
35,
16057,
774,
304,
339,
347,
511,
63,
12856,
63,
2609,
63,
4712,
63,
3266,
8,
277,
304,
267,
2202,
275,
13303,
2561,
288,
283,
5763,
998,
540,
63,
7405,
540,
63,
6885,
356,
283,
2219,
14,
396,
63,
23972,
14,
25157,
5455,
3007,
14858,
4267,
7,
267,
3828,
267,
543,
3598,
14,
9341,
63,
5451,
8,
3059,
29,
549,
9,
465,
336,
12,
971,
355,
291,
14,
1855,
8,
10227,
304,
288,
445,
16057,
7446,
8,
1751,
9,
288,
291,
14,
629,
8,
552,
8,
87,
395,
413,
9,
288,
291,
14,
4080,
480,
5763,
998,
540,
63,
7405,
540,
63,
6885,
401,
620,
8,
87,
59,
16,
1055,
1188,
430,
288,
291,
14,
4080,
480,
26442,
14,
7436,
14,
1311,
12508,
5455,
401,
620,
8,
87,
59,
16,
1055,
1188,
430,
339,
347,
511,
63,
23972,
63,
5933,
63,
27692,
63,
807,
8,
277,
304,
267,
7876,
275,
445,
16057,
7446,
3252,
1421,
356,
283,
1700,
3071,
267,
291,
14,
629,
8,
5933,
14,
1751,
459,
1421,
995,
283,
1700,
358,
267,
291,
14,
479,
2602,
1831,
2698,
8,
5933,
14,
1751,
12,
283,
27778,
63,
15704,
358,
339,
347,
511,
63,
23972,
63,
5933,
63,
27692,
63,
403,
8,
277,
304,
267,
7876,
275,
445,
16057,
7446,
342,
267,
291,
14,
479,
2602,
1831,
2698,
8,
5933,
14,
1751,
12,
283,
27778,
63,
15704,
358,
339,
347,
511,
63,
6667,
63,
3215,
63,
8721,
7735,
8,
277,
304,
267,
543,
3598,
14,
9341,
63,
5451,
8,
3059,
29,
549,
9,
465,
336,
26,
288,
7876,
275,
445,
16057,
7446,
8,
5268,
1012,
288,
19441,
7735,
275,
7876,
14,
8721,
7735,
288,
291,
14,
629,
8,
552,
8,
87,
395,
413,
9,
288,
291,
14,
4080,
480,
35,
16057,
7446,
14,
8721,
7735,
401,
620,
8,
87,
59,
16,
1055,
1188,
430,
288,
291,
14,
4080,
480,
35,
16057,
7446,
14,
12856,
63,
3422,
401,
620,
8,
87,
59,
16,
1055,
1188,
430
] |
[
3598,
199,
646,
2882,
199,
199,
646,
18918,
199,
504,
18918,
14,
23972,
492,
445,
16057,
12,
445,
16057,
7446,
12,
445,
16057,
3498,
199,
504,
18918,
14,
1751,
492,
13303,
12,
849,
63,
1751,
199,
504,
18918,
14,
12856,
3422,
492,
428,
12508,
5455,
199,
504,
18918,
14,
1208,
14,
12856,
492,
3758,
25157,
199,
504,
18918,
14,
1208,
14,
9923,
492,
2248,
63,
785,
199,
504,
18918,
14,
5359,
14,
20086,
492,
9195,
26192,
421,
199,
533,
3523,
35,
16057,
774,
8,
2796,
14,
1746,
304,
339,
347,
702,
2602,
1831,
2698,
8,
277,
12,
2202,
12,
790,
304,
267,
291,
14,
6926,
8,
1751,
12,
13303,
9,
267,
291,
14,
629,
8,
1751,
59,
498,
467,
2519,
8,
885,
63,
1751,
12,
790,
430,
421,
199,
533,
445,
16057,
1746,
8,
1563,
35,
16057,
774,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
23972,
275,
445,
16057,
8,
2698,
25157,
12,
13303,
1012,
339,
347,
511,
63,
6667,
63,
3215,
63,
8721,
7735,
8,
277,
304,
267,
543,
3598,
14,
9341,
63,
5451,
8,
3059,
29,
549,
9,
465,
336,
26,
288,
19441,
7735,
275,
291,
14,
23972,
14,
8721,
7735,
288,
291,
14,
629,
8,
552,
8,
87,
395,
413,
9,
288,
291,
14,
4080,
480,
35,
16057,
14,
8721,
7735,
401,
620,
8,
87,
59,
16,
1055,
1188,
430,
288,
5340,
63,
1886,
275,
2248,
63,
785,
8,
277,
14,
23972,
14,
1751,
459,
5763,
998,
540,
63,
7405,
540,
63,
6885,
1105,
288,
291,
14,
6926,
8,
8721,
7735,
12,
5340,
63,
1886,
9,
953,
291,
14,
23972,
14,
8721,
7735,
288,
291,
14,
629,
8,
552,
8,
87,
395,
413,
12,
298,
22673,
5906,
2879,
1454,
5403,
531,
339,
347,
511,
63,
13817,
63,
12856,
1886,
63,
1751,
8,
277,
304,
267,
18094,
63,
1751,
275,
791,
2864,
17,
356,
283,
12856,
297,
283,
2864,
18,
356,
283,
12856,
936,
267,
2199,
63,
1751,
275,
791,
2864,
17,
356,
283,
1715,
297,
283,
2864,
19,
356,
283,
1715,
936,
398,
1021,
8388,
5268,
25157,
8,
2698,
25157,
304,
288,
3537,
63,
1751,
275,
18094,
63,
1751,
398,
2202,
275,
13303,
342,
267,
2202,
14,
409,
807,
8,
1715,
63,
1751,
12,
7464,
534,
1715,
358,
267,
29550,
275,
445,
16057,
8,
7223,
5268,
25157,
12,
2202,
9,
398,
291,
14,
629,
8,
23972,
14,
1751,
14,
362,
360,
2864,
17,
659,
283,
12856,
358,
267,
291,
14,
629,
8,
23972,
14,
1751,
14,
362,
360,
2864,
18,
659,
283,
12856,
358,
267,
291,
14,
629,
8,
23972,
14,
1751,
14,
362,
360,
2864,
19,
659,
283,
1715,
358,
398,
291,
14,
3334,
8,
1751,
14,
11202,
9,
267,
291,
14,
1815,
8,
23972,
14,
1751,
14,
11202,
9,
339,
347,
511,
63,
23972,
63,
27692,
63,
807,
8,
277,
304,
267,
29550,
275,
445,
16057,
8,
2698,
25157,
12,
791,
1421,
356,
283,
1700,
3071,
267,
291,
14,
629,
8,
23972,
14,
1751,
459,
1421,
995,
283,
1700,
358,
267,
291,
14,
479,
2602,
1831,
2698,
8,
23972,
14,
1751,
12,
283,
27778,
63,
15704,
358,
339,
347,
511,
63,
23972,
63,
27692,
63,
403,
8,
277,
304,
267,
29550,
275,
445,
16057,
8,
2698,
25157,
9,
267,
291,
14,
479,
2602,
1831,
2698,
8,
23972,
14,
1751,
12,
283,
27778,
63,
15704,
358,
421,
199,
533,
428,
12508,
5268,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
12856,
63,
4229,
63,
1751,
8,
277,
304,
267,
1021,
4932,
25157,
8,
26442,
14,
25157,
304,
288,
536,
275,
283,
12856,
7,
288,
3537,
63,
1751,
275,
469,
355,
283,
10774,
22949,
1092,
1481,
906,
63,
15704,
356,
715,
288,
789,
398,
29550,
275,
445,
16057,
8,
5713,
25157,
12,
5009,
267,
5223,
63,
25752,
275,
359,
69,
855,
533,
363,
367,
325,
315,
29550,
14,
5359,
14,
14885,
758,
470,
61,
267,
291,
14,
4080,
8,
3358,
26192,
12,
5223,
63,
25752,
9,
421,
199,
533,
428,
12508,
5455,
3007,
14858,
4267,
8,
785,
304,
339,
347,
625,
11368,
63,
765,
8,
277,
304,
267,
986,
421,
199,
533,
8388,
25157,
5455,
8,
25157,
5455,
304,
272,
986,
421,
199,
533,
445,
16057,
7446,
1746,
8,
1563,
35,
16057,
774,
304,
339,
347,
511,
63,
12856,
63,
2609,
63,
4712,
63,
3266,
8,
277,
304,
267,
2202,
275,
13303,
2561,
288,
283,
5763,
998,
540,
63,
7405,
540,
63,
6885,
356,
283,
2219,
14,
396,
63,
23972,
14,
25157,
5455,
3007,
14858,
4267,
7,
267,
3828,
267,
543,
3598,
14,
9341,
63,
5451,
8,
3059,
29,
549,
9,
465,
336,
12,
971,
355,
291,
14,
1855,
8,
10227,
304,
288,
445,
16057,
7446,
8,
1751,
9,
288,
291,
14,
629,
8,
552,
8,
87,
395,
413,
9,
288,
291,
14,
4080,
480,
5763,
998,
540,
63,
7405,
540,
63,
6885,
401,
620,
8,
87,
59,
16,
1055,
1188,
430,
288,
291,
14,
4080,
480,
26442,
14,
7436,
14,
1311,
12508,
5455,
401,
620,
8,
87,
59,
16,
1055,
1188,
430,
339,
347,
511,
63,
23972,
63,
5933,
63,
27692,
63,
807,
8,
277,
304,
267,
7876,
275,
445,
16057,
7446,
3252,
1421,
356,
283,
1700,
3071,
267,
291,
14,
629,
8,
5933,
14,
1751,
459,
1421,
995,
283,
1700,
358,
267,
291,
14,
479,
2602,
1831,
2698,
8,
5933,
14,
1751,
12,
283,
27778,
63,
15704,
358,
339,
347,
511,
63,
23972,
63,
5933,
63,
27692,
63,
403,
8,
277,
304,
267,
7876,
275,
445,
16057,
7446,
342,
267,
291,
14,
479,
2602,
1831,
2698,
8,
5933,
14,
1751,
12,
283,
27778,
63,
15704,
358,
339,
347,
511,
63,
6667,
63,
3215,
63,
8721,
7735,
8,
277,
304,
267,
543,
3598,
14,
9341,
63,
5451,
8,
3059,
29,
549,
9,
465,
336,
26,
288,
7876,
275,
445,
16057,
7446,
8,
5268,
1012,
288,
19441,
7735,
275,
7876,
14,
8721,
7735,
288,
291,
14,
629,
8,
552,
8,
87,
395,
413,
9,
288,
291,
14,
4080,
480,
35,
16057,
7446,
14,
8721,
7735,
401,
620,
8,
87,
59,
16,
1055,
1188,
430,
288,
291,
14,
4080,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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
] |
babycaseny/audacity
|
lib-src/lv2/lv2/plugins/eg-metro.lv2/waflib/Tools/gxx.py
|
196
|
2806
|
#! /usr/bin/env python
# encoding: utf-8
# WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
from waflib.Tools import ccroot,ar
from waflib.Configure import conf
@conf
def find_gxx(conf):
cxx=conf.find_program(['g++','c++'],var='CXX')
cxx=conf.cmd_to_list(cxx)
conf.get_cc_version(cxx,gcc=True)
conf.env.CXX_NAME='gcc'
conf.env.CXX=cxx
@conf
def gxx_common_flags(conf):
v=conf.env
v['CXX_SRC_F']=[]
v['CXX_TGT_F']=['-c','-o']
if not v['LINK_CXX']:v['LINK_CXX']=v['CXX']
v['CXXLNK_SRC_F']=[]
v['CXXLNK_TGT_F']=['-o']
v['CPPPATH_ST']='-I%s'
v['DEFINES_ST']='-D%s'
v['LIB_ST']='-l%s'
v['LIBPATH_ST']='-L%s'
v['STLIB_ST']='-l%s'
v['STLIBPATH_ST']='-L%s'
v['RPATH_ST']='-Wl,-rpath,%s'
v['SONAME_ST']='-Wl,-h,%s'
v['SHLIB_MARKER']='-Wl,-Bdynamic'
v['STLIB_MARKER']='-Wl,-Bstatic'
v['cxxprogram_PATTERN']='%s'
v['CXXFLAGS_cxxshlib']=['-fPIC']
v['LINKFLAGS_cxxshlib']=['-shared']
v['cxxshlib_PATTERN']='lib%s.so'
v['LINKFLAGS_cxxstlib']=['-Wl,-Bstatic']
v['cxxstlib_PATTERN']='lib%s.a'
v['LINKFLAGS_MACBUNDLE']=['-bundle','-undefined','dynamic_lookup']
v['CXXFLAGS_MACBUNDLE']=['-fPIC']
v['macbundle_PATTERN']='%s.bundle'
@conf
def gxx_modifier_win32(conf):
v=conf.env
v['cxxprogram_PATTERN']='%s.exe'
v['cxxshlib_PATTERN']='%s.dll'
v['implib_PATTERN']='lib%s.dll.a'
v['IMPLIB_ST']='-Wl,--out-implib,%s'
v['CXXFLAGS_cxxshlib']=[]
v.append_value('LINKFLAGS',['-Wl,--enable-auto-import'])
@conf
def gxx_modifier_cygwin(conf):
gxx_modifier_win32(conf)
v=conf.env
v['cxxshlib_PATTERN']='cyg%s.dll'
v.append_value('LINKFLAGS_cxxshlib',['-Wl,--enable-auto-image-base'])
v['CXXFLAGS_cxxshlib']=[]
@conf
def gxx_modifier_darwin(conf):
v=conf.env
v['CXXFLAGS_cxxshlib']=['-fPIC']
v['LINKFLAGS_cxxshlib']=['-dynamiclib','-Wl,-compatibility_version,1','-Wl,-current_version,1']
v['cxxshlib_PATTERN']='lib%s.dylib'
v['FRAMEWORKPATH_ST']='-F%s'
v['FRAMEWORK_ST']=['-framework']
v['ARCH_ST']=['-arch']
v['LINKFLAGS_cxxstlib']=[]
v['SHLIB_MARKER']=[]
v['STLIB_MARKER']=[]
v['SONAME_ST']=[]
@conf
def gxx_modifier_aix(conf):
v=conf.env
v['LINKFLAGS_cxxprogram']=['-Wl,-brtl']
v['LINKFLAGS_cxxshlib']=['-shared','-Wl,-brtl,-bexpfull']
v['SHLIB_MARKER']=[]
@conf
def gxx_modifier_hpux(conf):
v=conf.env
v['SHLIB_MARKER']=[]
v['STLIB_MARKER']='-Bstatic'
v['CFLAGS_cxxshlib']=['-fPIC','-DPIC']
v['cxxshlib_PATTERN']='lib%s.sl'
@conf
def gxx_modifier_openbsd(conf):
conf.env.SONAME_ST=[]
@conf
def gxx_modifier_platform(conf):
gxx_modifier_func=getattr(conf,'gxx_modifier_'+conf.env.DEST_OS,None)
if gxx_modifier_func:
gxx_modifier_func()
def configure(conf):
conf.find_gxx()
conf.find_ar()
conf.gxx_common_flags()
conf.gxx_modifier_platform()
conf.cxx_load_tools()
conf.cxx_add_flags()
conf.link_add_flags()
|
gpl-2.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
3,
14750,
1,
4226,
440,
5283,
1,
1455,
921,
21500,
14,
31864,
14,
957,
15,
3187,
15,
4757,
15,
21500,
2706,
15,
4780,
14,
1360,
20930,
2873,
24522,
63,
1589,
63,
21500,
63,
493,
199,
199,
504,
31380,
14,
11654,
492,
7429,
1231,
12,
285,
199,
504,
31380,
14,
17324,
492,
3743,
199,
32,
2190,
199,
318,
2342,
63,
71,
2154,
8,
2190,
304,
199,
198,
9634,
29,
2190,
14,
1623,
63,
6815,
2941,
71,
4176,
1673,
67,
4176,
995,
1391,
534,
12206,
358,
199,
198,
9634,
29,
2190,
14,
1760,
63,
475,
63,
513,
8,
9634,
9,
199,
198,
2190,
14,
362,
63,
2055,
63,
1023,
8,
9634,
12,
13112,
29,
549,
9,
199,
198,
2190,
14,
1813,
14,
12206,
63,
2339,
534,
13112,
7,
199,
198,
2190,
14,
1813,
14,
12206,
29,
9634,
199,
32,
2190,
199,
318,
486,
2154,
63,
2330,
63,
2469,
8,
2190,
304,
199,
198,
86,
29,
2190,
14,
1813,
199,
198,
86,
459,
12206,
63,
12447,
63,
38,
418,
9811,
199,
198,
86,
459,
12206,
63,
26422,
63,
38,
418,
2968,
13,
67,
21810,
79,
418,
199,
198,
692,
440,
373,
459,
7916,
63,
12206,
2565,
86,
459,
7916,
63,
12206,
13784,
86,
459,
12206,
418,
199,
198,
86,
459,
12206,
44,
22780,
63,
12447,
63,
38,
418,
9811,
199,
198,
86,
459,
12206,
44,
22780,
63,
26422,
63,
38,
418,
2968,
13,
79,
418,
199,
198,
86,
459,
14533,
3243,
63,
840,
418,
18274,
41,
5,
83,
7,
199,
198,
86,
459,
27196,
63,
840,
418,
18274,
36,
5,
83,
7,
199,
198,
86,
459,
5617,
63,
840,
418,
18274,
76,
5,
83,
7,
199,
198,
86,
459,
32119,
63,
840,
418,
18274,
44,
5,
83,
7,
199,
198,
86,
459,
840,
5617,
63,
840,
418,
18274,
76,
5,
83,
7,
199,
198,
86,
459,
840,
32119,
63,
840,
418,
18274,
44,
5,
83,
7,
199,
198,
86,
459,
50,
3243,
63,
840,
418,
18274,
16239,
3057,
27841,
8719,
83,
7,
199,
198,
86,
459,
3377,
1991,
63,
840,
418,
18274,
16239,
3057,
72,
8719,
83,
7,
199,
198,
86,
459,
3234,
5617,
63,
18997,
418,
18274,
16239,
3057,
34,
7764,
7,
199,
198,
86,
459,
840,
5617,
63,
18997,
418,
18274,
16239,
3057,
34,
1986,
7,
199,
198,
86,
459,
9634,
6815,
63,
10764,
418,
9569,
83,
7,
199,
198,
86,
459,
26180,
63,
9634,
609,
773,
418,
2968,
13,
70,
26769,
418,
199,
198,
86,
459,
30388,
63,
9634,
609,
773,
418,
2968,
13,
5555,
418,
199,
198,
86,
459,
9634,
609,
773,
63,
10764,
32373,
773,
5,
83,
14,
1152,
7,
199,
198,
86,
459,
30388,
63,
9634,
270,
773,
418,
2968,
13,
16239,
3057,
34,
1986,
418,
199,
198,
86,
459,
9634,
270,
773,
63,
10764,
32373,
773,
5,
83,
14,
65,
7,
199,
198,
86,
459,
30388,
63,
9410,
32044,
906,
418,
2968,
13,
6469,
21810,
10705,
1673,
7764,
63,
3892,
418,
199,
198,
86,
459,
26180,
63,
9410,
32044,
906,
418,
2968,
13,
70,
26769,
418,
199,
198,
86,
459,
391,
2894,
4235,
63,
10764,
418,
9569,
83,
14,
6469,
7,
199,
32,
2190,
199,
318,
486,
2154,
63,
18156,
63,
2676,
708,
8,
2190,
304,
199,
198,
86,
29,
2190,
14,
1813,
199,
198,
86,
459,
9634,
6815,
63,
10764,
418,
9569,
83,
14,
5803,
7,
199,
198,
86,
459,
9634,
609,
773,
63,
10764,
418,
9569,
83,
14,
9259,
7,
199,
198,
86,
459,
3236,
773,
63,
10764,
32373,
773,
5,
83,
14,
9259,
14,
65,
7,
199,
198,
86,
459,
26312,
2100,
63,
840,
418,
18274,
16239,
28925,
548,
13,
3236,
773,
8719,
83,
7,
199,
198,
86,
459,
26180,
63,
9634,
609,
773,
418,
9811,
199,
198,
86,
14,
740,
63,
585,
360,
30388,
297,
459,
13,
16239,
28925,
4296,
13,
2495,
13,
646,
1105,
199,
32,
2190,
199,
318,
486,
2154,
63,
18156,
63,
16680,
8,
2190,
304,
199,
198,
71,
2154,
63,
18156,
63,
2676,
708,
8,
2190,
9,
199,
198,
86,
29,
2190,
14,
1813,
199,
198,
86,
459,
9634,
609,
773,
63,
10764,
32373,
15076,
5,
83,
14,
9259,
7,
199,
198,
86,
14,
740,
63,
585,
360,
30388,
63,
9634,
609,
773,
297,
459,
13,
16239,
28925,
4296,
13,
2495,
13,
1569,
13,
1095,
1105,
199,
198,
86,
459,
26180,
63,
9634,
609,
773,
418,
9811,
199,
32,
2190,
199,
318,
486,
2154,
63,
18156,
63,
13245,
8,
2190,
304,
199,
198,
86,
29,
2190,
14,
1813,
199,
198,
86,
459,
26180,
63,
9634,
609,
773,
418,
2968,
13,
70,
26769,
418,
199,
198,
86,
459,
30388,
63,
9634,
609,
773,
418,
2968,
13,
7764,
773,
21810,
16239,
3057,
15390,
63,
1023,
12,
17,
21810,
16239,
3057,
1818,
63,
1023,
12,
17,
418,
199,
198,
86,
459,
9634,
609,
773,
63,
10764,
32373,
773,
5,
83,
14,
22305,
7,
199,
198,
86,
459,
12683,
8406,
3243,
63,
840,
418,
18274,
38,
5,
83,
7,
199,
198,
86,
459,
12683,
8406,
63,
840,
418,
2968,
13,
4857,
418,
199,
198,
86,
459,
7762,
63,
840,
418,
2968,
13,
1047,
418,
199,
198,
86,
459,
30388,
63,
9634,
270,
773,
418,
9811,
199,
198,
86,
459,
3234,
5617,
63,
18997,
418,
9811,
199,
198,
86,
459,
840,
5617,
63,
18997,
418,
9811,
199,
198,
86,
459,
3377,
1991,
63,
840,
418,
9811,
199,
32,
2190,
199,
318,
486,
2154,
63,
18156,
63,
65,
1148,
8,
2190,
304,
199,
198,
86,
29,
2190,
14,
1813,
199,
198,
86,
459,
30388,
63,
9634,
6815,
418,
2968,
13,
16239,
3057,
66,
25011,
418,
199,
198,
86,
459,
30388,
63,
9634,
609,
773,
418,
2968,
13,
5555,
21810,
16239,
3057,
66,
25011,
3057,
66,
1474,
2861,
418,
199,
198,
86,
459,
3234,
5617,
63,
18997,
418,
9811,
199,
32,
2190,
199,
318,
486,
2154,
63,
18156,
63,
12025,
2521,
8,
2190,
304,
199,
198,
86,
29,
2190,
14,
1813,
199,
198,
86,
459,
3234,
5617,
63,
18997,
418,
9811,
199,
198,
86,
459,
840,
5617,
63,
18997,
418,
18274,
34,
1986,
7,
199,
198,
86,
459,
14804,
63,
9634,
609,
773
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
3,
14750,
1,
4226,
440,
5283,
1,
1455,
921,
21500,
14,
31864,
14,
957,
15,
3187,
15,
4757,
15,
21500,
2706,
15,
4780,
14,
1360,
20930,
2873,
24522,
63,
1589,
63,
21500,
63,
493,
199,
199,
504,
31380,
14,
11654,
492,
7429,
1231,
12,
285,
199,
504,
31380,
14,
17324,
492,
3743,
199,
32,
2190,
199,
318,
2342,
63,
71,
2154,
8,
2190,
304,
199,
198,
9634,
29,
2190,
14,
1623,
63,
6815,
2941,
71,
4176,
1673,
67,
4176,
995,
1391,
534,
12206,
358,
199,
198,
9634,
29,
2190,
14,
1760,
63,
475,
63,
513,
8,
9634,
9,
199,
198,
2190,
14,
362,
63,
2055,
63,
1023,
8,
9634,
12,
13112,
29,
549,
9,
199,
198,
2190,
14,
1813,
14,
12206,
63,
2339,
534,
13112,
7,
199,
198,
2190,
14,
1813,
14,
12206,
29,
9634,
199,
32,
2190,
199,
318,
486,
2154,
63,
2330,
63,
2469,
8,
2190,
304,
199,
198,
86,
29,
2190,
14,
1813,
199,
198,
86,
459,
12206,
63,
12447,
63,
38,
418,
9811,
199,
198,
86,
459,
12206,
63,
26422,
63,
38,
418,
2968,
13,
67,
21810,
79,
418,
199,
198,
692,
440,
373,
459,
7916,
63,
12206,
2565,
86,
459,
7916,
63,
12206,
13784,
86,
459,
12206,
418,
199,
198,
86,
459,
12206,
44,
22780,
63,
12447,
63,
38,
418,
9811,
199,
198,
86,
459,
12206,
44,
22780,
63,
26422,
63,
38,
418,
2968,
13,
79,
418,
199,
198,
86,
459,
14533,
3243,
63,
840,
418,
18274,
41,
5,
83,
7,
199,
198,
86,
459,
27196,
63,
840,
418,
18274,
36,
5,
83,
7,
199,
198,
86,
459,
5617,
63,
840,
418,
18274,
76,
5,
83,
7,
199,
198,
86,
459,
32119,
63,
840,
418,
18274,
44,
5,
83,
7,
199,
198,
86,
459,
840,
5617,
63,
840,
418,
18274,
76,
5,
83,
7,
199,
198,
86,
459,
840,
32119,
63,
840,
418,
18274,
44,
5,
83,
7,
199,
198,
86,
459,
50,
3243,
63,
840,
418,
18274,
16239,
3057,
27841,
8719,
83,
7,
199,
198,
86,
459,
3377,
1991,
63,
840,
418,
18274,
16239,
3057,
72,
8719,
83,
7,
199,
198,
86,
459,
3234,
5617,
63,
18997,
418,
18274,
16239,
3057,
34,
7764,
7,
199,
198,
86,
459,
840,
5617,
63,
18997,
418,
18274,
16239,
3057,
34,
1986,
7,
199,
198,
86,
459,
9634,
6815,
63,
10764,
418,
9569,
83,
7,
199,
198,
86,
459,
26180,
63,
9634,
609,
773,
418,
2968,
13,
70,
26769,
418,
199,
198,
86,
459,
30388,
63,
9634,
609,
773,
418,
2968,
13,
5555,
418,
199,
198,
86,
459,
9634,
609,
773,
63,
10764,
32373,
773,
5,
83,
14,
1152,
7,
199,
198,
86,
459,
30388,
63,
9634,
270,
773,
418,
2968,
13,
16239,
3057,
34,
1986,
418,
199,
198,
86,
459,
9634,
270,
773,
63,
10764,
32373,
773,
5,
83,
14,
65,
7,
199,
198,
86,
459,
30388,
63,
9410,
32044,
906,
418,
2968,
13,
6469,
21810,
10705,
1673,
7764,
63,
3892,
418,
199,
198,
86,
459,
26180,
63,
9410,
32044,
906,
418,
2968,
13,
70,
26769,
418,
199,
198,
86,
459,
391,
2894,
4235,
63,
10764,
418,
9569,
83,
14,
6469,
7,
199,
32,
2190,
199,
318,
486,
2154,
63,
18156,
63,
2676,
708,
8,
2190,
304,
199,
198,
86,
29,
2190,
14,
1813,
199,
198,
86,
459,
9634,
6815,
63,
10764,
418,
9569,
83,
14,
5803,
7,
199,
198,
86,
459,
9634,
609,
773,
63,
10764,
418,
9569,
83,
14,
9259,
7,
199,
198,
86,
459,
3236,
773,
63,
10764,
32373,
773,
5,
83,
14,
9259,
14,
65,
7,
199,
198,
86,
459,
26312,
2100,
63,
840,
418,
18274,
16239,
28925,
548,
13,
3236,
773,
8719,
83,
7,
199,
198,
86,
459,
26180,
63,
9634,
609,
773,
418,
9811,
199,
198,
86,
14,
740,
63,
585,
360,
30388,
297,
459,
13,
16239,
28925,
4296,
13,
2495,
13,
646,
1105,
199,
32,
2190,
199,
318,
486,
2154,
63,
18156,
63,
16680,
8,
2190,
304,
199,
198,
71,
2154,
63,
18156,
63,
2676,
708,
8,
2190,
9,
199,
198,
86,
29,
2190,
14,
1813,
199,
198,
86,
459,
9634,
609,
773,
63,
10764,
32373,
15076,
5,
83,
14,
9259,
7,
199,
198,
86,
14,
740,
63,
585,
360,
30388,
63,
9634,
609,
773,
297,
459,
13,
16239,
28925,
4296,
13,
2495,
13,
1569,
13,
1095,
1105,
199,
198,
86,
459,
26180,
63,
9634,
609,
773,
418,
9811,
199,
32,
2190,
199,
318,
486,
2154,
63,
18156,
63,
13245,
8,
2190,
304,
199,
198,
86,
29,
2190,
14,
1813,
199,
198,
86,
459,
26180,
63,
9634,
609,
773,
418,
2968,
13,
70,
26769,
418,
199,
198,
86,
459,
30388,
63,
9634,
609,
773,
418,
2968,
13,
7764,
773,
21810,
16239,
3057,
15390,
63,
1023,
12,
17,
21810,
16239,
3057,
1818,
63,
1023,
12,
17,
418,
199,
198,
86,
459,
9634,
609,
773,
63,
10764,
32373,
773,
5,
83,
14,
22305,
7,
199,
198,
86,
459,
12683,
8406,
3243,
63,
840,
418,
18274,
38,
5,
83,
7,
199,
198,
86,
459,
12683,
8406,
63,
840,
418,
2968,
13,
4857,
418,
199,
198,
86,
459,
7762,
63,
840,
418,
2968,
13,
1047,
418,
199,
198,
86,
459,
30388,
63,
9634,
270,
773,
418,
9811,
199,
198,
86,
459,
3234,
5617,
63,
18997,
418,
9811,
199,
198,
86,
459,
840,
5617,
63,
18997,
418,
9811,
199,
198,
86,
459,
3377,
1991,
63,
840,
418,
9811,
199,
32,
2190,
199,
318,
486,
2154,
63,
18156,
63,
65,
1148,
8,
2190,
304,
199,
198,
86,
29,
2190,
14,
1813,
199,
198,
86,
459,
30388,
63,
9634,
6815,
418,
2968,
13,
16239,
3057,
66,
25011,
418,
199,
198,
86,
459,
30388,
63,
9634,
609,
773,
418,
2968,
13,
5555,
21810,
16239,
3057,
66,
25011,
3057,
66,
1474,
2861,
418,
199,
198,
86,
459,
3234,
5617,
63,
18997,
418,
9811,
199,
32,
2190,
199,
318,
486,
2154,
63,
18156,
63,
12025,
2521,
8,
2190,
304,
199,
198,
86,
29,
2190,
14,
1813,
199,
198,
86,
459,
3234,
5617,
63,
18997,
418,
9811,
199,
198,
86,
459,
840,
5617,
63,
18997,
418,
18274,
34,
1986,
7,
199,
198,
86,
459,
14804,
63,
9634,
609,
773,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
lixiangning888/whole_project
|
modules/signatures_merge_tmp/antivm_vbox_files.py
|
3
|
2048
|
# -*- coding: utf-8 -*-
# Copyright (C) 2012 Claudio "nex" Guarnieri (@botherder)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from lib.cuckoo.common.abstracts import Signature
class VBoxDetectFiles(Signature):
name = "antivm_vbox_files"
description = "通过文件检测VirtualBox系统"
severity = 3
categories = ["anti-vm"]
authors = ["nex"]
minimum = "0.5"
def run(self):
indicators = [
".*VBoxDisp\.dll$",
".*VBoxHook\.dll$",
".*VBoxMRXNP\.dll$",
".*VBoxOGL\.dll$",
".*VBoxOGLarrayspu\.dll$",
".*VBoxOGLcrutil\.dll$",
".*VBoxOGLerrorspu\.dll$",
".*VBoxOGLfeedbackspu\.dll$",
".*VBoxOGLpackspu\.dll$",
".*VBoxOGLpassthroughspu\.dll$"
".*VBoxDisp\.dll$",
".*VBoxSF\.sys$",
".*VBoxControl\.exe$",
".*VBoxService\.exe$",
".*VBoxTray\.exe$",
".*VBoxDrvInst\.exe$",
".*VBoxWHQLFake\.exe$",
".*VBoxGuest\.[a-zA-Z]{3}$",
".*VBoxMouse\.[a-zA-Z]{3}$",
".*VBoxVideo\.[a-zA-Z]{3}$",
".*\\\\VirtualBox\\ Guest\\ Additions\\\\uninst\.exe$",
".*\\\\VirtualBox\\ Guest\\ Additions\\\\uninst\.exe\.dll$",
]
for indicator in indicators:
if self.check_file(pattern=indicator, regex=True):
return True
return False
|
lgpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
334,
35,
9,
6029,
24433,
5208,
298,
14743,
2,
12436,
1060,
4446,
73,
8593,
656,
728,
424,
9,
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,
504,
1973,
14,
67,
10112,
1534,
14,
2330,
14,
6198,
83,
492,
18603,
199,
199,
533,
812,
3532,
20064,
5535,
8,
10014,
304,
272,
536,
275,
298,
4466,
2611,
63,
19508,
63,
1725,
2,
272,
1369,
275,
298,
14333,
249,
13201,
230,
29303,
163,
97,
223,
19451,
234,
8735,
3532,
27842,
120,
9360,
254,
2,
272,
25574,
275,
650,
272,
9695,
275,
2097,
4466,
13,
2611,
937,
272,
11462,
275,
2097,
14743,
937,
272,
7481,
275,
298,
16,
14,
21,
2,
339,
347,
1255,
8,
277,
304,
267,
7262,
2750,
275,
359,
288,
298,
2795,
54,
3532,
2825,
80,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
8481,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
45,
15361,
14970,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
47,
2226,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
47,
2226,
10095,
3165,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
47,
2226,
1556,
1974,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
47,
2226,
705,
681,
85,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
47,
2226,
13485,
681,
85,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
47,
2226,
1389,
681,
85,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
47,
2226,
27197,
681,
85,
4537,
9259,
17351,
288,
298,
2795,
54,
3532,
2825,
80,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
13107,
4537,
1274,
11918,
288,
298,
2795,
54,
3532,
3717,
4537,
5803,
11918,
288,
298,
2795,
54,
3532,
3167,
4537,
5803,
11918,
288,
298,
2795,
54,
3532,
52,
803,
4537,
5803,
11918,
288,
298,
2795,
54,
3532,
36,
6310,
10083,
4537,
5803,
11918,
288,
298,
2795,
54,
3532,
9792,
2940,
8249,
4537,
5803,
11918,
288,
298,
2795,
54,
3532,
16022,
27658,
65,
13,
6353,
13,
58,
8194,
19,
93,
11918,
288,
298,
2795,
54,
3532,
17141,
27658,
65,
13,
6353,
13,
58,
8194,
19,
93,
11918,
288,
298,
2795,
54,
3532,
9166,
27658,
65,
13,
6353,
13,
58,
8194,
19,
93,
11918,
288,
298,
2795,
8712,
8735,
3532,
1103,
598,
5291,
1103,
4431,
3138,
8712,
324,
3615,
4537,
5803,
11918,
288,
298,
2795,
8712,
8735,
3532,
1103,
598,
5291,
1103,
4431,
3138,
8712,
324,
3615,
4537,
5803,
4537,
9259,
11918,
267,
1622,
398,
367,
16385,
315,
7262,
2750,
26,
288,
340,
291,
14,
1074,
63,
493,
8,
3401,
29,
15785,
12,
5163,
29,
549,
304,
355,
372,
715,
398,
372,
756,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
334,
35,
9,
6029,
24433,
5208,
298,
14743,
2,
12436,
1060,
4446,
73,
8593,
656,
728,
424,
9,
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,
504,
1973,
14,
67,
10112,
1534,
14,
2330,
14,
6198,
83,
492,
18603,
199,
199,
533,
812,
3532,
20064,
5535,
8,
10014,
304,
272,
536,
275,
298,
4466,
2611,
63,
19508,
63,
1725,
2,
272,
1369,
275,
298,
14333,
249,
13201,
230,
29303,
163,
97,
223,
19451,
234,
8735,
3532,
27842,
120,
9360,
254,
2,
272,
25574,
275,
650,
272,
9695,
275,
2097,
4466,
13,
2611,
937,
272,
11462,
275,
2097,
14743,
937,
272,
7481,
275,
298,
16,
14,
21,
2,
339,
347,
1255,
8,
277,
304,
267,
7262,
2750,
275,
359,
288,
298,
2795,
54,
3532,
2825,
80,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
8481,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
45,
15361,
14970,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
47,
2226,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
47,
2226,
10095,
3165,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
47,
2226,
1556,
1974,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
47,
2226,
705,
681,
85,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
47,
2226,
13485,
681,
85,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
47,
2226,
1389,
681,
85,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
47,
2226,
27197,
681,
85,
4537,
9259,
17351,
288,
298,
2795,
54,
3532,
2825,
80,
4537,
9259,
11918,
288,
298,
2795,
54,
3532,
13107,
4537,
1274,
11918,
288,
298,
2795,
54,
3532,
3717,
4537,
5803,
11918,
288,
298,
2795,
54,
3532,
3167,
4537,
5803,
11918,
288,
298,
2795,
54,
3532,
52,
803,
4537,
5803,
11918,
288,
298,
2795,
54,
3532,
36,
6310,
10083,
4537,
5803,
11918,
288,
298,
2795,
54,
3532,
9792,
2940,
8249,
4537,
5803,
11918,
288,
298,
2795,
54,
3532,
16022,
27658,
65,
13,
6353,
13,
58,
8194,
19,
93,
11918,
288,
298,
2795,
54,
3532,
17141,
27658,
65,
13,
6353,
13,
58,
8194,
19,
93,
11918,
288,
298,
2795,
54,
3532,
9166,
27658,
65,
13,
6353,
13,
58,
8194,
19,
93,
11918,
288,
298,
2795,
8712,
8735,
3532,
1103,
598,
5291,
1103,
4431,
3138,
8712,
324,
3615,
4537,
5803,
11918,
288,
298,
2795,
8712,
8735,
3532,
1103,
598,
5291,
1103,
4431,
3138,
8712,
324,
3615,
4537,
5803,
4537,
9259,
11918,
267,
1622,
398,
367,
16385,
315,
7262,
2750,
26,
288,
340,
291,
14,
1074,
63,
493,
8,
3401,
29,
15785,
12,
5163,
29,
549,
304,
355,
372,
715,
398,
372,
756,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
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64
|
13497
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import logging
import time
from openerp.osv import fields,osv
from openerp.tools.translate import _
import openerp.addons.decimal_precision as dp
from openerp.tools.safe_eval import safe_eval as eval
_logger = logging.getLogger(__name__)
class delivery_carrier(osv.osv):
_name = "delivery.carrier"
_description = "Carrier"
def name_get(self, cr, uid, ids, context=None):
if not len(ids):
return []
if context is None:
context = {}
order_id = context.get('order_id',False)
if not order_id:
res = super(delivery_carrier, self).name_get(cr, uid, ids, context=context)
else:
order = self.pool.get('sale.order').browse(cr, uid, order_id, context=context)
currency = order.pricelist_id.currency_id.name or ''
res = [(r['id'], r['name']+' ('+(str(r['price']))+' '+currency+')') for r in self.read(cr, uid, ids, ['name', 'price'], context)]
return res
def get_price(self, cr, uid, ids, field_name, arg=None, context=None):
res={}
if context is None:
context = {}
sale_obj=self.pool.get('sale.order')
grid_obj=self.pool.get('delivery.grid')
for carrier in self.browse(cr, uid, ids, context=context):
order_id=context.get('order_id',False)
price=False
available = False
if order_id:
order = sale_obj.browse(cr, uid, order_id, context=context)
carrier_grid=self.grid_get(cr,uid,[carrier.id],order.partner_shipping_id.id,context)
if carrier_grid:
try:
price=grid_obj.get_price(cr, uid, carrier_grid, order, time.strftime('%Y-%m-%d'), context)
available = True
except osv.except_osv, e:
# no suitable delivery method found, probably configuration error
_logger.error("Carrier %s: %s\n%s" % (carrier.name, e.name, e.value))
price = 0.0
else:
price = 0.0
res[carrier.id] = {
'price': price,
'available': available
}
return res
_columns = {
'name': fields.char('Delivery Method', required=True),
'partner_id': fields.many2one('res.partner', 'Transport Company', required=True, help="The partner that is doing the delivery service."),
'product_id': fields.many2one('product.product', 'Delivery Product', required=True),
'grids_id': fields.one2many('delivery.grid', 'carrier_id', 'Delivery Grids'),
'available' : fields.function(get_price, string='Available',type='boolean', multi='price',
help="Is the carrier method possible with the current order."),
'price' : fields.function(get_price, string='Price', multi='price'),
'active': fields.boolean('Active', help="If the active field is set to False, it will allow you to hide the delivery carrier without removing it."),
'normal_price': fields.float('Normal Price', help="Keep empty if the pricing depends on the advanced pricing per destination"),
'free_if_more_than': fields.boolean('Free If Order Total Amount Is More Than', help="If the order is more expensive than a certain amount, the customer can benefit from a free shipping"),
'amount': fields.float('Amount', help="Amount of the order to benefit from a free shipping, expressed in the company currency"),
'use_detailed_pricelist': fields.boolean('Advanced Pricing per Destination', help="Check this box if you want to manage delivery prices that depends on the destination, the weight, the total of the order, etc."),
'pricelist_ids': fields.one2many('delivery.grid', 'carrier_id', 'Advanced Pricing'),
}
_defaults = {
'active': 1,
'free_if_more_than': False,
}
def grid_get(self, cr, uid, ids, contact_id, context=None):
contact = self.pool.get('res.partner').browse(cr, uid, contact_id, context=context)
for carrier in self.browse(cr, uid, ids, context=context):
for grid in carrier.grids_id:
get_id = lambda x: x.id
country_ids = map(get_id, grid.country_ids)
state_ids = map(get_id, grid.state_ids)
if country_ids and not contact.country_id.id in country_ids:
continue
if state_ids and not contact.state_id.id in state_ids:
continue
if grid.zip_from and (contact.zip or '')< grid.zip_from:
continue
if grid.zip_to and (contact.zip or '')> grid.zip_to:
continue
return grid.id
return False
def create_grid_lines(self, cr, uid, ids, vals, context=None):
if context is None:
context = {}
grid_line_pool = self.pool.get('delivery.grid.line')
grid_pool = self.pool.get('delivery.grid')
for record in self.browse(cr, uid, ids, context=context):
# if using advanced pricing per destination: do not change
if record.use_detailed_pricelist:
continue
# not using advanced pricing per destination: override grid
grid_id = grid_pool.search(cr, uid, [('carrier_id', '=', record.id)], context=context)
if grid_id and not (record.normal_price is not False or record.free_if_more_than):
grid_pool.unlink(cr, uid, grid_id, context=context)
grid_id = None
if not (record.normal_price is not False or record.free_if_more_than):
continue
if not grid_id:
grid_data = {
'name': record.name,
'carrier_id': record.id,
'sequence': 10,
}
grid_id = [grid_pool.create(cr, uid, grid_data, context=context)]
lines = grid_line_pool.search(cr, uid, [('grid_id','in',grid_id)], context=context)
if lines:
grid_line_pool.unlink(cr, uid, lines, context=context)
#create the grid lines
if record.free_if_more_than:
line_data = {
'grid_id': grid_id and grid_id[0],
'name': _('Free if more than %.2f') % record.amount,
'type': 'price',
'operator': '>=',
'max_value': record.amount,
'standard_price': 0.0,
'list_price': 0.0,
}
grid_line_pool.create(cr, uid, line_data, context=context)
if record.normal_price is not False:
line_data = {
'grid_id': grid_id and grid_id[0],
'name': _('Default price'),
'type': 'price',
'operator': '>=',
'max_value': 0.0,
'standard_price': record.normal_price,
'list_price': record.normal_price,
}
grid_line_pool.create(cr, uid, line_data, context=context)
return True
def write(self, cr, uid, ids, vals, context=None):
if isinstance(ids, (int,long)):
ids = [ids]
res = super(delivery_carrier, self).write(cr, uid, ids, vals, context=context)
self.create_grid_lines(cr, uid, ids, vals, context=context)
return res
def create(self, cr, uid, vals, context=None):
res_id = super(delivery_carrier, self).create(cr, uid, vals, context=context)
self.create_grid_lines(cr, uid, [res_id], vals, context=context)
return res_id
class delivery_grid(osv.osv):
_name = "delivery.grid"
_description = "Delivery Grid"
_columns = {
'name': fields.char('Grid Name', required=True),
'sequence': fields.integer('Sequence', required=True, help="Gives the sequence order when displaying a list of delivery grid."),
'carrier_id': fields.many2one('delivery.carrier', 'Carrier', required=True, ondelete='cascade'),
'country_ids': fields.many2many('res.country', 'delivery_grid_country_rel', 'grid_id', 'country_id', 'Countries'),
'state_ids': fields.many2many('res.country.state', 'delivery_grid_state_rel', 'grid_id', 'state_id', 'States'),
'zip_from': fields.char('Start Zip', size=12),
'zip_to': fields.char('To Zip', size=12),
'line_ids': fields.one2many('delivery.grid.line', 'grid_id', 'Grid Line', copy=True),
'active': fields.boolean('Active', help="If the active field is set to False, it will allow you to hide the delivery grid without removing it."),
}
_defaults = {
'active': lambda *a: 1,
'sequence': lambda *a: 1,
}
_order = 'sequence'
def get_price(self, cr, uid, id, order, dt, context=None):
total = 0
weight = 0
volume = 0
quantity = 0
total_delivery = 0.0
product_uom_obj = self.pool.get('product.uom')
for line in order.order_line:
if line.state == 'cancel':
continue
if line.is_delivery:
total_delivery += line.price_subtotal + self.pool['sale.order']._amount_line_tax(cr, uid, line, context=context)
if not line.product_id or line.is_delivery:
continue
q = product_uom_obj._compute_qty(cr, uid, line.product_uom.id, line.product_uom_qty, line.product_id.uom_id.id)
weight += (line.product_id.weight or 0.0) * q
volume += (line.product_id.volume or 0.0) * q
quantity += q
total = (order.amount_total or 0.0) - total_delivery
return self.get_price_from_picking(cr, uid, id, total,weight, volume, quantity, context=context)
def get_price_from_picking(self, cr, uid, id, total, weight, volume, quantity, context=None):
grid = self.browse(cr, uid, id, context=context)
price = 0.0
ok = False
price_dict = {'price': total, 'volume':volume, 'weight': weight, 'wv':volume*weight, 'quantity': quantity}
for line in grid.line_ids:
test = eval(line.type+line.operator+str(line.max_value), price_dict)
if test:
if line.price_type=='variable':
price = line.list_price * price_dict[line.variable_factor]
else:
price = line.list_price
ok = True
break
if not ok:
raise osv.except_osv(_("Unable to fetch delivery method!"), _("Selected product in the delivery method doesn't fulfill any of the delivery grid(s) criteria."))
return price
class delivery_grid_line(osv.osv):
_name = "delivery.grid.line"
_description = "Delivery Grid Line"
_columns = {
'name': fields.char('Name', required=True),
'sequence': fields.integer('Sequence', required=True, help="Gives the sequence order when calculating delivery grid."),
'grid_id': fields.many2one('delivery.grid', 'Grid',required=True, ondelete='cascade'),
'type': fields.selection([('weight','Weight'),('volume','Volume'),\
('wv','Weight * Volume'), ('price','Price'), ('quantity','Quantity')],\
'Variable', required=True),
'operator': fields.selection([('==','='),('<=','<='),('<','<'),('>=','>='),('>','>')], 'Operator', required=True),
'max_value': fields.float('Maximum Value', required=True),
'price_type': fields.selection([('fixed','Fixed'),('variable','Variable')], 'Price Type', required=True),
'variable_factor': fields.selection([('weight','Weight'),('volume','Volume'),('wv','Weight * Volume'), ('price','Price'), ('quantity','Quantity')], 'Variable Factor', required=True),
'list_price': fields.float('Sale Price', digits_compute= dp.get_precision('Product Price'), required=True),
'standard_price': fields.float('Cost Price', digits_compute= dp.get_precision('Product Price'), required=True),
}
_defaults = {
'sequence': lambda *args: 10,
'type': lambda *args: 'weight',
'operator': lambda *args: '<=',
'price_type': lambda *args: 'fixed',
'variable_factor': lambda *args: 'weight',
}
_order = 'sequence, list_price'
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
2050,
199,
646,
900,
199,
504,
5166,
14,
4795,
492,
1504,
12,
4795,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
646,
5166,
14,
10788,
14,
6355,
63,
6833,
465,
12392,
199,
504,
5166,
14,
2537,
14,
3489,
63,
2579,
492,
5048,
63,
2579,
465,
3468,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
533,
18719,
63,
24499,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
298,
14564,
14,
24499,
2,
272,
485,
1802,
275,
298,
16034,
10742,
2,
339,
347,
536,
63,
362,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
340,
440,
822,
8,
1580,
304,
288,
372,
942,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
1865,
63,
344,
275,
1067,
14,
362,
360,
1648,
63,
344,
297,
797,
9,
267,
340,
440,
1865,
63,
344,
26,
288,
522,
275,
1613,
8,
14564,
63,
24499,
12,
291,
680,
354,
63,
362,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
9,
267,
587,
26,
288,
1865,
275,
291,
14,
2293,
14,
362,
360,
8515,
14,
1648,
1959,
4570,
8,
1556,
12,
1747,
12,
1865,
63,
344,
12,
1067,
29,
1100,
9,
288,
9952,
275,
1865,
14,
17385,
63,
344,
14,
4968,
63,
344,
14,
354,
503,
2125,
288,
522,
275,
3842,
82,
459,
344,
995,
519,
459,
354,
418,
4786,
661,
15622,
495,
8,
82,
459,
4777,
5156,
4786,
6681,
4968,
13854,
358,
367,
519,
315,
291,
14,
739,
8,
1556,
12,
1747,
12,
2762,
12,
788,
354,
297,
283,
4777,
995,
1067,
1874,
267,
372,
522,
339,
347,
664,
63,
4777,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
901,
63,
354,
12,
1680,
29,
403,
12,
1067,
29,
403,
304,
267,
522,
7622,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
13590,
63,
1113,
29,
277,
14,
2293,
14,
362,
360,
8515,
14,
1648,
358,
267,
6068,
63,
1113,
29,
277,
14,
2293,
14,
362,
360,
14564,
14,
3825,
358,
267,
367,
9590,
10742,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
1865,
63,
344,
29,
1100,
14,
362,
360,
1648,
63,
344,
297,
797,
9,
288,
8033,
29,
797,
288,
2808,
275,
756,
288,
340,
1865,
63,
344,
26,
1598,
1865,
275,
13590,
63,
1113,
14,
4570,
8,
1556,
12,
1747,
12,
1865,
63,
344,
12,
1067,
29,
1100,
9,
1598,
9590,
10742,
63,
3825,
29,
277,
14,
3825,
63,
362,
8,
1556,
12,
1535,
14343,
24499,
14,
344,
467,
1648,
14,
3899,
63,
17801,
63,
344,
14,
344,
12,
1100,
9,
1598,
340,
9590,
10742,
63,
3825,
26,
2116,
862,
26,
490,
8033,
29,
3825,
63,
1113,
14,
362,
63,
4777,
8,
1556,
12,
1747,
12,
9590,
10742,
63,
3825,
12,
1865,
12,
900,
14,
6205,
3508,
57,
3295,
77,
3295,
68,
659,
1067,
9,
490,
2808,
275,
715,
2116,
871,
9506,
14,
2590,
63,
4795,
12,
325,
26,
490,
327,
949,
11233,
18719,
1083,
1911,
12,
8646,
2897,
1125,
490,
485,
2921,
14,
705,
480,
16034,
10742,
450,
83,
26,
450,
83,
60,
78,
5,
83,
2,
450,
334,
24499,
14,
354,
12,
325,
14,
354,
12,
325,
14,
585,
430,
490,
8033,
275,
378,
14,
16,
1598,
587,
26,
2116,
8033,
275,
378,
14,
16,
288,
522,
59,
24499,
14,
344,
61,
275,
469,
355,
283,
4777,
356,
8033,
12,
355,
283,
4561,
356,
2808,
288,
789,
267,
372,
522,
339,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
24640,
9075,
297,
1415,
29,
549,
395,
267,
283,
3899,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
3899,
297,
283,
7836,
15878,
297,
1415,
29,
549,
12,
1720,
628,
1918,
5854,
626,
365,
9689,
314,
18719,
2435,
7651,
267,
283,
2558,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
2558,
14,
2558,
297,
283,
24640,
12705,
297,
1415,
29,
549,
395,
267,
283,
7928,
795,
63,
344,
356,
1504,
14,
368,
18,
3479,
360,
14564,
14,
3825,
297,
283,
24499,
63,
344,
297,
283,
24640,
598,
322,
795,
659,
267,
283,
4561,
7,
520,
1504,
14,
1593,
8,
362,
63,
4777,
12,
1059,
534,
11464,
297,
466,
534,
4871,
297,
3510,
534,
4777,
297,
288,
1720,
628,
1831,
314,
9590,
10742,
1083,
3962,
543,
314,
1453,
1865,
7651,
267,
283,
4777,
7,
520,
1504,
14,
1593,
8,
362,
63,
4777,
12,
1059,
534,
11826,
297,
3510,
534,
4777,
659,
267,
283,
2682,
356,
1504,
14,
4871,
360,
7472,
297,
1720,
628,
3917,
314,
4702,
901,
365,
663,
370,
756,
12,
652,
911,
2040,
1265,
370,
13714,
314,
18719,
9590,
10742,
1928,
12881,
652,
7651,
267,
283,
3302,
63,
4777,
356,
1504,
14,
1609,
360,
6241,
20276,
297,
1720,
628,
18567,
2701,
340,
314,
299,
1567,
316,
8350,
641,
314,
19472,
299,
1567,
316,
1126,
5724,
1288
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
2050,
199,
646,
900,
199,
504,
5166,
14,
4795,
492,
1504,
12,
4795,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
646,
5166,
14,
10788,
14,
6355,
63,
6833,
465,
12392,
199,
504,
5166,
14,
2537,
14,
3489,
63,
2579,
492,
5048,
63,
2579,
465,
3468,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
533,
18719,
63,
24499,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
298,
14564,
14,
24499,
2,
272,
485,
1802,
275,
298,
16034,
10742,
2,
339,
347,
536,
63,
362,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
340,
440,
822,
8,
1580,
304,
288,
372,
942,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
1865,
63,
344,
275,
1067,
14,
362,
360,
1648,
63,
344,
297,
797,
9,
267,
340,
440,
1865,
63,
344,
26,
288,
522,
275,
1613,
8,
14564,
63,
24499,
12,
291,
680,
354,
63,
362,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
9,
267,
587,
26,
288,
1865,
275,
291,
14,
2293,
14,
362,
360,
8515,
14,
1648,
1959,
4570,
8,
1556,
12,
1747,
12,
1865,
63,
344,
12,
1067,
29,
1100,
9,
288,
9952,
275,
1865,
14,
17385,
63,
344,
14,
4968,
63,
344,
14,
354,
503,
2125,
288,
522,
275,
3842,
82,
459,
344,
995,
519,
459,
354,
418,
4786,
661,
15622,
495,
8,
82,
459,
4777,
5156,
4786,
6681,
4968,
13854,
358,
367,
519,
315,
291,
14,
739,
8,
1556,
12,
1747,
12,
2762,
12,
788,
354,
297,
283,
4777,
995,
1067,
1874,
267,
372,
522,
339,
347,
664,
63,
4777,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
901,
63,
354,
12,
1680,
29,
403,
12,
1067,
29,
403,
304,
267,
522,
7622,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
13590,
63,
1113,
29,
277,
14,
2293,
14,
362,
360,
8515,
14,
1648,
358,
267,
6068,
63,
1113,
29,
277,
14,
2293,
14,
362,
360,
14564,
14,
3825,
358,
267,
367,
9590,
10742,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
1865,
63,
344,
29,
1100,
14,
362,
360,
1648,
63,
344,
297,
797,
9,
288,
8033,
29,
797,
288,
2808,
275,
756,
288,
340,
1865,
63,
344,
26,
1598,
1865,
275,
13590,
63,
1113,
14,
4570,
8,
1556,
12,
1747,
12,
1865,
63,
344,
12,
1067,
29,
1100,
9,
1598,
9590,
10742,
63,
3825,
29,
277,
14,
3825,
63,
362,
8,
1556,
12,
1535,
14343,
24499,
14,
344,
467,
1648,
14,
3899,
63,
17801,
63,
344,
14,
344,
12,
1100,
9,
1598,
340,
9590,
10742,
63,
3825,
26,
2116,
862,
26,
490,
8033,
29,
3825,
63,
1113,
14,
362,
63,
4777,
8,
1556,
12,
1747,
12,
9590,
10742,
63,
3825,
12,
1865,
12,
900,
14,
6205,
3508,
57,
3295,
77,
3295,
68,
659,
1067,
9,
490,
2808,
275,
715,
2116,
871,
9506,
14,
2590,
63,
4795,
12,
325,
26,
490,
327,
949,
11233,
18719,
1083,
1911,
12,
8646,
2897,
1125,
490,
485,
2921,
14,
705,
480,
16034,
10742,
450,
83,
26,
450,
83,
60,
78,
5,
83,
2,
450,
334,
24499,
14,
354,
12,
325,
14,
354,
12,
325,
14,
585,
430,
490,
8033,
275,
378,
14,
16,
1598,
587,
26,
2116,
8033,
275,
378,
14,
16,
288,
522,
59,
24499,
14,
344,
61,
275,
469,
355,
283,
4777,
356,
8033,
12,
355,
283,
4561,
356,
2808,
288,
789,
267,
372,
522,
339,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
24640,
9075,
297,
1415,
29,
549,
395,
267,
283,
3899,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
3899,
297,
283,
7836,
15878,
297,
1415,
29,
549,
12,
1720,
628,
1918,
5854,
626,
365,
9689,
314,
18719,
2435,
7651,
267,
283,
2558,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
2558,
14,
2558,
297,
283,
24640,
12705,
297,
1415,
29,
549,
395,
267,
283,
7928,
795,
63,
344,
356,
1504,
14,
368,
18,
3479,
360,
14564,
14,
3825,
297,
283,
24499,
63,
344,
297,
283,
24640,
598,
322,
795,
659,
267,
283,
4561,
7,
520,
1504,
14,
1593,
8,
362,
63,
4777,
12,
1059,
534,
11464,
297,
466,
534,
4871,
297,
3510,
534,
4777,
297,
288,
1720,
628,
1831,
314,
9590,
10742,
1083,
3962,
543,
314,
1453,
1865,
7651,
267,
283,
4777,
7,
520,
1504,
14,
1593,
8,
362,
63,
4777,
12,
1059,
534,
11826,
297,
3510,
534,
4777,
659,
267,
283,
2682,
356,
1504,
14,
4871,
360,
7472,
297,
1720,
628,
3917,
314,
4702,
901,
365,
663,
370,
756,
12,
652,
911,
2040,
1265,
370,
13714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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
] |
xccui/flink
|
flink-python/pyflink/serializers.py
|
4
|
6208
|
################################################################################
# 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 pickle
import struct
from abc import ABCMeta, abstractmethod
from itertools import chain
class SpecialLengths(object):
END_OF_DATA_SECTION = -1
NULL = -2
class Serializer(object, metaclass=ABCMeta):
# Note: our notion of "equality" is that output generated by
# equal serializers can be deserialized using the same serializer.
# This default implementation handles the simple cases;
# subclasses should override __eq__ as appropriate.
def __eq__(self, other):
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
def __ne__(self, other):
return not self.__eq__(other)
def __repr__(self):
return "%s()" % self.__class__.__name__
def __hash__(self):
return hash(str(self))
@abstractmethod
def dump_to_stream(self, iterator, stream):
"""
Serializes an iterator of objects to the output stream.
"""
pass
@abstractmethod
def load_from_stream(self, stream):
"""
Returns an iterator of deserialized objects from the input stream.
"""
pass
def _load_from_stream_without_unbatching(self, stream):
"""
Returns an iterator of deserialized batches (iterable) of objects from the input stream.
If the serializer does not operate on batches the default implementation returns an
iterator of single element lists.
"""
return map(lambda x: [x], self.load_from_stream(stream))
class VarLengthDataSerializer(Serializer):
"""
Serializer that writes objects as a stream of (length, data) pairs,
where length is a 32-bit integer and data is length bytes.
"""
def dump_to_stream(self, iterator, stream):
for obj in iterator:
self._write_with_length(obj, stream)
def load_from_stream(self, stream):
while True:
try:
yield self._read_with_length(stream)
except EOFError:
return
def _write_with_length(self, obj, stream):
serialized = self.dumps(obj)
if serialized is None:
raise ValueError("Serialized value should not be None")
if len(serialized) > (1 << 31):
raise ValueError("Can not serialize object larger than 2G")
write_int(len(serialized), stream)
stream.write(serialized)
def _read_with_length(self, stream):
length = read_int(stream)
if length == SpecialLengths.END_OF_DATA_SECTION:
raise EOFError
elif length == SpecialLengths.NULL:
return None
obj = stream.read(length)
if len(obj) < length:
raise EOFError
return self.loads(obj)
@abstractmethod
def dumps(self, obj):
"""
Serialize an object into a byte array.
When batching is used, this will be called with an array of objects.
"""
pass
@abstractmethod
def loads(self, obj):
"""
Deserialize an object from a byte array.
"""
pass
class PickleSerializer(VarLengthDataSerializer):
"""
Serializes objects using Python's pickle serializer:
http://docs.python.org/3/library/pickle.html
This serializer supports nearly any Python object, but may
not be as fast as more specialized serializers.
"""
def dumps(self, obj):
return pickle.dumps(obj, 3)
def loads(self, obj):
return pickle.loads(obj, encoding="bytes")
class BatchedSerializer(Serializer):
"""
Serializes a stream of objects in batches by calling its wrapped
Serializer with streams of objects.
"""
UNLIMITED_BATCH_SIZE = -1
UNKNOWN_BATCH_SIZE = 0
def __init__(self, serializer, batch_size=UNLIMITED_BATCH_SIZE):
self.serializer = serializer
self.batch_size = batch_size
def __repr__(self):
return "BatchedSerializer(%s, %d)" % (str(self.serializer), self.batch_size)
def _batched(self, iterator):
if self.batch_size == self.UNLIMITED_BATCH_SIZE:
yield list(iterator)
elif hasattr(iterator, "__len__") and hasattr(iterator, "__getslice__"):
n = len(iterator)
for i in range(0, n, self.batch_size):
yield iterator[i: i + self.batch_size]
else:
items = []
count = 0
for item in iterator:
items.append(item)
count += 1
if count == self.batch_size:
yield items
items = []
count = 0
if items:
yield items
def dump_to_stream(self, iterator, stream):
self.serializer.dump_to_stream(self._batched(iterator), stream)
def load_from_stream(self, stream):
return chain.from_iterable(self._load_from_stream_without_unbatching(stream))
def _load_from_stream_without_unbatching(self, stream):
return self.serializer.load_from_stream(stream)
def read_int(stream):
length = stream.read(4)
if not length:
raise EOFError
return struct.unpack("!i", length)[0]
def write_int(value, stream):
stream.write(struct.pack("!i", value))
|
apache-2.0
|
[
13289,
199,
3,
221,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
221,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
221,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
221,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
221,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
221,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
221,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
13289,
199,
199,
646,
5927,
199,
646,
2702,
199,
504,
13022,
492,
29565,
12,
9006,
765,
199,
504,
7975,
492,
6036,
421,
199,
533,
12568,
4625,
83,
8,
785,
304,
272,
7729,
63,
3359,
63,
3998,
63,
13835,
275,
446,
17,
272,
5962,
275,
446,
18,
421,
199,
533,
25555,
8,
785,
12,
17074,
29,
22254,
304,
339,
327,
3390,
26,
4154,
949,
296,
402,
298,
20982,
2,
365,
626,
1072,
4046,
701,
272,
327,
4472,
12506,
883,
506,
13256,
1808,
314,
2011,
9146,
14,
339,
327,
961,
849,
4514,
10022,
314,
3486,
5560,
27,
272,
327,
9180,
1077,
4278,
636,
4077,
363,
465,
5827,
14,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1228,
8,
1848,
12,
291,
855,
533,
3368,
436,
291,
855,
807,
363,
508,
1163,
855,
807,
363,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
291,
855,
4077,
721,
1848,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
2071,
83,
16493,
450,
291,
855,
533,
4914,
354,
363,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
495,
8,
277,
430,
339,
768,
10315,
272,
347,
5461,
63,
475,
63,
1745,
8,
277,
12,
6122,
12,
2547,
304,
267,
408,
267,
11973,
6491,
376,
6122,
402,
2251,
370,
314,
1072,
2547,
14,
267,
408,
267,
986,
339,
768,
10315,
272,
347,
2248,
63,
504,
63,
1745,
8,
277,
12,
2547,
304,
267,
408,
267,
1803,
376,
6122,
402,
13256,
2251,
687,
314,
1324,
2547,
14,
267,
408,
267,
986,
339,
347,
485,
912,
63,
504,
63,
1745,
63,
7395,
63,
324,
2912,
316,
8,
277,
12,
2547,
304,
267,
408,
267,
1803,
376,
6122,
402,
13256,
19593,
334,
8147,
9,
402,
2251,
687,
314,
1324,
2547,
14,
267,
982,
314,
9146,
1630,
440,
19218,
641,
19593,
314,
849,
4514,
2529,
376,
267,
6122,
402,
2849,
1819,
5548,
14,
267,
408,
267,
372,
2341,
8,
2734,
671,
26,
359,
88,
467,
291,
14,
912,
63,
504,
63,
1745,
8,
1745,
430,
421,
199,
533,
21084,
4625,
1451,
7299,
8,
7299,
304,
272,
408,
272,
25555,
626,
14511,
2251,
465,
282,
2547,
402,
334,
1267,
12,
666,
9,
6342,
12,
272,
2382,
2582,
365,
282,
4337,
13,
2075,
3000,
436,
666,
365,
2582,
2783,
14,
272,
408,
339,
347,
5461,
63,
475,
63,
1745,
8,
277,
12,
6122,
12,
2547,
304,
267,
367,
1559,
315,
6122,
26,
288,
291,
423,
952,
63,
1045,
63,
1267,
8,
1113,
12,
2547,
9,
339,
347,
2248,
63,
504,
63,
1745,
8,
277,
12,
2547,
304,
267,
1830,
715,
26,
288,
862,
26,
355,
1995,
291,
423,
739,
63,
1045,
63,
1267,
8,
1745,
9,
288,
871,
21157,
26,
355,
372,
339,
347,
485,
952,
63,
1045,
63,
1267,
8,
277,
12,
1559,
12,
2547,
304,
267,
6380,
275,
291,
14,
4180,
8,
1113,
9,
267,
340,
6380,
365,
488,
26,
288,
746,
1722,
480,
12023,
574,
1077,
440,
506,
488,
531,
267,
340,
822,
8,
8397,
9,
690,
334,
17,
5213,
7105,
304,
288,
746,
1722,
480,
6049,
440,
8437,
909,
12142,
2419,
499,
39,
531,
267,
2218,
63,
442,
8,
552,
8,
8397,
395,
2547,
9,
267,
2547,
14,
952,
8,
8397,
9,
339,
347,
485,
739,
63,
1045,
63,
1267,
8,
277,
12,
2547,
304,
267,
2582,
275,
1586,
63,
442,
8,
1745,
9,
267,
340,
2582,
508,
12568,
4625,
83,
14,
3902,
63,
3359,
63,
3998,
63,
13835,
26,
288,
746,
21157,
267,
916,
2582,
508,
12568,
4625,
83,
14,
8084,
26,
288,
372,
488,
267,
1559,
275,
2547,
14,
739,
8,
1267,
9,
267,
340,
822,
8,
1113,
9,
665,
2582,
26,
288,
746,
21157,
267,
372,
291,
14,
3640,
8,
1113,
9,
339,
768,
10315,
272,
347,
16864,
8,
277,
12,
1559,
304,
267,
408,
267,
11973,
794,
376,
909,
1901,
282,
3696,
1625,
14,
267,
3979,
3522,
316,
365,
1202,
12,
642,
911,
506,
2797,
543,
376,
1625,
402,
2251,
14,
267,
408,
267,
986,
339,
768,
10315,
272,
347,
14404,
8,
277,
12,
1559,
304,
267,
408,
267,
1487,
3549,
376,
909,
687,
282,
3696,
1625,
14,
267,
408,
267,
986,
421,
199,
533,
31732,
7299,
8,
5894,
4625,
1451,
7299,
304,
272,
408,
272,
11973,
6491,
2251,
1808,
2018,
1159,
5927,
9146,
26,
398,
1455,
921,
4757,
14,
1548,
14,
1308,
15,
19,
15,
4342,
15,
8092,
14,
1360,
339,
961,
9146,
5171,
17429,
590,
1263,
2018,
909,
12,
1325,
1443,
272,
440,
506,
465,
7377,
465,
1655,
27877,
12506,
14,
272,
408,
339,
347,
16864,
8,
277,
12,
1559,
304,
267,
372,
5927,
14,
4180,
8,
1113,
12,
650,
9,
339,
347,
14404,
8,
277,
12,
1559,
304,
267,
372,
5927,
14,
3640,
8,
1113,
12,
2644,
628,
2394,
531,
421,
199,
533,
17206,
379,
7299,
8,
7299,
304,
272,
408,
272,
11973,
6491,
282,
2547,
402,
2251,
315,
19593,
701,
6358,
2399,
8072,
272,
25555,
543,
13788,
402,
2251,
14,
272,
408,
339,
6778,
13387,
1149,
63,
20813,
63,
4305,
275,
446
] |
[
199,
3,
221,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
221,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
221,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
221,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
221,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
221,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
221,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
13289,
199,
199,
646,
5927,
199,
646,
2702,
199,
504,
13022,
492,
29565,
12,
9006,
765,
199,
504,
7975,
492,
6036,
421,
199,
533,
12568,
4625,
83,
8,
785,
304,
272,
7729,
63,
3359,
63,
3998,
63,
13835,
275,
446,
17,
272,
5962,
275,
446,
18,
421,
199,
533,
25555,
8,
785,
12,
17074,
29,
22254,
304,
339,
327,
3390,
26,
4154,
949,
296,
402,
298,
20982,
2,
365,
626,
1072,
4046,
701,
272,
327,
4472,
12506,
883,
506,
13256,
1808,
314,
2011,
9146,
14,
339,
327,
961,
849,
4514,
10022,
314,
3486,
5560,
27,
272,
327,
9180,
1077,
4278,
636,
4077,
363,
465,
5827,
14,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1228,
8,
1848,
12,
291,
855,
533,
3368,
436,
291,
855,
807,
363,
508,
1163,
855,
807,
363,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
291,
855,
4077,
721,
1848,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
2071,
83,
16493,
450,
291,
855,
533,
4914,
354,
363,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
495,
8,
277,
430,
339,
768,
10315,
272,
347,
5461,
63,
475,
63,
1745,
8,
277,
12,
6122,
12,
2547,
304,
267,
408,
267,
11973,
6491,
376,
6122,
402,
2251,
370,
314,
1072,
2547,
14,
267,
408,
267,
986,
339,
768,
10315,
272,
347,
2248,
63,
504,
63,
1745,
8,
277,
12,
2547,
304,
267,
408,
267,
1803,
376,
6122,
402,
13256,
2251,
687,
314,
1324,
2547,
14,
267,
408,
267,
986,
339,
347,
485,
912,
63,
504,
63,
1745,
63,
7395,
63,
324,
2912,
316,
8,
277,
12,
2547,
304,
267,
408,
267,
1803,
376,
6122,
402,
13256,
19593,
334,
8147,
9,
402,
2251,
687,
314,
1324,
2547,
14,
267,
982,
314,
9146,
1630,
440,
19218,
641,
19593,
314,
849,
4514,
2529,
376,
267,
6122,
402,
2849,
1819,
5548,
14,
267,
408,
267,
372,
2341,
8,
2734,
671,
26,
359,
88,
467,
291,
14,
912,
63,
504,
63,
1745,
8,
1745,
430,
421,
199,
533,
21084,
4625,
1451,
7299,
8,
7299,
304,
272,
408,
272,
25555,
626,
14511,
2251,
465,
282,
2547,
402,
334,
1267,
12,
666,
9,
6342,
12,
272,
2382,
2582,
365,
282,
4337,
13,
2075,
3000,
436,
666,
365,
2582,
2783,
14,
272,
408,
339,
347,
5461,
63,
475,
63,
1745,
8,
277,
12,
6122,
12,
2547,
304,
267,
367,
1559,
315,
6122,
26,
288,
291,
423,
952,
63,
1045,
63,
1267,
8,
1113,
12,
2547,
9,
339,
347,
2248,
63,
504,
63,
1745,
8,
277,
12,
2547,
304,
267,
1830,
715,
26,
288,
862,
26,
355,
1995,
291,
423,
739,
63,
1045,
63,
1267,
8,
1745,
9,
288,
871,
21157,
26,
355,
372,
339,
347,
485,
952,
63,
1045,
63,
1267,
8,
277,
12,
1559,
12,
2547,
304,
267,
6380,
275,
291,
14,
4180,
8,
1113,
9,
267,
340,
6380,
365,
488,
26,
288,
746,
1722,
480,
12023,
574,
1077,
440,
506,
488,
531,
267,
340,
822,
8,
8397,
9,
690,
334,
17,
5213,
7105,
304,
288,
746,
1722,
480,
6049,
440,
8437,
909,
12142,
2419,
499,
39,
531,
267,
2218,
63,
442,
8,
552,
8,
8397,
395,
2547,
9,
267,
2547,
14,
952,
8,
8397,
9,
339,
347,
485,
739,
63,
1045,
63,
1267,
8,
277,
12,
2547,
304,
267,
2582,
275,
1586,
63,
442,
8,
1745,
9,
267,
340,
2582,
508,
12568,
4625,
83,
14,
3902,
63,
3359,
63,
3998,
63,
13835,
26,
288,
746,
21157,
267,
916,
2582,
508,
12568,
4625,
83,
14,
8084,
26,
288,
372,
488,
267,
1559,
275,
2547,
14,
739,
8,
1267,
9,
267,
340,
822,
8,
1113,
9,
665,
2582,
26,
288,
746,
21157,
267,
372,
291,
14,
3640,
8,
1113,
9,
339,
768,
10315,
272,
347,
16864,
8,
277,
12,
1559,
304,
267,
408,
267,
11973,
794,
376,
909,
1901,
282,
3696,
1625,
14,
267,
3979,
3522,
316,
365,
1202,
12,
642,
911,
506,
2797,
543,
376,
1625,
402,
2251,
14,
267,
408,
267,
986,
339,
768,
10315,
272,
347,
14404,
8,
277,
12,
1559,
304,
267,
408,
267,
1487,
3549,
376,
909,
687,
282,
3696,
1625,
14,
267,
408,
267,
986,
421,
199,
533,
31732,
7299,
8,
5894,
4625,
1451,
7299,
304,
272,
408,
272,
11973,
6491,
2251,
1808,
2018,
1159,
5927,
9146,
26,
398,
1455,
921,
4757,
14,
1548,
14,
1308,
15,
19,
15,
4342,
15,
8092,
14,
1360,
339,
961,
9146,
5171,
17429,
590,
1263,
2018,
909,
12,
1325,
1443,
272,
440,
506,
465,
7377,
465,
1655,
27877,
12506,
14,
272,
408,
339,
347,
16864,
8,
277,
12,
1559,
304,
267,
372,
5927,
14,
4180,
8,
1113,
12,
650,
9,
339,
347,
14404,
8,
277,
12,
1559,
304,
267,
372,
5927,
14,
3640,
8,
1113,
12,
2644,
628,
2394,
531,
421,
199,
533,
17206,
379,
7299,
8,
7299,
304,
272,
408,
272,
11973,
6491,
282,
2547,
402,
2251,
315,
19593,
701,
6358,
2399,
8072,
272,
25555,
543,
13788,
402,
2251,
14,
272,
408,
339,
6778,
13387,
1149,
63,
20813,
63,
4305,
275,
446,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ctbrennan/cross-platform-message-analytics
|
imessage_export.py
|
1
|
11626
|
##Author: https://github.com/alexwchan
#!/usr/bin/python
# -*- encoding: utf8 -*-
"""imessage_export.py - this script takes the chat.db or sms.db SQL database
used to store messages on OS X or iOS and spits out a set of JSON files, one
for each thread.
The script is fairly rudimentary, and doesn't do anything to catch or
compensate for errors in the SQL, or malicious input. There also isn't any
support for merging and/or incremental updates (yet).
Use at your own risk, and back up your iMessage database before proceeding.
This depends on the following modules from my drabbles/ repo:
* confirmation.py
* filesequence.py
"""
import argparse
import datetime
from collections import namedtuple
import json
import os
import re
import sqlite3
import sys
from unidecode import unidecode
import confirmation
import filesequence
#------------------------------------------------------------------------------
# Utility functions
#------------------------------------------------------------------------------
def slugify(ustr):
"""Convert Unicode string into an ASCII slug.
Written by Dr. Drang: http://www.leancrew.com/all-this/2014/10/asciifying/
"""
ustr = re.sub(u'[–—/:;,.]', '-', ustr) # replace separating punctuation
astr = unidecode(ustr).lower() # best ASCII subs, lowercase
astr = re.sub(r'[^a-z0-9 -]', '', astr) # delete any other characters
astr = astr.replace(' ', '-') # spaces to hyphens
astr = re.sub(r'-+', '-', astr) # condense repeated hyphens
return astr
def imessage_date_str(date_int):
"""Dates in iMessage are stored as an integer, which counts the number of
seconds since 1 Jan 2001. This function takes an int as input, and returns
an ISO 8601 formatted date string.
"""
start = datetime.datetime(2001, 1, 1)
diff = datetime.timedelta(seconds=int(date_int))
return str(start + diff)
def cp_attachment(src, dst):
"""Copy an attachment to the attachments/ directory. If a file by that name
already exists, use the MD5 checksum to see if they're the same, and if
not, go to the next sequential filename.
"""
if src[0] == '~':
src = os.environ['HOME'] + src[1:]
safe_dst = filesequence.safe_file_copy(src, dst)
return safe_dst
#------------------------------------------------------------------------------
# Set up namedtuple instances
#------------------------------------------------------------------------------
Attachment = namedtuple('Attachment', ['guid', 'filename'])
Message = namedtuple('Message', ['guid', 'text', 'handle_id', 'subject', 'date', 'is_from_me', 'attachments'])
def message_dict(message):
"""Convert a Message instance to a dict which can be written to JSON."""
msg_dict = dict()
msg_dict['guid'] = message.guid
msg_dict['text'] = message.text
msg_dict['handle_id'] = message.handle_id
msg_dict['date'] = message.date
msg_dict['is_from_me'] = bool(message.is_from_me)
if message.subject is not None:
msg_dict['subject'] = message.subject
if message.attachments:
msg_dict['attachments'] = message.attachments
return msg_dict
#------------------------------------------------------------------------------
# Functions for reading the SQL database
#------------------------------------------------------------------------------
def handles(cursor):
"""Returns a dict of handles that form (ROWID, id) pairs."""
sql_handles = cursor.execute("SELECT ROWID, id FROM handle").fetchall()
all_handles = dict()
for handle in sql_handles:
rowid, contact_id = handle
all_handles[rowid] = contact_id
return all_handles
def chats(cursor):
"""Returns a dict of chats that form (ROWID, guid) pairs."""
sql_chats = cursor.execute("SELECT ROWID, guid FROM chat").fetchall()
all_chats = dict()
for chat in sql_chats:
rowid, guid = chat
all_chats[rowid] = guid
return all_chats
def attachments(cursor):
"""Returns a dict of attachments, in which the keys are the ROWIDs and the
values are Attachment() namedtuple instances.
"""
sql_attachments = cursor.execute("SELECT ROWID, guid, filename "
"from attachment").fetchall()
all_attachments = dict()
for attachment in sql_attachments:
ROWID, guid, filename = attachment
new_attach = Attachment(guid, filename)
all_attachments[ROWID] = new_attach
return all_attachments
def messages(cursor):
"""Returns a dict of messages, in which the keys are the ROWIDs and the
values are Message() instances.
"""
sql_messages = cursor.execute("SELECT ROWID, guid, text, handle_id, "
"subject, date, is_from_me from "
"message").fetchall()
all_messages = dict()
for message in sql_messages:
ROWID, args = message[0], message[1:]
new_message = Message(*args, attachments=[])
all_messages[ROWID] = new_message
return all_messages
def join_table(cursor, row1, row2):
"""Returns a list of joins, in which the values are a dict of IDs from each
table. row1 and row2 must be specified in the order the table is named.
"""
sql_joins = cursor.execute("SELECT * from %s_%s_join" % (row1, row2))
all_joins = list()
for join in sql_joins:
all_joins.append(join)
return all_joins
#------------------------------------------------------------------------------
# Join everything together: given a list of messages, chats, handles and
# attachments, create a collection of human-readable threads
#------------------------------------------------------------------------------
def unify_message_threads(sql_path, output_dir):
conn = sqlite3.connect(sql_path)
cursor = conn.cursor()
all_messages = messages(cursor)
all_attachments = attachments(cursor)
attachment_dir = os.path.join(output_dir, 'attachments')
thread_dir = os.path.join(output_dir, 'threads')
for output_dir in [attachment_dir, thread_dir]:
if not os.path.isdir(output_dir):
#os.makedirs(output_dir) #permission always gets denied
os.system("sudo mkdir -p ./" + output_dir) #changed this, should work - Connor
# Go through the message_attachment_join table, and append each attachment
# to the associated message.
join_msg_attach = join_table(cursor, 'message', 'attachment')
for join in join_msg_attach:
msg_id, attach_id = join
msg = all_messages[msg_id]
new_attachment = all_attachments[attach_id]
# Update the list of attachments
updated_attachments = msg.attachments
updated_attachments.append(new_attachment)
msg = msg._replace(attachments=updated_attachments)
all_messages[msg_id] = msg
# Replace the handle_id in each Message instance with the actual handle,
# and then discard the all_handles list: we won't use it again
all_handles = handles(cursor)
group_msgs_rowids = list()
for ROWID in all_messages:
msg = all_messages[ROWID]
# For reasons unknown, anything in a group message has handle_id 0. I
# haven't worked out how to work out who sent a particular message, so
# for now I'm just dropping anything with handle_id 0.
try:
true_handle = all_handles[msg.handle_id]
except KeyError:
group_msgs_rowids.append(ROWID)
continue
msg = msg._replace(handle_id=true_handle)
# While we're going through the messages, let's also replace the date
# string with something more human friendly
msg = msg._replace(date=imessage_date_str(msg.date))
# And we'll copy all the attachments into an 'attachments' folder to
# make them easier to find
"""
new_attachments = []
for attachment in msg.attachments:
dst = cp_attachment(attachment.filename, attachment_dir)
new_attachments.append(os.path.basename(dst))
msg = msg._replace(attachments=new_attachments)
"""
all_messages[ROWID] = msg
# Clean up all the group messages
for ROWID in group_msgs_rowids:
del all_messages[ROWID]
# Create a list of threads, go through and assign messages to that thread
all_threads = dict()
all_chats = chats(cursor)
join_chat_message = join_table(cursor, 'chat', 'message')
for join in join_chat_message:
chat_id, msg_id = join
chat_guid = all_chats[chat_id]
# Skip group messages
try:
msg = message_dict(all_messages[msg_id])
except KeyError:
continue
chat_messages = all_threads.get(chat_guid, [])
chat_messages.append(msg)
all_threads[chat_guid] = chat_messages
return all_threads
#------------------------------------------------------------------------------
# Mainline program flow
#------------------------------------------------------------------------------
def main(sql_path, output_dir):
"""Main program flow. This function gets input from the user about where
the SQL database is and where to save the files, checks that it's not about
to overwrite any existing exports
"""
"""
#--------------------------------------------------------------------------
# Set up the options for argparse
#--------------------------------------------------------------------------
parser = argparse.ArgumentParser(
description="A script for exporting threads and attachments from the "
"iMessage database to JSON.",
epilog="You should back up your iMessage database BEFORE using this "
"script. I am not responsible for any damage caused to your "
"database by this script."
)
parser.add_argument('-i', '--input', dest='sql_path',
help="path to the chat.db or sms.db SQL file from "
"the iMessage database")
parser.add_argument('-o', '--output', dest='output_dir',
help="path to the output directory to write the "
"thread and attachment data")
args = parser.parse_args()
"""
#--------------------------------------------------------------------------
# Validate user input: check that we have both an input and output file,
# that the input file exists, and that we don't already have export in
# the output directory.
#--------------------------------------------------------------------------
if (sql_path is None) and (output_dir is None):
print("Use the -h or --help flag for a help message.")
sys.exit(1)
if (sql_path is None) or (output_dir is None):
print("Please supply both --input and --output arguments. Use the -h "
"or --help flag for a help message.")
sys.exit(1)
if not os.path.exists(sql_path):
print("The database file %s does not exist." % sql_path)
sys.exit(1)
attach_dir = os.path.join(output_dir, 'attachments')
thread_dir = os.path.join(output_dir, 'threads')
os.system("sudo mkdir -p " + attach_dir) #had to add these
os.system("sudo mkdir -p " + thread_dir) #had to add these
os.system("sudo chmod -R 777 " + attach_dir) #had to add these
os.system("sudo chmod -R 777 " + thread_dir) #had to add these
if os.path.isdir(attach_dir) or os.path.isdir(thread_dir):
result = confirmation.twostep_confirm(
"There is already an export of the iMessage database in the "
"directory %s. Part of this export may be overwritten if you "
"proceed with the script." % output_dir,
'continue'
)
if not result:
print("Okay, stopping. Nothing has been changed.")
sys.exit(1)
#--------------------------------------------------------------------------
# Assuming we've validated the output, go ahead and export the database.
#--------------------------------------------------------------------------
unified_threads = unify_message_threads(sql_path, output_dir)
#for thread_guid, messages in unified_threads.iteritems():
for thread_guid, messages in unified_threads.items():
output_dict = dict({
'guid': thread_guid,
'messages': messages
})
outfile = os.path.join(thread_dir,
"thread_%s.json" % slugify(thread_guid))
with open(outfile, 'w') as ff:
json.dump(output_dict, ff, sort_keys=True, indent=2)
if __name__ == '__main__':
main()
|
mit
|
[
309,
5949,
26,
4178,
921,
5031,
14,
957,
15,
24421,
87,
11984,
199,
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2644,
26,
2774,
24,
1882,
199,
624,
1036,
712,
63,
3790,
14,
647,
446,
642,
2884,
6181,
314,
21472,
14,
697,
503,
308,
706,
14,
697,
5385,
3050,
199,
2972,
370,
3877,
3788,
641,
4403,
1323,
503,
284,
3100,
436,
2249,
1405,
734,
282,
663,
402,
4840,
1584,
12,
1373,
199,
509,
1924,
2462,
14,
199,
199,
1918,
2884,
365,
28092,
590,
519,
14525,
434,
695,
12,
436,
3181,
1133,
886,
7003,
370,
8579,
503,
199,
863,
8764,
323,
367,
2552,
315,
314,
5385,
12,
503,
333,
17999,
17326,
1324,
14,
6006,
2597,
5712,
1133,
1263,
199,
4058,
367,
22537,
436,
15,
269,
16316,
7029,
334,
28064,
680,
199,
199,
6119,
737,
2195,
5705,
22633,
12,
436,
1771,
1536,
2195,
284,
2209,
3050,
2544,
20320,
316,
14,
199,
199,
2765,
8350,
641,
314,
2569,
4621,
687,
3002,
366,
14411,
830,
83,
15,
3831,
26,
199,
10,
18791,
14,
647,
199,
10,
570,
4041,
14,
647,
199,
624,
199,
199,
646,
7534,
199,
646,
2197,
199,
504,
5055,
492,
12863,
199,
646,
2022,
199,
646,
747,
199,
646,
295,
199,
646,
11723,
19,
199,
646,
984,
199,
504,
625,
2655,
600,
492,
625,
2655,
600,
199,
199,
646,
18791,
199,
646,
570,
4041,
199,
199,
20974,
199,
3,
20511,
3423,
199,
20974,
199,
318,
29864,
8,
11409,
304,
199,
198,
624,
7306,
6140,
1059,
1901,
376,
10485,
8889,
14,
421,
198,
32329,
701,
577,
82,
14,
577,
82,
621,
26,
1455,
921,
1544,
14,
1270,
1353,
87,
14,
957,
15,
452,
13,
3749,
15,
7280,
15,
709,
15,
305,
559,
2021,
316,
15,
199,
198,
624,
199,
198,
11409,
275,
295,
14,
954,
8,
85,
3894,
8477,
242,
20292,
22075,
27,
18485,
4300,
17525,
399,
495,
9,
257,
327,
3350,
4216,
1958,
22929,
199,
198,
65,
495,
275,
625,
2655,
600,
8,
11409,
680,
2325,
342,
3698,
327,
5526,
10485,
13868,
12,
12141,
199,
198,
65,
495,
275,
295,
14,
954,
8,
82,
16122,
65,
13,
90,
16,
13,
25,
446,
4300,
3260,
282,
495,
9,
221,
327,
3145,
1263,
1163,
4110,
199,
198,
65,
495,
275,
282,
495,
14,
1814,
360,
1656,
26942,
3322,
327,
7883,
370,
7188,
27920,
199,
198,
65,
495,
275,
295,
14,
954,
8,
82,
7,
6793,
297,
17525,
282,
495,
9,
3515,
327,
406,
7253,
10877,
7188,
27920,
199,
198,
1107,
282,
495,
199,
199,
318,
284,
1188,
63,
602,
63,
495,
8,
602,
63,
442,
304,
199,
198,
624,
36,
2335,
315,
284,
2209,
787,
5489,
465,
376,
3000,
12,
1314,
8242,
314,
1329,
402,
199,
198,
4515,
3967,
413,
17474,
12521,
14,
961,
805,
6181,
376,
1109,
465,
1324,
12,
436,
2529,
199,
198,
290,
9055,
10300,
614,
7871,
1434,
1059,
14,
199,
198,
624,
199,
198,
928,
275,
2197,
14,
2083,
8,
8339,
12,
413,
12,
413,
9,
199,
198,
3028,
275,
2197,
14,
7473,
8,
4515,
29,
442,
8,
602,
63,
442,
430,
199,
198,
1107,
620,
8,
928,
435,
3915,
9,
199,
199,
318,
7667,
63,
8905,
8,
2164,
12,
5042,
304,
199,
198,
624,
5116,
376,
12193,
370,
314,
18912,
15,
2082,
14,
982,
282,
570,
701,
626,
536,
199,
198,
14039,
3495,
12,
675,
314,
15830,
21,
9040,
370,
1937,
340,
2985,
3984,
314,
2011,
12,
436,
340,
199,
198,
1397,
12,
2621,
370,
314,
2163,
23381,
1788,
14,
199,
198,
624,
199,
198,
692,
2928,
59,
16,
61,
508,
17352,
356,
507,
198,
2164,
275,
747,
14,
2314,
459,
9524,
418,
435,
2928,
59,
17,
2938,
199,
198,
3489,
63,
5119,
275,
570,
4041,
14,
3489,
63,
493,
63,
1574,
8,
2164,
12,
5042,
9,
199,
198,
1107,
5048,
63,
5119,
199,
199,
20974,
199,
3,
2494,
1536,
12863,
4454,
199,
20974,
199,
22662,
275,
12863,
360,
22662,
297,
788,
9473,
297,
283,
1501,
1105,
199,
2209,
275,
12863,
360,
2209,
297,
788,
9473,
297,
283,
505,
297,
283,
2479,
63,
344,
297,
283,
5875,
297,
283,
602,
297,
283,
374,
63,
504,
63,
278,
297,
283,
15855,
1105,
199,
199,
318,
1245,
63,
807,
8,
1188,
304,
199,
198,
624,
7306,
282,
6430,
1256,
370,
282,
1211,
1314,
883,
506,
5313,
370,
4840,
1041,
199,
198,
1328,
63,
807,
275,
1211,
342,
421,
198,
1328,
63,
807,
459,
9473,
418,
275,
1245,
14,
9473,
199,
198,
1328,
63,
807,
459,
505,
418,
275,
1245,
14,
505,
199,
198,
1328,
63,
807,
459,
2479,
63,
344,
418,
275,
1245,
14,
2479,
63,
344,
199,
198,
1328,
63,
807,
459,
602,
418,
275,
1245,
14,
602,
199,
198,
1328,
63,
807,
459,
374,
63,
504,
63,
278,
418,
275,
2155,
8,
1188,
14,
374,
63,
504,
63,
278,
9,
421,
198,
692,
1245,
14,
5875,
365,
440,
488,
26,
507,
198,
1328,
63,
807,
459,
5875,
418,
275,
1245,
14,
5875,
421,
198,
692,
1245,
14,
15855,
26,
507,
198,
1328,
63,
807,
459,
15855,
418,
275,
1245,
14,
15855,
421,
198,
1107,
1499,
63,
807,
199,
199,
20974,
199,
3,
17471,
367,
7664,
314,
5385,
3050,
199,
20974,
199,
318,
10022,
8,
3937,
304,
199,
198,
624,
3407,
282,
1211,
402,
10022,
626,
1824,
334,
1092,
9845,
12,
1305,
9,
6342,
1041,
199,
198,
3009,
63,
16947,
275,
3920,
14,
2526,
480,
4859,
9769,
9845,
12,
1305,
4442,
2429,
3471,
10174,
342,
199,
198,
452,
63,
16947,
275,
1211,
342,
421,
198,
509,
2429,
315,
3875,
63,
16947,
26,
507,
198,
29450,
12,
8966,
63,
344,
275,
2429,
507,
198,
452,
63,
16947,
59,
29450,
61,
275,
8966,
63,
344,
421,
198,
1107,
1006,
63,
16947,
199,
199,
318,
682,
1956,
8,
3937,
304,
199,
198,
624,
3407,
282,
1211,
402,
682,
1956,
626,
1824,
334,
1092,
9845,
12,
15593,
9,
6342,
1041,
199,
198,
3009,
63,
335,
1956,
275,
3920,
14,
2526,
480,
4859,
9769,
9845,
12,
15593,
4442,
21472,
3471,
10174,
342,
199,
198,
452,
63,
335,
1956,
275,
1211,
342,
421,
198,
509,
21472,
315,
3875,
63,
335,
1956,
26,
507,
198,
29450,
12,
15593,
275,
21472,
507,
198,
452,
63,
335,
1956,
59,
29450,
61
] |
[
5949,
26,
4178,
921,
5031,
14,
957,
15,
24421,
87,
11984,
199,
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2644,
26,
2774,
24,
1882,
199,
624,
1036,
712,
63,
3790,
14,
647,
446,
642,
2884,
6181,
314,
21472,
14,
697,
503,
308,
706,
14,
697,
5385,
3050,
199,
2972,
370,
3877,
3788,
641,
4403,
1323,
503,
284,
3100,
436,
2249,
1405,
734,
282,
663,
402,
4840,
1584,
12,
1373,
199,
509,
1924,
2462,
14,
199,
199,
1918,
2884,
365,
28092,
590,
519,
14525,
434,
695,
12,
436,
3181,
1133,
886,
7003,
370,
8579,
503,
199,
863,
8764,
323,
367,
2552,
315,
314,
5385,
12,
503,
333,
17999,
17326,
1324,
14,
6006,
2597,
5712,
1133,
1263,
199,
4058,
367,
22537,
436,
15,
269,
16316,
7029,
334,
28064,
680,
199,
199,
6119,
737,
2195,
5705,
22633,
12,
436,
1771,
1536,
2195,
284,
2209,
3050,
2544,
20320,
316,
14,
199,
199,
2765,
8350,
641,
314,
2569,
4621,
687,
3002,
366,
14411,
830,
83,
15,
3831,
26,
199,
10,
18791,
14,
647,
199,
10,
570,
4041,
14,
647,
199,
624,
199,
199,
646,
7534,
199,
646,
2197,
199,
504,
5055,
492,
12863,
199,
646,
2022,
199,
646,
747,
199,
646,
295,
199,
646,
11723,
19,
199,
646,
984,
199,
504,
625,
2655,
600,
492,
625,
2655,
600,
199,
199,
646,
18791,
199,
646,
570,
4041,
199,
199,
20974,
199,
3,
20511,
3423,
199,
20974,
199,
318,
29864,
8,
11409,
304,
199,
198,
624,
7306,
6140,
1059,
1901,
376,
10485,
8889,
14,
421,
198,
32329,
701,
577,
82,
14,
577,
82,
621,
26,
1455,
921,
1544,
14,
1270,
1353,
87,
14,
957,
15,
452,
13,
3749,
15,
7280,
15,
709,
15,
305,
559,
2021,
316,
15,
199,
198,
624,
199,
198,
11409,
275,
295,
14,
954,
8,
85,
3894,
8477,
242,
20292,
22075,
27,
18485,
4300,
17525,
399,
495,
9,
257,
327,
3350,
4216,
1958,
22929,
199,
198,
65,
495,
275,
625,
2655,
600,
8,
11409,
680,
2325,
342,
3698,
327,
5526,
10485,
13868,
12,
12141,
199,
198,
65,
495,
275,
295,
14,
954,
8,
82,
16122,
65,
13,
90,
16,
13,
25,
446,
4300,
3260,
282,
495,
9,
221,
327,
3145,
1263,
1163,
4110,
199,
198,
65,
495,
275,
282,
495,
14,
1814,
360,
1656,
26942,
3322,
327,
7883,
370,
7188,
27920,
199,
198,
65,
495,
275,
295,
14,
954,
8,
82,
7,
6793,
297,
17525,
282,
495,
9,
3515,
327,
406,
7253,
10877,
7188,
27920,
199,
198,
1107,
282,
495,
199,
199,
318,
284,
1188,
63,
602,
63,
495,
8,
602,
63,
442,
304,
199,
198,
624,
36,
2335,
315,
284,
2209,
787,
5489,
465,
376,
3000,
12,
1314,
8242,
314,
1329,
402,
199,
198,
4515,
3967,
413,
17474,
12521,
14,
961,
805,
6181,
376,
1109,
465,
1324,
12,
436,
2529,
199,
198,
290,
9055,
10300,
614,
7871,
1434,
1059,
14,
199,
198,
624,
199,
198,
928,
275,
2197,
14,
2083,
8,
8339,
12,
413,
12,
413,
9,
199,
198,
3028,
275,
2197,
14,
7473,
8,
4515,
29,
442,
8,
602,
63,
442,
430,
199,
198,
1107,
620,
8,
928,
435,
3915,
9,
199,
199,
318,
7667,
63,
8905,
8,
2164,
12,
5042,
304,
199,
198,
624,
5116,
376,
12193,
370,
314,
18912,
15,
2082,
14,
982,
282,
570,
701,
626,
536,
199,
198,
14039,
3495,
12,
675,
314,
15830,
21,
9040,
370,
1937,
340,
2985,
3984,
314,
2011,
12,
436,
340,
199,
198,
1397,
12,
2621,
370,
314,
2163,
23381,
1788,
14,
199,
198,
624,
199,
198,
692,
2928,
59,
16,
61,
508,
17352,
356,
507,
198,
2164,
275,
747,
14,
2314,
459,
9524,
418,
435,
2928,
59,
17,
2938,
199,
198,
3489,
63,
5119,
275,
570,
4041,
14,
3489,
63,
493,
63,
1574,
8,
2164,
12,
5042,
9,
199,
198,
1107,
5048,
63,
5119,
199,
199,
20974,
199,
3,
2494,
1536,
12863,
4454,
199,
20974,
199,
22662,
275,
12863,
360,
22662,
297,
788,
9473,
297,
283,
1501,
1105,
199,
2209,
275,
12863,
360,
2209,
297,
788,
9473,
297,
283,
505,
297,
283,
2479,
63,
344,
297,
283,
5875,
297,
283,
602,
297,
283,
374,
63,
504,
63,
278,
297,
283,
15855,
1105,
199,
199,
318,
1245,
63,
807,
8,
1188,
304,
199,
198,
624,
7306,
282,
6430,
1256,
370,
282,
1211,
1314,
883,
506,
5313,
370,
4840,
1041,
199,
198,
1328,
63,
807,
275,
1211,
342,
421,
198,
1328,
63,
807,
459,
9473,
418,
275,
1245,
14,
9473,
199,
198,
1328,
63,
807,
459,
505,
418,
275,
1245,
14,
505,
199,
198,
1328,
63,
807,
459,
2479,
63,
344,
418,
275,
1245,
14,
2479,
63,
344,
199,
198,
1328,
63,
807,
459,
602,
418,
275,
1245,
14,
602,
199,
198,
1328,
63,
807,
459,
374,
63,
504,
63,
278,
418,
275,
2155,
8,
1188,
14,
374,
63,
504,
63,
278,
9,
421,
198,
692,
1245,
14,
5875,
365,
440,
488,
26,
507,
198,
1328,
63,
807,
459,
5875,
418,
275,
1245,
14,
5875,
421,
198,
692,
1245,
14,
15855,
26,
507,
198,
1328,
63,
807,
459,
15855,
418,
275,
1245,
14,
15855,
421,
198,
1107,
1499,
63,
807,
199,
199,
20974,
199,
3,
17471,
367,
7664,
314,
5385,
3050,
199,
20974,
199,
318,
10022,
8,
3937,
304,
199,
198,
624,
3407,
282,
1211,
402,
10022,
626,
1824,
334,
1092,
9845,
12,
1305,
9,
6342,
1041,
199,
198,
3009,
63,
16947,
275,
3920,
14,
2526,
480,
4859,
9769,
9845,
12,
1305,
4442,
2429,
3471,
10174,
342,
199,
198,
452,
63,
16947,
275,
1211,
342,
421,
198,
509,
2429,
315,
3875,
63,
16947,
26,
507,
198,
29450,
12,
8966,
63,
344,
275,
2429,
507,
198,
452,
63,
16947,
59,
29450,
61,
275,
8966,
63,
344,
421,
198,
1107,
1006,
63,
16947,
199,
199,
318,
682,
1956,
8,
3937,
304,
199,
198,
624,
3407,
282,
1211,
402,
682,
1956,
626,
1824,
334,
1092,
9845,
12,
15593,
9,
6342,
1041,
199,
198,
3009,
63,
335,
1956,
275,
3920,
14,
2526,
480,
4859,
9769,
9845,
12,
15593,
4442,
21472,
3471,
10174,
342,
199,
198,
452,
63,
335,
1956,
275,
1211,
342,
421,
198,
509,
21472,
315,
3875,
63,
335,
1956,
26,
507,
198,
29450,
12,
15593,
275,
21472,
507,
198,
452,
63,
335,
1956,
59,
29450,
61,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
EasonYi/thrift
|
lib/py/src/transport/THttpClient.py
|
53
|
4251
|
#
# 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 httplib
import os
import socket
import sys
import urllib
import urlparse
import warnings
from cStringIO import StringIO
from TTransport import *
class THttpClient(TTransportBase):
"""Http implementation of TTransport base."""
def __init__(self, uri_or_host, port=None, path=None):
"""THttpClient supports two different types constructor parameters.
THttpClient(host, port, path) - deprecated
THttpClient(uri)
Only the second supports https.
"""
if port is not None:
warnings.warn(
"Please use the THttpClient('http://host:port/path') syntax",
DeprecationWarning,
stacklevel=2)
self.host = uri_or_host
self.port = port
assert path
self.path = path
self.scheme = 'http'
else:
parsed = urlparse.urlparse(uri_or_host)
self.scheme = parsed.scheme
assert self.scheme in ('http', 'https')
if self.scheme == 'http':
self.port = parsed.port or httplib.HTTP_PORT
elif self.scheme == 'https':
self.port = parsed.port or httplib.HTTPS_PORT
self.host = parsed.hostname
self.path = parsed.path
if parsed.query:
self.path += '?%s' % parsed.query
self.__wbuf = StringIO()
self.__http = None
self.__timeout = None
self.__custom_headers = None
def open(self):
if self.scheme == 'http':
self.__http = httplib.HTTP(self.host, self.port)
else:
self.__http = httplib.HTTPS(self.host, self.port)
def close(self):
self.__http.close()
self.__http = None
def isOpen(self):
return self.__http is not None
def setTimeout(self, ms):
if not hasattr(socket, 'getdefaulttimeout'):
raise NotImplementedError
if ms is None:
self.__timeout = None
else:
self.__timeout = ms / 1000.0
def setCustomHeaders(self, headers):
self.__custom_headers = headers
def read(self, sz):
return self.__http.file.read(sz)
def write(self, buf):
self.__wbuf.write(buf)
def __withTimeout(f):
def _f(*args, **kwargs):
orig_timeout = socket.getdefaulttimeout()
socket.setdefaulttimeout(args[0].__timeout)
try:
result = f(*args, **kwargs)
finally:
socket.setdefaulttimeout(orig_timeout)
return result
return _f
def flush(self):
if self.isOpen():
self.close()
self.open()
# Pull data out of buffer
data = self.__wbuf.getvalue()
self.__wbuf = StringIO()
# HTTP request
self.__http.putrequest('POST', self.path)
# Write headers
self.__http.putheader('Host', self.host)
self.__http.putheader('Content-Type', 'application/x-thrift')
self.__http.putheader('Content-Length', str(len(data)))
if not self.__custom_headers or 'User-Agent' not in self.__custom_headers:
user_agent = 'Python/THttpClient'
script = os.path.basename(sys.argv[0])
if script:
user_agent = '%s (%s)' % (user_agent, urllib.quote(script))
self.__http.putheader('User-Agent', user_agent)
if self.__custom_headers:
for key, val in self.__custom_headers.iteritems():
self.__http.putheader(key, val)
self.__http.endheaders()
# Write payload
self.__http.send(data)
# Get reply to flush the request
self.code, self.message, self.headers = self.__http.getreply()
# Decorate if we know how to timeout
if hasattr(socket, 'getdefaulttimeout'):
flush = __withTimeout(flush)
|
apache-2.0
|
[
3,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
3,
199,
199,
646,
8809,
199,
646,
747,
199,
646,
2838,
199,
646,
984,
199,
646,
4011,
199,
646,
7097,
199,
646,
3598,
199,
199,
504,
15073,
492,
5228,
199,
199,
504,
19391,
492,
627,
421,
199,
533,
4221,
3370,
3041,
8,
1481,
4808,
1563,
304,
523,
408,
5779,
4514,
402,
19391,
1300,
1041,
819,
347,
636,
826,
721,
277,
12,
5108,
63,
269,
63,
1102,
12,
1844,
29,
403,
12,
931,
29,
403,
304,
272,
408,
2080,
3370,
3041,
5171,
2877,
3365,
2943,
3787,
2633,
14,
339,
4221,
3370,
3041,
8,
1102,
12,
1844,
12,
931,
9,
446,
5906,
272,
4221,
3370,
3041,
8,
2302,
9,
339,
5972,
314,
3499,
5171,
4178,
14,
272,
408,
272,
340,
1844,
365,
440,
488,
26,
489,
3598,
14,
4050,
8,
267,
298,
8254,
675,
314,
4221,
3370,
3041,
360,
1014,
921,
1102,
26,
719,
15,
515,
358,
6302,
401,
267,
13413,
12,
267,
13232,
29,
18,
9,
489,
291,
14,
1102,
275,
5108,
63,
269,
63,
1102,
489,
291,
14,
719,
275,
1844,
489,
702,
931,
489,
291,
14,
515,
275,
931,
489,
291,
14,
5512,
275,
283,
1014,
7,
272,
587,
26,
489,
4565,
275,
7097,
14,
10290,
8,
2302,
63,
269,
63,
1102,
9,
489,
291,
14,
5512,
275,
4565,
14,
5512,
489,
702,
291,
14,
5512,
315,
661,
1014,
297,
283,
2859,
358,
489,
340,
291,
14,
5512,
508,
283,
1014,
356,
267,
291,
14,
719,
275,
4565,
14,
719,
503,
8809,
14,
2856,
63,
3657,
489,
916,
291,
14,
5512,
508,
283,
2859,
356,
267,
291,
14,
719,
275,
4565,
14,
719,
503,
8809,
14,
14921,
63,
3657,
489,
291,
14,
1102,
275,
4565,
14,
4269,
489,
291,
14,
515,
275,
4565,
14,
515,
489,
340,
4565,
14,
1131,
26,
267,
291,
14,
515,
847,
8720,
5,
83,
7,
450,
4565,
14,
1131,
272,
291,
855,
87,
1436,
275,
5228,
342,
272,
291,
855,
1014,
275,
488,
272,
291,
855,
2593,
275,
488,
272,
291,
855,
4229,
63,
2139,
275,
488,
819,
347,
1551,
8,
277,
304,
272,
340,
291,
14,
5512,
508,
283,
1014,
356,
489,
291,
855,
1014,
275,
8809,
14,
2856,
8,
277,
14,
1102,
12,
291,
14,
719,
9,
272,
587,
26,
489,
291,
855,
1014,
275,
8809,
14,
14921,
8,
277,
14,
1102,
12,
291,
14,
719,
9,
819,
347,
4002,
8,
277,
304,
272,
291,
855,
1014,
14,
1600,
342,
272,
291,
855,
1014,
275,
488,
819,
347,
365,
4299,
8,
277,
304,
272,
372,
291,
855,
1014,
365,
440,
488,
819,
347,
663,
6372,
8,
277,
12,
6605,
304,
272,
340,
440,
2688,
8,
3450,
12,
283,
362,
885,
2593,
735,
489,
746,
4279,
339,
340,
6605,
365,
488,
26,
489,
291,
855,
2593,
275,
488,
272,
587,
26,
489,
291,
855,
2593,
275,
6605,
1182,
5198,
14,
16,
819,
347,
663,
7223,
9883,
8,
277,
12,
2323,
304,
272,
291,
855,
4229,
63,
2139,
275,
2323,
819,
347,
1586,
8,
277,
12,
17176,
304,
272,
372,
291,
855,
1014,
14,
493,
14,
739,
8,
11803,
9,
819,
347,
2218,
8,
277,
12,
4123,
304,
272,
291,
855,
87,
1436,
14,
952,
8,
1436,
9,
819,
347,
636,
1045,
6372,
8,
70,
304,
272,
347,
485,
70,
2031,
589,
12,
1011,
958,
304,
489,
2306,
63,
2593,
275,
2838,
14,
362,
885,
2593,
342,
489,
2838,
14,
5486,
2593,
8,
589,
59,
16,
17979,
2593,
9,
489,
862,
26,
267,
754,
275,
289,
2031,
589,
12,
1011,
958,
9,
489,
3753,
26,
267,
2838,
14,
5486,
2593,
8,
2981,
63,
2593,
9,
489,
372,
754,
272,
372,
485,
70,
819,
347,
8976,
8,
277,
304,
272,
340,
291,
14,
374,
4299,
837,
489,
291,
14,
1600,
342,
272,
291,
14,
1490,
342,
339,
327,
27705,
666,
734,
402,
3335,
272,
666,
275,
291,
855,
87,
1436,
14,
7150,
342,
272,
291,
855,
87,
1436,
275,
5228,
342,
339,
327,
3101,
1056,
272,
291,
855,
1014,
14,
524,
1069,
360,
4030,
297,
291,
14,
515,
9,
339,
327,
6990,
2323,
272,
291,
855,
1014,
14,
31233,
360,
4965,
297,
291,
14,
1102,
9,
272,
291,
855,
1014,
14,
31233,
360,
2714,
13,
804,
297,
283,
3578,
15,
88,
13,
8430,
358,
272,
291,
855,
1014,
14,
31233,
360,
2714,
13,
4625,
297,
620,
8,
552,
8,
576,
1724,
339,
340,
440,
291,
855,
4229,
63,
2139,
503,
283,
1899,
13,
7788,
7,
440,
315,
291,
855,
4229,
63,
2139,
26,
489,
922,
63,
4054,
275,
283,
4718,
15,
2080,
3370,
3041,
7,
489,
2884,
275,
747,
14,
515,
14,
4846,
8,
1274,
14,
3020,
59,
16,
566,
489,
340,
2884,
26,
267,
922,
63,
4054,
275,
1543,
83,
4366,
83,
3171,
450,
334,
751,
63,
4054,
12,
4011,
14,
3513,
8,
1579,
430,
489,
291,
855,
1014,
14,
31233,
360,
1899,
13,
7788,
297,
922,
63,
4054,
9,
339,
340,
291,
855,
4229,
63,
2139,
26,
267,
367,
790,
12,
1139,
315,
291,
855,
4229,
63,
2139,
14,
4611,
837,
288,
291,
855,
1014,
14,
31233,
8,
498,
12,
1139,
9,
339,
291,
855,
1014,
14,
500
] |
[
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
3,
199,
199,
646,
8809,
199,
646,
747,
199,
646,
2838,
199,
646,
984,
199,
646,
4011,
199,
646,
7097,
199,
646,
3598,
199,
199,
504,
15073,
492,
5228,
199,
199,
504,
19391,
492,
627,
421,
199,
533,
4221,
3370,
3041,
8,
1481,
4808,
1563,
304,
523,
408,
5779,
4514,
402,
19391,
1300,
1041,
819,
347,
636,
826,
721,
277,
12,
5108,
63,
269,
63,
1102,
12,
1844,
29,
403,
12,
931,
29,
403,
304,
272,
408,
2080,
3370,
3041,
5171,
2877,
3365,
2943,
3787,
2633,
14,
339,
4221,
3370,
3041,
8,
1102,
12,
1844,
12,
931,
9,
446,
5906,
272,
4221,
3370,
3041,
8,
2302,
9,
339,
5972,
314,
3499,
5171,
4178,
14,
272,
408,
272,
340,
1844,
365,
440,
488,
26,
489,
3598,
14,
4050,
8,
267,
298,
8254,
675,
314,
4221,
3370,
3041,
360,
1014,
921,
1102,
26,
719,
15,
515,
358,
6302,
401,
267,
13413,
12,
267,
13232,
29,
18,
9,
489,
291,
14,
1102,
275,
5108,
63,
269,
63,
1102,
489,
291,
14,
719,
275,
1844,
489,
702,
931,
489,
291,
14,
515,
275,
931,
489,
291,
14,
5512,
275,
283,
1014,
7,
272,
587,
26,
489,
4565,
275,
7097,
14,
10290,
8,
2302,
63,
269,
63,
1102,
9,
489,
291,
14,
5512,
275,
4565,
14,
5512,
489,
702,
291,
14,
5512,
315,
661,
1014,
297,
283,
2859,
358,
489,
340,
291,
14,
5512,
508,
283,
1014,
356,
267,
291,
14,
719,
275,
4565,
14,
719,
503,
8809,
14,
2856,
63,
3657,
489,
916,
291,
14,
5512,
508,
283,
2859,
356,
267,
291,
14,
719,
275,
4565,
14,
719,
503,
8809,
14,
14921,
63,
3657,
489,
291,
14,
1102,
275,
4565,
14,
4269,
489,
291,
14,
515,
275,
4565,
14,
515,
489,
340,
4565,
14,
1131,
26,
267,
291,
14,
515,
847,
8720,
5,
83,
7,
450,
4565,
14,
1131,
272,
291,
855,
87,
1436,
275,
5228,
342,
272,
291,
855,
1014,
275,
488,
272,
291,
855,
2593,
275,
488,
272,
291,
855,
4229,
63,
2139,
275,
488,
819,
347,
1551,
8,
277,
304,
272,
340,
291,
14,
5512,
508,
283,
1014,
356,
489,
291,
855,
1014,
275,
8809,
14,
2856,
8,
277,
14,
1102,
12,
291,
14,
719,
9,
272,
587,
26,
489,
291,
855,
1014,
275,
8809,
14,
14921,
8,
277,
14,
1102,
12,
291,
14,
719,
9,
819,
347,
4002,
8,
277,
304,
272,
291,
855,
1014,
14,
1600,
342,
272,
291,
855,
1014,
275,
488,
819,
347,
365,
4299,
8,
277,
304,
272,
372,
291,
855,
1014,
365,
440,
488,
819,
347,
663,
6372,
8,
277,
12,
6605,
304,
272,
340,
440,
2688,
8,
3450,
12,
283,
362,
885,
2593,
735,
489,
746,
4279,
339,
340,
6605,
365,
488,
26,
489,
291,
855,
2593,
275,
488,
272,
587,
26,
489,
291,
855,
2593,
275,
6605,
1182,
5198,
14,
16,
819,
347,
663,
7223,
9883,
8,
277,
12,
2323,
304,
272,
291,
855,
4229,
63,
2139,
275,
2323,
819,
347,
1586,
8,
277,
12,
17176,
304,
272,
372,
291,
855,
1014,
14,
493,
14,
739,
8,
11803,
9,
819,
347,
2218,
8,
277,
12,
4123,
304,
272,
291,
855,
87,
1436,
14,
952,
8,
1436,
9,
819,
347,
636,
1045,
6372,
8,
70,
304,
272,
347,
485,
70,
2031,
589,
12,
1011,
958,
304,
489,
2306,
63,
2593,
275,
2838,
14,
362,
885,
2593,
342,
489,
2838,
14,
5486,
2593,
8,
589,
59,
16,
17979,
2593,
9,
489,
862,
26,
267,
754,
275,
289,
2031,
589,
12,
1011,
958,
9,
489,
3753,
26,
267,
2838,
14,
5486,
2593,
8,
2981,
63,
2593,
9,
489,
372,
754,
272,
372,
485,
70,
819,
347,
8976,
8,
277,
304,
272,
340,
291,
14,
374,
4299,
837,
489,
291,
14,
1600,
342,
272,
291,
14,
1490,
342,
339,
327,
27705,
666,
734,
402,
3335,
272,
666,
275,
291,
855,
87,
1436,
14,
7150,
342,
272,
291,
855,
87,
1436,
275,
5228,
342,
339,
327,
3101,
1056,
272,
291,
855,
1014,
14,
524,
1069,
360,
4030,
297,
291,
14,
515,
9,
339,
327,
6990,
2323,
272,
291,
855,
1014,
14,
31233,
360,
4965,
297,
291,
14,
1102,
9,
272,
291,
855,
1014,
14,
31233,
360,
2714,
13,
804,
297,
283,
3578,
15,
88,
13,
8430,
358,
272,
291,
855,
1014,
14,
31233,
360,
2714,
13,
4625,
297,
620,
8,
552,
8,
576,
1724,
339,
340,
440,
291,
855,
4229,
63,
2139,
503,
283,
1899,
13,
7788,
7,
440,
315,
291,
855,
4229,
63,
2139,
26,
489,
922,
63,
4054,
275,
283,
4718,
15,
2080,
3370,
3041,
7,
489,
2884,
275,
747,
14,
515,
14,
4846,
8,
1274,
14,
3020,
59,
16,
566,
489,
340,
2884,
26,
267,
922,
63,
4054,
275,
1543,
83,
4366,
83,
3171,
450,
334,
751,
63,
4054,
12,
4011,
14,
3513,
8,
1579,
430,
489,
291,
855,
1014,
14,
31233,
360,
1899,
13,
7788,
297,
922,
63,
4054,
9,
339,
340,
291,
855,
4229,
63,
2139,
26,
267,
367,
790,
12,
1139,
315,
291,
855,
4229,
63,
2139,
14,
4611,
837,
288,
291,
855,
1014,
14,
31233,
8,
498,
12,
1139,
9,
339,
291,
855,
1014,
14,
500,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
bob123bob/Sick-Beard
|
lib/requests/packages/chardet/chardistribution.py
|
215
|
8602
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Communicator client code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - port to Python
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
import constants
from euctwfreq import EUCTWCharToFreqOrder, EUCTW_TABLE_SIZE, EUCTW_TYPICAL_DISTRIBUTION_RATIO
from euckrfreq import EUCKRCharToFreqOrder, EUCKR_TABLE_SIZE, EUCKR_TYPICAL_DISTRIBUTION_RATIO
from gb2312freq import GB2312CharToFreqOrder, GB2312_TABLE_SIZE, GB2312_TYPICAL_DISTRIBUTION_RATIO
from big5freq import Big5CharToFreqOrder, BIG5_TABLE_SIZE, BIG5_TYPICAL_DISTRIBUTION_RATIO
from jisfreq import JISCharToFreqOrder, JIS_TABLE_SIZE, JIS_TYPICAL_DISTRIBUTION_RATIO
ENOUGH_DATA_THRESHOLD = 1024
SURE_YES = 0.99
SURE_NO = 0.01
class CharDistributionAnalysis:
def __init__(self):
self._mCharToFreqOrder = None # Mapping table to get frequency order from char order (get from GetOrder())
self._mTableSize = None # Size of above table
self._mTypicalDistributionRatio = None # This is a constant value which varies from language to language, used in calculating confidence. See http://www.mozilla.org/projects/intl/UniversalCharsetDetection.html for further detail.
self.reset()
def reset(self):
"""reset analyser, clear any state"""
self._mDone = constants.False # If this flag is set to constants.True, detection is done and conclusion has been made
self._mTotalChars = 0 # Total characters encountered
self._mFreqChars = 0 # The number of characters whose frequency order is less than 512
def feed(self, aStr, aCharLen):
"""feed a character with known length"""
if aCharLen == 2:
# we only care about 2-bytes character in our distribution analysis
order = self.get_order(aStr)
else:
order = -1
if order >= 0:
self._mTotalChars += 1
# order is valid
if order < self._mTableSize:
if 512 > self._mCharToFreqOrder[order]:
self._mFreqChars += 1
def get_confidence(self):
"""return confidence based on existing data"""
# if we didn't receive any character in our consideration range, return negative answer
if self._mTotalChars <= 0:
return SURE_NO
if self._mTotalChars != self._mFreqChars:
r = self._mFreqChars / ((self._mTotalChars - self._mFreqChars) * self._mTypicalDistributionRatio)
if r < SURE_YES:
return r
# normalize confidence (we don't want to be 100% sure)
return SURE_YES
def got_enough_data(self):
# It is not necessary to receive all data to draw conclusion. For charset detection,
# certain amount of data is enough
return self._mTotalChars > ENOUGH_DATA_THRESHOLD
def get_order(self, aStr):
# We do not handle characters based on the original encoding string, but
# convert this encoding string to a number, here called order.
# This allows multiple encodings of a language to share one frequency table.
return -1
class EUCTWDistributionAnalysis(CharDistributionAnalysis):
def __init__(self):
CharDistributionAnalysis.__init__(self)
self._mCharToFreqOrder = EUCTWCharToFreqOrder
self._mTableSize = EUCTW_TABLE_SIZE
self._mTypicalDistributionRatio = EUCTW_TYPICAL_DISTRIBUTION_RATIO
def get_order(self, aStr):
# for euc-TW encoding, we are interested
# first byte range: 0xc4 -- 0xfe
# second byte range: 0xa1 -- 0xfe
# no validation needed here. State machine has done that
if aStr[0] >= '\xC4':
return 94 * (ord(aStr[0]) - 0xC4) + ord(aStr[1]) - 0xA1
else:
return -1
class EUCKRDistributionAnalysis(CharDistributionAnalysis):
def __init__(self):
CharDistributionAnalysis.__init__(self)
self._mCharToFreqOrder = EUCKRCharToFreqOrder
self._mTableSize = EUCKR_TABLE_SIZE
self._mTypicalDistributionRatio = EUCKR_TYPICAL_DISTRIBUTION_RATIO
def get_order(self, aStr):
# for euc-KR encoding, we are interested
# first byte range: 0xb0 -- 0xfe
# second byte range: 0xa1 -- 0xfe
# no validation needed here. State machine has done that
if aStr[0] >= '\xB0':
return 94 * (ord(aStr[0]) - 0xB0) + ord(aStr[1]) - 0xA1
else:
return -1;
class GB2312DistributionAnalysis(CharDistributionAnalysis):
def __init__(self):
CharDistributionAnalysis.__init__(self)
self._mCharToFreqOrder = GB2312CharToFreqOrder
self._mTableSize = GB2312_TABLE_SIZE
self._mTypicalDistributionRatio = GB2312_TYPICAL_DISTRIBUTION_RATIO
def get_order(self, aStr):
# for GB2312 encoding, we are interested
# first byte range: 0xb0 -- 0xfe
# second byte range: 0xa1 -- 0xfe
# no validation needed here. State machine has done that
if (aStr[0] >= '\xB0') and (aStr[1] >= '\xA1'):
return 94 * (ord(aStr[0]) - 0xB0) + ord(aStr[1]) - 0xA1
else:
return -1;
class Big5DistributionAnalysis(CharDistributionAnalysis):
def __init__(self):
CharDistributionAnalysis.__init__(self)
self._mCharToFreqOrder = Big5CharToFreqOrder
self._mTableSize = BIG5_TABLE_SIZE
self._mTypicalDistributionRatio = BIG5_TYPICAL_DISTRIBUTION_RATIO
def get_order(self, aStr):
# for big5 encoding, we are interested
# first byte range: 0xa4 -- 0xfe
# second byte range: 0x40 -- 0x7e , 0xa1 -- 0xfe
# no validation needed here. State machine has done that
if aStr[0] >= '\xA4':
if aStr[1] >= '\xA1':
return 157 * (ord(aStr[0]) - 0xA4) + ord(aStr[1]) - 0xA1 + 63
else:
return 157 * (ord(aStr[0]) - 0xA4) + ord(aStr[1]) - 0x40
else:
return -1
class SJISDistributionAnalysis(CharDistributionAnalysis):
def __init__(self):
CharDistributionAnalysis.__init__(self)
self._mCharToFreqOrder = JISCharToFreqOrder
self._mTableSize = JIS_TABLE_SIZE
self._mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO
def get_order(self, aStr):
# for sjis encoding, we are interested
# first byte range: 0x81 -- 0x9f , 0xe0 -- 0xfe
# second byte range: 0x40 -- 0x7e, 0x81 -- oxfe
# no validation needed here. State machine has done that
if (aStr[0] >= '\x81') and (aStr[0] <= '\x9F'):
order = 188 * (ord(aStr[0]) - 0x81)
elif (aStr[0] >= '\xE0') and (aStr[0] <= '\xEF'):
order = 188 * (ord(aStr[0]) - 0xE0 + 31)
else:
return -1;
order = order + ord(aStr[1]) - 0x40
if aStr[1] > '\x7F':
order =- 1
return order
class EUCJPDistributionAnalysis(CharDistributionAnalysis):
def __init__(self):
CharDistributionAnalysis.__init__(self)
self._mCharToFreqOrder = JISCharToFreqOrder
self._mTableSize = JIS_TABLE_SIZE
self._mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO
def get_order(self, aStr):
# for euc-JP encoding, we are interested
# first byte range: 0xa0 -- 0xfe
# second byte range: 0xa1 -- 0xfe
# no validation needed here. State machine has done that
if aStr[0] >= '\xA0':
return 94 * (ord(aStr[0]) - 0xA1) + ord(aStr[1]) - 0xa1
else:
return -1
|
gpl-3.0
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
221,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
221,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
646,
5262,
199,
504,
325,
918,
87,
5646,
492,
662,
27120,
18139,
13875,
4738,
12,
662,
27120,
63,
8723,
63,
4305,
12,
662,
27120,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
199,
504,
325,
10112,
3941,
2103,
492,
26007,
27373,
18139,
13875,
4738,
12,
26007,
27373,
63,
8723,
63,
4305,
12,
26007,
27373,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
199,
504,
25411,
16909,
5646,
492,
18553,
16909,
18139,
13875,
4738,
12,
18553,
16909,
63,
8723,
63,
4305,
12,
18553,
16909,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
199,
504,
7282,
21,
5646,
492,
13123,
21,
18139,
13875,
4738,
12,
16524,
21,
63,
8723,
63,
4305,
12,
16524,
21,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
199,
504,
1335,
374,
5646,
492,
1603,
1311,
18139,
13875,
4738,
12,
1603,
1311,
63,
8723,
63,
4305,
12,
1603,
1311,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
199,
199,
15577,
10134,
40,
63,
3998,
63,
19307,
275,
6619,
199,
51,
3942,
63,
15641,
275,
378,
14,
1020,
199,
51,
3942,
63,
2826,
275,
378,
14,
614,
199,
199,
533,
6659,
24906,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
77,
18139,
13875,
4738,
275,
488,
327,
12340,
1817,
370,
664,
9857,
1865,
687,
1495,
1865,
334,
362,
687,
2372,
4738,
1012,
267,
291,
423,
77,
3186,
2320,
275,
488,
327,
14579,
402,
3432,
1817,
267,
291,
423,
30376,
8580,
13971,
275,
488,
327,
961,
365,
282,
4413,
574,
1314,
373,
3433,
687,
2637,
370,
2637,
12,
1202,
315,
26079,
15197,
14,
221,
1666,
1455,
921,
1544,
14,
12102,
14,
1308,
15,
6776,
15,
442,
76,
15,
1358,
10959,
28200,
31198,
14,
1360,
367,
9848,
10093,
14,
267,
291,
14,
3958,
342,
5493,
347,
5305,
8,
277,
304,
267,
408,
3958,
5909,
332,
12,
5436,
1263,
1174,
624,
267,
291,
423,
77,
10759,
275,
5262,
14,
797,
327,
982,
642,
3305,
365,
663,
370,
5262,
14,
549,
12,
15212,
365,
4224,
436,
406,
10248,
965,
2757,
6326,
267,
291,
423,
77,
7316,
11229,
275,
378,
327,
19271,
4110,
14556,
267,
291,
423,
77,
13875,
11229,
275,
378,
327,
710,
1329,
402,
4110,
7447,
9857,
1865,
365,
6656,
2419,
10574,
339,
347,
4733,
8,
277,
12,
282,
2848,
12,
282,
1610,
3166,
304,
267,
408,
3871,
282,
4528,
543,
6040,
2582,
624,
267,
340,
282,
1610,
3166,
508,
499,
26,
288,
327,
781,
1454,
10296,
3595,
499,
13,
2394,
4528,
315,
4154,
4084,
11284,
288,
1865,
275,
291,
14,
362,
63,
1648,
8,
65,
2848,
9,
267,
587,
26,
288,
1865,
275,
446,
17,
267,
340,
1865,
2356,
378,
26,
288,
291,
423,
77,
7316,
11229,
847,
413,
288,
327,
1865,
365,
1686,
288,
340,
1865,
665,
291,
423,
77,
3186,
2320,
26,
355,
340,
10574,
690,
291,
423,
77,
18139,
13875,
4738,
59,
1648,
2189,
490,
291,
423,
77,
13875,
11229,
847,
413,
339,
347,
664,
63,
13969,
8,
277,
304,
267,
408,
1107,
15197,
4079,
641,
3411,
666,
624,
267,
327,
340,
781,
9980,
1133,
9128,
1263,
4528,
315,
4154,
8219,
1754,
1425,
12,
372,
6946,
6385,
267,
340,
291,
423,
77,
7316,
11229,
2695,
378,
26,
288,
372,
428,
3942,
63,
2826,
398,
340,
291,
423,
77,
7316,
11229,
1137,
291,
423,
77,
13875,
11229,
26,
288,
519,
275,
291,
423,
77,
13875,
11229,
1182,
3666,
277,
423,
77,
7316,
11229,
446,
291,
423,
77,
13875,
11229,
9,
627,
291,
423,
30376,
8580,
13971,
9,
288,
340,
519,
665,
428,
3942,
63,
15641,
26,
355,
372,
519,
398,
327,
7666,
15197,
334,
1129,
2793,
1133,
2934,
370,
506,
2948,
5,
3238,
9,
267,
372,
428,
3942,
63,
15641,
339,
347,
4788,
63,
30881,
63,
576,
8,
277,
304,
267,
327,
2779,
365,
440,
5784,
370,
9128,
1006,
666,
370,
5954,
406,
10248,
14,
2104,
5960,
15212,
12,
267,
327,
9842,
5982,
402,
666,
365,
8321,
267,
372,
291,
423,
77,
7316,
11229,
690,
662,
2826,
10134,
40,
63,
3998,
63,
19307,
339,
347,
664,
63,
1648,
8,
277,
12,
282,
2848,
304,
267,
327,
2136,
886,
440,
2429,
4110,
4079,
641,
314,
3379,
2644,
1059,
12,
1325,
4960,
327,
3957,
642,
2644,
1059,
370,
282,
1329,
12,
2348,
2797,
1865,
14,
267,
327,
961,
6127,
3663,
14134,
402,
282,
2637,
370,
8663,
1373,
9857,
1817,
14,
267,
372,
446,
17,
1362,
199,
533,
662,
27120,
24906,
8,
1610,
24906,
304,
272,
347,
636,
826,
721,
277,
304,
267,
6659,
24906,
855,
826,
721,
277,
9,
267,
291,
423,
77,
18139,
13875,
4738,
275,
662,
27120,
18139,
13875,
4738,
267,
291,
423,
77,
3186,
2320,
275,
662,
27120,
63,
8723
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
221,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
221,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
646,
5262,
199,
504,
325,
918,
87,
5646,
492,
662,
27120,
18139,
13875,
4738,
12,
662,
27120,
63,
8723,
63,
4305,
12,
662,
27120,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
199,
504,
325,
10112,
3941,
2103,
492,
26007,
27373,
18139,
13875,
4738,
12,
26007,
27373,
63,
8723,
63,
4305,
12,
26007,
27373,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
199,
504,
25411,
16909,
5646,
492,
18553,
16909,
18139,
13875,
4738,
12,
18553,
16909,
63,
8723,
63,
4305,
12,
18553,
16909,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
199,
504,
7282,
21,
5646,
492,
13123,
21,
18139,
13875,
4738,
12,
16524,
21,
63,
8723,
63,
4305,
12,
16524,
21,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
199,
504,
1335,
374,
5646,
492,
1603,
1311,
18139,
13875,
4738,
12,
1603,
1311,
63,
8723,
63,
4305,
12,
1603,
1311,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
199,
199,
15577,
10134,
40,
63,
3998,
63,
19307,
275,
6619,
199,
51,
3942,
63,
15641,
275,
378,
14,
1020,
199,
51,
3942,
63,
2826,
275,
378,
14,
614,
199,
199,
533,
6659,
24906,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
77,
18139,
13875,
4738,
275,
488,
327,
12340,
1817,
370,
664,
9857,
1865,
687,
1495,
1865,
334,
362,
687,
2372,
4738,
1012,
267,
291,
423,
77,
3186,
2320,
275,
488,
327,
14579,
402,
3432,
1817,
267,
291,
423,
30376,
8580,
13971,
275,
488,
327,
961,
365,
282,
4413,
574,
1314,
373,
3433,
687,
2637,
370,
2637,
12,
1202,
315,
26079,
15197,
14,
221,
1666,
1455,
921,
1544,
14,
12102,
14,
1308,
15,
6776,
15,
442,
76,
15,
1358,
10959,
28200,
31198,
14,
1360,
367,
9848,
10093,
14,
267,
291,
14,
3958,
342,
5493,
347,
5305,
8,
277,
304,
267,
408,
3958,
5909,
332,
12,
5436,
1263,
1174,
624,
267,
291,
423,
77,
10759,
275,
5262,
14,
797,
327,
982,
642,
3305,
365,
663,
370,
5262,
14,
549,
12,
15212,
365,
4224,
436,
406,
10248,
965,
2757,
6326,
267,
291,
423,
77,
7316,
11229,
275,
378,
327,
19271,
4110,
14556,
267,
291,
423,
77,
13875,
11229,
275,
378,
327,
710,
1329,
402,
4110,
7447,
9857,
1865,
365,
6656,
2419,
10574,
339,
347,
4733,
8,
277,
12,
282,
2848,
12,
282,
1610,
3166,
304,
267,
408,
3871,
282,
4528,
543,
6040,
2582,
624,
267,
340,
282,
1610,
3166,
508,
499,
26,
288,
327,
781,
1454,
10296,
3595,
499,
13,
2394,
4528,
315,
4154,
4084,
11284,
288,
1865,
275,
291,
14,
362,
63,
1648,
8,
65,
2848,
9,
267,
587,
26,
288,
1865,
275,
446,
17,
267,
340,
1865,
2356,
378,
26,
288,
291,
423,
77,
7316,
11229,
847,
413,
288,
327,
1865,
365,
1686,
288,
340,
1865,
665,
291,
423,
77,
3186,
2320,
26,
355,
340,
10574,
690,
291,
423,
77,
18139,
13875,
4738,
59,
1648,
2189,
490,
291,
423,
77,
13875,
11229,
847,
413,
339,
347,
664,
63,
13969,
8,
277,
304,
267,
408,
1107,
15197,
4079,
641,
3411,
666,
624,
267,
327,
340,
781,
9980,
1133,
9128,
1263,
4528,
315,
4154,
8219,
1754,
1425,
12,
372,
6946,
6385,
267,
340,
291,
423,
77,
7316,
11229,
2695,
378,
26,
288,
372,
428,
3942,
63,
2826,
398,
340,
291,
423,
77,
7316,
11229,
1137,
291,
423,
77,
13875,
11229,
26,
288,
519,
275,
291,
423,
77,
13875,
11229,
1182,
3666,
277,
423,
77,
7316,
11229,
446,
291,
423,
77,
13875,
11229,
9,
627,
291,
423,
30376,
8580,
13971,
9,
288,
340,
519,
665,
428,
3942,
63,
15641,
26,
355,
372,
519,
398,
327,
7666,
15197,
334,
1129,
2793,
1133,
2934,
370,
506,
2948,
5,
3238,
9,
267,
372,
428,
3942,
63,
15641,
339,
347,
4788,
63,
30881,
63,
576,
8,
277,
304,
267,
327,
2779,
365,
440,
5784,
370,
9128,
1006,
666,
370,
5954,
406,
10248,
14,
2104,
5960,
15212,
12,
267,
327,
9842,
5982,
402,
666,
365,
8321,
267,
372,
291,
423,
77,
7316,
11229,
690,
662,
2826,
10134,
40,
63,
3998,
63,
19307,
339,
347,
664,
63,
1648,
8,
277,
12,
282,
2848,
304,
267,
327,
2136,
886,
440,
2429,
4110,
4079,
641,
314,
3379,
2644,
1059,
12,
1325,
4960,
327,
3957,
642,
2644,
1059,
370,
282,
1329,
12,
2348,
2797,
1865,
14,
267,
327,
961,
6127,
3663,
14134,
402,
282,
2637,
370,
8663,
1373,
9857,
1817,
14,
267,
372,
446,
17,
1362,
199,
533,
662,
27120,
24906,
8,
1610,
24906,
304,
272,
347,
636,
826,
721,
277,
304,
267,
6659,
24906,
855,
826,
721,
277,
9,
267,
291,
423,
77,
18139,
13875,
4738,
275,
662,
27120,
18139,
13875,
4738,
267,
291,
423,
77,
3186,
2320,
275,
662,
27120,
63,
8723,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jayceyxc/hue
|
desktop/core/ext-py/cffi-1.5.2/demo/manual2.py
|
12
|
1175
|
import _cffi_backend
ffi = _cffi_backend.FFI(b"manual2",
_version = 0x2601,
_types = b'\x00\x00\x01\x0D\x00\x00\x07\x01\x00\x00\x00\x0F\x00\x00\x00\x09\x00\x00\x00\x0B\x00\x00\x01\x03',
_globals = (b'\xff\xff\xff\x0bAA',0,b'\xff\xff\xff\x0bBB',-1,b'\xff\xff\xff\x0bCC',2,b'\xff\xff\xff\x1fFOO',0x9999999999999999,b'\x00\x00\x00#close',0,b'\x00\x00\x05#stdout',0),
_struct_unions = ((b'\x00\x00\x00\x03\x00\x00\x00\x00point_s',b'\x00\x00\x01\x11\xff\xff\xff\xffx',b'\x00\x00\x01\x11\xff\xff\xff\xffy'),),
_enums = (b'\x00\x00\x00\x04\x00\x00\x00\x07myenum_e\x00AA,BB,CC',),
_typenames = (b'\x00\x00\x00\x01myint_t',),
)
# trying it out
lib = ffi.dlopen(None)
assert lib.AA == 0
assert lib.BB == -1
assert lib.FOO == 0x9999999999999999
x = lib.close(-42)
assert x == -1
print lib.stdout
print ffi.new("struct point_s *")
print ffi.offsetof("struct point_s", "x")
print ffi.offsetof("struct point_s", "y")
print ffi.new("struct point_s[CC]")
assert ffi.sizeof("struct point_s[CC]") == 2 * ffi.sizeof("struct point_s")
print ffi.cast("enum myenum_e", 2)
print ffi.cast("myint_t", -2)
assert ffi.typeof("myint_t") == ffi.typeof("int")
del ffi, lib
|
apache-2.0
|
[
646,
485,
32407,
63,
4620,
199,
199,
11286,
275,
485,
32407,
63,
4620,
14,
1665,
41,
8,
66,
2,
9285,
18,
401,
272,
485,
1023,
275,
378,
88,
1479,
614,
12,
272,
485,
1313,
275,
330,
1154,
88,
383,
60,
88,
383,
60,
88,
614,
60,
88,
16,
36,
60,
88,
383,
60,
88,
383,
60,
88,
1780,
60,
88,
614,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
16,
38,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
1643,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
16,
34,
60,
88,
383,
60,
88,
383,
60,
88,
614,
60,
88,
1644,
297,
272,
485,
8473,
275,
334,
66,
1154,
3581,
60,
3581,
60,
3581,
60,
88,
16,
66,
2276,
297,
16,
12,
66,
1154,
3581,
60,
3581,
60,
3581,
60,
88,
16,
66,
5342,
297,
13,
17,
12,
66,
1154,
3581,
60,
3581,
60,
3581,
60,
88,
16,
66,
2571,
297,
18,
12,
66,
1154,
3581,
60,
3581,
60,
3581,
60,
88,
17,
70,
13046,
297,
16,
88,
13453,
13453,
12,
66,
1154,
88,
383,
60,
88,
383,
60,
88,
383,
3,
1600,
297,
16,
12,
66,
1154,
88,
383,
60,
88,
383,
60,
88,
1717,
3,
2703,
297,
16,
395,
272,
485,
1820,
63,
8888,
83,
275,
3666,
66,
1154,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
1644,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
1403,
63,
83,
297,
66,
1154,
88,
383,
60,
88,
383,
60,
88,
614,
60,
88,
845,
60,
3581,
60,
3581,
60,
3581,
60,
3581,
88,
297,
66,
1154,
88,
383,
60,
88,
383,
60,
88,
614,
60,
88,
845,
60,
3581,
60,
3581,
60,
3581,
60,
3581,
89,
659,
395,
272,
485,
19921,
275,
334,
66,
1154,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
966,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
1780,
1662,
4869,
63,
69,
60,
88,
383,
2276,
12,
5342,
12,
2571,
5529,
272,
485,
18596,
83,
275,
334,
66,
1154,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
614,
1662,
442,
63,
84,
5529,
199,
9,
4388,
199,
3,
9936,
652,
734,
199,
773,
275,
30865,
14,
68,
8329,
8,
403,
9,
199,
479,
1973,
14,
2276,
508,
378,
199,
479,
1973,
14,
5342,
508,
446,
17,
199,
479,
1973,
14,
13046,
508,
378,
88,
13453,
13453,
199,
88,
275,
1973,
14,
1600,
2801,
2260,
9,
199,
479,
671,
508,
446,
17,
199,
199,
1361,
1973,
14,
2703,
199,
199,
1361,
30865,
14,
1222,
480,
1820,
2376,
63,
83,
627,
531,
199,
1361,
30865,
14,
2743,
1618,
480,
1820,
2376,
63,
83,
401,
298,
88,
531,
199,
1361,
30865,
14,
2743,
1618,
480,
1820,
2376,
63,
83,
401,
298,
89,
531,
199,
1361,
30865,
14,
1222,
480,
1820,
2376,
63,
83,
59,
2571,
12523,
199,
479,
30865,
14,
12590,
480,
1820,
2376,
63,
83,
59,
2571,
12523,
508,
499,
627,
30865,
14,
12590,
480,
1820,
2376,
63,
83,
531,
199,
199,
1361,
30865,
14,
2931,
480,
4869,
3002,
4869,
63,
69,
401,
499,
9,
199,
1361,
30865,
14,
2931,
480,
1662,
442,
63,
84,
401,
446,
18,
9,
199,
479,
30865,
14,
23426,
480,
1662,
442,
63,
84,
531,
508,
30865,
14,
23426,
480,
442,
531,
199,
199,
2264,
30865,
12,
1973,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
485,
32407,
63,
4620,
199,
199,
11286,
275,
485,
32407,
63,
4620,
14,
1665,
41,
8,
66,
2,
9285,
18,
401,
272,
485,
1023,
275,
378,
88,
1479,
614,
12,
272,
485,
1313,
275,
330,
1154,
88,
383,
60,
88,
383,
60,
88,
614,
60,
88,
16,
36,
60,
88,
383,
60,
88,
383,
60,
88,
1780,
60,
88,
614,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
16,
38,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
1643,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
16,
34,
60,
88,
383,
60,
88,
383,
60,
88,
614,
60,
88,
1644,
297,
272,
485,
8473,
275,
334,
66,
1154,
3581,
60,
3581,
60,
3581,
60,
88,
16,
66,
2276,
297,
16,
12,
66,
1154,
3581,
60,
3581,
60,
3581,
60,
88,
16,
66,
5342,
297,
13,
17,
12,
66,
1154,
3581,
60,
3581,
60,
3581,
60,
88,
16,
66,
2571,
297,
18,
12,
66,
1154,
3581,
60,
3581,
60,
3581,
60,
88,
17,
70,
13046,
297,
16,
88,
13453,
13453,
12,
66,
1154,
88,
383,
60,
88,
383,
60,
88,
383,
3,
1600,
297,
16,
12,
66,
1154,
88,
383,
60,
88,
383,
60,
88,
1717,
3,
2703,
297,
16,
395,
272,
485,
1820,
63,
8888,
83,
275,
3666,
66,
1154,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
1644,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
1403,
63,
83,
297,
66,
1154,
88,
383,
60,
88,
383,
60,
88,
614,
60,
88,
845,
60,
3581,
60,
3581,
60,
3581,
60,
3581,
88,
297,
66,
1154,
88,
383,
60,
88,
383,
60,
88,
614,
60,
88,
845,
60,
3581,
60,
3581,
60,
3581,
60,
3581,
89,
659,
395,
272,
485,
19921,
275,
334,
66,
1154,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
966,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
1780,
1662,
4869,
63,
69,
60,
88,
383,
2276,
12,
5342,
12,
2571,
5529,
272,
485,
18596,
83,
275,
334,
66,
1154,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
614,
1662,
442,
63,
84,
5529,
199,
9,
4388,
199,
3,
9936,
652,
734,
199,
773,
275,
30865,
14,
68,
8329,
8,
403,
9,
199,
479,
1973,
14,
2276,
508,
378,
199,
479,
1973,
14,
5342,
508,
446,
17,
199,
479,
1973,
14,
13046,
508,
378,
88,
13453,
13453,
199,
88,
275,
1973,
14,
1600,
2801,
2260,
9,
199,
479,
671,
508,
446,
17,
199,
199,
1361,
1973,
14,
2703,
199,
199,
1361,
30865,
14,
1222,
480,
1820,
2376,
63,
83,
627,
531,
199,
1361,
30865,
14,
2743,
1618,
480,
1820,
2376,
63,
83,
401,
298,
88,
531,
199,
1361,
30865,
14,
2743,
1618,
480,
1820,
2376,
63,
83,
401,
298,
89,
531,
199,
1361,
30865,
14,
1222,
480,
1820,
2376,
63,
83,
59,
2571,
12523,
199,
479,
30865,
14,
12590,
480,
1820,
2376,
63,
83,
59,
2571,
12523,
508,
499,
627,
30865,
14,
12590,
480,
1820,
2376,
63,
83,
531,
199,
199,
1361,
30865,
14,
2931,
480,
4869,
3002,
4869,
63,
69,
401,
499,
9,
199,
1361,
30865,
14,
2931,
480,
1662,
442,
63,
84,
401,
446,
18,
9,
199,
479,
30865,
14,
23426,
480,
1662,
442,
63,
84,
531,
508,
30865,
14,
23426,
480,
442,
531,
199,
199,
2264,
30865,
12,
1973,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
LuckyLukert/Turnierserver
|
Frontend/commons.py
|
1
|
1422
|
from database import db
from flask import abort, make_response, Response
from flask.ext.login import current_user
from flask.ext.cache import Cache
from functools import wraps
class CommonErrors:
BAD_REQUEST = ({'error': 'Bad request.'}, 400)
INVALID_ID = ({'error': 'Invalid id.'}, 404)
NO_ACCESS = ({'error': 'Insufficient permissions.'}, 401)
IM_A_TEAPOT = ({'error': 'I\'m a teapot.'}, 418)
NOT_IMPLEMENTED = ({'error': 'Not implemented.'}, 501)
FTP_ERROR = ({'error': 'FTP-Error'}, 503)
def authenticated(f):
@wraps(f)
def wrapper(*args, **kwargs):
if current_user:
if current_user.is_authenticated:
try:
ret = f(*args, **kwargs)
db.session.commit()
return ret
except:
db.session.rollback()
db.session.close()
raise
return CommonErrors.NO_ACCESS
return wrapper
def authenticated_web(f):
@wraps(f)
def wrapper(*args, **kwargs):
if current_user:
if current_user.is_authenticated:
try:
ret = f(*args, **kwargs)
db.session.commit()
return ret
except:
db.session.rollback()
raise
return abort(401)
return wrapper
def nocache(f):
@wraps(f)
def wrapper(*args, **kwargs):
resp = f(*args, **kwargs)
if not isinstance(resp, Response):
resp = make_response(resp)
resp.cache_control.no_cache = True
resp.cache_control.no_store = True
return resp
return wrapper
cache = Cache(config={'CACHE_TYPE': 'simple'})
|
lgpl-3.0
|
[
504,
3050,
492,
1592,
199,
504,
7209,
492,
12004,
12,
1852,
63,
1310,
12,
7232,
199,
504,
7209,
14,
832,
14,
2886,
492,
1453,
63,
751,
199,
504,
7209,
14,
832,
14,
1637,
492,
11977,
199,
504,
9143,
492,
14018,
421,
199,
533,
13964,
9298,
26,
199,
198,
9439,
63,
6780,
275,
26227,
705,
356,
283,
5725,
1056,
14,
2267,
8290,
9,
199,
198,
9692,
63,
998,
275,
26227,
705,
356,
283,
3364,
1305,
14,
2267,
7901,
9,
199,
198,
2826,
63,
11074,
275,
26227,
705,
356,
283,
13962,
12983,
3443,
14,
2267,
13952,
9,
199,
198,
1469,
63,
33,
63,
3727,
1282,
1387,
275,
26227,
705,
356,
283,
41,
3985,
77,
282,
1565,
439,
357,
14,
2267,
841,
1085,
9,
199,
198,
4609,
63,
8947,
10320,
1149,
275,
26227,
705,
356,
283,
1763,
6366,
14,
2267,
28606,
9,
199,
198,
15123,
63,
3170,
275,
26227,
705,
356,
283,
15123,
13,
547,
2267,
24046,
9,
421,
199,
318,
15082,
8,
70,
304,
199,
198,
32,
13582,
8,
70,
9,
199,
198,
318,
4975,
2031,
589,
12,
1011,
958,
304,
507,
198,
692,
1453,
63,
751,
26,
686,
198,
692,
1453,
63,
751,
14,
374,
63,
12177,
26,
1585,
198,
893,
26,
1871,
198,
3292,
275,
289,
2031,
589,
12,
1011,
958,
9,
1871,
198,
697,
14,
1730,
14,
3543,
342,
1871,
198,
1107,
2203,
1585,
198,
2590,
26,
1871,
198,
697,
14,
1730,
14,
10437,
342,
1871,
198,
697,
14,
1730,
14,
1600,
342,
1871,
198,
3730,
507,
198,
1107,
13964,
9298,
14,
2826,
63,
11074,
199,
198,
1107,
4975,
421,
199,
318,
15082,
63,
2520,
8,
70,
304,
199,
198,
32,
13582,
8,
70,
9,
199,
198,
318,
4975,
2031,
589,
12,
1011,
958,
304,
507,
198,
692,
1453,
63,
751,
26,
686,
198,
692,
1453,
63,
751,
14,
374,
63,
12177,
26,
1585,
198,
893,
26,
1871,
198,
3292,
275,
289,
2031,
589,
12,
1011,
958,
9,
1871,
198,
697,
14,
1730,
14,
3543,
342,
1871,
198,
1107,
2203,
1585,
198,
2590,
26,
1871,
198,
697,
14,
1730,
14,
10437,
342,
1871,
198,
3730,
507,
198,
1107,
12004,
8,
8854,
9,
199,
198,
1107,
4975,
199,
199,
318,
302,
679,
21481,
8,
70,
304,
199,
198,
32,
13582,
8,
70,
9,
199,
198,
318,
4975,
2031,
589,
12,
1011,
958,
304,
507,
198,
4518,
275,
289,
2031,
589,
12,
1011,
958,
9,
507,
198,
692,
440,
1228,
8,
4518,
12,
7232,
304,
686,
198,
4518,
275,
1852,
63,
1310,
8,
4518,
9,
507,
198,
4518,
14,
1637,
63,
2785,
14,
889,
63,
1637,
275,
715,
507,
198,
4518,
14,
1637,
63,
2785,
14,
889,
63,
1617,
275,
715,
507,
198,
1107,
3085,
199,
198,
1107,
4975,
199,
199,
1637,
275,
11977,
8,
888,
3713,
8677,
63,
2711,
356,
283,
4129,
3071,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3050,
492,
1592,
199,
504,
7209,
492,
12004,
12,
1852,
63,
1310,
12,
7232,
199,
504,
7209,
14,
832,
14,
2886,
492,
1453,
63,
751,
199,
504,
7209,
14,
832,
14,
1637,
492,
11977,
199,
504,
9143,
492,
14018,
421,
199,
533,
13964,
9298,
26,
199,
198,
9439,
63,
6780,
275,
26227,
705,
356,
283,
5725,
1056,
14,
2267,
8290,
9,
199,
198,
9692,
63,
998,
275,
26227,
705,
356,
283,
3364,
1305,
14,
2267,
7901,
9,
199,
198,
2826,
63,
11074,
275,
26227,
705,
356,
283,
13962,
12983,
3443,
14,
2267,
13952,
9,
199,
198,
1469,
63,
33,
63,
3727,
1282,
1387,
275,
26227,
705,
356,
283,
41,
3985,
77,
282,
1565,
439,
357,
14,
2267,
841,
1085,
9,
199,
198,
4609,
63,
8947,
10320,
1149,
275,
26227,
705,
356,
283,
1763,
6366,
14,
2267,
28606,
9,
199,
198,
15123,
63,
3170,
275,
26227,
705,
356,
283,
15123,
13,
547,
2267,
24046,
9,
421,
199,
318,
15082,
8,
70,
304,
199,
198,
32,
13582,
8,
70,
9,
199,
198,
318,
4975,
2031,
589,
12,
1011,
958,
304,
507,
198,
692,
1453,
63,
751,
26,
686,
198,
692,
1453,
63,
751,
14,
374,
63,
12177,
26,
1585,
198,
893,
26,
1871,
198,
3292,
275,
289,
2031,
589,
12,
1011,
958,
9,
1871,
198,
697,
14,
1730,
14,
3543,
342,
1871,
198,
1107,
2203,
1585,
198,
2590,
26,
1871,
198,
697,
14,
1730,
14,
10437,
342,
1871,
198,
697,
14,
1730,
14,
1600,
342,
1871,
198,
3730,
507,
198,
1107,
13964,
9298,
14,
2826,
63,
11074,
199,
198,
1107,
4975,
421,
199,
318,
15082,
63,
2520,
8,
70,
304,
199,
198,
32,
13582,
8,
70,
9,
199,
198,
318,
4975,
2031,
589,
12,
1011,
958,
304,
507,
198,
692,
1453,
63,
751,
26,
686,
198,
692,
1453,
63,
751,
14,
374,
63,
12177,
26,
1585,
198,
893,
26,
1871,
198,
3292,
275,
289,
2031,
589,
12,
1011,
958,
9,
1871,
198,
697,
14,
1730,
14,
3543,
342,
1871,
198,
1107,
2203,
1585,
198,
2590,
26,
1871,
198,
697,
14,
1730,
14,
10437,
342,
1871,
198,
3730,
507,
198,
1107,
12004,
8,
8854,
9,
199,
198,
1107,
4975,
199,
199,
318,
302,
679,
21481,
8,
70,
304,
199,
198,
32,
13582,
8,
70,
9,
199,
198,
318,
4975,
2031,
589,
12,
1011,
958,
304,
507,
198,
4518,
275,
289,
2031,
589,
12,
1011,
958,
9,
507,
198,
692,
440,
1228,
8,
4518,
12,
7232,
304,
686,
198,
4518,
275,
1852,
63,
1310,
8,
4518,
9,
507,
198,
4518,
14,
1637,
63,
2785,
14,
889,
63,
1637,
275,
715,
507,
198,
4518,
14,
1637,
63,
2785,
14,
889,
63,
1617,
275,
715,
507,
198,
1107,
3085,
199,
198,
1107,
4975,
199,
199,
1637,
275,
11977,
8,
888,
3713,
8677,
63,
2711,
356,
283,
4129,
3071,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
ojii/sandlib
|
lib/lib-python/2.7/encodings/cp865.py
|
593
|
34874
|
""" Python Character Mapping Codec generated from 'VENDORS/MICSFT/PC/CP865.TXT' with gencodec.py.
"""#"
import codecs
### Codec APIs
class Codec(codecs.Codec):
def encode(self,input,errors='strict'):
return codecs.charmap_encode(input,errors,encoding_map)
def decode(self,input,errors='strict'):
return codecs.charmap_decode(input,errors,decoding_table)
class IncrementalEncoder(codecs.IncrementalEncoder):
def encode(self, input, final=False):
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
class IncrementalDecoder(codecs.IncrementalDecoder):
def decode(self, input, final=False):
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
class StreamWriter(Codec,codecs.StreamWriter):
pass
class StreamReader(Codec,codecs.StreamReader):
pass
### encodings module API
def getregentry():
return codecs.CodecInfo(
name='cp865',
encode=Codec().encode,
decode=Codec().decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
)
### Decoding Map
decoding_map = codecs.make_identity_dict(range(256))
decoding_map.update({
0x0080: 0x00c7, # LATIN CAPITAL LETTER C WITH CEDILLA
0x0081: 0x00fc, # LATIN SMALL LETTER U WITH DIAERESIS
0x0082: 0x00e9, # LATIN SMALL LETTER E WITH ACUTE
0x0083: 0x00e2, # LATIN SMALL LETTER A WITH CIRCUMFLEX
0x0084: 0x00e4, # LATIN SMALL LETTER A WITH DIAERESIS
0x0085: 0x00e0, # LATIN SMALL LETTER A WITH GRAVE
0x0086: 0x00e5, # LATIN SMALL LETTER A WITH RING ABOVE
0x0087: 0x00e7, # LATIN SMALL LETTER C WITH CEDILLA
0x0088: 0x00ea, # LATIN SMALL LETTER E WITH CIRCUMFLEX
0x0089: 0x00eb, # LATIN SMALL LETTER E WITH DIAERESIS
0x008a: 0x00e8, # LATIN SMALL LETTER E WITH GRAVE
0x008b: 0x00ef, # LATIN SMALL LETTER I WITH DIAERESIS
0x008c: 0x00ee, # LATIN SMALL LETTER I WITH CIRCUMFLEX
0x008d: 0x00ec, # LATIN SMALL LETTER I WITH GRAVE
0x008e: 0x00c4, # LATIN CAPITAL LETTER A WITH DIAERESIS
0x008f: 0x00c5, # LATIN CAPITAL LETTER A WITH RING ABOVE
0x0090: 0x00c9, # LATIN CAPITAL LETTER E WITH ACUTE
0x0091: 0x00e6, # LATIN SMALL LIGATURE AE
0x0092: 0x00c6, # LATIN CAPITAL LIGATURE AE
0x0093: 0x00f4, # LATIN SMALL LETTER O WITH CIRCUMFLEX
0x0094: 0x00f6, # LATIN SMALL LETTER O WITH DIAERESIS
0x0095: 0x00f2, # LATIN SMALL LETTER O WITH GRAVE
0x0096: 0x00fb, # LATIN SMALL LETTER U WITH CIRCUMFLEX
0x0097: 0x00f9, # LATIN SMALL LETTER U WITH GRAVE
0x0098: 0x00ff, # LATIN SMALL LETTER Y WITH DIAERESIS
0x0099: 0x00d6, # LATIN CAPITAL LETTER O WITH DIAERESIS
0x009a: 0x00dc, # LATIN CAPITAL LETTER U WITH DIAERESIS
0x009b: 0x00f8, # LATIN SMALL LETTER O WITH STROKE
0x009c: 0x00a3, # POUND SIGN
0x009d: 0x00d8, # LATIN CAPITAL LETTER O WITH STROKE
0x009e: 0x20a7, # PESETA SIGN
0x009f: 0x0192, # LATIN SMALL LETTER F WITH HOOK
0x00a0: 0x00e1, # LATIN SMALL LETTER A WITH ACUTE
0x00a1: 0x00ed, # LATIN SMALL LETTER I WITH ACUTE
0x00a2: 0x00f3, # LATIN SMALL LETTER O WITH ACUTE
0x00a3: 0x00fa, # LATIN SMALL LETTER U WITH ACUTE
0x00a4: 0x00f1, # LATIN SMALL LETTER N WITH TILDE
0x00a5: 0x00d1, # LATIN CAPITAL LETTER N WITH TILDE
0x00a6: 0x00aa, # FEMININE ORDINAL INDICATOR
0x00a7: 0x00ba, # MASCULINE ORDINAL INDICATOR
0x00a8: 0x00bf, # INVERTED QUESTION MARK
0x00a9: 0x2310, # REVERSED NOT SIGN
0x00aa: 0x00ac, # NOT SIGN
0x00ab: 0x00bd, # VULGAR FRACTION ONE HALF
0x00ac: 0x00bc, # VULGAR FRACTION ONE QUARTER
0x00ad: 0x00a1, # INVERTED EXCLAMATION MARK
0x00ae: 0x00ab, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
0x00af: 0x00a4, # CURRENCY SIGN
0x00b0: 0x2591, # LIGHT SHADE
0x00b1: 0x2592, # MEDIUM SHADE
0x00b2: 0x2593, # DARK SHADE
0x00b3: 0x2502, # BOX DRAWINGS LIGHT VERTICAL
0x00b4: 0x2524, # BOX DRAWINGS LIGHT VERTICAL AND LEFT
0x00b5: 0x2561, # BOX DRAWINGS VERTICAL SINGLE AND LEFT DOUBLE
0x00b6: 0x2562, # BOX DRAWINGS VERTICAL DOUBLE AND LEFT SINGLE
0x00b7: 0x2556, # BOX DRAWINGS DOWN DOUBLE AND LEFT SINGLE
0x00b8: 0x2555, # BOX DRAWINGS DOWN SINGLE AND LEFT DOUBLE
0x00b9: 0x2563, # BOX DRAWINGS DOUBLE VERTICAL AND LEFT
0x00ba: 0x2551, # BOX DRAWINGS DOUBLE VERTICAL
0x00bb: 0x2557, # BOX DRAWINGS DOUBLE DOWN AND LEFT
0x00bc: 0x255d, # BOX DRAWINGS DOUBLE UP AND LEFT
0x00bd: 0x255c, # BOX DRAWINGS UP DOUBLE AND LEFT SINGLE
0x00be: 0x255b, # BOX DRAWINGS UP SINGLE AND LEFT DOUBLE
0x00bf: 0x2510, # BOX DRAWINGS LIGHT DOWN AND LEFT
0x00c0: 0x2514, # BOX DRAWINGS LIGHT UP AND RIGHT
0x00c1: 0x2534, # BOX DRAWINGS LIGHT UP AND HORIZONTAL
0x00c2: 0x252c, # BOX DRAWINGS LIGHT DOWN AND HORIZONTAL
0x00c3: 0x251c, # BOX DRAWINGS LIGHT VERTICAL AND RIGHT
0x00c4: 0x2500, # BOX DRAWINGS LIGHT HORIZONTAL
0x00c5: 0x253c, # BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL
0x00c6: 0x255e, # BOX DRAWINGS VERTICAL SINGLE AND RIGHT DOUBLE
0x00c7: 0x255f, # BOX DRAWINGS VERTICAL DOUBLE AND RIGHT SINGLE
0x00c8: 0x255a, # BOX DRAWINGS DOUBLE UP AND RIGHT
0x00c9: 0x2554, # BOX DRAWINGS DOUBLE DOWN AND RIGHT
0x00ca: 0x2569, # BOX DRAWINGS DOUBLE UP AND HORIZONTAL
0x00cb: 0x2566, # BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL
0x00cc: 0x2560, # BOX DRAWINGS DOUBLE VERTICAL AND RIGHT
0x00cd: 0x2550, # BOX DRAWINGS DOUBLE HORIZONTAL
0x00ce: 0x256c, # BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL
0x00cf: 0x2567, # BOX DRAWINGS UP SINGLE AND HORIZONTAL DOUBLE
0x00d0: 0x2568, # BOX DRAWINGS UP DOUBLE AND HORIZONTAL SINGLE
0x00d1: 0x2564, # BOX DRAWINGS DOWN SINGLE AND HORIZONTAL DOUBLE
0x00d2: 0x2565, # BOX DRAWINGS DOWN DOUBLE AND HORIZONTAL SINGLE
0x00d3: 0x2559, # BOX DRAWINGS UP DOUBLE AND RIGHT SINGLE
0x00d4: 0x2558, # BOX DRAWINGS UP SINGLE AND RIGHT DOUBLE
0x00d5: 0x2552, # BOX DRAWINGS DOWN SINGLE AND RIGHT DOUBLE
0x00d6: 0x2553, # BOX DRAWINGS DOWN DOUBLE AND RIGHT SINGLE
0x00d7: 0x256b, # BOX DRAWINGS VERTICAL DOUBLE AND HORIZONTAL SINGLE
0x00d8: 0x256a, # BOX DRAWINGS VERTICAL SINGLE AND HORIZONTAL DOUBLE
0x00d9: 0x2518, # BOX DRAWINGS LIGHT UP AND LEFT
0x00da: 0x250c, # BOX DRAWINGS LIGHT DOWN AND RIGHT
0x00db: 0x2588, # FULL BLOCK
0x00dc: 0x2584, # LOWER HALF BLOCK
0x00dd: 0x258c, # LEFT HALF BLOCK
0x00de: 0x2590, # RIGHT HALF BLOCK
0x00df: 0x2580, # UPPER HALF BLOCK
0x00e0: 0x03b1, # GREEK SMALL LETTER ALPHA
0x00e1: 0x00df, # LATIN SMALL LETTER SHARP S
0x00e2: 0x0393, # GREEK CAPITAL LETTER GAMMA
0x00e3: 0x03c0, # GREEK SMALL LETTER PI
0x00e4: 0x03a3, # GREEK CAPITAL LETTER SIGMA
0x00e5: 0x03c3, # GREEK SMALL LETTER SIGMA
0x00e6: 0x00b5, # MICRO SIGN
0x00e7: 0x03c4, # GREEK SMALL LETTER TAU
0x00e8: 0x03a6, # GREEK CAPITAL LETTER PHI
0x00e9: 0x0398, # GREEK CAPITAL LETTER THETA
0x00ea: 0x03a9, # GREEK CAPITAL LETTER OMEGA
0x00eb: 0x03b4, # GREEK SMALL LETTER DELTA
0x00ec: 0x221e, # INFINITY
0x00ed: 0x03c6, # GREEK SMALL LETTER PHI
0x00ee: 0x03b5, # GREEK SMALL LETTER EPSILON
0x00ef: 0x2229, # INTERSECTION
0x00f0: 0x2261, # IDENTICAL TO
0x00f1: 0x00b1, # PLUS-MINUS SIGN
0x00f2: 0x2265, # GREATER-THAN OR EQUAL TO
0x00f3: 0x2264, # LESS-THAN OR EQUAL TO
0x00f4: 0x2320, # TOP HALF INTEGRAL
0x00f5: 0x2321, # BOTTOM HALF INTEGRAL
0x00f6: 0x00f7, # DIVISION SIGN
0x00f7: 0x2248, # ALMOST EQUAL TO
0x00f8: 0x00b0, # DEGREE SIGN
0x00f9: 0x2219, # BULLET OPERATOR
0x00fa: 0x00b7, # MIDDLE DOT
0x00fb: 0x221a, # SQUARE ROOT
0x00fc: 0x207f, # SUPERSCRIPT LATIN SMALL LETTER N
0x00fd: 0x00b2, # SUPERSCRIPT TWO
0x00fe: 0x25a0, # BLACK SQUARE
0x00ff: 0x00a0, # NO-BREAK SPACE
})
### Decoding Table
decoding_table = (
u'\x00' # 0x0000 -> NULL
u'\x01' # 0x0001 -> START OF HEADING
u'\x02' # 0x0002 -> START OF TEXT
u'\x03' # 0x0003 -> END OF TEXT
u'\x04' # 0x0004 -> END OF TRANSMISSION
u'\x05' # 0x0005 -> ENQUIRY
u'\x06' # 0x0006 -> ACKNOWLEDGE
u'\x07' # 0x0007 -> BELL
u'\x08' # 0x0008 -> BACKSPACE
u'\t' # 0x0009 -> HORIZONTAL TABULATION
u'\n' # 0x000a -> LINE FEED
u'\x0b' # 0x000b -> VERTICAL TABULATION
u'\x0c' # 0x000c -> FORM FEED
u'\r' # 0x000d -> CARRIAGE RETURN
u'\x0e' # 0x000e -> SHIFT OUT
u'\x0f' # 0x000f -> SHIFT IN
u'\x10' # 0x0010 -> DATA LINK ESCAPE
u'\x11' # 0x0011 -> DEVICE CONTROL ONE
u'\x12' # 0x0012 -> DEVICE CONTROL TWO
u'\x13' # 0x0013 -> DEVICE CONTROL THREE
u'\x14' # 0x0014 -> DEVICE CONTROL FOUR
u'\x15' # 0x0015 -> NEGATIVE ACKNOWLEDGE
u'\x16' # 0x0016 -> SYNCHRONOUS IDLE
u'\x17' # 0x0017 -> END OF TRANSMISSION BLOCK
u'\x18' # 0x0018 -> CANCEL
u'\x19' # 0x0019 -> END OF MEDIUM
u'\x1a' # 0x001a -> SUBSTITUTE
u'\x1b' # 0x001b -> ESCAPE
u'\x1c' # 0x001c -> FILE SEPARATOR
u'\x1d' # 0x001d -> GROUP SEPARATOR
u'\x1e' # 0x001e -> RECORD SEPARATOR
u'\x1f' # 0x001f -> UNIT SEPARATOR
u' ' # 0x0020 -> SPACE
u'!' # 0x0021 -> EXCLAMATION MARK
u'"' # 0x0022 -> QUOTATION MARK
u'#' # 0x0023 -> NUMBER SIGN
u'$' # 0x0024 -> DOLLAR SIGN
u'%' # 0x0025 -> PERCENT SIGN
u'&' # 0x0026 -> AMPERSAND
u"'" # 0x0027 -> APOSTROPHE
u'(' # 0x0028 -> LEFT PARENTHESIS
u')' # 0x0029 -> RIGHT PARENTHESIS
u'*' # 0x002a -> ASTERISK
u'+' # 0x002b -> PLUS SIGN
u',' # 0x002c -> COMMA
u'-' # 0x002d -> HYPHEN-MINUS
u'.' # 0x002e -> FULL STOP
u'/' # 0x002f -> SOLIDUS
u'0' # 0x0030 -> DIGIT ZERO
u'1' # 0x0031 -> DIGIT ONE
u'2' # 0x0032 -> DIGIT TWO
u'3' # 0x0033 -> DIGIT THREE
u'4' # 0x0034 -> DIGIT FOUR
u'5' # 0x0035 -> DIGIT FIVE
u'6' # 0x0036 -> DIGIT SIX
u'7' # 0x0037 -> DIGIT SEVEN
u'8' # 0x0038 -> DIGIT EIGHT
u'9' # 0x0039 -> DIGIT NINE
u':' # 0x003a -> COLON
u';' # 0x003b -> SEMICOLON
u'<' # 0x003c -> LESS-THAN SIGN
u'=' # 0x003d -> EQUALS SIGN
u'>' # 0x003e -> GREATER-THAN SIGN
u'?' # 0x003f -> QUESTION MARK
u'@' # 0x0040 -> COMMERCIAL AT
u'A' # 0x0041 -> LATIN CAPITAL LETTER A
u'B' # 0x0042 -> LATIN CAPITAL LETTER B
u'C' # 0x0043 -> LATIN CAPITAL LETTER C
u'D' # 0x0044 -> LATIN CAPITAL LETTER D
u'E' # 0x0045 -> LATIN CAPITAL LETTER E
u'F' # 0x0046 -> LATIN CAPITAL LETTER F
u'G' # 0x0047 -> LATIN CAPITAL LETTER G
u'H' # 0x0048 -> LATIN CAPITAL LETTER H
u'I' # 0x0049 -> LATIN CAPITAL LETTER I
u'J' # 0x004a -> LATIN CAPITAL LETTER J
u'K' # 0x004b -> LATIN CAPITAL LETTER K
u'L' # 0x004c -> LATIN CAPITAL LETTER L
u'M' # 0x004d -> LATIN CAPITAL LETTER M
u'N' # 0x004e -> LATIN CAPITAL LETTER N
u'O' # 0x004f -> LATIN CAPITAL LETTER O
u'P' # 0x0050 -> LATIN CAPITAL LETTER P
u'Q' # 0x0051 -> LATIN CAPITAL LETTER Q
u'R' # 0x0052 -> LATIN CAPITAL LETTER R
u'S' # 0x0053 -> LATIN CAPITAL LETTER S
u'T' # 0x0054 -> LATIN CAPITAL LETTER T
u'U' # 0x0055 -> LATIN CAPITAL LETTER U
u'V' # 0x0056 -> LATIN CAPITAL LETTER V
u'W' # 0x0057 -> LATIN CAPITAL LETTER W
u'X' # 0x0058 -> LATIN CAPITAL LETTER X
u'Y' # 0x0059 -> LATIN CAPITAL LETTER Y
u'Z' # 0x005a -> LATIN CAPITAL LETTER Z
u'[' # 0x005b -> LEFT SQUARE BRACKET
u'\\' # 0x005c -> REVERSE SOLIDUS
u']' # 0x005d -> RIGHT SQUARE BRACKET
u'^' # 0x005e -> CIRCUMFLEX ACCENT
u'_' # 0x005f -> LOW LINE
u'`' # 0x0060 -> GRAVE ACCENT
u'a' # 0x0061 -> LATIN SMALL LETTER A
u'b' # 0x0062 -> LATIN SMALL LETTER B
u'c' # 0x0063 -> LATIN SMALL LETTER C
u'd' # 0x0064 -> LATIN SMALL LETTER D
u'e' # 0x0065 -> LATIN SMALL LETTER E
u'f' # 0x0066 -> LATIN SMALL LETTER F
u'g' # 0x0067 -> LATIN SMALL LETTER G
u'h' # 0x0068 -> LATIN SMALL LETTER H
u'i' # 0x0069 -> LATIN SMALL LETTER I
u'j' # 0x006a -> LATIN SMALL LETTER J
u'k' # 0x006b -> LATIN SMALL LETTER K
u'l' # 0x006c -> LATIN SMALL LETTER L
u'm' # 0x006d -> LATIN SMALL LETTER M
u'n' # 0x006e -> LATIN SMALL LETTER N
u'o' # 0x006f -> LATIN SMALL LETTER O
u'p' # 0x0070 -> LATIN SMALL LETTER P
u'q' # 0x0071 -> LATIN SMALL LETTER Q
u'r' # 0x0072 -> LATIN SMALL LETTER R
u's' # 0x0073 -> LATIN SMALL LETTER S
u't' # 0x0074 -> LATIN SMALL LETTER T
u'u' # 0x0075 -> LATIN SMALL LETTER U
u'v' # 0x0076 -> LATIN SMALL LETTER V
u'w' # 0x0077 -> LATIN SMALL LETTER W
u'x' # 0x0078 -> LATIN SMALL LETTER X
u'y' # 0x0079 -> LATIN SMALL LETTER Y
u'z' # 0x007a -> LATIN SMALL LETTER Z
u'{' # 0x007b -> LEFT CURLY BRACKET
u'|' # 0x007c -> VERTICAL LINE
u'}' # 0x007d -> RIGHT CURLY BRACKET
u'~' # 0x007e -> TILDE
u'\x7f' # 0x007f -> DELETE
u'\xc7' # 0x0080 -> LATIN CAPITAL LETTER C WITH CEDILLA
u'\xfc' # 0x0081 -> LATIN SMALL LETTER U WITH DIAERESIS
u'\xe9' # 0x0082 -> LATIN SMALL LETTER E WITH ACUTE
u'\xe2' # 0x0083 -> LATIN SMALL LETTER A WITH CIRCUMFLEX
u'\xe4' # 0x0084 -> LATIN SMALL LETTER A WITH DIAERESIS
u'\xe0' # 0x0085 -> LATIN SMALL LETTER A WITH GRAVE
u'\xe5' # 0x0086 -> LATIN SMALL LETTER A WITH RING ABOVE
u'\xe7' # 0x0087 -> LATIN SMALL LETTER C WITH CEDILLA
u'\xea' # 0x0088 -> LATIN SMALL LETTER E WITH CIRCUMFLEX
u'\xeb' # 0x0089 -> LATIN SMALL LETTER E WITH DIAERESIS
u'\xe8' # 0x008a -> LATIN SMALL LETTER E WITH GRAVE
u'\xef' # 0x008b -> LATIN SMALL LETTER I WITH DIAERESIS
u'\xee' # 0x008c -> LATIN SMALL LETTER I WITH CIRCUMFLEX
u'\xec' # 0x008d -> LATIN SMALL LETTER I WITH GRAVE
u'\xc4' # 0x008e -> LATIN CAPITAL LETTER A WITH DIAERESIS
u'\xc5' # 0x008f -> LATIN CAPITAL LETTER A WITH RING ABOVE
u'\xc9' # 0x0090 -> LATIN CAPITAL LETTER E WITH ACUTE
u'\xe6' # 0x0091 -> LATIN SMALL LIGATURE AE
u'\xc6' # 0x0092 -> LATIN CAPITAL LIGATURE AE
u'\xf4' # 0x0093 -> LATIN SMALL LETTER O WITH CIRCUMFLEX
u'\xf6' # 0x0094 -> LATIN SMALL LETTER O WITH DIAERESIS
u'\xf2' # 0x0095 -> LATIN SMALL LETTER O WITH GRAVE
u'\xfb' # 0x0096 -> LATIN SMALL LETTER U WITH CIRCUMFLEX
u'\xf9' # 0x0097 -> LATIN SMALL LETTER U WITH GRAVE
u'\xff' # 0x0098 -> LATIN SMALL LETTER Y WITH DIAERESIS
u'\xd6' # 0x0099 -> LATIN CAPITAL LETTER O WITH DIAERESIS
u'\xdc' # 0x009a -> LATIN CAPITAL LETTER U WITH DIAERESIS
u'\xf8' # 0x009b -> LATIN SMALL LETTER O WITH STROKE
u'\xa3' # 0x009c -> POUND SIGN
u'\xd8' # 0x009d -> LATIN CAPITAL LETTER O WITH STROKE
u'\u20a7' # 0x009e -> PESETA SIGN
u'\u0192' # 0x009f -> LATIN SMALL LETTER F WITH HOOK
u'\xe1' # 0x00a0 -> LATIN SMALL LETTER A WITH ACUTE
u'\xed' # 0x00a1 -> LATIN SMALL LETTER I WITH ACUTE
u'\xf3' # 0x00a2 -> LATIN SMALL LETTER O WITH ACUTE
u'\xfa' # 0x00a3 -> LATIN SMALL LETTER U WITH ACUTE
u'\xf1' # 0x00a4 -> LATIN SMALL LETTER N WITH TILDE
u'\xd1' # 0x00a5 -> LATIN CAPITAL LETTER N WITH TILDE
u'\xaa' # 0x00a6 -> FEMININE ORDINAL INDICATOR
u'\xba' # 0x00a7 -> MASCULINE ORDINAL INDICATOR
u'\xbf' # 0x00a8 -> INVERTED QUESTION MARK
u'\u2310' # 0x00a9 -> REVERSED NOT SIGN
u'\xac' # 0x00aa -> NOT SIGN
u'\xbd' # 0x00ab -> VULGAR FRACTION ONE HALF
u'\xbc' # 0x00ac -> VULGAR FRACTION ONE QUARTER
u'\xa1' # 0x00ad -> INVERTED EXCLAMATION MARK
u'\xab' # 0x00ae -> LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
u'\xa4' # 0x00af -> CURRENCY SIGN
u'\u2591' # 0x00b0 -> LIGHT SHADE
u'\u2592' # 0x00b1 -> MEDIUM SHADE
u'\u2593' # 0x00b2 -> DARK SHADE
u'\u2502' # 0x00b3 -> BOX DRAWINGS LIGHT VERTICAL
u'\u2524' # 0x00b4 -> BOX DRAWINGS LIGHT VERTICAL AND LEFT
u'\u2561' # 0x00b5 -> BOX DRAWINGS VERTICAL SINGLE AND LEFT DOUBLE
u'\u2562' # 0x00b6 -> BOX DRAWINGS VERTICAL DOUBLE AND LEFT SINGLE
u'\u2556' # 0x00b7 -> BOX DRAWINGS DOWN DOUBLE AND LEFT SINGLE
u'\u2555' # 0x00b8 -> BOX DRAWINGS DOWN SINGLE AND LEFT DOUBLE
u'\u2563' # 0x00b9 -> BOX DRAWINGS DOUBLE VERTICAL AND LEFT
u'\u2551' # 0x00ba -> BOX DRAWINGS DOUBLE VERTICAL
u'\u2557' # 0x00bb -> BOX DRAWINGS DOUBLE DOWN AND LEFT
u'\u255d' # 0x00bc -> BOX DRAWINGS DOUBLE UP AND LEFT
u'\u255c' # 0x00bd -> BOX DRAWINGS UP DOUBLE AND LEFT SINGLE
u'\u255b' # 0x00be -> BOX DRAWINGS UP SINGLE AND LEFT DOUBLE
u'\u2510' # 0x00bf -> BOX DRAWINGS LIGHT DOWN AND LEFT
u'\u2514' # 0x00c0 -> BOX DRAWINGS LIGHT UP AND RIGHT
u'\u2534' # 0x00c1 -> BOX DRAWINGS LIGHT UP AND HORIZONTAL
u'\u252c' # 0x00c2 -> BOX DRAWINGS LIGHT DOWN AND HORIZONTAL
u'\u251c' # 0x00c3 -> BOX DRAWINGS LIGHT VERTICAL AND RIGHT
u'\u2500' # 0x00c4 -> BOX DRAWINGS LIGHT HORIZONTAL
u'\u253c' # 0x00c5 -> BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL
u'\u255e' # 0x00c6 -> BOX DRAWINGS VERTICAL SINGLE AND RIGHT DOUBLE
u'\u255f' # 0x00c7 -> BOX DRAWINGS VERTICAL DOUBLE AND RIGHT SINGLE
u'\u255a' # 0x00c8 -> BOX DRAWINGS DOUBLE UP AND RIGHT
u'\u2554' # 0x00c9 -> BOX DRAWINGS DOUBLE DOWN AND RIGHT
u'\u2569' # 0x00ca -> BOX DRAWINGS DOUBLE UP AND HORIZONTAL
u'\u2566' # 0x00cb -> BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL
u'\u2560' # 0x00cc -> BOX DRAWINGS DOUBLE VERTICAL AND RIGHT
u'\u2550' # 0x00cd -> BOX DRAWINGS DOUBLE HORIZONTAL
u'\u256c' # 0x00ce -> BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL
u'\u2567' # 0x00cf -> BOX DRAWINGS UP SINGLE AND HORIZONTAL DOUBLE
u'\u2568' # 0x00d0 -> BOX DRAWINGS UP DOUBLE AND HORIZONTAL SINGLE
u'\u2564' # 0x00d1 -> BOX DRAWINGS DOWN SINGLE AND HORIZONTAL DOUBLE
u'\u2565' # 0x00d2 -> BOX DRAWINGS DOWN DOUBLE AND HORIZONTAL SINGLE
u'\u2559' # 0x00d3 -> BOX DRAWINGS UP DOUBLE AND RIGHT SINGLE
u'\u2558' # 0x00d4 -> BOX DRAWINGS UP SINGLE AND RIGHT DOUBLE
u'\u2552' # 0x00d5 -> BOX DRAWINGS DOWN SINGLE AND RIGHT DOUBLE
u'\u2553' # 0x00d6 -> BOX DRAWINGS DOWN DOUBLE AND RIGHT SINGLE
u'\u256b' # 0x00d7 -> BOX DRAWINGS VERTICAL DOUBLE AND HORIZONTAL SINGLE
u'\u256a' # 0x00d8 -> BOX DRAWINGS VERTICAL SINGLE AND HORIZONTAL DOUBLE
u'\u2518' # 0x00d9 -> BOX DRAWINGS LIGHT UP AND LEFT
u'\u250c' # 0x00da -> BOX DRAWINGS LIGHT DOWN AND RIGHT
u'\u2588' # 0x00db -> FULL BLOCK
u'\u2584' # 0x00dc -> LOWER HALF BLOCK
u'\u258c' # 0x00dd -> LEFT HALF BLOCK
u'\u2590' # 0x00de -> RIGHT HALF BLOCK
u'\u2580' # 0x00df -> UPPER HALF BLOCK
u'\u03b1' # 0x00e0 -> GREEK SMALL LETTER ALPHA
u'\xdf' # 0x00e1 -> LATIN SMALL LETTER SHARP S
u'\u0393' # 0x00e2 -> GREEK CAPITAL LETTER GAMMA
u'\u03c0' # 0x00e3 -> GREEK SMALL LETTER PI
u'\u03a3' # 0x00e4 -> GREEK CAPITAL LETTER SIGMA
u'\u03c3' # 0x00e5 -> GREEK SMALL LETTER SIGMA
u'\xb5' # 0x00e6 -> MICRO SIGN
u'\u03c4' # 0x00e7 -> GREEK SMALL LETTER TAU
u'\u03a6' # 0x00e8 -> GREEK CAPITAL LETTER PHI
u'\u0398' # 0x00e9 -> GREEK CAPITAL LETTER THETA
u'\u03a9' # 0x00ea -> GREEK CAPITAL LETTER OMEGA
u'\u03b4' # 0x00eb -> GREEK SMALL LETTER DELTA
u'\u221e' # 0x00ec -> INFINITY
u'\u03c6' # 0x00ed -> GREEK SMALL LETTER PHI
u'\u03b5' # 0x00ee -> GREEK SMALL LETTER EPSILON
u'\u2229' # 0x00ef -> INTERSECTION
u'\u2261' # 0x00f0 -> IDENTICAL TO
u'\xb1' # 0x00f1 -> PLUS-MINUS SIGN
u'\u2265' # 0x00f2 -> GREATER-THAN OR EQUAL TO
u'\u2264' # 0x00f3 -> LESS-THAN OR EQUAL TO
u'\u2320' # 0x00f4 -> TOP HALF INTEGRAL
u'\u2321' # 0x00f5 -> BOTTOM HALF INTEGRAL
u'\xf7' # 0x00f6 -> DIVISION SIGN
u'\u2248' # 0x00f7 -> ALMOST EQUAL TO
u'\xb0' # 0x00f8 -> DEGREE SIGN
u'\u2219' # 0x00f9 -> BULLET OPERATOR
u'\xb7' # 0x00fa -> MIDDLE DOT
u'\u221a' # 0x00fb -> SQUARE ROOT
u'\u207f' # 0x00fc -> SUPERSCRIPT LATIN SMALL LETTER N
u'\xb2' # 0x00fd -> SUPERSCRIPT TWO
u'\u25a0' # 0x00fe -> BLACK SQUARE
u'\xa0' # 0x00ff -> NO-BREAK SPACE
)
### Encoding Map
encoding_map = {
0x0000: 0x0000, # NULL
0x0001: 0x0001, # START OF HEADING
0x0002: 0x0002, # START OF TEXT
0x0003: 0x0003, # END OF TEXT
0x0004: 0x0004, # END OF TRANSMISSION
0x0005: 0x0005, # ENQUIRY
0x0006: 0x0006, # ACKNOWLEDGE
0x0007: 0x0007, # BELL
0x0008: 0x0008, # BACKSPACE
0x0009: 0x0009, # HORIZONTAL TABULATION
0x000a: 0x000a, # LINE FEED
0x000b: 0x000b, # VERTICAL TABULATION
0x000c: 0x000c, # FORM FEED
0x000d: 0x000d, # CARRIAGE RETURN
0x000e: 0x000e, # SHIFT OUT
0x000f: 0x000f, # SHIFT IN
0x0010: 0x0010, # DATA LINK ESCAPE
0x0011: 0x0011, # DEVICE CONTROL ONE
0x0012: 0x0012, # DEVICE CONTROL TWO
0x0013: 0x0013, # DEVICE CONTROL THREE
0x0014: 0x0014, # DEVICE CONTROL FOUR
0x0015: 0x0015, # NEGATIVE ACKNOWLEDGE
0x0016: 0x0016, # SYNCHRONOUS IDLE
0x0017: 0x0017, # END OF TRANSMISSION BLOCK
0x0018: 0x0018, # CANCEL
0x0019: 0x0019, # END OF MEDIUM
0x001a: 0x001a, # SUBSTITUTE
0x001b: 0x001b, # ESCAPE
0x001c: 0x001c, # FILE SEPARATOR
0x001d: 0x001d, # GROUP SEPARATOR
0x001e: 0x001e, # RECORD SEPARATOR
0x001f: 0x001f, # UNIT SEPARATOR
0x0020: 0x0020, # SPACE
0x0021: 0x0021, # EXCLAMATION MARK
0x0022: 0x0022, # QUOTATION MARK
0x0023: 0x0023, # NUMBER SIGN
0x0024: 0x0024, # DOLLAR SIGN
0x0025: 0x0025, # PERCENT SIGN
0x0026: 0x0026, # AMPERSAND
0x0027: 0x0027, # APOSTROPHE
0x0028: 0x0028, # LEFT PARENTHESIS
0x0029: 0x0029, # RIGHT PARENTHESIS
0x002a: 0x002a, # ASTERISK
0x002b: 0x002b, # PLUS SIGN
0x002c: 0x002c, # COMMA
0x002d: 0x002d, # HYPHEN-MINUS
0x002e: 0x002e, # FULL STOP
0x002f: 0x002f, # SOLIDUS
0x0030: 0x0030, # DIGIT ZERO
0x0031: 0x0031, # DIGIT ONE
0x0032: 0x0032, # DIGIT TWO
0x0033: 0x0033, # DIGIT THREE
0x0034: 0x0034, # DIGIT FOUR
0x0035: 0x0035, # DIGIT FIVE
0x0036: 0x0036, # DIGIT SIX
0x0037: 0x0037, # DIGIT SEVEN
0x0038: 0x0038, # DIGIT EIGHT
0x0039: 0x0039, # DIGIT NINE
0x003a: 0x003a, # COLON
0x003b: 0x003b, # SEMICOLON
0x003c: 0x003c, # LESS-THAN SIGN
0x003d: 0x003d, # EQUALS SIGN
0x003e: 0x003e, # GREATER-THAN SIGN
0x003f: 0x003f, # QUESTION MARK
0x0040: 0x0040, # COMMERCIAL AT
0x0041: 0x0041, # LATIN CAPITAL LETTER A
0x0042: 0x0042, # LATIN CAPITAL LETTER B
0x0043: 0x0043, # LATIN CAPITAL LETTER C
0x0044: 0x0044, # LATIN CAPITAL LETTER D
0x0045: 0x0045, # LATIN CAPITAL LETTER E
0x0046: 0x0046, # LATIN CAPITAL LETTER F
0x0047: 0x0047, # LATIN CAPITAL LETTER G
0x0048: 0x0048, # LATIN CAPITAL LETTER H
0x0049: 0x0049, # LATIN CAPITAL LETTER I
0x004a: 0x004a, # LATIN CAPITAL LETTER J
0x004b: 0x004b, # LATIN CAPITAL LETTER K
0x004c: 0x004c, # LATIN CAPITAL LETTER L
0x004d: 0x004d, # LATIN CAPITAL LETTER M
0x004e: 0x004e, # LATIN CAPITAL LETTER N
0x004f: 0x004f, # LATIN CAPITAL LETTER O
0x0050: 0x0050, # LATIN CAPITAL LETTER P
0x0051: 0x0051, # LATIN CAPITAL LETTER Q
0x0052: 0x0052, # LATIN CAPITAL LETTER R
0x0053: 0x0053, # LATIN CAPITAL LETTER S
0x0054: 0x0054, # LATIN CAPITAL LETTER T
0x0055: 0x0055, # LATIN CAPITAL LETTER U
0x0056: 0x0056, # LATIN CAPITAL LETTER V
0x0057: 0x0057, # LATIN CAPITAL LETTER W
0x0058: 0x0058, # LATIN CAPITAL LETTER X
0x0059: 0x0059, # LATIN CAPITAL LETTER Y
0x005a: 0x005a, # LATIN CAPITAL LETTER Z
0x005b: 0x005b, # LEFT SQUARE BRACKET
0x005c: 0x005c, # REVERSE SOLIDUS
0x005d: 0x005d, # RIGHT SQUARE BRACKET
0x005e: 0x005e, # CIRCUMFLEX ACCENT
0x005f: 0x005f, # LOW LINE
0x0060: 0x0060, # GRAVE ACCENT
0x0061: 0x0061, # LATIN SMALL LETTER A
0x0062: 0x0062, # LATIN SMALL LETTER B
0x0063: 0x0063, # LATIN SMALL LETTER C
0x0064: 0x0064, # LATIN SMALL LETTER D
0x0065: 0x0065, # LATIN SMALL LETTER E
0x0066: 0x0066, # LATIN SMALL LETTER F
0x0067: 0x0067, # LATIN SMALL LETTER G
0x0068: 0x0068, # LATIN SMALL LETTER H
0x0069: 0x0069, # LATIN SMALL LETTER I
0x006a: 0x006a, # LATIN SMALL LETTER J
0x006b: 0x006b, # LATIN SMALL LETTER K
0x006c: 0x006c, # LATIN SMALL LETTER L
0x006d: 0x006d, # LATIN SMALL LETTER M
0x006e: 0x006e, # LATIN SMALL LETTER N
0x006f: 0x006f, # LATIN SMALL LETTER O
0x0070: 0x0070, # LATIN SMALL LETTER P
0x0071: 0x0071, # LATIN SMALL LETTER Q
0x0072: 0x0072, # LATIN SMALL LETTER R
0x0073: 0x0073, # LATIN SMALL LETTER S
0x0074: 0x0074, # LATIN SMALL LETTER T
0x0075: 0x0075, # LATIN SMALL LETTER U
0x0076: 0x0076, # LATIN SMALL LETTER V
0x0077: 0x0077, # LATIN SMALL LETTER W
0x0078: 0x0078, # LATIN SMALL LETTER X
0x0079: 0x0079, # LATIN SMALL LETTER Y
0x007a: 0x007a, # LATIN SMALL LETTER Z
0x007b: 0x007b, # LEFT CURLY BRACKET
0x007c: 0x007c, # VERTICAL LINE
0x007d: 0x007d, # RIGHT CURLY BRACKET
0x007e: 0x007e, # TILDE
0x007f: 0x007f, # DELETE
0x00a0: 0x00ff, # NO-BREAK SPACE
0x00a1: 0x00ad, # INVERTED EXCLAMATION MARK
0x00a3: 0x009c, # POUND SIGN
0x00a4: 0x00af, # CURRENCY SIGN
0x00aa: 0x00a6, # FEMININE ORDINAL INDICATOR
0x00ab: 0x00ae, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
0x00ac: 0x00aa, # NOT SIGN
0x00b0: 0x00f8, # DEGREE SIGN
0x00b1: 0x00f1, # PLUS-MINUS SIGN
0x00b2: 0x00fd, # SUPERSCRIPT TWO
0x00b5: 0x00e6, # MICRO SIGN
0x00b7: 0x00fa, # MIDDLE DOT
0x00ba: 0x00a7, # MASCULINE ORDINAL INDICATOR
0x00bc: 0x00ac, # VULGAR FRACTION ONE QUARTER
0x00bd: 0x00ab, # VULGAR FRACTION ONE HALF
0x00bf: 0x00a8, # INVERTED QUESTION MARK
0x00c4: 0x008e, # LATIN CAPITAL LETTER A WITH DIAERESIS
0x00c5: 0x008f, # LATIN CAPITAL LETTER A WITH RING ABOVE
0x00c6: 0x0092, # LATIN CAPITAL LIGATURE AE
0x00c7: 0x0080, # LATIN CAPITAL LETTER C WITH CEDILLA
0x00c9: 0x0090, # LATIN CAPITAL LETTER E WITH ACUTE
0x00d1: 0x00a5, # LATIN CAPITAL LETTER N WITH TILDE
0x00d6: 0x0099, # LATIN CAPITAL LETTER O WITH DIAERESIS
0x00d8: 0x009d, # LATIN CAPITAL LETTER O WITH STROKE
0x00dc: 0x009a, # LATIN CAPITAL LETTER U WITH DIAERESIS
0x00df: 0x00e1, # LATIN SMALL LETTER SHARP S
0x00e0: 0x0085, # LATIN SMALL LETTER A WITH GRAVE
0x00e1: 0x00a0, # LATIN SMALL LETTER A WITH ACUTE
0x00e2: 0x0083, # LATIN SMALL LETTER A WITH CIRCUMFLEX
0x00e4: 0x0084, # LATIN SMALL LETTER A WITH DIAERESIS
0x00e5: 0x0086, # LATIN SMALL LETTER A WITH RING ABOVE
0x00e6: 0x0091, # LATIN SMALL LIGATURE AE
0x00e7: 0x0087, # LATIN SMALL LETTER C WITH CEDILLA
0x00e8: 0x008a, # LATIN SMALL LETTER E WITH GRAVE
0x00e9: 0x0082, # LATIN SMALL LETTER E WITH ACUTE
0x00ea: 0x0088, # LATIN SMALL LETTER E WITH CIRCUMFLEX
0x00eb: 0x0089, # LATIN SMALL LETTER E WITH DIAERESIS
0x00ec: 0x008d, # LATIN SMALL LETTER I WITH GRAVE
0x00ed: 0x00a1, # LATIN SMALL LETTER I WITH ACUTE
0x00ee: 0x008c, # LATIN SMALL LETTER I WITH CIRCUMFLEX
0x00ef: 0x008b, # LATIN SMALL LETTER I WITH DIAERESIS
0x00f1: 0x00a4, # LATIN SMALL LETTER N WITH TILDE
0x00f2: 0x0095, # LATIN SMALL LETTER O WITH GRAVE
0x00f3: 0x00a2, # LATIN SMALL LETTER O WITH ACUTE
0x00f4: 0x0093, # LATIN SMALL LETTER O WITH CIRCUMFLEX
0x00f6: 0x0094, # LATIN SMALL LETTER O WITH DIAERESIS
0x00f7: 0x00f6, # DIVISION SIGN
0x00f8: 0x009b, # LATIN SMALL LETTER O WITH STROKE
0x00f9: 0x0097, # LATIN SMALL LETTER U WITH GRAVE
0x00fa: 0x00a3, # LATIN SMALL LETTER U WITH ACUTE
0x00fb: 0x0096, # LATIN SMALL LETTER U WITH CIRCUMFLEX
0x00fc: 0x0081, # LATIN SMALL LETTER U WITH DIAERESIS
0x00ff: 0x0098, # LATIN SMALL LETTER Y WITH DIAERESIS
0x0192: 0x009f, # LATIN SMALL LETTER F WITH HOOK
0x0393: 0x00e2, # GREEK CAPITAL LETTER GAMMA
0x0398: 0x00e9, # GREEK CAPITAL LETTER THETA
0x03a3: 0x00e4, # GREEK CAPITAL LETTER SIGMA
0x03a6: 0x00e8, # GREEK CAPITAL LETTER PHI
0x03a9: 0x00ea, # GREEK CAPITAL LETTER OMEGA
0x03b1: 0x00e0, # GREEK SMALL LETTER ALPHA
0x03b4: 0x00eb, # GREEK SMALL LETTER DELTA
0x03b5: 0x00ee, # GREEK SMALL LETTER EPSILON
0x03c0: 0x00e3, # GREEK SMALL LETTER PI
0x03c3: 0x00e5, # GREEK SMALL LETTER SIGMA
0x03c4: 0x00e7, # GREEK SMALL LETTER TAU
0x03c6: 0x00ed, # GREEK SMALL LETTER PHI
0x207f: 0x00fc, # SUPERSCRIPT LATIN SMALL LETTER N
0x20a7: 0x009e, # PESETA SIGN
0x2219: 0x00f9, # BULLET OPERATOR
0x221a: 0x00fb, # SQUARE ROOT
0x221e: 0x00ec, # INFINITY
0x2229: 0x00ef, # INTERSECTION
0x2248: 0x00f7, # ALMOST EQUAL TO
0x2261: 0x00f0, # IDENTICAL TO
0x2264: 0x00f3, # LESS-THAN OR EQUAL TO
0x2265: 0x00f2, # GREATER-THAN OR EQUAL TO
0x2310: 0x00a9, # REVERSED NOT SIGN
0x2320: 0x00f4, # TOP HALF INTEGRAL
0x2321: 0x00f5, # BOTTOM HALF INTEGRAL
0x2500: 0x00c4, # BOX DRAWINGS LIGHT HORIZONTAL
0x2502: 0x00b3, # BOX DRAWINGS LIGHT VERTICAL
0x250c: 0x00da, # BOX DRAWINGS LIGHT DOWN AND RIGHT
0x2510: 0x00bf, # BOX DRAWINGS LIGHT DOWN AND LEFT
0x2514: 0x00c0, # BOX DRAWINGS LIGHT UP AND RIGHT
0x2518: 0x00d9, # BOX DRAWINGS LIGHT UP AND LEFT
0x251c: 0x00c3, # BOX DRAWINGS LIGHT VERTICAL AND RIGHT
0x2524: 0x00b4, # BOX DRAWINGS LIGHT VERTICAL AND LEFT
0x252c: 0x00c2, # BOX DRAWINGS LIGHT DOWN AND HORIZONTAL
0x2534: 0x00c1, # BOX DRAWINGS LIGHT UP AND HORIZONTAL
0x253c: 0x00c5, # BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL
0x2550: 0x00cd, # BOX DRAWINGS DOUBLE HORIZONTAL
0x2551: 0x00ba, # BOX DRAWINGS DOUBLE VERTICAL
0x2552: 0x00d5, # BOX DRAWINGS DOWN SINGLE AND RIGHT DOUBLE
0x2553: 0x00d6, # BOX DRAWINGS DOWN DOUBLE AND RIGHT SINGLE
0x2554: 0x00c9, # BOX DRAWINGS DOUBLE DOWN AND RIGHT
0x2555: 0x00b8, # BOX DRAWINGS DOWN SINGLE AND LEFT DOUBLE
0x2556: 0x00b7, # BOX DRAWINGS DOWN DOUBLE AND LEFT SINGLE
0x2557: 0x00bb, # BOX DRAWINGS DOUBLE DOWN AND LEFT
0x2558: 0x00d4, # BOX DRAWINGS UP SINGLE AND RIGHT DOUBLE
0x2559: 0x00d3, # BOX DRAWINGS UP DOUBLE AND RIGHT SINGLE
0x255a: 0x00c8, # BOX DRAWINGS DOUBLE UP AND RIGHT
0x255b: 0x00be, # BOX DRAWINGS UP SINGLE AND LEFT DOUBLE
0x255c: 0x00bd, # BOX DRAWINGS UP DOUBLE AND LEFT SINGLE
0x255d: 0x00bc, # BOX DRAWINGS DOUBLE UP AND LEFT
0x255e: 0x00c6, # BOX DRAWINGS VERTICAL SINGLE AND RIGHT DOUBLE
0x255f: 0x00c7, # BOX DRAWINGS VERTICAL DOUBLE AND RIGHT SINGLE
0x2560: 0x00cc, # BOX DRAWINGS DOUBLE VERTICAL AND RIGHT
0x2561: 0x00b5, # BOX DRAWINGS VERTICAL SINGLE AND LEFT DOUBLE
0x2562: 0x00b6, # BOX DRAWINGS VERTICAL DOUBLE AND LEFT SINGLE
0x2563: 0x00b9, # BOX DRAWINGS DOUBLE VERTICAL AND LEFT
0x2564: 0x00d1, # BOX DRAWINGS DOWN SINGLE AND HORIZONTAL DOUBLE
0x2565: 0x00d2, # BOX DRAWINGS DOWN DOUBLE AND HORIZONTAL SINGLE
0x2566: 0x00cb, # BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL
0x2567: 0x00cf, # BOX DRAWINGS UP SINGLE AND HORIZONTAL DOUBLE
0x2568: 0x00d0, # BOX DRAWINGS UP DOUBLE AND HORIZONTAL SINGLE
0x2569: 0x00ca, # BOX DRAWINGS DOUBLE UP AND HORIZONTAL
0x256a: 0x00d8, # BOX DRAWINGS VERTICAL SINGLE AND HORIZONTAL DOUBLE
0x256b: 0x00d7, # BOX DRAWINGS VERTICAL DOUBLE AND HORIZONTAL SINGLE
0x256c: 0x00ce, # BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL
0x2580: 0x00df, # UPPER HALF BLOCK
0x2584: 0x00dc, # LOWER HALF BLOCK
0x2588: 0x00db, # FULL BLOCK
0x258c: 0x00dd, # LEFT HALF BLOCK
0x2590: 0x00de, # RIGHT HALF BLOCK
0x2591: 0x00b0, # LIGHT SHADE
0x2592: 0x00b1, # MEDIUM SHADE
0x2593: 0x00b2, # DARK SHADE
0x25a0: 0x00fe, # BLACK SQUARE
}
|
bsd-3-clause
|
[
624,
2018,
17660,
12340,
13732,
4046,
687,
283,
27839,
4149,
15,
17233,
51,
2161,
15,
4222,
15,
2890,
15102,
14,
17715,
7,
543,
486,
2143,
67,
14,
647,
14,
199,
199,
624,
23662,
199,
199,
646,
6010,
199,
199,
5680,
13732,
15913,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
2550,
12,
2991,
63,
1130,
9,
339,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
2550,
12,
12796,
63,
1224,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
277,
14,
2550,
12,
2991,
63,
1130,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
277,
14,
2550,
12,
12796,
63,
1224,
2788,
16,
61,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
1850,
15102,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
199,
199,
5680,
27368,
9672,
199,
199,
12796,
63,
1130,
275,
6010,
14,
1875,
63,
5582,
63,
807,
8,
1842,
8,
3912,
430,
199,
12796,
63,
1130,
14,
873,
2561,
272,
378,
88,
23686,
26,
378,
88,
383,
67,
23,
12,
258,
327,
221,
1948,
2678,
1578,
445,
1663,
15609,
272,
378,
88,
383,
2835,
26,
378,
88,
383,
3003,
12,
258,
327,
221,
1948,
2516,
1578,
738,
1663,
9680,
272,
378,
88,
383,
2564,
26,
378,
88,
383,
69,
25,
12,
258,
327,
221,
1948,
2516,
1578,
662,
1663,
8123,
272,
378,
88,
383,
2658,
26,
378,
88,
383,
69,
18,
12,
258,
327,
221,
1948,
2516,
1578,
437,
1663,
10040,
272,
378,
88,
30935,
26,
378,
88,
383,
69,
20,
12,
258,
327,
221,
1948,
2516,
1578,
437,
1663,
9680,
272,
378,
88,
383,
2426,
26,
378,
88,
383,
69,
16,
12,
258,
327,
221,
1948,
2516,
1578,
437,
1663,
11457,
272,
378,
88,
31743,
26,
378,
88,
383,
69,
21,
12,
258,
327,
221,
1948,
2516,
1578,
437,
1663,
24809,
16054,
272,
378,
88,
383,
1555,
26,
378,
88,
383,
69,
23,
12,
258,
327,
221,
1948,
2516,
1578,
445,
1663,
15609,
272,
378,
88,
31419,
26,
378,
88,
383,
4489,
12,
258,
327,
221,
1948,
2516,
1578,
662,
1663,
10040,
272,
378,
88,
383,
1407,
26,
378,
88,
383,
2871,
12,
258,
327,
221,
1948,
2516,
1578,
662,
1663,
9680,
272,
378,
88,
8662,
65,
26,
378,
88,
383,
69,
24,
12,
258,
327,
221,
1948,
2516,
1578,
662,
1663,
11457,
272,
378,
88,
8662,
66,
26,
378,
88,
383,
2829,
12,
258,
327,
221,
1948,
2516,
1578,
473,
1663,
9680,
272,
378,
88,
8662,
67,
26,
378,
88,
383,
1024,
12,
258,
327,
221,
1948,
2516,
1578,
473,
1663,
10040,
272,
378,
88,
8662,
68,
26,
378,
88,
383,
825,
12,
258,
327,
221,
1948,
2516,
1578,
473,
1663,
11457,
272,
378,
88,
8662,
69,
26,
378,
88,
383,
67,
20,
12,
258,
327,
221,
1948,
2678,
1578,
437,
1663,
9680,
272,
378,
88,
8662,
70,
26,
378,
88,
383,
67,
21,
12,
258,
327,
221,
1948,
2678,
1578,
437,
1663,
24809,
16054,
272,
378,
88,
28875,
26,
378,
88,
383,
67,
25,
12,
258,
327,
221,
1948,
2678,
1578,
662,
1663,
8123,
272,
378,
88,
383,
3328,
26,
378,
88,
383,
69,
22,
12,
258,
327,
221,
1948,
2516,
27427,
24475,
272,
378,
88,
383,
2942,
26,
378,
88,
383,
67,
22,
12,
258,
327,
221,
1948,
2678,
27427,
24475,
272,
378,
88,
383,
3129,
26,
378,
88,
383,
70,
20,
12,
258,
327,
221,
1948,
2516,
1578,
593,
1663,
10040,
272,
378,
88,
383,
2635,
26,
378,
88,
383,
70,
22,
12,
258,
327,
221,
1948,
2516,
1578,
593,
1663,
9680,
272,
378,
88,
383,
2720,
26,
378,
88,
383,
70,
18,
12,
258,
327,
221,
1948,
2516,
1578,
593,
1663,
11457,
272,
378,
88,
383,
2534,
26,
378,
88,
383,
4675,
12,
258,
327,
221,
1948,
2516,
1578,
738,
1663,
10040,
272,
378,
88,
383,
2576,
26,
378,
88,
383,
70,
25,
12,
258,
327,
221,
1948,
2516,
1578,
738,
1663,
11457,
272,
378,
88,
383,
2905,
26,
378,
88,
383,
556,
12,
258,
327,
221,
1948,
2516,
1578,
1488,
1663,
9680,
272,
378,
88,
29660,
26,
378,
88,
383,
68,
22,
12,
258,
327,
221,
1948,
2678,
1578,
593,
1663,
9680,
272,
378,
88,
8581,
65,
26,
378,
88,
383,
3833,
12,
258,
327,
221,
1948,
2678,
1578,
738,
1663,
9680,
272,
378,
88,
8581,
66,
26,
378,
88,
383,
70,
24,
12,
258,
327,
221,
1948,
2516,
1578,
593,
1663,
22755,
272,
378,
88,
8581,
67,
26,
378,
88,
383,
65,
19,
12,
258,
327,
221,
3625,
6131,
5056,
272,
378,
88,
8581,
68,
26,
378,
88,
383,
68,
24,
12,
258,
327,
221,
1948,
2678,
1578,
593,
1663,
22755,
272,
378,
88,
8581,
69,
26,
378,
88,
1165,
65,
23,
12,
258,
327,
221,
510,
654,
15808,
5056,
272,
378,
88,
8581,
70,
26,
378,
88,
614,
2942,
12,
258,
327,
221,
1948,
2516,
1578,
481,
1663,
7781,
3593,
272,
378,
88,
383,
65,
16,
26,
378,
88,
383,
69,
17,
12,
258,
327,
221,
1948,
2516,
1578,
437,
1663,
8123,
272,
378,
88,
383,
65,
17,
26,
378,
88,
383,
379,
12,
258,
327,
221,
1948,
2516,
1578,
473,
1663,
8123,
272,
378,
88,
383,
65,
18,
26,
378,
88,
383,
70,
19,
12,
258,
327,
221,
1948,
2516,
1578,
593,
1663,
8123,
272,
378,
88,
383,
65
] |
[
2018,
17660,
12340,
13732,
4046,
687,
283,
27839,
4149,
15,
17233,
51,
2161,
15,
4222,
15,
2890,
15102,
14,
17715,
7,
543,
486,
2143,
67,
14,
647,
14,
199,
199,
624,
23662,
199,
199,
646,
6010,
199,
199,
5680,
13732,
15913,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
2550,
12,
2991,
63,
1130,
9,
339,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
2550,
12,
12796,
63,
1224,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
277,
14,
2550,
12,
2991,
63,
1130,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
277,
14,
2550,
12,
12796,
63,
1224,
2788,
16,
61,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
1850,
15102,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
199,
199,
5680,
27368,
9672,
199,
199,
12796,
63,
1130,
275,
6010,
14,
1875,
63,
5582,
63,
807,
8,
1842,
8,
3912,
430,
199,
12796,
63,
1130,
14,
873,
2561,
272,
378,
88,
23686,
26,
378,
88,
383,
67,
23,
12,
258,
327,
221,
1948,
2678,
1578,
445,
1663,
15609,
272,
378,
88,
383,
2835,
26,
378,
88,
383,
3003,
12,
258,
327,
221,
1948,
2516,
1578,
738,
1663,
9680,
272,
378,
88,
383,
2564,
26,
378,
88,
383,
69,
25,
12,
258,
327,
221,
1948,
2516,
1578,
662,
1663,
8123,
272,
378,
88,
383,
2658,
26,
378,
88,
383,
69,
18,
12,
258,
327,
221,
1948,
2516,
1578,
437,
1663,
10040,
272,
378,
88,
30935,
26,
378,
88,
383,
69,
20,
12,
258,
327,
221,
1948,
2516,
1578,
437,
1663,
9680,
272,
378,
88,
383,
2426,
26,
378,
88,
383,
69,
16,
12,
258,
327,
221,
1948,
2516,
1578,
437,
1663,
11457,
272,
378,
88,
31743,
26,
378,
88,
383,
69,
21,
12,
258,
327,
221,
1948,
2516,
1578,
437,
1663,
24809,
16054,
272,
378,
88,
383,
1555,
26,
378,
88,
383,
69,
23,
12,
258,
327,
221,
1948,
2516,
1578,
445,
1663,
15609,
272,
378,
88,
31419,
26,
378,
88,
383,
4489,
12,
258,
327,
221,
1948,
2516,
1578,
662,
1663,
10040,
272,
378,
88,
383,
1407,
26,
378,
88,
383,
2871,
12,
258,
327,
221,
1948,
2516,
1578,
662,
1663,
9680,
272,
378,
88,
8662,
65,
26,
378,
88,
383,
69,
24,
12,
258,
327,
221,
1948,
2516,
1578,
662,
1663,
11457,
272,
378,
88,
8662,
66,
26,
378,
88,
383,
2829,
12,
258,
327,
221,
1948,
2516,
1578,
473,
1663,
9680,
272,
378,
88,
8662,
67,
26,
378,
88,
383,
1024,
12,
258,
327,
221,
1948,
2516,
1578,
473,
1663,
10040,
272,
378,
88,
8662,
68,
26,
378,
88,
383,
825,
12,
258,
327,
221,
1948,
2516,
1578,
473,
1663,
11457,
272,
378,
88,
8662,
69,
26,
378,
88,
383,
67,
20,
12,
258,
327,
221,
1948,
2678,
1578,
437,
1663,
9680,
272,
378,
88,
8662,
70,
26,
378,
88,
383,
67,
21,
12,
258,
327,
221,
1948,
2678,
1578,
437,
1663,
24809,
16054,
272,
378,
88,
28875,
26,
378,
88,
383,
67,
25,
12,
258,
327,
221,
1948,
2678,
1578,
662,
1663,
8123,
272,
378,
88,
383,
3328,
26,
378,
88,
383,
69,
22,
12,
258,
327,
221,
1948,
2516,
27427,
24475,
272,
378,
88,
383,
2942,
26,
378,
88,
383,
67,
22,
12,
258,
327,
221,
1948,
2678,
27427,
24475,
272,
378,
88,
383,
3129,
26,
378,
88,
383,
70,
20,
12,
258,
327,
221,
1948,
2516,
1578,
593,
1663,
10040,
272,
378,
88,
383,
2635,
26,
378,
88,
383,
70,
22,
12,
258,
327,
221,
1948,
2516,
1578,
593,
1663,
9680,
272,
378,
88,
383,
2720,
26,
378,
88,
383,
70,
18,
12,
258,
327,
221,
1948,
2516,
1578,
593,
1663,
11457,
272,
378,
88,
383,
2534,
26,
378,
88,
383,
4675,
12,
258,
327,
221,
1948,
2516,
1578,
738,
1663,
10040,
272,
378,
88,
383,
2576,
26,
378,
88,
383,
70,
25,
12,
258,
327,
221,
1948,
2516,
1578,
738,
1663,
11457,
272,
378,
88,
383,
2905,
26,
378,
88,
383,
556,
12,
258,
327,
221,
1948,
2516,
1578,
1488,
1663,
9680,
272,
378,
88,
29660,
26,
378,
88,
383,
68,
22,
12,
258,
327,
221,
1948,
2678,
1578,
593,
1663,
9680,
272,
378,
88,
8581,
65,
26,
378,
88,
383,
3833,
12,
258,
327,
221,
1948,
2678,
1578,
738,
1663,
9680,
272,
378,
88,
8581,
66,
26,
378,
88,
383,
70,
24,
12,
258,
327,
221,
1948,
2516,
1578,
593,
1663,
22755,
272,
378,
88,
8581,
67,
26,
378,
88,
383,
65,
19,
12,
258,
327,
221,
3625,
6131,
5056,
272,
378,
88,
8581,
68,
26,
378,
88,
383,
68,
24,
12,
258,
327,
221,
1948,
2678,
1578,
593,
1663,
22755,
272,
378,
88,
8581,
69,
26,
378,
88,
1165,
65,
23,
12,
258,
327,
221,
510,
654,
15808,
5056,
272,
378,
88,
8581,
70,
26,
378,
88,
614,
2942,
12,
258,
327,
221,
1948,
2516,
1578,
481,
1663,
7781,
3593,
272,
378,
88,
383,
65,
16,
26,
378,
88,
383,
69,
17,
12,
258,
327,
221,
1948,
2516,
1578,
437,
1663,
8123,
272,
378,
88,
383,
65,
17,
26,
378,
88,
383,
379,
12,
258,
327,
221,
1948,
2516,
1578,
473,
1663,
8123,
272,
378,
88,
383,
65,
18,
26,
378,
88,
383,
70,
19,
12,
258,
327,
221,
1948,
2516,
1578,
593,
1663,
8123,
272,
378,
88,
383,
65,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
GiladE/birde
|
venv/lib/python2.7/site-packages/static.py
|
5
|
16038
|
#!/usr/bin/env python
"""
Copyright (C) 2012 Roman Mohr <roman@fenkhuber.at>
"""
"""static - A stupidly simple WSGI way to serve static (or mixed) content.
(See the docstrings of the various functions and classes.)
Copyright (C) 2006-2009 Luke Arno - http://lukearno.com/
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to:
The Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
Luke Arno can be found at http://lukearno.com/
"""
import mimetypes
import email.utils as rfc822
import time
import string
import sys
from os import path, stat
from wsgiref import util
from wsgiref.headers import Headers
from wsgiref.simple_server import make_server
from optparse import OptionParser
try:
from pkg_resources import resource_filename, Requirement
except:
pass
try:
import kid
except:
pass
try:
from genshi.template import MarkupTemplate
except:
pass
if sys.version < '3':
import codecs
def u(x):
return codecs.unicode_escape_decode(x)[0]
else:
def u(x):
return x
class MagicError(Exception):
pass
def _encode(string, encoding):
if sys.version_info[0] > 2:
return string.encode(encoding=encoding, errors='strict')
else:
if type(u('')) == type(string):
string = string.encode(encoding)
return string
def _decode(string, encoding):
if sys.version_info[0] > 2:
return string.decode(encoding=encoding, errors='strict')
else:
return string
def _open(filename, encoding):
if sys.version_info[0] > 2:
return open(filename, 'r', encoding=encoding, errors='strict')
else:
return open(filename, 'rb')
class StatusApp:
"""Used by WSGI apps to return some HTTP status."""
def __init__(self, status, message=None, encoding=sys.getdefaultencoding()):
self.status = status
self.encoding = encoding
if message is None:
self.message = status
else:
self.message = message
def __call__(self, environ, start_response, headers=[]):
if self.message:
Headers(headers).add_header('Content-type', 'text/plain')
start_response(self.status, headers)
if environ['REQUEST_METHOD'] == 'HEAD':
return [_encode("", self.econding)]
else:
return [_encode(self.message, self.encoding)]
class Cling(object):
"""A stupidly simple way to serve static content via WSGI.
Serve the file of the same path as PATH_INFO in self.datadir.
Look up the Content-type in self.content_types by extension
or use 'text/plain' if the extension is not found.
Serve up the contents of the file or delegate to self.not_found.
"""
block_size = 16 * 4096
index_file = 'index.html'
not_found = StatusApp('404 Not Found')
not_modified = StatusApp('304 Not Modified', "")
moved_permanently = StatusApp('301 Moved Permanently')
method_not_allowed = StatusApp('405 Method Not Allowed')
def __init__(self, root, **kw):
"""Just set the root and any other attribs passes via **kw."""
self.root = root
self.encoding = sys.getdefaultencoding()
for k, v in kw.items():
setattr(self, k, v)
def __call__(self, environ, start_response):
"""Respond to a request when called in the usual WSGI way."""
if environ['REQUEST_METHOD'] not in ('GET', 'HEAD'):
headers = [('Allow', 'GET, HEAD')]
return self.method_not_allowed(environ, start_response, headers)
path_info = environ.get('PATH_INFO', '')
full_path = self._full_path(path_info)
if not self._is_under_root(full_path):
return self.not_found(environ, start_response)
if path.isdir(full_path):
if full_path[-1] != '/' or full_path == self.root:
location = util.request_uri(environ, include_query=False) + '/'
if environ.get('QUERY_STRING'):
location += '?' + environ.get('QUERY_STRING')
headers = [('Location', location)]
return self.moved_permanently(environ, start_response, headers)
else:
full_path = self._full_path(path_info + self.index_file)
content_type = self._guess_type(full_path)
try:
etag, last_modified = self._conditions(full_path, environ)
headers = [('Date', rfc822.formatdate(time.time())),
('Last-Modified', last_modified),
('ETag', etag)]
if_modified = environ.get('HTTP_IF_MODIFIED_SINCE')
if if_modified and (rfc822.parsedate(if_modified)
>= rfc822.parsedate(last_modified)):
return self.not_modified(environ, start_response, headers)
if_none = environ.get('HTTP_IF_NONE_MATCH')
if if_none and (if_none == '*' or etag in if_none):
return self.not_modified(environ, start_response, headers)
file_like = self._file_like(full_path)
headers.append(('Content-Type', content_type))
start_response("200 OK", headers)
if environ['REQUEST_METHOD'] == 'GET':
return self._body(full_path, environ, file_like)
else:
return ['']
except (IOError, OSError) as e:
print(e)
return self.not_found(environ, start_response)
def _full_path(self, path_info):
"""Return the full path from which to read."""
return self.root + path_info
def _is_under_root(self, full_path):
"""Guard against arbitrary file retrieval."""
if (path.abspath(full_path) + path.sep)\
.startswith(path.abspath(self.root) + path.sep):
return True
else:
return False
def _guess_type(self, full_path):
"""Guess the mime type using the mimetypes module."""
return mimetypes.guess_type(full_path)[0] or 'text/plain'
def _conditions(self, full_path, environ):
"""Return a tuple of etag, last_modified by mtime from stat."""
mtime = stat(full_path).st_mtime
return str(mtime), rfc822.formatdate(mtime)
def _file_like(self, full_path):
"""Return the appropriate file object."""
return open(full_path, 'rb')
def _body(self, full_path, environ, file_like):
"""Return an iterator over the body of the response."""
way_to_send = environ.get('wsgi.file_wrapper', iter_and_close)
return way_to_send(file_like, self.block_size)
def iter_and_close(file_like, block_size):
"""Yield file contents by block then close the file."""
while 1:
try:
block = file_like.read(block_size)
if block:
yield block
else:
raise StopIteration
except StopIteration as si:
file_like.close()
return
def cling_wrap(package_name, dir_name, **kw):
"""Return a Cling that serves from the given package and dir_name.
This uses pkg_resources.resource_filename which is not the
recommended way, since it extracts the files.
I think this works fine unless you have some _very_ serious
requirements for static content, in which case you probably
shouldn't be serving it through a WSGI app, IMHO. YMMV.
"""
resource = Requirement.parse(package_name)
return Cling(resource_filename(resource, dir_name), **kw)
class Shock(Cling):
"""A stupidly simple way to serve up mixed content.
Serves static content just like Cling (it's superclass)
except that it process content with the first matching
magic from self.magics if any apply.
See Cling and classes with "Magic" in their names in this module.
If you are using Shock with the StringMagic class for instance:
shock = Shock('/data', magics=[StringMagic(food='cheese')])
Let's say you have a file called /data/foo.txt.stp containing one line:
"I love to eat $food!"
When you do a GET on /foo.txt you will see this in your browser:
"I love to eat cheese!"
This is really nice if you have a color variable in your css files or
something trivial like that. It seems silly to create or change a
handful of objects for a couple of dynamic bits of text.
"""
magics = ()
def _match_magic(self, full_path):
"""Return the first magic that matches this path or None."""
for magic in self.magics:
if magic.matches(full_path):
return magic
def _full_path(self, path_info):
"""Return the full path from which to read."""
full_path = self.root + path_info
if path.exists(full_path):
return full_path
else:
for magic in self.magics:
if path.exists(magic.new_path(full_path)):
return magic.new_path(full_path)
else:
return full_path
def _guess_type(self, full_path):
"""Guess the mime type magically or using the mimetypes module."""
magic = self._match_magic(full_path)
if magic is not None:
return (mimetypes.guess_type(magic.old_path(full_path))[0]
or 'text/plain')
else:
return mimetypes.guess_type(full_path)[0] or 'text/plain'
def _conditions(self, full_path, environ):
"""Return Etag and Last-Modified values defaults to now for both."""
magic = self._match_magic(full_path)
if magic is not None:
return magic.conditions(full_path, environ)
else:
mtime = stat(full_path).st_mtime
return str(mtime), rfc822.formatdate(mtime)
def _file_like(self, full_path):
"""Return the appropriate file object."""
magic = self._match_magic(full_path)
if magic is not None:
return magic.file_like(full_path, self.encoding)
else:
return open(full_path, 'rb')
def _body(self, full_path, environ, file_like):
"""Return an iterator over the body of the response."""
magic = self._match_magic(full_path)
if magic is not None:
return [_encode(s,self.encoding) for s in magic.body(environ,
file_like)]
else:
way_to_send = environ.get('wsgi.file_wrapper', iter_and_close)
return way_to_send(file_like, self.block_size)
class BaseMagic(object):
"""Base class for magic file handling.
Really a do nothing if you were to use this directly.
In a strait forward case you would just override .extension and body().
(See StringMagic in this module for a simple example of subclassing.)
In a more complex case you may need to override many or all methods.
"""
extension = ''
def exists(self, full_path):
"""Check that self.new_path(full_path) exists."""
if path.exists(self.new_path(full_path)):
return self.new_path(full_path)
def new_path(self, full_path):
"""Add the self.extension to the path."""
return full_path + self.extension
def old_path(self, full_path):
"""Remove self.extension from path or raise MagicError."""
if self.matches(full_path):
return full_path[:-len(self.extension)]
else:
raise MagicError("Path does not match this magic.")
def matches(self, full_path):
"""Check that path ends with self.extension."""
if full_path.endswith(self.extension):
return full_path
def conditions(self, full_path, environ):
"""Return Etag and Last-Modified values (based on mtime)."""
mtime = int(time.time())
return str(mtime), rfc822.formatdate(mtime)
def file_like(self, full_path, encoding):
"""Return a file object for path."""
return _open(full_path, encoding)
def body(self, environ, file_like):
"""Return an iterator over the body of the response."""
return [file_like.read()]
class StringMagic(BaseMagic):
"""Magic to replace variables in file contents using string.Template.
Using this requires Python2.4.
"""
extension = '.stp'
safe = False
def __init__(self, **variables):
"""Keyword arguments populate self.variables."""
self.variables = variables
def body(self, environ, file_like):
"""Pass environ and self.variables in to template.
self.variables overrides environ so that suprises in environ don't
cause unexpected output if you are passing a value in explicitly.
"""
variables = environ.copy()
variables.update(self.variables)
template = string.Template(file_like.read())
if self.safe is True:
return [template.safe_substitute(variables)]
else:
return [template.substitute(variables)]
class KidMagic(StringMagic):
"""Like StringMagic only using the Kid templating language.
Using this requires Kid: http://kid.lesscode.org/
"""
extension = '.kid'
def body(self, environ, full_path):
"""Pass environ and **self.variables into the template."""
template = kid.Template(file=full_path,
environ=environ,
**self.variables)
return [template.serialize()]
class GenshiMagic(StringMagic):
"""Like StringMagic only using the Genshi templating language.
Using this requires Genshi
"""
extension = '.genshi'
def body(self, environ, full_path):
"""Pass environ and **self.variables into the template."""
template = MarkupTemplate(full_path.read())
variables = self.variables.copy()
variables["environ"] = environ
return [template.generate(**variables)
.render('html', doctype='html')]
def command():
parser = OptionParser(usage="%prog DIR [HOST][:][PORT]",
version="static 0.3.6")
options, args = parser.parse_args()
if len(args) in (1, 2):
if len(args) == 2:
parts = args[1].split(":")
if len(parts) == 1:
host = parts[0]
port = None
elif len(parts) == 2:
host, port = parts
else:
sys.exit("Invalid host:port specification.")
elif len(args) == 1:
host, port = None, None
if not host:
host = '0.0.0.0'
if not port:
port = 9999
try:
port = int(port)
except:
sys.exit("Invalid host:port specification.")
app = Cling(args[0])
try:
make_server(host, port, app).serve_forever()
except KeyboardInterrupt as ki:
print("Cio, baby!")
except:
sys.exit("Problem initializing server.")
else:
parser.print_help(sys.stderr)
sys.exit(1)
def test():
from wsgiref.validate import validator
magics = (StringMagic(title="String Test"),
KidMagic(title="Kid Test"), GenshiMagic(title="Genshi Test"))
app = Shock('testdata/pub', magics=magics)
try:
make_server('localhost', 9999, validator(app)).serve_forever()
except KeyboardInterrupt as ki:
print("Ciao, baby!")
if __name__ == '__main__':
test()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
7384,
334,
35,
9,
6029,
820,
21604,
3930,
6271,
665,
20971,
32,
70,
13762,
72,
10400,
14,
292,
30,
199,
624,
199,
199,
624,
1986,
446,
437,
410,
31596,
590,
3486,
9279,
4340,
370,
14062,
2955,
334,
269,
13492,
9,
1564,
14,
199,
199,
8,
9295,
314,
20964,
402,
314,
7750,
3423,
436,
3992,
4959,
199,
199,
7384,
334,
35,
9,
8315,
13,
8664,
30936,
415,
1952,
889,
446,
1455,
921,
10836,
415,
285,
889,
14,
957,
15,
199,
199,
2765,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
8951,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3761,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
1023,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
2765,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
44,
6350,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3761,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
26,
199,
199,
1918,
2868,
2290,
2752,
12,
3277,
2020,
199,
2869,
11236,
14259,
12,
12066,
11844,
12,
199,
34,
7797,
12,
4828,
221,
11315,
13,
10067,
12,
8217,
14,
199,
199,
18176,
415,
1952,
889,
883,
506,
1911,
737,
1455,
921,
10836,
415,
285,
889,
14,
957,
15,
199,
199,
624,
199,
199,
646,
13290,
199,
646,
3031,
14,
1208,
465,
18158,
10228,
199,
646,
900,
199,
646,
1059,
199,
646,
984,
199,
504,
747,
492,
931,
12,
5672,
199,
504,
12464,
1121,
492,
4884,
199,
504,
12464,
1121,
14,
2139,
492,
21391,
199,
504,
12464,
1121,
14,
4129,
63,
1000,
492,
1852,
63,
1000,
199,
504,
8691,
492,
13491,
199,
199,
893,
26,
272,
687,
5496,
63,
4435,
492,
2073,
63,
1501,
12,
25013,
199,
2590,
26,
272,
986,
199,
199,
893,
26,
272,
492,
1022,
344,
199,
2590,
26,
272,
986,
199,
199,
893,
26,
272,
687,
3805,
19377,
14,
1160,
492,
17504,
4231,
199,
2590,
26,
272,
986,
199,
199,
692,
984,
14,
1023,
665,
283,
19,
356,
272,
492,
6010,
339,
347,
399,
8,
88,
304,
267,
372,
6010,
14,
2975,
63,
3765,
63,
2708,
8,
88,
2788,
16,
61,
199,
2836,
26,
272,
347,
399,
8,
88,
304,
267,
372,
671,
421,
199,
533,
603,
6573,
547,
8,
1726,
304,
272,
986,
421,
199,
318,
485,
2143,
8,
875,
12,
2644,
304,
272,
340,
984,
14,
1023,
63,
815,
59,
16,
61,
690,
499,
26,
267,
372,
1059,
14,
2143,
8,
2991,
29,
2991,
12,
2552,
534,
4768,
358,
272,
587,
26,
267,
340,
730,
8,
85,
30991,
508,
730,
8,
875,
304,
288,
1059,
275,
1059,
14,
2143,
8,
2991,
9,
267,
372,
1059,
421,
199,
318,
485,
2708,
8,
875,
12,
2644,
304,
272,
340,
984,
14,
1023,
63,
815,
59,
16,
61,
690,
499,
26,
267,
372,
1059,
14,
2708,
8,
2991,
29,
2991,
12,
2552,
534,
4768,
358,
272,
587,
26,
267,
372,
1059,
421,
199,
318,
485,
1490,
8,
1501,
12,
2644,
304,
272,
340,
984,
14,
1023,
63,
815,
59,
16,
61,
690,
499,
26,
267,
372,
1551,
8,
1501,
12,
283,
82,
297,
2644,
29,
2991,
12,
2552,
534,
4768,
358,
272,
587,
26,
267,
372,
1551,
8,
1501,
12,
283,
4848,
358,
421,
199,
533,
9795,
2640,
26,
339,
408,
9167,
701,
9279,
8686,
370,
372,
2005,
3101,
2004,
1041,
339,
347,
636,
826,
721,
277,
12,
2004,
12,
1245,
29,
403,
12,
2644,
29,
1274,
14,
362,
27205,
28139,
5109,
267,
291,
14,
1205,
275,
2004,
267,
291,
14,
2991,
275,
2644,
267,
340,
1245,
365,
488,
26,
288,
291,
14,
1188,
275,
2004,
267,
587,
26,
288,
291,
14,
1188,
275,
1245,
339,
347,
636,
1250,
721,
277,
12,
6160,
12,
1343,
63,
1310,
12,
2323,
17894,
267,
340,
291,
14,
1188,
26,
288,
21391,
8,
2139,
680,
525,
63,
1291,
360,
2714,
13,
466,
297,
283,
505,
15,
6104,
358,
267,
1343,
63,
1310,
8,
277,
14,
1205,
12,
2323,
9,
267,
340,
6160,
459,
6780,
63,
9977,
418,
508,
283,
5211,
356,
288,
372,
15500,
2143,
12398,
291,
14,
69,
388,
1098,
1874,
267,
587,
26,
288,
372,
15500,
2143,
8,
277,
14,
1188,
12,
291,
14,
2991,
1874,
421,
199,
533,
445,
2983,
8,
785,
304,
339,
408,
33,
410,
31596,
590,
3486,
4340,
370,
14062,
2955,
1564,
4799,
9279,
14,
339,
3739,
432,
314,
570,
402,
314,
2011,
931,
465,
15097,
63,
4531,
315,
291,
14,
18259,
14,
339,
12077,
1536,
314,
6646,
13,
466,
315,
291,
14,
1317,
63,
1313,
701,
3329,
272,
503,
675,
283,
505,
15,
6104,
7,
340,
314,
3329,
365,
440,
1911,
14,
339,
3739,
432,
1536,
314,
4072,
402,
314,
570,
503,
13080,
370,
291,
14,
1397,
63,
4214,
14,
272,
408,
339,
1853,
63,
890,
275,
3193,
627,
17125,
272,
1478,
63,
493,
275,
283,
1080,
14,
1360,
7,
272,
440,
63,
4214,
275,
9795,
2640,
360,
5188,
2832,
2643,
358,
272,
440,
63,
5540,
275,
9795,
2640,
360,
8533,
2832,
22016,
297,
6899,
272,
12155,
63,
19904,
590,
275,
9795,
2640,
360,
8507,
6445,
3492,
11433,
590,
358,
272,
1083,
63,
1397,
63,
6541,
275,
9795,
2640,
360,
15770,
9075,
2832,
27301,
358,
339,
347,
636,
826,
721,
277,
12,
1738,
12,
1011,
829,
304,
267,
408,
22850,
663,
314,
1738,
436,
1263,
1163,
737,
19577,
14933,
4799,
1011,
829,
1041,
267,
291,
14,
1231,
275,
1738,
267,
291,
14,
2991,
275,
984,
14,
362,
27205,
28139,
342,
398,
367,
1022,
12,
373,
315,
4775,
14,
1744,
837,
288,
5371,
8,
277,
12,
1022,
12,
373,
9,
339,
347,
636,
1250,
721,
277,
12,
6160,
12,
1343,
63,
1310,
304,
267,
408,
1322,
31717,
370,
282,
1056,
1380,
2797,
315,
314,
20195,
9279,
4340,
1041,
267,
340,
6160,
459,
6780,
63,
9977,
418,
440,
315
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
7384,
334,
35,
9,
6029,
820,
21604,
3930,
6271,
665,
20971,
32,
70,
13762,
72,
10400,
14,
292,
30,
199,
624,
199,
199,
624,
1986,
446,
437,
410,
31596,
590,
3486,
9279,
4340,
370,
14062,
2955,
334,
269,
13492,
9,
1564,
14,
199,
199,
8,
9295,
314,
20964,
402,
314,
7750,
3423,
436,
3992,
4959,
199,
199,
7384,
334,
35,
9,
8315,
13,
8664,
30936,
415,
1952,
889,
446,
1455,
921,
10836,
415,
285,
889,
14,
957,
15,
199,
199,
2765,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
8951,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3761,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
1023,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
2765,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
44,
6350,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3761,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
26,
199,
199,
1918,
2868,
2290,
2752,
12,
3277,
2020,
199,
2869,
11236,
14259,
12,
12066,
11844,
12,
199,
34,
7797,
12,
4828,
221,
11315,
13,
10067,
12,
8217,
14,
199,
199,
18176,
415,
1952,
889,
883,
506,
1911,
737,
1455,
921,
10836,
415,
285,
889,
14,
957,
15,
199,
199,
624,
199,
199,
646,
13290,
199,
646,
3031,
14,
1208,
465,
18158,
10228,
199,
646,
900,
199,
646,
1059,
199,
646,
984,
199,
504,
747,
492,
931,
12,
5672,
199,
504,
12464,
1121,
492,
4884,
199,
504,
12464,
1121,
14,
2139,
492,
21391,
199,
504,
12464,
1121,
14,
4129,
63,
1000,
492,
1852,
63,
1000,
199,
504,
8691,
492,
13491,
199,
199,
893,
26,
272,
687,
5496,
63,
4435,
492,
2073,
63,
1501,
12,
25013,
199,
2590,
26,
272,
986,
199,
199,
893,
26,
272,
492,
1022,
344,
199,
2590,
26,
272,
986,
199,
199,
893,
26,
272,
687,
3805,
19377,
14,
1160,
492,
17504,
4231,
199,
2590,
26,
272,
986,
199,
199,
692,
984,
14,
1023,
665,
283,
19,
356,
272,
492,
6010,
339,
347,
399,
8,
88,
304,
267,
372,
6010,
14,
2975,
63,
3765,
63,
2708,
8,
88,
2788,
16,
61,
199,
2836,
26,
272,
347,
399,
8,
88,
304,
267,
372,
671,
421,
199,
533,
603,
6573,
547,
8,
1726,
304,
272,
986,
421,
199,
318,
485,
2143,
8,
875,
12,
2644,
304,
272,
340,
984,
14,
1023,
63,
815,
59,
16,
61,
690,
499,
26,
267,
372,
1059,
14,
2143,
8,
2991,
29,
2991,
12,
2552,
534,
4768,
358,
272,
587,
26,
267,
340,
730,
8,
85,
30991,
508,
730,
8,
875,
304,
288,
1059,
275,
1059,
14,
2143,
8,
2991,
9,
267,
372,
1059,
421,
199,
318,
485,
2708,
8,
875,
12,
2644,
304,
272,
340,
984,
14,
1023,
63,
815,
59,
16,
61,
690,
499,
26,
267,
372,
1059,
14,
2708,
8,
2991,
29,
2991,
12,
2552,
534,
4768,
358,
272,
587,
26,
267,
372,
1059,
421,
199,
318,
485,
1490,
8,
1501,
12,
2644,
304,
272,
340,
984,
14,
1023,
63,
815,
59,
16,
61,
690,
499,
26,
267,
372,
1551,
8,
1501,
12,
283,
82,
297,
2644,
29,
2991,
12,
2552,
534,
4768,
358,
272,
587,
26,
267,
372,
1551,
8,
1501,
12,
283,
4848,
358,
421,
199,
533,
9795,
2640,
26,
339,
408,
9167,
701,
9279,
8686,
370,
372,
2005,
3101,
2004,
1041,
339,
347,
636,
826,
721,
277,
12,
2004,
12,
1245,
29,
403,
12,
2644,
29,
1274,
14,
362,
27205,
28139,
5109,
267,
291,
14,
1205,
275,
2004,
267,
291,
14,
2991,
275,
2644,
267,
340,
1245,
365,
488,
26,
288,
291,
14,
1188,
275,
2004,
267,
587,
26,
288,
291,
14,
1188,
275,
1245,
339,
347,
636,
1250,
721,
277,
12,
6160,
12,
1343,
63,
1310,
12,
2323,
17894,
267,
340,
291,
14,
1188,
26,
288,
21391,
8,
2139,
680,
525,
63,
1291,
360,
2714,
13,
466,
297,
283,
505,
15,
6104,
358,
267,
1343,
63,
1310,
8,
277,
14,
1205,
12,
2323,
9,
267,
340,
6160,
459,
6780,
63,
9977,
418,
508,
283,
5211,
356,
288,
372,
15500,
2143,
12398,
291,
14,
69,
388,
1098,
1874,
267,
587,
26,
288,
372,
15500,
2143,
8,
277,
14,
1188,
12,
291,
14,
2991,
1874,
421,
199,
533,
445,
2983,
8,
785,
304,
339,
408,
33,
410,
31596,
590,
3486,
4340,
370,
14062,
2955,
1564,
4799,
9279,
14,
339,
3739,
432,
314,
570,
402,
314,
2011,
931,
465,
15097,
63,
4531,
315,
291,
14,
18259,
14,
339,
12077,
1536,
314,
6646,
13,
466,
315,
291,
14,
1317,
63,
1313,
701,
3329,
272,
503,
675,
283,
505,
15,
6104,
7,
340,
314,
3329,
365,
440,
1911,
14,
339,
3739,
432,
1536,
314,
4072,
402,
314,
570,
503,
13080,
370,
291,
14,
1397,
63,
4214,
14,
272,
408,
339,
1853,
63,
890,
275,
3193,
627,
17125,
272,
1478,
63,
493,
275,
283,
1080,
14,
1360,
7,
272,
440,
63,
4214,
275,
9795,
2640,
360,
5188,
2832,
2643,
358,
272,
440,
63,
5540,
275,
9795,
2640,
360,
8533,
2832,
22016,
297,
6899,
272,
12155,
63,
19904,
590,
275,
9795,
2640,
360,
8507,
6445,
3492,
11433,
590,
358,
272,
1083,
63,
1397,
63,
6541,
275,
9795,
2640,
360,
15770,
9075,
2832,
27301,
358,
339,
347,
636,
826,
721,
277,
12,
1738,
12,
1011,
829,
304,
267,
408,
22850,
663,
314,
1738,
436,
1263,
1163,
737,
19577,
14933,
4799,
1011,
829,
1041,
267,
291,
14,
1231,
275,
1738,
267,
291,
14,
2991,
275,
984,
14,
362,
27205,
28139,
342,
398,
367,
1022,
12,
373,
315,
4775,
14,
1744,
837,
288,
5371,
8,
277,
12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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
roadmapper/ansible
|
lib/ansible/module_utils/network/iosxr/providers/providers.py
|
114
|
3943
|
#
# (c) 2019, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#
import json
from threading import RLock
from ansible.module_utils.six import itervalues
from ansible.module_utils.network.common.utils import to_list
from ansible.module_utils.network.common.config import NetworkConfig
_registered_providers = {}
_provider_lock = RLock()
def register_provider(network_os, module_name):
def wrapper(cls):
_provider_lock.acquire()
try:
if network_os not in _registered_providers:
_registered_providers[network_os] = {}
for ct in cls.supported_connections:
if ct not in _registered_providers[network_os]:
_registered_providers[network_os][ct] = {}
for item in to_list(module_name):
for entry in itervalues(_registered_providers[network_os]):
entry[item] = cls
finally:
_provider_lock.release()
return cls
return wrapper
def get(network_os, module_name, connection_type):
network_os_providers = _registered_providers.get(network_os)
if network_os_providers is None:
raise ValueError('unable to find a suitable provider for this module')
if connection_type not in network_os_providers:
raise ValueError('provider does not support this connection type')
elif module_name not in network_os_providers[connection_type]:
raise ValueError('could not find a suitable provider for this module')
return network_os_providers[connection_type][module_name]
class ProviderBase(object):
supported_connections = ()
def __init__(self, params, connection=None, check_mode=False):
self.params = params
self.connection = connection
self.check_mode = check_mode
@property
def capabilities(self):
if not hasattr(self, '_capabilities'):
resp = self.from_json(self.connection.get_capabilities())
setattr(self, '_capabilities', resp)
return getattr(self, '_capabilities')
def get_value(self, path):
params = self.params.copy()
for key in path.split('.'):
params = params[key]
return params
def get_facts(self, subset=None):
raise NotImplementedError(self.__class__.__name__)
def edit_config(self):
raise NotImplementedError(self.__class__.__name__)
class CliProvider(ProviderBase):
supported_connections = ('network_cli',)
@property
def capabilities(self):
if not hasattr(self, '_capabilities'):
resp = self.from_json(self.connection.get_capabilities())
setattr(self, '_capabilities', resp)
return getattr(self, '_capabilities')
def get_config_context(self, config, path, indent=1):
if config is not None:
netcfg = NetworkConfig(indent=indent, contents=config)
try:
config = netcfg.get_block_config(to_list(path))
except ValueError:
config = None
return config
def render(self, config=None):
raise NotImplementedError(self.__class__.__name__)
def cli(self, command):
try:
if not hasattr(self, '_command_output'):
setattr(self, '_command_output', {})
return self._command_output[command]
except KeyError:
out = self.connection.get(command)
try:
out = json.loads(out)
except ValueError:
pass
self._command_output[command] = out
return out
def get_facts(self, subset=None):
return self.populate()
def edit_config(self, config=None):
commands = self.render(config)
if commands and self.check_mode is False:
self.connection.edit_config(commands)
return commands
|
gpl-3.0
|
[
3,
199,
3,
334,
67,
9,
20312,
12,
2622,
701,
9572,
13002,
12,
12864,
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,
3,
199,
646,
2022,
199,
199,
504,
5796,
492,
820,
6432,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
24451,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
2330,
14,
1208,
492,
370,
63,
513,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
2330,
14,
888,
492,
7220,
2028,
421,
199,
63,
11616,
63,
9710,
275,
1052,
199,
63,
3780,
63,
831,
275,
820,
6432,
342,
421,
199,
318,
2274,
63,
3780,
8,
1200,
63,
736,
12,
859,
63,
354,
304,
272,
347,
4975,
8,
1886,
304,
267,
485,
3780,
63,
831,
14,
8174,
342,
267,
862,
26,
288,
340,
2784,
63,
736,
440,
315,
485,
11616,
63,
9710,
26,
355,
485,
11616,
63,
9710,
59,
1200,
63,
736,
61,
275,
1052,
288,
367,
9428,
315,
843,
14,
4946,
63,
7995,
26,
355,
340,
9428,
440,
315,
485,
11616,
63,
9710,
59,
1200,
63,
736,
2189,
490,
485,
11616,
63,
9710,
59,
1200,
63,
736,
1527,
319,
61,
275,
1052,
288,
367,
1242,
315,
370,
63,
513,
8,
578,
63,
354,
304,
355,
367,
2397,
315,
24451,
1547,
11616,
63,
9710,
59,
1200,
63,
736,
4682,
490,
2397,
59,
1053,
61,
275,
843,
267,
3753,
26,
288,
485,
3780,
63,
831,
14,
3221,
342,
267,
372,
843,
272,
372,
4975,
421,
199,
318,
664,
8,
1200,
63,
736,
12,
859,
63,
354,
12,
1950,
63,
466,
304,
272,
2784,
63,
736,
63,
9710,
275,
485,
11616,
63,
9710,
14,
362,
8,
1200,
63,
736,
9,
272,
340,
2784,
63,
736,
63,
9710,
365,
488,
26,
267,
746,
1722,
360,
17200,
370,
2342,
282,
11233,
5022,
367,
642,
859,
358,
272,
340,
1950,
63,
466,
440,
315,
2784,
63,
736,
63,
9710,
26,
267,
746,
1722,
360,
3780,
1630,
440,
2291,
642,
1950,
730,
358,
272,
916,
859,
63,
354,
440,
315,
2784,
63,
736,
63,
9710,
59,
2105,
63,
466,
2189,
267,
746,
1722,
360,
15153,
440,
2342,
282,
11233,
5022,
367,
642,
859,
358,
272,
372,
2784,
63,
736,
63,
9710,
59,
2105,
63,
466,
1527,
578,
63,
354,
61,
421,
199,
533,
18489,
1563,
8,
785,
304,
339,
3748,
63,
7995,
275,
6248,
339,
347,
636,
826,
721,
277,
12,
1862,
12,
1950,
29,
403,
12,
1104,
63,
632,
29,
797,
304,
267,
291,
14,
1162,
275,
1862,
267,
291,
14,
2105,
275,
1950,
267,
291,
14,
1074,
63,
632,
275,
1104,
63,
632,
339,
768,
1829,
272,
347,
14918,
8,
277,
304,
267,
340,
440,
2688,
8,
277,
12,
2513,
10732,
735,
288,
3085,
275,
291,
14,
504,
63,
1001,
8,
277,
14,
2105,
14,
362,
63,
10732,
1012,
288,
5371,
8,
277,
12,
2513,
10732,
297,
3085,
9,
267,
372,
2519,
8,
277,
12,
2513,
10732,
358,
339,
347,
664,
63,
585,
8,
277,
12,
931,
304,
267,
1862,
275,
291,
14,
1162,
14,
1574,
342,
267,
367,
790,
315,
931,
14,
1294,
26461,
288,
1862,
275,
1862,
59,
498,
61,
267,
372,
1862,
339,
347,
664,
63,
5047,
8,
277,
12,
10026,
29,
403,
304,
267,
746,
4279,
8,
277,
855,
533,
4914,
354,
3368,
339,
347,
5283,
63,
888,
8,
277,
304,
267,
746,
4279,
8,
277,
855,
533,
4914,
354,
3368,
421,
199,
533,
445,
317,
6663,
8,
6663,
1563,
304,
339,
3748,
63,
7995,
275,
661,
1200,
63,
2764,
9538,
339,
768,
1829,
272,
347,
14918,
8,
277,
304,
267,
340,
440,
2688,
8,
277,
12,
2513,
10732,
735,
288,
3085,
275,
291,
14,
504,
63,
1001,
8,
277,
14,
2105,
14,
362,
63,
10732,
1012,
288,
5371,
8,
277,
12,
2513,
10732,
297,
3085,
9,
267,
372,
2519,
8,
277,
12,
2513,
10732,
358,
339,
347,
664,
63,
888,
63,
1100,
8,
277,
12,
1101,
12,
931,
12,
4363,
29,
17,
304,
267,
340,
1101,
365,
440,
488,
26,
288,
1851,
4128,
275,
7220,
2028,
8,
3724,
29,
3724,
12,
4072,
29,
888,
9,
288,
862,
26,
355,
1101,
275,
1851,
4128,
14,
362,
63,
1457,
63,
888,
8,
475,
63,
513,
8,
515,
430,
288,
871,
1722,
26,
355,
1101,
275,
488,
288,
372,
1101,
339,
347,
3795,
8,
277,
12,
1101,
29,
403,
304,
267,
746,
4279,
8,
277,
855,
533,
4914,
354,
3368,
339,
347,
5053,
8,
277,
12,
1414,
304,
267,
862,
26,
288,
340,
440,
2688,
8,
277,
12,
2513,
1531,
63,
1199,
735,
355,
5371,
8,
277,
12,
2513,
1531,
63,
1199,
297,
5009,
288,
372,
291,
423,
1531,
63,
1199,
59,
1531,
61,
267,
871,
4067,
26,
288,
734,
275,
291,
14,
2105,
14,
362,
8,
1531,
9,
288,
862,
26,
355,
734,
275,
2022,
14,
3640,
8,
548,
9,
288,
871,
1722,
26,
355,
986,
288,
291,
423,
1531,
63,
1199,
59,
1531,
61,
275,
734,
288,
372,
734,
339,
347,
664,
63,
5047,
8,
277,
12,
10026,
29,
403,
304,
267,
372,
291,
14,
13817,
342,
339,
347,
5283,
63,
888,
8,
277,
12,
1101,
29,
403,
304,
267,
3718,
275,
291,
14,
3352,
8,
888,
9,
267,
340,
3718,
436,
291,
14,
1074,
63,
632,
365,
756,
26,
288,
291,
14,
2105,
14,
3773,
63,
888,
8,
4405,
9,
267,
372,
3718,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
334,
67,
9,
20312,
12,
2622,
701,
9572,
13002,
12,
12864,
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,
3,
199,
646,
2022,
199,
199,
504,
5796,
492,
820,
6432,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
24451,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
2330,
14,
1208,
492,
370,
63,
513,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
2330,
14,
888,
492,
7220,
2028,
421,
199,
63,
11616,
63,
9710,
275,
1052,
199,
63,
3780,
63,
831,
275,
820,
6432,
342,
421,
199,
318,
2274,
63,
3780,
8,
1200,
63,
736,
12,
859,
63,
354,
304,
272,
347,
4975,
8,
1886,
304,
267,
485,
3780,
63,
831,
14,
8174,
342,
267,
862,
26,
288,
340,
2784,
63,
736,
440,
315,
485,
11616,
63,
9710,
26,
355,
485,
11616,
63,
9710,
59,
1200,
63,
736,
61,
275,
1052,
288,
367,
9428,
315,
843,
14,
4946,
63,
7995,
26,
355,
340,
9428,
440,
315,
485,
11616,
63,
9710,
59,
1200,
63,
736,
2189,
490,
485,
11616,
63,
9710,
59,
1200,
63,
736,
1527,
319,
61,
275,
1052,
288,
367,
1242,
315,
370,
63,
513,
8,
578,
63,
354,
304,
355,
367,
2397,
315,
24451,
1547,
11616,
63,
9710,
59,
1200,
63,
736,
4682,
490,
2397,
59,
1053,
61,
275,
843,
267,
3753,
26,
288,
485,
3780,
63,
831,
14,
3221,
342,
267,
372,
843,
272,
372,
4975,
421,
199,
318,
664,
8,
1200,
63,
736,
12,
859,
63,
354,
12,
1950,
63,
466,
304,
272,
2784,
63,
736,
63,
9710,
275,
485,
11616,
63,
9710,
14,
362,
8,
1200,
63,
736,
9,
272,
340,
2784,
63,
736,
63,
9710,
365,
488,
26,
267,
746,
1722,
360,
17200,
370,
2342,
282,
11233,
5022,
367,
642,
859,
358,
272,
340,
1950,
63,
466,
440,
315,
2784,
63,
736,
63,
9710,
26,
267,
746,
1722,
360,
3780,
1630,
440,
2291,
642,
1950,
730,
358,
272,
916,
859,
63,
354,
440,
315,
2784,
63,
736,
63,
9710,
59,
2105,
63,
466,
2189,
267,
746,
1722,
360,
15153,
440,
2342,
282,
11233,
5022,
367,
642,
859,
358,
272,
372,
2784,
63,
736,
63,
9710,
59,
2105,
63,
466,
1527,
578,
63,
354,
61,
421,
199,
533,
18489,
1563,
8,
785,
304,
339,
3748,
63,
7995,
275,
6248,
339,
347,
636,
826,
721,
277,
12,
1862,
12,
1950,
29,
403,
12,
1104,
63,
632,
29,
797,
304,
267,
291,
14,
1162,
275,
1862,
267,
291,
14,
2105,
275,
1950,
267,
291,
14,
1074,
63,
632,
275,
1104,
63,
632,
339,
768,
1829,
272,
347,
14918,
8,
277,
304,
267,
340,
440,
2688,
8,
277,
12,
2513,
10732,
735,
288,
3085,
275,
291,
14,
504,
63,
1001,
8,
277,
14,
2105,
14,
362,
63,
10732,
1012,
288,
5371,
8,
277,
12,
2513,
10732,
297,
3085,
9,
267,
372,
2519,
8,
277,
12,
2513,
10732,
358,
339,
347,
664,
63,
585,
8,
277,
12,
931,
304,
267,
1862,
275,
291,
14,
1162,
14,
1574,
342,
267,
367,
790,
315,
931,
14,
1294,
26461,
288,
1862,
275,
1862,
59,
498,
61,
267,
372,
1862,
339,
347,
664,
63,
5047,
8,
277,
12,
10026,
29,
403,
304,
267,
746,
4279,
8,
277,
855,
533,
4914,
354,
3368,
339,
347,
5283,
63,
888,
8,
277,
304,
267,
746,
4279,
8,
277,
855,
533,
4914,
354,
3368,
421,
199,
533,
445,
317,
6663,
8,
6663,
1563,
304,
339,
3748,
63,
7995,
275,
661,
1200,
63,
2764,
9538,
339,
768,
1829,
272,
347,
14918,
8,
277,
304,
267,
340,
440,
2688,
8,
277,
12,
2513,
10732,
735,
288,
3085,
275,
291,
14,
504,
63,
1001,
8,
277,
14,
2105,
14,
362,
63,
10732,
1012,
288,
5371,
8,
277,
12,
2513,
10732,
297,
3085,
9,
267,
372,
2519,
8,
277,
12,
2513,
10732,
358,
339,
347,
664,
63,
888,
63,
1100,
8,
277,
12,
1101,
12,
931,
12,
4363,
29,
17,
304,
267,
340,
1101,
365,
440,
488,
26,
288,
1851,
4128,
275,
7220,
2028,
8,
3724,
29,
3724,
12,
4072,
29,
888,
9,
288,
862,
26,
355,
1101,
275,
1851,
4128,
14,
362,
63,
1457,
63,
888,
8,
475,
63,
513,
8,
515,
430,
288,
871,
1722,
26,
355,
1101,
275,
488,
288,
372,
1101,
339,
347,
3795,
8,
277,
12,
1101,
29,
403,
304,
267,
746,
4279,
8,
277,
855,
533,
4914,
354,
3368,
339,
347,
5053,
8,
277,
12,
1414,
304,
267,
862,
26,
288,
340,
440,
2688,
8,
277,
12,
2513,
1531,
63,
1199,
735,
355,
5371,
8,
277,
12,
2513,
1531,
63,
1199,
297,
5009,
288,
372,
291,
423,
1531,
63,
1199,
59,
1531,
61,
267,
871,
4067,
26,
288,
734,
275,
291,
14,
2105,
14,
362,
8,
1531,
9,
288,
862,
26,
355,
734,
275,
2022,
14,
3640,
8,
548,
9,
288,
871,
1722,
26,
355,
986,
288,
291,
423,
1531,
63,
1199,
59,
1531,
61,
275,
734,
288,
372,
734,
339,
347,
664,
63,
5047,
8,
277,
12,
10026,
29,
403,
304,
267,
372,
291,
14,
13817,
342,
339,
347,
5283,
63,
888,
8,
277,
12,
1101,
29,
403,
304,
267,
3718,
275,
291,
14,
3352,
8,
888,
9,
267,
340,
3718,
436,
291,
14,
1074,
63,
632,
365,
756,
26,
288,
291,
14,
2105,
14,
3773,
63,
888,
8,
4405,
9,
267,
372,
3718,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
andreamerello/linux-stm32
|
Documentation/sphinx/kernel_include.py
|
44
|
8424
|
#!/usr/bin/env python3
# -*- coding: utf-8; mode: python -*-
# pylint: disable=R0903, C0330, R0914, R0912, E0401
u"""
kernel-include
~~~~~~~~~~~~~~
Implementation of the ``kernel-include`` reST-directive.
:copyright: Copyright (C) 2016 Markus Heiser
:license: GPL Version 2, June 1991 see linux/COPYING for details.
The ``kernel-include`` reST-directive is a replacement for the ``include``
directive. The ``kernel-include`` directive expand environment variables in
the path name and allows to include files from arbitrary locations.
.. hint::
Including files from arbitrary locations (e.g. from ``/etc``) is a
security risk for builders. This is why the ``include`` directive from
docutils *prohibit* pathnames pointing to locations *above* the filesystem
tree where the reST document with the include directive is placed.
Substrings of the form $name or ${name} are replaced by the value of
environment variable name. Malformed variable names and references to
non-existing variables are left unchanged.
"""
# ==============================================================================
# imports
# ==============================================================================
import os.path
from docutils import io, nodes, statemachine
from docutils.utils.error_reporting import SafeString, ErrorString
from docutils.parsers.rst import directives
from docutils.parsers.rst.directives.body import CodeBlock, NumberLines
from docutils.parsers.rst.directives.misc import Include
# ==============================================================================
def setup(app):
# ==============================================================================
app.add_directive("kernel-include", KernelInclude)
# ==============================================================================
class KernelInclude(Include):
# ==============================================================================
u"""KernelInclude (``kernel-include``) directive"""
def run(self):
path = os.path.realpath(
os.path.expandvars(self.arguments[0]))
# to get a bit security back, prohibit /etc:
if path.startswith(os.sep + "etc"):
raise self.severe(
'Problems with "%s" directive, prohibited path: %s'
% (self.name, path))
self.arguments[0] = path
#return super(KernelInclude, self).run() # won't work, see HINTs in _run()
return self._run()
def _run(self):
"""Include a file as part of the content of this reST file."""
# HINT: I had to copy&paste the whole Include.run method. I'am not happy
# with this, but due to security reasons, the Include.run method does
# not allow absolute or relative pathnames pointing to locations *above*
# the filesystem tree where the reST document is placed.
if not self.state.document.settings.file_insertion_enabled:
raise self.warning('"%s" directive disabled.' % self.name)
source = self.state_machine.input_lines.source(
self.lineno - self.state_machine.input_offset - 1)
source_dir = os.path.dirname(os.path.abspath(source))
path = directives.path(self.arguments[0])
if path.startswith('<') and path.endswith('>'):
path = os.path.join(self.standard_include_path, path[1:-1])
path = os.path.normpath(os.path.join(source_dir, path))
# HINT: this is the only line I had to change / commented out:
#path = utils.relative_path(None, path)
path = nodes.reprunicode(path)
encoding = self.options.get(
'encoding', self.state.document.settings.input_encoding)
e_handler=self.state.document.settings.input_encoding_error_handler
tab_width = self.options.get(
'tab-width', self.state.document.settings.tab_width)
try:
self.state.document.settings.record_dependencies.add(path)
include_file = io.FileInput(source_path=path,
encoding=encoding,
error_handler=e_handler)
except UnicodeEncodeError as error:
raise self.severe('Problems with "%s" directive path:\n'
'Cannot encode input file path "%s" '
'(wrong locale?).' %
(self.name, SafeString(path)))
except IOError as error:
raise self.severe('Problems with "%s" directive path:\n%s.' %
(self.name, ErrorString(error)))
startline = self.options.get('start-line', None)
endline = self.options.get('end-line', None)
try:
if startline or (endline is not None):
lines = include_file.readlines()
rawtext = ''.join(lines[startline:endline])
else:
rawtext = include_file.read()
except UnicodeError as error:
raise self.severe('Problem with "%s" directive:\n%s' %
(self.name, ErrorString(error)))
# start-after/end-before: no restrictions on newlines in match-text,
# and no restrictions on matching inside lines vs. line boundaries
after_text = self.options.get('start-after', None)
if after_text:
# skip content in rawtext before *and incl.* a matching text
after_index = rawtext.find(after_text)
if after_index < 0:
raise self.severe('Problem with "start-after" option of "%s" '
'directive:\nText not found.' % self.name)
rawtext = rawtext[after_index + len(after_text):]
before_text = self.options.get('end-before', None)
if before_text:
# skip content in rawtext after *and incl.* a matching text
before_index = rawtext.find(before_text)
if before_index < 0:
raise self.severe('Problem with "end-before" option of "%s" '
'directive:\nText not found.' % self.name)
rawtext = rawtext[:before_index]
include_lines = statemachine.string2lines(rawtext, tab_width,
convert_whitespace=True)
if 'literal' in self.options:
# Convert tabs to spaces, if `tab_width` is positive.
if tab_width >= 0:
text = rawtext.expandtabs(tab_width)
else:
text = rawtext
literal_block = nodes.literal_block(rawtext, source=path,
classes=self.options.get('class', []))
literal_block.line = 1
self.add_name(literal_block)
if 'number-lines' in self.options:
try:
startline = int(self.options['number-lines'] or 1)
except ValueError:
raise self.error(':number-lines: with non-integer '
'start value')
endline = startline + len(include_lines)
if text.endswith('\n'):
text = text[:-1]
tokens = NumberLines([([], text)], startline, endline)
for classes, value in tokens:
if classes:
literal_block += nodes.inline(value, value,
classes=classes)
else:
literal_block += nodes.Text(value, value)
else:
literal_block += nodes.Text(text, text)
return [literal_block]
if 'code' in self.options:
self.options['source'] = path
codeblock = CodeBlock(self.name,
[self.options.pop('code')], # arguments
self.options,
include_lines, # content
self.lineno,
self.content_offset,
self.block_text,
self.state,
self.state_machine)
return codeblock.run()
self.state_machine.insert_input(include_lines, path)
return []
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
27,
818,
26,
2366,
1882,
199,
3,
4287,
26,
3507,
29,
50,
1643,
1644,
12,
445,
8762,
16,
12,
820,
1643,
1079,
12,
820,
1643,
713,
12,
662,
28025,
199,
199,
85,
624,
272,
5114,
13,
2613,
272,
32202,
1714,
339,
24425,
402,
314,
1124,
4989,
13,
2613,
1040,
20883,
13,
15047,
14,
339,
520,
7307,
26,
221,
1898,
334,
35,
9,
7800,
221,
7173,
527,
5311,
25696,
272,
520,
1682,
26,
259,
14629,
3394,
499,
12,
1603,
11474,
9013,
17,
1937,
18369,
15,
16188,
1206,
367,
2436,
14,
339,
710,
1124,
4989,
13,
2613,
1040,
20883,
13,
15047,
365,
282,
8343,
367,
314,
1124,
2613,
1040,
272,
13613,
14,
710,
1124,
4989,
13,
2613,
1040,
13613,
6544,
3734,
2860,
315,
272,
314,
931,
536,
436,
6127,
370,
2387,
1584,
687,
9697,
9918,
14,
339,
2508,
8328,
447,
2541,
1010,
4923,
1584,
687,
9697,
9918,
334,
69,
14,
71,
14,
687,
1124,
15,
6839,
16580,
365,
282,
489,
6391,
22633,
367,
27378,
14,
961,
365,
10842,
314,
1124,
2613,
1040,
13613,
687,
489,
18382,
627,
496,
20215,
390,
10,
931,
1247,
20686,
370,
9918,
627,
16181,
10,
314,
10036,
489,
3123,
2382,
314,
20883,
2213,
543,
314,
2387,
13613,
365,
15090,
14,
339,
4804,
5465,
402,
314,
1824,
2672,
354,
503,
10839,
354,
93,
787,
8717,
701,
314,
574,
402,
272,
3734,
1750,
536,
14,
603,
24012,
1750,
1561,
436,
6941,
370,
272,
2222,
13,
5952,
2860,
787,
3602,
14874,
14,
199,
624,
199,
199,
3,
11148,
199,
3,
8925,
199,
3,
11148,
199,
199,
646,
747,
14,
515,
199,
199,
504,
18382,
492,
5890,
12,
3380,
12,
1174,
6744,
199,
504,
18382,
14,
1208,
14,
705,
63,
28071,
492,
14969,
1558,
12,
4520,
1558,
199,
504,
18382,
14,
11531,
14,
8332,
492,
13502,
199,
504,
18382,
14,
11531,
14,
8332,
14,
23216,
14,
2030,
492,
5495,
3142,
12,
4860,
9863,
199,
504,
18382,
14,
11531,
14,
8332,
14,
23216,
14,
9923,
492,
15783,
199,
199,
3,
11148,
199,
318,
3272,
8,
571,
304,
199,
3,
11148,
339,
1145,
14,
525,
63,
15047,
480,
4989,
13,
2613,
401,
24901,
7826,
9,
199,
199,
3,
11148,
199,
533,
24901,
7826,
8,
7826,
304,
199,
3,
11148,
339,
399,
624,
14127,
7826,
15693,
4989,
13,
2613,
16580,
13613,
624,
339,
347,
1255,
8,
277,
304,
267,
931,
275,
747,
14,
515,
14,
11091,
8,
288,
747,
14,
515,
14,
4441,
2936,
8,
277,
14,
4958,
59,
16,
2459,
398,
327,
370,
664,
282,
4546,
6391,
1771,
12,
557,
20215,
390,
1182,
6839,
26,
267,
340,
931,
14,
2460,
8,
736,
14,
4127,
435,
298,
6839,
2349,
288,
746,
291,
14,
261,
432,
264,
8,
355,
283,
919,
7561,
543,
2071,
83,
2,
13613,
12,
557,
20215,
5703,
931,
26,
450,
83,
7,
355,
450,
334,
277,
14,
354,
12,
931,
430,
398,
291,
14,
4958,
59,
16,
61,
275,
931,
398,
327,
1107,
1613,
8,
14127,
7826,
12,
291,
680,
1065,
342,
327,
7859,
1133,
1736,
12,
1937,
869,
2919,
83,
315,
485,
1065,
342,
267,
372,
291,
423,
1065,
342,
339,
347,
485,
1065,
8,
277,
304,
267,
408,
7826,
282,
570,
465,
1777,
402,
314,
1564,
402,
642,
20883,
570,
1041,
398,
327,
869,
2919,
26,
473,
10530,
370,
1331,
6,
16586,
314,
8852,
15783,
14,
1065,
1083,
14,
473,
7,
455,
440,
394,
18869,
267,
327,
543,
642,
12,
1325,
7037,
370,
6391,
14872,
12,
314,
15783,
14,
1065,
1083,
1630,
267,
327,
440,
2040,
3679,
503,
3847,
931,
1247,
20686,
370,
9918,
627,
16181,
10,
267,
327,
314,
10036,
3123,
2382,
314,
20883,
2213,
365,
15090,
14,
398,
340,
440,
291,
14,
929,
14,
3554,
14,
1751,
14,
493,
63,
14739,
63,
3827,
26,
288,
746,
291,
14,
3764,
32681,
83,
2,
13613,
6980,
3530,
450,
291,
14,
354,
9,
267,
1350,
275,
291,
14,
929,
63,
6744,
14,
1210,
63,
1278,
14,
1365,
8,
288,
291,
14,
3469,
446,
291,
14,
929,
63,
6744,
14,
1210,
63,
2743,
446,
413,
9,
267,
1350,
63,
694,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
8,
1365,
430,
267,
931,
275,
13502,
14,
515,
8,
277,
14,
4958,
59,
16,
566,
267,
340,
931,
14,
2460,
24240,
436,
931,
14,
4130,
16099,
735,
288,
931,
275,
747,
14,
515,
14,
904,
8,
277,
14,
6807,
63,
2613,
63,
515,
12,
931,
59,
17,
6809,
17,
566,
267,
931,
275,
747,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
904,
8,
1365,
63,
694,
12,
931,
430,
398,
327,
869,
2919,
26,
642,
365,
314,
1454,
1004,
473,
10530,
370,
1570,
1182,
21804,
734,
26,
267,
327,
515,
275,
3778,
14,
6188,
63,
515,
8,
403,
12,
931,
9,
398,
931,
275,
3380,
14,
1155,
1065,
1525,
8,
515,
9,
267,
2644,
275,
291,
14,
1419,
14,
362,
8,
288,
283,
2991,
297,
291,
14,
929,
14,
3554,
14,
1751,
14,
1210,
63,
2991,
9,
267,
325,
63,
2232,
29,
277,
14,
929,
14,
3554,
14,
1751,
14,
1210,
63,
2991,
63,
705,
63,
2232,
267,
5174,
63,
2063,
275,
291,
14,
1419,
14,
362,
8,
288,
283,
2902,
13,
2063,
297,
291,
14,
929,
14,
3554,
14,
1751,
14,
2902,
63,
2063,
9,
267,
862,
26,
288,
291,
14,
929,
14,
3554,
14,
1751,
14,
3059,
63,
5714,
14,
525,
8,
515,
9,
288,
2387,
63,
493,
275,
5890,
14,
1173,
3205,
8,
1365,
63,
515,
29,
515,
12,
3147,
2644,
29,
2991,
12,
3147,
1125,
63,
2232,
29,
69,
63,
2232,
9,
267,
871,
24094,
465,
1125,
26,
288,
746,
291,
14,
261,
432,
264,
360,
919,
7561,
543,
2071,
83,
2,
13613,
931,
3427,
78,
7,
2892,
283,
6612,
3752,
1324,
570,
931,
2071,
83,
2,
283,
2892,
8189,
10603,
5867,
31,
28823,
450,
2892,
334,
277,
14,
354,
12,
14969,
1558,
8,
515,
1724,
267,
871,
5925,
465,
1125,
26,
288,
746,
291,
14,
261,
432,
264,
360,
919,
7561,
543,
2071,
83,
2,
13613,
931,
3427,
78,
5,
83,
3530,
450,
1993,
334,
277,
14,
354,
12,
4520
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
27,
818,
26,
2366,
1882,
199,
3,
4287,
26,
3507,
29,
50,
1643,
1644,
12,
445,
8762,
16,
12,
820,
1643,
1079,
12,
820,
1643,
713,
12,
662,
28025,
199,
199,
85,
624,
272,
5114,
13,
2613,
272,
32202,
1714,
339,
24425,
402,
314,
1124,
4989,
13,
2613,
1040,
20883,
13,
15047,
14,
339,
520,
7307,
26,
221,
1898,
334,
35,
9,
7800,
221,
7173,
527,
5311,
25696,
272,
520,
1682,
26,
259,
14629,
3394,
499,
12,
1603,
11474,
9013,
17,
1937,
18369,
15,
16188,
1206,
367,
2436,
14,
339,
710,
1124,
4989,
13,
2613,
1040,
20883,
13,
15047,
365,
282,
8343,
367,
314,
1124,
2613,
1040,
272,
13613,
14,
710,
1124,
4989,
13,
2613,
1040,
13613,
6544,
3734,
2860,
315,
272,
314,
931,
536,
436,
6127,
370,
2387,
1584,
687,
9697,
9918,
14,
339,
2508,
8328,
447,
2541,
1010,
4923,
1584,
687,
9697,
9918,
334,
69,
14,
71,
14,
687,
1124,
15,
6839,
16580,
365,
282,
489,
6391,
22633,
367,
27378,
14,
961,
365,
10842,
314,
1124,
2613,
1040,
13613,
687,
489,
18382,
627,
496,
20215,
390,
10,
931,
1247,
20686,
370,
9918,
627,
16181,
10,
314,
10036,
489,
3123,
2382,
314,
20883,
2213,
543,
314,
2387,
13613,
365,
15090,
14,
339,
4804,
5465,
402,
314,
1824,
2672,
354,
503,
10839,
354,
93,
787,
8717,
701,
314,
574,
402,
272,
3734,
1750,
536,
14,
603,
24012,
1750,
1561,
436,
6941,
370,
272,
2222,
13,
5952,
2860,
787,
3602,
14874,
14,
199,
624,
199,
199,
3,
11148,
199,
3,
8925,
199,
3,
11148,
199,
199,
646,
747,
14,
515,
199,
199,
504,
18382,
492,
5890,
12,
3380,
12,
1174,
6744,
199,
504,
18382,
14,
1208,
14,
705,
63,
28071,
492,
14969,
1558,
12,
4520,
1558,
199,
504,
18382,
14,
11531,
14,
8332,
492,
13502,
199,
504,
18382,
14,
11531,
14,
8332,
14,
23216,
14,
2030,
492,
5495,
3142,
12,
4860,
9863,
199,
504,
18382,
14,
11531,
14,
8332,
14,
23216,
14,
9923,
492,
15783,
199,
199,
3,
11148,
199,
318,
3272,
8,
571,
304,
199,
3,
11148,
339,
1145,
14,
525,
63,
15047,
480,
4989,
13,
2613,
401,
24901,
7826,
9,
199,
199,
3,
11148,
199,
533,
24901,
7826,
8,
7826,
304,
199,
3,
11148,
339,
399,
624,
14127,
7826,
15693,
4989,
13,
2613,
16580,
13613,
624,
339,
347,
1255,
8,
277,
304,
267,
931,
275,
747,
14,
515,
14,
11091,
8,
288,
747,
14,
515,
14,
4441,
2936,
8,
277,
14,
4958,
59,
16,
2459,
398,
327,
370,
664,
282,
4546,
6391,
1771,
12,
557,
20215,
390,
1182,
6839,
26,
267,
340,
931,
14,
2460,
8,
736,
14,
4127,
435,
298,
6839,
2349,
288,
746,
291,
14,
261,
432,
264,
8,
355,
283,
919,
7561,
543,
2071,
83,
2,
13613,
12,
557,
20215,
5703,
931,
26,
450,
83,
7,
355,
450,
334,
277,
14,
354,
12,
931,
430,
398,
291,
14,
4958,
59,
16,
61,
275,
931,
398,
327,
1107,
1613,
8,
14127,
7826,
12,
291,
680,
1065,
342,
327,
7859,
1133,
1736,
12,
1937,
869,
2919,
83,
315,
485,
1065,
342,
267,
372,
291,
423,
1065,
342,
339,
347,
485,
1065,
8,
277,
304,
267,
408,
7826,
282,
570,
465,
1777,
402,
314,
1564,
402,
642,
20883,
570,
1041,
398,
327,
869,
2919,
26,
473,
10530,
370,
1331,
6,
16586,
314,
8852,
15783,
14,
1065,
1083,
14,
473,
7,
455,
440,
394,
18869,
267,
327,
543,
642,
12,
1325,
7037,
370,
6391,
14872,
12,
314,
15783,
14,
1065,
1083,
1630,
267,
327,
440,
2040,
3679,
503,
3847,
931,
1247,
20686,
370,
9918,
627,
16181,
10,
267,
327,
314,
10036,
3123,
2382,
314,
20883,
2213,
365,
15090,
14,
398,
340,
440,
291,
14,
929,
14,
3554,
14,
1751,
14,
493,
63,
14739,
63,
3827,
26,
288,
746,
291,
14,
3764,
32681,
83,
2,
13613,
6980,
3530,
450,
291,
14,
354,
9,
267,
1350,
275,
291,
14,
929,
63,
6744,
14,
1210,
63,
1278,
14,
1365,
8,
288,
291,
14,
3469,
446,
291,
14,
929,
63,
6744,
14,
1210,
63,
2743,
446,
413,
9,
267,
1350,
63,
694,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
8,
1365,
430,
267,
931,
275,
13502,
14,
515,
8,
277,
14,
4958,
59,
16,
566,
267,
340,
931,
14,
2460,
24240,
436,
931,
14,
4130,
16099,
735,
288,
931,
275,
747,
14,
515,
14,
904,
8,
277,
14,
6807,
63,
2613,
63,
515,
12,
931,
59,
17,
6809,
17,
566,
267,
931,
275,
747,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
904,
8,
1365,
63,
694,
12,
931,
430,
398,
327,
869,
2919,
26,
642,
365,
314,
1454,
1004,
473,
10530,
370,
1570,
1182,
21804,
734,
26,
267,
327,
515,
275,
3778,
14,
6188,
63,
515,
8,
403,
12,
931,
9,
398,
931,
275,
3380,
14,
1155,
1065,
1525,
8,
515,
9,
267,
2644,
275,
291,
14,
1419,
14,
362,
8,
288,
283,
2991,
297,
291,
14,
929,
14,
3554,
14,
1751,
14,
1210,
63,
2991,
9,
267,
325,
63,
2232,
29,
277,
14,
929,
14,
3554,
14,
1751,
14,
1210,
63,
2991,
63,
705,
63,
2232,
267,
5174,
63,
2063,
275,
291,
14,
1419,
14,
362,
8,
288,
283,
2902,
13,
2063,
297,
291,
14,
929,
14,
3554,
14,
1751,
14,
2902,
63,
2063,
9,
267,
862,
26,
288,
291,
14,
929,
14,
3554,
14,
1751,
14,
3059,
63,
5714,
14,
525,
8,
515,
9,
288,
2387,
63,
493,
275,
5890,
14,
1173,
3205,
8,
1365,
63,
515,
29,
515,
12,
3147,
2644,
29,
2991,
12,
3147,
1125,
63,
2232,
29,
69,
63,
2232,
9,
267,
871,
24094,
465,
1125,
26,
288,
746,
291,
14,
261,
432,
264,
360,
919,
7561,
543,
2071,
83,
2,
13613,
931,
3427,
78,
7,
2892,
283,
6612,
3752,
1324,
570,
931,
2071,
83,
2,
283,
2892,
8189,
10603,
5867,
31,
28823,
450,
2892,
334,
277,
14,
354,
12,
14969,
1558,
8,
515,
1724,
267,
871,
5925,
465,
1125,
26,
288,
746,
291,
14,
261,
432,
264,
360,
919,
7561,
543,
2071,
83,
2,
13613,
931,
3427,
78,
5,
83,
3530,
450,
1993,
334,
277,
14,
354,
12,
4520,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
JVenberg/PokemonGo-Bot-Desktop
|
pywin/Lib/encodings/zlib_codec.py
|
58
|
3048
|
""" Python 'zlib_codec' Codec - zlib compression encoding
Unlike most of the other codecs which target Unicode, this codec
will return Python string objects for both encode and decode.
Written by Marc-Andre Lemburg (mal@lemburg.com).
"""
import codecs
import zlib # this codec needs the optional zlib module !
### Codec APIs
def zlib_encode(input,errors='strict'):
""" Encodes the object input and returns a tuple (output
object, length consumed).
errors defines the error handling to apply. It defaults to
'strict' handling which is the only currently supported
error handling for this codec.
"""
assert errors == 'strict'
output = zlib.compress(input)
return (output, len(input))
def zlib_decode(input,errors='strict'):
""" Decodes the object input and returns a tuple (output
object, length consumed).
input must be an object which provides the bf_getreadbuf
buffer slot. Python strings, buffer objects and memory
mapped files are examples of objects providing this slot.
errors defines the error handling to apply. It defaults to
'strict' handling which is the only currently supported
error handling for this codec.
"""
assert errors == 'strict'
output = zlib.decompress(input)
return (output, len(input))
class Codec(codecs.Codec):
def encode(self, input, errors='strict'):
return zlib_encode(input, errors)
def decode(self, input, errors='strict'):
return zlib_decode(input, errors)
class IncrementalEncoder(codecs.IncrementalEncoder):
def __init__(self, errors='strict'):
assert errors == 'strict'
self.errors = errors
self.compressobj = zlib.compressobj()
def encode(self, input, final=False):
if final:
c = self.compressobj.compress(input)
return c + self.compressobj.flush()
else:
return self.compressobj.compress(input)
def reset(self):
self.compressobj = zlib.compressobj()
class IncrementalDecoder(codecs.IncrementalDecoder):
def __init__(self, errors='strict'):
assert errors == 'strict'
self.errors = errors
self.decompressobj = zlib.decompressobj()
def decode(self, input, final=False):
if final:
c = self.decompressobj.decompress(input)
return c + self.decompressobj.flush()
else:
return self.decompressobj.decompress(input)
def reset(self):
self.decompressobj = zlib.decompressobj()
class StreamWriter(Codec,codecs.StreamWriter):
pass
class StreamReader(Codec,codecs.StreamReader):
pass
### encodings module API
def getregentry():
return codecs.CodecInfo(
name='zlib',
encode=zlib_encode,
decode=zlib_decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
_is_text_encoding=False,
)
|
mit
|
[
624,
2018,
283,
15371,
63,
9276,
7,
13732,
446,
12472,
10291,
2644,
339,
25059,
4750,
402,
314,
1163,
6010,
1314,
1347,
6140,
12,
642,
9076,
272,
911,
372,
2018,
1059,
2251,
367,
3865,
3752,
436,
4849,
14,
339,
27694,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
199,
199,
624,
199,
646,
6010,
199,
646,
12472,
327,
642,
9076,
4839,
314,
2716,
12472,
859,
8546,
199,
199,
5680,
13732,
15913,
199,
199,
318,
12472,
63,
2143,
8,
1210,
12,
2550,
534,
4768,
735,
339,
408,
3447,
6021,
314,
909,
1324,
436,
2529,
282,
2008,
334,
1199,
267,
909,
12,
2582,
16949,
680,
398,
2552,
7890,
314,
1125,
7252,
370,
4838,
14,
2779,
4243,
370,
267,
283,
4768,
7,
7252,
1314,
365,
314,
1454,
5544,
3748,
267,
1125,
7252,
367,
642,
9076,
14,
339,
408,
272,
702,
2552,
508,
283,
4768,
7,
272,
1072,
275,
12472,
14,
6447,
8,
1210,
9,
272,
372,
334,
1199,
12,
822,
8,
1210,
430,
199,
199,
318,
12472,
63,
2708,
8,
1210,
12,
2550,
534,
4768,
735,
339,
408,
1487,
6021,
314,
909,
1324,
436,
2529,
282,
2008,
334,
1199,
267,
909,
12,
2582,
16949,
680,
398,
1324,
1471,
506,
376,
909,
1314,
6571,
314,
18839,
63,
362,
739,
1436,
267,
3335,
9348,
14,
2018,
3326,
12,
3335,
2251,
436,
4402,
267,
9994,
1584,
787,
7251,
402,
2251,
13070,
642,
9348,
14,
398,
2552,
7890,
314,
1125,
7252,
370,
4838,
14,
2779,
4243,
370,
267,
283,
4768,
7,
7252,
1314,
365,
314,
1454,
5544,
3748,
267,
1125,
7252,
367,
642,
9076,
14,
339,
408,
272,
702,
2552,
508,
283,
4768,
7,
272,
1072,
275,
12472,
14,
14954,
8,
1210,
9,
272,
372,
334,
1199,
12,
822,
8,
1210,
430,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
347,
3752,
8,
277,
12,
1324,
12,
2552,
534,
4768,
735,
267,
372,
12472,
63,
2143,
8,
1210,
12,
2552,
9,
272,
347,
4849,
8,
277,
12,
1324,
12,
2552,
534,
4768,
735,
267,
372,
12472,
63,
2708,
8,
1210,
12,
2552,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
636,
826,
721,
277,
12,
2552,
534,
4768,
735,
267,
702,
2552,
508,
283,
4768,
7,
267,
291,
14,
2550,
275,
2552,
267,
291,
14,
6447,
1113,
275,
12472,
14,
6447,
1113,
342,
339,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
340,
4242,
26,
288,
286,
275,
291,
14,
6447,
1113,
14,
6447,
8,
1210,
9,
288,
372,
286,
435,
291,
14,
6447,
1113,
14,
4939,
342,
267,
587,
26,
288,
372,
291,
14,
6447,
1113,
14,
6447,
8,
1210,
9,
339,
347,
5305,
8,
277,
304,
267,
291,
14,
6447,
1113,
275,
12472,
14,
6447,
1113,
342,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
636,
826,
721,
277,
12,
2552,
534,
4768,
735,
267,
702,
2552,
508,
283,
4768,
7,
267,
291,
14,
2550,
275,
2552,
267,
291,
14,
14954,
1113,
275,
12472,
14,
14954,
1113,
342,
339,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
340,
4242,
26,
288,
286,
275,
291,
14,
14954,
1113,
14,
14954,
8,
1210,
9,
288,
372,
286,
435,
291,
14,
14954,
1113,
14,
4939,
342,
267,
587,
26,
288,
372,
291,
14,
14954,
1113,
14,
14954,
8,
1210,
9,
339,
347,
5305,
8,
277,
304,
267,
291,
14,
14954,
1113,
275,
12472,
14,
14954,
1113,
342,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
15371,
297,
267,
3752,
29,
15371,
63,
2143,
12,
267,
4849,
29,
15371,
63,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
267,
485,
374,
63,
505,
63,
2991,
29,
797,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2018,
283,
15371,
63,
9276,
7,
13732,
446,
12472,
10291,
2644,
339,
25059,
4750,
402,
314,
1163,
6010,
1314,
1347,
6140,
12,
642,
9076,
272,
911,
372,
2018,
1059,
2251,
367,
3865,
3752,
436,
4849,
14,
339,
27694,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
199,
199,
624,
199,
646,
6010,
199,
646,
12472,
327,
642,
9076,
4839,
314,
2716,
12472,
859,
8546,
199,
199,
5680,
13732,
15913,
199,
199,
318,
12472,
63,
2143,
8,
1210,
12,
2550,
534,
4768,
735,
339,
408,
3447,
6021,
314,
909,
1324,
436,
2529,
282,
2008,
334,
1199,
267,
909,
12,
2582,
16949,
680,
398,
2552,
7890,
314,
1125,
7252,
370,
4838,
14,
2779,
4243,
370,
267,
283,
4768,
7,
7252,
1314,
365,
314,
1454,
5544,
3748,
267,
1125,
7252,
367,
642,
9076,
14,
339,
408,
272,
702,
2552,
508,
283,
4768,
7,
272,
1072,
275,
12472,
14,
6447,
8,
1210,
9,
272,
372,
334,
1199,
12,
822,
8,
1210,
430,
199,
199,
318,
12472,
63,
2708,
8,
1210,
12,
2550,
534,
4768,
735,
339,
408,
1487,
6021,
314,
909,
1324,
436,
2529,
282,
2008,
334,
1199,
267,
909,
12,
2582,
16949,
680,
398,
1324,
1471,
506,
376,
909,
1314,
6571,
314,
18839,
63,
362,
739,
1436,
267,
3335,
9348,
14,
2018,
3326,
12,
3335,
2251,
436,
4402,
267,
9994,
1584,
787,
7251,
402,
2251,
13070,
642,
9348,
14,
398,
2552,
7890,
314,
1125,
7252,
370,
4838,
14,
2779,
4243,
370,
267,
283,
4768,
7,
7252,
1314,
365,
314,
1454,
5544,
3748,
267,
1125,
7252,
367,
642,
9076,
14,
339,
408,
272,
702,
2552,
508,
283,
4768,
7,
272,
1072,
275,
12472,
14,
14954,
8,
1210,
9,
272,
372,
334,
1199,
12,
822,
8,
1210,
430,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
347,
3752,
8,
277,
12,
1324,
12,
2552,
534,
4768,
735,
267,
372,
12472,
63,
2143,
8,
1210,
12,
2552,
9,
272,
347,
4849,
8,
277,
12,
1324,
12,
2552,
534,
4768,
735,
267,
372,
12472,
63,
2708,
8,
1210,
12,
2552,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
636,
826,
721,
277,
12,
2552,
534,
4768,
735,
267,
702,
2552,
508,
283,
4768,
7,
267,
291,
14,
2550,
275,
2552,
267,
291,
14,
6447,
1113,
275,
12472,
14,
6447,
1113,
342,
339,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
340,
4242,
26,
288,
286,
275,
291,
14,
6447,
1113,
14,
6447,
8,
1210,
9,
288,
372,
286,
435,
291,
14,
6447,
1113,
14,
4939,
342,
267,
587,
26,
288,
372,
291,
14,
6447,
1113,
14,
6447,
8,
1210,
9,
339,
347,
5305,
8,
277,
304,
267,
291,
14,
6447,
1113,
275,
12472,
14,
6447,
1113,
342,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
636,
826,
721,
277,
12,
2552,
534,
4768,
735,
267,
702,
2552,
508,
283,
4768,
7,
267,
291,
14,
2550,
275,
2552,
267,
291,
14,
14954,
1113,
275,
12472,
14,
14954,
1113,
342,
339,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
340,
4242,
26,
288,
286,
275,
291,
14,
14954,
1113,
14,
14954,
8,
1210,
9,
288,
372,
286,
435,
291,
14,
14954,
1113,
14,
4939,
342,
267,
587,
26,
288,
372,
291,
14,
14954,
1113,
14,
14954,
8,
1210,
9,
339,
347,
5305,
8,
277,
304,
267,
291,
14,
14954,
1113,
275,
12472,
14,
14954,
1113,
342,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
15371,
297,
267,
3752,
29,
15371,
63,
2143,
12,
267,
4849,
29,
15371,
63,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
267,
485,
374,
63,
505,
63,
2991,
29,
797,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
joseAveleira/ardupilot
|
Tools/LogAnalyzer/tests/TestMotorBalance.py
|
215
|
2265
|
from LogAnalyzer import Test,TestResult
import DataflashLog
class TestBalanceTwist(Test):
'''test for badly unbalanced copter, including yaw twist'''
def __init__(self):
Test.__init__(self)
self.name = "Motor Balance"
def run(self, logdata, verbose):
self.result = TestResult()
self.result.status = TestResult.StatusType.GOOD
if logdata.vehicleType != "ArduCopter":
self.result.status = TestResult.StatusType.NA
return
self.result.status = TestResult.StatusType.UNKNOWN
if not "RCOU" in logdata.channels:
return
ch = []
for i in range(8):
if "Chan"+`(i+1)` in logdata.channels["RCOU"]:
ch.append(map(lambda x: x[1], logdata.channels["RCOU"]["Chan"+`(i+1)`].listData))
elif "Ch"+`(i+1)` in logdata.channels["RCOU"]:
ch.append(map(lambda x: x[1], logdata.channels["RCOU"]["Ch"+`(i+1)`].listData))
ch = zip(*ch)
num_channels = 0
for i in range(len(ch)):
ch[i] = filter(lambda x: (x>0 and x<3000), ch[i])
if num_channels < len(ch[i]):
num_channels = len(ch[i])
if num_channels < 2:
return
min_throttle = logdata.parameters["RC3_MIN"] + logdata.parameters["THR_MIN"] / (logdata.parameters["RC3_MAX"]-logdata.parameters["RC3_MIN"])/1000.0
ch = filter(lambda x:sum(x)/num_channels > min_throttle, ch)
if len(ch) == 0:
return
avg_all = map(lambda x:sum(x)/num_channels,ch)
avg_all = sum(avg_all)/len(avg_all)
avg_ch = []
for i in range(num_channels):
avg = map(lambda x: x[i],ch)
avg = sum(avg)/len(avg)
avg_ch.append(avg)
self.result.statusMessage = "Motor channel averages = %s\nAverage motor output = %.0f\nDifference between min and max motor averages = %.0f" % (str(avg_ch),avg_all,abs(min(avg_ch)-max(avg_ch)))
self.result.status = TestResult.StatusType.GOOD
if abs(min(avg_ch)-max(avg_ch)) > 75:
self.result.status = TestResult.StatusType.WARN
if abs(min(avg_ch)-max(avg_ch)) > 150:
self.result.status = TestResult.StatusType.FAIL
|
gpl-3.0
|
[
504,
5297,
17606,
492,
1379,
12,
13120,
199,
646,
3918,
11331,
2445,
421,
199,
533,
1379,
27106,
22879,
631,
8,
774,
304,
272,
1449,
396,
367,
4875,
590,
625,
18923,
4870,
351,
12,
5893,
612,
10084,
8900,
631,
2344,
272,
347,
636,
826,
721,
277,
304,
267,
1379,
855,
826,
721,
277,
9,
267,
291,
14,
354,
275,
298,
31642,
23928,
554,
2,
339,
347,
1255,
8,
277,
12,
943,
576,
12,
3376,
304,
267,
291,
14,
1099,
275,
23795,
342,
267,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
17316,
36,
398,
340,
943,
576,
14,
20073,
804,
1137,
298,
31924,
18268,
351,
582,
288,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
7170,
288,
372,
398,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
11588,
267,
340,
440,
298,
50,
1439,
53,
2,
315,
943,
576,
14,
6324,
26,
288,
372,
398,
682,
275,
942,
398,
367,
284,
315,
1425,
8,
24,
304,
288,
340,
298,
27039,
7709,
64,
8,
73,
11,
17,
12544,
315,
943,
576,
14,
6324,
905,
50,
1439,
53,
6229,
355,
682,
14,
740,
8,
1130,
8,
2734,
671,
26,
671,
59,
17,
467,
943,
576,
14,
6324,
905,
50,
1439,
53,
6611,
27039,
7709,
64,
8,
73,
11,
17,
12544,
1055,
513,
1451,
430,
288,
916,
298,
1049,
7709,
64,
8,
73,
11,
17,
12544,
315,
943,
576,
14,
6324,
905,
50,
1439,
53,
6229,
355,
682,
14,
740,
8,
1130,
8,
2734,
671,
26,
671,
59,
17,
467,
943,
576,
14,
6324,
905,
50,
1439,
53,
6611,
1049,
7709,
64,
8,
73,
11,
17,
12544,
1055,
513,
1451,
430,
398,
682,
275,
3482,
2031,
335,
9,
267,
1967,
63,
6324,
275,
378,
267,
367,
284,
315,
1425,
8,
552,
8,
335,
2298,
288,
682,
59,
73,
61,
275,
2457,
8,
2734,
671,
26,
334,
88,
30,
16,
436,
671,
28,
19962,
395,
682,
59,
73,
566,
288,
340,
1967,
63,
6324,
665,
822,
8,
335,
59,
73,
4682,
355,
1967,
63,
6324,
275,
822,
8,
335,
59,
73,
566,
398,
340,
1967,
63,
6324,
665,
499,
26,
288,
372,
398,
1748,
63,
20086,
275,
943,
576,
14,
3214,
905,
8205,
19,
63,
4896,
937,
435,
943,
576,
14,
3214,
905,
2080,
50,
63,
4896,
937,
1182,
334,
793,
576,
14,
3214,
905,
8205,
19,
63,
4283,
937,
13,
793,
576,
14,
3214,
905,
8205,
19,
63,
4896,
3135,
15,
5279,
14,
16,
267,
682,
275,
2457,
8,
2734,
671,
26,
1838,
8,
88,
2447,
1507,
63,
6324,
690,
1748,
63,
20086,
12,
682,
9,
398,
340,
822,
8,
335,
9,
508,
378,
26,
288,
372,
398,
12402,
63,
452,
275,
2341,
8,
2734,
671,
26,
1838,
8,
88,
2447,
1507,
63,
6324,
12,
335,
9,
267,
12402,
63,
452,
275,
3089,
8,
8595,
63,
452,
2447,
552,
8,
8595,
63,
452,
9,
267,
12402,
63,
335,
275,
942,
267,
367,
284,
315,
1425,
8,
1507,
63,
6324,
304,
288,
12402,
275,
2341,
8,
2734,
671,
26,
671,
59,
73,
467,
335,
9,
288,
12402,
275,
3089,
8,
8595,
2447,
552,
8,
8595,
9,
288,
12402,
63,
335,
14,
740,
8,
8595,
9,
398,
291,
14,
1099,
14,
1205,
2209,
275,
298,
31642,
3623,
8095,
83,
275,
450,
83,
60,
78,
17400,
28496,
1072,
275,
10536,
16,
70,
60,
78,
32279,
3382,
1748,
436,
1390,
28496,
8095,
83,
275,
10536,
16,
70,
2,
450,
334,
495,
8,
8595,
63,
335,
395,
8595,
63,
452,
12,
2101,
8,
827,
8,
8595,
63,
335,
7216,
988,
8,
8595,
63,
335,
1724,
398,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
17316,
36,
398,
340,
2853,
8,
827,
8,
8595,
63,
335,
7216,
988,
8,
8595,
63,
335,
430,
690,
13098,
26,
288,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
17449,
267,
340,
2853,
8,
827,
8,
8595,
63,
335,
7216,
988,
8,
8595,
63,
335,
430,
690,
14711,
26,
288,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
8784,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
5297,
17606,
492,
1379,
12,
13120,
199,
646,
3918,
11331,
2445,
421,
199,
533,
1379,
27106,
22879,
631,
8,
774,
304,
272,
1449,
396,
367,
4875,
590,
625,
18923,
4870,
351,
12,
5893,
612,
10084,
8900,
631,
2344,
272,
347,
636,
826,
721,
277,
304,
267,
1379,
855,
826,
721,
277,
9,
267,
291,
14,
354,
275,
298,
31642,
23928,
554,
2,
339,
347,
1255,
8,
277,
12,
943,
576,
12,
3376,
304,
267,
291,
14,
1099,
275,
23795,
342,
267,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
17316,
36,
398,
340,
943,
576,
14,
20073,
804,
1137,
298,
31924,
18268,
351,
582,
288,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
7170,
288,
372,
398,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
11588,
267,
340,
440,
298,
50,
1439,
53,
2,
315,
943,
576,
14,
6324,
26,
288,
372,
398,
682,
275,
942,
398,
367,
284,
315,
1425,
8,
24,
304,
288,
340,
298,
27039,
7709,
64,
8,
73,
11,
17,
12544,
315,
943,
576,
14,
6324,
905,
50,
1439,
53,
6229,
355,
682,
14,
740,
8,
1130,
8,
2734,
671,
26,
671,
59,
17,
467,
943,
576,
14,
6324,
905,
50,
1439,
53,
6611,
27039,
7709,
64,
8,
73,
11,
17,
12544,
1055,
513,
1451,
430,
288,
916,
298,
1049,
7709,
64,
8,
73,
11,
17,
12544,
315,
943,
576,
14,
6324,
905,
50,
1439,
53,
6229,
355,
682,
14,
740,
8,
1130,
8,
2734,
671,
26,
671,
59,
17,
467,
943,
576,
14,
6324,
905,
50,
1439,
53,
6611,
1049,
7709,
64,
8,
73,
11,
17,
12544,
1055,
513,
1451,
430,
398,
682,
275,
3482,
2031,
335,
9,
267,
1967,
63,
6324,
275,
378,
267,
367,
284,
315,
1425,
8,
552,
8,
335,
2298,
288,
682,
59,
73,
61,
275,
2457,
8,
2734,
671,
26,
334,
88,
30,
16,
436,
671,
28,
19962,
395,
682,
59,
73,
566,
288,
340,
1967,
63,
6324,
665,
822,
8,
335,
59,
73,
4682,
355,
1967,
63,
6324,
275,
822,
8,
335,
59,
73,
566,
398,
340,
1967,
63,
6324,
665,
499,
26,
288,
372,
398,
1748,
63,
20086,
275,
943,
576,
14,
3214,
905,
8205,
19,
63,
4896,
937,
435,
943,
576,
14,
3214,
905,
2080,
50,
63,
4896,
937,
1182,
334,
793,
576,
14,
3214,
905,
8205,
19,
63,
4283,
937,
13,
793,
576,
14,
3214,
905,
8205,
19,
63,
4896,
3135,
15,
5279,
14,
16,
267,
682,
275,
2457,
8,
2734,
671,
26,
1838,
8,
88,
2447,
1507,
63,
6324,
690,
1748,
63,
20086,
12,
682,
9,
398,
340,
822,
8,
335,
9,
508,
378,
26,
288,
372,
398,
12402,
63,
452,
275,
2341,
8,
2734,
671,
26,
1838,
8,
88,
2447,
1507,
63,
6324,
12,
335,
9,
267,
12402,
63,
452,
275,
3089,
8,
8595,
63,
452,
2447,
552,
8,
8595,
63,
452,
9,
267,
12402,
63,
335,
275,
942,
267,
367,
284,
315,
1425,
8,
1507,
63,
6324,
304,
288,
12402,
275,
2341,
8,
2734,
671,
26,
671,
59,
73,
467,
335,
9,
288,
12402,
275,
3089,
8,
8595,
2447,
552,
8,
8595,
9,
288,
12402,
63,
335,
14,
740,
8,
8595,
9,
398,
291,
14,
1099,
14,
1205,
2209,
275,
298,
31642,
3623,
8095,
83,
275,
450,
83,
60,
78,
17400,
28496,
1072,
275,
10536,
16,
70,
60,
78,
32279,
3382,
1748,
436,
1390,
28496,
8095,
83,
275,
10536,
16,
70,
2,
450,
334,
495,
8,
8595,
63,
335,
395,
8595,
63,
452,
12,
2101,
8,
827,
8,
8595,
63,
335,
7216,
988,
8,
8595,
63,
335,
1724,
398,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
17316,
36,
398,
340,
2853,
8,
827,
8,
8595,
63,
335,
7216,
988,
8,
8595,
63,
335,
430,
690,
13098,
26,
288,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
17449,
267,
340,
2853,
8,
827,
8,
8595,
63,
335,
7216,
988,
8,
8595,
63,
335,
430,
690,
14711,
26,
288,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
8784,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
ikaee/bfr-attendant
|
facerecognitionlibrary/jni-build/jni/include/tensorflow/tools/dist_test/server/parse_cluster_spec_test.py
|
147
|
3420
|
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for cluster-spec string parser in GRPC TensorFlow server."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.core.protobuf import tensorflow_server_pb2
from tensorflow.python.platform import test
from tensorflow.tools.dist_test.server import grpc_tensorflow_server
class ParseClusterSpecStringTest(test.TestCase):
def setUp(self):
self._cluster = tensorflow_server_pb2.ServerDef(protocol="grpc").cluster
def test_parse_multi_jobs_sunnyday(self):
cluster_spec = ("worker|worker0:2220;worker1:2221;worker2:2222,"
"ps|ps0:3220;ps1:3221")
grpc_tensorflow_server.parse_cluster_spec(cluster_spec, self._cluster)
self.assertEqual(2, len(self._cluster.job))
self.assertEqual("worker", self._cluster.job[0].name)
self.assertEqual(3, len(self._cluster.job[0].tasks))
self.assertEqual("worker0:2220", self._cluster.job[0].tasks[0])
self.assertEqual("worker1:2221", self._cluster.job[0].tasks[1])
self.assertEqual("worker2:2222", self._cluster.job[0].tasks[2])
self.assertEqual("ps", self._cluster.job[1].name)
self.assertEqual(2, len(self._cluster.job[1].tasks))
self.assertEqual("ps0:3220", self._cluster.job[1].tasks[0])
self.assertEqual("ps1:3221", self._cluster.job[1].tasks[1])
def test_empty_cluster_spec_string(self):
cluster_spec = ""
with self.assertRaisesRegexp(ValueError, "Empty cluster_spec string"):
grpc_tensorflow_server.parse_cluster_spec(cluster_spec, self._cluster)
def test_parse_misused_comma_for_semicolon(self):
cluster_spec = "worker|worker0:2220,worker1:2221"
with self.assertRaisesRegexp(ValueError,
"Not exactly one instance of \\'\\|\\'"):
grpc_tensorflow_server.parse_cluster_spec(cluster_spec, self._cluster)
def test_parse_misused_semicolon_for_comma(self):
cluster_spec = "worker|worker0:2220;ps|ps0:3220"
with self.assertRaisesRegexp(ValueError,
"Not exactly one instance of \\'\\|\\'"):
grpc_tensorflow_server.parse_cluster_spec(cluster_spec, self._cluster)
def test_parse_empty_job_name(self):
cluster_spec = "worker|worker0:2220,|ps0:3220"
with self.assertRaisesRegexp(ValueError, "Empty job_name in cluster_spec"):
grpc_tensorflow_server.parse_cluster_spec(cluster_spec, self._cluster)
print(self._cluster)
def test_parse_empty_task(self):
cluster_spec = "worker|worker0:2220,ps|"
with self.assertRaisesRegexp(ValueError, "Empty task string at position 0"):
grpc_tensorflow_server.parse_cluster_spec(cluster_spec, self._cluster)
if __name__ == "__main__":
test.main()
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
4350,
13,
1650,
1059,
1798,
315,
598,
8171,
9134,
1654,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1018,
14,
7204,
492,
3228,
63,
1000,
63,
3317,
18,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
2537,
14,
2686,
63,
396,
14,
1000,
492,
19753,
63,
16008,
63,
1000,
421,
199,
533,
6077,
9581,
5307,
1558,
774,
8,
396,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
291,
423,
4201,
275,
3228,
63,
1000,
63,
3317,
18,
14,
3120,
6172,
8,
3922,
628,
15391,
3471,
4201,
819,
347,
511,
63,
1122,
63,
3029,
63,
6920,
63,
11846,
9745,
2977,
8,
277,
304,
272,
4350,
63,
1650,
275,
1689,
6599,
92,
6599,
16,
26,
1081,
1165,
27,
6599,
17,
26,
1081,
2025,
27,
6599,
18,
26,
9993,
4589,
490,
298,
1190,
92,
1190,
16,
26,
708,
1165,
27,
1190,
17,
26,
708,
2025,
531,
339,
19753,
63,
16008,
63,
1000,
14,
1122,
63,
4201,
63,
1650,
8,
4201,
63,
1650,
12,
291,
423,
4201,
9,
339,
291,
14,
629,
8,
18,
12,
822,
8,
277,
423,
4201,
14,
2423,
430,
339,
291,
14,
629,
480,
6599,
401,
291,
423,
4201,
14,
2423,
59,
16,
1055,
354,
9,
272,
291,
14,
629,
8,
19,
12,
822,
8,
277,
423,
4201,
14,
2423,
59,
16,
1055,
5054,
430,
272,
291,
14,
629,
480,
6599,
16,
26,
1081,
1165,
401,
291,
423,
4201,
14,
2423,
59,
16,
1055,
5054,
59,
16,
566,
272,
291,
14,
629,
480,
6599,
17,
26,
1081,
2025,
401,
291,
423,
4201,
14,
2423,
59,
16,
1055,
5054,
59,
17,
566,
272,
291,
14,
629,
480,
6599,
18,
26,
9993,
401,
291,
423,
4201,
14,
2423,
59,
16,
1055,
5054,
59,
18,
566,
339,
291,
14,
629,
480,
1190,
401,
291,
423,
4201,
14,
2423,
59,
17,
1055,
354,
9,
272,
291,
14,
629,
8,
18,
12,
822,
8,
277,
423,
4201,
14,
2423,
59,
17,
1055,
5054,
430,
272,
291,
14,
629,
480,
1190,
16,
26,
708,
1165,
401,
291,
423,
4201,
14,
2423,
59,
17,
1055,
5054,
59,
16,
566,
272,
291,
14,
629,
480,
1190,
17,
26,
708,
2025,
401,
291,
423,
4201,
14,
2423,
59,
17,
1055,
5054,
59,
17,
566,
819,
347,
511,
63,
1667,
63,
4201,
63,
1650,
63,
875,
8,
277,
304,
272,
4350,
63,
1650,
275,
3087,
339,
543,
291,
14,
10835,
8,
3393,
12,
298,
4699,
4350,
63,
1650,
1059,
2349,
489,
19753,
63,
16008,
63,
1000,
14,
1122,
63,
4201,
63,
1650,
8,
4201,
63,
1650,
12,
291,
423,
4201,
9,
819,
347,
511,
63,
1122,
63,
1292,
2972,
63,
13184,
63,
509,
63,
19290,
12167,
8,
277,
304,
272,
4350,
63,
1650,
275,
298,
6599,
92,
6599,
16,
26,
1081,
1165,
12,
6599,
17,
26,
1081,
2025,
2,
339,
543,
291,
14,
10835,
8,
3393,
12,
639,
298,
1763,
8840,
1373,
1256,
402,
971,
3985,
1103,
17780,
7,
2349,
489,
19753,
63,
16008,
63,
1000,
14,
1122,
63,
4201,
63,
1650,
8,
4201,
63,
1650,
12,
291,
423,
4201,
9,
819,
347,
511,
63,
1122,
63,
1292,
2972,
63,
19290,
12167,
63,
509,
63,
13184,
8,
277,
304,
272,
4350,
63,
1650,
275,
298,
6599,
92,
6599,
16,
26,
1081,
1165,
27,
1190,
92,
1190,
16,
26,
708,
1165,
2,
339,
543,
291,
14,
10835,
8,
3393,
12,
639,
298,
1763,
8840,
1373,
1256,
402,
971,
3985,
1103,
17780,
7,
2349,
489,
19753,
63,
16008,
63,
1000,
14,
1122,
63,
4201,
63,
1650,
8,
4201,
63,
1650,
12,
291,
423,
4201,
9,
819,
347,
511,
63,
1122,
63,
1667,
63,
2423,
63,
354,
8,
277,
304,
272,
4350,
63,
1650,
275,
298,
6599,
92,
6599,
16,
26,
1081,
1165,
12,
92,
1190,
16,
26,
708,
1165,
2,
339,
543,
291,
14,
10835,
8,
3393,
12,
298,
4699,
3906,
63,
354,
315,
4350,
63,
1650,
2349,
489,
19753,
63,
16008,
63,
1000,
14,
1122,
63,
4201,
63,
1650,
8,
4201,
63,
1650,
12,
291,
423,
4201,
9,
489,
870,
8,
277,
423,
4201,
9,
819,
347,
511,
63,
1122,
63,
1667,
63,
1765,
8,
277,
304,
272,
4350,
63,
1650,
275,
298,
6599,
92,
6599,
16,
26,
1081,
1165,
12,
1190,
25576,
339,
543,
291,
14,
10835,
8,
3393,
12,
298,
4699,
2120,
1059,
737,
3421,
378,
2349,
489,
19753,
63,
16008,
63,
1000,
14,
1122,
63,
4201,
63,
1650,
8,
4201,
63,
1650,
12,
291,
423,
4201,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
511,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
4350,
13,
1650,
1059,
1798,
315,
598,
8171,
9134,
1654,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1018,
14,
7204,
492,
3228,
63,
1000,
63,
3317,
18,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
2537,
14,
2686,
63,
396,
14,
1000,
492,
19753,
63,
16008,
63,
1000,
421,
199,
533,
6077,
9581,
5307,
1558,
774,
8,
396,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
291,
423,
4201,
275,
3228,
63,
1000,
63,
3317,
18,
14,
3120,
6172,
8,
3922,
628,
15391,
3471,
4201,
819,
347,
511,
63,
1122,
63,
3029,
63,
6920,
63,
11846,
9745,
2977,
8,
277,
304,
272,
4350,
63,
1650,
275,
1689,
6599,
92,
6599,
16,
26,
1081,
1165,
27,
6599,
17,
26,
1081,
2025,
27,
6599,
18,
26,
9993,
4589,
490,
298,
1190,
92,
1190,
16,
26,
708,
1165,
27,
1190,
17,
26,
708,
2025,
531,
339,
19753,
63,
16008,
63,
1000,
14,
1122,
63,
4201,
63,
1650,
8,
4201,
63,
1650,
12,
291,
423,
4201,
9,
339,
291,
14,
629,
8,
18,
12,
822,
8,
277,
423,
4201,
14,
2423,
430,
339,
291,
14,
629,
480,
6599,
401,
291,
423,
4201,
14,
2423,
59,
16,
1055,
354,
9,
272,
291,
14,
629,
8,
19,
12,
822,
8,
277,
423,
4201,
14,
2423,
59,
16,
1055,
5054,
430,
272,
291,
14,
629,
480,
6599,
16,
26,
1081,
1165,
401,
291,
423,
4201,
14,
2423,
59,
16,
1055,
5054,
59,
16,
566,
272,
291,
14,
629,
480,
6599,
17,
26,
1081,
2025,
401,
291,
423,
4201,
14,
2423,
59,
16,
1055,
5054,
59,
17,
566,
272,
291,
14,
629,
480,
6599,
18,
26,
9993,
401,
291,
423,
4201,
14,
2423,
59,
16,
1055,
5054,
59,
18,
566,
339,
291,
14,
629,
480,
1190,
401,
291,
423,
4201,
14,
2423,
59,
17,
1055,
354,
9,
272,
291,
14,
629,
8,
18,
12,
822,
8,
277,
423,
4201,
14,
2423,
59,
17,
1055,
5054,
430,
272,
291,
14,
629,
480,
1190,
16,
26,
708,
1165,
401,
291,
423,
4201,
14,
2423,
59,
17,
1055,
5054,
59,
16,
566,
272,
291,
14,
629,
480,
1190,
17,
26,
708,
2025,
401,
291,
423,
4201,
14,
2423,
59,
17,
1055,
5054,
59,
17,
566,
819,
347,
511,
63,
1667,
63,
4201,
63,
1650,
63,
875,
8,
277,
304,
272,
4350,
63,
1650,
275,
3087,
339,
543,
291,
14,
10835,
8,
3393,
12,
298,
4699,
4350,
63,
1650,
1059,
2349,
489,
19753,
63,
16008,
63,
1000,
14,
1122,
63,
4201,
63,
1650,
8,
4201,
63,
1650,
12,
291,
423,
4201,
9,
819,
347,
511,
63,
1122,
63,
1292,
2972,
63,
13184,
63,
509,
63,
19290,
12167,
8,
277,
304,
272,
4350,
63,
1650,
275,
298,
6599,
92,
6599,
16,
26,
1081,
1165,
12,
6599,
17,
26,
1081,
2025,
2,
339,
543,
291,
14,
10835,
8,
3393,
12,
639,
298,
1763,
8840,
1373,
1256,
402,
971,
3985,
1103,
17780,
7,
2349,
489,
19753,
63,
16008,
63,
1000,
14,
1122,
63,
4201,
63,
1650,
8,
4201,
63,
1650,
12,
291,
423,
4201,
9,
819,
347,
511,
63,
1122,
63,
1292,
2972,
63,
19290,
12167,
63,
509,
63,
13184,
8,
277,
304,
272,
4350,
63,
1650,
275,
298,
6599,
92,
6599,
16,
26,
1081,
1165,
27,
1190,
92,
1190,
16,
26,
708,
1165,
2,
339,
543,
291,
14,
10835,
8,
3393,
12,
639,
298,
1763,
8840,
1373,
1256,
402,
971,
3985,
1103,
17780,
7,
2349,
489,
19753,
63,
16008,
63,
1000,
14,
1122,
63,
4201,
63,
1650,
8,
4201,
63,
1650,
12,
291,
423,
4201,
9,
819,
347,
511,
63,
1122,
63,
1667,
63,
2423,
63,
354,
8,
277,
304,
272,
4350,
63,
1650,
275,
298,
6599,
92,
6599,
16,
26,
1081,
1165,
12,
92,
1190,
16,
26,
708,
1165,
2,
339,
543,
291,
14,
10835,
8,
3393,
12,
298,
4699,
3906,
63,
354,
315,
4350,
63,
1650,
2349,
489,
19753,
63,
16008,
63,
1000,
14,
1122,
63,
4201,
63,
1650,
8,
4201,
63,
1650,
12,
291,
423,
4201,
9,
489,
870,
8,
277,
423,
4201,
9,
819,
347,
511,
63,
1122,
63,
1667,
63,
1765,
8,
277,
304,
272,
4350,
63,
1650,
275,
298,
6599,
92,
6599,
16,
26,
1081,
1165,
12,
1190,
25576,
339,
543,
291,
14,
10835,
8,
3393,
12,
298,
4699,
2120,
1059,
737,
3421,
378,
2349,
489,
19753,
63,
16008,
63,
1000,
14,
1122,
63,
4201,
63,
1650,
8,
4201,
63,
1650,
12,
291,
423,
4201,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
511,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
SnappleCap/oh-mainline
|
vendor/packages/python-social-auth/social/tests/test_storage.py
|
80
|
6433
|
import six
import random
import unittest2 as unittest
from social.strategies.base import BaseStrategy
from social.storage.base import UserMixin, NonceMixin, AssociationMixin, \
CodeMixin, BaseStorage
from social.tests.models import User
NOT_IMPLEMENTED_MSG = 'Implement in subclass'
class BrokenUser(UserMixin):
pass
class BrokenAssociation(AssociationMixin):
pass
class BrokenNonce(NonceMixin):
pass
class BrokenCode(CodeMixin):
pass
class BrokenStrategy(BaseStrategy):
pass
class BrokenStrategyWithSettings(BrokenStrategy):
def get_setting(self, name):
raise AttributeError()
class BrokenStorage(BaseStorage):
pass
class BrokenUserTests(unittest.TestCase):
def setUp(self):
self.user = BrokenUser
def tearDown(self):
self.user = None
def test_get_username(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.user.get_username(User('foobar'))
def test_user_model(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.user.user_model()
def test_username_max_length(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.user.username_max_length()
def test_get_user(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.user.get_user(1)
def test_get_social_auth(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.user.get_social_auth('foo', 1)
def test_get_social_auth_for_user(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.user.get_social_auth_for_user(User('foobar'))
def test_create_social_auth(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.user.create_social_auth(User('foobar'), 1, 'foo')
def test_disconnect(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.user.disconnect(BrokenUser())
class BrokenAssociationTests(unittest.TestCase):
def setUp(self):
self.association = BrokenAssociation
def tearDown(self):
self.association = None
def test_store(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.association.store('http://foobar.com', BrokenAssociation())
def test_get(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.association.get()
def test_remove(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.association.remove([1, 2, 3])
class BrokenNonceTests(unittest.TestCase):
def setUp(self):
self.nonce = BrokenNonce
def tearDown(self):
self.nonce = None
def test_use(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.nonce.use('http://foobar.com', 1364951922, 'foobar123')
class BrokenCodeTest(unittest.TestCase):
def setUp(self):
self.code = BrokenCode
def tearDown(self):
self.code = None
def test_get_code(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.code.get_code('foobar')
class BrokenStrategyTests(unittest.TestCase):
def setUp(self):
self.strategy = BrokenStrategy(storage=BrokenStorage)
def tearDown(self):
self.strategy = None
def test_redirect(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.redirect('http://foobar.com')
def test_get_setting(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.get_setting('foobar')
def test_html(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.html('<p>foobar</p>')
def test_request_data(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.request_data()
def test_request_host(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.request_host()
def test_session_get(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.session_get('foobar')
def test_session_set(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.session_set('foobar', 123)
def test_session_pop(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.session_pop('foobar')
def test_build_absolute_uri(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.build_absolute_uri('/foobar')
def test_render_html_with_tpl(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.render_html('foobar.html', context={})
def test_render_html_with_html(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.render_html(html='<p>foobar</p>', context={})
def test_render_html_with_none(self):
with self.assertRaisesRegexp(ValueError,
'Missing template or html parameters'):
self.strategy.render_html()
def test_is_integrity_error(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.storage.is_integrity_error(None)
def test_random_string(self):
self.assertTrue(isinstance(self.strategy.random_string(),
six.string_types))
def test_random_string_without_systemrandom(self):
def SystemRandom():
raise NotImplementedError()
orig_random = getattr(random, 'SystemRandom', None)
random.SystemRandom = SystemRandom
strategy = BrokenStrategyWithSettings(storage=BrokenStorage)
self.assertTrue(isinstance(strategy.random_string(), six.string_types))
random.SystemRandom = orig_random
|
agpl-3.0
|
[
646,
3816,
199,
646,
2196,
199,
646,
2882,
18,
465,
2882,
199,
199,
504,
20295,
14,
20694,
1500,
14,
1095,
492,
3523,
16199,
199,
504,
20295,
14,
3494,
14,
1095,
492,
2876,
4256,
12,
653,
5089,
4256,
12,
24207,
425,
4256,
12,
971,
1816,
5495,
4256,
12,
3523,
6408,
199,
199,
504,
20295,
14,
2219,
14,
992,
492,
2876,
421,
199,
4609,
63,
8947,
10320,
1149,
63,
9740,
275,
283,
26924,
315,
5516,
7,
421,
199,
533,
23804,
1899,
8,
1899,
4256,
304,
272,
986,
421,
199,
533,
23804,
18662,
8,
18662,
4256,
304,
272,
986,
421,
199,
533,
23804,
46,
5089,
8,
46,
5089,
4256,
304,
272,
986,
421,
199,
533,
23804,
3034,
8,
3034,
4256,
304,
272,
986,
421,
199,
533,
23804,
16199,
8,
1563,
16199,
304,
272,
986,
421,
199,
533,
23804,
16199,
3007,
5268,
8,
30509,
16199,
304,
272,
347,
664,
63,
6031,
8,
277,
12,
536,
304,
267,
746,
4281,
342,
421,
199,
533,
23804,
6408,
8,
1563,
6408,
304,
272,
986,
421,
199,
533,
23804,
1899,
2925,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
751,
275,
23804,
1899,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
751,
275,
488,
339,
347,
511,
63,
362,
63,
2473,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
751,
14,
362,
63,
2473,
8,
1899,
360,
9664,
1333,
339,
347,
511,
63,
751,
63,
1238,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
751,
14,
751,
63,
1238,
342,
339,
347,
511,
63,
2473,
63,
988,
63,
1267,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
751,
14,
2473,
63,
988,
63,
1267,
342,
339,
347,
511,
63,
362,
63,
751,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
751,
14,
362,
63,
751,
8,
17,
9,
339,
347,
511,
63,
362,
63,
13574,
63,
1178,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
751,
14,
362,
63,
13574,
63,
1178,
360,
1421,
297,
413,
9,
339,
347,
511,
63,
362,
63,
13574,
63,
1178,
63,
509,
63,
751,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
751,
14,
362,
63,
13574,
63,
1178,
63,
509,
63,
751,
8,
1899,
360,
9664,
1333,
339,
347,
511,
63,
981,
63,
13574,
63,
1178,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
751,
14,
981,
63,
13574,
63,
1178,
8,
1899,
360,
9664,
659,
413,
12,
283,
1421,
358,
339,
347,
511,
63,
10673,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
751,
14,
10673,
8,
30509,
1899,
1012,
421,
199,
533,
23804,
18662,
2925,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
20252,
275,
23804,
18662,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
20252,
275,
488,
339,
347,
511,
63,
1617,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
20252,
14,
1617,
360,
1014,
921,
9664,
14,
957,
297,
23804,
18662,
1012,
339,
347,
511,
63,
362,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
20252,
14,
362,
342,
339,
347,
511,
63,
2168,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
20252,
14,
2168,
779,
17,
12,
499,
12,
650,
566,
421,
199,
533,
23804,
46,
5089,
2925,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
10667,
275,
23804,
46,
5089,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
10667,
275,
488,
339,
347,
511,
63,
1180,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
10667,
14,
1180,
360,
1014,
921,
9664,
14,
957,
297,
4944,
772,
2720,
1167,
1081,
12,
283,
9664,
4288,
358,
421,
199,
533,
23804,
3034,
774,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
600,
275,
23804,
3034,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
600,
275,
488,
339,
347,
511,
63,
362,
63,
600,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
600,
14,
362,
63,
600,
360,
9664,
358,
421,
199,
533,
23804,
16199,
2925,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
8590,
275,
23804,
16199,
8,
3494,
29,
30509,
6408,
9,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
8590,
275,
488,
339,
347,
511,
63,
4876,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
8590,
14,
4876,
360,
1014,
921,
9664,
14,
957,
358,
339,
347,
511,
63,
362,
63,
6031,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
8590,
14,
362,
63,
6031,
360,
9664,
358,
339,
347,
511,
63,
1360,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
8590,
14,
1360,
4827,
80,
30,
9664,
1108,
80,
5971,
339,
347,
511,
63,
1069,
63,
576,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
8590,
14,
1069,
63,
576,
342,
339,
347,
511,
63,
1069
] |
[
3816,
199,
646,
2196,
199,
646,
2882,
18,
465,
2882,
199,
199,
504,
20295,
14,
20694,
1500,
14,
1095,
492,
3523,
16199,
199,
504,
20295,
14,
3494,
14,
1095,
492,
2876,
4256,
12,
653,
5089,
4256,
12,
24207,
425,
4256,
12,
971,
1816,
5495,
4256,
12,
3523,
6408,
199,
199,
504,
20295,
14,
2219,
14,
992,
492,
2876,
421,
199,
4609,
63,
8947,
10320,
1149,
63,
9740,
275,
283,
26924,
315,
5516,
7,
421,
199,
533,
23804,
1899,
8,
1899,
4256,
304,
272,
986,
421,
199,
533,
23804,
18662,
8,
18662,
4256,
304,
272,
986,
421,
199,
533,
23804,
46,
5089,
8,
46,
5089,
4256,
304,
272,
986,
421,
199,
533,
23804,
3034,
8,
3034,
4256,
304,
272,
986,
421,
199,
533,
23804,
16199,
8,
1563,
16199,
304,
272,
986,
421,
199,
533,
23804,
16199,
3007,
5268,
8,
30509,
16199,
304,
272,
347,
664,
63,
6031,
8,
277,
12,
536,
304,
267,
746,
4281,
342,
421,
199,
533,
23804,
6408,
8,
1563,
6408,
304,
272,
986,
421,
199,
533,
23804,
1899,
2925,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
751,
275,
23804,
1899,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
751,
275,
488,
339,
347,
511,
63,
362,
63,
2473,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
751,
14,
362,
63,
2473,
8,
1899,
360,
9664,
1333,
339,
347,
511,
63,
751,
63,
1238,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
751,
14,
751,
63,
1238,
342,
339,
347,
511,
63,
2473,
63,
988,
63,
1267,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
751,
14,
2473,
63,
988,
63,
1267,
342,
339,
347,
511,
63,
362,
63,
751,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
751,
14,
362,
63,
751,
8,
17,
9,
339,
347,
511,
63,
362,
63,
13574,
63,
1178,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
751,
14,
362,
63,
13574,
63,
1178,
360,
1421,
297,
413,
9,
339,
347,
511,
63,
362,
63,
13574,
63,
1178,
63,
509,
63,
751,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
751,
14,
362,
63,
13574,
63,
1178,
63,
509,
63,
751,
8,
1899,
360,
9664,
1333,
339,
347,
511,
63,
981,
63,
13574,
63,
1178,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
751,
14,
981,
63,
13574,
63,
1178,
8,
1899,
360,
9664,
659,
413,
12,
283,
1421,
358,
339,
347,
511,
63,
10673,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
751,
14,
10673,
8,
30509,
1899,
1012,
421,
199,
533,
23804,
18662,
2925,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
20252,
275,
23804,
18662,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
20252,
275,
488,
339,
347,
511,
63,
1617,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
20252,
14,
1617,
360,
1014,
921,
9664,
14,
957,
297,
23804,
18662,
1012,
339,
347,
511,
63,
362,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
20252,
14,
362,
342,
339,
347,
511,
63,
2168,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
20252,
14,
2168,
779,
17,
12,
499,
12,
650,
566,
421,
199,
533,
23804,
46,
5089,
2925,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
10667,
275,
23804,
46,
5089,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
10667,
275,
488,
339,
347,
511,
63,
1180,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
10667,
14,
1180,
360,
1014,
921,
9664,
14,
957,
297,
4944,
772,
2720,
1167,
1081,
12,
283,
9664,
4288,
358,
421,
199,
533,
23804,
3034,
774,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
600,
275,
23804,
3034,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
600,
275,
488,
339,
347,
511,
63,
362,
63,
600,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
600,
14,
362,
63,
600,
360,
9664,
358,
421,
199,
533,
23804,
16199,
2925,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
8590,
275,
23804,
16199,
8,
3494,
29,
30509,
6408,
9,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
8590,
275,
488,
339,
347,
511,
63,
4876,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
8590,
14,
4876,
360,
1014,
921,
9664,
14,
957,
358,
339,
347,
511,
63,
362,
63,
6031,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
8590,
14,
362,
63,
6031,
360,
9664,
358,
339,
347,
511,
63,
1360,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,
63,
9740,
304,
288,
291,
14,
8590,
14,
1360,
4827,
80,
30,
9664,
1108,
80,
5971,
339,
347,
511,
63,
1069,
63,
576,
8,
277,
304,
267,
543,
291,
14,
10835,
8,
18097,
12,
2845,
63,
8947,
10320,
1149,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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
] |
tarzan0820/odoo
|
addons/account_bank_statement_extensions/report/bank_statement_balance_report.py
|
378
|
2723
|
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
#
# Copyright (c) 2011 Noviat nv/sa (www.noviat.be). All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
from openerp.osv import osv
from openerp.report import report_sxw
class bank_statement_balance_report(report_sxw.rml_parse):
def set_context(self, objects, data, ids, report_type=None):
cr = self.cr
cr.execute('SELECT s.name as s_name, s.date AS s_date, j.code as j_code, s.balance_end_real as s_balance ' \
'FROM account_bank_statement s ' \
'INNER JOIN account_journal j on s.journal_id = j.id ' \
'INNER JOIN ' \
'(SELECT journal_id, max(date) as max_date FROM account_bank_statement ' \
'GROUP BY journal_id) d ' \
'ON (s.journal_id = d.journal_id AND s.date = d.max_date) ' \
'ORDER BY j.code')
lines = cr.dictfetchall()
self.localcontext.update( {
'lines': lines,
})
super(bank_statement_balance_report, self).set_context(objects, data, ids, report_type=report_type)
def __init__(self, cr, uid, name, context):
if context is None:
context = {}
super(bank_statement_balance_report, self).__init__(cr, uid, name, context=context)
self.localcontext.update( {
'time': time,
})
self.context = context
class report_bankstatementbalance(osv.AbstractModel):
_name = 'report.account_bank_statement_extensions.report_bankstatementbalance'
_inherit = 'report.abstract_report'
_template = 'account_bank_statement_extensions.report_bankstatementbalance'
_wrapped_report_class = bank_statement_balance_report
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
199,
3,
259,
1898,
334,
67,
9,
7760,
3091,
433,
292,
26510,
15,
2231,
334,
1544,
14,
889,
433,
292,
14,
1235,
680,
2900,
4481,
4644,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
900,
199,
504,
5166,
14,
4795,
492,
9506,
199,
504,
5166,
14,
3070,
492,
3622,
63,
20851,
421,
199,
533,
16297,
63,
6242,
63,
7358,
63,
3070,
8,
3070,
63,
20851,
14,
16300,
63,
1122,
304,
339,
347,
663,
63,
1100,
8,
277,
12,
2251,
12,
666,
12,
2762,
12,
3622,
63,
466,
29,
403,
304,
267,
2467,
275,
291,
14,
1556,
398,
2467,
14,
2526,
360,
4859,
308,
14,
354,
465,
308,
63,
354,
12,
308,
14,
602,
4319,
308,
63,
602,
12,
1335,
14,
600,
465,
1335,
63,
600,
12,
308,
14,
7358,
63,
500,
63,
3093,
465,
308,
63,
7358,
283,
971,
717,
283,
12491,
2933,
63,
9860,
63,
6242,
308,
283,
971,
717,
283,
31031,
10593,
2933,
63,
7067,
1335,
641,
308,
14,
7067,
63,
344,
275,
1335,
14,
344,
283,
971,
717,
283,
31031,
10593,
283,
971,
1169,
8189,
4859,
9605,
63,
344,
12,
1390,
8,
602,
9,
465,
1390,
63,
602,
4442,
2933,
63,
9860,
63,
6242,
283,
971,
1816,
283,
7823,
6515,
9605,
63,
344,
9,
366,
283,
971,
1816,
283,
615,
334,
83,
14,
7067,
63,
344,
275,
366,
14,
7067,
63,
344,
2401,
308,
14,
602,
275,
366,
14,
988,
63,
602,
9,
283,
971,
717,
283,
12125,
6515,
1335,
14,
600,
358,
267,
2385,
275,
2467,
14,
807,
10174,
342,
398,
291,
14,
17886,
14,
873,
8,
469,
288,
283,
1278,
356,
2385,
12,
267,
3828,
267,
1613,
8,
9860,
63,
6242,
63,
7358,
63,
3070,
12,
291,
680,
409,
63,
1100,
8,
1462,
12,
666,
12,
2762,
12,
3622,
63,
466,
29,
3070,
63,
466,
9,
339,
347,
636,
826,
721,
277,
12,
2467,
12,
1747,
12,
536,
12,
1067,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
1613,
8,
9860,
63,
6242,
63,
7358,
63,
3070,
12,
291,
2843,
826,
721,
1556,
12,
1747,
12,
536,
12,
1067,
29,
1100,
9,
267,
291,
14,
17886,
14,
873,
8,
469,
288,
283,
521,
356,
900,
12,
267,
3828,
267,
291,
14,
1100,
275,
1067,
421,
199,
533,
3622,
63,
9860,
6242,
7358,
8,
4795,
14,
8458,
1685,
304,
272,
485,
354,
275,
283,
3070,
14,
2048,
63,
9860,
63,
6242,
63,
5359,
14,
3070,
63,
9860,
6242,
7358,
7,
272,
485,
6486,
275,
283,
3070,
14,
6198,
63,
3070,
7,
272,
485,
1160,
275,
283,
2048,
63,
9860,
63,
6242,
63,
5359,
14,
3070,
63,
9860,
6242,
7358,
7,
272,
485,
9130,
63,
3070,
63,
533,
275,
16297,
63,
6242,
63,
7358,
63,
3070,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
199,
3,
259,
1898,
334,
67,
9,
7760,
3091,
433,
292,
26510,
15,
2231,
334,
1544,
14,
889,
433,
292,
14,
1235,
680,
2900,
4481,
4644,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
900,
199,
504,
5166,
14,
4795,
492,
9506,
199,
504,
5166,
14,
3070,
492,
3622,
63,
20851,
421,
199,
533,
16297,
63,
6242,
63,
7358,
63,
3070,
8,
3070,
63,
20851,
14,
16300,
63,
1122,
304,
339,
347,
663,
63,
1100,
8,
277,
12,
2251,
12,
666,
12,
2762,
12,
3622,
63,
466,
29,
403,
304,
267,
2467,
275,
291,
14,
1556,
398,
2467,
14,
2526,
360,
4859,
308,
14,
354,
465,
308,
63,
354,
12,
308,
14,
602,
4319,
308,
63,
602,
12,
1335,
14,
600,
465,
1335,
63,
600,
12,
308,
14,
7358,
63,
500,
63,
3093,
465,
308,
63,
7358,
283,
971,
717,
283,
12491,
2933,
63,
9860,
63,
6242,
308,
283,
971,
717,
283,
31031,
10593,
2933,
63,
7067,
1335,
641,
308,
14,
7067,
63,
344,
275,
1335,
14,
344,
283,
971,
717,
283,
31031,
10593,
283,
971,
1169,
8189,
4859,
9605,
63,
344,
12,
1390,
8,
602,
9,
465,
1390,
63,
602,
4442,
2933,
63,
9860,
63,
6242,
283,
971,
1816,
283,
7823,
6515,
9605,
63,
344,
9,
366,
283,
971,
1816,
283,
615,
334,
83,
14,
7067,
63,
344,
275,
366,
14,
7067,
63,
344,
2401,
308,
14,
602,
275,
366,
14,
988,
63,
602,
9,
283,
971,
717,
283,
12125,
6515,
1335,
14,
600,
358,
267,
2385,
275,
2467,
14,
807,
10174,
342,
398,
291,
14,
17886,
14,
873,
8,
469,
288,
283,
1278,
356,
2385,
12,
267,
3828,
267,
1613,
8,
9860,
63,
6242,
63,
7358,
63,
3070,
12,
291,
680,
409,
63,
1100,
8,
1462,
12,
666,
12,
2762,
12,
3622,
63,
466,
29,
3070,
63,
466,
9,
339,
347,
636,
826,
721,
277,
12,
2467,
12,
1747,
12,
536,
12,
1067,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
1613,
8,
9860,
63,
6242,
63,
7358,
63,
3070,
12,
291,
2843,
826,
721,
1556,
12,
1747,
12,
536,
12,
1067,
29,
1100,
9,
267,
291,
14,
17886,
14,
873,
8,
469,
288,
283,
521,
356,
900,
12,
267,
3828,
267,
291,
14,
1100,
275,
1067,
421,
199,
533,
3622,
63,
9860,
6242,
7358,
8,
4795,
14,
8458,
1685,
304,
272,
485,
354,
275,
283,
3070,
14,
2048,
63,
9860,
63,
6242,
63,
5359,
14,
3070,
63,
9860,
6242,
7358,
7,
272,
485,
6486,
275,
283,
3070,
14,
6198,
63,
3070,
7,
272,
485,
1160,
275,
283,
2048,
63,
9860,
63,
6242,
63,
5359,
14,
3070,
63,
9860,
6242,
7358,
7,
272,
485,
9130,
63,
3070,
63,
533,
275,
16297,
63,
6242,
63,
7358,
63,
3070,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jmr2704/betakore-alien
|
src/scons-local-2.0.1/SCons/Variables/PackageVariable.py
|
61
|
3612
|
"""engine.SCons.Variables.PackageVariable
This file defines the option type for SCons implementing 'package
activation'.
To be used whenever a 'package' may be enabled/disabled and the
package path may be specified.
Usage example:
Examples:
x11=no (disables X11 support)
x11=yes (will search for the package installation dir)
x11=/usr/local/X11 (will check this path for existance)
To replace autoconf's --with-xxx=yyy
opts = Variables()
opts.Add(PackageVariable('x11',
'use X11 installed here (yes = search some places',
'yes'))
...
if env['x11'] == True:
dir = ... search X11 in some standard places ...
env['x11'] = dir
if env['x11']:
... build with x11 ...
"""
#
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
__revision__ = "src/engine/SCons/Variables/PackageVariable.py 5134 2010/08/16 23:02:40 bdeegan"
__all__ = ['PackageVariable',]
import SCons.Errors
__enable_strings = ('1', 'yes', 'true', 'on', 'enable', 'search')
__disable_strings = ('0', 'no', 'false', 'off', 'disable')
def _converter(val):
"""
"""
lval = val.lower()
if lval in __enable_strings: return True
if lval in __disable_strings: return False
#raise ValueError("Invalid value for boolean option: %s" % val)
return val
def _validator(key, val, env, searchfunc):
# NB: searchfunc is currenty undocumented and unsupported
"""
"""
# todo: write validator, check for path
import os
if env[key] is True:
if searchfunc:
env[key] = searchfunc(key, val)
elif env[key] and not os.path.exists(val):
raise SCons.Errors.UserError(
'Path does not exist for option %s: %s' % (key, val))
def PackageVariable(key, help, default, searchfunc=None):
# NB: searchfunc is currenty undocumented and unsupported
"""
The input parameters describe a 'package list' option, thus they
are returned with the correct converter and validator appended. The
result is usable for input to opts.Add() .
A 'package list' option may either be 'all', 'none' or a list of
package names (seperated by space).
"""
help = '\n '.join(
(help, '( yes | no | /path/to/%s )' % key))
return (key, help, default,
lambda k, v, e: _validator(k,v,e,searchfunc),
_converter)
# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
|
gpl-2.0
|
[
624,
3908,
14,
18521,
14,
11458,
14,
8599,
2773,
199,
199,
2765,
570,
7890,
314,
945,
730,
367,
8218,
18234,
283,
2491,
199,
12312,
1370,
199,
199,
1378,
506,
1202,
18119,
282,
283,
2491,
7,
1443,
506,
5223,
15,
7011,
436,
314,
199,
2491,
931,
1443,
506,
2013,
14,
199,
199,
7692,
2893,
26,
819,
6058,
26,
489,
671,
845,
29,
889,
257,
334,
2297,
5921,
1323,
845,
2291,
9,
489,
671,
845,
29,
5066,
221,
334,
14117,
2754,
367,
314,
2559,
12096,
2935,
9,
489,
671,
845,
13043,
2647,
15,
1832,
15,
56,
845,
334,
14117,
1104,
642,
931,
367,
444,
73,
611,
9,
819,
4005,
3350,
2599,
2190,
1159,
1553,
1045,
13,
10013,
29,
30917,
221,
819,
3999,
275,
17198,
342,
523,
3999,
14,
1123,
8,
8599,
2773,
360,
88,
845,
297,
586,
283,
1180,
1323,
845,
4903,
2348,
334,
5066,
275,
2754,
2005,
9825,
297,
586,
283,
5066,
1333,
523,
2263,
523,
340,
2589,
459,
88,
845,
418,
508,
715,
26,
489,
2935,
275,
2263,
2754,
1323,
845,
315,
2005,
4465,
9825,
2263,
489,
2589,
459,
88,
845,
418,
275,
2935,
16421,
340,
2589,
459,
88,
845,
2565,
489,
2263,
1900,
543,
671,
845,
2263,
199,
624,
199,
199,
3,
199,
3,
1898,
334,
67,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
710,
8218,
2752,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
11458,
15,
8599,
2773,
14,
647,
959,
7582,
7129,
15,
2036,
15,
975,
6546,
26,
996,
26,
2167,
330,
271,
5902,
290,
2,
199,
199,
363,
452,
363,
275,
788,
8599,
2773,
297,
61,
199,
199,
646,
8218,
14,
9298,
199,
199,
363,
4296,
63,
5465,
221,
275,
661,
17,
297,
283,
5066,
297,
283,
2052,
297,
221,
283,
265,
297,
283,
4296,
297,
283,
1733,
358,
199,
363,
5993,
63,
5465,
275,
661,
16,
297,
283,
889,
297,
221,
283,
3910,
297,
283,
1997,
297,
283,
5993,
358,
199,
199,
318,
485,
11256,
8,
637,
304,
272,
408,
272,
408,
272,
634,
637,
275,
1139,
14,
2325,
342,
272,
340,
634,
637,
315,
636,
4296,
63,
5465,
26,
372,
715,
272,
340,
634,
637,
315,
636,
5993,
63,
5465,
26,
372,
756,
272,
327,
3730,
1722,
480,
3364,
574,
367,
5046,
945,
26,
450,
83,
2,
450,
1139,
9,
272,
372,
1139,
421,
199,
318,
485,
11034,
8,
498,
12,
1139,
12,
2589,
12,
2754,
1532,
304,
272,
327,
25377,
26,
2754,
1532,
365,
1453,
89,
625,
29383,
436,
16313,
272,
408,
272,
408,
272,
327,
11386,
26,
2218,
11822,
12,
1104,
367,
931,
272,
492,
747,
272,
340,
2589,
59,
498,
61,
365,
715,
26,
267,
340,
2754,
1532,
26,
288,
2589,
59,
498,
61,
275,
2754,
1532,
8,
498,
12,
1139,
9,
272,
916,
2589,
59,
498,
61,
436,
440,
747,
14,
515,
14,
2444,
8,
637,
304,
267,
746,
8218,
14,
9298,
14,
1899,
547,
8,
288,
283,
2042,
1630,
440,
2187,
367,
945,
450,
83,
26,
450,
83,
7,
450,
334,
498,
12,
1139,
430,
421,
199,
318,
15665,
2773,
8,
498,
12,
1720,
12,
849,
12,
2754,
1532,
29,
403,
304,
272,
327,
25377,
26,
2754,
1532,
365,
1453,
89,
625,
29383,
436,
16313,
272,
408,
272,
710,
1324,
2633,
13743,
282,
283,
2491,
769,
7,
945,
12,
12850,
2985,
272,
787,
2138,
543,
314,
3211,
11109,
436,
11822,
11544,
14,
710,
272,
754,
365,
18025,
367,
1324,
370,
3999,
14,
1123,
342,
1275,
339,
437,
283,
2491,
769,
7,
945,
1443,
1902,
506,
283,
452,
297,
283,
3592,
7,
503,
282,
769,
402,
272,
2559,
1561,
334,
261,
529,
972,
701,
4601,
680,
272,
408,
272,
1720,
275,
1557,
78,
259,
1987,
904,
8,
267,
334,
3437,
12,
8189,
9456,
1204,
949,
1204,
1182,
515,
15,
475,
3149,
83,
776,
7,
450,
790,
430,
272,
372,
334,
498,
12,
1720,
12,
849,
12,
288,
2400,
1022,
12,
373,
12,
325,
26,
485,
11034,
8,
75,
12,
86,
12,
69,
12,
1733,
1532,
395,
288,
485,
11256,
9,
199,
199,
3,
10111,
17198,
26,
199,
3,
5174,
13,
2063,
26,
20,
199,
3,
4363,
13,
8741,
13,
632,
26,
20613,
199,
3,
9599,
26,
199,
3,
6695,
26,
663,
26414,
20849,
29,
20,
20105,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3908,
14,
18521,
14,
11458,
14,
8599,
2773,
199,
199,
2765,
570,
7890,
314,
945,
730,
367,
8218,
18234,
283,
2491,
199,
12312,
1370,
199,
199,
1378,
506,
1202,
18119,
282,
283,
2491,
7,
1443,
506,
5223,
15,
7011,
436,
314,
199,
2491,
931,
1443,
506,
2013,
14,
199,
199,
7692,
2893,
26,
819,
6058,
26,
489,
671,
845,
29,
889,
257,
334,
2297,
5921,
1323,
845,
2291,
9,
489,
671,
845,
29,
5066,
221,
334,
14117,
2754,
367,
314,
2559,
12096,
2935,
9,
489,
671,
845,
13043,
2647,
15,
1832,
15,
56,
845,
334,
14117,
1104,
642,
931,
367,
444,
73,
611,
9,
819,
4005,
3350,
2599,
2190,
1159,
1553,
1045,
13,
10013,
29,
30917,
221,
819,
3999,
275,
17198,
342,
523,
3999,
14,
1123,
8,
8599,
2773,
360,
88,
845,
297,
586,
283,
1180,
1323,
845,
4903,
2348,
334,
5066,
275,
2754,
2005,
9825,
297,
586,
283,
5066,
1333,
523,
2263,
523,
340,
2589,
459,
88,
845,
418,
508,
715,
26,
489,
2935,
275,
2263,
2754,
1323,
845,
315,
2005,
4465,
9825,
2263,
489,
2589,
459,
88,
845,
418,
275,
2935,
16421,
340,
2589,
459,
88,
845,
2565,
489,
2263,
1900,
543,
671,
845,
2263,
199,
624,
199,
199,
3,
199,
3,
1898,
334,
67,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
710,
8218,
2752,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
11458,
15,
8599,
2773,
14,
647,
959,
7582,
7129,
15,
2036,
15,
975,
6546,
26,
996,
26,
2167,
330,
271,
5902,
290,
2,
199,
199,
363,
452,
363,
275,
788,
8599,
2773,
297,
61,
199,
199,
646,
8218,
14,
9298,
199,
199,
363,
4296,
63,
5465,
221,
275,
661,
17,
297,
283,
5066,
297,
283,
2052,
297,
221,
283,
265,
297,
283,
4296,
297,
283,
1733,
358,
199,
363,
5993,
63,
5465,
275,
661,
16,
297,
283,
889,
297,
221,
283,
3910,
297,
283,
1997,
297,
283,
5993,
358,
199,
199,
318,
485,
11256,
8,
637,
304,
272,
408,
272,
408,
272,
634,
637,
275,
1139,
14,
2325,
342,
272,
340,
634,
637,
315,
636,
4296,
63,
5465,
26,
372,
715,
272,
340,
634,
637,
315,
636,
5993,
63,
5465,
26,
372,
756,
272,
327,
3730,
1722,
480,
3364,
574,
367,
5046,
945,
26,
450,
83,
2,
450,
1139,
9,
272,
372,
1139,
421,
199,
318,
485,
11034,
8,
498,
12,
1139,
12,
2589,
12,
2754,
1532,
304,
272,
327,
25377,
26,
2754,
1532,
365,
1453,
89,
625,
29383,
436,
16313,
272,
408,
272,
408,
272,
327,
11386,
26,
2218,
11822,
12,
1104,
367,
931,
272,
492,
747,
272,
340,
2589,
59,
498,
61,
365,
715,
26,
267,
340,
2754,
1532,
26,
288,
2589,
59,
498,
61,
275,
2754,
1532,
8,
498,
12,
1139,
9,
272,
916,
2589,
59,
498,
61,
436,
440,
747,
14,
515,
14,
2444,
8,
637,
304,
267,
746,
8218,
14,
9298,
14,
1899,
547,
8,
288,
283,
2042,
1630,
440,
2187,
367,
945,
450,
83,
26,
450,
83,
7,
450,
334,
498,
12,
1139,
430,
421,
199,
318,
15665,
2773,
8,
498,
12,
1720,
12,
849,
12,
2754,
1532,
29,
403,
304,
272,
327,
25377,
26,
2754,
1532,
365,
1453,
89,
625,
29383,
436,
16313,
272,
408,
272,
710,
1324,
2633,
13743,
282,
283,
2491,
769,
7,
945,
12,
12850,
2985,
272,
787,
2138,
543,
314,
3211,
11109,
436,
11822,
11544,
14,
710,
272,
754,
365,
18025,
367,
1324,
370,
3999,
14,
1123,
342,
1275,
339,
437,
283,
2491,
769,
7,
945,
1443,
1902,
506,
283,
452,
297,
283,
3592,
7,
503,
282,
769,
402,
272,
2559,
1561,
334,
261,
529,
972,
701,
4601,
680,
272,
408,
272,
1720,
275,
1557,
78,
259,
1987,
904,
8,
267,
334,
3437,
12,
8189,
9456,
1204,
949,
1204,
1182,
515,
15,
475,
3149,
83,
776,
7,
450,
790,
430,
272,
372,
334,
498,
12,
1720,
12,
849,
12,
288,
2400,
1022,
12,
373,
12,
325,
26,
485,
11034,
8,
75,
12,
86,
12,
69,
12,
1733,
1532,
395,
288,
485,
11256,
9,
199,
199,
3,
10111,
17198,
26,
199,
3,
5174,
13,
2063,
26,
20,
199,
3,
4363,
13,
8741,
13,
632,
26,
20613,
199,
3,
9599,
26,
199,
3,
6695,
26,
663,
26414,
20849,
29,
20,
20105,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
unnikrishnankgs/va
|
venv/lib/python3.5/site-packages/IPython/utils/PyColorize.py
|
3
|
10460
|
# -*- coding: utf-8 -*-
"""
Class and program to colorize python source code for ANSI terminals.
Based on an HTML code highlighter by Jurgen Hermann found at:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52298
Modifications by Fernando Perez (fperez@colorado.edu).
Information on the original HTML highlighter follows:
MoinMoin - Python Source Parser
Title: Colorize Python source using the built-in tokenizer
Submitter: Jurgen Hermann
Last Updated:2001/04/06
Version no:1.2
Description:
This code is part of MoinMoin (http://moin.sourceforge.net/) and converts
Python source code to HTML markup, rendering comments, keywords,
operators, numeric and string literals in different colors.
It shows how to use the built-in keyword, token and tokenize modules to
scan Python source code and re-emit it with no changes to its original
formatting (which is the hard part).
"""
__all__ = ['ANSICodeColors','Parser']
_scheme_default = 'Linux'
# Imports
import keyword
import os
import sys
import token
import tokenize
generate_tokens = tokenize.generate_tokens
from IPython.utils.coloransi import TermColors, InputTermColors ,ColorScheme, ColorSchemeTable
from .colorable import Colorable
from io import StringIO
#############################################################################
### Python Source Parser (does Highlighting)
#############################################################################
_KEYWORD = token.NT_OFFSET + 1
_TEXT = token.NT_OFFSET + 2
#****************************************************************************
# Builtin color schemes
Colors = TermColors # just a shorthand
# Build a few color schemes
NoColor = ColorScheme(
'NoColor',{
'header' : Colors.NoColor,
token.NUMBER : Colors.NoColor,
token.OP : Colors.NoColor,
token.STRING : Colors.NoColor,
tokenize.COMMENT : Colors.NoColor,
token.NAME : Colors.NoColor,
token.ERRORTOKEN : Colors.NoColor,
_KEYWORD : Colors.NoColor,
_TEXT : Colors.NoColor,
'in_prompt' : InputTermColors.NoColor, # Input prompt
'in_number' : InputTermColors.NoColor, # Input prompt number
'in_prompt2' : InputTermColors.NoColor, # Continuation prompt
'in_normal' : InputTermColors.NoColor, # color off (usu. Colors.Normal)
'out_prompt' : Colors.NoColor, # Output prompt
'out_number' : Colors.NoColor, # Output prompt number
'normal' : Colors.NoColor # color off (usu. Colors.Normal)
} )
LinuxColors = ColorScheme(
'Linux',{
'header' : Colors.LightRed,
token.NUMBER : Colors.LightCyan,
token.OP : Colors.Yellow,
token.STRING : Colors.LightBlue,
tokenize.COMMENT : Colors.LightRed,
token.NAME : Colors.Normal,
token.ERRORTOKEN : Colors.Red,
_KEYWORD : Colors.LightGreen,
_TEXT : Colors.Yellow,
'in_prompt' : InputTermColors.Green,
'in_number' : InputTermColors.LightGreen,
'in_prompt2' : InputTermColors.Green,
'in_normal' : InputTermColors.Normal, # color off (usu. Colors.Normal)
'out_prompt' : Colors.Red,
'out_number' : Colors.LightRed,
'normal' : Colors.Normal # color off (usu. Colors.Normal)
} )
NeutralColors = ColorScheme(
'Neutral',{
'header' : Colors.Red,
token.NUMBER : Colors.Cyan,
token.OP : Colors.Blue,
token.STRING : Colors.Blue,
tokenize.COMMENT : Colors.Red,
token.NAME : Colors.Normal,
token.ERRORTOKEN : Colors.Red,
_KEYWORD : Colors.Green,
_TEXT : Colors.Blue,
'in_prompt' : InputTermColors.Blue,
'in_number' : InputTermColors.LightBlue,
'in_prompt2' : InputTermColors.Blue,
'in_normal' : InputTermColors.Normal, # color off (usu. Colors.Normal)
'out_prompt' : Colors.Red,
'out_number' : Colors.LightRed,
'normal' : Colors.Normal # color off (usu. Colors.Normal)
} )
# Hack: the 'neutral' colours are not very visible on a dark background on
# Windows. Since Windows command prompts have a dark background by default, and
# relatively few users are likely to alter that, we will use the 'Linux' colours,
# designed for a dark background, as the default on Windows. Changing it here
# avoids affecting the prompt colours rendered by prompt_toolkit, where the
# neutral defaults do work OK.
if os.name == 'nt':
NeutralColors = LinuxColors.copy(name='Neutral')
LightBGColors = ColorScheme(
'LightBG',{
'header' : Colors.Red,
token.NUMBER : Colors.Cyan,
token.OP : Colors.Blue,
token.STRING : Colors.Blue,
tokenize.COMMENT : Colors.Red,
token.NAME : Colors.Normal,
token.ERRORTOKEN : Colors.Red,
_KEYWORD : Colors.Green,
_TEXT : Colors.Blue,
'in_prompt' : InputTermColors.Blue,
'in_number' : InputTermColors.LightBlue,
'in_prompt2' : InputTermColors.Blue,
'in_normal' : InputTermColors.Normal, # color off (usu. Colors.Normal)
'out_prompt' : Colors.Red,
'out_number' : Colors.LightRed,
'normal' : Colors.Normal # color off (usu. Colors.Normal)
} )
# Build table of color schemes (needed by the parser)
ANSICodeColors = ColorSchemeTable([NoColor,LinuxColors,LightBGColors, NeutralColors],
_scheme_default)
Undefined = object()
class Parser(Colorable):
""" Format colored Python source.
"""
def __init__(self, color_table=None, out = sys.stdout, parent=None, style=None):
""" Create a parser with a specified color table and output channel.
Call format() to process code.
"""
super(Parser, self).__init__(parent=parent)
self.color_table = color_table and color_table or ANSICodeColors
self.out = out
if not style:
self.style = self.default_style
else:
self.style = style
def format(self, raw, out=None, scheme=Undefined):
import warnings
if scheme is not Undefined:
warnings.warn('The `scheme` argument of IPython.utils.PyColorize:Parser.format is deprecated since IPython 6.0.'
'It will have no effect. Set the parser `style` directly.',
stacklevel=2)
return self.format2(raw, out)[0]
def format2(self, raw, out = None):
""" Parse and send the colored source.
If out and scheme are not specified, the defaults (given to
constructor) are used.
out should be a file-type object. Optionally, out can be given as the
string 'str' and the parser will automatically return the output in a
string."""
string_output = 0
if out == 'str' or self.out == 'str' or \
isinstance(self.out,StringIO):
# XXX - I don't really like this state handling logic, but at this
# point I don't want to make major changes, so adding the
# isinstance() check is the simplest I can do to ensure correct
# behavior.
out_old = self.out
self.out = StringIO()
string_output = 1
elif out is not None:
self.out = out
# Fast return of the unmodified input for NoColor scheme
if self.style == 'NoColor':
error = False
self.out.write(raw)
if string_output:
return raw,error
else:
return None,error
# local shorthands
colors = self.color_table[self.style].colors
self.colors = colors # put in object so __call__ sees it
# Remove trailing whitespace and normalize tabs
self.raw = raw.expandtabs().rstrip()
# store line offsets in self.lines
self.lines = [0, 0]
pos = 0
raw_find = self.raw.find
lines_append = self.lines.append
while 1:
pos = raw_find('\n', pos) + 1
if not pos: break
lines_append(pos)
lines_append(len(self.raw))
# parse the source and write it
self.pos = 0
text = StringIO(self.raw)
error = False
try:
for atoken in generate_tokens(text.readline):
self(*atoken)
except tokenize.TokenError as ex:
msg = ex.args[0]
line = ex.args[1][0]
self.out.write("%s\n\n*** ERROR: %s%s%s\n" %
(colors[token.ERRORTOKEN],
msg, self.raw[self.lines[line]:],
colors.normal)
)
error = True
self.out.write(colors.normal+'\n')
if string_output:
output = self.out.getvalue()
self.out = out_old
return (output, error)
return (None, error)
def __call__(self, toktype, toktext, start_pos, end_pos, line):
""" Token handler, with syntax highlighting."""
(srow,scol) = start_pos
(erow,ecol) = end_pos
colors = self.colors
owrite = self.out.write
# line separator, so this works across platforms
linesep = os.linesep
# calculate new positions
oldpos = self.pos
newpos = self.lines[srow] + scol
self.pos = newpos + len(toktext)
# send the original whitespace, if needed
if newpos > oldpos:
owrite(self.raw[oldpos:newpos])
# skip indenting tokens
if toktype in [token.INDENT, token.DEDENT]:
self.pos = newpos
return
# map token type to a color group
if token.LPAR <= toktype <= token.OP:
toktype = token.OP
elif toktype == token.NAME and keyword.iskeyword(toktext):
toktype = _KEYWORD
color = colors.get(toktype, colors[_TEXT])
#print '<%s>' % toktext, # dbg
# Triple quoted strings must be handled carefully so that backtracking
# in pagers works correctly. We need color terminators on _each_ line.
if linesep in toktext:
toktext = toktext.replace(linesep, '%s%s%s' %
(colors.normal,linesep,color))
# send text
owrite('%s%s%s' % (color,toktext,colors.normal))
|
bsd-2-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
2543,
436,
2240,
370,
31019,
2366,
1350,
1233,
367,
25600,
5537,
2551,
14,
199,
199,
20409,
641,
376,
4163,
1233,
4721,
18975,
351,
701,
1603,
300,
2268,
18769,
20059,
1911,
737,
26,
199,
1014,
921,
305,
4812,
14,
32595,
14,
957,
15,
1179,
9060,
15,
967,
32632,
15,
4718,
15,
25879,
15,
29915,
2905,
199,
199,
29188,
83,
701,
481,
27569,
22066,
11379,
25409,
334,
70,
321,
25409,
32,
2326,
5129,
14,
8654,
680,
199,
199,
4935,
641,
314,
3379,
4163,
4721,
18975,
351,
11924,
26,
199,
199,
3716,
262,
3716,
262,
446,
2018,
5800,
10191,
199,
199,
6888,
26,
11581,
794,
2018,
1350,
1808,
314,
6137,
13,
262,
14803,
199,
199,
17187,
351,
26,
1603,
300,
2268,
18769,
20059,
199,
6090,
6162,
68,
26,
8339,
15,
966,
15,
1690,
199,
199,
3353,
949,
26,
17,
14,
18,
199,
199,
5831,
26,
199,
199,
2765,
1233,
365,
1777,
402,
3930,
262,
3716,
262,
334,
1014,
921,
573,
262,
14,
22943,
14,
846,
24793,
436,
15373,
199,
4718,
1350,
1233,
370,
4163,
9189,
12,
14066,
6786,
12,
7681,
12,
199,
12688,
12,
8950,
436,
1059,
18041,
315,
3365,
9229,
14,
199,
199,
7940,
13703,
4212,
370,
675,
314,
6137,
13,
262,
4252,
12,
1526,
436,
13343,
4621,
370,
199,
6282,
2018,
1350,
1233,
436,
295,
13,
8159,
652,
543,
949,
4493,
370,
2399,
3379,
199,
20034,
334,
6777,
365,
314,
7508,
1777,
680,
199,
624,
199,
199,
363,
452,
363,
275,
788,
5622,
948,
380,
20094,
1673,
2842,
418,
199,
199,
63,
5512,
63,
885,
275,
283,
14091,
7,
421,
199,
3,
24339,
199,
646,
4252,
199,
646,
747,
199,
646,
984,
199,
646,
1526,
199,
646,
13343,
199,
199,
4208,
63,
4504,
275,
13343,
14,
4208,
63,
4504,
199,
199,
504,
16243,
14,
1208,
14,
2326,
22204,
492,
13861,
77,
20094,
12,
6924,
21676,
20094,
2360,
4117,
19530,
12,
11581,
19530,
3186,
199,
504,
1275,
2326,
461,
492,
11581,
461,
199,
504,
5890,
492,
5228,
199,
199,
31635,
199,
5680,
2018,
5800,
10191,
334,
9105,
16332,
4040,
316,
9,
199,
31635,
199,
199,
63,
17714,
275,
1526,
14,
12460,
63,
14839,
435,
413,
199,
63,
3876,
259,
275,
1526,
14,
12460,
63,
14839,
435,
499,
199,
199,
3,
14355,
1116,
199,
3,
22422,
3164,
21149,
199,
199,
20094,
275,
13861,
77,
20094,
221,
327,
2951,
282,
1033,
23999,
199,
199,
3,
6516,
282,
9284,
3164,
21149,
199,
1944,
4117,
275,
11581,
19530,
8,
272,
283,
1944,
4117,
297,
91,
272,
283,
1291,
7,
260,
520,
3626,
1384,
14,
1944,
4117,
12,
272,
1526,
14,
9190,
258,
520,
3626,
1384,
14,
1944,
4117,
12,
272,
1526,
14,
1938,
260,
520,
3626,
1384,
14,
1944,
4117,
12,
272,
1526,
14,
5353,
258,
520,
3626,
1384,
14,
1944,
4117,
12,
272,
13343,
14,
10973,
520,
3626,
1384,
14,
1944,
4117,
12,
272,
1526,
14,
2339,
755,
520,
3626,
1384,
14,
1944,
4117,
12,
272,
1526,
14,
3170,
8803,
520,
3626,
1384,
14,
1944,
4117,
12,
339,
485,
17714,
260,
520,
3626,
1384,
14,
1944,
4117,
12,
272,
485,
3876,
3322,
520,
3626,
1384,
14,
1944,
4117,
12,
339,
283,
262,
63,
7650,
7,
420,
520,
6924,
21676,
20094,
14,
1944,
4117,
12,
221,
327,
6924,
8457,
272,
283,
262,
63,
1955,
7,
420,
520,
6924,
21676,
20094,
14,
1944,
4117,
12,
221,
327,
6924,
8457,
1329,
272,
283,
262,
63,
7650,
18,
7,
258,
520,
6924,
21676,
20094,
14,
1944,
4117,
12,
327,
1448,
1346,
4086,
8457,
272,
283,
262,
63,
3302,
7,
420,
520,
6924,
21676,
20094,
14,
1944,
4117,
12,
221,
327,
3164,
2331,
334,
527,
85,
14,
3626,
1384,
14,
6241,
9,
339,
283,
548,
63,
7650,
7,
258,
520,
3626,
1384,
14,
1944,
4117,
12,
327,
7242,
8457,
272,
283,
548,
63,
1955,
7,
258,
520,
3626,
1384,
14,
1944,
4117,
12,
327,
7242,
8457,
1329,
339,
283,
3302,
7,
260,
520,
3626,
1384,
14,
1944,
4117,
221,
327,
3164,
2331,
334,
527,
85,
14,
3626,
1384,
14,
6241,
9,
272,
789,
221,
776,
199,
199,
14091,
20094,
275,
11581,
19530,
8,
272,
283,
14091,
297,
91,
272,
283,
1291,
7,
260,
520,
3626,
1384,
14,
16393,
10858,
12,
272,
1526,
14,
9190,
258,
520,
3626,
1384,
14,
16393,
9156,
290,
12,
272,
1526,
14,
1938,
260,
520,
3626,
1384,
14,
57,
10723,
12,
272,
1526,
14,
5353,
258,
520,
3626,
1384,
14,
16393,
15617,
12,
272,
13343,
14,
10973,
520,
3626,
1384,
14,
16393,
10858,
12,
272,
1526,
14,
2339,
755,
520,
3626,
1384,
14,
6241,
12,
272,
1526,
14,
3170,
8803,
520,
3626,
1384,
14,
10858,
12,
339,
485,
17714,
260,
520,
3626,
1384,
14,
16393,
19456,
12,
272,
485,
3876,
3322,
520,
3626,
1384,
14,
57,
10723,
12,
339,
283,
262,
63,
7650,
7,
420,
520,
6924,
21676,
20094,
14,
19456,
12,
272,
283,
262,
63,
1955,
7,
420,
520,
6924,
21676,
20094,
14,
16393,
19456,
12,
272,
283,
262,
63,
7650,
18,
7,
258,
520,
6924,
21676,
20094,
14,
19456,
12,
272,
283,
262,
63,
3302,
7,
420,
520,
6924,
21676,
20094,
14,
6241,
12,
221,
327,
3164,
2331,
334,
527,
85,
14,
3626,
1384,
14,
6241,
9,
339,
283,
548,
63,
7650,
7,
258,
520,
3626,
1384,
14,
10858,
12,
272,
283,
548,
63,
1955,
7,
258,
520,
3626,
1384,
14,
16393,
10858,
12,
339,
283,
3302,
7,
260,
520,
3626,
1384,
14,
6241,
221,
327,
3164,
2331,
334,
527,
85,
14,
3626,
1384,
14,
6241,
9,
272,
789,
776,
199,
199,
4698,
29358,
20094,
275,
11581,
19530,
8,
272,
283,
4698,
29358,
297,
91,
272,
283,
1291,
7,
260,
520,
3626,
1384,
14,
10858,
12,
272,
1526,
14,
9190,
258,
520,
3626,
1384,
14,
9156,
290,
12,
272,
1526,
14,
1938,
260,
520,
3626,
1384,
14,
15617,
12,
272,
1526,
14,
5353,
258,
520,
3626,
1384,
14,
15617,
12,
272,
13343,
14,
10973,
520,
3626,
1384,
14,
10858,
12,
272,
1526,
14,
2339,
755,
520,
3626,
1384,
14,
6241,
12,
272,
1526,
14,
3170,
8803,
520,
3626,
1384,
14,
10858,
12,
339,
485,
17714,
260,
520,
3626,
1384,
14,
19456,
12,
272,
485,
3876,
3322,
520
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
2543,
436,
2240,
370,
31019,
2366,
1350,
1233,
367,
25600,
5537,
2551,
14,
199,
199,
20409,
641,
376,
4163,
1233,
4721,
18975,
351,
701,
1603,
300,
2268,
18769,
20059,
1911,
737,
26,
199,
1014,
921,
305,
4812,
14,
32595,
14,
957,
15,
1179,
9060,
15,
967,
32632,
15,
4718,
15,
25879,
15,
29915,
2905,
199,
199,
29188,
83,
701,
481,
27569,
22066,
11379,
25409,
334,
70,
321,
25409,
32,
2326,
5129,
14,
8654,
680,
199,
199,
4935,
641,
314,
3379,
4163,
4721,
18975,
351,
11924,
26,
199,
199,
3716,
262,
3716,
262,
446,
2018,
5800,
10191,
199,
199,
6888,
26,
11581,
794,
2018,
1350,
1808,
314,
6137,
13,
262,
14803,
199,
199,
17187,
351,
26,
1603,
300,
2268,
18769,
20059,
199,
6090,
6162,
68,
26,
8339,
15,
966,
15,
1690,
199,
199,
3353,
949,
26,
17,
14,
18,
199,
199,
5831,
26,
199,
199,
2765,
1233,
365,
1777,
402,
3930,
262,
3716,
262,
334,
1014,
921,
573,
262,
14,
22943,
14,
846,
24793,
436,
15373,
199,
4718,
1350,
1233,
370,
4163,
9189,
12,
14066,
6786,
12,
7681,
12,
199,
12688,
12,
8950,
436,
1059,
18041,
315,
3365,
9229,
14,
199,
199,
7940,
13703,
4212,
370,
675,
314,
6137,
13,
262,
4252,
12,
1526,
436,
13343,
4621,
370,
199,
6282,
2018,
1350,
1233,
436,
295,
13,
8159,
652,
543,
949,
4493,
370,
2399,
3379,
199,
20034,
334,
6777,
365,
314,
7508,
1777,
680,
199,
624,
199,
199,
363,
452,
363,
275,
788,
5622,
948,
380,
20094,
1673,
2842,
418,
199,
199,
63,
5512,
63,
885,
275,
283,
14091,
7,
421,
199,
3,
24339,
199,
646,
4252,
199,
646,
747,
199,
646,
984,
199,
646,
1526,
199,
646,
13343,
199,
199,
4208,
63,
4504,
275,
13343,
14,
4208,
63,
4504,
199,
199,
504,
16243,
14,
1208,
14,
2326,
22204,
492,
13861,
77,
20094,
12,
6924,
21676,
20094,
2360,
4117,
19530,
12,
11581,
19530,
3186,
199,
504,
1275,
2326,
461,
492,
11581,
461,
199,
504,
5890,
492,
5228,
199,
199,
31635,
199,
5680,
2018,
5800,
10191,
334,
9105,
16332,
4040,
316,
9,
199,
31635,
199,
199,
63,
17714,
275,
1526,
14,
12460,
63,
14839,
435,
413,
199,
63,
3876,
259,
275,
1526,
14,
12460,
63,
14839,
435,
499,
199,
199,
3,
14355,
1116,
199,
3,
22422,
3164,
21149,
199,
199,
20094,
275,
13861,
77,
20094,
221,
327,
2951,
282,
1033,
23999,
199,
199,
3,
6516,
282,
9284,
3164,
21149,
199,
1944,
4117,
275,
11581,
19530,
8,
272,
283,
1944,
4117,
297,
91,
272,
283,
1291,
7,
260,
520,
3626,
1384,
14,
1944,
4117,
12,
272,
1526,
14,
9190,
258,
520,
3626,
1384,
14,
1944,
4117,
12,
272,
1526,
14,
1938,
260,
520,
3626,
1384,
14,
1944,
4117,
12,
272,
1526,
14,
5353,
258,
520,
3626,
1384,
14,
1944,
4117,
12,
272,
13343,
14,
10973,
520,
3626,
1384,
14,
1944,
4117,
12,
272,
1526,
14,
2339,
755,
520,
3626,
1384,
14,
1944,
4117,
12,
272,
1526,
14,
3170,
8803,
520,
3626,
1384,
14,
1944,
4117,
12,
339,
485,
17714,
260,
520,
3626,
1384,
14,
1944,
4117,
12,
272,
485,
3876,
3322,
520,
3626,
1384,
14,
1944,
4117,
12,
339,
283,
262,
63,
7650,
7,
420,
520,
6924,
21676,
20094,
14,
1944,
4117,
12,
221,
327,
6924,
8457,
272,
283,
262,
63,
1955,
7,
420,
520,
6924,
21676,
20094,
14,
1944,
4117,
12,
221,
327,
6924,
8457,
1329,
272,
283,
262,
63,
7650,
18,
7,
258,
520,
6924,
21676,
20094,
14,
1944,
4117,
12,
327,
1448,
1346,
4086,
8457,
272,
283,
262,
63,
3302,
7,
420,
520,
6924,
21676,
20094,
14,
1944,
4117,
12,
221,
327,
3164,
2331,
334,
527,
85,
14,
3626,
1384,
14,
6241,
9,
339,
283,
548,
63,
7650,
7,
258,
520,
3626,
1384,
14,
1944,
4117,
12,
327,
7242,
8457,
272,
283,
548,
63,
1955,
7,
258,
520,
3626,
1384,
14,
1944,
4117,
12,
327,
7242,
8457,
1329,
339,
283,
3302,
7,
260,
520,
3626,
1384,
14,
1944,
4117,
221,
327,
3164,
2331,
334,
527,
85,
14,
3626,
1384,
14,
6241,
9,
272,
789,
221,
776,
199,
199,
14091,
20094,
275,
11581,
19530,
8,
272,
283,
14091,
297,
91,
272,
283,
1291,
7,
260,
520,
3626,
1384,
14,
16393,
10858,
12,
272,
1526,
14,
9190,
258,
520,
3626,
1384,
14,
16393,
9156,
290,
12,
272,
1526,
14,
1938,
260,
520,
3626,
1384,
14,
57,
10723,
12,
272,
1526,
14,
5353,
258,
520,
3626,
1384,
14,
16393,
15617,
12,
272,
13343,
14,
10973,
520,
3626,
1384,
14,
16393,
10858,
12,
272,
1526,
14,
2339,
755,
520,
3626,
1384,
14,
6241,
12,
272,
1526,
14,
3170,
8803,
520,
3626,
1384,
14,
10858,
12,
339,
485,
17714,
260,
520,
3626,
1384,
14,
16393,
19456,
12,
272,
485,
3876,
3322,
520,
3626,
1384,
14,
57,
10723,
12,
339,
283,
262,
63,
7650,
7,
420,
520,
6924,
21676,
20094,
14,
19456,
12,
272,
283,
262,
63,
1955,
7,
420,
520,
6924,
21676,
20094,
14,
16393,
19456,
12,
272,
283,
262,
63,
7650,
18,
7,
258,
520,
6924,
21676,
20094,
14,
19456,
12,
272,
283,
262,
63,
3302,
7,
420,
520,
6924,
21676,
20094,
14,
6241,
12,
221,
327,
3164,
2331,
334,
527,
85,
14,
3626,
1384,
14,
6241,
9,
339,
283,
548,
63,
7650,
7,
258,
520,
3626,
1384,
14,
10858,
12,
272,
283,
548,
63,
1955,
7,
258,
520,
3626,
1384,
14,
16393,
10858,
12,
339,
283,
3302,
7,
260,
520,
3626,
1384,
14,
6241,
221,
327,
3164,
2331,
334,
527,
85,
14,
3626,
1384,
14,
6241,
9,
272,
789,
776,
199,
199,
4698,
29358,
20094,
275,
11581,
19530,
8,
272,
283,
4698,
29358,
297,
91,
272,
283,
1291,
7,
260,
520,
3626,
1384,
14,
10858,
12,
272,
1526,
14,
9190,
258,
520,
3626,
1384,
14,
9156,
290,
12,
272,
1526,
14,
1938,
260,
520,
3626,
1384,
14,
15617,
12,
272,
1526,
14,
5353,
258,
520,
3626,
1384,
14,
15617,
12,
272,
13343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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
] |
ryanahall/django
|
django/core/management/commands/test.py
|
267
|
3933
|
import logging
import os
import sys
from django.conf import settings
from django.core.management.base import BaseCommand
from django.test.utils import get_runner
class Command(BaseCommand):
help = 'Discover and run tests in the specified modules or the current directory.'
requires_system_checks = False
def __init__(self):
self.test_runner = None
super(Command, self).__init__()
def run_from_argv(self, argv):
"""
Pre-parse the command line to extract the value of the --testrunner
option. This allows a test runner to define additional command line
arguments.
"""
option = '--testrunner='
for arg in argv[2:]:
if arg.startswith(option):
self.test_runner = arg[len(option):]
break
super(Command, self).run_from_argv(argv)
def add_arguments(self, parser):
parser.add_argument('args', metavar='test_label', nargs='*',
help='Module paths to test; can be modulename, modulename.TestCase or modulename.TestCase.test_method')
parser.add_argument('--noinput',
action='store_false', dest='interactive', default=True,
help='Tells Django to NOT prompt the user for input of any kind.'),
parser.add_argument('--failfast',
action='store_true', dest='failfast', default=False,
help='Tells Django to stop running the test suite after first '
'failed test.'),
parser.add_argument('--testrunner',
action='store', dest='testrunner',
help='Tells Django to use specified test runner class instead of '
'the one specified by the TEST_RUNNER setting.'),
parser.add_argument('--liveserver',
action='store', dest='liveserver', default=None,
help='Overrides the default address where the live server (used '
'with LiveServerTestCase) is expected to run from. The '
'default value is localhost:8081.'),
test_runner_class = get_runner(settings, self.test_runner)
if hasattr(test_runner_class, 'option_list'):
# Keeping compatibility with both optparse and argparse at this level
# would be too heavy for a non-critical item
raise RuntimeError(
"The method to extend accepted command-line arguments by the "
"test management command has changed in Django 1.8. Please "
"create an add_arguments class method to achieve this.")
if hasattr(test_runner_class, 'add_arguments'):
test_runner_class.add_arguments(parser)
def execute(self, *args, **options):
if options['verbosity'] > 0:
# ensure that deprecation warnings are displayed during testing
# the following state is assumed:
# logging.capturewarnings is true
# a "default" level warnings filter has been added for
# DeprecationWarning. See django.conf.LazySettings._configure_logging
logger = logging.getLogger('py.warnings')
handler = logging.StreamHandler()
logger.addHandler(handler)
super(Command, self).execute(*args, **options)
if options['verbosity'] > 0:
# remove the testing-specific handler
logger.removeHandler(handler)
def handle(self, *test_labels, **options):
from django.conf import settings
from django.test.utils import get_runner
TestRunner = get_runner(settings, options.get('testrunner'))
if options.get('liveserver') is not None:
os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] = options['liveserver']
del options['liveserver']
test_runner = TestRunner(**options)
failures = test_runner.run_tests(test_labels)
if failures:
sys.exit(bool(failures))
|
bsd-3-clause
|
[
646,
2050,
199,
646,
747,
199,
646,
984,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
199,
504,
1639,
14,
396,
14,
1208,
492,
664,
63,
5933,
421,
199,
533,
5817,
8,
25150,
304,
272,
1720,
275,
283,
2825,
5899,
436,
1255,
2295,
315,
314,
2013,
4621,
503,
314,
1453,
2082,
3530,
339,
5074,
63,
2253,
63,
8625,
275,
756,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
396,
63,
5933,
275,
488,
267,
1613,
8,
3110,
12,
291,
2843,
826,
4533,
339,
347,
1255,
63,
504,
63,
3020,
8,
277,
12,
9238,
304,
267,
408,
267,
5543,
13,
1122,
314,
1414,
1004,
370,
5536,
314,
574,
402,
314,
1553,
396,
5933,
267,
945,
14,
961,
6127,
282,
511,
7876,
370,
5627,
4722,
1414,
1004,
267,
2368,
14,
267,
408,
267,
945,
275,
2850,
396,
5933,
534,
267,
367,
1680,
315,
9238,
59,
18,
10688,
288,
340,
1680,
14,
2460,
8,
1422,
304,
355,
291,
14,
396,
63,
5933,
275,
1680,
59,
552,
8,
1422,
15405,
355,
2059,
267,
1613,
8,
3110,
12,
291,
680,
1065,
63,
504,
63,
3020,
8,
3020,
9,
339,
347,
1050,
63,
4958,
8,
277,
12,
1798,
304,
267,
1798,
14,
525,
63,
2094,
360,
589,
297,
8214,
534,
396,
63,
1302,
297,
9237,
534,
7693,
288,
1720,
534,
2377,
3792,
370,
511,
27,
883,
506,
30045,
12,
30045,
14,
1746,
503,
30045,
14,
1746,
14,
396,
63,
765,
358,
267,
1798,
14,
525,
63,
2094,
4517,
889,
1210,
297,
288,
1595,
534,
1617,
63,
3910,
297,
2053,
534,
13543,
297,
849,
29,
549,
12,
288,
1720,
534,
52,
6840,
5634,
370,
2845,
8457,
314,
922,
367,
1324,
402,
1263,
4928,
8038,
267,
1798,
14,
525,
63,
2094,
4517,
25829,
297,
288,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
25829,
297,
849,
29,
797,
12,
288,
1720,
534,
52,
6840,
5634,
370,
3631,
3879,
314,
511,
5241,
2410,
1642,
283,
326,
283,
4892,
511,
8038,
267,
1798,
14,
525,
63,
2094,
4517,
396,
5933,
297,
288,
1595,
534,
1617,
297,
2053,
534,
396,
5933,
297,
288,
1720,
534,
52,
6840,
5634,
370,
675,
2013,
511,
7876,
1021,
3140,
402,
283,
326,
283,
1589,
1373,
2013,
701,
314,
7393,
63,
9390,
15215,
4260,
8038,
267,
1798,
14,
525,
63,
2094,
4517,
6442,
1000,
297,
288,
1595,
534,
1617,
297,
2053,
534,
6442,
1000,
297,
849,
29,
403,
12,
288,
1720,
534,
27586,
314,
849,
2287,
2382,
314,
12166,
1654,
334,
2972,
283,
326,
283,
1045,
24683,
3120,
1746,
9,
365,
1420,
370,
1255,
687,
14,
710,
283,
326,
283,
885,
574,
365,
11667,
26,
1257,
2835,
8038,
398,
511,
63,
5933,
63,
533,
275,
664,
63,
5933,
8,
1751,
12,
291,
14,
396,
63,
5933,
9,
267,
340,
2688,
8,
396,
63,
5933,
63,
533,
12,
283,
1422,
63,
513,
735,
288,
327,
1804,
1024,
4073,
7163,
543,
3865,
8691,
436,
7534,
737,
642,
2166,
288,
327,
3955,
506,
4634,
946,
22421,
367,
282,
2222,
13,
13138,
1242,
288,
746,
6064,
8,
355,
298,
1918,
1083,
370,
12247,
10226,
1414,
13,
604,
2368,
701,
314,
298,
355,
298,
396,
10041,
1414,
965,
2896,
315,
5634,
413,
14,
24,
14,
7754,
298,
355,
298,
981,
376,
1050,
63,
4958,
1021,
1083,
370,
32194,
642,
2685,
398,
340,
2688,
8,
396,
63,
5933,
63,
533,
12,
283,
525,
63,
4958,
735,
288,
511,
63,
5933,
63,
533,
14,
525,
63,
4958,
8,
2087,
9,
339,
347,
5341,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
267,
340,
1511,
459,
9833,
418,
690,
378,
26,
288,
327,
4868,
626,
17831,
3598,
787,
9080,
5309,
5343,
288,
327,
314,
2569,
1174,
365,
10826,
26,
288,
327,
2050,
14,
12685,
5451,
365,
2549,
288,
327,
282,
298,
885,
2,
2166,
3598,
2457,
965,
2757,
3483,
367,
288,
327,
13413,
14,
1666,
1639,
14,
2190,
14,
14269,
5268,
423,
6472,
63,
4806,
288,
2512,
275,
2050,
14,
5572,
360,
647,
14,
5451,
358,
288,
3016,
275,
2050,
14,
22482,
342,
288,
2512,
14,
18826,
8,
2232,
9,
267,
1613,
8,
3110,
12,
291,
680,
2526,
2031,
589,
12,
1011,
1419,
9,
267,
340,
1511,
459,
9833,
418,
690,
378,
26,
288,
327,
2813,
314,
5343,
13,
6100,
3016,
288,
2512,
14,
2168,
2461,
8,
2232,
9,
339,
347,
2429,
8,
277,
12,
627,
396,
63,
3512,
12,
1011,
1419,
304,
267,
687,
1639,
14,
2190,
492,
2202,
267,
687,
1639,
14,
396,
14,
1208,
492,
664,
63,
5933,
398,
1379,
7446,
275,
664,
63,
5933,
8,
1751,
12,
1511,
14,
362,
360,
396,
5933,
1333,
398,
340,
1511,
14,
362,
360,
6442,
1000,
358,
365,
440,
488,
26,
288,
747,
14,
2314,
459,
22848,
63,
31541,
63,
2864,
63,
6613,
63,
12368,
418,
275,
1511,
459,
6442,
1000,
418,
288,
2150,
1511,
459,
6442,
1000,
418,
398,
511,
63,
5933,
275,
1379,
7446,
3682,
1419,
9,
267,
9081,
275,
511,
63,
5933,
14,
1065,
63,
2219,
8,
396,
63,
3512,
9,
398,
340,
9081,
26,
288,
984,
14,
2224,
8,
2245,
8,
9968,
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
] |
[
2050,
199,
646,
747,
199,
646,
984,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
199,
504,
1639,
14,
396,
14,
1208,
492,
664,
63,
5933,
421,
199,
533,
5817,
8,
25150,
304,
272,
1720,
275,
283,
2825,
5899,
436,
1255,
2295,
315,
314,
2013,
4621,
503,
314,
1453,
2082,
3530,
339,
5074,
63,
2253,
63,
8625,
275,
756,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
396,
63,
5933,
275,
488,
267,
1613,
8,
3110,
12,
291,
2843,
826,
4533,
339,
347,
1255,
63,
504,
63,
3020,
8,
277,
12,
9238,
304,
267,
408,
267,
5543,
13,
1122,
314,
1414,
1004,
370,
5536,
314,
574,
402,
314,
1553,
396,
5933,
267,
945,
14,
961,
6127,
282,
511,
7876,
370,
5627,
4722,
1414,
1004,
267,
2368,
14,
267,
408,
267,
945,
275,
2850,
396,
5933,
534,
267,
367,
1680,
315,
9238,
59,
18,
10688,
288,
340,
1680,
14,
2460,
8,
1422,
304,
355,
291,
14,
396,
63,
5933,
275,
1680,
59,
552,
8,
1422,
15405,
355,
2059,
267,
1613,
8,
3110,
12,
291,
680,
1065,
63,
504,
63,
3020,
8,
3020,
9,
339,
347,
1050,
63,
4958,
8,
277,
12,
1798,
304,
267,
1798,
14,
525,
63,
2094,
360,
589,
297,
8214,
534,
396,
63,
1302,
297,
9237,
534,
7693,
288,
1720,
534,
2377,
3792,
370,
511,
27,
883,
506,
30045,
12,
30045,
14,
1746,
503,
30045,
14,
1746,
14,
396,
63,
765,
358,
267,
1798,
14,
525,
63,
2094,
4517,
889,
1210,
297,
288,
1595,
534,
1617,
63,
3910,
297,
2053,
534,
13543,
297,
849,
29,
549,
12,
288,
1720,
534,
52,
6840,
5634,
370,
2845,
8457,
314,
922,
367,
1324,
402,
1263,
4928,
8038,
267,
1798,
14,
525,
63,
2094,
4517,
25829,
297,
288,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
25829,
297,
849,
29,
797,
12,
288,
1720,
534,
52,
6840,
5634,
370,
3631,
3879,
314,
511,
5241,
2410,
1642,
283,
326,
283,
4892,
511,
8038,
267,
1798,
14,
525,
63,
2094,
4517,
396,
5933,
297,
288,
1595,
534,
1617,
297,
2053,
534,
396,
5933,
297,
288,
1720,
534,
52,
6840,
5634,
370,
675,
2013,
511,
7876,
1021,
3140,
402,
283,
326,
283,
1589,
1373,
2013,
701,
314,
7393,
63,
9390,
15215,
4260,
8038,
267,
1798,
14,
525,
63,
2094,
4517,
6442,
1000,
297,
288,
1595,
534,
1617,
297,
2053,
534,
6442,
1000,
297,
849,
29,
403,
12,
288,
1720,
534,
27586,
314,
849,
2287,
2382,
314,
12166,
1654,
334,
2972,
283,
326,
283,
1045,
24683,
3120,
1746,
9,
365,
1420,
370,
1255,
687,
14,
710,
283,
326,
283,
885,
574,
365,
11667,
26,
1257,
2835,
8038,
398,
511,
63,
5933,
63,
533,
275,
664,
63,
5933,
8,
1751,
12,
291,
14,
396,
63,
5933,
9,
267,
340,
2688,
8,
396,
63,
5933,
63,
533,
12,
283,
1422,
63,
513,
735,
288,
327,
1804,
1024,
4073,
7163,
543,
3865,
8691,
436,
7534,
737,
642,
2166,
288,
327,
3955,
506,
4634,
946,
22421,
367,
282,
2222,
13,
13138,
1242,
288,
746,
6064,
8,
355,
298,
1918,
1083,
370,
12247,
10226,
1414,
13,
604,
2368,
701,
314,
298,
355,
298,
396,
10041,
1414,
965,
2896,
315,
5634,
413,
14,
24,
14,
7754,
298,
355,
298,
981,
376,
1050,
63,
4958,
1021,
1083,
370,
32194,
642,
2685,
398,
340,
2688,
8,
396,
63,
5933,
63,
533,
12,
283,
525,
63,
4958,
735,
288,
511,
63,
5933,
63,
533,
14,
525,
63,
4958,
8,
2087,
9,
339,
347,
5341,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
267,
340,
1511,
459,
9833,
418,
690,
378,
26,
288,
327,
4868,
626,
17831,
3598,
787,
9080,
5309,
5343,
288,
327,
314,
2569,
1174,
365,
10826,
26,
288,
327,
2050,
14,
12685,
5451,
365,
2549,
288,
327,
282,
298,
885,
2,
2166,
3598,
2457,
965,
2757,
3483,
367,
288,
327,
13413,
14,
1666,
1639,
14,
2190,
14,
14269,
5268,
423,
6472,
63,
4806,
288,
2512,
275,
2050,
14,
5572,
360,
647,
14,
5451,
358,
288,
3016,
275,
2050,
14,
22482,
342,
288,
2512,
14,
18826,
8,
2232,
9,
267,
1613,
8,
3110,
12,
291,
680,
2526,
2031,
589,
12,
1011,
1419,
9,
267,
340,
1511,
459,
9833,
418,
690,
378,
26,
288,
327,
2813,
314,
5343,
13,
6100,
3016,
288,
2512,
14,
2168,
2461,
8,
2232,
9,
339,
347,
2429,
8,
277,
12,
627,
396,
63,
3512,
12,
1011,
1419,
304,
267,
687,
1639,
14,
2190,
492,
2202,
267,
687,
1639,
14,
396,
14,
1208,
492,
664,
63,
5933,
398,
1379,
7446,
275,
664,
63,
5933,
8,
1751,
12,
1511,
14,
362,
360,
396,
5933,
1333,
398,
340,
1511,
14,
362,
360,
6442,
1000,
358,
365,
440,
488,
26,
288,
747,
14,
2314,
459,
22848,
63,
31541,
63,
2864,
63,
6613,
63,
12368,
418,
275,
1511,
459,
6442,
1000,
418,
288,
2150,
1511,
459,
6442,
1000,
418,
398,
511,
63,
5933,
275,
1379,
7446,
3682,
1419,
9,
267,
9081,
275,
511,
63,
5933,
14,
1065,
63,
2219,
8,
396,
63,
3512,
9,
398,
340,
9081,
26,
288,
984,
14,
2224,
8,
2245,
8,
9968,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pamoakoy/invenio
|
modules/websubmit/lib/functions/Mail_Approval_Withdrawn_to_Referee.py
|
35
|
17043
|
## This file is part of Invenio.
## Copyright (C) 2008, 2009, 2010, 2011 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.
"""Mail_Approval_Withdrawn_to_Referee: A function to send an email to the
referee of a document informing him/her that the request for its approval
has been withdrawn.
"""
__revision__ = "$Id$"
import os
import re
import sre_constants
from invenio.websubmit_config import InvenioWebSubmitFunctionWarning, \
CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN
from invenio.config import CFG_CERN_SITE, \
CFG_SITE_NAME, \
CFG_SITE_SUPPORT_EMAIL
from invenio.access_control_admin import acc_get_role_users, acc_get_role_id
from invenio.websubmit_functions.Shared_Functions import ParamFromFile
from invenio.errorlib import register_exception
from invenio.websubmit_dblayer import get_approval_request_notes
from invenio.mailutils import send_email
CFG_MAIL_BODY = """
The request for approval of the document [%(report-number)s] in
%(site-name)s has been withdrawn and no longer
requires your attention as referee.
"""
def Mail_Approval_Withdrawn_to_Referee(parameters, \
curdir, \
form, \
user_info=None):
"""
This function sends an email to the referee of a document informing
him/her that the request for its approval has been withdrawn.
@param categ_file_withd: (string) - some document types are
separated into different categories, each of which has its own
referee(s).
In such document types, it's necessary to know the document-
type's category in order to choose the referee.
This parameter provides a means by which the category information
can be extracted from a file in the current submission's working
directory. It should therefore be a filename.
@param categ_rnseek_withd: (string) - some document types are
separated into different categories, each of which has its own
referee(s).
In such document types, it's necessary to know the document-
type's category in order to choose the referee.
This parameter provides a means by which the category information
can be extracted from the document's reference number.
It is infact a string that will be compiled into a regexp and
an attempt will be made to match it agains the document's reference
number starting from the left-most position.
The only pre-requisite is that the segment in which the category is
sought should be indicated with <CATEGORY>.
Thus, an example might be as follows:
ATL(-COM)?-<CATEGORY>-.+
This would allow "PHYS" in the following reference number to be
recognised as the category:
ATL-COM-PHYS-2008-001
@return: (string) - empty string.
"""
## Get the reference number (as global rn - sorry!) and the document type:
global sysno, rn
doctype = form['doctype']
########
## Get the parameters from the list:
########
## Get the name of the category file:
#######
try:
## If it has been provided, get the name of the file in which the
## category is stored:
category_file = parameters["categ_file_withd"]
except KeyError:
## No value given for the category file:
category_file = None
else:
if category_file is not None:
category_file = str(category_file)
category_file = os.path.basename(category_file).strip()
if category_file == "":
category_file = None
########
## Get the regexp that is used to find the category in the report number:
########
try:
## If it has been provided, get the regexp used for identifying
## a document-type's category from its reference number:
category_rn_regexp = parameters["categ_rnseek_withd"]
except KeyError:
## No value given for the category regexp:
category_rn_regexp = None
else:
if category_rn_regexp is not None:
category_rn_regexp = str(category_rn_regexp).strip()
if category_rn_regexp == "":
category_rn_regexp = None
#######
## Resolve the document type's category:
##
## This is a long process. The end result is that the category is extracted
## either from a file in curdir, or from the report number.
## If it's taken from the report number, the admin must configure the
## function to accept a regular expression that is used to find the
## category in the report number.
##
if category_file is not None and category_rn_regexp is not None:
## It is not valid to have both a category file and a pattern
## describing how to extract the category from a report number.
## raise an InvenioWebSubmitFunctionWarning:
msg = "Error in Mail_Approval_Withdrawn_to_Referee function: " \
"received instructions to search for the document's category " \
"in both its report number AND in a category file. Could " \
"not determine which to use - please notify the " \
"administrator."
raise InvenioWebSubmitFunctionWarning(msg)
elif category_file is not None:
## Attempt to recover the category information from a file in the
## current submission's working directory:
category = ParamFromFile("%s/%s" % (curdir, category_file))
if category is not None:
category = category.strip()
if category in (None, ""):
## The category cannot be resolved.
msg = "Error in Mail_Approval_Withdrawn_to_Referee function: " \
"received instructions to search for the document's " \
"category in a category file, but could not recover the " \
"category from that file. The referee cannot be notified " \
"of the approval request withdrawal by mail."
raise InvenioWebSubmitFunctionWarning(msg)
elif category_rn_regexp is not None:
## Attempt to recover the category information from the document's
## reference number using the regexp in category_rn_regexp:
##
## Does the category regexp contain the key-phrase "<CATEG>"?
if category_rn_regexp.find("<CATEG>") != -1:
## Yes. Replace "<CATEG>" with "(?P<category>.+?)".
## For example, this:
## ATL(-COM)?-<CATEG>-
## Will be transformed into this:
## ATL(-COM)?-(?P<category>.+?)-
category_rn_final_regexp = \
category_rn_regexp.replace("<CATEG>", r"(?P<category>.+?)", 1)
else:
## The regexp for category didn't contain "<CATEG>", but this is
## mandatory.
msg = "Error in Mail_Approval_Withdrawn_to_Referee function: The" \
" [%(doctype)s] submission has been configured to search " \
"for the document type's category in its reference number," \
" using a poorly formed search expression (no marker for " \
"the category was present.) Since the document's category " \
"cannot be retrieved, the referee cannot be " \
"notified of the approval request withdrawal by mail." \
% { 'doctype' : doctype, }
raise InvenioWebSubmitFunctionWarning(msg)
##
try:
## Attempt to compile the regexp for finding the category:
re_categ_from_rn = re.compile(category_rn_final_regexp)
except sre_constants.error:
## The expression passed to this function could not be compiled
## into a regexp. Register this exception and raise an
## InvenioWebSubmitFunctionWarning:
exception_prefix = "Error in Mail_Approval_Withdrawn_to_Referee " \
"function: The [%(doctype)s] submission has " \
"been configured to search for the document " \
"type's category in its reference number, " \
"using the following regexp: /%(regexp)s/. " \
"This regexp, however, could not be " \
"compiled correctly (created it from " \
"%(categ-search-term)s.)" \
% { 'doctype' : doctype, \
'regexp' : category_rn_final_regexp, \
'categ-search-term' : category_rn_regexp, }
register_exception(prefix=exception_prefix)
msg = "Error in Mail_Approval_Withdrawn_to_Referee function: The" \
" [%(doctype)s] submission has been configured to search " \
"for the document type's category in its reference number," \
" using a poorly formed search expression. Since the " \
"document's category cannot be retrieved, the referee" \
"cannot be notified of the approval request withdrawal by " \
"mail." \
% { 'doctype' : doctype, }
raise InvenioWebSubmitFunctionWarning(msg)
else:
## Now attempt to recover the category from the RN string:
m_categ_from_rn = re_categ_from_rn.match(rn)
if m_categ_from_rn is not None:
## The pattern matched in the string.
## Extract the category from the match:
try:
category = m_categ_from_rn.group("category")
except IndexError:
## There was no "category" group. That group is mandatory.
exception_prefix = \
"Error in Mail_Approval_Withdrawn_to_Referee " \
"function: The [%(doctype)s] submission has been " \
"configured to search for the document type's " \
"category in its reference number using the " \
"following regexp: " \
"/%(regexp)s/. The search produced a match, but " \
"there was no \"category\" group in the match " \
"object although this group is mandatory. The " \
"regexp was compiled from the following string: " \
"[%(categ-search-term)s]." \
% { 'doctype' : doctype, \
'regexp' : category_rn_final_regexp, \
'categ-search-term' : category_rn_regexp, }
register_exception(prefix=exception_prefix)
msg = "Error in Mail_Approval_Withdrawn_to_Referee " \
"function: The [%(doctype)s] submission has been " \
"configured to search for the document type's " \
"category in its reference number, using a poorly " \
"formed search expression (there was no category " \
"marker). Since the document's category therefore " \
"cannot be retrieved, the referee cannot be " \
"notified of the approval request withdrawal " \
"by mail." \
% { 'doctype' : doctype, }
raise InvenioWebSubmitFunctionWarning(msg)
else:
category = category.strip()
if category == "":
msg = "Error in Mail_Approval_Withdrawn_to_Referee " \
"function: The [%(doctype)s] submission has " \
"been configured to search for the document " \
"type's category in its reference number, but " \
"no category was found. The referee cannot be " \
"notified of the approval request withdrawal " \
"by mail." \
% { 'doctype' : doctype, }
raise InvenioWebSubmitFunctionWarning(msg)
else:
## No match. Cannot find the category and therefore cannot
## continue:
msg = "Error in Mail_Approval_Withdrawn_to_Referee function:" \
" The [%(doctype)s] submission has been configured to " \
"search for the document type's category in its " \
"reference number, but no match was made. The referee " \
"cannot be notified of the approval request " \
"withdrawal by mail." \
% { 'doctype' : doctype, }
raise InvenioWebSubmitFunctionWarning(msg)
else:
## The document type has no category.
category = ""
##
## End of category recovery
#######
## Get the referee email address:
if CFG_CERN_SITE:
## The referees system in CERN now works with listbox membership.
## List names should take the format
## "service-cds-referee-doctype-category@cern.ch"
## Make sure that your list exists!
## FIXME - to be replaced by a mailing alias in webaccess in the
## future.
## see if was a PROC request or not
notes = get_approval_request_notes(doctype,rn)
was_proc = 'n'
was_slide = 'n'
if notes:
note_lines = notes.split('\n')
for note_line in note_lines:
if note_line.find('Requested Note Classification:') == 0:
note_type = note_line.split()[-1]
if note_type == 'PROC':
was_proc = 'y'
elif note_type == 'SLIDE':
was_slide = 'y'
break # there may be more than one - just take the first
if was_proc == 'y':
referee_listname = "service-cds-referee-%s" % doctype.lower()
referee_listname += "-%s" % 'proc'
elif was_slide == 'y':
referee_listname = "atlas-speakers-comm"
else:
referee_listname = "service-cds-referee-%s" % doctype.lower()
if category != "":
referee_listname += "-%s" % category.lower()
referee_listname += "@cern.ch"
mailto_addresses = referee_listname
if category == 'CDSTEST': ## our special testing category
referee_listname = "service-cds-referee-%s" % doctype.lower()
referee_listname += "-%s" % category.lower()
mailto_addresses = referee_listname + "@cern.ch"
else:
referee_address = ""
## Try to retrieve the referee's email from the referee's database:
for user in \
acc_get_role_users(acc_get_role_id("referee_%s_%s" \
% (doctype, category))):
referee_address += user[1] + ","
## And if there are general referees:
for user in \
acc_get_role_users(acc_get_role_id("referee_%s_*" % doctype)):
referee_address += user[1] + ","
referee_address = re.sub(",$", "", referee_address)
# Creation of the mail for the referee
mailto_addresses = ""
if referee_address != "":
mailto_addresses = referee_address + ","
else:
mailto_addresses = re.sub(",$", "", mailto_addresses)
##
## Send the email:
mail_subj = "Request for approval of [%s] withdrawn" % rn
mail_body = CFG_MAIL_BODY % \
{ 'site-name' : CFG_SITE_NAME,
'report-number' : rn,
}
send_email(CFG_SITE_SUPPORT_EMAIL,
mailto_addresses,
mail_subj,
mail_body,
copy_to_admin=CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN)
##
return ""
|
gpl-2.0
|
[
309,
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
9079,
12,
8937,
12,
7129,
12,
7760,
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,
13681,
63,
25923,
637,
63,
3007,
5485,
78,
63,
475,
63,
497,
771,
850,
26,
437,
805,
370,
3222,
376,
3031,
370,
314,
2043,
295,
771,
850,
402,
282,
2213,
315,
964,
316,
26457,
15,
2523,
626,
314,
1056,
367,
2399,
4286,
637,
2043,
965,
2757,
543,
5485,
78,
14,
199,
624,
421,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
199,
646,
747,
199,
646,
295,
199,
646,
25877,
63,
5559,
199,
504,
13640,
14,
2520,
7275,
63,
888,
492,
12235,
5926,
17187,
3481,
3849,
12,
971,
3660,
10974,
63,
13166,
6348,
13965,
63,
16188,
63,
8175,
51,
63,
2566,
63,
14288,
199,
504,
13640,
14,
888,
492,
10974,
63,
35,
14482,
63,
7917,
12,
971,
2574,
10974,
63,
7917,
63,
2339,
12,
971,
2574,
10974,
63,
7917,
63,
10640,
63,
10089,
199,
504,
13640,
14,
2732,
63,
2785,
63,
2113,
492,
6907,
63,
362,
63,
3756,
63,
3707,
12,
6907,
63,
362,
63,
3756,
63,
344,
199,
504,
13640,
14,
2520,
7275,
63,
5777,
14,
12197,
63,
13967,
492,
12608,
26637,
199,
504,
13640,
14,
705,
773,
492,
2274,
63,
1971,
199,
504,
13640,
14,
2520,
7275,
63,
697,
1897,
492,
664,
63,
28302,
63,
1069,
63,
5983,
199,
504,
13640,
14,
1198,
1208,
492,
3222,
63,
2123,
421,
199,
10118,
63,
8175,
63,
23708,
275,
408,
199,
1918,
1056,
367,
4286,
637,
402,
314,
2213,
359,
2840,
3070,
13,
1955,
9,
83,
61,
315,
199,
2840,
2124,
13,
354,
9,
83,
965,
2757,
543,
5485,
78,
436,
949,
8088,
199,
6537,
2195,
22814,
465,
295,
771,
850,
14,
199,
624,
4388,
199,
318,
18027,
63,
25923,
637,
63,
3007,
5485,
78,
63,
475,
63,
497,
771,
850,
8,
3214,
12,
971,
4318,
1094,
694,
12,
971,
4318,
1824,
12,
971,
4318,
922,
63,
815,
29,
403,
304,
272,
408,
272,
961,
805,
16178,
376,
3031,
370,
314,
295,
771,
850,
402,
282,
2213,
315,
964,
316,
272,
26457,
15,
2523,
626,
314,
1056,
367,
2399,
4286,
637,
965,
2757,
543,
5485,
78,
14,
339,
768,
635,
7737,
63,
493,
63,
1045,
68,
26,
334,
875,
9,
446,
2005,
2213,
2943,
787,
1779,
11673,
1901,
3365,
9695,
12,
1924,
402,
1314,
965,
2399,
5705,
1779,
295,
771,
850,
8,
83,
680,
1779,
1010,
4066,
2213,
2943,
12,
652,
1159,
5784,
370,
5715,
314,
2213,
13,
1779,
730,
1159,
4637,
315,
1865,
370,
11496,
314,
295,
771,
850,
14,
1779,
961,
2725,
6571,
282,
4910,
701,
1314,
314,
4637,
2556,
1779,
883,
506,
12509,
687,
282,
570,
315,
314,
1453,
13071,
1159,
6449,
1779,
2082,
14,
2779,
1077,
16119,
506,
282,
1788,
14,
339,
768,
635,
7737,
63,
11641,
5507,
63,
1045,
68,
26,
334,
875,
9,
446,
2005,
2213,
2943,
787,
1779,
11673,
1901,
3365,
9695,
12,
1924,
402,
1314,
965,
2399,
5705,
1779,
295,
771,
850,
8,
83,
680,
1779,
1010,
4066,
2213,
2943,
12,
652,
1159,
5784,
370,
5715,
314,
2213,
13,
1779,
730,
1159,
4637,
315,
1865,
370,
11496,
314,
295,
771,
850,
14,
1779,
961,
2725,
6571,
282,
4910,
701,
1314,
314,
4637,
2556,
1779,
883,
506,
12509,
687,
314,
2213,
1159,
3659,
1329,
14,
1779,
2779,
365,
315,
7783,
282,
1059,
626,
911,
506,
10311,
1901,
282,
13156,
436,
1779,
376,
7427,
911,
506,
6326,
370,
1336,
652,
4020,
83,
314,
2213,
1159,
3659,
1779,
1329,
6617,
687,
314,
3602,
13,
2786,
3421,
14,
1779,
710,
1454,
876,
13,
21763,
365,
626,
314,
8135,
315,
1314,
314,
4637,
365,
1779,
308,
20816,
1077,
506,
22141,
543,
665,
22690,
10827,
1779,
20227,
12,
376,
2893,
5594,
506,
465,
11924,
26,
1598,
437,
7308,
2801,
11265,
5547,
13,
28,
22690,
24860,
6977,
1779,
961,
3955,
2040,
298,
9791,
20238,
2,
315,
314,
2569,
3659,
1329,
370,
506,
1779,
17319,
9096,
465,
314,
4637,
26,
1598,
437,
7308,
13,
11265,
13,
9791,
20238,
13,
9300,
13,
4587,
339,
768,
1107,
26,
334,
875,
9,
446,
2701,
1059,
14,
272,
408,
272,
925,
2372,
314,
3659,
1329,
334,
305,
2288,
519,
78,
446,
308,
21342,
21866,
436,
314,
2213,
730,
26,
272,
2288,
984,
889,
12,
519,
78,
272,
13265,
275,
1824,
459,
6356,
418,
339,
21937,
272,
925,
2372,
314,
2633,
687,
314,
769,
26,
339,
21937,
272,
925,
2372,
314,
536,
402,
314,
4637,
570,
26,
272,
221,
14776,
272,
862,
26,
267,
925,
982,
652,
965,
2757,
2741,
12,
664,
314,
536,
402,
314,
570,
315,
1314,
314,
267,
925,
4637,
365,
5489,
26,
267,
4637,
63,
493,
275,
2633,
905,
3533,
63,
493,
63,
1045,
68,
937,
272,
871,
4067,
26,
267,
925,
3091,
574,
1627,
367,
314,
4637,
570,
26,
267,
4637,
63,
493,
275,
488,
272,
587,
26,
267,
340,
4637,
63,
493,
365,
440,
488,
26,
288,
4637,
63,
493,
275,
620,
8,
3710,
63,
493,
9,
288,
4637,
63,
493,
275,
747,
14,
515,
14,
4846,
8,
3710,
63,
493,
680,
1913,
342,
288,
340,
4637,
63,
493,
508,
10812,
355,
4637,
63,
493,
275,
488,
272,
21937,
272,
925,
2372,
314,
13156,
626
] |
[
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
9079,
12,
8937,
12,
7129,
12,
7760,
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,
13681,
63,
25923,
637,
63,
3007,
5485,
78,
63,
475,
63,
497,
771,
850,
26,
437,
805,
370,
3222,
376,
3031,
370,
314,
2043,
295,
771,
850,
402,
282,
2213,
315,
964,
316,
26457,
15,
2523,
626,
314,
1056,
367,
2399,
4286,
637,
2043,
965,
2757,
543,
5485,
78,
14,
199,
624,
421,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
199,
646,
747,
199,
646,
295,
199,
646,
25877,
63,
5559,
199,
504,
13640,
14,
2520,
7275,
63,
888,
492,
12235,
5926,
17187,
3481,
3849,
12,
971,
3660,
10974,
63,
13166,
6348,
13965,
63,
16188,
63,
8175,
51,
63,
2566,
63,
14288,
199,
504,
13640,
14,
888,
492,
10974,
63,
35,
14482,
63,
7917,
12,
971,
2574,
10974,
63,
7917,
63,
2339,
12,
971,
2574,
10974,
63,
7917,
63,
10640,
63,
10089,
199,
504,
13640,
14,
2732,
63,
2785,
63,
2113,
492,
6907,
63,
362,
63,
3756,
63,
3707,
12,
6907,
63,
362,
63,
3756,
63,
344,
199,
504,
13640,
14,
2520,
7275,
63,
5777,
14,
12197,
63,
13967,
492,
12608,
26637,
199,
504,
13640,
14,
705,
773,
492,
2274,
63,
1971,
199,
504,
13640,
14,
2520,
7275,
63,
697,
1897,
492,
664,
63,
28302,
63,
1069,
63,
5983,
199,
504,
13640,
14,
1198,
1208,
492,
3222,
63,
2123,
421,
199,
10118,
63,
8175,
63,
23708,
275,
408,
199,
1918,
1056,
367,
4286,
637,
402,
314,
2213,
359,
2840,
3070,
13,
1955,
9,
83,
61,
315,
199,
2840,
2124,
13,
354,
9,
83,
965,
2757,
543,
5485,
78,
436,
949,
8088,
199,
6537,
2195,
22814,
465,
295,
771,
850,
14,
199,
624,
4388,
199,
318,
18027,
63,
25923,
637,
63,
3007,
5485,
78,
63,
475,
63,
497,
771,
850,
8,
3214,
12,
971,
4318,
1094,
694,
12,
971,
4318,
1824,
12,
971,
4318,
922,
63,
815,
29,
403,
304,
272,
408,
272,
961,
805,
16178,
376,
3031,
370,
314,
295,
771,
850,
402,
282,
2213,
315,
964,
316,
272,
26457,
15,
2523,
626,
314,
1056,
367,
2399,
4286,
637,
965,
2757,
543,
5485,
78,
14,
339,
768,
635,
7737,
63,
493,
63,
1045,
68,
26,
334,
875,
9,
446,
2005,
2213,
2943,
787,
1779,
11673,
1901,
3365,
9695,
12,
1924,
402,
1314,
965,
2399,
5705,
1779,
295,
771,
850,
8,
83,
680,
1779,
1010,
4066,
2213,
2943,
12,
652,
1159,
5784,
370,
5715,
314,
2213,
13,
1779,
730,
1159,
4637,
315,
1865,
370,
11496,
314,
295,
771,
850,
14,
1779,
961,
2725,
6571,
282,
4910,
701,
1314,
314,
4637,
2556,
1779,
883,
506,
12509,
687,
282,
570,
315,
314,
1453,
13071,
1159,
6449,
1779,
2082,
14,
2779,
1077,
16119,
506,
282,
1788,
14,
339,
768,
635,
7737,
63,
11641,
5507,
63,
1045,
68,
26,
334,
875,
9,
446,
2005,
2213,
2943,
787,
1779,
11673,
1901,
3365,
9695,
12,
1924,
402,
1314,
965,
2399,
5705,
1779,
295,
771,
850,
8,
83,
680,
1779,
1010,
4066,
2213,
2943,
12,
652,
1159,
5784,
370,
5715,
314,
2213,
13,
1779,
730,
1159,
4637,
315,
1865,
370,
11496,
314,
295,
771,
850,
14,
1779,
961,
2725,
6571,
282,
4910,
701,
1314,
314,
4637,
2556,
1779,
883,
506,
12509,
687,
314,
2213,
1159,
3659,
1329,
14,
1779,
2779,
365,
315,
7783,
282,
1059,
626,
911,
506,
10311,
1901,
282,
13156,
436,
1779,
376,
7427,
911,
506,
6326,
370,
1336,
652,
4020,
83,
314,
2213,
1159,
3659,
1779,
1329,
6617,
687,
314,
3602,
13,
2786,
3421,
14,
1779,
710,
1454,
876,
13,
21763,
365,
626,
314,
8135,
315,
1314,
314,
4637,
365,
1779,
308,
20816,
1077,
506,
22141,
543,
665,
22690,
10827,
1779,
20227,
12,
376,
2893,
5594,
506,
465,
11924,
26,
1598,
437,
7308,
2801,
11265,
5547,
13,
28,
22690,
24860,
6977,
1779,
961,
3955,
2040,
298,
9791,
20238,
2,
315,
314,
2569,
3659,
1329,
370,
506,
1779,
17319,
9096,
465,
314,
4637,
26,
1598,
437,
7308,
13,
11265,
13,
9791,
20238,
13,
9300,
13,
4587,
339,
768,
1107,
26,
334,
875,
9,
446,
2701,
1059,
14,
272,
408,
272,
925,
2372,
314,
3659,
1329,
334,
305,
2288,
519,
78,
446,
308,
21342,
21866,
436,
314,
2213,
730,
26,
272,
2288,
984,
889,
12,
519,
78,
272,
13265,
275,
1824,
459,
6356,
418,
339,
21937,
272,
925,
2372,
314,
2633,
687,
314,
769,
26,
339,
21937,
272,
925,
2372,
314,
536,
402,
314,
4637,
570,
26,
272,
221,
14776,
272,
862,
26,
267,
925,
982,
652,
965,
2757,
2741,
12,
664,
314,
536,
402,
314,
570,
315,
1314,
314,
267,
925,
4637,
365,
5489,
26,
267,
4637,
63,
493,
275,
2633,
905,
3533,
63,
493,
63,
1045,
68,
937,
272,
871,
4067,
26,
267,
925,
3091,
574,
1627,
367,
314,
4637,
570,
26,
267,
4637,
63,
493,
275,
488,
272,
587,
26,
267,
340,
4637,
63,
493,
365,
440,
488,
26,
288,
4637,
63,
493,
275,
620,
8,
3710,
63,
493,
9,
288,
4637,
63,
493,
275,
747,
14,
515,
14,
4846,
8,
3710,
63,
493,
680,
1913,
342,
288,
340,
4637,
63,
493,
508,
10812,
355,
4637,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
srvg/ansible
|
test/lib/ansible_test/_internal/docker_util.py
|
6
|
13345
|
"""Functions for accessing docker via the docker cli."""
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import json
import os
import time
from . import types as t
from .io import (
open_binary_file,
read_text_file,
)
from .util import (
ApplicationError,
common_environment,
display,
find_executable,
SubprocessError,
)
from .http import (
urlparse,
)
from .util_common import (
run_command,
)
from .config import (
EnvironmentConfig,
)
BUFFER_SIZE = 256 * 256
def docker_available():
"""
:rtype: bool
"""
return find_executable('docker', required=False)
def get_docker_hostname(): # type: () -> str
"""Return the hostname of the Docker service."""
try:
return get_docker_hostname.hostname
except AttributeError:
pass
docker_host = os.environ.get('DOCKER_HOST')
if docker_host and docker_host.startswith('tcp://'):
try:
hostname = urlparse(docker_host)[1].split(':')[0]
display.info('Detected Docker host: %s' % hostname, verbosity=1)
except ValueError:
hostname = 'localhost'
display.warning('Could not parse DOCKER_HOST environment variable "%s", falling back to localhost.' % docker_host)
else:
hostname = 'localhost'
display.info('Assuming Docker is available on localhost.', verbosity=1)
get_docker_hostname.hostname = hostname
return hostname
def get_docker_container_id():
"""
:rtype: str | None
"""
try:
return get_docker_container_id.container_id
except AttributeError:
pass
path = '/proc/self/cpuset'
container_id = None
if os.path.exists(path):
# File content varies based on the environment:
# No Container: /
# Docker: /docker/c86f3732b5ba3d28bb83b6e14af767ab96abbc52de31313dcb1176a62d91a507
# Azure Pipelines (Docker): /azpl_job/0f2edfed602dd6ec9f2e42c867f4d5ee640ebf4c058e6d3196d4393bb8fd0891
# Podman: /../../../../../..
contents = read_text_file(path)
cgroup_path, cgroup_name = os.path.split(contents.strip())
if cgroup_path in ('/docker', '/azpl_job'):
container_id = cgroup_name
get_docker_container_id.container_id = container_id
if container_id:
display.info('Detected execution in Docker container: %s' % container_id, verbosity=1)
return container_id
def get_docker_container_ip(args, container_id):
"""
:type args: EnvironmentConfig
:type container_id: str
:rtype: str
"""
results = docker_inspect(args, container_id)
network_settings = results[0]['NetworkSettings']
networks = network_settings.get('Networks')
if networks:
network_name = get_docker_preferred_network_name(args)
ipaddress = networks[network_name]['IPAddress']
else:
# podman doesn't provide Networks, fall back to using IPAddress
ipaddress = network_settings['IPAddress']
if not ipaddress:
raise ApplicationError('Cannot retrieve IP address for container: %s' % container_id)
return ipaddress
def get_docker_network_name(args, container_id): # type: (EnvironmentConfig, str) -> str
"""
Return the network name of the specified container.
Raises an exception if zero or more than one network is found.
"""
networks = get_docker_networks(args, container_id)
if not networks:
raise ApplicationError('No network found for Docker container: %s.' % container_id)
if len(networks) > 1:
raise ApplicationError('Found multiple networks for Docker container %s instead of only one: %s' % (container_id, ', '.join(networks)))
return networks[0]
def get_docker_preferred_network_name(args): # type: (EnvironmentConfig) -> str
"""
Return the preferred network name for use with Docker. The selection logic is:
- the network selected by the user with `--docker-network`
- the network of the currently running docker container (if any)
- the default docker network (returns None)
"""
network = None
if args.docker_network:
network = args.docker_network
else:
current_container_id = get_docker_container_id()
if current_container_id:
# Make sure any additional containers we launch use the same network as the current container we're running in.
# This is needed when ansible-test is running in a container that is not connected to Docker's default network.
network = get_docker_network_name(args, current_container_id)
return network
def is_docker_user_defined_network(network): # type: (str) -> bool
"""Return True if the network being used is a user-defined network."""
return network and network != 'bridge'
def get_docker_networks(args, container_id):
"""
:param args: EnvironmentConfig
:param container_id: str
:rtype: list[str]
"""
results = docker_inspect(args, container_id)
# podman doesn't return Networks- just silently return None if it's missing...
networks = results[0]['NetworkSettings'].get('Networks')
if networks is None:
return None
return sorted(networks)
def docker_pull(args, image):
"""
:type args: EnvironmentConfig
:type image: str
"""
if ('@' in image or ':' in image) and docker_images(args, image):
display.info('Skipping docker pull of existing image with tag or digest: %s' % image, verbosity=2)
return
if not args.docker_pull:
display.warning('Skipping docker pull for "%s". Image may be out-of-date.' % image)
return
for _iteration in range(1, 10):
try:
docker_command(args, ['pull', image])
return
except SubprocessError:
display.warning('Failed to pull docker image "%s". Waiting a few seconds before trying again.' % image)
time.sleep(3)
raise ApplicationError('Failed to pull docker image "%s".' % image)
def docker_put(args, container_id, src, dst):
"""
:type args: EnvironmentConfig
:type container_id: str
:type src: str
:type dst: str
"""
# avoid 'docker cp' due to a bug which causes 'docker rm' to fail
with open_binary_file(src) as src_fd:
docker_exec(args, container_id, ['dd', 'of=%s' % dst, 'bs=%s' % BUFFER_SIZE],
options=['-i'], stdin=src_fd, capture=True)
def docker_get(args, container_id, src, dst):
"""
:type args: EnvironmentConfig
:type container_id: str
:type src: str
:type dst: str
"""
# avoid 'docker cp' due to a bug which causes 'docker rm' to fail
with open_binary_file(dst, 'wb') as dst_fd:
docker_exec(args, container_id, ['dd', 'if=%s' % src, 'bs=%s' % BUFFER_SIZE],
options=['-i'], stdout=dst_fd, capture=True)
def docker_run(args, image, options, cmd=None, create_only=False):
"""
:type args: EnvironmentConfig
:type image: str
:type options: list[str] | None
:type cmd: list[str] | None
:type create_only[bool] | False
:rtype: str | None, str | None
"""
if not options:
options = []
if not cmd:
cmd = []
if create_only:
command = 'create'
else:
command = 'run'
network = get_docker_preferred_network_name(args)
if is_docker_user_defined_network(network):
# Only when the network is not the default bridge network.
# Using this with the default bridge network results in an error when using --link: links are only supported for user-defined networks
options.extend(['--network', network])
for _iteration in range(1, 3):
try:
return docker_command(args, [command] + options + [image] + cmd, capture=True)
except SubprocessError as ex:
display.error(ex)
display.warning('Failed to run docker image "%s". Waiting a few seconds before trying again.' % image)
time.sleep(3)
raise ApplicationError('Failed to run docker image "%s".' % image)
def docker_start(args, container_id, options): # type: (EnvironmentConfig, str, t.List[str]) -> (t.Optional[str], t.Optional[str])
"""
Start a docker container by name or ID
"""
if not options:
options = []
for _iteration in range(1, 3):
try:
return docker_command(args, ['start'] + options + [container_id], capture=True)
except SubprocessError as ex:
display.error(ex)
display.warning('Failed to start docker container "%s". Waiting a few seconds before trying again.' % container_id)
time.sleep(3)
raise ApplicationError('Failed to run docker container "%s".' % container_id)
def docker_images(args, image):
"""
:param args: CommonConfig
:param image: str
:rtype: list[dict[str, any]]
"""
try:
stdout, _dummy = docker_command(args, ['images', image, '--format', '{{json .}}'], capture=True, always=True)
except SubprocessError as ex:
if 'no such image' in ex.stderr:
return [] # podman does not handle this gracefully, exits 125
if 'function "json" not defined' in ex.stderr:
# podman > 2 && < 2.2.0 breaks with --format {{json .}}, and requires --format json
# So we try this as a fallback. If it fails again, we just raise the exception and bail.
stdout, _dummy = docker_command(args, ['images', image, '--format', 'json'], capture=True, always=True)
else:
raise ex
if stdout.startswith('['):
# modern podman outputs a pretty-printed json list. Just load the whole thing.
return json.loads(stdout)
# docker outputs one json object per line (jsonl)
return [json.loads(line) for line in stdout.splitlines()]
def docker_rm(args, container_id):
"""
:type args: EnvironmentConfig
:type container_id: str
"""
try:
docker_command(args, ['rm', '-f', container_id], capture=True)
except SubprocessError as ex:
if 'no such container' in ex.stderr:
pass # podman does not handle this gracefully, exits 1
else:
raise ex
def docker_inspect(args, container_id):
"""
:type args: EnvironmentConfig
:type container_id: str
:rtype: list[dict]
"""
if args.explain:
return []
try:
stdout = docker_command(args, ['inspect', container_id], capture=True)[0]
return json.loads(stdout)
except SubprocessError as ex:
if 'no such image' in ex.stderr:
return [] # podman does not handle this gracefully, exits 125
try:
return json.loads(ex.stdout)
except Exception:
raise ex
def docker_network_disconnect(args, container_id, network):
"""
:param args: EnvironmentConfig
:param container_id: str
:param network: str
"""
docker_command(args, ['network', 'disconnect', network, container_id], capture=True)
def docker_network_inspect(args, network):
"""
:type args: EnvironmentConfig
:type network: str
:rtype: list[dict]
"""
if args.explain:
return []
try:
stdout = docker_command(args, ['network', 'inspect', network], capture=True)[0]
return json.loads(stdout)
except SubprocessError as ex:
try:
return json.loads(ex.stdout)
except Exception:
raise ex
def docker_exec(args, container_id, cmd, options=None, capture=False, stdin=None, stdout=None, data=None):
"""
:type args: EnvironmentConfig
:type container_id: str
:type cmd: list[str]
:type options: list[str] | None
:type capture: bool
:type stdin: BinaryIO | None
:type stdout: BinaryIO | None
:type data: str | None
:rtype: str | None, str | None
"""
if not options:
options = []
if data:
options.append('-i')
return docker_command(args, ['exec'] + options + [container_id] + cmd, capture=capture, stdin=stdin, stdout=stdout, data=data)
def docker_info(args):
"""
:param args: CommonConfig
:rtype: dict[str, any]
"""
stdout, _dummy = docker_command(args, ['info', '--format', '{{json .}}'], capture=True, always=True)
return json.loads(stdout)
def docker_version(args):
"""
:param args: CommonConfig
:rtype: dict[str, any]
"""
stdout, _dummy = docker_command(args, ['version', '--format', '{{json .}}'], capture=True, always=True)
return json.loads(stdout)
def docker_command(args, cmd, capture=False, stdin=None, stdout=None, always=False, data=None):
"""
:type args: CommonConfig
:type cmd: list[str]
:type capture: bool
:type stdin: file | None
:type stdout: file | None
:type always: bool
:type data: str | None
:rtype: str | None, str | None
"""
env = docker_environment()
return run_command(args, ['docker'] + cmd, env=env, capture=capture, stdin=stdin, stdout=stdout, always=always, data=data)
def docker_environment():
"""
:rtype: dict[str, str]
"""
env = common_environment()
env.update(dict((key, os.environ[key]) for key in os.environ if key.startswith('DOCKER_')))
return env
|
gpl-3.0
|
[
624,
13967,
367,
18549,
12424,
4799,
314,
12424,
5053,
1041,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
2022,
199,
646,
747,
199,
646,
900,
199,
199,
504,
1275,
492,
2943,
465,
307,
199,
199,
504,
1275,
2308,
492,
334,
272,
1551,
63,
3008,
63,
493,
12,
272,
1586,
63,
505,
63,
493,
12,
199,
9,
199,
199,
504,
1275,
1974,
492,
334,
272,
13515,
547,
12,
272,
2863,
63,
5418,
12,
272,
2929,
12,
272,
2342,
63,
5904,
12,
272,
4804,
1412,
547,
12,
199,
9,
199,
199,
504,
1275,
1014,
492,
334,
272,
7097,
12,
199,
9,
199,
199,
504,
1275,
1974,
63,
2330,
492,
334,
272,
1255,
63,
1531,
12,
199,
9,
199,
199,
504,
1275,
888,
492,
334,
272,
9711,
2028,
12,
199,
9,
199,
199,
10960,
63,
4305,
275,
7633,
627,
7633,
421,
199,
318,
12424,
63,
4561,
837,
272,
408,
272,
520,
4500,
26,
2155,
272,
408,
272,
372,
2342,
63,
5904,
360,
9991,
297,
1415,
29,
797,
9,
421,
199,
318,
664,
63,
9991,
63,
4269,
837,
221,
327,
730,
26,
6248,
1035,
620,
272,
408,
1767,
314,
6246,
402,
314,
22067,
2435,
1041,
272,
862,
26,
267,
372,
664,
63,
9991,
63,
4269,
14,
4269,
272,
871,
4281,
26,
267,
986,
339,
12424,
63,
1102,
275,
747,
14,
2314,
14,
362,
360,
29953,
63,
5449,
358,
339,
340,
12424,
63,
1102,
436,
12424,
63,
1102,
14,
2460,
360,
8815,
921,
735,
267,
862,
26,
288,
6246,
275,
7097,
8,
9991,
63,
1102,
2788,
17,
1055,
1294,
24050,
16,
61,
288,
2929,
14,
815,
360,
872,
4530,
22067,
1591,
26,
450,
83,
7,
450,
6246,
12,
8661,
29,
17,
9,
267,
871,
1722,
26,
288,
6246,
275,
283,
5967,
7,
288,
2929,
14,
3764,
360,
6531,
440,
2198,
3506,
2504,
540,
63,
5449,
3734,
1750,
2071,
83,
401,
32039,
1771,
370,
11667,
3530,
450,
12424,
63,
1102,
9,
272,
587,
26,
267,
6246,
275,
283,
5967,
7,
267,
2929,
14,
815,
360,
9824,
12848,
22067,
365,
2808,
641,
11667,
3130,
8661,
29,
17,
9,
339,
664,
63,
9991,
63,
4269,
14,
4269,
275,
6246,
339,
372,
6246,
421,
199,
318,
664,
63,
9991,
63,
3600,
63,
344,
837,
272,
408,
272,
520,
4500,
26,
620,
1204,
488,
272,
408,
272,
862,
26,
267,
372,
664,
63,
9991,
63,
3600,
63,
344,
14,
3600,
63,
344,
272,
871,
4281,
26,
267,
986,
339,
931,
275,
1994,
4687,
15,
277,
15,
3541,
409,
7,
272,
3970,
63,
344,
275,
488,
339,
340,
747,
14,
515,
14,
2444,
8,
515,
304,
267,
327,
3814,
1564,
373,
3433,
4079,
641,
314,
3734,
26,
267,
327,
257,
3091,
15395,
26,
1182,
267,
327,
257,
22067,
26,
1182,
9991,
15,
67,
1184,
70,
1401,
708,
66,
21,
2470,
19,
68,
1651,
2501,
2658,
66,
22,
69,
1079,
2756,
14787,
371,
2534,
371,
3776,
2528,
271,
19455,
969,
68,
2894,
31989,
65,
2789,
68,
3328,
65,
13583,
267,
327,
257,
15474,
16850,
1278,
334,
31463,
304,
1182,
4651,
1168,
63,
2423,
15,
16,
70,
18,
379,
15800,
28384,
617,
22,
825,
25,
70,
18,
69,
2260,
67,
14927,
70,
20,
68,
21,
1024,
12021,
2871,
70,
20,
67,
18009,
69,
22,
68,
19,
10800,
68,
20,
15490,
2501,
24,
2592,
16,
15601,
267,
327,
257,
510,
364,
1237,
26,
1182,
9707,
29866,
703,
267,
4072,
275,
1586,
63,
505,
63,
493,
8,
515,
9,
398,
286,
923,
63,
515,
12,
286,
923,
63,
354,
275,
747,
14,
515,
14,
1294,
8,
4407,
14,
1913,
1012,
398,
340,
286,
923,
63,
515,
315,
14606,
9991,
297,
1994,
4651,
1168,
63,
2423,
735,
288,
3970,
63,
344,
275,
286,
923,
63,
354,
339,
664,
63,
9991,
63,
3600,
63,
344,
14,
3600,
63,
344,
275,
3970,
63,
344,
339,
340,
3970,
63,
344,
26,
267,
2929,
14,
815,
360,
872,
4530,
6451,
315,
22067,
3970,
26,
450,
83,
7,
450,
3970,
63,
344,
12,
8661,
29,
17,
9,
339,
372,
3970,
63,
344,
421,
199,
318,
664,
63,
9991,
63,
3600,
63,
711,
8,
589,
12,
3970,
63,
344,
304,
272,
408,
272,
520,
466,
1249,
26,
9711,
2028,
272,
520,
466,
3970,
63,
344,
26,
620,
272,
520,
4500,
26,
620,
272,
408,
272,
2058,
275,
12424,
63,
10955,
8,
589,
12,
3970,
63,
344,
9,
272,
2784,
63,
1751,
275,
2058,
59,
16,
2733,
4491,
5268,
418,
272,
11759,
275,
2784,
63,
1751,
14,
362,
360,
30551,
358,
339,
340,
11759,
26,
267,
2784,
63,
354,
275,
664,
63,
9991,
63,
17477,
63,
1200,
63,
354,
8,
589,
9,
267,
20617,
275,
11759,
59,
1200,
63,
354,
2733,
14955,
418,
272,
587,
26,
267,
327,
15329,
1237,
3181,
1133,
5647,
17138,
12,
11264,
1771,
370,
1808,
3531,
1476,
267,
20617,
275,
2784,
63,
1751,
459,
14955,
418,
339,
340,
440,
20617,
26,
267,
746,
13515,
547,
360,
6612,
8044,
3531,
2287,
367,
3970,
26,
450,
83,
7,
450,
3970,
63,
344,
9,
339,
372,
20617,
421,
199,
318,
664,
63,
9991,
63,
1200,
63,
354,
8,
589,
12,
3970,
63,
344,
304,
221,
327,
730,
26,
334,
8263,
2028,
12,
620,
9,
1035,
620,
272,
408,
272,
1432,
314,
2784,
536,
402,
314,
2013,
3970,
14,
272,
6218,
376,
1919,
340,
4697,
503,
1655,
2419,
1373,
2784,
365,
1911,
14,
272,
408,
272,
11759,
275,
664,
63,
9991,
63,
7642,
8,
589,
12,
3970,
63,
344,
9,
339,
340,
440,
11759,
26,
267,
746,
13515,
547,
360,
1944,
2784,
1911,
367,
22067,
3970,
26,
450,
83,
3530,
450,
3970,
63,
344,
9,
339,
340,
822,
8,
7642,
9,
690,
413,
26,
267,
746,
13515,
547,
360,
3601,
3663,
11759,
367,
22067,
3970,
450,
83,
3140,
402,
1454,
1373,
26,
450,
83,
7,
450,
334,
3600,
63,
344,
12,
1656,
1987,
904,
8,
7642,
1724,
339,
372,
11759,
59,
16,
61,
421,
199,
318,
664,
63,
9991,
63,
17477,
63,
1200,
63,
354,
8,
589,
304,
221,
327,
730,
26,
334,
8263,
2028,
9,
1035,
620,
272,
408,
272,
1432,
314,
14388,
2784,
536,
367,
675,
543
] |
[
13967,
367,
18549,
12424,
4799,
314,
12424,
5053,
1041,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
2022,
199,
646,
747,
199,
646,
900,
199,
199,
504,
1275,
492,
2943,
465,
307,
199,
199,
504,
1275,
2308,
492,
334,
272,
1551,
63,
3008,
63,
493,
12,
272,
1586,
63,
505,
63,
493,
12,
199,
9,
199,
199,
504,
1275,
1974,
492,
334,
272,
13515,
547,
12,
272,
2863,
63,
5418,
12,
272,
2929,
12,
272,
2342,
63,
5904,
12,
272,
4804,
1412,
547,
12,
199,
9,
199,
199,
504,
1275,
1014,
492,
334,
272,
7097,
12,
199,
9,
199,
199,
504,
1275,
1974,
63,
2330,
492,
334,
272,
1255,
63,
1531,
12,
199,
9,
199,
199,
504,
1275,
888,
492,
334,
272,
9711,
2028,
12,
199,
9,
199,
199,
10960,
63,
4305,
275,
7633,
627,
7633,
421,
199,
318,
12424,
63,
4561,
837,
272,
408,
272,
520,
4500,
26,
2155,
272,
408,
272,
372,
2342,
63,
5904,
360,
9991,
297,
1415,
29,
797,
9,
421,
199,
318,
664,
63,
9991,
63,
4269,
837,
221,
327,
730,
26,
6248,
1035,
620,
272,
408,
1767,
314,
6246,
402,
314,
22067,
2435,
1041,
272,
862,
26,
267,
372,
664,
63,
9991,
63,
4269,
14,
4269,
272,
871,
4281,
26,
267,
986,
339,
12424,
63,
1102,
275,
747,
14,
2314,
14,
362,
360,
29953,
63,
5449,
358,
339,
340,
12424,
63,
1102,
436,
12424,
63,
1102,
14,
2460,
360,
8815,
921,
735,
267,
862,
26,
288,
6246,
275,
7097,
8,
9991,
63,
1102,
2788,
17,
1055,
1294,
24050,
16,
61,
288,
2929,
14,
815,
360,
872,
4530,
22067,
1591,
26,
450,
83,
7,
450,
6246,
12,
8661,
29,
17,
9,
267,
871,
1722,
26,
288,
6246,
275,
283,
5967,
7,
288,
2929,
14,
3764,
360,
6531,
440,
2198,
3506,
2504,
540,
63,
5449,
3734,
1750,
2071,
83,
401,
32039,
1771,
370,
11667,
3530,
450,
12424,
63,
1102,
9,
272,
587,
26,
267,
6246,
275,
283,
5967,
7,
267,
2929,
14,
815,
360,
9824,
12848,
22067,
365,
2808,
641,
11667,
3130,
8661,
29,
17,
9,
339,
664,
63,
9991,
63,
4269,
14,
4269,
275,
6246,
339,
372,
6246,
421,
199,
318,
664,
63,
9991,
63,
3600,
63,
344,
837,
272,
408,
272,
520,
4500,
26,
620,
1204,
488,
272,
408,
272,
862,
26,
267,
372,
664,
63,
9991,
63,
3600,
63,
344,
14,
3600,
63,
344,
272,
871,
4281,
26,
267,
986,
339,
931,
275,
1994,
4687,
15,
277,
15,
3541,
409,
7,
272,
3970,
63,
344,
275,
488,
339,
340,
747,
14,
515,
14,
2444,
8,
515,
304,
267,
327,
3814,
1564,
373,
3433,
4079,
641,
314,
3734,
26,
267,
327,
257,
3091,
15395,
26,
1182,
267,
327,
257,
22067,
26,
1182,
9991,
15,
67,
1184,
70,
1401,
708,
66,
21,
2470,
19,
68,
1651,
2501,
2658,
66,
22,
69,
1079,
2756,
14787,
371,
2534,
371,
3776,
2528,
271,
19455,
969,
68,
2894,
31989,
65,
2789,
68,
3328,
65,
13583,
267,
327,
257,
15474,
16850,
1278,
334,
31463,
304,
1182,
4651,
1168,
63,
2423,
15,
16,
70,
18,
379,
15800,
28384,
617,
22,
825,
25,
70,
18,
69,
2260,
67,
14927,
70,
20,
68,
21,
1024,
12021,
2871,
70,
20,
67,
18009,
69,
22,
68,
19,
10800,
68,
20,
15490,
2501,
24,
2592,
16,
15601,
267,
327,
257,
510,
364,
1237,
26,
1182,
9707,
29866,
703,
267,
4072,
275,
1586,
63,
505,
63,
493,
8,
515,
9,
398,
286,
923,
63,
515,
12,
286,
923,
63,
354,
275,
747,
14,
515,
14,
1294,
8,
4407,
14,
1913,
1012,
398,
340,
286,
923,
63,
515,
315,
14606,
9991,
297,
1994,
4651,
1168,
63,
2423,
735,
288,
3970,
63,
344,
275,
286,
923,
63,
354,
339,
664,
63,
9991,
63,
3600,
63,
344,
14,
3600,
63,
344,
275,
3970,
63,
344,
339,
340,
3970,
63,
344,
26,
267,
2929,
14,
815,
360,
872,
4530,
6451,
315,
22067,
3970,
26,
450,
83,
7,
450,
3970,
63,
344,
12,
8661,
29,
17,
9,
339,
372,
3970,
63,
344,
421,
199,
318,
664,
63,
9991,
63,
3600,
63,
711,
8,
589,
12,
3970,
63,
344,
304,
272,
408,
272,
520,
466,
1249,
26,
9711,
2028,
272,
520,
466,
3970,
63,
344,
26,
620,
272,
520,
4500,
26,
620,
272,
408,
272,
2058,
275,
12424,
63,
10955,
8,
589,
12,
3970,
63,
344,
9,
272,
2784,
63,
1751,
275,
2058,
59,
16,
2733,
4491,
5268,
418,
272,
11759,
275,
2784,
63,
1751,
14,
362,
360,
30551,
358,
339,
340,
11759,
26,
267,
2784,
63,
354,
275,
664,
63,
9991,
63,
17477,
63,
1200,
63,
354,
8,
589,
9,
267,
20617,
275,
11759,
59,
1200,
63,
354,
2733,
14955,
418,
272,
587,
26,
267,
327,
15329,
1237,
3181,
1133,
5647,
17138,
12,
11264,
1771,
370,
1808,
3531,
1476,
267,
20617,
275,
2784,
63,
1751,
459,
14955,
418,
339,
340,
440,
20617,
26,
267,
746,
13515,
547,
360,
6612,
8044,
3531,
2287,
367,
3970,
26,
450,
83,
7,
450,
3970,
63,
344,
9,
339,
372,
20617,
421,
199,
318,
664,
63,
9991,
63,
1200,
63,
354,
8,
589,
12,
3970,
63,
344,
304,
221,
327,
730,
26,
334,
8263,
2028,
12,
620,
9,
1035,
620,
272,
408,
272,
1432,
314,
2784,
536,
402,
314,
2013,
3970,
14,
272,
6218,
376,
1919,
340,
4697,
503,
1655,
2419,
1373,
2784,
365,
1911,
14,
272,
408,
272,
11759,
275,
664,
63,
9991,
63,
7642,
8,
589,
12,
3970,
63,
344,
9,
339,
340,
440,
11759,
26,
267,
746,
13515,
547,
360,
1944,
2784,
1911,
367,
22067,
3970,
26,
450,
83,
3530,
450,
3970,
63,
344,
9,
339,
340,
822,
8,
7642,
9,
690,
413,
26,
267,
746,
13515,
547,
360,
3601,
3663,
11759,
367,
22067,
3970,
450,
83,
3140,
402,
1454,
1373,
26,
450,
83,
7,
450,
334,
3600,
63,
344,
12,
1656,
1987,
904,
8,
7642,
1724,
339,
372,
11759,
59,
16,
61,
421,
199,
318,
664,
63,
9991,
63,
17477,
63,
1200,
63,
354,
8,
589,
304,
221,
327,
730,
26,
334,
8263,
2028,
9,
1035,
620,
272,
408,
272,
1432,
314,
14388,
2784,
536,
367,
675,
543,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ckuethe/gnuradio
|
gr-uhd/examples/python/usrp_nbfm_rcv.py
|
58
|
14409
|
#!/usr/bin/env python
#
# Copyright 2005,2007,2011,2012 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, audio, uhd
from gnuradio import blocks
from gnuradio import filter
from gnuradio import analog
from gnuradio.eng_option import eng_option
from gnuradio.wxgui import slider, powermate
from gnuradio.wxgui import stdgui2, fftsink2, form
from optparse import OptionParser
import sys
import math
import wx
#////////////////////////////////////////////////////////////////////////
# Control Stuff
#////////////////////////////////////////////////////////////////////////
class my_top_block (stdgui2.std_top_block):
def __init__(self,frame,panel,vbox,argv):
stdgui2.std_top_block.__init__ (self,frame,panel,vbox,argv)
parser=OptionParser(option_class=eng_option)
parser.add_option("-a", "--args", type="string", default="",
help="UHD device address args [default=%default]")
parser.add_option("", "--spec", type="string", default=None,
help="Subdevice of UHD device where appropriate")
parser.add_option("-A", "--antenna", type="string", default=None,
help="select Rx Antenna where appropriate")
parser.add_option("-f", "--freq", type="eng_float", default=146.585e6,
help="set frequency to FREQ", metavar="FREQ")
parser.add_option("-g", "--gain", type="eng_float", default=None,
help="set gain in dB (default is midpoint)")
parser.add_option("-V", "--volume", type="eng_float", default=None,
help="set volume (default is midpoint)")
parser.add_option("-O", "--audio-output", type="string", default="default",
help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp")
parser.add_option("-N", "--no-gui", action="store_true", default=False)
(options, args) = parser.parse_args()
if len(args) != 0:
parser.print_help()
sys.exit(1)
if options.freq < 1e6:
options.freq *= 1e6
self.frame = frame
self.panel = panel
self.state = "FREQ"
self.freq = 0
self.freq_step = 25e3
self.rxpath = receive_path(options.args, options.spec, options.antenna,
options.gain, options.audio_output)
self.connect(self.rxpath)
self._build_gui(vbox, options.no_gui)
# set initial values
if options.volume is not None:
self.set_volume(options.volume)
if not(self.set_freq(options.freq)):
self._set_status_msg("Failed to set initial frequency")
self.set_gain(self.rxpath.gain) # update gui
self.set_volume(self.rxpath.volume) # update gui
self.set_squelch(self.rxpath.threshold()) # update gui
def _set_status_msg(self, msg, which=0):
self.frame.GetStatusBar().SetStatusText(msg, which)
def _build_gui(self, vbox, no_gui):
def _form_set_freq(kv):
return self.set_freq(kv['freq'])
self.src_fft = None
if 0 and not(no_gui):
self.src_fft = fftsink2.fft_sink_c(self.panel,
title="Data from USRP",
fft_size=512,
sample_rate=self.rxpath.if_rate,
ref_scale=32768.0,
ref_level=0,
y_per_div=10,
y_divs=12)
self.connect (self.rxpath.u, self.src_fft)
vbox.Add (self.src_fft.win, 4, wx.EXPAND)
if 1 and not(no_gui):
rx_fft = fftsink2.fft_sink_c(self.panel,
title="Post s/w Resampling",
fft_size=512,
sample_rate=self.rxpath.quad_rate,
ref_level=80,
y_per_div=20)
self.connect (self.rxpath.resamp, rx_fft)
vbox.Add (rx_fft.win, 4, wx.EXPAND)
if 1 and not(no_gui):
post_deemph_fft = fftsink2.fft_sink_f(self.panel,
title="Post Deemph",
fft_size=512,
sample_rate=self.rxpath.audio_rate,
y_per_div=10,
ref_level=-40)
self.connect (self.rxpath.fmrx.deemph, post_deemph_fft)
vbox.Add (post_deemph_fft.win, 4, wx.EXPAND)
if 0:
post_filt_fft = fftsink2.fft_sink_f(self.panel,
title="Post Filter",
fft_size=512,
sample_rate=audio_rate,
y_per_div=10,
ref_level=-40)
self.connect (self.guts.audio_filter, post_filt)
vbox.Add (fft_win4, 4, wx.EXPAND)
# control area form at bottom
self.myform = myform = form.form()
hbox = wx.BoxSizer(wx.HORIZONTAL)
hbox.Add((5,0), 0)
myform['freq'] = form.float_field(
parent=self.panel, sizer=hbox, label="Freq", weight=1,
callback=myform.check_input_and_call(_form_set_freq,
self._set_status_msg))
#hbox.Add((5,0), 0)
#myform['freq_slider'] = \
# form.quantized_slider_field(parent=self.panel, sizer=hbox, weight=3,
# range=(87.9e6, 108.1e6, 0.1e6),
# callback=self.set_freq)
hbox.Add((5,0), 0)
vbox.Add(hbox, 0, wx.EXPAND)
hbox = wx.BoxSizer(wx.HORIZONTAL)
hbox.Add((5,0), 0)
myform['volume'] = \
form.quantized_slider_field(parent=self.panel, sizer=hbox, label="Volume",
weight=3, range=self.volume_range(),
callback=self.set_volume)
hbox.Add((5,0), 0)
myform['squelch'] = \
form.quantized_slider_field(parent=self.panel, sizer=hbox, label="Squelch",
weight=3, range=self.rxpath.squelch_range(),
callback=self.set_squelch)
g = self.rxpath.u.get_gain_range()
hbox.Add((5,0), 0)
myform['gain'] = \
form.quantized_slider_field(parent=self.panel, sizer=hbox, label="Gain",
weight=3, range=(g.start(), g.stop(), g.step()),
callback=self.set_gain)
hbox.Add((5,0), 0)
vbox.Add(hbox, 0, wx.EXPAND)
try:
self.knob = powermate.powermate(self.frame)
self.rot = 0
powermate.EVT_POWERMATE_ROTATE (self.frame, self.on_rotate)
powermate.EVT_POWERMATE_BUTTON (self.frame, self.on_button)
except:
print "FYI: No Powermate or Contour Knob found"
def on_rotate (self, event):
self.rot += event.delta
if (self.state == "FREQ"):
if self.rot >= 3:
self.set_freq(self.freq + self.freq_step)
self.rot -= 3
elif self.rot <=-3:
self.set_freq(self.freq - self.freq_step)
self.rot += 3
else:
step = self.volume_range()[2]
if self.rot >= 3:
self.set_volume(self.rxpath.volume + step)
self.rot -= 3
elif self.rot <=-3:
self.set_volume(self.rxpath.volume - step)
self.rot += 3
def on_button (self, event):
if event.value == 0: # button up
return
self.rot = 0
if self.state == "FREQ":
self.state = "VOL"
else:
self.state = "FREQ"
self.update_status_bar ()
def set_squelch(self, threshold_in_db):
self.rxpath.set_squelch(threshold_in_db)
self.myform['squelch'].set_value(self.rxpath.threshold())
def set_volume (self, vol):
self.rxpath.set_volume(vol)
self.myform['volume'].set_value(self.rxpath.volume)
self.update_status_bar ()
def set_freq(self, target_freq):
r = self.rxpath.set_freq(target_freq)
if r:
self.freq = target_freq
self.myform['freq'].set_value(target_freq) # update displayed value
#self.myform['freq_slider'].set_value(target_freq) # update displayed value
self.update_status_bar()
self._set_status_msg("OK", 0)
return True
self._set_status_msg("Failed", 0)
return False
def set_gain(self, gain):
self.myform['gain'].set_value(gain) # update displayed value
self.rxpath.set_gain(gain)
def update_status_bar (self):
msg = "Volume:%r Setting:%s" % (self.rxpath.volume, self.state)
self._set_status_msg(msg, 1)
if self.src_fft:
self.src_fft.set_baseband_freq(self.freq)
def volume_range(self):
return (-20.0, 0.0, 0.5)
#////////////////////////////////////////////////////////////////////////
# Receive Path
#////////////////////////////////////////////////////////////////////////
USE_SIMPLE_SQUELCH = False
class receive_path(gr.hier_block2):
def __init__(self, args, spec, antenna, gain, audio_output):
gr.hier_block2.__init__(self, "receive_path",
gr.io_signature(0, 0, 0), # Input signature
gr.io_signature(0, 0, 0)) # Output signature
self.u = uhd.usrp_source(device_addr=args, stream_args=uhd.stream_args('fc32'))
# Set the subdevice spec
if(spec):
self.u.set_subdev_spec(spec, 0)
# Set the antenna
if(antenna):
self.u.set_antenna(antenna, 0)
self.if_rate = 256e3
self.quad_rate = 64e3
self.audio_rate = 32e3
self.u.set_samp_rate(self.if_rate)
dev_rate = self.u.get_samp_rate()
# Create filter to get actual channel we want
nfilts = 32
chan_coeffs = filter.firdes.low_pass(nfilts, # gain
nfilts*dev_rate, # sampling rate
8e3, # low pass cutoff freq
2e3, # width of trans. band
filter.firdes.WIN_HANN) # filter type
rrate = self.quad_rate / dev_rate
self.resamp = filter.pfb.arb_resampler_ccf(rrate, chan_coeffs, nfilts)
if USE_SIMPLE_SQUELCH:
self.squelch = analog.simple_squelch_cc(20)
else:
self.squelch = analog.standard_squelch(self.audio_rate)
# instantiate the guts of the single channel receiver
self.fmrx = analog.nbfm_rx(self.audio_rate, self.quad_rate)
# audio gain / mute block
self._audio_gain = blocks.multiply_const_ff(1.0)
# sound card as final sink
audio_sink = audio.sink (int(self.audio_rate), audio_output)
# now wire it all together
if USE_SIMPLE_SQUELCH:
self.connect (self.u, self.resamp, self.squelch, self.fmrx,
self._audio_gain, audio_sink)
else:
self.connect (self.u, self.resamp, self.fmrx, self.squelch,
self._audio_gain, audio_sink)
if gain is None:
# if no gain was specified, use the mid-point in dB
g = self.u.get_gain_range()
gain = float(g.start()+g.stop())/2
self.set_gain(gain)
v = self.volume_range()
self.set_volume((v[0]+v[1])/2)
s = self.squelch_range()
self.set_squelch((s[0]+s[1])/2)
def volume_range(self):
return (-20.0, 0.0, 0.5)
def set_volume (self, vol):
g = self.volume_range()
self.volume = max(g[0], min(g[1], vol))
self._update_audio_gain()
def _update_audio_gain(self):
self._audio_gain.set_k(10**(self.volume/10))
def squelch_range(self):
r = self.squelch.squelch_range()
#print "squelch_range: ", r
return r
def set_squelch(self, threshold):
#print "SQL =", threshold
self.squelch.set_threshold(threshold)
def threshold(self):
t = self.squelch.threshold()
#print "t =", t
return t
def set_freq(self, target_freq):
"""
Set the center frequency we're interested in.
Args:
target_freq: frequency in Hz
@rypte: bool
"""
r = self.u.set_center_freq(target_freq)
if r:
return True
return False
def set_gain(self, gain):
self.gain = gain
self.u.set_gain(gain)
# ////////////////////////////////////////////////////////////////////////
# Main
# ////////////////////////////////////////////////////////////////////////
if __name__ == '__main__':
app = stdgui2.stdapp (my_top_block, "USRP NBFM RX")
app.MainLoop ()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
11811,
12,
9488,
12,
8128,
12,
7409,
2868,
2290,
2752,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
1664,
13514,
199,
3,
199,
3,
1664,
13514,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
1664,
13514,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
1664,
13514,
27,
1937,
314,
570,
9685,
14,
221,
982,
440,
12,
2218,
370,
199,
3,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
199,
3,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
199,
199,
504,
24526,
492,
7192,
12,
10491,
12,
399,
7952,
199,
504,
24526,
492,
5664,
199,
504,
24526,
492,
2457,
199,
504,
24526,
492,
20439,
199,
504,
24526,
14,
7420,
63,
1422,
492,
20171,
63,
1422,
199,
504,
24526,
14,
6323,
5885,
492,
31608,
12,
7074,
17684,
199,
504,
24526,
14,
6323,
5885,
492,
2418,
5885,
18,
12,
18160,
11279,
18,
12,
1824,
199,
504,
8691,
492,
13491,
199,
646,
984,
199,
646,
3473,
199,
646,
4818,
199,
199,
8411,
1368,
199,
3,
13235,
8612,
1933,
3043,
199,
8411,
1368,
199,
199,
533,
3002,
63,
2119,
63,
1457,
334,
1516,
5885,
18,
14,
1516,
63,
2119,
63,
1457,
304,
272,
347,
636,
826,
721,
277,
12,
1943,
12,
7885,
12,
19508,
12,
3020,
304,
267,
2418,
5885,
18,
14,
1516,
63,
2119,
63,
1457,
855,
826,
363,
334,
277,
12,
1943,
12,
7885,
12,
19508,
12,
3020,
9,
398,
1798,
29,
14553,
8,
1422,
63,
533,
29,
7420,
63,
1422,
9,
267,
1798,
14,
525,
63,
1422,
6096,
65,
401,
4320,
589,
401,
730,
628,
875,
401,
849,
8772,
2079,
1720,
628,
53,
14903,
2243,
2287,
1249,
359,
885,
2458,
885,
12523,
267,
1798,
14,
525,
63,
1422,
12398,
4320,
1650,
401,
730,
628,
875,
401,
849,
29,
403,
12,
507,
8295,
1720,
628,
2610,
1782,
402,
738,
14903,
2243,
2382,
5827,
531,
267,
1798,
14,
525,
63,
1422,
6096,
33,
401,
4320,
290,
21634,
401,
730,
628,
875,
401,
849,
29,
403,
12,
2079,
1720,
628,
2416,
820,
88,
1626,
21634,
2382,
5827,
531,
267,
1798,
14,
525,
63,
1422,
6096,
70,
401,
4320,
5646,
401,
730,
628,
7420,
63,
1609,
401,
849,
29,
11432,
14,
15959,
69,
22,
12,
2079,
1720,
628,
409,
9857,
370,
481,
14583,
401,
8214,
628,
38,
14583,
531,
267,
1798,
14,
525,
63,
1422,
6096,
71,
401,
4320,
13020,
401,
730,
628,
7420,
63,
1609,
401,
849,
29,
403,
12,
2079,
1720,
628,
409,
15334,
315,
366,
34,
334,
885,
365,
10887,
1403,
6320,
267,
1798,
14,
525,
63,
1422,
6096,
54,
401,
4320,
2405,
401,
730,
628,
7420,
63,
1609,
401,
849,
29,
403,
12,
2079,
1720,
628,
409,
3301,
334,
885,
365,
10887,
1403,
6320,
267,
1798,
14,
525,
63,
1422,
6096,
47,
401,
4320,
8130,
13,
1199,
401,
730,
628,
875,
401,
849,
628,
885,
401,
2079,
1720,
628,
2352,
77,
2243,
536,
14,
221,
662,
14,
71,
2020,
12073,
26,
16,
12,
16,
503,
6296,
2363,
2869,
503,
1182,
2374,
15,
68,
681,
531,
267,
1798,
14,
525,
63,
1422,
6096,
46,
401,
4320,
889,
13,
5885,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
9,
398,
334,
1419,
12,
1249,
9,
275,
1798,
14,
1122,
63,
589,
342,
267,
340,
822,
8,
589,
9,
1137,
378,
26,
288,
1798,
14,
1361,
63,
3437,
342,
288,
984,
14,
2224,
8,
17,
9,
398,
340,
1511,
14,
5646,
665,
413,
69,
22,
26,
288,
1511,
14,
5646,
9000,
413,
69,
22,
398,
291,
14,
1943,
275,
2787,
267,
291,
14,
7885,
275,
12748,
398,
291,
14,
929,
275,
298,
38,
14583,
2,
267,
291,
14,
5646,
275,
378,
267,
291,
14,
5646,
63,
2926,
275,
5661,
69,
19,
398,
291,
14,
6872,
515,
275,
9128,
63,
515,
8,
1419,
14,
589,
12,
1511,
14,
1650,
12,
1511,
14,
290,
21634,
12,
3521,
1511,
14,
13020,
12,
1511,
14,
8130,
63,
1199,
9,
199,
198,
277,
14,
2242,
8,
277,
14,
6872,
515,
9,
398,
291,
423,
1506,
63,
5885,
8,
19508,
12,
1511,
14,
889,
63,
5885,
9,
398,
327,
663,
2536,
1338,
398,
340,
1511,
14,
2405,
365,
440,
488,
26,
288,
291,
14,
409,
63,
2405,
8,
1419,
14,
2405,
9,
398,
340,
440,
8,
277,
14,
409,
63,
5646,
8,
1419,
14,
5646,
2298,
288,
291,
423,
409,
63,
1205,
63,
1328,
480,
4276,
370,
663,
2536,
9857,
531,
398,
291,
14,
409,
63,
13020,
8,
277,
14,
6872,
515,
14,
13020,
9,
5185,
327,
1678,
11621,
267,
291,
14,
409,
63,
2405,
8,
277,
14,
6872,
515,
14,
2405,
9,
3698,
327,
1678,
11621,
267,
291,
14,
409,
63,
83,
544,
76,
335,
8,
277,
14,
6872,
515,
14,
7227,
1012,
258,
327,
1678,
11621,
2378,
347,
485,
409,
63,
1205,
63,
1328,
8,
277,
12,
1499,
12,
1314,
29,
16,
304,
267,
291,
14,
1943,
14,
1002,
3694,
5281,
1252,
1084,
3694,
1872,
8,
1328,
12,
1314,
9,
2378,
347,
485,
1506,
63,
5885,
8,
277,
12,
20163,
12,
949,
63,
5885,
304,
398,
347,
485,
964,
63,
409,
63,
5646,
8,
11475,
304,
288,
372,
291,
14,
409,
63,
5646,
8,
11475,
459,
5646,
1105,
7318,
291,
14,
2164,
63,
9996,
275,
488,
267,
340,
378,
436,
440,
8,
889,
63,
5885,
304,
288,
291,
14,
2164,
63,
9996,
275,
18160,
11279,
18,
14,
9996,
63,
11279,
63,
67,
8,
277,
14,
7885,
12,
6901,
2538,
628,
1451,
687,
738
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
11811,
12,
9488,
12,
8128,
12,
7409,
2868,
2290,
2752,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
1664,
13514,
199,
3,
199,
3,
1664,
13514,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
1664,
13514,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
1664,
13514,
27,
1937,
314,
570,
9685,
14,
221,
982,
440,
12,
2218,
370,
199,
3,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
199,
3,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
199,
199,
504,
24526,
492,
7192,
12,
10491,
12,
399,
7952,
199,
504,
24526,
492,
5664,
199,
504,
24526,
492,
2457,
199,
504,
24526,
492,
20439,
199,
504,
24526,
14,
7420,
63,
1422,
492,
20171,
63,
1422,
199,
504,
24526,
14,
6323,
5885,
492,
31608,
12,
7074,
17684,
199,
504,
24526,
14,
6323,
5885,
492,
2418,
5885,
18,
12,
18160,
11279,
18,
12,
1824,
199,
504,
8691,
492,
13491,
199,
646,
984,
199,
646,
3473,
199,
646,
4818,
199,
199,
8411,
1368,
199,
3,
13235,
8612,
1933,
3043,
199,
8411,
1368,
199,
199,
533,
3002,
63,
2119,
63,
1457,
334,
1516,
5885,
18,
14,
1516,
63,
2119,
63,
1457,
304,
272,
347,
636,
826,
721,
277,
12,
1943,
12,
7885,
12,
19508,
12,
3020,
304,
267,
2418,
5885,
18,
14,
1516,
63,
2119,
63,
1457,
855,
826,
363,
334,
277,
12,
1943,
12,
7885,
12,
19508,
12,
3020,
9,
398,
1798,
29,
14553,
8,
1422,
63,
533,
29,
7420,
63,
1422,
9,
267,
1798,
14,
525,
63,
1422,
6096,
65,
401,
4320,
589,
401,
730,
628,
875,
401,
849,
8772,
2079,
1720,
628,
53,
14903,
2243,
2287,
1249,
359,
885,
2458,
885,
12523,
267,
1798,
14,
525,
63,
1422,
12398,
4320,
1650,
401,
730,
628,
875,
401,
849,
29,
403,
12,
507,
8295,
1720,
628,
2610,
1782,
402,
738,
14903,
2243,
2382,
5827,
531,
267,
1798,
14,
525,
63,
1422,
6096,
33,
401,
4320,
290,
21634,
401,
730,
628,
875,
401,
849,
29,
403,
12,
2079,
1720,
628,
2416,
820,
88,
1626,
21634,
2382,
5827,
531,
267,
1798,
14,
525,
63,
1422,
6096,
70,
401,
4320,
5646,
401,
730,
628,
7420,
63,
1609,
401,
849,
29,
11432,
14,
15959,
69,
22,
12,
2079,
1720,
628,
409,
9857,
370,
481,
14583,
401,
8214,
628,
38,
14583,
531,
267,
1798,
14,
525,
63,
1422,
6096,
71,
401,
4320,
13020,
401,
730,
628,
7420,
63,
1609,
401,
849,
29,
403,
12,
2079,
1720,
628,
409,
15334,
315,
366,
34,
334,
885,
365,
10887,
1403,
6320,
267,
1798,
14,
525,
63,
1422,
6096,
54,
401,
4320,
2405,
401,
730,
628,
7420,
63,
1609,
401,
849,
29,
403,
12,
2079,
1720,
628,
409,
3301,
334,
885,
365,
10887,
1403,
6320,
267,
1798,
14,
525,
63,
1422,
6096,
47,
401,
4320,
8130,
13,
1199,
401,
730,
628,
875,
401,
849,
628,
885,
401,
2079,
1720,
628,
2352,
77,
2243,
536,
14,
221,
662,
14,
71,
2020,
12073,
26,
16,
12,
16,
503,
6296,
2363,
2869,
503,
1182,
2374,
15,
68,
681,
531,
267,
1798,
14,
525,
63,
1422,
6096,
46,
401,
4320,
889,
13,
5885,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
9,
398,
334,
1419,
12,
1249,
9,
275,
1798,
14,
1122,
63,
589,
342,
267,
340,
822,
8,
589,
9,
1137,
378,
26,
288,
1798,
14,
1361,
63,
3437,
342,
288,
984,
14,
2224,
8,
17,
9,
398,
340,
1511,
14,
5646,
665,
413,
69,
22,
26,
288,
1511,
14,
5646,
9000,
413,
69,
22,
398,
291,
14,
1943,
275,
2787,
267,
291,
14,
7885,
275,
12748,
398,
291,
14,
929,
275,
298,
38,
14583,
2,
267,
291,
14,
5646,
275,
378,
267,
291,
14,
5646,
63,
2926,
275,
5661,
69,
19,
398,
291,
14,
6872,
515,
275,
9128,
63,
515,
8,
1419,
14,
589,
12,
1511,
14,
1650,
12,
1511,
14,
290,
21634,
12,
3521,
1511,
14,
13020,
12,
1511,
14,
8130,
63,
1199,
9,
199,
198,
277,
14,
2242,
8,
277,
14,
6872,
515,
9,
398,
291,
423,
1506,
63,
5885,
8,
19508,
12,
1511,
14,
889,
63,
5885,
9,
398,
327,
663,
2536,
1338,
398,
340,
1511,
14,
2405,
365,
440,
488,
26,
288,
291,
14,
409,
63,
2405,
8,
1419,
14,
2405,
9,
398,
340,
440,
8,
277,
14,
409,
63,
5646,
8,
1419,
14,
5646,
2298,
288,
291,
423,
409,
63,
1205,
63,
1328,
480,
4276,
370,
663,
2536,
9857,
531,
398,
291,
14,
409,
63,
13020,
8,
277,
14,
6872,
515,
14,
13020,
9,
5185,
327,
1678,
11621,
267,
291,
14,
409,
63,
2405,
8,
277,
14,
6872,
515,
14,
2405,
9,
3698,
327,
1678,
11621,
267,
291,
14,
409,
63,
83,
544,
76,
335,
8,
277,
14,
6872,
515,
14,
7227,
1012,
258,
327,
1678,
11621,
2378,
347,
485,
409,
63,
1205,
63,
1328,
8,
277,
12,
1499,
12,
1314,
29,
16,
304,
267,
291,
14,
1943,
14,
1002,
3694,
5281,
1252,
1084,
3694,
1872,
8,
1328,
12,
1314,
9,
2378,
347,
485,
1506,
63,
5885,
8,
277,
12,
20163,
12,
949,
63,
5885,
304,
398,
347,
485,
964,
63,
409,
63,
5646,
8,
11475,
304,
288,
372,
291,
14,
409,
63,
5646,
8,
11475,
459,
5646,
1105,
7318,
291,
14,
2164,
63,
9996,
275,
488,
267,
340,
378,
436,
440,
8,
889,
63,
5885,
304,
288,
291,
14,
2164,
63,
9996,
275,
18160,
11279,
18,
14,
9996,
63,
11279,
63,
67,
8,
277,
14,
7885,
12,
6901,
2538,
628,
1451,
687,
738,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kaarthikeyapreyan/Trust-for-Youth-and-Child-Leadership
|
mentor/views.py
|
2
|
4375
|
from django.shortcuts import render
from django.http import HttpResponseRedirect
from webapp_nkana.utils.common import mongo_instance
def register_mentor_profile(request):
if request.method == 'POST':
db = mongo_instance()
keys = db.tycl.find_one({'id': 'mentor_profile_reference'})['val']
for k in keys:
if k in ('username', ):
continue
elif k == "Area_of_Expertise":
keys[k] = request.POST[k.replace(' ', '_')].lower().split(',')
keys[k] = request.POST[k.replace(' ', '_')]
keys['username'] = request.user.username
db.tycl_mentor_profile.insert(keys)
return HttpResponseRedirect('/')
return render(request, 'profile.html')
def mentor_landing(request):
db = mongo_instance()
if request.method == "POST":
pass
res = db.tycl_questionnare_new.find({ "Participation in social/community events": { "$exists": True}},
{'_id':0, "Participation in social/community events":1 })
res2 = db.tycl_questionnare_new.find({ "Child relationship with friends": { "$exists": True}},
{'_id':0, "Child relationship with friends":1 })
res1 = [int(r.values()[0]) for r in res][:12]
res12 = [int(r.values()[0]) for r in res2][:12]
res3 = db.tycl_questionnare_new.find({ "Educational performance at the school": { '$exists': True}},
{'_id':0, "Educational performance at the school":1 })
res4 = db.tycl_questionnare_new.find({ "Participation in social/community events": { '$exists': True}},
{'_id':0, "Participation in social/community events":1 })
res13 = [int(r.values()[0]) for r in res3][:12]
res14 = [int(r.values()[0]) for r in res4][:12]
db = mongo_instance()
mentor_data = db.tycl_mentor_data.find_one({"username": request.user.username})
volunteer_data = db.tycl_vol_pfle.find_one({"username": mentor_data['volunteer']}, {'_id': 0, 'username': 0}).items()
child_data = db.tycl_vol_pfle.find_one({"username": mentor_data['child']}, {'_id': 0, 'username': 0}).items()
return render(request, 'landing.html', {'historic_feedback': [x.items() for x in mentor_data['feedback']],
'child_data': child_data, 'volunteer_data': volunteer_data,
'res': res1, 'res2': res12, 'res3': res13, 'res4': res14})
def mentor_questionnare(request):
db = mongo_instance()
if request.method == "POST":
ref_append = {'type': 'Objective'}
for entity in db.tycl.find_one({'id': 'q_reference'})['val']:
if entity in request.POST and request.POST[entity]:
ref_append[entity] = request.POST[entity]
ref_desc = {'type': 'descriptive'}
form_elements = ['Educational performance at the school_d',
'Health (physical and Mental well-being)condition of the child_d',
'Child relationship with family members_d',
'Child relationship with friends_d',
'Participation in co-curricular activities_d',
'Participation in social/community events_d',
'Feeling safe at Home, community and School_d',
'Social interaction with peers_d',
'Personal hygiene of the child_d',
'Date of meeting',
'Place of meeting',
'Meeting Agenda', 'Outcome of Meeting', 'Key Accomplishment', 'Purpose of Connection',
'Key learnings for Mentee', 'Key Challenges faced by volunteer',
'Key Challenges faced by mentee', 'Key Challenges faced by mentor']
# form elements reference
for element in form_elements:
if element in request.POST and request.POST[element]:
ref_desc[element] = request.POST[element]
db.tycl_questionnare_new.insert(ref_append)
db.tycl_questionnare_new.insert(ref_desc)
return HttpResponseRedirect('/')
return render(request, 'questionnare.html')
|
apache-2.0
|
[
504,
1639,
14,
17469,
492,
3795,
199,
504,
1639,
14,
1014,
492,
14935,
199,
504,
24812,
63,
78,
16933,
14,
1208,
14,
2330,
492,
18006,
63,
842,
421,
199,
318,
2274,
63,
434,
269,
63,
2913,
8,
1069,
304,
272,
340,
1056,
14,
765,
508,
283,
4030,
356,
267,
1592,
275,
18006,
63,
842,
342,
267,
2883,
275,
1592,
14,
369,
429,
14,
1623,
63,
368,
3252,
344,
356,
283,
434,
269,
63,
2913,
63,
4443,
3071,
459,
637,
418,
267,
367,
1022,
315,
2883,
26,
288,
340,
1022,
315,
661,
2473,
297,
3461,
355,
1980,
288,
916,
1022,
508,
298,
11043,
63,
1618,
63,
920,
529,
280,
261,
582,
355,
2883,
59,
75,
61,
275,
1056,
14,
4030,
59,
75,
14,
1814,
360,
1656,
18962,
1055,
2325,
1252,
1294,
11917,
288,
2883,
59,
75,
61,
275,
1056,
14,
4030,
59,
75,
14,
1814,
360,
1656,
2513,
5440,
267,
2883,
459,
2473,
418,
275,
1056,
14,
751,
14,
2473,
267,
1592,
14,
369,
429,
63,
434,
269,
63,
2913,
14,
3176,
8,
1612,
9,
267,
372,
14935,
7825,
339,
372,
3795,
8,
1069,
12,
283,
2913,
14,
1360,
358,
421,
199,
318,
221,
434,
269,
63,
9688,
316,
8,
1069,
304,
272,
1592,
275,
18006,
63,
842,
342,
272,
340,
1056,
14,
765,
508,
298,
4030,
582,
267,
986,
339,
522,
275,
1592,
14,
369,
429,
63,
4790,
78,
1530,
63,
1222,
14,
1623,
2561,
298,
1262,
31089,
387,
296,
315,
20295,
15,
9387,
4474,
582,
469,
7880,
2444,
582,
715,
13459,
12740,
32136,
344,
356,
16,
12,
298,
1262,
31089,
387,
296,
315,
20295,
15,
9387,
4474,
582,
17,
3828,
272,
522,
18,
275,
1592,
14,
369,
429,
63,
4790,
78,
1530,
63,
1222,
14,
1623,
2561,
298,
3493,
8931,
543,
26157,
582,
469,
7880,
2444,
582,
715,
13459,
12933,
32136,
344,
356,
16,
12,
298,
3493,
8931,
543,
26157,
582,
17,
3828,
272,
522,
17,
275,
359,
442,
8,
82,
14,
1459,
3430,
16,
566,
367,
519,
315,
522,
19663,
713,
61,
272,
522,
713,
275,
359,
442,
8,
82,
14,
1459,
3430,
16,
566,
367,
519,
315,
522,
18,
19663,
713,
61,
339,
522,
19,
275,
1592,
14,
369,
429,
63,
4790,
78,
1530,
63,
1222,
14,
1623,
2561,
298,
37,
5905,
6279,
10238,
737,
314,
308,
15089,
582,
469,
4505,
2444,
356,
715,
13459,
12933,
32136,
344,
356,
16,
12,
298,
37,
5905,
6279,
10238,
737,
314,
308,
15089,
582,
17,
3828,
272,
522,
20,
275,
1592,
14,
369,
429,
63,
4790,
78,
1530,
63,
1222,
14,
1623,
2561,
298,
1262,
31089,
387,
296,
315,
20295,
15,
9387,
4474,
582,
469,
4505,
2444,
356,
715,
13459,
12933,
32136,
344,
356,
16,
12,
298,
1262,
31089,
387,
296,
315,
20295,
15,
9387,
4474,
582,
17,
3828,
339,
522,
969,
275,
359,
442,
8,
82,
14,
1459,
3430,
16,
566,
367,
519,
315,
522,
19,
19663,
713,
61,
272,
522,
1079,
275,
359,
442,
8,
82,
14,
1459,
3430,
16,
566,
367,
519,
315,
522,
20,
19663,
713,
61,
339,
1592,
275,
18006,
63,
842,
342,
272,
221,
434,
269,
63,
576,
275,
1592,
14,
369,
429,
63,
434,
269,
63,
576,
14,
1623,
63,
368,
6333,
2473,
582,
1056,
14,
751,
14,
2473,
1552,
272,
5236,
27929,
63,
576,
275,
1592,
14,
369,
429,
63,
5650,
63,
9928,
274,
14,
1623,
63,
368,
6333,
2473,
582,
221,
434,
269,
63,
576,
459,
5650,
27929,
14949,
32136,
344,
356,
378,
12,
283,
2473,
356,
378,
21385,
1744,
342,
272,
1982,
63,
576,
275,
1592,
14,
369,
429,
63,
5650,
63,
9928,
274,
14,
1623,
63,
368,
6333,
2473,
582,
221,
434,
269,
63,
576,
459,
1739,
14949,
32136,
344,
356,
378,
12,
283,
2473,
356,
378,
21385,
1744,
342,
339,
372,
3795,
8,
1069,
12,
283,
9688,
316,
14,
1360,
297,
791,
11141,
269,
530,
63,
13485,
356,
359,
88,
14,
1744,
342,
367,
671,
315,
221,
434,
269,
63,
576,
459,
13485,
2157,
4490,
283,
1739,
63,
576,
356,
1982,
63,
576,
12,
283,
5650,
27929,
63,
576,
356,
5236,
27929,
63,
576,
12,
4490,
283,
470,
356,
522,
17,
12,
283,
470,
18,
356,
522,
713,
12,
283,
470,
19,
356,
522,
969,
12,
283,
470,
20,
356,
522,
1079,
1552,
421,
199,
318,
221,
434,
269,
63,
4790,
78,
1530,
8,
1069,
304,
272,
1592,
275,
18006,
63,
842,
342,
272,
340,
1056,
14,
765,
508,
298,
4030,
582,
267,
2984,
63,
740,
275,
791,
466,
356,
283,
29104,
936,
267,
367,
4642,
315,
1592,
14,
369,
429,
14,
1623,
63,
368,
3252,
344,
356,
283,
81,
63,
4443,
3071,
459,
637,
2565,
288,
340,
4642,
315,
1056,
14,
4030,
436,
1056,
14,
4030,
59,
4502,
2189,
355,
2984,
63,
740,
59,
4502,
61,
275,
1056,
14,
4030,
59,
4502,
61,
398,
2984,
63,
3257,
275,
791,
466,
356,
283,
271,
729,
21701,
936,
267,
1824,
63,
5527,
275,
788,
37,
5905,
6279,
10238,
737,
314,
308,
15089,
63,
68,
297,
586,
283,
18850,
334,
15020,
436,
603,
484,
279,
5521,
13,
1235,
316,
9,
5394,
402,
314,
1982,
63,
68,
297,
586,
283,
3493,
8931,
543,
9614,
7556,
63,
68,
297,
586,
283,
3493,
8931,
543,
26157,
63,
68,
297,
586,
283,
1262,
31089,
387,
296,
315,
512,
13,
895,
1567,
2238,
30744,
63,
68,
297,
586,
283,
1262,
31089,
387,
296,
315,
20295,
15,
9387,
4474,
63,
68,
297,
586,
283,
3456,
352,
316,
5048,
737,
14621,
12,
23633,
436,
428,
15089,
63,
68,
297,
586,
283,
31356,
18752,
543,
28166,
63,
68,
297,
586,
283,
7344,
279,
394,
5016,
73,
6349,
402,
314,
1982,
63,
68,
297,
586,
283,
2506,
402,
31495,
297,
586,
283,
11613,
402,
31495,
297,
586,
283,
1352,
13800,
21582,
29162,
297,
283,
2204,
4352,
402,
3194,
13800,
297,
283,
1197,
4473,
863,
1891,
434,
297,
283,
14959,
4070,
402,
8113,
297,
586,
283,
1197,
1026,
2627,
367,
603,
287,
15557,
297,
283,
1197,
2799,
30599,
1433,
6867,
701,
5236,
27929,
297,
586,
283,
1197,
2799,
30599,
1433,
6867,
701,
12953,
15557,
297,
283,
1197,
2799,
30599,
1433,
6867,
701,
221,
434,
269,
418,
398,
327,
1824,
4008,
3659,
267,
367,
1819
] |
[
1639,
14,
17469,
492,
3795,
199,
504,
1639,
14,
1014,
492,
14935,
199,
504,
24812,
63,
78,
16933,
14,
1208,
14,
2330,
492,
18006,
63,
842,
421,
199,
318,
2274,
63,
434,
269,
63,
2913,
8,
1069,
304,
272,
340,
1056,
14,
765,
508,
283,
4030,
356,
267,
1592,
275,
18006,
63,
842,
342,
267,
2883,
275,
1592,
14,
369,
429,
14,
1623,
63,
368,
3252,
344,
356,
283,
434,
269,
63,
2913,
63,
4443,
3071,
459,
637,
418,
267,
367,
1022,
315,
2883,
26,
288,
340,
1022,
315,
661,
2473,
297,
3461,
355,
1980,
288,
916,
1022,
508,
298,
11043,
63,
1618,
63,
920,
529,
280,
261,
582,
355,
2883,
59,
75,
61,
275,
1056,
14,
4030,
59,
75,
14,
1814,
360,
1656,
18962,
1055,
2325,
1252,
1294,
11917,
288,
2883,
59,
75,
61,
275,
1056,
14,
4030,
59,
75,
14,
1814,
360,
1656,
2513,
5440,
267,
2883,
459,
2473,
418,
275,
1056,
14,
751,
14,
2473,
267,
1592,
14,
369,
429,
63,
434,
269,
63,
2913,
14,
3176,
8,
1612,
9,
267,
372,
14935,
7825,
339,
372,
3795,
8,
1069,
12,
283,
2913,
14,
1360,
358,
421,
199,
318,
221,
434,
269,
63,
9688,
316,
8,
1069,
304,
272,
1592,
275,
18006,
63,
842,
342,
272,
340,
1056,
14,
765,
508,
298,
4030,
582,
267,
986,
339,
522,
275,
1592,
14,
369,
429,
63,
4790,
78,
1530,
63,
1222,
14,
1623,
2561,
298,
1262,
31089,
387,
296,
315,
20295,
15,
9387,
4474,
582,
469,
7880,
2444,
582,
715,
13459,
12740,
32136,
344,
356,
16,
12,
298,
1262,
31089,
387,
296,
315,
20295,
15,
9387,
4474,
582,
17,
3828,
272,
522,
18,
275,
1592,
14,
369,
429,
63,
4790,
78,
1530,
63,
1222,
14,
1623,
2561,
298,
3493,
8931,
543,
26157,
582,
469,
7880,
2444,
582,
715,
13459,
12933,
32136,
344,
356,
16,
12,
298,
3493,
8931,
543,
26157,
582,
17,
3828,
272,
522,
17,
275,
359,
442,
8,
82,
14,
1459,
3430,
16,
566,
367,
519,
315,
522,
19663,
713,
61,
272,
522,
713,
275,
359,
442,
8,
82,
14,
1459,
3430,
16,
566,
367,
519,
315,
522,
18,
19663,
713,
61,
339,
522,
19,
275,
1592,
14,
369,
429,
63,
4790,
78,
1530,
63,
1222,
14,
1623,
2561,
298,
37,
5905,
6279,
10238,
737,
314,
308,
15089,
582,
469,
4505,
2444,
356,
715,
13459,
12933,
32136,
344,
356,
16,
12,
298,
37,
5905,
6279,
10238,
737,
314,
308,
15089,
582,
17,
3828,
272,
522,
20,
275,
1592,
14,
369,
429,
63,
4790,
78,
1530,
63,
1222,
14,
1623,
2561,
298,
1262,
31089,
387,
296,
315,
20295,
15,
9387,
4474,
582,
469,
4505,
2444,
356,
715,
13459,
12933,
32136,
344,
356,
16,
12,
298,
1262,
31089,
387,
296,
315,
20295,
15,
9387,
4474,
582,
17,
3828,
339,
522,
969,
275,
359,
442,
8,
82,
14,
1459,
3430,
16,
566,
367,
519,
315,
522,
19,
19663,
713,
61,
272,
522,
1079,
275,
359,
442,
8,
82,
14,
1459,
3430,
16,
566,
367,
519,
315,
522,
20,
19663,
713,
61,
339,
1592,
275,
18006,
63,
842,
342,
272,
221,
434,
269,
63,
576,
275,
1592,
14,
369,
429,
63,
434,
269,
63,
576,
14,
1623,
63,
368,
6333,
2473,
582,
1056,
14,
751,
14,
2473,
1552,
272,
5236,
27929,
63,
576,
275,
1592,
14,
369,
429,
63,
5650,
63,
9928,
274,
14,
1623,
63,
368,
6333,
2473,
582,
221,
434,
269,
63,
576,
459,
5650,
27929,
14949,
32136,
344,
356,
378,
12,
283,
2473,
356,
378,
21385,
1744,
342,
272,
1982,
63,
576,
275,
1592,
14,
369,
429,
63,
5650,
63,
9928,
274,
14,
1623,
63,
368,
6333,
2473,
582,
221,
434,
269,
63,
576,
459,
1739,
14949,
32136,
344,
356,
378,
12,
283,
2473,
356,
378,
21385,
1744,
342,
339,
372,
3795,
8,
1069,
12,
283,
9688,
316,
14,
1360,
297,
791,
11141,
269,
530,
63,
13485,
356,
359,
88,
14,
1744,
342,
367,
671,
315,
221,
434,
269,
63,
576,
459,
13485,
2157,
4490,
283,
1739,
63,
576,
356,
1982,
63,
576,
12,
283,
5650,
27929,
63,
576,
356,
5236,
27929,
63,
576,
12,
4490,
283,
470,
356,
522,
17,
12,
283,
470,
18,
356,
522,
713,
12,
283,
470,
19,
356,
522,
969,
12,
283,
470,
20,
356,
522,
1079,
1552,
421,
199,
318,
221,
434,
269,
63,
4790,
78,
1530,
8,
1069,
304,
272,
1592,
275,
18006,
63,
842,
342,
272,
340,
1056,
14,
765,
508,
298,
4030,
582,
267,
2984,
63,
740,
275,
791,
466,
356,
283,
29104,
936,
267,
367,
4642,
315,
1592,
14,
369,
429,
14,
1623,
63,
368,
3252,
344,
356,
283,
81,
63,
4443,
3071,
459,
637,
2565,
288,
340,
4642,
315,
1056,
14,
4030,
436,
1056,
14,
4030,
59,
4502,
2189,
355,
2984,
63,
740,
59,
4502,
61,
275,
1056,
14,
4030,
59,
4502,
61,
398,
2984,
63,
3257,
275,
791,
466,
356,
283,
271,
729,
21701,
936,
267,
1824,
63,
5527,
275,
788,
37,
5905,
6279,
10238,
737,
314,
308,
15089,
63,
68,
297,
586,
283,
18850,
334,
15020,
436,
603,
484,
279,
5521,
13,
1235,
316,
9,
5394,
402,
314,
1982,
63,
68,
297,
586,
283,
3493,
8931,
543,
9614,
7556,
63,
68,
297,
586,
283,
3493,
8931,
543,
26157,
63,
68,
297,
586,
283,
1262,
31089,
387,
296,
315,
512,
13,
895,
1567,
2238,
30744,
63,
68,
297,
586,
283,
1262,
31089,
387,
296,
315,
20295,
15,
9387,
4474,
63,
68,
297,
586,
283,
3456,
352,
316,
5048,
737,
14621,
12,
23633,
436,
428,
15089,
63,
68,
297,
586,
283,
31356,
18752,
543,
28166,
63,
68,
297,
586,
283,
7344,
279,
394,
5016,
73,
6349,
402,
314,
1982,
63,
68,
297,
586,
283,
2506,
402,
31495,
297,
586,
283,
11613,
402,
31495,
297,
586,
283,
1352,
13800,
21582,
29162,
297,
283,
2204,
4352,
402,
3194,
13800,
297,
283,
1197,
4473,
863,
1891,
434,
297,
283,
14959,
4070,
402,
8113,
297,
586,
283,
1197,
1026,
2627,
367,
603,
287,
15557,
297,
283,
1197,
2799,
30599,
1433,
6867,
701,
5236,
27929,
297,
586,
283,
1197,
2799,
30599,
1433,
6867,
701,
12953,
15557,
297,
283,
1197,
2799,
30599,
1433,
6867,
701,
221,
434,
269,
418,
398,
327,
1824,
4008,
3659,
267,
367,
1819,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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networkx/algorithms/isomorphism/isomorphvf2.py
|
76
|
36794
|
# -*- coding: utf-8 -*-
"""
*************
VF2 Algorithm
*************
An implementation of VF2 algorithm for graph ismorphism testing.
The simplest interface to use this module is to call networkx.is_isomorphic().
Introduction
------------
The GraphMatcher and DiGraphMatcher are responsible for matching
graphs or directed graphs in a predetermined manner. This
usually means a check for an isomorphism, though other checks
are also possible. For example, a subgraph of one graph
can be checked for isomorphism to a second graph.
Matching is done via syntactic feasibility. It is also possible
to check for semantic feasibility. Feasibility, then, is defined
as the logical AND of the two functions.
To include a semantic check, the (Di)GraphMatcher class should be
subclassed, and the semantic_feasibility() function should be
redefined. By default, the semantic feasibility function always
returns True. The effect of this is that semantics are not
considered in the matching of G1 and G2.
Examples
--------
Suppose G1 and G2 are isomorphic graphs. Verification is as follows:
>>> from networkx.algorithms import isomorphism
>>> G1 = nx.path_graph(4)
>>> G2 = nx.path_graph(4)
>>> GM = isomorphism.GraphMatcher(G1,G2)
>>> GM.is_isomorphic()
True
GM.mapping stores the isomorphism mapping from G1 to G2.
>>> GM.mapping
{0: 0, 1: 1, 2: 2, 3: 3}
Suppose G1 and G2 are isomorphic directed graphs
graphs. Verification is as follows:
>>> G1 = nx.path_graph(4, create_using=nx.DiGraph())
>>> G2 = nx.path_graph(4, create_using=nx.DiGraph())
>>> DiGM = isomorphism.DiGraphMatcher(G1,G2)
>>> DiGM.is_isomorphic()
True
DiGM.mapping stores the isomorphism mapping from G1 to G2.
>>> DiGM.mapping
{0: 0, 1: 1, 2: 2, 3: 3}
Subgraph Isomorphism
--------------------
Graph theory literature can be ambiguious about the meaning of the
above statement, and we seek to clarify it now.
In the VF2 literature, a mapping M is said to be a graph-subgraph
isomorphism iff M is an isomorphism between G2 and a subgraph of G1.
Thus, to say that G1 and G2 are graph-subgraph isomorphic is to say
that a subgraph of G1 is isomorphic to G2.
Other literature uses the phrase 'subgraph isomorphic' as in 'G1 does
not have a subgraph isomorphic to G2'. Another use is as an in adverb
for isomorphic. Thus, to say that G1 and G2 are subgraph isomorphic
is to say that a subgraph of G1 is isomorphic to G2.
Finally, the term 'subgraph' can have multiple meanings. In this
context, 'subgraph' always means a 'node-induced subgraph'. Edge-induced
subgraph isomorphisms are not directly supported, but one should be
able to perform the check by making use of nx.line_graph(). For
subgraphs which are not induced, the term 'monomorphism' is preferred
over 'isomorphism'. Currently, it is not possible to check for
monomorphisms.
Let G=(N,E) be a graph with a set of nodes N and set of edges E.
If G'=(N',E') is a subgraph, then:
N' is a subset of N
E' is a subset of E
If G'=(N',E') is a node-induced subgraph, then:
N' is a subset of N
E' is the subset of edges in E relating nodes in N'
If G'=(N',E') is an edge-induced subgrpah, then:
N' is the subset of nodes in N related by edges in E'
E' is a subset of E
References
----------
[1] Luigi P. Cordella, Pasquale Foggia, Carlo Sansone, Mario Vento,
"A (Sub)Graph Isomorphism Algorithm for Matching Large Graphs",
IEEE Transactions on Pattern Analysis and Machine Intelligence,
vol. 26, no. 10, pp. 1367-1372, Oct., 2004.
http://ieeexplore.ieee.org/iel5/34/29305/01323804.pdf
[2] L. P. Cordella, P. Foggia, C. Sansone, M. Vento, "An Improved
Algorithm for Matching Large Graphs", 3rd IAPR-TC15 Workshop
on Graph-based Representations in Pattern Recognition, Cuen,
pp. 149-159, 2001.
http://amalfi.dis.unina.it/graph/db/papers/vf-algorithm.pdf
See Also
--------
syntactic_feasibliity(), semantic_feasibility()
Notes
-----
Modified to handle undirected graphs.
Modified to handle multiple edges.
In general, this problem is NP-Complete.
"""
# Copyright (C) 2007-2009 by the NetworkX maintainers
# All rights reserved.
# BSD license.
# This work was originally coded by Christopher Ellison
# as part of the Computational Mechanics Python (CMPy) project.
# James P. Crutchfield, principal investigator.
# Complexity Sciences Center and Physics Department, UC Davis.
import sys
import networkx as nx
__all__ = ['GraphMatcher',
'DiGraphMatcher']
class GraphMatcher(object):
"""Implementation of VF2 algorithm for matching undirected graphs.
Suitable for Graph and MultiGraph instances.
"""
def __init__(self, G1, G2):
"""Initialize GraphMatcher.
Parameters
----------
G1,G2: NetworkX Graph or MultiGraph instances.
The two graphs to check for isomorphism.
Examples
--------
To create a GraphMatcher which checks for syntactic feasibility:
>>> from networkx.algorithms import isomorphism
>>> G1 = nx.path_graph(4)
>>> G2 = nx.path_graph(4)
>>> GM = isomorphism.GraphMatcher(G1,G2)
"""
self.G1 = G1
self.G2 = G2
self.G1_nodes = set(G1.nodes())
self.G2_nodes = set(G2.nodes())
# Set recursion limit.
self.old_recursion_limit = sys.getrecursionlimit()
expected_max_recursion_level = len(self.G2)
if self.old_recursion_limit < 1.5 * expected_max_recursion_level:
# Give some breathing room.
sys.setrecursionlimit(int(1.5 * expected_max_recursion_level))
# Declare that we will be searching for a graph-graph isomorphism.
self.test = 'graph'
# Initialize state
self.initialize()
def reset_recursion_limit(self):
"""Restores the recursion limit."""
### TODO:
### Currently, we use recursion and set the recursion level higher.
### It would be nice to restore the level, but because the
### (Di)GraphMatcher classes make use of cyclic references, garbage
### collection will never happen when we define __del__() to
### restore the recursion level. The result is a memory leak.
### So for now, we do not automatically restore the recursion level,
### and instead provide a method to do this manually. Eventually,
### we should turn this into a non-recursive implementation.
sys.setrecursionlimit(self.old_recursion_limit)
def candidate_pairs_iter(self):
"""Iterator over candidate pairs of nodes in G1 and G2."""
# All computations are done using the current state!
G1_nodes = self.G1_nodes
G2_nodes = self.G2_nodes
# First we compute the inout-terminal sets.
T1_inout = [node for node in G1_nodes if (node in self.inout_1) and (node not in self.core_1)]
T2_inout = [node for node in G2_nodes if (node in self.inout_2) and (node not in self.core_2)]
# If T1_inout and T2_inout are both nonempty.
# P(s) = T1_inout x {min T2_inout}
if T1_inout and T2_inout:
for node in T1_inout:
yield node, min(T2_inout)
else:
# If T1_inout and T2_inout were both empty....
# P(s) = (N_1 - M_1) x {min (N_2 - M_2)}
##if not (T1_inout or T2_inout): # as suggested by [2], incorrect
if 1: # as inferred from [1], correct
# First we determine the candidate node for G2
other_node = min(G2_nodes - set(self.core_2))
for node in self.G1:
if node not in self.core_1:
yield node, other_node
# For all other cases, we don't have any candidate pairs.
def initialize(self):
"""Reinitializes the state of the algorithm.
This method should be redefined if using something other than GMState.
If only subclassing GraphMatcher, a redefinition is not necessary.
"""
# core_1[n] contains the index of the node paired with n, which is m,
# provided n is in the mapping.
# core_2[m] contains the index of the node paired with m, which is n,
# provided m is in the mapping.
self.core_1 = {}
self.core_2 = {}
# See the paper for definitions of M_x and T_x^{y}
# inout_1[n] is non-zero if n is in M_1 or in T_1^{inout}
# inout_2[m] is non-zero if m is in M_2 or in T_2^{inout}
#
# The value stored is the depth of the SSR tree when the node became
# part of the corresponding set.
self.inout_1 = {}
self.inout_2 = {}
# Practically, these sets simply store the nodes in the subgraph.
self.state = GMState(self)
# Provide a convienient way to access the isomorphism mapping.
self.mapping = self.core_1.copy()
def is_isomorphic(self):
"""Returns True if G1 and G2 are isomorphic graphs."""
# Let's do two very quick checks!
# QUESTION: Should we call faster_graph_could_be_isomorphic(G1,G2)?
# For now, I just copy the code.
# Check global properties
if self.G1.order() != self.G2.order(): return False
# Check local properties
d1=sorted(self.G1.degree().values())
d2=sorted(self.G2.degree().values())
if d1 != d2: return False
try:
x = next(self.isomorphisms_iter())
return True
except StopIteration:
return False
def isomorphisms_iter(self):
"""Generator over isomorphisms between G1 and G2."""
# Declare that we are looking for a graph-graph isomorphism.
self.test = 'graph'
self.initialize()
for mapping in self.match():
yield mapping
def match(self):
"""Extends the isomorphism mapping.
This function is called recursively to determine if a complete
isomorphism can be found between G1 and G2. It cleans up the class
variables after each recursive call. If an isomorphism is found,
we yield the mapping.
"""
if len(self.core_1) == len(self.G2):
# Save the final mapping, otherwise garbage collection deletes it.
self.mapping = self.core_1.copy()
# The mapping is complete.
yield self.mapping
else:
for G1_node, G2_node in self.candidate_pairs_iter():
if self.syntactic_feasibility(G1_node, G2_node):
if self.semantic_feasibility(G1_node, G2_node):
# Recursive call, adding the feasible state.
newstate = self.state.__class__(self, G1_node, G2_node)
for mapping in self.match():
yield mapping
# restore data structures
newstate.restore()
def semantic_feasibility(self, G1_node, G2_node):
"""Returns True if adding (G1_node, G2_node) is symantically feasible.
The semantic feasibility function should return True if it is
acceptable to add the candidate pair (G1_node, G2_node) to the current
partial isomorphism mapping. The logic should focus on semantic
information contained in the edge data or a formalized node class.
By acceptable, we mean that the subsequent mapping can still become a
complete isomorphism mapping. Thus, if adding the candidate pair
definitely makes it so that the subsequent mapping cannot become a
complete isomorphism mapping, then this function must return False.
The default semantic feasibility function always returns True. The
effect is that semantics are not considered in the matching of G1
and G2.
The semantic checks might differ based on the what type of test is
being performed. A keyword description of the test is stored in
self.test. Here is a quick description of the currently implemented
tests::
test='graph'
Indicates that the graph matcher is looking for a graph-graph
isomorphism.
test='subgraph'
Indicates that the graph matcher is looking for a subgraph-graph
isomorphism such that a subgraph of G1 is isomorphic to G2.
Any subclass which redefines semantic_feasibility() must maintain
the above form to keep the match() method functional. Implementations
should consider multigraphs.
"""
return True
def subgraph_is_isomorphic(self):
"""Returns True if a subgraph of G1 is isomorphic to G2."""
try:
x = next(self.subgraph_isomorphisms_iter())
return True
except StopIteration:
return False
# subgraph_is_isomorphic.__doc__ += "\n" + subgraph.replace('\n','\n'+indent)
def subgraph_isomorphisms_iter(self):
"""Generator over isomorphisms between a subgraph of G1 and G2."""
# Declare that we are looking for graph-subgraph isomorphism.
self.test = 'subgraph'
self.initialize()
for mapping in self.match():
yield mapping
# subgraph_isomorphisms_iter.__doc__ += "\n" + subgraph.replace('\n','\n'+indent)
def syntactic_feasibility(self, G1_node, G2_node):
"""Returns True if adding (G1_node, G2_node) is syntactically feasible.
This function returns True if it is adding the candidate pair
to the current partial isomorphism mapping is allowable. The addition
is allowable if the inclusion of the candidate pair does not make it
impossible for an isomorphism to be found.
"""
# The VF2 algorithm was designed to work with graphs having, at most,
# one edge connecting any two nodes. This is not the case when
# dealing with an MultiGraphs.
#
# Basically, when we test the look-ahead rules R_neighbor, we will
# make sure that the number of edges are checked. We also add
# a R_self check to verify that the number of selfloops is acceptable.
#
# Users might be comparing Graph instances with MultiGraph instances.
# So the generic GraphMatcher class must work with MultiGraphs.
# Care must be taken since the value in the innermost dictionary is a
# singlet for Graph instances. For MultiGraphs, the value in the
# innermost dictionary is a list.
###
### Test at each step to get a return value as soon as possible.
###
### Look ahead 0
# R_self
# The number of selfloops for G1_node must equal the number of
# self-loops for G2_node. Without this check, we would fail on
# R_neighbor at the next recursion level. But it is good to prune the
# search tree now.
if self.G1.number_of_edges(G1_node,G1_node) != self.G2.number_of_edges(G2_node,G2_node):
return False
# R_neighbor
# For each neighbor n' of n in the partial mapping, the corresponding
# node m' is a neighbor of m, and vice versa. Also, the number of
# edges must be equal.
for neighbor in self.G1[G1_node]:
if neighbor in self.core_1:
if not (self.core_1[neighbor] in self.G2[G2_node]):
return False
elif self.G1.number_of_edges(neighbor, G1_node) != self.G2.number_of_edges(self.core_1[neighbor], G2_node):
return False
for neighbor in self.G2[G2_node]:
if neighbor in self.core_2:
if not (self.core_2[neighbor] in self.G1[G1_node]):
return False
elif self.G1.number_of_edges(self.core_2[neighbor], G1_node) != self.G2.number_of_edges(neighbor, G2_node):
return False
### Look ahead 1
# R_terminout
# The number of neighbors of n that are in T_1^{inout} is equal to the
# number of neighbors of m that are in T_2^{inout}, and vice versa.
num1 = 0
for neighbor in self.G1[G1_node]:
if (neighbor in self.inout_1) and (neighbor not in self.core_1):
num1 += 1
num2 = 0
for neighbor in self.G2[G2_node]:
if (neighbor in self.inout_2) and (neighbor not in self.core_2):
num2 += 1
if self.test == 'graph':
if not (num1 == num2):
return False
else: # self.test == 'subgraph'
if not (num1 >= num2):
return False
### Look ahead 2
# R_new
# The number of neighbors of n that are neither in the core_1 nor
# T_1^{inout} is equal to the number of neighbors of m
# that are neither in core_2 nor T_2^{inout}.
num1 = 0
for neighbor in self.G1[G1_node]:
if neighbor not in self.inout_1:
num1 += 1
num2 = 0
for neighbor in self.G2[G2_node]:
if neighbor not in self.inout_2:
num2 += 1
if self.test == 'graph':
if not (num1 == num2):
return False
else: # self.test == 'subgraph'
if not (num1 >= num2):
return False
# Otherwise, this node pair is syntactically feasible!
return True
class DiGraphMatcher(GraphMatcher):
"""Implementation of VF2 algorithm for matching directed graphs.
Suitable for DiGraph and MultiDiGraph instances.
"""
# __doc__ += "Notes\n%s-----" % (indent,) + sources.replace('\n','\n'+indent)
def __init__(self, G1, G2):
"""Initialize DiGraphMatcher.
G1 and G2 should be nx.Graph or nx.MultiGraph instances.
Examples
--------
To create a GraphMatcher which checks for syntactic feasibility:
>>> from networkx.algorithms import isomorphism
>>> G1 = nx.DiGraph(nx.path_graph(4, create_using=nx.DiGraph()))
>>> G2 = nx.DiGraph(nx.path_graph(4, create_using=nx.DiGraph()))
>>> DiGM = isomorphism.DiGraphMatcher(G1,G2)
"""
super(DiGraphMatcher, self).__init__(G1, G2)
def candidate_pairs_iter(self):
"""Iterator over candidate pairs of nodes in G1 and G2."""
# All computations are done using the current state!
G1_nodes = self.G1_nodes
G2_nodes = self.G2_nodes
# First we compute the out-terminal sets.
T1_out = [node for node in G1_nodes if (node in self.out_1) and (node not in self.core_1)]
T2_out = [node for node in G2_nodes if (node in self.out_2) and (node not in self.core_2)]
# If T1_out and T2_out are both nonempty.
# P(s) = T1_out x {min T2_out}
if T1_out and T2_out:
node_2 = min(T2_out)
for node_1 in T1_out:
yield node_1, node_2
# If T1_out and T2_out were both empty....
# We compute the in-terminal sets.
##elif not (T1_out or T2_out): # as suggested by [2], incorrect
else: # as suggested by [1], correct
T1_in = [node for node in G1_nodes if (node in self.in_1) and (node not in self.core_1)]
T2_in = [node for node in G2_nodes if (node in self.in_2) and (node not in self.core_2)]
# If T1_in and T2_in are both nonempty.
# P(s) = T1_out x {min T2_out}
if T1_in and T2_in:
node_2 = min(T2_in)
for node_1 in T1_in:
yield node_1, node_2
# If all terminal sets are empty...
# P(s) = (N_1 - M_1) x {min (N_2 - M_2)}
##elif not (T1_in or T2_in): # as suggested by [2], incorrect
else: # as inferred from [1], correct
node_2 = min(G2_nodes - set(self.core_2))
for node_1 in G1_nodes:
if node_1 not in self.core_1:
yield node_1, node_2
# For all other cases, we don't have any candidate pairs.
def initialize(self):
"""Reinitializes the state of the algorithm.
This method should be redefined if using something other than DiGMState.
If only subclassing GraphMatcher, a redefinition is not necessary.
"""
# core_1[n] contains the index of the node paired with n, which is m,
# provided n is in the mapping.
# core_2[m] contains the index of the node paired with m, which is n,
# provided m is in the mapping.
self.core_1 = {}
self.core_2 = {}
# See the paper for definitions of M_x and T_x^{y}
# in_1[n] is non-zero if n is in M_1 or in T_1^{in}
# out_1[n] is non-zero if n is in M_1 or in T_1^{out}
#
# in_2[m] is non-zero if m is in M_2 or in T_2^{in}
# out_2[m] is non-zero if m is in M_2 or in T_2^{out}
#
# The value stored is the depth of the search tree when the node became
# part of the corresponding set.
self.in_1 = {}
self.in_2 = {}
self.out_1 = {}
self.out_2 = {}
self.state = DiGMState(self)
# Provide a convienient way to access the isomorphism mapping.
self.mapping = self.core_1.copy()
def syntactic_feasibility(self, G1_node, G2_node):
"""Returns True if adding (G1_node, G2_node) is syntactically feasible.
This function returns True if it is adding the candidate pair
to the current partial isomorphism mapping is allowable. The addition
is allowable if the inclusion of the candidate pair does not make it
impossible for an isomorphism to be found.
"""
# The VF2 algorithm was designed to work with graphs having, at most,
# one edge connecting any two nodes. This is not the case when
# dealing with an MultiGraphs.
#
# Basically, when we test the look-ahead rules R_pred and R_succ, we
# will make sure that the number of edges are checked. We also add
# a R_self check to verify that the number of selfloops is acceptable.
# Users might be comparing DiGraph instances with MultiDiGraph
# instances. So the generic DiGraphMatcher class must work with
# MultiDiGraphs. Care must be taken since the value in the innermost
# dictionary is a singlet for DiGraph instances. For MultiDiGraphs,
# the value in the innermost dictionary is a list.
###
### Test at each step to get a return value as soon as possible.
###
### Look ahead 0
# R_self
# The number of selfloops for G1_node must equal the number of
# self-loops for G2_node. Without this check, we would fail on R_pred
# at the next recursion level. This should prune the tree even further.
if self.G1.number_of_edges(G1_node,G1_node) != self.G2.number_of_edges(G2_node,G2_node):
return False
# R_pred
# For each predecessor n' of n in the partial mapping, the
# corresponding node m' is a predecessor of m, and vice versa. Also,
# the number of edges must be equal
for predecessor in self.G1.pred[G1_node]:
if predecessor in self.core_1:
if not (self.core_1[predecessor] in self.G2.pred[G2_node]):
return False
elif self.G1.number_of_edges(predecessor, G1_node) != self.G2.number_of_edges(self.core_1[predecessor], G2_node):
return False
for predecessor in self.G2.pred[G2_node]:
if predecessor in self.core_2:
if not (self.core_2[predecessor] in self.G1.pred[G1_node]):
return False
elif self.G1.number_of_edges(self.core_2[predecessor], G1_node) != self.G2.number_of_edges(predecessor, G2_node):
return False
# R_succ
# For each successor n' of n in the partial mapping, the corresponding
# node m' is a successor of m, and vice versa. Also, the number of
# edges must be equal.
for successor in self.G1[G1_node]:
if successor in self.core_1:
if not (self.core_1[successor] in self.G2[G2_node]):
return False
elif self.G1.number_of_edges(G1_node, successor) != self.G2.number_of_edges(G2_node, self.core_1[successor]):
return False
for successor in self.G2[G2_node]:
if successor in self.core_2:
if not (self.core_2[successor] in self.G1[G1_node]):
return False
elif self.G1.number_of_edges(G1_node, self.core_2[successor]) != self.G2.number_of_edges(G2_node, successor):
return False
### Look ahead 1
# R_termin
# The number of predecessors of n that are in T_1^{in} is equal to the
# number of predecessors of m that are in T_2^{in}.
num1 = 0
for predecessor in self.G1.pred[G1_node]:
if (predecessor in self.in_1) and (predecessor not in self.core_1):
num1 += 1
num2 = 0
for predecessor in self.G2.pred[G2_node]:
if (predecessor in self.in_2) and (predecessor not in self.core_2):
num2 += 1
if self.test == 'graph':
if not (num1 == num2):
return False
else: # self.test == 'subgraph'
if not (num1 >= num2):
return False
# The number of successors of n that are in T_1^{in} is equal to the
# number of successors of m that are in T_2^{in}.
num1 = 0
for successor in self.G1[G1_node]:
if (successor in self.in_1) and (successor not in self.core_1):
num1 += 1
num2 = 0
for successor in self.G2[G2_node]:
if (successor in self.in_2) and (successor not in self.core_2):
num2 += 1
if self.test == 'graph':
if not (num1 == num2):
return False
else: # self.test == 'subgraph'
if not (num1 >= num2):
return False
# R_termout
# The number of predecessors of n that are in T_1^{out} is equal to the
# number of predecessors of m that are in T_2^{out}.
num1 = 0
for predecessor in self.G1.pred[G1_node]:
if (predecessor in self.out_1) and (predecessor not in self.core_1):
num1 += 1
num2 = 0
for predecessor in self.G2.pred[G2_node]:
if (predecessor in self.out_2) and (predecessor not in self.core_2):
num2 += 1
if self.test == 'graph':
if not (num1 == num2):
return False
else: # self.test == 'subgraph'
if not (num1 >= num2):
return False
# The number of successors of n that are in T_1^{out} is equal to the
# number of successors of m that are in T_2^{out}.
num1 = 0
for successor in self.G1[G1_node]:
if (successor in self.out_1) and (successor not in self.core_1):
num1 += 1
num2 = 0
for successor in self.G2[G2_node]:
if (successor in self.out_2) and (successor not in self.core_2):
num2 += 1
if self.test == 'graph':
if not (num1 == num2):
return False
else: # self.test == 'subgraph'
if not (num1 >= num2):
return False
### Look ahead 2
# R_new
# The number of predecessors of n that are neither in the core_1 nor
# T_1^{in} nor T_1^{out} is equal to the number of predecessors of m
# that are neither in core_2 nor T_2^{in} nor T_2^{out}.
num1 = 0
for predecessor in self.G1.pred[G1_node]:
if (predecessor not in self.in_1) and (predecessor not in self.out_1):
num1 += 1
num2 = 0
for predecessor in self.G2.pred[G2_node]:
if (predecessor not in self.in_2) and (predecessor not in self.out_2):
num2 += 1
if self.test == 'graph':
if not (num1 == num2):
return False
else: # self.test == 'subgraph'
if not (num1 >= num2):
return False
# The number of successors of n that are neither in the core_1 nor
# T_1^{in} nor T_1^{out} is equal to the number of successors of m
# that are neither in core_2 nor T_2^{in} nor T_2^{out}.
num1 = 0
for successor in self.G1[G1_node]:
if (successor not in self.in_1) and (successor not in self.out_1):
num1 += 1
num2 = 0
for successor in self.G2[G2_node]:
if (successor not in self.in_2) and (successor not in self.out_2):
num2 += 1
if self.test == 'graph':
if not (num1 == num2):
return False
else: # self.test == 'subgraph'
if not (num1 >= num2):
return False
# Otherwise, this node pair is syntactically feasible!
return True
class GMState(object):
"""Internal representation of state for the GraphMatcher class.
This class is used internally by the GraphMatcher class. It is used
only to store state specific data. There will be at most G2.order() of
these objects in memory at a time, due to the depth-first search
strategy employed by the VF2 algorithm.
"""
def __init__(self, GM, G1_node=None, G2_node=None):
"""Initializes GMState object.
Pass in the GraphMatcher to which this GMState belongs and the
new node pair that will be added to the GraphMatcher's current
isomorphism mapping.
"""
self.GM = GM
# Initialize the last stored node pair.
self.G1_node = None
self.G2_node = None
self.depth = len(GM.core_1)
if G1_node is None or G2_node is None:
# Then we reset the class variables
GM.core_1 = {}
GM.core_2 = {}
GM.inout_1 = {}
GM.inout_2 = {}
# Watch out! G1_node == 0 should evaluate to True.
if G1_node is not None and G2_node is not None:
# Add the node pair to the isomorphism mapping.
GM.core_1[G1_node] = G2_node
GM.core_2[G2_node] = G1_node
# Store the node that was added last.
self.G1_node = G1_node
self.G2_node = G2_node
# Now we must update the other two vectors.
# We will add only if it is not in there already!
self.depth = len(GM.core_1)
# First we add the new nodes...
if G1_node not in GM.inout_1:
GM.inout_1[G1_node] = self.depth
if G2_node not in GM.inout_2:
GM.inout_2[G2_node] = self.depth
# Now we add every other node...
# Updates for T_1^{inout}
new_nodes = set([])
for node in GM.core_1:
new_nodes.update([neighbor for neighbor in GM.G1[node] if neighbor not in GM.core_1])
for node in new_nodes:
if node not in GM.inout_1:
GM.inout_1[node] = self.depth
# Updates for T_2^{inout}
new_nodes = set([])
for node in GM.core_2:
new_nodes.update([neighbor for neighbor in GM.G2[node] if neighbor not in GM.core_2])
for node in new_nodes:
if node not in GM.inout_2:
GM.inout_2[node] = self.depth
def restore(self):
"""Deletes the GMState object and restores the class variables."""
# First we remove the node that was added from the core vectors.
# Watch out! G1_node == 0 should evaluate to True.
if self.G1_node is not None and self.G2_node is not None:
del self.GM.core_1[self.G1_node]
del self.GM.core_2[self.G2_node]
# Now we revert the other two vectors.
# Thus, we delete all entries which have this depth level.
for vector in (self.GM.inout_1, self.GM.inout_2):
for node in list(vector.keys()):
if vector[node] == self.depth:
del vector[node]
class DiGMState(object):
"""Internal representation of state for the DiGraphMatcher class.
This class is used internally by the DiGraphMatcher class. It is used
only to store state specific data. There will be at most G2.order() of
these objects in memory at a time, due to the depth-first search
strategy employed by the VF2 algorithm.
"""
def __init__(self, GM, G1_node=None, G2_node=None):
"""Initializes DiGMState object.
Pass in the DiGraphMatcher to which this DiGMState belongs and the
new node pair that will be added to the GraphMatcher's current
isomorphism mapping.
"""
self.GM = GM
# Initialize the last stored node pair.
self.G1_node = None
self.G2_node = None
self.depth = len(GM.core_1)
if G1_node is None or G2_node is None:
# Then we reset the class variables
GM.core_1 = {}
GM.core_2 = {}
GM.in_1 = {}
GM.in_2 = {}
GM.out_1 = {}
GM.out_2 = {}
# Watch out! G1_node == 0 should evaluate to True.
if G1_node is not None and G2_node is not None:
# Add the node pair to the isomorphism mapping.
GM.core_1[G1_node] = G2_node
GM.core_2[G2_node] = G1_node
# Store the node that was added last.
self.G1_node = G1_node
self.G2_node = G2_node
# Now we must update the other four vectors.
# We will add only if it is not in there already!
self.depth = len(GM.core_1)
# First we add the new nodes...
for vector in (GM.in_1, GM.out_1):
if G1_node not in vector:
vector[G1_node] = self.depth
for vector in (GM.in_2, GM.out_2):
if G2_node not in vector:
vector[G2_node] = self.depth
# Now we add every other node...
# Updates for T_1^{in}
new_nodes = set([])
for node in GM.core_1:
new_nodes.update([predecessor for predecessor in GM.G1.predecessors(node) if predecessor not in GM.core_1])
for node in new_nodes:
if node not in GM.in_1:
GM.in_1[node] = self.depth
# Updates for T_2^{in}
new_nodes = set([])
for node in GM.core_2:
new_nodes.update([predecessor for predecessor in GM.G2.predecessors(node) if predecessor not in GM.core_2])
for node in new_nodes:
if node not in GM.in_2:
GM.in_2[node] = self.depth
# Updates for T_1^{out}
new_nodes = set([])
for node in GM.core_1:
new_nodes.update([successor for successor in GM.G1.successors(node) if successor not in GM.core_1])
for node in new_nodes:
if node not in GM.out_1:
GM.out_1[node] = self.depth
# Updates for T_2^{out}
new_nodes = set([])
for node in GM.core_2:
new_nodes.update([successor for successor in GM.G2.successors(node) if successor not in GM.core_2])
for node in new_nodes:
if node not in GM.out_2:
GM.out_2[node] = self.depth
def restore(self):
"""Deletes the DiGMState object and restores the class variables."""
# First we remove the node that was added from the core vectors.
# Watch out! G1_node == 0 should evaluate to True.
if self.G1_node is not None and self.G2_node is not None:
del self.GM.core_1[self.G1_node]
del self.GM.core_2[self.G2_node]
# Now we revert the other four vectors.
# Thus, we delete all entries which have this depth level.
for vector in (self.GM.in_1, self.GM.in_2, self.GM.out_1, self.GM.out_2):
for node in list(vector.keys()):
if vector[node] == self.depth:
del vector[node]
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
1801,
1116,
10,
199,
32364,
18,
23823,
199,
1801,
1116,
10,
199,
199,
2493,
4514,
402,
812,
38,
18,
5563,
367,
3343,
365,
10128,
19185,
5343,
14,
199,
199,
1918,
3486,
270,
3217,
370,
675,
642,
859,
365,
370,
1240,
24313,
14,
374,
63,
374,
25456,
530,
1252,
199,
199,
3241,
293,
5199,
199,
4559,
199,
199,
1918,
11513,
16073,
436,
3757,
4578,
16073,
787,
17845,
367,
4877,
199,
16670,
503,
23667,
18312,
315,
282,
876,
27248,
30800,
14,
221,
961,
199,
25118,
4910,
282,
1104,
367,
376,
365,
25456,
19185,
12,
10617,
1163,
5920,
199,
1530,
2597,
3962,
14,
221,
2104,
2893,
12,
282,
23649,
402,
1373,
3343,
199,
2425,
506,
7923,
367,
365,
25456,
19185,
370,
282,
3499,
3343,
14,
199,
199,
14215,
365,
4224,
4799,
1847,
343,
27296,
1964,
305,
29524,
14,
2779,
365,
2597,
3962,
199,
475,
1104,
367,
32451,
1964,
305,
29524,
14,
7949,
305,
29524,
12,
2066,
12,
365,
3247,
199,
305,
314,
11461,
2401,
402,
314,
2877,
3423,
14,
199,
199,
1378,
2387,
282,
32451,
1104,
12,
314,
334,
1341,
9,
4578,
16073,
1021,
1077,
506,
199,
954,
28271,
12,
436,
314,
32451,
63,
771,
305,
29524,
342,
805,
1077,
506,
199,
27913,
14,
221,
4885,
849,
12,
314,
32451,
1964,
305,
29524,
805,
3544,
199,
5808,
715,
14,
221,
710,
7763,
402,
642,
365,
626,
19002,
787,
440,
199,
388,
2441,
581,
315,
314,
4877,
402,
598,
17,
436,
598,
18,
14,
199,
199,
22787,
199,
518,
199,
199,
4710,
4070,
598,
17,
436,
598,
18,
787,
365,
25456,
530,
18312,
14,
5444,
7313,
365,
465,
11924,
26,
199,
199,
6071,
687,
24313,
14,
24365,
492,
365,
25456,
19185,
199,
6071,
598,
17,
275,
8484,
14,
515,
63,
2180,
8,
20,
9,
199,
6071,
598,
18,
275,
8484,
14,
515,
63,
2180,
8,
20,
9,
199,
6071,
598,
45,
275,
365,
25456,
19185,
14,
4578,
16073,
8,
39,
17,
12,
39,
18,
9,
199,
6071,
598,
45,
14,
374,
63,
374,
25456,
530,
342,
199,
549,
199,
199,
22636,
14,
4745,
14086,
314,
365,
25456,
19185,
4412,
687,
598,
17,
370,
598,
18,
14,
199,
199,
6071,
598,
45,
14,
4745,
199,
91,
16,
26,
378,
12,
413,
26,
413,
12,
499,
26,
499,
12,
650,
26,
650,
93,
421,
199,
4710,
4070,
598,
17,
436,
598,
18,
787,
365,
25456,
530,
23667,
18312,
199,
16670,
14,
5444,
7313,
365,
465,
11924,
26,
199,
199,
6071,
598,
17,
275,
8484,
14,
515,
63,
2180,
8,
20,
12,
1218,
63,
4941,
29,
7343,
14,
23208,
1012,
199,
6071,
598,
18,
275,
8484,
14,
515,
63,
2180,
8,
20,
12,
1218,
63,
4941,
29,
7343,
14,
23208,
1012,
199,
6071,
3757,
22636,
275,
365,
25456,
19185,
14,
23208,
16073,
8,
39,
17,
12,
39,
18,
9,
199,
6071,
3757,
22636,
14,
374,
63,
374,
25456,
530,
342,
199,
549,
199,
199,
1341,
22636,
14,
4745,
14086,
314,
365,
25456,
19185,
4412,
687,
598,
17,
370,
598,
18,
14,
199,
199,
6071,
3757,
22636,
14,
4745,
199,
91,
16,
26,
378,
12,
413,
26,
413,
12,
499,
26,
499,
12,
650,
26,
650,
93,
4388,
199,
2610,
2180,
6596,
25456,
19185,
199,
777,
375,
199,
4578,
30629,
7142,
1463,
883,
506,
16353,
528,
1907,
1785,
3595,
314,
11150,
402,
314,
199,
16181,
5164,
12,
436,
781,
12005,
370,
824,
285,
2021,
652,
3063,
14,
199,
199,
607,
314,
812,
38,
18,
7142,
1463,
12,
282,
4412,
603,
365,
25097,
370,
506,
282,
3343,
13,
954,
2180,
199,
374,
25456,
19185,
17963,
603,
365,
376,
365,
25456,
19185,
3382,
598,
18,
436,
282,
23649,
402,
598,
17,
14,
199,
2719,
527,
12,
370,
14722,
626,
598,
17,
436,
598,
18,
787,
3343,
13,
954,
2180,
365,
25456,
530,
365,
370,
14722,
199,
9099,
282,
23649,
402,
598,
17,
365,
365,
25456,
530,
370,
598,
18,
14,
199,
199,
8632,
7142,
1463,
4440,
314,
21621,
283,
954,
2180,
365,
25456,
530,
7,
465,
315,
283,
39,
17,
1630,
199,
1397,
1172,
282,
23649,
365,
25456,
530,
370,
598,
18,
1370,
221,
22604,
675,
365,
465,
376,
315,
1503,
17050,
199,
509,
365,
25456,
530,
14,
221,
20227,
12,
370,
14722,
626,
598,
17,
436,
598,
18,
787,
23649,
365,
25456,
530,
199,
374,
370,
14722,
626,
282,
23649,
402,
598,
17,
365,
365,
25456,
530,
370,
598,
18,
14,
199,
199,
8694,
1183,
12,
314,
6707,
283,
954,
2180,
7,
883,
1172,
3663,
4615,
780,
14,
1010,
642,
199,
1100,
12,
283,
954,
2180,
7,
3544,
4910,
282,
283,
932,
13,
688,
3683,
68,
23649,
1370,
25155,
13,
688,
3683,
68,
199,
954,
2180,
365,
25456,
374,
706,
787,
440,
5370,
3748,
12,
1325,
1373,
1077,
506,
199,
461,
370,
5147,
314,
1104,
701,
10663,
675,
402,
8484,
14,
604,
63,
2180,
1252,
2104,
199,
954,
16670,
1314,
787,
440,
315,
16584,
12,
314,
6707,
283,
2106,
25456,
19185,
7,
365,
14388,
199,
1883,
283,
374,
25456,
19185,
1370,
13550,
12,
652,
365,
440,
3962,
370,
1104,
367,
199,
2106,
25456,
374,
706,
14,
199,
199,
15314,
598,
2687,
46,
12,
37,
9,
506,
282,
3343,
543,
282,
663,
402,
3380,
653,
436,
663,
402,
8207,
662,
14,
199,
199,
3917,
598,
7,
2687,
46,
297,
37,
358,
365,
282,
23649,
12,
2066,
26,
272,
653,
7,
365,
282,
10026,
402,
653,
272,
662,
7,
365,
282,
10026,
402,
662,
199,
199,
3917,
598,
7,
2687,
46,
297,
37,
358,
365,
282,
1031,
13,
688,
3683,
68,
23649,
12,
2066,
26,
272,
653,
7,
365,
282,
10026,
402,
653,
272,
662,
7,
365,
314,
10026,
402,
8207,
315,
662,
4668,
1958,
3380,
315,
653,
7,
199,
199,
3917,
598,
7,
2687,
46,
297,
37,
358,
365,
376,
6275,
13,
688,
3683,
68,
1007,
2587,
387,
72,
12,
2066,
26,
272,
653,
7,
365,
314,
10026,
402,
3380,
315,
653,
4048,
701,
8207,
315,
662,
7,
272,
662,
7,
365,
282,
10026,
402,
662,
199,
199,
15242,
199,
9460,
199,
59,
17,
61,
257,
30936,
13721,
510,
14,
7499,
2264,
416,
12,
510,
305,
392,
1895,
481,
24798,
4674,
12,
14243
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
1801,
1116,
10,
199,
32364,
18,
23823,
199,
1801,
1116,
10,
199,
199,
2493,
4514,
402,
812,
38,
18,
5563,
367,
3343,
365,
10128,
19185,
5343,
14,
199,
199,
1918,
3486,
270,
3217,
370,
675,
642,
859,
365,
370,
1240,
24313,
14,
374,
63,
374,
25456,
530,
1252,
199,
199,
3241,
293,
5199,
199,
4559,
199,
199,
1918,
11513,
16073,
436,
3757,
4578,
16073,
787,
17845,
367,
4877,
199,
16670,
503,
23667,
18312,
315,
282,
876,
27248,
30800,
14,
221,
961,
199,
25118,
4910,
282,
1104,
367,
376,
365,
25456,
19185,
12,
10617,
1163,
5920,
199,
1530,
2597,
3962,
14,
221,
2104,
2893,
12,
282,
23649,
402,
1373,
3343,
199,
2425,
506,
7923,
367,
365,
25456,
19185,
370,
282,
3499,
3343,
14,
199,
199,
14215,
365,
4224,
4799,
1847,
343,
27296,
1964,
305,
29524,
14,
2779,
365,
2597,
3962,
199,
475,
1104,
367,
32451,
1964,
305,
29524,
14,
7949,
305,
29524,
12,
2066,
12,
365,
3247,
199,
305,
314,
11461,
2401,
402,
314,
2877,
3423,
14,
199,
199,
1378,
2387,
282,
32451,
1104,
12,
314,
334,
1341,
9,
4578,
16073,
1021,
1077,
506,
199,
954,
28271,
12,
436,
314,
32451,
63,
771,
305,
29524,
342,
805,
1077,
506,
199,
27913,
14,
221,
4885,
849,
12,
314,
32451,
1964,
305,
29524,
805,
3544,
199,
5808,
715,
14,
221,
710,
7763,
402,
642,
365,
626,
19002,
787,
440,
199,
388,
2441,
581,
315,
314,
4877,
402,
598,
17,
436,
598,
18,
14,
199,
199,
22787,
199,
518,
199,
199,
4710,
4070,
598,
17,
436,
598,
18,
787,
365,
25456,
530,
18312,
14,
5444,
7313,
365,
465,
11924,
26,
199,
199,
6071,
687,
24313,
14,
24365,
492,
365,
25456,
19185,
199,
6071,
598,
17,
275,
8484,
14,
515,
63,
2180,
8,
20,
9,
199,
6071,
598,
18,
275,
8484,
14,
515,
63,
2180,
8,
20,
9,
199,
6071,
598,
45,
275,
365,
25456,
19185,
14,
4578,
16073,
8,
39,
17,
12,
39,
18,
9,
199,
6071,
598,
45,
14,
374,
63,
374,
25456,
530,
342,
199,
549,
199,
199,
22636,
14,
4745,
14086,
314,
365,
25456,
19185,
4412,
687,
598,
17,
370,
598,
18,
14,
199,
199,
6071,
598,
45,
14,
4745,
199,
91,
16,
26,
378,
12,
413,
26,
413,
12,
499,
26,
499,
12,
650,
26,
650,
93,
421,
199,
4710,
4070,
598,
17,
436,
598,
18,
787,
365,
25456,
530,
23667,
18312,
199,
16670,
14,
5444,
7313,
365,
465,
11924,
26,
199,
199,
6071,
598,
17,
275,
8484,
14,
515,
63,
2180,
8,
20,
12,
1218,
63,
4941,
29,
7343,
14,
23208,
1012,
199,
6071,
598,
18,
275,
8484,
14,
515,
63,
2180,
8,
20,
12,
1218,
63,
4941,
29,
7343,
14,
23208,
1012,
199,
6071,
3757,
22636,
275,
365,
25456,
19185,
14,
23208,
16073,
8,
39,
17,
12,
39,
18,
9,
199,
6071,
3757,
22636,
14,
374,
63,
374,
25456,
530,
342,
199,
549,
199,
199,
1341,
22636,
14,
4745,
14086,
314,
365,
25456,
19185,
4412,
687,
598,
17,
370,
598,
18,
14,
199,
199,
6071,
3757,
22636,
14,
4745,
199,
91,
16,
26,
378,
12,
413,
26,
413,
12,
499,
26,
499,
12,
650,
26,
650,
93,
4388,
199,
2610,
2180,
6596,
25456,
19185,
199,
777,
375,
199,
4578,
30629,
7142,
1463,
883,
506,
16353,
528,
1907,
1785,
3595,
314,
11150,
402,
314,
199,
16181,
5164,
12,
436,
781,
12005,
370,
824,
285,
2021,
652,
3063,
14,
199,
199,
607,
314,
812,
38,
18,
7142,
1463,
12,
282,
4412,
603,
365,
25097,
370,
506,
282,
3343,
13,
954,
2180,
199,
374,
25456,
19185,
17963,
603,
365,
376,
365,
25456,
19185,
3382,
598,
18,
436,
282,
23649,
402,
598,
17,
14,
199,
2719,
527,
12,
370,
14722,
626,
598,
17,
436,
598,
18,
787,
3343,
13,
954,
2180,
365,
25456,
530,
365,
370,
14722,
199,
9099,
282,
23649,
402,
598,
17,
365,
365,
25456,
530,
370,
598,
18,
14,
199,
199,
8632,
7142,
1463,
4440,
314,
21621,
283,
954,
2180,
365,
25456,
530,
7,
465,
315,
283,
39,
17,
1630,
199,
1397,
1172,
282,
23649,
365,
25456,
530,
370,
598,
18,
1370,
221,
22604,
675,
365,
465,
376,
315,
1503,
17050,
199,
509,
365,
25456,
530,
14,
221,
20227,
12,
370,
14722,
626,
598,
17,
436,
598,
18,
787,
23649,
365,
25456,
530,
199,
374,
370,
14722,
626,
282,
23649,
402,
598,
17,
365,
365,
25456,
530,
370,
598,
18,
14,
199,
199,
8694,
1183,
12,
314,
6707,
283,
954,
2180,
7,
883,
1172,
3663,
4615,
780,
14,
1010,
642,
199,
1100,
12,
283,
954,
2180,
7,
3544,
4910,
282,
283,
932,
13,
688,
3683,
68,
23649,
1370,
25155,
13,
688,
3683,
68,
199,
954,
2180,
365,
25456,
374,
706,
787,
440,
5370,
3748,
12,
1325,
1373,
1077,
506,
199,
461,
370,
5147,
314,
1104,
701,
10663,
675,
402,
8484,
14,
604,
63,
2180,
1252,
2104,
199,
954,
16670,
1314,
787,
440,
315,
16584,
12,
314,
6707,
283,
2106,
25456,
19185,
7,
365,
14388,
199,
1883,
283,
374,
25456,
19185,
1370,
13550,
12,
652,
365,
440,
3962,
370,
1104,
367,
199,
2106,
25456,
374,
706,
14,
199,
199,
15314,
598,
2687,
46,
12,
37,
9,
506,
282,
3343,
543,
282,
663,
402,
3380,
653,
436,
663,
402,
8207,
662,
14,
199,
199,
3917,
598,
7,
2687,
46,
297,
37,
358,
365,
282,
23649,
12,
2066,
26,
272,
653,
7,
365,
282,
10026,
402,
653,
272,
662,
7,
365,
282,
10026,
402,
662,
199,
199,
3917,
598,
7,
2687,
46,
297,
37,
358,
365,
282,
1031,
13,
688,
3683,
68,
23649,
12,
2066,
26,
272,
653,
7,
365,
282,
10026,
402,
653,
272,
662,
7,
365,
314,
10026,
402,
8207,
315,
662,
4668,
1958,
3380,
315,
653,
7,
199,
199,
3917,
598,
7,
2687,
46,
297,
37,
358,
365,
376,
6275,
13,
688,
3683,
68,
1007,
2587,
387,
72,
12,
2066,
26,
272,
653,
7,
365,
314,
10026,
402,
3380,
315,
653,
4048,
701,
8207,
315,
662,
7,
272,
662,
7,
365,
282,
10026,
402,
662,
199,
199,
15242,
199,
9460,
199,
59,
17,
61,
257,
30936,
13721,
510,
14,
7499,
2264,
416,
12,
510,
305,
392,
1895,
481,
24798,
4674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
1,
1,
1,
1,
1
] |
akshmakov/Dolfin-Fijee-Fork
|
site-packages/dolfin/mesh/meshes.py
|
1
|
2144
|
"This module provides a simple Python wrapper for the SWIG-generated Mesh class"
# Copyright (C) 2012-2014 Anders Logg
#
# This file is part of DOLFIN.
#
# DOLFIN 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 3 of the License, or
# (at your option) any later version.
#
# DOLFIN 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 DOLFIN. If not, see <http://www.gnu.org/licenses/>.
#
# Modified by Marie E. Rognes (meg@simula.no)
# Modified by Martin S. Alnaes (martinal@simula.no) 2014
__all__ = []
# Import SWIG-generated extension module (DOLFIN C++)
import dolfin.cpp as cpp
# Replacement constructor for Mesh class. We cannot create a Python
# subclass of cpp.Mesh since then isinstance(UnitSquare, Mesh) would
# not be true.
def __init__(self, *args, **kwargs):
"""Create a mesh from a filename or a geometry.
A mesh may be created from a given filename, which should contain
mesh data stored in DOLFIN XML format:
.. code-block:: python
mesh = Mesh("mesh.xml")
An empty mesh may be created as follows:
.. code-block:: python
mesh = Mesh()
A copy of a mesh may be created as follows:
.. code-block:: python
mesh_copy = Mesh(mesh)
A mesh may also be created from a CSG geometry and a resolution:
.. code-block:: python
mesh = Mesh(geometry, resolution)
"""
# Reuse C++ doc-string too
__doc__ = cpp.Mesh.__doc__
# Initialize base class
cpp.Mesh.__cppinit__(self, *args, **kwargs)
# Change mesh constructor
cpp.Mesh.__cppinit__ = cpp.Mesh.__init__
cpp.Mesh.__init__ = __init__
# Attach ipython notebook svg rendering function for 1D and 2D meshes
from dolfin.mesh.svgtools import mesh2svg
cpp.Mesh._repr_svg_ = mesh2svg
|
gpl-3.0
|
[
2,
2765,
859,
6571,
282,
3486,
2018,
4975,
367,
314,
26480,
13,
10176,
603,
10613,
1021,
2,
199,
199,
3,
1898,
334,
35,
9,
6029,
13,
7280,
1626,
7735,
5297,
71,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28701,
17383,
14,
199,
3,
199,
3,
28701,
17383,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
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,
28701,
17383,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
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,
844,
199,
3,
3180,
543,
28701,
17383,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
22016,
701,
603,
759,
69,
662,
14,
6848,
784,
397,
334,
32177,
32,
13819,
65,
14,
889,
9,
199,
3,
22016,
701,
603,
26788,
428,
14,
4580,
3540,
397,
334,
77,
580,
1582,
32,
13819,
65,
14,
889,
9,
6927,
199,
199,
363,
452,
363,
275,
942,
199,
199,
3,
3161,
26480,
13,
10176,
3329,
859,
334,
1649,
15965,
568,
445,
25659,
199,
646,
886,
276,
262,
14,
5910,
465,
7246,
199,
199,
3,
14402,
434,
3787,
367,
603,
10613,
1021,
14,
2136,
3913,
1218,
282,
2018,
199,
3,
5516,
402,
7246,
14,
12241,
3967,
2066,
1228,
8,
5072,
23373,
12,
603,
10613,
9,
3955,
199,
3,
440,
506,
2549,
14,
199,
199,
318,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
408,
2499,
282,
9364,
687,
282,
1788,
503,
282,
3400,
14,
339,
437,
9364,
1443,
506,
2737,
687,
282,
1627,
1788,
12,
1314,
1077,
1395,
272,
9364,
666,
5489,
315,
28701,
17383,
4692,
1475,
26,
339,
2508,
1233,
13,
1457,
447,
2366,
398,
9364,
275,
603,
10613,
480,
6480,
14,
1652,
531,
339,
1626,
2701,
9364,
1443,
506,
2737,
465,
11924,
26,
339,
2508,
1233,
13,
1457,
447,
2366,
398,
9364,
275,
603,
10613,
342,
339,
437,
1331,
402,
282,
9364,
1443,
506,
2737,
465,
11924,
26,
339,
2508,
1233,
13,
1457,
447,
2366,
398,
9364,
63,
1574,
275,
603,
10613,
8,
6480,
9,
339,
437,
9364,
1443,
2597,
506,
2737,
687,
282,
445,
4254,
3400,
436,
282,
12401,
26,
339,
2508,
1233,
13,
1457,
447,
2366,
398,
9364,
275,
603,
10613,
8,
7660,
12,
12401,
9,
339,
408,
339,
327,
799,
1180,
445,
4176,
1382,
13,
875,
4634,
272,
636,
1301,
363,
275,
7246,
14,
12241,
855,
1301,
363,
339,
327,
11578,
1300,
1021,
272,
7246,
14,
12241,
855,
5910,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
9,
199,
199,
3,
7743,
9364,
3787,
199,
5910,
14,
12241,
855,
5910,
826,
363,
275,
7246,
14,
12241,
855,
826,
363,
199,
5910,
14,
12241,
855,
826,
363,
275,
636,
826,
363,
199,
199,
3,
21328,
284,
1548,
20751,
21218,
14066,
805,
367,
413,
36,
436,
499,
36,
9364,
397,
199,
504,
886,
276,
262,
14,
6480,
14,
10273,
2537,
492,
9364,
18,
10273,
199,
5910,
14,
12241,
423,
2722,
63,
10273,
63,
275,
9364,
18,
10273,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2765,
859,
6571,
282,
3486,
2018,
4975,
367,
314,
26480,
13,
10176,
603,
10613,
1021,
2,
199,
199,
3,
1898,
334,
35,
9,
6029,
13,
7280,
1626,
7735,
5297,
71,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28701,
17383,
14,
199,
3,
199,
3,
28701,
17383,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
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,
28701,
17383,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
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,
844,
199,
3,
3180,
543,
28701,
17383,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
22016,
701,
603,
759,
69,
662,
14,
6848,
784,
397,
334,
32177,
32,
13819,
65,
14,
889,
9,
199,
3,
22016,
701,
603,
26788,
428,
14,
4580,
3540,
397,
334,
77,
580,
1582,
32,
13819,
65,
14,
889,
9,
6927,
199,
199,
363,
452,
363,
275,
942,
199,
199,
3,
3161,
26480,
13,
10176,
3329,
859,
334,
1649,
15965,
568,
445,
25659,
199,
646,
886,
276,
262,
14,
5910,
465,
7246,
199,
199,
3,
14402,
434,
3787,
367,
603,
10613,
1021,
14,
2136,
3913,
1218,
282,
2018,
199,
3,
5516,
402,
7246,
14,
12241,
3967,
2066,
1228,
8,
5072,
23373,
12,
603,
10613,
9,
3955,
199,
3,
440,
506,
2549,
14,
199,
199,
318,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
408,
2499,
282,
9364,
687,
282,
1788,
503,
282,
3400,
14,
339,
437,
9364,
1443,
506,
2737,
687,
282,
1627,
1788,
12,
1314,
1077,
1395,
272,
9364,
666,
5489,
315,
28701,
17383,
4692,
1475,
26,
339,
2508,
1233,
13,
1457,
447,
2366,
398,
9364,
275,
603,
10613,
480,
6480,
14,
1652,
531,
339,
1626,
2701,
9364,
1443,
506,
2737,
465,
11924,
26,
339,
2508,
1233,
13,
1457,
447,
2366,
398,
9364,
275,
603,
10613,
342,
339,
437,
1331,
402,
282,
9364,
1443,
506,
2737,
465,
11924,
26,
339,
2508,
1233,
13,
1457,
447,
2366,
398,
9364,
63,
1574,
275,
603,
10613,
8,
6480,
9,
339,
437,
9364,
1443,
2597,
506,
2737,
687,
282,
445,
4254,
3400,
436,
282,
12401,
26,
339,
2508,
1233,
13,
1457,
447,
2366,
398,
9364,
275,
603,
10613,
8,
7660,
12,
12401,
9,
339,
408,
339,
327,
799,
1180,
445,
4176,
1382,
13,
875,
4634,
272,
636,
1301,
363,
275,
7246,
14,
12241,
855,
1301,
363,
339,
327,
11578,
1300,
1021,
272,
7246,
14,
12241,
855,
5910,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
9,
199,
199,
3,
7743,
9364,
3787,
199,
5910,
14,
12241,
855,
5910,
826,
363,
275,
7246,
14,
12241,
855,
826,
363,
199,
5910,
14,
12241,
855,
826,
363,
275,
636,
826,
363,
199,
199,
3,
21328,
284,
1548,
20751,
21218,
14066,
805,
367,
413,
36,
436,
499,
36,
9364,
397,
199,
504,
886,
276,
262,
14,
6480,
14,
10273,
2537,
492,
9364,
18,
10273,
199,
5910,
14,
12241,
423,
2722,
63,
10273,
63,
275,
9364,
18,
10273,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
lunafeng/django
|
tests/basic/tests.py
|
117
|
29910
|
from __future__ import unicode_literals
import threading
import warnings
from datetime import datetime, timedelta
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
from django.db import DEFAULT_DB_ALIAS, DatabaseError, connections
from django.db.models.fields import Field
from django.db.models.fields.related import ForeignObjectRel
from django.db.models.manager import BaseManager
from django.db.models.query import EmptyQuerySet, QuerySet
from django.test import (
SimpleTestCase, TestCase, TransactionTestCase, skipIfDBFeature,
skipUnlessDBFeature,
)
from django.utils import six
from django.utils.translation import ugettext_lazy
from .models import Article, ArticleSelectOnSave, SelfRef
class ModelInstanceCreationTests(TestCase):
def test_object_is_not_written_to_database_until_save_was_called(self):
a = Article(
id=None,
headline='Area man programs in Python',
pub_date=datetime(2005, 7, 28),
)
self.assertIsNone(a.id)
self.assertEqual(Article.objects.all().count(), 0)
# Save it into the database. You have to call save() explicitly.
a.save()
self.assertIsNotNone(a.id)
self.assertEqual(Article.objects.all().count(), 1)
def test_can_initialize_model_instance_using_positional_arguments(self):
"""
You can initialize a model instance using positional arguments,
which should match the field order as defined in the model.
"""
a = Article(None, 'Second article', datetime(2005, 7, 29))
a.save()
self.assertEqual(a.headline, 'Second article')
self.assertEqual(a.pub_date, datetime(2005, 7, 29, 0, 0))
def test_can_create_instance_using_kwargs(self):
a = Article(
id=None,
headline='Third article',
pub_date=datetime(2005, 7, 30),
)
a.save()
self.assertEqual(a.headline, 'Third article')
self.assertEqual(a.pub_date, datetime(2005, 7, 30, 0, 0))
def test_autofields_generate_different_values_for_each_instance(self):
a1 = Article.objects.create(headline='First', pub_date=datetime(2005, 7, 30, 0, 0))
a2 = Article.objects.create(headline='First', pub_date=datetime(2005, 7, 30, 0, 0))
a3 = Article.objects.create(headline='First', pub_date=datetime(2005, 7, 30, 0, 0))
self.assertNotEqual(a3.id, a1.id)
self.assertNotEqual(a3.id, a2.id)
def test_can_mix_and_match_position_and_kwargs(self):
# You can also mix and match position and keyword arguments, but
# be sure not to duplicate field information.
a = Article(None, 'Fourth article', pub_date=datetime(2005, 7, 31))
a.save()
self.assertEqual(a.headline, 'Fourth article')
def test_cannot_create_instance_with_invalid_kwargs(self):
six.assertRaisesRegex(
self,
TypeError,
"'foo' is an invalid keyword argument for this function",
Article,
id=None,
headline='Some headline',
pub_date=datetime(2005, 7, 31),
foo='bar',
)
def test_can_leave_off_value_for_autofield_and_it_gets_value_on_save(self):
"""
You can leave off the value for an AutoField when creating an
object, because it'll get filled in automatically when you save().
"""
a = Article(headline='Article 5', pub_date=datetime(2005, 7, 31))
a.save()
self.assertEqual(a.headline, 'Article 5')
self.assertNotEqual(a.id, None)
def test_leaving_off_a_field_with_default_set_the_default_will_be_saved(self):
a = Article(pub_date=datetime(2005, 7, 31))
a.save()
self.assertEqual(a.headline, 'Default headline')
def test_for_datetimefields_saves_as_much_precision_as_was_given(self):
"""as much precision in *seconds*"""
a1 = Article(
headline='Article 7',
pub_date=datetime(2005, 7, 31, 12, 30),
)
a1.save()
self.assertEqual(Article.objects.get(id__exact=a1.id).pub_date,
datetime(2005, 7, 31, 12, 30))
a2 = Article(
headline='Article 8',
pub_date=datetime(2005, 7, 31, 12, 30, 45),
)
a2.save()
self.assertEqual(Article.objects.get(id__exact=a2.id).pub_date,
datetime(2005, 7, 31, 12, 30, 45))
def test_saving_an_object_again_does_not_create_a_new_object(self):
a = Article(headline='original', pub_date=datetime(2014, 5, 16))
a.save()
current_id = a.id
a.save()
self.assertEqual(a.id, current_id)
a.headline = 'Updated headline'
a.save()
self.assertEqual(a.id, current_id)
def test_querysets_checking_for_membership(self):
headlines = [
'Area man programs in Python', 'Second article', 'Third article']
some_pub_date = datetime(2014, 5, 16, 12, 1)
for headline in headlines:
Article(headline=headline, pub_date=some_pub_date).save()
a = Article(headline='Some headline', pub_date=some_pub_date)
a.save()
# You can use 'in' to test for membership...
self.assertIn(a, Article.objects.all())
# ... but there will often be more efficient ways if that is all you need:
self.assertTrue(Article.objects.filter(id=a.id).exists())
class ModelTest(TestCase):
def test_objects_attribute_is_only_available_on_the_class_itself(self):
six.assertRaisesRegex(
self,
AttributeError,
"Manager isn't accessible via Article instances",
getattr,
Article(),
"objects",
)
self.assertFalse(hasattr(Article(), 'objects'))
self.assertTrue(hasattr(Article, 'objects'))
def test_queryset_delete_removes_all_items_in_that_queryset(self):
headlines = [
'An article', 'Article One', 'Amazing article', 'Boring article']
some_pub_date = datetime(2014, 5, 16, 12, 1)
for headline in headlines:
Article(headline=headline, pub_date=some_pub_date).save()
self.assertQuerysetEqual(Article.objects.all().order_by('headline'),
["<Article: Amazing article>",
"<Article: An article>",
"<Article: Article One>",
"<Article: Boring article>"])
Article.objects.filter(headline__startswith='A').delete()
self.assertQuerysetEqual(Article.objects.all().order_by('headline'),
["<Article: Boring article>"])
def test_not_equal_and_equal_operators_behave_as_expected_on_instances(self):
some_pub_date = datetime(2014, 5, 16, 12, 1)
a1 = Article.objects.create(headline='First', pub_date=some_pub_date)
a2 = Article.objects.create(headline='Second', pub_date=some_pub_date)
self.assertNotEqual(a1, a2)
self.assertEqual(a1, Article.objects.get(id__exact=a1.id))
self.assertNotEqual(Article.objects.get(id__exact=a1.id), Article.objects.get(id__exact=a2.id))
@skipUnlessDBFeature('supports_microsecond_precision')
def test_microsecond_precision(self):
# In PostgreSQL, microsecond-level precision is available.
a9 = Article(
headline='Article 9',
pub_date=datetime(2005, 7, 31, 12, 30, 45, 180),
)
a9.save()
self.assertEqual(Article.objects.get(pk=a9.pk).pub_date,
datetime(2005, 7, 31, 12, 30, 45, 180))
@skipIfDBFeature('supports_microsecond_precision')
def test_microsecond_precision_not_supported(self):
# In MySQL, microsecond-level precision isn't always available. You'll
# lose microsecond-level precision once the data is saved.
a9 = Article(
headline='Article 9',
pub_date=datetime(2005, 7, 31, 12, 30, 45, 180),
)
a9.save()
self.assertEqual(
Article.objects.get(id__exact=a9.id).pub_date,
datetime(2005, 7, 31, 12, 30, 45),
)
@skipIfDBFeature('supports_microsecond_precision')
def test_microsecond_precision_not_supported_edge_case(self):
# In MySQL, microsecond-level precision isn't always available. You'll
# lose microsecond-level precision once the data is saved.
a = Article.objects.create(
headline='Article',
pub_date=datetime(2008, 12, 31, 23, 59, 59, 999999),
)
self.assertEqual(
Article.objects.get(pk=a.pk).pub_date,
datetime(2008, 12, 31, 23, 59, 59),
)
def test_manually_specify_primary_key(self):
# You can manually specify the primary key when creating a new object.
a101 = Article(
id=101,
headline='Article 101',
pub_date=datetime(2005, 7, 31, 12, 30, 45),
)
a101.save()
a101 = Article.objects.get(pk=101)
self.assertEqual(a101.headline, 'Article 101')
def test_create_method(self):
# You can create saved objects in a single step
a10 = Article.objects.create(
headline="Article 10",
pub_date=datetime(2005, 7, 31, 12, 30, 45),
)
self.assertEqual(Article.objects.get(headline="Article 10"), a10)
def test_year_lookup_edge_case(self):
# Edge-case test: A year lookup should retrieve all objects in
# the given year, including Jan. 1 and Dec. 31.
Article.objects.create(
headline='Article 11',
pub_date=datetime(2008, 1, 1),
)
Article.objects.create(
headline='Article 12',
pub_date=datetime(2008, 12, 31, 23, 59, 59, 999999),
)
self.assertQuerysetEqual(Article.objects.filter(pub_date__year=2008),
["<Article: Article 11>", "<Article: Article 12>"])
def test_unicode_data(self):
# Unicode data works, too.
a = Article(
headline='\u6797\u539f \u3081\u3050\u307f',
pub_date=datetime(2005, 7, 28),
)
a.save()
self.assertEqual(Article.objects.get(pk=a.id).headline,
'\u6797\u539f \u3081\u3050\u307f')
def test_hash_function(self):
# Model instances have a hash function, so they can be used in sets
# or as dictionary keys. Two models compare as equal if their primary
# keys are equal.
a10 = Article.objects.create(
headline="Article 10",
pub_date=datetime(2005, 7, 31, 12, 30, 45),
)
a11 = Article.objects.create(
headline='Article 11',
pub_date=datetime(2008, 1, 1),
)
a12 = Article.objects.create(
headline='Article 12',
pub_date=datetime(2008, 12, 31, 23, 59, 59, 999999),
)
s = {a10, a11, a12}
self.assertIn(Article.objects.get(headline='Article 11'), s)
def test_field_ordering(self):
"""
Field instances have a `__lt__` comparison function to define an
ordering based on their creation. Prior to #17851 this ordering
comparison relied on the now unsupported `__cmp__` and was assuming
compared objects were both Field instances raising `AttributeError`
when it should have returned `NotImplemented`.
"""
f1 = Field()
f2 = Field(auto_created=True)
f3 = Field()
self.assertLess(f2, f1)
self.assertGreater(f3, f1)
self.assertIsNotNone(f1)
self.assertNotIn(f2, (None, 1, ''))
def test_extra_method_select_argument_with_dashes_and_values(self):
# The 'select' argument to extra() supports names with dashes in
# them, as long as you use values().
Article.objects.create(
headline="Article 10",
pub_date=datetime(2005, 7, 31, 12, 30, 45),
)
Article.objects.create(
headline='Article 11',
pub_date=datetime(2008, 1, 1),
)
Article.objects.create(
headline='Article 12',
pub_date=datetime(2008, 12, 31, 23, 59, 59, 999999),
)
dicts = Article.objects.filter(
pub_date__year=2008).extra(
select={'dashed-value': '1'}).values('headline', 'dashed-value')
self.assertEqual([sorted(d.items()) for d in dicts],
[[('dashed-value', 1), ('headline', 'Article 11')], [('dashed-value', 1), ('headline', 'Article 12')]])
def test_extra_method_select_argument_with_dashes(self):
# If you use 'select' with extra() and names containing dashes on a
# query that's *not* a values() query, those extra 'select' values
# will silently be ignored.
Article.objects.create(
headline="Article 10",
pub_date=datetime(2005, 7, 31, 12, 30, 45),
)
Article.objects.create(
headline='Article 11',
pub_date=datetime(2008, 1, 1),
)
Article.objects.create(
headline='Article 12',
pub_date=datetime(2008, 12, 31, 23, 59, 59, 999999),
)
articles = Article.objects.filter(
pub_date__year=2008).extra(select={'dashed-value': '1', 'undashedvalue': '2'})
self.assertEqual(articles[0].undashedvalue, 2)
def test_create_relation_with_ugettext_lazy(self):
"""
Test that ugettext_lazy objects work when saving model instances
through various methods. Refs #10498.
"""
notlazy = 'test'
lazy = ugettext_lazy(notlazy)
Article.objects.create(headline=lazy, pub_date=datetime.now())
article = Article.objects.get()
self.assertEqual(article.headline, notlazy)
# test that assign + save works with Promise objects
article.headline = lazy
article.save()
self.assertEqual(article.headline, notlazy)
# test .update()
Article.objects.update(headline=lazy)
article = Article.objects.get()
self.assertEqual(article.headline, notlazy)
# still test bulk_create()
Article.objects.all().delete()
Article.objects.bulk_create([Article(headline=lazy, pub_date=datetime.now())])
article = Article.objects.get()
self.assertEqual(article.headline, notlazy)
def test_emptyqs(self):
# Can't be instantiated
with self.assertRaises(TypeError):
EmptyQuerySet()
self.assertIsInstance(Article.objects.none(), EmptyQuerySet)
def test_emptyqs_values(self):
# test for #15959
Article.objects.create(headline='foo', pub_date=datetime.now())
with self.assertNumQueries(0):
qs = Article.objects.none().values_list('pk')
self.assertIsInstance(qs, EmptyQuerySet)
self.assertEqual(len(qs), 0)
def test_emptyqs_customqs(self):
# A hacky test for custom QuerySet subclass - refs #17271
Article.objects.create(headline='foo', pub_date=datetime.now())
class CustomQuerySet(QuerySet):
def do_something(self):
return 'did something'
qs = Article.objects.all()
qs.__class__ = CustomQuerySet
qs = qs.none()
with self.assertNumQueries(0):
self.assertEqual(len(qs), 0)
self.assertIsInstance(qs, EmptyQuerySet)
self.assertEqual(qs.do_something(), 'did something')
def test_emptyqs_values_order(self):
# Tests for ticket #17712
Article.objects.create(headline='foo', pub_date=datetime.now())
with self.assertNumQueries(0):
self.assertEqual(len(Article.objects.none().values_list('id').order_by('id')), 0)
with self.assertNumQueries(0):
self.assertEqual(len(Article.objects.none().filter(
id__in=Article.objects.values_list('id', flat=True))), 0)
@skipUnlessDBFeature('can_distinct_on_fields')
def test_emptyqs_distinct(self):
# Tests for #19426
Article.objects.create(headline='foo', pub_date=datetime.now())
with self.assertNumQueries(0):
self.assertEqual(len(Article.objects.none().distinct('headline', 'pub_date')), 0)
def test_ticket_20278(self):
sr = SelfRef.objects.create()
with self.assertRaises(ObjectDoesNotExist):
SelfRef.objects.get(selfref=sr)
def test_eq(self):
self.assertEqual(Article(id=1), Article(id=1))
self.assertNotEqual(Article(id=1), object())
self.assertNotEqual(object(), Article(id=1))
a = Article()
self.assertEqual(a, a)
self.assertNotEqual(Article(), a)
def test_hash(self):
# Value based on PK
self.assertEqual(hash(Article(id=1)), hash(1))
with self.assertRaises(TypeError):
# No PK value -> unhashable (because save() would then change
# hash)
hash(Article())
class ModelLookupTest(TestCase):
def setUp(self):
# Create an Article.
self.a = Article(
id=None,
headline='Area woman programs in Python',
pub_date=datetime(2005, 7, 28),
)
# Save it into the database. You have to call save() explicitly.
self.a.save()
def test_all_lookup(self):
# Change values by changing the attributes, then calling save().
self.a.headline = 'Area man programs in Python'
self.a.save()
# Article.objects.all() returns all the articles in the database.
self.assertQuerysetEqual(Article.objects.all(),
['<Article: Area man programs in Python>'])
def test_rich_lookup(self):
# Django provides a rich database lookup API.
self.assertEqual(Article.objects.get(id__exact=self.a.id), self.a)
self.assertEqual(Article.objects.get(headline__startswith='Area woman'), self.a)
self.assertEqual(Article.objects.get(pub_date__year=2005), self.a)
self.assertEqual(Article.objects.get(pub_date__year=2005, pub_date__month=7), self.a)
self.assertEqual(Article.objects.get(pub_date__year=2005, pub_date__month=7, pub_date__day=28), self.a)
self.assertEqual(Article.objects.get(pub_date__week_day=5), self.a)
def test_equal_lookup(self):
# The "__exact" lookup type can be omitted, as a shortcut.
self.assertEqual(Article.objects.get(id=self.a.id), self.a)
self.assertEqual(Article.objects.get(headline='Area woman programs in Python'), self.a)
self.assertQuerysetEqual(
Article.objects.filter(pub_date__year=2005),
['<Article: Area woman programs in Python>'],
)
self.assertQuerysetEqual(
Article.objects.filter(pub_date__year=2004),
[],
)
self.assertQuerysetEqual(
Article.objects.filter(pub_date__year=2005, pub_date__month=7),
['<Article: Area woman programs in Python>'],
)
self.assertQuerysetEqual(
Article.objects.filter(pub_date__week_day=5),
['<Article: Area woman programs in Python>'],
)
self.assertQuerysetEqual(
Article.objects.filter(pub_date__week_day=6),
[],
)
def test_does_not_exist(self):
# Django raises an Article.DoesNotExist exception for get() if the
# parameters don't match any object.
six.assertRaisesRegex(
self,
ObjectDoesNotExist,
"Article matching query does not exist.",
Article.objects.get,
id__exact=2000,
)
# To avoid dict-ordering related errors check only one lookup
# in single assert.
self.assertRaises(
ObjectDoesNotExist,
Article.objects.get,
pub_date__year=2005,
pub_date__month=8,
)
six.assertRaisesRegex(
self,
ObjectDoesNotExist,
"Article matching query does not exist.",
Article.objects.get,
pub_date__week_day=6,
)
def test_lookup_by_primary_key(self):
# Lookup by a primary key is the most common case, so Django
# provides a shortcut for primary-key exact lookups.
# The following is identical to articles.get(id=a.id).
self.assertEqual(Article.objects.get(pk=self.a.id), self.a)
# pk can be used as a shortcut for the primary key name in any query.
self.assertQuerysetEqual(Article.objects.filter(pk__in=[self.a.id]),
["<Article: Area woman programs in Python>"])
# Model instances of the same type and same ID are considered equal.
a = Article.objects.get(pk=self.a.id)
b = Article.objects.get(pk=self.a.id)
self.assertEqual(a, b)
def test_too_many(self):
# Create a very similar object
a = Article(
id=None,
headline='Area man programs in Python',
pub_date=datetime(2005, 7, 28),
)
a.save()
self.assertEqual(Article.objects.count(), 2)
# Django raises an Article.MultipleObjectsReturned exception if the
# lookup matches more than one object
six.assertRaisesRegex(
self,
MultipleObjectsReturned,
"get\(\) returned more than one Article -- it returned 2!",
Article.objects.get,
headline__startswith='Area',
)
six.assertRaisesRegex(
self,
MultipleObjectsReturned,
"get\(\) returned more than one Article -- it returned 2!",
Article.objects.get,
pub_date__year=2005,
)
six.assertRaisesRegex(
self,
MultipleObjectsReturned,
"get\(\) returned more than one Article -- it returned 2!",
Article.objects.get,
pub_date__year=2005,
pub_date__month=7,
)
class ConcurrentSaveTests(TransactionTestCase):
available_apps = ['basic']
@skipUnlessDBFeature('test_db_allows_multiple_connections')
def test_concurrent_delete_with_save(self):
"""
Test fetching, deleting and finally saving an object - we should get
an insert in this case.
"""
a = Article.objects.create(headline='foo', pub_date=datetime.now())
exceptions = []
def deleter():
try:
# Do not delete a directly - doing so alters its state.
Article.objects.filter(pk=a.pk).delete()
except Exception as e:
exceptions.append(e)
finally:
connections[DEFAULT_DB_ALIAS].close()
self.assertEqual(len(exceptions), 0)
t = threading.Thread(target=deleter)
t.start()
t.join()
a.save()
self.assertEqual(Article.objects.get(pk=a.pk).headline, 'foo')
class ManagerTest(SimpleTestCase):
QUERYSET_PROXY_METHODS = [
'none',
'count',
'dates',
'datetimes',
'distinct',
'extra',
'get',
'get_or_create',
'update_or_create',
'create',
'bulk_create',
'filter',
'aggregate',
'annotate',
'complex_filter',
'exclude',
'in_bulk',
'iterator',
'earliest',
'latest',
'first',
'last',
'order_by',
'select_for_update',
'select_related',
'prefetch_related',
'values',
'values_list',
'update',
'reverse',
'defer',
'only',
'using',
'exists',
'_insert',
'_update',
'raw',
]
def test_manager_methods(self):
"""
This test ensures that the correct set of methods from `QuerySet`
are copied onto `Manager`.
It's particularly useful to prevent accidentally leaking new methods
into `Manager`. New `QuerySet` methods that should also be copied onto
`Manager` will need to be added to `ManagerTest.QUERYSET_PROXY_METHODS`.
"""
self.assertEqual(
sorted(BaseManager._get_queryset_methods(QuerySet).keys()),
sorted(self.QUERYSET_PROXY_METHODS),
)
class SelectOnSaveTests(TestCase):
def test_select_on_save(self):
a1 = Article.objects.create(pub_date=datetime.now())
with self.assertNumQueries(1):
a1.save()
asos = ArticleSelectOnSave.objects.create(pub_date=datetime.now())
with self.assertNumQueries(2):
asos.save()
with self.assertNumQueries(1):
asos.save(force_update=True)
Article.objects.all().delete()
with self.assertRaises(DatabaseError):
with self.assertNumQueries(1):
asos.save(force_update=True)
def test_select_on_save_lying_update(self):
"""
Test that select_on_save works correctly if the database
doesn't return correct information about matched rows from
UPDATE.
"""
# Change the manager to not return "row matched" for update().
# We are going to change the Article's _base_manager class
# dynamically. This is a bit of a hack, but it seems hard to
# test this properly otherwise. Article's manager, because
# proxy models use their parent model's _base_manager.
orig_class = Article._base_manager.__class__
class FakeQuerySet(QuerySet):
# Make sure the _update method below is in fact called.
called = False
def _update(self, *args, **kwargs):
FakeQuerySet.called = True
super(FakeQuerySet, self)._update(*args, **kwargs)
return 0
class FakeManager(orig_class):
def get_queryset(self):
return FakeQuerySet(self.model)
try:
Article._base_manager.__class__ = FakeManager
asos = ArticleSelectOnSave.objects.create(pub_date=datetime.now())
with self.assertNumQueries(3):
asos.save()
self.assertTrue(FakeQuerySet.called)
# This is not wanted behavior, but this is how Django has always
# behaved for databases that do not return correct information
# about matched rows for UPDATE.
with self.assertRaises(DatabaseError):
asos.save(force_update=True)
with self.assertRaises(DatabaseError):
asos.save(update_fields=['pub_date'])
finally:
Article._base_manager.__class__ = orig_class
class ModelRefreshTests(TestCase):
def _truncate_ms(self, val):
# MySQL < 5.6.4 removes microseconds from the datetimes which can cause
# problems when comparing the original value to that loaded from DB
return val - timedelta(microseconds=val.microsecond)
def test_refresh(self):
a = Article.objects.create(pub_date=self._truncate_ms(datetime.now()))
Article.objects.create(pub_date=self._truncate_ms(datetime.now()))
Article.objects.filter(pk=a.pk).update(headline='new headline')
with self.assertNumQueries(1):
a.refresh_from_db()
self.assertEqual(a.headline, 'new headline')
orig_pub_date = a.pub_date
new_pub_date = a.pub_date + timedelta(10)
Article.objects.update(headline='new headline 2', pub_date=new_pub_date)
with self.assertNumQueries(1):
a.refresh_from_db(fields=['headline'])
self.assertEqual(a.headline, 'new headline 2')
self.assertEqual(a.pub_date, orig_pub_date)
with self.assertNumQueries(1):
a.refresh_from_db()
self.assertEqual(a.pub_date, new_pub_date)
def test_refresh_fk(self):
s1 = SelfRef.objects.create()
s2 = SelfRef.objects.create()
s3 = SelfRef.objects.create(selfref=s1)
s3_copy = SelfRef.objects.get(pk=s3.pk)
s3_copy.selfref.touched = True
s3.selfref = s2
s3.save()
with self.assertNumQueries(1):
s3_copy.refresh_from_db()
with self.assertNumQueries(1):
# The old related instance was thrown away (the selfref_id has
# changed). It needs to be reloaded on access, so one query
# executed.
self.assertFalse(hasattr(s3_copy.selfref, 'touched'))
self.assertEqual(s3_copy.selfref, s2)
def test_refresh_null_fk(self):
s1 = SelfRef.objects.create()
s2 = SelfRef.objects.create(selfref=s1)
s2.selfref = None
s2.refresh_from_db()
self.assertEqual(s2.selfref, s1)
def test_refresh_unsaved(self):
pub_date = self._truncate_ms(datetime.now())
a = Article.objects.create(pub_date=pub_date)
a2 = Article(id=a.pk)
with self.assertNumQueries(1):
a2.refresh_from_db()
self.assertEqual(a2.pub_date, pub_date)
self.assertEqual(a2._state.db, "default")
def test_refresh_no_fields(self):
a = Article.objects.create(pub_date=self._truncate_ms(datetime.now()))
with self.assertNumQueries(0):
a.refresh_from_db(fields=[])
class TestRelatedObjectDeprecation(SimpleTestCase):
def test_field_related_deprecation(self):
field = SelfRef._meta.get_field('selfref')
with warnings.catch_warnings(record=True) as warns:
warnings.simplefilter('always')
self.assertIsInstance(field.related, ForeignObjectRel)
self.assertEqual(len(warns), 1)
self.assertEqual(
str(warns.pop().message),
'Usage of field.related has been deprecated. Use field.remote_field instead.'
)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
5796,
199,
646,
3598,
199,
504,
2197,
492,
2197,
12,
6871,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
14326,
11188,
28239,
12,
24803,
199,
504,
1639,
14,
697,
492,
6186,
63,
2846,
63,
12644,
12,
27728,
12,
6947,
199,
504,
1639,
14,
697,
14,
992,
14,
955,
492,
5024,
199,
504,
1639,
14,
697,
14,
992,
14,
955,
14,
2407,
492,
481,
2692,
1692,
5640,
199,
504,
1639,
14,
697,
14,
992,
14,
2609,
492,
3523,
2988,
199,
504,
1639,
14,
697,
14,
992,
14,
1131,
492,
9630,
13689,
12,
18397,
199,
504,
1639,
14,
396,
492,
334,
272,
24424,
12,
7640,
12,
18244,
1746,
12,
3372,
3917,
18093,
12,
272,
3372,
5524,
18093,
12,
199,
9,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
199,
199,
504,
1275,
992,
492,
8281,
12,
8281,
5446,
3314,
8229,
12,
23820,
2891,
421,
199,
533,
5822,
3244,
13921,
2925,
8,
1746,
304,
339,
347,
511,
63,
785,
63,
374,
63,
1397,
63,
8938,
63,
475,
63,
4659,
63,
8111,
63,
2117,
63,
10274,
63,
3527,
8,
277,
304,
267,
282,
275,
8281,
8,
288,
1305,
29,
403,
12,
288,
21250,
534,
11043,
2169,
18572,
315,
2018,
297,
288,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
7294,
395,
267,
776,
267,
291,
14,
7702,
8,
65,
14,
344,
9,
267,
291,
14,
629,
8,
7221,
14,
1462,
14,
452,
1252,
835,
1062,
378,
9,
398,
327,
11063,
652,
1901,
314,
3050,
14,
2047,
1172,
370,
1240,
3354,
342,
7662,
14,
267,
282,
14,
2117,
342,
267,
291,
14,
10389,
8,
65,
14,
344,
9,
267,
291,
14,
629,
8,
7221,
14,
1462,
14,
452,
1252,
835,
1062,
413,
9,
339,
347,
511,
63,
2425,
63,
8489,
63,
1238,
63,
842,
63,
4941,
63,
17867,
63,
4958,
8,
277,
304,
267,
408,
267,
2047,
883,
8265,
282,
1402,
1256,
1808,
11333,
2368,
12,
267,
1314,
1077,
1336,
314,
901,
1865,
465,
3247,
315,
314,
1402,
14,
267,
408,
267,
282,
275,
8281,
8,
403,
12,
283,
11906,
9772,
297,
2197,
8,
9397,
12,
1520,
12,
7349,
430,
267,
282,
14,
2117,
342,
398,
291,
14,
629,
8,
65,
14,
11268,
12,
283,
11906,
9772,
358,
267,
291,
14,
629,
8,
65,
14,
5645,
63,
602,
12,
2197,
8,
9397,
12,
1520,
12,
7349,
12,
378,
12,
378,
430,
339,
347,
511,
63,
2425,
63,
981,
63,
842,
63,
4941,
63,
958,
8,
277,
304,
267,
282,
275,
8281,
8,
288,
1305,
29,
403,
12,
288,
21250,
534,
28611,
9772,
297,
288,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
4233,
395,
267,
776,
267,
282,
14,
2117,
342,
267,
291,
14,
629,
8,
65,
14,
11268,
12,
283,
28611,
9772,
358,
267,
291,
14,
629,
8,
65,
14,
5645,
63,
602,
12,
2197,
8,
9397,
12,
1520,
12,
4233,
12,
378,
12,
378,
430,
339,
347,
511,
63,
2495,
955,
63,
4208,
63,
14020,
63,
1459,
63,
509,
63,
10885,
63,
842,
8,
277,
304,
267,
282,
17,
275,
8281,
14,
1462,
14,
981,
8,
11268,
534,
7147,
297,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
4233,
12,
378,
12,
378,
430,
267,
282,
18,
275,
8281,
14,
1462,
14,
981,
8,
11268,
534,
7147,
297,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
4233,
12,
378,
12,
378,
430,
267,
282,
19,
275,
8281,
14,
1462,
14,
981,
8,
11268,
534,
7147,
297,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
4233,
12,
378,
12,
378,
430,
267,
291,
14,
7418,
8,
65,
19,
14,
344,
12,
282,
17,
14,
344,
9,
267,
291,
14,
7418,
8,
65,
19,
14,
344,
12,
282,
18,
14,
344,
9,
339,
347,
511,
63,
2425,
63,
13979,
63,
460,
63,
1431,
63,
3124,
63,
460,
63,
958,
8,
277,
304,
267,
327,
2047,
883,
2597,
13667,
436,
1336,
3421,
436,
4252,
2368,
12,
1325,
267,
327,
506,
3238,
440,
370,
9250,
901,
2556,
14,
267,
282,
275,
8281,
8,
403,
12,
283,
24766,
273,
9772,
297,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
7105,
430,
267,
282,
14,
2117,
342,
267,
291,
14,
629,
8,
65,
14,
11268,
12,
283,
24766,
273,
9772,
358,
339,
347,
511,
63,
11250,
63,
981,
63,
842,
63,
1045,
63,
3197,
63,
958,
8,
277,
304,
267,
3816,
14,
16499,
8,
288,
291,
12,
288,
3146,
12,
288,
3546,
1421,
7,
365,
376,
3866,
4252,
1423,
367,
642,
805,
401,
288,
8281,
12,
288,
1305,
29,
403,
12,
288,
21250,
534,
7700,
21250,
297,
288,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
7105,
395,
288,
3925,
534,
1700,
297,
267,
776,
339,
347,
511,
63,
2425,
63,
12422,
63,
1997,
63,
585,
63,
509,
63,
2495,
698,
63,
460,
63,
390,
63,
24894,
63,
585,
63,
265,
63,
2117,
8,
277,
304,
267,
408,
267,
2047,
883,
10137,
2331,
314,
574,
367,
376,
9195,
792,
1380,
6425,
376,
267,
909,
12,
2952,
652,
7171,
664,
13457,
315,
5847,
1380,
1265,
3354,
1252,
267,
408,
267,
282,
275,
8281,
8,
11268,
534,
7221,
959,
297,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
7105,
430,
267,
282,
14,
2117,
342,
267,
291,
14,
629,
8,
65,
14,
11268,
12,
283,
7221,
959,
358,
267,
291,
14,
7418,
8,
65,
14,
344,
12,
488,
9,
339,
347,
511,
63,
274,
5519,
63,
1997,
63,
65,
63,
698,
63,
1045,
63,
885,
63,
409,
63,
1589,
63,
885,
63,
14117,
63,
1235,
63,
8420,
8,
277,
304,
267,
282,
275,
8281,
8,
5645,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
7105,
430,
267,
282,
14,
2117,
342,
267,
291,
14,
629,
8,
65,
14,
11268,
12,
283,
2698,
21250,
358,
339,
347,
511,
63,
509,
63,
2083,
955,
63,
83,
7047,
63,
305,
63,
77,
2133,
63,
6833,
63,
305,
63,
10274,
63,
11809,
8,
277,
304,
267,
408,
305,
8298,
7151,
315,
627,
4515,
10,
624,
267,
282,
17,
275,
8281
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
5796,
199,
646,
3598,
199,
504,
2197,
492,
2197,
12,
6871,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
14326,
11188,
28239,
12,
24803,
199,
504,
1639,
14,
697,
492,
6186,
63,
2846,
63,
12644,
12,
27728,
12,
6947,
199,
504,
1639,
14,
697,
14,
992,
14,
955,
492,
5024,
199,
504,
1639,
14,
697,
14,
992,
14,
955,
14,
2407,
492,
481,
2692,
1692,
5640,
199,
504,
1639,
14,
697,
14,
992,
14,
2609,
492,
3523,
2988,
199,
504,
1639,
14,
697,
14,
992,
14,
1131,
492,
9630,
13689,
12,
18397,
199,
504,
1639,
14,
396,
492,
334,
272,
24424,
12,
7640,
12,
18244,
1746,
12,
3372,
3917,
18093,
12,
272,
3372,
5524,
18093,
12,
199,
9,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
199,
199,
504,
1275,
992,
492,
8281,
12,
8281,
5446,
3314,
8229,
12,
23820,
2891,
421,
199,
533,
5822,
3244,
13921,
2925,
8,
1746,
304,
339,
347,
511,
63,
785,
63,
374,
63,
1397,
63,
8938,
63,
475,
63,
4659,
63,
8111,
63,
2117,
63,
10274,
63,
3527,
8,
277,
304,
267,
282,
275,
8281,
8,
288,
1305,
29,
403,
12,
288,
21250,
534,
11043,
2169,
18572,
315,
2018,
297,
288,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
7294,
395,
267,
776,
267,
291,
14,
7702,
8,
65,
14,
344,
9,
267,
291,
14,
629,
8,
7221,
14,
1462,
14,
452,
1252,
835,
1062,
378,
9,
398,
327,
11063,
652,
1901,
314,
3050,
14,
2047,
1172,
370,
1240,
3354,
342,
7662,
14,
267,
282,
14,
2117,
342,
267,
291,
14,
10389,
8,
65,
14,
344,
9,
267,
291,
14,
629,
8,
7221,
14,
1462,
14,
452,
1252,
835,
1062,
413,
9,
339,
347,
511,
63,
2425,
63,
8489,
63,
1238,
63,
842,
63,
4941,
63,
17867,
63,
4958,
8,
277,
304,
267,
408,
267,
2047,
883,
8265,
282,
1402,
1256,
1808,
11333,
2368,
12,
267,
1314,
1077,
1336,
314,
901,
1865,
465,
3247,
315,
314,
1402,
14,
267,
408,
267,
282,
275,
8281,
8,
403,
12,
283,
11906,
9772,
297,
2197,
8,
9397,
12,
1520,
12,
7349,
430,
267,
282,
14,
2117,
342,
398,
291,
14,
629,
8,
65,
14,
11268,
12,
283,
11906,
9772,
358,
267,
291,
14,
629,
8,
65,
14,
5645,
63,
602,
12,
2197,
8,
9397,
12,
1520,
12,
7349,
12,
378,
12,
378,
430,
339,
347,
511,
63,
2425,
63,
981,
63,
842,
63,
4941,
63,
958,
8,
277,
304,
267,
282,
275,
8281,
8,
288,
1305,
29,
403,
12,
288,
21250,
534,
28611,
9772,
297,
288,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
4233,
395,
267,
776,
267,
282,
14,
2117,
342,
267,
291,
14,
629,
8,
65,
14,
11268,
12,
283,
28611,
9772,
358,
267,
291,
14,
629,
8,
65,
14,
5645,
63,
602,
12,
2197,
8,
9397,
12,
1520,
12,
4233,
12,
378,
12,
378,
430,
339,
347,
511,
63,
2495,
955,
63,
4208,
63,
14020,
63,
1459,
63,
509,
63,
10885,
63,
842,
8,
277,
304,
267,
282,
17,
275,
8281,
14,
1462,
14,
981,
8,
11268,
534,
7147,
297,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
4233,
12,
378,
12,
378,
430,
267,
282,
18,
275,
8281,
14,
1462,
14,
981,
8,
11268,
534,
7147,
297,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
4233,
12,
378,
12,
378,
430,
267,
282,
19,
275,
8281,
14,
1462,
14,
981,
8,
11268,
534,
7147,
297,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
4233,
12,
378,
12,
378,
430,
267,
291,
14,
7418,
8,
65,
19,
14,
344,
12,
282,
17,
14,
344,
9,
267,
291,
14,
7418,
8,
65,
19,
14,
344,
12,
282,
18,
14,
344,
9,
339,
347,
511,
63,
2425,
63,
13979,
63,
460,
63,
1431,
63,
3124,
63,
460,
63,
958,
8,
277,
304,
267,
327,
2047,
883,
2597,
13667,
436,
1336,
3421,
436,
4252,
2368,
12,
1325,
267,
327,
506,
3238,
440,
370,
9250,
901,
2556,
14,
267,
282,
275,
8281,
8,
403,
12,
283,
24766,
273,
9772,
297,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
7105,
430,
267,
282,
14,
2117,
342,
267,
291,
14,
629,
8,
65,
14,
11268,
12,
283,
24766,
273,
9772,
358,
339,
347,
511,
63,
11250,
63,
981,
63,
842,
63,
1045,
63,
3197,
63,
958,
8,
277,
304,
267,
3816,
14,
16499,
8,
288,
291,
12,
288,
3146,
12,
288,
3546,
1421,
7,
365,
376,
3866,
4252,
1423,
367,
642,
805,
401,
288,
8281,
12,
288,
1305,
29,
403,
12,
288,
21250,
534,
7700,
21250,
297,
288,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
7105,
395,
288,
3925,
534,
1700,
297,
267,
776,
339,
347,
511,
63,
2425,
63,
12422,
63,
1997,
63,
585,
63,
509,
63,
2495,
698,
63,
460,
63,
390,
63,
24894,
63,
585,
63,
265,
63,
2117,
8,
277,
304,
267,
408,
267,
2047,
883,
10137,
2331,
314,
574,
367,
376,
9195,
792,
1380,
6425,
376,
267,
909,
12,
2952,
652,
7171,
664,
13457,
315,
5847,
1380,
1265,
3354,
1252,
267,
408,
267,
282,
275,
8281,
8,
11268,
534,
7221,
959,
297,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
7105,
430,
267,
282,
14,
2117,
342,
267,
291,
14,
629,
8,
65,
14,
11268,
12,
283,
7221,
959,
358,
267,
291,
14,
7418,
8,
65,
14,
344,
12,
488,
9,
339,
347,
511,
63,
274,
5519,
63,
1997,
63,
65,
63,
698,
63,
1045,
63,
885,
63,
409,
63,
1589,
63,
885,
63,
14117,
63,
1235,
63,
8420,
8,
277,
304,
267,
282,
275,
8281,
8,
5645,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
7105,
430,
267,
282,
14,
2117,
342,
267,
291,
14,
629,
8,
65,
14,
11268,
12,
283,
2698,
21250,
358,
339,
347,
511,
63,
509,
63,
2083,
955,
63,
83,
7047,
63,
305,
63,
77,
2133,
63,
6833,
63,
305,
63,
10274,
63,
11809,
8,
277,
304,
267,
408,
305,
8298,
7151,
315,
627,
4515,
10,
624,
267,
282,
17,
275,
8281,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nishant2295/swiftp
|
cloud_server/httpd_doc_root/py/gcheckout.py
|
23
|
6830
|
from mod_python import apache
from log import log
import xml.dom.minidom
import re
import myutil
import string
import json
import socket
def do_db_work(req, py_obj):
"""Open a connection to the Erlang server that handles our database, write the given
object in JSON format, and return the server's response. The req parameter is a
mod_python Apache HTTP request object, so we can do logging."""
json_text = json.dumps(py_obj)
sock = socket.create_connection(('localhost', 2001))
sock.send(json_text)
response = sock.recv(8192)
sock.close()
response = json.loads(response)
if len(response) == 0:
return True
else:
log(req, "Failure response from Erlang server: " + str(response))
return False
def new_order_notification(req, dom):
"""Called iff the incoming XML request is a 'new-order-notification'"""
order_number = myutil.extract_node(dom, "google-order-number")
buyer_id = myutil.extract_node(dom, "buyer-id")
order_total = myutil.extract_node(dom, "order-total")
timestamp = myutil.extract_node(dom, "timestamp")
# Translate the dollar value of the user's order into GB's of transfer credit,
# or -1 for infinite
transfer_credit = myutil.get_price_value_map()[int(float(order_total))]
# The item description in the shopping cart will contain a substring
# like "android_id=123456789" that we must extract.
# Something could throw an exception in this section with bad input, which is fine.
description_text = myutil.extract_node(dom, ["shopping-cart", "items", "item", \
"item-description"])
log(req, "Description is: " + description_text)
re_pattern = re.compile('android_id=([a-zA-Z0-9]+),')
re_match = re_pattern.search(description_text)
android_id = re_match.group(1)
log(req, "Order number is: " + order_number)
log(req, "Buyer ID is: " + buyer_id)
log(req, "Android ID is: " + android_id)
log(req, "Order total is: " + order_total)
log(req, "Timestamp is: " + timestamp)
log(req, "Transfer credit: " + str(transfer_credit))
req.content_type = "application/xml"
if order_number is None or buyer_id is None or android_id is None \
or order_total is None or timestamp is None or transfer_credit is None:
req.write("Internal error")
return apache.HTTP_INTERNAL_SERVER_ERROR
response = do_db_work(req, \
{'event' : 'new-order-notification', \
'google-order-number' : order_number, \
'android_id' : android_id, \
'order-total' : order_total, \
'timestamp' : timestamp, \
'buyer-id' : buyer_id, \
'transfer-credit' : transfer_credit})
if response == True:
# On success, we will have received an empty JSON object
log(req, "New order notification success")
return apache.OK
else:
log(req, "New order notification failed")
return apache.HTTP_INTERNAL_SERVER_ERROR
def order_state_change_notification(req, dom):
"""Called iff the incoming XML request is an 'order-state-change-notification'"""
order_num = myutil.extract_node(dom, 'google-order-number')
order_state = myutil.extract_node(dom, 'new-financial-order-state')
timestamp = myutil.extract_node(dom, 'timestamp')
response = do_db_work(req, {'event' : 'order-state-change-notification', \
'google-order-number' : order_num, \
'new-financial-order-state' : order_state, \
'timestamp' : timestamp})
# The server will return an empty JSON object on success
if response == True:
log(req, "Order state change successful, order " + str(order_num) + " to state " + str(order_state))
return apache.OK
else:
log(req, "Order state change failed, order " + str(order_num) + " state " + str(order_state))
return apache.HTTP_INTERNAL_SERVER_ERROR
def charge_amount_notification(req, dom):
"""Called iff the incoming XML request is a 'charge-amount-notification'"""
order_num = myutil.extract_node(dom, 'google-order-number')
latest_amt = myutil.extract_node(dom, 'latest-charge-amount')
total_amt = myutil.extract_node(dom, 'total-charge-amount')
timestamp = myutil.extract_node(dom, 'timestamp')
response = do_db_work(req, {'event': 'charge-amount-notification', \
'google-order-number' : order_num, \
'latest-charge-amount' : latest_amt, \
'total-charge-amount' : total_amt, \
'timestamp' : timestamp })
if response == True:
log(req, "Charge amount successful, order " + str(order_num) + " amount " + str(total_amt))
log(req, "Sending ship notification for order " + str(order_num))
postdata = \
"""<?xml version="1.0" encoding="UTF-8"?>
<deliver-order xmlns="http://checkout.google.com/schema/2"
google-order-number="%(order_num)s">
</deliver-order>
""" % {'order_num' : order_num}
log(req, "Postdata is: " + str(postdata))
# Make the web service call and return a minidom object from the received XML
dom = myutil.gchk_call(req, postdata)
log(req, "deliver-order response was " + dom.toxml())
return apache.OK
else:
log(req, "Charge amount call failed, order " + str(order_num) + " amount " + str(total_amt))
return apache.HTTP_INTERNAL_SERVER_ERROR
def handler(req):
if not req.is_https():
req.content_type = "text/plain"
req.write("Must use HTTPS!")
return apache.OK
log(req, "gcheckout running, parsing")
req_body = req.read()
#log(req, "request body is: " + req_body)
dom = xml.dom.minidom.parseString(req_body)
req_type = dom.childNodes[0].nodeName
if req_type == 'new-order-notification':
ret_val = new_order_notification(req, dom)
elif req_type == 'order-state-change-notification':
ret_val = order_state_change_notification(req, dom)
elif req_type == 'charge-amount-notification':
ret_val = charge_amount_notification(req, dom)
elif req_type == 'risk-information-notification':
# We don't care about risk information, just return OK
log(req, "Ignoring incoming risk-information-notification")
ret_val = apache.OK
else:
log(req, "Unrecognized root node type: " + req_type)
ret_val = apache.HTTP_INTERNAL_SERVER_ERROR
#return ret_val
return apache.OK
|
gpl-3.0
|
[
504,
3413,
63,
1548,
492,
17098,
199,
504,
943,
492,
943,
199,
646,
2748,
14,
4556,
14,
21827,
199,
646,
295,
199,
646,
3002,
1974,
199,
646,
1059,
199,
646,
2022,
199,
646,
2838,
421,
199,
318,
886,
63,
697,
63,
800,
8,
2103,
12,
1134,
63,
1113,
304,
272,
408,
4299,
282,
1950,
370,
314,
221,
23223,
1654,
626,
10022,
4154,
3050,
12,
2218,
314,
1627,
272,
909,
315,
4840,
1475,
12,
436,
372,
314,
1654,
1159,
1177,
14,
710,
2648,
2725,
365,
282,
272,
3413,
63,
1548,
3668,
3101,
1056,
909,
12,
880,
781,
883,
886,
2050,
1041,
272,
2022,
63,
505,
275,
2022,
14,
4180,
8,
647,
63,
1113,
9,
272,
6771,
275,
2838,
14,
981,
63,
2105,
4725,
5967,
297,
12521,
430,
272,
6771,
14,
2254,
8,
1001,
63,
505,
9,
272,
1177,
275,
6771,
14,
7637,
8,
31526,
9,
272,
6771,
14,
1600,
342,
272,
1177,
275,
2022,
14,
3640,
8,
1310,
9,
272,
340,
822,
8,
1310,
9,
508,
378,
26,
267,
372,
715,
272,
587,
26,
267,
943,
8,
2103,
12,
298,
6782,
1177,
687,
221,
23223,
1654,
26,
298,
435,
620,
8,
1310,
430,
267,
372,
756,
199,
199,
318,
892,
63,
1648,
63,
6761,
8,
2103,
12,
8266,
304,
14821,
408,
10474,
17963,
314,
12467,
4692,
1056,
365,
282,
283,
1222,
13,
1648,
13,
6761,
26555,
14821,
1865,
63,
1955,
275,
3002,
1974,
14,
5005,
63,
932,
8,
4556,
12,
298,
3098,
13,
1648,
13,
1955,
531,
272,
1032,
23009,
63,
344,
275,
3002,
1974,
14,
5005,
63,
932,
8,
4556,
12,
298,
464,
23009,
13,
344,
531,
272,
1865,
63,
2923,
275,
3002,
1974,
14,
5005,
63,
932,
8,
4556,
12,
298,
1648,
13,
2923,
531,
272,
4913,
275,
3002,
1974,
14,
5005,
63,
932,
8,
4556,
12,
298,
3954,
531,
2286,
327,
25540,
314,
366,
25317,
574,
402,
314,
922,
1159,
1865,
1901,
18553,
1159,
402,
9307,
16630,
12,
272,
327,
503,
446,
17,
367,
15258,
272,
9307,
63,
9365,
275,
3002,
1974,
14,
362,
63,
4777,
63,
585,
63,
1130,
3430,
442,
8,
1609,
8,
1648,
63,
2923,
10524,
2286,
327,
710,
1242,
1369,
315,
314,
25630,
4073,
16942,
911,
1395,
282,
20597,
5591,
327,
2839,
298,
6238,
63,
344,
29,
11272,
2,
626,
781,
1471,
5536,
14,
272,
327,
27173,
4293,
7978,
376,
1919,
315,
642,
3420,
543,
4875,
1324,
12,
1314,
365,
15701,
14,
272,
1369,
63,
505,
275,
3002,
1974,
14,
5005,
63,
932,
8,
4556,
12,
2097,
15842,
13,
8153,
401,
298,
1744,
401,
298,
1053,
401,
971,
5101,
298,
1053,
13,
1802,
3135,
272,
943,
8,
2103,
12,
298,
5831,
365,
26,
298,
435,
1369,
63,
505,
9,
272,
295,
63,
3401,
275,
295,
14,
2014,
360,
6238,
63,
344,
30982,
65,
13,
6353,
13,
58,
16,
13,
25,
2807,
395,
358,
272,
295,
63,
1431,
275,
295,
63,
3401,
14,
1733,
8,
1802,
63,
505,
9,
272,
15516,
63,
344,
275,
295,
63,
1431,
14,
923,
8,
17,
9,
339,
943,
8,
2103,
12,
298,
4738,
1329,
365,
26,
298,
435,
1865,
63,
1955,
9,
272,
943,
8,
2103,
12,
298,
1713,
23009,
2870,
365,
26,
298,
435,
1032,
23009,
63,
344,
9,
272,
943,
8,
2103,
12,
298,
20762,
2870,
365,
26,
298,
435,
15516,
63,
344,
9,
272,
943,
8,
2103,
12,
298,
4738,
3141,
365,
26,
298,
435,
1865,
63,
2923,
9,
272,
943,
8,
2103,
12,
298,
10239,
365,
26,
298,
435,
4913,
9,
272,
943,
8,
2103,
12,
298,
11761,
16630,
26,
298,
435,
620,
8,
9609,
63,
9365,
430,
2286,
2648,
14,
1317,
63,
466,
275,
298,
3578,
15,
1652,
2,
339,
340,
1865,
63,
1955,
365,
488,
503,
1032,
23009,
63,
344,
365,
488,
503,
15516,
63,
344,
365,
488,
971,
2126,
503,
1865,
63,
2923,
365,
488,
503,
4913,
365,
488,
503,
9307,
63,
9365,
365,
488,
26,
267,
2648,
14,
952,
480,
8405,
1125,
531,
267,
372,
17098,
14,
2856,
63,
17681,
63,
6613,
63,
3170,
339,
1177,
275,
886,
63,
697,
63,
800,
8,
2103,
12,
971,
2079,
791,
1430,
7,
520,
283,
1222,
13,
1648,
13,
6761,
297,
971,
2574,
283,
3098,
13,
1648,
13,
1955,
7,
520,
1865,
63,
1955,
12,
971,
2574,
283,
6238,
63,
344,
7,
520,
15516,
63,
344,
12,
971,
2574,
283,
1648,
13,
2923,
7,
520,
1865,
63,
2923,
12,
971,
2574,
283,
3954,
7,
520,
4913,
12,
971,
2574,
283,
464,
23009,
13,
344,
7,
520,
1032,
23009,
63,
344,
12,
971,
2574,
283,
9609,
13,
9365,
7,
520,
9307,
63,
9365,
1552,
272,
340,
1177,
508,
715,
26,
267,
327,
4068,
3182,
12,
781,
911,
1172,
3086,
376,
2701,
4840,
909,
267,
943,
8,
2103,
12,
298,
4665,
1865,
6955,
3182,
531,
267,
372,
17098,
14,
3593,
272,
587,
26,
267,
943,
8,
2103,
12,
298,
4665,
1865,
6955,
3405,
531,
267,
372,
17098,
14,
2856,
63,
17681,
63,
6613,
63,
3170,
199,
199,
318,
1865,
63,
929,
63,
1461,
63,
6761,
8,
2103,
12,
8266,
304,
272,
408,
10474,
17963,
314,
12467,
4692,
1056,
365,
376,
283,
1648,
13,
929,
13,
1461,
13,
6761,
26555,
272,
1865,
63,
1507,
275,
3002,
1974,
14,
5005,
63,
932,
8,
4556,
12,
283,
3098,
13,
1648,
13,
1955,
358,
272,
1865,
63,
929,
275,
3002,
1974,
14,
5005,
63,
932,
8,
4556,
12,
283,
1222,
13,
2408,
24409,
13,
1648,
13,
929,
358,
272,
4913,
275,
3002,
1974,
14,
5005,
63,
932,
8,
4556,
12,
283,
3954,
358,
2286,
1177,
275,
886,
63,
697,
63,
800,
8,
2103,
12,
791,
1430,
7,
520,
283,
1648,
13,
929,
13,
1461,
13,
6761,
297,
971,
1816,
283,
3098,
13,
1648,
13,
1955,
7,
520,
1865,
63,
1507,
12,
971,
1816,
283,
1222,
13,
2408,
24409,
13,
1648,
13,
929,
7,
520,
1865,
63,
929,
12,
971,
1816,
283,
3954,
7,
520,
4913,
1552,
639,
272,
327,
710,
1654,
911,
372,
376,
2701,
4840,
909,
641,
3182,
272,
340,
1177,
508,
715,
26,
267,
943,
8,
2103,
12,
298,
4738,
1174,
1570,
9512,
12,
1865,
298,
435,
620,
8,
1648,
63,
1507,
9,
435,
298,
370,
1174,
298,
435,
620,
8,
1648
] |
[
3413,
63,
1548,
492,
17098,
199,
504,
943,
492,
943,
199,
646,
2748,
14,
4556,
14,
21827,
199,
646,
295,
199,
646,
3002,
1974,
199,
646,
1059,
199,
646,
2022,
199,
646,
2838,
421,
199,
318,
886,
63,
697,
63,
800,
8,
2103,
12,
1134,
63,
1113,
304,
272,
408,
4299,
282,
1950,
370,
314,
221,
23223,
1654,
626,
10022,
4154,
3050,
12,
2218,
314,
1627,
272,
909,
315,
4840,
1475,
12,
436,
372,
314,
1654,
1159,
1177,
14,
710,
2648,
2725,
365,
282,
272,
3413,
63,
1548,
3668,
3101,
1056,
909,
12,
880,
781,
883,
886,
2050,
1041,
272,
2022,
63,
505,
275,
2022,
14,
4180,
8,
647,
63,
1113,
9,
272,
6771,
275,
2838,
14,
981,
63,
2105,
4725,
5967,
297,
12521,
430,
272,
6771,
14,
2254,
8,
1001,
63,
505,
9,
272,
1177,
275,
6771,
14,
7637,
8,
31526,
9,
272,
6771,
14,
1600,
342,
272,
1177,
275,
2022,
14,
3640,
8,
1310,
9,
272,
340,
822,
8,
1310,
9,
508,
378,
26,
267,
372,
715,
272,
587,
26,
267,
943,
8,
2103,
12,
298,
6782,
1177,
687,
221,
23223,
1654,
26,
298,
435,
620,
8,
1310,
430,
267,
372,
756,
199,
199,
318,
892,
63,
1648,
63,
6761,
8,
2103,
12,
8266,
304,
14821,
408,
10474,
17963,
314,
12467,
4692,
1056,
365,
282,
283,
1222,
13,
1648,
13,
6761,
26555,
14821,
1865,
63,
1955,
275,
3002,
1974,
14,
5005,
63,
932,
8,
4556,
12,
298,
3098,
13,
1648,
13,
1955,
531,
272,
1032,
23009,
63,
344,
275,
3002,
1974,
14,
5005,
63,
932,
8,
4556,
12,
298,
464,
23009,
13,
344,
531,
272,
1865,
63,
2923,
275,
3002,
1974,
14,
5005,
63,
932,
8,
4556,
12,
298,
1648,
13,
2923,
531,
272,
4913,
275,
3002,
1974,
14,
5005,
63,
932,
8,
4556,
12,
298,
3954,
531,
2286,
327,
25540,
314,
366,
25317,
574,
402,
314,
922,
1159,
1865,
1901,
18553,
1159,
402,
9307,
16630,
12,
272,
327,
503,
446,
17,
367,
15258,
272,
9307,
63,
9365,
275,
3002,
1974,
14,
362,
63,
4777,
63,
585,
63,
1130,
3430,
442,
8,
1609,
8,
1648,
63,
2923,
10524,
2286,
327,
710,
1242,
1369,
315,
314,
25630,
4073,
16942,
911,
1395,
282,
20597,
5591,
327,
2839,
298,
6238,
63,
344,
29,
11272,
2,
626,
781,
1471,
5536,
14,
272,
327,
27173,
4293,
7978,
376,
1919,
315,
642,
3420,
543,
4875,
1324,
12,
1314,
365,
15701,
14,
272,
1369,
63,
505,
275,
3002,
1974,
14,
5005,
63,
932,
8,
4556,
12,
2097,
15842,
13,
8153,
401,
298,
1744,
401,
298,
1053,
401,
971,
5101,
298,
1053,
13,
1802,
3135,
272,
943,
8,
2103,
12,
298,
5831,
365,
26,
298,
435,
1369,
63,
505,
9,
272,
295,
63,
3401,
275,
295,
14,
2014,
360,
6238,
63,
344,
30982,
65,
13,
6353,
13,
58,
16,
13,
25,
2807,
395,
358,
272,
295,
63,
1431,
275,
295,
63,
3401,
14,
1733,
8,
1802,
63,
505,
9,
272,
15516,
63,
344,
275,
295,
63,
1431,
14,
923,
8,
17,
9,
339,
943,
8,
2103,
12,
298,
4738,
1329,
365,
26,
298,
435,
1865,
63,
1955,
9,
272,
943,
8,
2103,
12,
298,
1713,
23009,
2870,
365,
26,
298,
435,
1032,
23009,
63,
344,
9,
272,
943,
8,
2103,
12,
298,
20762,
2870,
365,
26,
298,
435,
15516,
63,
344,
9,
272,
943,
8,
2103,
12,
298,
4738,
3141,
365,
26,
298,
435,
1865,
63,
2923,
9,
272,
943,
8,
2103,
12,
298,
10239,
365,
26,
298,
435,
4913,
9,
272,
943,
8,
2103,
12,
298,
11761,
16630,
26,
298,
435,
620,
8,
9609,
63,
9365,
430,
2286,
2648,
14,
1317,
63,
466,
275,
298,
3578,
15,
1652,
2,
339,
340,
1865,
63,
1955,
365,
488,
503,
1032,
23009,
63,
344,
365,
488,
503,
15516,
63,
344,
365,
488,
971,
2126,
503,
1865,
63,
2923,
365,
488,
503,
4913,
365,
488,
503,
9307,
63,
9365,
365,
488,
26,
267,
2648,
14,
952,
480,
8405,
1125,
531,
267,
372,
17098,
14,
2856,
63,
17681,
63,
6613,
63,
3170,
339,
1177,
275,
886,
63,
697,
63,
800,
8,
2103,
12,
971,
2079,
791,
1430,
7,
520,
283,
1222,
13,
1648,
13,
6761,
297,
971,
2574,
283,
3098,
13,
1648,
13,
1955,
7,
520,
1865,
63,
1955,
12,
971,
2574,
283,
6238,
63,
344,
7,
520,
15516,
63,
344,
12,
971,
2574,
283,
1648,
13,
2923,
7,
520,
1865,
63,
2923,
12,
971,
2574,
283,
3954,
7,
520,
4913,
12,
971,
2574,
283,
464,
23009,
13,
344,
7,
520,
1032,
23009,
63,
344,
12,
971,
2574,
283,
9609,
13,
9365,
7,
520,
9307,
63,
9365,
1552,
272,
340,
1177,
508,
715,
26,
267,
327,
4068,
3182,
12,
781,
911,
1172,
3086,
376,
2701,
4840,
909,
267,
943,
8,
2103,
12,
298,
4665,
1865,
6955,
3182,
531,
267,
372,
17098,
14,
3593,
272,
587,
26,
267,
943,
8,
2103,
12,
298,
4665,
1865,
6955,
3405,
531,
267,
372,
17098,
14,
2856,
63,
17681,
63,
6613,
63,
3170,
199,
199,
318,
1865,
63,
929,
63,
1461,
63,
6761,
8,
2103,
12,
8266,
304,
272,
408,
10474,
17963,
314,
12467,
4692,
1056,
365,
376,
283,
1648,
13,
929,
13,
1461,
13,
6761,
26555,
272,
1865,
63,
1507,
275,
3002,
1974,
14,
5005,
63,
932,
8,
4556,
12,
283,
3098,
13,
1648,
13,
1955,
358,
272,
1865,
63,
929,
275,
3002,
1974,
14,
5005,
63,
932,
8,
4556,
12,
283,
1222,
13,
2408,
24409,
13,
1648,
13,
929,
358,
272,
4913,
275,
3002,
1974,
14,
5005,
63,
932,
8,
4556,
12,
283,
3954,
358,
2286,
1177,
275,
886,
63,
697,
63,
800,
8,
2103,
12,
791,
1430,
7,
520,
283,
1648,
13,
929,
13,
1461,
13,
6761,
297,
971,
1816,
283,
3098,
13,
1648,
13,
1955,
7,
520,
1865,
63,
1507,
12,
971,
1816,
283,
1222,
13,
2408,
24409,
13,
1648,
13,
929,
7,
520,
1865,
63,
929,
12,
971,
1816,
283,
3954,
7,
520,
4913,
1552,
639,
272,
327,
710,
1654,
911,
372,
376,
2701,
4840,
909,
641,
3182,
272,
340,
1177,
508,
715,
26,
267,
943,
8,
2103,
12,
298,
4738,
1174,
1570,
9512,
12,
1865,
298,
435,
620,
8,
1648,
63,
1507,
9,
435,
298,
370,
1174,
298,
435,
620,
8,
1648,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Mirantis/mos-horizon
|
horizon/utils/lazy_encoder.py
|
20
|
1037
|
# Copyright 2016 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.core.serializers.json import DjangoJSONEncoder
from django.utils.encoding import force_text
from django.utils.functional import Promise
class LazyTranslationEncoder(DjangoJSONEncoder):
"""JSON encoder that resolves lazy objects like translations"""
def default(self, obj):
if isinstance(obj, Promise):
return force_text(obj)
return super(LazyTranslationEncoder, self).default(obj)
|
apache-2.0
|
[
3,
1898,
7800,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
1018,
14,
12844,
14,
1001,
492,
5634,
23069,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
15481,
492,
27724,
572,
421,
199,
533,
22373,
18483,
6679,
8,
9323,
23069,
304,
272,
408,
6243,
10295,
626,
32253,
9617,
2251,
2839,
15547,
624,
272,
347,
849,
8,
277,
12,
1559,
304,
267,
340,
1228,
8,
1113,
12,
27724,
572,
304,
288,
372,
3542,
63,
505,
8,
1113,
9,
267,
372,
1613,
8,
14269,
18483,
6679,
12,
291,
680,
885,
8,
1113,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
7800,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
1018,
14,
12844,
14,
1001,
492,
5634,
23069,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
15481,
492,
27724,
572,
421,
199,
533,
22373,
18483,
6679,
8,
9323,
23069,
304,
272,
408,
6243,
10295,
626,
32253,
9617,
2251,
2839,
15547,
624,
272,
347,
849,
8,
277,
12,
1559,
304,
267,
340,
1228,
8,
1113,
12,
27724,
572,
304,
288,
372,
3542,
63,
505,
8,
1113,
9,
267,
372,
1613,
8,
14269,
18483,
6679,
12,
291,
680,
885,
8,
1113,
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,
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,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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
] |
datalogics-robb/scons
|
src/engine/SCons/Tool/sgic++.py
|
2
|
1846
|
"""SCons.Tool.sgic++
Tool-specific initialization for MIPSpro C++ on SGI.
There normally shouldn't be any need to import this module directly.
It will usually be imported through the generic SCons.Tool.Tool()
selection method.
"""
#
# __COPYRIGHT__
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import SCons.Util
cplusplus = __import__('c++', globals(), locals(), [])
def generate(env):
"""Add Builders and construction variables for SGI MIPS C++ to an Environment."""
cplusplus.generate(env)
env['CXX'] = 'CC'
env['CXXFLAGS'] = SCons.Util.CLVar('$CCFLAGS -LANG:std')
env['SHCXX'] = 'CC'
env['SHOBJSUFFIX'] = '.o'
env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
def exists(env):
return env.Detect('CC')
|
mit
|
[
624,
18521,
14,
5157,
14,
1226,
530,
4176,
199,
199,
5157,
13,
6100,
11097,
367,
603,
12346,
496,
445,
4176,
641,
18868,
41,
14,
199,
199,
10924,
12252,
9296,
1133,
506,
1263,
1929,
370,
492,
642,
859,
5370,
14,
199,
7940,
911,
9987,
506,
8439,
4012,
314,
7809,
8218,
14,
5157,
14,
5157,
342,
199,
5592,
1083,
14,
199,
199,
624,
199,
199,
3,
199,
3,
636,
32324,
5716,
363,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
4396,
3817,
363,
636,
907,
18775,
363,
636,
5390,
363,
636,
1093,
2524,
1484,
4227,
16526,
199,
199,
646,
8218,
14,
9562,
199,
199,
67,
6666,
6666,
275,
636,
646,
19734,
67,
31249,
7992,
1062,
9480,
1062,
3073,
199,
199,
318,
3550,
8,
1813,
304,
272,
408,
1123,
19286,
83,
436,
14538,
2860,
367,
18868,
41,
603,
12346,
445,
4176,
370,
376,
9711,
1041,
339,
286,
6666,
6666,
14,
4208,
8,
1813,
9,
339,
2589,
459,
12206,
418,
260,
275,
283,
2571,
7,
272,
2589,
459,
26180,
418,
259,
275,
8218,
14,
9562,
14,
1981,
5894,
14676,
2571,
4831,
446,
7442,
26,
1516,
358,
272,
2589,
459,
3234,
12206,
418,
755,
275,
283,
2571,
7,
272,
2589,
459,
51,
2979,
16262,
12273,
418,
275,
1987,
79,
7,
272,
2589,
459,
10449,
63,
3649,
63,
13772,
63,
9868,
51,
63,
8693,
63,
18061,
63,
19935,
418,
275,
413,
1362,
199,
318,
3495,
8,
1813,
304,
272,
372,
2589,
14,
20064,
360,
2571,
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
] |
[
18521,
14,
5157,
14,
1226,
530,
4176,
199,
199,
5157,
13,
6100,
11097,
367,
603,
12346,
496,
445,
4176,
641,
18868,
41,
14,
199,
199,
10924,
12252,
9296,
1133,
506,
1263,
1929,
370,
492,
642,
859,
5370,
14,
199,
7940,
911,
9987,
506,
8439,
4012,
314,
7809,
8218,
14,
5157,
14,
5157,
342,
199,
5592,
1083,
14,
199,
199,
624,
199,
199,
3,
199,
3,
636,
32324,
5716,
363,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
4396,
3817,
363,
636,
907,
18775,
363,
636,
5390,
363,
636,
1093,
2524,
1484,
4227,
16526,
199,
199,
646,
8218,
14,
9562,
199,
199,
67,
6666,
6666,
275,
636,
646,
19734,
67,
31249,
7992,
1062,
9480,
1062,
3073,
199,
199,
318,
3550,
8,
1813,
304,
272,
408,
1123,
19286,
83,
436,
14538,
2860,
367,
18868,
41,
603,
12346,
445,
4176,
370,
376,
9711,
1041,
339,
286,
6666,
6666,
14,
4208,
8,
1813,
9,
339,
2589,
459,
12206,
418,
260,
275,
283,
2571,
7,
272,
2589,
459,
26180,
418,
259,
275,
8218,
14,
9562,
14,
1981,
5894,
14676,
2571,
4831,
446,
7442,
26,
1516,
358,
272,
2589,
459,
3234,
12206,
418,
755,
275,
283,
2571,
7,
272,
2589,
459,
51,
2979,
16262,
12273,
418,
275,
1987,
79,
7,
272,
2589,
459,
10449,
63,
3649,
63,
13772,
63,
9868,
51,
63,
8693,
63,
18061,
63,
19935,
418,
275,
413,
1362,
199,
318,
3495,
8,
1813,
304,
272,
372,
2589,
14,
20064,
360,
2571,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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create a matplotlib graph.
This widget has the same properties as
:class:`kivy.ext.mpl.backend_kivyagg.FigureCanvasKivyAgg`. FigureCanvasKivy
instead of rendering a static image, uses the kivy graphics instructions
:class:`kivy.graphics.Line` and :class:`kivy.graphics.Mesh` to render on the
canvas.
Installation
------------
The matplotlib backend for kivy can be used by using the garden extension in
kivy following this .. _link: http://kivy.org/docs/api-kivy.garden.html ::
garden install matplotlib
Or if you want to include it directly on your application ::
cd myapp
garden install --app matplotlib
Initialization
--------------
A backend can be initialized in two ways. The first one is using pure pyplot
as explained
.. _here: http://matplotlib.org/faq/usage_faq.html#what-is-a-backend::
import matplotlib
matplotlib.use('module://kivy.garden.matplotlib.backend_kivy')
Once this is done, any figure instantiated after will be wrapped by a
:class:`FigureCanvasKivy` ready to use. From here there are two options to
continue with the development.
1. Use the :class:`FigureCanvasKivy` attribute defined as canvas from Figure,
to embed your matplotlib graph in your own Kivy application as can be seen in
the first example in the following section.
.. warning::
One can create a matplotlib widget by importing FigureCanvas::
from kivy.garden.matplotlib.backend_kivyagg import FigureCanvas
or
from kivy.garden.matplotlib.backend_kivy import FigureCanvas
and then instantiate an object::
fig, ax = plt.subplots()
my_mpl_kivy_widget = FigureCanvas(fig)
which will certainly work but a problem will arise if events were connected
before the FigureCanvas is instantiated. If this approach is taken please
connect matplotlib events after generating the matplotlib kivy widget
object ::
fig, ax = plt.subplots()
fig.canvas.mpl_connect('button_press_event', callback_handler)
my_mpl_kivy_widget = FigureCanvas(fig)
In this scenario button_press_event won't be connected with the object
being created in line 3, because will be connected to the default canvas
set by matplotlib. If this approach is taken be sure of connecting the
events after instantiation like the following: ::
fig, ax = plt.subplots()
my_mpl_kivy_widget = FigureCanvas(fig)
fig.canvas.mpl_connect('button_press_event', callback_handler)
2. Use pyplot to write the application following matplotlib sintax as can be
seen in the second example below. In this case a Kivy application will be
created automatically from the matplotlib instructions and a NavigationToolbar
will be added to the main canvas.
Examples
--------
1. Example of a simple Hello world matplotlib App::
fig, ax = plt.subplots()
ax.text(0.6, 0.5, "hello", size=50, rotation=30.,
ha="center", va="center",
bbox=dict(boxstyle="round",
ec=(1., 0.5, 0.5),
fc=(1., 0.8, 0.8),
)
)
ax.text(0.5, 0.4, "world", size=50, rotation=-30.,
ha="right", va="top",
bbox=dict(boxstyle="square",
ec=(1., 0.5, 0.5),
fc=(1., 0.8, 0.8),
)
)
canvas = fig.canvas
The object canvas can be added as a widget into the kivy tree widget.
If a change is done on the figure an update can be performed using
:meth:`~kivy.ext.mpl.backend_kivyagg.FigureCanvasKivyAgg.draw`.::
# update graph
canvas.draw()
The plot can be exported to png with
:meth:`~kivy.ext.mpl.backend_kivyagg.FigureCanvasKivyAgg.print_png`, as an
argument receives the `filename`.::
# export to png
canvas.print_png("my_plot.png")
2. Example of a pyplot application using matplotlib instructions::
import numpy as np
import matplotlib.pyplot as plt
N = 5
menMeans = (20, 35, 30, 35, 27)
menStd = (2, 3, 4, 1, 2)
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars
figure, ax = plt.subplots()
rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd)
womenMeans = (25, 32, 34, 20, 25)
womenStd = (3, 5, 2, 3, 3)
rects2 = ax.bar(ind + width, womenMeans, width, color='y', yerr=womenStd)
ax.set_ylabel('----------------------Scores------------------')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind + width)
ax.set_yticklabels(('Ahh', '--G1--', 'G2', 'G3', 'G4', 'G5', 'G5',
'G5', 'G5'), rotation=90)
ax.legend((rects1[0], rects2[0]), ('Men', 'Women'))
plt.draw()
plt.savefig("test.png")
plt.show()
Navigation Toolbar
-----------------
If initialized by the first step a :class:`NavigationToolbarKivy` widget can be
created as well by instantiating an object with a :class:`FigureCanvasKivy` as
parameter. The actual widget is stored in its actionbar attribute.
This can be seen in test_backend.py example ::
bl = BoxLayout(orientation="vertical")
my_mpl_kivy_widget1 = FigureCanvasKivy(fig1)
my_mpl_kivy_widget2 = FigureCanvasKivy(fig2)
nav1 = NavigationToolbar2Kivy(my_mpl_kivy_widget1)
nav2 = NavigationToolbar2Kivy(my_mpl_kivy_widget2)
bl.add_widget(nav1.actionbar)
bl.add_widget(my_mpl_kivy_widget1)
bl.add_widget(nav2.actionbar)
bl.add_widget(my_mpl_kivy_widget2)
Connecting Matplotlib events to Kivy Events
-----------------------
All matplotlib events are available: `button_press_event` which is raised
on a mouse button clicked or on touch down, `button_release_event` which is
raised when a click button is released or on touch up, `key_press_event` which
is raised when a key is pressed, `key_release_event` which is raised when a key
is released, `motion_notify_event` which is raised when the mouse is on motion,
`resize_event` which is raised when the dimensions of the widget change,
`scroll_event` which is raised when the mouse scroll wheel is rolled,
`figure_enter_event` which is raised when mouse enters a new figure,
`figure_leave_event` which is raised when mouse leaves a figure,
`close_event` which is raised when the window is closed,
`draw_event` which is raised on canvas draw,
`pick_event` which is raised when an object is selected,
`idle_event` (deprecated),
`axes_enter_event` which is fired when mouse enters axes,
`axes_leave_event` which is fired when mouse leaves axes.::
def press(event):
print('press released from test', event.x, event.y, event.button)
def release(event):
print('release released from test', event.x, event.y, event.button)
def keypress(event):
print('key down', event.key)
def keyup(event):
print('key up', event.key)
def motionnotify(event):
print('mouse move to ', event.x, event.y)
def resize(event):
print('resize from mpl ', event)
def scroll(event):
print('scroll event from mpl ', event.x, event.y, event.step)
def figure_enter(event):
print('figure enter mpl')
def figure_leave(event):
print('figure leaving mpl')
def close(event):
print('closing figure')
fig.canvas.mpl_connect('button_press_event', press)
fig.canvas.mpl_connect('button_release_event', release)
fig.canvas.mpl_connect('key_press_event', keypress)
fig.canvas.mpl_connect('key_release_event', keyup)
fig.canvas.mpl_connect('motion_notify_event', motionnotify)
fig.canvas.mpl_connect('resize_event', resize)
fig.canvas.mpl_connect('scroll_event', scroll)
fig.canvas.mpl_connect('figure_enter_event', figure_enter)
fig.canvas.mpl_connect('figure_leave_event', figure_leave)
fig.canvas.mpl_connect('close_event', close)
'''
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import six
import os
import matplotlib
import matplotlib.transforms as transforms
from matplotlib._pylab_helpers import Gcf
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
FigureManagerBase, FigureCanvasBase, NavigationToolbar2, TimerBase
from matplotlib.figure import Figure
from matplotlib.transforms import Bbox, Affine2D
from matplotlib.backend_bases import ShowBase, Event
from matplotlib.backends.backend_agg import FigureCanvasAgg
from matplotlib.mathtext import MathTextParser
from matplotlib import rcParams
from hashlib import md5
from matplotlib import _png
from matplotlib import _path
try:
import kivy
except ImportError:
raise ImportError("this backend requires Kivy to be installed.")
from kivy.app import App
from kivy.graphics.texture import Texture
from kivy.graphics import Rectangle
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.behaviors import FocusBehavior
from kivy.uix.actionbar import ActionBar, ActionView, \
ActionButton, ActionToggleButton, \
ActionPrevious, ActionOverflow, ActionSeparator
from kivy.base import EventLoop
from kivy.core.text import Label as CoreLabel
from kivy.core.image import Image
from kivy.graphics import Color, Line
from kivy.graphics import Rotate, Translate
from kivy.graphics.instructions import InstructionGroup
from kivy.graphics.tesselator import Tesselator
from kivy.graphics.context_instructions import PopMatrix, PushMatrix
from kivy.graphics import StencilPush, StencilPop, StencilUse,\
StencilUnUse
from kivy.logger import Logger
from kivy.graphics import Mesh
from kivy.resources import resource_find
from kivy.uix.stencilview import StencilView
from kivy.core.window import Window
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.relativelayout import RelativeLayout
from kivy.uix.popup import Popup
from kivy.properties import ObjectProperty
from kivy.uix.textinput import TextInput
from kivy.lang import Builder
from kivy.logger import Logger
from kivy.clock import Clock
from distutils.version import LooseVersion
_mpl_ge_1_5 = LooseVersion(matplotlib.__version__) >= LooseVersion('1.5.0')
_mpl_ge_2_0 = LooseVersion(matplotlib.__version__) >= LooseVersion('2.0.0')
import numpy as np
import io
import textwrap
import uuid
import numbers
from functools import partial
from math import cos, sin, pi
kivy.require('1.9.1')
toolbar = None
my_canvas = None
class SaveDialog(FloatLayout):
save = ObjectProperty(None)
text_input = ObjectProperty(None)
cancel = ObjectProperty(None)
class MPLKivyApp(App):
'''Creates the App initializing a FloatLayout with a figure and toolbar
widget.
'''
figure = ObjectProperty(None)
toolbar = ObjectProperty(None)
def build(self):
EventLoop.ensure_window()
layout = FloatLayout()
if self.figure:
self.figure.size_hint_y = 0.9
layout.add_widget(self.figure)
if self.toolbar:
self.toolbar.size_hint_y = 0.1
layout.add_widget(self.toolbar)
return layout
def draw_if_interactive():
'''Handle whether or not the backend is in interactive mode or not.
'''
if matplotlib.is_interactive():
figManager = Gcf.get_active()
if figManager:
figManager.canvas.draw_idle()
class Show(ShowBase):
'''mainloop needs to be overwritten to define the show() behavior for kivy
framework.
'''
def mainloop(self):
app = App.get_running_app()
if app is None:
app = MPLKivyApp(figure=my_canvas, toolbar=toolbar)
app.run()
show = Show()
def new_figure_manager(num, *args, **kwargs):
'''Create a new figure manager instance for the figure given.
'''
# if a main-level app must be created, this (and
# new_figure_manager_given_figure) is the usual place to
# do it -- see backend_wx, backend_wxagg and backend_tkagg for
# examples. Not all GUIs require explicit instantiation of a
# main-level app (egg backend_gtk, backend_gtkagg) for pylab
FigureClass = kwargs.pop('FigureClass', Figure)
thisFig = FigureClass(*args, **kwargs)
return new_figure_manager_given_figure(num, thisFig)
def new_figure_manager_given_figure(num, figure):
'''Create a new figure manager instance for the given figure.
'''
canvas = FigureCanvasKivy(figure)
manager = FigureManagerKivy(canvas, num)
global my_canvas
global toolbar
toolbar = manager.toolbar.actionbar if manager.toolbar else None
my_canvas = canvas
return manager
class RendererKivy(RendererBase):
'''The kivy renderer handles drawing/rendering operations. A RendererKivy
should be initialized with a FigureCanvasKivy widget. On initialization
a MathTextParser is instantiated to generate math text inside a
FigureCanvasKivy widget. Additionally a list to store clip_rectangles
is defined for elements that need to be clipped inside a rectangle such
as axes. The rest of the render is performed using kivy graphics
instructions.
'''
def __init__(self, widget):
super(RendererKivy, self).__init__()
self.widget = widget
self.dpi = widget.figure.dpi
self._markers = {}
# Can be enhanced by using TextToPath matplotlib, textpath.py
self.mathtext_parser = MathTextParser("Bitmap")
self.list_goraud_triangles = []
self.clip_rectangles = []
self.labels_inside_plot = []
def contains(self, widget, x, y):
'''Returns whether or not a point is inside the widget. The value
of the point is defined in x, y as kivy coordinates.
'''
left = widget.x
bottom = widget.y
top = widget.y + widget.height
right = widget.x + widget.width
return (left <= x <= right and
bottom <= y <= top)
def handle_clip_rectangle(self, gc, x, y):
'''It checks whether the point (x,y) collides with any already
existent stencil. If so it returns the index position of the
stencil it collides with. if the new clip rectangle bounds are
None it draws in the canvas otherwise it finds the correspondent
stencil or creates a new one for the new graphics instructions.
The point x,y is given in matplotlib coordinates.
'''
x = self.widget.x + x
y = self.widget.y + y
collides = self.collides_with_existent_stencil(x, y)
if collides > -1:
return collides
new_bounds = gc.get_clip_rectangle()
if new_bounds:
x = self.widget.x + int(new_bounds.bounds[0])
y = self.widget.y + int(new_bounds.bounds[1])
w = int(new_bounds.bounds[2])
h = int(new_bounds.bounds[3])
collides = self.collides_with_existent_stencil(x, y)
if collides == -1:
cliparea = StencilView(pos=(x, y), size=(w, h))
self.clip_rectangles.append(cliparea)
self.widget.add_widget(cliparea)
return len(self.clip_rectangles) - 1
else:
return collides
else:
return -2
def draw_path_collection(self, gc, master_transform, paths, all_transforms,
offsets, offsetTrans, facecolors, edgecolors,
linewidths, linestyles, antialiaseds, urls,
offset_position):
'''Draws a collection of paths selecting drawing properties from
the lists *facecolors*, *edgecolors*, *linewidths*,
*linestyles* and *antialiaseds*. *offsets* is a list of
offsets to apply to each of the paths. The offsets in
*offsets* are first transformed by *offsetTrans* before being
applied. *offset_position* may be either "screen" or "data"
depending on the space that the offsets are in.
'''
len_path = len(paths[0].vertices) if len(paths) > 0 else 0
uses_per_path = self._iter_collection_uses_per_path(
paths, all_transforms, offsets, facecolors, edgecolors)
# check whether an optimization is needed by calculating the cost of
# generating and use a path with the cost of emitting a path in-line.
should_do_optimization = \
len_path + uses_per_path + 5 < len_path * uses_per_path
if not should_do_optimization:
return RendererBase.draw_path_collection(
self, gc, master_transform, paths, all_transforms,
offsets, offsetTrans, facecolors, edgecolors,
linewidths, linestyles, antialiaseds, urls,
offset_position)
# Generate an array of unique paths with the respective transformations
path_codes = []
for i, (path, transform) in enumerate(self._iter_collection_raw_paths(
master_transform, paths, all_transforms)):
transform = Affine2D(transform.get_matrix()).scale(1.0, -1.0)
if _mpl_ge_2_0:
polygons = path.to_polygons(transform, closed_only=False)
else:
polygons = path.to_polygons(transform)
path_codes.append(polygons)
# Apply the styles and rgbFace to each one of the raw paths from
# the list. Additionally a transformation is being applied to
# translate each independent path
for xo, yo, path_poly, gc0, rgbFace in self._iter_collection(
gc, master_transform, all_transforms, path_codes, offsets,
offsetTrans, facecolors, edgecolors, linewidths, linestyles,
antialiaseds, urls, offset_position):
list_canvas_instruction = self.get_path_instructions(gc0, path_poly,
closed=True, rgbFace=rgbFace)
for widget, instructions in list_canvas_instruction:
widget.canvas.add(PushMatrix())
widget.canvas.add(Translate(xo, yo))
widget.canvas.add(instructions)
widget.canvas.add(PopMatrix())
def collides_with_existent_stencil(self, x, y):
'''Check all the clipareas and returns the index of the clip area that
contains this point. The point x, y is given in kivy coordinates.
'''
idx = -1
for cliparea in self.clip_rectangles:
idx += 1
if self.contains(cliparea, x, y):
return idx
return -1
def get_path_instructions(self, gc, polygons, closed=False, rgbFace=None):
'''With a graphics context and a set of polygons it returns a list
of InstructionGroups required to render the path.
'''
instructions_list = []
points_line = []
for polygon in polygons:
for x, y in polygon:
x = x + self.widget.x
y = y + self.widget.y
points_line += [float(x), float(y), ]
tess = Tesselator()
tess.add_contour(points_line)
if not tess.tesselate():
Logger.warning("Tesselator didn't work :(")
return
newclip = self.handle_clip_rectangle(gc, x, y)
if newclip > -1:
instructions_list.append((self.clip_rectangles[newclip],
self.get_graphics(gc, tess, points_line, rgbFace,
closed=closed)))
else:
instructions_list.append((self.widget,
self.get_graphics(gc, tess, points_line, rgbFace,
closed=closed)))
return instructions_list
def get_graphics(self, gc, polygons, points_line, rgbFace, closed=False):
'''Return an instruction group which contains the necessary graphics
instructions to draw the respective graphics.
'''
instruction_group = InstructionGroup()
if isinstance(gc.line['dash_list'], tuple):
gc.line['dash_list'] = list(gc.line['dash_list'])
if rgbFace is not None:
if len(polygons.meshes) != 0:
instruction_group.add(Color(*rgbFace))
for vertices, indices in polygons.meshes:
instruction_group.add(Mesh(
vertices=vertices,
indices=indices,
mode=str("triangle_fan")
))
instruction_group.add(Color(*gc.get_rgb()))
if _mpl_ge_1_5 and (not _mpl_ge_2_0) and closed:
points_poly_line = points_line[:-2]
else:
points_poly_line = points_line
if gc.line['width'] > 0:
instruction_group.add(Line(points=points_poly_line,
width=int(gc.line['width'] / 2),
dash_length=gc.line['dash_length'],
dash_offset=gc.line['dash_offset'],
dash_joint=gc.line['join_style'],
dash_list=gc.line['dash_list']))
return instruction_group
def draw_image(self, gc, x, y, im):
'''Render images that can be displayed on a matplotlib figure.
These images are generally called using imshow method from pyplot.
A Texture is applied to the FigureCanvas. The position x, y is
given in matplotlib coordinates.
'''
# Clip path to define an area to mask.
clippath, clippath_trans = gc.get_clip_path()
# Normal coordinates calculated and image added.
x = self.widget.x + x
y = self.widget.y + y
bbox = gc.get_clip_rectangle()
if bbox is not None:
l, b, w, h = bbox.bounds
else:
l = 0
b = 0
w = self.widget.width
h = self.widget.height
h, w = im.get_size_out()
rows, cols, image_str = im.as_rgba_str()
texture = Texture.create(size=(w, h))
texture.blit_buffer(image_str, colorfmt='rgba', bufferfmt='ubyte')
if clippath is None:
with self.widget.canvas:
Color(1.0, 1.0, 1.0, 1.0)
Rectangle(texture=texture, pos=(x, y), size=(w, h))
else:
if _mpl_ge_2_0:
polygons = clippath.to_polygons(clippath_trans, closed_only=False)
else:
polygons = clippath.to_polygons(clippath_trans)
list_canvas_instruction = self.get_path_instructions(gc, polygons,
rgbFace=(1.0, 1.0, 1.0, 1.0))
for widget, instructions in list_canvas_instruction:
widget.canvas.add(StencilPush())
widget.canvas.add(instructions)
widget.canvas.add(StencilUse())
widget.canvas.add(Color(1.0, 1.0, 1.0, 1.0))
widget.canvas.add(Rectangle(texture=texture,
pos=(x, y), size=(w, h)))
widget.canvas.add(StencilUnUse())
widget.canvas.add(StencilPop())
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
'''Render text that is displayed in the canvas. The position x, y is
given in matplotlib coordinates. A `GraphicsContextKivy` is given
to render according to the text properties such as color, size, etc.
An angle is given to change the orientation of the text when needed.
If the text is a math expression it will be rendered using a
MathText parser.
'''
if mtext:
transform = mtext.get_transform()
ax, ay = transform.transform_point(mtext.get_position())
angle_rad = mtext.get_rotation() * np.pi / 180.
dir_vert = np.array([np.sin(angle_rad), np.cos(angle_rad)])
if mtext.get_rotation_mode() == "anchor":
# if anchor mode, rotation is undone first
v_offset = np.dot(dir_vert, [(x - ax), (y - ay)])
ax = ax + v_offset * dir_vert[0]
ay = ay + v_offset * dir_vert[1]
w, h, d = self.get_text_width_height_descent(s, prop, ismath)
ha, va = mtext.get_ha(), mtext.get_va()
if ha == "center":
ax -= w / 2
elif ha == "right":
ax -= w
if va == "top":
ay -= h
elif va == "center":
ay -= h / 2
if mtext.get_rotation_mode() != "anchor":
# if not anchor mode, rotation is undone last
v_offset = np.dot(dir_vert, [(x - ax), (y - ay)])
ax = ax + v_offset * dir_vert[0]
ay = ay + v_offset * dir_vert[1]
x, y = ax, ay
x += self.widget.x
y += self.widget.y
if ismath:
self.draw_mathtext(gc, x, y, s, prop, angle)
else:
font = resource_find(prop.get_name() + ".ttf")
color = gc.get_rgb()
if font is None:
plot_text = CoreLabel(font_size=prop.get_size_in_points(), color=color)
else:
plot_text = CoreLabel(font_size=prop.get_size_in_points(),
font_name=prop.get_name(), color=color)
plot_text.text = six.text_type("{}".format(s))
if prop.get_style() == 'italic':
plot_text.italic = True
if self.weight_as_number(prop.get_weight()) > 500:
plot_text.bold = True
plot_text.refresh()
with self.widget.canvas:
if isinstance(angle, float):
PushMatrix()
Rotate(angle=angle, origin=(int(x), int(y)))
Rectangle(pos=(int(x), int(y)), texture=plot_text.texture,
size=plot_text.texture.size)
PopMatrix()
else:
Rectangle(pos=(int(x), int(y)), texture=plot_text.texture,
size=plot_text.texture.size)
def draw_mathtext(self, gc, x, y, s, prop, angle):
'''Draw the math text using matplotlib.mathtext. The position
x,y is given in Kivy coordinates.
'''
ftimage, depth = self.mathtext_parser.parse(s, self.dpi, prop)
w = ftimage.get_width()
h = ftimage.get_height()
texture = Texture.create(size=(w, h))
if _mpl_ge_1_5:
texture.blit_buffer(ftimage.as_rgba_str()[0][0], colorfmt='rgba',
bufferfmt='ubyte')
else:
texture.blit_buffer(ftimage.as_rgba_str(), colorfmt='rgba',
bufferfmt='ubyte')
texture.flip_vertical()
with self.widget.canvas:
Rectangle(texture=texture, pos=(x, y), size=(w, h))
def draw_path(self, gc, path, transform, rgbFace=None):
'''Produce the rendering of the graphics elements using
:class:`kivy.graphics.Line` and :class:`kivy.graphics.Mesh` kivy
graphics instructions. The paths are converted into polygons and
assigned either to a clip rectangle or to the same canvas for
rendering. Paths are received in matplotlib coordinates. The
aesthetics is defined by the `GraphicsContextKivy` gc.
'''
if _mpl_ge_2_0:
polygons = path.to_polygons(transform, self.widget.width,
self.widget.height, closed_only=False)
else:
polygons = path.to_polygons(transform, self.widget.width,
self.widget.height)
list_canvas_instruction = self.get_path_instructions(gc, polygons,
closed=True, rgbFace=rgbFace)
for widget, instructions in list_canvas_instruction:
widget.canvas.add(instructions)
def draw_markers(self, gc, marker_path, marker_trans, path,
trans, rgbFace=None):
'''Markers graphics instructions are stored on a dictionary and
hashed through graphics context and rgbFace values. If a marker_path
with the corresponding graphics context exist then the instructions
are pulled from the markers dictionary.
'''
if not len(path.vertices):
return
# get a string representation of the path
path_data = self._convert_path(
marker_path,
marker_trans + Affine2D().scale(1.0, -1.0),
simplify=False)
# get a string representation of the graphics context and rgbFace.
style = str(gc._get_style_dict(rgbFace))
dictkey = (path_data, str(style))
# check whether this marker has been created before.
list_instructions = self._markers.get(dictkey)
# creating a list of instructions for the specific marker.
if list_instructions is None:
if _mpl_ge_2_0:
polygons = marker_path.to_polygons(marker_trans, closed_only=False)
else:
polygons = marker_path.to_polygons(marker_trans)
self._markers[dictkey] = self.get_path_instructions(gc,
polygons, rgbFace=rgbFace)
# Traversing all the positions where a marker should be rendered
for vertices, codes in path.iter_segments(trans, simplify=False):
if len(vertices):
x, y = vertices[-2:]
for widget, instructions in self._markers[dictkey]:
widget.canvas.add(PushMatrix())
widget.canvas.add(Translate(x, y))
widget.canvas.add(instructions)
widget.canvas.add(PopMatrix())
def flipy(self):
return False
def _convert_path(self, path, transform=None, clip=None, simplify=None,
sketch=None):
if clip:
clip = (0.0, 0.0, self.width, self.height)
else:
clip = None
if _mpl_ge_1_5:
return _path.convert_to_string(
path, transform, clip, simplify, sketch, 6,
[b'M', b'L', b'Q', b'C', b'z'], False).decode('ascii')
else:
return _path.convert_to_svg(path, transform, clip, simplify, 6)
def get_canvas_width_height(self):
'''Get the actual width and height of the widget.
'''
return self.widget.width, self.widget.height
def get_text_width_height_descent(self, s, prop, ismath):
'''This method is needed specifically to calculate text positioning
in the canvas. Matplotlib needs the size to calculate the points
according to their layout
'''
if ismath:
ftimage, depth = self.mathtext_parser.parse(s, self.dpi, prop)
w = ftimage.get_width()
h = ftimage.get_height()
return w, h, depth
font = resource_find(prop.get_name() + ".ttf")
if font is None:
plot_text = CoreLabel(font_size=prop.get_size_in_points())
else:
plot_text = CoreLabel(font_size=prop.get_size_in_points(),
font_name=prop.get_name())
plot_text.text = six.text_type("{}".format(s))
plot_text.refresh()
return plot_text.texture.size[0], plot_text.texture.size[1], 1
def new_gc(self):
'''Instantiate a GraphicsContextKivy object
'''
return GraphicsContextKivy(self.widget)
def points_to_pixels(self, points):
return points / 72.0 * self.dpi
def weight_as_number(self, weight):
''' Replaces the deprecated matplotlib function of the same name
'''
# Return if number
if isinstance(weight, numbers.Number):
return weight
# else use the mapping of matplotlib 2.2
elif weight == 'ultralight':
return 100
elif weight == 'light':
return 200
elif weight == 'normal':
return 400
elif weight == 'regular':
return 400
elif weight == 'book':
return 500
elif weight == 'medium':
return 500
elif weight == 'roman':
return 500
elif weight == 'semibold':
return 600
elif weight == 'demibold':
return 600
elif weight == 'demi':
return 600
elif weight == 'bold':
return 700
elif weight == 'heavy':
return 800
elif weight == 'extra bold':
return 800
elif weight == 'black':
return 900
else:
raise ValueError('weight ' + weight + ' not valid')
class NavigationToolbar2Kivy(NavigationToolbar2):
'''This class extends from matplotlib class NavigationToolbar2 and
creates an action bar which is added to the main app to allow the
following operations to the figures.
Home: Resets the plot axes to the initial state.
Left: Undo an operation performed.
Right: Redo an operation performed.
Pan: Allows to drag the plot.
Zoom: Allows to define a rectangular area to zoom in.
Configure: Loads a pop up for repositioning elements.
Save: Loads a Save Dialog to generate an image.
'''
def __init__(self, canvas, **kwargs):
self.actionbar = ActionBar(pos_hint={'top': 1.0})
super(NavigationToolbar2Kivy, self).__init__(canvas)
self.rubberband_color = (1.0, 0.0, 0.0, 1.0)
self.lastrect = None
self.save_dialog = Builder.load_string(textwrap.dedent('''\
<SaveDialog>:
text_input: text_input
BoxLayout:
size: root.size
pos: root.pos
orientation: "vertical"
FileChooserListView:
id: filechooser
on_selection: text_input.text = self.selection and\
self.selection[0] or ''
TextInput:
id: text_input
size_hint_y: None
height: 30
multiline: False
BoxLayout:
size_hint_y: None
height: 30
Button:
text: "Cancel"
on_release: root.cancel()
Button:
text: "Save"
on_release: root.save(filechooser.path,\
text_input.text)
'''))
def _init_toolbar(self):
'''A Toolbar is created with an ActionBar widget in which buttons are
added with a specific behavior given by a callback. The buttons
properties are given by matplotlib.
'''
basedir = os.path.join(rcParams['datapath'], 'images')
actionview = ActionView()
actionprevious = ActionPrevious(title="Navigation", with_previous=False)
actionoverflow = ActionOverflow()
actionview.add_widget(actionprevious)
actionview.add_widget(actionoverflow)
actionview.use_separator = True
self.actionbar.add_widget(actionview)
id_group = uuid.uuid4()
for text, tooltip_text, image_file, callback in self.toolitems:
if text is None:
actionview.add_widget(ActionSeparator())
continue
fname = os.path.join(basedir, image_file + '.png')
if text in ['Pan', 'Zoom']:
action_button = ActionToggleButton(text=text, icon=fname,
group=id_group)
else:
action_button = ActionButton(text=text, icon=fname)
action_button.bind(on_press=getattr(self, callback))
actionview.add_widget(action_button)
def configure_subplots(self, *largs):
'''It will be implemented later.'''
pass
def dismiss_popup(self):
self._popup.dismiss()
def show_save(self):
'''Displays a popup widget to perform a save operation.'''
content = SaveDialog(save=self.save, cancel=self.dismiss_popup)
self._popup = Popup(title="Save file", content=content,
size_hint=(0.9, 0.9))
self._popup.open()
def save(self, path, filename):
self.canvas.export_to_png(os.path.join(path, filename))
self.dismiss_popup()
def save_figure(self, *args):
self.show_save()
def draw_rubberband(self, event, x0, y0, x1, y1):
w = abs(x1 - x0)
h = abs(y1 - y0)
rect = [int(val)for val in (min(x0, x1) + self.canvas.x, min(y0, y1)
+ self.canvas.y, w, h)]
if self.lastrect is None:
self.canvas.canvas.add(Color(*self.rubberband_color))
else:
self.canvas.canvas.remove(self.lastrect)
self.lastrect = InstructionGroup()
self.lastrect.add(Line(rectangle=rect, width=1.0, dash_length=5.0,
dash_offset=5.0))
self.lastrect.add(Color(1.0, 0.0, 0.0, 0.2))
self.lastrect.add(Rectangle(pos=(rect[0], rect[1]),
size=(rect[2], rect[3])))
self.canvas.canvas.add(self.lastrect)
def release_zoom(self, event):
self.lastrect = None
return super(NavigationToolbar2Kivy, self).release_zoom(event)
class GraphicsContextKivy(GraphicsContextBase, object):
'''The graphics context provides the color, line styles, etc... All the
mapping between matplotlib and kivy styling is done here.
The GraphicsContextKivy stores colors as a RGB tuple on the unit
interval, e.g., (0.5, 0.0, 1.0) such as in the Kivy framework.
Lines properties and styles are set accordingly to the kivy framework
definition for Line.
'''
_capd = {
'butt': 'square',
'projecting': 'square',
'round': 'round',
}
line = {}
def __init__(self, renderer):
super(GraphicsContextKivy, self).__init__()
self.renderer = renderer
self.line['cap_style'] = self.get_capstyle()
self.line['join_style'] = self.get_joinstyle()
self.line['dash_offset'] = None
self.line['dash_length'] = None
self.line['dash_list'] = []
def set_capstyle(self, cs):
'''Set the cap style based on the kivy framework cap styles.
'''
GraphicsContextBase.set_capstyle(self, cs)
self.line['cap_style'] = self._capd[self._capstyle]
def set_joinstyle(self, js):
'''Set the join style based on the kivy framework join styles.
'''
GraphicsContextBase.set_joinstyle(self, js)
self.line['join_style'] = js
def set_dashes(self, dash_offset, dash_list):
GraphicsContextBase.set_dashes(self, dash_offset, dash_list)
# dash_list is a list with numbers denoting the number of points
# in a dash and if it is on or off.
if dash_list is not None:
self.line['dash_list'] = dash_list
if dash_offset is not None:
self.line['dash_offset'] = int(dash_offset)
def set_linewidth(self, w):
GraphicsContextBase.set_linewidth(self, w)
self.line['width'] = w
def _get_style_dict(self, rgbFace):
'''Return the style string. style is generated from the
GraphicsContext and rgbFace
'''
attrib = {}
forced_alpha = self.get_forced_alpha()
if rgbFace is None:
attrib['fill'] = 'none'
else:
if tuple(rgbFace[:3]) != (0, 0, 0):
attrib['fill'] = str(rgbFace)
if len(rgbFace) == 4 and rgbFace[3] != 1.0 and not forced_alpha:
attrib['fill-opacity'] = str(rgbFace[3])
if forced_alpha and self.get_alpha() != 1.0:
attrib['opacity'] = str(self.get_alpha())
offset, seq = self.get_dashes()
if seq is not None:
attrib['line-dasharray'] = ','.join(['%f' % val for val in seq])
attrib['line-dashoffset'] = six.text_type(float(offset))
linewidth = self.get_linewidth()
if linewidth:
rgb = self.get_rgb()
attrib['line'] = str(rgb)
if not forced_alpha and rgb[3] != 1.0:
attrib['line-opacity'] = str(rgb[3])
if linewidth != 1.0:
attrib['line-width'] = str(linewidth)
if self.get_joinstyle() != 'round':
attrib['line-linejoin'] = self.get_joinstyle()
if self.get_capstyle() != 'butt':
attrib['line-linecap'] = _capd[self.get_capstyle()]
return attrib
class TimerKivy(TimerBase):
'''
Subclass of :class:`backend_bases.TimerBase` that uses Kivy for timer events.
Attributes:
* interval: The time between timer events in milliseconds. Default
is 1000 ms.
* single_shot: Boolean flag indicating whether this timer should
operate as single shot (run once and then stop). Defaults to False.
* callbacks: Stores list of (func, args) tuples that will be called
upon timer events. This list can be manipulated directly, or the
functions add_callback and remove_callback can be used.
'''
def _timer_start(self):
# Need to stop it, otherwise we potentially leak a timer id that will
# never be stopped.
self._timer_stop()
self._timer = Clock.schedule_interval(self._on_timer, self._interval / 1000.0)
def _timer_stop(self):
if self._timer is not None:
Clock.unschedule(self._timer)
self._timer = None
def _timer_set_interval(self):
# Only stop and restart it if the timer has already been started
if self._timer is not None:
self._timer_stop()
self._timer_start()
def _on_timer(self, dt):
super(TimerKivy, self)._on_timer()
class FigureCanvasKivy(FocusBehavior, Widget, FigureCanvasBase):
'''FigureCanvasKivy class. See module documentation for more information.
'''
def __init__(self, figure, **kwargs):
Window.bind(mouse_pos=self._on_mouse_pos)
self.bind(size=self._on_size_changed)
self.bind(pos=self._on_pos_changed)
self.entered_figure = True
self.figure = figure
super(FigureCanvasKivy, self).__init__(figure=self.figure, **kwargs)
def draw(self):
'''Draw the figure using the KivyRenderer
'''
self.clear_widgets()
self.canvas.clear()
self._renderer = RendererKivy(self)
self.figure.draw(self._renderer)
def on_touch_down(self, touch):
'''Kivy Event to trigger the following matplotlib events:
`motion_notify_event`, `scroll_event`, `button_press_event`,
`enter_notify_event` and `leave_notify_event`
'''
newcoord = self.to_widget(touch.x, touch.y, relative=True)
x = newcoord[0]
y = newcoord[1]
if super(FigureCanvasKivy, self).on_touch_down(touch):
return True
if self.collide_point(*touch.pos):
self.motion_notify_event(x, y, guiEvent=None)
touch.grab(self)
if 'button' in touch.profile and touch.button in ("scrollup", "scrolldown",):
self.scroll_event(x, y, 5, guiEvent=None)
else:
self.button_press_event(x, y, self.get_mouse_button(touch),
dblclick=False, guiEvent=None)
if self.entered_figure:
self.enter_notify_event(guiEvent=None, xy=None)
else:
if not self.entered_figure:
self.leave_notify_event(guiEvent=None)
return False
def on_touch_move(self, touch):
'''Kivy Event to trigger the following matplotlib events:
`motion_notify_event`, `enter_notify_event` and `leave_notify_event`
'''
newcoord = self.to_widget(touch.x, touch.y, relative=True)
x = newcoord[0]
y = newcoord[1]
inside = self.collide_point(touch.x, touch.y)
if inside:
self.motion_notify_event(x, y, guiEvent=None)
if not inside and not self.entered_figure:
self.leave_notify_event(guiEvent=None)
self.entered_figure = True
elif inside and self.entered_figure:
self.enter_notify_event(guiEvent=None, xy=(x, y))
self.entered_figure = False
return False
def get_mouse_button(self, touch):
'''Translate kivy convention for left, right and middle click button
into matplotlib int values: 1 for left, 2 for middle and 3 for
right.
'''
if 'button' in touch.profile:
if touch.button == "left":
return 1
elif touch.button == "middle":
return 2
elif touch.button == "right":
return 3
return -1
def on_touch_up(self, touch):
'''Kivy Event to trigger the following matplotlib events:
`scroll_event` and `button_release_event`.
'''
newcoord = self.to_widget(touch.x, touch.y, relative=True)
x = newcoord[0]
y = newcoord[1]
if touch.grab_current is self:
if 'button' in touch.profile and touch.button in ("scrollup", "scrolldown",):
self.scroll_event(x, y, 5, guiEvent=None)
else:
self.button_release_event(x, y, self.get_mouse_button(touch), guiEvent=None)
touch.ungrab(self)
else:
return super(FigureCanvasKivy, self).on_touch_up(touch)
return False
def keyboard_on_key_down(self, window, keycode, text, modifiers):
'''Kivy event to trigger matplotlib `key_press_event`.
'''
self.key_press_event(keycode[1], guiEvent=None)
return super(FigureCanvasKivy, self).keyboard_on_key_down(window,
keycode, text, modifiers)
def keyboard_on_key_up(self, window, keycode):
'''Kivy event to trigger matplotlib `key_release_event`.
'''
self.key_release_event(keycode[1], guiEvent=None)
return super(FigureCanvasKivy, self).keyboard_on_key_up(window, keycode)
def _on_mouse_pos(self, *args):
'''Kivy Event to trigger the following matplotlib events:
`motion_notify_event`, `leave_notify_event` and
`enter_notify_event`.
'''
pos = args[1]
newcoord = self.to_widget(pos[0], pos[1], relative=True)
x = newcoord[0]
y = newcoord[1]
inside = self.collide_point(*pos)
if inside:
self.motion_notify_event(x, y, guiEvent=None)
if not inside and not self.entered_figure:
self.leave_notify_event(guiEvent=None)
self.entered_figure = True
elif inside and self.entered_figure:
self.enter_notify_event(guiEvent=None, xy=(pos[0], pos[1]))
self.entered_figure = False
def enter_notify_event(self, guiEvent=None, xy=None):
event = Event('figure_enter_event', self, guiEvent)
self.callbacks.process('figure_enter_event', event)
def leave_notify_event(self, guiEvent=None):
event = Event('figure_leave_event', self, guiEvent)
self.callbacks.process('figure_leave_event', event)
def _on_pos_changed(self, *args):
self.draw()
def _on_size_changed(self, *args):
'''Changes the size of the matplotlib figure based on the size of the
widget. The widget will change size according to the parent Layout
size.
'''
w, h = self.size
dpival = self.figure.dpi
winch = float(w) / dpival
hinch = float(h) / dpival
self.figure.set_size_inches(winch, hinch, forward=False)
self.resize_event()
self.draw()
def callback(self, *largs):
self.draw()
def blit(self, bbox=None):
'''If bbox is None, blit the entire canvas to the widget. Otherwise
blit only the area defined by the bbox.
'''
self.blitbox = bbox
filetypes = FigureCanvasBase.filetypes.copy()
filetypes['png'] = 'Portable Network Graphics'
def print_png(self, filename, *args, **kwargs):
'''Call the widget function to make a png of the widget.
'''
fig = FigureCanvasAgg(self.figure)
FigureCanvasAgg.draw(fig)
l, b, w, h = self.figure.bbox.bounds
texture = Texture.create(size=(w, h))
texture.blit_buffer(bytes(fig.get_renderer().buffer_rgba()),
colorfmt='rgba', bufferfmt='ubyte')
texture.flip_vertical()
img = Image(texture)
img.save(filename)
def get_default_filetype(self):
return 'png'
def new_timer(self, *args, **kwargs):
"""
Creates a new backend-specific subclass of :class:`backend_bases.Timer`.
This is useful for getting periodic events through the backend's native
event loop. Implemented only for backends with GUIs.
optional arguments:
*interval*
Timer interval in milliseconds
*callbacks*
Sequence of (func, args, kwargs) where func(*args, **kwargs) will
be executed by the timer every *interval*.
"""
return TimerKivy(*args, **kwargs)
class FigureManagerKivy(FigureManagerBase):
'''The FigureManager main function is to instantiate the backend navigation
toolbar and to call show to instantiate the App.
'''
def __init__(self, canvas, num):
super(FigureManagerKivy, self).__init__(canvas, num)
self.canvas = canvas
self.toolbar = self._get_toolbar()
def show(self):
pass
def get_window_title(self):
return Window.title
def set_window_title(self, title):
Window.title = title
def resize(self, w, h):
if (w > 0) and (h > 0):
Window.size = w, h
def _get_toolbar(self):
if rcParams['toolbar'] == 'toolbar2':
toolbar = NavigationToolbar2Kivy(self.canvas)
else:
toolbar = None
return toolbar
'''Now just provide the standard names that backend.__init__ is expecting
'''
FigureCanvas = FigureCanvasKivy
FigureManager = FigureManagerKivy
NavigationToolbar = NavigationToolbar2Kivy
|
mit
|
[
2344,
199,
8447,
1804,
10241,
199,
19989,
199,
199,
703,
1834,
447,
5935,
15,
4620,
63,
16941,
63,
2694,
14,
8476,
272,
520,
5743,
26,
2451,
199,
199,
1918,
520,
533,
1705,
25590,
15174,
43,
10241,
64,
3938,
365,
1202,
370,
1218,
282,
8027,
3343,
14,
199,
2765,
3938,
965,
314,
2011,
4382,
465,
199,
26,
533,
1705,
16941,
14,
832,
14,
2421,
14,
4620,
63,
16941,
13452,
14,
25590,
15174,
43,
10241,
7248,
2313,
16266,
15174,
43,
10241,
199,
23145,
402,
14066,
282,
2955,
1834,
12,
4440,
314,
17227,
24348,
15794,
199,
26,
533,
1705,
16941,
14,
15707,
14,
3049,
64,
436,
520,
533,
1705,
16941,
14,
15707,
14,
12241,
64,
370,
3795,
641,
314,
199,
7682,
14,
199,
199,
31456,
199,
4559,
199,
199,
1918,
8027,
4865,
367,
17227,
883,
506,
1202,
701,
1808,
314,
486,
285,
848,
3329,
315,
199,
16941,
2569,
642,
2508,
485,
1073,
26,
1455,
921,
16941,
14,
1308,
15,
4757,
15,
1246,
13,
16941,
14,
23909,
848,
14,
1360,
3800,
339,
486,
285,
848,
3907,
8027,
199,
199,
2844,
340,
1265,
2934,
370,
2387,
652,
5370,
641,
2195,
4223,
3800,
339,
12829,
3002,
571,
272,
486,
285,
848,
3907,
1553,
571,
8027,
421,
199,
5733,
2072,
199,
10965,
199,
199,
33,
4865,
883,
506,
10038,
315,
2877,
15217,
14,
710,
1642,
1373,
365,
1808,
15111,
1134,
2798,
199,
305,
1437,
23918,
199,
703,
485,
1681,
26,
1455,
921,
16440,
14,
1308,
15,
667,
81,
15,
3807,
63,
667,
81,
14,
1360,
3,
10058,
13,
374,
13,
65,
13,
4620,
447,
339,
492,
8027,
272,
8027,
14,
1180,
360,
578,
921,
16941,
14,
23909,
848,
14,
16440,
14,
4620,
63,
16941,
358,
199,
199,
25690,
642,
365,
4224,
12,
1263,
9658,
17544,
2410,
911,
506,
8072,
701,
282,
199,
26,
533,
1705,
25590,
15174,
43,
10241,
64,
10144,
370,
675,
14,
11606,
2348,
2337,
787,
2877,
1511,
370,
199,
6958,
543,
314,
16367,
14,
199,
199,
17,
14,
3645,
314,
520,
533,
1705,
25590,
15174,
43,
10241,
64,
2225,
3247,
465,
10218,
687,
16266,
12,
199,
475,
6441,
2195,
8027,
3343,
315,
2195,
5705,
1804,
10241,
4223,
465,
883,
506,
6775,
315,
199,
1589,
1642,
2893,
315,
314,
2569,
3420,
14,
199,
199,
703,
5721,
447,
339,
7309,
883,
1218,
282,
8027,
3938,
701,
16306,
16266,
15174,
447,
398,
687,
17227,
14,
23909,
848,
14,
16440,
14,
4620,
63,
16941,
13452,
492,
16266,
15174,
267,
503,
267,
687,
17227,
14,
23909,
848,
14,
16440,
14,
4620,
63,
16941,
492,
16266,
15174,
339,
436,
2066,
17321,
376,
909,
447,
398,
6085,
12,
2185,
275,
4488,
14,
21430,
342,
267,
3002,
63,
2421,
63,
16941,
63,
3440,
275,
16266,
15174,
8,
592,
9,
339,
1314,
911,
9842,
590,
1736,
1325,
282,
5160,
911,
14554,
261,
340,
4474,
4898,
8539,
272,
2544,
314,
16266,
15174,
365,
17544,
14,
982,
642,
18140,
365,
9394,
8749,
272,
4907,
8027,
4474,
2410,
12999,
314,
8027,
17227,
3938,
272,
909,
3800,
398,
6085,
12,
2185,
275,
4488,
14,
21430,
342,
267,
6085,
14,
7682,
14,
2421,
63,
2242,
360,
3887,
63,
2915,
63,
1430,
297,
3233,
63,
2232,
9,
267,
3002,
63,
2421,
63,
16941,
63,
3440,
275,
16266,
15174,
8,
592,
9,
339,
1010,
642,
15728,
5528,
63,
2915,
63,
1430,
7859,
1133,
506,
8539,
543,
314,
909,
272,
3769,
2737,
315,
1004,
650,
12,
2952,
911,
506,
8539,
370,
314,
849,
10218,
272,
663,
701,
8027,
14,
982,
642,
18140,
365,
9394,
506,
3238,
402,
18170,
314,
272,
4474,
2410,
26621,
2839,
314,
2569,
26,
3800,
398,
6085,
12,
2185,
275,
4488,
14,
21430,
342,
267,
3002,
63,
2421,
63,
16941,
63,
3440,
275,
16266,
15174,
8,
592,
9,
267,
6085,
14,
7682,
14,
2421,
63,
2242,
360,
3887,
63,
2915,
63,
1430,
297,
3233,
63,
2232,
9,
199,
199,
18,
14,
3645,
1134,
2798,
370,
2218,
314,
4223,
2569,
8027,
308,
442,
1219,
465,
883,
506,
199,
8606,
315,
314,
3499,
2893,
5084,
14,
1010,
642,
1930,
282,
1804,
10241,
4223,
911,
506,
199,
3966,
5847,
687,
314,
8027,
15794,
436,
282,
20721,
5360,
29630,
199,
14117,
506,
3483,
370,
314,
2446,
10218,
14,
421,
199,
22787,
199,
518,
199,
199,
17,
14,
5679,
402,
282,
3486,
23833,
6701,
8027,
4693,
447,
339,
6085,
12,
2185,
275,
4488,
14,
21430,
342,
272,
2185,
14,
505,
8,
16,
14,
22,
12,
378,
14,
21,
12,
298,
5006,
401,
1568,
29,
1400,
12,
13038,
29,
1216,
2020,
288,
18251,
628,
4218,
401,
25819,
628,
4218,
401,
288,
12494,
29,
807,
8,
1977,
2487,
628,
2363,
401,
1993,
7062,
2687,
17,
2020,
378,
14,
21,
12,
378,
14,
21,
395,
1993,
10821,
2687,
17,
2020,
378,
14,
24,
12,
378,
14,
24,
395,
1993,
776,
288,
776,
272,
2185,
14,
505,
8,
16,
14,
21,
12,
378,
14,
20,
12,
298,
7617,
401,
1568,
29,
1400,
12,
13038,
4022,
1216,
2020,
288,
18251,
628,
1019,
401,
25819,
628,
2119,
401,
288,
12494,
29,
807,
8,
1977,
2487,
628,
9646,
401,
1993,
7062,
2687,
17,
2020,
378,
14,
21,
12,
378,
14,
21,
395,
1993,
10821,
2687,
17,
2020,
378,
14,
24,
12,
378,
14,
24,
395,
1993,
776,
288,
776,
272,
10218,
275,
6085,
14,
7682,
199,
199,
1918,
909,
10218,
883,
506,
3483,
465,
282,
3938,
1901,
314,
17227,
3123,
3938,
14,
199,
3917,
282,
1570,
365,
4224,
641,
314,
9658,
376,
1678,
883,
506,
10585,
1808,
199,
26,
5247,
6054,
16941,
14,
832,
14,
2421,
14,
4620,
63,
16941,
13452,
14,
25590,
15174,
43,
10241,
7248,
14,
5485,
2313,
447,
339,
327,
1678,
3343,
272,
10218,
14,
5485,
342,
199,
199,
1918,
5137,
883,
506,
16629,
370,
25296,
543,
199,
26,
5247,
6054,
16941,
14,
832,
14,
2421,
14,
4620,
63,
16941,
13452,
14,
25590,
15174,
43,
10241,
7248,
14,
1361,
63,
4524,
3559,
465,
376,
199,
2094,
23192,
314,
658,
1501,
2313,
447,
339,
327,
4843,
370,
25296,
272,
10218,
14,
1361,
63,
4524,
480,
1662,
63,
2798,
14,
4524,
531,
199,
199,
18,
14,
5679,
402,
282,
1134,
2798,
4223,
1808,
8027,
15794,
447,
339,
492,
2680,
465,
980,
272,
492,
8027,
14,
13563,
465,
4488,
339,
653,
275,
959,
272
] |
[
199,
8447,
1804,
10241,
199,
19989,
199,
199,
703,
1834,
447,
5935,
15,
4620,
63,
16941,
63,
2694,
14,
8476,
272,
520,
5743,
26,
2451,
199,
199,
1918,
520,
533,
1705,
25590,
15174,
43,
10241,
64,
3938,
365,
1202,
370,
1218,
282,
8027,
3343,
14,
199,
2765,
3938,
965,
314,
2011,
4382,
465,
199,
26,
533,
1705,
16941,
14,
832,
14,
2421,
14,
4620,
63,
16941,
13452,
14,
25590,
15174,
43,
10241,
7248,
2313,
16266,
15174,
43,
10241,
199,
23145,
402,
14066,
282,
2955,
1834,
12,
4440,
314,
17227,
24348,
15794,
199,
26,
533,
1705,
16941,
14,
15707,
14,
3049,
64,
436,
520,
533,
1705,
16941,
14,
15707,
14,
12241,
64,
370,
3795,
641,
314,
199,
7682,
14,
199,
199,
31456,
199,
4559,
199,
199,
1918,
8027,
4865,
367,
17227,
883,
506,
1202,
701,
1808,
314,
486,
285,
848,
3329,
315,
199,
16941,
2569,
642,
2508,
485,
1073,
26,
1455,
921,
16941,
14,
1308,
15,
4757,
15,
1246,
13,
16941,
14,
23909,
848,
14,
1360,
3800,
339,
486,
285,
848,
3907,
8027,
199,
199,
2844,
340,
1265,
2934,
370,
2387,
652,
5370,
641,
2195,
4223,
3800,
339,
12829,
3002,
571,
272,
486,
285,
848,
3907,
1553,
571,
8027,
421,
199,
5733,
2072,
199,
10965,
199,
199,
33,
4865,
883,
506,
10038,
315,
2877,
15217,
14,
710,
1642,
1373,
365,
1808,
15111,
1134,
2798,
199,
305,
1437,
23918,
199,
703,
485,
1681,
26,
1455,
921,
16440,
14,
1308,
15,
667,
81,
15,
3807,
63,
667,
81,
14,
1360,
3,
10058,
13,
374,
13,
65,
13,
4620,
447,
339,
492,
8027,
272,
8027,
14,
1180,
360,
578,
921,
16941,
14,
23909,
848,
14,
16440,
14,
4620,
63,
16941,
358,
199,
199,
25690,
642,
365,
4224,
12,
1263,
9658,
17544,
2410,
911,
506,
8072,
701,
282,
199,
26,
533,
1705,
25590,
15174,
43,
10241,
64,
10144,
370,
675,
14,
11606,
2348,
2337,
787,
2877,
1511,
370,
199,
6958,
543,
314,
16367,
14,
199,
199,
17,
14,
3645,
314,
520,
533,
1705,
25590,
15174,
43,
10241,
64,
2225,
3247,
465,
10218,
687,
16266,
12,
199,
475,
6441,
2195,
8027,
3343,
315,
2195,
5705,
1804,
10241,
4223,
465,
883,
506,
6775,
315,
199,
1589,
1642,
2893,
315,
314,
2569,
3420,
14,
199,
199,
703,
5721,
447,
339,
7309,
883,
1218,
282,
8027,
3938,
701,
16306,
16266,
15174,
447,
398,
687,
17227,
14,
23909,
848,
14,
16440,
14,
4620,
63,
16941,
13452,
492,
16266,
15174,
267,
503,
267,
687,
17227,
14,
23909,
848,
14,
16440,
14,
4620,
63,
16941,
492,
16266,
15174,
339,
436,
2066,
17321,
376,
909,
447,
398,
6085,
12,
2185,
275,
4488,
14,
21430,
342,
267,
3002,
63,
2421,
63,
16941,
63,
3440,
275,
16266,
15174,
8,
592,
9,
339,
1314,
911,
9842,
590,
1736,
1325,
282,
5160,
911,
14554,
261,
340,
4474,
4898,
8539,
272,
2544,
314,
16266,
15174,
365,
17544,
14,
982,
642,
18140,
365,
9394,
8749,
272,
4907,
8027,
4474,
2410,
12999,
314,
8027,
17227,
3938,
272,
909,
3800,
398,
6085,
12,
2185,
275,
4488,
14,
21430,
342,
267,
6085,
14,
7682,
14,
2421,
63,
2242,
360,
3887,
63,
2915,
63,
1430,
297,
3233,
63,
2232,
9,
267,
3002,
63,
2421,
63,
16941,
63,
3440,
275,
16266,
15174,
8,
592,
9,
339,
1010,
642,
15728,
5528,
63,
2915,
63,
1430,
7859,
1133,
506,
8539,
543,
314,
909,
272,
3769,
2737,
315,
1004,
650,
12,
2952,
911,
506,
8539,
370,
314,
849,
10218,
272,
663,
701,
8027,
14,
982,
642,
18140,
365,
9394,
506,
3238,
402,
18170,
314,
272,
4474,
2410,
26621,
2839,
314,
2569,
26,
3800,
398,
6085,
12,
2185,
275,
4488,
14,
21430,
342,
267,
3002,
63,
2421,
63,
16941,
63,
3440,
275,
16266,
15174,
8,
592,
9,
267,
6085,
14,
7682,
14,
2421,
63,
2242,
360,
3887,
63,
2915,
63,
1430,
297,
3233,
63,
2232,
9,
199,
199,
18,
14,
3645,
1134,
2798,
370,
2218,
314,
4223,
2569,
8027,
308,
442,
1219,
465,
883,
506,
199,
8606,
315,
314,
3499,
2893,
5084,
14,
1010,
642,
1930,
282,
1804,
10241,
4223,
911,
506,
199,
3966,
5847,
687,
314,
8027,
15794,
436,
282,
20721,
5360,
29630,
199,
14117,
506,
3483,
370,
314,
2446,
10218,
14,
421,
199,
22787,
199,
518,
199,
199,
17,
14,
5679,
402,
282,
3486,
23833,
6701,
8027,
4693,
447,
339,
6085,
12,
2185,
275,
4488,
14,
21430,
342,
272,
2185,
14,
505,
8,
16,
14,
22,
12,
378,
14,
21,
12,
298,
5006,
401,
1568,
29,
1400,
12,
13038,
29,
1216,
2020,
288,
18251,
628,
4218,
401,
25819,
628,
4218,
401,
288,
12494,
29,
807,
8,
1977,
2487,
628,
2363,
401,
1993,
7062,
2687,
17,
2020,
378,
14,
21,
12,
378,
14,
21,
395,
1993,
10821,
2687,
17,
2020,
378,
14,
24,
12,
378,
14,
24,
395,
1993,
776,
288,
776,
272,
2185,
14,
505,
8,
16,
14,
21,
12,
378,
14,
20,
12,
298,
7617,
401,
1568,
29,
1400,
12,
13038,
4022,
1216,
2020,
288,
18251,
628,
1019,
401,
25819,
628,
2119,
401,
288,
12494,
29,
807,
8,
1977,
2487,
628,
9646,
401,
1993,
7062,
2687,
17,
2020,
378,
14,
21,
12,
378,
14,
21,
395,
1993,
10821,
2687,
17,
2020,
378,
14,
24,
12,
378,
14,
24,
395,
1993,
776,
288,
776,
272,
10218,
275,
6085,
14,
7682,
199,
199,
1918,
909,
10218,
883,
506,
3483,
465,
282,
3938,
1901,
314,
17227,
3123,
3938,
14,
199,
3917,
282,
1570,
365,
4224,
641,
314,
9658,
376,
1678,
883,
506,
10585,
1808,
199,
26,
5247,
6054,
16941,
14,
832,
14,
2421,
14,
4620,
63,
16941,
13452,
14,
25590,
15174,
43,
10241,
7248,
14,
5485,
2313,
447,
339,
327,
1678,
3343,
272,
10218,
14,
5485,
342,
199,
199,
1918,
5137,
883,
506,
16629,
370,
25296,
543,
199,
26,
5247,
6054,
16941,
14,
832,
14,
2421,
14,
4620,
63,
16941,
13452,
14,
25590,
15174,
43,
10241,
7248,
14,
1361,
63,
4524,
3559,
465,
376,
199,
2094,
23192,
314,
658,
1501,
2313,
447,
339,
327,
4843,
370,
25296,
272,
10218,
14,
1361,
63,
4524,
480,
1662,
63,
2798,
14,
4524,
531,
199,
199,
18,
14,
5679,
402,
282,
1134,
2798,
4223,
1808,
8027,
15794,
447,
339,
492,
2680,
465,
980,
272,
492,
8027,
14,
13563,
465,
4488,
339,
653,
275,
959,
272,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
t-hey/QGIS-Original
|
python/plugins/processing/gui/FileSelectionPanel.py
|
8
|
3239
|
# -*- coding: utf-8 -*-
"""
***************************************************************************
FileSelectionPanel.py
---------------------
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* 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__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
import os
from qgis.PyQt import uic
from qgis.PyQt.QtWidgets import QFileDialog
from qgis.core import QgsSettings
from processing.tools.system import isWindows
pluginPath = os.path.split(os.path.dirname(__file__))[0]
WIDGET, BASE = uic.loadUiType(
os.path.join(pluginPath, 'ui', 'widgetBaseSelector.ui'))
class FileSelectionPanel(BASE, WIDGET):
def __init__(self, isFolder, ext=None):
super(FileSelectionPanel, self).__init__(None)
self.setupUi(self)
self.ext = ext or '*'
self.isFolder = isFolder
self.btnSelect.clicked.connect(self.showSelectionDialog)
def showSelectionDialog(self):
# Find the file dialog's working directory
settings = QgsSettings()
text = self.leText.text()
if os.path.isdir(text):
path = text
elif os.path.isdir(os.path.dirname(text)):
path = os.path.dirname(text)
elif settings.contains('/Processing/LastInputPath'):
path = settings.value('/Processing/LastInputPath')
else:
path = ''
if self.isFolder:
folder = QFileDialog.getExistingDirectory(self,
self.tr('Select folder'), path)
if folder:
self.leText.setText(folder)
settings.setValue('/Processing/LastInputPath',
os.path.dirname(folder))
else:
filenames, selected_filter = QFileDialog.getOpenFileNames(self,
self.tr('Select file'), path, self.tr('{} files').format(self.ext.upper()) + ' (*.' + self.ext + self.tr(');;All files (*.*)'))
if filenames:
self.leText.setText(u';'.join(filenames))
settings.setValue('/Processing/LastInputPath',
os.path.dirname(filenames[0]))
def getValue(self):
s = self.leText.text()
if isWindows():
s = s.replace('\\', '/')
return s
def setText(self, text):
self.leText.setText(text)
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
3814,
7713,
10185,
14,
647,
272,
10652,
9858,
272,
6148,
463,
520,
25298,
833,
6029,
272,
1898,
3322,
520,
334,
35,
9,
6029,
701,
6561,
630,
593,
817,
65,
272,
11426,
4483,
520,
5236,
1187,
2756,
737,
29712,
6308,
2414,
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,
2201,
630,
593,
817,
65,
7,
199,
363,
602,
363,
275,
283,
21640,
833,
6029,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
6029,
12,
6561,
630,
593,
817,
65,
7,
199,
199,
3,
961,
911,
664,
8717,
543,
282,
6135,
12002,
17,
1380,
1265,
886,
282,
6135,
6359,
199,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
199,
646,
747,
199,
199,
504,
15640,
14,
24107,
492,
399,
530,
199,
504,
15640,
14,
24107,
14,
29081,
492,
1413,
25213,
199,
504,
15640,
14,
1018,
492,
4888,
5268,
199,
199,
504,
6661,
14,
2537,
14,
2253,
492,
365,
8647,
199,
199,
2718,
2042,
275,
747,
14,
515,
14,
1294,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
59,
16,
61,
199,
9845,
2970,
12,
19721,
275,
399,
530,
14,
912,
18203,
804,
8,
272,
747,
14,
515,
14,
904,
8,
2718,
2042,
12,
283,
1907,
297,
283,
3440,
1563,
11212,
14,
1907,
1333,
421,
199,
533,
3814,
7713,
10185,
8,
5825,
12,
644,
998,
2970,
304,
339,
347,
636,
826,
721,
277,
12,
365,
7850,
12,
1599,
29,
403,
304,
267,
1613,
8,
1173,
7713,
10185,
12,
291,
2843,
826,
721,
403,
9,
267,
291,
14,
2758,
18203,
8,
277,
9,
398,
291,
14,
832,
275,
1599,
503,
13626,
267,
291,
14,
374,
7850,
275,
365,
7850,
398,
291,
14,
9633,
5446,
14,
11276,
14,
2242,
8,
277,
14,
2384,
7713,
5619,
9,
339,
347,
2498,
7713,
5619,
8,
277,
304,
267,
327,
6668,
314,
570,
9592,
1159,
6449,
2082,
267,
2202,
275,
4888,
5268,
342,
267,
1318,
275,
291,
14,
274,
1872,
14,
505,
342,
267,
340,
747,
14,
515,
14,
6027,
8,
505,
304,
288,
931,
275,
1318,
267,
916,
747,
14,
515,
14,
6027,
8,
736,
14,
515,
14,
3475,
8,
505,
2298,
288,
931,
275,
747,
14,
515,
14,
3475,
8,
505,
9,
267,
916,
2202,
14,
6134,
2336,
9589,
15,
6090,
3205,
2042,
735,
288,
931,
275,
2202,
14,
585,
2336,
9589,
15,
6090,
3205,
2042,
358,
267,
587,
26,
288,
931,
275,
2125,
398,
340,
291,
14,
374,
7850,
26,
288,
4922,
275,
1413,
25213,
14,
362,
23490,
6231,
8,
277,
12,
10028,
291,
14,
454,
360,
5446,
4922,
659,
931,
9,
288,
340,
4922,
26,
355,
291,
14,
274,
1872,
14,
8341,
8,
3741,
9,
355,
2202,
14,
14733,
2336,
9589,
15,
6090,
3205,
2042,
297,
3303,
747,
14,
515,
14,
3475,
8,
3741,
430,
267,
587,
26,
288,
6203,
12,
4895,
63,
1541,
275,
1413,
25213,
14,
362,
4299,
1173,
5866,
8,
277,
12,
6684,
420,
291,
14,
454,
360,
5446,
570,
659,
931,
12,
291,
14,
454,
17519,
1584,
1959,
908,
8,
277,
14,
832,
14,
4142,
1012,
435,
283,
19943,
3530,
435,
291,
14,
832,
435,
291,
14,
454,
8,
11339,
27,
2422,
1584,
19943,
12432,
1333,
288,
340,
6203,
26,
355,
291,
14,
274,
1872,
14,
8341,
8,
85,
13619,
1370,
904,
8,
10309,
430,
355,
2202,
14,
14733,
2336,
9589,
15,
6090,
3205,
2042,
297,
3303,
747,
14,
515,
14,
3475,
8,
10309,
59,
16,
2459,
339,
347,
664,
1110,
8,
277,
304,
267,
308,
275,
291,
14,
274,
1872,
14,
505,
342,
267,
340,
365,
8647,
837,
288,
308,
275,
308,
14,
1814,
20786,
15107,
267,
372,
308,
339,
347,
663,
1872,
8,
277,
12,
1318,
304,
267,
291,
14,
274,
1872,
14,
8341,
8,
505,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
3814,
7713,
10185,
14,
647,
272,
10652,
9858,
272,
6148,
463,
520,
25298,
833,
6029,
272,
1898,
3322,
520,
334,
35,
9,
6029,
701,
6561,
630,
593,
817,
65,
272,
11426,
4483,
520,
5236,
1187,
2756,
737,
29712,
6308,
2414,
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,
2201,
630,
593,
817,
65,
7,
199,
363,
602,
363,
275,
283,
21640,
833,
6029,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
6029,
12,
6561,
630,
593,
817,
65,
7,
199,
199,
3,
961,
911,
664,
8717,
543,
282,
6135,
12002,
17,
1380,
1265,
886,
282,
6135,
6359,
199,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
199,
646,
747,
199,
199,
504,
15640,
14,
24107,
492,
399,
530,
199,
504,
15640,
14,
24107,
14,
29081,
492,
1413,
25213,
199,
504,
15640,
14,
1018,
492,
4888,
5268,
199,
199,
504,
6661,
14,
2537,
14,
2253,
492,
365,
8647,
199,
199,
2718,
2042,
275,
747,
14,
515,
14,
1294,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
59,
16,
61,
199,
9845,
2970,
12,
19721,
275,
399,
530,
14,
912,
18203,
804,
8,
272,
747,
14,
515,
14,
904,
8,
2718,
2042,
12,
283,
1907,
297,
283,
3440,
1563,
11212,
14,
1907,
1333,
421,
199,
533,
3814,
7713,
10185,
8,
5825,
12,
644,
998,
2970,
304,
339,
347,
636,
826,
721,
277,
12,
365,
7850,
12,
1599,
29,
403,
304,
267,
1613,
8,
1173,
7713,
10185,
12,
291,
2843,
826,
721,
403,
9,
267,
291,
14,
2758,
18203,
8,
277,
9,
398,
291,
14,
832,
275,
1599,
503,
13626,
267,
291,
14,
374,
7850,
275,
365,
7850,
398,
291,
14,
9633,
5446,
14,
11276,
14,
2242,
8,
277,
14,
2384,
7713,
5619,
9,
339,
347,
2498,
7713,
5619,
8,
277,
304,
267,
327,
6668,
314,
570,
9592,
1159,
6449,
2082,
267,
2202,
275,
4888,
5268,
342,
267,
1318,
275,
291,
14,
274,
1872,
14,
505,
342,
267,
340,
747,
14,
515,
14,
6027,
8,
505,
304,
288,
931,
275,
1318,
267,
916,
747,
14,
515,
14,
6027,
8,
736,
14,
515,
14,
3475,
8,
505,
2298,
288,
931,
275,
747,
14,
515,
14,
3475,
8,
505,
9,
267,
916,
2202,
14,
6134,
2336,
9589,
15,
6090,
3205,
2042,
735,
288,
931,
275,
2202,
14,
585,
2336,
9589,
15,
6090,
3205,
2042,
358,
267,
587,
26,
288,
931,
275,
2125,
398,
340,
291,
14,
374,
7850,
26,
288,
4922,
275,
1413,
25213,
14,
362,
23490,
6231,
8,
277,
12,
10028,
291,
14,
454,
360,
5446,
4922,
659,
931,
9,
288,
340,
4922,
26,
355,
291,
14,
274,
1872,
14,
8341,
8,
3741,
9,
355,
2202,
14,
14733,
2336,
9589,
15,
6090,
3205,
2042,
297,
3303,
747,
14,
515,
14,
3475,
8,
3741,
430,
267,
587,
26,
288,
6203,
12,
4895,
63,
1541,
275,
1413,
25213,
14,
362,
4299,
1173,
5866,
8,
277,
12,
6684,
420,
291,
14,
454,
360,
5446,
570,
659,
931,
12,
291,
14,
454,
17519,
1584,
1959,
908,
8,
277,
14,
832,
14,
4142,
1012,
435,
283,
19943,
3530,
435,
291,
14,
832,
435,
291,
14,
454,
8,
11339,
27,
2422,
1584,
19943,
12432,
1333,
288,
340,
6203,
26,
355,
291,
14,
274,
1872,
14,
8341,
8,
85,
13619,
1370,
904,
8,
10309,
430,
355,
2202,
14,
14733,
2336,
9589,
15,
6090,
3205,
2042,
297,
3303,
747,
14,
515,
14,
3475,
8,
10309,
59,
16,
2459,
339,
347,
664,
1110,
8,
277,
304,
267,
308,
275,
291,
14,
274,
1872,
14,
505,
342,
267,
340,
365,
8647,
837,
288,
308,
275,
308,
14,
1814,
20786,
15107,
267,
372,
308,
339,
347,
663,
1872,
8,
277,
12,
1318,
304,
267,
291,
14,
274,
1872,
14,
8341,
8,
505,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
odoomrp/odoomrp-wip
|
product_variant_default_code/models/product.py
|
12
|
7401
|
# -*- encoding: utf-8 -*-
##############################################################################
#
# 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 models, fields, api, _
from openerp.exceptions import except_orm
import re
from string import Template
from collections import defaultdict
DEFAULT_REFERENCE_SEPARATOR = '-'
PLACE_HOLDER_4_MISSING_VALUE = '/'
class ReferenceMask(Template):
pattern = r'''\[(?:
(?P<escaped>\[) |
(?P<named>[^\]]+?)\] |
(?P<braced>[^\]]+?)\] |
(?P<invalid>)
)'''
def extract_token(s):
pattern = re.compile(r'\[([^\]]+?)\]')
return set(pattern.findall(s))
def sanitize_reference_mask(product, mask):
tokens = extract_token(mask)
attribute_names = set()
for line in product.attribute_line_ids:
attribute_names.add(line.attribute_id.name)
if not tokens.issubset(attribute_names):
raise except_orm(_('Error'), _('Found unrecognized attribute name in '
'"Variant Reference Mask"'))
def get_rendered_default_code(product, mask):
product_attrs = defaultdict(str)
reference_mask = ReferenceMask(mask)
for value in product.attribute_value_ids:
if value.attribute_code:
product_attrs[value.attribute_id.name] += value.attribute_code
all_attrs = extract_token(mask)
missing_attrs = all_attrs - set(product_attrs.keys())
missing = dict.fromkeys(missing_attrs, PLACE_HOLDER_4_MISSING_VALUE)
product_attrs.update(missing)
default_code = reference_mask.safe_substitute(product_attrs)
return default_code
def render_default_code(product, mask):
product.default_code = get_rendered_default_code(product, mask)
class ProductTemplate(models.Model):
_inherit = 'product.template'
reference_mask = fields.Char(
string='Variant reference mask',
help='Reference mask for building internal references of a '
'variant generated from this template.\n'
'Example:\n'
'A product named ABC with 2 attributes: Size and Color:\n'
'Product: ABC\n'
'Color: Red(r), Yellow(y), Black(b) #Red, Yellow, Black are '
'the attribute value, `r`, `y`, `b` are the corresponding code\n'
'Size: L (l), XL(x)\n'
'When setting Variant reference mask to `[Color]-[Size]`, the '
'default code on the variants will be something like `r-l` '
'`b-l` `r-x` ...\n'
'If you like, You can even have the attribute name appear more'
' than once in the mask. Such as , `fancyA/[Size]~[Color]~[Size]`'
' When saved, the default code on variants will be something like'
' `fancyA/l~r~l` (for variant with Color "Red" and Size "L") '
'`fancyA/x~y~x` (for variant with Color "Yellow" and Size "XL")\n'
'Note: make sure characters "[,]" do not appear in your '
'attribute name')
@api.model
def create(self, vals):
product = self.new(vals)
if not vals.get('reference_mask') and product.attribute_line_ids:
attribute_names = []
for line in product.attribute_line_ids:
attribute_names.append("[{}]".format(line.attribute_id.name))
default_mask = DEFAULT_REFERENCE_SEPARATOR.join(attribute_names)
vals['reference_mask'] = default_mask
elif vals.get('reference_mask'):
sanitize_reference_mask(product, vals['reference_mask'])
return super(ProductTemplate, self).create(vals)
@api.one
def write(self, vals):
product_obj = self.env['product.product']
if 'reference_mask' in vals and not vals['reference_mask']:
if self.attribute_line_ids:
attribute_names = []
for line in self.attribute_line_ids:
attribute_names.append("[{}]".format(
line.attribute_id.name))
default_mask = DEFAULT_REFERENCE_SEPARATOR.join(
attribute_names)
vals['reference_mask'] = default_mask
result = super(ProductTemplate, self).write(vals)
if vals.get('reference_mask'):
cond = [('product_tmpl_id', '=', self.id),
('manual_code', '=', False)]
products = product_obj.search(cond)
for product in products:
if product.reference_mask:
render_default_code(product, product.reference_mask)
return result
class ProductProduct(models.Model):
_inherit = 'product.product'
manual_code = fields.Boolean(string='Manual code')
@api.model
def create(self, values):
product = super(ProductProduct, self).create(values)
if product.reference_mask:
render_default_code(product, product.reference_mask)
return product
@api.one
@api.onchange('default_code')
def onchange_default_code(self):
self.manual_code = bool(self.default_code)
class ProductAttribute(models.Model):
_inherit = 'product.attribute'
_sql_constraints = [
('number_uniq', 'unique(name)', _('Attribute Name must be unique!'))]
class ProductAttributeValue(models.Model):
_inherit = 'product.attribute.value'
@api.one
@api.onchange('name')
def onchange_name(self):
if self.name:
self.attribute_code = self.name[0:2]
attribute_code = fields.Char(
string='Attribute Code', default=onchange_name)
@api.model
def create(self, values):
if 'attribute_code' not in values:
values['attribute_code'] = values.get('name', '')[0:2]
value = super(ProductAttributeValue, self).create(values)
return value
@api.one
def write(self, vals):
attribute_line_obj = self.env['product.attribute.line']
product_obj = self.env['product.product']
result = super(ProductAttributeValue, self).write(vals)
if 'attribute_code' in vals:
cond = [('attribute_id', '=', self.attribute_id.id)]
attribute_lines = attribute_line_obj.search(cond)
for line in attribute_lines:
cond = [('product_tmpl_id', '=', line.product_tmpl_id.id),
('manual_code', '=', False)]
products = product_obj.search(cond)
for product in products:
if product.reference_mask:
render_default_code(product, product.reference_mask)
return result
|
agpl-3.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
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,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
8083,
199,
3,
199,
4605,
199,
504,
5166,
492,
1709,
12,
1504,
12,
2986,
12,
485,
199,
504,
5166,
14,
3924,
492,
871,
63,
1025,
199,
646,
295,
199,
504,
1059,
492,
5458,
199,
504,
5055,
492,
10018,
199,
199,
3472,
63,
31177,
63,
15828,
275,
10791,
199,
23068,
63,
40,
15744,
63,
20,
63,
18701,
63,
7041,
275,
7324,
421,
199,
533,
10944,
5144,
8,
4231,
304,
272,
3851,
275,
519,
891,
30181,
5169,
490,
7558,
48,
28,
13572,
3072,
59,
9,
1204,
490,
7558,
48,
28,
4579,
13489,
60,
2677,
23778,
2862,
61,
1204,
490,
7558,
48,
28,
22359,
68,
13489,
60,
2677,
23778,
2862,
61,
1204,
490,
7558,
48,
28,
3197,
18956,
490,
776,
2344,
421,
199,
318,
5536,
63,
1418,
8,
83,
304,
272,
3851,
275,
295,
14,
2014,
8,
82,
30181,
21690,
2677,
23778,
2862,
10374,
272,
372,
663,
8,
3401,
14,
6452,
8,
83,
430,
421,
199,
318,
21077,
63,
4443,
63,
2629,
8,
2558,
12,
3656,
304,
272,
4645,
275,
5536,
63,
1418,
8,
2629,
9,
272,
2225,
63,
1247,
275,
663,
342,
272,
367,
1004,
315,
3336,
14,
3215,
63,
604,
63,
1580,
26,
267,
2225,
63,
1247,
14,
525,
8,
604,
14,
3215,
63,
344,
14,
354,
9,
272,
340,
440,
4645,
14,
374,
9401,
8,
3215,
63,
1247,
304,
267,
746,
871,
63,
1025,
6723,
547,
659,
4018,
3601,
24718,
2225,
536,
315,
283,
4318,
5522,
12935,
10944,
17581,
2,
1333,
421,
199,
318,
664,
63,
16841,
63,
885,
63,
600,
8,
2558,
12,
3656,
304,
272,
3336,
63,
3288,
275,
10018,
8,
495,
9,
272,
3659,
63,
2629,
275,
10944,
5144,
8,
2629,
9,
272,
367,
574,
315,
3336,
14,
3215,
63,
585,
63,
1580,
26,
267,
340,
574,
14,
3215,
63,
600,
26,
288,
3336,
63,
3288,
59,
585,
14,
3215,
63,
344,
14,
354,
61,
847,
574,
14,
3215,
63,
600,
272,
1006,
63,
3288,
275,
5536,
63,
1418,
8,
2629,
9,
272,
4124,
63,
3288,
275,
1006,
63,
3288,
446,
663,
8,
2558,
63,
3288,
14,
1612,
1012,
272,
4124,
275,
1211,
14,
19164,
8,
4752,
63,
3288,
12,
10092,
4121,
63,
40,
15744,
63,
20,
63,
18701,
63,
7041,
9,
272,
3336,
63,
3288,
14,
873,
8,
4752,
9,
272,
849,
63,
600,
275,
3659,
63,
2629,
14,
3489,
63,
20374,
8,
2558,
63,
3288,
9,
272,
372,
849,
63,
600,
421,
199,
318,
3795,
63,
885,
63,
600,
8,
2558,
12,
3656,
304,
272,
3336,
14,
885,
63,
600,
275,
664,
63,
16841,
63,
885,
63,
600,
8,
2558,
12,
3656,
9,
421,
199,
533,
12705,
4231,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
2558,
14,
1160,
7,
339,
3659,
63,
2629,
275,
1504,
14,
1610,
8,
267,
1059,
534,
12935,
3659,
3656,
297,
267,
1720,
534,
5083,
3656,
367,
10015,
5007,
6941,
402,
282,
283,
1467,
283,
8759,
4046,
687,
642,
1978,
3134,
78,
7,
10798,
283,
9846,
3427,
78,
7,
1467,
283,
33,
3336,
4310,
17281,
543,
499,
3004,
26,
14579,
436,
11581,
3427,
78,
7,
10798,
283,
5884,
26,
17281,
60,
78,
7,
1467,
283,
4117,
26,
9572,
8,
82,
395,
1488,
10723,
8,
89,
395,
30593,
8,
66,
9,
221,
327,
10858,
12,
1488,
10723,
12,
30593,
787,
283,
1467,
283,
1589,
2225,
574,
12,
658,
82,
3559,
658,
89,
3559,
658,
66,
64,
787,
314,
5226,
1233,
60,
78,
7,
1467,
283,
2320,
26,
491,
334,
76,
395,
1323,
44,
8,
88,
2862,
78,
7,
10798,
283,
11423,
4260,
21107,
867,
3659,
3656,
370,
14505,
4117,
11285,
59,
2320,
61,
3559,
314,
283,
1467,
283,
885,
1233,
641,
314,
21169,
911,
506,
6020,
2839,
658,
82,
13,
76,
64,
283,
1467,
26144,
66,
13,
76,
64,
658,
82,
13,
88,
64,
2263,
60,
78,
7,
10798,
283,
3917,
1265,
2839,
12,
2047,
883,
2755,
1172,
314,
2225,
536,
7468,
1655,
7,
1467,
283,
2419,
5403,
315,
314,
3656,
14,
32753,
465,
2360,
658,
25352,
33,
32418,
2320,
61,
94,
59,
4117,
61,
94,
59,
2320,
16090,
7,
1467,
283,
3979,
6290,
12,
314,
849,
1233,
641,
21169,
911,
506,
6020,
2839,
7,
1467,
283,
658,
25352,
33,
15,
76,
94,
82,
94,
76,
64,
334,
509,
9854,
543,
11581,
298,
10858,
2,
436,
14579,
298,
44,
531,
283,
1467,
26144,
25352,
33,
15,
88,
94,
89,
94,
88,
64,
334,
509,
9854,
543,
11581,
298,
57,
10723,
2,
436,
14579,
298,
25774,
27681,
78,
7,
10798,
283,
7443,
26,
1852,
3238,
4110,
7369,
12,
8480,
886,
440,
7468,
315,
2195,
283,
1467,
283,
3215,
536,
358,
339,
768,
1246,
14,
1238,
272,
347,
1218,
8,
277,
12,
5322,
304,
267,
3336,
275,
291,
14,
1222,
8,
3643,
9,
267,
340,
440,
5322,
14,
362,
360,
4443,
63,
2629,
358,
436,
3336,
14,
3215,
63,
604,
63,
1580,
26,
288,
2225,
63,
1247,
275,
942,
288,
367,
1004,
315,
3336,
14,
3215,
63,
604,
63,
1580,
26,
355,
2225,
63,
1247,
14,
740,
10994,
27922,
1674,
908,
8,
604,
14,
3215,
63,
344,
14,
354,
430,
288,
849,
63,
2629,
275,
6186,
63,
31177,
63,
15828,
14,
904,
8
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
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,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
8083,
199,
3,
199,
4605,
199,
504,
5166,
492,
1709,
12,
1504,
12,
2986,
12,
485,
199,
504,
5166,
14,
3924,
492,
871,
63,
1025,
199,
646,
295,
199,
504,
1059,
492,
5458,
199,
504,
5055,
492,
10018,
199,
199,
3472,
63,
31177,
63,
15828,
275,
10791,
199,
23068,
63,
40,
15744,
63,
20,
63,
18701,
63,
7041,
275,
7324,
421,
199,
533,
10944,
5144,
8,
4231,
304,
272,
3851,
275,
519,
891,
30181,
5169,
490,
7558,
48,
28,
13572,
3072,
59,
9,
1204,
490,
7558,
48,
28,
4579,
13489,
60,
2677,
23778,
2862,
61,
1204,
490,
7558,
48,
28,
22359,
68,
13489,
60,
2677,
23778,
2862,
61,
1204,
490,
7558,
48,
28,
3197,
18956,
490,
776,
2344,
421,
199,
318,
5536,
63,
1418,
8,
83,
304,
272,
3851,
275,
295,
14,
2014,
8,
82,
30181,
21690,
2677,
23778,
2862,
10374,
272,
372,
663,
8,
3401,
14,
6452,
8,
83,
430,
421,
199,
318,
21077,
63,
4443,
63,
2629,
8,
2558,
12,
3656,
304,
272,
4645,
275,
5536,
63,
1418,
8,
2629,
9,
272,
2225,
63,
1247,
275,
663,
342,
272,
367,
1004,
315,
3336,
14,
3215,
63,
604,
63,
1580,
26,
267,
2225,
63,
1247,
14,
525,
8,
604,
14,
3215,
63,
344,
14,
354,
9,
272,
340,
440,
4645,
14,
374,
9401,
8,
3215,
63,
1247,
304,
267,
746,
871,
63,
1025,
6723,
547,
659,
4018,
3601,
24718,
2225,
536,
315,
283,
4318,
5522,
12935,
10944,
17581,
2,
1333,
421,
199,
318,
664,
63,
16841,
63,
885,
63,
600,
8,
2558,
12,
3656,
304,
272,
3336,
63,
3288,
275,
10018,
8,
495,
9,
272,
3659,
63,
2629,
275,
10944,
5144,
8,
2629,
9,
272,
367,
574,
315,
3336,
14,
3215,
63,
585,
63,
1580,
26,
267,
340,
574,
14,
3215,
63,
600,
26,
288,
3336,
63,
3288,
59,
585,
14,
3215,
63,
344,
14,
354,
61,
847,
574,
14,
3215,
63,
600,
272,
1006,
63,
3288,
275,
5536,
63,
1418,
8,
2629,
9,
272,
4124,
63,
3288,
275,
1006,
63,
3288,
446,
663,
8,
2558,
63,
3288,
14,
1612,
1012,
272,
4124,
275,
1211,
14,
19164,
8,
4752,
63,
3288,
12,
10092,
4121,
63,
40,
15744,
63,
20,
63,
18701,
63,
7041,
9,
272,
3336,
63,
3288,
14,
873,
8,
4752,
9,
272,
849,
63,
600,
275,
3659,
63,
2629,
14,
3489,
63,
20374,
8,
2558,
63,
3288,
9,
272,
372,
849,
63,
600,
421,
199,
318,
3795,
63,
885,
63,
600,
8,
2558,
12,
3656,
304,
272,
3336,
14,
885,
63,
600,
275,
664,
63,
16841,
63,
885,
63,
600,
8,
2558,
12,
3656,
9,
421,
199,
533,
12705,
4231,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
2558,
14,
1160,
7,
339,
3659,
63,
2629,
275,
1504,
14,
1610,
8,
267,
1059,
534,
12935,
3659,
3656,
297,
267,
1720,
534,
5083,
3656,
367,
10015,
5007,
6941,
402,
282,
283,
1467,
283,
8759,
4046,
687,
642,
1978,
3134,
78,
7,
10798,
283,
9846,
3427,
78,
7,
1467,
283,
33,
3336,
4310,
17281,
543,
499,
3004,
26,
14579,
436,
11581,
3427,
78,
7,
10798,
283,
5884,
26,
17281,
60,
78,
7,
1467,
283,
4117,
26,
9572,
8,
82,
395,
1488,
10723,
8,
89,
395,
30593,
8,
66,
9,
221,
327,
10858,
12,
1488,
10723,
12,
30593,
787,
283,
1467,
283,
1589,
2225,
574,
12,
658,
82,
3559,
658,
89,
3559,
658,
66,
64,
787,
314,
5226,
1233,
60,
78,
7,
1467,
283,
2320,
26,
491,
334,
76,
395,
1323,
44,
8,
88,
2862,
78,
7,
10798,
283,
11423,
4260,
21107,
867,
3659,
3656,
370,
14505,
4117,
11285,
59,
2320,
61,
3559,
314,
283,
1467,
283,
885,
1233,
641,
314,
21169,
911,
506,
6020,
2839,
658,
82,
13,
76,
64,
283,
1467,
26144,
66,
13,
76,
64,
658,
82,
13,
88,
64,
2263,
60,
78,
7,
10798,
283,
3917,
1265,
2839,
12,
2047,
883,
2755,
1172,
314,
2225,
536,
7468,
1655,
7,
1467,
283,
2419,
5403,
315,
314,
3656,
14,
32753,
465,
2360,
658,
25352,
33,
32418,
2320,
61,
94,
59,
4117,
61,
94,
59,
2320,
16090,
7,
1467,
283,
3979,
6290,
12,
314,
849,
1233,
641,
21169,
911,
506,
6020,
2839,
7,
1467,
283,
658,
25352,
33,
15,
76,
94,
82,
94,
76,
64,
334,
509,
9854,
543,
11581,
298,
10858,
2,
436,
14579,
298,
44,
531,
283,
1467,
26144,
25352,
33,
15,
88,
94,
89,
94,
88,
64,
334,
509,
9854,
543,
11581,
298,
57,
10723,
2,
436,
14579,
298,
25774,
27681,
78,
7,
10798,
283,
7443,
26,
1852,
3238,
4110,
7369,
12,
8480,
886,
440,
7468,
315,
2195,
283,
1467,
283,
3215,
536,
358,
339,
768,
1246,
14,
1238,
272,
347,
1218,
8,
277,
12,
5322,
304,
267,
3336,
275,
291,
14,
1222,
8,
3643,
9,
267,
340,
440,
5322,
14,
362,
360,
4443,
63,
2629,
358,
436,
3336,
14,
3215,
63,
604,
63,
1580,
26,
288,
2225,
63,
1247,
275,
942,
288,
367,
1004,
315,
3336,
14,
3215,
63,
604,
63,
1580,
26,
355,
2225,
63,
1247,
14,
740,
10994,
27922,
1674,
908,
8,
604,
14,
3215,
63,
344,
14,
354,
430,
288,
849,
63,
2629,
275,
6186,
63,
31177,
63,
15828,
14,
904,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
TouK/vumi
|
vumi/application/bridge.py
|
1
|
4451
|
# -*- test-case-name: vumi.application.tests.test_bridge -*-
from base64 import b64encode
from twisted.python import log
from twisted.web import http
from twisted.internet.defer import inlineCallbacks
from vumi.application.base import ApplicationWorker
from vumi.utils import http_request_full
from vumi.errors import VumiError
from vumi.config import ConfigText, ConfigUrl
from datetime import datetime
class BridgeError(VumiError):
pass
class BridgeConfig(ApplicationWorker.CONFIG_CLASS):
# TODO: Make these less static?
url = ConfigUrl(
"URL to submit incoming message to.", required=True, static=True)
http_method = ConfigText(
"HTTP method for submitting messages.", default='POST', static=True)
content_type = ConfigText(
"HTTP Content-Type.", default='application/json', static=True)
auth_method = ConfigText(
"HTTP authentication method.", default='basic', static=True)
username = ConfigText("Username for HTTP authentication.", default='')
password = ConfigText("Password for HTTP authentication.", default='')
class BridgeApplication(ApplicationWorker):
CONFIG_CLASS = BridgeConfig
reply_header = 'X-Vumi-HTTPRelay-Reply'
reply_header_good_value = 'true'
end_of_session_header = 'end-of-session'
def validate_config(self):
self.supported_auth_methods = {
'basic': self.generate_basic_auth_headers,
}
config = self.get_static_config()
if config.auth_method not in self.supported_auth_methods:
raise BridgeError(
'HTTP Authentication method %s not supported' %
(repr(config.auth_method,)))
def generate_basic_auth_headers(self, username, password):
credentials = ':'.join([username, password])
auth_string = b64encode(credentials.encode('utf-8'))
return {
'Authorization': ['Basic %s' % (auth_string,)]
}
def get_auth_headers(self, config):
if config.username:
handler = self.supported_auth_methods.get(config.auth_method)
return handler(config.username, config.password)
return {}
def get_content_type_headers(self, config):
config_content_type = config.content_type
if config_content_type:
return {'Content-Type': config_content_type}
return {}
def _handle_bad_response(self, failure, message):
now = datetime.now()
seconds = now.second + 60*now.minute + 360*now.hour
log.msg("Darkness [%s] is comming: %s" %
(seconds, failure.getErrorMessage()))
self.reply_to(message, "Error [%s]" % seconds, continue_session=False)
def _handle_good_response(self, response, message, config):
headers = response.headers
if response.code == http.OK:
if headers.hasHeader(self.reply_header):
raw_reply_headers = headers.getRawHeaders(self.reply_header)
content = response.delivered_body.strip()
if (raw_reply_headers[0].lower() ==
self.reply_header_good_value) and content:
continue_session = True
if headers.hasHeader(self.end_of_session_header):
raw_end_of_session_headers = \
headers.getRawHeaders(self.end_of_session_header)
if raw_end_of_session_headers[0].lower() == 'true':
continue_session = False
self.reply_to(message, content,
continue_session=continue_session)
else:
log.err('%s responded with %s' % (config.url.geturl(),
response.code))
@inlineCallbacks
def consume_user_message(self, message):
config = yield self.get_config(message)
headers = self.get_auth_headers(config)
headers.update(self.get_content_type_headers(config))
response = http_request_full(config.url.geturl(), message.to_json(),
headers, config.http_method)
response.addCallback(lambda response:
self._handle_good_response(
response, message, config))
response.addErrback(lambda fail:
self._handle_bad_response(fail, message))
yield response
|
bsd-3-clause
|
[
3,
1882,
511,
13,
2546,
13,
354,
26,
373,
453,
73,
14,
3578,
14,
2219,
14,
396,
63,
9528,
1882,
199,
199,
504,
1300,
772,
492,
330,
772,
2143,
199,
199,
504,
7390,
14,
1548,
492,
943,
199,
504,
7390,
14,
2520,
492,
1455,
199,
504,
7390,
14,
4901,
14,
11610,
492,
8308,
17958,
199,
199,
504,
373,
453,
73,
14,
3578,
14,
1095,
492,
13515,
12678,
199,
504,
373,
453,
73,
14,
1208,
492,
1455,
63,
1069,
63,
2861,
199,
504,
373,
453,
73,
14,
2550,
492,
812,
453,
73,
547,
199,
504,
373,
453,
73,
14,
888,
492,
4094,
1872,
12,
4094,
6417,
199,
199,
504,
2197,
492,
2197,
421,
199,
533,
699,
5562,
547,
8,
54,
453,
73,
547,
304,
272,
986,
421,
199,
533,
699,
5562,
2028,
8,
5039,
12678,
14,
5569,
63,
6885,
304,
339,
327,
3254,
26,
4155,
3520,
6656,
2955,
31,
272,
1166,
275,
4094,
6417,
8,
267,
298,
2632,
370,
11482,
12467,
1245,
370,
4765,
1415,
29,
549,
12,
2955,
29,
549,
9,
272,
1455,
63,
765,
275,
4094,
1872,
8,
267,
298,
2856,
1083,
367,
11482,
1337,
3788,
4765,
849,
534,
4030,
297,
2955,
29,
549,
9,
272,
1564,
63,
466,
275,
4094,
1872,
8,
267,
298,
2856,
6646,
13,
804,
4765,
849,
534,
3578,
15,
1001,
297,
2955,
29,
549,
9,
339,
1790,
63,
765,
275,
4094,
1872,
8,
267,
298,
2856,
6299,
1083,
4765,
849,
534,
4316,
297,
2955,
29,
549,
9,
339,
3434,
275,
4094,
1872,
480,
13355,
367,
3101,
6299,
4765,
849,
13275,
272,
2505,
275,
4094,
1872,
480,
6139,
367,
3101,
6299,
4765,
849,
13275,
421,
199,
533,
699,
5562,
5039,
8,
5039,
12678,
304,
272,
15869,
63,
6885,
275,
699,
5562,
2028,
339,
9351,
63,
1291,
275,
283,
56,
13,
54,
453,
73,
13,
2856,
5640,
1187,
13,
14166,
7,
272,
9351,
63,
1291,
63,
8302,
63,
585,
275,
283,
2052,
7,
272,
1284,
63,
1618,
63,
1730,
63,
1291,
275,
283,
500,
13,
1618,
13,
1730,
7,
339,
347,
4107,
63,
888,
8,
277,
304,
267,
291,
14,
4946,
63,
1178,
63,
2474,
275,
469,
288,
283,
4316,
356,
291,
14,
4208,
63,
4316,
63,
1178,
63,
2139,
12,
267,
789,
267,
1101,
275,
291,
14,
362,
63,
1986,
63,
888,
342,
267,
340,
1101,
14,
1178,
63,
765,
440,
315,
291,
14,
4946,
63,
1178,
63,
2474,
26,
288,
746,
699,
5562,
547,
8,
355,
283,
2856,
15995,
1083,
450,
83,
440,
3748,
7,
450,
355,
334,
2722,
8,
888,
14,
1178,
63,
765,
20097,
339,
347,
3550,
63,
4316,
63,
1178,
63,
2139,
8,
277,
12,
3434,
12,
2505,
304,
267,
6235,
275,
29010,
904,
779,
2473,
12,
2505,
566,
267,
1790,
63,
875,
275,
330,
772,
2143,
8,
6942,
14,
2143,
360,
1624,
13,
24,
1333,
267,
372,
469,
288,
283,
11626,
356,
788,
6845,
450,
83,
7,
450,
334,
1178,
63,
875,
12,
1874,
267,
789,
339,
347,
664,
63,
1178,
63,
2139,
8,
277,
12,
1101,
304,
267,
340,
1101,
14,
2473,
26,
288,
3016,
275,
291,
14,
4946,
63,
1178,
63,
2474,
14,
362,
8,
888,
14,
1178,
63,
765,
9,
288,
372,
3016,
8,
888,
14,
2473,
12,
1101,
14,
2060,
9,
267,
372,
1052,
339,
347,
664,
63,
1317,
63,
466,
63,
2139,
8,
277,
12,
1101,
304,
267,
1101,
63,
1317,
63,
466,
275,
1101,
14,
1317,
63,
466,
267,
340,
1101,
63,
1317,
63,
466,
26,
288,
372,
791,
2714,
13,
804,
356,
1101,
63,
1317,
63,
466,
93,
267,
372,
1052,
339,
347,
485,
2479,
63,
4087,
63,
1310,
8,
277,
12,
5988,
12,
1245,
304,
267,
3063,
275,
2197,
14,
2131,
342,
267,
4696,
275,
3063,
14,
4375,
435,
5212,
10,
2131,
14,
10698,
435,
19434,
10,
2131,
14,
5180,
267,
943,
14,
1328,
480,
36,
1096,
4171,
8978,
83,
61,
365,
1923,
316,
26,
450,
83,
2,
450,
355,
334,
4515,
12,
5988,
14,
362,
547,
2209,
4059,
267,
291,
14,
8102,
63,
475,
8,
1188,
12,
298,
547,
8978,
83,
8480,
450,
4696,
12,
1980,
63,
1730,
29,
797,
9,
339,
347,
485,
2479,
63,
8302,
63,
1310,
8,
277,
12,
1177,
12,
1245,
12,
1101,
304,
267,
2323,
275,
1177,
14,
2139,
267,
340,
1177,
14,
600,
508,
1455,
14,
3593,
26,
288,
340,
2323,
14,
1989,
2567,
8,
277,
14,
8102,
63,
1291,
304,
355,
3066,
63,
8102,
63,
2139,
275,
2323,
14,
362,
7963,
9883,
8,
277,
14,
8102,
63,
1291,
9,
355,
1564,
275,
1177,
14,
30480,
63,
2030,
14,
1913,
342,
355,
340,
334,
1773,
63,
8102,
63,
2139,
59,
16,
1055,
2325,
342,
508,
673,
291,
14,
8102,
63,
1291,
63,
8302,
63,
585,
9,
436,
1564,
26,
490,
1980,
63,
1730,
275,
715,
490,
340,
2323,
14,
1989,
2567,
8,
277,
14,
500,
63,
1618,
63,
1730,
63,
1291,
304,
717,
3066,
63,
500,
63,
1618,
63,
1730,
63,
2139,
275,
971,
1169,
2323,
14,
362,
7963,
9883,
8,
277,
14,
500,
63,
1618,
63,
1730,
63,
1291,
9,
717,
340,
3066,
63,
500,
63,
1618,
63,
1730,
63,
2139,
59,
16,
1055,
2325,
342,
508,
283,
2052,
356,
1169,
1980,
63,
1730,
275,
756,
490,
291,
14,
8102,
63,
475,
8,
1188,
12,
1564,
12,
3303,
1980,
63,
1730,
29,
6958,
63,
1730,
9,
267,
587,
26,
288,
943,
14,
1508,
3508,
83,
9163,
770,
543,
450,
83,
7,
450,
334,
888,
14,
633,
14,
32130,
1062,
6343,
1177,
14,
600,
430,
339,
768,
24813,
272,
347,
9451,
63,
751,
63,
1188,
8,
277,
12,
1245,
304,
267,
1101,
275,
1995,
291,
14,
362,
63,
888,
8,
1188,
9,
267,
2323,
275,
291,
14,
362,
63,
1178,
63,
2139,
8,
888,
9,
267,
2323,
14,
873,
8,
277,
14,
362,
63,
1317,
63,
466,
63,
2139,
8,
888,
430,
398,
1177,
275,
1455,
63,
1069,
63,
2861,
8,
888,
14,
633,
14,
32130,
1062,
1245,
14,
475,
63,
1001,
1062,
3660,
2323,
12,
1101,
14,
1014,
63,
765,
9,
398,
1177,
14,
10053,
8,
2734,
1177,
26,
2490,
291,
423,
2479,
63,
8302,
63,
1310,
8,
639,
1177,
12,
1245,
12,
1101,
430,
267,
1177,
14
] |
[
1882,
511,
13,
2546,
13,
354,
26,
373,
453,
73,
14,
3578,
14,
2219,
14,
396,
63,
9528,
1882,
199,
199,
504,
1300,
772,
492,
330,
772,
2143,
199,
199,
504,
7390,
14,
1548,
492,
943,
199,
504,
7390,
14,
2520,
492,
1455,
199,
504,
7390,
14,
4901,
14,
11610,
492,
8308,
17958,
199,
199,
504,
373,
453,
73,
14,
3578,
14,
1095,
492,
13515,
12678,
199,
504,
373,
453,
73,
14,
1208,
492,
1455,
63,
1069,
63,
2861,
199,
504,
373,
453,
73,
14,
2550,
492,
812,
453,
73,
547,
199,
504,
373,
453,
73,
14,
888,
492,
4094,
1872,
12,
4094,
6417,
199,
199,
504,
2197,
492,
2197,
421,
199,
533,
699,
5562,
547,
8,
54,
453,
73,
547,
304,
272,
986,
421,
199,
533,
699,
5562,
2028,
8,
5039,
12678,
14,
5569,
63,
6885,
304,
339,
327,
3254,
26,
4155,
3520,
6656,
2955,
31,
272,
1166,
275,
4094,
6417,
8,
267,
298,
2632,
370,
11482,
12467,
1245,
370,
4765,
1415,
29,
549,
12,
2955,
29,
549,
9,
272,
1455,
63,
765,
275,
4094,
1872,
8,
267,
298,
2856,
1083,
367,
11482,
1337,
3788,
4765,
849,
534,
4030,
297,
2955,
29,
549,
9,
272,
1564,
63,
466,
275,
4094,
1872,
8,
267,
298,
2856,
6646,
13,
804,
4765,
849,
534,
3578,
15,
1001,
297,
2955,
29,
549,
9,
339,
1790,
63,
765,
275,
4094,
1872,
8,
267,
298,
2856,
6299,
1083,
4765,
849,
534,
4316,
297,
2955,
29,
549,
9,
339,
3434,
275,
4094,
1872,
480,
13355,
367,
3101,
6299,
4765,
849,
13275,
272,
2505,
275,
4094,
1872,
480,
6139,
367,
3101,
6299,
4765,
849,
13275,
421,
199,
533,
699,
5562,
5039,
8,
5039,
12678,
304,
272,
15869,
63,
6885,
275,
699,
5562,
2028,
339,
9351,
63,
1291,
275,
283,
56,
13,
54,
453,
73,
13,
2856,
5640,
1187,
13,
14166,
7,
272,
9351,
63,
1291,
63,
8302,
63,
585,
275,
283,
2052,
7,
272,
1284,
63,
1618,
63,
1730,
63,
1291,
275,
283,
500,
13,
1618,
13,
1730,
7,
339,
347,
4107,
63,
888,
8,
277,
304,
267,
291,
14,
4946,
63,
1178,
63,
2474,
275,
469,
288,
283,
4316,
356,
291,
14,
4208,
63,
4316,
63,
1178,
63,
2139,
12,
267,
789,
267,
1101,
275,
291,
14,
362,
63,
1986,
63,
888,
342,
267,
340,
1101,
14,
1178,
63,
765,
440,
315,
291,
14,
4946,
63,
1178,
63,
2474,
26,
288,
746,
699,
5562,
547,
8,
355,
283,
2856,
15995,
1083,
450,
83,
440,
3748,
7,
450,
355,
334,
2722,
8,
888,
14,
1178,
63,
765,
20097,
339,
347,
3550,
63,
4316,
63,
1178,
63,
2139,
8,
277,
12,
3434,
12,
2505,
304,
267,
6235,
275,
29010,
904,
779,
2473,
12,
2505,
566,
267,
1790,
63,
875,
275,
330,
772,
2143,
8,
6942,
14,
2143,
360,
1624,
13,
24,
1333,
267,
372,
469,
288,
283,
11626,
356,
788,
6845,
450,
83,
7,
450,
334,
1178,
63,
875,
12,
1874,
267,
789,
339,
347,
664,
63,
1178,
63,
2139,
8,
277,
12,
1101,
304,
267,
340,
1101,
14,
2473,
26,
288,
3016,
275,
291,
14,
4946,
63,
1178,
63,
2474,
14,
362,
8,
888,
14,
1178,
63,
765,
9,
288,
372,
3016,
8,
888,
14,
2473,
12,
1101,
14,
2060,
9,
267,
372,
1052,
339,
347,
664,
63,
1317,
63,
466,
63,
2139,
8,
277,
12,
1101,
304,
267,
1101,
63,
1317,
63,
466,
275,
1101,
14,
1317,
63,
466,
267,
340,
1101,
63,
1317,
63,
466,
26,
288,
372,
791,
2714,
13,
804,
356,
1101,
63,
1317,
63,
466,
93,
267,
372,
1052,
339,
347,
485,
2479,
63,
4087,
63,
1310,
8,
277,
12,
5988,
12,
1245,
304,
267,
3063,
275,
2197,
14,
2131,
342,
267,
4696,
275,
3063,
14,
4375,
435,
5212,
10,
2131,
14,
10698,
435,
19434,
10,
2131,
14,
5180,
267,
943,
14,
1328,
480,
36,
1096,
4171,
8978,
83,
61,
365,
1923,
316,
26,
450,
83,
2,
450,
355,
334,
4515,
12,
5988,
14,
362,
547,
2209,
4059,
267,
291,
14,
8102,
63,
475,
8,
1188,
12,
298,
547,
8978,
83,
8480,
450,
4696,
12,
1980,
63,
1730,
29,
797,
9,
339,
347,
485,
2479,
63,
8302,
63,
1310,
8,
277,
12,
1177,
12,
1245,
12,
1101,
304,
267,
2323,
275,
1177,
14,
2139,
267,
340,
1177,
14,
600,
508,
1455,
14,
3593,
26,
288,
340,
2323,
14,
1989,
2567,
8,
277,
14,
8102,
63,
1291,
304,
355,
3066,
63,
8102,
63,
2139,
275,
2323,
14,
362,
7963,
9883,
8,
277,
14,
8102,
63,
1291,
9,
355,
1564,
275,
1177,
14,
30480,
63,
2030,
14,
1913,
342,
355,
340,
334,
1773,
63,
8102,
63,
2139,
59,
16,
1055,
2325,
342,
508,
673,
291,
14,
8102,
63,
1291,
63,
8302,
63,
585,
9,
436,
1564,
26,
490,
1980,
63,
1730,
275,
715,
490,
340,
2323,
14,
1989,
2567,
8,
277,
14,
500,
63,
1618,
63,
1730,
63,
1291,
304,
717,
3066,
63,
500,
63,
1618,
63,
1730,
63,
2139,
275,
971,
1169,
2323,
14,
362,
7963,
9883,
8,
277,
14,
500,
63,
1618,
63,
1730,
63,
1291,
9,
717,
340,
3066,
63,
500,
63,
1618,
63,
1730,
63,
2139,
59,
16,
1055,
2325,
342,
508,
283,
2052,
356,
1169,
1980,
63,
1730,
275,
756,
490,
291,
14,
8102,
63,
475,
8,
1188,
12,
1564,
12,
3303,
1980,
63,
1730,
29,
6958,
63,
1730,
9,
267,
587,
26,
288,
943,
14,
1508,
3508,
83,
9163,
770,
543,
450,
83,
7,
450,
334,
888,
14,
633,
14,
32130,
1062,
6343,
1177,
14,
600,
430,
339,
768,
24813,
272,
347,
9451,
63,
751,
63,
1188,
8,
277,
12,
1245,
304,
267,
1101,
275,
1995,
291,
14,
362,
63,
888,
8,
1188,
9,
267,
2323,
275,
291,
14,
362,
63,
1178,
63,
2139,
8,
888,
9,
267,
2323,
14,
873,
8,
277,
14,
362,
63,
1317,
63,
466,
63,
2139,
8,
888,
430,
398,
1177,
275,
1455,
63,
1069,
63,
2861,
8,
888,
14,
633,
14,
32130,
1062,
1245,
14,
475,
63,
1001,
1062,
3660,
2323,
12,
1101,
14,
1014,
63,
765,
9,
398,
1177,
14,
10053,
8,
2734,
1177,
26,
2490,
291,
423,
2479,
63,
8302,
63,
1310,
8,
639,
1177,
12,
1245,
12,
1101,
430,
267,
1177,
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,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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
] |
marc-sensenich/ansible
|
lib/ansible/plugins/shell/__init__.py
|
9
|
8652
|
# (c) 2016 RedHat
#
# This file is part of Ansible.
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
import os.path
import random
import re
import time
import ansible.constants as C
from ansible.errors import AnsibleError
from ansible.module_utils.six import text_type
from ansible.module_utils.six.moves import shlex_quote
from ansible.module_utils._text import to_native
from ansible.plugins import AnsiblePlugin
_USER_HOME_PATH_RE = re.compile(r'^~[_.A-Za-z0-9][-_.A-Za-z0-9]*$')
class ShellBase(AnsiblePlugin):
def __init__(self):
super(ShellBase, self).__init__()
self.env = {}
if C.DEFAULT_MODULE_SET_LOCALE:
module_locale = C.DEFAULT_MODULE_LANG
self.env = {'LANG': module_locale,
'LC_ALL': module_locale,
'LC_MESSAGES': module_locale}
self.tmpdir = None
self.executable = None
def _normalize_system_tmpdirs(self):
# Normalize the tmp directory strings. We don't use expanduser/expandvars because those
# can vary between remote user and become user. Therefore the safest practice will be for
# this to always be specified as full paths)
normalized_paths = [d.rstrip('/') for d in self.get_option('system_tmpdirs')]
# Make sure all system_tmpdirs are absolute otherwise they'd be relative to the login dir
# which is almost certainly going to fail in a cornercase.
if not all(os.path.isabs(d) for d in normalized_paths):
raise AnsibleError('The configured system_tmpdirs contains a relative path: {0}. All'
' system_tmpdirs must be absolute'.format(to_native(normalized_paths)))
self.set_option('system_tmpdirs', normalized_paths)
def set_options(self, task_keys=None, var_options=None, direct=None):
super(ShellBase, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct)
# set env if needed, deal with environment's 'dual nature' list of dicts or dict
env = self.get_option('environment')
if isinstance(env, list):
for env_dict in env:
self.env.update(env_dict)
else:
self.env.update(env)
# We can remove the try: except in the future when we make ShellBase a proper subset of
# *all* shells. Right now powershell and third party shells which do not use the
# shell_common documentation fragment (and so do not have system_tmpdirs) will fail
try:
self._normalize_system_tmpdirs()
except KeyError:
pass
def env_prefix(self, **kwargs):
return ' '.join(['%s=%s' % (k, shlex_quote(text_type(v))) for k, v in kwargs.items()])
def join_path(self, *args):
return os.path.join(*args)
# some shells (eg, powershell) are snooty about filenames/extensions, this lets the shell plugin have a say
def get_remote_filename(self, pathname):
base_name = os.path.basename(pathname.strip())
return base_name.strip()
def path_has_trailing_slash(self, path):
return path.endswith('/')
def chmod(self, paths, mode):
cmd = ['chmod', mode]
cmd.extend(paths)
cmd = [shlex_quote(c) for c in cmd]
return ' '.join(cmd)
def chown(self, paths, user):
cmd = ['chown', user]
cmd.extend(paths)
cmd = [shlex_quote(c) for c in cmd]
return ' '.join(cmd)
def set_user_facl(self, paths, user, mode):
"""Only sets acls for users as that's really all we need"""
cmd = ['setfacl', '-m', 'u:%s:%s' % (user, mode)]
cmd.extend(paths)
cmd = [shlex_quote(c) for c in cmd]
return ' '.join(cmd)
def remove(self, path, recurse=False):
path = shlex_quote(path)
cmd = 'rm -f '
if recurse:
cmd += '-r '
return cmd + "%s %s" % (path, self._SHELL_REDIRECT_ALLNULL)
def exists(self, path):
cmd = ['test', '-e', shlex_quote(path)]
return ' '.join(cmd)
def mkdtemp(self, basefile=None, system=False, mode=0o700, tmpdir=None):
if not basefile:
basefile = 'ansible-tmp-%s-%s' % (time.time(), random.randint(0, 2**48))
# When system is specified we have to create this in a directory where
# other users can read and access the tmp directory.
# This is because we use system to create tmp dirs for unprivileged users who are
# sudo'ing to a second unprivileged user.
# The 'system_tmpdirs' setting defines dirctories we can use for this purpose
# the default are, /tmp and /var/tmp.
# So we only allow one of those locations if system=True, using the
# passed in tmpdir if it is valid or the first one from the setting if not.
if system:
tmpdir = tmpdir.rstrip('/')
if tmpdir in self.get_option('system_tmpdirs'):
basetmpdir = tmpdir
else:
basetmpdir = self.get_option('system_tmpdirs')[0]
else:
if tmpdir is None:
basetmpdir = self.get_option('remote_tmp')
else:
basetmpdir = tmpdir
basetmp = self.join_path(basetmpdir, basefile)
cmd = 'mkdir -p %s echo %s %s' % (self._SHELL_SUB_LEFT, basetmp, self._SHELL_SUB_RIGHT)
cmd += ' %s echo %s=%s echo %s %s' % (self._SHELL_AND, basefile, self._SHELL_SUB_LEFT, basetmp, self._SHELL_SUB_RIGHT)
# change the umask in a subshell to achieve the desired mode
# also for directories created with `mkdir -p`
if mode:
tmp_umask = 0o777 & ~mode
cmd = '%s umask %o %s %s %s' % (self._SHELL_GROUP_LEFT, tmp_umask, self._SHELL_AND, cmd, self._SHELL_GROUP_RIGHT)
return cmd
def expand_user(self, user_home_path, username=''):
''' Return a command to expand tildes in a path
It can be either "~" or "~username". We just ignore $HOME
We use the POSIX definition of a username:
http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_426
http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_276
Falls back to 'current workind directory' as we assume 'home is where the remote user ends up'
'''
# Check that the user_path to expand is safe
if user_home_path != '~':
if not _USER_HOME_PATH_RE.match(user_home_path):
# shlex_quote will make the shell return the string verbatim
user_home_path = shlex_quote(user_home_path)
elif username:
# if present the user name is appended to resolve "that user's home"
user_home_path += username
return 'echo %s' % user_home_path
def pwd(self):
"""Return the working directory after connecting"""
return 'echo %spwd%s' % (self._SHELL_SUB_LEFT, self._SHELL_SUB_RIGHT)
def build_module_command(self, env_string, shebang, cmd, arg_path=None):
# don't quote the cmd if it's an empty string, because this will break pipelining mode
if cmd.strip() != '':
cmd = shlex_quote(cmd)
cmd_parts = []
if shebang:
shebang = shebang.replace("#!", "").strip()
else:
shebang = ""
cmd_parts.extend([env_string.strip(), shebang, cmd])
if arg_path is not None:
cmd_parts.append(arg_path)
new_cmd = " ".join(cmd_parts)
return new_cmd
def append_command(self, cmd, cmd_to_append):
"""Append an additional command if supported by the shell"""
if self._SHELL_AND:
cmd += ' %s %s' % (self._SHELL_AND, cmd_to_append)
return cmd
def wrap_for_exec(self, cmd):
"""wrap script execution with any necessary decoration (eg '&' for quoted powershell script paths)"""
return cmd
|
gpl-3.0
|
[
3,
334,
67,
9,
7800,
9572,
40,
292,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
14,
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,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
2196,
199,
646,
295,
199,
646,
900,
199,
199,
646,
3242,
14,
5559,
465,
445,
199,
504,
3242,
14,
2550,
492,
13358,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
1318,
63,
466,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
14,
4912,
492,
16701,
63,
3513,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
6106,
199,
504,
3242,
14,
5265,
492,
2622,
5061,
199,
199,
63,
3791,
63,
9524,
63,
3243,
63,
907,
275,
295,
14,
2014,
8,
82,
4289,
94,
59,
3754,
33,
13,
13163,
13,
90,
16,
13,
25,
15898,
3754,
33,
13,
13163,
13,
90,
16,
13,
25,
3672,
9988,
421,
199,
533,
24599,
1563,
8,
10047,
5061,
304,
272,
347,
636,
826,
721,
277,
304,
398,
1613,
8,
8529,
1563,
12,
291,
2843,
826,
4533,
398,
291,
14,
1813,
275,
1052,
267,
340,
445,
14,
3472,
63,
10001,
63,
3597,
63,
20828,
26,
288,
859,
63,
5508,
275,
445,
14,
3472,
63,
10001,
63,
7442,
288,
291,
14,
1813,
275,
791,
7442,
356,
859,
63,
5508,
12,
717,
283,
7027,
63,
1761,
356,
859,
63,
5508,
12,
717,
283,
7027,
63,
23229,
356,
859,
63,
5508,
93,
398,
291,
14,
8616,
275,
488,
267,
291,
14,
5904,
275,
488,
339,
347,
485,
7721,
63,
2253,
63,
2791,
3220,
8,
277,
304,
267,
327,
21017,
314,
3529,
2082,
3326,
14,
2136,
2793,
1133,
675,
6544,
751,
15,
4441,
2936,
2952,
5204,
267,
327,
883,
17083,
3382,
3982,
922,
436,
8649,
922,
14,
221,
21039,
314,
17925,
597,
24471,
911,
506,
367,
267,
327,
642,
370,
3544,
506,
2013,
465,
2615,
3792,
9,
267,
9657,
63,
3771,
275,
359,
68,
14,
6735,
7825,
367,
366,
315,
291,
14,
362,
63,
1422,
360,
2253,
63,
2791,
3220,
5440,
398,
327,
4155,
3238,
1006,
2656,
63,
2791,
3220,
787,
3679,
4257,
2985,
5121,
506,
3847,
370,
314,
4676,
2935,
267,
327,
1314,
365,
18871,
9842,
590,
9995,
370,
2449,
315,
282,
17703,
2546,
14,
267,
340,
440,
1006,
8,
736,
14,
515,
14,
17896,
8,
68,
9,
367,
366,
315,
9657,
63,
3771,
304,
288,
746,
13358,
360,
1918,
7526,
2656,
63,
2791,
3220,
3509,
282,
3847,
931,
26,
469,
16,
5565,
2900,
7,
3044,
283,
2656,
63,
2791,
3220,
1471,
506,
3679,
1370,
908,
8,
475,
63,
6106,
8,
12916,
63,
3771,
1724,
398,
291,
14,
409,
63,
1422,
360,
2253,
63,
2791,
3220,
297,
9657,
63,
3771,
9,
339,
347,
663,
63,
1419,
8,
277,
12,
2120,
63,
1612,
29,
403,
12,
2729,
63,
1419,
29,
403,
12,
4125,
29,
403,
304,
398,
1613,
8,
8529,
1563,
12,
291,
680,
409,
63,
1419,
8,
1765,
63,
1612,
29,
1765,
63,
1612,
12,
2729,
63,
1419,
29,
1391,
63,
1419,
12,
4125,
29,
2275,
9,
398,
327,
663,
2589,
340,
4346,
12,
7962,
543,
3734,
1159,
283,
17962,
302,
1463,
7,
769,
402,
10809,
503,
1211,
267,
2589,
275,
291,
14,
362,
63,
1422,
360,
5418,
358,
267,
340,
1228,
8,
1813,
12,
769,
304,
288,
367,
2589,
63,
807,
315,
2589,
26,
355,
291,
14,
1813,
14,
873,
8,
1813,
63,
807,
9,
267,
587,
26,
288,
291,
14,
1813,
14,
873,
8,
1813,
9,
398,
327,
2136,
883,
2813,
314,
862,
26,
871,
315,
314,
6466,
1380,
781,
1852,
24599,
1563,
282,
5576,
10026,
402,
267,
327,
627,
452,
10,
1033,
6840,
14,
221,
20854,
3063,
7074,
5641,
436,
10919,
17135,
1033,
6840,
1314,
886,
440,
675,
314,
267,
327,
5218,
63,
2330,
3794,
7956,
334,
460,
880,
886,
440,
1172,
2656,
63,
2791,
3220,
9,
911,
2449,
267,
862,
26,
288,
291,
423,
7721,
63,
2253,
63,
2791,
3220,
342,
267,
871,
4067,
26,
288,
986,
339,
347,
2589,
63,
1861,
8,
277,
12,
1011,
958,
304,
267,
372,
283,
1987,
904,
26861,
83,
2458,
83,
7,
450,
334,
75,
12,
16701,
63,
3513,
8,
505,
63,
466,
8,
86,
1724,
367,
1022,
12,
373,
315,
2074,
14,
1744,
9383,
339,
347,
4263,
63,
515,
8,
277,
12,
627,
589,
304,
267,
372,
747,
14,
515,
14,
904,
2031,
589,
9,
339,
327,
2005,
1033,
6840,
334,
5902,
12,
7074,
5641,
9,
787,
308,
889,
357,
89,
3595,
6203,
15,
5359,
12,
642,
19083,
314,
5218,
3589,
1172,
282,
14722,
272,
347,
664,
63,
3846,
63,
1501,
8,
277,
12,
11776,
304,
267,
1300,
63,
354,
275,
747,
14,
515,
14,
4846,
8,
12445,
14,
1913,
1012,
267,
372,
1300,
63,
354,
14,
1913,
342,
339,
347,
931,
63,
1989,
63,
15910,
63,
7001,
8,
277,
12,
931,
304,
267,
372,
931,
14,
4130,
7825,
339,
347,
30106,
8,
277,
12,
3792,
12,
818,
304,
267,
2088,
275,
788,
11693,
297,
818,
61,
267,
2088,
14,
2880,
8,
3771,
9,
267,
2088,
275,
359,
32507,
63,
3513,
8,
67,
9,
367,
286,
315,
2088,
61,
398,
372,
283,
1987,
904,
8,
1760,
9,
339,
347,
286,
1917,
78,
8,
277,
12
] |
[
334,
67,
9,
7800,
9572,
40,
292,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
14,
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,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
2196,
199,
646,
295,
199,
646,
900,
199,
199,
646,
3242,
14,
5559,
465,
445,
199,
504,
3242,
14,
2550,
492,
13358,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
1318,
63,
466,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
14,
4912,
492,
16701,
63,
3513,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
6106,
199,
504,
3242,
14,
5265,
492,
2622,
5061,
199,
199,
63,
3791,
63,
9524,
63,
3243,
63,
907,
275,
295,
14,
2014,
8,
82,
4289,
94,
59,
3754,
33,
13,
13163,
13,
90,
16,
13,
25,
15898,
3754,
33,
13,
13163,
13,
90,
16,
13,
25,
3672,
9988,
421,
199,
533,
24599,
1563,
8,
10047,
5061,
304,
272,
347,
636,
826,
721,
277,
304,
398,
1613,
8,
8529,
1563,
12,
291,
2843,
826,
4533,
398,
291,
14,
1813,
275,
1052,
267,
340,
445,
14,
3472,
63,
10001,
63,
3597,
63,
20828,
26,
288,
859,
63,
5508,
275,
445,
14,
3472,
63,
10001,
63,
7442,
288,
291,
14,
1813,
275,
791,
7442,
356,
859,
63,
5508,
12,
717,
283,
7027,
63,
1761,
356,
859,
63,
5508,
12,
717,
283,
7027,
63,
23229,
356,
859,
63,
5508,
93,
398,
291,
14,
8616,
275,
488,
267,
291,
14,
5904,
275,
488,
339,
347,
485,
7721,
63,
2253,
63,
2791,
3220,
8,
277,
304,
267,
327,
21017,
314,
3529,
2082,
3326,
14,
2136,
2793,
1133,
675,
6544,
751,
15,
4441,
2936,
2952,
5204,
267,
327,
883,
17083,
3382,
3982,
922,
436,
8649,
922,
14,
221,
21039,
314,
17925,
597,
24471,
911,
506,
367,
267,
327,
642,
370,
3544,
506,
2013,
465,
2615,
3792,
9,
267,
9657,
63,
3771,
275,
359,
68,
14,
6735,
7825,
367,
366,
315,
291,
14,
362,
63,
1422,
360,
2253,
63,
2791,
3220,
5440,
398,
327,
4155,
3238,
1006,
2656,
63,
2791,
3220,
787,
3679,
4257,
2985,
5121,
506,
3847,
370,
314,
4676,
2935,
267,
327,
1314,
365,
18871,
9842,
590,
9995,
370,
2449,
315,
282,
17703,
2546,
14,
267,
340,
440,
1006,
8,
736,
14,
515,
14,
17896,
8,
68,
9,
367,
366,
315,
9657,
63,
3771,
304,
288,
746,
13358,
360,
1918,
7526,
2656,
63,
2791,
3220,
3509,
282,
3847,
931,
26,
469,
16,
5565,
2900,
7,
3044,
283,
2656,
63,
2791,
3220,
1471,
506,
3679,
1370,
908,
8,
475,
63,
6106,
8,
12916,
63,
3771,
1724,
398,
291,
14,
409,
63,
1422,
360,
2253,
63,
2791,
3220,
297,
9657,
63,
3771,
9,
339,
347,
663,
63,
1419,
8,
277,
12,
2120,
63,
1612,
29,
403,
12,
2729,
63,
1419,
29,
403,
12,
4125,
29,
403,
304,
398,
1613,
8,
8529,
1563,
12,
291,
680,
409,
63,
1419,
8,
1765,
63,
1612,
29,
1765,
63,
1612,
12,
2729,
63,
1419,
29,
1391,
63,
1419,
12,
4125,
29,
2275,
9,
398,
327,
663,
2589,
340,
4346,
12,
7962,
543,
3734,
1159,
283,
17962,
302,
1463,
7,
769,
402,
10809,
503,
1211,
267,
2589,
275,
291,
14,
362,
63,
1422,
360,
5418,
358,
267,
340,
1228,
8,
1813,
12,
769,
304,
288,
367,
2589,
63,
807,
315,
2589,
26,
355,
291,
14,
1813,
14,
873,
8,
1813,
63,
807,
9,
267,
587,
26,
288,
291,
14,
1813,
14,
873,
8,
1813,
9,
398,
327,
2136,
883,
2813,
314,
862,
26,
871,
315,
314,
6466,
1380,
781,
1852,
24599,
1563,
282,
5576,
10026,
402,
267,
327,
627,
452,
10,
1033,
6840,
14,
221,
20854,
3063,
7074,
5641,
436,
10919,
17135,
1033,
6840,
1314,
886,
440,
675,
314,
267,
327,
5218,
63,
2330,
3794,
7956,
334,
460,
880,
886,
440,
1172,
2656,
63,
2791,
3220,
9,
911,
2449,
267,
862,
26,
288,
291,
423,
7721,
63,
2253,
63,
2791,
3220,
342,
267,
871,
4067,
26,
288,
986,
339,
347,
2589,
63,
1861,
8,
277,
12,
1011,
958,
304,
267,
372,
283,
1987,
904,
26861,
83,
2458,
83,
7,
450,
334,
75,
12,
16701,
63,
3513,
8,
505,
63,
466,
8,
86,
1724,
367,
1022,
12,
373,
315,
2074,
14,
1744,
9383,
339,
347,
4263,
63,
515,
8,
277,
12,
627,
589,
304,
267,
372,
747,
14,
515,
14,
904,
2031,
589,
9,
339,
327,
2005,
1033,
6840,
334,
5902,
12,
7074,
5641,
9,
787,
308,
889,
357,
89,
3595,
6203,
15,
5359,
12,
642,
19083,
314,
5218,
3589,
1172,
282,
14722,
272,
347,
664,
63,
3846,
63,
1501,
8,
277,
12,
11776,
304,
267,
1300,
63,
354,
275,
747,
14,
515,
14,
4846,
8,
12445,
14,
1913,
1012,
267,
372,
1300,
63,
354,
14,
1913,
342,
339,
347,
931,
63,
1989,
63,
15910,
63,
7001,
8,
277,
12,
931,
304,
267,
372,
931,
14,
4130,
7825,
339,
347,
30106,
8,
277,
12,
3792,
12,
818,
304,
267,
2088,
275,
788,
11693,
297,
818,
61,
267,
2088,
14,
2880,
8,
3771,
9,
267,
2088,
275,
359,
32507,
63,
3513,
8,
67,
9,
367,
286,
315,
2088,
61,
398,
372,
283,
1987,
904,
8,
1760,
9,
339,
347,
286,
1917,
78,
8,
277,
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,
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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
] |
ehashman/oh-mainline
|
vendor/packages/whoosh/src/whoosh/support/relativedelta.py
|
116
|
17347
|
"""
Copyright (c) 2003-2010 Gustavo Niemeyer <gustavo@niemeyer.net>
This module offers extensions to the standard python 2.3+
datetime module.
"""
__author__ = "Gustavo Niemeyer <gustavo@niemeyer.net>"
__license__ = "PSF License"
import datetime
import calendar
__all__ = ["relativedelta", "MO", "TU", "WE", "TH", "FR", "SA", "SU"]
class weekday(object):
__slots__ = ["weekday", "n"]
def __init__(self, weekday, n=None):
self.weekday = weekday
self.n = n
def __call__(self, n):
if n == self.n:
return self
else:
return self.__class__(self.weekday, n)
def __eq__(self, other):
try:
if self.weekday != other.weekday or self.n != other.n:
return False
except AttributeError:
return False
return True
def __repr__(self):
s = ("MO", "TU", "WE", "TH", "FR", "SA", "SU")[self.weekday]
if not self.n:
return s
else:
return "%s(%+d)" % (s, self.n)
MO, TU, WE, TH, FR, SA, SU = weekdays = tuple([weekday(x) for x in range(7)])
class relativedelta:
"""
The relativedelta type is based on the specification of the excellent
work done by M.-A. Lemburg in his mx.DateTime extension. However,
notice that this type does *NOT* implement the same algorithm as
his work. Do *NOT* expect it to behave like mx.DateTime's counterpart.
There's two different ways to build a relativedelta instance. The
first one is passing it two date/datetime classes:
relativedelta(datetime1, datetime2)
And the other way is to use the following keyword arguments:
year, month, day, hour, minute, second, microsecond:
Absolute information.
years, months, weeks, days, hours, minutes, seconds, microseconds:
Relative information, may be negative.
weekday:
One of the weekday instances (MO, TU, etc). These instances may
receive a parameter N, specifying the Nth weekday, which could
be positive or negative (like MO(+1) or MO(-2). Not specifying
it is the same as specifying +1. You can also use an integer,
where 0=MO.
leapdays:
Will add given days to the date found, if year is a leap
year, and the date found is post 28 of february.
yearday, nlyearday:
Set the yearday or the non-leap year day (jump leap days).
These are converted to day/month/leapdays information.
Here is the behavior of operations with relativedelta:
1) Calculate the absolute year, using the 'year' argument, or the
original datetime year, if the argument is not present.
2) Add the relative 'years' argument to the absolute year.
3) Do steps 1 and 2 for month/months.
4) Calculate the absolute day, using the 'day' argument, or the
original datetime day, if the argument is not present. Then,
subtract from the day until it fits in the year and month
found after their operations.
5) Add the relative 'days' argument to the absolute day. Notice
that the 'weeks' argument is multiplied by 7 and added to
'days'.
6) Do steps 1 and 2 for hour/hours, minute/minutes, second/seconds,
microsecond/microseconds.
7) If the 'weekday' argument is present, calculate the weekday,
with the given (wday, nth) tuple. wday is the index of the
weekday (0-6, 0=Mon), and nth is the number of weeks to add
forward or backward, depending on its signal. Notice that if
the calculated date is already Monday, for example, using
(0, 1) or (0, -1) won't change the day.
"""
def __init__(self, dt1=None, dt2=None,
years=0, months=0, days=0, leapdays=0, weeks=0,
hours=0, minutes=0, seconds=0, microseconds=0,
year=None, month=None, day=None, weekday=None,
yearday=None, nlyearday=None,
hour=None, minute=None, second=None, microsecond=None):
if dt1 and dt2:
if not isinstance(dt1, datetime.date) or \
not isinstance(dt2, datetime.date):
raise TypeError("relativedelta only diffs datetime/date")
if type(dt1) is not type(dt2):
if not isinstance(dt1, datetime.datetime):
dt1 = datetime.datetime.fromordinal(dt1.toordinal())
elif not isinstance(dt2, datetime.datetime):
dt2 = datetime.datetime.fromordinal(dt2.toordinal())
self.years = 0
self.months = 0
self.days = 0
self.leapdays = 0
self.hours = 0
self.minutes = 0
self.seconds = 0
self.microseconds = 0
self.year = None
self.month = None
self.day = None
self.weekday = None
self.hour = None
self.minute = None
self.second = None
self.microsecond = None
self._has_time = 0
months = (dt1.year * 12 + dt1.month) - (dt2.year * 12 + dt2.month)
self._set_months(months)
dtm = self.__radd__(dt2)
if dt1 < dt2:
while dt1 > dtm:
months += 1
self._set_months(months)
dtm = self.__radd__(dt2)
else:
while dt1 < dtm:
months -= 1
self._set_months(months)
dtm = self.__radd__(dt2)
delta = dt1 - dtm
self.seconds = delta.seconds + delta.days * 86400
self.microseconds = delta.microseconds
else:
self.years = years
self.months = months
self.days = days + weeks * 7
self.leapdays = leapdays
self.hours = hours
self.minutes = minutes
self.seconds = seconds
self.microseconds = microseconds
self.year = year
self.month = month
self.day = day
self.hour = hour
self.minute = minute
self.second = second
self.microsecond = microsecond
if type(weekday) is int:
self.weekday = weekdays[weekday]
else:
self.weekday = weekday
yday = 0
if nlyearday:
yday = nlyearday
elif yearday:
yday = yearday
if yearday > 59:
self.leapdays = -1
if yday:
ydayidx = [31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334,
366]
for idx, ydays in enumerate(ydayidx):
if yday <= ydays:
self.month = idx + 1
if idx == 0:
self.day = yday
else:
self.day = yday - ydayidx[idx - 1]
break
else:
raise ValueError("invalid year day (%d)" % yday)
self._fix()
def _fix(self):
if abs(self.microseconds) > 999999:
s = self.microseconds // abs(self.microseconds)
div, mod = divmod(self.microseconds * s, 1000000)
self.microseconds = mod * s
self.seconds += div * s
if abs(self.seconds) > 59:
s = self.seconds // abs(self.seconds)
div, mod = divmod(self.seconds * s, 60)
self.seconds = mod * s
self.minutes += div * s
if abs(self.minutes) > 59:
s = self.minutes // abs(self.minutes)
div, mod = divmod(self.minutes * s, 60)
self.minutes = mod * s
self.hours += div * s
if abs(self.hours) > 23:
s = self.hours // abs(self.hours)
div, mod = divmod(self.hours * s, 24)
self.hours = mod * s
self.days += div * s
if abs(self.months) > 11:
s = self.months // abs(self.months)
div, mod = divmod(self.months * s, 12)
self.months = mod * s
self.years += div * s
if (self.hours or self.minutes or self.seconds or self.microseconds or
self.hour is not None or self.minute is not None or
self.second is not None or self.microsecond is not None):
self._has_time = 1
else:
self._has_time = 0
def _set_months(self, months):
self.months = months
if abs(self.months) > 11:
s = self.months // abs(self.months)
div, mod = divmod(self.months * s, 12)
self.months = mod * s
self.years = div * s
else:
self.years = 0
def __radd__(self, other):
if not isinstance(other, datetime.date):
raise TypeError("unsupported type for add operation")
elif self._has_time and not isinstance(other, datetime.datetime):
other = datetime.datetime.fromordinal(other.toordinal())
year = (self.year or other.year) + self.years
month = self.month or other.month
if self.months:
assert 1 <= abs(self.months) <= 12
month += self.months
if month > 12:
year += 1
month -= 12
elif month < 1:
year -= 1
month += 12
day = min(calendar.monthrange(year, month)[1],
self.day or other.day)
repl = {"year": year, "month": month, "day": day}
for attr in ["hour", "minute", "second", "microsecond"]:
value = getattr(self, attr)
if value is not None:
repl[attr] = value
days = self.days
if self.leapdays and month > 2 and calendar.isleap(year):
days += self.leapdays
ret = (other.replace(**repl)
+ datetime.timedelta(days=days,
hours=self.hours,
minutes=self.minutes,
seconds=self.seconds,
microseconds=self.microseconds))
if self.weekday:
weekday, nth = self.weekday.weekday, self.weekday.n or 1
jumpdays = (abs(nth) - 1) * 7
if nth > 0:
jumpdays += (7 - ret.weekday() + weekday) % 7
else:
jumpdays += (ret.weekday() - weekday) % 7
jumpdays *= -1
ret += datetime.timedelta(days=jumpdays)
return ret
def __rsub__(self, other):
return self.__neg__().__radd__(other)
def __add__(self, other):
if not isinstance(other, relativedelta):
raise TypeError("unsupported type for add operation")
return relativedelta(years=other.years + self.years,
months=other.months + self.months,
days=other.days + self.days,
hours=other.hours + self.hours,
minutes=other.minutes + self.minutes,
seconds=other.seconds + self.seconds,
microseconds=other.microseconds + self.microseconds,
leapdays=other.leapdays or self.leapdays,
year=other.year or self.year,
month=other.month or self.month,
day=other.day or self.day,
weekday=other.weekday or self.weekday,
hour=other.hour or self.hour,
minute=other.minute or self.minute,
second=other.second or self.second,
microsecond=other.second or self.microsecond)
def __sub__(self, other):
if not isinstance(other, relativedelta):
raise TypeError("unsupported type for sub operation")
return relativedelta(years=other.years - self.years,
months=other.months - self.months,
days=other.days - self.days,
hours=other.hours - self.hours,
minutes=other.minutes - self.minutes,
seconds=other.seconds - self.seconds,
microseconds=other.microseconds - self.microseconds,
leapdays=other.leapdays or self.leapdays,
year=other.year or self.year,
month=other.month or self.month,
day=other.day or self.day,
weekday=other.weekday or self.weekday,
hour=other.hour or self.hour,
minute=other.minute or self.minute,
second=other.second or self.second,
microsecond=other.second or self.microsecond)
def __neg__(self):
return relativedelta(years= -self.years,
months= -self.months,
days= -self.days,
hours= -self.hours,
minutes= -self.minutes,
seconds= -self.seconds,
microseconds= -self.microseconds,
leapdays=self.leapdays,
year=self.year,
month=self.month,
day=self.day,
weekday=self.weekday,
hour=self.hour,
minute=self.minute,
second=self.second,
microsecond=self.microsecond)
def __nonzero__(self):
return not (not self.years and
not self.months and
not self.days and
not self.hours and
not self.minutes and
not self.seconds and
not self.microseconds and
not self.leapdays and
self.year is None and
self.month is None and
self.day is None and
self.weekday is None and
self.hour is None and
self.minute is None and
self.second is None and
self.microsecond is None)
__bool__ = __nonzero__
def __mul__(self, other):
f = float(other)
return relativedelta(years=self.years * f,
months=self.months * f,
days=self.days * f,
hours=self.hours * f,
minutes=self.minutes * f,
seconds=self.seconds * f,
microseconds=self.microseconds * f,
leapdays=self.leapdays,
year=self.year,
month=self.month,
day=self.day,
weekday=self.weekday,
hour=self.hour,
minute=self.minute,
second=self.second,
microsecond=self.microsecond)
def __eq__(self, other):
if not isinstance(other, relativedelta):
return False
if self.weekday or other.weekday:
if not self.weekday or not other.weekday:
return False
if self.weekday.weekday != other.weekday.weekday:
return False
n1, n2 = self.weekday.n, other.weekday.n
if n1 != n2 and not ((not n1 or n1 == 1) and (not n2 or n2 == 1)):
return False
return (self.years == other.years and
self.months == other.months and
self.days == other.days and
self.hours == other.hours and
self.minutes == other.minutes and
self.seconds == other.seconds and
self.leapdays == other.leapdays and
self.year == other.year and
self.month == other.month and
self.day == other.day and
self.hour == other.hour and
self.minute == other.minute and
self.second == other.second and
self.microsecond == other.microsecond)
def __ne__(self, other):
return not self.__eq__(other)
def __div__(self, other):
return self.__mul__(1 / float(other))
def __repr__(self):
l = []
for attr in ["years", "months", "days", "leapdays",
"hours", "minutes", "seconds", "microseconds"]:
value = getattr(self, attr)
if value:
l.append("%s=%+d" % (attr, value))
for attr in ["year", "month", "day", "weekday",
"hour", "minute", "second", "microsecond"]:
value = getattr(self, attr)
if value is not None:
l.append("%s=%s" % (attr, repr(value)))
return "%s(%s)" % (self.__class__.__name__, ", ".join(l))
# vim:ts=4:sw=4:et
|
agpl-3.0
|
[
624,
199,
7384,
334,
67,
9,
13004,
13,
6542,
221,
598,
833,
1214,
79,
653,
1873,
278,
23009,
665,
71,
833,
1214,
79,
32,
78,
1873,
278,
23009,
14,
846,
30,
199,
199,
2765,
859,
32563,
5478,
370,
314,
4465,
2366,
499,
14,
19,
11,
199,
2083,
859,
14,
199,
624,
199,
363,
2502,
363,
275,
298,
39,
833,
1214,
79,
653,
1873,
278,
23009,
665,
71,
833,
1214,
79,
32,
78,
1873,
278,
23009,
14,
846,
4335,
199,
363,
1682,
363,
275,
298,
5067,
38,
844,
2,
199,
199,
646,
2197,
199,
646,
11234,
199,
199,
363,
452,
363,
275,
2097,
32300,
401,
298,
2679,
401,
298,
21364,
401,
298,
5408,
401,
298,
2080,
401,
298,
5372,
401,
298,
4251,
401,
298,
6195,
937,
421,
199,
533,
20947,
8,
785,
304,
272,
636,
7257,
363,
275,
2097,
12451,
401,
298,
78,
937,
339,
347,
636,
826,
721,
277,
12,
20947,
12,
302,
29,
403,
304,
267,
291,
14,
12451,
275,
20947,
267,
291,
14,
78,
275,
302,
339,
347,
636,
1250,
721,
277,
12,
302,
304,
267,
340,
302,
508,
291,
14,
78,
26,
288,
372,
291,
267,
587,
26,
288,
372,
291,
855,
533,
721,
277,
14,
12451,
12,
302,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
862,
26,
288,
340,
291,
14,
12451,
1137,
1163,
14,
12451,
503,
291,
14,
78,
1137,
1163,
14,
78,
26,
355,
372,
756,
267,
871,
4281,
26,
288,
372,
756,
267,
372,
715,
339,
347,
636,
2722,
721,
277,
304,
267,
308,
275,
1689,
2679,
401,
298,
21364,
401,
298,
5408,
401,
298,
2080,
401,
298,
5372,
401,
298,
4251,
401,
298,
6195,
9981,
277,
14,
12451,
61,
267,
340,
440,
291,
14,
78,
26,
288,
372,
308,
267,
587,
26,
288,
372,
2071,
83,
4042,
11,
68,
2924,
450,
334,
83,
12,
291,
14,
78,
9,
199,
199,
2679,
12,
377,
53,
12,
644,
37,
12,
4221,
12,
28671,
12,
13950,
12,
5698,
275,
8620,
4899,
275,
2008,
779,
12451,
8,
88,
9,
367,
671,
315,
1425,
8,
23,
3948,
421,
199,
533,
20599,
26,
272,
408,
199,
1918,
20599,
730,
365,
4079,
641,
314,
8929,
402,
314,
444,
6067,
12518,
199,
800,
4224,
701,
603,
23683,
33,
14,
7005,
32649,
315,
17049,
8728,
14,
3926,
3329,
14,
9738,
12,
199,
20556,
626,
642,
730,
1630,
627,
4609,
10,
5669,
314,
2011,
5563,
465,
199,
866,
1736,
14,
4226,
627,
4609,
10,
4282,
652,
370,
24062,
2839,
8728,
14,
3926,
1159,
7055,
2064,
14,
199,
199,
10924,
1159,
2877,
3365,
15217,
370,
1900,
282,
20599,
1256,
14,
710,
199,
2246,
1373,
365,
9476,
652,
2877,
1434,
15,
2083,
3992,
26,
339,
20599,
8,
2083,
17,
12,
2197,
18,
9,
199,
199,
3325,
314,
1163,
4340,
365,
370,
675,
314,
2569,
4252,
2368,
26,
339,
5361,
12,
5794,
12,
5382,
12,
6925,
12,
12709,
12,
3499,
12,
25824,
26,
267,
24964,
2556,
14,
339,
17399,
12,
20096,
12,
29540,
12,
7609,
12,
10857,
12,
9395,
12,
4696,
12,
21574,
26,
267,
22419,
2556,
12,
1443,
506,
6946,
14,
339,
20947,
26,
267,
7309,
402,
314,
20947,
4454,
334,
2679,
12,
377,
53,
12,
5423,
680,
5723,
4454,
1443,
267,
9128,
282,
2725,
653,
12,
9176,
314,
653,
273,
20947,
12,
1314,
4293,
267,
506,
7317,
503,
6946,
334,
2930,
10362,
24303,
17,
9,
503,
10362,
2801,
18,
680,
2832,
9176,
267,
652,
365,
314,
2011,
465,
9176,
435,
17,
14,
2047,
883,
2597,
675,
376,
3000,
12,
267,
2382,
378,
29,
2679,
14,
339,
29487,
4899,
26,
267,
12823,
1050,
1627,
7609,
370,
314,
1434,
1911,
12,
340,
5361,
365,
282,
29487,
267,
5361,
12,
436,
314,
1434,
1911,
365,
2963,
7294,
402,
1964,
3289,
20527,
14,
339,
5361,
2977,
12,
302,
590,
2210,
2977,
26,
267,
2494,
314,
5361,
2977,
503,
314,
2222,
13,
28764,
5361,
5382,
334,
11126,
29487,
7609,
680,
267,
5723,
787,
6702,
370,
5382,
15,
4482,
15,
28764,
4899,
2556,
14,
199,
199,
21741,
365,
314,
5953,
402,
5331,
543,
20599,
26,
199,
199,
17,
9,
12707,
314,
3679,
5361,
12,
1808,
314,
283,
3403,
7,
1423,
12,
503,
314,
2043,
3379,
2197,
5361,
12,
340,
314,
1423,
365,
440,
3451,
14,
199,
199,
18,
9,
2654,
314,
3847,
283,
18431,
7,
1423,
370,
314,
3679,
5361,
14,
199,
199,
19,
9,
4226,
7124,
413,
436,
499,
367,
5794,
15,
16745,
14,
199,
199,
20,
9,
12707,
314,
3679,
5382,
12,
1808,
314,
283,
2977,
7,
1423,
12,
503,
314,
2043,
3379,
2197,
5382,
12,
340,
314,
1423,
365,
440,
3451,
14,
9442,
12,
2043,
24129,
687,
314,
5382,
5133,
652,
20147,
315,
314,
5361,
436,
5794,
2043,
1911,
2410,
3932,
5331,
14,
199,
199,
21,
9,
2654,
314,
3847,
283,
4899,
7,
1423,
370,
314,
3679,
5382,
14,
3091,
3548,
2043,
626,
314,
283,
25287,
7,
1423,
365,
29597,
701,
1520,
436,
3483,
370,
2043,
283,
4899,
1370,
199,
199,
22,
9,
4226,
7124,
413,
436,
499,
367,
6925,
15,
8419,
12,
12709,
15,
10430,
12,
3499,
15,
4515,
12,
2043,
25824,
15,
18144,
14,
199,
199,
23,
9,
982,
314,
283,
12451,
7,
1423,
365,
3451,
12,
8671,
314,
20947,
12,
2043,
543,
314,
1627,
334,
87,
2977,
12,
30564,
9,
2008,
14,
336,
2977,
365,
314,
1478,
402,
314,
2043,
20947,
334,
16,
13,
22,
12,
378,
29,
6671,
395,
436,
30564,
365,
314,
1329,
402,
29540,
370,
1050,
2043,
7568,
503,
13388,
12,
10298,
641,
2399,
4673,
14,
3091,
3548,
626,
340,
2043,
314,
12950,
1434,
365,
2575,
32740,
12,
367,
2893,
12,
1808,
2043,
334,
16,
12,
413,
9,
503,
334,
16,
12,
446,
17,
9,
7859,
1133,
1570,
314,
5382,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
4487,
17,
29,
403,
12,
4487,
18,
29,
403,
12,
326,
17399,
29,
16,
12,
20096,
29,
16,
12,
7609,
29,
16,
12,
29487,
4899,
29,
16,
12,
29540,
29,
16,
12,
326,
10857,
29,
16,
12,
9395,
29,
16,
12,
4696,
29,
16,
12,
21574,
29,
16,
12,
326,
5361,
29,
403,
12,
5794,
29,
403,
12,
5382,
29,
403,
12,
20947,
29,
403,
12,
326,
5361,
2977,
29
] |
[
199,
7384,
334,
67,
9,
13004,
13,
6542,
221,
598,
833,
1214,
79,
653,
1873,
278,
23009,
665,
71,
833,
1214,
79,
32,
78,
1873,
278,
23009,
14,
846,
30,
199,
199,
2765,
859,
32563,
5478,
370,
314,
4465,
2366,
499,
14,
19,
11,
199,
2083,
859,
14,
199,
624,
199,
363,
2502,
363,
275,
298,
39,
833,
1214,
79,
653,
1873,
278,
23009,
665,
71,
833,
1214,
79,
32,
78,
1873,
278,
23009,
14,
846,
4335,
199,
363,
1682,
363,
275,
298,
5067,
38,
844,
2,
199,
199,
646,
2197,
199,
646,
11234,
199,
199,
363,
452,
363,
275,
2097,
32300,
401,
298,
2679,
401,
298,
21364,
401,
298,
5408,
401,
298,
2080,
401,
298,
5372,
401,
298,
4251,
401,
298,
6195,
937,
421,
199,
533,
20947,
8,
785,
304,
272,
636,
7257,
363,
275,
2097,
12451,
401,
298,
78,
937,
339,
347,
636,
826,
721,
277,
12,
20947,
12,
302,
29,
403,
304,
267,
291,
14,
12451,
275,
20947,
267,
291,
14,
78,
275,
302,
339,
347,
636,
1250,
721,
277,
12,
302,
304,
267,
340,
302,
508,
291,
14,
78,
26,
288,
372,
291,
267,
587,
26,
288,
372,
291,
855,
533,
721,
277,
14,
12451,
12,
302,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
862,
26,
288,
340,
291,
14,
12451,
1137,
1163,
14,
12451,
503,
291,
14,
78,
1137,
1163,
14,
78,
26,
355,
372,
756,
267,
871,
4281,
26,
288,
372,
756,
267,
372,
715,
339,
347,
636,
2722,
721,
277,
304,
267,
308,
275,
1689,
2679,
401,
298,
21364,
401,
298,
5408,
401,
298,
2080,
401,
298,
5372,
401,
298,
4251,
401,
298,
6195,
9981,
277,
14,
12451,
61,
267,
340,
440,
291,
14,
78,
26,
288,
372,
308,
267,
587,
26,
288,
372,
2071,
83,
4042,
11,
68,
2924,
450,
334,
83,
12,
291,
14,
78,
9,
199,
199,
2679,
12,
377,
53,
12,
644,
37,
12,
4221,
12,
28671,
12,
13950,
12,
5698,
275,
8620,
4899,
275,
2008,
779,
12451,
8,
88,
9,
367,
671,
315,
1425,
8,
23,
3948,
421,
199,
533,
20599,
26,
272,
408,
199,
1918,
20599,
730,
365,
4079,
641,
314,
8929,
402,
314,
444,
6067,
12518,
199,
800,
4224,
701,
603,
23683,
33,
14,
7005,
32649,
315,
17049,
8728,
14,
3926,
3329,
14,
9738,
12,
199,
20556,
626,
642,
730,
1630,
627,
4609,
10,
5669,
314,
2011,
5563,
465,
199,
866,
1736,
14,
4226,
627,
4609,
10,
4282,
652,
370,
24062,
2839,
8728,
14,
3926,
1159,
7055,
2064,
14,
199,
199,
10924,
1159,
2877,
3365,
15217,
370,
1900,
282,
20599,
1256,
14,
710,
199,
2246,
1373,
365,
9476,
652,
2877,
1434,
15,
2083,
3992,
26,
339,
20599,
8,
2083,
17,
12,
2197,
18,
9,
199,
199,
3325,
314,
1163,
4340,
365,
370,
675,
314,
2569,
4252,
2368,
26,
339,
5361,
12,
5794,
12,
5382,
12,
6925,
12,
12709,
12,
3499,
12,
25824,
26,
267,
24964,
2556,
14,
339,
17399,
12,
20096,
12,
29540,
12,
7609,
12,
10857,
12,
9395,
12,
4696,
12,
21574,
26,
267,
22419,
2556,
12,
1443,
506,
6946,
14,
339,
20947,
26,
267,
7309,
402,
314,
20947,
4454,
334,
2679,
12,
377,
53,
12,
5423,
680,
5723,
4454,
1443,
267,
9128,
282,
2725,
653,
12,
9176,
314,
653,
273,
20947,
12,
1314,
4293,
267,
506,
7317,
503,
6946,
334,
2930,
10362,
24303,
17,
9,
503,
10362,
2801,
18,
680,
2832,
9176,
267,
652,
365,
314,
2011,
465,
9176,
435,
17,
14,
2047,
883,
2597,
675,
376,
3000,
12,
267,
2382,
378,
29,
2679,
14,
339,
29487,
4899,
26,
267,
12823,
1050,
1627,
7609,
370,
314,
1434,
1911,
12,
340,
5361,
365,
282,
29487,
267,
5361,
12,
436,
314,
1434,
1911,
365,
2963,
7294,
402,
1964,
3289,
20527,
14,
339,
5361,
2977,
12,
302,
590,
2210,
2977,
26,
267,
2494,
314,
5361,
2977,
503,
314,
2222,
13,
28764,
5361,
5382,
334,
11126,
29487,
7609,
680,
267,
5723,
787,
6702,
370,
5382,
15,
4482,
15,
28764,
4899,
2556,
14,
199,
199,
21741,
365,
314,
5953,
402,
5331,
543,
20599,
26,
199,
199,
17,
9,
12707,
314,
3679,
5361,
12,
1808,
314,
283,
3403,
7,
1423,
12,
503,
314,
2043,
3379,
2197,
5361,
12,
340,
314,
1423,
365,
440,
3451,
14,
199,
199,
18,
9,
2654,
314,
3847,
283,
18431,
7,
1423,
370,
314,
3679,
5361,
14,
199,
199,
19,
9,
4226,
7124,
413,
436,
499,
367,
5794,
15,
16745,
14,
199,
199,
20,
9,
12707,
314,
3679,
5382,
12,
1808,
314,
283,
2977,
7,
1423,
12,
503,
314,
2043,
3379,
2197,
5382,
12,
340,
314,
1423,
365,
440,
3451,
14,
9442,
12,
2043,
24129,
687,
314,
5382,
5133,
652,
20147,
315,
314,
5361,
436,
5794,
2043,
1911,
2410,
3932,
5331,
14,
199,
199,
21,
9,
2654,
314,
3847,
283,
4899,
7,
1423,
370,
314,
3679,
5382,
14,
3091,
3548,
2043,
626,
314,
283,
25287,
7,
1423,
365,
29597,
701,
1520,
436,
3483,
370,
2043,
283,
4899,
1370,
199,
199,
22,
9,
4226,
7124,
413,
436,
499,
367,
6925,
15,
8419,
12,
12709,
15,
10430,
12,
3499,
15,
4515,
12,
2043,
25824,
15,
18144,
14,
199,
199,
23,
9,
982,
314,
283,
12451,
7,
1423,
365,
3451,
12,
8671,
314,
20947,
12,
2043,
543,
314,
1627,
334,
87,
2977,
12,
30564,
9,
2008,
14,
336,
2977,
365,
314,
1478,
402,
314,
2043,
20947,
334,
16,
13,
22,
12,
378,
29,
6671,
395,
436,
30564,
365,
314,
1329,
402,
29540,
370,
1050,
2043,
7568,
503,
13388,
12,
10298,
641,
2399,
4673,
14,
3091,
3548,
626,
340,
2043,
314,
12950,
1434,
365,
2575,
32740,
12,
367,
2893,
12,
1808,
2043,
334,
16,
12,
413,
9,
503,
334,
16,
12,
446,
17,
9,
7859,
1133,
1570,
314,
5382,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
4487,
17,
29,
403,
12,
4487,
18,
29,
403,
12,
326,
17399,
29,
16,
12,
20096,
29,
16,
12,
7609,
29,
16,
12,
29487,
4899,
29,
16,
12,
29540,
29,
16,
12,
326,
10857,
29,
16,
12,
9395,
29,
16,
12,
4696,
29,
16,
12,
21574,
29,
16,
12,
326,
5361,
29,
403,
12,
5794,
29,
403,
12,
5382,
29,
403,
12,
20947,
29,
403,
12,
326,
5361,
2977,
29,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
luistorresm/odoo
|
openerp/exceptions.py
|
312
|
3157
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2011 OpenERP s.a. (<http://openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
""" OpenERP core exceptions.
This module defines a few exception types. Those types are understood by the
RPC layer. Any other exception type bubbling until the RPC layer will be
treated as a 'Server error'.
If you consider introducing new exceptions, check out the test_exceptions addon.
"""
# kept for backward compatibility
class except_orm(Exception):
def __init__(self, name, value):
self.name = name
self.value = value
self.args = (name, value)
class Warning(Exception):
pass
class RedirectWarning(Exception):
""" Warning with a possibility to redirect the user instead of simply
diplaying the warning message.
Should receive as parameters:
:param int action_id: id of the action where to perform the redirection
:param string button_text: text to put on the button that will trigger
the redirection.
"""
class AccessDenied(Exception):
""" Login/password error. No message, no traceback. """
def __init__(self):
super(AccessDenied, self).__init__('Access denied.')
self.traceback = ('', '', '')
class AccessError(except_orm):
""" Access rights error. """
def __init__(self, msg):
super(AccessError, self).__init__('AccessError', msg)
class MissingError(except_orm):
""" Missing record(s). """
def __init__(self, msg):
super(MissingError, self).__init__('MissingError', msg)
class ValidationError(except_orm):
def __init__(self, msg):
super(ValidationError, self).__init__('ValidateError', msg)
class DeferredException(Exception):
""" Exception object holding a traceback for asynchronous reporting.
Some RPC calls (database creation and report generation) happen with
an initial request followed by multiple, polling requests. This class
is used to store the possible exception occuring in the thread serving
the first request, and is then sent to a polling request.
('Traceback' is misleading, this is really a exc_info() triple.)
"""
def __init__(self, msg, tb):
self.message = msg
self.traceback = tb
# 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,
7760,
7653,
308,
14,
65,
14,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
624,
7653,
6170,
4967,
14,
199,
199,
2765,
859,
7890,
282,
9284,
1919,
2943,
14,
18049,
261,
2943,
787,
1334,
14308,
364,
701,
314,
199,
8171,
4045,
14,
6184,
1163,
1919,
730,
330,
9256,
2983,
5133,
314,
11785,
4045,
911,
506,
199,
84,
9640,
465,
282,
283,
3120,
1125,
1370,
199,
199,
3917,
1265,
11201,
13318,
14713,
892,
4967,
12,
1104,
734,
314,
511,
63,
3924,
13553,
14,
199,
624,
199,
199,
3,
16204,
367,
13388,
7163,
199,
533,
871,
63,
1025,
8,
1726,
304,
272,
347,
636,
826,
721,
277,
12,
536,
12,
574,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
585,
275,
574,
267,
291,
14,
589,
275,
334,
354,
12,
574,
9,
199,
199,
533,
15902,
8,
1726,
304,
272,
986,
199,
199,
533,
18532,
3849,
8,
1726,
304,
272,
408,
15902,
543,
282,
31077,
370,
4660,
314,
922,
3140,
402,
9329,
272,
487,
22224,
314,
5721,
1245,
14,
339,
7719,
9128,
465,
2633,
26,
489,
520,
635,
1109,
1595,
63,
344,
26,
1305,
402,
314,
1595,
2382,
370,
5147,
314,
23713,
489,
520,
635,
1059,
5528,
63,
505,
26,
1318,
370,
5324,
641,
314,
5528,
626,
911,
6804,
881,
314,
23713,
14,
272,
408,
199,
199,
533,
11003,
15729,
8,
1726,
304,
272,
408,
16430,
15,
2060,
1125,
14,
3091,
1245,
12,
949,
5190,
14,
408,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
3946,
15729,
12,
291,
2843,
826,
19734,
3946,
23355,
2659,
267,
291,
14,
6894,
275,
13134,
3260,
4074,
199,
199,
533,
11003,
547,
8,
2590,
63,
1025,
304,
272,
408,
11003,
4481,
1125,
14,
408,
272,
347,
636,
826,
721,
277,
12,
1499,
304,
267,
1613,
8,
3946,
547,
12,
291,
2843,
826,
19734,
3946,
547,
297,
1499,
9,
199,
199,
533,
15626,
547,
8,
2590,
63,
1025,
304,
272,
408,
15626,
2777,
8,
83,
680,
408,
272,
347,
636,
826,
721,
277,
12,
1499,
304,
267,
1613,
8,
7718,
547,
12,
291,
2843,
826,
19734,
7718,
547,
297,
1499,
9,
199,
199,
533,
8505,
8,
2590,
63,
1025,
304,
272,
347,
636,
826,
721,
277,
12,
1499,
304,
267,
1613,
8,
8172,
12,
291,
2843,
826,
19734,
12584,
547,
297,
1499,
9,
199,
199,
533,
17448,
1726,
8,
1726,
304,
272,
408,
2186,
909,
17573,
282,
5190,
367,
15608,
17290,
14,
339,
6601,
11785,
4882,
334,
4659,
7143,
436,
3622,
10152,
9,
5992,
543,
272,
376,
2536,
1056,
9437,
701,
3663,
12,
12353,
4145,
14,
961,
1021,
272,
365,
1202,
370,
3877,
314,
3962,
1919,
4781,
316,
315,
314,
2462,
22701,
272,
314,
1642,
1056,
12,
436,
365,
2066,
4847,
370,
282,
12353,
1056,
14,
339,
661,
15905,
7,
365,
3201,
16812,
12,
642,
365,
7710,
282,
3178,
63,
815,
342,
19671,
4959,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1499,
12,
7070,
304,
267,
291,
14,
1188,
275,
1499,
267,
291,
14,
6894,
275,
7070,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
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,
7760,
7653,
308,
14,
65,
14,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
624,
7653,
6170,
4967,
14,
199,
199,
2765,
859,
7890,
282,
9284,
1919,
2943,
14,
18049,
261,
2943,
787,
1334,
14308,
364,
701,
314,
199,
8171,
4045,
14,
6184,
1163,
1919,
730,
330,
9256,
2983,
5133,
314,
11785,
4045,
911,
506,
199,
84,
9640,
465,
282,
283,
3120,
1125,
1370,
199,
199,
3917,
1265,
11201,
13318,
14713,
892,
4967,
12,
1104,
734,
314,
511,
63,
3924,
13553,
14,
199,
624,
199,
199,
3,
16204,
367,
13388,
7163,
199,
533,
871,
63,
1025,
8,
1726,
304,
272,
347,
636,
826,
721,
277,
12,
536,
12,
574,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
585,
275,
574,
267,
291,
14,
589,
275,
334,
354,
12,
574,
9,
199,
199,
533,
15902,
8,
1726,
304,
272,
986,
199,
199,
533,
18532,
3849,
8,
1726,
304,
272,
408,
15902,
543,
282,
31077,
370,
4660,
314,
922,
3140,
402,
9329,
272,
487,
22224,
314,
5721,
1245,
14,
339,
7719,
9128,
465,
2633,
26,
489,
520,
635,
1109,
1595,
63,
344,
26,
1305,
402,
314,
1595,
2382,
370,
5147,
314,
23713,
489,
520,
635,
1059,
5528,
63,
505,
26,
1318,
370,
5324,
641,
314,
5528,
626,
911,
6804,
881,
314,
23713,
14,
272,
408,
199,
199,
533,
11003,
15729,
8,
1726,
304,
272,
408,
16430,
15,
2060,
1125,
14,
3091,
1245,
12,
949,
5190,
14,
408,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
3946,
15729,
12,
291,
2843,
826,
19734,
3946,
23355,
2659,
267,
291,
14,
6894,
275,
13134,
3260,
4074,
199,
199,
533,
11003,
547,
8,
2590,
63,
1025,
304,
272,
408,
11003,
4481,
1125,
14,
408,
272,
347,
636,
826,
721,
277,
12,
1499,
304,
267,
1613,
8,
3946,
547,
12,
291,
2843,
826,
19734,
3946,
547,
297,
1499,
9,
199,
199,
533,
15626,
547,
8,
2590,
63,
1025,
304,
272,
408,
15626,
2777,
8,
83,
680,
408,
272,
347,
636,
826,
721,
277,
12,
1499,
304,
267,
1613,
8,
7718,
547,
12,
291,
2843,
826,
19734,
7718,
547,
297,
1499,
9,
199,
199,
533,
8505,
8,
2590,
63,
1025,
304,
272,
347,
636,
826,
721,
277,
12,
1499,
304,
267,
1613,
8,
8172,
12,
291,
2843,
826,
19734,
12584,
547,
297,
1499,
9,
199,
199,
533,
17448,
1726,
8,
1726,
304,
272,
408,
2186,
909,
17573,
282,
5190,
367,
15608,
17290,
14,
339,
6601,
11785,
4882,
334,
4659,
7143,
436,
3622,
10152,
9,
5992,
543,
272,
376,
2536,
1056,
9437,
701,
3663,
12,
12353,
4145,
14,
961,
1021,
272,
365,
1202,
370,
3877,
314,
3962,
1919,
4781,
316,
315,
314,
2462,
22701,
272,
314,
1642,
1056,
12,
436,
365,
2066,
4847,
370,
282,
12353,
1056,
14,
339,
661,
15905,
7,
365,
3201,
16812,
12,
642,
365,
7710,
282,
3178,
63,
815,
342,
19671,
4959,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1499,
12,
7070,
304,
267,
291,
14,
1188,
275,
1499,
267,
291,
14,
6894,
275,
7070,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ikool/metact06-djan
|
lib/apitools/base/py/list_pager_test.py
|
23
|
6861
|
"""Tests for list_pager."""
import unittest2
from apitools.base.py import list_pager
from apitools.base.py.testing import mock
from apitools.base.py.testing import testclient as fusiontables
class ListPagerTest(unittest2.TestCase):
def _AssertInstanceSequence(self, results, n):
counter = 0
for instance in results:
self.assertEqual(instance.name, 'c' + str(counter))
counter += 1
self.assertEqual(counter, n)
def setUp(self):
self.mocked_client = mock.Client(fusiontables.FusiontablesV1)
self.mocked_client.Mock()
self.addCleanup(self.mocked_client.Unmock)
def testYieldFromList(self):
self.mocked_client.column.List.Expect(
fusiontables.FusiontablesColumnListRequest(
maxResults=100,
pageToken=None,
tableId='mytable',
),
fusiontables.ColumnList(
items=[
fusiontables.Column(name='c0'),
fusiontables.Column(name='c1'),
fusiontables.Column(name='c2'),
fusiontables.Column(name='c3'),
],
nextPageToken='x',
))
self.mocked_client.column.List.Expect(
fusiontables.FusiontablesColumnListRequest(
maxResults=100,
pageToken='x',
tableId='mytable',
),
fusiontables.ColumnList(
items=[
fusiontables.Column(name='c4'),
fusiontables.Column(name='c5'),
fusiontables.Column(name='c6'),
fusiontables.Column(name='c7'),
],
))
client = fusiontables.FusiontablesV1(get_credentials=False)
request = fusiontables.FusiontablesColumnListRequest(tableId='mytable')
results = list_pager.YieldFromList(client.column, request)
self._AssertInstanceSequence(results, 8)
def testYieldNoRecords(self):
client = fusiontables.FusiontablesV1(get_credentials=False)
request = fusiontables.FusiontablesColumnListRequest(tableId='mytable')
results = list_pager.YieldFromList(client.column, request, limit=False)
self.assertEqual(0, len(list(results)))
def testYieldFromListPartial(self):
self.mocked_client.column.List.Expect(
fusiontables.FusiontablesColumnListRequest(
maxResults=100,
pageToken=None,
tableId='mytable',
),
fusiontables.ColumnList(
items=[
fusiontables.Column(name='c0'),
fusiontables.Column(name='c1'),
fusiontables.Column(name='c2'),
fusiontables.Column(name='c3'),
],
nextPageToken='x',
))
self.mocked_client.column.List.Expect(
fusiontables.FusiontablesColumnListRequest(
maxResults=100,
pageToken='x',
tableId='mytable',
),
fusiontables.ColumnList(
items=[
fusiontables.Column(name='c4'),
fusiontables.Column(name='c5'),
fusiontables.Column(name='c6'),
fusiontables.Column(name='c7'),
],
))
client = fusiontables.FusiontablesV1(get_credentials=False)
request = fusiontables.FusiontablesColumnListRequest(tableId='mytable')
results = list_pager.YieldFromList(client.column, request, limit=6)
self._AssertInstanceSequence(results, 6)
def testYieldFromListEmpty(self):
self.mocked_client.column.List.Expect(
fusiontables.FusiontablesColumnListRequest(
maxResults=100,
pageToken=None,
tableId='mytable',
),
fusiontables.ColumnList())
client = fusiontables.FusiontablesV1(get_credentials=False)
request = fusiontables.FusiontablesColumnListRequest(tableId='mytable')
results = list_pager.YieldFromList(client.column, request, limit=6)
self._AssertInstanceSequence(results, 0)
def testYieldFromListWithPredicate(self):
self.mocked_client.column.List.Expect(
fusiontables.FusiontablesColumnListRequest(
maxResults=100,
pageToken=None,
tableId='mytable',
),
fusiontables.ColumnList(
items=[
fusiontables.Column(name='c0'),
fusiontables.Column(name='bad0'),
fusiontables.Column(name='c1'),
fusiontables.Column(name='bad1'),
],
nextPageToken='x',
))
self.mocked_client.column.List.Expect(
fusiontables.FusiontablesColumnListRequest(
maxResults=100,
pageToken='x',
tableId='mytable',
),
fusiontables.ColumnList(
items=[
fusiontables.Column(name='c2'),
],
))
client = fusiontables.FusiontablesV1(get_credentials=False)
request = fusiontables.FusiontablesColumnListRequest(tableId='mytable')
results = list_pager.YieldFromList(
client.column, request, predicate=lambda x: 'c' in x.name)
self._AssertInstanceSequence(results, 3)
def testYieldFromListWithAttributes(self):
self.mocked_client.columnalternate.List.Expect(
fusiontables.FusiontablesColumnListAlternateRequest(
pageSize=100,
pageToken=None,
tableId='mytable',
),
fusiontables.ColumnListAlternate(
columns=[
fusiontables.Column(name='c0'),
fusiontables.Column(name='c1'),
],
nextPageToken='x',
))
self.mocked_client.columnalternate.List.Expect(
fusiontables.FusiontablesColumnListAlternateRequest(
pageSize=100,
pageToken='x',
tableId='mytable',
),
fusiontables.ColumnListAlternate(
columns=[
fusiontables.Column(name='c2'),
],
))
client = fusiontables.FusiontablesV1(get_credentials=False)
request = fusiontables.FusiontablesColumnListAlternateRequest(
tableId='mytable')
results = list_pager.YieldFromList(
client.columnalternate, request,
batch_size_attribute='pageSize', field='columns')
self._AssertInstanceSequence(results, 3)
|
bsd-3-clause
|
[
624,
2925,
367,
769,
63,
21219,
1041,
199,
199,
646,
2882,
18,
199,
199,
504,
2771,
390,
5998,
14,
1095,
14,
647,
492,
769,
63,
21219,
199,
504,
2771,
390,
5998,
14,
1095,
14,
647,
14,
4776,
492,
1683,
199,
504,
2771,
390,
5998,
14,
1095,
14,
647,
14,
4776,
492,
511,
1258,
465,
289,
12444,
5987,
421,
199,
533,
3820,
48,
1456,
774,
8,
2796,
18,
14,
1746,
304,
339,
347,
485,
9699,
3244,
5826,
8,
277,
12,
2058,
12,
302,
304,
267,
7055,
275,
378,
267,
367,
1256,
315,
2058,
26,
288,
291,
14,
629,
8,
842,
14,
354,
12,
283,
67,
7,
435,
620,
8,
5337,
430,
288,
7055,
847,
413,
398,
291,
14,
629,
8,
5337,
12,
302,
9,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
27740,
63,
1258,
275,
1683,
14,
3041,
8,
70,
12444,
5987,
14,
38,
12444,
5987,
54,
17,
9,
267,
291,
14,
27740,
63,
1258,
14,
3346,
342,
267,
291,
14,
12808,
8,
277,
14,
27740,
63,
1258,
14,
1358,
1805,
9,
339,
347,
511,
22889,
2532,
1296,
8,
277,
304,
267,
291,
14,
27740,
63,
1258,
14,
2301,
14,
1296,
14,
13495,
8,
288,
289,
12444,
5987,
14,
38,
12444,
5987,
4547,
1296,
2017,
8,
355,
1390,
6579,
29,
1960,
12,
355,
2034,
3264,
29,
403,
12,
355,
1817,
1304,
534,
1662,
1224,
297,
288,
2318,
288,
289,
12444,
5987,
14,
4547,
1296,
8,
355,
2974,
1524,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
16,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
17,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
18,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
19,
659,
355,
2156,
355,
2163,
3276,
3264,
534,
88,
297,
288,
5082,
267,
291,
14,
27740,
63,
1258,
14,
2301,
14,
1296,
14,
13495,
8,
288,
289,
12444,
5987,
14,
38,
12444,
5987,
4547,
1296,
2017,
8,
355,
1390,
6579,
29,
1960,
12,
355,
2034,
3264,
534,
88,
297,
355,
1817,
1304,
534,
1662,
1224,
297,
288,
2318,
288,
289,
12444,
5987,
14,
4547,
1296,
8,
355,
2974,
1524,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
20,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
21,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
22,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
23,
659,
355,
2156,
288,
5082,
398,
1890,
275,
289,
12444,
5987,
14,
38,
12444,
5987,
54,
17,
8,
362,
63,
6942,
29,
797,
9,
267,
1056,
275,
289,
12444,
5987,
14,
38,
12444,
5987,
4547,
1296,
2017,
8,
1224,
1304,
534,
1662,
1224,
358,
267,
2058,
275,
769,
63,
21219,
14,
22889,
2532,
1296,
8,
1258,
14,
2301,
12,
1056,
9,
398,
291,
423,
9699,
3244,
5826,
8,
2604,
12,
1695,
9,
339,
347,
511,
22889,
1944,
14941,
8,
277,
304,
267,
1890,
275,
289,
12444,
5987,
14,
38,
12444,
5987,
54,
17,
8,
362,
63,
6942,
29,
797,
9,
267,
1056,
275,
289,
12444,
5987,
14,
38,
12444,
5987,
4547,
1296,
2017,
8,
1224,
1304,
534,
1662,
1224,
358,
267,
2058,
275,
769,
63,
21219,
14,
22889,
2532,
1296,
8,
1258,
14,
2301,
12,
1056,
12,
2304,
29,
797,
9,
267,
291,
14,
629,
8,
16,
12,
822,
8,
513,
8,
2604,
1724,
339,
347,
511,
22889,
2532,
1296,
18192,
8,
277,
304,
267,
291,
14,
27740,
63,
1258,
14,
2301,
14,
1296,
14,
13495,
8,
288,
289,
12444,
5987,
14,
38,
12444,
5987,
4547,
1296,
2017,
8,
355,
1390,
6579,
29,
1960,
12,
355,
2034,
3264,
29,
403,
12,
355,
1817,
1304,
534,
1662,
1224,
297,
288,
2318,
288,
289,
12444,
5987,
14,
4547,
1296,
8,
355,
2974,
1524,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
16,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
17,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
18,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
19,
659,
355,
2156,
355,
2163,
3276,
3264,
534,
88,
297,
288,
5082,
267,
291,
14,
27740,
63,
1258,
14,
2301,
14,
1296,
14,
13495,
8,
288,
289,
12444,
5987,
14,
38,
12444,
5987,
4547,
1296,
2017,
8,
355,
1390,
6579,
29,
1960,
12,
355,
2034,
3264,
534,
88,
297,
355,
1817,
1304,
534,
1662,
1224,
297,
288,
2318,
288,
289,
12444,
5987,
14,
4547,
1296,
8,
355,
2974,
1524,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
20,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
21,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
22,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
23,
659,
355,
2156,
288,
5082,
398,
1890,
275,
289,
12444,
5987,
14,
38,
12444,
5987,
54,
17,
8,
362,
63,
6942,
29,
797,
9,
267,
1056,
275,
289,
12444,
5987,
14,
38,
12444,
5987,
4547,
1296,
2017,
8,
1224,
1304,
534,
1662,
1224,
358,
267,
2058,
275,
769,
63,
21219,
14,
22889,
2532,
1296,
8,
1258,
14,
2301,
12,
1056,
12,
2304,
29,
22,
9,
398,
291,
423,
9699,
3244,
5826,
8,
2604,
12,
1227,
9,
339,
347,
511,
22889,
2532,
1296,
4699,
8,
277,
304,
267,
291,
14,
27740,
63,
1258,
14,
2301,
14,
1296,
14,
13495,
8,
288,
289,
12444,
5987,
14,
38,
12444,
5987,
4547,
1296,
2017,
8,
355,
1390,
6579,
29,
1960,
12,
355,
2034,
3264,
29,
403,
12,
355,
1817,
1304,
534,
1662,
1224,
297,
288,
2318,
288,
289,
12444,
5987,
14,
4547,
1296,
1012,
398,
1890,
275,
289,
12444,
5987,
14,
38,
12444,
5987,
54,
17,
8,
362,
63,
6942,
29,
797,
9,
267,
1056,
275,
289,
12444,
5987,
14,
38,
12444,
5987,
4547,
1296,
2017,
8,
1224,
1304,
534,
1662,
1224,
358,
267,
2058,
275,
769,
63,
21219,
14,
22889,
2532,
1296,
8,
1258,
14,
2301,
12,
1056,
12,
2304,
29,
22,
9,
398,
291,
423,
9699,
3244,
5826,
8,
2604,
12,
378,
9,
339,
347,
511,
22889,
2532,
1296,
3007,
22236,
8,
277,
304,
267,
291,
14,
27740,
63,
1258,
14,
2301,
14,
1296,
14,
13495,
8,
288,
289,
12444
] |
[
2925,
367,
769,
63,
21219,
1041,
199,
199,
646,
2882,
18,
199,
199,
504,
2771,
390,
5998,
14,
1095,
14,
647,
492,
769,
63,
21219,
199,
504,
2771,
390,
5998,
14,
1095,
14,
647,
14,
4776,
492,
1683,
199,
504,
2771,
390,
5998,
14,
1095,
14,
647,
14,
4776,
492,
511,
1258,
465,
289,
12444,
5987,
421,
199,
533,
3820,
48,
1456,
774,
8,
2796,
18,
14,
1746,
304,
339,
347,
485,
9699,
3244,
5826,
8,
277,
12,
2058,
12,
302,
304,
267,
7055,
275,
378,
267,
367,
1256,
315,
2058,
26,
288,
291,
14,
629,
8,
842,
14,
354,
12,
283,
67,
7,
435,
620,
8,
5337,
430,
288,
7055,
847,
413,
398,
291,
14,
629,
8,
5337,
12,
302,
9,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
27740,
63,
1258,
275,
1683,
14,
3041,
8,
70,
12444,
5987,
14,
38,
12444,
5987,
54,
17,
9,
267,
291,
14,
27740,
63,
1258,
14,
3346,
342,
267,
291,
14,
12808,
8,
277,
14,
27740,
63,
1258,
14,
1358,
1805,
9,
339,
347,
511,
22889,
2532,
1296,
8,
277,
304,
267,
291,
14,
27740,
63,
1258,
14,
2301,
14,
1296,
14,
13495,
8,
288,
289,
12444,
5987,
14,
38,
12444,
5987,
4547,
1296,
2017,
8,
355,
1390,
6579,
29,
1960,
12,
355,
2034,
3264,
29,
403,
12,
355,
1817,
1304,
534,
1662,
1224,
297,
288,
2318,
288,
289,
12444,
5987,
14,
4547,
1296,
8,
355,
2974,
1524,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
16,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
17,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
18,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
19,
659,
355,
2156,
355,
2163,
3276,
3264,
534,
88,
297,
288,
5082,
267,
291,
14,
27740,
63,
1258,
14,
2301,
14,
1296,
14,
13495,
8,
288,
289,
12444,
5987,
14,
38,
12444,
5987,
4547,
1296,
2017,
8,
355,
1390,
6579,
29,
1960,
12,
355,
2034,
3264,
534,
88,
297,
355,
1817,
1304,
534,
1662,
1224,
297,
288,
2318,
288,
289,
12444,
5987,
14,
4547,
1296,
8,
355,
2974,
1524,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
20,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
21,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
22,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
23,
659,
355,
2156,
288,
5082,
398,
1890,
275,
289,
12444,
5987,
14,
38,
12444,
5987,
54,
17,
8,
362,
63,
6942,
29,
797,
9,
267,
1056,
275,
289,
12444,
5987,
14,
38,
12444,
5987,
4547,
1296,
2017,
8,
1224,
1304,
534,
1662,
1224,
358,
267,
2058,
275,
769,
63,
21219,
14,
22889,
2532,
1296,
8,
1258,
14,
2301,
12,
1056,
9,
398,
291,
423,
9699,
3244,
5826,
8,
2604,
12,
1695,
9,
339,
347,
511,
22889,
1944,
14941,
8,
277,
304,
267,
1890,
275,
289,
12444,
5987,
14,
38,
12444,
5987,
54,
17,
8,
362,
63,
6942,
29,
797,
9,
267,
1056,
275,
289,
12444,
5987,
14,
38,
12444,
5987,
4547,
1296,
2017,
8,
1224,
1304,
534,
1662,
1224,
358,
267,
2058,
275,
769,
63,
21219,
14,
22889,
2532,
1296,
8,
1258,
14,
2301,
12,
1056,
12,
2304,
29,
797,
9,
267,
291,
14,
629,
8,
16,
12,
822,
8,
513,
8,
2604,
1724,
339,
347,
511,
22889,
2532,
1296,
18192,
8,
277,
304,
267,
291,
14,
27740,
63,
1258,
14,
2301,
14,
1296,
14,
13495,
8,
288,
289,
12444,
5987,
14,
38,
12444,
5987,
4547,
1296,
2017,
8,
355,
1390,
6579,
29,
1960,
12,
355,
2034,
3264,
29,
403,
12,
355,
1817,
1304,
534,
1662,
1224,
297,
288,
2318,
288,
289,
12444,
5987,
14,
4547,
1296,
8,
355,
2974,
1524,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
16,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
17,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
18,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
19,
659,
355,
2156,
355,
2163,
3276,
3264,
534,
88,
297,
288,
5082,
267,
291,
14,
27740,
63,
1258,
14,
2301,
14,
1296,
14,
13495,
8,
288,
289,
12444,
5987,
14,
38,
12444,
5987,
4547,
1296,
2017,
8,
355,
1390,
6579,
29,
1960,
12,
355,
2034,
3264,
534,
88,
297,
355,
1817,
1304,
534,
1662,
1224,
297,
288,
2318,
288,
289,
12444,
5987,
14,
4547,
1296,
8,
355,
2974,
1524,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
20,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
21,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
22,
659,
490,
289,
12444,
5987,
14,
4547,
8,
354,
534,
67,
23,
659,
355,
2156,
288,
5082,
398,
1890,
275,
289,
12444,
5987,
14,
38,
12444,
5987,
54,
17,
8,
362,
63,
6942,
29,
797,
9,
267,
1056,
275,
289,
12444,
5987,
14,
38,
12444,
5987,
4547,
1296,
2017,
8,
1224,
1304,
534,
1662,
1224,
358,
267,
2058,
275,
769,
63,
21219,
14,
22889,
2532,
1296,
8,
1258,
14,
2301,
12,
1056,
12,
2304,
29,
22,
9,
398,
291,
423,
9699,
3244,
5826,
8,
2604,
12,
1227,
9,
339,
347,
511,
22889,
2532,
1296,
4699,
8,
277,
304,
267,
291,
14,
27740,
63,
1258,
14,
2301,
14,
1296,
14,
13495,
8,
288,
289,
12444,
5987,
14,
38,
12444,
5987,
4547,
1296,
2017,
8,
355,
1390,
6579,
29,
1960,
12,
355,
2034,
3264,
29,
403,
12,
355,
1817,
1304,
534,
1662,
1224,
297,
288,
2318,
288,
289,
12444,
5987,
14,
4547,
1296,
1012,
398,
1890,
275,
289,
12444,
5987,
14,
38,
12444,
5987,
54,
17,
8,
362,
63,
6942,
29,
797,
9,
267,
1056,
275,
289,
12444,
5987,
14,
38,
12444,
5987,
4547,
1296,
2017,
8,
1224,
1304,
534,
1662,
1224,
358,
267,
2058,
275,
769,
63,
21219,
14,
22889,
2532,
1296,
8,
1258,
14,
2301,
12,
1056,
12,
2304,
29,
22,
9,
398,
291,
423,
9699,
3244,
5826,
8,
2604,
12,
378,
9,
339,
347,
511,
22889,
2532,
1296,
3007,
22236,
8,
277,
304,
267,
291,
14,
27740,
63,
1258,
14,
2301,
14,
1296,
14,
13495,
8,
288,
289,
12444,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
OCForks/phantomjs
|
src/breakpad/src/third_party/protobuf/protobuf/examples/list_people.py
|
429
|
1135
|
#! /usr/bin/python
# See README.txt for information and build instructions.
import addressbook_pb2
import sys
# Iterates though all people in the AddressBook and prints info about them.
def ListPeople(address_book):
for person in address_book.person:
print "Person ID:", person.id
print " Name:", person.name
if person.HasField('email'):
print " E-mail address:", person.email
for phone_number in person.phone:
if phone_number.type == addressbook_pb2.Person.MOBILE:
print " Mobile phone #:",
elif phone_number.type == addressbook_pb2.Person.HOME:
print " Home phone #:",
elif phone_number.type == addressbook_pb2.Person.WORK:
print " Work phone #:",
print phone_number.number
# Main procedure: Reads the entire address book from a file and prints all
# the information inside.
if len(sys.argv) != 2:
print "Usage:", sys.argv[0], "ADDRESS_BOOK_FILE"
sys.exit(-1)
address_book = addressbook_pb2.AddressBook()
# Read the existing address book.
f = open(sys.argv[1], "rb")
address_book.ParseFromString(f.read())
f.close()
ListPeople(address_book)
|
bsd-3-clause
|
[
3168,
1182,
2647,
15,
1393,
15,
1548,
199,
199,
3,
1666,
27781,
14,
2424,
367,
2556,
436,
1900,
15794,
14,
199,
199,
646,
2287,
2706,
63,
3317,
18,
199,
646,
984,
199,
199,
3,
11953,
2335,
10617,
1006,
13135,
315,
314,
9906,
8696,
436,
14767,
2256,
3595,
3062,
14,
199,
318,
3820,
8070,
7939,
8,
1562,
63,
2706,
304,
523,
367,
4954,
315,
2287,
63,
2706,
14,
5484,
26,
272,
870,
298,
7344,
2870,
6783,
4954,
14,
344,
272,
870,
298,
221,
2812,
6783,
4954,
14,
354,
272,
340,
4954,
14,
19416,
360,
2123,
735,
489,
870,
298,
221,
662,
13,
1198,
2287,
6783,
4954,
14,
2123,
339,
367,
14617,
63,
1955,
315,
4954,
14,
9339,
26,
489,
340,
14617,
63,
1955,
14,
466,
508,
2287,
2706,
63,
3317,
18,
14,
7344,
14,
2679,
34,
8453,
26,
267,
870,
298,
221,
29724,
14617,
6079,
401,
489,
916,
14617,
63,
1955,
14,
466,
508,
2287,
2706,
63,
3317,
18,
14,
7344,
14,
9524,
26,
267,
870,
298,
221,
14621,
14617,
6079,
401,
489,
916,
14617,
63,
1955,
14,
466,
508,
2287,
2706,
63,
3317,
18,
14,
7344,
14,
8406,
26,
267,
870,
298,
221,
9361,
14617,
6079,
401,
489,
870,
14617,
63,
1955,
14,
1955,
199,
199,
3,
11298,
17782,
26,
221,
26129,
314,
8039,
2287,
6719,
687,
282,
570,
436,
14767,
1006,
199,
3,
257,
314,
2556,
6272,
14,
199,
692,
822,
8,
1274,
14,
3020,
9,
1137,
499,
26,
523,
870,
298,
7692,
6783,
984,
14,
3020,
59,
16,
467,
298,
12368,
63,
21155,
63,
3817,
2,
523,
984,
14,
2224,
2801,
17,
9,
199,
199,
1562,
63,
2706,
275,
2287,
2706,
63,
3317,
18,
14,
1476,
8696,
342,
199,
199,
3,
5574,
314,
3411,
2287,
6719,
14,
199,
70,
275,
1551,
8,
1274,
14,
3020,
59,
17,
467,
298,
4848,
531,
199,
1562,
63,
2706,
14,
28685,
8,
70,
14,
739,
1012,
199,
70,
14,
1600,
342,
199,
199,
1296,
8070,
7939,
8,
1562,
63,
2706,
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
] |
[
1182,
2647,
15,
1393,
15,
1548,
199,
199,
3,
1666,
27781,
14,
2424,
367,
2556,
436,
1900,
15794,
14,
199,
199,
646,
2287,
2706,
63,
3317,
18,
199,
646,
984,
199,
199,
3,
11953,
2335,
10617,
1006,
13135,
315,
314,
9906,
8696,
436,
14767,
2256,
3595,
3062,
14,
199,
318,
3820,
8070,
7939,
8,
1562,
63,
2706,
304,
523,
367,
4954,
315,
2287,
63,
2706,
14,
5484,
26,
272,
870,
298,
7344,
2870,
6783,
4954,
14,
344,
272,
870,
298,
221,
2812,
6783,
4954,
14,
354,
272,
340,
4954,
14,
19416,
360,
2123,
735,
489,
870,
298,
221,
662,
13,
1198,
2287,
6783,
4954,
14,
2123,
339,
367,
14617,
63,
1955,
315,
4954,
14,
9339,
26,
489,
340,
14617,
63,
1955,
14,
466,
508,
2287,
2706,
63,
3317,
18,
14,
7344,
14,
2679,
34,
8453,
26,
267,
870,
298,
221,
29724,
14617,
6079,
401,
489,
916,
14617,
63,
1955,
14,
466,
508,
2287,
2706,
63,
3317,
18,
14,
7344,
14,
9524,
26,
267,
870,
298,
221,
14621,
14617,
6079,
401,
489,
916,
14617,
63,
1955,
14,
466,
508,
2287,
2706,
63,
3317,
18,
14,
7344,
14,
8406,
26,
267,
870,
298,
221,
9361,
14617,
6079,
401,
489,
870,
14617,
63,
1955,
14,
1955,
199,
199,
3,
11298,
17782,
26,
221,
26129,
314,
8039,
2287,
6719,
687,
282,
570,
436,
14767,
1006,
199,
3,
257,
314,
2556,
6272,
14,
199,
692,
822,
8,
1274,
14,
3020,
9,
1137,
499,
26,
523,
870,
298,
7692,
6783,
984,
14,
3020,
59,
16,
467,
298,
12368,
63,
21155,
63,
3817,
2,
523,
984,
14,
2224,
2801,
17,
9,
199,
199,
1562,
63,
2706,
275,
2287,
2706,
63,
3317,
18,
14,
1476,
8696,
342,
199,
199,
3,
5574,
314,
3411,
2287,
6719,
14,
199,
70,
275,
1551,
8,
1274,
14,
3020,
59,
17,
467,
298,
4848,
531,
199,
1562,
63,
2706,
14,
28685,
8,
70,
14,
739,
1012,
199,
70,
14,
1600,
342,
199,
199,
1296,
8070,
7939,
8,
1562,
63,
2706,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ibmsoe/ImpalaPPC
|
testdata/bin/random_avro_schema.py
|
2
|
5828
|
#!/usr/bin/env impala-python
# Copyright (c) 2015 Cloudera, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from random import choice, randint, random, shuffle
from os.path import join as join_path
from optparse import OptionParser
import json
MAX_NUM_STRUCT_FIELDS = 8
NULL_CHANCE = 0.5
SCALAR_TYPES = ['boolean', 'int', 'long', 'float', 'double', 'string']
class Node(object):
def __init__(self, num_fields, node_type):
self.node_type = node_type # one of struct, map, array
self.num_fields = num_fields
self.fields = []
class SchemaTreeGenerator(object):
def __init__(self, target_num_scalars=10, target_depth=3):
self._target_num_scalars = target_num_scalars
self._target_depth = target_depth
self._nodes = []
self._num_scalars_created = 0
self.root = None
def _create_random_node(self):
node_type = choice(('map', 'array', 'struct'))
if node_type in ('map', 'array'):
result_node = Node(1, node_type)
else:
num_fields = randint(1, MAX_NUM_STRUCT_FIELDS)
self._num_scalars_created += num_fields - 1
result_node = Node(num_fields, 'struct')
self._nodes.append(result_node)
return result_node
def _get_random_existing_node(self):
nodes = []
for node in self._nodes:
for _ in range(node.num_fields - len(node.fields)):
nodes.append(node)
return choice(nodes)
def _generate_rest(self):
while self._num_scalars_created < self._target_num_scalars:
node = self._get_random_existing_node()
node.fields.append(self._create_random_node())
self._finalize()
def _generate_trunk(self):
cur = self.root
for i in range(self._target_depth):
new_node = self._create_random_node()
self._nodes.append(new_node)
cur.fields.append(new_node)
cur = new_node
def _finalize(self):
for node in self._nodes:
for _ in range(node.num_fields - len(node.fields)):
node.fields.append(choice(SCALAR_TYPES))
shuffle(node.fields)
def create_tree(self):
self.root = Node(randint(1, MAX_NUM_STRUCT_FIELDS), 'struct')
self._nodes = [self.root]
self._num_scalars_created = self.root.num_fields
self._generate_trunk()
self._generate_rest()
return self.root
class AvroGenerator(object):
def __init__(self, schema_tree_generator):
self.cur_id = 0
self._schema_tree_generator = schema_tree_generator
def _next_id(self):
self.cur_id += 1
return str(self.cur_id)
def clear_state(self):
self.cur_id = 0
def create(self, table_name):
tree_root = self._schema_tree_generator.create_tree()
result = {}
result['type'] = 'record'
result['namespace'] = 'com.cloudera.impala'
result['name'] = table_name
result['fields'] = self._convert_struct_fields(tree_root.fields)
return result
def _convert_struct_fields(self, fields):
return [self._convert_struct_field(field) for field in fields]
def _convert_struct_field(self, struct_field_node):
result = {}
result['type'] = self._convert_node(struct_field_node)
result['name'] = 'field_' + self._next_id()
return result
def _convert_node(self, node):
if isinstance(node, str):
result = node
elif node.node_type == 'array':
result = self._convert_array(node)
elif node.node_type == 'map':
result = self._convert_map(node)
elif node.node_type == 'struct':
result = self._convert_struct(node)
else:
assert False, 'Unknown type: ' + node.node_types
if random() < NULL_CHANCE:
# Make it nullable
return ['null', result]
else:
return result
def _convert_array(self, array_node):
result = {}
result['type'] = 'array'
result['items'] = self._convert_node(array_node.fields[0])
return result
def _convert_map(self, map_node):
result = {}
result['type'] = 'map'
result['values'] = self._convert_node(map_node.fields[0])
return result
def _convert_struct(self, struct_node):
result = {}
result['type'] = 'record'
result['name'] = 'struct_' + self._next_id()
result['fields'] = self._convert_struct_fields(struct_node.fields)
return result
if __name__ == '__main__':
parser = OptionParser()
parser.add_option('--target_dir', default='/tmp',
help='Directory where the avro schemas will be saved.')
parser.add_option('--num_tables', default='4', type='int',
help='Number of schemas to generate.')
parser.add_option('--num_scalars', default='10', type='int',
help='Number of schemas to generate.')
parser.add_option('--nesting_depth', default='3', type='int',
help='Number of schemas to generate.')
parser.add_option('--base_table_name', default='table_',
help='Base table name.')
options, args = parser.parse_args()
schema_generator = SchemaTreeGenerator(target_num_scalars=options.num_scalars,
target_depth=options.nesting_depth)
writer = AvroGenerator(schema_generator)
for table_num in range(options.num_tables):
writer.clear_state()
table_name = options.base_table_name + str(table_num)
json_result = writer.create(table_name)
file_path = join_path(options.target_dir, table_name + '.avsc')
with open(file_path, 'w') as f:
json.dump(json_result, f, indent=2, sort_keys=True)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
1742,
14774,
13,
1548,
199,
3,
1898,
334,
67,
9,
6900,
5980,
3786,
345,
12,
3277,
14,
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,
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,
2196,
492,
7141,
12,
29722,
12,
2196,
12,
13031,
199,
504,
747,
14,
515,
492,
4263,
465,
4263,
63,
515,
199,
504,
8691,
492,
13491,
199,
199,
646,
2022,
199,
199,
4283,
63,
7125,
63,
8893,
63,
12767,
275,
1695,
199,
8084,
63,
1244,
7140,
275,
378,
14,
21,
199,
17209,
689,
63,
7893,
275,
788,
4871,
297,
283,
442,
297,
283,
2809,
297,
283,
1609,
297,
283,
3157,
297,
283,
875,
418,
199,
199,
533,
5013,
8,
785,
304,
819,
347,
636,
826,
721,
277,
12,
1967,
63,
955,
12,
1031,
63,
466,
304,
272,
291,
14,
932,
63,
466,
275,
1031,
63,
466,
327,
1373,
402,
2702,
12,
2341,
12,
1625,
272,
291,
14,
1507,
63,
955,
275,
1967,
63,
955,
272,
291,
14,
955,
275,
942,
421,
199,
533,
13268,
3987,
7599,
8,
785,
304,
819,
347,
636,
826,
721,
277,
12,
1347,
63,
1507,
63,
4732,
4291,
29,
709,
12,
1347,
63,
4631,
29,
19,
304,
272,
291,
423,
1375,
63,
1507,
63,
4732,
4291,
275,
1347,
63,
1507,
63,
4732,
4291,
272,
291,
423,
1375,
63,
4631,
275,
1347,
63,
4631,
272,
291,
423,
2415,
275,
942,
272,
291,
423,
1507,
63,
4732,
4291,
63,
3966,
275,
378,
272,
291,
14,
1231,
275,
488,
819,
347,
485,
981,
63,
2355,
63,
932,
8,
277,
304,
272,
1031,
63,
466,
275,
7141,
4725,
1130,
297,
283,
1144,
297,
283,
1820,
1333,
272,
340,
1031,
63,
466,
315,
661,
1130,
297,
283,
1144,
735,
489,
754,
63,
932,
275,
5013,
8,
17,
12,
1031,
63,
466,
9,
272,
587,
26,
489,
1967,
63,
955,
275,
29722,
8,
17,
12,
9141,
63,
7125,
63,
8893,
63,
12767,
9,
489,
291,
423,
1507,
63,
4732,
4291,
63,
3966,
847,
1967,
63,
955,
446,
413,
489,
754,
63,
932,
275,
5013,
8,
1507,
63,
955,
12,
283,
1820,
358,
272,
291,
423,
2415,
14,
740,
8,
1099,
63,
932,
9,
272,
372,
754,
63,
932,
819,
347,
485,
362,
63,
2355,
63,
5952,
63,
932,
8,
277,
304,
272,
3380,
275,
942,
272,
367,
1031,
315,
291,
423,
2415,
26,
489,
367,
485,
315,
1425,
8,
932,
14,
1507,
63,
955,
446,
822,
8,
932,
14,
955,
2298,
267,
3380,
14,
740,
8,
932,
9,
272,
372,
7141,
8,
2415,
9,
819,
347,
485,
4208,
63,
3911,
8,
277,
304,
272,
1830,
291,
423,
1507,
63,
4732,
4291,
63,
3966,
665,
291,
423,
1375,
63,
1507,
63,
4732,
4291,
26,
489,
1031,
275,
291,
423,
362,
63,
2355,
63,
5952,
63,
932,
342,
489,
1031,
14,
955,
14,
740,
8,
277,
423,
981,
63,
2355,
63,
932,
1012,
272,
291,
423,
14450,
342,
819,
347,
485,
4208,
63,
13409,
8,
277,
304,
272,
1094,
275,
291,
14,
1231,
272,
367,
284,
315,
1425,
8,
277,
423,
1375,
63,
4631,
304,
489,
892,
63,
932,
275,
291,
423,
981,
63,
2355,
63,
932,
342,
489,
291,
423,
2415,
14,
740,
8,
1222,
63,
932,
9,
489,
1094,
14,
955,
14,
740,
8,
1222,
63,
932,
9,
489,
1094,
275,
892,
63,
932,
819,
347,
485,
14450,
8,
277,
304,
272,
367,
1031,
315,
291,
423,
2415,
26,
489,
367,
485,
315,
1425,
8,
932,
14,
1507,
63,
955,
446,
822,
8,
932,
14,
955,
2298,
267,
1031,
14,
955,
14,
740,
8,
5095,
8,
17209,
689,
63,
7893,
430,
489,
13031,
8,
932,
14,
955,
9,
819,
347,
1218,
63,
2350,
8,
277,
304,
272,
291,
14,
1231,
275,
5013,
8,
8393,
8,
17,
12,
9141,
63,
7125,
63,
8893,
63,
12767,
395,
283,
1820,
358,
272,
291,
423,
2415,
275,
359,
277,
14,
1231,
61,
272,
291,
423,
1507,
63,
4732,
4291,
63,
3966,
275,
291,
14,
1231,
14,
1507,
63,
955,
272,
291,
423,
4208,
63,
13409,
342,
272,
291,
423,
4208,
63,
3911,
342,
272,
372,
291,
14,
1231,
421,
199,
533,
16599,
293,
7599,
8,
785,
304,
819,
347,
636,
826,
721,
277,
12,
4177,
63,
2350,
63,
4679,
304,
272,
291,
14,
895,
63,
344,
275,
378,
272,
291,
423,
3629,
63,
2350,
63,
4679,
275,
4177,
63,
2350,
63,
4679,
819,
347,
485,
2184,
63,
344,
8,
277,
304,
272,
291,
14,
895,
63,
344,
847,
413,
272,
372,
620,
8,
277,
14,
895,
63,
344,
9,
819,
347,
5436,
63,
929,
8,
277,
304,
272,
291,
14,
895,
63,
344,
275,
378,
819,
347,
1218,
8,
277,
12,
1817,
63,
354,
304,
272,
3123,
63,
1231,
275,
291,
423,
3629,
63,
2350,
63,
4679,
14,
981,
63,
2350,
342,
272,
754,
275,
1052,
272,
754,
459,
466,
418,
275,
283,
3059,
7,
272,
754,
459,
3251,
418,
275,
283,
957,
14,
1251,
3786,
345,
14,
3236,
14774,
7,
272,
754,
459,
354,
418,
275,
1817,
63,
354,
272,
754,
459,
955,
418,
275,
291,
423,
3916,
63,
1820,
63,
955,
8,
2350,
63,
1231,
14,
955,
9,
272,
372,
754,
819,
347,
485,
3916,
63,
1820,
63,
955,
8,
277,
12,
1504,
304,
272,
372,
359,
277,
423,
3916,
63,
1820,
63,
698,
8,
698,
9,
367,
901,
315,
1504,
61,
819,
347,
485,
3916,
63,
1820,
63,
698,
8,
277,
12,
2702,
63,
698,
63,
932,
304
] |
[
2647,
15,
1393,
15,
1813,
1742,
14774,
13,
1548,
199,
3,
1898,
334,
67,
9,
6900,
5980,
3786,
345,
12,
3277,
14,
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,
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,
2196,
492,
7141,
12,
29722,
12,
2196,
12,
13031,
199,
504,
747,
14,
515,
492,
4263,
465,
4263,
63,
515,
199,
504,
8691,
492,
13491,
199,
199,
646,
2022,
199,
199,
4283,
63,
7125,
63,
8893,
63,
12767,
275,
1695,
199,
8084,
63,
1244,
7140,
275,
378,
14,
21,
199,
17209,
689,
63,
7893,
275,
788,
4871,
297,
283,
442,
297,
283,
2809,
297,
283,
1609,
297,
283,
3157,
297,
283,
875,
418,
199,
199,
533,
5013,
8,
785,
304,
819,
347,
636,
826,
721,
277,
12,
1967,
63,
955,
12,
1031,
63,
466,
304,
272,
291,
14,
932,
63,
466,
275,
1031,
63,
466,
327,
1373,
402,
2702,
12,
2341,
12,
1625,
272,
291,
14,
1507,
63,
955,
275,
1967,
63,
955,
272,
291,
14,
955,
275,
942,
421,
199,
533,
13268,
3987,
7599,
8,
785,
304,
819,
347,
636,
826,
721,
277,
12,
1347,
63,
1507,
63,
4732,
4291,
29,
709,
12,
1347,
63,
4631,
29,
19,
304,
272,
291,
423,
1375,
63,
1507,
63,
4732,
4291,
275,
1347,
63,
1507,
63,
4732,
4291,
272,
291,
423,
1375,
63,
4631,
275,
1347,
63,
4631,
272,
291,
423,
2415,
275,
942,
272,
291,
423,
1507,
63,
4732,
4291,
63,
3966,
275,
378,
272,
291,
14,
1231,
275,
488,
819,
347,
485,
981,
63,
2355,
63,
932,
8,
277,
304,
272,
1031,
63,
466,
275,
7141,
4725,
1130,
297,
283,
1144,
297,
283,
1820,
1333,
272,
340,
1031,
63,
466,
315,
661,
1130,
297,
283,
1144,
735,
489,
754,
63,
932,
275,
5013,
8,
17,
12,
1031,
63,
466,
9,
272,
587,
26,
489,
1967,
63,
955,
275,
29722,
8,
17,
12,
9141,
63,
7125,
63,
8893,
63,
12767,
9,
489,
291,
423,
1507,
63,
4732,
4291,
63,
3966,
847,
1967,
63,
955,
446,
413,
489,
754,
63,
932,
275,
5013,
8,
1507,
63,
955,
12,
283,
1820,
358,
272,
291,
423,
2415,
14,
740,
8,
1099,
63,
932,
9,
272,
372,
754,
63,
932,
819,
347,
485,
362,
63,
2355,
63,
5952,
63,
932,
8,
277,
304,
272,
3380,
275,
942,
272,
367,
1031,
315,
291,
423,
2415,
26,
489,
367,
485,
315,
1425,
8,
932,
14,
1507,
63,
955,
446,
822,
8,
932,
14,
955,
2298,
267,
3380,
14,
740,
8,
932,
9,
272,
372,
7141,
8,
2415,
9,
819,
347,
485,
4208,
63,
3911,
8,
277,
304,
272,
1830,
291,
423,
1507,
63,
4732,
4291,
63,
3966,
665,
291,
423,
1375,
63,
1507,
63,
4732,
4291,
26,
489,
1031,
275,
291,
423,
362,
63,
2355,
63,
5952,
63,
932,
342,
489,
1031,
14,
955,
14,
740,
8,
277,
423,
981,
63,
2355,
63,
932,
1012,
272,
291,
423,
14450,
342,
819,
347,
485,
4208,
63,
13409,
8,
277,
304,
272,
1094,
275,
291,
14,
1231,
272,
367,
284,
315,
1425,
8,
277,
423,
1375,
63,
4631,
304,
489,
892,
63,
932,
275,
291,
423,
981,
63,
2355,
63,
932,
342,
489,
291,
423,
2415,
14,
740,
8,
1222,
63,
932,
9,
489,
1094,
14,
955,
14,
740,
8,
1222,
63,
932,
9,
489,
1094,
275,
892,
63,
932,
819,
347,
485,
14450,
8,
277,
304,
272,
367,
1031,
315,
291,
423,
2415,
26,
489,
367,
485,
315,
1425,
8,
932,
14,
1507,
63,
955,
446,
822,
8,
932,
14,
955,
2298,
267,
1031,
14,
955,
14,
740,
8,
5095,
8,
17209,
689,
63,
7893,
430,
489,
13031,
8,
932,
14,
955,
9,
819,
347,
1218,
63,
2350,
8,
277,
304,
272,
291,
14,
1231,
275,
5013,
8,
8393,
8,
17,
12,
9141,
63,
7125,
63,
8893,
63,
12767,
395,
283,
1820,
358,
272,
291,
423,
2415,
275,
359,
277,
14,
1231,
61,
272,
291,
423,
1507,
63,
4732,
4291,
63,
3966,
275,
291,
14,
1231,
14,
1507,
63,
955,
272,
291,
423,
4208,
63,
13409,
342,
272,
291,
423,
4208,
63,
3911,
342,
272,
372,
291,
14,
1231,
421,
199,
533,
16599,
293,
7599,
8,
785,
304,
819,
347,
636,
826,
721,
277,
12,
4177,
63,
2350,
63,
4679,
304,
272,
291,
14,
895,
63,
344,
275,
378,
272,
291,
423,
3629,
63,
2350,
63,
4679,
275,
4177,
63,
2350,
63,
4679,
819,
347,
485,
2184,
63,
344,
8,
277,
304,
272,
291,
14,
895,
63,
344,
847,
413,
272,
372,
620,
8,
277,
14,
895,
63,
344,
9,
819,
347,
5436,
63,
929,
8,
277,
304,
272,
291,
14,
895,
63,
344,
275,
378,
819,
347,
1218,
8,
277,
12,
1817,
63,
354,
304,
272,
3123,
63,
1231,
275,
291,
423,
3629,
63,
2350,
63,
4679,
14,
981,
63,
2350,
342,
272,
754,
275,
1052,
272,
754,
459,
466,
418,
275,
283,
3059,
7,
272,
754,
459,
3251,
418,
275,
283,
957,
14,
1251,
3786,
345,
14,
3236,
14774,
7,
272,
754,
459,
354,
418,
275,
1817,
63,
354,
272,
754,
459,
955,
418,
275,
291,
423,
3916,
63,
1820,
63,
955,
8,
2350,
63,
1231,
14,
955,
9,
272,
372,
754,
819,
347,
485,
3916,
63,
1820,
63,
955,
8,
277,
12,
1504,
304,
272,
372,
359,
277,
423,
3916,
63,
1820,
63,
698,
8,
698,
9,
367,
901,
315,
1504,
61,
819,
347,
485,
3916,
63,
1820,
63,
698,
8,
277,
12,
2702,
63,
698,
63,
932,
304,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jaysonsantos/servo
|
tests/wpt/web-platform-tests/tools/pytest/_pytest/_code/_py2traceback.py
|
192
|
2887
|
# copied from python-2.7.3's traceback.py
# CHANGES:
# - some_str is replaced, trying to create unicode strings
#
import types
def format_exception_only(etype, value):
"""Format the exception part of a traceback.
The arguments are the exception type and value such as given by
sys.last_type and sys.last_value. The return value is a list of
strings, each ending in a newline.
Normally, the list contains a single string; however, for
SyntaxError exceptions, it contains several lines that (when
printed) display detailed information about where the syntax
error occurred.
The message indicating which exception occurred is always the last
string in the list.
"""
# An instance should not have a meaningful value parameter, but
# sometimes does, particularly for string exceptions, such as
# >>> raise string1, string2 # deprecated
#
# Clear these out first because issubtype(string1, SyntaxError)
# would throw another exception and mask the original problem.
if (isinstance(etype, BaseException) or
isinstance(etype, types.InstanceType) or
etype is None or type(etype) is str):
return [_format_final_exc_line(etype, value)]
stype = etype.__name__
if not issubclass(etype, SyntaxError):
return [_format_final_exc_line(stype, value)]
# It was a syntax error; show exactly where the problem was found.
lines = []
try:
msg, (filename, lineno, offset, badline) = value.args
except Exception:
pass
else:
filename = filename or "<string>"
lines.append(' File "%s", line %d\n' % (filename, lineno))
if badline is not None:
if isinstance(badline, bytes): # python 2 only
badline = badline.decode('utf-8', 'replace')
lines.append(u' %s\n' % badline.strip())
if offset is not None:
caretspace = badline.rstrip('\n')[:offset].lstrip()
# non-space whitespace (likes tabs) must be kept for alignment
caretspace = ((c.isspace() and c or ' ') for c in caretspace)
# only three spaces to account for offset1 == pos 0
lines.append(' %s^\n' % ''.join(caretspace))
value = msg
lines.append(_format_final_exc_line(stype, value))
return lines
def _format_final_exc_line(etype, value):
"""Return a list of a single line -- normal case for format_exception_only"""
valuestr = _some_str(value)
if value is None or not valuestr:
line = "%s\n" % etype
else:
line = "%s: %s\n" % (etype, valuestr)
return line
def _some_str(value):
try:
return unicode(value)
except Exception:
try:
return str(value)
except Exception:
pass
return '<unprintable %s object>' % type(value).__name__
|
mpl-2.0
|
[
3,
8876,
687,
2366,
13,
18,
14,
23,
14,
19,
1159,
5190,
14,
647,
199,
3,
6624,
3986,
654,
26,
199,
3,
446,
2005,
63,
495,
365,
8717,
12,
9936,
370,
1218,
2649,
3326,
199,
3,
199,
646,
2943,
199,
199,
318,
1475,
63,
1971,
63,
2118,
8,
29232,
12,
574,
304,
272,
408,
3484,
314,
1919,
1777,
402,
282,
5190,
14,
339,
710,
2368,
787,
314,
1919,
730,
436,
574,
4066,
465,
1627,
701,
272,
984,
14,
2019,
63,
466,
436,
984,
14,
2019,
63,
585,
14,
710,
372,
574,
365,
282,
769,
402,
272,
3326,
12,
1924,
13401,
315,
282,
8057,
14,
339,
24573,
12,
314,
769,
3509,
282,
2849,
1059,
27,
13432,
12,
367,
272,
12053,
4967,
12,
652,
3509,
9978,
2385,
626,
334,
6526,
272,
12487,
9,
2929,
16212,
2556,
3595,
2382,
314,
6302,
272,
1125,
8920,
14,
339,
710,
1245,
9297,
1314,
1919,
8920,
365,
3544,
314,
2061,
272,
1059,
315,
314,
769,
14,
339,
408,
339,
327,
1626,
1256,
1077,
440,
1172,
282,
26562,
574,
2725,
12,
1325,
272,
327,
15026,
1630,
12,
6770,
590,
367,
1059,
4967,
12,
4066,
465,
272,
327,
1306,
746,
1059,
17,
12,
1059,
18,
221,
327,
5906,
272,
327,
272,
327,
14836,
3520,
734,
1642,
2952,
365,
10512,
8,
875,
17,
12,
12053,
9,
272,
327,
3955,
7978,
4573,
1919,
436,
3656,
314,
3379,
5160,
14,
272,
340,
334,
6074,
8,
29232,
12,
25416,
9,
503,
267,
1228,
8,
29232,
12,
2943,
14,
3244,
804,
9,
503,
267,
30527,
365,
488,
503,
730,
8,
29232,
9,
365,
620,
304,
267,
372,
15500,
908,
63,
5094,
63,
2804,
63,
604,
8,
29232,
12,
574,
1874,
339,
410,
514,
275,
30527,
855,
354,
363,
339,
340,
440,
11602,
8,
29232,
12,
12053,
304,
267,
372,
15500,
908,
63,
5094,
63,
2804,
63,
604,
8,
20615,
12,
574,
1874,
339,
327,
2779,
1990,
282,
6302,
1125,
27,
2498,
8840,
2382,
314,
5160,
1990,
1911,
14,
272,
2385,
275,
942,
272,
862,
26,
267,
1499,
12,
334,
1501,
12,
5874,
12,
3268,
12,
4875,
604,
9,
275,
574,
14,
589,
272,
871,
2186,
26,
267,
986,
272,
587,
26,
267,
1788,
275,
1788,
503,
3886,
875,
4335,
267,
2385,
14,
740,
360,
221,
3814,
2071,
83,
401,
1004,
450,
68,
60,
78,
7,
450,
334,
1501,
12,
5874,
430,
267,
340,
4875,
604,
365,
440,
488,
26,
288,
340,
1228,
8,
4087,
604,
12,
2783,
304,
221,
327,
2366,
499,
1454,
355,
4875,
604,
275,
4875,
604,
14,
2708,
360,
1624,
13,
24,
297,
283,
1814,
358,
288,
2385,
14,
740,
8,
85,
7,
259,
450,
83,
60,
78,
7,
450,
4875,
604,
14,
1913,
1012,
288,
340,
3268,
365,
440,
488,
26,
355,
10296,
1086,
1142,
275,
4875,
604,
14,
6735,
2258,
78,
358,
1491,
2743,
1055,
10124,
342,
355,
327,
2222,
13,
2638,
8139,
334,
29572,
12187,
9,
1471,
506,
16204,
367,
13177,
355,
10296,
1086,
1142,
275,
3666,
67,
14,
23360,
342,
436,
286,
503,
283,
5320,
367,
286,
315,
10296,
1086,
1142,
9,
355,
327,
1454,
7795,
7883,
370,
2933,
367,
3268,
17,
508,
2086,
378,
355,
2385,
14,
740,
360,
257,
450,
83,
12773,
78,
7,
450,
6522,
904,
8,
28654,
1086,
1142,
430,
267,
574,
275,
1499,
339,
2385,
14,
740,
1547,
908,
63,
5094,
63,
2804,
63,
604,
8,
20615,
12,
574,
430,
272,
372,
2385,
199,
199,
318,
485,
908,
63,
5094,
63,
2804,
63,
604,
8,
29232,
12,
574,
304,
272,
408,
1767,
282,
769,
402,
282,
2849,
1004,
1553,
3293,
1930,
367,
1475,
63,
1971,
63,
2118,
624,
272,
574,
495,
275,
485,
3972,
63,
495,
8,
585,
9,
272,
340,
574,
365,
488,
503,
440,
574,
495,
26,
267,
1004,
275,
2071,
83,
60,
78,
2,
450,
30527,
272,
587,
26,
267,
1004,
275,
2071,
83,
26,
450,
83,
60,
78,
2,
450,
334,
29232,
12,
574,
495,
9,
272,
372,
1004,
199,
199,
318,
485,
3972,
63,
495,
8,
585,
304,
272,
862,
26,
267,
372,
2649,
8,
585,
9,
272,
871,
2186,
26,
267,
862,
26,
288,
372,
620,
8,
585,
9,
267,
871,
2186,
26,
288,
986,
272,
372,
2650,
324,
20557,
450,
83,
909,
3524,
450,
730,
8,
585,
2843,
354,
363,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
8876,
687,
2366,
13,
18,
14,
23,
14,
19,
1159,
5190,
14,
647,
199,
3,
6624,
3986,
654,
26,
199,
3,
446,
2005,
63,
495,
365,
8717,
12,
9936,
370,
1218,
2649,
3326,
199,
3,
199,
646,
2943,
199,
199,
318,
1475,
63,
1971,
63,
2118,
8,
29232,
12,
574,
304,
272,
408,
3484,
314,
1919,
1777,
402,
282,
5190,
14,
339,
710,
2368,
787,
314,
1919,
730,
436,
574,
4066,
465,
1627,
701,
272,
984,
14,
2019,
63,
466,
436,
984,
14,
2019,
63,
585,
14,
710,
372,
574,
365,
282,
769,
402,
272,
3326,
12,
1924,
13401,
315,
282,
8057,
14,
339,
24573,
12,
314,
769,
3509,
282,
2849,
1059,
27,
13432,
12,
367,
272,
12053,
4967,
12,
652,
3509,
9978,
2385,
626,
334,
6526,
272,
12487,
9,
2929,
16212,
2556,
3595,
2382,
314,
6302,
272,
1125,
8920,
14,
339,
710,
1245,
9297,
1314,
1919,
8920,
365,
3544,
314,
2061,
272,
1059,
315,
314,
769,
14,
339,
408,
339,
327,
1626,
1256,
1077,
440,
1172,
282,
26562,
574,
2725,
12,
1325,
272,
327,
15026,
1630,
12,
6770,
590,
367,
1059,
4967,
12,
4066,
465,
272,
327,
1306,
746,
1059,
17,
12,
1059,
18,
221,
327,
5906,
272,
327,
272,
327,
14836,
3520,
734,
1642,
2952,
365,
10512,
8,
875,
17,
12,
12053,
9,
272,
327,
3955,
7978,
4573,
1919,
436,
3656,
314,
3379,
5160,
14,
272,
340,
334,
6074,
8,
29232,
12,
25416,
9,
503,
267,
1228,
8,
29232,
12,
2943,
14,
3244,
804,
9,
503,
267,
30527,
365,
488,
503,
730,
8,
29232,
9,
365,
620,
304,
267,
372,
15500,
908,
63,
5094,
63,
2804,
63,
604,
8,
29232,
12,
574,
1874,
339,
410,
514,
275,
30527,
855,
354,
363,
339,
340,
440,
11602,
8,
29232,
12,
12053,
304,
267,
372,
15500,
908,
63,
5094,
63,
2804,
63,
604,
8,
20615,
12,
574,
1874,
339,
327,
2779,
1990,
282,
6302,
1125,
27,
2498,
8840,
2382,
314,
5160,
1990,
1911,
14,
272,
2385,
275,
942,
272,
862,
26,
267,
1499,
12,
334,
1501,
12,
5874,
12,
3268,
12,
4875,
604,
9,
275,
574,
14,
589,
272,
871,
2186,
26,
267,
986,
272,
587,
26,
267,
1788,
275,
1788,
503,
3886,
875,
4335,
267,
2385,
14,
740,
360,
221,
3814,
2071,
83,
401,
1004,
450,
68,
60,
78,
7,
450,
334,
1501,
12,
5874,
430,
267,
340,
4875,
604,
365,
440,
488,
26,
288,
340,
1228,
8,
4087,
604,
12,
2783,
304,
221,
327,
2366,
499,
1454,
355,
4875,
604,
275,
4875,
604,
14,
2708,
360,
1624,
13,
24,
297,
283,
1814,
358,
288,
2385,
14,
740,
8,
85,
7,
259,
450,
83,
60,
78,
7,
450,
4875,
604,
14,
1913,
1012,
288,
340,
3268,
365,
440,
488,
26,
355,
10296,
1086,
1142,
275,
4875,
604,
14,
6735,
2258,
78,
358,
1491,
2743,
1055,
10124,
342,
355,
327,
2222,
13,
2638,
8139,
334,
29572,
12187,
9,
1471,
506,
16204,
367,
13177,
355,
10296,
1086,
1142,
275,
3666,
67,
14,
23360,
342,
436,
286,
503,
283,
5320,
367,
286,
315,
10296,
1086,
1142,
9,
355,
327,
1454,
7795,
7883,
370,
2933,
367,
3268,
17,
508,
2086,
378,
355,
2385,
14,
740,
360,
257,
450,
83,
12773,
78,
7,
450,
6522,
904,
8,
28654,
1086,
1142,
430,
267,
574,
275,
1499,
339,
2385,
14,
740,
1547,
908,
63,
5094,
63,
2804,
63,
604,
8,
20615,
12,
574,
430,
272,
372,
2385,
199,
199,
318,
485,
908,
63,
5094,
63,
2804,
63,
604,
8,
29232,
12,
574,
304,
272,
408,
1767,
282,
769,
402,
282,
2849,
1004,
1553,
3293,
1930,
367,
1475,
63,
1971,
63,
2118,
624,
272,
574,
495,
275,
485,
3972,
63,
495,
8,
585,
9,
272,
340,
574,
365,
488,
503,
440,
574,
495,
26,
267,
1004,
275,
2071,
83,
60,
78,
2,
450,
30527,
272,
587,
26,
267,
1004,
275,
2071,
83,
26,
450,
83,
60,
78,
2,
450,
334,
29232,
12,
574,
495,
9,
272,
372,
1004,
199,
199,
318,
485,
3972,
63,
495,
8,
585,
304,
272,
862,
26,
267,
372,
2649,
8,
585,
9,
272,
871,
2186,
26,
267,
862,
26,
288,
372,
620,
8,
585,
9,
267,
871,
2186,
26,
288,
986,
272,
372,
2650,
324,
20557,
450,
83,
909,
3524,
450,
730,
8,
585,
2843,
354,
363,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
godfather1103/WeiboRobot
|
python27/1.0/lib/test/test_multibytecodec_support.py
|
18
|
14605
|
# test_multibytecodec_support.py
# Common Unittest Routines for CJK codecs
#
import codecs
import os
import re
import sys
import unittest
from httplib import HTTPException
from test import test_support
from StringIO import StringIO
class TestBase:
encoding = '' # codec name
codec = None # codec tuple (with 4 elements)
tstring = '' # string to test StreamReader
codectests = None # must set. codec test tuple
roundtriptest = 1 # set if roundtrip is possible with unicode
has_iso10646 = 0 # set if this encoding contains whole iso10646 map
xmlcharnametest = None # string to test xmlcharrefreplace
unmappedunicode = u'\udeee' # a unicode code point that is not mapped.
def setUp(self):
if self.codec is None:
self.codec = codecs.lookup(self.encoding)
self.encode = self.codec.encode
self.decode = self.codec.decode
self.reader = self.codec.streamreader
self.writer = self.codec.streamwriter
self.incrementalencoder = self.codec.incrementalencoder
self.incrementaldecoder = self.codec.incrementaldecoder
def test_chunkcoding(self):
for native, utf8 in zip(*[StringIO(f).readlines()
for f in self.tstring]):
u = self.decode(native)[0]
self.assertEqual(u, utf8.decode('utf-8'))
if self.roundtriptest:
self.assertEqual(native, self.encode(u)[0])
def test_errorhandle(self):
for source, scheme, expected in self.codectests:
if isinstance(source, bytes):
func = self.decode
else:
func = self.encode
if expected:
result = func(source, scheme)[0]
if func is self.decode:
self.assertTrue(type(result) is unicode, type(result))
self.assertEqual(result, expected,
'%r.decode(%r, %r)=%r != %r'
% (source, self.encoding, scheme, result,
expected))
else:
self.assertTrue(type(result) is bytes, type(result))
self.assertEqual(result, expected,
'%r.encode(%r, %r)=%r != %r'
% (source, self.encoding, scheme, result,
expected))
else:
self.assertRaises(UnicodeError, func, source, scheme)
def test_xmlcharrefreplace(self):
if self.has_iso10646:
self.skipTest('encoding contains full ISO 10646 map')
s = u"\u0b13\u0b23\u0b60 nd eggs"
self.assertEqual(
self.encode(s, "xmlcharrefreplace")[0],
"ଓଣୠ nd eggs"
)
def test_customreplace_encode(self):
if self.has_iso10646:
self.skipTest('encoding contains full ISO 10646 map')
from htmlentitydefs import codepoint2name
def xmlcharnamereplace(exc):
if not isinstance(exc, UnicodeEncodeError):
raise TypeError("don't know how to handle %r" % exc)
l = []
for c in exc.object[exc.start:exc.end]:
if ord(c) in codepoint2name:
l.append(u"&%s;" % codepoint2name[ord(c)])
else:
l.append(u"&#%d;" % ord(c))
return (u"".join(l), exc.end)
codecs.register_error("test.xmlcharnamereplace", xmlcharnamereplace)
if self.xmlcharnametest:
sin, sout = self.xmlcharnametest
else:
sin = u"\xab\u211c\xbb = \u2329\u1234\u232a"
sout = "«ℜ» = ⟨ሴ⟩"
self.assertEqual(self.encode(sin,
"test.xmlcharnamereplace")[0], sout)
def test_callback_wrong_objects(self):
def myreplace(exc):
return (ret, exc.end)
codecs.register_error("test.cjktest", myreplace)
for ret in ([1, 2, 3], [], None, object(), 'string', ''):
self.assertRaises(TypeError, self.encode, self.unmappedunicode,
'test.cjktest')
def test_callback_long_index(self):
def myreplace(exc):
return (u'x', long(exc.end))
codecs.register_error("test.cjktest", myreplace)
self.assertEqual(self.encode(u'abcd' + self.unmappedunicode + u'efgh',
'test.cjktest'), ('abcdxefgh', 9))
def myreplace(exc):
return (u'x', sys.maxint + 1)
codecs.register_error("test.cjktest", myreplace)
self.assertRaises(IndexError, self.encode, self.unmappedunicode,
'test.cjktest')
def test_callback_None_index(self):
def myreplace(exc):
return (u'x', None)
codecs.register_error("test.cjktest", myreplace)
self.assertRaises(TypeError, self.encode, self.unmappedunicode,
'test.cjktest')
def test_callback_backward_index(self):
def myreplace(exc):
if myreplace.limit > 0:
myreplace.limit -= 1
return (u'REPLACED', 0)
else:
return (u'TERMINAL', exc.end)
myreplace.limit = 3
codecs.register_error("test.cjktest", myreplace)
self.assertEqual(self.encode(u'abcd' + self.unmappedunicode + u'efgh',
'test.cjktest'),
('abcdREPLACEDabcdREPLACEDabcdREPLACEDabcdTERMINALefgh', 9))
def test_callback_forward_index(self):
def myreplace(exc):
return (u'REPLACED', exc.end + 2)
codecs.register_error("test.cjktest", myreplace)
self.assertEqual(self.encode(u'abcd' + self.unmappedunicode + u'efgh',
'test.cjktest'), ('abcdREPLACEDgh', 9))
def test_callback_index_outofbound(self):
def myreplace(exc):
return (u'TERM', 100)
codecs.register_error("test.cjktest", myreplace)
self.assertRaises(IndexError, self.encode, self.unmappedunicode,
'test.cjktest')
def test_incrementalencoder(self):
UTF8Reader = codecs.getreader('utf-8')
for sizehint in [None] + range(1, 33) + \
[64, 128, 256, 512, 1024]:
istream = UTF8Reader(StringIO(self.tstring[1]))
ostream = StringIO()
encoder = self.incrementalencoder()
while 1:
if sizehint is not None:
data = istream.read(sizehint)
else:
data = istream.read()
if not data:
break
e = encoder.encode(data)
ostream.write(e)
self.assertEqual(ostream.getvalue(), self.tstring[0])
def test_incrementaldecoder(self):
UTF8Writer = codecs.getwriter('utf-8')
for sizehint in [None, -1] + range(1, 33) + \
[64, 128, 256, 512, 1024]:
istream = StringIO(self.tstring[0])
ostream = UTF8Writer(StringIO())
decoder = self.incrementaldecoder()
while 1:
data = istream.read(sizehint)
if not data:
break
else:
u = decoder.decode(data)
ostream.write(u)
self.assertEqual(ostream.getvalue(), self.tstring[1])
def test_incrementalencoder_error_callback(self):
inv = self.unmappedunicode
e = self.incrementalencoder()
self.assertRaises(UnicodeEncodeError, e.encode, inv, True)
e.errors = 'ignore'
self.assertEqual(e.encode(inv, True), '')
e.reset()
def tempreplace(exc):
return (u'called', exc.end)
codecs.register_error('test.incremental_error_callback', tempreplace)
e.errors = 'test.incremental_error_callback'
self.assertEqual(e.encode(inv, True), 'called')
# again
e.errors = 'ignore'
self.assertEqual(e.encode(inv, True), '')
def test_streamreader(self):
UTF8Writer = codecs.getwriter('utf-8')
for name in ["read", "readline", "readlines"]:
for sizehint in [None, -1] + range(1, 33) + \
[64, 128, 256, 512, 1024]:
istream = self.reader(StringIO(self.tstring[0]))
ostream = UTF8Writer(StringIO())
func = getattr(istream, name)
while 1:
data = func(sizehint)
if not data:
break
if name == "readlines":
ostream.writelines(data)
else:
ostream.write(data)
self.assertEqual(ostream.getvalue(), self.tstring[1])
def test_streamwriter(self):
readfuncs = ('read', 'readline', 'readlines')
UTF8Reader = codecs.getreader('utf-8')
for name in readfuncs:
for sizehint in [None] + range(1, 33) + \
[64, 128, 256, 512, 1024]:
istream = UTF8Reader(StringIO(self.tstring[1]))
ostream = self.writer(StringIO())
func = getattr(istream, name)
while 1:
if sizehint is not None:
data = func(sizehint)
else:
data = func()
if not data:
break
if name == "readlines":
ostream.writelines(data)
else:
ostream.write(data)
self.assertEqual(ostream.getvalue(), self.tstring[0])
class TestBase_Mapping(unittest.TestCase):
pass_enctest = []
pass_dectest = []
supmaps = []
codectests = []
def __init__(self, *args, **kw):
unittest.TestCase.__init__(self, *args, **kw)
try:
self.open_mapping_file().close() # test it to report the error early
except (IOError, HTTPException):
self.skipTest("Could not retrieve "+self.mapfileurl)
def open_mapping_file(self):
return test_support.open_urlresource(self.mapfileurl)
def test_mapping_file(self):
if self.mapfileurl.endswith('.xml'):
self._test_mapping_file_ucm()
else:
self._test_mapping_file_plain()
def _test_mapping_file_plain(self):
_unichr = lambda c: eval("u'\\U%08x'" % int(c, 16))
unichrs = lambda s: u''.join(_unichr(c) for c in s.split('+'))
urt_wa = {}
with self.open_mapping_file() as f:
for line in f:
if not line:
break
data = line.split('#')[0].strip().split()
if len(data) != 2:
continue
csetval = eval(data[0])
if csetval <= 0x7F:
csetch = chr(csetval & 0xff)
elif csetval >= 0x1000000:
csetch = chr(csetval >> 24) + chr((csetval >> 16) & 0xff) + \
chr((csetval >> 8) & 0xff) + chr(csetval & 0xff)
elif csetval >= 0x10000:
csetch = chr(csetval >> 16) + \
chr((csetval >> 8) & 0xff) + chr(csetval & 0xff)
elif csetval >= 0x100:
csetch = chr(csetval >> 8) + chr(csetval & 0xff)
else:
continue
unich = unichrs(data[1])
if unich == u'\ufffd' or unich in urt_wa:
continue
urt_wa[unich] = csetch
self._testpoint(csetch, unich)
def _test_mapping_file_ucm(self):
with self.open_mapping_file() as f:
ucmdata = f.read()
uc = re.findall('<a u="([A-F0-9]{4})" b="([0-9A-F ]+)"/>', ucmdata)
for uni, coded in uc:
unich = unichr(int(uni, 16))
codech = ''.join(chr(int(c, 16)) for c in coded.split())
self._testpoint(codech, unich)
def test_mapping_supplemental(self):
for mapping in self.supmaps:
self._testpoint(*mapping)
def _testpoint(self, csetch, unich):
if (csetch, unich) not in self.pass_enctest:
try:
self.assertEqual(unich.encode(self.encoding), csetch)
except UnicodeError, exc:
self.fail('Encoding failed while testing %s -> %s: %s' % (
repr(unich), repr(csetch), exc.reason))
if (csetch, unich) not in self.pass_dectest:
try:
self.assertEqual(csetch.decode(self.encoding), unich)
except UnicodeError, exc:
self.fail('Decoding failed while testing %s -> %s: %s' % (
repr(csetch), repr(unich), exc.reason))
def test_errorhandle(self):
for source, scheme, expected in self.codectests:
if isinstance(source, bytes):
func = source.decode
else:
func = source.encode
if expected:
if isinstance(source, bytes):
result = func(self.encoding, scheme)
self.assertTrue(type(result) is unicode, type(result))
self.assertEqual(result, expected,
'%r.decode(%r, %r)=%r != %r'
% (source, self.encoding, scheme, result,
expected))
else:
result = func(self.encoding, scheme)
self.assertTrue(type(result) is bytes, type(result))
self.assertEqual(result, expected,
'%r.encode(%r, %r)=%r != %r'
% (source, self.encoding, scheme, result,
expected))
else:
self.assertRaises(UnicodeError, func, self.encoding, scheme)
def load_teststring(name):
dir = os.path.join(os.path.dirname(__file__), 'cjkencodings')
with open(os.path.join(dir, name + '.txt'), 'rb') as f:
encoded = f.read()
with open(os.path.join(dir, name + '-utf8.txt'), 'rb') as f:
utf8 = f.read()
return encoded, utf8
|
gpl-3.0
|
[
3,
511,
63,
3029,
4414,
9276,
63,
4058,
14,
647,
199,
3,
257,
13964,
1910,
1770,
30790,
3746,
367,
445,
25575,
6010,
199,
3,
199,
199,
646,
6010,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
646,
2882,
199,
504,
8809,
492,
28185,
199,
504,
511,
492,
511,
63,
4058,
199,
504,
5228,
492,
5228,
199,
199,
533,
1379,
1563,
26,
272,
2644,
263,
275,
2125,
257,
327,
9076,
536,
272,
9076,
3698,
275,
488,
327,
9076,
2008,
334,
1045,
841,
4008,
9,
272,
307,
875,
260,
275,
2125,
257,
327,
1059,
370,
511,
22970,
339,
9076,
2219,
420,
275,
488,
327,
1471,
663,
14,
9076,
511,
2008,
272,
6168,
7254,
396,
257,
275,
413,
259,
327,
663,
340,
6168,
7254,
365,
3962,
543,
2649,
272,
965,
63,
4595,
709,
11387,
259,
275,
378,
259,
327,
663,
340,
642,
2644,
3509,
8852,
11601,
709,
11387,
2341,
272,
2748,
1560,
354,
396,
275,
488,
327,
1059,
370,
511,
2748,
24253,
1814,
272,
625,
11663,
2975,
275,
399,
1154,
3786,
1024,
7,
327,
282,
2649,
1233,
2376,
626,
365,
440,
9994,
14,
339,
347,
3613,
8,
277,
304,
267,
340,
291,
14,
9276,
365,
488,
26,
288,
291,
14,
9276,
275,
6010,
14,
3892,
8,
277,
14,
2991,
9,
267,
291,
14,
2143,
275,
291,
14,
9276,
14,
2143,
267,
291,
14,
2708,
275,
291,
14,
9276,
14,
2708,
267,
291,
14,
5503,
275,
291,
14,
9276,
14,
1745,
5503,
267,
291,
14,
5491,
275,
291,
14,
9276,
14,
1745,
5491,
267,
291,
14,
9728,
24080,
275,
291,
14,
9276,
14,
9728,
24080,
267,
291,
14,
23760,
8813,
275,
291,
14,
9276,
14,
23760,
8813,
339,
347,
511,
63,
4604,
1523,
8,
277,
304,
267,
367,
5438,
12,
2774,
24,
315,
3482,
23151,
6424,
8,
70,
680,
9684,
342,
3303,
367,
289,
315,
291,
14,
84,
875,
4682,
288,
399,
275,
291,
14,
2708,
8,
6106,
2788,
16,
61,
288,
291,
14,
629,
8,
85,
12,
2774,
24,
14,
2708,
360,
1624,
13,
24,
1333,
288,
340,
291,
14,
25920,
396,
26,
355,
291,
14,
629,
8,
6106,
12,
291,
14,
2143,
8,
85,
2788,
16,
566,
339,
347,
511,
63,
705,
2479,
8,
277,
304,
267,
367,
1350,
12,
5687,
12,
1420,
315,
291,
14,
9276,
2219,
26,
288,
340,
1228,
8,
1365,
12,
2783,
304,
355,
2562,
275,
291,
14,
2708,
288,
587,
26,
355,
2562,
275,
291,
14,
2143,
288,
340,
1420,
26,
355,
754,
275,
2562,
8,
1365,
12,
5687,
2788,
16,
61,
355,
340,
2562,
365,
291,
14,
2708,
26,
490,
291,
14,
1815,
8,
466,
8,
1099,
9,
365,
2649,
12,
730,
8,
1099,
430,
490,
291,
14,
629,
8,
1099,
12,
1420,
12,
3660,
1543,
82,
14,
2708,
4042,
82,
12,
450,
82,
9,
2458,
82,
1137,
450,
82,
7,
3660,
450,
334,
1365,
12,
291,
14,
2991,
12,
5687,
12,
754,
12,
3147,
1420,
430,
355,
587,
26,
490,
291,
14,
1815,
8,
466,
8,
1099,
9,
365,
2783,
12,
730,
8,
1099,
430,
490,
291,
14,
629,
8,
1099,
12,
1420,
12,
3660,
1543,
82,
14,
2143,
4042,
82,
12,
450,
82,
9,
2458,
82,
1137,
450,
82,
7,
3660,
450,
334,
1365,
12,
291,
14,
2991,
12,
5687,
12,
754,
12,
3147,
1420,
430,
288,
587,
26,
355,
291,
14,
1855,
8,
7087,
547,
12,
2562,
12,
1350,
12,
5687,
9,
339,
347,
511,
63,
1652,
24253,
1814,
8,
277,
304,
267,
340,
291,
14,
1989,
63,
4595,
709,
11387,
26,
288,
291,
14,
23809,
360,
2991,
3509,
2615,
9055,
1616,
11387,
2341,
358,
398,
308,
275,
399,
3212,
85,
16,
66,
969,
60,
85,
16,
66,
1789,
60,
85,
16,
66,
2259,
5222,
22151,
2,
267,
291,
14,
629,
8,
288,
291,
14,
2143,
8,
83,
12,
298,
1652,
24253,
1814,
9981,
16,
467,
288,
27720,
1651,
1276,
14328,
1651,
2869,
14328,
1398,
713,
27,
5222,
22151,
2,
267,
776,
339,
347,
511,
63,
4229,
1814,
63,
2143,
8,
277,
304,
267,
340,
291,
14,
1989,
63,
4595,
709,
11387,
26,
288,
291,
14,
23809,
360,
2991,
3509,
2615,
9055,
1616,
11387,
2341,
358,
398,
687,
30010,
552,
1701,
8710,
492,
1233,
1403,
18,
354,
398,
347,
2748,
1560,
354,
1814,
8,
2804,
304,
288,
340,
440,
1228,
8,
2804,
12,
24094,
304,
355,
746,
3146,
480,
13196,
1133,
5715,
4212,
370,
2429,
450,
82,
2,
450,
3178,
9,
288,
634,
275,
942,
288,
367,
286,
315,
3178,
14,
785,
59,
2804,
14,
928,
26,
2804,
14,
500,
2189,
355,
340,
6206,
8,
67,
9,
315,
1233,
1403,
18,
354,
26,
490,
634,
14,
740,
8,
85,
2,
6,
5,
83,
9426,
450,
1233,
1403,
18,
354,
59,
2181,
8,
67,
3948,
355,
587,
26,
490,
634,
14,
740,
8,
85,
2,
7997,
5,
68,
9426,
450,
6206,
8,
67,
430,
288,
372,
334,
85,
25148,
904,
8,
76,
395,
3178,
14,
500,
9,
398,
6010,
14,
2683,
63,
705,
480,
396,
14,
1652,
1560,
354,
1814,
401,
2748,
1560,
354,
1814,
9,
398,
340,
291,
14,
1652,
1560,
354,
396,
26,
288,
9829,
12,
308,
548,
275,
291,
14,
1652,
1560,
354,
396,
267,
587,
26,
288,
9829,
275,
399,
3212,
10097,
60,
85,
12832,
67,
60,
9932,
275,
971,
85,
8001,
25,
60,
85,
4321,
60,
85,
8001,
65,
2,
288,
308,
548,
275,
11746,
416,
14209,
15337,
3093,
15337,
345,
14209,
27,
275,
1253,
4159,
14328,
20,
15268,
15337,
82,
621,
9426,
267,
291,
14,
629,
8,
277,
14,
2143,
8,
5911,
12,
2511,
298,
396,
14,
1652,
1560,
354,
1814,
9981,
16,
467,
308,
548,
9,
339,
347,
511,
63,
3058,
63,
10603,
63,
1462,
8,
277,
304,
267,
347,
3002,
1814,
8,
2804,
304,
288,
372,
334,
3292,
12,
3178,
14,
500,
9,
267,
6010,
14,
2683,
63,
705,
480,
396,
14,
67,
17421,
396,
401,
3002,
1814,
9,
398,
367,
2203,
315,
7287,
17,
12,
499,
12,
650,
467,
990,
488,
12,
909,
1062,
283,
875,
297,
21019,
288,
291,
14,
1855,
8,
4333,
12,
291,
14,
2143,
12,
291,
14,
324,
11663,
2975,
12,
2892,
283,
396,
14,
67,
17421,
396,
358,
339,
347,
511,
63
] |
[
511,
63,
3029,
4414,
9276,
63,
4058,
14,
647,
199,
3,
257,
13964,
1910,
1770,
30790,
3746,
367,
445,
25575,
6010,
199,
3,
199,
199,
646,
6010,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
646,
2882,
199,
504,
8809,
492,
28185,
199,
504,
511,
492,
511,
63,
4058,
199,
504,
5228,
492,
5228,
199,
199,
533,
1379,
1563,
26,
272,
2644,
263,
275,
2125,
257,
327,
9076,
536,
272,
9076,
3698,
275,
488,
327,
9076,
2008,
334,
1045,
841,
4008,
9,
272,
307,
875,
260,
275,
2125,
257,
327,
1059,
370,
511,
22970,
339,
9076,
2219,
420,
275,
488,
327,
1471,
663,
14,
9076,
511,
2008,
272,
6168,
7254,
396,
257,
275,
413,
259,
327,
663,
340,
6168,
7254,
365,
3962,
543,
2649,
272,
965,
63,
4595,
709,
11387,
259,
275,
378,
259,
327,
663,
340,
642,
2644,
3509,
8852,
11601,
709,
11387,
2341,
272,
2748,
1560,
354,
396,
275,
488,
327,
1059,
370,
511,
2748,
24253,
1814,
272,
625,
11663,
2975,
275,
399,
1154,
3786,
1024,
7,
327,
282,
2649,
1233,
2376,
626,
365,
440,
9994,
14,
339,
347,
3613,
8,
277,
304,
267,
340,
291,
14,
9276,
365,
488,
26,
288,
291,
14,
9276,
275,
6010,
14,
3892,
8,
277,
14,
2991,
9,
267,
291,
14,
2143,
275,
291,
14,
9276,
14,
2143,
267,
291,
14,
2708,
275,
291,
14,
9276,
14,
2708,
267,
291,
14,
5503,
275,
291,
14,
9276,
14,
1745,
5503,
267,
291,
14,
5491,
275,
291,
14,
9276,
14,
1745,
5491,
267,
291,
14,
9728,
24080,
275,
291,
14,
9276,
14,
9728,
24080,
267,
291,
14,
23760,
8813,
275,
291,
14,
9276,
14,
23760,
8813,
339,
347,
511,
63,
4604,
1523,
8,
277,
304,
267,
367,
5438,
12,
2774,
24,
315,
3482,
23151,
6424,
8,
70,
680,
9684,
342,
3303,
367,
289,
315,
291,
14,
84,
875,
4682,
288,
399,
275,
291,
14,
2708,
8,
6106,
2788,
16,
61,
288,
291,
14,
629,
8,
85,
12,
2774,
24,
14,
2708,
360,
1624,
13,
24,
1333,
288,
340,
291,
14,
25920,
396,
26,
355,
291,
14,
629,
8,
6106,
12,
291,
14,
2143,
8,
85,
2788,
16,
566,
339,
347,
511,
63,
705,
2479,
8,
277,
304,
267,
367,
1350,
12,
5687,
12,
1420,
315,
291,
14,
9276,
2219,
26,
288,
340,
1228,
8,
1365,
12,
2783,
304,
355,
2562,
275,
291,
14,
2708,
288,
587,
26,
355,
2562,
275,
291,
14,
2143,
288,
340,
1420,
26,
355,
754,
275,
2562,
8,
1365,
12,
5687,
2788,
16,
61,
355,
340,
2562,
365,
291,
14,
2708,
26,
490,
291,
14,
1815,
8,
466,
8,
1099,
9,
365,
2649,
12,
730,
8,
1099,
430,
490,
291,
14,
629,
8,
1099,
12,
1420,
12,
3660,
1543,
82,
14,
2708,
4042,
82,
12,
450,
82,
9,
2458,
82,
1137,
450,
82,
7,
3660,
450,
334,
1365,
12,
291,
14,
2991,
12,
5687,
12,
754,
12,
3147,
1420,
430,
355,
587,
26,
490,
291,
14,
1815,
8,
466,
8,
1099,
9,
365,
2783,
12,
730,
8,
1099,
430,
490,
291,
14,
629,
8,
1099,
12,
1420,
12,
3660,
1543,
82,
14,
2143,
4042,
82,
12,
450,
82,
9,
2458,
82,
1137,
450,
82,
7,
3660,
450,
334,
1365,
12,
291,
14,
2991,
12,
5687,
12,
754,
12,
3147,
1420,
430,
288,
587,
26,
355,
291,
14,
1855,
8,
7087,
547,
12,
2562,
12,
1350,
12,
5687,
9,
339,
347,
511,
63,
1652,
24253,
1814,
8,
277,
304,
267,
340,
291,
14,
1989,
63,
4595,
709,
11387,
26,
288,
291,
14,
23809,
360,
2991,
3509,
2615,
9055,
1616,
11387,
2341,
358,
398,
308,
275,
399,
3212,
85,
16,
66,
969,
60,
85,
16,
66,
1789,
60,
85,
16,
66,
2259,
5222,
22151,
2,
267,
291,
14,
629,
8,
288,
291,
14,
2143,
8,
83,
12,
298,
1652,
24253,
1814,
9981,
16,
467,
288,
27720,
1651,
1276,
14328,
1651,
2869,
14328,
1398,
713,
27,
5222,
22151,
2,
267,
776,
339,
347,
511,
63,
4229,
1814,
63,
2143,
8,
277,
304,
267,
340,
291,
14,
1989,
63,
4595,
709,
11387,
26,
288,
291,
14,
23809,
360,
2991,
3509,
2615,
9055,
1616,
11387,
2341,
358,
398,
687,
30010,
552,
1701,
8710,
492,
1233,
1403,
18,
354,
398,
347,
2748,
1560,
354,
1814,
8,
2804,
304,
288,
340,
440,
1228,
8,
2804,
12,
24094,
304,
355,
746,
3146,
480,
13196,
1133,
5715,
4212,
370,
2429,
450,
82,
2,
450,
3178,
9,
288,
634,
275,
942,
288,
367,
286,
315,
3178,
14,
785,
59,
2804,
14,
928,
26,
2804,
14,
500,
2189,
355,
340,
6206,
8,
67,
9,
315,
1233,
1403,
18,
354,
26,
490,
634,
14,
740,
8,
85,
2,
6,
5,
83,
9426,
450,
1233,
1403,
18,
354,
59,
2181,
8,
67,
3948,
355,
587,
26,
490,
634,
14,
740,
8,
85,
2,
7997,
5,
68,
9426,
450,
6206,
8,
67,
430,
288,
372,
334,
85,
25148,
904,
8,
76,
395,
3178,
14,
500,
9,
398,
6010,
14,
2683,
63,
705,
480,
396,
14,
1652,
1560,
354,
1814,
401,
2748,
1560,
354,
1814,
9,
398,
340,
291,
14,
1652,
1560,
354,
396,
26,
288,
9829,
12,
308,
548,
275,
291,
14,
1652,
1560,
354,
396,
267,
587,
26,
288,
9829,
275,
399,
3212,
10097,
60,
85,
12832,
67,
60,
9932,
275,
971,
85,
8001,
25,
60,
85,
4321,
60,
85,
8001,
65,
2,
288,
308,
548,
275,
11746,
416,
14209,
15337,
3093,
15337,
345,
14209,
27,
275,
1253,
4159,
14328,
20,
15268,
15337,
82,
621,
9426,
267,
291,
14,
629,
8,
277,
14,
2143,
8,
5911,
12,
2511,
298,
396,
14,
1652,
1560,
354,
1814,
9981,
16,
467,
308,
548,
9,
339,
347,
511,
63,
3058,
63,
10603,
63,
1462,
8,
277,
304,
267,
347,
3002,
1814,
8,
2804,
304,
288,
372,
334,
3292,
12,
3178,
14,
500,
9,
267,
6010,
14,
2683,
63,
705,
480,
396,
14,
67,
17421,
396,
401,
3002,
1814,
9,
398,
367,
2203,
315,
7287,
17,
12,
499,
12,
650,
467,
990,
488,
12,
909,
1062,
283,
875,
297,
21019,
288,
291,
14,
1855,
8,
4333,
12,
291,
14,
2143,
12,
291,
14,
324,
11663,
2975,
12,
2892,
283,
396,
14,
67,
17421,
396,
358,
339,
347,
511,
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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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
stwolny/GrovePi
|
Software/Python/grove_electromagnet.py
|
7
|
2291
|
#!/usr/bin/env python
#
# GrovePi Example for using the Grove Electromagnet (http://www.seeedstudio.com/wiki/Grove_-_Electromagnet)
#
# The GrovePi connects the Raspberry Pi and Grove sensors. You can learn more about GrovePi here: http://www.dexterindustries.com/GrovePi
#
# Have a question about this example? Ask on the forums here: http://www.dexterindustries.com/forum/?forum=grovepi
#
'''
## License
The MIT License (MIT)
GrovePi for the Raspberry Pi: an open source platform for connecting Grove Sensors to the Raspberry Pi.
Copyright (C) 2015 Dexter Industries
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''
import time
import grovepi
# The electromagnet can hold a 1KG weight
# Connect the Grove Electromagnet to digital port D4
# SIG,NC,VCC,GND
electromagnet = 4
grovepi.pinMode(electromagnet,"OUTPUT")
time.sleep(1)
while True:
try:
# Switch on electromagnet
grovepi.digitalWrite(electromagnet,1)
print ("on")
time.sleep(2)
# Switch off electromagnet
grovepi.digitalWrite(electromagnet,0)
print ("off")
time.sleep(2)
except KeyboardInterrupt:
grovepi.digitalWrite(electromagnet,0)
break
except IOError:
print ("Error")
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
202,
199,
3,
202,
199,
3,
598,
11750,
10542,
5679,
367,
1808,
314,
598,
11750,
662,
1264,
293,
19902,
386,
334,
1014,
921,
1544,
14,
3239,
379,
19806,
14,
957,
15,
6797,
15,
39,
11750,
32069,
63,
37,
1264,
293,
19902,
386,
9,
202,
199,
3,
202,
199,
3,
710,
598,
11750,
10542,
4907,
83,
314,
820,
20222,
605,
651,
19835,
436,
598,
11750,
19678,
14,
221,
2047,
883,
12537,
1655,
3595,
598,
11750,
10542,
2348,
26,
221,
1455,
921,
1544,
14,
731,
351,
688,
85,
816,
397,
14,
957,
15,
39,
11750,
10542,
202,
199,
3,
202,
199,
3,
26858,
282,
7894,
3595,
642,
2893,
31,
221,
30481,
641,
314,
21575,
83,
2348,
26,
221,
1455,
921,
1544,
14,
731,
351,
688,
85,
816,
397,
14,
957,
15,
10044,
10197,
10044,
29,
71,
11750,
1038,
202,
199,
3,
2999,
199,
2344,
202,
199,
309,
844,
2999,
199,
1918,
10697,
844,
334,
13965,
9,
2999,
199,
39,
11750,
10542,
367,
314,
820,
20222,
605,
651,
19835,
26,
376,
1551,
1350,
4298,
367,
18170,
598,
11750,
428,
17564,
370,
314,
820,
20222,
605,
651,
19835,
14,
202,
199,
7384,
334,
35,
9,
6900,
221,
577,
476,
351,
473,
977,
85,
816,
397,
2999,
199,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
202,
199,
1618,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
202,
199,
262,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
202,
199,
475,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
202,
199,
16847,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
202,
199,
70,
13399,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
2999,
199,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
202,
199,
452,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
2999,
199,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
202,
199,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
202,
199,
38,
3061,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
202,
199,
5580,
4149,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
202,
199,
2673,
2477,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
202,
199,
1877,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
202,
199,
18061,
4141,
14,
202,
199,
2344,
2999,
199,
646,
900,
202,
199,
646,
486,
11750,
1038,
2999,
199,
3,
710,
28933,
293,
19902,
386,
883,
10266,
282,
413,
14634,
5401,
2999,
199,
3,
15175,
314,
598,
11750,
662,
1264,
293,
19902,
386,
370,
20545,
1844,
577,
20,
202,
199,
3,
15522,
12,
6389,
12,
54,
2571,
12,
39,
8711,
202,
199,
26334,
293,
19902,
386,
275,
841,
2999,
199,
71,
11750,
1038,
14,
7751,
1385,
8,
26334,
293,
19902,
386,
4589,
8414,
531,
202,
199,
521,
14,
4532,
8,
17,
9,
2999,
199,
6710,
715,
26,
1128,
862,
26,
1039,
327,
17711,
641,
28933,
293,
19902,
386,
1039,
486,
11750,
1038,
14,
25888,
3534,
8,
26334,
293,
19902,
386,
12,
17,
9,
1039,
870,
1689,
265,
531,
1039,
900,
14,
4532,
8,
18,
9,
4341,
327,
17711,
2331,
28933,
293,
19902,
386,
1039,
486,
11750,
1038,
14,
25888,
3534,
8,
26334,
293,
19902,
386,
12,
16,
9,
1039,
870,
1689,
1997,
531,
1039,
900,
14,
4532,
8,
18,
9,
2958,
871,
13483,
26,
1039,
486,
11750,
1038,
14,
25888,
3534,
8,
26334,
293,
19902,
386,
12,
16,
9,
1039,
2059,
1128,
871,
5925,
26,
1039,
870,
1689,
547,
531,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
202,
199,
3,
202,
199,
3,
598,
11750,
10542,
5679,
367,
1808,
314,
598,
11750,
662,
1264,
293,
19902,
386,
334,
1014,
921,
1544,
14,
3239,
379,
19806,
14,
957,
15,
6797,
15,
39,
11750,
32069,
63,
37,
1264,
293,
19902,
386,
9,
202,
199,
3,
202,
199,
3,
710,
598,
11750,
10542,
4907,
83,
314,
820,
20222,
605,
651,
19835,
436,
598,
11750,
19678,
14,
221,
2047,
883,
12537,
1655,
3595,
598,
11750,
10542,
2348,
26,
221,
1455,
921,
1544,
14,
731,
351,
688,
85,
816,
397,
14,
957,
15,
39,
11750,
10542,
202,
199,
3,
202,
199,
3,
26858,
282,
7894,
3595,
642,
2893,
31,
221,
30481,
641,
314,
21575,
83,
2348,
26,
221,
1455,
921,
1544,
14,
731,
351,
688,
85,
816,
397,
14,
957,
15,
10044,
10197,
10044,
29,
71,
11750,
1038,
202,
199,
3,
2999,
199,
2344,
202,
199,
309,
844,
2999,
199,
1918,
10697,
844,
334,
13965,
9,
2999,
199,
39,
11750,
10542,
367,
314,
820,
20222,
605,
651,
19835,
26,
376,
1551,
1350,
4298,
367,
18170,
598,
11750,
428,
17564,
370,
314,
820,
20222,
605,
651,
19835,
14,
202,
199,
7384,
334,
35,
9,
6900,
221,
577,
476,
351,
473,
977,
85,
816,
397,
2999,
199,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
202,
199,
1618,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
202,
199,
262,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
202,
199,
475,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
202,
199,
16847,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
202,
199,
70,
13399,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
2999,
199,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
202,
199,
452,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
2999,
199,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
202,
199,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
202,
199,
38,
3061,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
202,
199,
5580,
4149,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
202,
199,
2673,
2477,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
202,
199,
1877,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
202,
199,
18061,
4141,
14,
202,
199,
2344,
2999,
199,
646,
900,
202,
199,
646,
486,
11750,
1038,
2999,
199,
3,
710,
28933,
293,
19902,
386,
883,
10266,
282,
413,
14634,
5401,
2999,
199,
3,
15175,
314,
598,
11750,
662,
1264,
293,
19902,
386,
370,
20545,
1844,
577,
20,
202,
199,
3,
15522,
12,
6389,
12,
54,
2571,
12,
39,
8711,
202,
199,
26334,
293,
19902,
386,
275,
841,
2999,
199,
71,
11750,
1038,
14,
7751,
1385,
8,
26334,
293,
19902,
386,
4589,
8414,
531,
202,
199,
521,
14,
4532,
8,
17,
9,
2999,
199,
6710,
715,
26,
1128,
862,
26,
1039,
327,
17711,
641,
28933,
293,
19902,
386,
1039,
486,
11750,
1038,
14,
25888,
3534,
8,
26334,
293,
19902,
386,
12,
17,
9,
1039,
870,
1689,
265,
531,
1039,
900,
14,
4532,
8,
18,
9,
4341,
327,
17711,
2331,
28933,
293,
19902,
386,
1039,
486,
11750,
1038,
14,
25888,
3534,
8,
26334,
293,
19902,
386,
12,
16,
9,
1039,
870,
1689,
1997,
531,
1039,
900,
14,
4532,
8,
18,
9,
2958,
871,
13483,
26,
1039,
486,
11750,
1038,
14,
25888,
3534,
8,
26334,
293,
19902,
386,
12,
16,
9,
1039,
2059,
1128,
871,
5925,
26,
1039,
870,
1689,
547,
531,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hiroakis/ansible
|
lib/ansible/plugins/lookup/etcd.py
|
151
|
2323
|
# (c) 2013, Jan-Piet Mens <jpmens(at)gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
try:
import json
except ImportError:
import simplejson as json
from ansible.plugins.lookup import LookupBase
from ansible.module_utils.urls import open_url
# this can be made configurable, not should not use ansible.cfg
ANSIBLE_ETCD_URL = 'http://127.0.0.1:4001'
if os.getenv('ANSIBLE_ETCD_URL') is not None:
ANSIBLE_ETCD_URL = os.environ['ANSIBLE_ETCD_URL']
class Etcd:
def __init__(self, url=ANSIBLE_ETCD_URL, validate_certs=True):
self.url = url
self.baseurl = '%s/v1/keys' % (self.url)
self.validate_certs = validate_certs
def get(self, key):
url = "%s/%s" % (self.baseurl, key)
data = None
value = ""
try:
r = open_url(url, validate_certs=self.validate_certs)
data = r.read()
except:
return value
try:
# {"action":"get","key":"/name","value":"Jane Jolie","index":5}
item = json.loads(data)
if 'value' in item:
value = item['value']
if 'errorCode' in item:
value = "ENOENT"
except:
raise
pass
return value
class LookupModule(LookupBase):
def run(self, terms, variables, **kwargs):
validate_certs = kwargs.get('validate_certs', True)
etcd = Etcd(validate_certs=validate_certs)
ret = []
for term in terms:
key = term.split()[0]
value = etcd.get(key)
ret.append(value)
return ret
|
gpl-3.0
|
[
3,
334,
67,
9,
6171,
12,
17474,
13,
10542,
386,
603,
8764,
665,
11538,
278,
561,
8,
292,
9,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
747,
199,
199,
893,
26,
272,
492,
2022,
199,
2590,
3545,
26,
272,
492,
13804,
465,
2022,
199,
199,
504,
3242,
14,
5265,
14,
3892,
492,
12785,
1563,
199,
504,
3242,
14,
578,
63,
1208,
14,
3603,
492,
1551,
63,
633,
199,
199,
3,
642,
883,
506,
6326,
30241,
12,
440,
1077,
440,
675,
3242,
14,
4128,
199,
8490,
63,
775,
7695,
63,
2632,
275,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
20,
4587,
7,
199,
692,
747,
14,
12959,
360,
8490,
63,
775,
7695,
63,
2632,
358,
365,
440,
488,
26,
272,
32271,
7187,
63,
775,
7695,
63,
2632,
275,
747,
14,
2314,
459,
8490,
63,
775,
7695,
63,
2632,
418,
199,
199,
533,
662,
84,
2866,
26,
272,
347,
636,
826,
721,
277,
12,
1166,
29,
8490,
63,
775,
7695,
63,
2632,
12,
4107,
63,
8356,
29,
549,
304,
267,
291,
14,
633,
275,
1166,
267,
291,
14,
28937,
275,
1543,
83,
15,
86,
17,
15,
1612,
7,
450,
334,
277,
14,
633,
9,
267,
291,
14,
3502,
63,
8356,
275,
4107,
63,
8356,
339,
347,
664,
8,
277,
12,
790,
304,
267,
1166,
275,
2071,
83,
3149,
83,
2,
450,
334,
277,
14,
28937,
12,
790,
9,
398,
666,
275,
488,
267,
574,
275,
3087,
267,
862,
26,
288,
519,
275,
1551,
63,
633,
8,
633,
12,
4107,
63,
8356,
29,
277,
14,
3502,
63,
8356,
9,
288,
666,
275,
519,
14,
739,
342,
267,
871,
26,
288,
372,
574,
398,
862,
26,
288,
327,
2420,
1287,
5122,
362,
2266,
498,
5122,
15,
354,
2266,
585,
5122,
42,
5865,
7135,
21530,
2266,
1080,
582,
21,
93,
288,
1242,
275,
2022,
14,
3640,
8,
576,
9,
288,
340,
283,
585,
7,
315,
1242,
26,
355,
574,
275,
1242,
459,
585,
418,
288,
340,
283,
705,
3034,
7,
315,
1242,
26,
355,
574,
275,
298,
20465,
2,
267,
871,
26,
288,
746,
288,
986,
398,
372,
574,
199,
199,
533,
12785,
2377,
8,
7521,
1563,
304,
339,
347,
1255,
8,
277,
12,
2895,
12,
2860,
12,
1011,
958,
304,
398,
4107,
63,
8356,
275,
2074,
14,
362,
360,
3502,
63,
8356,
297,
715,
9,
398,
10844,
2866,
275,
662,
84,
2866,
8,
3502,
63,
8356,
29,
3502,
63,
8356,
9,
398,
2203,
275,
942,
267,
367,
6707,
315,
2895,
26,
288,
790,
275,
6707,
14,
1294,
3430,
16,
61,
288,
574,
275,
10844,
2866,
14,
362,
8,
498,
9,
288,
2203,
14,
740,
8,
585,
9,
267,
372,
2203,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
334,
67,
9,
6171,
12,
17474,
13,
10542,
386,
603,
8764,
665,
11538,
278,
561,
8,
292,
9,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
747,
199,
199,
893,
26,
272,
492,
2022,
199,
2590,
3545,
26,
272,
492,
13804,
465,
2022,
199,
199,
504,
3242,
14,
5265,
14,
3892,
492,
12785,
1563,
199,
504,
3242,
14,
578,
63,
1208,
14,
3603,
492,
1551,
63,
633,
199,
199,
3,
642,
883,
506,
6326,
30241,
12,
440,
1077,
440,
675,
3242,
14,
4128,
199,
8490,
63,
775,
7695,
63,
2632,
275,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
20,
4587,
7,
199,
692,
747,
14,
12959,
360,
8490,
63,
775,
7695,
63,
2632,
358,
365,
440,
488,
26,
272,
32271,
7187,
63,
775,
7695,
63,
2632,
275,
747,
14,
2314,
459,
8490,
63,
775,
7695,
63,
2632,
418,
199,
199,
533,
662,
84,
2866,
26,
272,
347,
636,
826,
721,
277,
12,
1166,
29,
8490,
63,
775,
7695,
63,
2632,
12,
4107,
63,
8356,
29,
549,
304,
267,
291,
14,
633,
275,
1166,
267,
291,
14,
28937,
275,
1543,
83,
15,
86,
17,
15,
1612,
7,
450,
334,
277,
14,
633,
9,
267,
291,
14,
3502,
63,
8356,
275,
4107,
63,
8356,
339,
347,
664,
8,
277,
12,
790,
304,
267,
1166,
275,
2071,
83,
3149,
83,
2,
450,
334,
277,
14,
28937,
12,
790,
9,
398,
666,
275,
488,
267,
574,
275,
3087,
267,
862,
26,
288,
519,
275,
1551,
63,
633,
8,
633,
12,
4107,
63,
8356,
29,
277,
14,
3502,
63,
8356,
9,
288,
666,
275,
519,
14,
739,
342,
267,
871,
26,
288,
372,
574,
398,
862,
26,
288,
327,
2420,
1287,
5122,
362,
2266,
498,
5122,
15,
354,
2266,
585,
5122,
42,
5865,
7135,
21530,
2266,
1080,
582,
21,
93,
288,
1242,
275,
2022,
14,
3640,
8,
576,
9,
288,
340,
283,
585,
7,
315,
1242,
26,
355,
574,
275,
1242,
459,
585,
418,
288,
340,
283,
705,
3034,
7,
315,
1242,
26,
355,
574,
275,
298,
20465,
2,
267,
871,
26,
288,
746,
288,
986,
398,
372,
574,
199,
199,
533,
12785,
2377,
8,
7521,
1563,
304,
339,
347,
1255,
8,
277,
12,
2895,
12,
2860,
12,
1011,
958,
304,
398,
4107,
63,
8356,
275,
2074,
14,
362,
360,
3502,
63,
8356,
297,
715,
9,
398,
10844,
2866,
275,
662,
84,
2866,
8,
3502,
63,
8356,
29,
3502,
63,
8356,
9,
398,
2203,
275,
942,
267,
367,
6707,
315,
2895,
26,
288,
790,
275,
6707,
14,
1294,
3430,
16,
61,
288,
574,
275,
10844,
2866,
14,
362,
8,
498,
9,
288,
2203,
14,
740,
8,
585,
9,
267,
372,
2203,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
Kaniabi/ben10
|
source/python/clikit/_tests/test_clikit_command.py
|
2
|
6146
|
from __future__ import unicode_literals
from ben10.foundation.string import Dedent
from clikit.command import Command, InvalidFixture
from clikit.console import BufferedConsole
import pytest
#===================================================================================================
# TESTS
#===================================================================================================
class Test:
def testConstructor(self):
def Hello():
'''
Hello function.
'''
cmd = Command(Hello)
assert cmd.names == ['Hello']
assert cmd.description == 'Hello function.'
cmd = Command(Hello, names='h')
assert cmd.names == ['h']
cmd = Command(Hello, names=['h1', 'h2'])
assert cmd.names == ['h1', 'h2']
def no_doc():
""
cmd = Command(no_doc)
assert cmd.description == '(no description)'
def testArg(self):
arg = Command.Arg('arg', 'INVALID_ARG_TYPE')
with pytest.raises(TypeError):
arg.ConfigureArgumentParser(None)
def testArguments(self):
def Hello(console_, filename, option='yes', no_setup=False, no_default=None, *config):
'''
Hello function.
This is Hello.
:param filename: The name of the file.
:param no_setup: False if set
:param no_default: Receives None
:param config: Configurations
'''
console_.Print('%s - %s' % (filename, option))
[console_.Item(i) for i in config]
cmd = Command(Hello)
assert cmd.names == ['Hello']
assert cmd.description == 'Hello function.'
assert cmd.args.keys() == ['console_', 'filename', 'option', 'no_setup', 'no_default', 'config']
assert map(unicode, cmd.args.values()) == [
'console_',
'filename',
'option=yes',
'no-setup',
'no-default=VALUE',
'*config'
]
assert map(repr, cmd.args.values()) == [
'<Arg console_>',
'<Arg filename>',
'<Arg option=yes>',
'<Arg no-setup>',
'<Arg no-default=VALUE>',
'<Arg *config>',
]
assert cmd.kwargs is None
console = BufferedConsole()
cmd.Call(
fixtures={'console_' : (lambda:console, lambda:None)},
argd={'filename' : 'alpha.txt', 'config' : ['one', 'two', 'three']}
)
assert console.GetOutput() == 'alpha.txt - yes\n- one\n- two\n- three\n'
# Ignores all invalid arguments passed to Call.
console = BufferedConsole()
cmd.Call(
fixtures={'console_' : (lambda:console, lambda:None)},
argd={'filename' : 'bravo.txt', 'INVALID' : 'INVALID'}
)
assert console.GetOutput() == 'bravo.txt - yes\n'
with pytest.raises(InvalidFixture):
cmd.Call({}, {'filename' : 'alpha.txt'})
with pytest.raises(TypeError):
cmd.Call({'console_' : console}, {})
assert cmd.description == 'Hello function.'
assert cmd.long_description == Dedent(
'''
Hello function.
This is Hello.
'''
)
assert cmd.FormatHelp() == Dedent(
'''
Usage:
Hello <filename> <*config> [--option=yes],[--no-setup],[--no-default=VALUE]
Parameters:
filename The name of the file.
config Configurations
Options:
--option (no description) [default: yes]
--no-setup False if set
--no-default Receives None
'''
)
assert cmd.FormatHelp() == Dedent(
'''
Usage:
Hello <filename> <*config> [--option=yes],[--no-setup],[--no-default=VALUE]
Parameters:
filename The name of the file.
config Configurations
Options:
--option (no description) [default: yes]
--no-setup False if set
--no-default Receives None
'''
)
import argparse
parser = argparse.ArgumentParser('TEST')
cmd.ConfigureArgumentParser(parser)
assert parser.format_help() == Dedent(
'''
usage: TEST [-h] [--option OPTION] [--no-setup] [--no-default NO_DEFAULT]
filename [config [config ...]]
positional arguments:
filename
config
optional arguments:
-h, --help show this help message and exit
--option OPTION
--no-setup
--no-default NO_DEFAULT
'''
)
def testNoArgument(self):
def Hello():
'''
Hello function.
:param noargument: This argument does not exist.
'''
with pytest.raises(RuntimeError):
Command(Hello)
def testDEFAULT(self):
'''
Tests the DEFAULT argument type to declare a positional argument with a default value.
'''
def Hello(console_, first=Command.DEFAULT('one')):
'''
Hello function.
'''
console_.Print(first)
cmd = Command(Hello)
assert cmd.names == ['Hello']
assert cmd.description == 'Hello function.'
assert cmd.args.keys() == ['console_', 'first']
assert map(unicode, cmd.args.values()) == ['console_', "first=one"]
assert cmd.kwargs is None
console = BufferedConsole()
cmd.Call(
fixtures={'console_' : (lambda:console, lambda:None)},
argd={}
)
assert console.GetOutput() == 'one\n'
console = BufferedConsole()
cmd.Call(
fixtures={'console_' : (lambda:console, lambda:None)},
argd={'first' : 'two'}
)
assert console.GetOutput() == 'two\n'
|
lgpl-2.1
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
330,
287,
709,
14,
4214,
425,
14,
875,
492,
1487,
1326,
199,
504,
5053,
6065,
14,
1531,
492,
5817,
12,
6378,
12812,
199,
504,
5053,
6065,
14,
6614,
492,
26832,
9270,
199,
646,
4613,
4388,
199,
14813,
2486,
5918,
199,
3,
7393,
51,
199,
14813,
2486,
5918,
199,
199,
533,
1379,
26,
339,
347,
511,
11447,
8,
277,
304,
267,
347,
23833,
837,
288,
1449,
288,
23833,
805,
14,
288,
1449,
398,
2088,
275,
5817,
8,
6257,
9,
267,
702,
2088,
14,
1247,
508,
788,
6257,
418,
267,
702,
2088,
14,
1802,
508,
283,
6257,
805,
3530,
398,
2088,
275,
5817,
8,
6257,
12,
1561,
534,
72,
358,
267,
702,
2088,
14,
1247,
508,
788,
72,
418,
398,
2088,
275,
5817,
8,
6257,
12,
1561,
2968,
72,
17,
297,
283,
72,
18,
1105,
267,
702,
2088,
14,
1247,
508,
788,
72,
17,
297,
283,
72,
18,
418,
7318,
347,
949,
63,
1301,
837,
288,
3087,
398,
2088,
275,
5817,
8,
889,
63,
1301,
9,
267,
702,
2088,
14,
1802,
508,
8189,
889,
1369,
3171,
2378,
347,
511,
6373,
8,
277,
304,
398,
1680,
275,
5817,
14,
6373,
360,
1273,
297,
283,
9692,
63,
11611,
63,
2711,
358,
398,
543,
4613,
14,
3536,
8,
4333,
304,
288,
1680,
14,
17324,
10730,
8,
403,
9,
2378,
347,
511,
14517,
8,
277,
304,
398,
347,
23833,
8,
6614,
3131,
1788,
12,
945,
534,
5066,
297,
949,
63,
2758,
29,
797,
12,
949,
63,
885,
29,
403,
12,
627,
888,
304,
288,
1449,
288,
23833,
805,
14,
953,
961,
365,
23833,
14,
953,
520,
635,
1788,
26,
710,
536,
402,
314,
570,
14,
288,
520,
635,
949,
63,
2758,
26,
756,
340,
663,
288,
520,
635,
949,
63,
885,
26,
799,
2375,
397,
488,
288,
520,
635,
1101,
26,
4094,
6556,
288,
1449,
288,
8559,
3754,
5375,
3508,
83,
446,
450,
83,
7,
450,
334,
1501,
12,
945,
430,
288,
359,
6614,
3754,
2081,
8,
73,
9,
367,
284,
315,
1101,
61,
398,
2088,
275,
5817,
8,
6257,
9,
267,
702,
2088,
14,
1247,
508,
788,
6257,
418,
267,
702,
2088,
14,
1802,
508,
283,
6257,
805,
3530,
398,
702,
2088,
14,
589,
14,
1612,
342,
508,
788,
6614,
14474,
283,
1501,
297,
283,
1422,
297,
283,
889,
63,
2758,
297,
283,
889,
63,
885,
297,
283,
888,
418,
267,
702,
2341,
8,
2975,
12,
2088,
14,
589,
14,
1459,
1012,
508,
359,
288,
283,
6614,
14474,
288,
283,
1501,
297,
288,
283,
1422,
29,
5066,
297,
288,
283,
889,
13,
2758,
297,
288,
283,
889,
13,
885,
29,
7041,
297,
288,
6438,
888,
7,
267,
1622,
267,
702,
2341,
8,
2722,
12,
2088,
14,
589,
14,
1459,
1012,
508,
359,
288,
2650,
6373,
8559,
63,
4206,
288,
2650,
6373,
1788,
4206,
288,
2650,
6373,
945,
29,
5066,
4206,
288,
2650,
6373,
949,
13,
2758,
4206,
288,
2650,
6373,
949,
13,
885,
29,
7041,
4206,
288,
2650,
6373,
627,
888,
4206,
267,
1622,
267,
702,
2088,
14,
958,
365,
488,
398,
8559,
275,
26832,
9270,
342,
267,
2088,
14,
2176,
8,
288,
15188,
3713,
6614,
8650,
520,
334,
2734,
26,
6614,
12,
2400,
26,
403,
16658,
288,
23846,
3713,
1501,
7,
520,
283,
4468,
14,
2424,
297,
283,
888,
7,
520,
788,
368,
297,
283,
5601,
297,
283,
10480,
12074,
267,
776,
267,
702,
8559,
14,
18614,
342,
508,
283,
4468,
14,
2424,
446,
9456,
60,
78,
13,
1373,
60,
78,
13,
2877,
60,
78,
13,
7795,
60,
78,
7,
398,
327,
20489,
7944,
1006,
3866,
2368,
3032,
370,
6523,
14,
267,
8559,
275,
26832,
9270,
342,
267,
2088,
14,
2176,
8,
288,
15188,
3713,
6614,
8650,
520,
334,
2734,
26,
6614,
12,
2400,
26,
403,
16658,
288,
23846,
3713,
1501,
7,
520,
283,
7828,
2392,
14,
2424,
297,
283,
9692,
7,
520,
283,
9692,
936,
267,
776,
267,
702,
8559,
14,
18614,
342,
508,
283,
7828,
2392,
14,
2424,
446,
9456,
60,
78,
7,
398,
543,
4613,
14,
3536,
8,
3364,
12812,
304,
288,
2088,
14,
2176,
16037,
791,
1501,
7,
520,
283,
4468,
14,
2424,
3071,
398,
543,
4613,
14,
3536,
8,
4333,
304,
288,
2088,
14,
2176,
3252,
6614,
8650,
520,
8559,
1386,
5009,
398,
702,
2088,
14,
1802,
508,
283,
6257,
805,
3530,
267,
702,
2088,
14,
2809,
63,
1802,
508,
1487,
1326,
8,
288,
1449,
288,
23833,
805,
14,
953,
961,
365,
23833,
14,
288,
1449,
267,
776,
398,
702,
2088,
14,
3484,
8673,
342,
508,
1487,
1326,
8,
288,
1449,
288,
11028,
26,
355,
23833,
665,
1501,
30,
665,
10,
888,
30,
19344,
1422,
29,
5066,
6922,
306,
889,
13,
2758,
6922,
306,
889,
13,
885,
29,
7041,
61,
953,
3897,
26,
355,
1788,
257,
710,
536,
402,
314,
570,
14,
355,
1101,
257,
4094,
6556,
953,
8394,
26,
355,
1553,
1422,
257,
334,
889,
1369,
9,
359,
885,
26,
9456,
61,
355,
1553,
889,
13,
2758,
257,
756,
340,
663,
355,
1553,
889,
13,
885,
257,
799,
2375,
397,
488,
953,
1449,
267,
776,
398,
702,
2088,
14,
3484,
8673,
342,
508,
1487,
1326,
8,
288,
1449,
288,
11028,
26,
355,
23833,
665,
1501,
30,
665,
10,
888,
30,
19344,
1422,
29,
5066,
6922,
306,
889,
13,
2758,
6922,
306,
889,
13,
885,
29,
7041,
61,
953,
3897,
26,
355,
1788,
257,
710,
536,
402,
314,
570,
14,
355,
1101,
257,
4094,
6556,
953,
8394,
26,
355,
1553,
1422,
257,
334,
889,
1369,
9,
359,
885,
26,
9456,
61,
355,
1553,
889,
13,
2758,
257,
756,
340,
663,
355,
1553,
889,
13,
885,
257,
799,
2375,
397,
488,
953,
1449,
267,
776,
398,
492,
7534,
267,
1798,
275,
7534,
14,
10730,
360,
2864,
358,
267,
2088,
14,
17324,
10730,
8,
2087,
9,
267,
702,
1798,
14,
908,
63,
3437,
342,
508,
1487,
1326,
8,
288,
1449,
288,
4503,
26,
7393,
5243,
72,
61,
19344,
1422,
11662,
1075,
61,
19344,
889,
13,
2758,
61,
19344,
889,
13,
885,
4825,
63,
3472,
61,
717,
1788,
359,
888,
359,
888,
2263,
2677,
953,
11333,
2368,
26,
1598,
1788,
1598,
1101,
953,
2716,
2368,
26,
1598,
446,
72,
12,
1553,
3437,
3322,
2498,
642,
1720
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
330,
287,
709,
14,
4214,
425,
14,
875,
492,
1487,
1326,
199,
504,
5053,
6065,
14,
1531,
492,
5817,
12,
6378,
12812,
199,
504,
5053,
6065,
14,
6614,
492,
26832,
9270,
199,
646,
4613,
4388,
199,
14813,
2486,
5918,
199,
3,
7393,
51,
199,
14813,
2486,
5918,
199,
199,
533,
1379,
26,
339,
347,
511,
11447,
8,
277,
304,
267,
347,
23833,
837,
288,
1449,
288,
23833,
805,
14,
288,
1449,
398,
2088,
275,
5817,
8,
6257,
9,
267,
702,
2088,
14,
1247,
508,
788,
6257,
418,
267,
702,
2088,
14,
1802,
508,
283,
6257,
805,
3530,
398,
2088,
275,
5817,
8,
6257,
12,
1561,
534,
72,
358,
267,
702,
2088,
14,
1247,
508,
788,
72,
418,
398,
2088,
275,
5817,
8,
6257,
12,
1561,
2968,
72,
17,
297,
283,
72,
18,
1105,
267,
702,
2088,
14,
1247,
508,
788,
72,
17,
297,
283,
72,
18,
418,
7318,
347,
949,
63,
1301,
837,
288,
3087,
398,
2088,
275,
5817,
8,
889,
63,
1301,
9,
267,
702,
2088,
14,
1802,
508,
8189,
889,
1369,
3171,
2378,
347,
511,
6373,
8,
277,
304,
398,
1680,
275,
5817,
14,
6373,
360,
1273,
297,
283,
9692,
63,
11611,
63,
2711,
358,
398,
543,
4613,
14,
3536,
8,
4333,
304,
288,
1680,
14,
17324,
10730,
8,
403,
9,
2378,
347,
511,
14517,
8,
277,
304,
398,
347,
23833,
8,
6614,
3131,
1788,
12,
945,
534,
5066,
297,
949,
63,
2758,
29,
797,
12,
949,
63,
885,
29,
403,
12,
627,
888,
304,
288,
1449,
288,
23833,
805,
14,
953,
961,
365,
23833,
14,
953,
520,
635,
1788,
26,
710,
536,
402,
314,
570,
14,
288,
520,
635,
949,
63,
2758,
26,
756,
340,
663,
288,
520,
635,
949,
63,
885,
26,
799,
2375,
397,
488,
288,
520,
635,
1101,
26,
4094,
6556,
288,
1449,
288,
8559,
3754,
5375,
3508,
83,
446,
450,
83,
7,
450,
334,
1501,
12,
945,
430,
288,
359,
6614,
3754,
2081,
8,
73,
9,
367,
284,
315,
1101,
61,
398,
2088,
275,
5817,
8,
6257,
9,
267,
702,
2088,
14,
1247,
508,
788,
6257,
418,
267,
702,
2088,
14,
1802,
508,
283,
6257,
805,
3530,
398,
702,
2088,
14,
589,
14,
1612,
342,
508,
788,
6614,
14474,
283,
1501,
297,
283,
1422,
297,
283,
889,
63,
2758,
297,
283,
889,
63,
885,
297,
283,
888,
418,
267,
702,
2341,
8,
2975,
12,
2088,
14,
589,
14,
1459,
1012,
508,
359,
288,
283,
6614,
14474,
288,
283,
1501,
297,
288,
283,
1422,
29,
5066,
297,
288,
283,
889,
13,
2758,
297,
288,
283,
889,
13,
885,
29,
7041,
297,
288,
6438,
888,
7,
267,
1622,
267,
702,
2341,
8,
2722,
12,
2088,
14,
589,
14,
1459,
1012,
508,
359,
288,
2650,
6373,
8559,
63,
4206,
288,
2650,
6373,
1788,
4206,
288,
2650,
6373,
945,
29,
5066,
4206,
288,
2650,
6373,
949,
13,
2758,
4206,
288,
2650,
6373,
949,
13,
885,
29,
7041,
4206,
288,
2650,
6373,
627,
888,
4206,
267,
1622,
267,
702,
2088,
14,
958,
365,
488,
398,
8559,
275,
26832,
9270,
342,
267,
2088,
14,
2176,
8,
288,
15188,
3713,
6614,
8650,
520,
334,
2734,
26,
6614,
12,
2400,
26,
403,
16658,
288,
23846,
3713,
1501,
7,
520,
283,
4468,
14,
2424,
297,
283,
888,
7,
520,
788,
368,
297,
283,
5601,
297,
283,
10480,
12074,
267,
776,
267,
702,
8559,
14,
18614,
342,
508,
283,
4468,
14,
2424,
446,
9456,
60,
78,
13,
1373,
60,
78,
13,
2877,
60,
78,
13,
7795,
60,
78,
7,
398,
327,
20489,
7944,
1006,
3866,
2368,
3032,
370,
6523,
14,
267,
8559,
275,
26832,
9270,
342,
267,
2088,
14,
2176,
8,
288,
15188,
3713,
6614,
8650,
520,
334,
2734,
26,
6614,
12,
2400,
26,
403,
16658,
288,
23846,
3713,
1501,
7,
520,
283,
7828,
2392,
14,
2424,
297,
283,
9692,
7,
520,
283,
9692,
936,
267,
776,
267,
702,
8559,
14,
18614,
342,
508,
283,
7828,
2392,
14,
2424,
446,
9456,
60,
78,
7,
398,
543,
4613,
14,
3536,
8,
3364,
12812,
304,
288,
2088,
14,
2176,
16037,
791,
1501,
7,
520,
283,
4468,
14,
2424,
3071,
398,
543,
4613,
14,
3536,
8,
4333,
304,
288,
2088,
14,
2176,
3252,
6614,
8650,
520,
8559,
1386,
5009,
398,
702,
2088,
14,
1802,
508,
283,
6257,
805,
3530,
267,
702,
2088,
14,
2809,
63,
1802,
508,
1487,
1326,
8,
288,
1449,
288,
23833,
805,
14,
953,
961,
365,
23833,
14,
288,
1449,
267,
776,
398,
702,
2088,
14,
3484,
8673,
342,
508,
1487,
1326,
8,
288,
1449,
288,
11028,
26,
355,
23833,
665,
1501,
30,
665,
10,
888,
30,
19344,
1422,
29,
5066,
6922,
306,
889,
13,
2758,
6922,
306,
889,
13,
885,
29,
7041,
61,
953,
3897,
26,
355,
1788,
257,
710,
536,
402,
314,
570,
14,
355,
1101,
257,
4094,
6556,
953,
8394,
26,
355,
1553,
1422,
257,
334,
889,
1369,
9,
359,
885,
26,
9456,
61,
355,
1553,
889,
13,
2758,
257,
756,
340,
663,
355,
1553,
889,
13,
885,
257,
799,
2375,
397,
488,
953,
1449,
267,
776,
398,
702,
2088,
14,
3484,
8673,
342,
508,
1487,
1326,
8,
288,
1449,
288,
11028,
26,
355,
23833,
665,
1501,
30,
665,
10,
888,
30,
19344,
1422,
29,
5066,
6922,
306,
889,
13,
2758,
6922,
306,
889,
13,
885,
29,
7041,
61,
953,
3897,
26,
355,
1788,
257,
710,
536,
402,
314,
570,
14,
355,
1101,
257,
4094,
6556,
953,
8394,
26,
355,
1553,
1422,
257,
334,
889,
1369,
9,
359,
885,
26,
9456,
61,
355,
1553,
889,
13,
2758,
257,
756,
340,
663,
355,
1553,
889,
13,
885,
257,
799,
2375,
397,
488,
953,
1449,
267,
776,
398,
492,
7534,
267,
1798,
275,
7534,
14,
10730,
360,
2864,
358,
267,
2088,
14,
17324,
10730,
8,
2087,
9,
267,
702,
1798,
14,
908,
63,
3437,
342,
508,
1487,
1326,
8,
288,
1449,
288,
4503,
26,
7393,
5243,
72,
61,
19344,
1422,
11662,
1075,
61,
19344,
889,
13,
2758,
61,
19344,
889,
13,
885,
4825,
63,
3472,
61,
717,
1788,
359,
888,
359,
888,
2263,
2677,
953,
11333,
2368,
26,
1598,
1788,
1598,
1101,
953,
2716,
2368,
26,
1598,
446,
72,
12,
1553,
3437,
3322,
2498,
642,
1720,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
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/parametertree/ParameterTree.py
|
47
|
5662
|
from ..Qt import QtCore, QtGui
from ..widgets.TreeWidget import TreeWidget
import os, weakref, re
from .ParameterItem import ParameterItem
#import functions as fn
class ParameterTree(TreeWidget):
"""Widget used to display or control data from a hierarchy of Parameters"""
def __init__(self, parent=None, showHeader=True):
"""
============== ========================================================
**Arguments:**
parent (QWidget) An optional parent widget
showHeader (bool) If True, then the QTreeView header is displayed.
============== ========================================================
"""
TreeWidget.__init__(self, parent)
self.setVerticalScrollMode(self.ScrollPerPixel)
self.setHorizontalScrollMode(self.ScrollPerPixel)
self.setAnimated(False)
self.setColumnCount(2)
self.setHeaderLabels(["Parameter", "Value"])
self.setAlternatingRowColors(True)
self.paramSet = None
self.header().setResizeMode(QtGui.QHeaderView.ResizeToContents)
self.setHeaderHidden(not showHeader)
self.itemChanged.connect(self.itemChangedEvent)
self.lastSel = None
self.setRootIsDecorated(False)
def setParameters(self, param, showTop=True):
"""
Set the top-level :class:`Parameter <pyqtgraph.parametertree.Parameter>`
to be displayed in this ParameterTree.
If *showTop* is False, then the top-level parameter is hidden and only
its children will be visible. This is a convenience method equivalent
to::
tree.clear()
tree.addParameters(param, showTop)
"""
self.clear()
self.addParameters(param, showTop=showTop)
def addParameters(self, param, root=None, depth=0, showTop=True):
"""
Adds one top-level :class:`Parameter <pyqtgraph.parametertree.Parameter>`
to the view.
============== ==========================================================
**Arguments:**
param The :class:`Parameter <pyqtgraph.parametertree.Parameter>`
to add.
root The item within the tree to which *param* should be added.
By default, *param* is added as a top-level item.
showTop If False, then *param* will be hidden, and only its
children will be visible in the tree.
============== ==========================================================
"""
item = param.makeTreeItem(depth=depth)
if root is None:
root = self.invisibleRootItem()
## Hide top-level item
if not showTop:
item.setText(0, '')
item.setSizeHint(0, QtCore.QSize(1,1))
item.setSizeHint(1, QtCore.QSize(1,1))
depth -= 1
root.addChild(item)
item.treeWidgetChanged()
for ch in param:
self.addParameters(ch, root=item, depth=depth+1)
def clear(self):
"""
Remove all parameters from the tree.
"""
self.invisibleRootItem().takeChildren()
def focusNext(self, item, forward=True):
"""Give input focus to the next (or previous) item after *item*
"""
while True:
parent = item.parent()
if parent is None:
return
nextItem = self.nextFocusableChild(parent, item, forward=forward)
if nextItem is not None:
nextItem.setFocus()
self.setCurrentItem(nextItem)
return
item = parent
def focusPrevious(self, item):
self.focusNext(item, forward=False)
def nextFocusableChild(self, root, startItem=None, forward=True):
if startItem is None:
if forward:
index = 0
else:
index = root.childCount()-1
else:
if forward:
index = root.indexOfChild(startItem) + 1
else:
index = root.indexOfChild(startItem) - 1
if forward:
inds = list(range(index, root.childCount()))
else:
inds = list(range(index, -1, -1))
for i in inds:
item = root.child(i)
if hasattr(item, 'isFocusable') and item.isFocusable():
return item
else:
item = self.nextFocusableChild(item, forward=forward)
if item is not None:
return item
return None
def contextMenuEvent(self, ev):
item = self.currentItem()
if hasattr(item, 'contextMenuEvent'):
item.contextMenuEvent(ev)
def itemChangedEvent(self, item, col):
if hasattr(item, 'columnChangedEvent'):
item.columnChangedEvent(col)
def selectionChanged(self, *args):
sel = self.selectedItems()
if len(sel) != 1:
sel = None
if self.lastSel is not None and isinstance(self.lastSel, ParameterItem):
self.lastSel.selected(False)
if sel is None:
self.lastSel = None
return
self.lastSel = sel[0]
if hasattr(sel[0], 'selected'):
sel[0].selected(True)
return TreeWidget.selectionChanged(self, *args)
def wheelEvent(self, ev):
self.clearSelection()
return TreeWidget.wheelEvent(self, ev)
|
mit
|
[
504,
2508,
4238,
492,
10565,
12,
5928,
199,
504,
2508,
8583,
14,
3987,
3339,
492,
12178,
3339,
199,
646,
747,
12,
13852,
12,
295,
199,
504,
1275,
4720,
2081,
492,
12009,
2081,
199,
3,
646,
3423,
465,
4325,
268,
1467,
199,
199,
533,
12009,
3987,
8,
3987,
3339,
304,
272,
408,
3339,
1202,
370,
2929,
503,
3304,
666,
687,
282,
14446,
402,
3897,
624,
2286,
347,
636,
826,
721,
277,
12,
1676,
29,
403,
12,
2498,
2567,
29,
549,
304,
267,
408,
267,
275,
9152,
19691,
18673,
267,
1011,
14517,
19003,
267,
1676,
260,
334,
23894,
9,
1626,
2716,
1676,
3938,
267,
2498,
2567,
258,
334,
2245,
9,
982,
715,
12,
2066,
314,
1413,
32656,
1406,
365,
9080,
14,
267,
275,
9152,
19691,
18673,
267,
408,
267,
12178,
3339,
855,
826,
721,
277,
12,
1676,
9,
267,
291,
14,
409,
19462,
13127,
1385,
8,
277,
14,
13127,
2623,
14383,
9,
267,
291,
14,
409,
19918,
13127,
1385,
8,
277,
14,
13127,
2623,
14383,
9,
267,
291,
14,
409,
2493,
12754,
8,
797,
9,
267,
291,
14,
409,
4547,
2353,
8,
18,
9,
267,
291,
14,
409,
2567,
14016,
5234,
4720,
401,
298,
1110,
3135,
267,
291,
14,
409,
19978,
1958,
5810,
20094,
8,
549,
9,
267,
291,
14,
635,
1084,
275,
488,
267,
291,
14,
1291,
1252,
409,
24559,
1385,
8,
10604,
14,
49,
2567,
2768,
14,
24559,
1378,
11383,
9,
267,
291,
14,
409,
2567,
14983,
8,
1397,
2498,
2567,
9,
267,
291,
14,
1053,
6970,
14,
2242,
8,
277,
14,
1053,
6970,
2390,
9,
267,
291,
14,
2019,
20920,
275,
488,
267,
291,
14,
409,
6405,
1831,
8584,
269,
972,
8,
797,
9,
5493,
347,
663,
5976,
8,
277,
12,
1215,
12,
2498,
6105,
29,
549,
304,
267,
408,
267,
2494,
314,
2746,
13,
1896,
520,
533,
1705,
4720,
665,
24835,
2180,
14,
5329,
2350,
14,
4720,
8637,
267,
370,
506,
9080,
315,
642,
12009,
3987,
14,
398,
982,
627,
2384,
6105,
10,
365,
756,
12,
2066,
314,
2746,
13,
1896,
2725,
365,
8752,
436,
1454,
4960,
2399,
4978,
911,
506,
8917,
14,
961,
365,
282,
16777,
1083,
7353,
4960,
370,
447,
27180,
3123,
14,
3584,
342,
288,
3123,
14,
525,
5976,
8,
635,
12,
2498,
6105,
9,
267,
408,
267,
291,
14,
3584,
342,
267,
291,
14,
525,
5976,
8,
635,
12,
2498,
6105,
29,
2384,
6105,
9,
5493,
347,
1050,
5976,
8,
277,
12,
1215,
12,
1738,
29,
403,
12,
5818,
29,
16,
12,
2498,
6105,
29,
549,
304,
267,
408,
267,
15747,
1373,
2746,
13,
1896,
520,
533,
1705,
4720,
665,
24835,
2180,
14,
5329,
2350,
14,
4720,
8637,
267,
370,
314,
2455,
14,
221,
2728,
275,
9152,
19691,
15495,
267,
1011,
14517,
19003,
4960,
1215,
3515,
710,
520,
533,
1705,
4720,
665,
24835,
2180,
14,
5329,
2350,
14,
4720,
8637,
221,
2432,
370,
1050,
14,
267,
1738,
3698,
710,
1242,
4453,
314,
3123,
370,
1314,
627,
635,
10,
1077,
506,
3483,
14,
2432,
4885,
849,
12,
627,
635,
10,
365,
3483,
465,
282,
2746,
13,
1896,
1242,
14,
267,
2498,
6105,
263,
982,
756,
12,
2066,
627,
635,
10,
911,
506,
8752,
12,
436,
1454,
2399,
221,
2432,
4978,
911,
506,
8917,
315,
314,
3123,
14,
267,
275,
9152,
19691,
15495,
267,
408,
267,
1242,
275,
1215,
14,
1875,
3987,
2081,
8,
4631,
29,
4631,
9,
267,
340,
1738,
365,
488,
26,
288,
1738,
275,
291,
14,
262,
6604,
6405,
2081,
342,
288,
925,
869,
2655,
2746,
13,
1896,
1242,
288,
340,
440,
2498,
6105,
26,
355,
1242,
14,
8341,
8,
16,
12,
4074,
355,
1242,
14,
21735,
20891,
8,
16,
12,
10565,
14,
15531,
8,
17,
12,
17,
430,
355,
1242,
14,
21735,
20891,
8,
17,
12,
10565,
14,
15531,
8,
17,
12,
17,
430,
355,
5818,
4862,
413,
267,
1738,
14,
23897,
8,
1053,
9,
267,
1242,
14,
2350,
3339,
6970,
342,
10631,
367,
682,
315,
1215,
26,
288,
291,
14,
525,
5976,
8,
335,
12,
1738,
29,
1053,
12,
5818,
29,
4631,
11,
17,
9,
339,
347,
5436,
8,
277,
304,
267,
408,
267,
5852,
1006,
2633,
687,
314,
3123,
14,
18418,
408,
267,
291,
14,
262,
6604,
6405,
2081,
1252,
11066,
7139,
342,
260,
15567,
347,
16470,
5765,
8,
277,
12,
1242,
12,
7568,
29,
549,
304,
267,
408,
39,
1912,
1324,
16470,
370,
314,
2163,
334,
269,
4136,
9,
1242,
2410,
627,
1053,
10,
267,
408,
267,
1830,
715,
26,
288,
1676,
275,
1242,
14,
1708,
342,
288,
340,
1676,
365,
488,
26,
355,
372,
288,
2163,
2081,
275,
291,
14,
2184,
17310,
461,
3493,
8,
1708,
12,
1242,
12,
7568,
29,
6688,
9,
288,
340,
2163,
2081,
365,
440,
488,
26,
355,
2163,
2081,
14,
409,
17310,
342,
355,
291,
14,
23222,
2081,
8,
2184,
2081,
9,
355,
372,
288,
1242,
275,
1676,
339,
347,
16470,
18021,
8,
277,
12,
1242,
304,
267,
291,
14,
12283,
5765,
8,
1053,
12,
7568,
29,
797,
9,
339,
347,
2163,
17310,
461,
3493,
8,
277,
12,
1738,
12,
1343,
2081,
29,
403,
12,
7568,
29,
549,
304,
267,
340,
1343,
2081,
365,
488,
26,
288,
340,
7568,
26,
355,
1478,
275,
378,
288,
587,
26,
355,
1478,
275,
1738,
14,
1739,
2353,
22251,
17,
267,
587,
26,
288,
340,
7568,
26,
355,
1478,
275,
1738,
14,
31397,
3493,
8,
928,
2081,
9,
435,
413,
288,
587,
26,
355,
1478,
275,
1738,
14,
31397,
3493,
8,
928,
2081,
9,
446,
413,
10631,
340,
7568,
26,
288,
315,
795,
275,
769,
8,
1842,
8,
1080,
12,
1738,
14,
1739,
2353,
4059,
267,
587,
26,
288,
315,
795,
275,
769,
8,
1842,
8,
1080,
12,
446,
17,
12,
446,
17,
430,
10631,
367,
284,
315,
315,
795,
26,
288,
1242,
275,
1738,
14,
1739,
8,
73,
9,
288,
340,
2688,
8,
1053,
12,
283,
374,
17310,
461,
358,
436,
1242,
14,
374,
17310,
461,
837,
355,
372,
1242,
288,
587,
26,
355,
1242,
275,
291,
14,
2184,
17310,
461,
3493,
8,
1053,
12,
7568,
29,
6688,
9,
355,
340,
1242,
365,
440,
488,
26,
490,
372,
1242,
267,
372,
488,
339,
347,
1067,
5977,
2390,
8,
277,
12,
8145,
304,
267,
1242,
275,
291,
14,
1818,
2081,
342
] |
[
2508,
4238,
492,
10565,
12,
5928,
199,
504,
2508,
8583,
14,
3987,
3339,
492,
12178,
3339,
199,
646,
747,
12,
13852,
12,
295,
199,
504,
1275,
4720,
2081,
492,
12009,
2081,
199,
3,
646,
3423,
465,
4325,
268,
1467,
199,
199,
533,
12009,
3987,
8,
3987,
3339,
304,
272,
408,
3339,
1202,
370,
2929,
503,
3304,
666,
687,
282,
14446,
402,
3897,
624,
2286,
347,
636,
826,
721,
277,
12,
1676,
29,
403,
12,
2498,
2567,
29,
549,
304,
267,
408,
267,
275,
9152,
19691,
18673,
267,
1011,
14517,
19003,
267,
1676,
260,
334,
23894,
9,
1626,
2716,
1676,
3938,
267,
2498,
2567,
258,
334,
2245,
9,
982,
715,
12,
2066,
314,
1413,
32656,
1406,
365,
9080,
14,
267,
275,
9152,
19691,
18673,
267,
408,
267,
12178,
3339,
855,
826,
721,
277,
12,
1676,
9,
267,
291,
14,
409,
19462,
13127,
1385,
8,
277,
14,
13127,
2623,
14383,
9,
267,
291,
14,
409,
19918,
13127,
1385,
8,
277,
14,
13127,
2623,
14383,
9,
267,
291,
14,
409,
2493,
12754,
8,
797,
9,
267,
291,
14,
409,
4547,
2353,
8,
18,
9,
267,
291,
14,
409,
2567,
14016,
5234,
4720,
401,
298,
1110,
3135,
267,
291,
14,
409,
19978,
1958,
5810,
20094,
8,
549,
9,
267,
291,
14,
635,
1084,
275,
488,
267,
291,
14,
1291,
1252,
409,
24559,
1385,
8,
10604,
14,
49,
2567,
2768,
14,
24559,
1378,
11383,
9,
267,
291,
14,
409,
2567,
14983,
8,
1397,
2498,
2567,
9,
267,
291,
14,
1053,
6970,
14,
2242,
8,
277,
14,
1053,
6970,
2390,
9,
267,
291,
14,
2019,
20920,
275,
488,
267,
291,
14,
409,
6405,
1831,
8584,
269,
972,
8,
797,
9,
5493,
347,
663,
5976,
8,
277,
12,
1215,
12,
2498,
6105,
29,
549,
304,
267,
408,
267,
2494,
314,
2746,
13,
1896,
520,
533,
1705,
4720,
665,
24835,
2180,
14,
5329,
2350,
14,
4720,
8637,
267,
370,
506,
9080,
315,
642,
12009,
3987,
14,
398,
982,
627,
2384,
6105,
10,
365,
756,
12,
2066,
314,
2746,
13,
1896,
2725,
365,
8752,
436,
1454,
4960,
2399,
4978,
911,
506,
8917,
14,
961,
365,
282,
16777,
1083,
7353,
4960,
370,
447,
27180,
3123,
14,
3584,
342,
288,
3123,
14,
525,
5976,
8,
635,
12,
2498,
6105,
9,
267,
408,
267,
291,
14,
3584,
342,
267,
291,
14,
525,
5976,
8,
635,
12,
2498,
6105,
29,
2384,
6105,
9,
5493,
347,
1050,
5976,
8,
277,
12,
1215,
12,
1738,
29,
403,
12,
5818,
29,
16,
12,
2498,
6105,
29,
549,
304,
267,
408,
267,
15747,
1373,
2746,
13,
1896,
520,
533,
1705,
4720,
665,
24835,
2180,
14,
5329,
2350,
14,
4720,
8637,
267,
370,
314,
2455,
14,
221,
2728,
275,
9152,
19691,
15495,
267,
1011,
14517,
19003,
4960,
1215,
3515,
710,
520,
533,
1705,
4720,
665,
24835,
2180,
14,
5329,
2350,
14,
4720,
8637,
221,
2432,
370,
1050,
14,
267,
1738,
3698,
710,
1242,
4453,
314,
3123,
370,
1314,
627,
635,
10,
1077,
506,
3483,
14,
2432,
4885,
849,
12,
627,
635,
10,
365,
3483,
465,
282,
2746,
13,
1896,
1242,
14,
267,
2498,
6105,
263,
982,
756,
12,
2066,
627,
635,
10,
911,
506,
8752,
12,
436,
1454,
2399,
221,
2432,
4978,
911,
506,
8917,
315,
314,
3123,
14,
267,
275,
9152,
19691,
15495,
267,
408,
267,
1242,
275,
1215,
14,
1875,
3987,
2081,
8,
4631,
29,
4631,
9,
267,
340,
1738,
365,
488,
26,
288,
1738,
275,
291,
14,
262,
6604,
6405,
2081,
342,
288,
925,
869,
2655,
2746,
13,
1896,
1242,
288,
340,
440,
2498,
6105,
26,
355,
1242,
14,
8341,
8,
16,
12,
4074,
355,
1242,
14,
21735,
20891,
8,
16,
12,
10565,
14,
15531,
8,
17,
12,
17,
430,
355,
1242,
14,
21735,
20891,
8,
17,
12,
10565,
14,
15531,
8,
17,
12,
17,
430,
355,
5818,
4862,
413,
267,
1738,
14,
23897,
8,
1053,
9,
267,
1242,
14,
2350,
3339,
6970,
342,
10631,
367,
682,
315,
1215,
26,
288,
291,
14,
525,
5976,
8,
335,
12,
1738,
29,
1053,
12,
5818,
29,
4631,
11,
17,
9,
339,
347,
5436,
8,
277,
304,
267,
408,
267,
5852,
1006,
2633,
687,
314,
3123,
14,
18418,
408,
267,
291,
14,
262,
6604,
6405,
2081,
1252,
11066,
7139,
342,
260,
15567,
347,
16470,
5765,
8,
277,
12,
1242,
12,
7568,
29,
549,
304,
267,
408,
39,
1912,
1324,
16470,
370,
314,
2163,
334,
269,
4136,
9,
1242,
2410,
627,
1053,
10,
267,
408,
267,
1830,
715,
26,
288,
1676,
275,
1242,
14,
1708,
342,
288,
340,
1676,
365,
488,
26,
355,
372,
288,
2163,
2081,
275,
291,
14,
2184,
17310,
461,
3493,
8,
1708,
12,
1242,
12,
7568,
29,
6688,
9,
288,
340,
2163,
2081,
365,
440,
488,
26,
355,
2163,
2081,
14,
409,
17310,
342,
355,
291,
14,
23222,
2081,
8,
2184,
2081,
9,
355,
372,
288,
1242,
275,
1676,
339,
347,
16470,
18021,
8,
277,
12,
1242,
304,
267,
291,
14,
12283,
5765,
8,
1053,
12,
7568,
29,
797,
9,
339,
347,
2163,
17310,
461,
3493,
8,
277,
12,
1738,
12,
1343,
2081,
29,
403,
12,
7568,
29,
549,
304,
267,
340,
1343,
2081,
365,
488,
26,
288,
340,
7568,
26,
355,
1478,
275,
378,
288,
587,
26,
355,
1478,
275,
1738,
14,
1739,
2353,
22251,
17,
267,
587,
26,
288,
340,
7568,
26,
355,
1478,
275,
1738,
14,
31397,
3493,
8,
928,
2081,
9,
435,
413,
288,
587,
26,
355,
1478,
275,
1738,
14,
31397,
3493,
8,
928,
2081,
9,
446,
413,
10631,
340,
7568,
26,
288,
315,
795,
275,
769,
8,
1842,
8,
1080,
12,
1738,
14,
1739,
2353,
4059,
267,
587,
26,
288,
315,
795,
275,
769,
8,
1842,
8,
1080,
12,
446,
17,
12,
446,
17,
430,
10631,
367,
284,
315,
315,
795,
26,
288,
1242,
275,
1738,
14,
1739,
8,
73,
9,
288,
340,
2688,
8,
1053,
12,
283,
374,
17310,
461,
358,
436,
1242,
14,
374,
17310,
461,
837,
355,
372,
1242,
288,
587,
26,
355,
1242,
275,
291,
14,
2184,
17310,
461,
3493,
8,
1053,
12,
7568,
29,
6688,
9,
355,
340,
1242,
365,
440,
488,
26,
490,
372,
1242,
267,
372,
488,
339,
347,
1067,
5977,
2390,
8,
277,
12,
8145,
304,
267,
1242,
275,
291,
14,
1818,
2081,
342,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
louyihua/edx-platform
|
lms/djangoapps/instructor/tests/test_services.py
|
4
|
5481
|
"""
Tests for the InstructorService
"""
import json
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from courseware.models import StudentModule
from instructor.access import allow_access
from instructor.services import InstructorService
from instructor.tests.test_tools import msk_from_problem_urlname
from nose.plugins.attrib import attr
from student.models import CourseEnrollment
from student.tests.factories import UserFactory
import mock
@attr(shard=1)
class InstructorServiceTests(SharedModuleStoreTestCase):
"""
Tests for the InstructorService
"""
@classmethod
def setUpClass(cls):
super(InstructorServiceTests, cls).setUpClass()
cls.course = CourseFactory.create()
cls.problem_location = msk_from_problem_urlname(
cls.course.id,
'robot-some-problem-urlname'
)
cls.other_problem_location = msk_from_problem_urlname(
cls.course.id,
'robot-some-other_problem-urlname'
)
cls.problem_urlname = unicode(cls.problem_location)
cls.other_problem_urlname = unicode(cls.other_problem_location)
def setUp(self):
super(InstructorServiceTests, self).setUp()
self.student = UserFactory()
CourseEnrollment.enroll(self.student, self.course.id)
self.service = InstructorService()
self.module_to_reset = StudentModule.objects.create(
student=self.student,
course_id=self.course.id,
module_state_key=self.problem_location,
state=json.dumps({'attempts': 2}),
)
def test_reset_student_attempts_delete(self):
"""
Test delete student state.
"""
# make sure the attempt is there
self.assertEqual(
StudentModule.objects.filter(
student=self.module_to_reset.student,
course_id=self.course.id,
module_state_key=self.module_to_reset.module_state_key,
).count(),
1
)
self.service.delete_student_attempt(
self.student.username,
unicode(self.course.id),
self.problem_urlname,
requesting_user=self.student,
)
# make sure the module has been deleted
self.assertEqual(
StudentModule.objects.filter(
student=self.module_to_reset.student,
course_id=self.course.id,
module_state_key=self.module_to_reset.module_state_key,
).count(),
0
)
def test_reset_bad_content_id(self):
"""
Negative test of trying to reset attempts with bad content_id
"""
result = self.service.delete_student_attempt(
self.student.username,
unicode(self.course.id),
'foo/bar/baz',
requesting_user=self.student,
)
self.assertIsNone(result)
def test_reset_bad_user(self):
"""
Negative test of trying to reset attempts with bad user identifier
"""
result = self.service.delete_student_attempt(
'bad_student',
unicode(self.course.id),
'foo/bar/baz',
requesting_user=self.student,
)
self.assertIsNone(result)
def test_reset_non_existing_attempt(self):
"""
Negative test of trying to reset attempts with bad user identifier
"""
result = self.service.delete_student_attempt(
self.student.username,
unicode(self.course.id),
self.other_problem_urlname,
requesting_user=self.student,
)
self.assertIsNone(result)
def test_is_user_staff(self):
"""
Test to assert that the user is staff or not
"""
result = self.service.is_course_staff(
self.student,
unicode(self.course.id)
)
self.assertFalse(result)
# allow staff access to the student
allow_access(self.course, self.student, 'staff')
result = self.service.is_course_staff(
self.student,
unicode(self.course.id)
)
self.assertTrue(result)
def test_report_suspicious_attempt(self):
"""
Test to verify that the create_zendesk_ticket() is called
"""
requester_name = "edx-proctoring"
email = "edx-proctoring@edx.org"
subject = "Proctored Exam Review: {review_status}".format(review_status="Suspicious")
body = "A proctored exam attempt for {exam_name} in {course_name} by username: {student_username} was " \
"reviewed as {review_status} by the proctored exam review provider."
body = body.format(
exam_name="test_exam", course_name=self.course.display_name, student_username="test_student",
review_status="Suspicious"
)
tags = ["proctoring"]
with mock.patch("instructor.services.create_zendesk_ticket") as mock_create_zendesk_ticket:
self.service.send_support_notification(
course_id=unicode(self.course.id),
exam_name="test_exam",
student_username="test_student",
review_status="Suspicious"
)
mock_create_zendesk_ticket.assert_called_with(requester_name, email, subject, body, tags)
|
agpl-3.0
|
[
624,
199,
2925,
367,
314,
26150,
3167,
199,
624,
199,
199,
646,
2022,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
23752,
27863,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
17862,
199,
504,
20736,
14,
992,
492,
17246,
2377,
199,
504,
17724,
14,
2732,
492,
2040,
63,
2732,
199,
504,
17724,
14,
5950,
492,
26150,
3167,
199,
504,
17724,
14,
2219,
14,
396,
63,
2537,
492,
333,
1339,
63,
504,
63,
6462,
63,
633,
354,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
504,
6474,
14,
992,
492,
18946,
199,
504,
6474,
14,
2219,
14,
15406,
492,
16047,
199,
646,
1683,
421,
199,
32,
962,
8,
10810,
29,
17,
9,
199,
533,
26150,
3167,
2925,
8,
12197,
27863,
304,
272,
408,
272,
6496,
367,
314,
26150,
3167,
272,
408,
272,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
1613,
8,
30742,
3167,
2925,
12,
843,
680,
27777,
342,
267,
843,
14,
1972,
275,
17862,
14,
981,
342,
267,
843,
14,
6462,
63,
1985,
275,
333,
1339,
63,
504,
63,
6462,
63,
633,
354,
8,
288,
843,
14,
1972,
14,
344,
12,
288,
283,
9751,
13,
3972,
13,
6462,
13,
633,
354,
7,
267,
776,
267,
843,
14,
1848,
63,
6462,
63,
1985,
275,
333,
1339,
63,
504,
63,
6462,
63,
633,
354,
8,
288,
843,
14,
1972,
14,
344,
12,
288,
283,
9751,
13,
3972,
13,
1848,
63,
6462,
13,
633,
354,
7,
267,
776,
267,
843,
14,
6462,
63,
633,
354,
275,
2649,
8,
1886,
14,
6462,
63,
1985,
9,
267,
843,
14,
1848,
63,
6462,
63,
633,
354,
275,
2649,
8,
1886,
14,
1848,
63,
6462,
63,
1985,
9,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
30742,
3167,
2925,
12,
291,
680,
5996,
342,
398,
291,
14,
5500,
275,
16047,
342,
267,
18946,
14,
14695,
8,
277,
14,
5500,
12,
291,
14,
1972,
14,
344,
9,
398,
291,
14,
1364,
275,
26150,
3167,
342,
267,
291,
14,
578,
63,
475,
63,
3958,
275,
17246,
2377,
14,
1462,
14,
981,
8,
288,
6474,
29,
277,
14,
5500,
12,
288,
2518,
63,
344,
29,
277,
14,
1972,
14,
344,
12,
288,
859,
63,
929,
63,
498,
29,
277,
14,
6462,
63,
1985,
12,
288,
1174,
29,
1001,
14,
4180,
3252,
13143,
356,
499,
8688,
267,
776,
339,
347,
511,
63,
3958,
63,
5500,
63,
13143,
63,
1807,
8,
277,
304,
267,
408,
267,
1379,
3145,
6474,
1174,
14,
267,
408,
398,
327,
1852,
3238,
314,
7427,
365,
2337,
267,
291,
14,
629,
8,
288,
17246,
2377,
14,
1462,
14,
1541,
8,
355,
6474,
29,
277,
14,
578,
63,
475,
63,
3958,
14,
5500,
12,
355,
2518,
63,
344,
29,
277,
14,
1972,
14,
344,
12,
355,
859,
63,
929,
63,
498,
29,
277,
14,
578,
63,
475,
63,
3958,
14,
578,
63,
929,
63,
498,
12,
288,
7092,
835,
1062,
288,
413,
267,
776,
398,
291,
14,
1364,
14,
1807,
63,
5500,
63,
16880,
8,
288,
291,
14,
5500,
14,
2473,
12,
288,
2649,
8,
277,
14,
1972,
14,
344,
395,
288,
291,
14,
6462,
63,
633,
354,
12,
288,
23502,
63,
751,
29,
277,
14,
5500,
12,
267,
776,
398,
327,
1852,
3238,
314,
859,
965,
2757,
5463,
267,
291,
14,
629,
8,
288,
17246,
2377,
14,
1462,
14,
1541,
8,
355,
6474,
29,
277,
14,
578,
63,
475,
63,
3958,
14,
5500,
12,
355,
2518,
63,
344,
29,
277,
14,
1972,
14,
344,
12,
355,
859,
63,
929,
63,
498,
29,
277,
14,
578,
63,
475,
63,
3958,
14,
578,
63,
929,
63,
498,
12,
288,
7092,
835,
1062,
288,
378,
267,
776,
339,
347,
511,
63,
3958,
63,
4087,
63,
1317,
63,
344,
8,
277,
304,
267,
408,
267,
32548,
511,
402,
9936,
370,
5305,
12454,
543,
4875,
1564,
63,
344,
267,
408,
398,
754,
275,
291,
14,
1364,
14,
1807,
63,
5500,
63,
16880,
8,
288,
291,
14,
5500,
14,
2473,
12,
288,
2649,
8,
277,
14,
1972,
14,
344,
395,
288,
283,
1421,
15,
1700,
15,
6185,
297,
288,
23502,
63,
751,
29,
277,
14,
5500,
12,
267,
776,
267,
291,
14,
7702,
8,
1099,
9,
339,
347,
511,
63,
3958,
63,
4087,
63,
751,
8,
277,
304,
267,
408,
267,
32548,
511,
402,
9936,
370,
5305,
12454,
543,
4875,
922,
5148,
267,
408,
398,
754,
275,
291,
14,
1364,
14,
1807,
63,
5500,
63,
16880,
8,
288,
283,
4087,
63,
5500,
297,
288,
2649,
8,
277,
14,
1972,
14,
344,
395,
288,
283,
1421,
15,
1700,
15,
6185,
297,
288,
23502,
63,
751,
29,
277,
14,
5500,
12,
267,
776,
267,
291,
14,
7702,
8,
1099,
9,
339,
347,
511,
63,
3958,
63,
2865,
63,
5952,
63,
16880,
8,
277,
304,
267,
408,
267,
32548,
511,
402,
9936,
370,
5305,
12454,
543,
4875,
922,
5148,
267,
408,
398,
754,
275,
291,
14,
1364,
14,
1807,
63,
5500,
63,
16880,
8,
288,
291,
14,
5500,
14,
2473,
12,
288,
2649,
8,
277,
14,
1972,
14,
344,
395,
288,
291,
14,
1848,
63,
6462,
63,
633,
354,
12,
288,
23502,
63,
751,
29,
277,
14,
5500,
12,
267,
776,
267,
291,
14,
7702,
8,
1099,
9,
339,
347,
511,
63,
374,
63,
751,
63,
7018,
8,
277,
304,
267,
408,
267,
1379,
370,
702,
626,
314,
922,
365,
12622,
503,
440,
267,
408,
267,
754,
275,
291,
14,
1364,
14,
374,
63,
1972,
63,
7018,
8,
288,
291,
14,
5500,
12,
288,
2649,
8,
277,
14,
1972,
14,
344,
9,
267,
776,
267,
291,
14,
3334,
8,
1099,
9,
398,
327,
2040,
12622,
2879,
370,
314,
6474,
267,
2040,
63,
2732,
8,
277,
14,
1972,
12,
291,
14,
5500,
12,
283,
7018,
358,
267,
754,
275,
291,
14,
1364,
14,
374,
63,
1972,
63,
7018,
8,
288,
291,
14,
5500,
12,
288,
2649,
8,
277,
14,
1972,
14,
344,
9,
267,
776,
267,
291,
14,
1815,
8,
1099,
9,
339,
347,
511,
63,
3070,
63,
25253,
26904,
63,
16880,
8,
277,
304,
267,
408,
267,
1379,
370,
4911,
626,
314,
1218,
63,
5193,
10368,
63,
9201,
342,
365,
2797,
267,
408,
267,
295,
18246,
63,
354,
275,
298
] |
[
199,
2925,
367,
314,
26150,
3167,
199,
624,
199,
199,
646,
2022,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
23752,
27863,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
17862,
199,
504,
20736,
14,
992,
492,
17246,
2377,
199,
504,
17724,
14,
2732,
492,
2040,
63,
2732,
199,
504,
17724,
14,
5950,
492,
26150,
3167,
199,
504,
17724,
14,
2219,
14,
396,
63,
2537,
492,
333,
1339,
63,
504,
63,
6462,
63,
633,
354,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
504,
6474,
14,
992,
492,
18946,
199,
504,
6474,
14,
2219,
14,
15406,
492,
16047,
199,
646,
1683,
421,
199,
32,
962,
8,
10810,
29,
17,
9,
199,
533,
26150,
3167,
2925,
8,
12197,
27863,
304,
272,
408,
272,
6496,
367,
314,
26150,
3167,
272,
408,
272,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
1613,
8,
30742,
3167,
2925,
12,
843,
680,
27777,
342,
267,
843,
14,
1972,
275,
17862,
14,
981,
342,
267,
843,
14,
6462,
63,
1985,
275,
333,
1339,
63,
504,
63,
6462,
63,
633,
354,
8,
288,
843,
14,
1972,
14,
344,
12,
288,
283,
9751,
13,
3972,
13,
6462,
13,
633,
354,
7,
267,
776,
267,
843,
14,
1848,
63,
6462,
63,
1985,
275,
333,
1339,
63,
504,
63,
6462,
63,
633,
354,
8,
288,
843,
14,
1972,
14,
344,
12,
288,
283,
9751,
13,
3972,
13,
1848,
63,
6462,
13,
633,
354,
7,
267,
776,
267,
843,
14,
6462,
63,
633,
354,
275,
2649,
8,
1886,
14,
6462,
63,
1985,
9,
267,
843,
14,
1848,
63,
6462,
63,
633,
354,
275,
2649,
8,
1886,
14,
1848,
63,
6462,
63,
1985,
9,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
30742,
3167,
2925,
12,
291,
680,
5996,
342,
398,
291,
14,
5500,
275,
16047,
342,
267,
18946,
14,
14695,
8,
277,
14,
5500,
12,
291,
14,
1972,
14,
344,
9,
398,
291,
14,
1364,
275,
26150,
3167,
342,
267,
291,
14,
578,
63,
475,
63,
3958,
275,
17246,
2377,
14,
1462,
14,
981,
8,
288,
6474,
29,
277,
14,
5500,
12,
288,
2518,
63,
344,
29,
277,
14,
1972,
14,
344,
12,
288,
859,
63,
929,
63,
498,
29,
277,
14,
6462,
63,
1985,
12,
288,
1174,
29,
1001,
14,
4180,
3252,
13143,
356,
499,
8688,
267,
776,
339,
347,
511,
63,
3958,
63,
5500,
63,
13143,
63,
1807,
8,
277,
304,
267,
408,
267,
1379,
3145,
6474,
1174,
14,
267,
408,
398,
327,
1852,
3238,
314,
7427,
365,
2337,
267,
291,
14,
629,
8,
288,
17246,
2377,
14,
1462,
14,
1541,
8,
355,
6474,
29,
277,
14,
578,
63,
475,
63,
3958,
14,
5500,
12,
355,
2518,
63,
344,
29,
277,
14,
1972,
14,
344,
12,
355,
859,
63,
929,
63,
498,
29,
277,
14,
578,
63,
475,
63,
3958,
14,
578,
63,
929,
63,
498,
12,
288,
7092,
835,
1062,
288,
413,
267,
776,
398,
291,
14,
1364,
14,
1807,
63,
5500,
63,
16880,
8,
288,
291,
14,
5500,
14,
2473,
12,
288,
2649,
8,
277,
14,
1972,
14,
344,
395,
288,
291,
14,
6462,
63,
633,
354,
12,
288,
23502,
63,
751,
29,
277,
14,
5500,
12,
267,
776,
398,
327,
1852,
3238,
314,
859,
965,
2757,
5463,
267,
291,
14,
629,
8,
288,
17246,
2377,
14,
1462,
14,
1541,
8,
355,
6474,
29,
277,
14,
578,
63,
475,
63,
3958,
14,
5500,
12,
355,
2518,
63,
344,
29,
277,
14,
1972,
14,
344,
12,
355,
859,
63,
929,
63,
498,
29,
277,
14,
578,
63,
475,
63,
3958,
14,
578,
63,
929,
63,
498,
12,
288,
7092,
835,
1062,
288,
378,
267,
776,
339,
347,
511,
63,
3958,
63,
4087,
63,
1317,
63,
344,
8,
277,
304,
267,
408,
267,
32548,
511,
402,
9936,
370,
5305,
12454,
543,
4875,
1564,
63,
344,
267,
408,
398,
754,
275,
291,
14,
1364,
14,
1807,
63,
5500,
63,
16880,
8,
288,
291,
14,
5500,
14,
2473,
12,
288,
2649,
8,
277,
14,
1972,
14,
344,
395,
288,
283,
1421,
15,
1700,
15,
6185,
297,
288,
23502,
63,
751,
29,
277,
14,
5500,
12,
267,
776,
267,
291,
14,
7702,
8,
1099,
9,
339,
347,
511,
63,
3958,
63,
4087,
63,
751,
8,
277,
304,
267,
408,
267,
32548,
511,
402,
9936,
370,
5305,
12454,
543,
4875,
922,
5148,
267,
408,
398,
754,
275,
291,
14,
1364,
14,
1807,
63,
5500,
63,
16880,
8,
288,
283,
4087,
63,
5500,
297,
288,
2649,
8,
277,
14,
1972,
14,
344,
395,
288,
283,
1421,
15,
1700,
15,
6185,
297,
288,
23502,
63,
751,
29,
277,
14,
5500,
12,
267,
776,
267,
291,
14,
7702,
8,
1099,
9,
339,
347,
511,
63,
3958,
63,
2865,
63,
5952,
63,
16880,
8,
277,
304,
267,
408,
267,
32548,
511,
402,
9936,
370,
5305,
12454,
543,
4875,
922,
5148,
267,
408,
398,
754,
275,
291,
14,
1364,
14,
1807,
63,
5500,
63,
16880,
8,
288,
291,
14,
5500,
14,
2473,
12,
288,
2649,
8,
277,
14,
1972,
14,
344,
395,
288,
291,
14,
1848,
63,
6462,
63,
633,
354,
12,
288,
23502,
63,
751,
29,
277,
14,
5500,
12,
267,
776,
267,
291,
14,
7702,
8,
1099,
9,
339,
347,
511,
63,
374,
63,
751,
63,
7018,
8,
277,
304,
267,
408,
267,
1379,
370,
702,
626,
314,
922,
365,
12622,
503,
440,
267,
408,
267,
754,
275,
291,
14,
1364,
14,
374,
63,
1972,
63,
7018,
8,
288,
291,
14,
5500,
12,
288,
2649,
8,
277,
14,
1972,
14,
344,
9,
267,
776,
267,
291,
14,
3334,
8,
1099,
9,
398,
327,
2040,
12622,
2879,
370,
314,
6474,
267,
2040,
63,
2732,
8,
277,
14,
1972,
12,
291,
14,
5500,
12,
283,
7018,
358,
267,
754,
275,
291,
14,
1364,
14,
374,
63,
1972,
63,
7018,
8,
288,
291,
14,
5500,
12,
288,
2649,
8,
277,
14,
1972,
14,
344,
9,
267,
776,
267,
291,
14,
1815,
8,
1099,
9,
339,
347,
511,
63,
3070,
63,
25253,
26904,
63,
16880,
8,
277,
304,
267,
408,
267,
1379,
370,
4911,
626,
314,
1218,
63,
5193,
10368,
63,
9201,
342,
365,
2797,
267,
408,
267,
295,
18246,
63,
354,
275,
298,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
Ayub-Khan/edx-platform
|
cms/djangoapps/contentstore/push_notification.py
|
154
|
2772
|
"""
Helper methods for push notifications from Studio.
"""
from uuid import uuid4
from django.conf import settings
from logging import exception as log_exception
from contentstore.tasks import push_course_update_task
from contentstore.models import PushNotificationConfig
from xmodule.modulestore.django import modulestore
from parse_rest.installation import Push
from parse_rest.connection import register
from parse_rest.core import ParseError
def push_notification_enabled():
"""
Returns whether the push notification feature is enabled.
"""
return PushNotificationConfig.is_enabled()
def enqueue_push_course_update(update, course_key):
"""
Enqueues a task for push notification for the given update for the given course if
(1) the feature is enabled and
(2) push_notification is selected for the update
"""
if push_notification_enabled() and update.get("push_notification_selected"):
course = modulestore().get_course(course_key)
if course:
push_course_update_task.delay(
unicode(course_key),
course.clean_id(padding_char='_'),
course.display_name
)
def send_push_course_update(course_key_string, course_subscription_id, course_display_name):
"""
Sends a push notification for a course update, given the course's subscription_id and display_name.
"""
if settings.PARSE_KEYS:
try:
register(
settings.PARSE_KEYS["APPLICATION_ID"],
settings.PARSE_KEYS["REST_API_KEY"],
)
push_payload = {
"action": "course.announcement",
"notification-id": unicode(uuid4()),
"course-id": course_key_string,
"course-name": course_display_name,
}
push_channels = [course_subscription_id]
# Push to all Android devices
Push.alert(
data=push_payload,
channels={"$in": push_channels},
where={"deviceType": "android"},
)
# Push to all iOS devices
# With additional payload so that
# 1. The push is displayed automatically
# 2. The app gets it even in the background.
# See http://stackoverflow.com/questions/19239737/silent-push-notification-in-ios-7-does-not-work
push_payload.update({
"alert": "",
"content-available": 1
})
Push.alert(
data=push_payload,
channels={"$in": push_channels},
where={"deviceType": "ios"},
)
except ParseError as error:
log_exception(error.message)
|
agpl-3.0
|
[
624,
199,
4433,
3102,
367,
6675,
13116,
687,
13225,
14,
199,
624,
199,
199,
504,
5377,
492,
5377,
20,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
2050,
492,
1919,
465,
943,
63,
1971,
199,
199,
504,
23061,
14,
5054,
492,
6675,
63,
1972,
63,
873,
63,
1765,
199,
504,
23061,
14,
992,
492,
22643,
11598,
2028,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
2198,
63,
3911,
14,
23048,
492,
22643,
199,
504,
2198,
63,
3911,
14,
2105,
492,
2274,
199,
504,
2198,
63,
3911,
14,
1018,
492,
21743,
421,
199,
318,
6675,
63,
6761,
63,
3827,
837,
272,
408,
272,
1803,
3775,
314,
6675,
6955,
3878,
365,
5223,
14,
272,
408,
272,
372,
22643,
11598,
2028,
14,
374,
63,
3827,
342,
421,
199,
318,
14892,
63,
5335,
63,
1972,
63,
873,
8,
873,
12,
2518,
63,
498,
304,
272,
408,
272,
3447,
18849,
282,
2120,
367,
6675,
6955,
367,
314,
1627,
1678,
367,
314,
1627,
2518,
340,
489,
334,
17,
9,
314,
3878,
365,
5223,
436,
489,
334,
18,
9,
6675,
63,
6761,
365,
4895,
367,
314,
1678,
272,
408,
272,
340,
6675,
63,
6761,
63,
3827,
342,
436,
1678,
14,
362,
480,
5335,
63,
6761,
63,
5511,
2349,
267,
2518,
275,
10996,
1252,
362,
63,
1972,
8,
1972,
63,
498,
9,
267,
340,
2518,
26,
288,
6675,
63,
1972,
63,
873,
63,
1765,
14,
5814,
8,
355,
2649,
8,
1972,
63,
498,
395,
355,
2518,
14,
3118,
63,
344,
8,
8358,
63,
1560,
17574,
659,
355,
2518,
14,
2918,
63,
354,
288,
776,
421,
199,
318,
3222,
63,
5335,
63,
1972,
63,
873,
8,
1972,
63,
498,
63,
875,
12,
2518,
63,
6645,
63,
344,
12,
2518,
63,
2918,
63,
354,
304,
272,
408,
272,
428,
3198,
282,
6675,
6955,
367,
282,
2518,
1678,
12,
1627,
314,
2518,
1159,
9966,
63,
344,
436,
2929,
63,
354,
14,
272,
408,
272,
340,
2202,
14,
23354,
63,
17434,
26,
267,
862,
26,
288,
2274,
8,
355,
2202,
14,
23354,
63,
17434,
905,
24051,
63,
998,
2255,
355,
2202,
14,
23354,
63,
17434,
905,
15740,
63,
3735,
63,
3078,
2255,
288,
776,
288,
6675,
63,
4749,
275,
469,
355,
298,
1287,
582,
298,
1972,
14,
17803,
434,
401,
355,
298,
6761,
13,
344,
582,
2649,
8,
2580,
20,
4000,
2234,
298,
1972,
13,
344,
582,
2518,
63,
498,
63,
875,
12,
355,
298,
1972,
13,
354,
582,
2518,
63,
2918,
63,
354,
12,
288,
789,
288,
6675,
63,
6324,
275,
359,
1972,
63,
6645,
63,
344,
61,
953,
327,
22643,
370,
1006,
14694,
7256,
288,
22643,
14,
9241,
8,
355,
666,
29,
5335,
63,
4749,
12,
355,
9245,
8871,
4,
262,
582,
6675,
63,
6324,
1386,
355,
2382,
8871,
1782,
804,
582,
298,
6238,
6018,
288,
776,
953,
327,
22643,
370,
1006,
284,
3100,
7256,
288,
327,
8777,
4722,
4886,
880,
626,
288,
327,
413,
14,
710,
6675,
365,
9080,
5847,
288,
327,
499,
14,
710,
1145,
7545,
652,
2755,
315,
314,
8020,
14,
288,
327,
1666,
1455,
921,
23153,
14,
957,
15,
16069,
15,
5756,
13145,
1401,
15,
14434,
13,
5335,
13,
6761,
13,
262,
13,
9207,
13,
23,
13,
9105,
13,
1397,
13,
800,
288,
6675,
63,
4749,
14,
873,
2561,
355,
298,
9241,
582,
4873,
355,
298,
1317,
13,
4561,
582,
413,
288,
3828,
288,
22643,
14,
9241,
8,
355,
666,
29,
5335,
63,
4749,
12,
355,
9245,
8871,
4,
262,
582,
6675,
63,
6324,
1386,
355,
2382,
8871,
1782,
804,
582,
298,
9207,
6018,
288,
776,
398,
871,
21743,
465,
1125,
26,
288,
943,
63,
1971,
8,
705,
14,
1188,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
4433,
3102,
367,
6675,
13116,
687,
13225,
14,
199,
624,
199,
199,
504,
5377,
492,
5377,
20,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
2050,
492,
1919,
465,
943,
63,
1971,
199,
199,
504,
23061,
14,
5054,
492,
6675,
63,
1972,
63,
873,
63,
1765,
199,
504,
23061,
14,
992,
492,
22643,
11598,
2028,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
2198,
63,
3911,
14,
23048,
492,
22643,
199,
504,
2198,
63,
3911,
14,
2105,
492,
2274,
199,
504,
2198,
63,
3911,
14,
1018,
492,
21743,
421,
199,
318,
6675,
63,
6761,
63,
3827,
837,
272,
408,
272,
1803,
3775,
314,
6675,
6955,
3878,
365,
5223,
14,
272,
408,
272,
372,
22643,
11598,
2028,
14,
374,
63,
3827,
342,
421,
199,
318,
14892,
63,
5335,
63,
1972,
63,
873,
8,
873,
12,
2518,
63,
498,
304,
272,
408,
272,
3447,
18849,
282,
2120,
367,
6675,
6955,
367,
314,
1627,
1678,
367,
314,
1627,
2518,
340,
489,
334,
17,
9,
314,
3878,
365,
5223,
436,
489,
334,
18,
9,
6675,
63,
6761,
365,
4895,
367,
314,
1678,
272,
408,
272,
340,
6675,
63,
6761,
63,
3827,
342,
436,
1678,
14,
362,
480,
5335,
63,
6761,
63,
5511,
2349,
267,
2518,
275,
10996,
1252,
362,
63,
1972,
8,
1972,
63,
498,
9,
267,
340,
2518,
26,
288,
6675,
63,
1972,
63,
873,
63,
1765,
14,
5814,
8,
355,
2649,
8,
1972,
63,
498,
395,
355,
2518,
14,
3118,
63,
344,
8,
8358,
63,
1560,
17574,
659,
355,
2518,
14,
2918,
63,
354,
288,
776,
421,
199,
318,
3222,
63,
5335,
63,
1972,
63,
873,
8,
1972,
63,
498,
63,
875,
12,
2518,
63,
6645,
63,
344,
12,
2518,
63,
2918,
63,
354,
304,
272,
408,
272,
428,
3198,
282,
6675,
6955,
367,
282,
2518,
1678,
12,
1627,
314,
2518,
1159,
9966,
63,
344,
436,
2929,
63,
354,
14,
272,
408,
272,
340,
2202,
14,
23354,
63,
17434,
26,
267,
862,
26,
288,
2274,
8,
355,
2202,
14,
23354,
63,
17434,
905,
24051,
63,
998,
2255,
355,
2202,
14,
23354,
63,
17434,
905,
15740,
63,
3735,
63,
3078,
2255,
288,
776,
288,
6675,
63,
4749,
275,
469,
355,
298,
1287,
582,
298,
1972,
14,
17803,
434,
401,
355,
298,
6761,
13,
344,
582,
2649,
8,
2580,
20,
4000,
2234,
298,
1972,
13,
344,
582,
2518,
63,
498,
63,
875,
12,
355,
298,
1972,
13,
354,
582,
2518,
63,
2918,
63,
354,
12,
288,
789,
288,
6675,
63,
6324,
275,
359,
1972,
63,
6645,
63,
344,
61,
953,
327,
22643,
370,
1006,
14694,
7256,
288,
22643,
14,
9241,
8,
355,
666,
29,
5335,
63,
4749,
12,
355,
9245,
8871,
4,
262,
582,
6675,
63,
6324,
1386,
355,
2382,
8871,
1782,
804,
582,
298,
6238,
6018,
288,
776,
953,
327,
22643,
370,
1006,
284,
3100,
7256,
288,
327,
8777,
4722,
4886,
880,
626,
288,
327,
413,
14,
710,
6675,
365,
9080,
5847,
288,
327,
499,
14,
710,
1145,
7545,
652,
2755,
315,
314,
8020,
14,
288,
327,
1666,
1455,
921,
23153,
14,
957,
15,
16069,
15,
5756,
13145,
1401,
15,
14434,
13,
5335,
13,
6761,
13,
262,
13,
9207,
13,
23,
13,
9105,
13,
1397,
13,
800,
288,
6675,
63,
4749,
14,
873,
2561,
355,
298,
9241,
582,
4873,
355,
298,
1317,
13,
4561,
582,
413,
288,
3828,
288,
22643,
14,
9241,
8,
355,
666,
29,
5335,
63,
4749,
12,
355,
9245,
8871,
4,
262,
582,
6675,
63,
6324,
1386,
355,
2382,
8871,
1782,
804,
582,
298,
9207,
6018,
288,
776,
398,
871,
21743,
465,
1125,
26,
288,
943,
63,
1971,
8,
705,
14,
1188,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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right 2016 F5 Networks Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'status': ['preview'],
'supported_by': 'community',
'version': '1.0'}
DOCUMENTATION = '''
---
module: bigip_sys_db
short_description: Manage BIG-IP system database variables
description:
- Manage BIG-IP system database variables
version_added: "2.2"
options:
key:
description:
- The database variable to manipulate.
required: true
state:
description:
- The state of the variable on the system. When C(present), guarantees
that an existing variable is set to C(value). When C(reset) sets the
variable back to the default value. At least one of value and state
C(reset) are required.
required: false
default: present
choices:
- present
- reset
value:
description:
- The value to set the key to. At least one of value and state C(reset)
are required.
required: false
notes:
- Requires the f5-sdk Python package on the host. This is as easy as pip
install f5-sdk.
- Requires BIG-IP version 12.0.0 or greater
extends_documentation_fragment: f5
requirements:
- f5-sdk
author:
- Tim Rupp (@caphrim007)
'''
EXAMPLES = '''
- name: Set the boot.quiet DB variable on the BIG-IP
bigip_sys_db:
user: "admin"
password: "secret"
server: "lb.mydomain.com"
key: "boot.quiet"
value: "disable"
delegate_to: localhost
- name: Disable the initial setup screen
bigip_sys_db:
user: "admin"
password: "secret"
server: "lb.mydomain.com"
key: "setup.run"
value: "false"
delegate_to: localhost
- name: Reset the initial setup screen
bigip_sys_db:
user: "admin"
password: "secret"
server: "lb.mydomain.com"
key: "setup.run"
state: "reset"
delegate_to: localhost
'''
RETURN = '''
name:
description: The key in the system database that was specified
returned: changed and success
type: string
sample: "setup.run"
default_value:
description: The default value of the key
returned: changed and success
type: string
sample: "true"
value:
description: The value that you set the key to
returned: changed and success
type: string
sample: "false"
'''
try:
from f5.bigip import ManagementRoot
HAS_F5SDK = True
except ImportError:
HAS_F5SDK = False
class BigIpSysDb(object):
def __init__(self, *args, **kwargs):
if not HAS_F5SDK:
raise F5ModuleError("The python f5-sdk module is required")
self.params = kwargs
self.api = ManagementRoot(kwargs['server'],
kwargs['user'],
kwargs['password'],
port=kwargs['server_port'])
def flush(self):
result = dict()
state = self.params['state']
value = self.params['value']
if not state == 'reset' and not value:
raise F5ModuleError(
"When setting a key, a value must be supplied"
)
current = self.read()
if self.params['check_mode']:
if value == current:
changed = False
else:
changed = True
else:
if state == "present":
changed = self.present()
elif state == "reset":
changed = self.reset()
current = self.read()
result.update(
name=current.name,
default_value=current.defaultValue,
value=current.value
)
result.update(dict(changed=changed))
return result
def read(self):
dbs = self.api.tm.sys.dbs.db.load(
name=self.params['key']
)
return dbs
def present(self):
current = self.read()
if current.value == self.params['value']:
return False
current.update(value=self.params['value'])
current.refresh()
if current.value != self.params['value']:
raise F5ModuleError(
"Failed to set the DB variable"
)
return True
def reset(self):
current = self.read()
default = current.defaultValue
if current.value == default:
return False
current.update(value=default)
current.refresh()
if current.value != current.defaultValue:
raise F5ModuleError(
"Failed to reset the DB variable"
)
return True
def main():
argument_spec = f5_argument_spec()
meta_args = dict(
key=dict(required=True),
state=dict(default='present', choices=['present', 'reset']),
value=dict(required=False, default=None)
)
argument_spec.update(meta_args)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True
)
try:
obj = BigIpSysDb(check_mode=module.check_mode, **module.params)
result = obj.flush()
module.exit_json(**result)
except F5ModuleError as e:
module.fail_json(msg=str(e))
from ansible.module_utils.basic import *
from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
7800,
481,
21,
17138,
3277,
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,
8490,
63,
8314,
275,
791,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
1023,
356,
283,
17,
14,
16,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
27281,
63,
1274,
63,
697,
199,
3612,
63,
1802,
26,
14944,
16524,
13,
1772,
2656,
3050,
2860,
199,
1802,
26,
523,
446,
14944,
16524,
13,
1772,
2656,
3050,
2860,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
1419,
26,
523,
790,
26,
272,
1369,
26,
489,
446,
710,
3050,
1750,
370,
27232,
14,
272,
1415,
26,
2549,
523,
1174,
26,
272,
1369,
26,
489,
446,
710,
1174,
402,
314,
1750,
641,
314,
2656,
14,
3979,
445,
8,
1881,
395,
12072,
397,
267,
626,
376,
3411,
1750,
365,
663,
370,
445,
8,
585,
680,
3979,
445,
8,
3958,
9,
5951,
314,
267,
1750,
1771,
370,
314,
849,
574,
14,
2854,
5210,
1373,
402,
574,
436,
1174,
267,
445,
8,
3958,
9,
787,
1415,
14,
272,
1415,
26,
3055,
272,
849,
26,
3451,
272,
3415,
26,
489,
446,
3451,
489,
446,
5305,
523,
574,
26,
272,
1369,
26,
489,
446,
710,
574,
370,
663,
314,
790,
370,
14,
2854,
5210,
1373,
402,
574,
436,
1174,
445,
8,
3958,
9,
267,
787,
1415,
14,
272,
1415,
26,
3055,
199,
5983,
26,
523,
446,
15127,
314,
289,
21,
13,
9277,
2018,
2559,
641,
314,
1591,
14,
961,
365,
465,
8837,
465,
7305,
272,
3907,
289,
21,
13,
9277,
14,
523,
446,
15127,
16524,
13,
1772,
1015,
3144,
14,
16,
14,
16,
503,
8932,
199,
11036,
63,
9970,
63,
7677,
26,
289,
21,
199,
7538,
26,
523,
446,
289,
21,
13,
9277,
199,
2502,
26,
523,
446,
26244,
820,
384,
80,
8593,
2874,
72,
31898,
8255,
9,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
2494,
314,
8498,
14,
10243,
6249,
1750,
641,
314,
16524,
13,
1772,
523,
27281,
63,
1274,
63,
697,
26,
489,
922,
26,
298,
2113,
2,
489,
2505,
26,
298,
4731,
2,
489,
1654,
26,
298,
6374,
14,
30945,
14,
957,
2,
489,
790,
26,
298,
4930,
14,
10243,
2,
489,
574,
26,
298,
5993,
2,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
17534,
314,
2536,
3272,
6426,
523,
27281,
63,
1274,
63,
697,
26,
489,
922,
26,
298,
2113,
2,
489,
2505,
26,
298,
4731,
2,
489,
1654,
26,
298,
6374,
14,
30945,
14,
957,
2,
489,
790,
26,
298,
2758,
14,
1065,
2,
489,
574,
26,
298,
3910,
2,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
15510,
314,
2536,
3272,
6426,
523,
27281,
63,
1274,
63,
697,
26,
489,
922,
26,
298,
2113,
2,
489,
2505,
26,
298,
4731,
2,
489,
1654,
26,
298,
6374,
14,
30945,
14,
957,
2,
489,
790,
26,
298,
2758,
14,
1065,
2,
489,
1174,
26,
298,
3958,
2,
523,
13080,
63,
475,
26,
11667,
199,
2344,
199,
199,
9677,
275,
1449,
199,
354,
26,
272,
1369,
26,
710,
790,
315,
314,
2656,
3050,
626,
1990,
2013,
272,
2138,
26,
2896,
436,
3182,
272,
730,
26,
1059,
272,
2690,
26,
298,
2758,
14,
1065,
2,
199,
885,
63,
585,
26,
272,
1369,
26,
710,
849,
574,
402,
314,
790,
272,
2138,
26,
2896,
436,
3182,
272,
730,
26,
1059,
272,
2690,
26,
298,
2052,
2,
199,
585,
26,
272,
1369,
26,
710,
574,
626,
1265,
663,
314,
790,
370,
272,
2138,
26,
2896,
436,
3182,
272,
730,
26,
1059,
272,
2690,
26,
298,
3910,
2,
199,
2344,
199,
199,
893,
26,
272,
687,
289,
21,
14,
17833,
492,
8259,
6405,
272,
7509,
63,
38,
21,
14939,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
38,
21,
14939,
275,
756,
421,
199,
533,
13123,
6583,
11319,
8882,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
7509,
63,
38,
21,
14939,
26,
288,
746,
481,
21,
12232,
480,
1918,
2366,
289,
21,
13,
9277,
859,
365,
1415,
531,
398,
291,
14,
1162,
275,
2074,
267,
291,
14,
1246,
275,
8259,
6405,
8,
958,
459,
1000,
995,
3303,
2074,
459,
751,
995,
3303,
2074,
459,
2060,
995,
3303,
1844,
29,
958,
459,
1000,
63,
719,
1105,
339,
347,
8976,
8,
277,
304,
267,
754,
275,
1211,
342,
267,
1174,
275,
291,
14,
1162,
459,
929,
418,
267,
574,
275,
291,
14,
1162,
459,
585,
418,
398,
340,
440,
1174,
508,
283,
3958,
7,
436,
440,
574,
26,
288,
746,
481,
21,
12232,
8,
355,
298,
11423,
4260,
282,
790,
12,
282,
574,
1471,
506,
6841,
2,
288,
776,
398,
1453,
275,
291,
14,
739,
342,
398,
340,
291,
14,
1162,
459,
1074,
63,
632,
2565,
288,
340,
574,
508,
1453,
26,
355,
2896,
275,
756,
288,
587,
26,
355,
2896,
275,
715,
267,
587,
26,
288,
340,
1174,
508,
298,
1881,
582,
355,
2896,
275,
291,
14,
1881,
342,
288,
916,
1174,
508,
298,
3958,
582,
355,
2896,
275,
291,
14,
3958,
342,
288,
1453,
275,
291,
14,
739,
342,
288
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
7800,
481,
21,
17138,
3277,
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,
8490,
63,
8314,
275,
791,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
1023,
356,
283,
17,
14,
16,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
27281,
63,
1274,
63,
697,
199,
3612,
63,
1802,
26,
14944,
16524,
13,
1772,
2656,
3050,
2860,
199,
1802,
26,
523,
446,
14944,
16524,
13,
1772,
2656,
3050,
2860,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
1419,
26,
523,
790,
26,
272,
1369,
26,
489,
446,
710,
3050,
1750,
370,
27232,
14,
272,
1415,
26,
2549,
523,
1174,
26,
272,
1369,
26,
489,
446,
710,
1174,
402,
314,
1750,
641,
314,
2656,
14,
3979,
445,
8,
1881,
395,
12072,
397,
267,
626,
376,
3411,
1750,
365,
663,
370,
445,
8,
585,
680,
3979,
445,
8,
3958,
9,
5951,
314,
267,
1750,
1771,
370,
314,
849,
574,
14,
2854,
5210,
1373,
402,
574,
436,
1174,
267,
445,
8,
3958,
9,
787,
1415,
14,
272,
1415,
26,
3055,
272,
849,
26,
3451,
272,
3415,
26,
489,
446,
3451,
489,
446,
5305,
523,
574,
26,
272,
1369,
26,
489,
446,
710,
574,
370,
663,
314,
790,
370,
14,
2854,
5210,
1373,
402,
574,
436,
1174,
445,
8,
3958,
9,
267,
787,
1415,
14,
272,
1415,
26,
3055,
199,
5983,
26,
523,
446,
15127,
314,
289,
21,
13,
9277,
2018,
2559,
641,
314,
1591,
14,
961,
365,
465,
8837,
465,
7305,
272,
3907,
289,
21,
13,
9277,
14,
523,
446,
15127,
16524,
13,
1772,
1015,
3144,
14,
16,
14,
16,
503,
8932,
199,
11036,
63,
9970,
63,
7677,
26,
289,
21,
199,
7538,
26,
523,
446,
289,
21,
13,
9277,
199,
2502,
26,
523,
446,
26244,
820,
384,
80,
8593,
2874,
72,
31898,
8255,
9,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
2494,
314,
8498,
14,
10243,
6249,
1750,
641,
314,
16524,
13,
1772,
523,
27281,
63,
1274,
63,
697,
26,
489,
922,
26,
298,
2113,
2,
489,
2505,
26,
298,
4731,
2,
489,
1654,
26,
298,
6374,
14,
30945,
14,
957,
2,
489,
790,
26,
298,
4930,
14,
10243,
2,
489,
574,
26,
298,
5993,
2,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
17534,
314,
2536,
3272,
6426,
523,
27281,
63,
1274,
63,
697,
26,
489,
922,
26,
298,
2113,
2,
489,
2505,
26,
298,
4731,
2,
489,
1654,
26,
298,
6374,
14,
30945,
14,
957,
2,
489,
790,
26,
298,
2758,
14,
1065,
2,
489,
574,
26,
298,
3910,
2,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
15510,
314,
2536,
3272,
6426,
523,
27281,
63,
1274,
63,
697,
26,
489,
922,
26,
298,
2113,
2,
489,
2505,
26,
298,
4731,
2,
489,
1654,
26,
298,
6374,
14,
30945,
14,
957,
2,
489,
790,
26,
298,
2758,
14,
1065,
2,
489,
1174,
26,
298,
3958,
2,
523,
13080,
63,
475,
26,
11667,
199,
2344,
199,
199,
9677,
275,
1449,
199,
354,
26,
272,
1369,
26,
710,
790,
315,
314,
2656,
3050,
626,
1990,
2013,
272,
2138,
26,
2896,
436,
3182,
272,
730,
26,
1059,
272,
2690,
26,
298,
2758,
14,
1065,
2,
199,
885,
63,
585,
26,
272,
1369,
26,
710,
849,
574,
402,
314,
790,
272,
2138,
26,
2896,
436,
3182,
272,
730,
26,
1059,
272,
2690,
26,
298,
2052,
2,
199,
585,
26,
272,
1369,
26,
710,
574,
626,
1265,
663,
314,
790,
370,
272,
2138,
26,
2896,
436,
3182,
272,
730,
26,
1059,
272,
2690,
26,
298,
3910,
2,
199,
2344,
199,
199,
893,
26,
272,
687,
289,
21,
14,
17833,
492,
8259,
6405,
272,
7509,
63,
38,
21,
14939,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
38,
21,
14939,
275,
756,
421,
199,
533,
13123,
6583,
11319,
8882,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
7509,
63,
38,
21,
14939,
26,
288,
746,
481,
21,
12232,
480,
1918,
2366,
289,
21,
13,
9277,
859,
365,
1415,
531,
398,
291,
14,
1162,
275,
2074,
267,
291,
14,
1246,
275,
8259,
6405,
8,
958,
459,
1000,
995,
3303,
2074,
459,
751,
995,
3303,
2074,
459,
2060,
995,
3303,
1844,
29,
958,
459,
1000,
63,
719,
1105,
339,
347,
8976,
8,
277,
304,
267,
754,
275,
1211,
342,
267,
1174,
275,
291,
14,
1162,
459,
929,
418,
267,
574,
275,
291,
14,
1162,
459,
585,
418,
398,
340,
440,
1174,
508,
283,
3958,
7,
436,
440,
574,
26,
288,
746,
481,
21,
12232,
8,
355,
298,
11423,
4260,
282,
790,
12,
282,
574,
1471,
506,
6841,
2,
288,
776,
398,
1453,
275,
291,
14,
739,
342,
398,
340,
291,
14,
1162,
459,
1074,
63,
632,
2565,
288,
340,
574,
508,
1453,
26,
355,
2896,
275,
756,
288,
587,
26,
355,
2896,
275,
715,
267,
587,
26,
288,
340,
1174,
508,
298,
1881,
582,
355,
2896,
275,
291,
14,
1881,
342,
288,
916,
1174,
508,
298,
3958,
582,
355,
2896,
275,
291,
14,
3958,
342,
288,
1453,
275,
291,
14,
739,
342,
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,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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
] |
jmacmahon/invenio
|
modules/webaccess/web/admin/webaccessadmin.py
|
3
|
14191
|
# This file is part of Invenio.
# Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 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.
"""Invenio WebAccess Administrator Interface."""
__revision__ = "$Id$"
from invenio.config import CFG_SITE_LANG
import invenio.webaccessadmin_lib as wal
from invenio.access_control_config import CFG_ACC_EMPTY_ROLE_DEFINITION_SRC
# reload(wal)
# from invenio.webaccessadmin_lib import index
index = wal.index
def rolearea(req, grep='', ln=CFG_SITE_LANG):
"""create the role area menu page."""
return wal.perform_rolearea(req=req, grep=grep)
def actionarea(req, grep='', ln=CFG_SITE_LANG):
"""create the role area menu page."""
return wal.perform_actionarea(req=req, grep=grep)
def managerobotlogin(req, robot_name='', new_pwd1='', new_pwd2='', login_method='', timeout='', referer='', ip='', action='', confirm=0, email='', groups='', nickname='', json_assertion='', url_only=0, ln=CFG_SITE_LANG):
"""Manage robot login keys and test URL."""
return wal.perform_managerobotlogin(req=req, robot_name=robot_name, new_pwd1=new_pwd1, new_pwd2=new_pwd2, login_method=login_method, timeout=timeout, referer=referer, ip=ip, action=action, confirm=confirm, email=email, groups=groups, nickname=nickname, json_assertion=json_assertion, url_only=url_only)
def userarea(req, email_user_pattern='', ln=CFG_SITE_LANG):
"""create the user area menu page. """
return wal.perform_userarea(req=req,
email_user_pattern=email_user_pattern)
def listgroups(req, ln=CFG_SITE_LANG):
return wal.perform_listgroups(req=req)
def resetarea(req, ln=CFG_SITE_LANG):
"""create the role area menu page."""
return wal.perform_resetarea(req=req)
def resetdefaultsettings(req, superusers=[], confirm=0, ln=CFG_SITE_LANG):
"""create the reset default settings page. """
return wal.perform_resetdefaultsettings(req=req,
superusers=superusers,
confirm=confirm)
def adddefaultsettings(req, superusers=[], confirm=0, ln=CFG_SITE_LANG):
"""create the add default settings page. """
return wal.perform_adddefaultsettings(req=req,
superusers=superusers,
confirm=confirm)
def manageaccounts(req, mtype='', content='', confirm=0, ln=CFG_SITE_LANG):
"""enable, disable and edit accounts"""
return wal.perform_manageaccounts(req=req, mtype=mtype, content=content, confirm=confirm)
def modifyaccountstatus(req, userID, email_user_pattern='', limit_to=-1, maxpage=25, page=1, callback='yes', confirm=0, ln=CFG_SITE_LANG):
"""enable or disable account"""
return wal.perform_modifyaccountstatus(req=req, userID=userID, email_user_pattern=email_user_pattern, limit_to=limit_to, maxpage=maxpage, page=page, callback=callback, confirm=confirm)
def modifypreferences(req, userID, login_method='', callback='yes', confirm=0, ln=CFG_SITE_LANG):
"""modify the preferences of an account"""
return wal.perform_modifypreferences(req=req, userID=userID, login_method=login_method, callback=callback, confirm=confirm)
def modifyapikeydata(req, userID, keyID, status, callback='yes', confirm=0, ln=CFG_SITE_LANG):
"""modify the status of a REST API key"""
return wal.perform_modifyapikeydata(req=req, userID=userID, keyID=keyID, status=status, callback=callback, confirm=confirm)
def modifylogindata(req, userID, nickname='', email='', password='', callback='yes', confirm=0, ln=CFG_SITE_LANG):
"""modify the email/password of an account"""
return wal.perform_modifylogindata(req=req, userID=userID, nickname=nickname, email=email, password=password, callback=callback, confirm=confirm)
def rejectaccount(req, userID, email_user_pattern='', limit_to=-1, maxpage=25, page=1, callback='yes', confirm=0, ln=CFG_SITE_LANG):
"""Set account inactive, delete it and send email to the owner."""
return wal.perform_rejectaccount(req=req, userID=userID, email_user_pattern=email_user_pattern, limit_to=limit_to, maxpage=maxpage, page=page, callback=callback, confirm=confirm)
def deleteaccount(req, userID, callback='yes', confirm=0, ln=CFG_SITE_LANG):
"""delete account"""
return wal.perform_deleteaccount(req=req, userID=userID, callback=callback, confirm=confirm)
def createaccount(req, email='', password='', callback='yes', confirm=0, ln=CFG_SITE_LANG):
"""create account"""
return wal.perform_createaccount(req=req, email=email, password=password, callback=callback, confirm=confirm)
def editaccount(req, userID, mtype='', content='', callback='yes', confirm=0, ln=CFG_SITE_LANG):
"""edit account. """
return wal.perform_editaccount(req=req, userID=userID, mtype=mtype, content=content, callback=callback, confirm=confirm)
def becomeuser(req, userID='', callback='yes', confirm=0, ln=CFG_SITE_LANG):
"""edit account. """
return wal.perform_becomeuser(req=req, userID=userID, callback=callback, confirm=confirm)
def modifyaccounts(req, email_user_pattern='', limit_to=-1, maxpage=25, page=1, callback='yes', confirm=0, ln=CFG_SITE_LANG):
"""Modify accounts. """
return wal.perform_modifyaccounts(req=req, email_user_pattern=email_user_pattern, limit_to=limit_to, maxpage=maxpage, page=page, callback=callback,confirm=confirm)
def delegate_startarea(req, ln=CFG_SITE_LANG):
"""add info here"""
return wal.perform_delegate_startarea(req=req)
def delegate_adminsetup(req, id_role_admin=0, id_role_delegate=0, confirm=0, ln=CFG_SITE_LANG):
"""add info here"""
return wal.perform_delegate_adminsetup(req=req,
id_role_admin=id_role_admin,
id_role_delegate=id_role_delegate,
confirm=confirm)
def delegate_adduserrole(req, id_role=0, email_user_pattern='', id_user=0, confirm=0, ln=CFG_SITE_LANG):
"""add info here"""
return wal.perform_delegate_adduserrole(req=req,
id_role=id_role,
email_user_pattern=email_user_pattern,
id_user=id_user,
confirm=confirm)
def delegate_deleteuserrole(req, id_role=0, id_user=0, confirm=0, ln=CFG_SITE_LANG):
"""add info here"""
return wal.perform_delegate_deleteuserrole(req=req,
id_role=id_role,
id_user=id_user,
confirm=confirm)
def addrole(req, name_role='', description='put description here.', firerole_def_src=CFG_ACC_EMPTY_ROLE_DEFINITION_SRC, confirm=0, ln=CFG_SITE_LANG):
"""form to add a new role with these values:
name_role - name of the new role
description - optional description of the role
firerole_def_src - optional firerole like definition
"""
return wal.perform_addrole(req=req,
name_role=name_role,
description=description,
firerole_def_src=firerole_def_src,
confirm=confirm)
def modifyrole(req, id_role='0', name_role='', description='put description here.', firerole_def_src='', modified='0', confirm=0, ln=CFG_SITE_LANG):
"""form to add a new role with these values:
name_role - name of the new role
description - optional description of the role
firerole_def_src - optional firerole like definition
"""
return wal.perform_modifyrole(req=req,
id_role=id_role,
name_role=name_role,
description=description,
firerole_def_src=firerole_def_src,
modified=modified,
confirm=confirm)
def deleterole(req, id_role="0", confirm=0, ln=CFG_SITE_LANG):
"""select a role and show all connected information,
users - users that can access the role.
actions - actions with possible authorizations."""
return wal.perform_deleterole(req=req,
id_role=id_role,
confirm=confirm)
def showroledetails(req, id_role='0', ln=CFG_SITE_LANG):
"""show the details of a role."""
return wal.perform_showroledetails(req=req,
id_role=id_role)
def showactiondetails(req, id_action="0", ln=CFG_SITE_LANG):
"""show the details of an action. """
return wal.perform_showactiondetails(req=req,
id_action=id_action)
def showuserdetails(req, id_user="0", ln=CFG_SITE_LANG):
"""show the details of an action. """
return wal.perform_showuserdetails(req=req,
id_user=id_user)
def adduserrole(req, id_role='0', email_user_pattern='', id_user='0', confirm=0, ln=CFG_SITE_LANG):
"""create connection between user and role.
id_role - id of the role to add user to
email_user_pattern - search for users using this pattern
id_user - id of user to add to the role. """
return wal.perform_adduserrole(req=req,
id_role=id_role,
email_user_pattern=email_user_pattern,
id_user=id_user,
confirm=confirm)
def addroleuser(req, email_user_pattern='', id_user='0', id_role='0', confirm=0, ln=CFG_SITE_LANG):
"""create connection between user and role.
email_user_pattern - search for users using this pattern
id_user - id of user to add to the role.
id_role - id of the role to add user to. """
return wal.perform_addroleuser(req=req,
email_user_pattern=email_user_pattern,
id_user=id_user,
id_role=id_role,
confirm=confirm)
def deleteuserrole(req, id_role='0', id_user='0', reverse=0, confirm=0, ln=CFG_SITE_LANG):
"""delete connection between role and user.
id_role - id of role to disconnect
id_user - id of user to disconnect. """
return wal.perform_deleteuserrole(req=req,
id_role=id_role,
id_user=id_user,
reverse=reverse,
confirm=confirm)
def addauthorization(req, id_role="0", id_action="0", reverse="0", confirm=0, **keywords):
""" form to add new connection between user and role:
id_role - role to connect
id_action - action to connect
reverse - role or action first? """
return wal.perform_addauthorization(req=req,
id_role=id_role,
id_action=id_action,
reverse=reverse,
confirm=confirm,
**keywords)
def deleteroleaction(req, id_role="0", id_action="0", reverse=0, confirm=0, ln=CFG_SITE_LANG):
"""delete all connections between a role and an action.
id_role - id of the role
id_action - id of the action
reverse - 0: ask for role first
1: ask for action first"""
return wal.perform_deleteroleaction(req=req,
id_role=id_role,
id_action=id_action,
reverse=reverse,
confirm=confirm)
def modifyauthorizations(req, id_role="0", id_action="0", reverse=0, confirm=0, sel='', errortext='', authids=[], ln=CFG_SITE_LANG):
"""given ids of a role and an action, show all possible action combinations
with checkboxes and allow user to access other functions.
id_role - id of the role
id_action - id of the action
reverse - 0: ask for role first
1: ask for action first
sel - which button and modification that is selected
errortext - text to print when no connection exist between role and action
authids - ids of checked checkboxes """
return wal.perform_modifyauthorizations(req=req,
id_role=id_role,
id_action=id_action,
reverse=reverse,
confirm=confirm,
sel=sel,
authids=authids)
def simpleauthorization(req, id_role=0, id_action=0, ln=CFG_SITE_LANG):
"""show a page with simple overview of authorizations between a
connected role and action. """
return wal.perform_simpleauthorization(req=req,
id_role=id_role,
id_action=id_action)
def showroleusers(req, id_role=0, ln=CFG_SITE_LANG):
"""show a page with simple overview of a role and connected users. """
return wal.perform_showroleusers(req=req,
id_role=id_role)
|
gpl-2.0
|
[
3,
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
7760,
24354,
14,
199,
3,
199,
3,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
624,
607,
7597,
6001,
3946,
30660,
14816,
1041,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
199,
504,
13640,
14,
888,
492,
10974,
63,
7917,
63,
7442,
199,
646,
13640,
14,
2520,
2732,
2113,
63,
773,
465,
336,
279,
199,
504,
13640,
14,
2732,
63,
2785,
63,
888,
492,
10974,
63,
7372,
63,
13993,
63,
15468,
63,
5638,
8727,
1075,
63,
12447,
199,
3,
13101,
8,
20877,
9,
199,
3,
687,
13640,
14,
2520,
2732,
2113,
63,
773,
492,
1478,
199,
199,
1080,
275,
336,
279,
14,
1080,
199,
199,
318,
4719,
6789,
8,
2103,
12,
20595,
4581,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
408,
981,
314,
4719,
9150,
6269,
2034,
1041,
339,
372,
336,
279,
14,
15795,
63,
3756,
6789,
8,
2103,
29,
2103,
12,
20595,
29,
25914,
9,
421,
199,
318,
1595,
6789,
8,
2103,
12,
20595,
4581,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
408,
981,
314,
4719,
9150,
6269,
2034,
1041,
339,
372,
336,
279,
14,
15795,
63,
1287,
6789,
8,
2103,
29,
2103,
12,
20595,
29,
25914,
9,
199,
199,
318,
5256,
17800,
2886,
8,
2103,
12,
14544,
63,
354,
4581,
892,
63,
14258,
17,
4581,
892,
63,
14258,
18,
4581,
4676,
63,
765,
4581,
2653,
4581,
25104,
4581,
3384,
4581,
1595,
4581,
12679,
29,
16,
12,
3031,
4581,
4652,
4581,
24332,
4581,
2022,
63,
18487,
4581,
1166,
63,
2118,
29,
16,
12,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
408,
20588,
14544,
4676,
2883,
436,
511,
2851,
1041,
272,
372,
336,
279,
14,
15795,
63,
2609,
17800,
2886,
8,
2103,
29,
2103,
12,
14544,
63,
354,
29,
9751,
63,
354,
12,
892,
63,
14258,
17,
29,
1222,
63,
14258,
17,
12,
892,
63,
14258,
18,
29,
1222,
63,
14258,
18,
12,
4676,
63,
765,
29,
2886,
63,
765,
12,
2653,
29,
2593,
12,
25104,
29,
20996,
12,
3384,
29,
711,
12,
1595,
29,
1287,
12,
12679,
29,
9548,
12,
3031,
29,
2123,
12,
4652,
29,
2634,
12,
24332,
29,
18544,
12,
2022,
63,
18487,
29,
1001,
63,
18487,
12,
1166,
63,
2118,
29,
633,
63,
2118,
9,
199,
199,
318,
922,
6789,
8,
2103,
12,
3031,
63,
751,
63,
3401,
4581,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
408,
981,
314,
922,
9150,
6269,
2034,
14,
408,
339,
372,
336,
279,
14,
15795,
63,
751,
6789,
8,
2103,
29,
2103,
12,
1816,
3031,
63,
751,
63,
3401,
29,
2123,
63,
751,
63,
3401,
9,
199,
199,
318,
769,
2634,
8,
2103,
12,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
372,
336,
279,
14,
15795,
63,
513,
2634,
8,
2103,
29,
2103,
9,
199,
199,
318,
5305,
6789,
8,
2103,
12,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
408,
981,
314,
4719,
9150,
6269,
2034,
1041,
339,
372,
336,
279,
14,
15795,
63,
3958,
6789,
8,
2103,
29,
2103,
9,
421,
199,
318,
5305,
885,
1751,
8,
2103,
12,
1613,
3707,
6034,
12679,
29,
16,
12,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
408,
981,
314,
5305,
849,
2202,
2034,
14,
408,
339,
372,
336,
279,
14,
15795,
63,
3958,
885,
1751,
8,
2103,
29,
2103,
12,
4490,
1613,
3707,
29,
4792,
3707,
12,
4490,
12679,
29,
9548,
9,
421,
199,
318,
1050,
885,
1751,
8,
2103,
12,
1613,
3707,
6034,
12679,
29,
16,
12,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
408,
981,
314,
1050,
849,
2202,
2034,
14,
408,
339,
372,
336,
279,
14,
15795,
63,
525,
885,
1751,
8,
2103,
29,
2103,
12,
5101,
1613,
3707,
29,
4792,
3707,
12,
5101,
12679,
29,
9548,
9,
421,
199,
318,
9635,
8370,
8,
2103,
12,
21021,
4581,
1564,
4581,
12679,
29,
16,
12,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
408,
4296,
12,
3507,
436,
5283,
12639,
624,
339,
372,
336,
279,
14,
15795,
63,
9053,
8370,
8,
2103,
29,
2103,
12,
21021,
29,
77,
466,
12,
1564,
29,
1317,
12,
12679,
29,
9548,
9,
199,
199,
318,
2811,
2048,
1205,
8,
2103,
12,
922,
998,
12,
3031,
63,
751,
63,
3401,
4581,
2304,
63,
475,
4022,
17,
12,
1390,
1606,
29,
821,
12,
2034,
29,
17,
12,
3233,
534,
5066,
297,
12679,
29,
16,
12,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
408,
4296,
503,
3507,
2933,
624,
339,
372,
336,
279,
14,
15795,
63,
8951,
2048,
1205,
8,
2103,
29,
2103,
12,
922,
998,
29,
751,
998,
12,
3031,
63,
751,
63,
3401,
29,
2123,
63,
751,
63,
3401,
12,
2304,
63,
475,
29,
3097,
63,
475,
12,
1390,
1606,
29,
988,
1606,
12,
2034,
29,
1606,
12,
3233,
29,
3058,
12,
12679,
29,
9548,
9,
199,
199,
318,
2811,
18063,
8,
2103,
12,
922,
998,
12,
4676,
63,
765,
4581,
3233,
534,
5066,
297,
12679,
29,
16,
12,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
408,
8951,
314,
23453,
402,
376,
2933,
624,
339,
372,
336,
279,
14,
15795,
63,
8951,
18063,
8
] |
[
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
7760,
24354,
14,
199,
3,
199,
3,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
624,
607,
7597,
6001,
3946,
30660,
14816,
1041,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
199,
504,
13640,
14,
888,
492,
10974,
63,
7917,
63,
7442,
199,
646,
13640,
14,
2520,
2732,
2113,
63,
773,
465,
336,
279,
199,
504,
13640,
14,
2732,
63,
2785,
63,
888,
492,
10974,
63,
7372,
63,
13993,
63,
15468,
63,
5638,
8727,
1075,
63,
12447,
199,
3,
13101,
8,
20877,
9,
199,
3,
687,
13640,
14,
2520,
2732,
2113,
63,
773,
492,
1478,
199,
199,
1080,
275,
336,
279,
14,
1080,
199,
199,
318,
4719,
6789,
8,
2103,
12,
20595,
4581,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
408,
981,
314,
4719,
9150,
6269,
2034,
1041,
339,
372,
336,
279,
14,
15795,
63,
3756,
6789,
8,
2103,
29,
2103,
12,
20595,
29,
25914,
9,
421,
199,
318,
1595,
6789,
8,
2103,
12,
20595,
4581,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
408,
981,
314,
4719,
9150,
6269,
2034,
1041,
339,
372,
336,
279,
14,
15795,
63,
1287,
6789,
8,
2103,
29,
2103,
12,
20595,
29,
25914,
9,
199,
199,
318,
5256,
17800,
2886,
8,
2103,
12,
14544,
63,
354,
4581,
892,
63,
14258,
17,
4581,
892,
63,
14258,
18,
4581,
4676,
63,
765,
4581,
2653,
4581,
25104,
4581,
3384,
4581,
1595,
4581,
12679,
29,
16,
12,
3031,
4581,
4652,
4581,
24332,
4581,
2022,
63,
18487,
4581,
1166,
63,
2118,
29,
16,
12,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
408,
20588,
14544,
4676,
2883,
436,
511,
2851,
1041,
272,
372,
336,
279,
14,
15795,
63,
2609,
17800,
2886,
8,
2103,
29,
2103,
12,
14544,
63,
354,
29,
9751,
63,
354,
12,
892,
63,
14258,
17,
29,
1222,
63,
14258,
17,
12,
892,
63,
14258,
18,
29,
1222,
63,
14258,
18,
12,
4676,
63,
765,
29,
2886,
63,
765,
12,
2653,
29,
2593,
12,
25104,
29,
20996,
12,
3384,
29,
711,
12,
1595,
29,
1287,
12,
12679,
29,
9548,
12,
3031,
29,
2123,
12,
4652,
29,
2634,
12,
24332,
29,
18544,
12,
2022,
63,
18487,
29,
1001,
63,
18487,
12,
1166,
63,
2118,
29,
633,
63,
2118,
9,
199,
199,
318,
922,
6789,
8,
2103,
12,
3031,
63,
751,
63,
3401,
4581,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
408,
981,
314,
922,
9150,
6269,
2034,
14,
408,
339,
372,
336,
279,
14,
15795,
63,
751,
6789,
8,
2103,
29,
2103,
12,
1816,
3031,
63,
751,
63,
3401,
29,
2123,
63,
751,
63,
3401,
9,
199,
199,
318,
769,
2634,
8,
2103,
12,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
372,
336,
279,
14,
15795,
63,
513,
2634,
8,
2103,
29,
2103,
9,
199,
199,
318,
5305,
6789,
8,
2103,
12,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
408,
981,
314,
4719,
9150,
6269,
2034,
1041,
339,
372,
336,
279,
14,
15795,
63,
3958,
6789,
8,
2103,
29,
2103,
9,
421,
199,
318,
5305,
885,
1751,
8,
2103,
12,
1613,
3707,
6034,
12679,
29,
16,
12,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
408,
981,
314,
5305,
849,
2202,
2034,
14,
408,
339,
372,
336,
279,
14,
15795,
63,
3958,
885,
1751,
8,
2103,
29,
2103,
12,
4490,
1613,
3707,
29,
4792,
3707,
12,
4490,
12679,
29,
9548,
9,
421,
199,
318,
1050,
885,
1751,
8,
2103,
12,
1613,
3707,
6034,
12679,
29,
16,
12,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
408,
981,
314,
1050,
849,
2202,
2034,
14,
408,
339,
372,
336,
279,
14,
15795,
63,
525,
885,
1751,
8,
2103,
29,
2103,
12,
5101,
1613,
3707,
29,
4792,
3707,
12,
5101,
12679,
29,
9548,
9,
421,
199,
318,
9635,
8370,
8,
2103,
12,
21021,
4581,
1564,
4581,
12679,
29,
16,
12,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
408,
4296,
12,
3507,
436,
5283,
12639,
624,
339,
372,
336,
279,
14,
15795,
63,
9053,
8370,
8,
2103,
29,
2103,
12,
21021,
29,
77,
466,
12,
1564,
29,
1317,
12,
12679,
29,
9548,
9,
199,
199,
318,
2811,
2048,
1205,
8,
2103,
12,
922,
998,
12,
3031,
63,
751,
63,
3401,
4581,
2304,
63,
475,
4022,
17,
12,
1390,
1606,
29,
821,
12,
2034,
29,
17,
12,
3233,
534,
5066,
297,
12679,
29,
16,
12,
10359,
29,
10118,
63,
7917,
63,
7442,
304,
272,
408,
4296,
503,
3507,
2933,
624,
339,
372,
336,
279,
14,
15795,
63,
8951,
2048,
1205,
8,
2103,
29,
2103,
12,
922,
998,
29,
751,
998,
12,
3031,
63,
751,
63,
3401,
29,
2123,
63,
751,
63,
3401,
12,
2304,
63,
475,
29,
3097,
63,
475,
12,
1390,
1606,
29,
988,
1606,
12,
2034,
29,
1606,
12,
3233,
29,
3058,
12,
12679,
29,
9548,
9,
199,
199,
318,
2811,
18063,
8,
2103,
12,
922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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
] |
nathanbjenx/cairis
|
cairis/core/EnvironmentParameters.py
|
2
|
2186
|
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from .ObjectCreationParameters import ObjectCreationParameters
__author__ = 'Shamal Faily'
class EnvironmentParameters(ObjectCreationParameters):
def __init__(self,conName,conSc,conDesc,environments = [],duplProperty = 'None',overridingEnvironment = '', envTensions = None):
ObjectCreationParameters.__init__(self)
self.theName = conName
self.theShortCode = conSc
self.theDescription = conDesc
self.theEnvironments = environments
self.theDuplicateProperty = duplProperty
self.theOverridingEnvironment = overridingEnvironment
self.theAssetValues = None
if (envTensions == None):
self.theTensions = {}
defaultTension = (0,'None')
idx = 0
while idx < 4:
iidx = 4
while iidx < 8:
self.theTensions[(idx,iidx)] = defaultTension
iidx += 1
idx += 1
else:
self.theTensions = envTensions
def setAssetValues(self,avs):
self.theAssetValues = avs
def name(self): return self.theName
def shortCode(self): return self.theShortCode
def description(self): return self.theDescription
def environments(self): return self.theEnvironments
def duplicateProperty(self): return self.theDuplicateProperty
def overridingEnvironment(self): return self.theOverridingEnvironment
def assetValues(self): return self.theAssetValues
def tensions(self): return self.theTensions
|
apache-2.0
|
[
3,
221,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
221,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
221,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
221,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
221,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
221,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
221,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
221,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
221,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
221,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
221,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
221,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
221,
1334,
314,
844,
14,
421,
199,
504,
1275,
1692,
13921,
5976,
492,
6935,
13921,
5976,
199,
199,
363,
2502,
363,
275,
283,
2662,
455,
279,
12176,
89,
7,
199,
199,
533,
9711,
5976,
8,
1692,
13921,
5976,
304,
523,
347,
636,
826,
721,
277,
12,
388,
985,
12,
388,
7181,
12,
388,
9921,
12,
26411,
275,
990,
11048,
76,
3697,
275,
283,
403,
297,
1883,
15526,
8263,
275,
3260,
2589,
22216,
1356,
275,
488,
304,
272,
6935,
13921,
5976,
855,
826,
721,
277,
9,
272,
291,
14,
1589,
985,
275,
406,
985,
272,
291,
14,
1589,
10039,
3034,
275,
406,
7181,
272,
291,
14,
1589,
5831,
275,
406,
9921,
272,
291,
14,
1589,
23027,
1470,
275,
22196,
272,
291,
14,
1589,
14773,
3697,
275,
11866,
76,
3697,
5591,
291,
14,
1589,
5674,
15526,
8263,
275,
18972,
8263,
272,
291,
14,
1589,
19979,
6550,
275,
488,
272,
340,
334,
1813,
22216,
1356,
508,
488,
304,
489,
291,
14,
1589,
22216,
1356,
275,
1052,
489,
849,
22216,
438,
275,
334,
16,
2584,
403,
358,
489,
4280,
275,
378,
489,
1830,
4280,
665,
841,
26,
267,
284,
2996,
275,
841,
267,
1830,
284,
2996,
665,
1695,
26,
881,
291,
14,
1589,
22216,
1356,
7528,
2996,
12,
73,
2996,
1874,
275,
849,
22216,
438,
881,
284,
2996,
847,
413,
267,
4280,
847,
413,
272,
587,
26,
489,
291,
14,
1589,
22216,
1356,
275,
2589,
22216,
1356,
819,
347,
663,
19979,
6550,
8,
277,
12,
1214,
83,
304,
272,
291,
14,
1589,
19979,
6550,
275,
2289,
83,
819,
347,
536,
8,
277,
304,
372,
291,
14,
1589,
985,
523,
347,
3974,
3034,
8,
277,
304,
372,
291,
14,
1589,
10039,
3034,
523,
347,
1369,
8,
277,
304,
372,
291,
14,
1589,
5831,
523,
347,
22196,
8,
277,
304,
372,
291,
14,
1589,
23027,
1470,
523,
347,
9250,
3697,
8,
277,
304,
372,
291,
14,
1589,
14773,
3697,
523,
347,
18972,
8263,
8,
277,
304,
372,
291,
14,
1589,
5674,
15526,
8263,
523,
347,
8977,
6550,
8,
277,
304,
372,
291,
14,
1589,
19979,
6550,
523,
347,
16685,
1356,
8,
277,
304,
372,
291,
14,
1589,
22216,
1356,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
221,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
221,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
221,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
221,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
221,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
221,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
221,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
221,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
221,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
221,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
221,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
221,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
221,
1334,
314,
844,
14,
421,
199,
504,
1275,
1692,
13921,
5976,
492,
6935,
13921,
5976,
199,
199,
363,
2502,
363,
275,
283,
2662,
455,
279,
12176,
89,
7,
199,
199,
533,
9711,
5976,
8,
1692,
13921,
5976,
304,
523,
347,
636,
826,
721,
277,
12,
388,
985,
12,
388,
7181,
12,
388,
9921,
12,
26411,
275,
990,
11048,
76,
3697,
275,
283,
403,
297,
1883,
15526,
8263,
275,
3260,
2589,
22216,
1356,
275,
488,
304,
272,
6935,
13921,
5976,
855,
826,
721,
277,
9,
272,
291,
14,
1589,
985,
275,
406,
985,
272,
291,
14,
1589,
10039,
3034,
275,
406,
7181,
272,
291,
14,
1589,
5831,
275,
406,
9921,
272,
291,
14,
1589,
23027,
1470,
275,
22196,
272,
291,
14,
1589,
14773,
3697,
275,
11866,
76,
3697,
5591,
291,
14,
1589,
5674,
15526,
8263,
275,
18972,
8263,
272,
291,
14,
1589,
19979,
6550,
275,
488,
272,
340,
334,
1813,
22216,
1356,
508,
488,
304,
489,
291,
14,
1589,
22216,
1356,
275,
1052,
489,
849,
22216,
438,
275,
334,
16,
2584,
403,
358,
489,
4280,
275,
378,
489,
1830,
4280,
665,
841,
26,
267,
284,
2996,
275,
841,
267,
1830,
284,
2996,
665,
1695,
26,
881,
291,
14,
1589,
22216,
1356,
7528,
2996,
12,
73,
2996,
1874,
275,
849,
22216,
438,
881,
284,
2996,
847,
413,
267,
4280,
847,
413,
272,
587,
26,
489,
291,
14,
1589,
22216,
1356,
275,
2589,
22216,
1356,
819,
347,
663,
19979,
6550,
8,
277,
12,
1214,
83,
304,
272,
291,
14,
1589,
19979,
6550,
275,
2289,
83,
819,
347,
536,
8,
277,
304,
372,
291,
14,
1589,
985,
523,
347,
3974,
3034,
8,
277,
304,
372,
291,
14,
1589,
10039,
3034,
523,
347,
1369,
8,
277,
304,
372,
291,
14,
1589,
5831,
523,
347,
22196,
8,
277,
304,
372,
291,
14,
1589,
23027,
1470,
523,
347,
9250,
3697,
8,
277,
304,
372,
291,
14,
1589,
14773,
3697,
523,
347,
18972,
8263,
8,
277,
304,
372,
291,
14,
1589,
5674,
15526,
8263,
523,
347,
8977,
6550,
8,
277,
304,
372,
291,
14,
1589,
19979,
6550,
523,
347,
16685,
1356,
8,
277,
304,
372,
291,
14,
1589,
22216,
1356,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
IKholopov/HackUPC2017
|
hackupc/env/lib/python3.5/site-packages/social/tests/backends/test_dummy.py
|
80
|
3932
|
import json
import datetime
import time
from httpretty import HTTPretty
from social.actions import do_disconnect
from social.backends.oauth import BaseOAuth2
from social.exceptions import AuthForbidden
from social.tests.models import User
from social.tests.backends.oauth import OAuth2Test
class DummyOAuth2(BaseOAuth2):
name = 'dummy'
AUTHORIZATION_URL = 'http://dummy.com/oauth/authorize'
ACCESS_TOKEN_URL = 'http://dummy.com/oauth/access_token'
REVOKE_TOKEN_URL = 'https://dummy.com/oauth/revoke'
REVOKE_TOKEN_METHOD = 'GET'
EXTRA_DATA = [
('id', 'id'),
('expires', 'expires'),
('empty', 'empty', True),
'url'
]
def get_user_details(self, response):
"""Return user details from Github account"""
return {'username': response.get('username'),
'email': response.get('email', ''),
'first_name': response.get('first_name', ''),
'last_name': response.get('last_name', '')}
def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
return self.get_json('http://dummy.com/user', params={
'access_token': access_token
})
class DummyOAuth2Test(OAuth2Test):
backend_path = 'social.tests.backends.test_dummy.DummyOAuth2'
user_data_url = 'http://dummy.com/user'
expected_username = 'foobar'
access_token_body = json.dumps({
'access_token': 'foobar',
'token_type': 'bearer'
})
user_data_body = json.dumps({
'id': 1,
'username': 'foobar',
'url': 'http://dummy.com/user/foobar',
'first_name': 'Foo',
'last_name': 'Bar',
'email': 'foo@bar.com'
})
def test_login(self):
self.do_login()
def test_partial_pipeline(self):
self.do_partial_pipeline()
def test_tokens(self):
user = self.do_login()
self.assertEqual(user.social[0].access_token, 'foobar')
def test_revoke_token(self):
self.strategy.set_settings({
'SOCIAL_AUTH_REVOKE_TOKENS_ON_DISCONNECT': True
})
self.do_login()
user = User.get(self.expected_username)
user.password = 'password'
HTTPretty.register_uri(self._method(self.backend.REVOKE_TOKEN_METHOD),
self.backend.REVOKE_TOKEN_URL,
status=200)
do_disconnect(self.backend, user)
class WhitelistEmailsTest(DummyOAuth2Test):
def test_valid_login(self):
self.strategy.set_settings({
'SOCIAL_AUTH_WHITELISTED_EMAILS': ['foo@bar.com']
})
self.do_login()
def test_invalid_login(self):
self.strategy.set_settings({
'SOCIAL_AUTH_WHITELISTED_EMAILS': ['foo2@bar.com']
})
with self.assertRaises(AuthForbidden):
self.do_login()
class WhitelistDomainsTest(DummyOAuth2Test):
def test_valid_login(self):
self.strategy.set_settings({
'SOCIAL_AUTH_WHITELISTED_DOMAINS': ['bar.com']
})
self.do_login()
def test_invalid_login(self):
self.strategy.set_settings({
'SOCIAL_AUTH_WHITELISTED_EMAILS': ['bar2.com']
})
with self.assertRaises(AuthForbidden):
self.do_login()
DELTA = datetime.timedelta(days=1)
class ExpirationTimeTest(DummyOAuth2Test):
user_data_body = json.dumps({
'id': 1,
'username': 'foobar',
'url': 'http://dummy.com/user/foobar',
'first_name': 'Foo',
'last_name': 'Bar',
'email': 'foo@bar.com',
'expires': time.mktime((datetime.datetime.utcnow() +
DELTA).timetuple())
})
def test_expires_time(self):
user = self.do_login()
social = user.social[0]
expiration = social.expiration_datetime()
self.assertEqual(expiration <= DELTA, True)
|
apache-2.0
|
[
646,
2022,
199,
646,
2197,
199,
646,
900,
199,
199,
504,
22768,
9118,
492,
3101,
21958,
199,
199,
504,
20295,
14,
3723,
492,
886,
63,
10673,
199,
504,
20295,
14,
7765,
14,
6126,
492,
3523,
12906,
18,
199,
504,
20295,
14,
3924,
492,
3590,
17454,
199,
199,
504,
20295,
14,
2219,
14,
992,
492,
2876,
199,
504,
20295,
14,
2219,
14,
7765,
14,
6126,
492,
11715,
18,
774,
421,
199,
533,
9762,
12906,
18,
8,
1563,
12906,
18,
304,
272,
536,
275,
283,
5869,
7,
272,
7560,
7123,
2594,
63,
2632,
275,
283,
1014,
921,
5869,
14,
957,
15,
6126,
15,
14204,
7,
272,
437,
10203,
63,
8803,
63,
2632,
275,
283,
1014,
921,
5869,
14,
957,
15,
6126,
15,
2732,
63,
1418,
7,
272,
5363,
10662,
2430,
63,
8803,
63,
2632,
275,
283,
2859,
921,
5869,
14,
957,
15,
6126,
15,
24445,
7,
272,
5363,
10662,
2430,
63,
8803,
63,
9977,
275,
283,
2970,
7,
272,
3651,
13954,
63,
3998,
275,
359,
267,
661,
344,
297,
283,
344,
659,
267,
661,
12342,
297,
283,
12342,
659,
267,
661,
1667,
297,
283,
1667,
297,
715,
395,
267,
283,
633,
7,
272,
1622,
339,
347,
664,
63,
751,
63,
5087,
8,
277,
12,
1177,
304,
267,
408,
1767,
922,
2436,
687,
598,
4049,
2933,
624,
267,
372,
791,
2473,
356,
1177,
14,
362,
360,
2473,
659,
355,
283,
2123,
356,
1177,
14,
362,
360,
2123,
297,
9929,
355,
283,
2246,
63,
354,
356,
1177,
14,
362,
360,
2246,
63,
354,
297,
9929,
355,
283,
2019,
63,
354,
356,
1177,
14,
362,
360,
2019,
63,
354,
297,
4074,
93,
339,
347,
922,
63,
576,
8,
277,
12,
2879,
63,
1418,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
30777,
922,
666,
687,
2435,
624,
267,
372,
291,
14,
362,
63,
1001,
360,
1014,
921,
5869,
14,
957,
15,
751,
297,
1862,
3126,
288,
283,
2732,
63,
1418,
356,
2879,
63,
1418,
267,
3828,
421,
199,
533,
9762,
12906,
18,
774,
8,
12906,
18,
774,
304,
272,
4865,
63,
515,
275,
283,
13574,
14,
2219,
14,
7765,
14,
396,
63,
5869,
14,
11324,
12906,
18,
7,
272,
922,
63,
576,
63,
633,
275,
283,
1014,
921,
5869,
14,
957,
15,
751,
7,
272,
1420,
63,
2473,
275,
283,
9664,
7,
272,
2879,
63,
1418,
63,
2030,
275,
2022,
14,
4180,
2561,
267,
283,
2732,
63,
1418,
356,
283,
9664,
297,
267,
283,
1418,
63,
466,
356,
283,
1235,
21462,
7,
272,
3828,
272,
922,
63,
576,
63,
2030,
275,
2022,
14,
4180,
2561,
267,
283,
344,
356,
413,
12,
267,
283,
2473,
356,
283,
9664,
297,
267,
283,
633,
356,
283,
1014,
921,
5869,
14,
957,
15,
751,
15,
9664,
297,
267,
283,
2246,
63,
354,
356,
283,
5686,
297,
267,
283,
2019,
63,
354,
356,
283,
5281,
297,
267,
283,
2123,
356,
283,
1421,
32,
1700,
14,
957,
7,
272,
3828,
339,
347,
511,
63,
2886,
8,
277,
304,
267,
291,
14,
1117,
63,
2886,
342,
339,
347,
511,
63,
6672,
63,
7379,
8,
277,
304,
267,
291,
14,
1117,
63,
6672,
63,
7379,
342,
339,
347,
511,
63,
4504,
8,
277,
304,
267,
922,
275,
291,
14,
1117,
63,
2886,
342,
267,
291,
14,
629,
8,
751,
14,
13574,
59,
16,
1055,
2732,
63,
1418,
12,
283,
9664,
358,
339,
347,
511,
63,
24445,
63,
1418,
8,
277,
304,
267,
291,
14,
8590,
14,
409,
63,
1751,
2561,
288,
283,
4118,
21212,
63,
5580,
63,
907,
10662,
2430,
63,
8803,
51,
63,
615,
63,
6178,
14657,
356,
715,
267,
3828,
267,
291,
14,
1117,
63,
2886,
342,
267,
922,
275,
2876,
14,
362,
8,
277,
14,
2062,
63,
2473,
9,
267,
922,
14,
2060,
275,
283,
2060,
7,
267,
3101,
21958,
14,
2683,
63,
2302,
8,
277,
423,
765,
8,
277,
14,
4620,
14,
907,
10662,
2430,
63,
8803,
63,
9977,
395,
3044,
291,
14,
4620,
14,
907,
10662,
2430,
63,
8803,
63,
2632,
12,
3044,
2004,
29,
1840,
9,
267,
886,
63,
10673,
8,
277,
14,
4620,
12,
922,
9,
421,
199,
533,
2816,
1175,
513,
7035,
26935,
8,
11324,
12906,
18,
774,
304,
272,
347,
511,
63,
1078,
63,
2886,
8,
277,
304,
267,
291,
14,
8590,
14,
409,
63,
1751,
2561,
288,
283,
4118,
21212,
63,
5580,
63,
18817,
4924,
1149,
63,
10089,
51,
356,
788,
1421,
32,
1700,
14,
957,
418,
267,
3828,
267,
291,
14,
1117,
63,
2886,
342,
339,
347,
511,
63,
3197,
63,
2886,
8,
277,
304,
267,
291,
14,
8590,
14,
409,
63,
1751,
2561,
288,
283,
4118,
21212,
63,
5580,
63,
18817,
4924,
1149,
63,
10089,
51,
356,
788,
1421,
18,
32,
1700,
14,
957,
418,
267,
3828,
267,
543,
291,
14,
1855,
8,
2817,
17454,
304,
288,
291,
14,
1117,
63,
2886,
342,
421,
199,
533,
2816,
1175,
513,
7705,
26935,
8,
11324,
12906,
18,
774,
304,
272,
347,
511,
63,
1078,
63,
2886,
8,
277,
304,
267,
291,
14,
8590,
14,
409,
63,
1751,
2561,
288,
283,
4118,
21212,
63,
5580,
63,
18817,
4924,
1149,
63,
7378,
51,
356,
788,
1700,
14,
957,
418,
267,
3828,
267,
291,
14,
1117,
63,
2886,
342,
339,
347,
511,
63,
3197,
63,
2886,
8,
277,
304,
267,
291,
14,
8590,
14,
409,
63,
1751,
2561,
288,
283,
4118,
21212,
63,
5580,
63,
18817,
4924,
1149,
63,
10089,
51,
356,
788,
1700,
18,
14,
957,
418,
267,
3828,
267,
543,
291,
14,
1855,
8,
2817,
17454,
304,
288,
291,
14,
1117,
63,
2886,
342,
421,
199,
4424,
6166,
275,
2197,
14,
7473,
8,
4899,
29,
17,
9,
421,
199,
533,
1316,
1038,
1754,
1366,
774,
8,
11324,
12906,
18,
774,
304,
272,
922,
63,
576,
63,
2030,
275,
2022,
14,
4180,
2561,
267,
283,
344,
356,
413,
12,
267,
283,
2473,
356,
283,
9664,
297,
267,
283,
633,
356,
283,
1014,
921,
5869,
14,
957,
15,
751,
15,
9664,
297,
267,
283,
2246,
63,
354,
356,
283,
5686,
297,
267,
283,
2019,
63,
354,
356,
283,
5281,
297,
267,
283,
2123,
356,
283,
1421,
32,
1700,
14,
957,
297,
267,
283,
12342,
356,
900,
14,
23456,
1332,
2083,
14,
2083,
14,
10779,
342,
435,
1816,
12355,
6166
] |
[
2022,
199,
646,
2197,
199,
646,
900,
199,
199,
504,
22768,
9118,
492,
3101,
21958,
199,
199,
504,
20295,
14,
3723,
492,
886,
63,
10673,
199,
504,
20295,
14,
7765,
14,
6126,
492,
3523,
12906,
18,
199,
504,
20295,
14,
3924,
492,
3590,
17454,
199,
199,
504,
20295,
14,
2219,
14,
992,
492,
2876,
199,
504,
20295,
14,
2219,
14,
7765,
14,
6126,
492,
11715,
18,
774,
421,
199,
533,
9762,
12906,
18,
8,
1563,
12906,
18,
304,
272,
536,
275,
283,
5869,
7,
272,
7560,
7123,
2594,
63,
2632,
275,
283,
1014,
921,
5869,
14,
957,
15,
6126,
15,
14204,
7,
272,
437,
10203,
63,
8803,
63,
2632,
275,
283,
1014,
921,
5869,
14,
957,
15,
6126,
15,
2732,
63,
1418,
7,
272,
5363,
10662,
2430,
63,
8803,
63,
2632,
275,
283,
2859,
921,
5869,
14,
957,
15,
6126,
15,
24445,
7,
272,
5363,
10662,
2430,
63,
8803,
63,
9977,
275,
283,
2970,
7,
272,
3651,
13954,
63,
3998,
275,
359,
267,
661,
344,
297,
283,
344,
659,
267,
661,
12342,
297,
283,
12342,
659,
267,
661,
1667,
297,
283,
1667,
297,
715,
395,
267,
283,
633,
7,
272,
1622,
339,
347,
664,
63,
751,
63,
5087,
8,
277,
12,
1177,
304,
267,
408,
1767,
922,
2436,
687,
598,
4049,
2933,
624,
267,
372,
791,
2473,
356,
1177,
14,
362,
360,
2473,
659,
355,
283,
2123,
356,
1177,
14,
362,
360,
2123,
297,
9929,
355,
283,
2246,
63,
354,
356,
1177,
14,
362,
360,
2246,
63,
354,
297,
9929,
355,
283,
2019,
63,
354,
356,
1177,
14,
362,
360,
2019,
63,
354,
297,
4074,
93,
339,
347,
922,
63,
576,
8,
277,
12,
2879,
63,
1418,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
30777,
922,
666,
687,
2435,
624,
267,
372,
291,
14,
362,
63,
1001,
360,
1014,
921,
5869,
14,
957,
15,
751,
297,
1862,
3126,
288,
283,
2732,
63,
1418,
356,
2879,
63,
1418,
267,
3828,
421,
199,
533,
9762,
12906,
18,
774,
8,
12906,
18,
774,
304,
272,
4865,
63,
515,
275,
283,
13574,
14,
2219,
14,
7765,
14,
396,
63,
5869,
14,
11324,
12906,
18,
7,
272,
922,
63,
576,
63,
633,
275,
283,
1014,
921,
5869,
14,
957,
15,
751,
7,
272,
1420,
63,
2473,
275,
283,
9664,
7,
272,
2879,
63,
1418,
63,
2030,
275,
2022,
14,
4180,
2561,
267,
283,
2732,
63,
1418,
356,
283,
9664,
297,
267,
283,
1418,
63,
466,
356,
283,
1235,
21462,
7,
272,
3828,
272,
922,
63,
576,
63,
2030,
275,
2022,
14,
4180,
2561,
267,
283,
344,
356,
413,
12,
267,
283,
2473,
356,
283,
9664,
297,
267,
283,
633,
356,
283,
1014,
921,
5869,
14,
957,
15,
751,
15,
9664,
297,
267,
283,
2246,
63,
354,
356,
283,
5686,
297,
267,
283,
2019,
63,
354,
356,
283,
5281,
297,
267,
283,
2123,
356,
283,
1421,
32,
1700,
14,
957,
7,
272,
3828,
339,
347,
511,
63,
2886,
8,
277,
304,
267,
291,
14,
1117,
63,
2886,
342,
339,
347,
511,
63,
6672,
63,
7379,
8,
277,
304,
267,
291,
14,
1117,
63,
6672,
63,
7379,
342,
339,
347,
511,
63,
4504,
8,
277,
304,
267,
922,
275,
291,
14,
1117,
63,
2886,
342,
267,
291,
14,
629,
8,
751,
14,
13574,
59,
16,
1055,
2732,
63,
1418,
12,
283,
9664,
358,
339,
347,
511,
63,
24445,
63,
1418,
8,
277,
304,
267,
291,
14,
8590,
14,
409,
63,
1751,
2561,
288,
283,
4118,
21212,
63,
5580,
63,
907,
10662,
2430,
63,
8803,
51,
63,
615,
63,
6178,
14657,
356,
715,
267,
3828,
267,
291,
14,
1117,
63,
2886,
342,
267,
922,
275,
2876,
14,
362,
8,
277,
14,
2062,
63,
2473,
9,
267,
922,
14,
2060,
275,
283,
2060,
7,
267,
3101,
21958,
14,
2683,
63,
2302,
8,
277,
423,
765,
8,
277,
14,
4620,
14,
907,
10662,
2430,
63,
8803,
63,
9977,
395,
3044,
291,
14,
4620,
14,
907,
10662,
2430,
63,
8803,
63,
2632,
12,
3044,
2004,
29,
1840,
9,
267,
886,
63,
10673,
8,
277,
14,
4620,
12,
922,
9,
421,
199,
533,
2816,
1175,
513,
7035,
26935,
8,
11324,
12906,
18,
774,
304,
272,
347,
511,
63,
1078,
63,
2886,
8,
277,
304,
267,
291,
14,
8590,
14,
409,
63,
1751,
2561,
288,
283,
4118,
21212,
63,
5580,
63,
18817,
4924,
1149,
63,
10089,
51,
356,
788,
1421,
32,
1700,
14,
957,
418,
267,
3828,
267,
291,
14,
1117,
63,
2886,
342,
339,
347,
511,
63,
3197,
63,
2886,
8,
277,
304,
267,
291,
14,
8590,
14,
409,
63,
1751,
2561,
288,
283,
4118,
21212,
63,
5580,
63,
18817,
4924,
1149,
63,
10089,
51,
356,
788,
1421,
18,
32,
1700,
14,
957,
418,
267,
3828,
267,
543,
291,
14,
1855,
8,
2817,
17454,
304,
288,
291,
14,
1117,
63,
2886,
342,
421,
199,
533,
2816,
1175,
513,
7705,
26935,
8,
11324,
12906,
18,
774,
304,
272,
347,
511,
63,
1078,
63,
2886,
8,
277,
304,
267,
291,
14,
8590,
14,
409,
63,
1751,
2561,
288,
283,
4118,
21212,
63,
5580,
63,
18817,
4924,
1149,
63,
7378,
51,
356,
788,
1700,
14,
957,
418,
267,
3828,
267,
291,
14,
1117,
63,
2886,
342,
339,
347,
511,
63,
3197,
63,
2886,
8,
277,
304,
267,
291,
14,
8590,
14,
409,
63,
1751,
2561,
288,
283,
4118,
21212,
63,
5580,
63,
18817,
4924,
1149,
63,
10089,
51,
356,
788,
1700,
18,
14,
957,
418,
267,
3828,
267,
543,
291,
14,
1855,
8,
2817,
17454,
304,
288,
291,
14,
1117,
63,
2886,
342,
421,
199,
4424,
6166,
275,
2197,
14,
7473,
8,
4899,
29,
17,
9,
421,
199,
533,
1316,
1038,
1754,
1366,
774,
8,
11324,
12906,
18,
774,
304,
272,
922,
63,
576,
63,
2030,
275,
2022,
14,
4180,
2561,
267,
283,
344,
356,
413,
12,
267,
283,
2473,
356,
283,
9664,
297,
267,
283,
633,
356,
283,
1014,
921,
5869,
14,
957,
15,
751,
15,
9664,
297,
267,
283,
2246,
63,
354,
356,
283,
5686,
297,
267,
283,
2019,
63,
354,
356,
283,
5281,
297,
267,
283,
2123,
356,
283,
1421,
32,
1700,
14,
957,
297,
267,
283,
12342,
356,
900,
14,
23456,
1332,
2083,
14,
2083,
14,
10779,
342,
435,
1816,
12355,
6166,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kmod/icbd
|
stdlib/python2.5/shelve.py
|
91
|
7565
|
"""Manage shelves of pickled objects.
A "shelf" is a persistent, dictionary-like object. The difference
with dbm databases is that the values (not the keys!) in a shelf can
be essentially arbitrary Python objects -- anything that the "pickle"
module can handle. This includes most class instances, recursive data
types, and objects containing lots of shared sub-objects. The keys
are ordinary strings.
To summarize the interface (key is a string, data is an arbitrary
object):
import shelve
d = shelve.open(filename) # open, with (g)dbm filename -- no suffix
d[key] = data # store data at key (overwrites old data if
# using an existing key)
data = d[key] # retrieve a COPY of the data at key (raise
# KeyError if no such key) -- NOTE that this
# access returns a *copy* of the entry!
del d[key] # delete data stored at key (raises KeyError
# if no such key)
flag = d.has_key(key) # true if the key exists; same as "key in d"
list = d.keys() # a list of all existing keys (slow!)
d.close() # close it
Dependent on the implementation, closing a persistent dictionary may
or may not be necessary to flush changes to disk.
Normally, d[key] returns a COPY of the entry. This needs care when
mutable entries are mutated: for example, if d[key] is a list,
d[key].append(anitem)
does NOT modify the entry d[key] itself, as stored in the persistent
mapping -- it only modifies the copy, which is then immediately
discarded, so that the append has NO effect whatsoever. To append an
item to d[key] in a way that will affect the persistent mapping, use:
data = d[key]
data.append(anitem)
d[key] = data
To avoid the problem with mutable entries, you may pass the keyword
argument writeback=True in the call to shelve.open. When you use:
d = shelve.open(filename, writeback=True)
then d keeps a cache of all entries you access, and writes them all back
to the persistent mapping when you call d.close(). This ensures that
such usage as d[key].append(anitem) works as intended.
However, using keyword argument writeback=True may consume vast amount
of memory for the cache, and it may make d.close() very slow, if you
access many of d's entries after opening it in this way: d has no way to
check which of the entries you access are mutable and/or which ones you
actually mutate, so it must cache, and write back at close, all of the
entries that you access. You can call d.sync() to write back all the
entries in the cache, and empty the cache (d.sync() also synchronizes
the persistent dictionary on disk, if feasible).
"""
# Try using cPickle and cStringIO if available.
try:
from cPickle import Pickler, Unpickler
except ImportError:
from pickle import Pickler, Unpickler
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
import UserDict
import warnings
__all__ = ["Shelf","BsdDbShelf","DbfilenameShelf","open"]
class Shelf(UserDict.DictMixin):
"""Base class for shelf implementations.
This is initialized with a dictionary-like object.
See the module's __doc__ string for an overview of the interface.
"""
def __init__(self, dict, protocol=None, writeback=False):
self.dict = dict
if protocol is None:
protocol = 0
self._protocol = protocol
self.writeback = writeback
self.cache = {}
def keys(self):
return self.dict.keys()
def __len__(self):
return len(self.dict)
def has_key(self, key):
return self.dict.has_key(key)
def __contains__(self, key):
return self.dict.has_key(key)
def get(self, key, default=None):
if self.dict.has_key(key):
return self[key]
return default
def __getitem__(self, key):
try:
value = self.cache[key]
except KeyError:
f = StringIO(self.dict[key])
value = Unpickler(f).load()
if self.writeback:
self.cache[key] = value
return value
def __setitem__(self, key, value):
if self.writeback:
self.cache[key] = value
f = StringIO()
p = Pickler(f, self._protocol)
p.dump(value)
self.dict[key] = f.getvalue()
def __delitem__(self, key):
del self.dict[key]
try:
del self.cache[key]
except KeyError:
pass
def close(self):
self.sync()
try:
self.dict.close()
except AttributeError:
pass
self.dict = 0
def __del__(self):
if not hasattr(self, 'writeback'):
# __init__ didn't succeed, so don't bother closing
return
self.close()
def sync(self):
if self.writeback and self.cache:
self.writeback = False
for key, entry in self.cache.iteritems():
self[key] = entry
self.writeback = True
self.cache = {}
if hasattr(self.dict, 'sync'):
self.dict.sync()
class BsdDbShelf(Shelf):
"""Shelf implementation using the "BSD" db interface.
This adds methods first(), next(), previous(), last() and
set_location() that have no counterpart in [g]dbm databases.
The actual database must be opened using one of the "bsddb"
modules "open" routines (i.e. bsddb.hashopen, bsddb.btopen or
bsddb.rnopen) and passed to the constructor.
See the module's __doc__ string for an overview of the interface.
"""
def __init__(self, dict, protocol=None, writeback=False):
Shelf.__init__(self, dict, protocol, writeback)
def set_location(self, key):
(key, value) = self.dict.set_location(key)
f = StringIO(value)
return (key, Unpickler(f).load())
def next(self):
(key, value) = self.dict.next()
f = StringIO(value)
return (key, Unpickler(f).load())
def previous(self):
(key, value) = self.dict.previous()
f = StringIO(value)
return (key, Unpickler(f).load())
def first(self):
(key, value) = self.dict.first()
f = StringIO(value)
return (key, Unpickler(f).load())
def last(self):
(key, value) = self.dict.last()
f = StringIO(value)
return (key, Unpickler(f).load())
class DbfilenameShelf(Shelf):
"""Shelf implementation using the "anydbm" generic dbm interface.
This is initialized with the filename for the dbm database.
See the module's __doc__ string for an overview of the interface.
"""
def __init__(self, filename, flag='c', protocol=None, writeback=False):
import anydbm
Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback)
def open(filename, flag='c', protocol=None, writeback=False):
"""Open a persistent dictionary for reading and writing.
The filename parameter is the base filename for the underlying
database. As a side-effect, an extension may be added to the
filename and more than one file may be created. The optional flag
parameter has the same interpretation as the flag parameter of
anydbm.open(). The optional protocol parameter specifies the
version of the pickle protocol (0, 1, or 2).
See the module's __doc__ string for an overview of the interface.
"""
return DbfilenameShelf(filename, flag, protocol, writeback)
|
mit
|
[
624,
20588,
1033,
352,
2310,
402,
18731,
2251,
14,
199,
199,
33,
298,
19195,
276,
2,
365,
282,
16149,
12,
2600,
13,
2930,
909,
14,
221,
710,
8865,
199,
1045,
31093,
16219,
365,
626,
314,
1338,
334,
1397,
314,
2883,
21866,
315,
282,
21920,
276,
883,
199,
1235,
28891,
9697,
2018,
2251,
1553,
7003,
626,
314,
298,
8092,
2,
199,
578,
883,
2429,
14,
221,
961,
6952,
4750,
1021,
4454,
12,
9133,
666,
199,
1313,
12,
436,
2251,
3035,
24213,
402,
5709,
1007,
13,
1462,
14,
221,
710,
2883,
199,
1530,
24801,
3326,
14,
199,
199,
1378,
22301,
314,
3217,
334,
498,
365,
282,
1059,
12,
666,
365,
376,
9697,
199,
785,
304,
398,
492,
1033,
15320,
267,
366,
275,
1033,
15320,
14,
1490,
8,
1501,
9,
327,
1551,
12,
543,
334,
71,
9,
20666,
1788,
1553,
949,
4739,
398,
366,
59,
498,
61,
275,
666,
257,
327,
3877,
666,
737,
790,
334,
1883,
16334,
2269,
666,
340,
717,
327,
1808,
376,
3411,
790,
9,
267,
666,
275,
366,
59,
498,
61,
257,
327,
8044,
282,
9357,
402,
314,
666,
737,
790,
334,
3730,
717,
327,
4067,
340,
949,
4066,
790,
9,
1553,
6944,
626,
642,
717,
327,
2879,
2529,
282,
627,
1574,
10,
402,
314,
2397,
1,
267,
2150,
366,
59,
498,
61,
420,
327,
3145,
666,
5489,
737,
790,
334,
3536,
4067,
717,
327,
340,
949,
4066,
790,
9,
267,
3305,
275,
366,
14,
1989,
63,
498,
8,
498,
9,
257,
327,
2549,
340,
314,
790,
3495,
27,
2011,
465,
298,
498,
315,
366,
2,
267,
769,
275,
366,
14,
1612,
342,
327,
282,
769,
402,
1006,
3411,
2883,
334,
14362,
21866,
398,
366,
14,
1600,
342,
755,
327,
4002,
652,
199,
199,
872,
5476,
641,
314,
4514,
12,
11261,
282,
16149,
2600,
1443,
199,
269,
1443,
440,
506,
5784,
370,
8976,
4493,
370,
4543,
14,
199,
199,
15548,
1183,
12,
366,
59,
498,
61,
2529,
282,
9357,
402,
314,
2397,
14,
221,
961,
4839,
10296,
1380,
199,
17404,
4811,
787,
8567,
972,
26,
367,
2893,
12,
340,
366,
59,
498,
61,
365,
282,
769,
12,
267,
366,
59,
498,
1055,
740,
8,
290,
1053,
9,
199,
9105,
2845,
2811,
314,
2397,
366,
59,
498,
61,
6337,
12,
465,
5489,
315,
314,
16149,
199,
4745,
1553,
652,
1454,
26473,
314,
1331,
12,
1314,
365,
2066,
9939,
199,
6409,
12910,
12,
880,
626,
314,
5666,
965,
4825,
7763,
4052,
1152,
5907,
14,
221,
4005,
5666,
376,
199,
1053,
370,
366,
59,
498,
61,
315,
282,
4340,
626,
911,
12787,
314,
16149,
4412,
12,
675,
26,
267,
666,
275,
366,
59,
498,
61,
267,
666,
14,
740,
8,
290,
1053,
9,
267,
366,
59,
498,
61,
275,
666,
199,
199,
1378,
5126,
314,
5160,
543,
17194,
4811,
12,
1265,
1443,
986,
314,
4252,
199,
2094,
2218,
894,
29,
549,
315,
314,
1240,
370,
1033,
15320,
14,
1490,
14,
221,
3979,
1265,
675,
26,
267,
366,
275,
1033,
15320,
14,
1490,
8,
1501,
12,
2218,
894,
29,
549,
9,
199,
12726,
366,
18578,
282,
2581,
402,
1006,
4811,
1265,
2879,
12,
436,
14511,
3062,
1006,
1771,
199,
475,
314,
16149,
4412,
1380,
1265,
1240,
366,
14,
1600,
1252,
221,
961,
15620,
626,
199,
10180,
4503,
465,
366,
59,
498,
1055,
740,
8,
290,
1053,
9,
5419,
465,
11619,
14,
199,
199,
18335,
5907,
12,
1808,
4252,
1423,
2218,
894,
29,
549,
1443,
9451,
373,
1810,
5982,
199,
1618,
4402,
367,
314,
2581,
12,
436,
652,
1443,
1852,
366,
14,
1600,
342,
7437,
11999,
12,
340,
1265,
199,
2732,
5002,
402,
366,
1159,
4811,
2410,
13618,
652,
315,
642,
4340,
26,
366,
965,
949,
4340,
370,
199,
1074,
1314,
402,
314,
4811,
1265,
2879,
787,
17194,
436,
15,
269,
1314,
7869,
1265,
199,
2442,
3163,
31173,
12,
880,
652,
1471,
2581,
12,
436,
2218,
1771,
737,
4002,
12,
1006,
402,
314,
199,
3189,
626,
1265,
2879,
14,
221,
2047,
883,
1240,
366,
14,
5186,
342,
370,
2218,
1771,
1006,
314,
199,
3189,
315,
314,
2581,
12,
436,
2701,
314,
2581,
334,
68,
14,
5186,
342,
2597,
15354,
6491,
199,
1589,
16149,
2600,
641,
4543,
12,
340,
1964,
305,
7247,
680,
199,
624,
199,
199,
3,
7649,
1808,
17572,
436,
15073,
340,
2808,
14,
199,
199,
893,
26,
272,
687,
17572,
492,
16568,
1435,
12,
1910,
23468,
199,
2590,
3545,
26,
272,
687,
5927,
492,
16568,
1435,
12,
1910,
23468,
199,
199,
893,
26,
272,
687,
15073,
492,
5228,
199,
2590,
3545,
26,
272,
687,
5228,
492,
5228,
199,
199,
646,
32241,
199,
646,
3598,
199,
199,
363,
452,
363,
275,
2097,
31306,
276,
2266,
34,
3893,
8882,
31306,
276,
2266,
8882,
1501,
31306,
276,
2266,
1490,
937,
199,
199,
533,
428,
426,
276,
8,
30088,
14,
2141,
4256,
304,
272,
408,
1563,
1021,
367,
21920,
276,
12591,
14,
339,
961,
365,
10038,
543,
282,
2600,
13,
2930,
909,
14,
272,
1666,
314,
859,
1159,
636,
1301,
363,
1059,
367,
376,
23503,
402,
314,
3217,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1211,
12,
4113,
29,
403,
12,
2218,
894,
29,
797,
304,
267,
291,
14,
807,
275,
1211,
267,
340,
4113,
365,
488,
26,
288,
4113,
275,
378,
267,
291,
423,
3922,
275,
4113,
267,
291,
14,
952,
894,
275,
2218,
894,
267,
291,
14,
1637,
275,
1052,
339,
347,
2883,
8,
277,
304,
267,
372,
291,
14,
807,
14,
1612,
342,
339,
347,
636,
552,
721,
277,
304,
267,
372,
822,
8,
277,
14,
807,
9,
339,
347,
965,
63,
498,
8,
277,
12,
790,
304,
267,
372,
291,
14,
807,
14,
1989,
63,
498,
8,
498,
9,
339,
347,
636,
6134,
721,
277,
12,
790,
304,
267,
372,
291,
14,
807,
14,
1989,
63,
498,
8,
498,
9,
339,
347,
664,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
340,
291,
14,
807,
14,
1989,
63,
498,
8,
498,
304,
288,
372,
291,
59,
498,
61,
267,
372,
849,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
862,
26,
288,
574,
275,
291,
14,
1637,
59,
498,
61,
267,
871,
4067,
26,
288,
289,
275,
5228,
8,
277,
14,
807,
59,
498,
566,
288,
574,
275,
1910
] |
[
20588,
1033,
352,
2310,
402,
18731,
2251,
14,
199,
199,
33,
298,
19195,
276,
2,
365,
282,
16149,
12,
2600,
13,
2930,
909,
14,
221,
710,
8865,
199,
1045,
31093,
16219,
365,
626,
314,
1338,
334,
1397,
314,
2883,
21866,
315,
282,
21920,
276,
883,
199,
1235,
28891,
9697,
2018,
2251,
1553,
7003,
626,
314,
298,
8092,
2,
199,
578,
883,
2429,
14,
221,
961,
6952,
4750,
1021,
4454,
12,
9133,
666,
199,
1313,
12,
436,
2251,
3035,
24213,
402,
5709,
1007,
13,
1462,
14,
221,
710,
2883,
199,
1530,
24801,
3326,
14,
199,
199,
1378,
22301,
314,
3217,
334,
498,
365,
282,
1059,
12,
666,
365,
376,
9697,
199,
785,
304,
398,
492,
1033,
15320,
267,
366,
275,
1033,
15320,
14,
1490,
8,
1501,
9,
327,
1551,
12,
543,
334,
71,
9,
20666,
1788,
1553,
949,
4739,
398,
366,
59,
498,
61,
275,
666,
257,
327,
3877,
666,
737,
790,
334,
1883,
16334,
2269,
666,
340,
717,
327,
1808,
376,
3411,
790,
9,
267,
666,
275,
366,
59,
498,
61,
257,
327,
8044,
282,
9357,
402,
314,
666,
737,
790,
334,
3730,
717,
327,
4067,
340,
949,
4066,
790,
9,
1553,
6944,
626,
642,
717,
327,
2879,
2529,
282,
627,
1574,
10,
402,
314,
2397,
1,
267,
2150,
366,
59,
498,
61,
420,
327,
3145,
666,
5489,
737,
790,
334,
3536,
4067,
717,
327,
340,
949,
4066,
790,
9,
267,
3305,
275,
366,
14,
1989,
63,
498,
8,
498,
9,
257,
327,
2549,
340,
314,
790,
3495,
27,
2011,
465,
298,
498,
315,
366,
2,
267,
769,
275,
366,
14,
1612,
342,
327,
282,
769,
402,
1006,
3411,
2883,
334,
14362,
21866,
398,
366,
14,
1600,
342,
755,
327,
4002,
652,
199,
199,
872,
5476,
641,
314,
4514,
12,
11261,
282,
16149,
2600,
1443,
199,
269,
1443,
440,
506,
5784,
370,
8976,
4493,
370,
4543,
14,
199,
199,
15548,
1183,
12,
366,
59,
498,
61,
2529,
282,
9357,
402,
314,
2397,
14,
221,
961,
4839,
10296,
1380,
199,
17404,
4811,
787,
8567,
972,
26,
367,
2893,
12,
340,
366,
59,
498,
61,
365,
282,
769,
12,
267,
366,
59,
498,
1055,
740,
8,
290,
1053,
9,
199,
9105,
2845,
2811,
314,
2397,
366,
59,
498,
61,
6337,
12,
465,
5489,
315,
314,
16149,
199,
4745,
1553,
652,
1454,
26473,
314,
1331,
12,
1314,
365,
2066,
9939,
199,
6409,
12910,
12,
880,
626,
314,
5666,
965,
4825,
7763,
4052,
1152,
5907,
14,
221,
4005,
5666,
376,
199,
1053,
370,
366,
59,
498,
61,
315,
282,
4340,
626,
911,
12787,
314,
16149,
4412,
12,
675,
26,
267,
666,
275,
366,
59,
498,
61,
267,
666,
14,
740,
8,
290,
1053,
9,
267,
366,
59,
498,
61,
275,
666,
199,
199,
1378,
5126,
314,
5160,
543,
17194,
4811,
12,
1265,
1443,
986,
314,
4252,
199,
2094,
2218,
894,
29,
549,
315,
314,
1240,
370,
1033,
15320,
14,
1490,
14,
221,
3979,
1265,
675,
26,
267,
366,
275,
1033,
15320,
14,
1490,
8,
1501,
12,
2218,
894,
29,
549,
9,
199,
12726,
366,
18578,
282,
2581,
402,
1006,
4811,
1265,
2879,
12,
436,
14511,
3062,
1006,
1771,
199,
475,
314,
16149,
4412,
1380,
1265,
1240,
366,
14,
1600,
1252,
221,
961,
15620,
626,
199,
10180,
4503,
465,
366,
59,
498,
1055,
740,
8,
290,
1053,
9,
5419,
465,
11619,
14,
199,
199,
18335,
5907,
12,
1808,
4252,
1423,
2218,
894,
29,
549,
1443,
9451,
373,
1810,
5982,
199,
1618,
4402,
367,
314,
2581,
12,
436,
652,
1443,
1852,
366,
14,
1600,
342,
7437,
11999,
12,
340,
1265,
199,
2732,
5002,
402,
366,
1159,
4811,
2410,
13618,
652,
315,
642,
4340,
26,
366,
965,
949,
4340,
370,
199,
1074,
1314,
402,
314,
4811,
1265,
2879,
787,
17194,
436,
15,
269,
1314,
7869,
1265,
199,
2442,
3163,
31173,
12,
880,
652,
1471,
2581,
12,
436,
2218,
1771,
737,
4002,
12,
1006,
402,
314,
199,
3189,
626,
1265,
2879,
14,
221,
2047,
883,
1240,
366,
14,
5186,
342,
370,
2218,
1771,
1006,
314,
199,
3189,
315,
314,
2581,
12,
436,
2701,
314,
2581,
334,
68,
14,
5186,
342,
2597,
15354,
6491,
199,
1589,
16149,
2600,
641,
4543,
12,
340,
1964,
305,
7247,
680,
199,
624,
199,
199,
3,
7649,
1808,
17572,
436,
15073,
340,
2808,
14,
199,
199,
893,
26,
272,
687,
17572,
492,
16568,
1435,
12,
1910,
23468,
199,
2590,
3545,
26,
272,
687,
5927,
492,
16568,
1435,
12,
1910,
23468,
199,
199,
893,
26,
272,
687,
15073,
492,
5228,
199,
2590,
3545,
26,
272,
687,
5228,
492,
5228,
199,
199,
646,
32241,
199,
646,
3598,
199,
199,
363,
452,
363,
275,
2097,
31306,
276,
2266,
34,
3893,
8882,
31306,
276,
2266,
8882,
1501,
31306,
276,
2266,
1490,
937,
199,
199,
533,
428,
426,
276,
8,
30088,
14,
2141,
4256,
304,
272,
408,
1563,
1021,
367,
21920,
276,
12591,
14,
339,
961,
365,
10038,
543,
282,
2600,
13,
2930,
909,
14,
272,
1666,
314,
859,
1159,
636,
1301,
363,
1059,
367,
376,
23503,
402,
314,
3217,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1211,
12,
4113,
29,
403,
12,
2218,
894,
29,
797,
304,
267,
291,
14,
807,
275,
1211,
267,
340,
4113,
365,
488,
26,
288,
4113,
275,
378,
267,
291,
423,
3922,
275,
4113,
267,
291,
14,
952,
894,
275,
2218,
894,
267,
291,
14,
1637,
275,
1052,
339,
347,
2883,
8,
277,
304,
267,
372,
291,
14,
807,
14,
1612,
342,
339,
347,
636,
552,
721,
277,
304,
267,
372,
822,
8,
277,
14,
807,
9,
339,
347,
965,
63,
498,
8,
277,
12,
790,
304,
267,
372,
291,
14,
807,
14,
1989,
63,
498,
8,
498,
9,
339,
347,
636,
6134,
721,
277,
12,
790,
304,
267,
372,
291,
14,
807,
14,
1989,
63,
498,
8,
498,
9,
339,
347,
664,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
340,
291,
14,
807,
14,
1989,
63,
498,
8,
498,
304,
288,
372,
291,
59,
498,
61,
267,
372,
849,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
862,
26,
288,
574,
275,
291,
14,
1637,
59,
498,
61,
267,
871,
4067,
26,
288,
289,
275,
5228,
8,
277,
14,
807,
59,
498,
566,
288,
574,
275,
1910,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
chokribr/invenio
|
invenio/modules/formatter/format_elements/bfe_video_platform_sources.py
|
13
|
5200
|
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 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.
"""BibFormat element
* Part of the video platform prototype
* Creates a <select> element with <option> elements
containing various information about video sources. The options are later
evaluated by javascript and the video source is dynamically injected in the
HTML5 video element.
* Based on bfe_video_selector.py
"""
from six import iteritems
from invenio.legacy.bibdocfile.api import BibRecDocs
def format_element(bfo):
""" Format element function to create the select and option elements
with HTML5 data attributes that store all the necesarry metadata to
construct video sources with JavaScript."""
videos = {
'360p': {'width': 640, 'height': 360, 'poster': None, 'mp4': None, 'webm': None, 'ogv': None},
'480p': {'width': 854,'height': 480, 'poster': None, 'mp4': None, 'webm': None, 'ogv': None,},
'720p': {'width': 1280, 'height': 720, 'poster': None, 'mp4': None, 'webm': None, 'ogv': None},
'1080p': {'width': 1920, 'height': 1080, 'poster': None, 'mp4': None, 'webm': None, 'ogv': None}
}
recdoc = BibRecDocs(bfo.recID)
bibdocs = recdoc.list_bibdocs()
## Go through all the BibDocs and search for video related signatures
for bibdoc in bibdocs:
bibdocfiles = bibdoc.list_all_files()
for bibdocfile in bibdocfiles:
## When a video signature is found, add the url to the videos dictionary
if bibdocfile.get_superformat() in ('.mp4', '.webm', '.ogv') and bibdocfile.get_subformat() in ('360p', '480p', '720p', '1080p'):
src = bibdocfile.get_url()
codec = bibdocfile.get_superformat()[1:]
size = bibdocfile.get_subformat()
videos[size][codec] = src
## When a poster signature is found, add the url to the videos dictionary
elif bibdocfile.get_comment() in ('SUGGESTIONTUMB', 'BIGTHUMB', 'POSTER', 'SMALLTHUMB') and bibdocfile.get_subformat() in ('360p', '480p', '720p', '1080p'):
src = bibdocfile.get_url()
size = bibdocfile.get_subformat()
videos[size]['poster'] = src
## Build video select options for every video size format that was found
select_options = []
for key, options in iteritems(videos):
## If we have at least one url, the format is available
if options['mp4'] or options['webm'] or options['ogv']:
## create am option element
option_element = create_option_element(url_webm=options['webm'], url_ogv=options['ogv'], url_mp4=options['mp4'],
url_poster=options['poster'], width=options['width'], height=options['height'],
subformat=key)
select_options.append(option_element)
select_element = create_select_element(select_options)
return select_element
def create_select_element(options):
""" Creates the HTML select element that carries the video format options
"""
text = """<select id="mejs-resolution">
%s
</select>
""" % '\n'.join(options)
return text
def create_option_element(width, height, subformat, url_webm=None, url_ogv=None, url_mp4=None, url_poster=None,):
""" Creates an HTML option element that carries all video information
"""
if url_webm:
webm = """data-src-webm="%s" data-type-webm='video/webm; codecs="vp8, vorbis"'""" % url_webm
else:
webm = ""
if url_ogv:
ogv = """data-src-ogg="%s" data-type-ogv='video/ogv; codecs="theora, vorbis"'""" % url_ogv
else:
ogv = ""
if url_mp4:
mp4 = """data-src-mp4="%s" data-type-mp4='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'""" % url_mp4
else:
mp4 = ""
text = """<option %(webm)s %(ogv)s %(mp4)s data-poster="%(url_poster)s" data-video-width="%(width)spx" data-video-height="%(height)spx">%(subformat)s</option>""" % {
'webm': webm,
'ogv': ogv,
'mp4': mp4,
'url_poster': url_poster,
'width': width,
'height': height,
'subformat': subformat
}
return text
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
7760,
24354,
14,
199,
3,
199,
3,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
624,
25217,
3484,
1819,
199,
10,
14320,
402,
314,
3991,
4298,
19393,
199,
10,
10560,
282,
665,
2416,
30,
1819,
543,
665,
1422,
30,
4008,
523,
3035,
7750,
2556,
3595,
3991,
5274,
14,
710,
1511,
787,
2945,
523,
13006,
701,
18910,
436,
314,
3991,
1350,
365,
18774,
26121,
315,
314,
523,
4163,
21,
3991,
1819,
14,
199,
10,
21311,
641,
330,
771,
63,
3722,
63,
6662,
14,
647,
199,
624,
199,
199,
504,
3816,
492,
10849,
199,
504,
13640,
14,
10000,
14,
26415,
493,
14,
1246,
492,
21949,
21561,
27858,
199,
199,
318,
1475,
63,
2108,
8,
66,
545,
304,
272,
408,
9701,
1819,
805,
370,
1218,
314,
3504,
436,
945,
4008,
272,
543,
4163,
21,
666,
3004,
626,
3877,
1006,
314,
1279,
823,
285,
651,
3341,
370,
272,
6982,
3991,
5274,
543,
15250,
1041,
272,
22010,
275,
469,
1467,
283,
11197,
80,
356,
791,
2063,
356,
5049,
16,
12,
283,
3333,
356,
19434,
12,
283,
20801,
356,
488,
12,
283,
311,
20,
356,
488,
12,
283,
30504,
356,
488,
12,
283,
974,
86,
356,
488,
1386,
1467,
283,
21853,
80,
356,
791,
2063,
356,
1695,
1477,
2584,
3333,
356,
29504,
12,
283,
20801,
356,
488,
12,
283,
311,
20,
356,
488,
12,
283,
30504,
356,
488,
12,
283,
974,
86,
356,
488,
12,
1386,
1467,
283,
18386,
80,
356,
791,
2063,
356,
3144,
1257,
12,
283,
3333,
356,
29692,
12,
283,
20801,
356,
488,
12,
283,
311,
20,
356,
488,
12,
283,
30504,
356,
488,
12,
283,
974,
86,
356,
488,
1386,
1467,
283,
23514,
80,
356,
791,
2063,
356,
5851,
1165,
12,
283,
3333,
356,
1616,
1257,
12,
283,
20801,
356,
488,
12,
283,
311,
20,
356,
488,
12,
283,
30504,
356,
488,
12,
283,
974,
86,
356,
488,
93,
1467,
789,
272,
6488,
1301,
275,
21949,
21561,
27858,
8,
66,
545,
14,
2761,
998,
9,
272,
11314,
4757,
275,
6488,
1301,
14,
513,
63,
8804,
4757,
342,
272,
925,
3971,
4012,
1006,
314,
21949,
27858,
436,
2754,
367,
3991,
4048,
17597,
272,
367,
23682,
315,
11314,
4757,
26,
267,
23682,
1725,
275,
23682,
14,
513,
63,
452,
63,
1725,
342,
267,
367,
23682,
493,
315,
23682,
1725,
26,
288,
925,
3979,
282,
3991,
4955,
365,
1911,
12,
1050,
314,
1166,
370,
314,
22010,
2600,
288,
340,
23682,
493,
14,
362,
63,
4792,
908,
342,
315,
23500,
311,
20,
297,
1987,
30504,
297,
1987,
974,
86,
358,
436,
23682,
493,
14,
362,
63,
954,
908,
342,
315,
661,
11197,
80,
297,
283,
21853,
80,
297,
283,
18386,
80,
297,
283,
23514,
80,
735,
355,
2928,
275,
23682,
493,
14,
362,
63,
633,
342,
355,
9076,
275,
23682,
493,
14,
362,
63,
4792,
908,
3430,
17,
2938,
355,
1568,
275,
23682,
493,
14,
362,
63,
954,
908,
342,
355,
22010,
59,
890,
1527,
9276,
61,
275,
2928,
288,
925,
3979,
282,
2086,
351,
4955,
365,
1911,
12,
1050,
314,
1166,
370,
314,
22010,
2600,
288,
916,
23682,
493,
14,
362,
63,
3349,
342,
315,
661,
6195,
2916,
19212,
52,
2639,
34,
297,
283,
18643,
2080,
2639,
34,
297,
283,
4030,
540,
297,
283,
28570,
2080,
2639,
34,
358,
436,
23682,
493,
14,
362,
63,
954,
908,
342,
315,
661,
11197,
80,
297,
283,
21853,
80,
297,
283,
18386,
80,
297,
283,
23514,
80,
735,
355,
2928,
275,
23682,
493,
14,
362,
63,
633,
342,
355,
1568,
275,
23682,
493,
14,
362,
63,
954,
908,
342,
355,
22010,
59,
890,
2733,
20801,
418,
275,
2928,
272,
925,
6516,
3991,
3504,
1511,
367,
4036,
3991,
1568,
1475,
626,
1990,
1911,
272,
3504,
63,
1419,
275,
942,
272,
367,
790,
12,
1511,
315,
10849,
8,
11418,
304,
267,
925,
982,
781,
1172,
737,
5210,
1373,
1166,
12,
314,
1475,
365,
2808,
267,
340,
1511,
459,
311,
20,
418,
503,
1511,
459,
30504,
418,
503,
1511,
459,
974,
86,
2565,
288,
925,
1218,
8140,
945,
1819,
288,
945,
63,
2108,
275,
1218,
63,
1422,
63,
2108,
8,
633,
63,
30504,
29,
1419,
459,
30504,
995,
1166,
63,
974,
86,
29,
1419,
459,
974,
86,
995,
1166,
63,
311,
20,
29,
1419,
459,
311,
20,
995,
8962,
1166,
63,
20801,
29,
1419,
459,
20801,
995,
3462,
29,
1419,
459,
2063,
995,
4569,
29,
1419,
459,
3333,
995,
8962,
1007,
908,
29,
498,
9,
288,
3504,
63,
1419,
14,
740,
8,
1422,
63,
2108,
9,
272,
3504,
63,
2108,
275,
1218,
63,
2416,
63,
2108,
8,
2416,
63,
1419,
9,
272,
372,
3504,
63,
2108,
199,
199,
318,
1218,
63,
2416,
63,
2108,
8,
1419,
304,
272,
408,
10560,
314,
4163,
3504,
1819,
626,
9590,
1996,
314,
3991,
1475,
1511,
272,
408,
272,
1318,
275,
8894,
2416,
1305,
628,
278,
3596,
13,
12588,
1743,
1598,
450,
83,
1598,
3068,
2416,
30,
1779,
408,
450,
1557,
78,
1370,
904,
8,
1419,
9,
272,
372,
1318,
421,
199,
318,
1218,
63,
1422,
63,
2108,
8,
2063,
12,
4569,
12,
1007,
908,
12,
1166,
63,
30504,
29,
403,
12,
1166,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
7760,
24354,
14,
199,
3,
199,
3,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
624,
25217,
3484,
1819,
199,
10,
14320,
402,
314,
3991,
4298,
19393,
199,
10,
10560,
282,
665,
2416,
30,
1819,
543,
665,
1422,
30,
4008,
523,
3035,
7750,
2556,
3595,
3991,
5274,
14,
710,
1511,
787,
2945,
523,
13006,
701,
18910,
436,
314,
3991,
1350,
365,
18774,
26121,
315,
314,
523,
4163,
21,
3991,
1819,
14,
199,
10,
21311,
641,
330,
771,
63,
3722,
63,
6662,
14,
647,
199,
624,
199,
199,
504,
3816,
492,
10849,
199,
504,
13640,
14,
10000,
14,
26415,
493,
14,
1246,
492,
21949,
21561,
27858,
199,
199,
318,
1475,
63,
2108,
8,
66,
545,
304,
272,
408,
9701,
1819,
805,
370,
1218,
314,
3504,
436,
945,
4008,
272,
543,
4163,
21,
666,
3004,
626,
3877,
1006,
314,
1279,
823,
285,
651,
3341,
370,
272,
6982,
3991,
5274,
543,
15250,
1041,
272,
22010,
275,
469,
1467,
283,
11197,
80,
356,
791,
2063,
356,
5049,
16,
12,
283,
3333,
356,
19434,
12,
283,
20801,
356,
488,
12,
283,
311,
20,
356,
488,
12,
283,
30504,
356,
488,
12,
283,
974,
86,
356,
488,
1386,
1467,
283,
21853,
80,
356,
791,
2063,
356,
1695,
1477,
2584,
3333,
356,
29504,
12,
283,
20801,
356,
488,
12,
283,
311,
20,
356,
488,
12,
283,
30504,
356,
488,
12,
283,
974,
86,
356,
488,
12,
1386,
1467,
283,
18386,
80,
356,
791,
2063,
356,
3144,
1257,
12,
283,
3333,
356,
29692,
12,
283,
20801,
356,
488,
12,
283,
311,
20,
356,
488,
12,
283,
30504,
356,
488,
12,
283,
974,
86,
356,
488,
1386,
1467,
283,
23514,
80,
356,
791,
2063,
356,
5851,
1165,
12,
283,
3333,
356,
1616,
1257,
12,
283,
20801,
356,
488,
12,
283,
311,
20,
356,
488,
12,
283,
30504,
356,
488,
12,
283,
974,
86,
356,
488,
93,
1467,
789,
272,
6488,
1301,
275,
21949,
21561,
27858,
8,
66,
545,
14,
2761,
998,
9,
272,
11314,
4757,
275,
6488,
1301,
14,
513,
63,
8804,
4757,
342,
272,
925,
3971,
4012,
1006,
314,
21949,
27858,
436,
2754,
367,
3991,
4048,
17597,
272,
367,
23682,
315,
11314,
4757,
26,
267,
23682,
1725,
275,
23682,
14,
513,
63,
452,
63,
1725,
342,
267,
367,
23682,
493,
315,
23682,
1725,
26,
288,
925,
3979,
282,
3991,
4955,
365,
1911,
12,
1050,
314,
1166,
370,
314,
22010,
2600,
288,
340,
23682,
493,
14,
362,
63,
4792,
908,
342,
315,
23500,
311,
20,
297,
1987,
30504,
297,
1987,
974,
86,
358,
436,
23682,
493,
14,
362,
63,
954,
908,
342,
315,
661,
11197,
80,
297,
283,
21853,
80,
297,
283,
18386,
80,
297,
283,
23514,
80,
735,
355,
2928,
275,
23682,
493,
14,
362,
63,
633,
342,
355,
9076,
275,
23682,
493,
14,
362,
63,
4792,
908,
3430,
17,
2938,
355,
1568,
275,
23682,
493,
14,
362,
63,
954,
908,
342,
355,
22010,
59,
890,
1527,
9276,
61,
275,
2928,
288,
925,
3979,
282,
2086,
351,
4955,
365,
1911,
12,
1050,
314,
1166,
370,
314,
22010,
2600,
288,
916,
23682,
493,
14,
362,
63,
3349,
342,
315,
661,
6195,
2916,
19212,
52,
2639,
34,
297,
283,
18643,
2080,
2639,
34,
297,
283,
4030,
540,
297,
283,
28570,
2080,
2639,
34,
358,
436,
23682,
493,
14,
362,
63,
954,
908,
342,
315,
661,
11197,
80,
297,
283,
21853,
80,
297,
283,
18386,
80,
297,
283,
23514,
80,
735,
355,
2928,
275,
23682,
493,
14,
362,
63,
633,
342,
355,
1568,
275,
23682,
493,
14,
362,
63,
954,
908,
342,
355,
22010,
59,
890,
2733,
20801,
418,
275,
2928,
272,
925,
6516,
3991,
3504,
1511,
367,
4036,
3991,
1568,
1475,
626,
1990,
1911,
272,
3504,
63,
1419,
275,
942,
272,
367,
790,
12,
1511,
315,
10849,
8,
11418,
304,
267,
925,
982,
781,
1172,
737,
5210,
1373,
1166,
12,
314,
1475,
365,
2808,
267,
340,
1511,
459,
311,
20,
418,
503,
1511,
459,
30504,
418,
503,
1511,
459,
974,
86,
2565,
288,
925,
1218,
8140,
945,
1819,
288,
945,
63,
2108,
275,
1218,
63,
1422,
63,
2108,
8,
633,
63,
30504,
29,
1419,
459,
30504,
995,
1166,
63,
974,
86,
29,
1419,
459,
974,
86,
995,
1166,
63,
311,
20,
29,
1419,
459,
311,
20,
995,
8962,
1166,
63,
20801,
29,
1419,
459,
20801,
995,
3462,
29,
1419,
459,
2063,
995,
4569,
29,
1419,
459,
3333,
995,
8962,
1007,
908,
29,
498,
9,
288,
3504,
63,
1419,
14,
740,
8,
1422,
63,
2108,
9,
272,
3504,
63,
2108,
275,
1218,
63,
2416,
63,
2108,
8,
2416,
63,
1419,
9,
272,
372,
3504,
63,
2108,
199,
199,
318,
1218,
63,
2416,
63,
2108,
8,
1419,
304,
272,
408,
10560,
314,
4163,
3504,
1819,
626,
9590,
1996,
314,
3991,
1475,
1511,
272,
408,
272,
1318,
275,
8894,
2416,
1305,
628,
278,
3596,
13,
12588,
1743,
1598,
450,
83,
1598,
3068,
2416,
30,
1779,
408,
450,
1557,
78,
1370,
904,
8,
1419,
9,
272,
372,
1318,
421,
199,
318,
1218,
63,
1422,
63,
2108,
8,
2063,
12,
4569,
12,
1007,
908,
12,
1166,
63,
30504,
29,
403,
12,
1166,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
BeiLuoShiMen/nupic
|
nupic/regions/PictureSensorExplorers/vertical.py
|
17
|
1762
|
# ----------------------------------------------------------------------
# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2013, Numenta, Inc. Unless you have an agreement
# with Numenta, Inc., for a separate license for this software code, the
# following terms and conditions apply:
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero Public License for more details.
#
# You should have received a copy of the GNU Affero Public License
# along with this program. If not, see http://www.gnu.org/licenses.
#
# http://numenta.org/licenses/
# ----------------------------------------------------------------------
"""
This file defines VerticalPictureExplorer, an explorer for
PictureSensor.
"""
# Third-party imports
import numpy
# Local imports
from nupic.regions.PictureSensorExplorers.random import RandomPictureExplorer
class VerticalPictureExplorer(RandomPictureExplorer):
"""
Specialization of 'random' explorer that allows vertical
sweeps only.
"""
def initSequence(self, state, params):
# Invoke base class
super(VerticalPictureExplorer, self).initSequence(state, params)
# Force horizontal velocity to be zero
state['velocityX'] = 0
# Make sure we don't allow stationary (no velocity)
if state['velocityY'] == 0:
state['velocityY'] = self._rng.choice(numpy.array([-1, 1], dtype=int) \
* max(1, params['minVelocity']))
|
agpl-3.0
|
[
3,
20359,
199,
3,
22783,
16078,
367,
8883,
24024,
27799,
334,
21988,
26769,
9,
199,
3,
1898,
334,
35,
9,
6171,
12,
22783,
12,
3277,
14,
221,
4158,
1265,
1172,
376,
25025,
199,
3,
543,
22783,
12,
3277,
2020,
367,
282,
7396,
4190,
367,
642,
2032,
1233,
12,
314,
199,
3,
2569,
2895,
436,
3704,
4838,
26,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1684,
844,
1015,
650,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
4265,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
199,
3,
1455,
921,
78,
18952,
14,
1308,
15,
2383,
15,
199,
3,
20359,
199,
199,
624,
199,
2765,
570,
7890,
5444,
3294,
29439,
4527,
22732,
12,
376,
15868,
3859,
367,
199,
29439,
10160,
14,
199,
624,
199,
199,
3,
31079,
13,
7522,
8925,
199,
646,
2680,
199,
199,
3,
10111,
8925,
199,
504,
26084,
14,
11963,
14,
29439,
10160,
4527,
320,
21105,
14,
2355,
492,
9571,
29439,
4527,
22732,
4388,
199,
533,
5444,
3294,
29439,
4527,
22732,
8,
3883,
29439,
4527,
22732,
304,
523,
408,
523,
12568,
2072,
402,
283,
2355,
7,
15868,
3859,
626,
6127,
13763,
523,
5584,
1024,
1190,
1454,
14,
523,
408,
819,
347,
4205,
5826,
8,
277,
12,
1174,
12,
1862,
304,
272,
327,
31049,
1300,
1021,
272,
1613,
8,
19462,
29439,
4527,
22732,
12,
291,
680,
826,
5826,
8,
929,
12,
1862,
9,
272,
327,
18771,
17528,
20508,
370,
506,
4697,
272,
1174,
459,
16350,
56,
418,
275,
378,
272,
327,
4155,
3238,
781,
2793,
1133,
2040,
16518,
695,
334,
889,
20508,
9,
272,
340,
1174,
459,
16350,
57,
418,
508,
378,
26,
489,
1174,
459,
16350,
57,
418,
275,
291,
423,
12686,
14,
5095,
8,
4714,
14,
1144,
11468,
17,
12,
413,
467,
2152,
29,
442,
9,
971,
586,
627,
1390,
8,
17,
12,
1862,
459,
827,
23213,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
20359,
199,
3,
22783,
16078,
367,
8883,
24024,
27799,
334,
21988,
26769,
9,
199,
3,
1898,
334,
35,
9,
6171,
12,
22783,
12,
3277,
14,
221,
4158,
1265,
1172,
376,
25025,
199,
3,
543,
22783,
12,
3277,
2020,
367,
282,
7396,
4190,
367,
642,
2032,
1233,
12,
314,
199,
3,
2569,
2895,
436,
3704,
4838,
26,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1684,
844,
1015,
650,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
4265,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
199,
3,
1455,
921,
78,
18952,
14,
1308,
15,
2383,
15,
199,
3,
20359,
199,
199,
624,
199,
2765,
570,
7890,
5444,
3294,
29439,
4527,
22732,
12,
376,
15868,
3859,
367,
199,
29439,
10160,
14,
199,
624,
199,
199,
3,
31079,
13,
7522,
8925,
199,
646,
2680,
199,
199,
3,
10111,
8925,
199,
504,
26084,
14,
11963,
14,
29439,
10160,
4527,
320,
21105,
14,
2355,
492,
9571,
29439,
4527,
22732,
4388,
199,
533,
5444,
3294,
29439,
4527,
22732,
8,
3883,
29439,
4527,
22732,
304,
523,
408,
523,
12568,
2072,
402,
283,
2355,
7,
15868,
3859,
626,
6127,
13763,
523,
5584,
1024,
1190,
1454,
14,
523,
408,
819,
347,
4205,
5826,
8,
277,
12,
1174,
12,
1862,
304,
272,
327,
31049,
1300,
1021,
272,
1613,
8,
19462,
29439,
4527,
22732,
12,
291,
680,
826,
5826,
8,
929,
12,
1862,
9,
272,
327,
18771,
17528,
20508,
370,
506,
4697,
272,
1174,
459,
16350,
56,
418,
275,
378,
272,
327,
4155,
3238,
781,
2793,
1133,
2040,
16518,
695,
334,
889,
20508,
9,
272,
340,
1174,
459,
16350,
57,
418,
508,
378,
26,
489,
1174,
459,
16350,
57,
418,
275,
291,
423,
12686,
14,
5095,
8,
4714,
14,
1144,
11468,
17,
12,
413,
467,
2152,
29,
442,
9,
971,
586,
627,
1390,
8,
17,
12,
1862,
459,
827,
23213,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
40123103/2015cd_40123103
|
wsgi.py
|
1
|
34518
|
#@+leo-ver=5-thin
#@+node:2014fall.20141212095015.1775: * @file wsgi.py
# coding=utf-8
# 上面的程式內容編碼必須在程式的第一或者第二行才會有作用
################# (1) 模組導入區
# 導入 cherrypy 模組, 為了在 OpenShift 平台上使用 cherrypy 模組, 必須透過 setup.py 安裝
#@@language python
#@@tabwidth -4
#@+<<declarations>>
#@+node:2014fall.20141212095015.1776: ** <<declarations>> (wsgi)
import cherrypy
# 導入 Python 內建的 os 模組, 因為 os 模組為 Python 內建, 所以無需透過 setup.py 安裝
import os
# 導入 random 模組
import random
# 導入 gear 模組
import gear
################# (2) 廣域變數設定區
# 確定程式檔案所在目錄, 在 Windows 下有最後的反斜線
_curdir = os.path.join(os.getcwd(), os.path.dirname(__file__))
# 設定在雲端與近端的資料儲存目錄
if 'OPENSHIFT_REPO_DIR' in os.environ.keys():
# 表示程式在雲端執行
download_root_dir = os.environ['OPENSHIFT_DATA_DIR']
data_dir = os.environ['OPENSHIFT_DATA_DIR']
else:
# 表示程式在近端執行
download_root_dir = _curdir + "/local_data/"
data_dir = _curdir + "/local_data/"
'''以下為近端 input() 與 for 迴圈應用的程式碼, 若要將程式送到 OpenShift 執行, 除了採用 CherryPy 網際框架外, 還要轉為 html 列印
# 利用 input() 取得的資料型別為字串
toprint = input("要印甚麼內容?")
# 若要將 input() 取得的字串轉為整數使用, 必須利用 int() 轉換
repeat_no = int(input("重複列印幾次?"))
for i in range(repeat_no):
print(toprint)
'''
#@-<<declarations>>
#@+others
#@+node:2014fall.20141212095015.1777: ** class Hello
################# (3) 程式類別定義區
# 以下改用 CherryPy 網際框架程式架構
# 以下為 Hello 類別的設計內容, 其中的 object 使用, 表示 Hello 類別繼承 object 的所有特性, 包括方法與屬性設計
class Hello(object):
# Hello 類別的啟動設定
_cp_config = {
'tools.encode.encoding': 'utf-8',
'tools.sessions.on' : True,
'tools.sessions.storage_type' : 'file',
#'tools.sessions.locking' : 'explicit',
# session 以檔案儲存, 而且位於 data_dir 下的 tmp 目錄
'tools.sessions.storage_path' : data_dir+'/tmp',
# session 有效時間設為 60 分鐘
'tools.sessions.timeout' : 60
}
#@+others
#@+node:2014fall.20141212095015.2004: *3* __init__
def __init__(self):
# 配合透過案例啟始建立所需的目錄
if not os.path.isdir(data_dir+'/tmp'):
os.mkdir(data_dir+'/tmp')
if not os.path.isdir(data_dir+"/downloads"):
os.mkdir(data_dir+"/downloads")
if not os.path.isdir(data_dir+"/images"):
os.mkdir(data_dir+"/images")
#@+node:2014fall.20141212095015.1778: *3* index_orig
# 以 @ 開頭的 cherrypy.expose 為 decorator, 用來表示隨後的成員方法, 可以直接讓使用者以 URL 連結執行
@cherrypy.expose
# index 方法為 CherryPy 各類別成員方法中的內建(default)方法, 當使用者執行時未指定方法, 系統將會優先執行 index 方法
# 有 self 的方法為類別中的成員方法, Python 程式透過此一 self 在各成員方法間傳遞物件內容
def index_orig(self, toprint="Hello World!"):
return toprint
#@+node:2014fall.20141212095015.1779: *3* hello
@cherrypy.expose
def hello(self, toprint="Hello World!"):
return toprint
#@+node:2014fall.20141215194146.1791: *3* index
@cherrypy.expose
def two(self, guess=None):
# 將標準答案存入 answer session 對應區
theanswer = random.randint(1, 100)
thecount = 0
# 將答案與計算次數變數存進 session 對應變數
cherrypy.session['answer'] = theanswer
cherrypy.session['count'] = thecount
# 印出讓使用者輸入的超文件表單
outstring = '''
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<!-- 載入 brython.js -->
<script type="text/javascript" src="/static/Brython3.1.1-20150328-091302/brython.js"></script>
<script src="/static/Cango2D.js" type="text/javascript"></script>
<script src="/static/gearUtils-04.js" type="text/javascript"></script>
</head>
<!-- 啟動 brython() -->
<body onload="brython()">
<form method=POST action=doCheck>
請輸入您所猜的整數:<input type=text name=guess><br />
<input type=submit value=send>
</form>
<hr>
<!-- 以下在網頁內嵌 Brython 程式 -->
<script type="text/python">
from browser import document, alert
def echo(ev):
alert(document["zone"].value)
# 將文件中名稱為 mybutton 的物件, 透過 click 事件與 echo 函式 bind 在一起
document['mybutton'].bind('click',echo)
</script>
<input id="zone"><button id="mybutton">click !</button>
<hr>
<!-- 以下為 canvas 畫圖程式 -->
<script type="text/python">
# 從 browser 導入 document
from browser import document
import math
# 畫布指定在名稱為 plotarea 的 canvas 上
# 以下使用中文變數名稱
canvas = document["plotarea"]
ctx = canvas.getContext("2d")
# 用紅色畫一條直線
ctx.beginPath()
ctx.lineWidth = 3
ctx.moveTo(0, 0)
ctx.lineTo(0, 500)
ctx.strokeStyle = "red"
ctx.stroke()
# 用藍色再畫一條直線
ctx.beginPath()
ctx.lineWidth = 3
ctx.moveTo(0, 0)
ctx.lineTo(500, 0)
ctx.strokeStyle = "blue"
ctx.stroke()
# 用綠色再畫一條直線
ctx.beginPath()
ctx.lineWidth = 3
ctx.moveTo(0, 0)
ctx.lineTo(500, 500)
ctx.strokeStyle = "green"
ctx.stroke()
# 用黑色畫一個圓
ctx.beginPath()
ctx.lineWidth = 3
ctx.strokeStyle = "black"
ctx.arc(250,250,50,0,2*math.pi)
ctx.stroke()
</script>
<canvas id="plotarea" width="800" height="600"></canvas>
</body>
</html>
'''
return outstring
#@+node:2015.20150330144929.1713: *3* twoDgear
@cherrypy.expose
# A齒數1,B齒數2,C齒數3,D齒數4,E齒數5,F齒數6, M 為模數, P 為壓力角
def index(self,A=None,B=None,C=None,D=None, E=None, F=None, M=None, P=None):
outstring = '''
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<!-- 載入 brython.js -->
<script type="text/javascript" src="/static/Brython3.1.1-20150328-091302/brython.js"></script>
<script src="/static/Cango2D.js" type="text/javascript"></script>
<script src="/static/gearUtils-04.js" type="text/javascript"></script>
40123103<br>周于婷
</head>
<!-- 啟動 brython() -->
<body onload="brython()">
<form method=POST action=mygeartest2>
<p>齒數1:
<select name=A>
<option>10
<option>11
<option>12
<option>13
<option>14
<option>15
<option>16
<option>17
<option>18
<option>19
<option>20
<option>21
<option>22
<option>23
<option>24
<option>25
<option>26
<option>27
<option>28
<option>29
<option>30
</select>
<p>齒數2:
<select name=B>
<option>10
<option>11
<option>12
<option>13
<option>14
<option>15
<option>16
<option>17
<option>18
<option>19
<option>20
<option>21
<option>22
<option>23
<option>24
<option>25
<option>26
<option>27
<option>28
<option>29
<option>30
</select>
<p>齒數3:
<select name=C>
<option>10
<option>11
<option>12
<option>13
<option>14
<option>15
<option>16
<option>17
<option>18
<option>19
<option>20
<option>21
<option>22
<option>23
<option>24
<option>25
<option>26
<option>27
<option>28
<option>29
<option>30
</select>
<p>齒數4:
<select name=D>
<option>10
<option>11
<option>12
<option>13
<option>14
<option>15
<option>16
<option>17
<option>18
<option>19
<option>20
<option>21
<option>22
<option>23
<option>24
<option>25
<option>26
<option>27
<option>28
<option>29
<option>30
</select>
<p>齒數5:
<select name=E>
<option>10
<option>11
<option>12
<option>13
<option>14
<option>15
<option>16
<option>17
<option>18
<option>19
<option>20
<option>21
<option>22
<option>23
<option>24
<option>25
<option>26
<option>27
<option>28
<option>29
<option>30
</select>
</select>
<p>齒數6:
<select name=F>
<option>10
<option>11
<option>12
<option>13
<option>14
<option>15
<option>16
<option>17
<option>18
<option>19
<option>20
<option>21
<option>22
<option>23
<option>24
<option>25
<option>26
<option>27
<option>28
<option>29
<option>30
</select>
<p>模數:
<select name=M>
<option>2
<option>3
<option>4
<option>5
<option>6
<option>7
<option>8
<option>9
<option>10
<option>11
<option>12
<option>13
<option>14
<option>15
<option>16
<option>17
<option>18
<option>19
<option>20
<option>21
<option>22
<option>23
<option>24
<option>25
</select>
<p>壓力角:
<select name=P>
<option>14.5
<option>15.0
<option>15.5
<option>16.0
<option>16.5
<option>17.0
<option>17.5
<option>18.0
<option>18.5
<option>19.0
<option>19.5
<option>20.0
<option>20.5
<option>21.0
<option>21.5
<option>22.0
<option>22.5
</select>
</br>
<input type=submit value=send>
</form>
</body>
</html>
'''
return outstring
#@+node:2015.20150331094055.1733: *3* threeDgear
@cherrypy.expose
# N 為齒數, M 為模數, P 為壓力角
def threeDgear(self, N=20, M=5, P=15):
outstring = '''
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<!-- 載入 brython.js -->
<script type="text/javascript" src="/static/Brython3.1.1-20150328-091302/brython.js"></script>
<script src="/static/Cango2D.js" type="text/javascript"></script>
<script src="/static/gearUtils-04.js" type="text/javascript"></script>
</head>
<!-- 啟動 brython() -->
<body onload="brython()">
<form method=POST action=do3Dgear>
齒數:<input type=text name=N><br />
模數:<input type=text name=M><br />
壓力角:<input type=text name=P><br />
<input type=submit value=send>
</form>
</body>
</html>
'''
return outstring
#@+node:2015.20150330144929.1762: *3* do2Dgear
@cherrypy.expose
# N 為齒數, M 為模數, P 為壓力角
def do2Dgear(self, N=20, M=5, P=15):
outstring = '''
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<!-- 載入 brython.js -->
<script type="text/javascript" src="/static/Brython3.1.1-20150328-091302/brython.js"></script>
<script src="/static/Cango2D.js" type="text/javascript"></script>
<script src="/static/gearUtils-04.js" type="text/javascript"></script>
</head>
<!-- 啟動 brython() -->
<body onload="brython()">
<!-- 以下為 canvas 畫圖程式 -->
<script type="text/python">
# 從 browser 導入 document
from browser import document
import math
# 畫布指定在名稱為 plotarea 的 canvas 上
canvas = document["plotarea"]
ctx = canvas.getContext("2d")
# 用紅色畫一條直線
ctx.beginPath()
ctx.lineWidth = 3
'''
outstring += '''
ctx.moveTo('''+str(N)+","+str(M)+")"
outstring += '''
ctx.lineTo(0, 500)
ctx.strokeStyle = "red"
ctx.stroke()
# 用藍色再畫一條直線
ctx.beginPath()
ctx.lineWidth = 3
ctx.moveTo(0, 0)
ctx.lineTo(500, 0)
ctx.strokeStyle = "blue"
ctx.stroke()
# 用綠色再畫一條直線
ctx.beginPath()
ctx.lineWidth = 3
ctx.moveTo(0, 0)
ctx.lineTo(500, 500)
ctx.strokeStyle = "green"
ctx.stroke()
# 用黑色畫一個圓
ctx.beginPath()
ctx.lineWidth = 3
ctx.strokeStyle = "black"
ctx.arc(250,250,50,0,2*math.pi)
ctx.stroke()
</script>
<canvas id="plotarea" width="800" height="600"></canvas>
</body>
</html>
'''
return outstring
#@+node:2015.20150331094055.1735: *3* do3Dgear
@cherrypy.expose
# N 為齒數, M 為模數, P 為壓力角
def do3Dgear(self, N=20, M=5, P=15):
outstring = '''
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<!-- 載入 brython.js -->
<script type="text/javascript" src="/static/Brython3.1.1-20150328-091302/brython.js"></script>
<script src="/static/Cango2D.js" type="text/javascript"></script>
<script src="/static/gearUtils-04.js" type="text/javascript"></script>
</head>
<!-- 啟動 brython() -->
<body onload="brython()">
<!-- 以下為 canvas 畫圖程式 -->
<script type="text/python">
# 從 browser 導入 document
from browser import document
import math
# 畫布指定在名稱為 plotarea 的 canvas 上
canvas = document["plotarea"]
ctx = canvas.getContext("2d")
# 用紅色畫一條直線
ctx.beginPath()
ctx.lineWidth = 3
'''
outstring += '''
ctx.moveTo('''+str(N)+","+str(M)+")"
outstring += '''
ctx.lineTo(0, 500)
ctx.strokeStyle = "red"
ctx.stroke()
# 用藍色再畫一條直線
ctx.beginPath()
ctx.lineWidth = 3
ctx.moveTo(0, 0)
ctx.lineTo(500, 0)
ctx.strokeStyle = "blue"
ctx.stroke()
# 用綠色再畫一條直線
ctx.beginPath()
ctx.lineWidth = 3
ctx.moveTo(0, 0)
ctx.lineTo(500, 500)
ctx.strokeStyle = "green"
ctx.stroke()
# 用黑色畫一個圓
ctx.beginPath()
ctx.lineWidth = 3
ctx.strokeStyle = "black"
ctx.arc(250,250,50,0,2*math.pi)
ctx.stroke()
</script>
<canvas id="plotarea" width="800" height="600"></canvas>
</body>
</html>
'''
return outstring
#@+node:2015.20150330144929.1765: *3* mygeartest
@cherrypy.expose
# N 為齒數, M 為模數, P 為壓力角
def mygeartest(self, N=20, M=5, P=15):
outstring = '''
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<!-- 載入 brython.js -->
<script type="text/javascript" src="/static/Brython3.1.1-20150328-091302/brython.js"></script>
<script src="/static/Cango2D.js" type="text/javascript"></script>
<script src="/static/gearUtils-04.js" type="text/javascript"></script>
</head>
<!-- 啟動 brython() -->
<body onload="brython()">
<!-- 以下為 canvas 畫圖程式 -->
<script type="text/python">
# 從 browser 導入 document
from browser import document
from math import *
# 準備在 id="plotarea" 的 canvas 中繪圖
canvas = document["plotarea"]
ctx = canvas.getContext("2d")
def create_line(x1, y1, x2, y2, width=3, fill="red"):
ctx.beginPath()
ctx.lineWidth = width
ctx.moveTo(x1, y1)
ctx.lineTo(x2, y2)
ctx.strokeStyle = fill
ctx.stroke()
# 導入數學函式後, 圓周率為 pi
# deg 為角度轉為徑度的轉換因子
deg = pi/180.
#
# 以下分別為正齒輪繪圖與主 tkinter 畫布繪圖
#
# 定義一個繪正齒輪的繪圖函式
# midx 為齒輪圓心 x 座標
# midy 為齒輪圓心 y 座標
# rp 為節圓半徑, n 為齒數
def 齒輪(midx, midy, rp, n, 顏色):
# 將角度轉換因子設為全域變數
global deg
# 齒輪漸開線分成 15 線段繪製
imax = 15
# 在輸入的畫布上繪製直線, 由圓心到節圓 y 軸頂點畫一直線
create_line(midx, midy, midx, midy-rp)
# 畫出 rp 圓, 畫圓函式尚未定義
#create_oval(midx-rp, midy-rp, midx+rp, midy+rp, width=2)
# a 為模數 (代表公制中齒的大小), 模數為節圓直徑(稱為節徑)除以齒數
# 模數也就是齒冠大小
a=2*rp/n
# d 為齒根大小, 為模數的 1.157 或 1.25倍, 這裡採 1.25 倍
d=2.5*rp/n
# ra 為齒輪的外圍半徑
ra=rp+a
print("ra:", ra)
# 畫出 ra 圓, 畫圓函式尚未定義
#create_oval(midx-ra, midy-ra, midx+ra, midy+ra, width=1)
# rb 則為齒輪的基圓半徑
# 基圓為漸開線長齒之基準圓
rb=rp*cos(20*deg)
print("rp:", rp)
print("rb:", rb)
# 畫出 rb 圓 (基圓), 畫圓函式尚未定義
#create_oval(midx-rb, midy-rb, midx+rb, midy+rb, width=1)
# rd 為齒根圓半徑
rd=rp-d
# 當 rd 大於 rb 時
print("rd:", rd)
# 畫出 rd 圓 (齒根圓), 畫圓函式尚未定義
#create_oval(midx-rd, midy-rd, midx+rd, midy+rd, width=1)
# dr 則為基圓到齒頂圓半徑分成 imax 段後的每段半徑增量大小
# 將圓弧分成 imax 段來繪製漸開線
dr=(ra-rb)/imax
# tan(20*deg)-20*deg 為漸開線函數
sigma=pi/(2*n)+tan(20*deg)-20*deg
for j in range(n):
ang=-2.*j*pi/n+sigma
ang2=2.*j*pi/n+sigma
lxd=midx+rd*sin(ang2-2.*pi/n)
lyd=midy-rd*cos(ang2-2.*pi/n)
#for(i=0;i<=imax;i++):
for i in range(imax+1):
r=rb+i*dr
theta=sqrt((r*r)/(rb*rb)-1.)
alpha=theta-atan(theta)
xpt=r*sin(alpha-ang)
ypt=r*cos(alpha-ang)
xd=rd*sin(-ang)
yd=rd*cos(-ang)
# i=0 時, 繪線起點由齒根圓上的點, 作為起點
if(i==0):
last_x = midx+xd
last_y = midy-yd
# 由左側齒根圓作為起點, 除第一點 (xd,yd) 齒根圓上的起點外, 其餘的 (xpt,ypt)則為漸開線上的分段點
create_line((midx+xpt),(midy-ypt),(last_x),(last_y),fill=顏色)
# 最後一點, 則為齒頂圓
if(i==imax):
lfx=midx+xpt
lfy=midy-ypt
last_x = midx+xpt
last_y = midy-ypt
# the line from last end of dedendum point to the recent
# end of dedendum point
# lxd 為齒根圓上的左側 x 座標, lyd 則為 y 座標
# 下列為齒根圓上用來近似圓弧的直線
create_line((lxd),(lyd),(midx+xd),(midy-yd),fill=顏色)
#for(i=0;i<=imax;i++):
for i in range(imax+1):
r=rb+i*dr
theta=sqrt((r*r)/(rb*rb)-1.)
alpha=theta-atan(theta)
xpt=r*sin(ang2-alpha)
ypt=r*cos(ang2-alpha)
xd=rd*sin(ang2)
yd=rd*cos(ang2)
# i=0 時, 繪線起點由齒根圓上的點, 作為起點
if(i==0):
last_x = midx+xd
last_y = midy-yd
# 由右側齒根圓作為起點, 除第一點 (xd,yd) 齒根圓上的起點外, 其餘的 (xpt,ypt)則為漸開線上的分段點
create_line((midx+xpt),(midy-ypt),(last_x),(last_y),fill=顏色)
# 最後一點, 則為齒頂圓
if(i==imax):
rfx=midx+xpt
rfy=midy-ypt
last_x = midx+xpt
last_y = midy-ypt
# lfx 為齒頂圓上的左側 x 座標, lfy 則為 y 座標
# 下列為齒頂圓上用來近似圓弧的直線
create_line(lfx,lfy,rfx,rfy,fill=顏色)
齒輪(400,400,300,41,"blue")
</script>
<canvas id="plotarea" width="800" height="800"></canvas>
</body>
</html>
'''
return outstring
#@+node:amd.20150415215023.1: *3* mygeartest2
@cherrypy.expose
# A齒數1,B齒數2,C齒數3,D齒數4,E齒數5,F齒數6, M 為模數, P 為壓力角
def mygeartest2(self,A=15,B=17,C=15,D=17, E=15, F=17, M=5, P=15):
outstring = '''
<!DOCTYPE html>
<html>
<head>
<a href='/index'>返回</a>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<!-- 載入 brython.js -->
<script type="text/javascript" src="/static/Brython3.1.1-20150328-091302/brython.js"></script>
<script src="/static/Cango2D.js" type="text/javascript"></script>
<script src="/static/gearUtils-04.js" type="text/javascript"></script>
</head>
<!-- 啟動 brython() -->
<body onload="brython()">
<!-- 以下為 canvas 畫圖程式 -->
<script type="text/python">
# 從 browser 導入 document
from browser import document
from math import *
# 請注意, 這裡導入位於 Lib/site-packages 目錄下的 spur.py 檔案
import spur
# 準備在 id="plotarea" 的 canvas 中繪圖
canvas = document["plotarea"]
ctx = canvas.getContext("2d")
# 以下利用 spur.py 程式進行繪圖, 接下來的協同設計運算必須要配合使用者的需求進行設計運算與繪圖
# 其中並將工作分配給其他組員建立類似 spur.py 的相關零件繪圖模組
# midx, midy 為齒輪圓心座標, rp 為節圓半徑, n 為齒數, pa 為壓力角, color 為線的顏色
# Gear(midx, midy, rp, n=20, pa=20, color="black"):
# 模數決定齒的尺寸大小, 囓合齒輪組必須有相同的模數與壓力角
# 壓力角 pa 單位為角度
pa ='''+str(P)+'''
# m 為模數
m = '''+str(M)+'''
# 第1齒輪齒數
n_g1 = '''+str(A)+'''
# 第2齒輪齒數
n_g2 = '''+str(B)+'''
# 第3齒輪齒數
n_g3 = '''+str(C)+'''
# 第4齒輪齒數
n_g4 = '''+str(D)+'''
# 第5齒輪齒數
n_g5 = '''+str(E)+'''
# 第6齒輪齒數
n_g6 = '''+str(F)+'''
# 計算兩齒輪的節圓半徑
rp_g1 = m*n_g1/2
rp_g2 = m*n_g2/2
rp_g3 = m*n_g3/2
rp_g4 = m*n_g4/2
rp_g5 = m*n_g5/2
rp_g6 = m*n_g6/2
# 繪圖第1齒輪的圓心座標
x_g1 = 280
y_g1 = 400
# 第2齒輪的圓心座標, 假設排列成水平, 表示各齒輪圓心 y 座標相同
x_g2 = x_g1 + rp_g1 + rp_g2
y_g2 = y_g1
# 第3齒輪的圓心座標
x_g3 = x_g1 + rp_g1 + 2*rp_g2 + rp_g3
y_g3 = y_g1
# 第4齒輪的圓心座標
x_g4 = x_g1 + rp_g1 + 2*rp_g2 +2* rp_g3+ rp_g4
y_g4 = y_g1
# 第5齒輪的圓心座標
x_g5 = x_g1 + rp_g1 + 2*rp_g2 +2* rp_g3+2* rp_g4 + rp_g5
y_g5 = y_g1
# 第6齒輪的圓心座標
x_g6 = x_g1 + rp_g1 + 2*rp_g2 +2* rp_g3+2* rp_g4+2*rp_g5+rp_g6
y_g6 = y_g1
# 將第1齒輪順時鐘轉 90 度
# 使用 ctx.save() 與 ctx.restore() 以確保各齒輪以相對座標進行旋轉繪圖
ctx.save()
# translate to the origin of second gear
ctx.translate(x_g1, y_g1)
# rotate to engage
ctx.rotate(pi/2)
# put it back
ctx.translate(-x_g1, -y_g1)
spur.Spur(ctx).Gear(x_g1, y_g1, rp_g1, n_g1, pa, "red")
ctx.restore()
# 將第2齒輪逆時鐘轉 90 度之後, 再多轉一齒, 以便與第1齒輪進行囓合
ctx.save()
# translate to the origin of second gear
ctx.translate(x_g2, y_g2)
# rotate to engage
ctx.rotate(-pi/2-pi/n_g2)
# put it back
ctx.translate(-x_g2, -y_g2)
spur.Spur(ctx).Gear(x_g2, y_g2, rp_g2, n_g2, pa, "Orange")
ctx.restore()
# 將第3齒輪逆時鐘轉 90 度之後, 再往回轉第2齒輪定位帶動轉角, 然後再逆時鐘多轉一齒, 以便與第2齒輪進行囓合
ctx.save()
# translate to the origin of second gear
ctx.translate(x_g3, y_g3)
# rotate to engage
# pi+pi/n_g2 為第2齒輪從順時鐘轉 90 度之後, 必須配合目前的標記線所作的齒輪 2 轉動角度, 要轉換到齒輪3 的轉動角度
# 必須乘上兩齒輪齒數的比例, 若齒輪2 大, 則齒輪3 會轉動較快
# 第1個 -pi/2 為將原先垂直的第3齒輪定位線逆時鐘旋轉 90 度
# -pi/n_g3 則是第3齒與第2齒定位線重合後, 必須再逆時鐘多轉一齒的轉角, 以便進行囓合
# (pi+pi/n_g2)*n_g2/n_g3 則是第2齒原定位線為順時鐘轉動 90 度,
# 但是第2齒輪為了與第1齒輪囓合, 已經距離定位線, 多轉了 180 度, 再加上第2齒輪的一齒角度, 因為要帶動第3齒輪定位,
# 這個修正角度必須要再配合第2齒與第3齒的轉速比加以轉換成第3齒輪的轉角, 因此乘上 n_g2/n_g3
ctx.rotate(-pi/2-pi/n_g3+(pi+pi/n_g2)*n_g2/n_g3)
# put it back
ctx.translate(-x_g3, -y_g3)
spur.Spur(ctx).Gear(x_g3, y_g3, rp_g3, n_g3, pa, "yellow")
ctx.restore()
#第4齒輪
ctx.save()
# translate to the origin of second gear
ctx.translate(x_g4, y_g4)
# rotate to engage
ctx.rotate(-pi/2+(pi+pi/n_g3)*n_g3/n_g4)
# put it back
ctx.translate(-x_g4, -y_g4)
spur.Spur(ctx).Gear(x_g4, y_g4, rp_g4, n_g4, pa, "green")
ctx.restore()
#第5齒輪
ctx.save()
# translate to the origin of second gear
ctx.translate(x_g5, y_g5)
# rotate to engage
ctx.rotate(-pi/2-pi/n_g5+(pi+pi/n_g4)*n_g4/n_g5)
# put it back
ctx.translate(-x_g5, -y_g5)
spur.Spur(ctx).Gear(x_g5, y_g5, rp_g5, n_g5, pa, "blue")
ctx.restore()
#第6齒輪(囓合有問題)
ctx.save()
# translate to the origin of second gear
ctx.translate(x_g6, y_g6)
# rotate to engage
ctx.rotate(-pi/2+pi/n_g6+(pi+pi/n_g5)*n_g5/n_g6)
# put it back
ctx.translate(-x_g6, -y_g6)
spur.Spur(ctx).Gear(x_g6, y_g6, rp_g6, n_g6, pa, "purple")
ctx.restore()
</script>
<canvas id="plotarea" width="4000" height="1200"></canvas>
</body>
</html>
'''
return outstring
#@+node:2015.20150331094055.1737: *3* my3Dgeartest
@cherrypy.expose
# N 為齒數, M 為模數, P 為壓力角
def my3Dgeartest(self, N=20, M=5, P=15):
outstring = '''
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<!-- 載入 brython.js -->
<script type="text/javascript" src="/static/Brython3.1.1-20150328-091302/brython.js"></script>
<script src="/static/Cango2D.js" type="text/javascript"></script>
<script src="/static/gearUtils-04.js" type="text/javascript"></script>
</head>
<!-- 啟動 brython() -->
<body onload="brython()">
<!-- 以下為 canvas 畫圖程式 -->
<script type="text/python">
# 從 browser 導入 document
from browser import document
from math import *
# 準備在 id="plotarea" 的 canvas 中繪圖
canvas = document["plotarea"]
ctx = canvas.getContext("2d")
def create_line(x1, y1, x2, y2, width=3, fill="red"):
ctx.beginPath()
ctx.lineWidth = width
ctx.moveTo(x1, y1)
ctx.lineTo(x2, y2)
ctx.strokeStyle = fill
ctx.stroke()
# 導入數學函式後, 圓周率為 pi
# deg 為角度轉為徑度的轉換因子
deg = pi/180.
#
# 以下分別為正齒輪繪圖與主 tkinter 畫布繪圖
#
# 定義一個繪正齒輪的繪圖函式
# midx 為齒輪圓心 x 座標
# midy 為齒輪圓心 y 座標
# rp 為節圓半徑, n 為齒數
def gear(midx, midy, rp, n, 顏色):
# 將角度轉換因子設為全域變數
global deg
# 齒輪漸開線分成 15 線段繪製
imax = 15
# 在輸入的畫布上繪製直線, 由圓心到節圓 y 軸頂點畫一直線
create_line(midx, midy, midx, midy-rp)
# 畫出 rp 圓, 畫圓函式尚未定義
#create_oval(midx-rp, midy-rp, midx+rp, midy+rp, width=2)
# a 為模數 (代表公制中齒的大小), 模數為節圓直徑(稱為節徑)除以齒數
# 模數也就是齒冠大小
a=2*rp/n
# d 為齒根大小, 為模數的 1.157 或 1.25倍, 這裡採 1.25 倍
d=2.5*rp/n
# ra 為齒輪的外圍半徑
ra=rp+a
print("ra:", ra)
# 畫出 ra 圓, 畫圓函式尚未定義
#create_oval(midx-ra, midy-ra, midx+ra, midy+ra, width=1)
# rb 則為齒輪的基圓半徑
# 基圓為漸開線長齒之基準圓
rb=rp*cos(20*deg)
print("rp:", rp)
print("rb:", rb)
# 畫出 rb 圓 (基圓), 畫圓函式尚未定義
#create_oval(midx-rb, midy-rb, midx+rb, midy+rb, width=1)
# rd 為齒根圓半徑
rd=rp-d
# 當 rd 大於 rb 時
print("rd:", rd)
# 畫出 rd 圓 (齒根圓), 畫圓函式尚未定義
#create_oval(midx-rd, midy-rd, midx+rd, midy+rd, width=1)
# dr 則為基圓到齒頂圓半徑分成 imax 段後的每段半徑增量大小
# 將圓弧分成 imax 段來繪製漸開線
dr=(ra-rb)/imax
# tan(20*deg)-20*deg 為漸開線函數
sigma=pi/(2*n)+tan(20*deg)-20*deg
for j in range(n):
ang=-2.*j*pi/n+sigma
ang2=2.*j*pi/n+sigma
lxd=midx+rd*sin(ang2-2.*pi/n)
lyd=midy-rd*cos(ang2-2.*pi/n)
#for(i=0;i<=imax;i++):
for i in range(imax+1):
r=rb+i*dr
theta=sqrt((r*r)/(rb*rb)-1.)
alpha=theta-atan(theta)
xpt=r*sin(alpha-ang)
ypt=r*cos(alpha-ang)
xd=rd*sin(-ang)
yd=rd*cos(-ang)
# i=0 時, 繪線起點由齒根圓上的點, 作為起點
if(i==0):
last_x = midx+xd
last_y = midy-yd
# 由左側齒根圓作為起點, 除第一點 (xd,yd) 齒根圓上的起點外, 其餘的 (xpt,ypt)則為漸開線上的分段點
create_line((midx+xpt),(midy-ypt),(last_x),(last_y),fill=顏色)
# 最後一點, 則為齒頂圓
if(i==imax):
lfx=midx+xpt
lfy=midy-ypt
last_x = midx+xpt
last_y = midy-ypt
# the line from last end of dedendum point to the recent
# end of dedendum point
# lxd 為齒根圓上的左側 x 座標, lyd 則為 y 座標
# 下列為齒根圓上用來近似圓弧的直線
create_line((lxd),(lyd),(midx+xd),(midy-yd),fill=顏色)
#for(i=0;i<=imax;i++):
for i in range(imax+1):
r=rb+i*dr
theta=sqrt((r*r)/(rb*rb)-1.)
alpha=theta-atan(theta)
xpt=r*sin(ang2-alpha)
ypt=r*cos(ang2-alpha)
xd=rd*sin(ang2)
yd=rd*cos(ang2)
# i=0 時, 繪線起點由齒根圓上的點, 作為起點
if(i==0):
last_x = midx+xd
last_y = midy-yd
# 由右側齒根圓作為起點, 除第一點 (xd,yd) 齒根圓上的起點外, 其餘的 (xpt,ypt)則為漸開線上的分段點
create_line((midx+xpt),(midy-ypt),(last_x),(last_y),fill=顏色)
# 最後一點, 則為齒頂圓
if(i==imax):
rfx=midx+xpt
rfy=midy-ypt
last_x = midx+xpt
last_y = midy-ypt
# lfx 為齒頂圓上的左側 x 座標, lfy 則為 y 座標
# 下列為齒頂圓上用來近似圓弧的直線
create_line(lfx,lfy,rfx,rfy,fill=顏色)
gear(400,400,300,41,"blue")
</script>
<canvas id="plotarea" width="800" height="800"></canvas>
</body>
</html>
'''
return outstring
#@+node:2014fall.20141215194146.1793: *3* doCheck
@cherrypy.expose
def doCheck(self, guess=None):
# 假如使用者直接執行 doCheck, 則設法轉回根方法
if guess is None:
raise cherrypy.HTTPRedirect("/")
# 從 session 取出 answer 對應資料, 且處理直接執行 doCheck 時無法取 session 值情況
try:
theanswer = int(cherrypy.session.get('answer'))
except:
raise cherrypy.HTTPRedirect("/")
# 經由表單所取得的 guess 資料型別為 string
try:
theguess = int(guess)
except:
return "error " + self.guessform()
# 每執行 doCheck 一次,次數增量一次
cherrypy.session['count'] += 1
# 答案與所猜數字進行比對
if theanswer < theguess:
return "big " + self.guessform()
elif theanswer > theguess:
return "small " + self.guessform()
else:
# 已經猜對, 從 session 取出累計猜測次數
thecount = cherrypy.session.get('count')
return "exact: <a href=''>再猜</a>"
#@+node:2014fall.20141215194146.1789: *3* guessform
def guessform(self):
# 印出讓使用者輸入的超文件表單
outstring = str(cherrypy.session.get('answer')) + "/" + str(cherrypy.session.get('count')) + '''<form method=POST action=doCheck>
請輸入您所猜的整數:<input type=text name=guess><br />
<input type=submit value=send>
</form>'''
return outstring
#@-others
#@-others
################# (4) 程式啟動區
# 配合程式檔案所在目錄設定靜態目錄或靜態檔案
application_conf = {'/static':{
'tools.staticdir.on': True,
# 程式執行目錄下, 必須自行建立 static 目錄
'tools.staticdir.dir': _curdir+"/static"},
'/downloads':{
'tools.staticdir.on': True,
'tools.staticdir.dir': data_dir+"/downloads"},
'/images':{
'tools.staticdir.on': True,
'tools.staticdir.dir': data_dir+"/images"}
}
root = Hello()
root.gear = gear.Gear()
if 'OPENSHIFT_REPO_DIR' in os.environ.keys():
# 表示在 OpenSfhit 執行
application = cherrypy.Application(root, config=application_conf)
else:
# 表示在近端執行
cherrypy.quickstart(root, config=application_conf)
#@-leo
|
gpl-3.0
|
[
17577,
11,
274,
79,
13,
422,
29,
21,
13,
24474,
199,
17577,
11,
932,
26,
7280,
70,
452,
14,
7280,
25481,
1643,
8216,
21,
14,
8881,
21,
26,
627,
768,
493,
12464,
14,
647,
199,
3,
2803,
29,
1624,
13,
24,
199,
3,
221,
22661,
26398,
96,
8106,
30664,
21041,
8379,
101,
10270,
118,
27035,
102,
164,
96,
121,
16989,
228,
166,
255,
231,
21448,
30664,
21041,
8106,
25238,
106,
9372,
9077,
245,
18497,
25238,
106,
6923,
235,
12609,
10862,
236,
6587,
226,
20916,
21927,
11428,
199,
199,
749,
3,
334,
17,
9,
8853,
102,
95,
23767,
227,
15348,
237,
18236,
10450,
223,
199,
3,
7094,
109,
237,
18236,
13397,
8853,
102,
95,
23767,
227,
12,
9112,
18760,
30998,
21448,
3232,
14379,
7094,
118,
112,
6075,
109,
22661,
30026,
13397,
8853,
102,
95,
23767,
227,
12,
7094,
124,
228,
166,
255,
231,
14333,
238,
24744,
237,
3272,
14,
647,
7094,
107,
232,
29655,
252,
421,
199,
3,
7492,
3671,
2366,
199,
3,
7492,
2902,
2063,
446,
20,
199,
199,
17577,
11,
8999,
21200,
1140,
199,
17577,
11,
932,
26,
7280,
70,
452,
14,
7280,
25481,
1643,
8216,
21,
14,
8881,
22,
26,
1011,
5213,
21200,
1140,
334,
6508,
9,
199,
646,
13397,
199,
3,
7094,
109,
237,
18236,
2018,
7094,
228,
101,
29427,
119,
8106,
747,
8853,
102,
95,
23767,
227,
12,
7094,
250,
255,
24889,
747,
8853,
102,
95,
23767,
227,
24889,
2018,
7094,
228,
101,
29427,
119,
12,
8853,
232,
223,
23681,
164,
227,
95,
166,
251,
223,
14333,
238,
24744,
237,
3272,
14,
647,
7094,
107,
232,
29655,
252,
199,
646,
747,
199,
3,
7094,
109,
237,
18236,
2196,
8853,
102,
95,
23767,
227,
199,
646,
2196,
199,
3,
7094,
109,
237,
18236,
2312,
285,
8853,
102,
95,
23767,
227,
199,
646,
2312,
285,
199,
199,
749,
3,
334,
18,
9,
7094,
120,
97,
25056,
254,
14082,
233,
24814,
20278,
256,
20766,
10450,
223,
199,
3,
9112,
96,
119,
20766,
30664,
21041,
163,
104,
243,
31333,
231,
16570,
21448,
31869,
166,
235,
227,
12,
7094,
251,
102,
5417,
221,
24233,
20916,
23112,
19073,
235,
8106,
6075,
236,
10310,
251,
27035,
249,
199,
63,
15594,
275,
747,
14,
515,
14,
904,
8,
736,
14,
9458,
1062,
747,
14,
515,
14,
3475,
3460,
493,
8964,
199,
3,
9065,
102,
256,
20766,
21448,
22982,
111,
21341,
108,
165,
231,
230,
13201,
240,
21341,
108,
8106,
29273,
230,
10310,
248,
162,
227,
111,
29846,
31869,
166,
235,
227,
199,
692,
283,
9935,
18013,
63,
20424,
63,
3022,
7,
315,
747,
14,
2314,
14,
1612,
837,
272,
327,
9065,
95,
102,
29875,
119,
30664,
21041,
21448,
22982,
111,
21341,
108,
25056,
116,
12609,
272,
5235,
63,
1231,
63,
694,
275,
747,
14,
2314,
459,
9935,
18013,
63,
3998,
63,
3022,
418,
272,
666,
63,
694,
275,
747,
14,
2314,
459,
9935,
18013,
63,
3998,
63,
3022,
418,
199,
2836,
26,
272,
327,
9065,
95,
102,
29875,
119,
30664,
21041,
21448,
13201,
240,
21341,
108,
25056,
116,
12609,
272,
5235,
63,
1231,
63,
694,
275,
485,
15594,
435,
3286,
1832,
63,
576,
6687,
272,
666,
63,
694,
275,
485,
15594,
435,
3286,
1832,
63,
576,
6687,
199,
199,
2344,
23681,
24233,
24889,
13201,
240,
21341,
108,
1324,
342,
9065,
231,
230,
367,
9065,
124,
113,
11987,
231,
163,
230,
232,
11428,
8106,
30664,
21041,
164,
96,
121,
12,
9065,
234,
99,
22274,
15348,
230,
30664,
21041,
14333,
224,
29507,
3232,
14379,
7094,
254,
116,
12609,
12,
10469,
248,
98,
30998,
17797,
95,
11428,
30992,
27794,
9112,
115,
111,
166,
249,
250,
31333,
229,
19349,
115,
11546,
245,
12,
10469,
225,
227,
22274,
19182,
232,
24889,
3517,
7094,
231,
246,
10450,
109,
199,
3,
7094,
231,
103,
11428,
1324,
342,
221,
22924,
19073,
246,
8106,
29273,
230,
10310,
248,
162,
9809,
9051,
99,
24889,
26032,
4344,
111,
199,
2119,
672,
275,
1324,
480,
22274,
10450,
109,
8383,
249,
166,
119,
121,
8379,
101,
10270,
118,
18582,
199,
3,
9065,
234,
99,
22274,
15348,
230,
1324,
342,
221,
22924,
19073,
246,
8106,
26032,
4344,
111,
19182,
232,
24889,
9221,
113,
24814,
30026,
12,
7094,
124,
228,
166,
255,
231,
9051,
103,
11428,
1109,
342,
9065,
122,
232,
22843,
250,
199,
8755,
63,
889,
275,
1109,
8,
1210,
480,
10770,
236,
165,
98,
230,
32551,
10450,
109,
16322,
123,
30493,
31,
2237,
199,
509,
284,
315,
1425,
8,
8755,
63,
889,
304,
272,
870,
8,
2119,
672,
9,
199,
2344,
199,
17577,
13,
8999,
21200,
1140,
199,
17577,
11,
21714,
199,
17577,
11,
932,
26,
7280,
70,
452,
14,
7280,
25481,
1643,
8216,
21,
14,
8881,
23,
26,
1011,
1021,
23833,
199,
749,
3,
334,
19,
9,
9112,
102,
234,
21041,
27513,
253,
9051,
99,
20766,
164,
123,
103,
10450,
223,
199,
3,
221,
23681,
24233,
17130,
118,
11428,
30992,
27794,
9112,
115,
111,
166,
249,
250,
31333,
229,
19349,
115,
30664,
21041,
19349,
115,
163,
101,
234,
199,
3,
221,
23681,
24233,
24889,
23833,
10469,
95,
253,
9051,
99,
8106,
20278,
256,
20278,
231,
8379,
101,
10270,
118,
12,
7094,
228,
115,
17088,
8106,
909,
221,
30026,
12,
9065,
95,
102,
29875,
119,
23833,
10469,
95,
253,
9051,
99,
164,
118,
121,
10862,
124,
909,
221,
8106,
16570,
20916,
19431,
118,
17182,
101,
12,
7094,
235,
228,
163,
234,
106,
24302,
27397,
165,
231,
230,
27289,
106,
17182,
101,
20278,
256,
20278,
231,
199,
533,
23833,
8,
785,
304,
339,
327,
23833,
10469,
95,
253,
9051,
99,
8106,
29548,
254,
162,
234,
244,
20278,
256,
20766,
272,
485,
1850,
63,
888,
275,
469,
272,
283,
2537,
14,
2143,
14,
2991,
356,
283,
1624,
13,
24,
297,
272,
283,
2537,
14,
11676,
14,
265,
7,
520,
715,
12,
272,
283,
2537,
14,
11676,
14,
3494,
63,
466,
7,
520,
283,
493,
297,
272,
17384,
2537,
14,
11676,
14,
24056,
7,
520,
283,
10306,
297,
272,
327,
2351,
221,
23681,
163,
104,
243,
31333,
231,
162,
227,
111,
29846,
12,
9065,
223,
235,
4344,
243,
30555,
10310,
121,
666,
63,
694,
221,
24233,
8106,
3529,
9112,
250,
107,
166,
235,
227,
272,
283,
2537,
14,
11676,
14,
3494,
63,
515,
7,
520,
666,
63,
694,
23164,
2791,
297,
272,
327,
2351
] |
[
11,
274,
79,
13,
422,
29,
21,
13,
24474,
199,
17577,
11,
932,
26,
7280,
70,
452,
14,
7280,
25481,
1643,
8216,
21,
14,
8881,
21,
26,
627,
768,
493,
12464,
14,
647,
199,
3,
2803,
29,
1624,
13,
24,
199,
3,
221,
22661,
26398,
96,
8106,
30664,
21041,
8379,
101,
10270,
118,
27035,
102,
164,
96,
121,
16989,
228,
166,
255,
231,
21448,
30664,
21041,
8106,
25238,
106,
9372,
9077,
245,
18497,
25238,
106,
6923,
235,
12609,
10862,
236,
6587,
226,
20916,
21927,
11428,
199,
199,
749,
3,
334,
17,
9,
8853,
102,
95,
23767,
227,
15348,
237,
18236,
10450,
223,
199,
3,
7094,
109,
237,
18236,
13397,
8853,
102,
95,
23767,
227,
12,
9112,
18760,
30998,
21448,
3232,
14379,
7094,
118,
112,
6075,
109,
22661,
30026,
13397,
8853,
102,
95,
23767,
227,
12,
7094,
124,
228,
166,
255,
231,
14333,
238,
24744,
237,
3272,
14,
647,
7094,
107,
232,
29655,
252,
421,
199,
3,
7492,
3671,
2366,
199,
3,
7492,
2902,
2063,
446,
20,
199,
199,
17577,
11,
8999,
21200,
1140,
199,
17577,
11,
932,
26,
7280,
70,
452,
14,
7280,
25481,
1643,
8216,
21,
14,
8881,
22,
26,
1011,
5213,
21200,
1140,
334,
6508,
9,
199,
646,
13397,
199,
3,
7094,
109,
237,
18236,
2018,
7094,
228,
101,
29427,
119,
8106,
747,
8853,
102,
95,
23767,
227,
12,
7094,
250,
255,
24889,
747,
8853,
102,
95,
23767,
227,
24889,
2018,
7094,
228,
101,
29427,
119,
12,
8853,
232,
223,
23681,
164,
227,
95,
166,
251,
223,
14333,
238,
24744,
237,
3272,
14,
647,
7094,
107,
232,
29655,
252,
199,
646,
747,
199,
3,
7094,
109,
237,
18236,
2196,
8853,
102,
95,
23767,
227,
199,
646,
2196,
199,
3,
7094,
109,
237,
18236,
2312,
285,
8853,
102,
95,
23767,
227,
199,
646,
2312,
285,
199,
199,
749,
3,
334,
18,
9,
7094,
120,
97,
25056,
254,
14082,
233,
24814,
20278,
256,
20766,
10450,
223,
199,
3,
9112,
96,
119,
20766,
30664,
21041,
163,
104,
243,
31333,
231,
16570,
21448,
31869,
166,
235,
227,
12,
7094,
251,
102,
5417,
221,
24233,
20916,
23112,
19073,
235,
8106,
6075,
236,
10310,
251,
27035,
249,
199,
63,
15594,
275,
747,
14,
515,
14,
904,
8,
736,
14,
9458,
1062,
747,
14,
515,
14,
3475,
3460,
493,
8964,
199,
3,
9065,
102,
256,
20766,
21448,
22982,
111,
21341,
108,
165,
231,
230,
13201,
240,
21341,
108,
8106,
29273,
230,
10310,
248,
162,
227,
111,
29846,
31869,
166,
235,
227,
199,
692,
283,
9935,
18013,
63,
20424,
63,
3022,
7,
315,
747,
14,
2314,
14,
1612,
837,
272,
327,
9065,
95,
102,
29875,
119,
30664,
21041,
21448,
22982,
111,
21341,
108,
25056,
116,
12609,
272,
5235,
63,
1231,
63,
694,
275,
747,
14,
2314,
459,
9935,
18013,
63,
3998,
63,
3022,
418,
272,
666,
63,
694,
275,
747,
14,
2314,
459,
9935,
18013,
63,
3998,
63,
3022,
418,
199,
2836,
26,
272,
327,
9065,
95,
102,
29875,
119,
30664,
21041,
21448,
13201,
240,
21341,
108,
25056,
116,
12609,
272,
5235,
63,
1231,
63,
694,
275,
485,
15594,
435,
3286,
1832,
63,
576,
6687,
272,
666,
63,
694,
275,
485,
15594,
435,
3286,
1832,
63,
576,
6687,
199,
199,
2344,
23681,
24233,
24889,
13201,
240,
21341,
108,
1324,
342,
9065,
231,
230,
367,
9065,
124,
113,
11987,
231,
163,
230,
232,
11428,
8106,
30664,
21041,
164,
96,
121,
12,
9065,
234,
99,
22274,
15348,
230,
30664,
21041,
14333,
224,
29507,
3232,
14379,
7094,
254,
116,
12609,
12,
10469,
248,
98,
30998,
17797,
95,
11428,
30992,
27794,
9112,
115,
111,
166,
249,
250,
31333,
229,
19349,
115,
11546,
245,
12,
10469,
225,
227,
22274,
19182,
232,
24889,
3517,
7094,
231,
246,
10450,
109,
199,
3,
7094,
231,
103,
11428,
1324,
342,
221,
22924,
19073,
246,
8106,
29273,
230,
10310,
248,
162,
9809,
9051,
99,
24889,
26032,
4344,
111,
199,
2119,
672,
275,
1324,
480,
22274,
10450,
109,
8383,
249,
166,
119,
121,
8379,
101,
10270,
118,
18582,
199,
3,
9065,
234,
99,
22274,
15348,
230,
1324,
342,
221,
22924,
19073,
246,
8106,
26032,
4344,
111,
19182,
232,
24889,
9221,
113,
24814,
30026,
12,
7094,
124,
228,
166,
255,
231,
9051,
103,
11428,
1109,
342,
9065,
122,
232,
22843,
250,
199,
8755,
63,
889,
275,
1109,
8,
1210,
480,
10770,
236,
165,
98,
230,
32551,
10450,
109,
16322,
123,
30493,
31,
2237,
199,
509,
284,
315,
1425,
8,
8755,
63,
889,
304,
272,
870,
8,
2119,
672,
9,
199,
2344,
199,
17577,
13,
8999,
21200,
1140,
199,
17577,
11,
21714,
199,
17577,
11,
932,
26,
7280,
70,
452,
14,
7280,
25481,
1643,
8216,
21,
14,
8881,
23,
26,
1011,
1021,
23833,
199,
749,
3,
334,
19,
9,
9112,
102,
234,
21041,
27513,
253,
9051,
99,
20766,
164,
123,
103,
10450,
223,
199,
3,
221,
23681,
24233,
17130,
118,
11428,
30992,
27794,
9112,
115,
111,
166,
249,
250,
31333,
229,
19349,
115,
30664,
21041,
19349,
115,
163,
101,
234,
199,
3,
221,
23681,
24233,
24889,
23833,
10469,
95,
253,
9051,
99,
8106,
20278,
256,
20278,
231,
8379,
101,
10270,
118,
12,
7094,
228,
115,
17088,
8106,
909,
221,
30026,
12,
9065,
95,
102,
29875,
119,
23833,
10469,
95,
253,
9051,
99,
164,
118,
121,
10862,
124,
909,
221,
8106,
16570,
20916,
19431,
118,
17182,
101,
12,
7094,
235,
228,
163,
234,
106,
24302,
27397,
165,
231,
230,
27289,
106,
17182,
101,
20278,
256,
20278,
231,
199,
533,
23833,
8,
785,
304,
339,
327,
23833,
10469,
95,
253,
9051,
99,
8106,
29548,
254,
162,
234,
244,
20278,
256,
20766,
272,
485,
1850,
63,
888,
275,
469,
272,
283,
2537,
14,
2143,
14,
2991,
356,
283,
1624,
13,
24,
297,
272,
283,
2537,
14,
11676,
14,
265,
7,
520,
715,
12,
272,
283,
2537,
14,
11676,
14,
3494,
63,
466,
7,
520,
283,
493,
297,
272,
17384,
2537,
14,
11676,
14,
24056,
7,
520,
283,
10306,
297,
272,
327,
2351,
221,
23681,
163,
104,
243,
31333,
231,
162,
227,
111,
29846,
12,
9065,
223,
235,
4344,
243,
30555,
10310,
121,
666,
63,
694,
221,
24233,
8106,
3529,
9112,
250,
107,
166,
235,
227,
272,
283,
2537,
14,
11676,
14,
3494,
63,
515,
7,
520,
666,
63,
694,
23164,
2791,
297,
272,
327,
2351,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Mashape/dd-agent
|
checks.d/http_check.py
|
6
|
17943
|
# stdlib
from datetime import datetime
import os.path
import re
import socket
import ssl
import time
import warnings
from urlparse import urlparse
# 3rd party
import requests
import tornado
from requests.adapters import HTTPAdapter
from requests.packages import urllib3
from requests.packages.urllib3.util import ssl_
from requests.packages.urllib3.exceptions import (
SecurityWarning,
)
from requests.packages.urllib3.packages.ssl_match_hostname import \
match_hostname
# project
from checks.network_checks import EventType, NetworkCheck, Status
from config import _is_affirmative
from util import headers as agent_headers
from utils.proxy import get_proxy
DEFAULT_EXPECTED_CODE = "(1|2|3)\d\d"
class WeakCiphersHTTPSConnection(urllib3.connection.VerifiedHTTPSConnection):
SUPPORTED_CIPHERS = (
'ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:'
'ECDH+HIGH:DH+HIGH:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+HIGH:'
'RSA+3DES:ECDH+RC4:DH+RC4:RSA+RC4:!aNULL:!eNULL:!EXP:-MD5:RSA+RC4+MD5'
)
def __init__(self, host, port, ciphers=None, **kwargs):
self.ciphers = ciphers if ciphers is not None else self.SUPPORTED_CIPHERS
super(WeakCiphersHTTPSConnection, self).__init__(host, port, **kwargs)
def connect(self):
# Add certificate verification
conn = self._new_conn()
resolved_cert_reqs = ssl_.resolve_cert_reqs(self.cert_reqs)
resolved_ssl_version = ssl_.resolve_ssl_version(self.ssl_version)
hostname = self.host
if getattr(self, '_tunnel_host', None):
# _tunnel_host was added in Python 2.6.3
# (See:
# http://hg.python.org/cpython/rev/0f57b30a152f)
#
# However this check is still necessary in 2.7.x
self.sock = conn
# Calls self._set_hostport(), so self.host is
# self._tunnel_host below.
self._tunnel()
# Mark this connection as not reusable
self.auto_open = 0
# Override the host with the one we're requesting data from.
hostname = self._tunnel_host
# Wrap socket using verification with the root certs in trusted_root_certs
self.sock = ssl_.ssl_wrap_socket(conn, self.key_file, self.cert_file,
cert_reqs=resolved_cert_reqs,
ca_certs=self.ca_certs,
server_hostname=hostname,
ssl_version=resolved_ssl_version,
ciphers=self.ciphers)
if self.assert_fingerprint:
ssl_.assert_fingerprint(self.sock.getpeercert(binary_form=True), self.assert_fingerprint)
elif resolved_cert_reqs != ssl.CERT_NONE \
and self.assert_hostname is not False:
cert = self.sock.getpeercert()
if not cert.get('subjectAltName', ()):
warnings.warn((
'Certificate has no `subjectAltName`, falling back to check for a `commonName` for now. '
'This feature is being removed by major browsers and deprecated by RFC 2818. '
'(See https://github.com/shazow/urllib3/issues/497 for details.)'),
SecurityWarning
)
match_hostname(cert, self.assert_hostname or hostname)
self.is_verified = (resolved_cert_reqs == ssl.CERT_REQUIRED
or self.assert_fingerprint is not None)
class WeakCiphersHTTPSConnectionPool(urllib3.connectionpool.HTTPSConnectionPool):
ConnectionCls = WeakCiphersHTTPSConnection
class WeakCiphersPoolManager(urllib3.poolmanager.PoolManager):
def _new_pool(self, scheme, host, port):
if scheme == 'https':
return WeakCiphersHTTPSConnectionPool(host, port, **(self.connection_pool_kw))
return super(WeakCiphersPoolManager, self)._new_pool(scheme, host, port)
class WeakCiphersAdapter(HTTPAdapter):
""""Transport adapter" that allows us to use TLS_RSA_WITH_RC4_128_MD5."""
def init_poolmanager(self, connections, maxsize, block=False, **pool_kwargs):
# Rewrite of the
# requests.adapters.HTTPAdapter.init_poolmanager method
# to use WeakCiphersPoolManager instead of
# urllib3's PoolManager
self._pool_connections = connections
self._pool_maxsize = maxsize
self._pool_block = block
self.poolmanager = WeakCiphersPoolManager(num_pools=connections,
maxsize=maxsize, block=block, strict=True, **pool_kwargs)
def get_ca_certs_path():
"""
Get a path to the trusted certificates of the system
"""
CA_CERTS = [
'/opt/datadog-agent/embedded/ssl/certs/cacert.pem',
os.path.join(os.path.dirname(tornado.__file__), 'ca-certificates.crt'),
'/etc/ssl/certs/ca-certificates.crt',
]
for f in CA_CERTS:
if os.path.exists(f):
return f
return None
class HTTPCheck(NetworkCheck):
SOURCE_TYPE_NAME = 'system'
SC_STATUS = 'http.can_connect'
SC_SSL_CERT = 'http.ssl_cert'
def __init__(self, name, init_config, agentConfig, instances):
self.ca_certs = init_config.get('ca_certs', get_ca_certs_path())
proxy_settings = get_proxy(agentConfig)
if not proxy_settings:
self.proxies = None
else:
uri = "{host}:{port}".format(
host=proxy_settings['host'],
port=proxy_settings['port'])
if proxy_settings['user'] and proxy_settings['password']:
uri = "{user}:{password}@{uri}".format(
user=proxy_settings['user'],
password=proxy_settings['password'],
uri=uri)
self.proxies = {
'http': "http://{uri}".format(uri=uri),
'https': "https://{uri}".format(uri=uri)
}
NetworkCheck.__init__(self, name, init_config, agentConfig, instances)
def _load_conf(self, instance):
# Fetches the conf
tags = instance.get('tags', [])
username = instance.get('username')
password = instance.get('password')
http_response_status_code = str(instance.get('http_response_status_code', DEFAULT_EXPECTED_CODE))
timeout = int(instance.get('timeout', 10))
config_headers = instance.get('headers', {})
headers = agent_headers(self.agentConfig)
headers.update(config_headers)
url = instance.get('url')
content_match = instance.get('content_match')
response_time = _is_affirmative(instance.get('collect_response_time', True))
if not url:
raise Exception("Bad configuration. You must specify a url")
include_content = _is_affirmative(instance.get('include_content', False))
ssl = _is_affirmative(instance.get('disable_ssl_validation', True))
ssl_expire = _is_affirmative(instance.get('check_certificate_expiration', True))
instance_ca_certs = instance.get('ca_certs', self.ca_certs)
weakcipher = _is_affirmative(instance.get('weakciphers', False))
ignore_ssl_warning = _is_affirmative(instance.get('ignore_ssl_warning', False))
return url, username, password, http_response_status_code, timeout, include_content,\
headers, response_time, content_match, tags, ssl, ssl_expire, instance_ca_certs,\
weakcipher, ignore_ssl_warning
def _check(self, instance):
addr, username, password, http_response_status_code, timeout, include_content, headers,\
response_time, content_match, tags, disable_ssl_validation,\
ssl_expire, instance_ca_certs, weakcipher, ignore_ssl_warning = self._load_conf(instance)
start = time.time()
service_checks = []
try:
parsed_uri = urlparse(addr)
self.log.debug("Connecting to %s" % addr)
if disable_ssl_validation and parsed_uri.scheme == "https" and not ignore_ssl_warning:
self.warning("Skipping SSL certificate validation for %s based on configuration"
% addr)
auth = None
if username is not None and password is not None:
auth = (username, password)
sess = requests.Session()
if weakcipher:
base_addr = '{uri.scheme}://{uri.netloc}/'.format(uri=parsed_uri)
sess.mount(base_addr, WeakCiphersAdapter())
self.log.debug("Weak Ciphers will be used for {0}. Suppoted Cipherlist: {1}".format(
base_addr, WeakCiphersHTTPSConnection.SUPPORTED_CIPHERS))
r = sess.request('GET', addr, auth=auth, timeout=timeout, headers=headers, proxies = self.proxies,
verify=False if disable_ssl_validation else instance_ca_certs)
except (socket.timeout, requests.exceptions.ConnectionError, requests.exceptions.Timeout) as e:
length = int((time.time() - start) * 1000)
self.log.info("%s is DOWN, error: %s. Connection failed after %s ms"
% (addr, str(e), length))
service_checks.append((
self.SC_STATUS,
Status.DOWN,
"%s. Connection failed after %s ms" % (str(e), length)
))
except socket.error, e:
length = int((time.time() - start) * 1000)
self.log.info("%s is DOWN, error: %s. Connection failed after %s ms"
% (addr, repr(e), length))
service_checks.append((
self.SC_STATUS,
Status.DOWN,
"Socket error: %s. Connection failed after %s ms" % (repr(e), length)
))
except Exception, e:
length = int((time.time() - start) * 1000)
self.log.error("Unhandled exception %s. Connection failed after %s ms"
% (str(e), length))
raise
# Only report this metric if the site is not down
if response_time and not service_checks:
# Stop the timer as early as possible
running_time = time.time() - start
# Store tags in a temporary list so that we don't modify the global tags data structure
tags_list = list(tags)
tags_list.append('url:%s' % addr)
self.gauge('network.http.response_time', running_time, tags=tags_list)
# Check HTTP response status code
if not (service_checks or re.match(http_response_status_code, str(r.status_code))):
if http_response_status_code == DEFAULT_EXPECTED_CODE:
expected_code = "1xx or 2xx or 3xx"
else:
expected_code = http_response_status_code
message = "Incorrect HTTP return code for url %s. Expected %s, got %s" % (
addr, expected_code, str(r.status_code))
self.log.info(message)
service_checks.append((
self.SC_STATUS,
Status.DOWN,
message
))
if not service_checks:
# Host is UP
# Check content matching is set
if content_match:
content = r.content
if re.search(content_match, content, re.UNICODE):
self.log.debug("%s is found in return content" % content_match)
service_checks.append((
self.SC_STATUS, Status.UP, "UP"
))
else:
self.log.info("%s not found in content" % content_match)
self.log.debug("Content returned:\n%s" % content)
service_checks.append((
self.SC_STATUS,
Status.DOWN,
'Content "%s" not found in response' % content_match
))
else:
self.log.debug("%s is UP" % addr)
service_checks.append((
self.SC_STATUS, Status.UP, "UP"
))
if ssl_expire and parsed_uri.scheme == "https":
status, msg = self.check_cert_expiration(instance, timeout, instance_ca_certs)
service_checks.append((
self.SC_SSL_CERT, status, msg
))
return service_checks
# FIXME: 5.3 drop this function
def _create_status_event(self, sc_name, status, msg, instance):
# Create only this deprecated event for old check
if sc_name != self.SC_STATUS:
return
# Get the instance settings
url = instance.get('url', None)
name = instance.get('name', None)
nb_failures = self.statuses[name][sc_name].count(Status.DOWN)
nb_tries = len(self.statuses[name][sc_name])
tags = instance.get('tags', [])
tags_list = []
tags_list.extend(tags)
tags_list.append('url:%s' % url)
# Get a custom message that will be displayed in the event
custom_message = instance.get('message', "")
if custom_message:
custom_message += " \n"
# Let the possibility to override the source type name
instance_source_type_name = instance.get('source_type', None)
if instance_source_type_name is None:
source_type = "%s.%s" % (NetworkCheck.SOURCE_TYPE_NAME, name)
else:
source_type = "%s.%s" % (NetworkCheck.SOURCE_TYPE_NAME, instance_source_type_name)
# Get the handles you want to notify
notify = instance.get('notify', self.init_config.get('notify', []))
notify_message = ""
if notify:
notify_list = []
for handle in notify:
notify_list.append("@%s" % handle.strip())
notify_message = " ".join(notify_list) + " \n"
if status == Status.DOWN:
# format the HTTP response body into the event
if isinstance(msg, tuple):
code, reason, content = msg
# truncate and html-escape content
if len(content) > 200:
content = content[:197] + '...'
msg = u"%d %s\n\n%s" % (code, reason, content)
msg = msg.rstrip()
title = "[Alert] %s reported that %s is down" % (self.hostname, name)
alert_type = "error"
msg = u"%s %s %s reported that %s (%s) failed %s time(s) within %s last attempt(s)."\
" Last error: %s" % (notify_message, custom_message, self.hostname,
name, url, nb_failures, nb_tries, msg)
event_type = EventType.DOWN
else: # Status is UP
title = "[Recovered] %s reported that %s is up" % (self.hostname, name)
alert_type = "success"
msg = u"%s %s %s reported that %s (%s) recovered" \
% (notify_message, custom_message, self.hostname, name, url)
event_type = EventType.UP
return {
'timestamp': int(time.time()),
'event_type': event_type,
'host': self.hostname,
'msg_text': msg,
'msg_title': title,
'alert_type': alert_type,
"source_type_name": source_type,
"event_object": name,
"tags": tags_list
}
def report_as_service_check(self, sc_name, status, instance, msg=None):
instance_name = self.normalize(instance['name'])
url = instance.get('url', None)
sc_tags = ['url:{0}'.format(url), "instance:{0}".format(instance_name)]
custom_tags = instance.get('tags', [])
tags = sc_tags + custom_tags
if sc_name == self.SC_STATUS:
# format the HTTP response body into the event
if isinstance(msg, tuple):
code, reason, content = msg
# truncate and html-escape content
if len(content) > 200:
content = content[:197] + '...'
msg = u"%d %s\n\n%s" % (code, reason, content)
msg = msg.rstrip()
self.service_check(sc_name,
NetworkCheck.STATUS_TO_SERVICE_CHECK[status],
tags=tags,
message=msg
)
def check_cert_expiration(self, instance, timeout, instance_ca_certs):
warning_days = int(instance.get('days_warning', 14))
critical_days = int(instance.get('days_critical', 7))
url = instance.get('url')
o = urlparse(url)
host = o.hostname
port = o.port or 443
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(float(timeout))
sock.connect((host, port))
ssl_sock = ssl.wrap_socket(sock, cert_reqs=ssl.CERT_REQUIRED,
ca_certs=instance_ca_certs)
cert = ssl_sock.getpeercert()
except Exception as e:
return Status.DOWN, "%s" % (str(e))
exp_date = datetime.strptime(cert['notAfter'], "%b %d %H:%M:%S %Y %Z")
days_left = exp_date - datetime.utcnow()
if days_left.days < 0:
return Status.DOWN, "Expired by {0} days".format(days_left.days)
elif days_left.days < critical_days:
return Status.CRITICAL, "This cert TTL is critical: only {0} days before it expires"\
.format(days_left.days)
elif days_left.days < warning_days:
return Status.WARNING, "This cert is almost expired, only {0} days left"\
.format(days_left.days)
else:
return Status.UP, "Days left: {0}".format(days_left.days)
|
bsd-3-clause
|
[
3,
26678,
199,
504,
2197,
492,
2197,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
2838,
199,
646,
6149,
199,
646,
900,
199,
646,
3598,
199,
504,
7097,
492,
7097,
199,
199,
3,
650,
6883,
17135,
199,
646,
4145,
199,
646,
12148,
199,
199,
504,
4145,
14,
21680,
492,
3101,
10200,
199,
504,
4145,
14,
5154,
492,
4011,
19,
199,
504,
4145,
14,
5154,
14,
4078,
19,
14,
1974,
492,
6149,
63,
199,
199,
504,
4145,
14,
5154,
14,
4078,
19,
14,
3924,
492,
334,
272,
13863,
3849,
12,
199,
9,
199,
504,
4145,
14,
5154,
14,
4078,
19,
14,
5154,
14,
4266,
63,
1431,
63,
4269,
492,
971,
272,
1336,
63,
4269,
199,
199,
3,
2199,
199,
504,
5920,
14,
1200,
63,
8625,
492,
6763,
804,
12,
7220,
1799,
12,
9795,
199,
504,
1101,
492,
485,
374,
63,
2756,
1795,
391,
857,
199,
504,
4884,
492,
2323,
465,
6631,
63,
2139,
199,
504,
3778,
14,
3280,
492,
664,
63,
3280,
199,
199,
3472,
63,
22358,
63,
6012,
275,
7340,
17,
92,
18,
92,
19,
2862,
68,
60,
68,
2,
199,
199,
533,
28224,
35,
27198,
27945,
8,
4078,
19,
14,
2105,
14,
3673,
4541,
27945,
304,
339,
32501,
63,
35,
1772,
31700,
275,
334,
267,
283,
4220,
13860,
11,
14494,
29009,
26,
13860,
11,
14494,
29009,
26,
4220,
13860,
11,
14494,
3912,
26,
13860,
11,
14494,
3912,
26,
4220,
13860,
11,
14494,
3933,
26,
13860,
11,
14494,
4881,
267,
283,
4220,
13860,
11,
17624,
26,
13860,
11,
17624,
26,
4220,
13860,
11,
19,
4448,
26,
13860,
11,
19,
4448,
26,
12115,
11,
14494,
29009,
26,
12115,
11,
14494,
26,
12115,
11,
17624,
4881,
267,
283,
12115,
11,
19,
4448,
26,
4220,
13860,
11,
8205,
20,
26,
13860,
11,
8205,
20,
26,
12115,
11,
8205,
20,
26,
1,
65,
8084,
26,
1,
69,
8084,
26,
1,
11992,
6809,
5127,
21,
26,
12115,
11,
8205,
20,
11,
5127,
21,
7,
272,
776,
339,
347,
636,
826,
721,
277,
12,
1591,
12,
1844,
12,
30377,
29,
403,
12,
1011,
958,
304,
267,
291,
14,
27426,
275,
30377,
340,
30377,
365,
440,
488,
587,
291,
14,
15925,
63,
35,
1772,
31700,
267,
1613,
8,
18889,
35,
27198,
27945,
12,
291,
2843,
826,
721,
1102,
12,
1844,
12,
1011,
958,
9,
339,
347,
4907,
8,
277,
304,
267,
327,
2654,
5897,
14786,
267,
2557,
275,
291,
423,
1222,
63,
1631,
342,
398,
12152,
63,
4736,
63,
12720,
275,
6149,
3754,
6983,
63,
4736,
63,
12720,
8,
277,
14,
4736,
63,
12720,
9,
267,
12152,
63,
4266,
63,
1023,
275,
6149,
3754,
6983,
63,
4266,
63,
1023,
8,
277,
14,
4266,
63,
1023,
9,
398,
6246,
275,
291,
14,
1102,
267,
340,
2519,
8,
277,
12,
2513,
15360,
63,
1102,
297,
488,
304,
288,
327,
485,
15360,
63,
1102,
1990,
3483,
315,
2018,
499,
14,
22,
14,
19,
288,
327,
334,
9295,
26,
288,
327,
1455,
921,
9208,
14,
1548,
14,
1308,
15,
67,
1548,
15,
4964,
15,
16,
70,
1641,
66,
1216,
65,
11024,
70,
9,
288,
327,
288,
327,
9738,
642,
1104,
365,
5139,
5784,
315,
499,
14,
23,
14,
88,
953,
291,
14,
5096,
275,
2557,
288,
327,
28055,
291,
423,
409,
63,
1102,
719,
1062,
880,
291,
14,
1102,
365,
288,
327,
291,
423,
15360,
63,
1102,
5084,
14,
288,
291,
423,
15360,
342,
288,
327,
7173,
642,
1950,
465,
440,
295,
14418,
288,
291,
14,
2495,
63,
1490,
275,
378,
953,
327,
11041,
314,
1591,
543,
314,
1373,
781,
3984,
23502,
666,
687,
14,
288,
6246,
275,
291,
423,
15360,
63,
1102,
398,
327,
20322,
2838,
1808,
14786,
543,
314,
1738,
25949,
315,
19427,
63,
1231,
63,
8356,
267,
291,
14,
5096,
275,
6149,
3754,
4266,
63,
3823,
63,
3450,
8,
1631,
12,
291,
14,
498,
63,
493,
12,
291,
14,
4736,
63,
493,
12,
3147,
6250,
63,
12720,
29,
13697,
63,
4736,
63,
12720,
12,
3147,
1704,
63,
8356,
29,
277,
14,
696,
63,
8356,
12,
3147,
1654,
63,
4269,
29,
4269,
12,
3147,
6149,
63,
1023,
29,
13697,
63,
4266,
63,
1023,
12,
3147,
30377,
29,
277,
14,
27426,
9,
398,
340,
291,
14,
479,
63,
15077,
26,
288,
6149,
3754,
479,
63,
15077,
8,
277,
14,
5096,
14,
362,
7866,
4736,
8,
3008,
63,
964,
29,
549,
395,
291,
14,
479,
63,
15077,
9,
267,
916,
12152,
63,
4736,
63,
12720,
1137,
6149,
14,
11163,
63,
9185,
971,
355,
436,
291,
14,
479,
63,
4269,
365,
440,
756,
26,
288,
6250,
275,
291,
14,
5096,
14,
362,
7866,
4736,
342,
288,
340,
440,
6250,
14,
362,
360,
5875,
29171,
297,
334,
2298,
355,
3598,
14,
4050,
1332,
490,
283,
11414,
965,
949,
658,
5875,
29171,
3559,
32039,
1771,
370,
1104,
367,
282,
658,
2330,
985,
64,
367,
3063,
14,
283,
490,
283,
2765,
3878,
365,
3769,
4829,
701,
12160,
23776,
436,
5906,
701,
7329,
7294,
1085,
14,
283,
490,
8189,
9295,
4178,
921,
5031,
14,
957,
15,
609,
4651,
583,
15,
4078,
19,
15,
10115,
15,
19180,
367,
2436,
4959,
659,
490,
13863,
3849,
355,
776,
288,
1336,
63,
4269,
8,
4736,
12,
291,
14,
479,
63,
4269,
503,
6246,
9,
398,
291,
14,
374,
63,
12949,
275,
334,
13697,
63,
4736,
63,
12720,
508,
6149,
14,
11163,
63,
12496,
1169,
503,
291,
14,
479,
63,
15077,
365,
440,
488,
9,
421,
199,
533,
28224,
35,
27198,
14921,
23929,
8,
4078,
19,
14,
2105,
2293,
14,
14921,
23929,
304,
339,
8113,
24342,
275,
28224,
35,
27198,
27945,
421,
199,
533,
28224,
35,
27198,
5453,
2988,
8,
4078,
19,
14,
2293,
2609,
14,
5453,
2988,
304,
339,
347,
485,
1222,
63,
2293,
8,
277,
12,
5687,
12,
1591,
12,
1844,
304,
267,
340,
5687,
508,
283,
2859,
356,
288,
372,
28224,
35,
27198,
14921,
23929,
8,
1102,
12,
1844,
12,
1011,
8,
277,
14,
2105,
63,
2293,
63,
829,
430,
267,
372,
1613,
8,
18889,
35,
27198,
5453,
2988,
12,
291,
10445,
1222,
63,
2293,
8,
5512,
12,
1591,
12,
1844,
9,
421,
199,
533,
28224,
35,
27198,
10200,
8,
2856,
10200,
304,
272,
408,
2,
7836,
12146,
2,
626,
6127,
2739,
370,
675,
12213,
63,
12115,
63,
9139,
63
] |
[
26678,
199,
504,
2197,
492,
2197,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
2838,
199,
646,
6149,
199,
646,
900,
199,
646,
3598,
199,
504,
7097,
492,
7097,
199,
199,
3,
650,
6883,
17135,
199,
646,
4145,
199,
646,
12148,
199,
199,
504,
4145,
14,
21680,
492,
3101,
10200,
199,
504,
4145,
14,
5154,
492,
4011,
19,
199,
504,
4145,
14,
5154,
14,
4078,
19,
14,
1974,
492,
6149,
63,
199,
199,
504,
4145,
14,
5154,
14,
4078,
19,
14,
3924,
492,
334,
272,
13863,
3849,
12,
199,
9,
199,
504,
4145,
14,
5154,
14,
4078,
19,
14,
5154,
14,
4266,
63,
1431,
63,
4269,
492,
971,
272,
1336,
63,
4269,
199,
199,
3,
2199,
199,
504,
5920,
14,
1200,
63,
8625,
492,
6763,
804,
12,
7220,
1799,
12,
9795,
199,
504,
1101,
492,
485,
374,
63,
2756,
1795,
391,
857,
199,
504,
4884,
492,
2323,
465,
6631,
63,
2139,
199,
504,
3778,
14,
3280,
492,
664,
63,
3280,
199,
199,
3472,
63,
22358,
63,
6012,
275,
7340,
17,
92,
18,
92,
19,
2862,
68,
60,
68,
2,
199,
199,
533,
28224,
35,
27198,
27945,
8,
4078,
19,
14,
2105,
14,
3673,
4541,
27945,
304,
339,
32501,
63,
35,
1772,
31700,
275,
334,
267,
283,
4220,
13860,
11,
14494,
29009,
26,
13860,
11,
14494,
29009,
26,
4220,
13860,
11,
14494,
3912,
26,
13860,
11,
14494,
3912,
26,
4220,
13860,
11,
14494,
3933,
26,
13860,
11,
14494,
4881,
267,
283,
4220,
13860,
11,
17624,
26,
13860,
11,
17624,
26,
4220,
13860,
11,
19,
4448,
26,
13860,
11,
19,
4448,
26,
12115,
11,
14494,
29009,
26,
12115,
11,
14494,
26,
12115,
11,
17624,
4881,
267,
283,
12115,
11,
19,
4448,
26,
4220,
13860,
11,
8205,
20,
26,
13860,
11,
8205,
20,
26,
12115,
11,
8205,
20,
26,
1,
65,
8084,
26,
1,
69,
8084,
26,
1,
11992,
6809,
5127,
21,
26,
12115,
11,
8205,
20,
11,
5127,
21,
7,
272,
776,
339,
347,
636,
826,
721,
277,
12,
1591,
12,
1844,
12,
30377,
29,
403,
12,
1011,
958,
304,
267,
291,
14,
27426,
275,
30377,
340,
30377,
365,
440,
488,
587,
291,
14,
15925,
63,
35,
1772,
31700,
267,
1613,
8,
18889,
35,
27198,
27945,
12,
291,
2843,
826,
721,
1102,
12,
1844,
12,
1011,
958,
9,
339,
347,
4907,
8,
277,
304,
267,
327,
2654,
5897,
14786,
267,
2557,
275,
291,
423,
1222,
63,
1631,
342,
398,
12152,
63,
4736,
63,
12720,
275,
6149,
3754,
6983,
63,
4736,
63,
12720,
8,
277,
14,
4736,
63,
12720,
9,
267,
12152,
63,
4266,
63,
1023,
275,
6149,
3754,
6983,
63,
4266,
63,
1023,
8,
277,
14,
4266,
63,
1023,
9,
398,
6246,
275,
291,
14,
1102,
267,
340,
2519,
8,
277,
12,
2513,
15360,
63,
1102,
297,
488,
304,
288,
327,
485,
15360,
63,
1102,
1990,
3483,
315,
2018,
499,
14,
22,
14,
19,
288,
327,
334,
9295,
26,
288,
327,
1455,
921,
9208,
14,
1548,
14,
1308,
15,
67,
1548,
15,
4964,
15,
16,
70,
1641,
66,
1216,
65,
11024,
70,
9,
288,
327,
288,
327,
9738,
642,
1104,
365,
5139,
5784,
315,
499,
14,
23,
14,
88,
953,
291,
14,
5096,
275,
2557,
288,
327,
28055,
291,
423,
409,
63,
1102,
719,
1062,
880,
291,
14,
1102,
365,
288,
327,
291,
423,
15360,
63,
1102,
5084,
14,
288,
291,
423,
15360,
342,
288,
327,
7173,
642,
1950,
465,
440,
295,
14418,
288,
291,
14,
2495,
63,
1490,
275,
378,
953,
327,
11041,
314,
1591,
543,
314,
1373,
781,
3984,
23502,
666,
687,
14,
288,
6246,
275,
291,
423,
15360,
63,
1102,
398,
327,
20322,
2838,
1808,
14786,
543,
314,
1738,
25949,
315,
19427,
63,
1231,
63,
8356,
267,
291,
14,
5096,
275,
6149,
3754,
4266,
63,
3823,
63,
3450,
8,
1631,
12,
291,
14,
498,
63,
493,
12,
291,
14,
4736,
63,
493,
12,
3147,
6250,
63,
12720,
29,
13697,
63,
4736,
63,
12720,
12,
3147,
1704,
63,
8356,
29,
277,
14,
696,
63,
8356,
12,
3147,
1654,
63,
4269,
29,
4269,
12,
3147,
6149,
63,
1023,
29,
13697,
63,
4266,
63,
1023,
12,
3147,
30377,
29,
277,
14,
27426,
9,
398,
340,
291,
14,
479,
63,
15077,
26,
288,
6149,
3754,
479,
63,
15077,
8,
277,
14,
5096,
14,
362,
7866,
4736,
8,
3008,
63,
964,
29,
549,
395,
291,
14,
479,
63,
15077,
9,
267,
916,
12152,
63,
4736,
63,
12720,
1137,
6149,
14,
11163,
63,
9185,
971,
355,
436,
291,
14,
479,
63,
4269,
365,
440,
756,
26,
288,
6250,
275,
291,
14,
5096,
14,
362,
7866,
4736,
342,
288,
340,
440,
6250,
14,
362,
360,
5875,
29171,
297,
334,
2298,
355,
3598,
14,
4050,
1332,
490,
283,
11414,
965,
949,
658,
5875,
29171,
3559,
32039,
1771,
370,
1104,
367,
282,
658,
2330,
985,
64,
367,
3063,
14,
283,
490,
283,
2765,
3878,
365,
3769,
4829,
701,
12160,
23776,
436,
5906,
701,
7329,
7294,
1085,
14,
283,
490,
8189,
9295,
4178,
921,
5031,
14,
957,
15,
609,
4651,
583,
15,
4078,
19,
15,
10115,
15,
19180,
367,
2436,
4959,
659,
490,
13863,
3849,
355,
776,
288,
1336,
63,
4269,
8,
4736,
12,
291,
14,
479,
63,
4269,
503,
6246,
9,
398,
291,
14,
374,
63,
12949,
275,
334,
13697,
63,
4736,
63,
12720,
508,
6149,
14,
11163,
63,
12496,
1169,
503,
291,
14,
479,
63,
15077,
365,
440,
488,
9,
421,
199,
533,
28224,
35,
27198,
14921,
23929,
8,
4078,
19,
14,
2105,
2293,
14,
14921,
23929,
304,
339,
8113,
24342,
275,
28224,
35,
27198,
27945,
421,
199,
533,
28224,
35,
27198,
5453,
2988,
8,
4078,
19,
14,
2293,
2609,
14,
5453,
2988,
304,
339,
347,
485,
1222,
63,
2293,
8,
277,
12,
5687,
12,
1591,
12,
1844,
304,
267,
340,
5687,
508,
283,
2859,
356,
288,
372,
28224,
35,
27198,
14921,
23929,
8,
1102,
12,
1844,
12,
1011,
8,
277,
14,
2105,
63,
2293,
63,
829,
430,
267,
372,
1613,
8,
18889,
35,
27198,
5453,
2988,
12,
291,
10445,
1222,
63,
2293,
8,
5512,
12,
1591,
12,
1844,
9,
421,
199,
533,
28224,
35,
27198,
10200,
8,
2856,
10200,
304,
272,
408,
2,
7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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
citrix-openstack-build/nova
|
nova/virt/hyperv/volumeops.py
|
4
|
9453
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 Pedro Navarro Perez
# Copyright 2013 Cloudbase Solutions Srl
# 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.
"""
Management class for Storage-related functions (attach, detach, etc).
"""
import time
from oslo.config import cfg
from nova import exception
from nova.openstack.common.gettextutils import _
from nova.openstack.common import log as logging
from nova.virt import driver
from nova.virt.hyperv import utilsfactory
from nova.virt.hyperv import vmutils
LOG = logging.getLogger(__name__)
hyper_volumeops_opts = [
cfg.IntOpt('volume_attach_retry_count',
default=10,
help='The number of times to retry to attach a volume'),
cfg.IntOpt('volume_attach_retry_interval',
default=5,
help='Interval between volume attachment attempts, in seconds'),
]
CONF = cfg.CONF
CONF.register_opts(hyper_volumeops_opts, 'hyperv')
CONF.import_opt('host', 'nova.netconf')
CONF.import_opt('my_ip', 'nova.netconf')
class VolumeOps(object):
"""
Management class for Volume-related tasks
"""
def __init__(self):
self._hostutils = utilsfactory.get_hostutils()
self._vmutils = utilsfactory.get_vmutils()
self._volutils = utilsfactory.get_volumeutils()
self._initiator = None
self._default_root_device = 'vda'
def ebs_root_in_block_devices(self, block_device_info):
return self._volutils.volume_in_mapping(self._default_root_device,
block_device_info)
def attach_volumes(self, block_device_info, instance_name, ebs_root):
mapping = driver.block_device_info_get_mapping(block_device_info)
if ebs_root:
self.attach_volume(mapping[0]['connection_info'],
instance_name, True)
mapping = mapping[1:]
for vol in mapping:
self.attach_volume(vol['connection_info'], instance_name)
def login_storage_targets(self, block_device_info):
mapping = driver.block_device_info_get_mapping(block_device_info)
for vol in mapping:
self._login_storage_target(vol['connection_info'])
def _login_storage_target(self, connection_info):
data = connection_info['data']
target_lun = data['target_lun']
target_iqn = data['target_iqn']
target_portal = data['target_portal']
# Check if we already logged in
if self._volutils.get_device_number_for_target(target_iqn, target_lun):
LOG.debug(_("Already logged in on storage target. No need to "
"login. Portal: %(target_portal)s, "
"IQN: %(target_iqn)s, LUN: %(target_lun)s"),
{'target_portal': target_portal,
'target_iqn': target_iqn, 'target_lun': target_lun})
else:
LOG.debug(_("Logging in on storage target. Portal: "
"%(target_portal)s, IQN: %(target_iqn)s, "
"LUN: %(target_lun)s"),
{'target_portal': target_portal,
'target_iqn': target_iqn, 'target_lun': target_lun})
self._volutils.login_storage_target(target_lun, target_iqn,
target_portal)
# Wait for the target to be mounted
self._get_mounted_disk_from_lun(target_iqn, target_lun, True)
def attach_volume(self, connection_info, instance_name, ebs_root=False):
"""
Attach a volume to the SCSI controller or to the IDE controller if
ebs_root is True
"""
LOG.debug(_("Attach_volume: %(connection_info)s to %(instance_name)s"),
{'connection_info': connection_info,
'instance_name': instance_name})
try:
self._login_storage_target(connection_info)
data = connection_info['data']
target_lun = data['target_lun']
target_iqn = data['target_iqn']
#Getting the mounted disk
mounted_disk_path = self._get_mounted_disk_from_lun(target_iqn,
target_lun)
if ebs_root:
#Find the IDE controller for the vm.
ctrller_path = self._vmutils.get_vm_ide_controller(
instance_name, 0)
#Attaching to the first slot
slot = 0
else:
#Find the SCSI controller for the vm
ctrller_path = self._vmutils.get_vm_scsi_controller(
instance_name)
slot = self._get_free_controller_slot(ctrller_path)
self._vmutils.attach_volume_to_controller(instance_name,
ctrller_path,
slot,
mounted_disk_path)
except Exception as exn:
LOG.exception(_('Attach volume failed: %s'), exn)
self._volutils.logout_storage_target(target_iqn)
raise vmutils.HyperVException(_('Unable to attach volume '
'to instance %s') % instance_name)
def _get_free_controller_slot(self, scsi_controller_path):
#Slots starts from 0, so the lenght of the disks gives us the free slot
return self._vmutils.get_attached_disks_count(scsi_controller_path)
def detach_volumes(self, block_device_info, instance_name):
mapping = driver.block_device_info_get_mapping(block_device_info)
for vol in mapping:
self.detach_volume(vol['connection_info'], instance_name)
def logout_storage_target(self, target_iqn):
LOG.debug(_("Logging off storage target %s"), target_iqn)
self._volutils.logout_storage_target(target_iqn)
def detach_volume(self, connection_info, instance_name):
"""Dettach a volume to the SCSI controller."""
LOG.debug(_("Detach_volume: %(connection_info)s "
"from %(instance_name)s"),
{'connection_info': connection_info,
'instance_name': instance_name})
data = connection_info['data']
target_lun = data['target_lun']
target_iqn = data['target_iqn']
#Getting the mounted disk
mounted_disk_path = self._get_mounted_disk_from_lun(target_iqn,
target_lun)
LOG.debug(_("Detaching physical disk from instance: %s"),
mounted_disk_path)
self._vmutils.detach_vm_disk(instance_name, mounted_disk_path)
self.logout_storage_target(target_iqn)
def get_volume_connector(self, instance):
if not self._initiator:
self._initiator = self._volutils.get_iscsi_initiator()
if not self._initiator:
LOG.warn(_('Could not determine iscsi initiator name'),
instance=instance)
return {
'ip': CONF.my_ip,
'host': CONF.host,
'initiator': self._initiator,
}
def _get_mounted_disk_from_lun(self, target_iqn, target_lun,
wait_for_device=False):
device_number = self._volutils.get_device_number_for_target(target_iqn,
target_lun)
if device_number is None:
raise exception.NotFound(_('Unable to find a mounted disk for '
'target_iqn: %s') % target_iqn)
LOG.debug(_('Device number: %(device_number)s, '
'target lun: %(target_lun)s'),
{'device_number': device_number, 'target_lun': target_lun})
#Finding Mounted disk drive
for i in range(0, CONF.hyperv.volume_attach_retry_count):
mounted_disk_path = self._vmutils.get_mounted_disk_by_drive_number(
device_number)
if mounted_disk_path or not wait_for_device:
break
time.sleep(CONF.hyperv.volume_attach_retry_interval)
if not mounted_disk_path:
raise exception.NotFound(_('Unable to find a mounted disk '
'for target_iqn: %s') % target_iqn)
return mounted_disk_path
def disconnect_volume(self, physical_drive_path):
#Get the session_id of the ISCSI connection
session_id = self._volutils.get_session_id_from_mounted_disk(
physical_drive_path)
#Logging out the target
self._volutils.execute_log_out(session_id)
def get_target_from_disk_path(self, physical_drive_path):
return self._volutils.get_target_from_disk_path(physical_drive_path)
|
apache-2.0
|
[
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
6029,
510,
379,
293,
653,
1214,
285,
293,
11379,
25409,
199,
3,
1898,
6171,
5980,
8301,
482,
17991,
8653,
428,
4308,
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,
624,
199,
14552,
1021,
367,
10533,
13,
2407,
3423,
334,
5040,
12,
21236,
12,
5423,
680,
199,
624,
199,
646,
900,
199,
199,
504,
11258,
14,
888,
492,
4810,
199,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
8512,
14,
2330,
14,
5152,
1208,
492,
485,
199,
504,
5913,
14,
8512,
14,
2330,
492,
943,
465,
2050,
199,
504,
5913,
14,
4549,
492,
5253,
199,
504,
5913,
14,
4549,
14,
9547,
86,
492,
3778,
3702,
199,
504,
5913,
14,
4549,
14,
9547,
86,
492,
4169,
1208,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
9547,
63,
2405,
1483,
63,
3291,
275,
359,
272,
4810,
14,
3241,
9985,
360,
2405,
63,
5040,
63,
7154,
63,
835,
297,
2049,
849,
29,
709,
12,
2049,
1720,
534,
1918,
1329,
402,
5431,
370,
7269,
370,
6554,
282,
3301,
659,
272,
4810,
14,
3241,
9985,
360,
2405,
63,
5040,
63,
7154,
63,
4284,
297,
2049,
849,
29,
21,
12,
2049,
1720,
534,
8227,
3382,
3301,
12193,
12454,
12,
315,
4696,
659,
199,
61,
199,
199,
3103,
275,
4810,
14,
3103,
199,
3103,
14,
2683,
63,
3291,
8,
9547,
63,
2405,
1483,
63,
3291,
12,
283,
9547,
86,
358,
199,
3103,
14,
646,
63,
2992,
360,
1102,
297,
283,
6765,
14,
18242,
358,
199,
3103,
14,
646,
63,
2992,
360,
1662,
63,
711,
297,
283,
6765,
14,
18242,
358,
421,
199,
533,
15018,
16452,
8,
785,
304,
272,
408,
272,
8259,
1021,
367,
15018,
13,
2407,
6527,
272,
408,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
1102,
1208,
275,
3778,
3702,
14,
362,
63,
1102,
1208,
342,
267,
291,
423,
2611,
1208,
275,
3778,
3702,
14,
362,
63,
2611,
1208,
342,
267,
291,
423,
5650,
1208,
275,
3778,
3702,
14,
362,
63,
2405,
1208,
342,
267,
291,
423,
17974,
275,
488,
267,
291,
423,
885,
63,
1231,
63,
1782,
275,
283,
86,
983,
7,
339,
347,
325,
1533,
63,
1231,
63,
262,
63,
1457,
63,
6410,
8,
277,
12,
1853,
63,
1782,
63,
815,
304,
267,
372,
291,
423,
5650,
1208,
14,
2405,
63,
262,
63,
4745,
8,
277,
423,
885,
63,
1231,
63,
1782,
12,
6059,
1853,
63,
1782,
63,
815,
9,
339,
347,
6554,
63,
8838,
8,
277,
12,
1853,
63,
1782,
63,
815,
12,
1256,
63,
354,
12,
325,
1533,
63,
1231,
304,
267,
4412,
275,
5253,
14,
1457,
63,
1782,
63,
815,
63,
362,
63,
4745,
8,
1457,
63,
1782,
63,
815,
9,
398,
340,
325,
1533,
63,
1231,
26,
288,
291,
14,
5040,
63,
2405,
8,
4745,
59,
16,
2733,
2105,
63,
815,
995,
3044,
1256,
63,
354,
12,
715,
9,
288,
4412,
275,
4412,
59,
17,
2938,
267,
367,
5236,
315,
4412,
26,
288,
291,
14,
5040,
63,
2405,
8,
5650,
459,
2105,
63,
815,
995,
1256,
63,
354,
9,
339,
347,
4676,
63,
3494,
63,
4684,
8,
277,
12,
1853,
63,
1782,
63,
815,
304,
267,
4412,
275,
5253,
14,
1457,
63,
1782,
63,
815,
63,
362,
63,
4745,
8,
1457,
63,
1782,
63,
815,
9,
267,
367,
5236,
315,
4412,
26,
288,
291,
423,
2886,
63,
3494,
63,
1375,
8,
5650,
459,
2105,
63,
815,
1105,
339,
347,
485,
2886,
63,
3494,
63,
1375,
8,
277,
12,
1950,
63,
815,
304,
267,
666,
275,
1950,
63,
815,
459,
576,
418,
267,
1347,
63,
13542,
275,
666,
459,
1375,
63,
13542,
418,
267,
1347,
63,
27071,
275,
666,
459,
1375,
63,
27071,
418,
267,
1347,
63,
8707,
275,
666,
459,
1375,
63,
8707,
418,
267,
327,
2670,
340,
781,
2575,
10367,
315,
267,
340,
291,
423,
5650,
1208,
14,
362,
63,
1782,
63,
1955,
63,
509,
63,
1375,
8,
1375,
63,
27071,
12,
1347,
63,
13542,
304,
288,
5051,
14,
1757,
6115,
16760,
10367,
315,
641,
4887,
1347,
14,
3091,
1929,
370,
298,
717,
298,
2886,
14,
10977,
279,
26,
2818,
1375,
63,
8707,
9,
83,
12,
298,
717,
298,
23559,
46,
26,
2818,
1375,
63,
27071,
9,
83,
12,
491,
1734,
26,
2818,
1375,
63,
13542,
9,
83,
1288,
1993,
791,
1375,
63,
8707,
356,
1347,
63,
8707,
12,
2432,
283,
1375,
63,
27071,
356,
1347,
63,
27071,
12,
283,
1375,
63,
13542,
356,
1347,
63,
13542,
1552,
267,
587,
26,
288,
5051,
14,
1757,
6115,
14054,
315,
641,
4887,
1347,
14,
10977,
279,
26,
298,
717,
11792,
1375,
63,
8707,
9,
83,
12,
473,
32045,
26,
2818,
1375,
63,
27071,
9,
83,
12,
298,
717,
298,
44,
1734,
26,
2818,
1375,
63,
13542,
9,
83,
1288,
1993,
791,
1375,
63,
8707,
356,
1347,
63,
8707,
12,
2432,
283,
1375,
63,
27071,
356,
1347,
63,
27071,
12,
283,
1375,
63,
13542,
356,
1347,
63,
13542,
1552,
288,
291,
423,
5650,
1208,
14,
2886,
63,
3494,
63,
1375,
8,
1375,
63,
13542,
12,
1347,
63,
27071,
12,
6059,
1347,
63,
8707,
9,
288,
327,
13144,
367,
314,
1347,
370,
506,
27979,
288,
291,
423,
362,
63,
27919,
63,
4032,
63,
504,
63,
13542,
8,
1375,
63,
27071,
12,
1347,
63,
13542,
12,
715,
9,
339,
347,
6554,
63,
2405,
8,
277
] |
[
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
6029,
510,
379,
293,
653,
1214,
285,
293,
11379,
25409,
199,
3,
1898,
6171,
5980,
8301,
482,
17991,
8653,
428,
4308,
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,
624,
199,
14552,
1021,
367,
10533,
13,
2407,
3423,
334,
5040,
12,
21236,
12,
5423,
680,
199,
624,
199,
646,
900,
199,
199,
504,
11258,
14,
888,
492,
4810,
199,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
8512,
14,
2330,
14,
5152,
1208,
492,
485,
199,
504,
5913,
14,
8512,
14,
2330,
492,
943,
465,
2050,
199,
504,
5913,
14,
4549,
492,
5253,
199,
504,
5913,
14,
4549,
14,
9547,
86,
492,
3778,
3702,
199,
504,
5913,
14,
4549,
14,
9547,
86,
492,
4169,
1208,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
9547,
63,
2405,
1483,
63,
3291,
275,
359,
272,
4810,
14,
3241,
9985,
360,
2405,
63,
5040,
63,
7154,
63,
835,
297,
2049,
849,
29,
709,
12,
2049,
1720,
534,
1918,
1329,
402,
5431,
370,
7269,
370,
6554,
282,
3301,
659,
272,
4810,
14,
3241,
9985,
360,
2405,
63,
5040,
63,
7154,
63,
4284,
297,
2049,
849,
29,
21,
12,
2049,
1720,
534,
8227,
3382,
3301,
12193,
12454,
12,
315,
4696,
659,
199,
61,
199,
199,
3103,
275,
4810,
14,
3103,
199,
3103,
14,
2683,
63,
3291,
8,
9547,
63,
2405,
1483,
63,
3291,
12,
283,
9547,
86,
358,
199,
3103,
14,
646,
63,
2992,
360,
1102,
297,
283,
6765,
14,
18242,
358,
199,
3103,
14,
646,
63,
2992,
360,
1662,
63,
711,
297,
283,
6765,
14,
18242,
358,
421,
199,
533,
15018,
16452,
8,
785,
304,
272,
408,
272,
8259,
1021,
367,
15018,
13,
2407,
6527,
272,
408,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
1102,
1208,
275,
3778,
3702,
14,
362,
63,
1102,
1208,
342,
267,
291,
423,
2611,
1208,
275,
3778,
3702,
14,
362,
63,
2611,
1208,
342,
267,
291,
423,
5650,
1208,
275,
3778,
3702,
14,
362,
63,
2405,
1208,
342,
267,
291,
423,
17974,
275,
488,
267,
291,
423,
885,
63,
1231,
63,
1782,
275,
283,
86,
983,
7,
339,
347,
325,
1533,
63,
1231,
63,
262,
63,
1457,
63,
6410,
8,
277,
12,
1853,
63,
1782,
63,
815,
304,
267,
372,
291,
423,
5650,
1208,
14,
2405,
63,
262,
63,
4745,
8,
277,
423,
885,
63,
1231,
63,
1782,
12,
6059,
1853,
63,
1782,
63,
815,
9,
339,
347,
6554,
63,
8838,
8,
277,
12,
1853,
63,
1782,
63,
815,
12,
1256,
63,
354,
12,
325,
1533,
63,
1231,
304,
267,
4412,
275,
5253,
14,
1457,
63,
1782,
63,
815,
63,
362,
63,
4745,
8,
1457,
63,
1782,
63,
815,
9,
398,
340,
325,
1533,
63,
1231,
26,
288,
291,
14,
5040,
63,
2405,
8,
4745,
59,
16,
2733,
2105,
63,
815,
995,
3044,
1256,
63,
354,
12,
715,
9,
288,
4412,
275,
4412,
59,
17,
2938,
267,
367,
5236,
315,
4412,
26,
288,
291,
14,
5040,
63,
2405,
8,
5650,
459,
2105,
63,
815,
995,
1256,
63,
354,
9,
339,
347,
4676,
63,
3494,
63,
4684,
8,
277,
12,
1853,
63,
1782,
63,
815,
304,
267,
4412,
275,
5253,
14,
1457,
63,
1782,
63,
815,
63,
362,
63,
4745,
8,
1457,
63,
1782,
63,
815,
9,
267,
367,
5236,
315,
4412,
26,
288,
291,
423,
2886,
63,
3494,
63,
1375,
8,
5650,
459,
2105,
63,
815,
1105,
339,
347,
485,
2886,
63,
3494,
63,
1375,
8,
277,
12,
1950,
63,
815,
304,
267,
666,
275,
1950,
63,
815,
459,
576,
418,
267,
1347,
63,
13542,
275,
666,
459,
1375,
63,
13542,
418,
267,
1347,
63,
27071,
275,
666,
459,
1375,
63,
27071,
418,
267,
1347,
63,
8707,
275,
666,
459,
1375,
63,
8707,
418,
267,
327,
2670,
340,
781,
2575,
10367,
315,
267,
340,
291,
423,
5650,
1208,
14,
362,
63,
1782,
63,
1955,
63,
509,
63,
1375,
8,
1375,
63,
27071,
12,
1347,
63,
13542,
304,
288,
5051,
14,
1757,
6115,
16760,
10367,
315,
641,
4887,
1347,
14,
3091,
1929,
370,
298,
717,
298,
2886,
14,
10977,
279,
26,
2818,
1375,
63,
8707,
9,
83,
12,
298,
717,
298,
23559,
46,
26,
2818,
1375,
63,
27071,
9,
83,
12,
491,
1734,
26,
2818,
1375,
63,
13542,
9,
83,
1288,
1993,
791,
1375,
63,
8707,
356,
1347,
63,
8707,
12,
2432,
283,
1375,
63,
27071,
356,
1347,
63,
27071,
12,
283,
1375,
63,
13542,
356,
1347,
63,
13542,
1552,
267,
587,
26,
288,
5051,
14,
1757,
6115,
14054,
315,
641,
4887,
1347,
14,
10977,
279,
26,
298,
717,
11792,
1375,
63,
8707,
9,
83,
12,
473,
32045,
26,
2818,
1375,
63,
27071,
9,
83,
12,
298,
717,
298,
44,
1734,
26,
2818,
1375,
63,
13542,
9,
83,
1288,
1993,
791,
1375,
63,
8707,
356,
1347,
63,
8707,
12,
2432,
283,
1375,
63,
27071,
356,
1347,
63,
27071,
12,
283,
1375,
63,
13542,
356,
1347,
63,
13542,
1552,
288,
291,
423,
5650,
1208,
14,
2886,
63,
3494,
63,
1375,
8,
1375,
63,
13542,
12,
1347,
63,
27071,
12,
6059,
1347,
63,
8707,
9,
288,
327,
13144,
367,
314,
1347,
370,
506,
27979,
288,
291,
423,
362,
63,
27919,
63,
4032,
63,
504,
63,
13542,
8,
1375,
63,
27071,
12,
1347,
63,
13542,
12,
715,
9,
339,
347,
6554,
63,
2405,
8,
277,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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utils import formats
from django.utils.encoding import force_text
register = Library()
@register.filter(is_safe=False)
def localize(value):
"""
Forces a value to be rendered as a localized value,
regardless of the value of ``settings.USE_L10N``.
"""
return force_text(formats.localize(value, use_l10n=True))
@register.filter(is_safe=False)
def unlocalize(value):
"""
Forces a value to be rendered as a non-localized value,
regardless of the value of ``settings.USE_L10N``.
"""
return force_text(value)
class LocalizeNode(Node):
def __init__(self, nodelist, use_l10n):
self.nodelist = nodelist
self.use_l10n = use_l10n
def __repr__(self):
return "<LocalizeNode>"
def render(self, context):
old_setting = context.use_l10n
context.use_l10n = self.use_l10n
output = self.nodelist.render(context)
context.use_l10n = old_setting
return output
@register.tag('localize')
def localize_tag(parser, token):
"""
Forces or prevents localization of values, regardless of the value of
`settings.USE_L10N`.
Sample usage::
{% localize off %}
var pi = {{ 3.1415 }};
{% endlocalize %}
"""
use_l10n = None
bits = list(token.split_contents())
if len(bits) == 1:
use_l10n = True
elif len(bits) > 2 or bits[1] not in ('on', 'off'):
raise TemplateSyntaxError("%r argument should be 'on' or 'off'" % bits[0])
else:
use_l10n = bits[1] == 'on'
nodelist = parser.parse(('endlocalize',))
parser.delete_first_token()
return LocalizeNode(nodelist, use_l10n)
|
apache-2.0
|
[
504,
1639,
14,
1160,
492,
11243,
12,
5013,
12,
17762,
199,
504,
1639,
14,
1208,
492,
6752,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
199,
2683,
275,
11243,
342,
421,
199,
32,
2683,
14,
1541,
8,
374,
63,
3489,
29,
797,
9,
199,
318,
2257,
794,
8,
585,
304,
272,
408,
272,
2104,
823,
282,
574,
370,
506,
8018,
465,
282,
25460,
574,
12,
272,
15270,
402,
314,
574,
402,
1124,
1751,
14,
4701,
63,
44,
709,
46,
4345,
272,
408,
272,
372,
3542,
63,
505,
8,
6321,
14,
21279,
8,
585,
12,
675,
63,
76,
709,
78,
29,
549,
430,
421,
199,
32,
2683,
14,
1541,
8,
374,
63,
3489,
29,
797,
9,
199,
318,
625,
21279,
8,
585,
304,
272,
408,
272,
2104,
823,
282,
574,
370,
506,
8018,
465,
282,
2222,
13,
22729,
574,
12,
272,
15270,
402,
314,
574,
402,
1124,
1751,
14,
4701,
63,
44,
709,
46,
4345,
272,
408,
272,
372,
3542,
63,
505,
8,
585,
9,
421,
199,
533,
10111,
794,
1716,
8,
1716,
304,
272,
347,
636,
826,
721,
277,
12,
13642,
12,
675,
63,
76,
709,
78,
304,
267,
291,
14,
14371,
275,
13642,
267,
291,
14,
1180,
63,
76,
709,
78,
275,
675,
63,
76,
709,
78,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
3886,
5339,
794,
1716,
4335,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
2269,
63,
6031,
275,
1067,
14,
1180,
63,
76,
709,
78,
267,
1067,
14,
1180,
63,
76,
709,
78,
275,
291,
14,
1180,
63,
76,
709,
78,
267,
1072,
275,
291,
14,
14371,
14,
3352,
8,
1100,
9,
267,
1067,
14,
1180,
63,
76,
709,
78,
275,
2269,
63,
6031,
267,
372,
1072,
421,
199,
32,
2683,
14,
1450,
360,
21279,
358,
199,
318,
2257,
794,
63,
1450,
8,
2087,
12,
1526,
304,
272,
408,
272,
2104,
823,
503,
21925,
2257,
2072,
402,
1338,
12,
15270,
402,
314,
574,
402,
272,
658,
1751,
14,
4701,
63,
44,
709,
46,
2313,
339,
15227,
4503,
447,
398,
7749,
2257,
794,
2331,
3674,
288,
2729,
6682,
275,
8448,
650,
14,
32689,
3586,
27,
267,
7749,
1284,
21279,
3674,
272,
408,
272,
675,
63,
76,
709,
78,
275,
488,
272,
5821,
275,
769,
8,
1418,
14,
1294,
63,
4407,
1012,
272,
340,
822,
8,
5609,
9,
508,
413,
26,
267,
675,
63,
76,
709,
78,
275,
715,
272,
916,
822,
8,
5609,
9,
690,
499,
503,
5821,
59,
17,
61,
440,
315,
661,
265,
297,
283,
1997,
735,
267,
746,
17762,
3647,
82,
1423,
1077,
506,
283,
265,
7,
503,
283,
1997,
4065,
450,
5821,
59,
16,
566,
272,
587,
26,
267,
675,
63,
76,
709,
78,
275,
5821,
59,
17,
61,
508,
283,
265,
7,
272,
13642,
275,
1798,
14,
1122,
4725,
500,
21279,
16829,
272,
1798,
14,
1807,
63,
2246,
63,
1418,
342,
272,
372,
10111,
794,
1716,
8,
14371,
12,
675,
63,
76,
709,
78,
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
] |
[
1639,
14,
1160,
492,
11243,
12,
5013,
12,
17762,
199,
504,
1639,
14,
1208,
492,
6752,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
199,
2683,
275,
11243,
342,
421,
199,
32,
2683,
14,
1541,
8,
374,
63,
3489,
29,
797,
9,
199,
318,
2257,
794,
8,
585,
304,
272,
408,
272,
2104,
823,
282,
574,
370,
506,
8018,
465,
282,
25460,
574,
12,
272,
15270,
402,
314,
574,
402,
1124,
1751,
14,
4701,
63,
44,
709,
46,
4345,
272,
408,
272,
372,
3542,
63,
505,
8,
6321,
14,
21279,
8,
585,
12,
675,
63,
76,
709,
78,
29,
549,
430,
421,
199,
32,
2683,
14,
1541,
8,
374,
63,
3489,
29,
797,
9,
199,
318,
625,
21279,
8,
585,
304,
272,
408,
272,
2104,
823,
282,
574,
370,
506,
8018,
465,
282,
2222,
13,
22729,
574,
12,
272,
15270,
402,
314,
574,
402,
1124,
1751,
14,
4701,
63,
44,
709,
46,
4345,
272,
408,
272,
372,
3542,
63,
505,
8,
585,
9,
421,
199,
533,
10111,
794,
1716,
8,
1716,
304,
272,
347,
636,
826,
721,
277,
12,
13642,
12,
675,
63,
76,
709,
78,
304,
267,
291,
14,
14371,
275,
13642,
267,
291,
14,
1180,
63,
76,
709,
78,
275,
675,
63,
76,
709,
78,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
3886,
5339,
794,
1716,
4335,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
2269,
63,
6031,
275,
1067,
14,
1180,
63,
76,
709,
78,
267,
1067,
14,
1180,
63,
76,
709,
78,
275,
291,
14,
1180,
63,
76,
709,
78,
267,
1072,
275,
291,
14,
14371,
14,
3352,
8,
1100,
9,
267,
1067,
14,
1180,
63,
76,
709,
78,
275,
2269,
63,
6031,
267,
372,
1072,
421,
199,
32,
2683,
14,
1450,
360,
21279,
358,
199,
318,
2257,
794,
63,
1450,
8,
2087,
12,
1526,
304,
272,
408,
272,
2104,
823,
503,
21925,
2257,
2072,
402,
1338,
12,
15270,
402,
314,
574,
402,
272,
658,
1751,
14,
4701,
63,
44,
709,
46,
2313,
339,
15227,
4503,
447,
398,
7749,
2257,
794,
2331,
3674,
288,
2729,
6682,
275,
8448,
650,
14,
32689,
3586,
27,
267,
7749,
1284,
21279,
3674,
272,
408,
272,
675,
63,
76,
709,
78,
275,
488,
272,
5821,
275,
769,
8,
1418,
14,
1294,
63,
4407,
1012,
272,
340,
822,
8,
5609,
9,
508,
413,
26,
267,
675,
63,
76,
709,
78,
275,
715,
272,
916,
822,
8,
5609,
9,
690,
499,
503,
5821,
59,
17,
61,
440,
315,
661,
265,
297,
283,
1997,
735,
267,
746,
17762,
3647,
82,
1423,
1077,
506,
283,
265,
7,
503,
283,
1997,
4065,
450,
5821,
59,
16,
566,
272,
587,
26,
267,
675,
63,
76,
709,
78,
275,
5821,
59,
17,
61,
508,
283,
265,
7,
272,
13642,
275,
1798,
14,
1122,
4725,
500,
21279,
16829,
272,
1798,
14,
1807,
63,
2246,
63,
1418,
342,
272,
372,
10111,
794,
1716,
8,
14371,
12,
675,
63,
76,
709,
78,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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-
# Copyright: (c) 2017, Red Hat, Inc.
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'core'}
DOCUMENTATION = '''
module: win_disk_image
short_description: Manage ISO/VHD/VHDX mounts on Windows hosts
version_added: '2.3'
description:
- Manages mount behavior for a specified ISO, VHD, or VHDX image on a Windows host. When C(state) is C(present),
the image will be mounted under a system-assigned drive letter, which will be returned in the C(mount_path) value
of the module result. Requires Windows 8+ or Windows Server 2012+.
options:
image_path:
description:
- Path to an ISO, VHD, or VHDX image on the target Windows host (the file cannot reside on a network share)
required: yes
state:
description:
- Whether the image should be present as a drive-letter mount or not.
choices: [ absent, present ]
default: present
author:
- Matt Davis (@nitzmahone)
'''
RETURN = r'''
mount_path:
description: filesystem path where the target image is mounted
returned: when C(state) is C(present)
type: string
sample: F:\
'''
EXAMPLES = r'''
# Run installer from mounted ISO, then unmount
- name: Ensure an ISO is mounted
win_disk_image:
image_path: C:\install.iso
state: present
register: disk_image_out
- name: Run installer from mounted iso
win_package:
path: '{{ disk_image_out.mount_path }}setup\setup.exe'
product_id: 35a4e767-0161-46b0-979f-e61f282fee21
state: present
- name: Unmount iso
win_disk_image:
image_path: C:\install.iso
state: absent
'''
|
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,
9708,
12,
9572,
13002,
12,
3277,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
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,
1018,
936,
199,
199,
8948,
275,
1449,
199,
578,
26,
4747,
63,
4032,
63,
1569,
199,
3612,
63,
1802,
26,
14944,
9055,
15,
54,
14903,
15,
54,
14903,
56,
10760,
83,
641,
5417,
7057,
199,
1023,
63,
3270,
26,
283,
18,
14,
19,
7,
199,
1802,
26,
1362,
446,
21612,
10760,
5953,
367,
282,
2013,
9055,
12,
812,
14903,
12,
503,
812,
14903,
56,
1834,
641,
282,
5417,
1591,
14,
3979,
445,
8,
929,
9,
365,
445,
8,
1881,
395,
2126,
314,
1834,
911,
506,
27979,
1334,
282,
2656,
13,
12941,
12912,
8082,
12,
1314,
911,
506,
2138,
315,
314,
445,
8,
3956,
63,
515,
9,
574,
2126,
402,
314,
859,
754,
14,
15127,
5417,
1695,
11,
503,
5417,
7146,
6029,
26240,
199,
1419,
26,
523,
1834,
63,
515,
26,
272,
1369,
26,
489,
446,
6912,
370,
376,
9055,
12,
812,
14903,
12,
503,
812,
14903,
56,
1834,
641,
314,
1347,
5417,
1591,
334,
1589,
570,
3913,
295,
2441,
641,
282,
2784,
8663,
9,
272,
1415,
26,
9456,
523,
1174,
26,
272,
1369,
26,
489,
446,
7480,
314,
1834,
1077,
506,
3451,
465,
282,
12912,
13,
9269,
10760,
503,
440,
14,
272,
3415,
26,
359,
9552,
12,
3451,
1622,
272,
849,
26,
3451,
199,
2502,
26,
272,
446,
31653,
577,
1214,
374,
8593,
78,
23751,
391,
72,
368,
9,
199,
2344,
199,
199,
9677,
275,
519,
2344,
199,
3956,
63,
515,
26,
272,
1369,
26,
10036,
931,
2382,
314,
1347,
1834,
365,
27979,
272,
2138,
26,
1380,
445,
8,
929,
9,
365,
445,
8,
1881,
9,
272,
730,
26,
1059,
272,
2690,
26,
481,
3427,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
3,
3378,
18535,
687,
27979,
9055,
12,
2066,
625,
3956,
199,
13,
536,
26,
7523,
376,
9055,
365,
27979,
523,
4747,
63,
4032,
63,
1569,
26,
272,
1834,
63,
515,
26,
445,
3427,
3174,
14,
4595,
272,
1174,
26,
3451,
523,
2274,
26,
4543,
63,
1569,
63,
548,
199,
199,
13,
536,
26,
3378,
18535,
687,
27979,
11601,
523,
4747,
63,
2491,
26,
272,
931,
26,
11400,
4543,
63,
1569,
63,
548,
14,
3956,
63,
515,
3586,
2758,
60,
2758,
14,
5803,
7,
272,
3336,
63,
344,
26,
8685,
65,
20,
69,
14787,
13,
27793,
13,
2466,
66,
16,
13,
31955,
70,
13,
69,
2976,
70,
16450,
11195,
2025,
272,
1174,
26,
3451,
199,
199,
13,
536,
26,
1910,
3956,
11601,
523,
4747,
63,
4032,
63,
1569,
26,
272,
1834,
63,
515,
26,
445,
3427,
3174,
14,
4595,
272,
1174,
26,
9552,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
26,
334,
67,
9,
9708,
12,
9572,
13002,
12,
3277,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
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,
1018,
936,
199,
199,
8948,
275,
1449,
199,
578,
26,
4747,
63,
4032,
63,
1569,
199,
3612,
63,
1802,
26,
14944,
9055,
15,
54,
14903,
15,
54,
14903,
56,
10760,
83,
641,
5417,
7057,
199,
1023,
63,
3270,
26,
283,
18,
14,
19,
7,
199,
1802,
26,
1362,
446,
21612,
10760,
5953,
367,
282,
2013,
9055,
12,
812,
14903,
12,
503,
812,
14903,
56,
1834,
641,
282,
5417,
1591,
14,
3979,
445,
8,
929,
9,
365,
445,
8,
1881,
395,
2126,
314,
1834,
911,
506,
27979,
1334,
282,
2656,
13,
12941,
12912,
8082,
12,
1314,
911,
506,
2138,
315,
314,
445,
8,
3956,
63,
515,
9,
574,
2126,
402,
314,
859,
754,
14,
15127,
5417,
1695,
11,
503,
5417,
7146,
6029,
26240,
199,
1419,
26,
523,
1834,
63,
515,
26,
272,
1369,
26,
489,
446,
6912,
370,
376,
9055,
12,
812,
14903,
12,
503,
812,
14903,
56,
1834,
641,
314,
1347,
5417,
1591,
334,
1589,
570,
3913,
295,
2441,
641,
282,
2784,
8663,
9,
272,
1415,
26,
9456,
523,
1174,
26,
272,
1369,
26,
489,
446,
7480,
314,
1834,
1077,
506,
3451,
465,
282,
12912,
13,
9269,
10760,
503,
440,
14,
272,
3415,
26,
359,
9552,
12,
3451,
1622,
272,
849,
26,
3451,
199,
2502,
26,
272,
446,
31653,
577,
1214,
374,
8593,
78,
23751,
391,
72,
368,
9,
199,
2344,
199,
199,
9677,
275,
519,
2344,
199,
3956,
63,
515,
26,
272,
1369,
26,
10036,
931,
2382,
314,
1347,
1834,
365,
27979,
272,
2138,
26,
1380,
445,
8,
929,
9,
365,
445,
8,
1881,
9,
272,
730,
26,
1059,
272,
2690,
26,
481,
3427,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
3,
3378,
18535,
687,
27979,
9055,
12,
2066,
625,
3956,
199,
13,
536,
26,
7523,
376,
9055,
365,
27979,
523,
4747,
63,
4032,
63,
1569,
26,
272,
1834,
63,
515,
26,
445,
3427,
3174,
14,
4595,
272,
1174,
26,
3451,
523,
2274,
26,
4543,
63,
1569,
63,
548,
199,
199,
13,
536,
26,
3378,
18535,
687,
27979,
11601,
523,
4747,
63,
2491,
26,
272,
931,
26,
11400,
4543,
63,
1569,
63,
548,
14,
3956,
63,
515,
3586,
2758,
60,
2758,
14,
5803,
7,
272,
3336,
63,
344,
26,
8685,
65,
20,
69,
14787,
13,
27793,
13,
2466,
66,
16,
13,
31955,
70,
13,
69,
2976,
70,
16450,
11195,
2025,
272,
1174,
26,
3451,
199,
199,
13,
536,
26,
1910,
3956,
11601,
523,
4747,
63,
4032,
63,
1569,
26,
272,
1834,
63,
515,
26,
445,
3427,
3174,
14,
4595,
272,
1174,
26,
9552,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
arskom/spyne
|
spyne/test/interop/server/httprpc_pod_basic_twisted.py
|
2
|
2015
|
#!/usr/bin/env python
#
# spyne - Copyright (C) Spyne contributors.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
#
"""pod being plain old data"""
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('spyne.protocol.xml')
logger.setLevel(logging.DEBUG)
from spyne.test.interop.server import get_open_port
from spyne.application import Application
from spyne.test.interop.server._service import services
from spyne.protocol.http import HttpRpc
from spyne.server.twisted import TwistedWebResource
httprpc_soap_application = Application(services,
'spyne.test.interop.server.httprpc.pod',
in_protocol=HttpRpc(), out_protocol=HttpRpc())
host = '127.0.0.1'
port = [0]
def main(argv):
from twisted.web.server import Site
from twisted.internet import reactor
from twisted.python import log
observer = log.PythonLoggingObserver('twisted')
log.startLoggingWithObserver(observer.emit, setStdout=False)
if port[0] == 0:
port[0] = get_open_port()
wr = TwistedWebResource(httprpc_soap_application)
site = Site(wr)
reactor.listenTCP(port[0], site)
logging.info("listening on: %s:%d" % (host,port[0]))
return reactor.run()
if __name__ == '__main__':
import sys
sys.exit(main(sys.argv))
|
lgpl-2.1
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
308,
647,
685,
446,
1898,
334,
35,
9,
428,
647,
685,
8417,
14,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
199,
3,
199,
199,
624,
12656,
3769,
8971,
2269,
666,
624,
199,
199,
646,
2050,
199,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
5287,
9,
199,
2921,
275,
2050,
14,
5572,
360,
15252,
685,
14,
3922,
14,
1652,
358,
199,
2921,
14,
13548,
8,
4806,
14,
5287,
9,
199,
199,
504,
308,
647,
685,
14,
396,
14,
5707,
2675,
14,
1000,
492,
664,
63,
1490,
63,
719,
199,
504,
308,
647,
685,
14,
3578,
492,
13515,
199,
504,
308,
647,
685,
14,
396,
14,
5707,
2675,
14,
1000,
423,
1364,
492,
8500,
199,
504,
308,
647,
685,
14,
3922,
14,
1014,
492,
4760,
15569,
199,
504,
308,
647,
685,
14,
1000,
14,
12145,
492,
17078,
5926,
4031,
199,
199,
1014,
4354,
63,
21818,
63,
3578,
275,
13515,
8,
5950,
12,
1816,
283,
15252,
685,
14,
396,
14,
5707,
2675,
14,
1000,
14,
1014,
4354,
14,
12656,
297,
1816,
315,
63,
3922,
29,
5779,
15569,
1062,
734,
63,
3922,
29,
5779,
15569,
1012,
199,
199,
1102,
275,
283,
4195,
14,
16,
14,
16,
14,
17,
7,
199,
719,
275,
359,
16,
61,
199,
199,
318,
2446,
8,
3020,
304,
272,
687,
7390,
14,
2520,
14,
1000,
492,
11666,
272,
687,
7390,
14,
4901,
492,
9655,
272,
687,
7390,
14,
1548,
492,
943,
272,
27336,
275,
943,
14,
4718,
14054,
22715,
360,
12145,
358,
272,
943,
14,
928,
14054,
3007,
22715,
8,
23968,
14,
8159,
12,
663,
26080,
29,
797,
9,
339,
340,
1844,
59,
16,
61,
508,
378,
26,
267,
1844,
59,
16,
61,
275,
664,
63,
1490,
63,
719,
342,
339,
19865,
275,
17078,
5926,
4031,
8,
1014,
4354,
63,
21818,
63,
3578,
9,
272,
4770,
275,
11666,
8,
17097,
9,
339,
9655,
14,
5859,
9735,
8,
719,
59,
16,
467,
4770,
9,
272,
2050,
14,
815,
480,
5859,
316,
641,
26,
450,
83,
2689,
68,
2,
450,
334,
1102,
12,
719,
59,
16,
2459,
339,
372,
9655,
14,
1065,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
984,
272,
984,
14,
2224,
8,
973,
8,
1274,
14,
3020,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
308,
647,
685,
446,
1898,
334,
35,
9,
428,
647,
685,
8417,
14,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
199,
3,
199,
199,
624,
12656,
3769,
8971,
2269,
666,
624,
199,
199,
646,
2050,
199,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
5287,
9,
199,
2921,
275,
2050,
14,
5572,
360,
15252,
685,
14,
3922,
14,
1652,
358,
199,
2921,
14,
13548,
8,
4806,
14,
5287,
9,
199,
199,
504,
308,
647,
685,
14,
396,
14,
5707,
2675,
14,
1000,
492,
664,
63,
1490,
63,
719,
199,
504,
308,
647,
685,
14,
3578,
492,
13515,
199,
504,
308,
647,
685,
14,
396,
14,
5707,
2675,
14,
1000,
423,
1364,
492,
8500,
199,
504,
308,
647,
685,
14,
3922,
14,
1014,
492,
4760,
15569,
199,
504,
308,
647,
685,
14,
1000,
14,
12145,
492,
17078,
5926,
4031,
199,
199,
1014,
4354,
63,
21818,
63,
3578,
275,
13515,
8,
5950,
12,
1816,
283,
15252,
685,
14,
396,
14,
5707,
2675,
14,
1000,
14,
1014,
4354,
14,
12656,
297,
1816,
315,
63,
3922,
29,
5779,
15569,
1062,
734,
63,
3922,
29,
5779,
15569,
1012,
199,
199,
1102,
275,
283,
4195,
14,
16,
14,
16,
14,
17,
7,
199,
719,
275,
359,
16,
61,
199,
199,
318,
2446,
8,
3020,
304,
272,
687,
7390,
14,
2520,
14,
1000,
492,
11666,
272,
687,
7390,
14,
4901,
492,
9655,
272,
687,
7390,
14,
1548,
492,
943,
272,
27336,
275,
943,
14,
4718,
14054,
22715,
360,
12145,
358,
272,
943,
14,
928,
14054,
3007,
22715,
8,
23968,
14,
8159,
12,
663,
26080,
29,
797,
9,
339,
340,
1844,
59,
16,
61,
508,
378,
26,
267,
1844,
59,
16,
61,
275,
664,
63,
1490,
63,
719,
342,
339,
19865,
275,
17078,
5926,
4031,
8,
1014,
4354,
63,
21818,
63,
3578,
9,
272,
4770,
275,
11666,
8,
17097,
9,
339,
9655,
14,
5859,
9735,
8,
719,
59,
16,
467,
4770,
9,
272,
2050,
14,
815,
480,
5859,
316,
641,
26,
450,
83,
2689,
68,
2,
450,
334,
1102,
12,
719,
59,
16,
2459,
339,
372,
9655,
14,
1065,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
984,
272,
984,
14,
2224,
8,
973,
8,
1274,
14,
3020,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
rsyvarth/Schemify
|
lib/wtforms/widgets/core.py
|
51
|
8239
|
from __future__ import unicode_literals
from cgi import escape
from wtforms.compat import text_type, string_types, iteritems
__all__ = (
'CheckboxInput', 'FileInput', 'HiddenInput', 'ListWidget', 'PasswordInput',
'RadioInput', 'Select', 'SubmitInput', 'TableWidget', 'TextArea',
'TextInput', 'Option'
)
def html_params(**kwargs):
"""
Generate HTML parameters from inputted keyword arguments.
The output value is sorted by the passed keys, to provide consistent output
each time this function is called with the same parameters. Because of the
frequent use of the normally reserved keywords `class` and `for`, suffixing
these with an underscore will allow them to be used.
>>> html_params(name='text1', id='f', class_='text') == 'class="text" id="f" name="text1"'
True
"""
params = []
for k,v in sorted(iteritems(kwargs)):
if k in ('class_', 'class__', 'for_'):
k = k[:-1]
if v is True:
params.append(k)
else:
params.append('%s="%s"' % (text_type(k), escape(text_type(v), quote=True)))
return ' '.join(params)
class HTMLString(text_type):
def __html__(self):
return self
class ListWidget(object):
"""
Renders a list of fields as a `ul` or `ol` list.
This is used for fields which encapsulate many inner fields as subfields.
The widget will try to iterate the field to get access to the subfields and
call them to render them.
If `prefix_label` is set, the subfield's label is printed before the field,
otherwise afterwards. The latter is useful for iterating radios or
checkboxes.
"""
def __init__(self, html_tag='ul', prefix_label=True):
assert html_tag in ('ol', 'ul')
self.html_tag = html_tag
self.prefix_label = prefix_label
def __call__(self, field, **kwargs):
kwargs.setdefault('id', field.id)
html = ['<%s %s>' % (self.html_tag, html_params(**kwargs))]
for subfield in field:
if self.prefix_label:
html.append('<li>%s %s</li>' % (subfield.label, subfield()))
else:
html.append('<li>%s %s</li>' % (subfield(), subfield.label))
html.append('</%s>' % self.html_tag)
return HTMLString(''.join(html))
class TableWidget(object):
"""
Renders a list of fields as a set of table rows with th/td pairs.
If `with_table_tag` is True, then an enclosing <table> is placed around the
rows.
Hidden fields will not be displayed with a row, instead the field will be
pushed into a subsequent table row to ensure XHTML validity. Hidden fields
at the end of the field list will appear outside the table.
"""
def __init__(self, with_table_tag=True):
self.with_table_tag = with_table_tag
def __call__(self, field, **kwargs):
html = []
if self.with_table_tag:
kwargs.setdefault('id', field.id)
html.append('<table %s>' % html_params(**kwargs))
hidden = ''
for subfield in field:
if subfield.type == 'HiddenField':
hidden += text_type(subfield)
else:
html.append('<tr><th>%s</th><td>%s%s</td></tr>' % (text_type(subfield.label), hidden, text_type(subfield)))
hidden = ''
if self.with_table_tag:
html.append('</table>')
if hidden:
html.append(hidden)
return HTMLString(''.join(html))
class Input(object):
"""
Render a basic ``<input>`` field.
This is used as the basis for most of the other input fields.
By default, the `_value()` method will be called upon the associated field
to provide the ``value=`` HTML attribute.
"""
html_params = staticmethod(html_params)
def __init__(self, input_type=None):
if input_type is not None:
self.input_type = input_type
def __call__(self, field, **kwargs):
kwargs.setdefault('id', field.id)
kwargs.setdefault('type', self.input_type)
if 'value' not in kwargs:
kwargs['value'] = field._value()
return HTMLString('<input %s>' % self.html_params(name=field.name, **kwargs))
class TextInput(Input):
"""
Render a single-line text input.
"""
input_type = 'text'
class PasswordInput(Input):
"""
Render a password input.
For security purposes, this field will not reproduce the value on a form
submit by default. To have the value filled in, set `hide_value` to
`False`.
"""
input_type = 'password'
def __init__(self, hide_value=True):
self.hide_value = hide_value
def __call__(self, field, **kwargs):
if self.hide_value:
kwargs['value'] = ''
return super(PasswordInput, self).__call__(field, **kwargs)
class HiddenInput(Input):
"""
Render a hidden input.
"""
input_type = 'hidden'
class CheckboxInput(Input):
"""
Render a checkbox.
The ``checked`` HTML attribute is set if the field's data is a non-false value.
"""
input_type = 'checkbox'
def __call__(self, field, **kwargs):
if getattr(field, 'checked', field.data):
kwargs['checked'] = True
return super(CheckboxInput, self).__call__(field, **kwargs)
class RadioInput(Input):
"""
Render a single radio button.
This widget is most commonly used in conjunction with ListWidget or some
other listing, as singular radio buttons are not very useful.
"""
input_type = 'radio'
def __call__(self, field, **kwargs):
if field.checked:
kwargs['checked'] = True
return super(RadioInput, self).__call__(field, **kwargs)
class FileInput(object):
"""
Renders a file input chooser field.
"""
def __call__(self, field, **kwargs):
kwargs.setdefault('id', field.id)
return HTMLString('<input %s>' % html_params(name=field.name, type='file', **kwargs))
class SubmitInput(Input):
"""
Renders a submit button.
The field's label is used as the text of the submit button instead of the
data on the field.
"""
input_type = 'submit'
def __call__(self, field, **kwargs):
kwargs.setdefault('value', field.label.text)
return super(SubmitInput, self).__call__(field, **kwargs)
class TextArea(object):
"""
Renders a multi-line text area.
`rows` and `cols` ought to be passed as keyword args when rendering.
"""
def __call__(self, field, **kwargs):
kwargs.setdefault('id', field.id)
return HTMLString('<textarea %s>%s</textarea>' % (html_params(name=field.name, **kwargs), escape(text_type(field._value()))))
class Select(object):
"""
Renders a select field.
If `multiple` is True, then the `size` property should be specified on
rendering to make the field useful.
The field must provide an `iter_choices()` method which the widget will
call on rendering; this method must yield tuples of
`(value, label, selected)`.
"""
def __init__(self, multiple=False):
self.multiple = multiple
def __call__(self, field, **kwargs):
kwargs.setdefault('id', field.id)
if self.multiple:
kwargs['multiple'] = True
html = ['<select %s>' % html_params(name=field.name, **kwargs)]
for val, label, selected in field.iter_choices():
html.append(self.render_option(val, label, selected))
html.append('</select>')
return HTMLString(''.join(html))
@classmethod
def render_option(cls, value, label, selected, **kwargs):
options = dict(kwargs, value=value)
if selected:
options['selected'] = True
return HTMLString('<option %s>%s</option>' % (html_params(**options), escape(text_type(label))))
class Option(object):
"""
Renders the individual option from a select field.
This is just a convenience for various custom rendering situations, and an
option by itself does not constitute an entire field.
"""
def __call__(self, field, **kwargs):
return Select.render_option(field._value(), field.label.text, field.checked, **kwargs)
|
mit
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
16004,
492,
4772,
199,
199,
504,
24756,
3351,
14,
5819,
492,
1318,
63,
466,
12,
1059,
63,
1313,
12,
10849,
199,
199,
363,
452,
363,
275,
334,
272,
283,
26366,
3205,
297,
283,
1173,
3205,
297,
283,
25419,
297,
283,
1296,
3339,
297,
283,
31804,
297,
272,
283,
16065,
3205,
297,
283,
5446,
297,
283,
17187,
3205,
297,
283,
3186,
3339,
297,
283,
1872,
11043,
297,
272,
283,
18362,
297,
283,
2602,
7,
199,
9,
421,
199,
318,
3517,
63,
1162,
3682,
958,
304,
272,
408,
272,
7958,
4163,
2633,
687,
1324,
471,
4252,
2368,
14,
339,
710,
1072,
574,
365,
3355,
701,
314,
3032,
2883,
12,
370,
5647,
12137,
1072,
272,
1924,
900,
642,
805,
365,
2797,
543,
314,
2011,
2633,
14,
221,
13821,
402,
314,
272,
28914,
675,
402,
314,
12252,
4644,
7681,
658,
533,
64,
436,
658,
509,
3559,
4739,
316,
272,
3520,
543,
376,
18888,
911,
2040,
3062,
370,
506,
1202,
14,
339,
1306,
3517,
63,
1162,
8,
354,
534,
505,
17,
297,
1305,
534,
70,
297,
1021,
7993,
505,
358,
508,
283,
533,
628,
505,
2,
1305,
628,
70,
2,
536,
628,
505,
17,
4507,
272,
715,
272,
408,
272,
1862,
275,
942,
272,
367,
1022,
12,
86,
315,
3355,
8,
4611,
8,
958,
2298,
267,
340,
1022,
315,
661,
533,
14474,
283,
533,
7500,
283,
509,
25865,
288,
1022,
275,
1022,
4439,
17,
61,
267,
340,
373,
365,
715,
26,
288,
1862,
14,
740,
8,
75,
9,
267,
587,
26,
288,
1862,
14,
740,
3508,
83,
5961,
83,
4507,
450,
334,
505,
63,
466,
8,
75,
395,
4772,
8,
505,
63,
466,
8,
86,
395,
6313,
29,
549,
1724,
272,
372,
283,
1987,
904,
8,
1162,
9,
421,
199,
533,
4163,
1558,
8,
505,
63,
466,
304,
272,
347,
636,
1360,
721,
277,
304,
267,
372,
291,
421,
199,
533,
3820,
3339,
8,
785,
304,
272,
408,
272,
10055,
7735,
282,
769,
402,
1504,
465,
282,
658,
348,
64,
503,
658,
393,
64,
769,
14,
339,
961,
365,
1202,
367,
1504,
1314,
22667,
5434,
5002,
6506,
1504,
465,
1007,
955,
14,
272,
710,
3938,
911,
862,
370,
13974,
314,
901,
370,
664,
2879,
370,
314,
1007,
955,
436,
272,
1240,
3062,
370,
3795,
3062,
14,
339,
982,
658,
1861,
63,
1302,
64,
365,
663,
12,
314,
31014,
1159,
1768,
365,
12487,
2544,
314,
901,
12,
272,
4257,
26982,
14,
710,
19045,
365,
2997,
367,
25012,
14070,
736,
503,
272,
1104,
12922,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3517,
63,
1450,
534,
348,
297,
2403,
63,
1302,
29,
549,
304,
267,
702,
3517,
63,
1450,
315,
661,
393,
297,
283,
348,
358,
267,
291,
14,
1360,
63,
1450,
275,
3517,
63,
1450,
267,
291,
14,
1861,
63,
1302,
275,
2403,
63,
1302,
339,
347,
636,
1250,
721,
277,
12,
901,
12,
1011,
958,
304,
267,
2074,
14,
5486,
360,
344,
297,
901,
14,
344,
9,
267,
3517,
275,
12329,
5,
83,
450,
83,
3524,
450,
334,
277,
14,
1360,
63,
1450,
12,
3517,
63,
1162,
3682,
958,
10524,
267,
367,
31014,
315,
901,
26,
288,
340,
291,
14,
1861,
63,
1302,
26,
355,
3517,
14,
740,
4827,
317,
6598,
83,
450,
83,
1108,
317,
3524,
450,
334,
11852,
14,
1302,
12,
31014,
4059,
288,
587,
26,
355,
3517,
14,
740,
4827,
317,
6598,
83,
450,
83,
1108,
317,
3524,
450,
334,
11852,
1062,
31014,
14,
1302,
430,
267,
3517,
14,
740,
26576,
83,
3524,
450,
291,
14,
1360,
63,
1450,
9,
267,
372,
4163,
1558,
17840,
904,
8,
1360,
430,
421,
199,
533,
6957,
3339,
8,
785,
304,
272,
408,
272,
10055,
7735,
282,
769,
402,
1504,
465,
282,
663,
402,
1817,
4730,
543,
294,
15,
2076,
6342,
14,
339,
982,
658,
1045,
63,
1224,
63,
1450,
64,
365,
715,
12,
2066,
376,
25188,
665,
1224,
30,
365,
15090,
6818,
314,
272,
4730,
14,
339,
26401,
1504,
911,
440,
506,
9080,
543,
282,
1962,
12,
3140,
314,
901,
911,
506,
272,
22319,
1901,
282,
13372,
1817,
1962,
370,
4868,
26223,
25667,
14,
26401,
1504,
272,
737,
314,
1284,
402,
314,
901,
769,
911,
7468,
9682,
314,
1817,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
543,
63,
1224,
63,
1450,
29,
549,
304,
267,
291,
14,
1045,
63,
1224,
63,
1450,
275,
543,
63,
1224,
63,
1450,
339,
347,
636,
1250,
721,
277,
12,
901,
12,
1011,
958,
304,
267,
3517,
275,
942,
267,
340,
291,
14,
1045,
63,
1224,
63,
1450,
26,
288,
2074,
14,
5486,
360,
344,
297,
901,
14,
344,
9,
288,
3517,
14,
740,
4827,
1224,
450,
83,
3524,
450,
3517,
63,
1162,
3682,
958,
430,
267,
8752,
275,
2125,
267,
367,
31014,
315,
901,
26,
288,
340,
31014,
14,
466,
508,
283,
14983,
792,
356,
355,
8752,
847,
1318,
63,
466,
8,
11852,
9,
288,
587,
26,
355,
3517,
14,
740,
4827,
454,
2535,
273,
6598,
83,
1108,
273,
2535,
2076,
6598,
83,
5,
83,
1108,
2076,
2957,
454,
3524,
450,
334,
505,
63,
466,
8,
11852,
14,
1302,
395,
8752,
12,
1318,
63,
466,
8,
11852,
1724,
355,
8752,
275,
2125,
267,
340,
291,
14,
1045,
63,
1224,
63,
1450,
26,
288,
3517,
14,
740,
14264,
1224,
5971,
267,
340,
8752,
26,
288,
3517,
14,
740,
8,
5642,
9,
267,
372,
4163,
1558,
17840,
904,
8,
1360,
430,
421,
199,
533,
6924,
8,
785,
304,
272,
408,
272,
17769,
282,
5678,
23696,
1210,
28210,
901,
14,
339,
961,
365,
1202,
465,
314,
5597,
367,
4750,
402,
314,
1163,
1324,
1504,
14,
339,
4885,
849,
12,
314,
18494,
585,
11995,
1083,
911,
506,
2797,
12188,
314,
4568,
901,
272,
370,
5647,
314,
1124,
585,
29,
1040,
4163,
2225,
14,
272,
408,
272,
3517,
63,
1162,
275,
12822,
8,
1360,
63,
1162,
9,
339,
347,
636,
826,
721,
277,
12,
1324,
63,
466,
29,
403,
304,
267,
340,
1324,
63,
466,
365,
440,
488,
26,
288,
291,
14,
1210,
63,
466,
275,
1324,
63,
466,
339,
347,
636,
1250,
721,
277,
12,
901,
12,
1011,
958,
304,
267,
2074,
14,
5486,
360,
344,
297,
901,
14,
344,
9
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
16004,
492,
4772,
199,
199,
504,
24756,
3351,
14,
5819,
492,
1318,
63,
466,
12,
1059,
63,
1313,
12,
10849,
199,
199,
363,
452,
363,
275,
334,
272,
283,
26366,
3205,
297,
283,
1173,
3205,
297,
283,
25419,
297,
283,
1296,
3339,
297,
283,
31804,
297,
272,
283,
16065,
3205,
297,
283,
5446,
297,
283,
17187,
3205,
297,
283,
3186,
3339,
297,
283,
1872,
11043,
297,
272,
283,
18362,
297,
283,
2602,
7,
199,
9,
421,
199,
318,
3517,
63,
1162,
3682,
958,
304,
272,
408,
272,
7958,
4163,
2633,
687,
1324,
471,
4252,
2368,
14,
339,
710,
1072,
574,
365,
3355,
701,
314,
3032,
2883,
12,
370,
5647,
12137,
1072,
272,
1924,
900,
642,
805,
365,
2797,
543,
314,
2011,
2633,
14,
221,
13821,
402,
314,
272,
28914,
675,
402,
314,
12252,
4644,
7681,
658,
533,
64,
436,
658,
509,
3559,
4739,
316,
272,
3520,
543,
376,
18888,
911,
2040,
3062,
370,
506,
1202,
14,
339,
1306,
3517,
63,
1162,
8,
354,
534,
505,
17,
297,
1305,
534,
70,
297,
1021,
7993,
505,
358,
508,
283,
533,
628,
505,
2,
1305,
628,
70,
2,
536,
628,
505,
17,
4507,
272,
715,
272,
408,
272,
1862,
275,
942,
272,
367,
1022,
12,
86,
315,
3355,
8,
4611,
8,
958,
2298,
267,
340,
1022,
315,
661,
533,
14474,
283,
533,
7500,
283,
509,
25865,
288,
1022,
275,
1022,
4439,
17,
61,
267,
340,
373,
365,
715,
26,
288,
1862,
14,
740,
8,
75,
9,
267,
587,
26,
288,
1862,
14,
740,
3508,
83,
5961,
83,
4507,
450,
334,
505,
63,
466,
8,
75,
395,
4772,
8,
505,
63,
466,
8,
86,
395,
6313,
29,
549,
1724,
272,
372,
283,
1987,
904,
8,
1162,
9,
421,
199,
533,
4163,
1558,
8,
505,
63,
466,
304,
272,
347,
636,
1360,
721,
277,
304,
267,
372,
291,
421,
199,
533,
3820,
3339,
8,
785,
304,
272,
408,
272,
10055,
7735,
282,
769,
402,
1504,
465,
282,
658,
348,
64,
503,
658,
393,
64,
769,
14,
339,
961,
365,
1202,
367,
1504,
1314,
22667,
5434,
5002,
6506,
1504,
465,
1007,
955,
14,
272,
710,
3938,
911,
862,
370,
13974,
314,
901,
370,
664,
2879,
370,
314,
1007,
955,
436,
272,
1240,
3062,
370,
3795,
3062,
14,
339,
982,
658,
1861,
63,
1302,
64,
365,
663,
12,
314,
31014,
1159,
1768,
365,
12487,
2544,
314,
901,
12,
272,
4257,
26982,
14,
710,
19045,
365,
2997,
367,
25012,
14070,
736,
503,
272,
1104,
12922,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3517,
63,
1450,
534,
348,
297,
2403,
63,
1302,
29,
549,
304,
267,
702,
3517,
63,
1450,
315,
661,
393,
297,
283,
348,
358,
267,
291,
14,
1360,
63,
1450,
275,
3517,
63,
1450,
267,
291,
14,
1861,
63,
1302,
275,
2403,
63,
1302,
339,
347,
636,
1250,
721,
277,
12,
901,
12,
1011,
958,
304,
267,
2074,
14,
5486,
360,
344,
297,
901,
14,
344,
9,
267,
3517,
275,
12329,
5,
83,
450,
83,
3524,
450,
334,
277,
14,
1360,
63,
1450,
12,
3517,
63,
1162,
3682,
958,
10524,
267,
367,
31014,
315,
901,
26,
288,
340,
291,
14,
1861,
63,
1302,
26,
355,
3517,
14,
740,
4827,
317,
6598,
83,
450,
83,
1108,
317,
3524,
450,
334,
11852,
14,
1302,
12,
31014,
4059,
288,
587,
26,
355,
3517,
14,
740,
4827,
317,
6598,
83,
450,
83,
1108,
317,
3524,
450,
334,
11852,
1062,
31014,
14,
1302,
430,
267,
3517,
14,
740,
26576,
83,
3524,
450,
291,
14,
1360,
63,
1450,
9,
267,
372,
4163,
1558,
17840,
904,
8,
1360,
430,
421,
199,
533,
6957,
3339,
8,
785,
304,
272,
408,
272,
10055,
7735,
282,
769,
402,
1504,
465,
282,
663,
402,
1817,
4730,
543,
294,
15,
2076,
6342,
14,
339,
982,
658,
1045,
63,
1224,
63,
1450,
64,
365,
715,
12,
2066,
376,
25188,
665,
1224,
30,
365,
15090,
6818,
314,
272,
4730,
14,
339,
26401,
1504,
911,
440,
506,
9080,
543,
282,
1962,
12,
3140,
314,
901,
911,
506,
272,
22319,
1901,
282,
13372,
1817,
1962,
370,
4868,
26223,
25667,
14,
26401,
1504,
272,
737,
314,
1284,
402,
314,
901,
769,
911,
7468,
9682,
314,
1817,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
543,
63,
1224,
63,
1450,
29,
549,
304,
267,
291,
14,
1045,
63,
1224,
63,
1450,
275,
543,
63,
1224,
63,
1450,
339,
347,
636,
1250,
721,
277,
12,
901,
12,
1011,
958,
304,
267,
3517,
275,
942,
267,
340,
291,
14,
1045,
63,
1224,
63,
1450,
26,
288,
2074,
14,
5486,
360,
344,
297,
901,
14,
344,
9,
288,
3517,
14,
740,
4827,
1224,
450,
83,
3524,
450,
3517,
63,
1162,
3682,
958,
430,
267,
8752,
275,
2125,
267,
367,
31014,
315,
901,
26,
288,
340,
31014,
14,
466,
508,
283,
14983,
792,
356,
355,
8752,
847,
1318,
63,
466,
8,
11852,
9,
288,
587,
26,
355,
3517,
14,
740,
4827,
454,
2535,
273,
6598,
83,
1108,
273,
2535,
2076,
6598,
83,
5,
83,
1108,
2076,
2957,
454,
3524,
450,
334,
505,
63,
466,
8,
11852,
14,
1302,
395,
8752,
12,
1318,
63,
466,
8,
11852,
1724,
355,
8752,
275,
2125,
267,
340,
291,
14,
1045,
63,
1224,
63,
1450,
26,
288,
3517,
14,
740,
14264,
1224,
5971,
267,
340,
8752,
26,
288,
3517,
14,
740,
8,
5642,
9,
267,
372,
4163,
1558,
17840,
904,
8,
1360,
430,
421,
199,
533,
6924,
8,
785,
304,
272,
408,
272,
17769,
282,
5678,
23696,
1210,
28210,
901,
14,
339,
961,
365,
1202,
465,
314,
5597,
367,
4750,
402,
314,
1163,
1324,
1504,
14,
339,
4885,
849,
12,
314,
18494,
585,
11995,
1083,
911,
506,
2797,
12188,
314,
4568,
901,
272,
370,
5647,
314,
1124,
585,
29,
1040,
4163,
2225,
14,
272,
408,
272,
3517,
63,
1162,
275,
12822,
8,
1360,
63,
1162,
9,
339,
347,
636,
826,
721,
277,
12,
1324,
63,
466,
29,
403,
304,
267,
340,
1324,
63,
466,
365,
440,
488,
26,
288,
291,
14,
1210,
63,
466,
275,
1324,
63,
466,
339,
347,
636,
1250,
721,
277,
12,
901,
12,
1011,
958,
304,
267,
2074,
14,
5486,
360,
344,
297,
901,
14,
344,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
kgsn1763/deep-learning-from-scratch
|
ch08/deep_convnet.py
|
1
|
6086
|
#!/usr/bin/env python
# coding: utf-8
import sys, os
sys.path.append(os.pardir) # 親ディレクトリのファイルをインポートするための設定
import pickle
import numpy as np
from common.layers import Convolution, Relu, Pooling, Affine, Dropout, SoftmaxWithLoss
class DeepConvNet:
"""認識率99%以上の高精度なConvNet
ネットワーク構成は下記の通り
conv - relu - conv- relu - pool -
conv - relu - conv- relu - pool -
conv - relu - conv- relu - pool -
affine - relu - dropout - affine - dropout - softmax
"""
def __init__(self, input_dim=(1, 28, 28),
conv_param_1={'filter_num': 16, 'filter_size': 3, 'pad': 1, 'stride': 1},
conv_param_2={'filter_num': 16, 'filter_size': 3, 'pad': 1, 'stride': 1},
conv_param_3={'filter_num': 32, 'filter_size': 3, 'pad': 1, 'stride': 1},
conv_param_4={'filter_num': 32, 'filter_size': 3, 'pad': 2, 'stride': 1},
conv_param_5={'filter_num': 64, 'filter_size': 3, 'pad': 1, 'stride': 1},
conv_param_6={'filter_num': 64, 'filter_size': 3, 'pad': 1, 'stride': 1},
hidden_size=50, output_size=10):
# 重みの初期化===========
# 各層のニューロンひとつあたりが、前層のニューロンといくつのつながりがあるか(TODO:自動で計算する)
pre_node_nums = np.array([1*3*3, 16*3*3, 16*3*3, 32*3*3, 32*3*3, 64*3*3, 64*4*4, hidden_size])
wight_init_scales = np.sqrt(2.0 / pre_node_nums) # ReLUを使う場合に推奨される初期値
self.params = {}
pre_channel_num = input_dim[0]
for idx, conv_param in enumerate([conv_param_1, conv_param_2, conv_param_3, conv_param_4, conv_param_5, conv_param_6]):
self.params['W' + str(idx+1)] = wight_init_scales[idx] * np.random.randn(conv_param['filter_num'], pre_channel_num, conv_param['filter_size'], conv_param['filter_size'])
self.params['b' + str(idx+1)] = np.zeros(conv_param['filter_num'])
pre_channel_num = conv_param['filter_num']
self.params['W7'] = wight_init_scales[6] * np.random.randn(64*4*4, hidden_size)
self.params['b7'] = np.zeros(hidden_size)
self.params['W8'] = wight_init_scales[7] * np.random.randn(hidden_size, output_size)
self.params['b8'] = np.zeros(output_size)
# レイヤの生成===========
self.layers = []
self.layers.append(Convolution(self.params['W1'], self.params['b1'],
conv_param_1['stride'], conv_param_1['pad']))
self.layers.append(Relu())
self.layers.append(Convolution(self.params['W2'], self.params['b2'],
conv_param_2['stride'], conv_param_2['pad']))
self.layers.append(Relu())
self.layers.append(Pooling(pool_h=2, pool_w=2, stride=2))
self.layers.append(Convolution(self.params['W3'], self.params['b3'],
conv_param_3['stride'], conv_param_3['pad']))
self.layers.append(Relu())
self.layers.append(Convolution(self.params['W4'], self.params['b4'],
conv_param_4['stride'], conv_param_4['pad']))
self.layers.append(Relu())
self.layers.append(Pooling(pool_h=2, pool_w=2, stride=2))
self.layers.append(Convolution(self.params['W5'], self.params['b5'],
conv_param_5['stride'], conv_param_5['pad']))
self.layers.append(Relu())
self.layers.append(Convolution(self.params['W6'], self.params['b6'],
conv_param_6['stride'], conv_param_6['pad']))
self.layers.append(Relu())
self.layers.append(Pooling(pool_h=2, pool_w=2, stride=2))
self.layers.append(Affine(self.params['W7'], self.params['b7']))
self.layers.append(Relu())
self.layers.append(Dropout(0.5))
self.layers.append(Affine(self.params['W8'], self.params['b8']))
self.layers.append(Dropout(0.5))
self.last_layer = SoftmaxWithLoss()
def predict(self, x, train_flg=False):
for layer in self.layers:
if isinstance(layer, Dropout):
x = layer.forward(x, train_flg)
else:
x = layer.forward(x)
return x
def loss(self, x, t):
y = self.predict(x, train_flg=True)
return self.last_layer.forward(y, t)
def accuracy(self, x, t, batch_size=100):
if t.ndim != 1:
t = np.argmax(t, axis=1)
acc = 0.0
for i in range(int(x.shape[0] / batch_size)):
tx = x[i*batch_size:(i+1)*batch_size]
tt = t[i*batch_size:(i+1)*batch_size]
y = self.predict(tx, train_flg=False)
y = np.argmax(y, axis=1)
acc += np.sum(y == tt)
return acc / x.shape[0]
def gradient(self, x, t):
# forward
self.loss(x, t)
# backward
dout = 1
dout = self.last_layer.backward(dout)
tmp_layers = self.layers.copy()
tmp_layers.reverse()
for layer in tmp_layers:
dout = layer.backward(dout)
# 設定
grads = {}
for i, layer_idx in enumerate((0, 2, 5, 7, 10, 12, 15, 18)):
grads['W' + str(i+1)] = self.layers[layer_idx].dW
grads['b' + str(i+1)] = self.layers[layer_idx].db
return grads
def save_params(self, file_name="params.pkl"):
params = {}
for key, val in self.params.items():
params[key] = val
with open(file_name, 'wb') as f:
pickle.dump(params, f)
def load_params(self, file_name="params.pkl"):
with open(file_name, 'rb') as f:
params = pickle.load(f)
for key, val in params.items():
self.params[key] = val
for i, layer_idx in enumerate((0, 2, 5, 7, 10, 12, 15, 18)):
self.layers[layer_idx].W = self.params['W' + str(i+1)]
self.layers[layer_idx].b = self.params['b' + str(i+1)]
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2803,
26,
2774,
13,
24,
199,
199,
646,
984,
12,
747,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
21386,
9,
221,
327,
9065,
100,
104,
5692,
230,
5573,
97,
5692,
106,
5573,
108,
23869,
5692,
104,
14741,
5692,
244,
5573,
95,
26873,
29910,
17593,
26873,
23488,
5692,
252,
17670,
23869,
24549,
25871,
4197,
254,
5573,
224,
14741,
20278,
256,
20766,
199,
646,
5927,
199,
646,
2680,
465,
980,
199,
504,
2863,
14,
4359,
492,
19140,
3347,
12,
9781,
85,
12,
15553,
316,
12,
31030,
1132,
12,
18110,
548,
12,
27238,
988,
3007,
8610,
421,
199,
533,
577,
7840,
11596,
2480,
26,
272,
408,
165,
104,
236,
165,
256,
247,
23434,
230,
1020,
5,
23681,
22661,
14741,
166,
105,
247,
164,
111,
123,
32413,
4197,
104,
11596,
2480,
339,
221,
5692,
236,
5692,
226,
23869,
5692,
108,
17670,
5573,
108,
163,
101,
234,
16888,
31564,
24233,
20278,
247,
14741,
14333,
249,
5573,
233,
267,
8260,
446,
4668,
85,
446,
8260,
13,
4668,
85,
446,
4203,
446,
267,
8260,
446,
4668,
85,
446,
8260,
13,
4668,
85,
446,
4203,
446,
267,
8260,
446,
4668,
85,
446,
8260,
13,
4668,
85,
446,
4203,
446,
267,
31435,
446,
4668,
85,
446,
19795,
446,
31435,
446,
19795,
446,
28344,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1324,
63,
3572,
2687,
17,
12,
7294,
12,
7294,
395,
326,
8260,
63,
635,
63,
17,
3713,
1541,
63,
1507,
356,
3193,
12,
283,
1541,
63,
890,
356,
650,
12,
283,
6226,
356,
413,
12,
283,
12318,
356,
413,
1386,
326,
8260,
63,
635,
63,
18,
3713,
1541,
63,
1507,
356,
3193,
12,
283,
1541,
63,
890,
356,
650,
12,
283,
6226,
356,
413,
12,
283,
12318,
356,
413,
1386,
326,
8260,
63,
635,
63,
19,
3713,
1541,
63,
1507,
356,
4337,
12,
283,
1541,
63,
890,
356,
650,
12,
283,
6226,
356,
413,
12,
283,
12318,
356,
413,
1386,
326,
8260,
63,
635,
63,
20,
3713,
1541,
63,
1507,
356,
4337,
12,
283,
1541,
63,
890,
356,
650,
12,
283,
6226,
356,
499,
12,
283,
12318,
356,
413,
1386,
326,
8260,
63,
635,
63,
21,
3713,
1541,
63,
1507,
356,
5049,
12,
283,
1541,
63,
890,
356,
650,
12,
283,
6226,
356,
413,
12,
283,
12318,
356,
413,
1386,
326,
8260,
63,
635,
63,
22,
3713,
1541,
63,
1507,
356,
5049,
12,
283,
1541,
63,
890,
356,
650,
12,
283,
6226,
356,
413,
12,
283,
12318,
356,
413,
1386,
326,
8752,
63,
890,
29,
1400,
12,
1072,
63,
890,
29,
709,
304,
267,
327,
10469,
230,
236,
4197,
124,
14741,
9051,
252,
14152,
21018,
245,
21326,
267,
327,
7094,
239,
227,
27289,
98,
14741,
5692,
234,
5692,
99,
17670,
5692,
256,
23488,
4197,
111,
29472,
4197,
98,
4197,
225,
4197,
254,
5573,
233,
32143,
23709,
27284,
27289,
98,
14741,
5692,
234,
5692,
99,
17670,
5692,
256,
23488,
29472,
20724,
4197,
238,
4197,
98,
14741,
4197,
98,
4197,
104,
32143,
5573,
233,
32143,
4197,
225,
25871,
4197,
234,
8454,
231,
11768,
26,
27345,
104,
162,
234,
244,
31221,
20278,
231,
16716,
18056,
248,
25871,
8454,
232,
267,
876,
63,
932,
63,
16084,
275,
980,
14,
1144,
779,
17,
10,
19,
10,
19,
12,
3193,
10,
19,
10,
19,
12,
3193,
10,
19,
10,
19,
12,
4337,
10,
19,
10,
19,
12,
4337,
10,
19,
10,
19,
12,
5049,
10,
19,
10,
19,
12,
5049,
10,
20,
10,
20,
12,
8752,
63,
890,
566,
267,
336,
1070,
63,
826,
63,
30832,
275,
980,
14,
5079,
8,
18,
14,
16,
1182,
876,
63,
932,
63,
16084,
9,
221,
327,
799,
20237,
17593,
28446,
28075,
162,
255,
113,
16803,
28612,
17797,
102,
25440,
102,
4197,
244,
5573,
235,
25871,
9051,
252,
14152,
20757,
98,
398,
291,
14,
1162,
275,
1052,
267,
876,
63,
2775,
63,
1507,
275,
1324,
63,
3572,
59,
16,
61,
267,
367,
4280,
12,
8260,
63,
635,
315,
3874,
779,
5598,
63,
635,
63,
17,
12,
8260,
63,
635,
63,
18,
12,
8260,
63,
635,
63,
19,
12,
8260,
63,
635,
63,
20,
12,
8260,
63,
635,
63,
21,
12,
8260,
63,
635,
63,
22,
4682,
288,
291,
14,
1162,
459,
55,
7,
435,
620,
8,
2996,
11,
17,
1874,
275,
336,
1070,
63,
826,
63,
30832,
59,
2996,
61,
627,
980,
14,
2355,
14,
10843,
8,
5598,
63,
635,
459,
1541,
63,
1507,
995,
876,
63,
2775,
63,
1507,
12,
8260,
63,
635,
459,
1541,
63,
890,
995,
8260,
63,
635,
459,
1541,
63,
890,
1105,
288,
291,
14,
1162,
459,
66,
7,
435,
620,
8,
2996,
11,
17,
1874,
275,
980,
14,
4250,
8,
5598,
63,
635,
459,
1541,
63,
1507,
1105,
288,
876,
63,
2775,
63,
1507,
275,
8260,
63,
635,
459,
1541,
63,
1507,
418,
267,
291,
14,
1162,
459,
55,
23,
418,
275,
336,
1070,
63,
826,
63,
30832,
59,
22,
61,
627,
980,
14,
2355,
14,
10843,
8,
772,
10,
20,
10,
20,
12,
8752,
63,
890,
9,
267,
291,
14,
1162,
459,
66,
23,
418,
275,
980,
14,
4250,
8,
5642,
63,
890,
9,
267,
291,
14,
1162,
459,
55,
24,
418,
275,
336,
1070,
63,
826,
63,
30832,
59,
23,
61,
627,
980,
14,
2355,
14,
10843,
8,
5642,
63,
890,
12,
1072,
63,
890,
9,
267,
291,
14,
1162,
459,
66,
24,
418,
275,
980,
14,
4250,
8,
1199,
63,
890,
9,
398,
327,
221,
5692,
106,
26873,
5692,
98,
14741,
29319,
16888,
21326,
267,
291,
14,
4359,
275,
942,
267,
291,
14,
4359,
14,
740,
8,
27394,
8,
277,
14,
1162,
459,
55,
17,
995,
291,
14,
1162,
459,
66,
17,
995,
2574,
8260,
63,
635,
63,
17,
459,
12318,
995,
8260,
63,
635,
63,
17,
459,
6226,
5156,
267,
291,
14,
4359,
14,
740,
8,
5640,
85,
1012,
267,
291,
14,
4359,
14,
740,
8,
27394,
8,
277,
14,
1162,
459,
55,
18,
995,
291,
14,
1162,
459,
66,
18,
995,
2574,
8260,
63,
635,
63,
18,
459,
12318,
995,
8260,
63,
635,
63,
18,
459,
6226,
5156,
267,
291,
14,
4359,
14,
740,
8,
5640,
85,
1012,
267,
291,
14,
4359,
14,
740,
8,
22349,
8,
2293,
63
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2803,
26,
2774,
13,
24,
199,
199,
646,
984,
12,
747,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
21386,
9,
221,
327,
9065,
100,
104,
5692,
230,
5573,
97,
5692,
106,
5573,
108,
23869,
5692,
104,
14741,
5692,
244,
5573,
95,
26873,
29910,
17593,
26873,
23488,
5692,
252,
17670,
23869,
24549,
25871,
4197,
254,
5573,
224,
14741,
20278,
256,
20766,
199,
646,
5927,
199,
646,
2680,
465,
980,
199,
504,
2863,
14,
4359,
492,
19140,
3347,
12,
9781,
85,
12,
15553,
316,
12,
31030,
1132,
12,
18110,
548,
12,
27238,
988,
3007,
8610,
421,
199,
533,
577,
7840,
11596,
2480,
26,
272,
408,
165,
104,
236,
165,
256,
247,
23434,
230,
1020,
5,
23681,
22661,
14741,
166,
105,
247,
164,
111,
123,
32413,
4197,
104,
11596,
2480,
339,
221,
5692,
236,
5692,
226,
23869,
5692,
108,
17670,
5573,
108,
163,
101,
234,
16888,
31564,
24233,
20278,
247,
14741,
14333,
249,
5573,
233,
267,
8260,
446,
4668,
85,
446,
8260,
13,
4668,
85,
446,
4203,
446,
267,
8260,
446,
4668,
85,
446,
8260,
13,
4668,
85,
446,
4203,
446,
267,
8260,
446,
4668,
85,
446,
8260,
13,
4668,
85,
446,
4203,
446,
267,
31435,
446,
4668,
85,
446,
19795,
446,
31435,
446,
19795,
446,
28344,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1324,
63,
3572,
2687,
17,
12,
7294,
12,
7294,
395,
326,
8260,
63,
635,
63,
17,
3713,
1541,
63,
1507,
356,
3193,
12,
283,
1541,
63,
890,
356,
650,
12,
283,
6226,
356,
413,
12,
283,
12318,
356,
413,
1386,
326,
8260,
63,
635,
63,
18,
3713,
1541,
63,
1507,
356,
3193,
12,
283,
1541,
63,
890,
356,
650,
12,
283,
6226,
356,
413,
12,
283,
12318,
356,
413,
1386,
326,
8260,
63,
635,
63,
19,
3713,
1541,
63,
1507,
356,
4337,
12,
283,
1541,
63,
890,
356,
650,
12,
283,
6226,
356,
413,
12,
283,
12318,
356,
413,
1386,
326,
8260,
63,
635,
63,
20,
3713,
1541,
63,
1507,
356,
4337,
12,
283,
1541,
63,
890,
356,
650,
12,
283,
6226,
356,
499,
12,
283,
12318,
356,
413,
1386,
326,
8260,
63,
635,
63,
21,
3713,
1541,
63,
1507,
356,
5049,
12,
283,
1541,
63,
890,
356,
650,
12,
283,
6226,
356,
413,
12,
283,
12318,
356,
413,
1386,
326,
8260,
63,
635,
63,
22,
3713,
1541,
63,
1507,
356,
5049,
12,
283,
1541,
63,
890,
356,
650,
12,
283,
6226,
356,
413,
12,
283,
12318,
356,
413,
1386,
326,
8752,
63,
890,
29,
1400,
12,
1072,
63,
890,
29,
709,
304,
267,
327,
10469,
230,
236,
4197,
124,
14741,
9051,
252,
14152,
21018,
245,
21326,
267,
327,
7094,
239,
227,
27289,
98,
14741,
5692,
234,
5692,
99,
17670,
5692,
256,
23488,
4197,
111,
29472,
4197,
98,
4197,
225,
4197,
254,
5573,
233,
32143,
23709,
27284,
27289,
98,
14741,
5692,
234,
5692,
99,
17670,
5692,
256,
23488,
29472,
20724,
4197,
238,
4197,
98,
14741,
4197,
98,
4197,
104,
32143,
5573,
233,
32143,
4197,
225,
25871,
4197,
234,
8454,
231,
11768,
26,
27345,
104,
162,
234,
244,
31221,
20278,
231,
16716,
18056,
248,
25871,
8454,
232,
267,
876,
63,
932,
63,
16084,
275,
980,
14,
1144,
779,
17,
10,
19,
10,
19,
12,
3193,
10,
19,
10,
19,
12,
3193,
10,
19,
10,
19,
12,
4337,
10,
19,
10,
19,
12,
4337,
10,
19,
10,
19,
12,
5049,
10,
19,
10,
19,
12,
5049,
10,
20,
10,
20,
12,
8752,
63,
890,
566,
267,
336,
1070,
63,
826,
63,
30832,
275,
980,
14,
5079,
8,
18,
14,
16,
1182,
876,
63,
932,
63,
16084,
9,
221,
327,
799,
20237,
17593,
28446,
28075,
162,
255,
113,
16803,
28612,
17797,
102,
25440,
102,
4197,
244,
5573,
235,
25871,
9051,
252,
14152,
20757,
98,
398,
291,
14,
1162,
275,
1052,
267,
876,
63,
2775,
63,
1507,
275,
1324,
63,
3572,
59,
16,
61,
267,
367,
4280,
12,
8260,
63,
635,
315,
3874,
779,
5598,
63,
635,
63,
17,
12,
8260,
63,
635,
63,
18,
12,
8260,
63,
635,
63,
19,
12,
8260,
63,
635,
63,
20,
12,
8260,
63,
635,
63,
21,
12,
8260,
63,
635,
63,
22,
4682,
288,
291,
14,
1162,
459,
55,
7,
435,
620,
8,
2996,
11,
17,
1874,
275,
336,
1070,
63,
826,
63,
30832,
59,
2996,
61,
627,
980,
14,
2355,
14,
10843,
8,
5598,
63,
635,
459,
1541,
63,
1507,
995,
876,
63,
2775,
63,
1507,
12,
8260,
63,
635,
459,
1541,
63,
890,
995,
8260,
63,
635,
459,
1541,
63,
890,
1105,
288,
291,
14,
1162,
459,
66,
7,
435,
620,
8,
2996,
11,
17,
1874,
275,
980,
14,
4250,
8,
5598,
63,
635,
459,
1541,
63,
1507,
1105,
288,
876,
63,
2775,
63,
1507,
275,
8260,
63,
635,
459,
1541,
63,
1507,
418,
267,
291,
14,
1162,
459,
55,
23,
418,
275,
336,
1070,
63,
826,
63,
30832,
59,
22,
61,
627,
980,
14,
2355,
14,
10843,
8,
772,
10,
20,
10,
20,
12,
8752,
63,
890,
9,
267,
291,
14,
1162,
459,
66,
23,
418,
275,
980,
14,
4250,
8,
5642,
63,
890,
9,
267,
291,
14,
1162,
459,
55,
24,
418,
275,
336,
1070,
63,
826,
63,
30832,
59,
23,
61,
627,
980,
14,
2355,
14,
10843,
8,
5642,
63,
890,
12,
1072,
63,
890,
9,
267,
291,
14,
1162,
459,
66,
24,
418,
275,
980,
14,
4250,
8,
1199,
63,
890,
9,
398,
327,
221,
5692,
106,
26873,
5692,
98,
14741,
29319,
16888,
21326,
267,
291,
14,
4359,
275,
942,
267,
291,
14,
4359,
14,
740,
8,
27394,
8,
277,
14,
1162,
459,
55,
17,
995,
291,
14,
1162,
459,
66,
17,
995,
2574,
8260,
63,
635,
63,
17,
459,
12318,
995,
8260,
63,
635,
63,
17,
459,
6226,
5156,
267,
291,
14,
4359,
14,
740,
8,
5640,
85,
1012,
267,
291,
14,
4359,
14,
740,
8,
27394,
8,
277,
14,
1162,
459,
55,
18,
995,
291,
14,
1162,
459,
66,
18,
995,
2574,
8260,
63,
635,
63,
18,
459,
12318,
995,
8260,
63,
635,
63,
18,
459,
6226,
5156,
267,
291,
14,
4359,
14,
740,
8,
5640,
85,
1012,
267,
291,
14,
4359,
14,
740,
8,
22349,
8,
2293,
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,
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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
] |
SohKai/ChronoLogger
|
web/flask/lib/python2.7/site-packages/jinja2/parser.py
|
637
|
35186
|
# -*- coding: utf-8 -*-
"""
jinja2.parser
~~~~~~~~~~~~~
Implements the template parser.
:copyright: (c) 2010 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
from jinja2 import nodes
from jinja2.exceptions import TemplateSyntaxError, TemplateAssertionError
from jinja2.lexer import describe_token, describe_token_expr
from jinja2._compat import next, imap
#: statements that callinto
_statement_keywords = frozenset(['for', 'if', 'block', 'extends', 'print',
'macro', 'include', 'from', 'import',
'set'])
_compare_operators = frozenset(['eq', 'ne', 'lt', 'lteq', 'gt', 'gteq'])
class Parser(object):
"""This is the central parsing class Jinja2 uses. It's passed to
extensions and can be used to parse expressions or statements.
"""
def __init__(self, environment, source, name=None, filename=None,
state=None):
self.environment = environment
self.stream = environment._tokenize(source, name, filename, state)
self.name = name
self.filename = filename
self.closed = False
self.extensions = {}
for extension in environment.iter_extensions():
for tag in extension.tags:
self.extensions[tag] = extension.parse
self._last_identifier = 0
self._tag_stack = []
self._end_token_stack = []
def fail(self, msg, lineno=None, exc=TemplateSyntaxError):
"""Convenience method that raises `exc` with the message, passed
line number or last line number as well as the current name and
filename.
"""
if lineno is None:
lineno = self.stream.current.lineno
raise exc(msg, lineno, self.name, self.filename)
def _fail_ut_eof(self, name, end_token_stack, lineno):
expected = []
for exprs in end_token_stack:
expected.extend(imap(describe_token_expr, exprs))
if end_token_stack:
currently_looking = ' or '.join(
"'%s'" % describe_token_expr(expr)
for expr in end_token_stack[-1])
else:
currently_looking = None
if name is None:
message = ['Unexpected end of template.']
else:
message = ['Encountered unknown tag \'%s\'.' % name]
if currently_looking:
if name is not None and name in expected:
message.append('You probably made a nesting mistake. Jinja '
'is expecting this tag, but currently looking '
'for %s.' % currently_looking)
else:
message.append('Jinja was looking for the following tags: '
'%s.' % currently_looking)
if self._tag_stack:
message.append('The innermost block that needs to be '
'closed is \'%s\'.' % self._tag_stack[-1])
self.fail(' '.join(message), lineno)
def fail_unknown_tag(self, name, lineno=None):
"""Called if the parser encounters an unknown tag. Tries to fail
with a human readable error message that could help to identify
the problem.
"""
return self._fail_ut_eof(name, self._end_token_stack, lineno)
def fail_eof(self, end_tokens=None, lineno=None):
"""Like fail_unknown_tag but for end of template situations."""
stack = list(self._end_token_stack)
if end_tokens is not None:
stack.append(end_tokens)
return self._fail_ut_eof(None, stack, lineno)
def is_tuple_end(self, extra_end_rules=None):
"""Are we at the end of a tuple?"""
if self.stream.current.type in ('variable_end', 'block_end', 'rparen'):
return True
elif extra_end_rules is not None:
return self.stream.current.test_any(extra_end_rules)
return False
def free_identifier(self, lineno=None):
"""Return a new free identifier as :class:`~jinja2.nodes.InternalName`."""
self._last_identifier += 1
rv = object.__new__(nodes.InternalName)
nodes.Node.__init__(rv, 'fi%d' % self._last_identifier, lineno=lineno)
return rv
def parse_statement(self):
"""Parse a single statement."""
token = self.stream.current
if token.type != 'name':
self.fail('tag name expected', token.lineno)
self._tag_stack.append(token.value)
pop_tag = True
try:
if token.value in _statement_keywords:
return getattr(self, 'parse_' + self.stream.current.value)()
if token.value == 'call':
return self.parse_call_block()
if token.value == 'filter':
return self.parse_filter_block()
ext = self.extensions.get(token.value)
if ext is not None:
return ext(self)
# did not work out, remove the token we pushed by accident
# from the stack so that the unknown tag fail function can
# produce a proper error message.
self._tag_stack.pop()
pop_tag = False
self.fail_unknown_tag(token.value, token.lineno)
finally:
if pop_tag:
self._tag_stack.pop()
def parse_statements(self, end_tokens, drop_needle=False):
"""Parse multiple statements into a list until one of the end tokens
is reached. This is used to parse the body of statements as it also
parses template data if appropriate. The parser checks first if the
current token is a colon and skips it if there is one. Then it checks
for the block end and parses until if one of the `end_tokens` is
reached. Per default the active token in the stream at the end of
the call is the matched end token. If this is not wanted `drop_needle`
can be set to `True` and the end token is removed.
"""
# the first token may be a colon for python compatibility
self.stream.skip_if('colon')
# in the future it would be possible to add whole code sections
# by adding some sort of end of statement token and parsing those here.
self.stream.expect('block_end')
result = self.subparse(end_tokens)
# we reached the end of the template too early, the subparser
# does not check for this, so we do that now
if self.stream.current.type == 'eof':
self.fail_eof(end_tokens)
if drop_needle:
next(self.stream)
return result
def parse_set(self):
"""Parse an assign statement."""
lineno = next(self.stream).lineno
target = self.parse_assign_target()
self.stream.expect('assign')
expr = self.parse_tuple()
return nodes.Assign(target, expr, lineno=lineno)
def parse_for(self):
"""Parse a for loop."""
lineno = self.stream.expect('name:for').lineno
target = self.parse_assign_target(extra_end_rules=('name:in',))
self.stream.expect('name:in')
iter = self.parse_tuple(with_condexpr=False,
extra_end_rules=('name:recursive',))
test = None
if self.stream.skip_if('name:if'):
test = self.parse_expression()
recursive = self.stream.skip_if('name:recursive')
body = self.parse_statements(('name:endfor', 'name:else'))
if next(self.stream).value == 'endfor':
else_ = []
else:
else_ = self.parse_statements(('name:endfor',), drop_needle=True)
return nodes.For(target, iter, body, else_, test,
recursive, lineno=lineno)
def parse_if(self):
"""Parse an if construct."""
node = result = nodes.If(lineno=self.stream.expect('name:if').lineno)
while 1:
node.test = self.parse_tuple(with_condexpr=False)
node.body = self.parse_statements(('name:elif', 'name:else',
'name:endif'))
token = next(self.stream)
if token.test('name:elif'):
new_node = nodes.If(lineno=self.stream.current.lineno)
node.else_ = [new_node]
node = new_node
continue
elif token.test('name:else'):
node.else_ = self.parse_statements(('name:endif',),
drop_needle=True)
else:
node.else_ = []
break
return result
def parse_block(self):
node = nodes.Block(lineno=next(self.stream).lineno)
node.name = self.stream.expect('name').value
node.scoped = self.stream.skip_if('name:scoped')
# common problem people encounter when switching from django
# to jinja. we do not support hyphens in block names, so let's
# raise a nicer error message in that case.
if self.stream.current.type == 'sub':
self.fail('Block names in Jinja have to be valid Python '
'identifiers and may not contain hyphens, use an '
'underscore instead.')
node.body = self.parse_statements(('name:endblock',), drop_needle=True)
self.stream.skip_if('name:' + node.name)
return node
def parse_extends(self):
node = nodes.Extends(lineno=next(self.stream).lineno)
node.template = self.parse_expression()
return node
def parse_import_context(self, node, default):
if self.stream.current.test_any('name:with', 'name:without') and \
self.stream.look().test('name:context'):
node.with_context = next(self.stream).value == 'with'
self.stream.skip()
else:
node.with_context = default
return node
def parse_include(self):
node = nodes.Include(lineno=next(self.stream).lineno)
node.template = self.parse_expression()
if self.stream.current.test('name:ignore') and \
self.stream.look().test('name:missing'):
node.ignore_missing = True
self.stream.skip(2)
else:
node.ignore_missing = False
return self.parse_import_context(node, True)
def parse_import(self):
node = nodes.Import(lineno=next(self.stream).lineno)
node.template = self.parse_expression()
self.stream.expect('name:as')
node.target = self.parse_assign_target(name_only=True).name
return self.parse_import_context(node, False)
def parse_from(self):
node = nodes.FromImport(lineno=next(self.stream).lineno)
node.template = self.parse_expression()
self.stream.expect('name:import')
node.names = []
def parse_context():
if self.stream.current.value in ('with', 'without') and \
self.stream.look().test('name:context'):
node.with_context = next(self.stream).value == 'with'
self.stream.skip()
return True
return False
while 1:
if node.names:
self.stream.expect('comma')
if self.stream.current.type == 'name':
if parse_context():
break
target = self.parse_assign_target(name_only=True)
if target.name.startswith('_'):
self.fail('names starting with an underline can not '
'be imported', target.lineno,
exc=TemplateAssertionError)
if self.stream.skip_if('name:as'):
alias = self.parse_assign_target(name_only=True)
node.names.append((target.name, alias.name))
else:
node.names.append(target.name)
if parse_context() or self.stream.current.type != 'comma':
break
else:
break
if not hasattr(node, 'with_context'):
node.with_context = False
self.stream.skip_if('comma')
return node
def parse_signature(self, node):
node.args = args = []
node.defaults = defaults = []
self.stream.expect('lparen')
while self.stream.current.type != 'rparen':
if args:
self.stream.expect('comma')
arg = self.parse_assign_target(name_only=True)
arg.set_ctx('param')
if self.stream.skip_if('assign'):
defaults.append(self.parse_expression())
args.append(arg)
self.stream.expect('rparen')
def parse_call_block(self):
node = nodes.CallBlock(lineno=next(self.stream).lineno)
if self.stream.current.type == 'lparen':
self.parse_signature(node)
else:
node.args = []
node.defaults = []
node.call = self.parse_expression()
if not isinstance(node.call, nodes.Call):
self.fail('expected call', node.lineno)
node.body = self.parse_statements(('name:endcall',), drop_needle=True)
return node
def parse_filter_block(self):
node = nodes.FilterBlock(lineno=next(self.stream).lineno)
node.filter = self.parse_filter(None, start_inline=True)
node.body = self.parse_statements(('name:endfilter',),
drop_needle=True)
return node
def parse_macro(self):
node = nodes.Macro(lineno=next(self.stream).lineno)
node.name = self.parse_assign_target(name_only=True).name
self.parse_signature(node)
node.body = self.parse_statements(('name:endmacro',),
drop_needle=True)
return node
def parse_print(self):
node = nodes.Output(lineno=next(self.stream).lineno)
node.nodes = []
while self.stream.current.type != 'block_end':
if node.nodes:
self.stream.expect('comma')
node.nodes.append(self.parse_expression())
return node
def parse_assign_target(self, with_tuple=True, name_only=False,
extra_end_rules=None):
"""Parse an assignment target. As Jinja2 allows assignments to
tuples, this function can parse all allowed assignment targets. Per
default assignments to tuples are parsed, that can be disable however
by setting `with_tuple` to `False`. If only assignments to names are
wanted `name_only` can be set to `True`. The `extra_end_rules`
parameter is forwarded to the tuple parsing function.
"""
if name_only:
token = self.stream.expect('name')
target = nodes.Name(token.value, 'store', lineno=token.lineno)
else:
if with_tuple:
target = self.parse_tuple(simplified=True,
extra_end_rules=extra_end_rules)
else:
target = self.parse_primary()
target.set_ctx('store')
if not target.can_assign():
self.fail('can\'t assign to %r' % target.__class__.
__name__.lower(), target.lineno)
return target
def parse_expression(self, with_condexpr=True):
"""Parse an expression. Per default all expressions are parsed, if
the optional `with_condexpr` parameter is set to `False` conditional
expressions are not parsed.
"""
if with_condexpr:
return self.parse_condexpr()
return self.parse_or()
def parse_condexpr(self):
lineno = self.stream.current.lineno
expr1 = self.parse_or()
while self.stream.skip_if('name:if'):
expr2 = self.parse_or()
if self.stream.skip_if('name:else'):
expr3 = self.parse_condexpr()
else:
expr3 = None
expr1 = nodes.CondExpr(expr2, expr1, expr3, lineno=lineno)
lineno = self.stream.current.lineno
return expr1
def parse_or(self):
lineno = self.stream.current.lineno
left = self.parse_and()
while self.stream.skip_if('name:or'):
right = self.parse_and()
left = nodes.Or(left, right, lineno=lineno)
lineno = self.stream.current.lineno
return left
def parse_and(self):
lineno = self.stream.current.lineno
left = self.parse_not()
while self.stream.skip_if('name:and'):
right = self.parse_not()
left = nodes.And(left, right, lineno=lineno)
lineno = self.stream.current.lineno
return left
def parse_not(self):
if self.stream.current.test('name:not'):
lineno = next(self.stream).lineno
return nodes.Not(self.parse_not(), lineno=lineno)
return self.parse_compare()
def parse_compare(self):
lineno = self.stream.current.lineno
expr = self.parse_add()
ops = []
while 1:
token_type = self.stream.current.type
if token_type in _compare_operators:
next(self.stream)
ops.append(nodes.Operand(token_type, self.parse_add()))
elif self.stream.skip_if('name:in'):
ops.append(nodes.Operand('in', self.parse_add()))
elif self.stream.current.test('name:not') and \
self.stream.look().test('name:in'):
self.stream.skip(2)
ops.append(nodes.Operand('notin', self.parse_add()))
else:
break
lineno = self.stream.current.lineno
if not ops:
return expr
return nodes.Compare(expr, ops, lineno=lineno)
def parse_add(self):
lineno = self.stream.current.lineno
left = self.parse_sub()
while self.stream.current.type == 'add':
next(self.stream)
right = self.parse_sub()
left = nodes.Add(left, right, lineno=lineno)
lineno = self.stream.current.lineno
return left
def parse_sub(self):
lineno = self.stream.current.lineno
left = self.parse_concat()
while self.stream.current.type == 'sub':
next(self.stream)
right = self.parse_concat()
left = nodes.Sub(left, right, lineno=lineno)
lineno = self.stream.current.lineno
return left
def parse_concat(self):
lineno = self.stream.current.lineno
args = [self.parse_mul()]
while self.stream.current.type == 'tilde':
next(self.stream)
args.append(self.parse_mul())
if len(args) == 1:
return args[0]
return nodes.Concat(args, lineno=lineno)
def parse_mul(self):
lineno = self.stream.current.lineno
left = self.parse_div()
while self.stream.current.type == 'mul':
next(self.stream)
right = self.parse_div()
left = nodes.Mul(left, right, lineno=lineno)
lineno = self.stream.current.lineno
return left
def parse_div(self):
lineno = self.stream.current.lineno
left = self.parse_floordiv()
while self.stream.current.type == 'div':
next(self.stream)
right = self.parse_floordiv()
left = nodes.Div(left, right, lineno=lineno)
lineno = self.stream.current.lineno
return left
def parse_floordiv(self):
lineno = self.stream.current.lineno
left = self.parse_mod()
while self.stream.current.type == 'floordiv':
next(self.stream)
right = self.parse_mod()
left = nodes.FloorDiv(left, right, lineno=lineno)
lineno = self.stream.current.lineno
return left
def parse_mod(self):
lineno = self.stream.current.lineno
left = self.parse_pow()
while self.stream.current.type == 'mod':
next(self.stream)
right = self.parse_pow()
left = nodes.Mod(left, right, lineno=lineno)
lineno = self.stream.current.lineno
return left
def parse_pow(self):
lineno = self.stream.current.lineno
left = self.parse_unary()
while self.stream.current.type == 'pow':
next(self.stream)
right = self.parse_unary()
left = nodes.Pow(left, right, lineno=lineno)
lineno = self.stream.current.lineno
return left
def parse_unary(self, with_filter=True):
token_type = self.stream.current.type
lineno = self.stream.current.lineno
if token_type == 'sub':
next(self.stream)
node = nodes.Neg(self.parse_unary(False), lineno=lineno)
elif token_type == 'add':
next(self.stream)
node = nodes.Pos(self.parse_unary(False), lineno=lineno)
else:
node = self.parse_primary()
node = self.parse_postfix(node)
if with_filter:
node = self.parse_filter_expr(node)
return node
def parse_primary(self):
token = self.stream.current
if token.type == 'name':
if token.value in ('true', 'false', 'True', 'False'):
node = nodes.Const(token.value in ('true', 'True'),
lineno=token.lineno)
elif token.value in ('none', 'None'):
node = nodes.Const(None, lineno=token.lineno)
else:
node = nodes.Name(token.value, 'load', lineno=token.lineno)
next(self.stream)
elif token.type == 'string':
next(self.stream)
buf = [token.value]
lineno = token.lineno
while self.stream.current.type == 'string':
buf.append(self.stream.current.value)
next(self.stream)
node = nodes.Const(''.join(buf), lineno=lineno)
elif token.type in ('integer', 'float'):
next(self.stream)
node = nodes.Const(token.value, lineno=token.lineno)
elif token.type == 'lparen':
next(self.stream)
node = self.parse_tuple(explicit_parentheses=True)
self.stream.expect('rparen')
elif token.type == 'lbracket':
node = self.parse_list()
elif token.type == 'lbrace':
node = self.parse_dict()
else:
self.fail("unexpected '%s'" % describe_token(token), token.lineno)
return node
def parse_tuple(self, simplified=False, with_condexpr=True,
extra_end_rules=None, explicit_parentheses=False):
"""Works like `parse_expression` but if multiple expressions are
delimited by a comma a :class:`~jinja2.nodes.Tuple` node is created.
This method could also return a regular expression instead of a tuple
if no commas where found.
The default parsing mode is a full tuple. If `simplified` is `True`
only names and literals are parsed. The `no_condexpr` parameter is
forwarded to :meth:`parse_expression`.
Because tuples do not require delimiters and may end in a bogus comma
an extra hint is needed that marks the end of a tuple. For example
for loops support tuples between `for` and `in`. In that case the
`extra_end_rules` is set to ``['name:in']``.
`explicit_parentheses` is true if the parsing was triggered by an
expression in parentheses. This is used to figure out if an empty
tuple is a valid expression or not.
"""
lineno = self.stream.current.lineno
if simplified:
parse = self.parse_primary
elif with_condexpr:
parse = self.parse_expression
else:
parse = lambda: self.parse_expression(with_condexpr=False)
args = []
is_tuple = False
while 1:
if args:
self.stream.expect('comma')
if self.is_tuple_end(extra_end_rules):
break
args.append(parse())
if self.stream.current.type == 'comma':
is_tuple = True
else:
break
lineno = self.stream.current.lineno
if not is_tuple:
if args:
return args[0]
# if we don't have explicit parentheses, an empty tuple is
# not a valid expression. This would mean nothing (literally
# nothing) in the spot of an expression would be an empty
# tuple.
if not explicit_parentheses:
self.fail('Expected an expression, got \'%s\'' %
describe_token(self.stream.current))
return nodes.Tuple(args, 'load', lineno=lineno)
def parse_list(self):
token = self.stream.expect('lbracket')
items = []
while self.stream.current.type != 'rbracket':
if items:
self.stream.expect('comma')
if self.stream.current.type == 'rbracket':
break
items.append(self.parse_expression())
self.stream.expect('rbracket')
return nodes.List(items, lineno=token.lineno)
def parse_dict(self):
token = self.stream.expect('lbrace')
items = []
while self.stream.current.type != 'rbrace':
if items:
self.stream.expect('comma')
if self.stream.current.type == 'rbrace':
break
key = self.parse_expression()
self.stream.expect('colon')
value = self.parse_expression()
items.append(nodes.Pair(key, value, lineno=key.lineno))
self.stream.expect('rbrace')
return nodes.Dict(items, lineno=token.lineno)
def parse_postfix(self, node):
while 1:
token_type = self.stream.current.type
if token_type == 'dot' or token_type == 'lbracket':
node = self.parse_subscript(node)
# calls are valid both after postfix expressions (getattr
# and getitem) as well as filters and tests
elif token_type == 'lparen':
node = self.parse_call(node)
else:
break
return node
def parse_filter_expr(self, node):
while 1:
token_type = self.stream.current.type
if token_type == 'pipe':
node = self.parse_filter(node)
elif token_type == 'name' and self.stream.current.value == 'is':
node = self.parse_test(node)
# calls are valid both after postfix expressions (getattr
# and getitem) as well as filters and tests
elif token_type == 'lparen':
node = self.parse_call(node)
else:
break
return node
def parse_subscript(self, node):
token = next(self.stream)
if token.type == 'dot':
attr_token = self.stream.current
next(self.stream)
if attr_token.type == 'name':
return nodes.Getattr(node, attr_token.value, 'load',
lineno=token.lineno)
elif attr_token.type != 'integer':
self.fail('expected name or number', attr_token.lineno)
arg = nodes.Const(attr_token.value, lineno=attr_token.lineno)
return nodes.Getitem(node, arg, 'load', lineno=token.lineno)
if token.type == 'lbracket':
args = []
while self.stream.current.type != 'rbracket':
if args:
self.stream.expect('comma')
args.append(self.parse_subscribed())
self.stream.expect('rbracket')
if len(args) == 1:
arg = args[0]
else:
arg = nodes.Tuple(args, 'load', lineno=token.lineno)
return nodes.Getitem(node, arg, 'load', lineno=token.lineno)
self.fail('expected subscript expression', self.lineno)
def parse_subscribed(self):
lineno = self.stream.current.lineno
if self.stream.current.type == 'colon':
next(self.stream)
args = [None]
else:
node = self.parse_expression()
if self.stream.current.type != 'colon':
return node
next(self.stream)
args = [node]
if self.stream.current.type == 'colon':
args.append(None)
elif self.stream.current.type not in ('rbracket', 'comma'):
args.append(self.parse_expression())
else:
args.append(None)
if self.stream.current.type == 'colon':
next(self.stream)
if self.stream.current.type not in ('rbracket', 'comma'):
args.append(self.parse_expression())
else:
args.append(None)
else:
args.append(None)
return nodes.Slice(lineno=lineno, *args)
def parse_call(self, node):
token = self.stream.expect('lparen')
args = []
kwargs = []
dyn_args = dyn_kwargs = None
require_comma = False
def ensure(expr):
if not expr:
self.fail('invalid syntax for function call expression',
token.lineno)
while self.stream.current.type != 'rparen':
if require_comma:
self.stream.expect('comma')
# support for trailing comma
if self.stream.current.type == 'rparen':
break
if self.stream.current.type == 'mul':
ensure(dyn_args is None and dyn_kwargs is None)
next(self.stream)
dyn_args = self.parse_expression()
elif self.stream.current.type == 'pow':
ensure(dyn_kwargs is None)
next(self.stream)
dyn_kwargs = self.parse_expression()
else:
ensure(dyn_args is None and dyn_kwargs is None)
if self.stream.current.type == 'name' and \
self.stream.look().type == 'assign':
key = self.stream.current.value
self.stream.skip(2)
value = self.parse_expression()
kwargs.append(nodes.Keyword(key, value,
lineno=value.lineno))
else:
ensure(not kwargs)
args.append(self.parse_expression())
require_comma = True
self.stream.expect('rparen')
if node is None:
return args, kwargs, dyn_args, dyn_kwargs
return nodes.Call(node, args, kwargs, dyn_args, dyn_kwargs,
lineno=token.lineno)
def parse_filter(self, node, start_inline=False):
while self.stream.current.type == 'pipe' or start_inline:
if not start_inline:
next(self.stream)
token = self.stream.expect('name')
name = token.value
while self.stream.current.type == 'dot':
next(self.stream)
name += '.' + self.stream.expect('name').value
if self.stream.current.type == 'lparen':
args, kwargs, dyn_args, dyn_kwargs = self.parse_call(None)
else:
args = []
kwargs = []
dyn_args = dyn_kwargs = None
node = nodes.Filter(node, name, args, kwargs, dyn_args,
dyn_kwargs, lineno=token.lineno)
start_inline = False
return node
def parse_test(self, node):
token = next(self.stream)
if self.stream.current.test('name:not'):
next(self.stream)
negated = True
else:
negated = False
name = self.stream.expect('name').value
while self.stream.current.type == 'dot':
next(self.stream)
name += '.' + self.stream.expect('name').value
dyn_args = dyn_kwargs = None
kwargs = []
if self.stream.current.type == 'lparen':
args, kwargs, dyn_args, dyn_kwargs = self.parse_call(None)
elif self.stream.current.type in ('name', 'string', 'integer',
'float', 'lparen', 'lbracket',
'lbrace') and not \
self.stream.current.test_any('name:else', 'name:or',
'name:and'):
if self.stream.current.test('name:is'):
self.fail('You cannot chain multiple tests with is')
args = [self.parse_expression()]
else:
args = []
node = nodes.Test(node, name, args, kwargs, dyn_args,
dyn_kwargs, lineno=token.lineno)
if negated:
node = nodes.Not(node, lineno=token.lineno)
return node
def subparse(self, end_tokens=None):
body = []
data_buffer = []
add_data = data_buffer.append
if end_tokens is not None:
self._end_token_stack.append(end_tokens)
def flush_data():
if data_buffer:
lineno = data_buffer[0].lineno
body.append(nodes.Output(data_buffer[:], lineno=lineno))
del data_buffer[:]
try:
while self.stream:
token = self.stream.current
if token.type == 'data':
if token.value:
add_data(nodes.TemplateData(token.value,
lineno=token.lineno))
next(self.stream)
elif token.type == 'variable_begin':
next(self.stream)
add_data(self.parse_tuple(with_condexpr=True))
self.stream.expect('variable_end')
elif token.type == 'block_begin':
flush_data()
next(self.stream)
if end_tokens is not None and \
self.stream.current.test_any(*end_tokens):
return body
rv = self.parse_statement()
if isinstance(rv, list):
body.extend(rv)
else:
body.append(rv)
self.stream.expect('block_end')
else:
raise AssertionError('internal parsing error')
flush_data()
finally:
if end_tokens is not None:
self._end_token_stack.pop()
return body
def parse(self):
"""Parse the whole template into a `Template` node."""
result = nodes.Template(self.subparse(), lineno=1)
result.set_environment(self.environment)
return result
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10321,
18,
14,
2087,
272,
32202,
94,
339,
24664,
314,
1978,
1798,
14,
339,
520,
7307,
26,
334,
67,
9,
7129,
701,
314,
17300,
11682,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
504,
10321,
18,
492,
3380,
199,
504,
10321,
18,
14,
3924,
492,
17762,
12,
5458,
14844,
199,
504,
10321,
18,
14,
11729,
492,
13743,
63,
1418,
12,
13743,
63,
1418,
63,
3684,
199,
504,
10321,
18,
423,
5819,
492,
2163,
12,
23646,
421,
199,
12573,
9834,
626,
1240,
9924,
221,
199,
63,
6242,
63,
7511,
275,
9522,
2941,
509,
297,
283,
692,
297,
283,
1457,
297,
283,
11036,
297,
283,
1361,
297,
639,
283,
11300,
297,
283,
2613,
297,
283,
504,
297,
283,
646,
297,
639,
283,
409,
1105,
199,
63,
5785,
63,
12688,
275,
9522,
2941,
4077,
297,
283,
685,
297,
283,
4116,
297,
283,
20740,
81,
297,
283,
3308,
297,
283,
19586,
81,
1105,
421,
199,
533,
10191,
8,
785,
304,
272,
408,
2765,
365,
314,
18796,
6057,
1021,
17300,
18,
4440,
14,
221,
2779,
1159,
3032,
370,
272,
5478,
436,
883,
506,
1202,
370,
2198,
8455,
503,
9834,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
3734,
12,
1350,
12,
536,
29,
403,
12,
1788,
29,
403,
12,
326,
1174,
29,
403,
304,
267,
291,
14,
5418,
275,
3734,
267,
291,
14,
1745,
275,
3734,
423,
15246,
8,
1365,
12,
536,
12,
1788,
12,
1174,
9,
267,
291,
14,
354,
275,
536,
267,
291,
14,
1501,
275,
1788,
267,
291,
14,
5938,
275,
756,
267,
291,
14,
5359,
275,
1052,
267,
367,
3329,
315,
3734,
14,
1661,
63,
5359,
837,
288,
367,
1947,
315,
3329,
14,
2969,
26,
355,
291,
14,
5359,
59,
1450,
61,
275,
3329,
14,
1122,
267,
291,
423,
2019,
63,
5364,
275,
378,
267,
291,
423,
1450,
63,
2340,
275,
942,
267,
291,
423,
500,
63,
1418,
63,
2340,
275,
942,
339,
347,
2449,
8,
277,
12,
1499,
12,
5874,
29,
403,
12,
3178,
29,
20837,
304,
267,
408,
714,
23329,
1083,
626,
6534,
658,
2804,
64,
543,
314,
1245,
12,
3032,
267,
1004,
1329,
503,
2061,
1004,
1329,
465,
5521,
465,
314,
1453,
536,
436,
267,
1788,
14,
267,
408,
267,
340,
5874,
365,
488,
26,
288,
5874,
275,
291,
14,
1745,
14,
1818,
14,
3469,
267,
746,
3178,
8,
1328,
12,
5874,
12,
291,
14,
354,
12,
291,
14,
1501,
9,
339,
347,
485,
1633,
63,
337,
63,
11670,
8,
277,
12,
536,
12,
1284,
63,
1418,
63,
2340,
12,
5874,
304,
267,
1420,
275,
942,
267,
367,
23770,
315,
1284,
63,
1418,
63,
2340,
26,
288,
1420,
14,
2880,
8,
15311,
8,
11935,
63,
1418,
63,
3684,
12,
23770,
430,
267,
340,
1284,
63,
1418,
63,
2340,
26,
288,
5544,
63,
11660,
316,
275,
283,
503,
1987,
904,
8,
355,
17648,
83,
4065,
450,
13743,
63,
1418,
63,
3684,
8,
3684,
9,
355,
367,
5348,
315,
1284,
63,
1418,
63,
2340,
1988,
17,
566,
267,
587,
26,
288,
5544,
63,
11660,
316,
275,
488,
398,
340,
536,
365,
488,
26,
288,
1245,
275,
788,
8708,
1284,
402,
1978,
14,
418,
267,
587,
26,
288,
1245,
275,
788,
1327,
12613,
5809,
1947,
19095,
83,
60,
30484,
450,
536,
61,
398,
340,
5544,
63,
11660,
316,
26,
288,
340,
536,
365,
440,
488,
436,
536,
315,
1420,
26,
355,
1245,
14,
740,
360,
5556,
8646,
6326,
282,
19500,
27572,
1728,
14,
17300,
283,
3044,
283,
374,
21055,
642,
1947,
12,
1325,
5544,
10023,
283,
3044,
283,
509,
450,
83,
3530,
450,
5544,
63,
11660,
316,
9,
288,
587,
26,
355,
1245,
14,
740,
360,
42,
4135,
1990,
10023,
367,
314,
2569,
3762,
26,
283,
3044,
1543,
83,
3530,
450,
5544,
63,
11660,
316,
9,
398,
340,
291,
423,
1450,
63,
2340,
26,
288,
1245,
14,
740,
360,
1918,
6506,
2786,
1853,
626,
4839,
370,
506,
283,
2574,
283,
5938,
365,
19095,
83,
60,
30484,
450,
291,
423,
1450,
63,
2340,
1988,
17,
566,
398,
291,
14,
1633,
360,
1987,
904,
8,
1188,
395,
5874,
9,
339,
347,
2449,
63,
5187,
63,
1450,
8,
277,
12,
536,
12,
5874,
29,
403,
304,
267,
408,
10474,
340,
314,
1798,
655,
16558,
376,
5809,
1947,
14,
221,
377,
1996,
370,
2449,
267,
543,
282,
11779,
12701,
1125,
1245,
626,
4293,
1720,
370,
10405,
267,
314,
5160,
14,
267,
408,
267,
372,
291,
423,
1633,
63,
337,
63,
11670,
8,
354,
12,
291,
423,
500,
63,
1418,
63,
2340,
12,
5874,
9,
339,
347,
2449,
63,
11670,
8,
277,
12,
1284,
63,
4504,
29,
403,
12,
5874,
29,
403,
304,
267,
408,
12545,
2449,
63,
5187,
63,
1450,
1325,
367,
1284,
402,
1978,
24325,
1041,
267,
3464,
275,
769,
8,
277,
423,
500,
63,
1418,
63,
2340,
9,
267,
340,
1284,
63,
4504,
365,
440,
488,
26,
288,
3464,
14,
740,
8,
500,
63,
4504,
9,
267,
372,
291,
423,
1633,
63,
337,
63,
11670,
8,
403,
12,
3464,
12,
5874,
9,
339,
347,
365,
63,
2960,
63,
500,
8,
277,
12,
2402,
63,
500,
63,
4423,
29,
403,
304,
267,
408,
17683,
781,
737,
314,
1284,
402,
282,
2008,
30196,
267,
340,
291,
14,
1745,
14,
1818,
14,
466,
315,
661,
1975,
63,
500,
297,
283,
1457,
63,
500,
297,
283,
82,
9575,
735,
288,
372,
715,
267,
916,
2402,
63,
500,
63,
4423,
365,
440,
488,
26,
288,
372,
291,
14,
1745,
14,
1818,
14,
396,
63,
1629,
8,
2911,
63,
500,
63,
4423,
9,
267,
372,
756,
339,
347,
2867,
63,
5364,
8,
277,
12,
5874,
29,
403,
304,
267,
408,
1767,
282,
892,
2867,
5148,
465,
520,
533,
6054,
12264,
18,
14,
2415,
14,
8405,
985,
17105,
267,
291,
423,
2019,
63,
5364,
847,
413,
267,
4336,
275,
909,
855,
1222,
721,
2415,
14,
8405,
985,
9,
267,
3380,
14,
1716,
855,
826,
721,
6310,
12,
283,
329,
5,
68,
7,
450,
291,
423,
2019,
63,
5364,
12,
5874,
29,
3469,
9,
267,
372,
4336,
339,
347,
2198,
63,
6242,
8,
277,
304,
267,
408,
4003,
282,
2849,
5164,
1041,
267,
1526
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10321,
18,
14,
2087,
272,
32202,
94,
339,
24664,
314,
1978,
1798,
14,
339,
520,
7307,
26,
334,
67,
9,
7129,
701,
314,
17300,
11682,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
504,
10321,
18,
492,
3380,
199,
504,
10321,
18,
14,
3924,
492,
17762,
12,
5458,
14844,
199,
504,
10321,
18,
14,
11729,
492,
13743,
63,
1418,
12,
13743,
63,
1418,
63,
3684,
199,
504,
10321,
18,
423,
5819,
492,
2163,
12,
23646,
421,
199,
12573,
9834,
626,
1240,
9924,
221,
199,
63,
6242,
63,
7511,
275,
9522,
2941,
509,
297,
283,
692,
297,
283,
1457,
297,
283,
11036,
297,
283,
1361,
297,
639,
283,
11300,
297,
283,
2613,
297,
283,
504,
297,
283,
646,
297,
639,
283,
409,
1105,
199,
63,
5785,
63,
12688,
275,
9522,
2941,
4077,
297,
283,
685,
297,
283,
4116,
297,
283,
20740,
81,
297,
283,
3308,
297,
283,
19586,
81,
1105,
421,
199,
533,
10191,
8,
785,
304,
272,
408,
2765,
365,
314,
18796,
6057,
1021,
17300,
18,
4440,
14,
221,
2779,
1159,
3032,
370,
272,
5478,
436,
883,
506,
1202,
370,
2198,
8455,
503,
9834,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
3734,
12,
1350,
12,
536,
29,
403,
12,
1788,
29,
403,
12,
326,
1174,
29,
403,
304,
267,
291,
14,
5418,
275,
3734,
267,
291,
14,
1745,
275,
3734,
423,
15246,
8,
1365,
12,
536,
12,
1788,
12,
1174,
9,
267,
291,
14,
354,
275,
536,
267,
291,
14,
1501,
275,
1788,
267,
291,
14,
5938,
275,
756,
267,
291,
14,
5359,
275,
1052,
267,
367,
3329,
315,
3734,
14,
1661,
63,
5359,
837,
288,
367,
1947,
315,
3329,
14,
2969,
26,
355,
291,
14,
5359,
59,
1450,
61,
275,
3329,
14,
1122,
267,
291,
423,
2019,
63,
5364,
275,
378,
267,
291,
423,
1450,
63,
2340,
275,
942,
267,
291,
423,
500,
63,
1418,
63,
2340,
275,
942,
339,
347,
2449,
8,
277,
12,
1499,
12,
5874,
29,
403,
12,
3178,
29,
20837,
304,
267,
408,
714,
23329,
1083,
626,
6534,
658,
2804,
64,
543,
314,
1245,
12,
3032,
267,
1004,
1329,
503,
2061,
1004,
1329,
465,
5521,
465,
314,
1453,
536,
436,
267,
1788,
14,
267,
408,
267,
340,
5874,
365,
488,
26,
288,
5874,
275,
291,
14,
1745,
14,
1818,
14,
3469,
267,
746,
3178,
8,
1328,
12,
5874,
12,
291,
14,
354,
12,
291,
14,
1501,
9,
339,
347,
485,
1633,
63,
337,
63,
11670,
8,
277,
12,
536,
12,
1284,
63,
1418,
63,
2340,
12,
5874,
304,
267,
1420,
275,
942,
267,
367,
23770,
315,
1284,
63,
1418,
63,
2340,
26,
288,
1420,
14,
2880,
8,
15311,
8,
11935,
63,
1418,
63,
3684,
12,
23770,
430,
267,
340,
1284,
63,
1418,
63,
2340,
26,
288,
5544,
63,
11660,
316,
275,
283,
503,
1987,
904,
8,
355,
17648,
83,
4065,
450,
13743,
63,
1418,
63,
3684,
8,
3684,
9,
355,
367,
5348,
315,
1284,
63,
1418,
63,
2340,
1988,
17,
566,
267,
587,
26,
288,
5544,
63,
11660,
316,
275,
488,
398,
340,
536,
365,
488,
26,
288,
1245,
275,
788,
8708,
1284,
402,
1978,
14,
418,
267,
587,
26,
288,
1245,
275,
788,
1327,
12613,
5809,
1947,
19095,
83,
60,
30484,
450,
536,
61,
398,
340,
5544,
63,
11660,
316,
26,
288,
340,
536,
365,
440,
488,
436,
536,
315,
1420,
26,
355,
1245,
14,
740,
360,
5556,
8646,
6326,
282,
19500,
27572,
1728,
14,
17300,
283,
3044,
283,
374,
21055,
642,
1947,
12,
1325,
5544,
10023,
283,
3044,
283,
509,
450,
83,
3530,
450,
5544,
63,
11660,
316,
9,
288,
587,
26,
355,
1245,
14,
740,
360,
42,
4135,
1990,
10023,
367,
314,
2569,
3762,
26,
283,
3044,
1543,
83,
3530,
450,
5544,
63,
11660,
316,
9,
398,
340,
291,
423,
1450,
63,
2340,
26,
288,
1245,
14,
740,
360,
1918,
6506,
2786,
1853,
626,
4839,
370,
506,
283,
2574,
283,
5938,
365,
19095,
83,
60,
30484,
450,
291,
423,
1450,
63,
2340,
1988,
17,
566,
398,
291,
14,
1633,
360,
1987,
904,
8,
1188,
395,
5874,
9,
339,
347,
2449,
63,
5187,
63,
1450,
8,
277,
12,
536,
12,
5874,
29,
403,
304,
267,
408,
10474,
340,
314,
1798,
655,
16558,
376,
5809,
1947,
14,
221,
377,
1996,
370,
2449,
267,
543,
282,
11779,
12701,
1125,
1245,
626,
4293,
1720,
370,
10405,
267,
314,
5160,
14,
267,
408,
267,
372,
291,
423,
1633,
63,
337,
63,
11670,
8,
354,
12,
291,
423,
500,
63,
1418,
63,
2340,
12,
5874,
9,
339,
347,
2449,
63,
11670,
8,
277,
12,
1284,
63,
4504,
29,
403,
12,
5874,
29,
403,
304,
267,
408,
12545,
2449,
63,
5187,
63,
1450,
1325,
367,
1284,
402,
1978,
24325,
1041,
267,
3464,
275,
769,
8,
277,
423,
500,
63,
1418,
63,
2340,
9,
267,
340,
1284,
63,
4504,
365,
440,
488,
26,
288,
3464,
14,
740,
8,
500,
63,
4504,
9,
267,
372,
291,
423,
1633,
63,
337,
63,
11670,
8,
403,
12,
3464,
12,
5874,
9,
339,
347,
365,
63,
2960,
63,
500,
8,
277,
12,
2402,
63,
500,
63,
4423,
29,
403,
304,
267,
408,
17683,
781,
737,
314,
1284,
402,
282,
2008,
30196,
267,
340,
291,
14,
1745,
14,
1818,
14,
466,
315,
661,
1975,
63,
500,
297,
283,
1457,
63,
500,
297,
283,
82,
9575,
735,
288,
372,
715,
267,
916,
2402,
63,
500,
63,
4423,
365,
440,
488,
26,
288,
372,
291,
14,
1745,
14,
1818,
14,
396,
63,
1629,
8,
2911,
63,
500,
63,
4423,
9,
267,
372,
756,
339,
347,
2867,
63,
5364,
8,
277,
12,
5874,
29,
403,
304,
267,
408,
1767,
282,
892,
2867,
5148,
465,
520,
533,
6054,
12264,
18,
14,
2415,
14,
8405,
985,
17105,
267,
291,
423,
2019,
63,
5364,
847,
413,
267,
4336,
275,
909,
855,
1222,
721,
2415,
14,
8405,
985,
9,
267,
3380,
14,
1716,
855,
826,
721,
6310,
12,
283,
329,
5,
68,
7,
450,
291,
423,
2019,
63,
5364,
12,
5874,
29,
3469,
9,
267,
372,
4336,
339,
347,
2198,
63,
6242,
8,
277,
304,
267,
408,
4003,
282,
2849,
5164,
1041,
267,
1526,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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2074
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('finaid', '0009_auto_20150917_1629'),
]
operations = [
migrations.RemoveField(
model_name='financialaidapplication',
name='portfolios',
),
migrations.RemoveField(
model_name='financialaidapplication',
name='use_of_python',
),
migrations.AlterField(
model_name='financialaidapplication',
name='involvement',
field=models.CharField(help_text='Describe your involvement in any open source projects or community.', max_length=1024, verbose_name='Your involvement', blank=True),
),
migrations.AlterField(
model_name='financialaidapplication',
name='presenting',
field=models.IntegerField(help_text='Will you be speaking, hosting a poster session, or otherwise presenting at this PyCon?', verbose_name='Presenting', choices=[(1, 'Yes'), (2, 'No'), (3, "I have applied but don't know yet")]),
),
migrations.AlterField(
model_name='financialaidapplication',
name='profession',
field=models.CharField(help_text='What is your career, or where are you a student?', max_length=500, verbose_name='Profession'),
),
migrations.AlterField(
model_name='financialaidapplication',
name='travel_plans',
field=models.CharField(help_text='Please describe your travel plans, including the country you will travel from.', max_length=1024, verbose_name='Travel plans'),
),
migrations.AlterField(
model_name='financialaidapplication',
name='what_you_want',
field=models.CharField(help_text='Please tell us how you use Python currently, and what you hope to get out of attending PyCon.', max_length=500, verbose_name='How you use Python and how PyCon will help'),
),
]
|
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,
1709,
12,
6180,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
2408,
21745,
297,
283,
21144,
63,
2495,
63,
1797,
6576,
1196,
63,
975,
1398,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
5587,
792,
8,
288,
1402,
63,
354,
534,
2408,
24409,
21745,
3578,
297,
288,
536,
534,
719,
545,
317,
736,
297,
267,
2318,
267,
6180,
14,
5587,
792,
8,
288,
1402,
63,
354,
534,
2408,
24409,
21745,
3578,
297,
288,
536,
534,
1180,
63,
1618,
63,
1548,
297,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
2408,
24409,
21745,
3578,
297,
288,
536,
534,
5350,
3344,
434,
297,
288,
901,
29,
992,
14,
2183,
8,
3437,
63,
505,
534,
19506,
2195,
4572,
3344,
434,
315,
1263,
1551,
1350,
11336,
503,
23633,
3130,
1390,
63,
1267,
29,
7727,
12,
3376,
63,
354,
534,
14398,
4572,
3344,
434,
297,
4596,
29,
549,
395,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
2408,
24409,
21745,
3578,
297,
288,
536,
534,
1881,
316,
297,
288,
901,
29,
992,
14,
3901,
8,
3437,
63,
505,
534,
20326,
1265,
506,
308,
8556,
316,
12,
1591,
316,
282,
2086,
351,
2351,
12,
503,
4257,
3451,
316,
737,
642,
1611,
714,
7044,
3376,
63,
354,
534,
19794,
316,
297,
3415,
17497,
17,
12,
283,
12555,
659,
334,
18,
12,
283,
1944,
659,
334,
19,
12,
298,
41,
1172,
6781,
1325,
2793,
1133,
5715,
5966,
531,
2522,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
2408,
24409,
21745,
3578,
297,
288,
536,
534,
14979,
3552,
297,
288,
901,
29,
992,
14,
2183,
8,
3437,
63,
505,
534,
21015,
365,
2195,
10296,
281,
12,
503,
2382,
787,
1265,
282,
6474,
7044,
1390,
63,
1267,
29,
5783,
12,
3376,
63,
354,
534,
919,
70,
3552,
659,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
2408,
24409,
21745,
3578,
297,
288,
536,
534,
1239,
1090,
63,
1168,
796,
297,
288,
901,
29,
992,
14,
2183,
8,
3437,
63,
505,
534,
8254,
13743,
2195,
1468,
1090,
1620,
796,
12,
221,
5893,
314,
9023,
1265,
911,
1468,
1090,
687,
3130,
1390,
63,
1267,
29,
7727,
12,
3376,
63,
354,
534,
2437,
1090,
1620,
796,
659,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
2408,
24409,
21745,
3578,
297,
288,
536,
534,
10058,
63,
13297,
63,
7051,
297,
288,
901,
29,
992,
14,
2183,
8,
3437,
63,
505,
534,
8254,
11480,
2739,
4212,
1265,
675,
2018,
5544,
12,
436,
4052,
1265,
3661,
370,
664,
734,
402,
22624,
1098,
1611,
714,
3130,
1390,
63,
1267,
29,
5783,
12,
3376,
63,
354,
534,
18335,
1265,
675,
2018,
436,
4212,
1611,
714,
911,
1720,
659,
267,
2318,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
12,
6180,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
2408,
21745,
297,
283,
21144,
63,
2495,
63,
1797,
6576,
1196,
63,
975,
1398,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
5587,
792,
8,
288,
1402,
63,
354,
534,
2408,
24409,
21745,
3578,
297,
288,
536,
534,
719,
545,
317,
736,
297,
267,
2318,
267,
6180,
14,
5587,
792,
8,
288,
1402,
63,
354,
534,
2408,
24409,
21745,
3578,
297,
288,
536,
534,
1180,
63,
1618,
63,
1548,
297,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
2408,
24409,
21745,
3578,
297,
288,
536,
534,
5350,
3344,
434,
297,
288,
901,
29,
992,
14,
2183,
8,
3437,
63,
505,
534,
19506,
2195,
4572,
3344,
434,
315,
1263,
1551,
1350,
11336,
503,
23633,
3130,
1390,
63,
1267,
29,
7727,
12,
3376,
63,
354,
534,
14398,
4572,
3344,
434,
297,
4596,
29,
549,
395,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
2408,
24409,
21745,
3578,
297,
288,
536,
534,
1881,
316,
297,
288,
901,
29,
992,
14,
3901,
8,
3437,
63,
505,
534,
20326,
1265,
506,
308,
8556,
316,
12,
1591,
316,
282,
2086,
351,
2351,
12,
503,
4257,
3451,
316,
737,
642,
1611,
714,
7044,
3376,
63,
354,
534,
19794,
316,
297,
3415,
17497,
17,
12,
283,
12555,
659,
334,
18,
12,
283,
1944,
659,
334,
19,
12,
298,
41,
1172,
6781,
1325,
2793,
1133,
5715,
5966,
531,
2522,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
2408,
24409,
21745,
3578,
297,
288,
536,
534,
14979,
3552,
297,
288,
901,
29,
992,
14,
2183,
8,
3437,
63,
505,
534,
21015,
365,
2195,
10296,
281,
12,
503,
2382,
787,
1265,
282,
6474,
7044,
1390,
63,
1267,
29,
5783,
12,
3376,
63,
354,
534,
919,
70,
3552,
659,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
2408,
24409,
21745,
3578,
297,
288,
536,
534,
1239,
1090,
63,
1168,
796,
297,
288,
901,
29,
992,
14,
2183,
8,
3437,
63,
505,
534,
8254,
13743,
2195,
1468,
1090,
1620,
796,
12,
221,
5893,
314,
9023,
1265,
911,
1468,
1090,
687,
3130,
1390,
63,
1267,
29,
7727,
12,
3376,
63,
354,
534,
2437,
1090,
1620,
796,
659,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
2408,
24409,
21745,
3578,
297,
288,
536,
534,
10058,
63,
13297,
63,
7051,
297,
288,
901,
29,
992,
14,
2183,
8,
3437,
63,
505,
534,
8254,
11480,
2739,
4212,
1265,
675,
2018,
5544,
12,
436,
4052,
1265,
3661,
370,
664,
734,
402,
22624,
1098,
1611,
714,
3130,
1390,
63,
1267,
29,
5783,
12,
3376,
63,
354,
534,
18335,
1265,
675,
2018,
436,
4212,
1611,
714,
911,
1720,
659,
267,
2318,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,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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
] |
geodrinx/gearthview
|
ext-libs/twisted/internet/_posixstdio.py
|
19
|
5015
|
# -*- test-case-name: twisted.test.test_stdio -*-
"""Standard input/out/err support.
Future Plans::
support for stderr, perhaps
Rewrite to use the reactor instead of an ad-hoc mechanism for connecting
protocols to transport.
Maintainer: James Y Knight
"""
import warnings
from zope.interface import implements
from twisted.internet import process, error, interfaces
from twisted.python import log, failure
class PipeAddress(object):
implements(interfaces.IAddress)
class StandardIO(object):
implements(interfaces.ITransport, interfaces.IProducer,
interfaces.IConsumer, interfaces.IHalfCloseableDescriptor)
_reader = None
_writer = None
disconnected = False
disconnecting = False
def __init__(self, proto, stdin=0, stdout=1, reactor=None):
if reactor is None:
from twisted.internet import reactor
self.protocol = proto
self._writer = process.ProcessWriter(reactor, self, 'write', stdout)
self._reader = process.ProcessReader(reactor, self, 'read', stdin)
self._reader.startReading()
self.protocol.makeConnection(self)
# ITransport
# XXX Actually, see #3597.
def loseWriteConnection(self):
if self._writer is not None:
self._writer.loseConnection()
def write(self, data):
if self._writer is not None:
self._writer.write(data)
def writeSequence(self, data):
if self._writer is not None:
self._writer.writeSequence(data)
def loseConnection(self):
self.disconnecting = True
if self._writer is not None:
self._writer.loseConnection()
if self._reader is not None:
# Don't loseConnection, because we don't want to SIGPIPE it.
self._reader.stopReading()
def getPeer(self):
return PipeAddress()
def getHost(self):
return PipeAddress()
# Callbacks from process.ProcessReader/ProcessWriter
def childDataReceived(self, fd, data):
self.protocol.dataReceived(data)
def childConnectionLost(self, fd, reason):
if self.disconnected:
return
if reason.value.__class__ == error.ConnectionDone:
# Normal close
if fd == 'read':
self._readConnectionLost(reason)
else:
self._writeConnectionLost(reason)
else:
self.connectionLost(reason)
def connectionLost(self, reason):
self.disconnected = True
# Make sure to cleanup the other half
_reader = self._reader
_writer = self._writer
protocol = self.protocol
self._reader = self._writer = None
self.protocol = None
if _writer is not None and not _writer.disconnected:
_writer.connectionLost(reason)
if _reader is not None and not _reader.disconnected:
_reader.connectionLost(reason)
try:
protocol.connectionLost(reason)
except:
log.err()
def _writeConnectionLost(self, reason):
self._writer=None
if self.disconnecting:
self.connectionLost(reason)
return
p = interfaces.IHalfCloseableProtocol(self.protocol, None)
if p:
try:
p.writeConnectionLost()
except:
log.err()
self.connectionLost(failure.Failure())
def _readConnectionLost(self, reason):
self._reader=None
p = interfaces.IHalfCloseableProtocol(self.protocol, None)
if p:
try:
p.readConnectionLost()
except:
log.err()
self.connectionLost(failure.Failure())
else:
self.connectionLost(reason)
# IConsumer
def registerProducer(self, producer, streaming):
if self._writer is None:
producer.stopProducing()
else:
self._writer.registerProducer(producer, streaming)
def unregisterProducer(self):
if self._writer is not None:
self._writer.unregisterProducer()
# IProducer
def stopProducing(self):
self.loseConnection()
def pauseProducing(self):
if self._reader is not None:
self._reader.pauseProducing()
def resumeProducing(self):
if self._reader is not None:
self._reader.resumeProducing()
# Stupid compatibility:
def closeStdin(self):
"""Compatibility only, don't use. Same as loseWriteConnection."""
warnings.warn("This function is deprecated, use loseWriteConnection instead.",
category=DeprecationWarning, stacklevel=2)
self.loseWriteConnection()
def stopReading(self):
"""Compatibility only, don't use. Call pauseProducing."""
self.pauseProducing()
def startReading(self):
"""Compatibility only, don't use. Call resumeProducing."""
self.resumeProducing()
|
gpl-3.0
|
[
3,
1882,
511,
13,
2546,
13,
354,
26,
7390,
14,
396,
14,
396,
63,
32011,
1882,
199,
199,
624,
9232,
1324,
15,
548,
15,
1508,
2291,
14,
199,
199,
14224,
7497,
796,
447,
339,
2291,
367,
4635,
12,
25358,
272,
799,
952,
370,
675,
314,
9655,
3140,
402,
376,
1503,
13,
20402,
14729,
367,
18170,
267,
19230,
370,
7773,
14,
199,
199,
11903,
8368,
281,
26,
1603,
14015,
1488,
1804,
14873,
199,
624,
199,
199,
646,
3598,
199,
504,
20110,
14,
3266,
492,
9031,
199,
199,
504,
7390,
14,
4901,
492,
2112,
12,
1125,
12,
8386,
199,
504,
7390,
14,
1548,
492,
943,
12,
5988,
421,
199,
533,
16850,
1476,
8,
785,
304,
272,
9031,
8,
7436,
14,
41,
1476,
9,
421,
199,
533,
9739,
2090,
8,
785,
304,
272,
9031,
8,
7436,
14,
649,
4808,
12,
8386,
14,
41,
15532,
12,
2049,
8386,
14,
41,
18186,
12,
8386,
14,
19824,
7411,
4724,
461,
4311,
9,
339,
485,
5503,
275,
488,
272,
485,
5491,
275,
488,
272,
25602,
275,
756,
272,
17639,
316,
275,
756,
339,
347,
636,
826,
721,
277,
12,
4104,
12,
9009,
29,
16,
12,
3839,
29,
17,
12,
9655,
29,
403,
304,
267,
340,
9655,
365,
488,
26,
288,
687,
7390,
14,
4901,
492,
9655,
267,
291,
14,
3922,
275,
4104,
398,
291,
423,
5491,
275,
2112,
14,
3498,
6261,
8,
13544,
12,
291,
12,
283,
952,
297,
3839,
9,
267,
291,
423,
5503,
275,
2112,
14,
3498,
5929,
8,
13544,
12,
291,
12,
283,
739,
297,
9009,
9,
267,
291,
423,
5503,
14,
928,
20568,
342,
267,
291,
14,
3922,
14,
1875,
3225,
8,
277,
9,
339,
327,
473,
7836,
339,
327,
5787,
18982,
3163,
12,
1937,
327,
1276,
2576,
14,
272,
347,
27332,
3534,
3225,
8,
277,
304,
267,
340,
291,
423,
5491,
365,
440,
488,
26,
288,
291,
423,
5491,
14,
32452,
342,
339,
347,
2218,
8,
277,
12,
666,
304,
267,
340,
291,
423,
5491,
365,
440,
488,
26,
288,
291,
423,
5491,
14,
952,
8,
576,
9,
339,
347,
2218,
5826,
8,
277,
12,
666,
304,
267,
340,
291,
423,
5491,
365,
440,
488,
26,
288,
291,
423,
5491,
14,
952,
5826,
8,
576,
9,
339,
347,
27332,
3225,
8,
277,
304,
267,
291,
14,
10673,
316,
275,
715,
398,
340,
291,
423,
5491,
365,
440,
488,
26,
288,
291,
423,
5491,
14,
32452,
342,
267,
340,
291,
423,
5503,
365,
440,
488,
26,
288,
327,
7529,
1133,
27332,
3225,
12,
2952,
781,
2793,
1133,
2934,
370,
15522,
6089,
652,
14,
288,
291,
423,
5503,
14,
2379,
20568,
342,
339,
347,
664,
12566,
8,
277,
304,
267,
372,
16850,
1476,
342,
339,
347,
664,
4965,
8,
277,
304,
267,
372,
16850,
1476,
342,
2378,
327,
17555,
83,
687,
2112,
14,
3498,
5929,
15,
3498,
6261,
272,
347,
1982,
1451,
9392,
8,
277,
12,
6111,
12,
666,
304,
267,
291,
14,
3922,
14,
25037,
8,
576,
9,
339,
347,
1982,
3225,
14074,
8,
277,
12,
6111,
12,
4499,
304,
267,
340,
291,
14,
27476,
26,
288,
372,
398,
340,
4499,
14,
585,
855,
533,
363,
508,
1125,
14,
3225,
10759,
26,
288,
327,
11514,
4002,
288,
340,
6111,
508,
283,
739,
356,
355,
291,
423,
739,
3225,
14074,
8,
5764,
9,
288,
587,
26,
355,
291,
423,
952,
3225,
14074,
8,
5764,
9,
267,
587,
26,
288,
291,
14,
2105,
14074,
8,
5764,
9,
339,
347,
1950,
14074,
8,
277,
12,
4499,
304,
267,
291,
14,
27476,
275,
715,
398,
327,
4155,
3238,
370,
9058,
314,
1163,
12995,
267,
485,
5503,
275,
291,
423,
5503,
267,
485,
5491,
275,
291,
423,
5491,
267,
4113,
275,
291,
14,
3922,
267,
291,
423,
5503,
275,
291,
423,
5491,
275,
488,
267,
291,
14,
3922,
275,
488,
398,
340,
485,
5491,
365,
440,
488,
436,
440,
485,
5491,
14,
27476,
26,
288,
485,
5491,
14,
2105,
14074,
8,
5764,
9,
398,
340,
485,
5503,
365,
440,
488,
436,
440,
485,
5503,
14,
27476,
26,
288,
485,
5503,
14,
2105,
14074,
8,
5764,
9,
398,
862,
26,
288,
4113,
14,
2105,
14074,
8,
5764,
9,
267,
871,
26,
288,
943,
14,
1508,
342,
339,
347,
485,
952,
3225,
14074,
8,
277,
12,
4499,
304,
267,
291,
423,
5491,
29,
403,
267,
340,
291,
14,
10673,
316,
26,
288,
291,
14,
2105,
14074,
8,
5764,
9,
288,
372,
398,
299,
275,
8386,
14,
19824,
7411,
4724,
461,
3658,
8,
277,
14,
3922,
12,
488,
9,
267,
340,
299,
26,
288,
862,
26,
355,
299,
14,
952,
3225,
14074,
342,
288,
871,
26,
355,
943,
14,
1508,
342,
355,
291,
14,
2105,
14074,
8,
5328,
14,
6782,
1012,
339,
347,
485,
739,
3225,
14074,
8,
277,
12,
4499,
304,
267,
291,
423,
5503,
29,
403,
267,
299,
275,
8386,
14,
19824,
7411,
4724,
461,
3658,
8,
277,
14,
3922,
12,
488,
9,
267,
340,
299,
26,
288,
862,
26,
355,
299,
14,
739,
3225,
14074,
342,
288,
871,
26,
355,
943,
14,
1508,
342,
355,
291,
14,
2105,
14074,
8,
5328,
14,
6782,
1012,
267,
587,
26,
288,
291,
14,
2105,
14074,
8,
5764,
9,
339,
327,
473,
18186,
272,
347,
2274,
15532,
8,
277,
12,
17339,
12,
18490,
304,
267,
340,
291,
423,
5491,
365,
488,
26,
288,
17339,
14,
2379,
24982,
342,
267,
587,
26,
288,
291,
423,
5491,
14,
2683,
15532,
8,
16376,
12,
18490,
9,
339,
347,
24369,
15532,
8,
277,
304,
267,
340,
291,
423,
5491,
365,
440,
488,
26,
288,
291,
423,
5491,
14,
18408,
15532,
342,
339,
327,
473,
15532,
272,
347,
3631,
24982,
8,
277,
304,
267,
291,
14,
32452,
342,
339,
347,
16834,
24982,
8,
277,
304,
267,
340,
291,
423,
5503,
365,
440,
488,
26,
288,
291,
423,
5503,
14,
11241,
24982,
342,
339,
347,
14604,
24982,
8,
277,
304,
267,
340,
291,
423,
5503,
365,
440,
488,
26,
288,
291,
423,
5503,
14,
9964,
24982,
342,
339,
327,
1933,
31596,
7163,
26,
272,
347,
4002,
11976,
262,
8,
277,
304,
267,
408,
2404,
5880,
1454,
12,
2793,
1133,
675,
14,
14766,
465,
27332,
3534,
3225,
1041,
267,
3598,
14,
4050,
480,
2765,
805,
365,
5906,
12,
675,
27332,
3534,
3225,
3140
] |
[
1882,
511,
13,
2546,
13,
354,
26,
7390,
14,
396,
14,
396,
63,
32011,
1882,
199,
199,
624,
9232,
1324,
15,
548,
15,
1508,
2291,
14,
199,
199,
14224,
7497,
796,
447,
339,
2291,
367,
4635,
12,
25358,
272,
799,
952,
370,
675,
314,
9655,
3140,
402,
376,
1503,
13,
20402,
14729,
367,
18170,
267,
19230,
370,
7773,
14,
199,
199,
11903,
8368,
281,
26,
1603,
14015,
1488,
1804,
14873,
199,
624,
199,
199,
646,
3598,
199,
504,
20110,
14,
3266,
492,
9031,
199,
199,
504,
7390,
14,
4901,
492,
2112,
12,
1125,
12,
8386,
199,
504,
7390,
14,
1548,
492,
943,
12,
5988,
421,
199,
533,
16850,
1476,
8,
785,
304,
272,
9031,
8,
7436,
14,
41,
1476,
9,
421,
199,
533,
9739,
2090,
8,
785,
304,
272,
9031,
8,
7436,
14,
649,
4808,
12,
8386,
14,
41,
15532,
12,
2049,
8386,
14,
41,
18186,
12,
8386,
14,
19824,
7411,
4724,
461,
4311,
9,
339,
485,
5503,
275,
488,
272,
485,
5491,
275,
488,
272,
25602,
275,
756,
272,
17639,
316,
275,
756,
339,
347,
636,
826,
721,
277,
12,
4104,
12,
9009,
29,
16,
12,
3839,
29,
17,
12,
9655,
29,
403,
304,
267,
340,
9655,
365,
488,
26,
288,
687,
7390,
14,
4901,
492,
9655,
267,
291,
14,
3922,
275,
4104,
398,
291,
423,
5491,
275,
2112,
14,
3498,
6261,
8,
13544,
12,
291,
12,
283,
952,
297,
3839,
9,
267,
291,
423,
5503,
275,
2112,
14,
3498,
5929,
8,
13544,
12,
291,
12,
283,
739,
297,
9009,
9,
267,
291,
423,
5503,
14,
928,
20568,
342,
267,
291,
14,
3922,
14,
1875,
3225,
8,
277,
9,
339,
327,
473,
7836,
339,
327,
5787,
18982,
3163,
12,
1937,
327,
1276,
2576,
14,
272,
347,
27332,
3534,
3225,
8,
277,
304,
267,
340,
291,
423,
5491,
365,
440,
488,
26,
288,
291,
423,
5491,
14,
32452,
342,
339,
347,
2218,
8,
277,
12,
666,
304,
267,
340,
291,
423,
5491,
365,
440,
488,
26,
288,
291,
423,
5491,
14,
952,
8,
576,
9,
339,
347,
2218,
5826,
8,
277,
12,
666,
304,
267,
340,
291,
423,
5491,
365,
440,
488,
26,
288,
291,
423,
5491,
14,
952,
5826,
8,
576,
9,
339,
347,
27332,
3225,
8,
277,
304,
267,
291,
14,
10673,
316,
275,
715,
398,
340,
291,
423,
5491,
365,
440,
488,
26,
288,
291,
423,
5491,
14,
32452,
342,
267,
340,
291,
423,
5503,
365,
440,
488,
26,
288,
327,
7529,
1133,
27332,
3225,
12,
2952,
781,
2793,
1133,
2934,
370,
15522,
6089,
652,
14,
288,
291,
423,
5503,
14,
2379,
20568,
342,
339,
347,
664,
12566,
8,
277,
304,
267,
372,
16850,
1476,
342,
339,
347,
664,
4965,
8,
277,
304,
267,
372,
16850,
1476,
342,
2378,
327,
17555,
83,
687,
2112,
14,
3498,
5929,
15,
3498,
6261,
272,
347,
1982,
1451,
9392,
8,
277,
12,
6111,
12,
666,
304,
267,
291,
14,
3922,
14,
25037,
8,
576,
9,
339,
347,
1982,
3225,
14074,
8,
277,
12,
6111,
12,
4499,
304,
267,
340,
291,
14,
27476,
26,
288,
372,
398,
340,
4499,
14,
585,
855,
533,
363,
508,
1125,
14,
3225,
10759,
26,
288,
327,
11514,
4002,
288,
340,
6111,
508,
283,
739,
356,
355,
291,
423,
739,
3225,
14074,
8,
5764,
9,
288,
587,
26,
355,
291,
423,
952,
3225,
14074,
8,
5764,
9,
267,
587,
26,
288,
291,
14,
2105,
14074,
8,
5764,
9,
339,
347,
1950,
14074,
8,
277,
12,
4499,
304,
267,
291,
14,
27476,
275,
715,
398,
327,
4155,
3238,
370,
9058,
314,
1163,
12995,
267,
485,
5503,
275,
291,
423,
5503,
267,
485,
5491,
275,
291,
423,
5491,
267,
4113,
275,
291,
14,
3922,
267,
291,
423,
5503,
275,
291,
423,
5491,
275,
488,
267,
291,
14,
3922,
275,
488,
398,
340,
485,
5491,
365,
440,
488,
436,
440,
485,
5491,
14,
27476,
26,
288,
485,
5491,
14,
2105,
14074,
8,
5764,
9,
398,
340,
485,
5503,
365,
440,
488,
436,
440,
485,
5503,
14,
27476,
26,
288,
485,
5503,
14,
2105,
14074,
8,
5764,
9,
398,
862,
26,
288,
4113,
14,
2105,
14074,
8,
5764,
9,
267,
871,
26,
288,
943,
14,
1508,
342,
339,
347,
485,
952,
3225,
14074,
8,
277,
12,
4499,
304,
267,
291,
423,
5491,
29,
403,
267,
340,
291,
14,
10673,
316,
26,
288,
291,
14,
2105,
14074,
8,
5764,
9,
288,
372,
398,
299,
275,
8386,
14,
19824,
7411,
4724,
461,
3658,
8,
277,
14,
3922,
12,
488,
9,
267,
340,
299,
26,
288,
862,
26,
355,
299,
14,
952,
3225,
14074,
342,
288,
871,
26,
355,
943,
14,
1508,
342,
355,
291,
14,
2105,
14074,
8,
5328,
14,
6782,
1012,
339,
347,
485,
739,
3225,
14074,
8,
277,
12,
4499,
304,
267,
291,
423,
5503,
29,
403,
267,
299,
275,
8386,
14,
19824,
7411,
4724,
461,
3658,
8,
277,
14,
3922,
12,
488,
9,
267,
340,
299,
26,
288,
862,
26,
355,
299,
14,
739,
3225,
14074,
342,
288,
871,
26,
355,
943,
14,
1508,
342,
355,
291,
14,
2105,
14074,
8,
5328,
14,
6782,
1012,
267,
587,
26,
288,
291,
14,
2105,
14074,
8,
5764,
9,
339,
327,
473,
18186,
272,
347,
2274,
15532,
8,
277,
12,
17339,
12,
18490,
304,
267,
340,
291,
423,
5491,
365,
488,
26,
288,
17339,
14,
2379,
24982,
342,
267,
587,
26,
288,
291,
423,
5491,
14,
2683,
15532,
8,
16376,
12,
18490,
9,
339,
347,
24369,
15532,
8,
277,
304,
267,
340,
291,
423,
5491,
365,
440,
488,
26,
288,
291,
423,
5491,
14,
18408,
15532,
342,
339,
327,
473,
15532,
272,
347,
3631,
24982,
8,
277,
304,
267,
291,
14,
32452,
342,
339,
347,
16834,
24982,
8,
277,
304,
267,
340,
291,
423,
5503,
365,
440,
488,
26,
288,
291,
423,
5503,
14,
11241,
24982,
342,
339,
347,
14604,
24982,
8,
277,
304,
267,
340,
291,
423,
5503,
365,
440,
488,
26,
288,
291,
423,
5503,
14,
9964,
24982,
342,
339,
327,
1933,
31596,
7163,
26,
272,
347,
4002,
11976,
262,
8,
277,
304,
267,
408,
2404,
5880,
1454,
12,
2793,
1133,
675,
14,
14766,
465,
27332,
3534,
3225,
1041,
267,
3598,
14,
4050,
480,
2765,
805,
365,
5906,
12,
675,
27332,
3534,
3225,
3140,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
adamsp/adnwc
|
web/wsgi.py
|
31
|
2357
|
"""
WSGI Utilities
(from web.py)
"""
import os, sys
import http
import webapi as web
from utils import listget, intget
from net import validaddr, validip
import httpserver
def runfcgi(func, addr=('localhost', 8000)):
"""Runs a WSGI function as a FastCGI server."""
import flup.server.fcgi as flups
return flups.WSGIServer(func, multiplexed=True, bindAddress=addr, debug=False).run()
def runscgi(func, addr=('localhost', 4000)):
"""Runs a WSGI function as an SCGI server."""
import flup.server.scgi as flups
return flups.WSGIServer(func, bindAddress=addr, debug=False).run()
def runwsgi(func):
"""
Runs a WSGI-compatible `func` using FCGI, SCGI, or a simple web server,
as appropriate based on context and `sys.argv`.
"""
if os.environ.has_key('SERVER_SOFTWARE'): # cgi
os.environ['FCGI_FORCE_CGI'] = 'Y'
if (os.environ.has_key('PHP_FCGI_CHILDREN') #lighttpd fastcgi
or os.environ.has_key('SERVER_SOFTWARE')):
return runfcgi(func, None)
if 'fcgi' in sys.argv or 'fastcgi' in sys.argv:
args = sys.argv[1:]
if 'fastcgi' in args: args.remove('fastcgi')
elif 'fcgi' in args: args.remove('fcgi')
if args:
return runfcgi(func, validaddr(args[0]))
else:
return runfcgi(func, None)
if 'scgi' in sys.argv:
args = sys.argv[1:]
args.remove('scgi')
if args:
return runscgi(func, validaddr(args[0]))
else:
return runscgi(func)
server_addr = validip(listget(sys.argv, 1, ''))
if os.environ.has_key('PORT'): # e.g. Heroku
server_addr = ('0.0.0.0', intget(os.environ['PORT']))
return httpserver.runsimple(func, server_addr)
def _is_dev_mode():
# Some embedded python interpreters won't have sys.arv
# For details, see https://github.com/webpy/webpy/issues/87
argv = getattr(sys, "argv", [])
# quick hack to check if the program is running in dev mode.
if os.environ.has_key('SERVER_SOFTWARE') \
or os.environ.has_key('PHP_FCGI_CHILDREN') \
or 'fcgi' in argv or 'fastcgi' in argv \
or 'mod_wsgi' in argv:
return False
return True
# When running the builtin-server, enable debug mode if not already set.
web.config.setdefault('debug', _is_dev_mode())
|
apache-2.0
|
[
624,
199,
16828,
738,
17933,
199,
8,
504,
3330,
14,
647,
9,
199,
624,
199,
199,
646,
747,
12,
984,
199,
199,
646,
1455,
199,
646,
3330,
1246,
465,
3330,
199,
504,
3778,
492,
769,
362,
12,
1109,
362,
199,
504,
1851,
492,
1686,
2697,
12,
1139,
9897,
80,
199,
646,
1455,
1000,
1362,
199,
318,
1255,
30076,
8,
1532,
12,
5552,
7782,
5967,
297,
29855,
2298,
272,
408,
16291,
282,
9279,
805,
465,
282,
22613,
21337,
1654,
1041,
272,
492,
2717,
384,
14,
1000,
14,
30076,
465,
2717,
15203,
272,
372,
2717,
15203,
14,
55,
28732,
8,
1532,
12,
3663,
7887,
29,
549,
12,
5398,
1476,
29,
2697,
12,
3105,
29,
797,
680,
1065,
342,
199,
199,
318,
1255,
551,
6153,
8,
1532,
12,
5552,
7782,
5967,
297,
31092,
2298,
272,
408,
16291,
282,
9279,
805,
465,
376,
428,
21337,
1654,
1041,
272,
492,
2717,
384,
14,
1000,
14,
551,
6153,
465,
2717,
15203,
272,
372,
2717,
15203,
14,
55,
28732,
8,
1532,
12,
5398,
1476,
29,
2697,
12,
3105,
29,
797,
680,
1065,
342,
199,
199,
318,
1255,
6508,
8,
1532,
304,
272,
408,
272,
23773,
282,
9279,
13,
6490,
658,
1532,
64,
1808,
481,
21337,
12,
428,
21337,
12,
503,
282,
3486,
3330,
1654,
12,
272,
465,
5827,
4079,
641,
1067,
436,
658,
1274,
14,
3020,
2313,
272,
408,
2286,
340,
747,
14,
2314,
14,
1989,
63,
498,
360,
6613,
63,
26734,
735,
327,
16004,
267,
747,
14,
2314,
459,
38,
21337,
63,
27240,
63,
21337,
418,
275,
283,
57,
7,
339,
340,
334,
736,
14,
2314,
14,
1989,
63,
498,
360,
31300,
63,
38,
21337,
63,
1244,
1193,
4564,
742,
358,
327,
4040,
683,
68,
7377,
13814,
489,
503,
747,
14,
2314,
14,
1989,
63,
498,
360,
6613,
63,
26734,
8109,
267,
372,
1255,
30076,
8,
1532,
12,
488,
9,
2286,
340,
283,
30076,
7,
315,
984,
14,
3020,
503,
283,
7015,
13814,
7,
315,
984,
14,
3020,
26,
267,
1249,
275,
984,
14,
3020,
59,
17,
2938,
267,
340,
283,
7015,
13814,
7,
315,
1249,
26,
1249,
14,
2168,
360,
7015,
13814,
358,
267,
916,
283,
30076,
7,
315,
1249,
26,
1249,
14,
2168,
360,
30076,
358,
267,
340,
1249,
26,
288,
372,
1255,
30076,
8,
1532,
12,
1686,
2697,
8,
589,
59,
16,
2459,
267,
587,
26,
288,
372,
1255,
30076,
8,
1532,
12,
488,
9,
2286,
340,
283,
551,
6153,
7,
315,
984,
14,
3020,
26,
267,
1249,
275,
984,
14,
3020,
59,
17,
2938,
267,
1249,
14,
2168,
360,
551,
6153,
358,
267,
340,
1249,
26,
288,
372,
1255,
551,
6153,
8,
1532,
12,
1686,
2697,
8,
589,
59,
16,
2459,
267,
587,
26,
288,
372,
1255,
551,
6153,
8,
1532,
9,
17635,
1654,
63,
2697,
275,
1139,
9897,
80,
8,
513,
362,
8,
1274,
14,
3020,
12,
413,
12,
12381,
272,
340,
747,
14,
2314,
14,
1989,
63,
498,
360,
3657,
735,
327,
325,
14,
71,
14,
18769,
745,
85,
267,
1654,
63,
2697,
275,
661,
16,
14,
16,
14,
16,
14,
16,
297,
1109,
362,
8,
736,
14,
2314,
459,
3657,
5156,
2286,
372,
1455,
1000,
14,
1065,
4129,
8,
1532,
12,
1654,
63,
2697,
9,
1362,
199,
318,
485,
374,
63,
2374,
63,
632,
837,
272,
327,
6601,
12169,
2366,
6421,
878,
7859,
1133,
1172,
984,
14,
285,
86,
272,
327,
2104,
2436,
12,
1937,
4178,
921,
5031,
14,
957,
15,
2520,
647,
15,
2520,
647,
15,
10115,
15,
1555,
272,
9238,
275,
2519,
8,
1274,
12,
298,
3020,
401,
3073,
339,
327,
12530,
11176,
370,
1104,
340,
314,
2240,
365,
3879,
315,
4866,
818,
14,
272,
340,
747,
14,
2314,
14,
1989,
63,
498,
360,
6613,
63,
26734,
358,
971,
267,
503,
747,
14,
2314,
14,
1989,
63,
498,
360,
31300,
63,
38,
21337,
63,
1244,
1193,
4564,
742,
358,
971,
267,
503,
283,
30076,
7,
315,
9238,
503,
283,
7015,
13814,
7,
315,
9238,
971,
267,
503,
283,
1494,
63,
6508,
7,
315,
9238,
26,
288,
372,
756,
272,
372,
715,
199,
199,
3,
3979,
3879,
314,
6762,
13,
1000,
12,
4756,
3105,
818,
340,
440,
2575,
663,
14,
199,
2520,
14,
888,
14,
5486,
360,
1757,
297,
485,
374,
63,
2374,
63,
632,
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
] |
[
199,
16828,
738,
17933,
199,
8,
504,
3330,
14,
647,
9,
199,
624,
199,
199,
646,
747,
12,
984,
199,
199,
646,
1455,
199,
646,
3330,
1246,
465,
3330,
199,
504,
3778,
492,
769,
362,
12,
1109,
362,
199,
504,
1851,
492,
1686,
2697,
12,
1139,
9897,
80,
199,
646,
1455,
1000,
1362,
199,
318,
1255,
30076,
8,
1532,
12,
5552,
7782,
5967,
297,
29855,
2298,
272,
408,
16291,
282,
9279,
805,
465,
282,
22613,
21337,
1654,
1041,
272,
492,
2717,
384,
14,
1000,
14,
30076,
465,
2717,
15203,
272,
372,
2717,
15203,
14,
55,
28732,
8,
1532,
12,
3663,
7887,
29,
549,
12,
5398,
1476,
29,
2697,
12,
3105,
29,
797,
680,
1065,
342,
199,
199,
318,
1255,
551,
6153,
8,
1532,
12,
5552,
7782,
5967,
297,
31092,
2298,
272,
408,
16291,
282,
9279,
805,
465,
376,
428,
21337,
1654,
1041,
272,
492,
2717,
384,
14,
1000,
14,
551,
6153,
465,
2717,
15203,
272,
372,
2717,
15203,
14,
55,
28732,
8,
1532,
12,
5398,
1476,
29,
2697,
12,
3105,
29,
797,
680,
1065,
342,
199,
199,
318,
1255,
6508,
8,
1532,
304,
272,
408,
272,
23773,
282,
9279,
13,
6490,
658,
1532,
64,
1808,
481,
21337,
12,
428,
21337,
12,
503,
282,
3486,
3330,
1654,
12,
272,
465,
5827,
4079,
641,
1067,
436,
658,
1274,
14,
3020,
2313,
272,
408,
2286,
340,
747,
14,
2314,
14,
1989,
63,
498,
360,
6613,
63,
26734,
735,
327,
16004,
267,
747,
14,
2314,
459,
38,
21337,
63,
27240,
63,
21337,
418,
275,
283,
57,
7,
339,
340,
334,
736,
14,
2314,
14,
1989,
63,
498,
360,
31300,
63,
38,
21337,
63,
1244,
1193,
4564,
742,
358,
327,
4040,
683,
68,
7377,
13814,
489,
503,
747,
14,
2314,
14,
1989,
63,
498,
360,
6613,
63,
26734,
8109,
267,
372,
1255,
30076,
8,
1532,
12,
488,
9,
2286,
340,
283,
30076,
7,
315,
984,
14,
3020,
503,
283,
7015,
13814,
7,
315,
984,
14,
3020,
26,
267,
1249,
275,
984,
14,
3020,
59,
17,
2938,
267,
340,
283,
7015,
13814,
7,
315,
1249,
26,
1249,
14,
2168,
360,
7015,
13814,
358,
267,
916,
283,
30076,
7,
315,
1249,
26,
1249,
14,
2168,
360,
30076,
358,
267,
340,
1249,
26,
288,
372,
1255,
30076,
8,
1532,
12,
1686,
2697,
8,
589,
59,
16,
2459,
267,
587,
26,
288,
372,
1255,
30076,
8,
1532,
12,
488,
9,
2286,
340,
283,
551,
6153,
7,
315,
984,
14,
3020,
26,
267,
1249,
275,
984,
14,
3020,
59,
17,
2938,
267,
1249,
14,
2168,
360,
551,
6153,
358,
267,
340,
1249,
26,
288,
372,
1255,
551,
6153,
8,
1532,
12,
1686,
2697,
8,
589,
59,
16,
2459,
267,
587,
26,
288,
372,
1255,
551,
6153,
8,
1532,
9,
17635,
1654,
63,
2697,
275,
1139,
9897,
80,
8,
513,
362,
8,
1274,
14,
3020,
12,
413,
12,
12381,
272,
340,
747,
14,
2314,
14,
1989,
63,
498,
360,
3657,
735,
327,
325,
14,
71,
14,
18769,
745,
85,
267,
1654,
63,
2697,
275,
661,
16,
14,
16,
14,
16,
14,
16,
297,
1109,
362,
8,
736,
14,
2314,
459,
3657,
5156,
2286,
372,
1455,
1000,
14,
1065,
4129,
8,
1532,
12,
1654,
63,
2697,
9,
1362,
199,
318,
485,
374,
63,
2374,
63,
632,
837,
272,
327,
6601,
12169,
2366,
6421,
878,
7859,
1133,
1172,
984,
14,
285,
86,
272,
327,
2104,
2436,
12,
1937,
4178,
921,
5031,
14,
957,
15,
2520,
647,
15,
2520,
647,
15,
10115,
15,
1555,
272,
9238,
275,
2519,
8,
1274,
12,
298,
3020,
401,
3073,
339,
327,
12530,
11176,
370,
1104,
340,
314,
2240,
365,
3879,
315,
4866,
818,
14,
272,
340,
747,
14,
2314,
14,
1989,
63,
498,
360,
6613,
63,
26734,
358,
971,
267,
503,
747,
14,
2314,
14,
1989,
63,
498,
360,
31300,
63,
38,
21337,
63,
1244,
1193,
4564,
742,
358,
971,
267,
503,
283,
30076,
7,
315,
9238,
503,
283,
7015,
13814,
7,
315,
9238,
971,
267,
503,
283,
1494,
63,
6508,
7,
315,
9238,
26,
288,
372,
756,
272,
372,
715,
199,
199,
3,
3979,
3879,
314,
6762,
13,
1000,
12,
4756,
3105,
818,
340,
440,
2575,
663,
14,
199,
2520,
14,
888,
14,
5486,
360,
1757,
297,
485,
374,
63,
2374,
63,
632,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kswiat/django
|
django/core/urlresolvers.py
|
1
|
24713
|
"""
This module converts requested URLs to callback view functions.
RegexURLResolver is the main class here. Its resolve() method takes a URL (as
a string) and returns a tuple in this format:
(view_function, function_args, function_kwargs)
"""
from __future__ import unicode_literals
import functools
from importlib import import_module
import re
from threading import local
import warnings
from django.http import Http404
from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
from django.utils.datastructures import MultiValueDict
from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.encoding import force_str, force_text, iri_to_uri
from django.utils.functional import lazy
from django.utils.http import RFC3986_SUBDELIMS, urlquote
from django.utils.module_loading import module_has_submodule
from django.utils.regex_helper import normalize
from django.utils import six, lru_cache
from django.utils.translation import get_language
# SCRIPT_NAME prefixes for each thread are stored here. If there's no entry for
# the current thread (which is the only one we ever access), it is assumed to
# be empty.
_prefixes = local()
# Overridden URLconfs for each thread are stored here.
_urlconfs = local()
class ResolverMatch(object):
def __init__(self, func, args, kwargs, url_name=None, app_name=None, namespaces=None):
self.func = func
self.args = args
self.kwargs = kwargs
self.url_name = url_name
self.app_name = app_name
if namespaces:
self.namespaces = [x for x in namespaces if x]
else:
self.namespaces = []
self.namespace = ':'.join(self.namespaces)
if not hasattr(func, '__name__'):
# A class-based view
self._func_path = '.'.join([func.__class__.__module__, func.__class__.__name__])
else:
# A function-based view
self._func_path = '.'.join([func.__module__, func.__name__])
view_path = url_name or self._func_path
self.view_name = ':'.join(self.namespaces + [view_path])
def __getitem__(self, index):
return (self.func, self.args, self.kwargs)[index]
def __repr__(self):
return "ResolverMatch(func=%s, args=%s, kwargs=%s, url_name=%s, app_name=%s, namespaces=%s)" % (
self._func_path, self.args, self.kwargs, self.url_name, self.app_name, self.namespaces)
class Resolver404(Http404):
pass
class NoReverseMatch(Exception):
pass
@lru_cache.lru_cache(maxsize=None)
def get_callable(lookup_view, can_fail=False):
"""
Return a callable corresponding to lookup_view. This function is used
by both resolve() and reverse(), so can_fail allows the caller to choose
between returning the input as is and raising an exception when the input
string can't be interpreted as an import path.
If lookup_view is already a callable, return it.
If lookup_view is a string import path that can be resolved to a callable,
import that callable and return it.
If lookup_view is some other kind of string and can_fail is True, the string
is returned as is. If can_fail is False, an exception is raised (either
ImportError or ViewDoesNotExist).
"""
if callable(lookup_view):
return lookup_view
mod_name, func_name = get_mod_func(lookup_view)
if not func_name: # No '.' in lookup_view
if can_fail:
return lookup_view
else:
raise ImportError(
"Could not import '%s'. The path must be fully qualified." %
lookup_view)
try:
mod = import_module(mod_name)
except ImportError:
if can_fail:
return lookup_view
else:
parentmod, submod = get_mod_func(mod_name)
if submod and not module_has_submodule(import_module(parentmod), submod):
raise ViewDoesNotExist(
"Could not import '%s'. Parent module %s does not exist." %
(lookup_view, mod_name))
else:
raise
else:
try:
view_func = getattr(mod, func_name)
except AttributeError:
if can_fail:
return lookup_view
else:
raise ViewDoesNotExist(
"Could not import '%s'. View does not exist in module %s." %
(lookup_view, mod_name))
else:
if not callable(view_func):
# For backwards compatibility this is raised regardless of can_fail
raise ViewDoesNotExist(
"Could not import '%s.%s'. View is not callable." %
(mod_name, func_name))
return view_func
@lru_cache.lru_cache(maxsize=None)
def get_resolver(urlconf):
if urlconf is None:
from django.conf import settings
urlconf = settings.ROOT_URLCONF
return RegexURLResolver(r'^/', urlconf)
@lru_cache.lru_cache(maxsize=None)
def get_ns_resolver(ns_pattern, resolver):
# Build a namespaced resolver for the given parent urlconf pattern.
# This makes it possible to have captured parameters in the parent
# urlconf pattern.
ns_resolver = RegexURLResolver(ns_pattern, resolver.url_patterns)
return RegexURLResolver(r'^/', [ns_resolver])
def get_mod_func(callback):
# Converts 'django.views.news.stories.story_detail' to
# ['django.views.news.stories', 'story_detail']
try:
dot = callback.rindex('.')
except ValueError:
return callback, ''
return callback[:dot], callback[dot + 1:]
class LocaleRegexProvider(object):
"""
A mixin to provide a default regex property which can vary by active
language.
"""
def __init__(self, regex):
# regex is either a string representing a regular expression, or a
# translatable string (using ugettext_lazy) representing a regular
# expression.
self._regex = regex
self._regex_dict = {}
@property
def regex(self):
"""
Returns a compiled regular expression, depending upon the activated
language-code.
"""
language_code = get_language()
if language_code not in self._regex_dict:
if isinstance(self._regex, six.string_types):
regex = self._regex
else:
regex = force_text(self._regex)
try:
compiled_regex = re.compile(regex, re.UNICODE)
except re.error as e:
raise ImproperlyConfigured(
'"%s" is not a valid regular expression: %s' %
(regex, six.text_type(e)))
self._regex_dict[language_code] = compiled_regex
return self._regex_dict[language_code]
class RegexURLPattern(LocaleRegexProvider):
def __init__(self, regex, callback, default_args=None, name=None):
LocaleRegexProvider.__init__(self, regex)
# callback is either a string like 'foo.views.news.stories.story_detail'
# which represents the path to a module and a view function name, or a
# callable object (view).
if callable(callback):
self._callback = callback
else:
self._callback = None
self._callback_str = callback
self.default_args = default_args or {}
self.name = name
def __repr__(self):
return force_str('<%s %s %s>' % (self.__class__.__name__, self.name, self.regex.pattern))
def add_prefix(self, prefix):
"""
Adds the prefix string to a string-based callback.
"""
if not prefix or not hasattr(self, '_callback_str'):
return
self._callback_str = prefix + '.' + self._callback_str
def resolve(self, path):
match = self.regex.search(path)
if match:
# If there are any named groups, use those as kwargs, ignoring
# non-named groups. Otherwise, pass all non-named arguments as
# positional arguments.
kwargs = match.groupdict()
if kwargs:
args = ()
else:
args = match.groups()
# In both cases, pass any extra_kwargs as **kwargs.
kwargs.update(self.default_args)
return ResolverMatch(self.callback, args, kwargs, self.name)
@property
def callback(self):
if self._callback is not None:
return self._callback
self._callback = get_callable(self._callback_str)
return self._callback
class RegexURLResolver(LocaleRegexProvider):
def __init__(self, regex, urlconf_name, default_kwargs=None, app_name=None, namespace=None):
LocaleRegexProvider.__init__(self, regex)
# urlconf_name is a string representing the module containing URLconfs.
self.urlconf_name = urlconf_name
if not isinstance(urlconf_name, six.string_types):
self._urlconf_module = self.urlconf_name
self.callback = None
self.default_kwargs = default_kwargs or {}
self.namespace = namespace
self.app_name = app_name
self._reverse_dict = {}
self._namespace_dict = {}
self._app_dict = {}
# set of dotted paths to all functions and classes that are used in
# urlpatterns
self._callback_strs = set()
self._populated = False
def __repr__(self):
if isinstance(self.urlconf_name, list) and len(self.urlconf_name):
# Don't bother to output the whole list, it can be huge
urlconf_repr = '<%s list>' % self.urlconf_name[0].__class__.__name__
else:
urlconf_repr = repr(self.urlconf_name)
return str('<%s %s (%s:%s) %s>') % (
self.__class__.__name__, urlconf_repr, self.app_name,
self.namespace, self.regex.pattern)
def _populate(self):
lookups = MultiValueDict()
namespaces = {}
apps = {}
language_code = get_language()
for pattern in reversed(self.url_patterns):
if hasattr(pattern, '_callback_str'):
self._callback_strs.add(pattern._callback_str)
elif hasattr(pattern, '_callback'):
callback = pattern._callback
if isinstance(callback, functools.partial):
callback = callback.func
if not hasattr(callback, '__name__'):
lookup_str = callback.__module__ + "." + callback.__class__.__name__
else:
lookup_str = callback.__module__ + "." + callback.__name__
self._callback_strs.add(lookup_str)
p_pattern = pattern.regex.pattern
if p_pattern.startswith('^'):
p_pattern = p_pattern[1:]
if isinstance(pattern, RegexURLResolver):
if pattern.namespace:
namespaces[pattern.namespace] = (p_pattern, pattern)
if pattern.app_name:
apps.setdefault(pattern.app_name, []).append(pattern.namespace)
else:
parent_pat = pattern.regex.pattern
for name in pattern.reverse_dict:
for matches, pat, defaults in pattern.reverse_dict.getlist(name):
new_matches = normalize(parent_pat + pat)
lookups.appendlist(
name,
(
new_matches,
p_pattern + pat,
dict(defaults, **pattern.default_kwargs),
)
)
for namespace, (prefix, sub_pattern) in pattern.namespace_dict.items():
namespaces[namespace] = (p_pattern + prefix, sub_pattern)
for app_name, namespace_list in pattern.app_dict.items():
apps.setdefault(app_name, []).extend(namespace_list)
self._callback_strs.update(pattern._callback_strs)
else:
bits = normalize(p_pattern)
lookups.appendlist(pattern.callback, (bits, p_pattern, pattern.default_args))
if pattern.name is not None:
lookups.appendlist(pattern.name, (bits, p_pattern, pattern.default_args))
self._reverse_dict[language_code] = lookups
self._namespace_dict[language_code] = namespaces
self._app_dict[language_code] = apps
self._populated = True
@property
def reverse_dict(self):
language_code = get_language()
if language_code not in self._reverse_dict:
self._populate()
return self._reverse_dict[language_code]
@property
def namespace_dict(self):
language_code = get_language()
if language_code not in self._namespace_dict:
self._populate()
return self._namespace_dict[language_code]
@property
def app_dict(self):
language_code = get_language()
if language_code not in self._app_dict:
self._populate()
return self._app_dict[language_code]
def _is_callback(self, name):
if not self._populated:
self._populate()
return name in self._callback_strs
def resolve(self, path):
path = force_text(path) # path may be a reverse_lazy object
tried = []
match = self.regex.search(path)
if match:
new_path = path[match.end():]
for pattern in self.url_patterns:
try:
sub_match = pattern.resolve(new_path)
except Resolver404 as e:
sub_tried = e.args[0].get('tried')
if sub_tried is not None:
tried.extend([pattern] + t for t in sub_tried)
else:
tried.append([pattern])
else:
if sub_match:
sub_match_dict = dict(match.groupdict(), **self.default_kwargs)
sub_match_dict.update(sub_match.kwargs)
return ResolverMatch(
sub_match.func,
sub_match.args,
sub_match_dict,
sub_match.url_name,
self.app_name or sub_match.app_name,
[self.namespace] + sub_match.namespaces
)
tried.append([pattern])
raise Resolver404({'tried': tried, 'path': new_path})
raise Resolver404({'path': path})
@property
def urlconf_module(self):
try:
return self._urlconf_module
except AttributeError:
self._urlconf_module = import_module(self.urlconf_name)
return self._urlconf_module
@property
def url_patterns(self):
# urlconf_module might be a valid set of patterns, so we default to it
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
try:
iter(patterns)
except TypeError:
msg = (
"The included urlconf '{name}' does not appear to have any "
"patterns in it. If you see valid patterns in the file then "
"the issue is probably caused by a circular import."
)
raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
return patterns
def resolve_error_handler(self, view_type):
callback = getattr(self.urlconf_module, 'handler%s' % view_type, None)
if not callback:
# No handler specified in file; use default
# Lazy import, since django.urls imports this file
from django.conf import urls
callback = getattr(urls, 'handler%s' % view_type)
return get_callable(callback), {}
def reverse(self, lookup_view, *args, **kwargs):
return self._reverse_with_prefix(lookup_view, '', *args, **kwargs)
def _reverse_with_prefix(self, lookup_view, _prefix, *args, **kwargs):
if args and kwargs:
raise ValueError("Don't mix *args and **kwargs in call to reverse()!")
text_args = [force_text(v) for v in args]
text_kwargs = dict((k, force_text(v)) for (k, v) in kwargs.items())
if not self._populated:
self._populate()
original_lookup = lookup_view
try:
if self._is_callback(lookup_view):
lookup_view = get_callable(lookup_view, True)
except (ImportError, AttributeError) as e:
raise NoReverseMatch("Error importing '%s': %s." % (lookup_view, e))
else:
if not callable(original_lookup) and callable(lookup_view):
warnings.warn(
'Reversing by dotted path is deprecated (%s).' % original_lookup,
RemovedInDjango20Warning, stacklevel=3
)
possibilities = self.reverse_dict.getlist(lookup_view)
prefix_norm, prefix_args = normalize(urlquote(_prefix))[0]
for possibility, pattern, defaults in possibilities:
for result, params in possibility:
if args:
if len(args) != len(params) + len(prefix_args):
continue
candidate_subs = dict(zip(prefix_args + params, text_args))
else:
if (set(kwargs.keys()) | set(defaults.keys()) != set(params) |
set(defaults.keys()) | set(prefix_args)):
continue
matches = True
for k, v in defaults.items():
if kwargs.get(k, v) != v:
matches = False
break
if not matches:
continue
candidate_subs = text_kwargs
# WSGI provides decoded URLs, without %xx escapes, and the URL
# resolver operates on such URLs. First substitute arguments
# without quoting to build a decoded URL and look for a match.
# Then, if we have a match, redo the substitution with quoted
# arguments in order to return a properly encoded URL.
candidate_pat = prefix_norm.replace('%', '%%') + result
if re.search('^%s%s' % (prefix_norm, pattern), candidate_pat % candidate_subs, re.UNICODE):
# safe characters from `pchar` definition of RFC 3986
candidate_subs = dict((k, urlquote(v, safe=RFC3986_SUBDELIMS + str('/~:@')))
for (k, v) in candidate_subs.items())
url = candidate_pat % candidate_subs
# Don't allow construction of scheme relative urls.
if url.startswith('//'):
url = '/%%2F%s' % url[2:]
return url
# lookup_view can be URL label, or dotted path, or callable, Any of
# these can be passed in at the top, but callables are not friendly in
# error messages.
m = getattr(lookup_view, '__module__', None)
n = getattr(lookup_view, '__name__', None)
if m is not None and n is not None:
lookup_view_s = "%s.%s" % (m, n)
else:
lookup_view_s = lookup_view
patterns = [pattern for (possibility, pattern, defaults) in possibilities]
raise NoReverseMatch("Reverse for '%s' with arguments '%s' and keyword "
"arguments '%s' not found. %d pattern(s) tried: %s" %
(lookup_view_s, args, kwargs, len(patterns), patterns))
class LocaleRegexURLResolver(RegexURLResolver):
"""
A URL resolver that always matches the active language code as URL prefix.
Rather than taking a regex argument, we just override the ``regex``
function to always return the active language-code as regex.
"""
def __init__(self, urlconf_name, default_kwargs=None, app_name=None, namespace=None):
super(LocaleRegexURLResolver, self).__init__(
None, urlconf_name, default_kwargs, app_name, namespace)
@property
def regex(self):
language_code = get_language()
if language_code not in self._regex_dict:
regex_compiled = re.compile('^%s/' % language_code, re.UNICODE)
self._regex_dict[language_code] = regex_compiled
return self._regex_dict[language_code]
def resolve(path, urlconf=None):
if urlconf is None:
urlconf = get_urlconf()
return get_resolver(urlconf).resolve(path)
def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None, current_app=None):
if urlconf is None:
urlconf = get_urlconf()
resolver = get_resolver(urlconf)
args = args or []
kwargs = kwargs or {}
if prefix is None:
prefix = get_script_prefix()
if not isinstance(viewname, six.string_types):
view = viewname
else:
parts = viewname.split(':')
parts.reverse()
view = parts[0]
path = parts[1:]
resolved_path = []
ns_pattern = ''
while path:
ns = path.pop()
# Lookup the name to see if it could be an app identifier
try:
app_list = resolver.app_dict[ns]
# Yes! Path part matches an app in the current Resolver
if current_app and current_app in app_list:
# If we are reversing for a particular app,
# use that namespace
ns = current_app
elif ns not in app_list:
# The name isn't shared by one of the instances
# (i.e., the default) so just pick the first instance
# as the default.
ns = app_list[0]
except KeyError:
pass
try:
extra, resolver = resolver.namespace_dict[ns]
resolved_path.append(ns)
ns_pattern = ns_pattern + extra
except KeyError as key:
if resolved_path:
raise NoReverseMatch(
"%s is not a registered namespace inside '%s'" %
(key, ':'.join(resolved_path)))
else:
raise NoReverseMatch("%s is not a registered namespace" %
key)
if ns_pattern:
resolver = get_ns_resolver(ns_pattern, resolver)
return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
reverse_lazy = lazy(reverse, str)
def clear_url_caches():
get_callable.cache_clear()
get_resolver.cache_clear()
get_ns_resolver.cache_clear()
def set_script_prefix(prefix):
"""
Sets the script prefix for the current thread.
"""
if not prefix.endswith('/'):
prefix += '/'
_prefixes.value = prefix
def get_script_prefix():
"""
Returns the currently active script prefix. Useful for client code that
wishes to construct their own URLs manually (although accessing the request
instance is normally going to be a lot cleaner).
"""
return getattr(_prefixes, "value", '/')
def clear_script_prefix():
"""
Unsets the script prefix for the current thread.
"""
try:
del _prefixes.value
except AttributeError:
pass
def set_urlconf(urlconf_name):
"""
Sets the URLconf for the current thread (overriding the default one in
settings). Set to None to revert back to the default.
"""
if urlconf_name:
_urlconfs.value = urlconf_name
else:
if hasattr(_urlconfs, "value"):
del _urlconfs.value
def get_urlconf(default=None):
"""
Returns the root URLconf to use for the current thread if it has been
changed from the default one.
"""
return getattr(_urlconfs, "value", default)
def is_valid_path(path, urlconf=None):
"""
Returns True if the given path resolves against the default URL resolver,
False otherwise.
This is a convenience method to make working with "is this a match?" cases
easier, avoiding unnecessarily indented try...except blocks.
"""
try:
resolve(path, urlconf)
return True
except Resolver404:
return False
|
bsd-3-clause
|
[
624,
199,
2765,
859,
15373,
5839,
10867,
370,
3233,
2455,
3423,
14,
199,
199,
5103,
2632,
12407,
365,
314,
2446,
1021,
2348,
14,
22940,
7512,
342,
1083,
6181,
282,
2851,
334,
305,
199,
65,
1059,
9,
436,
2529,
282,
2008,
315,
642,
1475,
26,
339,
334,
1345,
63,
1593,
12,
805,
63,
589,
12,
805,
63,
958,
9,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
9143,
199,
504,
14802,
492,
492,
63,
578,
199,
646,
295,
199,
504,
5796,
492,
2257,
199,
646,
3598,
199,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
12,
10935,
7400,
199,
504,
1639,
14,
1208,
14,
23004,
492,
6879,
24811,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
1165,
3849,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
495,
12,
3542,
63,
505,
12,
24086,
63,
475,
63,
2302,
199,
504,
1639,
14,
1208,
14,
15481,
492,
9617,
199,
504,
1639,
14,
1208,
14,
1014,
492,
7329,
29451,
63,
6348,
4424,
1469,
51,
12,
1166,
3513,
199,
504,
1639,
14,
1208,
14,
578,
63,
8786,
492,
859,
63,
1989,
63,
16229,
199,
504,
1639,
14,
1208,
14,
3821,
63,
3676,
492,
7666,
199,
504,
1639,
14,
1208,
492,
3816,
12,
634,
6558,
63,
1637,
199,
504,
1639,
14,
1208,
14,
6893,
492,
664,
63,
3671,
421,
199,
3,
30203,
63,
2339,
13158,
367,
1924,
2462,
787,
5489,
2348,
14,
982,
2337,
1159,
949,
2397,
367,
199,
3,
314,
1453,
2462,
334,
6777,
365,
314,
1454,
1373,
781,
14433,
2879,
395,
652,
365,
10826,
370,
199,
3,
506,
2701,
14,
199,
63,
14124,
275,
2257,
342,
199,
199,
3,
7259,
8639,
2851,
2190,
83,
367,
1924,
2462,
787,
5489,
2348,
14,
199,
63,
21801,
83,
275,
2257,
342,
421,
199,
533,
26046,
4486,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
2562,
12,
1249,
12,
2074,
12,
1166,
63,
354,
29,
403,
12,
1145,
63,
354,
29,
403,
12,
10747,
29,
403,
304,
267,
291,
14,
1532,
275,
2562,
267,
291,
14,
589,
275,
1249,
267,
291,
14,
958,
275,
2074,
267,
291,
14,
633,
63,
354,
275,
1166,
63,
354,
267,
291,
14,
571,
63,
354,
275,
1145,
63,
354,
398,
340,
10747,
26,
288,
291,
14,
9247,
275,
359,
88,
367,
671,
315,
10747,
340,
671,
61,
267,
587,
26,
288,
291,
14,
9247,
275,
942,
267,
291,
14,
3251,
275,
29010,
904,
8,
277,
14,
9247,
9,
398,
340,
440,
2688,
8,
1532,
12,
2560,
354,
12168,
288,
327,
437,
1021,
13,
6788,
2455,
288,
291,
423,
1532,
63,
515,
275,
15671,
904,
779,
1532,
855,
533,
4914,
578,
3108,
2562,
855,
533,
4914,
354,
363,
566,
267,
587,
26,
288,
327,
437,
805,
13,
6788,
2455,
288,
291,
423,
1532,
63,
515,
275,
15671,
904,
779,
1532,
855,
578,
3108,
2562,
855,
354,
363,
566,
398,
2455,
63,
515,
275,
1166,
63,
354,
503,
291,
423,
1532,
63,
515,
267,
291,
14,
1345,
63,
354,
275,
29010,
904,
8,
277,
14,
9247,
435,
359,
1345,
63,
515,
566,
339,
347,
636,
6095,
721,
277,
12,
1478,
304,
267,
372,
334,
277,
14,
1532,
12,
291,
14,
589,
12,
291,
14,
958,
2788,
1080,
61,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
298,
12407,
4486,
8,
1532,
2458,
83,
12,
1249,
2458,
83,
12,
2074,
2458,
83,
12,
1166,
63,
354,
2458,
83,
12,
1145,
63,
354,
2458,
83,
12,
10747,
2458,
83,
2924,
450,
334,
288,
291,
423,
1532,
63,
515,
12,
291,
14,
589,
12,
291,
14,
958,
12,
291,
14,
633,
63,
354,
12,
291,
14,
571,
63,
354,
12,
291,
14,
9247,
9,
421,
199,
533,
26046,
5188,
8,
5779,
5188,
304,
272,
986,
421,
199,
533,
32036,
8,
1726,
304,
272,
986,
421,
199,
32,
25003,
63,
1637,
14,
25003,
63,
1637,
8,
13634,
29,
403,
9,
199,
318,
664,
63,
8296,
8,
3892,
63,
1345,
12,
883,
63,
1633,
29,
797,
304,
272,
408,
272,
1432,
282,
4550,
5226,
370,
4237,
63,
1345,
14,
961,
805,
365,
1202,
272,
701,
3865,
7512,
342,
436,
3837,
1062,
880,
883,
63,
1633,
6127,
314,
8025,
370,
11496,
272,
3382,
8152,
314,
1324,
465,
365,
436,
17026,
376,
1919,
1380,
314,
1324,
272,
1059,
883,
1133,
506,
11922,
465,
376,
492,
931,
14,
339,
982,
4237,
63,
1345,
365,
2575,
282,
4550,
12,
372,
652,
14,
272,
982,
4237,
63,
1345,
365,
282,
1059,
492,
931,
626,
883,
506,
12152,
370,
282,
4550,
12,
489,
492,
626,
4550,
436,
372,
652,
14,
272,
982,
4237,
63,
1345,
365,
2005,
1163,
4928,
402,
1059,
436,
883,
63,
1633,
365,
715,
12,
314,
1059,
489,
365,
2138,
465,
365,
14,
982,
883,
63,
1633,
365,
756,
12,
376,
1919,
365,
4915,
334,
22051,
489,
3545,
503,
10935,
7400,
680,
272,
408,
272,
340,
4550,
8,
3892,
63,
1345,
304,
267,
372,
4237,
63,
1345,
339,
3413,
63,
354,
12,
2562,
63,
354,
275,
664,
63,
1494,
63,
1532,
8,
3892,
63,
1345,
9,
272,
340,
440,
2562,
63,
354,
26,
221,
327,
3091,
7815,
315,
4237,
63,
1345,
267,
340,
883,
63,
1633,
26,
288,
372,
4237,
63,
1345,
267,
587,
26,
288,
746,
3545,
8,
355,
298,
6531,
440,
492,
1543,
83,
1370,
710,
931,
1471,
506,
9999,
12313,
2122,
450,
355,
4237,
63,
1345,
9,
339,
862,
26,
267,
3413,
275,
492,
63,
578,
8,
1494,
63,
354,
9,
272,
871,
3545,
26,
267,
340,
883,
63,
1633,
26,
288,
372,
4237,
63,
1345,
267,
587,
26,
288,
1676,
1494,
12,
1007,
1494,
275,
664,
63,
1494,
63,
1532,
8,
1494,
63,
354,
9,
288,
340,
1007,
1494,
436,
440,
859,
63,
1989,
63,
16229,
8,
646,
63,
578,
8,
1708,
1494,
395,
1007,
1494,
304,
355,
746,
10935,
7400,
8,
490,
298,
6531,
440,
492,
1543,
83,
1370,
16396,
859,
450,
83,
1630,
440,
2187,
2122,
450,
490,
334,
3892,
63,
1345,
12,
3413,
63,
354,
430,
288,
587,
26,
355,
746,
272,
587,
26,
267,
862,
26,
288,
2455,
63,
1532,
275,
2519,
8,
1494,
12,
2562,
63
] |
[
199,
2765,
859,
15373,
5839,
10867,
370,
3233,
2455,
3423,
14,
199,
199,
5103,
2632,
12407,
365,
314,
2446,
1021,
2348,
14,
22940,
7512,
342,
1083,
6181,
282,
2851,
334,
305,
199,
65,
1059,
9,
436,
2529,
282,
2008,
315,
642,
1475,
26,
339,
334,
1345,
63,
1593,
12,
805,
63,
589,
12,
805,
63,
958,
9,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
9143,
199,
504,
14802,
492,
492,
63,
578,
199,
646,
295,
199,
504,
5796,
492,
2257,
199,
646,
3598,
199,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
12,
10935,
7400,
199,
504,
1639,
14,
1208,
14,
23004,
492,
6879,
24811,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
1165,
3849,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
495,
12,
3542,
63,
505,
12,
24086,
63,
475,
63,
2302,
199,
504,
1639,
14,
1208,
14,
15481,
492,
9617,
199,
504,
1639,
14,
1208,
14,
1014,
492,
7329,
29451,
63,
6348,
4424,
1469,
51,
12,
1166,
3513,
199,
504,
1639,
14,
1208,
14,
578,
63,
8786,
492,
859,
63,
1989,
63,
16229,
199,
504,
1639,
14,
1208,
14,
3821,
63,
3676,
492,
7666,
199,
504,
1639,
14,
1208,
492,
3816,
12,
634,
6558,
63,
1637,
199,
504,
1639,
14,
1208,
14,
6893,
492,
664,
63,
3671,
421,
199,
3,
30203,
63,
2339,
13158,
367,
1924,
2462,
787,
5489,
2348,
14,
982,
2337,
1159,
949,
2397,
367,
199,
3,
314,
1453,
2462,
334,
6777,
365,
314,
1454,
1373,
781,
14433,
2879,
395,
652,
365,
10826,
370,
199,
3,
506,
2701,
14,
199,
63,
14124,
275,
2257,
342,
199,
199,
3,
7259,
8639,
2851,
2190,
83,
367,
1924,
2462,
787,
5489,
2348,
14,
199,
63,
21801,
83,
275,
2257,
342,
421,
199,
533,
26046,
4486,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
2562,
12,
1249,
12,
2074,
12,
1166,
63,
354,
29,
403,
12,
1145,
63,
354,
29,
403,
12,
10747,
29,
403,
304,
267,
291,
14,
1532,
275,
2562,
267,
291,
14,
589,
275,
1249,
267,
291,
14,
958,
275,
2074,
267,
291,
14,
633,
63,
354,
275,
1166,
63,
354,
267,
291,
14,
571,
63,
354,
275,
1145,
63,
354,
398,
340,
10747,
26,
288,
291,
14,
9247,
275,
359,
88,
367,
671,
315,
10747,
340,
671,
61,
267,
587,
26,
288,
291,
14,
9247,
275,
942,
267,
291,
14,
3251,
275,
29010,
904,
8,
277,
14,
9247,
9,
398,
340,
440,
2688,
8,
1532,
12,
2560,
354,
12168,
288,
327,
437,
1021,
13,
6788,
2455,
288,
291,
423,
1532,
63,
515,
275,
15671,
904,
779,
1532,
855,
533,
4914,
578,
3108,
2562,
855,
533,
4914,
354,
363,
566,
267,
587,
26,
288,
327,
437,
805,
13,
6788,
2455,
288,
291,
423,
1532,
63,
515,
275,
15671,
904,
779,
1532,
855,
578,
3108,
2562,
855,
354,
363,
566,
398,
2455,
63,
515,
275,
1166,
63,
354,
503,
291,
423,
1532,
63,
515,
267,
291,
14,
1345,
63,
354,
275,
29010,
904,
8,
277,
14,
9247,
435,
359,
1345,
63,
515,
566,
339,
347,
636,
6095,
721,
277,
12,
1478,
304,
267,
372,
334,
277,
14,
1532,
12,
291,
14,
589,
12,
291,
14,
958,
2788,
1080,
61,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
298,
12407,
4486,
8,
1532,
2458,
83,
12,
1249,
2458,
83,
12,
2074,
2458,
83,
12,
1166,
63,
354,
2458,
83,
12,
1145,
63,
354,
2458,
83,
12,
10747,
2458,
83,
2924,
450,
334,
288,
291,
423,
1532,
63,
515,
12,
291,
14,
589,
12,
291,
14,
958,
12,
291,
14,
633,
63,
354,
12,
291,
14,
571,
63,
354,
12,
291,
14,
9247,
9,
421,
199,
533,
26046,
5188,
8,
5779,
5188,
304,
272,
986,
421,
199,
533,
32036,
8,
1726,
304,
272,
986,
421,
199,
32,
25003,
63,
1637,
14,
25003,
63,
1637,
8,
13634,
29,
403,
9,
199,
318,
664,
63,
8296,
8,
3892,
63,
1345,
12,
883,
63,
1633,
29,
797,
304,
272,
408,
272,
1432,
282,
4550,
5226,
370,
4237,
63,
1345,
14,
961,
805,
365,
1202,
272,
701,
3865,
7512,
342,
436,
3837,
1062,
880,
883,
63,
1633,
6127,
314,
8025,
370,
11496,
272,
3382,
8152,
314,
1324,
465,
365,
436,
17026,
376,
1919,
1380,
314,
1324,
272,
1059,
883,
1133,
506,
11922,
465,
376,
492,
931,
14,
339,
982,
4237,
63,
1345,
365,
2575,
282,
4550,
12,
372,
652,
14,
272,
982,
4237,
63,
1345,
365,
282,
1059,
492,
931,
626,
883,
506,
12152,
370,
282,
4550,
12,
489,
492,
626,
4550,
436,
372,
652,
14,
272,
982,
4237,
63,
1345,
365,
2005,
1163,
4928,
402,
1059,
436,
883,
63,
1633,
365,
715,
12,
314,
1059,
489,
365,
2138,
465,
365,
14,
982,
883,
63,
1633,
365,
756,
12,
376,
1919,
365,
4915,
334,
22051,
489,
3545,
503,
10935,
7400,
680,
272,
408,
272,
340,
4550,
8,
3892,
63,
1345,
304,
267,
372,
4237,
63,
1345,
339,
3413,
63,
354,
12,
2562,
63,
354,
275,
664,
63,
1494,
63,
1532,
8,
3892,
63,
1345,
9,
272,
340,
440,
2562,
63,
354,
26,
221,
327,
3091,
7815,
315,
4237,
63,
1345,
267,
340,
883,
63,
1633,
26,
288,
372,
4237,
63,
1345,
267,
587,
26,
288,
746,
3545,
8,
355,
298,
6531,
440,
492,
1543,
83,
1370,
710,
931,
1471,
506,
9999,
12313,
2122,
450,
355,
4237,
63,
1345,
9,
339,
862,
26,
267,
3413,
275,
492,
63,
578,
8,
1494,
63,
354,
9,
272,
871,
3545,
26,
267,
340,
883,
63,
1633,
26,
288,
372,
4237,
63,
1345,
267,
587,
26,
288,
1676,
1494,
12,
1007,
1494,
275,
664,
63,
1494,
63,
1532,
8,
1494,
63,
354,
9,
288,
340,
1007,
1494,
436,
440,
859,
63,
1989,
63,
16229,
8,
646,
63,
578,
8,
1708,
1494,
395,
1007,
1494,
304,
355,
746,
10935,
7400,
8,
490,
298,
6531,
440,
492,
1543,
83,
1370,
16396,
859,
450,
83,
1630,
440,
2187,
2122,
450,
490,
334,
3892,
63,
1345,
12,
3413,
63,
354,
430,
288,
587,
26,
355,
746,
272,
587,
26,
267,
862,
26,
288,
2455,
63,
1532,
275,
2519,
8,
1494,
12,
2562,
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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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
] |
newrocknj/horizon
|
openstack_dashboard/dashboards/admin/hypervisors/compute/tabs.py
|
57
|
1309
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import tabs
from openstack_dashboard.api import nova
from openstack_dashboard.dashboards.admin.hypervisors.compute import tables
class ComputeHostTab(tabs.TableTab):
table_classes = (tables.ComputeHostTable,)
name = _("Compute Host")
slug = "compute_host"
template_name = "horizon/common/_detail_table.html"
def get_compute_host_data(self):
try:
return nova.service_list(self.tab_group.request,
binary='nova-compute')
except Exception:
msg = _('Unable to get nova services list.')
exceptions.handle(self.tab_group.request, msg)
return []
|
apache-2.0
|
[
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
21726,
492,
4967,
199,
504,
21726,
492,
12187,
199,
199,
504,
13869,
63,
9743,
14,
1246,
492,
5913,
199,
504,
13869,
63,
9743,
14,
30424,
14,
2113,
14,
9547,
27215,
14,
3357,
492,
6716,
421,
199,
533,
8354,
4965,
7690,
8,
8741,
14,
3186,
7690,
304,
272,
1817,
63,
2888,
275,
334,
5987,
14,
8564,
4965,
3186,
4258,
272,
536,
275,
3824,
8564,
10891,
531,
272,
8889,
275,
298,
3357,
63,
1102,
2,
272,
1978,
63,
354,
275,
298,
16561,
15,
2330,
15607,
5506,
63,
1224,
14,
1360,
2,
339,
347,
664,
63,
3357,
63,
1102,
63,
576,
8,
277,
304,
267,
862,
26,
288,
372,
5913,
14,
1364,
63,
513,
8,
277,
14,
2902,
63,
923,
14,
1069,
12,
3660,
3366,
534,
6765,
13,
3357,
358,
267,
871,
2186,
26,
288,
1499,
275,
4018,
6005,
370,
664,
5913,
8500,
769,
2659,
288,
4967,
14,
2479,
8,
277,
14,
2902,
63,
923,
14,
1069,
12,
1499,
9,
288,
372,
942,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
21726,
492,
4967,
199,
504,
21726,
492,
12187,
199,
199,
504,
13869,
63,
9743,
14,
1246,
492,
5913,
199,
504,
13869,
63,
9743,
14,
30424,
14,
2113,
14,
9547,
27215,
14,
3357,
492,
6716,
421,
199,
533,
8354,
4965,
7690,
8,
8741,
14,
3186,
7690,
304,
272,
1817,
63,
2888,
275,
334,
5987,
14,
8564,
4965,
3186,
4258,
272,
536,
275,
3824,
8564,
10891,
531,
272,
8889,
275,
298,
3357,
63,
1102,
2,
272,
1978,
63,
354,
275,
298,
16561,
15,
2330,
15607,
5506,
63,
1224,
14,
1360,
2,
339,
347,
664,
63,
3357,
63,
1102,
63,
576,
8,
277,
304,
267,
862,
26,
288,
372,
5913,
14,
1364,
63,
513,
8,
277,
14,
2902,
63,
923,
14,
1069,
12,
3660,
3366,
534,
6765,
13,
3357,
358,
267,
871,
2186,
26,
288,
1499,
275,
4018,
6005,
370,
664,
5913,
8500,
769,
2659,
288,
4967,
14,
2479,
8,
277,
14,
2902,
63,
923,
14,
1069,
12,
1499,
9,
288,
372,
942,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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/big5freq.py
|
3133
|
82594
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Communicator client code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - port to Python
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
# Big5 frequency table
# by Taiwan's Mandarin Promotion Council
# <http://www.edu.tw:81/mandr/>
#
# 128 --> 0.42261
# 256 --> 0.57851
# 512 --> 0.74851
# 1024 --> 0.89384
# 2048 --> 0.97583
#
# Ideal Distribution Ratio = 0.74851/(1-0.74851) =2.98
# Random Distribution Ration = 512/(5401-512)=0.105
#
# Typical Distribution Ratio about 25% of Ideal one, still much higher than RDR
BIG5_TYPICAL_DISTRIBUTION_RATIO = 0.75
#Char to FreqOrder table
BIG5_TABLE_SIZE = 5376
Big5CharToFreqOrder = (
1,1801,1506, 255,1431, 198, 9, 82, 6,5008, 177, 202,3681,1256,2821, 110, # 16
3814, 33,3274, 261, 76, 44,2114, 16,2946,2187,1176, 659,3971, 26,3451,2653, # 32
1198,3972,3350,4202, 410,2215, 302, 590, 361,1964, 8, 204, 58,4510,5009,1932, # 48
63,5010,5011, 317,1614, 75, 222, 159,4203,2417,1480,5012,3555,3091, 224,2822, # 64
3682, 3, 10,3973,1471, 29,2787,1135,2866,1940, 873, 130,3275,1123, 312,5013, # 80
4511,2052, 507, 252, 682,5014, 142,1915, 124, 206,2947, 34,3556,3204, 64, 604, # 96
5015,2501,1977,1978, 155,1991, 645, 641,1606,5016,3452, 337, 72, 406,5017, 80, # 112
630, 238,3205,1509, 263, 939,1092,2654, 756,1440,1094,3453, 449, 69,2987, 591, # 128
179,2096, 471, 115,2035,1844, 60, 50,2988, 134, 806,1869, 734,2036,3454, 180, # 144
995,1607, 156, 537,2907, 688,5018, 319,1305, 779,2145, 514,2379, 298,4512, 359, # 160
2502, 90,2716,1338, 663, 11, 906,1099,2553, 20,2441, 182, 532,1716,5019, 732, # 176
1376,4204,1311,1420,3206, 25,2317,1056, 113, 399, 382,1950, 242,3455,2474, 529, # 192
3276, 475,1447,3683,5020, 117, 21, 656, 810,1297,2300,2334,3557,5021, 126,4205, # 208
706, 456, 150, 613,4513, 71,1118,2037,4206, 145,3092, 85, 835, 486,2115,1246, # 224
1426, 428, 727,1285,1015, 800, 106, 623, 303,1281,5022,2128,2359, 347,3815, 221, # 240
3558,3135,5023,1956,1153,4207, 83, 296,1199,3093, 192, 624, 93,5024, 822,1898, # 256
2823,3136, 795,2065, 991,1554,1542,1592, 27, 43,2867, 859, 139,1456, 860,4514, # 272
437, 712,3974, 164,2397,3137, 695, 211,3037,2097, 195,3975,1608,3559,3560,3684, # 288
3976, 234, 811,2989,2098,3977,2233,1441,3561,1615,2380, 668,2077,1638, 305, 228, # 304
1664,4515, 467, 415,5025, 262,2099,1593, 239, 108, 300, 200,1033, 512,1247,2078, # 320
5026,5027,2176,3207,3685,2682, 593, 845,1062,3277, 88,1723,2038,3978,1951, 212, # 336
266, 152, 149, 468,1899,4208,4516, 77, 187,5028,3038, 37, 5,2990,5029,3979, # 352
5030,5031, 39,2524,4517,2908,3208,2079, 55, 148, 74,4518, 545, 483,1474,1029, # 368
1665, 217,1870,1531,3138,1104,2655,4209, 24, 172,3562, 900,3980,3563,3564,4519, # 384
32,1408,2824,1312, 329, 487,2360,2251,2717, 784,2683, 4,3039,3351,1427,1789, # 400
188, 109, 499,5032,3686,1717,1790, 888,1217,3040,4520,5033,3565,5034,3352,1520, # 416
3687,3981, 196,1034, 775,5035,5036, 929,1816, 249, 439, 38,5037,1063,5038, 794, # 432
3982,1435,2301, 46, 178,3278,2066,5039,2381,5040, 214,1709,4521, 804, 35, 707, # 448
324,3688,1601,2554, 140, 459,4210,5041,5042,1365, 839, 272, 978,2262,2580,3456, # 464
2129,1363,3689,1423, 697, 100,3094, 48, 70,1231, 495,3139,2196,5043,1294,5044, # 480
2080, 462, 586,1042,3279, 853, 256, 988, 185,2382,3457,1698, 434,1084,5045,3458, # 496
314,2625,2788,4522,2335,2336, 569,2285, 637,1817,2525, 757,1162,1879,1616,3459, # 512
287,1577,2116, 768,4523,1671,2868,3566,2526,1321,3816, 909,2418,5046,4211, 933, # 528
3817,4212,2053,2361,1222,4524, 765,2419,1322, 786,4525,5047,1920,1462,1677,2909, # 544
1699,5048,4526,1424,2442,3140,3690,2600,3353,1775,1941,3460,3983,4213, 309,1369, # 560
1130,2825, 364,2234,1653,1299,3984,3567,3985,3986,2656, 525,1085,3041, 902,2001, # 576
1475, 964,4527, 421,1845,1415,1057,2286, 940,1364,3141, 376,4528,4529,1381, 7, # 592
2527, 983,2383, 336,1710,2684,1846, 321,3461, 559,1131,3042,2752,1809,1132,1313, # 608
265,1481,1858,5049, 352,1203,2826,3280, 167,1089, 420,2827, 776, 792,1724,3568, # 624
4214,2443,3281,5050,4215,5051, 446, 229, 333,2753, 901,3818,1200,1557,4530,2657, # 640
1921, 395,2754,2685,3819,4216,1836, 125, 916,3209,2626,4531,5052,5053,3820,5054, # 656
5055,5056,4532,3142,3691,1133,2555,1757,3462,1510,2318,1409,3569,5057,2146, 438, # 672
2601,2910,2384,3354,1068, 958,3043, 461, 311,2869,2686,4217,1916,3210,4218,1979, # 688
383, 750,2755,2627,4219, 274, 539, 385,1278,1442,5058,1154,1965, 384, 561, 210, # 704
98,1295,2556,3570,5059,1711,2420,1482,3463,3987,2911,1257, 129,5060,3821, 642, # 720
523,2789,2790,2658,5061, 141,2235,1333, 68, 176, 441, 876, 907,4220, 603,2602, # 736
710, 171,3464, 404, 549, 18,3143,2398,1410,3692,1666,5062,3571,4533,2912,4534, # 752
5063,2991, 368,5064, 146, 366, 99, 871,3693,1543, 748, 807,1586,1185, 22,2263, # 768
379,3822,3211,5065,3212, 505,1942,2628,1992,1382,2319,5066, 380,2362, 218, 702, # 784
1818,1248,3465,3044,3572,3355,3282,5067,2992,3694, 930,3283,3823,5068, 59,5069, # 800
585, 601,4221, 497,3466,1112,1314,4535,1802,5070,1223,1472,2177,5071, 749,1837, # 816
690,1900,3824,1773,3988,1476, 429,1043,1791,2236,2117, 917,4222, 447,1086,1629, # 832
5072, 556,5073,5074,2021,1654, 844,1090, 105, 550, 966,1758,2828,1008,1783, 686, # 848
1095,5075,2287, 793,1602,5076,3573,2603,4536,4223,2948,2302,4537,3825, 980,2503, # 864
544, 353, 527,4538, 908,2687,2913,5077, 381,2629,1943,1348,5078,1341,1252, 560, # 880
3095,5079,3467,2870,5080,2054, 973, 886,2081, 143,4539,5081,5082, 157,3989, 496, # 896
4224, 57, 840, 540,2039,4540,4541,3468,2118,1445, 970,2264,1748,1966,2082,4225, # 912
3144,1234,1776,3284,2829,3695, 773,1206,2130,1066,2040,1326,3990,1738,1725,4226, # 928
279,3145, 51,1544,2604, 423,1578,2131,2067, 173,4542,1880,5083,5084,1583, 264, # 944
610,3696,4543,2444, 280, 154,5085,5086,5087,1739, 338,1282,3096, 693,2871,1411, # 960
1074,3826,2445,5088,4544,5089,5090,1240, 952,2399,5091,2914,1538,2688, 685,1483, # 976
4227,2475,1436, 953,4228,2055,4545, 671,2400, 79,4229,2446,3285, 608, 567,2689, # 992
3469,4230,4231,1691, 393,1261,1792,2401,5092,4546,5093,5094,5095,5096,1383,1672, # 1008
3827,3213,1464, 522,1119, 661,1150, 216, 675,4547,3991,1432,3574, 609,4548,2690, # 1024
2402,5097,5098,5099,4232,3045, 0,5100,2476, 315, 231,2447, 301,3356,4549,2385, # 1040
5101, 233,4233,3697,1819,4550,4551,5102, 96,1777,1315,2083,5103, 257,5104,1810, # 1056
3698,2718,1139,1820,4234,2022,1124,2164,2791,1778,2659,5105,3097, 363,1655,3214, # 1072
5106,2993,5107,5108,5109,3992,1567,3993, 718, 103,3215, 849,1443, 341,3357,2949, # 1088
1484,5110,1712, 127, 67, 339,4235,2403, 679,1412, 821,5111,5112, 834, 738, 351, # 1104
2994,2147, 846, 235,1497,1881, 418,1993,3828,2719, 186,1100,2148,2756,3575,1545, # 1120
1355,2950,2872,1377, 583,3994,4236,2581,2995,5113,1298,3699,1078,2557,3700,2363, # 1136
78,3829,3830, 267,1289,2100,2002,1594,4237, 348, 369,1274,2197,2178,1838,4552, # 1152
1821,2830,3701,2757,2288,2003,4553,2951,2758, 144,3358, 882,4554,3995,2759,3470, # 1168
4555,2915,5114,4238,1726, 320,5115,3996,3046, 788,2996,5116,2831,1774,1327,2873, # 1184
3997,2832,5117,1306,4556,2004,1700,3831,3576,2364,2660, 787,2023, 506, 824,3702, # 1200
534, 323,4557,1044,3359,2024,1901, 946,3471,5118,1779,1500,1678,5119,1882,4558, # 1216
165, 243,4559,3703,2528, 123, 683,4239, 764,4560, 36,3998,1793, 589,2916, 816, # 1232
626,1667,3047,2237,1639,1555,1622,3832,3999,5120,4000,2874,1370,1228,1933, 891, # 1248
2084,2917, 304,4240,5121, 292,2997,2720,3577, 691,2101,4241,1115,4561, 118, 662, # 1264
5122, 611,1156, 854,2386,1316,2875, 2, 386, 515,2918,5123,5124,3286, 868,2238, # 1280
1486, 855,2661, 785,2216,3048,5125,1040,3216,3578,5126,3146, 448,5127,1525,5128, # 1296
2165,4562,5129,3833,5130,4242,2833,3579,3147, 503, 818,4001,3148,1568, 814, 676, # 1312
1444, 306,1749,5131,3834,1416,1030, 197,1428, 805,2834,1501,4563,5132,5133,5134, # 1328
1994,5135,4564,5136,5137,2198, 13,2792,3704,2998,3149,1229,1917,5138,3835,2132, # 1344
5139,4243,4565,2404,3580,5140,2217,1511,1727,1120,5141,5142, 646,3836,2448, 307, # 1360
5143,5144,1595,3217,5145,5146,5147,3705,1113,1356,4002,1465,2529,2530,5148, 519, # 1376
5149, 128,2133, 92,2289,1980,5150,4003,1512, 342,3150,2199,5151,2793,2218,1981, # 1392
3360,4244, 290,1656,1317, 789, 827,2365,5152,3837,4566, 562, 581,4004,5153, 401, # 1408
4567,2252, 94,4568,5154,1399,2794,5155,1463,2025,4569,3218,1944,5156, 828,1105, # 1424
4245,1262,1394,5157,4246, 605,4570,5158,1784,2876,5159,2835, 819,2102, 578,2200, # 1440
2952,5160,1502, 436,3287,4247,3288,2836,4005,2919,3472,3473,5161,2721,2320,5162, # 1456
5163,2337,2068, 23,4571, 193, 826,3838,2103, 699,1630,4248,3098, 390,1794,1064, # 1472
3581,5164,1579,3099,3100,1400,5165,4249,1839,1640,2877,5166,4572,4573, 137,4250, # 1488
598,3101,1967, 780, 104, 974,2953,5167, 278, 899, 253, 402, 572, 504, 493,1339, # 1504
5168,4006,1275,4574,2582,2558,5169,3706,3049,3102,2253, 565,1334,2722, 863, 41, # 1520
5170,5171,4575,5172,1657,2338, 19, 463,2760,4251, 606,5173,2999,3289,1087,2085, # 1536
1323,2662,3000,5174,1631,1623,1750,4252,2691,5175,2878, 791,2723,2663,2339, 232, # 1552
2421,5176,3001,1498,5177,2664,2630, 755,1366,3707,3290,3151,2026,1609, 119,1918, # 1568
3474, 862,1026,4253,5178,4007,3839,4576,4008,4577,2265,1952,2477,5179,1125, 817, # 1584
4254,4255,4009,1513,1766,2041,1487,4256,3050,3291,2837,3840,3152,5180,5181,1507, # 1600
5182,2692, 733, 40,1632,1106,2879, 345,4257, 841,2531, 230,4578,3002,1847,3292, # 1616
3475,5183,1263, 986,3476,5184, 735, 879, 254,1137, 857, 622,1300,1180,1388,1562, # 1632
4010,4011,2954, 967,2761,2665,1349, 592,2134,1692,3361,3003,1995,4258,1679,4012, # 1648
1902,2188,5185, 739,3708,2724,1296,1290,5186,4259,2201,2202,1922,1563,2605,2559, # 1664
1871,2762,3004,5187, 435,5188, 343,1108, 596, 17,1751,4579,2239,3477,3709,5189, # 1680
4580, 294,3582,2955,1693, 477, 979, 281,2042,3583, 643,2043,3710,2631,2795,2266, # 1696
1031,2340,2135,2303,3584,4581, 367,1249,2560,5190,3585,5191,4582,1283,3362,2005, # 1712
240,1762,3363,4583,4584, 836,1069,3153, 474,5192,2149,2532, 268,3586,5193,3219, # 1728
1521,1284,5194,1658,1546,4260,5195,3587,3588,5196,4261,3364,2693,1685,4262, 961, # 1744
1673,2632, 190,2006,2203,3841,4585,4586,5197, 570,2504,3711,1490,5198,4587,2633, # 1760
3293,1957,4588, 584,1514, 396,1045,1945,5199,4589,1968,2449,5200,5201,4590,4013, # 1776
619,5202,3154,3294, 215,2007,2796,2561,3220,4591,3221,4592, 763,4263,3842,4593, # 1792
5203,5204,1958,1767,2956,3365,3712,1174, 452,1477,4594,3366,3155,5205,2838,1253, # 1808
2387,2189,1091,2290,4264, 492,5206, 638,1169,1825,2136,1752,4014, 648, 926,1021, # 1824
1324,4595, 520,4596, 997, 847,1007, 892,4597,3843,2267,1872,3713,2405,1785,4598, # 1840
1953,2957,3103,3222,1728,4265,2044,3714,4599,2008,1701,3156,1551, 30,2268,4266, # 1856
5207,2027,4600,3589,5208, 501,5209,4267, 594,3478,2166,1822,3590,3479,3591,3223, # 1872
829,2839,4268,5210,1680,3157,1225,4269,5211,3295,4601,4270,3158,2341,5212,4602, # 1888
4271,5213,4015,4016,5214,1848,2388,2606,3367,5215,4603, 374,4017, 652,4272,4273, # 1904
375,1140, 798,5216,5217,5218,2366,4604,2269, 546,1659, 138,3051,2450,4605,5219, # 1920
2254, 612,1849, 910, 796,3844,1740,1371, 825,3845,3846,5220,2920,2562,5221, 692, # 1936
444,3052,2634, 801,4606,4274,5222,1491, 244,1053,3053,4275,4276, 340,5223,4018, # 1952
1041,3005, 293,1168, 87,1357,5224,1539, 959,5225,2240, 721, 694,4277,3847, 219, # 1968
1478, 644,1417,3368,2666,1413,1401,1335,1389,4019,5226,5227,3006,2367,3159,1826, # 1984
730,1515, 184,2840, 66,4607,5228,1660,2958, 246,3369, 378,1457, 226,3480, 975, # 2000
4020,2959,1264,3592, 674, 696,5229, 163,5230,1141,2422,2167, 713,3593,3370,4608, # 2016
4021,5231,5232,1186, 15,5233,1079,1070,5234,1522,3224,3594, 276,1050,2725, 758, # 2032
1126, 653,2960,3296,5235,2342, 889,3595,4022,3104,3007, 903,1250,4609,4023,3481, # 2048
3596,1342,1681,1718, 766,3297, 286, 89,2961,3715,5236,1713,5237,2607,3371,3008, # 2064
5238,2962,2219,3225,2880,5239,4610,2505,2533, 181, 387,1075,4024, 731,2190,3372, # 2080
5240,3298, 310, 313,3482,2304, 770,4278, 54,3054, 189,4611,3105,3848,4025,5241, # 2096
1230,1617,1850, 355,3597,4279,4612,3373, 111,4280,3716,1350,3160,3483,3055,4281, # 2112
2150,3299,3598,5242,2797,4026,4027,3009, 722,2009,5243,1071, 247,1207,2343,2478, # 2128
1378,4613,2010, 864,1437,1214,4614, 373,3849,1142,2220, 667,4615, 442,2763,2563, # 2144
3850,4028,1969,4282,3300,1840, 837, 170,1107, 934,1336,1883,5244,5245,2119,4283, # 2160
2841, 743,1569,5246,4616,4284, 582,2389,1418,3484,5247,1803,5248, 357,1395,1729, # 2176
3717,3301,2423,1564,2241,5249,3106,3851,1633,4617,1114,2086,4285,1532,5250, 482, # 2192
2451,4618,5251,5252,1492, 833,1466,5253,2726,3599,1641,2842,5254,1526,1272,3718, # 2208
4286,1686,1795, 416,2564,1903,1954,1804,5255,3852,2798,3853,1159,2321,5256,2881, # 2224
4619,1610,1584,3056,2424,2764, 443,3302,1163,3161,5257,5258,4029,5259,4287,2506, # 2240
3057,4620,4030,3162,2104,1647,3600,2011,1873,4288,5260,4289, 431,3485,5261, 250, # 2256
97, 81,4290,5262,1648,1851,1558, 160, 848,5263, 866, 740,1694,5264,2204,2843, # 2272
3226,4291,4621,3719,1687, 950,2479, 426, 469,3227,3720,3721,4031,5265,5266,1188, # 2288
424,1996, 861,3601,4292,3854,2205,2694, 168,1235,3602,4293,5267,2087,1674,4622, # 2304
3374,3303, 220,2565,1009,5268,3855, 670,3010, 332,1208, 717,5269,5270,3603,2452, # 2320
4032,3375,5271, 513,5272,1209,2882,3376,3163,4623,1080,5273,5274,5275,5276,2534, # 2336
3722,3604, 815,1587,4033,4034,5277,3605,3486,3856,1254,4624,1328,3058,1390,4035, # 2352
1741,4036,3857,4037,5278, 236,3858,2453,3304,5279,5280,3723,3859,1273,3860,4625, # 2368
5281, 308,5282,4626, 245,4627,1852,2480,1307,2583, 430, 715,2137,2454,5283, 270, # 2384
199,2883,4038,5284,3606,2727,1753, 761,1754, 725,1661,1841,4628,3487,3724,5285, # 2400
5286, 587, 14,3305, 227,2608, 326, 480,2270, 943,2765,3607, 291, 650,1884,5287, # 2416
1702,1226, 102,1547, 62,3488, 904,4629,3489,1164,4294,5288,5289,1224,1548,2766, # 2432
391, 498,1493,5290,1386,1419,5291,2056,1177,4630, 813, 880,1081,2368, 566,1145, # 2448
4631,2291,1001,1035,2566,2609,2242, 394,1286,5292,5293,2069,5294, 86,1494,1730, # 2464
4039, 491,1588, 745, 897,2963, 843,3377,4040,2767,2884,3306,1768, 998,2221,2070, # 2480
397,1827,1195,1970,3725,3011,3378, 284,5295,3861,2507,2138,2120,1904,5296,4041, # 2496
2151,4042,4295,1036,3490,1905, 114,2567,4296, 209,1527,5297,5298,2964,2844,2635, # 2512
2390,2728,3164, 812,2568,5299,3307,5300,1559, 737,1885,3726,1210, 885, 28,2695, # 2528
3608,3862,5301,4297,1004,1780,4632,5302, 346,1982,2222,2696,4633,3863,1742, 797, # 2544
1642,4043,1934,1072,1384,2152, 896,4044,3308,3727,3228,2885,3609,5303,2569,1959, # 2560
4634,2455,1786,5304,5305,5306,4045,4298,1005,1308,3728,4299,2729,4635,4636,1528, # 2576
2610, 161,1178,4300,1983, 987,4637,1101,4301, 631,4046,1157,3229,2425,1343,1241, # 2592
1016,2243,2570, 372, 877,2344,2508,1160, 555,1935, 911,4047,5307, 466,1170, 169, # 2608
1051,2921,2697,3729,2481,3012,1182,2012,2571,1251,2636,5308, 992,2345,3491,1540, # 2624
2730,1201,2071,2406,1997,2482,5309,4638, 528,1923,2191,1503,1874,1570,2369,3379, # 2640
3309,5310, 557,1073,5311,1828,3492,2088,2271,3165,3059,3107, 767,3108,2799,4639, # 2656
1006,4302,4640,2346,1267,2179,3730,3230, 778,4048,3231,2731,1597,2667,5312,4641, # 2672
5313,3493,5314,5315,5316,3310,2698,1433,3311, 131, 95,1504,4049, 723,4303,3166, # 2688
1842,3610,2768,2192,4050,2028,2105,3731,5317,3013,4051,1218,5318,3380,3232,4052, # 2704
4304,2584, 248,1634,3864, 912,5319,2845,3732,3060,3865, 654, 53,5320,3014,5321, # 2720
1688,4642, 777,3494,1032,4053,1425,5322, 191, 820,2121,2846, 971,4643, 931,3233, # 2736
135, 664, 783,3866,1998, 772,2922,1936,4054,3867,4644,2923,3234, 282,2732, 640, # 2752
1372,3495,1127, 922, 325,3381,5323,5324, 711,2045,5325,5326,4055,2223,2800,1937, # 2768
4056,3382,2224,2255,3868,2305,5327,4645,3869,1258,3312,4057,3235,2139,2965,4058, # 2784
4059,5328,2225, 258,3236,4646, 101,1227,5329,3313,1755,5330,1391,3314,5331,2924, # 2800
2057, 893,5332,5333,5334,1402,4305,2347,5335,5336,3237,3611,5337,5338, 878,1325, # 2816
1781,2801,4647, 259,1385,2585, 744,1183,2272,4648,5339,4060,2509,5340, 684,1024, # 2832
4306,5341, 472,3612,3496,1165,3315,4061,4062, 322,2153, 881, 455,1695,1152,1340, # 2848
660, 554,2154,4649,1058,4650,4307, 830,1065,3383,4063,4651,1924,5342,1703,1919, # 2864
5343, 932,2273, 122,5344,4652, 947, 677,5345,3870,2637, 297,1906,1925,2274,4653, # 2880
2322,3316,5346,5347,4308,5348,4309, 84,4310, 112, 989,5349, 547,1059,4064, 701, # 2896
3613,1019,5350,4311,5351,3497, 942, 639, 457,2306,2456, 993,2966, 407, 851, 494, # 2912
4654,3384, 927,5352,1237,5353,2426,3385, 573,4312, 680, 921,2925,1279,1875, 285, # 2928
790,1448,1984, 719,2168,5354,5355,4655,4065,4066,1649,5356,1541, 563,5357,1077, # 2944
5358,3386,3061,3498, 511,3015,4067,4068,3733,4069,1268,2572,3387,3238,4656,4657, # 2960
5359, 535,1048,1276,1189,2926,2029,3167,1438,1373,2847,2967,1134,2013,5360,4313, # 2976
1238,2586,3109,1259,5361, 700,5362,2968,3168,3734,4314,5363,4315,1146,1876,1907, # 2992
4658,2611,4070, 781,2427, 132,1589, 203, 147, 273,2802,2407, 898,1787,2155,4071, # 3008
4072,5364,3871,2803,5365,5366,4659,4660,5367,3239,5368,1635,3872, 965,5369,1805, # 3024
2699,1516,3614,1121,1082,1329,3317,4073,1449,3873, 65,1128,2848,2927,2769,1590, # 3040
3874,5370,5371, 12,2668, 45, 976,2587,3169,4661, 517,2535,1013,1037,3240,5372, # 3056
3875,2849,5373,3876,5374,3499,5375,2612, 614,1999,2323,3877,3110,2733,2638,5376, # 3072
2588,4316, 599,1269,5377,1811,3735,5378,2700,3111, 759,1060, 489,1806,3388,3318, # 3088
1358,5379,5380,2391,1387,1215,2639,2256, 490,5381,5382,4317,1759,2392,2348,5383, # 3104
4662,3878,1908,4074,2640,1807,3241,4663,3500,3319,2770,2349, 874,5384,5385,3501, # 3120
3736,1859, 91,2928,3737,3062,3879,4664,5386,3170,4075,2669,5387,3502,1202,1403, # 3136
3880,2969,2536,1517,2510,4665,3503,2511,5388,4666,5389,2701,1886,1495,1731,4076, # 3152
2370,4667,5390,2030,5391,5392,4077,2702,1216, 237,2589,4318,2324,4078,3881,4668, # 3168
4669,2703,3615,3504, 445,4670,5393,5394,5395,5396,2771, 61,4079,3738,1823,4080, # 3184
5397, 687,2046, 935, 925, 405,2670, 703,1096,1860,2734,4671,4081,1877,1367,2704, # 3200
3389, 918,2106,1782,2483, 334,3320,1611,1093,4672, 564,3171,3505,3739,3390, 945, # 3216
2641,2058,4673,5398,1926, 872,4319,5399,3506,2705,3112, 349,4320,3740,4082,4674, # 3232
3882,4321,3741,2156,4083,4675,4676,4322,4677,2408,2047, 782,4084, 400, 251,4323, # 3248
1624,5400,5401, 277,3742, 299,1265, 476,1191,3883,2122,4324,4325,1109, 205,5402, # 3264
2590,1000,2157,3616,1861,5403,5404,5405,4678,5406,4679,2573, 107,2484,2158,4085, # 3280
3507,3172,5407,1533, 541,1301, 158, 753,4326,2886,3617,5408,1696, 370,1088,4327, # 3296
4680,3618, 579, 327, 440, 162,2244, 269,1938,1374,3508, 968,3063, 56,1396,3113, # 3312
2107,3321,3391,5409,1927,2159,4681,3016,5410,3619,5411,5412,3743,4682,2485,5413, # 3328
2804,5414,1650,4683,5415,2613,5416,5417,4086,2671,3392,1149,3393,4087,3884,4088, # 3344
5418,1076, 49,5419, 951,3242,3322,3323, 450,2850, 920,5420,1812,2805,2371,4328, # 3360
1909,1138,2372,3885,3509,5421,3243,4684,1910,1147,1518,2428,4685,3886,5422,4686, # 3376
2393,2614, 260,1796,3244,5423,5424,3887,3324, 708,5425,3620,1704,5426,3621,1351, # 3392
1618,3394,3017,1887, 944,4329,3395,4330,3064,3396,4331,5427,3744, 422, 413,1714, # 3408
3325, 500,2059,2350,4332,2486,5428,1344,1911, 954,5429,1668,5430,5431,4089,2409, # 3424
4333,3622,3888,4334,5432,2307,1318,2512,3114, 133,3115,2887,4687, 629, 31,2851, # 3440
2706,3889,4688, 850, 949,4689,4090,2970,1732,2089,4335,1496,1853,5433,4091, 620, # 3456
3245, 981,1242,3745,3397,1619,3746,1643,3326,2140,2457,1971,1719,3510,2169,5434, # 3472
3246,5435,5436,3398,1829,5437,1277,4690,1565,2048,5438,1636,3623,3116,5439, 869, # 3488
2852, 655,3890,3891,3117,4092,3018,3892,1310,3624,4691,5440,5441,5442,1733, 558, # 3504
4692,3747, 335,1549,3065,1756,4336,3748,1946,3511,1830,1291,1192, 470,2735,2108, # 3520
2806, 913,1054,4093,5443,1027,5444,3066,4094,4693, 982,2672,3399,3173,3512,3247, # 3536
3248,1947,2807,5445, 571,4694,5446,1831,5447,3625,2591,1523,2429,5448,2090, 984, # 3552
4695,3749,1960,5449,3750, 852, 923,2808,3513,3751, 969,1519, 999,2049,2325,1705, # 3568
5450,3118, 615,1662, 151, 597,4095,2410,2326,1049, 275,4696,3752,4337, 568,3753, # 3584
3626,2487,4338,3754,5451,2430,2275, 409,3249,5452,1566,2888,3514,1002, 769,2853, # 3600
194,2091,3174,3755,2226,3327,4339, 628,1505,5453,5454,1763,2180,3019,4096, 521, # 3616
1161,2592,1788,2206,2411,4697,4097,1625,4340,4341, 412, 42,3119, 464,5455,2642, # 3632
4698,3400,1760,1571,2889,3515,2537,1219,2207,3893,2643,2141,2373,4699,4700,3328, # 3648
1651,3401,3627,5456,5457,3628,2488,3516,5458,3756,5459,5460,2276,2092, 460,5461, # 3664
4701,5462,3020, 962, 588,3629, 289,3250,2644,1116, 52,5463,3067,1797,5464,5465, # 3680
5466,1467,5467,1598,1143,3757,4342,1985,1734,1067,4702,1280,3402, 465,4703,1572, # 3696
510,5468,1928,2245,1813,1644,3630,5469,4704,3758,5470,5471,2673,1573,1534,5472, # 3712
5473, 536,1808,1761,3517,3894,3175,2645,5474,5475,5476,4705,3518,2929,1912,2809, # 3728
5477,3329,1122, 377,3251,5478, 360,5479,5480,4343,1529, 551,5481,2060,3759,1769, # 3744
2431,5482,2930,4344,3330,3120,2327,2109,2031,4706,1404, 136,1468,1479, 672,1171, # 3760
3252,2308, 271,3176,5483,2772,5484,2050, 678,2736, 865,1948,4707,5485,2014,4098, # 3776
2971,5486,2737,2227,1397,3068,3760,4708,4709,1735,2931,3403,3631,5487,3895, 509, # 3792
2854,2458,2890,3896,5488,5489,3177,3178,4710,4345,2538,4711,2309,1166,1010, 552, # 3808
681,1888,5490,5491,2972,2973,4099,1287,1596,1862,3179, 358, 453, 736, 175, 478, # 3824
1117, 905,1167,1097,5492,1854,1530,5493,1706,5494,2181,3519,2292,3761,3520,3632, # 3840
4346,2093,4347,5495,3404,1193,2489,4348,1458,2193,2208,1863,1889,1421,3331,2932, # 3856
3069,2182,3521, 595,2123,5496,4100,5497,5498,4349,1707,2646, 223,3762,1359, 751, # 3872
3121, 183,3522,5499,2810,3021, 419,2374, 633, 704,3897,2394, 241,5500,5501,5502, # 3888
838,3022,3763,2277,2773,2459,3898,1939,2051,4101,1309,3122,2246,1181,5503,1136, # 3904
2209,3899,2375,1446,4350,2310,4712,5504,5505,4351,1055,2615, 484,3764,5506,4102, # 3920
625,4352,2278,3405,1499,4353,4103,5507,4104,4354,3253,2279,2280,3523,5508,5509, # 3936
2774, 808,2616,3765,3406,4105,4355,3123,2539, 526,3407,3900,4356, 955,5510,1620, # 3952
4357,2647,2432,5511,1429,3766,1669,1832, 994, 928,5512,3633,1260,5513,5514,5515, # 3968
1949,2293, 741,2933,1626,4358,2738,2460, 867,1184, 362,3408,1392,5516,5517,4106, # 3984
4359,1770,1736,3254,2934,4713,4714,1929,2707,1459,1158,5518,3070,3409,2891,1292, # 4000
1930,2513,2855,3767,1986,1187,2072,2015,2617,4360,5519,2574,2514,2170,3768,2490, # 4016
3332,5520,3769,4715,5521,5522, 666,1003,3023,1022,3634,4361,5523,4716,1814,2257, # 4032
574,3901,1603, 295,1535, 705,3902,4362, 283, 858, 417,5524,5525,3255,4717,4718, # 4048
3071,1220,1890,1046,2281,2461,4107,1393,1599, 689,2575, 388,4363,5526,2491, 802, # 4064
5527,2811,3903,2061,1405,2258,5528,4719,3904,2110,1052,1345,3256,1585,5529, 809, # 4080
5530,5531,5532, 575,2739,3524, 956,1552,1469,1144,2328,5533,2329,1560,2462,3635, # 4096
3257,4108, 616,2210,4364,3180,2183,2294,5534,1833,5535,3525,4720,5536,1319,3770, # 4112
3771,1211,3636,1023,3258,1293,2812,5537,5538,5539,3905, 607,2311,3906, 762,2892, # 4128
1439,4365,1360,4721,1485,3072,5540,4722,1038,4366,1450,2062,2648,4367,1379,4723, # 4144
2593,5541,5542,4368,1352,1414,2330,2935,1172,5543,5544,3907,3908,4724,1798,1451, # 4160
5545,5546,5547,5548,2936,4109,4110,2492,2351, 411,4111,4112,3637,3333,3124,4725, # 4176
1561,2674,1452,4113,1375,5549,5550, 47,2974, 316,5551,1406,1591,2937,3181,5552, # 4192
1025,2142,3125,3182, 354,2740, 884,2228,4369,2412, 508,3772, 726,3638, 996,2433, # 4208
3639, 729,5553, 392,2194,1453,4114,4726,3773,5554,5555,2463,3640,2618,1675,2813, # 4224
919,2352,2975,2353,1270,4727,4115, 73,5556,5557, 647,5558,3259,2856,2259,1550, # 4240
1346,3024,5559,1332, 883,3526,5560,5561,5562,5563,3334,2775,5564,1212, 831,1347, # 4256
4370,4728,2331,3909,1864,3073, 720,3910,4729,4730,3911,5565,4371,5566,5567,4731, # 4272
5568,5569,1799,4732,3774,2619,4733,3641,1645,2376,4734,5570,2938, 669,2211,2675, # 4288
2434,5571,2893,5572,5573,1028,3260,5574,4372,2413,5575,2260,1353,5576,5577,4735, # 4304
3183, 518,5578,4116,5579,4373,1961,5580,2143,4374,5581,5582,3025,2354,2355,3912, # 4320
516,1834,1454,4117,2708,4375,4736,2229,2620,1972,1129,3642,5583,2776,5584,2976, # 4336
1422, 577,1470,3026,1524,3410,5585,5586, 432,4376,3074,3527,5587,2594,1455,2515, # 4352
2230,1973,1175,5588,1020,2741,4118,3528,4737,5589,2742,5590,1743,1361,3075,3529, # 4368
2649,4119,4377,4738,2295, 895, 924,4378,2171, 331,2247,3076, 166,1627,3077,1098, # 4384
5591,1232,2894,2231,3411,4739, 657, 403,1196,2377, 542,3775,3412,1600,4379,3530, # 4400
5592,4740,2777,3261, 576, 530,1362,4741,4742,2540,2676,3776,4120,5593, 842,3913, # 4416
5594,2814,2032,1014,4121, 213,2709,3413, 665, 621,4380,5595,3777,2939,2435,5596, # 4432
2436,3335,3643,3414,4743,4381,2541,4382,4744,3644,1682,4383,3531,1380,5597, 724, # 4448
2282, 600,1670,5598,1337,1233,4745,3126,2248,5599,1621,4746,5600, 651,4384,5601, # 4464
1612,4385,2621,5602,2857,5603,2743,2312,3078,5604, 716,2464,3079, 174,1255,2710, # 4480
4122,3645, 548,1320,1398, 728,4123,1574,5605,1891,1197,3080,4124,5606,3081,3082, # 4496
3778,3646,3779, 747,5607, 635,4386,4747,5608,5609,5610,4387,5611,5612,4748,5613, # 4512
3415,4749,2437, 451,5614,3780,2542,2073,4388,2744,4389,4125,5615,1764,4750,5616, # 4528
4390, 350,4751,2283,2395,2493,5617,4391,4126,2249,1434,4127, 488,4752, 458,4392, # 4544
4128,3781, 771,1330,2396,3914,2576,3184,2160,2414,1553,2677,3185,4393,5618,2494, # 4560
2895,2622,1720,2711,4394,3416,4753,5619,2543,4395,5620,3262,4396,2778,5621,2016, # 4576
2745,5622,1155,1017,3782,3915,5623,3336,2313, 201,1865,4397,1430,5624,4129,5625, # 4592
5626,5627,5628,5629,4398,1604,5630, 414,1866, 371,2595,4754,4755,3532,2017,3127, # 4608
4756,1708, 960,4399, 887, 389,2172,1536,1663,1721,5631,2232,4130,2356,2940,1580, # 4624
5632,5633,1744,4757,2544,4758,4759,5634,4760,5635,2074,5636,4761,3647,3417,2896, # 4640
4400,5637,4401,2650,3418,2815, 673,2712,2465, 709,3533,4131,3648,4402,5638,1148, # 4656
502, 634,5639,5640,1204,4762,3649,1575,4763,2623,3783,5641,3784,3128, 948,3263, # 4672
121,1745,3916,1110,5642,4403,3083,2516,3027,4132,3785,1151,1771,3917,1488,4133, # 4688
1987,5643,2438,3534,5644,5645,2094,5646,4404,3918,1213,1407,2816, 531,2746,2545, # 4704
3264,1011,1537,4764,2779,4405,3129,1061,5647,3786,3787,1867,2897,5648,2018, 120, # 4720
4406,4407,2063,3650,3265,2314,3919,2678,3419,1955,4765,4134,5649,3535,1047,2713, # 4736
1266,5650,1368,4766,2858, 649,3420,3920,2546,2747,1102,2859,2679,5651,5652,2000, # 4752
5653,1111,3651,2977,5654,2495,3921,3652,2817,1855,3421,3788,5655,5656,3422,2415, # 4768
2898,3337,3266,3653,5657,2577,5658,3654,2818,4135,1460, 856,5659,3655,5660,2899, # 4784
2978,5661,2900,3922,5662,4408, 632,2517, 875,3923,1697,3924,2296,5663,5664,4767, # 4800
3028,1239, 580,4768,4409,5665, 914, 936,2075,1190,4136,1039,2124,5666,5667,5668, # 4816
5669,3423,1473,5670,1354,4410,3925,4769,2173,3084,4137, 915,3338,4411,4412,3339, # 4832
1605,1835,5671,2748, 398,3656,4413,3926,4138, 328,1913,2860,4139,3927,1331,4414, # 4848
3029, 937,4415,5672,3657,4140,4141,3424,2161,4770,3425, 524, 742, 538,3085,1012, # 4864
5673,5674,3928,2466,5675, 658,1103, 225,3929,5676,5677,4771,5678,4772,5679,3267, # 4880
1243,5680,4142, 963,2250,4773,5681,2714,3658,3186,5682,5683,2596,2332,5684,4774, # 4896
5685,5686,5687,3536, 957,3426,2547,2033,1931,2941,2467, 870,2019,3659,1746,2780, # 4912
2781,2439,2468,5688,3930,5689,3789,3130,3790,3537,3427,3791,5690,1179,3086,5691, # 4928
3187,2378,4416,3792,2548,3188,3131,2749,4143,5692,3428,1556,2549,2297, 977,2901, # 4944
2034,4144,1205,3429,5693,1765,3430,3189,2125,1271, 714,1689,4775,3538,5694,2333, # 4960
3931, 533,4417,3660,2184, 617,5695,2469,3340,3539,2315,5696,5697,3190,5698,5699, # 4976
3932,1988, 618, 427,2651,3540,3431,5700,5701,1244,1690,5702,2819,4418,4776,5703, # 4992
3541,4777,5704,2284,1576, 473,3661,4419,3432, 972,5705,3662,5706,3087,5707,5708, # 5008
4778,4779,5709,3793,4145,4146,5710, 153,4780, 356,5711,1892,2902,4420,2144, 408, # 5024
803,2357,5712,3933,5713,4421,1646,2578,2518,4781,4782,3934,5714,3935,4422,5715, # 5040
2416,3433, 752,5716,5717,1962,3341,2979,5718, 746,3030,2470,4783,4423,3794, 698, # 5056
4784,1893,4424,3663,2550,4785,3664,3936,5719,3191,3434,5720,1824,1302,4147,2715, # 5072
3937,1974,4425,5721,4426,3192, 823,1303,1288,1236,2861,3542,4148,3435, 774,3938, # 5088
5722,1581,4786,1304,2862,3939,4787,5723,2440,2162,1083,3268,4427,4149,4428, 344, # 5104
1173, 288,2316, 454,1683,5724,5725,1461,4788,4150,2597,5726,5727,4789, 985, 894, # 5120
5728,3436,3193,5729,1914,2942,3795,1989,5730,2111,1975,5731,4151,5732,2579,1194, # 5136
425,5733,4790,3194,1245,3796,4429,5734,5735,2863,5736, 636,4791,1856,3940, 760, # 5152
1800,5737,4430,2212,1508,4792,4152,1894,1684,2298,5738,5739,4793,4431,4432,2213, # 5168
479,5740,5741, 832,5742,4153,2496,5743,2980,2497,3797, 990,3132, 627,1815,2652, # 5184
4433,1582,4434,2126,2112,3543,4794,5744, 799,4435,3195,5745,4795,2113,1737,3031, # 5200
1018, 543, 754,4436,3342,1676,4796,4797,4154,4798,1489,5746,3544,5747,2624,2903, # 5216
4155,5748,5749,2981,5750,5751,5752,5753,3196,4799,4800,2185,1722,5754,3269,3270, # 5232
1843,3665,1715, 481, 365,1976,1857,5755,5756,1963,2498,4801,5757,2127,3666,3271, # 5248
433,1895,2064,2076,5758, 602,2750,5759,5760,5761,5762,5763,3032,1628,3437,5764, # 5264
3197,4802,4156,2904,4803,2519,5765,2551,2782,5766,5767,5768,3343,4804,2905,5769, # 5280
4805,5770,2864,4806,4807,1221,2982,4157,2520,5771,5772,5773,1868,1990,5774,5775, # 5296
5776,1896,5777,5778,4808,1897,4158, 318,5779,2095,4159,4437,5780,5781, 485,5782, # 5312
938,3941, 553,2680, 116,5783,3942,3667,5784,3545,2681,2783,3438,3344,2820,5785, # 5328
3668,2943,4160,1747,2944,2983,5786,5787, 207,5788,4809,5789,4810,2521,5790,3033, # 5344
890,3669,3943,5791,1878,3798,3439,5792,2186,2358,3440,1652,5793,5794,5795, 941, # 5360
2299, 208,3546,4161,2020, 330,4438,3944,2906,2499,3799,4439,4811,5796,5797,5798, # 5376 #last 512
#Everything below is of no interest for detection purpose
2522,1613,4812,5799,3345,3945,2523,5800,4162,5801,1637,4163,2471,4813,3946,5802, # 5392
2500,3034,3800,5803,5804,2195,4814,5805,2163,5806,5807,5808,5809,5810,5811,5812, # 5408
5813,5814,5815,5816,5817,5818,5819,5820,5821,5822,5823,5824,5825,5826,5827,5828, # 5424
5829,5830,5831,5832,5833,5834,5835,5836,5837,5838,5839,5840,5841,5842,5843,5844, # 5440
5845,5846,5847,5848,5849,5850,5851,5852,5853,5854,5855,5856,5857,5858,5859,5860, # 5456
5861,5862,5863,5864,5865,5866,5867,5868,5869,5870,5871,5872,5873,5874,5875,5876, # 5472
5877,5878,5879,5880,5881,5882,5883,5884,5885,5886,5887,5888,5889,5890,5891,5892, # 5488
5893,5894,5895,5896,5897,5898,5899,5900,5901,5902,5903,5904,5905,5906,5907,5908, # 5504
5909,5910,5911,5912,5913,5914,5915,5916,5917,5918,5919,5920,5921,5922,5923,5924, # 5520
5925,5926,5927,5928,5929,5930,5931,5932,5933,5934,5935,5936,5937,5938,5939,5940, # 5536
5941,5942,5943,5944,5945,5946,5947,5948,5949,5950,5951,5952,5953,5954,5955,5956, # 5552
5957,5958,5959,5960,5961,5962,5963,5964,5965,5966,5967,5968,5969,5970,5971,5972, # 5568
5973,5974,5975,5976,5977,5978,5979,5980,5981,5982,5983,5984,5985,5986,5987,5988, # 5584
5989,5990,5991,5992,5993,5994,5995,5996,5997,5998,5999,6000,6001,6002,6003,6004, # 5600
6005,6006,6007,6008,6009,6010,6011,6012,6013,6014,6015,6016,6017,6018,6019,6020, # 5616
6021,6022,6023,6024,6025,6026,6027,6028,6029,6030,6031,6032,6033,6034,6035,6036, # 5632
6037,6038,6039,6040,6041,6042,6043,6044,6045,6046,6047,6048,6049,6050,6051,6052, # 5648
6053,6054,6055,6056,6057,6058,6059,6060,6061,6062,6063,6064,6065,6066,6067,6068, # 5664
6069,6070,6071,6072,6073,6074,6075,6076,6077,6078,6079,6080,6081,6082,6083,6084, # 5680
6085,6086,6087,6088,6089,6090,6091,6092,6093,6094,6095,6096,6097,6098,6099,6100, # 5696
6101,6102,6103,6104,6105,6106,6107,6108,6109,6110,6111,6112,6113,6114,6115,6116, # 5712
6117,6118,6119,6120,6121,6122,6123,6124,6125,6126,6127,6128,6129,6130,6131,6132, # 5728
6133,6134,6135,6136,6137,6138,6139,6140,6141,6142,6143,6144,6145,6146,6147,6148, # 5744
6149,6150,6151,6152,6153,6154,6155,6156,6157,6158,6159,6160,6161,6162,6163,6164, # 5760
6165,6166,6167,6168,6169,6170,6171,6172,6173,6174,6175,6176,6177,6178,6179,6180, # 5776
6181,6182,6183,6184,6185,6186,6187,6188,6189,6190,6191,6192,6193,6194,6195,6196, # 5792
6197,6198,6199,6200,6201,6202,6203,6204,6205,6206,6207,6208,6209,6210,6211,6212, # 5808
6213,6214,6215,6216,6217,6218,6219,6220,6221,6222,6223,3670,6224,6225,6226,6227, # 5824
6228,6229,6230,6231,6232,6233,6234,6235,6236,6237,6238,6239,6240,6241,6242,6243, # 5840
6244,6245,6246,6247,6248,6249,6250,6251,6252,6253,6254,6255,6256,6257,6258,6259, # 5856
6260,6261,6262,6263,6264,6265,6266,6267,6268,6269,6270,6271,6272,6273,6274,6275, # 5872
6276,6277,6278,6279,6280,6281,6282,6283,6284,6285,4815,6286,6287,6288,6289,6290, # 5888
6291,6292,4816,6293,6294,6295,6296,6297,6298,6299,6300,6301,6302,6303,6304,6305, # 5904
6306,6307,6308,6309,6310,6311,4817,4818,6312,6313,6314,6315,6316,6317,6318,4819, # 5920
6319,6320,6321,6322,6323,6324,6325,6326,6327,6328,6329,6330,6331,6332,6333,6334, # 5936
6335,6336,6337,4820,6338,6339,6340,6341,6342,6343,6344,6345,6346,6347,6348,6349, # 5952
6350,6351,6352,6353,6354,6355,6356,6357,6358,6359,6360,6361,6362,6363,6364,6365, # 5968
6366,6367,6368,6369,6370,6371,6372,6373,6374,6375,6376,6377,6378,6379,6380,6381, # 5984
6382,6383,6384,6385,6386,6387,6388,6389,6390,6391,6392,6393,6394,6395,6396,6397, # 6000
6398,6399,6400,6401,6402,6403,6404,6405,6406,6407,6408,6409,6410,3441,6411,6412, # 6016
6413,6414,6415,6416,6417,6418,6419,6420,6421,6422,6423,6424,6425,4440,6426,6427, # 6032
6428,6429,6430,6431,6432,6433,6434,6435,6436,6437,6438,6439,6440,6441,6442,6443, # 6048
6444,6445,6446,6447,6448,6449,6450,6451,6452,6453,6454,4821,6455,6456,6457,6458, # 6064
6459,6460,6461,6462,6463,6464,6465,6466,6467,6468,6469,6470,6471,6472,6473,6474, # 6080
6475,6476,6477,3947,3948,6478,6479,6480,6481,3272,4441,6482,6483,6484,6485,4442, # 6096
6486,6487,6488,6489,6490,6491,6492,6493,6494,6495,6496,4822,6497,6498,6499,6500, # 6112
6501,6502,6503,6504,6505,6506,6507,6508,6509,6510,6511,6512,6513,6514,6515,6516, # 6128
6517,6518,6519,6520,6521,6522,6523,6524,6525,6526,6527,6528,6529,6530,6531,6532, # 6144
6533,6534,6535,6536,6537,6538,6539,6540,6541,6542,6543,6544,6545,6546,6547,6548, # 6160
6549,6550,6551,6552,6553,6554,6555,6556,2784,6557,4823,6558,6559,6560,6561,6562, # 6176
6563,6564,6565,6566,6567,6568,6569,3949,6570,6571,6572,4824,6573,6574,6575,6576, # 6192
6577,6578,6579,6580,6581,6582,6583,4825,6584,6585,6586,3950,2785,6587,6588,6589, # 6208
6590,6591,6592,6593,6594,6595,6596,6597,6598,6599,6600,6601,6602,6603,6604,6605, # 6224
6606,6607,6608,6609,6610,6611,6612,4826,6613,6614,6615,4827,6616,6617,6618,6619, # 6240
6620,6621,6622,6623,6624,6625,4164,6626,6627,6628,6629,6630,6631,6632,6633,6634, # 6256
3547,6635,4828,6636,6637,6638,6639,6640,6641,6642,3951,2984,6643,6644,6645,6646, # 6272
6647,6648,6649,4165,6650,4829,6651,6652,4830,6653,6654,6655,6656,6657,6658,6659, # 6288
6660,6661,6662,4831,6663,6664,6665,6666,6667,6668,6669,6670,6671,4166,6672,4832, # 6304
3952,6673,6674,6675,6676,4833,6677,6678,6679,4167,6680,6681,6682,3198,6683,6684, # 6320
6685,6686,6687,6688,6689,6690,6691,6692,6693,6694,6695,6696,6697,4834,6698,6699, # 6336
6700,6701,6702,6703,6704,6705,6706,6707,6708,6709,6710,6711,6712,6713,6714,6715, # 6352
6716,6717,6718,6719,6720,6721,6722,6723,6724,6725,6726,6727,6728,6729,6730,6731, # 6368
6732,6733,6734,4443,6735,6736,6737,6738,6739,6740,6741,6742,6743,6744,6745,4444, # 6384
6746,6747,6748,6749,6750,6751,6752,6753,6754,6755,6756,6757,6758,6759,6760,6761, # 6400
6762,6763,6764,6765,6766,6767,6768,6769,6770,6771,6772,6773,6774,6775,6776,6777, # 6416
6778,6779,6780,6781,4168,6782,6783,3442,6784,6785,6786,6787,6788,6789,6790,6791, # 6432
4169,6792,6793,6794,6795,6796,6797,6798,6799,6800,6801,6802,6803,6804,6805,6806, # 6448
6807,6808,6809,6810,6811,4835,6812,6813,6814,4445,6815,6816,4446,6817,6818,6819, # 6464
6820,6821,6822,6823,6824,6825,6826,6827,6828,6829,6830,6831,6832,6833,6834,6835, # 6480
3548,6836,6837,6838,6839,6840,6841,6842,6843,6844,6845,6846,4836,6847,6848,6849, # 6496
6850,6851,6852,6853,6854,3953,6855,6856,6857,6858,6859,6860,6861,6862,6863,6864, # 6512
6865,6866,6867,6868,6869,6870,6871,6872,6873,6874,6875,6876,6877,3199,6878,6879, # 6528
6880,6881,6882,4447,6883,6884,6885,6886,6887,6888,6889,6890,6891,6892,6893,6894, # 6544
6895,6896,6897,6898,6899,6900,6901,6902,6903,6904,4170,6905,6906,6907,6908,6909, # 6560
6910,6911,6912,6913,6914,6915,6916,6917,6918,6919,6920,6921,6922,6923,6924,6925, # 6576
6926,6927,4837,6928,6929,6930,6931,6932,6933,6934,6935,6936,3346,6937,6938,4838, # 6592
6939,6940,6941,4448,6942,6943,6944,6945,6946,4449,6947,6948,6949,6950,6951,6952, # 6608
6953,6954,6955,6956,6957,6958,6959,6960,6961,6962,6963,6964,6965,6966,6967,6968, # 6624
6969,6970,6971,6972,6973,6974,6975,6976,6977,6978,6979,6980,6981,6982,6983,6984, # 6640
6985,6986,6987,6988,6989,6990,6991,6992,6993,6994,3671,6995,6996,6997,6998,4839, # 6656
6999,7000,7001,7002,3549,7003,7004,7005,7006,7007,7008,7009,7010,7011,7012,7013, # 6672
7014,7015,7016,7017,7018,7019,7020,7021,7022,7023,7024,7025,7026,7027,7028,7029, # 6688
7030,4840,7031,7032,7033,7034,7035,7036,7037,7038,4841,7039,7040,7041,7042,7043, # 6704
7044,7045,7046,7047,7048,7049,7050,7051,7052,7053,7054,7055,7056,7057,7058,7059, # 6720
7060,7061,7062,7063,7064,7065,7066,7067,7068,7069,7070,2985,7071,7072,7073,7074, # 6736
7075,7076,7077,7078,7079,7080,4842,7081,7082,7083,7084,7085,7086,7087,7088,7089, # 6752
7090,7091,7092,7093,7094,7095,7096,7097,7098,7099,7100,7101,7102,7103,7104,7105, # 6768
7106,7107,7108,7109,7110,7111,7112,7113,7114,7115,7116,7117,7118,4450,7119,7120, # 6784
7121,7122,7123,7124,7125,7126,7127,7128,7129,7130,7131,7132,7133,7134,7135,7136, # 6800
7137,7138,7139,7140,7141,7142,7143,4843,7144,7145,7146,7147,7148,7149,7150,7151, # 6816
7152,7153,7154,7155,7156,7157,7158,7159,7160,7161,7162,7163,7164,7165,7166,7167, # 6832
7168,7169,7170,7171,7172,7173,7174,7175,7176,7177,7178,7179,7180,7181,7182,7183, # 6848
7184,7185,7186,7187,7188,4171,4172,7189,7190,7191,7192,7193,7194,7195,7196,7197, # 6864
7198,7199,7200,7201,7202,7203,7204,7205,7206,7207,7208,7209,7210,7211,7212,7213, # 6880
7214,7215,7216,7217,7218,7219,7220,7221,7222,7223,7224,7225,7226,7227,7228,7229, # 6896
7230,7231,7232,7233,7234,7235,7236,7237,7238,7239,7240,7241,7242,7243,7244,7245, # 6912
7246,7247,7248,7249,7250,7251,7252,7253,7254,7255,7256,7257,7258,7259,7260,7261, # 6928
7262,7263,7264,7265,7266,7267,7268,7269,7270,7271,7272,7273,7274,7275,7276,7277, # 6944
7278,7279,7280,7281,7282,7283,7284,7285,7286,7287,7288,7289,7290,7291,7292,7293, # 6960
7294,7295,7296,4844,7297,7298,7299,7300,7301,7302,7303,7304,7305,7306,7307,7308, # 6976
7309,7310,7311,7312,7313,7314,7315,7316,4451,7317,7318,7319,7320,7321,7322,7323, # 6992
7324,7325,7326,7327,7328,7329,7330,7331,7332,7333,7334,7335,7336,7337,7338,7339, # 7008
7340,7341,7342,7343,7344,7345,7346,7347,7348,7349,7350,7351,7352,7353,4173,7354, # 7024
7355,4845,7356,7357,7358,7359,7360,7361,7362,7363,7364,7365,7366,7367,7368,7369, # 7040
7370,7371,7372,7373,7374,7375,7376,7377,7378,7379,7380,7381,7382,7383,7384,7385, # 7056
7386,7387,7388,4846,7389,7390,7391,7392,7393,7394,7395,7396,7397,7398,7399,7400, # 7072
7401,7402,7403,7404,7405,3672,7406,7407,7408,7409,7410,7411,7412,7413,7414,7415, # 7088
7416,7417,7418,7419,7420,7421,7422,7423,7424,7425,7426,7427,7428,7429,7430,7431, # 7104
7432,7433,7434,7435,7436,7437,7438,7439,7440,7441,7442,7443,7444,7445,7446,7447, # 7120
7448,7449,7450,7451,7452,7453,4452,7454,3200,7455,7456,7457,7458,7459,7460,7461, # 7136
7462,7463,7464,7465,7466,7467,7468,7469,7470,7471,7472,7473,7474,4847,7475,7476, # 7152
7477,3133,7478,7479,7480,7481,7482,7483,7484,7485,7486,7487,7488,7489,7490,7491, # 7168
7492,7493,7494,7495,7496,7497,7498,7499,7500,7501,7502,3347,7503,7504,7505,7506, # 7184
7507,7508,7509,7510,7511,7512,7513,7514,7515,7516,7517,7518,7519,7520,7521,4848, # 7200
7522,7523,7524,7525,7526,7527,7528,7529,7530,7531,7532,7533,7534,7535,7536,7537, # 7216
7538,7539,7540,7541,7542,7543,7544,7545,7546,7547,7548,7549,3801,4849,7550,7551, # 7232
7552,7553,7554,7555,7556,7557,7558,7559,7560,7561,7562,7563,7564,7565,7566,7567, # 7248
7568,7569,3035,7570,7571,7572,7573,7574,7575,7576,7577,7578,7579,7580,7581,7582, # 7264
7583,7584,7585,7586,7587,7588,7589,7590,7591,7592,7593,7594,7595,7596,7597,7598, # 7280
7599,7600,7601,7602,7603,7604,7605,7606,7607,7608,7609,7610,7611,7612,7613,7614, # 7296
7615,7616,4850,7617,7618,3802,7619,7620,7621,7622,7623,7624,7625,7626,7627,7628, # 7312
7629,7630,7631,7632,4851,7633,7634,7635,7636,7637,7638,7639,7640,7641,7642,7643, # 7328
7644,7645,7646,7647,7648,7649,7650,7651,7652,7653,7654,7655,7656,7657,7658,7659, # 7344
7660,7661,7662,7663,7664,7665,7666,7667,7668,7669,7670,4453,7671,7672,7673,7674, # 7360
7675,7676,7677,7678,7679,7680,7681,7682,7683,7684,7685,7686,7687,7688,7689,7690, # 7376
7691,7692,7693,7694,7695,7696,7697,3443,7698,7699,7700,7701,7702,4454,7703,7704, # 7392
7705,7706,7707,7708,7709,7710,7711,7712,7713,2472,7714,7715,7716,7717,7718,7719, # 7408
7720,7721,7722,7723,7724,7725,7726,7727,7728,7729,7730,7731,3954,7732,7733,7734, # 7424
7735,7736,7737,7738,7739,7740,7741,7742,7743,7744,7745,7746,7747,7748,7749,7750, # 7440
3134,7751,7752,4852,7753,7754,7755,4853,7756,7757,7758,7759,7760,4174,7761,7762, # 7456
7763,7764,7765,7766,7767,7768,7769,7770,7771,7772,7773,7774,7775,7776,7777,7778, # 7472
7779,7780,7781,7782,7783,7784,7785,7786,7787,7788,7789,7790,7791,7792,7793,7794, # 7488
7795,7796,7797,7798,7799,7800,7801,7802,7803,7804,7805,4854,7806,7807,7808,7809, # 7504
7810,7811,7812,7813,7814,7815,7816,7817,7818,7819,7820,7821,7822,7823,7824,7825, # 7520
4855,7826,7827,7828,7829,7830,7831,7832,7833,7834,7835,7836,7837,7838,7839,7840, # 7536
7841,7842,7843,7844,7845,7846,7847,3955,7848,7849,7850,7851,7852,7853,7854,7855, # 7552
7856,7857,7858,7859,7860,3444,7861,7862,7863,7864,7865,7866,7867,7868,7869,7870, # 7568
7871,7872,7873,7874,7875,7876,7877,7878,7879,7880,7881,7882,7883,7884,7885,7886, # 7584
7887,7888,7889,7890,7891,4175,7892,7893,7894,7895,7896,4856,4857,7897,7898,7899, # 7600
7900,2598,7901,7902,7903,7904,7905,7906,7907,7908,4455,7909,7910,7911,7912,7913, # 7616
7914,3201,7915,7916,7917,7918,7919,7920,7921,4858,7922,7923,7924,7925,7926,7927, # 7632
7928,7929,7930,7931,7932,7933,7934,7935,7936,7937,7938,7939,7940,7941,7942,7943, # 7648
7944,7945,7946,7947,7948,7949,7950,7951,7952,7953,7954,7955,7956,7957,7958,7959, # 7664
7960,7961,7962,7963,7964,7965,7966,7967,7968,7969,7970,7971,7972,7973,7974,7975, # 7680
7976,7977,7978,7979,7980,7981,4859,7982,7983,7984,7985,7986,7987,7988,7989,7990, # 7696
7991,7992,7993,7994,7995,7996,4860,7997,7998,7999,8000,8001,8002,8003,8004,8005, # 7712
8006,8007,8008,8009,8010,8011,8012,8013,8014,8015,8016,4176,8017,8018,8019,8020, # 7728
8021,8022,8023,4861,8024,8025,8026,8027,8028,8029,8030,8031,8032,8033,8034,8035, # 7744
8036,4862,4456,8037,8038,8039,8040,4863,8041,8042,8043,8044,8045,8046,8047,8048, # 7760
8049,8050,8051,8052,8053,8054,8055,8056,8057,8058,8059,8060,8061,8062,8063,8064, # 7776
8065,8066,8067,8068,8069,8070,8071,8072,8073,8074,8075,8076,8077,8078,8079,8080, # 7792
8081,8082,8083,8084,8085,8086,8087,8088,8089,8090,8091,8092,8093,8094,8095,8096, # 7808
8097,8098,8099,4864,4177,8100,8101,8102,8103,8104,8105,8106,8107,8108,8109,8110, # 7824
8111,8112,8113,8114,8115,8116,8117,8118,8119,8120,4178,8121,8122,8123,8124,8125, # 7840
8126,8127,8128,8129,8130,8131,8132,8133,8134,8135,8136,8137,8138,8139,8140,8141, # 7856
8142,8143,8144,8145,4865,4866,8146,8147,8148,8149,8150,8151,8152,8153,8154,8155, # 7872
8156,8157,8158,8159,8160,8161,8162,8163,8164,8165,4179,8166,8167,8168,8169,8170, # 7888
8171,8172,8173,8174,8175,8176,8177,8178,8179,8180,8181,4457,8182,8183,8184,8185, # 7904
8186,8187,8188,8189,8190,8191,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201, # 7920
8202,8203,8204,8205,8206,8207,8208,8209,8210,8211,8212,8213,8214,8215,8216,8217, # 7936
8218,8219,8220,8221,8222,8223,8224,8225,8226,8227,8228,8229,8230,8231,8232,8233, # 7952
8234,8235,8236,8237,8238,8239,8240,8241,8242,8243,8244,8245,8246,8247,8248,8249, # 7968
8250,8251,8252,8253,8254,8255,8256,3445,8257,8258,8259,8260,8261,8262,4458,8263, # 7984
8264,8265,8266,8267,8268,8269,8270,8271,8272,4459,8273,8274,8275,8276,3550,8277, # 8000
8278,8279,8280,8281,8282,8283,8284,8285,8286,8287,8288,8289,4460,8290,8291,8292, # 8016
8293,8294,8295,8296,8297,8298,8299,8300,8301,8302,8303,8304,8305,8306,8307,4867, # 8032
8308,8309,8310,8311,8312,3551,8313,8314,8315,8316,8317,8318,8319,8320,8321,8322, # 8048
8323,8324,8325,8326,4868,8327,8328,8329,8330,8331,8332,8333,8334,8335,8336,8337, # 8064
8338,8339,8340,8341,8342,8343,8344,8345,8346,8347,8348,8349,8350,8351,8352,8353, # 8080
8354,8355,8356,8357,8358,8359,8360,8361,8362,8363,4869,4461,8364,8365,8366,8367, # 8096
8368,8369,8370,4870,8371,8372,8373,8374,8375,8376,8377,8378,8379,8380,8381,8382, # 8112
8383,8384,8385,8386,8387,8388,8389,8390,8391,8392,8393,8394,8395,8396,8397,8398, # 8128
8399,8400,8401,8402,8403,8404,8405,8406,8407,8408,8409,8410,4871,8411,8412,8413, # 8144
8414,8415,8416,8417,8418,8419,8420,8421,8422,4462,8423,8424,8425,8426,8427,8428, # 8160
8429,8430,8431,8432,8433,2986,8434,8435,8436,8437,8438,8439,8440,8441,8442,8443, # 8176
8444,8445,8446,8447,8448,8449,8450,8451,8452,8453,8454,8455,8456,8457,8458,8459, # 8192
8460,8461,8462,8463,8464,8465,8466,8467,8468,8469,8470,8471,8472,8473,8474,8475, # 8208
8476,8477,8478,4180,8479,8480,8481,8482,8483,8484,8485,8486,8487,8488,8489,8490, # 8224
8491,8492,8493,8494,8495,8496,8497,8498,8499,8500,8501,8502,8503,8504,8505,8506, # 8240
8507,8508,8509,8510,8511,8512,8513,8514,8515,8516,8517,8518,8519,8520,8521,8522, # 8256
8523,8524,8525,8526,8527,8528,8529,8530,8531,8532,8533,8534,8535,8536,8537,8538, # 8272
8539,8540,8541,8542,8543,8544,8545,8546,8547,8548,8549,8550,8551,8552,8553,8554, # 8288
8555,8556,8557,8558,8559,8560,8561,8562,8563,8564,4872,8565,8566,8567,8568,8569, # 8304
8570,8571,8572,8573,4873,8574,8575,8576,8577,8578,8579,8580,8581,8582,8583,8584, # 8320
8585,8586,8587,8588,8589,8590,8591,8592,8593,8594,8595,8596,8597,8598,8599,8600, # 8336
8601,8602,8603,8604,8605,3803,8606,8607,8608,8609,8610,8611,8612,8613,4874,3804, # 8352
8614,8615,8616,8617,8618,8619,8620,8621,3956,8622,8623,8624,8625,8626,8627,8628, # 8368
8629,8630,8631,8632,8633,8634,8635,8636,8637,8638,2865,8639,8640,8641,8642,8643, # 8384
8644,8645,8646,8647,8648,8649,8650,8651,8652,8653,8654,8655,8656,4463,8657,8658, # 8400
8659,4875,4876,8660,8661,8662,8663,8664,8665,8666,8667,8668,8669,8670,8671,8672, # 8416
8673,8674,8675,8676,8677,8678,8679,8680,8681,4464,8682,8683,8684,8685,8686,8687, # 8432
8688,8689,8690,8691,8692,8693,8694,8695,8696,8697,8698,8699,8700,8701,8702,8703, # 8448
8704,8705,8706,8707,8708,8709,2261,8710,8711,8712,8713,8714,8715,8716,8717,8718, # 8464
8719,8720,8721,8722,8723,8724,8725,8726,8727,8728,8729,8730,8731,8732,8733,4181, # 8480
8734,8735,8736,8737,8738,8739,8740,8741,8742,8743,8744,8745,8746,8747,8748,8749, # 8496
8750,8751,8752,8753,8754,8755,8756,8757,8758,8759,8760,8761,8762,8763,4877,8764, # 8512
8765,8766,8767,8768,8769,8770,8771,8772,8773,8774,8775,8776,8777,8778,8779,8780, # 8528
8781,8782,8783,8784,8785,8786,8787,8788,4878,8789,4879,8790,8791,8792,4880,8793, # 8544
8794,8795,8796,8797,8798,8799,8800,8801,4881,8802,8803,8804,8805,8806,8807,8808, # 8560
8809,8810,8811,8812,8813,8814,8815,3957,8816,8817,8818,8819,8820,8821,8822,8823, # 8576
8824,8825,8826,8827,8828,8829,8830,8831,8832,8833,8834,8835,8836,8837,8838,8839, # 8592
8840,8841,8842,8843,8844,8845,8846,8847,4882,8848,8849,8850,8851,8852,8853,8854, # 8608
8855,8856,8857,8858,8859,8860,8861,8862,8863,8864,8865,8866,8867,8868,8869,8870, # 8624
8871,8872,8873,8874,8875,8876,8877,8878,8879,8880,8881,8882,8883,8884,3202,8885, # 8640
8886,8887,8888,8889,8890,8891,8892,8893,8894,8895,8896,8897,8898,8899,8900,8901, # 8656
8902,8903,8904,8905,8906,8907,8908,8909,8910,8911,8912,8913,8914,8915,8916,8917, # 8672
8918,8919,8920,8921,8922,8923,8924,4465,8925,8926,8927,8928,8929,8930,8931,8932, # 8688
4883,8933,8934,8935,8936,8937,8938,8939,8940,8941,8942,8943,2214,8944,8945,8946, # 8704
8947,8948,8949,8950,8951,8952,8953,8954,8955,8956,8957,8958,8959,8960,8961,8962, # 8720
8963,8964,8965,4884,8966,8967,8968,8969,8970,8971,8972,8973,8974,8975,8976,8977, # 8736
8978,8979,8980,8981,8982,8983,8984,8985,8986,8987,8988,8989,8990,8991,8992,4885, # 8752
8993,8994,8995,8996,8997,8998,8999,9000,9001,9002,9003,9004,9005,9006,9007,9008, # 8768
9009,9010,9011,9012,9013,9014,9015,9016,9017,9018,9019,9020,9021,4182,9022,9023, # 8784
9024,9025,9026,9027,9028,9029,9030,9031,9032,9033,9034,9035,9036,9037,9038,9039, # 8800
9040,9041,9042,9043,9044,9045,9046,9047,9048,9049,9050,9051,9052,9053,9054,9055, # 8816
9056,9057,9058,9059,9060,9061,9062,9063,4886,9064,9065,9066,9067,9068,9069,4887, # 8832
9070,9071,9072,9073,9074,9075,9076,9077,9078,9079,9080,9081,9082,9083,9084,9085, # 8848
9086,9087,9088,9089,9090,9091,9092,9093,9094,9095,9096,9097,9098,9099,9100,9101, # 8864
9102,9103,9104,9105,9106,9107,9108,9109,9110,9111,9112,9113,9114,9115,9116,9117, # 8880
9118,9119,9120,9121,9122,9123,9124,9125,9126,9127,9128,9129,9130,9131,9132,9133, # 8896
9134,9135,9136,9137,9138,9139,9140,9141,3958,9142,9143,9144,9145,9146,9147,9148, # 8912
9149,9150,9151,4888,9152,9153,9154,9155,9156,9157,9158,9159,9160,9161,9162,9163, # 8928
9164,9165,9166,9167,9168,9169,9170,9171,9172,9173,9174,9175,4889,9176,9177,9178, # 8944
9179,9180,9181,9182,9183,9184,9185,9186,9187,9188,9189,9190,9191,9192,9193,9194, # 8960
9195,9196,9197,9198,9199,9200,9201,9202,9203,4890,9204,9205,9206,9207,9208,9209, # 8976
9210,9211,9212,9213,9214,9215,9216,9217,9218,9219,9220,9221,9222,4466,9223,9224, # 8992
9225,9226,9227,9228,9229,9230,9231,9232,9233,9234,9235,9236,9237,9238,9239,9240, # 9008
9241,9242,9243,9244,9245,4891,9246,9247,9248,9249,9250,9251,9252,9253,9254,9255, # 9024
9256,9257,4892,9258,9259,9260,9261,4893,4894,9262,9263,9264,9265,9266,9267,9268, # 9040
9269,9270,9271,9272,9273,4467,9274,9275,9276,9277,9278,9279,9280,9281,9282,9283, # 9056
9284,9285,3673,9286,9287,9288,9289,9290,9291,9292,9293,9294,9295,9296,9297,9298, # 9072
9299,9300,9301,9302,9303,9304,9305,9306,9307,9308,9309,9310,9311,9312,9313,9314, # 9088
9315,9316,9317,9318,9319,9320,9321,9322,4895,9323,9324,9325,9326,9327,9328,9329, # 9104
9330,9331,9332,9333,9334,9335,9336,9337,9338,9339,9340,9341,9342,9343,9344,9345, # 9120
9346,9347,4468,9348,9349,9350,9351,9352,9353,9354,9355,9356,9357,9358,9359,9360, # 9136
9361,9362,9363,9364,9365,9366,9367,9368,9369,9370,9371,9372,9373,4896,9374,4469, # 9152
9375,9376,9377,9378,9379,4897,9380,9381,9382,9383,9384,9385,9386,9387,9388,9389, # 9168
9390,9391,9392,9393,9394,9395,9396,9397,9398,9399,9400,9401,9402,9403,9404,9405, # 9184
9406,4470,9407,2751,9408,9409,3674,3552,9410,9411,9412,9413,9414,9415,9416,9417, # 9200
9418,9419,9420,9421,4898,9422,9423,9424,9425,9426,9427,9428,9429,3959,9430,9431, # 9216
9432,9433,9434,9435,9436,4471,9437,9438,9439,9440,9441,9442,9443,9444,9445,9446, # 9232
9447,9448,9449,9450,3348,9451,9452,9453,9454,9455,9456,9457,9458,9459,9460,9461, # 9248
9462,9463,9464,9465,9466,9467,9468,9469,9470,9471,9472,4899,9473,9474,9475,9476, # 9264
9477,4900,9478,9479,9480,9481,9482,9483,9484,9485,9486,9487,9488,3349,9489,9490, # 9280
9491,9492,9493,9494,9495,9496,9497,9498,9499,9500,9501,9502,9503,9504,9505,9506, # 9296
9507,9508,9509,9510,9511,9512,9513,9514,9515,9516,9517,9518,9519,9520,4901,9521, # 9312
9522,9523,9524,9525,9526,4902,9527,9528,9529,9530,9531,9532,9533,9534,9535,9536, # 9328
9537,9538,9539,9540,9541,9542,9543,9544,9545,9546,9547,9548,9549,9550,9551,9552, # 9344
9553,9554,9555,9556,9557,9558,9559,9560,9561,9562,9563,9564,9565,9566,9567,9568, # 9360
9569,9570,9571,9572,9573,9574,9575,9576,9577,9578,9579,9580,9581,9582,9583,9584, # 9376
3805,9585,9586,9587,9588,9589,9590,9591,9592,9593,9594,9595,9596,9597,9598,9599, # 9392
9600,9601,9602,4903,9603,9604,9605,9606,9607,4904,9608,9609,9610,9611,9612,9613, # 9408
9614,4905,9615,9616,9617,9618,9619,9620,9621,9622,9623,9624,9625,9626,9627,9628, # 9424
9629,9630,9631,9632,4906,9633,9634,9635,9636,9637,9638,9639,9640,9641,9642,9643, # 9440
4907,9644,9645,9646,9647,9648,9649,9650,9651,9652,9653,9654,9655,9656,9657,9658, # 9456
9659,9660,9661,9662,9663,9664,9665,9666,9667,9668,9669,9670,9671,9672,4183,9673, # 9472
9674,9675,9676,9677,4908,9678,9679,9680,9681,4909,9682,9683,9684,9685,9686,9687, # 9488
9688,9689,9690,4910,9691,9692,9693,3675,9694,9695,9696,2945,9697,9698,9699,9700, # 9504
9701,9702,9703,9704,9705,4911,9706,9707,9708,9709,9710,9711,9712,9713,9714,9715, # 9520
9716,9717,9718,9719,9720,9721,9722,9723,9724,9725,9726,9727,9728,9729,9730,9731, # 9536
9732,9733,9734,9735,4912,9736,9737,9738,9739,9740,4913,9741,9742,9743,9744,9745, # 9552
9746,9747,9748,9749,9750,9751,9752,9753,9754,9755,9756,9757,9758,4914,9759,9760, # 9568
9761,9762,9763,9764,9765,9766,9767,9768,9769,9770,9771,9772,9773,9774,9775,9776, # 9584
9777,9778,9779,9780,9781,9782,4915,9783,9784,9785,9786,9787,9788,9789,9790,9791, # 9600
9792,9793,4916,9794,9795,9796,9797,9798,9799,9800,9801,9802,9803,9804,9805,9806, # 9616
9807,9808,9809,9810,9811,9812,9813,9814,9815,9816,9817,9818,9819,9820,9821,9822, # 9632
9823,9824,9825,9826,9827,9828,9829,9830,9831,9832,9833,9834,9835,9836,9837,9838, # 9648
9839,9840,9841,9842,9843,9844,9845,9846,9847,9848,9849,9850,9851,9852,9853,9854, # 9664
9855,9856,9857,9858,9859,9860,9861,9862,9863,9864,9865,9866,9867,9868,4917,9869, # 9680
9870,9871,9872,9873,9874,9875,9876,9877,9878,9879,9880,9881,9882,9883,9884,9885, # 9696
9886,9887,9888,9889,9890,9891,9892,4472,9893,9894,9895,9896,9897,3806,9898,9899, # 9712
9900,9901,9902,9903,9904,9905,9906,9907,9908,9909,9910,9911,9912,9913,9914,4918, # 9728
9915,9916,9917,4919,9918,9919,9920,9921,4184,9922,9923,9924,9925,9926,9927,9928, # 9744
9929,9930,9931,9932,9933,9934,9935,9936,9937,9938,9939,9940,9941,9942,9943,9944, # 9760
9945,9946,4920,9947,9948,9949,9950,9951,9952,9953,9954,9955,4185,9956,9957,9958, # 9776
9959,9960,9961,9962,9963,9964,9965,4921,9966,9967,9968,4473,9969,9970,9971,9972, # 9792
9973,9974,9975,9976,9977,4474,9978,9979,9980,9981,9982,9983,9984,9985,9986,9987, # 9808
9988,9989,9990,9991,9992,9993,9994,9995,9996,9997,9998,9999,10000,10001,10002,10003, # 9824
10004,10005,10006,10007,10008,10009,10010,10011,10012,10013,10014,10015,10016,10017,10018,10019, # 9840
10020,10021,4922,10022,4923,10023,10024,10025,10026,10027,10028,10029,10030,10031,10032,10033, # 9856
10034,10035,10036,10037,10038,10039,10040,10041,10042,10043,10044,10045,10046,10047,10048,4924, # 9872
10049,10050,10051,10052,10053,10054,10055,10056,10057,10058,10059,10060,10061,10062,10063,10064, # 9888
10065,10066,10067,10068,10069,10070,10071,10072,10073,10074,10075,10076,10077,10078,10079,10080, # 9904
10081,10082,10083,10084,10085,10086,10087,4475,10088,10089,10090,10091,10092,10093,10094,10095, # 9920
10096,10097,4476,10098,10099,10100,10101,10102,10103,10104,10105,10106,10107,10108,10109,10110, # 9936
10111,2174,10112,10113,10114,10115,10116,10117,10118,10119,10120,10121,10122,10123,10124,10125, # 9952
10126,10127,10128,10129,10130,10131,10132,10133,10134,10135,10136,10137,10138,10139,10140,3807, # 9968
4186,4925,10141,10142,10143,10144,10145,10146,10147,4477,4187,10148,10149,10150,10151,10152, # 9984
10153,4188,10154,10155,10156,10157,10158,10159,10160,10161,4926,10162,10163,10164,10165,10166, #10000
10167,10168,10169,10170,10171,10172,10173,10174,10175,10176,10177,10178,10179,10180,10181,10182, #10016
10183,10184,10185,10186,10187,10188,10189,10190,10191,10192,3203,10193,10194,10195,10196,10197, #10032
10198,10199,10200,4478,10201,10202,10203,10204,4479,10205,10206,10207,10208,10209,10210,10211, #10048
10212,10213,10214,10215,10216,10217,10218,10219,10220,10221,10222,10223,10224,10225,10226,10227, #10064
10228,10229,10230,10231,10232,10233,10234,4927,10235,10236,10237,10238,10239,10240,10241,10242, #10080
10243,10244,10245,10246,10247,10248,10249,10250,10251,10252,10253,10254,10255,10256,10257,10258, #10096
10259,10260,10261,10262,10263,10264,10265,10266,10267,10268,10269,10270,10271,10272,10273,4480, #10112
4928,4929,10274,10275,10276,10277,10278,10279,10280,10281,10282,10283,10284,10285,10286,10287, #10128
10288,10289,10290,10291,10292,10293,10294,10295,10296,10297,10298,10299,10300,10301,10302,10303, #10144
10304,10305,10306,10307,10308,10309,10310,10311,10312,10313,10314,10315,10316,10317,10318,10319, #10160
10320,10321,10322,10323,10324,10325,10326,10327,10328,10329,10330,10331,10332,10333,10334,4930, #10176
10335,10336,10337,10338,10339,10340,10341,10342,4931,10343,10344,10345,10346,10347,10348,10349, #10192
10350,10351,10352,10353,10354,10355,3088,10356,2786,10357,10358,10359,10360,4189,10361,10362, #10208
10363,10364,10365,10366,10367,10368,10369,10370,10371,10372,10373,10374,10375,4932,10376,10377, #10224
10378,10379,10380,10381,10382,10383,10384,10385,10386,10387,10388,10389,10390,10391,10392,4933, #10240
10393,10394,10395,4934,10396,10397,10398,10399,10400,10401,10402,10403,10404,10405,10406,10407, #10256
10408,10409,10410,10411,10412,3446,10413,10414,10415,10416,10417,10418,10419,10420,10421,10422, #10272
10423,4935,10424,10425,10426,10427,10428,10429,10430,4936,10431,10432,10433,10434,10435,10436, #10288
10437,10438,10439,10440,10441,10442,10443,4937,10444,10445,10446,10447,4481,10448,10449,10450, #10304
10451,10452,10453,10454,10455,10456,10457,10458,10459,10460,10461,10462,10463,10464,10465,10466, #10320
10467,10468,10469,10470,10471,10472,10473,10474,10475,10476,10477,10478,10479,10480,10481,10482, #10336
10483,10484,10485,10486,10487,10488,10489,10490,10491,10492,10493,10494,10495,10496,10497,10498, #10352
10499,10500,10501,10502,10503,10504,10505,4938,10506,10507,10508,10509,10510,2552,10511,10512, #10368
10513,10514,10515,10516,3447,10517,10518,10519,10520,10521,10522,10523,10524,10525,10526,10527, #10384
10528,10529,10530,10531,10532,10533,10534,10535,10536,10537,10538,10539,10540,10541,10542,10543, #10400
4482,10544,4939,10545,10546,10547,10548,10549,10550,10551,10552,10553,10554,10555,10556,10557, #10416
10558,10559,10560,10561,10562,10563,10564,10565,10566,10567,3676,4483,10568,10569,10570,10571, #10432
10572,3448,10573,10574,10575,10576,10577,10578,10579,10580,10581,10582,10583,10584,10585,10586, #10448
10587,10588,10589,10590,10591,10592,10593,10594,10595,10596,10597,10598,10599,10600,10601,10602, #10464
10603,10604,10605,10606,10607,10608,10609,10610,10611,10612,10613,10614,10615,10616,10617,10618, #10480
10619,10620,10621,10622,10623,10624,10625,10626,10627,4484,10628,10629,10630,10631,10632,4940, #10496
10633,10634,10635,10636,10637,10638,10639,10640,10641,10642,10643,10644,10645,10646,10647,10648, #10512
10649,10650,10651,10652,10653,10654,10655,10656,4941,10657,10658,10659,2599,10660,10661,10662, #10528
10663,10664,10665,10666,3089,10667,10668,10669,10670,10671,10672,10673,10674,10675,10676,10677, #10544
10678,10679,10680,4942,10681,10682,10683,10684,10685,10686,10687,10688,10689,10690,10691,10692, #10560
10693,10694,10695,10696,10697,4485,10698,10699,10700,10701,10702,10703,10704,4943,10705,3677, #10576
10706,10707,10708,10709,10710,10711,10712,4944,10713,10714,10715,10716,10717,10718,10719,10720, #10592
10721,10722,10723,10724,10725,10726,10727,10728,4945,10729,10730,10731,10732,10733,10734,10735, #10608
10736,10737,10738,10739,10740,10741,10742,10743,10744,10745,10746,10747,10748,10749,10750,10751, #10624
10752,10753,10754,10755,10756,10757,10758,10759,10760,10761,4946,10762,10763,10764,10765,10766, #10640
10767,4947,4948,10768,10769,10770,10771,10772,10773,10774,10775,10776,10777,10778,10779,10780, #10656
10781,10782,10783,10784,10785,10786,10787,10788,10789,10790,10791,10792,10793,10794,10795,10796, #10672
10797,10798,10799,10800,10801,10802,10803,10804,10805,10806,10807,10808,10809,10810,10811,10812, #10688
10813,10814,10815,10816,10817,10818,10819,10820,10821,10822,10823,10824,10825,10826,10827,10828, #10704
10829,10830,10831,10832,10833,10834,10835,10836,10837,10838,10839,10840,10841,10842,10843,10844, #10720
10845,10846,10847,10848,10849,10850,10851,10852,10853,10854,10855,10856,10857,10858,10859,10860, #10736
10861,10862,10863,10864,10865,10866,10867,10868,10869,10870,10871,10872,10873,10874,10875,10876, #10752
10877,10878,4486,10879,10880,10881,10882,10883,10884,10885,4949,10886,10887,10888,10889,10890, #10768
10891,10892,10893,10894,10895,10896,10897,10898,10899,10900,10901,10902,10903,10904,10905,10906, #10784
10907,10908,10909,10910,10911,10912,10913,10914,10915,10916,10917,10918,10919,4487,10920,10921, #10800
10922,10923,10924,10925,10926,10927,10928,10929,10930,10931,10932,4950,10933,10934,10935,10936, #10816
10937,10938,10939,10940,10941,10942,10943,10944,10945,10946,10947,10948,10949,4488,10950,10951, #10832
10952,10953,10954,10955,10956,10957,10958,10959,4190,10960,10961,10962,10963,10964,10965,10966, #10848
10967,10968,10969,10970,10971,10972,10973,10974,10975,10976,10977,10978,10979,10980,10981,10982, #10864
10983,10984,10985,10986,10987,10988,10989,10990,10991,10992,10993,10994,10995,10996,10997,10998, #10880
10999,11000,11001,11002,11003,11004,11005,11006,3960,11007,11008,11009,11010,11011,11012,11013, #10896
11014,11015,11016,11017,11018,11019,11020,11021,11022,11023,11024,11025,11026,11027,11028,11029, #10912
11030,11031,11032,4951,11033,11034,11035,11036,11037,11038,11039,11040,11041,11042,11043,11044, #10928
11045,11046,11047,4489,11048,11049,11050,11051,4952,11052,11053,11054,11055,11056,11057,11058, #10944
4953,11059,11060,11061,11062,11063,11064,11065,11066,11067,11068,11069,11070,11071,4954,11072, #10960
11073,11074,11075,11076,11077,11078,11079,11080,11081,11082,11083,11084,11085,11086,11087,11088, #10976
11089,11090,11091,11092,11093,11094,11095,11096,11097,11098,11099,11100,11101,11102,11103,11104, #10992
11105,11106,11107,11108,11109,11110,11111,11112,11113,11114,11115,3808,11116,11117,11118,11119, #11008
11120,11121,11122,11123,11124,11125,11126,11127,11128,11129,11130,11131,11132,11133,11134,4955, #11024
11135,11136,11137,11138,11139,11140,11141,11142,11143,11144,11145,11146,11147,11148,11149,11150, #11040
11151,11152,11153,11154,11155,11156,11157,11158,11159,11160,11161,4956,11162,11163,11164,11165, #11056
11166,11167,11168,11169,11170,11171,11172,11173,11174,11175,11176,11177,11178,11179,11180,4957, #11072
11181,11182,11183,11184,11185,11186,4958,11187,11188,11189,11190,11191,11192,11193,11194,11195, #11088
11196,11197,11198,11199,11200,3678,11201,11202,11203,11204,11205,11206,4191,11207,11208,11209, #11104
11210,11211,11212,11213,11214,11215,11216,11217,11218,11219,11220,11221,11222,11223,11224,11225, #11120
11226,11227,11228,11229,11230,11231,11232,11233,11234,11235,11236,11237,11238,11239,11240,11241, #11136
11242,11243,11244,11245,11246,11247,11248,11249,11250,11251,4959,11252,11253,11254,11255,11256, #11152
11257,11258,11259,11260,11261,11262,11263,11264,11265,11266,11267,11268,11269,11270,11271,11272, #11168
11273,11274,11275,11276,11277,11278,11279,11280,11281,11282,11283,11284,11285,11286,11287,11288, #11184
11289,11290,11291,11292,11293,11294,11295,11296,11297,11298,11299,11300,11301,11302,11303,11304, #11200
11305,11306,11307,11308,11309,11310,11311,11312,11313,11314,3679,11315,11316,11317,11318,4490, #11216
11319,11320,11321,11322,11323,11324,11325,11326,11327,11328,11329,11330,11331,11332,11333,11334, #11232
11335,11336,11337,11338,11339,11340,11341,11342,11343,11344,11345,11346,11347,4960,11348,11349, #11248
11350,11351,11352,11353,11354,11355,11356,11357,11358,11359,11360,11361,11362,11363,11364,11365, #11264
11366,11367,11368,11369,11370,11371,11372,11373,11374,11375,11376,11377,3961,4961,11378,11379, #11280
11380,11381,11382,11383,11384,11385,11386,11387,11388,11389,11390,11391,11392,11393,11394,11395, #11296
11396,11397,4192,11398,11399,11400,11401,11402,11403,11404,11405,11406,11407,11408,11409,11410, #11312
11411,4962,11412,11413,11414,11415,11416,11417,11418,11419,11420,11421,11422,11423,11424,11425, #11328
11426,11427,11428,11429,11430,11431,11432,11433,11434,11435,11436,11437,11438,11439,11440,11441, #11344
11442,11443,11444,11445,11446,11447,11448,11449,11450,11451,11452,11453,11454,11455,11456,11457, #11360
11458,11459,11460,11461,11462,11463,11464,11465,11466,11467,11468,11469,4963,11470,11471,4491, #11376
11472,11473,11474,11475,4964,11476,11477,11478,11479,11480,11481,11482,11483,11484,11485,11486, #11392
11487,11488,11489,11490,11491,11492,4965,11493,11494,11495,11496,11497,11498,11499,11500,11501, #11408
11502,11503,11504,11505,11506,11507,11508,11509,11510,11511,11512,11513,11514,11515,11516,11517, #11424
11518,11519,11520,11521,11522,11523,11524,11525,11526,11527,11528,11529,3962,11530,11531,11532, #11440
11533,11534,11535,11536,11537,11538,11539,11540,11541,11542,11543,11544,11545,11546,11547,11548, #11456
11549,11550,11551,11552,11553,11554,11555,11556,11557,11558,11559,11560,11561,11562,11563,11564, #11472
4193,4194,11565,11566,11567,11568,11569,11570,11571,11572,11573,11574,11575,11576,11577,11578, #11488
11579,11580,11581,11582,11583,11584,11585,11586,11587,11588,11589,11590,11591,4966,4195,11592, #11504
11593,11594,11595,11596,11597,11598,11599,11600,11601,11602,11603,11604,3090,11605,11606,11607, #11520
11608,11609,11610,4967,11611,11612,11613,11614,11615,11616,11617,11618,11619,11620,11621,11622, #11536
11623,11624,11625,11626,11627,11628,11629,11630,11631,11632,11633,11634,11635,11636,11637,11638, #11552
11639,11640,11641,11642,11643,11644,11645,11646,11647,11648,11649,11650,11651,11652,11653,11654, #11568
11655,11656,11657,11658,11659,11660,11661,11662,11663,11664,11665,11666,11667,11668,11669,11670, #11584
11671,11672,11673,11674,4968,11675,11676,11677,11678,11679,11680,11681,11682,11683,11684,11685, #11600
11686,11687,11688,11689,11690,11691,11692,11693,3809,11694,11695,11696,11697,11698,11699,11700, #11616
11701,11702,11703,11704,11705,11706,11707,11708,11709,11710,11711,11712,11713,11714,11715,11716, #11632
11717,11718,3553,11719,11720,11721,11722,11723,11724,11725,11726,11727,11728,11729,11730,4969, #11648
11731,11732,11733,11734,11735,11736,11737,11738,11739,11740,4492,11741,11742,11743,11744,11745, #11664
11746,11747,11748,11749,11750,11751,11752,4970,11753,11754,11755,11756,11757,11758,11759,11760, #11680
11761,11762,11763,11764,11765,11766,11767,11768,11769,11770,11771,11772,11773,11774,11775,11776, #11696
11777,11778,11779,11780,11781,11782,11783,11784,11785,11786,11787,11788,11789,11790,4971,11791, #11712
11792,11793,11794,11795,11796,11797,4972,11798,11799,11800,11801,11802,11803,11804,11805,11806, #11728
11807,11808,11809,11810,4973,11811,11812,11813,11814,11815,11816,11817,11818,11819,11820,11821, #11744
11822,11823,11824,11825,11826,11827,11828,11829,11830,11831,11832,11833,11834,3680,3810,11835, #11760
11836,4974,11837,11838,11839,11840,11841,11842,11843,11844,11845,11846,11847,11848,11849,11850, #11776
11851,11852,11853,11854,11855,11856,11857,11858,11859,11860,11861,11862,11863,11864,11865,11866, #11792
11867,11868,11869,11870,11871,11872,11873,11874,11875,11876,11877,11878,11879,11880,11881,11882, #11808
11883,11884,4493,11885,11886,11887,11888,11889,11890,11891,11892,11893,11894,11895,11896,11897, #11824
11898,11899,11900,11901,11902,11903,11904,11905,11906,11907,11908,11909,11910,11911,11912,11913, #11840
11914,11915,4975,11916,11917,11918,11919,11920,11921,11922,11923,11924,11925,11926,11927,11928, #11856
11929,11930,11931,11932,11933,11934,11935,11936,11937,11938,11939,11940,11941,11942,11943,11944, #11872
11945,11946,11947,11948,11949,4976,11950,11951,11952,11953,11954,11955,11956,11957,11958,11959, #11888
11960,11961,11962,11963,11964,11965,11966,11967,11968,11969,11970,11971,11972,11973,11974,11975, #11904
11976,11977,11978,11979,11980,11981,11982,11983,11984,11985,11986,11987,4196,11988,11989,11990, #11920
11991,11992,4977,11993,11994,11995,11996,11997,11998,11999,12000,12001,12002,12003,12004,12005, #11936
12006,12007,12008,12009,12010,12011,12012,12013,12014,12015,12016,12017,12018,12019,12020,12021, #11952
12022,12023,12024,12025,12026,12027,12028,12029,12030,12031,12032,12033,12034,12035,12036,12037, #11968
12038,12039,12040,12041,12042,12043,12044,12045,12046,12047,12048,12049,12050,12051,12052,12053, #11984
12054,12055,12056,12057,12058,12059,12060,12061,4978,12062,12063,12064,12065,12066,12067,12068, #12000
12069,12070,12071,12072,12073,12074,12075,12076,12077,12078,12079,12080,12081,12082,12083,12084, #12016
12085,12086,12087,12088,12089,12090,12091,12092,12093,12094,12095,12096,12097,12098,12099,12100, #12032
12101,12102,12103,12104,12105,12106,12107,12108,12109,12110,12111,12112,12113,12114,12115,12116, #12048
12117,12118,12119,12120,12121,12122,12123,4979,12124,12125,12126,12127,12128,4197,12129,12130, #12064
12131,12132,12133,12134,12135,12136,12137,12138,12139,12140,12141,12142,12143,12144,12145,12146, #12080
12147,12148,12149,12150,12151,12152,12153,12154,4980,12155,12156,12157,12158,12159,12160,4494, #12096
12161,12162,12163,12164,3811,12165,12166,12167,12168,12169,4495,12170,12171,4496,12172,12173, #12112
12174,12175,12176,3812,12177,12178,12179,12180,12181,12182,12183,12184,12185,12186,12187,12188, #12128
12189,12190,12191,12192,12193,12194,12195,12196,12197,12198,12199,12200,12201,12202,12203,12204, #12144
12205,12206,12207,12208,12209,12210,12211,12212,12213,12214,12215,12216,12217,12218,12219,12220, #12160
12221,4981,12222,12223,12224,12225,12226,12227,12228,12229,12230,12231,12232,12233,12234,12235, #12176
4982,12236,12237,12238,12239,12240,12241,12242,12243,12244,12245,4983,12246,12247,12248,12249, #12192
4984,12250,12251,12252,12253,12254,12255,12256,12257,12258,12259,12260,12261,12262,12263,12264, #12208
4985,12265,4497,12266,12267,12268,12269,12270,12271,12272,12273,12274,12275,12276,12277,12278, #12224
12279,12280,12281,12282,12283,12284,12285,12286,12287,4986,12288,12289,12290,12291,12292,12293, #12240
12294,12295,12296,2473,12297,12298,12299,12300,12301,12302,12303,12304,12305,12306,12307,12308, #12256
12309,12310,12311,12312,12313,12314,12315,12316,12317,12318,12319,3963,12320,12321,12322,12323, #12272
12324,12325,12326,12327,12328,12329,12330,12331,12332,4987,12333,12334,12335,12336,12337,12338, #12288
12339,12340,12341,12342,12343,12344,12345,12346,12347,12348,12349,12350,12351,12352,12353,12354, #12304
12355,12356,12357,12358,12359,3964,12360,12361,12362,12363,12364,12365,12366,12367,12368,12369, #12320
12370,3965,12371,12372,12373,12374,12375,12376,12377,12378,12379,12380,12381,12382,12383,12384, #12336
12385,12386,12387,12388,12389,12390,12391,12392,12393,12394,12395,12396,12397,12398,12399,12400, #12352
12401,12402,12403,12404,12405,12406,12407,12408,4988,12409,12410,12411,12412,12413,12414,12415, #12368
12416,12417,12418,12419,12420,12421,12422,12423,12424,12425,12426,12427,12428,12429,12430,12431, #12384
12432,12433,12434,12435,12436,12437,12438,3554,12439,12440,12441,12442,12443,12444,12445,12446, #12400
12447,12448,12449,12450,12451,12452,12453,12454,12455,12456,12457,12458,12459,12460,12461,12462, #12416
12463,12464,4989,12465,12466,12467,12468,12469,12470,12471,12472,12473,12474,12475,12476,12477, #12432
12478,12479,12480,4990,12481,12482,12483,12484,12485,12486,12487,12488,12489,4498,12490,12491, #12448
12492,12493,12494,12495,12496,12497,12498,12499,12500,12501,12502,12503,12504,12505,12506,12507, #12464
12508,12509,12510,12511,12512,12513,12514,12515,12516,12517,12518,12519,12520,12521,12522,12523, #12480
12524,12525,12526,12527,12528,12529,12530,12531,12532,12533,12534,12535,12536,12537,12538,12539, #12496
12540,12541,12542,12543,12544,12545,12546,12547,12548,12549,12550,12551,4991,12552,12553,12554, #12512
12555,12556,12557,12558,12559,12560,12561,12562,12563,12564,12565,12566,12567,12568,12569,12570, #12528
12571,12572,12573,12574,12575,12576,12577,12578,3036,12579,12580,12581,12582,12583,3966,12584, #12544
12585,12586,12587,12588,12589,12590,12591,12592,12593,12594,12595,12596,12597,12598,12599,12600, #12560
12601,12602,12603,12604,12605,12606,12607,12608,12609,12610,12611,12612,12613,12614,12615,12616, #12576
12617,12618,12619,12620,12621,12622,12623,12624,12625,12626,12627,12628,12629,12630,12631,12632, #12592
12633,12634,12635,12636,12637,12638,12639,12640,12641,12642,12643,12644,12645,12646,4499,12647, #12608
12648,12649,12650,12651,12652,12653,12654,12655,12656,12657,12658,12659,12660,12661,12662,12663, #12624
12664,12665,12666,12667,12668,12669,12670,12671,12672,12673,12674,12675,12676,12677,12678,12679, #12640
12680,12681,12682,12683,12684,12685,12686,12687,12688,12689,12690,12691,12692,12693,12694,12695, #12656
12696,12697,12698,4992,12699,12700,12701,12702,12703,12704,12705,12706,12707,12708,12709,12710, #12672
12711,12712,12713,12714,12715,12716,12717,12718,12719,12720,12721,12722,12723,12724,12725,12726, #12688
12727,12728,12729,12730,12731,12732,12733,12734,12735,12736,12737,12738,12739,12740,12741,12742, #12704
12743,12744,12745,12746,12747,12748,12749,12750,12751,12752,12753,12754,12755,12756,12757,12758, #12720
12759,12760,12761,12762,12763,12764,12765,12766,12767,12768,12769,12770,12771,12772,12773,12774, #12736
12775,12776,12777,12778,4993,2175,12779,12780,12781,12782,12783,12784,12785,12786,4500,12787, #12752
12788,12789,12790,12791,12792,12793,12794,12795,12796,12797,12798,12799,12800,12801,12802,12803, #12768
12804,12805,12806,12807,12808,12809,12810,12811,12812,12813,12814,12815,12816,12817,12818,12819, #12784
12820,12821,12822,12823,12824,12825,12826,4198,3967,12827,12828,12829,12830,12831,12832,12833, #12800
12834,12835,12836,12837,12838,12839,12840,12841,12842,12843,12844,12845,12846,12847,12848,12849, #12816
12850,12851,12852,12853,12854,12855,12856,12857,12858,12859,12860,12861,4199,12862,12863,12864, #12832
12865,12866,12867,12868,12869,12870,12871,12872,12873,12874,12875,12876,12877,12878,12879,12880, #12848
12881,12882,12883,12884,12885,12886,12887,4501,12888,12889,12890,12891,12892,12893,12894,12895, #12864
12896,12897,12898,12899,12900,12901,12902,12903,12904,12905,12906,12907,12908,12909,12910,12911, #12880
12912,4994,12913,12914,12915,12916,12917,12918,12919,12920,12921,12922,12923,12924,12925,12926, #12896
12927,12928,12929,12930,12931,12932,12933,12934,12935,12936,12937,12938,12939,12940,12941,12942, #12912
12943,12944,12945,12946,12947,12948,12949,12950,12951,12952,12953,12954,12955,12956,1772,12957, #12928
12958,12959,12960,12961,12962,12963,12964,12965,12966,12967,12968,12969,12970,12971,12972,12973, #12944
12974,12975,12976,12977,12978,12979,12980,12981,12982,12983,12984,12985,12986,12987,12988,12989, #12960
12990,12991,12992,12993,12994,12995,12996,12997,4502,12998,4503,12999,13000,13001,13002,13003, #12976
4504,13004,13005,13006,13007,13008,13009,13010,13011,13012,13013,13014,13015,13016,13017,13018, #12992
13019,13020,13021,13022,13023,13024,13025,13026,13027,13028,13029,3449,13030,13031,13032,13033, #13008
13034,13035,13036,13037,13038,13039,13040,13041,13042,13043,13044,13045,13046,13047,13048,13049, #13024
13050,13051,13052,13053,13054,13055,13056,13057,13058,13059,13060,13061,13062,13063,13064,13065, #13040
13066,13067,13068,13069,13070,13071,13072,13073,13074,13075,13076,13077,13078,13079,13080,13081, #13056
13082,13083,13084,13085,13086,13087,13088,13089,13090,13091,13092,13093,13094,13095,13096,13097, #13072
13098,13099,13100,13101,13102,13103,13104,13105,13106,13107,13108,13109,13110,13111,13112,13113, #13088
13114,13115,13116,13117,13118,3968,13119,4995,13120,13121,13122,13123,13124,13125,13126,13127, #13104
4505,13128,13129,13130,13131,13132,13133,13134,4996,4506,13135,13136,13137,13138,13139,4997, #13120
13140,13141,13142,13143,13144,13145,13146,13147,13148,13149,13150,13151,13152,13153,13154,13155, #13136
13156,13157,13158,13159,4998,13160,13161,13162,13163,13164,13165,13166,13167,13168,13169,13170, #13152
13171,13172,13173,13174,13175,13176,4999,13177,13178,13179,13180,13181,13182,13183,13184,13185, #13168
13186,13187,13188,13189,13190,13191,13192,13193,13194,13195,13196,13197,13198,13199,13200,13201, #13184
13202,13203,13204,13205,13206,5000,13207,13208,13209,13210,13211,13212,13213,13214,13215,13216, #13200
13217,13218,13219,13220,13221,13222,13223,13224,13225,13226,13227,4200,5001,13228,13229,13230, #13216
13231,13232,13233,13234,13235,13236,13237,13238,13239,13240,3969,13241,13242,13243,13244,3970, #13232
13245,13246,13247,13248,13249,13250,13251,13252,13253,13254,13255,13256,13257,13258,13259,13260, #13248
13261,13262,13263,13264,13265,13266,13267,13268,3450,13269,13270,13271,13272,13273,13274,13275, #13264
13276,5002,13277,13278,13279,13280,13281,13282,13283,13284,13285,13286,13287,13288,13289,13290, #13280
13291,13292,13293,13294,13295,13296,13297,13298,13299,13300,13301,13302,3813,13303,13304,13305, #13296
13306,13307,13308,13309,13310,13311,13312,13313,13314,13315,13316,13317,13318,13319,13320,13321, #13312
13322,13323,13324,13325,13326,13327,13328,4507,13329,13330,13331,13332,13333,13334,13335,13336, #13328
13337,13338,13339,13340,13341,5003,13342,13343,13344,13345,13346,13347,13348,13349,13350,13351, #13344
13352,13353,13354,13355,13356,13357,13358,13359,13360,13361,13362,13363,13364,13365,13366,13367, #13360
5004,13368,13369,13370,13371,13372,13373,13374,13375,13376,13377,13378,13379,13380,13381,13382, #13376
13383,13384,13385,13386,13387,13388,13389,13390,13391,13392,13393,13394,13395,13396,13397,13398, #13392
13399,13400,13401,13402,13403,13404,13405,13406,13407,13408,13409,13410,13411,13412,13413,13414, #13408
13415,13416,13417,13418,13419,13420,13421,13422,13423,13424,13425,13426,13427,13428,13429,13430, #13424
13431,13432,4508,13433,13434,13435,4201,13436,13437,13438,13439,13440,13441,13442,13443,13444, #13440
13445,13446,13447,13448,13449,13450,13451,13452,13453,13454,13455,13456,13457,5005,13458,13459, #13456
13460,13461,13462,13463,13464,13465,13466,13467,13468,13469,13470,4509,13471,13472,13473,13474, #13472
13475,13476,13477,13478,13479,13480,13481,13482,13483,13484,13485,13486,13487,13488,13489,13490, #13488
13491,13492,13493,13494,13495,13496,13497,13498,13499,13500,13501,13502,13503,13504,13505,13506, #13504
13507,13508,13509,13510,13511,13512,13513,13514,13515,13516,13517,13518,13519,13520,13521,13522, #13520
13523,13524,13525,13526,13527,13528,13529,13530,13531,13532,13533,13534,13535,13536,13537,13538, #13536
13539,13540,13541,13542,13543,13544,13545,13546,13547,13548,13549,13550,13551,13552,13553,13554, #13552
13555,13556,13557,13558,13559,13560,13561,13562,13563,13564,13565,13566,13567,13568,13569,13570, #13568
13571,13572,13573,13574,13575,13576,13577,13578,13579,13580,13581,13582,13583,13584,13585,13586, #13584
13587,13588,13589,13590,13591,13592,13593,13594,13595,13596,13597,13598,13599,13600,13601,13602, #13600
13603,13604,13605,13606,13607,13608,13609,13610,13611,13612,13613,13614,13615,13616,13617,13618, #13616
13619,13620,13621,13622,13623,13624,13625,13626,13627,13628,13629,13630,13631,13632,13633,13634, #13632
13635,13636,13637,13638,13639,13640,13641,13642,5006,13643,13644,13645,13646,13647,13648,13649, #13648
13650,13651,5007,13652,13653,13654,13655,13656,13657,13658,13659,13660,13661,13662,13663,13664, #13664
13665,13666,13667,13668,13669,13670,13671,13672,13673,13674,13675,13676,13677,13678,13679,13680, #13680
13681,13682,13683,13684,13685,13686,13687,13688,13689,13690,13691,13692,13693,13694,13695,13696, #13696
13697,13698,13699,13700,13701,13702,13703,13704,13705,13706,13707,13708,13709,13710,13711,13712, #13712
13713,13714,13715,13716,13717,13718,13719,13720,13721,13722,13723,13724,13725,13726,13727,13728, #13728
13729,13730,13731,13732,13733,13734,13735,13736,13737,13738,13739,13740,13741,13742,13743,13744, #13744
13745,13746,13747,13748,13749,13750,13751,13752,13753,13754,13755,13756,13757,13758,13759,13760, #13760
13761,13762,13763,13764,13765,13766,13767,13768,13769,13770,13771,13772,13773,13774,3273,13775, #13776
13776,13777,13778,13779,13780,13781,13782,13783,13784,13785,13786,13787,13788,13789,13790,13791, #13792
13792,13793,13794,13795,13796,13797,13798,13799,13800,13801,13802,13803,13804,13805,13806,13807, #13808
13808,13809,13810,13811,13812,13813,13814,13815,13816,13817,13818,13819,13820,13821,13822,13823, #13824
13824,13825,13826,13827,13828,13829,13830,13831,13832,13833,13834,13835,13836,13837,13838,13839, #13840
13840,13841,13842,13843,13844,13845,13846,13847,13848,13849,13850,13851,13852,13853,13854,13855, #13856
13856,13857,13858,13859,13860,13861,13862,13863,13864,13865,13866,13867,13868,13869,13870,13871, #13872
13872,13873,13874,13875,13876,13877,13878,13879,13880,13881,13882,13883,13884,13885,13886,13887, #13888
13888,13889,13890,13891,13892,13893,13894,13895,13896,13897,13898,13899,13900,13901,13902,13903, #13904
13904,13905,13906,13907,13908,13909,13910,13911,13912,13913,13914,13915,13916,13917,13918,13919, #13920
13920,13921,13922,13923,13924,13925,13926,13927,13928,13929,13930,13931,13932,13933,13934,13935, #13936
13936,13937,13938,13939,13940,13941,13942,13943,13944,13945,13946,13947,13948,13949,13950,13951, #13952
13952,13953,13954,13955,13956,13957,13958,13959,13960,13961,13962,13963,13964,13965,13966,13967, #13968
13968,13969,13970,13971,13972) #13973
# flake8: noqa
|
mit
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
3,
13123,
21,
9857,
1817,
199,
3,
701,
377,
5789,
20444,
1159,
603,
460,
285,
262,
27724,
23193,
1849,
1097,
382,
199,
3,
665,
1014,
921,
1544,
14,
8654,
14,
8122,
26,
2835,
15,
10333,
82,
3133,
199,
3,
199,
3,
7960,
221,
10541,
378,
14,
23814,
2976,
199,
3,
7633,
221,
10541,
378,
14,
1641,
22740,
199,
3,
10574,
221,
10541,
378,
14,
1342,
22740,
199,
3,
6619,
10541,
378,
14,
1407,
8188,
199,
3,
18427,
10541,
378,
14,
2576,
16793,
199,
3,
199,
3,
473,
21245,
11839,
820,
32736,
275,
378,
14,
1342,
22740,
7985,
17,
13,
16,
14,
1342,
22740,
9,
275,
18,
14,
2905,
199,
3,
9571,
11839,
820,
425,
275,
10574,
7985,
1477,
614,
13,
7736,
23397,
16,
14,
7320,
199,
3,
199,
3,
29267,
11839,
820,
32736,
3595,
5661,
5,
402,
473,
21245,
1373,
12,
5139,
8298,
10948,
2419,
820,
4564,
199,
199,
18643,
21,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
275,
378,
14,
2194,
199,
199,
3,
1610,
370,
481,
2103,
4738,
1817,
199,
18643,
21,
63,
8723,
63,
4305,
275,
959,
11452,
199,
199,
7279,
21,
18139,
13875,
4738,
275,
334,
2043,
413,
12,
1085,
614,
12,
1046,
1690,
12,
5450,
12,
1079,
2192,
12,
413,
2905,
12,
257,
1749,
12,
221,
18051,
12,
257,
1227,
12,
5783,
24,
12,
413,
1138,
12,
19328,
12,
1344,
2835,
12,
713,
1367,
12,
1651,
2025,
12,
16814,
12,
327,
257,
3193,
199,
1703,
1079,
12,
221,
9404,
12,
708,
1342,
12,
499,
2976,
12,
221,
14646,
12,
221,
10868,
12,
18,
7636,
12,
221,
3193,
12,
1398,
2466,
12,
9252,
23,
12,
31989,
12,
1227,
1427,
12,
1355,
3172,
12,
221,
7875,
12,
1082,
2869,
12,
1479,
2481,
12,
327,
257,
4337,
199,
845,
2905,
12,
1355,
2819,
12,
1153,
1400,
12,
2260,
996,
12,
32321,
12,
1081,
1046,
12,
11485,
12,
959,
2710,
12,
650,
2976,
12,
1167,
772,
12,
257,
1695,
12,
14785,
12,
221,
13713,
12,
2322,
709,
12,
5783,
25,
12,
1167,
708,
12,
327,
257,
9615,
523,
13668,
12,
8216,
16,
12,
8216,
17,
12,
650,
1196,
12,
975,
1079,
12,
221,
13098,
12,
26485,
12,
413,
1427,
12,
20,
11341,
12,
1194,
1196,
12,
1079,
1257,
12,
8216,
18,
12,
10156,
21,
12,
1216,
3328,
12,
18565,
12,
29736,
12,
327,
257,
5049,
199,
1344,
2564,
12,
257,
650,
12,
221,
1616,
12,
1355,
2898,
12,
1079,
3172,
12,
221,
7349,
12,
1465,
1555,
12,
845,
1276,
12,
11125,
22,
12,
30614,
12,
10513,
19,
12,
21334,
12,
708,
2194,
12,
17,
4288,
12,
650,
713,
12,
8216,
19,
12,
327,
257,
5939,
199,
2322,
845,
12,
1165,
2528,
12,
959,
1780,
12,
27210,
12,
1227,
2564,
12,
8216,
20,
12,
31308,
12,
1167,
1046,
12,
25442,
12,
26761,
12,
1398,
2417,
12,
221,
8177,
12,
10156,
22,
12,
708,
966,
12,
221,
5049,
12,
1227,
966,
12,
327,
257,
15580,
199,
8216,
21,
12,
821,
614,
12,
1167,
1138,
12,
1167,
2277,
12,
29710,
12,
7155,
17,
12,
5049,
21,
12,
5049,
17,
12,
975,
1690,
12,
8216,
22,
12,
1082,
2528,
12,
650,
1401,
12,
221,
15323,
12,
841,
1690,
12,
8216,
23,
12,
221,
5939,
12,
327,
221,
20240,
199,
1227,
1216,
12,
27077,
12,
708,
1717,
12,
1046,
1643,
12,
499,
2766,
12,
1749,
1355,
12,
709,
2942,
12,
1479,
1477,
12,
1520,
1367,
12,
1079,
2167,
12,
709,
2635,
12,
1082,
2481,
12,
841,
1887,
12,
221,
14610,
12,
1398,
1555,
12,
959,
3328,
12,
327,
221,
7960,
199,
31420,
12,
1165,
2534,
12,
841,
3172,
12,
22560,
12,
1165,
1276,
12,
1085,
1602,
12,
221,
5212,
12,
221,
5238,
12,
1398,
1299,
12,
25956,
12,
5939,
22,
12,
1085,
1876,
12,
1520,
1082,
12,
1165,
1344,
12,
1082,
1477,
12,
13576,
12,
327,
221,
21771,
199,
8806,
21,
12,
975,
1780,
12,
32609,
12,
959,
1401,
12,
1398,
1780,
12,
1227,
1299,
12,
8216,
24,
12,
650,
1167,
12,
969,
1717,
12,
8375,
25,
12,
6886,
21,
12,
959,
1079,
12,
10638,
25,
12,
499,
2905,
12,
2322,
713,
12,
650,
1427,
12,
327,
221,
21235,
199,
27874,
12,
221,
9137,
12,
1465,
975,
12,
969,
1703,
12,
1227,
2766,
12,
221,
4119,
12,
1749,
1690,
12,
709,
1020,
12,
2299,
19,
12,
221,
3388,
12,
1194,
2953,
12,
413,
2564,
12,
959,
708,
12,
1196,
975,
12,
8216,
25,
12,
1520,
708,
12,
327,
221,
27827,
199,
969,
2114,
12,
2260,
966,
12,
969,
845,
12,
1079,
1165,
12,
708,
1690,
12,
221,
5661,
12,
1789,
1196,
12,
709,
1367,
12,
24073,
12,
650,
1020,
12,
650,
2564
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
3,
13123,
21,
9857,
1817,
199,
3,
701,
377,
5789,
20444,
1159,
603,
460,
285,
262,
27724,
23193,
1849,
1097,
382,
199,
3,
665,
1014,
921,
1544,
14,
8654,
14,
8122,
26,
2835,
15,
10333,
82,
3133,
199,
3,
199,
3,
7960,
221,
10541,
378,
14,
23814,
2976,
199,
3,
7633,
221,
10541,
378,
14,
1641,
22740,
199,
3,
10574,
221,
10541,
378,
14,
1342,
22740,
199,
3,
6619,
10541,
378,
14,
1407,
8188,
199,
3,
18427,
10541,
378,
14,
2576,
16793,
199,
3,
199,
3,
473,
21245,
11839,
820,
32736,
275,
378,
14,
1342,
22740,
7985,
17,
13,
16,
14,
1342,
22740,
9,
275,
18,
14,
2905,
199,
3,
9571,
11839,
820,
425,
275,
10574,
7985,
1477,
614,
13,
7736,
23397,
16,
14,
7320,
199,
3,
199,
3,
29267,
11839,
820,
32736,
3595,
5661,
5,
402,
473,
21245,
1373,
12,
5139,
8298,
10948,
2419,
820,
4564,
199,
199,
18643,
21,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
275,
378,
14,
2194,
199,
199,
3,
1610,
370,
481,
2103,
4738,
1817,
199,
18643,
21,
63,
8723,
63,
4305,
275,
959,
11452,
199,
199,
7279,
21,
18139,
13875,
4738,
275,
334,
2043,
413,
12,
1085,
614,
12,
1046,
1690,
12,
5450,
12,
1079,
2192,
12,
413,
2905,
12,
257,
1749,
12,
221,
18051,
12,
257,
1227,
12,
5783,
24,
12,
413,
1138,
12,
19328,
12,
1344,
2835,
12,
713,
1367,
12,
1651,
2025,
12,
16814,
12,
327,
257,
3193,
199,
1703,
1079,
12,
221,
9404,
12,
708,
1342,
12,
499,
2976,
12,
221,
14646,
12,
221,
10868,
12,
18,
7636,
12,
221,
3193,
12,
1398,
2466,
12,
9252,
23,
12,
31989,
12,
1227,
1427,
12,
1355,
3172,
12,
221,
7875,
12,
1082,
2869,
12,
1479,
2481,
12,
327,
257,
4337,
199,
845,
2905,
12,
1355,
2819,
12,
1153,
1400,
12,
2260,
996,
12,
32321,
12,
1081,
1046,
12,
11485,
12,
959,
2710,
12,
650,
2976,
12,
1167,
772,
12,
257,
1695,
12,
14785,
12,
221,
13713,
12,
2322,
709,
12,
5783,
25,
12,
1167,
708,
12,
327,
257,
9615,
523,
13668,
12,
8216,
16,
12,
8216,
17,
12,
650,
1196,
12,
975,
1079,
12,
221,
13098,
12,
26485,
12,
413,
1427,
12,
20,
11341,
12,
1194,
1196,
12,
1079,
1257,
12,
8216,
18,
12,
10156,
21,
12,
1216,
3328,
12,
18565,
12,
29736,
12,
327,
257,
5049,
199,
1344,
2564,
12,
257,
650,
12,
221,
1616,
12,
1355,
2898,
12,
1079,
3172,
12,
221,
7349,
12,
1465,
1555,
12,
845,
1276,
12,
11125,
22,
12,
30614,
12,
10513,
19,
12,
21334,
12,
708,
2194,
12,
17,
4288,
12,
650,
713,
12,
8216,
19,
12,
327,
257,
5939,
199,
2322,
845,
12,
1165,
2528,
12,
959,
1780,
12,
27210,
12,
1227,
2564,
12,
8216,
20,
12,
31308,
12,
1167,
1046,
12,
25442,
12,
26761,
12,
1398,
2417,
12,
221,
8177,
12,
10156,
22,
12,
708,
966,
12,
221,
5049,
12,
1227,
966,
12,
327,
257,
15580,
199,
8216,
21,
12,
821,
614,
12,
1167,
1138,
12,
1167,
2277,
12,
29710,
12,
7155,
17,
12,
5049,
21,
12,
5049,
17,
12,
975,
1690,
12,
8216,
22,
12,
1082,
2528,
12,
650,
1401,
12,
221,
15323,
12,
841,
1690,
12,
8216,
23,
12,
221,
5939,
12,
327,
221,
20240,
199,
1227,
1216,
12,
27077,
12,
708,
1717,
12,
1046,
1643,
12,
499,
2766,
12,
1749,
1355,
12,
709,
2942,
12,
1479,
1477,
12,
1520,
1367,
12,
1079,
2167,
12,
709,
2635,
12,
1082,
2481,
12,
841,
1887,
12,
221,
14610,
12,
1398,
1555,
12,
959,
3328,
12,
327,
221,
7960,
199,
31420,
12,
1165,
2534,
12,
841,
3172,
12,
22560,
12,
1165,
1276,
12,
1085,
1602,
12,
221,
5212,
12,
221,
5238,
12,
1398,
1299,
12,
25956,
12,
5939,
22,
12,
1085,
1876,
12,
1520,
1082,
12,
1165,
1344,
12,
1082,
1477,
12,
13576,
12,
327,
221,
21771,
199,
8806,
21,
12,
975,
1780,
12,
32609,
12,
959,
1401,
12,
1398,
1780,
12,
1227,
1299,
12,
8216,
24,
12,
650,
1167,
12,
969,
1717,
12,
8375,
25,
12,
6886,
21,
12,
959,
1079,
12,
10638,
25,
12,
499,
2905,
12,
2322,
713,
12,
650,
1427,
12,
327,
221,
21235,
199,
27874,
12,
221,
9137,
12,
1465,
975,
12,
969,
1703,
12,
1227,
2766,
12,
221,
4119,
12,
1749,
1690,
12,
709,
1020,
12,
2299,
19,
12,
221,
3388,
12,
1194,
2953,
12,
413,
2564,
12,
959,
708,
12,
1196,
975,
12,
8216,
25,
12,
1520,
708,
12,
327,
221,
27827,
199,
969,
2114,
12,
2260,
966,
12,
969,
845,
12,
1079,
1165,
12,
708,
1690,
12,
221,
5661,
12,
1789,
1196,
12,
709,
1367,
12,
24073,
12,
650,
1020,
12,
650,
2564,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
iivic/BoiseStateX
|
lms/djangoapps/instructor/management/commands/openended_stats.py
|
86
|
5361
|
"""
Command to get statistics about open ended problems.
"""
import csv
import time
from django.core.management.base import BaseCommand
from optparse import make_option
from xmodule.modulestore.django import modulestore
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from xmodule.open_ended_grading_classes.openendedchild import OpenEndedChild
from courseware.courses import get_course
from courseware.models import StudentModule
from student.models import anonymous_id_for_user, CourseEnrollment
from instructor.utils import get_module_for_student
class Command(BaseCommand):
"""
Command to get statistics about open ended problems.
"""
help = "Usage: openended_stats <course_id> <problem_location> --task-number=<task_number>\n"
option_list = BaseCommand.option_list + (
make_option('--task-number',
type='int', default=0,
help="Task number to get statistics about."),
)
def handle(self, *args, **options):
"""Handler for command."""
task_number = options['task_number']
if len(args) == 2:
course_id = SlashSeparatedCourseKey.from_deprecated_string(args[0])
usage_key = course_id.make_usage_key_from_deprecated_string(args[1])
else:
print self.help
return
try:
course = get_course(course_id)
except ValueError as err:
print err
return
descriptor = modulestore().get_item(usage_key, depth=0)
if descriptor is None:
print "Location {0} not found in course".format(usage_key)
return
try:
enrolled_students = CourseEnrollment.objects.users_enrolled_in(course_id)
print "Total students enrolled in {0}: {1}".format(course_id, enrolled_students.count())
calculate_task_statistics(enrolled_students, course, usage_key, task_number)
except KeyboardInterrupt:
print "\nOperation Cancelled"
def calculate_task_statistics(students, course, location, task_number, write_to_file=True):
"""Print stats of students."""
stats = {
OpenEndedChild.INITIAL: 0,
OpenEndedChild.ASSESSING: 0,
OpenEndedChild.POST_ASSESSMENT: 0,
OpenEndedChild.DONE: 0
}
students_with_saved_answers = []
students_with_ungraded_submissions = [] # pylint: disable=invalid-name
students_with_graded_submissions = [] # pylint: disable=invalid-name
students_with_no_state = []
student_modules = StudentModule.objects.filter(module_state_key=location, student__in=students).order_by('student')
print "Total student modules: {0}".format(student_modules.count())
for index, student_module in enumerate(student_modules):
if index % 100 == 0:
print "--- {0} students processed ---".format(index)
student = student_module.student
print "{0}:{1}".format(student.id, student.username)
module = get_module_for_student(student, location, course=course)
if module is None:
print " WARNING: No state found"
students_with_no_state.append(student)
continue
latest_task = module.child_module.get_task_number(task_number)
if latest_task is None:
print " No task state found"
students_with_no_state.append(student)
continue
task_state = latest_task.child_state
stats[task_state] += 1
print " State: {0}".format(task_state)
if task_state == OpenEndedChild.INITIAL:
if latest_task.stored_answer is not None:
students_with_saved_answers.append(student)
elif task_state == OpenEndedChild.ASSESSING:
students_with_ungraded_submissions.append(student)
elif task_state == OpenEndedChild.POST_ASSESSMENT or task_state == OpenEndedChild.DONE:
students_with_graded_submissions.append(student)
print "----------------------------------"
print "Time: {0}".format(time.strftime("%Y %b %d %H:%M:%S +0000", time.gmtime()))
print "Course: {0}".format(course.id)
print "Location: {0}".format(location)
print "No state: {0}".format(len(students_with_no_state))
print "Initial State: {0}".format(stats[OpenEndedChild.INITIAL] - len(students_with_saved_answers))
print "Saved answers: {0}".format(len(students_with_saved_answers))
print "Submitted answers: {0}".format(stats[OpenEndedChild.ASSESSING])
print "Received grades: {0}".format(stats[OpenEndedChild.POST_ASSESSMENT] + stats[OpenEndedChild.DONE])
print "----------------------------------"
if write_to_file:
filename = "stats.{0}.{1}".format(location.course, location.name)
time_stamp = time.strftime("%Y%m%d-%H%M%S")
with open('{0}.{1}.csv'.format(filename, time_stamp), 'wb') as csv_file:
writer = csv.writer(csv_file, delimiter=' ', quoting=csv.QUOTE_MINIMAL)
for student in students_with_ungraded_submissions:
writer.writerow(("ungraded", student.id, anonymous_id_for_user(student, None), student.username))
for student in students_with_graded_submissions:
writer.writerow(("graded", student.id, anonymous_id_for_user(student, None), student.username))
return stats
|
agpl-3.0
|
[
624,
199,
3110,
370,
664,
11076,
3595,
1551,
22480,
8826,
14,
199,
624,
199,
646,
7392,
199,
646,
900,
199,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
199,
504,
8691,
492,
1852,
63,
1422,
199,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
15058,
63,
1612,
14,
8268,
14,
8022,
492,
30687,
199,
504,
9872,
14,
1490,
63,
8960,
63,
16050,
63,
2888,
14,
1490,
8960,
1739,
492,
3232,
32615,
3493,
199,
199,
504,
20736,
14,
11653,
492,
664,
63,
1972,
199,
504,
20736,
14,
992,
492,
17246,
2377,
199,
504,
6474,
14,
992,
492,
16535,
63,
344,
63,
509,
63,
751,
12,
18946,
199,
199,
504,
17724,
14,
1208,
492,
664,
63,
578,
63,
509,
63,
5500,
421,
199,
533,
5817,
8,
25150,
304,
272,
408,
272,
5817,
370,
664,
11076,
3595,
1551,
22480,
8826,
14,
272,
408,
339,
1720,
275,
298,
7692,
26,
1551,
8960,
63,
3200,
665,
1972,
63,
344,
30,
665,
6462,
63,
1985,
30,
1553,
1765,
13,
1955,
18987,
1765,
63,
1955,
3072,
78,
2,
339,
945,
63,
513,
275,
22239,
14,
1422,
63,
513,
435,
334,
267,
1852,
63,
1422,
4517,
1765,
13,
1955,
297,
490,
730,
534,
442,
297,
849,
29,
16,
12,
490,
1720,
628,
4476,
1329,
370,
664,
11076,
3595,
7651,
272,
776,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
267,
408,
2461,
367,
1414,
1041,
398,
2120,
63,
1955,
275,
1511,
459,
1765,
63,
1955,
418,
398,
340,
822,
8,
589,
9,
508,
499,
26,
288,
2518,
63,
344,
275,
30687,
14,
504,
63,
6667,
63,
875,
8,
589,
59,
16,
566,
288,
4503,
63,
498,
275,
2518,
63,
344,
14,
1875,
63,
3807,
63,
498,
63,
504,
63,
6667,
63,
875,
8,
589,
59,
17,
566,
267,
587,
26,
288,
870,
291,
14,
3437,
288,
372,
398,
862,
26,
288,
2518,
275,
664,
63,
1972,
8,
1972,
63,
344,
9,
267,
871,
1722,
465,
2329,
26,
288,
870,
2329,
288,
372,
398,
5872,
275,
10996,
1252,
362,
63,
1053,
8,
3807,
63,
498,
12,
5818,
29,
16,
9,
267,
340,
5872,
365,
488,
26,
288,
870,
298,
6592,
469,
16,
93,
440,
1911,
315,
2518,
1674,
908,
8,
3807,
63,
498,
9,
288,
372,
398,
862,
26,
288,
26802,
63,
17921,
275,
18946,
14,
1462,
14,
3707,
63,
22428,
63,
262,
8,
1972,
63,
344,
9,
288,
870,
298,
7316,
18557,
26802,
315,
469,
16,
9160,
469,
17,
5469,
908,
8,
1972,
63,
344,
12,
26802,
63,
17921,
14,
835,
1012,
953,
8671,
63,
1765,
63,
13724,
8,
22428,
63,
17921,
12,
2518,
12,
4503,
63,
498,
12,
2120,
63,
1955,
9,
398,
871,
13483,
26,
288,
870,
1867,
78,
6044,
28374,
1146,
2,
421,
199,
318,
8671,
63,
1765,
63,
13724,
8,
17921,
12,
2518,
12,
2909,
12,
2120,
63,
1955,
12,
2218,
63,
475,
63,
493,
29,
549,
304,
272,
408,
5375,
5020,
402,
18557,
1041,
339,
5020,
275,
469,
267,
3232,
32615,
3493,
14,
13768,
26,
378,
12,
267,
3232,
32615,
3493,
14,
3755,
1608,
1206,
26,
378,
12,
267,
3232,
32615,
3493,
14,
4030,
63,
3755,
1608,
4479,
26,
378,
12,
267,
3232,
32615,
3493,
14,
22162,
26,
378,
272,
789,
339,
18557,
63,
1045,
63,
8420,
63,
13379,
275,
942,
272,
18557,
63,
1045,
63,
324,
13688,
63,
29752,
275,
942,
221,
327,
4287,
26,
3507,
29,
3197,
13,
354,
272,
18557,
63,
1045,
63,
13688,
63,
29752,
275,
942,
221,
327,
4287,
26,
3507,
29,
3197,
13,
354,
272,
18557,
63,
1045,
63,
889,
63,
929,
275,
942,
339,
6474,
63,
3112,
275,
17246,
2377,
14,
1462,
14,
1541,
8,
578,
63,
929,
63,
498,
29,
1985,
12,
6474,
363,
262,
29,
17921,
680,
1648,
63,
991,
360,
5500,
358,
272,
870,
298,
7316,
6474,
4621,
26,
469,
16,
5469,
908,
8,
5500,
63,
3112,
14,
835,
1012,
339,
367,
1478,
12,
6474,
63,
578,
315,
3874,
8,
5500,
63,
3112,
304,
267,
340,
1478,
450,
2948,
508,
378,
26,
288,
870,
298,
2595,
469,
16,
93,
18557,
7686,
10894,
1674,
908,
8,
1080,
9,
398,
6474,
275,
6474,
63,
578,
14,
5500,
267,
870,
5310,
16,
16495,
17,
5469,
908,
8,
5500,
14,
344,
12,
6474,
14,
2473,
9,
398,
859,
275,
664,
63,
578,
63,
509,
63,
5500,
8,
5500,
12,
2909,
12,
2518,
29,
1972,
9,
267,
340,
859,
365,
488,
26,
288,
870,
298,
221,
14750,
26,
3091,
1174,
1911,
2,
288,
18557,
63,
1045,
63,
889,
63,
929,
14,
740,
8,
5500,
9,
288,
1980,
398,
8839,
63,
1765,
275,
859,
14,
1739,
63,
578,
14,
362,
63,
1765,
63,
1955,
8,
1765,
63,
1955,
9,
267,
340,
8839,
63,
1765,
365,
488,
26,
288,
870,
298,
221,
3091,
2120,
1174,
1911,
2,
288,
18557,
63,
1045,
63,
889,
63,
929,
14,
740,
8,
5500,
9,
288,
1980,
398,
2120,
63,
929,
275,
8839,
63,
1765,
14,
1739,
63,
929,
267,
5020,
59,
1765,
63,
929,
61,
847,
413,
267,
870,
298,
221,
8511,
26,
469,
16,
5469,
908,
8,
1765,
63,
929,
9,
398,
340,
2120,
63,
929,
508,
3232,
32615,
3493,
14,
13768,
26,
288,
340,
8839,
63,
1765,
14,
16431,
63,
5934,
365,
440,
488,
26,
355,
18557,
63,
1045,
63,
8420,
63,
13379,
14,
740,
8,
5500,
9,
267,
916,
2120,
63,
929,
508,
3232,
32615,
3493,
14,
3755,
1608,
1206,
26,
288,
18557,
63,
1045,
63,
324,
13688,
63,
29752,
14,
740,
8,
5500,
9,
267,
916,
2120,
63,
929,
508,
3232,
32615,
3493,
14,
4030,
63,
3755,
1608,
4479,
503,
2120,
63,
929,
508,
3232,
32615,
3493,
14,
22162,
26,
288,
18557,
63,
1045,
63,
13688,
63,
29752,
14,
740,
8,
5500,
9,
339,
870,
298,
1444,
306,
2,
272,
870,
298,
1366,
26,
469,
16,
5469,
908,
8,
521,
14,
6205,
3647,
57,
450,
66,
450,
68,
450,
40,
2689,
45,
2689,
51,
435,
993,
401,
900,
14,
22227,
4059,
272,
870,
298,
6979,
26,
469,
16,
5469,
908,
8,
1972,
14,
344,
9,
272,
870,
298,
6592,
26,
469,
16,
5469,
908,
8,
1985,
9,
272,
870,
298,
1944,
1174,
26,
469
] |
[
199,
3110,
370,
664,
11076,
3595,
1551,
22480,
8826,
14,
199,
624,
199,
646,
7392,
199,
646,
900,
199,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
199,
504,
8691,
492,
1852,
63,
1422,
199,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
15058,
63,
1612,
14,
8268,
14,
8022,
492,
30687,
199,
504,
9872,
14,
1490,
63,
8960,
63,
16050,
63,
2888,
14,
1490,
8960,
1739,
492,
3232,
32615,
3493,
199,
199,
504,
20736,
14,
11653,
492,
664,
63,
1972,
199,
504,
20736,
14,
992,
492,
17246,
2377,
199,
504,
6474,
14,
992,
492,
16535,
63,
344,
63,
509,
63,
751,
12,
18946,
199,
199,
504,
17724,
14,
1208,
492,
664,
63,
578,
63,
509,
63,
5500,
421,
199,
533,
5817,
8,
25150,
304,
272,
408,
272,
5817,
370,
664,
11076,
3595,
1551,
22480,
8826,
14,
272,
408,
339,
1720,
275,
298,
7692,
26,
1551,
8960,
63,
3200,
665,
1972,
63,
344,
30,
665,
6462,
63,
1985,
30,
1553,
1765,
13,
1955,
18987,
1765,
63,
1955,
3072,
78,
2,
339,
945,
63,
513,
275,
22239,
14,
1422,
63,
513,
435,
334,
267,
1852,
63,
1422,
4517,
1765,
13,
1955,
297,
490,
730,
534,
442,
297,
849,
29,
16,
12,
490,
1720,
628,
4476,
1329,
370,
664,
11076,
3595,
7651,
272,
776,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
267,
408,
2461,
367,
1414,
1041,
398,
2120,
63,
1955,
275,
1511,
459,
1765,
63,
1955,
418,
398,
340,
822,
8,
589,
9,
508,
499,
26,
288,
2518,
63,
344,
275,
30687,
14,
504,
63,
6667,
63,
875,
8,
589,
59,
16,
566,
288,
4503,
63,
498,
275,
2518,
63,
344,
14,
1875,
63,
3807,
63,
498,
63,
504,
63,
6667,
63,
875,
8,
589,
59,
17,
566,
267,
587,
26,
288,
870,
291,
14,
3437,
288,
372,
398,
862,
26,
288,
2518,
275,
664,
63,
1972,
8,
1972,
63,
344,
9,
267,
871,
1722,
465,
2329,
26,
288,
870,
2329,
288,
372,
398,
5872,
275,
10996,
1252,
362,
63,
1053,
8,
3807,
63,
498,
12,
5818,
29,
16,
9,
267,
340,
5872,
365,
488,
26,
288,
870,
298,
6592,
469,
16,
93,
440,
1911,
315,
2518,
1674,
908,
8,
3807,
63,
498,
9,
288,
372,
398,
862,
26,
288,
26802,
63,
17921,
275,
18946,
14,
1462,
14,
3707,
63,
22428,
63,
262,
8,
1972,
63,
344,
9,
288,
870,
298,
7316,
18557,
26802,
315,
469,
16,
9160,
469,
17,
5469,
908,
8,
1972,
63,
344,
12,
26802,
63,
17921,
14,
835,
1012,
953,
8671,
63,
1765,
63,
13724,
8,
22428,
63,
17921,
12,
2518,
12,
4503,
63,
498,
12,
2120,
63,
1955,
9,
398,
871,
13483,
26,
288,
870,
1867,
78,
6044,
28374,
1146,
2,
421,
199,
318,
8671,
63,
1765,
63,
13724,
8,
17921,
12,
2518,
12,
2909,
12,
2120,
63,
1955,
12,
2218,
63,
475,
63,
493,
29,
549,
304,
272,
408,
5375,
5020,
402,
18557,
1041,
339,
5020,
275,
469,
267,
3232,
32615,
3493,
14,
13768,
26,
378,
12,
267,
3232,
32615,
3493,
14,
3755,
1608,
1206,
26,
378,
12,
267,
3232,
32615,
3493,
14,
4030,
63,
3755,
1608,
4479,
26,
378,
12,
267,
3232,
32615,
3493,
14,
22162,
26,
378,
272,
789,
339,
18557,
63,
1045,
63,
8420,
63,
13379,
275,
942,
272,
18557,
63,
1045,
63,
324,
13688,
63,
29752,
275,
942,
221,
327,
4287,
26,
3507,
29,
3197,
13,
354,
272,
18557,
63,
1045,
63,
13688,
63,
29752,
275,
942,
221,
327,
4287,
26,
3507,
29,
3197,
13,
354,
272,
18557,
63,
1045,
63,
889,
63,
929,
275,
942,
339,
6474,
63,
3112,
275,
17246,
2377,
14,
1462,
14,
1541,
8,
578,
63,
929,
63,
498,
29,
1985,
12,
6474,
363,
262,
29,
17921,
680,
1648,
63,
991,
360,
5500,
358,
272,
870,
298,
7316,
6474,
4621,
26,
469,
16,
5469,
908,
8,
5500,
63,
3112,
14,
835,
1012,
339,
367,
1478,
12,
6474,
63,
578,
315,
3874,
8,
5500,
63,
3112,
304,
267,
340,
1478,
450,
2948,
508,
378,
26,
288,
870,
298,
2595,
469,
16,
93,
18557,
7686,
10894,
1674,
908,
8,
1080,
9,
398,
6474,
275,
6474,
63,
578,
14,
5500,
267,
870,
5310,
16,
16495,
17,
5469,
908,
8,
5500,
14,
344,
12,
6474,
14,
2473,
9,
398,
859,
275,
664,
63,
578,
63,
509,
63,
5500,
8,
5500,
12,
2909,
12,
2518,
29,
1972,
9,
267,
340,
859,
365,
488,
26,
288,
870,
298,
221,
14750,
26,
3091,
1174,
1911,
2,
288,
18557,
63,
1045,
63,
889,
63,
929,
14,
740,
8,
5500,
9,
288,
1980,
398,
8839,
63,
1765,
275,
859,
14,
1739,
63,
578,
14,
362,
63,
1765,
63,
1955,
8,
1765,
63,
1955,
9,
267,
340,
8839,
63,
1765,
365,
488,
26,
288,
870,
298,
221,
3091,
2120,
1174,
1911,
2,
288,
18557,
63,
1045,
63,
889,
63,
929,
14,
740,
8,
5500,
9,
288,
1980,
398,
2120,
63,
929,
275,
8839,
63,
1765,
14,
1739,
63,
929,
267,
5020,
59,
1765,
63,
929,
61,
847,
413,
267,
870,
298,
221,
8511,
26,
469,
16,
5469,
908,
8,
1765,
63,
929,
9,
398,
340,
2120,
63,
929,
508,
3232,
32615,
3493,
14,
13768,
26,
288,
340,
8839,
63,
1765,
14,
16431,
63,
5934,
365,
440,
488,
26,
355,
18557,
63,
1045,
63,
8420,
63,
13379,
14,
740,
8,
5500,
9,
267,
916,
2120,
63,
929,
508,
3232,
32615,
3493,
14,
3755,
1608,
1206,
26,
288,
18557,
63,
1045,
63,
324,
13688,
63,
29752,
14,
740,
8,
5500,
9,
267,
916,
2120,
63,
929,
508,
3232,
32615,
3493,
14,
4030,
63,
3755,
1608,
4479,
503,
2120,
63,
929,
508,
3232,
32615,
3493,
14,
22162,
26,
288,
18557,
63,
1045,
63,
13688,
63,
29752,
14,
740,
8,
5500,
9,
339,
870,
298,
1444,
306,
2,
272,
870,
298,
1366,
26,
469,
16,
5469,
908,
8,
521,
14,
6205,
3647,
57,
450,
66,
450,
68,
450,
40,
2689,
45,
2689,
51,
435,
993,
401,
900,
14,
22227,
4059,
272,
870,
298,
6979,
26,
469,
16,
5469,
908,
8,
1972,
14,
344,
9,
272,
870,
298,
6592,
26,
469,
16,
5469,
908,
8,
1985,
9,
272,
870,
298,
1944,
1174,
26,
469,
0
] |
[
1,
1,
1,
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oolWall
|
user/python/Lib/test/test_gzip.py
|
10
|
1207
|
import sys, os
import gzip, tempfile
filename = tempfile.mktemp()
data1 = """ int length=DEFAULTALLOC, err = Z_OK;
PyObject *RetVal;
int flushmode = Z_FINISH;
unsigned long start_total_out;
"""
data2 = """/* zlibmodule.c -- gzip-compatible data compression */
/* See http://www.cdrom.com/pub/infozip/zlib/ */
/* See http://www.winimage.com/zLibDll for Windows */
"""
f = gzip.GzipFile(filename, 'wb') ; f.write(data1 * 50) ; f.close()
f = gzip.GzipFile(filename, 'rb') ; d = f.read() ; f.close()
assert d == data1*50
# Append to the previous file
f = gzip.GzipFile(filename, 'ab') ; f.write(data2 * 15) ; f.close()
f = gzip.GzipFile(filename, 'rb') ; d = f.read() ; f.close()
assert d == (data1*50) + (data2*15)
# Try .readline() with varying line lengths
f = gzip.GzipFile(filename, 'rb')
line_length = 0
while 1:
L = f.readline( line_length )
if L == "" and line_length != 0: break
assert len(L) <= line_length
line_length = (line_length + 1) % 50
f.close()
# Try .readlines()
f = gzip.GzipFile(filename, 'rb')
L = f.readlines()
f.close()
f = gzip.GzipFile(filename, 'rb')
while 1:
L = f.readlines(150)
if L == []: break
f.close()
os.unlink( filename )
|
gpl-2.0
|
[
199,
646,
984,
12,
747,
199,
646,
11756,
12,
5549,
199,
199,
1501,
275,
5549,
14,
22136,
342,
199,
199,
576,
17,
275,
408,
221,
1109,
2582,
29,
3472,
28605,
12,
2329,
275,
3107,
63,
3593,
27,
523,
24106,
627,
6816,
7562,
27,
523,
1109,
8976,
632,
275,
3107,
63,
17383,
13898,
27,
523,
7381,
1846,
1343,
63,
2923,
63,
548,
27,
199,
199,
624,
199,
199,
576,
18,
275,
408,
6331,
12472,
578,
14,
67,
1553,
11756,
13,
6490,
666,
10291,
11589,
199,
6331,
1666,
1455,
921,
1544,
14,
2866,
417,
14,
957,
15,
5645,
15,
815,
3065,
15,
15371,
15,
11589,
199,
6331,
1666,
1455,
921,
1544,
14,
2676,
1569,
14,
957,
15,
90,
4728,
29479,
367,
5417,
11589,
199,
624,
199,
199,
70,
275,
11756,
14,
29827,
8,
1501,
12,
283,
6603,
358,
8700,
289,
14,
952,
8,
576,
17,
627,
5238,
9,
8700,
289,
14,
1600,
342,
199,
199,
70,
275,
11756,
14,
29827,
8,
1501,
12,
283,
4848,
358,
8700,
366,
275,
289,
14,
739,
342,
8700,
289,
14,
1600,
342,
199,
479,
366,
508,
666,
17,
10,
1400,
199,
199,
3,
18726,
370,
314,
4136,
570,
199,
70,
275,
11756,
14,
29827,
8,
1501,
12,
283,
371,
358,
8700,
289,
14,
952,
8,
576,
18,
627,
4114,
9,
8700,
289,
14,
1600,
342,
199,
199,
70,
275,
11756,
14,
29827,
8,
1501,
12,
283,
4848,
358,
8700,
366,
275,
289,
14,
739,
342,
8700,
289,
14,
1600,
342,
199,
479,
366,
508,
334,
576,
17,
10,
1400,
9,
435,
334,
576,
18,
10,
1046,
9,
199,
199,
3,
7649,
1275,
6407,
342,
543,
17083,
316,
1004,
17464,
199,
199,
70,
275,
11756,
14,
29827,
8,
1501,
12,
283,
4848,
358,
199,
604,
63,
1267,
275,
378,
199,
6710,
413,
26,
272,
491,
275,
289,
14,
6407,
8,
1004,
63,
1267,
776,
272,
340,
491,
508,
3087,
436,
1004,
63,
1267,
1137,
378,
26,
2059,
272,
702,
822,
8,
44,
9,
2695,
1004,
63,
1267,
272,
1004,
63,
1267,
275,
334,
604,
63,
1267,
435,
413,
9,
450,
5238,
199,
70,
14,
1600,
342,
199,
199,
3,
7649,
1275,
9684,
342,
9948,
199,
70,
275,
11756,
14,
29827,
8,
1501,
12,
283,
4848,
358,
199,
44,
275,
289,
14,
9684,
342,
199,
70,
14,
1600,
342,
199,
199,
70,
275,
11756,
14,
29827,
8,
1501,
12,
283,
4848,
358,
199,
6710,
413,
26,
272,
491,
275,
289,
14,
9684,
8,
8251,
9,
272,
340,
491,
508,
18410,
2059,
258,
199,
70,
14,
1600,
342,
421,
199,
736,
14,
7162,
8,
1788,
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
] |
[
646,
984,
12,
747,
199,
646,
11756,
12,
5549,
199,
199,
1501,
275,
5549,
14,
22136,
342,
199,
199,
576,
17,
275,
408,
221,
1109,
2582,
29,
3472,
28605,
12,
2329,
275,
3107,
63,
3593,
27,
523,
24106,
627,
6816,
7562,
27,
523,
1109,
8976,
632,
275,
3107,
63,
17383,
13898,
27,
523,
7381,
1846,
1343,
63,
2923,
63,
548,
27,
199,
199,
624,
199,
199,
576,
18,
275,
408,
6331,
12472,
578,
14,
67,
1553,
11756,
13,
6490,
666,
10291,
11589,
199,
6331,
1666,
1455,
921,
1544,
14,
2866,
417,
14,
957,
15,
5645,
15,
815,
3065,
15,
15371,
15,
11589,
199,
6331,
1666,
1455,
921,
1544,
14,
2676,
1569,
14,
957,
15,
90,
4728,
29479,
367,
5417,
11589,
199,
624,
199,
199,
70,
275,
11756,
14,
29827,
8,
1501,
12,
283,
6603,
358,
8700,
289,
14,
952,
8,
576,
17,
627,
5238,
9,
8700,
289,
14,
1600,
342,
199,
199,
70,
275,
11756,
14,
29827,
8,
1501,
12,
283,
4848,
358,
8700,
366,
275,
289,
14,
739,
342,
8700,
289,
14,
1600,
342,
199,
479,
366,
508,
666,
17,
10,
1400,
199,
199,
3,
18726,
370,
314,
4136,
570,
199,
70,
275,
11756,
14,
29827,
8,
1501,
12,
283,
371,
358,
8700,
289,
14,
952,
8,
576,
18,
627,
4114,
9,
8700,
289,
14,
1600,
342,
199,
199,
70,
275,
11756,
14,
29827,
8,
1501,
12,
283,
4848,
358,
8700,
366,
275,
289,
14,
739,
342,
8700,
289,
14,
1600,
342,
199,
479,
366,
508,
334,
576,
17,
10,
1400,
9,
435,
334,
576,
18,
10,
1046,
9,
199,
199,
3,
7649,
1275,
6407,
342,
543,
17083,
316,
1004,
17464,
199,
199,
70,
275,
11756,
14,
29827,
8,
1501,
12,
283,
4848,
358,
199,
604,
63,
1267,
275,
378,
199,
6710,
413,
26,
272,
491,
275,
289,
14,
6407,
8,
1004,
63,
1267,
776,
272,
340,
491,
508,
3087,
436,
1004,
63,
1267,
1137,
378,
26,
2059,
272,
702,
822,
8,
44,
9,
2695,
1004,
63,
1267,
272,
1004,
63,
1267,
275,
334,
604,
63,
1267,
435,
413,
9,
450,
5238,
199,
70,
14,
1600,
342,
199,
199,
3,
7649,
1275,
9684,
342,
9948,
199,
70,
275,
11756,
14,
29827,
8,
1501,
12,
283,
4848,
358,
199,
44,
275,
289,
14,
9684,
342,
199,
70,
14,
1600,
342,
199,
199,
70,
275,
11756,
14,
29827,
8,
1501,
12,
283,
4848,
358,
199,
6710,
413,
26,
272,
491,
275,
289,
14,
9684,
8,
8251,
9,
272,
340,
491,
508,
18410,
2059,
258,
199,
70,
14,
1600,
342,
421,
199,
736,
14,
7162,
8,
1788,
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,
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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
goldhand/terpene
|
rasputin/users/migrations/0001_initial.py
|
25
|
2693
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import django.utils.timezone
import django.core.validators
class Migration(migrations.Migration):
dependencies = [
('auth', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(default=django.utils.timezone.now, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(help_text='Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.', unique=True, max_length=30, verbose_name='username', validators=[django.core.validators.RegexValidator('^[\\w.@+-]+$', 'Enter a valid username.', 'invalid')])),
('first_name', models.CharField(max_length=30, verbose_name='first name', blank=True)),
('last_name', models.CharField(max_length=30, verbose_name='last name', blank=True)),
('email', models.EmailField(max_length=75, verbose_name='email address', blank=True)),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('groups', models.ManyToManyField(related_query_name='user', related_name='user_set', to='auth.Group', blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of his/her group.', verbose_name='groups')),
('user_permissions', models.ManyToManyField(related_query_name='user', related_name='user_set', to='auth.Permission', blank=True, help_text='Specific permissions for this user.', verbose_name='user permissions')),
],
options={
'abstract': False,
'verbose_name': 'user',
'verbose_name_plural': 'users',
},
bases=(models.Model,),
)
]
|
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,
1709,
12,
6180,
199,
646,
1639,
14,
1208,
14,
7145,
199,
646,
1639,
14,
1018,
14,
11346,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
1178,
297,
283,
4183,
63,
2747,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
1899,
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,
2060,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
3933,
12,
3376,
63,
354,
534,
2060,
3855,
355,
661,
2019,
63,
2886,
297,
1709,
14,
4626,
8,
885,
29,
1176,
14,
1208,
14,
7145,
14,
2131,
12,
3376,
63,
354,
534,
2019,
4676,
3855,
355,
661,
374,
63,
11434,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
1720,
63,
505,
534,
20924,
2335,
626,
642,
922,
965,
1006,
3443,
1928,
7662,
26694,
3062,
3130,
3376,
63,
354,
534,
11434,
2004,
3855,
355,
661,
2473,
297,
1709,
14,
2183,
8,
3437,
63,
505,
534,
8030,
14,
4233,
4110,
503,
27392,
14,
12230,
878,
12,
7576,
436,
768,
8083,
15,
19616,
13,
15607,
1454,
3130,
3747,
29,
549,
12,
1390,
63,
1267,
29,
1216,
12,
3376,
63,
354,
534,
2473,
297,
14370,
1524,
1176,
14,
1018,
14,
11346,
14,
5103,
8640,
9097,
59,
1103,
87,
14,
32,
16341,
2807,
4268,
283,
8468,
282,
1686,
3434,
3130,
283,
3197,
2023,
395,
355,
661,
2246,
63,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1216,
12,
3376,
63,
354,
534,
2246,
536,
297,
4596,
29,
549,
1826,
355,
661,
2019,
63,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1216,
12,
3376,
63,
354,
534,
2019,
536,
297,
4596,
29,
549,
1826,
355,
661,
2123,
297,
1709,
14,
16577,
8,
988,
63,
1267,
29,
2194,
12,
3376,
63,
354,
534,
2123,
2287,
297,
4596,
29,
549,
1826,
355,
661,
374,
63,
7018,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
1720,
63,
505,
534,
20924,
2335,
3775,
314,
922,
883,
943,
1901,
642,
4628,
4770,
3130,
3376,
63,
354,
534,
7018,
2004,
3855,
355,
661,
374,
63,
2682,
297,
1709,
14,
5036,
8,
885,
29,
549,
12,
1720,
63,
505,
534,
20924,
2335,
3775,
642,
922,
1077,
506,
10184,
465,
4702,
14,
1910,
2416,
642,
3140,
402,
13794,
12639,
3130,
3376,
63,
354,
534,
2682,
3855,
355,
661,
602,
63,
11806,
297,
1709,
14,
4626,
8,
885,
29,
1176,
14,
1208,
14,
7145,
14,
2131,
12,
3376,
63,
354,
534,
602,
16538,
3855,
355,
661,
2634,
297,
1709,
14,
7624,
8,
2407,
63,
1131,
63,
354,
534,
751,
297,
4048,
63,
354,
534,
751,
63,
409,
297,
370,
534,
1178,
14,
2448,
297,
4596,
29,
549,
12,
1720,
63,
505,
534,
1918,
4652,
642,
922,
15006,
370,
14,
437,
922,
911,
664,
1006,
3443,
10009,
370,
1924,
402,
17049,
15,
2523,
1572,
3130,
3376,
63,
354,
534,
2634,
3855,
355,
661,
751,
63,
6060,
297,
1709,
14,
7624,
8,
2407,
63,
1131,
63,
354,
534,
751,
297,
4048,
63,
354,
534,
751,
63,
409,
297,
370,
534,
1178,
14,
7980,
297,
4596,
29,
549,
12,
1720,
63,
505,
534,
16786,
3443,
367,
642,
922,
3130,
3376,
63,
354,
534,
751,
3443,
3855,
288,
2156,
288,
1511,
3126,
355,
283,
6198,
356,
756,
12,
355,
283,
3832,
63,
354,
356,
283,
751,
297,
355,
283,
3832,
63,
354,
63,
10019,
356,
283,
3707,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
776,
272,
1622,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
12,
6180,
199,
646,
1639,
14,
1208,
14,
7145,
199,
646,
1639,
14,
1018,
14,
11346,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
1178,
297,
283,
4183,
63,
2747,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
1899,
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,
2060,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
3933,
12,
3376,
63,
354,
534,
2060,
3855,
355,
661,
2019,
63,
2886,
297,
1709,
14,
4626,
8,
885,
29,
1176,
14,
1208,
14,
7145,
14,
2131,
12,
3376,
63,
354,
534,
2019,
4676,
3855,
355,
661,
374,
63,
11434,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
1720,
63,
505,
534,
20924,
2335,
626,
642,
922,
965,
1006,
3443,
1928,
7662,
26694,
3062,
3130,
3376,
63,
354,
534,
11434,
2004,
3855,
355,
661,
2473,
297,
1709,
14,
2183,
8,
3437,
63,
505,
534,
8030,
14,
4233,
4110,
503,
27392,
14,
12230,
878,
12,
7576,
436,
768,
8083,
15,
19616,
13,
15607,
1454,
3130,
3747,
29,
549,
12,
1390,
63,
1267,
29,
1216,
12,
3376,
63,
354,
534,
2473,
297,
14370,
1524,
1176,
14,
1018,
14,
11346,
14,
5103,
8640,
9097,
59,
1103,
87,
14,
32,
16341,
2807,
4268,
283,
8468,
282,
1686,
3434,
3130,
283,
3197,
2023,
395,
355,
661,
2246,
63,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1216,
12,
3376,
63,
354,
534,
2246,
536,
297,
4596,
29,
549,
1826,
355,
661,
2019,
63,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1216,
12,
3376,
63,
354,
534,
2019,
536,
297,
4596,
29,
549,
1826,
355,
661,
2123,
297,
1709,
14,
16577,
8,
988,
63,
1267,
29,
2194,
12,
3376,
63,
354,
534,
2123,
2287,
297,
4596,
29,
549,
1826,
355,
661,
374,
63,
7018,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
1720,
63,
505,
534,
20924,
2335,
3775,
314,
922,
883,
943,
1901,
642,
4628,
4770,
3130,
3376,
63,
354,
534,
7018,
2004,
3855,
355,
661,
374,
63,
2682,
297,
1709,
14,
5036,
8,
885,
29,
549,
12,
1720,
63,
505,
534,
20924,
2335,
3775,
642,
922,
1077,
506,
10184,
465,
4702,
14,
1910,
2416,
642,
3140,
402,
13794,
12639,
3130,
3376,
63,
354,
534,
2682,
3855,
355,
661,
602,
63,
11806,
297,
1709,
14,
4626,
8,
885,
29,
1176,
14,
1208,
14,
7145,
14,
2131,
12,
3376,
63,
354,
534,
602,
16538,
3855,
355,
661,
2634,
297,
1709,
14,
7624,
8,
2407,
63,
1131,
63,
354,
534,
751,
297,
4048,
63,
354,
534,
751,
63,
409,
297,
370,
534,
1178,
14,
2448,
297,
4596,
29,
549,
12,
1720,
63,
505,
534,
1918,
4652,
642,
922,
15006,
370,
14,
437,
922,
911,
664,
1006,
3443,
10009,
370,
1924,
402,
17049,
15,
2523,
1572,
3130,
3376,
63,
354,
534,
2634,
3855,
355,
661,
751,
63,
6060,
297,
1709,
14,
7624,
8,
2407,
63,
1131,
63,
354,
534,
751,
297,
4048,
63,
354,
534,
751,
63,
409,
297,
370,
534,
1178,
14,
7980,
297,
4596,
29,
549,
12,
1720,
63,
505,
534,
16786,
3443,
367,
642,
922,
3130,
3376,
63,
354,
534,
751,
3443,
3855,
288,
2156,
288,
1511,
3126,
355,
283,
6198,
356,
756,
12,
355,
283,
3832,
63,
354,
356,
283,
751,
297,
355,
283,
3832,
63,
354,
63,
10019,
356,
283,
3707,
297,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
776,
272,
1622,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
Conjuro/GitPython
|
refs/headref.py
|
1
|
5050
|
from reference import Reference
from git.config import SectionConstraint
from git.util import join_path
__all__ = ["Head"]
class Head(Reference):
"""The GitPyhton Head implementation provides more git-command based features
A Head is a named reference to a Commit. Every Head instance contains a name
and a Commit object.
Examples::
>>> repo = Repo("/path/to/repo")
>>> head = repo.heads[0]
>>> head.name
'master'
>>> head.commit
<git.Commit "1c09f116cbc2cb4100fb6935bb162daa4723f455">
>>> head.commit.hexsha
'1c09f116cbc2cb4100fb6935bb162daa4723f455'"""
__slots__ = tuple()
_common_path_default = "refs/heads"
k_config_remote = "remote"
k_config_remote_ref = "merge" # branch to merge from remote
# will be set by init method !
RemoteReferenceCls = None
#{ Configuration
def set_tracking_branch(self, remote_reference):
"""
Configure this branch to track the given remote reference. This will alter
this branch's configuration accordingly.
:param remote_reference: The remote reference to track or None to untrack
any references
:return: self"""
if remote_reference is not None and not isinstance(remote_reference, self.RemoteReferenceCls):
raise ValueError("Incorrect parameter type: %r" % remote_reference)
# END handle type
writer = self.config_writer()
if remote_reference is None:
writer.remove_option(self.k_config_remote)
writer.remove_option(self.k_config_remote_ref)
if len(writer.options()) == 0:
writer.remove_section()
# END handle remove section
else:
writer.set_value(self.k_config_remote, remote_reference.remote_name)
writer.set_value(self.k_config_remote_ref, Head.to_full_path(remote_reference.remote_head))
# END handle ref value
return self
def tracking_branch(self):
"""
:return: The remote_reference we are tracking, or None if we are
not a tracking branch"""
reader = self.config_reader()
if reader.has_option(self.k_config_remote) and reader.has_option(self.k_config_remote_ref):
ref = Head(self.repo, Head.to_full_path(reader.get_value(self.k_config_remote_ref)))
remote_refpath = self.RemoteReferenceCls.to_full_path(join_path(reader.get_value(self.k_config_remote), ref.name))
return self.RemoteReferenceCls(self.repo, remote_refpath)
# END handle have tracking branch
# we are not a tracking branch
return None
#{ Configruation
def _config_parser(self, read_only):
if read_only:
parser = self.repo.config_reader()
else:
parser = self.repo.config_writer()
# END handle parser instance
return SectionConstraint(parser, 'branch "%s"' % self.name)
def config_reader(self):
"""
:return: A configuration parser instance constrained to only read
this instance's values"""
return self._config_parser(read_only=True)
def config_writer(self):
"""
:return: A configuration writer instance with read-and write acccess
to options of this head"""
return self._config_parser(read_only=False)
#} END configuration
@classmethod
def delete(cls, repo, *heads, **kwargs):
"""Delete the given heads
:param force:
If True, the heads will be deleted even if they are not yet merged into
the main development stream.
Default False"""
force = kwargs.get("force", False)
flag = "-d"
if force:
flag = "-D"
repo.git.branch(flag, *heads)
def rename(self, new_path, force=False):
"""Rename self to a new path
:param new_path:
Either a simple name or a path, i.e. new_name or features/new_name.
The prefix refs/heads is implied
:param force:
If True, the rename will succeed even if a head with the target name
already exists.
:return: self
:note: respects the ref log as git commands are used"""
flag = "-m"
if force:
flag = "-M"
self.repo.git.branch(flag, self, new_path)
self.path = "%s/%s" % (self._common_path_default, new_path)
return self
def checkout(self, force=False, **kwargs):
"""Checkout this head by setting the HEAD to this reference, by updating the index
to reflect the tree we point to and by updating the working tree to reflect
the latest index.
The command will fail if changed working tree files would be overwritten.
:param force:
If True, changes to the index and the working tree will be discarded.
If False, GitCommandError will be raised in that situation.
:param kwargs:
Additional keyword arguments to be passed to git checkout, i.e.
b='new_branch' to create a new branch at the given spot.
:return:
The active branch after the checkout operation, usually self unless
a new branch has been created.
:note:
By default it is only allowed to checkout heads - everything else
will leave the HEAD detached which is allowed and possible, but remains
a special state that some tools might not be able to handle."""
args = list()
kwargs['f'] = force
if kwargs['f'] == False:
kwargs.pop('f')
self.repo.git.checkout(self, **kwargs)
return self.repo.active_branch
|
bsd-3-clause
|
[
504,
3659,
492,
10944,
199,
504,
6135,
14,
888,
492,
15247,
8463,
199,
504,
6135,
14,
1974,
492,
4263,
63,
515,
199,
199,
363,
452,
363,
275,
2097,
11664,
937,
199,
199,
533,
5311,
350,
8,
5083,
304,
199,
198,
624,
1918,
12579,
2713,
517,
265,
5311,
350,
4514,
6571,
1655,
6135,
13,
1531,
4079,
4534,
8299,
198,
33,
5311,
350,
365,
282,
4310,
3659,
370,
282,
21447,
14,
18414,
5311,
350,
1256,
3509,
282,
536,
199,
198,
460,
282,
21447,
909,
14,
421,
198,
22787,
447,
2742,
198,
6071,
3831,
275,
20069,
4769,
515,
15,
475,
15,
3417,
531,
507,
198,
6071,
4854,
275,
3831,
14,
17033,
59,
16,
61,
2742,
198,
6071,
4854,
14,
354,
507,
198,
6704,
2311,
7,
2742,
198,
6071,
4854,
14,
3543,
507,
198,
28,
3187,
14,
11421,
298,
17,
67,
1643,
70,
7524,
19279,
18,
2894,
20,
1960,
4675,
1876,
1276,
2501,
12438,
30908,
2417,
1789,
70,
13267,
1743,
2742,
198,
6071,
4854,
14,
3543,
14,
4097,
4835,
507,
198,
7,
17,
67,
1643,
70,
7524,
19279,
18,
2894,
20,
1960,
4675,
1876,
1276,
2501,
12438,
30908,
2417,
1789,
70,
13267,
26555,
199,
198,
363,
7257,
363,
275,
2008,
342,
8299,
198,
63,
2330,
63,
515,
63,
885,
275,
298,
7655,
15,
17033,
2,
199,
198,
75,
63,
888,
63,
3846,
275,
298,
3846,
2,
199,
198,
75,
63,
888,
63,
3846,
63,
1121,
275,
298,
5628,
2,
1057,
198,
3,
5246,
370,
5389,
687,
3982,
8299,
198,
3,
911,
506,
663,
701,
4205,
1083,
8546,
199,
198,
6713,
5083,
24342,
275,
488,
8299,
198,
3,
91,
11595,
8299,
198,
318,
663,
63,
14428,
63,
4694,
8,
277,
12,
3982,
63,
4443,
304,
507,
198,
624,
507,
198,
17324,
642,
5246,
370,
4426,
314,
1627,
3982,
3659,
14,
961,
911,
17355,
686,
198,
3749,
5246,
1159,
2897,
24137,
14,
9068,
198,
26,
635,
3982,
63,
4443,
26,
710,
3982,
3659,
370,
4426,
503,
488,
370,
625,
3885,
20866,
198,
1629,
6941,
507,
198,
26,
1107,
26,
291,
624,
507,
198,
692,
3982,
63,
4443,
365,
440,
488,
436,
440,
1228,
8,
3846,
63,
4443,
12,
291,
14,
6713,
5083,
24342,
304,
686,
198,
3730,
1722,
480,
18298,
2725,
730,
26,
450,
82,
2,
450,
3982,
63,
4443,
9,
507,
198,
3,
7729,
2429,
730,
9068,
198,
5491,
275,
291,
14,
888,
63,
5491,
342,
507,
198,
692,
3982,
63,
4443,
365,
488,
26,
686,
198,
5491,
14,
2168,
63,
1422,
8,
277,
14,
75,
63,
888,
63,
3846,
9,
686,
198,
5491,
14,
2168,
63,
1422,
8,
277,
14,
75,
63,
888,
63,
3846,
63,
1121,
9,
686,
198,
692,
822,
8,
5491,
14,
1419,
1012,
508,
378,
26,
1585,
198,
5491,
14,
2168,
63,
2792,
342,
686,
198,
3,
7729,
2429,
2813,
3420,
507,
198,
2836,
26,
686,
198,
5491,
14,
409,
63,
585,
8,
277,
14,
75,
63,
888,
63,
3846,
12,
3982,
63,
4443,
14,
3846,
63,
354,
9,
686,
198,
5491,
14,
409,
63,
585,
8,
277,
14,
75,
63,
888,
63,
3846,
63,
1121,
12,
5311,
350,
14,
475,
63,
2861,
63,
515,
8,
3846,
63,
4443,
14,
3846,
63,
2993,
430,
507,
198,
3,
7729,
2429,
2984,
574,
9068,
198,
1107,
291,
18118,
198,
318,
15161,
63,
4694,
8,
277,
304,
507,
198,
624,
507,
198,
26,
1107,
26,
710,
3982,
63,
4443,
781,
787,
15161,
12,
503,
488,
340,
781,
787,
20866,
198,
1397,
282,
15161,
5246,
624,
507,
198,
5503,
275,
291,
14,
888,
63,
5503,
342,
507,
198,
692,
7002,
14,
1989,
63,
1422,
8,
277,
14,
75,
63,
888,
63,
3846,
9,
436,
7002,
14,
1989,
63,
1422,
8,
277,
14,
75,
63,
888,
63,
3846,
63,
1121,
304,
686,
198,
1121,
275,
5311,
350,
8,
277,
14,
3417,
12,
5311,
350,
14,
475,
63,
2861,
63,
515,
8,
5503,
14,
362,
63,
585,
8,
277,
14,
75,
63,
888,
63,
3846,
63,
1121,
1724,
686,
198,
3846,
63,
1121,
515,
275,
291,
14,
6713,
5083,
24342,
14,
475,
63,
2861,
63,
515,
8,
904,
63,
515,
8,
5503,
14,
362,
63,
585,
8,
277,
14,
75,
63,
888,
63,
3846,
395,
2984,
14,
354,
430,
686,
198,
1107,
291,
14,
6713,
5083,
24342,
8,
277,
14,
3417,
12,
3982,
63,
1121,
515,
9,
507,
198,
3,
7729,
2429,
1172,
15161,
5246,
9068,
198,
3,
781,
787,
440,
282,
15161,
5246,
507,
198,
1107,
488,
507,
18118,
198,
3,
91,
4094,
82,
4086,
8299,
198,
318,
485,
888,
63,
2087,
8,
277,
12,
1586,
63,
2118,
304,
507,
198,
692,
1586,
63,
2118,
26,
686,
198,
2087,
275,
291,
14,
3417,
14,
888,
63,
5503,
342,
507,
198,
2836,
26,
686,
198,
2087,
275,
291,
14,
3417,
14,
888,
63,
5491,
342,
507,
198,
3,
7729,
2429,
1798,
1256,
9068,
198,
1107,
15247,
8463,
8,
2087,
12,
283,
4694,
2071,
83,
4507,
450,
291,
14,
354,
9,
8299,
198,
318,
1101,
63,
5503,
8,
277,
304,
507,
198,
624,
507,
198,
26,
1107,
26,
437,
2897,
1798,
1256,
28483,
370,
1454,
1586,
20866,
198,
3749,
1256,
1159,
1338,
624,
507,
198,
1107,
291,
423,
888,
63,
2087,
8,
739,
63,
2118,
29,
549,
9,
18118,
198,
318,
1101,
63,
5491,
8,
277,
304,
507,
198,
624,
507,
198,
26,
1107,
26,
437,
2897,
7060,
1256,
543,
1586,
13,
460,
2218,
6907,
670,
686,
198,
475,
1511,
402,
642,
4854,
624,
507,
198,
1107,
291,
423,
888,
63,
2087,
8,
739,
63,
2118,
29,
797,
9,
8299,
198,
3,
93,
7729,
2897,
8299,
198,
32,
3744,
199,
198,
318,
3145,
8,
1886,
12,
3831,
12,
627,
17033,
12,
1011,
958,
304,
507,
198,
624,
5392,
314,
1627,
25362,
507,
198,
26,
635,
3542,
26,
686,
198,
3917,
715,
12,
314,
25362,
911,
506,
5463,
2755,
340,
2985,
787,
440,
5966,
9545,
1901,
686,
198,
1589,
2446,
16367,
2547,
14,
686,
198,
2698,
756,
624,
507,
198,
3990,
275,
2074,
14,
362,
480,
3990,
401,
756,
9,
507,
198,
4173,
275,
3905,
68,
2,
507,
198,
692,
3542,
26,
686,
198,
4173,
275,
3905,
36,
2,
507,
198,
3417,
14,
3187,
14,
4694,
8,
4173,
12,
627,
17033,
9
] |
[
3659,
492,
10944,
199,
504,
6135,
14,
888,
492,
15247,
8463,
199,
504,
6135,
14,
1974,
492,
4263,
63,
515,
199,
199,
363,
452,
363,
275,
2097,
11664,
937,
199,
199,
533,
5311,
350,
8,
5083,
304,
199,
198,
624,
1918,
12579,
2713,
517,
265,
5311,
350,
4514,
6571,
1655,
6135,
13,
1531,
4079,
4534,
8299,
198,
33,
5311,
350,
365,
282,
4310,
3659,
370,
282,
21447,
14,
18414,
5311,
350,
1256,
3509,
282,
536,
199,
198,
460,
282,
21447,
909,
14,
421,
198,
22787,
447,
2742,
198,
6071,
3831,
275,
20069,
4769,
515,
15,
475,
15,
3417,
531,
507,
198,
6071,
4854,
275,
3831,
14,
17033,
59,
16,
61,
2742,
198,
6071,
4854,
14,
354,
507,
198,
6704,
2311,
7,
2742,
198,
6071,
4854,
14,
3543,
507,
198,
28,
3187,
14,
11421,
298,
17,
67,
1643,
70,
7524,
19279,
18,
2894,
20,
1960,
4675,
1876,
1276,
2501,
12438,
30908,
2417,
1789,
70,
13267,
1743,
2742,
198,
6071,
4854,
14,
3543,
14,
4097,
4835,
507,
198,
7,
17,
67,
1643,
70,
7524,
19279,
18,
2894,
20,
1960,
4675,
1876,
1276,
2501,
12438,
30908,
2417,
1789,
70,
13267,
26555,
199,
198,
363,
7257,
363,
275,
2008,
342,
8299,
198,
63,
2330,
63,
515,
63,
885,
275,
298,
7655,
15,
17033,
2,
199,
198,
75,
63,
888,
63,
3846,
275,
298,
3846,
2,
199,
198,
75,
63,
888,
63,
3846,
63,
1121,
275,
298,
5628,
2,
1057,
198,
3,
5246,
370,
5389,
687,
3982,
8299,
198,
3,
911,
506,
663,
701,
4205,
1083,
8546,
199,
198,
6713,
5083,
24342,
275,
488,
8299,
198,
3,
91,
11595,
8299,
198,
318,
663,
63,
14428,
63,
4694,
8,
277,
12,
3982,
63,
4443,
304,
507,
198,
624,
507,
198,
17324,
642,
5246,
370,
4426,
314,
1627,
3982,
3659,
14,
961,
911,
17355,
686,
198,
3749,
5246,
1159,
2897,
24137,
14,
9068,
198,
26,
635,
3982,
63,
4443,
26,
710,
3982,
3659,
370,
4426,
503,
488,
370,
625,
3885,
20866,
198,
1629,
6941,
507,
198,
26,
1107,
26,
291,
624,
507,
198,
692,
3982,
63,
4443,
365,
440,
488,
436,
440,
1228,
8,
3846,
63,
4443,
12,
291,
14,
6713,
5083,
24342,
304,
686,
198,
3730,
1722,
480,
18298,
2725,
730,
26,
450,
82,
2,
450,
3982,
63,
4443,
9,
507,
198,
3,
7729,
2429,
730,
9068,
198,
5491,
275,
291,
14,
888,
63,
5491,
342,
507,
198,
692,
3982,
63,
4443,
365,
488,
26,
686,
198,
5491,
14,
2168,
63,
1422,
8,
277,
14,
75,
63,
888,
63,
3846,
9,
686,
198,
5491,
14,
2168,
63,
1422,
8,
277,
14,
75,
63,
888,
63,
3846,
63,
1121,
9,
686,
198,
692,
822,
8,
5491,
14,
1419,
1012,
508,
378,
26,
1585,
198,
5491,
14,
2168,
63,
2792,
342,
686,
198,
3,
7729,
2429,
2813,
3420,
507,
198,
2836,
26,
686,
198,
5491,
14,
409,
63,
585,
8,
277,
14,
75,
63,
888,
63,
3846,
12,
3982,
63,
4443,
14,
3846,
63,
354,
9,
686,
198,
5491,
14,
409,
63,
585,
8,
277,
14,
75,
63,
888,
63,
3846,
63,
1121,
12,
5311,
350,
14,
475,
63,
2861,
63,
515,
8,
3846,
63,
4443,
14,
3846,
63,
2993,
430,
507,
198,
3,
7729,
2429,
2984,
574,
9068,
198,
1107,
291,
18118,
198,
318,
15161,
63,
4694,
8,
277,
304,
507,
198,
624,
507,
198,
26,
1107,
26,
710,
3982,
63,
4443,
781,
787,
15161,
12,
503,
488,
340,
781,
787,
20866,
198,
1397,
282,
15161,
5246,
624,
507,
198,
5503,
275,
291,
14,
888,
63,
5503,
342,
507,
198,
692,
7002,
14,
1989,
63,
1422,
8,
277,
14,
75,
63,
888,
63,
3846,
9,
436,
7002,
14,
1989,
63,
1422,
8,
277,
14,
75,
63,
888,
63,
3846,
63,
1121,
304,
686,
198,
1121,
275,
5311,
350,
8,
277,
14,
3417,
12,
5311,
350,
14,
475,
63,
2861,
63,
515,
8,
5503,
14,
362,
63,
585,
8,
277,
14,
75,
63,
888,
63,
3846,
63,
1121,
1724,
686,
198,
3846,
63,
1121,
515,
275,
291,
14,
6713,
5083,
24342,
14,
475,
63,
2861,
63,
515,
8,
904,
63,
515,
8,
5503,
14,
362,
63,
585,
8,
277,
14,
75,
63,
888,
63,
3846,
395,
2984,
14,
354,
430,
686,
198,
1107,
291,
14,
6713,
5083,
24342,
8,
277,
14,
3417,
12,
3982,
63,
1121,
515,
9,
507,
198,
3,
7729,
2429,
1172,
15161,
5246,
9068,
198,
3,
781,
787,
440,
282,
15161,
5246,
507,
198,
1107,
488,
507,
18118,
198,
3,
91,
4094,
82,
4086,
8299,
198,
318,
485,
888,
63,
2087,
8,
277,
12,
1586,
63,
2118,
304,
507,
198,
692,
1586,
63,
2118,
26,
686,
198,
2087,
275,
291,
14,
3417,
14,
888,
63,
5503,
342,
507,
198,
2836,
26,
686,
198,
2087,
275,
291,
14,
3417,
14,
888,
63,
5491,
342,
507,
198,
3,
7729,
2429,
1798,
1256,
9068,
198,
1107,
15247,
8463,
8,
2087,
12,
283,
4694,
2071,
83,
4507,
450,
291,
14,
354,
9,
8299,
198,
318,
1101,
63,
5503,
8,
277,
304,
507,
198,
624,
507,
198,
26,
1107,
26,
437,
2897,
1798,
1256,
28483,
370,
1454,
1586,
20866,
198,
3749,
1256,
1159,
1338,
624,
507,
198,
1107,
291,
423,
888,
63,
2087,
8,
739,
63,
2118,
29,
549,
9,
18118,
198,
318,
1101,
63,
5491,
8,
277,
304,
507,
198,
624,
507,
198,
26,
1107,
26,
437,
2897,
7060,
1256,
543,
1586,
13,
460,
2218,
6907,
670,
686,
198,
475,
1511,
402,
642,
4854,
624,
507,
198,
1107,
291,
423,
888,
63,
2087,
8,
739,
63,
2118,
29,
797,
9,
8299,
198,
3,
93,
7729,
2897,
8299,
198,
32,
3744,
199,
198,
318,
3145,
8,
1886,
12,
3831,
12,
627,
17033,
12,
1011,
958,
304,
507,
198,
624,
5392,
314,
1627,
25362,
507,
198,
26,
635,
3542,
26,
686,
198,
3917,
715,
12,
314,
25362,
911,
506,
5463,
2755,
340,
2985,
787,
440,
5966,
9545,
1901,
686,
198,
1589,
2446,
16367,
2547,
14,
686,
198,
2698,
756,
624,
507,
198,
3990,
275,
2074,
14,
362,
480,
3990,
401,
756,
9,
507,
198,
4173,
275,
3905,
68,
2,
507,
198,
692,
3542,
26,
686,
198,
4173,
275,
3905,
36,
2,
507,
198,
3417,
14,
3187,
14,
4694,
8,
4173,
12,
627,
17033,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
tensorflow/models
|
research/delf/delf/python/datasets/google_landmarks_dataset/compute_recognition_metrics.py
|
1
|
3672
|
# Copyright 2019 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.
# ==============================================================================
"""Computes metrics for Google Landmarks Recognition dataset predictions.
Metrics are written to stdout.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import sys
from absl import app
from delf.python.datasets.google_landmarks_dataset import dataset_file_io
from delf.python.datasets.google_landmarks_dataset import metrics
cmd_args = None
def main(argv):
if len(argv) > 1:
raise RuntimeError('Too many command-line arguments.')
# Read solution.
print('Reading solution...')
public_solution, private_solution, ignored_ids = dataset_file_io.ReadSolution(
cmd_args.solution_path, dataset_file_io.RECOGNITION_TASK_ID)
print('done!')
# Read predictions.
print('Reading predictions...')
public_predictions, private_predictions = dataset_file_io.ReadPredictions(
cmd_args.predictions_path, set(public_solution.keys()),
set(private_solution.keys()), set(ignored_ids),
dataset_file_io.RECOGNITION_TASK_ID)
print('done!')
# Global Average Precision.
print('**********************************************')
print('(Public) Global Average Precision: %f' %
metrics.GlobalAveragePrecision(public_predictions, public_solution))
print('(Private) Global Average Precision: %f' %
metrics.GlobalAveragePrecision(private_predictions, private_solution))
# Global Average Precision ignoring non-landmark queries.
print('**********************************************')
print(
'(Public) Global Average Precision ignoring non-landmark queries: %f' %
metrics.GlobalAveragePrecision(
public_predictions, public_solution, ignore_non_gt_test_images=True))
print(
'(Private) Global Average Precision ignoring non-landmark queries: %f' %
metrics.GlobalAveragePrecision(
private_predictions, private_solution,
ignore_non_gt_test_images=True))
# Top-1 accuracy.
print('**********************************************')
print('(Public) Top-1 accuracy: %.2f' %
(100.0 * metrics.Top1Accuracy(public_predictions, public_solution)))
print('(Private) Top-1 accuracy: %.2f' %
(100.0 * metrics.Top1Accuracy(private_predictions, private_solution)))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.register('type', 'bool', lambda v: v.lower() == 'true')
parser.add_argument(
'--predictions_path',
type=str,
default='/tmp/predictions.csv',
help="""
Path to CSV predictions file, formatted with columns 'id,landmarks' (the
file should include a header).
""")
parser.add_argument(
'--solution_path',
type=str,
default='/tmp/solution.csv',
help="""
Path to CSV solution file, formatted with columns 'id,landmarks,Usage'
(the file should include a header).
""")
cmd_args, unparsed = parser.parse_known_args()
app.run(main=main, argv=[sys.argv[0]] + unparsed)
|
apache-2.0
|
[
3,
1898,
20312,
710,
9134,
6642,
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,
22594,
7186,
367,
4475,
491,
460,
10375,
799,
6862,
15415,
4789,
7914,
14,
199,
199,
17213,
787,
5313,
370,
3839,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
7534,
199,
646,
984,
199,
199,
504,
2853,
76,
492,
1145,
199,
504,
477,
276,
14,
1548,
14,
12281,
14,
3098,
63,
9688,
10375,
63,
5214,
492,
4789,
63,
493,
63,
2308,
199,
504,
477,
276,
14,
1548,
14,
12281,
14,
3098,
63,
9688,
10375,
63,
5214,
492,
7186,
199,
199,
1760,
63,
589,
275,
488,
421,
199,
318,
2446,
8,
3020,
304,
523,
340,
822,
8,
3020,
9,
690,
413,
26,
272,
746,
6064,
360,
13749,
5002,
1414,
13,
604,
2368,
2659,
819,
327,
5574,
8744,
14,
523,
870,
360,
20568,
8744,
15103,
523,
4575,
63,
14458,
12,
5726,
63,
14458,
12,
5525,
63,
1580,
275,
4789,
63,
493,
63,
2308,
14,
3284,
24277,
8,
489,
2088,
63,
589,
14,
14458,
63,
515,
12,
4789,
63,
493,
63,
2308,
14,
907,
1439,
15306,
12039,
63,
17179,
63,
998,
9,
523,
870,
360,
4456,
10916,
819,
327,
5574,
7914,
14,
523,
870,
360,
20568,
7914,
15103,
523,
4575,
63,
9869,
12,
5726,
63,
9869,
275,
4789,
63,
493,
63,
2308,
14,
3284,
14730,
2452,
8,
489,
2088,
63,
589,
14,
9869,
63,
515,
12,
663,
8,
3455,
63,
14458,
14,
1612,
4000,
489,
663,
8,
4239,
63,
14458,
14,
1612,
4000,
663,
8,
11996,
63,
1580,
395,
489,
4789,
63,
493,
63,
2308,
14,
907,
1439,
15306,
12039,
63,
17179,
63,
998,
9,
523,
870,
360,
4456,
10916,
819,
327,
13641,
437,
3652,
5543,
3688,
14,
523,
870,
360,
5815,
1801,
26537,
358,
523,
870,
14097,
9885,
9,
221,
13641,
437,
3652,
5543,
3688,
26,
450,
70,
7,
450,
267,
7186,
14,
7025,
17400,
28984,
8,
3455,
63,
9869,
12,
4575,
63,
14458,
430,
523,
870,
14097,
12185,
9,
13641,
437,
3652,
5543,
3688,
26,
450,
70,
7,
450,
267,
7186,
14,
7025,
17400,
28984,
8,
4239,
63,
9869,
12,
5726,
63,
14458,
430,
819,
327,
13641,
437,
3652,
5543,
3688,
17289,
2222,
13,
9688,
1657,
9212,
14,
523,
870,
360,
5815,
1801,
26537,
358,
523,
870,
8,
489,
8189,
9885,
9,
221,
13641,
437,
3652,
5543,
3688,
17289,
2222,
13,
9688,
1657,
9212,
26,
450,
70,
7,
450,
489,
7186,
14,
7025,
17400,
28984,
8,
881,
4575,
63,
9869,
12,
4575,
63,
14458,
12,
3686,
63,
2865,
63,
3308,
63,
396,
63,
4782,
29,
549,
430,
523,
870,
8,
489,
8189,
12185,
9,
13641,
437,
3652,
5543,
3688,
17289,
2222,
13,
9688,
1657,
9212,
26,
450,
70,
7,
450,
489,
7186,
14,
7025,
17400,
28984,
8,
881,
5726,
63,
9869,
12,
5726,
63,
14458,
12,
881,
3686,
63,
2865,
63,
3308,
63,
396,
63,
4782,
29,
549,
430,
819,
327,
14132,
13,
17,
12862,
14,
523,
870,
360,
5815,
1801,
26537,
358,
523,
870,
14097,
9885,
9,
221,
14132,
13,
17,
12862,
26,
10536,
18,
70,
7,
450,
267,
334,
1960,
14,
16,
627,
7186,
14,
6105,
17,
1945,
7933,
8,
3455,
63,
9869,
12,
4575,
63,
14458,
1724,
523,
870,
14097,
12185,
9,
14132,
13,
17,
12862,
26,
10536,
18,
70,
7,
450,
267,
334,
1960,
14,
16,
627,
7186,
14,
6105,
17,
1945,
7933,
8,
4239,
63,
9869,
12,
5726,
63,
14458,
1724,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
1798,
275,
7534,
14,
10730,
342,
523,
1798,
14,
2683,
360,
466,
297,
283,
2245,
297,
2400,
373,
26,
373,
14,
2325,
342,
508,
283,
2052,
358,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
9869,
63,
515,
297,
489,
730,
29,
495,
12,
489,
849,
8805,
2791,
15,
9869,
14,
4737,
297,
489,
1720,
11916,
489,
6912,
370,
14689,
7914,
570,
12,
7871,
543,
4362,
283,
344,
12,
9688,
10375,
7,
334,
1589,
489,
570,
1077,
2387,
282,
1406,
680,
489,
7857,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
14458,
63,
515,
297,
489,
730,
29,
495,
12,
489,
849,
8805,
2791,
15,
14458,
14,
4737,
297,
489,
1720,
11916,
489,
6912,
370,
14689,
8744,
570,
12,
7871,
543,
4362,
283,
344,
12,
9688,
10375,
12,
7692,
7,
489,
334,
1589,
570,
1077,
2387,
282,
1406,
680,
489,
7857,
523,
2088,
63,
589,
12,
31857,
275,
1798,
14,
1122,
63,
3159,
63,
589,
342,
523,
1145,
14,
1065,
8,
973,
29,
973,
12,
9238,
1524,
1274,
14,
3020,
59,
16,
2677,
435,
31857,
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
] |
[
1898,
20312,
710,
9134,
6642,
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,
22594,
7186,
367,
4475,
491,
460,
10375,
799,
6862,
15415,
4789,
7914,
14,
199,
199,
17213,
787,
5313,
370,
3839,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
7534,
199,
646,
984,
199,
199,
504,
2853,
76,
492,
1145,
199,
504,
477,
276,
14,
1548,
14,
12281,
14,
3098,
63,
9688,
10375,
63,
5214,
492,
4789,
63,
493,
63,
2308,
199,
504,
477,
276,
14,
1548,
14,
12281,
14,
3098,
63,
9688,
10375,
63,
5214,
492,
7186,
199,
199,
1760,
63,
589,
275,
488,
421,
199,
318,
2446,
8,
3020,
304,
523,
340,
822,
8,
3020,
9,
690,
413,
26,
272,
746,
6064,
360,
13749,
5002,
1414,
13,
604,
2368,
2659,
819,
327,
5574,
8744,
14,
523,
870,
360,
20568,
8744,
15103,
523,
4575,
63,
14458,
12,
5726,
63,
14458,
12,
5525,
63,
1580,
275,
4789,
63,
493,
63,
2308,
14,
3284,
24277,
8,
489,
2088,
63,
589,
14,
14458,
63,
515,
12,
4789,
63,
493,
63,
2308,
14,
907,
1439,
15306,
12039,
63,
17179,
63,
998,
9,
523,
870,
360,
4456,
10916,
819,
327,
5574,
7914,
14,
523,
870,
360,
20568,
7914,
15103,
523,
4575,
63,
9869,
12,
5726,
63,
9869,
275,
4789,
63,
493,
63,
2308,
14,
3284,
14730,
2452,
8,
489,
2088,
63,
589,
14,
9869,
63,
515,
12,
663,
8,
3455,
63,
14458,
14,
1612,
4000,
489,
663,
8,
4239,
63,
14458,
14,
1612,
4000,
663,
8,
11996,
63,
1580,
395,
489,
4789,
63,
493,
63,
2308,
14,
907,
1439,
15306,
12039,
63,
17179,
63,
998,
9,
523,
870,
360,
4456,
10916,
819,
327,
13641,
437,
3652,
5543,
3688,
14,
523,
870,
360,
5815,
1801,
26537,
358,
523,
870,
14097,
9885,
9,
221,
13641,
437,
3652,
5543,
3688,
26,
450,
70,
7,
450,
267,
7186,
14,
7025,
17400,
28984,
8,
3455,
63,
9869,
12,
4575,
63,
14458,
430,
523,
870,
14097,
12185,
9,
13641,
437,
3652,
5543,
3688,
26,
450,
70,
7,
450,
267,
7186,
14,
7025,
17400,
28984,
8,
4239,
63,
9869,
12,
5726,
63,
14458,
430,
819,
327,
13641,
437,
3652,
5543,
3688,
17289,
2222,
13,
9688,
1657,
9212,
14,
523,
870,
360,
5815,
1801,
26537,
358,
523,
870,
8,
489,
8189,
9885,
9,
221,
13641,
437,
3652,
5543,
3688,
17289,
2222,
13,
9688,
1657,
9212,
26,
450,
70,
7,
450,
489,
7186,
14,
7025,
17400,
28984,
8,
881,
4575,
63,
9869,
12,
4575,
63,
14458,
12,
3686,
63,
2865,
63,
3308,
63,
396,
63,
4782,
29,
549,
430,
523,
870,
8,
489,
8189,
12185,
9,
13641,
437,
3652,
5543,
3688,
17289,
2222,
13,
9688,
1657,
9212,
26,
450,
70,
7,
450,
489,
7186,
14,
7025,
17400,
28984,
8,
881,
5726,
63,
9869,
12,
5726,
63,
14458,
12,
881,
3686,
63,
2865,
63,
3308,
63,
396,
63,
4782,
29,
549,
430,
819,
327,
14132,
13,
17,
12862,
14,
523,
870,
360,
5815,
1801,
26537,
358,
523,
870,
14097,
9885,
9,
221,
14132,
13,
17,
12862,
26,
10536,
18,
70,
7,
450,
267,
334,
1960,
14,
16,
627,
7186,
14,
6105,
17,
1945,
7933,
8,
3455,
63,
9869,
12,
4575,
63,
14458,
1724,
523,
870,
14097,
12185,
9,
14132,
13,
17,
12862,
26,
10536,
18,
70,
7,
450,
267,
334,
1960,
14,
16,
627,
7186,
14,
6105,
17,
1945,
7933,
8,
4239,
63,
9869,
12,
5726,
63,
14458,
1724,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
1798,
275,
7534,
14,
10730,
342,
523,
1798,
14,
2683,
360,
466,
297,
283,
2245,
297,
2400,
373,
26,
373,
14,
2325,
342,
508,
283,
2052,
358,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
9869,
63,
515,
297,
489,
730,
29,
495,
12,
489,
849,
8805,
2791,
15,
9869,
14,
4737,
297,
489,
1720,
11916,
489,
6912,
370,
14689,
7914,
570,
12,
7871,
543,
4362,
283,
344,
12,
9688,
10375,
7,
334,
1589,
489,
570,
1077,
2387,
282,
1406,
680,
489,
7857,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
14458,
63,
515,
297,
489,
730,
29,
495,
12,
489,
849,
8805,
2791,
15,
14458,
14,
4737,
297,
489,
1720,
11916,
489,
6912,
370,
14689,
8744,
570,
12,
7871,
543,
4362,
283,
344,
12,
9688,
10375,
12,
7692,
7,
489,
334,
1589,
570,
1077,
2387,
282,
1406,
680,
489,
7857,
523,
2088,
63,
589,
12,
31857,
275,
1798,
14,
1122,
63,
3159,
63,
589,
342,
523,
1145,
14,
1065,
8,
973,
29,
973,
12,
9238,
1524,
1274,
14,
3020,
59,
16,
2677,
435,
31857,
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,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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
tximikel/kuma
|
kuma/search/views.py
|
18
|
3210
|
import json
from django.http import HttpResponse, HttpResponseBadRequest
from django.shortcuts import render
from django.views.decorators.cache import cache_page
from rest_framework.generics import ListAPIView
from rest_framework.renderers import JSONRenderer
from kuma.wiki.search import WikiDocumentType
from .exceptions import ValidationError
from .filters import (AdvancedSearchQueryBackend, DatabaseFilterBackend,
get_filters, HighlightFilterBackend,
LanguageFilterBackend, SearchQueryBackend)
from .jobs import AvailableFiltersJob
from .paginator import SearchPaginator
from .renderers import ExtendedTemplateHTMLRenderer
from .serializers import (DocumentSerializer, FilterWithGroupSerializer,
SearchQuerySerializer, SearchSerializer)
class SearchView(ListAPIView):
http_method_names = ['get']
serializer_class = DocumentSerializer
renderer_classes = (
ExtendedTemplateHTMLRenderer,
JSONRenderer,
)
#: list of filters to applies in order of listing, each implementing
#: the specific search feature
filter_backends = (
SearchQueryBackend,
AdvancedSearchQueryBackend,
DatabaseFilterBackend,
LanguageFilterBackend,
HighlightFilterBackend,
)
paginator_class = SearchPaginator
paginate_by = 10
max_paginate_by = 100
paginate_by_param = 'per_page'
pagination_serializer_class = SearchSerializer
def initial(self, request, *args, **kwargs):
super(SearchView, self).initial(request, *args, **kwargs)
self.current_page = self.request.QUERY_PARAMS.get(self.page_kwarg, 1)
self.available_filters = AvailableFiltersJob().get()
self.serialized_filters = (
FilterWithGroupSerializer(self.available_filters, many=True).data)
self.selected_filters = get_filters(self.request.QUERY_PARAMS.getlist)
self.query_params = {}
def get_queryset(self):
return WikiDocumentType.search()
def list(self, request, *args, **kwargs):
"""
We override the `list` method here to store the URL.
"""
# Stash some data here for the serializer.
self.url = request.get_full_path()
query_params = SearchQuerySerializer(data=request.QUERY_PARAMS)
if not query_params.is_valid():
raise ValidationError(query_params.errors)
self.query_params = query_params.data
return super(SearchView, self).list(request, *args, **kwargs)
search = SearchView.as_view()
@cache_page(60 * 15) # 15 minutes.
def suggestions(request):
"""Return empty array until we restore internal search system."""
content_type = 'application/x-suggestions+json'
term = request.GET.get('q')
if not term:
return HttpResponseBadRequest(content_type=content_type)
results = []
return HttpResponse(json.dumps(results), content_type=content_type)
@cache_page(60 * 60 * 168) # 1 week.
def plugin(request):
"""Render an OpenSearch Plugin."""
return render(request, 'search/plugin.html', {
'locale': request.locale
}, content_type='application/opensearchdescription+xml')
|
mpl-2.0
|
[
646,
2022,
199,
199,
504,
1639,
14,
1014,
492,
6183,
12,
6183,
12380,
199,
504,
1639,
14,
17469,
492,
3795,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1637,
492,
2581,
63,
1606,
199,
199,
504,
4618,
63,
4857,
14,
2038,
2932,
492,
3820,
25778,
199,
504,
4618,
63,
4857,
14,
828,
26529,
492,
4840,
11355,
199,
199,
504,
1022,
85,
391,
14,
6797,
14,
1733,
492,
644,
11545,
5564,
804,
199,
199,
504,
1275,
3924,
492,
8505,
199,
504,
1275,
4273,
492,
334,
23613,
5278,
3227,
8447,
12,
8692,
4131,
8447,
12,
1993,
664,
63,
4273,
12,
16332,
4040,
4131,
8447,
12,
1993,
8466,
4131,
8447,
12,
8730,
3227,
8447,
9,
199,
504,
1275,
6920,
492,
23840,
18053,
6694,
199,
504,
1275,
22073,
492,
8730,
23862,
8566,
199,
504,
1275,
828,
26529,
492,
13706,
4231,
4943,
11355,
199,
504,
1275,
12844,
492,
334,
5564,
7299,
12,
9388,
3007,
2448,
7299,
12,
2079,
8730,
3227,
7299,
12,
8730,
7299,
9,
421,
199,
533,
8730,
2768,
8,
1296,
25778,
304,
272,
1455,
63,
765,
63,
1247,
275,
788,
362,
418,
272,
9146,
63,
533,
275,
7543,
7299,
272,
11889,
63,
2888,
275,
334,
267,
13706,
4231,
4943,
11355,
12,
267,
4840,
11355,
12,
272,
776,
272,
6079,
769,
402,
4766,
370,
12966,
315,
1865,
402,
13778,
12,
1924,
18234,
272,
6079,
314,
2488,
2754,
3878,
272,
2457,
63,
7765,
275,
334,
267,
8730,
3227,
8447,
12,
267,
32445,
5278,
3227,
8447,
12,
267,
8692,
4131,
8447,
12,
267,
8466,
4131,
8447,
12,
267,
16332,
4040,
4131,
8447,
12,
272,
776,
272,
21398,
63,
533,
275,
8730,
23862,
8566,
272,
9881,
23043,
63,
991,
275,
1616,
272,
1390,
63,
30979,
63,
991,
275,
2948,
272,
9881,
23043,
63,
991,
63,
635,
275,
283,
529,
63,
1606,
7,
272,
21192,
63,
8349,
63,
533,
275,
8730,
7299,
339,
347,
2536,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
5278,
2768,
12,
291,
680,
2747,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
267,
291,
14,
1818,
63,
1606,
275,
291,
14,
1069,
14,
11938,
63,
17978,
14,
362,
8,
277,
14,
1606,
63,
12745,
12,
413,
9,
267,
291,
14,
4561,
63,
4273,
275,
23840,
18053,
6694,
1252,
362,
342,
267,
291,
14,
8397,
63,
4273,
275,
334,
288,
9388,
3007,
2448,
7299,
8,
277,
14,
4561,
63,
4273,
12,
5002,
29,
549,
680,
576,
9,
267,
291,
14,
5511,
63,
4273,
275,
664,
63,
4273,
8,
277,
14,
1069,
14,
11938,
63,
17978,
14,
21343,
9,
267,
291,
14,
1131,
63,
1162,
275,
1052,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
372,
644,
11545,
5564,
804,
14,
1733,
342,
339,
347,
769,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
267,
2136,
4278,
314,
658,
513,
64,
1083,
2348,
370,
3877,
314,
2851,
14,
267,
408,
267,
327,
10126,
2005,
666,
2348,
367,
314,
9146,
14,
267,
291,
14,
633,
275,
1056,
14,
362,
63,
2861,
63,
515,
342,
267,
1827,
63,
1162,
275,
8730,
3227,
7299,
8,
576,
29,
1069,
14,
11938,
63,
17978,
9,
267,
340,
440,
1827,
63,
1162,
14,
374,
63,
1078,
837,
288,
746,
8505,
8,
1131,
63,
1162,
14,
2550,
9,
267,
291,
14,
1131,
63,
1162,
275,
1827,
63,
1162,
14,
576,
398,
372,
1613,
8,
5278,
2768,
12,
291,
680,
513,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
421,
199,
1733,
275,
8730,
2768,
14,
305,
63,
1345,
342,
421,
199,
32,
1637,
63,
1606,
8,
2259,
627,
4114,
9,
221,
327,
4114,
9395,
14,
199,
318,
18453,
15293,
8,
1069,
304,
272,
408,
1767,
2701,
1625,
5133,
781,
9066,
5007,
2754,
2656,
1041,
339,
1564,
63,
466,
275,
283,
3578,
15,
88,
13,
19957,
15293,
11,
1001,
7,
339,
6707,
275,
1056,
14,
2970,
14,
362,
360,
81,
358,
272,
340,
440,
6707,
26,
267,
372,
6183,
12380,
8,
1317,
63,
466,
29,
1317,
63,
466,
9,
339,
2058,
275,
942,
272,
372,
6183,
8,
1001,
14,
4180,
8,
2604,
395,
1564,
63,
466,
29,
1317,
63,
466,
9,
421,
199,
32,
1637,
63,
1606,
8,
2259,
627,
5212,
627,
413,
2333,
9,
221,
327,
413,
8620,
14,
199,
318,
3589,
8,
1069,
304,
272,
408,
9216,
376,
32617,
11349,
1041,
272,
372,
3795,
8,
1069,
12,
283,
1733,
15,
2718,
14,
1360,
297,
469,
267,
283,
5508,
356,
1056,
14,
5508,
272,
1660,
1564,
63,
466,
534,
3578,
15,
27285,
1802,
11,
1652,
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
] |
[
2022,
199,
199,
504,
1639,
14,
1014,
492,
6183,
12,
6183,
12380,
199,
504,
1639,
14,
17469,
492,
3795,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1637,
492,
2581,
63,
1606,
199,
199,
504,
4618,
63,
4857,
14,
2038,
2932,
492,
3820,
25778,
199,
504,
4618,
63,
4857,
14,
828,
26529,
492,
4840,
11355,
199,
199,
504,
1022,
85,
391,
14,
6797,
14,
1733,
492,
644,
11545,
5564,
804,
199,
199,
504,
1275,
3924,
492,
8505,
199,
504,
1275,
4273,
492,
334,
23613,
5278,
3227,
8447,
12,
8692,
4131,
8447,
12,
1993,
664,
63,
4273,
12,
16332,
4040,
4131,
8447,
12,
1993,
8466,
4131,
8447,
12,
8730,
3227,
8447,
9,
199,
504,
1275,
6920,
492,
23840,
18053,
6694,
199,
504,
1275,
22073,
492,
8730,
23862,
8566,
199,
504,
1275,
828,
26529,
492,
13706,
4231,
4943,
11355,
199,
504,
1275,
12844,
492,
334,
5564,
7299,
12,
9388,
3007,
2448,
7299,
12,
2079,
8730,
3227,
7299,
12,
8730,
7299,
9,
421,
199,
533,
8730,
2768,
8,
1296,
25778,
304,
272,
1455,
63,
765,
63,
1247,
275,
788,
362,
418,
272,
9146,
63,
533,
275,
7543,
7299,
272,
11889,
63,
2888,
275,
334,
267,
13706,
4231,
4943,
11355,
12,
267,
4840,
11355,
12,
272,
776,
272,
6079,
769,
402,
4766,
370,
12966,
315,
1865,
402,
13778,
12,
1924,
18234,
272,
6079,
314,
2488,
2754,
3878,
272,
2457,
63,
7765,
275,
334,
267,
8730,
3227,
8447,
12,
267,
32445,
5278,
3227,
8447,
12,
267,
8692,
4131,
8447,
12,
267,
8466,
4131,
8447,
12,
267,
16332,
4040,
4131,
8447,
12,
272,
776,
272,
21398,
63,
533,
275,
8730,
23862,
8566,
272,
9881,
23043,
63,
991,
275,
1616,
272,
1390,
63,
30979,
63,
991,
275,
2948,
272,
9881,
23043,
63,
991,
63,
635,
275,
283,
529,
63,
1606,
7,
272,
21192,
63,
8349,
63,
533,
275,
8730,
7299,
339,
347,
2536,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
5278,
2768,
12,
291,
680,
2747,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
267,
291,
14,
1818,
63,
1606,
275,
291,
14,
1069,
14,
11938,
63,
17978,
14,
362,
8,
277,
14,
1606,
63,
12745,
12,
413,
9,
267,
291,
14,
4561,
63,
4273,
275,
23840,
18053,
6694,
1252,
362,
342,
267,
291,
14,
8397,
63,
4273,
275,
334,
288,
9388,
3007,
2448,
7299,
8,
277,
14,
4561,
63,
4273,
12,
5002,
29,
549,
680,
576,
9,
267,
291,
14,
5511,
63,
4273,
275,
664,
63,
4273,
8,
277,
14,
1069,
14,
11938,
63,
17978,
14,
21343,
9,
267,
291,
14,
1131,
63,
1162,
275,
1052,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
372,
644,
11545,
5564,
804,
14,
1733,
342,
339,
347,
769,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
267,
2136,
4278,
314,
658,
513,
64,
1083,
2348,
370,
3877,
314,
2851,
14,
267,
408,
267,
327,
10126,
2005,
666,
2348,
367,
314,
9146,
14,
267,
291,
14,
633,
275,
1056,
14,
362,
63,
2861,
63,
515,
342,
267,
1827,
63,
1162,
275,
8730,
3227,
7299,
8,
576,
29,
1069,
14,
11938,
63,
17978,
9,
267,
340,
440,
1827,
63,
1162,
14,
374,
63,
1078,
837,
288,
746,
8505,
8,
1131,
63,
1162,
14,
2550,
9,
267,
291,
14,
1131,
63,
1162,
275,
1827,
63,
1162,
14,
576,
398,
372,
1613,
8,
5278,
2768,
12,
291,
680,
513,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
421,
199,
1733,
275,
8730,
2768,
14,
305,
63,
1345,
342,
421,
199,
32,
1637,
63,
1606,
8,
2259,
627,
4114,
9,
221,
327,
4114,
9395,
14,
199,
318,
18453,
15293,
8,
1069,
304,
272,
408,
1767,
2701,
1625,
5133,
781,
9066,
5007,
2754,
2656,
1041,
339,
1564,
63,
466,
275,
283,
3578,
15,
88,
13,
19957,
15293,
11,
1001,
7,
339,
6707,
275,
1056,
14,
2970,
14,
362,
360,
81,
358,
272,
340,
440,
6707,
26,
267,
372,
6183,
12380,
8,
1317,
63,
466,
29,
1317,
63,
466,
9,
339,
2058,
275,
942,
272,
372,
6183,
8,
1001,
14,
4180,
8,
2604,
395,
1564,
63,
466,
29,
1317,
63,
466,
9,
421,
199,
32,
1637,
63,
1606,
8,
2259,
627,
5212,
627,
413,
2333,
9,
221,
327,
413,
8620,
14,
199,
318,
3589,
8,
1069,
304,
272,
408,
9216,
376,
32617,
11349,
1041,
272,
372,
3795,
8,
1069,
12,
283,
1733,
15,
2718,
14,
1360,
297,
469,
267,
283,
5508,
356,
1056,
14,
5508,
272,
1660,
1564,
63,
466,
534,
3578,
15,
27285,
1802,
11,
1652,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
googleapis/python-api-core
|
owlbot.py
|
1
|
1224
|
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This script is used to synthesize generated parts of this library."""
import synthtool as s
from synthtool import gcp
common = gcp.CommonTemplates()
# ----------------------------------------------------------------------------
# Add templated files
# ----------------------------------------------------------------------------
templated_files = common.py_library(cov_level=100)
s.move(templated_files, excludes=["noxfile.py", ".flake8", ".coveragerc", "setup.cfg"])
# Add pytype support
s.replace(
".gitignore",
"""\
.pytest_cache
""",
"""\
.pytest_cache
.pytype
""",
)
s.shell.run(["nox", "-s", "blacken"], hide_output=False)
|
apache-2.0
|
[
3,
1898,
25455,
4475,
20376,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
2765,
2884,
365,
1202,
370,
9560,
1589,
890,
4046,
4184,
402,
642,
3555,
1041,
199,
199,
646,
9560,
273,
3557,
465,
308,
199,
504,
9560,
273,
3557,
492,
22088,
199,
199,
2330,
275,
22088,
14,
7844,
17969,
342,
199,
199,
3,
27103,
199,
3,
2654,
27960,
1584,
199,
3,
27103,
199,
1160,
68,
63,
1725,
275,
2863,
14,
647,
63,
4342,
8,
8695,
63,
1896,
29,
1960,
9,
199,
83,
14,
1185,
8,
1160,
68,
63,
1725,
12,
23388,
6270,
889,
88,
493,
14,
647,
401,
3680,
14163,
415,
24,
401,
3680,
5899,
1456,
67,
401,
298,
2758,
14,
4128,
3135,
199,
199,
3,
2654,
1134,
466,
2291,
199,
83,
14,
1814,
8,
272,
3680,
71,
5277,
7160,
401,
272,
9638,
199,
14,
4462,
63,
1637,
199,
7208,
272,
9638,
199,
14,
4462,
63,
1637,
199,
14,
647,
466,
199,
7208,
199,
9,
199,
199,
83,
14,
5641,
14,
1065,
5234,
889,
88,
401,
3905,
83,
401,
298,
8399,
287,
2255,
13714,
63,
1199,
29,
797,
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
] |
[
1898,
25455,
4475,
20376,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
2765,
2884,
365,
1202,
370,
9560,
1589,
890,
4046,
4184,
402,
642,
3555,
1041,
199,
199,
646,
9560,
273,
3557,
465,
308,
199,
504,
9560,
273,
3557,
492,
22088,
199,
199,
2330,
275,
22088,
14,
7844,
17969,
342,
199,
199,
3,
27103,
199,
3,
2654,
27960,
1584,
199,
3,
27103,
199,
1160,
68,
63,
1725,
275,
2863,
14,
647,
63,
4342,
8,
8695,
63,
1896,
29,
1960,
9,
199,
83,
14,
1185,
8,
1160,
68,
63,
1725,
12,
23388,
6270,
889,
88,
493,
14,
647,
401,
3680,
14163,
415,
24,
401,
3680,
5899,
1456,
67,
401,
298,
2758,
14,
4128,
3135,
199,
199,
3,
2654,
1134,
466,
2291,
199,
83,
14,
1814,
8,
272,
3680,
71,
5277,
7160,
401,
272,
9638,
199,
14,
4462,
63,
1637,
199,
7208,
272,
9638,
199,
14,
4462,
63,
1637,
199,
14,
647,
466,
199,
7208,
199,
9,
199,
199,
83,
14,
5641,
14,
1065,
5234,
889,
88,
401,
3905,
83,
401,
298,
8399,
287,
2255,
13714,
63,
1199,
29,
797,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kohr-h/odl
|
odl/test/tomo/backends/skimage_test.py
|
2
|
1554
|
# Copyright 2014-2017 The ODL contributors
#
# This file is part of ODL.
#
# 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/.
"""Test skimage back-end."""
from __future__ import division
import numpy as np
import odl
from odl.tomo.backends.skimage_radon import (
skimage_radon_forward_projector, skimage_radon_back_projector)
from odl.tomo.util.testutils import skip_if_no_skimage
@skip_if_no_skimage
def test_skimage_radon_projector_parallel2d():
"""Parallel 2D forward and backward projectors with skimage."""
# Create reco space and a phantom
reco_space = odl.uniform_discr([-5, -5], [5, 5], (5, 5))
phantom = odl.phantom.cuboid(reco_space, min_pt=[0, 0], max_pt=[5, 5])
# Create parallel geometry
angle_part = odl.uniform_partition(0, np.pi, 5)
det_part = odl.uniform_partition(-6, 6, 6)
geom = odl.tomo.Parallel2dGeometry(angle_part, det_part)
# Make projection space
proj_space = odl.uniform_discr_frompartition(geom.partition)
# Forward evaluation
proj_data = skimage_radon_forward_projector(phantom, geom, proj_space)
assert proj_data.shape == proj_space.shape
assert proj_data.norm() > 0
# Backward evaluation
backproj = skimage_radon_back_projector(proj_data, geom, reco_space)
assert backproj.shape == reco_space.shape
assert backproj.norm() > 0
if __name__ == '__main__':
odl.util.test_file(__file__)
|
mpl-2.0
|
[
3,
1898,
6927,
13,
10680,
710,
593,
8045,
8417,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
593,
8045,
14,
199,
3,
199,
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
844,
12,
199,
3,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
570,
12,
2047,
883,
199,
3,
3332,
1373,
737,
4178,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
624,
774,
2386,
1569,
1771,
13,
500,
1041,
199,
199,
504,
636,
2443,
363,
492,
4629,
199,
646,
2680,
465,
980,
199,
199,
646,
312,
5030,
199,
504,
312,
5030,
14,
475,
573,
14,
7765,
14,
1339,
1569,
63,
9525,
265,
492,
334,
272,
2386,
1569,
63,
9525,
265,
63,
6688,
63,
1715,
269,
12,
2386,
1569,
63,
9525,
265,
63,
894,
63,
1715,
269,
9,
199,
504,
312,
5030,
14,
475,
573,
14,
1974,
14,
396,
1208,
492,
3372,
63,
692,
63,
889,
63,
1339,
1569,
421,
199,
32,
2759,
63,
692,
63,
889,
63,
1339,
1569,
199,
318,
511,
63,
1339,
1569,
63,
9525,
265,
63,
1715,
269,
63,
11887,
18,
68,
837,
272,
408,
25721,
499,
36,
7568,
436,
13388,
2199,
1384,
543,
2386,
1569,
1041,
339,
327,
2790,
295,
331,
4601,
436,
282,
3945,
290,
3151,
272,
295,
331,
63,
2638,
275,
312,
5030,
14,
8830,
63,
6409,
82,
11468,
21,
12,
446,
21,
467,
359,
21,
12,
959,
467,
334,
21,
12,
959,
430,
272,
3945,
290,
3151,
275,
312,
5030,
14,
16014,
3151,
14,
18455,
1170,
8,
264,
331,
63,
2638,
12,
1748,
63,
541,
1524,
16,
12,
378,
467,
1390,
63,
541,
1524,
21,
12,
959,
566,
339,
327,
2790,
9861,
3400,
272,
9324,
63,
2064,
275,
312,
5030,
14,
8830,
63,
5312,
8,
16,
12,
980,
14,
1038,
12,
959,
9,
272,
20894,
63,
2064,
275,
312,
5030,
14,
8830,
63,
5312,
2801,
22,
12,
1227,
12,
1227,
9,
272,
9671,
275,
312,
5030,
14,
475,
573,
14,
25721,
18,
68,
6831,
8,
4593,
63,
2064,
12,
20894,
63,
2064,
9,
339,
327,
4155,
14777,
4601,
272,
13523,
63,
2638,
275,
312,
5030,
14,
8830,
63,
6409,
82,
63,
21775,
311,
285,
3348,
8,
6481,
14,
5312,
9,
339,
327,
22536,
11735,
272,
13523,
63,
576,
275,
2386,
1569,
63,
9525,
265,
63,
6688,
63,
1715,
269,
8,
16014,
3151,
12,
9671,
12,
13523,
63,
2638,
9,
272,
702,
13523,
63,
576,
14,
1392,
508,
13523,
63,
2638,
14,
1392,
272,
702,
13523,
63,
576,
14,
4791,
342,
690,
378,
339,
327,
10257,
3079,
11735,
272,
1771,
5468,
275,
2386,
1569,
63,
9525,
265,
63,
894,
63,
1715,
269,
8,
5468,
63,
576,
12,
9671,
12,
295,
331,
63,
2638,
9,
272,
702,
1771,
5468,
14,
1392,
508,
295,
331,
63,
2638,
14,
1392,
272,
702,
1771,
5468,
14,
4791,
342,
690,
378,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
312,
5030,
14,
1974,
14,
396,
63,
493,
3460,
493,
3368,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6927,
13,
10680,
710,
593,
8045,
8417,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
593,
8045,
14,
199,
3,
199,
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
844,
12,
199,
3,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
570,
12,
2047,
883,
199,
3,
3332,
1373,
737,
4178,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
624,
774,
2386,
1569,
1771,
13,
500,
1041,
199,
199,
504,
636,
2443,
363,
492,
4629,
199,
646,
2680,
465,
980,
199,
199,
646,
312,
5030,
199,
504,
312,
5030,
14,
475,
573,
14,
7765,
14,
1339,
1569,
63,
9525,
265,
492,
334,
272,
2386,
1569,
63,
9525,
265,
63,
6688,
63,
1715,
269,
12,
2386,
1569,
63,
9525,
265,
63,
894,
63,
1715,
269,
9,
199,
504,
312,
5030,
14,
475,
573,
14,
1974,
14,
396,
1208,
492,
3372,
63,
692,
63,
889,
63,
1339,
1569,
421,
199,
32,
2759,
63,
692,
63,
889,
63,
1339,
1569,
199,
318,
511,
63,
1339,
1569,
63,
9525,
265,
63,
1715,
269,
63,
11887,
18,
68,
837,
272,
408,
25721,
499,
36,
7568,
436,
13388,
2199,
1384,
543,
2386,
1569,
1041,
339,
327,
2790,
295,
331,
4601,
436,
282,
3945,
290,
3151,
272,
295,
331,
63,
2638,
275,
312,
5030,
14,
8830,
63,
6409,
82,
11468,
21,
12,
446,
21,
467,
359,
21,
12,
959,
467,
334,
21,
12,
959,
430,
272,
3945,
290,
3151,
275,
312,
5030,
14,
16014,
3151,
14,
18455,
1170,
8,
264,
331,
63,
2638,
12,
1748,
63,
541,
1524,
16,
12,
378,
467,
1390,
63,
541,
1524,
21,
12,
959,
566,
339,
327,
2790,
9861,
3400,
272,
9324,
63,
2064,
275,
312,
5030,
14,
8830,
63,
5312,
8,
16,
12,
980,
14,
1038,
12,
959,
9,
272,
20894,
63,
2064,
275,
312,
5030,
14,
8830,
63,
5312,
2801,
22,
12,
1227,
12,
1227,
9,
272,
9671,
275,
312,
5030,
14,
475,
573,
14,
25721,
18,
68,
6831,
8,
4593,
63,
2064,
12,
20894,
63,
2064,
9,
339,
327,
4155,
14777,
4601,
272,
13523,
63,
2638,
275,
312,
5030,
14,
8830,
63,
6409,
82,
63,
21775,
311,
285,
3348,
8,
6481,
14,
5312,
9,
339,
327,
22536,
11735,
272,
13523,
63,
576,
275,
2386,
1569,
63,
9525,
265,
63,
6688,
63,
1715,
269,
8,
16014,
3151,
12,
9671,
12,
13523,
63,
2638,
9,
272,
702,
13523,
63,
576,
14,
1392,
508,
13523,
63,
2638,
14,
1392,
272,
702,
13523,
63,
576,
14,
4791,
342,
690,
378,
339,
327,
10257,
3079,
11735,
272,
1771,
5468,
275,
2386,
1569,
63,
9525,
265,
63,
894,
63,
1715,
269,
8,
5468,
63,
576,
12,
9671,
12,
295,
331,
63,
2638,
9,
272,
702,
1771,
5468,
14,
1392,
508,
295,
331,
63,
2638,
14,
1392,
272,
702,
1771,
5468,
14,
4791,
342,
690,
378,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
312,
5030,
14,
1974,
14,
396,
63,
493,
3460,
493,
3368,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
insertnamehere1/maraschino
|
lib/sqlalchemy/dialects/maxdb/base.py
|
22
|
42809
|
# maxdb/base.py
# Copyright (C) 2005-2011 the SQLAlchemy authors and contributors <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
"""Support for the MaxDB database.
This dialect is *not* ported to SQLAlchemy 0.6 or 0.7.
This dialect is *not* tested on SQLAlchemy 0.6 or 0.7.
Overview
--------
The ``maxdb`` dialect is **experimental** and has only been tested on 7.6.03.007
and 7.6.00.037. Of these, **only 7.6.03.007 will work** with SQLAlchemy's ORM.
The earlier version has severe ``LEFT JOIN`` limitations and will return
incorrect results from even very simple ORM queries.
Only the native Python DB-API is currently supported. ODBC driver support
is a future enhancement.
Connecting
----------
The username is case-sensitive. If you usually connect to the
database with sqlcli and other tools in lower case, you likely need to
use upper case for DB-API.
Implementation Notes
--------------------
With the 7.6.00.37 driver and Python 2.5, it seems that all DB-API
generated exceptions are broken and can cause Python to crash.
For 'somecol.in_([])' to work, the IN operator's generation must be changed
to cast 'NULL' to a numeric, i.e. NUM(NULL). The DB-API doesn't accept a
bind parameter there, so that particular generation must inline the NULL value,
which depends on [ticket:807].
The DB-API is very picky about where bind params may be used in queries.
Bind params for some functions (e.g. MOD) need type information supplied.
The dialect does not yet do this automatically.
Max will occasionally throw up 'bad sql, compile again' exceptions for
perfectly valid SQL. The dialect does not currently handle these, more
research is needed.
MaxDB 7.5 and Sap DB <= 7.4 reportedly do not support schemas. A very
slightly different version of this dialect would be required to support
those versions, and can easily be added if there is demand. Some other
required components such as an Max-aware 'old oracle style' join compiler
(thetas with (+) outer indicators) are already done and available for
integration- email the devel list if you're interested in working on
this.
Versions tested: 7.6.03.07 and 7.6.00.37, native Python DB-API
* MaxDB has severe limitations on OUTER JOINs, which are essential to ORM
eager loading. And rather than raise an error if a SELECT can't be serviced,
the database simply returns incorrect results.
* Version 7.6.03.07 seems to JOIN properly, however the docs do not show the
OUTER restrictions being lifted (as of this writing), and no changelog is
available to confirm either. If you are using a different server version and
your tasks require the ORM or any semi-advanced SQL through the SQL layer,
running the SQLAlchemy test suite against your database is HIGHLY
recommended before you begin.
* Version 7.6.00.37 is LHS/RHS sensitive in `FROM lhs LEFT OUTER JOIN rhs ON
lhs.col=rhs.col` vs `rhs.col=lhs.col`!
* Version 7.6.00.37 is confused by `SELECT DISTINCT col as alias FROM t ORDER
BY col` - these aliased, DISTINCT, ordered queries need to be re-written to
order by the alias name.
* Version 7.6.x supports creating a SAVEPOINT but not its RELEASE.
* MaxDB supports autoincrement-style columns (DEFAULT SERIAL) and independent
sequences. When including a DEFAULT SERIAL column in an insert, 0 needs to
be inserted rather than NULL to generate a value.
* MaxDB supports ANSI and "old Oracle style" theta joins with (+) outer join
indicators.
* The SQLAlchemy dialect is schema-aware and probably won't function correctly
on server versions (pre-7.6?). Support for schema-less server versions could
be added if there's call.
* ORDER BY is not supported in subqueries. LIMIT is not supported in
subqueries. In 7.6.00.37, TOP does work in subqueries, but without limit not
so useful. OFFSET does not work in 7.6 despite being in the docs. Row number
tricks in WHERE via ROWNO may be possible but it only seems to allow
less-than comparison!
* Version 7.6.03.07 can't LIMIT if a derived table is in FROM: `SELECT * FROM
(SELECT * FROM a) LIMIT 2`
* MaxDB does not support sql's CAST and can only usefullly cast two types.
There isn't much implicit type conversion, so be precise when creating
`PassiveDefaults` in DDL generation: `'3'` and `3` aren't the same.
sapdb.dbapi
^^^^^^^^^^^
* As of 2007-10-22 the Python 2.4 and 2.5 compatible versions of the DB-API
are no longer available. A forum posting at SAP states that the Python
driver will be available again "in the future". The last release from MySQL
AB works if you can find it.
* sequence.NEXTVAL skips every other value!
* No rowcount for executemany()
* If an INSERT into a table with a DEFAULT SERIAL column inserts the results
of a function `INSERT INTO t VALUES (LENGTH('foo'))`, the cursor won't have
the serial id. It needs to be manually yanked from tablename.CURRVAL.
* Super-duper picky about where bind params can be placed. Not smart about
converting Python types for some functions, such as `MOD(5, ?)`.
* LONG (text, binary) values in result sets are read-once. The dialect uses a
caching RowProxy when these types are present.
* Connection objects seem like they want to be either `close()`d or garbage
collected, but not both. There's a warning issued but it seems harmless.
"""
import datetime, itertools, re
from sqlalchemy import exc, schema, sql, util, processors
from sqlalchemy.sql import operators as sql_operators, expression as sql_expr
from sqlalchemy.sql import compiler, visitors
from sqlalchemy.engine import base as engine_base, default, reflection
from sqlalchemy import types as sqltypes
class _StringType(sqltypes.String):
_type = None
def __init__(self, length=None, encoding=None, **kw):
super(_StringType, self).__init__(length=length, **kw)
self.encoding = encoding
def bind_processor(self, dialect):
if self.encoding == 'unicode':
return None
else:
def process(value):
if isinstance(value, unicode):
return value.encode(dialect.encoding)
else:
return value
return process
def result_processor(self, dialect, coltype):
#XXX: this code is probably very slow and one should try (if at all
# possible) to determine the correct code path on a per-connection
# basis (ie, here in result_processor, instead of inside the processor
# function itself) and probably also use a few generic
# processors, or possibly per query (though there is no mechanism
# for that yet).
def process(value):
while True:
if value is None:
return None
elif isinstance(value, unicode):
return value
elif isinstance(value, str):
if self.convert_unicode or dialect.convert_unicode:
return value.decode(dialect.encoding)
else:
return value
elif hasattr(value, 'read'):
# some sort of LONG, snarf and retry
value = value.read(value.remainingLength())
continue
else:
# unexpected type, return as-is
return value
return process
class MaxString(_StringType):
_type = 'VARCHAR'
class MaxUnicode(_StringType):
_type = 'VARCHAR'
def __init__(self, length=None, **kw):
kw['encoding'] = 'unicode'
super(MaxUnicode, self).__init__(length=length, **kw)
class MaxChar(_StringType):
_type = 'CHAR'
class MaxText(_StringType):
_type = 'LONG'
def __init__(self, length=None, **kw):
super(MaxText, self).__init__(length, **kw)
def get_col_spec(self):
spec = 'LONG'
if self.encoding is not None:
spec = ' '.join((spec, self.encoding))
elif self.convert_unicode:
spec = ' '.join((spec, 'UNICODE'))
return spec
class MaxNumeric(sqltypes.Numeric):
"""The FIXED (also NUMERIC, DECIMAL) data type."""
def __init__(self, precision=None, scale=None, **kw):
kw.setdefault('asdecimal', True)
super(MaxNumeric, self).__init__(scale=scale, precision=precision,
**kw)
def bind_processor(self, dialect):
return None
class MaxTimestamp(sqltypes.DateTime):
def bind_processor(self, dialect):
def process(value):
if value is None:
return None
elif isinstance(value, basestring):
return value
elif dialect.datetimeformat == 'internal':
ms = getattr(value, 'microsecond', 0)
return value.strftime("%Y%m%d%H%M%S" + ("%06u" % ms))
elif dialect.datetimeformat == 'iso':
ms = getattr(value, 'microsecond', 0)
return value.strftime("%Y-%m-%d %H:%M:%S." + ("%06u" % ms))
else:
raise exc.InvalidRequestError(
"datetimeformat '%s' is not supported." % (
dialect.datetimeformat,))
return process
def result_processor(self, dialect, coltype):
if dialect.datetimeformat == 'internal':
def process(value):
if value is None:
return None
else:
return datetime.datetime(
*[int(v)
for v in (value[0:4], value[4:6], value[6:8],
value[8:10], value[10:12], value[12:14],
value[14:])])
elif dialect.datetimeformat == 'iso':
def process(value):
if value is None:
return None
else:
return datetime.datetime(
*[int(v)
for v in (value[0:4], value[5:7], value[8:10],
value[11:13], value[14:16], value[17:19],
value[20:])])
else:
raise exc.InvalidRequestError(
"datetimeformat '%s' is not supported." %
dialect.datetimeformat)
return process
class MaxDate(sqltypes.Date):
def bind_processor(self, dialect):
def process(value):
if value is None:
return None
elif isinstance(value, basestring):
return value
elif dialect.datetimeformat == 'internal':
return value.strftime("%Y%m%d")
elif dialect.datetimeformat == 'iso':
return value.strftime("%Y-%m-%d")
else:
raise exc.InvalidRequestError(
"datetimeformat '%s' is not supported." % (
dialect.datetimeformat,))
return process
def result_processor(self, dialect, coltype):
if dialect.datetimeformat == 'internal':
def process(value):
if value is None:
return None
else:
return datetime.date(int(value[0:4]), int(value[4:6]),
int(value[6:8]))
elif dialect.datetimeformat == 'iso':
def process(value):
if value is None:
return None
else:
return datetime.date(int(value[0:4]), int(value[5:7]),
int(value[8:10]))
else:
raise exc.InvalidRequestError(
"datetimeformat '%s' is not supported." %
dialect.datetimeformat)
return process
class MaxTime(sqltypes.Time):
def bind_processor(self, dialect):
def process(value):
if value is None:
return None
elif isinstance(value, basestring):
return value
elif dialect.datetimeformat == 'internal':
return value.strftime("%H%M%S")
elif dialect.datetimeformat == 'iso':
return value.strftime("%H-%M-%S")
else:
raise exc.InvalidRequestError(
"datetimeformat '%s' is not supported." % (
dialect.datetimeformat,))
return process
def result_processor(self, dialect, coltype):
if dialect.datetimeformat == 'internal':
def process(value):
if value is None:
return None
else:
return datetime.time(int(value[0:4]), int(value[4:6]),
int(value[6:8]))
elif dialect.datetimeformat == 'iso':
def process(value):
if value is None:
return None
else:
return datetime.time(int(value[0:4]), int(value[5:7]),
int(value[8:10]))
else:
raise exc.InvalidRequestError(
"datetimeformat '%s' is not supported." %
dialect.datetimeformat)
return process
class MaxBlob(sqltypes.LargeBinary):
def bind_processor(self, dialect):
return processors.to_str
def result_processor(self, dialect, coltype):
def process(value):
if value is None:
return None
else:
return value.read(value.remainingLength())
return process
class MaxDBTypeCompiler(compiler.GenericTypeCompiler):
def _string_spec(self, string_spec, type_):
if type_.length is None:
spec = 'LONG'
else:
spec = '%s(%s)' % (string_spec, type_.length)
if getattr(type_, 'encoding'):
spec = ' '.join([spec, getattr(type_, 'encoding').upper()])
return spec
def visit_text(self, type_):
spec = 'LONG'
if getattr(type_, 'encoding', None):
spec = ' '.join((spec, type_.encoding))
elif type_.convert_unicode:
spec = ' '.join((spec, 'UNICODE'))
return spec
def visit_char(self, type_):
return self._string_spec("CHAR", type_)
def visit_string(self, type_):
return self._string_spec("VARCHAR", type_)
def visit_large_binary(self, type_):
return "LONG BYTE"
def visit_numeric(self, type_):
if type_.scale and type_.precision:
return 'FIXED(%s, %s)' % (type_.precision, type_.scale)
elif type_.precision:
return 'FIXED(%s)' % type_.precision
else:
return 'INTEGER'
def visit_BOOLEAN(self, type_):
return "BOOLEAN"
colspecs = {
sqltypes.Numeric: MaxNumeric,
sqltypes.DateTime: MaxTimestamp,
sqltypes.Date: MaxDate,
sqltypes.Time: MaxTime,
sqltypes.String: MaxString,
sqltypes.Unicode:MaxUnicode,
sqltypes.LargeBinary: MaxBlob,
sqltypes.Text: MaxText,
sqltypes.CHAR: MaxChar,
sqltypes.TIMESTAMP: MaxTimestamp,
sqltypes.BLOB: MaxBlob,
sqltypes.Unicode: MaxUnicode,
}
ischema_names = {
'boolean': sqltypes.BOOLEAN,
'char': sqltypes.CHAR,
'character': sqltypes.CHAR,
'date': sqltypes.DATE,
'fixed': sqltypes.Numeric,
'float': sqltypes.FLOAT,
'int': sqltypes.INT,
'integer': sqltypes.INT,
'long binary': sqltypes.BLOB,
'long unicode': sqltypes.Text,
'long': sqltypes.Text,
'long': sqltypes.Text,
'smallint': sqltypes.SmallInteger,
'time': sqltypes.Time,
'timestamp': sqltypes.TIMESTAMP,
'varchar': sqltypes.VARCHAR,
}
# TODO: migrate this to sapdb.py
class MaxDBExecutionContext(default.DefaultExecutionContext):
def post_exec(self):
# DB-API bug: if there were any functions as values,
# then do another select and pull CURRVAL from the
# autoincrement column's implicit sequence... ugh
if self.compiled.isinsert and not self.executemany:
table = self.compiled.statement.table
index, serial_col = _autoserial_column(table)
if serial_col and (not self.compiled._safeserial or
not(self._last_inserted_ids) or
self._last_inserted_ids[index] in (None, 0)):
if table.schema:
sql = "SELECT %s.CURRVAL FROM DUAL" % (
self.compiled.preparer.format_table(table))
else:
sql = "SELECT CURRENT_SCHEMA.%s.CURRVAL FROM DUAL" % (
self.compiled.preparer.format_table(table))
rs = self.cursor.execute(sql)
id = rs.fetchone()[0]
if not self._last_inserted_ids:
# This shouldn't ever be > 1? Right?
self._last_inserted_ids = \
[None] * len(table.primary_key.columns)
self._last_inserted_ids[index] = id
super(MaxDBExecutionContext, self).post_exec()
def get_result_proxy(self):
if self.cursor.description is not None:
for column in self.cursor.description:
if column[1] in ('Long Binary', 'Long', 'Long Unicode'):
return MaxDBResultProxy(self)
return engine_base.ResultProxy(self)
@property
def rowcount(self):
if hasattr(self, '_rowcount'):
return self._rowcount
else:
return self.cursor.rowcount
def fire_sequence(self, seq):
if seq.optional:
return None
return self._execute_scalar("SELECT %s.NEXTVAL FROM DUAL" % (
self.dialect.identifier_preparer.format_sequence(seq)))
class MaxDBCachedColumnRow(engine_base.RowProxy):
"""A RowProxy that only runs result_processors once per column."""
def __init__(self, parent, row):
super(MaxDBCachedColumnRow, self).__init__(parent, row)
self.columns = {}
self._row = row
self._parent = parent
def _get_col(self, key):
if key not in self.columns:
self.columns[key] = self._parent._get_col(self._row, key)
return self.columns[key]
def __iter__(self):
for i in xrange(len(self._row)):
yield self._get_col(i)
def __repr__(self):
return repr(list(self))
def __eq__(self, other):
return ((other is self) or
(other == tuple([self._get_col(key)
for key in xrange(len(self._row))])))
def __getitem__(self, key):
if isinstance(key, slice):
indices = key.indices(len(self._row))
return tuple([self._get_col(i) for i in xrange(*indices)])
else:
return self._get_col(key)
def __getattr__(self, name):
try:
return self._get_col(name)
except KeyError:
raise AttributeError(name)
class MaxDBResultProxy(engine_base.ResultProxy):
_process_row = MaxDBCachedColumnRow
class MaxDBCompiler(compiler.SQLCompiler):
function_conversion = {
'CURRENT_DATE': 'DATE',
'CURRENT_TIME': 'TIME',
'CURRENT_TIMESTAMP': 'TIMESTAMP',
}
# These functions must be written without parens when called with no
# parameters. e.g. 'SELECT DATE FROM DUAL' not 'SELECT DATE() FROM DUAL'
bare_functions = set([
'CURRENT_SCHEMA', 'DATE', 'FALSE', 'SYSDBA', 'TIME', 'TIMESTAMP',
'TIMEZONE', 'TRANSACTION', 'TRUE', 'USER', 'UID', 'USERGROUP',
'UTCDATE', 'UTCDIFF'])
def visit_mod(self, binary, **kw):
return "mod(%s, %s)" % \
(self.process(binary.left), self.process(binary.right))
def default_from(self):
return ' FROM DUAL'
def for_update_clause(self, select):
clause = select.for_update
if clause is True:
return " WITH LOCK EXCLUSIVE"
elif clause is None:
return ""
elif clause == "read":
return " WITH LOCK"
elif clause == "ignore":
return " WITH LOCK (IGNORE) EXCLUSIVE"
elif clause == "nowait":
return " WITH LOCK (NOWAIT) EXCLUSIVE"
elif isinstance(clause, basestring):
return " WITH LOCK %s" % clause.upper()
elif not clause:
return ""
else:
return " WITH LOCK EXCLUSIVE"
def function_argspec(self, fn, **kw):
if fn.name.upper() in self.bare_functions:
return ""
elif len(fn.clauses) > 0:
return compiler.SQLCompiler.function_argspec(self, fn, **kw)
else:
return ""
def visit_function(self, fn, **kw):
transform = self.function_conversion.get(fn.name.upper(), None)
if transform:
fn = fn._clone()
fn.name = transform
return super(MaxDBCompiler, self).visit_function(fn, **kw)
def visit_cast(self, cast, **kwargs):
# MaxDB only supports casts * to NUMERIC, * to VARCHAR or
# date/time to VARCHAR. Casts of LONGs will fail.
if isinstance(cast.type, (sqltypes.Integer, sqltypes.Numeric)):
return "NUM(%s)" % self.process(cast.clause)
elif isinstance(cast.type, sqltypes.String):
return "CHR(%s)" % self.process(cast.clause)
else:
return self.process(cast.clause)
def visit_sequence(self, sequence):
if sequence.optional:
return None
else:
return (
self.dialect.identifier_preparer.format_sequence(sequence) +
".NEXTVAL")
class ColumnSnagger(visitors.ClauseVisitor):
def __init__(self):
self.count = 0
self.column = None
def visit_column(self, column):
self.column = column
self.count += 1
def _find_labeled_columns(self, columns, use_labels=False):
labels = {}
for column in columns:
if isinstance(column, basestring):
continue
snagger = self.ColumnSnagger()
snagger.traverse(column)
if snagger.count == 1:
if isinstance(column, sql_expr._Label):
labels[unicode(snagger.column)] = column.name
elif use_labels:
labels[unicode(snagger.column)] = column._label
return labels
def order_by_clause(self, select, **kw):
order_by = self.process(select._order_by_clause, **kw)
# ORDER BY clauses in DISTINCT queries must reference aliased
# inner columns by alias name, not true column name.
if order_by and getattr(select, '_distinct', False):
labels = self._find_labeled_columns(select.inner_columns,
select.use_labels)
if labels:
for needs_alias in labels.keys():
r = re.compile(r'(^| )(%s)(,| |$)' %
re.escape(needs_alias))
order_by = r.sub((r'\1%s\3' % labels[needs_alias]),
order_by)
# No ORDER BY in subqueries.
if order_by:
if self.is_subquery():
# It's safe to simply drop the ORDER BY if there is no
# LIMIT. Right? Other dialects seem to get away with
# dropping order.
if select._limit:
raise exc.InvalidRequestError(
"MaxDB does not support ORDER BY in subqueries")
else:
return ""
return " ORDER BY " + order_by
else:
return ""
def get_select_precolumns(self, select):
# Convert a subquery's LIMIT to TOP
sql = select._distinct and 'DISTINCT ' or ''
if self.is_subquery() and select._limit:
if select._offset:
raise exc.InvalidRequestError(
'MaxDB does not support LIMIT with an offset.')
sql += 'TOP %s ' % select._limit
return sql
def limit_clause(self, select):
# The docs say offsets are supported with LIMIT. But they're not.
# TODO: maybe emulate by adding a ROWNO/ROWNUM predicate?
# TODO: does MaxDB support bind params for LIMIT / TOP ?
if self.is_subquery():
# sub queries need TOP
return ''
elif select._offset:
raise exc.InvalidRequestError(
'MaxDB does not support LIMIT with an offset.')
else:
return ' \n LIMIT %s' % (select._limit,)
def visit_insert(self, insert):
self.isinsert = True
self._safeserial = True
colparams = self._get_colparams(insert)
for value in (insert.parameters or {}).itervalues():
if isinstance(value, sql_expr.Function):
self._safeserial = False
break
return ''.join(('INSERT INTO ',
self.preparer.format_table(insert.table),
' (',
', '.join([self.preparer.format_column(c[0])
for c in colparams]),
') VALUES (',
', '.join([c[1] for c in colparams]),
')'))
class MaxDBIdentifierPreparer(compiler.IdentifierPreparer):
reserved_words = set([
'abs', 'absolute', 'acos', 'adddate', 'addtime', 'all', 'alpha',
'alter', 'any', 'ascii', 'asin', 'atan', 'atan2', 'avg', 'binary',
'bit', 'boolean', 'byte', 'case', 'ceil', 'ceiling', 'char',
'character', 'check', 'chr', 'column', 'concat', 'constraint', 'cos',
'cosh', 'cot', 'count', 'cross', 'curdate', 'current', 'curtime',
'database', 'date', 'datediff', 'day', 'dayname', 'dayofmonth',
'dayofweek', 'dayofyear', 'dec', 'decimal', 'decode', 'default',
'degrees', 'delete', 'digits', 'distinct', 'double', 'except',
'exists', 'exp', 'expand', 'first', 'fixed', 'float', 'floor', 'for',
'from', 'full', 'get_objectname', 'get_schema', 'graphic', 'greatest',
'group', 'having', 'hex', 'hextoraw', 'hour', 'ifnull', 'ignore',
'index', 'initcap', 'inner', 'insert', 'int', 'integer', 'internal',
'intersect', 'into', 'join', 'key', 'last', 'lcase', 'least', 'left',
'length', 'lfill', 'list', 'ln', 'locate', 'log', 'log10', 'long',
'longfile', 'lower', 'lpad', 'ltrim', 'makedate', 'maketime',
'mapchar', 'max', 'mbcs', 'microsecond', 'min', 'minute', 'mod',
'month', 'monthname', 'natural', 'nchar', 'next', 'no', 'noround',
'not', 'now', 'null', 'num', 'numeric', 'object', 'of', 'on',
'order', 'packed', 'pi', 'power', 'prev', 'primary', 'radians',
'real', 'reject', 'relative', 'replace', 'rfill', 'right', 'round',
'rowid', 'rowno', 'rpad', 'rtrim', 'second', 'select', 'selupd',
'serial', 'set', 'show', 'sign', 'sin', 'sinh', 'smallint', 'some',
'soundex', 'space', 'sqrt', 'stamp', 'statistics', 'stddev',
'subdate', 'substr', 'substring', 'subtime', 'sum', 'sysdba',
'table', 'tan', 'tanh', 'time', 'timediff', 'timestamp', 'timezone',
'to', 'toidentifier', 'transaction', 'translate', 'trim', 'trunc',
'truncate', 'ucase', 'uid', 'unicode', 'union', 'update', 'upper',
'user', 'usergroup', 'using', 'utcdate', 'utcdiff', 'value', 'values',
'varchar', 'vargraphic', 'variance', 'week', 'weekofyear', 'when',
'where', 'with', 'year', 'zoned' ])
def _normalize_name(self, name):
if name is None:
return None
if name.isupper():
lc_name = name.lower()
if not self._requires_quotes(lc_name):
return lc_name
return name
def _denormalize_name(self, name):
if name is None:
return None
elif (name.islower() and
not self._requires_quotes(name)):
return name.upper()
else:
return name
def _maybe_quote_identifier(self, name):
if self._requires_quotes(name):
return self.quote_identifier(name)
else:
return name
class MaxDBDDLCompiler(compiler.DDLCompiler):
def get_column_specification(self, column, **kw):
colspec = [self.preparer.format_column(column),
self.dialect.type_compiler.process(column.type)]
if not column.nullable:
colspec.append('NOT NULL')
default = column.default
default_str = self.get_column_default_string(column)
# No DDL default for columns specified with non-optional sequence-
# this defaulting behavior is entirely client-side. (And as a
# consequence, non-reflectable.)
if (default and isinstance(default, schema.Sequence) and
not default.optional):
pass
# Regular default
elif default_str is not None:
colspec.append('DEFAULT %s' % default_str)
# Assign DEFAULT SERIAL heuristically
elif column.primary_key and column.autoincrement:
# For SERIAL on a non-primary key member, use
# DefaultClause(text('SERIAL'))
try:
first = [c for c in column.table.primary_key.columns
if (c.autoincrement and
(isinstance(c.type, sqltypes.Integer) or
(isinstance(c.type, MaxNumeric) and
c.type.precision)) and
not c.foreign_keys)].pop(0)
if column is first:
colspec.append('DEFAULT SERIAL')
except IndexError:
pass
return ' '.join(colspec)
def get_column_default_string(self, column):
if isinstance(column.server_default, schema.DefaultClause):
if isinstance(column.default.arg, basestring):
if isinstance(column.type, sqltypes.Integer):
return str(column.default.arg)
else:
return "'%s'" % column.default.arg
else:
return unicode(self._compile(column.default.arg, None))
else:
return None
def visit_create_sequence(self, create):
"""Creates a SEQUENCE.
TODO: move to module doc?
start
With an integer value, set the START WITH option.
increment
An integer value to increment by. Default is the database default.
maxdb_minvalue
maxdb_maxvalue
With an integer value, sets the corresponding sequence option.
maxdb_no_minvalue
maxdb_no_maxvalue
Defaults to False. If true, sets the corresponding sequence option.
maxdb_cycle
Defaults to False. If true, sets the CYCLE option.
maxdb_cache
With an integer value, sets the CACHE option.
maxdb_no_cache
Defaults to False. If true, sets NOCACHE.
"""
sequence = create.element
if (not sequence.optional and
(not self.checkfirst or
not self.dialect.has_sequence(self.connection, sequence.name))):
ddl = ['CREATE SEQUENCE',
self.preparer.format_sequence(sequence)]
sequence.increment = 1
if sequence.increment is not None:
ddl.extend(('INCREMENT BY', str(sequence.increment)))
if sequence.start is not None:
ddl.extend(('START WITH', str(sequence.start)))
opts = dict([(pair[0][6:].lower(), pair[1])
for pair in sequence.kwargs.items()
if pair[0].startswith('maxdb_')])
if 'maxvalue' in opts:
ddl.extend(('MAXVALUE', str(opts['maxvalue'])))
elif opts.get('no_maxvalue', False):
ddl.append('NOMAXVALUE')
if 'minvalue' in opts:
ddl.extend(('MINVALUE', str(opts['minvalue'])))
elif opts.get('no_minvalue', False):
ddl.append('NOMINVALUE')
if opts.get('cycle', False):
ddl.append('CYCLE')
if 'cache' in opts:
ddl.extend(('CACHE', str(opts['cache'])))
elif opts.get('no_cache', False):
ddl.append('NOCACHE')
return ' '.join(ddl)
class MaxDBDialect(default.DefaultDialect):
name = 'maxdb'
supports_alter = True
supports_unicode_statements = True
max_identifier_length = 32
supports_sane_rowcount = True
supports_sane_multi_rowcount = False
preparer = MaxDBIdentifierPreparer
statement_compiler = MaxDBCompiler
ddl_compiler = MaxDBDDLCompiler
execution_ctx_cls = MaxDBExecutionContext
ported_sqla_06 = False
colspecs = colspecs
ischema_names = ischema_names
# MaxDB-specific
datetimeformat = 'internal'
def __init__(self, _raise_known_sql_errors=False, **kw):
super(MaxDBDialect, self).__init__(**kw)
self._raise_known = _raise_known_sql_errors
if self.dbapi is None:
self.dbapi_type_map = {}
else:
self.dbapi_type_map = {
'Long Binary': MaxBlob(),
'Long byte_t': MaxBlob(),
'Long Unicode': MaxText(),
'Timestamp': MaxTimestamp(),
'Date': MaxDate(),
'Time': MaxTime(),
datetime.datetime: MaxTimestamp(),
datetime.date: MaxDate(),
datetime.time: MaxTime(),
}
def do_execute(self, cursor, statement, parameters, context=None):
res = cursor.execute(statement, parameters)
if isinstance(res, int) and context is not None:
context._rowcount = res
def do_release_savepoint(self, connection, name):
# Does MaxDB truly support RELEASE SAVEPOINT <id>? All my attempts
# produce "SUBTRANS COMMIT/ROLLBACK not allowed without SUBTRANS
# BEGIN SQLSTATE: I7065"
# Note that ROLLBACK TO works fine. In theory, a RELEASE should
# just free up some transactional resources early, before the overall
# COMMIT/ROLLBACK so omitting it should be relatively ok.
pass
def _get_default_schema_name(self, connection):
return self.identifier_preparer._normalize_name(
connection.execute(
'SELECT CURRENT_SCHEMA FROM DUAL').scalar())
def has_table(self, connection, table_name, schema=None):
denormalize = self.identifier_preparer._denormalize_name
bind = [denormalize(table_name)]
if schema is None:
sql = ("SELECT tablename FROM TABLES "
"WHERE TABLES.TABLENAME=? AND"
" TABLES.SCHEMANAME=CURRENT_SCHEMA ")
else:
sql = ("SELECT tablename FROM TABLES "
"WHERE TABLES.TABLENAME = ? AND"
" TABLES.SCHEMANAME=? ")
bind.append(denormalize(schema))
rp = connection.execute(sql, bind)
return bool(rp.first())
@reflection.cache
def get_table_names(self, connection, schema=None, **kw):
if schema is None:
sql = (" SELECT TABLENAME FROM TABLES WHERE "
" SCHEMANAME=CURRENT_SCHEMA ")
rs = connection.execute(sql)
else:
sql = (" SELECT TABLENAME FROM TABLES WHERE "
" SCHEMANAME=? ")
matchname = self.identifier_preparer._denormalize_name(schema)
rs = connection.execute(sql, matchname)
normalize = self.identifier_preparer._normalize_name
return [normalize(row[0]) for row in rs]
def reflecttable(self, connection, table, include_columns):
denormalize = self.identifier_preparer._denormalize_name
normalize = self.identifier_preparer._normalize_name
st = ('SELECT COLUMNNAME, MODE, DATATYPE, CODETYPE, LEN, DEC, '
' NULLABLE, "DEFAULT", DEFAULTFUNCTION '
'FROM COLUMNS '
'WHERE TABLENAME=? AND SCHEMANAME=%s '
'ORDER BY POS')
fk = ('SELECT COLUMNNAME, FKEYNAME, '
' REFSCHEMANAME, REFTABLENAME, REFCOLUMNNAME, RULE, '
' (CASE WHEN REFSCHEMANAME = CURRENT_SCHEMA '
' THEN 1 ELSE 0 END) AS in_schema '
'FROM FOREIGNKEYCOLUMNS '
'WHERE TABLENAME=? AND SCHEMANAME=%s '
'ORDER BY FKEYNAME ')
params = [denormalize(table.name)]
if not table.schema:
st = st % 'CURRENT_SCHEMA'
fk = fk % 'CURRENT_SCHEMA'
else:
st = st % '?'
fk = fk % '?'
params.append(denormalize(table.schema))
rows = connection.execute(st, params).fetchall()
if not rows:
raise exc.NoSuchTableError(table.fullname)
include_columns = set(include_columns or [])
for row in rows:
(name, mode, col_type, encoding, length, scale,
nullable, constant_def, func_def) = row
name = normalize(name)
if include_columns and name not in include_columns:
continue
type_args, type_kw = [], {}
if col_type == 'FIXED':
type_args = length, scale
# Convert FIXED(10) DEFAULT SERIAL to our Integer
if (scale == 0 and
func_def is not None and func_def.startswith('SERIAL')):
col_type = 'INTEGER'
type_args = length,
elif col_type in 'FLOAT':
type_args = length,
elif col_type in ('CHAR', 'VARCHAR'):
type_args = length,
type_kw['encoding'] = encoding
elif col_type == 'LONG':
type_kw['encoding'] = encoding
try:
type_cls = ischema_names[col_type.lower()]
type_instance = type_cls(*type_args, **type_kw)
except KeyError:
util.warn("Did not recognize type '%s' of column '%s'" %
(col_type, name))
type_instance = sqltypes.NullType
col_kw = {'autoincrement': False}
col_kw['nullable'] = (nullable == 'YES')
col_kw['primary_key'] = (mode == 'KEY')
if func_def is not None:
if func_def.startswith('SERIAL'):
if col_kw['primary_key']:
# No special default- let the standard autoincrement
# support handle SERIAL pk columns.
col_kw['autoincrement'] = True
else:
# strip current numbering
col_kw['server_default'] = schema.DefaultClause(
sql.text('SERIAL'))
col_kw['autoincrement'] = True
else:
col_kw['server_default'] = schema.DefaultClause(
sql.text(func_def))
elif constant_def is not None:
col_kw['server_default'] = schema.DefaultClause(sql.text(
"'%s'" % constant_def.replace("'", "''")))
table.append_column(schema.Column(name, type_instance, **col_kw))
fk_sets = itertools.groupby(connection.execute(fk, params),
lambda row: row.FKEYNAME)
for fkeyname, fkey in fk_sets:
fkey = list(fkey)
if include_columns:
key_cols = set([r.COLUMNNAME for r in fkey])
if key_cols != include_columns:
continue
columns, referants = [], []
quote = self.identifier_preparer._maybe_quote_identifier
for row in fkey:
columns.append(normalize(row.COLUMNNAME))
if table.schema or not row.in_schema:
referants.append('.'.join(
[quote(normalize(row[c]))
for c in ('REFSCHEMANAME', 'REFTABLENAME',
'REFCOLUMNNAME')]))
else:
referants.append('.'.join(
[quote(normalize(row[c]))
for c in ('REFTABLENAME', 'REFCOLUMNNAME')]))
constraint_kw = {'name': fkeyname.lower()}
if fkey[0].RULE is not None:
rule = fkey[0].RULE
if rule.startswith('DELETE '):
rule = rule[7:]
constraint_kw['ondelete'] = rule
table_kw = {}
if table.schema or not row.in_schema:
table_kw['schema'] = normalize(fkey[0].REFSCHEMANAME)
ref_key = schema._get_table_key(normalize(fkey[0].REFTABLENAME),
table_kw.get('schema'))
if ref_key not in table.metadata.tables:
schema.Table(normalize(fkey[0].REFTABLENAME),
table.metadata,
autoload=True, autoload_with=connection,
**table_kw)
constraint = schema.ForeignKeyConstraint(
columns, referants, link_to_name=True,
**constraint_kw)
table.append_constraint(constraint)
def has_sequence(self, connection, name):
# [ticket:726] makes this schema-aware.
denormalize = self.identifier_preparer._denormalize_name
sql = ("SELECT sequence_name FROM SEQUENCES "
"WHERE SEQUENCE_NAME=? ")
rp = connection.execute(sql, denormalize(name))
return bool(rp.first())
def _autoserial_column(table):
"""Finds the effective DEFAULT SERIAL column of a Table, if any."""
for index, col in enumerate(table.primary_key.columns):
if (isinstance(col.type, (sqltypes.Integer, sqltypes.Numeric)) and
col.autoincrement):
if isinstance(col.default, schema.Sequence):
if col.default.optional:
return index, col
elif (col.default is None or
(not isinstance(col.server_default, schema.DefaultClause))):
return index, col
return None, None
|
mit
|
[
3,
1390,
697,
15,
1095,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
13,
8128,
314,
14303,
11462,
436,
8417,
665,
3239,
10610,
570,
30,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
624,
11532,
367,
314,
8228,
2846,
3050,
14,
199,
199,
2765,
10982,
365,
627,
1397,
10,
299,
1376,
370,
14303,
378,
14,
22,
503,
378,
14,
23,
14,
199,
199,
2765,
10982,
365,
627,
1397,
10,
12470,
641,
14303,
378,
14,
22,
503,
378,
14,
23,
14,
199,
199,
28077,
199,
518,
199,
199,
1918,
1124,
28255,
1040,
10982,
365,
1011,
18924,
538,
436,
965,
1454,
2757,
12470,
641,
1520,
14,
22,
14,
1644,
14,
8255,
199,
460,
1520,
14,
22,
14,
383,
14,
18325,
14,
221,
24545,
3520,
12,
1011,
2118,
1520,
14,
22,
14,
1644,
14,
8255,
911,
1736,
538,
543,
14303,
1159,
23383,
14,
199,
1918,
14119,
1015,
965,
542,
432,
264,
1124,
9894,
10593,
1040,
4204,
436,
911,
372,
199,
15448,
2058,
687,
2755,
7437,
3486,
23383,
9212,
14,
199,
199,
5903,
314,
5438,
2018,
6249,
13,
3735,
365,
5544,
3748,
14,
221,
593,
23317,
5253,
2291,
199,
374,
282,
6466,
655,
14666,
434,
14,
199,
199,
32000,
199,
9460,
199,
199,
1918,
3434,
365,
1930,
13,
7361,
14,
221,
982,
1265,
9987,
4907,
370,
314,
199,
4659,
543,
3875,
2764,
436,
1163,
7249,
315,
5117,
1930,
12,
1265,
12060,
1929,
370,
199,
1180,
7008,
1930,
367,
6249,
13,
3735,
14,
199,
199,
7921,
8144,
199,
777,
375,
199,
199,
3007,
314,
1520,
14,
22,
14,
383,
14,
1401,
5253,
436,
2018,
499,
14,
21,
12,
652,
12237,
626,
1006,
6249,
13,
3735,
199,
10176,
4967,
787,
10529,
436,
883,
7675,
2018,
370,
12420,
14,
199,
199,
1858,
283,
3972,
761,
14,
262,
63,
4157,
7,
370,
1736,
12,
314,
1621,
4182,
1159,
10152,
1471,
506,
2896,
199,
475,
9106,
283,
8084,
7,
370,
282,
8950,
12,
284,
14,
69,
14,
11576,
8,
8084,
680,
221,
710,
6249,
13,
3735,
3181,
1133,
4729,
282,
199,
3409,
2725,
2337,
12,
880,
626,
6770,
10152,
1471,
8308,
314,
5962,
574,
12,
199,
6777,
8350,
641,
359,
9201,
26,
11369,
1055,
199,
199,
1918,
6249,
13,
3735,
365,
7437,
3732,
89,
3595,
2382,
5398,
1862,
1443,
506,
1202,
315,
9212,
14,
199,
199,
8198,
1862,
367,
2005,
3423,
334,
69,
14,
71,
14,
30920,
9,
1929,
730,
2556,
6841,
14,
199,
1918,
10982,
1630,
440,
5966,
886,
642,
5847,
14,
199,
199,
4261,
911,
14706,
305,
1636,
1183,
7978,
1536,
283,
4087,
3875,
12,
6555,
4020,
7,
4967,
367,
199,
9452,
449,
590,
1686,
5385,
14,
221,
710,
10982,
1630,
440,
5544,
2429,
3520,
12,
1655,
199,
31788,
365,
4346,
14,
199,
199,
4261,
2846,
1520,
14,
21,
436,
428,
439,
6249,
2695,
1520,
14,
20,
14581,
590,
886,
440,
2291,
32536,
14,
221,
437,
7437,
199,
83,
4040,
590,
3365,
1015,
402,
642,
10982,
3955,
506,
1415,
370,
2291,
199,
273,
3362,
5459,
12,
436,
883,
16174,
506,
3483,
340,
2337,
365,
29237,
14,
221,
6601,
1163,
199,
2427,
7323,
4066,
465,
376,
8228,
13,
14600,
283,
1753,
28123,
3449,
7,
4263,
6365,
199,
8,
273,
386,
305,
543,
334,
8771,
6890,
7262,
2750,
9,
787,
2575,
4224,
436,
2808,
367,
199,
15092,
13,
3031,
314,
477,
1090,
769,
340,
1265,
3984,
22201,
315,
6449,
641,
199,
3749,
14,
199,
199,
21167,
12470,
26,
1520,
14,
22,
14,
1644,
14,
1780,
436,
1520,
14,
22,
14,
383,
14,
1401,
12,
5438,
2018,
6249,
13,
3735,
199,
199,
10,
8228,
2846,
965,
542,
432,
264,
4204,
641,
31682,
10593,
83,
12,
1314,
787,
22829,
1009,
370,
23383,
523,
21719,
8697,
14,
6061,
7830,
2419,
746,
376,
1125,
340,
282,
10468,
883,
1133,
506,
2435,
68,
12,
523,
314,
3050,
9329,
2529,
8927,
2058,
14,
199,
10,
3394,
1520,
14,
22,
14,
1644,
14,
1780,
12237,
370,
10593,
7684,
12,
13432,
314,
9149,
886,
440,
2498,
314,
523,
31682,
24488,
3769,
221,
853,
471,
334,
305,
402,
642,
3575,
395,
436,
949,
1570,
793,
365,
523,
2808,
370,
12679,
1902,
14,
982,
1265,
787,
1808,
282,
3365,
1654,
1015,
436,
523,
2195,
6527,
4409,
314,
23383,
503,
1263,
18734,
13,
14652,
5385,
4012,
314,
5385,
4045,
12,
523,
3879,
314,
14303,
511,
5241,
6169,
2195,
3050,
365,
869,
13454,
6084,
523,
14318,
2544,
1265,
5386,
14,
199,
10,
3394,
1520,
14,
22,
14,
383,
14,
1401,
365,
491,
15467,
15,
50,
15467,
18423,
315,
658,
12491,
13180,
6578,
31682,
10593,
9085,
5258,
523,
13180,
14,
761,
29,
12071,
14,
761,
64,
8118,
658,
12071,
14,
761,
29,
12697,
14,
761,
64,
1,
199,
10,
3394,
1520,
14,
22,
14,
383,
14,
1401,
365,
3743,
2972,
701,
658,
4859,
28424,
28437,
1048,
465,
5162,
4442,
307,
16044,
523,
6515,
1048,
64,
446,
3520,
26642,
12,
28424,
28437,
12,
7741,
9212,
1929,
370,
506,
295,
13,
8938,
370,
523,
1865,
701,
314,
5162,
536,
14,
199,
10,
3394,
1520,
14,
22,
14,
88,
5171,
6425,
282,
13950,
2524,
7217,
1325,
440,
2399,
5363,
17177,
14,
199,
10,
8228,
2846,
5171,
32497,
13,
2487,
4362,
334,
3472,
7017,
4938,
9,
436,
12717,
523,
8013,
14,
3979,
5893,
282,
6186,
7017,
4938,
2763,
315,
376,
5518,
12,
378,
4839,
370,
523,
506,
11788,
7830,
2419,
5962,
370,
3550,
282,
574,
14,
199,
10,
8228,
2846,
5171,
25600,
436,
298,
1753,
15309,
3449,
2,
12724,
18266,
543,
334,
8771,
6890,
4263,
523,
7262,
2750,
14,
199,
10,
710,
14303,
10982,
365,
4177,
13,
14600,
436,
8646,
7859,
1133,
805,
6657,
523,
641,
1654,
5459,
334,
657,
13,
23,
14,
22,
31,
680,
12502,
367,
4177,
13,
2003,
1654,
5459,
4293,
523,
506,
3483,
340,
2337,
1159,
1240,
14,
199,
10,
16044,
6515,
365,
440,
3748,
315,
1007,
10590,
14,
5138,
365,
440,
3748,
315,
523,
1007,
10590,
14,
1010,
1520,
14,
22,
14,
383,
14,
1401,
12,
32582,
1630,
1736,
315,
1007,
10590,
12,
1325,
1928,
2304,
440,
523,
880,
2997,
14,
32633,
3597,
1630,
440
] |
[
1390,
697,
15,
1095,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
13,
8128,
314,
14303,
11462,
436,
8417,
665,
3239,
10610,
570,
30,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
624,
11532,
367,
314,
8228,
2846,
3050,
14,
199,
199,
2765,
10982,
365,
627,
1397,
10,
299,
1376,
370,
14303,
378,
14,
22,
503,
378,
14,
23,
14,
199,
199,
2765,
10982,
365,
627,
1397,
10,
12470,
641,
14303,
378,
14,
22,
503,
378,
14,
23,
14,
199,
199,
28077,
199,
518,
199,
199,
1918,
1124,
28255,
1040,
10982,
365,
1011,
18924,
538,
436,
965,
1454,
2757,
12470,
641,
1520,
14,
22,
14,
1644,
14,
8255,
199,
460,
1520,
14,
22,
14,
383,
14,
18325,
14,
221,
24545,
3520,
12,
1011,
2118,
1520,
14,
22,
14,
1644,
14,
8255,
911,
1736,
538,
543,
14303,
1159,
23383,
14,
199,
1918,
14119,
1015,
965,
542,
432,
264,
1124,
9894,
10593,
1040,
4204,
436,
911,
372,
199,
15448,
2058,
687,
2755,
7437,
3486,
23383,
9212,
14,
199,
199,
5903,
314,
5438,
2018,
6249,
13,
3735,
365,
5544,
3748,
14,
221,
593,
23317,
5253,
2291,
199,
374,
282,
6466,
655,
14666,
434,
14,
199,
199,
32000,
199,
9460,
199,
199,
1918,
3434,
365,
1930,
13,
7361,
14,
221,
982,
1265,
9987,
4907,
370,
314,
199,
4659,
543,
3875,
2764,
436,
1163,
7249,
315,
5117,
1930,
12,
1265,
12060,
1929,
370,
199,
1180,
7008,
1930,
367,
6249,
13,
3735,
14,
199,
199,
7921,
8144,
199,
777,
375,
199,
199,
3007,
314,
1520,
14,
22,
14,
383,
14,
1401,
5253,
436,
2018,
499,
14,
21,
12,
652,
12237,
626,
1006,
6249,
13,
3735,
199,
10176,
4967,
787,
10529,
436,
883,
7675,
2018,
370,
12420,
14,
199,
199,
1858,
283,
3972,
761,
14,
262,
63,
4157,
7,
370,
1736,
12,
314,
1621,
4182,
1159,
10152,
1471,
506,
2896,
199,
475,
9106,
283,
8084,
7,
370,
282,
8950,
12,
284,
14,
69,
14,
11576,
8,
8084,
680,
221,
710,
6249,
13,
3735,
3181,
1133,
4729,
282,
199,
3409,
2725,
2337,
12,
880,
626,
6770,
10152,
1471,
8308,
314,
5962,
574,
12,
199,
6777,
8350,
641,
359,
9201,
26,
11369,
1055,
199,
199,
1918,
6249,
13,
3735,
365,
7437,
3732,
89,
3595,
2382,
5398,
1862,
1443,
506,
1202,
315,
9212,
14,
199,
199,
8198,
1862,
367,
2005,
3423,
334,
69,
14,
71,
14,
30920,
9,
1929,
730,
2556,
6841,
14,
199,
1918,
10982,
1630,
440,
5966,
886,
642,
5847,
14,
199,
199,
4261,
911,
14706,
305,
1636,
1183,
7978,
1536,
283,
4087,
3875,
12,
6555,
4020,
7,
4967,
367,
199,
9452,
449,
590,
1686,
5385,
14,
221,
710,
10982,
1630,
440,
5544,
2429,
3520,
12,
1655,
199,
31788,
365,
4346,
14,
199,
199,
4261,
2846,
1520,
14,
21,
436,
428,
439,
6249,
2695,
1520,
14,
20,
14581,
590,
886,
440,
2291,
32536,
14,
221,
437,
7437,
199,
83,
4040,
590,
3365,
1015,
402,
642,
10982,
3955,
506,
1415,
370,
2291,
199,
273,
3362,
5459,
12,
436,
883,
16174,
506,
3483,
340,
2337,
365,
29237,
14,
221,
6601,
1163,
199,
2427,
7323,
4066,
465,
376,
8228,
13,
14600,
283,
1753,
28123,
3449,
7,
4263,
6365,
199,
8,
273,
386,
305,
543,
334,
8771,
6890,
7262,
2750,
9,
787,
2575,
4224,
436,
2808,
367,
199,
15092,
13,
3031,
314,
477,
1090,
769,
340,
1265,
3984,
22201,
315,
6449,
641,
199,
3749,
14,
199,
199,
21167,
12470,
26,
1520,
14,
22,
14,
1644,
14,
1780,
436,
1520,
14,
22,
14,
383,
14,
1401,
12,
5438,
2018,
6249,
13,
3735,
199,
199,
10,
8228,
2846,
965,
542,
432,
264,
4204,
641,
31682,
10593,
83,
12,
1314,
787,
22829,
1009,
370,
23383,
523,
21719,
8697,
14,
6061,
7830,
2419,
746,
376,
1125,
340,
282,
10468,
883,
1133,
506,
2435,
68,
12,
523,
314,
3050,
9329,
2529,
8927,
2058,
14,
199,
10,
3394,
1520,
14,
22,
14,
1644,
14,
1780,
12237,
370,
10593,
7684,
12,
13432,
314,
9149,
886,
440,
2498,
314,
523,
31682,
24488,
3769,
221,
853,
471,
334,
305,
402,
642,
3575,
395,
436,
949,
1570,
793,
365,
523,
2808,
370,
12679,
1902,
14,
982,
1265,
787,
1808,
282,
3365,
1654,
1015,
436,
523,
2195,
6527,
4409,
314,
23383,
503,
1263,
18734,
13,
14652,
5385,
4012,
314,
5385,
4045,
12,
523,
3879,
314,
14303,
511,
5241,
6169,
2195,
3050,
365,
869,
13454,
6084,
523,
14318,
2544,
1265,
5386,
14,
199,
10,
3394,
1520,
14,
22,
14,
383,
14,
1401,
365,
491,
15467,
15,
50,
15467,
18423,
315,
658,
12491,
13180,
6578,
31682,
10593,
9085,
5258,
523,
13180,
14,
761,
29,
12071,
14,
761,
64,
8118,
658,
12071,
14,
761,
29,
12697,
14,
761,
64,
1,
199,
10,
3394,
1520,
14,
22,
14,
383,
14,
1401,
365,
3743,
2972,
701,
658,
4859,
28424,
28437,
1048,
465,
5162,
4442,
307,
16044,
523,
6515,
1048,
64,
446,
3520,
26642,
12,
28424,
28437,
12,
7741,
9212,
1929,
370,
506,
295,
13,
8938,
370,
523,
1865,
701,
314,
5162,
536,
14,
199,
10,
3394,
1520,
14,
22,
14,
88,
5171,
6425,
282,
13950,
2524,
7217,
1325,
440,
2399,
5363,
17177,
14,
199,
10,
8228,
2846,
5171,
32497,
13,
2487,
4362,
334,
3472,
7017,
4938,
9,
436,
12717,
523,
8013,
14,
3979,
5893,
282,
6186,
7017,
4938,
2763,
315,
376,
5518,
12,
378,
4839,
370,
523,
506,
11788,
7830,
2419,
5962,
370,
3550,
282,
574,
14,
199,
10,
8228,
2846,
5171,
25600,
436,
298,
1753,
15309,
3449,
2,
12724,
18266,
543,
334,
8771,
6890,
4263,
523,
7262,
2750,
14,
199,
10,
710,
14303,
10982,
365,
4177,
13,
14600,
436,
8646,
7859,
1133,
805,
6657,
523,
641,
1654,
5459,
334,
657,
13,
23,
14,
22,
31,
680,
12502,
367,
4177,
13,
2003,
1654,
5459,
4293,
523,
506,
3483,
340,
2337,
1159,
1240,
14,
199,
10,
16044,
6515,
365,
440,
3748,
315,
1007,
10590,
14,
5138,
365,
440,
3748,
315,
523,
1007,
10590,
14,
1010,
1520,
14,
22,
14,
383,
14,
1401,
12,
32582,
1630,
1736,
315,
1007,
10590,
12,
1325,
1928,
2304,
440,
523,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
obulpathi/reversecoin
|
reversecoin/bitcoin/rpc.py
|
1
|
9261
|
# Copyright 2011 Jeff Garzik
#
# RawProxy has the following improvements over python-jsonrpc's ServiceProxy
# class:
#
# - HTTP connections persist for the life of the RawProxy object (if server
# supports HTTP/1.1)
# - sends protocol 'version', per JSON-RPC 1.1
# - sends proper, incrementing 'id'
# - sends Basic HTTP authentication headers
# - parses all JSON numbers that look like floats as Decimal
# - uses standard Python json lib
#
# Previous copyright, from python-jsonrpc/jsonrpc/proxy.py:
#
# Copyright (c) 2007 Jan-Klaas Kollhof
#
# This file is part of jsonrpc.
#
# jsonrpc is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this software; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
try:
import http.client as httplib
except ImportError:
import httplib
import base64
import decimal
import json
import os
import platform
try:
import urllib.parse as urlparse
except ImportError:
import urlparse
from reversecoin.bitcoin.coredefs import COIN
from reversecoin.bitcoin.base58 import CBitcoinAddress
USER_AGENT = "AuthServiceProxy/0.1"
HTTP_TIMEOUT = 180
class JSONRPCException(Exception):
def __init__(self, rpc_error):
super(JSONRPCException, self).__init__('msg: %r code: %r' %
(rpc_error['message'], rpc_error['code']))
self.error = rpc_error
class RawProxy(object):
# FIXME: need a CChainParams rather than hard-coded service_port
def __init__(self, service_url=None,
service_port=8332,
btc_conf_file=None,
timeout=HTTP_TIMEOUT,
_connection=None):
"""Low-level JSON-RPC proxy
Unlike Proxy no conversion is done from the raw JSON objects.
"""
if service_url is None:
# Figure out the path to the bitcoin.conf file
if btc_conf_file is None:
if platform.system() == 'Darwin':
btc_conf_file = os.path.join(os.environ['APPDATA'], 'Bitcoin')
elif platform.system() == 'Windows':
btc_conf_file = os.path.expanduser('~/Library/Application Support/Bitcoin/')
else:
btc_conf_file = os.path.expanduser('~/.bitcoin')
btc_conf_file = os.path.join(btc_conf_file, 'bitcoin.conf')
# Extract contents of bitcoin.conf to build service_url
with open(btc_conf_file, 'r') as fd:
conf = {}
for line in fd.readlines():
if '#' in line:
line = line[:line.index('#')]
if '=' not in line:
continue
k, v = line.split('=', 1)
conf[k.strip()] = v.strip()
conf['rpcport'] = int(conf.get('rpcport', service_port))
conf['rpcssl'] = conf.get('rpcssl', '0')
if conf['rpcssl'].lower() in ('0', 'false'):
conf['rpcssl'] = False
elif conf['rpcssl'].lower() in ('1', 'true'):
conf['rpcssl'] = True
else:
raise ValueError('Unknown rpcssl value %r' % conf['rpcssl'])
service_url = ('%s://%s:%s@localhost:%d' %
('https' if conf['rpcssl'] else 'http',
conf['rpcuser'], conf['rpcpassword'],
conf['rpcport']))
self.__service_url = service_url
self.__url = urlparse.urlparse(service_url)
if self.__url.port is None:
port = 80
else:
port = self.__url.port
self.__id_count = 0
authpair = "%s:%s" % (self.__url.username, self.__url.password)
authpair = authpair.encode('utf8')
self.__auth_header = b"Basic " + base64.b64encode(authpair)
if _connection:
# Callables re-use the connection of the original proxy
self.__conn = _connection
elif self.__url.scheme == 'https':
self.__conn = httplib.HTTPSConnection(self.__url.hostname, port,
None, None, False,
timeout)
else:
self.__conn = httplib.HTTPConnection(self.__url.hostname, port,
False, timeout)
def _call(self, service_name, *args):
self.__id_count += 1
postdata = json.dumps({'version': '1.1',
'method': service_name,
'params': args,
'id': self.__id_count})
self.__conn.request('POST', self.__url.path, postdata,
{'Host': self.__url.hostname,
'User-Agent': USER_AGENT,
'Authorization': self.__auth_header,
'Content-type': 'application/json'})
response = self._get_response()
if response['error'] is not None:
raise JSONRPCException(response['error'])
elif 'result' not in response:
raise JSONRPCException({
'code': -343, 'message': 'missing JSON-RPC result'})
else:
return response['result']
def __getattr__(self, name):
if name.startswith('__') and name.endswith('__'):
# Python internal stuff
raise AttributeError
# Create a callable to do the actual call
f = lambda *args: self._call(name, *args)
# Make debuggers show <function bitcoin.rpc.name> rather than <function
# bitcoin.rpc.<lambda>>
f.__name__ = name
return f
def _batch(self, rpc_call_list):
postdata = json.dumps(list(rpc_call_list))
self.__conn.request('POST', self.__url.path, postdata,
{'Host': self.__url.hostname,
'User-Agent': USER_AGENT,
'Authorization': self.__auth_header,
'Content-type': 'application/json'})
return self._get_response()
def _get_response(self):
http_response = self.__conn.getresponse()
if http_response is None:
raise JSONRPCException({
'code': -342, 'message': 'missing HTTP response from server'})
return json.loads(http_response.read().decode('utf8'),
parse_float=decimal.Decimal)
class Proxy(RawProxy):
def __init__(self, service_url=None,
service_port=8332,
btc_conf_file=None,
timeout=HTTP_TIMEOUT,
**kwargs):
"""Create a proxy to a bitcoin RPC service
Unlike RawProxy data is passed as objects, rather than JSON. (not yet
fully implemented)
If service_url is not specified the username and password are read out
of the file btc_conf_file. If btc_conf_file is not specified
~/.bitcoin/bitcoin.conf or equivalent is used by default.
Usually no arguments to Proxy() are needed; the local bitcoind will be
used.
timeout - timeout in seconds before the HTTP interface times out
"""
super(Proxy, self).__init__(service_url=service_url, service_port=service_port, btc_conf_file=btc_conf_file,
timeout=HTTP_TIMEOUT,
**kwargs)
def getinfo(self):
"""Returns an object containing various state info"""
r = self._call('getinfo')
r['balance'] = int(r['balance'] * COIN)
r['paytxfee'] = int(r['paytxfee'] * COIN)
return r
def getnewaddress(self, account=None):
"""Return a new Bitcoin address for receiving payments.
If account is not None, it is added to the address book so payments
received with the address will be credited to account.
"""
r = None
if account is not None:
r = self._call('getnewaddress', account)
else:
r = self._call('getnewaddress')
return CBitcoinAddress.from_str(r)
def getaccountaddress(self, account=None):
"""Return the current Bitcoin address for receiving payments to this account."""
r = self._call('getaccountaddress', account)
return CBitcoinAddress.from_str(r)
def validateaddress(self, address):
"""Return information about an address"""
r = self._call('validateaddress', str(address))
r['address'] = CBitcoinAddress.from_str(r['address'])
return r
|
gpl-2.0
|
[
3,
1898,
7760,
1603,
3609,
598,
285,
90,
3258,
199,
3,
199,
3,
13480,
4936,
965,
314,
2569,
19053,
1470,
1806,
2366,
13,
31395,
1159,
7591,
4936,
199,
3,
1021,
26,
199,
3,
199,
3,
446,
3101,
6947,
22400,
367,
314,
15451,
402,
314,
13480,
4936,
909,
334,
692,
1654,
199,
3,
257,
5171,
3101,
15,
17,
14,
17,
9,
199,
3,
446,
16178,
4113,
283,
1023,
297,
1126,
4840,
13,
8171,
413,
14,
17,
199,
3,
446,
16178,
5576,
12,
11609,
316,
283,
344,
7,
199,
3,
446,
16178,
10082,
3101,
6299,
2323,
199,
3,
446,
19953,
1006,
4840,
5579,
626,
3648,
2839,
15657,
465,
6345,
199,
3,
446,
4440,
4465,
2018,
2022,
1973,
199,
3,
199,
3,
26902,
4248,
12,
687,
2366,
13,
31395,
15,
31395,
15,
3280,
14,
647,
26,
199,
3,
199,
3,
1898,
334,
67,
9,
10219,
17474,
13,
43,
416,
305,
1804,
14385,
526,
70,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2022,
4354,
14,
199,
3,
199,
3,
2022,
4354,
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,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2032,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2032,
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,
221,
15673,
13,
13421,
221,
8217,
199,
199,
893,
26,
272,
492,
1455,
14,
1258,
465,
8809,
199,
2590,
3545,
26,
272,
492,
8809,
199,
646,
1300,
772,
199,
646,
6107,
199,
646,
2022,
199,
646,
747,
199,
646,
4298,
199,
893,
26,
272,
492,
4011,
14,
1122,
465,
7097,
199,
2590,
3545,
26,
272,
492,
7097,
199,
199,
504,
3837,
9061,
14,
22816,
14,
1018,
8710,
492,
5099,
568,
199,
504,
3837,
9061,
14,
22816,
14,
1095,
2010,
492,
445,
4734,
9061,
1476,
199,
199,
3791,
63,
14565,
275,
298,
2817,
3167,
4936,
15,
16,
14,
17,
2,
199,
199,
2856,
63,
8899,
275,
13576,
421,
199,
533,
4840,
8171,
1726,
8,
1726,
304,
272,
347,
636,
826,
721,
277,
12,
8985,
63,
705,
304,
267,
1613,
8,
6243,
8171,
1726,
12,
291,
2843,
826,
19734,
1328,
26,
450,
82,
221,
1233,
26,
450,
82,
7,
450,
355,
334,
4354,
63,
705,
459,
1188,
995,
8985,
63,
705,
459,
600,
5156,
267,
291,
14,
705,
275,
8985,
63,
705,
421,
199,
533,
13480,
4936,
8,
785,
304,
272,
327,
7600,
26,
1929,
282,
445,
10720,
6007,
7830,
2419,
7508,
13,
15282,
2435,
63,
719,
272,
347,
636,
826,
721,
277,
12,
2435,
63,
633,
29,
403,
12,
2432,
2435,
63,
719,
29,
2658,
708,
12,
2432,
330,
3641,
63,
2190,
63,
493,
29,
403,
12,
2432,
2653,
29,
2856,
63,
8899,
12,
2432,
485,
2105,
29,
403,
304,
267,
408,
10281,
13,
1896,
4840,
13,
8171,
4566,
398,
25059,
12373,
949,
8603,
365,
4224,
687,
314,
3066,
4840,
2251,
14,
267,
408,
398,
340,
2435,
63,
633,
365,
488,
26,
288,
327,
16266,
734,
314,
931,
370,
314,
27214,
14,
2190,
570,
288,
340,
330,
3641,
63,
2190,
63,
493,
365,
488,
26,
355,
340,
4298,
14,
2253,
342,
508,
283,
31065,
356,
490,
330,
3641,
63,
2190,
63,
493,
275,
747,
14,
515,
14,
904,
8,
736,
14,
2314,
459,
28057,
995,
283,
4734,
9061,
358,
355,
916,
4298,
14,
2253,
342,
508,
283,
8647,
356,
490,
330,
3641,
63,
2190,
63,
493,
275,
747,
14,
515,
14,
12131,
21114,
15,
7424,
15,
5039,
12502,
15,
4734,
9061,
6217,
355,
587,
26,
490,
330,
3641,
63,
2190,
63,
493,
275,
747,
14,
515,
14,
12131,
21114,
8083,
22816,
358,
355,
330,
3641,
63,
2190,
63,
493,
275,
747,
14,
515,
14,
904,
8,
66,
3641,
63,
2190,
63,
493,
12,
283,
22816,
14,
2190,
358,
953,
327,
12892,
4072,
402,
27214,
14,
2190,
370,
1900,
2435,
63,
633,
288,
543,
1551,
8,
66,
3641,
63,
2190,
63,
493,
12,
283,
82,
358,
465,
6111,
26,
355,
3743,
275,
1052,
355,
367,
1004,
315,
6111,
14,
9684,
837,
490,
340,
19619,
315,
1004,
26,
717,
1004,
275,
1004,
1491,
604,
14,
1080,
7863,
5440,
490,
340,
14051,
440,
315,
1004,
26,
717,
1980,
490,
1022,
12,
373,
275,
1004,
14,
1294,
25283,
413,
9,
490,
3743,
59,
75,
14,
1913,
5106,
275,
373,
14,
1913,
342,
2234,
3743,
459,
4354,
719,
418,
275,
1109,
8,
2190,
14,
362,
360,
4354,
719,
297,
2435,
63,
719,
430,
355,
3743,
459,
4354,
4266,
418,
275,
3743,
14,
362,
360,
4354,
4266,
297,
283,
16,
358,
2234,
340,
3743,
459,
4354,
4266,
2278,
2325,
342,
315,
661,
16,
297,
283,
3910,
735,
490,
3743,
459,
4354,
4266,
418,
275,
756,
355,
916,
3743,
459,
4354,
4266,
2278,
2325,
342,
315,
661,
17,
297,
283,
2052,
735,
490,
3743,
459,
4354,
4266,
418,
275,
715,
355,
587,
26,
490,
746,
1722,
360,
5912,
8985,
4266,
574,
450,
82,
7,
450,
3743,
459,
4354,
4266,
1105,
2234,
2435,
63,
633,
275,
16651,
83,
13827,
83,
2689,
83,
32,
5967,
2689,
68,
7,
450,
490,
661,
2859,
7,
340,
3743,
459,
4354,
4266,
418,
587,
283,
1014,
297,
2151,
3743,
459,
4354,
751,
995,
3743,
459,
4354,
2060,
995,
2151,
3743,
459,
4354,
719,
5156,
398,
291,
855,
1364,
63,
633,
275,
2435,
63,
633,
267,
291,
855,
633,
275,
7097,
14,
10290,
8,
1364,
63,
633,
9,
267,
340,
291,
855,
633,
14,
719,
365,
488,
26,
288,
1844,
275,
5939,
267,
587,
26,
288,
1844,
275,
291,
855,
633,
14
] |
[
1898,
7760,
1603,
3609,
598,
285,
90,
3258,
199,
3,
199,
3,
13480,
4936,
965,
314,
2569,
19053,
1470,
1806,
2366,
13,
31395,
1159,
7591,
4936,
199,
3,
1021,
26,
199,
3,
199,
3,
446,
3101,
6947,
22400,
367,
314,
15451,
402,
314,
13480,
4936,
909,
334,
692,
1654,
199,
3,
257,
5171,
3101,
15,
17,
14,
17,
9,
199,
3,
446,
16178,
4113,
283,
1023,
297,
1126,
4840,
13,
8171,
413,
14,
17,
199,
3,
446,
16178,
5576,
12,
11609,
316,
283,
344,
7,
199,
3,
446,
16178,
10082,
3101,
6299,
2323,
199,
3,
446,
19953,
1006,
4840,
5579,
626,
3648,
2839,
15657,
465,
6345,
199,
3,
446,
4440,
4465,
2018,
2022,
1973,
199,
3,
199,
3,
26902,
4248,
12,
687,
2366,
13,
31395,
15,
31395,
15,
3280,
14,
647,
26,
199,
3,
199,
3,
1898,
334,
67,
9,
10219,
17474,
13,
43,
416,
305,
1804,
14385,
526,
70,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2022,
4354,
14,
199,
3,
199,
3,
2022,
4354,
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,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2032,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2032,
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,
221,
15673,
13,
13421,
221,
8217,
199,
199,
893,
26,
272,
492,
1455,
14,
1258,
465,
8809,
199,
2590,
3545,
26,
272,
492,
8809,
199,
646,
1300,
772,
199,
646,
6107,
199,
646,
2022,
199,
646,
747,
199,
646,
4298,
199,
893,
26,
272,
492,
4011,
14,
1122,
465,
7097,
199,
2590,
3545,
26,
272,
492,
7097,
199,
199,
504,
3837,
9061,
14,
22816,
14,
1018,
8710,
492,
5099,
568,
199,
504,
3837,
9061,
14,
22816,
14,
1095,
2010,
492,
445,
4734,
9061,
1476,
199,
199,
3791,
63,
14565,
275,
298,
2817,
3167,
4936,
15,
16,
14,
17,
2,
199,
199,
2856,
63,
8899,
275,
13576,
421,
199,
533,
4840,
8171,
1726,
8,
1726,
304,
272,
347,
636,
826,
721,
277,
12,
8985,
63,
705,
304,
267,
1613,
8,
6243,
8171,
1726,
12,
291,
2843,
826,
19734,
1328,
26,
450,
82,
221,
1233,
26,
450,
82,
7,
450,
355,
334,
4354,
63,
705,
459,
1188,
995,
8985,
63,
705,
459,
600,
5156,
267,
291,
14,
705,
275,
8985,
63,
705,
421,
199,
533,
13480,
4936,
8,
785,
304,
272,
327,
7600,
26,
1929,
282,
445,
10720,
6007,
7830,
2419,
7508,
13,
15282,
2435,
63,
719,
272,
347,
636,
826,
721,
277,
12,
2435,
63,
633,
29,
403,
12,
2432,
2435,
63,
719,
29,
2658,
708,
12,
2432,
330,
3641,
63,
2190,
63,
493,
29,
403,
12,
2432,
2653,
29,
2856,
63,
8899,
12,
2432,
485,
2105,
29,
403,
304,
267,
408,
10281,
13,
1896,
4840,
13,
8171,
4566,
398,
25059,
12373,
949,
8603,
365,
4224,
687,
314,
3066,
4840,
2251,
14,
267,
408,
398,
340,
2435,
63,
633,
365,
488,
26,
288,
327,
16266,
734,
314,
931,
370,
314,
27214,
14,
2190,
570,
288,
340,
330,
3641,
63,
2190,
63,
493,
365,
488,
26,
355,
340,
4298,
14,
2253,
342,
508,
283,
31065,
356,
490,
330,
3641,
63,
2190,
63,
493,
275,
747,
14,
515,
14,
904,
8,
736,
14,
2314,
459,
28057,
995,
283,
4734,
9061,
358,
355,
916,
4298,
14,
2253,
342,
508,
283,
8647,
356,
490,
330,
3641,
63,
2190,
63,
493,
275,
747,
14,
515,
14,
12131,
21114,
15,
7424,
15,
5039,
12502,
15,
4734,
9061,
6217,
355,
587,
26,
490,
330,
3641,
63,
2190,
63,
493,
275,
747,
14,
515,
14,
12131,
21114,
8083,
22816,
358,
355,
330,
3641,
63,
2190,
63,
493,
275,
747,
14,
515,
14,
904,
8,
66,
3641,
63,
2190,
63,
493,
12,
283,
22816,
14,
2190,
358,
953,
327,
12892,
4072,
402,
27214,
14,
2190,
370,
1900,
2435,
63,
633,
288,
543,
1551,
8,
66,
3641,
63,
2190,
63,
493,
12,
283,
82,
358,
465,
6111,
26,
355,
3743,
275,
1052,
355,
367,
1004,
315,
6111,
14,
9684,
837,
490,
340,
19619,
315,
1004,
26,
717,
1004,
275,
1004,
1491,
604,
14,
1080,
7863,
5440,
490,
340,
14051,
440,
315,
1004,
26,
717,
1980,
490,
1022,
12,
373,
275,
1004,
14,
1294,
25283,
413,
9,
490,
3743,
59,
75,
14,
1913,
5106,
275,
373,
14,
1913,
342,
2234,
3743,
459,
4354,
719,
418,
275,
1109,
8,
2190,
14,
362,
360,
4354,
719,
297,
2435,
63,
719,
430,
355,
3743,
459,
4354,
4266,
418,
275,
3743,
14,
362,
360,
4354,
4266,
297,
283,
16,
358,
2234,
340,
3743,
459,
4354,
4266,
2278,
2325,
342,
315,
661,
16,
297,
283,
3910,
735,
490,
3743,
459,
4354,
4266,
418,
275,
756,
355,
916,
3743,
459,
4354,
4266,
2278,
2325,
342,
315,
661,
17,
297,
283,
2052,
735,
490,
3743,
459,
4354,
4266,
418,
275,
715,
355,
587,
26,
490,
746,
1722,
360,
5912,
8985,
4266,
574,
450,
82,
7,
450,
3743,
459,
4354,
4266,
1105,
2234,
2435,
63,
633,
275,
16651,
83,
13827,
83,
2689,
83,
32,
5967,
2689,
68,
7,
450,
490,
661,
2859,
7,
340,
3743,
459,
4354,
4266,
418,
587,
283,
1014,
297,
2151,
3743,
459,
4354,
751,
995,
3743,
459,
4354,
2060,
995,
2151,
3743,
459,
4354,
719,
5156,
398,
291,
855,
1364,
63,
633,
275,
2435,
63,
633,
267,
291,
855,
633,
275,
7097,
14,
10290,
8,
1364,
63,
633,
9,
267,
340,
291,
855,
633,
14,
719,
365,
488,
26,
288,
1844,
275,
5939,
267,
587,
26,
288,
1844,
275,
291,
855,
633,
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,
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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
] |
youprofit/NewsBlur
|
vendor/mms-agent/agent.py
|
19
|
12651
|
"""
(C) Copyright 2011, 10gen
This is a label on a mattress. Do not modify this file!
"""
# App
import settings as _settings
import logConfig
# Python
import sys, socket, time, os, hmac, urllib2, threading, subprocess, traceback
try:
import hashlib
except ImportError:
sys.exit( 'ERROR - you must have hashlib installed - see README for more info' )
_logger = logConfig.initLogger()
socket.setdefaulttimeout( _settings.socket_timeout )
_pymongoVersion = None
_processPid = os.getpid()
# Try and reduce the stack size.
try:
threading.stack_size( 409600 )
except:
pass
if _settings.mms_key == '@API_KEY@':
sys.exit( 'ERROR - you must set your @API_KEY@ - see https://mms.10gen.com/settings' )
if _settings.secret_key == '@SECRET_KEY@':
sys.exit( 'ERROR - you must set your @SECRET_KEY@ - see https://mms.10gen.com/settings' )
if sys.version_info < ( 2, 4 ):
sys.exit( 'ERROR - old Python - the MMS agent requires Python 2.4 or higher' )
# Make sure pymongo is installed
try:
import pymongo
import bson
except ImportError:
sys.exit( 'ERROR - pymongo not installed - see: http://api.mongodb.org/python/ - run: easy_install pymongo' )
# Check the version of pymongo.
pyv = pymongo.version
if "partition" in dir( pyv ):
pyv = pyv.partition( "+" )[0]
_pymongoVersion = pyv
if map( int, pyv.split('.') ) < [ 1, 9]:
sys.exit( 'ERROR - The MMS agent requires pymongo 1.9 or higher: easy_install -U pymongo' )
if _settings.useSslForAllConnections:
if map( int, pyv.split('.') ) < [ 2, 1, 1]:
sys.exit( 'ERROR - The MMS agent requires pymongo 2.1.1 or higher to use SSL: easy_install -U pymongo' )
_pymongoVersion = pymongo.version
class AgentProcessContainer( object ):
""" Store the handle and lock to the agent process. """
def __init__( self ):
""" Init the lock and init process to none """
self.lock = threading.Lock()
self.agent = None
def pingAgentProcess( self ):
""" Ping the agent process """
try:
self.lock.acquire()
if self.agent is None or self.agent.poll() is not None:
return
self.agent.stdin.write( 'hello\n' )
self.agent.stdin.flush()
finally:
self.lock.release()
def stopAgentProcess( self ):
""" Send the stop message to the agent process """
try:
self.lock.acquire()
if self.agent is None or self.agent.poll() is not None:
return
self.agent.stdin.write( 'seeya\n' )
self.agent.stdin.flush()
time.sleep( 1 )
self.agent = None
finally:
self.lock.release()
class AgentShutdownListenerThread( threading.Thread ):
""" Disabled by default. When enabled listens for shutdown messages. """
def __init__( self, loggerObj, settingsObj ):
""" Initialize the object """
self.logger = loggerObj
self.settings = settingsObj
threading.Thread.__init__( self )
def run( self ):
""" Listen for the shutdown messages """
try:
sock = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
sock.bind( ( self.settings.shutdownAgentBindAddr, self.settings.shutdownAgentBindPort ) )
except Exception, e:
self.logger.error( traceback.format_exc( e ) )
self.logger.info( 'Shutdown listener bound to address %s on port %d' % ( self.settings.shutdownAgentBindAddr, self.settings.shutdownAgentBindPort ) )
while True:
try:
time.sleep( 5 )
data, addr = sock.recvfrom( 1024 )
if data != self.settings.shutdownAgentBindChallenge:
self.logger.error( 'received bad shutdown message from: %s' % addr[0] )
else:
self.logger.info( 'received valid shutdown message from: %s - exiting' % addr[0] )
os._exit( 0 )
except:
pass
class AgentProcessMonitorThread( threading.Thread ):
""" Make sure the agent process is running """
def __init__( self, logger, agentDir, processContainerObj ):
""" Initialize the object """
self.logger = logger
self.agentDir = agentDir
self.processContainer = processContainerObj
threading.Thread.__init__( self )
def _launchAgentProcess( self ):
""" Execute the agent process and keep a handle to it. """
return subprocess.Popen( [ sys.executable, os.path.join( sys.path[0], 'agentProcess.py' ), str( _processPid ) ], stdin=subprocess.PIPE, stdout=subprocess.PIPE )
def run( self ):
""" If the agent process is not alive, start the process """
while True:
try:
time.sleep( 5 )
self._monitorProcess()
except Exception, e:
self.logger.error( traceback.format_exc( e ) )
def _monitorProcess( self ):
""" Monitor the child process """
self.processContainer.lock.acquire()
try:
try:
if self.processContainer.agent is None or self.processContainer.agent.poll() is not None:
self.processContainer.agent = self._launchAgentProcess()
except Exception, e:
self.logger.error( traceback.format_exc( e ) )
finally:
self.processContainer.lock.release()
class AgentUpdateThread( threading.Thread ):
""" Check to see if updates are available - if so download and restart agent process """
def __init__( self, logger, agentDir, settingsObj, processContainerObj ):
""" Initialize the object """
self.logger = logger
self.agentDir = agentDir
self.settings = settingsObj
self.processContainer = processContainerObj
threading.Thread.__init__( self )
def run( self ):
""" Update the agent if possible """
while True:
try:
time.sleep( 300 )
self._checkForUpdate()
except Exception, e:
self.logger.error( 'Problem with upgrade check: ' + traceback.format_exc( e ) )
def _checkForUpdate( self ):
""" Update the agent if possible """
res = urllib2.urlopen( self.settings.version_url % { 'key' : self.settings.mms_key } )
resBson = None
try:
resBson = bson.decode_all( res.read() )
finally:
if res is not None:
res.close()
res = None
if len(resBson) != 1:
return
versionResponse = resBson[0]
if 'status' not in versionResponse or versionResponse['status'] != 'ok':
return
if 'agentVersion' not in versionResponse or 'authCode' not in versionResponse:
return
remoteAgentVersion = versionResponse['agentVersion']
authCode = versionResponse['authCode']
if authCode != hmac.new( self.settings.secret_key, remoteAgentVersion, digestmod=hashlib.sha1 ).hexdigest():
self.logger.error( 'Invalid auth code - please confirm your secret key (defined on Settings page) is correct and hmac is properly installed - http://mms.10gen.com/help/' )
return
if self._shouldUpgradeAgent( self.settings.settingsAgentVersion, remoteAgentVersion ):
self._upgradeAgent( remoteAgentVersion )
def _shouldUpgradeAgent( self, localVersion, remoteVersion ):
""" Returns true if the agent should upgrade itself. """
try:
for l, r in zip( localVersion.split('.'), remoteVersion.split('.') ):
if int( l ) < int( r ):
return True
if int( l ) > int( r ):
return False
except StandardError:
self.logger.error( "Upgrade problem with versions - local: '%s' - remote: '%s'" % ( localVersion, remoteVersion ) )
return False
def _upgradeAgent( self, newAgentVersion ):
""" Pull down the files, verify and then stop the current process """
res = urllib2.urlopen( self.settings.upgrade_url % { 'key' : self.settings.mms_key } )
resBson = None
try:
resBson = bson.decode_all( res.read() )
finally:
if res is not None:
res.close()
res = None
if len(resBson) != 1:
return
upgradeResponse = resBson[0]
if 'status' not in upgradeResponse or upgradeResponse['status'] != 'ok' or 'files' not in upgradeResponse:
return
# Verify the auth codes for all files and names first.
for fileInfo in upgradeResponse['files']:
if fileInfo['fileAuthCode'] != hmac.new( self.settings.secret_key, fileInfo['file'], digestmod=hashlib.sha1 ).hexdigest():
self.logger.error( 'Invalid file auth code for upgrade - cancelling' )
return
if fileInfo['fileNameAuthCode'] != hmac.new( self.settings.secret_key, fileInfo['fileName'], digestmod=hashlib.sha1 ).hexdigest():
self.logger.error( 'Invalid file name auth code for upgrade - cancelling' )
return
# Write the files.
for fileInfo in upgradeResponse['files']:
fileContent = fileInfo['file']
fileName = fileInfo['fileName']
# If the user has a global username/password defined, make sure it is set in the new settings.py file.
if fileName == 'settings.py' and getattr( self.settings, 'globalAuthUsername', None ) is not None and getattr( self.settings, 'globalAuthPassword', None ) is not None:
fileContent = fileContent.replace( 'globalAuthPassword = None', 'globalAuthPassword=%r' % self.settings.globalAuthPassword )
fileContent = fileContent.replace( 'globalAuthUsername = None', 'globalAuthUsername=%r' % self.settings.globalAuthUsername )
fileSystemName = os.path.join( self.agentDir, fileName )
newFile = open( fileSystemName, 'w' )
try:
newFile.write( fileContent )
finally:
if newFile is not None:
newFile.close()
# Stop the current agent process
try:
self.processContainer.stopAgentProcess()
self.settings.settingsAgentVersion = newAgentVersion
self.logger.info( 'Agent upgraded to version: ' + newAgentVersion + ' - there is up to a five minute timeout before data will be sent again' )
except Exception, e:
self.logger.error( 'Problem restarting agent process: ' + traceback.format_exc( e ) )
#
# Run the process monitor and update threads.
#
if __name__ == "__main__":
try:
_logger.info( 'Starting agent parent process - version: %s' % ( _settings.settingsAgentVersion ) )
_logger.info( 'Note: If you have hundreds or thousands of databases, disable dbstats on the settings page before running the MMS agent.' )
processContainer = AgentProcessContainer()
# Star the agent monitor thread.
monitorThread = AgentProcessMonitorThread( _logger, sys.path[0], processContainer )
monitorThread.setName( 'AgentProcessMonitorThread' )
monitorThread.setDaemon( True )
monitorThread.start()
# If enabled, start the shutdown listener thread (disabled by default).
if _settings.shutdownAgentBindAddr is not None:
shutdownListenerThread = AgentShutdownListenerThread( _logger, _settings )
shutdownListenerThread.setName( 'AgentShutdownListenerThread' )
shutdownListenerThread.setDaemon( True )
shutdownListenerThread.start()
if _settings.autoUpdateEnabled:
updateThread = AgentUpdateThread( _logger, sys.path[0], _settings, processContainer )
updateThread.setName( 'AgentUpdateThread' )
updateThread.setDaemon( True )
updateThread.start()
_logger.info( 'Started agent parent process - version: %s' % ( _settings.settingsAgentVersion ) )
# The parent process will let the child process know it's alive.
while True:
try:
time.sleep( 2 )
processContainer.pingAgentProcess()
except Exception, exc:
_logger.error( traceback.format_exc( exc ) )
except KeyboardInterrupt:
processContainer.stopAgentProcess()
except Exception, ex:
_logger.error( traceback.format_exc( ex ) )
|
mit
|
[
624,
199,
8,
35,
9,
1898,
7760,
12,
1616,
2268,
199,
199,
2765,
365,
282,
1768,
641,
282,
2530,
84,
753,
14,
4226,
440,
2811,
642,
570,
1,
199,
624,
199,
199,
3,
4693,
199,
646,
2202,
465,
485,
1751,
199,
646,
943,
2028,
199,
199,
3,
2018,
199,
646,
984,
12,
2838,
12,
900,
12,
747,
12,
20330,
12,
4011,
18,
12,
5796,
12,
3873,
12,
5190,
199,
199,
893,
26,
272,
492,
8337,
199,
2590,
3545,
26,
272,
984,
14,
2224,
8,
283,
3170,
446,
1265,
1471,
1172,
8337,
4903,
446,
1937,
27781,
367,
1655,
2256,
7,
776,
199,
199,
63,
2921,
275,
943,
2028,
14,
826,
4455,
342,
199,
199,
3450,
14,
5486,
2593,
8,
485,
1751,
14,
3450,
63,
2593,
776,
199,
199,
63,
29380,
3353,
275,
488,
199,
199,
63,
1412,
29620,
275,
747,
14,
17829,
342,
199,
199,
3,
7649,
436,
7114,
314,
3464,
1568,
14,
199,
893,
26,
272,
5796,
14,
2340,
63,
890,
8,
21292,
6683,
776,
199,
2590,
26,
272,
986,
199,
199,
692,
485,
1751,
14,
596,
83,
63,
498,
508,
10267,
3735,
63,
3078,
32,
356,
272,
984,
14,
2224,
8,
283,
3170,
446,
1265,
1471,
663,
2195,
768,
3735,
63,
3078,
32,
446,
1937,
4178,
921,
596,
83,
14,
709,
2268,
14,
957,
15,
1751,
7,
776,
199,
199,
692,
485,
1751,
14,
4731,
63,
498,
508,
10267,
12961,
63,
3078,
32,
356,
272,
984,
14,
2224,
8,
283,
3170,
446,
1265,
1471,
663,
2195,
768,
12961,
63,
3078,
32,
446,
1937,
4178,
921,
596,
83,
14,
709,
2268,
14,
957,
15,
1751,
7,
776,
199,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
499,
12,
841,
3461,
272,
984,
14,
2224,
8,
283,
3170,
446,
2269,
2018,
446,
314,
603,
3053,
6631,
5074,
2018,
499,
14,
20,
503,
10948,
7,
776,
199,
199,
3,
4155,
3238,
21878,
365,
4903,
199,
893,
26,
272,
492,
21878,
272,
492,
330,
834,
199,
2590,
3545,
26,
272,
984,
14,
2224,
8,
283,
3170,
446,
21878,
440,
4903,
446,
1937,
26,
1455,
921,
1246,
14,
22130,
13152,
14,
1308,
15,
1548,
15,
446,
1255,
26,
8837,
63,
3174,
21878,
7,
776,
199,
199,
3,
2670,
314,
1015,
402,
21878,
14,
199,
647,
86,
275,
21878,
14,
1023,
199,
692,
298,
5312,
2,
315,
2935,
8,
1134,
86,
3461,
272,
1134,
86,
275,
1134,
86,
14,
5312,
8,
298,
5207,
29688,
16,
61,
272,
485,
29380,
3353,
275,
1134,
86,
272,
340,
2341,
8,
1109,
12,
1134,
86,
14,
1294,
7563,
776,
665,
359,
413,
12,
1749,
2189,
267,
984,
14,
2224,
8,
283,
3170,
446,
710,
603,
3053,
6631,
5074,
21878,
413,
14,
25,
503,
10948,
26,
8837,
63,
3174,
446,
53,
21878,
7,
776,
339,
340,
485,
1751,
14,
1180,
51,
2482,
30462,
22122,
26,
267,
340,
2341,
8,
1109,
12,
1134,
86,
14,
1294,
7563,
776,
665,
359,
499,
12,
413,
12,
413,
2189,
288,
984,
14,
2224,
8,
283,
3170,
446,
710,
603,
3053,
6631,
5074,
21878,
499,
14,
17,
14,
17,
503,
10948,
370,
675,
7799,
26,
8837,
63,
3174,
446,
53,
21878,
7,
776,
199,
199,
63,
29380,
3353,
275,
21878,
14,
1023,
199,
199,
533,
19866,
3498,
4076,
8,
909,
3461,
272,
408,
13874,
314,
2429,
436,
4650,
370,
314,
6631,
2112,
14,
408,
339,
347,
636,
826,
721,
291,
3461,
267,
408,
21026,
314,
4650,
436,
4205,
2112,
370,
7179,
408,
267,
291,
14,
831,
275,
5796,
14,
6432,
342,
267,
291,
14,
4054,
275,
488,
339,
347,
18249,
7788,
3498,
8,
291,
3461,
267,
408,
510,
316,
314,
6631,
2112,
408,
267,
862,
26,
288,
291,
14,
831,
14,
8174,
342,
953,
340,
291,
14,
4054,
365,
488,
503,
291,
14,
4054,
14,
6843,
342,
365,
440,
488,
26,
355,
372,
953,
291,
14,
4054,
14,
6626,
14,
952,
8,
283,
5006,
60,
78,
7,
776,
288,
291,
14,
4054,
14,
6626,
14,
4939,
342,
267,
3753,
26,
288,
291,
14,
831,
14,
3221,
342,
339,
347,
3631,
7788,
3498,
8,
291,
3461,
267,
408,
10217,
314,
3631,
1245,
370,
314,
6631,
2112,
408,
267,
862,
26,
288,
291,
14,
831,
14,
8174,
342,
953,
340,
291,
14,
4054,
365,
488,
503,
291,
14,
4054,
14,
6843,
342,
365,
440,
488,
26,
355,
372,
953,
291,
14,
4054,
14,
6626,
14,
952,
8,
283,
3239,
11552,
60,
78,
7,
776,
288,
291,
14,
4054,
14,
6626,
14,
4939,
342,
953,
900,
14,
4532,
8,
413,
776,
288,
291,
14,
4054,
275,
488,
398,
3753,
26,
288,
291,
14,
831,
14,
3221,
342,
199,
199,
533,
19866,
20043,
10464,
4436,
8,
5796,
14,
4436,
3461,
272,
408,
5289,
1909,
701,
849,
14,
3979,
5223,
1212,
1597,
561,
367,
12842,
3788,
14,
408,
339,
347,
636,
826,
721,
291,
12,
2512,
5665,
12,
2202,
5665,
3461,
267,
408,
11578,
314,
909,
408,
267,
291,
14,
2921,
275,
2512,
5665,
267,
291,
14,
1751,
275,
2202,
5665,
267,
5796,
14,
4436,
855,
826,
721,
291,
776,
339,
347,
1255,
8,
291,
3461,
267,
408,
491,
7938,
367,
314,
12842,
3788,
408,
267,
862,
26,
288,
6771,
275,
2838,
14,
3450,
8,
2838,
14,
5699,
63,
11367,
12,
221,
2838,
14,
9469,
63,
25351,
776,
288,
6771,
14,
3409,
8,
334,
291,
14,
1751,
14,
8831,
7788,
8198,
11404,
12,
291,
14,
1751,
14,
8831,
7788,
8198,
4313,
776,
776,
267,
871,
2186,
12,
325,
26,
288,
291,
14,
2921,
14,
705,
8,
5190,
14,
908,
63,
2804,
8,
325,
776,
776,
398,
291,
14,
2921,
14,
815,
8,
283,
20043,
11647,
3914,
370,
2287,
450,
83,
641,
1844,
450,
68,
7,
450,
334,
291,
14,
1751,
14,
8831,
7788,
8198,
11404,
12,
291,
14,
1751,
14,
8831,
7788,
8198,
4313,
776,
776,
398,
1830,
715,
26,
288,
862,
26,
355,
900,
14,
4532,
8,
959,
776,
355,
666,
12,
5552,
275,
6771,
14,
7637,
504,
8,
6619,
776,
355,
340,
666,
1137,
291,
14,
1751,
14,
8831,
7788,
8198,
30531,
26,
490,
291,
14,
2921,
14,
705,
8,
283,
9226,
4875,
12842,
1245,
687,
26,
450,
83,
7,
450,
5552,
59,
16,
61,
776,
355,
587,
26,
490,
291
] |
[
199,
8,
35,
9,
1898,
7760,
12,
1616,
2268,
199,
199,
2765,
365,
282,
1768,
641,
282,
2530,
84,
753,
14,
4226,
440,
2811,
642,
570,
1,
199,
624,
199,
199,
3,
4693,
199,
646,
2202,
465,
485,
1751,
199,
646,
943,
2028,
199,
199,
3,
2018,
199,
646,
984,
12,
2838,
12,
900,
12,
747,
12,
20330,
12,
4011,
18,
12,
5796,
12,
3873,
12,
5190,
199,
199,
893,
26,
272,
492,
8337,
199,
2590,
3545,
26,
272,
984,
14,
2224,
8,
283,
3170,
446,
1265,
1471,
1172,
8337,
4903,
446,
1937,
27781,
367,
1655,
2256,
7,
776,
199,
199,
63,
2921,
275,
943,
2028,
14,
826,
4455,
342,
199,
199,
3450,
14,
5486,
2593,
8,
485,
1751,
14,
3450,
63,
2593,
776,
199,
199,
63,
29380,
3353,
275,
488,
199,
199,
63,
1412,
29620,
275,
747,
14,
17829,
342,
199,
199,
3,
7649,
436,
7114,
314,
3464,
1568,
14,
199,
893,
26,
272,
5796,
14,
2340,
63,
890,
8,
21292,
6683,
776,
199,
2590,
26,
272,
986,
199,
199,
692,
485,
1751,
14,
596,
83,
63,
498,
508,
10267,
3735,
63,
3078,
32,
356,
272,
984,
14,
2224,
8,
283,
3170,
446,
1265,
1471,
663,
2195,
768,
3735,
63,
3078,
32,
446,
1937,
4178,
921,
596,
83,
14,
709,
2268,
14,
957,
15,
1751,
7,
776,
199,
199,
692,
485,
1751,
14,
4731,
63,
498,
508,
10267,
12961,
63,
3078,
32,
356,
272,
984,
14,
2224,
8,
283,
3170,
446,
1265,
1471,
663,
2195,
768,
12961,
63,
3078,
32,
446,
1937,
4178,
921,
596,
83,
14,
709,
2268,
14,
957,
15,
1751,
7,
776,
199,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
499,
12,
841,
3461,
272,
984,
14,
2224,
8,
283,
3170,
446,
2269,
2018,
446,
314,
603,
3053,
6631,
5074,
2018,
499,
14,
20,
503,
10948,
7,
776,
199,
199,
3,
4155,
3238,
21878,
365,
4903,
199,
893,
26,
272,
492,
21878,
272,
492,
330,
834,
199,
2590,
3545,
26,
272,
984,
14,
2224,
8,
283,
3170,
446,
21878,
440,
4903,
446,
1937,
26,
1455,
921,
1246,
14,
22130,
13152,
14,
1308,
15,
1548,
15,
446,
1255,
26,
8837,
63,
3174,
21878,
7,
776,
199,
199,
3,
2670,
314,
1015,
402,
21878,
14,
199,
647,
86,
275,
21878,
14,
1023,
199,
692,
298,
5312,
2,
315,
2935,
8,
1134,
86,
3461,
272,
1134,
86,
275,
1134,
86,
14,
5312,
8,
298,
5207,
29688,
16,
61,
272,
485,
29380,
3353,
275,
1134,
86,
272,
340,
2341,
8,
1109,
12,
1134,
86,
14,
1294,
7563,
776,
665,
359,
413,
12,
1749,
2189,
267,
984,
14,
2224,
8,
283,
3170,
446,
710,
603,
3053,
6631,
5074,
21878,
413,
14,
25,
503,
10948,
26,
8837,
63,
3174,
446,
53,
21878,
7,
776,
339,
340,
485,
1751,
14,
1180,
51,
2482,
30462,
22122,
26,
267,
340,
2341,
8,
1109,
12,
1134,
86,
14,
1294,
7563,
776,
665,
359,
499,
12,
413,
12,
413,
2189,
288,
984,
14,
2224,
8,
283,
3170,
446,
710,
603,
3053,
6631,
5074,
21878,
499,
14,
17,
14,
17,
503,
10948,
370,
675,
7799,
26,
8837,
63,
3174,
446,
53,
21878,
7,
776,
199,
199,
63,
29380,
3353,
275,
21878,
14,
1023,
199,
199,
533,
19866,
3498,
4076,
8,
909,
3461,
272,
408,
13874,
314,
2429,
436,
4650,
370,
314,
6631,
2112,
14,
408,
339,
347,
636,
826,
721,
291,
3461,
267,
408,
21026,
314,
4650,
436,
4205,
2112,
370,
7179,
408,
267,
291,
14,
831,
275,
5796,
14,
6432,
342,
267,
291,
14,
4054,
275,
488,
339,
347,
18249,
7788,
3498,
8,
291,
3461,
267,
408,
510,
316,
314,
6631,
2112,
408,
267,
862,
26,
288,
291,
14,
831,
14,
8174,
342,
953,
340,
291,
14,
4054,
365,
488,
503,
291,
14,
4054,
14,
6843,
342,
365,
440,
488,
26,
355,
372,
953,
291,
14,
4054,
14,
6626,
14,
952,
8,
283,
5006,
60,
78,
7,
776,
288,
291,
14,
4054,
14,
6626,
14,
4939,
342,
267,
3753,
26,
288,
291,
14,
831,
14,
3221,
342,
339,
347,
3631,
7788,
3498,
8,
291,
3461,
267,
408,
10217,
314,
3631,
1245,
370,
314,
6631,
2112,
408,
267,
862,
26,
288,
291,
14,
831,
14,
8174,
342,
953,
340,
291,
14,
4054,
365,
488,
503,
291,
14,
4054,
14,
6843,
342,
365,
440,
488,
26,
355,
372,
953,
291,
14,
4054,
14,
6626,
14,
952,
8,
283,
3239,
11552,
60,
78,
7,
776,
288,
291,
14,
4054,
14,
6626,
14,
4939,
342,
953,
900,
14,
4532,
8,
413,
776,
288,
291,
14,
4054,
275,
488,
398,
3753,
26,
288,
291,
14,
831,
14,
3221,
342,
199,
199,
533,
19866,
20043,
10464,
4436,
8,
5796,
14,
4436,
3461,
272,
408,
5289,
1909,
701,
849,
14,
3979,
5223,
1212,
1597,
561,
367,
12842,
3788,
14,
408,
339,
347,
636,
826,
721,
291,
12,
2512,
5665,
12,
2202,
5665,
3461,
267,
408,
11578,
314,
909,
408,
267,
291,
14,
2921,
275,
2512,
5665,
267,
291,
14,
1751,
275,
2202,
5665,
267,
5796,
14,
4436,
855,
826,
721,
291,
776,
339,
347,
1255,
8,
291,
3461,
267,
408,
491,
7938,
367,
314,
12842,
3788,
408,
267,
862,
26,
288,
6771,
275,
2838,
14,
3450,
8,
2838,
14,
5699,
63,
11367,
12,
221,
2838,
14,
9469,
63,
25351,
776,
288,
6771,
14,
3409,
8,
334,
291,
14,
1751,
14,
8831,
7788,
8198,
11404,
12,
291,
14,
1751,
14,
8831,
7788,
8198,
4313,
776,
776,
267,
871,
2186,
12,
325,
26,
288,
291,
14,
2921,
14,
705,
8,
5190,
14,
908,
63,
2804,
8,
325,
776,
776,
398,
291,
14,
2921,
14,
815,
8,
283,
20043,
11647,
3914,
370,
2287,
450,
83,
641,
1844,
450,
68,
7,
450,
334,
291,
14,
1751,
14,
8831,
7788,
8198,
11404,
12,
291,
14,
1751,
14,
8831,
7788,
8198,
4313,
776,
776,
398,
1830,
715,
26,
288,
862,
26,
355,
900,
14,
4532,
8,
959,
776,
355,
666,
12,
5552,
275,
6771,
14,
7637,
504,
8,
6619,
776,
355,
340,
666,
1137,
291,
14,
1751,
14,
8831,
7788,
8198,
30531,
26,
490,
291,
14,
2921,
14,
705,
8,
283,
9226,
4875,
12842,
1245,
687,
26,
450,
83,
7,
450,
5552,
59,
16,
61,
776,
355,
587,
26,
490,
291,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
alqfahad/odoo
|
addons/resource/faces/resource.py
|
433
|
25890
|
#@+leo-ver=4
#@+node:@file resource.py
#@@language python
#@<< Copyright >>
#@+node:<< Copyright >>
############################################################################
# Copyright (C) 2005, 2006, 2007, 2008 by Reithinger GmbH
# mreithinger@web.de
#
# This file is part of faces.
#
# faces 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.
#
# faces 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
############################################################################
#@-node:<< Copyright >>
#@nl
#@<< Imports >>
#@+node:<< Imports >>
import pcalendar
import datetime
import utils
import string
import bisect
import plocale
#@-node:<< Imports >>
#@nl
_is_source = True
_to_datetime = pcalendar.to_datetime
_ = plocale.get_gettext()
#@+others
#@+node:_isattrib
#@+doc
#@nonl
# is used to find snapshot attributes
#@-doc
#@@code
def _isattrib(obj, a):
return a[0] != "_" \
and not callable(getattr(obj, a)) \
and not a.endswith("_members") \
and a not in ("name")
#@-node:_isattrib
#@+node:class ResourceCalendar
class ResourceCalendar(object):
"""
The resource calendar saves the load time of a resource.
Is ia sequence of time intervals of loads. An example of
such a sequence is:
[ (datetime.min, 0),
(2006/1/1, 1.0),
(2006/1/10, 0.5),
(2006/1/15, 0) ]
That means the resource:
is free till january the first 2006
is fully booked from january the first to january 10th
is half booked from january 10th to january 15th
is free since january 15th
"""
#@ @+others
#@+node:__init__
def __init__(self, src=None):
if src:
self.bookings = list(src.bookings)
else:
self.bookings = [ (datetime.datetime.min, 0) ]
#@-node:__init__
#@+node:__str__
def __str__(self):
return str(self.bookings)
#@-node:__str__
#@+node:__repr__
def __repr__(self):
return "<ResourceCalendar %s>" % (str(self))
#@-node:__repr__
#@+node:add_load
def add_load(self, start, end, load):
start = _to_datetime(start)
end = _to_datetime(end)
bookings = self.bookings
# the load will be converted in an integer to avoid
# rouning problems
load = int(load * 10000)
start_item = (start, 0)
start_pos = bisect.bisect_left(bookings, start_item)
left_load = 0
left_load = bookings[start_pos - 1][1]
if start_pos < len(bookings) and bookings[start_pos][0] == start:
prev_load = bookings[start_pos][1]
if prev_load + load == left_load:
del bookings[start_pos]
else:
bookings[start_pos] = (start, prev_load + load)
start_pos += 1
else:
bookings.insert(start_pos, (start, load + left_load))
start_pos += 1
item = (datetime.datetime.min, 0)
for i in range(start_pos, len(bookings)):
end_pos = i
item = bookings[i]
if item[0] >= end: break
bookings[i] = (item[0], item[1] + load)
else:
end_pos = len(bookings)
left_load = bookings[end_pos - 1][1]
if item[0] == end:
if item[1] == left_load:
del bookings[end_pos]
else:
bookings.insert(end_pos, (end, left_load - load))
#@-node:add_load
#@+node:end_of_booking_interval
def end_of_booking_interval(self, date):
date = _to_datetime(date)
bookings = self.bookings
date_item = (date, 999999)
date_pos = bisect.bisect_left(bookings, date_item) - 1
next_date = datetime.datetime.max
load = 0
try:
book_item = bookings[date_pos]
load = bookings[date_pos][1] / 10000.0
next_date = bookings[date_pos + 1][0]
except:
pass
return next_date, load
#@-node:end_of_booking_interval
#@+node:find_free_time
def find_free_time(self, start, length, load, max_load):
bookings = self.bookings
if isinstance(start, datetime.datetime):
adjust_date = _to_datetime
else:
adjust_date = start.calendar.EndDate
start = _to_datetime(start)
load = int(load * 10000)
max_load = int(max_load * 10000)
lb = len(bookings)
def next_possible(index):
while index < lb:
sd, lo = bookings[index]
if lo + load <= max_load:
break
index += 1
sd = adjust_date(max(start, sd))
ed = sd + length
end = _to_datetime(ed)
index += 1
while index < lb:
date, lo = bookings[index]
if date >= end:
#I found a good start date
return None, sd
if lo + load > max_load:
return index + 1, None
index += 1
return None, sd
start_item = (start, 1000000)
i = bisect.bisect_left(bookings, start_item) - 1
next_start = None
while not next_start and i < lb:
i, next_start = next_possible(i)
assert(next_start is not None)
return next_start
#@-node:find_free_time
#@+node:get_bookings
def get_bookings(self, start, end):
start = _to_datetime(start)
end = _to_datetime(end)
bookings = self.bookings
start_item = (start, 0)
start_pos = bisect.bisect_left(bookings, start_item)
if start_pos >= len(bookings) or bookings[start_pos][0] > start:
start_pos -= 1
end_item = (end, 0)
end_pos = bisect.bisect_left(bookings, end_item)
return start_pos, end_pos, bookings
#@-node:get_bookings
#@+node:get_load
def get_load(self, date):
date = _to_datetime(date)
bookings = self.bookings
item = (date, 100000)
pos = bisect.bisect_left(bookings, item) - 1
return bookings[pos][1] / 10000.0
#@-node:get_load
#@-others
#@-node:class ResourceCalendar
#@+node:class _ResourceBase
class _ResourceBase(object):
pass
#@-node:class _ResourceBase
#@+node:class _MetaResource
class _MetaResource(type):
doc_template = """
A resource class. The resources default attributes can
be changed when the class ist instanciated, i.e.
%(name)s(max_load=2.0)
@var max_load:
Specify the maximal allowed load sum of all simultaneously
allocated tasks of a resource. A ME{max_load} of 1.0 (default)
means the resource may be fully allocated. A ME{max_load} of 1.3
means the resource may be allocated with 30%% overtime.
@var title:
Specifies an alternative more descriptive name for the task.
@var efficiency:
The efficiency of a resource can be used for two purposes. First
you can use it as a crude way to model a team. A team of 5 people
should have an efficiency of 5.0. Keep in mind that you cannot
track the member of the team individually if you use this
feature. The other use is to model performance variations between
your resources.
@var vacation:
Specifies the vacation of the resource. This attribute is
specified as a list of date literals or date literal intervals.
Be aware that the end of an interval is excluded, i.e. it is
the first working date.
"""
#@ @+others
#@+node:__init__
def __init__(self, name, bases, dict_):
super(_MetaResource, self).__init__(name, bases, dict_)
self.name = name
self.title = dict_.get("title", name)
self._calendar = { None: ResourceCalendar() }
self._tasks = { }
self.__set_vacation()
self.__add_resource(bases[0])
self.__doc__ = dict_.get("__doc__", self.doc_template) % locals()
#@-node:__init__
#@+node:__or__
def __or__(self, other):
return self().__or__(other)
#@-node:__or__
#@+node:__and__
def __and__(self, other):
return self().__and__(other)
#@-node:__and__
#@+node:__cmp__
def __cmp__(self, other):
return cmp(self.name, getattr(other, "name", None))
#@-node:__cmp__
#@+node:__repr__
def __repr__(self):
return "<Resource %s>" % self.name
#@-node:__repr__
#@+node:__str__
def __str__(self):
return repr(self)
#@-node:__str__
#@+node:__set_vacation
def __set_vacation(self):
vacation = self.vacation
if isinstance(vacation, (tuple, list)):
for v in vacation:
if isinstance(v, (tuple, list)):
self.add_vacation(v[0], v[1])
else:
self.add_vacation(v)
else:
self.add_vacation(vacation)
#@-node:__set_vacation
#@+node:__add_resource
def __add_resource(self, base):
if issubclass(base, _ResourceBase):
members = getattr(base, base.__name__ + "_members", [])
members.append(self)
setattr(base, base.__name__ + "_members", members)
#@-node:__add_resource
#@+node:get_members
def get_members(self):
return getattr(self, self.__name__ + "_members", [])
#@-node:get_members
#@+node:add_vacation
def add_vacation(self, start, end=None):
start_date = _to_datetime(start)
if not end:
end_date = start_date.replace(hour=23, minute=59)
else:
end_date = _to_datetime(end)
for cal in self._calendar.itervalues():
cal.add_load(start_date, end_date, 1)
tp = Booking()
tp.start = start_date
tp.end = end_date
tp.book_start = start_date
tp.book_end = end_date
tp.work_time = end_date - start_date
tp.load = 1.0
tp.name = tp.title = _("(vacation)")
tp._id = ""
self._tasks.setdefault("", []).append(tp)
#@-node:add_vacation
#@+node:calendar
def calendar(self, scenario):
try:
return self._calendar[scenario]
except KeyError:
cal = self._calendar[scenario] = ResourceCalendar(self._calendar[None])
return cal
#@-node:calendar
#@-others
#@-node:class _MetaResource
#@+node:make_team
def make_team(resource):
members = resource.get_members()
if not members:
return resource
result = make_team(members[0])
for r in members[1:]:
result = result & make_team(r)
return result
#@-node:make_team
#@+node:class Booking
class Booking(object):
"""
A booking unit for a task.
"""
#@ << declarations >>
#@+node:<< declarations >>
book_start = datetime.datetime.min
book_end = datetime.datetime.max
actual = False
_id = ""
#@-node:<< declarations >>
#@nl
#@ @+others
#@+node:__init__
def __init__(self, task=None):
self.__task = task
#@-node:__init__
#@+node:__cmp__
def __cmp__(self, other):
return cmp(self._id, other._id)
#@-node:__cmp__
#@+node:path
def path(self):
first_dot = self._id.find(".")
return "root" + self._id[first_dot:]
path = property(path)
#@nonl
#@-node:path
#@+node:_idendity_
def _idendity_(self):
return self._id
#@-node:_idendity_
#@+node:__getattr__
def __getattr__(self, name):
if self.__task:
return getattr(self.__task, name)
raise AttributeError("'%s' is not a valid attribute" % (name))
#@-node:__getattr__
#@-others
#@-node:class Booking
#@+node:class ResourceList
class ResourceList(list):
#@ @+others
#@+node:__init__
def __init__(self, *args):
if args: self.extend(args)
#@-node:__init__
#@-others
#@-node:class ResourceList
#@+node:class Resource
class Resource(_ResourceBase):
#@ << declarations >>
#@+node:<< declarations >>
__metaclass__ = _MetaResource
__attrib_completions__ = {\
"max_load": 'max_load = ',
"title": 'title = "|"',
"efficiency": 'efficiency = ',
"vacation": 'vacation = [("|2002-02-01", "2002-02-05")]' }
__type_image__ = "resource16"
max_load = None # the maximum sum load for all task
vacation = ()
efficiency = 1.0
#@-node:<< declarations >>
#@nl
#@ @+others
#@+node:__init__
def __init__(self, **kwargs):
for k, v in kwargs.iteritems():
setattr(self, k, v)
#@-node:__init__
#@+node:_idendity_
def _idendity_(cls):
return "resource:" + cls.__name__
_idendity_ = classmethod(_idendity_)
#@-node:_idendity_
#@+node:__repr__
def __repr__(self):
return "<Resource %s>" % self.__class__.__name__
#@-node:__repr__
#@+node:__str__
def __str__(self):
return repr(self)
#@-node:__str__
#@+node:__call__
def __call__(self):
return self
#@-node:__call__
#@+node:__hash__
def __hash__(self):
return hash(self.__class__)
#@-node:__hash__
#@+node:__cmp__
def __cmp__(self, other):
return cmp(self.name, other.name)
#@-node:__cmp__
#@+node:__or__
def __or__(self, other):
if type(other) is _MetaResource:
other = other()
result = Resource()
result._subresource = _OrResourceGroup(self, other)
return result
#@-node:__or__
#@+node:__and__
def __and__(self, other):
if type(other) is _MetaResource:
other = other()
result = Resource()
result._subresource = _AndResourceGroup(self, other)
return result
#@-node:__and__
#@+node:_permutation_count
def _permutation_count(self):
if hasattr(self, "_subresource"):
return self._subresource._permutation_count()
return 1
#@-node:_permutation_count
#@+node:_get_resources
def _get_resources(self, state):
if hasattr(self, "_subresource"):
result = self._subresource._get_resources(state)
if self.name != "Resource":
result.name = self.name
if self.title != "Resource":
result.title = self.title
return result
result = ResourceList(self)
return result
#@-node:_get_resources
#@+node:all_members
def all_members(self):
if hasattr(self, "_subresource"):
return self._subresource.all_members()
return [ self.__class__ ]
#@-node:all_members
#@+node:unbook_tasks_of_project
def unbook_tasks_of_project(cls, project_id, scenario):
try:
task_list = cls._tasks[scenario]
except KeyError:
return
add_load = cls.calendar(scenario).add_load
for task_id, bookings in task_list.items():
if task_id.startswith(project_id):
for item in bookings:
add_load(item.book_start, item.book_end, -item.load)
del task_list[task_id]
if not task_list:
del cls._tasks[scenario]
unbook_tasks_of_project = classmethod(unbook_tasks_of_project)
#@-node:unbook_tasks_of_project
#@+node:unbook_task
def unbook_task(cls, task):
identdity = task._idendity_()
scenario = task.scenario
try:
task_list = cls._tasks[scenario]
bookings = task_list[identdity]
except KeyError:
return
add_load = cls.calendar(scenario).add_load
for b in bookings:
add_load(b.book_start, b.book_end, -b.load)
del task_list[identdity]
if not task_list:
del cls._tasks[scenario]
unbook_task = classmethod(unbook_task)
#@-node:unbook_task
#@+node:correct_bookings
def correct_bookings(cls, task):
#correct the booking data with the actual task data
try:
tasks = cls._tasks[task.scenario][task._idendity_()]
except KeyError:
return
for t in tasks:
t.start = task.start.to_datetime()
t.end = task.end.to_datetime()
correct_bookings = classmethod(correct_bookings)
#@-node:correct_bookings
#@+node:book_task
def book_task(cls, task, start, end, load, work_time, actual):
if not work_time: return
start = _to_datetime(start)
end = _to_datetime(end)
identdity = task._idendity_()
task_list = cls._tasks.setdefault(task.scenario, {})
bookings = task_list.setdefault(identdity, [])
add_load = cls.calendar(task.scenario).add_load
tb = Booking(task)
tb.book_start = start
tb.book_end = end
tb._id = identdity
tb.load = load
tb.start = _to_datetime(task.start)
tb.end = _to_datetime(task.end)
tb.title = task.title
tb.name = task.name
tb.work_time = int(work_time)
tb.actual = actual
bookings.append(tb)
result = add_load(start, end, load)
return result
book_task = classmethod(book_task)
#@-node:book_task
#@+node:length_of
def length_of(cls, task):
cal = task.root.calendar
bookings = cls.get_bookings(task)
return sum(map(lambda b: task._to_delta(b.work_time).round(), bookings))
length_of = classmethod(length_of)
#@-node:length_of
#@+node:done_of
def done_of(self, task):
cal = task.root.calendar
now = cal.now
bookings = self.get_bookings(task)
if task.__dict__.has_key("effort"):
efficiency = self.efficiency * task.efficiency
else:
efficiency = 1
def book_done(booking):
if booking.book_start >= now:
return 0
factor = 1
if booking.book_end > now:
start = task._to_start(booking.book_start)
end = task._to_end(booking.book_end)
cnow = task._to_start(now)
factor = float(cnow - start) / ((end - start) or 1)
return factor * booking.work_time * efficiency
return task._to_delta(sum(map(book_done, bookings)))
#@-node:done_of
#@+node:todo_of
def todo_of(self, task):
cal = task.root.calendar
now = cal.now
bookings = self.get_bookings(task)
if task.__dict__.has_key("effort"):
efficiency = self.efficiency * task.efficiency
else:
efficiency = 1
def book_todo(booking):
if booking.book_end <= now:
return 0
factor = 1
if booking.book_start < now:
start = task._to_start(booking.book_start)
end = task._to_end(booking.book_end)
cnow = task._to_start(now)
factor = float(end - cnow) / ((end - start) or 1)
return factor * booking.work_time * efficiency
return task._to_delta(sum(map(book_todo, bookings)))
#@-node:todo_of
#@+node:get_bookings
def get_bookings(cls, task):
return cls._tasks.get(task.scenario, {}).get(task._idendity_(), ())
get_bookings = classmethod(get_bookings)
#@-node:get_bookings
#@+node:get_bookings_at
def get_bookings_at(cls, start, end, scenario):
result = []
try:
items = cls._tasks[scenario].iteritems()
except KeyError:
return ()
for task_id, bookings in items:
result += [ booking for booking in bookings
if booking.book_start < end
and booking.book_end > start ]
vacations = cls._tasks.get("", ())
result += [ booking for booking in vacations
if booking.book_start < end
and booking.book_end > start ]
return result
get_bookings_at = classmethod(get_bookings_at)
#@-node:get_bookings_at
#@+node:find_free_time
def find_free_time(cls, start, length, load, max_load, scenario):
return cls.calendar(scenario).find_free_time(start, length, load, max_load)
find_free_time = classmethod(find_free_time)
#@-node:find_free_time
#@+node:get_load
def get_load(cls, date, scenario):
return cls.calendar(scenario).get_load(date)
get_load = classmethod(get_load)
#@-node:get_load
#@+node:end_of_booking_interval
def end_of_booking_interval(cls, date, task):
return cls.calendar(task.scenario).end_of_booking_interval(date)
end_of_booking_interval = classmethod(end_of_booking_interval)
#@-node:end_of_booking_interval
#@+node:snapshot
def snapshot(self):
from task import _as_string
def isattrib(a):
if a == "max_load" and self.max_load is None: return False
if a in ("name", "title", "vacation"): return False
return _isattrib(self, a)
attribs = filter(isattrib, dir(self))
attribs = map(lambda a: "%s=%s" % (a, _as_string(getattr(self, a))),
attribs)
return self.name + "(%s)" % ", ".join(attribs)
#@-node:snapshot
#@-others
#@-node:class Resource
#@+node:class _ResourceGroup
class _ResourceGroup(object):
#@ @+others
#@+node:__init__
def __init__(self, *args):
self.resources = []
for a in args:
self.__append(a)
#@-node:__init__
#@+node:all_members
def all_members(self):
group = reduce(lambda a, b: a + b.all_members(),
self.resources, [])
group = map(lambda r: (r, True), group)
group = dict(group)
group = group.keys()
return group
#@-node:all_members
#@+node:_permutation_count
def _permutation_count(self):
abstract
#@-node:_permutation_count
#@+node:_refactor
def _refactor(self, arg):
pass
#@-node:_refactor
#@+node:__append
def __append(self, arg):
if isinstance(arg, self.__class__):
self.resources += arg.resources
for r in arg.resources:
self._refactor(r)
return
elif isinstance(arg, Resource):
subresources = getattr(arg, "_subresource", None)
if subresources:
self.__append(subresources)
return
else:
self.resources.append(arg)
else:
assert(isinstance(arg, _ResourceGroup))
self.resources.append(arg)
self._refactor(arg)
#@-node:__append
#@+node:__str__
def __str__(self):
op = lower(self.__class__.__name__[0:-13])
return "(" + \
string.join([str(r) for r in self.resources],
" " + op + " ") + \
")"
#@-node:__str__
#@-others
#@-node:class _ResourceGroup
#@+node:class _OrResourceGroup
class _OrResourceGroup(_ResourceGroup):
#@ @+others
#@+node:_get_resources
def _get_resources(self, state):
for r in self.resources:
c = r._permutation_count()
if c <= state:
state -= c
else:
return r._get_resources(state)
assert(0)
#@-node:_get_resources
#@+node:_permutation_count
def _permutation_count(self):
return sum([ r._permutation_count() for r in self.resources])
#@-node:_permutation_count
#@-others
#@-node:class _OrResourceGroup
#@+node:class _AndResourceGroup
class _AndResourceGroup(_ResourceGroup):
#@ @+others
#@+node:__init__
def __init__(self, *args):
self.factors = [ 1 ]
_ResourceGroup.__init__(self, *args)
#@-node:__init__
#@+node:_refactor
def _refactor(self, arg):
count = arg._permutation_count()
self.factors = [ count * f for f in self.factors ]
self.factors.append(1)
#@-node:_refactor
#@+node:_permutation_count
#print "AndResourceGroup", count, arg, self.factors
def _permutation_count(self):
return self.factors[0]
#@-node:_permutation_count
#@+node:_get_resources
def _get_resources(self, state):
"""delivers None when there are duplicate resources"""
result = []
for i in range(1, len(self.factors)):
f = self.factors[i]
substate = state / f
state %= f
result.append(self.resources[i - 1]._get_resources(substate))
result = ResourceList(*list(utils.flatten(result)))
dupl_test = { }
for r in result:
if dupl_test.has_key(r):
return None
else:
dupl_test[r] = 1
return result
#@-node:_get_resources
#@+node:_has_duplicates
def _has_duplicates(self, state):
resources = self._get_resources(state)
tmp = { }
for r in resources:
if tmp.has_key(r):
return True
tmp[r] = 1
return False
#@-node:_has_duplicates
#@-others
#@-node:class _AndResourceGroup
#@-others
#@-node:@file resource.py
#@-leo
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
17577,
11,
274,
79,
13,
422,
29,
20,
199,
17577,
11,
932,
26,
32,
493,
2073,
14,
647,
199,
3,
7492,
3671,
2366,
199,
17577,
8999,
1898,
4331,
199,
17577,
11,
932,
32022,
1898,
4331,
199,
3949,
381,
199,
3,
257,
1898,
334,
35,
9,
11811,
12,
8315,
12,
10219,
12,
9079,
701,
799,
448,
7886,
23428,
199,
3,
257,
333,
264,
448,
7886,
32,
2520,
14,
271,
199,
3,
199,
3,
257,
961,
570,
365,
1777,
402,
21143,
14,
199,
3,
199,
3,
257,
21143,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
257,
21143,
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,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
199,
3,
257,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
257,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
3949,
381,
199,
199,
17577,
13,
932,
32022,
1898,
4331,
199,
17577,
7530,
199,
17577,
8999,
24339,
4331,
199,
17577,
11,
932,
32022,
24339,
4331,
199,
646,
299,
8183,
199,
646,
2197,
199,
646,
3778,
199,
646,
1059,
199,
646,
19063,
199,
646,
299,
5508,
199,
17577,
13,
932,
32022,
24339,
4331,
199,
17577,
7530,
199,
199,
63,
374,
63,
1365,
275,
715,
199,
63,
475,
63,
2083,
275,
299,
8183,
14,
475,
63,
2083,
199,
63,
275,
299,
5508,
14,
362,
63,
5152,
342,
199,
199,
17577,
11,
21714,
199,
17577,
11,
932,
22003,
374,
6640,
199,
17577,
11,
1301,
199,
17577,
2865,
76,
199,
3,
365,
1202,
370,
2342,
5740,
3004,
199,
17577,
13,
1301,
199,
3,
7492,
600,
199,
318,
485,
374,
6640,
8,
1113,
12,
282,
304,
272,
372,
282,
59,
16,
61,
1137,
14220,
971,
1779,
436,
440,
4550,
8,
5675,
8,
1113,
12,
282,
430,
971,
1779,
436,
440,
282,
14,
4130,
11008,
6334,
531,
971,
1779,
436,
282,
440,
315,
1689,
354,
531,
199,
17577,
13,
932,
22003,
374,
6640,
199,
17577,
11,
932,
26,
533,
7337,
18688,
199,
533,
7337,
18688,
8,
785,
304,
272,
408,
272,
710,
2073,
11234,
23050,
314,
2248,
900,
402,
282,
2073,
14,
272,
6596,
284,
65,
3414,
402,
900,
15802,
402,
14404,
14,
1626,
2893,
402,
272,
4066,
282,
3414,
365,
26,
267,
359,
334,
2083,
14,
827,
12,
378,
395,
881,
334,
7968,
15,
17,
15,
17,
12,
413,
14,
16,
395,
881,
334,
7968,
15,
17,
15,
709,
12,
378,
14,
21,
395,
881,
334,
7968,
15,
17,
15,
1046,
12,
378,
9,
1622,
339,
10314,
4910,
314,
2073,
26,
267,
365,
2867,
31801,
1335,
290,
20527,
314,
1642,
8315,
267,
365,
9999,
6719,
379,
687,
1335,
290,
20527,
314,
1642,
370,
1335,
290,
20527,
1616,
273,
267,
365,
12995,
6719,
379,
687,
1335,
290,
20527,
1616,
273,
370,
1335,
290,
20527,
4114,
273,
267,
365,
2867,
3967,
1335,
290,
20527,
4114,
273,
272,
408,
339,
9213,
198,
32,
11,
21714,
272,
18215,
932,
21363,
826,
363,
272,
347,
636,
826,
721,
277,
12,
2928,
29,
403,
304,
267,
340,
2928,
26,
288,
291,
14,
2706,
780,
275,
769,
8,
2164,
14,
2706,
780,
9,
267,
587,
26,
288,
291,
14,
2706,
780,
275,
359,
334,
2083,
14,
2083,
14,
827,
12,
378,
9,
1622,
272,
18059,
932,
21363,
826,
363,
272,
18215,
932,
21363,
495,
363,
272,
347,
636,
495,
721,
277,
304,
267,
372,
620,
8,
277,
14,
2706,
780,
9,
272,
18059,
932,
21363,
495,
363,
272,
18215,
932,
21363,
2722,
363,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
3886,
4031,
18688,
450,
83,
4335,
450,
334,
495,
8,
277,
430,
272,
18059,
932,
21363,
2722,
363,
272,
18215,
932,
26,
525,
63,
912,
272,
347,
1050,
63,
912,
8,
277,
12,
1343,
12,
1284,
12,
2248,
304,
267,
1343,
275,
485,
475,
63,
2083,
8,
928,
9,
267,
1284,
275,
485,
475,
63,
2083,
8,
500,
9,
398,
6719,
780,
275,
291,
14,
2706,
780,
398,
327,
314,
2248,
911,
506,
6702,
315,
376,
3000,
370,
5126,
267,
327,
882,
324,
316,
8826,
267,
2248,
275,
1109,
8,
912,
627,
11630,
9,
398,
1343,
63,
1053,
275,
334,
928,
12,
378,
9,
267,
1343,
63,
1712,
275,
19063,
14,
23247,
63,
3039,
8,
2706,
780,
12,
1343,
63,
1053,
9,
398,
3602,
63,
912,
275,
378,
267,
3602,
63,
912,
275,
6719,
780,
59,
928,
63,
1712,
446,
413,
1527,
17,
61,
398,
340,
1343,
63,
1712,
665,
822,
8,
2706,
780,
9,
436,
6719,
780,
59,
928,
63,
1712,
1527,
16,
61,
508,
1343,
26,
288,
5071,
63,
912,
275,
6719,
780,
59,
928,
63,
1712,
1527,
17,
61,
288,
340,
5071,
63,
912,
435,
2248,
508,
3602,
63,
912,
26,
355,
2150,
6719,
780,
59,
928,
63,
1712,
61,
288,
587,
26,
355,
6719,
780,
59,
928,
63,
1712,
61,
275,
334,
928,
12,
5071,
63,
912,
435,
2248,
9,
355,
1343,
63,
1712,
847,
413,
267,
587,
26,
288,
6719,
780,
14,
3176,
8,
928,
63,
1712,
12,
334,
928,
12,
2248,
435,
3602,
63,
912,
430,
288,
1343,
63,
1712,
847,
413,
398,
1242,
275,
334,
2083,
14,
2083,
14,
827,
12,
378,
9,
267,
367,
284,
315,
1425,
8,
928,
63,
1712,
12,
822,
8,
2706,
780,
2298,
288,
1284,
63,
1712,
275,
284,
288,
1242,
275,
6719,
780,
59,
73,
61,
288,
340,
1242,
59,
16,
61,
2356,
1284,
26,
2059,
288,
6719,
780,
59,
73,
61,
275,
334,
1053,
59,
16,
467,
1242,
59,
17,
61,
435
] |
[
11,
274,
79,
13,
422,
29,
20,
199,
17577,
11,
932,
26,
32,
493,
2073,
14,
647,
199,
3,
7492,
3671,
2366,
199,
17577,
8999,
1898,
4331,
199,
17577,
11,
932,
32022,
1898,
4331,
199,
3949,
381,
199,
3,
257,
1898,
334,
35,
9,
11811,
12,
8315,
12,
10219,
12,
9079,
701,
799,
448,
7886,
23428,
199,
3,
257,
333,
264,
448,
7886,
32,
2520,
14,
271,
199,
3,
199,
3,
257,
961,
570,
365,
1777,
402,
21143,
14,
199,
3,
199,
3,
257,
21143,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
257,
21143,
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,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
199,
3,
257,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
257,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
3949,
381,
199,
199,
17577,
13,
932,
32022,
1898,
4331,
199,
17577,
7530,
199,
17577,
8999,
24339,
4331,
199,
17577,
11,
932,
32022,
24339,
4331,
199,
646,
299,
8183,
199,
646,
2197,
199,
646,
3778,
199,
646,
1059,
199,
646,
19063,
199,
646,
299,
5508,
199,
17577,
13,
932,
32022,
24339,
4331,
199,
17577,
7530,
199,
199,
63,
374,
63,
1365,
275,
715,
199,
63,
475,
63,
2083,
275,
299,
8183,
14,
475,
63,
2083,
199,
63,
275,
299,
5508,
14,
362,
63,
5152,
342,
199,
199,
17577,
11,
21714,
199,
17577,
11,
932,
22003,
374,
6640,
199,
17577,
11,
1301,
199,
17577,
2865,
76,
199,
3,
365,
1202,
370,
2342,
5740,
3004,
199,
17577,
13,
1301,
199,
3,
7492,
600,
199,
318,
485,
374,
6640,
8,
1113,
12,
282,
304,
272,
372,
282,
59,
16,
61,
1137,
14220,
971,
1779,
436,
440,
4550,
8,
5675,
8,
1113,
12,
282,
430,
971,
1779,
436,
440,
282,
14,
4130,
11008,
6334,
531,
971,
1779,
436,
282,
440,
315,
1689,
354,
531,
199,
17577,
13,
932,
22003,
374,
6640,
199,
17577,
11,
932,
26,
533,
7337,
18688,
199,
533,
7337,
18688,
8,
785,
304,
272,
408,
272,
710,
2073,
11234,
23050,
314,
2248,
900,
402,
282,
2073,
14,
272,
6596,
284,
65,
3414,
402,
900,
15802,
402,
14404,
14,
1626,
2893,
402,
272,
4066,
282,
3414,
365,
26,
267,
359,
334,
2083,
14,
827,
12,
378,
395,
881,
334,
7968,
15,
17,
15,
17,
12,
413,
14,
16,
395,
881,
334,
7968,
15,
17,
15,
709,
12,
378,
14,
21,
395,
881,
334,
7968,
15,
17,
15,
1046,
12,
378,
9,
1622,
339,
10314,
4910,
314,
2073,
26,
267,
365,
2867,
31801,
1335,
290,
20527,
314,
1642,
8315,
267,
365,
9999,
6719,
379,
687,
1335,
290,
20527,
314,
1642,
370,
1335,
290,
20527,
1616,
273,
267,
365,
12995,
6719,
379,
687,
1335,
290,
20527,
1616,
273,
370,
1335,
290,
20527,
4114,
273,
267,
365,
2867,
3967,
1335,
290,
20527,
4114,
273,
272,
408,
339,
9213,
198,
32,
11,
21714,
272,
18215,
932,
21363,
826,
363,
272,
347,
636,
826,
721,
277,
12,
2928,
29,
403,
304,
267,
340,
2928,
26,
288,
291,
14,
2706,
780,
275,
769,
8,
2164,
14,
2706,
780,
9,
267,
587,
26,
288,
291,
14,
2706,
780,
275,
359,
334,
2083,
14,
2083,
14,
827,
12,
378,
9,
1622,
272,
18059,
932,
21363,
826,
363,
272,
18215,
932,
21363,
495,
363,
272,
347,
636,
495,
721,
277,
304,
267,
372,
620,
8,
277,
14,
2706,
780,
9,
272,
18059,
932,
21363,
495,
363,
272,
18215,
932,
21363,
2722,
363,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
3886,
4031,
18688,
450,
83,
4335,
450,
334,
495,
8,
277,
430,
272,
18059,
932,
21363,
2722,
363,
272,
18215,
932,
26,
525,
63,
912,
272,
347,
1050,
63,
912,
8,
277,
12,
1343,
12,
1284,
12,
2248,
304,
267,
1343,
275,
485,
475,
63,
2083,
8,
928,
9,
267,
1284,
275,
485,
475,
63,
2083,
8,
500,
9,
398,
6719,
780,
275,
291,
14,
2706,
780,
398,
327,
314,
2248,
911,
506,
6702,
315,
376,
3000,
370,
5126,
267,
327,
882,
324,
316,
8826,
267,
2248,
275,
1109,
8,
912,
627,
11630,
9,
398,
1343,
63,
1053,
275,
334,
928,
12,
378,
9,
267,
1343,
63,
1712,
275,
19063,
14,
23247,
63,
3039,
8,
2706,
780,
12,
1343,
63,
1053,
9,
398,
3602,
63,
912,
275,
378,
267,
3602,
63,
912,
275,
6719,
780,
59,
928,
63,
1712,
446,
413,
1527,
17,
61,
398,
340,
1343,
63,
1712,
665,
822,
8,
2706,
780,
9,
436,
6719,
780,
59,
928,
63,
1712,
1527,
16,
61,
508,
1343,
26,
288,
5071,
63,
912,
275,
6719,
780,
59,
928,
63,
1712,
1527,
17,
61,
288,
340,
5071,
63,
912,
435,
2248,
508,
3602,
63,
912,
26,
355,
2150,
6719,
780,
59,
928,
63,
1712,
61,
288,
587,
26,
355,
6719,
780,
59,
928,
63,
1712,
61,
275,
334,
928,
12,
5071,
63,
912,
435,
2248,
9,
355,
1343,
63,
1712,
847,
413,
267,
587,
26,
288,
6719,
780,
14,
3176,
8,
928,
63,
1712,
12,
334,
928,
12,
2248,
435,
3602,
63,
912,
430,
288,
1343,
63,
1712,
847,
413,
398,
1242,
275,
334,
2083,
14,
2083,
14,
827,
12,
378,
9,
267,
367,
284,
315,
1425,
8,
928,
63,
1712,
12,
822,
8,
2706,
780,
2298,
288,
1284,
63,
1712,
275,
284,
288,
1242,
275,
6719,
780,
59,
73,
61,
288,
340,
1242,
59,
16,
61,
2356,
1284,
26,
2059,
288,
6719,
780,
59,
73,
61,
275,
334,
1053,
59,
16,
467,
1242,
59,
17,
61,
435,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
adhoc-dev/odoo-addons
|
portal_partner_fix/__openerp__.py
|
4
|
1590
|
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2015 ADHOC SA (http://www.adhoc.com.ar)
# All Rights Reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Portal Partner Fix',
'version': '8.0.1.0.0',
'category': '',
'sequence': 14,
'summary': '',
'description': """
Portal Partner Fix
==================
Let user read his commercial partner
""",
'author': 'ADHOC SA',
'website': 'www.adhoc.com.ar',
'license': 'AGPL-3',
'images': [
],
'depends': [
'portal',
],
'data': [
'security/portal_security.xml',
],
'demo': [
],
'test': [
],
'installable': True,
'auto_install': False,
'application': False,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
1898,
334,
35,
9,
6900,
221,
16271,
2979,
35,
13950,
221,
334,
1014,
921,
1544,
14,
350,
20402,
14,
957,
14,
285,
9,
199,
3,
259,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
91,
272,
283,
354,
356,
283,
26708,
31351,
14811,
297,
272,
283,
1023,
356,
283,
24,
14,
16,
14,
17,
14,
16,
14,
16,
297,
272,
283,
3710,
356,
3260,
272,
283,
4041,
356,
4329,
12,
272,
283,
4705,
356,
3260,
272,
283,
1802,
356,
408,
199,
26708,
31351,
14811,
199,
1280,
389,
199,
15314,
922,
1586,
17049,
2414,
23012,
5854,
272,
10327,
272,
283,
2502,
356,
221,
283,
1554,
2979,
35,
13950,
297,
272,
283,
7360,
356,
283,
1544,
14,
350,
20402,
14,
957,
14,
285,
297,
272,
283,
1682,
356,
283,
1254,
2749,
13,
19,
297,
272,
283,
4782,
356,
359,
272,
2156,
272,
283,
8912,
356,
359,
267,
283,
8707,
297,
272,
2156,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
8707,
63,
4416,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
359,
272,
2156,
272,
283,
396,
356,
359,
272,
2156,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
272,
283,
3578,
356,
756,
12,
199,
93,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
1898,
334,
35,
9,
6900,
221,
16271,
2979,
35,
13950,
221,
334,
1014,
921,
1544,
14,
350,
20402,
14,
957,
14,
285,
9,
199,
3,
259,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
91,
272,
283,
354,
356,
283,
26708,
31351,
14811,
297,
272,
283,
1023,
356,
283,
24,
14,
16,
14,
17,
14,
16,
14,
16,
297,
272,
283,
3710,
356,
3260,
272,
283,
4041,
356,
4329,
12,
272,
283,
4705,
356,
3260,
272,
283,
1802,
356,
408,
199,
26708,
31351,
14811,
199,
1280,
389,
199,
15314,
922,
1586,
17049,
2414,
23012,
5854,
272,
10327,
272,
283,
2502,
356,
221,
283,
1554,
2979,
35,
13950,
297,
272,
283,
7360,
356,
283,
1544,
14,
350,
20402,
14,
957,
14,
285,
297,
272,
283,
1682,
356,
283,
1254,
2749,
13,
19,
297,
272,
283,
4782,
356,
359,
272,
2156,
272,
283,
8912,
356,
359,
267,
283,
8707,
297,
272,
2156,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
8707,
63,
4416,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
359,
272,
2156,
272,
283,
396,
356,
359,
272,
2156,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
272,
283,
3578,
356,
756,
12,
199,
93,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
marcosschroh/Flask-Simple-Serializer
|
flask_simple_serializer/serializers.py
|
1
|
2916
|
import six
from werkzeug.datastructures import MultiDict
from collections import OrderedDict
from wtforms.form import Form
from wtforms_alchemy import ModelForm
def serializer_factory(base=Form):
class BaseSerializer(base):
def __init__(self, data_dict=None, model_instance=None, **kwargs):
# Supouse that the data is already a Python Dict
self._validate_called = None
self.model_instance = model_instance
self.formdata = MultiDict({})
if data_dict:
if not isinstance(data_dict, dict):
raise ValueError("Data must be a Dict instance")
self.formdata = MultiDict(data_dict)
super(BaseSerializer, self).__init__(formdata=self.formdata, **kwargs)
def is_valid(self):
self._validate_called = True
return super(BaseSerializer, self).validate()
@property
def data(self):
if not self._validate_called:
msg = 'You must call `.is_valid()` before accessing `.data`.'
raise AssertionError(msg)
return super(BaseSerializer, self).data
def validate(self):
raise NotImplementedError
@property
def errors(self):
if not self._validate_called:
msg = 'You must call `.is_valid()` before accessing `.errors`.'
raise AssertionError(msg)
return super(BaseSerializer, self).errors
return BaseSerializer
BaseSerializer = serializer_factory()
ModelBaseSerilizer = serializer_factory(base=ModelForm)
class SerializerMetaclass(type):
"""
This metaclass sets a dictionary named `_declared_fields` on the class.
Any instances of `Field` included as attributes on either the class
or on any of its superclasses will be include in the
`_declared_fields` dictionary.
"""
@classmethod
def _get_declared_fields(cls, bases, attrs):
fields = [(field_name, attrs.pop(field_name))
for field_name, obj in list(attrs.items())
if isinstance(obj, dict)]
fields.sort(key=lambda x: x[1]._creation_counter)
# If this class is subclassing another Serializer, add that Serializer's
# fields. Note that we loop over the bases in *reverse*. This is necessary
# in order to maintain the correct order of fields.
for base in reversed(bases):
if hasattr(base, '_declared_fields'):
fields = list(base._declared_fields.items()) + fields
return OrderedDict(fields)
def __new__(cls, name, bases, attrs):
attrs['_declared_fields'] = cls._get_declared_fields(bases, attrs)
return super(SerializerMetaclass, cls).__new__(cls, name, bases, attrs)
class Serializer(BaseSerializer):
pass
class ModelSerializer(ModelBaseSerilizer):
pass
|
mit
|
[
646,
3816,
199,
199,
504,
10380,
14,
23004,
492,
29393,
199,
504,
5055,
492,
8773,
199,
199,
504,
24756,
3351,
14,
964,
492,
8204,
199,
504,
24756,
3351,
63,
6732,
492,
28455,
421,
199,
318,
9146,
63,
3702,
8,
1095,
29,
2821,
304,
339,
1021,
3523,
7299,
8,
1095,
304,
398,
347,
636,
826,
721,
277,
12,
666,
63,
807,
29,
403,
12,
1402,
63,
842,
29,
403,
12,
1011,
958,
304,
288,
327,
6820,
7130,
626,
314,
666,
365,
2575,
282,
2018,
7448,
288,
291,
423,
3502,
63,
3527,
275,
488,
288,
291,
14,
1238,
63,
842,
275,
1402,
63,
842,
288,
291,
14,
30942,
275,
29393,
14079,
953,
340,
666,
63,
807,
26,
355,
340,
440,
1228,
8,
576,
63,
807,
12,
1211,
304,
490,
746,
1722,
480,
1451,
1471,
506,
282,
7448,
1256,
531,
355,
291,
14,
30942,
275,
29393,
8,
576,
63,
807,
9,
953,
1613,
8,
1563,
7299,
12,
291,
2843,
826,
721,
30942,
29,
277,
14,
30942,
12,
1011,
958,
9,
398,
347,
365,
63,
1078,
8,
277,
304,
288,
291,
423,
3502,
63,
3527,
275,
715,
288,
372,
1613,
8,
1563,
7299,
12,
291,
680,
3502,
342,
398,
768,
1829,
267,
347,
666,
8,
277,
304,
288,
340,
440,
291,
423,
3502,
63,
3527,
26,
355,
1499,
275,
283,
5556,
1471,
1240,
19853,
374,
63,
1078,
11995,
2544,
18549,
19853,
576,
2313,
7,
355,
746,
9070,
8,
1328,
9,
288,
372,
1613,
8,
1563,
7299,
12,
291,
680,
576,
398,
347,
4107,
8,
277,
304,
288,
746,
4279,
398,
768,
1829,
267,
347,
2552,
8,
277,
304,
288,
340,
440,
291,
423,
3502,
63,
3527,
26,
355,
1499,
275,
283,
5556,
1471,
1240,
19853,
374,
63,
1078,
11995,
2544,
18549,
19853,
2550,
2313,
7,
355,
746,
9070,
8,
1328,
9,
288,
372,
1613,
8,
1563,
7299,
12,
291,
680,
2550,
339,
372,
3523,
7299,
421,
199,
1563,
7299,
275,
9146,
63,
3702,
342,
199,
1685,
1563,
1505,
1638,
2282,
275,
9146,
63,
3702,
8,
1095,
29,
15937,
9,
421,
199,
533,
25555,
29387,
8,
466,
304,
272,
408,
272,
961,
17074,
5951,
282,
2600,
4310,
18494,
13545,
63,
955,
64,
641,
314,
1021,
14,
272,
6184,
4454,
402,
658,
792,
64,
5120,
465,
3004,
641,
1902,
314,
1021,
272,
503,
641,
1263,
402,
2399,
1613,
2888,
911,
506,
2387,
315,
314,
272,
18494,
13545,
63,
955,
64,
2600,
14,
272,
408,
339,
768,
3744,
272,
347,
485,
362,
63,
13545,
63,
955,
8,
1886,
12,
9768,
12,
3290,
304,
267,
1504,
275,
3842,
698,
63,
354,
12,
3290,
14,
1935,
8,
698,
63,
354,
430,
2116,
367,
901,
63,
354,
12,
1559,
315,
769,
8,
3288,
14,
1744,
1012,
2116,
340,
1228,
8,
1113,
12,
1211,
1874,
267,
1504,
14,
3191,
8,
498,
29,
2734,
671,
26,
671,
59,
17,
18289,
8782,
63,
5337,
9,
398,
327,
982,
642,
1021,
365,
24572,
4573,
25555,
12,
1050,
626,
25555,
1159,
267,
327,
1504,
14,
221,
3390,
626,
781,
4438,
1806,
314,
9768,
315,
627,
4471,
4856,
961,
365,
5784,
267,
327,
315,
1865,
370,
11075,
314,
3211,
1865,
402,
1504,
14,
267,
367,
1300,
315,
10822,
8,
12087,
304,
288,
340,
2688,
8,
1095,
12,
2513,
13545,
63,
955,
735,
355,
1504,
275,
769,
8,
1095,
423,
13545,
63,
955,
14,
1744,
1012,
435,
1504,
398,
372,
8773,
8,
955,
9,
339,
347,
636,
1222,
721,
1886,
12,
536,
12,
9768,
12,
3290,
304,
267,
3290,
8680,
13545,
63,
955,
418,
275,
843,
423,
362,
63,
13545,
63,
955,
8,
12087,
12,
3290,
9,
267,
372,
1613,
8,
7299,
29387,
12,
843,
2843,
1222,
721,
1886,
12,
536,
12,
9768,
12,
3290,
9,
421,
199,
533,
25555,
8,
1563,
7299,
304,
272,
986,
421,
199,
533,
5822,
7299,
8,
1685,
1563,
1505,
1638,
2282,
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
] |
[
3816,
199,
199,
504,
10380,
14,
23004,
492,
29393,
199,
504,
5055,
492,
8773,
199,
199,
504,
24756,
3351,
14,
964,
492,
8204,
199,
504,
24756,
3351,
63,
6732,
492,
28455,
421,
199,
318,
9146,
63,
3702,
8,
1095,
29,
2821,
304,
339,
1021,
3523,
7299,
8,
1095,
304,
398,
347,
636,
826,
721,
277,
12,
666,
63,
807,
29,
403,
12,
1402,
63,
842,
29,
403,
12,
1011,
958,
304,
288,
327,
6820,
7130,
626,
314,
666,
365,
2575,
282,
2018,
7448,
288,
291,
423,
3502,
63,
3527,
275,
488,
288,
291,
14,
1238,
63,
842,
275,
1402,
63,
842,
288,
291,
14,
30942,
275,
29393,
14079,
953,
340,
666,
63,
807,
26,
355,
340,
440,
1228,
8,
576,
63,
807,
12,
1211,
304,
490,
746,
1722,
480,
1451,
1471,
506,
282,
7448,
1256,
531,
355,
291,
14,
30942,
275,
29393,
8,
576,
63,
807,
9,
953,
1613,
8,
1563,
7299,
12,
291,
2843,
826,
721,
30942,
29,
277,
14,
30942,
12,
1011,
958,
9,
398,
347,
365,
63,
1078,
8,
277,
304,
288,
291,
423,
3502,
63,
3527,
275,
715,
288,
372,
1613,
8,
1563,
7299,
12,
291,
680,
3502,
342,
398,
768,
1829,
267,
347,
666,
8,
277,
304,
288,
340,
440,
291,
423,
3502,
63,
3527,
26,
355,
1499,
275,
283,
5556,
1471,
1240,
19853,
374,
63,
1078,
11995,
2544,
18549,
19853,
576,
2313,
7,
355,
746,
9070,
8,
1328,
9,
288,
372,
1613,
8,
1563,
7299,
12,
291,
680,
576,
398,
347,
4107,
8,
277,
304,
288,
746,
4279,
398,
768,
1829,
267,
347,
2552,
8,
277,
304,
288,
340,
440,
291,
423,
3502,
63,
3527,
26,
355,
1499,
275,
283,
5556,
1471,
1240,
19853,
374,
63,
1078,
11995,
2544,
18549,
19853,
2550,
2313,
7,
355,
746,
9070,
8,
1328,
9,
288,
372,
1613,
8,
1563,
7299,
12,
291,
680,
2550,
339,
372,
3523,
7299,
421,
199,
1563,
7299,
275,
9146,
63,
3702,
342,
199,
1685,
1563,
1505,
1638,
2282,
275,
9146,
63,
3702,
8,
1095,
29,
15937,
9,
421,
199,
533,
25555,
29387,
8,
466,
304,
272,
408,
272,
961,
17074,
5951,
282,
2600,
4310,
18494,
13545,
63,
955,
64,
641,
314,
1021,
14,
272,
6184,
4454,
402,
658,
792,
64,
5120,
465,
3004,
641,
1902,
314,
1021,
272,
503,
641,
1263,
402,
2399,
1613,
2888,
911,
506,
2387,
315,
314,
272,
18494,
13545,
63,
955,
64,
2600,
14,
272,
408,
339,
768,
3744,
272,
347,
485,
362,
63,
13545,
63,
955,
8,
1886,
12,
9768,
12,
3290,
304,
267,
1504,
275,
3842,
698,
63,
354,
12,
3290,
14,
1935,
8,
698,
63,
354,
430,
2116,
367,
901,
63,
354,
12,
1559,
315,
769,
8,
3288,
14,
1744,
1012,
2116,
340,
1228,
8,
1113,
12,
1211,
1874,
267,
1504,
14,
3191,
8,
498,
29,
2734,
671,
26,
671,
59,
17,
18289,
8782,
63,
5337,
9,
398,
327,
982,
642,
1021,
365,
24572,
4573,
25555,
12,
1050,
626,
25555,
1159,
267,
327,
1504,
14,
221,
3390,
626,
781,
4438,
1806,
314,
9768,
315,
627,
4471,
4856,
961,
365,
5784,
267,
327,
315,
1865,
370,
11075,
314,
3211,
1865,
402,
1504,
14,
267,
367,
1300,
315,
10822,
8,
12087,
304,
288,
340,
2688,
8,
1095,
12,
2513,
13545,
63,
955,
735,
355,
1504,
275,
769,
8,
1095,
423,
13545,
63,
955,
14,
1744,
1012,
435,
1504,
398,
372,
8773,
8,
955,
9,
339,
347,
636,
1222,
721,
1886,
12,
536,
12,
9768,
12,
3290,
304,
267,
3290,
8680,
13545,
63,
955,
418,
275,
843,
423,
362,
63,
13545,
63,
955,
8,
12087,
12,
3290,
9,
267,
372,
1613,
8,
7299,
29387,
12,
843,
2843,
1222,
721,
1886,
12,
536,
12,
9768,
12,
3290,
9,
421,
199,
533,
25555,
8,
1563,
7299,
304,
272,
986,
421,
199,
533,
5822,
7299,
8,
1685,
1563,
1505,
1638,
2282,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
devs1991/test_edx_docmode
|
venv/lib/python2.7/site-packages/git/index/fun.py
|
6
|
10630
|
# Contains standalone functions to accompany the index implementation and make it
# more versatile
# NOTE: Autodoc hates it if this is a docstring
from stat import (
S_IFDIR,
S_IFLNK,
S_ISLNK,
S_IFDIR,
S_ISDIR,
S_IFMT,
S_IFREG,
)
S_IFGITLINK = S_IFLNK | S_IFDIR # a submodule
from cStringIO import StringIO
from git.util import IndexFileSHA1Writer
from git.exc import UnmergedEntriesError
from git.objects.fun import (
tree_to_stream,
traverse_tree_recursive,
traverse_trees_recursive
)
from typ import (
BaseIndexEntry,
IndexEntry,
CE_NAMEMASK,
CE_STAGESHIFT
)
CE_NAMEMASK_INV = ~CE_NAMEMASK
from util import (
pack,
unpack
)
from gitdb.base import IStream
from gitdb.typ import str_tree_type
__all__ = ('write_cache', 'read_cache', 'write_tree_from_cache', 'entry_key',
'stat_mode_to_index_mode', 'S_IFGITLINK')
def stat_mode_to_index_mode(mode):
"""Convert the given mode from a stat call to the corresponding index mode
and return it"""
if S_ISLNK(mode): # symlinks
return S_IFLNK
if S_ISDIR(mode) or S_IFMT(mode) == S_IFGITLINK: # submodules
return S_IFGITLINK
return S_IFREG | 0644 | (mode & 0100) # blobs with or without executable bit
def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1Writer):
"""Write the cache represented by entries to a stream
:param entries: **sorted** list of entries
:param stream: stream to wrap into the AdapterStreamCls - it is used for
final output.
:param ShaStreamCls: Type to use when writing to the stream. It produces a sha
while writing to it, before the data is passed on to the wrapped stream
:param extension_data: any kind of data to write as a trailer, it must begin
a 4 byte identifier, followed by its size ( 4 bytes )"""
# wrap the stream into a compatible writer
stream = ShaStreamCls(stream)
tell = stream.tell
write = stream.write
# header
version = 2
write("DIRC")
write(pack(">LL", version, len(entries)))
# body
for entry in entries:
beginoffset = tell()
write(entry[4]) # ctime
write(entry[5]) # mtime
path = entry[3]
plen = len(path) & CE_NAMEMASK # path length
assert plen == len(path), "Path %s too long to fit into index" % entry[3]
flags = plen | (entry[2] & CE_NAMEMASK_INV) # clear possible previous values
write(pack(">LLLLLL20sH", entry[6], entry[7], entry[0],
entry[8], entry[9], entry[10], entry[1], flags))
write(path)
real_size = ((tell() - beginoffset + 8) & ~7)
write("\0" * ((beginoffset + real_size) - tell()))
# END for each entry
# write previously cached extensions data
if extension_data is not None:
stream.write(extension_data)
# write the sha over the content
stream.write_sha()
def read_header(stream):
"""Return tuple(version_long, num_entries) from the given stream"""
type_id = stream.read(4)
if type_id != "DIRC":
raise AssertionError("Invalid index file header: %r" % type_id)
version, num_entries = unpack(">LL", stream.read(4 * 2))
# TODO: handle version 3: extended data, see read-cache.c
assert version in (1, 2)
return version, num_entries
def entry_key(*entry):
""":return: Key suitable to be used for the index.entries dictionary
:param entry: One instance of type BaseIndexEntry or the path and the stage"""
if len(entry) == 1:
return (entry[0].path, entry[0].stage)
else:
return tuple(entry)
# END handle entry
def read_cache(stream):
"""Read a cache file from the given stream
:return: tuple(version, entries_dict, extension_data, content_sha)
* version is the integer version number
* entries dict is a dictionary which maps IndexEntry instances to a path
at a stage
* extension_data is '' or 4 bytes of type + 4 bytes of size + size bytes
* content_sha is a 20 byte sha on all cache file contents"""
version, num_entries = read_header(stream)
count = 0
entries = dict()
read = stream.read
tell = stream.tell
while count < num_entries:
beginoffset = tell()
ctime = unpack(">8s", read(8))[0]
mtime = unpack(">8s", read(8))[0]
(dev, ino, mode, uid, gid, size, sha, flags) = \
unpack(">LLLLLL20sH", read(20 + 4 * 6 + 2))
path_size = flags & CE_NAMEMASK
path = read(path_size)
real_size = ((tell() - beginoffset + 8) & ~7)
data = read((beginoffset + real_size) - tell())
entry = IndexEntry((mode, sha, flags, path, ctime, mtime, dev, ino, uid, gid, size))
# entry_key would be the method to use, but we safe the effort
entries[(path, entry.stage)] = entry
count += 1
# END for each entry
# the footer contains extension data and a sha on the content so far
# Keep the extension footer,and verify we have a sha in the end
# Extension data format is:
# 4 bytes ID
# 4 bytes length of chunk
# repeated 0 - N times
extension_data = stream.read(~0)
assert len(extension_data) > 19, "Index Footer was not at least a sha on content as it was only %i bytes in size" % len(extension_data)
content_sha = extension_data[-20:]
# truncate the sha in the end as we will dynamically create it anyway
extension_data = extension_data[:-20]
return (version, entries, extension_data, content_sha)
def write_tree_from_cache(entries, odb, sl, si=0):
"""Create a tree from the given sorted list of entries and put the respective
trees into the given object database
:param entries: **sorted** list of IndexEntries
:param odb: object database to store the trees in
:param si: start index at which we should start creating subtrees
:param sl: slice indicating the range we should process on the entries list
:return: tuple(binsha, list(tree_entry, ...)) a tuple of a sha and a list of
tree entries being a tuple of hexsha, mode, name"""
tree_items = list()
tree_items_append = tree_items.append
ci = sl.start
end = sl.stop
while ci < end:
entry = entries[ci]
if entry.stage != 0:
raise UnmergedEntriesError(entry)
# END abort on unmerged
ci += 1
rbound = entry.path.find('/', si)
if rbound == -1:
# its not a tree
tree_items_append((entry.binsha, entry.mode, entry.path[si:]))
else:
# find common base range
base = entry.path[si:rbound]
xi = ci
while xi < end:
oentry = entries[xi]
orbound = oentry.path.find('/', si)
if orbound == -1 or oentry.path[si:orbound] != base:
break
# END abort on base mismatch
xi += 1
# END find common base
# enter recursion
# ci - 1 as we want to count our current item as well
sha, tree_entry_list = write_tree_from_cache(entries, odb, slice(ci-1, xi), rbound+1)
tree_items_append((sha, S_IFDIR, base))
# skip ahead
ci = xi
# END handle bounds
# END for each entry
# finally create the tree
sio = StringIO()
tree_to_stream(tree_items, sio.write)
sio.seek(0)
istream = odb.store(IStream(str_tree_type, len(sio.getvalue()), sio))
return (istream.binsha, tree_items)
def _tree_entry_to_baseindexentry(tree_entry, stage):
return BaseIndexEntry((tree_entry[1], tree_entry[0], stage <<CE_STAGESHIFT, tree_entry[2]))
def aggressive_tree_merge(odb, tree_shas):
"""
:return: list of BaseIndexEntries representing the aggressive merge of the given
trees. All valid entries are on stage 0, whereas the conflicting ones are left
on stage 1, 2 or 3, whereas stage 1 corresponds to the common ancestor tree,
2 to our tree and 3 to 'their' tree.
:param tree_shas: 1, 2 or 3 trees as identified by their binary 20 byte shas
If 1 or two, the entries will effectively correspond to the last given tree
If 3 are given, a 3 way merge is performed"""
out = list()
out_append = out.append
# one and two way is the same for us, as we don't have to handle an existing
# index, instrea
if len(tree_shas) in (1,2):
for entry in traverse_tree_recursive(odb, tree_shas[-1], ''):
out_append(_tree_entry_to_baseindexentry(entry, 0))
# END for each entry
return out
# END handle single tree
if len(tree_shas) > 3:
raise ValueError("Cannot handle %i trees at once" % len(tree_shas))
# three trees
for base, ours, theirs in traverse_trees_recursive(odb, tree_shas, ''):
if base is not None:
# base version exists
if ours is not None:
# ours exists
if theirs is not None:
# it exists in all branches, if it was changed in both
# its a conflict, otherwise we take the changed version
# This should be the most common branch, so it comes first
if( base[0] != ours[0] and base[0] != theirs[0] and ours[0] != theirs[0] ) or \
( base[1] != ours[1] and base[1] != theirs[1] and ours[1] != theirs[1] ):
# changed by both
out_append(_tree_entry_to_baseindexentry(base, 1))
out_append(_tree_entry_to_baseindexentry(ours, 2))
out_append(_tree_entry_to_baseindexentry(theirs, 3))
elif base[0] != ours[0] or base[1] != ours[1]:
# only we changed it
out_append(_tree_entry_to_baseindexentry(ours, 0))
else:
# either nobody changed it, or they did. In either
# case, use theirs
out_append(_tree_entry_to_baseindexentry(theirs, 0))
# END handle modification
else:
if ours[0] != base[0] or ours[1] != base[1]:
# they deleted it, we changed it, conflict
out_append(_tree_entry_to_baseindexentry(base, 1))
out_append(_tree_entry_to_baseindexentry(ours, 2))
# else:
# we didn't change it, ignore
# pass
# END handle our change
# END handle theirs
else:
if theirs is None:
# deleted in both, its fine - its out
pass
else:
if theirs[0] != base[0] or theirs[1] != base[1]:
# deleted in ours, changed theirs, conflict
out_append(_tree_entry_to_baseindexentry(base, 1))
out_append(_tree_entry_to_baseindexentry(theirs, 3))
# END theirs changed
#else:
# theirs didnt change
# pass
# END handle theirs
# END handle ours
else:
# all three can't be None
if ours is None:
# added in their branch
out_append(_tree_entry_to_baseindexentry(theirs, 0))
elif theirs is None:
# added in our branch
out_append(_tree_entry_to_baseindexentry(ours, 0))
else:
# both have it, except for the base, see whether it changed
if ours[0] != theirs[0] or ours[1] != theirs[1]:
out_append(_tree_entry_to_baseindexentry(ours, 2))
out_append(_tree_entry_to_baseindexentry(theirs, 3))
else:
# it was added the same in both
out_append(_tree_entry_to_baseindexentry(ours, 0))
# END handle two items
# END handle heads
# END handle base exists
# END for each entries tuple
return out
|
agpl-3.0
|
[
3,
22493,
18042,
3423,
370,
21727,
314,
1478,
4514,
436,
1852,
652,
199,
3,
1655,
809,
83,
23590,
199,
3,
6944,
26,
27722,
17496,
394,
2335,
652,
340,
642,
365,
282,
9214,
199,
504,
5672,
492,
334,
1871,
198,
51,
63,
4656,
3022,
12,
1871,
198,
51,
63,
41,
3143,
22780,
12,
1871,
198,
51,
63,
1311,
44,
22780,
12,
1871,
198,
51,
63,
4656,
3022,
12,
1871,
198,
51,
63,
1311,
3022,
12,
1871,
198,
51,
63,
4656,
5747,
12,
1871,
198,
51,
63,
4656,
5616,
12,
1585,
198,
9,
199,
199,
51,
63,
4656,
20072,
7916,
275,
428,
63,
41,
3143,
22780,
1204,
428,
63,
4656,
3022,
198,
198,
3,
282,
22988,
199,
199,
504,
15073,
492,
5228,
199,
199,
504,
6135,
14,
1974,
492,
5499,
1173,
8461,
17,
6261,
199,
504,
6135,
14,
2804,
492,
1910,
15269,
17816,
547,
199,
504,
6135,
14,
1462,
14,
7036,
492,
334,
11674,
198,
2350,
63,
475,
63,
1745,
12,
11674,
198,
23650,
63,
2350,
63,
9931,
12,
11674,
198,
23650,
63,
14635,
63,
9931,
5264,
198,
9,
199,
199,
504,
6211,
492,
334,
1871,
198,
1563,
2681,
3900,
12,
1871,
198,
2681,
3900,
12,
1871,
198,
2089,
63,
2339,
12880,
12,
221,
1871,
198,
2089,
63,
840,
5383,
11183,
2161,
1585,
198,
9,
199,
2089,
63,
2339,
12880,
63,
568,
54,
275,
6146,
2089,
63,
2339,
12880,
199,
199,
504,
4884,
492,
221,
198,
8,
1871,
198,
1389,
12,
221,
1871,
198,
5301,
1871,
198,
9,
199,
199,
504,
6135,
697,
14,
1095,
492,
473,
3296,
199,
504,
6135,
697,
14,
9749,
492,
620,
63,
2350,
63,
466,
199,
199,
363,
452,
363,
275,
661,
952,
63,
1637,
297,
283,
739,
63,
1637,
297,
283,
952,
63,
2350,
63,
504,
63,
1637,
297,
283,
2373,
63,
498,
297,
20866,
198,
1159,
84,
292,
63,
632,
63,
475,
63,
1080,
63,
632,
297,
283,
51,
63,
4656,
20072,
7916,
358,
421,
199,
318,
5672,
63,
632,
63,
475,
63,
1080,
63,
632,
8,
632,
304,
199,
198,
624,
7306,
314,
1627,
818,
687,
282,
5672,
1240,
370,
314,
5226,
1478,
818,
199,
198,
460,
372,
652,
624,
199,
198,
692,
428,
63,
1311,
44,
22780,
8,
632,
304,
198,
3,
19891,
507,
198,
1107,
428,
63,
41,
3143,
22780,
199,
198,
692,
428,
63,
1311,
3022,
8,
632,
9,
503,
428,
63,
4656,
5747,
8,
632,
9,
508,
428,
63,
4656,
20072,
7916,
26,
198,
3,
29449,
507,
198,
1107,
428,
63,
4656,
20072,
7916,
199,
198,
1107,
428,
63,
4656,
5616,
1204,
378,
10893,
1204,
334,
632,
1253,
378,
1960,
9,
22427,
198,
3,
9182,
83,
543,
503,
1928,
7286,
4546,
421,
199,
318,
2218,
63,
1637,
8,
3189,
12,
2547,
12,
3329,
63,
576,
29,
403,
12,
428,
2411,
3296,
24342,
29,
2681,
1173,
8461,
17,
6261,
304,
199,
198,
624,
3534,
314,
2581,
11159,
701,
4811,
370,
282,
2547,
8299,
198,
26,
635,
4811,
26,
1011,
5917,
538,
769,
402,
4811,
199,
198,
26,
635,
2547,
26,
2547,
370,
4816,
1901,
314,
4431,
4185,
3296,
24342,
446,
652,
365,
1202,
367,
507,
198,
5094,
1072,
14,
18118,
198,
26,
635,
428,
2411,
3296,
24342,
26,
2434,
370,
675,
1380,
3575,
370,
314,
2547,
14,
2779,
16904,
282,
7793,
507,
198,
6710,
3575,
370,
652,
12,
2544,
314,
666,
365,
3032,
641,
370,
314,
8072,
2547,
18118,
198,
26,
635,
3329,
63,
576,
26,
1263,
4928,
402,
666,
370,
2218,
465,
282,
17357,
12,
652,
1471,
5386,
507,
198,
65,
841,
3696,
5148,
12,
9437,
701,
2399,
1568,
334,
841,
2783,
776,
624,
199,
198,
3,
4816,
314,
2547,
1901,
282,
9025,
7060,
199,
198,
1745,
275,
428,
2411,
3296,
24342,
8,
1745,
9,
8299,
198,
9974,
275,
2547,
14,
9974,
199,
198,
952,
275,
2547,
14,
952,
421,
198,
3,
1406,
199,
198,
1023,
275,
499,
199,
198,
952,
480,
3022,
35,
531,
199,
198,
952,
8,
1389,
19651,
4464,
401,
1015,
12,
822,
8,
3189,
1724,
421,
198,
3,
2396,
199,
198,
509,
2397,
315,
4811,
26,
507,
198,
5037,
2743,
275,
11480,
342,
507,
198,
952,
8,
2373,
59,
20,
566,
1057,
198,
3,
286,
521,
507,
198,
952,
8,
2373,
59,
21,
566,
1057,
198,
3,
15005,
507,
198,
515,
275,
2397,
59,
19,
61,
507,
198,
80,
552,
275,
822,
8,
515,
9,
1253,
19392,
63,
2339,
12880,
198,
198,
3,
931,
2582,
507,
198,
479,
299,
552,
508,
822,
8,
515,
395,
298,
2042,
450,
83,
4634,
1846,
370,
5542,
1901,
1478,
2,
450,
2397,
59,
19,
61,
507,
198,
2469,
275,
299,
552,
1204,
334,
2373,
59,
18,
61,
1253,
19392,
63,
2339,
12880,
63,
568,
54,
9,
198,
198,
3,
5436,
3962,
4136,
1338,
507,
198,
952,
8,
1389,
19651,
4464,
4464,
4464,
1165,
83,
40,
401,
2397,
59,
22,
467,
2397,
59,
23,
467,
2397,
59,
16,
467,
22680,
198,
2373,
59,
24,
467,
2397,
59,
25,
467,
2397,
59,
709,
467,
2397,
59,
17,
467,
3285,
430,
507,
198,
952,
8,
515,
9,
507,
198,
3093,
63,
890,
275,
3666,
9974,
342,
446,
5386,
2743,
435,
1695,
9,
1253,
6146,
23,
9,
507,
198,
952,
4582,
16,
2,
627,
3666,
5037,
2743,
435,
3363,
63,
890,
9,
446,
11480,
4059,
199,
198,
3,
7729,
367,
1924,
2397,
421,
198,
3,
2218,
10889,
6328,
5478,
666,
199,
198,
692,
3329,
63,
576,
365,
440,
488,
26,
507,
198,
1745,
14,
952,
8,
3435,
63,
576,
9,
421,
198,
3,
2218,
314,
7793,
1806,
314,
1564,
199,
198,
1745,
14,
952,
63,
4835,
342,
507,
199,
318,
1586,
63,
1291,
8,
1745,
304,
507,
198,
624,
1767,
2008,
8,
1023,
63,
2809,
12,
1967,
63,
3189,
9,
687,
314,
1627,
2547,
624,
507,
198,
466,
63,
344,
275,
2547,
14,
739,
8,
20,
9,
507,
198,
692,
730,
63,
344,
1137,
298,
3022,
35,
582,
686,
198,
3730,
9070,
480,
3364,
1478,
570,
1406,
26,
450,
82,
2,
450,
730,
63,
344,
9,
507,
198,
1023,
12,
1967,
63,
3189,
275,
7787,
19651,
4464,
401,
2547,
14,
739,
8,
20,
627,
499,
430,
9068,
198,
3,
3254,
26,
2429,
1015,
650,
26,
9243,
666,
12
] |
[
22493,
18042,
3423,
370,
21727,
314,
1478,
4514,
436,
1852,
652,
199,
3,
1655,
809,
83,
23590,
199,
3,
6944,
26,
27722,
17496,
394,
2335,
652,
340,
642,
365,
282,
9214,
199,
504,
5672,
492,
334,
1871,
198,
51,
63,
4656,
3022,
12,
1871,
198,
51,
63,
41,
3143,
22780,
12,
1871,
198,
51,
63,
1311,
44,
22780,
12,
1871,
198,
51,
63,
4656,
3022,
12,
1871,
198,
51,
63,
1311,
3022,
12,
1871,
198,
51,
63,
4656,
5747,
12,
1871,
198,
51,
63,
4656,
5616,
12,
1585,
198,
9,
199,
199,
51,
63,
4656,
20072,
7916,
275,
428,
63,
41,
3143,
22780,
1204,
428,
63,
4656,
3022,
198,
198,
3,
282,
22988,
199,
199,
504,
15073,
492,
5228,
199,
199,
504,
6135,
14,
1974,
492,
5499,
1173,
8461,
17,
6261,
199,
504,
6135,
14,
2804,
492,
1910,
15269,
17816,
547,
199,
504,
6135,
14,
1462,
14,
7036,
492,
334,
11674,
198,
2350,
63,
475,
63,
1745,
12,
11674,
198,
23650,
63,
2350,
63,
9931,
12,
11674,
198,
23650,
63,
14635,
63,
9931,
5264,
198,
9,
199,
199,
504,
6211,
492,
334,
1871,
198,
1563,
2681,
3900,
12,
1871,
198,
2681,
3900,
12,
1871,
198,
2089,
63,
2339,
12880,
12,
221,
1871,
198,
2089,
63,
840,
5383,
11183,
2161,
1585,
198,
9,
199,
2089,
63,
2339,
12880,
63,
568,
54,
275,
6146,
2089,
63,
2339,
12880,
199,
199,
504,
4884,
492,
221,
198,
8,
1871,
198,
1389,
12,
221,
1871,
198,
5301,
1871,
198,
9,
199,
199,
504,
6135,
697,
14,
1095,
492,
473,
3296,
199,
504,
6135,
697,
14,
9749,
492,
620,
63,
2350,
63,
466,
199,
199,
363,
452,
363,
275,
661,
952,
63,
1637,
297,
283,
739,
63,
1637,
297,
283,
952,
63,
2350,
63,
504,
63,
1637,
297,
283,
2373,
63,
498,
297,
20866,
198,
1159,
84,
292,
63,
632,
63,
475,
63,
1080,
63,
632,
297,
283,
51,
63,
4656,
20072,
7916,
358,
421,
199,
318,
5672,
63,
632,
63,
475,
63,
1080,
63,
632,
8,
632,
304,
199,
198,
624,
7306,
314,
1627,
818,
687,
282,
5672,
1240,
370,
314,
5226,
1478,
818,
199,
198,
460,
372,
652,
624,
199,
198,
692,
428,
63,
1311,
44,
22780,
8,
632,
304,
198,
3,
19891,
507,
198,
1107,
428,
63,
41,
3143,
22780,
199,
198,
692,
428,
63,
1311,
3022,
8,
632,
9,
503,
428,
63,
4656,
5747,
8,
632,
9,
508,
428,
63,
4656,
20072,
7916,
26,
198,
3,
29449,
507,
198,
1107,
428,
63,
4656,
20072,
7916,
199,
198,
1107,
428,
63,
4656,
5616,
1204,
378,
10893,
1204,
334,
632,
1253,
378,
1960,
9,
22427,
198,
3,
9182,
83,
543,
503,
1928,
7286,
4546,
421,
199,
318,
2218,
63,
1637,
8,
3189,
12,
2547,
12,
3329,
63,
576,
29,
403,
12,
428,
2411,
3296,
24342,
29,
2681,
1173,
8461,
17,
6261,
304,
199,
198,
624,
3534,
314,
2581,
11159,
701,
4811,
370,
282,
2547,
8299,
198,
26,
635,
4811,
26,
1011,
5917,
538,
769,
402,
4811,
199,
198,
26,
635,
2547,
26,
2547,
370,
4816,
1901,
314,
4431,
4185,
3296,
24342,
446,
652,
365,
1202,
367,
507,
198,
5094,
1072,
14,
18118,
198,
26,
635,
428,
2411,
3296,
24342,
26,
2434,
370,
675,
1380,
3575,
370,
314,
2547,
14,
2779,
16904,
282,
7793,
507,
198,
6710,
3575,
370,
652,
12,
2544,
314,
666,
365,
3032,
641,
370,
314,
8072,
2547,
18118,
198,
26,
635,
3329,
63,
576,
26,
1263,
4928,
402,
666,
370,
2218,
465,
282,
17357,
12,
652,
1471,
5386,
507,
198,
65,
841,
3696,
5148,
12,
9437,
701,
2399,
1568,
334,
841,
2783,
776,
624,
199,
198,
3,
4816,
314,
2547,
1901,
282,
9025,
7060,
199,
198,
1745,
275,
428,
2411,
3296,
24342,
8,
1745,
9,
8299,
198,
9974,
275,
2547,
14,
9974,
199,
198,
952,
275,
2547,
14,
952,
421,
198,
3,
1406,
199,
198,
1023,
275,
499,
199,
198,
952,
480,
3022,
35,
531,
199,
198,
952,
8,
1389,
19651,
4464,
401,
1015,
12,
822,
8,
3189,
1724,
421,
198,
3,
2396,
199,
198,
509,
2397,
315,
4811,
26,
507,
198,
5037,
2743,
275,
11480,
342,
507,
198,
952,
8,
2373,
59,
20,
566,
1057,
198,
3,
286,
521,
507,
198,
952,
8,
2373,
59,
21,
566,
1057,
198,
3,
15005,
507,
198,
515,
275,
2397,
59,
19,
61,
507,
198,
80,
552,
275,
822,
8,
515,
9,
1253,
19392,
63,
2339,
12880,
198,
198,
3,
931,
2582,
507,
198,
479,
299,
552,
508,
822,
8,
515,
395,
298,
2042,
450,
83,
4634,
1846,
370,
5542,
1901,
1478,
2,
450,
2397,
59,
19,
61,
507,
198,
2469,
275,
299,
552,
1204,
334,
2373,
59,
18,
61,
1253,
19392,
63,
2339,
12880,
63,
568,
54,
9,
198,
198,
3,
5436,
3962,
4136,
1338,
507,
198,
952,
8,
1389,
19651,
4464,
4464,
4464,
1165,
83,
40,
401,
2397,
59,
22,
467,
2397,
59,
23,
467,
2397,
59,
16,
467,
22680,
198,
2373,
59,
24,
467,
2397,
59,
25,
467,
2397,
59,
709,
467,
2397,
59,
17,
467,
3285,
430,
507,
198,
952,
8,
515,
9,
507,
198,
3093,
63,
890,
275,
3666,
9974,
342,
446,
5386,
2743,
435,
1695,
9,
1253,
6146,
23,
9,
507,
198,
952,
4582,
16,
2,
627,
3666,
5037,
2743,
435,
3363,
63,
890,
9,
446,
11480,
4059,
199,
198,
3,
7729,
367,
1924,
2397,
421,
198,
3,
2218,
10889,
6328,
5478,
666,
199,
198,
692,
3329,
63,
576,
365,
440,
488,
26,
507,
198,
1745,
14,
952,
8,
3435,
63,
576,
9,
421,
198,
3,
2218,
314,
7793,
1806,
314,
1564,
199,
198,
1745,
14,
952,
63,
4835,
342,
507,
199,
318,
1586,
63,
1291,
8,
1745,
304,
507,
198,
624,
1767,
2008,
8,
1023,
63,
2809,
12,
1967,
63,
3189,
9,
687,
314,
1627,
2547,
624,
507,
198,
466,
63,
344,
275,
2547,
14,
739,
8,
20,
9,
507,
198,
692,
730,
63,
344,
1137,
298,
3022,
35,
582,
686,
198,
3730,
9070,
480,
3364,
1478,
570,
1406,
26,
450,
82,
2,
450,
730,
63,
344,
9,
507,
198,
1023,
12,
1967,
63,
3189,
275,
7787,
19651,
4464,
401,
2547,
14,
739,
8,
20,
627,
499,
430,
9068,
198,
3,
3254,
26,
2429,
1015,
650,
26,
9243,
666,
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,
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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
] |
ldoktor/avocado-vt
|
virttest/staging/utils_memory.py
|
6
|
12938
|
from __future__ import division
import re
import math
import logging
import os
from avocado.core import exceptions
from avocado.utils import process
from virttest import kernel_interface
# Returns total memory in kb
def read_from_meminfo(key, session=None):
"""
wrapper to return value from /proc/meminfo using key
:param key: filter based on the key
:param session: ShellSession Object of remote host / guest
:return: value mapped to the key of type int
"""
func = process.getoutput
if session:
func = session.cmd_output
meminfo = func('grep %s /proc/meminfo' % key)
return int(re.search(r'\d+', meminfo).group(0))
def memtotal(session=None):
"""
Method to get the memtotal from /proc/meminfo
:param session: ShellSession Object of remote host / guest
"""
return read_from_meminfo('MemTotal', session=session)
def freememtotal(session=None):
"""
Method to get the freememtotal from /proc/meminfo
:param session: ShellSession Object of remote host / guest
"""
return read_from_meminfo('MemFree', session=session)
def rounded_memtotal(session=None):
"""
Method to get total of all physical mem, in kbytes
:param session: ShellSession Object of remote host / guest
"""
usable_kbytes = memtotal(session=session)
# usable_kbytes is system's usable DRAM in kbytes,
# as reported by memtotal() from device /proc/meminfo memtotal
# after Linux deducts 1.5% to 5.1% for system table overhead
# Undo the unknown actual deduction by rounding up
# to next small multiple of a big power-of-two
# eg 12GB - 5.1% gets rounded back up to 12GB
mindeduct = 0.015 # 1.5 percent
maxdeduct = 0.055 # 5.5 percent
# deduction range 1.5% .. 5.5% supports physical mem sizes
# 6GB .. 12GB in steps of .5GB
# 12GB .. 24GB in steps of 1 GB
# 24GB .. 48GB in steps of 2 GB ...
# Finer granularity in physical mem sizes would require
# tighter spread between min and max possible deductions
# increase mem size by at least min deduction, without rounding
min_kbytes = int(usable_kbytes / (1.0 - mindeduct))
# increase mem size further by 2**n rounding, by 0..roundKb or more
round_kbytes = int(usable_kbytes / (1.0 - maxdeduct)) - min_kbytes
# find least binary roundup 2**n that covers worst-cast roundKb
mod2n = 1 << int(math.ceil(math.log(round_kbytes, 2)))
# have round_kbytes <= mod2n < round_kbytes*2
# round min_kbytes up to next multiple of mod2n
phys_kbytes = min_kbytes + mod2n - 1
phys_kbytes = phys_kbytes - (phys_kbytes % mod2n) # clear low bits
return phys_kbytes
def numa_nodes(session=None):
"""
Method to get total no of numa nodes
:param session: ShellSession Object of remote host / guest
"""
func = process.getoutput
if session:
func = session.cmd_output
base_path = "/sys/devices/system/node"
node_avail = func("ls %s | grep 'node'" % base_path).split()
node_paths = [os.path.join(base_path, each_node) for each_node in node_avail]
nodes = [int(re.sub(r'.*node(\d+)', r'\1', x)) for x in node_paths]
return (sorted(nodes))
def node_size(session=None):
"""
Method to get node size
:param session: ShellSession Object of remote host / guest
"""
nodes = max(len(numa_nodes(session=session)), 1)
return ((memtotal() * 1024) // nodes)
def get_huge_page_size(session=None):
"""
Method to get huge page size
:param session: ShellSession Object of remote host / guest
"""
return read_from_meminfo('Hugepagesize', session=session)
def get_num_huge_pages(session=None):
"""
Method to get total no of hugepages
:param session: ShellSession Object of remote host / guest
"""
return read_from_meminfo('HugePages_Total', session=session)
def get_num_huge_pages_free(session=None):
"""
Method to get free hugepages available
:param session: ShellSession Object of remote host / guest
"""
return read_from_meminfo('HugePages_Free', session=session)
def get_num_huge_pages_rsvd(session=None):
"""
Method to get reserved hugepage pages
:param session: ShellSession Object of remote host / guest
"""
return read_from_meminfo('HugePages_Rsvd', session=session)
def get_num_huge_pages_surp(session=None):
"""
Method to get surplus hugepage pages
:param session: ShellSession Object of remote host / guest
"""
return read_from_meminfo('HugePages_Surp', session=session)
def get_num_anon_huge_pages(pid=0, session=None):
"""
Method to get total no of anon hugepages
:param pid: pid of the specific process
:param session: ShellSession Object of remote host / guest
"""
if int(pid) > 1:
# get AnonHugePages usage of specified process
return read_from_smaps(pid, 'AnonHugePages', session=session)
else:
# invalid pid, so return AnonHugePages of the host
return read_from_meminfo('AnonHugePages', session=session)
def get_transparent_hugepage(session=None, regex="[]"):
"""
Method to get total no of transparent hugepage
:param regex: regex used to hightlight the selected value
:param session: ShellSession Object of remote host / guest
"""
UPSTREAM_THP_PATH = "/sys/kernel/mm/transparent_hugepage"
RH_THP_PATH = "/sys/kernel/mm/redhat_transparent_hugepage"
if os.path.isdir(UPSTREAM_THP_PATH):
thp_path = UPSTREAM_THP_PATH
elif os.path.isdir(RH_THP_PATH):
thp_path = RH_THP_PATH
else:
raise exceptions.TestFail("transparent hugepage Not supported")
thp = kernel_interface.SysFS(os.path.join(thp_path, 'enabled'),
session=session)
return thp.sys_fs_value.strip(regex)
def set_num_huge_pages(num, session=None):
"""
Method to set no of transparent hugepages
:param num: value to be set for THP
:param session: ShellSession Object of remote host / guest
"""
func = process.system
if session:
func = session.cmd_status
return func('/sbin/sysctl vm.nr_hugepages=%d' % num) == 0
def set_transparent_hugepage(sflag, session=None):
"""
Method to set THP parameter
:param sflag: only can be set always, madvise or never.
:param session: ShellSession Object of remote host / guest
"""
flags = ['always', 'madvise', 'never']
if sflag not in flags:
raise exceptions.TestFail("specify wrong parameter")
UPSTREAM_THP_PATH = "/sys/kernel/mm/transparent_hugepage"
RH_THP_PATH = "/sys/kernel/mm/redhat_transparent_hugepage"
if os.path.isdir(UPSTREAM_THP_PATH):
thp_path = UPSTREAM_THP_PATH
elif os.path.isdir(RH_THP_PATH):
thp_path = RH_THP_PATH
else:
raise exceptions.TestFail("transparent hugepage Not supported")
thp = kernel_interface.SysFS(os.path.join(thp_path, 'enabled'),
session=session)
thp.sys_fs_value = sflag
if sflag not in thp.sys_fs_value:
raise exceptions.TestFail("setting transparent_hugepage failed")
def drop_caches(session=None):
"""
Method to write back all dirty pages to disk and clears all the caches
:param session: ShellSession Object of remote host / guest
"""
func = process.getoutput
if session:
func = session.cmd_output
func("sync")
# We ignore failures here as this will fail on 2.6.11 kernels.
drop_caches = kernel_interface.ProcFS("/proc/sys/vm/drop_caches",
session=session)
drop_caches.proc_fs_value = 3
def read_from_vmstat(key, session=None):
"""
Get specific item value from vmstat
:param key: The item you want to check from vmstat
:type key: String
:param session: ShellSession Object of remote host / guest
:return: The value of the item
:rtype: int
"""
func = process.getoutput
if session:
func = session.cmd_output
vmstat_info = func("cat /proc/vmstat")
return int(re.findall("%s\s+(\d+)" % key, vmstat_info)[0])
def read_from_smaps(pid, key, session=None):
"""
Get specific item value from the smaps of a process include all sections.
:param pid: Process id
:type pid: String
:param key: The item you want to check from smaps
:type key: String
:param session: ShellSession Object of remote host / guest
:return: The value of the item in kb
:rtype: int
"""
func = process.getoutput
if session:
func = session.cmd_output
smaps_info = func('grep %s /proc/%s/smaps' % (key, pid))
memory_size = 0
for each_number in re.findall("%s:\s+(\d+)" % key, smaps_info):
memory_size += int(each_number)
return memory_size
def read_from_numastat(pid, key, session=None):
"""
Get the process numastat from numastat output.
:param pid: pid of the specific process
:param key: filter based on the key
:param session: ShellSession Object of remote host / guest
"""
func = process.getoutput
if session:
func = session.cmd_output
cmd = "numastat %s" % pid
numa_mem = func(cmd).strip()
mem_line = re.findall(r"^%s.*" % key, numa_mem, re.M)[0]
return re.findall(r"(\d+.\d+)", mem_line)
def read_from_numa_maps(pid, key, session=None):
"""
Get the process numa related info from numa_maps. This function
only use to get the numbers like anon=1.
:param pid: Process id
:type pid: String
:param key: The item you want to check from numa_maps
:type key: String
:param session: ShellSession Object of remote host / guest
:return: A dict using the address as the keys
:rtype: dict
"""
func = process.getoutput
if session:
func = session.cmd_output
numa_map_info = func("cat /proc/%s/numa_maps" % pid)
numa_maps_dict = {}
numa_pattern = r"(^[\dabcdfe]+)\s+.*%s[=:](\d+)" % key
for address, number in re.findall(numa_pattern, numa_map_info, re.M):
numa_maps_dict[address] = number
return numa_maps_dict
def get_buddy_info(chunk_sizes, nodes="all", zones="all", session=None):
"""
Get the fragement status of the host. It use the same method
to get the page size in buddyinfo.
2^chunk_size * page_size
The chunk_sizes can be string make up by all orders that you want to check
splited with blank or a mathematical expression with '>', '<' or '='.
For example:
The input of chunk_size could be: "0 2 4"
And the return will be: {'0': 3, '2': 286, '4': 687}
if you are using expression: ">=9"
the return will be: {'9': 63, '10': 225}
:param chunk_size: The order number shows in buddyinfo. This is not
the real page size.
:type chunk_size: string
:param nodes: The numa node that you want to check. Default value is all
:type nodes: string
:param zones: The memory zone that you want to check. Default value is all
:type zones: string
:param session: ShellSession Object of remote host / guest
:return: A dict using the chunk_size as the keys
:rtype: dict
"""
func = process.getoutput
if session:
func = session.cmd_output
buddy_info_content = func("cat /proc/buddyinfo")
re_buddyinfo = "Node\s+"
if nodes == "all":
re_buddyinfo += "(\d+)"
else:
re_buddyinfo += "(%s)" % "|".join(nodes.split())
if not re.findall(re_buddyinfo, buddy_info_content):
logging.warn("Can not find Nodes %s" % nodes)
return None
re_buddyinfo += ".*?zone\s+"
if zones == "all":
re_buddyinfo += "(\w+)"
else:
re_buddyinfo += "(%s)" % "|".join(zones.split())
if not re.findall(re_buddyinfo, buddy_info_content):
logging.warn("Can not find zones %s" % zones)
return None
re_buddyinfo += "\s+([\s\d]+)"
buddy_list = re.findall(re_buddyinfo, buddy_info_content)
if re.findall("[<>=]", chunk_sizes) and buddy_list:
size_list = list(range(len(buddy_list[-1][-1].strip().split())))
chunk_sizes = [str(_) for _ in size_list if eval("%s %s" % (_,
chunk_sizes))]
chunk_sizes = ' '.join(chunk_sizes)
buddyinfo_dict = {}
for chunk_size in chunk_sizes.split():
buddyinfo_dict[chunk_size] = 0
for _, _, chunk_info in buddy_list:
chunk_info = chunk_info.strip().split()[int(chunk_size)]
buddyinfo_dict[chunk_size] += int(chunk_info)
return buddyinfo_dict
def getpagesize(session=None):
"""
Get system page size
:param session: ShellSession Object of VM/remote host
:return: pagesize in kB
"""
func = process.getoutput
if session:
func = session.cmd_output
return int(func('getconf PAGE_SIZE')) // 1024
|
gpl-2.0
|
[
504,
636,
2443,
363,
492,
4629,
199,
646,
295,
199,
646,
3473,
199,
646,
2050,
199,
646,
747,
199,
199,
504,
2289,
679,
5129,
14,
1018,
492,
4967,
199,
504,
2289,
679,
5129,
14,
1208,
492,
2112,
199,
199,
504,
12043,
396,
492,
5114,
63,
3266,
421,
199,
3,
1803,
3141,
4402,
315,
19932,
199,
318,
1586,
63,
504,
63,
5286,
815,
8,
498,
12,
2351,
29,
403,
304,
272,
408,
272,
4975,
370,
372,
574,
687,
1182,
4687,
15,
5286,
815,
1808,
790,
339,
520,
635,
790,
26,
2457,
4079,
641,
314,
790,
272,
520,
635,
2351,
26,
24599,
4434,
6935,
402,
3982,
1591,
1182,
13980,
272,
520,
1107,
26,
574,
9994,
370,
314,
790,
402,
730,
1109,
272,
408,
272,
2562,
275,
2112,
14,
362,
1199,
272,
340,
2351,
26,
267,
2562,
275,
2351,
14,
1760,
63,
1199,
272,
7573,
815,
275,
2562,
360,
25914,
450,
83,
1182,
4687,
15,
5286,
815,
7,
450,
790,
9,
272,
372,
1109,
8,
264,
14,
1733,
8,
82,
1154,
68,
7386,
7573,
815,
680,
923,
8,
16,
430,
421,
199,
318,
562,
2037,
1735,
8,
1730,
29,
403,
304,
272,
408,
272,
9075,
370,
664,
314,
562,
2037,
1735,
687,
1182,
4687,
15,
5286,
815,
339,
520,
635,
2351,
26,
24599,
4434,
6935,
402,
3982,
1591,
1182,
13980,
272,
408,
272,
372,
1586,
63,
504,
63,
5286,
815,
360,
14169,
7316,
297,
2351,
29,
1730,
9,
421,
199,
318,
2867,
278,
2037,
1735,
8,
1730,
29,
403,
304,
272,
408,
272,
9075,
370,
664,
314,
2867,
278,
2037,
1735,
687,
1182,
4687,
15,
5286,
815,
339,
520,
635,
2351,
26,
24599,
4434,
6935,
402,
3982,
1591,
1182,
13980,
272,
408,
272,
372,
1586,
63,
504,
63,
5286,
815,
360,
14169,
10146,
297,
2351,
29,
1730,
9,
421,
199,
318,
24671,
63,
278,
2037,
1735,
8,
1730,
29,
403,
304,
272,
408,
272,
9075,
370,
664,
3141,
402,
1006,
14095,
7573,
12,
315,
1022,
2394,
339,
520,
635,
2351,
26,
24599,
4434,
6935,
402,
3982,
1591,
1182,
13980,
272,
408,
272,
18025,
63,
75,
2394,
275,
562,
2037,
1735,
8,
1730,
29,
1730,
9,
272,
327,
18025,
63,
75,
2394,
365,
2656,
1159,
18025,
577,
30839,
315,
1022,
2394,
12,
272,
327,
257,
465,
14581,
701,
562,
2037,
1735,
342,
687,
2243,
1182,
4687,
15,
5286,
815,
562,
2037,
1735,
272,
327,
257,
2410,
10130,
477,
1601,
83,
413,
14,
21,
5,
370,
959,
14,
17,
5,
367,
2656,
1817,
24075,
272,
327,
738,
21175,
314,
5809,
3503,
477,
5199,
701,
18100,
1536,
272,
327,
257,
370,
2163,
7425,
3663,
402,
282,
7282,
7074,
13,
1618,
13,
5601,
272,
327,
257,
11837,
221,
3144,
6487,
446,
959,
14,
17,
5,
7545,
24671,
1771,
1536,
370,
3144,
6487,
272,
1748,
770,
918,
275,
378,
14,
11164,
221,
327,
413,
14,
21,
8878,
272,
1390,
770,
918,
275,
378,
14,
16458,
221,
327,
959,
14,
21,
8878,
272,
327,
477,
5199,
1425,
413,
14,
21,
5,
2508,
959,
14,
21,
5,
5171,
14095,
7573,
10627,
272,
327,
259,
1227,
6487,
2508,
3144,
6487,
315,
7124,
402,
1275,
21,
6487,
272,
327,
257,
3144,
6487,
2508,
5504,
6487,
315,
7124,
402,
413,
18553,
272,
327,
257,
5504,
6487,
2508,
9615,
6487,
315,
7124,
402,
499,
18553,
2263,
272,
327,
11711,
281,
9202,
22504,
315,
14095,
7573,
10627,
3955,
4409,
272,
327,
257,
3367,
3561,
351,
308,
8984,
3382,
1748,
436,
1390,
3962,
477,
18311,
339,
327,
19781,
7573,
1568,
701,
737,
5210,
1748,
477,
5199,
12,
1928,
18100,
272,
1748,
63,
75,
2394,
275,
1109,
8,
14418,
63,
75,
2394,
1182,
334,
17,
14,
16,
446,
1748,
770,
918,
430,
272,
327,
19781,
7573,
1568,
9848,
701,
499,
538,
78,
18100,
12,
701,
378,
703,
2363,
43,
66,
503,
1655,
272,
6168,
63,
75,
2394,
275,
1109,
8,
14418,
63,
75,
2394,
1182,
334,
17,
14,
16,
446,
1390,
770,
918,
430,
446,
1748,
63,
75,
2394,
272,
327,
2342,
5210,
3366,
6168,
384,
499,
538,
78,
626,
25858,
1319,
270,
13,
2931,
6168,
43,
66,
272,
3413,
18,
78,
275,
413,
5213,
1109,
8,
3442,
14,
14085,
8,
3442,
14,
793,
8,
2363,
63,
75,
2394,
12,
499,
1724,
272,
327,
1172,
6168,
63,
75,
2394,
2695,
3413,
18,
78,
665,
6168,
63,
75,
2394,
10,
18,
272,
327,
6168,
1748,
63,
75,
2394,
1536,
370,
2163,
3663,
402,
3413,
18,
78,
272,
3945,
588,
63,
75,
2394,
275,
1748,
63,
75,
2394,
435,
3413,
18,
78,
446,
413,
272,
3945,
588,
63,
75,
2394,
275,
3945,
588,
63,
75,
2394,
446,
334,
26827,
63,
75,
2394,
450,
3413,
18,
78,
9,
221,
327,
5436,
6465,
5821,
272,
372,
3945,
588,
63,
75,
2394,
421,
199,
318,
15699,
391,
63,
2415,
8,
1730,
29,
403,
304,
272,
408,
272,
9075,
370,
664,
3141,
949,
402,
15699,
391,
3380,
339,
520,
635,
2351,
26,
24599,
4434,
6935,
402,
3982,
1591,
1182,
13980,
272,
408,
272,
2562,
275,
2112,
14,
362,
1199,
272,
340,
2351,
26,
267,
2562,
275,
2351,
14,
1760,
63,
1199,
272,
1300,
63,
515,
275,
3286,
1274,
15,
6410,
15,
2253,
15,
932,
2,
272,
1031,
63,
18961,
275,
2562,
480,
478,
450,
83,
1204,
20595,
283,
932,
4065,
450,
1300,
63,
515,
680,
1294,
342,
272,
1031,
63,
3771,
275,
359,
736,
14,
515,
14,
904,
8,
1095,
63,
515,
12,
1924,
63,
932,
9,
367,
1924,
63,
932,
315,
1031,
63,
18961,
61,
272,
3380,
275,
359,
442,
8,
264,
14,
954,
8,
82,
24898,
932,
2961,
68,
14705,
519,
1154,
17,
297,
671,
430,
367,
671,
315,
1031,
63,
3771,
61,
272,
372,
334,
5917,
8,
2415,
430,
421,
199,
318,
1031,
63,
890,
8,
1730,
29,
403,
304,
272,
408,
272,
9075,
370,
664,
1031,
1568,
339,
520,
635,
2351,
26,
24599,
4434,
6935,
402,
3982,
1591,
1182,
13980,
272,
408,
272,
3380,
275,
1390,
8,
552,
8,
19498,
63,
2415,
8,
1730,
29,
1730,
1826,
413,
9,
272,
372,
3666,
278,
2037,
1735,
342,
627,
6619,
9,
5001,
3380,
9,
421,
199,
318,
664,
63,
29947,
63,
1606,
63,
890,
8,
1730,
29,
403,
304,
272,
408,
272,
9075,
370,
664
] |
[
636,
2443,
363,
492,
4629,
199,
646,
295,
199,
646,
3473,
199,
646,
2050,
199,
646,
747,
199,
199,
504,
2289,
679,
5129,
14,
1018,
492,
4967,
199,
504,
2289,
679,
5129,
14,
1208,
492,
2112,
199,
199,
504,
12043,
396,
492,
5114,
63,
3266,
421,
199,
3,
1803,
3141,
4402,
315,
19932,
199,
318,
1586,
63,
504,
63,
5286,
815,
8,
498,
12,
2351,
29,
403,
304,
272,
408,
272,
4975,
370,
372,
574,
687,
1182,
4687,
15,
5286,
815,
1808,
790,
339,
520,
635,
790,
26,
2457,
4079,
641,
314,
790,
272,
520,
635,
2351,
26,
24599,
4434,
6935,
402,
3982,
1591,
1182,
13980,
272,
520,
1107,
26,
574,
9994,
370,
314,
790,
402,
730,
1109,
272,
408,
272,
2562,
275,
2112,
14,
362,
1199,
272,
340,
2351,
26,
267,
2562,
275,
2351,
14,
1760,
63,
1199,
272,
7573,
815,
275,
2562,
360,
25914,
450,
83,
1182,
4687,
15,
5286,
815,
7,
450,
790,
9,
272,
372,
1109,
8,
264,
14,
1733,
8,
82,
1154,
68,
7386,
7573,
815,
680,
923,
8,
16,
430,
421,
199,
318,
562,
2037,
1735,
8,
1730,
29,
403,
304,
272,
408,
272,
9075,
370,
664,
314,
562,
2037,
1735,
687,
1182,
4687,
15,
5286,
815,
339,
520,
635,
2351,
26,
24599,
4434,
6935,
402,
3982,
1591,
1182,
13980,
272,
408,
272,
372,
1586,
63,
504,
63,
5286,
815,
360,
14169,
7316,
297,
2351,
29,
1730,
9,
421,
199,
318,
2867,
278,
2037,
1735,
8,
1730,
29,
403,
304,
272,
408,
272,
9075,
370,
664,
314,
2867,
278,
2037,
1735,
687,
1182,
4687,
15,
5286,
815,
339,
520,
635,
2351,
26,
24599,
4434,
6935,
402,
3982,
1591,
1182,
13980,
272,
408,
272,
372,
1586,
63,
504,
63,
5286,
815,
360,
14169,
10146,
297,
2351,
29,
1730,
9,
421,
199,
318,
24671,
63,
278,
2037,
1735,
8,
1730,
29,
403,
304,
272,
408,
272,
9075,
370,
664,
3141,
402,
1006,
14095,
7573,
12,
315,
1022,
2394,
339,
520,
635,
2351,
26,
24599,
4434,
6935,
402,
3982,
1591,
1182,
13980,
272,
408,
272,
18025,
63,
75,
2394,
275,
562,
2037,
1735,
8,
1730,
29,
1730,
9,
272,
327,
18025,
63,
75,
2394,
365,
2656,
1159,
18025,
577,
30839,
315,
1022,
2394,
12,
272,
327,
257,
465,
14581,
701,
562,
2037,
1735,
342,
687,
2243,
1182,
4687,
15,
5286,
815,
562,
2037,
1735,
272,
327,
257,
2410,
10130,
477,
1601,
83,
413,
14,
21,
5,
370,
959,
14,
17,
5,
367,
2656,
1817,
24075,
272,
327,
738,
21175,
314,
5809,
3503,
477,
5199,
701,
18100,
1536,
272,
327,
257,
370,
2163,
7425,
3663,
402,
282,
7282,
7074,
13,
1618,
13,
5601,
272,
327,
257,
11837,
221,
3144,
6487,
446,
959,
14,
17,
5,
7545,
24671,
1771,
1536,
370,
3144,
6487,
272,
1748,
770,
918,
275,
378,
14,
11164,
221,
327,
413,
14,
21,
8878,
272,
1390,
770,
918,
275,
378,
14,
16458,
221,
327,
959,
14,
21,
8878,
272,
327,
477,
5199,
1425,
413,
14,
21,
5,
2508,
959,
14,
21,
5,
5171,
14095,
7573,
10627,
272,
327,
259,
1227,
6487,
2508,
3144,
6487,
315,
7124,
402,
1275,
21,
6487,
272,
327,
257,
3144,
6487,
2508,
5504,
6487,
315,
7124,
402,
413,
18553,
272,
327,
257,
5504,
6487,
2508,
9615,
6487,
315,
7124,
402,
499,
18553,
2263,
272,
327,
11711,
281,
9202,
22504,
315,
14095,
7573,
10627,
3955,
4409,
272,
327,
257,
3367,
3561,
351,
308,
8984,
3382,
1748,
436,
1390,
3962,
477,
18311,
339,
327,
19781,
7573,
1568,
701,
737,
5210,
1748,
477,
5199,
12,
1928,
18100,
272,
1748,
63,
75,
2394,
275,
1109,
8,
14418,
63,
75,
2394,
1182,
334,
17,
14,
16,
446,
1748,
770,
918,
430,
272,
327,
19781,
7573,
1568,
9848,
701,
499,
538,
78,
18100,
12,
701,
378,
703,
2363,
43,
66,
503,
1655,
272,
6168,
63,
75,
2394,
275,
1109,
8,
14418,
63,
75,
2394,
1182,
334,
17,
14,
16,
446,
1390,
770,
918,
430,
446,
1748,
63,
75,
2394,
272,
327,
2342,
5210,
3366,
6168,
384,
499,
538,
78,
626,
25858,
1319,
270,
13,
2931,
6168,
43,
66,
272,
3413,
18,
78,
275,
413,
5213,
1109,
8,
3442,
14,
14085,
8,
3442,
14,
793,
8,
2363,
63,
75,
2394,
12,
499,
1724,
272,
327,
1172,
6168,
63,
75,
2394,
2695,
3413,
18,
78,
665,
6168,
63,
75,
2394,
10,
18,
272,
327,
6168,
1748,
63,
75,
2394,
1536,
370,
2163,
3663,
402,
3413,
18,
78,
272,
3945,
588,
63,
75,
2394,
275,
1748,
63,
75,
2394,
435,
3413,
18,
78,
446,
413,
272,
3945,
588,
63,
75,
2394,
275,
3945,
588,
63,
75,
2394,
446,
334,
26827,
63,
75,
2394,
450,
3413,
18,
78,
9,
221,
327,
5436,
6465,
5821,
272,
372,
3945,
588,
63,
75,
2394,
421,
199,
318,
15699,
391,
63,
2415,
8,
1730,
29,
403,
304,
272,
408,
272,
9075,
370,
664,
3141,
949,
402,
15699,
391,
3380,
339,
520,
635,
2351,
26,
24599,
4434,
6935,
402,
3982,
1591,
1182,
13980,
272,
408,
272,
2562,
275,
2112,
14,
362,
1199,
272,
340,
2351,
26,
267,
2562,
275,
2351,
14,
1760,
63,
1199,
272,
1300,
63,
515,
275,
3286,
1274,
15,
6410,
15,
2253,
15,
932,
2,
272,
1031,
63,
18961,
275,
2562,
480,
478,
450,
83,
1204,
20595,
283,
932,
4065,
450,
1300,
63,
515,
680,
1294,
342,
272,
1031,
63,
3771,
275,
359,
736,
14,
515,
14,
904,
8,
1095,
63,
515,
12,
1924,
63,
932,
9,
367,
1924,
63,
932,
315,
1031,
63,
18961,
61,
272,
3380,
275,
359,
442,
8,
264,
14,
954,
8,
82,
24898,
932,
2961,
68,
14705,
519,
1154,
17,
297,
671,
430,
367,
671,
315,
1031,
63,
3771,
61,
272,
372,
334,
5917,
8,
2415,
430,
421,
199,
318,
1031,
63,
890,
8,
1730,
29,
403,
304,
272,
408,
272,
9075,
370,
664,
1031,
1568,
339,
520,
635,
2351,
26,
24599,
4434,
6935,
402,
3982,
1591,
1182,
13980,
272,
408,
272,
3380,
275,
1390,
8,
552,
8,
19498,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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
] |
Jandersolutions/jander777-ghost
|
node_modules/grunt-docker/node_modules/docker/node_modules/pygmentize-bundled/vendor/pygments/build-3.3/pygments/lexers/other.py
|
94
|
170941
|
# -*- coding: utf-8 -*-
"""
pygments.lexers.other
~~~~~~~~~~~~~~~~~~~~~
Lexers for other languages.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
from pygments.lexer import RegexLexer, include, bygroups, using, \
this, combined, ExtendedRegexLexer
from pygments.token import Error, Punctuation, Literal, Token, \
Text, Comment, Operator, Keyword, Name, String, Number, Generic, \
Whitespace
from pygments.util import get_bool_opt
from pygments.lexers.web import HtmlLexer
from pygments.lexers._openedgebuiltins import OPENEDGEKEYWORDS
from pygments.lexers._robotframeworklexer import RobotFrameworkLexer
# backwards compatibility
from pygments.lexers.sql import SqlLexer, MySqlLexer, SqliteConsoleLexer
from pygments.lexers.shell import BashLexer, BashSessionLexer, BatchLexer, \
TcshLexer
__all__ = ['BrainfuckLexer', 'BefungeLexer', 'RedcodeLexer', 'MOOCodeLexer',
'SmalltalkLexer', 'LogtalkLexer', 'GnuplotLexer', 'PovrayLexer',
'AppleScriptLexer', 'ModelicaLexer', 'RebolLexer', 'ABAPLexer',
'NewspeakLexer', 'GherkinLexer', 'AsymptoteLexer', 'PostScriptLexer',
'AutohotkeyLexer', 'GoodDataCLLexer', 'MaqlLexer', 'ProtoBufLexer',
'HybrisLexer', 'AwkLexer', 'Cfengine3Lexer', 'SnobolLexer',
'ECLLexer', 'UrbiscriptLexer', 'OpenEdgeLexer', 'BroLexer',
'MscgenLexer', 'KconfigLexer', 'VGLLexer', 'SourcePawnLexer',
'RobotFrameworkLexer', 'PuppetLexer', 'NSISLexer', 'RPMSpecLexer',
'CbmBasicV2Lexer', 'AutoItLexer', 'RexxLexer']
class ECLLexer(RegexLexer):
"""
Lexer for the declarative big-data `ECL
<http://hpccsystems.com/community/docs/ecl-language-reference/html>`_
language.
*New in Pygments 1.5.*
"""
name = 'ECL'
aliases = ['ecl']
filenames = ['*.ecl']
mimetypes = ['application/x-ecl']
flags = re.IGNORECASE | re.MULTILINE
tokens = {
'root': [
include('whitespace'),
include('statements'),
],
'whitespace': [
(r'\s+', Text),
(r'\/\/.*', Comment.Single),
(r'/(\\\n)?\*(.|\n)*?\*(\\\n)?/', Comment.Multiline),
],
'statements': [
include('types'),
include('keywords'),
include('functions'),
include('hash'),
(r'"', String, 'string'),
(r'\'', String, 'string'),
(r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*', Number.Float),
(r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
(r'0x[0-9a-fA-F]+[LlUu]*', Number.Hex),
(r'0[0-7]+[LlUu]*', Number.Oct),
(r'\d+[LlUu]*', Number.Integer),
(r'\*/', Error),
(r'[~!%^&*+=|?:<>/-]+', Operator),
(r'[{}()\[\],.;]', Punctuation),
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
],
'hash': [
(r'^#.*$', Comment.Preproc),
],
'types': [
(r'(RECORD|END)\D', Keyword.Declaration),
(r'((?:ASCII|BIG_ENDIAN|BOOLEAN|DATA|DECIMAL|EBCDIC|INTEGER|PATTERN|'
r'QSTRING|REAL|RECORD|RULE|SET OF|STRING|TOKEN|UDECIMAL|UNICODE|'
r'UNSIGNED|VARSTRING|VARUNICODE)\d*)(\s+)',
bygroups(Keyword.Type, Text)),
],
'keywords': [
(r'(APPLY|ASSERT|BUILD|BUILDINDEX|EVALUATE|FAIL|KEYDIFF|KEYPATCH|'
r'LOADXML|NOTHOR|NOTIFY|OUTPUT|PARALLEL|SEQUENTIAL|SOAPCALL|WAIT'
r'CHECKPOINT|DEPRECATED|FAILCODE|FAILMESSAGE|FAILURE|GLOBAL|'
r'INDEPENDENT|ONWARNING|PERSIST|PRIORITY|RECOVERY|STORED|SUCCESS|'
r'WAIT|WHEN)\b', Keyword.Reserved),
# These are classed differently, check later
(r'(ALL|AND|ANY|AS|ATMOST|BEFORE|BEGINC\+\+|BEST|BETWEEN|CASE|CONST|'
r'COUNTER|CSV|DESCEND|ENCRYPT|ENDC\+\+|ENDMACRO|EXCEPT|EXCLUSIVE|'
r'EXPIRE|EXPORT|EXTEND|FALSE|FEW|FIRST|FLAT|FULL|FUNCTION|GROUP|'
r'HEADER|HEADING|HOLE|IFBLOCK|IMPORT|IN|JOINED|KEEP|KEYED|LAST|'
r'LEFT|LIMIT|LOAD|LOCAL|LOCALE|LOOKUP|MACRO|MANY|MAXCOUNT|'
r'MAXLENGTH|MIN SKEW|MODULE|INTERFACE|NAMED|NOCASE|NOROOT|NOSCAN|'
r'NOSORT|NOT|OF|ONLY|OPT|OR|OUTER|OVERWRITE|PACKED|PARTITION|'
r'PENALTY|PHYSICALLENGTH|PIPE|QUOTE|RELATIONSHIP|REPEAT|RETURN|'
r'RIGHT|SCAN|SELF|SEPARATOR|SERVICE|SHARED|SKEW|SKIP|SQL|STORE|'
r'TERMINATOR|THOR|THRESHOLD|TOKEN|TRANSFORM|TRIM|TRUE|TYPE|'
r'UNICODEORDER|UNSORTED|VALIDATE|VIRTUAL|WHOLE|WILD|WITHIN|XML|'
r'XPATH|__COMPRESSED__)\b', Keyword.Reserved),
],
'functions': [
(r'(ABS|ACOS|ALLNODES|ASCII|ASIN|ASSTRING|ATAN|ATAN2|AVE|CASE|'
r'CHOOSE|CHOOSEN|CHOOSESETS|CLUSTERSIZE|COMBINE|CORRELATION|COS|'
r'COSH|COUNT|COVARIANCE|CRON|DATASET|DEDUP|DEFINE|DENORMALIZE|'
r'DISTRIBUTE|DISTRIBUTED|DISTRIBUTION|EBCDIC|ENTH|ERROR|EVALUATE|'
r'EVENT|EVENTEXTRA|EVENTNAME|EXISTS|EXP|FAILCODE|FAILMESSAGE|'
r'FETCH|FROMUNICODE|GETISVALID|GLOBAL|GRAPH|GROUP|HASH|HASH32|'
r'HASH64|HASHCRC|HASHMD5|HAVING|IF|INDEX|INTFORMAT|ISVALID|'
r'ITERATE|JOIN|KEYUNICODE|LENGTH|LIBRARY|LIMIT|LN|LOCAL|LOG|LOOP|'
r'MAP|MATCHED|MATCHLENGTH|MATCHPOSITION|MATCHTEXT|MATCHUNICODE|'
r'MAX|MERGE|MERGEJOIN|MIN|NOLOCAL|NONEMPTY|NORMALIZE|PARSE|PIPE|'
r'POWER|PRELOAD|PROCESS|PROJECT|PULL|RANDOM|RANGE|RANK|RANKED|'
r'REALFORMAT|RECORDOF|REGEXFIND|REGEXREPLACE|REGROUP|REJECTED|'
r'ROLLUP|ROUND|ROUNDUP|ROW|ROWDIFF|SAMPLE|SET|SIN|SINH|SIZEOF|'
r'SOAPCALL|SORT|SORTED|SQRT|STEPPED|STORED|SUM|TABLE|TAN|TANH|'
r'THISNODE|TOPN|TOUNICODE|TRANSFER|TRIM|TRUNCATE|TYPEOF|UNGROUP|'
r'UNICODEORDER|VARIANCE|WHICH|WORKUNIT|XMLDECODE|XMLENCODE|'
r'XMLTEXT|XMLUNICODE)\b', Name.Function),
],
'string': [
(r'"', String, '#pop'),
(r'\'', String, '#pop'),
(r'[^"\']+', String),
],
}
class BrainfuckLexer(RegexLexer):
"""
Lexer for the esoteric `BrainFuck <http://www.muppetlabs.com/~breadbox/bf/>`_
language.
"""
name = 'Brainfuck'
aliases = ['brainfuck', 'bf']
filenames = ['*.bf', '*.b']
mimetypes = ['application/x-brainfuck']
tokens = {
'common': [
# use different colors for different instruction types
(r'[.,]+', Name.Tag),
(r'[+-]+', Name.Builtin),
(r'[<>]+', Name.Variable),
(r'[^.,+\-<>\[\]]+', Comment),
],
'root': [
(r'\[', Keyword, 'loop'),
(r'\]', Error),
include('common'),
],
'loop': [
(r'\[', Keyword, '#push'),
(r'\]', Keyword, '#pop'),
include('common'),
]
}
class BefungeLexer(RegexLexer):
"""
Lexer for the esoteric `Befunge <http://en.wikipedia.org/wiki/Befunge>`_
language.
*New in Pygments 0.7.*
"""
name = 'Befunge'
aliases = ['befunge']
filenames = ['*.befunge']
mimetypes = ['application/x-befunge']
tokens = {
'root': [
(r'[0-9a-f]', Number),
(r'[\+\*/%!`-]', Operator), # Traditional math
(r'[<>^v?\[\]rxjk]', Name.Variable), # Move, imperatives
(r'[:\\$.,n]', Name.Builtin), # Stack ops, imperatives
(r'[|_mw]', Keyword),
(r'[{}]', Name.Tag), # Befunge-98 stack ops
(r'".*?"', String.Double), # Strings don't appear to allow escapes
(r'\'.', String.Single), # Single character
(r'[#;]', Comment), # Trampoline... depends on direction hit
(r'[pg&~=@iotsy]', Keyword), # Misc
(r'[()A-Z]', Comment), # Fingerprints
(r'\s+', Text), # Whitespace doesn't matter
],
}
class RedcodeLexer(RegexLexer):
"""
A simple Redcode lexer based on ICWS'94.
Contributed by Adam Blinkinsop <blinks@acm.org>.
*New in Pygments 0.8.*
"""
name = 'Redcode'
aliases = ['redcode']
filenames = ['*.cw']
opcodes = ['DAT','MOV','ADD','SUB','MUL','DIV','MOD',
'JMP','JMZ','JMN','DJN','CMP','SLT','SPL',
'ORG','EQU','END']
modifiers = ['A','B','AB','BA','F','X','I']
tokens = {
'root': [
# Whitespace:
(r'\s+', Text),
(r';.*$', Comment.Single),
# Lexemes:
# Identifiers
(r'\b(%s)\b' % '|'.join(opcodes), Name.Function),
(r'\b(%s)\b' % '|'.join(modifiers), Name.Decorator),
(r'[A-Za-z_][A-Za-z_0-9]+', Name),
# Operators
(r'[-+*/%]', Operator),
(r'[#$@<>]', Operator), # mode
(r'[.,]', Punctuation), # mode
# Numbers
(r'[-+]?\d+', Number.Integer),
],
}
class MOOCodeLexer(RegexLexer):
"""
For `MOOCode <http://www.moo.mud.org/>`_ (the MOO scripting
language).
*New in Pygments 0.9.*
"""
name = 'MOOCode'
filenames = ['*.moo']
aliases = ['moocode', 'moo']
mimetypes = ['text/x-moocode']
tokens = {
'root' : [
# Numbers
(r'(0|[1-9][0-9_]*)', Number.Integer),
# Strings
(r'"(\\\\|\\"|[^"])*"', String),
# exceptions
(r'(E_PERM|E_DIV)', Name.Exception),
# db-refs
(r'((#[-0-9]+)|(\$[a-z_A-Z0-9]+))', Name.Entity),
# Keywords
(r'\b(if|else|elseif|endif|for|endfor|fork|endfork|while'
r'|endwhile|break|continue|return|try'
r'|except|endtry|finally|in)\b', Keyword),
# builtins
(r'(random|length)', Name.Builtin),
# special variables
(r'(player|caller|this|args)', Name.Variable.Instance),
# skip whitespace
(r'\s+', Text),
(r'\n', Text),
# other operators
(r'([!;=,{}&\|:\.\[\]@\(\)\<\>\?]+)', Operator),
# function call
(r'([a-z_A-Z0-9]+)(\()', bygroups(Name.Function, Operator)),
# variables
(r'([a-zA-Z_0-9]+)', Text),
]
}
class SmalltalkLexer(RegexLexer):
"""
For `Smalltalk <http://www.smalltalk.org/>`_ syntax.
Contributed by Stefan Matthias Aust.
Rewritten by Nils Winter.
*New in Pygments 0.10.*
"""
name = 'Smalltalk'
filenames = ['*.st']
aliases = ['smalltalk', 'squeak', 'st']
mimetypes = ['text/x-smalltalk']
tokens = {
'root' : [
(r'(<)(\w+:)(.*?)(>)', bygroups(Text, Keyword, Text, Text)),
include('squeak fileout'),
include('whitespaces'),
include('method definition'),
(r'(\|)([\w\s]*)(\|)', bygroups(Operator, Name.Variable, Operator)),
include('objects'),
(r'\^|\:=|\_', Operator),
# temporaries
(r'[\]({}.;!]', Text),
],
'method definition' : [
# Not perfect can't allow whitespaces at the beginning and the
# without breaking everything
(r'([a-zA-Z]+\w*:)(\s*)(\w+)',
bygroups(Name.Function, Text, Name.Variable)),
(r'^(\b[a-zA-Z]+\w*\b)(\s*)$', bygroups(Name.Function, Text)),
(r'^([-+*/\\~<>=|&!?,@%]+)(\s*)(\w+)(\s*)$',
bygroups(Name.Function, Text, Name.Variable, Text)),
],
'blockvariables' : [
include('whitespaces'),
(r'(:)(\s*)(\w+)',
bygroups(Operator, Text, Name.Variable)),
(r'\|', Operator, '#pop'),
(r'', Text, '#pop'), # else pop
],
'literals' : [
(r"'(''|[^'])*'", String, 'afterobject'),
(r'\$.', String.Char, 'afterobject'),
(r'#\(', String.Symbol, 'parenth'),
(r'\)', Text, 'afterobject'),
(r'(\d+r)?-?\d+(\.\d+)?(e-?\d+)?', Number, 'afterobject'),
],
'_parenth_helper' : [
include('whitespaces'),
(r'(\d+r)?-?\d+(\.\d+)?(e-?\d+)?', Number),
(r'[-+*/\\~<>=|&#!?,@%\w:]+', String.Symbol),
# literals
(r"'(''|[^'])*'", String),
(r'\$.', String.Char),
(r'#*\(', String.Symbol, 'inner_parenth'),
],
'parenth' : [
# This state is a bit tricky since
# we can't just pop this state
(r'\)', String.Symbol, ('root', 'afterobject')),
include('_parenth_helper'),
],
'inner_parenth': [
(r'\)', String.Symbol, '#pop'),
include('_parenth_helper'),
],
'whitespaces' : [
# skip whitespace and comments
(r'\s+', Text),
(r'"(""|[^"])*"', Comment),
],
'objects' : [
(r'\[', Text, 'blockvariables'),
(r'\]', Text, 'afterobject'),
(r'\b(self|super|true|false|nil|thisContext)\b',
Name.Builtin.Pseudo, 'afterobject'),
(r'\b[A-Z]\w*(?!:)\b', Name.Class, 'afterobject'),
(r'\b[a-z]\w*(?!:)\b', Name.Variable, 'afterobject'),
(r'#("(""|[^"])*"|[-+*/\\~<>=|&!?,@%]+|[\w:]+)',
String.Symbol, 'afterobject'),
include('literals'),
],
'afterobject' : [
(r'! !$', Keyword , '#pop'), # squeak chunk delimiter
include('whitespaces'),
(r'\b(ifTrue:|ifFalse:|whileTrue:|whileFalse:|timesRepeat:)',
Name.Builtin, '#pop'),
(r'\b(new\b(?!:))', Name.Builtin),
(r'\:=|\_', Operator, '#pop'),
(r'\b[a-zA-Z]+\w*:', Name.Function, '#pop'),
(r'\b[a-zA-Z]+\w*', Name.Function),
(r'\w+:?|[-+*/\\~<>=|&!?,@%]+', Name.Function, '#pop'),
(r'\.', Punctuation, '#pop'),
(r';', Punctuation),
(r'[\])}]', Text),
(r'[\[({]', Text, '#pop'),
],
'squeak fileout' : [
# Squeak fileout format (optional)
(r'^"(""|[^"])*"!', Keyword),
(r"^'(''|[^'])*'!", Keyword),
(r'^(!)(\w+)( commentStamp: )(.*?)( prior: .*?!\n)(.*?)(!)',
bygroups(Keyword, Name.Class, Keyword, String, Keyword, Text, Keyword)),
(r"^(!)(\w+(?: class)?)( methodsFor: )('(?:''|[^'])*')(.*?!)",
bygroups(Keyword, Name.Class, Keyword, String, Keyword)),
(r'^(\w+)( subclass: )(#\w+)'
r'(\s+instanceVariableNames: )(.*?)'
r'(\s+classVariableNames: )(.*?)'
r'(\s+poolDictionaries: )(.*?)'
r'(\s+category: )(.*?)(!)',
bygroups(Name.Class, Keyword, String.Symbol, Keyword, String, Keyword,
String, Keyword, String, Keyword, String, Keyword)),
(r'^(\w+(?: class)?)(\s+instanceVariableNames: )(.*?)(!)',
bygroups(Name.Class, Keyword, String, Keyword)),
(r'(!\n)(\].*)(! !)$', bygroups(Keyword, Text, Keyword)),
(r'! !$', Keyword),
],
}
class LogtalkLexer(RegexLexer):
"""
For `Logtalk <http://logtalk.org/>`_ source code.
*New in Pygments 0.10.*
"""
name = 'Logtalk'
aliases = ['logtalk']
filenames = ['*.lgt']
mimetypes = ['text/x-logtalk']
tokens = {
'root': [
# Directives
(r'^\s*:-\s',Punctuation,'directive'),
# Comments
(r'%.*?\n', Comment),
(r'/\*(.|\n)*?\*/',Comment),
# Whitespace
(r'\n', Text),
(r'\s+', Text),
# Numbers
(r"0'.", Number),
(r'0b[01]+', Number),
(r'0o[0-7]+', Number),
(r'0x[0-9a-fA-F]+', Number),
(r'\d+\.?\d*((e|E)(\+|-)?\d+)?', Number),
# Variables
(r'([A-Z_][a-zA-Z0-9_]*)', Name.Variable),
# Event handlers
(r'(after|before)(?=[(])', Keyword),
# Execution-context methods
(r'(parameter|this|se(lf|nder))(?=[(])', Keyword),
# Reflection
(r'(current_predicate|predicate_property)(?=[(])', Keyword),
# DCGs and term expansion
(r'(expand_(goal|term)|(goal|term)_expansion|phrase)(?=[(])',
Keyword),
# Entity
(r'(abolish|c(reate|urrent))_(object|protocol|category)(?=[(])',
Keyword),
(r'(object|protocol|category)_property(?=[(])', Keyword),
# Entity relations
(r'co(mplements_object|nforms_to_protocol)(?=[(])', Keyword),
(r'extends_(object|protocol|category)(?=[(])', Keyword),
(r'imp(lements_protocol|orts_category)(?=[(])', Keyword),
(r'(instantiat|specializ)es_class(?=[(])', Keyword),
# Events
(r'(current_event|(abolish|define)_events)(?=[(])', Keyword),
# Flags
(r'(current|set)_logtalk_flag(?=[(])', Keyword),
# Compiling, loading, and library paths
(r'logtalk_(compile|l(ibrary_path|oad_context|oad))(?=[(])',
Keyword),
# Database
(r'(clause|retract(all)?)(?=[(])', Keyword),
(r'a(bolish|ssert(a|z))(?=[(])', Keyword),
# Control constructs
(r'(ca(ll|tch)|throw)(?=[(])', Keyword),
(r'(fail|true)\b', Keyword),
# All solutions
(r'((bag|set)of|f(ind|or)all)(?=[(])', Keyword),
# Multi-threading meta-predicates
(r'threaded(_(call|once|ignore|exit|peek|wait|notify))?(?=[(])',
Keyword),
# Term unification
(r'unify_with_occurs_check(?=[(])', Keyword),
# Term creation and decomposition
(r'(functor|arg|copy_term|numbervars)(?=[(])', Keyword),
# Evaluable functors
(r'(rem|mod|abs|sign)(?=[(])', Keyword),
(r'float(_(integer|fractional)_part)?(?=[(])', Keyword),
(r'(floor|truncate|round|ceiling)(?=[(])', Keyword),
# Other arithmetic functors
(r'(cos|atan|exp|log|s(in|qrt))(?=[(])', Keyword),
# Term testing
(r'(var|atom(ic)?|integer|float|c(allable|ompound)|n(onvar|umber)|'
r'ground)(?=[(])', Keyword),
# Term comparison
(r'compare(?=[(])', Keyword),
# Stream selection and control
(r'(curren|se)t_(in|out)put(?=[(])', Keyword),
(r'(open|close)(?=[(])', Keyword),
(r'flush_output(?=[(])', Keyword),
(r'(at_end_of_stream|flush_output)\b', Keyword),
(r'(stream_property|at_end_of_stream|set_stream_position)(?=[(])',
Keyword),
# Character and byte input/output
(r'(nl|(get|peek|put)_(byte|c(har|ode)))(?=[(])', Keyword),
(r'\bnl\b', Keyword),
# Term input/output
(r'read(_term)?(?=[(])', Keyword),
(r'write(q|_(canonical|term))?(?=[(])', Keyword),
(r'(current_)?op(?=[(])', Keyword),
(r'(current_)?char_conversion(?=[(])', Keyword),
# Atomic term processing
(r'atom_(length|c(hars|o(ncat|des)))(?=[(])', Keyword),
(r'(char_code|sub_atom)(?=[(])', Keyword),
(r'number_c(har|ode)s(?=[(])', Keyword),
# Implementation defined hooks functions
(r'(se|curren)t_prolog_flag(?=[(])', Keyword),
(r'\bhalt\b', Keyword),
(r'halt(?=[(])', Keyword),
# Message sending operators
(r'(::|:|\^\^)', Operator),
# External call
(r'[{}]', Keyword),
# Logic and control
(r'\b(ignore|once)(?=[(])', Keyword),
(r'\brepeat\b', Keyword),
# Sorting
(r'(key)?sort(?=[(])', Keyword),
# Bitwise functors
(r'(>>|<<|/\\|\\\\|\\)', Operator),
# Arithemtic evaluation
(r'\bis\b', Keyword),
# Arithemtic comparison
(r'(=:=|=\\=|<|=<|>=|>)', Operator),
# Term creation and decomposition
(r'=\.\.', Operator),
# Term unification
(r'(=|\\=)', Operator),
# Term comparison
(r'(==|\\==|@=<|@<|@>=|@>)', Operator),
# Evaluable functors
(r'(//|[-+*/])', Operator),
(r'\b(e|pi|mod|rem)\b', Operator),
# Other arithemtic functors
(r'\b\*\*\b', Operator),
# DCG rules
(r'-->', Operator),
# Control constructs
(r'([!;]|->)', Operator),
# Logic and control
(r'\\+', Operator),
# Mode operators
(r'[?@]', Operator),
# Existential quantifier
(r'\^', Operator),
# Strings
(r'"(\\\\|\\"|[^"])*"', String),
# Ponctuation
(r'[()\[\],.|]', Text),
# Atoms
(r"[a-z][a-zA-Z0-9_]*", Text),
(r"'", String, 'quoted_atom'),
],
'quoted_atom': [
(r"''", String),
(r"'", String, '#pop'),
(r'\\([\\abfnrtv"\']|(x[a-fA-F0-9]+|[0-7]+)\\)', String.Escape),
(r"[^\\'\n]+", String),
(r'\\', String),
],
'directive': [
# Conditional compilation directives
(r'(el)?if(?=[(])', Keyword, 'root'),
(r'(e(lse|ndif))[.]', Keyword, 'root'),
# Entity directives
(r'(category|object|protocol)(?=[(])', Keyword, 'entityrelations'),
(r'(end_(category|object|protocol))[.]',Keyword, 'root'),
# Predicate scope directives
(r'(public|protected|private)(?=[(])', Keyword, 'root'),
# Other directives
(r'e(n(coding|sure_loaded)|xport)(?=[(])', Keyword, 'root'),
(r'in(fo|itialization)(?=[(])', Keyword, 'root'),
(r'(dynamic|synchronized|threaded)[.]', Keyword, 'root'),
(r'(alias|d(ynamic|iscontiguous)|m(eta_predicate|ode|ultifile)|'
r's(et_(logtalk|prolog)_flag|ynchronized))(?=[(])',
Keyword, 'root'),
(r'op(?=[(])', Keyword, 'root'),
(r'(c(alls|oinductive)|reexport|use(s|_module))(?=[(])',
Keyword, 'root'),
(r'[a-z][a-zA-Z0-9_]*(?=[(])', Text, 'root'),
(r'[a-z][a-zA-Z0-9_]*[.]', Text, 'root'),
],
'entityrelations': [
(r'(complements|extends|i(nstantiates|mp(lements|orts))|specializes)'
r'(?=[(])', Keyword),
# Numbers
(r"0'.", Number),
(r'0b[01]+', Number),
(r'0o[0-7]+', Number),
(r'0x[0-9a-fA-F]+', Number),
(r'\d+\.?\d*((e|E)(\+|-)?\d+)?', Number),
# Variables
(r'([A-Z_][a-zA-Z0-9_]*)', Name.Variable),
# Atoms
(r"[a-z][a-zA-Z0-9_]*", Text),
(r"'", String, 'quoted_atom'),
# Strings
(r'"(\\\\|\\"|[^"])*"', String),
# End of entity-opening directive
(r'([)]\.)', Text, 'root'),
# Scope operator
(r'(::)', Operator),
# Ponctuation
(r'[()\[\],.|]', Text),
# Comments
(r'%.*?\n', Comment),
(r'/\*(.|\n)*?\*/',Comment),
# Whitespace
(r'\n', Text),
(r'\s+', Text),
]
}
def analyse_text(text):
if ':- object(' in text:
return True
if ':- protocol(' in text:
return True
if ':- category(' in text:
return True
return False
def _shortened(word):
dpos = word.find('$')
return '|'.join([word[:dpos] + word[dpos+1:i] + r'\b'
for i in range(len(word), dpos, -1)])
def _shortened_many(*words):
return '|'.join(map(_shortened, words))
class GnuplotLexer(RegexLexer):
"""
For `Gnuplot <http://gnuplot.info/>`_ plotting scripts.
*New in Pygments 0.11.*
"""
name = 'Gnuplot'
aliases = ['gnuplot']
filenames = ['*.plot', '*.plt']
mimetypes = ['text/x-gnuplot']
tokens = {
'root': [
include('whitespace'),
(_shortened('bi$nd'), Keyword, 'bind'),
(_shortened_many('ex$it', 'q$uit'), Keyword, 'quit'),
(_shortened('f$it'), Keyword, 'fit'),
(r'(if)(\s*)(\()', bygroups(Keyword, Text, Punctuation), 'if'),
(r'else\b', Keyword),
(_shortened('pa$use'), Keyword, 'pause'),
(_shortened_many('p$lot', 'rep$lot', 'sp$lot'), Keyword, 'plot'),
(_shortened('sa$ve'), Keyword, 'save'),
(_shortened('se$t'), Keyword, ('genericargs', 'optionarg')),
(_shortened_many('sh$ow', 'uns$et'),
Keyword, ('noargs', 'optionarg')),
(_shortened_many('low$er', 'ra$ise', 'ca$ll', 'cd$', 'cl$ear',
'h$elp', '\\?$', 'hi$story', 'l$oad', 'pr$int',
'pwd$', 're$read', 'res$et', 'scr$eendump',
'she$ll', 'sy$stem', 'up$date'),
Keyword, 'genericargs'),
(_shortened_many('pwd$', 're$read', 'res$et', 'scr$eendump',
'she$ll', 'test$'),
Keyword, 'noargs'),
('([a-zA-Z_][a-zA-Z0-9_]*)(\s*)(=)',
bygroups(Name.Variable, Text, Operator), 'genericargs'),
('([a-zA-Z_][a-zA-Z0-9_]*)(\s*\(.*?\)\s*)(=)',
bygroups(Name.Function, Text, Operator), 'genericargs'),
(r'@[a-zA-Z_][a-zA-Z0-9_]*', Name.Constant), # macros
(r';', Keyword),
],
'comment': [
(r'[^\\\n]', Comment),
(r'\\\n', Comment),
(r'\\', Comment),
# don't add the newline to the Comment token
('', Comment, '#pop'),
],
'whitespace': [
('#', Comment, 'comment'),
(r'[ \t\v\f]+', Text),
],
'noargs': [
include('whitespace'),
# semicolon and newline end the argument list
(r';', Punctuation, '#pop'),
(r'\n', Text, '#pop'),
],
'dqstring': [
(r'"', String, '#pop'),
(r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
(r'[^\\"\n]+', String), # all other characters
(r'\\\n', String), # line continuation
(r'\\', String), # stray backslash
(r'\n', String, '#pop'), # newline ends the string too
],
'sqstring': [
(r"''", String), # escaped single quote
(r"'", String, '#pop'),
(r"[^\\'\n]+", String), # all other characters
(r'\\\n', String), # line continuation
(r'\\', String), # normal backslash
(r'\n', String, '#pop'), # newline ends the string too
],
'genericargs': [
include('noargs'),
(r'"', String, 'dqstring'),
(r"'", String, 'sqstring'),
(r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+', Number.Float),
(r'(\d+\.\d*|\.\d+)', Number.Float),
(r'-?\d+', Number.Integer),
('[,.~!%^&*+=|?:<>/-]', Operator),
('[{}()\[\]]', Punctuation),
(r'(eq|ne)\b', Operator.Word),
(r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*)(\()',
bygroups(Name.Function, Text, Punctuation)),
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
(r'@[a-zA-Z_][a-zA-Z0-9_]*', Name.Constant), # macros
(r'\\\n', Text),
],
'optionarg': [
include('whitespace'),
(_shortened_many(
"a$ll","an$gles","ar$row","au$toscale","b$ars","bor$der",
"box$width","cl$abel","c$lip","cn$trparam","co$ntour","da$ta",
"data$file","dg$rid3d","du$mmy","enc$oding","dec$imalsign",
"fit$","font$path","fo$rmat","fu$nction","fu$nctions","g$rid",
"hid$den3d","his$torysize","is$osamples","k$ey","keyt$itle",
"la$bel","li$nestyle","ls$","loa$dpath","loc$ale","log$scale",
"mac$ros","map$ping","map$ping3d","mar$gin","lmar$gin",
"rmar$gin","tmar$gin","bmar$gin","mo$use","multi$plot",
"mxt$ics","nomxt$ics","mx2t$ics","nomx2t$ics","myt$ics",
"nomyt$ics","my2t$ics","nomy2t$ics","mzt$ics","nomzt$ics",
"mcbt$ics","nomcbt$ics","of$fsets","or$igin","o$utput",
"pa$rametric","pm$3d","pal$ette","colorb$ox","p$lot",
"poi$ntsize","pol$ar","pr$int","obj$ect","sa$mples","si$ze",
"st$yle","su$rface","table$","t$erminal","termo$ptions","ti$cs",
"ticsc$ale","ticsl$evel","timef$mt","tim$estamp","tit$le",
"v$ariables","ve$rsion","vi$ew","xyp$lane","xda$ta","x2da$ta",
"yda$ta","y2da$ta","zda$ta","cbda$ta","xl$abel","x2l$abel",
"yl$abel","y2l$abel","zl$abel","cbl$abel","xti$cs","noxti$cs",
"x2ti$cs","nox2ti$cs","yti$cs","noyti$cs","y2ti$cs","noy2ti$cs",
"zti$cs","nozti$cs","cbti$cs","nocbti$cs","xdti$cs","noxdti$cs",
"x2dti$cs","nox2dti$cs","ydti$cs","noydti$cs","y2dti$cs",
"noy2dti$cs","zdti$cs","nozdti$cs","cbdti$cs","nocbdti$cs",
"xmti$cs","noxmti$cs","x2mti$cs","nox2mti$cs","ymti$cs",
"noymti$cs","y2mti$cs","noy2mti$cs","zmti$cs","nozmti$cs",
"cbmti$cs","nocbmti$cs","xr$ange","x2r$ange","yr$ange",
"y2r$ange","zr$ange","cbr$ange","rr$ange","tr$ange","ur$ange",
"vr$ange","xzeroa$xis","x2zeroa$xis","yzeroa$xis","y2zeroa$xis",
"zzeroa$xis","zeroa$xis","z$ero"), Name.Builtin, '#pop'),
],
'bind': [
('!', Keyword, '#pop'),
(_shortened('all$windows'), Name.Builtin),
include('genericargs'),
],
'quit': [
(r'gnuplot\b', Keyword),
include('noargs'),
],
'fit': [
(r'via\b', Name.Builtin),
include('plot'),
],
'if': [
(r'\)', Punctuation, '#pop'),
include('genericargs'),
],
'pause': [
(r'(mouse|any|button1|button2|button3)\b', Name.Builtin),
(_shortened('key$press'), Name.Builtin),
include('genericargs'),
],
'plot': [
(_shortened_many('ax$es', 'axi$s', 'bin$ary', 'ev$ery', 'i$ndex',
'mat$rix', 's$mooth', 'thru$', 't$itle',
'not$itle', 'u$sing', 'w$ith'),
Name.Builtin),
include('genericargs'),
],
'save': [
(_shortened_many('f$unctions', 's$et', 't$erminal', 'v$ariables'),
Name.Builtin),
include('genericargs'),
],
}
class PovrayLexer(RegexLexer):
"""
For `Persistence of Vision Raytracer <http://www.povray.org/>`_ files.
*New in Pygments 0.11.*
"""
name = 'POVRay'
aliases = ['pov']
filenames = ['*.pov', '*.inc']
mimetypes = ['text/x-povray']
tokens = {
'root': [
(r'/\*[\w\W]*?\*/', Comment.Multiline),
(r'//.*\n', Comment.Single),
(r'(?s)"(?:\\.|[^"\\])+"', String.Double),
(r'#(debug|default|else|end|error|fclose|fopen|ifdef|ifndef|'
r'include|range|read|render|statistics|switch|undef|version|'
r'warning|while|write|define|macro|local|declare)\b',
Comment.Preproc),
(r'\b(aa_level|aa_threshold|abs|acos|acosh|adaptive|adc_bailout|'
r'agate|agate_turb|all|alpha|ambient|ambient_light|angle|'
r'aperture|arc_angle|area_light|asc|asin|asinh|assumed_gamma|'
r'atan|atan2|atanh|atmosphere|atmospheric_attenuation|'
r'attenuating|average|background|black_hole|blue|blur_samples|'
r'bounded_by|box_mapping|bozo|break|brick|brick_size|'
r'brightness|brilliance|bumps|bumpy1|bumpy2|bumpy3|bump_map|'
r'bump_size|case|caustics|ceil|checker|chr|clipped_by|clock|'
r'color|color_map|colour|colour_map|component|composite|concat|'
r'confidence|conic_sweep|constant|control0|control1|cos|cosh|'
r'count|crackle|crand|cube|cubic_spline|cylindrical_mapping|'
r'debug|declare|default|degrees|dents|diffuse|direction|'
r'distance|distance_maximum|div|dust|dust_type|eccentricity|'
r'else|emitting|end|error|error_bound|exp|exponent|'
r'fade_distance|fade_power|falloff|falloff_angle|false|'
r'file_exists|filter|finish|fisheye|flatness|flip|floor|'
r'focal_point|fog|fog_alt|fog_offset|fog_type|frequency|gif|'
r'global_settings|glowing|gradient|granite|gray_threshold|'
r'green|halo|hexagon|hf_gray_16|hierarchy|hollow|hypercomplex|'
r'if|ifdef|iff|image_map|incidence|include|int|interpolate|'
r'inverse|ior|irid|irid_wavelength|jitter|lambda|leopard|'
r'linear|linear_spline|linear_sweep|location|log|looks_like|'
r'look_at|low_error_factor|mandel|map_type|marble|material_map|'
r'matrix|max|max_intersections|max_iteration|max_trace_level|'
r'max_value|metallic|min|minimum_reuse|mod|mortar|'
r'nearest_count|no|normal|normal_map|no_shadow|number_of_waves|'
r'octaves|off|offset|omega|omnimax|on|once|onion|open|'
r'orthographic|panoramic|pattern1|pattern2|pattern3|'
r'perspective|pgm|phase|phong|phong_size|pi|pigment|'
r'pigment_map|planar_mapping|png|point_at|pot|pow|ppm|'
r'precision|pwr|quadratic_spline|quaternion|quick_color|'
r'quick_colour|quilted|radial|radians|radiosity|radius|rainbow|'
r'ramp_wave|rand|range|reciprocal|recursion_limit|red|'
r'reflection|refraction|render|repeat|rgb|rgbf|rgbft|rgbt|'
r'right|ripples|rotate|roughness|samples|scale|scallop_wave|'
r'scattering|seed|shadowless|sin|sine_wave|sinh|sky|sky_sphere|'
r'slice|slope_map|smooth|specular|spherical_mapping|spiral|'
r'spiral1|spiral2|spotlight|spotted|sqr|sqrt|statistics|str|'
r'strcmp|strength|strlen|strlwr|strupr|sturm|substr|switch|sys|'
r't|tan|tanh|test_camera_1|test_camera_2|test_camera_3|'
r'test_camera_4|texture|texture_map|tga|thickness|threshold|'
r'tightness|tile2|tiles|track|transform|translate|transmit|'
r'triangle_wave|true|ttf|turbulence|turb_depth|type|'
r'ultra_wide_angle|up|use_color|use_colour|use_index|u_steps|'
r'val|variance|vaxis_rotate|vcross|vdot|version|vlength|'
r'vnormalize|volume_object|volume_rendered|vol_with_light|'
r'vrotate|v_steps|warning|warp|water_level|waves|while|width|'
r'wood|wrinkles|yes)\b', Keyword),
(r'(bicubic_patch|blob|box|camera|cone|cubic|cylinder|difference|'
r'disc|height_field|intersection|julia_fractal|lathe|'
r'light_source|merge|mesh|object|plane|poly|polygon|prism|'
r'quadric|quartic|smooth_triangle|sor|sphere|superellipsoid|'
r'text|torus|triangle|union)\b', Name.Builtin),
# TODO: <=, etc
(r'[\[\](){}<>;,]', Punctuation),
(r'[-+*/=]', Operator),
(r'\b(x|y|z|u|v)\b', Name.Builtin.Pseudo),
(r'[a-zA-Z_][a-zA-Z_0-9]*', Name),
(r'[0-9]+\.[0-9]*', Number.Float),
(r'\.[0-9]+', Number.Float),
(r'[0-9]+', Number.Integer),
(r'\s+', Text),
]
}
class AppleScriptLexer(RegexLexer):
"""
For `AppleScript source code
<http://developer.apple.com/documentation/AppleScript/
Conceptual/AppleScriptLangGuide>`_,
including `AppleScript Studio
<http://developer.apple.com/documentation/AppleScript/
Reference/StudioReference>`_.
Contributed by Andreas Amann <aamann@mac.com>.
"""
name = 'AppleScript'
aliases = ['applescript']
filenames = ['*.applescript']
flags = re.MULTILINE | re.DOTALL
Identifiers = r'[a-zA-Z]\w*'
Literals = ['AppleScript', 'current application', 'false', 'linefeed',
'missing value', 'pi','quote', 'result', 'return', 'space',
'tab', 'text item delimiters', 'true', 'version']
Classes = ['alias ', 'application ', 'boolean ', 'class ', 'constant ',
'date ', 'file ', 'integer ', 'list ', 'number ', 'POSIX file ',
'real ', 'record ', 'reference ', 'RGB color ', 'script ',
'text ', 'unit types', '(?:Unicode )?text', 'string']
BuiltIn = ['attachment', 'attribute run', 'character', 'day', 'month',
'paragraph', 'word', 'year']
HandlerParams = ['about', 'above', 'against', 'apart from', 'around',
'aside from', 'at', 'below', 'beneath', 'beside',
'between', 'for', 'given', 'instead of', 'on', 'onto',
'out of', 'over', 'since']
Commands = ['ASCII (character|number)', 'activate', 'beep', 'choose URL',
'choose application', 'choose color', 'choose file( name)?',
'choose folder', 'choose from list',
'choose remote application', 'clipboard info',
'close( access)?', 'copy', 'count', 'current date', 'delay',
'delete', 'display (alert|dialog)', 'do shell script',
'duplicate', 'exists', 'get eof', 'get volume settings',
'info for', 'launch', 'list (disks|folder)', 'load script',
'log', 'make', 'mount volume', 'new', 'offset',
'open( (for access|location))?', 'path to', 'print', 'quit',
'random number', 'read', 'round', 'run( script)?',
'say', 'scripting components',
'set (eof|the clipboard to|volume)', 'store script',
'summarize', 'system attribute', 'system info',
'the clipboard', 'time to GMT', 'write', 'quoted form']
References = ['(in )?back of', '(in )?front of', '[0-9]+(st|nd|rd|th)',
'first', 'second', 'third', 'fourth', 'fifth', 'sixth',
'seventh', 'eighth', 'ninth', 'tenth', 'after', 'back',
'before', 'behind', 'every', 'front', 'index', 'last',
'middle', 'some', 'that', 'through', 'thru', 'where', 'whose']
Operators = ["and", "or", "is equal", "equals", "(is )?equal to", "is not",
"isn't", "isn't equal( to)?", "is not equal( to)?",
"doesn't equal", "does not equal", "(is )?greater than",
"comes after", "is not less than or equal( to)?",
"isn't less than or equal( to)?", "(is )?less than",
"comes before", "is not greater than or equal( to)?",
"isn't greater than or equal( to)?",
"(is )?greater than or equal( to)?", "is not less than",
"isn't less than", "does not come before",
"doesn't come before", "(is )?less than or equal( to)?",
"is not greater than", "isn't greater than",
"does not come after", "doesn't come after", "starts? with",
"begins? with", "ends? with", "contains?", "does not contain",
"doesn't contain", "is in", "is contained by", "is not in",
"is not contained by", "isn't contained by", "div", "mod",
"not", "(a )?(ref( to)?|reference to)", "is", "does"]
Control = ['considering', 'else', 'error', 'exit', 'from', 'if',
'ignoring', 'in', 'repeat', 'tell', 'then', 'times', 'to',
'try', 'until', 'using terms from', 'while', 'whith',
'with timeout( of)?', 'with transaction', 'by', 'continue',
'end', 'its?', 'me', 'my', 'return', 'of' , 'as']
Declarations = ['global', 'local', 'prop(erty)?', 'set', 'get']
Reserved = ['but', 'put', 'returning', 'the']
StudioClasses = ['action cell', 'alert reply', 'application', 'box',
'browser( cell)?', 'bundle', 'button( cell)?', 'cell',
'clip view', 'color well', 'color-panel',
'combo box( item)?', 'control',
'data( (cell|column|item|row|source))?', 'default entry',
'dialog reply', 'document', 'drag info', 'drawer',
'event', 'font(-panel)?', 'formatter',
'image( (cell|view))?', 'matrix', 'menu( item)?', 'item',
'movie( view)?', 'open-panel', 'outline view', 'panel',
'pasteboard', 'plugin', 'popup button',
'progress indicator', 'responder', 'save-panel',
'scroll view', 'secure text field( cell)?', 'slider',
'sound', 'split view', 'stepper', 'tab view( item)?',
'table( (column|header cell|header view|view))',
'text( (field( cell)?|view))?', 'toolbar( item)?',
'user-defaults', 'view', 'window']
StudioEvents = ['accept outline drop', 'accept table drop', 'action',
'activated', 'alert ended', 'awake from nib', 'became key',
'became main', 'begin editing', 'bounds changed',
'cell value', 'cell value changed', 'change cell value',
'change item value', 'changed', 'child of item',
'choose menu item', 'clicked', 'clicked toolbar item',
'closed', 'column clicked', 'column moved',
'column resized', 'conclude drop', 'data representation',
'deminiaturized', 'dialog ended', 'document nib name',
'double clicked', 'drag( (entered|exited|updated))?',
'drop', 'end editing', 'exposed', 'idle', 'item expandable',
'item value', 'item value changed', 'items changed',
'keyboard down', 'keyboard up', 'launched',
'load data representation', 'miniaturized', 'mouse down',
'mouse dragged', 'mouse entered', 'mouse exited',
'mouse moved', 'mouse up', 'moved',
'number of browser rows', 'number of items',
'number of rows', 'open untitled', 'opened', 'panel ended',
'parameters updated', 'plugin loaded', 'prepare drop',
'prepare outline drag', 'prepare outline drop',
'prepare table drag', 'prepare table drop',
'read from file', 'resigned active', 'resigned key',
'resigned main', 'resized( sub views)?',
'right mouse down', 'right mouse dragged',
'right mouse up', 'rows changed', 'scroll wheel',
'selected tab view item', 'selection changed',
'selection changing', 'should begin editing',
'should close', 'should collapse item',
'should end editing', 'should expand item',
'should open( untitled)?',
'should quit( after last window closed)?',
'should select column', 'should select item',
'should select row', 'should select tab view item',
'should selection change', 'should zoom', 'shown',
'update menu item', 'update parameters',
'update toolbar item', 'was hidden', 'was miniaturized',
'will become active', 'will close', 'will dismiss',
'will display browser cell', 'will display cell',
'will display item cell', 'will display outline cell',
'will finish launching', 'will hide', 'will miniaturize',
'will move', 'will open', 'will pop up', 'will quit',
'will resign active', 'will resize( sub views)?',
'will select tab view item', 'will show', 'will zoom',
'write to file', 'zoomed']
StudioCommands = ['animate', 'append', 'call method', 'center',
'close drawer', 'close panel', 'display',
'display alert', 'display dialog', 'display panel', 'go',
'hide', 'highlight', 'increment', 'item for',
'load image', 'load movie', 'load nib', 'load panel',
'load sound', 'localized string', 'lock focus', 'log',
'open drawer', 'path for', 'pause', 'perform action',
'play', 'register', 'resume', 'scroll', 'select( all)?',
'show', 'size to fit', 'start', 'step back',
'step forward', 'stop', 'synchronize', 'unlock focus',
'update']
StudioProperties = ['accepts arrow key', 'action method', 'active',
'alignment', 'allowed identifiers',
'allows branch selection', 'allows column reordering',
'allows column resizing', 'allows column selection',
'allows customization',
'allows editing text attributes',
'allows empty selection', 'allows mixed state',
'allows multiple selection', 'allows reordering',
'allows undo', 'alpha( value)?', 'alternate image',
'alternate increment value', 'alternate title',
'animation delay', 'associated file name',
'associated object', 'auto completes', 'auto display',
'auto enables items', 'auto repeat',
'auto resizes( outline column)?',
'auto save expanded items', 'auto save name',
'auto save table columns', 'auto saves configuration',
'auto scroll', 'auto sizes all columns to fit',
'auto sizes cells', 'background color', 'bezel state',
'bezel style', 'bezeled', 'border rect', 'border type',
'bordered', 'bounds( rotation)?', 'box type',
'button returned', 'button type',
'can choose directories', 'can choose files',
'can draw', 'can hide',
'cell( (background color|size|type))?', 'characters',
'class', 'click count', 'clicked( data)? column',
'clicked data item', 'clicked( data)? row',
'closeable', 'collating', 'color( (mode|panel))',
'command key down', 'configuration',
'content(s| (size|view( margins)?))?', 'context',
'continuous', 'control key down', 'control size',
'control tint', 'control view',
'controller visible', 'coordinate system',
'copies( on scroll)?', 'corner view', 'current cell',
'current column', 'current( field)? editor',
'current( menu)? item', 'current row',
'current tab view item', 'data source',
'default identifiers', 'delta (x|y|z)',
'destination window', 'directory', 'display mode',
'displayed cell', 'document( (edited|rect|view))?',
'double value', 'dragged column', 'dragged distance',
'dragged items', 'draws( cell)? background',
'draws grid', 'dynamically scrolls', 'echos bullets',
'edge', 'editable', 'edited( data)? column',
'edited data item', 'edited( data)? row', 'enabled',
'enclosing scroll view', 'ending page',
'error handling', 'event number', 'event type',
'excluded from windows menu', 'executable path',
'expanded', 'fax number', 'field editor', 'file kind',
'file name', 'file type', 'first responder',
'first visible column', 'flipped', 'floating',
'font( panel)?', 'formatter', 'frameworks path',
'frontmost', 'gave up', 'grid color', 'has data items',
'has horizontal ruler', 'has horizontal scroller',
'has parent data item', 'has resize indicator',
'has shadow', 'has sub menu', 'has vertical ruler',
'has vertical scroller', 'header cell', 'header view',
'hidden', 'hides when deactivated', 'highlights by',
'horizontal line scroll', 'horizontal page scroll',
'horizontal ruler view', 'horizontally resizable',
'icon image', 'id', 'identifier',
'ignores multiple clicks',
'image( (alignment|dims when disabled|frame style|'
'scaling))?',
'imports graphics', 'increment value',
'indentation per level', 'indeterminate', 'index',
'integer value', 'intercell spacing', 'item height',
'key( (code|equivalent( modifier)?|window))?',
'knob thickness', 'label', 'last( visible)? column',
'leading offset', 'leaf', 'level', 'line scroll',
'loaded', 'localized sort', 'location', 'loop mode',
'main( (bunde|menu|window))?', 'marker follows cell',
'matrix mode', 'maximum( content)? size',
'maximum visible columns',
'menu( form representation)?', 'miniaturizable',
'miniaturized', 'minimized image', 'minimized title',
'minimum column width', 'minimum( content)? size',
'modal', 'modified', 'mouse down state',
'movie( (controller|file|rect))?', 'muted', 'name',
'needs display', 'next state', 'next text',
'number of tick marks', 'only tick mark values',
'opaque', 'open panel', 'option key down',
'outline table column', 'page scroll', 'pages across',
'pages down', 'palette label', 'pane splitter',
'parent data item', 'parent window', 'pasteboard',
'path( (names|separator))?', 'playing',
'plays every frame', 'plays selection only', 'position',
'preferred edge', 'preferred type', 'pressure',
'previous text', 'prompt', 'properties',
'prototype cell', 'pulls down', 'rate',
'released when closed', 'repeated',
'requested print time', 'required file type',
'resizable', 'resized column', 'resource path',
'returns records', 'reuses columns', 'rich text',
'roll over', 'row height', 'rulers visible',
'save panel', 'scripts path', 'scrollable',
'selectable( identifiers)?', 'selected cell',
'selected( data)? columns?', 'selected data items?',
'selected( data)? rows?', 'selected item identifier',
'selection by rect', 'send action on arrow key',
'sends action when done editing', 'separates columns',
'separator item', 'sequence number', 'services menu',
'shared frameworks path', 'shared support path',
'sheet', 'shift key down', 'shows alpha',
'shows state by', 'size( mode)?',
'smart insert delete enabled', 'sort case sensitivity',
'sort column', 'sort order', 'sort type',
'sorted( data rows)?', 'sound', 'source( mask)?',
'spell checking enabled', 'starting page', 'state',
'string value', 'sub menu', 'super menu', 'super view',
'tab key traverses cells', 'tab state', 'tab type',
'tab view', 'table view', 'tag', 'target( printer)?',
'text color', 'text container insert',
'text container origin', 'text returned',
'tick mark position', 'time stamp',
'title(d| (cell|font|height|position|rect))?',
'tool tip', 'toolbar', 'trailing offset', 'transparent',
'treat packages as directories', 'truncated labels',
'types', 'unmodified characters', 'update views',
'use sort indicator', 'user defaults',
'uses data source', 'uses ruler',
'uses threaded animation',
'uses title from previous column', 'value wraps',
'version',
'vertical( (line scroll|page scroll|ruler view))?',
'vertically resizable', 'view',
'visible( document rect)?', 'volume', 'width', 'window',
'windows menu', 'wraps', 'zoomable', 'zoomed']
tokens = {
'root': [
(r'\s+', Text),
(r'¬\n', String.Escape),
(r"'s\s+", Text), # This is a possessive, consider moving
(r'(--|#).*?$', Comment),
(r'\(\*', Comment.Multiline, 'comment'),
(r'[\(\){}!,.:]', Punctuation),
(r'(«)([^»]+)(»)',
bygroups(Text, Name.Builtin, Text)),
(r'\b((?:considering|ignoring)\s*)'
r'(application responses|case|diacriticals|hyphens|'
r'numeric strings|punctuation|white space)',
bygroups(Keyword, Name.Builtin)),
(r'(-|\*|\+|&|≠|>=?|<=?|=|≥|≤|/|÷|\^)', Operator),
(r"\b(%s)\b" % '|'.join(Operators), Operator.Word),
(r'^(\s*(?:on|end)\s+)'
r'(%s)' % '|'.join(StudioEvents[::-1]),
bygroups(Keyword, Name.Function)),
(r'^(\s*)(in|on|script|to)(\s+)', bygroups(Text, Keyword, Text)),
(r'\b(as )(%s)\b' % '|'.join(Classes),
bygroups(Keyword, Name.Class)),
(r'\b(%s)\b' % '|'.join(Literals), Name.Constant),
(r'\b(%s)\b' % '|'.join(Commands), Name.Builtin),
(r'\b(%s)\b' % '|'.join(Control), Keyword),
(r'\b(%s)\b' % '|'.join(Declarations), Keyword),
(r'\b(%s)\b' % '|'.join(Reserved), Name.Builtin),
(r'\b(%s)s?\b' % '|'.join(BuiltIn), Name.Builtin),
(r'\b(%s)\b' % '|'.join(HandlerParams), Name.Builtin),
(r'\b(%s)\b' % '|'.join(StudioProperties), Name.Attribute),
(r'\b(%s)s?\b' % '|'.join(StudioClasses), Name.Builtin),
(r'\b(%s)\b' % '|'.join(StudioCommands), Name.Builtin),
(r'\b(%s)\b' % '|'.join(References), Name.Builtin),
(r'"(\\\\|\\"|[^"])*"', String.Double),
(r'\b(%s)\b' % Identifiers, Name.Variable),
(r'[-+]?(\d+\.\d*|\d*\.\d+)(E[-+][0-9]+)?', Number.Float),
(r'[-+]?\d+', Number.Integer),
],
'comment': [
('\(\*', Comment.Multiline, '#push'),
('\*\)', Comment.Multiline, '#pop'),
('[^*(]+', Comment.Multiline),
('[*(]', Comment.Multiline),
],
}
class ModelicaLexer(RegexLexer):
"""
For `Modelica <http://www.modelica.org/>`_ source code.
*New in Pygments 1.1.*
"""
name = 'Modelica'
aliases = ['modelica']
filenames = ['*.mo']
mimetypes = ['text/x-modelica']
flags = re.IGNORECASE | re.DOTALL
tokens = {
'whitespace': [
(r'\n', Text),
(r'\s+', Text),
(r'\\\n', Text), # line continuation
(r'//(\n|(.|\n)*?[^\\]\n)', Comment),
(r'/(\\\n)?\*(.|\n)*?\*(\\\n)?/', Comment),
],
'statements': [
(r'"', String, 'string'),
(r'(\d+\.\d*|\.\d+|\d+|\d.)[eE][+-]?\d+[lL]?', Number.Float),
(r'(\d+\.\d*|\.\d+)', Number.Float),
(r'\d+[Ll]?', Number.Integer),
(r'[~!%^&*+=|?:<>/-]', Operator),
(r'[()\[\]{},.;]', Punctuation),
(r'(true|false|NULL|Real|Integer|Boolean)\b', Name.Builtin),
(r"([a-zA-Z_][\w]*|'[a-zA-Z_\+\-\*\/\^][\w]*')"
r"(\.([a-zA-Z_][\w]*|'[a-zA-Z_\+\-\*\/\^][\w]*'))+", Name.Class),
(r"('[\w\+\-\*\/\^]+'|\w+)", Name),
],
'root': [
include('whitespace'),
include('keywords'),
include('functions'),
include('operators'),
include('classes'),
(r'("<html>|<html>)', Name.Tag, 'html-content'),
include('statements'),
],
'keywords': [
(r'(algorithm|annotation|break|connect|constant|constrainedby|'
r'discrete|each|else|elseif|elsewhen|encapsulated|enumeration|'
r'end|equation|exit|expandable|extends|'
r'external|false|final|flow|for|if|import|impure|in|initial\sequation|'
r'inner|input|loop|nondiscrete|outer|output|parameter|partial|'
r'protected|public|pure|redeclare|replaceable|stream|time|then|true|'
r'when|while|within)\b', Keyword),
],
'functions': [
(r'(abs|acos|acosh|asin|asinh|atan|atan2|atan3|ceil|cos|cosh|'
r'cross|div|exp|floor|getInstanceName|log|log10|mod|rem|'
r'semiLinear|sign|sin|sinh|size|spatialDistribution|sqrt|tan|'
r'tanh|zeros)\b', Name.Function),
],
'operators': [
(r'(actualStream|and|assert|cardinality|change|Clock|delay|der|edge|'
r'hold|homotopy|initial|inStream|noEvent|not|or|pre|previous|reinit|'
r'return|sample|smooth|spatialDistribution|subSample|terminal|'
r'terminate)\b', Name.Builtin),
],
'classes': [
(r'(block|class|connector|function|model|package|'
r'record|type)(\s+)([A-Za-z_]+)',
bygroups(Keyword, Text, Name.Class))
],
'string': [
(r'"', String, '#pop'),
(r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})',
String.Escape),
(r'[^\\"\n]+', String), # all other characters
(r'\\\n', String), # line continuation
(r'\\', String), # stray backslash
],
'html-content': [
(r'<\s*/\s*html\s*>', Name.Tag, '#pop'),
(r'.+?(?=<\s*/\s*html\s*>)', using(HtmlLexer)),
]
}
class RebolLexer(RegexLexer):
"""
A `REBOL <http://www.rebol.com/>`_ lexer.
*New in Pygments 1.1.*
"""
name = 'REBOL'
aliases = ['rebol']
filenames = ['*.r', '*.r3']
mimetypes = ['text/x-rebol']
flags = re.IGNORECASE | re.MULTILINE
re.IGNORECASE
escape_re = r'(?:\^\([0-9a-fA-F]{1,4}\)*)'
def word_callback(lexer, match):
word = match.group()
if re.match(".*:$", word):
yield match.start(), Generic.Subheading, word
elif re.match(
r'(native|alias|all|any|as-string|as-binary|bind|bound\?|case|'
r'catch|checksum|comment|debase|dehex|exclude|difference|disarm|'
r'either|else|enbase|foreach|remove-each|form|free|get|get-env|if|'
r'in|intersect|loop|minimum-of|maximum-of|mold|new-line|'
r'new-line\?|not|now|prin|print|reduce|compose|construct|repeat|'
r'reverse|save|script\?|set|shift|switch|throw|to-hex|trace|try|'
r'type\?|union|unique|unless|unprotect|unset|until|use|value\?|'
r'while|compress|decompress|secure|open|close|read|read-io|'
r'write-io|write|update|query|wait|input\?|exp|log-10|log-2|'
r'log-e|square-root|cosine|sine|tangent|arccosine|arcsine|'
r'arctangent|protect|lowercase|uppercase|entab|detab|connected\?|'
r'browse|launch|stats|get-modes|set-modes|to-local-file|'
r'to-rebol-file|encloak|decloak|create-link|do-browser|bind\?|'
r'hide|draw|show|size-text|textinfo|offset-to-caret|'
r'caret-to-offset|local-request-file|rgb-to-hsv|hsv-to-rgb|'
r'crypt-strength\?|dh-make-key|dh-generate-key|dh-compute-key|'
r'dsa-make-key|dsa-generate-key|dsa-make-signature|'
r'dsa-verify-signature|rsa-make-key|rsa-generate-key|'
r'rsa-encrypt)$', word):
yield match.start(), Name.Builtin, word
elif re.match(
r'(add|subtract|multiply|divide|remainder|power|and~|or~|xor~|'
r'minimum|maximum|negate|complement|absolute|random|head|tail|'
r'next|back|skip|at|pick|first|second|third|fourth|fifth|sixth|'
r'seventh|eighth|ninth|tenth|last|path|find|select|make|to|copy\*|'
r'insert|remove|change|poke|clear|trim|sort|min|max|abs|cp|'
r'copy)$', word):
yield match.start(), Name.Function, word
elif re.match(
r'(error|source|input|license|help|install|echo|Usage|with|func|'
r'throw-on-error|function|does|has|context|probe|\?\?|as-pair|'
r'mod|modulo|round|repend|about|set-net|append|join|rejoin|reform|'
r'remold|charset|array|replace|move|extract|forskip|forall|alter|'
r'first+|also|take|for|forever|dispatch|attempt|what-dir|'
r'change-dir|clean-path|list-dir|dirize|rename|split-path|delete|'
r'make-dir|delete-dir|in-dir|confirm|dump-obj|upgrade|what|'
r'build-tag|process-source|build-markup|decode-cgi|read-cgi|'
r'write-user|save-user|set-user-name|protect-system|parse-xml|'
r'cvs-date|cvs-version|do-boot|get-net-info|desktop|layout|'
r'scroll-para|get-face|alert|set-face|uninstall|unfocus|'
r'request-dir|center-face|do-events|net-error|decode-url|'
r'parse-header|parse-header-date|parse-email-addrs|import-email|'
r'send|build-attach-body|resend|show-popup|hide-popup|open-events|'
r'find-key-face|do-face|viewtop|confine|find-window|'
r'insert-event-func|remove-event-func|inform|dump-pane|dump-face|'
r'flag-face|deflag-face|clear-fields|read-net|vbug|path-thru|'
r'read-thru|load-thru|do-thru|launch-thru|load-image|'
r'request-download|do-face-alt|set-font|set-para|get-style|'
r'set-style|make-face|stylize|choose|hilight-text|hilight-all|'
r'unlight-text|focus|scroll-drag|clear-face|reset-face|scroll-face|'
r'resize-face|load-stock|load-stock-block|notify|request|flash|'
r'request-color|request-pass|request-text|request-list|'
r'request-date|request-file|dbug|editor|link-relative-path|'
r'emailer|parse-error)$', word):
yield match.start(), Keyword.Namespace, word
elif re.match(
r'(halt|quit|do|load|q|recycle|call|run|ask|parse|view|unview|'
r'return|exit|break)$', word):
yield match.start(), Name.Exception, word
elif re.match('REBOL$', word):
yield match.start(), Generic.Heading, word
elif re.match("to-.*", word):
yield match.start(), Keyword, word
elif re.match('(\+|-|\*|/|//|\*\*|and|or|xor|=\?|=|==|<>|<|>|<=|>=)$',
word):
yield match.start(), Operator, word
elif re.match(".*\?$", word):
yield match.start(), Keyword, word
elif re.match(".*\!$", word):
yield match.start(), Keyword.Type, word
elif re.match("'.*", word):
yield match.start(), Name.Variable.Instance, word # lit-word
elif re.match("#.*", word):
yield match.start(), Name.Label, word # issue
elif re.match("%.*", word):
yield match.start(), Name.Decorator, word # file
else:
yield match.start(), Name.Variable, word
tokens = {
'root': [
(r'REBOL', Generic.Strong, 'script'),
(r'R', Comment),
(r'[^R]+', Comment),
],
'script': [
(r'\s+', Text),
(r'#"', String.Char, 'char'),
(r'#{[0-9a-fA-F]*}', Number.Hex),
(r'2#{', Number.Hex, 'bin2'),
(r'64#{[0-9a-zA-Z+/=\s]*}', Number.Hex),
(r'"', String, 'string'),
(r'{', String, 'string2'),
(r';#+.*\n', Comment.Special),
(r';\*+.*\n', Comment.Preproc),
(r';.*\n', Comment),
(r'%"', Name.Decorator, 'stringFile'),
(r'%[^(\^{^")\s\[\]]+', Name.Decorator),
(r'[+-]?([a-zA-Z]{1,3})?\$\d+(\.\d+)?', Number.Float), # money
(r'[+-]?\d+\:\d+(\:\d+)?(\.\d+)?', String.Other), # time
(r'\d+\-[0-9a-zA-Z]+\-\d+(\/\d+\:\d+(\:\d+)?'
r'([\.\d+]?([+-]?\d+:\d+)?)?)?', String.Other), # date
(r'\d+(\.\d+)+\.\d+', Keyword.Constant), # tuple
(r'\d+[xX]\d+', Keyword.Constant), # pair
(r'[+-]?\d+(\'\d+)?([\.,]\d*)?[eE][+-]?\d+', Number.Float),
(r'[+-]?\d+(\'\d+)?[\.,]\d*', Number.Float),
(r'[+-]?\d+(\'\d+)?', Number),
(r'[\[\]\(\)]', Generic.Strong),
(r'[a-zA-Z]+[^(\^{"\s:)]*://[^(\^{"\s)]*', Name.Decorator), # url
(r'mailto:[^(\^{"@\s)]+@[^(\^{"@\s)]+', Name.Decorator), # url
(r'[^(\^{"@\s)]+@[^(\^{"@\s)]+', Name.Decorator), # email
(r'comment\s', Comment, 'comment'),
(r'/[^(\^{^")\s/[\]]*', Name.Attribute),
(r'([^(\^{^")\s/[\]]+)(?=[:({"\s/\[\]])', word_callback),
(r'<[a-zA-Z0-9:._-]*>', Name.Tag),
(r'<[^(<>\s")]+', Name.Tag, 'tag'),
(r'([^(\^{^")\s]+)', Text),
],
'string': [
(r'[^(\^")]+', String),
(escape_re, String.Escape),
(r'[\(|\)]+', String),
(r'\^.', String.Escape),
(r'"', String, '#pop'),
],
'string2': [
(r'[^(\^{^})]+', String),
(escape_re, String.Escape),
(r'[\(|\)]+', String),
(r'\^.', String.Escape),
(r'{', String, '#push'),
(r'}', String, '#pop'),
],
'stringFile': [
(r'[^(\^")]+', Name.Decorator),
(escape_re, Name.Decorator),
(r'\^.', Name.Decorator),
(r'"', Name.Decorator, '#pop'),
],
'char': [
(escape_re + '"', String.Char, '#pop'),
(r'\^."', String.Char, '#pop'),
(r'."', String.Char, '#pop'),
],
'tag': [
(escape_re, Name.Tag),
(r'"', Name.Tag, 'tagString'),
(r'[^(<>\r\n")]+', Name.Tag),
(r'>', Name.Tag, '#pop'),
],
'tagString': [
(r'[^(\^")]+', Name.Tag),
(escape_re, Name.Tag),
(r'[\(|\)]+', Name.Tag),
(r'\^.', Name.Tag),
(r'"', Name.Tag, '#pop'),
],
'tuple': [
(r'(\d+\.)+', Keyword.Constant),
(r'\d+', Keyword.Constant, '#pop'),
],
'bin2': [
(r'\s+', Number.Hex),
(r'([0-1]\s*){8}', Number.Hex),
(r'}', Number.Hex, '#pop'),
],
'comment': [
(r'"', Comment, 'commentString1'),
(r'{', Comment, 'commentString2'),
(r'\[', Comment, 'commentBlock'),
(r'[^(\s{\"\[]+', Comment, '#pop'),
],
'commentString1': [
(r'[^(\^")]+', Comment),
(escape_re, Comment),
(r'[\(|\)]+', Comment),
(r'\^.', Comment),
(r'"', Comment, '#pop'),
],
'commentString2': [
(r'[^(\^{^})]+', Comment),
(escape_re, Comment),
(r'[\(|\)]+', Comment),
(r'\^.', Comment),
(r'{', Comment, '#push'),
(r'}', Comment, '#pop'),
],
'commentBlock': [
(r'\[', Comment, '#push'),
(r'\]', Comment, '#pop'),
(r'[^(\[\])]+', Comment),
],
}
class ABAPLexer(RegexLexer):
"""
Lexer for ABAP, SAP's integrated language.
*New in Pygments 1.1.*
"""
name = 'ABAP'
aliases = ['abap']
filenames = ['*.abap']
mimetypes = ['text/x-abap']
flags = re.IGNORECASE | re.MULTILINE
tokens = {
'common': [
(r'\s+', Text),
(r'^\*.*$', Comment.Single),
(r'\".*?\n', Comment.Single),
],
'variable-names': [
(r'<[\S_]+>', Name.Variable),
(r'\w[\w~]*(?:(\[\])|->\*)?', Name.Variable),
],
'root': [
include('common'),
#function calls
(r'(CALL\s+(?:BADI|CUSTOMER-FUNCTION|FUNCTION))(\s+)(\'?\S+\'?)',
bygroups(Keyword, Text, Name.Function)),
(r'(CALL\s+(?:DIALOG|SCREEN|SUBSCREEN|SELECTION-SCREEN|'
r'TRANSACTION|TRANSFORMATION))\b',
Keyword),
(r'(FORM|PERFORM)(\s+)(\w+)',
bygroups(Keyword, Text, Name.Function)),
(r'(PERFORM)(\s+)(\()(\w+)(\))',
bygroups(Keyword, Text, Punctuation, Name.Variable, Punctuation )),
(r'(MODULE)(\s+)(\S+)(\s+)(INPUT|OUTPUT)',
bygroups(Keyword, Text, Name.Function, Text, Keyword)),
# method implementation
(r'(METHOD)(\s+)([\w~]+)',
bygroups(Keyword, Text, Name.Function)),
# method calls
(r'(\s+)([\w\-]+)([=\-]>)([\w\-~]+)',
bygroups(Text, Name.Variable, Operator, Name.Function)),
# call methodnames returning style
(r'(?<=(=|-)>)([\w\-~]+)(?=\()', Name.Function),
# keywords with dashes in them.
# these need to be first, because for instance the -ID part
# of MESSAGE-ID wouldn't get highlighted if MESSAGE was
# first in the list of keywords.
(r'(ADD-CORRESPONDING|AUTHORITY-CHECK|'
r'CLASS-DATA|CLASS-EVENTS|CLASS-METHODS|CLASS-POOL|'
r'DELETE-ADJACENT|DIVIDE-CORRESPONDING|'
r'EDITOR-CALL|ENHANCEMENT-POINT|ENHANCEMENT-SECTION|EXIT-COMMAND|'
r'FIELD-GROUPS|FIELD-SYMBOLS|FUNCTION-POOL|'
r'INTERFACE-POOL|INVERTED-DATE|'
r'LOAD-OF-PROGRAM|LOG-POINT|'
r'MESSAGE-ID|MOVE-CORRESPONDING|MULTIPLY-CORRESPONDING|'
r'NEW-LINE|NEW-PAGE|NEW-SECTION|NO-EXTENSION|'
r'OUTPUT-LENGTH|PRINT-CONTROL|'
r'SELECT-OPTIONS|START-OF-SELECTION|SUBTRACT-CORRESPONDING|'
r'SYNTAX-CHECK|SYSTEM-EXCEPTIONS|'
r'TYPE-POOL|TYPE-POOLS'
r')\b', Keyword),
# keyword kombinations
(r'CREATE\s+(PUBLIC|PRIVATE|DATA|OBJECT)|'
r'((PUBLIC|PRIVATE|PROTECTED)\s+SECTION|'
r'(TYPE|LIKE)(\s+(LINE\s+OF|REF\s+TO|'
r'(SORTED|STANDARD|HASHED)\s+TABLE\s+OF))?|'
r'FROM\s+(DATABASE|MEMORY)|CALL\s+METHOD|'
r'(GROUP|ORDER) BY|HAVING|SEPARATED BY|'
r'GET\s+(BADI|BIT|CURSOR|DATASET|LOCALE|PARAMETER|'
r'PF-STATUS|(PROPERTY|REFERENCE)\s+OF|'
r'RUN\s+TIME|TIME\s+(STAMP)?)?|'
r'SET\s+(BIT|BLANK\s+LINES|COUNTRY|CURSOR|DATASET|EXTENDED\s+CHECK|'
r'HANDLER|HOLD\s+DATA|LANGUAGE|LEFT\s+SCROLL-BOUNDARY|'
r'LOCALE|MARGIN|PARAMETER|PF-STATUS|PROPERTY\s+OF|'
r'RUN\s+TIME\s+(ANALYZER|CLOCK\s+RESOLUTION)|SCREEN|'
r'TITLEBAR|UPADTE\s+TASK\s+LOCAL|USER-COMMAND)|'
r'CONVERT\s+((INVERTED-)?DATE|TIME|TIME\s+STAMP|TEXT)|'
r'(CLOSE|OPEN)\s+(DATASET|CURSOR)|'
r'(TO|FROM)\s+(DATA BUFFER|INTERNAL TABLE|MEMORY ID|'
r'DATABASE|SHARED\s+(MEMORY|BUFFER))|'
r'DESCRIBE\s+(DISTANCE\s+BETWEEN|FIELD|LIST|TABLE)|'
r'FREE\s(MEMORY|OBJECT)?|'
r'PROCESS\s+(BEFORE\s+OUTPUT|AFTER\s+INPUT|'
r'ON\s+(VALUE-REQUEST|HELP-REQUEST))|'
r'AT\s+(LINE-SELECTION|USER-COMMAND|END\s+OF|NEW)|'
r'AT\s+SELECTION-SCREEN(\s+(ON(\s+(BLOCK|(HELP|VALUE)-REQUEST\s+FOR|'
r'END\s+OF|RADIOBUTTON\s+GROUP))?|OUTPUT))?|'
r'SELECTION-SCREEN:?\s+((BEGIN|END)\s+OF\s+((TABBED\s+)?BLOCK|LINE|'
r'SCREEN)|COMMENT|FUNCTION\s+KEY|'
r'INCLUDE\s+BLOCKS|POSITION|PUSHBUTTON|'
r'SKIP|ULINE)|'
r'LEAVE\s+(LIST-PROCESSING|PROGRAM|SCREEN|'
r'TO LIST-PROCESSING|TO TRANSACTION)'
r'(ENDING|STARTING)\s+AT|'
r'FORMAT\s+(COLOR|INTENSIFIED|INVERSE|HOTSPOT|INPUT|FRAMES|RESET)|'
r'AS\s+(CHECKBOX|SUBSCREEN|WINDOW)|'
r'WITH\s+(((NON-)?UNIQUE)?\s+KEY|FRAME)|'
r'(BEGIN|END)\s+OF|'
r'DELETE(\s+ADJACENT\s+DUPLICATES\sFROM)?|'
r'COMPARING(\s+ALL\s+FIELDS)?|'
r'INSERT(\s+INITIAL\s+LINE\s+INTO|\s+LINES\s+OF)?|'
r'IN\s+((BYTE|CHARACTER)\s+MODE|PROGRAM)|'
r'END-OF-(DEFINITION|PAGE|SELECTION)|'
r'WITH\s+FRAME(\s+TITLE)|'
# simple kombinations
r'AND\s+(MARK|RETURN)|CLIENT\s+SPECIFIED|CORRESPONDING\s+FIELDS\s+OF|'
r'IF\s+FOUND|FOR\s+EVENT|INHERITING\s+FROM|LEAVE\s+TO\s+SCREEN|'
r'LOOP\s+AT\s+(SCREEN)?|LOWER\s+CASE|MATCHCODE\s+OBJECT|MODIF\s+ID|'
r'MODIFY\s+SCREEN|NESTING\s+LEVEL|NO\s+INTERVALS|OF\s+STRUCTURE|'
r'RADIOBUTTON\s+GROUP|RANGE\s+OF|REF\s+TO|SUPPRESS DIALOG|'
r'TABLE\s+OF|UPPER\s+CASE|TRANSPORTING\s+NO\s+FIELDS|'
r'VALUE\s+CHECK|VISIBLE\s+LENGTH|HEADER\s+LINE)\b', Keyword),
# single word keywords.
(r'(^|(?<=(\s|\.)))(ABBREVIATED|ADD|ALIASES|APPEND|ASSERT|'
r'ASSIGN(ING)?|AT(\s+FIRST)?|'
r'BACK|BLOCK|BREAK-POINT|'
r'CASE|CATCH|CHANGING|CHECK|CLASS|CLEAR|COLLECT|COLOR|COMMIT|'
r'CREATE|COMMUNICATION|COMPONENTS?|COMPUTE|CONCATENATE|CONDENSE|'
r'CONSTANTS|CONTEXTS|CONTINUE|CONTROLS|'
r'DATA|DECIMALS|DEFAULT|DEFINE|DEFINITION|DEFERRED|DEMAND|'
r'DETAIL|DIRECTORY|DIVIDE|DO|'
r'ELSE(IF)?|ENDAT|ENDCASE|ENDCLASS|ENDDO|ENDFORM|ENDFUNCTION|'
r'ENDIF|ENDLOOP|ENDMETHOD|ENDMODULE|ENDSELECT|ENDTRY|'
r'ENHANCEMENT|EVENTS|EXCEPTIONS|EXIT|EXPORT|EXPORTING|EXTRACT|'
r'FETCH|FIELDS?|FIND|FOR|FORM|FORMAT|FREE|FROM|'
r'HIDE|'
r'ID|IF|IMPORT|IMPLEMENTATION|IMPORTING|IN|INCLUDE|INCLUDING|'
r'INDEX|INFOTYPES|INITIALIZATION|INTERFACE|INTERFACES|INTO|'
r'LENGTH|LINES|LOAD|LOCAL|'
r'JOIN|'
r'KEY|'
r'MAXIMUM|MESSAGE|METHOD[S]?|MINIMUM|MODULE|MODIFY|MOVE|MULTIPLY|'
r'NODES|'
r'OBLIGATORY|OF|OFF|ON|OVERLAY|'
r'PACK|PARAMETERS|PERCENTAGE|POSITION|PROGRAM|PROVIDE|PUBLIC|PUT|'
r'RAISE|RAISING|RANGES|READ|RECEIVE|REFRESH|REJECT|REPORT|RESERVE|'
r'RESUME|RETRY|RETURN|RETURNING|RIGHT|ROLLBACK|'
r'SCROLL|SEARCH|SELECT|SHIFT|SINGLE|SKIP|SORT|SPLIT|STATICS|STOP|'
r'SUBMIT|SUBTRACT|SUM|SUMMARY|SUMMING|SUPPLY|'
r'TABLE|TABLES|TIMES|TITLE|TO|TOP-OF-PAGE|TRANSFER|TRANSLATE|TRY|TYPES|'
r'ULINE|UNDER|UNPACK|UPDATE|USING|'
r'VALUE|VALUES|VIA|'
r'WAIT|WHEN|WHERE|WHILE|WITH|WINDOW|WRITE)\b', Keyword),
# builtins
(r'(abs|acos|asin|atan|'
r'boolc|boolx|bit_set|'
r'char_off|charlen|ceil|cmax|cmin|condense|contains|'
r'contains_any_of|contains_any_not_of|concat_lines_of|cos|cosh|'
r'count|count_any_of|count_any_not_of|'
r'dbmaxlen|distance|'
r'escape|exp|'
r'find|find_end|find_any_of|find_any_not_of|floor|frac|from_mixed|'
r'insert|'
r'lines|log|log10|'
r'match|matches|'
r'nmax|nmin|numofchar|'
r'repeat|replace|rescale|reverse|round|'
r'segment|shift_left|shift_right|sign|sin|sinh|sqrt|strlen|'
r'substring|substring_after|substring_from|substring_before|substring_to|'
r'tan|tanh|to_upper|to_lower|to_mixed|translate|trunc|'
r'xstrlen)(\()\b', bygroups(Name.Builtin, Punctuation)),
(r'&[0-9]', Name),
(r'[0-9]+', Number.Integer),
# operators which look like variable names before
# parsing variable names.
(r'(?<=(\s|.))(AND|EQ|NE|GT|LT|GE|LE|CO|CN|CA|NA|CS|NOT|NS|CP|NP|'
r'BYTE-CO|BYTE-CN|BYTE-CA|BYTE-NA|BYTE-CS|BYTE-NS|'
r'IS\s+(NOT\s+)?(INITIAL|ASSIGNED|REQUESTED|BOUND))\b', Operator),
include('variable-names'),
# standard oparators after variable names,
# because < and > are part of field symbols.
(r'[?*<>=\-+]', Operator),
(r"'(''|[^'])*'", String.Single),
(r'[/;:()\[\],\.]', Punctuation)
],
}
class NewspeakLexer(RegexLexer):
"""
For `Newspeak <http://newspeaklanguage.org/>` syntax.
"""
name = 'Newspeak'
filenames = ['*.ns2']
aliases = ['newspeak', ]
mimetypes = ['text/x-newspeak']
tokens = {
'root' : [
(r'\b(Newsqueak2)\b',Keyword.Declaration),
(r"'[^']*'",String),
(r'\b(class)(\s+)([a-zA-Z0-9_]+)(\s*)',
bygroups(Keyword.Declaration,Text,Name.Class,Text)),
(r'\b(mixin|self|super|private|public|protected|nil|true|false)\b',
Keyword),
(r'([a-zA-Z0-9_]+\:)(\s*)([a-zA-Z_]\w+)',
bygroups(Name.Function,Text,Name.Variable)),
(r'([a-zA-Z0-9_]+)(\s*)(=)',
bygroups(Name.Attribute,Text,Operator)),
(r'<[a-zA-Z0-9_]+>', Comment.Special),
include('expressionstat'),
include('whitespace')
],
'expressionstat': [
(r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
(r'\d+', Number.Integer),
(r':\w+',Name.Variable),
(r'(\w+)(::)', bygroups(Name.Variable, Operator)),
(r'\w+:', Name.Function),
(r'\w+', Name.Variable),
(r'\(|\)', Punctuation),
(r'\[|\]', Punctuation),
(r'\{|\}', Punctuation),
(r'(\^|\+|\/|~|\*|<|>|=|@|%|\||&|\?|!|,|-|:)', Operator),
(r'\.|;', Punctuation),
include('whitespace'),
include('literals'),
],
'literals': [
(r'\$.', String),
(r"'[^']*'", String),
(r"#'[^']*'", String.Symbol),
(r"#\w+:?", String.Symbol),
(r"#(\+|\/|~|\*|<|>|=|@|%|\||&|\?|!|,|-)+", String.Symbol)
],
'whitespace' : [
(r'\s+', Text),
(r'"[^"]*"', Comment)
]
}
class GherkinLexer(RegexLexer):
"""
For `Gherkin <http://github.com/aslakhellesoy/gherkin/>` syntax.
*New in Pygments 1.2.*
"""
name = 'Gherkin'
aliases = ['Cucumber', 'cucumber', 'Gherkin', 'gherkin']
filenames = ['*.feature']
mimetypes = ['text/x-gherkin']
feature_keywords = r'^(기능|機能|功能|フィーチャ|خاصية|תכונה|Функціонал|Функционалност|Функционал|Фича|Особина|Могућност|Özellik|Właściwość|Tính năng|Trajto|Savybė|Požiadavka|Požadavek|Osobina|Ominaisuus|Omadus|OH HAI|Mogućnost|Mogucnost|Jellemző|Fīča|Funzionalità|Funktionalität|Funkcionalnost|Funkcionalitāte|Funcționalitate|Functionaliteit|Functionalitate|Funcionalitat|Funcionalidade|Fonctionnalité|Fitur|Feature|Egenskap|Egenskab|Crikey|Característica|Arwedd)(:)(.*)$'
feature_element_keywords = r'^(\s*)(시나리오 개요|시나리오|배경|背景|場景大綱|場景|场景大纲|场景|劇本大綱|劇本|テンプレ|シナリオテンプレート|シナリオテンプレ|シナリオアウトライン|シナリオ|سيناريو مخطط|سيناريو|الخلفية|תרחיש|תבנית תרחיש|רקע|Тарих|Сценарій|Сценарио|Сценарий структураси|Сценарий|Структура сценарію|Структура сценарија|Структура сценария|Скица|Рамка на сценарий|Пример|Предыстория|Предистория|Позадина|Передумова|Основа|Концепт|Контекст|Założenia|Wharrimean is|Tình huống|The thing of it is|Tausta|Taust|Tapausaihio|Tapaus|Szenariogrundriss|Szenario|Szablon scenariusza|Stsenaarium|Struktura scenarija|Skica|Skenario konsep|Skenario|Situācija|Senaryo taslağı|Senaryo|Scénář|Scénario|Schema dello scenario|Scenārijs pēc parauga|Scenārijs|Scenár|Scenaro|Scenariusz|Scenariul de şablon|Scenariul de sablon|Scenariu|Scenario Outline|Scenario Amlinellol|Scenario|Scenarijus|Scenarijaus šablonas|Scenarij|Scenarie|Rerefons|Raamstsenaarium|Primer|Pozadí|Pozadina|Pozadie|Plan du scénario|Plan du Scénario|Osnova scénáře|Osnova|Náčrt Scénáře|Náčrt Scenáru|Mate|MISHUN SRSLY|MISHUN|Kịch bản|Konturo de la scenaro|Kontext|Konteksts|Kontekstas|Kontekst|Koncept|Khung tình huống|Khung kịch bản|Háttér|Grundlage|Geçmiş|Forgatókönyv vázlat|Forgatókönyv|Fono|Esquema do Cenário|Esquema do Cenario|Esquema del escenario|Esquema de l\'escenari|Escenario|Escenari|Dis is what went down|Dasar|Contexto|Contexte|Contesto|Condiţii|Conditii|Cenário|Cenario|Cefndir|Bối cảnh|Blokes|Bakgrunn|Bakgrund|Baggrund|Background|B4|Antecedents|Antecedentes|All y\'all|Achtergrond|Abstrakt Scenario|Abstract Scenario)(:)(.*)$'
examples_keywords = r'^(\s*)(예|例子|例|サンプル|امثلة|דוגמאות|Сценарији|Примери|Приклади|Мисоллар|Значения|Örnekler|Voorbeelden|Variantai|Tapaukset|Scenarios|Scenariji|Scenarijai|Příklady|Példák|Príklady|Przykłady|Primjeri|Primeri|Piemēri|Pavyzdžiai|Paraugs|Juhtumid|Exemplos|Exemples|Exemplele|Exempel|Examples|Esempi|Enghreifftiau|Ekzemploj|Eksempler|Ejemplos|EXAMPLZ|Dữ liệu|Contoh|Cobber|Beispiele)(:)(.*)$'
step_keywords = r'^(\s*)(하지만|조건|먼저|만일|만약|단|그리고|그러면|那麼|那么|而且|當|当|前提|假設|假如|但是|但し|並且|もし|ならば|ただし|しかし|かつ|و |متى |لكن |عندما |ثم |بفرض |اذاً |כאשר |וגם |בהינתן |אזי |אז |אבל |Якщо |Унда |То |Припустимо, що |Припустимо |Онда |Но |Нехай |Лекин |Когато |Када |Кад |К тому же |И |Задато |Задати |Задате |Если |Допустим |Дадено |Ва |Бирок |Аммо |Али |Але |Агар |А |І |Și |És |Zatati |Zakładając |Zadato |Zadate |Zadano |Zadani |Zadan |Youse know when youse got |Youse know like when |Yna |Ya know how |Ya gotta |Y |Wun |Wtedy |When y\'all |When |Wenn |WEN |Và |Ve |Und |Un |Thì |Then y\'all |Then |Tapi |Tak |Tada |Tad |Så |Stel |Soit |Siis |Si |Sed |Se |Quando |Quand |Quan |Pryd |Pokud |Pokiaľ |Però |Pero |Pak |Oraz |Onda |Ond |Oletetaan |Og |Och |O zaman |Når |När |Niin |Nhưng |N |Mutta |Men |Mas |Maka |Majd |Mais |Maar |Ma |Lorsque |Lorsqu\'|Kun |Kuid |Kui |Khi |Keď |Ketika |Když |Kaj |Kai |Kada |Kad |Jeżeli |Ja |Ir |I CAN HAZ |I |Ha |Givun |Givet |Given y\'all |Given |Gitt |Gegeven |Gegeben sei |Fakat |Eğer ki |Etant donné |Et |Então |Entonces |Entao |En |Eeldades |E |Duota |Dun |Donitaĵo |Donat |Donada |Do |Diyelim ki |Dengan |Den youse gotta |De |Dato |Dar |Dann |Dan |Dado |Dacă |Daca |DEN |Când |Cuando |Cho |Cept |Cand |Cal |But y\'all |But |Buh |Biết |Bet |BUT |Atès |Atunci |Atesa |Anrhegedig a |Angenommen |And y\'all |And |An |Ama |Als |Alors |Allora |Ali |Aleshores |Ale |Akkor |Aber |AN |A také |A |\* )'
tokens = {
'comments': [
(r'#.*$', Comment),
],
'feature_elements' : [
(step_keywords, Keyword, "step_content_stack"),
include('comments'),
(r"(\s|.)", Name.Function),
],
'feature_elements_on_stack' : [
(step_keywords, Keyword, "#pop:2"),
include('comments'),
(r"(\s|.)", Name.Function),
],
'examples_table': [
(r"\s+\|", Keyword, 'examples_table_header'),
include('comments'),
(r"(\s|.)", Name.Function),
],
'examples_table_header': [
(r"\s+\|\s*$", Keyword, "#pop:2"),
include('comments'),
(r"\s*\|", Keyword),
(r"[^\|]", Name.Variable),
],
'scenario_sections_on_stack': [
(feature_element_keywords, bygroups(Name.Function, Keyword, Keyword, Name.Function), "feature_elements_on_stack"),
],
'narrative': [
include('scenario_sections_on_stack'),
(r"(\s|.)", Name.Function),
],
'table_vars': [
(r'(<[^>]+>)', Name.Variable),
],
'numbers': [
(r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', String),
],
'string': [
include('table_vars'),
(r'(\s|.)', String),
],
'py_string': [
(r'"""', Keyword, "#pop"),
include('string'),
],
'step_content_root':[
(r"$", Keyword, "#pop"),
include('step_content'),
],
'step_content_stack':[
(r"$", Keyword, "#pop:2"),
include('step_content'),
],
'step_content':[
(r'"', Name.Function, "double_string"),
include('table_vars'),
include('numbers'),
include('comments'),
(r'(\s|.)', Name.Function),
],
'table_content': [
(r"\s+\|\s*$", Keyword, "#pop"),
include('comments'),
(r"\s*\|", Keyword),
include('string'),
],
'double_string': [
(r'"', Name.Function, "#pop"),
include('string'),
],
'root': [
(r'\n', Name.Function),
include('comments'),
(r'"""', Keyword, "py_string"),
(r'\s+\|', Keyword, 'table_content'),
(r'"', Name.Function, "double_string"),
include('table_vars'),
include('numbers'),
(r'(\s*)(@[^@\r\n\t ]+)', bygroups(Name.Function, Name.Tag)),
(step_keywords, bygroups(Name.Function, Keyword),
'step_content_root'),
(feature_keywords, bygroups(Keyword, Keyword, Name.Function),
'narrative'),
(feature_element_keywords,
bygroups(Name.Function, Keyword, Keyword, Name.Function),
'feature_elements'),
(examples_keywords,
bygroups(Name.Function, Keyword, Keyword, Name.Function),
'examples_table'),
(r'(\s|.)', Name.Function),
]
}
class AsymptoteLexer(RegexLexer):
"""
For `Asymptote <http://asymptote.sf.net/>`_ source code.
*New in Pygments 1.2.*
"""
name = 'Asymptote'
aliases = ['asy', 'asymptote']
filenames = ['*.asy']
mimetypes = ['text/x-asymptote']
#: optional Comment or Whitespace
_ws = r'(?:\s|//.*?\n|/\*.*?\*/)+'
tokens = {
'whitespace': [
(r'\n', Text),
(r'\s+', Text),
(r'\\\n', Text), # line continuation
(r'//(\n|(.|\n)*?[^\\]\n)', Comment),
(r'/(\\\n)?\*(.|\n)*?\*(\\\n)?/', Comment),
],
'statements': [
# simple string (TeX friendly)
(r'"(\\\\|\\"|[^"])*"', String),
# C style string (with character escapes)
(r"'", String, 'string'),
(r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
(r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
(r'0x[0-9a-fA-F]+[Ll]?', Number.Hex),
(r'0[0-7]+[Ll]?', Number.Oct),
(r'\d+[Ll]?', Number.Integer),
(r'[~!%^&*+=|?:<>/-]', Operator),
(r'[()\[\],.]', Punctuation),
(r'\b(case)(.+?)(:)', bygroups(Keyword, using(this), Text)),
(r'(and|controls|tension|atleast|curl|if|else|while|for|do|'
r'return|break|continue|struct|typedef|new|access|import|'
r'unravel|from|include|quote|static|public|private|restricted|'
r'this|explicit|true|false|null|cycle|newframe|operator)\b', Keyword),
# Since an asy-type-name can be also an asy-function-name,
# in the following we test if the string " [a-zA-Z]" follows
# the Keyword.Type.
# Of course it is not perfect !
(r'(Braid|FitResult|Label|Legend|TreeNode|abscissa|arc|arrowhead|'
r'binarytree|binarytreeNode|block|bool|bool3|bounds|bqe|circle|'
r'conic|coord|coordsys|cputime|ellipse|file|filltype|frame|grid3|'
r'guide|horner|hsv|hyperbola|indexedTransform|int|inversion|key|'
r'light|line|linefit|marginT|marker|mass|object|pair|parabola|path|'
r'path3|pen|picture|point|position|projection|real|revolution|'
r'scaleT|scientific|segment|side|slice|splitface|string|surface|'
r'tensionSpecifier|ticklocate|ticksgridT|tickvalues|transform|'
r'transformation|tree|triangle|trilinear|triple|vector|'
r'vertex|void)(?=([ ]{1,}[a-zA-Z]))', Keyword.Type),
# Now the asy-type-name which are not asy-function-name
# except yours !
# Perhaps useless
(r'(Braid|FitResult|TreeNode|abscissa|arrowhead|block|bool|bool3|'
r'bounds|coord|frame|guide|horner|int|linefit|marginT|pair|pen|'
r'picture|position|real|revolution|slice|splitface|ticksgridT|'
r'tickvalues|tree|triple|vertex|void)\b', Keyword.Type),
('[a-zA-Z_][a-zA-Z0-9_]*:(?!:)', Name.Label),
('[a-zA-Z_][a-zA-Z0-9_]*', Name),
],
'root': [
include('whitespace'),
# functions
(r'((?:[a-zA-Z0-9_*\s])+?(?:\s|\*))' # return arguments
r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name
r'(\s*\([^;]*?\))' # signature
r'(' + _ws + r')({)',
bygroups(using(this), Name.Function, using(this), using(this),
Punctuation),
'function'),
# function declarations
(r'((?:[a-zA-Z0-9_*\s])+?(?:\s|\*))' # return arguments
r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name
r'(\s*\([^;]*?\))' # signature
r'(' + _ws + r')(;)',
bygroups(using(this), Name.Function, using(this), using(this),
Punctuation)),
('', Text, 'statement'),
],
'statement' : [
include('whitespace'),
include('statements'),
('[{}]', Punctuation),
(';', Punctuation, '#pop'),
],
'function': [
include('whitespace'),
include('statements'),
(';', Punctuation),
('{', Punctuation, '#push'),
('}', Punctuation, '#pop'),
],
'string': [
(r"'", String, '#pop'),
(r'\\([\\abfnrtv"\'?]|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
(r'\n', String),
(r"[^\\'\n]+", String), # all other characters
(r'\\\n', String),
(r'\\n', String), # line continuation
(r'\\', String), # stray backslash
]
}
def get_tokens_unprocessed(self, text):
from pygments.lexers._asybuiltins import ASYFUNCNAME, ASYVARNAME
for index, token, value in \
RegexLexer.get_tokens_unprocessed(self, text):
if token is Name and value in ASYFUNCNAME:
token = Name.Function
elif token is Name and value in ASYVARNAME:
token = Name.Variable
yield index, token, value
class PostScriptLexer(RegexLexer):
"""
Lexer for PostScript files.
The PostScript Language Reference published by Adobe at
<http://partners.adobe.com/public/developer/en/ps/PLRM.pdf>
is the authority for this.
*New in Pygments 1.4.*
"""
name = 'PostScript'
aliases = ['postscript', 'postscr']
filenames = ['*.ps', '*.eps']
mimetypes = ['application/postscript']
delimiter = r'\(\)\<\>\[\]\{\}\/\%\s'
delimiter_end = r'(?=[%s])' % delimiter
valid_name_chars = r'[^%s]' % delimiter
valid_name = r"%s+%s" % (valid_name_chars, delimiter_end)
tokens = {
'root': [
# All comment types
(r'^%!.+\n', Comment.Preproc),
(r'%%.*\n', Comment.Special),
(r'(^%.*\n){2,}', Comment.Multiline),
(r'%.*\n', Comment.Single),
# String literals are awkward; enter separate state.
(r'\(', String, 'stringliteral'),
(r'[\{\}(\<\<)(\>\>)\[\]]', Punctuation),
# Numbers
(r'<[0-9A-Fa-f]+>' + delimiter_end, Number.Hex),
# Slight abuse: use Oct to signify any explicit base system
(r'[0-9]+\#(\-|\+)?([0-9]+\.?|[0-9]*\.[0-9]+|[0-9]+\.[0-9]*)'
r'((e|E)[0-9]+)?' + delimiter_end, Number.Oct),
(r'(\-|\+)?([0-9]+\.?|[0-9]*\.[0-9]+|[0-9]+\.[0-9]*)((e|E)[0-9]+)?'
+ delimiter_end, Number.Float),
(r'(\-|\+)?[0-9]+' + delimiter_end, Number.Integer),
# References
(r'\/%s' % valid_name, Name.Variable),
# Names
(valid_name, Name.Function), # Anything else is executed
# These keywords taken from
# <http://www.math.ubc.ca/~cass/graphics/manual/pdf/a1.pdf>
# Is there an authoritative list anywhere that doesn't involve
# trawling documentation?
(r'(false|true)' + delimiter_end, Keyword.Constant),
# Conditionals / flow control
(r'(eq|ne|ge|gt|le|lt|and|or|not|if|ifelse|for|forall)'
+ delimiter_end, Keyword.Reserved),
('(abs|add|aload|arc|arcn|array|atan|begin|bind|ceiling|charpath|'
'clip|closepath|concat|concatmatrix|copy|cos|currentlinewidth|'
'currentmatrix|currentpoint|curveto|cvi|cvs|def|defaultmatrix|'
'dict|dictstackoverflow|div|dtransform|dup|end|exch|exec|exit|exp|'
'fill|findfont|floor|get|getinterval|grestore|gsave|gt|'
'identmatrix|idiv|idtransform|index|invertmatrix|itransform|'
'length|lineto|ln|load|log|loop|matrix|mod|moveto|mul|neg|newpath|'
'pathforall|pathbbox|pop|print|pstack|put|quit|rand|rangecheck|'
'rcurveto|repeat|restore|rlineto|rmoveto|roll|rotate|round|run|'
'save|scale|scalefont|setdash|setfont|setgray|setlinecap|'
'setlinejoin|setlinewidth|setmatrix|setrgbcolor|shfill|show|'
'showpage|sin|sqrt|stack|stringwidth|stroke|strokepath|sub|'
'syntaxerror|transform|translate|truncate|typecheck|undefined|'
'undefinedfilename|undefinedresult)' + delimiter_end,
Name.Builtin),
(r'\s+', Text),
],
'stringliteral': [
(r'[^\(\)\\]+', String),
(r'\\', String.Escape, 'escape'),
(r'\(', String, '#push'),
(r'\)', String, '#pop'),
],
'escape': [
(r'([0-8]{3}|n|r|t|b|f|\\|\(|\))?', String.Escape, '#pop'),
],
}
class AutohotkeyLexer(RegexLexer):
"""
For `autohotkey <http://www.autohotkey.com/>`_ source code.
*New in Pygments 1.4.*
"""
name = 'autohotkey'
aliases = ['ahk', 'autohotkey']
filenames = ['*.ahk', '*.ahkl']
mimetypes = ['text/x-autohotkey']
tokens = {
'root': [
(r'^(\s*)(/\*)', bygroups(Text, Comment.Multiline),
'incomment'),
(r'^(\s*)(\()', bygroups(Text, Generic), 'incontinuation'),
(r'\s+;.*?$', Comment.Singleline),
(r'^;.*?$', Comment.Singleline),
(r'[]{}(),;[]', Punctuation),
(r'(in|is|and|or|not)\b', Operator.Word),
(r'\%[a-zA-Z_#@$][a-zA-Z0-9_#@$]*\%', Name.Variable),
(r'!=|==|:=|\.=|<<|>>|[-~+/*%=<>&^|?:!.]', Operator),
include('commands'),
include('labels'),
include('builtInFunctions'),
include('builtInVariables'),
(r'"', String, combined('stringescape', 'dqs')),
include('numbers'),
(r'[a-zA-Z_#@$][a-zA-Z0-9_#@$]*', Name),
(r'\\|\'', Text),
(r'\`([\,\%\`abfnrtv\-\+;])', String.Escape),
include('garbage'),
],
'incomment': [
(r'^\s*\*/', Comment.Multiline, '#pop'),
(r'[^*/]', Comment.Multiline),
(r'[*/]', Comment.Multiline)
],
'incontinuation': [
(r'^\s*\)', Generic, '#pop'),
(r'[^)]', Generic),
(r'[)]', Generic),
],
'commands': [
(r'(?i)^(\s*)(global|local|static|'
r'#AllowSameLineComments|#ClipboardTimeout|#CommentFlag|'
r'#ErrorStdOut|#EscapeChar|#HotkeyInterval|#HotkeyModifierTimeout|'
r'#Hotstring|#IfWinActive|#IfWinExist|#IfWinNotActive|'
r'#IfWinNotExist|#IncludeAgain|#Include|#InstallKeybdHook|'
r'#InstallMouseHook|#KeyHistory|#LTrim|#MaxHotkeysPerInterval|'
r'#MaxMem|#MaxThreads|#MaxThreadsBuffer|#MaxThreadsPerHotkey|'
r'#NoEnv|#NoTrayIcon|#Persistent|#SingleInstance|#UseHook|'
r'#WinActivateForce|AutoTrim|BlockInput|Break|Click|ClipWait|'
r'Continue|Control|ControlClick|ControlFocus|ControlGetFocus|'
r'ControlGetPos|ControlGetText|ControlGet|ControlMove|ControlSend|'
r'ControlSendRaw|ControlSetText|CoordMode|Critical|'
r'DetectHiddenText|DetectHiddenWindows|Drive|DriveGet|'
r'DriveSpaceFree|Edit|Else|EnvAdd|EnvDiv|EnvGet|EnvMult|EnvSet|'
r'EnvSub|EnvUpdate|Exit|ExitApp|FileAppend|'
r'FileCopy|FileCopyDir|FileCreateDir|FileCreateShortcut|'
r'FileDelete|FileGetAttrib|FileGetShortcut|FileGetSize|'
r'FileGetTime|FileGetVersion|FileInstall|FileMove|FileMoveDir|'
r'FileRead|FileReadLine|FileRecycle|FileRecycleEmpty|'
r'FileRemoveDir|FileSelectFile|FileSelectFolder|FileSetAttrib|'
r'FileSetTime|FormatTime|GetKeyState|Gosub|Goto|GroupActivate|'
r'GroupAdd|GroupClose|GroupDeactivate|Gui|GuiControl|'
r'GuiControlGet|Hotkey|IfEqual|IfExist|IfGreaterOrEqual|IfGreater|'
r'IfInString|IfLess|IfLessOrEqual|IfMsgBox|IfNotEqual|IfNotExist|'
r'IfNotInString|IfWinActive|IfWinExist|IfWinNotActive|'
r'IfWinNotExist|If |ImageSearch|IniDelete|IniRead|IniWrite|'
r'InputBox|Input|KeyHistory|KeyWait|ListHotkeys|ListLines|'
r'ListVars|Loop|Menu|MouseClickDrag|MouseClick|MouseGetPos|'
r'MouseMove|MsgBox|OnExit|OutputDebug|Pause|PixelGetColor|'
r'PixelSearch|PostMessage|Process|Progress|Random|RegDelete|'
r'RegRead|RegWrite|Reload|Repeat|Return|RunAs|RunWait|Run|'
r'SendEvent|SendInput|SendMessage|SendMode|SendPlay|SendRaw|Send|'
r'SetBatchLines|SetCapslockState|SetControlDelay|'
r'SetDefaultMouseSpeed|SetEnv|SetFormat|SetKeyDelay|'
r'SetMouseDelay|SetNumlockState|SetScrollLockState|'
r'SetStoreCapslockMode|SetTimer|SetTitleMatchMode|'
r'SetWinDelay|SetWorkingDir|Shutdown|Sleep|Sort|SoundBeep|'
r'SoundGet|SoundGetWaveVolume|SoundPlay|SoundSet|'
r'SoundSetWaveVolume|SplashImage|SplashTextOff|SplashTextOn|'
r'SplitPath|StatusBarGetText|StatusBarWait|StringCaseSense|'
r'StringGetPos|StringLeft|StringLen|StringLower|StringMid|'
r'StringReplace|StringRight|StringSplit|StringTrimLeft|'
r'StringTrimRight|StringUpper|Suspend|SysGet|Thread|ToolTip|'
r'Transform|TrayTip|URLDownloadToFile|While|WinActivate|'
r'WinActivateBottom|WinClose|WinGetActiveStats|WinGetActiveTitle|'
r'WinGetClass|WinGetPos|WinGetText|WinGetTitle|WinGet|WinHide|'
r'WinKill|WinMaximize|WinMenuSelectItem|WinMinimizeAllUndo|'
r'WinMinimizeAll|WinMinimize|WinMove|WinRestore|WinSetTitle|'
r'WinSet|WinShow|WinWaitActive|WinWaitClose|WinWaitNotActive|'
r'WinWait)\b', bygroups(Text, Name.Builtin)),
],
'builtInFunctions': [
(r'(?i)(Abs|ACos|Asc|ASin|ATan|Ceil|Chr|Cos|DllCall|Exp|FileExist|'
r'Floor|GetKeyState|IL_Add|IL_Create|IL_Destroy|InStr|IsFunc|'
r'IsLabel|Ln|Log|LV_Add|LV_Delete|LV_DeleteCol|LV_GetCount|'
r'LV_GetNext|LV_GetText|LV_Insert|LV_InsertCol|LV_Modify|'
r'LV_ModifyCol|LV_SetImageList|Mod|NumGet|NumPut|OnMessage|'
r'RegExMatch|RegExReplace|RegisterCallback|Round|SB_SetIcon|'
r'SB_SetParts|SB_SetText|Sin|Sqrt|StrLen|SubStr|Tan|TV_Add|'
r'TV_Delete|TV_GetChild|TV_GetCount|TV_GetNext|TV_Get|'
r'TV_GetParent|TV_GetPrev|TV_GetSelection|TV_GetText|TV_Modify|'
r'VarSetCapacity|WinActive|WinExist|Object|ComObjActive|'
r'ComObjArray|ComObjEnwrap|ComObjUnwrap|ComObjParameter|'
r'ComObjType|ComObjConnect|ComObjCreate|ComObjGet|ComObjError|'
r'ComObjValue|Insert|MinIndex|MaxIndex|Remove|SetCapacity|'
r'GetCapacity|GetAddress|_NewEnum|FileOpen|Read|Write|ReadLine|'
r'WriteLine|ReadNumType|WriteNumType|RawRead|RawWrite|Seek|Tell|'
r'Close|Next|IsObject|StrPut|StrGet|Trim|LTrim|RTrim)\b',
Name.Function),
],
'builtInVariables': [
(r'(?i)(A_AhkPath|A_AhkVersion|A_AppData|A_AppDataCommon|'
r'A_AutoTrim|A_BatchLines|A_CaretX|A_CaretY|A_ComputerName|'
r'A_ControlDelay|A_Cursor|A_DDDD|A_DDD|A_DD|A_DefaultMouseSpeed|'
r'A_Desktop|A_DesktopCommon|A_DetectHiddenText|'
r'A_DetectHiddenWindows|A_EndChar|A_EventInfo|A_ExitReason|'
r'A_FormatFloat|A_FormatInteger|A_Gui|A_GuiEvent|A_GuiControl|'
r'A_GuiControlEvent|A_GuiHeight|A_GuiWidth|A_GuiX|A_GuiY|A_Hour|'
r'A_IconFile|A_IconHidden|A_IconNumber|A_IconTip|A_Index|'
r'A_IPAddress1|A_IPAddress2|A_IPAddress3|A_IPAddress4|A_ISAdmin|'
r'A_IsCompiled|A_IsCritical|A_IsPaused|A_IsSuspended|A_KeyDelay|'
r'A_Language|A_LastError|A_LineFile|A_LineNumber|A_LoopField|'
r'A_LoopFileAttrib|A_LoopFileDir|A_LoopFileExt|A_LoopFileFullPath|'
r'A_LoopFileLongPath|A_LoopFileName|A_LoopFileShortName|'
r'A_LoopFileShortPath|A_LoopFileSize|A_LoopFileSizeKB|'
r'A_LoopFileSizeMB|A_LoopFileTimeAccessed|A_LoopFileTimeCreated|'
r'A_LoopFileTimeModified|A_LoopReadLine|A_LoopRegKey|'
r'A_LoopRegName|A_LoopRegSubkey|A_LoopRegTimeModified|'
r'A_LoopRegType|A_MDAY|A_Min|A_MM|A_MMM|A_MMMM|A_Mon|A_MouseDelay|'
r'A_MSec|A_MyDocuments|A_Now|A_NowUTC|A_NumBatchLines|A_OSType|'
r'A_OSVersion|A_PriorHotkey|A_ProgramFiles|A_Programs|'
r'A_ProgramsCommon|A_ScreenHeight|A_ScreenWidth|A_ScriptDir|'
r'A_ScriptFullPath|A_ScriptName|A_Sec|A_Space|A_StartMenu|'
r'A_StartMenuCommon|A_Startup|A_StartupCommon|A_StringCaseSense|'
r'A_Tab|A_Temp|A_ThisFunc|A_ThisHotkey|A_ThisLabel|A_ThisMenu|'
r'A_ThisMenuItem|A_ThisMenuItemPos|A_TickCount|A_TimeIdle|'
r'A_TimeIdlePhysical|A_TimeSincePriorHotkey|A_TimeSinceThisHotkey|'
r'A_TitleMatchMode|A_TitleMatchModeSpeed|A_UserName|A_WDay|'
r'A_WinDelay|A_WinDir|A_WorkingDir|A_YDay|A_YEAR|A_YWeek|A_YYYY|'
r'Clipboard|ClipboardAll|ComSpec|ErrorLevel|ProgramFiles|True|'
r'False|A_IsUnicode|A_FileEncoding|A_OSVersion|A_PtrSize)\b',
Name.Variable),
],
'labels': [
# hotkeys and labels
# technically, hotkey names are limited to named keys and buttons
(r'(^\s*)([^:\s\(\"]+?:{1,2})', bygroups(Text, Name.Label)),
(r'(^\s*)(::[^:\s]+?::)', bygroups(Text, Name.Label)),
],
'numbers': [
(r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
(r'\d+[eE][+-]?[0-9]+', Number.Float),
(r'0\d+', Number.Oct),
(r'0[xX][a-fA-F0-9]+', Number.Hex),
(r'\d+L', Number.Integer.Long),
(r'\d+', Number.Integer)
],
'stringescape': [
(r'\"\"|\`([\,\%\`abfnrtv])', String.Escape),
],
'strings': [
(r'[^"\n]+', String),
],
'dqs': [
(r'"', String, '#pop'),
include('strings')
],
'garbage': [
(r'[^\S\n]', Text),
# (r'.', Text), # no cheating
],
}
class MaqlLexer(RegexLexer):
"""
Lexer for `GoodData MAQL
<https://secure.gooddata.com/docs/html/advanced.metric.tutorial.html>`_
scripts.
*New in Pygments 1.4.*
"""
name = 'MAQL'
aliases = ['maql']
filenames = ['*.maql']
mimetypes = ['text/x-gooddata-maql','application/x-gooddata-maql']
flags = re.IGNORECASE
tokens = {
'root': [
# IDENTITY
(r'IDENTIFIER\b', Name.Builtin),
# IDENTIFIER
(r'\{[^}]+\}', Name.Variable),
# NUMBER
(r'[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]{1,3})?', Literal.Number),
# STRING
(r'"', Literal.String, 'string-literal'),
# RELATION
(r'\<\>|\!\=', Operator),
(r'\=|\>\=|\>|\<\=|\<', Operator),
# :=
(r'\:\=', Operator),
# OBJECT
(r'\[[^]]+\]', Name.Variable.Class),
# keywords
(r'(DIMENSIONS?|BOTTOM|METRIC|COUNT|OTHER|FACT|WITH|TOP|OR|'
r'ATTRIBUTE|CREATE|PARENT|FALSE|ROWS?|FROM|ALL|AS|PF|'
r'COLUMNS?|DEFINE|REPORT|LIMIT|TABLE|LIKE|AND|BY|'
r'BETWEEN|EXCEPT|SELECT|MATCH|WHERE|TRUE|FOR|IN|'
r'WITHOUT|FILTER|ALIAS|ORDER|FACT|WHEN|NOT|ON|'
r'KEYS|KEY|FULLSET|PRIMARY|LABELS|LABEL|VISUAL|'
r'TITLE|DESCRIPTION|FOLDER|ALTER|DROP|ADD|DATASET|'
r'DATATYPE|INT|BIGINT|DOUBLE|DATE|VARCHAR|DECIMAL|'
r'SYNCHRONIZE|TYPE|DEFAULT|ORDER|ASC|DESC|HYPERLINK|'
r'INCLUDE|TEMPLATE|MODIFY)\b', Keyword),
# FUNCNAME
(r'[a-zA-Z]\w*\b', Name.Function),
# Comments
(r'#.*', Comment.Single),
# Punctuation
(r'[,;\(\)]', Token.Punctuation),
# Space is not significant
(r'\s+', Text)
],
'string-literal': [
(r'\\[tnrfbae"\\]', String.Escape),
(r'"', Literal.String, '#pop'),
(r'[^\\"]+', Literal.String)
],
}
class GoodDataCLLexer(RegexLexer):
"""
Lexer for `GoodData-CL <http://github.com/gooddata/GoodData-CL/raw/master/cli/src/main/resources/com/gooddata/processor/COMMANDS.txt>`_
script files.
*New in Pygments 1.4.*
"""
name = 'GoodData-CL'
aliases = ['gooddata-cl']
filenames = ['*.gdc']
mimetypes = ['text/x-gooddata-cl']
flags = re.IGNORECASE
tokens = {
'root': [
# Comments
(r'#.*', Comment.Single),
# Function call
(r'[a-zA-Z]\w*', Name.Function),
# Argument list
(r'\(', Token.Punctuation, 'args-list'),
# Punctuation
(r';', Token.Punctuation),
# Space is not significant
(r'\s+', Text)
],
'args-list': [
(r'\)', Token.Punctuation, '#pop'),
(r',', Token.Punctuation),
(r'[a-zA-Z]\w*', Name.Variable),
(r'=', Operator),
(r'"', Literal.String, 'string-literal'),
(r'[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]{1,3})?', Literal.Number),
# Space is not significant
(r'\s', Text)
],
'string-literal': [
(r'\\[tnrfbae"\\]', String.Escape),
(r'"', Literal.String, '#pop'),
(r'[^\\"]+', Literal.String)
]
}
class ProtoBufLexer(RegexLexer):
"""
Lexer for `Protocol Buffer <http://code.google.com/p/protobuf/>`_
definition files.
*New in Pygments 1.4.*
"""
name = 'Protocol Buffer'
aliases = ['protobuf', 'proto']
filenames = ['*.proto']
tokens = {
'root': [
(r'[ \t]+', Text),
(r'[,;{}\[\]\(\)]', Punctuation),
(r'/(\\\n)?/(\n|(.|\n)*?[^\\]\n)', Comment.Single),
(r'/(\\\n)?\*(.|\n)*?\*(\\\n)?/', Comment.Multiline),
(r'\b(import|option|optional|required|repeated|default|packed|'
r'ctype|extensions|to|max|rpc|returns)\b', Keyword),
(r'(int32|int64|uint32|uint64|sint32|sint64|'
r'fixed32|fixed64|sfixed32|sfixed64|'
r'float|double|bool|string|bytes)\b', Keyword.Type),
(r'(true|false)\b', Keyword.Constant),
(r'(package)(\s+)', bygroups(Keyword.Namespace, Text), 'package'),
(r'(message|extend)(\s+)',
bygroups(Keyword.Declaration, Text), 'message'),
(r'(enum|group|service)(\s+)',
bygroups(Keyword.Declaration, Text), 'type'),
(r'\".*\"', String),
(r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*', Number.Float),
(r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
(r'(\-?(inf|nan))', Number.Float),
(r'0x[0-9a-fA-F]+[LlUu]*', Number.Hex),
(r'0[0-7]+[LlUu]*', Number.Oct),
(r'\d+[LlUu]*', Number.Integer),
(r'[+-=]', Operator),
(r'([a-zA-Z_][a-zA-Z0-9_\.]*)([ \t]*)(=)',
bygroups(Name.Attribute, Text, Operator)),
('[a-zA-Z_][a-zA-Z0-9_\.]*', Name),
],
'package': [
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Namespace, '#pop')
],
'message': [
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')
],
'type': [
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name, '#pop')
],
}
class HybrisLexer(RegexLexer):
"""
For `Hybris <http://www.hybris-lang.org>`_ source code.
*New in Pygments 1.4.*
"""
name = 'Hybris'
aliases = ['hybris', 'hy']
filenames = ['*.hy', '*.hyb']
mimetypes = ['text/x-hybris', 'application/x-hybris']
flags = re.MULTILINE | re.DOTALL
tokens = {
'root': [
# method names
(r'^(\s*(?:function|method|operator\s+)+?)'
r'([a-zA-Z_][a-zA-Z0-9_]*)'
r'(\s*)(\()', bygroups(Keyword, Name.Function, Text, Operator)),
(r'[^\S\n]+', Text),
(r'//.*?\n', Comment.Single),
(r'/\*.*?\*/', Comment.Multiline),
(r'@[a-zA-Z_][a-zA-Z0-9_\.]*', Name.Decorator),
(r'(break|case|catch|next|default|do|else|finally|for|foreach|of|'
r'unless|if|new|return|switch|me|throw|try|while)\b', Keyword),
(r'(extends|private|protected|public|static|throws|function|method|'
r'operator)\b', Keyword.Declaration),
(r'(true|false|null|__FILE__|__LINE__|__VERSION__|__LIB_PATH__|'
r'__INC_PATH__)\b', Keyword.Constant),
(r'(class|struct)(\s+)',
bygroups(Keyword.Declaration, Text), 'class'),
(r'(import|include)(\s+)',
bygroups(Keyword.Namespace, Text), 'import'),
(r'(gc_collect|gc_mm_items|gc_mm_usage|gc_collect_threshold|'
r'urlencode|urldecode|base64encode|base64decode|sha1|crc32|sha2|'
r'md5|md5_file|acos|asin|atan|atan2|ceil|cos|cosh|exp|fabs|floor|'
r'fmod|log|log10|pow|sin|sinh|sqrt|tan|tanh|isint|isfloat|ischar|'
r'isstring|isarray|ismap|isalias|typeof|sizeof|toint|tostring|'
r'fromxml|toxml|binary|pack|load|eval|var_names|var_values|'
r'user_functions|dyn_functions|methods|call|call_method|mknod|'
r'mkfifo|mount|umount2|umount|ticks|usleep|sleep|time|strtime|'
r'strdate|dllopen|dlllink|dllcall|dllcall_argv|dllclose|env|exec|'
r'fork|getpid|wait|popen|pclose|exit|kill|pthread_create|'
r'pthread_create_argv|pthread_exit|pthread_join|pthread_kill|'
r'smtp_send|http_get|http_post|http_download|socket|bind|listen|'
r'accept|getsockname|getpeername|settimeout|connect|server|recv|'
r'send|close|print|println|printf|input|readline|serial_open|'
r'serial_fcntl|serial_get_attr|serial_get_ispeed|serial_get_ospeed|'
r'serial_set_attr|serial_set_ispeed|serial_set_ospeed|serial_write|'
r'serial_read|serial_close|xml_load|xml_parse|fopen|fseek|ftell|'
r'fsize|fread|fwrite|fgets|fclose|file|readdir|pcre_replace|size|'
r'pop|unmap|has|keys|values|length|find|substr|replace|split|trim|'
r'remove|contains|join)\b', Name.Builtin),
(r'(MethodReference|Runner|Dll|Thread|Pipe|Process|Runnable|'
r'CGI|ClientSocket|Socket|ServerSocket|File|Console|Directory|'
r'Exception)\b', Keyword.Type),
(r'"(\\\\|\\"|[^"])*"', String),
(r"'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'", String.Char),
(r'(\.)([a-zA-Z_][a-zA-Z0-9_]*)',
bygroups(Operator, Name.Attribute)),
(r'[a-zA-Z_][a-zA-Z0-9_]*:', Name.Label),
(r'[a-zA-Z_\$][a-zA-Z0-9_]*', Name),
(r'[~\^\*!%&\[\]\(\)\{\}<>\|+=:;,./?\-@]+', Operator),
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
(r'0x[0-9a-f]+', Number.Hex),
(r'[0-9]+L?', Number.Integer),
(r'\n', Text),
],
'class': [
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')
],
'import': [
(r'[a-zA-Z0-9_.]+\*?', Name.Namespace, '#pop')
],
}
class AwkLexer(RegexLexer):
"""
For Awk scripts.
*New in Pygments 1.5.*
"""
name = 'Awk'
aliases = ['awk', 'gawk', 'mawk', 'nawk']
filenames = ['*.awk']
mimetypes = ['application/x-awk']
tokens = {
'commentsandwhitespace': [
(r'\s+', Text),
(r'#.*$', Comment.Single)
],
'slashstartsregex': [
include('commentsandwhitespace'),
(r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
r'\B', String.Regex, '#pop'),
(r'(?=/)', Text, ('#pop', 'badregex')),
(r'', Text, '#pop')
],
'badregex': [
(r'\n', Text, '#pop')
],
'root': [
(r'^(?=\s|/)', Text, 'slashstartsregex'),
include('commentsandwhitespace'),
(r'\+\+|--|\|\||&&|in|\$|!?~|'
r'(\*\*|[-<>+*%\^/!=])=?', Operator, 'slashstartsregex'),
(r'[{(\[;,]', Punctuation, 'slashstartsregex'),
(r'[})\].]', Punctuation),
(r'(break|continue|do|while|exit|for|if|'
r'return)\b', Keyword, 'slashstartsregex'),
(r'function\b', Keyword.Declaration, 'slashstartsregex'),
(r'(atan2|cos|exp|int|log|rand|sin|sqrt|srand|gensub|gsub|index|'
r'length|match|split|sprintf|sub|substr|tolower|toupper|close|'
r'fflush|getline|next|nextfile|print|printf|strftime|systime|'
r'delete|system)\b', Keyword.Reserved),
(r'(ARGC|ARGIND|ARGV|CONVFMT|ENVIRON|ERRNO|FIELDWIDTHS|FILENAME|FNR|FS|'
r'IGNORECASE|NF|NR|OFMT|OFS|ORFS|RLENGTH|RS|RSTART|RT|'
r'SUBSEP)\b', Name.Builtin),
(r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other),
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
(r'0x[0-9a-fA-F]+', Number.Hex),
(r'[0-9]+', Number.Integer),
(r'"(\\\\|\\"|[^"])*"', String.Double),
(r"'(\\\\|\\'|[^'])*'", String.Single),
]
}
class Cfengine3Lexer(RegexLexer):
"""
Lexer for `CFEngine3 <http://cfengine.org>`_ policy files.
*New in Pygments 1.5.*
"""
name = 'CFEngine3'
aliases = ['cfengine3', 'cf3']
filenames = ['*.cf']
mimetypes = []
tokens = {
'root': [
(r'#.*?\n', Comment),
(r'(body)(\s+)(\S+)(\s+)(control)',
bygroups(Keyword, Text, Keyword, Text, Keyword)),
(r'(body|bundle)(\s+)(\S+)(\s+)(\w+)(\()',
bygroups(Keyword, Text, Keyword, Text, Name.Function, Punctuation),
'arglist'),
(r'(body|bundle)(\s+)(\S+)(\s+)(\w+)',
bygroups(Keyword, Text, Keyword, Text, Name.Function)),
(r'(")([^"]+)(")(\s+)(string|slist|int|real)(\s*)(=>)(\s*)',
bygroups(Punctuation,Name.Variable,Punctuation,
Text,Keyword.Type,Text,Operator,Text)),
(r'(\S+)(\s*)(=>)(\s*)',
bygroups(Keyword.Reserved,Text,Operator,Text)),
(r'"', String, 'string'),
(r'(\w+)(\()', bygroups(Name.Function, Punctuation)),
(r'([\w.!&|\(\)]+)(::)', bygroups(Name.Class, Punctuation)),
(r'(\w+)(:)', bygroups(Keyword.Declaration,Punctuation)),
(r'@[\{\(][^\)\}]+[\}\)]', Name.Variable),
(r'[(){},;]', Punctuation),
(r'=>', Operator),
(r'->', Operator),
(r'\d+\.\d+', Number.Float),
(r'\d+', Number.Integer),
(r'\w+', Name.Function),
(r'\s+', Text),
],
'string': [
(r'\$[\{\(]', String.Interpol, 'interpol'),
(r'\\.', String.Escape),
(r'"', String, '#pop'),
(r'\n', String),
(r'.', String),
],
'interpol': [
(r'\$[\{\(]', String.Interpol, '#push'),
(r'[\}\)]', String.Interpol, '#pop'),
(r'[^\$\{\(\)\}]+', String.Interpol),
],
'arglist': [
(r'\)', Punctuation, '#pop'),
(r',', Punctuation),
(r'\w+', Name.Variable),
(r'\s+', Text),
],
}
class SnobolLexer(RegexLexer):
"""
Lexer for the SNOBOL4 programming language.
Recognizes the common ASCII equivalents of the original SNOBOL4 operators.
Does not require spaces around binary operators.
*New in Pygments 1.5.*
"""
name = "Snobol"
aliases = ["snobol"]
filenames = ['*.snobol']
mimetypes = ['text/x-snobol']
tokens = {
# root state, start of line
# comments, continuation lines, and directives start in column 1
# as do labels
'root': [
(r'\*.*\n', Comment),
(r'[\+\.] ', Punctuation, 'statement'),
(r'-.*\n', Comment),
(r'END\s*\n', Name.Label, 'heredoc'),
(r'[A-Za-z\$][\w$]*', Name.Label, 'statement'),
(r'\s+', Text, 'statement'),
],
# statement state, line after continuation or label
'statement': [
(r'\s*\n', Text, '#pop'),
(r'\s+', Text),
(r'(?<=[^\w.])(LT|LE|EQ|NE|GE|GT|INTEGER|IDENT|DIFFER|LGT|SIZE|'
r'REPLACE|TRIM|DUPL|REMDR|DATE|TIME|EVAL|APPLY|OPSYN|LOAD|UNLOAD|'
r'LEN|SPAN|BREAK|ANY|NOTANY|TAB|RTAB|REM|POS|RPOS|FAIL|FENCE|'
r'ABORT|ARB|ARBNO|BAL|SUCCEED|INPUT|OUTPUT|TERMINAL)(?=[^\w.])',
Name.Builtin),
(r'[A-Za-z][\w\.]*', Name),
# ASCII equivalents of original operators
# | for the EBCDIC equivalent, ! likewise
# \ for EBCDIC negation
(r'\*\*|[\?\$\.!%\*/#+\-@\|&\\=]', Operator),
(r'"[^"]*"', String),
(r"'[^']*'", String),
# Accept SPITBOL syntax for real numbers
# as well as Macro SNOBOL4
(r'[0-9]+(?=[^\.EeDd])', Number.Integer),
(r'[0-9]+(\.[0-9]*)?([EDed][-+]?[0-9]+)?', Number.Float),
# Goto
(r':', Punctuation, 'goto'),
(r'[\(\)<>,;]', Punctuation),
],
# Goto block
'goto': [
(r'\s*\n', Text, "#pop:2"),
(r'\s+', Text),
(r'F|S', Keyword),
(r'(\()([A-Za-z][\w.]*)(\))',
bygroups(Punctuation, Name.Label, Punctuation))
],
# everything after the END statement is basically one
# big heredoc.
'heredoc': [
(r'.*\n', String.Heredoc)
]
}
class UrbiscriptLexer(ExtendedRegexLexer):
"""
For UrbiScript source code.
*New in Pygments 1.5.*
"""
name = 'UrbiScript'
aliases = ['urbiscript']
filenames = ['*.u']
mimetypes = ['application/x-urbiscript']
flags = re.DOTALL
## TODO
# - handle Experimental and deprecated tags with specific tokens
# - handle Angles and Durations with specific tokens
def blob_callback(lexer, match, ctx):
text_before_blob = match.group(1)
blob_start = match.group(2)
blob_size_str = match.group(3)
blob_size = int(blob_size_str)
yield match.start(), String, text_before_blob
ctx.pos += len(text_before_blob)
# if blob size doesn't match blob format (example : "\B(2)(aaa)")
# yield blob as a string
if ctx.text[match.end() + blob_size] != ")":
result = "\\B(" + blob_size_str + ")("
yield match.start(), String, result
ctx.pos += len(result)
return
# if blob is well formated, yield as Escape
blob_text = blob_start + ctx.text[match.end():match.end()+blob_size] + ")"
yield match.start(), String.Escape, blob_text
ctx.pos = match.end() + blob_size + 1 # +1 is the ending ")"
tokens = {
'root': [
(r'\s+', Text),
# comments
(r'//.*?\n', Comment),
(r'/\*', Comment.Multiline, 'comment'),
(r'(?:every|for|loop|while)(?:;|&|\||,)',Keyword),
(r'(?:assert|at|break|case|catch|closure|compl|continue|'
r'default|else|enum|every|external|finally|for|freezeif|if|new|'
r'onleave|return|stopif|switch|this|throw|timeout|try|'
r'waituntil|whenever|while)\b', Keyword),
(r'(?:asm|auto|bool|char|const_cast|delete|double|dynamic_cast|'
r'explicit|export|extern|float|friend|goto|inline|int|'
r'long|mutable|namespace|register|reinterpret_cast|short|'
r'signed|sizeof|static_cast|struct|template|typedef|typeid|'
r'typename|union|unsigned|using|virtual|volatile|'
r'wchar_t)\b', Keyword.Reserved),
# deprecated keywords, use a meaningfull token when available
(r'(?:emit|foreach|internal|loopn|static)\b', Keyword),
# ignored keywords, use a meaningfull token when available
(r'(?:private|protected|public)\b', Keyword),
(r'(?:var|do|const|function|class)\b', Keyword.Declaration),
(r'(?:true|false|nil|void)\b', Keyword.Constant),
(r'(?:Barrier|Binary|Boolean|CallMessage|Channel|Code|'
r'Comparable|Container|Control|Date|Dictionary|Directory|'
r'Duration|Enumeration|Event|Exception|Executable|File|Finalizable|'
r'Float|FormatInfo|Formatter|Global|Group|Hash|InputStream|'
r'IoService|Job|Kernel|Lazy|List|Loadable|Lobby|Location|Logger|Math|'
r'Mutex|nil|Object|Orderable|OutputStream|Pair|Path|Pattern|Position|'
r'Primitive|Process|Profile|PseudoLazy|PubSub|RangeIterable|Regexp|'
r'Semaphore|Server|Singleton|Socket|StackFrame|Stream|String|System|'
r'Tag|Timeout|Traceable|TrajectoryGenerator|Triplet|Tuple'
r'|UObject|UValue|UVar)\b', Name.Builtin),
(r'(?:this)\b', Name.Builtin.Pseudo),
# don't match single | and &
(r'(?:[-=+*%/<>~^:]+|\.&?|\|\||&&)', Operator),
(r'(?:and_eq|and|bitand|bitor|in|not|not_eq|or_eq|or|xor_eq|xor)\b',
Operator.Word),
(r'[{}\[\]()]+', Punctuation),
(r'(?:;|\||,|&|\?|!)+', Punctuation),
(r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other),
(r'0x[0-9a-fA-F]+', Number.Hex),
# Float, Integer, Angle and Duration
(r'(?:[0-9]+(?:(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?)?'
r'((?:rad|deg|grad)|(?:ms|s|min|h|d))?)\b', Number.Float),
# handle binary blob in strings
(r'"', String.Double, "string.double"),
(r"'", String.Single, "string.single"),
],
'string.double': [
(r'((?:\\\\|\\"|[^"])*?)(\\B\((\d+)\)\()', blob_callback),
(r'(\\\\|\\"|[^"])*?"', String.Double, '#pop'),
],
'string.single': [
(r"((?:\\\\|\\'|[^'])*?)(\\B\((\d+)\)\()", blob_callback),
(r"(\\\\|\\'|[^'])*?'", String.Single, '#pop'),
],
# from http://pygments.org/docs/lexerdevelopment/#changing-states
'comment': [
(r'[^*/]', Comment.Multiline),
(r'/\*', Comment.Multiline, '#push'),
(r'\*/', Comment.Multiline, '#pop'),
(r'[*/]', Comment.Multiline),
]
}
class OpenEdgeLexer(RegexLexer):
"""
Lexer for `OpenEdge ABL (formerly Progress)
<http://web.progress.com/en/openedge/abl.html>`_ source code.
*New in Pygments 1.5.*
"""
name = 'OpenEdge ABL'
aliases = ['openedge', 'abl', 'progress']
filenames = ['*.p', '*.cls']
mimetypes = ['text/x-openedge', 'application/x-openedge']
types = (r'(?i)(^|(?<=[^0-9a-z_\-]))(CHARACTER|CHAR|CHARA|CHARAC|CHARACT|CHARACTE|'
r'COM-HANDLE|DATE|DATETIME|DATETIME-TZ|'
r'DECIMAL|DEC|DECI|DECIM|DECIMA|HANDLE|'
r'INT64|INTEGER|INT|INTE|INTEG|INTEGE|'
r'LOGICAL|LONGCHAR|MEMPTR|RAW|RECID|ROWID)\s*($|(?=[^0-9a-z_\-]))')
keywords = (r'(?i)(^|(?<=[^0-9a-z_\-]))(' +
r'|'.join(OPENEDGEKEYWORDS) +
r')\s*($|(?=[^0-9a-z_\-]))')
tokens = {
'root': [
(r'/\*', Comment.Multiline, 'comment'),
(r'\{', Comment.Preproc, 'preprocessor'),
(r'\s*&.*', Comment.Preproc),
(r'0[xX][0-9a-fA-F]+[LlUu]*', Number.Hex),
(r'(?i)(DEFINE|DEF|DEFI|DEFIN)\b', Keyword.Declaration),
(types, Keyword.Type),
(keywords, Name.Builtin),
(r'"(\\\\|\\"|[^"])*"', String.Double),
(r"'(\\\\|\\'|[^'])*'", String.Single),
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
(r'[0-9]+', Number.Integer),
(r'\s+', Text),
(r'[+*/=-]', Operator),
(r'[.:()]', Punctuation),
(r'.', Name.Variable), # Lazy catch-all
],
'comment': [
(r'[^*/]', Comment.Multiline),
(r'/\*', Comment.Multiline, '#push'),
(r'\*/', Comment.Multiline, '#pop'),
(r'[*/]', Comment.Multiline)
],
'preprocessor': [
(r'[^{}]', Comment.Preproc),
(r'{', Comment.Preproc, '#push'),
(r'}', Comment.Preproc, '#pop'),
],
}
class BroLexer(RegexLexer):
"""
For `Bro <http://bro-ids.org/>`_ scripts.
*New in Pygments 1.5.*
"""
name = 'Bro'
aliases = ['bro']
filenames = ['*.bro']
_hex = r'[0-9a-fA-F_]+'
_float = r'((\d*\.?\d+)|(\d+\.?\d*))([eE][-+]?\d+)?'
_h = r'[A-Za-z0-9][-A-Za-z0-9]*'
tokens = {
'root': [
# Whitespace
(r'^@.*?\n', Comment.Preproc),
(r'#.*?\n', Comment.Single),
(r'\n', Text),
(r'\s+', Text),
(r'\\\n', Text),
# Keywords
(r'(add|alarm|break|case|const|continue|delete|do|else|enum|event'
r'|export|for|function|if|global|hook|local|module|next'
r'|of|print|redef|return|schedule|switch|type|when|while)\b', Keyword),
(r'(addr|any|bool|count|counter|double|file|int|interval|net'
r'|pattern|port|record|set|string|subnet|table|time|timer'
r'|vector)\b', Keyword.Type),
(r'(T|F)\b', Keyword.Constant),
(r'(&)((?:add|delete|expire)_func|attr|(?:create|read|write)_expire'
r'|default|disable_print_hook|raw_output|encrypt|group|log'
r'|mergeable|optional|persistent|priority|redef'
r'|rotate_(?:interval|size)|synchronized)\b', bygroups(Punctuation,
Keyword)),
(r'\s+module\b', Keyword.Namespace),
# Addresses, ports and networks
(r'\d+/(tcp|udp|icmp|unknown)\b', Number),
(r'(\d+\.){3}\d+', Number),
(r'(' + _hex + r'){7}' + _hex, Number),
(r'0x' + _hex + r'(' + _hex + r'|:)*::(' + _hex + r'|:)*', Number),
(r'((\d+|:)(' + _hex + r'|:)*)?::(' + _hex + r'|:)*', Number),
(r'(\d+\.\d+\.|(\d+\.){2}\d+)', Number),
# Hostnames
(_h + r'(\.' + _h + r')+', String),
# Numeric
(_float + r'\s+(day|hr|min|sec|msec|usec)s?\b', Literal.Date),
(r'0[xX]' + _hex, Number.Hex),
(_float, Number.Float),
(r'\d+', Number.Integer),
(r'/', String.Regex, 'regex'),
(r'"', String, 'string'),
# Operators
(r'[!%*/+:<=>?~|-]', Operator),
(r'([-+=&|]{2}|[+=!><-]=)', Operator),
(r'(in|match)\b', Operator.Word),
(r'[{}()\[\]$.,;]', Punctuation),
# Identfier
(r'([_a-zA-Z]\w*)(::)', bygroups(Name, Name.Namespace)),
(r'[a-zA-Z_][a-zA-Z_0-9]*', Name)
],
'string': [
(r'"', String, '#pop'),
(r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
(r'[^\\"\n]+', String),
(r'\\\n', String),
(r'\\', String)
],
'regex': [
(r'/', String.Regex, '#pop'),
(r'\\[\\nt/]', String.Regex), # String.Escape is too intense here.
(r'[^\\/\n]+', String.Regex),
(r'\\\n', String.Regex),
(r'\\', String.Regex)
]
}
class CbmBasicV2Lexer(RegexLexer):
"""
For CBM BASIC V2 sources.
*New in Pygments 1.6.*
"""
name = 'CBM BASIC V2'
aliases = ['cbmbas']
filenames = ['*.bas']
flags = re.IGNORECASE
tokens = {
'root': [
(r'rem.*\n', Comment.Single),
(r'\s+', Text),
(r'new|run|end|for|to|next|step|go(to|sub)?|on|return|stop|cont'
r'|if|then|input#?|read|wait|load|save|verify|poke|sys|print#?'
r'|list|clr|cmd|open|close|get#?', Keyword.Reserved),
(r'data|restore|dim|let|def|fn', Keyword.Declaration),
(r'tab|spc|sgn|int|abs|usr|fre|pos|sqr|rnd|log|exp|cos|sin|tan|atn'
r'|peek|len|val|asc|(str|chr|left|right|mid)\$', Name.Builtin),
(r'[-+*/^<>=]', Operator),
(r'not|and|or', Operator.Word),
(r'"[^"\n]*.', String),
(r'\d+|[-+]?\d*\.\d*(e[-+]?\d+)?', Number.Float),
(r'[\(\),:;]', Punctuation),
(r'\w+[$%]?', Name),
]
}
def analyse_text(self, text):
# if it starts with a line number, it shouldn't be a "modern" Basic
# like VB.net
if re.match(r'\d+', text):
return True
class MscgenLexer(RegexLexer):
"""
For `Mscgen <http://www.mcternan.me.uk/mscgen/>`_ files.
*New in Pygments 1.6.*
"""
name = 'Mscgen'
aliases = ['mscgen', 'msc']
filenames = ['*.msc']
_var = r'([a-zA-Z0-9_]+|"(?:\\"|[^"])*")'
tokens = {
'root': [
(r'msc\b', Keyword.Type),
# Options
(r'(hscale|HSCALE|width|WIDTH|wordwraparcs|WORDWRAPARCS'
r'|arcgradient|ARCGRADIENT)\b', Name.Property),
# Operators
(r'(abox|ABOX|rbox|RBOX|box|BOX|note|NOTE)\b', Operator.Word),
(r'(\.|-|\|){3}', Keyword),
(r'(?:-|=|\.|:){2}'
r'|<<=>>|<->|<=>|<<>>|<:>'
r'|->|=>>|>>|=>|:>|-x|-X'
r'|<-|<<=|<<|<=|<:|x-|X-|=', Operator),
# Names
(r'\*', Name.Builtin),
(_var, Name.Variable),
# Other
(r'\[', Punctuation, 'attrs'),
(r'\{|\}|,|;', Punctuation),
include('comments')
],
'attrs': [
(r'\]', Punctuation, '#pop'),
(_var + r'(\s*)(=)(\s*)' + _var,
bygroups(Name.Attribute, Text.Whitespace, Operator, Text.Whitespace,
String)),
(r',', Punctuation),
include('comments')
],
'comments': [
(r'(?://|#).*?\n', Comment.Single),
(r'/\*(?:.|\n)*?\*/', Comment.Multiline),
(r'[ \t\r\n]+', Text.Whitespace)
]
}
def _rx_indent(level):
# Kconfig *always* interprets a tab as 8 spaces, so this is the default.
# Edit this if you are in an environment where KconfigLexer gets expanded
# input (tabs expanded to spaces) and the expansion tab width is != 8,
# e.g. in connection with Trac (trac.ini, [mimeviewer], tab_width).
# Value range here is 2 <= {tab_width} <= 8.
tab_width = 8
# Regex matching a given indentation {level}, assuming that indentation is
# a multiple of {tab_width}. In other cases there might be problems.
return r'(?:\t| {1,%s}\t| {%s}){%s}.*\n' % (tab_width-1, tab_width, level)
class KconfigLexer(RegexLexer):
"""
For Linux-style Kconfig files.
*New in Pygments 1.6.*
"""
name = 'Kconfig'
aliases = ['kconfig', 'menuconfig', 'linux-config', 'kernel-config']
# Adjust this if new kconfig file names appear in your environment
filenames = ['Kconfig', '*Config.in*', 'external.in*',
'standard-modules.in']
mimetypes = ['text/x-kconfig']
# No re.MULTILINE, indentation-aware help text needs line-by-line handling
flags = 0
def call_indent(level):
# If indentation >= {level} is detected, enter state 'indent{level}'
return (_rx_indent(level), String.Doc, 'indent%s' % level)
def do_indent(level):
# Print paragraphs of indentation level >= {level} as String.Doc,
# ignoring blank lines. Then return to 'root' state.
return [
(_rx_indent(level), String.Doc),
(r'\s*\n', Text),
(r'', Generic, '#pop:2')
]
tokens = {
'root': [
(r'\s+', Text),
(r'#.*?\n', Comment.Single),
(r'(mainmenu|config|menuconfig|choice|endchoice|comment|menu|'
r'endmenu|visible if|if|endif|source|prompt|select|depends on|'
r'default|range|option)\b', Keyword),
(r'(---help---|help)[\t ]*\n', Keyword, 'help'),
(r'(bool|tristate|string|hex|int|defconfig_list|modules|env)\b',
Name.Builtin),
(r'[!=&|]', Operator),
(r'[()]', Punctuation),
(r'[0-9]+', Number.Integer),
(r"'(''|[^'])*'", String.Single),
(r'"(""|[^"])*"', String.Double),
(r'\S+', Text),
],
# Help text is indented, multi-line and ends when a lower indentation
# level is detected.
'help': [
# Skip blank lines after help token, if any
(r'\s*\n', Text),
# Determine the first help line's indentation level heuristically(!).
# Attention: this is not perfect, but works for 99% of "normal"
# indentation schemes up to a max. indentation level of 7.
call_indent(7),
call_indent(6),
call_indent(5),
call_indent(4),
call_indent(3),
call_indent(2),
call_indent(1),
('', Text, '#pop'), # for incomplete help sections without text
],
# Handle text for indentation levels 7 to 1
'indent7': do_indent(7),
'indent6': do_indent(6),
'indent5': do_indent(5),
'indent4': do_indent(4),
'indent3': do_indent(3),
'indent2': do_indent(2),
'indent1': do_indent(1),
}
class VGLLexer(RegexLexer):
"""
For `SampleManager VGL <http://www.thermoscientific.com/samplemanager>`_
source code.
*New in Pygments 1.6.*
"""
name = 'VGL'
aliases = ['vgl']
filenames = ['*.rpf']
flags = re.MULTILINE | re.DOTALL | re.IGNORECASE
tokens = {
'root': [
(r'\{[^\}]*\}', Comment.Multiline),
(r'declare', Keyword.Constant),
(r'(if|then|else|endif|while|do|endwhile|and|or|prompt|object'
r'|create|on|line|with|global|routine|value|endroutine|constant'
r'|global|set|join|library|compile_option|file|exists|create|copy'
r'|delete|enable|windows|name|notprotected)(?! *[=<>.,()])',
Keyword),
(r'(true|false|null|empty|error|locked)', Keyword.Constant),
(r'[~\^\*\#!%&\[\]\(\)<>\|+=:;,./?-]', Operator),
(r'"[^"]*"', String),
(r'(\.)([a-z_\$][a-z0-9_\$]*)', bygroups(Operator, Name.Attribute)),
(r'[0-9][0-9]*(\.[0-9]+(e[+\-]?[0-9]+)?)?', Number),
(r'[a-z_\$][a-z0-9_\$]*', Name),
(r'[\r\n]+', Text),
(r'\s+', Text)
]
}
class SourcePawnLexer(RegexLexer):
"""
For SourcePawn source code with preprocessor directives.
*New in Pygments 1.6.*
"""
name = 'SourcePawn'
aliases = ['sp']
filenames = ['*.sp']
mimetypes = ['text/x-sourcepawn']
#: optional Comment or Whitespace
_ws = r'(?:\s|//.*?\n|/\*.*?\*/)+'
tokens = {
'root': [
# preprocessor directives: without whitespace
('^#if\s+0', Comment.Preproc, 'if0'),
('^#', Comment.Preproc, 'macro'),
# or with whitespace
('^' + _ws + r'#if\s+0', Comment.Preproc, 'if0'),
('^' + _ws + '#', Comment.Preproc, 'macro'),
(r'\n', Text),
(r'\s+', Text),
(r'\\\n', Text), # line continuation
(r'/(\\\n)?/(\n|(.|\n)*?[^\\]\n)', Comment.Single),
(r'/(\\\n)?\*(.|\n)*?\*(\\\n)?/', Comment.Multiline),
(r'[{}]', Punctuation),
(r'L?"', String, 'string'),
(r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char),
(r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*', Number.Float),
(r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
(r'0x[0-9a-fA-F]+[LlUu]*', Number.Hex),
(r'0[0-7]+[LlUu]*', Number.Oct),
(r'\d+[LlUu]*', Number.Integer),
(r'\*/', Error),
(r'[~!%^&*+=|?:<>/-]', Operator),
(r'[()\[\],.;]', Punctuation),
(r'(case|const|continue|native|'
r'default|else|enum|for|if|new|operator|'
r'public|return|sizeof|static|decl|struct|switch)\b', Keyword),
(r'(bool|Float)\b', Keyword.Type),
(r'(true|false)\b', Keyword.Constant),
('[a-zA-Z_][a-zA-Z0-9_]*', Name),
],
'string': [
(r'"', String, '#pop'),
(r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
(r'[^\\"\n]+', String), # all other characters
(r'\\\n', String), # line continuation
(r'\\', String), # stray backslash
],
'macro': [
(r'[^/\n]+', Comment.Preproc),
(r'/\*(.|\n)*?\*/', Comment.Multiline),
(r'//.*?\n', Comment.Single, '#pop'),
(r'/', Comment.Preproc),
(r'(?<=\\)\n', Comment.Preproc),
(r'\n', Comment.Preproc, '#pop'),
],
'if0': [
(r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
(r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
(r'.*?\n', Comment),
]
}
SM_TYPES = ['Action', 'bool', 'Float', 'Plugin', 'String', 'any',
'AdminFlag', 'OverrideType', 'OverrideRule', 'ImmunityType',
'GroupId', 'AdminId', 'AdmAccessMode', 'AdminCachePart',
'CookieAccess', 'CookieMenu', 'CookieMenuAction', 'NetFlow',
'ConVarBounds', 'QueryCookie', 'ReplySource',
'ConVarQueryResult', 'ConVarQueryFinished', 'Function',
'Action', 'Identity', 'PluginStatus', 'PluginInfo', 'DBResult',
'DBBindType', 'DBPriority', 'PropType', 'PropFieldType',
'MoveType', 'RenderMode', 'RenderFx', 'EventHookMode',
'EventHook', 'FileType', 'FileTimeMode', 'PathType',
'ParamType', 'ExecType', 'DialogType', 'Handle', 'KvDataTypes',
'NominateResult', 'MapChange', 'MenuStyle', 'MenuAction',
'MenuSource', 'RegexError', 'SDKCallType', 'SDKLibrary',
'SDKFuncConfSource', 'SDKType', 'SDKPassMethod', 'RayType',
'TraceEntityFilter', 'ListenOverride', 'SortOrder', 'SortType',
'SortFunc2D', 'APLRes', 'FeatureType', 'FeatureStatus',
'SMCResult', 'SMCError', 'TFClassType', 'TFTeam', 'TFCond',
'TFResourceType', 'Timer', 'TopMenuAction', 'TopMenuObjectType',
'TopMenuPosition', 'TopMenuObject', 'UserMsg']
def __init__(self, **options):
self.smhighlighting = get_bool_opt(options,
'sourcemod', True)
self._functions = []
if self.smhighlighting:
from pygments.lexers._sourcemodbuiltins import FUNCTIONS
self._functions.extend(FUNCTIONS)
RegexLexer.__init__(self, **options)
def get_tokens_unprocessed(self, text):
for index, token, value in \
RegexLexer.get_tokens_unprocessed(self, text):
if token is Name:
if self.smhighlighting:
if value in self.SM_TYPES:
token = Keyword.Type
elif value in self._functions:
token = Name.Builtin
yield index, token, value
class PuppetLexer(RegexLexer):
"""
For `Puppet <http://puppetlabs.com/>`__ configuration DSL.
*New in Pygments 1.6.*
"""
name = 'Puppet'
aliases = ['puppet']
filenames = ['*.pp']
tokens = {
'root': [
include('comments'),
include('keywords'),
include('names'),
include('numbers'),
include('operators'),
include('strings'),
(r'[]{}:(),;[]', Punctuation),
(r'[^\S\n]+', Text),
],
'comments': [
(r'\s*#.*$', Comment),
(r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
],
'operators': [
(r'(=>|\?|<|>|=|\+|-|/|\*|~|!|\|)', Operator),
(r'(in|and|or|not)\b', Operator.Word),
],
'names': [
('[a-zA-Z_][a-zA-Z0-9_]*', Name.Attribute),
(r'(\$\S+)(\[)(\S+)(\])', bygroups(Name.Variable, Punctuation,
String, Punctuation)),
(r'\$\S+', Name.Variable),
],
'numbers': [
# Copypasta from the Python lexer
(r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?', Number.Float),
(r'\d+[eE][+-]?[0-9]+j?', Number.Float),
(r'0[0-7]+j?', Number.Oct),
(r'0[xX][a-fA-F0-9]+', Number.Hex),
(r'\d+L', Number.Integer.Long),
(r'\d+j?', Number.Integer)
],
'keywords': [
# Left out 'group' and 'require'
# Since they're often used as attributes
(r'(?i)(absent|alert|alias|audit|augeas|before|case|check|class|'
r'computer|configured|contained|create_resources|crit|cron|debug|'
r'default|define|defined|directory|else|elsif|emerg|err|exec|'
r'extlookup|fail|false|file|filebucket|fqdn_rand|generate|host|if|'
r'import|include|info|inherits|inline_template|installed|'
r'interface|k5login|latest|link|loglevel|macauthorization|'
r'mailalias|maillist|mcx|md5|mount|mounted|nagios_command|'
r'nagios_contact|nagios_contactgroup|nagios_host|'
r'nagios_hostdependency|nagios_hostescalation|nagios_hostextinfo|'
r'nagios_hostgroup|nagios_service|nagios_servicedependency|'
r'nagios_serviceescalation|nagios_serviceextinfo|'
r'nagios_servicegroup|nagios_timeperiod|node|noop|notice|notify|'
r'package|present|purged|realize|regsubst|resources|role|router|'
r'running|schedule|scheduled_task|search|selboolean|selmodule|'
r'service|sha1|shellquote|split|sprintf|ssh_authorized_key|sshkey|'
r'stage|stopped|subscribe|tag|tagged|template|tidy|true|undef|'
r'unmounted|user|versioncmp|vlan|warning|yumrepo|zfs|zone|'
r'zpool)\b', Keyword),
],
'strings': [
(r'"([^"])*"', String),
(r'\'([^\'])*\'', String),
],
}
class NSISLexer(RegexLexer):
"""
For `NSIS <http://nsis.sourceforge.net/>`_ scripts.
*New in Pygments 1.6.*
"""
name = 'NSIS'
aliases = ['nsis', 'nsi', 'nsh']
filenames = ['*.nsi', '*.nsh']
mimetypes = ['text/x-nsis']
flags = re.IGNORECASE
tokens = {
'root': [
(r'[;\#].*\n', Comment),
(r"'.*?'", String.Single),
(r'"', String.Double, 'str_double'),
(r'`', String.Backtick, 'str_backtick'),
include('macro'),
include('interpol'),
include('basic'),
(r'\$\{[a-z_|][\w|]*\}', Keyword.Pseudo),
(r'/[a-z_]\w*', Name.Attribute),
('.', Text),
],
'basic': [
(r'(\n)(Function)(\s+)([._a-z][.\w]*)\b',
bygroups(Text, Keyword, Text, Name.Function)),
(r'\b([_a-z]\w*)(::)([a-z][a-z0-9]*)\b',
bygroups(Keyword.Namespace, Punctuation, Name.Function)),
(r'\b([_a-z]\w*)(:)', bygroups(Name.Label, Punctuation)),
(r'(\b[ULS]|\B)([\!\<\>=]?=|\<\>?|\>)\B', Operator),
(r'[|+-]', Operator),
(r'\\', Punctuation),
(r'\b(Abort|Add(?:BrandingImage|Size)|'
r'Allow(?:RootDirInstall|SkipFiles)|AutoCloseWindow|'
r'BG(?:Font|Gradient)|BrandingText|BringToFront|Call(?:InstDLL)?|'
r'(?:Sub)?Caption|ChangeUI|CheckBitmap|ClearErrors|CompletedText|'
r'ComponentText|CopyFiles|CRCCheck|'
r'Create(?:Directory|Font|Shortcut)|Delete(?:INI(?:Sec|Str)|'
r'Reg(?:Key|Value))?|DetailPrint|DetailsButtonText|'
r'Dir(?:Show|Text|Var|Verify)|(?:Disabled|Enabled)Bitmap|'
r'EnableWindow|EnumReg(?:Key|Value)|Exch|Exec(?:Shell|Wait)?|'
r'ExpandEnvStrings|File(?:BufSize|Close|ErrorText|Open|'
r'Read(?:Byte)?|Seek|Write(?:Byte)?)?|'
r'Find(?:Close|First|Next|Window)|FlushINI|Function(?:End)?|'
r'Get(?:CurInstType|CurrentAddress|DlgItem|DLLVersion(?:Local)?|'
r'ErrorLevel|FileTime(?:Local)?|FullPathName|FunctionAddress|'
r'InstDirError|LabelAddress|TempFileName)|'
r'Goto|HideWindow|Icon|'
r'If(?:Abort|Errors|FileExists|RebootFlag|Silent)|'
r'InitPluginsDir|Install(?:ButtonText|Colors|Dir(?:RegKey)?)|'
r'Inst(?:ProgressFlags|Type(?:[GS]etText)?)|Int(?:CmpU?|Fmt|Op)|'
r'IsWindow|LangString(?:UP)?|'
r'License(?:BkColor|Data|ForceSelection|LangString|Text)|'
r'LoadLanguageFile|LockWindow|Log(?:Set|Text)|MessageBox|'
r'MiscButtonText|Name|Nop|OutFile|(?:Uninst)?Page(?:Ex(?:End)?)?|'
r'PluginDir|Pop|Push|Quit|Read(?:(?:Env|INI|Reg)Str|RegDWORD)|'
r'Reboot|(?:Un)?RegDLL|Rename|RequestExecutionLevel|ReserveFile|'
r'Return|RMDir|SearchPath|Section(?:Divider|End|'
r'(?:(?:Get|Set)(?:Flags|InstTypes|Size|Text))|Group(?:End)?|In)?|'
r'SendMessage|Set(?:AutoClose|BrandingImage|Compress(?:ionLevel|'
r'or(?:DictSize)?)?|CtlColors|CurInstType|DatablockOptimize|'
r'DateSave|Details(?:Print|View)|Error(?:s|Level)|FileAttributes|'
r'Font|OutPath|Overwrite|PluginUnload|RebootFlag|ShellVarContext|'
r'Silent|StaticBkColor)|'
r'Show(?:(?:I|Uni)nstDetails|Window)|Silent(?:Un)?Install|Sleep|'
r'SpaceTexts|Str(?:CmpS?|Cpy|Len)|SubSection(?:End)?|'
r'Uninstall(?:ButtonText|(?:Sub)?Caption|EXEName|Icon|Text)|'
r'UninstPage|Var|VI(?:AddVersionKey|ProductVersion)|WindowIcon|'
r'Write(?:INIStr|Reg(:?Bin|DWORD|(?:Expand)?Str)|Uninstaller)|'
r'XPStyle)\b', Keyword),
(r'\b(CUR|END|(?:FILE_ATTRIBUTE_)?'
r'(?:ARCHIVE|HIDDEN|NORMAL|OFFLINE|READONLY|SYSTEM|TEMPORARY)|'
r'HK(CC|CR|CU|DD|LM|PD|U)|'
r'HKEY_(?:CLASSES_ROOT|CURRENT_(?:CONFIG|USER)|DYN_DATA|'
r'LOCAL_MACHINE|PERFORMANCE_DATA|USERS)|'
r'ID(?:ABORT|CANCEL|IGNORE|NO|OK|RETRY|YES)|'
r'MB_(?:ABORTRETRYIGNORE|DEFBUTTON[1-4]|'
r'ICON(?:EXCLAMATION|INFORMATION|QUESTION|STOP)|'
r'OK(?:CANCEL)?|RETRYCANCEL|RIGHT|SETFOREGROUND|TOPMOST|USERICON|'
r'YESNO(?:CANCEL)?)|SET|SHCTX|'
r'SW_(?:HIDE|SHOW(?:MAXIMIZED|MINIMIZED|NORMAL))|'
r'admin|all|auto|both|bottom|bzip2|checkbox|colored|current|false|'
r'force|hide|highest|if(?:diff|newer)|lastused|leave|left|'
r'listonly|lzma|nevershow|none|normal|off|on|pop|push|'
r'radiobuttons|right|show|silent|silentlog|smooth|textonly|top|'
r'true|try|user|zlib)\b', Name.Constant),
],
'macro': [
(r'\!(addincludedir(?:dir)?|addplugindir|appendfile|cd|define|'
r'delfilefile|echo(?:message)?|else|endif|error|execute|'
r'if(?:macro)?n?(?:def)?|include|insertmacro|macro(?:end)?|packhdr|'
r'search(?:parse|replace)|system|tempfilesymbol|undef|verbose|'
r'warning)\b', Comment.Preproc),
],
'interpol': [
(r'\$(R?[0-9])', Name.Builtin.Pseudo), # registers
(r'\$(ADMINTOOLS|APPDATA|CDBURN_AREA|COOKIES|COMMONFILES(?:32|64)|'
r'DESKTOP|DOCUMENTS|EXE(?:DIR|FILE|PATH)|FAVORITES|FONTS|HISTORY|'
r'HWNDPARENT|INTERNET_CACHE|LOCALAPPDATA|MUSIC|NETHOOD|PICTURES|'
r'PLUGINSDIR|PRINTHOOD|PROFILE|PROGRAMFILES(?:32|64)|QUICKLAUNCH|'
r'RECENT|RESOURCES(?:_LOCALIZED)?|SENDTO|SM(?:PROGRAMS|STARTUP)|'
r'STARTMENU|SYSDIR|TEMP(?:LATES)?|VIDEOS|WINDIR|\{NSISDIR\})',
Name.Builtin),
(r'\$(CMDLINE|INSTDIR|OUTDIR|LANGUAGE)', Name.Variable.Global),
(r'\$[a-z_]\w*', Name.Variable),
],
'str_double': [
(r'"', String, '#pop'),
(r'\$(\\[nrt"]|\$)', String.Escape),
include('interpol'),
(r'.', String.Double),
],
'str_backtick': [
(r'`', String, '#pop'),
(r'\$(\\[nrt"]|\$)', String.Escape),
include('interpol'),
(r'.', String.Double),
],
}
class RPMSpecLexer(RegexLexer):
"""
For RPM *.spec files
*New in Pygments 1.6.*
"""
name = 'RPMSpec'
aliases = ['spec']
filenames = ['*.spec']
mimetypes = ['text/x-rpm-spec']
_directives = ('(?:package|prep|build|install|clean|check|pre[a-z]*|'
'post[a-z]*|trigger[a-z]*|files)')
tokens = {
'root': [
(r'#.*\n', Comment),
include('basic'),
],
'description': [
(r'^(%' + _directives + ')(.*)$',
bygroups(Name.Decorator, Text), '#pop'),
(r'\n', Text),
(r'.', Text),
],
'changelog': [
(r'\*.*\n', Generic.Subheading),
(r'^(%' + _directives + ')(.*)$',
bygroups(Name.Decorator, Text), '#pop'),
(r'\n', Text),
(r'.', Text),
],
'string': [
(r'"', String.Double, '#pop'),
(r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
include('interpol'),
(r'.', String.Double),
],
'basic': [
include('macro'),
(r'(?i)^(Name|Version|Release|Epoch|Summary|Group|License|Packager|'
r'Vendor|Icon|URL|Distribution|Prefix|Patch[0-9]*|Source[0-9]*|'
r'Requires\(?[a-z]*\)?|[a-z]+Req|Obsoletes|Suggests|Provides|Conflicts|'
r'Build[a-z]+|[a-z]+Arch|Auto[a-z]+)(:)(.*)$',
bygroups(Generic.Heading, Punctuation, using(this))),
(r'^%description', Name.Decorator, 'description'),
(r'^%changelog', Name.Decorator, 'changelog'),
(r'^(%' + _directives + ')(.*)$', bygroups(Name.Decorator, Text)),
(r'%(attr|defattr|dir|doc(?:dir)?|setup|config(?:ure)?|'
r'make(?:install)|ghost|patch[0-9]+|find_lang|exclude|verify)',
Keyword),
include('interpol'),
(r"'.*?'", String.Single),
(r'"', String.Double, 'string'),
(r'.', Text),
],
'macro': [
(r'%define.*\n', Comment.Preproc),
(r'%\{\!\?.*%define.*\}', Comment.Preproc),
(r'(%(?:if(?:n?arch)?|else(?:if)?|endif))(.*)$',
bygroups(Comment.Preproc, Text)),
],
'interpol': [
(r'%\{?__[a-z_]+\}?', Name.Function),
(r'%\{?_([a-z_]+dir|[a-z_]+path|prefix)\}?', Keyword.Pseudo),
(r'%\{\?[A-Za-z0-9_]+\}', Name.Variable),
(r'\$\{?RPM_[A-Z0-9_]+\}?', Name.Variable.Global),
(r'%\{[a-zA-Z][a-zA-Z0-9_]+\}', Keyword.Constant),
]
}
class AutoItLexer(RegexLexer):
"""
For `AutoIt <http://www.autoitscript.com/site/autoit/>`_ files.
AutoIt is a freeware BASIC-like scripting language
designed for automating the Windows GUI and general scripting
*New in Pygments 1.6.*
"""
name = 'AutoIt'
aliases = ['autoit', 'Autoit']
filenames = ['*.au3']
mimetypes = ['text/x-autoit']
# Keywords, functions, macros from au3.keywords.properties
# which can be found in AutoIt installed directory, e.g.
# c:\Program Files (x86)\AutoIt3\SciTE\au3.keywords.properties
keywords = """\
#include-once #include #endregion #forcedef #forceref #region
and byref case continueloop dim do else elseif endfunc endif
endselect exit exitloop for func global
if local next not or return select step
then to until wend while exit""".split()
functions = """\
abs acos adlibregister adlibunregister asc ascw asin assign atan
autoitsetoption autoitwingettitle autoitwinsettitle beep binary binarylen
binarymid binarytostring bitand bitnot bitor bitrotate bitshift bitxor
blockinput break call cdtray ceiling chr chrw clipget clipput consoleread
consolewrite consolewriteerror controlclick controlcommand controldisable
controlenable controlfocus controlgetfocus controlgethandle controlgetpos
controlgettext controlhide controllistview controlmove controlsend
controlsettext controlshow controltreeview cos dec dircopy dircreate
dirgetsize dirmove dirremove dllcall dllcalladdress dllcallbackfree
dllcallbackgetptr dllcallbackregister dllclose dllopen dllstructcreate
dllstructgetdata dllstructgetptr dllstructgetsize dllstructsetdata
drivegetdrive drivegetfilesystem drivegetlabel drivegetserial drivegettype
drivemapadd drivemapdel drivemapget drivesetlabel drivespacefree
drivespacetotal drivestatus envget envset envupdate eval execute exp
filechangedir fileclose filecopy filecreatentfslink filecreateshortcut
filedelete fileexists filefindfirstfile filefindnextfile fileflush
filegetattrib filegetencoding filegetlongname filegetpos filegetshortcut
filegetshortname filegetsize filegettime filegetversion fileinstall filemove
fileopen fileopendialog fileread filereadline filerecycle filerecycleempty
filesavedialog fileselectfolder filesetattrib filesetpos filesettime
filewrite filewriteline floor ftpsetproxy guicreate guictrlcreateavi
guictrlcreatebutton guictrlcreatecheckbox guictrlcreatecombo
guictrlcreatecontextmenu guictrlcreatedate guictrlcreatedummy
guictrlcreateedit guictrlcreategraphic guictrlcreategroup guictrlcreateicon
guictrlcreateinput guictrlcreatelabel guictrlcreatelist
guictrlcreatelistview guictrlcreatelistviewitem guictrlcreatemenu
guictrlcreatemenuitem guictrlcreatemonthcal guictrlcreateobj
guictrlcreatepic guictrlcreateprogress guictrlcreateradio
guictrlcreateslider guictrlcreatetab guictrlcreatetabitem
guictrlcreatetreeview guictrlcreatetreeviewitem guictrlcreateupdown
guictrldelete guictrlgethandle guictrlgetstate guictrlread guictrlrecvmsg
guictrlregisterlistviewsort guictrlsendmsg guictrlsendtodummy
guictrlsetbkcolor guictrlsetcolor guictrlsetcursor guictrlsetdata
guictrlsetdefbkcolor guictrlsetdefcolor guictrlsetfont guictrlsetgraphic
guictrlsetimage guictrlsetlimit guictrlsetonevent guictrlsetpos
guictrlsetresizing guictrlsetstate guictrlsetstyle guictrlsettip guidelete
guigetcursorinfo guigetmsg guigetstyle guiregistermsg guisetaccelerators
guisetbkcolor guisetcoord guisetcursor guisetfont guisethelp guiseticon
guisetonevent guisetstate guisetstyle guistartgroup guiswitch hex hotkeyset
httpsetproxy httpsetuseragent hwnd inetclose inetget inetgetinfo inetgetsize
inetread inidelete iniread inireadsection inireadsectionnames
inirenamesection iniwrite iniwritesection inputbox int isadmin isarray
isbinary isbool isdeclared isdllstruct isfloat ishwnd isint iskeyword
isnumber isobj isptr isstring log memgetstats mod mouseclick mouseclickdrag
mousedown mousegetcursor mousegetpos mousemove mouseup mousewheel msgbox
number objcreate objcreateinterface objevent objevent objget objname
onautoitexitregister onautoitexitunregister opt ping pixelchecksum
pixelgetcolor pixelsearch pluginclose pluginopen processclose processexists
processgetstats processlist processsetpriority processwait processwaitclose
progressoff progresson progressset ptr random regdelete regenumkey
regenumval regread regwrite round run runas runaswait runwait send
sendkeepactive seterror setextended shellexecute shellexecutewait shutdown
sin sleep soundplay soundsetwavevolume splashimageon splashoff splashtexton
sqrt srandom statusbargettext stderrread stdinwrite stdioclose stdoutread
string stringaddcr stringcompare stringformat stringfromasciiarray
stringinstr stringisalnum stringisalpha stringisascii stringisdigit
stringisfloat stringisint stringislower stringisspace stringisupper
stringisxdigit stringleft stringlen stringlower stringmid stringregexp
stringregexpreplace stringreplace stringright stringsplit stringstripcr
stringstripws stringtoasciiarray stringtobinary stringtrimleft
stringtrimright stringupper tan tcpaccept tcpclosesocket tcpconnect
tcplisten tcpnametoip tcprecv tcpsend tcpshutdown tcpstartup timerdiff
timerinit tooltip traycreateitem traycreatemenu traygetmsg trayitemdelete
trayitemgethandle trayitemgetstate trayitemgettext trayitemsetonevent
trayitemsetstate trayitemsettext traysetclick trayseticon traysetonevent
traysetpauseicon traysetstate traysettooltip traytip ubound udpbind
udpclosesocket udpopen udprecv udpsend udpshutdown udpstartup vargettype
winactivate winactive winclose winexists winflash wingetcaretpos
wingetclasslist wingetclientsize wingethandle wingetpos wingetprocess
wingetstate wingettext wingettitle winkill winlist winmenuselectitem
winminimizeall winminimizeallundo winmove winsetontop winsetstate
winsettitle winsettrans winwait winwaitactive winwaitclose
winwaitnotactive""".split()
macros = """\
@appdatacommondir @appdatadir @autoitexe @autoitpid @autoitversion
@autoitx64 @com_eventobj @commonfilesdir @compiled @computername @comspec
@cpuarch @cr @crlf @desktopcommondir @desktopdepth @desktopdir
@desktopheight @desktoprefresh @desktopwidth @documentscommondir @error
@exitcode @exitmethod @extended @favoritescommondir @favoritesdir
@gui_ctrlhandle @gui_ctrlid @gui_dragfile @gui_dragid @gui_dropid
@gui_winhandle @homedrive @homepath @homeshare @hotkeypressed @hour
@ipaddress1 @ipaddress2 @ipaddress3 @ipaddress4 @kblayout @lf
@logondnsdomain @logondomain @logonserver @mday @min @mon @msec @muilang
@mydocumentsdir @numparams @osarch @osbuild @oslang @osservicepack @ostype
@osversion @programfilesdir @programscommondir @programsdir @scriptdir
@scriptfullpath @scriptlinenumber @scriptname @sec @startmenucommondir
@startmenudir @startupcommondir @startupdir @sw_disable @sw_enable @sw_hide
@sw_lock @sw_maximize @sw_minimize @sw_restore @sw_show @sw_showdefault
@sw_showmaximized @sw_showminimized @sw_showminnoactive @sw_showna
@sw_shownoactivate @sw_shownormal @sw_unlock @systemdir @tab @tempdir
@tray_id @trayiconflashing @trayiconvisible @username @userprofiledir @wday
@windowsdir @workingdir @yday @year""".split()
tokens = {
'root': [
(r';.*\n', Comment.Single),
(r'(#comments-start|#cs).*?(#comments-end|#ce)', Comment.Multiline),
(r'[\[\]{}(),;]', Punctuation),
(r'(and|or|not)\b', Operator.Word),
(r'[\$|@][a-zA-Z_][a-zA-Z0-9_]*', Name.Variable),
(r'!=|==|:=|\.=|<<|>>|[-~+/*%=<>&^|?:!.]', Operator),
include('commands'),
include('labels'),
include('builtInFunctions'),
include('builtInMarcros'),
(r'"', String, combined('stringescape', 'dqs')),
include('numbers'),
(r'[a-zA-Z_#@$][a-zA-Z0-9_#@$]*', Name),
(r'\\|\'', Text),
(r'\`([\,\%\`abfnrtv\-\+;])', String.Escape),
(r'_\n', Text), # Line continuation
include('garbage'),
],
'commands': [
(r'(?i)(\s*)(%s)\b' % '|'.join(keywords),
bygroups(Text, Name.Builtin)),
],
'builtInFunctions': [
(r'(?i)(%s)\b' % '|'.join(functions),
Name.Function),
],
'builtInMarcros': [
(r'(?i)(%s)\b' % '|'.join(macros),
Name.Variable.Global),
],
'labels': [
# sendkeys
(r'(^\s*)({\S+?})', bygroups(Text, Name.Label)),
],
'numbers': [
(r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
(r'\d+[eE][+-]?[0-9]+', Number.Float),
(r'0\d+', Number.Oct),
(r'0[xX][a-fA-F0-9]+', Number.Hex),
(r'\d+L', Number.Integer.Long),
(r'\d+', Number.Integer)
],
'stringescape': [
(r'\"\"|\`([\,\%\`abfnrtv])', String.Escape),
],
'strings': [
(r'[^"\n]+', String),
],
'dqs': [
(r'"', String, '#pop'),
include('strings')
],
'garbage': [
(r'[^\S\n]', Text),
],
}
class RexxLexer(RegexLexer):
"""
`Rexx <http://www.rexxinfo.org/>`_ is a scripting language available for
a wide range of different platforms with its roots found on mainframe
systems. It is popular for I/O- and data based tasks and can act as glue
language to bind different applications together.
*New in Pygments 1.7.*
"""
name = 'Rexx'
aliases = ['rexx', 'ARexx', 'arexx']
filenames = ['*.rexx', '*.rex', '*.rx', '*.arexx']
mimetypes = ['text/x-rexx']
flags = re.IGNORECASE
tokens = {
'root': [
(r'\s', Whitespace),
(r'/\*', Comment.Multiline, 'comment'),
(r'"', String, 'string_double'),
(r"'", String, 'string_single'),
(r'[0-9]+(\.[0-9]+)?(e[+-]?[0-9])?', Number),
(r'([a-z_][a-z0-9_]*)(\s*)(:)(\s*)(procedure)\b',
bygroups(Name.Function, Whitespace, Operator, Whitespace,
Keyword.Declaration)),
(r'([a-z_][a-z0-9_]*)(\s*)(:)',
bygroups(Name.Label, Whitespace, Operator)),
include('function'),
include('keyword'),
include('operator'),
(r'[a-z_][a-z0-9_]*', Text),
],
'function': [
(r'(abbrev|abs|address|arg|b2x|bitand|bitor|bitxor|c2d|c2x|'
r'center|charin|charout|chars|compare|condition|copies|d2c|'
r'd2x|datatype|date|delstr|delword|digits|errortext|form|'
r'format|fuzz|insert|lastpos|left|length|linein|lineout|lines|'
r'max|min|overlay|pos|queued|random|reverse|right|sign|'
r'sourceline|space|stream|strip|substr|subword|symbol|time|'
r'trace|translate|trunc|value|verify|word|wordindex|'
r'wordlength|wordpos|words|x2b|x2c|x2d|xrange)(\s*)(\()',
bygroups(Name.Builtin, Whitespace, Operator)),
],
'keyword': [
(r'(address|arg|by|call|do|drop|else|end|exit|for|forever|if|'
r'interpret|iterate|leave|nop|numeric|off|on|options|parse|'
r'pull|push|queue|return|say|select|signal|to|then|trace|until|'
r'while)\b', Keyword.Reserved),
],
'operator': [
(r'(-|//|/|\(|\)|\*\*|\*|\\<<|\\<|\\==|\\=|\\>>|\\>|\\|\|\||\||'
r'&&|&|%|\+|<<=|<<|<=|<>|<|==|=|><|>=|>>=|>>|>|¬<<|¬<|¬==|¬=|'
r'¬>>|¬>|¬|\.|,)', Operator),
],
'string_double': [
(r'[^"\n]+', String),
(r'""', String),
(r'"', String, '#pop'),
(r'\n', Text, '#pop'), # Stray linefeed also terminates strings.
],
'string_single': [
(r'[^\'\n]', String),
(r'\'\'', String),
(r'\'', String, '#pop'),
(r'\n', Text, '#pop'), # Stray linefeed also terminates strings.
],
'comment': [
(r'[^*]+', Comment.Multiline),
(r'\*/', Comment.Multiline, '#pop'),
(r'\*', Comment.Multiline),
]
}
_c = lambda s: re.compile(s, re.MULTILINE)
_ADDRESS_COMMAND_PATTERN = _c(r'^\s*address\s+command\b')
_ADDRESS_PATTERN = _c(r'^\s*address\s+')
_DO_WHILE_PATTERN = _c(r'^\s*do\s+while\b')
_IF_THEN_DO_PATTERN = _c(r'^\s*if\b.+\bthen\s+do\s*$')
_PROCEDURE_PATTERN = _c(r'^\s*([a-z_][a-z0-9_]*)(\s*)(:)(\s*)(procedure)\b')
_ELSE_DO_PATTERN = _c(r'\belse\s+do\s*$')
_PARSE_ARG_PATTERN = _c(r'^\s*parse\s+(upper\s+)?(arg|value)\b')
PATTERNS_AND_WEIGHTS = (
(_ADDRESS_COMMAND_PATTERN, 0.2),
(_ADDRESS_PATTERN, 0.05),
(_DO_WHILE_PATTERN, 0.1),
(_ELSE_DO_PATTERN, 0.1),
(_IF_THEN_DO_PATTERN, 0.1),
(_PROCEDURE_PATTERN, 0.5),
(_PARSE_ARG_PATTERN, 0.2),
)
def analyse_text(text):
"""
Check for inital comment and patterns that distinguish Rexx from other
C-like languages.
"""
if re.search(r'/\*\**\s*rexx', text, re.IGNORECASE):
# Header matches MVS Rexx requirements, this is certainly a Rexx
# script.
return 1.0
elif text.startswith('/*'):
# Header matches general Rexx requirements; the source code might
# still be any language using C comments such as C++, C# or Java.
lowerText = text.lower()
result = sum(weight
for (pattern, weight) in RexxLexer.PATTERNS_AND_WEIGHTS
if pattern.search(lowerText)) + 0.01
return min(result, 1.0)
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
1848,
272,
18294,
2878,
94,
339,
491,
476,
1192,
367,
1163,
10815,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
199,
504,
13277,
14,
11729,
492,
12939,
5838,
12,
2387,
12,
10259,
12,
1808,
12,
971,
1362,
642,
12,
12149,
12,
13706,
19856,
199,
504,
13277,
14,
1418,
492,
4520,
12,
10357,
12,
18271,
12,
8767,
12,
971,
1362,
4516,
12,
6819,
12,
11013,
12,
6431,
12,
2812,
12,
2624,
12,
4860,
12,
8307,
12,
971,
1362,
24403,
199,
504,
13277,
14,
1974,
492,
664,
63,
2245,
63,
2992,
199,
504,
13277,
14,
12245,
14,
2520,
492,
20880,
5838,
199,
199,
504,
13277,
14,
12245,
423,
1490,
5173,
10372,
492,
24164,
1149,
4962,
32187,
199,
504,
13277,
14,
12245,
423,
9751,
4857,
11729,
492,
820,
17800,
16442,
5838,
199,
199,
3,
8552,
7163,
199,
504,
13277,
14,
12245,
14,
3009,
492,
428,
1710,
5838,
12,
4932,
16790,
5838,
12,
428,
29498,
9270,
5838,
199,
504,
13277,
14,
12245,
14,
5641,
492,
699,
1119,
5838,
12,
699,
1119,
4434,
5838,
12,
17206,
5838,
12,
971,
1362,
377,
28736,
5838,
199,
199,
363,
452,
363,
275,
788,
17171,
4904,
10112,
5838,
297,
283,
34,
2829,
16993,
5838,
297,
283,
10858,
600,
5838,
297,
283,
2679,
47,
3034,
5838,
297,
1779,
283,
10712,
21890,
5838,
297,
283,
2445,
21890,
5838,
297,
283,
21641,
5838,
297,
283,
1575,
86,
803,
5838,
297,
1779,
283,
25051,
5229,
5838,
297,
283,
1385,
7518,
5838,
297,
283,
497,
23484,
5838,
297,
283,
1217,
1282,
5838,
297,
1779,
283,
24730,
8556,
5838,
297,
283,
39,
2523,
19269,
5838,
297,
283,
33,
1786,
311,
475,
266,
5838,
297,
283,
6564,
5229,
5838,
297,
1779,
283,
3358,
8885,
498,
5838,
297,
283,
20652,
1451,
1981,
5838,
297,
283,
11903,
1710,
5838,
297,
283,
8548,
11312,
5838,
297,
1779,
283,
21568,
66,
5719,
5838,
297,
283,
33,
14947,
5838,
297,
283,
24304,
3908,
19,
5838,
297,
283,
51,
889,
23484,
5838,
297,
1779,
283,
37,
1981,
5838,
297,
283,
53,
4848,
374,
1669,
5838,
297,
283,
4299,
12886,
5838,
297,
283,
34,
293,
5838,
297,
1779,
283,
45,
551,
2268,
5838,
297,
283,
28033,
5838,
297,
283,
54,
2226,
5838,
297,
283,
2980,
4232,
3501,
5838,
297,
1779,
283,
21823,
16442,
5838,
297,
283,
48,
17934,
5838,
297,
283,
2709,
1311,
5838,
297,
283,
18612,
3053,
733,
5838,
297,
1779,
283,
35,
12648,
6845,
54,
18,
5838,
297,
283,
3358,
7940,
5838,
297,
283,
50,
476,
88,
5838,
418,
421,
199,
533,
662,
1981,
5838,
8,
19856,
304,
272,
408,
272,
21125,
367,
314,
30191,
7282,
13,
576,
658,
37,
1981,
272,
665,
1014,
921,
72,
2352,
1259,
3045,
83,
14,
957,
15,
9387,
15,
4757,
15,
69,
429,
13,
3671,
13,
4443,
15,
1360,
18740,
272,
2637,
14,
339,
627,
4665,
315,
14493,
413,
14,
21,
2795,
272,
408,
339,
536,
275,
283,
37,
1981,
7,
272,
5481,
275,
788,
69,
429,
418,
272,
6203,
275,
17855,
69,
429,
418,
272,
13290,
275,
788,
3578,
15,
88,
13,
69,
429,
418,
339,
3285,
275,
295,
14,
15434,
1204,
295,
14,
16661,
339,
4645,
275,
469,
267,
283,
1231,
356,
359,
288,
2387,
360,
8506,
659,
288,
2387,
360,
15384,
659,
267,
2156,
267,
283,
8506,
356,
359,
288,
334,
82,
1154,
83,
7386,
4516,
395,
288,
334,
82,
1154,
6307,
15,
16110,
6819,
14,
7200,
395,
288,
334,
82,
7,
7985,
9780,
78,
5547,
60,
5830,
14,
6113,
78,
3342,
8995,
5830,
9780,
78,
5547,
3678,
6819,
14,
18933,
395,
267,
2156,
267,
283,
15384,
356,
359,
288,
2387,
360,
1313,
659,
288,
2387,
360,
7511,
659,
288,
2387,
360,
5777,
659,
288,
2387,
360,
2227,
659,
288,
334,
82,
24487,
2624,
12,
283,
875,
659,
288,
334,
82,
1154,
6448,
2624,
12,
283,
875,
659,
288,
334,
82,
13445,
68,
23294,
68,
10,
6113,
3134,
68,
11,
6113,
68,
11,
2788,
20565,
1527,
16341,
22426,
68,
21324,
23096,
53,
85,
22952,
4860,
14,
5136,
395,
288,
334,
82,
13445,
68,
23294,
68,
10,
6113,
3134,
68,
11,
6113,
68,
21324,
70,
38,
11057,
70,
38,
61,
7044,
4860,
14,
5136,
395,
288,
334,
82,
7,
16,
88,
59,
16,
13,
25,
65,
13,
13753,
13,
38,
2807,
59,
23096,
53,
85,
22952,
4860,
14,
10373,
395,
288,
334,
82,
7,
16,
59,
16,
13,
23,
2807,
59,
23096,
53,
85,
22952,
4860,
14,
17584,
395,
288,
334,
82,
1154,
68,
21324,
23096,
53,
85,
22952,
4860,
14,
2674,
395,
288,
334,
82,
1154,
10,
3678,
4520,
395,
288,
334,
82,
3894,
94,
1,
5,
62,
6,
10,
10365,
92,
31,
16875,
12202,
13,
11529,
11013,
395,
288,
334,
82,
3894,
2440,
17158,
7023,
467,
14,
27,
4300,
10357,
395,
288,
334,
82,
3894,
65,
13,
6353,
13,
58,
17900,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
297,
2812,
395,
267,
2156,
267,
283,
2227,
356,
359,
288,
334,
82,
4289,
3,
2795,
4268,
6819,
14,
19285,
395,
267,
2156,
267,
283,
1313,
356,
359,
288,
334,
82,
6774,
15060,
92,
3902,
2862,
36,
297,
6431,
14,
17737,
395,
288,
334,
82,
7,
17304,
26,
12292,
92,
18643,
63,
21046,
92,
25312,
92,
3998,
92,
23925,
92,
37,
6265,
36,
948,
92,
9596,
92,
10764,
5227,
1467,
519,
7,
49,
5353,
92,
15508,
92,
15060,
92,
13578,
92,
3597,
1634,
92,
5353,
92,
8803,
92,
11749,
35,
16980,
92,
12819,
5227,
1467,
519,
7,
30805,
92,
5568,
5353,
92,
5568,
12819,
2862,
68,
10,
10127,
83,
14705,
1467,
10259,
8,
10650,
14,
804,
12,
4516,
1826,
267,
2156,
267,
283,
7511,
356,
359,
288,
334,
82,
6774,
1282,
31370,
92,
24790,
92,
8248,
92,
8248,
10215,
92,
28805,
53,
1951,
92,
8784,
92,
3078,
10596,
92,
3078,
17073,
5227,
1467,
519,
7,
7405,
4317,
92,
4609,
40,
726,
92,
24972,
92,
8414,
92,
4014,
748,
906,
44,
92,
9020,
92,
4118,
1282,
11978,
92,
12458,
7,
1467,
519,
7,
8936
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
1848,
272,
18294,
2878,
94,
339,
491,
476,
1192,
367,
1163,
10815,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
199,
504,
13277,
14,
11729,
492,
12939,
5838,
12,
2387,
12,
10259,
12,
1808,
12,
971,
1362,
642,
12,
12149,
12,
13706,
19856,
199,
504,
13277,
14,
1418,
492,
4520,
12,
10357,
12,
18271,
12,
8767,
12,
971,
1362,
4516,
12,
6819,
12,
11013,
12,
6431,
12,
2812,
12,
2624,
12,
4860,
12,
8307,
12,
971,
1362,
24403,
199,
504,
13277,
14,
1974,
492,
664,
63,
2245,
63,
2992,
199,
504,
13277,
14,
12245,
14,
2520,
492,
20880,
5838,
199,
199,
504,
13277,
14,
12245,
423,
1490,
5173,
10372,
492,
24164,
1149,
4962,
32187,
199,
504,
13277,
14,
12245,
423,
9751,
4857,
11729,
492,
820,
17800,
16442,
5838,
199,
199,
3,
8552,
7163,
199,
504,
13277,
14,
12245,
14,
3009,
492,
428,
1710,
5838,
12,
4932,
16790,
5838,
12,
428,
29498,
9270,
5838,
199,
504,
13277,
14,
12245,
14,
5641,
492,
699,
1119,
5838,
12,
699,
1119,
4434,
5838,
12,
17206,
5838,
12,
971,
1362,
377,
28736,
5838,
199,
199,
363,
452,
363,
275,
788,
17171,
4904,
10112,
5838,
297,
283,
34,
2829,
16993,
5838,
297,
283,
10858,
600,
5838,
297,
283,
2679,
47,
3034,
5838,
297,
1779,
283,
10712,
21890,
5838,
297,
283,
2445,
21890,
5838,
297,
283,
21641,
5838,
297,
283,
1575,
86,
803,
5838,
297,
1779,
283,
25051,
5229,
5838,
297,
283,
1385,
7518,
5838,
297,
283,
497,
23484,
5838,
297,
283,
1217,
1282,
5838,
297,
1779,
283,
24730,
8556,
5838,
297,
283,
39,
2523,
19269,
5838,
297,
283,
33,
1786,
311,
475,
266,
5838,
297,
283,
6564,
5229,
5838,
297,
1779,
283,
3358,
8885,
498,
5838,
297,
283,
20652,
1451,
1981,
5838,
297,
283,
11903,
1710,
5838,
297,
283,
8548,
11312,
5838,
297,
1779,
283,
21568,
66,
5719,
5838,
297,
283,
33,
14947,
5838,
297,
283,
24304,
3908,
19,
5838,
297,
283,
51,
889,
23484,
5838,
297,
1779,
283,
37,
1981,
5838,
297,
283,
53,
4848,
374,
1669,
5838,
297,
283,
4299,
12886,
5838,
297,
283,
34,
293,
5838,
297,
1779,
283,
45,
551,
2268,
5838,
297,
283,
28033,
5838,
297,
283,
54,
2226,
5838,
297,
283,
2980,
4232,
3501,
5838,
297,
1779,
283,
21823,
16442,
5838,
297,
283,
48,
17934,
5838,
297,
283,
2709,
1311,
5838,
297,
283,
18612,
3053,
733,
5838,
297,
1779,
283,
35,
12648,
6845,
54,
18,
5838,
297,
283,
3358,
7940,
5838,
297,
283,
50,
476,
88,
5838,
418,
421,
199,
533,
662,
1981,
5838,
8,
19856,
304,
272,
408,
272,
21125,
367,
314,
30191,
7282,
13,
576,
658,
37,
1981,
272,
665,
1014,
921,
72,
2352,
1259,
3045,
83,
14,
957,
15,
9387,
15,
4757,
15,
69,
429,
13,
3671,
13,
4443,
15,
1360,
18740,
272,
2637,
14,
339,
627,
4665,
315,
14493,
413,
14,
21,
2795,
272,
408,
339,
536,
275,
283,
37,
1981,
7,
272,
5481,
275,
788,
69,
429,
418,
272,
6203,
275,
17855,
69,
429,
418,
272,
13290,
275,
788,
3578,
15,
88,
13,
69,
429,
418,
339,
3285,
275,
295,
14,
15434,
1204,
295,
14,
16661,
339,
4645,
275,
469,
267,
283,
1231,
356,
359,
288,
2387,
360,
8506,
659,
288,
2387,
360,
15384,
659,
267,
2156,
267,
283,
8506,
356,
359,
288,
334,
82,
1154,
83,
7386,
4516,
395,
288,
334,
82,
1154,
6307,
15,
16110,
6819,
14,
7200,
395,
288,
334,
82,
7,
7985,
9780,
78,
5547,
60,
5830,
14,
6113,
78,
3342,
8995,
5830,
9780,
78,
5547,
3678,
6819,
14,
18933,
395,
267,
2156,
267,
283,
15384,
356,
359,
288,
2387,
360,
1313,
659,
288,
2387,
360,
7511,
659,
288,
2387,
360,
5777,
659,
288,
2387,
360,
2227,
659,
288,
334,
82,
24487,
2624,
12,
283,
875,
659,
288,
334,
82,
1154,
6448,
2624,
12,
283,
875,
659,
288,
334,
82,
13445,
68,
23294,
68,
10,
6113,
3134,
68,
11,
6113,
68,
11,
2788,
20565,
1527,
16341,
22426,
68,
21324,
23096,
53,
85,
22952,
4860,
14,
5136,
395,
288,
334,
82,
13445,
68,
23294,
68,
10,
6113,
3134,
68,
11,
6113,
68,
21324,
70,
38,
11057,
70,
38,
61,
7044,
4860,
14,
5136,
395,
288,
334,
82,
7,
16,
88,
59,
16,
13,
25,
65,
13,
13753,
13,
38,
2807,
59,
23096,
53,
85,
22952,
4860,
14,
10373,
395,
288,
334,
82,
7,
16,
59,
16,
13,
23,
2807,
59,
23096,
53,
85,
22952,
4860,
14,
17584,
395,
288,
334,
82,
1154,
68,
21324,
23096,
53,
85,
22952,
4860,
14,
2674,
395,
288,
334,
82,
1154,
10,
3678,
4520,
395,
288,
334,
82,
3894,
94,
1,
5,
62,
6,
10,
10365,
92,
31,
16875,
12202,
13,
11529,
11013,
395,
288,
334,
82,
3894,
2440,
17158,
7023,
467,
14,
27,
4300,
10357,
395,
288,
334,
82,
3894,
65,
13,
6353,
13,
58,
17900,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
297,
2812,
395,
267,
2156,
267,
283,
2227,
356,
359,
288,
334,
82,
4289,
3,
2795,
4268,
6819,
14,
19285,
395,
267,
2156,
267,
283,
1313,
356,
359,
288,
334,
82,
6774,
15060,
92,
3902,
2862,
36,
297,
6431,
14,
17737,
395,
288,
334,
82,
7,
17304,
26,
12292,
92,
18643,
63,
21046,
92,
25312,
92,
3998,
92,
23925,
92,
37,
6265,
36,
948,
92,
9596,
92,
10764,
5227,
1467,
519,
7,
49,
5353,
92,
15508,
92,
15060,
92,
13578,
92,
3597,
1634,
92,
5353,
92,
8803,
92,
11749,
35,
16980,
92,
12819,
5227,
1467,
519,
7,
30805,
92,
5568,
5353,
92,
5568,
12819,
2862,
68,
10,
10127,
83,
14705,
1467,
10259,
8,
10650,
14,
804,
12,
4516,
1826,
267,
2156,
267,
283,
7511,
356,
359,
288,
334,
82,
6774,
1282,
31370,
92,
24790,
92,
8248,
92,
8248,
10215,
92,
28805,
53,
1951,
92,
8784,
92,
3078,
10596,
92,
3078,
17073,
5227,
1467,
519,
7,
7405,
4317,
92,
4609,
40,
726,
92,
24972,
92,
8414,
92,
4014,
748,
906,
44,
92,
9020,
92,
4118,
1282,
11978,
92,
12458,
7,
1467,
519,
7,
8936,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
zhuwenping/python-for-android
|
python-modules/twisted/twisted/web/twcgi.py
|
49
|
11768
|
# -*- test-case-name: twisted.web.test.test_cgi -*-
# Copyright (c) 2001-2010 Twisted Matrix Laboratories.
# See LICENSE for details.
"""
I hold resource classes and helper classes that deal with CGI scripts.
"""
# System Imports
import string
import os
import urllib
# Twisted Imports
from twisted.web import http
from twisted.internet import reactor, protocol
from twisted.spread import pb
from twisted.python import log, filepath
from twisted.python.deprecate import deprecatedModuleAttribute
from twisted.python.versions import Version
from twisted.web import resource, server, static
class CGIDirectory(resource.Resource, filepath.FilePath):
def __init__(self, pathname):
resource.Resource.__init__(self)
filepath.FilePath.__init__(self, pathname)
def getChild(self, path, request):
fnp = self.child(path)
if not fnp.exists():
return static.File.childNotFound
elif fnp.isdir():
return CGIDirectory(fnp.path)
else:
return CGIScript(fnp.path)
return resource.NoResource()
def render(self, request):
notFound = resource.NoResource(
"CGI directories do not support directory listing.")
return notFound.render(request)
class CGIScript(resource.Resource):
"""
L{CGIScript} is a resource which runs child processes according to the CGI
specification.
The implementation is complex due to the fact that it requires asynchronous
IPC with an external process with an unpleasant protocol.
"""
isLeaf = 1
def __init__(self, filename, registry=None):
"""
Initialize, with the name of a CGI script file.
"""
self.filename = filename
def render(self, request):
"""
Do various things to conform to the CGI specification.
I will set up the usual slew of environment variables, then spin off a
process.
@type request: L{twisted.web.http.Request}
@param request: An HTTP request.
"""
script_name = "/"+string.join(request.prepath, '/')
serverName = string.split(request.getRequestHostname(), ':')[0]
env = {"SERVER_SOFTWARE": server.version,
"SERVER_NAME": serverName,
"GATEWAY_INTERFACE": "CGI/1.1",
"SERVER_PROTOCOL": request.clientproto,
"SERVER_PORT": str(request.getHost().port),
"REQUEST_METHOD": request.method,
"SCRIPT_NAME": script_name, # XXX
"SCRIPT_FILENAME": self.filename,
"REQUEST_URI": request.uri,
}
client = request.getClient()
if client is not None:
env['REMOTE_HOST'] = client
ip = request.getClientIP()
if ip is not None:
env['REMOTE_ADDR'] = ip
pp = request.postpath
if pp:
env["PATH_INFO"] = "/"+string.join(pp, '/')
if hasattr(request, "content"):
# request.content is either a StringIO or a TemporaryFile, and
# the file pointer is sitting at the beginning (seek(0,0))
request.content.seek(0,2)
length = request.content.tell()
request.content.seek(0,0)
env['CONTENT_LENGTH'] = str(length)
qindex = string.find(request.uri, '?')
if qindex != -1:
qs = env['QUERY_STRING'] = request.uri[qindex+1:]
if '=' in qs:
qargs = []
else:
qargs = [urllib.unquote(x) for x in qs.split('+')]
else:
env['QUERY_STRING'] = ''
qargs = []
# Propogate HTTP headers
for title, header in request.getAllHeaders().items():
envname = string.upper(string.replace(title, '-', '_'))
if title not in ('content-type', 'content-length'):
envname = "HTTP_" + envname
env[envname] = header
# Propogate our environment
for key, value in os.environ.items():
if not env.has_key(key):
env[key] = value
# And they're off!
self.runProcess(env, request, qargs)
return server.NOT_DONE_YET
def runProcess(self, env, request, qargs=[]):
"""
Run the cgi script.
@type env: A C{dict} of C{str}, or C{None}
@param env: The environment variables to pass to the processs that will
get spawned. See
L{twisted.internet.interfaces.IReactorProcess.spawnProcess} for more
information about environments and process creation.
@type request: L{twisted.web.http.Request}
@param request: An HTTP request.
@type qargs: A C{list} of C{str}
@param qargs: The command line arguments to pass to the process that
will get spawned.
"""
p = CGIProcessProtocol(request)
reactor.spawnProcess(p, self.filename, [self.filename] + qargs, env,
os.path.dirname(self.filename))
class FilteredScript(CGIScript):
"""
I am a special version of a CGI script, that uses a specific executable.
This is useful for interfacing with other scripting languages that adhere to
the CGI standard. My C{filter} attribute specifies what executable to run,
and my C{filename} init parameter describes which script to pass to the
first argument of that script.
To customize me for a particular location of a CGI interpreter, override
C{filter}.
@type filter: C{str}
@ivar filter: The absolute path to the executable.
"""
filter = '/usr/bin/cat'
def runProcess(self, env, request, qargs=[]):
"""
Run a script through the C{filter} executable.
@type env: A C{dict} of C{str}, or C{None}
@param env: The environment variables to pass to the processs that will
get spawned. See
L{twisted.internet.interfaces.IReactorProcess.spawnProcess} for more
information about environments and process creation.
@type request: L{twisted.web.http.Request}
@param request: An HTTP request.
@type qargs: A C{list} of C{str}
@param qargs: The command line arguments to pass to the process that
will get spawned.
"""
p = CGIProcessProtocol(request)
reactor.spawnProcess(p, self.filter,
[self.filter, self.filename] + qargs, env,
os.path.dirname(self.filename))
class PHP3Script(FilteredScript):
"""
L{PHP3Script} is deprecated. See L{FilteredScript} for how to create a
platform-specific configuration for the location of a PHP CGI interpreter.
I am a L{FilteredScript} that uses the default PHP3 command on most systems.
"""
deprecatedModuleAttribute(
Version("Twisted", 10, 1, 0),
"PHP3Script is deprecated. Use twisted.web.twcgi.FilteredScript "
"instead.",
__name__, "PHP3Script")
filter = '/usr/bin/php3'
class PHPScript(FilteredScript):
"""
L{PHPScript} is deprecated. See L{FilteredScript} for how to create a
platform-specific configuration for the location of a PHP CGI interpreter.
I am a L{FilteredScript} that uses the PHP command on most systems.
Sometimes, PHP wants the path to itself as C{argv[0]}. This is that time.
"""
deprecatedModuleAttribute(
Version("Twisted", 10, 1, 0),
"PHPScript is deprecated. Use twisted.web.twcgi.FilteredScript "
"instead.",
__name__, "PHPScript")
filter = '/usr/bin/php4'
class CGIProcessProtocol(protocol.ProcessProtocol, pb.Viewable):
handling_headers = 1
headers_written = 0
headertext = ''
errortext = ''
# Remotely relay producer interface.
def view_resumeProducing(self, issuer):
self.resumeProducing()
def view_pauseProducing(self, issuer):
self.pauseProducing()
def view_stopProducing(self, issuer):
self.stopProducing()
def resumeProducing(self):
self.transport.resumeProducing()
def pauseProducing(self):
self.transport.pauseProducing()
def stopProducing(self):
self.transport.loseConnection()
def __init__(self, request):
self.request = request
def connectionMade(self):
self.request.registerProducer(self, 1)
self.request.content.seek(0, 0)
content = self.request.content.read()
if content:
self.transport.write(content)
self.transport.closeStdin()
def errReceived(self, error):
self.errortext = self.errortext + error
def outReceived(self, output):
"""
Handle a chunk of input
"""
# First, make sure that the headers from the script are sorted
# out (we'll want to do some parsing on these later.)
if self.handling_headers:
text = self.headertext + output
headerEnds = []
for delimiter in '\n\n','\r\n\r\n','\r\r', '\n\r\n':
headerend = string.find(text,delimiter)
if headerend != -1:
headerEnds.append((headerend, delimiter))
if headerEnds:
headerEnds.sort()
headerend, delimiter = headerEnds[0]
self.headertext = text[:headerend]
# This is a final version of the header text.
linebreak = delimiter[:len(delimiter)/2]
headers = string.split(self.headertext, linebreak)
for header in headers:
br = string.find(header,': ')
if br == -1:
log.msg( 'ignoring malformed CGI header: %s' % header )
else:
headerName = string.lower(header[:br])
headerText = header[br+2:]
if headerName == 'location':
self.request.setResponseCode(http.FOUND)
if headerName == 'status':
try:
statusNum = int(headerText[:3]) #"XXX <description>" sometimes happens.
except:
log.msg( "malformed status header" )
else:
self.request.setResponseCode(statusNum)
else:
# Don't allow the application to control these required headers.
if headerName.lower() not in ('server', 'date'):
self.request.responseHeaders.addRawHeader(headerName, headerText)
output = text[headerend+len(delimiter):]
self.handling_headers = 0
if self.handling_headers:
self.headertext = text
if not self.handling_headers:
self.request.write(output)
def processEnded(self, reason):
if reason.value.exitCode != 0:
log.msg("CGI %s exited with exit code %s" %
(self.request.uri, reason.value.exitCode))
if self.errortext:
log.msg("Errors from CGI %s: %s" % (self.request.uri, self.errortext))
if self.handling_headers:
log.msg("Premature end of headers in %s: %s" % (self.request.uri, self.headertext))
self.request.write(
resource.ErrorPage(http.INTERNAL_SERVER_ERROR,
"CGI Script Error",
"Premature end of script headers.").render(self.request))
self.request.unregisterProducer()
self.request.finish()
|
apache-2.0
|
[
3,
1882,
511,
13,
2546,
13,
354,
26,
7390,
14,
2520,
14,
396,
14,
396,
63,
13814,
1882,
199,
3,
1898,
334,
67,
9,
12521,
13,
6542,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
421,
199,
624,
199,
41,
10266,
2073,
3992,
436,
5922,
3992,
626,
7962,
543,
28716,
10554,
14,
199,
624,
199,
199,
3,
6187,
24339,
199,
646,
1059,
199,
646,
747,
199,
646,
4011,
199,
199,
3,
17078,
24339,
199,
504,
7390,
14,
2520,
492,
1455,
199,
504,
7390,
14,
4901,
492,
9655,
12,
4113,
199,
504,
7390,
14,
29889,
492,
10446,
199,
504,
7390,
14,
1548,
492,
943,
12,
9911,
199,
504,
7390,
14,
1548,
14,
27891,
492,
5906,
2377,
1646,
199,
504,
7390,
14,
1548,
14,
6234,
492,
3394,
199,
504,
7390,
14,
2520,
492,
2073,
12,
1654,
12,
2955,
421,
199,
533,
18657,
998,
73,
1497,
8,
1927,
14,
4031,
12,
9911,
14,
14225,
304,
272,
347,
636,
826,
721,
277,
12,
11776,
304,
267,
2073,
14,
4031,
855,
826,
721,
277,
9,
267,
9911,
14,
14225,
855,
826,
721,
277,
12,
11776,
9,
339,
347,
664,
3493,
8,
277,
12,
931,
12,
1056,
304,
267,
289,
1590,
275,
291,
14,
1739,
8,
515,
9,
267,
340,
440,
289,
1590,
14,
2444,
837,
288,
372,
2955,
14,
1173,
14,
1739,
4667,
267,
916,
289,
1590,
14,
6027,
837,
288,
372,
18657,
998,
73,
1497,
8,
70,
1590,
14,
515,
9,
267,
587,
26,
288,
372,
445,
11092,
1669,
8,
70,
1590,
14,
515,
9,
267,
372,
2073,
14,
1944,
4031,
342,
339,
347,
3795,
8,
277,
12,
1056,
304,
267,
440,
3601,
275,
2073,
14,
1944,
4031,
8,
288,
298,
21337,
6602,
886,
440,
2291,
2082,
13778,
2685,
267,
372,
440,
3601,
14,
3352,
8,
1069,
9,
199,
199,
533,
445,
11092,
1669,
8,
1927,
14,
4031,
304,
272,
408,
272,
491,
91,
4064,
1311,
1669,
93,
365,
282,
2073,
1314,
7858,
1982,
10358,
7182,
370,
314,
28716,
272,
8929,
14,
339,
710,
4514,
365,
6114,
7037,
370,
314,
10572,
626,
652,
5074,
15608,
272,
3531,
35,
543,
376,
5957,
2112,
543,
376,
625,
11045,
305,
867,
4113,
14,
272,
408,
272,
365,
20475,
275,
413,
272,
347,
636,
826,
721,
277,
12,
1788,
12,
7086,
29,
403,
304,
267,
408,
267,
11578,
12,
543,
314,
536,
402,
282,
28716,
2884,
570,
14,
267,
408,
267,
291,
14,
1501,
275,
1788,
2378,
347,
3795,
8,
277,
12,
1056,
304,
267,
408,
267,
4226,
7750,
7645,
370,
26449,
370,
314,
28716,
8929,
14,
398,
473,
911,
663,
1536,
314,
20195,
26220,
87,
402,
3734,
2860,
12,
2066,
20749,
2331,
282,
267,
2112,
14,
398,
768,
466,
1056,
26,
491,
91,
12145,
14,
2520,
14,
1014,
14,
2017,
93,
267,
768,
635,
1056,
26,
1626,
3101,
1056,
14,
267,
408,
267,
2884,
63,
354,
275,
3286,
7709,
875,
14,
904,
8,
1069,
14,
657,
515,
12,
15107,
267,
1654,
985,
275,
1059,
14,
1294,
8,
1069,
14,
362,
2017,
25680,
1062,
7596,
5832,
16,
61,
267,
2589,
275,
2420,
6613,
63,
26734,
582,
257,
1654,
14,
1023,
12,
2049,
298,
6613,
63,
2339,
582,
755,
1654,
985,
12,
2049,
298,
26624,
17488,
63,
17598,
582,
298,
21337,
15,
17,
14,
17,
401,
2049,
298,
6613,
63,
9583,
582,
257,
1056,
14,
1258,
2625,
12,
2049,
298,
6613,
63,
3657,
582,
755,
620,
8,
1069,
14,
362,
4965,
1252,
719,
395,
2049,
298,
6780,
63,
9977,
582,
259,
1056,
14,
765,
12,
2049,
298,
10484,
63,
2339,
582,
755,
2884,
63,
354,
12,
327,
5787,
2049,
298,
10484,
63,
15440,
582,
257,
291,
14,
1501,
12,
2049,
298,
6780,
63,
7639,
582,
755,
1056,
14,
2302,
12,
267,
789,
398,
1890,
275,
1056,
14,
362,
3041,
342,
267,
340,
1890,
365,
440,
488,
26,
288,
2589,
459,
16058,
63,
5449,
418,
275,
1890,
267,
3384,
275,
1056,
14,
362,
3041,
1772,
342,
267,
340,
3384,
365,
440,
488,
26,
288,
2589,
459,
16058,
63,
7803,
418,
275,
3384,
267,
11618,
275,
1056,
14,
1932,
515,
267,
340,
11618,
26,
288,
2589,
905,
3243,
63,
4531,
937,
275,
3286,
7709,
875,
14,
904,
8,
802,
12,
15107,
398,
340,
2688,
8,
1069,
12,
298,
1317,
2349,
288,
327,
1056,
14,
1317,
365,
1902,
282,
5228,
503,
282,
21791,
1173,
12,
436,
288,
327,
314,
570,
7849,
365,
13867,
1337,
737,
314,
9608,
334,
5507,
8,
16,
12,
16,
430,
288,
1056,
14,
1317,
14,
5507,
8,
16,
12,
18,
9,
288,
2582,
275,
1056,
14,
1317,
14,
9974,
342,
288,
1056,
14,
1317,
14,
5507,
8,
16,
12,
16,
9,
288,
2589,
459,
9663,
63,
9127,
418,
275,
620,
8,
1267,
9,
398,
1894,
1080,
275,
1059,
14,
1623,
8,
1069,
14,
2302,
12,
8720,
358,
267,
340,
1894,
1080,
1137,
446,
17,
26,
288,
6377,
275,
2589,
459,
11938,
63,
5353,
418,
275,
1056,
14,
2302,
59,
81,
1080,
11,
17,
2938,
288,
340,
14051,
315,
6377,
26,
355,
1894,
589,
275,
942,
288,
587,
26,
355,
1894,
589,
275,
359,
4078,
14,
12240,
8,
88,
9,
367,
671,
315,
6377,
14,
1294,
19975,
5440,
267,
587,
26,
288,
2589,
459,
11938,
63,
5353,
418,
275,
2125,
288,
1894,
589,
275,
942,
398,
327,
2165,
555,
3237,
3101,
2323,
267,
367,
2538,
12,
1406,
315,
1056,
14,
31359,
9883,
1252,
1744,
837,
288,
2589,
354,
275,
1059,
14,
4142,
8,
875,
14,
1814,
8,
1213,
12,
17525,
2513,
1333,
288,
340,
2538,
440,
315,
661,
1317,
13,
466,
297,
283,
1317,
13,
1267,
735,
355,
2589,
354,
275,
298,
2856,
12172,
435,
2589,
354,
288,
2589,
59,
1813,
354,
61,
275,
1406,
267,
327,
2165,
555,
3237,
4154,
3734,
267,
367,
790,
12,
574,
315,
747,
14,
2314,
14,
1744,
837,
288,
340,
440,
2589,
14,
1989,
63,
498,
8,
498,
304,
355,
2589,
59,
498,
61,
275,
574,
267,
327,
6061,
2985,
3984,
2331,
1,
267,
291,
14,
1065,
3498,
8,
1813,
12,
1056,
12,
1894,
589,
9,
267,
372,
1654,
14,
4609,
63,
22162,
63,
57,
775,
2378,
347,
1255,
3498,
8,
277,
12,
2589,
12,
1056,
12,
1894,
589,
17894,
267,
408,
267,
3378
] |
[
1882,
511,
13,
2546,
13,
354,
26,
7390,
14,
2520,
14,
396,
14,
396,
63,
13814,
1882,
199,
3,
1898,
334,
67,
9,
12521,
13,
6542,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
421,
199,
624,
199,
41,
10266,
2073,
3992,
436,
5922,
3992,
626,
7962,
543,
28716,
10554,
14,
199,
624,
199,
199,
3,
6187,
24339,
199,
646,
1059,
199,
646,
747,
199,
646,
4011,
199,
199,
3,
17078,
24339,
199,
504,
7390,
14,
2520,
492,
1455,
199,
504,
7390,
14,
4901,
492,
9655,
12,
4113,
199,
504,
7390,
14,
29889,
492,
10446,
199,
504,
7390,
14,
1548,
492,
943,
12,
9911,
199,
504,
7390,
14,
1548,
14,
27891,
492,
5906,
2377,
1646,
199,
504,
7390,
14,
1548,
14,
6234,
492,
3394,
199,
504,
7390,
14,
2520,
492,
2073,
12,
1654,
12,
2955,
421,
199,
533,
18657,
998,
73,
1497,
8,
1927,
14,
4031,
12,
9911,
14,
14225,
304,
272,
347,
636,
826,
721,
277,
12,
11776,
304,
267,
2073,
14,
4031,
855,
826,
721,
277,
9,
267,
9911,
14,
14225,
855,
826,
721,
277,
12,
11776,
9,
339,
347,
664,
3493,
8,
277,
12,
931,
12,
1056,
304,
267,
289,
1590,
275,
291,
14,
1739,
8,
515,
9,
267,
340,
440,
289,
1590,
14,
2444,
837,
288,
372,
2955,
14,
1173,
14,
1739,
4667,
267,
916,
289,
1590,
14,
6027,
837,
288,
372,
18657,
998,
73,
1497,
8,
70,
1590,
14,
515,
9,
267,
587,
26,
288,
372,
445,
11092,
1669,
8,
70,
1590,
14,
515,
9,
267,
372,
2073,
14,
1944,
4031,
342,
339,
347,
3795,
8,
277,
12,
1056,
304,
267,
440,
3601,
275,
2073,
14,
1944,
4031,
8,
288,
298,
21337,
6602,
886,
440,
2291,
2082,
13778,
2685,
267,
372,
440,
3601,
14,
3352,
8,
1069,
9,
199,
199,
533,
445,
11092,
1669,
8,
1927,
14,
4031,
304,
272,
408,
272,
491,
91,
4064,
1311,
1669,
93,
365,
282,
2073,
1314,
7858,
1982,
10358,
7182,
370,
314,
28716,
272,
8929,
14,
339,
710,
4514,
365,
6114,
7037,
370,
314,
10572,
626,
652,
5074,
15608,
272,
3531,
35,
543,
376,
5957,
2112,
543,
376,
625,
11045,
305,
867,
4113,
14,
272,
408,
272,
365,
20475,
275,
413,
272,
347,
636,
826,
721,
277,
12,
1788,
12,
7086,
29,
403,
304,
267,
408,
267,
11578,
12,
543,
314,
536,
402,
282,
28716,
2884,
570,
14,
267,
408,
267,
291,
14,
1501,
275,
1788,
2378,
347,
3795,
8,
277,
12,
1056,
304,
267,
408,
267,
4226,
7750,
7645,
370,
26449,
370,
314,
28716,
8929,
14,
398,
473,
911,
663,
1536,
314,
20195,
26220,
87,
402,
3734,
2860,
12,
2066,
20749,
2331,
282,
267,
2112,
14,
398,
768,
466,
1056,
26,
491,
91,
12145,
14,
2520,
14,
1014,
14,
2017,
93,
267,
768,
635,
1056,
26,
1626,
3101,
1056,
14,
267,
408,
267,
2884,
63,
354,
275,
3286,
7709,
875,
14,
904,
8,
1069,
14,
657,
515,
12,
15107,
267,
1654,
985,
275,
1059,
14,
1294,
8,
1069,
14,
362,
2017,
25680,
1062,
7596,
5832,
16,
61,
267,
2589,
275,
2420,
6613,
63,
26734,
582,
257,
1654,
14,
1023,
12,
2049,
298,
6613,
63,
2339,
582,
755,
1654,
985,
12,
2049,
298,
26624,
17488,
63,
17598,
582,
298,
21337,
15,
17,
14,
17,
401,
2049,
298,
6613,
63,
9583,
582,
257,
1056,
14,
1258,
2625,
12,
2049,
298,
6613,
63,
3657,
582,
755,
620,
8,
1069,
14,
362,
4965,
1252,
719,
395,
2049,
298,
6780,
63,
9977,
582,
259,
1056,
14,
765,
12,
2049,
298,
10484,
63,
2339,
582,
755,
2884,
63,
354,
12,
327,
5787,
2049,
298,
10484,
63,
15440,
582,
257,
291,
14,
1501,
12,
2049,
298,
6780,
63,
7639,
582,
755,
1056,
14,
2302,
12,
267,
789,
398,
1890,
275,
1056,
14,
362,
3041,
342,
267,
340,
1890,
365,
440,
488,
26,
288,
2589,
459,
16058,
63,
5449,
418,
275,
1890,
267,
3384,
275,
1056,
14,
362,
3041,
1772,
342,
267,
340,
3384,
365,
440,
488,
26,
288,
2589,
459,
16058,
63,
7803,
418,
275,
3384,
267,
11618,
275,
1056,
14,
1932,
515,
267,
340,
11618,
26,
288,
2589,
905,
3243,
63,
4531,
937,
275,
3286,
7709,
875,
14,
904,
8,
802,
12,
15107,
398,
340,
2688,
8,
1069,
12,
298,
1317,
2349,
288,
327,
1056,
14,
1317,
365,
1902,
282,
5228,
503,
282,
21791,
1173,
12,
436,
288,
327,
314,
570,
7849,
365,
13867,
1337,
737,
314,
9608,
334,
5507,
8,
16,
12,
16,
430,
288,
1056,
14,
1317,
14,
5507,
8,
16,
12,
18,
9,
288,
2582,
275,
1056,
14,
1317,
14,
9974,
342,
288,
1056,
14,
1317,
14,
5507,
8,
16,
12,
16,
9,
288,
2589,
459,
9663,
63,
9127,
418,
275,
620,
8,
1267,
9,
398,
1894,
1080,
275,
1059,
14,
1623,
8,
1069,
14,
2302,
12,
8720,
358,
267,
340,
1894,
1080,
1137,
446,
17,
26,
288,
6377,
275,
2589,
459,
11938,
63,
5353,
418,
275,
1056,
14,
2302,
59,
81,
1080,
11,
17,
2938,
288,
340,
14051,
315,
6377,
26,
355,
1894,
589,
275,
942,
288,
587,
26,
355,
1894,
589,
275,
359,
4078,
14,
12240,
8,
88,
9,
367,
671,
315,
6377,
14,
1294,
19975,
5440,
267,
587,
26,
288,
2589,
459,
11938,
63,
5353,
418,
275,
2125,
288,
1894,
589,
275,
942,
398,
327,
2165,
555,
3237,
3101,
2323,
267,
367,
2538,
12,
1406,
315,
1056,
14,
31359,
9883,
1252,
1744,
837,
288,
2589,
354,
275,
1059,
14,
4142,
8,
875,
14,
1814,
8,
1213,
12,
17525,
2513,
1333,
288,
340,
2538,
440,
315,
661,
1317,
13,
466,
297,
283,
1317,
13,
1267,
735,
355,
2589,
354,
275,
298,
2856,
12172,
435,
2589,
354,
288,
2589,
59,
1813,
354,
61,
275,
1406,
267,
327,
2165,
555,
3237,
4154,
3734,
267,
367,
790,
12,
574,
315,
747,
14,
2314,
14,
1744,
837,
288,
340,
440,
2589,
14,
1989,
63,
498,
8,
498,
304,
355,
2589,
59,
498,
61,
275,
574,
267,
327,
6061,
2985,
3984,
2331,
1,
267,
291,
14,
1065,
3498,
8,
1813,
12,
1056,
12,
1894,
589,
9,
267,
372,
1654,
14,
4609,
63,
22162,
63,
57,
775,
2378,
347,
1255,
3498,
8,
277,
12,
2589,
12,
1056,
12,
1894,
589,
17894,
267,
408,
267,
3378,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
buckiracer/data-science-from-scratch
|
dataScienceFromScratch/DataScienceFromScratch/visualizing_data.py
|
58
|
5116
|
import matplotlib.pyplot as plt
from collections import Counter
def make_chart_simple_line_chart(plt):
years = [1950, 1960, 1970, 1980, 1990, 2000, 2010]
gdp = [300.2, 543.3, 1075.9, 2862.5, 5979.6, 10289.7, 14958.3]
# create a line chart, years on x-axis, gdp on y-axis
plt.plot(years, gdp, color='green', marker='o', linestyle='solid')
# add a title
plt.title("Nominal GDP")
# add a label to the y-axis
plt.ylabel("Billions of $")
plt.show()
def make_chart_simple_bar_chart(plt):
movies = ["Annie Hall", "Ben-Hur", "Casablanca", "Gandhi", "West Side Story"]
num_oscars = [5, 11, 3, 8, 10]
# bars are by default width 0.8, so we'll add 0.1 to the left coordinates
# so that each bar is centered
xs = [i + 0.1 for i, _ in enumerate(movies)]
# plot bars with left x-coordinates [xs], heights [num_oscars]
plt.bar(xs, num_oscars)
plt.ylabel("# of Academy Awards")
plt.title("My Favorite Movies")
# label x-axis with movie names at bar centers
plt.xticks([i + 0.5 for i, _ in enumerate(movies)], movies)
plt.show()
def make_chart_histogram(plt):
grades = [83,95,91,87,70,0,85,82,100,67,73,77,0]
decile = lambda grade: grade // 10 * 10
histogram = Counter(decile(grade) for grade in grades)
plt.bar([x - 4 for x in histogram.keys()], # shift each bar to the left by 4
histogram.values(), # give each bar its correct height
8) # give each bar a width of 8
plt.axis([-5, 105, 0, 5]) # x-axis from -5 to 105,
# y-axis from 0 to 5
plt.xticks([10 * i for i in range(11)]) # x-axis labels at 0, 10, ..., 100
plt.xlabel("Decile")
plt.ylabel("# of Students")
plt.title("Distribution of Exam 1 Grades")
plt.show()
def make_chart_misleading_y_axis(plt, mislead=True):
mentions = [500, 505]
years = [2013, 2014]
plt.bar([2012.6, 2013.6], mentions, 0.8)
plt.xticks(years)
plt.ylabel("# of times I heard someone say 'data science'")
# if you don't do this, matplotlib will label the x-axis 0, 1
# and then add a +2.013e3 off in the corner (bad matplotlib!)
plt.ticklabel_format(useOffset=False)
if mislead:
# misleading y-axis only shows the part above 500
plt.axis([2012.5,2014.5,499,506])
plt.title("Look at the 'Huge' Increase!")
else:
plt.axis([2012.5,2014.5,0,550])
plt.title("Not So Huge Anymore.")
plt.show()
def make_chart_several_line_charts(plt):
variance = [1,2,4,8,16,32,64,128,256]
bias_squared = [256,128,64,32,16,8,4,2,1]
total_error = [x + y for x, y in zip(variance, bias_squared)]
xs = range(len(variance))
# we can make multiple calls to plt.plot
# to show multiple series on the same chart
plt.plot(xs, variance, 'g-', label='variance') # green solid line
plt.plot(xs, bias_squared, 'r-.', label='bias^2') # red dot-dashed line
plt.plot(xs, total_error, 'b:', label='total error') # blue dotted line
# because we've assigned labels to each series
# we can get a legend for free
# loc=9 means "top center"
plt.legend(loc=9)
plt.xlabel("model complexity")
plt.title("The Bias-Variance Tradeoff")
plt.show()
def make_chart_scatter_plot(plt):
friends = [ 70, 65, 72, 63, 71, 64, 60, 64, 67]
minutes = [175, 170, 205, 120, 220, 130, 105, 145, 190]
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
plt.scatter(friends, minutes)
# label each point
for label, friend_count, minute_count in zip(labels, friends, minutes):
plt.annotate(label,
xy=(friend_count, minute_count), # put the label with its point
xytext=(5, -5), # but slightly offset
textcoords='offset points')
plt.title("Daily Minutes vs. Number of Friends")
plt.xlabel("# of friends")
plt.ylabel("daily minutes spent on the site")
plt.show()
def make_chart_scatterplot_axes(plt, equal_axes=False):
test_1_grades = [ 99, 90, 85, 97, 80]
test_2_grades = [100, 85, 60, 90, 70]
plt.scatter(test_1_grades, test_2_grades)
plt.xlabel("test 1 grade")
plt.ylabel("test 2 grade")
if equal_axes:
plt.title("Axes Are Comparable")
plt.axis("equal")
else:
plt.title("Axes Aren't Comparable")
plt.show()
def make_chart_pie_chart(plt):
plt.pie([0.95, 0.05], labels=["Uses pie charts", "Knows better"])
# make sure pie is a circle and not an oval
plt.axis("equal")
plt.show()
if __name__ == "__main__":
make_chart_simple_line_chart(plt)
make_chart_simple_bar_chart(plt)
make_chart_histogram(plt)
make_chart_misleading_y_axis(plt, mislead=True)
make_chart_misleading_y_axis(plt, mislead=False)
make_chart_several_line_charts(plt)
make_chart_scatterplot_axes(plt, equal_axes=False)
make_chart_scatterplot_axes(plt, equal_axes=True)
make_chart_pie_chart(plt)
|
unlicense
|
[
646,
8027,
14,
13563,
465,
4488,
199,
504,
5055,
492,
14427,
199,
199,
318,
1852,
63,
9019,
63,
4129,
63,
604,
63,
9019,
8,
6003,
304,
339,
17399,
275,
359,
1167,
1400,
12,
5851,
2259,
12,
413,
20598,
12,
5851,
1257,
12,
9013,
16,
12,
12293,
12,
7129,
61,
272,
486,
5780,
275,
359,
5863,
14,
18,
12,
959,
2824,
14,
19,
12,
1616,
2194,
14,
25,
12,
499,
16414,
14,
21,
12,
8155,
1965,
14,
22,
12,
12996,
1407,
14,
23,
12,
28528,
2010,
14,
19,
61,
339,
327,
1218,
282,
1004,
10943,
12,
17399,
641,
671,
13,
3127,
12,
486,
5780,
641,
612,
13,
3127,
272,
4488,
14,
2798,
8,
18431,
12,
486,
5780,
12,
3164,
534,
7731,
297,
3608,
534,
79,
297,
27880,
534,
18533,
358,
339,
327,
1050,
282,
2538,
272,
4488,
14,
1213,
480,
46,
676,
1582,
598,
11741,
531,
339,
327,
1050,
282,
1768,
370,
314,
612,
13,
3127,
272,
4488,
14,
13849,
480,
34,
8148,
4654,
402,
2672,
531,
272,
4488,
14,
2384,
342,
421,
199,
318,
1852,
63,
9019,
63,
4129,
63,
1700,
63,
9019,
8,
6003,
304,
339,
1303,
14484,
275,
2097,
2493,
78,
1873,
869,
452,
401,
298,
31231,
13,
40,
300,
401,
298,
35,
305,
371,
1502,
696,
401,
298,
39,
460,
5812,
401,
298,
55,
597,
428,
2655,
1933,
1089,
937,
272,
1967,
63,
26737,
4291,
275,
359,
21,
12,
4119,
12,
650,
12,
1695,
12,
1616,
61,
339,
327,
29130,
787,
701,
849,
3462,
378,
14,
24,
12,
880,
781,
7171,
1050,
378,
14,
17,
370,
314,
3602,
8983,
272,
327,
880,
626,
1924,
4681,
365,
23903,
272,
12965,
275,
359,
73,
435,
378,
14,
17,
367,
284,
12,
485,
315,
3874,
8,
20888,
1874,
339,
327,
5137,
29130,
543,
3602,
671,
13,
12924,
359,
7977,
467,
946,
2492,
359,
1507,
63,
26737,
4291,
61,
272,
4488,
14,
1700,
8,
7977,
12,
1967,
63,
26737,
4291,
9,
272,
4488,
14,
13849,
10064,
402,
437,
9490,
1662,
437,
4751,
531,
272,
4488,
14,
1213,
480,
5713,
481,
12958,
1175,
3930,
14484,
531,
339,
327,
1768,
671,
13,
3127,
543,
14360,
1561,
737,
4681,
19190,
272,
4488,
14,
26217,
779,
73,
435,
378,
14,
21,
367,
284,
12,
485,
315,
3874,
8,
20888,
4360,
1303,
14484,
9,
2286,
4488,
14,
2384,
342,
199,
199,
318,
1852,
63,
9019,
63,
14805,
8,
6003,
304,
272,
1999,
3424,
275,
359,
2658,
12,
2720,
12,
3328,
12,
1555,
12,
2760,
12,
16,
12,
2426,
12,
2564,
12,
1960,
12,
1822,
12,
2898,
12,
1138,
12,
16,
61,
272,
9700,
441,
275,
2400,
16183,
26,
16183,
5001,
1616,
627,
1616,
5591,
15379,
275,
14427,
8,
7778,
441,
8,
4523,
9,
367,
16183,
315,
1999,
3424,
9,
339,
4488,
14,
1700,
779,
88,
446,
841,
367,
671,
315,
15379,
14,
1612,
15618,
327,
7706,
1924,
4681,
370,
314,
3602,
701,
841,
288,
15379,
14,
1459,
1062,
4483,
327,
8120,
1924,
4681,
2399,
3211,
4569,
288,
1695,
9,
2476,
327,
8120,
1924,
4681,
282,
3462,
402,
1695,
272,
4488,
14,
3127,
11468,
21,
12,
20462,
12,
378,
12,
959,
566,
8295,
327,
671,
13,
3127,
687,
446,
21,
370,
20462,
12,
6901,
327,
612,
13,
3127,
687,
378,
370,
959,
272,
4488,
14,
26217,
779,
709,
627,
284,
367,
284,
315,
1425,
8,
845,
3948,
259,
327,
671,
13,
3127,
3628,
737,
378,
12,
1616,
12,
14263,
2948,
272,
4488,
14,
14168,
480,
8584,
441,
531,
272,
4488,
14,
13849,
10064,
402,
17246,
83,
531,
272,
4488,
14,
1213,
480,
8580,
402,
1316,
455,
413,
10268,
3424,
531,
272,
4488,
14,
2384,
342,
199,
199,
318,
1852,
63,
9019,
63,
1292,
16812,
63,
89,
63,
3127,
8,
6003,
12,
3201,
13799,
29,
549,
304,
339,
12953,
852,
275,
359,
5783,
12,
959,
1717,
61,
272,
17399,
275,
359,
6965,
12,
6927,
61,
339,
4488,
14,
1700,
779,
7409,
14,
22,
12,
6171,
14,
22,
467,
12953,
852,
12,
378,
14,
24,
9,
272,
4488,
14,
26217,
8,
18431,
9,
272,
4488,
14,
13849,
10064,
402,
5431,
473,
946,
1005,
17122,
14722,
283,
576,
6276,
4894,
9859,
339,
327,
340,
1265,
2793,
1133,
886,
642,
12,
8027,
911,
1768,
314,
671,
13,
3127,
378,
12,
413,
272,
327,
436,
2066,
1050,
282,
435,
18,
14,
13264,
69,
19,
2331,
315,
314,
17703,
334,
4087,
8027,
21866,
272,
4488,
14,
8284,
1302,
63,
908,
8,
1180,
6397,
29,
797,
9,
339,
340,
3201,
13799,
26,
267,
327,
3201,
16812,
612,
13,
3127,
1454,
13703,
314,
1777,
3432,
6891,
267,
4488,
14,
3127,
779,
7409,
14,
21,
12,
7280,
14,
21,
12,
22402,
12,
13725,
566,
267,
4488,
14,
1213,
480,
20926,
737,
314,
283,
40,
17730,
7,
1010,
16772,
9124,
272,
587,
26,
267,
4488,
14,
3127,
779,
7409,
14,
21,
12,
7280,
14,
21,
12,
16,
12,
16859,
566,
267,
4488,
14,
1213,
480,
1763,
2002,
869,
17730,
6184,
6878,
2685,
263,
272,
4488,
14,
2384,
342,
199,
199,
318,
1852,
63,
9019,
63,
261,
422,
279,
63,
604,
63,
31522,
8,
6003,
304,
339,
11773,
258,
275,
359,
17,
12,
18,
12,
20,
12,
24,
12,
975,
12,
708,
12,
772,
12,
3933,
12,
3912,
61,
272,
10671,
63,
12973,
275,
359,
3912,
12,
3933,
12,
772,
12,
708,
12,
975,
12,
24,
12,
20,
12,
18,
12,
17,
61,
272,
3141,
63,
705,
221,
275,
359,
88,
435,
612,
367,
671,
12,
612,
315,
3482,
8,
6221,
12,
10671,
63,
12973,
1874,
339,
12965,
275,
1425,
8,
552,
8,
6221,
430,
339,
327,
781,
883,
1852,
3663,
4882,
370,
4488,
14,
2798,
5591,
327,
370,
2498,
3663,
6779,
641,
314,
2011,
10943,
272,
4488,
14,
2798,
8,
7977,
12,
11773,
12,
258,
283,
71,
14382,
221,
1768,
534,
6221,
358,
259,
327,
12431,
18609,
1004,
272,
4488,
14,
2798,
8,
7977,
12,
10671,
63,
12973,
12,
283,
82,
13,
3130,
1768,
534,
8160,
62,
18,
358,
420,
327,
8992,
6308,
13,
6760,
379,
1004,
272,
4488,
14,
2798,
8,
7977,
12,
3141,
63,
705,
12,
221,
283,
66,
6536,
221,
1768,
534,
2923,
1125,
358,
327,
10030,
18947,
1004,
339,
327,
2952,
781,
9064,
7943,
3628,
370,
1924
] |
[
8027,
14,
13563,
465,
4488,
199,
504,
5055,
492,
14427,
199,
199,
318,
1852,
63,
9019,
63,
4129,
63,
604,
63,
9019,
8,
6003,
304,
339,
17399,
275,
359,
1167,
1400,
12,
5851,
2259,
12,
413,
20598,
12,
5851,
1257,
12,
9013,
16,
12,
12293,
12,
7129,
61,
272,
486,
5780,
275,
359,
5863,
14,
18,
12,
959,
2824,
14,
19,
12,
1616,
2194,
14,
25,
12,
499,
16414,
14,
21,
12,
8155,
1965,
14,
22,
12,
12996,
1407,
14,
23,
12,
28528,
2010,
14,
19,
61,
339,
327,
1218,
282,
1004,
10943,
12,
17399,
641,
671,
13,
3127,
12,
486,
5780,
641,
612,
13,
3127,
272,
4488,
14,
2798,
8,
18431,
12,
486,
5780,
12,
3164,
534,
7731,
297,
3608,
534,
79,
297,
27880,
534,
18533,
358,
339,
327,
1050,
282,
2538,
272,
4488,
14,
1213,
480,
46,
676,
1582,
598,
11741,
531,
339,
327,
1050,
282,
1768,
370,
314,
612,
13,
3127,
272,
4488,
14,
13849,
480,
34,
8148,
4654,
402,
2672,
531,
272,
4488,
14,
2384,
342,
421,
199,
318,
1852,
63,
9019,
63,
4129,
63,
1700,
63,
9019,
8,
6003,
304,
339,
1303,
14484,
275,
2097,
2493,
78,
1873,
869,
452,
401,
298,
31231,
13,
40,
300,
401,
298,
35,
305,
371,
1502,
696,
401,
298,
39,
460,
5812,
401,
298,
55,
597,
428,
2655,
1933,
1089,
937,
272,
1967,
63,
26737,
4291,
275,
359,
21,
12,
4119,
12,
650,
12,
1695,
12,
1616,
61,
339,
327,
29130,
787,
701,
849,
3462,
378,
14,
24,
12,
880,
781,
7171,
1050,
378,
14,
17,
370,
314,
3602,
8983,
272,
327,
880,
626,
1924,
4681,
365,
23903,
272,
12965,
275,
359,
73,
435,
378,
14,
17,
367,
284,
12,
485,
315,
3874,
8,
20888,
1874,
339,
327,
5137,
29130,
543,
3602,
671,
13,
12924,
359,
7977,
467,
946,
2492,
359,
1507,
63,
26737,
4291,
61,
272,
4488,
14,
1700,
8,
7977,
12,
1967,
63,
26737,
4291,
9,
272,
4488,
14,
13849,
10064,
402,
437,
9490,
1662,
437,
4751,
531,
272,
4488,
14,
1213,
480,
5713,
481,
12958,
1175,
3930,
14484,
531,
339,
327,
1768,
671,
13,
3127,
543,
14360,
1561,
737,
4681,
19190,
272,
4488,
14,
26217,
779,
73,
435,
378,
14,
21,
367,
284,
12,
485,
315,
3874,
8,
20888,
4360,
1303,
14484,
9,
2286,
4488,
14,
2384,
342,
199,
199,
318,
1852,
63,
9019,
63,
14805,
8,
6003,
304,
272,
1999,
3424,
275,
359,
2658,
12,
2720,
12,
3328,
12,
1555,
12,
2760,
12,
16,
12,
2426,
12,
2564,
12,
1960,
12,
1822,
12,
2898,
12,
1138,
12,
16,
61,
272,
9700,
441,
275,
2400,
16183,
26,
16183,
5001,
1616,
627,
1616,
5591,
15379,
275,
14427,
8,
7778,
441,
8,
4523,
9,
367,
16183,
315,
1999,
3424,
9,
339,
4488,
14,
1700,
779,
88,
446,
841,
367,
671,
315,
15379,
14,
1612,
15618,
327,
7706,
1924,
4681,
370,
314,
3602,
701,
841,
288,
15379,
14,
1459,
1062,
4483,
327,
8120,
1924,
4681,
2399,
3211,
4569,
288,
1695,
9,
2476,
327,
8120,
1924,
4681,
282,
3462,
402,
1695,
272,
4488,
14,
3127,
11468,
21,
12,
20462,
12,
378,
12,
959,
566,
8295,
327,
671,
13,
3127,
687,
446,
21,
370,
20462,
12,
6901,
327,
612,
13,
3127,
687,
378,
370,
959,
272,
4488,
14,
26217,
779,
709,
627,
284,
367,
284,
315,
1425,
8,
845,
3948,
259,
327,
671,
13,
3127,
3628,
737,
378,
12,
1616,
12,
14263,
2948,
272,
4488,
14,
14168,
480,
8584,
441,
531,
272,
4488,
14,
13849,
10064,
402,
17246,
83,
531,
272,
4488,
14,
1213,
480,
8580,
402,
1316,
455,
413,
10268,
3424,
531,
272,
4488,
14,
2384,
342,
199,
199,
318,
1852,
63,
9019,
63,
1292,
16812,
63,
89,
63,
3127,
8,
6003,
12,
3201,
13799,
29,
549,
304,
339,
12953,
852,
275,
359,
5783,
12,
959,
1717,
61,
272,
17399,
275,
359,
6965,
12,
6927,
61,
339,
4488,
14,
1700,
779,
7409,
14,
22,
12,
6171,
14,
22,
467,
12953,
852,
12,
378,
14,
24,
9,
272,
4488,
14,
26217,
8,
18431,
9,
272,
4488,
14,
13849,
10064,
402,
5431,
473,
946,
1005,
17122,
14722,
283,
576,
6276,
4894,
9859,
339,
327,
340,
1265,
2793,
1133,
886,
642,
12,
8027,
911,
1768,
314,
671,
13,
3127,
378,
12,
413,
272,
327,
436,
2066,
1050,
282,
435,
18,
14,
13264,
69,
19,
2331,
315,
314,
17703,
334,
4087,
8027,
21866,
272,
4488,
14,
8284,
1302,
63,
908,
8,
1180,
6397,
29,
797,
9,
339,
340,
3201,
13799,
26,
267,
327,
3201,
16812,
612,
13,
3127,
1454,
13703,
314,
1777,
3432,
6891,
267,
4488,
14,
3127,
779,
7409,
14,
21,
12,
7280,
14,
21,
12,
22402,
12,
13725,
566,
267,
4488,
14,
1213,
480,
20926,
737,
314,
283,
40,
17730,
7,
1010,
16772,
9124,
272,
587,
26,
267,
4488,
14,
3127,
779,
7409,
14,
21,
12,
7280,
14,
21,
12,
16,
12,
16859,
566,
267,
4488,
14,
1213,
480,
1763,
2002,
869,
17730,
6184,
6878,
2685,
263,
272,
4488,
14,
2384,
342,
199,
199,
318,
1852,
63,
9019,
63,
261,
422,
279,
63,
604,
63,
31522,
8,
6003,
304,
339,
11773,
258,
275,
359,
17,
12,
18,
12,
20,
12,
24,
12,
975,
12,
708,
12,
772,
12,
3933,
12,
3912,
61,
272,
10671,
63,
12973,
275,
359,
3912,
12,
3933,
12,
772,
12,
708,
12,
975,
12,
24,
12,
20,
12,
18,
12,
17,
61,
272,
3141,
63,
705,
221,
275,
359,
88,
435,
612,
367,
671,
12,
612,
315,
3482,
8,
6221,
12,
10671,
63,
12973,
1874,
339,
12965,
275,
1425,
8,
552,
8,
6221,
430,
339,
327,
781,
883,
1852,
3663,
4882,
370,
4488,
14,
2798,
5591,
327,
370,
2498,
3663,
6779,
641,
314,
2011,
10943,
272,
4488,
14,
2798,
8,
7977,
12,
11773,
12,
258,
283,
71,
14382,
221,
1768,
534,
6221,
358,
259,
327,
12431,
18609,
1004,
272,
4488,
14,
2798,
8,
7977,
12,
10671,
63,
12973,
12,
283,
82,
13,
3130,
1768,
534,
8160,
62,
18,
358,
420,
327,
8992,
6308,
13,
6760,
379,
1004,
272,
4488,
14,
2798,
8,
7977,
12,
3141,
63,
705,
12,
221,
283,
66,
6536,
221,
1768,
534,
2923,
1125,
358,
327,
10030,
18947,
1004,
339,
327,
2952,
781,
9064,
7943,
3628,
370,
1924,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
gurneyalex/OpenUpgrade
|
openerp/report/print_fnc.py
|
458
|
1318
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
functions = {
'today': lambda x: time.strftime('%d/%m/%Y', time.localtime()).decode('latin1')
}
#
# TODO: call an object internal function too
#
def print_fnc(fnc, arg):
if fnc in functions:
return functions[fnc](arg)
return ''
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
199,
646,
900,
199,
199,
5777,
275,
469,
272,
283,
8136,
356,
2400,
671,
26,
900,
14,
6205,
3508,
68,
3149,
77,
3149,
57,
297,
900,
14,
15198,
8801,
2708,
360,
10378,
17,
358,
199,
93,
199,
199,
3,
199,
3,
3254,
26,
1240,
376,
909,
5007,
805,
4634,
199,
3,
199,
318,
870,
63,
2324,
67,
8,
2324,
67,
12,
1680,
304,
272,
340,
4325,
67,
315,
3423,
26,
267,
372,
3423,
59,
2324,
67,
8738,
1273,
9,
272,
372,
2125,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
199,
646,
900,
199,
199,
5777,
275,
469,
272,
283,
8136,
356,
2400,
671,
26,
900,
14,
6205,
3508,
68,
3149,
77,
3149,
57,
297,
900,
14,
15198,
8801,
2708,
360,
10378,
17,
358,
199,
93,
199,
199,
3,
199,
3,
3254,
26,
1240,
376,
909,
5007,
805,
4634,
199,
3,
199,
318,
870,
63,
2324,
67,
8,
2324,
67,
12,
1680,
304,
272,
340,
4325,
67,
315,
3423,
26,
267,
372,
3423,
59,
2324,
67,
8738,
1273,
9,
272,
372,
2125,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
csrocha/OpenUpgrade
|
addons/l10n_ca/__init__.py
|
438
|
1056
|
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2010 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
#
# 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/>.
#
##############################################################################
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
7129,
428,
1214,
19142,
13,
667,
3621,
10130,
8642,
1014,
921,
1544,
14,
23374,
19142,
667,
3621,
5135,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
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,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
7129,
428,
1214,
19142,
13,
667,
3621,
10130,
8642,
1014,
921,
1544,
14,
23374,
19142,
667,
3621,
5135,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
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,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
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|
networking_odl/tests/unit/common/test_client.py
|
1
|
2166
|
# Copyright (c) 2015 Intel Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_config import cfg
from oslo_config import fixture as config_fixture
from networking_odl.common import client
from neutron.tests import base
class ClientTestCase(base.DietTestCase):
def setUp(self):
self.cfg = self.useFixture(config_fixture.Config())
self.cfg.config(mechanism_drivers=[
'logger', 'opendaylight_v2'], group='ml2')
super(ClientTestCase, self).setUp()
def _set_config(self, url='http://127.0.0.1:9999', username='someuser',
password='somepass'):
self.cfg.config(url=url, group='ml2_odl')
self.cfg.config(username=username, group='ml2_odl')
self.cfg.config(password=password, group='ml2_odl')
def _test_missing_config(self, **kwargs):
self._set_config(**kwargs)
self.assertRaisesRegex(cfg.RequiredOptError,
r'value required for option \w+ in group '
r'\[ml2_odl\]',
client.OpenDaylightRestClient._check_opt,
cfg.CONF.ml2_odl.url)
def test_valid_config(self):
self._set_config()
client.OpenDaylightRestClient._check_opt(cfg.CONF.ml2_odl.url)
def test_missing_url_raises_exception(self):
self._test_missing_config(url=None)
def test_missing_username_raises_exception(self):
self._test_missing_config(username=None)
def test_missing_password_raises_exception(self):
self._test_missing_config(password=None)
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6900,
20619,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
11258,
63,
888,
492,
4810,
199,
504,
11258,
63,
888,
492,
10949,
465,
1101,
63,
5997,
199,
199,
504,
2784,
316,
63,
364,
76,
14,
2330,
492,
1890,
199,
199,
504,
8224,
14,
2219,
492,
1300,
421,
199,
533,
6810,
1746,
8,
1095,
14,
1341,
386,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
4128,
275,
291,
14,
31015,
8,
888,
63,
5997,
14,
2028,
1012,
267,
291,
14,
4128,
14,
888,
8,
278,
11993,
63,
13337,
1524,
717,
283,
2921,
297,
283,
411,
500,
1187,
4040,
63,
86,
18,
995,
1572,
534,
757,
18,
358,
267,
1613,
8,
3041,
1746,
12,
291,
680,
5996,
342,
339,
347,
485,
409,
63,
888,
8,
277,
12,
1166,
534,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
5008,
297,
3434,
534,
3972,
751,
297,
490,
2505,
534,
3972,
1529,
735,
267,
291,
14,
4128,
14,
888,
8,
633,
29,
633,
12,
1572,
534,
757,
18,
63,
364,
76,
358,
267,
291,
14,
4128,
14,
888,
8,
2473,
29,
2473,
12,
1572,
534,
757,
18,
63,
364,
76,
358,
267,
291,
14,
4128,
14,
888,
8,
2060,
29,
2060,
12,
1572,
534,
757,
18,
63,
364,
76,
358,
339,
347,
485,
396,
63,
4752,
63,
888,
8,
277,
12,
1011,
958,
304,
267,
291,
423,
409,
63,
888,
3682,
958,
9,
267,
291,
14,
16499,
8,
4128,
14,
8030,
9985,
547,
12,
3044,
519,
7,
585,
1415,
367,
945,
971,
87,
11,
315,
1572,
283,
3044,
519,
30181,
757,
18,
63,
364,
76,
60,
4300,
3044,
1890,
14,
4299,
12631,
4040,
13726,
3041,
423,
1074,
63,
2992,
12,
3044,
4810,
14,
3103,
14,
757,
18,
63,
364,
76,
14,
633,
9,
339,
347,
511,
63,
1078,
63,
888,
8,
277,
304,
267,
291,
423,
409,
63,
888,
342,
267,
1890,
14,
4299,
12631,
4040,
13726,
3041,
423,
1074,
63,
2992,
8,
4128,
14,
3103,
14,
757,
18,
63,
364,
76,
14,
633,
9,
339,
347,
511,
63,
4752,
63,
633,
63,
3536,
63,
1971,
8,
277,
304,
267,
291,
423,
396,
63,
4752,
63,
888,
8,
633,
29,
403,
9,
339,
347,
511,
63,
4752,
63,
2473,
63,
3536,
63,
1971,
8,
277,
304,
267,
291,
423,
396,
63,
4752,
63,
888,
8,
2473,
29,
403,
9,
339,
347,
511,
63,
4752,
63,
2060,
63,
3536,
63,
1971,
8,
277,
304,
267,
291,
423,
396,
63,
4752,
63,
888,
8,
2060,
29,
403,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
6900,
20619,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
11258,
63,
888,
492,
4810,
199,
504,
11258,
63,
888,
492,
10949,
465,
1101,
63,
5997,
199,
199,
504,
2784,
316,
63,
364,
76,
14,
2330,
492,
1890,
199,
199,
504,
8224,
14,
2219,
492,
1300,
421,
199,
533,
6810,
1746,
8,
1095,
14,
1341,
386,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
4128,
275,
291,
14,
31015,
8,
888,
63,
5997,
14,
2028,
1012,
267,
291,
14,
4128,
14,
888,
8,
278,
11993,
63,
13337,
1524,
717,
283,
2921,
297,
283,
411,
500,
1187,
4040,
63,
86,
18,
995,
1572,
534,
757,
18,
358,
267,
1613,
8,
3041,
1746,
12,
291,
680,
5996,
342,
339,
347,
485,
409,
63,
888,
8,
277,
12,
1166,
534,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
5008,
297,
3434,
534,
3972,
751,
297,
490,
2505,
534,
3972,
1529,
735,
267,
291,
14,
4128,
14,
888,
8,
633,
29,
633,
12,
1572,
534,
757,
18,
63,
364,
76,
358,
267,
291,
14,
4128,
14,
888,
8,
2473,
29,
2473,
12,
1572,
534,
757,
18,
63,
364,
76,
358,
267,
291,
14,
4128,
14,
888,
8,
2060,
29,
2060,
12,
1572,
534,
757,
18,
63,
364,
76,
358,
339,
347,
485,
396,
63,
4752,
63,
888,
8,
277,
12,
1011,
958,
304,
267,
291,
423,
409,
63,
888,
3682,
958,
9,
267,
291,
14,
16499,
8,
4128,
14,
8030,
9985,
547,
12,
3044,
519,
7,
585,
1415,
367,
945,
971,
87,
11,
315,
1572,
283,
3044,
519,
30181,
757,
18,
63,
364,
76,
60,
4300,
3044,
1890,
14,
4299,
12631,
4040,
13726,
3041,
423,
1074,
63,
2992,
12,
3044,
4810,
14,
3103,
14,
757,
18,
63,
364,
76,
14,
633,
9,
339,
347,
511,
63,
1078,
63,
888,
8,
277,
304,
267,
291,
423,
409,
63,
888,
342,
267,
1890,
14,
4299,
12631,
4040,
13726,
3041,
423,
1074,
63,
2992,
8,
4128,
14,
3103,
14,
757,
18,
63,
364,
76,
14,
633,
9,
339,
347,
511,
63,
4752,
63,
633,
63,
3536,
63,
1971,
8,
277,
304,
267,
291,
423,
396,
63,
4752,
63,
888,
8,
633,
29,
403,
9,
339,
347,
511,
63,
4752,
63,
2473,
63,
3536,
63,
1971,
8,
277,
304,
267,
291,
423,
396,
63,
4752,
63,
888,
8,
2473,
29,
403,
9,
339,
347,
511,
63,
4752,
63,
2060,
63,
3536,
63,
1971,
8,
277,
304,
267,
291,
423,
396,
63,
4752,
63,
888,
8,
2060,
29,
403,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,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0,
0,
0,
0
] |
Collisio-Adolebitque/pfne-2017
|
pynet/pyth_ans_ecourse/napalm/napalm_ex2.py
|
2
|
1058
|
#!/usr/bin/env python
"""Test NAPALM config merge operations on one of the Cisco routers."""
from napalm_base import get_network_driver
from my_devices import pynet_rtr1
def main():
"""Test NAPALM config merge operations on one of the Cisco routers."""
for a_device in (pynet_rtr1,):
device_type = a_device.pop('device_type')
driver = get_network_driver(device_type)
device = driver(**a_device)
print
print ">>>Device open"
device.open()
print
print ">>>Load config change (merge) - no commit"
device.load_merge_candidate(filename='cisco_merge.txt')
print device.compare_config()
print
print ">>>Discard config change (merge)"
device.discard_config()
print device.compare_config()
print
print ">>>Load config change (merge) - commit"
device.load_merge_candidate(filename='cisco_merge.txt')
print device.compare_config()
device.commit_config()
print
if __name__ == "__main__":
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
774,
653,
1282,
748,
45,
1101,
5389,
5331,
641,
1373,
402,
314,
28356,
24464,
1041,
199,
504,
302,
439,
279,
77,
63,
1095,
492,
664,
63,
1200,
63,
3090,
199,
504,
3002,
63,
6410,
492,
1134,
846,
63,
82,
454,
17,
199,
199,
318,
2446,
837,
272,
408,
774,
653,
1282,
748,
45,
1101,
5389,
5331,
641,
1373,
402,
314,
28356,
24464,
1041,
272,
367,
282,
63,
1782,
315,
334,
647,
846,
63,
82,
454,
17,
16095,
267,
2243,
63,
466,
275,
282,
63,
1782,
14,
1935,
360,
1782,
63,
466,
358,
267,
5253,
275,
664,
63,
1200,
63,
3090,
8,
1782,
63,
466,
9,
267,
2243,
275,
5253,
3682,
65,
63,
1782,
9,
398,
870,
267,
870,
298,
6071,
2510,
1551,
2,
267,
2243,
14,
1490,
342,
398,
870,
267,
870,
298,
6071,
6200,
1101,
1570,
334,
5628,
9,
446,
949,
5532,
2,
267,
2243,
14,
912,
63,
5628,
63,
9007,
8,
1501,
534,
19597,
63,
5628,
14,
2424,
358,
267,
870,
2243,
14,
5785,
63,
888,
342,
398,
870,
267,
870,
298,
6071,
2825,
5841,
1101,
1570,
334,
5628,
2924,
267,
2243,
14,
14394,
63,
888,
342,
267,
870,
2243,
14,
5785,
63,
888,
342,
398,
870,
267,
870,
298,
6071,
6200,
1101,
1570,
334,
5628,
9,
446,
5532,
2,
267,
2243,
14,
912,
63,
5628,
63,
9007,
8,
1501,
534,
19597,
63,
5628,
14,
2424,
358,
267,
870,
2243,
14,
5785,
63,
888,
342,
267,
2243,
14,
3543,
63,
888,
342,
339,
870,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
774,
653,
1282,
748,
45,
1101,
5389,
5331,
641,
1373,
402,
314,
28356,
24464,
1041,
199,
504,
302,
439,
279,
77,
63,
1095,
492,
664,
63,
1200,
63,
3090,
199,
504,
3002,
63,
6410,
492,
1134,
846,
63,
82,
454,
17,
199,
199,
318,
2446,
837,
272,
408,
774,
653,
1282,
748,
45,
1101,
5389,
5331,
641,
1373,
402,
314,
28356,
24464,
1041,
272,
367,
282,
63,
1782,
315,
334,
647,
846,
63,
82,
454,
17,
16095,
267,
2243,
63,
466,
275,
282,
63,
1782,
14,
1935,
360,
1782,
63,
466,
358,
267,
5253,
275,
664,
63,
1200,
63,
3090,
8,
1782,
63,
466,
9,
267,
2243,
275,
5253,
3682,
65,
63,
1782,
9,
398,
870,
267,
870,
298,
6071,
2510,
1551,
2,
267,
2243,
14,
1490,
342,
398,
870,
267,
870,
298,
6071,
6200,
1101,
1570,
334,
5628,
9,
446,
949,
5532,
2,
267,
2243,
14,
912,
63,
5628,
63,
9007,
8,
1501,
534,
19597,
63,
5628,
14,
2424,
358,
267,
870,
2243,
14,
5785,
63,
888,
342,
398,
870,
267,
870,
298,
6071,
2825,
5841,
1101,
1570,
334,
5628,
2924,
267,
2243,
14,
14394,
63,
888,
342,
267,
870,
2243,
14,
5785,
63,
888,
342,
398,
870,
267,
870,
298,
6071,
6200,
1101,
1570,
334,
5628,
9,
446,
5532,
2,
267,
2243,
14,
912,
63,
5628,
63,
9007,
8,
1501,
534,
19597,
63,
5628,
14,
2424,
358,
267,
870,
2243,
14,
5785,
63,
888,
342,
267,
2243,
14,
3543,
63,
888,
342,
339,
870,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
USGSDenverPychron/pychron
|
pychron/core/filtering.py
|
1
|
3462
|
# ===============================================================================
# Copyright 2015 Jake Ross
#
# 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.
# ===============================================================================
# ============= enthought library imports =======================
import re
from numpy import ma
# ============= standard library imports ========================
# ============= local library imports ==========================
def filter_items(items, predicate_str, return_indices=True):
omits = []
if predicate_str:
match = re.search(r'(?P<name>[A-Za-z])', predicate_str)
if match:
variable_name = match.group('name')
omits = [(eval(predicate_str, {variable_name: yi}), i) for i, yi in enumerate(items)]
omits = [idx for ti, idx in omits if ti]
if not return_indices:
omits = [items[i] for i in omits]
return omits
regex = re.compile(r'error|percent_error|(?! and| or)[A-Za-z]+')
def validate_filter_predicate(predicate):
attr = regex.findall(predicate)
ctx = {}
for ai in attr:
ctx[ai] = 1
try:
eval(predicate, ctx)
return True
except BaseException:
pass
def filter_ufloats(items, predicate_str, return_indices=True):
"""
return a list of omitted indices (or values) where predicate evaluates to true
:param items: a list of 2-tuples
:param predicate_str: predicate to perform filtering. item is included in the returned list if predicate evaluates
True.
:param return_indices:
:return: a list of omitted indices if return_indices is True or a list of omitted items
"""
attrs = regex.findall(predicate_str)
def make_ctx(v, e):
ctx = {}
for ai in attrs:
if ai == 'error':
ctx[ai] = e
elif ai == 'percent_error':
ctx[ai] = e / v * 100 if v else 0
else:
ctx[ai] = v
return ctx
omits = [(i, eval(predicate_str, make_ctx(*uf))) for i, uf in enumerate(items)]
omits = [idx for idx, ti in omits if ti]
if not return_indices:
omits = [items[i] for i in omits]
return omits
def sigma_filter(vs, nsigma):
mean = vs.mean()
s = vs.std()
ds = abs(vs - mean)
omits = ma.where(ds > (s * nsigma))[0]
return list(omits)
if __name__ == '__main__':
x = ma.array([1, 1, 1, 1, 1, 10], mask=False)
x.mask[5] = True
o = sigma_filter(x, 1)
# filter_objects([], 'x.error>10')
# print filter_ufloats([(1,1),(10,11), (20,1)], 'age>10')
# print filter_objects([(1,1),(10,11), (20,1)], 'x>10 or error>10')
# print filter_objects([(1,1),(10,1), (20,11)], 'x>10 and error>10')
# filter_objects([], 'x>10 and error>10')
# filter_objects([], 'x>10 and percent_error>10')
# print filter_items([1, 10, 20], '10<x or x<5')
# ============= EOF =============================================
|
apache-2.0
|
[
3,
7819,
17224,
199,
3,
1898,
6900,
1603,
1728,
6848,
385,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
7819,
17224,
199,
199,
3,
275,
5769,
655,
273,
20816,
3555,
8925,
16248,
23476,
199,
646,
295,
199,
199,
504,
2680,
492,
610,
421,
199,
3,
275,
5769,
4465,
3555,
8925,
16248,
18673,
199,
3,
275,
5769,
2257,
3555,
8925,
221,
16248,
15495,
421,
199,
318,
2457,
63,
1744,
8,
1744,
12,
11944,
63,
495,
12,
372,
63,
4108,
29,
549,
304,
272,
19413,
83,
275,
942,
272,
340,
11944,
63,
495,
26,
267,
1336,
275,
295,
14,
1733,
8,
82,
10120,
48,
28,
354,
9514,
33,
13,
13163,
13,
90,
22206,
11944,
63,
495,
9,
267,
340,
1336,
26,
288,
1750,
63,
354,
275,
1336,
14,
923,
360,
354,
358,
288,
19413,
83,
275,
3842,
2579,
8,
14463,
63,
495,
12,
469,
1975,
63,
354,
26,
28008,
8688,
284,
9,
367,
284,
12,
28008,
315,
3874,
8,
1744,
1874,
288,
19413,
83,
275,
359,
2996,
367,
3367,
12,
4280,
315,
19413,
83,
340,
3367,
61,
288,
340,
440,
372,
63,
4108,
26,
355,
19413,
83,
275,
359,
1744,
59,
73,
61,
367,
284,
315,
19413,
83,
61,
339,
372,
19413,
83,
421,
199,
3821,
275,
295,
14,
2014,
8,
82,
7,
705,
92,
7045,
63,
705,
92,
26313,
436,
92,
503,
2788,
33,
13,
13163,
13,
90,
2807,
358,
421,
199,
318,
4107,
63,
1541,
63,
14463,
8,
14463,
304,
272,
1921,
275,
5163,
14,
6452,
8,
14463,
9,
272,
4027,
275,
1052,
272,
367,
15933,
315,
1921,
26,
267,
4027,
59,
5789,
61,
275,
413,
339,
862,
26,
267,
3468,
8,
14463,
12,
4027,
9,
267,
372,
715,
272,
871,
25416,
26,
267,
986,
421,
199,
318,
2457,
63,
1286,
1088,
83,
8,
1744,
12,
11944,
63,
495,
12,
372,
63,
4108,
29,
549,
304,
272,
408,
272,
372,
282,
769,
402,
11684,
4918,
334,
269,
1338,
9,
2382,
11944,
22014,
370,
2549,
339,
520,
635,
2974,
26,
282,
769,
402,
499,
13,
11760,
272,
520,
635,
11944,
63,
495,
26,
11944,
370,
5147,
14545,
14,
1242,
365,
5120,
315,
314,
2138,
769,
340,
11944,
22014,
272,
715,
14,
272,
520,
635,
372,
63,
4108,
26,
272,
520,
1107,
26,
282,
769,
402,
11684,
4918,
340,
372,
63,
4108,
365,
715,
503,
282,
769,
402,
11684,
2974,
272,
408,
272,
3290,
275,
5163,
14,
6452,
8,
14463,
63,
495,
9,
339,
347,
1852,
63,
3799,
8,
86,
12,
325,
304,
267,
4027,
275,
1052,
267,
367,
15933,
315,
3290,
26,
288,
340,
15933,
508,
283,
705,
356,
355,
4027,
59,
5789,
61,
275,
325,
288,
916,
15933,
508,
283,
7045,
63,
705,
356,
355,
4027,
59,
5789,
61,
275,
325,
1182,
373,
627,
2948,
340,
373,
587,
378,
288,
587,
26,
355,
4027,
59,
5789,
61,
275,
373,
267,
372,
4027,
339,
19413,
83,
275,
3842,
73,
12,
3468,
8,
14463,
63,
495,
12,
1852,
63,
3799,
2031,
1286,
1724,
367,
284,
12,
399,
70,
315,
3874,
8,
1744,
1874,
272,
19413,
83,
275,
359,
2996,
367,
4280,
12,
3367,
315,
19413,
83,
340,
3367,
61,
272,
340,
440,
372,
63,
4108,
26,
267,
19413,
83,
275,
359,
1744,
59,
73,
61,
367,
284,
315,
19413,
83,
61,
339,
372,
19413,
83,
421,
199,
318,
10819,
63,
1541,
8,
3122,
12,
302,
9412,
304,
272,
4615,
275,
8118,
14,
3670,
342,
272,
308,
275,
8118,
14,
1516,
342,
272,
6364,
275,
2853,
8,
3122,
446,
4615,
9,
272,
19413,
83,
275,
610,
14,
4509,
8,
795,
690,
334,
83,
627,
302,
9412,
11515,
16,
61,
272,
372,
769,
8,
676,
1405,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
671,
275,
610,
14,
1144,
779,
17,
12,
413,
12,
413,
12,
413,
12,
413,
12,
1616,
467,
3656,
29,
797,
9,
272,
671,
14,
2629,
59,
21,
61,
275,
715,
272,
312,
275,
10819,
63,
1541,
8,
88,
12,
413,
9,
199,
199,
3,
2457,
63,
1462,
8798,
283,
88,
14,
705,
30,
709,
358,
199,
3,
870,
2457,
63,
1286,
1088,
83,
7694,
17,
12,
17,
11865,
709,
12,
845,
395,
334,
1165,
12,
17,
4360,
283,
474,
30,
709,
358,
199,
3,
870,
2457,
63,
1462,
7694,
17,
12,
17,
11865,
709,
12,
845,
395,
334,
1165,
12,
17,
4360,
283,
88,
30,
709,
503,
1125,
30,
709,
358,
199,
3,
870,
2457,
63,
1462,
7694,
17,
12,
17,
11865,
709,
12,
17,
395,
334,
1165,
12,
845,
4360,
283,
88,
30,
709,
436,
1125,
30,
709,
358,
199,
3,
2457,
63,
1462,
8798,
283,
88,
30,
709,
436,
1125,
30,
709,
358,
199,
3,
2457,
63,
1462,
8798,
283,
88,
30,
709,
436,
8878,
63,
705,
30,
709,
358,
199,
199,
3,
870,
2457,
63,
1744,
779,
17,
12,
1616,
12,
3388,
467,
283,
709,
28,
88,
503,
671,
28,
21,
358,
199,
3,
275,
5769,
9027,
19469,
5769,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
7819,
17224,
199,
3,
1898,
6900,
1603,
1728,
6848,
385,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
7819,
17224,
199,
199,
3,
275,
5769,
655,
273,
20816,
3555,
8925,
16248,
23476,
199,
646,
295,
199,
199,
504,
2680,
492,
610,
421,
199,
3,
275,
5769,
4465,
3555,
8925,
16248,
18673,
199,
3,
275,
5769,
2257,
3555,
8925,
221,
16248,
15495,
421,
199,
318,
2457,
63,
1744,
8,
1744,
12,
11944,
63,
495,
12,
372,
63,
4108,
29,
549,
304,
272,
19413,
83,
275,
942,
272,
340,
11944,
63,
495,
26,
267,
1336,
275,
295,
14,
1733,
8,
82,
10120,
48,
28,
354,
9514,
33,
13,
13163,
13,
90,
22206,
11944,
63,
495,
9,
267,
340,
1336,
26,
288,
1750,
63,
354,
275,
1336,
14,
923,
360,
354,
358,
288,
19413,
83,
275,
3842,
2579,
8,
14463,
63,
495,
12,
469,
1975,
63,
354,
26,
28008,
8688,
284,
9,
367,
284,
12,
28008,
315,
3874,
8,
1744,
1874,
288,
19413,
83,
275,
359,
2996,
367,
3367,
12,
4280,
315,
19413,
83,
340,
3367,
61,
288,
340,
440,
372,
63,
4108,
26,
355,
19413,
83,
275,
359,
1744,
59,
73,
61,
367,
284,
315,
19413,
83,
61,
339,
372,
19413,
83,
421,
199,
3821,
275,
295,
14,
2014,
8,
82,
7,
705,
92,
7045,
63,
705,
92,
26313,
436,
92,
503,
2788,
33,
13,
13163,
13,
90,
2807,
358,
421,
199,
318,
4107,
63,
1541,
63,
14463,
8,
14463,
304,
272,
1921,
275,
5163,
14,
6452,
8,
14463,
9,
272,
4027,
275,
1052,
272,
367,
15933,
315,
1921,
26,
267,
4027,
59,
5789,
61,
275,
413,
339,
862,
26,
267,
3468,
8,
14463,
12,
4027,
9,
267,
372,
715,
272,
871,
25416,
26,
267,
986,
421,
199,
318,
2457,
63,
1286,
1088,
83,
8,
1744,
12,
11944,
63,
495,
12,
372,
63,
4108,
29,
549,
304,
272,
408,
272,
372,
282,
769,
402,
11684,
4918,
334,
269,
1338,
9,
2382,
11944,
22014,
370,
2549,
339,
520,
635,
2974,
26,
282,
769,
402,
499,
13,
11760,
272,
520,
635,
11944,
63,
495,
26,
11944,
370,
5147,
14545,
14,
1242,
365,
5120,
315,
314,
2138,
769,
340,
11944,
22014,
272,
715,
14,
272,
520,
635,
372,
63,
4108,
26,
272,
520,
1107,
26,
282,
769,
402,
11684,
4918,
340,
372,
63,
4108,
365,
715,
503,
282,
769,
402,
11684,
2974,
272,
408,
272,
3290,
275,
5163,
14,
6452,
8,
14463,
63,
495,
9,
339,
347,
1852,
63,
3799,
8,
86,
12,
325,
304,
267,
4027,
275,
1052,
267,
367,
15933,
315,
3290,
26,
288,
340,
15933,
508,
283,
705,
356,
355,
4027,
59,
5789,
61,
275,
325,
288,
916,
15933,
508,
283,
7045,
63,
705,
356,
355,
4027,
59,
5789,
61,
275,
325,
1182,
373,
627,
2948,
340,
373,
587,
378,
288,
587,
26,
355,
4027,
59,
5789,
61,
275,
373,
267,
372,
4027,
339,
19413,
83,
275,
3842,
73,
12,
3468,
8,
14463,
63,
495,
12,
1852,
63,
3799,
2031,
1286,
1724,
367,
284,
12,
399,
70,
315,
3874,
8,
1744,
1874,
272,
19413,
83,
275,
359,
2996,
367,
4280,
12,
3367,
315,
19413,
83,
340,
3367,
61,
272,
340,
440,
372,
63,
4108,
26,
267,
19413,
83,
275,
359,
1744,
59,
73,
61,
367,
284,
315,
19413,
83,
61,
339,
372,
19413,
83,
421,
199,
318,
10819,
63,
1541,
8,
3122,
12,
302,
9412,
304,
272,
4615,
275,
8118,
14,
3670,
342,
272,
308,
275,
8118,
14,
1516,
342,
272,
6364,
275,
2853,
8,
3122,
446,
4615,
9,
272,
19413,
83,
275,
610,
14,
4509,
8,
795,
690,
334,
83,
627,
302,
9412,
11515,
16,
61,
272,
372,
769,
8,
676,
1405,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
671,
275,
610,
14,
1144,
779,
17,
12,
413,
12,
413,
12,
413,
12,
413,
12,
1616,
467,
3656,
29,
797,
9,
272,
671,
14,
2629,
59,
21,
61,
275,
715,
272,
312,
275,
10819,
63,
1541,
8,
88,
12,
413,
9,
199,
199,
3,
2457,
63,
1462,
8798,
283,
88,
14,
705,
30,
709,
358,
199,
3,
870,
2457,
63,
1286,
1088,
83,
7694,
17,
12,
17,
11865,
709,
12,
845,
395,
334,
1165,
12,
17,
4360,
283,
474,
30,
709,
358,
199,
3,
870,
2457,
63,
1462,
7694,
17,
12,
17,
11865,
709,
12,
845,
395,
334,
1165,
12,
17,
4360,
283,
88,
30,
709,
503,
1125,
30,
709,
358,
199,
3,
870,
2457,
63,
1462,
7694,
17,
12,
17,
11865,
709,
12,
17,
395,
334,
1165,
12,
845,
4360,
283,
88,
30,
709,
436,
1125,
30,
709,
358,
199,
3,
2457,
63,
1462,
8798,
283,
88,
30,
709,
436,
1125,
30,
709,
358,
199,
3,
2457,
63,
1462,
8798,
283,
88,
30,
709,
436,
8878,
63,
705,
30,
709,
358,
199,
199,
3,
870,
2457,
63,
1744,
779,
17,
12,
1616,
12,
3388,
467,
283,
709,
28,
88,
503,
671,
28,
21,
358,
199,
3,
275,
5769,
9027,
19469,
5769,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ahamilton55/ansible
|
test/runner/lib/git.py
|
40
|
2324
|
"""Wrapper around git command-line tools."""
from __future__ import absolute_import, print_function
from lib.util import (
CommonConfig,
SubprocessError,
run_command,
)
class Git(object):
"""Wrapper around git command-line tools."""
def __init__(self, args):
"""
:type args: CommonConfig
"""
self.args = args
self.git = 'git'
def get_diff(self, args):
"""
:type args: list[str]
:rtype: list[str]
"""
cmd = ['diff'] + args
return self.run_git_split(cmd, '\n')
def get_diff_names(self, args):
"""
:type args: list[str]
:rtype: list[str]
"""
cmd = ['diff', '--name-only', '--no-renames', '-z'] + args
return self.run_git_split(cmd, '\0')
def get_file_names(self, args):
"""
:type args: list[str]
:rtype: list[str]
"""
cmd = ['ls-files', '-z'] + args
return self.run_git_split(cmd, '\0')
def get_branches(self):
"""
:rtype: list[str]
"""
cmd = ['for-each-ref', 'refs/heads/', '--format', '%(refname:strip=2)']
return self.run_git_split(cmd)
def get_branch(self):
"""
:rtype: str
"""
cmd = ['symbolic-ref', '--short', 'HEAD']
return self.run_git(cmd).strip()
def get_branch_fork_point(self, branch):
"""
:type branch: str
:rtype: str
"""
cmd = ['merge-base', '--fork-point', branch]
return self.run_git(cmd).strip()
def is_valid_ref(self, ref):
"""
:type ref: str
:rtype: bool
"""
cmd = ['show', ref]
try:
self.run_git(cmd)
return True
except SubprocessError:
return False
def run_git_split(self, cmd, separator=None):
"""
:type cmd: list[str]
:param separator: str | None
:rtype: list[str]
"""
output = self.run_git(cmd).strip(separator)
if not output:
return []
return output.split(separator)
def run_git(self, cmd):
"""
:type cmd: list[str]
:rtype: str
"""
return run_command(self.args, [self.git] + cmd, capture=True, always=True)[0]
|
gpl-3.0
|
[
624,
4590,
6818,
6135,
1414,
13,
604,
7249,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
504,
1973,
14,
1974,
492,
334,
272,
13964,
2028,
12,
272,
4804,
1412,
547,
12,
272,
1255,
63,
1531,
12,
199,
9,
421,
199,
533,
12579,
8,
785,
304,
272,
408,
4590,
6818,
6135,
1414,
13,
604,
7249,
1041,
272,
347,
636,
826,
721,
277,
12,
1249,
304,
267,
408,
267,
520,
466,
1249,
26,
13964,
2028,
267,
408,
267,
291,
14,
589,
275,
1249,
267,
291,
14,
3187,
275,
283,
3187,
7,
339,
347,
664,
63,
3028,
8,
277,
12,
1249,
304,
267,
408,
267,
520,
466,
1249,
26,
769,
59,
495,
61,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
2088,
275,
788,
3028,
418,
435,
1249,
267,
372,
291,
14,
1065,
63,
3187,
63,
1294,
8,
1760,
12,
1557,
78,
358,
339,
347,
664,
63,
3028,
63,
1247,
8,
277,
12,
1249,
304,
267,
408,
267,
520,
466,
1249,
26,
769,
59,
495,
61,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
2088,
275,
788,
3028,
297,
2850,
354,
13,
2118,
297,
2850,
889,
13,
264,
1247,
297,
2475,
90,
418,
435,
1249,
267,
372,
291,
14,
1065,
63,
3187,
63,
1294,
8,
1760,
12,
1557,
16,
358,
339,
347,
664,
63,
493,
63,
1247,
8,
277,
12,
1249,
304,
267,
408,
267,
520,
466,
1249,
26,
769,
59,
495,
61,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
2088,
275,
788,
478,
13,
1725,
297,
2475,
90,
418,
435,
1249,
267,
372,
291,
14,
1065,
63,
3187,
63,
1294,
8,
1760,
12,
1557,
16,
358,
339,
347,
664,
63,
16896,
8,
277,
304,
267,
408,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
2088,
275,
788,
509,
13,
10885,
13,
1121,
297,
283,
7655,
15,
17033,
3678,
2850,
908,
297,
9487,
29124,
26,
1913,
29,
18,
9,
418,
267,
372,
291,
14,
1065,
63,
3187,
63,
1294,
8,
1760,
9,
339,
347,
664,
63,
4694,
8,
277,
304,
267,
408,
267,
520,
4500,
26,
620,
267,
408,
267,
2088,
275,
788,
22836,
13,
1121,
297,
2850,
3612,
297,
283,
5211,
418,
267,
372,
291,
14,
1065,
63,
3187,
8,
1760,
680,
1913,
342,
339,
347,
664,
63,
4694,
63,
11796,
63,
1403,
8,
277,
12,
5246,
304,
267,
408,
267,
520,
466,
5246,
26,
620,
267,
520,
4500,
26,
620,
267,
408,
267,
2088,
275,
788,
5628,
13,
1095,
297,
2850,
11796,
13,
1403,
297,
5246,
61,
267,
372,
291,
14,
1065,
63,
3187,
8,
1760,
680,
1913,
342,
339,
347,
365,
63,
1078,
63,
1121,
8,
277,
12,
2984,
304,
267,
408,
267,
520,
466,
2984,
26,
620,
267,
520,
4500,
26,
2155,
267,
408,
267,
2088,
275,
788,
2384,
297,
2984,
61,
267,
862,
26,
288,
291,
14,
1065,
63,
3187,
8,
1760,
9,
288,
372,
715,
267,
871,
4804,
1412,
547,
26,
288,
372,
756,
339,
347,
1255,
63,
3187,
63,
1294,
8,
277,
12,
2088,
12,
9432,
29,
403,
304,
267,
408,
267,
520,
466,
2088,
26,
769,
59,
495,
61,
267,
520,
635,
9432,
26,
620,
1204,
488,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
1072,
275,
291,
14,
1065,
63,
3187,
8,
1760,
680,
1913,
8,
9896,
9,
398,
340,
440,
1072,
26,
288,
372,
942,
398,
372,
1072,
14,
1294,
8,
9896,
9,
339,
347,
1255,
63,
3187,
8,
277,
12,
2088,
304,
267,
408,
267,
520,
466,
2088,
26,
769,
59,
495,
61,
267,
520,
4500,
26,
620,
267,
408,
267,
372,
1255,
63,
1531,
8,
277,
14,
589,
12,
359,
277,
14,
3187,
61,
435,
2088,
12,
12296,
29,
549,
12,
3544,
29,
549,
2788,
16,
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
] |
[
4590,
6818,
6135,
1414,
13,
604,
7249,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
504,
1973,
14,
1974,
492,
334,
272,
13964,
2028,
12,
272,
4804,
1412,
547,
12,
272,
1255,
63,
1531,
12,
199,
9,
421,
199,
533,
12579,
8,
785,
304,
272,
408,
4590,
6818,
6135,
1414,
13,
604,
7249,
1041,
272,
347,
636,
826,
721,
277,
12,
1249,
304,
267,
408,
267,
520,
466,
1249,
26,
13964,
2028,
267,
408,
267,
291,
14,
589,
275,
1249,
267,
291,
14,
3187,
275,
283,
3187,
7,
339,
347,
664,
63,
3028,
8,
277,
12,
1249,
304,
267,
408,
267,
520,
466,
1249,
26,
769,
59,
495,
61,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
2088,
275,
788,
3028,
418,
435,
1249,
267,
372,
291,
14,
1065,
63,
3187,
63,
1294,
8,
1760,
12,
1557,
78,
358,
339,
347,
664,
63,
3028,
63,
1247,
8,
277,
12,
1249,
304,
267,
408,
267,
520,
466,
1249,
26,
769,
59,
495,
61,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
2088,
275,
788,
3028,
297,
2850,
354,
13,
2118,
297,
2850,
889,
13,
264,
1247,
297,
2475,
90,
418,
435,
1249,
267,
372,
291,
14,
1065,
63,
3187,
63,
1294,
8,
1760,
12,
1557,
16,
358,
339,
347,
664,
63,
493,
63,
1247,
8,
277,
12,
1249,
304,
267,
408,
267,
520,
466,
1249,
26,
769,
59,
495,
61,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
2088,
275,
788,
478,
13,
1725,
297,
2475,
90,
418,
435,
1249,
267,
372,
291,
14,
1065,
63,
3187,
63,
1294,
8,
1760,
12,
1557,
16,
358,
339,
347,
664,
63,
16896,
8,
277,
304,
267,
408,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
2088,
275,
788,
509,
13,
10885,
13,
1121,
297,
283,
7655,
15,
17033,
3678,
2850,
908,
297,
9487,
29124,
26,
1913,
29,
18,
9,
418,
267,
372,
291,
14,
1065,
63,
3187,
63,
1294,
8,
1760,
9,
339,
347,
664,
63,
4694,
8,
277,
304,
267,
408,
267,
520,
4500,
26,
620,
267,
408,
267,
2088,
275,
788,
22836,
13,
1121,
297,
2850,
3612,
297,
283,
5211,
418,
267,
372,
291,
14,
1065,
63,
3187,
8,
1760,
680,
1913,
342,
339,
347,
664,
63,
4694,
63,
11796,
63,
1403,
8,
277,
12,
5246,
304,
267,
408,
267,
520,
466,
5246,
26,
620,
267,
520,
4500,
26,
620,
267,
408,
267,
2088,
275,
788,
5628,
13,
1095,
297,
2850,
11796,
13,
1403,
297,
5246,
61,
267,
372,
291,
14,
1065,
63,
3187,
8,
1760,
680,
1913,
342,
339,
347,
365,
63,
1078,
63,
1121,
8,
277,
12,
2984,
304,
267,
408,
267,
520,
466,
2984,
26,
620,
267,
520,
4500,
26,
2155,
267,
408,
267,
2088,
275,
788,
2384,
297,
2984,
61,
267,
862,
26,
288,
291,
14,
1065,
63,
3187,
8,
1760,
9,
288,
372,
715,
267,
871,
4804,
1412,
547,
26,
288,
372,
756,
339,
347,
1255,
63,
3187,
63,
1294,
8,
277,
12,
2088,
12,
9432,
29,
403,
304,
267,
408,
267,
520,
466,
2088,
26,
769,
59,
495,
61,
267,
520,
635,
9432,
26,
620,
1204,
488,
267,
520,
4500,
26,
769,
59,
495,
61,
267,
408,
267,
1072,
275,
291,
14,
1065,
63,
3187,
8,
1760,
680,
1913,
8,
9896,
9,
398,
340,
440,
1072,
26,
288,
372,
942,
398,
372,
1072,
14,
1294,
8,
9896,
9,
339,
347,
1255,
63,
3187,
8,
277,
12,
2088,
304,
267,
408,
267,
520,
466,
2088,
26,
769,
59,
495,
61,
267,
520,
4500,
26,
620,
267,
408,
267,
372,
1255,
63,
1531,
8,
277,
14,
589,
12,
359,
277,
14,
3187,
61,
435,
2088,
12,
12296,
29,
549,
12,
3544,
29,
549,
2788,
16,
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,
32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0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
foursquare/pants
|
src/python/pants/backend/jvm/tasks/jar_publish.py
|
1
|
43360
|
# coding=utf-8
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from __future__ import absolute_import, division, print_function, unicode_literals
import functools
import getpass
import hashlib
import os
import pkgutil
import shutil
import sys
from builtins import input, next, object, str
from collections import OrderedDict, defaultdict, namedtuple
from copy import copy
from twitter.common.collections import OrderedSet
from pants.backend.jvm.ossrh_publication_metadata import OSSRHPublicationMetadata
from pants.backend.jvm.targets.exportable_jvm_library import ExportableJvmLibrary
from pants.backend.jvm.targets.jarable import Jarable
from pants.backend.jvm.targets.scala_library import ScalaLibrary
from pants.backend.jvm.tasks.jar_task import JarTask
from pants.backend.jvm.tasks.properties import Properties
from pants.base.build_environment import get_buildroot, get_scm
from pants.base.build_file import BuildFile
from pants.base.exceptions import TaskError
from pants.base.generator import Generator, TemplateData
from pants.build_graph.address import Address
from pants.build_graph.address_lookup_error import AddressLookupError
from pants.build_graph.build_file_parser import BuildFileParser
from pants.build_graph.build_graph import sort_targets
from pants.ivy.bootstrapper import Bootstrapper
from pants.ivy.ivy import Ivy
from pants.task.scm_publish_mixin import Namedver, ScmPublishMixin, Semver
from pants.task.target_restriction_mixins import HasTransitiveOptionMixin, TransitiveOptionRegistrar
from pants.util.dirutil import safe_mkdir, safe_open, safe_rmtree
from pants.util.strutil import ensure_text
_TEMPLATES_RELPATH = os.path.join('templates', 'jar_publish')
class PushDb(object):
@staticmethod
def load(path):
"""Loads a pushdb maintained in a properties file at the given path."""
with open(path, 'r') as props:
properties = Properties.load(props)
return PushDb(properties)
class Entry(object):
def __init__(self, sem_ver, named_ver, named_is_latest, sha, fingerprint):
"""Records the most recent push/release of an artifact.
:param Semver sem_ver: The last semantically versioned release (or Semver(0.0.0))
:param Namedver named_ver: The last named release of this entry (or None)
:param boolean named_is_latest: True if named_ver is the latest, false if sem_ver is
:param string sha: The last Git SHA (or None)
:param string fingerprint: A unique hash for the most recent version of the target.
"""
self.sem_ver = sem_ver
self.named_ver = named_ver
self.named_is_latest = named_is_latest
self.sha = sha
self.fingerprint = fingerprint
def version(self):
if self.named_is_latest:
return self.named_ver
else:
return self.sem_ver
def with_sem_ver(self, sem_ver):
"""Returns a clone of this entry with the given sem_ver marked as the latest."""
return PushDb.Entry(sem_ver, self.named_ver, False, self.sha, self.fingerprint)
def with_named_ver(self, named_ver):
"""Returns a clone of this entry with the given name_ver marked as the latest."""
return PushDb.Entry(self.sem_ver, named_ver, True, self.sha, self.fingerprint)
def with_sha_and_fingerprint(self, sha, fingerprint):
"""Returns a clone of this entry with the given sha and fingerprint."""
return PushDb.Entry(self.sem_ver, self.named_ver, self.named_is_latest, sha, fingerprint)
def __repr__(self):
return '<{}, {}, {}, {}, {}, {}>'.format(
self.__class__.__name__, self.sem_ver, self.named_ver, self.named_is_latest,
self.sha, self.fingerprint)
def __init__(self, props=None):
self._props = props or OrderedDict()
def get_entry(self, target):
"""Given an internal target, return a PushDb.Entry, which might contain defaults."""
db_get, _ = self._accessors_for_target(target)
major = int(db_get('revision.major', '0'))
minor = int(db_get('revision.minor', '0'))
patch = int(db_get('revision.patch', '0'))
snapshot = str(db_get('revision.snapshot', 'false')).lower() == 'true'
named_version = db_get('revision.named_version', None)
named_is_latest = str(db_get('revision.named_is_latest', 'false')).lower() == 'true'
sha = db_get('revision.sha', None)
fingerprint = db_get('revision.fingerprint', None)
sem_ver = Semver(major, minor, patch, snapshot=snapshot)
named_ver = Namedver(named_version) if named_version else None
return self.Entry(sem_ver, named_ver, named_is_latest, sha, fingerprint)
def set_entry(self, target, pushdb_entry):
pe = pushdb_entry
_, db_set = self._accessors_for_target(target)
db_set('revision.major', pe.sem_ver.major)
db_set('revision.minor', pe.sem_ver.minor)
db_set('revision.patch', pe.sem_ver.patch)
db_set('revision.snapshot', str(pe.sem_ver.snapshot).lower())
if pe.named_ver:
db_set('revision.named_version', pe.named_ver.version())
db_set('revision.named_is_latest', str(pe.named_is_latest).lower())
db_set('revision.sha', pe.sha)
db_set('revision.fingerprint', pe.fingerprint)
def _accessors_for_target(self, target):
jar_dep, exported = target.get_artifact_info()
if not exported:
raise ValueError
def key(prefix):
return '{}.{}%{}'.format(prefix, jar_dep.org, jar_dep.name)
def getter(prefix, default=None):
return self._props.get(key(prefix), default)
def setter(prefix, value):
self._props[key(prefix)] = value
return getter, setter
def dump(self, path):
"""Saves the pushdb as a properties file to the given path."""
with open(path, 'w') as props:
Properties.dump(self._props, props)
class PomWriter(object):
def __init__(self, get_db, tag):
self._get_db = get_db
self._tag = tag
def write(self, target, path):
dependencies = OrderedDict()
for internal_dep in target_internal_dependencies(target):
jar = self._as_versioned_jar(internal_dep)
key = (jar.org, jar.name)
dependencies[key] = self._internaldep(jar, internal_dep)
for jar in target.jar_dependencies:
jardep = self._jardep(jar)
if jardep:
key = (jar.org, jar.name, jar.classifier)
dependencies[key] = jardep
target_jar = self._internaldep(self._as_versioned_jar(target), target)
if target_jar:
target_jar = target_jar.extend(dependencies=list(dependencies.values()))
template_relpath = os.path.join(_TEMPLATES_RELPATH, 'pom.xml.mustache')
template_text = pkgutil.get_data(__name__, template_relpath)
generator = Generator(template_text, project=target_jar)
with safe_open(path, 'w') as output:
generator.write(output)
def _as_versioned_jar(self, internal_target):
"""Fetches the jar representation of the given target, and applies the latest pushdb version."""
jar, _ = internal_target.get_artifact_info()
pushdb_entry = self._get_db(internal_target).get_entry(internal_target)
return jar.copy(rev=pushdb_entry.version().version())
def _internaldep(self, jar_dependency, target):
template_data = self._jardep(jar_dependency)
if isinstance(target.provides.publication_metadata, OSSRHPublicationMetadata):
pom = target.provides.publication_metadata
# Forming the project name from the coordinates like this is acceptable as a fallback when
# the user supplies no project name.
# See: http://central.sonatype.org/pages/requirements.html#project-name-description-and-url
name = pom.name or '{}:{}'.format(jar_dependency.org, jar_dependency.name)
template_data = template_data.extend(name=name,
description=pom.description,
url=pom.url,
licenses=pom.licenses,
scm=pom.scm.tagged(self._tag),
developers=pom.developers)
return template_data
def _jardep(self, jar):
return TemplateData(
classifier=jar.classifier,
artifact_id=jar.name,
group_id=jar.org,
version=jar.rev,
scope='compile',
excludes=[TemplateData(org=exclude.org, name=exclude.name)
for exclude in jar.excludes if exclude.name])
def coordinate(org, name, rev=None):
return '{}#{};{}'.format(org, name, rev) if rev else '{}#{}'.format(org, name)
def jar_coordinate(jar, rev=None):
return coordinate(jar.org, jar.name, rev or jar.rev)
def pushdb_coordinate(jar, entry):
return jar_coordinate(jar, rev=entry.version().version())
def target_internal_dependencies(target):
"""Returns internal Jarable dependencies that were "directly" declared.
Directly declared deps are those that are explicitly listed in the definition of a
target, rather than being depended on transitively. But in order to walk through
aggregator targets such as `target`, `dependencies`, or `jar_library`, this recursively
descends the dep graph and stops at Jarable instances."""
for dep in target.dependencies:
if isinstance(dep, Jarable):
yield dep
else:
for childdep in target_internal_dependencies(dep):
yield childdep
class JarPublish(TransitiveOptionRegistrar, HasTransitiveOptionMixin, ScmPublishMixin, JarTask):
"""Publish jars to a maven repository.
At a high-level, pants uses `Apache Ivy <http://ant.apache.org/ivy/>`_ to
publish artifacts to Maven-style repositories. Pants performs prerequisite
tasks like compiling, creating jars, and generating ``pom.xml`` files then
invokes Ivy to actually publish the artifacts, so publishing is largely
configured in ``ivysettings.xml``. ``BUILD`` and ``pants.ini`` files
primarily provide linkage between publishable targets and the
Ivy ``resolvers`` used to publish them.
The following target types are publishable:
`java_library <build_dictionary.html#java_library>`_,
`scala_library <build_dictionary.html#scala_library>`_,
`java_thrift_library <build_dictionary.html#java_thrift_library>`_,
`annotation_processor <build_dictionary.html#annotation_processor>`_.
Targets to publish and their dependencies must be publishable target
types and specify the ``provides`` argument. One exception is
`jar <build_dictionary.html#jar>`_\s - pants will generate a pom file that
depends on the already-published jar.
Example usage: ::
# By default pants will perform a dry-run.
./pants clean-all publish src/java/com/twitter/mybird
# Actually publish.
./pants clean-all publish src/java/com/twitter/mybird --no-publish-dryrun
Please see ``./pants publish -h`` for a detailed description of all
publishing options.
Publishing can be configured with the following options:
* ``--repos`` - Required dictionary of settings for repos that may be pushed to.
* ``--jvm-options`` - Optional list of JVM command-line args when invoking Ivy.
* ``--restrict-push-branches`` - Optional list of branches to restrict publishing to.
Example repos dictionary: ::
repos = {
# repository target name is paired with this key
'myrepo': {
# ivysettings.xml resolver to use for publishing
'resolver': 'maven.example.com',
# address of a Credentials target to use when publishing
'auth': 'address/of/credentials:target',
# help message if unable to initialize the Credentials target.
'help': 'Please check your credentials and try again.',
},
}
"""
class Publication(namedtuple('Publication', ['name', 'classifier', 'ext'])):
"""Represents an artifact publication.
There will be at least 2 of these for any given published coordinate - a pom, and at least one
other artifact.
"""
class DuplicateArtifactError(TaskError):
"""An artifact was defined by two different targets."""
@classmethod
def register_options(cls, register):
super(JarPublish, cls).register_options(register)
# TODO(John Sirois): Support a preview mode that outputs a file with entries like:
# artifact id:
# revision:
# publish: (true|false)
# changelog:
#
# Allow re-running this goal with the file as input to support forcing an arbitrary set of
# revisions and supply of hand edited changelogs.
register('--dryrun', default=True, type=bool,
help='Run through a push without actually pushing artifacts, editing publish dbs or '
'otherwise writing data')
register('--commit', default=True, type=bool,
help='Commit the push db. Turn off for local testing.')
register('--local', metavar='<PATH>',
help='Publish jars to a maven repository on the local filesystem at this path.')
register('--local-snapshot', default=True, type=bool,
help='If --local is specified, publishes jars with -SNAPSHOT revision suffixes.')
register('--named-snapshot', default=None,
help='Publish all artifacts with the given snapshot name, replacing their version. '
'This is not Semantic Versioning compatible, but is easier to consume in cases '
'where many artifacts must align.')
register('--force', type=bool,
help='Force pushing jars even if there have been no changes since the last push.')
register('--override', type=list,
help='Specifies a published jar revision override in the form: '
'([org]#[name]|[target spec])=[new revision] '
'For example, to specify 2 overrides: '
'--override=com.foo.bar#baz=0.1.2 --override=src/java/com/foo/bar/qux=1.0.0')
register('--restart-at',
help='Restart a fail push at the given jar. Jars can be identified by '
'maven coordinate [org]#[name] or target. '
'For example: --restart-at=com.twitter.common#quantity '
'Or: --restart-at=src/java/com/twitter/common/base')
register('--ivy_settings', advanced=True, default=None,
help='Specify a custom ivysettings.xml file to be used when publishing.')
register('--repos', advanced=True, type=dict,
help='Settings for repositories that can be pushed to. See '
'https://pantsbuild.org/publish.html for details.')
register('--publish-extras', advanced=True, type=dict,
help='Extra products to publish. See '
'https://pantsbuild.org/dev_tasks_publish_extras.html for details.')
register('--individual-plugins', advanced=True, type=bool,
help='Extra products to publish as a individual artifact.')
register('--push-postscript', advanced=True, default=None,
help='A post-script to add to pushdb commit messages and push tag commit messages.')
register('--changelog', default=True, type=bool,
help='A changelog.txt file will be created and printed to the console for each '
'artifact published')
register('--prompt', default=True, type=bool,
help='Interactively prompt user before publishing each artifact.')
@classmethod
def prepare(cls, options, round_manager):
super(JarPublish, cls).prepare(options, round_manager)
round_manager.require('jars')
round_manager.require('javadoc')
round_manager.require('scaladoc')
@staticmethod
def _is_exported(target):
return isinstance(target, ExportableJvmLibrary) and target.provides
def __init__(self, *args, **kwargs):
super(JarPublish, self).__init__(*args, **kwargs)
self.cachedir = os.path.join(self.workdir, 'cache')
self._jvm_options = self.get_options().jvm_options
self.log = self.context.log
if self.get_options().local:
local_repo = dict(
resolver='publish_local',
path=os.path.abspath(os.path.expanduser(self.get_options().local)),
confs=['default'],
auth=None
)
self.repos = defaultdict(lambda: local_repo)
self.commit = False
self.local_snapshot = self.get_options().local_snapshot
else:
self.repos = self.get_options().repos
if not self.repos:
raise TaskError(
"This repo is not configured to publish externally! Please configure per\n"
"http://pantsbuild.org/publish.html#authenticating-to-the-artifact-repository,\n"
"by setting --publish-jar-repos=<dict> or re-run with '--publish-jar-local=<dir>'.")
for repo, data in self.repos.items():
auth = data.get('auth')
if auth:
credentials = next(iter(self.context.resolve(auth)))
user = credentials.username(data['resolver'])
password = credentials.password(data['resolver'])
self.context.log.debug('Found auth for repo={} user={}'.format(repo, user))
self.repos[repo]['username'] = user
self.repos[repo]['password'] = password
self.commit = self.get_options().commit
self.push_postscript = self.get_options().push_postscript or ''
self.local_snapshot = False
self.scm = get_scm() if self.commit else None
self.named_snapshot = self.get_options().named_snapshot
if self.named_snapshot:
self.named_snapshot = Namedver.parse(self.named_snapshot)
self.dryrun = self.get_options().dryrun
self.force = self.get_options().force
self.publish_changelog = self.get_options().changelog and self.scm
def parse_jarcoordinate(coordinate):
components = coordinate.split('#', 1)
if len(components) == 2:
org, name = components
return org, name
else:
spec = components[0]
address = Address.parse(spec)
try:
self.context.build_graph.inject_address_closure(address)
target = self.context.build_graph.get_target(address)
if not target:
siblings = self.context.address_mapper.addresses_in_spec_path(address.spec_path)
prompt = 'did you mean' if len(siblings) == 1 else 'maybe you meant one of these'
raise TaskError('{} => {}?:\n {}'.format(address, prompt,
'\n '.join(str(a) for a in siblings)))
if not self._is_exported(target):
raise TaskError('{} is not an exported target'.format(coordinate))
return target.provides.org, target.provides.name
except (BuildFile.BuildFileError,
BuildFileParser.BuildFileParserError,
AddressLookupError) as e:
raise TaskError('{message}\n Problem identifying target at {spec}'
.format(message=e, spec=spec))
self.overrides = {}
if self.get_options().override:
if self.named_snapshot:
raise TaskError('Options --named-snapshot and --override are mutually exclusive!')
def parse_override(override):
try:
coordinate, rev = override.split('=', 1)
try:
# overrides imply semantic versioning
rev = Semver.parse(rev)
except ValueError as e:
raise TaskError('Invalid version {}: {}'.format(rev, e))
return parse_jarcoordinate(coordinate), rev
except ValueError:
raise TaskError('Invalid override: {}'.format(override))
self.overrides.update(parse_override(o) for o in self.get_options().override)
self.restart_at = None
if self.get_options().restart_at:
self.restart_at = parse_jarcoordinate(self.get_options().restart_at)
def confirm_push(self, coord, version):
"""Ask the user if a push should be done for a particular version of a
particular coordinate. Return True if the push should be done"""
if not self.get_options().prompt:
return True
try:
isatty = os.isatty(sys.stdin.fileno())
except ValueError:
# In tests, sys.stdin might not have a fileno
isatty = False
if not isatty:
return True
push = input('\nPublish {} with revision {} ? [y|N] '.format(
coord, version
))
print('\n')
return push.strip().lower() == 'y'
def _copy_artifact(self, tgt, jar, version, typename, suffix='', extension='jar',
artifact_ext='', override_name=None):
"""Copy the products for a target into the artifact path for the jar/version"""
genmap = self.context.products.get(typename)
product_mapping = genmap.get(tgt)
if product_mapping is None:
raise ValueError("No product mapping in {} for {}. "
"You may need to run some other task first".format(typename, tgt))
for basedir, jars in product_mapping.items():
for artifact in jars:
path = self.artifact_path(jar, version, name=override_name, suffix=suffix,
extension=extension, artifact_ext=artifact_ext)
safe_mkdir(os.path.dirname(path))
shutil.copy(os.path.join(basedir, artifact), path)
def _ivy_jvm_options(self, repo):
"""Get the JVM options for ivy authentication, if needed."""
# Get authentication for the publish repo if needed.
if not repo.get('auth'):
# No need to copy here, as this list isn't modified by the caller.
return self._jvm_options
# Create a copy of the options, so that the modification is appropriately transient.
jvm_options = copy(self._jvm_options)
user = repo.get('username')
password = repo.get('password')
if user and password:
jvm_options.append('-Dlogin={}'.format(user))
jvm_options.append('-Dpassword={}'.format(password))
else:
raise TaskError('Unable to publish to {}. {}'
.format(repo.get('resolver'), repo.get('help', '')))
return jvm_options
def publish(self, publications, jar, entry, repo, published):
"""Run ivy to publish a jar. ivyxml_path is the path to the ivy file; published
is a list of jars published so far (including this one). entry is a pushdb entry."""
try:
ivy = Bootstrapper.default_ivy()
except Bootstrapper.Error as e:
raise TaskError('Failed to push {0}! {1}'.format(pushdb_coordinate(jar, entry), e))
path = repo.get('path')
ivysettings = self.generate_ivysettings(ivy, published, publish_local=path)
version = entry.version().version()
ivyxml = self.generate_ivy(jar, version, publications)
resolver = repo['resolver']
args = [
'-settings', ivysettings,
'-ivy', ivyxml,
# Without this setting, the ivy.xml is delivered to the CWD, littering the workspace. We
# don't need the ivy.xml, so just give it path under the workdir we won't use.
'-deliverto', ivyxml + '.unused',
'-publish', resolver,
'-publishpattern', '{}/[organisation]/[module]/'
'[artifact]-[revision](-[classifier]).[ext]'.format(self.workdir),
'-revision', version,
'-m2compatible',
]
# TODO(John Sirois): global logging options should be hidden behind some sort of log manager
# that we can:
# a.) obtain a handle to (dependency injection or manual plumbing)
# b.) query for log detail, ie: `if log_manager.is_verbose:`
if self.get_options().level == 'debug':
args.append('-verbose')
if self.local_snapshot:
args.append('-overwrite')
try:
jvm_options = self._ivy_jvm_options(repo)
ivy.execute(jvm_options=jvm_options, args=args,
workunit_factory=self.context.new_workunit, workunit_name='ivy-publish')
except Ivy.Error as e:
raise TaskError('Failed to push {0}! {1}'.format(pushdb_coordinate(jar, entry), e))
def execute(self):
self.check_clean_master(commit=(not self.dryrun and self.commit))
exported_targets = self.exported_targets()
self.check_targets(exported_targets)
pushdbs = {}
def get_db(tgt):
# TODO(tdesai) Handle resource type in get_db.
if tgt.provides is None:
raise TaskError('trying to publish target {!r} which does not provide an artifact'.format(tgt))
dbfile = tgt.provides.repo.push_db(tgt)
result = pushdbs.get(dbfile)
if not result:
# Create an empty pushdb if no dbfile exists.
if (os.path.exists(dbfile)):
db = PushDb.load(dbfile)
else:
safe_mkdir(os.path.dirname(dbfile))
db = PushDb()
try:
repo = self.repos[tgt.provides.repo.name]
except KeyError:
raise TaskError('Repository {0} has no entry in the --repos option.'.format(
tgt.provides.repo.name))
result = (db, dbfile, repo)
pushdbs[dbfile] = result
return result
def get_pushdb(tgt):
return get_db(tgt)[0]
def fingerprint_internal(tgt):
pushdb = get_pushdb(tgt)
entry = pushdb.get_entry(tgt)
return entry.fingerprint or '0.0.0'
def stage_artifacts(tgt, jar, version, tag, changelog):
publications = OrderedSet()
# TODO Remove this once we fix https://github.com/pantsbuild/pants/issues/1229
if (not self.context.products.get('jars').has(tgt) and
not self.get_options().individual_plugins):
raise TaskError('Expected to find a primary artifact for {} but there was no jar for it.'
.format(tgt.address.reference()))
# TODO Remove this guard once we fix https://github.com/pantsbuild/pants/issues/1229, there
# should always be a primary artifact.
if self.context.products.get('jars').has(tgt):
self._copy_artifact(tgt, jar, version, typename='jars')
publications.add(self.Publication(name=jar.name, classifier=None, ext='jar'))
self.create_source_jar(tgt, jar, version)
publications.add(self.Publication(name=jar.name, classifier='sources', ext='jar'))
# don't request docs unless they are available for all transitive targets
# TODO: doc products should be checked by an independent jar'ing task, and
# conditionally enabled; see https://github.com/pantsbuild/pants/issues/568
doc_jar = self.create_doc_jar(tgt, jar, version)
if doc_jar:
publications.add(self.Publication(name=jar.name, classifier='javadoc', ext='jar'))
if self.publish_changelog:
changelog_path = self.artifact_path(jar, version, suffix='-CHANGELOG', extension='txt')
with safe_open(changelog_path, 'wb') as changelog_file:
changelog_file.write(changelog.encode('utf-8'))
publications.add(self.Publication(name=jar.name, classifier='CHANGELOG', ext='txt'))
# Process any extra jars that might have been previously generated for this target, or a
# target that it was derived from.
for extra_product, extra_config in (self.get_options().publish_extras or {}).items():
override_name = jar.name
if 'override_name' in extra_config:
# If the supplied string has a '{target_provides_name}' in it, replace it with the
# current jar name. If not, the string will be taken verbatim.
override_name = extra_config['override_name'].format(target_provides_name=jar.name)
classifier = None
suffix = ''
if 'classifier' in extra_config:
classifier = extra_config['classifier']
suffix = "-{0}".format(classifier)
extension = extra_config.get('extension', 'jar')
extra_pub = self.Publication(name=override_name, classifier=classifier, ext=extension)
# A lot of flexibility is allowed in parameterizing the extra artifact, ensure those
# parameters lead to a unique publication.
# TODO(John Sirois): Check this much earlier.
if extra_pub in publications:
raise TaskError("publish_extra for '{0}' must override one of name, classifier or "
"extension with a non-default value.".format(extra_product))
# Build a list of targets to check. This list will consist of the current target, plus the
# entire derived_from chain.
target_list = [tgt]
target = tgt
while target.derived_from != target:
target_list.append(target.derived_from)
target = target.derived_from
for cur_tgt in target_list:
if self.context.products.get(extra_product).has(cur_tgt):
self._copy_artifact(cur_tgt, jar, version, typename=extra_product, suffix=suffix,
extension=extension, override_name=override_name)
publications.add(extra_pub)
pom_path = self.artifact_path(jar, version, extension='pom')
PomWriter(get_pushdb, tag).write(tgt, path=pom_path)
return publications
if self.overrides:
print('\nPublishing with revision overrides:')
for (org, name), rev in self.overrides.items():
print('{0}={1}'.format(coordinate(org, name), rev))
head_sha = self.scm.commit_id if self.scm else None
safe_rmtree(self.workdir)
published = []
skip = (self.restart_at is not None)
for target in exported_targets:
pushdb, dbfile, repo = get_db(target)
oldentry = pushdb.get_entry(target)
# the jar version is ignored here, since it is overridden below with the new entry
jar, _ = target.get_artifact_info()
published.append(jar)
if skip and (jar.org, jar.name) == self.restart_at:
skip = False
# select the next version: either a named version, or semver via the pushdb/overrides
if self.named_snapshot:
newentry = oldentry.with_named_ver(self.named_snapshot)
else:
override = self.overrides.get((jar.org, jar.name))
sem_ver = override if override else oldentry.sem_ver.bump()
if self.local_snapshot:
sem_ver = sem_ver.make_snapshot()
if sem_ver <= oldentry.sem_ver:
raise TaskError('Requested version {} must be greater than the current version {}'.format(
sem_ver, oldentry.sem_ver
))
newentry = oldentry.with_sem_ver(sem_ver)
newfingerprint = self.entry_fingerprint(target, fingerprint_internal)
newentry = newentry.with_sha_and_fingerprint(head_sha, newfingerprint)
no_changes = newentry.fingerprint == oldentry.fingerprint
changelog = ''
if self.publish_changelog:
if no_changes:
changelog = 'No changes for {0} - forced push.\n'.format(pushdb_coordinate(jar, oldentry))
else:
changelog = self.changelog(target, oldentry.sha) or 'Direct dependencies changed.\n'
org = jar.org
name = jar.name
rev = newentry.version().version()
tag_name = '{org}-{name}-{rev}'.format(org=org, name=name, rev=rev) if self.commit else None
if no_changes and not self.force:
print('No changes for {0}'.format(pushdb_coordinate(jar, oldentry)))
stage_artifacts(target, jar, oldentry.version().version(), tag_name, changelog)
elif skip:
print('Skipping {} to resume at {}'.format(
jar_coordinate(jar, (newentry.version() if self.force else oldentry.version()).version()),
coordinate(self.restart_at[0], self.restart_at[1])
))
stage_artifacts(target, jar, oldentry.version().version(), tag_name, changelog)
else:
if not self.dryrun:
# Confirm push looks good
if self.publish_changelog:
if no_changes:
print(changelog)
else:
# The changelog may contain non-ascii text, but the print function can, under certain
# circumstances, incorrectly detect the output encoding to be ascii and thus blow up
# on non-ascii changelog characters. Here we explicitly control the encoding to avoid
# the print function's mis-interpretation.
# TODO(John Sirois): Consider introducing a pants/util `print_safe` helper for this.
message = '\nChanges for {} since {} @ {}:\n\n{}\n'.format(
coordinate(jar.org, jar.name), oldentry.version(), oldentry.sha, changelog)
# The stdout encoding can be detected as None when running without a tty (common in
# tests), in which case we want to force encoding with a unicode-supporting codec.
encoding = sys.stdout.encoding or 'utf-8'
sys.stdout.write(message.encode(encoding))
if not self.confirm_push(coordinate(jar.org, jar.name), newentry.version()):
raise TaskError('User aborted push')
pushdb.set_entry(target, newentry)
publications = stage_artifacts(target, jar, rev, tag_name, changelog)
if self.dryrun:
print('Skipping publish of {0} in test mode.'.format(pushdb_coordinate(jar, newentry)))
else:
self.publish(publications, jar=jar, entry=newentry, repo=repo, published=published)
if self.commit:
coord = coordinate(org, name, rev)
pushdb.dump(dbfile)
self.publish_pushdb_changes_to_remote_scm(
pushdb_file=dbfile,
coordinate=coord,
tag_name=tag_name,
tag_message='Publish of {coordinate} initiated by {user} {cause}'.format(
coordinate=coord,
user=getpass.getuser(),
cause='with forced revision' if (org, name) in self.overrides else '(autoinc)',
),
postscript=self.push_postscript
)
def artifact_path(self, jar, version, name=None, suffix='', extension='jar', artifact_ext=''):
return os.path.join(self.workdir, jar.org, jar.name + artifact_ext,
'{}{}-{}{}.{}'.format((name or jar.name),
artifact_ext if name != 'ivy' else '',
version,
suffix,
extension))
def check_for_duplicate_artifacts(self, targets):
targets_by_artifact = defaultdict(list)
duplicates = set()
for target in targets:
artifact = target.provides
if artifact in targets_by_artifact:
duplicates.add(artifact)
targets_by_artifact[artifact].append(target)
def duplication_message(artifact):
specs = sorted('\n {}'.format(t.address.spec) for t in targets_by_artifact[artifact])
return '\n {artifact} is defined by:{specs}'.format(artifact=artifact, specs=''.join(specs))
if duplicates:
raise self.DuplicateArtifactError('Multiple targets define the same artifacts!\n{}'.format(
'\n'.join(duplication_message(artifact) for artifact in duplicates)))
def check_targets(self, targets):
self.check_for_duplicate_artifacts(targets)
invalid = defaultdict(lambda: defaultdict(set))
derived_by_target = defaultdict(set)
def collect_invalid(publish_target, walked_target):
for derived_target in walked_target.derived_from_chain:
derived_by_target[derived_target].add(walked_target)
if not walked_target.has_sources() or not walked_target.sources_relative_to_buildroot():
invalid[publish_target][walked_target].add('No sources.')
if not self._is_exported(walked_target):
invalid[publish_target][walked_target].add('Does not provide a binary artifact.')
for target in targets:
target.walk(functools.partial(collect_invalid, target),
predicate=lambda t: isinstance(t, Jarable))
# When walking the graph of a publishable target, we may encounter families of sibling targets
# that form a derivation chain. As long as one of these siblings is publishable, we can
# proceed and publish a valid graph.
for publish_target, invalid_targets in list(invalid.items()):
for invalid_target, reasons in list(invalid_targets.items()):
derived_from_set = derived_by_target[invalid_target]
if derived_from_set - set(invalid_targets.keys()):
invalid_targets.pop(invalid_target)
if not invalid_targets:
invalid.pop(publish_target)
if invalid:
msg = list()
def first_address(pair):
first, _ = pair
return str(first.address)
for publish_target, invalid_targets in sorted(invalid.items(), key=first_address):
msg.append('\n Cannot publish {} due to:'.format(publish_target.address))
for invalid_target, reasons in sorted(invalid_targets.items(), key=first_address):
for reason in sorted(reasons):
msg.append('\n {} - {}'.format(invalid_target.address, reason))
raise TaskError('The following errors must be resolved to publish.{}'.format(''.join(msg)))
def exported_targets(self):
candidates = set(self.get_targets())
if not self.act_transitively:
def get_synthetic(lang, target):
mappings = self.context.products.get(lang).get(target)
if mappings:
for key, generated in mappings.items():
for synthetic in generated:
yield synthetic
# Handle the case where a code gen target is in the listed roots and thus the publishable
# target is a synthetic twin generated by a code gen task upstream.
# TODO(benjyw): Create a unified mechanism for acting on derived targets.
# See https://github.com/pantsbuild/pants/issues/5356.
for candidate in self.context.target_roots:
candidates.update(get_synthetic('java', candidate))
candidates.update(get_synthetic('scala', candidate))
def exportable(tgt):
return tgt in candidates and self._is_exported(tgt)
return OrderedSet(target for target in
reversed(sort_targets(candidate for candidate in candidates
if exportable(candidate)))
if exportable(target))
def entry_fingerprint(self, target, fingerprint_internal):
sha = hashlib.sha1()
sha.update(target.invalidation_hash())
# TODO(Tejal Desai): pantsbuild/pants/65: Remove java_sources attribute for ScalaLibrary
if isinstance(target, ScalaLibrary):
for java_source in sorted(target.java_sources):
sha.update(java_source.invalidation_hash())
# TODO(John Sirois): handle resources
for jarsig in sorted([jar_coordinate(j) for j in target.jar_dependencies if j.rev]):
sha.update(jarsig)
# TODO(tdesai) Handle resource type in get_db.
internal_dependencies = sorted(target_internal_dependencies(target), key=lambda t: t.id)
for internal_target in internal_dependencies:
fingerprint = fingerprint_internal(internal_target)
sha.update(fingerprint)
return sha.hexdigest()
def changelog(self, target, sha):
# Filter synthetic files.
files = [filename for filename in target.sources_relative_to_buildroot()
if not filename.startswith(os.pardir)]
return ensure_text(self.scm.changelog(from_commit=sha, files=files))
def fetch_ivysettings(self, ivy):
if self.get_options().ivy_settings:
return self.get_options().ivy_settings
elif ivy.ivy_settings is None:
raise TaskError('An ivysettings.xml with writeable resolvers is required for publishing, '
'but none was configured.')
else:
return ivy.ivy_settings
def generate_ivysettings(self, ivy, publishedjars, publish_local=None):
template_relpath = os.path.join(_TEMPLATES_RELPATH, 'ivysettings.xml.mustache')
template_text = pkgutil.get_data(__name__, template_relpath)
published = [TemplateData(org=jar.org, name=jar.name) for jar in publishedjars]
generator = Generator(template_text,
ivysettings=self.fetch_ivysettings(ivy),
dir=self.workdir,
cachedir=self.cachedir,
published=published,
publish_local=publish_local)
with safe_open(os.path.join(self.workdir, 'ivysettings.xml'), 'w') as wrapper:
generator.write(wrapper)
return wrapper.name
def generate_ivy(self, jar, version, publications):
template_relpath = os.path.join(_TEMPLATES_RELPATH, 'ivy.xml.mustache')
template_text = pkgutil.get_data(__name__, template_relpath)
pubs = [TemplateData(name=None if p.name == jar.name else p.name,
classifier=p.classifier,
ext=None if p.ext == 'jar' else p.ext) for p in publications]
generator = Generator(template_text,
org=jar.org,
name=jar.name,
rev=version,
publications=pubs)
with safe_open(os.path.join(self.workdir, 'ivy.xml'), 'w') as ivyxml:
generator.write(ivyxml)
return ivyxml.name
def create_source_jar(self, target, open_jar, version):
# TODO(Tejal Desai) pantsbuild/pants/65: Avoid creating 2 jars with java sources for a
# scala_library with java_sources. Currently publish fails fast if scala_library owning
# java sources pointed by java_library target also provides an artifact. However, jar_create
# ends up creating 2 jars one scala and other java both including the java_sources.
def abs_and_relative_sources(target):
abs_source_root = os.path.join(get_buildroot(), target.target_base)
for source in target.sources_relative_to_source_root():
yield os.path.join(abs_source_root, source), source
jar_path = self.artifact_path(open_jar, version, suffix='-sources')
with self.open_jar(jar_path, overwrite=True, compressed=True) as open_jar:
for abs_source, rel_source in abs_and_relative_sources(target):
open_jar.write(abs_source, rel_source)
# TODO(Tejal Desai): pantsbuild/pants/65 Remove java_sources attribute for ScalaLibrary
if isinstance(target, ScalaLibrary):
for java_source_target in target.java_sources:
for abs_source, rel_source in abs_and_relative_sources(java_source_target):
open_jar.write(abs_source, rel_source)
if target.has_resources:
for resource_target in target.resources:
for abs_source, rel_source in abs_and_relative_sources(resource_target):
open_jar.write(abs_source, rel_source)
return jar_path
def _java_doc(self, target):
return self.context.products.get('javadoc').get(target)
def _scala_doc(self, target):
return self.context.products.get('scaladoc').get(target)
def create_doc_jar(self, target, open_jar, version):
"""Returns a doc jar if either scala or java docs are available for the given target."""
javadoc = self._java_doc(target)
scaladoc = self._scala_doc(target)
if javadoc or scaladoc:
jar_path = self.artifact_path(open_jar, version, suffix='-javadoc')
with self.open_jar(jar_path, overwrite=True, compressed=True) as open_jar:
def add_docs(docs):
if docs:
for basedir, doc_files in docs.items():
for doc_file in doc_files:
open_jar.write(os.path.join(basedir, doc_file), doc_file)
add_docs(javadoc)
add_docs(scaladoc)
return jar_path
else:
return None
|
apache-2.0
|
[
3,
2803,
29,
1624,
13,
24,
199,
3,
1898,
6927,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
646,
9143,
199,
646,
18354,
199,
646,
8337,
199,
646,
747,
199,
646,
28728,
199,
646,
5145,
199,
646,
984,
199,
504,
12963,
492,
1324,
12,
2163,
12,
909,
12,
620,
199,
504,
5055,
492,
8773,
12,
10018,
12,
12863,
199,
504,
1331,
492,
1331,
199,
199,
504,
15811,
14,
2330,
14,
7882,
492,
23617,
199,
199,
504,
18081,
14,
4620,
14,
15813,
14,
26890,
17157,
63,
22678,
63,
2343,
492,
593,
2300,
31809,
27283,
5142,
199,
504,
18081,
14,
4620,
14,
15813,
14,
4684,
14,
3790,
461,
63,
15813,
63,
4342,
492,
20220,
461,
42,
2611,
7424,
199,
504,
18081,
14,
4620,
14,
15813,
14,
4684,
14,
7338,
461,
492,
1603,
19816,
199,
504,
18081,
14,
4620,
14,
15813,
14,
4684,
14,
28708,
63,
4342,
492,
17619,
65,
7424,
199,
504,
18081,
14,
4620,
14,
15813,
14,
5054,
14,
7338,
63,
1765,
492,
1603,
285,
4476,
199,
504,
18081,
14,
4620,
14,
15813,
14,
5054,
14,
3282,
492,
19329,
199,
504,
18081,
14,
1095,
14,
1506,
63,
5418,
492,
664,
63,
1506,
1231,
12,
664,
63,
17143,
199,
504,
18081,
14,
1095,
14,
1506,
63,
493,
492,
6516,
1173,
199,
504,
18081,
14,
1095,
14,
3924,
492,
8495,
547,
199,
504,
18081,
14,
1095,
14,
4679,
492,
15042,
12,
5458,
1451,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1562,
492,
9906,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1562,
63,
3892,
63,
705,
492,
9906,
32060,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1506,
63,
493,
63,
2087,
492,
6516,
1173,
2842,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1506,
63,
2180,
492,
4069,
63,
4684,
199,
504,
18081,
14,
10241,
14,
4930,
270,
2369,
492,
27324,
270,
2369,
199,
504,
18081,
14,
10241,
14,
10241,
492,
473,
16091,
199,
504,
18081,
14,
1765,
14,
17143,
63,
4763,
63,
20406,
492,
16198,
422,
12,
428,
4400,
13956,
4256,
12,
3240,
77,
422,
199,
504,
18081,
14,
1765,
14,
1375,
63,
23423,
63,
30192,
492,
13481,
14612,
3013,
2602,
4256,
12,
19894,
3013,
2602,
2872,
31777,
199,
504,
18081,
14,
1974,
14,
694,
1974,
492,
5048,
63,
8215,
12,
5048,
63,
1490,
12,
5048,
63,
9242,
199,
504,
18081,
14,
1974,
14,
495,
1974,
492,
4868,
63,
505,
421,
199,
63,
25437,
63,
13604,
3243,
275,
747,
14,
515,
14,
904,
360,
5876,
297,
283,
7338,
63,
4763,
358,
421,
199,
533,
22643,
8882,
8,
785,
304,
819,
768,
4639,
523,
347,
2248,
8,
515,
304,
272,
408,
30777,
282,
6675,
697,
26391,
315,
282,
4382,
570,
737,
314,
1627,
931,
1041,
272,
543,
1551,
8,
515,
12,
283,
82,
358,
465,
10792,
26,
489,
4382,
275,
19329,
14,
912,
8,
6750,
9,
489,
372,
22643,
8882,
8,
3282,
9,
819,
1021,
11855,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
26298,
63,
422,
12,
4310,
63,
422,
12,
4310,
63,
374,
63,
7410,
12,
7793,
12,
18020,
304,
489,
408,
14941,
314,
4750,
8058,
6675,
15,
3221,
402,
376,
18115,
14,
2541,
520,
635,
3240,
77,
422,
26298,
63,
422,
26,
710,
2061,
15184,
17269,
31792,
4683,
334,
269,
3240,
77,
422,
8,
16,
14,
16,
14,
16,
430,
489,
520,
635,
16198,
422,
4310,
63,
422,
26,
710,
2061,
4310,
4683,
402,
642,
2397,
334,
269,
488,
9,
489,
520,
635,
5046,
4310,
63,
374,
63,
7410,
26,
715,
340,
4310,
63,
422,
365,
314,
8839,
12,
3055,
340,
26298,
63,
422,
365,
489,
520,
635,
1059,
7793,
26,
710,
2061,
12579,
12002,
334,
269,
488,
9,
489,
520,
635,
1059,
18020,
26,
437,
3747,
2631,
367,
314,
4750,
8058,
1015,
402,
314,
1347,
14,
489,
408,
489,
291,
14,
21678,
63,
422,
275,
26298,
63,
422,
489,
291,
14,
4579,
63,
422,
275,
4310,
63,
422,
489,
291,
14,
4579,
63,
374,
63,
7410,
275,
4310,
63,
374,
63,
7410,
489,
291,
14,
4835,
275,
7793,
489,
291,
14,
15077,
275,
18020,
339,
347,
1015,
8,
277,
304,
489,
340,
291,
14,
4579,
63,
374,
63,
7410,
26,
267,
372,
291,
14,
4579,
63,
422,
489,
587,
26,
267,
372,
291,
14,
21678,
63,
422,
339,
347,
543,
63,
21678,
63,
422,
8,
277,
12,
26298,
63,
422,
304,
489,
408,
3407,
282,
7289,
402,
642,
2397,
543,
314,
1627,
26298,
63,
422,
11584,
465,
314,
8839,
1041,
489,
372,
22643,
8882,
14,
3900,
8,
21678,
63,
422,
12,
291,
14,
4579,
63,
422,
12,
756,
12,
291,
14,
4835,
12,
291,
14,
15077,
9,
339,
347,
543,
63,
4579,
63,
422,
8,
277,
12,
4310,
63,
422,
304,
489,
408,
3407,
282,
7289,
402,
642,
2397,
543,
314,
1627,
536,
63,
422,
11584,
465,
314,
8839,
1041,
489,
372,
22643,
8882,
14,
3900,
8,
277,
14,
21678,
63,
422,
12,
4310,
63,
422,
12,
715,
12,
291,
14,
4835,
12,
291,
14,
15077,
9,
339,
347,
543,
63,
4835,
63,
460,
63,
15077,
8,
277,
12,
7793,
12,
18020,
304,
489,
408,
3407,
282,
7289,
402,
642,
2397,
543,
314,
1627,
7793,
436,
18020,
1041,
489,
372,
22643,
8882,
14,
3900,
8,
277,
14,
21678,
63,
422,
12,
291,
14,
4579,
63,
422,
12,
291,
14,
4579,
63,
374,
63,
7410,
12,
7793,
12,
18020,
9,
339,
347,
636,
2722,
721,
277,
304,
489,
372,
2650,
27125,
5479,
5479,
5479,
5479,
1052,
22936,
908,
8,
267,
291,
855,
533,
4914,
354,
3108,
291,
14,
21678,
63,
422,
12,
291,
14,
4579,
63,
422,
12,
291,
14,
4579,
63,
374,
63,
7410,
12,
267,
291,
14,
4835,
12,
291,
14,
15077,
9,
819,
347,
636,
826,
721,
277,
12,
10792,
29,
403,
304,
272,
291,
423,
6750,
275,
10792,
503,
8773,
342,
819,
347,
664,
63,
2373,
8,
277,
12,
1347,
304,
272,
408,
13735,
376,
5007,
1347,
12,
372,
282,
22643,
8882,
14,
3900,
12,
1314
] |
[
2803,
29,
1624,
13,
24,
199,
3,
1898,
6927,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
646,
9143,
199,
646,
18354,
199,
646,
8337,
199,
646,
747,
199,
646,
28728,
199,
646,
5145,
199,
646,
984,
199,
504,
12963,
492,
1324,
12,
2163,
12,
909,
12,
620,
199,
504,
5055,
492,
8773,
12,
10018,
12,
12863,
199,
504,
1331,
492,
1331,
199,
199,
504,
15811,
14,
2330,
14,
7882,
492,
23617,
199,
199,
504,
18081,
14,
4620,
14,
15813,
14,
26890,
17157,
63,
22678,
63,
2343,
492,
593,
2300,
31809,
27283,
5142,
199,
504,
18081,
14,
4620,
14,
15813,
14,
4684,
14,
3790,
461,
63,
15813,
63,
4342,
492,
20220,
461,
42,
2611,
7424,
199,
504,
18081,
14,
4620,
14,
15813,
14,
4684,
14,
7338,
461,
492,
1603,
19816,
199,
504,
18081,
14,
4620,
14,
15813,
14,
4684,
14,
28708,
63,
4342,
492,
17619,
65,
7424,
199,
504,
18081,
14,
4620,
14,
15813,
14,
5054,
14,
7338,
63,
1765,
492,
1603,
285,
4476,
199,
504,
18081,
14,
4620,
14,
15813,
14,
5054,
14,
3282,
492,
19329,
199,
504,
18081,
14,
1095,
14,
1506,
63,
5418,
492,
664,
63,
1506,
1231,
12,
664,
63,
17143,
199,
504,
18081,
14,
1095,
14,
1506,
63,
493,
492,
6516,
1173,
199,
504,
18081,
14,
1095,
14,
3924,
492,
8495,
547,
199,
504,
18081,
14,
1095,
14,
4679,
492,
15042,
12,
5458,
1451,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1562,
492,
9906,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1562,
63,
3892,
63,
705,
492,
9906,
32060,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1506,
63,
493,
63,
2087,
492,
6516,
1173,
2842,
199,
504,
18081,
14,
1506,
63,
2180,
14,
1506,
63,
2180,
492,
4069,
63,
4684,
199,
504,
18081,
14,
10241,
14,
4930,
270,
2369,
492,
27324,
270,
2369,
199,
504,
18081,
14,
10241,
14,
10241,
492,
473,
16091,
199,
504,
18081,
14,
1765,
14,
17143,
63,
4763,
63,
20406,
492,
16198,
422,
12,
428,
4400,
13956,
4256,
12,
3240,
77,
422,
199,
504,
18081,
14,
1765,
14,
1375,
63,
23423,
63,
30192,
492,
13481,
14612,
3013,
2602,
4256,
12,
19894,
3013,
2602,
2872,
31777,
199,
504,
18081,
14,
1974,
14,
694,
1974,
492,
5048,
63,
8215,
12,
5048,
63,
1490,
12,
5048,
63,
9242,
199,
504,
18081,
14,
1974,
14,
495,
1974,
492,
4868,
63,
505,
421,
199,
63,
25437,
63,
13604,
3243,
275,
747,
14,
515,
14,
904,
360,
5876,
297,
283,
7338,
63,
4763,
358,
421,
199,
533,
22643,
8882,
8,
785,
304,
819,
768,
4639,
523,
347,
2248,
8,
515,
304,
272,
408,
30777,
282,
6675,
697,
26391,
315,
282,
4382,
570,
737,
314,
1627,
931,
1041,
272,
543,
1551,
8,
515,
12,
283,
82,
358,
465,
10792,
26,
489,
4382,
275,
19329,
14,
912,
8,
6750,
9,
489,
372,
22643,
8882,
8,
3282,
9,
819,
1021,
11855,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
26298,
63,
422,
12,
4310,
63,
422,
12,
4310,
63,
374,
63,
7410,
12,
7793,
12,
18020,
304,
489,
408,
14941,
314,
4750,
8058,
6675,
15,
3221,
402,
376,
18115,
14,
2541,
520,
635,
3240,
77,
422,
26298,
63,
422,
26,
710,
2061,
15184,
17269,
31792,
4683,
334,
269,
3240,
77,
422,
8,
16,
14,
16,
14,
16,
430,
489,
520,
635,
16198,
422,
4310,
63,
422,
26,
710,
2061,
4310,
4683,
402,
642,
2397,
334,
269,
488,
9,
489,
520,
635,
5046,
4310,
63,
374,
63,
7410,
26,
715,
340,
4310,
63,
422,
365,
314,
8839,
12,
3055,
340,
26298,
63,
422,
365,
489,
520,
635,
1059,
7793,
26,
710,
2061,
12579,
12002,
334,
269,
488,
9,
489,
520,
635,
1059,
18020,
26,
437,
3747,
2631,
367,
314,
4750,
8058,
1015,
402,
314,
1347,
14,
489,
408,
489,
291,
14,
21678,
63,
422,
275,
26298,
63,
422,
489,
291,
14,
4579,
63,
422,
275,
4310,
63,
422,
489,
291,
14,
4579,
63,
374,
63,
7410,
275,
4310,
63,
374,
63,
7410,
489,
291,
14,
4835,
275,
7793,
489,
291,
14,
15077,
275,
18020,
339,
347,
1015,
8,
277,
304,
489,
340,
291,
14,
4579,
63,
374,
63,
7410,
26,
267,
372,
291,
14,
4579,
63,
422,
489,
587,
26,
267,
372,
291,
14,
21678,
63,
422,
339,
347,
543,
63,
21678,
63,
422,
8,
277,
12,
26298,
63,
422,
304,
489,
408,
3407,
282,
7289,
402,
642,
2397,
543,
314,
1627,
26298,
63,
422,
11584,
465,
314,
8839,
1041,
489,
372,
22643,
8882,
14,
3900,
8,
21678,
63,
422,
12,
291,
14,
4579,
63,
422,
12,
756,
12,
291,
14,
4835,
12,
291,
14,
15077,
9,
339,
347,
543,
63,
4579,
63,
422,
8,
277,
12,
4310,
63,
422,
304,
489,
408,
3407,
282,
7289,
402,
642,
2397,
543,
314,
1627,
536,
63,
422,
11584,
465,
314,
8839,
1041,
489,
372,
22643,
8882,
14,
3900,
8,
277,
14,
21678,
63,
422,
12,
4310,
63,
422,
12,
715,
12,
291,
14,
4835,
12,
291,
14,
15077,
9,
339,
347,
543,
63,
4835,
63,
460,
63,
15077,
8,
277,
12,
7793,
12,
18020,
304,
489,
408,
3407,
282,
7289,
402,
642,
2397,
543,
314,
1627,
7793,
436,
18020,
1041,
489,
372,
22643,
8882,
14,
3900,
8,
277,
14,
21678,
63,
422,
12,
291,
14,
4579,
63,
422,
12,
291,
14,
4579,
63,
374,
63,
7410,
12,
7793,
12,
18020,
9,
339,
347,
636,
2722,
721,
277,
304,
489,
372,
2650,
27125,
5479,
5479,
5479,
5479,
1052,
22936,
908,
8,
267,
291,
855,
533,
4914,
354,
3108,
291,
14,
21678,
63,
422,
12,
291,
14,
4579,
63,
422,
12,
291,
14,
4579,
63,
374,
63,
7410,
12,
267,
291,
14,
4835,
12,
291,
14,
15077,
9,
819,
347,
636,
826,
721,
277,
12,
10792,
29,
403,
304,
272,
291,
423,
6750,
275,
10792,
503,
8773,
342,
819,
347,
664,
63,
2373,
8,
277,
12,
1347,
304,
272,
408,
13735,
376,
5007,
1347,
12,
372,
282,
22643,
8882,
14,
3900,
12,
1314,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
adaussy/eclipse-monkey-revival
|
plugins/python/org.eclipse.eclipsemonkey.lang.python/Lib/test/test_pep277.py
|
119
|
7875
|
# Test the Unicode versions of normal file functions
# open, os.open, os.stat. os.listdir, os.rename, os.remove, os.mkdir, os.chdir, os.rmdir
import sys, os, unittest
from unicodedata import normalize
from test import test_support
filenames = [
'1_abc',
u'2_ascii',
u'3_Gr\xfc\xdf-Gott',
u'4_\u0393\u03b5\u03b9\u03ac-\u03c3\u03b1\u03c2',
u'5_\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435',
u'6_\u306b\u307d\u3093',
u'7_\u05d4\u05e9\u05e7\u05e6\u05e5\u05e1',
u'8_\u66e8\u66e9\u66eb',
u'9_\u66e8\u05e9\u3093\u0434\u0393\xdf',
# Specific code points: fn, NFC(fn) and NFKC(fn) all differents
u'10_\u1fee\u1ffd',
]
# Mac OS X decomposes Unicode names, using Normal Form D.
# http://developer.apple.com/mac/library/qa/qa2001/qa1173.html
# "However, most volume formats do not follow the exact specification for
# these normal forms. For example, HFS Plus uses a variant of Normal Form D
# in which U+2000 through U+2FFF, U+F900 through U+FAFF, and U+2F800 through
# U+2FAFF are not decomposed."
if sys.platform != 'darwin':
filenames.extend([
# Specific code points: NFC(fn), NFD(fn), NFKC(fn) and NFKD(fn) all differents
u'11_\u0385\u03d3\u03d4',
u'12_\u00a8\u0301\u03d2\u0301\u03d2\u0308', # == NFD(u'\u0385\u03d3\u03d4')
u'13_\u0020\u0308\u0301\u038e\u03ab', # == NFKC(u'\u0385\u03d3\u03d4')
u'14_\u1e9b\u1fc1\u1fcd\u1fce\u1fcf\u1fdd\u1fde\u1fdf\u1fed',
# Specific code points: fn, NFC(fn) and NFKC(fn) all differents
u'15_\u1fee\u1ffd\ufad1',
u'16_\u2000\u2000\u2000A',
u'17_\u2001\u2001\u2001A',
u'18_\u2003\u2003\u2003A', # == NFC(u'\u2001\u2001\u2001A')
u'19_\u0020\u0020\u0020A', # u'\u0020' == u' ' == NFKC(u'\u2000') ==
# NFKC(u'\u2001') == NFKC(u'\u2003')
])
# Is it Unicode-friendly?
if not os.path.supports_unicode_filenames:
fsencoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
try:
for name in filenames:
name.encode(fsencoding)
except UnicodeEncodeError:
raise unittest.SkipTest("only NT+ and systems with "
"Unicode-friendly filesystem encoding")
# Destroy directory dirname and all files under it, to one level.
def deltree(dirname):
# Don't hide legitimate errors: if one of these suckers exists, it's
# an error if we can't remove it.
if os.path.exists(dirname):
# must pass unicode to os.listdir() so we get back unicode results.
for fname in os.listdir(unicode(dirname)):
os.unlink(os.path.join(dirname, fname))
os.rmdir(dirname)
class UnicodeFileTests(unittest.TestCase):
files = set(filenames)
normal_form = None
def setUp(self):
try:
os.mkdir(test_support.TESTFN)
except OSError:
pass
files = set()
for name in self.files:
name = os.path.join(test_support.TESTFN, self.norm(name))
with open(name, 'w') as f:
f.write((name+'\n').encode("utf-8"))
os.stat(name)
files.add(name)
self.files = files
def tearDown(self):
deltree(test_support.TESTFN)
def norm(self, s):
if self.normal_form and isinstance(s, unicode):
return normalize(self.normal_form, s)
return s
def _apply_failure(self, fn, filename, expected_exception,
check_fn_in_exception = True):
with self.assertRaises(expected_exception) as c:
fn(filename)
exc_filename = c.exception.filename
# the "filename" exception attribute may be encoded
if isinstance(exc_filename, str):
filename = filename.encode(sys.getfilesystemencoding())
if check_fn_in_exception:
self.assertEqual(exc_filename, filename, "Function '%s(%r) failed "
"with bad filename in the exception: %r" %
(fn.__name__, filename, exc_filename))
def test_failures(self):
# Pass non-existing Unicode filenames all over the place.
for name in self.files:
name = "not_" + name
self._apply_failure(open, name, IOError)
self._apply_failure(os.stat, name, OSError)
self._apply_failure(os.chdir, name, OSError)
self._apply_failure(os.rmdir, name, OSError)
self._apply_failure(os.remove, name, OSError)
# listdir may append a wildcard to the filename, so dont check
self._apply_failure(os.listdir, name, OSError, False)
def test_open(self):
for name in self.files:
f = open(name, 'w')
f.write((name+'\n').encode("utf-8"))
f.close()
os.stat(name)
# Skip the test on darwin, because darwin does normalize the filename to
# NFD (a variant of Unicode NFD form). Normalize the filename to NFC, NFKC,
# NFKD in Python is useless, because darwin will normalize it later and so
# open(), os.stat(), etc. don't raise any exception.
@unittest.skipIf(sys.platform == 'darwin', 'irrelevant test on Mac OS X')
def test_normalize(self):
files = set(f for f in self.files if isinstance(f, unicode))
others = set()
for nf in set(['NFC', 'NFD', 'NFKC', 'NFKD']):
others |= set(normalize(nf, file) for file in files)
others -= files
for name in others:
self._apply_failure(open, name, IOError)
self._apply_failure(os.stat, name, OSError)
self._apply_failure(os.chdir, name, OSError)
self._apply_failure(os.rmdir, name, OSError)
self._apply_failure(os.remove, name, OSError)
# listdir may append a wildcard to the filename, so dont check
self._apply_failure(os.listdir, name, OSError, False)
# Skip the test on darwin, because darwin uses a normalization different
# than Python NFD normalization: filenames are different even if we use
# Python NFD normalization.
@unittest.skipIf(sys.platform == 'darwin', 'irrelevant test on Mac OS X')
def test_listdir(self):
sf0 = set(self.files)
f1 = os.listdir(test_support.TESTFN)
f2 = os.listdir(unicode(test_support.TESTFN,
sys.getfilesystemencoding()))
sf2 = set(os.path.join(unicode(test_support.TESTFN), f) for f in f2)
self.assertEqual(sf0, sf2)
self.assertEqual(len(f1), len(f2))
def test_rename(self):
for name in self.files:
os.rename(name, "tmp")
os.rename("tmp", name)
def test_directory(self):
dirname = os.path.join(test_support.TESTFN,
u'Gr\xfc\xdf-\u66e8\u66e9\u66eb')
filename = u'\xdf-\u66e8\u66e9\u66eb'
oldwd = os.getcwd()
os.mkdir(dirname)
os.chdir(dirname)
try:
with open(filename, 'w') as f:
f.write((filename + '\n').encode("utf-8"))
os.access(filename,os.R_OK)
os.remove(filename)
finally:
os.chdir(oldwd)
os.rmdir(dirname)
class UnicodeNFCFileTests(UnicodeFileTests):
normal_form = 'NFC'
class UnicodeNFDFileTests(UnicodeFileTests):
normal_form = 'NFD'
class UnicodeNFKCFileTests(UnicodeFileTests):
normal_form = 'NFKC'
class UnicodeNFKDFileTests(UnicodeFileTests):
normal_form = 'NFKD'
def test_main():
try:
test_support.run_unittest(
UnicodeFileTests,
UnicodeNFCFileTests,
UnicodeNFDFileTests,
UnicodeNFKCFileTests,
UnicodeNFKDFileTests,
)
finally:
deltree(test_support.TESTFN)
if __name__ == "__main__":
test_main()
|
epl-1.0
|
[
3,
1379,
314,
6140,
5459,
402,
3293,
570,
3423,
199,
3,
1551,
12,
747,
14,
1490,
12,
747,
14,
3736,
14,
747,
14,
7374,
12,
747,
14,
8165,
12,
747,
14,
2168,
12,
747,
14,
8215,
12,
747,
14,
8563,
12,
747,
14,
19405,
199,
646,
984,
12,
747,
12,
2882,
199,
504,
23128,
492,
7666,
199,
504,
511,
492,
511,
63,
4058,
199,
199,
10309,
275,
359,
272,
283,
17,
63,
3175,
297,
272,
399,
7,
18,
63,
4371,
297,
272,
399,
7,
19,
63,
23765,
60,
10347,
60,
10418,
13,
13662,
84,
297,
272,
399,
7,
20,
18005,
85,
10005,
19,
60,
85,
1644,
66,
21,
60,
85,
1644,
66,
25,
60,
85,
1644,
645,
2696,
85,
1644,
67,
19,
60,
85,
1644,
66,
17,
60,
85,
1644,
67,
18,
297,
272,
399,
7,
21,
18005,
85,
966,
1196,
60,
85,
26190,
60,
85,
16113,
60,
85,
12212,
60,
85,
17436,
60,
85,
21229,
60,
85,
21711,
60,
85,
17436,
60,
85,
31426,
60,
85,
966,
1355,
60,
85,
21711,
60,
85,
15321,
297,
272,
399,
7,
22,
18005,
85,
11363,
66,
60,
85,
11516,
68,
60,
85,
1216,
3129,
297,
272,
399,
7,
23,
18005,
85,
1717,
68,
20,
60,
85,
1717,
69,
25,
60,
85,
1717,
69,
23,
60,
85,
1717,
69,
22,
60,
85,
1717,
69,
21,
60,
85,
1717,
69,
17,
297,
272,
399,
7,
24,
18005,
85,
1272,
69,
24,
60,
85,
1272,
69,
25,
60,
85,
1272,
2871,
297,
272,
399,
7,
25,
18005,
85,
1272,
69,
24,
60,
85,
1717,
69,
25,
60,
85,
1216,
3129,
60,
85,
26190,
60,
85,
10005,
19,
60,
10418,
297,
272,
327,
20411,
1233,
4501,
26,
4325,
12,
653,
4161,
8,
2324,
9,
436,
653,
38,
18504,
8,
2324,
9,
1006,
3365,
83,
272,
399,
7,
709,
18005,
85,
17,
11195,
60,
85,
17,
30329,
297,
272,
1622,
199,
199,
3,
10444,
4403,
1323,
477,
7784,
874,
6140,
1561,
12,
1808,
11514,
8204,
577,
14,
199,
3,
1455,
921,
11071,
14,
12820,
14,
957,
15,
3088,
15,
4342,
15,
7096,
15,
7096,
8339,
15,
7096,
845,
2898,
14,
1360,
199,
3,
298,
18335,
5907,
12,
4750,
3301,
6752,
886,
440,
2035,
314,
5835,
8929,
367,
199,
3,
3520,
3293,
4513,
14,
221,
2104,
2893,
12,
869,
7079,
7497,
527,
4440,
282,
9854,
402,
11514,
8204,
577,
199,
3,
315,
1314,
738,
11,
8269,
4012,
738,
11,
18,
24254,
12,
738,
11,
38,
17518,
4012,
738,
11,
2078,
1665,
12,
436,
738,
11,
18,
38,
6718,
4012,
199,
3,
738,
11,
18,
2078,
1665,
787,
440,
477,
7784,
939,
2122,
199,
692,
984,
14,
3246,
1137,
283,
13245,
356,
272,
6203,
14,
2880,
779,
267,
327,
20411,
1233,
4501,
26,
653,
4161,
8,
2324,
395,
653,
7902,
8,
2324,
395,
653,
38,
18504,
8,
2324,
9,
436,
653,
38,
13368,
8,
2324,
9,
1006,
3365,
83,
267,
399,
7,
845,
18005,
85,
1644,
2426,
60,
85,
1644,
68,
19,
60,
85,
1644,
68,
20,
297,
267,
399,
7,
713,
18005,
85,
383,
65,
24,
60,
85,
1644,
614,
60,
85,
1644,
68,
18,
60,
85,
1644,
614,
60,
85,
1644,
68,
18,
60,
85,
16,
12127,
297,
259,
327,
508,
653,
7902,
8,
85,
1154,
85,
1644,
2426,
60,
85,
1644,
68,
19,
60,
85,
1644,
68,
20,
358,
267,
399,
7,
969,
18005,
85,
20734,
60,
85,
16,
12127,
60,
85,
1644,
614,
60,
85,
14273,
69,
60,
85,
1644,
371,
297,
3515,
327,
508,
653,
38,
18504,
8,
85,
1154,
85,
1644,
2426,
60,
85,
1644,
68,
19,
60,
85,
1644,
68,
20,
358,
267,
399,
7,
1079,
18005,
85,
17,
69,
25,
66,
60,
85,
17,
3003,
17,
60,
85,
17,
29873,
60,
85,
17,
70,
301,
60,
85,
17,
70,
2177,
60,
85,
17,
70,
617,
60,
85,
17,
70,
271,
60,
85,
17,
24864,
60,
85,
17,
15800,
297,
398,
327,
20411,
1233,
4501,
26,
4325,
12,
653,
4161,
8,
2324,
9,
436,
653,
38,
18504,
8,
2324,
9,
1006,
3365,
83,
267,
399,
7,
1046,
18005,
85,
17,
11195,
60,
85,
17,
30329,
60,
1286,
350,
17,
297,
267,
399,
7,
975,
18005,
85,
8269,
60,
85,
8269,
60,
85,
8269,
33,
297,
267,
399,
7,
1196,
18005,
85,
8339,
60,
85,
8339,
60,
85,
8339,
33,
297,
267,
399,
7,
1085,
18005,
85,
17919,
60,
85,
17919,
60,
85,
17919,
33,
297,
327,
508,
653,
4161,
8,
85,
1154,
85,
8339,
60,
85,
8339,
60,
85,
8339,
33,
358,
267,
399,
7,
1167,
18005,
85,
20734,
60,
85,
20734,
60,
85,
20734,
33,
297,
327,
399,
1154,
85,
20734,
7,
508,
399,
7,
283,
508,
653,
38,
18504,
8,
85,
1154,
85,
8269,
358,
508,
3521,
327,
257,
653,
38,
18504,
8,
85,
1154,
85,
8339,
358,
508,
653,
38,
18504,
8,
85,
1154,
85,
17919,
358,
199,
566,
421,
199,
3,
6596,
652,
6140,
13,
17317,
31,
199,
692,
440,
747,
14,
515,
14,
9823,
63,
2975,
63,
10309,
26,
272,
289,
2464,
1523,
275,
984,
14,
23462,
32255,
342,
503,
984,
14,
362,
27205,
28139,
342,
272,
862,
26,
267,
367,
536,
315,
6203,
26,
288,
536,
14,
2143,
8,
70,
2464,
1523,
9,
272,
871,
24094,
26,
267,
746,
2882,
14,
25755,
480,
2118,
23350,
11,
436,
10460,
543,
298,
1816,
298,
7087,
13,
17317,
10036,
2644,
531,
421,
199,
3,
20547,
4813,
2082,
9017,
436,
1006,
1584,
1334,
652,
12,
370,
1373,
2166,
14,
199,
318,
2150,
2350,
8,
3475,
304,
272,
327,
7529,
1133,
13714,
1026,
6153,
2906,
323,
2552,
26,
221,
340,
1373,
402,
3520,
308,
10112,
1192,
3495,
12,
652,
1159,
272,
327,
376,
1125,
340,
781,
883,
1133,
2813,
652,
14,
272,
340,
747,
14,
515,
14,
2444,
8,
3475,
304,
267,
327,
1471,
986,
2649,
370,
747,
14,
7374,
342,
880,
781,
664,
1771,
2649,
2058,
14,
267,
367,
6748,
315,
747,
14,
7374,
8,
2975,
8,
3475,
2298,
288,
747,
14,
7162,
8,
736,
14,
515,
14,
904,
8,
3475,
12,
6748,
430,
267,
747,
14,
19405,
8,
3475,
9,
421,
199,
533,
6140,
1173,
2925,
8,
2796,
14,
1746,
304,
272,
1584
] |
[
1379,
314,
6140,
5459,
402,
3293,
570,
3423,
199,
3,
1551,
12,
747,
14,
1490,
12,
747,
14,
3736,
14,
747,
14,
7374,
12,
747,
14,
8165,
12,
747,
14,
2168,
12,
747,
14,
8215,
12,
747,
14,
8563,
12,
747,
14,
19405,
199,
646,
984,
12,
747,
12,
2882,
199,
504,
23128,
492,
7666,
199,
504,
511,
492,
511,
63,
4058,
199,
199,
10309,
275,
359,
272,
283,
17,
63,
3175,
297,
272,
399,
7,
18,
63,
4371,
297,
272,
399,
7,
19,
63,
23765,
60,
10347,
60,
10418,
13,
13662,
84,
297,
272,
399,
7,
20,
18005,
85,
10005,
19,
60,
85,
1644,
66,
21,
60,
85,
1644,
66,
25,
60,
85,
1644,
645,
2696,
85,
1644,
67,
19,
60,
85,
1644,
66,
17,
60,
85,
1644,
67,
18,
297,
272,
399,
7,
21,
18005,
85,
966,
1196,
60,
85,
26190,
60,
85,
16113,
60,
85,
12212,
60,
85,
17436,
60,
85,
21229,
60,
85,
21711,
60,
85,
17436,
60,
85,
31426,
60,
85,
966,
1355,
60,
85,
21711,
60,
85,
15321,
297,
272,
399,
7,
22,
18005,
85,
11363,
66,
60,
85,
11516,
68,
60,
85,
1216,
3129,
297,
272,
399,
7,
23,
18005,
85,
1717,
68,
20,
60,
85,
1717,
69,
25,
60,
85,
1717,
69,
23,
60,
85,
1717,
69,
22,
60,
85,
1717,
69,
21,
60,
85,
1717,
69,
17,
297,
272,
399,
7,
24,
18005,
85,
1272,
69,
24,
60,
85,
1272,
69,
25,
60,
85,
1272,
2871,
297,
272,
399,
7,
25,
18005,
85,
1272,
69,
24,
60,
85,
1717,
69,
25,
60,
85,
1216,
3129,
60,
85,
26190,
60,
85,
10005,
19,
60,
10418,
297,
272,
327,
20411,
1233,
4501,
26,
4325,
12,
653,
4161,
8,
2324,
9,
436,
653,
38,
18504,
8,
2324,
9,
1006,
3365,
83,
272,
399,
7,
709,
18005,
85,
17,
11195,
60,
85,
17,
30329,
297,
272,
1622,
199,
199,
3,
10444,
4403,
1323,
477,
7784,
874,
6140,
1561,
12,
1808,
11514,
8204,
577,
14,
199,
3,
1455,
921,
11071,
14,
12820,
14,
957,
15,
3088,
15,
4342,
15,
7096,
15,
7096,
8339,
15,
7096,
845,
2898,
14,
1360,
199,
3,
298,
18335,
5907,
12,
4750,
3301,
6752,
886,
440,
2035,
314,
5835,
8929,
367,
199,
3,
3520,
3293,
4513,
14,
221,
2104,
2893,
12,
869,
7079,
7497,
527,
4440,
282,
9854,
402,
11514,
8204,
577,
199,
3,
315,
1314,
738,
11,
8269,
4012,
738,
11,
18,
24254,
12,
738,
11,
38,
17518,
4012,
738,
11,
2078,
1665,
12,
436,
738,
11,
18,
38,
6718,
4012,
199,
3,
738,
11,
18,
2078,
1665,
787,
440,
477,
7784,
939,
2122,
199,
692,
984,
14,
3246,
1137,
283,
13245,
356,
272,
6203,
14,
2880,
779,
267,
327,
20411,
1233,
4501,
26,
653,
4161,
8,
2324,
395,
653,
7902,
8,
2324,
395,
653,
38,
18504,
8,
2324,
9,
436,
653,
38,
13368,
8,
2324,
9,
1006,
3365,
83,
267,
399,
7,
845,
18005,
85,
1644,
2426,
60,
85,
1644,
68,
19,
60,
85,
1644,
68,
20,
297,
267,
399,
7,
713,
18005,
85,
383,
65,
24,
60,
85,
1644,
614,
60,
85,
1644,
68,
18,
60,
85,
1644,
614,
60,
85,
1644,
68,
18,
60,
85,
16,
12127,
297,
259,
327,
508,
653,
7902,
8,
85,
1154,
85,
1644,
2426,
60,
85,
1644,
68,
19,
60,
85,
1644,
68,
20,
358,
267,
399,
7,
969,
18005,
85,
20734,
60,
85,
16,
12127,
60,
85,
1644,
614,
60,
85,
14273,
69,
60,
85,
1644,
371,
297,
3515,
327,
508,
653,
38,
18504,
8,
85,
1154,
85,
1644,
2426,
60,
85,
1644,
68,
19,
60,
85,
1644,
68,
20,
358,
267,
399,
7,
1079,
18005,
85,
17,
69,
25,
66,
60,
85,
17,
3003,
17,
60,
85,
17,
29873,
60,
85,
17,
70,
301,
60,
85,
17,
70,
2177,
60,
85,
17,
70,
617,
60,
85,
17,
70,
271,
60,
85,
17,
24864,
60,
85,
17,
15800,
297,
398,
327,
20411,
1233,
4501,
26,
4325,
12,
653,
4161,
8,
2324,
9,
436,
653,
38,
18504,
8,
2324,
9,
1006,
3365,
83,
267,
399,
7,
1046,
18005,
85,
17,
11195,
60,
85,
17,
30329,
60,
1286,
350,
17,
297,
267,
399,
7,
975,
18005,
85,
8269,
60,
85,
8269,
60,
85,
8269,
33,
297,
267,
399,
7,
1196,
18005,
85,
8339,
60,
85,
8339,
60,
85,
8339,
33,
297,
267,
399,
7,
1085,
18005,
85,
17919,
60,
85,
17919,
60,
85,
17919,
33,
297,
327,
508,
653,
4161,
8,
85,
1154,
85,
8339,
60,
85,
8339,
60,
85,
8339,
33,
358,
267,
399,
7,
1167,
18005,
85,
20734,
60,
85,
20734,
60,
85,
20734,
33,
297,
327,
399,
1154,
85,
20734,
7,
508,
399,
7,
283,
508,
653,
38,
18504,
8,
85,
1154,
85,
8269,
358,
508,
3521,
327,
257,
653,
38,
18504,
8,
85,
1154,
85,
8339,
358,
508,
653,
38,
18504,
8,
85,
1154,
85,
17919,
358,
199,
566,
421,
199,
3,
6596,
652,
6140,
13,
17317,
31,
199,
692,
440,
747,
14,
515,
14,
9823,
63,
2975,
63,
10309,
26,
272,
289,
2464,
1523,
275,
984,
14,
23462,
32255,
342,
503,
984,
14,
362,
27205,
28139,
342,
272,
862,
26,
267,
367,
536,
315,
6203,
26,
288,
536,
14,
2143,
8,
70,
2464,
1523,
9,
272,
871,
24094,
26,
267,
746,
2882,
14,
25755,
480,
2118,
23350,
11,
436,
10460,
543,
298,
1816,
298,
7087,
13,
17317,
10036,
2644,
531,
421,
199,
3,
20547,
4813,
2082,
9017,
436,
1006,
1584,
1334,
652,
12,
370,
1373,
2166,
14,
199,
318,
2150,
2350,
8,
3475,
304,
272,
327,
7529,
1133,
13714,
1026,
6153,
2906,
323,
2552,
26,
221,
340,
1373,
402,
3520,
308,
10112,
1192,
3495,
12,
652,
1159,
272,
327,
376,
1125,
340,
781,
883,
1133,
2813,
652,
14,
272,
340,
747,
14,
515,
14,
2444,
8,
3475,
304,
267,
327,
1471,
986,
2649,
370,
747,
14,
7374,
342,
880,
781,
664,
1771,
2649,
2058,
14,
267,
367,
6748,
315,
747,
14,
7374,
8,
2975,
8,
3475,
2298,
288,
747,
14,
7162,
8,
736,
14,
515,
14,
904,
8,
3475,
12,
6748,
430,
267,
747,
14,
19405,
8,
3475,
9,
421,
199,
533,
6140,
1173,
2925,
8,
2796,
14,
1746,
304,
272,
1584,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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