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
|
|---|---|---|---|---|---|---|---|---|
digwanderlust/pants
|
tests/python/pants_test/tasks/test_cache_manager.py
|
1
|
4690
|
# coding=utf-8
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)
import shutil
import tempfile
from pants.base.build_invalidator import CacheKey, CacheKeyGenerator
from pants.base.cache_manager import InvalidationCacheManager, InvalidationCheck, VersionedTarget
from pants_test.base_test import BaseTest
class AppendingCacheKeyGenerator(CacheKeyGenerator):
"""Generates cache keys for versions of target sets."""
@staticmethod
def combine_cache_keys(cache_keys):
if len(cache_keys) == 1:
return cache_keys[0]
else:
sorted_cache_keys = sorted(cache_keys) # For commutativity.
combined_id = ','.join([cache_key.id for cache_key in sorted_cache_keys])
combined_hash = ','.join([cache_key.hash for cache_key in sorted_cache_keys])
combined_num_sources = reduce(lambda x, y: x + y,
[cache_key.num_sources for cache_key in sorted_cache_keys], 0)
return CacheKey(combined_id, combined_hash, combined_num_sources)
def key_for_target(self, target, sources=None, transitive=False, fingerprint_strategy=None):
return CacheKey(target.id, target.id, target.num_chunking_units)
def key_for(self, tid, sources):
return CacheKey(tid, tid, len(sources))
def print_vt(vt):
print('%d (%s) %s: [ %s ]' % (len(vt.targets), vt.cache_key, vt.valid, ', '.join(['%s(%s)' % (v.id, v.cache_key) for v in vt.versioned_targets])))
class InvalidationCacheManagerTest(BaseTest):
class TestInvalidationCacheManager(InvalidationCacheManager):
def __init__(self, tmpdir):
InvalidationCacheManager.__init__(self, AppendingCacheKeyGenerator(), tmpdir, True)
def setUp(self):
super(InvalidationCacheManagerTest, self).setUp()
self._dir = tempfile.mkdtemp()
self.cache_manager = InvalidationCacheManagerTest.TestInvalidationCacheManager(self._dir)
def tearDown(self):
shutil.rmtree(self._dir, ignore_errors=True)
super(InvalidationCacheManagerTest, self).tearDown()
def make_vts(self, target):
return VersionedTarget(self.cache_manager, target, target.id)
def test_partition(self):
# The default EmptyPayload chunking unit happens to be 1, so each of these Targets
# has a chunking unit contribution of 1
a = self.make_target(':a', dependencies=[])
b = self.make_target(':b', dependencies=[a])
c = self.make_target(':c', dependencies=[b])
d = self.make_target(':d', dependencies=[c, a])
e = self.make_target(':e', dependencies=[d])
targets = [a, b, c, d, e]
def print_partitions(partitions):
strs = []
for partition in partitions:
strs.append('(%s)' % ', '.join([t.id for t in partition.targets]))
print('[%s]' % ' '.join(strs))
# Verify basic data structure soundness.
all_vts = self.cache_manager.wrap_targets(targets)
invalid_vts = filter(lambda vt: not vt.valid, all_vts)
self.assertEquals(5, len(invalid_vts))
self.assertEquals(5, len(all_vts))
vts_targets = [vt.targets[0] for vt in all_vts]
self.assertEquals(set(targets), set(vts_targets))
# Test a simple partition.
ic = InvalidationCheck(all_vts, [], 3)
partitioned = ic.all_vts_partitioned
print_partitions(partitioned)
# Several correct partitionings are possible, but in all cases 4 1-source targets will be
# added to the first partition before it exceeds the limit of 3, and the final target will
# be in a partition by itself.
self.assertEquals(2, len(partitioned))
self.assertEquals(4, len(partitioned[0].targets))
self.assertEquals(1, len(partitioned[1].targets))
# Test partition with colors.
red = 'red'
blue = 'blue'
colors = {
a: blue,
b: red,
c: red,
d: red,
e: blue
}
# As a reference, we partition without colors.
ic = InvalidationCheck(all_vts, [], 2)
partitioned = ic.all_vts_partitioned
print_partitions(partitioned)
self.assertEquals(2, len(partitioned))
self.assertEquals(3, len(partitioned[0].targets))
self.assertEquals(2, len(partitioned[1].targets))
# Now apply color restrictions.
ic = InvalidationCheck(all_vts, [], 2, target_colors=colors)
partitioned = ic.all_vts_partitioned
print_partitions(partitioned)
self.assertEquals(3, len(partitioned))
self.assertEquals(1, len(partitioned[0].targets))
self.assertEquals(3, len(partitioned[1].targets))
self.assertEquals(1, len(partitioned[2].targets))
|
apache-2.0
|
[
3,
2803,
29,
1624,
13,
24,
199,
3,
1898,
6927,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
16952,
12,
6032,
63,
14129,
12,
870,
63,
1593,
12,
717,
2649,
63,
5955,
12,
543,
63,
6242,
9,
199,
199,
646,
5145,
199,
646,
5549,
199,
199,
504,
18081,
14,
1095,
14,
1506,
63,
3197,
707,
492,
11977,
1197,
12,
11977,
1197,
7599,
199,
504,
18081,
14,
1095,
14,
1637,
63,
2609,
492,
1010,
6136,
4437,
2988,
12,
1010,
6136,
1799,
12,
5444,
12308,
4277,
199,
504,
18081,
63,
396,
14,
1095,
63,
396,
492,
3523,
774,
421,
199,
533,
4693,
3219,
4437,
1197,
7599,
8,
4437,
1197,
7599,
304,
523,
408,
20551,
2581,
2883,
367,
5459,
402,
1347,
5951,
1041,
819,
768,
4639,
523,
347,
13323,
63,
1637,
63,
1612,
8,
1637,
63,
1612,
304,
272,
340,
822,
8,
1637,
63,
1612,
9,
508,
413,
26,
489,
372,
2581,
63,
1612,
59,
16,
61,
272,
587,
26,
489,
3355,
63,
1637,
63,
1612,
275,
3355,
8,
1637,
63,
1612,
9,
221,
327,
2104,
1923,
337,
2159,
18936,
14,
489,
12149,
63,
344,
275,
12814,
904,
779,
1637,
63,
498,
14,
344,
367,
2581,
63,
498,
315,
3355,
63,
1637,
63,
1612,
566,
489,
12149,
63,
2227,
275,
12814,
904,
779,
1637,
63,
498,
14,
2227,
367,
2581,
63,
498,
315,
3355,
63,
1637,
63,
1612,
566,
489,
12149,
63,
1507,
63,
4553,
275,
7114,
8,
2734,
671,
12,
612,
26,
671,
435,
612,
12,
2511,
359,
1637,
63,
498,
14,
1507,
63,
4553,
367,
2581,
63,
498,
315,
3355,
63,
1637,
63,
1612,
467,
378,
9,
489,
372,
11977,
1197,
8,
17583,
63,
344,
12,
12149,
63,
2227,
12,
12149,
63,
1507,
63,
4553,
9,
819,
347,
790,
63,
509,
63,
1375,
8,
277,
12,
1347,
12,
5274,
29,
403,
12,
7115,
3013,
29,
797,
12,
18020,
63,
8590,
29,
403,
304,
272,
372,
11977,
1197,
8,
1375,
14,
344,
12,
1347,
14,
344,
12,
1347,
14,
1507,
63,
4604,
316,
63,
5260,
9,
819,
347,
790,
63,
509,
8,
277,
12,
11559,
12,
5274,
304,
272,
372,
11977,
1197,
8,
5700,
12,
11559,
12,
822,
8,
4553,
430,
421,
199,
318,
870,
63,
5941,
8,
5941,
304,
523,
870,
3508,
68,
4366,
83,
9,
450,
83,
26,
359,
450,
83,
1622,
7,
450,
334,
552,
8,
5941,
14,
4684,
395,
18585,
14,
1637,
63,
498,
12,
18585,
14,
1078,
12,
1656,
1987,
904,
26861,
83,
4042,
83,
3171,
450,
334,
86,
14,
344,
12,
373,
14,
1637,
63,
498,
9,
367,
373,
315,
18585,
14,
24155,
63,
4684,
11845,
421,
199,
533,
1010,
6136,
4437,
2988,
774,
8,
23170,
304,
523,
1021,
1379,
3364,
425,
4437,
2988,
8,
3364,
425,
4437,
2988,
304,
272,
347,
636,
826,
721,
277,
12,
12885,
304,
489,
1010,
6136,
4437,
2988,
855,
826,
721,
277,
12,
4693,
3219,
4437,
1197,
7599,
1062,
12885,
12,
715,
9,
819,
347,
3613,
8,
277,
304,
272,
1613,
8,
3364,
425,
4437,
2988,
774,
12,
291,
680,
5996,
342,
272,
291,
423,
694,
275,
5549,
14,
11983,
342,
272,
291,
14,
1637,
63,
2609,
275,
1010,
6136,
4437,
2988,
774,
14,
774,
3364,
425,
4437,
2988,
8,
277,
423,
694,
9,
819,
347,
6766,
8,
277,
304,
272,
5145,
14,
9242,
8,
277,
423,
694,
12,
3686,
63,
2550,
29,
549,
9,
272,
1613,
8,
3364,
425,
4437,
2988,
774,
12,
291,
680,
12336,
342,
819,
347,
1852,
63,
86,
1086,
8,
277,
12,
1347,
304,
272,
372,
5444,
12308,
4277,
8,
277,
14,
1637,
63,
2609,
12,
1347,
12,
1347,
14,
344,
9,
819,
347,
511,
63,
5312,
8,
277,
304,
272,
327,
710,
849,
9630,
17215,
3728,
316,
4137,
10986,
370,
506,
413,
12,
880,
1924,
402,
3520,
10256,
83,
272,
327,
965,
282,
3728,
316,
4137,
406,
15980,
402,
413,
272,
282,
275,
291,
14,
1875,
63,
1375,
6176,
65,
297,
5124,
14285,
272,
330,
275,
291,
14,
1875,
63,
1375,
6176,
66,
297,
5124,
1524,
65,
566,
272,
286,
275,
291,
14,
1875,
63,
1375,
6176,
67,
297,
5124,
1524,
66,
566,
272,
366,
275,
291,
14,
1875,
63,
1375,
6176,
68,
297,
5124,
1524,
67,
12,
282,
566,
272,
325,
275,
291,
14,
1875,
63,
1375,
6176,
69,
297,
5124,
1524,
68,
566,
339,
4545,
275,
359,
65,
12,
330,
12,
286,
12,
366,
12,
325,
61,
339,
347,
870,
63,
12553,
8,
12553,
304,
489,
620,
83,
275,
942,
489,
367,
6484,
315,
16394,
26,
267,
620,
83,
14,
740,
360,
4042,
83,
3171,
450,
1656,
1987,
904,
779,
84,
14,
344,
367,
307,
315,
6484,
14,
4684,
2459,
489,
870,
360,
9722,
83,
6616,
450,
283,
1987,
904,
8,
16144,
430,
339,
327,
7635,
5678,
666,
5523,
20453,
4171,
14,
272,
1006,
63,
86,
1086,
275,
291,
14,
1637,
63,
2609,
14,
3823,
63,
4684,
8,
4684,
9,
272,
3866,
63,
86,
1086,
275,
2457,
8,
2734,
18585,
26,
440,
18585,
14,
1078,
12,
1006,
63,
86,
1086,
9,
272,
291,
14,
2947,
8,
21,
12,
822,
8,
3197,
63,
86,
1086,
430,
272,
291,
14,
2947,
8,
21,
12,
822,
8,
452,
63,
86,
1086,
430,
272,
373,
1086,
63,
4684,
275,
359,
5941,
14,
4684,
59,
16,
61,
367,
18585,
315,
1006,
63,
86,
1086,
61,
272,
291,
14,
2947,
8,
409,
8,
4684,
395,
663,
8,
86,
1086,
63,
4684,
430,
339,
327,
1379,
282,
3486,
6484,
14,
272,
284,
67,
275,
1010,
6136,
1799,
8,
452,
63,
86,
1086,
12,
990,
650,
9,
272,
27105,
275,
284,
67,
14,
452,
63,
86,
1086,
63,
5312,
379,
272,
870,
63,
12553,
8,
5312,
379,
9,
339,
327,
3240,
422,
279,
3211,
6484,
780,
787,
3962,
12,
1325,
315,
1006,
5560,
841,
413,
13,
1365,
4545,
911,
506,
272,
327,
3483,
370,
314,
1642,
6484,
2544,
652,
22338,
314,
2304,
402,
650,
12,
436,
314,
4242,
1347,
911,
272,
327,
506,
315,
282,
6484,
701,
6337,
14,
272,
291,
14
] |
[
2803,
29,
1624,
13,
24,
199,
3,
1898,
6927,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
16952,
12,
6032,
63,
14129,
12,
870,
63,
1593,
12,
717,
2649,
63,
5955,
12,
543,
63,
6242,
9,
199,
199,
646,
5145,
199,
646,
5549,
199,
199,
504,
18081,
14,
1095,
14,
1506,
63,
3197,
707,
492,
11977,
1197,
12,
11977,
1197,
7599,
199,
504,
18081,
14,
1095,
14,
1637,
63,
2609,
492,
1010,
6136,
4437,
2988,
12,
1010,
6136,
1799,
12,
5444,
12308,
4277,
199,
504,
18081,
63,
396,
14,
1095,
63,
396,
492,
3523,
774,
421,
199,
533,
4693,
3219,
4437,
1197,
7599,
8,
4437,
1197,
7599,
304,
523,
408,
20551,
2581,
2883,
367,
5459,
402,
1347,
5951,
1041,
819,
768,
4639,
523,
347,
13323,
63,
1637,
63,
1612,
8,
1637,
63,
1612,
304,
272,
340,
822,
8,
1637,
63,
1612,
9,
508,
413,
26,
489,
372,
2581,
63,
1612,
59,
16,
61,
272,
587,
26,
489,
3355,
63,
1637,
63,
1612,
275,
3355,
8,
1637,
63,
1612,
9,
221,
327,
2104,
1923,
337,
2159,
18936,
14,
489,
12149,
63,
344,
275,
12814,
904,
779,
1637,
63,
498,
14,
344,
367,
2581,
63,
498,
315,
3355,
63,
1637,
63,
1612,
566,
489,
12149,
63,
2227,
275,
12814,
904,
779,
1637,
63,
498,
14,
2227,
367,
2581,
63,
498,
315,
3355,
63,
1637,
63,
1612,
566,
489,
12149,
63,
1507,
63,
4553,
275,
7114,
8,
2734,
671,
12,
612,
26,
671,
435,
612,
12,
2511,
359,
1637,
63,
498,
14,
1507,
63,
4553,
367,
2581,
63,
498,
315,
3355,
63,
1637,
63,
1612,
467,
378,
9,
489,
372,
11977,
1197,
8,
17583,
63,
344,
12,
12149,
63,
2227,
12,
12149,
63,
1507,
63,
4553,
9,
819,
347,
790,
63,
509,
63,
1375,
8,
277,
12,
1347,
12,
5274,
29,
403,
12,
7115,
3013,
29,
797,
12,
18020,
63,
8590,
29,
403,
304,
272,
372,
11977,
1197,
8,
1375,
14,
344,
12,
1347,
14,
344,
12,
1347,
14,
1507,
63,
4604,
316,
63,
5260,
9,
819,
347,
790,
63,
509,
8,
277,
12,
11559,
12,
5274,
304,
272,
372,
11977,
1197,
8,
5700,
12,
11559,
12,
822,
8,
4553,
430,
421,
199,
318,
870,
63,
5941,
8,
5941,
304,
523,
870,
3508,
68,
4366,
83,
9,
450,
83,
26,
359,
450,
83,
1622,
7,
450,
334,
552,
8,
5941,
14,
4684,
395,
18585,
14,
1637,
63,
498,
12,
18585,
14,
1078,
12,
1656,
1987,
904,
26861,
83,
4042,
83,
3171,
450,
334,
86,
14,
344,
12,
373,
14,
1637,
63,
498,
9,
367,
373,
315,
18585,
14,
24155,
63,
4684,
11845,
421,
199,
533,
1010,
6136,
4437,
2988,
774,
8,
23170,
304,
523,
1021,
1379,
3364,
425,
4437,
2988,
8,
3364,
425,
4437,
2988,
304,
272,
347,
636,
826,
721,
277,
12,
12885,
304,
489,
1010,
6136,
4437,
2988,
855,
826,
721,
277,
12,
4693,
3219,
4437,
1197,
7599,
1062,
12885,
12,
715,
9,
819,
347,
3613,
8,
277,
304,
272,
1613,
8,
3364,
425,
4437,
2988,
774,
12,
291,
680,
5996,
342,
272,
291,
423,
694,
275,
5549,
14,
11983,
342,
272,
291,
14,
1637,
63,
2609,
275,
1010,
6136,
4437,
2988,
774,
14,
774,
3364,
425,
4437,
2988,
8,
277,
423,
694,
9,
819,
347,
6766,
8,
277,
304,
272,
5145,
14,
9242,
8,
277,
423,
694,
12,
3686,
63,
2550,
29,
549,
9,
272,
1613,
8,
3364,
425,
4437,
2988,
774,
12,
291,
680,
12336,
342,
819,
347,
1852,
63,
86,
1086,
8,
277,
12,
1347,
304,
272,
372,
5444,
12308,
4277,
8,
277,
14,
1637,
63,
2609,
12,
1347,
12,
1347,
14,
344,
9,
819,
347,
511,
63,
5312,
8,
277,
304,
272,
327,
710,
849,
9630,
17215,
3728,
316,
4137,
10986,
370,
506,
413,
12,
880,
1924,
402,
3520,
10256,
83,
272,
327,
965,
282,
3728,
316,
4137,
406,
15980,
402,
413,
272,
282,
275,
291,
14,
1875,
63,
1375,
6176,
65,
297,
5124,
14285,
272,
330,
275,
291,
14,
1875,
63,
1375,
6176,
66,
297,
5124,
1524,
65,
566,
272,
286,
275,
291,
14,
1875,
63,
1375,
6176,
67,
297,
5124,
1524,
66,
566,
272,
366,
275,
291,
14,
1875,
63,
1375,
6176,
68,
297,
5124,
1524,
67,
12,
282,
566,
272,
325,
275,
291,
14,
1875,
63,
1375,
6176,
69,
297,
5124,
1524,
68,
566,
339,
4545,
275,
359,
65,
12,
330,
12,
286,
12,
366,
12,
325,
61,
339,
347,
870,
63,
12553,
8,
12553,
304,
489,
620,
83,
275,
942,
489,
367,
6484,
315,
16394,
26,
267,
620,
83,
14,
740,
360,
4042,
83,
3171,
450,
1656,
1987,
904,
779,
84,
14,
344,
367,
307,
315,
6484,
14,
4684,
2459,
489,
870,
360,
9722,
83,
6616,
450,
283,
1987,
904,
8,
16144,
430,
339,
327,
7635,
5678,
666,
5523,
20453,
4171,
14,
272,
1006,
63,
86,
1086,
275,
291,
14,
1637,
63,
2609,
14,
3823,
63,
4684,
8,
4684,
9,
272,
3866,
63,
86,
1086,
275,
2457,
8,
2734,
18585,
26,
440,
18585,
14,
1078,
12,
1006,
63,
86,
1086,
9,
272,
291,
14,
2947,
8,
21,
12,
822,
8,
3197,
63,
86,
1086,
430,
272,
291,
14,
2947,
8,
21,
12,
822,
8,
452,
63,
86,
1086,
430,
272,
373,
1086,
63,
4684,
275,
359,
5941,
14,
4684,
59,
16,
61,
367,
18585,
315,
1006,
63,
86,
1086,
61,
272,
291,
14,
2947,
8,
409,
8,
4684,
395,
663,
8,
86,
1086,
63,
4684,
430,
339,
327,
1379,
282,
3486,
6484,
14,
272,
284,
67,
275,
1010,
6136,
1799,
8,
452,
63,
86,
1086,
12,
990,
650,
9,
272,
27105,
275,
284,
67,
14,
452,
63,
86,
1086,
63,
5312,
379,
272,
870,
63,
12553,
8,
5312,
379,
9,
339,
327,
3240,
422,
279,
3211,
6484,
780,
787,
3962,
12,
1325,
315,
1006,
5560,
841,
413,
13,
1365,
4545,
911,
506,
272,
327,
3483,
370,
314,
1642,
6484,
2544,
652,
22338,
314,
2304,
402,
650,
12,
436,
314,
4242,
1347,
911,
272,
327,
506,
315,
282,
6484,
701,
6337,
14,
272,
291,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
amanzi/ats-dev
|
tools/utils/transect_data.py
|
2
|
7741
|
"""Loads and/or plots 2D, topologlically structured data on quadrilaterals using matplotlib.
"""
import sys,os
import numpy as np
import h5py
import mesh
import colors
def fullname(varname):
fullname = varname
if not '.cell.' in fullname:
fullname = fullname+'.cell.0'
return fullname
def transect_data(varnames, keys='all', directory=".", filename="visdump_data.h5",
mesh_filename="visdump_mesh.h5", coord_order=None, deformable=False, return_map=False):
"""Pulls simulation output into structured 2D arrays for transect-based, (i,j) indexing.
Input:
varnames | A list of variable names to pull, e.g.
| ['saturation_liquid', 'saturation_ice'], or a single variable
| name, e.g. 'saturation_liquid'
keys | Indices of timesteps to pull. Either an int (i.e. 0, -1, etc)
| for the kth timestep, or a list of ints, or 'all'.
directory | Directory of the run. Defaults to '.'
filename | Filename of the run. Defaults to 'visdump_data.h5'
mesh_filename | Filename of the mesh. Defaults to 'visdump_mesh.h5'
coord_order | Order of the transect coordinates. Defaults to ['x','z']. The
| mesh is sorted in this order.
deformable | Is the mesh deforming?
return_map | See return value below.
Output:
Output is an array of shape:
( len(varnames+2), len(keys), n_cells_coord_order[0], n_cells_coord_order[1] )
data[0,0,:,:] is the coord_order[0] centroid
data[1,0,:,:] is the coord_order[1] centroid
data[i+2,k,:,:] is the ith varname data at the kth requested timestep, sorted in
the same way as the centroids.
Note that the data is re-ordered in INCREASING coordinate, i.e. bottom to top in z.
If return_map is True, then returns a tuple, (data, map) where
map is a (NX,NZ) array of integers specifying which global id
corresponds to the (i,j) cell. This is useful for mapping input
data back INTO the unstructured mesh.
Example usage:
Calculate and plot the thaw depth at step 5.
// Pull saturation ice -- TD is where sat ice = 0."
data = transect_data(['saturation_ice', 5)
// x coordinate for plotting
x = data[0,0,:,0]
// for each column, find highest z where sat_ice > 0.
td_i = np.array([np.where(data[2,0,i,:] > 0.)[0][-1] for i in range(data.shape[2])])
// now that we have an index into the highest cell with ice, determine td as the
// mean of the highest cell with ice and the one above that. Note this assumes
// all columns have some thawing.
td_z = np.array( [ (dat[1,0,i,td_i[i]] + dat[1,0,i,td_i[i+1]]) / 2.
for i in range(len(td_i)) ] )
plt.plot(x, td_z)
"""
if coord_order is None:
coord_order = ['x','z']
if type(varnames) is str:
varnames = [varnames,]
# get centroids
xyz = mesh.meshElemCentroids(mesh_filename, directory)
# round to avoid issues
xyz = np.round(xyz, decimals=5)
# get ordering of centroids
dtype = [(coord_order[0], float), (coord_order[1], float)]
num_order = []
for i in coord_order:
if i == 'x':
num_order.append(0)
elif i == 'y':
num_order.append(1)
elif i == 'z':
num_order.append(2)
xyz_sort_order = np.array([tuple([xyz[i,x] for x in num_order]) for i in range(len(xyz))], dtype=dtype)
xyz_sorting = xyz_sort_order.argsort(order=coord_order)
with h5py.File(os.path.join(directory,filename),'r') as dat:
keys_avail = dat[fullname(varnames[0])].keys()
keys_avail.sort(lambda a,b: int.__cmp__(int(a),int(b)))
if keys == 'all':
keys = keys_avail
elif type(keys) is str:
keys = [keys,]
elif type(keys) is int:
keys = [keys_avail[keys],]
elif type(keys) is slice:
keys = keys_avail[keys]
elif type(keys) is list:
if all(type(k) is int for k in keys):
keys = [keys_avail[k] for k in keys]
elif all(type(k) is str for k in keys):
pass
else:
raise RuntimeError("Keys requested cannot be processed -- should be 'all', int, or str key, or list of ints or strs.")
# get data
vals = np.zeros((len(varnames)+2, len(keys), len(xyz)), 'd')
for i,key in enumerate(keys):
if deformable:
xyz = mesh.meshElemCentroids(mesh_filename, directory)
vals[0,i,:] = xyz[xyz_sorting,num_order[0]]
vals[1,i,:] = xyz[xyz_sorting,num_order[1]]
for j,varname in enumerate(varnames):
vals[j+2,i,:] = dat[fullname(varname)][key][:,0][xyz_sorting]
# reshape the data
# determine nx
nx = len(set(vals[0,0,:]))
nz = vals.shape[2] / nx
if (nx * nz != vals.shape[2]):
raise RuntimeError("Assumption about first coordinate being cleanly binnable is falling apart -- ask Ethan to rethink this algorithm!")
shp = vals.shape
if not return_map:
return vals.reshape(shp[0], shp[1], nx, nz)
else:
return vals.reshape(shp[0], shp[1], nx, nz), xyz_sorting.reshape(nx, nz)
def plot(dataset, ax, cax=None, vmin=None, vmax=None, cmap="jet",
label=None, mesh_filename="visdump_mesh.h5", directory=".", y_coord=0.0,
linewidths=1):
"""Draws a dataset on an ax."""
import matplotlib.collections
from matplotlib import pyplot as plt
if vmin is None:
vmin = dataset.min()
if vmax is None:
vmax = dataset.max()
# get the mesh and collapse to 2D
etype, coords, conn = mesh.meshElemXYZ(filename=mesh_filename, directory=directory)
if etype is not 'HEX':
raise RuntimeError("Only works for Hexs")
coords2 = np.array([[coords[i][0::2] for i in c[1:] if abs(coords[i][1] - y_coord) < 1.e-8] for c in conn])
try:
assert coords2.shape[2] == 2
assert coords2.shape[1] == 4
except AssertionError:
print(coords2.shape)
for c in conn:
if len(c) != 9:
print c
raise RuntimeError("what is a conn?")
coords3 = np.array([coords[i][:] for i in c[1:] if abs(coords[i][1] - y_coord) < 1.e-8])
if coords3.shape[0] != 4:
print coords
raise RuntimeError("Unable to squash to 2D")
# reorder anti-clockwise
for i,c in enumerate(coords2):
centroid = c.mean(axis=0)
def angle(p1,p2):
a1 = np.arctan2((p1[1]-centroid[1]),(p1[0]-centroid[0]))
a2 = np.arctan2((p2[1]-centroid[1]),(p2[0]-centroid[0]))
if a1 < a2:
return -1
elif a2 < a1:
return 1
else:
return 0
c2 = np.array(sorted(c,angle))
coords2[i] = c2
polygons = matplotlib.collections.PolyCollection(coords2, edgecolor='k', cmap=cmap, linewidths=linewidths)
polygons.set_array(dataset)
polygons.set_clim(vmin,vmax)
ax.add_collection(polygons)
xmin = min(c[0] for c in coords.itervalues())
xmax = max(c[0] for c in coords.itervalues())
zmin = min(c[2] for c in coords.itervalues())
zmax = max(c[2] for c in coords.itervalues())
ax.set_xlim(xmin,xmax)
ax.set_ylim(zmin,zmax)
if cax is not None:
cb = plt.colorbar(polygons, cax=cax)
if label is not None:
cb.set_label(label)
return ((xmin,xmax),(zmin,zmax))
|
bsd-3-clause
|
[
624,
30777,
436,
15,
269,
19695,
499,
36,
12,
11111,
793,
606,
1183,
21781,
666,
641,
16744,
322,
18103,
2551,
1808,
8027,
14,
199,
624,
199,
199,
646,
984,
12,
736,
199,
646,
2680,
465,
980,
199,
646,
394,
21,
647,
199,
646,
9364,
199,
646,
9229,
199,
199,
318,
11064,
8,
16043,
304,
272,
11064,
275,
22071,
272,
340,
440,
1987,
3890,
3530,
315,
11064,
26,
267,
11064,
275,
11064,
18098,
3890,
14,
16,
7,
272,
372,
11064,
421,
199,
318,
7115,
8519,
63,
576,
8,
1391,
1247,
12,
2883,
534,
452,
297,
2082,
628,
4765,
1788,
628,
5068,
2724,
63,
576,
14,
72,
21,
401,
2116,
9364,
63,
1501,
628,
5068,
2724,
63,
6480,
14,
72,
21,
401,
11021,
63,
1648,
29,
403,
12,
347,
1025,
461,
29,
797,
12,
372,
63,
1130,
29,
797,
304,
272,
408,
48,
13072,
17625,
1072,
1901,
21781,
499,
36,
6572,
367,
7115,
8519,
13,
6788,
12,
334,
73,
12,
74,
9,
16356,
14,
339,
6924,
26,
489,
2729,
1247,
755,
1204,
437,
769,
402,
1750,
1561,
370,
10299,
12,
325,
14,
71,
14,
2151,
1204,
221,
788,
14997,
1542,
63,
317,
28398,
297,
283,
14997,
1542,
63,
1885,
995,
503,
282,
2849,
1750,
2151,
1204,
221,
536,
12,
325,
14,
71,
14,
283,
14997,
1542,
63,
317,
28398,
7,
489,
2883,
3698,
1204,
1010,
12503,
402,
900,
5895,
370,
10299,
14,
221,
13083,
376,
1109,
334,
73,
14,
69,
14,
378,
12,
446,
17,
12,
5423,
9,
221,
2151,
1204,
221,
367,
314,
1022,
273,
900,
2926,
12,
503,
282,
769,
402,
14526,
12,
503,
283,
452,
1370,
489,
2082,
420,
1204,
15191,
402,
314,
1255,
14,
221,
7827,
370,
7815,
489,
1788,
755,
1204,
31167,
402,
314,
1255,
14,
221,
7827,
370,
283,
5068,
2724,
63,
576,
14,
72,
21,
7,
489,
9364,
63,
1501,
221,
1204,
31167,
402,
314,
9364,
14,
221,
7827,
370,
283,
5068,
2724,
63,
6480,
14,
72,
21,
7,
489,
11021,
63,
1648,
259,
1204,
9240,
402,
314,
7115,
8519,
8983,
14,
221,
7827,
370,
788,
88,
1673,
90,
2278,
221,
710,
221,
2151,
1204,
221,
9364,
365,
3355,
315,
642,
1865,
14,
489,
347,
1025,
461,
258,
1204,
6596,
314,
9364,
347,
1025,
316,
31,
489,
372,
63,
1130,
258,
1204,
1666,
372,
574,
5084,
14,
272,
272,
7242,
26,
489,
7242,
365,
376,
1625,
402,
2215,
26,
489,
334,
822,
8,
1391,
1247,
11,
18,
395,
822,
8,
1612,
395,
302,
63,
9041,
63,
7988,
63,
1648,
59,
16,
467,
302,
63,
9041,
63,
7988,
63,
1648,
59,
17,
61,
776,
1362,
489,
666,
59,
16,
12,
16,
32306,
2938,
365,
314,
11021,
63,
1648,
59,
16,
61,
27587,
489,
666,
59,
17,
12,
16,
32306,
2938,
365,
314,
11021,
63,
1648,
59,
17,
61,
27587,
489,
666,
59,
73,
11,
18,
12,
75,
32306,
2938,
365,
314,
284,
273,
22071,
666,
737,
314,
1022,
273,
5839,
900,
2926,
12,
3355,
315,
221,
1993,
314,
2011,
4340,
465,
314,
13345,
26188,
14,
2541,
3390,
626,
314,
666,
365,
295,
13,
8235,
315,
1621,
5798,
1179,
1206,
10021,
12,
284,
14,
69,
14,
9048,
370,
2746,
315,
1315,
14,
2541,
982,
372,
63,
1130,
365,
715,
12,
2066,
2529,
282,
2008,
12,
334,
576,
12,
2341,
9,
2382,
489,
2341,
365,
282,
334,
16764,
12,
19011,
9,
1625,
402,
9446,
9176,
1314,
2288,
1305,
489,
13718,
370,
314,
334,
73,
12,
74,
9,
4917,
14,
221,
961,
365,
2997,
367,
4412,
1324,
489,
666,
1771,
12872,
314,
625,
15774,
9364,
14,
339,
5679,
4503,
26,
257,
489,
12707,
436,
5137,
314,
294,
10084,
5818,
737,
3650,
959,
14,
2541,
5001,
27705,
21845,
1542,
284,
301,
1553,
31360,
365,
2382,
21845,
284,
301,
275,
378,
2122,
489,
666,
275,
7115,
8519,
63,
576,
2941,
14997,
1542,
63,
1885,
297,
959,
9,
2541,
5001,
671,
10021,
367,
25174,
489,
671,
275,
666,
59,
16,
12,
16,
32306,
16,
61,
1362,
489,
5001,
367,
1924,
2763,
12,
2342,
15356,
1315,
2382,
21845,
63,
1885,
690,
378,
14,
489,
12749,
63,
73,
275,
980,
14,
1144,
779,
1590,
14,
4509,
8,
576,
59,
18,
12,
16,
12,
73,
21063,
690,
378,
14,
2788,
16,
15898,
17,
61,
367,
284,
315,
1425,
8,
576,
14,
1392,
59,
18,
24310,
2541,
5001,
3063,
626,
781,
1172,
376,
1478,
1901,
314,
15356,
4917,
543,
284,
301,
12,
6705,
12749,
465,
314,
15166,
5001,
4615,
402,
314,
15356,
4917,
543,
284,
301,
436,
314,
1373,
3432,
626,
14,
221,
3390,
642,
15194,
489,
5001,
1006,
4362,
1172,
2005,
294,
10084,
316,
14,
489,
12749,
63,
90,
275,
980,
14,
1144,
8,
359,
221,
334,
4616,
59,
17,
12,
16,
12,
73,
12,
2076,
63,
73,
59,
73,
2677,
435,
6394,
59,
17,
12,
16,
12,
73,
12,
2076,
63,
73,
59,
73,
11,
17,
3934,
1182,
499,
14,
221,
2892,
367,
284,
315,
1425,
8,
552,
8,
2076,
63,
73,
430,
1622,
776,
2541,
4488,
14,
2798,
8,
88,
12,
12749,
63,
90,
9,
339,
408,
272,
340,
11021,
63,
1648,
365,
488,
26,
267,
11021,
63,
1648,
275,
788,
88,
1673,
90,
418,
339,
340,
730,
8,
1391,
1247,
9,
365,
620,
26,
267,
2729,
1247,
275,
359,
1391,
1247,
12,
61,
339,
327,
664,
13345,
26188,
272,
24122,
275,
9364,
14,
6480,
28284,
22744,
26188,
8,
6480,
63,
1501,
12,
2082,
9,
339,
327,
6168,
370,
5126,
10876,
272,
24122,
275,
980,
14,
2363,
8,
8568,
12,
6107,
83,
29,
21,
9,
339,
327,
664,
7794,
402,
13345,
26188,
272,
2152,
275,
3842,
7988,
63,
1648,
59,
16,
467,
2069,
395,
334,
7988,
63,
1648,
59,
17,
467,
2069,
1874,
272,
1967,
63,
1648,
275,
942,
272,
367,
284,
315,
11021,
63,
1648,
26,
267,
340,
284,
508,
283,
88,
356,
288,
1967,
63,
1648,
14,
740,
8,
16,
9,
267,
916,
284,
508,
283,
89,
356,
288,
1967,
63,
1648,
14,
740,
8,
17,
9,
267,
916,
284,
508,
283,
90,
356,
288,
1967,
63,
1648,
14,
740,
8,
18,
9,
339,
24122,
63,
3191,
63,
1648,
275,
980,
14,
1144,
779,
2960,
779,
8568,
59,
73,
12,
88,
61,
367,
671,
315
] |
[
30777,
436,
15,
269,
19695,
499,
36,
12,
11111,
793,
606,
1183,
21781,
666,
641,
16744,
322,
18103,
2551,
1808,
8027,
14,
199,
624,
199,
199,
646,
984,
12,
736,
199,
646,
2680,
465,
980,
199,
646,
394,
21,
647,
199,
646,
9364,
199,
646,
9229,
199,
199,
318,
11064,
8,
16043,
304,
272,
11064,
275,
22071,
272,
340,
440,
1987,
3890,
3530,
315,
11064,
26,
267,
11064,
275,
11064,
18098,
3890,
14,
16,
7,
272,
372,
11064,
421,
199,
318,
7115,
8519,
63,
576,
8,
1391,
1247,
12,
2883,
534,
452,
297,
2082,
628,
4765,
1788,
628,
5068,
2724,
63,
576,
14,
72,
21,
401,
2116,
9364,
63,
1501,
628,
5068,
2724,
63,
6480,
14,
72,
21,
401,
11021,
63,
1648,
29,
403,
12,
347,
1025,
461,
29,
797,
12,
372,
63,
1130,
29,
797,
304,
272,
408,
48,
13072,
17625,
1072,
1901,
21781,
499,
36,
6572,
367,
7115,
8519,
13,
6788,
12,
334,
73,
12,
74,
9,
16356,
14,
339,
6924,
26,
489,
2729,
1247,
755,
1204,
437,
769,
402,
1750,
1561,
370,
10299,
12,
325,
14,
71,
14,
2151,
1204,
221,
788,
14997,
1542,
63,
317,
28398,
297,
283,
14997,
1542,
63,
1885,
995,
503,
282,
2849,
1750,
2151,
1204,
221,
536,
12,
325,
14,
71,
14,
283,
14997,
1542,
63,
317,
28398,
7,
489,
2883,
3698,
1204,
1010,
12503,
402,
900,
5895,
370,
10299,
14,
221,
13083,
376,
1109,
334,
73,
14,
69,
14,
378,
12,
446,
17,
12,
5423,
9,
221,
2151,
1204,
221,
367,
314,
1022,
273,
900,
2926,
12,
503,
282,
769,
402,
14526,
12,
503,
283,
452,
1370,
489,
2082,
420,
1204,
15191,
402,
314,
1255,
14,
221,
7827,
370,
7815,
489,
1788,
755,
1204,
31167,
402,
314,
1255,
14,
221,
7827,
370,
283,
5068,
2724,
63,
576,
14,
72,
21,
7,
489,
9364,
63,
1501,
221,
1204,
31167,
402,
314,
9364,
14,
221,
7827,
370,
283,
5068,
2724,
63,
6480,
14,
72,
21,
7,
489,
11021,
63,
1648,
259,
1204,
9240,
402,
314,
7115,
8519,
8983,
14,
221,
7827,
370,
788,
88,
1673,
90,
2278,
221,
710,
221,
2151,
1204,
221,
9364,
365,
3355,
315,
642,
1865,
14,
489,
347,
1025,
461,
258,
1204,
6596,
314,
9364,
347,
1025,
316,
31,
489,
372,
63,
1130,
258,
1204,
1666,
372,
574,
5084,
14,
272,
272,
7242,
26,
489,
7242,
365,
376,
1625,
402,
2215,
26,
489,
334,
822,
8,
1391,
1247,
11,
18,
395,
822,
8,
1612,
395,
302,
63,
9041,
63,
7988,
63,
1648,
59,
16,
467,
302,
63,
9041,
63,
7988,
63,
1648,
59,
17,
61,
776,
1362,
489,
666,
59,
16,
12,
16,
32306,
2938,
365,
314,
11021,
63,
1648,
59,
16,
61,
27587,
489,
666,
59,
17,
12,
16,
32306,
2938,
365,
314,
11021,
63,
1648,
59,
17,
61,
27587,
489,
666,
59,
73,
11,
18,
12,
75,
32306,
2938,
365,
314,
284,
273,
22071,
666,
737,
314,
1022,
273,
5839,
900,
2926,
12,
3355,
315,
221,
1993,
314,
2011,
4340,
465,
314,
13345,
26188,
14,
2541,
3390,
626,
314,
666,
365,
295,
13,
8235,
315,
1621,
5798,
1179,
1206,
10021,
12,
284,
14,
69,
14,
9048,
370,
2746,
315,
1315,
14,
2541,
982,
372,
63,
1130,
365,
715,
12,
2066,
2529,
282,
2008,
12,
334,
576,
12,
2341,
9,
2382,
489,
2341,
365,
282,
334,
16764,
12,
19011,
9,
1625,
402,
9446,
9176,
1314,
2288,
1305,
489,
13718,
370,
314,
334,
73,
12,
74,
9,
4917,
14,
221,
961,
365,
2997,
367,
4412,
1324,
489,
666,
1771,
12872,
314,
625,
15774,
9364,
14,
339,
5679,
4503,
26,
257,
489,
12707,
436,
5137,
314,
294,
10084,
5818,
737,
3650,
959,
14,
2541,
5001,
27705,
21845,
1542,
284,
301,
1553,
31360,
365,
2382,
21845,
284,
301,
275,
378,
2122,
489,
666,
275,
7115,
8519,
63,
576,
2941,
14997,
1542,
63,
1885,
297,
959,
9,
2541,
5001,
671,
10021,
367,
25174,
489,
671,
275,
666,
59,
16,
12,
16,
32306,
16,
61,
1362,
489,
5001,
367,
1924,
2763,
12,
2342,
15356,
1315,
2382,
21845,
63,
1885,
690,
378,
14,
489,
12749,
63,
73,
275,
980,
14,
1144,
779,
1590,
14,
4509,
8,
576,
59,
18,
12,
16,
12,
73,
21063,
690,
378,
14,
2788,
16,
15898,
17,
61,
367,
284,
315,
1425,
8,
576,
14,
1392,
59,
18,
24310,
2541,
5001,
3063,
626,
781,
1172,
376,
1478,
1901,
314,
15356,
4917,
543,
284,
301,
12,
6705,
12749,
465,
314,
15166,
5001,
4615,
402,
314,
15356,
4917,
543,
284,
301,
436,
314,
1373,
3432,
626,
14,
221,
3390,
642,
15194,
489,
5001,
1006,
4362,
1172,
2005,
294,
10084,
316,
14,
489,
12749,
63,
90,
275,
980,
14,
1144,
8,
359,
221,
334,
4616,
59,
17,
12,
16,
12,
73,
12,
2076,
63,
73,
59,
73,
2677,
435,
6394,
59,
17,
12,
16,
12,
73,
12,
2076,
63,
73,
59,
73,
11,
17,
3934,
1182,
499,
14,
221,
2892,
367,
284,
315,
1425,
8,
552,
8,
2076,
63,
73,
430,
1622,
776,
2541,
4488,
14,
2798,
8,
88,
12,
12749,
63,
90,
9,
339,
408,
272,
340,
11021,
63,
1648,
365,
488,
26,
267,
11021,
63,
1648,
275,
788,
88,
1673,
90,
418,
339,
340,
730,
8,
1391,
1247,
9,
365,
620,
26,
267,
2729,
1247,
275,
359,
1391,
1247,
12,
61,
339,
327,
664,
13345,
26188,
272,
24122,
275,
9364,
14,
6480,
28284,
22744,
26188,
8,
6480,
63,
1501,
12,
2082,
9,
339,
327,
6168,
370,
5126,
10876,
272,
24122,
275,
980,
14,
2363,
8,
8568,
12,
6107,
83,
29,
21,
9,
339,
327,
664,
7794,
402,
13345,
26188,
272,
2152,
275,
3842,
7988,
63,
1648,
59,
16,
467,
2069,
395,
334,
7988,
63,
1648,
59,
17,
467,
2069,
1874,
272,
1967,
63,
1648,
275,
942,
272,
367,
284,
315,
11021,
63,
1648,
26,
267,
340,
284,
508,
283,
88,
356,
288,
1967,
63,
1648,
14,
740,
8,
16,
9,
267,
916,
284,
508,
283,
89,
356,
288,
1967,
63,
1648,
14,
740,
8,
17,
9,
267,
916,
284,
508,
283,
90,
356,
288,
1967,
63,
1648,
14,
740,
8,
18,
9,
339,
24122,
63,
3191,
63,
1648,
275,
980,
14,
1144,
779,
2960,
779,
8568,
59,
73,
12,
88,
61,
367,
671,
315,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ltilve/chromium
|
chrome/test/data/search/tools/instant_extended_manual_tests.py
|
70
|
1952
|
#!/usr/bin/env python
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Records or runs web-page-replay data for InstantExtendedManualTests.*.
Typical usage is:
$ cd src/chrome/test/data/search/tools/
$ sudo instant_extended_manual_tests.py record \
../../../../../third_party/webpagereplay/replay.py \
../../../../../out/Debug/interactive_ui_tests \
../replay/archive.wpr
This will create the archive.wpr file against the lastest google.com GWS.
The tests then can be isolated from the live site by replaying this captured
session on the bots.
This archive.wpr file should be re-recorded and checked into the repo whenever
new manual tests are created.
"""
import signal
import subprocess
import sys
def Usage():
print 'Usage: sudo python instant_extended_manual_tests.py (record|run) \\'
print ' <path/to/replay> <path/to/ui_tests> <path/to/data>'
return 1
def ReplayTests(replay_path, test_path, data_path, arg=None):
# Start up web-page-replay.
if not arg:
p = subprocess.Popen([replay_path, data_path])
else:
p = subprocess.Popen([replay_path, arg, data_path])
# Run the tests within the mock server.
return_value = subprocess.call(
[test_path,
'--gtest_filter=InstantExtendedManualTest.*',
'--run-manual',
'--enable-benchmarking',
'--enable-stats-table',
'--ignore-certificate-errors'])
# Shut down web-page-replay and save the recorded session to |data_path|.
p.send_signal(signal.SIGINT)
p.wait()
return return_value
def main():
if len(sys.argv) != 5:
return Usage()
if sys.argv[1] == 'record':
return ReplayTests(sys.argv[2], sys.argv[3], sys.argv[4], '--record')
if sys.argv[1] == 'run':
return ReplayTests(sys.argv[2], sys.argv[3], sys.argv[4])
return Usage()
if __name__ == '__main__':
sys.exit(main())
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
14941,
503,
7858,
3330,
13,
1606,
13,
19540,
666,
367,
1010,
4715,
14107,
22382,
2925,
2795,
14,
199,
26876,
4503,
365,
26,
421,
2672,
12829,
2928,
15,
9887,
15,
396,
15,
576,
15,
1733,
15,
2537,
15,
199,
2672,
14682,
2727,
867,
63,
10525,
63,
9285,
63,
2219,
14,
647,
2777,
971,
1362,
24272,
9707,
9707,
11470,
63,
7522,
15,
12022,
19540,
15,
19540,
14,
647,
971,
1362,
24272,
9707,
9707,
548,
15,
7084,
15,
13543,
63,
1907,
63,
2219,
971,
1362,
24272,
19540,
15,
6404,
14,
87,
2700,
199,
199,
2765,
911,
1218,
314,
6359,
14,
87,
2700,
570,
6169,
314,
23325,
396,
6233,
14,
957,
598,
5035,
14,
199,
1918,
2295,
2066,
883,
506,
23348,
687,
314,
12166,
4770,
701,
24331,
316,
642,
17487,
199,
1730,
641,
314,
31726,
14,
199,
199,
2765,
6359,
14,
87,
2700,
570,
1077,
506,
295,
13,
264,
15402,
436,
7923,
1901,
314,
3831,
18119,
199,
1222,
8722,
2295,
787,
2737,
14,
199,
624,
199,
199,
646,
4673,
199,
646,
3873,
199,
646,
984,
199,
199,
318,
11028,
837,
523,
870,
283,
7692,
26,
14682,
2366,
2727,
867,
63,
10525,
63,
9285,
63,
2219,
14,
647,
334,
3059,
92,
1065,
9,
971,
3985,
523,
870,
283,
260,
665,
515,
15,
475,
15,
19540,
30,
665,
515,
15,
475,
15,
1907,
63,
2219,
30,
665,
515,
15,
475,
15,
576,
3524,
523,
372,
413,
199,
199,
318,
799,
2802,
2925,
8,
19540,
63,
515,
12,
511,
63,
515,
12,
666,
63,
515,
12,
1680,
29,
403,
304,
523,
327,
7707,
1536,
3330,
13,
1606,
13,
19540,
14,
523,
340,
440,
1680,
26,
272,
299,
275,
3873,
14,
7942,
779,
19540,
63,
515,
12,
666,
63,
515,
566,
523,
587,
26,
272,
299,
275,
3873,
14,
7942,
779,
19540,
63,
515,
12,
1680,
12,
666,
63,
515,
566,
819,
327,
3378,
314,
2295,
4453,
314,
1683,
1654,
14,
523,
372,
63,
585,
275,
3873,
14,
1250,
8,
272,
359,
396,
63,
515,
12,
1362,
2850,
8385,
63,
1541,
29,
607,
4715,
14107,
22382,
774,
16110,
1362,
2850,
1065,
13,
9285,
297,
1362,
2850,
4296,
13,
11861,
316,
297,
1362,
2850,
4296,
13,
3200,
13,
1224,
297,
1362,
2850,
4247,
13,
6999,
13,
2550,
1105,
819,
327,
5244,
337,
3224,
3330,
13,
1606,
13,
19540,
436,
3354,
314,
18894,
2351,
370,
1204,
576,
63,
515,
18257,
523,
299,
14,
2254,
63,
4653,
8,
4653,
14,
21223,
9,
523,
299,
14,
2573,
342,
523,
372,
372,
63,
585,
199,
199,
318,
2446,
837,
523,
340,
822,
8,
1274,
14,
3020,
9,
1137,
959,
26,
272,
372,
11028,
342,
819,
340,
984,
14,
3020,
59,
17,
61,
508,
283,
3059,
356,
272,
372,
799,
2802,
2925,
8,
1274,
14,
3020,
59,
18,
467,
984,
14,
3020,
59,
19,
467,
984,
14,
3020,
59,
20,
467,
2850,
3059,
358,
819,
340,
984,
14,
3020,
59,
17,
61,
508,
283,
1065,
356,
272,
372,
799,
2802,
2925,
8,
1274,
14,
3020,
59,
18,
467,
984,
14,
3020,
59,
19,
467,
984,
14,
3020,
59,
20,
566,
819,
372,
11028,
342,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
984,
14,
2224,
8,
973,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
14941,
503,
7858,
3330,
13,
1606,
13,
19540,
666,
367,
1010,
4715,
14107,
22382,
2925,
2795,
14,
199,
26876,
4503,
365,
26,
421,
2672,
12829,
2928,
15,
9887,
15,
396,
15,
576,
15,
1733,
15,
2537,
15,
199,
2672,
14682,
2727,
867,
63,
10525,
63,
9285,
63,
2219,
14,
647,
2777,
971,
1362,
24272,
9707,
9707,
11470,
63,
7522,
15,
12022,
19540,
15,
19540,
14,
647,
971,
1362,
24272,
9707,
9707,
548,
15,
7084,
15,
13543,
63,
1907,
63,
2219,
971,
1362,
24272,
19540,
15,
6404,
14,
87,
2700,
199,
199,
2765,
911,
1218,
314,
6359,
14,
87,
2700,
570,
6169,
314,
23325,
396,
6233,
14,
957,
598,
5035,
14,
199,
1918,
2295,
2066,
883,
506,
23348,
687,
314,
12166,
4770,
701,
24331,
316,
642,
17487,
199,
1730,
641,
314,
31726,
14,
199,
199,
2765,
6359,
14,
87,
2700,
570,
1077,
506,
295,
13,
264,
15402,
436,
7923,
1901,
314,
3831,
18119,
199,
1222,
8722,
2295,
787,
2737,
14,
199,
624,
199,
199,
646,
4673,
199,
646,
3873,
199,
646,
984,
199,
199,
318,
11028,
837,
523,
870,
283,
7692,
26,
14682,
2366,
2727,
867,
63,
10525,
63,
9285,
63,
2219,
14,
647,
334,
3059,
92,
1065,
9,
971,
3985,
523,
870,
283,
260,
665,
515,
15,
475,
15,
19540,
30,
665,
515,
15,
475,
15,
1907,
63,
2219,
30,
665,
515,
15,
475,
15,
576,
3524,
523,
372,
413,
199,
199,
318,
799,
2802,
2925,
8,
19540,
63,
515,
12,
511,
63,
515,
12,
666,
63,
515,
12,
1680,
29,
403,
304,
523,
327,
7707,
1536,
3330,
13,
1606,
13,
19540,
14,
523,
340,
440,
1680,
26,
272,
299,
275,
3873,
14,
7942,
779,
19540,
63,
515,
12,
666,
63,
515,
566,
523,
587,
26,
272,
299,
275,
3873,
14,
7942,
779,
19540,
63,
515,
12,
1680,
12,
666,
63,
515,
566,
819,
327,
3378,
314,
2295,
4453,
314,
1683,
1654,
14,
523,
372,
63,
585,
275,
3873,
14,
1250,
8,
272,
359,
396,
63,
515,
12,
1362,
2850,
8385,
63,
1541,
29,
607,
4715,
14107,
22382,
774,
16110,
1362,
2850,
1065,
13,
9285,
297,
1362,
2850,
4296,
13,
11861,
316,
297,
1362,
2850,
4296,
13,
3200,
13,
1224,
297,
1362,
2850,
4247,
13,
6999,
13,
2550,
1105,
819,
327,
5244,
337,
3224,
3330,
13,
1606,
13,
19540,
436,
3354,
314,
18894,
2351,
370,
1204,
576,
63,
515,
18257,
523,
299,
14,
2254,
63,
4653,
8,
4653,
14,
21223,
9,
523,
299,
14,
2573,
342,
523,
372,
372,
63,
585,
199,
199,
318,
2446,
837,
523,
340,
822,
8,
1274,
14,
3020,
9,
1137,
959,
26,
272,
372,
11028,
342,
819,
340,
984,
14,
3020,
59,
17,
61,
508,
283,
3059,
356,
272,
372,
799,
2802,
2925,
8,
1274,
14,
3020,
59,
18,
467,
984,
14,
3020,
59,
19,
467,
984,
14,
3020,
59,
20,
467,
2850,
3059,
358,
819,
340,
984,
14,
3020,
59,
17,
61,
508,
283,
1065,
356,
272,
372,
799,
2802,
2925,
8,
1274,
14,
3020,
59,
18,
467,
984,
14,
3020,
59,
19,
467,
984,
14,
3020,
59,
20,
566,
819,
372,
11028,
342,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
984,
14,
2224,
8,
973,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
gunan/tensorflow
|
tensorflow/python/keras/layers/preprocessing/benchmarks/categorical_encoding_benchmark.py
|
1
|
3177
|
# Copyright 2020 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.
# ==============================================================================
"""Benchmark for Keras categorical_encoding preprocessing layer."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import time
from absl import flags
import numpy as np
from tensorflow.python import keras
from tensorflow.python.compat import v2_compat
from tensorflow.python.data.ops import dataset_ops
from tensorflow.python.framework import dtypes
from tensorflow.python.keras.layers.preprocessing import categorical_encoding
from tensorflow.python.ops import random_ops
from tensorflow.python.platform import benchmark
from tensorflow.python.platform import test
FLAGS = flags.FLAGS
v2_compat.enable_v2_behavior()
class BenchmarkLayer(benchmark.Benchmark):
"""Benchmark the layer forward pass."""
def run_dataset_implementation(self, output_mode, batch_size, sequence_length,
max_tokens):
input_t = keras.Input(shape=(sequence_length,), dtype=dtypes.int32)
layer = categorical_encoding.CategoricalEncoding(
max_tokens=max_tokens, output_mode=output_mode)
_ = layer(input_t)
num_repeats = 5
starts = []
ends = []
for _ in range(num_repeats):
ds = dataset_ops.Dataset.from_tensor_slices(
random_ops.random_uniform([batch_size * 10, sequence_length],
minval=0,
maxval=max_tokens - 1,
dtype=dtypes.int32))
ds = ds.shuffle(batch_size * 100)
ds = ds.batch(batch_size)
num_batches = 5
ds = ds.take(num_batches)
ds = ds.prefetch(num_batches)
starts.append(time.time())
# Benchmarked code begins here.
for i in ds:
_ = layer(i)
# Benchmarked code ends here.
ends.append(time.time())
avg_time = np.mean(np.array(ends) - np.array(starts)) / num_batches
name = "categorical_encoding|batch_%s|seq_length_%s|%s_max_tokens" % (
batch_size, sequence_length, max_tokens)
self.report_benchmark(iters=num_repeats, wall_time=avg_time, name=name)
def benchmark_vocab_size_by_batch(self):
for batch in [32, 256, 2048]:
for sequence_length in [10, 1000]:
for num_tokens in [100, 1000, 20000]:
self.run_dataset_implementation(
output_mode="count",
batch_size=batch,
sequence_length=sequence_length,
max_tokens=num_tokens)
if __name__ == "__main__":
test.main()
|
apache-2.0
|
[
3,
1898,
25455,
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,
18644,
367,
1804,
30037,
22138,
63,
2991,
26471,
4045,
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,
646,
900,
199,
199,
504,
2853,
76,
492,
3285,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
492,
11708,
199,
504,
3228,
14,
1548,
14,
5819,
492,
373,
18,
63,
5819,
199,
504,
3228,
14,
1548,
14,
576,
14,
1483,
492,
4789,
63,
1483,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
8811,
14,
4359,
14,
21402,
492,
22138,
63,
2991,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2196,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
12338,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
199,
4831,
275,
3285,
14,
4831,
199,
199,
86,
18,
63,
5819,
14,
4296,
63,
86,
18,
63,
17537,
342,
421,
199,
533,
27067,
5003,
8,
11861,
14,
18644,
304,
523,
408,
18644,
314,
4045,
7568,
986,
1041,
819,
347,
1255,
63,
5214,
63,
12236,
8,
277,
12,
1072,
63,
632,
12,
3522,
63,
890,
12,
3414,
63,
1267,
12,
639,
1390,
63,
4504,
304,
272,
1324,
63,
84,
275,
11708,
14,
3205,
8,
1392,
2687,
4041,
63,
1267,
4706,
2152,
29,
5717,
14,
442,
708,
9,
272,
4045,
275,
22138,
63,
2991,
14,
23306,
7630,
8,
267,
1390,
63,
4504,
29,
988,
63,
4504,
12,
1072,
63,
632,
29,
1199,
63,
632,
9,
272,
485,
275,
4045,
8,
1210,
63,
84,
9,
339,
1967,
63,
32547,
275,
959,
272,
9174,
275,
942,
272,
11187,
275,
942,
272,
367,
485,
315,
1425,
8,
1507,
63,
32547,
304,
489,
6364,
275,
4789,
63,
1483,
14,
9271,
14,
504,
63,
3128,
63,
14865,
8,
881,
2196,
63,
1483,
14,
2355,
63,
8830,
779,
2912,
63,
890,
627,
1616,
12,
3414,
63,
1267,
467,
2511,
30135,
29,
16,
12,
2511,
23291,
29,
988,
63,
4504,
446,
413,
12,
2511,
2152,
29,
5717,
14,
442,
708,
430,
489,
6364,
275,
6364,
14,
11777,
8,
2912,
63,
890,
627,
2948,
9,
489,
6364,
275,
6364,
14,
2912,
8,
2912,
63,
890,
9,
489,
1967,
63,
14896,
275,
959,
489,
6364,
275,
6364,
14,
11066,
8,
1507,
63,
14896,
9,
489,
6364,
275,
6364,
14,
15576,
8,
1507,
63,
14896,
9,
489,
9174,
14,
740,
8,
521,
14,
521,
1012,
489,
327,
27067,
379,
1233,
22241,
2348,
14,
489,
367,
284,
315,
6364,
26,
267,
485,
275,
4045,
8,
73,
9,
489,
327,
27067,
379,
1233,
11187,
2348,
14,
489,
11187,
14,
740,
8,
521,
14,
521,
1012,
339,
12402,
63,
521,
275,
980,
14,
3670,
8,
1590,
14,
1144,
8,
3198,
9,
446,
980,
14,
1144,
8,
17116,
430,
1182,
1967,
63,
14896,
272,
536,
275,
298,
16810,
63,
2991,
92,
2912,
4970,
83,
92,
3610,
63,
1267,
4970,
83,
15287,
83,
63,
988,
63,
4504,
2,
450,
334,
267,
3522,
63,
890,
12,
3414,
63,
1267,
12,
1390,
63,
4504,
9,
272,
291,
14,
3070,
63,
11861,
8,
15266,
29,
1507,
63,
32547,
12,
19882,
63,
521,
29,
8595,
63,
521,
12,
536,
29,
354,
9,
819,
347,
12338,
63,
9953,
63,
890,
63,
991,
63,
2912,
8,
277,
304,
272,
367,
3522,
315,
359,
708,
12,
7633,
12,
18427,
2189,
489,
367,
3414,
63,
1267,
315,
359,
709,
12,
5198,
2189,
267,
367,
1967,
63,
4504,
315,
359,
1960,
12,
5198,
12,
499,
993,
2189,
881,
291,
14,
1065,
63,
5214,
63,
12236,
8,
1598,
1072,
63,
632,
628,
835,
401,
1598,
3522,
63,
890,
29,
2912,
12,
1598,
3414,
63,
1267,
29,
4041,
63,
1267,
12,
1598,
1390,
63,
4504,
29,
1507,
63,
4504,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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,
18644,
367,
1804,
30037,
22138,
63,
2991,
26471,
4045,
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,
646,
900,
199,
199,
504,
2853,
76,
492,
3285,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
492,
11708,
199,
504,
3228,
14,
1548,
14,
5819,
492,
373,
18,
63,
5819,
199,
504,
3228,
14,
1548,
14,
576,
14,
1483,
492,
4789,
63,
1483,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
8811,
14,
4359,
14,
21402,
492,
22138,
63,
2991,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2196,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
12338,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
199,
4831,
275,
3285,
14,
4831,
199,
199,
86,
18,
63,
5819,
14,
4296,
63,
86,
18,
63,
17537,
342,
421,
199,
533,
27067,
5003,
8,
11861,
14,
18644,
304,
523,
408,
18644,
314,
4045,
7568,
986,
1041,
819,
347,
1255,
63,
5214,
63,
12236,
8,
277,
12,
1072,
63,
632,
12,
3522,
63,
890,
12,
3414,
63,
1267,
12,
639,
1390,
63,
4504,
304,
272,
1324,
63,
84,
275,
11708,
14,
3205,
8,
1392,
2687,
4041,
63,
1267,
4706,
2152,
29,
5717,
14,
442,
708,
9,
272,
4045,
275,
22138,
63,
2991,
14,
23306,
7630,
8,
267,
1390,
63,
4504,
29,
988,
63,
4504,
12,
1072,
63,
632,
29,
1199,
63,
632,
9,
272,
485,
275,
4045,
8,
1210,
63,
84,
9,
339,
1967,
63,
32547,
275,
959,
272,
9174,
275,
942,
272,
11187,
275,
942,
272,
367,
485,
315,
1425,
8,
1507,
63,
32547,
304,
489,
6364,
275,
4789,
63,
1483,
14,
9271,
14,
504,
63,
3128,
63,
14865,
8,
881,
2196,
63,
1483,
14,
2355,
63,
8830,
779,
2912,
63,
890,
627,
1616,
12,
3414,
63,
1267,
467,
2511,
30135,
29,
16,
12,
2511,
23291,
29,
988,
63,
4504,
446,
413,
12,
2511,
2152,
29,
5717,
14,
442,
708,
430,
489,
6364,
275,
6364,
14,
11777,
8,
2912,
63,
890,
627,
2948,
9,
489,
6364,
275,
6364,
14,
2912,
8,
2912,
63,
890,
9,
489,
1967,
63,
14896,
275,
959,
489,
6364,
275,
6364,
14,
11066,
8,
1507,
63,
14896,
9,
489,
6364,
275,
6364,
14,
15576,
8,
1507,
63,
14896,
9,
489,
9174,
14,
740,
8,
521,
14,
521,
1012,
489,
327,
27067,
379,
1233,
22241,
2348,
14,
489,
367,
284,
315,
6364,
26,
267,
485,
275,
4045,
8,
73,
9,
489,
327,
27067,
379,
1233,
11187,
2348,
14,
489,
11187,
14,
740,
8,
521,
14,
521,
1012,
339,
12402,
63,
521,
275,
980,
14,
3670,
8,
1590,
14,
1144,
8,
3198,
9,
446,
980,
14,
1144,
8,
17116,
430,
1182,
1967,
63,
14896,
272,
536,
275,
298,
16810,
63,
2991,
92,
2912,
4970,
83,
92,
3610,
63,
1267,
4970,
83,
15287,
83,
63,
988,
63,
4504,
2,
450,
334,
267,
3522,
63,
890,
12,
3414,
63,
1267,
12,
1390,
63,
4504,
9,
272,
291,
14,
3070,
63,
11861,
8,
15266,
29,
1507,
63,
32547,
12,
19882,
63,
521,
29,
8595,
63,
521,
12,
536,
29,
354,
9,
819,
347,
12338,
63,
9953,
63,
890,
63,
991,
63,
2912,
8,
277,
304,
272,
367,
3522,
315,
359,
708,
12,
7633,
12,
18427,
2189,
489,
367,
3414,
63,
1267,
315,
359,
709,
12,
5198,
2189,
267,
367,
1967,
63,
4504,
315,
359,
1960,
12,
5198,
12,
499,
993,
2189,
881,
291,
14,
1065,
63,
5214,
63,
12236,
8,
1598,
1072,
63,
632,
628,
835,
401,
1598,
3522,
63,
890,
29,
2912,
12,
1598,
3414,
63,
1267,
29,
4041,
63,
1267,
12,
1598,
1390,
63,
4504,
29,
1507,
63,
4504,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
nattee/cafe-grader-web
|
lib/assets/Lib/pprint.py
|
9
|
13127
|
# Author: Fred L. Drake, Jr.
# fdrake@acm.org
#
# This is a simple little module I wrote to make life easier. I didn't
# see anything quite like it in the library, though I may have overlooked
# something. I wrote this when I was trying to read some heavily nested
# tuples with fairly non-descriptive content. This is modeled very much
# after Lisp/Scheme - style pretty-printing of lists. If you find it
# useful, thank small children who sleep at night.
"""Support to pretty-print lists, tuples, & dictionaries recursively.
Very simple, but useful, especially in debugging data structures.
Classes
-------
PrettyPrinter()
Handle pretty-printing operations onto a stream using a configured
set of formatting parameters.
Functions
---------
pformat()
Format a Python object into a pretty-printed representation.
pprint()
Pretty-print a Python object to a stream [default is sys.stdout].
saferepr()
Generate a 'standard' repr()-like value, but protect against recursive
data structures.
"""
import sys as _sys
from collections import OrderedDict as _OrderedDict
from io import StringIO as _StringIO
__all__ = ["pprint","pformat","isreadable","isrecursive","saferepr",
"PrettyPrinter"]
# cache these for faster access:
_commajoin = ", ".join
_id = id
_len = len
_type = type
def pprint(object, stream=None, indent=1, width=80, depth=None):
"""Pretty-print a Python object to a stream [default is sys.stdout]."""
printer = PrettyPrinter(
stream=stream, indent=indent, width=width, depth=depth)
printer.pprint(object)
def pformat(object, indent=1, width=80, depth=None):
"""Format a Python object into a pretty-printed representation."""
return PrettyPrinter(indent=indent, width=width, depth=depth).pformat(object)
def saferepr(object):
"""Version of repr() which can handle recursive data structures."""
return _safe_repr(object, {}, None, 0)[0]
def isreadable(object):
"""Determine if saferepr(object) is readable by eval()."""
return _safe_repr(object, {}, None, 0)[1]
def isrecursive(object):
"""Determine if object requires a recursive representation."""
return _safe_repr(object, {}, None, 0)[2]
class _safe_key:
"""Helper function for key functions when sorting unorderable objects.
The wrapped-object will fallback to an Py2.x style comparison for
unorderable types (sorting first comparing the type name and then by
the obj ids). Does not work recursively, so dict.items() must have
_safe_key applied to both the key and the value.
"""
__slots__ = ['obj']
def __init__(self, obj):
self.obj = obj
def __lt__(self, other):
try:
rv = self.obj.__lt__(other.obj)
except TypeError:
rv = NotImplemented
if rv is NotImplemented:
rv = (str(type(self.obj)), id(self.obj)) < \
(str(type(other.obj)), id(other.obj))
return rv
def _safe_tuple(t):
"Helper function for comparing 2-tuples"
return _safe_key(t[0]), _safe_key(t[1])
class PrettyPrinter:
def __init__(self, indent=1, width=80, depth=None, stream=None):
"""Handle pretty printing operations onto a stream using a set of
configured parameters.
indent
Number of spaces to indent for each level of nesting.
width
Attempted maximum number of columns in the output.
depth
The maximum depth to print out nested structures.
stream
The desired output stream. If omitted (or false), the standard
output stream available at construction will be used.
"""
indent = int(indent)
width = int(width)
assert indent >= 0, "indent must be >= 0"
assert depth is None or depth > 0, "depth must be > 0"
assert width, "width must be != 0"
self._depth = depth
self._indent_per_level = indent
self._width = width
if stream is not None:
self._stream = stream
else:
self._stream = _sys.stdout
def pprint(self, object):
self._format(object, self._stream, 0, 0, {}, 0)
self._stream.write("\n")
def pformat(self, object):
sio = _StringIO()
self._format(object, sio, 0, 0, {}, 0)
return sio.getvalue()
def isrecursive(self, object):
return self.format(object, {}, 0, 0)[2]
def isreadable(self, object):
s, readable, recursive = self.format(object, {}, 0, 0)
return readable and not recursive
def _format(self, object, stream, indent, allowance, context, level):
level = level + 1
import sys
sys.stderr.write(str(object))
objid = _id(object)
if objid in context:
stream.write(_recursion(object))
self._recursive = True
self._readable = False
return
rep = self._repr(object, context, level - 1)
typ = _type(object)
sepLines = _len(rep) > (self._width - 1 - indent - allowance)
write = stream.write
if self._depth and level > self._depth:
write(rep)
return
if sepLines:
r = getattr(typ, "__repr__", None)
if issubclass(typ, dict):
write('{')
if self._indent_per_level > 1:
write((self._indent_per_level - 1) * ' ')
length = _len(object)
if length:
context[objid] = 1
indent = indent + self._indent_per_level
if issubclass(typ, _OrderedDict):
items = list(object.items())
else:
items = sorted(object.items(), key=_safe_tuple)
key, ent = items[0]
rep = self._repr(key, context, level)
write(rep)
write(': ')
self._format(ent, stream, indent + _len(rep) + 2,
allowance + 1, context, level)
if length > 1:
for key, ent in items[1:]:
rep = self._repr(key, context, level)
write(',\n%s%s: ' % (' '*indent, rep))
self._format(ent, stream, indent + _len(rep) + 2,
allowance + 1, context, level)
indent = indent - self._indent_per_level
del context[objid]
write('}')
return
if ((issubclass(typ, list) and r is list.__repr__) or
(issubclass(typ, tuple) and r is tuple.__repr__) or
(issubclass(typ, set) and r is set.__repr__) or
(issubclass(typ, frozenset) and r is frozenset.__repr__)
):
length = _len(object)
if issubclass(typ, list):
write('[')
endchar = ']'
elif issubclass(typ, tuple):
write('(')
endchar = ')'
else:
if not length:
write(rep)
return
if typ is set:
write('{')
endchar = '}'
else:
write(typ.__name__)
write('({')
endchar = '})'
indent += len(typ.__name__) + 1
object = sorted(object, key=_safe_key)
if self._indent_per_level > 1:
write((self._indent_per_level - 1) * ' ')
if length:
context[objid] = 1
indent = indent + self._indent_per_level
self._format(object[0], stream, indent, allowance + 1,
context, level)
if length > 1:
for ent in object[1:]:
write(',\n' + ' '*indent)
self._format(ent, stream, indent,
allowance + 1, context, level)
indent = indent - self._indent_per_level
del context[objid]
if issubclass(typ, tuple) and length == 1:
write(',')
write(endchar)
return
write(rep)
def _repr(self, object, context, level):
repr, readable, recursive = self.format(object, context.copy(),
self._depth, level)
if not readable:
self._readable = False
if recursive:
self._recursive = True
return repr
def format(self, object, context, maxlevels, level):
"""Format object for a specific context, returning a string
and flags indicating whether the representation is 'readable'
and whether the object represents a recursive construct.
"""
return _safe_repr(object, context, maxlevels, level)
# Return triple (repr_string, isreadable, isrecursive).
def _safe_repr(object, context, maxlevels, level):
typ = _type(object)
if typ is str:
if 'locale' not in _sys.modules:
return repr(object), True, False
if "'" in object and '"' not in object:
closure = '"'
quotes = {'"': '\\"'}
else:
closure = "'"
quotes = {"'": "\\'"}
qget = quotes.get
sio = _StringIO()
write = sio.write
for char in object:
if char.isalpha():
write(char)
else:
write(qget(char, repr(char)[1:-1]))
return ("%s%s%s" % (closure, sio.getvalue(), closure)), True, False
r = getattr(typ, "__repr__", None)
if issubclass(typ, dict) and r is dict.__repr__:
if not object:
return "{}", True, False
objid = _id(object)
if maxlevels and level >= maxlevels:
return "{...}", False, objid in context
if objid in context:
return _recursion(object), False, True
context[objid] = 1
readable = True
recursive = False
components = []
append = components.append
level += 1
saferepr = _safe_repr
items = sorted(object.items(), key=_safe_tuple)
for k, v in items:
krepr, kreadable, krecur = saferepr(k, context, maxlevels, level)
vrepr, vreadable, vrecur = saferepr(v, context, maxlevels, level)
append("%s: %s" % (krepr, vrepr))
readable = readable and kreadable and vreadable
if krecur or vrecur:
recursive = True
del context[objid]
return "{%s}" % _commajoin(components), readable, recursive
if (issubclass(typ, list) and r is list.__repr__) or \
(issubclass(typ, tuple) and r is tuple.__repr__):
if issubclass(typ, list):
if not object:
return "[]", True, False
format = "[%s]"
elif _len(object) == 1:
format = "(%s,)"
else:
if not object:
return "()", True, False
format = "(%s)"
objid = _id(object)
if maxlevels and level >= maxlevels:
return format % "...", False, objid in context
if objid in context:
return _recursion(object), False, True
context[objid] = 1
readable = True
recursive = False
components = []
append = components.append
level += 1
for o in object:
orepr, oreadable, orecur = _safe_repr(o, context, maxlevels, level)
append(orepr)
if not oreadable:
readable = False
if orecur:
recursive = True
del context[objid]
return format % _commajoin(components), readable, recursive
rep = repr(object)
return rep, (rep and not rep.startswith('<')), False
def _recursion(object):
return ("<Recursion on %s with id=%s>"
% (_type(object).__name__, _id(object)))
def _perfcheck(object=None):
import time
if object is None:
object = [("string", (1, 2), [3, 4], {5: 6, 7: 8})] * 100000
p = PrettyPrinter()
t1 = time.time()
_safe_repr(object, {}, None, 0)
t2 = time.time()
p.pformat(object)
t3 = time.time()
print("_safe_repr:", t2 - t1)
print("pformat:", t3 - t2)
if __name__ == "__main__":
_perfcheck()
|
mit
|
[
3,
221,
6529,
26,
420,
481,
581,
491,
14,
577,
345,
415,
12,
1603,
82,
14,
202,
199,
3,
5185,
6111,
345,
415,
32,
645,
77,
14,
1308,
202,
199,
3,
202,
199,
3,
221,
961,
365,
282,
3486,
12050,
859,
473,
336,
22665,
370,
1852,
15451,
14905,
14,
221,
473,
9980,
1133,
202,
199,
3,
221,
1937,
7003,
18794,
2839,
652,
315,
314,
3555,
12,
10617,
473,
1443,
1172,
1806,
320,
7620,
202,
199,
3,
221,
6020,
14,
221,
473,
336,
22665,
642,
1380,
473,
1990,
9936,
370,
1586,
2005,
946,
1214,
3444,
6032,
202,
199,
3,
221,
6346,
543,
28092,
590,
2222,
13,
271,
729,
21701,
1564,
14,
221,
961,
365,
818,
1146,
7437,
8298,
202,
199,
3,
221,
2410,
491,
27474,
15,
19530,
446,
3449,
7268,
13,
26514,
402,
5548,
14,
221,
982,
1265,
2342,
652,
202,
199,
3,
221,
2997,
12,
2419,
75,
7425,
4978,
3963,
9435,
737,
302,
1070,
14,
2999,
199,
624,
11532,
370,
7268,
13,
1361,
5548,
12,
6346,
12,
1253,
11196,
15035,
14,
2999,
199,
54,
994,
3486,
12,
1325,
2997,
12,
24002,
315,
10201,
666,
13955,
14,
2999,
199,
15711,
202,
199,
12797,
2999,
199,
27153,
14131,
342,
1128,
8690,
7268,
13,
26514,
5331,
14602,
282,
2547,
1808,
282,
7526,
1128,
663,
402,
10803,
2633,
14,
2999,
199,
13967,
202,
199,
9960,
2999,
199,
24225,
342,
1128,
9701,
282,
2018,
909,
1901,
282,
7268,
13,
27131,
6025,
14,
2999,
199,
15380,
342,
1128,
31651,
13,
1361,
282,
2018,
909,
370,
282,
2547,
359,
885,
365,
984,
14,
2703,
1055,
2999,
199,
3489,
2722,
342,
1128,
7958,
282,
283,
6807,
7,
4700,
22251,
2930,
574,
12,
1325,
25863,
6169,
9133,
1128,
666,
13955,
14,
2999,
199,
624,
2999,
199,
646,
984,
465,
485,
1274,
202,
199,
504,
5055,
492,
8773,
465,
485,
16882,
202,
199,
504,
5890,
492,
5228,
465,
485,
6424,
2999,
199,
363,
452,
363,
275,
2097,
15380,
2266,
24225,
2266,
374,
11875,
2266,
374,
9931,
2266,
3489,
2722,
401,
18691,
298,
27153,
14131,
937,
2999,
199,
3,
2581,
3520,
367,
12930,
2879,
26,
202,
199,
63,
13184,
904,
275,
3872,
3680,
904,
202,
199,
63,
344,
275,
1305,
202,
199,
63,
552,
275,
822,
202,
199,
63,
466,
275,
730,
8065,
199,
318,
10933,
8,
785,
12,
2547,
29,
403,
12,
4363,
29,
17,
12,
3462,
29,
1257,
12,
5818,
29,
403,
304,
1128,
408,
27153,
13,
1361,
282,
2018,
909,
370,
282,
2547,
359,
885,
365,
984,
14,
2703,
61,
1041,
1128,
16639,
275,
31651,
14131,
8,
1039,
2547,
29,
1745,
12,
4363,
29,
3724,
12,
3462,
29,
2063,
12,
5818,
29,
4631,
9,
1128,
16639,
14,
15380,
8,
785,
9,
2999,
199,
318,
30843,
8,
785,
12,
4363,
29,
17,
12,
3462,
29,
1257,
12,
5818,
29,
403,
304,
1128,
408,
3484,
282,
2018,
909,
1901,
282,
7268,
13,
27131,
6025,
1041,
1128,
372,
31651,
14131,
8,
3724,
29,
3724,
12,
3462,
29,
2063,
12,
5818,
29,
4631,
680,
24225,
8,
785,
9,
2999,
199,
318,
5048,
2722,
8,
785,
304,
1128,
408,
3353,
402,
4700,
342,
1314,
883,
2429,
9133,
666,
13955,
1041,
1128,
372,
485,
3489,
63,
2722,
8,
785,
12,
5479,
488,
12,
378,
2788,
16,
61,
2999,
199,
318,
365,
11875,
8,
785,
304,
1128,
408,
21767,
340,
5048,
2722,
8,
785,
9,
365,
12701,
701,
3468,
20693,
1128,
372,
485,
3489,
63,
2722,
8,
785,
12,
5479,
488,
12,
378,
2788,
17,
61,
2999,
199,
318,
365,
9931,
8,
785,
304,
1128,
408,
21767,
340,
909,
5074,
282,
9133,
6025,
1041,
1128,
372,
485,
3489,
63,
2722,
8,
785,
12,
5479,
488,
12,
378,
2788,
18,
61,
2999,
199,
533,
485,
3489,
63,
498,
26,
1128,
408,
4433,
805,
367,
790,
3423,
1380,
13351,
625,
27788,
6842,
2251,
14,
2958,
710,
8072,
13,
785,
911,
9567,
370,
376,
1611,
18,
14,
88,
3449,
9132,
367,
1128,
625,
27788,
6842,
2943,
334,
29411,
1642,
20234,
314,
730,
536,
436,
2066,
701,
1128,
314,
1559,
2762,
680,
221,
12078,
440,
1736,
15035,
12,
880,
1211,
14,
1744,
342,
1471,
1172,
1128,
485,
3489,
63,
498,
6781,
370,
3865,
314,
790,
436,
314,
574,
14,
2958,
408,
2958,
636,
7257,
363,
275,
788,
1113,
418,
2958,
347,
636,
826,
721,
277,
12,
1559,
304,
1039,
291,
14,
1113,
275,
1559,
2958,
347,
636,
4116,
721,
277,
12,
1163,
304,
1039,
862,
26,
1675,
4336,
275,
291,
14,
1113,
855,
4116,
721,
1848,
14,
1113,
9,
1039,
871,
3146,
26,
1675,
4336,
275,
3784,
4341,
340,
4336,
365,
3784,
26,
1675,
4336,
275,
334,
495,
8,
466,
8,
277,
14,
1113,
1826,
1305,
8,
277,
14,
1113,
430,
665,
971,
20085,
334,
495,
8,
466,
8,
1848,
14,
1113,
1826,
1305,
8,
1848,
14,
1113,
430,
1039,
372,
4336,
2999,
199,
318,
485,
3489,
63,
2960,
8,
84,
304,
1128,
298,
4433,
805,
367,
20234,
499,
13,
11760,
2,
1128,
372,
485,
3489,
63,
498,
8,
84,
59,
16,
2522,
485,
3489,
63,
498,
8,
84,
59,
17,
566,
2999,
199,
533,
31651,
14131,
26,
1128,
347,
636,
826,
721,
277,
12,
4363,
29,
17,
12,
3462,
29,
1257,
12,
5818,
29,
403,
12,
2547,
29,
403,
304,
1039,
408,
5940,
7268,
16116,
5331,
14602,
282,
2547,
1808,
282,
663,
402,
1039,
7526,
2633,
14,
4341,
4363,
1675,
4860,
402,
7883,
370,
4363,
367,
1924,
2166,
402,
19500,
14,
4341,
3462,
1675,
17413,
471,
5696,
1329,
402,
4362,
315,
314,
1072,
14,
4341,
5818,
1675,
710,
5696,
5818,
370,
870,
734,
6032,
13955,
14,
4341,
2547,
1675,
710,
6387,
1072,
2547,
14,
221,
982,
11684,
334,
269,
3055,
395,
314,
4465,
1675,
1072,
2547,
2808,
737,
14538,
911,
506,
1202,
14,
4341,
408,
1039,
4363,
275,
1109,
8,
3724,
9,
1039,
3462,
275,
1109,
8,
2063,
9,
1039,
702,
4363,
2356,
378,
12,
298,
3724,
1471,
506,
2356,
378,
2,
1039,
702,
5818,
365,
488,
503,
5818,
690,
378,
12,
298,
4631,
1471,
506,
690,
378,
2,
1039,
702,
3462,
12,
298,
2063,
1471,
506,
1137,
378,
2,
1039,
291,
423,
4631,
275,
5818,
1039,
291,
423,
3724,
63,
529,
63,
1896,
275,
4363,
1039,
291,
423,
2063,
275,
3462
] |
[
221,
6529,
26,
420,
481,
581,
491,
14,
577,
345,
415,
12,
1603,
82,
14,
202,
199,
3,
5185,
6111,
345,
415,
32,
645,
77,
14,
1308,
202,
199,
3,
202,
199,
3,
221,
961,
365,
282,
3486,
12050,
859,
473,
336,
22665,
370,
1852,
15451,
14905,
14,
221,
473,
9980,
1133,
202,
199,
3,
221,
1937,
7003,
18794,
2839,
652,
315,
314,
3555,
12,
10617,
473,
1443,
1172,
1806,
320,
7620,
202,
199,
3,
221,
6020,
14,
221,
473,
336,
22665,
642,
1380,
473,
1990,
9936,
370,
1586,
2005,
946,
1214,
3444,
6032,
202,
199,
3,
221,
6346,
543,
28092,
590,
2222,
13,
271,
729,
21701,
1564,
14,
221,
961,
365,
818,
1146,
7437,
8298,
202,
199,
3,
221,
2410,
491,
27474,
15,
19530,
446,
3449,
7268,
13,
26514,
402,
5548,
14,
221,
982,
1265,
2342,
652,
202,
199,
3,
221,
2997,
12,
2419,
75,
7425,
4978,
3963,
9435,
737,
302,
1070,
14,
2999,
199,
624,
11532,
370,
7268,
13,
1361,
5548,
12,
6346,
12,
1253,
11196,
15035,
14,
2999,
199,
54,
994,
3486,
12,
1325,
2997,
12,
24002,
315,
10201,
666,
13955,
14,
2999,
199,
15711,
202,
199,
12797,
2999,
199,
27153,
14131,
342,
1128,
8690,
7268,
13,
26514,
5331,
14602,
282,
2547,
1808,
282,
7526,
1128,
663,
402,
10803,
2633,
14,
2999,
199,
13967,
202,
199,
9960,
2999,
199,
24225,
342,
1128,
9701,
282,
2018,
909,
1901,
282,
7268,
13,
27131,
6025,
14,
2999,
199,
15380,
342,
1128,
31651,
13,
1361,
282,
2018,
909,
370,
282,
2547,
359,
885,
365,
984,
14,
2703,
1055,
2999,
199,
3489,
2722,
342,
1128,
7958,
282,
283,
6807,
7,
4700,
22251,
2930,
574,
12,
1325,
25863,
6169,
9133,
1128,
666,
13955,
14,
2999,
199,
624,
2999,
199,
646,
984,
465,
485,
1274,
202,
199,
504,
5055,
492,
8773,
465,
485,
16882,
202,
199,
504,
5890,
492,
5228,
465,
485,
6424,
2999,
199,
363,
452,
363,
275,
2097,
15380,
2266,
24225,
2266,
374,
11875,
2266,
374,
9931,
2266,
3489,
2722,
401,
18691,
298,
27153,
14131,
937,
2999,
199,
3,
2581,
3520,
367,
12930,
2879,
26,
202,
199,
63,
13184,
904,
275,
3872,
3680,
904,
202,
199,
63,
344,
275,
1305,
202,
199,
63,
552,
275,
822,
202,
199,
63,
466,
275,
730,
8065,
199,
318,
10933,
8,
785,
12,
2547,
29,
403,
12,
4363,
29,
17,
12,
3462,
29,
1257,
12,
5818,
29,
403,
304,
1128,
408,
27153,
13,
1361,
282,
2018,
909,
370,
282,
2547,
359,
885,
365,
984,
14,
2703,
61,
1041,
1128,
16639,
275,
31651,
14131,
8,
1039,
2547,
29,
1745,
12,
4363,
29,
3724,
12,
3462,
29,
2063,
12,
5818,
29,
4631,
9,
1128,
16639,
14,
15380,
8,
785,
9,
2999,
199,
318,
30843,
8,
785,
12,
4363,
29,
17,
12,
3462,
29,
1257,
12,
5818,
29,
403,
304,
1128,
408,
3484,
282,
2018,
909,
1901,
282,
7268,
13,
27131,
6025,
1041,
1128,
372,
31651,
14131,
8,
3724,
29,
3724,
12,
3462,
29,
2063,
12,
5818,
29,
4631,
680,
24225,
8,
785,
9,
2999,
199,
318,
5048,
2722,
8,
785,
304,
1128,
408,
3353,
402,
4700,
342,
1314,
883,
2429,
9133,
666,
13955,
1041,
1128,
372,
485,
3489,
63,
2722,
8,
785,
12,
5479,
488,
12,
378,
2788,
16,
61,
2999,
199,
318,
365,
11875,
8,
785,
304,
1128,
408,
21767,
340,
5048,
2722,
8,
785,
9,
365,
12701,
701,
3468,
20693,
1128,
372,
485,
3489,
63,
2722,
8,
785,
12,
5479,
488,
12,
378,
2788,
17,
61,
2999,
199,
318,
365,
9931,
8,
785,
304,
1128,
408,
21767,
340,
909,
5074,
282,
9133,
6025,
1041,
1128,
372,
485,
3489,
63,
2722,
8,
785,
12,
5479,
488,
12,
378,
2788,
18,
61,
2999,
199,
533,
485,
3489,
63,
498,
26,
1128,
408,
4433,
805,
367,
790,
3423,
1380,
13351,
625,
27788,
6842,
2251,
14,
2958,
710,
8072,
13,
785,
911,
9567,
370,
376,
1611,
18,
14,
88,
3449,
9132,
367,
1128,
625,
27788,
6842,
2943,
334,
29411,
1642,
20234,
314,
730,
536,
436,
2066,
701,
1128,
314,
1559,
2762,
680,
221,
12078,
440,
1736,
15035,
12,
880,
1211,
14,
1744,
342,
1471,
1172,
1128,
485,
3489,
63,
498,
6781,
370,
3865,
314,
790,
436,
314,
574,
14,
2958,
408,
2958,
636,
7257,
363,
275,
788,
1113,
418,
2958,
347,
636,
826,
721,
277,
12,
1559,
304,
1039,
291,
14,
1113,
275,
1559,
2958,
347,
636,
4116,
721,
277,
12,
1163,
304,
1039,
862,
26,
1675,
4336,
275,
291,
14,
1113,
855,
4116,
721,
1848,
14,
1113,
9,
1039,
871,
3146,
26,
1675,
4336,
275,
3784,
4341,
340,
4336,
365,
3784,
26,
1675,
4336,
275,
334,
495,
8,
466,
8,
277,
14,
1113,
1826,
1305,
8,
277,
14,
1113,
430,
665,
971,
20085,
334,
495,
8,
466,
8,
1848,
14,
1113,
1826,
1305,
8,
1848,
14,
1113,
430,
1039,
372,
4336,
2999,
199,
318,
485,
3489,
63,
2960,
8,
84,
304,
1128,
298,
4433,
805,
367,
20234,
499,
13,
11760,
2,
1128,
372,
485,
3489,
63,
498,
8,
84,
59,
16,
2522,
485,
3489,
63,
498,
8,
84,
59,
17,
566,
2999,
199,
533,
31651,
14131,
26,
1128,
347,
636,
826,
721,
277,
12,
4363,
29,
17,
12,
3462,
29,
1257,
12,
5818,
29,
403,
12,
2547,
29,
403,
304,
1039,
408,
5940,
7268,
16116,
5331,
14602,
282,
2547,
1808,
282,
663,
402,
1039,
7526,
2633,
14,
4341,
4363,
1675,
4860,
402,
7883,
370,
4363,
367,
1924,
2166,
402,
19500,
14,
4341,
3462,
1675,
17413,
471,
5696,
1329,
402,
4362,
315,
314,
1072,
14,
4341,
5818,
1675,
710,
5696,
5818,
370,
870,
734,
6032,
13955,
14,
4341,
2547,
1675,
710,
6387,
1072,
2547,
14,
221,
982,
11684,
334,
269,
3055,
395,
314,
4465,
1675,
1072,
2547,
2808,
737,
14538,
911,
506,
1202,
14,
4341,
408,
1039,
4363,
275,
1109,
8,
3724,
9,
1039,
3462,
275,
1109,
8,
2063,
9,
1039,
702,
4363,
2356,
378,
12,
298,
3724,
1471,
506,
2356,
378,
2,
1039,
702,
5818,
365,
488,
503,
5818,
690,
378,
12,
298,
4631,
1471,
506,
690,
378,
2,
1039,
702,
3462,
12,
298,
2063,
1471,
506,
1137,
378,
2,
1039,
291,
423,
4631,
275,
5818,
1039,
291,
423,
3724,
63,
529,
63,
1896,
275,
4363,
1039,
291,
423,
2063,
275,
3462,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mommermi/callhorizons
|
callhorizons/callhorizons.py
|
1
|
60381
|
"""CALLHORIZONS - a Python interface to access JPL HORIZONS
ephemerides and orbital elements.
This module provides a convenient python interface to the JPL
HORIZONS system by directly accessing and parsing the HORIZONS
website. Ephemerides can be obtained through get_ephemerides,
orbital elements through get_elements. Function
export2pyephem provides an interface to the PyEphem module.
michael.mommert (at) nau.edu, latest version: v1.0.5, 2017-05-05.
This code is inspired by code created by Alex Hagen.
* v1.
* v1.0.5: 15-epoch limit for set_discreteepochs removed
* v1.0.4: improved asteroid and comet name parsing
* v1.0.3: ObsEclLon and ObsEclLat added to get_ephemerides
* v1.0.2: Python 3.5 compatibility implemented
* v1.0.1: get_ephemerides fixed
* v1.0: bugfixes completed, planets/satellites accessible, too
* v0.9: first release
"""
from __future__ import (print_function, unicode_literals)
import re
import sys
import time
import numpy as np
import warnings
try:
# Python 3
import urllib.request as urllib
except ImportError:
# Python 2
import urllib2 as urllib
warnings.filterwarnings('once', category=DeprecationWarning)
warnings.warn(('CALLHORIZONS is not maintained anymore; please use '
'astroquery.jplhorizons instead (https://github.com/'
'astropy/astroquery)'),
DeprecationWarning)
def _char2int(char):
""" translate characters to integer values (upper and lower case)"""
if char.isdigit():
return int(float(char))
if char.isupper():
return int(char, 36)
else:
return 26 + int(char, 36)
class query():
# constructor
def __init__(self, targetname, smallbody=True, cap=True, nofrag=False,
comet=False, asteroid=False):
"""Initialize query to Horizons
:param targetname: HORIZONS-readable target number, name, or designation
:param smallbody: boolean use ``smallbody=False`` if targetname is a
planet or spacecraft (optional, default: `True`);
also use `True` if the targetname is exact and
should be queried as is
:param cap: set to `True` to return the current apparition for
comet targets
:param nofrag: set to `True` to disable HORIZONS's comet
fragment search
:param comet: set to `True` if this is a comet (will override
automatic targetname parsing)
:param asteroid: set to `True` if this is an asteroid (will override
automatic targetname parsing)
:return: None
"""
self.targetname = str(targetname)
self.not_smallbody = not smallbody
self.cap = cap
self.nofrag = nofrag
self.comet = comet # is this object a comet?
self.asteroid = asteroid # is this object an asteroid?
self.start_epoch = None
self.stop_epoch = None
self.step_size = None
self.discreteepochs = None
self.url = None
self.data = None
assert not (
self.comet and self.asteroid), 'Only one of comet or asteroid can be `True`.'
return None
# small body designation parsing
def parse_comet(self):
"""Parse `targetname` as if it were a comet.
:return: (string or None, int or None, string or None);
The designation, number and prefix, and name of the comet as derived
from `self.targetname` are extracted into a tuple; each element that
does not exist is set to `None`. Parenthesis in `self.targetname`
will be ignored.
:example: the following table shows the result of the parsing:
+--------------------------------+--------------------------------+
|targetname |(desig, prefixnumber, name) |
+================================+================================+
|1P/Halley |(None, '1P', 'Halley') |
+--------------------------------+--------------------------------+
|3D/Biela |(None, '3D', 'Biela') |
+--------------------------------+--------------------------------+
|9P/Tempel 1 |(None, '9P', 'Tempel 1') |
+--------------------------------+--------------------------------+
|73P/Schwassmann Wachmann 3 C |(None, '73P', |
| |'Schwassmann Wachmann 3 C') |
+--------------------------------+--------------------------------+
|73P-C/Schwassmann Wachmann 3 C |(None, '73P-C', |
| |'Schwassmann Wachmann 3 C') |
+--------------------------------+--------------------------------+
|73P-BB |(None, '73P-BB', None) |
+--------------------------------+--------------------------------+
|322P |(None, '322P', None) |
+--------------------------------+--------------------------------+
|X/1106 C1 |('1166 C1', 'X', None) |
+--------------------------------+--------------------------------+
|P/1994 N2 (McNaught-Hartley) |('1994 N2', 'P', |
| |'McNaught-Hartley') |
+--------------------------------+--------------------------------+
|P/2001 YX127 (LINEAR) |('2001 YX127', 'P', 'LINEAR') |
+--------------------------------+--------------------------------+
|C/-146 P1 |('-146 P1', 'C', None) |
+--------------------------------+--------------------------------+
|C/2001 A2-A (LINEAR) |('2001 A2-A', 'C', 'LINEAR') |
+--------------------------------+--------------------------------+
|C/2013 US10 |('2013 US10', 'C', None) |
+--------------------------------+--------------------------------+
|C/2015 V2 (Johnson) |('2015 V2', 'C', 'Johnson') |
+--------------------------------+--------------------------------+
|C/2016 KA (Catalina) |('2016 KA', 'C', 'Catalina') |
+--------------------------------+--------------------------------+
"""
import re
pat = ('^(([1-9]+[PDCXAI](-[A-Z]{1,2})?)|[PDCXAI]/)' + # prefix [0,1,2]
'|([-]?[0-9]{3,4}[ _][A-Z]{1,2}([0-9]{1,3})?(-[1-9A-Z]{0,2})?)' +
# designation [3,4]
('|(([A-Z][a-z]?[A-Z]*[a-z]*[ -]?[A-Z]?[1-9]*[a-z]*)' +
'( [1-9A-Z]{1,2})*)') # name [5,6]
)
m = re.findall(pat, self.targetname.strip())
# print(m)
prefixnumber = None
desig = None
name = None
if len(m) > 0:
for el in m:
# prefix/number
if len(el[0]) > 0:
prefixnumber = el[0].replace('/', '')
# designation
if len(el[3]) > 0:
desig = el[3].replace('_', ' ')
# name
if len(el[5]) > 0:
if len(el[5]) > 1:
name = el[5]
return (desig, prefixnumber, name)
def parse_asteroid(self):
"""Parse `targetname` as if it were a asteroid.
:return: (string or None, int or None, string or None);
The designation, number, and name of the asteroid as derived from
`self.targetname` are extracted into a tuple; each element that
does not exist is set to `None`. Parenthesis in `self.targetname`
will be ignored. Packed designations and numbers are unpacked.
:example: the following table shows the result of the parsing:
+--------------------------------+---------------------------------+
|targetname |(desig, number, name) |
+================================+=================================+
|1 |(None, 1, None) |
+--------------------------------+---------------------------------+
|2 Pallas |(None, 2, Pallas) |
+--------------------------------+---------------------------------+
|\(2001\) Einstein |(None, 2001, Einstein) |
+--------------------------------+---------------------------------+
|1714 Sy |(None, 1714, Sy) |
+--------------------------------+---------------------------------+
|2014 MU69 |(2014 MU69, None, None) |
+--------------------------------+---------------------------------+
|(228195) 6675 P-L |(6675 P-L, 228195, None) |
+--------------------------------+---------------------------------+
|4101 T-3 |(4101 T-3, None, None) |
+--------------------------------+---------------------------------+
|4015 Wilson-Harrington (1979 VA)|(1979 VA, 4015, Wilson-Harrington|
+--------------------------------+---------------------------------+
|J95X00A |(1995 XA, None, None) |
+--------------------------------+---------------------------------+
|K07Tf8A |(2007 TA418, None, None) |
+--------------------------------+---------------------------------+
|G3693 |(None, 163693, None) |
+--------------------------------+---------------------------------+
|2017 U1 |(None, None, None) |
+--------------------------------+---------------------------------+
"""
pat = ('(([1-2][0-9]{0,3}[ _][A-Z]{2}[0-9]{0,3})' # designation [0,1]
'|([1-9][0-9]{3}[ _](P-L|T-[1-3])))' # Palomar-Leiden [0,2,3]
'|([IJKL][0-9]{2}[A-Z][0-9a-z][0-9][A-Z])' # packed desig [4]
'|([A-Za-z][0-9]{4})' # packed number [5]
'|([A-Z][A-Z]*[a-z][a-z]*[^0-9]*'
'[ -]?[A-Z]?[a-z]*[^0-9]*)' # name [6]
'|([1-9][0-9]*(\b|$))') # number [7,8]
# regex patterns that will be ignored as they might cause
# confusion
non_pat = ('([1-2][0-9]{0,3}[ _][A-Z][0-9]*(\b|$))') # comet desig
if sys.version_info > (3, 0):
raw = self.targetname.translate(str.maketrans('()', ' ')).strip()
else:
import string
raw = self.targetname.translate(string.maketrans('()',
' ')).strip()
# reject non_pat patterns
non_m = re.findall(non_pat, raw)
# print('reject', raw, non_m)
if len(non_m) > 0:
for ps in non_m:
for p in ps:
if p == '':
continue
raw = raw[:raw.find(p)] + raw[raw.find(p)+len(p):]
# match target patterns
m = re.findall(pat, raw)
# print(raw, m)
desig = None
number = None
name = None
if len(m) > 0:
for el in m:
# designation
if len(el[0]) > 0:
desig = el[0]
# packed designation (unpack here)
elif len(el[4]) > 0:
ident = el[4]
# old designation style, e.g.: 1989AB
if (len(ident.strip()) < 7 and ident[:4].isdigit() and
ident[4:6].isalpha()):
desig = ident[:4]+' '+ident[4:6]
# Palomar Survey
elif ident.find("PLS") == 0:
desig = ident[3:] + " P-L"
# Trojan Surveys
elif ident.find("T1S") == 0:
desig = ident[3:] + " T-1"
elif ident.find("T2S") == 0:
desig = ident[3:] + " T-2"
elif ident.find("T3S") == 0:
desig = ident[3:] + " T-3"
# insert blank in designations
elif (ident[0:4].isdigit() and ident[4:6].isalpha() and
ident[4] != ' '):
desig = ident[:4]+" "+ident[4:]
# MPC packed 7-digit designation
elif (ident[0].isalpha() and ident[1:3].isdigit() and
ident[-1].isalpha() and ident[-2].isdigit()):
yr = str(_char2int(ident[0]))+ident[1:3]
let = ident[3]+ident[-1]
num = str(_char2int(ident[4]))+ident[5]
num = num.lstrip("0")
desig = yr+' '+let+num
# nothing to do
else:
desig = ident
# packed number (unpack here)
elif len(el[5]) > 0:
ident = el[5]
number = ident = int(str(_char2int(ident[0]))+ident[1:])
# number
elif len(el[7]) > 0:
if sys.version_info > (3, 0):
number = int(float(el[7].translate(str.maketrans('()',
' '))))
else:
import string
number = int(float(el[7].translate(string.maketrans('()',
' '))))
# name (strip here)
elif len(el[6]) > 0:
if len(el[6].strip()) > 1:
name = el[6].strip()
return (desig, number, name)
def isorbit_record(self):
"""`True` if `targetname` appears to be a comet orbit record number.
NAIF record numbers are 6 digits, begin with a '9' and can
change at any time.
"""
import re
test = re.match('^9[0-9]{5}$', self.targetname.strip()) is not None
return test
def iscomet(self):
"""`True` if `targetname` appears to be a comet. """
# treat this object as comet if there is a prefix/number
if self.comet is not None:
return self.comet
elif self.asteroid is not None:
return not self.asteroid
else:
return (self.parse_comet()[0] is not None or
self.parse_comet()[1] is not None)
def isasteroid(self):
"""`True` if `targetname` appears to be an asteroid."""
if self.asteroid is not None:
return self.asteroid
elif self.comet is not None:
return not self.comet
else:
return any(self.parse_asteroid()) is not None
# set epochs
def set_epochrange(self, start_epoch, stop_epoch, step_size):
"""Set a range of epochs, all times are UT
:param start_epoch: str;
start epoch of the format 'YYYY-MM-DD [HH-MM-SS]'
:param stop_epoch: str;
final epoch of the format 'YYYY-MM-DD [HH-MM-SS]'
:param step_size: str;
epoch step size, e.g., '1d' for 1 day, '10m' for 10 minutes...
:return: None
:example: >>> import callhorizons
>>> ceres = callhorizons.query('Ceres')
>>> ceres.set_epochrange('2016-02-26', '2016-10-25', '1d')
Note that dates are mandatory; if no time is given, midnight is assumed.
"""
self.start_epoch = start_epoch
self.stop_epoch = stop_epoch
self.step_size = step_size
return None
def set_discreteepochs(self, discreteepochs):
"""Set a list of discrete epochs, epochs have to be given as Julian
Dates
:param discreteepochs: array_like
list or 1D array of floats or strings
:return: None
:example: >>> import callhorizons
>>> ceres = callhorizons.query('Ceres')
>>> ceres.set_discreteepochs([2457446.177083, 2457446.182343])
"""
if not isinstance(discreteepochs, (list, np.ndarray)):
discreteepochs = [discreteepochs]
self.discreteepochs = list(discreteepochs)
# data access functions
@property
def fields(self):
"""returns list of available properties for all epochs"""
try:
return self.data.dtype.names
except AttributeError:
return []
def __len__(self):
"""returns total number of epochs that have been queried"""
try:
# Cast to int because a long is returned from shape on Windows.
return int(self.data.shape[0])
except AttributeError:
return 0
@property
def dates(self):
"""returns list of epochs that have been queried (format 'YYYY-MM-DD HH-MM-SS')"""
try:
return self.data['datetime']
except:
return []
@property
def query(self):
"""returns URL that has been used in calling HORIZONS"""
try:
return self.url
except:
return []
@property
def dates_jd(self):
"""returns list of epochs that have been queried (Julian Dates)"""
try:
return self.data['datetime_jd']
except:
return []
def __repr__(self):
"""returns brief query information"""
return "<callhorizons.query object: %s>" % self.targetname
def __str__(self):
"""returns information on the current query as string"""
output = "targetname: %s\n" % self.targetname
if self.discreteepochs is not None:
output += "discrete epochs: %s\n" % \
" ".join([str(epoch) for epoch in self.discreteepochs])
if (self.start_epoch is not None and self.stop_epoch is not None and
self.step_size is not None):
output += "epoch range from %s to %s in steps of %s\n" % \
(self.start_epoch, self.stop_epoch, self.step_size)
output += "%d data sets queried with %d different fields" % \
(len(self), len(self.fields))
return output
def __getitem__(self, key):
"""provides access to query data
:param key: str/int;
epoch index or property key
:return: query data according to key
"""
# check if data exist
if self.data is None or len(self.data) == 0:
print('CALLHORIZONS ERROR: run get_ephemerides or get_elements',
'first')
return None
return self.data[key]
# call functions
def get_ephemerides(self, observatory_code,
airmass_lessthan=99,
solar_elongation=(0, 180),
skip_daylight=False):
"""Call JPL HORIZONS website to obtain ephemerides based on the
provided targetname, epochs, and observatory_code. For a list
of valid observatory codes, refer to
http://minorplanetcenter.net/iau/lists/ObsCodesF.html
:param observatory_code: str/int;
observer's location code according to Minor Planet Center
:param airmass_lessthan: float;
maximum airmass (optional, default: 99)
:param solar_elongation: tuple;
permissible solar elongation range (optional, deg)
:param skip_daylight: boolean;
crop daylight epoch during query (optional)
:result: int; number of epochs queried
:example: >>> ceres = callhorizons.query('Ceres')
>>> ceres.set_epochrange('2016-02-23 00:00', '2016-02-24 00:00', '1h')
>>> print (ceres.get_ephemerides(568), 'epochs queried')
The queried properties and their definitions are:
+------------------+-----------------------------------------------+
| Property | Definition |
+==================+===============================================+
| targetname | official number, name, designation [string] |
+------------------+-----------------------------------------------+
| H | absolute magnitude in V band (float, mag) |
+------------------+-----------------------------------------------+
| G | photometric slope parameter (float) |
+------------------+-----------------------------------------------+
| datetime | epoch date and time (str, YYYY-MM-DD HH:MM:SS)|
+------------------+-----------------------------------------------+
| datetime_jd | epoch Julian Date (float) |
+------------------+-----------------------------------------------+
| solar_presence | information on Sun's presence (str) |
+------------------+-----------------------------------------------+
| lunar_presence | information on Moon's presence (str) |
+------------------+-----------------------------------------------+
| RA | target RA (float, J2000.0) |
+------------------+-----------------------------------------------+
| DEC | target DEC (float, J2000.0) |
+------------------+-----------------------------------------------+
| RA_rate | target rate RA (float, arcsec/s) |
+------------------+-----------------------------------------------+
| DEC_rate | target RA (float, arcsec/s, includes cos(DEC))|
+------------------+-----------------------------------------------+
| AZ | Azimuth meas East(90) of North(0) (float, deg)|
+------------------+-----------------------------------------------+
| EL | Elevation (float, deg) |
+------------------+-----------------------------------------------+
| airmass | target optical airmass (float) |
+------------------+-----------------------------------------------+
| magextinct | V-mag extinction due airmass (float, mag) |
+------------------+-----------------------------------------------+
| V | V magnitude (comets: total mag) (float, mag) |
+------------------+-----------------------------------------------+
| illumination | fraction of illuminated disk (float) |
+------------------+-----------------------------------------------+
| EclLon | heliocentr. ecl. long. (float, deg, J2000.0) |
+------------------+-----------------------------------------------+
| EclLat | heliocentr. ecl. lat. (float, deg, J2000.0) |
+------------------+-----------------------------------------------+
| ObsEclLon | obscentr. ecl. long. (float, deg, J2000.0) |
+------------------+-----------------------------------------------+
| ObsEclLat | obscentr. ecl. lat. (float, deg, J2000.0) |
+------------------+-----------------------------------------------+
| r | heliocentric distance (float, au) |
+------------------+-----------------------------------------------+
| r_rate | heliocentric radial rate (float, km/s) |
+------------------+-----------------------------------------------+
| delta | distance from the observer (float, au) |
+------------------+-----------------------------------------------+
| delta_rate | obs-centric radial rate (float, km/s) |
+------------------+-----------------------------------------------+
| lighttime | one-way light time (float, s) |
+------------------+-----------------------------------------------+
| elong | solar elongation (float, deg) |
+------------------+-----------------------------------------------+
| elongFlag | app. position relative to Sun (str) |
+------------------+-----------------------------------------------+
| alpha | solar phase angle (float, deg) |
+------------------+-----------------------------------------------+
| sunTargetPA | PA of Sun->target vector (float, deg, EoN) |
+------------------+-----------------------------------------------+
| velocityPA | PA of velocity vector (float, deg, EoN) |
+------------------+-----------------------------------------------+
| GlxLon | galactic longitude (float, deg) |
+------------------+-----------------------------------------------+
| GlxLat | galactic latitude (float, deg) |
+------------------+-----------------------------------------------+
| RA_3sigma | 3sigma pos. unc. in RA (float, arcsec) |
+------------------+-----------------------------------------------+
| DEC_3sigma | 3sigma pos. unc. in DEC (float, arcsec) |
+------------------+-----------------------------------------------+
"""
# queried fields (see HORIZONS website for details)
# if fields are added here, also update the field identification below
quantities = '1,3,4,8,9,10,18,19,20,21,23,24,27,31,33,36'
# encode objectname for use in URL
objectname = urllib.quote(self.targetname.encode("utf8"))
# construct URL for HORIZONS query
url = "https://ssd.jpl.nasa.gov/horizons_batch.cgi?batch=l" \
+ "&TABLE_TYPE='OBSERVER'" \
+ "&QUANTITIES='" + str(quantities) + "'" \
+ "&CSV_FORMAT='YES'" \
+ "&ANG_FORMAT='DEG'" \
+ "&CAL_FORMAT='BOTH'" \
+ "&SOLAR_ELONG='" + str(solar_elongation[0]) + "," \
+ str(solar_elongation[1]) + "'" \
+ "&CENTER='"+str(observatory_code)+"'"
if self.not_smallbody:
url += "&COMMAND='" + \
urllib.quote(self.targetname.encode("utf8")) + "'"
elif self.cap and self.comet:
for ident in self.parse_comet():
if ident is not None:
break
if ident is None:
ident = self.targetname
url += "&COMMAND='DES=" + \
urllib.quote(ident.encode("utf8")) + "%3B" + \
("CAP'" if self.cap else "'")
elif self.isorbit_record():
# Comet orbit record. Do not use DES, CAP. This test must
# occur before asteroid test.
url += "&COMMAND='" + \
urllib.quote(self.targetname.encode("utf8")) + "%3B'"
elif self.isasteroid() and not self.comet:
# for asteroids, use 'DES="designation";'
for ident in self.parse_asteroid():
if ident is not None:
break
if ident is None:
ident = self.targetname
url += "&COMMAND='" + \
urllib.quote(str(ident).encode("utf8")) + "%3B'"
elif self.iscomet() and not self.asteroid:
# for comets, potentially append the current apparition
# (CAP) parameter, or the fragmentation flag (NOFRAG)
for ident in self.parse_comet():
if ident is not None:
break
if ident is None:
ident = self.targetname
url += "&COMMAND='DES=" + \
urllib.quote(ident.encode("utf8")) + "%3B" + \
("NOFRAG%3B" if self.nofrag else "") + \
("CAP'" if self.cap else "'")
# elif (not self.targetname.replace(' ', '').isalpha() and not
# self.targetname.isdigit() and not
# self.targetname.islower() and not
# self.targetname.isupper()):
# # lower case + upper case + numbers = pot. case sensitive designation
# url += "&COMMAND='DES=" + \
# urllib.quote(self.targetname.encode("utf8")) + "%3B'"
else:
url += "&COMMAND='" + \
urllib.quote(self.targetname.encode("utf8")) + "%3B'"
if self.discreteepochs is not None:
url += "&TLIST="
for date in self.discreteepochs:
url += "'" + str(date) + "'"
elif (self.start_epoch is not None and self.stop_epoch is not None and
self.step_size is not None):
url += "&START_TIME='" \
+ urllib.quote(self.start_epoch.encode("utf8")) + "'" \
+ "&STOP_TIME='" \
+ urllib.quote(self.stop_epoch.encode("utf8")) + "'" \
+ "&STEP_SIZE='" + str(self.step_size) + "'"
else:
raise IOError('no epoch information given')
if airmass_lessthan < 99:
url += "&AIRMASS='" + str(airmass_lessthan) + "'"
if skip_daylight:
url += "&SKIP_DAYLT='YES'"
else:
url += "&SKIP_DAYLT='NO'"
self.url = url
# print (url)
# call HORIZONS
i = 0 # count number of connection tries
while True:
try:
src = urllib.urlopen(url).readlines()
break
except urllib.URLError:
time.sleep(0.1)
# in case the HORIZONS website is blocked (due to another query)
# wait 0.1 second and try again
i += 1
if i > 50:
return 0 # website could not be reached
# disseminate website source code
# identify header line and extract data block (ephemerides data)
# also extract targetname, absolute mag. (H), and slope parameter (G)
headerline = []
datablock = []
in_datablock = False
H, G = np.nan, np.nan
for idx, line in enumerate(src):
line = line.decode('UTF-8')
if "Date__(UT)__HR:MN" in line:
headerline = line.split(',')
if "$$EOE\n" in line:
in_datablock = False
if in_datablock:
datablock.append(line)
if "$$SOE\n" in line:
in_datablock = True
if "Target body name" in line:
targetname = line[18:50].strip()
if ("rotational period in hours)" in
src[idx].decode('UTF-8')):
HGline = src[idx+2].decode('UTF-8').split('=')
if 'B-V' in HGline[2] and 'G' in HGline[1]:
try:
H = float(HGline[1].rstrip('G'))
except ValueError:
pass
try:
G = float(HGline[2].rstrip('B-V'))
except ValueError:
pass
if ("Multiple major-bodies match string" in
src[idx].decode('UTF-8') or
("Matching small-bodies" in src[idx].decode('UTF-8') and not
"No matches found" in src[idx+1].decode('UTF-8'))):
raise ValueError('Ambiguous target name; check URL: %s' %
url)
if ("Matching small-bodies" in src[idx].decode('UTF-8') and
"No matches found" in src[idx+1].decode('UTF-8')):
raise ValueError('Unknown target; check URL: %s' % url)
# field identification for each line
ephemerides = []
for line in datablock:
line = line.split(',')
# ignore line that don't hold any data
if len(line) < len(quantities.split(',')):
continue
this_eph = []
fieldnames = []
datatypes = []
# create a dictionary for each date (each line)
for idx, item in enumerate(headerline):
if ('Date__(UT)__HR:MN' in item):
this_eph.append(line[idx].strip())
fieldnames.append('datetime')
datatypes.append(object)
if ('Date_________JDUT' in item):
this_eph.append(np.float64(line[idx]))
fieldnames.append('datetime_jd')
datatypes.append(np.float64)
# read out and convert solar presence
try:
this_eph.append({'*': 'daylight', 'C': 'civil twilight',
'N': 'nautical twilight',
'A': 'astronomical twilight',
' ': 'dark',
't': 'transiting'}[line[idx+1]])
except KeyError:
this_eph.append('n.a.')
fieldnames.append('solar_presence')
datatypes.append(object)
# read out and convert lunar presence
try:
this_eph.append({'m': 'moonlight',
' ': 'dark'}[line[idx+2]])
except KeyError:
this_eph.append('n.a.')
fieldnames.append('lunar_presence')
datatypes.append(object)
if (item.find('R.A._(ICRF/J2000.0)') > -1):
this_eph.append(np.float64(line[idx]))
fieldnames.append('RA')
datatypes.append(np.float64)
if (item.find('DEC_(ICRF/J2000.0)') > -1):
this_eph.append(np.float64(line[idx]))
fieldnames.append('DEC')
datatypes.append(np.float64)
if (item.find('dRA*cosD') > -1):
try:
this_eph.append(np.float64(line[idx])/3600.) # "/s
except ValueError:
this_eph.append(np.nan)
fieldnames.append('RA_rate')
datatypes.append(np.float64)
if (item.find('d(DEC)/dt') > -1):
try:
this_eph.append(np.float64(line[idx])/3600.) # "/s
except ValueError:
this_eph.append(np.nan)
fieldnames.append('DEC_rate')
datatypes.append(np.float64)
if (item.find('Azi_(a-app)') > -1):
try: # if AZ not given, e.g. for space telescopes
this_eph.append(np.float64(line[idx]))
fieldnames.append('AZ')
datatypes.append(np.float64)
except ValueError:
pass
if (item.find('Elev_(a-app)') > -1):
try: # if EL not given, e.g. for space telescopes
this_eph.append(np.float64(line[idx]))
fieldnames.append('EL')
datatypes.append(np.float64)
except ValueError:
pass
if (item.find('a-mass') > -1):
try: # if airmass not given, e.g. for space telescopes
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('airmass')
datatypes.append(np.float64)
if (item.find('mag_ex') > -1):
try: # if mag_ex not given, e.g. for space telescopes
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('magextinct')
datatypes.append(np.float64)
if (item.find('APmag') > -1):
try:
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('V')
datatypes.append(np.float64)
if (item.find('Illu%') > -1):
try:
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('illumination')
datatypes.append(np.float64)
if (item.find('hEcl-Lon') > -1):
try:
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('EclLon')
datatypes.append(np.float64)
if (item.find('hEcl-Lat') > -1):
try:
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('EclLat')
datatypes.append(np.float64)
if (item.find('ObsEcLon') > -1):
try:
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('ObsEclLon')
datatypes.append(np.float64)
if (item.find('ObsEcLat') > -1):
try:
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('ObsEclLat')
datatypes.append(np.float64)
if (item.find(' r') > -1) and \
(headerline[idx+1].find("rdot") > -1):
try:
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('r')
datatypes.append(np.float64)
if (item.find('rdot') > -1):
try:
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('r_rate')
datatypes.append(np.float64)
if (item.find('delta') > -1):
try:
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('delta')
datatypes.append(np.float64)
if (item.find('deldot') > -1):
try:
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('delta_rate')
datatypes.append(np.float64)
if (item.find('1-way_LT') > -1):
try:
this_eph.append(np.float64(line[idx])*60.) # seconds
except ValueError:
this_eph.append(np.nan)
fieldnames.append('lighttime')
datatypes.append(np.float64)
if (item.find('S-O-T') > -1):
try:
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('elong')
datatypes.append(np.float64)
# in the case of space telescopes, '/r S-T-O' is used;
# ground-based telescopes have both parameters in separate
# columns
if (item.find('/r S-T-O') > -1):
this_eph.append({'/L': 'leading', '/T': 'trailing'}
[line[idx].split()[0]])
fieldnames.append('elongFlag')
datatypes.append(object)
try:
this_eph.append(np.float64(line[idx].split()[1]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('alpha')
datatypes.append(np.float64)
elif (item.find('S-T-O') > -1):
try:
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('alpha')
datatypes.append(np.float64)
elif (item.find('/r') > -1):
this_eph.append({'/L': 'leading', '/T': 'trailing',
'/?': 'not defined'}
[line[idx]])
fieldnames.append('elongFlag')
datatypes.append(object)
if (item.find('PsAng') > -1):
try:
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('sunTargetPA')
datatypes.append(np.float64)
if (item.find('PsAMV') > -1):
try:
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('velocityPA')
datatypes.append(np.float64)
if (item.find('GlxLon') > -1):
try:
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('GlxLon')
datatypes.append(np.float64)
if (item.find('GlxLat') > -1):
try:
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('GlxLat')
datatypes.append(np.float64)
if (item.find('RA_3sigma') > -1):
try:
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('RA_3sigma')
datatypes.append(np.float64)
if (item.find('DEC_3sigma') > -1):
try:
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('DEC_3sigma')
datatypes.append(np.float64)
# in the case of a comet, use total mag for V
if (item.find('T-mag') > -1):
try:
this_eph.append(np.float64(line[idx]))
except ValueError:
this_eph.append(np.nan)
fieldnames.append('V')
datatypes.append(np.float64)
# append target name
this_eph.append(targetname)
fieldnames.append('targetname')
datatypes.append(object)
# append H
this_eph.append(H)
fieldnames.append('H')
datatypes.append(np.float64)
# append G
this_eph.append(G)
fieldnames.append('G')
datatypes.append(np.float64)
if len(this_eph) > 0:
ephemerides.append(tuple(this_eph))
if len(ephemerides) == 0:
return 0
# combine ephemerides with column names and data types into ndarray
assert len(ephemerides[0]) == len(fieldnames) == len(datatypes)
self.data = np.array(ephemerides,
dtype=[(str(fieldnames[i]), datatypes[i]) for i
in range(len(fieldnames))])
return len(self)
def get_elements(self, center='500@10', asteroid=False, comet=False):
"""Call JPL HORIZONS website to obtain orbital elements based on the
provided targetname, epochs, and center code. For valid center
codes, please refer to http://ssd.jpl.nasa.gov/horizons.cgi
:param center: str;
center body (default: 500@10 = Sun)
:result: int; number of epochs queried
:example: >>> ceres = callhorizons.query('Ceres')
>>> ceres.set_epochrange('2016-02-23 00:00', '2016-02-24 00:00', '1h')
>>> print (ceres.get_elements(), 'epochs queried')
The queried properties and their definitions are:
+------------------+-----------------------------------------------+
| Property | Definition |
+==================+===============================================+
| targetname | official number, name, designation [string] |
+------------------+-----------------------------------------------+
| H | absolute magnitude in V band (float, mag) |
+------------------+-----------------------------------------------+
| G | photometric slope parameter (float) |
+------------------+-----------------------------------------------+
| datetime_jd | epoch Julian Date (float) |
+------------------+-----------------------------------------------+
| e | eccentricity (float) |
+------------------+-----------------------------------------------+
| p | periapsis distance (float, au) |
+------------------+-----------------------------------------------+
| a | semi-major axis (float, au) |
+------------------+-----------------------------------------------+
| incl | inclination (float, deg) |
+------------------+-----------------------------------------------+
| node | longitude of Asc. Node (float, deg) |
+------------------+-----------------------------------------------+
| argper | argument of the perifocus (float, deg) |
+------------------+-----------------------------------------------+
| Tp | time of periapsis (float, Julian Date) |
+------------------+-----------------------------------------------+
| meananomaly | mean anomaly (float, deg) |
+------------------+-----------------------------------------------+
| trueanomaly | true anomaly (float, deg) |
+------------------+-----------------------------------------------+
| period | orbital period (float, Earth yr) |
+------------------+-----------------------------------------------+
| Q | apoapsis distance (float, au) |
+------------------+-----------------------------------------------+
"""
# encode objectname for use in URL
objectname = urllib.quote(self.targetname.encode("utf8"))
# call Horizons website and extract data
url = "https://ssd.jpl.nasa.gov/horizons_batch.cgi?batch=l" \
+ "&TABLE_TYPE='ELEMENTS'" \
+ "&CSV_FORMAT='YES'" \
+ "&CENTER='" + str(center) + "'" \
+ "&OUT_UNITS='AU-D'" \
+ "&REF_PLANE='ECLIPTIC'" \
+ "REF_SYSTEM='J2000'" \
+ "&TP_TYPE='ABSOLUTE'" \
+ "&ELEM_LABELS='YES'" \
+ "CSV_FORMAT='YES'" \
+ "&OBJ_DATA='YES'"
# check if self.targetname is a designation
# lower case + upper case + numbers = pot. case sensitive designation
if self.not_smallbody:
url += "&COMMAND='" + \
urllib.quote(self.targetname.encode("utf8")) + "'"
elif self.isorbit_record():
# Comet orbit record. Do not use DES, CAP. This test must
# occur before asteroid test.
url += "&COMMAND='" + \
urllib.quote(self.targetname.encode("utf8")) + "%3B'"
elif self.isasteroid() and not self.comet:
# for asteroids, use 'DES="designation";'
for ident in self.parse_asteroid():
if ident is not None:
break
if ident is None:
ident = self.targetname
url += "&COMMAND='" + \
urllib.quote(str(ident).encode("utf8")) + "%3B'"
elif self.iscomet() and not self.asteroid:
# for comets, potentially append the current apparition
# (CAP) parameter, or the fragmentation flag (NOFRAG)
for ident in self.parse_comet():
if ident is not None:
break
if ident is None:
ident = self.targetname
url += "&COMMAND='DES=" + \
urllib.quote(ident.encode("utf8")) + "%3B" + \
("NOFRAG%3B" if self.nofrag else "") + \
("CAP'" if self.cap else "'")
# elif (not self.targetname.replace(' ', '').isalpha() and not
# self.targetname.isdigit() and not
# self.targetname.islower() and not
# self.targetname.isupper()):
# url += "&COMMAND='DES=" + str(objectname) + "%3B'"
else:
url += "&COMMAND='" + str(objectname) + "%3B'"
if self.discreteepochs is not None:
url += "&TLIST="
for date in self.discreteepochs:
url += "'" + str(date) + "'"
elif (self.start_epoch is not None and self.stop_epoch is not None and
self.step_size is not None):
url += "&START_TIME='" \
+ urllib.quote(self.start_epoch.encode("utf8")) + "'" \
+ "&STOP_TIME='" \
+ urllib.quote(self.stop_epoch.encode("utf8")) + "'" \
+ "&STEP_SIZE='" + str(self.step_size) + "'"
else:
raise IOError('no epoch information given')
self.url = url
i = 0 # count number of connection tries
while True:
try:
src = urllib.urlopen(url).readlines()
break
except urllib.URLError:
time.sleep(0.1)
# in case the HORIZONS website is blocked (due to another query)
# wait 1 second and try again
i += 1
if i > 50:
return 0 # website could not be reached
# disseminate website source code
# identify header line and extract data block (elements data)
# also extract targetname, abs. magnitude (H), and slope parameter (G)
headerline = []
datablock = []
in_datablock = False
H, G = np.nan, np.nan
for idx, line in enumerate(src):
line = line.decode('UTF-8')
if 'JDTDB,' in line:
headerline = line.split(',')
if "$$EOE\n" in line:
in_datablock = False
if in_datablock:
datablock.append(line)
if "$$SOE\n" in line:
in_datablock = True
if "Target body name" in line:
targetname = line[18:50].strip()
if "rotational period in hours)" in src[idx].decode('UTF-8'):
HGline = src[idx+2].decode('UTF-8').split('=')
if 'B-V' in HGline[2] and 'G' in HGline[1]:
try:
H = float(HGline[1].rstrip('G'))
except ValueError:
pass
try:
G = float(HGline[2].rstrip('B-V'))
except ValueError:
pass
if ("Multiple major-bodies match string" in src[idx].decode('UTF-8') or
("Matching small-bodies" in src[idx].decode('UTF-8') and not
"No matches found" in src[idx+1].decode('UTF-8'))):
raise ValueError('Ambiguous target name; check URL: %s' %
url)
if ("Matching small-bodies" in src[idx].decode('UTF-8') and
"No matches found" in src[idx+1].decode('UTF-8')):
raise ValueError('Unknown target; check URL: %s' % url)
# field identification for each line in
elements = []
for line in datablock:
line = line.split(',')
this_el = []
fieldnames = []
datatypes = []
# create a dictionary for each date (each line)
for idx, item in enumerate(headerline):
if (item.find('JDTDB') > -1):
this_el.append(np.float64(line[idx]))
fieldnames.append('datetime_jd')
datatypes.append(np.float64)
if (item.find('EC') > -1):
this_el.append(np.float64(line[idx]))
fieldnames.append('e')
datatypes.append(np.float64)
if (item.find('QR') > -1):
this_el.append(np.float64(line[idx]))
fieldnames.append('p')
datatypes.append(np.float64)
if (item.find('A') > -1) and len(item.strip()) == 1:
this_el.append(np.float64(line[idx]))
fieldnames.append('a')
datatypes.append(np.float64)
if (item.find('IN') > -1):
this_el.append(np.float64(line[idx]))
fieldnames.append('incl')
datatypes.append(np.float64)
if (item.find('OM') > -1):
this_el.append(np.float64(line[idx]))
fieldnames.append('node')
datatypes.append(np.float64)
if (item.find('W') > -1):
this_el.append(np.float64(line[idx]))
fieldnames.append('argper')
datatypes.append(np.float64)
if (item.find('Tp') > -1):
this_el.append(np.float64(line[idx]))
fieldnames.append('Tp')
datatypes.append(np.float64)
if (item.find('MA') > -1):
this_el.append(np.float64(line[idx]))
fieldnames.append('meananomaly')
datatypes.append(np.float64)
if (item.find('TA') > -1):
this_el.append(np.float64(line[idx]))
fieldnames.append('trueanomaly')
datatypes.append(np.float64)
if (item.find('PR') > -1):
# Earth years
this_el.append(np.float64(line[idx])/(365.256))
fieldnames.append('period')
datatypes.append(np.float64)
if (item.find('AD') > -1):
this_el.append(np.float64(line[idx]))
fieldnames.append('Q')
datatypes.append(np.float64)
# append targetname
this_el.append(targetname)
fieldnames.append('targetname')
datatypes.append(object)
# append H
this_el.append(H)
fieldnames.append('H')
datatypes.append(np.float64)
# append G
this_el.append(G)
fieldnames.append('G')
datatypes.append(np.float64)
if len(this_el) > 0:
elements.append(tuple(this_el))
if len(elements) == 0:
return 0
# combine elements with column names and data types into ndarray
assert len(elements[0]) == len(fieldnames) == len(datatypes)
self.data = np.array(elements,
dtype=[(str(fieldnames[i]), datatypes[i]) for i
in range(len(fieldnames))])
return len(self)
def export2pyephem(self, center='500@10', equinox=2000.):
"""Call JPL HORIZONS website to obtain orbital elements based on the
provided targetname, epochs, and center code and create a
PyEphem (http://rhodesmill.org/pyephem/) object. This function
requires PyEphem to be installed.
:param center: str;
center body (default: 500@10 = Sun)
:param equinox: float;
equinox (default: 2000.0)
:result: list;
list of PyEphem objects, one per epoch
:example: >>> import callhorizons
>>> import numpy
>>> import ephem
>>>
>>> ceres = callhorizons.query('Ceres')
>>> ceres.set_epochrange('2016-02-23 00:00', '2016-02-24 00:00', '1h')
>>> ceres_pyephem = ceres.export2pyephem()
>>>
>>> nau = ephem.Observer() # setup observer site
>>> nau.lon = -111.653152/180.*numpy.pi
>>> nau.lat = 35.184108/180.*numpy.pi
>>> nau.elevation = 2100 # m
>>> nau.date = '2015/10/5 01:23' # UT
>>> print ('next rising: %s' % nau.next_rising(ceres_pyephem[0]))
>>> print ('next transit: %s' % nau.next_transit(ceres_pyephem[0]))
>>> print ('next setting: %s' % nau.next_setting(ceres_pyephem[0]))
"""
try:
import ephem
except ImportError:
raise ImportError(
'export2pyephem requires PyEphem to be installed')
# obtain orbital elements
self.get_elements(center)
objects = []
for el in self.data:
n = 0.9856076686/np.sqrt(el['a']**3) # mean daily motion
epoch_djd = el['datetime_jd']-2415020.0 # Dublin Julian date
epoch = ephem.date(epoch_djd)
epoch_str = "%d/%f/%d" % (epoch.triple()[1], epoch.triple()[2],
epoch.triple()[0])
# export to PyEphem
objects.append(ephem.readdb("%s,e,%f,%f,%f,%f,%f,%f,%f,%s,%i,%f,%f" %
(el['targetname'], el['incl'], el['node'],
el['argper'], el['a'], n, el['e'],
el['meananomaly'], epoch_str, equinox,
el['H'], el['G'])))
return objects
|
mit
|
[
624,
11978,
40,
7123,
23300,
446,
282,
2018,
3217,
370,
2879,
1603,
2749,
869,
7123,
23300,
199,
1545,
426,
278,
2188,
83,
436,
503,
2075,
279,
4008,
14,
199,
199,
2765,
859,
6571,
282,
22700,
2366,
3217,
370,
314,
1603,
2749,
199,
40,
7123,
23300,
2656,
701,
5370,
18549,
436,
6057,
314,
869,
7123,
23300,
199,
7360,
14,
27255,
426,
278,
2188,
83,
883,
506,
15884,
4012,
664,
63,
1545,
426,
278,
2188,
83,
12,
199,
28043,
279,
4008,
4012,
664,
63,
5527,
14,
6801,
199,
3790,
18,
647,
1545,
27037,
6571,
376,
3217,
370,
314,
1611,
14057,
27037,
859,
14,
199,
199,
22333,
14,
31714,
278,
2591,
334,
292,
9,
302,
3844,
14,
8654,
12,
8839,
1015,
26,
373,
17,
14,
16,
14,
21,
12,
9708,
13,
1717,
13,
1717,
14,
199,
2765,
1233,
365,
315,
8721,
581,
701,
1233,
2737,
701,
22986,
869,
24758,
14,
199,
199,
10,
373,
17,
14,
199,
10,
373,
17,
14,
16,
14,
21,
26,
4114,
13,
7367,
2304,
367,
663,
63,
23591,
13161,
4829,
199,
10,
373,
17,
14,
16,
14,
20,
26,
1742,
26429,
465,
266,
3977,
436,
512,
10207,
536,
6057,
199,
10,
373,
17,
14,
16,
14,
19,
26,
593,
1533,
37,
429,
31253,
436,
593,
1533,
37,
429,
22510,
3483,
370,
664,
63,
1545,
426,
278,
2188,
83,
199,
10,
373,
17,
14,
16,
14,
18,
26,
2018,
650,
14,
21,
7163,
6366,
199,
10,
373,
17,
14,
16,
14,
17,
26,
664,
63,
1545,
426,
278,
2188,
83,
6317,
199,
10,
373,
17,
14,
16,
26,
257,
6519,
26205,
9709,
12,
8683,
8716,
15,
83,
323,
13876,
744,
17909,
12,
4634,
199,
10,
373,
16,
14,
25,
26,
257,
1642,
4683,
421,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
334,
1361,
63,
1593,
12,
2649,
63,
5955,
9,
199,
199,
646,
295,
199,
646,
984,
199,
646,
900,
199,
646,
2680,
465,
980,
199,
646,
3598,
199,
893,
26,
272,
327,
2018,
650,
272,
492,
4011,
14,
1069,
465,
4011,
199,
2590,
3545,
26,
272,
327,
2018,
499,
272,
492,
4011,
18,
465,
4011,
199,
199,
5451,
14,
23945,
360,
5089,
297,
4637,
29,
15561,
9,
199,
5451,
14,
4050,
4725,
11978,
40,
7123,
23300,
365,
440,
26391,
20827,
27,
8749,
675,
283,
2049,
283,
1810,
293,
1131,
14,
74,
1168,
72,
5546,
4654,
3140,
334,
2859,
921,
5031,
14,
957,
4805,
2049,
283,
1810,
7537,
15,
1810,
293,
1131,
11218,
1598,
13413,
9,
421,
199,
318,
485,
1560,
18,
442,
8,
1560,
304,
272,
408,
9028,
4110,
370,
3000,
1338,
334,
4142,
436,
5117,
1930,
9471,
272,
340,
1495,
14,
13896,
837,
267,
372,
1109,
8,
1609,
8,
1560,
430,
272,
340,
1495,
14,
374,
4142,
837,
267,
372,
1109,
8,
1560,
12,
8780,
9,
272,
587,
26,
267,
372,
7875,
435,
1109,
8,
1560,
12,
8780,
9,
421,
199,
533,
1827,
837,
339,
327,
3787,
272,
347,
636,
826,
721,
277,
12,
1347,
354,
12,
7425,
2030,
29,
549,
12,
4021,
29,
549,
12,
949,
11255,
29,
797,
12,
326,
512,
10207,
29,
797,
12,
465,
266,
3977,
29,
797,
304,
267,
408,
9345,
1827,
370,
869,
5546,
4654,
398,
520,
635,
1347,
354,
26,
869,
7123,
23300,
13,
11875,
1347,
1329,
12,
536,
12,
503,
12899,
425,
267,
520,
635,
7425,
2030,
26,
221,
5046,
221,
675,
1124,
7241,
2030,
29,
797,
1040,
340,
1347,
354,
365,
282,
2574,
8683,
386,
503,
4601,
32342,
334,
4144,
12,
849,
26,
658,
549,
64,
2736,
2574,
2597,
675,
658,
549,
64,
340,
314,
1347,
354,
365,
5835,
436,
2574,
1077,
506,
30081,
465,
365,
267,
520,
635,
4021,
26,
663,
370,
658,
549,
64,
370,
372,
314,
1453,
2771,
462,
15415,
367,
490,
512,
10207,
4545,
267,
520,
635,
949,
11255,
26,
663,
370,
658,
549,
64,
370,
3507,
869,
7123,
23300,
1159,
512,
10207,
2432,
7956,
2754,
267,
520,
635,
512,
10207,
26,
663,
370,
658,
549,
64,
340,
642,
365,
282,
512,
10207,
334,
14117,
4278,
1993,
4834,
1347,
354,
6057,
9,
267,
520,
635,
465,
266,
3977,
26,
663,
370,
658,
549,
64,
340,
642,
365,
376,
465,
266,
3977,
334,
14117,
4278,
586,
4834,
1347,
354,
6057,
9,
267,
520,
1107,
26,
488,
398,
408,
398,
291,
14,
1375,
354,
275,
620,
8,
1375,
354,
9,
267,
291,
14,
1397,
63,
7241,
2030,
275,
440,
7425,
2030,
267,
291,
14,
2874,
275,
4021,
267,
291,
14,
889,
11255,
275,
949,
11255,
267,
291,
14,
4352,
84,
275,
512,
10207,
221,
327,
365,
642,
909,
282,
512,
10207,
31,
267,
291,
14,
9209,
3977,
275,
465,
266,
3977,
221,
327,
365,
642,
909,
376,
465,
266,
3977,
31,
267,
291,
14,
928,
63,
7367,
275,
488,
267,
291,
14,
2379,
63,
7367,
275,
488,
267,
291,
14,
2926,
63,
890,
275,
488,
267,
291,
14,
23591,
13161,
275,
488,
267,
291,
14,
633,
275,
488,
267,
291,
14,
576,
275,
488,
398,
702,
440,
334,
288,
291,
14,
4352,
84,
436,
291,
14,
9209,
3977,
395,
283,
5903,
1373,
402,
512,
10207,
503,
465,
266,
3977,
883,
506,
658,
549,
2313,
7,
398,
372,
488,
339,
327,
7425,
2396,
12899,
425,
6057,
339,
347,
2198,
63,
4352,
84,
8,
277,
304,
267,
408,
4003,
658,
1375,
354,
64,
465,
340,
652,
4898,
282,
512,
10207,
14,
398,
520,
1107,
26,
334,
875,
503,
488,
12,
1109,
503,
488,
12,
1059,
503,
488,
2736,
881,
710,
12899,
425,
12,
1329,
436,
2403,
12,
436,
536,
402,
314,
512,
10207,
465,
7131,
881,
687,
658,
277,
14,
1375,
354,
64,
787,
12509,
1901,
282,
2008,
27,
1924,
1819,
626,
881,
1630,
440,
2187,
365,
663,
370,
658,
403,
2313,
10164,
828,
14925,
315,
658,
277,
14,
1375,
354,
64,
881,
911,
506,
5525,
14,
267,
520,
2694,
26,
314,
2569,
1817,
13703,
314,
754,
402,
314,
6057,
26,
398,
435,
1444,
24780,
11,
267,
1204,
1375,
354,
10473,
1204,
8,
271,
4093,
12,
2403,
1955,
12,
536,
9,
258,
1204,
267,
435,
2486,
11,
2486,
11,
267,
1204,
17,
48,
15,
40,
4598,
89,
9668,
1204,
8,
403,
12,
283,
17,
48,
297,
283,
40,
4598,
89
] |
[
11978,
40,
7123,
23300,
446,
282,
2018,
3217,
370,
2879,
1603,
2749,
869,
7123,
23300,
199,
1545,
426,
278,
2188,
83,
436,
503,
2075,
279,
4008,
14,
199,
199,
2765,
859,
6571,
282,
22700,
2366,
3217,
370,
314,
1603,
2749,
199,
40,
7123,
23300,
2656,
701,
5370,
18549,
436,
6057,
314,
869,
7123,
23300,
199,
7360,
14,
27255,
426,
278,
2188,
83,
883,
506,
15884,
4012,
664,
63,
1545,
426,
278,
2188,
83,
12,
199,
28043,
279,
4008,
4012,
664,
63,
5527,
14,
6801,
199,
3790,
18,
647,
1545,
27037,
6571,
376,
3217,
370,
314,
1611,
14057,
27037,
859,
14,
199,
199,
22333,
14,
31714,
278,
2591,
334,
292,
9,
302,
3844,
14,
8654,
12,
8839,
1015,
26,
373,
17,
14,
16,
14,
21,
12,
9708,
13,
1717,
13,
1717,
14,
199,
2765,
1233,
365,
315,
8721,
581,
701,
1233,
2737,
701,
22986,
869,
24758,
14,
199,
199,
10,
373,
17,
14,
199,
10,
373,
17,
14,
16,
14,
21,
26,
4114,
13,
7367,
2304,
367,
663,
63,
23591,
13161,
4829,
199,
10,
373,
17,
14,
16,
14,
20,
26,
1742,
26429,
465,
266,
3977,
436,
512,
10207,
536,
6057,
199,
10,
373,
17,
14,
16,
14,
19,
26,
593,
1533,
37,
429,
31253,
436,
593,
1533,
37,
429,
22510,
3483,
370,
664,
63,
1545,
426,
278,
2188,
83,
199,
10,
373,
17,
14,
16,
14,
18,
26,
2018,
650,
14,
21,
7163,
6366,
199,
10,
373,
17,
14,
16,
14,
17,
26,
664,
63,
1545,
426,
278,
2188,
83,
6317,
199,
10,
373,
17,
14,
16,
26,
257,
6519,
26205,
9709,
12,
8683,
8716,
15,
83,
323,
13876,
744,
17909,
12,
4634,
199,
10,
373,
16,
14,
25,
26,
257,
1642,
4683,
421,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
334,
1361,
63,
1593,
12,
2649,
63,
5955,
9,
199,
199,
646,
295,
199,
646,
984,
199,
646,
900,
199,
646,
2680,
465,
980,
199,
646,
3598,
199,
893,
26,
272,
327,
2018,
650,
272,
492,
4011,
14,
1069,
465,
4011,
199,
2590,
3545,
26,
272,
327,
2018,
499,
272,
492,
4011,
18,
465,
4011,
199,
199,
5451,
14,
23945,
360,
5089,
297,
4637,
29,
15561,
9,
199,
5451,
14,
4050,
4725,
11978,
40,
7123,
23300,
365,
440,
26391,
20827,
27,
8749,
675,
283,
2049,
283,
1810,
293,
1131,
14,
74,
1168,
72,
5546,
4654,
3140,
334,
2859,
921,
5031,
14,
957,
4805,
2049,
283,
1810,
7537,
15,
1810,
293,
1131,
11218,
1598,
13413,
9,
421,
199,
318,
485,
1560,
18,
442,
8,
1560,
304,
272,
408,
9028,
4110,
370,
3000,
1338,
334,
4142,
436,
5117,
1930,
9471,
272,
340,
1495,
14,
13896,
837,
267,
372,
1109,
8,
1609,
8,
1560,
430,
272,
340,
1495,
14,
374,
4142,
837,
267,
372,
1109,
8,
1560,
12,
8780,
9,
272,
587,
26,
267,
372,
7875,
435,
1109,
8,
1560,
12,
8780,
9,
421,
199,
533,
1827,
837,
339,
327,
3787,
272,
347,
636,
826,
721,
277,
12,
1347,
354,
12,
7425,
2030,
29,
549,
12,
4021,
29,
549,
12,
949,
11255,
29,
797,
12,
326,
512,
10207,
29,
797,
12,
465,
266,
3977,
29,
797,
304,
267,
408,
9345,
1827,
370,
869,
5546,
4654,
398,
520,
635,
1347,
354,
26,
869,
7123,
23300,
13,
11875,
1347,
1329,
12,
536,
12,
503,
12899,
425,
267,
520,
635,
7425,
2030,
26,
221,
5046,
221,
675,
1124,
7241,
2030,
29,
797,
1040,
340,
1347,
354,
365,
282,
2574,
8683,
386,
503,
4601,
32342,
334,
4144,
12,
849,
26,
658,
549,
64,
2736,
2574,
2597,
675,
658,
549,
64,
340,
314,
1347,
354,
365,
5835,
436,
2574,
1077,
506,
30081,
465,
365,
267,
520,
635,
4021,
26,
663,
370,
658,
549,
64,
370,
372,
314,
1453,
2771,
462,
15415,
367,
490,
512,
10207,
4545,
267,
520,
635,
949,
11255,
26,
663,
370,
658,
549,
64,
370,
3507,
869,
7123,
23300,
1159,
512,
10207,
2432,
7956,
2754,
267,
520,
635,
512,
10207,
26,
663,
370,
658,
549,
64,
340,
642,
365,
282,
512,
10207,
334,
14117,
4278,
1993,
4834,
1347,
354,
6057,
9,
267,
520,
635,
465,
266,
3977,
26,
663,
370,
658,
549,
64,
340,
642,
365,
376,
465,
266,
3977,
334,
14117,
4278,
586,
4834,
1347,
354,
6057,
9,
267,
520,
1107,
26,
488,
398,
408,
398,
291,
14,
1375,
354,
275,
620,
8,
1375,
354,
9,
267,
291,
14,
1397,
63,
7241,
2030,
275,
440,
7425,
2030,
267,
291,
14,
2874,
275,
4021,
267,
291,
14,
889,
11255,
275,
949,
11255,
267,
291,
14,
4352,
84,
275,
512,
10207,
221,
327,
365,
642,
909,
282,
512,
10207,
31,
267,
291,
14,
9209,
3977,
275,
465,
266,
3977,
221,
327,
365,
642,
909,
376,
465,
266,
3977,
31,
267,
291,
14,
928,
63,
7367,
275,
488,
267,
291,
14,
2379,
63,
7367,
275,
488,
267,
291,
14,
2926,
63,
890,
275,
488,
267,
291,
14,
23591,
13161,
275,
488,
267,
291,
14,
633,
275,
488,
267,
291,
14,
576,
275,
488,
398,
702,
440,
334,
288,
291,
14,
4352,
84,
436,
291,
14,
9209,
3977,
395,
283,
5903,
1373,
402,
512,
10207,
503,
465,
266,
3977,
883,
506,
658,
549,
2313,
7,
398,
372,
488,
339,
327,
7425,
2396,
12899,
425,
6057,
339,
347,
2198,
63,
4352,
84,
8,
277,
304,
267,
408,
4003,
658,
1375,
354,
64,
465,
340,
652,
4898,
282,
512,
10207,
14,
398,
520,
1107,
26,
334,
875,
503,
488,
12,
1109,
503,
488,
12,
1059,
503,
488,
2736,
881,
710,
12899,
425,
12,
1329,
436,
2403,
12,
436,
536,
402,
314,
512,
10207,
465,
7131,
881,
687,
658,
277,
14,
1375,
354,
64,
787,
12509,
1901,
282,
2008,
27,
1924,
1819,
626,
881,
1630,
440,
2187,
365,
663,
370,
658,
403,
2313,
10164,
828,
14925,
315,
658,
277,
14,
1375,
354,
64,
881,
911,
506,
5525,
14,
267,
520,
2694,
26,
314,
2569,
1817,
13703,
314,
754,
402,
314,
6057,
26,
398,
435,
1444,
24780,
11,
267,
1204,
1375,
354,
10473,
1204,
8,
271,
4093,
12,
2403,
1955,
12,
536,
9,
258,
1204,
267,
435,
2486,
11,
2486,
11,
267,
1204,
17,
48,
15,
40,
4598,
89,
9668,
1204,
8,
403,
12,
283,
17,
48,
297,
283,
40,
4598,
89,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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. 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 sys
from pyspark.sql import SparkSession
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: sort <file>", file=sys.stderr)
sys.exit(-1)
spark = SparkSession\
.builder\
.appName("PythonSort")\
.getOrCreate()
lines = spark.read.text(sys.argv[1]).rdd.map(lambda r: r[0])
sortedCount = lines.flatMap(lambda x: x.split(' ')) \
.map(lambda x: (int(x), 1)) \
.sortByKey()
# This is just a demo on how to bring all the sorted data back to a single node.
# In reality, we wouldn't want to collect all the data to the driver node.
output = sortedCount.collect()
for (num, unitcount) in output:
print(num)
spark.stop()
|
apache-2.0
|
[
3,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
646,
984,
199,
199,
504,
15847,
14,
3009,
492,
13932,
4434,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
340,
822,
8,
1274,
14,
3020,
9,
1137,
499,
26,
267,
870,
480,
7692,
26,
4069,
665,
493,
7166,
570,
29,
1274,
14,
3083,
9,
267,
984,
14,
2224,
2801,
17,
9,
339,
15442,
275,
13932,
4434,
60,
267,
1275,
5649,
60,
267,
1275,
571,
985,
480,
4718,
14376,
27681,
267,
1275,
30457,
2499,
342,
339,
2385,
275,
15442,
14,
739,
14,
505,
8,
1274,
14,
3020,
59,
17,
6575,
20533,
14,
1130,
8,
2734,
519,
26,
519,
59,
16,
566,
272,
3355,
2353,
275,
2385,
14,
7088,
2956,
8,
2734,
671,
26,
671,
14,
1294,
360,
20005,
971,
267,
1275,
1130,
8,
2734,
671,
26,
334,
442,
8,
88,
395,
413,
430,
971,
267,
1275,
3191,
2175,
1197,
342,
272,
327,
961,
365,
2951,
282,
14779,
641,
4212,
370,
330,
5985,
1006,
314,
3355,
666,
1771,
370,
282,
2849,
1031,
14,
272,
327,
1010,
3363,
1209,
12,
781,
3955,
78,
1133,
2934,
370,
8775,
1006,
314,
666,
370,
314,
5253,
1031,
14,
272,
1072,
275,
3355,
2353,
14,
7112,
342,
272,
367,
334,
1507,
12,
4137,
835,
9,
315,
1072,
26,
267,
870,
8,
1507,
9,
339,
15442,
14,
2379,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
646,
984,
199,
199,
504,
15847,
14,
3009,
492,
13932,
4434,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
340,
822,
8,
1274,
14,
3020,
9,
1137,
499,
26,
267,
870,
480,
7692,
26,
4069,
665,
493,
7166,
570,
29,
1274,
14,
3083,
9,
267,
984,
14,
2224,
2801,
17,
9,
339,
15442,
275,
13932,
4434,
60,
267,
1275,
5649,
60,
267,
1275,
571,
985,
480,
4718,
14376,
27681,
267,
1275,
30457,
2499,
342,
339,
2385,
275,
15442,
14,
739,
14,
505,
8,
1274,
14,
3020,
59,
17,
6575,
20533,
14,
1130,
8,
2734,
519,
26,
519,
59,
16,
566,
272,
3355,
2353,
275,
2385,
14,
7088,
2956,
8,
2734,
671,
26,
671,
14,
1294,
360,
20005,
971,
267,
1275,
1130,
8,
2734,
671,
26,
334,
442,
8,
88,
395,
413,
430,
971,
267,
1275,
3191,
2175,
1197,
342,
272,
327,
961,
365,
2951,
282,
14779,
641,
4212,
370,
330,
5985,
1006,
314,
3355,
666,
1771,
370,
282,
2849,
1031,
14,
272,
327,
1010,
3363,
1209,
12,
781,
3955,
78,
1133,
2934,
370,
8775,
1006,
314,
666,
370,
314,
5253,
1031,
14,
272,
1072,
275,
3355,
2353,
14,
7112,
342,
272,
367,
334,
1507,
12,
4137,
835,
9,
315,
1072,
26,
267,
870,
8,
1507,
9,
339,
15442,
14,
2379,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ducthien1490/youtube-dl
|
youtube_dl/extractor/niconico.py
|
59
|
11056
|
# encoding: utf-8
from __future__ import unicode_literals
import re
import json
import datetime
from .common import InfoExtractor
from ..compat import (
compat_urllib_parse,
compat_urllib_request,
compat_urlparse,
)
from ..utils import (
ExtractorError,
int_or_none,
parse_duration,
parse_iso8601,
xpath_text,
determine_ext,
)
class NiconicoIE(InfoExtractor):
IE_NAME = 'niconico'
IE_DESC = 'ニコニコ動画'
_TESTS = [{
'url': 'http://www.nicovideo.jp/watch/sm22312215',
'md5': 'd1a75c0823e2f629128c43e1212760f9',
'info_dict': {
'id': 'sm22312215',
'ext': 'mp4',
'title': 'Big Buck Bunny',
'uploader': 'takuya0301',
'uploader_id': '2698420',
'upload_date': '20131123',
'timestamp': 1385182762,
'description': '(c) copyright 2008, Blender Foundation / www.bigbuckbunny.org',
'duration': 33,
},
}, {
# File downloaded with and without credentials are different, so omit
# the md5 field
'url': 'http://www.nicovideo.jp/watch/nm14296458',
'info_dict': {
'id': 'nm14296458',
'ext': 'swf',
'title': '【鏡音リン】Dance on media【オリジナル】take2!',
'description': 'md5:689f066d74610b3b22e0f1739add0f58',
'uploader': 'りょうた',
'uploader_id': '18822557',
'upload_date': '20110429',
'timestamp': 1304065916,
'duration': 209,
},
}, {
# 'video exists but is marked as "deleted"
# md5 is unstable
'url': 'http://www.nicovideo.jp/watch/sm10000',
'info_dict': {
'id': 'sm10000',
'ext': 'unknown_video',
'description': 'deleted',
'title': 'ドラえもんエターナル第3話「決戦第3新東京市」<前編>',
'upload_date': '20071224',
'timestamp': 1198527840, # timestamp field has different value if logged in
'duration': 304,
},
}, {
'url': 'http://www.nicovideo.jp/watch/so22543406',
'info_dict': {
'id': '1388129933',
'ext': 'mp4',
'title': '【第1回】RADIOアニメロミックス ラブライブ!~のぞえりRadio Garden~',
'description': 'md5:b27d224bb0ff53d3c8269e9f8b561cf1',
'timestamp': 1388851200,
'upload_date': '20140104',
'uploader': 'アニメロチャンネル',
'uploader_id': '312',
}
}]
_VALID_URL = r'https?://(?:www\.|secure\.)?nicovideo\.jp/watch/(?P<id>(?:[a-z]{2})?[0-9]+)'
_NETRC_MACHINE = 'niconico'
# Determine whether the downloader used authentication to download video
_AUTHENTICATED = False
def _real_initialize(self):
self._login()
def _login(self):
(username, password) = self._get_login_info()
# No authentication to be performed
if not username:
return True
# Log in
login_form_strs = {
'mail': username,
'password': password,
}
# Convert to UTF-8 *before* urlencode because Python 2.x's urlencode
# chokes on unicode
login_form = dict((k.encode('utf-8'), v.encode('utf-8')) for k, v in login_form_strs.items())
login_data = compat_urllib_parse.urlencode(login_form).encode('utf-8')
request = compat_urllib_request.Request(
'https://secure.nicovideo.jp/secure/login', login_data)
login_results = self._download_webpage(
request, None, note='Logging in', errnote='Unable to log in')
if re.search(r'(?i)<h1 class="mb8p4">Log in error</h1>', login_results) is not None:
self._downloader.report_warning('unable to log in: bad username or password')
return False
# Successful login
self._AUTHENTICATED = True
return True
def _real_extract(self, url):
video_id = self._match_id(url)
# Get video webpage. We are not actually interested in it for normal
# cases, but need the cookies in order to be able to download the
# info webpage
webpage, handle = self._download_webpage_handle(
'http://www.nicovideo.jp/watch/' + video_id, video_id)
if video_id.startswith('so'):
video_id = self._match_id(handle.geturl())
video_info = self._download_xml(
'http://ext.nicovideo.jp/api/getthumbinfo/' + video_id, video_id,
note='Downloading video info page')
if self._AUTHENTICATED:
# Get flv info
flv_info_webpage = self._download_webpage(
'http://flapi.nicovideo.jp/api/getflv/' + video_id + '?as3=1',
video_id, 'Downloading flv info')
else:
# Get external player info
ext_player_info = self._download_webpage(
'http://ext.nicovideo.jp/thumb_watch/' + video_id, video_id)
thumb_play_key = self._search_regex(
r'\'thumbPlayKey\'\s*:\s*\'(.*?)\'', ext_player_info, 'thumbPlayKey')
# Get flv info
flv_info_data = compat_urllib_parse.urlencode({
'k': thumb_play_key,
'v': video_id
})
flv_info_request = compat_urllib_request.Request(
'http://ext.nicovideo.jp/thumb_watch', flv_info_data,
{'Content-Type': 'application/x-www-form-urlencoded'})
flv_info_webpage = self._download_webpage(
flv_info_request, video_id,
note='Downloading flv info', errnote='Unable to download flv info')
flv_info = compat_urlparse.parse_qs(flv_info_webpage)
if 'url' not in flv_info:
if 'deleted' in flv_info:
raise ExtractorError('The video has been deleted.',
expected=True)
else:
raise ExtractorError('Unable to find video URL')
video_real_url = flv_info['url'][0]
# Start extracting information
title = xpath_text(video_info, './/title')
if not title:
title = self._og_search_title(webpage, default=None)
if not title:
title = self._html_search_regex(
r'<span[^>]+class="videoHeaderTitle"[^>]*>([^<]+)</span>',
webpage, 'video title')
watch_api_data_string = self._html_search_regex(
r'<div[^>]+id="watchAPIDataContainer"[^>]+>([^<]+)</div>',
webpage, 'watch api data', default=None)
watch_api_data = self._parse_json(watch_api_data_string, video_id) if watch_api_data_string else {}
video_detail = watch_api_data.get('videoDetail', {})
extension = xpath_text(video_info, './/movie_type')
if not extension:
extension = determine_ext(video_real_url)
thumbnail = (
xpath_text(video_info, './/thumbnail_url') or
self._html_search_meta('image', webpage, 'thumbnail', default=None) or
video_detail.get('thumbnail'))
description = xpath_text(video_info, './/description')
timestamp = parse_iso8601(xpath_text(video_info, './/first_retrieve'))
if not timestamp:
match = self._html_search_meta('datePublished', webpage, 'date published', default=None)
if match:
timestamp = parse_iso8601(match.replace('+', ':00+'))
if not timestamp and video_detail.get('postedAt'):
timestamp = parse_iso8601(
video_detail['postedAt'].replace('/', '-'),
delimiter=' ', timezone=datetime.timedelta(hours=9))
view_count = int_or_none(xpath_text(video_info, './/view_counter'))
if not view_count:
match = self._html_search_regex(
r'>Views: <strong[^>]*>([^<]+)</strong>',
webpage, 'view count', default=None)
if match:
view_count = int_or_none(match.replace(',', ''))
view_count = view_count or video_detail.get('viewCount')
comment_count = int_or_none(xpath_text(video_info, './/comment_num'))
if not comment_count:
match = self._html_search_regex(
r'>Comments: <strong[^>]*>([^<]+)</strong>',
webpage, 'comment count', default=None)
if match:
comment_count = int_or_none(match.replace(',', ''))
comment_count = comment_count or video_detail.get('commentCount')
duration = (parse_duration(
xpath_text(video_info, './/length') or
self._html_search_meta(
'video:duration', webpage, 'video duration', default=None)) or
video_detail.get('length'))
webpage_url = xpath_text(video_info, './/watch_url') or url
if video_info.find('.//ch_id') is not None:
uploader_id = video_info.find('.//ch_id').text
uploader = video_info.find('.//ch_name').text
elif video_info.find('.//user_id') is not None:
uploader_id = video_info.find('.//user_id').text
uploader = video_info.find('.//user_nickname').text
else:
uploader_id = uploader = None
return {
'id': video_id,
'url': video_real_url,
'title': title,
'ext': extension,
'format_id': 'economy' if video_real_url.endswith('low') else 'normal',
'thumbnail': thumbnail,
'description': description,
'uploader': uploader,
'timestamp': timestamp,
'uploader_id': uploader_id,
'view_count': view_count,
'comment_count': comment_count,
'duration': duration,
'webpage_url': webpage_url,
}
class NiconicoPlaylistIE(InfoExtractor):
_VALID_URL = r'https?://www\.nicovideo\.jp/mylist/(?P<id>\d+)'
_TEST = {
'url': 'http://www.nicovideo.jp/mylist/27411728',
'info_dict': {
'id': '27411728',
'title': 'AKB48のオールナイトニッポン',
},
'playlist_mincount': 225,
}
def _real_extract(self, url):
list_id = self._match_id(url)
webpage = self._download_webpage(url, list_id)
entries_json = self._search_regex(r'Mylist\.preload\(\d+, (\[.*\])\);',
webpage, 'entries')
entries = json.loads(entries_json)
entries = [{
'_type': 'url',
'ie_key': NiconicoIE.ie_key(),
'url': ('http://www.nicovideo.jp/watch/%s' %
entry['item_data']['video_id']),
} for entry in entries]
return {
'_type': 'playlist',
'title': self._search_regex(r'\s+name: "(.*?)"', webpage, 'title'),
'id': list_id,
'entries': entries,
}
|
unlicense
|
[
3,
2644,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
646,
2022,
199,
646,
2197,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
5819,
492,
334,
272,
8434,
63,
4078,
63,
1122,
12,
272,
8434,
63,
4078,
63,
1069,
12,
272,
8434,
63,
10290,
12,
199,
9,
199,
504,
2508,
1208,
492,
334,
272,
19783,
12,
272,
1109,
63,
269,
63,
3592,
12,
272,
2198,
63,
5553,
12,
272,
2198,
63,
4595,
15363,
12,
272,
14462,
63,
505,
12,
272,
6705,
63,
832,
12,
199,
9,
421,
199,
533,
653,
4677,
12802,
4332,
8,
18283,
304,
272,
15292,
63,
2339,
275,
283,
78,
4677,
12802,
7,
272,
15292,
63,
15119,
275,
283,
5692,
234,
5573,
112,
5692,
234,
5573,
112,
162,
234,
244,
8383,
120,
7,
339,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
8445,
331,
3722,
14,
11538,
15,
6821,
15,
3300,
11583,
7507,
1046,
297,
267,
283,
1064,
21,
356,
283,
68,
17,
65,
2194,
67,
2036,
1789,
69,
18,
70,
29151,
3933,
67,
2824,
69,
25481,
19036,
70,
25,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
3300,
11583,
7507,
1046,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
7279,
4779,
346,
699,
324,
9745,
297,
288,
283,
13671,
356,
283,
502,
20661,
11552,
1644,
614,
297,
288,
283,
13671,
63,
344,
356,
283,
12442,
1349,
1165,
297,
288,
283,
5064,
63,
602,
356,
283,
1797,
2192,
4288,
297,
288,
283,
3954,
356,
413,
13846,
1085,
1465,
2789,
12,
288,
283,
1802,
356,
8189,
67,
9,
4248,
9079,
12,
699,
24912,
2752,
1182,
20732,
14,
5076,
27954,
66,
324,
9745,
14,
1308,
297,
288,
283,
5553,
356,
9404,
12,
267,
1660,
272,
1660,
469,
267,
327,
3814,
13557,
543,
436,
1928,
6235,
787,
3365,
12,
880,
19413,
267,
327,
314,
6128,
21,
901,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
8445,
331,
3722,
14,
11538,
15,
6821,
15,
10756,
1079,
1398,
772,
2010,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
10756,
1079,
1398,
772,
2010,
297,
288,
283,
832,
356,
283,
20426,
297,
288,
283,
1213,
356,
283,
12805,
239,
166,
238,
95,
166,
254,
112,
5692,
104,
23488,
12805,
240,
36,
554,
641,
5898,
12805,
239,
5573,
104,
5692,
104,
5573,
117,
5692,
233,
29910,
12805,
240,
11066,
18,
12389,
288,
283,
1802,
356,
283,
1064,
21,
26,
29114,
70,
14045,
68,
17718,
709,
66,
19,
66,
1081,
69,
16,
70,
1196,
1355,
525,
16,
70,
2010,
297,
288,
283,
13671,
356,
283,
5573,
233,
5573,
230,
28075,
4197,
254,
297,
288,
283,
13671,
63,
344,
356,
283,
1085,
2564,
28656,
297,
288,
283,
5064,
63,
602,
356,
283,
1797,
6785,
1398,
297,
288,
283,
3954,
356,
4944,
966,
1690,
1427,
975,
12,
288,
283,
5553,
356,
499,
1643,
12,
267,
1660,
272,
1660,
469,
267,
327,
283,
3722,
3495,
1325,
365,
11584,
465,
298,
6062,
2,
267,
327,
6128,
21,
365,
625,
11989,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
8445,
331,
3722,
14,
11538,
15,
6821,
15,
3300,
9943,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
3300,
9943,
297,
288,
283,
832,
356,
283,
5187,
63,
3722,
297,
288,
283,
1802,
356,
283,
6062,
297,
288,
283,
1213,
356,
283,
5692,
232,
5692,
103,
4197,
231,
5573,
225,
5573,
242,
5573,
102,
31520,
17670,
5692,
233,
29910,
25238,
106,
19,
165,
103,
110,
12805,
235,
22639,
119,
9077,
100,
25238,
106,
19,
22737,
15771,
110,
6923,
106,
15280,
225,
12805,
236,
8454,
251,
27284,
27035,
102,
8454,
253,
297,
288,
283,
5064,
63,
602,
356,
283,
9488,
713,
1194,
297,
288,
283,
3954,
356,
26497,
2426,
1465,
13462,
12,
221,
327,
4913,
901,
965,
3365,
574,
340,
10367,
315,
288,
283,
5553,
356,
20398,
12,
267,
1660,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
8445,
331,
3722,
14,
11538,
15,
6821,
15,
1152,
18,
8306,
1082,
1690,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
969,
1299,
713,
1020,
1153,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
12805,
239,
25238,
106,
17,
22234,
12805,
240,
19662,
2090,
5573,
96,
5692,
234,
5692,
95,
5692,
256,
5692,
254,
5692,
226,
5573,
108,
25111,
221,
5692,
103,
5692,
245,
5692,
103,
26873,
5692,
245,
8454,
224,
172,
122,
253,
14741,
4197,
253,
4197,
231,
5573,
233,
16065,
598,
285,
848,
172,
122,
253,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
66,
1465,
68,
8731,
2501,
16,
556,
2481,
68,
19,
67,
24,
12442,
69,
25,
70,
24,
66,
17538,
2177,
17,
297,
288,
283,
3954,
356,
4944,
1299,
2426,
23781,
12,
288,
283,
5064,
63,
602,
356,
283,
7280,
614,
966,
297,
288,
283,
13671,
356,
283,
5573,
96,
5692,
234,
5692,
95,
5692,
256,
5692,
224,
5692,
97,
23488,
5692,
236,
29910,
297,
288,
283,
13671,
63,
344,
356,
283,
16683,
297,
267,
789,
272,
14877,
339,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
32327,
7817,
20316,
8445,
331,
3722,
4537,
11538,
15,
6821,
9448,
48,
28,
344,
30,
25060,
65,
13,
90,
8194,
18,
1552,
26736,
16,
13,
25,
29716,
272,
485,
7278,
8205,
63,
20890,
275,
283,
78,
4677,
12802,
7,
272,
327,
14703,
3775,
314,
3224,
3422,
1202,
6299,
370,
5235,
3991,
272,
485,
22923,
6989,
275,
756,
339,
347,
485,
3093,
63,
8489,
8,
277,
304,
267,
291,
423,
2886,
342,
339,
347,
485,
2886,
8,
277,
304,
267,
334,
2473,
12,
2505,
9,
275,
291,
423,
362,
63,
2886,
63,
815,
342,
267,
327,
3091,
6299,
370,
506,
10585,
267,
340,
440,
3434,
26,
288,
372,
715,
398,
327,
5297,
315,
267,
4676,
63,
964,
63,
16144,
275,
469,
288,
283,
1198,
356,
3434,
12,
288,
283,
2060,
356,
2505,
12,
267,
789,
267,
327,
7905,
370,
9094,
13,
24,
627,
5182,
10,
16511,
2952,
2018,
499,
14,
88,
1159,
16511,
267,
327,
2468,
9246,
641,
2649
] |
[
2644,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
646,
2022,
199,
646,
2197,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
5819,
492,
334,
272,
8434,
63,
4078,
63,
1122,
12,
272,
8434,
63,
4078,
63,
1069,
12,
272,
8434,
63,
10290,
12,
199,
9,
199,
504,
2508,
1208,
492,
334,
272,
19783,
12,
272,
1109,
63,
269,
63,
3592,
12,
272,
2198,
63,
5553,
12,
272,
2198,
63,
4595,
15363,
12,
272,
14462,
63,
505,
12,
272,
6705,
63,
832,
12,
199,
9,
421,
199,
533,
653,
4677,
12802,
4332,
8,
18283,
304,
272,
15292,
63,
2339,
275,
283,
78,
4677,
12802,
7,
272,
15292,
63,
15119,
275,
283,
5692,
234,
5573,
112,
5692,
234,
5573,
112,
162,
234,
244,
8383,
120,
7,
339,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
8445,
331,
3722,
14,
11538,
15,
6821,
15,
3300,
11583,
7507,
1046,
297,
267,
283,
1064,
21,
356,
283,
68,
17,
65,
2194,
67,
2036,
1789,
69,
18,
70,
29151,
3933,
67,
2824,
69,
25481,
19036,
70,
25,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
3300,
11583,
7507,
1046,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
7279,
4779,
346,
699,
324,
9745,
297,
288,
283,
13671,
356,
283,
502,
20661,
11552,
1644,
614,
297,
288,
283,
13671,
63,
344,
356,
283,
12442,
1349,
1165,
297,
288,
283,
5064,
63,
602,
356,
283,
1797,
2192,
4288,
297,
288,
283,
3954,
356,
413,
13846,
1085,
1465,
2789,
12,
288,
283,
1802,
356,
8189,
67,
9,
4248,
9079,
12,
699,
24912,
2752,
1182,
20732,
14,
5076,
27954,
66,
324,
9745,
14,
1308,
297,
288,
283,
5553,
356,
9404,
12,
267,
1660,
272,
1660,
469,
267,
327,
3814,
13557,
543,
436,
1928,
6235,
787,
3365,
12,
880,
19413,
267,
327,
314,
6128,
21,
901,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
8445,
331,
3722,
14,
11538,
15,
6821,
15,
10756,
1079,
1398,
772,
2010,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
10756,
1079,
1398,
772,
2010,
297,
288,
283,
832,
356,
283,
20426,
297,
288,
283,
1213,
356,
283,
12805,
239,
166,
238,
95,
166,
254,
112,
5692,
104,
23488,
12805,
240,
36,
554,
641,
5898,
12805,
239,
5573,
104,
5692,
104,
5573,
117,
5692,
233,
29910,
12805,
240,
11066,
18,
12389,
288,
283,
1802,
356,
283,
1064,
21,
26,
29114,
70,
14045,
68,
17718,
709,
66,
19,
66,
1081,
69,
16,
70,
1196,
1355,
525,
16,
70,
2010,
297,
288,
283,
13671,
356,
283,
5573,
233,
5573,
230,
28075,
4197,
254,
297,
288,
283,
13671,
63,
344,
356,
283,
1085,
2564,
28656,
297,
288,
283,
5064,
63,
602,
356,
283,
1797,
6785,
1398,
297,
288,
283,
3954,
356,
4944,
966,
1690,
1427,
975,
12,
288,
283,
5553,
356,
499,
1643,
12,
267,
1660,
272,
1660,
469,
267,
327,
283,
3722,
3495,
1325,
365,
11584,
465,
298,
6062,
2,
267,
327,
6128,
21,
365,
625,
11989,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
8445,
331,
3722,
14,
11538,
15,
6821,
15,
3300,
9943,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
3300,
9943,
297,
288,
283,
832,
356,
283,
5187,
63,
3722,
297,
288,
283,
1802,
356,
283,
6062,
297,
288,
283,
1213,
356,
283,
5692,
232,
5692,
103,
4197,
231,
5573,
225,
5573,
242,
5573,
102,
31520,
17670,
5692,
233,
29910,
25238,
106,
19,
165,
103,
110,
12805,
235,
22639,
119,
9077,
100,
25238,
106,
19,
22737,
15771,
110,
6923,
106,
15280,
225,
12805,
236,
8454,
251,
27284,
27035,
102,
8454,
253,
297,
288,
283,
5064,
63,
602,
356,
283,
9488,
713,
1194,
297,
288,
283,
3954,
356,
26497,
2426,
1465,
13462,
12,
221,
327,
4913,
901,
965,
3365,
574,
340,
10367,
315,
288,
283,
5553,
356,
20398,
12,
267,
1660,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
8445,
331,
3722,
14,
11538,
15,
6821,
15,
1152,
18,
8306,
1082,
1690,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
969,
1299,
713,
1020,
1153,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
12805,
239,
25238,
106,
17,
22234,
12805,
240,
19662,
2090,
5573,
96,
5692,
234,
5692,
95,
5692,
256,
5692,
254,
5692,
226,
5573,
108,
25111,
221,
5692,
103,
5692,
245,
5692,
103,
26873,
5692,
245,
8454,
224,
172,
122,
253,
14741,
4197,
253,
4197,
231,
5573,
233,
16065,
598,
285,
848,
172,
122,
253,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
66,
1465,
68,
8731,
2501,
16,
556,
2481,
68,
19,
67,
24,
12442,
69,
25,
70,
24,
66,
17538,
2177,
17,
297,
288,
283,
3954,
356,
4944,
1299,
2426,
23781,
12,
288,
283,
5064,
63,
602,
356,
283,
7280,
614,
966,
297,
288,
283,
13671,
356,
283,
5573,
96,
5692,
234,
5692,
95,
5692,
256,
5692,
224,
5692,
97,
23488,
5692,
236,
29910,
297,
288,
283,
13671,
63,
344,
356,
283,
16683,
297,
267,
789,
272,
14877,
339,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
32327,
7817,
20316,
8445,
331,
3722,
4537,
11538,
15,
6821,
9448,
48,
28,
344,
30,
25060,
65,
13,
90,
8194,
18,
1552,
26736,
16,
13,
25,
29716,
272,
485,
7278,
8205,
63,
20890,
275,
283,
78,
4677,
12802,
7,
272,
327,
14703,
3775,
314,
3224,
3422,
1202,
6299,
370,
5235,
3991,
272,
485,
22923,
6989,
275,
756,
339,
347,
485,
3093,
63,
8489,
8,
277,
304,
267,
291,
423,
2886,
342,
339,
347,
485,
2886,
8,
277,
304,
267,
334,
2473,
12,
2505,
9,
275,
291,
423,
362,
63,
2886,
63,
815,
342,
267,
327,
3091,
6299,
370,
506,
10585,
267,
340,
440,
3434,
26,
288,
372,
715,
398,
327,
5297,
315,
267,
4676,
63,
964,
63,
16144,
275,
469,
288,
283,
1198,
356,
3434,
12,
288,
283,
2060,
356,
2505,
12,
267,
789,
267,
327,
7905,
370,
9094,
13,
24,
627,
5182,
10,
16511,
2952,
2018,
499,
14,
88,
1159,
16511,
267,
327,
2468,
9246,
641,
2649,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
poljeff/odoo
|
addons/account/wizard/account_invoice_state.py
|
340
|
2875
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import osv
from openerp.tools.translate import _
class account_invoice_confirm(osv.osv_memory):
"""
This wizard will confirm the all the selected draft invoices
"""
_name = "account.invoice.confirm"
_description = "Confirm the selected invoices"
def invoice_confirm(self, cr, uid, ids, context=None):
if context is None:
context = {}
active_ids = context.get('active_ids', []) or []
proxy = self.pool['account.invoice']
for record in proxy.browse(cr, uid, active_ids, context=context):
if record.state not in ('draft', 'proforma', 'proforma2'):
raise osv.except_osv(_('Warning!'), _("Selected invoice(s) cannot be confirmed as they are not in 'Draft' or 'Pro-Forma' state."))
record.signal_workflow('invoice_open')
return {'type': 'ir.actions.act_window_close'}
class account_invoice_cancel(osv.osv_memory):
"""
This wizard will cancel the all the selected invoices.
If in the journal, the option allow cancelling entry is not selected then it will give warning message.
"""
_name = "account.invoice.cancel"
_description = "Cancel the Selected Invoices"
def invoice_cancel(self, cr, uid, ids, context=None):
if context is None:
context = {}
proxy = self.pool['account.invoice']
active_ids = context.get('active_ids', []) or []
for record in proxy.browse(cr, uid, active_ids, context=context):
if record.state in ('cancel','paid'):
raise osv.except_osv(_('Warning!'), _("Selected invoice(s) cannot be cancelled as they are already in 'Cancelled' or 'Done' state."))
record.signal_workflow('invoice_cancel')
return {'type': 'ir.actions.act_window_close'}
# 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,
504,
5166,
14,
4795,
492,
9506,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
199,
533,
2933,
63,
5404,
63,
9548,
8,
4795,
14,
4795,
63,
4844,
304,
272,
408,
272,
961,
12262,
911,
12679,
314,
1006,
314,
4895,
11872,
26175,
272,
408,
339,
485,
354,
275,
298,
2048,
14,
5404,
14,
9548,
2,
272,
485,
1802,
275,
298,
26857,
314,
4895,
26175,
2,
339,
347,
8485,
63,
9548,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
4702,
63,
1580,
275,
1067,
14,
362,
360,
2682,
63,
1580,
297,
3073,
503,
942,
398,
4566,
275,
291,
14,
2293,
459,
2048,
14,
5404,
418,
267,
367,
2777,
315,
4566,
14,
4570,
8,
1556,
12,
1747,
12,
4702,
63,
1580,
12,
1067,
29,
1100,
304,
288,
340,
2777,
14,
929,
440,
315,
661,
7185,
297,
283,
496,
10928,
297,
283,
496,
10928,
18,
735,
355,
746,
9506,
14,
2590,
63,
4795,
6723,
3849,
15659,
3824,
12461,
8485,
8,
83,
9,
3913,
506,
22763,
465,
2985,
787,
440,
315,
283,
18332,
7,
503,
283,
919,
13,
1858,
391,
7,
1174,
13853,
288,
2777,
14,
4653,
63,
8856,
360,
5404,
63,
1490,
358,
10631,
372,
791,
466,
356,
283,
723,
14,
3723,
14,
2442,
63,
3806,
63,
1600,
936,
421,
199,
533,
2933,
63,
5404,
63,
6406,
8,
4795,
14,
4795,
63,
4844,
304,
272,
408,
272,
961,
12262,
911,
9311,
314,
1006,
314,
4895,
26175,
14,
272,
982,
315,
314,
9605,
12,
314,
945,
2040,
286,
554,
10564,
2397,
365,
440,
4895,
2066,
652,
911,
8120,
5721,
1245,
14,
272,
408,
339,
485,
354,
275,
298,
2048,
14,
5404,
14,
6406,
2,
272,
485,
1802,
275,
298,
9083,
314,
3240,
2820,
1010,
16687,
2,
339,
347,
8485,
63,
6406,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
4566,
275,
291,
14,
2293,
459,
2048,
14,
5404,
418,
267,
4702,
63,
1580,
275,
1067,
14,
362,
360,
2682,
63,
1580,
297,
3073,
503,
942,
398,
367,
2777,
315,
4566,
14,
4570,
8,
1556,
12,
1747,
12,
4702,
63,
1580,
12,
1067,
29,
1100,
304,
288,
340,
2777,
14,
929,
315,
661,
6406,
1673,
16555,
735,
355,
746,
9506,
14,
2590,
63,
4795,
6723,
3849,
15659,
3824,
12461,
8485,
8,
83,
9,
3913,
506,
20115,
465,
2985,
787,
2575,
315,
283,
22127,
7,
503,
283,
10759,
7,
1174,
13853,
288,
2777,
14,
4653,
63,
8856,
360,
5404,
63,
6406,
358,
267,
372,
791,
466,
356,
283,
723,
14,
3723,
14,
2442,
63,
3806,
63,
1600,
936,
421,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
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,
504,
5166,
14,
4795,
492,
9506,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
199,
533,
2933,
63,
5404,
63,
9548,
8,
4795,
14,
4795,
63,
4844,
304,
272,
408,
272,
961,
12262,
911,
12679,
314,
1006,
314,
4895,
11872,
26175,
272,
408,
339,
485,
354,
275,
298,
2048,
14,
5404,
14,
9548,
2,
272,
485,
1802,
275,
298,
26857,
314,
4895,
26175,
2,
339,
347,
8485,
63,
9548,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
4702,
63,
1580,
275,
1067,
14,
362,
360,
2682,
63,
1580,
297,
3073,
503,
942,
398,
4566,
275,
291,
14,
2293,
459,
2048,
14,
5404,
418,
267,
367,
2777,
315,
4566,
14,
4570,
8,
1556,
12,
1747,
12,
4702,
63,
1580,
12,
1067,
29,
1100,
304,
288,
340,
2777,
14,
929,
440,
315,
661,
7185,
297,
283,
496,
10928,
297,
283,
496,
10928,
18,
735,
355,
746,
9506,
14,
2590,
63,
4795,
6723,
3849,
15659,
3824,
12461,
8485,
8,
83,
9,
3913,
506,
22763,
465,
2985,
787,
440,
315,
283,
18332,
7,
503,
283,
919,
13,
1858,
391,
7,
1174,
13853,
288,
2777,
14,
4653,
63,
8856,
360,
5404,
63,
1490,
358,
10631,
372,
791,
466,
356,
283,
723,
14,
3723,
14,
2442,
63,
3806,
63,
1600,
936,
421,
199,
533,
2933,
63,
5404,
63,
6406,
8,
4795,
14,
4795,
63,
4844,
304,
272,
408,
272,
961,
12262,
911,
9311,
314,
1006,
314,
4895,
26175,
14,
272,
982,
315,
314,
9605,
12,
314,
945,
2040,
286,
554,
10564,
2397,
365,
440,
4895,
2066,
652,
911,
8120,
5721,
1245,
14,
272,
408,
339,
485,
354,
275,
298,
2048,
14,
5404,
14,
6406,
2,
272,
485,
1802,
275,
298,
9083,
314,
3240,
2820,
1010,
16687,
2,
339,
347,
8485,
63,
6406,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
4566,
275,
291,
14,
2293,
459,
2048,
14,
5404,
418,
267,
4702,
63,
1580,
275,
1067,
14,
362,
360,
2682,
63,
1580,
297,
3073,
503,
942,
398,
367,
2777,
315,
4566,
14,
4570,
8,
1556,
12,
1747,
12,
4702,
63,
1580,
12,
1067,
29,
1100,
304,
288,
340,
2777,
14,
929,
315,
661,
6406,
1673,
16555,
735,
355,
746,
9506,
14,
2590,
63,
4795,
6723,
3849,
15659,
3824,
12461,
8485,
8,
83,
9,
3913,
506,
20115,
465,
2985,
787,
2575,
315,
283,
22127,
7,
503,
283,
10759,
7,
1174,
13853,
288,
2777,
14,
4653,
63,
8856,
360,
5404,
63,
6406,
358,
267,
372,
791,
466,
356,
283,
723,
14,
3723,
14,
2442,
63,
3806,
63,
1600,
936,
421,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ioanpocol/superdesk-core
|
apps/keywords/service.py
|
6
|
1080
|
# -*- coding: utf-8; -*-
#
# This file is part of Superdesk.
#
# Copyright 2013, 2014 Sourcefabric z.u. and contributors.
#
# For the full copyright and license information, please see the
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license
from superdesk.errors import SuperdeskApiError
from superdesk.services import BaseService
class KeywordsService(BaseService):
"""Analyze the text and extract the keywords"""
def __init__(self, datasource=None, backend=None):
super().__init__(datasource, backend)
self.provider = None
def create(self, docs, **kwargs):
if not self.provider:
raise SuperdeskApiError.internalError('Not set a keywords provider')
try:
ids = []
for doc in docs:
doc['keywords'] = self.provider.get_keywords(doc.get('text', ''))
ids.append(len(ids))
return ids
except Exception as ex:
raise SuperdeskApiError.internalError(str(ex), exception=ex)
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
27,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
17897,
10368,
14,
199,
3,
199,
3,
1898,
6171,
12,
6927,
5800,
4991,
1315,
14,
85,
14,
436,
8417,
14,
199,
3,
199,
3,
2104,
314,
2615,
4248,
436,
4190,
2556,
12,
8749,
1937,
314,
199,
3,
10610,
436,
5113,
1584,
1854,
543,
642,
1350,
1233,
12,
503,
199,
3,
737,
4178,
921,
1544,
14,
1365,
4991,
14,
1308,
15,
4792,
10368,
15,
1682,
199,
199,
504,
1613,
10368,
14,
2550,
492,
17897,
10368,
7394,
547,
199,
504,
1613,
10368,
14,
5950,
492,
3523,
3167,
421,
199,
533,
2606,
3148,
3167,
8,
1563,
3167,
304,
272,
408,
8014,
806,
314,
1318,
436,
5536,
314,
7681,
624,
339,
347,
636,
826,
721,
277,
12,
29289,
29,
403,
12,
4865,
29,
403,
304,
267,
1613,
11027,
826,
721,
21208,
12,
4865,
9,
267,
291,
14,
3780,
275,
488,
339,
347,
1218,
8,
277,
12,
9149,
12,
1011,
958,
304,
267,
340,
440,
291,
14,
3780,
26,
288,
746,
17897,
10368,
7394,
547,
14,
4672,
547,
360,
1763,
663,
282,
7681,
5022,
358,
398,
862,
26,
288,
2762,
275,
942,
288,
367,
1382,
315,
9149,
26,
355,
1382,
459,
7511,
418,
275,
291,
14,
3780,
14,
362,
63,
7511,
8,
1301,
14,
362,
360,
505,
297,
12381,
355,
2762,
14,
740,
8,
552,
8,
1580,
430,
288,
372,
2762,
267,
871,
2186,
465,
444,
26,
288,
746,
17897,
10368,
7394,
547,
14,
4672,
547,
8,
495,
8,
476,
395,
1919,
29,
476,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
27,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
17897,
10368,
14,
199,
3,
199,
3,
1898,
6171,
12,
6927,
5800,
4991,
1315,
14,
85,
14,
436,
8417,
14,
199,
3,
199,
3,
2104,
314,
2615,
4248,
436,
4190,
2556,
12,
8749,
1937,
314,
199,
3,
10610,
436,
5113,
1584,
1854,
543,
642,
1350,
1233,
12,
503,
199,
3,
737,
4178,
921,
1544,
14,
1365,
4991,
14,
1308,
15,
4792,
10368,
15,
1682,
199,
199,
504,
1613,
10368,
14,
2550,
492,
17897,
10368,
7394,
547,
199,
504,
1613,
10368,
14,
5950,
492,
3523,
3167,
421,
199,
533,
2606,
3148,
3167,
8,
1563,
3167,
304,
272,
408,
8014,
806,
314,
1318,
436,
5536,
314,
7681,
624,
339,
347,
636,
826,
721,
277,
12,
29289,
29,
403,
12,
4865,
29,
403,
304,
267,
1613,
11027,
826,
721,
21208,
12,
4865,
9,
267,
291,
14,
3780,
275,
488,
339,
347,
1218,
8,
277,
12,
9149,
12,
1011,
958,
304,
267,
340,
440,
291,
14,
3780,
26,
288,
746,
17897,
10368,
7394,
547,
14,
4672,
547,
360,
1763,
663,
282,
7681,
5022,
358,
398,
862,
26,
288,
2762,
275,
942,
288,
367,
1382,
315,
9149,
26,
355,
1382,
459,
7511,
418,
275,
291,
14,
3780,
14,
362,
63,
7511,
8,
1301,
14,
362,
360,
505,
297,
12381,
355,
2762,
14,
740,
8,
552,
8,
1580,
430,
288,
372,
2762,
267,
871,
2186,
465,
444,
26,
288,
746,
17897,
10368,
7394,
547,
14,
4672,
547,
8,
495,
8,
476,
395,
1919,
29,
476,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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|
3
|
1049
|
# -*- coding: utf-8 -*-
# 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.
#
from collections import OrderedDict
from typing import Dict, Type
from .base import AdGroupLabelServiceTransport
from .grpc import AdGroupLabelServiceGrpcTransport
# Compile a registry of transports.
_transport_registry = OrderedDict() # type: Dict[str, Type[AdGroupLabelServiceTransport]]
_transport_registry['grpc'] = AdGroupLabelServiceGrpcTransport
__all__ = (
'AdGroupLabelServiceTransport',
'AdGroupLabelServiceGrpcTransport',
)
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
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,
3,
199,
504,
5055,
492,
8773,
199,
504,
14090,
492,
7448,
12,
2434,
199,
199,
504,
1275,
1095,
492,
4431,
2448,
4314,
3167,
7836,
199,
504,
1275,
15391,
492,
4431,
2448,
4314,
3167,
39,
4354,
7836,
421,
199,
3,
24562,
282,
7086,
402,
7773,
83,
14,
199,
63,
5545,
63,
5189,
275,
8773,
342,
221,
327,
730,
26,
7448,
59,
495,
12,
2434,
59,
2767,
2448,
4314,
3167,
7836,
2677,
199,
63,
5545,
63,
5189,
459,
15391,
418,
275,
4431,
2448,
4314,
3167,
39,
4354,
7836,
421,
199,
363,
452,
363,
275,
334,
272,
283,
2767,
2448,
4314,
3167,
7836,
297,
272,
283,
2767,
2448,
4314,
3167,
39,
4354,
7836,
297,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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,
3,
199,
504,
5055,
492,
8773,
199,
504,
14090,
492,
7448,
12,
2434,
199,
199,
504,
1275,
1095,
492,
4431,
2448,
4314,
3167,
7836,
199,
504,
1275,
15391,
492,
4431,
2448,
4314,
3167,
39,
4354,
7836,
421,
199,
3,
24562,
282,
7086,
402,
7773,
83,
14,
199,
63,
5545,
63,
5189,
275,
8773,
342,
221,
327,
730,
26,
7448,
59,
495,
12,
2434,
59,
2767,
2448,
4314,
3167,
7836,
2677,
199,
63,
5545,
63,
5189,
459,
15391,
418,
275,
4431,
2448,
4314,
3167,
39,
4354,
7836,
421,
199,
363,
452,
363,
275,
334,
272,
283,
2767,
2448,
4314,
3167,
7836,
297,
272,
283,
2767,
2448,
4314,
3167,
39,
4354,
7836,
297,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
MiltosD/CEFELRC
|
lib/python2.7/site-packages/django/utils/daemonize.py
|
452
|
1907
|
import os
import sys
if os.name == 'posix':
def become_daemon(our_home_dir='.', out_log='/dev/null',
err_log='/dev/null', umask=022):
"Robustly turn into a UNIX daemon, running in our_home_dir."
# First fork
try:
if os.fork() > 0:
sys.exit(0) # kill off parent
except OSError, e:
sys.stderr.write("fork #1 failed: (%d) %s\n" % (e.errno, e.strerror))
sys.exit(1)
os.setsid()
os.chdir(our_home_dir)
os.umask(umask)
# Second fork
try:
if os.fork() > 0:
os._exit(0)
except OSError, e:
sys.stderr.write("fork #2 failed: (%d) %s\n" % (e.errno, e.strerror))
os._exit(1)
si = open('/dev/null', 'r')
so = open(out_log, 'a+', 0)
se = open(err_log, 'a+', 0)
os.dup2(si.fileno(), sys.stdin.fileno())
os.dup2(so.fileno(), sys.stdout.fileno())
os.dup2(se.fileno(), sys.stderr.fileno())
# Set custom file descriptors so that they get proper buffering.
sys.stdout, sys.stderr = so, se
else:
def become_daemon(our_home_dir='.', out_log=None, err_log=None, umask=022):
"""
If we're not running under a POSIX system, just simulate the daemon
mode by doing redirections and directory changing.
"""
os.chdir(our_home_dir)
os.umask(umask)
sys.stdin.close()
sys.stdout.close()
sys.stderr.close()
if err_log:
sys.stderr = open(err_log, 'a', 0)
else:
sys.stderr = NullDevice()
if out_log:
sys.stdout = open(out_log, 'a', 0)
else:
sys.stdout = NullDevice()
class NullDevice:
"A writeable object that writes to nowhere -- like /dev/null."
def write(self, s):
pass
|
bsd-3-clause
|
[
646,
747,
199,
646,
984,
199,
199,
692,
747,
14,
354,
508,
283,
9228,
356,
272,
347,
8649,
63,
10824,
8,
567,
63,
4219,
63,
694,
534,
3130,
734,
63,
793,
8805,
2374,
15,
2307,
297,
1993,
2329,
63,
793,
8805,
2374,
15,
2307,
297,
29812,
29,
16348,
304,
267,
298,
3863,
15549,
590,
7485,
1901,
282,
22242,
11128,
12,
3879,
315,
4154,
63,
4219,
63,
694,
2122,
267,
327,
7758,
14926,
267,
862,
26,
288,
340,
747,
14,
11796,
342,
690,
378,
26,
355,
984,
14,
2224,
8,
16,
9,
258,
327,
14561,
2331,
1676,
267,
871,
6440,
12,
325,
26,
288,
984,
14,
3083,
14,
952,
480,
11796,
327,
17,
3405,
26,
4366,
68,
9,
450,
83,
60,
78,
2,
450,
334,
69,
14,
7931,
12,
325,
14,
20395,
430,
288,
984,
14,
2224,
8,
17,
9,
267,
747,
14,
409,
4148,
342,
267,
747,
14,
8563,
8,
567,
63,
4219,
63,
694,
9,
267,
747,
14,
18315,
8,
18315,
9,
398,
327,
16707,
14926,
267,
862,
26,
288,
340,
747,
14,
11796,
342,
690,
378,
26,
355,
747,
423,
2224,
8,
16,
9,
267,
871,
6440,
12,
325,
26,
288,
984,
14,
3083,
14,
952,
480,
11796,
327,
18,
3405,
26,
4366,
68,
9,
450,
83,
60,
78,
2,
450,
334,
69,
14,
7931,
12,
325,
14,
20395,
430,
288,
747,
423,
2224,
8,
17,
9,
398,
13877,
275,
1551,
2336,
2374,
15,
2307,
297,
283,
82,
358,
267,
880,
275,
1551,
8,
548,
63,
793,
12,
283,
65,
7386,
378,
9,
267,
542,
275,
1551,
8,
1508,
63,
793,
12,
283,
65,
7386,
378,
9,
267,
747,
14,
11048,
18,
8,
338,
14,
9843,
1062,
984,
14,
6626,
14,
9843,
1012,
267,
747,
14,
11048,
18,
8,
1152,
14,
9843,
1062,
984,
14,
2703,
14,
9843,
1012,
267,
747,
14,
11048,
18,
8,
261,
14,
9843,
1062,
984,
14,
3083,
14,
9843,
1012,
267,
327,
2494,
3537,
570,
15428,
880,
626,
2985,
664,
5576,
21033,
14,
267,
984,
14,
2703,
12,
984,
14,
3083,
275,
880,
12,
542,
199,
2836,
26,
272,
347,
8649,
63,
10824,
8,
567,
63,
4219,
63,
694,
534,
3130,
734,
63,
793,
29,
403,
12,
2329,
63,
793,
29,
403,
12,
29812,
29,
16348,
304,
267,
408,
267,
982,
781,
3984,
440,
3879,
1334,
282,
18169,
2656,
12,
2951,
20577,
314,
11128,
267,
818,
701,
9689,
295,
27917,
436,
2082,
13729,
14,
267,
408,
267,
747,
14,
8563,
8,
567,
63,
4219,
63,
694,
9,
267,
747,
14,
18315,
8,
18315,
9,
267,
984,
14,
6626,
14,
1600,
342,
267,
984,
14,
2703,
14,
1600,
342,
267,
984,
14,
3083,
14,
1600,
342,
267,
340,
2329,
63,
793,
26,
288,
984,
14,
3083,
275,
1551,
8,
1508,
63,
793,
12,
283,
65,
297,
378,
9,
267,
587,
26,
288,
984,
14,
3083,
275,
12119,
2510,
342,
267,
340,
734,
63,
793,
26,
288,
984,
14,
2703,
275,
1551,
8,
548,
63,
793,
12,
283,
65,
297,
378,
9,
267,
587,
26,
288,
984,
14,
2703,
275,
12119,
2510,
342,
339,
1021,
12119,
2510,
26,
267,
298,
33,
2218,
461,
909,
626,
14511,
370,
3063,
1681,
1553,
2839,
1182,
2374,
15,
2307,
2122,
267,
347,
2218,
8,
277,
12,
308,
304,
288,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
747,
199,
646,
984,
199,
199,
692,
747,
14,
354,
508,
283,
9228,
356,
272,
347,
8649,
63,
10824,
8,
567,
63,
4219,
63,
694,
534,
3130,
734,
63,
793,
8805,
2374,
15,
2307,
297,
1993,
2329,
63,
793,
8805,
2374,
15,
2307,
297,
29812,
29,
16348,
304,
267,
298,
3863,
15549,
590,
7485,
1901,
282,
22242,
11128,
12,
3879,
315,
4154,
63,
4219,
63,
694,
2122,
267,
327,
7758,
14926,
267,
862,
26,
288,
340,
747,
14,
11796,
342,
690,
378,
26,
355,
984,
14,
2224,
8,
16,
9,
258,
327,
14561,
2331,
1676,
267,
871,
6440,
12,
325,
26,
288,
984,
14,
3083,
14,
952,
480,
11796,
327,
17,
3405,
26,
4366,
68,
9,
450,
83,
60,
78,
2,
450,
334,
69,
14,
7931,
12,
325,
14,
20395,
430,
288,
984,
14,
2224,
8,
17,
9,
267,
747,
14,
409,
4148,
342,
267,
747,
14,
8563,
8,
567,
63,
4219,
63,
694,
9,
267,
747,
14,
18315,
8,
18315,
9,
398,
327,
16707,
14926,
267,
862,
26,
288,
340,
747,
14,
11796,
342,
690,
378,
26,
355,
747,
423,
2224,
8,
16,
9,
267,
871,
6440,
12,
325,
26,
288,
984,
14,
3083,
14,
952,
480,
11796,
327,
18,
3405,
26,
4366,
68,
9,
450,
83,
60,
78,
2,
450,
334,
69,
14,
7931,
12,
325,
14,
20395,
430,
288,
747,
423,
2224,
8,
17,
9,
398,
13877,
275,
1551,
2336,
2374,
15,
2307,
297,
283,
82,
358,
267,
880,
275,
1551,
8,
548,
63,
793,
12,
283,
65,
7386,
378,
9,
267,
542,
275,
1551,
8,
1508,
63,
793,
12,
283,
65,
7386,
378,
9,
267,
747,
14,
11048,
18,
8,
338,
14,
9843,
1062,
984,
14,
6626,
14,
9843,
1012,
267,
747,
14,
11048,
18,
8,
1152,
14,
9843,
1062,
984,
14,
2703,
14,
9843,
1012,
267,
747,
14,
11048,
18,
8,
261,
14,
9843,
1062,
984,
14,
3083,
14,
9843,
1012,
267,
327,
2494,
3537,
570,
15428,
880,
626,
2985,
664,
5576,
21033,
14,
267,
984,
14,
2703,
12,
984,
14,
3083,
275,
880,
12,
542,
199,
2836,
26,
272,
347,
8649,
63,
10824,
8,
567,
63,
4219,
63,
694,
534,
3130,
734,
63,
793,
29,
403,
12,
2329,
63,
793,
29,
403,
12,
29812,
29,
16348,
304,
267,
408,
267,
982,
781,
3984,
440,
3879,
1334,
282,
18169,
2656,
12,
2951,
20577,
314,
11128,
267,
818,
701,
9689,
295,
27917,
436,
2082,
13729,
14,
267,
408,
267,
747,
14,
8563,
8,
567,
63,
4219,
63,
694,
9,
267,
747,
14,
18315,
8,
18315,
9,
267,
984,
14,
6626,
14,
1600,
342,
267,
984,
14,
2703,
14,
1600,
342,
267,
984,
14,
3083,
14,
1600,
342,
267,
340,
2329,
63,
793,
26,
288,
984,
14,
3083,
275,
1551,
8,
1508,
63,
793,
12,
283,
65,
297,
378,
9,
267,
587,
26,
288,
984,
14,
3083,
275,
12119,
2510,
342,
267,
340,
734,
63,
793,
26,
288,
984,
14,
2703,
275,
1551,
8,
548,
63,
793,
12,
283,
65,
297,
378,
9,
267,
587,
26,
288,
984,
14,
2703,
275,
12119,
2510,
342,
339,
1021,
12119,
2510,
26,
267,
298,
33,
2218,
461,
909,
626,
14511,
370,
3063,
1681,
1553,
2839,
1182,
2374,
15,
2307,
2122,
267,
347,
2218,
8,
277,
12,
308,
304,
288,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
JulyKikuAkita/PythonPrac
|
cs15211/SoupServings.py
|
1
|
5860
|
__source__ = 'https://leetcode.com/problems/soup-servings/'
# Time: O(N^2)
# Space: O(N^2)
#
# Description: Leetcode # 808. Soup Servings
#
# There are two types of soup: type A and type B.
# Initially we have N ml of each type of soup. There are four kinds of operations:
#
# Serve 100 ml of soup A and 0 ml of soup B
# Serve 75 ml of soup A and 25 ml of soup B
# Serve 50 ml of soup A and 50 ml of soup B
# Serve 25 ml of soup A and 75 ml of soup B
#
# When we serve some soup, we give it to someone and we no longer have it.
# Each turn, we will choose from the four operations with equal probability 0.25.
# If the remaining volume of soup is not enough to complete the operation,
# we will serve as much as we can.
# We stop once we no longer have some quantity of both types of soup.
#
# Note that we do not have the operation where all 100 ml's of soup B are used first.
#
# Return the probability that soup A will be empty first,
# plus half the probability that A and B become empty at the same time.
#
#
# Example:
# Input: N = 50
# Output: 0.625
# Explanation:
# If we choose the first two operations, A will become empty first. For the third operation,
# A and B will become empty at the same time. For the fourth operation, B will become empty first.
# So the total probability of A becoming empty first plus half the probability that
# A and B become empty at the same time, is 0.25 * (1 + 1 + 0.5 + 0) = 0.625.
#
# Notes:
#
# 0 <= N <= 10^9.
# Answers within 10^-6 of the true value will be accepted as correct.
#
import unittest
# 60ms 21.28%
class Solution(object):
def soupServings(self, N):
"""
:type N: int
:rtype: float
"""
Q, R = divmod(N, 25)
N = Q + (R > 0)
if N >= 500: return 1
memo = {}
def dp(x, y):
if (x, y) not in memo:
if x <= 0 or y <= 0:
ans = 0.5 if x<=0 and y<=0 else 1.0 if x<=0 else 0.0
else:
ans = 0.25 * (dp(x-4,y)+dp(x-3,y-1)+dp(x-2,y-2)+dp(x-1,y-3))
memo[x, y] = ans
return memo[x, y]
return dp(N, N)
class TestMethods(unittest.TestCase):
def test_Local(self):
self.assertEqual(1, 1)
if __name__ == '__main__':
unittest.main()
Java = '''
# Thought: https://leetcode.com/problems/soup-servings/solution/
#
Note: The most important hint in this problem for me is
"Answers within 10^-6 of the true value will be accepted as correct.".
And when I get timed out or runtime error with my DP,
I tried to print out results of each call for each N.
They are monotonically increasing, and getting closer and closer to 1.
If you print it out, you will observe that when it is as large as 5551
the gap between the result and 1 is less than 10^-6.
Approach #1: Dynamic Programming [Accepted]
Complexity Analysis
Time Complexity: O(1). (There exists a constant C such that the algorithm never performs more than C steps.)
Space Complexity: O(1) (There exists a constant C such that the algorithm never uses more than C space.)
# 7ms 56.04%
class Solution {
public double soupServings(int N) {
N = N / 25 + ( N % 25 > 0 ? 1: 0);
if (N > 500) return 1.0;
double[][] memo = new double[N + 1][N + 1];
for (int s = 0; s <= 2 * N; s++) {
for (int i = 0; i <= N; i++) {
int j = s - i;
if (j < 0 || j > N) continue;
double ans = 0.0;
if (i == 0) ans = 1.0;
if (i == 0 && j == 0) ans = 0.5;
if (i > 0 && j > 0) {
ans = 0.25 * (memo[M(i-4)][j] + memo[M(i-3)][M(j-1)] +
memo[M(i-2)][M(j-2)] + memo[M(i-1)][M(j-3)]);
}
memo[i][j] = ans;
}
}
return memo[N][N];
}
private int M(int x) {
return Math.max(0, x);
}
}
# DFS + pruning
# 7ms 56.04%
class Solution {
public double soupServings(int N) {
if (N > 5000) return 1.0; // see Note
return helper(N, N, new Double[N + 1][N + 1]);
}
private double helper(int A, int B, Double[][] memo) {
if (A <= 0 && B <= 0) return 0.5; // base case 1
if (A <= 0) return 1.0; // base case 2
if (B <= 0) return 0.0; // base case 3
if (memo[A][B] != null) return memo[A][B];
int[] serveA = {100, 75, 50, 25};
int[] serveB = {0, 25, 50, 75};
memo[A][B] = 0.0;
for (int i = 0; i < 4; i++) {
memo[A][B] += helper(A - serveA[i], B - serveB[i], memo);
}
return memo[A][B] *= 0.25;
}
}
# 2ms 100%
class Solution {
public double soupServings(int N) {
int n = N;
if (n >= 10000) {
return 1; // because you have 75% cost A more than B.
}
if (n % 25 != 0) {
n = n / 25 + 1;
} else {
n = n / 25;
}
int[][] options = new int[][]{{4, 0}, {3, 1}, {2, 2}, {1, 3}};
return dfs(n, n, options, new Double[n + 1][n + 1]);
}
private double dfs(int soupA, int soupB, int[][]options, Double[][] mem) {
if (soupA <= 0) {
if (soupB > 0) {
return 1;
}
if (soupB <= 0) {
return 0.5;
}
}
if (soupB <= 0) {
return 0;
}
if (mem[soupA][soupB] != null) {
return mem[soupA][soupB];
}
// 4 options
double res = 0.0;
for (int i = 0; i < options.length; i++) {
int nextA = soupA - options[i][0];
int nextB = soupB - options[i][1];
res += 0.25 * dfs(nextA, nextB, options, mem);
}
mem[soupA][soupB] = res;
return res;
}
}
'''
|
apache-2.0
|
[
363,
1365,
363,
275,
283,
2859,
921,
274,
386,
600,
14,
957,
15,
22959,
15,
9317,
13,
7297,
780,
4805,
199,
3,
4703,
26,
221,
593,
8,
46,
62,
18,
9,
199,
3,
19326,
26,
593,
8,
46,
62,
18,
9,
199,
3,
199,
3,
11994,
26,
7005,
386,
600,
327,
5939,
24,
14,
28028,
3739,
86,
780,
199,
3,
199,
3,
6006,
787,
2877,
2943,
402,
9108,
26,
730,
437,
436,
730,
699,
14,
199,
3,
21412,
1183,
781,
1172,
653,
19184,
402,
1924,
730,
402,
9108,
14,
6006,
787,
11648,
24241,
402,
5331,
26,
199,
3,
199,
3,
258,
3739,
432,
2948,
19184,
402,
9108,
437,
436,
378,
19184,
402,
9108,
699,
199,
3,
258,
3739,
432,
13098,
19184,
402,
9108,
437,
436,
5661,
19184,
402,
9108,
699,
199,
3,
258,
3739,
432,
5238,
19184,
402,
9108,
437,
436,
5238,
19184,
402,
9108,
699,
199,
3,
258,
3739,
432,
5661,
19184,
402,
9108,
437,
436,
13098,
19184,
402,
9108,
699,
199,
3,
199,
3,
3979,
781,
14062,
2005,
9108,
12,
781,
8120,
652,
370,
17122,
436,
781,
949,
8088,
1172,
652,
14,
199,
3,
7048,
7485,
12,
781,
911,
11496,
687,
314,
11648,
5331,
543,
4472,
12224,
378,
14,
821,
14,
199,
3,
982,
314,
7971,
3301,
402,
9108,
365,
440,
8321,
370,
4890,
314,
3439,
12,
199,
3,
781,
911,
14062,
465,
8298,
465,
781,
883,
14,
199,
3,
2136,
3631,
5403,
781,
949,
8088,
1172,
2005,
12524,
402,
3865,
2943,
402,
9108,
14,
199,
3,
199,
3,
3390,
626,
781,
886,
440,
1172,
314,
3439,
2382,
1006,
2948,
19184,
1159,
402,
9108,
699,
787,
1202,
1642,
14,
199,
3,
199,
3,
1432,
314,
12224,
626,
9108,
437,
911,
506,
2701,
1642,
12,
199,
3,
12254,
12995,
314,
12224,
626,
437,
436,
699,
8649,
2701,
737,
314,
2011,
900,
14,
199,
3,
199,
3,
199,
3,
5679,
26,
199,
3,
6924,
26,
653,
275,
5238,
199,
3,
7242,
26,
378,
14,
22475,
199,
3,
1316,
10304,
26,
199,
3,
982,
781,
11496,
314,
1642,
2877,
5331,
12,
437,
911,
8649,
2701,
1642,
14,
2104,
314,
10919,
3439,
12,
199,
3,
437,
436,
699,
911,
8649,
2701,
737,
314,
2011,
900,
14,
2104,
314,
11648,
273,
3439,
12,
699,
911,
8649,
2701,
1642,
14,
199,
3,
2002,
314,
3141,
12224,
402,
437,
506,
7909,
2701,
1642,
12254,
12995,
314,
12224,
626,
199,
3,
437,
436,
699,
8649,
2701,
737,
314,
2011,
900,
12,
365,
378,
14,
821,
627,
334,
17,
435,
413,
435,
378,
14,
21,
435,
378,
9,
275,
378,
14,
22475,
14,
199,
3,
199,
3,
8144,
26,
199,
3,
199,
3,
258,
378,
2695,
653,
2695,
1616,
62,
25,
14,
199,
3,
258,
437,
561,
12203,
4453,
1616,
26185,
22,
402,
314,
2549,
574,
911,
506,
10226,
465,
3211,
14,
199,
3,
199,
646,
2882,
199,
3,
5212,
706,
7829,
14,
1651,
5,
199,
533,
9274,
8,
785,
304,
272,
347,
9108,
1505,
86,
780,
8,
277,
12,
653,
304,
267,
408,
267,
520,
466,
653,
26,
1109,
267,
520,
4500,
26,
2069,
267,
408,
267,
1413,
12,
820,
275,
16438,
8,
46,
12,
5661,
9,
267,
653,
275,
1413,
435,
334,
50,
690,
378,
9,
267,
340,
653,
2356,
6891,
26,
372,
413,
398,
11955,
275,
1052,
267,
347,
12392,
8,
88,
12,
612,
304,
288,
340,
334,
88,
12,
612,
9,
440,
315,
11955,
26,
355,
340,
671,
2695,
378,
503,
612,
2695,
378,
26,
490,
4987,
275,
378,
14,
21,
340,
671,
12932,
16,
436,
612,
12932,
16,
587,
413,
14,
16,
340,
671,
12932,
16,
587,
378,
14,
16,
355,
587,
26,
490,
4987,
275,
378,
14,
821,
627,
334,
5780,
8,
88,
13,
20,
12,
89,
6393,
5780,
8,
88,
13,
19,
12,
89,
13,
17,
6393,
5780,
8,
88,
13,
18,
12,
89,
13,
18,
6393,
5780,
8,
88,
13,
17,
12,
89,
13,
19,
430,
355,
11955,
59,
88,
12,
612,
61,
275,
4987,
288,
372,
11955,
59,
88,
12,
612,
61,
398,
372,
12392,
8,
46,
12,
653,
9,
199,
199,
533,
1379,
10385,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
5339,
8,
277,
304,
267,
291,
14,
629,
8,
17,
12,
413,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
199,
12576,
275,
1449,
199,
3,
18049,
10846,
26,
4178,
921,
274,
386,
600,
14,
957,
15,
22959,
15,
9317,
13,
7297,
780,
15,
14458,
15,
199,
3,
199,
7443,
26,
710,
4750,
11012,
8328,
315,
642,
5160,
367,
562,
365,
221,
199,
2,
33,
561,
12203,
4453,
1616,
26185,
22,
402,
314,
2549,
574,
911,
506,
10226,
465,
3211,
15848,
199,
3325,
1380,
473,
664,
18590,
734,
503,
8836,
1125,
543,
3002,
577,
48,
12,
221,
199,
41,
16416,
370,
870,
734,
2058,
402,
1924,
1240,
367,
1924,
653,
14,
199,
1918,
89,
787,
3485,
357,
265,
7288,
22255,
12,
436,
10232,
2463,
332,
436,
2463,
332,
370,
413,
14,
199,
3917,
1265,
870,
652,
734,
12,
1265,
911,
2607,
4909,
626,
1380,
652,
365,
465,
7031,
465,
959,
23327,
221,
199,
1589,
16301,
3382,
314,
754,
436,
413,
365,
6656,
2419,
1616,
26185,
22,
14,
199,
199,
25923,
1225,
327,
17,
26,
21907,
2165,
9258,
359,
1945,
7203,
61,
199,
14500,
1209,
21916,
199,
1366,
19178,
1209,
26,
593,
8,
17,
680,
334,
10924,
3495,
282,
4413,
445,
4066,
626,
314,
5563,
7078,
18628,
1655,
2419,
445,
7124,
4959,
199,
7643,
19178,
1209,
26,
593,
8,
17,
9,
334,
10924,
3495,
282,
4413,
445,
4066,
626,
314,
5563,
7078,
4440,
1655,
2419,
445,
4601,
4959,
199,
199,
3,
1520,
706,
12001,
14,
966,
5,
199,
533,
9274,
469,
272,
4575,
4270,
9108,
1505,
86,
780,
8,
442,
653,
9,
469,
267,
653,
275,
653,
1182,
5661,
435,
334,
653,
450,
5661,
690,
378,
5805,
413,
26,
378,
2736,
267,
340,
334,
46,
690,
6891,
9,
372,
413,
14,
16,
27,
2728,
4270,
59,
1527,
61,
11955,
275,
892,
4270,
59,
46,
435,
413,
1527,
46,
435,
413,
11566,
267,
367,
334,
442,
308,
275,
378,
27,
308,
2695,
499,
627,
653,
27,
308,
25659,
469,
288,
367
] |
[
1365,
363,
275,
283,
2859,
921,
274,
386,
600,
14,
957,
15,
22959,
15,
9317,
13,
7297,
780,
4805,
199,
3,
4703,
26,
221,
593,
8,
46,
62,
18,
9,
199,
3,
19326,
26,
593,
8,
46,
62,
18,
9,
199,
3,
199,
3,
11994,
26,
7005,
386,
600,
327,
5939,
24,
14,
28028,
3739,
86,
780,
199,
3,
199,
3,
6006,
787,
2877,
2943,
402,
9108,
26,
730,
437,
436,
730,
699,
14,
199,
3,
21412,
1183,
781,
1172,
653,
19184,
402,
1924,
730,
402,
9108,
14,
6006,
787,
11648,
24241,
402,
5331,
26,
199,
3,
199,
3,
258,
3739,
432,
2948,
19184,
402,
9108,
437,
436,
378,
19184,
402,
9108,
699,
199,
3,
258,
3739,
432,
13098,
19184,
402,
9108,
437,
436,
5661,
19184,
402,
9108,
699,
199,
3,
258,
3739,
432,
5238,
19184,
402,
9108,
437,
436,
5238,
19184,
402,
9108,
699,
199,
3,
258,
3739,
432,
5661,
19184,
402,
9108,
437,
436,
13098,
19184,
402,
9108,
699,
199,
3,
199,
3,
3979,
781,
14062,
2005,
9108,
12,
781,
8120,
652,
370,
17122,
436,
781,
949,
8088,
1172,
652,
14,
199,
3,
7048,
7485,
12,
781,
911,
11496,
687,
314,
11648,
5331,
543,
4472,
12224,
378,
14,
821,
14,
199,
3,
982,
314,
7971,
3301,
402,
9108,
365,
440,
8321,
370,
4890,
314,
3439,
12,
199,
3,
781,
911,
14062,
465,
8298,
465,
781,
883,
14,
199,
3,
2136,
3631,
5403,
781,
949,
8088,
1172,
2005,
12524,
402,
3865,
2943,
402,
9108,
14,
199,
3,
199,
3,
3390,
626,
781,
886,
440,
1172,
314,
3439,
2382,
1006,
2948,
19184,
1159,
402,
9108,
699,
787,
1202,
1642,
14,
199,
3,
199,
3,
1432,
314,
12224,
626,
9108,
437,
911,
506,
2701,
1642,
12,
199,
3,
12254,
12995,
314,
12224,
626,
437,
436,
699,
8649,
2701,
737,
314,
2011,
900,
14,
199,
3,
199,
3,
199,
3,
5679,
26,
199,
3,
6924,
26,
653,
275,
5238,
199,
3,
7242,
26,
378,
14,
22475,
199,
3,
1316,
10304,
26,
199,
3,
982,
781,
11496,
314,
1642,
2877,
5331,
12,
437,
911,
8649,
2701,
1642,
14,
2104,
314,
10919,
3439,
12,
199,
3,
437,
436,
699,
911,
8649,
2701,
737,
314,
2011,
900,
14,
2104,
314,
11648,
273,
3439,
12,
699,
911,
8649,
2701,
1642,
14,
199,
3,
2002,
314,
3141,
12224,
402,
437,
506,
7909,
2701,
1642,
12254,
12995,
314,
12224,
626,
199,
3,
437,
436,
699,
8649,
2701,
737,
314,
2011,
900,
12,
365,
378,
14,
821,
627,
334,
17,
435,
413,
435,
378,
14,
21,
435,
378,
9,
275,
378,
14,
22475,
14,
199,
3,
199,
3,
8144,
26,
199,
3,
199,
3,
258,
378,
2695,
653,
2695,
1616,
62,
25,
14,
199,
3,
258,
437,
561,
12203,
4453,
1616,
26185,
22,
402,
314,
2549,
574,
911,
506,
10226,
465,
3211,
14,
199,
3,
199,
646,
2882,
199,
3,
5212,
706,
7829,
14,
1651,
5,
199,
533,
9274,
8,
785,
304,
272,
347,
9108,
1505,
86,
780,
8,
277,
12,
653,
304,
267,
408,
267,
520,
466,
653,
26,
1109,
267,
520,
4500,
26,
2069,
267,
408,
267,
1413,
12,
820,
275,
16438,
8,
46,
12,
5661,
9,
267,
653,
275,
1413,
435,
334,
50,
690,
378,
9,
267,
340,
653,
2356,
6891,
26,
372,
413,
398,
11955,
275,
1052,
267,
347,
12392,
8,
88,
12,
612,
304,
288,
340,
334,
88,
12,
612,
9,
440,
315,
11955,
26,
355,
340,
671,
2695,
378,
503,
612,
2695,
378,
26,
490,
4987,
275,
378,
14,
21,
340,
671,
12932,
16,
436,
612,
12932,
16,
587,
413,
14,
16,
340,
671,
12932,
16,
587,
378,
14,
16,
355,
587,
26,
490,
4987,
275,
378,
14,
821,
627,
334,
5780,
8,
88,
13,
20,
12,
89,
6393,
5780,
8,
88,
13,
19,
12,
89,
13,
17,
6393,
5780,
8,
88,
13,
18,
12,
89,
13,
18,
6393,
5780,
8,
88,
13,
17,
12,
89,
13,
19,
430,
355,
11955,
59,
88,
12,
612,
61,
275,
4987,
288,
372,
11955,
59,
88,
12,
612,
61,
398,
372,
12392,
8,
46,
12,
653,
9,
199,
199,
533,
1379,
10385,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
5339,
8,
277,
304,
267,
291,
14,
629,
8,
17,
12,
413,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
199,
12576,
275,
1449,
199,
3,
18049,
10846,
26,
4178,
921,
274,
386,
600,
14,
957,
15,
22959,
15,
9317,
13,
7297,
780,
15,
14458,
15,
199,
3,
199,
7443,
26,
710,
4750,
11012,
8328,
315,
642,
5160,
367,
562,
365,
221,
199,
2,
33,
561,
12203,
4453,
1616,
26185,
22,
402,
314,
2549,
574,
911,
506,
10226,
465,
3211,
15848,
199,
3325,
1380,
473,
664,
18590,
734,
503,
8836,
1125,
543,
3002,
577,
48,
12,
221,
199,
41,
16416,
370,
870,
734,
2058,
402,
1924,
1240,
367,
1924,
653,
14,
199,
1918,
89,
787,
3485,
357,
265,
7288,
22255,
12,
436,
10232,
2463,
332,
436,
2463,
332,
370,
413,
14,
199,
3917,
1265,
870,
652,
734,
12,
1265,
911,
2607,
4909,
626,
1380,
652,
365,
465,
7031,
465,
959,
23327,
221,
199,
1589,
16301,
3382,
314,
754,
436,
413,
365,
6656,
2419,
1616,
26185,
22,
14,
199,
199,
25923,
1225,
327,
17,
26,
21907,
2165,
9258,
359,
1945,
7203,
61,
199,
14500,
1209,
21916,
199,
1366,
19178,
1209,
26,
593,
8,
17,
680,
334,
10924,
3495,
282,
4413,
445,
4066,
626,
314,
5563,
7078,
18628,
1655,
2419,
445,
7124,
4959,
199,
7643,
19178,
1209,
26,
593,
8,
17,
9,
334,
10924,
3495,
282,
4413,
445,
4066,
626,
314,
5563,
7078,
4440,
1655,
2419,
445,
4601,
4959,
199,
199,
3,
1520,
706,
12001,
14,
966,
5,
199,
533,
9274,
469,
272,
4575,
4270,
9108,
1505,
86,
780,
8,
442,
653,
9,
469,
267,
653,
275,
653,
1182,
5661,
435,
334,
653,
450,
5661,
690,
378,
5805,
413,
26,
378,
2736,
267,
340,
334,
46,
690,
6891,
9,
372,
413,
14,
16,
27,
2728,
4270,
59,
1527,
61,
11955,
275,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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
torkelsson/meta-package-manager
|
meta_package_manager/managers/mas.py
|
1
|
5319
|
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016-2018 Kevin Deldycke <kevin@deldycke.com>
# and contributors.
# All Rights Reserved.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from __future__ import (
absolute_import,
division,
print_function,
unicode_literals
)
import re
from boltons.cacheutils import cachedproperty
from ..base import PackageManager
from ..platform import MACOS
class MAS(PackageManager):
platforms = frozenset([MACOS])
# 'mas outdated' output has been changed in 1.3.1: https://github.com
# /mas-cli/mas/commit/ca72ee42b1c5f482513b1d2fbf780b0bf3d9618b
requirement = '>= 1.3.1'
name = "Mac AppStore"
def get_version(self):
""" Fetch version from ``mas version`` output."""
return self.run([self.cli_path, 'version'])
@cachedproperty
def installed(self):
""" Fetch installed packages from ``mas list`` output.
Raw CLI output samples:
.. code-block:: shell-session
$ mas list
408981434 iMovie (10.1.4)
747648890 Telegram (2.30)
"""
installed = {}
output = self.run([self.cli_path] + self.cli_args + ['list'])
if output:
regexp = re.compile(r'(\d+) (.*) \((\S+)\)$')
for package in output.split('\n'):
match = regexp.match(package)
if match:
package_id, package_name, installed_version = \
match.groups()
installed[package_id] = {
'id': package_id,
'name': package_name,
# Normalize unknown version. See:
# https://github.com/mas-cli/mas/commit
# /1859eaedf49f6a1ebefe8c8d71ec653732674341
'installed_version': (
installed_version if installed_version != 'unknown'
else None)}
return installed
def search(self, query):
""" Fetch matching packages from ``mas search`` output.
Raw CLI output samples:
.. code-block:: shell-session
$ mas search python
689176796 Python Runner
630736088 Learning Python
945397020 Run Python
891162632 Python Lint
1025391371 Tutorial for Python
1164498373 PythonGames
"""
matches = {}
output = self.run([self.cli_path] + self.cli_args + [
'search', query])
if output:
regexp = re.compile(r'(\d+) (.*)$')
for package in output.split('\n'):
match = regexp.match(package)
if match:
package_id, package_name = match.groups()
matches[package_id] = {
'id': package_id,
'name': package_name,
'latest_version': None,
'exact': self.exact_match(query, package_name)}
return matches
@cachedproperty
def outdated(self):
""" Fetch outdated packages from ``mas outdated`` output.
Raw CLI output samples:
.. code-block:: shell-session
$ mas outdated
.. todo
An example of ``mas outdated`` output is missing above.
"""
outdated = {}
output = self.run([self.cli_path] + self.cli_args + ['outdated'])
if output:
regexp = re.compile(r'(\d+) (.*) \((\S+) -> (\S+)\)$')
for package in output.split('\n'):
match = regexp.match(package)
if match:
package_id, package_name, installed_version, \
latest_version = match.groups()
outdated[package_id] = {
'id': package_id,
'name': package_name,
'latest_version': latest_version,
# Normalize unknown version. See:
# https://github.com/mas-cli/mas/commit
# /1859eaedf49f6a1ebefe8c8d71ec653732674341
'installed_version': (
installed_version if installed_version != 'unknown'
else None)}
return outdated
def upgrade_cli(self, package_id=None):
cmd = [self.cli_path] + self.cli_args + ['upgrade']
if package_id:
cmd.append(package_id)
return cmd
def upgrade_all_cli(self):
return self.upgrade_cli()
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
7800,
13,
12682,
25645,
11908,
577,
457,
89,
21531,
665,
415,
11908,
32,
271,
1447,
89,
21531,
14,
957,
30,
199,
3,
12793,
436,
8417,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
961,
2240,
365,
2868,
2290,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
446,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
12,
8217,
14,
199,
199,
504,
636,
2443,
363,
492,
334,
272,
3679,
63,
646,
12,
272,
4629,
12,
272,
870,
63,
1593,
12,
272,
2649,
63,
5955,
199,
9,
199,
199,
646,
295,
199,
199,
504,
330,
393,
1860,
83,
14,
1637,
1208,
492,
6328,
1829,
199,
199,
504,
2508,
1095,
492,
15665,
2988,
199,
504,
2508,
3246,
492,
13347,
3100,
421,
199,
533,
603,
1179,
8,
8599,
2988,
304,
339,
10677,
275,
9522,
779,
9410,
3100,
566,
339,
327,
283,
5892,
734,
19074,
7,
1072,
965,
2757,
2896,
315,
413,
14,
19,
14,
17,
26,
4178,
921,
5031,
14,
957,
272,
327,
1182,
5892,
13,
2764,
15,
5892,
15,
3543,
15,
696,
2819,
1024,
2260,
66,
17,
67,
21,
70,
2006,
821,
969,
66,
17,
68,
18,
70,
4361,
31829,
66,
16,
4361,
19,
68,
2534,
1085,
66,
272,
10685,
275,
283,
8119,
413,
14,
19,
14,
17,
7,
339,
536,
275,
298,
3399,
4693,
5502,
2,
339,
347,
664,
63,
1023,
8,
277,
304,
267,
408,
16347,
1015,
687,
1124,
5892,
1015,
1040,
1072,
1041,
267,
372,
291,
14,
1065,
779,
277,
14,
2764,
63,
515,
12,
283,
1023,
1105,
339,
768,
5245,
1829,
272,
347,
4903,
8,
277,
304,
267,
408,
16347,
4903,
6117,
687,
1124,
5892,
769,
1040,
1072,
14,
398,
13480,
14214,
1072,
5845,
26,
398,
2508,
1233,
13,
1457,
447,
5218,
13,
1730,
953,
2672,
28065,
769,
288,
6335,
13176,
1079,
1082,
284,
19088,
334,
709,
14,
17,
14,
20,
9,
288,
9720,
29871,
1299,
2710,
23884,
1679,
334,
18,
14,
1216,
9,
267,
408,
267,
4903,
275,
1052,
398,
1072,
275,
291,
14,
1065,
779,
277,
14,
2764,
63,
515,
61,
435,
291,
14,
2764,
63,
589,
435,
788,
513,
1105,
398,
340,
1072,
26,
288,
13156,
275,
295,
14,
2014,
8,
82,
13445,
68,
8771,
334,
12432,
971,
1332,
60,
51,
13439,
9,
9988,
288,
367,
2559,
315,
1072,
14,
1294,
2258,
78,
735,
355,
1336,
275,
13156,
14,
1431,
8,
2491,
9,
355,
340,
1336,
26,
490,
2559,
63,
344,
12,
2559,
63,
354,
12,
4903,
63,
1023,
275,
971,
717,
1336,
14,
2634,
342,
490,
4903,
59,
2491,
63,
344,
61,
275,
469,
717,
283,
344,
356,
2559,
63,
344,
12,
717,
283,
354,
356,
2559,
63,
354,
12,
717,
327,
21017,
5809,
1015,
14,
1666,
26,
717,
327,
4178,
921,
5031,
14,
957,
15,
5892,
13,
2764,
15,
5892,
15,
3543,
717,
327,
1182,
1085,
1427,
4489,
27680,
1887,
70,
22,
65,
17,
69,
1235,
771,
24,
67,
24,
68,
3172,
825,
2182,
1401,
8342,
1342,
15590,
717,
283,
7657,
63,
1023,
356,
334,
1169,
4903,
63,
1023,
340,
4903,
63,
1023,
1137,
283,
5187,
7,
1169,
587,
488,
6769,
398,
372,
4903,
339,
347,
2754,
8,
277,
12,
1827,
304,
267,
408,
16347,
4877,
6117,
687,
1124,
5892,
2754,
1040,
1072,
14,
398,
13480,
14214,
1072,
5845,
26,
398,
2508,
1233,
13,
1457,
447,
5218,
13,
1730,
953,
2672,
28065,
2754,
2366,
288,
1227,
1407,
1196,
1822,
2534,
2018,
3378,
1372,
288,
1227,
11516,
11197,
1299,
29127,
2018,
288,
1749,
2322,
13145,
10173,
3378,
2018,
288,
17838,
7524,
1479,
708,
2018,
491,
442,
288,
1616,
821,
1355,
969,
3172,
377,
15888,
367,
2018,
288,
4119,
772,
20537,
14539,
2018,
11454,
83,
267,
408,
267,
4450,
275,
1052,
398,
1072,
275,
291,
14,
1065,
779,
277,
14,
2764,
63,
515,
61,
435,
291,
14,
2764,
63,
589,
435,
359,
288,
283,
1733,
297,
1827,
566,
398,
340,
1072,
26,
288,
13156,
275,
295,
14,
2014,
8,
82,
13445,
68,
8771,
334,
12432,
9988,
288,
367,
2559,
315,
1072,
14,
1294,
2258,
78,
735,
355,
1336,
275,
13156,
14,
1431,
8,
2491,
9,
355,
340,
1336,
26,
490,
2559,
63,
344,
12,
2559,
63,
354,
275,
1336,
14,
2634,
342,
490,
4450,
59,
2491,
63,
344,
61,
275,
469,
717,
283,
344,
356,
2559,
63,
344,
12,
717,
283,
354,
356,
2559,
63,
354,
12,
717,
283,
7410,
63,
1023,
356,
488,
12,
717,
283,
7327,
356,
291,
14,
7327,
63,
1431,
8,
1131,
12,
2559,
63,
354,
6769,
398,
372,
4450,
339,
768,
5245,
1829,
272,
347,
734,
19074,
8,
277,
304,
267,
408,
16347,
734,
19074,
6117,
687,
1124,
5892,
734,
19074,
1040,
1072,
14,
398,
13480,
14214,
1072,
5845,
26,
398,
2508,
1233,
13,
1457,
447,
5218,
13,
1730,
953,
2672,
28065,
734,
19074,
398,
2508,
11386,
953,
1626,
2893,
402,
1124,
5892,
734,
19074,
1040,
1072,
365,
4124,
3432,
14,
267,
408,
267,
734,
19074,
275,
1052,
398,
1072,
275,
291,
14,
1065,
779,
277,
14,
2764,
63,
515,
61,
435,
291,
14,
2764,
63,
589,
435,
788,
548,
19074,
1105,
398,
340,
1072,
26,
288,
13156,
275,
295,
14,
2014,
8,
82,
13445,
68,
8771,
334,
12432,
971,
1332,
60,
51,
8771,
1035,
14749,
51,
13439,
9,
9988,
288,
367,
2559,
315,
1072,
14,
1294,
2258,
78
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
7800,
13,
12682,
25645,
11908,
577,
457,
89,
21531,
665,
415,
11908,
32,
271,
1447,
89,
21531,
14,
957,
30,
199,
3,
12793,
436,
8417,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
961,
2240,
365,
2868,
2290,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
446,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
12,
8217,
14,
199,
199,
504,
636,
2443,
363,
492,
334,
272,
3679,
63,
646,
12,
272,
4629,
12,
272,
870,
63,
1593,
12,
272,
2649,
63,
5955,
199,
9,
199,
199,
646,
295,
199,
199,
504,
330,
393,
1860,
83,
14,
1637,
1208,
492,
6328,
1829,
199,
199,
504,
2508,
1095,
492,
15665,
2988,
199,
504,
2508,
3246,
492,
13347,
3100,
421,
199,
533,
603,
1179,
8,
8599,
2988,
304,
339,
10677,
275,
9522,
779,
9410,
3100,
566,
339,
327,
283,
5892,
734,
19074,
7,
1072,
965,
2757,
2896,
315,
413,
14,
19,
14,
17,
26,
4178,
921,
5031,
14,
957,
272,
327,
1182,
5892,
13,
2764,
15,
5892,
15,
3543,
15,
696,
2819,
1024,
2260,
66,
17,
67,
21,
70,
2006,
821,
969,
66,
17,
68,
18,
70,
4361,
31829,
66,
16,
4361,
19,
68,
2534,
1085,
66,
272,
10685,
275,
283,
8119,
413,
14,
19,
14,
17,
7,
339,
536,
275,
298,
3399,
4693,
5502,
2,
339,
347,
664,
63,
1023,
8,
277,
304,
267,
408,
16347,
1015,
687,
1124,
5892,
1015,
1040,
1072,
1041,
267,
372,
291,
14,
1065,
779,
277,
14,
2764,
63,
515,
12,
283,
1023,
1105,
339,
768,
5245,
1829,
272,
347,
4903,
8,
277,
304,
267,
408,
16347,
4903,
6117,
687,
1124,
5892,
769,
1040,
1072,
14,
398,
13480,
14214,
1072,
5845,
26,
398,
2508,
1233,
13,
1457,
447,
5218,
13,
1730,
953,
2672,
28065,
769,
288,
6335,
13176,
1079,
1082,
284,
19088,
334,
709,
14,
17,
14,
20,
9,
288,
9720,
29871,
1299,
2710,
23884,
1679,
334,
18,
14,
1216,
9,
267,
408,
267,
4903,
275,
1052,
398,
1072,
275,
291,
14,
1065,
779,
277,
14,
2764,
63,
515,
61,
435,
291,
14,
2764,
63,
589,
435,
788,
513,
1105,
398,
340,
1072,
26,
288,
13156,
275,
295,
14,
2014,
8,
82,
13445,
68,
8771,
334,
12432,
971,
1332,
60,
51,
13439,
9,
9988,
288,
367,
2559,
315,
1072,
14,
1294,
2258,
78,
735,
355,
1336,
275,
13156,
14,
1431,
8,
2491,
9,
355,
340,
1336,
26,
490,
2559,
63,
344,
12,
2559,
63,
354,
12,
4903,
63,
1023,
275,
971,
717,
1336,
14,
2634,
342,
490,
4903,
59,
2491,
63,
344,
61,
275,
469,
717,
283,
344,
356,
2559,
63,
344,
12,
717,
283,
354,
356,
2559,
63,
354,
12,
717,
327,
21017,
5809,
1015,
14,
1666,
26,
717,
327,
4178,
921,
5031,
14,
957,
15,
5892,
13,
2764,
15,
5892,
15,
3543,
717,
327,
1182,
1085,
1427,
4489,
27680,
1887,
70,
22,
65,
17,
69,
1235,
771,
24,
67,
24,
68,
3172,
825,
2182,
1401,
8342,
1342,
15590,
717,
283,
7657,
63,
1023,
356,
334,
1169,
4903,
63,
1023,
340,
4903,
63,
1023,
1137,
283,
5187,
7,
1169,
587,
488,
6769,
398,
372,
4903,
339,
347,
2754,
8,
277,
12,
1827,
304,
267,
408,
16347,
4877,
6117,
687,
1124,
5892,
2754,
1040,
1072,
14,
398,
13480,
14214,
1072,
5845,
26,
398,
2508,
1233,
13,
1457,
447,
5218,
13,
1730,
953,
2672,
28065,
2754,
2366,
288,
1227,
1407,
1196,
1822,
2534,
2018,
3378,
1372,
288,
1227,
11516,
11197,
1299,
29127,
2018,
288,
1749,
2322,
13145,
10173,
3378,
2018,
288,
17838,
7524,
1479,
708,
2018,
491,
442,
288,
1616,
821,
1355,
969,
3172,
377,
15888,
367,
2018,
288,
4119,
772,
20537,
14539,
2018,
11454,
83,
267,
408,
267,
4450,
275,
1052,
398,
1072,
275,
291,
14,
1065,
779,
277,
14,
2764,
63,
515,
61,
435,
291,
14,
2764,
63,
589,
435,
359,
288,
283,
1733,
297,
1827,
566,
398,
340,
1072,
26,
288,
13156,
275,
295,
14,
2014,
8,
82,
13445,
68,
8771,
334,
12432,
9988,
288,
367,
2559,
315,
1072,
14,
1294,
2258,
78,
735,
355,
1336,
275,
13156,
14,
1431,
8,
2491,
9,
355,
340,
1336,
26,
490,
2559,
63,
344,
12,
2559,
63,
354,
275,
1336,
14,
2634,
342,
490,
4450,
59,
2491,
63,
344,
61,
275,
469,
717,
283,
344,
356,
2559,
63,
344,
12,
717,
283,
354,
356,
2559,
63,
354,
12,
717,
283,
7410,
63,
1023,
356,
488,
12,
717,
283,
7327,
356,
291,
14,
7327,
63,
1431,
8,
1131,
12,
2559,
63,
354,
6769,
398,
372,
4450,
339,
768,
5245,
1829,
272,
347,
734,
19074,
8,
277,
304,
267,
408,
16347,
734,
19074,
6117,
687,
1124,
5892,
734,
19074,
1040,
1072,
14,
398,
13480,
14214,
1072,
5845,
26,
398,
2508,
1233,
13,
1457,
447,
5218,
13,
1730,
953,
2672,
28065,
734,
19074,
398,
2508,
11386,
953,
1626,
2893,
402,
1124,
5892,
734,
19074,
1040,
1072,
365,
4124,
3432,
14,
267,
408,
267,
734,
19074,
275,
1052,
398,
1072,
275,
291,
14,
1065,
779,
277,
14,
2764,
63,
515,
61,
435,
291,
14,
2764,
63,
589,
435,
788,
548,
19074,
1105,
398,
340,
1072,
26,
288,
13156,
275,
295,
14,
2014,
8,
82,
13445,
68,
8771,
334,
12432,
971,
1332,
60,
51,
8771,
1035,
14749,
51,
13439,
9,
9988,
288,
367,
2559,
315,
1072,
14,
1294,
2258,
78,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tedelhourani/ansible
|
test/legacy/cleanup_ec2.py
|
149
|
6962
|
'''
Find and delete AWS resources matching the provided --match string. Unless
--yes|-y is provided, the prompt for confirmation prior to deleting resources.
Please use caution, you can easily delete you're *ENTIRE* EC2 infrastructure.
'''
import boto
import boto.ec2.elb
import optparse
import os
import os.path
import re
import sys
import time
import yaml
from ansible.module_utils.six.moves import input
def delete_aws_resources(get_func, attr, opts):
for item in get_func():
val = getattr(item, attr)
if re.search(opts.match_re, val):
prompt_and_delete(item, "Delete matching %s? [y/n]: " % (item,), opts.assumeyes)
def delete_autoscaling_group(get_func, attr, opts):
assumeyes = opts.assumeyes
group_name = None
for item in get_func():
group_name = getattr(item, attr)
if re.search(opts.match_re, group_name):
if not opts.assumeyes:
assumeyes = input("Delete matching %s? [y/n]: " % (item).lower()) == 'y'
break
if assumeyes and group_name:
groups = asg.get_all_groups(names=[group_name])
if groups:
group = groups[0]
group.max_size = 0
group.min_size = 0
group.desired_capacity = 0
group.update()
instances = True
while instances:
tmp_groups = asg.get_all_groups(names=[group_name])
if tmp_groups:
tmp_group = tmp_groups[0]
if not tmp_group.instances:
instances = False
time.sleep(10)
group.delete()
while len(asg.get_all_groups(names=[group_name])):
time.sleep(5)
print("Terminated ASG: %s" % group_name)
def delete_aws_eips(get_func, attr, opts):
# the file might not be there if the integration test wasn't run
try:
eip_log = open(opts.eip_log, 'r').read().splitlines()
except IOError:
print('%s not found.' % opts.eip_log)
return
for item in get_func():
val = getattr(item, attr)
if val in eip_log:
prompt_and_delete(item, "Delete matching %s? [y/n]: " % (item,), opts.assumeyes)
def delete_aws_instances(reservation, opts):
for list in reservation:
for item in list.instances:
prompt_and_delete(item, "Delete matching %s? [y/n]: " % (item,), opts.assumeyes)
def prompt_and_delete(item, prompt, assumeyes):
if not assumeyes:
assumeyes = input(prompt).lower() == 'y'
assert hasattr(item, 'delete') or hasattr(item, 'terminate'), "Class <%s> has no delete or terminate attribute" % item.__class__
if assumeyes:
if hasattr(item, 'delete'):
item.delete()
print("Deleted %s" % item)
if hasattr(item, 'terminate'):
item.terminate()
print("Terminated %s" % item)
def parse_args():
# Load details from credentials.yml
default_aws_access_key = os.environ.get('AWS_ACCESS_KEY', None)
default_aws_secret_key = os.environ.get('AWS_SECRET_KEY', None)
if os.path.isfile('credentials.yml'):
credentials = yaml.load(open('credentials.yml', 'r'))
if default_aws_access_key is None:
default_aws_access_key = credentials['ec2_access_key']
if default_aws_secret_key is None:
default_aws_secret_key = credentials['ec2_secret_key']
parser = optparse.OptionParser(
usage="%s [options]" % (sys.argv[0], ),
description=__doc__
)
parser.add_option(
"--access",
action="store", dest="ec2_access_key",
default=default_aws_access_key,
help="Amazon ec2 access id. Can use EC2_ACCESS_KEY environment variable, or a values from credentials.yml."
)
parser.add_option(
"--secret",
action="store", dest="ec2_secret_key",
default=default_aws_secret_key,
help="Amazon ec2 secret key. Can use EC2_SECRET_KEY environment variable, or a values from credentials.yml."
)
parser.add_option(
"--eip-log",
action="store", dest="eip_log",
default=None,
help="Path to log of EIPs created during test."
)
parser.add_option(
"--integration-config",
action="store", dest="int_config",
default="integration_config.yml",
help="path to integration config"
)
parser.add_option(
"--credentials", "-c",
action="store", dest="credential_file",
default="credentials.yml",
help="YAML file to read cloud credentials (default: %default)"
)
parser.add_option(
"--yes", "-y",
action="store_true", dest="assumeyes",
default=False,
help="Don't prompt for confirmation"
)
parser.add_option(
"--match",
action="store", dest="match_re",
default="^ansible-testing-",
help="Regular expression used to find AWS resources (default: %default)"
)
(opts, args) = parser.parse_args()
for required in ['ec2_access_key', 'ec2_secret_key']:
if getattr(opts, required) is None:
parser.error("Missing required parameter: --%s" % required)
return (opts, args)
if __name__ == '__main__':
(opts, args) = parse_args()
int_config = yaml.load(open(opts.int_config).read())
if not opts.eip_log:
output_dir = os.path.expanduser(int_config["output_dir"])
opts.eip_log = output_dir + '/' + opts.match_re.replace('^', '') + '-eip_integration_tests.log'
# Connect to AWS
aws = boto.connect_ec2(aws_access_key_id=opts.ec2_access_key,
aws_secret_access_key=opts.ec2_secret_key)
elb = boto.connect_elb(aws_access_key_id=opts.ec2_access_key,
aws_secret_access_key=opts.ec2_secret_key)
asg = boto.connect_autoscale(aws_access_key_id=opts.ec2_access_key,
aws_secret_access_key=opts.ec2_secret_key)
try:
# Delete matching keys
delete_aws_resources(aws.get_all_key_pairs, 'name', opts)
# Delete matching security groups
delete_aws_resources(aws.get_all_security_groups, 'name', opts)
# Delete matching ASGs
delete_autoscaling_group(asg.get_all_groups, 'name', opts)
# Delete matching launch configs
delete_aws_resources(asg.get_all_launch_configurations, 'name', opts)
# Delete ELBs
delete_aws_resources(elb.get_all_load_balancers, 'name', opts)
# Delete recorded EIPs
delete_aws_eips(aws.get_all_addresses, 'public_ip', opts)
# Delete temporary instances
filters = {"tag:Name": opts.match_re.replace('^', ''), "instance-state-name": ['running', 'pending', 'stopped']}
delete_aws_instances(aws.get_all_instances(filters=filters), opts)
except KeyboardInterrupt as e:
print("\nExiting on user command.")
|
gpl-3.0
|
[
2344,
199,
6591,
436,
3145,
10168,
5944,
4877,
314,
2741,
1553,
1431,
1059,
14,
221,
4158,
199,
306,
5066,
28447,
89,
365,
2741,
12,
314,
8457,
367,
18791,
6791,
370,
13794,
5944,
14,
199,
8254,
675,
1704,
2206,
12,
1265,
883,
16174,
3145,
1265,
3984,
627,
1309,
21201,
10,
15352,
18,
28890,
6976,
14,
199,
2344,
199,
199,
646,
6055,
199,
646,
6055,
14,
825,
18,
14,
17778,
199,
646,
8691,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
984,
199,
646,
900,
199,
646,
8864,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
14,
4912,
492,
1324,
421,
199,
318,
3145,
63,
7231,
63,
4435,
8,
362,
63,
1532,
12,
1921,
12,
3999,
304,
272,
367,
1242,
315,
664,
63,
1532,
837,
267,
1139,
275,
2519,
8,
1053,
12,
1921,
9,
267,
340,
295,
14,
1733,
8,
3291,
14,
1431,
63,
264,
12,
1139,
304,
288,
8457,
63,
460,
63,
1807,
8,
1053,
12,
298,
5392,
4877,
450,
83,
31,
359,
89,
15,
78,
2189,
298,
450,
334,
1053,
4706,
3999,
14,
21946,
5066,
9,
421,
199,
318,
3145,
63,
2495,
12153,
63,
923,
8,
362,
63,
1532,
12,
1921,
12,
3999,
304,
272,
5534,
5066,
275,
3999,
14,
21946,
5066,
272,
1572,
63,
354,
275,
488,
272,
367,
1242,
315,
664,
63,
1532,
837,
267,
1572,
63,
354,
275,
2519,
8,
1053,
12,
1921,
9,
267,
340,
295,
14,
1733,
8,
3291,
14,
1431,
63,
264,
12,
1572,
63,
354,
304,
288,
340,
440,
3999,
14,
21946,
5066,
26,
355,
5534,
5066,
275,
1324,
480,
5392,
4877,
450,
83,
31,
359,
89,
15,
78,
2189,
298,
450,
334,
1053,
680,
2325,
1012,
508,
283,
89,
7,
288,
2059,
272,
340,
5534,
5066,
436,
1572,
63,
354,
26,
267,
4652,
275,
465,
71,
14,
362,
63,
452,
63,
2634,
8,
1247,
1524,
923,
63,
354,
566,
267,
340,
4652,
26,
288,
1572,
275,
4652,
59,
16,
61,
288,
1572,
14,
988,
63,
890,
275,
378,
288,
1572,
14,
827,
63,
890,
275,
378,
288,
1572,
14,
16035,
63,
10457,
275,
378,
288,
1572,
14,
873,
342,
288,
4454,
275,
715,
288,
1830,
4454,
26,
355,
3529,
63,
2634,
275,
465,
71,
14,
362,
63,
452,
63,
2634,
8,
1247,
1524,
923,
63,
354,
566,
355,
340,
3529,
63,
2634,
26,
490,
3529,
63,
923,
275,
3529,
63,
2634,
59,
16,
61,
490,
340,
440,
3529,
63,
923,
14,
5990,
26,
717,
4454,
275,
756,
355,
900,
14,
4532,
8,
709,
9,
953,
1572,
14,
1807,
342,
288,
1830,
822,
8,
305,
71,
14,
362,
63,
452,
63,
2634,
8,
1247,
1524,
923,
63,
354,
18710,
355,
900,
14,
4532,
8,
21,
9,
288,
870,
480,
12154,
972,
437,
4254,
26,
450,
83,
2,
450,
1572,
63,
354,
9,
421,
199,
318,
3145,
63,
7231,
63,
69,
6142,
8,
362,
63,
1532,
12,
1921,
12,
3999,
304,
339,
327,
314,
570,
5594,
440,
506,
2337,
340,
314,
13150,
511,
17373,
1133,
1255,
272,
862,
26,
267,
325,
711,
63,
793,
275,
1551,
8,
3291,
14,
69,
711,
63,
793,
12,
283,
82,
1959,
739,
1252,
7644,
342,
272,
871,
5925,
26,
267,
870,
3508,
83,
440,
1911,
3530,
450,
3999,
14,
69,
711,
63,
793,
9,
267,
372,
339,
367,
1242,
315,
664,
63,
1532,
837,
267,
1139,
275,
2519,
8,
1053,
12,
1921,
9,
267,
340,
1139,
315,
325,
711,
63,
793,
26,
288,
8457,
63,
460,
63,
1807,
8,
1053,
12,
298,
5392,
4877,
450,
83,
31,
359,
89,
15,
78,
2189,
298,
450,
334,
1053,
4706,
3999,
14,
21946,
5066,
9,
421,
199,
318,
3145,
63,
7231,
63,
5990,
8,
20522,
12,
3999,
304,
272,
367,
769,
315,
25476,
26,
267,
367,
1242,
315,
769,
14,
5990,
26,
288,
8457,
63,
460,
63,
1807,
8,
1053,
12,
298,
5392,
4877,
450,
83,
31,
359,
89,
15,
78,
2189,
298,
450,
334,
1053,
4706,
3999,
14,
21946,
5066,
9,
421,
199,
318,
8457,
63,
460,
63,
1807,
8,
1053,
12,
8457,
12,
5534,
5066,
304,
272,
340,
440,
5534,
5066,
26,
267,
5534,
5066,
275,
1324,
8,
7650,
680,
2325,
342,
508,
283,
89,
7,
272,
702,
2688,
8,
1053,
12,
283,
1807,
358,
503,
2688,
8,
1053,
12,
283,
14478,
659,
298,
2543,
21808,
83,
30,
965,
949,
3145,
503,
15095,
2225,
2,
450,
1242,
855,
533,
363,
272,
340,
5534,
5066,
26,
267,
340,
2688,
8,
1053,
12,
283,
1807,
735,
288,
1242,
14,
1807,
342,
288,
870,
480,
17735,
450,
83,
2,
450,
1242,
9,
267,
340,
2688,
8,
1053,
12,
283,
14478,
735,
288,
1242,
14,
14478,
342,
288,
870,
480,
12154,
972,
450,
83,
2,
450,
1242,
9,
421,
199,
318,
2198,
63,
589,
837,
272,
327,
7190,
2436,
687,
6235,
14,
11714,
272,
849,
63,
7231,
63,
2732,
63,
498,
275,
747,
14,
2314,
14,
362,
360,
13226,
63,
11074,
63,
3078,
297,
488,
9,
272,
849,
63,
7231,
63,
4731,
63,
498,
275,
747,
14,
2314,
14,
362,
360,
13226,
63,
12961,
63,
3078,
297,
488,
9,
272,
340,
747,
14,
515,
14,
6292,
360,
6942,
14,
11714,
735,
267,
6235,
275,
8864,
14,
912,
8,
1490,
360,
6942,
14,
11714,
297,
283,
82,
1333,
398,
340,
849,
63,
7231,
63,
2732,
63,
498,
365,
488,
26,
288,
849,
63,
7231,
63,
2732,
63,
498,
275,
6235,
459,
825,
18,
63,
2732,
63,
498,
418,
267,
340,
849,
63,
7231,
63,
4731,
63,
498,
365,
488,
26,
288,
849,
63,
7231,
63,
4731,
63,
498,
275,
6235,
459,
825,
18,
63,
4731,
63,
498,
418,
339,
1798,
275,
8691,
14,
14553,
8,
267,
4503,
5961,
83,
359,
1419,
8480,
450,
334,
1274,
14,
3020,
59,
16,
467,
2318,
267,
1369,
18971,
1301,
363,
272,
776,
272,
1798,
14,
525,
63,
1422,
8,
267,
4320,
2732,
401,
267,
1595,
628,
1617,
401,
2053,
628,
825,
18,
63,
2732,
63,
498,
401,
267,
849,
29,
885,
63,
7231,
63,
2732,
63,
498,
12,
267,
1720,
628,
33,
8872,
7062,
18,
2879,
1305,
14,
221,
6855,
675,
15352,
18,
63,
11074,
63,
3078,
3734,
1750,
12,
503,
282,
1338,
687,
6235
] |
[
199,
6591,
436,
3145,
10168,
5944,
4877,
314,
2741,
1553,
1431,
1059,
14,
221,
4158,
199,
306,
5066,
28447,
89,
365,
2741,
12,
314,
8457,
367,
18791,
6791,
370,
13794,
5944,
14,
199,
8254,
675,
1704,
2206,
12,
1265,
883,
16174,
3145,
1265,
3984,
627,
1309,
21201,
10,
15352,
18,
28890,
6976,
14,
199,
2344,
199,
199,
646,
6055,
199,
646,
6055,
14,
825,
18,
14,
17778,
199,
646,
8691,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
984,
199,
646,
900,
199,
646,
8864,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
14,
4912,
492,
1324,
421,
199,
318,
3145,
63,
7231,
63,
4435,
8,
362,
63,
1532,
12,
1921,
12,
3999,
304,
272,
367,
1242,
315,
664,
63,
1532,
837,
267,
1139,
275,
2519,
8,
1053,
12,
1921,
9,
267,
340,
295,
14,
1733,
8,
3291,
14,
1431,
63,
264,
12,
1139,
304,
288,
8457,
63,
460,
63,
1807,
8,
1053,
12,
298,
5392,
4877,
450,
83,
31,
359,
89,
15,
78,
2189,
298,
450,
334,
1053,
4706,
3999,
14,
21946,
5066,
9,
421,
199,
318,
3145,
63,
2495,
12153,
63,
923,
8,
362,
63,
1532,
12,
1921,
12,
3999,
304,
272,
5534,
5066,
275,
3999,
14,
21946,
5066,
272,
1572,
63,
354,
275,
488,
272,
367,
1242,
315,
664,
63,
1532,
837,
267,
1572,
63,
354,
275,
2519,
8,
1053,
12,
1921,
9,
267,
340,
295,
14,
1733,
8,
3291,
14,
1431,
63,
264,
12,
1572,
63,
354,
304,
288,
340,
440,
3999,
14,
21946,
5066,
26,
355,
5534,
5066,
275,
1324,
480,
5392,
4877,
450,
83,
31,
359,
89,
15,
78,
2189,
298,
450,
334,
1053,
680,
2325,
1012,
508,
283,
89,
7,
288,
2059,
272,
340,
5534,
5066,
436,
1572,
63,
354,
26,
267,
4652,
275,
465,
71,
14,
362,
63,
452,
63,
2634,
8,
1247,
1524,
923,
63,
354,
566,
267,
340,
4652,
26,
288,
1572,
275,
4652,
59,
16,
61,
288,
1572,
14,
988,
63,
890,
275,
378,
288,
1572,
14,
827,
63,
890,
275,
378,
288,
1572,
14,
16035,
63,
10457,
275,
378,
288,
1572,
14,
873,
342,
288,
4454,
275,
715,
288,
1830,
4454,
26,
355,
3529,
63,
2634,
275,
465,
71,
14,
362,
63,
452,
63,
2634,
8,
1247,
1524,
923,
63,
354,
566,
355,
340,
3529,
63,
2634,
26,
490,
3529,
63,
923,
275,
3529,
63,
2634,
59,
16,
61,
490,
340,
440,
3529,
63,
923,
14,
5990,
26,
717,
4454,
275,
756,
355,
900,
14,
4532,
8,
709,
9,
953,
1572,
14,
1807,
342,
288,
1830,
822,
8,
305,
71,
14,
362,
63,
452,
63,
2634,
8,
1247,
1524,
923,
63,
354,
18710,
355,
900,
14,
4532,
8,
21,
9,
288,
870,
480,
12154,
972,
437,
4254,
26,
450,
83,
2,
450,
1572,
63,
354,
9,
421,
199,
318,
3145,
63,
7231,
63,
69,
6142,
8,
362,
63,
1532,
12,
1921,
12,
3999,
304,
339,
327,
314,
570,
5594,
440,
506,
2337,
340,
314,
13150,
511,
17373,
1133,
1255,
272,
862,
26,
267,
325,
711,
63,
793,
275,
1551,
8,
3291,
14,
69,
711,
63,
793,
12,
283,
82,
1959,
739,
1252,
7644,
342,
272,
871,
5925,
26,
267,
870,
3508,
83,
440,
1911,
3530,
450,
3999,
14,
69,
711,
63,
793,
9,
267,
372,
339,
367,
1242,
315,
664,
63,
1532,
837,
267,
1139,
275,
2519,
8,
1053,
12,
1921,
9,
267,
340,
1139,
315,
325,
711,
63,
793,
26,
288,
8457,
63,
460,
63,
1807,
8,
1053,
12,
298,
5392,
4877,
450,
83,
31,
359,
89,
15,
78,
2189,
298,
450,
334,
1053,
4706,
3999,
14,
21946,
5066,
9,
421,
199,
318,
3145,
63,
7231,
63,
5990,
8,
20522,
12,
3999,
304,
272,
367,
769,
315,
25476,
26,
267,
367,
1242,
315,
769,
14,
5990,
26,
288,
8457,
63,
460,
63,
1807,
8,
1053,
12,
298,
5392,
4877,
450,
83,
31,
359,
89,
15,
78,
2189,
298,
450,
334,
1053,
4706,
3999,
14,
21946,
5066,
9,
421,
199,
318,
8457,
63,
460,
63,
1807,
8,
1053,
12,
8457,
12,
5534,
5066,
304,
272,
340,
440,
5534,
5066,
26,
267,
5534,
5066,
275,
1324,
8,
7650,
680,
2325,
342,
508,
283,
89,
7,
272,
702,
2688,
8,
1053,
12,
283,
1807,
358,
503,
2688,
8,
1053,
12,
283,
14478,
659,
298,
2543,
21808,
83,
30,
965,
949,
3145,
503,
15095,
2225,
2,
450,
1242,
855,
533,
363,
272,
340,
5534,
5066,
26,
267,
340,
2688,
8,
1053,
12,
283,
1807,
735,
288,
1242,
14,
1807,
342,
288,
870,
480,
17735,
450,
83,
2,
450,
1242,
9,
267,
340,
2688,
8,
1053,
12,
283,
14478,
735,
288,
1242,
14,
14478,
342,
288,
870,
480,
12154,
972,
450,
83,
2,
450,
1242,
9,
421,
199,
318,
2198,
63,
589,
837,
272,
327,
7190,
2436,
687,
6235,
14,
11714,
272,
849,
63,
7231,
63,
2732,
63,
498,
275,
747,
14,
2314,
14,
362,
360,
13226,
63,
11074,
63,
3078,
297,
488,
9,
272,
849,
63,
7231,
63,
4731,
63,
498,
275,
747,
14,
2314,
14,
362,
360,
13226,
63,
12961,
63,
3078,
297,
488,
9,
272,
340,
747,
14,
515,
14,
6292,
360,
6942,
14,
11714,
735,
267,
6235,
275,
8864,
14,
912,
8,
1490,
360,
6942,
14,
11714,
297,
283,
82,
1333,
398,
340,
849,
63,
7231,
63,
2732,
63,
498,
365,
488,
26,
288,
849,
63,
7231,
63,
2732,
63,
498,
275,
6235,
459,
825,
18,
63,
2732,
63,
498,
418,
267,
340,
849,
63,
7231,
63,
4731,
63,
498,
365,
488,
26,
288,
849,
63,
7231,
63,
4731,
63,
498,
275,
6235,
459,
825,
18,
63,
4731,
63,
498,
418,
339,
1798,
275,
8691,
14,
14553,
8,
267,
4503,
5961,
83,
359,
1419,
8480,
450,
334,
1274,
14,
3020,
59,
16,
467,
2318,
267,
1369,
18971,
1301,
363,
272,
776,
272,
1798,
14,
525,
63,
1422,
8,
267,
4320,
2732,
401,
267,
1595,
628,
1617,
401,
2053,
628,
825,
18,
63,
2732,
63,
498,
401,
267,
849,
29,
885,
63,
7231,
63,
2732,
63,
498,
12,
267,
1720,
628,
33,
8872,
7062,
18,
2879,
1305,
14,
221,
6855,
675,
15352,
18,
63,
11074,
63,
3078,
3734,
1750,
12,
503,
282,
1338,
687,
6235,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
appsembler/edx-platform
|
lms/djangoapps/staticbook/tests.py
|
13
|
11107
|
"""
Test the lms/staticbook views.
"""
import textwrap
import mock
import requests
from django.urls import NoReverseMatch, reverse
from six import text_type
from student.tests.factories import CourseEnrollmentFactory, UserFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
IMAGE_BOOK = ("An Image Textbook", "http://example.com/the_book/")
PDF_BOOK = {
"tab_title": "Textbook",
"title": "A PDF Textbook",
"chapters": [
{"title": "Chapter 1 for PDF", "url": "https://somehost.com/the_book/chap1.pdf"},
{"title": "Chapter 2 for PDF", "url": "https://somehost.com/the_book/chap2.pdf"},
],
}
PORTABLE_PDF_BOOK = {
"tab_title": "Textbook",
"title": "A PDF Textbook",
"chapters": [
{"title": "Chapter 1 for PDF", "url": "/static/chap1.pdf"},
{"title": "Chapter 2 for PDF", "url": "/static/chap2.pdf"},
],
}
HTML_BOOK = {
"tab_title": "Textbook",
"title": "An HTML Textbook",
"chapters": [
{"title": "Chapter 1 for HTML", "url": "https://somehost.com/the_book/chap1.html"},
{"title": "Chapter 2 for HTML", "url": "https://somehost.com/the_book/chap2.html"},
],
}
class StaticBookTest(ModuleStoreTestCase):
"""
Helpers for the static book tests.
"""
def __init__(self, *args, **kwargs):
super(StaticBookTest, self).__init__(*args, **kwargs)
self.course = None
def make_course(self, **kwargs):
"""
Make a course with an enrolled logged-in student.
"""
self.course = CourseFactory.create(**kwargs)
user = UserFactory.create()
CourseEnrollmentFactory.create(user=user, course_id=self.course.id)
self.client.login(username=user.username, password='test')
def make_url(self, url_name, **kwargs):
"""
Make a URL for a `url_name` using keyword args for url slots.
Automatically provides the course id.
"""
kwargs['course_id'] = text_type(self.course.id)
url = reverse(url_name, kwargs=kwargs)
return url
class StaticImageBookTest(StaticBookTest):
"""
Test the image-based static book view.
"""
def test_book(self):
# We can access a book.
with mock.patch.object(requests, 'get') as mock_get:
mock_get.return_value.text = textwrap.dedent('''\
<?xml version="1.0"?>
<table_of_contents>
<entry page="9" page_label="ix" name="Contents!?"/>
<entry page="1" page_label="i" name="Preamble">
<entry page="4" page_label="iv" name="About the Elephants"/>
</entry>
</table_of_contents>
''')
self.make_course(textbooks=[IMAGE_BOOK])
url = self.make_url('book', book_index=0)
response = self.client.get(url)
self.assertContains(response, "Contents!?")
self.assertContains(response, "About the Elephants")
def test_bad_book_id(self):
# A bad book id will be a 404.
self.make_course(textbooks=[IMAGE_BOOK])
with self.assertRaises(NoReverseMatch):
self.make_url('book', book_index='fooey')
def test_out_of_range_book_id(self):
self.make_course()
url = self.make_url('book', book_index=0)
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
def test_bad_page_id(self):
# A bad page id will cause a 404.
self.make_course(textbooks=[IMAGE_BOOK])
with self.assertRaises(NoReverseMatch):
self.make_url('book', book_index=0, page='xyzzy')
class StaticPdfBookTest(StaticBookTest):
"""
Test the PDF static book view.
"""
def test_book(self):
# We can access a book.
self.make_course(pdf_textbooks=[PDF_BOOK])
url = self.make_url('pdf_book', book_index=0)
response = self.client.get(url)
self.assertContains(response, "Chapter 1 for PDF")
self.assertNotContains(response, "options.chapterNum =")
self.assertNotContains(response, "page=")
def test_book_chapter(self):
# We can access a book at a particular chapter.
self.make_course(pdf_textbooks=[PDF_BOOK])
url = self.make_url('pdf_book', book_index=0, chapter=2)
response = self.client.get(url)
self.assertContains(response, "Chapter 2 for PDF")
self.assertContains(response, "file={}".format(PDF_BOOK['chapters'][1]['url']))
self.assertNotContains(response, "page=")
def test_book_page(self):
# We can access a book at a particular page.
self.make_course(pdf_textbooks=[PDF_BOOK])
url = self.make_url('pdf_book', book_index=0, page=17)
response = self.client.get(url)
self.assertContains(response, "Chapter 1 for PDF")
self.assertNotContains(response, "options.chapterNum =")
self.assertContains(response, "page=17")
def test_book_chapter_page(self):
# We can access a book at a particular chapter and page.
self.make_course(pdf_textbooks=[PDF_BOOK])
url = self.make_url('pdf_book', book_index=0, chapter=2, page=17)
response = self.client.get(url)
self.assertContains(response, "Chapter 2 for PDF")
self.assertContains(response, "file={}".format(PDF_BOOK['chapters'][1]['url']))
self.assertContains(response, "page=17")
def test_bad_book_id(self):
# If the book id isn't an int, we'll get a 404.
self.make_course(pdf_textbooks=[PDF_BOOK])
with self.assertRaises(NoReverseMatch):
self.make_url('pdf_book', book_index='fooey', chapter=1)
def test_out_of_range_book_id(self):
# If we have one book, asking for the second book will fail with a 404.
self.make_course(pdf_textbooks=[PDF_BOOK])
url = self.make_url('pdf_book', book_index=1, chapter=1)
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
def test_no_book(self):
# If we have no books, asking for the first book will fail with a 404.
self.make_course()
url = self.make_url('pdf_book', book_index=0, chapter=1)
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
def test_chapter_xss(self):
# The chapter in the URL used to go right on the page.
self.make_course(pdf_textbooks=[PDF_BOOK])
# It's no longer possible to use a non-integer chapter.
with self.assertRaises(NoReverseMatch):
self.make_url('pdf_book', book_index=0, chapter='xyzzy')
def test_page_xss(self):
# The page in the URL used to go right on the page.
self.make_course(pdf_textbooks=[PDF_BOOK])
# It's no longer possible to use a non-integer page.
with self.assertRaises(NoReverseMatch):
self.make_url('pdf_book', book_index=0, page='xyzzy')
def test_chapter_page_xss(self):
# The page in the URL used to go right on the page.
self.make_course(pdf_textbooks=[PDF_BOOK])
# It's no longer possible to use a non-integer page and a non-integer chapter.
with self.assertRaises(NoReverseMatch):
self.make_url('pdf_book', book_index=0, chapter='fooey', page='xyzzy')
def test_static_url_map_contentstore(self):
"""
This ensure static URL mapping is happening properly for
a course that uses the contentstore
"""
self.make_course(pdf_textbooks=[PORTABLE_PDF_BOOK])
url = self.make_url('pdf_book', book_index=0, chapter=1)
response = self.client.get(url)
self.assertNotContains(response, 'file={}'.format(PORTABLE_PDF_BOOK['chapters'][0]['url']))
self.assertContains(response, 'file=/c4x/{0.org}/{0.course}/asset/{1}'.format(
self.course.location,
PORTABLE_PDF_BOOK['chapters'][0]['url'].replace('/static/', '')))
def test_static_url_map_static_asset_path(self):
"""
Like above, but used when the course has set a static_asset_path
"""
self.make_course(pdf_textbooks=[PORTABLE_PDF_BOOK], static_asset_path='awesomesauce')
url = self.make_url('pdf_book', book_index=0, chapter=1)
response = self.client.get(url)
self.assertNotContains(response, 'file={}'.format(PORTABLE_PDF_BOOK['chapters'][0]['url']))
self.assertNotContains(response, 'file=/c4x/{0.org}/{0.course}/asset/{1}'.format(
self.course.location,
PORTABLE_PDF_BOOK['chapters'][0]['url'].replace('/static/', '')))
self.assertContains(response, 'file=/static/awesomesauce/{}'.format(
PORTABLE_PDF_BOOK['chapters'][0]['url'].replace('/static/', '')))
def test_invalid_chapter_id(self):
"""
Test that 1st chapter is displayed to the user when an invalid chapter id is provided
"""
self.make_course(pdf_textbooks=[PDF_BOOK])
invalid_chapter = len(PDF_BOOK['chapters']) + 1
url = self.make_url('pdf_book', book_index=0, chapter=invalid_chapter)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Chapter 1 for PDF")
class StaticHtmlBookTest(StaticBookTest):
"""
Test the HTML static book view.
"""
def test_book(self):
# We can access a book.
self.make_course(html_textbooks=[HTML_BOOK])
url = self.make_url('html_book', book_index=0)
response = self.client.get(url)
self.assertContains(response, "Chapter 1 for HTML")
self.assertNotContains(response, "options.chapterNum =")
def test_book_chapter(self):
# We can access a book at a particular chapter.
self.make_course(html_textbooks=[HTML_BOOK])
url = self.make_url('html_book', book_index=0, chapter=2)
response = self.client.get(url)
self.assertContains(response, "Chapter 2 for HTML")
self.assertContains(response, "options.chapterNum = 2;")
def test_bad_book_id(self):
# If we have one book, asking for the second book will fail with a 404.
self.make_course(html_textbooks=[HTML_BOOK])
url = self.make_url('html_book', book_index=1, chapter=1)
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
def test_no_book(self):
# If we have no books, asking for the first book will fail with a 404.
self.make_course()
url = self.make_url('html_book', book_index=0, chapter=1)
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
def test_chapter_xss(self):
# The chapter in the URL used to go right on the page.
self.make_course(pdf_textbooks=[HTML_BOOK])
# It's no longer possible to use a non-integer chapter.
with self.assertRaises(NoReverseMatch):
self.make_url('html_book', book_index=0, chapter='xyzzy')
|
agpl-3.0
|
[
624,
199,
774,
314,
21577,
15,
1986,
2706,
6858,
14,
199,
624,
199,
199,
646,
13390,
199,
199,
646,
1683,
199,
646,
4145,
199,
504,
1639,
14,
3603,
492,
32036,
12,
3837,
199,
504,
3816,
492,
1318,
63,
466,
199,
199,
504,
6474,
14,
2219,
14,
15406,
492,
18946,
2927,
12,
16047,
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,
199,
199,
9438,
63,
21155,
275,
1689,
2493,
6047,
4516,
2706,
401,
298,
1014,
921,
2694,
14,
957,
15,
1589,
63,
2706,
13589,
199,
199,
7638,
63,
21155,
275,
469,
272,
298,
2902,
63,
1213,
582,
298,
1872,
2706,
401,
272,
298,
1213,
582,
298,
33,
15537,
4516,
2706,
401,
272,
298,
335,
12552,
582,
359,
267,
2420,
1213,
582,
298,
30791,
413,
367,
15537,
401,
298,
633,
582,
298,
2859,
921,
3972,
1102,
14,
957,
15,
1589,
63,
2706,
15,
28765,
17,
14,
5607,
6018,
267,
2420,
1213,
582,
298,
30791,
499,
367,
15537,
401,
298,
633,
582,
298,
2859,
921,
3972,
1102,
14,
957,
15,
1589,
63,
2706,
15,
28765,
18,
14,
5607,
6018,
272,
2156,
199,
93,
199,
199,
3657,
2617,
63,
7638,
63,
21155,
275,
469,
272,
298,
2902,
63,
1213,
582,
298,
1872,
2706,
401,
272,
298,
1213,
582,
298,
33,
15537,
4516,
2706,
401,
272,
298,
335,
12552,
582,
359,
267,
2420,
1213,
582,
298,
30791,
413,
367,
15537,
401,
298,
633,
582,
3286,
1986,
15,
28765,
17,
14,
5607,
6018,
267,
2420,
1213,
582,
298,
30791,
499,
367,
15537,
401,
298,
633,
582,
3286,
1986,
15,
28765,
18,
14,
5607,
6018,
272,
2156,
199,
93,
199,
199,
4943,
63,
21155,
275,
469,
272,
298,
2902,
63,
1213,
582,
298,
1872,
2706,
401,
272,
298,
1213,
582,
298,
2493,
4163,
4516,
2706,
401,
272,
298,
335,
12552,
582,
359,
267,
2420,
1213,
582,
298,
30791,
413,
367,
4163,
401,
298,
633,
582,
298,
2859,
921,
3972,
1102,
14,
957,
15,
1589,
63,
2706,
15,
28765,
17,
14,
1360,
6018,
267,
2420,
1213,
582,
298,
30791,
499,
367,
4163,
401,
298,
633,
582,
298,
2859,
921,
3972,
1102,
14,
957,
15,
1589,
63,
2706,
15,
28765,
18,
14,
1360,
6018,
272,
2156,
199,
93,
421,
199,
533,
13599,
8696,
774,
8,
27863,
304,
272,
408,
272,
11642,
83,
367,
314,
2955,
6719,
2295,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
9278,
8696,
774,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
1972,
275,
488,
339,
347,
1852,
63,
1972,
8,
277,
12,
1011,
958,
304,
267,
408,
267,
4155,
282,
2518,
543,
376,
26802,
10367,
13,
262,
6474,
14,
267,
408,
267,
291,
14,
1972,
275,
17862,
14,
981,
3682,
958,
9,
267,
922,
275,
16047,
14,
981,
342,
267,
18946,
2927,
14,
981,
8,
751,
29,
751,
12,
2518,
63,
344,
29,
277,
14,
1972,
14,
344,
9,
267,
291,
14,
1258,
14,
2886,
8,
2473,
29,
751,
14,
2473,
12,
2505,
534,
396,
358,
339,
347,
1852,
63,
633,
8,
277,
12,
1166,
63,
354,
12,
1011,
958,
304,
267,
408,
267,
4155,
282,
2851,
367,
282,
658,
633,
63,
354,
64,
1808,
4252,
1249,
367,
1166,
14319,
14,
398,
9195,
17174,
6571,
314,
2518,
1305,
14,
398,
408,
267,
2074,
459,
1972,
63,
344,
418,
275,
1318,
63,
466,
8,
277,
14,
1972,
14,
344,
9,
267,
1166,
275,
3837,
8,
633,
63,
354,
12,
2074,
29,
958,
9,
267,
372,
1166,
421,
199,
533,
13599,
3491,
8696,
774,
8,
9278,
8696,
774,
304,
272,
408,
272,
1379,
314,
1834,
13,
6788,
2955,
6719,
2455,
14,
272,
408,
339,
347,
511,
63,
2706,
8,
277,
304,
267,
327,
2136,
883,
2879,
282,
6719,
14,
267,
543,
1683,
14,
2068,
14,
785,
8,
6615,
12,
283,
362,
358,
465,
1683,
63,
362,
26,
288,
1683,
63,
362,
14,
1107,
63,
585,
14,
505,
275,
13390,
14,
14674,
10505,
60,
355,
665,
31,
1652,
1015,
628,
17,
14,
16,
24327,
355,
665,
1224,
63,
1618,
63,
4407,
30,
355,
665,
2373,
2034,
628,
25,
2,
2034,
63,
1302,
628,
1148,
2,
536,
628,
11383,
1,
31,
7897,
355,
665,
2373,
2034,
628,
17,
2,
2034,
63,
1302,
628,
73,
2,
536,
628,
29423,
1743,
490,
665,
2373,
2034,
628,
20,
2,
2034,
63,
1302,
628,
1003,
2,
536,
628,
18816,
314,
662,
274,
838,
2285,
7897,
355,
3068,
2373,
30,
355,
3068,
1224,
63,
1618,
63,
4407,
30,
355,
21464,
953,
291,
14,
1875,
63,
1972,
8,
505,
8858,
1524,
9438,
63,
21155,
566,
288,
1166,
275,
291,
14,
1875,
63,
633,
360,
2706,
297,
6719,
63,
1080,
29,
16,
9,
288,
1177,
275,
291,
14,
1258,
14,
362,
8,
633,
9,
398,
291,
14,
9535,
8,
1310,
12,
298,
11383,
1,
18582,
267,
291,
14,
9535,
8,
1310,
12,
298,
18816,
314,
662,
274,
838,
2285,
531,
339,
347,
511,
63,
4087,
63,
2706,
63,
344,
8,
277,
304,
267,
327,
437,
4875,
6719,
1305,
911,
506,
282,
7901,
14,
267,
291,
14,
1875,
63,
1972,
8,
505,
8858,
1524,
9438,
63,
21155,
566,
267,
543,
291,
14,
1855,
8,
1944,
25249,
304,
288,
291,
14,
1875,
63,
633,
360,
2706,
297,
6719,
63,
1080,
534,
1421,
14655,
358,
339,
347,
511,
63,
548,
63,
1618,
63,
1842,
63,
2706,
63,
344,
8,
277,
304,
267,
291,
14,
1875,
63,
1972,
342,
267,
1166,
275,
291,
14,
1875,
63,
633,
360,
2706,
297,
6719,
63,
1080,
29,
16,
9,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
633,
9,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
7901,
9,
339,
347,
511,
63,
4087,
63,
1606,
63,
344,
8,
277,
304,
267,
327,
437,
4875,
2034,
1305,
911,
7675,
282,
7901,
14,
267,
291,
14,
1875,
63,
1972,
8,
505,
8858,
1524,
9438,
63,
21155,
566,
267,
543,
291,
14,
1855,
8,
1944,
25249,
304,
288,
291,
14,
1875,
63,
633,
360,
2706,
297,
6719,
63,
1080,
29,
16,
12,
2034,
534,
8568,
3605,
358,
421,
199,
533,
13599
] |
[
199,
774,
314,
21577,
15,
1986,
2706,
6858,
14,
199,
624,
199,
199,
646,
13390,
199,
199,
646,
1683,
199,
646,
4145,
199,
504,
1639,
14,
3603,
492,
32036,
12,
3837,
199,
504,
3816,
492,
1318,
63,
466,
199,
199,
504,
6474,
14,
2219,
14,
15406,
492,
18946,
2927,
12,
16047,
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,
199,
199,
9438,
63,
21155,
275,
1689,
2493,
6047,
4516,
2706,
401,
298,
1014,
921,
2694,
14,
957,
15,
1589,
63,
2706,
13589,
199,
199,
7638,
63,
21155,
275,
469,
272,
298,
2902,
63,
1213,
582,
298,
1872,
2706,
401,
272,
298,
1213,
582,
298,
33,
15537,
4516,
2706,
401,
272,
298,
335,
12552,
582,
359,
267,
2420,
1213,
582,
298,
30791,
413,
367,
15537,
401,
298,
633,
582,
298,
2859,
921,
3972,
1102,
14,
957,
15,
1589,
63,
2706,
15,
28765,
17,
14,
5607,
6018,
267,
2420,
1213,
582,
298,
30791,
499,
367,
15537,
401,
298,
633,
582,
298,
2859,
921,
3972,
1102,
14,
957,
15,
1589,
63,
2706,
15,
28765,
18,
14,
5607,
6018,
272,
2156,
199,
93,
199,
199,
3657,
2617,
63,
7638,
63,
21155,
275,
469,
272,
298,
2902,
63,
1213,
582,
298,
1872,
2706,
401,
272,
298,
1213,
582,
298,
33,
15537,
4516,
2706,
401,
272,
298,
335,
12552,
582,
359,
267,
2420,
1213,
582,
298,
30791,
413,
367,
15537,
401,
298,
633,
582,
3286,
1986,
15,
28765,
17,
14,
5607,
6018,
267,
2420,
1213,
582,
298,
30791,
499,
367,
15537,
401,
298,
633,
582,
3286,
1986,
15,
28765,
18,
14,
5607,
6018,
272,
2156,
199,
93,
199,
199,
4943,
63,
21155,
275,
469,
272,
298,
2902,
63,
1213,
582,
298,
1872,
2706,
401,
272,
298,
1213,
582,
298,
2493,
4163,
4516,
2706,
401,
272,
298,
335,
12552,
582,
359,
267,
2420,
1213,
582,
298,
30791,
413,
367,
4163,
401,
298,
633,
582,
298,
2859,
921,
3972,
1102,
14,
957,
15,
1589,
63,
2706,
15,
28765,
17,
14,
1360,
6018,
267,
2420,
1213,
582,
298,
30791,
499,
367,
4163,
401,
298,
633,
582,
298,
2859,
921,
3972,
1102,
14,
957,
15,
1589,
63,
2706,
15,
28765,
18,
14,
1360,
6018,
272,
2156,
199,
93,
421,
199,
533,
13599,
8696,
774,
8,
27863,
304,
272,
408,
272,
11642,
83,
367,
314,
2955,
6719,
2295,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
9278,
8696,
774,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
1972,
275,
488,
339,
347,
1852,
63,
1972,
8,
277,
12,
1011,
958,
304,
267,
408,
267,
4155,
282,
2518,
543,
376,
26802,
10367,
13,
262,
6474,
14,
267,
408,
267,
291,
14,
1972,
275,
17862,
14,
981,
3682,
958,
9,
267,
922,
275,
16047,
14,
981,
342,
267,
18946,
2927,
14,
981,
8,
751,
29,
751,
12,
2518,
63,
344,
29,
277,
14,
1972,
14,
344,
9,
267,
291,
14,
1258,
14,
2886,
8,
2473,
29,
751,
14,
2473,
12,
2505,
534,
396,
358,
339,
347,
1852,
63,
633,
8,
277,
12,
1166,
63,
354,
12,
1011,
958,
304,
267,
408,
267,
4155,
282,
2851,
367,
282,
658,
633,
63,
354,
64,
1808,
4252,
1249,
367,
1166,
14319,
14,
398,
9195,
17174,
6571,
314,
2518,
1305,
14,
398,
408,
267,
2074,
459,
1972,
63,
344,
418,
275,
1318,
63,
466,
8,
277,
14,
1972,
14,
344,
9,
267,
1166,
275,
3837,
8,
633,
63,
354,
12,
2074,
29,
958,
9,
267,
372,
1166,
421,
199,
533,
13599,
3491,
8696,
774,
8,
9278,
8696,
774,
304,
272,
408,
272,
1379,
314,
1834,
13,
6788,
2955,
6719,
2455,
14,
272,
408,
339,
347,
511,
63,
2706,
8,
277,
304,
267,
327,
2136,
883,
2879,
282,
6719,
14,
267,
543,
1683,
14,
2068,
14,
785,
8,
6615,
12,
283,
362,
358,
465,
1683,
63,
362,
26,
288,
1683,
63,
362,
14,
1107,
63,
585,
14,
505,
275,
13390,
14,
14674,
10505,
60,
355,
665,
31,
1652,
1015,
628,
17,
14,
16,
24327,
355,
665,
1224,
63,
1618,
63,
4407,
30,
355,
665,
2373,
2034,
628,
25,
2,
2034,
63,
1302,
628,
1148,
2,
536,
628,
11383,
1,
31,
7897,
355,
665,
2373,
2034,
628,
17,
2,
2034,
63,
1302,
628,
73,
2,
536,
628,
29423,
1743,
490,
665,
2373,
2034,
628,
20,
2,
2034,
63,
1302,
628,
1003,
2,
536,
628,
18816,
314,
662,
274,
838,
2285,
7897,
355,
3068,
2373,
30,
355,
3068,
1224,
63,
1618,
63,
4407,
30,
355,
21464,
953,
291,
14,
1875,
63,
1972,
8,
505,
8858,
1524,
9438,
63,
21155,
566,
288,
1166,
275,
291,
14,
1875,
63,
633,
360,
2706,
297,
6719,
63,
1080,
29,
16,
9,
288,
1177,
275,
291,
14,
1258,
14,
362,
8,
633,
9,
398,
291,
14,
9535,
8,
1310,
12,
298,
11383,
1,
18582,
267,
291,
14,
9535,
8,
1310,
12,
298,
18816,
314,
662,
274,
838,
2285,
531,
339,
347,
511,
63,
4087,
63,
2706,
63,
344,
8,
277,
304,
267,
327,
437,
4875,
6719,
1305,
911,
506,
282,
7901,
14,
267,
291,
14,
1875,
63,
1972,
8,
505,
8858,
1524,
9438,
63,
21155,
566,
267,
543,
291,
14,
1855,
8,
1944,
25249,
304,
288,
291,
14,
1875,
63,
633,
360,
2706,
297,
6719,
63,
1080,
534,
1421,
14655,
358,
339,
347,
511,
63,
548,
63,
1618,
63,
1842,
63,
2706,
63,
344,
8,
277,
304,
267,
291,
14,
1875,
63,
1972,
342,
267,
1166,
275,
291,
14,
1875,
63,
633,
360,
2706,
297,
6719,
63,
1080,
29,
16,
9,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
633,
9,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
7901,
9,
339,
347,
511,
63,
4087,
63,
1606,
63,
344,
8,
277,
304,
267,
327,
437,
4875,
2034,
1305,
911,
7675,
282,
7901,
14,
267,
291,
14,
1875,
63,
1972,
8,
505,
8858,
1524,
9438,
63,
21155,
566,
267,
543,
291,
14,
1855,
8,
1944,
25249,
304,
288,
291,
14,
1875,
63,
633,
360,
2706,
297,
6719,
63,
1080,
29,
16,
12,
2034,
534,
8568,
3605,
358,
421,
199,
533,
13599,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
apuigsech/CryptoAPI
|
CryptoAPI/CryptoAPI.py
|
1
|
8197
|
#!/usr/bin/env python
# CryptoAPI: Python Crypto API implementation
#
# Copyright (c) 2014 - Albert Puigsech Galicia (albert@puigsech.com)
#
# 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.
from CryptsyAPI import CryptsyAPI
from BittrexAPI import BittrexAPI
class CryptoAPI_iface(object):
def balances(self, currency=None, cached=None):
raise NotImplementedError( "Method not implemented" )
def marketstatus(self, market=None, depth_level=None, cached=None):
raise NotImplementedError( "Method not implemented" )
def orders(self, market=None, cached=None):
raise NotImplementedError( "Method not implemented" )
def putorder(self, market, type, pricetype, amount, price=None, simulation=None):
raise NotImplementedError( "Method not implemented" )
def delorder(self, order_id=None, simulation=None):
raise NotImplementedError( "Method not implemented" )
class CryptoAPI_cryptsy(CryptsyAPI, CryptoAPI_iface):
def __init__(self, key, secret, simulation=False, cached=False):
super(CryptoAPI_cryptsy, self).__init__(key, secret, simulation, cached)
CryptoAPI_iface.__init__(self)
def balances(self, currency=None, cached=None):
if cached == None:
cached = self.cached
ret = {
'available': {},
'hold': {},
'total': {},
}
info = self.getinfo(cached)['return']
for i in info['balances_available']:
if i == currency or (currency == None and (float(info['balances_available'][i]) > 0 or info['balances_hold'].has_key(i))):
ret['available'][i] = float(info['balances_available'][i])
ret['hold'][i] = float(info['balances_hold'][i]) if info['balances_hold'].has_key(i) else float(0)
ret['total'][i] = ret['available'][i] + ret['hold'][i]
return ret
def marketstatus(self, market=None, depth_level=None, cached=None):
if cached == None:
cached = self.cached
status = self.getmarkets(cached)['return']
ret = {}
for i in status:
marketname = '{0}-{1}'.format(i['secondary_currency_code'], i['primary_currency_code'])
if marketname == market or i['primary_currency_code'] == market or i['secondary_currency_code'] == market or market == None:
ret[marketname] = {
'id': int(i['marketid']),
'last_price': float(i['last_trade']),
'high_price': float(i['high_trade']),
'low_price': float(i['low_trade']),
'volume': float(i['current_volume']),
'depth': None
}
if depth_level != None and depth_level > 0:
depth = self.depth(i['marketid'], cached)['return']
ret[marketname]['depth'] = {
'buy': [],
'sell': [],
}
for j in depth['buy'][0:depth_level]:
ret[marketname]['depth']['buy'].append([float(j[0]),float(j[1])])
for j in depth['sell'][0:depth_level]:
ret[marketname]['depth']['sell'].append([float(j[0]),float(j[1])])
return ret
def orders(self, market=None, cached=None):
if cached == None:
cached = self.cached
orders = self.allmyorders(cached)['return']
ret = []
for i in orders:
marketname = self._getmarketfromid(i['marketid'])
ret.append({
'id': int(i['orderid']),
'market': 'TBD',
'price': i['price'],
'amount': i['orig_quantity'],
'remaining_amount': i['quantity'],
})
return ret
def putorder(self, market, type, pricetype, amount, price=None, simulation=None):
if simulation == None:
simulation = self.simulation
status = self.marketstatus(market, 1)
print status
if pricetype == 'market':
price = 4294967296
elif pricetype == 'best':
if type == 'buy':
price = status[market]['depth']['sell'][0][0]
elif type == 'sell':
price = status[market]['depth']['buy'][0][0]
elif pricetype == 'border' or pricetype == 'overboder':
if type == 'buy':
price = status[market]['depth']['buy'][0][0]
elif type == 'sell':
price = status[market]['depth']['sell'][0][0]
if pricetype == 'overboder':
if type == 'buy':
price += 0.00000001
elif type == 'sell':
price -= 0.00000001
return self.createorder(status[market]['id'], type, amount, price)
def delorder(self, order_id=None, simulation=None):
return None
def _getmarketfromid(self, id):
markets = self.marketstatus(cached=True)
for marketname in markets:
if markets[marketname]['id'] == id:
return marketname
return None
def _getidfrommarket(self, market):
markets = self.marketstatus(cached=True)
if markets.has_key(market):
return markets[market]['id']
else:
return None
class CryptoAPI_bittrex(BittrexAPI, CryptoAPI_iface):
def __init__(self, key, secret, simulation=False, cached=False):
super(CryptoAPI_bittrex, self).__init__(key, secret, simulation, cached)
def balances(self, currency=None, cached=None):
if cached == None:
cached = self.cached
ret = {
'available': {},
'hold': {},
'total': {},
}
if currency==None:
info = self.getbalances(cached)['result']
else:
pass
info = [self.getbalance(currency, cached)['result']]
for i in info:
ret['available'][i['Currency']] = float(i['Available'])
ret['hold'][i['Currency']] = float(i['Pending'])
ret['total'][i['Currency']] = float(i['Balance'])
return ret
def marketstatus(self, market=None, depth_level=None, cached=None):
if cached == None:
cached = self.cached
ret = {}
status = self.getmarkets(cached)['result']
status = self.getmarketsummaries(cached)['result']
for i in status:
marketname = i['MarketName']
#if marketname == market or market == i['BaseCurrency'] or market == i['MarketCurrency'] or market == None:
if marketname == market or market in marketname or market == None:
if i['Volume'] == None:
i['Volume'] = 0
ret[marketname] = {
'id': marketname,
'last_price': float(i['Last']),
'high_price': float(str(i['High'])), # FIX a bug on Bittrex data returned
'low_price': float(i['Low']),
'volume': float(i['Volume']),
'depth': None
}
if depth_level != None and depth_level > 0:
depth = self.getorderbook(marketname, 'both', depth_level, cached)['result']
ret[marketname]['depth'] = {
'buy': [],
'sell': [],
}
for j in depth['buy'][0:depth_level]:
ret[marketname]['depth']['buy'].append([float(j['Rate']),float(j['Quantity'])])
for j in depth['sell'][0:depth_level]:
ret[marketname]['depth']['sell'].append([float(j['Rate']),float(j['Quantity'])])
return ret
def orders(self, market=None, cached=None):
if cached == None:
cached = self.cached
ret = []
orders = self.getopenorders(market, cached)['return']
for i in orders:
marketname = self._getmarketfromid(i['marketid'])
ret.append({
'id': int(i['orderid']),
'market': 'TBD',
'price': i['price'],
'amount': i['orig_quantity'],
'remaining_amount': i['quantity'],
})
return ret
pass
def putorder(self, market, type, pricetype, amount, price=None, simulation=None):
pass
def delorder(self, order_id=None, simulation=None):
pass
def CryptoAPI(type, key, secret, simulation=False, cached=False):
# TODO Security: type validation
code = 'CryptoAPI_{0}(key, secret, simulation, cached)'.format(type)
api = eval(code)
return api
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
18855,
3735,
26,
2018,
18855,
3261,
4514,
199,
3,
199,
3,
1898,
334,
67,
9,
6927,
446,
4580,
12504,
510,
85,
528,
261,
335,
598,
17999,
4674,
334,
279,
12504,
32,
3165,
528,
261,
335,
14,
957,
9,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
199,
3,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
199,
3,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
199,
3,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
199,
3,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
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,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
221,
1621,
4825,
6461,
7000,
199,
3,
2334,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
199,
3,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
199,
3,
13198,
1621,
2334,
4141,
14,
199,
199,
504,
445,
13656,
1786,
3735,
492,
445,
13656,
1786,
3735,
199,
504,
10199,
84,
15063,
3735,
492,
10199,
84,
15063,
3735,
199,
199,
533,
18855,
3735,
63,
11166,
8,
785,
304,
421,
198,
318,
8091,
13236,
8,
277,
12,
9952,
29,
403,
12,
6328,
29,
403,
304,
507,
198,
3730,
4279,
8,
298,
3767,
440,
6366,
2,
776,
421,
198,
318,
26584,
1205,
8,
277,
12,
26584,
29,
403,
12,
5818,
63,
1896,
29,
403,
12,
6328,
29,
403,
304,
507,
198,
3730,
4279,
8,
298,
3767,
440,
6366,
2,
776,
421,
198,
318,
15460,
8,
277,
12,
26584,
29,
403,
12,
6328,
29,
403,
304,
507,
198,
3730,
4279,
8,
298,
3767,
440,
6366,
2,
776,
221,
421,
198,
318,
5324,
1648,
8,
277,
12,
26584,
12,
730,
12,
8033,
466,
12,
5982,
12,
8033,
29,
403,
12,
17625,
29,
403,
304,
507,
198,
3730,
4279,
8,
298,
3767,
440,
6366,
2,
776,
421,
198,
318,
2150,
1648,
8,
277,
12,
1865,
63,
344,
29,
403,
12,
17625,
29,
403,
304,
507,
198,
3730,
4279,
8,
298,
3767,
440,
6366,
2,
776,
421,
199,
533,
18855,
3735,
63,
4997,
1786,
8,
35,
13656,
1786,
3735,
12,
18855,
3735,
63,
11166,
304,
199,
198,
318,
636,
826,
721,
277,
12,
790,
12,
7565,
12,
17625,
29,
797,
12,
6328,
29,
797,
304,
507,
198,
4792,
8,
17134,
3735,
63,
4997,
1786,
12,
291,
2843,
826,
721,
498,
12,
7565,
12,
17625,
12,
6328,
9,
507,
198,
17134,
3735,
63,
11166,
855,
826,
721,
277,
9,
421,
198,
318,
8091,
13236,
8,
277,
12,
9952,
29,
403,
12,
6328,
29,
403,
304,
507,
198,
692,
6328,
508,
488,
26,
686,
198,
5245,
275,
291,
14,
5245,
2742,
198,
3292,
275,
469,
686,
198,
7,
4561,
356,
5479,
686,
198,
7,
12239,
356,
5479,
686,
198,
1133,
1735,
356,
5479,
507,
198,
93,
2742,
198,
815,
275,
291,
14,
32286,
8,
5245,
11820,
1107,
418,
2742,
198,
509,
284,
315,
2256,
459,
7358,
83,
63,
4561,
2565,
686,
198,
692,
284,
508,
9952,
503,
334,
4968,
508,
488,
436,
334,
1609,
8,
815,
459,
7358,
83,
63,
4561,
3488,
73,
566,
690,
378,
503,
2256,
459,
7358,
83,
63,
12239,
2278,
1989,
63,
498,
8,
73,
15206,
1585,
198,
3292,
459,
4561,
3488,
73,
61,
275,
2069,
8,
815,
459,
7358,
83,
63,
4561,
3488,
73,
566,
1585,
198,
3292,
459,
12239,
3488,
73,
61,
275,
2069,
8,
815,
459,
7358,
83,
63,
12239,
3488,
73,
566,
340,
2256,
459,
7358,
83,
63,
12239,
2278,
1989,
63,
498,
8,
73,
9,
587,
2069,
8,
16,
9,
1585,
198,
3292,
459,
2923,
3488,
73,
61,
275,
2203,
459,
4561,
3488,
73,
61,
435,
2203,
459,
12239,
3488,
73,
61,
2742,
198,
1107,
2203,
4388,
198,
318,
26584,
1205,
8,
277,
12,
26584,
29,
403,
12,
5818,
63,
1896,
29,
403,
12,
6328,
29,
403,
304,
507,
198,
692,
6328,
508,
488,
26,
686,
198,
5245,
275,
291,
14,
5245,
2742,
198,
1205,
275,
291,
14,
362,
1657,
8716,
8,
5245,
11820,
1107,
418,
9068,
198,
3292,
275,
1052,
2742,
198,
509,
284,
315,
2004,
26,
686,
198,
22270,
354,
275,
5041,
16,
30289,
17,
5285,
908,
8,
73,
459,
12371,
63,
4968,
63,
600,
995,
284,
459,
3327,
63,
4968,
63,
600,
1105,
686,
198,
692,
26584,
354,
508,
26584,
503,
284,
459,
3327,
63,
4968,
63,
600,
418,
508,
26584,
503,
284,
459,
12371,
63,
4968,
63,
600,
418,
508,
26584,
503,
26584,
508,
488,
26,
1585,
198,
3292,
59,
22270,
354,
61,
275,
469,
1871,
198,
7,
344,
356,
1109,
8,
73,
459,
4584,
415,
5700,
3815,
1871,
198,
7,
2019,
63,
4777,
356,
2069,
8,
73,
459,
2019,
63,
21697,
3815,
1871,
198,
7,
6260,
63,
4777,
356,
2069,
8,
73,
459,
6260,
63,
21697,
3815,
1871,
198,
7,
674,
63,
4777,
356,
2069,
8,
73,
459,
674,
63,
21697,
3815,
1871,
198,
7,
2405,
356,
2069,
8,
73,
459,
1818,
63,
2405,
3815,
1871,
198,
5121,
1545,
273,
356,
488,
1585,
198,
93,
1585,
198,
692,
5818,
63,
1896,
1137,
488,
436,
5818,
63,
1896,
690,
378,
26,
1871,
198,
4631,
275,
291,
14,
4631,
8,
73,
459,
4584,
415,
5700,
995,
6328,
11820,
1107,
418,
28558,
198,
3292,
59,
22270,
354,
2733,
4631,
418,
275,
469,
4671,
198,
7,
31240,
356,
990,
4671,
198,
1159,
1697,
356,
990,
1871,
198,
93,
28558,
198,
509,
1335,
315,
5818,
459,
31240,
3488,
16,
26
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
18855,
3735,
26,
2018,
18855,
3261,
4514,
199,
3,
199,
3,
1898,
334,
67,
9,
6927,
446,
4580,
12504,
510,
85,
528,
261,
335,
598,
17999,
4674,
334,
279,
12504,
32,
3165,
528,
261,
335,
14,
957,
9,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
199,
3,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
199,
3,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
199,
3,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
199,
3,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
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,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
221,
1621,
4825,
6461,
7000,
199,
3,
2334,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
199,
3,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
199,
3,
13198,
1621,
2334,
4141,
14,
199,
199,
504,
445,
13656,
1786,
3735,
492,
445,
13656,
1786,
3735,
199,
504,
10199,
84,
15063,
3735,
492,
10199,
84,
15063,
3735,
199,
199,
533,
18855,
3735,
63,
11166,
8,
785,
304,
421,
198,
318,
8091,
13236,
8,
277,
12,
9952,
29,
403,
12,
6328,
29,
403,
304,
507,
198,
3730,
4279,
8,
298,
3767,
440,
6366,
2,
776,
421,
198,
318,
26584,
1205,
8,
277,
12,
26584,
29,
403,
12,
5818,
63,
1896,
29,
403,
12,
6328,
29,
403,
304,
507,
198,
3730,
4279,
8,
298,
3767,
440,
6366,
2,
776,
421,
198,
318,
15460,
8,
277,
12,
26584,
29,
403,
12,
6328,
29,
403,
304,
507,
198,
3730,
4279,
8,
298,
3767,
440,
6366,
2,
776,
221,
421,
198,
318,
5324,
1648,
8,
277,
12,
26584,
12,
730,
12,
8033,
466,
12,
5982,
12,
8033,
29,
403,
12,
17625,
29,
403,
304,
507,
198,
3730,
4279,
8,
298,
3767,
440,
6366,
2,
776,
421,
198,
318,
2150,
1648,
8,
277,
12,
1865,
63,
344,
29,
403,
12,
17625,
29,
403,
304,
507,
198,
3730,
4279,
8,
298,
3767,
440,
6366,
2,
776,
421,
199,
533,
18855,
3735,
63,
4997,
1786,
8,
35,
13656,
1786,
3735,
12,
18855,
3735,
63,
11166,
304,
199,
198,
318,
636,
826,
721,
277,
12,
790,
12,
7565,
12,
17625,
29,
797,
12,
6328,
29,
797,
304,
507,
198,
4792,
8,
17134,
3735,
63,
4997,
1786,
12,
291,
2843,
826,
721,
498,
12,
7565,
12,
17625,
12,
6328,
9,
507,
198,
17134,
3735,
63,
11166,
855,
826,
721,
277,
9,
421,
198,
318,
8091,
13236,
8,
277,
12,
9952,
29,
403,
12,
6328,
29,
403,
304,
507,
198,
692,
6328,
508,
488,
26,
686,
198,
5245,
275,
291,
14,
5245,
2742,
198,
3292,
275,
469,
686,
198,
7,
4561,
356,
5479,
686,
198,
7,
12239,
356,
5479,
686,
198,
1133,
1735,
356,
5479,
507,
198,
93,
2742,
198,
815,
275,
291,
14,
32286,
8,
5245,
11820,
1107,
418,
2742,
198,
509,
284,
315,
2256,
459,
7358,
83,
63,
4561,
2565,
686,
198,
692,
284,
508,
9952,
503,
334,
4968,
508,
488,
436,
334,
1609,
8,
815,
459,
7358,
83,
63,
4561,
3488,
73,
566,
690,
378,
503,
2256,
459,
7358,
83,
63,
12239,
2278,
1989,
63,
498,
8,
73,
15206,
1585,
198,
3292,
459,
4561,
3488,
73,
61,
275,
2069,
8,
815,
459,
7358,
83,
63,
4561,
3488,
73,
566,
1585,
198,
3292,
459,
12239,
3488,
73,
61,
275,
2069,
8,
815,
459,
7358,
83,
63,
12239,
3488,
73,
566,
340,
2256,
459,
7358,
83,
63,
12239,
2278,
1989,
63,
498,
8,
73,
9,
587,
2069,
8,
16,
9,
1585,
198,
3292,
459,
2923,
3488,
73,
61,
275,
2203,
459,
4561,
3488,
73,
61,
435,
2203,
459,
12239,
3488,
73,
61,
2742,
198,
1107,
2203,
4388,
198,
318,
26584,
1205,
8,
277,
12,
26584,
29,
403,
12,
5818,
63,
1896,
29,
403,
12,
6328,
29,
403,
304,
507,
198,
692,
6328,
508,
488,
26,
686,
198,
5245,
275,
291,
14,
5245,
2742,
198,
1205,
275,
291,
14,
362,
1657,
8716,
8,
5245,
11820,
1107,
418,
9068,
198,
3292,
275,
1052,
2742,
198,
509,
284,
315,
2004,
26,
686,
198,
22270,
354,
275,
5041,
16,
30289,
17,
5285,
908,
8,
73,
459,
12371,
63,
4968,
63,
600,
995,
284,
459,
3327,
63,
4968,
63,
600,
1105,
686,
198,
692,
26584,
354,
508,
26584,
503,
284,
459,
3327,
63,
4968,
63,
600,
418,
508,
26584,
503,
284,
459,
12371,
63,
4968,
63,
600,
418,
508,
26584,
503,
26584,
508,
488,
26,
1585,
198,
3292,
59,
22270,
354,
61,
275,
469,
1871,
198,
7,
344,
356,
1109,
8,
73,
459,
4584,
415,
5700,
3815,
1871,
198,
7,
2019,
63,
4777,
356,
2069,
8,
73,
459,
2019,
63,
21697,
3815,
1871,
198,
7,
6260,
63,
4777,
356,
2069,
8,
73,
459,
6260,
63,
21697,
3815,
1871,
198,
7,
674,
63,
4777,
356,
2069,
8,
73,
459,
674,
63,
21697,
3815,
1871,
198,
7,
2405,
356,
2069,
8,
73,
459,
1818,
63,
2405,
3815,
1871,
198,
5121,
1545,
273,
356,
488,
1585,
198,
93,
1585,
198,
692,
5818,
63,
1896,
1137,
488,
436,
5818,
63,
1896,
690,
378,
26,
1871,
198,
4631,
275,
291,
14,
4631,
8,
73,
459,
4584,
415,
5700,
995,
6328,
11820,
1107,
418,
28558,
198,
3292,
59,
22270,
354,
2733,
4631,
418,
275,
469,
4671,
198,
7,
31240,
356,
990,
4671,
198,
1159,
1697,
356,
990,
1871,
198,
93,
28558,
198,
509,
1335,
315,
5818,
459,
31240,
3488,
16,
26,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
maniteja123/sympy
|
sympy/physics/quantum/tests/test_cg.py
|
64
|
8623
|
from __future__ import division
from sympy import S, sqrt, Sum, symbols
from sympy.physics.quantum.cg import Wigner3j, Wigner6j, Wigner9j, CG, cg_simp
from sympy.functions.special.tensor_functions import KroneckerDelta
from sympy.utilities.pytest import slow
@slow
def test_cg_simp_add():
j, m1, m1p, m2, m2p = symbols('j m1 m1p m2 m2p')
# Test Varshalovich 8.7.1 Eq 1
a = CG(S(1)/2, S(1)/2, 0, 0, S(1)/2, S(1)/2)
b = CG(S(1)/2, -S(1)/2, 0, 0, S(1)/2, -S(1)/2)
c = CG(1, 1, 0, 0, 1, 1)
d = CG(1, 0, 0, 0, 1, 0)
e = CG(1, -1, 0, 0, 1, -1)
assert cg_simp(a + b) == 2
assert cg_simp(c + d + e) == 3
assert cg_simp(a + b + c + d + e) == 5
assert cg_simp(a + b + c) == 2 + c
assert cg_simp(2*a + b) == 2 + a
assert cg_simp(2*c + d + e) == 3 + c
assert cg_simp(5*a + 5*b) == 10
assert cg_simp(5*c + 5*d + 5*e) == 15
assert cg_simp(-a - b) == -2
assert cg_simp(-c - d - e) == -3
assert cg_simp(-6*a - 6*b) == -12
assert cg_simp(-4*c - 4*d - 4*e) == -12
a = CG(S(1)/2, S(1)/2, j, 0, S(1)/2, S(1)/2)
b = CG(S(1)/2, -S(1)/2, j, 0, S(1)/2, -S(1)/2)
c = CG(1, 1, j, 0, 1, 1)
d = CG(1, 0, j, 0, 1, 0)
e = CG(1, -1, j, 0, 1, -1)
assert cg_simp(a + b) == 2*KroneckerDelta(j, 0)
assert cg_simp(c + d + e) == 3*KroneckerDelta(j, 0)
assert cg_simp(a + b + c + d + e) == 5*KroneckerDelta(j, 0)
assert cg_simp(a + b + c) == 2*KroneckerDelta(j, 0) + c
assert cg_simp(2*a + b) == 2*KroneckerDelta(j, 0) + a
assert cg_simp(2*c + d + e) == 3*KroneckerDelta(j, 0) + c
assert cg_simp(5*a + 5*b) == 10*KroneckerDelta(j, 0)
assert cg_simp(5*c + 5*d + 5*e) == 15*KroneckerDelta(j, 0)
assert cg_simp(-a - b) == -2*KroneckerDelta(j, 0)
assert cg_simp(-c - d - e) == -3*KroneckerDelta(j, 0)
assert cg_simp(-6*a - 6*b) == -12*KroneckerDelta(j, 0)
assert cg_simp(-4*c - 4*d - 4*e) == -12*KroneckerDelta(j, 0)
# Test Varshalovich 8.7.1 Eq 2
a = CG(S(1)/2, S(1)/2, S(1)/2, -S(1)/2, 0, 0)
b = CG(S(1)/2, -S(1)/2, S(1)/2, S(1)/2, 0, 0)
c = CG(1, 1, 1, -1, 0, 0)
d = CG(1, 0, 1, 0, 0, 0)
e = CG(1, -1, 1, 1, 0, 0)
assert cg_simp(a - b) == sqrt(2)
assert cg_simp(c - d + e) == sqrt(3)
assert cg_simp(a - b + c - d + e) == sqrt(2) + sqrt(3)
assert cg_simp(a - b + c) == sqrt(2) + c
assert cg_simp(2*a - b) == sqrt(2) + a
assert cg_simp(2*c - d + e) == sqrt(3) + c
assert cg_simp(5*a - 5*b) == 5*sqrt(2)
assert cg_simp(5*c - 5*d + 5*e) == 5*sqrt(3)
assert cg_simp(-a + b) == -sqrt(2)
assert cg_simp(-c + d - e) == -sqrt(3)
assert cg_simp(-6*a + 6*b) == -6*sqrt(2)
assert cg_simp(-4*c + 4*d - 4*e) == -4*sqrt(3)
a = CG(S(1)/2, S(1)/2, S(1)/2, -S(1)/2, j, 0)
b = CG(S(1)/2, -S(1)/2, S(1)/2, S(1)/2, j, 0)
c = CG(1, 1, 1, -1, j, 0)
d = CG(1, 0, 1, 0, j, 0)
e = CG(1, -1, 1, 1, j, 0)
assert cg_simp(a - b) == sqrt(2)*KroneckerDelta(j, 0)
assert cg_simp(c - d + e) == sqrt(3)*KroneckerDelta(j, 0)
assert cg_simp(a - b + c - d + e) == sqrt(
2)*KroneckerDelta(j, 0) + sqrt(3)*KroneckerDelta(j, 0)
assert cg_simp(a - b + c) == sqrt(2)*KroneckerDelta(j, 0) + c
assert cg_simp(2*a - b) == sqrt(2)*KroneckerDelta(j, 0) + a
assert cg_simp(2*c - d + e) == sqrt(3)*KroneckerDelta(j, 0) + c
assert cg_simp(5*a - 5*b) == 5*sqrt(2)*KroneckerDelta(j, 0)
assert cg_simp(5*c - 5*d + 5*e) == 5*sqrt(3)*KroneckerDelta(j, 0)
assert cg_simp(-a + b) == -sqrt(2)*KroneckerDelta(j, 0)
assert cg_simp(-c + d - e) == -sqrt(3)*KroneckerDelta(j, 0)
assert cg_simp(-6*a + 6*b) == -6*sqrt(2)*KroneckerDelta(j, 0)
assert cg_simp(-4*c + 4*d - 4*e) == -4*sqrt(3)*KroneckerDelta(j, 0)
# Test Varshalovich 8.7.2 Eq 9
# alpha=alphap,beta=betap case
# numerical
a = CG(S(1)/2, S(1)/2, S(1)/2, -S(1)/2, 1, 0)**2
b = CG(S(1)/2, S(1)/2, S(1)/2, -S(1)/2, 0, 0)**2
c = CG(1, 0, 1, 1, 1, 1)**2
d = CG(1, 0, 1, 1, 2, 1)**2
assert cg_simp(a + b) == 1
assert cg_simp(c + d) == 1
assert cg_simp(a + b + c + d) == 2
assert cg_simp(4*a + 4*b) == 4
assert cg_simp(4*c + 4*d) == 4
assert cg_simp(5*a + 3*b) == 3 + 2*a
assert cg_simp(5*c + 3*d) == 3 + 2*c
assert cg_simp(-a - b) == -1
assert cg_simp(-c - d) == -1
# symbolic
a = CG(S(1)/2, m1, S(1)/2, m2, 1, 1)**2
b = CG(S(1)/2, m1, S(1)/2, m2, 1, 0)**2
c = CG(S(1)/2, m1, S(1)/2, m2, 1, -1)**2
d = CG(S(1)/2, m1, S(1)/2, m2, 0, 0)**2
assert cg_simp(a + b + c + d) == 1
assert cg_simp(4*a + 4*b + 4*c + 4*d) == 4
assert cg_simp(3*a + 5*b + 3*c + 4*d) == 3 + 2*b + d
assert cg_simp(-a - b - c - d) == -1
a = CG(1, m1, 1, m2, 2, 2)**2
b = CG(1, m1, 1, m2, 2, 1)**2
c = CG(1, m1, 1, m2, 2, 0)**2
d = CG(1, m1, 1, m2, 2, -1)**2
e = CG(1, m1, 1, m2, 2, -2)**2
f = CG(1, m1, 1, m2, 1, 1)**2
g = CG(1, m1, 1, m2, 1, 0)**2
h = CG(1, m1, 1, m2, 1, -1)**2
i = CG(1, m1, 1, m2, 0, 0)**2
assert cg_simp(a + b + c + d + e + f + g + h + i) == 1
assert cg_simp(4*(a + b + c + d + e + f + g + h + i)) == 4
assert cg_simp(a + b + 2*c + d + 4*e + f + g + h + i) == 1 + c + 3*e
assert cg_simp(-a - b - c - d - e - f - g - h - i) == -1
# alpha!=alphap or beta!=betap case
# numerical
a = CG(S(1)/2, S(
1)/2, S(1)/2, -S(1)/2, 1, 0)*CG(S(1)/2, -S(1)/2, S(1)/2, S(1)/2, 1, 0)
b = CG(S(1)/2, S(
1)/2, S(1)/2, -S(1)/2, 0, 0)*CG(S(1)/2, -S(1)/2, S(1)/2, S(1)/2, 0, 0)
c = CG(1, 1, 1, 0, 2, 1)*CG(1, 0, 1, 1, 2, 1)
d = CG(1, 1, 1, 0, 1, 1)*CG(1, 0, 1, 1, 1, 1)
assert cg_simp(a + b) == 0
assert cg_simp(c + d) == 0
# symbolic
a = CG(S(1)/2, m1, S(1)/2, m2, 1, 1)*CG(S(1)/2, m1p, S(1)/2, m2p, 1, 1)
b = CG(S(1)/2, m1, S(1)/2, m2, 1, 0)*CG(S(1)/2, m1p, S(1)/2, m2p, 1, 0)
c = CG(S(1)/2, m1, S(1)/2, m2, 1, -1)*CG(S(1)/2, m1p, S(1)/2, m2p, 1, -1)
d = CG(S(1)/2, m1, S(1)/2, m2, 0, 0)*CG(S(1)/2, m1p, S(1)/2, m2p, 0, 0)
assert cg_simp(a + b + c + d) == KroneckerDelta(m1, m1p)*KroneckerDelta(m2, m2p)
a = CG(1, m1, 1, m2, 2, 2)*CG(1, m1p, 1, m2p, 2, 2)
b = CG(1, m1, 1, m2, 2, 1)*CG(1, m1p, 1, m2p, 2, 1)
c = CG(1, m1, 1, m2, 2, 0)*CG(1, m1p, 1, m2p, 2, 0)
d = CG(1, m1, 1, m2, 2, -1)*CG(1, m1p, 1, m2p, 2, -1)
e = CG(1, m1, 1, m2, 2, -2)*CG(1, m1p, 1, m2p, 2, -2)
f = CG(1, m1, 1, m2, 1, 1)*CG(1, m1p, 1, m2p, 1, 1)
g = CG(1, m1, 1, m2, 1, 0)*CG(1, m1p, 1, m2p, 1, 0)
h = CG(1, m1, 1, m2, 1, -1)*CG(1, m1p, 1, m2p, 1, -1)
i = CG(1, m1, 1, m2, 0, 0)*CG(1, m1p, 1, m2p, 0, 0)
assert cg_simp(
a + b + c + d + e + f + g + h + i) == KroneckerDelta(m1, m1p)*KroneckerDelta(m2, m2p)
def test_cg_simp_sum():
x, a, b, c, cp, alpha, beta, gamma, gammap = symbols(
'x a b c cp alpha beta gamma gammap')
# Varshalovich 8.7.1 Eq 1
assert cg_simp(x * Sum(CG(a, alpha, b, 0, a, alpha), (alpha, -a, a)
)) == x*(2*a + 1)*KroneckerDelta(b, 0)
assert cg_simp(x * Sum(CG(a, alpha, b, 0, a, alpha), (alpha, -a, a)) + CG(1, 0, 1, 0, 1, 0)) == x*(2*a + 1)*KroneckerDelta(b, 0) + CG(1, 0, 1, 0, 1, 0)
assert cg_simp(2 * Sum(CG(1, alpha, 0, 0, 1, alpha), (alpha, -1, 1))) == 6
# Varshalovich 8.7.1 Eq 2
assert cg_simp(x*Sum((-1)**(a - alpha) * CG(a, alpha, a, -alpha, c,
0), (alpha, -a, a))) == x*sqrt(2*a + 1)*KroneckerDelta(c, 0)
assert cg_simp(3*Sum((-1)**(2 - alpha) * CG(
2, alpha, 2, -alpha, 0, 0), (alpha, -2, 2))) == 3*sqrt(5)
# Varshalovich 8.7.2 Eq 4
assert cg_simp(Sum(CG(a, alpha, b, beta, c, gamma)*CG(a, alpha, b, beta, cp, gammap), (alpha, -a, a), (beta, -b, b))) == KroneckerDelta(c, cp)*KroneckerDelta(gamma, gammap)
assert cg_simp(Sum(CG(a, alpha, b, beta, c, gamma)*CG(a, alpha, b, beta, c, gammap), (alpha, -a, a), (beta, -b, b))) == KroneckerDelta(gamma, gammap)
assert cg_simp(Sum(CG(a, alpha, b, beta, c, gamma)*CG(a, alpha, b, beta, cp, gamma), (alpha, -a, a), (beta, -b, b))) == KroneckerDelta(c, cp)
assert cg_simp(Sum(CG(
a, alpha, b, beta, c, gamma)**2, (alpha, -a, a), (beta, -b, b))) == 1
assert cg_simp(Sum(CG(2, alpha, 1, beta, 2, gamma)*CG(2, alpha, 1, beta, 2, gammap), (alpha, -2, 2), (beta, -1, 1))) == KroneckerDelta(gamma, gammap)
def test_doit():
assert Wigner3j(1/2, -1/2, 1/2, 1/2, 0, 0).doit() == -sqrt(2)/2
assert Wigner6j(1, 2, 3, 2, 1, 2).doit() == sqrt(21)/105
assert Wigner6j(3, 1, 2, 2, 2, 1).doit() == sqrt(21) / 105
assert Wigner9j(
2, 1, 1, S(3)/2, S(1)/2, 1, S(1)/2, S(1)/2, 0).doit() == sqrt(2)/12
assert CG(1/2, 1/2, 1/2, -1/2, 1, 0).doit() == sqrt(2)/2
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
4629,
199,
504,
5840,
492,
428,
12,
7452,
12,
12094,
12,
6698,
199,
504,
5840,
14,
24724,
14,
25999,
14,
12595,
492,
644,
1030,
281,
19,
74,
12,
644,
1030,
281,
22,
74,
12,
644,
1030,
281,
25,
74,
12,
18657,
12,
19711,
63,
11184,
199,
504,
5840,
14,
5777,
14,
6664,
14,
3128,
63,
5777,
492,
1804,
82,
368,
22043,
13411,
199,
504,
5840,
14,
16355,
14,
4462,
492,
11999,
421,
199,
32,
14362,
199,
318,
511,
63,
12595,
63,
11184,
63,
525,
837,
272,
1335,
12,
333,
17,
12,
333,
17,
80,
12,
333,
18,
12,
333,
18,
80,
275,
6698,
360,
74,
333,
17,
333,
17,
80,
333,
18,
333,
18,
80,
358,
272,
327,
1379,
21084,
609,
12201,
433,
335,
1695,
14,
23,
14,
17,
21779,
413,
272,
282,
275,
18657,
8,
51,
8,
17,
2447,
18,
12,
428,
8,
17,
2447,
18,
12,
378,
12,
378,
12,
428,
8,
17,
2447,
18,
12,
428,
8,
17,
2447,
18,
9,
272,
330,
275,
18657,
8,
51,
8,
17,
2447,
18,
12,
446,
51,
8,
17,
2447,
18,
12,
378,
12,
378,
12,
428,
8,
17,
2447,
18,
12,
446,
51,
8,
17,
2447,
18,
9,
272,
286,
275,
18657,
8,
17,
12,
413,
12,
378,
12,
378,
12,
413,
12,
413,
9,
272,
366,
275,
18657,
8,
17,
12,
378,
12,
378,
12,
378,
12,
413,
12,
378,
9,
272,
325,
275,
18657,
8,
17,
12,
446,
17,
12,
378,
12,
378,
12,
413,
12,
446,
17,
9,
272,
702,
19711,
63,
11184,
8,
65,
435,
330,
9,
508,
499,
272,
702,
19711,
63,
11184,
8,
67,
435,
366,
435,
325,
9,
508,
650,
272,
702,
19711,
63,
11184,
8,
65,
435,
330,
435,
286,
435,
366,
435,
325,
9,
508,
959,
272,
702,
19711,
63,
11184,
8,
65,
435,
330,
435,
286,
9,
508,
499,
435,
286,
272,
702,
19711,
63,
11184,
8,
18,
10,
65,
435,
330,
9,
508,
499,
435,
282,
272,
702,
19711,
63,
11184,
8,
18,
10,
67,
435,
366,
435,
325,
9,
508,
650,
435,
286,
272,
702,
19711,
63,
11184,
8,
21,
10,
65,
435,
959,
10,
66,
9,
508,
1616,
272,
702,
19711,
63,
11184,
8,
21,
10,
67,
435,
959,
10,
68,
435,
959,
10,
69,
9,
508,
4114,
272,
702,
19711,
63,
11184,
2801,
65,
446,
330,
9,
508,
446,
18,
272,
702,
19711,
63,
11184,
2801,
67,
446,
366,
446,
325,
9,
508,
446,
19,
272,
702,
19711,
63,
11184,
2801,
22,
10,
65,
446,
1227,
10,
66,
9,
508,
446,
713,
272,
702,
19711,
63,
11184,
2801,
20,
10,
67,
446,
841,
10,
68,
446,
841,
10,
69,
9,
508,
446,
713,
272,
282,
275,
18657,
8,
51,
8,
17,
2447,
18,
12,
428,
8,
17,
2447,
18,
12,
1335,
12,
378,
12,
428,
8,
17,
2447,
18,
12,
428,
8,
17,
2447,
18,
9,
272,
330,
275,
18657,
8,
51,
8,
17,
2447,
18,
12,
446,
51,
8,
17,
2447,
18,
12,
1335,
12,
378,
12,
428,
8,
17,
2447,
18,
12,
446,
51,
8,
17,
2447,
18,
9,
272,
286,
275,
18657,
8,
17,
12,
413,
12,
1335,
12,
378,
12,
413,
12,
413,
9,
272,
366,
275,
18657,
8,
17,
12,
378,
12,
1335,
12,
378,
12,
413,
12,
378,
9,
272,
325,
275,
18657,
8,
17,
12,
446,
17,
12,
1335,
12,
378,
12,
413,
12,
446,
17,
9,
272,
702,
19711,
63,
11184,
8,
65,
435,
330,
9,
508,
499,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
272,
702,
19711,
63,
11184,
8,
67,
435,
366,
435,
325,
9,
508,
650,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
272,
702,
19711,
63,
11184,
8,
65,
435,
330,
435,
286,
435,
366,
435,
325,
9,
508,
959,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
272,
702,
19711,
63,
11184,
8,
65,
435,
330,
435,
286,
9,
508,
499,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
435,
286,
272,
702,
19711,
63,
11184,
8,
18,
10,
65,
435,
330,
9,
508,
499,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
435,
282,
272,
702,
19711,
63,
11184,
8,
18,
10,
67,
435,
366,
435,
325,
9,
508,
650,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
435,
286,
272,
702,
19711,
63,
11184,
8,
21,
10,
65,
435,
959,
10,
66,
9,
508,
1616,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
272,
702,
19711,
63,
11184,
8,
21,
10,
67,
435,
959,
10,
68,
435,
959,
10,
69,
9,
508,
4114,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
272,
702,
19711,
63,
11184,
2801,
65,
446,
330,
9,
508,
446,
18,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
272,
702,
19711,
63,
11184,
2801,
67,
446,
366,
446,
325,
9,
508,
446,
19,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
272,
702,
19711,
63,
11184,
2801,
22,
10,
65,
446,
1227,
10,
66,
9,
508,
446,
713,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
272,
702,
19711,
63,
11184,
2801,
20,
10,
67,
446,
841,
10,
68,
446,
841,
10,
69,
9,
508,
446,
713,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
272,
327,
1379,
21084,
609,
12201,
433,
335,
1695,
14,
23,
14,
17,
21779,
499,
272,
282,
275,
18657,
8,
51,
8,
17,
2447,
18,
12,
428,
8,
17,
2447,
18,
12,
428,
8,
17,
2447,
18,
12,
446,
51,
8,
17,
2447,
18,
12,
378,
12,
378,
9,
272,
330,
275,
18657,
8,
51,
8,
17,
2447,
18,
12,
446,
51,
8,
17,
2447,
18,
12,
428,
8,
17,
2447,
18,
12,
428,
8,
17,
2447,
18,
12,
378,
12,
378,
9,
272,
286,
275,
18657,
8,
17,
12,
413,
12,
413,
12,
446,
17,
12,
378,
12,
378,
9,
272,
366,
275,
18657,
8,
17,
12,
378,
12,
413,
12,
378,
12,
378,
12,
378,
9,
272,
325,
275,
18657,
8,
17,
12,
446,
17,
12,
413,
12,
413,
12,
378,
12
] |
[
636,
2443,
363,
492,
4629,
199,
504,
5840,
492,
428,
12,
7452,
12,
12094,
12,
6698,
199,
504,
5840,
14,
24724,
14,
25999,
14,
12595,
492,
644,
1030,
281,
19,
74,
12,
644,
1030,
281,
22,
74,
12,
644,
1030,
281,
25,
74,
12,
18657,
12,
19711,
63,
11184,
199,
504,
5840,
14,
5777,
14,
6664,
14,
3128,
63,
5777,
492,
1804,
82,
368,
22043,
13411,
199,
504,
5840,
14,
16355,
14,
4462,
492,
11999,
421,
199,
32,
14362,
199,
318,
511,
63,
12595,
63,
11184,
63,
525,
837,
272,
1335,
12,
333,
17,
12,
333,
17,
80,
12,
333,
18,
12,
333,
18,
80,
275,
6698,
360,
74,
333,
17,
333,
17,
80,
333,
18,
333,
18,
80,
358,
272,
327,
1379,
21084,
609,
12201,
433,
335,
1695,
14,
23,
14,
17,
21779,
413,
272,
282,
275,
18657,
8,
51,
8,
17,
2447,
18,
12,
428,
8,
17,
2447,
18,
12,
378,
12,
378,
12,
428,
8,
17,
2447,
18,
12,
428,
8,
17,
2447,
18,
9,
272,
330,
275,
18657,
8,
51,
8,
17,
2447,
18,
12,
446,
51,
8,
17,
2447,
18,
12,
378,
12,
378,
12,
428,
8,
17,
2447,
18,
12,
446,
51,
8,
17,
2447,
18,
9,
272,
286,
275,
18657,
8,
17,
12,
413,
12,
378,
12,
378,
12,
413,
12,
413,
9,
272,
366,
275,
18657,
8,
17,
12,
378,
12,
378,
12,
378,
12,
413,
12,
378,
9,
272,
325,
275,
18657,
8,
17,
12,
446,
17,
12,
378,
12,
378,
12,
413,
12,
446,
17,
9,
272,
702,
19711,
63,
11184,
8,
65,
435,
330,
9,
508,
499,
272,
702,
19711,
63,
11184,
8,
67,
435,
366,
435,
325,
9,
508,
650,
272,
702,
19711,
63,
11184,
8,
65,
435,
330,
435,
286,
435,
366,
435,
325,
9,
508,
959,
272,
702,
19711,
63,
11184,
8,
65,
435,
330,
435,
286,
9,
508,
499,
435,
286,
272,
702,
19711,
63,
11184,
8,
18,
10,
65,
435,
330,
9,
508,
499,
435,
282,
272,
702,
19711,
63,
11184,
8,
18,
10,
67,
435,
366,
435,
325,
9,
508,
650,
435,
286,
272,
702,
19711,
63,
11184,
8,
21,
10,
65,
435,
959,
10,
66,
9,
508,
1616,
272,
702,
19711,
63,
11184,
8,
21,
10,
67,
435,
959,
10,
68,
435,
959,
10,
69,
9,
508,
4114,
272,
702,
19711,
63,
11184,
2801,
65,
446,
330,
9,
508,
446,
18,
272,
702,
19711,
63,
11184,
2801,
67,
446,
366,
446,
325,
9,
508,
446,
19,
272,
702,
19711,
63,
11184,
2801,
22,
10,
65,
446,
1227,
10,
66,
9,
508,
446,
713,
272,
702,
19711,
63,
11184,
2801,
20,
10,
67,
446,
841,
10,
68,
446,
841,
10,
69,
9,
508,
446,
713,
272,
282,
275,
18657,
8,
51,
8,
17,
2447,
18,
12,
428,
8,
17,
2447,
18,
12,
1335,
12,
378,
12,
428,
8,
17,
2447,
18,
12,
428,
8,
17,
2447,
18,
9,
272,
330,
275,
18657,
8,
51,
8,
17,
2447,
18,
12,
446,
51,
8,
17,
2447,
18,
12,
1335,
12,
378,
12,
428,
8,
17,
2447,
18,
12,
446,
51,
8,
17,
2447,
18,
9,
272,
286,
275,
18657,
8,
17,
12,
413,
12,
1335,
12,
378,
12,
413,
12,
413,
9,
272,
366,
275,
18657,
8,
17,
12,
378,
12,
1335,
12,
378,
12,
413,
12,
378,
9,
272,
325,
275,
18657,
8,
17,
12,
446,
17,
12,
1335,
12,
378,
12,
413,
12,
446,
17,
9,
272,
702,
19711,
63,
11184,
8,
65,
435,
330,
9,
508,
499,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
272,
702,
19711,
63,
11184,
8,
67,
435,
366,
435,
325,
9,
508,
650,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
272,
702,
19711,
63,
11184,
8,
65,
435,
330,
435,
286,
435,
366,
435,
325,
9,
508,
959,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
272,
702,
19711,
63,
11184,
8,
65,
435,
330,
435,
286,
9,
508,
499,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
435,
286,
272,
702,
19711,
63,
11184,
8,
18,
10,
65,
435,
330,
9,
508,
499,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
435,
282,
272,
702,
19711,
63,
11184,
8,
18,
10,
67,
435,
366,
435,
325,
9,
508,
650,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
435,
286,
272,
702,
19711,
63,
11184,
8,
21,
10,
65,
435,
959,
10,
66,
9,
508,
1616,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
272,
702,
19711,
63,
11184,
8,
21,
10,
67,
435,
959,
10,
68,
435,
959,
10,
69,
9,
508,
4114,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
272,
702,
19711,
63,
11184,
2801,
65,
446,
330,
9,
508,
446,
18,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
272,
702,
19711,
63,
11184,
2801,
67,
446,
366,
446,
325,
9,
508,
446,
19,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
272,
702,
19711,
63,
11184,
2801,
22,
10,
65,
446,
1227,
10,
66,
9,
508,
446,
713,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
272,
702,
19711,
63,
11184,
2801,
20,
10,
67,
446,
841,
10,
68,
446,
841,
10,
69,
9,
508,
446,
713,
10,
27399,
368,
22043,
13411,
8,
74,
12,
378,
9,
272,
327,
1379,
21084,
609,
12201,
433,
335,
1695,
14,
23,
14,
17,
21779,
499,
272,
282,
275,
18657,
8,
51,
8,
17,
2447,
18,
12,
428,
8,
17,
2447,
18,
12,
428,
8,
17,
2447,
18,
12,
446,
51,
8,
17,
2447,
18,
12,
378,
12,
378,
9,
272,
330,
275,
18657,
8,
51,
8,
17,
2447,
18,
12,
446,
51,
8,
17,
2447,
18,
12,
428,
8,
17,
2447,
18,
12,
428,
8,
17,
2447,
18,
12,
378,
12,
378,
9,
272,
286,
275,
18657,
8,
17,
12,
413,
12,
413,
12,
446,
17,
12,
378,
12,
378,
9,
272,
366,
275,
18657,
8,
17,
12,
378,
12,
413,
12,
378,
12,
378,
12,
378,
9,
272,
325,
275,
18657,
8,
17,
12,
446,
17,
12,
413,
12,
413,
12,
378,
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,
1
] |
ashyx/Samsung-Galaxy-Tab-S2-Kernel
|
tools/perf/scripts/python/check-perf-trace.py
|
11214
|
2503
|
# perf script event handlers, generated by perf script -g python
# (c) 2010, Tom Zanussi <tzanussi@gmail.com>
# Licensed under the terms of the GNU GPL License version 2
#
# This script tests basic functionality such as flag and symbol
# strings, common_xxx() calls back into perf, begin, end, unhandled
# events, etc. Basically, if this script runs successfully and
# displays expected results, Python scripting support should be ok.
import os
import sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from Core import *
from perf_trace_context import *
unhandled = autodict()
def trace_begin():
print "trace_begin"
pass
def trace_end():
print_unhandled()
def irq__softirq_entry(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
vec):
print_header(event_name, common_cpu, common_secs, common_nsecs,
common_pid, common_comm)
print_uncommon(context)
print "vec=%s\n" % \
(symbol_str("irq__softirq_entry", "vec", vec)),
def kmem__kmalloc(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
call_site, ptr, bytes_req, bytes_alloc,
gfp_flags):
print_header(event_name, common_cpu, common_secs, common_nsecs,
common_pid, common_comm)
print_uncommon(context)
print "call_site=%u, ptr=%u, bytes_req=%u, " \
"bytes_alloc=%u, gfp_flags=%s\n" % \
(call_site, ptr, bytes_req, bytes_alloc,
flag_str("kmem__kmalloc", "gfp_flags", gfp_flags)),
def trace_unhandled(event_name, context, event_fields_dict):
try:
unhandled[event_name] += 1
except TypeError:
unhandled[event_name] = 1
def print_header(event_name, cpu, secs, nsecs, pid, comm):
print "%-20s %5u %05u.%09u %8u %-20s " % \
(event_name, cpu, secs, nsecs, pid, comm),
# print trace fields not included in handler args
def print_uncommon(context):
print "common_preempt_count=%d, common_flags=%s, common_lock_depth=%d, " \
% (common_pc(context), trace_flag_str(common_flags(context)), \
common_lock_depth(context))
def print_unhandled():
keys = unhandled.keys()
if not keys:
return
print "\nunhandled events:\n\n",
print "%-40s %10s\n" % ("event", "count"),
print "%-40s %10s\n" % ("----------------------------------------", \
"-----------"),
for event_name in keys:
print "%-40s %10d\n" % (event_name, unhandled[event_name])
|
gpl-2.0
|
[
3,
8582,
2884,
1566,
8297,
12,
4046,
701,
8582,
2884,
446,
71,
2366,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
961,
2884,
2295,
5678,
9330,
4066,
465,
3305,
436,
5272,
199,
3,
3326,
12,
2863,
63,
10013,
342,
4882,
1771,
1901,
8582,
12,
5386,
12,
1284,
12,
23090,
199,
3,
4474,
12,
5423,
14,
221,
10082,
1183,
12,
340,
642,
2884,
7858,
8792,
436,
199,
3,
17561,
1420,
2058,
12,
2018,
2884,
316,
2291,
1077,
506,
4112,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
11672,
492,
627,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
199,
23648,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
3446,
63,
5037,
2,
199,
198,
1529,
199,
199,
318,
3307,
63,
500,
837,
267,
870,
63,
23648,
342,
199,
199,
318,
10476,
363,
18316,
63,
2373,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
6046,
304,
507,
198,
1361,
63,
1291,
8,
1430,
63,
354,
12,
2863,
63,
3541,
12,
2863,
63,
4855,
12,
2863,
63,
9618,
12,
686,
198,
2330,
63,
3150,
12,
2863,
63,
1404,
9,
2234,
870,
63,
324,
2330,
8,
1100,
9,
2742,
198,
1361,
298,
6046,
2458,
83,
60,
78,
2,
450,
971,
507,
198,
8,
5155,
63,
495,
480,
7277,
363,
18316,
63,
2373,
401,
298,
6046,
401,
10782,
1826,
199,
199,
318,
1022,
5286,
363,
75,
23981,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
1250,
63,
2124,
12,
12448,
12,
2783,
63,
2103,
12,
2783,
63,
9373,
12,
199,
198,
71,
3997,
63,
2469,
304,
507,
198,
1361,
63,
1291,
8,
1430,
63,
354,
12,
2863,
63,
3541,
12,
2863,
63,
4855,
12,
2863,
63,
9618,
12,
686,
198,
2330,
63,
3150,
12,
2863,
63,
1404,
9,
2234,
870,
63,
324,
2330,
8,
1100,
9,
2742,
198,
1361,
298,
1250,
63,
2124,
2458,
85,
12,
12448,
2458,
85,
12,
2783,
63,
2103,
2458,
85,
12,
298,
971,
507,
198,
2,
2394,
63,
9373,
2458,
85,
12,
486,
3997,
63,
2469,
2458,
83,
60,
78,
2,
450,
971,
507,
198,
8,
1250,
63,
2124,
12,
12448,
12,
2783,
63,
2103,
12,
2783,
63,
9373,
12,
2742,
198,
4173,
63,
495,
480,
75,
5286,
363,
75,
23981,
401,
298,
71,
3997,
63,
2469,
401,
486,
3997,
63,
2469,
1826,
199,
199,
318,
3307,
63,
23648,
8,
1430,
63,
354,
12,
1067,
12,
1566,
63,
955,
63,
807,
304,
272,
862,
26,
267,
23090,
59,
1430,
63,
354,
61,
847,
413,
272,
871,
3146,
26,
267,
23090,
59,
1430,
63,
354,
61,
275,
413,
199,
199,
318,
870,
63,
1291,
8,
1430,
63,
354,
12,
5033,
12,
20091,
12,
13781,
12,
4422,
12,
1923,
304,
199,
198,
1361,
18301,
1165,
83,
450,
21,
85,
450,
1717,
85,
4111,
1643,
85,
450,
24,
85,
19752,
1165,
83,
298,
450,
971,
199,
198,
8,
1430,
63,
354,
12,
5033,
12,
20091,
12,
13781,
12,
4422,
12,
1923,
395,
199,
199,
3,
870,
3307,
1504,
440,
5120,
315,
3016,
1249,
199,
318,
870,
63,
324,
2330,
8,
1100,
304,
272,
870,
298,
2330,
63,
657,
19046,
63,
835,
2458,
68,
12,
2863,
63,
2469,
2458,
83,
12,
2863,
63,
831,
63,
4631,
2458,
68,
12,
298,
971,
267,
450,
334,
2330,
63,
2352,
8,
1100,
395,
3307,
63,
4173,
63,
495,
8,
2330,
63,
2469,
8,
1100,
1826,
971,
2049,
2863,
63,
831,
63,
4631,
8,
1100,
430,
199,
199,
318,
870,
63,
23648,
837,
272,
2883,
275,
23090,
14,
1612,
342,
272,
340,
440,
2883,
26,
267,
372,
339,
870,
1867,
78,
23648,
4474,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
13715,
1288,
339,
367,
1566,
63,
354,
315,
2883,
26,
199,
198,
1361,
18301,
2167,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
1430,
63,
354,
12,
23090,
59,
1430,
63,
354,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
8582,
2884,
1566,
8297,
12,
4046,
701,
8582,
2884,
446,
71,
2366,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
961,
2884,
2295,
5678,
9330,
4066,
465,
3305,
436,
5272,
199,
3,
3326,
12,
2863,
63,
10013,
342,
4882,
1771,
1901,
8582,
12,
5386,
12,
1284,
12,
23090,
199,
3,
4474,
12,
5423,
14,
221,
10082,
1183,
12,
340,
642,
2884,
7858,
8792,
436,
199,
3,
17561,
1420,
2058,
12,
2018,
2884,
316,
2291,
1077,
506,
4112,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
11672,
492,
627,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
199,
23648,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
3446,
63,
5037,
2,
199,
198,
1529,
199,
199,
318,
3307,
63,
500,
837,
267,
870,
63,
23648,
342,
199,
199,
318,
10476,
363,
18316,
63,
2373,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
6046,
304,
507,
198,
1361,
63,
1291,
8,
1430,
63,
354,
12,
2863,
63,
3541,
12,
2863,
63,
4855,
12,
2863,
63,
9618,
12,
686,
198,
2330,
63,
3150,
12,
2863,
63,
1404,
9,
2234,
870,
63,
324,
2330,
8,
1100,
9,
2742,
198,
1361,
298,
6046,
2458,
83,
60,
78,
2,
450,
971,
507,
198,
8,
5155,
63,
495,
480,
7277,
363,
18316,
63,
2373,
401,
298,
6046,
401,
10782,
1826,
199,
199,
318,
1022,
5286,
363,
75,
23981,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
1250,
63,
2124,
12,
12448,
12,
2783,
63,
2103,
12,
2783,
63,
9373,
12,
199,
198,
71,
3997,
63,
2469,
304,
507,
198,
1361,
63,
1291,
8,
1430,
63,
354,
12,
2863,
63,
3541,
12,
2863,
63,
4855,
12,
2863,
63,
9618,
12,
686,
198,
2330,
63,
3150,
12,
2863,
63,
1404,
9,
2234,
870,
63,
324,
2330,
8,
1100,
9,
2742,
198,
1361,
298,
1250,
63,
2124,
2458,
85,
12,
12448,
2458,
85,
12,
2783,
63,
2103,
2458,
85,
12,
298,
971,
507,
198,
2,
2394,
63,
9373,
2458,
85,
12,
486,
3997,
63,
2469,
2458,
83,
60,
78,
2,
450,
971,
507,
198,
8,
1250,
63,
2124,
12,
12448,
12,
2783,
63,
2103,
12,
2783,
63,
9373,
12,
2742,
198,
4173,
63,
495,
480,
75,
5286,
363,
75,
23981,
401,
298,
71,
3997,
63,
2469,
401,
486,
3997,
63,
2469,
1826,
199,
199,
318,
3307,
63,
23648,
8,
1430,
63,
354,
12,
1067,
12,
1566,
63,
955,
63,
807,
304,
272,
862,
26,
267,
23090,
59,
1430,
63,
354,
61,
847,
413,
272,
871,
3146,
26,
267,
23090,
59,
1430,
63,
354,
61,
275,
413,
199,
199,
318,
870,
63,
1291,
8,
1430,
63,
354,
12,
5033,
12,
20091,
12,
13781,
12,
4422,
12,
1923,
304,
199,
198,
1361,
18301,
1165,
83,
450,
21,
85,
450,
1717,
85,
4111,
1643,
85,
450,
24,
85,
19752,
1165,
83,
298,
450,
971,
199,
198,
8,
1430,
63,
354,
12,
5033,
12,
20091,
12,
13781,
12,
4422,
12,
1923,
395,
199,
199,
3,
870,
3307,
1504,
440,
5120,
315,
3016,
1249,
199,
318,
870,
63,
324,
2330,
8,
1100,
304,
272,
870,
298,
2330,
63,
657,
19046,
63,
835,
2458,
68,
12,
2863,
63,
2469,
2458,
83,
12,
2863,
63,
831,
63,
4631,
2458,
68,
12,
298,
971,
267,
450,
334,
2330,
63,
2352,
8,
1100,
395,
3307,
63,
4173,
63,
495,
8,
2330,
63,
2469,
8,
1100,
1826,
971,
2049,
2863,
63,
831,
63,
4631,
8,
1100,
430,
199,
199,
318,
870,
63,
23648,
837,
272,
2883,
275,
23090,
14,
1612,
342,
272,
340,
440,
2883,
26,
267,
372,
339,
870,
1867,
78,
23648,
4474,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
13715,
1288,
339,
367,
1566,
63,
354,
315,
2883,
26,
199,
198,
1361,
18301,
2167,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
1430,
63,
354,
12,
23090,
59,
1430,
63,
354,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jbq/ufw
|
src/backend.py
|
1
|
24402
|
'''backend.py: interface for ufw backends'''
#
# Copyright 2008-2011 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import errno
import os
import re
import stat
import sys
import ufw.util
from ufw.util import warn, debug
from ufw.common import UFWError, config_dir, iptables_dir, UFWRule
import ufw.applications
class UFWBackend:
'''Interface for backends'''
def __init__(self, name, dryrun, extra_files=None):
self.defaults = None
self.name = name
self.dryrun = dryrun
self.rules = []
self.rules6 = []
self.files = {'defaults': os.path.join(config_dir, 'default/ufw'),
'conf': os.path.join(config_dir, 'ufw/ufw.conf'),
'apps': os.path.join(config_dir, 'ufw/applications.d') }
if extra_files != None:
self.files.update(extra_files)
self.loglevels = {'off': 0,
'low': 100,
'medium': 200,
'high': 300,
'full': 400 }
self.do_checks = True
try:
self._do_checks()
self._get_defaults()
self._read_rules()
except Exception:
raise
self.profiles = ufw.applications.get_profiles(self.files['apps'])
self.iptables = os.path.join(iptables_dir, "iptables")
self.iptables_restore = os.path.join(iptables_dir, "iptables-restore")
self.ip6tables = os.path.join(iptables_dir, "ip6tables")
self.ip6tables_restore = os.path.join(iptables_dir, \
"ip6tables-restore")
self.iptables_version = ufw.util.get_iptables_version(self.iptables)
def is_enabled(self):
'''Is firewall configured as enabled'''
if self.defaults.has_key('enabled') and \
self.defaults['enabled'] == 'yes':
return True
return False
def use_ipv6(self):
'''Is firewall configured to use IPv6'''
if self.defaults.has_key('ipv6') and \
self.defaults['ipv6'] == 'yes' and \
os.path.exists("/proc/sys/net/ipv6"):
return True
return False
def _get_default_policy(self, primary="input"):
'''Get default policy for specified primary chain'''
policy = "default_" + primary + "_policy"
rstr = ""
if self.defaults[policy] == "accept":
rstr = "allow"
elif self.defaults[policy] == "accept_no_track":
rstr = "allow-without-tracking"
elif self.defaults[policy] == "reject":
rstr = "reject"
else:
rstr = "deny"
return rstr
def _do_checks(self):
'''Perform basic security checks:
is setuid or setgid (for non-Linux systems)
checks that script is owned by root
checks that every component in absolute path are owned by root
warn if script is group writable
warn if part of script path is group writable
Doing this at the beginning causes a race condition with later
operations that don't do these checks. However, if the user running
this script is root, then need to be root to exploit the race
condition (and you are hosed anyway...)
'''
if not self.do_checks:
err_msg = _("Checks disabled")
warn(err_msg)
return True
# Not needed on Linux, but who knows the places we will go...
if os.getuid() != os.geteuid():
err_msg = _("ERROR: this script should not be SUID")
raise UFWError(err_msg)
if os.getgid() != os.getegid():
err_msg = _("ERROR: this script should not be SGID")
raise UFWError(err_msg)
uid = os.getuid()
if uid != 0:
err_msg = _("You need to be root to run this script")
raise UFWError(err_msg)
# Use these so we only warn once
warned_world_write = {}
warned_group_write = {}
warned_owner = {}
profiles = []
if not os.path.isdir(self.files['apps']):
warn_msg = _("'%s' does not exist") % (self.files['apps'])
warn(warn_msg)
else:
pat = re.compile(r'^\.')
for profile in os.listdir(self.files['apps']):
if not pat.search(profile):
profiles.append(os.path.join(self.files['apps'], profile))
for path in self.files.values() + [ os.path.abspath(sys.argv[0]) ] + \
profiles:
while True:
debug("Checking " + path)
if path == self.files['apps'] and \
not os.path.isdir(self.files['apps']):
break
try:
statinfo = os.stat(path)
mode = statinfo[stat.ST_MODE]
except OSError:
err_msg = _("Couldn't stat '%s'") % (path)
raise UFWError(err_msg)
except Exception:
raise
if statinfo.st_uid != 0 and not warned_owner.has_key(path):
warn_msg = _("uid is %(uid)s but '%(path)s' is owned by " \
"%(st_uid)s") % ({'uid': str(uid), \
'path': path, \
'st_uid': str(statinfo.st_uid)})
warn(warn_msg)
warned_owner[path] = True
if mode & stat.S_IWOTH and not warned_world_write.has_key(path):
warn_msg = _("%s is world writable!") % (path)
warn(warn_msg)
warned_world_write[path] = True
if mode & stat.S_IWGRP and not warned_group_write.has_key(path):
warn_msg = _("%s is group writable!") % (path)
warn(warn_msg)
warned_group_write[path] = True
if path == "/":
break
path = os.path.dirname(path)
if not path:
raise OSError(errno.ENOENT, "Could not find '%s'" % (path))
for f in self.files:
if f != 'apps' and not os.path.isfile(self.files[f]):
err_msg = _("'%(f)s' file '%(name)s' does not exist") % \
({'f': f, 'name': self.files[f]})
raise UFWError(err_msg)
def _get_defaults(self):
'''Get all settings from defaults file'''
self.defaults = {}
for f in [self.files['defaults'], self.files['conf']]:
try:
orig = ufw.util.open_file_read(f)
except Exception:
err_msg = _("Couldn't open '%s' for reading") % (f)
raise UFWError(err_msg)
pat = re.compile(r'^\w+="?\w+"?')
for line in orig:
if pat.search(line):
tmp = re.split(r'=', line.strip())
self.defaults[tmp[0].lower()] = tmp[1].lower().strip('"\'')
orig.close()
# do some default policy sanity checking
policies = ['accept', 'accept_no_track', 'drop', 'reject']
for c in [ 'input', 'output', 'forward' ]:
if not self.defaults.has_key('default_%s_policy' % (c)):
err_msg = _("Missing policy for '%s'" % (c))
raise UFWError(err_msg)
p = self.defaults['default_%s_policy' % (c)]
if p not in policies or \
(p == 'accept_no_track' and c == 'forward'):
err_msg = _("Invalid policy '%(policy)s' for '%(chain)s'" % \
({'policy': p, 'chain': c}))
raise UFWError(err_msg)
def set_default(self, fn, opt, value):
'''Sets option in defaults file'''
if not re.match(r'^[\w_]+$', opt):
err_msg = _("Invalid option")
raise UFWError(err_msg)
# Perform this here so we can present a nice error to the user rather
# than a traceback
if not os.access(fn, os.W_OK):
err_msg = _("'%s' is not writable" % (fn))
raise UFWError(err_msg)
try:
fns = ufw.util.open_files(fn)
except Exception:
raise
fd = fns['tmp']
found = False
pat = re.compile(r'^' + opt + '=')
for line in fns['orig']:
if pat.search(line):
ufw.util.write_to_file(fd, opt + "=" + value + "\n")
found = True
else:
ufw.util.write_to_file(fd, line)
# Add the entry if not found
if not found:
ufw.util.write_to_file(fd, opt + "=" + value + "\n")
try:
ufw.util.close_files(fns)
except Exception:
raise
# Now that the files are written out, update value in memory
self.defaults[opt.lower()] = value.lower().strip('"\'')
def set_default_application_policy(self, policy):
'''Sets default application policy of firewall'''
if not self.dryrun:
if policy == "allow":
try:
self.set_default(self.files['defaults'], \
"DEFAULT_APPLICATION_POLICY", \
"\"ACCEPT\"")
except Exception:
raise
elif policy == "deny":
try:
self.set_default(self.files['defaults'], \
"DEFAULT_APPLICATION_POLICY", \
"\"DROP\"")
except Exception:
raise
elif policy == "reject":
try:
self.set_default(self.files['defaults'], \
"DEFAULT_APPLICATION_POLICY", \
"\"REJECT\"")
except Exception:
raise
elif policy == "skip":
try:
self.set_default(self.files['defaults'], \
"DEFAULT_APPLICATION_POLICY", \
"\"SKIP\"")
except Exception:
raise
else:
err_msg = _("Unsupported policy '%s'") % (policy)
raise UFWError(err_msg)
rstr = _("Default application policy changed to '%s'") % (policy)
return rstr
def get_app_rules_from_template(self, template):
'''Return a list of UFWRules based on the template rule'''
rules = []
profile_names = self.profiles.keys()
if template.dport in profile_names and template.sport in profile_names:
dports = ufw.applications.get_ports(self.profiles[template.dport])
sports = ufw.applications.get_ports(self.profiles[template.sport])
for i in dports:
tmp = template.dup_rule()
tmp.dapp = ""
tmp.set_port("any", "src")
try:
(port, proto) = ufw.util.parse_port_proto(i)
tmp.set_protocol(proto)
tmp.set_port(port, "dst")
except Exception:
raise
tmp.dapp = template.dapp
if template.dport == template.sport:
# Just use the same ports as dst for src when they are the
# same to avoid duplicate rules
tmp.sapp = ""
try:
(port, proto) = ufw.util.parse_port_proto(i)
tmp.set_protocol(proto)
tmp.set_port(port, "src")
except Exception:
raise
tmp.sapp = template.sapp
rules.append(tmp)
else:
for j in sports:
rule = tmp.dup_rule()
rule.sapp = ""
try:
(port, proto) = ufw.util.parse_port_proto(j)
rule.set_protocol(proto)
rule.set_port(port, "src")
except Exception:
raise
if rule.protocol == "any":
rule.set_protocol(tmp.protocol)
rule.sapp = template.sapp
rules.append(rule)
elif template.sport in profile_names:
for p in ufw.applications.get_ports(self.profiles[template.sport]):
rule = template.dup_rule()
rule.sapp = ""
try:
(port, proto) = ufw.util.parse_port_proto(p)
rule.set_protocol(proto)
rule.set_port(port, "src")
except Exception:
raise
rule.sapp = template.sapp
rules.append(rule)
elif template.dport in profile_names:
for p in ufw.applications.get_ports(self.profiles[template.dport]):
rule = template.dup_rule()
rule.dapp = ""
try:
(port, proto) = ufw.util.parse_port_proto(p)
rule.set_protocol(proto)
rule.set_port(port, "dst")
except Exception:
raise
rule.dapp = template.dapp
rules.append(rule)
if len(rules) < 1:
err_msg = _("No rules found for application profile")
raise UFWError(err_msg)
return rules
def update_app_rule(self, profile):
'''Update rule for profile in place. Returns result string and bool
on whether or not the profile is used in the current ruleset.
'''
updated_rules = []
updated_rules6 = []
last_tuple = ""
rstr = ""
updated_profile = False
# Remember, self.rules is from user[6].rules, and not the running
# firewall.
for r in self.rules + self.rules6:
if r.dapp == profile or r.sapp == profile:
# We assume that the rules are in app rule order. Specifically,
# if app rule has multiple rules, they are one after the other.
# If the rule ordering changes, the below will have to change.
tupl = r.get_app_tuple()
if tupl == last_tuple:
# Skip the rule if seen this tuple already (ie, it is part
# of a known tuple).
continue
else:
# Have a new tuple, so find and insert new app rules here
template = r.dup_rule()
template.set_protocol("any")
if template.dapp != "":
template.set_port(template.dapp, "dst")
if template.sapp != "":
template.set_port(template.sapp, "src")
try:
new_app_rules = self.get_app_rules_from_template(\
template)
except Exception:
raise
for new_r in new_app_rules:
new_r.normalize()
if new_r.v6:
updated_rules6.append(new_r)
else:
updated_rules.append(new_r)
last_tuple = tupl
updated_profile = True
else:
if r.v6:
updated_rules6.append(r)
else:
updated_rules.append(r)
if updated_profile:
self.rules = updated_rules
self.rules6 = updated_rules6
rstr += _("Rules updated for profile '%s'") % (profile)
try:
self._write_rules(False) # ipv4
self._write_rules(True) # ipv6
except Exception:
err_msg = _("Couldn't update application rules")
raise UFWError(err_msg)
return (rstr, updated_profile)
def find_application_name(self, profile_name):
'''Find the application profile name for profile_name'''
if self.profiles.has_key(profile_name):
return profile_name
match = ""
matches = 0
for n in self.profiles.keys():
if n.lower() == profile_name.lower():
match = n
matches += 1
debug_msg = "'%d' matches for '%s'" % (matches, profile_name)
debug(debug_msg)
if matches == 1:
return match
elif matches > 1:
err_msg = _("Found multiple matches for '%s'. Please use exact profile name") % \
(profile_name)
err_msg = _("Could not find a profile matching '%s'") % (profile_name)
raise UFWError(err_msg)
def find_other_position(self, position, v6):
'''Return the absolute position in the other list of the rule with the
user position of the given list. For example, find_other_position(4,
True) will return the absolute position of the rule in the ipv4 list
matching the user specified '4' rule in the ipv6 list.
'''
# Invalid search (v6 rule with too low position)
if v6 and position > len(self.rules6):
raise ValueError()
# Invalid search (v4 rule with too high position)
if not v6 and position > len(self.rules):
raise ValueError()
if position < 1:
raise ValueError()
rules = []
if v6:
rules = self.rules6
else:
rules = self.rules
# self.rules[6] is a list of tuples. Some application rules have
# multiple tuples but the user specifies by ufw rule, not application
# tuple, so we need to find how many tuples there are leading up to
# the specified position, which we can then use as an offset for
# getting the proper match_rule.
app_rules = {}
tuple_offset = 0
for i, r in enumerate(rules):
if i >= position:
break
tupl = ""
if r.dapp != "" or r.sapp != "":
tupl = r.get_app_tuple()
if app_rules.has_key(tupl):
tuple_offset += 1
else:
app_rules[tupl] = True
rules = []
if v6:
rules = self.rules
match_rule = self.rules6[position - 1 + tuple_offset].dup_rule()
match_rule.set_v6(False)
else:
rules = self.rules6
match_rule = self.rules[position - 1 + tuple_offset].dup_rule()
match_rule.set_v6(True)
count = 1
for r in rules:
if UFWRule.match(r, match_rule) == 0:
return count
count += 1
return 0
def get_loglevel(self):
'''Gets current log level of firewall'''
level = 0
rstr = _("Logging: ")
if not self.defaults.has_key('loglevel') or \
self.defaults['loglevel'] not in self.loglevels.keys():
level = -1
rstr += _("unknown")
else:
level = self.loglevels[self.defaults['loglevel']]
if level == 0:
rstr += "off"
else:
rstr += "on (%s)" % (self.defaults['loglevel'])
return (level, rstr)
def set_loglevel(self, level):
'''Sets log level of firewall'''
if level not in self.loglevels.keys() + ['on']:
err_msg = _("Invalid log level '%s'") % (level)
raise UFWError(err_msg)
new_level = level
if level == "on":
if not self.defaults.has_key('loglevel') or \
self.defaults['loglevel'] == "off":
new_level = "low"
else:
new_level = self.defaults['loglevel']
try:
self.set_default(self.files['conf'], "LOGLEVEL", new_level)
self.update_logging(new_level)
except Exception:
raise
if new_level == "off":
return _("Logging disabled")
else:
return _("Logging enabled")
def get_rules(self):
'''Return list of all rules'''
return self.rules + self.rules6
def get_rules_count(self, v6):
'''Return number of ufw rules (not iptables rules)'''
rules = []
if v6:
rules = self.rules6
else:
rules = self.rules
count = 0
app_rules = {}
for r in rules:
tupl = ""
if r.dapp != "" or r.sapp != "":
tupl = r.get_app_tuple()
if app_rules.has_key(tupl):
debug("Skipping found tuple '%s'" % (tupl))
continue
else:
app_rules[tupl] = True
count += 1
return count
def get_rule_by_number(self, num):
'''Return rule specified by number seen via "status numbered"'''
rules = self.get_rules()
count = 1
app_rules = {}
for r in rules:
tupl = ""
if r.dapp != "" or r.sapp != "":
tupl = r.get_app_tuple()
if app_rules.has_key(tupl):
debug("Skipping found tuple '%s'" % (tupl))
continue
else:
app_rules[tupl] = True
if count == int(num):
return r
count += 1
return None
def get_matching(self, rule):
'''See if there is a matching rule in the existing ruleset. Note this
does not group rules by tuples.'''
matched = []
count = 0
for r in self.get_rules():
count += 1
ret = rule.fuzzy_dst_match(r)
if ret < 1:
matched.append(count)
return matched
# API overrides
def set_default_policy(self, policy, direction):
'''Set default policy for specified direction'''
raise UFWError("UFWBackend.set_default_policy: need to override")
def get_running_raw(self, rules_type):
'''Get status of running firewall'''
raise UFWError("UFWBackend.get_running_raw: need to override")
def get_status(self, verbose, show_count):
'''Get managed rules'''
raise UFWError("UFWBackend.get_status: need to override")
def set_rule(self, rule, allow_reload):
'''Update firewall with rule'''
raise UFWError("UFWBackend.set_rule: need to override")
def start_firewall(self):
'''Start the firewall'''
raise UFWError("UFWBackend.start_firewall: need to override")
def stop_firewall(self):
'''Stop the firewall'''
raise UFWError("UFWBackend.stop_firewall: need to override")
def get_app_rules_from_system(self, template, v6):
'''Get a list if rules based on template'''
raise UFWError("UFWBackend.get_app_rules_from_system: need to " + \
"override")
def update_logging(self, level):
'''Update loglevel of running firewall'''
raise UFWError("UFWBackend.update_logging: need to override")
def reset(self):
'''Reset the firewall'''
raise UFWError("UFWBackend.reset: need to override")
|
gpl-3.0
|
[
2344,
4620,
14,
647,
26,
3217,
367,
399,
8835,
14745,
2344,
199,
3,
199,
3,
1898,
9079,
13,
8128,
6855,
7174,
12126,
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,
1696,
1684,
844,
1015,
650,
12,
199,
3,
259,
465,
3267,
701,
314,
2868,
2290,
2752,
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,
199,
3,
199,
199,
646,
7554,
199,
646,
747,
199,
646,
295,
199,
646,
5672,
199,
646,
984,
199,
646,
399,
8835,
14,
1974,
199,
504,
399,
8835,
14,
1974,
492,
7987,
12,
3105,
199,
504,
399,
8835,
14,
2330,
492,
738,
19445,
547,
12,
1101,
63,
694,
12,
29458,
63,
694,
12,
738,
19445,
5065,
199,
646,
399,
8835,
14,
15853,
199,
199,
533,
738,
19445,
8447,
26,
272,
1449,
4267,
367,
14745,
2344,
272,
347,
636,
826,
721,
277,
12,
536,
12,
9951,
1065,
12,
2402,
63,
1725,
29,
403,
304,
267,
291,
14,
4322,
275,
488,
267,
291,
14,
354,
275,
536,
267,
291,
14,
10481,
1065,
275,
9951,
1065,
267,
291,
14,
4423,
275,
942,
267,
291,
14,
4423,
22,
275,
942,
398,
291,
14,
1725,
275,
791,
4322,
356,
747,
14,
515,
14,
904,
8,
888,
63,
694,
12,
283,
885,
15,
1286,
87,
659,
1993,
283,
2190,
356,
747,
14,
515,
14,
904,
8,
888,
63,
694,
12,
283,
1286,
87,
15,
1286,
87,
14,
2190,
659,
1993,
283,
5181,
356,
747,
14,
515,
14,
904,
8,
888,
63,
694,
12,
283,
1286,
87,
15,
15853,
14,
68,
358,
789,
267,
340,
2402,
63,
1725,
1137,
488,
26,
288,
291,
14,
1725,
14,
873,
8,
2911,
63,
1725,
9,
398,
291,
14,
793,
11402,
275,
791,
1997,
356,
755,
378,
12,
2079,
283,
674,
356,
258,
2948,
12,
2079,
283,
14345,
356,
221,
1926,
12,
2079,
283,
6260,
356,
259,
9601,
12,
2079,
283,
2861,
356,
259,
8290,
789,
398,
291,
14,
1117,
63,
8625,
275,
715,
267,
862,
26,
288,
291,
423,
1117,
63,
8625,
342,
288,
291,
423,
362,
63,
4322,
342,
288,
291,
423,
739,
63,
4423,
342,
267,
871,
2186,
26,
288,
746,
398,
291,
14,
11225,
275,
399,
8835,
14,
15853,
14,
362,
63,
11225,
8,
277,
14,
1725,
459,
5181,
1105,
398,
291,
14,
23232,
275,
747,
14,
515,
14,
904,
8,
23232,
63,
694,
12,
298,
23232,
531,
267,
291,
14,
23232,
63,
8011,
275,
747,
14,
515,
14,
904,
8,
23232,
63,
694,
12,
298,
23232,
13,
8011,
531,
267,
291,
14,
711,
22,
5987,
275,
747,
14,
515,
14,
904,
8,
23232,
63,
694,
12,
298,
711,
22,
5987,
531,
267,
291,
14,
711,
22,
5987,
63,
8011,
275,
747,
14,
515,
14,
904,
8,
23232,
63,
694,
12,
971,
6343,
298,
711,
22,
5987,
13,
8011,
531,
398,
291,
14,
23232,
63,
1023,
275,
399,
8835,
14,
1974,
14,
362,
63,
23232,
63,
1023,
8,
277,
14,
23232,
9,
339,
347,
365,
63,
3827,
8,
277,
304,
267,
1449,
1831,
12042,
7526,
465,
5223,
2344,
267,
340,
291,
14,
4322,
14,
1989,
63,
498,
360,
3827,
358,
436,
971,
1779,
291,
14,
4322,
459,
3827,
418,
508,
283,
5066,
356,
288,
372,
715,
267,
372,
756,
339,
347,
675,
63,
4774,
22,
8,
277,
304,
267,
1449,
1831,
12042,
7526,
370,
675,
6509,
22,
2344,
267,
340,
291,
14,
4322,
14,
1989,
63,
498,
360,
4774,
22,
358,
436,
971,
1779,
291,
14,
4322,
459,
4774,
22,
418,
508,
283,
5066,
7,
436,
971,
1779,
747,
14,
515,
14,
2444,
4769,
4687,
15,
1274,
15,
846,
15,
4774,
22,
2349,
288,
372,
715,
267,
372,
756,
339,
347,
485,
362,
63,
885,
63,
3185,
8,
277,
12,
5062,
628,
1210,
2349,
267,
1449,
1002,
849,
4592,
367,
2013,
5062,
6036,
2344,
267,
4592,
275,
298,
885,
12172,
435,
5062,
435,
2668,
3185,
2,
398,
519,
495,
275,
3087,
267,
340,
291,
14,
4322,
59,
3185,
61,
508,
298,
5694,
582,
288,
519,
495,
275,
298,
3306,
2,
267,
916,
291,
14,
4322,
59,
3185,
61,
508,
298,
5694,
63,
889,
63,
3885,
582,
288,
519,
495,
275,
298,
3306,
13,
7395,
13,
14428,
2,
267,
916,
291,
14,
4322,
59,
3185,
61,
508,
298,
16857,
582,
288,
519,
495,
275,
298,
16857,
2,
267,
587,
26,
288,
519,
495,
275,
298,
23040,
2,
398,
372,
519,
495,
339,
347,
485,
1117,
63,
8625,
8,
277,
304,
267,
1449,
20906,
5678,
6391,
5920,
26,
267,
365,
663,
1535,
503,
663,
8787,
334,
509,
2222,
13,
14091,
10460,
9,
267,
5920,
626,
2884,
365,
23191,
701,
1738,
267,
5920,
626,
4036,
3931,
315,
3679,
931,
787,
23191,
701,
1738,
267,
7987,
340,
2884,
365,
1572,
17267,
267,
7987,
340,
1777,
402,
2884,
931,
365,
1572,
17267,
398,
4226,
316,
642,
737,
314,
9608,
14486,
282,
21209,
5558,
543,
2945,
267,
5331,
626,
2793,
1133,
886,
3520,
5920,
14,
221,
9738,
12,
340,
314,
922,
3879,
267,
642,
2884,
365,
1738,
12,
2066,
1929,
370,
506,
1738,
370,
15868,
390,
314,
21209,
267,
5558,
334,
460,
1265,
787,
2636,
939,
15988,
11965,
267,
1449,
398,
340,
440,
291,
14,
1117,
63,
8625,
26,
288,
2329,
63,
1328,
275,
3824,
11834,
6980,
531,
288,
7987,
8,
1508,
63,
1328,
9,
288,
372,
715,
398,
327,
2832,
4346,
641,
10130,
12,
1325,
3963,
19428,
314,
9825,
781,
911,
2621,
1396,
267,
340,
747,
14,
362,
1535,
342,
1137,
747,
14,
31508,
1535,
837,
288,
2329,
63,
1328,
275,
3824,
3170,
26,
642,
2884,
1077,
440,
506
] |
[
4620,
14,
647,
26,
3217,
367,
399,
8835,
14745,
2344,
199,
3,
199,
3,
1898,
9079,
13,
8128,
6855,
7174,
12126,
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,
1696,
1684,
844,
1015,
650,
12,
199,
3,
259,
465,
3267,
701,
314,
2868,
2290,
2752,
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,
199,
3,
199,
199,
646,
7554,
199,
646,
747,
199,
646,
295,
199,
646,
5672,
199,
646,
984,
199,
646,
399,
8835,
14,
1974,
199,
504,
399,
8835,
14,
1974,
492,
7987,
12,
3105,
199,
504,
399,
8835,
14,
2330,
492,
738,
19445,
547,
12,
1101,
63,
694,
12,
29458,
63,
694,
12,
738,
19445,
5065,
199,
646,
399,
8835,
14,
15853,
199,
199,
533,
738,
19445,
8447,
26,
272,
1449,
4267,
367,
14745,
2344,
272,
347,
636,
826,
721,
277,
12,
536,
12,
9951,
1065,
12,
2402,
63,
1725,
29,
403,
304,
267,
291,
14,
4322,
275,
488,
267,
291,
14,
354,
275,
536,
267,
291,
14,
10481,
1065,
275,
9951,
1065,
267,
291,
14,
4423,
275,
942,
267,
291,
14,
4423,
22,
275,
942,
398,
291,
14,
1725,
275,
791,
4322,
356,
747,
14,
515,
14,
904,
8,
888,
63,
694,
12,
283,
885,
15,
1286,
87,
659,
1993,
283,
2190,
356,
747,
14,
515,
14,
904,
8,
888,
63,
694,
12,
283,
1286,
87,
15,
1286,
87,
14,
2190,
659,
1993,
283,
5181,
356,
747,
14,
515,
14,
904,
8,
888,
63,
694,
12,
283,
1286,
87,
15,
15853,
14,
68,
358,
789,
267,
340,
2402,
63,
1725,
1137,
488,
26,
288,
291,
14,
1725,
14,
873,
8,
2911,
63,
1725,
9,
398,
291,
14,
793,
11402,
275,
791,
1997,
356,
755,
378,
12,
2079,
283,
674,
356,
258,
2948,
12,
2079,
283,
14345,
356,
221,
1926,
12,
2079,
283,
6260,
356,
259,
9601,
12,
2079,
283,
2861,
356,
259,
8290,
789,
398,
291,
14,
1117,
63,
8625,
275,
715,
267,
862,
26,
288,
291,
423,
1117,
63,
8625,
342,
288,
291,
423,
362,
63,
4322,
342,
288,
291,
423,
739,
63,
4423,
342,
267,
871,
2186,
26,
288,
746,
398,
291,
14,
11225,
275,
399,
8835,
14,
15853,
14,
362,
63,
11225,
8,
277,
14,
1725,
459,
5181,
1105,
398,
291,
14,
23232,
275,
747,
14,
515,
14,
904,
8,
23232,
63,
694,
12,
298,
23232,
531,
267,
291,
14,
23232,
63,
8011,
275,
747,
14,
515,
14,
904,
8,
23232,
63,
694,
12,
298,
23232,
13,
8011,
531,
267,
291,
14,
711,
22,
5987,
275,
747,
14,
515,
14,
904,
8,
23232,
63,
694,
12,
298,
711,
22,
5987,
531,
267,
291,
14,
711,
22,
5987,
63,
8011,
275,
747,
14,
515,
14,
904,
8,
23232,
63,
694,
12,
971,
6343,
298,
711,
22,
5987,
13,
8011,
531,
398,
291,
14,
23232,
63,
1023,
275,
399,
8835,
14,
1974,
14,
362,
63,
23232,
63,
1023,
8,
277,
14,
23232,
9,
339,
347,
365,
63,
3827,
8,
277,
304,
267,
1449,
1831,
12042,
7526,
465,
5223,
2344,
267,
340,
291,
14,
4322,
14,
1989,
63,
498,
360,
3827,
358,
436,
971,
1779,
291,
14,
4322,
459,
3827,
418,
508,
283,
5066,
356,
288,
372,
715,
267,
372,
756,
339,
347,
675,
63,
4774,
22,
8,
277,
304,
267,
1449,
1831,
12042,
7526,
370,
675,
6509,
22,
2344,
267,
340,
291,
14,
4322,
14,
1989,
63,
498,
360,
4774,
22,
358,
436,
971,
1779,
291,
14,
4322,
459,
4774,
22,
418,
508,
283,
5066,
7,
436,
971,
1779,
747,
14,
515,
14,
2444,
4769,
4687,
15,
1274,
15,
846,
15,
4774,
22,
2349,
288,
372,
715,
267,
372,
756,
339,
347,
485,
362,
63,
885,
63,
3185,
8,
277,
12,
5062,
628,
1210,
2349,
267,
1449,
1002,
849,
4592,
367,
2013,
5062,
6036,
2344,
267,
4592,
275,
298,
885,
12172,
435,
5062,
435,
2668,
3185,
2,
398,
519,
495,
275,
3087,
267,
340,
291,
14,
4322,
59,
3185,
61,
508,
298,
5694,
582,
288,
519,
495,
275,
298,
3306,
2,
267,
916,
291,
14,
4322,
59,
3185,
61,
508,
298,
5694,
63,
889,
63,
3885,
582,
288,
519,
495,
275,
298,
3306,
13,
7395,
13,
14428,
2,
267,
916,
291,
14,
4322,
59,
3185,
61,
508,
298,
16857,
582,
288,
519,
495,
275,
298,
16857,
2,
267,
587,
26,
288,
519,
495,
275,
298,
23040,
2,
398,
372,
519,
495,
339,
347,
485,
1117,
63,
8625,
8,
277,
304,
267,
1449,
20906,
5678,
6391,
5920,
26,
267,
365,
663,
1535,
503,
663,
8787,
334,
509,
2222,
13,
14091,
10460,
9,
267,
5920,
626,
2884,
365,
23191,
701,
1738,
267,
5920,
626,
4036,
3931,
315,
3679,
931,
787,
23191,
701,
1738,
267,
7987,
340,
2884,
365,
1572,
17267,
267,
7987,
340,
1777,
402,
2884,
931,
365,
1572,
17267,
398,
4226,
316,
642,
737,
314,
9608,
14486,
282,
21209,
5558,
543,
2945,
267,
5331,
626,
2793,
1133,
886,
3520,
5920,
14,
221,
9738,
12,
340,
314,
922,
3879,
267,
642,
2884,
365,
1738,
12,
2066,
1929,
370,
506,
1738,
370,
15868,
390,
314,
21209,
267,
5558,
334,
460,
1265,
787,
2636,
939,
15988,
11965,
267,
1449,
398,
340,
440,
291,
14,
1117,
63,
8625,
26,
288,
2329,
63,
1328,
275,
3824,
11834,
6980,
531,
288,
7987,
8,
1508,
63,
1328,
9,
288,
372,
715,
398,
327,
2832,
4346,
641,
10130,
12,
1325,
3963,
19428,
314,
9825,
781,
911,
2621,
1396,
267,
340,
747,
14,
362,
1535,
342,
1137,
747,
14,
31508,
1535,
837,
288,
2329,
63,
1328,
275,
3824,
3170,
26,
642,
2884,
1077,
440,
506,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dkodnik/arp
|
addons/point_of_sale/wizard/__init__.py
|
382
|
1200
|
# -*- 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 pos_box
import pos_confirm
import pos_details
import pos_discount
import pos_open_statement
import pos_payment
import pos_session_opening
# 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,
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,
420,
199,
3,
199,
4605,
199,
199,
646,
2086,
63,
1977,
199,
646,
2086,
63,
9548,
199,
646,
2086,
63,
5087,
199,
646,
2086,
63,
15446,
199,
646,
2086,
63,
1490,
63,
6242,
199,
646,
2086,
63,
7948,
199,
646,
2086,
63,
1730,
63,
21849,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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,
420,
199,
3,
199,
4605,
199,
199,
646,
2086,
63,
1977,
199,
646,
2086,
63,
9548,
199,
646,
2086,
63,
5087,
199,
646,
2086,
63,
15446,
199,
646,
2086,
63,
1490,
63,
6242,
199,
646,
2086,
63,
7948,
199,
646,
2086,
63,
1730,
63,
21849,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
jamielennox/deluge
|
ez_setup.py
|
8
|
10077
|
#!python
"""Bootstrap setuptools installation
If you want to use setuptools in your package's setup.py, just include this
file in the same directory with it, and add this to the top of your setup.py::
from ez_setup import use_setuptools
use_setuptools()
If you want to require a specific version of setuptools, set a download
mirror, or use an alternate download directory, you can do so by supplying
the appropriate options to ``use_setuptools()``.
This file can also be run as a script to install or upgrade setuptools.
"""
import sys
DEFAULT_VERSION = "0.6c11"
DEFAULT_URL = "http://pypi.python.org/packages/%s/s/setuptools/" % sys.version[:3]
md5_data = {
'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca',
'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb',
'setuptools-0.6b2-py2.3.egg': '5657759d8a6d8fc44070a9d07272d99b',
'setuptools-0.6b2-py2.4.egg': '4996a8d169d2be661fa32a6e52e4f82a',
'setuptools-0.6b3-py2.3.egg': 'bb31c0fc7399a63579975cad9f5a0618',
'setuptools-0.6b3-py2.4.egg': '38a8c6b3d6ecd22247f179f7da669fac',
'setuptools-0.6b4-py2.3.egg': '62045a24ed4e1ebc77fe039aa4e6f7e5',
'setuptools-0.6b4-py2.4.egg': '4cb2a185d228dacffb2d17f103b3b1c4',
'setuptools-0.6c1-py2.3.egg': 'b3f2b5539d65cb7f74ad79127f1a908c',
'setuptools-0.6c1-py2.4.egg': 'b45adeda0667d2d2ffe14009364f2a4b',
'setuptools-0.6c2-py2.3.egg': 'f0064bf6aa2b7d0f3ba0b43f20817c27',
'setuptools-0.6c2-py2.4.egg': '616192eec35f47e8ea16cd6a122b7277',
'setuptools-0.6c3-py2.3.egg': 'f181fa125dfe85a259c9cd6f1d7b78fa',
'setuptools-0.6c3-py2.4.egg': 'e0ed74682c998bfb73bf803a50e7b71e',
'setuptools-0.6c3-py2.5.egg': 'abef16fdd61955514841c7c6bd98965e',
'setuptools-0.6c4-py2.3.egg': 'b0b9131acab32022bfac7f44c5d7971f',
'setuptools-0.6c4-py2.4.egg': '2a1f9656d4fbf3c97bf946c0a124e6e2',
'setuptools-0.6c4-py2.5.egg': '8f5a052e32cdb9c72bcf4b5526f28afc',
'setuptools-0.6c5-py2.3.egg': 'ee9fd80965da04f2f3e6b3576e9d8167',
'setuptools-0.6c5-py2.4.egg': 'afe2adf1c01701ee841761f5bcd8aa64',
'setuptools-0.6c5-py2.5.egg': 'a8d3f61494ccaa8714dfed37bccd3d5d',
'setuptools-0.6c6-py2.3.egg': '35686b78116a668847237b69d549ec20',
'setuptools-0.6c6-py2.4.egg': '3c56af57be3225019260a644430065ab',
'setuptools-0.6c6-py2.5.egg': 'b2f8a7520709a5b34f80946de5f02f53',
'setuptools-0.6c7-py2.3.egg': '209fdf9adc3a615e5115b725658e13e2',
'setuptools-0.6c7-py2.4.egg': '5a8f954807d46a0fb67cf1f26c55a82e',
'setuptools-0.6c7-py2.5.egg': '45d2ad28f9750e7434111fde831e8372',
'setuptools-0.6c8-py2.3.egg': '50759d29b349db8cfd807ba8303f1902',
'setuptools-0.6c8-py2.4.egg': 'cba38d74f7d483c06e9daa6070cce6de',
'setuptools-0.6c8-py2.5.egg': '1721747ee329dc150590a58b3e1ac95b',
'setuptools-0.6c9-py2.3.egg': 'a83c4020414807b496e4cfbe08507c03',
'setuptools-0.6c9-py2.4.egg': '260a2be2e5388d66bdaee06abec6342a',
'setuptools-0.6c9-py2.5.egg': 'fe67c3e5a17b12c0e7c541b7ea43a8e6',
'setuptools-0.6c9-py2.6.egg': 'ca37b1ff16fa2ede6e19383e7b59245a',
'setuptools-0.6c11-py2.3.egg' : '2baeac6e13d414a9d28e7ba5b5a596de',
'setuptools-0.6c11-py2.4.egg' : 'bd639f9b0eac4c42497034dec2ec0c2b',
'setuptools-0.6c11-py2.5.egg' : '64c94f3bf7a72a13ec83e0b24f2749b2',
'setuptools-0.6c11-py2.6.egg' : 'bfa92100bd772d5a213eedd356d64086',
'setuptools-0.6c11-py2.7.egg' : 'fe1f997bc722265116870bc7919059ea',
}
import sys, os
try: from hashlib import md5
except ImportError: from md5 import md5
def _validate_md5(egg_name, data):
if egg_name in md5_data:
digest = md5(data).hexdigest()
if digest != md5_data[egg_name]:
print >>sys.stderr, (
"md5 validation of %s failed! (Possible download problem?)"
% egg_name
)
sys.exit(2)
return data
def use_setuptools(
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
download_delay=15
):
"""Automatically find/download setuptools and make it available on sys.path
`version` should be a valid setuptools version number that is available
as an egg for download under the `download_base` URL (which should end with
a '/'). `to_dir` is the directory where setuptools will be downloaded, if
it is not already available. If `download_delay` is specified, it should
be the number of seconds that will be paused before initiating a download,
should one be required. If an older version of setuptools is installed,
this routine will print a message to ``sys.stderr`` and raise SystemExit in
an attempt to abort the calling script.
"""
was_imported = 'pkg_resources' in sys.modules or 'setuptools' in sys.modules
def do_download():
egg = download_setuptools(version, download_base, to_dir, download_delay)
sys.path.insert(0, egg)
import setuptools; setuptools.bootstrap_install_from = egg
try:
import pkg_resources
except ImportError:
return do_download()
try:
pkg_resources.require("setuptools>="+version); return
except pkg_resources.VersionConflict, e:
if was_imported:
print >>sys.stderr, (
"The required version of setuptools (>=%s) is not available, and\n"
"can't be installed while this script is running. Please install\n"
" a more recent version first, using 'easy_install -U setuptools'."
"\n\n(Currently using %r)"
) % (version, e.args[0])
sys.exit(2)
else:
del pkg_resources, sys.modules['pkg_resources'] # reload ok
return do_download()
except pkg_resources.DistributionNotFound:
return do_download()
def download_setuptools(
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
delay = 15
):
"""Download setuptools from a specified location and return its filename
`version` should be a valid setuptools version number that is available
as an egg for download under the `download_base` URL (which should end
with a '/'). `to_dir` is the directory where the egg will be downloaded.
`delay` is the number of seconds to pause before an actual download attempt.
"""
import urllib2, shutil
egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3])
url = download_base + egg_name
saveto = os.path.join(to_dir, egg_name)
src = dst = None
if not os.path.exists(saveto): # Avoid repeated downloads
try:
from distutils import log
if delay:
log.warn("""
---------------------------------------------------------------------------
This script requires setuptools version %s to run (even to display
help). I will attempt to download it for you (from
%s), but
you may need to enable firewall access for this script first.
I will start the download in %d seconds.
(Note: if this machine does not have network access, please obtain the file
%s
and place it in this directory before rerunning this script.)
---------------------------------------------------------------------------""",
version, download_base, delay, url
); from time import sleep; sleep(delay)
log.warn("Downloading %s", url)
src = urllib2.urlopen(url)
# Read/write all in one block, so we don't create a corrupt file
# if the download is interrupted.
data = _validate_md5(egg_name, src.read())
dst = open(saveto,"wb"); dst.write(data)
finally:
if src: src.close()
if dst: dst.close()
return os.path.realpath(saveto)
def main(argv, version=DEFAULT_VERSION):
"""Install or upgrade setuptools and EasyInstall"""
try:
import setuptools
except ImportError:
egg = None
try:
egg = download_setuptools(version, delay=0)
sys.path.insert(0,egg)
from setuptools.command.easy_install import main
return main(list(argv)+[egg]) # we're done here
finally:
if egg and os.path.exists(egg):
os.unlink(egg)
else:
if setuptools.__version__ == '0.0.1':
print >>sys.stderr, (
"You have an obsolete version of setuptools installed. Please\n"
"remove it from your system entirely before rerunning this script."
)
sys.exit(2)
req = "setuptools>="+version
import pkg_resources
try:
pkg_resources.require(req)
except pkg_resources.VersionConflict:
try:
from setuptools.command.easy_install import main
except ImportError:
from easy_install import main
main(list(argv)+[download_setuptools(delay=0)])
sys.exit(0) # try to force an exit
else:
if argv:
from setuptools.command.easy_install import main
main(argv)
else:
print "Setuptools version",version,"or greater has been installed."
print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)'
def update_md5(filenames):
"""Update our built-in md5 registry"""
import re
for name in filenames:
base = os.path.basename(name)
f = open(name,'rb')
md5_data[base] = md5(f.read()).hexdigest()
f.close()
data = [" %r: %r,\n" % it for it in md5_data.items()]
data.sort()
repl = "".join(data)
import inspect
srcfile = inspect.getsourcefile(sys.modules[__name__])
f = open(srcfile, 'rb'); src = f.read(); f.close()
match = re.search("\nmd5_data = {\n([^}]+)}", src)
if not match:
print >>sys.stderr, "Internal error!"
sys.exit(2)
src = src[:match.start(1)] + repl + src[match.end(1):]
f = open(srcfile,'w')
f.write(src)
f.close()
if __name__=='__main__':
if len(sys.argv)>2 and sys.argv[1]=='--md5update':
update_md5(sys.argv[2:])
else:
main(sys.argv[1:])
|
gpl-3.0
|
[
3168,
1548,
199,
624,
17989,
7868,
9116,
12096,
199,
199,
3917,
1265,
2934,
370,
675,
9116,
315,
2195,
2559,
1159,
3272,
14,
647,
12,
2951,
2387,
642,
199,
493,
315,
314,
2011,
2082,
543,
652,
12,
436,
1050,
642,
370,
314,
2746,
402,
2195,
3272,
14,
647,
447,
339,
687,
325,
90,
63,
2758,
492,
675,
63,
13623,
272,
675,
63,
13623,
342,
199,
199,
3917,
1265,
2934,
370,
4409,
282,
2488,
1015,
402,
9116,
12,
663,
282,
5235,
199,
12324,
12,
503,
675,
376,
18034,
5235,
2082,
12,
1265,
883,
886,
880,
701,
4973,
6670,
199,
1589,
5827,
1511,
370,
1124,
1180,
63,
13623,
28566,
199,
199,
2765,
570,
883,
2597,
506,
1255,
465,
282,
2884,
370,
3907,
503,
10754,
9116,
14,
199,
624,
199,
646,
984,
199,
3472,
63,
4612,
275,
298,
16,
14,
22,
67,
845,
2,
199,
3472,
63,
2632,
258,
275,
298,
1014,
921,
17343,
14,
1548,
14,
1308,
15,
5154,
3149,
83,
15,
83,
15,
13623,
6687,
450,
984,
14,
1023,
1491,
19,
61,
199,
199,
1064,
21,
63,
576,
275,
469,
272,
283,
13623,
13,
16,
14,
22,
66,
17,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
1299,
1081,
27956,
23166,
7991,
68,
15186,
66,
14140,
66,
23,
70,
821,
67,
22,
69,
22,
696,
297,
272,
283,
13623,
13,
16,
14,
22,
66,
17,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
66,
1965,
65,
24,
65,
13353,
69,
2322,
996,
70,
2501,
2426,
1024,
19,
70,
10860,
1196,
1276,
2894,
297,
272,
283,
13623,
13,
16,
14,
22,
66,
18,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
1367,
13539,
1427,
68,
24,
65,
22,
68,
24,
3003,
1602,
19235,
65,
25,
68,
1780,
12900,
68,
1020,
66,
297,
272,
283,
13623,
13,
16,
14,
22,
66,
18,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
20,
14140,
65,
24,
68,
10143,
68,
18,
1235,
19528,
667,
708,
65,
22,
69,
2528,
69,
20,
70,
2564,
65,
297,
272,
283,
13623,
13,
16,
14,
22,
66,
19,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
2501,
2192,
67,
16,
3003,
2898,
1020,
65,
22,
13155,
1020,
2194,
28806,
25,
70,
21,
65,
1690,
1085,
297,
272,
283,
13623,
13,
16,
14,
22,
66,
19,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
1703,
65,
24,
67,
22,
66,
19,
68,
22,
30441,
1081,
11717,
70,
10699,
70,
23,
983,
15014,
12668,
297,
272,
283,
13623,
13,
16,
14,
22,
66,
20,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
2789,
12618,
65,
1194,
379,
20,
69,
17,
26816,
1138,
771,
10005,
2158,
20,
69,
22,
70,
23,
69,
21,
297,
272,
283,
13623,
13,
16,
14,
22,
66,
20,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
20,
2894,
18,
65,
10233,
68,
12048,
31811,
31311,
18,
68,
1196,
70,
8845,
66,
19,
66,
17,
67,
20,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
17,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
66,
19,
70,
18,
66,
1229,
1355,
68,
2182,
2894,
23,
70,
1342,
350,
1965,
4195,
70,
17,
65,
25,
2036,
67,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
17,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
66,
2322,
3074,
65,
14045,
23,
68,
18,
68,
18,
2026,
1079,
383,
3129,
772,
70,
18,
65,
20,
66,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
18,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
70,
29851,
4361,
22,
2158,
18,
66,
23,
68,
16,
70,
19,
2470,
16,
66,
2824,
70,
10630,
1196,
67,
1465,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
18,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
26666,
5756,
69,
825,
1276,
70,
2417,
69,
24,
4489,
975,
2866,
22,
65,
7507,
66,
2819,
1138,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
19,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
70,
12851,
667,
6889,
68,
771,
2426,
65,
11990,
67,
25,
2866,
22,
70,
17,
68,
23,
66,
2277,
667,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
19,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
69,
16,
379,
1342,
24255,
67,
13830,
4361,
66,
2898,
4361,
14187,
65,
1400,
69,
23,
66,
3172,
69,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
19,
13,
647,
18,
14,
21,
14,
5799,
356,
283,
371,
2829,
975,
70,
617,
30270,
15722,
1079,
19211,
67,
23,
67,
22,
3691,
30924,
2182,
69,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
20,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
66,
16,
66,
25,
11780,
645,
371,
708,
16348,
4361,
645,
23,
70,
1602,
67,
21,
68,
1965,
3172,
70,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
20,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
18,
65,
17,
70,
2534,
1367,
68,
20,
70,
4361,
19,
67,
2576,
4361,
30626,
67,
16,
65,
7214,
69,
22,
69,
18,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
20,
13,
647,
18,
14,
21,
14,
5799,
356,
283,
24,
70,
21,
65,
19730,
69,
708,
24035,
25,
67,
2819,
66,
2177,
20,
66,
1229,
1479,
70,
1651,
2756,
67,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
21,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
1024,
25,
2592,
11782,
2182,
983,
966,
70,
18,
70,
19,
69,
22,
66,
1276,
2114,
69,
25,
68,
24,
10806,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
21,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
6504,
18,
24642,
17,
67,
9570,
614,
1024,
1349,
1196,
2976,
70,
21,
26333,
24,
2158,
772,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
21,
13,
647,
18,
14,
21,
14,
5799,
356,
283,
65,
24,
68,
19,
70,
32392,
2635,
30031,
65,
1555,
1079,
1587,
379,
1401,
21976,
68,
19,
68,
21,
68,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
22,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
1276,
10253,
66,
2277,
7524,
65,
1272,
1299,
2417,
10638,
66,
1876,
68,
15419
] |
[
1548,
199,
624,
17989,
7868,
9116,
12096,
199,
199,
3917,
1265,
2934,
370,
675,
9116,
315,
2195,
2559,
1159,
3272,
14,
647,
12,
2951,
2387,
642,
199,
493,
315,
314,
2011,
2082,
543,
652,
12,
436,
1050,
642,
370,
314,
2746,
402,
2195,
3272,
14,
647,
447,
339,
687,
325,
90,
63,
2758,
492,
675,
63,
13623,
272,
675,
63,
13623,
342,
199,
199,
3917,
1265,
2934,
370,
4409,
282,
2488,
1015,
402,
9116,
12,
663,
282,
5235,
199,
12324,
12,
503,
675,
376,
18034,
5235,
2082,
12,
1265,
883,
886,
880,
701,
4973,
6670,
199,
1589,
5827,
1511,
370,
1124,
1180,
63,
13623,
28566,
199,
199,
2765,
570,
883,
2597,
506,
1255,
465,
282,
2884,
370,
3907,
503,
10754,
9116,
14,
199,
624,
199,
646,
984,
199,
3472,
63,
4612,
275,
298,
16,
14,
22,
67,
845,
2,
199,
3472,
63,
2632,
258,
275,
298,
1014,
921,
17343,
14,
1548,
14,
1308,
15,
5154,
3149,
83,
15,
83,
15,
13623,
6687,
450,
984,
14,
1023,
1491,
19,
61,
199,
199,
1064,
21,
63,
576,
275,
469,
272,
283,
13623,
13,
16,
14,
22,
66,
17,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
1299,
1081,
27956,
23166,
7991,
68,
15186,
66,
14140,
66,
23,
70,
821,
67,
22,
69,
22,
696,
297,
272,
283,
13623,
13,
16,
14,
22,
66,
17,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
66,
1965,
65,
24,
65,
13353,
69,
2322,
996,
70,
2501,
2426,
1024,
19,
70,
10860,
1196,
1276,
2894,
297,
272,
283,
13623,
13,
16,
14,
22,
66,
18,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
1367,
13539,
1427,
68,
24,
65,
22,
68,
24,
3003,
1602,
19235,
65,
25,
68,
1780,
12900,
68,
1020,
66,
297,
272,
283,
13623,
13,
16,
14,
22,
66,
18,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
20,
14140,
65,
24,
68,
10143,
68,
18,
1235,
19528,
667,
708,
65,
22,
69,
2528,
69,
20,
70,
2564,
65,
297,
272,
283,
13623,
13,
16,
14,
22,
66,
19,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
2501,
2192,
67,
16,
3003,
2898,
1020,
65,
22,
13155,
1020,
2194,
28806,
25,
70,
21,
65,
1690,
1085,
297,
272,
283,
13623,
13,
16,
14,
22,
66,
19,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
1703,
65,
24,
67,
22,
66,
19,
68,
22,
30441,
1081,
11717,
70,
10699,
70,
23,
983,
15014,
12668,
297,
272,
283,
13623,
13,
16,
14,
22,
66,
20,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
2789,
12618,
65,
1194,
379,
20,
69,
17,
26816,
1138,
771,
10005,
2158,
20,
69,
22,
70,
23,
69,
21,
297,
272,
283,
13623,
13,
16,
14,
22,
66,
20,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
20,
2894,
18,
65,
10233,
68,
12048,
31811,
31311,
18,
68,
1196,
70,
8845,
66,
19,
66,
17,
67,
20,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
17,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
66,
19,
70,
18,
66,
1229,
1355,
68,
2182,
2894,
23,
70,
1342,
350,
1965,
4195,
70,
17,
65,
25,
2036,
67,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
17,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
66,
2322,
3074,
65,
14045,
23,
68,
18,
68,
18,
2026,
1079,
383,
3129,
772,
70,
18,
65,
20,
66,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
18,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
70,
29851,
4361,
22,
2158,
18,
66,
23,
68,
16,
70,
19,
2470,
16,
66,
2824,
70,
10630,
1196,
67,
1465,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
18,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
26666,
5756,
69,
825,
1276,
70,
2417,
69,
24,
4489,
975,
2866,
22,
65,
7507,
66,
2819,
1138,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
19,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
70,
12851,
667,
6889,
68,
771,
2426,
65,
11990,
67,
25,
2866,
22,
70,
17,
68,
23,
66,
2277,
667,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
19,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
69,
16,
379,
1342,
24255,
67,
13830,
4361,
66,
2898,
4361,
14187,
65,
1400,
69,
23,
66,
3172,
69,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
19,
13,
647,
18,
14,
21,
14,
5799,
356,
283,
371,
2829,
975,
70,
617,
30270,
15722,
1079,
19211,
67,
23,
67,
22,
3691,
30924,
2182,
69,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
20,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
66,
16,
66,
25,
11780,
645,
371,
708,
16348,
4361,
645,
23,
70,
1602,
67,
21,
68,
1965,
3172,
70,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
20,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
18,
65,
17,
70,
2534,
1367,
68,
20,
70,
4361,
19,
67,
2576,
4361,
30626,
67,
16,
65,
7214,
69,
22,
69,
18,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
20,
13,
647,
18,
14,
21,
14,
5799,
356,
283,
24,
70,
21,
65,
19730,
69,
708,
24035,
25,
67,
2819,
66,
2177,
20,
66,
1229,
1479,
70,
1651,
2756,
67,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
21,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
1024,
25,
2592,
11782,
2182,
983,
966,
70,
18,
70,
19,
69,
22,
66,
1276,
2114,
69,
25,
68,
24,
10806,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
21,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
6504,
18,
24642,
17,
67,
9570,
614,
1024,
1349,
1196,
2976,
70,
21,
26333,
24,
2158,
772,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
21,
13,
647,
18,
14,
21,
14,
5799,
356,
283,
65,
24,
68,
19,
70,
32392,
2635,
30031,
65,
1555,
1079,
1587,
379,
1401,
21976,
68,
19,
68,
21,
68,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
22,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
1276,
10253,
66,
2277,
7524,
65,
1272,
1299,
2417,
10638,
66,
1876,
68,
15419,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bluetib/netaddr
|
docs/source/conf.py
|
2
|
7898
|
# -*- coding: utf-8 -*-
#
# netaddr documentation build configuration file, created by
# sphinx-quickstart on Sun May 27 22:23:51 2012.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.viewcode']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'netaddr'
copyright = u'2008-2015, David P. D. Moss. All rights reserved'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.7.16'
# The full version, including alpha/beta/rc tags.
release = '0.7.18'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = []
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'netaddrdoc'
# -- Options for LaTeX output --------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'netaddr.tex', u'netaddr Documentation',
u'David P. D. Moss', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'netaddr', u'netaddr Documentation',
[u'David P. D. Moss'], 1)
]
# If true, show URL addresses after external links.
#man_show_urls = False
# -- Options for Texinfo output ------------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index',
'netaddr',
u'netaddr Documentation',
u'David P. D. Moss',
'netaddr',
'A network address manipulation library for Python',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
25798,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
25625,
10162,
8087,
6928,
26,
1789,
26,
2869,
6029,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
984,
12,
747,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24535,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
10065,
63,
8008,
275,
283,
17,
14,
16,
7,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
788,
8008,
14,
832,
14,
28056,
297,
283,
8008,
14,
832,
14,
11390,
297,
283,
8008,
14,
832,
14,
11396,
297,
283,
8008,
14,
832,
14,
10828,
297,
283,
8008,
14,
832,
14,
1345,
600,
418,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
846,
2697,
7,
199,
7307,
275,
399,
7,
9300,
13,
7806,
12,
20232,
510,
14,
577,
14,
3930,
385,
14,
2900,
4481,
4644,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
16,
14,
23,
14,
975,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
16,
14,
23,
14,
1085,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
3671,
275,
488,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
7970,
12,
3847,
370,
1350,
2082,
12,
626,
1336,
1584,
436,
199,
3,
6602,
370,
3686,
1380,
10023,
367,
1350,
1584,
14,
199,
5473,
63,
7435,
275,
942,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
1666,
314,
3794,
367,
199,
3,
282,
769,
402,
6762,
17915,
14,
199,
1360,
63,
7915,
275,
283,
885,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
1360,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
1360,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
25798,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
25625,
10162,
8087,
6928,
26,
1789,
26,
2869,
6029,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
984,
12,
747,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24535,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
10065,
63,
8008,
275,
283,
17,
14,
16,
7,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
788,
8008,
14,
832,
14,
28056,
297,
283,
8008,
14,
832,
14,
11390,
297,
283,
8008,
14,
832,
14,
11396,
297,
283,
8008,
14,
832,
14,
10828,
297,
283,
8008,
14,
832,
14,
1345,
600,
418,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
846,
2697,
7,
199,
7307,
275,
399,
7,
9300,
13,
7806,
12,
20232,
510,
14,
577,
14,
3930,
385,
14,
2900,
4481,
4644,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
16,
14,
23,
14,
975,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
16,
14,
23,
14,
1085,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
3671,
275,
488,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
7970,
12,
3847,
370,
1350,
2082,
12,
626,
1336,
1584,
436,
199,
3,
6602,
370,
3686,
1380,
10023,
367,
1350,
1584,
14,
199,
5473,
63,
7435,
275,
942,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
1666,
314,
3794,
367,
199,
3,
282,
769,
402,
6762,
17915,
14,
199,
1360,
63,
7915,
275,
283,
885,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
1360,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
1360,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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
|
3775
|
#!/usr/bin/env python
# encoding: utf-8
# daniel.svensson at purplescout.se 2008
import os
import Task, Options, Utils
from TaskGen import before, feature, after
from Configure import conf
@feature('rubyext')
@before('apply_incpaths', 'apply_type_vars', 'apply_lib_vars', 'apply_bundle')
@after('default_cc', 'vars_target_cshlib')
def init_rubyext(self):
self.default_install_path = '${ARCHDIR_RUBY}'
self.uselib = self.to_list(getattr(self, 'uselib', ''))
if not 'RUBY' in self.uselib:
self.uselib.append('RUBY')
if not 'RUBYEXT' in self.uselib:
self.uselib.append('RUBYEXT')
@feature('rubyext')
@before('apply_link')
def apply_ruby_so_name(self):
self.env['shlib_PATTERN'] = self.env['rubyext_PATTERN']
@conf
def check_ruby_version(conf, minver=()):
"""
Checks if ruby is installed.
If installed the variable RUBY will be set in environment.
Ruby binary can be overridden by --with-ruby-binary config variable
"""
if Options.options.rubybinary:
conf.env.RUBY = Options.options.rubybinary
else:
conf.find_program("ruby", var="RUBY", mandatory=True)
ruby = conf.env.RUBY
try:
version = Utils.cmd_output([ruby, '-e', 'puts defined?(VERSION) ? VERSION : RUBY_VERSION']).strip()
except:
conf.fatal('could not determine ruby version')
conf.env.RUBY_VERSION = version
try:
ver = tuple(map(int, version.split(".")))
except:
conf.fatal('unsupported ruby version %r' % version)
cver = ''
if minver:
if ver < minver:
conf.fatal('ruby is too old')
cver = ".".join([str(x) for x in minver])
conf.check_message('ruby', cver, True, version)
@conf
def check_ruby_ext_devel(conf):
if not conf.env.RUBY:
conf.fatal('ruby detection is required first')
if not conf.env.CC_NAME and not conf.env.CXX_NAME:
conf.fatal('load a c/c++ compiler first')
version = tuple(map(int, conf.env.RUBY_VERSION.split(".")))
def read_out(cmd):
return Utils.to_list(Utils.cmd_output([conf.env.RUBY, '-rrbconfig', '-e', cmd]))
def read_config(key):
return read_out('puts Config::CONFIG[%r]' % key)
ruby = conf.env['RUBY']
archdir = read_config('archdir')
cpppath = archdir
if version >= (1, 9, 0):
ruby_hdrdir = read_config('rubyhdrdir')
cpppath += ruby_hdrdir
cpppath += [os.path.join(ruby_hdrdir[0], read_config('arch')[0])]
conf.check(header_name='ruby.h', includes=cpppath, mandatory=True, errmsg='could not find ruby header file')
conf.env.LIBPATH_RUBYEXT = read_config('libdir')
conf.env.LIBPATH_RUBYEXT += archdir
conf.env.CPPPATH_RUBYEXT = cpppath
conf.env.CCFLAGS_RUBYEXT = read_config("CCDLFLAGS")
conf.env.rubyext_PATTERN = '%s.' + read_config('DLEXT')[0]
# ok this is really stupid, but the command and flags are combined.
# so we try to find the first argument...
flags = read_config('LDSHARED')
while flags and flags[0][0] != '-':
flags = flags[1:]
# we also want to strip out the deprecated ppc flags
if len(flags) > 1 and flags[1] == "ppc":
flags = flags[2:]
conf.env.LINKFLAGS_RUBYEXT = flags
conf.env.LINKFLAGS_RUBYEXT += read_config("LIBS")
conf.env.LINKFLAGS_RUBYEXT += read_config("LIBRUBYARG_SHARED")
if Options.options.rubyarchdir:
conf.env.ARCHDIR_RUBY = Options.options.rubyarchdir
else:
conf.env.ARCHDIR_RUBY = read_config('sitearchdir')[0]
if Options.options.rubylibdir:
conf.env.LIBDIR_RUBY = Options.options.rubylibdir
else:
conf.env.LIBDIR_RUBY = read_config('sitelibdir')[0]
def set_options(opt):
opt.add_option('--with-ruby-archdir', type='string', dest='rubyarchdir', help='Specify directory where to install arch specific files')
opt.add_option('--with-ruby-libdir', type='string', dest='rubylibdir', help='Specify alternate ruby library path')
opt.add_option('--with-ruby-binary', type='string', dest='rubybinary', help='Specify alternate ruby binary')
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
3,
366,
290,
14769,
14,
83,
1856,
385,
265,
737,
5861,
80,
2978,
31009,
14,
261,
9079,
199,
199,
646,
747,
199,
646,
8495,
12,
8394,
12,
17397,
199,
504,
8495,
8168,
492,
2544,
12,
3878,
12,
2410,
199,
504,
15453,
492,
3743,
199,
199,
32,
4445,
360,
21952,
832,
358,
199,
32,
5182,
360,
4998,
63,
6559,
3771,
297,
283,
4998,
63,
466,
63,
2936,
297,
283,
4998,
63,
773,
63,
2936,
297,
283,
4998,
63,
6469,
358,
199,
32,
4399,
360,
885,
63,
2055,
297,
283,
2936,
63,
1375,
63,
28736,
773,
358,
199,
318,
4205,
63,
21952,
832,
8,
277,
304,
199,
198,
277,
14,
885,
63,
3174,
63,
515,
275,
20044,
7762,
3022,
63,
50,
2533,
57,
6834,
199,
198,
277,
14,
1180,
773,
275,
291,
14,
475,
63,
513,
8,
5675,
8,
277,
12,
283,
1180,
773,
297,
12381,
199,
198,
692,
440,
283,
50,
2533,
57,
7,
315,
291,
14,
1180,
773,
26,
507,
198,
277,
14,
1180,
773,
14,
740,
360,
50,
2533,
57,
358,
199,
198,
692,
440,
283,
50,
2533,
57,
2472,
7,
315,
291,
14,
1180,
773,
26,
507,
198,
277,
14,
1180,
773,
14,
740,
360,
50,
2533,
57,
2472,
358,
199,
199,
32,
4445,
360,
21952,
832,
358,
199,
32,
5182,
360,
4998,
63,
1073,
358,
199,
318,
4838,
63,
21952,
63,
1152,
63,
354,
8,
277,
304,
199,
198,
277,
14,
1813,
459,
609,
773,
63,
10764,
418,
275,
291,
14,
1813,
459,
21952,
832,
63,
10764,
418,
199,
199,
32,
2190,
199,
318,
1104,
63,
21952,
63,
1023,
8,
2190,
12,
1748,
422,
23603,
199,
198,
624,
199,
198,
11834,
340,
31855,
365,
4903,
14,
199,
198,
3917,
4903,
314,
1750,
820,
2533,
57,
911,
506,
663,
315,
3734,
14,
199,
198,
50,
10972,
3366,
883,
506,
10087,
701,
1553,
1045,
13,
21952,
13,
3008,
1101,
1750,
199,
198,
624,
421,
198,
692,
8394,
14,
1419,
14,
21952,
3008,
26,
507,
198,
2190,
14,
1813,
14,
50,
2533,
57,
275,
8394,
14,
1419,
14,
21952,
3008,
199,
198,
2836,
26,
507,
198,
2190,
14,
1623,
63,
6815,
480,
21952,
401,
2729,
628,
50,
2533,
57,
401,
15230,
29,
549,
9,
421,
198,
21952,
275,
3743,
14,
1813,
14,
50,
2533,
57,
421,
198,
893,
26,
507,
198,
1023,
275,
17397,
14,
1760,
63,
1199,
779,
21952,
12,
2475,
69,
297,
283,
524,
83,
3247,
31,
8,
4612,
9,
5805,
15945,
520,
820,
2533,
57,
63,
4612,
13227,
1913,
342,
199,
198,
2590,
26,
507,
198,
2190,
14,
16208,
360,
15153,
440,
6705,
31855,
1015,
358,
199,
198,
2190,
14,
1813,
14,
50,
2533,
57,
63,
4612,
275,
1015,
421,
198,
893,
26,
507,
198,
422,
275,
2008,
8,
1130,
8,
442,
12,
1015,
14,
1294,
480,
2122,
1724,
199,
198,
2590,
26,
507,
198,
2190,
14,
16208,
360,
15267,
31855,
1015,
450,
82,
7,
450,
1015,
9,
421,
198,
67,
422,
275,
2125,
199,
198,
692,
1748,
422,
26,
507,
198,
692,
809,
665,
1748,
422,
26,
686,
198,
2190,
14,
16208,
360,
21952,
365,
4634,
2269,
358,
507,
198,
67,
422,
275,
32443,
904,
779,
495,
8,
88,
9,
367,
671,
315,
1748,
422,
566,
421,
198,
2190,
14,
1074,
63,
1188,
360,
21952,
297,
286,
422,
12,
715,
12,
1015,
9,
199,
199,
32,
2190,
199,
318,
1104,
63,
21952,
63,
832,
63,
27870,
8,
2190,
304,
199,
198,
692,
440,
3743,
14,
1813,
14,
50,
2533,
57,
26,
507,
198,
2190,
14,
16208,
360,
21952,
15212,
365,
1415,
1642,
358,
421,
198,
692,
440,
3743,
14,
1813,
14,
2571,
63,
2339,
436,
440,
3743,
14,
1813,
14,
12206,
63,
2339,
26,
507,
198,
2190,
14,
16208,
360,
912,
282,
286,
15,
67,
4176,
6365,
1642,
358,
421,
198,
1023,
275,
2008,
8,
1130,
8,
442,
12,
3743,
14,
1813,
14,
50,
2533,
57,
63,
4612,
14,
1294,
480,
2122,
1724,
421,
198,
318,
1586,
63,
548,
8,
1760,
304,
507,
198,
1107,
17397,
14,
475,
63,
513,
8,
7535,
14,
1760,
63,
1199,
779,
2190,
14,
1813,
14,
50,
2533,
57,
12,
2475,
82,
4848,
888,
297,
2475,
69,
297,
2088,
2459,
421,
198,
318,
1586,
63,
888,
8,
498,
304,
507,
198,
1107,
1586,
63,
548,
360,
524,
83,
4094,
447,
5569,
9722,
82,
6616,
450,
790,
9,
421,
198,
21952,
275,
3743,
14,
1813,
459,
50,
2533,
57,
418,
199,
198,
1047,
694,
275,
1586,
63,
888,
360,
1047,
694,
358,
199,
198,
5910,
515,
275,
3819,
694,
199,
198,
692,
1015,
2356,
334,
17,
12,
1749,
12,
378,
304,
507,
198,
21952,
63,
11244,
694,
275,
1586,
63,
888,
360,
21952,
11244,
694,
358,
507,
198,
5910,
515,
847,
31855,
63,
11244,
694,
507,
198,
5910,
515,
847,
359,
736,
14,
515,
14,
904,
8,
21952,
63,
11244,
694,
59,
16,
467,
1586,
63,
888,
360,
1047,
5832,
16,
12457,
421,
198,
2190,
14,
1074,
8,
1291,
63,
354,
534,
21952,
14,
72,
297,
6952,
29,
5910,
515,
12,
15230,
29,
549,
12,
22070,
534,
15153,
440,
2342,
31855,
1406,
570,
358,
421,
198,
2190,
14,
1813,
14,
32119,
63,
50,
2533,
57,
2472,
275,
1586,
63,
888,
360,
30789,
358,
199,
198,
2190,
14,
1813,
14,
32119,
63,
50,
2533,
57,
2472,
847,
3819,
694,
199,
198,
2190,
14,
1813,
14,
14533,
3243,
63,
50,
2533,
57,
2472,
275,
7246,
515,
199,
198,
2190,
14,
1813,
14,
2571,
4831,
63,
50,
2533,
57,
2472,
275,
1586,
63,
888,
480,
2571,
8045,
4831,
531,
199,
198,
2190,
14,
1813,
14,
21952,
832,
63,
10764,
275,
1543,
83,
3530,
435,
1586,
63,
888,
360,
36,
8066,
52,
5832,
16,
61,
421,
198,
3,
4112,
642,
365,
7710,
410,
31596,
12,
1325,
314,
1414,
436,
3285,
787,
12149,
14,
199,
198,
3,
880,
781,
862,
370,
2342,
314,
1642,
1423,
1396,
199,
198,
2469,
275,
1586,
63,
888,
360,
44,
3177,
30958,
1149,
358,
199,
198,
6710,
3285,
436,
3285,
59,
16,
1527,
16,
61,
1137,
20905,
507,
198,
2469,
275,
3285,
59,
17,
2938,
421,
198,
3,
781,
2597,
2934
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
3,
366,
290,
14769,
14,
83,
1856,
385,
265,
737,
5861,
80,
2978,
31009,
14,
261,
9079,
199,
199,
646,
747,
199,
646,
8495,
12,
8394,
12,
17397,
199,
504,
8495,
8168,
492,
2544,
12,
3878,
12,
2410,
199,
504,
15453,
492,
3743,
199,
199,
32,
4445,
360,
21952,
832,
358,
199,
32,
5182,
360,
4998,
63,
6559,
3771,
297,
283,
4998,
63,
466,
63,
2936,
297,
283,
4998,
63,
773,
63,
2936,
297,
283,
4998,
63,
6469,
358,
199,
32,
4399,
360,
885,
63,
2055,
297,
283,
2936,
63,
1375,
63,
28736,
773,
358,
199,
318,
4205,
63,
21952,
832,
8,
277,
304,
199,
198,
277,
14,
885,
63,
3174,
63,
515,
275,
20044,
7762,
3022,
63,
50,
2533,
57,
6834,
199,
198,
277,
14,
1180,
773,
275,
291,
14,
475,
63,
513,
8,
5675,
8,
277,
12,
283,
1180,
773,
297,
12381,
199,
198,
692,
440,
283,
50,
2533,
57,
7,
315,
291,
14,
1180,
773,
26,
507,
198,
277,
14,
1180,
773,
14,
740,
360,
50,
2533,
57,
358,
199,
198,
692,
440,
283,
50,
2533,
57,
2472,
7,
315,
291,
14,
1180,
773,
26,
507,
198,
277,
14,
1180,
773,
14,
740,
360,
50,
2533,
57,
2472,
358,
199,
199,
32,
4445,
360,
21952,
832,
358,
199,
32,
5182,
360,
4998,
63,
1073,
358,
199,
318,
4838,
63,
21952,
63,
1152,
63,
354,
8,
277,
304,
199,
198,
277,
14,
1813,
459,
609,
773,
63,
10764,
418,
275,
291,
14,
1813,
459,
21952,
832,
63,
10764,
418,
199,
199,
32,
2190,
199,
318,
1104,
63,
21952,
63,
1023,
8,
2190,
12,
1748,
422,
23603,
199,
198,
624,
199,
198,
11834,
340,
31855,
365,
4903,
14,
199,
198,
3917,
4903,
314,
1750,
820,
2533,
57,
911,
506,
663,
315,
3734,
14,
199,
198,
50,
10972,
3366,
883,
506,
10087,
701,
1553,
1045,
13,
21952,
13,
3008,
1101,
1750,
199,
198,
624,
421,
198,
692,
8394,
14,
1419,
14,
21952,
3008,
26,
507,
198,
2190,
14,
1813,
14,
50,
2533,
57,
275,
8394,
14,
1419,
14,
21952,
3008,
199,
198,
2836,
26,
507,
198,
2190,
14,
1623,
63,
6815,
480,
21952,
401,
2729,
628,
50,
2533,
57,
401,
15230,
29,
549,
9,
421,
198,
21952,
275,
3743,
14,
1813,
14,
50,
2533,
57,
421,
198,
893,
26,
507,
198,
1023,
275,
17397,
14,
1760,
63,
1199,
779,
21952,
12,
2475,
69,
297,
283,
524,
83,
3247,
31,
8,
4612,
9,
5805,
15945,
520,
820,
2533,
57,
63,
4612,
13227,
1913,
342,
199,
198,
2590,
26,
507,
198,
2190,
14,
16208,
360,
15153,
440,
6705,
31855,
1015,
358,
199,
198,
2190,
14,
1813,
14,
50,
2533,
57,
63,
4612,
275,
1015,
421,
198,
893,
26,
507,
198,
422,
275,
2008,
8,
1130,
8,
442,
12,
1015,
14,
1294,
480,
2122,
1724,
199,
198,
2590,
26,
507,
198,
2190,
14,
16208,
360,
15267,
31855,
1015,
450,
82,
7,
450,
1015,
9,
421,
198,
67,
422,
275,
2125,
199,
198,
692,
1748,
422,
26,
507,
198,
692,
809,
665,
1748,
422,
26,
686,
198,
2190,
14,
16208,
360,
21952,
365,
4634,
2269,
358,
507,
198,
67,
422,
275,
32443,
904,
779,
495,
8,
88,
9,
367,
671,
315,
1748,
422,
566,
421,
198,
2190,
14,
1074,
63,
1188,
360,
21952,
297,
286,
422,
12,
715,
12,
1015,
9,
199,
199,
32,
2190,
199,
318,
1104,
63,
21952,
63,
832,
63,
27870,
8,
2190,
304,
199,
198,
692,
440,
3743,
14,
1813,
14,
50,
2533,
57,
26,
507,
198,
2190,
14,
16208,
360,
21952,
15212,
365,
1415,
1642,
358,
421,
198,
692,
440,
3743,
14,
1813,
14,
2571,
63,
2339,
436,
440,
3743,
14,
1813,
14,
12206,
63,
2339,
26,
507,
198,
2190,
14,
16208,
360,
912,
282,
286,
15,
67,
4176,
6365,
1642,
358,
421,
198,
1023,
275,
2008,
8,
1130,
8,
442,
12,
3743,
14,
1813,
14,
50,
2533,
57,
63,
4612,
14,
1294,
480,
2122,
1724,
421,
198,
318,
1586,
63,
548,
8,
1760,
304,
507,
198,
1107,
17397,
14,
475,
63,
513,
8,
7535,
14,
1760,
63,
1199,
779,
2190,
14,
1813,
14,
50,
2533,
57,
12,
2475,
82,
4848,
888,
297,
2475,
69,
297,
2088,
2459,
421,
198,
318,
1586,
63,
888,
8,
498,
304,
507,
198,
1107,
1586,
63,
548,
360,
524,
83,
4094,
447,
5569,
9722,
82,
6616,
450,
790,
9,
421,
198,
21952,
275,
3743,
14,
1813,
459,
50,
2533,
57,
418,
199,
198,
1047,
694,
275,
1586,
63,
888,
360,
1047,
694,
358,
199,
198,
5910,
515,
275,
3819,
694,
199,
198,
692,
1015,
2356,
334,
17,
12,
1749,
12,
378,
304,
507,
198,
21952,
63,
11244,
694,
275,
1586,
63,
888,
360,
21952,
11244,
694,
358,
507,
198,
5910,
515,
847,
31855,
63,
11244,
694,
507,
198,
5910,
515,
847,
359,
736,
14,
515,
14,
904,
8,
21952,
63,
11244,
694,
59,
16,
467,
1586,
63,
888,
360,
1047,
5832,
16,
12457,
421,
198,
2190,
14,
1074,
8,
1291,
63,
354,
534,
21952,
14,
72,
297,
6952,
29,
5910,
515,
12,
15230,
29,
549,
12,
22070,
534,
15153,
440,
2342,
31855,
1406,
570,
358,
421,
198,
2190,
14,
1813,
14,
32119,
63,
50,
2533,
57,
2472,
275,
1586,
63,
888,
360,
30789,
358,
199,
198,
2190,
14,
1813,
14,
32119,
63,
50,
2533,
57,
2472,
847,
3819,
694,
199,
198,
2190,
14,
1813,
14,
14533,
3243,
63,
50,
2533,
57,
2472,
275,
7246,
515,
199,
198,
2190,
14,
1813,
14,
2571,
4831,
63,
50,
2533,
57,
2472,
275,
1586,
63,
888,
480,
2571,
8045,
4831,
531,
199,
198,
2190,
14,
1813,
14,
21952,
832,
63,
10764,
275,
1543,
83,
3530,
435,
1586,
63,
888,
360,
36,
8066,
52,
5832,
16,
61,
421,
198,
3,
4112,
642,
365,
7710,
410,
31596,
12,
1325,
314,
1414,
436,
3285,
787,
12149,
14,
199,
198,
3,
880,
781,
862,
370,
2342,
314,
1642,
1423,
1396,
199,
198,
2469,
275,
1586,
63,
888,
360,
44,
3177,
30958,
1149,
358,
199,
198,
6710,
3285,
436,
3285,
59,
16,
1527,
16,
61,
1137,
20905,
507,
198,
2469,
275,
3285,
59,
17,
2938,
421,
198,
3,
781,
2597,
2934,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
smikes/depot_tools
|
third_party/pylint/lint.py
|
18
|
39136
|
# Copyright (c) 2003-2010 Sylvain Thenault (thenault@gmail.com).
# Copyright (c) 2003-2010 LOGILAB S.A. (Paris, FRANCE).
# http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
""" %prog [options] module_or_package
Check that a module satisfy a coding standard (and more !).
%prog --help
Display this help message and exit.
%prog --help-msg <msg-id>[,<msg-id>]
Display help messages about given message identifiers and exit.
"""
# import this first to avoid builtin namespace pollution
from pylint.checkers import utils
import sys
import os
import re
import tokenize
from warnings import warn
from logilab.common.configuration import UnsupportedAction, OptionsManagerMixIn
from logilab.common.optik_ext import check_csv
from logilab.common.modutils import load_module_from_name
from logilab.common.interface import implements
from logilab.common.textutils import splitstrip
from logilab.common.ureports import Table, Text, Section
from logilab.common.__pkginfo__ import version as common_version
from logilab.astng import MANAGER, nodes, ASTNGBuildingException
from logilab.astng.__pkginfo__ import version as astng_version
from pylint.utils import PyLintASTWalker, UnknownMessage, MessagesHandlerMixIn,\
ReportsHandlerMixIn, MSG_TYPES, expand_modules
from pylint.interfaces import ILinter, IRawChecker, IASTNGChecker
from pylint.checkers import BaseRawChecker, EmptyReport, \
table_lines_from_stats
from pylint.reporters.text import TextReporter, ParseableTextReporter, \
VSTextReporter, ColorizedTextReporter
from pylint.reporters.html import HTMLReporter
from pylint import config
from pylint.__pkginfo__ import version
OPTION_RGX = re.compile('\s*#*\s*pylint:(.*)')
REPORTER_OPT_MAP = {'text': TextReporter,
'parseable': ParseableTextReporter,
'msvs': VSTextReporter,
'colorized': ColorizedTextReporter,
'html': HTMLReporter,}
# Python Linter class #########################################################
MSGS = {
'F0001': ('%s',
'Used when an error occurred preventing the analysis of a \
module (unable to find it for instance).'),
'F0002': ('%s: %s',
'Used when an unexpected error occurred while building the ASTNG \
representation. This is usually accompanied by a traceback. \
Please report such errors !'),
'F0003': ('ignored builtin module %s',
'Used to indicate that the user asked to analyze a builtin module\
which has been skipped.'),
'F0004': ('unexpected inferred value %s',
'Used to indicate that some value of an unexpected type has been \
inferred.'),
'F0010': ('error while code parsing: %s',
'Used when an exception occured while building the ASTNG \
representation which could be handled by astng.'),
'I0001': ('Unable to run raw checkers on built-in module %s',
'Used to inform that a built-in module has not been checked \
using the raw checkers.'),
'I0010': ('Unable to consider inline option %r',
'Used when an inline option is either badly formatted or can\'t \
be used inside modules.'),
'I0011': ('Locally disabling %s',
'Used when an inline option disables a message or a messages \
category.'),
'I0012': ('Locally enabling %s',
'Used when an inline option enables a message or a messages \
category.'),
'I0013': ('Ignoring entire file',
'Used to inform that the file will not be checked'),
'E0001': ('%s',
'Used when a syntax error is raised for a module.'),
'E0011': ('Unrecognized file option %r',
'Used when an unknown inline option is encountered.'),
'E0012': ('Bad option value %r',
'Used when a bad value for an inline option is encountered.'),
}
class PyLinter(OptionsManagerMixIn, MessagesHandlerMixIn, ReportsHandlerMixIn,
BaseRawChecker):
"""lint Python modules using external checkers.
This is the main checker controlling the other ones and the reports
generation. It is itself both a raw checker and an astng checker in order
to:
* handle message activation / deactivation at the module level
* handle some basic but necessary stats'data (number of classes, methods...)
IDE plugins developpers: you may have to call
`logilab.astng.builder.MANAGER.astng_cache.clear()` accross run if you want
to ensure the latest code version is actually checked.
"""
__implements__ = (ILinter, IRawChecker)
name = 'master'
priority = 0
level = 0
msgs = MSGS
may_be_disabled = False
@staticmethod
def make_options():
return (('ignore',
{'type' : 'csv', 'metavar' : '<file>[,<file>...]',
'dest' : 'black_list', 'default' : ('CVS',),
'help' : 'Add files or directories to the blacklist. \
They should be base names, not paths.'}),
('persistent',
{'default': True, 'type' : 'yn', 'metavar' : '<y_or_n>',
'level': 1,
'help' : 'Pickle collected data for later comparisons.'}),
('load-plugins',
{'type' : 'csv', 'metavar' : '<modules>', 'default' : (),
'level': 1,
'help' : 'List of plugins (as comma separated values of \
python modules names) to load, usually to register additional checkers.'}),
('output-format',
{'default': 'text', 'type': 'choice', 'metavar' : '<format>',
'choices': REPORTER_OPT_MAP.keys(),
'short': 'f',
'group': 'Reports',
'help' : 'Set the output format. Available formats are text,\
parseable, colorized, msvs (visual studio) and html'}),
('include-ids',
{'type' : 'yn', 'metavar' : '<y_or_n>', 'default' : 0,
'short': 'i',
'group': 'Reports',
'help' : 'Include message\'s id in output'}),
('files-output',
{'default': 0, 'type' : 'yn', 'metavar' : '<y_or_n>',
'group': 'Reports', 'level': 1,
'help' : 'Put messages in a separate file for each module / \
package specified on the command line instead of printing them on stdout. \
Reports (if any) will be written in a file name "pylint_global.[txt|html]".'}),
('reports',
{'default': 1, 'type' : 'yn', 'metavar' : '<y_or_n>',
'short': 'r',
'group': 'Reports',
'help' : 'Tells whether to display a full report or only the\
messages'}),
('evaluation',
{'type' : 'string', 'metavar' : '<python_expression>',
'group': 'Reports', 'level': 1,
'default': '10.0 - ((float(5 * error + warning + refactor + \
convention) / statement) * 10)',
'help' : 'Python expression which should return a note less \
than 10 (10 is the highest note). You have access to the variables errors \
warning, statement which respectively contain the number of errors / warnings\
messages and the total number of statements analyzed. This is used by the \
global evaluation report (RP0004).'}),
('comment',
{'default': 0, 'type' : 'yn', 'metavar' : '<y_or_n>',
'group': 'Reports', 'level': 1,
'help' : 'Add a comment according to your evaluation note. \
This is used by the global evaluation report (RP0004).'}),
('enable',
{'type' : 'csv', 'metavar': '<msg ids>',
'short': 'e',
'group': 'Messages control',
'help' : 'Enable the message, report, category or checker with the '
'given id(s). You can either give multiple identifier '
'separated by comma (,) or put this option multiple time.'}),
('disable',
{'type' : 'csv', 'metavar': '<msg ids>',
'short': 'd',
'group': 'Messages control',
'help' : 'Disable the message, report, category or checker '
'with the given id(s). You can either give multiple identifier'
' separated by comma (,) or put this option multiple time '
'(only on the command line, not in the configuration file '
'where it should appear only once).'}),
)
option_groups = (
('Messages control', 'Options controling analysis messages'),
('Reports', 'Options related to output formating and reporting'),
)
def __init__(self, options=(), reporter=None, option_groups=(),
pylintrc=None):
# some stuff has to be done before ancestors initialization...
#
# checkers / reporter / astng manager
self.reporter = None
self._checkers = {}
self._ignore_file = False
# visit variables
self.base_name = None
self.base_file = None
self.current_name = None
self.current_file = None
self.stats = None
# init options
self.options = options + PyLinter.make_options()
self.option_groups = option_groups + PyLinter.option_groups
self._options_methods = {
'enable': self.enable,
'disable': self.disable}
self._bw_options_methods = {'disable-msg': self.disable,
'enable-msg': self.enable}
full_version = '%%prog %s, \nastng %s, common %s\nPython %s' % (
version, astng_version, common_version, sys.version)
OptionsManagerMixIn.__init__(self, usage=__doc__,
version=full_version,
config_file=pylintrc or config.PYLINTRC)
MessagesHandlerMixIn.__init__(self)
ReportsHandlerMixIn.__init__(self)
BaseRawChecker.__init__(self)
# provided reports
self.reports = (('RP0001', 'Messages by category',
report_total_messages_stats),
('RP0002', '% errors / warnings by module',
report_messages_by_module_stats),
('RP0003', 'Messages',
report_messages_stats),
('RP0004', 'Global evaluation',
self.report_evaluation),
)
self.register_checker(self)
self._dynamic_plugins = []
self.load_provider_defaults()
self.set_reporter(reporter or TextReporter(sys.stdout))
def load_default_plugins(self):
from pylint import checkers
checkers.initialize(self)
def load_plugin_modules(self, modnames):
"""take a list of module names which are pylint plugins and load
and register them
"""
for modname in modnames:
if modname in self._dynamic_plugins:
continue
self._dynamic_plugins.append(modname)
module = load_module_from_name(modname)
module.register(self)
def set_reporter(self, reporter):
"""set the reporter used to display messages and reports"""
self.reporter = reporter
reporter.linter = self
def set_option(self, optname, value, action=None, optdict=None):
"""overridden from configuration.OptionsProviderMixin to handle some
special options
"""
if optname in self._options_methods or optname in self._bw_options_methods:
if value:
try:
meth = self._options_methods[optname]
except KeyError:
meth = self._bw_options_methods[optname]
warn('%s is deprecated, replace it by %s' % (
optname, optname.split('-')[0]), DeprecationWarning)
value = check_csv(None, optname, value)
if isinstance(value, (list, tuple)):
for _id in value :
meth(_id)
else :
meth(value)
elif optname == 'output-format':
self.set_reporter(REPORTER_OPT_MAP[value.lower()]())
try:
BaseRawChecker.set_option(self, optname, value, action, optdict)
except UnsupportedAction:
print >> sys.stderr, 'option %s can\'t be read from config file' % \
optname
# checkers manipulation methods ############################################
def register_checker(self, checker):
"""register a new checker
checker is an object implementing IRawChecker or / and IASTNGChecker
"""
assert checker.priority <= 0, 'checker priority can\'t be >= 0'
self._checkers.setdefault(checker.name, []).append(checker)
for r_id, r_title, r_cb in checker.reports:
self.register_report(r_id, r_title, r_cb, checker)
self.register_options_provider(checker)
if hasattr(checker, 'msgs'):
self.register_messages(checker)
checker.load_defaults()
def disable_noerror_messages(self):
for msgcat, msgids in self._msgs_by_category.iteritems():
if msgcat == 'E':
for msgid in msgids:
self.enable(msgid)
else:
for msgid in msgids:
self.disable(msgid)
def disable_reporters(self):
"""disable all reporters"""
for reporters in self._reports.values():
for report_id, _title, _cb in reporters:
self.disable_report(report_id)
def error_mode(self):
"""error mode: enable only errors; no reports, no persistent"""
self.disable_noerror_messages()
self.disable('miscellaneous')
self.set_option('reports', False)
self.set_option('persistent', False)
# block level option handling #############################################
#
# see func_block_disable_msg.py test case for expected behaviour
def process_tokens(self, tokens):
"""process tokens from the current module to search for module/block
level options
"""
comment = tokenize.COMMENT
newline = tokenize.NEWLINE
for (tok_type, _, start, _, line) in tokens:
if tok_type not in (comment, newline):
continue
match = OPTION_RGX.search(line)
if match is None:
continue
if match.group(1).strip() == "disable-all":
self.add_message('I0013', line=start[0])
self._ignore_file = True
return
try:
opt, value = match.group(1).split('=', 1)
except ValueError:
self.add_message('I0010', args=match.group(1).strip(),
line=start[0])
continue
opt = opt.strip()
if opt in self._options_methods or opt in self._bw_options_methods:
try:
meth = self._options_methods[opt]
except KeyError:
meth = self._bw_options_methods[opt]
warn('%s is deprecated, replace it by %s (%s, line %s)' % (
opt, opt.split('-')[0], self.current_file, line),
DeprecationWarning)
for msgid in splitstrip(value):
try:
meth(msgid, 'module', start[0])
except UnknownMessage:
self.add_message('E0012', args=msgid, line=start[0])
else:
self.add_message('E0011', args=opt, line=start[0])
def collect_block_lines(self, node, msg_state):
"""walk ast to collect block level options line numbers"""
# recurse on children (depth first)
for child in node.get_children():
self.collect_block_lines(child, msg_state)
first = node.fromlineno
last = node.tolineno
# first child line number used to distinguish between disable
# which are the first child of scoped node with those defined later.
# For instance in the code below:
#
# 1. def meth8(self):
# 2. """test late disabling"""
# 3. # pylint: disable=E1102
# 4. print self.blip
# 5. # pylint: disable=E1101
# 6. print self.bla
#
# E1102 should be disabled from line 1 to 6 while E1101 from line 5 to 6
#
# this is necessary to disable locally messages applying to class /
# function using their fromlineno
if isinstance(node, (nodes.Module, nodes.Class, nodes.Function)) and node.body:
firstchildlineno = node.body[0].fromlineno
else:
firstchildlineno = last
for msgid, lines in msg_state.iteritems():
for lineno, state in lines.items():
if first <= lineno <= last:
if lineno > firstchildlineno:
state = True
# set state for all lines for this block
first, last = node.block_range(lineno)
for line in xrange(first, last+1):
# do not override existing entries
if not line in self._module_msgs_state.get(msgid, ()):
if line in lines: # state change in the same block
state = lines[line]
try:
self._module_msgs_state[msgid][line] = state
except KeyError:
self._module_msgs_state[msgid] = {line: state}
del lines[lineno]
# code checking methods ###################################################
def get_checkers(self):
"""return all available checkers as a list"""
return [self] + [c for checkers in self._checkers.values()
for c in checkers if c is not self]
def prepare_checkers(self):
"""return checkers needed for activated messages and reports"""
if not self.config.reports:
self.disable_reporters()
# get needed checkers
neededcheckers = [self]
for checker in self.get_checkers()[1:]:
messages = set(msg for msg in checker.msgs
if self.is_message_enabled(msg))
if (messages or
any(self.report_is_enabled(r[0]) for r in checker.reports)):
neededcheckers.append(checker)
checker.active_msgs = messages
return neededcheckers
def check(self, files_or_modules):
"""main checking entry: check a list of files or modules from their
name.
"""
self.reporter.include_ids = self.config.include_ids
if not isinstance(files_or_modules, (list, tuple)):
files_or_modules = (files_or_modules,)
walker = PyLintASTWalker(self)
checkers = self.prepare_checkers()
rawcheckers = [c for c in checkers if implements(c, IRawChecker)
and c is not self]
# notify global begin
for checker in checkers:
checker.open()
if implements(checker, IASTNGChecker):
walker.add_checker(checker)
# build ast and check modules or packages
for descr in self.expand_files(files_or_modules):
modname, filepath = descr['name'], descr['path']
self.set_current_module(modname, filepath)
# get the module representation
astng = self.get_astng(filepath, modname)
if astng is None:
continue
self.base_name = descr['basename']
self.base_file = descr['basepath']
if self.config.files_output:
reportfile = 'pylint_%s.%s' % (modname, self.reporter.extension)
self.reporter.set_output(open(reportfile, 'w'))
self._ignore_file = False
# fix the current file (if the source file was not available or
# if it's actually a c extension)
self.current_file = astng.file
self.check_astng_module(astng, walker, rawcheckers)
# notify global end
self.set_current_module('')
self.stats['statement'] = walker.nbstatements
checkers.reverse()
for checker in checkers:
checker.close()
def expand_files(self, modules):
"""get modules and errors from a list of modules and handle errors
"""
result, errors = expand_modules(modules, self.config.black_list)
for error in errors:
message = modname = error["mod"]
key = error["key"]
self.set_current_module(modname)
if key == "F0001":
message = str(error["ex"]).replace(os.getcwd() + os.sep, '')
self.add_message(key, args=message)
return result
def set_current_module(self, modname, filepath=None):
"""set the name of the currently analyzed module and
init statistics for it
"""
if not modname and filepath is None:
return
self.current_name = modname
self.current_file = filepath or modname
self.stats['by_module'][modname] = {}
self.stats['by_module'][modname]['statement'] = 0
for msg_cat in MSG_TYPES.values():
self.stats['by_module'][modname][msg_cat] = 0
# XXX hack, to be correct we need to keep module_msgs_state
# for every analyzed module (the problem stands with localized
# messages which are only detected in the .close step)
if modname:
self._module_msgs_state = {}
self._module_msg_cats_state = {}
def get_astng(self, filepath, modname):
"""return a astng representation for a module"""
try:
return MANAGER.astng_from_file(filepath, modname, source=True)
except SyntaxError, ex:
self.add_message('E0001', line=ex.lineno, args=ex.msg)
except ASTNGBuildingException, ex:
self.add_message('F0010', args=ex)
except Exception, ex:
import traceback
traceback.print_exc()
self.add_message('F0002', args=(ex.__class__, ex))
def check_astng_module(self, astng, walker, rawcheckers):
"""check a module from its astng representation, real work"""
# call raw checkers if possible
if not astng.pure_python:
self.add_message('I0001', args=astng.name)
else:
#assert astng.file.endswith('.py')
# invoke IRawChecker interface on self to fetch module/block
# level options
self.process_module(astng)
if self._ignore_file:
return False
# walk ast to collect line numbers
orig_state = self._module_msgs_state.copy()
self._module_msgs_state = {}
self.collect_block_lines(astng, orig_state)
for checker in rawcheckers:
checker.process_module(astng)
# generate events to astng checkers
walker.walk(astng)
return True
# IASTNGChecker interface #################################################
def open(self):
"""initialize counters"""
self.stats = { 'by_module' : {},
'by_msg' : {},
}
for msg_cat in MSG_TYPES.values():
self.stats[msg_cat] = 0
def close(self):
"""close the whole package /module, it's time to make reports !
if persistent run, pickle results for later comparison
"""
if self.base_name is not None:
# load old results if any
old_stats = config.load_results(self.base_name)
if self.config.reports:
self.make_reports(self.stats, old_stats)
elif self.config.output_format == 'html':
self.reporter.display_results(Section())
# save results if persistent run
if self.config.persistent:
config.save_results(self.stats, self.base_name)
# specific reports ########################################################
def report_evaluation(self, sect, stats, old_stats):
"""make the global evaluation report"""
# check with at least check 1 statements (usually 0 when there is a
# syntax error preventing pylint from further processing)
if stats['statement'] == 0:
raise EmptyReport()
# get a global note for the code
evaluation = self.config.evaluation
try:
note = eval(evaluation, {}, self.stats)
except Exception, ex:
msg = 'An exception occurred while rating: %s' % ex
else:
stats['global_note'] = note
msg = 'Your code has been rated at %.2f/10' % note
if 'global_note' in old_stats:
msg += ' (previous run: %.2f/10)' % old_stats['global_note']
if self.config.comment:
msg = '%s\n%s' % (msg, config.get_note_message(note))
sect.append(Text(msg))
# some reporting functions ####################################################
def report_total_messages_stats(sect, stats, old_stats):
"""make total errors / warnings report"""
lines = ['type', 'number', 'previous', 'difference']
lines += table_lines_from_stats(stats, old_stats,
('convention', 'refactor',
'warning', 'error'))
sect.append(Table(children=lines, cols=4, rheaders=1))
def report_messages_stats(sect, stats, _):
"""make messages type report"""
if not stats['by_msg']:
# don't print this report when we didn't detected any errors
raise EmptyReport()
in_order = sorted([(value, msg_id)
for msg_id, value in stats['by_msg'].items()
if not msg_id.startswith('I')])
in_order.reverse()
lines = ('message id', 'occurrences')
for value, msg_id in in_order:
lines += (msg_id, str(value))
sect.append(Table(children=lines, cols=2, rheaders=1))
def report_messages_by_module_stats(sect, stats, _):
"""make errors / warnings by modules report"""
if len(stats['by_module']) == 1:
# don't print this report when we are analysing a single module
raise EmptyReport()
by_mod = {}
for m_type in ('fatal', 'error', 'warning', 'refactor', 'convention'):
total = stats[m_type]
for module in stats['by_module'].keys():
mod_total = stats['by_module'][module][m_type]
if total == 0:
percent = 0
else:
percent = float((mod_total)*100) / total
by_mod.setdefault(module, {})[m_type] = percent
sorted_result = []
for module, mod_info in by_mod.items():
sorted_result.append((mod_info['error'],
mod_info['warning'],
mod_info['refactor'],
mod_info['convention'],
module))
sorted_result.sort()
sorted_result.reverse()
lines = ['module', 'error', 'warning', 'refactor', 'convention']
for line in sorted_result:
if line[0] == 0 and line[1] == 0:
break
lines.append(line[-1])
for val in line[:-1]:
lines.append('%.2f' % val)
if len(lines) == 5:
raise EmptyReport()
sect.append(Table(children=lines, cols=5, rheaders=1))
# utilities ###################################################################
# this may help to import modules using gettext
try:
__builtins__._ = str
except AttributeError:
__builtins__['_'] = str
class ArgumentPreprocessingError(Exception):
"""Raised if an error occurs during argument preprocessing."""
def preprocess_options(args, search_for):
"""look for some options (keys of <search_for>) which have to be processed
before others
values of <search_for> are callback functions to call when the option is
found
"""
i = 0
while i < len(args):
arg = args[i]
if arg.startswith('--'):
try:
option, val = arg[2:].split('=', 1)
except ValueError:
option, val = arg[2:], None
try:
cb, takearg = search_for[option]
del args[i]
if takearg and val is None:
if i >= len(args) or args[i].startswith('-'):
raise ArgumentPreprocessingError(arg)
val = args[i]
del args[i]
cb(option, val)
except KeyError:
i += 1
else:
i += 1
class Run:
"""helper class to use as main for pylint :
run(*sys.argv[1:])
"""
LinterClass = PyLinter
option_groups = (
('Commands', 'Options which are actually commands. Options in this \
group are mutually exclusive.'),
)
def __init__(self, args, reporter=None, exit=True):
self._rcfile = None
self._plugins = []
try:
preprocess_options(args, {
# option: (callback, takearg)
'rcfile': (self.cb_set_rcfile, True),
'load-plugins': (self.cb_add_plugins, True),
})
except ArgumentPreprocessingError, e:
print >> sys.stderr, 'Argument %s expects a value.' % (e.args[0],)
sys.exit(32)
self.linter = linter = self.LinterClass((
('rcfile',
{'action' : 'callback', 'callback' : lambda *args: 1,
'type': 'string', 'metavar': '<file>',
'help' : 'Specify a configuration file.'}),
('init-hook',
{'action' : 'callback', 'type' : 'string', 'metavar': '<code>',
'callback' : cb_init_hook, 'level': 1,
'help' : 'Python code to execute, usually for sys.path \
manipulation such as pygtk.require().'}),
('help-msg',
{'action' : 'callback', 'type' : 'string', 'metavar': '<msg-id>',
'callback' : self.cb_help_message,
'group': 'Commands',
'help' : '''Display a help message for the given message id and \
exit. The value may be a comma separated list of message ids.'''}),
('list-msgs',
{'action' : 'callback', 'metavar': '<msg-id>',
'callback' : self.cb_list_messages,
'group': 'Commands', 'level': 1,
'help' : "Generate pylint's messages."}),
('full-documentation',
{'action' : 'callback', 'metavar': '<msg-id>',
'callback' : self.cb_full_documentation,
'group': 'Commands', 'level': 1,
'help' : "Generate pylint's full documentation."}),
('generate-rcfile',
{'action' : 'callback', 'callback' : self.cb_generate_config,
'group': 'Commands',
'help' : '''Generate a sample configuration file according to \
the current configuration. You can put other options before this one to get \
them in the generated configuration.'''}),
('generate-man',
{'action' : 'callback', 'callback' : self.cb_generate_manpage,
'group': 'Commands',
'help' : "Generate pylint's man page.",'hide': True}),
('errors-only',
{'action' : 'callback', 'callback' : self.cb_error_mode,
'short': 'E',
'help' : '''In error mode, checkers without error messages are \
disabled and for others, only the ERROR messages are displayed, and no reports \
are done by default'''}),
('profile',
{'type' : 'yn', 'metavar' : '<y_or_n>',
'default': False, 'hide': True,
'help' : 'Profiled execution.'}),
), option_groups=self.option_groups,
reporter=reporter, pylintrc=self._rcfile)
# register standard checkers
linter.load_default_plugins()
# load command line plugins
linter.load_plugin_modules(self._plugins)
# add some help section
linter.add_help_section('Environment variables', config.ENV_HELP, level=1)
linter.add_help_section('Output', '''
Using the default text output, the message format is :
MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE
There are 5 kind of message types :
* (C) convention, for programming standard violation
* (R) refactor, for bad code smell
* (W) warning, for python specific problems
* (E) error, for probable bugs in the code
* (F) fatal, if an error occurred which prevented pylint from doing further
processing.
''', level=1)
linter.add_help_section('Output status code', '''
Pylint should leave with following status code:
* 0 if everything went fine
* 1 if a fatal message was issued
* 2 if an error message was issued
* 4 if a warning message was issued
* 8 if a refactor message was issued
* 16 if a convention message was issued
* 32 on usage error
status 1 to 16 will be bit-ORed so you can know which different categories has
been issued by analysing pylint output status code
''', level=1)
# read configuration
linter.disable('W0704')
linter.read_config_file()
# is there some additional plugins in the file configuration, in
config_parser = linter.cfgfile_parser
if config_parser.has_option('MASTER', 'load-plugins'):
plugins = splitstrip(config_parser.get('MASTER', 'load-plugins'))
linter.load_plugin_modules(plugins)
# now we can load file config and command line, plugins (which can
# provide options) have been registered
linter.load_config_file()
if reporter:
# if a custom reporter is provided as argument, it may be overridden
# by file parameters, so re-set it here, but before command line
# parsing so it's still overrideable by command line option
linter.set_reporter(reporter)
try:
args = linter.load_command_line_configuration(args)
except SystemExit, exc:
if exc.code == 2: # bad options
exc.code = 32
raise
if not args:
print linter.help()
sys.exit(32)
# insert current working directory to the python path to have a correct
# behaviour
sys.path.insert(0, os.getcwd())
if self.linter.config.profile:
print >> sys.stderr, '** profiled run'
import cProfile, pstats
cProfile.runctx('linter.check(%r)' % args, globals(), locals(), 'stones.prof' )
data = pstats.Stats('stones.prof')
data.strip_dirs()
data.sort_stats('time', 'calls')
data.print_stats(30)
else:
linter.check(args)
sys.path.pop(0)
if exit:
sys.exit(self.linter.msg_status)
def cb_set_rcfile(self, name, value):
"""callback for option preprocessing (i.e. before optik parsing)"""
self._rcfile = value
def cb_add_plugins(self, name, value):
"""callback for option preprocessing (i.e. before optik parsing)"""
self._plugins.extend(splitstrip(value))
def cb_error_mode(self, *args, **kwargs):
"""error mode:
* disable all but error messages
* disable the 'miscellaneous' checker which can be safely deactivated in
debug
* disable reports
* do not save execution information
"""
self.linter.error_mode()
def cb_generate_config(self, *args, **kwargs):
"""optik callback for sample config file generation"""
self.linter.generate_config(skipsections=('COMMANDS',))
sys.exit(0)
def cb_generate_manpage(self, *args, **kwargs):
"""optik callback for sample config file generation"""
from pylint import __pkginfo__
self.linter.generate_manpage(__pkginfo__)
sys.exit(0)
def cb_help_message(self, option, optname, value, parser):
"""optik callback for printing some help about a particular message"""
self.linter.help_message(splitstrip(value))
sys.exit(0)
def cb_full_documentation(self, option, optname, value, parser):
"""optik callback for printing full documentation"""
self.linter.print_full_documentation()
sys.exit(0)
def cb_list_messages(self, option, optname, value, parser): # FIXME
"""optik callback for printing available messages"""
self.linter.list_messages()
sys.exit(0)
def cb_init_hook(option, optname, value, parser):
"""exec arbitrary code to set sys.path for instance"""
exec value
if __name__ == '__main__':
Run(sys.argv[1:])
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
13004,
13,
6542,
5515,
6371,
1581,
9442,
558,
334,
12726,
558,
32,
6799,
14,
957,
680,
199,
3,
1898,
334,
67,
9,
13004,
13,
6542,
5051,
1193,
1217,
428,
14,
33,
14,
334,
1262,
374,
12,
28671,
7140,
680,
199,
3,
1455,
921,
1544,
14,
793,
24142,
14,
4391,
15,
1553,
6016,
475,
26,
7811,
32,
793,
24142,
14,
4391,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
199,
3,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
199,
3,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
2436,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
446,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
12,
8217,
14,
199,
624,
450,
6595,
359,
1419,
61,
859,
63,
269,
63,
2491,
819,
2670,
626,
282,
859,
23082,
282,
2803,
4465,
334,
460,
1655,
8546,
680,
339,
450,
6595,
1553,
3437,
819,
12175,
642,
1720,
1245,
436,
4458,
14,
339,
450,
6595,
1553,
3437,
13,
1328,
665,
1328,
13,
344,
9514,
30027,
1328,
13,
344,
19109,
819,
12175,
1720,
3788,
3595,
1627,
1245,
14154,
436,
4458,
14,
199,
624,
199,
199,
3,
492,
642,
1642,
370,
5126,
6762,
3231,
11271,
2206,
199,
504,
4287,
14,
32514,
492,
3778,
199,
199,
646,
984,
199,
646,
747,
199,
646,
295,
199,
646,
13343,
199,
504,
3598,
492,
7987,
199,
199,
504,
943,
24142,
14,
2330,
14,
4758,
492,
19022,
3310,
12,
8394,
2988,
26527,
199,
504,
943,
24142,
14,
2330,
14,
411,
30298,
63,
832,
492,
1104,
63,
4737,
199,
504,
943,
24142,
14,
2330,
14,
1494,
1208,
492,
2248,
63,
578,
63,
504,
63,
354,
199,
504,
943,
24142,
14,
2330,
14,
3266,
492,
9031,
199,
504,
943,
24142,
14,
2330,
14,
505,
1208,
492,
3715,
1913,
199,
504,
943,
24142,
14,
2330,
14,
608,
5203,
492,
6957,
12,
4516,
12,
15247,
199,
504,
943,
24142,
14,
2330,
855,
4600,
815,
363,
492,
1015,
465,
2863,
63,
1023,
199,
199,
504,
943,
24142,
14,
1810,
2753,
492,
26688,
1254,
540,
12,
3380,
12,
20788,
12259,
16461,
1726,
199,
504,
943,
24142,
14,
1810,
2753,
855,
4600,
815,
363,
492,
1015,
465,
6073,
2753,
63,
1023,
199,
199,
504,
4287,
14,
1208,
492,
1611,
44,
442,
11307,
26020,
12,
14831,
2209,
12,
27377,
2461,
26527,
4202,
1362,
799,
5203,
2461,
26527,
12,
23620,
63,
7893,
12,
6544,
63,
3112,
199,
504,
4287,
14,
7436,
492,
473,
44,
1058,
12,
473,
7963,
3048,
12,
473,
11307,
12259,
3048,
199,
504,
4287,
14,
32514,
492,
3523,
7963,
3048,
12,
9630,
7457,
12,
971,
1362,
1817,
63,
1278,
63,
504,
63,
3200,
199,
504,
4287,
14,
1155,
27568,
14,
505,
492,
4516,
15891,
12,
6077,
461,
1872,
15891,
12,
971,
1362,
812,
840,
832,
15891,
12,
11581,
1759,
1872,
15891,
199,
504,
4287,
14,
1155,
27568,
14,
1360,
492,
4163,
15891,
199,
504,
4287,
492,
1101,
199,
199,
504,
4287,
855,
4600,
815,
363,
492,
1015,
421,
199,
13352,
63,
14058,
56,
275,
295,
14,
2014,
2258,
83,
10,
3,
7590,
83,
10,
26324,
26,
19276,
5942,
199,
22554,
726,
1157,
63,
5123,
63,
5443,
275,
791,
505,
356,
4516,
15891,
12,
490,
283,
1122,
461,
356,
6077,
461,
1872,
15891,
12,
490,
283,
8338,
356,
812,
840,
832,
15891,
12,
490,
283,
2326,
1759,
356,
11581,
1759,
1872,
15891,
12,
490,
283,
1360,
356,
4163,
15891,
28209,
421,
199,
3,
2018,
491,
1058,
1021,
10371,
19054,
199,
199,
3053,
8021,
275,
469,
272,
283,
38,
4183,
356,
16651,
83,
297,
1598,
283,
9167,
1380,
376,
1125,
8920,
7981,
316,
314,
11284,
402,
282,
971,
1598,
859,
334,
17200,
370,
2342,
652,
367,
1256,
680,
659,
272,
283,
38,
9425,
356,
16651,
83,
26,
450,
83,
297,
1598,
283,
9167,
1380,
376,
10537,
1125,
8920,
1830,
10015,
314,
20788,
12259,
971,
1598,
6025,
14,
961,
365,
9987,
1066,
863,
290,
5299,
701,
282,
5190,
14,
971,
1598,
7754,
3622,
4066,
2552,
8546,
659,
272,
283,
38,
16861,
356,
661,
11996,
6762,
859,
450,
83,
297,
1598,
283,
9167,
370,
6623,
626,
314,
922,
20864,
370,
19897,
282,
6762,
859,
60,
1598,
1314,
965,
2757,
9645,
8038,
272,
283,
38,
16643,
356,
661,
8953,
22515,
574,
450,
83,
297,
1598,
283,
9167,
370,
6623,
626,
2005,
574,
402,
376,
10537,
730,
965,
2757,
971,
1598,
22515,
8038,
272,
283,
38,
17657,
356,
661,
705,
1830,
1233,
6057,
26,
450,
83,
297,
1598,
283,
9167,
1380,
376,
1919,
28408,
1830,
10015,
314,
20788,
12259,
971,
2049,
6025,
1314,
4293,
506,
8860,
701,
6073,
2753,
8038,
2378,
283,
41,
4183,
356,
661,
6005,
370,
1255,
3066,
1104,
1192,
641,
6137,
13,
262,
859,
450,
83,
297,
1598,
283,
9167,
370,
315,
964,
626,
282,
6137,
13,
262,
859,
965,
440,
2757,
7923,
971,
1598,
1808,
314,
3066,
1104,
1192,
8038,
339,
283,
41,
17657,
356,
661,
6005,
370,
11201,
8308,
945,
450,
82,
297,
1598,
283,
9167,
1380,
376,
8308,
945,
365,
1902,
4875,
590,
7871,
503,
883,
3985,
84,
971,
1598,
506,
1202,
6272,
4621,
8038,
339,
283,
41,
20679,
356,
661,
3040,
1183,
30723,
450,
83,
297,
1598,
283,
9167,
1380,
376,
8308,
945,
28421,
282,
1245,
503,
282,
3788,
971,
1598,
4637,
8038,
272,
283,
41,
22728,
356,
661,
3040,
1183,
29310,
450,
83,
297,
1598,
283,
9167,
1380,
376,
8308,
945,
22741,
282,
1245,
503,
282,
3788,
971,
1598,
4637,
8038,
272,
283,
41,
24250,
356,
661,
32390,
8039,
570,
297,
1598,
283,
9167,
370,
315,
964,
626,
314,
570,
911
] |
[
1898,
334,
67,
9,
13004,
13,
6542,
5515,
6371,
1581,
9442,
558,
334,
12726,
558,
32,
6799,
14,
957,
680,
199,
3,
1898,
334,
67,
9,
13004,
13,
6542,
5051,
1193,
1217,
428,
14,
33,
14,
334,
1262,
374,
12,
28671,
7140,
680,
199,
3,
1455,
921,
1544,
14,
793,
24142,
14,
4391,
15,
1553,
6016,
475,
26,
7811,
32,
793,
24142,
14,
4391,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
199,
3,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
199,
3,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
2436,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
446,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
12,
8217,
14,
199,
624,
450,
6595,
359,
1419,
61,
859,
63,
269,
63,
2491,
819,
2670,
626,
282,
859,
23082,
282,
2803,
4465,
334,
460,
1655,
8546,
680,
339,
450,
6595,
1553,
3437,
819,
12175,
642,
1720,
1245,
436,
4458,
14,
339,
450,
6595,
1553,
3437,
13,
1328,
665,
1328,
13,
344,
9514,
30027,
1328,
13,
344,
19109,
819,
12175,
1720,
3788,
3595,
1627,
1245,
14154,
436,
4458,
14,
199,
624,
199,
199,
3,
492,
642,
1642,
370,
5126,
6762,
3231,
11271,
2206,
199,
504,
4287,
14,
32514,
492,
3778,
199,
199,
646,
984,
199,
646,
747,
199,
646,
295,
199,
646,
13343,
199,
504,
3598,
492,
7987,
199,
199,
504,
943,
24142,
14,
2330,
14,
4758,
492,
19022,
3310,
12,
8394,
2988,
26527,
199,
504,
943,
24142,
14,
2330,
14,
411,
30298,
63,
832,
492,
1104,
63,
4737,
199,
504,
943,
24142,
14,
2330,
14,
1494,
1208,
492,
2248,
63,
578,
63,
504,
63,
354,
199,
504,
943,
24142,
14,
2330,
14,
3266,
492,
9031,
199,
504,
943,
24142,
14,
2330,
14,
505,
1208,
492,
3715,
1913,
199,
504,
943,
24142,
14,
2330,
14,
608,
5203,
492,
6957,
12,
4516,
12,
15247,
199,
504,
943,
24142,
14,
2330,
855,
4600,
815,
363,
492,
1015,
465,
2863,
63,
1023,
199,
199,
504,
943,
24142,
14,
1810,
2753,
492,
26688,
1254,
540,
12,
3380,
12,
20788,
12259,
16461,
1726,
199,
504,
943,
24142,
14,
1810,
2753,
855,
4600,
815,
363,
492,
1015,
465,
6073,
2753,
63,
1023,
199,
199,
504,
4287,
14,
1208,
492,
1611,
44,
442,
11307,
26020,
12,
14831,
2209,
12,
27377,
2461,
26527,
4202,
1362,
799,
5203,
2461,
26527,
12,
23620,
63,
7893,
12,
6544,
63,
3112,
199,
504,
4287,
14,
7436,
492,
473,
44,
1058,
12,
473,
7963,
3048,
12,
473,
11307,
12259,
3048,
199,
504,
4287,
14,
32514,
492,
3523,
7963,
3048,
12,
9630,
7457,
12,
971,
1362,
1817,
63,
1278,
63,
504,
63,
3200,
199,
504,
4287,
14,
1155,
27568,
14,
505,
492,
4516,
15891,
12,
6077,
461,
1872,
15891,
12,
971,
1362,
812,
840,
832,
15891,
12,
11581,
1759,
1872,
15891,
199,
504,
4287,
14,
1155,
27568,
14,
1360,
492,
4163,
15891,
199,
504,
4287,
492,
1101,
199,
199,
504,
4287,
855,
4600,
815,
363,
492,
1015,
421,
199,
13352,
63,
14058,
56,
275,
295,
14,
2014,
2258,
83,
10,
3,
7590,
83,
10,
26324,
26,
19276,
5942,
199,
22554,
726,
1157,
63,
5123,
63,
5443,
275,
791,
505,
356,
4516,
15891,
12,
490,
283,
1122,
461,
356,
6077,
461,
1872,
15891,
12,
490,
283,
8338,
356,
812,
840,
832,
15891,
12,
490,
283,
2326,
1759,
356,
11581,
1759,
1872,
15891,
12,
490,
283,
1360,
356,
4163,
15891,
28209,
421,
199,
3,
2018,
491,
1058,
1021,
10371,
19054,
199,
199,
3053,
8021,
275,
469,
272,
283,
38,
4183,
356,
16651,
83,
297,
1598,
283,
9167,
1380,
376,
1125,
8920,
7981,
316,
314,
11284,
402,
282,
971,
1598,
859,
334,
17200,
370,
2342,
652,
367,
1256,
680,
659,
272,
283,
38,
9425,
356,
16651,
83,
26,
450,
83,
297,
1598,
283,
9167,
1380,
376,
10537,
1125,
8920,
1830,
10015,
314,
20788,
12259,
971,
1598,
6025,
14,
961,
365,
9987,
1066,
863,
290,
5299,
701,
282,
5190,
14,
971,
1598,
7754,
3622,
4066,
2552,
8546,
659,
272,
283,
38,
16861,
356,
661,
11996,
6762,
859,
450,
83,
297,
1598,
283,
9167,
370,
6623,
626,
314,
922,
20864,
370,
19897,
282,
6762,
859,
60,
1598,
1314,
965,
2757,
9645,
8038,
272,
283,
38,
16643,
356,
661,
8953,
22515,
574,
450,
83,
297,
1598,
283,
9167,
370,
6623,
626,
2005,
574,
402,
376,
10537,
730,
965,
2757,
971,
1598,
22515,
8038,
272,
283,
38,
17657,
356,
661,
705,
1830,
1233,
6057,
26,
450,
83,
297,
1598,
283,
9167,
1380,
376,
1919,
28408,
1830,
10015,
314,
20788,
12259,
971,
2049,
6025,
1314,
4293,
506,
8860,
701,
6073,
2753,
8038,
2378,
283,
41,
4183,
356,
661,
6005,
370,
1255,
3066,
1104,
1192,
641,
6137,
13,
262,
859,
450,
83,
297,
1598,
283,
9167,
370,
315,
964,
626,
282,
6137,
13,
262,
859,
965,
440,
2757,
7923,
971,
1598,
1808,
314,
3066,
1104,
1192,
8038,
339,
283,
41,
17657,
356,
661,
6005,
370,
11201,
8308,
945,
450,
82,
297,
1598,
283,
9167,
1380,
376,
8308,
945,
365,
1902,
4875,
590,
7871,
503,
883,
3985,
84,
971,
1598,
506,
1202,
6272,
4621,
8038,
339,
283,
41,
20679,
356,
661,
3040,
1183,
30723,
450,
83,
297,
1598,
283,
9167,
1380,
376,
8308,
945,
28421,
282,
1245,
503,
282,
3788,
971,
1598,
4637,
8038,
272,
283,
41,
22728,
356,
661,
3040,
1183,
29310,
450,
83,
297,
1598,
283,
9167,
1380,
376,
8308,
945,
22741,
282,
1245,
503,
282,
3788,
971,
1598,
4637,
8038,
272,
283,
41,
24250,
356,
661,
32390,
8039,
570,
297,
1598,
283,
9167,
370,
315,
964,
626,
314,
570,
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
1,
1,
1
] |
manics/ansible-modules-core
|
network/nxos/nxos_snmp_location.py
|
20
|
12471
|
#!/usr/bin/python
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
DOCUMENTATION = '''
---
module: nxos_snmp_location
version_added: "2.2"
short_description: Manages SNMP location information.
description:
- Manages SNMP location configuration.
extends_documentation_fragment: nxos
author:
- Jason Edelman (@jedelman8)
- Gabriele Gerbino (@GGabriele)
options:
location:
description:
- Location information.
required: true
state:
description:
- Manage the state of the resource.
required: false
default: present
choices: ['present','absent']
'''
EXAMPLES = '''
# ensure snmp location is configured
- nxos_snmp_location:
location: Test
state: present
host: {{ inventory_hostname }}
username: {{ un }}
password: {{ pwd }}
# ensure snmp location is not configured
- nxos_snmp_location:
location: Test
state: absent
host: {{ inventory_hostname }}
username: {{ un }}
password: {{ pwd }}
'''
RETURN = '''
proposed:
description: k/v pairs of parameters passed into module
returned: always
type: dict
sample: {"location": "New_Test"}
existing:
description: k/v pairs of existing snmp location
type: dict
sample: {"location": "Test"}
end_state:
description: k/v pairs of location info after module execution
returned: always
type: dict or null
sample: {"location": "New_Test"}
updates:
description: command sent to the device
returned: always
type: list
sample: ["snmp-server location New_Test"]
changed:
description: check to see if a change was made on the device
returned: always
type: boolean
sample: true
'''
import json
# COMMON CODE FOR MIGRATION
import re
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
from ansible.module_utils.shell import ShellError
try:
from ansible.module_utils.nxos import get_module
except ImportError:
from ansible.module_utils.nxos import NetworkModule
def to_list(val):
if isinstance(val, (list, tuple)):
return list(val)
elif val is not None:
return [val]
else:
return list()
class CustomNetworkConfig(NetworkConfig):
def expand_section(self, configobj, S=None):
if S is None:
S = list()
S.append(configobj)
for child in configobj.children:
if child in S:
continue
self.expand_section(child, S)
return S
def get_object(self, path):
for item in self.items:
if item.text == path[-1]:
parents = [p.text for p in item.parents]
if parents == path[:-1]:
return item
def to_block(self, section):
return '\n'.join([item.raw for item in section])
def get_section(self, path):
try:
section = self.get_section_objects(path)
return self.to_block(section)
except ValueError:
return list()
def get_section_objects(self, path):
if not isinstance(path, list):
path = [path]
obj = self.get_object(path)
if not obj:
raise ValueError('path does not exist in config')
return self.expand_section(obj)
def add(self, lines, parents=None):
"""Adds one or lines of configuration
"""
ancestors = list()
offset = 0
obj = None
## global config command
if not parents:
for line in to_list(lines):
item = ConfigLine(line)
item.raw = line
if item not in self.items:
self.items.append(item)
else:
for index, p in enumerate(parents):
try:
i = index + 1
obj = self.get_section_objects(parents[:i])[0]
ancestors.append(obj)
except ValueError:
# add parent to config
offset = index * self.indent
obj = ConfigLine(p)
obj.raw = p.rjust(len(p) + offset)
if ancestors:
obj.parents = list(ancestors)
ancestors[-1].children.append(obj)
self.items.append(obj)
ancestors.append(obj)
# add child objects
for line in to_list(lines):
# check if child already exists
for child in ancestors[-1].children:
if child.text == line:
break
else:
offset = len(parents) * self.indent
item = ConfigLine(line)
item.raw = line.rjust(len(line) + offset)
item.parents = ancestors
ancestors[-1].children.append(item)
self.items.append(item)
def get_network_module(**kwargs):
try:
return get_module(**kwargs)
except NameError:
return NetworkModule(**kwargs)
def get_config(module, include_defaults=False):
config = module.params['config']
if not config:
try:
config = module.get_config()
except AttributeError:
defaults = module.params['include_defaults']
config = module.config.get_config(include_defaults=defaults)
return CustomNetworkConfig(indent=2, contents=config)
def load_config(module, candidate):
config = get_config(module)
commands = candidate.difference(config)
commands = [str(c).strip() for c in commands]
save_config = module.params['save']
result = dict(changed=False)
if commands:
if not module.check_mode:
try:
module.configure(commands)
except AttributeError:
module.config(commands)
if save_config:
try:
module.config.save_config()
except AttributeError:
module.execute(['copy running-config startup-config'])
result['changed'] = True
result['updates'] = commands
return result
# END OF COMMON CODE
def execute_config_command(commands, module):
try:
module.configure(commands)
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending CLI commands',
error=str(clie), commands=commands)
except AttributeError:
try:
commands.insert(0, 'configure')
module.cli.add_commands(commands, output='config')
module.cli.run_commands()
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending CLI commands',
error=str(clie), commands=commands)
def get_cli_body_ssh(command, response, module):
"""Get response for when transport=cli. This is kind of a hack and mainly
needed because these modules were originally written for NX-API. And
not every command supports "| json" when using cli/ssh. As such, we assume
if | json returns an XML string, it is a valid command, but that the
resource doesn't exist yet. Instead, the output will be a raw string
when issuing commands containing 'show run'.
"""
if 'xml' in response[0]:
body = []
elif 'show run' in command:
body = response
else:
try:
body = [json.loads(response[0])]
except ValueError:
module.fail_json(msg='Command does not support JSON output',
command=command)
return body
def execute_show(cmds, module, command_type=None):
command_type_map = {
'cli_show': 'json',
'cli_show_ascii': 'text'
}
try:
if command_type:
response = module.execute(cmds, command_type=command_type)
else:
response = module.execute(cmds)
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending {0}'.format(cmds),
error=str(clie))
except AttributeError:
try:
if command_type:
command_type = command_type_map.get(command_type)
module.cli.add_commands(cmds, output=command_type)
response = module.cli.run_commands()
else:
module.cli.add_commands(cmds, raw=True)
response = module.cli.run_commands()
except ShellError:
clie = get_exception()
module.fail_json(msg='Error sending {0}'.format(cmds),
error=str(clie))
return response
def execute_show_command(command, module, command_type='cli_show'):
if module.params['transport'] == 'cli':
if 'show run' not in command:
command += ' | json'
cmds = [command]
response = execute_show(cmds, module)
body = get_cli_body_ssh(command, response, module)
elif module.params['transport'] == 'nxapi':
cmds = [command]
body = execute_show(cmds, module, command_type=command_type)
return body
def apply_key_map(key_map, table):
new_dict = {}
for key, value in table.items():
new_key = key_map.get(key)
if new_key:
value = table.get(key)
if value:
new_dict[new_key] = str(value)
else:
new_dict[new_key] = value
return new_dict
def flatten_list(command_lists):
flat_command_list = []
for command in command_lists:
if isinstance(command, list):
flat_command_list.extend(command)
else:
flat_command_list.append(command)
return flat_command_list
def get_snmp_location(module):
location = {}
location_regex = '.*snmp-server\slocation\s(?P<location>\S+).*'
command = 'show run snmp'
body = execute_show_command(command, module, command_type='cli_show_ascii')
try:
match_location = re.match(location_regex, body[0], re.DOTALL)
group_location = match_location.groupdict()
location['location'] = group_location["location"]
except (AttributeError, TypeError):
location = {}
return location
def main():
argument_spec = dict(
location=dict(required=True, type='str'),
state=dict(choices=['absent', 'present'],
default='present')
)
module = get_network_module(argument_spec=argument_spec,
supports_check_mode=True)
location = module.params['location']
state = module.params['state']
existing = get_snmp_location(module)
changed = False
commands = []
proposed = dict(location=location)
end_state = existing
if state == 'absent':
if existing and existing['location'] == location:
commands.append('no snmp-server location')
elif state == 'present':
if not existing or existing['location'] != location:
commands.append('snmp-server location {0}'.format(location))
cmds = flatten_list(commands)
if cmds:
if module.check_mode:
module.exit_json(changed=True, commands=cmds)
else:
changed = True
execute_config_command(cmds, module)
end_state = get_snmp_location(module)
if 'configure' in cmds:
cmds.pop(0)
results = {}
results['proposed'] = proposed
results['existing'] = existing
results['end_state'] = end_state
results['updates'] = cmds
results['changed'] = changed
module.exit_json(**results)
from ansible.module_utils.basic import *
if __name__ == "__main__":
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
22072,
63,
15523,
63,
1985,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
3612,
63,
1802,
26,
21612,
26549,
2909,
2556,
14,
199,
1802,
26,
272,
446,
21612,
26549,
2909,
2897,
14,
199,
11036,
63,
9970,
63,
7677,
26,
22072,
199,
2502,
26,
272,
446,
1603,
2660,
662,
2264,
1237,
8593,
6532,
2264,
1237,
24,
9,
272,
446,
598,
371,
322,
8081,
22261,
1393,
79,
8593,
2916,
371,
322,
8081,
9,
199,
1419,
26,
272,
2909,
26,
267,
1369,
26,
288,
446,
12625,
2556,
14,
267,
1415,
26,
2549,
272,
1174,
26,
267,
1369,
26,
288,
446,
14944,
314,
1174,
402,
314,
2073,
14,
267,
1415,
26,
3055,
267,
849,
26,
3451,
267,
3415,
26,
788,
1881,
1673,
5575,
418,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
4868,
20143,
2909,
365,
7526,
199,
13,
22072,
63,
15523,
63,
1985,
26,
272,
2909,
26,
1379,
272,
1174,
26,
3451,
272,
1591,
26,
8448,
8200,
63,
4269,
3586,
272,
3434,
26,
8448,
625,
3586,
272,
2505,
26,
8448,
14374,
3586,
199,
199,
3,
4868,
20143,
2909,
365,
440,
7526,
199,
13,
22072,
63,
15523,
63,
1985,
26,
272,
2909,
26,
1379,
272,
1174,
26,
9552,
272,
1591,
26,
8448,
8200,
63,
4269,
3586,
272,
3434,
26,
8448,
625,
3586,
272,
2505,
26,
8448,
14374,
3586,
199,
2344,
199,
199,
9677,
275,
1449,
199,
15676,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
2633,
3032,
1901,
859,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
2420,
1985,
582,
298,
4665,
63,
774,
3570,
199,
5952,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
3411,
20143,
2909,
272,
730,
26,
1211,
272,
2690,
26,
2420,
1985,
582,
298,
774,
3570,
199,
500,
63,
929,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
2909,
2256,
2410,
859,
6451,
272,
2138,
26,
3544,
272,
730,
26,
1211,
503,
2973,
272,
2690,
26,
2420,
1985,
582,
298,
4665,
63,
774,
3570,
199,
7618,
26,
272,
1369,
26,
1414,
4847,
370,
314,
2243,
272,
2138,
26,
3544,
272,
730,
26,
769,
272,
2690,
26,
2097,
15523,
13,
1000,
2909,
7053,
63,
774,
937,
199,
2489,
26,
272,
1369,
26,
1104,
370,
1937,
340,
282,
1570,
1990,
6326,
641,
314,
2243,
272,
2138,
26,
3544,
272,
730,
26,
5046,
272,
2690,
26,
2549,
199,
2344,
199,
199,
646,
2022,
199,
199,
3,
11293,
615,
22547,
2381,
603,
1277,
23743,
199,
646,
295,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
664,
63,
1971,
199,
504,
3242,
14,
578,
63,
1208,
14,
846,
4128,
492,
7220,
2028,
12,
4094,
3049,
199,
504,
3242,
14,
578,
63,
1208,
14,
5641,
492,
24599,
547,
199,
199,
893,
26,
272,
687,
3242,
14,
578,
63,
1208,
14,
17982,
492,
664,
63,
578,
199,
2590,
3545,
26,
272,
687,
3242,
14,
578,
63,
1208,
14,
17982,
492,
7220,
2377,
421,
199,
318,
370,
63,
513,
8,
637,
304,
1362,
340,
1228,
8,
637,
12,
334,
513,
12,
2008,
2298,
268,
372,
769,
8,
637,
9,
1362,
916,
1139,
365,
440,
488,
26,
268,
372,
359,
637,
61,
1362,
587,
26,
268,
372,
769,
342,
421,
199,
533,
8388,
4491,
2028,
8,
4491,
2028,
304,
339,
347,
6544,
63,
2792,
8,
277,
12,
1101,
1113,
12,
428,
29,
403,
304,
267,
340,
428,
365,
488,
26,
288,
428,
275,
769,
342,
267,
428,
14,
740,
8,
888,
1113,
9,
267,
367,
1982,
315,
1101,
1113,
14,
3223,
26,
288,
340,
1982,
315,
428,
26,
355,
1980,
288,
291,
14,
4441,
63,
2792,
8,
1739,
12,
428,
9,
267,
372,
428,
339,
347,
664,
63,
785,
8,
277,
12,
931,
304,
267,
367,
1242,
315,
291,
14,
1744,
26,
288,
340,
1242,
14,
505,
508,
931,
1988,
17,
2189,
355,
8623,
275,
359,
80,
14,
505,
367,
299,
315,
1242,
14,
8859,
61,
355,
340,
8623,
508,
931,
4439,
17,
2189,
490,
372,
1242,
339,
347,
370,
63,
1457,
8,
277,
12,
3420,
304,
267,
372,
1557,
78,
1370,
904,
779,
1053,
14,
1773,
367,
1242,
315,
3420,
566,
339,
347,
664,
63,
2792,
8,
277,
12,
931,
304,
267,
862,
26,
288,
3420,
275,
291,
14,
362,
63,
2792,
63,
1462,
8,
515,
9,
288,
372,
291,
14,
475,
63,
1457,
8,
2792,
9,
267,
871,
1722,
26,
288,
372,
769,
342,
339,
347,
664,
63,
2792,
63,
1462,
8,
277,
12,
931,
304,
267,
340,
440,
1228,
8,
515,
12,
769,
304,
288,
931,
275,
359,
515,
61,
267,
1559,
275,
291,
14,
362,
63,
785,
8,
515,
9,
267,
340,
440,
1559,
26,
288,
746,
1722,
360,
515,
1630,
440,
2187,
315,
1101,
358,
267,
372,
291,
14,
4441,
63,
2792,
8,
1113,
9,
2378,
347,
1050,
8,
277,
12,
2385,
12,
8623,
29,
403,
304,
267,
408,
14995,
1373,
503,
2385,
402,
2897,
267,
408,
398,
20158,
275,
769,
342,
267,
3268,
275,
378,
267,
1559,
275,
488,
398,
925,
2288,
1101,
1414,
267,
340,
440,
8623,
26,
288,
367,
1004,
315,
370,
63,
513,
8,
1278,
304,
355,
1242,
275,
4094,
3049,
8,
604,
9
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
22072,
63,
15523,
63,
1985,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
3612,
63,
1802,
26,
21612,
26549,
2909,
2556,
14,
199,
1802,
26,
272,
446,
21612,
26549,
2909,
2897,
14,
199,
11036,
63,
9970,
63,
7677,
26,
22072,
199,
2502,
26,
272,
446,
1603,
2660,
662,
2264,
1237,
8593,
6532,
2264,
1237,
24,
9,
272,
446,
598,
371,
322,
8081,
22261,
1393,
79,
8593,
2916,
371,
322,
8081,
9,
199,
1419,
26,
272,
2909,
26,
267,
1369,
26,
288,
446,
12625,
2556,
14,
267,
1415,
26,
2549,
272,
1174,
26,
267,
1369,
26,
288,
446,
14944,
314,
1174,
402,
314,
2073,
14,
267,
1415,
26,
3055,
267,
849,
26,
3451,
267,
3415,
26,
788,
1881,
1673,
5575,
418,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
4868,
20143,
2909,
365,
7526,
199,
13,
22072,
63,
15523,
63,
1985,
26,
272,
2909,
26,
1379,
272,
1174,
26,
3451,
272,
1591,
26,
8448,
8200,
63,
4269,
3586,
272,
3434,
26,
8448,
625,
3586,
272,
2505,
26,
8448,
14374,
3586,
199,
199,
3,
4868,
20143,
2909,
365,
440,
7526,
199,
13,
22072,
63,
15523,
63,
1985,
26,
272,
2909,
26,
1379,
272,
1174,
26,
9552,
272,
1591,
26,
8448,
8200,
63,
4269,
3586,
272,
3434,
26,
8448,
625,
3586,
272,
2505,
26,
8448,
14374,
3586,
199,
2344,
199,
199,
9677,
275,
1449,
199,
15676,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
2633,
3032,
1901,
859,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
2420,
1985,
582,
298,
4665,
63,
774,
3570,
199,
5952,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
3411,
20143,
2909,
272,
730,
26,
1211,
272,
2690,
26,
2420,
1985,
582,
298,
774,
3570,
199,
500,
63,
929,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
2909,
2256,
2410,
859,
6451,
272,
2138,
26,
3544,
272,
730,
26,
1211,
503,
2973,
272,
2690,
26,
2420,
1985,
582,
298,
4665,
63,
774,
3570,
199,
7618,
26,
272,
1369,
26,
1414,
4847,
370,
314,
2243,
272,
2138,
26,
3544,
272,
730,
26,
769,
272,
2690,
26,
2097,
15523,
13,
1000,
2909,
7053,
63,
774,
937,
199,
2489,
26,
272,
1369,
26,
1104,
370,
1937,
340,
282,
1570,
1990,
6326,
641,
314,
2243,
272,
2138,
26,
3544,
272,
730,
26,
5046,
272,
2690,
26,
2549,
199,
2344,
199,
199,
646,
2022,
199,
199,
3,
11293,
615,
22547,
2381,
603,
1277,
23743,
199,
646,
295,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
664,
63,
1971,
199,
504,
3242,
14,
578,
63,
1208,
14,
846,
4128,
492,
7220,
2028,
12,
4094,
3049,
199,
504,
3242,
14,
578,
63,
1208,
14,
5641,
492,
24599,
547,
199,
199,
893,
26,
272,
687,
3242,
14,
578,
63,
1208,
14,
17982,
492,
664,
63,
578,
199,
2590,
3545,
26,
272,
687,
3242,
14,
578,
63,
1208,
14,
17982,
492,
7220,
2377,
421,
199,
318,
370,
63,
513,
8,
637,
304,
1362,
340,
1228,
8,
637,
12,
334,
513,
12,
2008,
2298,
268,
372,
769,
8,
637,
9,
1362,
916,
1139,
365,
440,
488,
26,
268,
372,
359,
637,
61,
1362,
587,
26,
268,
372,
769,
342,
421,
199,
533,
8388,
4491,
2028,
8,
4491,
2028,
304,
339,
347,
6544,
63,
2792,
8,
277,
12,
1101,
1113,
12,
428,
29,
403,
304,
267,
340,
428,
365,
488,
26,
288,
428,
275,
769,
342,
267,
428,
14,
740,
8,
888,
1113,
9,
267,
367,
1982,
315,
1101,
1113,
14,
3223,
26,
288,
340,
1982,
315,
428,
26,
355,
1980,
288,
291,
14,
4441,
63,
2792,
8,
1739,
12,
428,
9,
267,
372,
428,
339,
347,
664,
63,
785,
8,
277,
12,
931,
304,
267,
367,
1242,
315,
291,
14,
1744,
26,
288,
340,
1242,
14,
505,
508,
931,
1988,
17,
2189,
355,
8623,
275,
359,
80,
14,
505,
367,
299,
315,
1242,
14,
8859,
61,
355,
340,
8623,
508,
931,
4439,
17,
2189,
490,
372,
1242,
339,
347,
370,
63,
1457,
8,
277,
12,
3420,
304,
267,
372,
1557,
78,
1370,
904,
779,
1053,
14,
1773,
367,
1242,
315,
3420,
566,
339,
347,
664,
63,
2792,
8,
277,
12,
931,
304,
267,
862,
26,
288,
3420,
275,
291,
14,
362,
63,
2792,
63,
1462,
8,
515,
9,
288,
372,
291,
14,
475,
63,
1457,
8,
2792,
9,
267,
871,
1722,
26,
288,
372,
769,
342,
339,
347,
664,
63,
2792,
63,
1462,
8,
277,
12,
931,
304,
267,
340,
440,
1228,
8,
515,
12,
769,
304,
288,
931,
275,
359,
515,
61,
267,
1559,
275,
291,
14,
362,
63,
785,
8,
515,
9,
267,
340,
440,
1559,
26,
288,
746,
1722,
360,
515,
1630,
440,
2187,
315,
1101,
358,
267,
372,
291,
14,
4441,
63,
2792,
8,
1113,
9,
2378,
347,
1050,
8,
277,
12,
2385,
12,
8623,
29,
403,
304,
267,
408,
14995,
1373,
503,
2385,
402,
2897,
267,
408,
398,
20158,
275,
769,
342,
267,
3268,
275,
378,
267,
1559,
275,
488,
398,
925,
2288,
1101,
1414,
267,
340,
440,
8623,
26,
288,
367,
1004,
315,
370,
63,
513,
8,
1278,
304,
355,
1242,
275,
4094,
3049,
8,
604,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
lbishal/scikit-learn
|
examples/gaussian_process/plot_gpc_isoprobability.py
|
45
|
3025
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
=================================================================
Iso-probability lines for Gaussian Processes classification (GPC)
=================================================================
A two-dimensional classification example showing iso-probability lines for
the predicted probabilities.
"""
print(__doc__)
# Author: Vincent Dubourg <vincent.dubourg@gmail.com>
# Adapted to GaussianProcessClassifier:
# Jan Hendrik Metzen <jhm@informatik.uni-bremen.de>
# Licence: BSD 3 clause
import numpy as np
from matplotlib import pyplot as pl
from matplotlib import cm
from sklearn.gaussian_process import GaussianProcessClassifier
from sklearn.gaussian_process.kernels import DotProduct, ConstantKernel as C
# A few constants
lim = 8
def g(x):
"""The function to predict (classification will then consist in predicting
whether g(x) <= 0 or not)"""
return 5. - x[:, 1] - .5 * x[:, 0] ** 2.
# Design of experiments
X = np.array([[-4.61611719, -6.00099547],
[4.10469096, 5.32782448],
[0.00000000, -0.50000000],
[-6.17289014, -4.6984743],
[1.3109306, -6.93271427],
[-5.03823144, 3.10584743],
[-2.87600388, 6.74310541],
[5.21301203, 4.26386883]])
# Observations
y = np.array(g(X) > 0, dtype=int)
# Instanciate and fit Gaussian Process Model
kernel = C(0.1, (1e-5, np.inf)) * DotProduct(sigma_0=0.1) ** 2
gp = GaussianProcessClassifier(kernel=kernel)
gp.fit(X, y)
print("Learned kernel: %s " % gp.kernel_)
# Evaluate real function and the predicted probability
res = 50
x1, x2 = np.meshgrid(np.linspace(- lim, lim, res),
np.linspace(- lim, lim, res))
xx = np.vstack([x1.reshape(x1.size), x2.reshape(x2.size)]).T
y_true = g(xx)
y_prob = gp.predict_proba(xx)[:, 1]
y_true = y_true.reshape((res, res))
y_prob = y_prob.reshape((res, res))
# Plot the probabilistic classification iso-values
fig = pl.figure(1)
ax = fig.gca()
ax.axes.set_aspect('equal')
pl.xticks([])
pl.yticks([])
ax.set_xticklabels([])
ax.set_yticklabels([])
pl.xlabel('$x_1$')
pl.ylabel('$x_2$')
cax = pl.imshow(y_prob, cmap=cm.gray_r, alpha=0.8,
extent=(-lim, lim, -lim, lim))
norm = pl.matplotlib.colors.Normalize(vmin=0., vmax=0.9)
cb = pl.colorbar(cax, ticks=[0., 0.2, 0.4, 0.6, 0.8, 1.], norm=norm)
cb.set_label('${\\rm \mathbb{P}}\left[\widehat{G}(\mathbf{x}) \leq 0\\right]$')
pl.clim(0, 1)
pl.plot(X[y <= 0, 0], X[y <= 0, 1], 'r.', markersize=12)
pl.plot(X[y > 0, 0], X[y > 0, 1], 'b.', markersize=12)
cs = pl.contour(x1, x2, y_true, [0.], colors='k', linestyles='dashdot')
cs = pl.contour(x1, x2, y_prob, [0.666], colors='b',
linestyles='solid')
pl.clabel(cs, fontsize=11)
cs = pl.contour(x1, x2, y_prob, [0.5], colors='k',
linestyles='dashed')
pl.clabel(cs, fontsize=11)
cs = pl.contour(x1, x2, y_prob, [0.334], colors='r',
linestyles='solid')
pl.clabel(cs, fontsize=11)
pl.show()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
5695,
29,
199,
41,
1152,
13,
17210,
2385,
367,
17131,
2165,
5804,
12505,
334,
39,
4222,
9,
199,
5695,
29,
199,
199,
33,
2877,
13,
13014,
12505,
2893,
21207,
11601,
13,
17210,
2385,
367,
199,
1589,
14746,
19555,
14,
199,
624,
199,
1361,
3460,
1301,
3368,
199,
199,
3,
6529,
26,
28882,
2946,
577,
456,
567,
71,
665,
11908,
2946,
14,
68,
456,
567,
71,
32,
6799,
14,
957,
30,
199,
3,
4431,
18309,
370,
17131,
3498,
8508,
26,
199,
3,
260,
17474,
869,
500,
25844,
10072,
5193,
665,
74,
14038,
32,
262,
10928,
30298,
14,
5411,
13,
10205,
1410,
14,
271,
30,
199,
3,
491,
530,
4894,
26,
6289,
650,
8502,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
8027,
492,
1134,
2798,
465,
1620,
199,
504,
8027,
492,
6904,
199,
199,
504,
6357,
14,
22911,
63,
1412,
492,
17131,
3498,
8508,
199,
504,
6357,
14,
22911,
63,
1412,
14,
29824,
492,
24716,
5884,
12,
19991,
14127,
465,
445,
199,
199,
3,
437,
9284,
5262,
199,
4175,
275,
1695,
421,
199,
318,
486,
8,
88,
304,
272,
408,
1918,
805,
370,
12610,
334,
14368,
911,
2066,
17568,
315,
12610,
316,
272,
3775,
486,
8,
88,
9,
2695,
378,
503,
440,
9471,
272,
372,
959,
14,
446,
671,
3981,
413,
61,
446,
1275,
21,
627,
671,
3981,
378,
61,
1011,
499,
14,
199,
199,
3,
29410,
402,
444,
22263,
199,
56,
275,
980,
14,
1144,
22844,
20,
14,
26666,
7362,
1167,
12,
446,
22,
14,
1493,
1020,
16710,
467,
1598,
359,
20,
14,
6785,
1876,
9211,
12,
959,
14,
708,
2277,
1194,
2006,
467,
1598,
359,
16,
14,
3607,
12,
446,
16,
14,
21,
9084,
467,
1598,
5243,
22,
14,
10419,
1407,
10752,
12,
446,
20,
14,
1876,
1349,
21712,
467,
1598,
359,
17,
14,
19,
6996,
11363,
12,
446,
22,
14,
25,
11754,
1079,
1465,
467,
1598,
5243,
21,
14,
14273,
1789,
9862,
12,
650,
14,
7320,
1349,
21712,
467,
1598,
5243,
18,
14,
1555,
6683,
11403,
12,
1227,
14,
1342,
18035,
21278,
467,
1598,
359,
21,
14,
18,
10067,
11341,
12,
841,
14,
1479,
8040,
16456,
3934,
199,
199,
3,
17985,
12225,
199,
89,
275,
980,
14,
1144,
8,
71,
8,
56,
9,
690,
378,
12,
2152,
29,
442,
9,
199,
199,
3,
1010,
9746,
559,
323,
436,
5542,
17131,
7132,
5822,
199,
4989,
275,
445,
8,
16,
14,
17,
12,
334,
17,
69,
13,
21,
12,
980,
14,
4904,
430,
627,
24716,
5884,
8,
9412,
63,
16,
29,
16,
14,
17,
9,
1011,
499,
199,
4927,
275,
17131,
3498,
8508,
8,
4989,
29,
4989,
9,
199,
4927,
14,
3269,
8,
56,
12,
612,
9,
199,
1361,
480,
21424,
379,
5114,
26,
450,
83,
298,
450,
15852,
14,
4989,
4602,
199,
199,
3,
27450,
3363,
805,
436,
314,
14746,
12224,
199,
470,
275,
5238,
199,
88,
17,
12,
671,
18,
275,
980,
14,
6480,
3825,
8,
1590,
14,
11649,
2801,
1212,
77,
12,
1212,
77,
12,
522,
395,
2151,
980,
14,
11649,
2801,
1212,
77,
12,
1212,
77,
12,
522,
430,
199,
2154,
275,
980,
14,
20221,
779,
88,
17,
14,
5217,
8,
88,
17,
14,
890,
395,
671,
18,
14,
5217,
8,
88,
18,
14,
890,
3948,
14,
52,
199,
199,
89,
63,
2052,
275,
486,
8,
2154,
9,
199,
89,
63,
6101,
275,
15852,
14,
6892,
63,
14417,
8,
2154,
24517,
413,
61,
199,
89,
63,
2052,
275,
612,
63,
2052,
14,
5217,
1332,
470,
12,
522,
430,
199,
89,
63,
6101,
275,
612,
63,
6101,
14,
5217,
1332,
470,
12,
522,
430,
199,
199,
3,
14794,
314,
5128,
14677,
513,
530,
12505,
11601,
13,
1459,
199,
592,
275,
1620,
14,
8941,
8,
17,
9,
199,
1219,
275,
6085,
14,
71,
696,
342,
199,
1219,
14,
6402,
14,
409,
63,
18658,
360,
1452,
358,
199,
1168,
14,
26217,
4157,
199,
1168,
14,
30588,
4157,
199,
1219,
14,
409,
63,
88,
27435,
4157,
199,
1219,
14,
409,
63,
89,
27435,
4157,
199,
1168,
14,
14168,
14676,
88,
63,
17,
9988,
199,
1168,
14,
13849,
14676,
88,
63,
18,
9988,
199,
199,
696,
88,
275,
1620,
14,
20413,
8,
89,
63,
6101,
12,
14920,
29,
4400,
14,
12150,
63,
82,
12,
5131,
29,
16,
14,
24,
12,
355,
13675,
26154,
4175,
12,
1212,
77,
12,
446,
4175,
12,
1212,
77,
430,
199,
4791,
275,
1620,
14,
16440,
14,
7120,
14,
22580,
8,
28895,
29,
16,
2020,
23349,
29,
16,
14,
25,
9,
199,
2894,
275,
1620,
14,
30995,
8,
696,
88,
12,
17779,
1524,
16,
2020,
378,
14,
18,
12,
378,
14,
20,
12,
378,
14,
22,
12,
378,
14,
24,
12,
413,
8333,
6316,
29,
4791,
9,
199,
2894,
14,
409,
63,
1302,
360,
10545,
1103,
5682,
971,
3442,
2501,
91,
48,
4863,
60,
3039,
7023,
13062,
8554,
91,
39,
93,
2961,
30286,
91,
88,
1552,
971,
274,
81,
378,
1103,
1019,
61,
9988,
199,
1168,
14,
2764,
77,
8,
16,
12,
413,
9,
199,
199,
1168,
14,
2798,
8,
56,
59,
89,
2695,
378,
12,
378,
467,
1323,
59,
89,
2695,
378,
12,
413,
467,
283,
82,
3130,
3608,
890,
29,
713,
9,
199,
199,
1168,
14,
2798,
8,
56,
59,
89,
690,
378,
12,
378,
467,
1323,
59,
89,
690,
378,
12,
413,
467,
283,
66,
3130,
3608,
890,
29,
713,
9,
199,
199,
1259,
275,
1620,
14,
17798,
8,
88,
17,
12,
671,
18,
12,
612,
63,
2052,
12,
359,
16,
8333,
9229,
534,
75,
297,
27880,
83,
534,
6760,
3287,
358,
199,
199,
1259,
275,
1620,
14,
17798,
8,
88,
17,
12,
671,
18,
12,
612,
63,
6101,
12,
359,
16,
14,
11829,
467,
9229,
534,
66,
297,
355,
27880,
83,
534,
18533,
358,
199,
1168,
14,
429,
902,
8,
1259,
12,
19740,
29,
845,
9,
199,
199,
1259,
275,
1620,
14,
17798,
8,
88,
17,
12,
671,
18,
12,
612,
63,
6101,
12,
359,
16,
14,
21,
467,
9229,
534,
75,
297,
355,
27880,
83,
534,
6760,
379,
358,
199,
1168,
14,
429,
902,
8,
1259,
12,
19740,
29,
845,
9,
199,
199,
1259,
275,
1620
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
5695,
29,
199,
41,
1152,
13,
17210,
2385,
367,
17131,
2165,
5804,
12505,
334,
39,
4222,
9,
199,
5695,
29,
199,
199,
33,
2877,
13,
13014,
12505,
2893,
21207,
11601,
13,
17210,
2385,
367,
199,
1589,
14746,
19555,
14,
199,
624,
199,
1361,
3460,
1301,
3368,
199,
199,
3,
6529,
26,
28882,
2946,
577,
456,
567,
71,
665,
11908,
2946,
14,
68,
456,
567,
71,
32,
6799,
14,
957,
30,
199,
3,
4431,
18309,
370,
17131,
3498,
8508,
26,
199,
3,
260,
17474,
869,
500,
25844,
10072,
5193,
665,
74,
14038,
32,
262,
10928,
30298,
14,
5411,
13,
10205,
1410,
14,
271,
30,
199,
3,
491,
530,
4894,
26,
6289,
650,
8502,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
8027,
492,
1134,
2798,
465,
1620,
199,
504,
8027,
492,
6904,
199,
199,
504,
6357,
14,
22911,
63,
1412,
492,
17131,
3498,
8508,
199,
504,
6357,
14,
22911,
63,
1412,
14,
29824,
492,
24716,
5884,
12,
19991,
14127,
465,
445,
199,
199,
3,
437,
9284,
5262,
199,
4175,
275,
1695,
421,
199,
318,
486,
8,
88,
304,
272,
408,
1918,
805,
370,
12610,
334,
14368,
911,
2066,
17568,
315,
12610,
316,
272,
3775,
486,
8,
88,
9,
2695,
378,
503,
440,
9471,
272,
372,
959,
14,
446,
671,
3981,
413,
61,
446,
1275,
21,
627,
671,
3981,
378,
61,
1011,
499,
14,
199,
199,
3,
29410,
402,
444,
22263,
199,
56,
275,
980,
14,
1144,
22844,
20,
14,
26666,
7362,
1167,
12,
446,
22,
14,
1493,
1020,
16710,
467,
1598,
359,
20,
14,
6785,
1876,
9211,
12,
959,
14,
708,
2277,
1194,
2006,
467,
1598,
359,
16,
14,
3607,
12,
446,
16,
14,
21,
9084,
467,
1598,
5243,
22,
14,
10419,
1407,
10752,
12,
446,
20,
14,
1876,
1349,
21712,
467,
1598,
359,
17,
14,
19,
6996,
11363,
12,
446,
22,
14,
25,
11754,
1079,
1465,
467,
1598,
5243,
21,
14,
14273,
1789,
9862,
12,
650,
14,
7320,
1349,
21712,
467,
1598,
5243,
18,
14,
1555,
6683,
11403,
12,
1227,
14,
1342,
18035,
21278,
467,
1598,
359,
21,
14,
18,
10067,
11341,
12,
841,
14,
1479,
8040,
16456,
3934,
199,
199,
3,
17985,
12225,
199,
89,
275,
980,
14,
1144,
8,
71,
8,
56,
9,
690,
378,
12,
2152,
29,
442,
9,
199,
199,
3,
1010,
9746,
559,
323,
436,
5542,
17131,
7132,
5822,
199,
4989,
275,
445,
8,
16,
14,
17,
12,
334,
17,
69,
13,
21,
12,
980,
14,
4904,
430,
627,
24716,
5884,
8,
9412,
63,
16,
29,
16,
14,
17,
9,
1011,
499,
199,
4927,
275,
17131,
3498,
8508,
8,
4989,
29,
4989,
9,
199,
4927,
14,
3269,
8,
56,
12,
612,
9,
199,
1361,
480,
21424,
379,
5114,
26,
450,
83,
298,
450,
15852,
14,
4989,
4602,
199,
199,
3,
27450,
3363,
805,
436,
314,
14746,
12224,
199,
470,
275,
5238,
199,
88,
17,
12,
671,
18,
275,
980,
14,
6480,
3825,
8,
1590,
14,
11649,
2801,
1212,
77,
12,
1212,
77,
12,
522,
395,
2151,
980,
14,
11649,
2801,
1212,
77,
12,
1212,
77,
12,
522,
430,
199,
2154,
275,
980,
14,
20221,
779,
88,
17,
14,
5217,
8,
88,
17,
14,
890,
395,
671,
18,
14,
5217,
8,
88,
18,
14,
890,
3948,
14,
52,
199,
199,
89,
63,
2052,
275,
486,
8,
2154,
9,
199,
89,
63,
6101,
275,
15852,
14,
6892,
63,
14417,
8,
2154,
24517,
413,
61,
199,
89,
63,
2052,
275,
612,
63,
2052,
14,
5217,
1332,
470,
12,
522,
430,
199,
89,
63,
6101,
275,
612,
63,
6101,
14,
5217,
1332,
470,
12,
522,
430,
199,
199,
3,
14794,
314,
5128,
14677,
513,
530,
12505,
11601,
13,
1459,
199,
592,
275,
1620,
14,
8941,
8,
17,
9,
199,
1219,
275,
6085,
14,
71,
696,
342,
199,
1219,
14,
6402,
14,
409,
63,
18658,
360,
1452,
358,
199,
1168,
14,
26217,
4157,
199,
1168,
14,
30588,
4157,
199,
1219,
14,
409,
63,
88,
27435,
4157,
199,
1219,
14,
409,
63,
89,
27435,
4157,
199,
1168,
14,
14168,
14676,
88,
63,
17,
9988,
199,
1168,
14,
13849,
14676,
88,
63,
18,
9988,
199,
199,
696,
88,
275,
1620,
14,
20413,
8,
89,
63,
6101,
12,
14920,
29,
4400,
14,
12150,
63,
82,
12,
5131,
29,
16,
14,
24,
12,
355,
13675,
26154,
4175,
12,
1212,
77,
12,
446,
4175,
12,
1212,
77,
430,
199,
4791,
275,
1620,
14,
16440,
14,
7120,
14,
22580,
8,
28895,
29,
16,
2020,
23349,
29,
16,
14,
25,
9,
199,
2894,
275,
1620,
14,
30995,
8,
696,
88,
12,
17779,
1524,
16,
2020,
378,
14,
18,
12,
378,
14,
20,
12,
378,
14,
22,
12,
378,
14,
24,
12,
413,
8333,
6316,
29,
4791,
9,
199,
2894,
14,
409,
63,
1302,
360,
10545,
1103,
5682,
971,
3442,
2501,
91,
48,
4863,
60,
3039,
7023,
13062,
8554,
91,
39,
93,
2961,
30286,
91,
88,
1552,
971,
274,
81,
378,
1103,
1019,
61,
9988,
199,
1168,
14,
2764,
77,
8,
16,
12,
413,
9,
199,
199,
1168,
14,
2798,
8,
56,
59,
89,
2695,
378,
12,
378,
467,
1323,
59,
89,
2695,
378,
12,
413,
467,
283,
82,
3130,
3608,
890,
29,
713,
9,
199,
199,
1168,
14,
2798,
8,
56,
59,
89,
690,
378,
12,
378,
467,
1323,
59,
89,
690,
378,
12,
413,
467,
283,
66,
3130,
3608,
890,
29,
713,
9,
199,
199,
1259,
275,
1620,
14,
17798,
8,
88,
17,
12,
671,
18,
12,
612,
63,
2052,
12,
359,
16,
8333,
9229,
534,
75,
297,
27880,
83,
534,
6760,
3287,
358,
199,
199,
1259,
275,
1620,
14,
17798,
8,
88,
17,
12,
671,
18,
12,
612,
63,
6101,
12,
359,
16,
14,
11829,
467,
9229,
534,
66,
297,
355,
27880,
83,
534,
18533,
358,
199,
1168,
14,
429,
902,
8,
1259,
12,
19740,
29,
845,
9,
199,
199,
1259,
275,
1620,
14,
17798,
8,
88,
17,
12,
671,
18,
12,
612,
63,
6101,
12,
359,
16,
14,
21,
467,
9229,
534,
75,
297,
355,
27880,
83,
534,
6760,
379,
358,
199,
1168,
14,
429,
902,
8,
1259,
12,
19740,
29,
845,
9,
199,
199,
1259,
275,
1620,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Thermi/ocfs2-tools
|
ocfs2console/ocfs2interface/classlabel.py
|
8
|
1201
|
# OCFS2Console - GUI frontend for OCFS2 management and debugging
# Copyright (C) 2005 Oracle. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.
import re
caps = re.compile('(?!\A)[A-Z][a-z]')
def make_title(m):
return ' ' + m.group()
class class_label(object):
def __get__(self, obj, cls):
return caps.sub(make_title, cls.__name__)
class_label = class_label()
def main():
import sys
cls = type(sys.argv[1], (), {'label': class_label})
print cls.label
if __name__ == '__main__':
main()
|
gpl-2.0
|
[
3,
593,
5487,
51,
18,
9270,
446,
17160,
22523,
367,
593,
5487,
51,
18,
10041,
436,
10201,
199,
3,
1898,
334,
35,
9,
11811,
15309,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
446,
14453,
13540,
12,
8226,
12,
4828,
12497,
845,
709,
13,
13421,
12,
8217,
14,
199,
199,
646,
295,
199,
199,
12029,
275,
295,
14,
2014,
28353,
12525,
33,
2788,
33,
13,
58,
1527,
65,
13,
90,
10374,
199,
199,
318,
1852,
63,
1213,
8,
77,
304,
272,
372,
283,
283,
435,
333,
14,
923,
342,
199,
199,
533,
1021,
63,
1302,
8,
785,
304,
272,
347,
636,
362,
721,
277,
12,
1559,
12,
843,
304,
267,
372,
22053,
14,
954,
8,
1875,
63,
1213,
12,
843,
855,
354,
3368,
199,
199,
533,
63,
1302,
275,
1021,
63,
1302,
342,
199,
199,
318,
2446,
837,
272,
492,
984,
339,
843,
275,
730,
8,
1274,
14,
3020,
59,
17,
467,
11969,
791,
1302,
356,
1021,
63,
1302,
1552,
272,
870,
843,
14,
1302,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
593,
5487,
51,
18,
9270,
446,
17160,
22523,
367,
593,
5487,
51,
18,
10041,
436,
10201,
199,
3,
1898,
334,
35,
9,
11811,
15309,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
446,
14453,
13540,
12,
8226,
12,
4828,
12497,
845,
709,
13,
13421,
12,
8217,
14,
199,
199,
646,
295,
199,
199,
12029,
275,
295,
14,
2014,
28353,
12525,
33,
2788,
33,
13,
58,
1527,
65,
13,
90,
10374,
199,
199,
318,
1852,
63,
1213,
8,
77,
304,
272,
372,
283,
283,
435,
333,
14,
923,
342,
199,
199,
533,
1021,
63,
1302,
8,
785,
304,
272,
347,
636,
362,
721,
277,
12,
1559,
12,
843,
304,
267,
372,
22053,
14,
954,
8,
1875,
63,
1213,
12,
843,
855,
354,
3368,
199,
199,
533,
63,
1302,
275,
1021,
63,
1302,
342,
199,
199,
318,
2446,
837,
272,
492,
984,
339,
843,
275,
730,
8,
1274,
14,
3020,
59,
17,
467,
11969,
791,
1302,
356,
1021,
63,
1302,
1552,
272,
870,
843,
14,
1302,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
TUB-Control/PaPI
|
papi/plugin/io/UDP_Plugin/UDP_Plugin.py
|
1
|
26844
|
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Copyright (C) 2014 Technische Universität Berlin,
Fakultät IV - Elektrotechnik und Informatik,
Fachgebiet Regelungssysteme,
Einsteinufer 17, D-10587 Berlin, Germany
This file is part of PaPI.
PaPI 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.b
PaPI 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 PaPI. If not, see <http://www.gnu.org/licenses/>.
Contributors
Christian Klauer
Stefan Ruppin
"""
from papi.plugin.base_classes.iop_base import iop_base
from papi.data.DPlugin import DBlock
from papi.data.DSignal import DSignal
from papi.data.DParameter import DParameter
import numpy as np
import threading
import os
import sys
import socket
import ast
import struct
import json
import time
import pickle
import base64
from threading import Timer
from socketIO_client import SocketIO, LoggingNamespace
class OptionalObject(object):
def __init__(self, ORTD_par_id, nvalues):
self.ORTD_par_id = ORTD_par_id
self.nvalues = nvalues
self.sendOnReceivePort = True
self.UseSocketIO = True
class UDP_Plugin(iop_base):
def cb_get_plugin_configuration(self):
config = {
'address': {
'value': '127.0.0.1',
'advanced': 'Connection',
'tooltip': 'IP address of the source',
'display_text': 'Target IP address'
},
'source_port': {
'value': '20000',
'advanced': 'Connection',
'tooltip': 'Port of incoming data',
'display_text': 'Source Port'
},
'out_port': {
'value': '20001',
'advanced': 'Connection',
'tooltip': 'Port for outgoing data',
'display_text': 'Send Port'
},
'SeparateSignals': {
'value': '0',
'advanced': 'General',
'tooltip': 'Split up signal vectors to separate signals',
'display_text': 'Separate Signals'
},
'SendOnReceivePort': {
'value': '0',
'advanced': 'Connection',
'display_text': 'Same port for send and receive',
'tooltip': 'Use the source port to send data back to the target'
},
"UseSocketIO" : {
'value' : '0',
'advanced' : 'SocketIO',
'tooltip' : 'Use socket.io connection to node.js target-server',
'display_text': 'Use SocketIO',
'type' : 'bool'
},
'socketio_port': {
'value': '8091',
'advanced': 'SocketIO',
'tooltip': 'Port for the SocketIO Connection',
'display_text': 'SocketIO Port'
},
"OnlyInitialConfig" : {
'value' :'0',
'tooltip' : 'Use only first configuration, ignore further configurations.',
'type' : 'bool',
'advanced': 'General'
}
}
return config
def cb_initialize_plugin(self):
print('ORTD', self.__id__, ':process id', os.getpid())
self.config = self.pl_get_current_config_ref()
# open UDP
self.HOST = self.config['address']['value']
self.SOURCE_PORT = int(self.config['source_port']['value'])
self.OUT_PORT = int(self.config['out_port']['value'])
self.LOCALBIND_HOST = '' # config['source_address']['value'] #CK
self.sendOnReceivePort = True if self.config['SendOnReceivePort']['value'] == '1' else False
self.UseSocketIO = True if self.config['UseSocketIO']['value'] == '1' else False
if self.UseSocketIO:
self.SocketIOPort = int(self.config['socketio_port']['value'])
#self.sendOnReceivePort = True # NOTE: remove this
#self.UseSocketIO = True # NOTE: remove this
print ("SendOnReceivePort = ", self.sendOnReceivePort)
print ("UseSocketIO = ", self.UseSocketIO)
self.PAPI_SIMULINK_BLOCK = False
self.separate = int(self.config['SeparateSignals']['value'])
self.onlyInitialConfig = self.config['OnlyInitialConfig']['value'] == '1'
self.hasInitialConfig = False
if (not self.sendOnReceivePort):
# SOCK_DGRAM is the socket type to use for UDP sockets
self.sock_parameter = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.sock_parameter.setblocking(1)
self.ControlBlock = DBlock('ControllerSignals')
self.ControlBlock.add_signal(DSignal('ControlSignalReset'))
self.ControlBlock.add_signal(DSignal('ControlSignalCreate'))
self.ControlBlock.add_signal(DSignal('ControlSignalSub'))
self.ControlBlock.add_signal(DSignal('ControllerSignalParameter'))
self.ControlBlock.add_signal(DSignal('ControllerSignalClose'))
self.ControlBlock.add_signal(DSignal('ActiveTab'))
self.pl_send_new_block_list([self.ControlBlock])
self.t = 0
self.pl_set_event_trigger_mode(True)
if not self.UseSocketIO:
self.sock_recv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
if (not self.sendOnReceivePort):
try:
self.sock_recv.bind((self.LOCALBIND_HOST, self.SOURCE_PORT)) # CK
print("UDP_Plugin-plugin listening on: ", self.LOCALBIND_HOST, ":", self.SOURCE_PORT) #CK
except socket.error as msg:
sys.stderr.write("[ERROR] Can't start UDP_Plugin due to %s\n" % msg)
return False
else:
print ("---- Using client UDP mode (not binding to a port) ----")
self.sock_recv.settimeout(1)
self.thread_goOn = True
self.lock = threading.Lock()
self.thread = threading.Thread(target=self.thread_execute)
self.thread.start()
if self.UseSocketIO:
print ("Using socket.io connection on port", self.SocketIOPort)
self.thread_socket_goOn = True
self.thread_socketio = threading.Thread(target=self.thread_socketio_execute)
self.blocks = {}
self.Sources = {}
self.parameters = {}
self.signal_values = {}
self.block_id = 0
self.config_complete = False
self.config_buffer = {}
self.timer = Timer(3,self.callback_timeout_timer)
self.timer_active = False
self.ConsoleBlock = DBlock('ConsoleSignals')
self.ConsoleBlock.add_signal(DSignal('MainSignal'))
self.pl_send_new_block_list([self.ConsoleBlock])
self.consoleIn = DParameter('consoleIn',default='')
self.pl_send_new_parameter_list([self.consoleIn])
if self.UseSocketIO:
self.thread_socketio.start()
return True
def SIO_callback_SCISTOUT(self, data):
# Got a chunk of data from a console interface in the target server
self.sio_count += 1
self.pl_send_new_data(self.ConsoleBlock.name, [self.sio_count], {'MainSignal':data['Data']})
def SIO_callback_PAPICONFIG(self, data):
# Got a new PaPI plugin configuration in JSON-format via socket.io connection
# currently the config is transmitted via ORTD packets that may also be encapsulated into socket.io
# added 12.8.15, CK
print ("Got a new config in JSON/socket.io format")
print (data)
self.check_and_process_cfg(data)
# TODO: Test this
def SIO_callback_ORTDPACKET(self, data):
# Got an encapsulated packet from ORTD, not transfered via UDP but encapsulated within the socket.io connection
#print ("Got data packet from ORTD via socket.io")
#print (data)
self.process_received_package(base64.b64decode(data)) # data must be a binary blob
def thread_socketio_execute(self):
#self.sio = SocketIO('localhost', 8091, LoggingNamespace)
#self.sio.on('SCISTOUT',self.callback_SCISTOUT)
while True:
try:
with SocketIO(self.HOST, self.SocketIOPort, LoggingNamespace) as self.sio:
self.sio.on('SCISTOUT',self.SIO_callback_SCISTOUT)
self.sio.on('PAPICONFIG',self.SIO_callback_PAPICONFIG)
self.sio.on('ORTDPACKET',self.SIO_callback_ORTDPACKET)
self.request_new_config_from_ORTD()
self.sio_count = 0
while self.thread_socket_goOn:
self.sio.wait(seconds=1)
except:
print("Something failed within socket.io")
def cb_pause(self):
self.lock.acquire()
self.thread_goOn = False
self.lock.release()
self.thread.join()
def cb_resume(self):
self.thread_goOn = True
self.thread = threading.Thread(target=self.thread_execute, args=(self.HOST, self.SOURCE_PORT))
self.thread.start()
def thread_execute(self):
time.sleep(2) # TODO: Grrr. do not use sleep for thread sync...
#try:
if not self.UseSocketIO:
self.request_new_config_from_ORTD()
goOn = True
newData = False
signal_values = {}
while goOn:
try:
if not self.sendOnReceivePort:
rev = self.sock_recv.recv(65507) # not feasible for network connection other than loopback
else:
#print ("---- Waiting for data ----")
rev, server = self.sock_recv.recvfrom(65507) # not feasible for network connection other than loopback
#print ("---- got ----")
#print (rev)
except socket.timeout:
# print('timeout')
newData = False
except socket.error:
print('ORTD got socket error')
else:
newData = True
if newData:
self.process_received_package(rev)
# check if thread should go on
self.lock.acquire()
goOn = self.thread_goOn
self.lock.release()
# Thread ended
self.sock_recv.close()
def process_received_package(self, rev):
SenderId, Counter, SourceId = struct.unpack_from('<iii', rev)
if SourceId == -1 and len(self.blocks) > 0:
# data stream finished
self.process_finished_action(SourceId, rev)
self.signal_values = {}
if SourceId >= 0 and len(self.blocks) > 0:
# got data stream
self.process_data_stream(SourceId, rev)
if SourceId == -2:
# new config in ORTD available
# send trigger to get new config
self.request_new_config_from_ORTD()
self.config_complete = False
self.config_buffer = {}
if SourceId == -100:
self.PAPI_SIMULINK_BLOCK = True
# got data stream from the PaPI-Simulink Block
self.process_papi_data_stream(rev)
if SourceId == -4:
self.PAPI_SIMULINK_BLOCK = False
# new configItem
# print("Part of a new configuration");
# receive new config item and execute cfg in PaPI
# unpack package
i = 16 # Offset: 4 ints
unp = ''
while i < len(rev):
unp = unp + str(struct.unpack_from('<s',rev,i)[0])[2]
i += 1
if int(Counter) not in self.config_buffer:
self.config_buffer[int(Counter)] = unp
else:
if self.config_buffer[int(Counter)] != unp:
self.config_buffer = {}
# Check counter key series for holes
counters = list(self.config_buffer.keys())
counters.sort()
i = 1
config_file = ''
self.config_complete = True
for c in counters:
if i == c:
config_file += self.config_buffer[c]
i += 1
else:
self.config_complete = False
break
if self.config_complete:
if not self.check_and_process_cfg(config_file):
self.start_timeout_timer()
else:
self.stop_timeout_timer()
else:
self.start_timeout_timer()
def start_timeout_timer(self):
if not self.timer_active:
self.timer = Timer(3,self.callback_timeout_timer)
self.timer.start()
self.timer_active = True
else:
self.timer.cancel()
self.timer = Timer(3,self.callback_timeout_timer)
self.timer.start()
def stop_timeout_timer(self):
if self.timer_active:
self.timer.cancel()
self.timer_active = False
#self.config_buffer = {}
def callback_timeout_timer(self):
print('ORTD_PLUGIN: Config timeout, requesting a new config')
self.timer_active = False
self.config_buffer = {}
self.request_new_config_from_ORTD()
def request_new_config_from_ORTD(self):
Counter = 1
data = struct.pack('<iiid', 12, Counter, int(-3), float(0))
if self.UseSocketIO:
print ("Requesting config via socket.io")
self.sio.emit('ORTDPACKET', base64.b64encode(data).decode('ascii') )
# TODO test this
else:
if not self.sendOnReceivePort:
self.sock_parameter.sendto(data, (self.HOST, self.OUT_PORT))
else:
self.sock_recv.sendto(data, (self.HOST, self.SOURCE_PORT))
def check_and_process_cfg(self, config_file):
try:
# config completely received
# extract new configuration
cfg = json.loads(config_file)
ORTDSources, ORTDParameters, plToCreate, \
plToClose, subscriptions, paraConnections, activeTab = self.extract_config_elements(cfg)
if self.hasInitialConfig and self.onlyInitialConfig:
return True
self.hasInitialConfig = True
self.update_block_list(ORTDSources)
self.update_parameter_list(ORTDParameters)
self.process_papi_configuration(plToCreate, plToClose, subscriptions, paraConnections, activeTab)
return True
except ValueError as e:
return False
def process_papi_configuration(self, toCreate, toClose, subs, paraConnections, activeTab):
self.pl_send_new_data('ControllerSignals', [1], {'ControlSignalReset': 1,
'ControlSignalCreate':None,
'ControlSignalSub':None,
'ControllerSignalParameter':None,
'ControllerSignalClose':None,
'ActiveTab': None })
self.pl_send_new_data('ControllerSignals', [1], {'ControlSignalReset':0,
'ControlSignalCreate':toCreate,
'ControlSignalSub':subs,
'ControllerSignalParameter':paraConnections,
'ControllerSignalClose':toClose,
'ActiveTab': activeTab})
def parse_json_stream(self,stream):
decoder = json.JSONDecoder()
while stream:
obj, idx = decoder.raw_decode(stream)
yield obj
stream = stream[idx:].lstrip()
def update_parameter_list(self, ORTDParameter):
newList ={}
for para_id in ORTDParameter:
para_name = ORTDParameter[para_id]['ParameterName']
if para_name in self.parameters:
para_object = self.parameters.pop(para_name)
else:
val_count = int(ORTDParameter[para_id]['NValues'])
opt_object = OptionalObject(para_id, val_count)
if "initial_value" in ORTDParameter[para_id]:
val = ORTDParameter[para_id]['initial_value']
if val_count > 1:
val = val[1:-1]
init_value = list(map(float,val.split(',')))
else:
init_value = float(val)
else:
init_value = 0
para_object = DParameter(para_name, default=str(init_value), OptionalObject=opt_object)
self.pl_send_new_parameter_list([para_object])
newList[para_name] = para_object
toDeleteDict = self.parameters
self.parameters = newList
for par in toDeleteDict:
self.pl_send_delete_parameter(par)
def update_block_list(self,ORTDSources):
#self.block_id = self.block_id +1
#newBlock = DBlock('SourceGroup'+str(self.block_id))
#self.blocks['SourceGroup'+str(self.block_id)] = newBlock
if 'SourceGroup0' in self.blocks:
self.pl_send_delete_block('SourceGroup0')
newBlock = DBlock('SourceGroup0')
self.blocks['SourceGroup0'] = newBlock
self.Sources = ORTDSources
keys = list(self.Sources.keys())
for key in keys:
Source = self.Sources[key]
sig_name = Source['SourceName']
newBlock.add_signal(DSignal(sig_name))
self.pl_send_new_block_list([newBlock])
# Remove BLOCKS
#if 'SourceGroup'+str(self.block_id-1) in self.blocks:
#self.pl_send_delete_block(self.blocks.pop('SourceGroup'+str(self.block_id-1)).name)
def process_papi_data_stream(self, rev):
timestamp = None
offset = 4*4
for i in range(len(self.Sources)):
try:
val = []
# offset += i*(4+4+4)
# Get current signal ID:
# signal_id,data = struct.unpack_from('<id', rev, offset)
signal_id, data = struct.unpack_from('<id', rev, offset)
# print('Offset=' + str(offset))
#
# print('SignalID: ' + str(signal_id))
# print('Data: ' + str(data))
if str(signal_id) in self.Sources:
Source = self.Sources[str(signal_id)]
NValues = int(Source['NValues_send'])
# print("NValues : " + str(NValues))
#print("Offset:" + str(offset))
offset += 4
for n in range(NValues):
# print('#Value=' + str(n))
# print('Offset=' + str(offset))
try:
data = struct.unpack_from('<d', rev, offset)[0]
# print('Data=' + str(data))
val.append(data)
except struct.error:
# print(sys.exc_info()[0])
# print('!!!! except !!!!')
val.append(0)
offset += 8
# print('Data: ' + str(val))
# if NValues > 1:
# signal_id,data = struct.unpack_from('<id%sd' %NValues, rev, offset)
# offset += (NValues-1)*(4+4)
if self.Sources[str(signal_id)]["SourceName"] == "SourceTime":
timestamp = val[0]
self.signal_values[signal_id] = val
#print("Signal: " + str(signal_id) + " Data: " + str(data) );
except struct.error:
print('Error on line {}'.format(sys.exc_info()[-1].tb_lineno))
print(sys.exc_info()[1])
print("Can't unpack.")
self.process_finished_action(-1,None, timestamp)
def process_data_stream(self, SourceId, rev):
# Received a data packet
# Lookup the Source behind the given SourceId
if str(SourceId) in self.Sources:
Source = self.Sources[str(SourceId)]
NValues = int(Source['NValues_send'])
# Read NVales from the received packet
val = []
for i in range(NValues):
try:
val.append(struct.unpack_from('<d', rev, 3 * 4 + i * 8)[0])
except:
val.append(0)
self.signal_values[SourceId] = val
else:
dp_info = self.pl_get_dplugin_info()
print('ORTD_PLUGIN - '+dp_info.uname+': received data with an unknown id ('+str(SourceId)+')')
def process_finished_action(self, SourceId, rev, timestamp=None):
if SourceId == -1:
# unpack group ID
# GroupId = struct.unpack_from('<i', rev, 3 * 4)[0]
self.t += 1.0
keys = list(self.signal_values.keys())
keys.sort() # REMARK: Die liste keys nur einmal sortieren; bei initialisierung
signals_to_send = {}
for key in keys:
if str(key) in self.Sources:
sig_name = self.Sources[str(key)]['SourceName']
signals_to_send[sig_name] = self.signal_values[key]
if len( list(self.blocks.keys()) ) >0:
block = list(self.blocks.keys())[0]
if len(self.blocks[block].signals) == len(signals_to_send)+1:
if timestamp is None:
self.pl_send_new_data(block, [self.t], signals_to_send )
else:
self.pl_send_new_data(block, [timestamp], signals_to_send )
def cb_execute(self, Data=None, block_name = None, plugin_uname = None):
raise Exception('Should not be called!')
def cb_set_parameter(self, name, value):
if name in self.parameters:
parameter = self.parameters[name]
Pid = parameter.OptionalObject.ORTD_par_id
Counter = 111
if value is not None:
data = None
# get values in float from string
valueCast = ast.literal_eval(value)
# check is it is a list, if not, cast to list
if not isinstance(valueCast,list):
valueCast = [valueCast]
if self.PAPI_SIMULINK_BLOCK:
data = struct.pack('<iii%sd' %len(valueCast), 12, Counter, int(Pid),*valueCast)
else:
data = struct.pack('<iii%sd' %len(valueCast), 12, Counter, int(Pid),*valueCast)
#if isinstance(valueCast, list):
#data += struct.pack('%sd' %len(valueCast),*valueCast)
# for i in range(0,len(valueCast)):
# data += struct.pack('<d',valueCast[i])
#else:
# data += struct.pack('d',float(value))
if self.UseSocketIO:
print ("Setting parameter via socket.io")
self.sio.emit('ORTDPACKET', base64.b64encode(data).decode('ascii') )
# TODO test this
else:
if not self.sendOnReceivePort:
self.sock_parameter.sendto(data, (self.HOST, self.OUT_PORT))
else:
self.sock_recv.sendto(data, (self.HOST, self.SOURCE_PORT))
else:
if name == 'consoleIn' and self.UseSocketIO:
self.sio.emit('ConsoleCommand', { 'ConsoleId' : '1' , 'Data' : value })
def cb_quit(self):
self.lock.acquire()
self.thread_goOn = False
self.lock.release()
self.thread.join()
if not self.sendOnReceivePort:
self.sock_parameter.close()
print('ORTD-Plugin will quit')
def cb_plugin_meta_updated(self):
pass
def plconf(self):
cfg = {}
subs = {}
paras = {}
close = {}
if 'PaPIConfig' in self.ProtocolConfig:
if 'ToCreate' in self.ProtocolConfig['PaPIConfig']:
cfg = self.ProtocolConfig['PaPIConfig']['ToCreate']
if 'ToSub' in self.ProtocolConfig['PaPIConfig']:
subs = self.ProtocolConfig['PaPIConfig']['ToSub']
if 'ToControl' in self.ProtocolConfig['PaPIConfig']:
paras = self.ProtocolConfig['PaPIConfig']['ToControl']
if 'ToClose' in self.ProtocolConfig['PaPIConfig']:
close = self.ProtocolConfig['PaPIConfig']['ToClose']
return cfg, subs, paras, close
def extract_config_elements(self, configuration):
plToCreate = {}
subscriptions = {}
paraConnections = {}
plToClose = {}
ORTDSources = {}
ORTDParameters = {}
activeTab = 'PaPI-Tab'
if 'PaPIConfig' in configuration:
if 'ToCreate' in configuration['PaPIConfig']:
plToCreate = configuration['PaPIConfig']['ToCreate']
if 'ToSub' in configuration['PaPIConfig']:
subscriptions = configuration['PaPIConfig']['ToSub']
if 'ToControl' in configuration['PaPIConfig']:
paraConnections = configuration['PaPIConfig']['ToControl']
if 'ToClose' in configuration['PaPIConfig']:
plToClose = configuration['PaPIConfig']['ToClose']
if 'ActiveTab' in configuration['PaPIConfig']:
activeTab = configuration['PaPIConfig']['tab']
if 'SourcesConfig' in configuration:
ORTDSources = configuration['SourcesConfig']
if 'ParametersConfig' in configuration:
ORTDParameters = configuration['ParametersConfig']
return ORTDSources, ORTDParameters, plToCreate, plToClose, subscriptions, paraConnections, activeTab
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
7384,
334,
35,
9,
6927,
5773,
11019,
374,
595,
1910,
4380,
2221,
13733,
84,
23207,
472,
12,
199,
38,
1151,
427,
13733,
84,
27892,
446,
662,
274,
75,
1374,
266,
11019,
3258,
625,
68,
1010,
10928,
30298,
12,
199,
38,
1225,
303,
4492,
386,
799,
24920,
10335,
385,
588,
266,
278,
12,
199,
37,
262,
1597,
262,
1286,
281,
5557,
12,
577,
13,
7320,
1555,
23207,
472,
12,
22261,
3479,
199,
199,
2765,
570,
365,
1777,
402,
10164,
2252,
14,
199,
199,
4232,
2252,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
66,
199,
199,
4232,
2252,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
17732,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
21632,
543,
10164,
2252,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
714,
1925,
6622,
199,
1049,
18824,
5653,
1804,
416,
14262,
199,
26696,
12269,
820,
384,
7751,
199,
199,
624,
4388,
199,
504,
299,
1246,
14,
2718,
14,
1095,
63,
2888,
14,
73,
411,
63,
1095,
492,
284,
411,
63,
1095,
199,
199,
504,
299,
1246,
14,
576,
14,
36,
5061,
492,
577,
3142,
199,
504,
299,
1246,
14,
576,
14,
3177,
1030,
279,
492,
577,
11274,
199,
504,
299,
1246,
14,
576,
14,
36,
4720,
492,
577,
4720,
199,
199,
646,
2680,
465,
980,
199,
199,
646,
5796,
199,
199,
646,
747,
199,
646,
984,
199,
199,
646,
2838,
199,
646,
6073,
199,
646,
2702,
199,
646,
2022,
199,
646,
900,
199,
646,
5927,
199,
646,
1300,
772,
199,
199,
504,
5796,
492,
22287,
199,
504,
2838,
2090,
63,
1258,
492,
17766,
2090,
12,
19928,
8814,
6905,
199,
533,
4879,
1692,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1549,
13449,
63,
462,
63,
344,
12,
302,
1459,
304,
267,
291,
14,
2596,
36,
63,
462,
63,
344,
275,
1549,
13449,
63,
462,
63,
344,
267,
291,
14,
78,
1459,
275,
302,
1459,
267,
291,
14,
2254,
3314,
14235,
4313,
275,
715,
267,
291,
14,
6119,
3869,
2090,
275,
715,
4388,
199,
533,
21802,
63,
5061,
8,
73,
411,
63,
1095,
304,
272,
347,
7434,
63,
362,
63,
2718,
63,
4758,
8,
277,
304,
267,
1101,
275,
469,
288,
283,
1562,
356,
469,
355,
283,
585,
356,
283,
4195,
14,
16,
14,
16,
14,
17,
297,
355,
283,
14652,
356,
283,
3225,
297,
355,
283,
22972,
356,
283,
1772,
2287,
402,
314,
1350,
297,
355,
283,
2918,
63,
505,
356,
283,
4277,
3531,
2287,
7,
288,
1660,
288,
283,
1365,
63,
719,
356,
469,
355,
283,
585,
356,
283,
27140,
297,
355,
283,
14652,
356,
283,
3225,
297,
355,
283,
22972,
356,
283,
4313,
402,
12467,
666,
297,
355,
283,
2918,
63,
505,
356,
283,
2980,
10977,
7,
288,
1660,
288,
283,
548,
63,
719,
356,
469,
355,
283,
585,
356,
283,
1840,
614,
297,
355,
283,
14652,
356,
283,
3225,
297,
355,
283,
22972,
356,
283,
4313,
367,
21507,
666,
297,
355,
283,
2918,
63,
505,
356,
283,
6795,
10977,
7,
288,
1660,
288,
283,
12653,
323,
28536,
356,
469,
355,
283,
585,
356,
283,
16,
297,
355,
283,
14652,
356,
283,
14109,
297,
355,
283,
22972,
356,
283,
8862,
1536,
4673,
11102,
370,
7396,
10166,
297,
355,
283,
2918,
63,
505,
356,
283,
12653,
323,
6632,
2551,
7,
288,
1660,
288,
283,
6795,
3314,
14235,
4313,
356,
469,
355,
283,
585,
356,
283,
16,
297,
355,
283,
14652,
356,
283,
3225,
297,
355,
283,
2918,
63,
505,
356,
283,
8479,
1844,
367,
3222,
436,
9128,
297,
355,
283,
22972,
356,
283,
6119,
314,
1350,
1844,
370,
3222,
666,
1771,
370,
314,
1347,
7,
288,
1660,
288,
298,
6119,
3869,
2090,
2,
520,
469,
355,
283,
585,
7,
520,
283,
16,
297,
355,
283,
14652,
7,
520,
283,
3869,
2090,
297,
355,
283,
22972,
7,
520,
283,
6119,
2838,
14,
2308,
1950,
370,
1031,
14,
3596,
1347,
13,
1000,
297,
355,
283,
2918,
63,
505,
356,
283,
6119,
17766,
2090,
297,
355,
283,
466,
7,
520,
283,
2245,
7,
288,
1660,
288,
283,
5096,
69,
4538,
63,
719,
356,
469,
355,
283,
585,
356,
283,
1257,
3328,
297,
355,
283,
14652,
356,
283,
3869,
2090,
297,
355,
283,
22972,
356,
283,
4313,
367,
314,
17766,
2090,
8113,
297,
355,
283,
2918,
63,
505,
356,
283,
3869,
2090,
10977,
7,
288,
1660,
288,
298,
5903,
5733,
2028,
2,
520,
469,
355,
283,
585,
7,
520,
7,
16,
297,
355,
283,
22972,
7,
520,
283,
6119,
1454,
1642,
2897,
12,
3686,
9848,
13422,
3130,
355,
283,
466,
7,
520,
283,
2245,
297,
355,
283,
14652,
356,
283,
14109,
7,
288,
789,
267,
789,
398,
372,
1101,
339,
347,
7434,
63,
8489,
63,
2718,
8,
277,
304,
267,
870,
360,
2596,
36,
297,
291,
855,
344,
3108,
7596,
1412,
1305,
297,
747,
14,
17829,
1012,
267,
291,
14,
888,
275,
291,
14,
1168,
63,
362,
63,
1818,
63,
888,
63,
1121,
342,
267,
327,
1551,
21802,
267,
291,
14,
5449,
275,
291,
14,
888,
459,
1562,
2545,
585,
418,
267,
291,
14,
10187,
63,
3657,
275,
1109,
8,
277,
14,
888,
459,
1365,
63,
719,
2545,
585,
1105,
267,
291,
14,
1877,
63,
3657,
275,
1109,
8,
277,
14,
888,
459,
548,
63,
719,
2545,
585,
1105,
398,
291,
14,
7486,
15585,
63,
5449,
275,
2125,
327,
1101,
459,
1365,
63,
1562,
2545,
585,
418,
258,
327,
2504,
421,
398,
291,
14,
2254,
3314,
14235,
4313,
275,
715,
340,
291,
14,
888,
459,
6795,
3314,
14235,
4313,
2545,
585,
418,
508,
283,
17
] |
[
2647,
15,
1393,
15,
1548,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
7384,
334,
35,
9,
6927,
5773,
11019,
374,
595,
1910,
4380,
2221,
13733,
84,
23207,
472,
12,
199,
38,
1151,
427,
13733,
84,
27892,
446,
662,
274,
75,
1374,
266,
11019,
3258,
625,
68,
1010,
10928,
30298,
12,
199,
38,
1225,
303,
4492,
386,
799,
24920,
10335,
385,
588,
266,
278,
12,
199,
37,
262,
1597,
262,
1286,
281,
5557,
12,
577,
13,
7320,
1555,
23207,
472,
12,
22261,
3479,
199,
199,
2765,
570,
365,
1777,
402,
10164,
2252,
14,
199,
199,
4232,
2252,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
66,
199,
199,
4232,
2252,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
17732,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
21632,
543,
10164,
2252,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
714,
1925,
6622,
199,
1049,
18824,
5653,
1804,
416,
14262,
199,
26696,
12269,
820,
384,
7751,
199,
199,
624,
4388,
199,
504,
299,
1246,
14,
2718,
14,
1095,
63,
2888,
14,
73,
411,
63,
1095,
492,
284,
411,
63,
1095,
199,
199,
504,
299,
1246,
14,
576,
14,
36,
5061,
492,
577,
3142,
199,
504,
299,
1246,
14,
576,
14,
3177,
1030,
279,
492,
577,
11274,
199,
504,
299,
1246,
14,
576,
14,
36,
4720,
492,
577,
4720,
199,
199,
646,
2680,
465,
980,
199,
199,
646,
5796,
199,
199,
646,
747,
199,
646,
984,
199,
199,
646,
2838,
199,
646,
6073,
199,
646,
2702,
199,
646,
2022,
199,
646,
900,
199,
646,
5927,
199,
646,
1300,
772,
199,
199,
504,
5796,
492,
22287,
199,
504,
2838,
2090,
63,
1258,
492,
17766,
2090,
12,
19928,
8814,
6905,
199,
533,
4879,
1692,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1549,
13449,
63,
462,
63,
344,
12,
302,
1459,
304,
267,
291,
14,
2596,
36,
63,
462,
63,
344,
275,
1549,
13449,
63,
462,
63,
344,
267,
291,
14,
78,
1459,
275,
302,
1459,
267,
291,
14,
2254,
3314,
14235,
4313,
275,
715,
267,
291,
14,
6119,
3869,
2090,
275,
715,
4388,
199,
533,
21802,
63,
5061,
8,
73,
411,
63,
1095,
304,
272,
347,
7434,
63,
362,
63,
2718,
63,
4758,
8,
277,
304,
267,
1101,
275,
469,
288,
283,
1562,
356,
469,
355,
283,
585,
356,
283,
4195,
14,
16,
14,
16,
14,
17,
297,
355,
283,
14652,
356,
283,
3225,
297,
355,
283,
22972,
356,
283,
1772,
2287,
402,
314,
1350,
297,
355,
283,
2918,
63,
505,
356,
283,
4277,
3531,
2287,
7,
288,
1660,
288,
283,
1365,
63,
719,
356,
469,
355,
283,
585,
356,
283,
27140,
297,
355,
283,
14652,
356,
283,
3225,
297,
355,
283,
22972,
356,
283,
4313,
402,
12467,
666,
297,
355,
283,
2918,
63,
505,
356,
283,
2980,
10977,
7,
288,
1660,
288,
283,
548,
63,
719,
356,
469,
355,
283,
585,
356,
283,
1840,
614,
297,
355,
283,
14652,
356,
283,
3225,
297,
355,
283,
22972,
356,
283,
4313,
367,
21507,
666,
297,
355,
283,
2918,
63,
505,
356,
283,
6795,
10977,
7,
288,
1660,
288,
283,
12653,
323,
28536,
356,
469,
355,
283,
585,
356,
283,
16,
297,
355,
283,
14652,
356,
283,
14109,
297,
355,
283,
22972,
356,
283,
8862,
1536,
4673,
11102,
370,
7396,
10166,
297,
355,
283,
2918,
63,
505,
356,
283,
12653,
323,
6632,
2551,
7,
288,
1660,
288,
283,
6795,
3314,
14235,
4313,
356,
469,
355,
283,
585,
356,
283,
16,
297,
355,
283,
14652,
356,
283,
3225,
297,
355,
283,
2918,
63,
505,
356,
283,
8479,
1844,
367,
3222,
436,
9128,
297,
355,
283,
22972,
356,
283,
6119,
314,
1350,
1844,
370,
3222,
666,
1771,
370,
314,
1347,
7,
288,
1660,
288,
298,
6119,
3869,
2090,
2,
520,
469,
355,
283,
585,
7,
520,
283,
16,
297,
355,
283,
14652,
7,
520,
283,
3869,
2090,
297,
355,
283,
22972,
7,
520,
283,
6119,
2838,
14,
2308,
1950,
370,
1031,
14,
3596,
1347,
13,
1000,
297,
355,
283,
2918,
63,
505,
356,
283,
6119,
17766,
2090,
297,
355,
283,
466,
7,
520,
283,
2245,
7,
288,
1660,
288,
283,
5096,
69,
4538,
63,
719,
356,
469,
355,
283,
585,
356,
283,
1257,
3328,
297,
355,
283,
14652,
356,
283,
3869,
2090,
297,
355,
283,
22972,
356,
283,
4313,
367,
314,
17766,
2090,
8113,
297,
355,
283,
2918,
63,
505,
356,
283,
3869,
2090,
10977,
7,
288,
1660,
288,
298,
5903,
5733,
2028,
2,
520,
469,
355,
283,
585,
7,
520,
7,
16,
297,
355,
283,
22972,
7,
520,
283,
6119,
1454,
1642,
2897,
12,
3686,
9848,
13422,
3130,
355,
283,
466,
7,
520,
283,
2245,
297,
355,
283,
14652,
356,
283,
14109,
7,
288,
789,
267,
789,
398,
372,
1101,
339,
347,
7434,
63,
8489,
63,
2718,
8,
277,
304,
267,
870,
360,
2596,
36,
297,
291,
855,
344,
3108,
7596,
1412,
1305,
297,
747,
14,
17829,
1012,
267,
291,
14,
888,
275,
291,
14,
1168,
63,
362,
63,
1818,
63,
888,
63,
1121,
342,
267,
327,
1551,
21802,
267,
291,
14,
5449,
275,
291,
14,
888,
459,
1562,
2545,
585,
418,
267,
291,
14,
10187,
63,
3657,
275,
1109,
8,
277,
14,
888,
459,
1365,
63,
719,
2545,
585,
1105,
267,
291,
14,
1877,
63,
3657,
275,
1109,
8,
277,
14,
888,
459,
548,
63,
719,
2545,
585,
1105,
398,
291,
14,
7486,
15585,
63,
5449,
275,
2125,
327,
1101,
459,
1365,
63,
1562,
2545,
585,
418,
258,
327,
2504,
421,
398,
291,
14,
2254,
3314,
14235,
4313,
275,
715,
340,
291,
14,
888,
459,
6795,
3314,
14235,
4313,
2545,
585,
418,
508,
283,
17,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
craigderington/studentloan5
|
tests/engine.py
|
1
|
5088
|
from subprocess import call
from os import path
import hitchpostgres
import hitchselenium
import hitchpython
import hitchserve
import hitchredis
import hitchtest
import hitchsmtp
# Get directory above this file
PROJECT_DIRECTORY = path.abspath(path.join(path.dirname(__file__), '..'))
class ExecutionEngine(hitchtest.ExecutionEngine):
"""Engine for orchestating and interacting with the app."""
def set_up(self):
"""Ensure virtualenv present, then run all services."""
python_package = hitchpython.PythonPackage(
python_version=self.preconditions['python_version']
)
python_package.build()
python_package.verify()
call([
python_package.pip, "install", "-r",
path.join(PROJECT_DIRECTORY, "requirements/local.txt")
])
postgres_package = hitchpostgres.PostgresPackage(
version=self.settings["postgres_version"],
)
postgres_package.build()
postgres_package.verify()
redis_package = hitchredis.RedisPackage(version="2.8.4")
redis_package.build()
redis_package.verify()
self.services = hitchserve.ServiceBundle(
project_directory=PROJECT_DIRECTORY,
startup_timeout=float(self.settings["startup_timeout"]),
shutdown_timeout=5.0,
)
postgres_user = hitchpostgres.PostgresUser("studentloan5", "password")
self.services['Postgres'] = hitchpostgres.PostgresService(
postgres_package=postgres_package,
users=[postgres_user, ],
databases=[hitchpostgres.PostgresDatabase("studentloan5", postgres_user), ]
)
self.services['HitchSMTP'] = hitchsmtp.HitchSMTPService(port=1025)
self.services['Django'] = hitchpython.DjangoService(
python=python_package.python,
port=8000,
version=str(self.settings.get("django_version")),
settings="config.settings.local",
needs=[self.services['Postgres'], ],
env_vars=self.settings['environment_variables'],
)
self.services['Redis'] = hitchredis.RedisService(
redis_package=redis_package,
port=16379,
)
self.services['Firefox'] = hitchselenium.SeleniumService(
xvfb=self.settings.get("quiet", False),
no_libfaketime=True,
)
# import hitchcron
# self.services['Cron'] = hitchcron.CronService(
# run=self.services['Django'].manage("trigger").command,
# every=1,
# needs=[ self.services['Django'], ],
# )
self.services.startup(interactive=False)
# Configure selenium driver
self.driver = self.services['Firefox'].driver
self.driver.set_window_size(self.settings['window_size']['height'], self.settings['window_size']['width'])
self.driver.set_window_position(0, 0)
self.driver.implicitly_wait(2.0)
self.driver.accept_next_alert = True
def pause(self, message=None):
"""Stop. IPython time."""
if hasattr(self, 'services'):
self.services.start_interactive_mode()
self.ipython(message)
if hasattr(self, 'services'):
self.services.stop_interactive_mode()
def load_website(self):
"""Navigate to website in Firefox."""
self.driver.get(self.services['Django'].url())
def click(self, on):
"""Click on HTML id."""
self.driver.find_element_by_id(on).click()
def fill_form(self, **kwargs):
"""Fill in a form with id=value."""
for element, text in kwargs.items():
self.driver.find_element_by_id(element).send_keys(text)
def click_submit(self):
"""Click on a submit button if it exists."""
self.driver.find_element_by_css_selector("button[type=\"submit\"]").click()
def confirm_emails_sent(self, number):
"""Count number of emails sent by app."""
assert len(self.services['HitchSMTP'].logs.json()) == int(number)
def wait_for_email(self, containing=None):
"""Wait for, and return email."""
self.services['HitchSMTP'].logs.out.tail.until_json(
lambda email: containing in email['payload'] or containing in email['subject'],
timeout=25,
lines_back=1,
)
def time_travel(self, days=""):
"""Make all services think that time has skipped forward."""
self.services.time_travel(days=int(days))
def on_failure(self):
"""Stop and IPython."""
if not self.settings['quiet']:
if self.settings.get("pause_on_failure", False):
self.pause(message=self.stacktrace.to_template())
def on_success(self):
"""Pause on success if enabled."""
if self.settings.get("pause_on_success", False):
self.pause(message="SUCCESS")
def tear_down(self):
"""Shut down services required to run your test."""
if hasattr(self, 'services'):
self.services.shutdown()
|
bsd-3-clause
|
[
504,
3873,
492,
1240,
199,
504,
747,
492,
931,
199,
646,
394,
9414,
10675,
199,
646,
394,
9414,
15041,
199,
646,
394,
9414,
1548,
199,
646,
394,
9414,
4909,
199,
646,
394,
9414,
15369,
199,
646,
394,
9414,
396,
199,
646,
394,
9414,
15592,
421,
199,
3,
2372,
2082,
3432,
642,
570,
199,
10797,
63,
16436,
275,
931,
14,
4832,
8,
515,
14,
904,
8,
515,
14,
3475,
3460,
493,
10139,
11541,
1333,
421,
199,
533,
28573,
8524,
8,
72,
9414,
396,
14,
11310,
8524,
304,
272,
408,
8524,
367,
503,
595,
270,
1958,
436,
17232,
316,
543,
314,
1145,
1041,
339,
347,
663,
63,
384,
8,
277,
304,
267,
408,
13913,
19128,
3451,
12,
2066,
1255,
1006,
8500,
1041,
267,
2366,
63,
2491,
275,
394,
9414,
1548,
14,
4718,
8599,
8,
288,
2366,
63,
1023,
29,
277,
14,
657,
9855,
459,
1548,
63,
1023,
418,
267,
776,
267,
2366,
63,
2491,
14,
1506,
342,
267,
2366,
63,
2491,
14,
4712,
342,
398,
1240,
779,
288,
2366,
63,
2491,
14,
9983,
12,
298,
3174,
401,
3905,
82,
401,
288,
931,
14,
904,
8,
10797,
63,
16436,
12,
298,
7538,
15,
1832,
14,
2424,
531,
267,
4794,
398,
19533,
63,
2491,
275,
394,
9414,
10675,
14,
6564,
7266,
8599,
8,
288,
1015,
29,
277,
14,
1751,
905,
10675,
63,
1023,
2255,
267,
776,
267,
19533,
63,
2491,
14,
1506,
342,
267,
19533,
63,
2491,
14,
4712,
342,
398,
16967,
63,
2491,
275,
394,
9414,
15369,
14,
29605,
8599,
8,
1023,
628,
18,
14,
24,
14,
20,
531,
267,
16967,
63,
2491,
14,
1506,
342,
267,
16967,
63,
2491,
14,
4712,
342,
398,
291,
14,
5950,
275,
394,
9414,
4909,
14,
3167,
12320,
8,
288,
2199,
63,
3619,
29,
10797,
63,
16436,
12,
288,
14210,
63,
2593,
29,
1609,
8,
277,
14,
1751,
905,
16480,
63,
2593,
10252,
288,
12842,
63,
2593,
29,
21,
14,
16,
12,
267,
776,
398,
19533,
63,
751,
275,
394,
9414,
10675,
14,
6564,
7266,
1899,
480,
5500,
320,
290,
21,
401,
298,
2060,
531,
398,
291,
14,
5950,
459,
6564,
7266,
418,
275,
394,
9414,
10675,
14,
6564,
7266,
3167,
8,
288,
19533,
63,
2491,
29,
10675,
63,
2491,
12,
288,
4390,
1524,
10675,
63,
751,
12,
2156,
288,
16219,
1524,
72,
9414,
10675,
14,
6564,
7266,
7243,
480,
5500,
320,
290,
21,
401,
19533,
63,
751,
395,
1622,
267,
776,
398,
291,
14,
5950,
459,
40,
9414,
20927,
418,
275,
394,
9414,
15592,
14,
40,
9414,
20927,
3167,
8,
719,
29,
32105,
9,
398,
291,
14,
5950,
459,
9323,
418,
275,
394,
9414,
1548,
14,
9323,
3167,
8,
288,
2366,
29,
1548,
63,
2491,
14,
1548,
12,
288,
1844,
29,
15214,
12,
288,
1015,
29,
495,
8,
277,
14,
1751,
14,
362,
480,
1176,
63,
1023,
8150,
288,
2202,
628,
888,
14,
1751,
14,
1832,
401,
288,
4839,
1524,
277,
14,
5950,
459,
6564,
7266,
995,
2156,
288,
2589,
63,
2936,
29,
277,
14,
1751,
459,
5418,
63,
3669,
995,
267,
776,
398,
291,
14,
5950,
459,
29605,
418,
275,
394,
9414,
15369,
14,
29605,
3167,
8,
288,
16967,
63,
2491,
29,
15369,
63,
2491,
12,
288,
1844,
29,
975,
12015,
12,
267,
776,
398,
291,
14,
5950,
459,
27983,
418,
275,
394,
9414,
15041,
14,
31315,
3167,
8,
288,
671,
86,
4675,
29,
277,
14,
1751,
14,
362,
480,
10243,
401,
756,
395,
288,
949,
63,
773,
3183,
521,
29,
549,
12,
267,
776,
199,
199,
3,
263,
492,
394,
9414,
14829,
199,
3,
263,
291,
14,
5950,
459,
35,
2641,
418,
275,
394,
9414,
14829,
14,
35,
2641,
3167,
8,
199,
3,
3322,
1255,
29,
277,
14,
5950,
459,
9323,
2278,
9053,
480,
7631,
3471,
1531,
12,
199,
3,
3322,
4036,
29,
17,
12,
199,
3,
3322,
4839,
1524,
291,
14,
5950,
459,
9323,
995,
2156,
199,
3,
263,
776,
398,
291,
14,
5950,
14,
16480,
8,
13543,
29,
797,
9,
398,
327,
15453,
19481,
5253,
267,
291,
14,
3090,
275,
291,
14,
5950,
459,
27983,
2278,
3090,
267,
291,
14,
3090,
14,
409,
63,
3806,
63,
890,
8,
277,
14,
1751,
459,
3806,
63,
890,
2545,
3333,
995,
291,
14,
1751,
459,
3806,
63,
890,
2545,
2063,
1105,
267,
291,
14,
3090,
14,
409,
63,
3806,
63,
3124,
8,
16,
12,
378,
9,
267,
291,
14,
3090,
14,
31120,
63,
2573,
8,
18,
14,
16,
9,
267,
291,
14,
3090,
14,
5694,
63,
2184,
63,
9241,
275,
715,
339,
347,
16834,
8,
277,
12,
1245,
29,
403,
304,
267,
408,
6293,
14,
16243,
900,
1041,
267,
340,
2688,
8,
277,
12,
283,
5950,
735,
288,
291,
14,
5950,
14,
928,
63,
13543,
63,
632,
342,
267,
291,
14,
22691,
8,
1188,
9,
267,
340,
2688,
8,
277,
12,
283,
5950,
735,
288,
291,
14,
5950,
14,
2379,
63,
13543,
63,
632,
342,
339,
347,
2248,
63,
7360,
8,
277,
304,
267,
408,
31914,
370,
10691,
315,
24584,
1041,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
5950,
459,
9323,
2278,
633,
1012,
339,
347,
8968,
8,
277,
12,
641,
304,
267,
408,
12040,
641,
4163,
1305,
1041,
267,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
8,
265,
680,
4891,
342,
339,
347,
5554,
63,
964,
8,
277,
12,
1011,
958,
304,
267,
408,
12914,
315,
282,
1824,
543,
1305,
29,
585,
1041,
267,
367,
1819,
12,
1318,
315,
2074,
14,
1744,
837,
288,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
8,
2108,
680,
2254,
63,
1612,
8,
505,
9,
339,
347,
8968,
63,
7275,
8,
277,
304,
267,
408,
12040,
641,
282,
11482,
5528,
340,
652,
3495,
1041,
267,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
3919,
63,
6662,
480,
3887,
59,
466,
8178,
7275,
60,
937,
3471,
4891,
342,
339,
347,
12679,
63,
14170,
63,
1150,
8,
277,
12,
1329,
304,
267,
408,
2353,
1329,
402,
14931,
4847,
701,
1145,
1041,
267,
702,
822,
8,
277,
14,
5950,
459,
40,
9414,
20927,
2278,
7270,
14,
1001,
1012,
508,
1109,
8,
1955,
9,
339,
347,
3618,
63,
509,
63,
2123,
8,
277,
12,
3035,
29,
403,
304,
267,
408,
7536,
367,
12,
436,
372
] |
[
3873,
492,
1240,
199,
504,
747,
492,
931,
199,
646,
394,
9414,
10675,
199,
646,
394,
9414,
15041,
199,
646,
394,
9414,
1548,
199,
646,
394,
9414,
4909,
199,
646,
394,
9414,
15369,
199,
646,
394,
9414,
396,
199,
646,
394,
9414,
15592,
421,
199,
3,
2372,
2082,
3432,
642,
570,
199,
10797,
63,
16436,
275,
931,
14,
4832,
8,
515,
14,
904,
8,
515,
14,
3475,
3460,
493,
10139,
11541,
1333,
421,
199,
533,
28573,
8524,
8,
72,
9414,
396,
14,
11310,
8524,
304,
272,
408,
8524,
367,
503,
595,
270,
1958,
436,
17232,
316,
543,
314,
1145,
1041,
339,
347,
663,
63,
384,
8,
277,
304,
267,
408,
13913,
19128,
3451,
12,
2066,
1255,
1006,
8500,
1041,
267,
2366,
63,
2491,
275,
394,
9414,
1548,
14,
4718,
8599,
8,
288,
2366,
63,
1023,
29,
277,
14,
657,
9855,
459,
1548,
63,
1023,
418,
267,
776,
267,
2366,
63,
2491,
14,
1506,
342,
267,
2366,
63,
2491,
14,
4712,
342,
398,
1240,
779,
288,
2366,
63,
2491,
14,
9983,
12,
298,
3174,
401,
3905,
82,
401,
288,
931,
14,
904,
8,
10797,
63,
16436,
12,
298,
7538,
15,
1832,
14,
2424,
531,
267,
4794,
398,
19533,
63,
2491,
275,
394,
9414,
10675,
14,
6564,
7266,
8599,
8,
288,
1015,
29,
277,
14,
1751,
905,
10675,
63,
1023,
2255,
267,
776,
267,
19533,
63,
2491,
14,
1506,
342,
267,
19533,
63,
2491,
14,
4712,
342,
398,
16967,
63,
2491,
275,
394,
9414,
15369,
14,
29605,
8599,
8,
1023,
628,
18,
14,
24,
14,
20,
531,
267,
16967,
63,
2491,
14,
1506,
342,
267,
16967,
63,
2491,
14,
4712,
342,
398,
291,
14,
5950,
275,
394,
9414,
4909,
14,
3167,
12320,
8,
288,
2199,
63,
3619,
29,
10797,
63,
16436,
12,
288,
14210,
63,
2593,
29,
1609,
8,
277,
14,
1751,
905,
16480,
63,
2593,
10252,
288,
12842,
63,
2593,
29,
21,
14,
16,
12,
267,
776,
398,
19533,
63,
751,
275,
394,
9414,
10675,
14,
6564,
7266,
1899,
480,
5500,
320,
290,
21,
401,
298,
2060,
531,
398,
291,
14,
5950,
459,
6564,
7266,
418,
275,
394,
9414,
10675,
14,
6564,
7266,
3167,
8,
288,
19533,
63,
2491,
29,
10675,
63,
2491,
12,
288,
4390,
1524,
10675,
63,
751,
12,
2156,
288,
16219,
1524,
72,
9414,
10675,
14,
6564,
7266,
7243,
480,
5500,
320,
290,
21,
401,
19533,
63,
751,
395,
1622,
267,
776,
398,
291,
14,
5950,
459,
40,
9414,
20927,
418,
275,
394,
9414,
15592,
14,
40,
9414,
20927,
3167,
8,
719,
29,
32105,
9,
398,
291,
14,
5950,
459,
9323,
418,
275,
394,
9414,
1548,
14,
9323,
3167,
8,
288,
2366,
29,
1548,
63,
2491,
14,
1548,
12,
288,
1844,
29,
15214,
12,
288,
1015,
29,
495,
8,
277,
14,
1751,
14,
362,
480,
1176,
63,
1023,
8150,
288,
2202,
628,
888,
14,
1751,
14,
1832,
401,
288,
4839,
1524,
277,
14,
5950,
459,
6564,
7266,
995,
2156,
288,
2589,
63,
2936,
29,
277,
14,
1751,
459,
5418,
63,
3669,
995,
267,
776,
398,
291,
14,
5950,
459,
29605,
418,
275,
394,
9414,
15369,
14,
29605,
3167,
8,
288,
16967,
63,
2491,
29,
15369,
63,
2491,
12,
288,
1844,
29,
975,
12015,
12,
267,
776,
398,
291,
14,
5950,
459,
27983,
418,
275,
394,
9414,
15041,
14,
31315,
3167,
8,
288,
671,
86,
4675,
29,
277,
14,
1751,
14,
362,
480,
10243,
401,
756,
395,
288,
949,
63,
773,
3183,
521,
29,
549,
12,
267,
776,
199,
199,
3,
263,
492,
394,
9414,
14829,
199,
3,
263,
291,
14,
5950,
459,
35,
2641,
418,
275,
394,
9414,
14829,
14,
35,
2641,
3167,
8,
199,
3,
3322,
1255,
29,
277,
14,
5950,
459,
9323,
2278,
9053,
480,
7631,
3471,
1531,
12,
199,
3,
3322,
4036,
29,
17,
12,
199,
3,
3322,
4839,
1524,
291,
14,
5950,
459,
9323,
995,
2156,
199,
3,
263,
776,
398,
291,
14,
5950,
14,
16480,
8,
13543,
29,
797,
9,
398,
327,
15453,
19481,
5253,
267,
291,
14,
3090,
275,
291,
14,
5950,
459,
27983,
2278,
3090,
267,
291,
14,
3090,
14,
409,
63,
3806,
63,
890,
8,
277,
14,
1751,
459,
3806,
63,
890,
2545,
3333,
995,
291,
14,
1751,
459,
3806,
63,
890,
2545,
2063,
1105,
267,
291,
14,
3090,
14,
409,
63,
3806,
63,
3124,
8,
16,
12,
378,
9,
267,
291,
14,
3090,
14,
31120,
63,
2573,
8,
18,
14,
16,
9,
267,
291,
14,
3090,
14,
5694,
63,
2184,
63,
9241,
275,
715,
339,
347,
16834,
8,
277,
12,
1245,
29,
403,
304,
267,
408,
6293,
14,
16243,
900,
1041,
267,
340,
2688,
8,
277,
12,
283,
5950,
735,
288,
291,
14,
5950,
14,
928,
63,
13543,
63,
632,
342,
267,
291,
14,
22691,
8,
1188,
9,
267,
340,
2688,
8,
277,
12,
283,
5950,
735,
288,
291,
14,
5950,
14,
2379,
63,
13543,
63,
632,
342,
339,
347,
2248,
63,
7360,
8,
277,
304,
267,
408,
31914,
370,
10691,
315,
24584,
1041,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
5950,
459,
9323,
2278,
633,
1012,
339,
347,
8968,
8,
277,
12,
641,
304,
267,
408,
12040,
641,
4163,
1305,
1041,
267,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
8,
265,
680,
4891,
342,
339,
347,
5554,
63,
964,
8,
277,
12,
1011,
958,
304,
267,
408,
12914,
315,
282,
1824,
543,
1305,
29,
585,
1041,
267,
367,
1819,
12,
1318,
315,
2074,
14,
1744,
837,
288,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
8,
2108,
680,
2254,
63,
1612,
8,
505,
9,
339,
347,
8968,
63,
7275,
8,
277,
304,
267,
408,
12040,
641,
282,
11482,
5528,
340,
652,
3495,
1041,
267,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
3919,
63,
6662,
480,
3887,
59,
466,
8178,
7275,
60,
937,
3471,
4891,
342,
339,
347,
12679,
63,
14170,
63,
1150,
8,
277,
12,
1329,
304,
267,
408,
2353,
1329,
402,
14931,
4847,
701,
1145,
1041,
267,
702,
822,
8,
277,
14,
5950,
459,
40,
9414,
20927,
2278,
7270,
14,
1001,
1012,
508,
1109,
8,
1955,
9,
339,
347,
3618,
63,
509,
63,
2123,
8,
277,
12,
3035,
29,
403,
304,
267,
408,
7536,
367,
12,
436,
372,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
imammedo/virt-test
|
virttest/utils_cgroup.py
|
2
|
13909
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Helpers for cgroup testing.
@copyright: 2011 Red Hat Inc.
@author: Lukas Doktor <ldoktor@redhat.com>
"""
import logging, os, shutil, subprocess, time, re
from tempfile import mkdtemp
from autotest.client import utils
from autotest.client.shared import error
class Cgroup(object):
"""
Cgroup handling class.
"""
def __init__(self, module, _client):
"""
Constructor
@param module: Name of the cgroup module
@param _client: Test script pwd + name
"""
self.module = module
self._client = _client
self.root = None
self.cgroups = []
def __del__(self):
"""
Destructor
"""
self.cgroups.sort(reverse=True)
for pwd in self.cgroups[:]:
for task in self.get_property("tasks", pwd):
if task:
self.set_root_cgroup(int(task))
self.rm_cgroup(pwd)
def initialize(self, modules):
"""
Initializes object for use.
@param modules: Array of all available cgroup modules.
"""
self.root = modules.get_pwd(self.module)
if not self.root:
raise error.TestError("cg.initialize(): Module %s not found"
% self.module)
def mk_cgroup(self, pwd=None):
"""
Creates new temporary cgroup
@param pwd: where to create this cgroup (default: self.root)
@return: 0 when PASSED
"""
if pwd == None:
pwd = self.root
if isinstance(pwd, int):
pwd = self.cgroups[pwd]
try:
pwd = mkdtemp(prefix='cgroup-', dir=pwd) + '/'
except Exception, inst:
raise error.TestError("cg.mk_cgroup(): %s" % inst)
self.cgroups.append(pwd)
return pwd
def rm_cgroup(self, pwd):
"""
Removes cgroup.
@param pwd: cgroup directory.
"""
if isinstance(pwd, int):
pwd = self.cgroups[pwd]
try:
os.rmdir(pwd)
self.cgroups.remove(pwd)
except ValueError:
logging.warn("cg.rm_cgroup(): Removed cgroup which wasn't created"
"using this Cgroup")
except Exception, inst:
raise error.TestError("cg.rm_cgroup(): %s" % inst)
def test(self, cmd):
"""
Executes cgroup_client.py with cmd parameter.
@param cmd: command to be executed
@return: subprocess.Popen() process
"""
logging.debug("cg.test(): executing paralel process '%s'", cmd)
cmd = self._client + ' ' + cmd
process = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True)
return process
def is_cgroup(self, pid, pwd):
"""
Checks if the 'pid' process is in 'pwd' cgroup
@param pid: pid of the process
@param pwd: cgroup directory
@return: 0 when is 'pwd' member
"""
if isinstance(pwd, int):
pwd = self.cgroups[pwd]
if open(pwd + '/tasks').readlines().count("%d\n" % pid) > 0:
return 0
else:
return -1
def is_root_cgroup(self, pid):
"""
Checks if the 'pid' process is in root cgroup (WO cgroup)
@param pid: pid of the process
@return: 0 when is 'root' member
"""
return self.is_cgroup(pid, self.root)
def set_cgroup(self, pid, pwd=None):
"""
Sets cgroup membership
@param pid: pid of the process
@param pwd: cgroup directory
"""
if pwd == None:
pwd = self.root
if isinstance(pwd, int):
pwd = self.cgroups[pwd]
try:
open(pwd+'/tasks', 'w').write(str(pid))
except Exception, inst:
raise error.TestError("cg.set_cgroup(): %s" % inst)
if self.is_cgroup(pid, pwd):
raise error.TestError("cg.set_cgroup(): Setting %d pid into %s "
"cgroup failed" % (pid, pwd))
def set_root_cgroup(self, pid):
"""
Resets the cgroup membership (sets to root)
@param pid: pid of the process
@return: 0 when PASSED
"""
return self.set_cgroup(pid, self.root)
def get_property(self, prop, pwd=None):
"""
Gets the property value
@param prop: property name (file)
@param pwd: cgroup directory
@return: [] values or None when FAILED
"""
if pwd == None:
pwd = self.root
if isinstance(pwd, int):
pwd = self.cgroups[pwd]
try:
# Remove tailing '\n' from each line
ret = [_[:-1] for _ in open(pwd+prop, 'r').readlines()]
if ret:
return ret
else:
return [""]
except Exception, inst:
raise error.TestError("cg.get_property(): %s" % inst)
def set_property_h(self, prop, value, pwd=None, check=True, checkprop=None):
"""
Sets the one-line property value concerning the K,M,G postfix
@param prop: property name (file)
@param value: desired value
@param pwd: cgroup directory
@param check: check the value after setup / override checking value
@param checkprop: override prop when checking the value
"""
_value = value
try:
value = str(value)
human = {'B': 1,
'K': 1024,
'M': 1048576,
'G': 1073741824,
'T': 1099511627776
}
if human.has_key(value[-1]):
value = int(value[:-1]) * human[value[-1]]
except Exception:
logging.warn("cg.set_prop() fallback into cg.set_property.")
value = _value
self.set_property(prop, value, pwd, check, checkprop)
def set_property(self, prop, value, pwd=None, check=True, checkprop=None):
"""
Sets the property value
@param prop: property name (file)
@param value: desired value
@param pwd: cgroup directory
@param check: check the value after setup / override checking value
@param checkprop: override prop when checking the value
"""
value = str(value)
if pwd == None:
pwd = self.root
if isinstance(pwd, int):
pwd = self.cgroups[pwd]
try:
open(os.path.join(pwd, prop), 'w').write(value)
except Exception, inst:
raise error.TestError("cg.set_property(): %s" % inst)
if check is not False:
if check is True:
check = value
if checkprop is None:
checkprop = prop
_values = self.get_property(checkprop, pwd)
# Sanitize non printable characters before check
check = " ".join(check.split())
if check not in _values:
raise error.TestError("cg.set_property(): Setting failed: "
"desired = %s, real values = %s"
% (repr(check), repr(_values)))
def smoke_test(self):
"""
Smoke test
Module independent basic tests
"""
pwd = self.mk_cgroup()
ps = self.test("smoke")
if ps == None:
raise error.TestError("cg.smoke_test: Couldn't create process")
if (ps.poll() != None):
raise error.TestError("cg.smoke_test: Process died unexpectidly")
# New process should be a root member
if self.is_root_cgroup(ps.pid):
raise error.TestError("cg.smoke_test: Process is not a root member")
# Change the cgroup
self.set_cgroup(ps.pid, pwd)
# Try to remove used cgroup
try:
self.rm_cgroup(pwd)
except error.TestError:
pass
else:
raise error.TestError("cg.smoke_test: Unexpected successful deletion"
" of the used cgroup")
# Return the process into the root cgroup
self.set_root_cgroup(ps.pid)
# It should be safe to remove the cgroup now
self.rm_cgroup(pwd)
# Finish the process
ps.stdin.write('\n')
time.sleep(2)
if (ps.poll() == None):
raise error.TestError("cg.smoke_test: Process is not finished")
class CgroupModules(object):
"""
Handles the list of different cgroup filesystems.
"""
def __init__(self):
self.modules = []
self.modules.append([])
self.modules.append([])
self.modules.append([])
self.mountdir = mkdtemp(prefix='cgroup-') + '/'
def __del__(self):
"""
Unmount all cgroups and remove the mountdir
"""
for i in range(len(self.modules[0])):
if self.modules[2][i]:
try:
utils.system('umount %s -l' % self.modules[1][i])
except Exception, failure_detail:
logging.warn("CGM: Couldn't unmount %s directory: %s",
self.modules[1][i], failure_detail)
try:
shutil.rmtree(self.mountdir)
except Exception:
logging.warn("CGM: Couldn't remove the %s directory", self.mountdir)
def init(self, _modules):
"""
Checks the mounted modules and if necessary mounts them into tmp
mountdir.
@param _modules: Desired modules.
@return: Number of initialized modules.
"""
logging.debug("Desired cgroup modules: %s", _modules)
mounts = []
proc_mounts = open('/proc/mounts', 'r')
line = proc_mounts.readline().split()
while line:
if line[2] == 'cgroup':
mounts.append(line)
line = proc_mounts.readline().split()
proc_mounts.close()
for module in _modules:
# Is it already mounted?
i = False
for mount in mounts:
if module in mount[3].split(','):
self.modules[0].append(module)
self.modules[1].append(mount[1] + '/')
self.modules[2].append(False)
i = True
break
if not i:
# Not yet mounted
os.mkdir(self.mountdir + module)
cmd = ('mount -t cgroup -o %s %s %s' %
(module, module, self.mountdir + module))
try:
utils.run(cmd)
self.modules[0].append(module)
self.modules[1].append(self.mountdir + module)
self.modules[2].append(True)
except error.CmdError:
logging.info("Cgroup module '%s' not available", module)
logging.debug("Initialized cgroup modules: %s", self.modules[0])
return len(self.modules[0])
def get_pwd(self, module):
"""
Returns the mount directory of 'module'
@param module: desired module (memory, ...)
@return: mount directory of 'module' or None
"""
try:
i = self.modules[0].index(module)
except Exception, inst:
logging.error("module %s not found: %s", module, inst)
return None
return self.modules[1][i]
def get_load_per_cpu(_stats=None):
"""
Gather load per cpu from /proc/stat
@param _stats: previous values
@return: list of diff/absolute values of CPU times [SUM, CPU1, CPU2, ...]
"""
stats = []
f_stat = open('/proc/stat', 'r')
if _stats:
for i in range(len(_stats)):
stats.append(int(f_stat.readline().split()[1]) - _stats[i])
else:
line = f_stat.readline()
while line:
if line.startswith('cpu'):
stats.append(int(line.split()[1]))
else:
break
line = f_stat.readline()
return stats
def get_cgroup_mountpoint(controller):
controller_list = [ 'cpuacct', 'cpu', 'memory', 'cpuset',
'devices', 'freezer', 'blkio', 'netcls' ]
if controller not in controller_list:
raise error.TestError("Doesn't support controller <%s>" % controller)
f_cgcon = open("/proc/mounts", "rU")
cgconf_txt = f_cgcon.read()
f_cgcon.close()
mntpt = re.findall(r"\s(\S*cgroup/%s)" % controller, cgconf_txt)
return mntpt[0]
def resolve_task_cgroup_path(pid, controller):
"""
Resolving cgroup mount path of a particular task
@params: pid : process id of a task for which the cgroup path required
@params: controller: takes one of the controller names in controller list
@return: resolved path for cgroup controllers of a given pid
"""
# Initialise cgroup controller list
controller_list = [ 'cpuacct', 'cpu', 'memory', 'cpuset',
'devices', 'freezer', 'blkio', 'netcls' ]
if controller not in controller_list:
raise error.TestError("Doesn't support controller <%s>" % controller)
root_path = get_cgroup_mountpoint(controller)
proc_cgroup = "/proc/%d/cgroup" % pid
if not os.path.isfile(proc_cgroup):
raise NameError('File %s does not exist\n Check whether cgroup \
installed in the system' % proc_cgroup)
f = open(proc_cgroup, 'r')
proc_cgroup_txt = f.read()
f.close
mount_path = re.findall(r":%s:(\S*)\n" % controller, proc_cgroup_txt)
path = root_path + mount_path[0]
return path
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
4433,
83,
367,
286,
923,
5343,
14,
199,
199,
32,
7307,
26,
7760,
9572,
13002,
3277,
14,
199,
32,
2502,
26,
491,
3210,
305,
577,
745,
8270,
665,
1447,
745,
8270,
32,
17164,
14,
957,
30,
199,
624,
199,
646,
2050,
12,
747,
12,
5145,
12,
3873,
12,
900,
12,
295,
199,
504,
5549,
492,
31781,
199,
504,
2599,
396,
14,
1258,
492,
3778,
199,
504,
2599,
396,
14,
1258,
14,
5555,
492,
1125,
199,
199,
533,
445,
923,
8,
785,
304,
272,
408,
272,
445,
923,
7252,
1021,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
859,
12,
485,
1258,
304,
267,
408,
267,
20297,
267,
768,
635,
859,
26,
2812,
402,
314,
286,
923,
859,
267,
768,
635,
485,
1258,
26,
1379,
2884,
14374,
435,
536,
267,
408,
267,
291,
14,
578,
275,
859,
267,
291,
423,
1258,
275,
485,
1258,
267,
291,
14,
1231,
275,
488,
267,
291,
14,
67,
2634,
275,
942,
2378,
347,
636,
2264,
721,
277,
304,
267,
408,
267,
1487,
1426,
267,
408,
267,
291,
14,
67,
2634,
14,
3191,
8,
4471,
29,
549,
9,
267,
367,
14374,
315,
291,
14,
67,
2634,
32734,
288,
367,
2120,
315,
291,
14,
362,
63,
1829,
480,
5054,
401,
14374,
304,
355,
340,
2120,
26,
490,
291,
14,
409,
63,
1231,
63,
24483,
8,
442,
8,
1765,
430,
288,
291,
14,
5682,
63,
24483,
8,
14258,
9,
339,
347,
8265,
8,
277,
12,
4621,
304,
267,
408,
267,
6026,
6491,
909,
367,
675,
14,
398,
768,
635,
4621,
26,
8725,
402,
1006,
2808,
286,
923,
4621,
14,
267,
408,
267,
291,
14,
1231,
275,
4621,
14,
362,
63,
14258,
8,
277,
14,
578,
9,
267,
340,
440,
291,
14,
1231,
26,
288,
746,
1125,
14,
774,
547,
480,
12595,
14,
8489,
837,
5673,
450,
83,
440,
1911,
2,
17743,
450,
291,
14,
578,
9,
2378,
347,
9199,
63,
24483,
8,
277,
12,
14374,
29,
403,
304,
267,
408,
267,
10560,
892,
7937,
286,
923,
267,
768,
635,
14374,
26,
2382,
370,
1218,
642,
286,
923,
334,
885,
26,
291,
14,
1231,
9,
267,
768,
1107,
26,
378,
1380,
510,
32032,
267,
408,
267,
340,
14374,
508,
488,
26,
288,
14374,
275,
291,
14,
1231,
267,
340,
1228,
8,
14258,
12,
1109,
304,
288,
14374,
275,
291,
14,
67,
2634,
59,
14258,
61,
267,
862,
26,
288,
14374,
275,
31781,
8,
1861,
534,
24483,
14382,
2935,
29,
14258,
9,
435,
7324,
267,
871,
2186,
12,
2727,
26,
288,
746,
1125,
14,
774,
547,
480,
12595,
14,
3880,
63,
24483,
837,
450,
83,
2,
450,
2727,
9,
267,
291,
14,
67,
2634,
14,
740,
8,
14258,
9,
267,
372,
14374,
2378,
347,
14267,
63,
24483,
8,
277,
12,
14374,
304,
267,
408,
267,
23169,
286,
923,
14,
398,
768,
635,
14374,
26,
286,
923,
2082,
14,
267,
408,
267,
340,
1228,
8,
14258,
12,
1109,
304,
288,
14374,
275,
291,
14,
67,
2634,
59,
14258,
61,
267,
862,
26,
288,
747,
14,
19405,
8,
14258,
9,
288,
291,
14,
67,
2634,
14,
2168,
8,
14258,
9,
267,
871,
1722,
26,
288,
2050,
14,
4050,
480,
12595,
14,
5682,
63,
24483,
837,
799,
3539,
286,
923,
1314,
17373,
1133,
2737,
2,
586,
298,
4941,
642,
445,
923,
531,
267,
871,
2186,
12,
2727,
26,
288,
746,
1125,
14,
774,
547,
480,
12595,
14,
5682,
63,
24483,
837,
450,
83,
2,
450,
2727,
9,
2378,
347,
511,
8,
277,
12,
2088,
304,
267,
408,
267,
9434,
3862,
286,
923,
63,
1258,
14,
647,
543,
2088,
2725,
14,
398,
768,
635,
2088,
26,
1414,
370,
506,
7934,
267,
768,
1107,
26,
3873,
14,
7942,
342,
2112,
267,
408,
267,
2050,
14,
1757,
480,
12595,
14,
396,
837,
14043,
623,
1895,
76,
2112,
1543,
83,
4662,
2088,
9,
267,
2088,
275,
291,
423,
1258,
435,
283,
283,
435,
2088,
267,
2112,
275,
3873,
14,
7942,
8,
1760,
12,
5218,
29,
549,
12,
9009,
29,
5781,
14,
6089,
12,
3521,
3839,
29,
5781,
14,
6089,
12,
3521,
4635,
29,
5781,
14,
6089,
12,
4002,
63,
14240,
29,
549,
9,
267,
372,
2112,
2378,
347,
365,
63,
24483,
8,
277,
12,
4422,
12,
14374,
304,
267,
408,
267,
13813,
340,
314,
283,
3150,
7,
2112,
365,
315,
283,
14258,
7,
286,
923,
267,
768,
635,
4422,
26,
4422,
402,
314,
2112,
267,
768,
635,
14374,
26,
286,
923,
2082,
267,
768,
1107,
26,
378,
1380,
365,
283,
14258,
7,
3653,
267,
408,
267,
340,
1228,
8,
14258,
12,
1109,
304,
288,
14374,
275,
291,
14,
67,
2634,
59,
14258,
61,
267,
340,
1551,
8,
14258,
435,
1994,
5054,
1959,
9684,
1252,
835,
3647,
68,
60,
78,
2,
450,
4422,
9,
690,
378,
26,
288,
372,
378,
267,
587,
26,
288,
372,
446,
17,
2378,
347,
365,
63,
1231,
63,
24483,
8,
277,
12,
4422,
304,
267,
408,
267,
13813,
340,
314,
283,
3150,
7,
2112,
365,
315,
1738,
286,
923,
334,
11325,
286,
923,
9,
267,
768,
635,
4422,
26,
4422,
402,
314,
2112,
267,
768,
1107,
26,
378,
1380,
365,
283,
1231,
7,
3653,
267,
408,
267,
372,
291,
14,
374,
63,
24483,
8,
3150,
12,
291,
14,
1231,
9,
2378,
347,
663,
63,
24483,
8,
277,
12,
4422,
12,
14374,
29,
403,
304,
267,
408,
267,
10729,
286,
923,
14616,
267,
768,
635,
4422,
26,
4422,
402,
314,
2112,
267,
768,
635,
14374,
26,
286,
923,
2082,
267,
408,
267,
340,
14374,
508,
488,
26,
288,
14374,
275,
291,
14,
1231,
267,
340,
1228,
8,
14258,
12,
1109,
304,
288,
14374,
275,
291,
14,
67,
2634,
59,
14258,
61,
267,
862,
26,
288,
1551,
8,
14258,
23164,
5054,
297,
283,
87,
1959,
952,
8,
495,
8,
3150,
430,
267,
871,
2186,
12,
2727,
26,
288,
746,
1125,
14,
774,
547,
480,
12595,
14,
409,
63,
24483,
837,
450,
83,
2,
450,
2727,
9,
267,
340,
291,
14,
374,
63,
24483,
8,
3150,
12,
14374,
304,
288,
746,
1125,
14,
774,
547,
480,
12595,
14,
409,
63,
24483,
837,
13510,
450,
68,
4422,
1901,
450,
83,
298
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
4433,
83,
367,
286,
923,
5343,
14,
199,
199,
32,
7307,
26,
7760,
9572,
13002,
3277,
14,
199,
32,
2502,
26,
491,
3210,
305,
577,
745,
8270,
665,
1447,
745,
8270,
32,
17164,
14,
957,
30,
199,
624,
199,
646,
2050,
12,
747,
12,
5145,
12,
3873,
12,
900,
12,
295,
199,
504,
5549,
492,
31781,
199,
504,
2599,
396,
14,
1258,
492,
3778,
199,
504,
2599,
396,
14,
1258,
14,
5555,
492,
1125,
199,
199,
533,
445,
923,
8,
785,
304,
272,
408,
272,
445,
923,
7252,
1021,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
859,
12,
485,
1258,
304,
267,
408,
267,
20297,
267,
768,
635,
859,
26,
2812,
402,
314,
286,
923,
859,
267,
768,
635,
485,
1258,
26,
1379,
2884,
14374,
435,
536,
267,
408,
267,
291,
14,
578,
275,
859,
267,
291,
423,
1258,
275,
485,
1258,
267,
291,
14,
1231,
275,
488,
267,
291,
14,
67,
2634,
275,
942,
2378,
347,
636,
2264,
721,
277,
304,
267,
408,
267,
1487,
1426,
267,
408,
267,
291,
14,
67,
2634,
14,
3191,
8,
4471,
29,
549,
9,
267,
367,
14374,
315,
291,
14,
67,
2634,
32734,
288,
367,
2120,
315,
291,
14,
362,
63,
1829,
480,
5054,
401,
14374,
304,
355,
340,
2120,
26,
490,
291,
14,
409,
63,
1231,
63,
24483,
8,
442,
8,
1765,
430,
288,
291,
14,
5682,
63,
24483,
8,
14258,
9,
339,
347,
8265,
8,
277,
12,
4621,
304,
267,
408,
267,
6026,
6491,
909,
367,
675,
14,
398,
768,
635,
4621,
26,
8725,
402,
1006,
2808,
286,
923,
4621,
14,
267,
408,
267,
291,
14,
1231,
275,
4621,
14,
362,
63,
14258,
8,
277,
14,
578,
9,
267,
340,
440,
291,
14,
1231,
26,
288,
746,
1125,
14,
774,
547,
480,
12595,
14,
8489,
837,
5673,
450,
83,
440,
1911,
2,
17743,
450,
291,
14,
578,
9,
2378,
347,
9199,
63,
24483,
8,
277,
12,
14374,
29,
403,
304,
267,
408,
267,
10560,
892,
7937,
286,
923,
267,
768,
635,
14374,
26,
2382,
370,
1218,
642,
286,
923,
334,
885,
26,
291,
14,
1231,
9,
267,
768,
1107,
26,
378,
1380,
510,
32032,
267,
408,
267,
340,
14374,
508,
488,
26,
288,
14374,
275,
291,
14,
1231,
267,
340,
1228,
8,
14258,
12,
1109,
304,
288,
14374,
275,
291,
14,
67,
2634,
59,
14258,
61,
267,
862,
26,
288,
14374,
275,
31781,
8,
1861,
534,
24483,
14382,
2935,
29,
14258,
9,
435,
7324,
267,
871,
2186,
12,
2727,
26,
288,
746,
1125,
14,
774,
547,
480,
12595,
14,
3880,
63,
24483,
837,
450,
83,
2,
450,
2727,
9,
267,
291,
14,
67,
2634,
14,
740,
8,
14258,
9,
267,
372,
14374,
2378,
347,
14267,
63,
24483,
8,
277,
12,
14374,
304,
267,
408,
267,
23169,
286,
923,
14,
398,
768,
635,
14374,
26,
286,
923,
2082,
14,
267,
408,
267,
340,
1228,
8,
14258,
12,
1109,
304,
288,
14374,
275,
291,
14,
67,
2634,
59,
14258,
61,
267,
862,
26,
288,
747,
14,
19405,
8,
14258,
9,
288,
291,
14,
67,
2634,
14,
2168,
8,
14258,
9,
267,
871,
1722,
26,
288,
2050,
14,
4050,
480,
12595,
14,
5682,
63,
24483,
837,
799,
3539,
286,
923,
1314,
17373,
1133,
2737,
2,
586,
298,
4941,
642,
445,
923,
531,
267,
871,
2186,
12,
2727,
26,
288,
746,
1125,
14,
774,
547,
480,
12595,
14,
5682,
63,
24483,
837,
450,
83,
2,
450,
2727,
9,
2378,
347,
511,
8,
277,
12,
2088,
304,
267,
408,
267,
9434,
3862,
286,
923,
63,
1258,
14,
647,
543,
2088,
2725,
14,
398,
768,
635,
2088,
26,
1414,
370,
506,
7934,
267,
768,
1107,
26,
3873,
14,
7942,
342,
2112,
267,
408,
267,
2050,
14,
1757,
480,
12595,
14,
396,
837,
14043,
623,
1895,
76,
2112,
1543,
83,
4662,
2088,
9,
267,
2088,
275,
291,
423,
1258,
435,
283,
283,
435,
2088,
267,
2112,
275,
3873,
14,
7942,
8,
1760,
12,
5218,
29,
549,
12,
9009,
29,
5781,
14,
6089,
12,
3521,
3839,
29,
5781,
14,
6089,
12,
3521,
4635,
29,
5781,
14,
6089,
12,
4002,
63,
14240,
29,
549,
9,
267,
372,
2112,
2378,
347,
365,
63,
24483,
8,
277,
12,
4422,
12,
14374,
304,
267,
408,
267,
13813,
340,
314,
283,
3150,
7,
2112,
365,
315,
283,
14258,
7,
286,
923,
267,
768,
635,
4422,
26,
4422,
402,
314,
2112,
267,
768,
635,
14374,
26,
286,
923,
2082,
267,
768,
1107,
26,
378,
1380,
365,
283,
14258,
7,
3653,
267,
408,
267,
340,
1228,
8,
14258,
12,
1109,
304,
288,
14374,
275,
291,
14,
67,
2634,
59,
14258,
61,
267,
340,
1551,
8,
14258,
435,
1994,
5054,
1959,
9684,
1252,
835,
3647,
68,
60,
78,
2,
450,
4422,
9,
690,
378,
26,
288,
372,
378,
267,
587,
26,
288,
372,
446,
17,
2378,
347,
365,
63,
1231,
63,
24483,
8,
277,
12,
4422,
304,
267,
408,
267,
13813,
340,
314,
283,
3150,
7,
2112,
365,
315,
1738,
286,
923,
334,
11325,
286,
923,
9,
267,
768,
635,
4422,
26,
4422,
402,
314,
2112,
267,
768,
1107,
26,
378,
1380,
365,
283,
1231,
7,
3653,
267,
408,
267,
372,
291,
14,
374,
63,
24483,
8,
3150,
12,
291,
14,
1231,
9,
2378,
347,
663,
63,
24483,
8,
277,
12,
4422,
12,
14374,
29,
403,
304,
267,
408,
267,
10729,
286,
923,
14616,
267,
768,
635,
4422,
26,
4422,
402,
314,
2112,
267,
768,
635,
14374,
26,
286,
923,
2082,
267,
408,
267,
340,
14374,
508,
488,
26,
288,
14374,
275,
291,
14,
1231,
267,
340,
1228,
8,
14258,
12,
1109,
304,
288,
14374,
275,
291,
14,
67,
2634,
59,
14258,
61,
267,
862,
26,
288,
1551,
8,
14258,
23164,
5054,
297,
283,
87,
1959,
952,
8,
495,
8,
3150,
430,
267,
871,
2186,
12,
2727,
26,
288,
746,
1125,
14,
774,
547,
480,
12595,
14,
409,
63,
24483,
837,
450,
83,
2,
450,
2727,
9,
267,
340,
291,
14,
374,
63,
24483,
8,
3150,
12,
14374,
304,
288,
746,
1125,
14,
774,
547,
480,
12595,
14,
409,
63,
24483,
837,
13510,
450,
68,
4422,
1901,
450,
83,
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,
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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
] |
otherness-space/myProject003
|
my_project_003/lib/python2.7/site-packages/django/contrib/auth/tests/test_models.py
|
104
|
6290
|
import warnings
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import (Group, User, SiteProfileNotAvailable,
UserManager)
from django.contrib.auth.tests.custom_user import IsActiveTestUser1
from django.contrib.auth.tests.utils import skipIfCustomUser
from django.db.models.signals import post_save
from django.test import TestCase
from django.test.utils import override_settings
from django.utils import six
@skipIfCustomUser
@override_settings(USE_TZ=False, AUTH_PROFILE_MODULE='')
class ProfileTestCase(TestCase):
def test_site_profile_not_available(self):
user = User.objects.create(username='testclient')
# calling get_profile without AUTH_PROFILE_MODULE set
del settings.AUTH_PROFILE_MODULE
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
with six.assertRaisesRegex(self, SiteProfileNotAvailable,
"You need to set AUTH_PROFILE_MODULE in your project"):
user.get_profile()
# Bad syntax in AUTH_PROFILE_MODULE:
settings.AUTH_PROFILE_MODULE = 'foobar'
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
with six.assertRaisesRegex(self, SiteProfileNotAvailable,
"app_label and model_name should be separated by a dot"):
user.get_profile()
# module that doesn't exist
settings.AUTH_PROFILE_MODULE = 'foo.bar'
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
with six.assertRaisesRegex(self, SiteProfileNotAvailable,
"Unable to load the profile model"):
user.get_profile()
@skipIfCustomUser
@override_settings(USE_TZ=False)
class NaturalKeysTestCase(TestCase):
fixtures = ['authtestdata.json']
def test_user_natural_key(self):
staff_user = User.objects.get(username='staff')
self.assertEqual(User.objects.get_by_natural_key('staff'), staff_user)
self.assertEqual(staff_user.natural_key(), ('staff',))
def test_group_natural_key(self):
users_group = Group.objects.create(name='users')
self.assertEqual(Group.objects.get_by_natural_key('users'), users_group)
@skipIfCustomUser
@override_settings(USE_TZ=False)
class LoadDataWithoutNaturalKeysTestCase(TestCase):
fixtures = ['regular.json']
def test_user_is_created_and_added_to_group(self):
user = User.objects.get(username='my_username')
group = Group.objects.get(name='my_group')
self.assertEqual(group, user.groups.get())
@skipIfCustomUser
@override_settings(USE_TZ=False)
class LoadDataWithNaturalKeysTestCase(TestCase):
fixtures = ['natural.json']
def test_user_is_created_and_added_to_group(self):
user = User.objects.get(username='my_username')
group = Group.objects.get(name='my_group')
self.assertEqual(group, user.groups.get())
@skipIfCustomUser
class UserManagerTestCase(TestCase):
def test_create_user(self):
email_lowercase = 'normal@normal.com'
user = User.objects.create_user('user', email_lowercase)
self.assertEqual(user.email, email_lowercase)
self.assertEqual(user.username, 'user')
self.assertFalse(user.has_usable_password())
def test_create_user_email_domain_normalize_rfc3696(self):
# According to http://tools.ietf.org/html/rfc3696#section-3
# the "@" symbol can be part of the local part of an email address
returned = UserManager.normalize_email(r'Abc\@DEF@EXAMPLE.com')
self.assertEqual(returned, r'Abc\@DEF@example.com')
def test_create_user_email_domain_normalize(self):
returned = UserManager.normalize_email('normal@DOMAIN.COM')
self.assertEqual(returned, 'normal@domain.com')
def test_create_user_email_domain_normalize_with_whitespace(self):
returned = UserManager.normalize_email('email\ with_whitespace@D.COM')
self.assertEqual(returned, 'email\ with_whitespace@d.com')
def test_empty_username(self):
self.assertRaisesMessage(ValueError,
'The given username must be set',
User.objects.create_user, username='')
class IsActiveTestCase(TestCase):
"""
Tests the behavior of the guaranteed is_active attribute
"""
@skipIfCustomUser
def test_builtin_user_isactive(self):
user = User.objects.create(username='foo', email='foo@bar.com')
# is_active is true by default
self.assertEqual(user.is_active, True)
user.is_active = False
user.save()
user_fetched = User.objects.get(pk=user.pk)
# the is_active flag is saved
self.assertFalse(user_fetched.is_active)
@override_settings(AUTH_USER_MODEL='auth.IsActiveTestUser1')
def test_is_active_field_default(self):
"""
tests that the default value for is_active is provided
"""
UserModel = get_user_model()
user = UserModel(username='foo')
self.assertEqual(user.is_active, True)
# you can set the attribute - but it will not save
user.is_active = False
# there should be no problem saving - but the attribute is not saved
user.save()
user_fetched = UserModel._default_manager.get(pk=user.pk)
# the attribute is always true for newly retrieved instance
self.assertEqual(user_fetched.is_active, True)
@skipIfCustomUser
class TestCreateSuperUserSignals(TestCase):
"""
Simple test case for ticket #20541
"""
def post_save_listener(self, *args, **kwargs):
self.signals_count += 1
def setUp(self):
self.signals_count = 0
post_save.connect(self.post_save_listener, sender=User)
def tearDown(self):
post_save.disconnect(self.post_save_listener, sender=User)
def test_create_user(self):
User.objects.create_user("JohnDoe")
self.assertEqual(self.signals_count, 1)
def test_create_superuser(self):
User.objects.create_superuser("JohnDoe", "mail@example.com", "1")
self.assertEqual(self.signals_count, 1)
|
mit
|
[
646,
3598,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
492,
664,
63,
751,
63,
1238,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
334,
2448,
12,
2876,
12,
11666,
5736,
1763,
11464,
12,
272,
2876,
2988,
9,
199,
504,
1639,
14,
2828,
14,
1178,
14,
2219,
14,
4229,
63,
751,
492,
6596,
7472,
774,
1899,
17,
199,
504,
1639,
14,
2828,
14,
1178,
14,
2219,
14,
1208,
492,
3372,
3917,
31482,
199,
504,
1639,
14,
697,
14,
992,
14,
10458,
492,
2963,
63,
2117,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
504,
1639,
14,
1208,
492,
3816,
421,
199,
32,
15118,
31482,
199,
32,
4415,
63,
1751,
8,
4701,
63,
14226,
29,
797,
12,
7560,
63,
16632,
63,
10001,
13275,
199,
533,
14386,
1746,
8,
1746,
304,
339,
347,
511,
63,
2124,
63,
2913,
63,
1397,
63,
4561,
8,
277,
304,
267,
922,
275,
2876,
14,
1462,
14,
981,
8,
2473,
534,
396,
1258,
358,
398,
327,
6358,
664,
63,
2913,
1928,
7560,
63,
16632,
63,
10001,
663,
267,
2150,
2202,
14,
5580,
63,
16632,
63,
10001,
267,
543,
3598,
14,
9341,
63,
5451,
837,
288,
3598,
14,
18815,
480,
4247,
401,
13413,
9,
288,
543,
3816,
14,
16499,
8,
277,
12,
11666,
5736,
1763,
11464,
12,
490,
298,
5556,
1929,
370,
663,
7560,
63,
16632,
63,
10001,
315,
2195,
2199,
2349,
355,
922,
14,
362,
63,
2913,
342,
398,
327,
8857,
6302,
315,
7560,
63,
16632,
63,
10001,
26,
267,
2202,
14,
5580,
63,
16632,
63,
10001,
275,
283,
9664,
7,
267,
543,
3598,
14,
9341,
63,
5451,
837,
288,
3598,
14,
18815,
480,
4247,
401,
13413,
9,
288,
543,
3816,
14,
16499,
8,
277,
12,
11666,
5736,
1763,
11464,
12,
490,
298,
571,
63,
1302,
436,
1402,
63,
354,
1077,
506,
11673,
701,
282,
6308,
2349,
355,
922,
14,
362,
63,
2913,
342,
398,
327,
859,
626,
3181,
1133,
2187,
267,
2202,
14,
5580,
63,
16632,
63,
10001,
275,
283,
1421,
14,
1700,
7,
267,
543,
3598,
14,
9341,
63,
5451,
837,
288,
3598,
14,
18815,
480,
4247,
401,
13413,
9,
288,
543,
3816,
14,
16499,
8,
277,
12,
11666,
5736,
1763,
11464,
12,
490,
298,
6005,
370,
2248,
314,
4690,
1402,
2349,
355,
922,
14,
362,
63,
2913,
342,
421,
199,
32,
15118,
31482,
199,
32,
4415,
63,
1751,
8,
4701,
63,
14226,
29,
797,
9,
199,
533,
653,
292,
4889,
6340,
1746,
8,
1746,
304,
272,
15188,
275,
788,
1178,
18481,
14,
1001,
418,
339,
347,
511,
63,
751,
63,
15759,
63,
498,
8,
277,
304,
267,
12622,
63,
751,
275,
2876,
14,
1462,
14,
362,
8,
2473,
534,
7018,
358,
267,
291,
14,
629,
8,
1899,
14,
1462,
14,
362,
63,
991,
63,
15759,
63,
498,
360,
7018,
659,
12622,
63,
751,
9,
267,
291,
14,
629,
8,
7018,
63,
751,
14,
15759,
63,
498,
1062,
661,
7018,
16829,
339,
347,
511,
63,
923,
63,
15759,
63,
498,
8,
277,
304,
267,
4390,
63,
923,
275,
5611,
14,
1462,
14,
981,
8,
354,
534,
3707,
358,
267,
291,
14,
629,
8,
2448,
14,
1462,
14,
362,
63,
991,
63,
15759,
63,
498,
360,
3707,
659,
4390,
63,
923,
9,
421,
199,
32,
15118,
31482,
199,
32,
4415,
63,
1751,
8,
4701,
63,
14226,
29,
797,
9,
199,
533,
7190,
1451,
12450,
23604,
4889,
6340,
1746,
8,
1746,
304,
272,
15188,
275,
788,
7898,
14,
1001,
418,
339,
347,
511,
63,
751,
63,
374,
63,
3966,
63,
460,
63,
3270,
63,
475,
63,
923,
8,
277,
304,
267,
922,
275,
2876,
14,
1462,
14,
362,
8,
2473,
534,
1662,
63,
2473,
358,
267,
1572,
275,
5611,
14,
1462,
14,
362,
8,
354,
534,
1662,
63,
923,
358,
267,
291,
14,
629,
8,
923,
12,
922,
14,
2634,
14,
362,
1012,
421,
199,
32,
15118,
31482,
199,
32,
4415,
63,
1751,
8,
4701,
63,
14226,
29,
797,
9,
199,
533,
7190,
1451,
3007,
23604,
4889,
6340,
1746,
8,
1746,
304,
272,
15188,
275,
788,
15759,
14,
1001,
418,
339,
347,
511,
63,
751,
63,
374,
63,
3966,
63,
460,
63,
3270,
63,
475,
63,
923,
8,
277,
304,
267,
922,
275,
2876,
14,
1462,
14,
362,
8,
2473,
534,
1662,
63,
2473,
358,
267,
1572,
275,
5611,
14,
1462,
14,
362,
8,
354,
534,
1662,
63,
923,
358,
267,
291,
14,
629,
8,
923,
12,
922,
14,
2634,
14,
362,
1012,
421,
199,
32,
15118,
31482,
199,
533,
2876,
2988,
1746,
8,
1746,
304,
339,
347,
511,
63,
981,
63,
751,
8,
277,
304,
267,
3031,
63,
21636,
275,
283,
3302,
32,
3302,
14,
957,
7,
267,
922,
275,
2876,
14,
1462,
14,
981,
63,
751,
360,
751,
297,
3031,
63,
21636,
9,
267,
291,
14,
629,
8,
751,
14,
2123,
12,
3031,
63,
21636,
9,
267,
291,
14,
629,
8,
751,
14,
2473,
12,
283,
751,
358,
267,
291,
14,
3334,
8,
751,
14,
1989,
63,
14418,
63,
2060,
1012,
339,
347,
511,
63,
981,
63,
751,
63,
2123,
63,
2261,
63,
7721,
63,
8973,
1344,
2534,
8,
277,
304,
267,
327,
31970,
370,
221,
1455,
921,
2537,
14,
15799,
14,
1308,
15,
1360,
15,
8973,
1344,
2534,
3,
2792,
13,
19,
267,
327,
314,
9244,
2,
5272,
883,
506,
1777,
402,
314,
2257,
1777,
402,
376,
3031,
2287,
267,
2138,
275,
2876,
2988,
14,
7721,
63,
2123,
8,
82,
7,
30293,
60,
32,
5638,
32,
26900,
14,
957,
358,
267,
291,
14,
629,
8,
19065,
12,
519,
7,
30293,
60,
32,
5638,
32,
2694,
14,
957,
358,
339,
347,
511,
63,
981,
63,
751,
63,
2123,
63,
2261,
63,
7721,
8,
277,
304,
267,
2138,
275,
2876,
2988,
14,
7721,
63,
2123,
360,
3302,
32,
7378,
14,
11265,
358,
267,
291,
14,
629,
8,
19065,
12,
283,
3302,
32,
2261,
14,
957,
358,
339,
347,
511,
63,
981,
63,
751,
63,
2123,
63,
2261,
63,
7721,
63,
1045,
63,
8506,
8,
277,
304,
267,
2138,
275,
2876,
2988,
14,
7721,
63,
2123,
360,
2123,
60,
543,
63,
8506,
32,
36,
14,
11265,
358,
267,
291,
14,
629
] |
[
3598,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
492,
664,
63,
751,
63,
1238,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
334,
2448,
12,
2876,
12,
11666,
5736,
1763,
11464,
12,
272,
2876,
2988,
9,
199,
504,
1639,
14,
2828,
14,
1178,
14,
2219,
14,
4229,
63,
751,
492,
6596,
7472,
774,
1899,
17,
199,
504,
1639,
14,
2828,
14,
1178,
14,
2219,
14,
1208,
492,
3372,
3917,
31482,
199,
504,
1639,
14,
697,
14,
992,
14,
10458,
492,
2963,
63,
2117,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
504,
1639,
14,
1208,
492,
3816,
421,
199,
32,
15118,
31482,
199,
32,
4415,
63,
1751,
8,
4701,
63,
14226,
29,
797,
12,
7560,
63,
16632,
63,
10001,
13275,
199,
533,
14386,
1746,
8,
1746,
304,
339,
347,
511,
63,
2124,
63,
2913,
63,
1397,
63,
4561,
8,
277,
304,
267,
922,
275,
2876,
14,
1462,
14,
981,
8,
2473,
534,
396,
1258,
358,
398,
327,
6358,
664,
63,
2913,
1928,
7560,
63,
16632,
63,
10001,
663,
267,
2150,
2202,
14,
5580,
63,
16632,
63,
10001,
267,
543,
3598,
14,
9341,
63,
5451,
837,
288,
3598,
14,
18815,
480,
4247,
401,
13413,
9,
288,
543,
3816,
14,
16499,
8,
277,
12,
11666,
5736,
1763,
11464,
12,
490,
298,
5556,
1929,
370,
663,
7560,
63,
16632,
63,
10001,
315,
2195,
2199,
2349,
355,
922,
14,
362,
63,
2913,
342,
398,
327,
8857,
6302,
315,
7560,
63,
16632,
63,
10001,
26,
267,
2202,
14,
5580,
63,
16632,
63,
10001,
275,
283,
9664,
7,
267,
543,
3598,
14,
9341,
63,
5451,
837,
288,
3598,
14,
18815,
480,
4247,
401,
13413,
9,
288,
543,
3816,
14,
16499,
8,
277,
12,
11666,
5736,
1763,
11464,
12,
490,
298,
571,
63,
1302,
436,
1402,
63,
354,
1077,
506,
11673,
701,
282,
6308,
2349,
355,
922,
14,
362,
63,
2913,
342,
398,
327,
859,
626,
3181,
1133,
2187,
267,
2202,
14,
5580,
63,
16632,
63,
10001,
275,
283,
1421,
14,
1700,
7,
267,
543,
3598,
14,
9341,
63,
5451,
837,
288,
3598,
14,
18815,
480,
4247,
401,
13413,
9,
288,
543,
3816,
14,
16499,
8,
277,
12,
11666,
5736,
1763,
11464,
12,
490,
298,
6005,
370,
2248,
314,
4690,
1402,
2349,
355,
922,
14,
362,
63,
2913,
342,
421,
199,
32,
15118,
31482,
199,
32,
4415,
63,
1751,
8,
4701,
63,
14226,
29,
797,
9,
199,
533,
653,
292,
4889,
6340,
1746,
8,
1746,
304,
272,
15188,
275,
788,
1178,
18481,
14,
1001,
418,
339,
347,
511,
63,
751,
63,
15759,
63,
498,
8,
277,
304,
267,
12622,
63,
751,
275,
2876,
14,
1462,
14,
362,
8,
2473,
534,
7018,
358,
267,
291,
14,
629,
8,
1899,
14,
1462,
14,
362,
63,
991,
63,
15759,
63,
498,
360,
7018,
659,
12622,
63,
751,
9,
267,
291,
14,
629,
8,
7018,
63,
751,
14,
15759,
63,
498,
1062,
661,
7018,
16829,
339,
347,
511,
63,
923,
63,
15759,
63,
498,
8,
277,
304,
267,
4390,
63,
923,
275,
5611,
14,
1462,
14,
981,
8,
354,
534,
3707,
358,
267,
291,
14,
629,
8,
2448,
14,
1462,
14,
362,
63,
991,
63,
15759,
63,
498,
360,
3707,
659,
4390,
63,
923,
9,
421,
199,
32,
15118,
31482,
199,
32,
4415,
63,
1751,
8,
4701,
63,
14226,
29,
797,
9,
199,
533,
7190,
1451,
12450,
23604,
4889,
6340,
1746,
8,
1746,
304,
272,
15188,
275,
788,
7898,
14,
1001,
418,
339,
347,
511,
63,
751,
63,
374,
63,
3966,
63,
460,
63,
3270,
63,
475,
63,
923,
8,
277,
304,
267,
922,
275,
2876,
14,
1462,
14,
362,
8,
2473,
534,
1662,
63,
2473,
358,
267,
1572,
275,
5611,
14,
1462,
14,
362,
8,
354,
534,
1662,
63,
923,
358,
267,
291,
14,
629,
8,
923,
12,
922,
14,
2634,
14,
362,
1012,
421,
199,
32,
15118,
31482,
199,
32,
4415,
63,
1751,
8,
4701,
63,
14226,
29,
797,
9,
199,
533,
7190,
1451,
3007,
23604,
4889,
6340,
1746,
8,
1746,
304,
272,
15188,
275,
788,
15759,
14,
1001,
418,
339,
347,
511,
63,
751,
63,
374,
63,
3966,
63,
460,
63,
3270,
63,
475,
63,
923,
8,
277,
304,
267,
922,
275,
2876,
14,
1462,
14,
362,
8,
2473,
534,
1662,
63,
2473,
358,
267,
1572,
275,
5611,
14,
1462,
14,
362,
8,
354,
534,
1662,
63,
923,
358,
267,
291,
14,
629,
8,
923,
12,
922,
14,
2634,
14,
362,
1012,
421,
199,
32,
15118,
31482,
199,
533,
2876,
2988,
1746,
8,
1746,
304,
339,
347,
511,
63,
981,
63,
751,
8,
277,
304,
267,
3031,
63,
21636,
275,
283,
3302,
32,
3302,
14,
957,
7,
267,
922,
275,
2876,
14,
1462,
14,
981,
63,
751,
360,
751,
297,
3031,
63,
21636,
9,
267,
291,
14,
629,
8,
751,
14,
2123,
12,
3031,
63,
21636,
9,
267,
291,
14,
629,
8,
751,
14,
2473,
12,
283,
751,
358,
267,
291,
14,
3334,
8,
751,
14,
1989,
63,
14418,
63,
2060,
1012,
339,
347,
511,
63,
981,
63,
751,
63,
2123,
63,
2261,
63,
7721,
63,
8973,
1344,
2534,
8,
277,
304,
267,
327,
31970,
370,
221,
1455,
921,
2537,
14,
15799,
14,
1308,
15,
1360,
15,
8973,
1344,
2534,
3,
2792,
13,
19,
267,
327,
314,
9244,
2,
5272,
883,
506,
1777,
402,
314,
2257,
1777,
402,
376,
3031,
2287,
267,
2138,
275,
2876,
2988,
14,
7721,
63,
2123,
8,
82,
7,
30293,
60,
32,
5638,
32,
26900,
14,
957,
358,
267,
291,
14,
629,
8,
19065,
12,
519,
7,
30293,
60,
32,
5638,
32,
2694,
14,
957,
358,
339,
347,
511,
63,
981,
63,
751,
63,
2123,
63,
2261,
63,
7721,
8,
277,
304,
267,
2138,
275,
2876,
2988,
14,
7721,
63,
2123,
360,
3302,
32,
7378,
14,
11265,
358,
267,
291,
14,
629,
8,
19065,
12,
283,
3302,
32,
2261,
14,
957,
358,
339,
347,
511,
63,
981,
63,
751,
63,
2123,
63,
2261,
63,
7721,
63,
1045,
63,
8506,
8,
277,
304,
267,
2138,
275,
2876,
2988,
14,
7721,
63,
2123,
360,
2123,
60,
543,
63,
8506,
32,
36,
14,
11265,
358,
267,
291,
14,
629,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
horance-liu/tensorflow
|
tensorflow/python/ops/distributions/uniform.py
|
73
|
6818
|
# 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.
# ==============================================================================
"""The Uniform distribution class."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import math
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import ops
from tensorflow.python.framework import tensor_shape
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import check_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import random_ops
from tensorflow.python.ops.distributions import distribution
class Uniform(distribution.Distribution):
"""Uniform distribution with `low` and `high` parameters.
#### Mathematical Details
The probability density function (pdf) is,
```none
pdf(x; a, b) = I[a <= x < b] / Z
Z = b - a
```
where:
* `low = a`,
* `high = b`,
* `Z` is the normalizing constant, and,
* `I[predicate]` is the [indicator function](
https://en.wikipedia.org/wiki/Indicator_function) for `predicate`.
The parameters `low` and `high` must be shaped in a way that supports
broadcasting (e.g., `high - low` is a valid operation).
#### Examples
```python
# Without broadcasting:
u1 = Uniform(low=3.0, high=4.0) # a single uniform distribution [3, 4]
u2 = Uniform(low=[1.0, 2.0],
high=[3.0, 4.0]) # 2 distributions [1, 3], [2, 4]
u3 = Uniform(low=[[1.0, 2.0],
[3.0, 4.0]],
high=[[1.5, 2.5],
[3.5, 4.5]]) # 4 distributions
```
```python
# With broadcasting:
u1 = Uniform(low=3.0, high=[5.0, 6.0, 7.0]) # 3 distributions
```
"""
def __init__(self,
low=0.,
high=1.,
validate_args=False,
allow_nan_stats=True,
name="Uniform"):
"""Initialize a batch of Uniform distributions.
Args:
low: Floating point tensor, lower boundary of the output interval. Must
have `low < high`.
high: Floating point tensor, upper boundary of the output interval. Must
have `low < high`.
validate_args: Python `bool`, default `False`. When `True` distribution
parameters are checked for validity despite possibly degrading runtime
performance. When `False` invalid inputs may silently render incorrect
outputs.
allow_nan_stats: Python `bool`, default `True`. When `True`, statistics
(e.g., mean, mode, variance) use the value "`NaN`" to indicate the
result is undefined. When `False`, an exception is raised if one or
more of the statistic's batch members are undefined.
name: Python `str` name prefixed to Ops created by this class.
Raises:
InvalidArgumentError: if `low >= high` and `validate_args=False`.
"""
parameters = locals()
with ops.name_scope(name, values=[low, high]):
with ops.control_dependencies([
check_ops.assert_less(
low, high, message="uniform not defined when low >= high.")
] if validate_args else []):
self._low = array_ops.identity(low, name="low")
self._high = array_ops.identity(high, name="high")
check_ops.assert_same_float_dtype([self._low, self._high])
super(Uniform, self).__init__(
dtype=self._low.dtype,
reparameterization_type=distribution.FULLY_REPARAMETERIZED,
validate_args=validate_args,
allow_nan_stats=allow_nan_stats,
parameters=parameters,
graph_parents=[self._low,
self._high],
name=name)
@staticmethod
def _param_shapes(sample_shape):
return dict(
zip(("low", "high"),
([ops.convert_to_tensor(sample_shape, dtype=dtypes.int32)] * 2)))
@property
def low(self):
"""Lower boundary of the output interval."""
return self._low
@property
def high(self):
"""Upper boundary of the output interval."""
return self._high
def range(self, name="range"):
"""`high - low`."""
with self._name_scope(name):
return self.high - self.low
def _batch_shape_tensor(self):
return array_ops.broadcast_dynamic_shape(
array_ops.shape(self.low),
array_ops.shape(self.high))
def _batch_shape(self):
return array_ops.broadcast_static_shape(
self.low.get_shape(),
self.high.get_shape())
def _event_shape_tensor(self):
return constant_op.constant([], dtype=dtypes.int32)
def _event_shape(self):
return tensor_shape.scalar()
def _sample_n(self, n, seed=None):
shape = array_ops.concat([[n], self.batch_shape_tensor()], 0)
samples = random_ops.random_uniform(shape=shape,
dtype=self.dtype,
seed=seed)
return self.low + self.range() * samples
def _log_prob(self, x):
return math_ops.log(self._prob(x))
def _prob(self, x):
broadcasted_x = x * array_ops.ones(self.batch_shape_tensor())
return array_ops.where(
math_ops.is_nan(broadcasted_x),
broadcasted_x,
array_ops.where(
math_ops.logical_or(broadcasted_x < self.low,
broadcasted_x >= self.high),
array_ops.zeros_like(broadcasted_x),
array_ops.ones_like(broadcasted_x) / self.range()))
def _log_cdf(self, x):
return math_ops.log(self.cdf(x))
def _cdf(self, x):
broadcast_shape = array_ops.broadcast_dynamic_shape(
array_ops.shape(x), self.batch_shape_tensor())
zeros = array_ops.zeros(broadcast_shape, dtype=self.dtype)
ones = array_ops.ones(broadcast_shape, dtype=self.dtype)
broadcasted_x = x * ones
result_if_not_big = array_ops.where(
x < self.low, zeros, (broadcasted_x - self.low) / self.range())
return array_ops.where(x >= self.high, ones, result_if_not_big)
def _entropy(self):
return math_ops.log(self.range())
def _mean(self):
return (self.low + self.high) / 2.
def _variance(self):
return math_ops.square(self.range()) / 12.
def _stddev(self):
return self.range() / math.sqrt(12.)
|
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,
1918,
1910,
8241,
4084,
1021,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
3473,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1392,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1104,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2196,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
492,
4084,
421,
199,
533,
1910,
8241,
8,
4972,
14,
8580,
304,
523,
408,
12421,
4084,
543,
658,
674,
64,
436,
658,
6260,
64,
2633,
14,
819,
14055,
16593,
28491,
15621,
819,
710,
12224,
13650,
805,
334,
5607,
9,
365,
12,
819,
10841,
3592,
523,
11249,
8,
88,
27,
282,
12,
330,
9,
275,
473,
59,
65,
2695,
671,
665,
330,
61,
1182,
3107,
523,
3107,
275,
330,
446,
282,
523,
10841,
819,
2382,
26,
523,
627,
658,
674,
275,
282,
3559,
523,
627,
658,
6260,
275,
330,
3559,
523,
627,
658,
58,
64,
365,
314,
3293,
9147,
4413,
12,
436,
12,
523,
627,
658,
41,
59,
14463,
16090,
365,
314,
359,
15785,
805,
8738,
272,
4178,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
24000,
63,
1593,
9,
367,
658,
14463,
2313,
819,
710,
2633,
658,
674,
64,
436,
658,
6260,
64,
1471,
506,
2215,
68,
315,
282,
4340,
626,
5171,
523,
32001,
334,
69,
14,
71,
2020,
658,
6260,
446,
6465,
64,
365,
282,
1686,
3439,
680,
819,
14055,
6058,
819,
10841,
1548,
523,
327,
23952,
32001,
26,
523,
399,
17,
275,
1910,
8241,
8,
674,
29,
19,
14,
16,
12,
4721,
29,
20,
14,
16,
9,
221,
327,
282,
2849,
14818,
4084,
359,
19,
12,
841,
61,
523,
399,
18,
275,
1910,
8241,
8,
674,
1524,
17,
14,
16,
12,
499,
14,
16,
467,
2049,
4721,
1524,
19,
14,
16,
12,
841,
14,
16,
566,
221,
327,
499,
10208,
359,
17,
12,
650,
467,
359,
18,
12,
841,
61,
523,
399,
19,
275,
1910,
8241,
8,
674,
16025,
17,
14,
16,
12,
499,
14,
16,
467,
490,
359,
19,
14,
16,
12,
841,
14,
16,
2365,
2049,
4721,
16025,
17,
14,
21,
12,
499,
14,
21,
467,
2151,
359,
19,
14,
21,
12,
841,
14,
21,
3934,
221,
327,
841,
10208,
523,
10841,
819,
10841,
1548,
523,
327,
8777,
32001,
26,
523,
399,
17,
275,
1910,
8241,
8,
674,
29,
19,
14,
16,
12,
4721,
1524,
21,
14,
16,
12,
1227,
14,
16,
12,
1520,
14,
16,
566,
221,
327,
650,
10208,
523,
10841,
819,
408,
819,
347,
636,
826,
721,
277,
12,
2049,
6465,
29,
16,
2020,
2049,
4721,
29,
17,
2020,
2049,
4107,
63,
589,
29,
797,
12,
2049,
2040,
63,
4304,
63,
3200,
29,
549,
12,
2049,
536,
628,
12421,
2349,
272,
408,
9345,
282,
3522,
402,
1910,
8241,
10208,
14,
339,
3033,
26,
489,
6465,
26,
27729,
2376,
2345,
12,
5117,
8424,
402,
314,
1072,
6252,
14,
9498,
267,
1172,
658,
674,
665,
4721,
2313,
489,
4721,
26,
27729,
2376,
2345,
12,
7008,
8424,
402,
314,
1072,
6252,
14,
9498,
267,
1172,
658,
674,
665,
4721,
2313,
489,
4107,
63,
589,
26,
2018,
658,
2245,
3559,
849,
658,
797,
2313,
3979,
658,
549,
64,
4084,
267,
2633,
787,
7923,
367,
25667,
477,
681,
1175,
12570,
477,
16050,
8836,
267,
10238,
14,
3979,
658,
797,
64,
3866,
4153,
1443,
18030,
3795,
8927,
267,
4704,
14,
489,
2040,
63,
4304,
63,
3200,
26,
2018,
658,
2245,
3559,
849,
658,
549,
2313,
3979,
658,
549,
3559,
11076,
267,
334,
69,
14,
71,
2020,
4615,
12,
818,
12,
11773,
9,
675,
314,
574,
24505,
14300,
64,
2,
370,
6623,
314,
267,
754,
365,
10942,
14,
3979,
658,
797,
3559,
376,
1919,
365,
4915,
340,
1373,
503,
267,
1655,
402,
314,
22394,
1159,
3522,
7556,
787,
10942,
14,
489,
536,
26,
2018,
658,
495,
64,
536,
18239,
370,
593,
1190,
2737,
701,
642,
1021,
14,
339,
6218,
26,
489,
6378,
17042,
26,
340,
658,
674,
2356,
4721,
64,
436,
658,
3502,
63,
589,
29,
797,
2313,
272,
408,
272,
2633,
275,
9480,
342,
272,
543,
4156,
14,
354,
63,
2645,
8,
354,
12,
1338,
1524,
674,
12,
4721,
4682,
489,
543,
4156,
14,
2785,
63,
5714,
779,
881,
1104,
63,
1483,
14,
479,
63,
2003,
8,
1598,
6465,
12,
4721,
12,
1245,
628,
8830,
440,
3247,
1380,
6465,
2356,
4721,
2685,
489,
1622,
340,
4107,
63,
589,
587,
12319,
267,
291,
423,
674,
275,
1625,
63,
1483,
14,
5582,
8,
674,
12,
536,
628,
674,
531,
267,
291,
423,
6260,
275,
1625,
63,
1483,
14,
5582,
8,
6260,
12,
536,
628,
6260,
531,
267,
1104,
63,
1483,
14,
479,
63,
7191,
63,
1609,
63,
2271,
779,
277,
423,
674,
12,
291,
423,
6260,
566,
272,
1613,
8,
12421,
12,
291,
2843,
826,
721,
267,
2152,
29,
277,
423,
674,
14,
2271,
12,
267,
295,
8121,
6236,
13362,
63,
466,
29,
4972,
14,
14742,
57
] |
[
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,
1918,
1910,
8241,
4084,
1021,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
3473,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1392,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1104,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2196,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
492,
4084,
421,
199,
533,
1910,
8241,
8,
4972,
14,
8580,
304,
523,
408,
12421,
4084,
543,
658,
674,
64,
436,
658,
6260,
64,
2633,
14,
819,
14055,
16593,
28491,
15621,
819,
710,
12224,
13650,
805,
334,
5607,
9,
365,
12,
819,
10841,
3592,
523,
11249,
8,
88,
27,
282,
12,
330,
9,
275,
473,
59,
65,
2695,
671,
665,
330,
61,
1182,
3107,
523,
3107,
275,
330,
446,
282,
523,
10841,
819,
2382,
26,
523,
627,
658,
674,
275,
282,
3559,
523,
627,
658,
6260,
275,
330,
3559,
523,
627,
658,
58,
64,
365,
314,
3293,
9147,
4413,
12,
436,
12,
523,
627,
658,
41,
59,
14463,
16090,
365,
314,
359,
15785,
805,
8738,
272,
4178,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
24000,
63,
1593,
9,
367,
658,
14463,
2313,
819,
710,
2633,
658,
674,
64,
436,
658,
6260,
64,
1471,
506,
2215,
68,
315,
282,
4340,
626,
5171,
523,
32001,
334,
69,
14,
71,
2020,
658,
6260,
446,
6465,
64,
365,
282,
1686,
3439,
680,
819,
14055,
6058,
819,
10841,
1548,
523,
327,
23952,
32001,
26,
523,
399,
17,
275,
1910,
8241,
8,
674,
29,
19,
14,
16,
12,
4721,
29,
20,
14,
16,
9,
221,
327,
282,
2849,
14818,
4084,
359,
19,
12,
841,
61,
523,
399,
18,
275,
1910,
8241,
8,
674,
1524,
17,
14,
16,
12,
499,
14,
16,
467,
2049,
4721,
1524,
19,
14,
16,
12,
841,
14,
16,
566,
221,
327,
499,
10208,
359,
17,
12,
650,
467,
359,
18,
12,
841,
61,
523,
399,
19,
275,
1910,
8241,
8,
674,
16025,
17,
14,
16,
12,
499,
14,
16,
467,
490,
359,
19,
14,
16,
12,
841,
14,
16,
2365,
2049,
4721,
16025,
17,
14,
21,
12,
499,
14,
21,
467,
2151,
359,
19,
14,
21,
12,
841,
14,
21,
3934,
221,
327,
841,
10208,
523,
10841,
819,
10841,
1548,
523,
327,
8777,
32001,
26,
523,
399,
17,
275,
1910,
8241,
8,
674,
29,
19,
14,
16,
12,
4721,
1524,
21,
14,
16,
12,
1227,
14,
16,
12,
1520,
14,
16,
566,
221,
327,
650,
10208,
523,
10841,
819,
408,
819,
347,
636,
826,
721,
277,
12,
2049,
6465,
29,
16,
2020,
2049,
4721,
29,
17,
2020,
2049,
4107,
63,
589,
29,
797,
12,
2049,
2040,
63,
4304,
63,
3200,
29,
549,
12,
2049,
536,
628,
12421,
2349,
272,
408,
9345,
282,
3522,
402,
1910,
8241,
10208,
14,
339,
3033,
26,
489,
6465,
26,
27729,
2376,
2345,
12,
5117,
8424,
402,
314,
1072,
6252,
14,
9498,
267,
1172,
658,
674,
665,
4721,
2313,
489,
4721,
26,
27729,
2376,
2345,
12,
7008,
8424,
402,
314,
1072,
6252,
14,
9498,
267,
1172,
658,
674,
665,
4721,
2313,
489,
4107,
63,
589,
26,
2018,
658,
2245,
3559,
849,
658,
797,
2313,
3979,
658,
549,
64,
4084,
267,
2633,
787,
7923,
367,
25667,
477,
681,
1175,
12570,
477,
16050,
8836,
267,
10238,
14,
3979,
658,
797,
64,
3866,
4153,
1443,
18030,
3795,
8927,
267,
4704,
14,
489,
2040,
63,
4304,
63,
3200,
26,
2018,
658,
2245,
3559,
849,
658,
549,
2313,
3979,
658,
549,
3559,
11076,
267,
334,
69,
14,
71,
2020,
4615,
12,
818,
12,
11773,
9,
675,
314,
574,
24505,
14300,
64,
2,
370,
6623,
314,
267,
754,
365,
10942,
14,
3979,
658,
797,
3559,
376,
1919,
365,
4915,
340,
1373,
503,
267,
1655,
402,
314,
22394,
1159,
3522,
7556,
787,
10942,
14,
489,
536,
26,
2018,
658,
495,
64,
536,
18239,
370,
593,
1190,
2737,
701,
642,
1021,
14,
339,
6218,
26,
489,
6378,
17042,
26,
340,
658,
674,
2356,
4721,
64,
436,
658,
3502,
63,
589,
29,
797,
2313,
272,
408,
272,
2633,
275,
9480,
342,
272,
543,
4156,
14,
354,
63,
2645,
8,
354,
12,
1338,
1524,
674,
12,
4721,
4682,
489,
543,
4156,
14,
2785,
63,
5714,
779,
881,
1104,
63,
1483,
14,
479,
63,
2003,
8,
1598,
6465,
12,
4721,
12,
1245,
628,
8830,
440,
3247,
1380,
6465,
2356,
4721,
2685,
489,
1622,
340,
4107,
63,
589,
587,
12319,
267,
291,
423,
674,
275,
1625,
63,
1483,
14,
5582,
8,
674,
12,
536,
628,
674,
531,
267,
291,
423,
6260,
275,
1625,
63,
1483,
14,
5582,
8,
6260,
12,
536,
628,
6260,
531,
267,
1104,
63,
1483,
14,
479,
63,
7191,
63,
1609,
63,
2271,
779,
277,
423,
674,
12,
291,
423,
6260,
566,
272,
1613,
8,
12421,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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
] |
equitania/myodoo-addons-v10
|
eq_project/models/__init__.py
|
1
|
1068
|
# -*- coding: utf-8 -*-
##############################################################################
#
# Odoo Addon, Open Source Management Solution
# Copyright (C) 2014-now Equitania Software GmbH(<http://www.equitania.de>).
#
# 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 eq_project_extension
import eq_extension_project_task_type
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
28935,
29366,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
6927,
13,
2131,
662,
10589,
290,
4674,
2290,
23428,
27530,
1014,
921,
1544,
14,
69,
10589,
290,
4674,
14,
271,
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,
646,
3850,
63,
1715,
63,
3435,
199,
646,
3850,
63,
3435,
63,
1715,
63,
1765,
63,
466,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
28935,
29366,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
6927,
13,
2131,
662,
10589,
290,
4674,
2290,
23428,
27530,
1014,
921,
1544,
14,
69,
10589,
290,
4674,
14,
271,
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,
646,
3850,
63,
1715,
63,
3435,
199,
646,
3850,
63,
3435,
63,
1715,
63,
1765,
63,
466,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mavit/ansible
|
lib/ansible/modules/storage/netapp/netapp_e_syslog.py
|
25
|
10538
|
#!/usr/bin/python
# (c) 2018, NetApp, Inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = """
---
module: netapp_e_syslog
short_description: NetApp E-Series manage syslog settings
description:
- Allow the syslog settings to be configured for an individual E-Series storage-system
version_added: '2.7'
author: Nathan Swartz (@ndswartz)
extends_documentation_fragment:
- netapp.eseries
options:
state:
description:
- Add or remove the syslog server configuration for E-Series storage array.
- Existing syslog server configuration will be removed or updated when its address matches I(address).
- Fully qualified hostname that resolve to an IPv4 address that matches I(address) will not be
treated as a match.
choices:
- present
- absent
default: present
address:
description:
- The syslog server's IPv4 address or a fully qualified hostname.
- All existing syslog configurations will be removed when I(state=absent) and I(address=None).
port:
description:
- This is the port the syslog server is using.
default: 514
protocol:
description:
- This is the transmission protocol the syslog server's using to receive syslog messages.
choices:
- udp
- tcp
- tls
default: udp
components:
description:
- The e-series logging components define the specific logs to transfer to the syslog server.
- At the time of writing, 'auditLog' is the only logging component but more may become available.
default: ["auditLog"]
test:
description:
- This forces a test syslog message to be sent to the stated syslog server.
- Only attempts transmission when I(state=present).
type: bool
default: no
log_path:
description:
- This argument specifies a local path for logging purposes.
required: no
notes:
- Check mode is supported.
- This API is currently only supported with the Embedded Web Services API v2.12 (bundled with
SANtricity OS 11.40.2) and higher.
"""
EXAMPLES = """
- name: Add two syslog server configurations to NetApp E-Series storage array.
netapp_e_syslog:
state: present
address: "{{ item }}"
port: 514
protocol: tcp
component: "auditLog"
api_url: "10.1.1.1:8443"
api_username: "admin"
api_password: "myPass"
loop:
- "192.168.1.1"
- "192.168.1.100"
"""
RETURN = """
msg:
description: Success message
returned: on success
type: string
sample: The settings have been updated.
syslog:
description:
- True if syslog server configuration has been added to e-series storage array.
returned: on success
sample: True
type: bool
"""
import json
import logging
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netapp import request, eseries_host_argument_spec
from ansible.module_utils._text import to_native
HEADERS = {
"Content-Type": "application/json",
"Accept": "application/json",
}
class Syslog(object):
def __init__(self):
argument_spec = eseries_host_argument_spec()
argument_spec.update(dict(
state=dict(choices=["present", "absent"], required=False, default="present"),
address=dict(type="str", required=False),
port=dict(type="int", default=514, required=False),
protocol=dict(choices=["tcp", "tls", "udp"], default="udp", required=False),
components=dict(type="list", required=False, default=["auditLog"]),
test=dict(type="bool", default=False, require=False),
log_path=dict(type="str", required=False),
))
required_if = [
["state", "present", ["address", "port", "protocol", "components"]],
]
mutually_exclusive = [
["test", "absent"],
]
self.module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, required_if=required_if,
mutually_exclusive=mutually_exclusive)
args = self.module.params
self.syslog = args["state"] in ["present"]
self.address = args["address"]
self.port = args["port"]
self.protocol = args["protocol"]
self.components = args["components"]
self.test = args["test"]
self.ssid = args["ssid"]
self.url = args["api_url"]
self.creds = dict(url_password=args["api_password"],
validate_certs=args["validate_certs"],
url_username=args["api_username"], )
self.components.sort()
self.check_mode = self.module.check_mode
# logging setup
log_path = args["log_path"]
self._logger = logging.getLogger(self.__class__.__name__)
if log_path:
logging.basicConfig(
level=logging.DEBUG, filename=log_path, filemode='w',
format='%(relativeCreated)dms %(levelname)s %(module)s.%(funcName)s:%(lineno)d\n %(message)s')
if not self.url.endswith('/'):
self.url += '/'
def get_configuration(self):
"""Retrieve existing syslog configuration."""
try:
(rc, result) = request(self.url + "storage-systems/{0}/syslog".format(self.ssid),
headers=HEADERS, **self.creds)
return result
except Exception as err:
self.module.fail_json(msg="Failed to retrieve syslog configuration! Array Id [%s]. Error [%s]."
% (self.ssid, to_native(err)))
def test_configuration(self, body):
"""Send test syslog message to the storage array.
Allows fix number of retries to occur before failure is issued to give the storage array time to create
new syslog server record.
"""
try:
(rc, result) = request(self.url + "storage-systems/{0}/syslog/{1}/test".format(self.ssid, body["id"]),
method='POST', headers=HEADERS, **self.creds)
except Exception as err:
self.module.fail_json(
msg="We failed to send test message! Array Id [{0}]. Error [{1}].".format(self.ssid, to_native(err)))
def update_configuration(self):
"""Post the syslog request to array."""
config_match = None
perfect_match = None
update = False
body = dict()
# search existing configuration for syslog server entry match
configs = self.get_configuration()
if self.address:
for config in configs:
if config["serverAddress"] == self.address:
config_match = config
if (config["port"] == self.port and config["protocol"] == self.protocol and
len(config["components"]) == len(self.components) and
all([component["type"] in self.components for component in config["components"]])):
perfect_match = config_match
break
# generate body for the http request
if self.syslog:
if not perfect_match:
update = True
if config_match:
body.update(dict(id=config_match["id"]))
components = [dict(type=component_type) for component_type in self.components]
body.update(dict(serverAddress=self.address, port=self.port,
protocol=self.protocol, components=components))
self._logger.info(body)
self.make_configuration_request(body)
# remove specific syslog server configuration
elif self.address:
update = True
body.update(dict(id=config_match["id"]))
self._logger.info(body)
self.make_configuration_request(body)
# if no address is specified, remove all syslog server configurations
elif configs:
update = True
for config in configs:
body.update(dict(id=config["id"]))
self._logger.info(body)
self.make_configuration_request(body)
return update
def make_configuration_request(self, body):
# make http request(s)
if not self.check_mode:
try:
if self.syslog:
if "id" in body:
(rc, result) = request(
self.url + "storage-systems/{0}/syslog/{1}".format(self.ssid, body["id"]),
method='POST', data=json.dumps(body), headers=HEADERS, **self.creds)
else:
(rc, result) = request(self.url + "storage-systems/{0}/syslog".format(self.ssid),
method='POST', data=json.dumps(body), headers=HEADERS, **self.creds)
body.update(result)
# send syslog test message
if self.test:
self.test_configuration(body)
elif "id" in body:
(rc, result) = request(self.url + "storage-systems/{0}/syslog/{1}".format(self.ssid, body["id"]),
method='DELETE', headers=HEADERS, **self.creds)
# This is going to catch cases like a connection failure
except Exception as err:
self.module.fail_json(msg="We failed to modify syslog configuration! Array Id [%s]. Error [%s]."
% (self.ssid, to_native(err)))
def update(self):
"""Update configuration and respond to ansible."""
update = self.update_configuration()
self.module.exit_json(msg="The syslog settings have been updated.", changed=update)
def __call__(self, *args, **kwargs):
self.update()
def main():
settings = Syslog()
settings()
if __name__ == "__main__":
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
334,
67,
9,
14894,
12,
28076,
12,
3277,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
363,
6577,
363,
275,
730,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
15742,
63,
69,
63,
16878,
199,
3612,
63,
1802,
26,
28076,
662,
13,
9641,
9635,
22112,
2202,
199,
1802,
26,
272,
446,
9812,
314,
22112,
2202,
370,
506,
7526,
367,
376,
8212,
662,
13,
9641,
4887,
13,
2253,
199,
1023,
63,
3270,
26,
283,
18,
14,
23,
7,
199,
2502,
26,
653,
1619,
290,
16666,
28124,
8593,
78,
795,
87,
28124,
9,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
15742,
14,
69,
5602,
199,
1419,
26,
272,
1174,
26,
267,
1369,
26,
288,
446,
2654,
503,
2813,
314,
22112,
1654,
2897,
367,
662,
13,
9641,
4887,
1625,
14,
288,
446,
1316,
26958,
22112,
1654,
2897,
911,
506,
4829,
503,
4588,
1380,
2399,
2287,
4450,
473,
8,
1562,
680,
288,
446,
481,
8525,
12313,
6246,
626,
7512,
370,
376,
6509,
20,
2287,
626,
4450,
473,
8,
1562,
9,
911,
440,
506,
1598,
10184,
465,
282,
1336,
14,
267,
3415,
26,
288,
446,
3451,
288,
446,
9552,
267,
849,
26,
3451,
272,
2287,
26,
267,
1369,
26,
288,
446,
710,
22112,
1654,
1159,
6509,
20,
2287,
503,
282,
9999,
12313,
6246,
14,
288,
446,
2900,
3411,
22112,
13422,
911,
506,
4829,
1380,
473,
8,
929,
29,
5575,
9,
436,
473,
8,
1562,
29,
403,
680,
272,
1844,
26,
267,
1369,
26,
288,
446,
961,
365,
314,
1844,
314,
22112,
1654,
365,
1808,
14,
267,
849,
26,
959,
1079,
272,
4113,
26,
267,
1369,
26,
288,
446,
961,
365,
314,
1752,
2250,
4113,
314,
22112,
1654,
1159,
1808,
370,
9128,
22112,
3788,
14,
267,
3415,
26,
288,
446,
18419,
288,
446,
14719,
288,
446,
15142,
267,
849,
26,
18419,
272,
7323,
26,
267,
1369,
26,
288,
446,
710,
325,
13,
5602,
2050,
7323,
5627,
314,
2488,
9610,
370,
9307,
370,
314,
22112,
1654,
14,
288,
446,
2854,
314,
900,
402,
3575,
12,
283,
14274,
2445,
7,
365,
314,
1454,
2050,
3931,
1325,
1655,
1443,
8649,
2808,
14,
267,
849,
26,
2097,
14274,
2445,
937,
272,
511,
26,
267,
1369,
26,
288,
446,
961,
25983,
282,
511,
22112,
1245,
370,
506,
4847,
370,
314,
410,
972,
22112,
1654,
14,
288,
446,
5972,
12454,
1752,
2250,
1380,
473,
8,
929,
29,
1881,
680,
267,
730,
26,
2155,
267,
849,
26,
949,
272,
943,
63,
515,
26,
267,
1369,
26,
288,
446,
961,
1423,
9314,
282,
2257,
931,
367,
2050,
12901,
14,
267,
1415,
26,
949,
199,
5983,
26,
272,
446,
2670,
818,
365,
3748,
14,
272,
446,
961,
3261,
365,
5544,
1454,
3748,
543,
314,
24297,
770,
6001,
21813,
3261,
373,
18,
14,
713,
334,
66,
725,
1146,
543,
489,
428,
879,
599,
3690,
4403,
4119,
14,
2167,
14,
18,
9,
436,
10948,
14,
199,
624,
199,
199,
8918,
275,
408,
272,
446,
536,
26,
2654,
2877,
22112,
1654,
13422,
370,
28076,
662,
13,
9641,
4887,
1625,
14,
489,
15742,
63,
69,
63,
16878,
26,
267,
1174,
26,
3451,
267,
2287,
26,
7370,
1242,
7820,
267,
1844,
26,
959,
1079,
267,
4113,
26,
14719,
267,
3931,
26,
298,
14274,
2445,
2,
267,
2986,
63,
633,
26,
298,
709,
14,
17,
14,
17,
14,
17,
26,
1349,
2824,
2,
267,
2986,
63,
2473,
26,
298,
2113,
2,
267,
2986,
63,
2060,
26,
298,
1662,
4986,
2,
489,
4438,
26,
267,
446,
298,
5756,
14,
6568,
14,
17,
14,
17,
2,
267,
446,
298,
5756,
14,
6568,
14,
17,
14,
1960,
2,
199,
624,
199,
199,
9677,
275,
408,
199,
1328,
26,
272,
1369,
26,
22318,
1245,
272,
2138,
26,
641,
3182,
272,
730,
26,
1059,
272,
2690,
26,
710,
2202,
1172,
2757,
4588,
14,
199,
16878,
26,
272,
1369,
26,
267,
446,
715,
340,
22112,
1654,
2897,
965,
2757,
3483,
370,
325,
13,
5602,
4887,
1625,
14,
272,
2138,
26,
641,
3182,
272,
2690,
26,
715,
272,
730,
26,
2155,
199,
624,
199,
199,
646,
2022,
199,
646,
2050,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
25830,
492,
1056,
12,
325,
5602,
63,
1102,
63,
2094,
63,
1650,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
6106,
199,
199,
21178,
275,
469,
272,
298,
2714,
13,
804,
582,
298,
3578,
15,
1001,
401,
272,
298,
8422,
582,
298,
3578,
15,
1001,
401,
199,
93,
421,
199,
533,
28766,
793,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1423,
63,
1650,
275,
325,
5602,
63,
1102,
63,
2094,
63,
1650,
342,
267,
1423,
63,
1650,
14,
873,
8,
807,
8,
288,
1174,
29,
807,
8,
4577,
6270,
1881,
401,
298,
5575,
2255,
1415,
29,
797,
12,
849,
628,
1881,
1288,
288,
2287,
29,
807,
8,
466,
628,
495,
401,
1415,
29,
797,
395,
288,
1844,
29,
807,
8,
466,
628,
442,
401,
849,
29,
24098,
12,
1415,
29,
797,
395,
288,
4113,
29,
807,
8,
4577,
6270,
8815,
401,
298,
9945,
401,
298,
15036,
2255,
849,
628,
15036,
401,
1415,
29,
797,
395,
288,
7323,
29,
807,
8,
466,
628,
513,
401,
1415,
29,
797,
12,
849,
6270,
14274,
2445,
10252,
288,
511,
29,
807,
8,
466,
628,
2245,
401,
849,
29,
797,
12,
4409,
29,
797,
395,
288,
943,
63,
515,
29,
807,
8,
466,
628,
495,
401,
1415,
29,
797,
395,
267,
5082,
398,
1415,
63,
692,
275,
359,
288,
2097,
929,
401,
298,
1881,
401,
2097,
1562,
401,
298,
719,
401,
298,
3922,
401,
298,
4608,
18396,
267,
1622,
398,
16108,
63,
12730,
275,
359,
288,
2097,
396,
401,
298,
5575
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
334,
67,
9,
14894,
12,
28076,
12,
3277,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
363,
6577,
363,
275,
730,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
15742,
63,
69,
63,
16878,
199,
3612,
63,
1802,
26,
28076,
662,
13,
9641,
9635,
22112,
2202,
199,
1802,
26,
272,
446,
9812,
314,
22112,
2202,
370,
506,
7526,
367,
376,
8212,
662,
13,
9641,
4887,
13,
2253,
199,
1023,
63,
3270,
26,
283,
18,
14,
23,
7,
199,
2502,
26,
653,
1619,
290,
16666,
28124,
8593,
78,
795,
87,
28124,
9,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
15742,
14,
69,
5602,
199,
1419,
26,
272,
1174,
26,
267,
1369,
26,
288,
446,
2654,
503,
2813,
314,
22112,
1654,
2897,
367,
662,
13,
9641,
4887,
1625,
14,
288,
446,
1316,
26958,
22112,
1654,
2897,
911,
506,
4829,
503,
4588,
1380,
2399,
2287,
4450,
473,
8,
1562,
680,
288,
446,
481,
8525,
12313,
6246,
626,
7512,
370,
376,
6509,
20,
2287,
626,
4450,
473,
8,
1562,
9,
911,
440,
506,
1598,
10184,
465,
282,
1336,
14,
267,
3415,
26,
288,
446,
3451,
288,
446,
9552,
267,
849,
26,
3451,
272,
2287,
26,
267,
1369,
26,
288,
446,
710,
22112,
1654,
1159,
6509,
20,
2287,
503,
282,
9999,
12313,
6246,
14,
288,
446,
2900,
3411,
22112,
13422,
911,
506,
4829,
1380,
473,
8,
929,
29,
5575,
9,
436,
473,
8,
1562,
29,
403,
680,
272,
1844,
26,
267,
1369,
26,
288,
446,
961,
365,
314,
1844,
314,
22112,
1654,
365,
1808,
14,
267,
849,
26,
959,
1079,
272,
4113,
26,
267,
1369,
26,
288,
446,
961,
365,
314,
1752,
2250,
4113,
314,
22112,
1654,
1159,
1808,
370,
9128,
22112,
3788,
14,
267,
3415,
26,
288,
446,
18419,
288,
446,
14719,
288,
446,
15142,
267,
849,
26,
18419,
272,
7323,
26,
267,
1369,
26,
288,
446,
710,
325,
13,
5602,
2050,
7323,
5627,
314,
2488,
9610,
370,
9307,
370,
314,
22112,
1654,
14,
288,
446,
2854,
314,
900,
402,
3575,
12,
283,
14274,
2445,
7,
365,
314,
1454,
2050,
3931,
1325,
1655,
1443,
8649,
2808,
14,
267,
849,
26,
2097,
14274,
2445,
937,
272,
511,
26,
267,
1369,
26,
288,
446,
961,
25983,
282,
511,
22112,
1245,
370,
506,
4847,
370,
314,
410,
972,
22112,
1654,
14,
288,
446,
5972,
12454,
1752,
2250,
1380,
473,
8,
929,
29,
1881,
680,
267,
730,
26,
2155,
267,
849,
26,
949,
272,
943,
63,
515,
26,
267,
1369,
26,
288,
446,
961,
1423,
9314,
282,
2257,
931,
367,
2050,
12901,
14,
267,
1415,
26,
949,
199,
5983,
26,
272,
446,
2670,
818,
365,
3748,
14,
272,
446,
961,
3261,
365,
5544,
1454,
3748,
543,
314,
24297,
770,
6001,
21813,
3261,
373,
18,
14,
713,
334,
66,
725,
1146,
543,
489,
428,
879,
599,
3690,
4403,
4119,
14,
2167,
14,
18,
9,
436,
10948,
14,
199,
624,
199,
199,
8918,
275,
408,
272,
446,
536,
26,
2654,
2877,
22112,
1654,
13422,
370,
28076,
662,
13,
9641,
4887,
1625,
14,
489,
15742,
63,
69,
63,
16878,
26,
267,
1174,
26,
3451,
267,
2287,
26,
7370,
1242,
7820,
267,
1844,
26,
959,
1079,
267,
4113,
26,
14719,
267,
3931,
26,
298,
14274,
2445,
2,
267,
2986,
63,
633,
26,
298,
709,
14,
17,
14,
17,
14,
17,
26,
1349,
2824,
2,
267,
2986,
63,
2473,
26,
298,
2113,
2,
267,
2986,
63,
2060,
26,
298,
1662,
4986,
2,
489,
4438,
26,
267,
446,
298,
5756,
14,
6568,
14,
17,
14,
17,
2,
267,
446,
298,
5756,
14,
6568,
14,
17,
14,
1960,
2,
199,
624,
199,
199,
9677,
275,
408,
199,
1328,
26,
272,
1369,
26,
22318,
1245,
272,
2138,
26,
641,
3182,
272,
730,
26,
1059,
272,
2690,
26,
710,
2202,
1172,
2757,
4588,
14,
199,
16878,
26,
272,
1369,
26,
267,
446,
715,
340,
22112,
1654,
2897,
965,
2757,
3483,
370,
325,
13,
5602,
4887,
1625,
14,
272,
2138,
26,
641,
3182,
272,
2690,
26,
715,
272,
730,
26,
2155,
199,
624,
199,
199,
646,
2022,
199,
646,
2050,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
25830,
492,
1056,
12,
325,
5602,
63,
1102,
63,
2094,
63,
1650,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
6106,
199,
199,
21178,
275,
469,
272,
298,
2714,
13,
804,
582,
298,
3578,
15,
1001,
401,
272,
298,
8422,
582,
298,
3578,
15,
1001,
401,
199,
93,
421,
199,
533,
28766,
793,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1423,
63,
1650,
275,
325,
5602,
63,
1102,
63,
2094,
63,
1650,
342,
267,
1423,
63,
1650,
14,
873,
8,
807,
8,
288,
1174,
29,
807,
8,
4577,
6270,
1881,
401,
298,
5575,
2255,
1415,
29,
797,
12,
849,
628,
1881,
1288,
288,
2287,
29,
807,
8,
466,
628,
495,
401,
1415,
29,
797,
395,
288,
1844,
29,
807,
8,
466,
628,
442,
401,
849,
29,
24098,
12,
1415,
29,
797,
395,
288,
4113,
29,
807,
8,
4577,
6270,
8815,
401,
298,
9945,
401,
298,
15036,
2255,
849,
628,
15036,
401,
1415,
29,
797,
395,
288,
7323,
29,
807,
8,
466,
628,
513,
401,
1415,
29,
797,
12,
849,
6270,
14274,
2445,
10252,
288,
511,
29,
807,
8,
466,
628,
2245,
401,
849,
29,
797,
12,
4409,
29,
797,
395,
288,
943,
63,
515,
29,
807,
8,
466,
628,
495,
401,
1415,
29,
797,
395,
267,
5082,
398,
1415,
63,
692,
275,
359,
288,
2097,
929,
401,
298,
1881,
401,
2097,
1562,
401,
298,
719,
401,
298,
3922,
401,
298,
4608,
18396,
267,
1622,
398,
16108,
63,
12730,
275,
359,
288,
2097,
396,
401,
298,
5575,
0
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,
1
] |
borevitzlab/Gigavision
|
libs/SysUtil.py
|
2
|
24107
|
import subprocess
import random, string, os, socket, json, time
from glob import glob
from urllib import request
import threading
import configparser
import yaml
import logging
import logging.config
import fcntl
import datetime
USBDEVFS_RESET = 21780
try:
logging.config.fileConfig("logging.ini")
except:
pass
def sizeof_fmt(num, suffix='B'):
for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
if abs(num) < 1024.0:
return "%3.1f%s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f%s%s" % (num, 'Yi', suffix)
default_config = """
[DEFAULT]
exposure = 0
enabled = on
resize = on
[camera]
name =
enabled = on
[ftp]
enabled = on
replace = on
resize = on
timestamped = on
server = sftp.traitcapture.org
directory = /
username = picam
password = DEFAULT_PASSWORD
[timelapse]
interval = 300
starttime = 00:00
stoptime = 23:59
[localfiles]
spooling_dir =
upload_dir =
"""
default_light_config = """
[light]
max_power = 1000
min_power = 0
wavelengths = "400nm,420nm,450nm,530nm,630nm,660nm,735nm"
csv_keys = "LED1,LED2,LED3,LED4,LED5,LED6,LED7"
file_path = "lights_byserial/{identifier}.scf"
[telnet]
telnet_host = "192.168.2.124"
telnet_port = 50630
set_all_command = setall {power}
set_wavelength_command = setwlrelpower {wavelength} {power}
set_all_wavelength_command = setwlsrelpower {} {} {} {} {} {} {}
get_wavelength_command = getwlrelpower {wavelength}
[url]
url_host = "192.168.2.124"
control_uri = /cgi-bin/userI.cgi
set_all_command = "setAllTo": {percent}, "setAllSub": "set"
set_all_wavelength_command = "wl1":{}, "wl2":{}, "wl3":{}, "wl4":{}, "wl5":{}, "wl6":{}, "wl7":{}
"""
class SysUtil(object):
"""
System utility class.
Helper class to cache various things like the hostname, machine-id, amount of space in the filesystem.
"""
_ip_address = "0.0.0.0", 0
_external_ip = "0.0.0.0", 0
_machine_id = "", 0
_hostname = "HOSTNAME", 0
_tor_host = ("unknown.onion", "not a real key", "not a real client"), 0
_version = "Unknown spc-eyepi version", 0
a_statvfs = os.statvfs("/")
_fs = (a_statvfs.f_frsize * a_statvfs.f_bavail, a_statvfs.f_frsize * a_statvfs.f_blocks), 0
_watches = list()
thread = None
stop = False
logger = logging.getLogger("SysUtil")
def __init__(self):
if SysUtil.thread is None:
SysUtil.thread = threading.Thread(target=self._thread)
SysUtil.thread.start()
pass
@staticmethod
def reset_usb_device(bus: int, dev: int) -> bool:
"""
resets a usb device.
:param bus: bus number
:type bus: int
:param dev: device number of the device on the bus above
:type dev: int
"""
try:
fn = "/dev/bus/usb/{bus:03d}/{dev:03d}".format(bus=bus, dev=dev)
with open(fn, 'w', os.O_WRONLY) as f:
fcntl.ioctl(f, USBDEVFS_RESET, 0)
return True
except Exception as e:
SysUtil.logger.error("Couldnt reset usb device (possible filenotfound): {}".format(str(e)))
@staticmethod
def default_identifier(prefix=None):
"""
returns an identifier, If no prefix available, generates something.
:param prefix:
:return: string of the itentifier.
:rtype: str
"""
if prefix:
return SysUtil.get_identifier_from_name(prefix)
else:
from hashlib import md5
serialnumber = ("AUTO_" + md5(bytes(prefix, 'utf-8')).hexdigest()[len("AUTO_"):])[:32]
SysUtil.logger.warning("using autogenerated serialnumber {}".format(serialnumber))
return serialnumber
@staticmethod
def _nested_lookup(key, document):
"""
nested document lookup,
works on dicts and lists
:param key: string of key to lookup
:param document: dict or list to lookup
:return: yields item
"""
if isinstance(document, list):
for d in document:
for result in SysUtil._nested_lookup(key, d):
yield result
if isinstance(document, dict):
for k, v in document.items():
if k == key:
yield v
elif isinstance(v, dict):
for result in SysUtil._nested_lookup(key, v):
yield result
elif isinstance(v, list):
for d in v:
for result in SysUtil._nested_lookup(key, d):
yield result
@staticmethod
def sizeof_fmt(num, suffix='B')->str:
"""
formats a number of bytes in to a human readable string.
returns in SI units
eg sizeof_fmt(1234) returns '1.2KiB'
:param num: number of bytes to format
:param suffix: the suffix to use
:return: human formattted string.
:rtype: str
"""
for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
if abs(num) < 1024.0:
return "%3.1f%s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f%s%s" % (num, 'Yi', suffix)
@classmethod
def update_from_git(cls):
"""
updates spc-eyepi from git.
"""
os.system("git fetch --all;git reset --hard origin/master")
os.system("systemctl restart spc-eyepi_capture.service")
@classmethod
def get_hostname(cls)->str:
"""
gets the current hostname.
if there is no /etc/hostname file, sets the hostname randomly.
:return: the current hostname or the hostname it was set to
:rtype: str
"""
if abs(cls._hostname[-1] - time.time()) > 10:
if not os.path.isfile("/etc/hostname"):
hostname = "".join(random.choice(string.ascii_letters) for _ in range(8))
os.system("hostname {}".format(cls._hostname))
else:
with open("/etc/hostname", "r") as fn:
hostname = fn.read().strip()
cls._hostname = hostname, time.time()
return cls._hostname[0]
@classmethod
def set_hostname(cls, hostname: str):
"""
sets the machines hosname, in /etc/hosts and /etc/hostname
:param hostname: the string of which to set the hostname to.
"""
try:
with open(os.path.join("/etc/", "hostname"), 'w') as f:
f.write(hostname + "\n")
with open(os.path.join("/etc/", "hosts"), 'w') as hosts_file:
h_tmpl = "127.0.0.1\tlocalhost.localdomain localhost {hostname}\n"
h_tmpl += "::1\tlocalhost.localdomain localhost {hostname}\n"
hosts_file.write(h_tmpl.format(hostname=hostname))
except Exception as e:
cls.logger.error("Failed setting hostname for machine. {}".format(str(e)))
@classmethod
def get_machineid(cls)->str:
"""
gets the machine id, or initialises the machine id if it doesnt exist.
:return: string of the machine-id
:rtype: str
"""
if abs(cls._machine_id[-1] - time.time()) > 10:
if not os.path.isfile("/etc/machine-id"):
os.system("systemd-machine-id-setup")
with open("/etc/machine-id") as f:
cls._machine_id = f.read().strip(), time.time()
return cls._machine_id[0]
@classmethod
def get_tor_host(cls)->tuple:
"""
gets a tuple of the current tor host.
:return: tuple of hostname(onion address), client key, client name
:rtype: tuple[str, str, str]
"""
if abs(cls._tor_host[-1] - time.time()) > 10:
try:
with open("/home/tor_private/hostname") as f:
onion_address = f.read().replace('\n', '')
cls._tor_host = onion_address.split(" ")[:3], time.time()
except:
cls._tor_host = ("unknown", 'unknown', "unknown"), time.time()
return cls._tor_host[0]
@classmethod
def get_fs_space(cls)->tuple:
"""
returns free/total space of root filesystem as bytes(?)
:return: tuple of free/total space
:rtype: tuple[int, int]
"""
if abs(cls._fs[-1] - time.time()) > 10:
try:
a_statvfs = os.statvfs("/")
cls._fs = (
a_statvfs.f_frsize * a_statvfs.f_bavail, a_statvfs.f_frsize * a_statvfs.f_blocks), time.time()
except:
cls._fs = (0, 0), time.time()
return cls._fs[0]
@classmethod
def get_fs_space_mb(cls)->tuple:
"""
returns the filesystems free space in mebibytes.
see :func:`get_fs_space`
:return: tuple of free/total space
:rtype:tuple[int, int]
"""
free_space, total_space = SysUtil.get_fs_space()
for x in range(0, 2):
free_space /= 1024.0
total_space /= 1024.0
return free_space, total_space
@classmethod
def get_version(cls)->str:
"""
gets the "describe" version of the current git repo as a string.
:return: the current version
:rtype: str
"""
if abs(cls._version[-1] - time.time()) > 10:
try:
cmd = "/usr/bin/git describe --always"
cls._version = subprocess.check_output([cmd], shell=True).decode().strip("\n"), time.time()
except:
cls._version = "unknown", time.time()
return cls._version[0]
@classmethod
def get_internal_ip(cls):
"""
gets the internal ip by attempting to connect to googles DNS
:return: the current internal ip
:rtype: str
"""
if abs(cls._ip_address[-1] - time.time()) > 10:
try:
try:
import netifaces
ip = netifaces.ifaddresses("tun0")[netifaces.AF_INET][0]["addr"]
cls._ip_address = ip, time.time()
except:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 0))
cls._ip_address = s.getsockname()[0], time.time()
except:
cls._ip_address = "0.0.0.0", time.time()
return cls._ip_address[0]
@classmethod
def get_log_files(cls) -> list:
"""
returns the spc-eyepi log files that have been rotated.
:return: list of filenames
:rtype: list(str)
"""
return list(glob("/home/spc-eyepi/spc-eyepi.log.*"))
@classmethod
def clear_files(cls, filenames: list):
"""
removes all files in the list provided, skipping and logging on an error removing
todo: Do different things based on whether is a directory.
:param filenames: list of directories or files
:type filenames: list or tuple
"""
for f in filenames:
try:
os.remove(f)
except FileNotFoundError as e:
cls.logger.debug(str(e))
except IsADirectoryError as e:
cls.logger.error(str(e))
except Exception as e:
cls.logger.error(str(e))
@classmethod
def get_isonow(cls):
"""
gets the current time as an iso8601 string
:return: the current time as iso8601
:rtype: str
"""
return datetime.datetime.now().isoformat()
@classmethod
def get_external_ip(cls):
"""
returns the external IP address of the raspberry pi through api.ipify.org
:return: the external ip address
:rtype: str
"""
if abs(cls._external_ip[-1] - time.time()) > 60:
try:
url = 'https://api.ipify.org/?format=json'
response = request.urlopen(url, timeout=10).read().decode('utf-8')
cls._external_ip = json.loads(response)['ip'], time.time()
except:
cls._external_ip = "0.0.0.0", time.time()
return cls._external_ip[0]
@classmethod
def get_identifier_from_name(cls, name):
"""
returns either the identifier (from name) or the name filled with the machine id
clamps to 32 characters.
:param name: name to fill
:type name: str
:return: filled name
:rtype: str
"""
identifier = "".join((x if idx > len(name) - 1 else name[idx] for idx, x in enumerate(cls.get_machineid())))
return identifier[:32]
@classmethod
def get_identifier_from_filename(cls, file_name):
"""
returns either the identifier (from the file name) or the name filled with the machine id
:param file_name: filename
:type file_name: str
:return: string identifier,
:rtype: str
"""
fsn = next(iter(os.path.splitext(os.path.basename(file_name))), "")
return cls.get_identifier_from_name(fsn)
@classmethod
def ensure_config(cls, identifier):
"""
ensures a configuration file exists for this identifier.
if a config file doesnt exist then it will create a default one.
:param identifier: identifier to create or find a configuration file for.
:type identifier: str
:return: the configuration file dict or configparser object.
:rtype: dict or configparser.ConfigParser
"""
config = configparser.ConfigParser()
config.read_string(default_config)
path = cls.identifier_to_ini(identifier)
try:
if len(config.read(path)):
return config
except Exception as e:
print(str(e))
if not config['localfiles']['spooling_dir']:
config['localfiles']['spooling_dir'] = "/home/images/spool/{}".format(identifier)
if not config['localfiles']['upload_dir']:
config['localfiles']['upload_dir'] = "/home/images/upload/{}".format(identifier)
if not config['camera']['name']:
config['camera']['name'] = cls.get_hostname() + identifier[:6]
cls.write_config(config, identifier)
return config
@classmethod
def write_config(cls, config: configparser.ConfigParser, identifier: str):
"""
writes a configuration file to an correct config file path.
:param config: configuration file (configparser object)
:type identifier: str
:param identifier: identifier to user as the raget file name.
:return: configparser object
"""
path = SysUtil.identifier_to_ini(identifier)
with open(path, 'w+') as configfile:
config.write(configfile)
return config
@classmethod
def identifier_to_ini(cls, identifier: str)->str:
"""
gets a valid .ini path for an identifier.
:param identifier: identifier to find an ini for.
:return: file path for identifier
:rtype: str
"""
for fn in glob("configs_byserial/*.ini"):
if identifier == cls.get_identifier_from_filename(fn):
return fn
else:
return os.path.join("configs_byserial/", identifier) + ".ini"
@classmethod
def ensure_light_config(cls, identifier):
"""
ensures a configuration file exists for this identifier.
if a config file doesnt exist then it will create a default one.
:param identifier: identifier of the light
:type identifier: str
:return: configuration for the light
:rtype: configparser.ConfigParser
"""
config = configparser.ConfigParser()
config.read_string(default_light_config)
path = cls.identifier_to_ini(identifier)
try:
if len(config.read(path)):
return config
except Exception as e:
print(str(e))
if "{identifier}" in config.get("light", "file_path"):
config.set("light", "file_path",
config.get('light', "file_path").format(identifier=identifier))
cls.write_light_config(config, identifier)
return config
@classmethod
def get_light_configs(cls):
"""
gets a dict of the light config files (.ini)
:return: dict of light configs
:rtype: dict(str: configparser.ConfigParser)
"""
def slc_csv_exists(fp):
return os.path.exists(os.path.splitext(fp)[0]+".csv") or os.path.exists(os.path.splitext(fp)[0]+".slc")
def get_id(fp):
n, ext = os.path.splitext(os.path.basename(fp))
return n
try:
files = [x for x in glob("light_configs_byip/*.ini") if slc_csv_exists(x)]
f_and_id = {get_id(x): x for x in files}
return f_and_id
except Exception as e:
cls.logger.error("Couldnt enumerate lights, no light functionality. {}".format(str(e)))
return dict()
@classmethod
def write_light_config(cls, config: configparser.ConfigParser, identifier: str):
"""
writes a configuration file to an correct config file path.
:param config: configuration file (configparser object)
:param identifier: identifier of the light.
:type identifier: str
:return: configparser object
"""
path = SysUtil.light_identifier_to_ini(identifier)
with open(path, 'w+') as configfile:
config.write(configfile)
return config
@classmethod
def get_light_datafile(cls, identifier: str)->str:
"""
gets a light datafile
:param identifier: identifier to use to find the data file.
:type identifier: str
:return: file path for csv or slc.
:rtype: str
"""
csv = "lights_byip/{}.csv".format(identifier)
slc = "lights_byip/{}.slc".format(identifier)
if os.path.exists(slc) and os.path.isfile(slc):
return slc
elif os.path.exists(csv) and os.path.isfile(csv):
return csv
else:
return ""
@classmethod
def load_or_fix_solarcalc(cls, identifier: str)->list:
"""
function to either load an existing fixed up solarcalc file or to coerce one into the fixed format.
:param identifier: identifier of the light for which the solarcalc file exists.
:type identifier: str
:return: light timing data as a list of lists.
:rtype: list(list())
"""
lx = []
fp = cls.get_light_datafile(identifier)
path, ext = os.path.splitext(fp)
header10 = ['datetime', 'temp', 'relativehumidity', 'LED1', 'LED2', 'LED3', 'LED4', 'LED5', 'LED6', 'LED7',
'LED8', 'LED9', 'LED10', 'total_solar_watt', 'simulated_datetime']
header7 = ['datetime', 'temp', 'relativehumidity', 'LED1', 'LED2', 'LED3', 'LED4', 'LED5', 'LED6', 'LED7',
'total_solar_watt', 'simulated_datetime']
if not os.path.isfile(fp):
SysUtil.logger.error("no SolarCalc file.")
raise FileNotFoundError()
if ext == ".slc":
with open(fp) as f:
lx = [x.strip().split(",") for x in f.readlines()]
else:
with open(fp) as f:
l = [x.strip().split(",") for x in f.readlines()]
def get_lines(li):
print("Loading csv")
for idx, line in enumerate(li):
try:
yield [
datetime.datetime.strptime("{}_{}".format(line[0], line[1]), "%d/%m/%Y_%H:%M").isoformat(),
*line[2:-1],
datetime.datetime.strptime(line[-1], "%d %b %Y %H:%M").isoformat()
]
except Exception as e:
SysUtil.logger.error("Couldnt fix solarcalc file. {}".format(str(e)))
print(l)
lx.extend(get_lines(l))
if len(l[0]) == 15:
lx.insert(0, header10)
else:
lx.insert(0, header7)
with open(path+".slc", 'w') as f:
f.write("\n".join([",".join(x) for x in lx]))
for idx, x in enumerate(lx[1:]):
lx[idx+1][0] = datetime.datetime.strptime(x[0], "%Y-%m-%dT%H:%M:%S")
lx[idx+1][-1] = datetime.datetime.strptime(x[-1], "%Y-%m-%dT%H:%M:%S")
return lx[1:]
@classmethod
def light_identifier_to_ini(cls, identifier: str)->str:
"""
gets a valid .ini path for an identifier.
:param identifier: identifier for a light
:type identifier: str
:return: ini filename for a light
:rtype: str
"""
for fn in glob("lights_byip/*.ini"):
if identifier == cls.get_identifier_from_filename(fn):
return fn
else:
return os.path.join("lights_byip/", identifier) + ".ini"
@classmethod
def identifier_to_yml(cls, identifier: str)->str:
"""
the same as identifier_to_ini but for yml files
:param identifier: identifier for a matching yml file.
:type identifier: str
:return: string filepath for the yml file.
:rtype: str
"""
for fn in glob("configs_byserial/*.yml"):
if identifier == cls.get_identifier_from_filename(fn):
return fn
else:
return os.path.join("configs_byserial/", identifier) + ".yml"
@classmethod
def configs_from_identifiers(cls, identifiers: set) -> dict:
"""
given a set of identifiers, returns a dictionary of the data contained in those config files with the key
for each config file data being the identifier
:param identifiers:
:type identifiers: list(str)
:return: dictionary of configuration datas
:rtype: dict(str: dict)
"""
data = dict()
for ini in ["configs_byserial/{}.ini".format(x) for x in identifiers]:
cfg = configparser.ConfigParser()
cfg.read(ini)
d = dict()
d = {section: dict(cfg.items(section)) for section in cfg.sections()}
data[cls.get_identifier_from_filename(ini)] = d
return data
@classmethod
def add_watch(cls, path: str, callback):
"""
adds a watch that calls the callback on file change
:param path: path of the file to watch
:type path: str
:param callback: function signature to call when the file is changed
"""
cls._watches.append((path, os.stat(path).st_mtime, callback))
@classmethod
def open_yaml(cls, filename):
"""
opens a yaml file using yaml.load
:param filename: yaml file to load
:return: dictionary of values in yaml file
:rtype: dict
"""
try:
with open(filename) as e:
q = yaml.load(e.read())
return q
except Exception as e:
print(str(e))
return dict()
@classmethod
def _thread(cls):
"""
runs the watchers
"""
while True and not cls.stop:
try:
for index, (path, mtime, callback) in enumerate(cls._watches):
tmt = os.stat(path).st_mtime
if tmt != mtime:
cls._watches[index] = (path, tmt, callback)
try:
print("calling {}".format(callback))
callback()
except Exception as e:
print(str(e))
time.sleep(1)
except Exception as e:
break
cls.thread = None
|
mit
|
[
646,
3873,
199,
646,
2196,
12,
1059,
12,
747,
12,
2838,
12,
2022,
12,
900,
199,
504,
5739,
492,
5739,
199,
504,
4011,
492,
1056,
199,
646,
5796,
199,
646,
21230,
199,
646,
8864,
199,
646,
2050,
199,
646,
2050,
14,
888,
199,
646,
12871,
199,
646,
2197,
199,
199,
19919,
13260,
7079,
63,
18066,
275,
499,
1196,
1257,
199,
893,
26,
272,
2050,
14,
888,
14,
493,
2028,
480,
4806,
14,
2730,
531,
199,
2590,
26,
272,
986,
199,
199,
318,
13855,
63,
5045,
8,
1507,
12,
4739,
534,
34,
735,
272,
367,
4137,
315,
18179,
283,
32198,
297,
283,
14738,
297,
283,
30815,
297,
283,
22731,
297,
283,
10542,
297,
283,
37,
73,
297,
283,
22534,
2565,
267,
340,
2853,
8,
1507,
9,
665,
6619,
14,
16,
26,
288,
372,
2071,
19,
14,
17,
70,
5,
83,
5,
83,
2,
450,
334,
1507,
12,
4137,
12,
4739,
9,
267,
1967,
12257,
6619,
14,
16,
272,
372,
31681,
17,
70,
5,
83,
5,
83,
2,
450,
334,
1507,
12,
283,
21001,
297,
4739,
9,
421,
199,
885,
63,
888,
275,
408,
199,
59,
3472,
61,
199,
28480,
275,
378,
199,
3827,
275,
641,
199,
8709,
275,
641,
199,
199,
59,
11928,
61,
199,
354,
275,
199,
3827,
275,
641,
199,
199,
59,
8915,
61,
199,
3827,
275,
641,
199,
1814,
275,
641,
199,
8709,
275,
641,
199,
3954,
379,
275,
641,
199,
1000,
275,
308,
8915,
14,
22687,
12685,
14,
1308,
199,
3619,
275,
1182,
199,
2473,
275,
26559,
455,
199,
2060,
275,
6186,
63,
9032,
199,
199,
59,
521,
12057,
61,
199,
4284,
275,
9601,
199,
32183,
275,
8733,
26,
383,
199,
2379,
521,
275,
6546,
26,
1427,
199,
199,
59,
320,
696,
12059,
83,
61,
199,
83,
28624,
63,
694,
275,
199,
5064,
63,
694,
275,
199,
624,
199,
199,
885,
63,
4040,
63,
888,
275,
408,
199,
199,
59,
4040,
61,
199,
988,
63,
5652,
275,
5198,
199,
827,
63,
5652,
275,
378,
199,
10024,
14563,
275,
298,
5303,
10756,
12,
25102,
10756,
12,
24223,
10756,
12,
27030,
10756,
12,
22,
1216,
10756,
12,
15268,
10756,
12,
31327,
10756,
2,
199,
4737,
63,
1612,
275,
298,
5290,
17,
12,
5290,
18,
12,
5290,
19,
12,
5290,
20,
12,
5290,
21,
12,
5290,
22,
12,
5290,
23,
2,
199,
493,
63,
515,
275,
298,
27227,
63,
991,
2171,
5321,
5364,
5565,
27441,
2,
199,
199,
59,
31085,
61,
199,
31085,
63,
1102,
275,
298,
5756,
14,
6568,
14,
18,
14,
7214,
2,
199,
31085,
63,
719,
275,
959,
1690,
1216,
199,
409,
63,
452,
63,
1531,
275,
663,
452,
469,
5652,
93,
199,
409,
63,
10024,
1267,
63,
1531,
275,
663,
20159,
3369,
5652,
469,
10024,
1267,
93,
469,
5652,
93,
199,
409,
63,
452,
63,
10024,
1267,
63,
1531,
275,
663,
87,
478,
3369,
5652,
1052,
1052,
1052,
1052,
1052,
1052,
1052,
199,
362,
63,
10024,
1267,
63,
1531,
275,
664,
20159,
3369,
5652,
469,
10024,
1267,
93,
199,
199,
59,
633,
61,
199,
633,
63,
1102,
275,
298,
5756,
14,
6568,
14,
18,
14,
7214,
2,
199,
2785,
63,
2302,
275,
1182,
13814,
13,
1393,
15,
751,
41,
14,
13814,
199,
409,
63,
452,
63,
1531,
275,
298,
409,
2422,
1378,
582,
469,
7045,
1386,
298,
409,
2422,
2610,
582,
298,
409,
2,
199,
409,
63,
452,
63,
10024,
1267,
63,
1531,
275,
298,
20159,
17,
582,
27125,
298,
20159,
18,
582,
27125,
298,
20159,
19,
582,
27125,
298,
20159,
20,
582,
27125,
298,
20159,
21,
582,
27125,
298,
20159,
22,
582,
27125,
298,
20159,
23,
582,
2440,
199,
199,
624,
421,
199,
533,
28766,
9562,
8,
785,
304,
272,
408,
272,
6187,
11420,
1021,
14,
272,
11642,
1021,
370,
2581,
7750,
7645,
2839,
314,
6246,
12,
6844,
13,
344,
12,
5982,
402,
4601,
315,
314,
10036,
14,
272,
408,
272,
485,
711,
63,
1562,
275,
298,
16,
14,
16,
14,
16,
14,
16,
401,
378,
272,
485,
5159,
63,
711,
275,
298,
16,
14,
16,
14,
16,
14,
16,
401,
378,
272,
485,
6744,
63,
344,
275,
4873,
378,
272,
485,
4269,
275,
298,
22647,
401,
378,
272,
485,
8270,
63,
1102,
275,
1689,
5187,
14,
265,
1636,
401,
298,
1397,
282,
3363,
790,
401,
298,
1397,
282,
3363,
1890,
1288,
378,
272,
485,
1023,
275,
298,
5912,
2249,
67,
13,
15240,
1038,
1015,
401,
378,
272,
282,
63,
3736,
20970,
275,
747,
14,
3736,
20970,
19031,
272,
485,
2319,
275,
334,
65,
63,
3736,
20970,
14,
70,
63,
4391,
890,
627,
282,
63,
3736,
20970,
14,
70,
63,
66,
18961,
12,
282,
63,
3736,
20970,
14,
70,
63,
4391,
890,
627,
282,
63,
3736,
20970,
14,
70,
63,
4166,
395,
378,
272,
485,
6821,
397,
275,
769,
342,
272,
2462,
275,
488,
272,
3631,
275,
756,
272,
2512,
275,
2050,
14,
5572,
480,
11319,
9562,
531,
2378,
347,
636,
826,
721,
277,
304,
267,
340,
28766,
9562,
14,
2671,
365,
488,
26,
288,
28766,
9562,
14,
2671,
275,
5796,
14,
4436,
8,
1375,
29,
277,
423,
2671,
9,
288,
28766,
9562,
14,
2671,
14,
928,
342,
267,
986,
339,
768,
4639,
272,
347,
5305,
63,
17411,
63,
1782,
8,
5610,
26,
1109,
12,
4866,
26,
1109,
9,
1035,
2155,
26,
267,
408,
267,
295,
2193,
282,
27923,
2243,
14,
398,
520,
635,
10414,
26,
10414,
1329,
267,
520,
466,
10414,
26,
1109,
267,
520,
635,
4866,
26,
2243,
1329,
402,
314,
2243,
641,
314,
10414,
3432,
267,
520,
466,
4866,
26,
1109,
267,
408,
267,
862,
26,
288,
4325,
275,
3286,
2374,
15,
5610,
15,
17411,
5321,
5610,
26,
1644,
68,
16152,
2374,
26,
1644,
68,
5469,
908,
8,
5610,
29,
5610,
12,
4866,
29,
2374,
9,
288,
543,
1551,
8,
2324,
12,
283,
87,
297,
747,
14,
47,
63,
6524,
10452,
9,
465,
289,
26,
355,
12871,
14,
2308,
8077,
8,
70,
12,
28655,
13260,
7079,
63,
18066,
12,
378,
9,
288,
372,
715,
267,
871,
2186,
465,
325,
26,
288,
28766,
9562,
14,
2921,
14,
705,
480,
6531,
343,
5305,
27923,
2243,
334,
13893,
570,
32353,
304,
8352,
908,
8,
495,
8,
69,
1724,
339,
768,
4639,
272,
347,
849,
63,
5364,
8,
1861,
29
] |
[
3873,
199,
646,
2196,
12,
1059,
12,
747,
12,
2838,
12,
2022,
12,
900,
199,
504,
5739,
492,
5739,
199,
504,
4011,
492,
1056,
199,
646,
5796,
199,
646,
21230,
199,
646,
8864,
199,
646,
2050,
199,
646,
2050,
14,
888,
199,
646,
12871,
199,
646,
2197,
199,
199,
19919,
13260,
7079,
63,
18066,
275,
499,
1196,
1257,
199,
893,
26,
272,
2050,
14,
888,
14,
493,
2028,
480,
4806,
14,
2730,
531,
199,
2590,
26,
272,
986,
199,
199,
318,
13855,
63,
5045,
8,
1507,
12,
4739,
534,
34,
735,
272,
367,
4137,
315,
18179,
283,
32198,
297,
283,
14738,
297,
283,
30815,
297,
283,
22731,
297,
283,
10542,
297,
283,
37,
73,
297,
283,
22534,
2565,
267,
340,
2853,
8,
1507,
9,
665,
6619,
14,
16,
26,
288,
372,
2071,
19,
14,
17,
70,
5,
83,
5,
83,
2,
450,
334,
1507,
12,
4137,
12,
4739,
9,
267,
1967,
12257,
6619,
14,
16,
272,
372,
31681,
17,
70,
5,
83,
5,
83,
2,
450,
334,
1507,
12,
283,
21001,
297,
4739,
9,
421,
199,
885,
63,
888,
275,
408,
199,
59,
3472,
61,
199,
28480,
275,
378,
199,
3827,
275,
641,
199,
8709,
275,
641,
199,
199,
59,
11928,
61,
199,
354,
275,
199,
3827,
275,
641,
199,
199,
59,
8915,
61,
199,
3827,
275,
641,
199,
1814,
275,
641,
199,
8709,
275,
641,
199,
3954,
379,
275,
641,
199,
1000,
275,
308,
8915,
14,
22687,
12685,
14,
1308,
199,
3619,
275,
1182,
199,
2473,
275,
26559,
455,
199,
2060,
275,
6186,
63,
9032,
199,
199,
59,
521,
12057,
61,
199,
4284,
275,
9601,
199,
32183,
275,
8733,
26,
383,
199,
2379,
521,
275,
6546,
26,
1427,
199,
199,
59,
320,
696,
12059,
83,
61,
199,
83,
28624,
63,
694,
275,
199,
5064,
63,
694,
275,
199,
624,
199,
199,
885,
63,
4040,
63,
888,
275,
408,
199,
199,
59,
4040,
61,
199,
988,
63,
5652,
275,
5198,
199,
827,
63,
5652,
275,
378,
199,
10024,
14563,
275,
298,
5303,
10756,
12,
25102,
10756,
12,
24223,
10756,
12,
27030,
10756,
12,
22,
1216,
10756,
12,
15268,
10756,
12,
31327,
10756,
2,
199,
4737,
63,
1612,
275,
298,
5290,
17,
12,
5290,
18,
12,
5290,
19,
12,
5290,
20,
12,
5290,
21,
12,
5290,
22,
12,
5290,
23,
2,
199,
493,
63,
515,
275,
298,
27227,
63,
991,
2171,
5321,
5364,
5565,
27441,
2,
199,
199,
59,
31085,
61,
199,
31085,
63,
1102,
275,
298,
5756,
14,
6568,
14,
18,
14,
7214,
2,
199,
31085,
63,
719,
275,
959,
1690,
1216,
199,
409,
63,
452,
63,
1531,
275,
663,
452,
469,
5652,
93,
199,
409,
63,
10024,
1267,
63,
1531,
275,
663,
20159,
3369,
5652,
469,
10024,
1267,
93,
469,
5652,
93,
199,
409,
63,
452,
63,
10024,
1267,
63,
1531,
275,
663,
87,
478,
3369,
5652,
1052,
1052,
1052,
1052,
1052,
1052,
1052,
199,
362,
63,
10024,
1267,
63,
1531,
275,
664,
20159,
3369,
5652,
469,
10024,
1267,
93,
199,
199,
59,
633,
61,
199,
633,
63,
1102,
275,
298,
5756,
14,
6568,
14,
18,
14,
7214,
2,
199,
2785,
63,
2302,
275,
1182,
13814,
13,
1393,
15,
751,
41,
14,
13814,
199,
409,
63,
452,
63,
1531,
275,
298,
409,
2422,
1378,
582,
469,
7045,
1386,
298,
409,
2422,
2610,
582,
298,
409,
2,
199,
409,
63,
452,
63,
10024,
1267,
63,
1531,
275,
298,
20159,
17,
582,
27125,
298,
20159,
18,
582,
27125,
298,
20159,
19,
582,
27125,
298,
20159,
20,
582,
27125,
298,
20159,
21,
582,
27125,
298,
20159,
22,
582,
27125,
298,
20159,
23,
582,
2440,
199,
199,
624,
421,
199,
533,
28766,
9562,
8,
785,
304,
272,
408,
272,
6187,
11420,
1021,
14,
272,
11642,
1021,
370,
2581,
7750,
7645,
2839,
314,
6246,
12,
6844,
13,
344,
12,
5982,
402,
4601,
315,
314,
10036,
14,
272,
408,
272,
485,
711,
63,
1562,
275,
298,
16,
14,
16,
14,
16,
14,
16,
401,
378,
272,
485,
5159,
63,
711,
275,
298,
16,
14,
16,
14,
16,
14,
16,
401,
378,
272,
485,
6744,
63,
344,
275,
4873,
378,
272,
485,
4269,
275,
298,
22647,
401,
378,
272,
485,
8270,
63,
1102,
275,
1689,
5187,
14,
265,
1636,
401,
298,
1397,
282,
3363,
790,
401,
298,
1397,
282,
3363,
1890,
1288,
378,
272,
485,
1023,
275,
298,
5912,
2249,
67,
13,
15240,
1038,
1015,
401,
378,
272,
282,
63,
3736,
20970,
275,
747,
14,
3736,
20970,
19031,
272,
485,
2319,
275,
334,
65,
63,
3736,
20970,
14,
70,
63,
4391,
890,
627,
282,
63,
3736,
20970,
14,
70,
63,
66,
18961,
12,
282,
63,
3736,
20970,
14,
70,
63,
4391,
890,
627,
282,
63,
3736,
20970,
14,
70,
63,
4166,
395,
378,
272,
485,
6821,
397,
275,
769,
342,
272,
2462,
275,
488,
272,
3631,
275,
756,
272,
2512,
275,
2050,
14,
5572,
480,
11319,
9562,
531,
2378,
347,
636,
826,
721,
277,
304,
267,
340,
28766,
9562,
14,
2671,
365,
488,
26,
288,
28766,
9562,
14,
2671,
275,
5796,
14,
4436,
8,
1375,
29,
277,
423,
2671,
9,
288,
28766,
9562,
14,
2671,
14,
928,
342,
267,
986,
339,
768,
4639,
272,
347,
5305,
63,
17411,
63,
1782,
8,
5610,
26,
1109,
12,
4866,
26,
1109,
9,
1035,
2155,
26,
267,
408,
267,
295,
2193,
282,
27923,
2243,
14,
398,
520,
635,
10414,
26,
10414,
1329,
267,
520,
466,
10414,
26,
1109,
267,
520,
635,
4866,
26,
2243,
1329,
402,
314,
2243,
641,
314,
10414,
3432,
267,
520,
466,
4866,
26,
1109,
267,
408,
267,
862,
26,
288,
4325,
275,
3286,
2374,
15,
5610,
15,
17411,
5321,
5610,
26,
1644,
68,
16152,
2374,
26,
1644,
68,
5469,
908,
8,
5610,
29,
5610,
12,
4866,
29,
2374,
9,
288,
543,
1551,
8,
2324,
12,
283,
87,
297,
747,
14,
47,
63,
6524,
10452,
9,
465,
289,
26,
355,
12871,
14,
2308,
8077,
8,
70,
12,
28655,
13260,
7079,
63,
18066,
12,
378,
9,
288,
372,
715,
267,
871,
2186,
465,
325,
26,
288,
28766,
9562,
14,
2921,
14,
705,
480,
6531,
343,
5305,
27923,
2243,
334,
13893,
570,
32353,
304,
8352,
908,
8,
495,
8,
69,
1724,
339,
768,
4639,
272,
347,
849,
63,
5364,
8,
1861,
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,
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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
] |
wsmith323/django
|
django/http/multipartparser.py
|
332
|
24331
|
"""
Multi-part parsing for file uploads.
Exposes one class, ``MultiPartParser``, which feeds chunks of uploaded data to
file upload handlers for processing.
"""
from __future__ import unicode_literals
import base64
import binascii
import cgi
import sys
from django.conf import settings
from django.core.exceptions import SuspiciousMultipartForm
from django.core.files.uploadhandler import (
SkipFile, StopFutureHandlers, StopUpload,
)
from django.utils import six
from django.utils.datastructures import MultiValueDict
from django.utils.encoding import force_text
from django.utils.six.moves.urllib.parse import unquote
from django.utils.text import unescape_entities
__all__ = ('MultiPartParser', 'MultiPartParserError', 'InputStreamExhausted')
class MultiPartParserError(Exception):
pass
class InputStreamExhausted(Exception):
"""
No more reads are allowed from this device.
"""
pass
RAW = "raw"
FILE = "file"
FIELD = "field"
_BASE64_DECODE_ERROR = TypeError if six.PY2 else binascii.Error
class MultiPartParser(object):
"""
A rfc2388 multipart/form-data parser.
``MultiValueDict.parse()`` reads the input stream in ``chunk_size`` chunks
and returns a tuple of ``(MultiValueDict(POST), MultiValueDict(FILES))``.
"""
def __init__(self, META, input_data, upload_handlers, encoding=None):
"""
Initialize the MultiPartParser object.
:META:
The standard ``META`` dictionary in Django request objects.
:input_data:
The raw post data, as a file-like object.
:upload_handlers:
A list of UploadHandler instances that perform operations on the uploaded
data.
:encoding:
The encoding with which to treat the incoming data.
"""
#
# Content-Type should contain multipart and the boundary information.
#
content_type = META.get('HTTP_CONTENT_TYPE', META.get('CONTENT_TYPE', ''))
if not content_type.startswith('multipart/'):
raise MultiPartParserError('Invalid Content-Type: %s' % content_type)
# Parse the header to get the boundary to split the parts.
ctypes, opts = parse_header(content_type.encode('ascii'))
boundary = opts.get('boundary')
if not boundary or not cgi.valid_boundary(boundary):
raise MultiPartParserError('Invalid boundary in multipart: %s' % boundary)
# Content-Length should contain the length of the body we are about
# to receive.
try:
content_length = int(META.get('HTTP_CONTENT_LENGTH', META.get('CONTENT_LENGTH', 0)))
except (ValueError, TypeError):
content_length = 0
if content_length < 0:
# This means we shouldn't continue...raise an error.
raise MultiPartParserError("Invalid content length: %r" % content_length)
if isinstance(boundary, six.text_type):
boundary = boundary.encode('ascii')
self._boundary = boundary
self._input_data = input_data
# For compatibility with low-level network APIs (with 32-bit integers),
# the chunk size should be < 2^31, but still divisible by 4.
possible_sizes = [x.chunk_size for x in upload_handlers if x.chunk_size]
self._chunk_size = min([2 ** 31 - 4] + possible_sizes)
self._meta = META
self._encoding = encoding or settings.DEFAULT_CHARSET
self._content_length = content_length
self._upload_handlers = upload_handlers
def parse(self):
"""
Parse the POST data and break it into a FILES MultiValueDict and a POST
MultiValueDict.
Returns a tuple containing the POST and FILES dictionary, respectively.
"""
# We have to import QueryDict down here to avoid a circular import.
from django.http import QueryDict
encoding = self._encoding
handlers = self._upload_handlers
# HTTP spec says that Content-Length >= 0 is valid
# handling content-length == 0 before continuing
if self._content_length == 0:
return QueryDict('', encoding=self._encoding), MultiValueDict()
# See if any of the handlers take care of the parsing.
# This allows overriding everything if need be.
for handler in handlers:
result = handler.handle_raw_input(self._input_data,
self._meta,
self._content_length,
self._boundary,
encoding)
# Check to see if it was handled
if result is not None:
return result[0], result[1]
# Create the data structures to be used later.
self._post = QueryDict('', mutable=True)
self._files = MultiValueDict()
# Instantiate the parser and stream:
stream = LazyStream(ChunkIter(self._input_data, self._chunk_size))
# Whether or not to signal a file-completion at the beginning of the loop.
old_field_name = None
counters = [0] * len(handlers)
try:
for item_type, meta_data, field_stream in Parser(stream, self._boundary):
if old_field_name:
# We run this at the beginning of the next loop
# since we cannot be sure a file is complete until
# we hit the next boundary/part of the multipart content.
self.handle_file_complete(old_field_name, counters)
old_field_name = None
try:
disposition = meta_data['content-disposition'][1]
field_name = disposition['name'].strip()
except (KeyError, IndexError, AttributeError):
continue
transfer_encoding = meta_data.get('content-transfer-encoding')
if transfer_encoding is not None:
transfer_encoding = transfer_encoding[0].strip()
field_name = force_text(field_name, encoding, errors='replace')
if item_type == FIELD:
# This is a post field, we can just set it in the post
if transfer_encoding == 'base64':
raw_data = field_stream.read()
try:
data = base64.b64decode(raw_data)
except _BASE64_DECODE_ERROR:
data = raw_data
else:
data = field_stream.read()
self._post.appendlist(field_name,
force_text(data, encoding, errors='replace'))
elif item_type == FILE:
# This is a file, use the handler...
file_name = disposition.get('filename')
if not file_name:
continue
file_name = force_text(file_name, encoding, errors='replace')
file_name = self.IE_sanitize(unescape_entities(file_name))
content_type, content_type_extra = meta_data.get('content-type', ('', {}))
content_type = content_type.strip()
charset = content_type_extra.get('charset')
try:
content_length = int(meta_data.get('content-length')[0])
except (IndexError, TypeError, ValueError):
content_length = None
counters = [0] * len(handlers)
try:
for handler in handlers:
try:
handler.new_file(field_name, file_name,
content_type, content_length,
charset, content_type_extra)
except StopFutureHandlers:
break
for chunk in field_stream:
if transfer_encoding == 'base64':
# We only special-case base64 transfer encoding
# We should always decode base64 chunks by multiple of 4,
# ignoring whitespace.
stripped_chunk = b"".join(chunk.split())
remaining = len(stripped_chunk) % 4
while remaining != 0:
over_chunk = field_stream.read(4 - remaining)
stripped_chunk += b"".join(over_chunk.split())
remaining = len(stripped_chunk) % 4
try:
chunk = base64.b64decode(stripped_chunk)
except Exception as e:
# Since this is only a chunk, any error is an unfixable error.
msg = "Could not decode base64 data: %r" % e
six.reraise(MultiPartParserError, MultiPartParserError(msg), sys.exc_info()[2])
for i, handler in enumerate(handlers):
chunk_length = len(chunk)
chunk = handler.receive_data_chunk(chunk,
counters[i])
counters[i] += chunk_length
if chunk is None:
# If the chunk received by the handler is None, then don't continue.
break
except SkipFile:
self._close_files()
# Just use up the rest of this file...
exhaust(field_stream)
else:
# Handle file upload completions on next iteration.
old_field_name = field_name
else:
# If this is neither a FIELD or a FILE, just exhaust the stream.
exhaust(stream)
except StopUpload as e:
self._close_files()
if not e.connection_reset:
exhaust(self._input_data)
else:
# Make sure that the request data is all fed
exhaust(self._input_data)
# Signal that the upload has completed.
for handler in handlers:
retval = handler.upload_complete()
if retval:
break
return self._post, self._files
def handle_file_complete(self, old_field_name, counters):
"""
Handle all the signaling that takes place when a file is complete.
"""
for i, handler in enumerate(self._upload_handlers):
file_obj = handler.file_complete(counters[i])
if file_obj:
# If it returns a file object, then set the files dict.
self._files.appendlist(
force_text(old_field_name, self._encoding, errors='replace'),
file_obj)
break
def IE_sanitize(self, filename):
"""Cleanup filename from Internet Explorer full paths."""
return filename and filename[filename.rfind("\\") + 1:].strip()
def _close_files(self):
# Free up all file handles.
# FIXME: this currently assumes that upload handlers store the file as 'file'
# We should document that... (Maybe add handler.free_file to complement new_file)
for handler in self._upload_handlers:
if hasattr(handler, 'file'):
handler.file.close()
class LazyStream(six.Iterator):
"""
The LazyStream wrapper allows one to get and "unget" bytes from a stream.
Given a producer object (an iterator that yields bytestrings), the
LazyStream object will support iteration, reading, and keeping a "look-back"
variable in case you need to "unget" some bytes.
"""
def __init__(self, producer, length=None):
"""
Every LazyStream must have a producer when instantiated.
A producer is an iterable that returns a string each time it
is called.
"""
self._producer = producer
self._empty = False
self._leftover = b''
self.length = length
self.position = 0
self._remaining = length
self._unget_history = []
def tell(self):
return self.position
def read(self, size=None):
def parts():
remaining = self._remaining if size is None else size
# do the whole thing in one shot if no limit was provided.
if remaining is None:
yield b''.join(self)
return
# otherwise do some bookkeeping to return exactly enough
# of the stream and stashing any extra content we get from
# the producer
while remaining != 0:
assert remaining > 0, 'remaining bytes to read should never go negative'
try:
chunk = next(self)
except StopIteration:
return
else:
emitting = chunk[:remaining]
self.unget(chunk[remaining:])
remaining -= len(emitting)
yield emitting
out = b''.join(parts())
return out
def __next__(self):
"""
Used when the exact number of bytes to read is unimportant.
This procedure just returns whatever is chunk is conveniently returned
from the iterator instead. Useful to avoid unnecessary bookkeeping if
performance is an issue.
"""
if self._leftover:
output = self._leftover
self._leftover = b''
else:
output = next(self._producer)
self._unget_history = []
self.position += len(output)
return output
def close(self):
"""
Used to invalidate/disable this lazy stream.
Replaces the producer with an empty list. Any leftover bytes that have
already been read will still be reported upon read() and/or next().
"""
self._producer = []
def __iter__(self):
return self
def unget(self, bytes):
"""
Places bytes back onto the front of the lazy stream.
Future calls to read() will return those bytes first. The
stream position and thus tell() will be rewound.
"""
if not bytes:
return
self._update_unget_history(len(bytes))
self.position -= len(bytes)
self._leftover = b''.join([bytes, self._leftover])
def _update_unget_history(self, num_bytes):
"""
Updates the unget history as a sanity check to see if we've pushed
back the same number of bytes in one chunk. If we keep ungetting the
same number of bytes many times (here, 50), we're mostly likely in an
infinite loop of some sort. This is usually caused by a
maliciously-malformed MIME request.
"""
self._unget_history = [num_bytes] + self._unget_history[:49]
number_equal = len([current_number for current_number in self._unget_history
if current_number == num_bytes])
if number_equal > 40:
raise SuspiciousMultipartForm(
"The multipart parser got stuck, which shouldn't happen with"
" normal uploaded files. Check for malicious upload activity;"
" if there is none, report this to the Django developers."
)
class ChunkIter(six.Iterator):
"""
An iterable that will yield chunks of data. Given a file-like object as the
constructor, this object will yield chunks of read operations from that
object.
"""
def __init__(self, flo, chunk_size=64 * 1024):
self.flo = flo
self.chunk_size = chunk_size
def __next__(self):
try:
data = self.flo.read(self.chunk_size)
except InputStreamExhausted:
raise StopIteration()
if data:
return data
else:
raise StopIteration()
def __iter__(self):
return self
class InterBoundaryIter(six.Iterator):
"""
A Producer that will iterate over boundaries.
"""
def __init__(self, stream, boundary):
self._stream = stream
self._boundary = boundary
def __iter__(self):
return self
def __next__(self):
try:
return LazyStream(BoundaryIter(self._stream, self._boundary))
except InputStreamExhausted:
raise StopIteration()
class BoundaryIter(six.Iterator):
"""
A Producer that is sensitive to boundaries.
Will happily yield bytes until a boundary is found. Will yield the bytes
before the boundary, throw away the boundary bytes themselves, and push the
post-boundary bytes back on the stream.
The future calls to next() after locating the boundary will raise a
StopIteration exception.
"""
def __init__(self, stream, boundary):
self._stream = stream
self._boundary = boundary
self._done = False
# rollback an additional six bytes because the format is like
# this: CRLF<boundary>[--CRLF]
self._rollback = len(boundary) + 6
# Try to use mx fast string search if available. Otherwise
# use Python find. Wrap the latter for consistency.
unused_char = self._stream.read(1)
if not unused_char:
raise InputStreamExhausted()
self._stream.unget(unused_char)
def __iter__(self):
return self
def __next__(self):
if self._done:
raise StopIteration()
stream = self._stream
rollback = self._rollback
bytes_read = 0
chunks = []
for bytes in stream:
bytes_read += len(bytes)
chunks.append(bytes)
if bytes_read > rollback:
break
if not bytes:
break
else:
self._done = True
if not chunks:
raise StopIteration()
chunk = b''.join(chunks)
boundary = self._find_boundary(chunk, len(chunk) < self._rollback)
if boundary:
end, next = boundary
stream.unget(chunk[next:])
self._done = True
return chunk[:end]
else:
# make sure we don't treat a partial boundary (and
# its separators) as data
if not chunk[:-rollback]: # and len(chunk) >= (len(self._boundary) + 6):
# There's nothing left, we should just return and mark as done.
self._done = True
return chunk
else:
stream.unget(chunk[-rollback:])
return chunk[:-rollback]
def _find_boundary(self, data, eof=False):
"""
Finds a multipart boundary in data.
Should no boundary exist in the data None is returned instead. Otherwise
a tuple containing the indices of the following are returned:
* the end of current encapsulation
* the start of the next encapsulation
"""
index = data.find(self._boundary)
if index < 0:
return None
else:
end = index
next = index + len(self._boundary)
# backup over CRLF
last = max(0, end - 1)
if data[last:last + 1] == b'\n':
end -= 1
last = max(0, end - 1)
if data[last:last + 1] == b'\r':
end -= 1
return end, next
def exhaust(stream_or_iterable):
"""
Completely exhausts an iterator or stream.
Raise a MultiPartParserError if the argument is not a stream or an iterable.
"""
iterator = None
try:
iterator = iter(stream_or_iterable)
except TypeError:
iterator = ChunkIter(stream_or_iterable, 16384)
if iterator is None:
raise MultiPartParserError('multipartparser.exhaust() was passed a non-iterable or stream parameter')
for __ in iterator:
pass
def parse_boundary_stream(stream, max_header_size):
"""
Parses one and exactly one stream that encapsulates a boundary.
"""
# Stream at beginning of header, look for end of header
# and parse it if found. The header must fit within one
# chunk.
chunk = stream.read(max_header_size)
# 'find' returns the top of these four bytes, so we'll
# need to munch them later to prevent them from polluting
# the payload.
header_end = chunk.find(b'\r\n\r\n')
def _parse_header(line):
main_value_pair, params = parse_header(line)
try:
name, value = main_value_pair.split(':', 1)
except ValueError:
raise ValueError("Invalid header: %r" % line)
return name, (value, params)
if header_end == -1:
# we find no header, so we just mark this fact and pass on
# the stream verbatim
stream.unget(chunk)
return (RAW, {}, stream)
header = chunk[:header_end]
# here we place any excess chunk back onto the stream, as
# well as throwing away the CRLFCRLF bytes from above.
stream.unget(chunk[header_end + 4:])
TYPE = RAW
outdict = {}
# Eliminate blank lines
for line in header.split(b'\r\n'):
# This terminology ("main value" and "dictionary of
# parameters") is from the Python docs.
try:
name, (value, params) = _parse_header(line)
except ValueError:
continue
if name == 'content-disposition':
TYPE = FIELD
if params.get('filename'):
TYPE = FILE
outdict[name] = value, params
if TYPE == RAW:
stream.unget(chunk)
return (TYPE, outdict, stream)
class Parser(object):
def __init__(self, stream, boundary):
self._stream = stream
self._separator = b'--' + boundary
def __iter__(self):
boundarystream = InterBoundaryIter(self._stream, self._separator)
for sub_stream in boundarystream:
# Iterate over each part
yield parse_boundary_stream(sub_stream, 1024)
def parse_header(line):
""" Parse the header into a key-value.
Input (line): bytes, output: unicode for key/name, bytes for value which
will be decoded later
"""
plist = _parse_header_params(b';' + line)
key = plist.pop(0).lower().decode('ascii')
pdict = {}
for p in plist:
i = p.find(b'=')
if i >= 0:
has_encoding = False
name = p[:i].strip().lower().decode('ascii')
if name.endswith('*'):
# Lang/encoding embedded in the value (like "filename*=UTF-8''file.ext")
# http://tools.ietf.org/html/rfc2231#section-4
name = name[:-1]
if p.count(b"'") == 2:
has_encoding = True
value = p[i + 1:].strip()
if has_encoding:
encoding, lang, value = value.split(b"'")
if six.PY3:
value = unquote(value.decode(), encoding=encoding.decode())
else:
value = unquote(value).decode(encoding)
if len(value) >= 2 and value[:1] == value[-1:] == b'"':
value = value[1:-1]
value = value.replace(b'\\\\', b'\\').replace(b'\\"', b'"')
pdict[name] = value
return key, pdict
def _parse_header_params(s):
plist = []
while s[:1] == b';':
s = s[1:]
end = s.find(b';')
while end > 0 and s.count(b'"', 0, end) % 2:
end = s.find(b';', end + 1)
if end < 0:
end = len(s)
f = s[:end]
plist.append(f.strip())
s = s[end:]
return plist
|
bsd-3-clause
|
[
624,
199,
3947,
13,
2064,
6057,
367,
570,
26598,
14,
199,
199,
920,
10553,
1373,
1021,
12,
1124,
3947,
8416,
2842,
4542,
1314,
22295,
8291,
402,
14238,
666,
370,
199,
493,
5802,
8297,
367,
6661,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
1300,
772,
199,
646,
14755,
199,
646,
16004,
199,
646,
984,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
3924,
492,
428,
28651,
27242,
2821,
199,
504,
1639,
14,
1018,
14,
1725,
14,
5064,
2232,
492,
334,
272,
8232,
1173,
12,
8015,
14224,
25096,
12,
8015,
10301,
12,
199,
9,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
23004,
492,
6879,
24811,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
1122,
492,
14342,
199,
504,
1639,
14,
1208,
14,
505,
492,
22221,
63,
8327,
199,
199,
363,
452,
363,
275,
661,
3947,
8416,
2842,
297,
283,
3947,
8416,
21811,
297,
283,
27611,
920,
2411,
7274,
358,
421,
199,
533,
6879,
8416,
21811,
8,
1726,
304,
272,
986,
421,
199,
533,
6924,
3296,
920,
2411,
7274,
8,
1726,
304,
272,
408,
272,
3091,
1655,
11597,
787,
4370,
687,
642,
2243,
14,
272,
408,
272,
986,
199,
199,
4307,
275,
298,
1773,
2,
199,
3817,
275,
298,
493,
2,
199,
8609,
275,
298,
698,
2,
199,
199,
63,
5825,
772,
63,
1093,
6012,
63,
3170,
275,
3146,
340,
3816,
14,
4521,
18,
587,
14755,
14,
547,
421,
199,
533,
6879,
8416,
2842,
8,
785,
304,
272,
408,
272,
437,
18158,
1789,
1299,
15193,
15,
964,
13,
576,
1798,
14,
339,
1124,
3947,
24811,
14,
1122,
8497,
11597,
314,
1324,
2547,
315,
1124,
4604,
63,
890,
1040,
8291,
272,
436,
2529,
282,
2008,
402,
15475,
3947,
24811,
8,
4030,
395,
6879,
24811,
8,
9472,
430,
4345,
272,
408,
272,
347,
636,
826,
721,
277,
12,
603,
15808,
12,
1324,
63,
576,
12,
5802,
63,
5586,
12,
2644,
29,
403,
304,
267,
408,
267,
11578,
314,
6879,
8416,
2842,
909,
14,
398,
520,
10614,
26,
288,
710,
4465,
1124,
10614,
1040,
2600,
315,
5634,
1056,
2251,
14,
267,
520,
1210,
63,
576,
26,
288,
710,
3066,
2963,
666,
12,
465,
282,
570,
13,
2930,
909,
14,
267,
520,
5064,
63,
5586,
26,
288,
437,
769,
402,
19149,
2461,
4454,
626,
5147,
5331,
641,
314,
14238,
288,
666,
14,
267,
520,
2991,
26,
288,
710,
2644,
543,
1314,
370,
14312,
314,
12467,
666,
14,
267,
408,
398,
327,
267,
327,
6646,
13,
804,
1077,
1395,
15193,
436,
314,
8424,
2556,
14,
267,
327,
398,
1564,
63,
466,
275,
603,
15808,
14,
362,
360,
2856,
63,
9663,
63,
2711,
297,
603,
15808,
14,
362,
360,
9663,
63,
2711,
297,
12381,
267,
340,
440,
1564,
63,
466,
14,
2460,
360,
10123,
26985,
288,
746,
6879,
8416,
21811,
360,
3364,
6646,
13,
804,
26,
450,
83,
7,
450,
1564,
63,
466,
9,
398,
327,
6077,
314,
1406,
370,
664,
314,
8424,
370,
3715,
314,
4184,
14,
267,
5577,
12,
3999,
275,
2198,
63,
1291,
8,
1317,
63,
466,
14,
2143,
360,
4371,
1333,
267,
8424,
275,
3999,
14,
362,
360,
9891,
358,
267,
340,
440,
8424,
503,
440,
16004,
14,
1078,
63,
9891,
8,
9891,
304,
288,
746,
6879,
8416,
21811,
360,
3364,
8424,
315,
15193,
26,
450,
83,
7,
450,
8424,
9,
398,
327,
6646,
13,
4625,
1077,
1395,
314,
2582,
402,
314,
2396,
781,
787,
3595,
267,
327,
370,
9128,
14,
267,
862,
26,
288,
1564,
63,
1267,
275,
1109,
8,
10614,
14,
362,
360,
2856,
63,
9663,
63,
9127,
297,
603,
15808,
14,
362,
360,
9663,
63,
9127,
297,
378,
1724,
267,
871,
334,
3393,
12,
3146,
304,
288,
1564,
63,
1267,
275,
378,
398,
340,
1564,
63,
1267,
665,
378,
26,
288,
327,
961,
4910,
781,
9296,
1133,
1980,
1396,
3730,
376,
1125,
14,
288,
746,
6879,
8416,
21811,
480,
3364,
1564,
2582,
26,
450,
82,
2,
450,
1564,
63,
1267,
9,
398,
340,
1228,
8,
9891,
12,
3816,
14,
505,
63,
466,
304,
288,
8424,
275,
8424,
14,
2143,
360,
4371,
358,
267,
291,
423,
9891,
275,
8424,
267,
291,
423,
1210,
63,
576,
275,
1324,
63,
576,
398,
327,
2104,
7163,
543,
6465,
13,
1896,
2784,
15913,
334,
1045,
4337,
13,
2075,
9446,
395,
267,
327,
314,
3728,
1568,
1077,
506,
665,
499,
62,
2192,
12,
1325,
5139,
487,
6604,
701,
841,
14,
267,
3962,
63,
7723,
275,
359,
88,
14,
4604,
63,
890,
367,
671,
315,
5802,
63,
5586,
340,
671,
14,
4604,
63,
890,
61,
267,
291,
423,
4604,
63,
890,
275,
1748,
779,
18,
1011,
7105,
446,
841,
61,
435,
3962,
63,
7723,
9,
398,
291,
423,
2024,
275,
603,
15808,
267,
291,
423,
2991,
275,
2644,
503,
2202,
14,
3472,
63,
23969,
267,
291,
423,
1317,
63,
1267,
275,
1564,
63,
1267,
267,
291,
423,
5064,
63,
5586,
275,
5802,
63,
5586,
339,
347,
2198,
8,
277,
304,
267,
408,
267,
6077,
314,
8761,
666,
436,
2059,
652,
1901,
282,
16444,
654,
6879,
24811,
436,
282,
8761,
267,
6879,
24811,
14,
398,
1803,
282,
2008,
3035,
314,
8761,
436,
16444,
654,
2600,
12,
17342,
14,
267,
408,
267,
327,
2136,
1172,
370,
492,
8133,
2141,
3224,
2348,
370,
5126,
282,
15032,
492,
14,
267,
687,
1639,
14,
1014,
492,
8133,
2141,
398,
2644,
275,
291,
423,
2991,
267,
8297,
275,
291,
423,
5064,
63,
5586,
398,
327,
3101,
3158,
20065,
626,
6646,
13,
4625,
2356,
378,
365,
1686,
267,
327,
7252,
1564,
13,
1267,
508,
378,
2544,
32620,
267,
340,
291,
423,
1317,
63,
1267,
508,
378,
26,
288,
372,
8133,
2141,
8594,
2644,
29,
277,
423,
2991,
395,
6879,
24811,
342,
398,
327,
1666,
340,
1263,
402,
314,
8297,
5452,
10296,
402,
314,
6057,
14,
267,
327,
961,
6127,
18972,
8137,
340,
1929,
506,
14,
267,
367,
3016,
315,
8297,
26,
288,
754,
275,
3016,
14,
2479,
63,
1773,
63,
1210,
8,
277,
423,
1210,
63,
576,
12,
6343,
291,
423,
2024,
12,
6343,
291,
423,
1317,
63,
1267,
12,
6343,
291,
423,
9891,
12
] |
[
199,
3947,
13,
2064,
6057,
367,
570,
26598,
14,
199,
199,
920,
10553,
1373,
1021,
12,
1124,
3947,
8416,
2842,
4542,
1314,
22295,
8291,
402,
14238,
666,
370,
199,
493,
5802,
8297,
367,
6661,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
1300,
772,
199,
646,
14755,
199,
646,
16004,
199,
646,
984,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
3924,
492,
428,
28651,
27242,
2821,
199,
504,
1639,
14,
1018,
14,
1725,
14,
5064,
2232,
492,
334,
272,
8232,
1173,
12,
8015,
14224,
25096,
12,
8015,
10301,
12,
199,
9,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
23004,
492,
6879,
24811,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
1122,
492,
14342,
199,
504,
1639,
14,
1208,
14,
505,
492,
22221,
63,
8327,
199,
199,
363,
452,
363,
275,
661,
3947,
8416,
2842,
297,
283,
3947,
8416,
21811,
297,
283,
27611,
920,
2411,
7274,
358,
421,
199,
533,
6879,
8416,
21811,
8,
1726,
304,
272,
986,
421,
199,
533,
6924,
3296,
920,
2411,
7274,
8,
1726,
304,
272,
408,
272,
3091,
1655,
11597,
787,
4370,
687,
642,
2243,
14,
272,
408,
272,
986,
199,
199,
4307,
275,
298,
1773,
2,
199,
3817,
275,
298,
493,
2,
199,
8609,
275,
298,
698,
2,
199,
199,
63,
5825,
772,
63,
1093,
6012,
63,
3170,
275,
3146,
340,
3816,
14,
4521,
18,
587,
14755,
14,
547,
421,
199,
533,
6879,
8416,
2842,
8,
785,
304,
272,
408,
272,
437,
18158,
1789,
1299,
15193,
15,
964,
13,
576,
1798,
14,
339,
1124,
3947,
24811,
14,
1122,
8497,
11597,
314,
1324,
2547,
315,
1124,
4604,
63,
890,
1040,
8291,
272,
436,
2529,
282,
2008,
402,
15475,
3947,
24811,
8,
4030,
395,
6879,
24811,
8,
9472,
430,
4345,
272,
408,
272,
347,
636,
826,
721,
277,
12,
603,
15808,
12,
1324,
63,
576,
12,
5802,
63,
5586,
12,
2644,
29,
403,
304,
267,
408,
267,
11578,
314,
6879,
8416,
2842,
909,
14,
398,
520,
10614,
26,
288,
710,
4465,
1124,
10614,
1040,
2600,
315,
5634,
1056,
2251,
14,
267,
520,
1210,
63,
576,
26,
288,
710,
3066,
2963,
666,
12,
465,
282,
570,
13,
2930,
909,
14,
267,
520,
5064,
63,
5586,
26,
288,
437,
769,
402,
19149,
2461,
4454,
626,
5147,
5331,
641,
314,
14238,
288,
666,
14,
267,
520,
2991,
26,
288,
710,
2644,
543,
1314,
370,
14312,
314,
12467,
666,
14,
267,
408,
398,
327,
267,
327,
6646,
13,
804,
1077,
1395,
15193,
436,
314,
8424,
2556,
14,
267,
327,
398,
1564,
63,
466,
275,
603,
15808,
14,
362,
360,
2856,
63,
9663,
63,
2711,
297,
603,
15808,
14,
362,
360,
9663,
63,
2711,
297,
12381,
267,
340,
440,
1564,
63,
466,
14,
2460,
360,
10123,
26985,
288,
746,
6879,
8416,
21811,
360,
3364,
6646,
13,
804,
26,
450,
83,
7,
450,
1564,
63,
466,
9,
398,
327,
6077,
314,
1406,
370,
664,
314,
8424,
370,
3715,
314,
4184,
14,
267,
5577,
12,
3999,
275,
2198,
63,
1291,
8,
1317,
63,
466,
14,
2143,
360,
4371,
1333,
267,
8424,
275,
3999,
14,
362,
360,
9891,
358,
267,
340,
440,
8424,
503,
440,
16004,
14,
1078,
63,
9891,
8,
9891,
304,
288,
746,
6879,
8416,
21811,
360,
3364,
8424,
315,
15193,
26,
450,
83,
7,
450,
8424,
9,
398,
327,
6646,
13,
4625,
1077,
1395,
314,
2582,
402,
314,
2396,
781,
787,
3595,
267,
327,
370,
9128,
14,
267,
862,
26,
288,
1564,
63,
1267,
275,
1109,
8,
10614,
14,
362,
360,
2856,
63,
9663,
63,
9127,
297,
603,
15808,
14,
362,
360,
9663,
63,
9127,
297,
378,
1724,
267,
871,
334,
3393,
12,
3146,
304,
288,
1564,
63,
1267,
275,
378,
398,
340,
1564,
63,
1267,
665,
378,
26,
288,
327,
961,
4910,
781,
9296,
1133,
1980,
1396,
3730,
376,
1125,
14,
288,
746,
6879,
8416,
21811,
480,
3364,
1564,
2582,
26,
450,
82,
2,
450,
1564,
63,
1267,
9,
398,
340,
1228,
8,
9891,
12,
3816,
14,
505,
63,
466,
304,
288,
8424,
275,
8424,
14,
2143,
360,
4371,
358,
267,
291,
423,
9891,
275,
8424,
267,
291,
423,
1210,
63,
576,
275,
1324,
63,
576,
398,
327,
2104,
7163,
543,
6465,
13,
1896,
2784,
15913,
334,
1045,
4337,
13,
2075,
9446,
395,
267,
327,
314,
3728,
1568,
1077,
506,
665,
499,
62,
2192,
12,
1325,
5139,
487,
6604,
701,
841,
14,
267,
3962,
63,
7723,
275,
359,
88,
14,
4604,
63,
890,
367,
671,
315,
5802,
63,
5586,
340,
671,
14,
4604,
63,
890,
61,
267,
291,
423,
4604,
63,
890,
275,
1748,
779,
18,
1011,
7105,
446,
841,
61,
435,
3962,
63,
7723,
9,
398,
291,
423,
2024,
275,
603,
15808,
267,
291,
423,
2991,
275,
2644,
503,
2202,
14,
3472,
63,
23969,
267,
291,
423,
1317,
63,
1267,
275,
1564,
63,
1267,
267,
291,
423,
5064,
63,
5586,
275,
5802,
63,
5586,
339,
347,
2198,
8,
277,
304,
267,
408,
267,
6077,
314,
8761,
666,
436,
2059,
652,
1901,
282,
16444,
654,
6879,
24811,
436,
282,
8761,
267,
6879,
24811,
14,
398,
1803,
282,
2008,
3035,
314,
8761,
436,
16444,
654,
2600,
12,
17342,
14,
267,
408,
267,
327,
2136,
1172,
370,
492,
8133,
2141,
3224,
2348,
370,
5126,
282,
15032,
492,
14,
267,
687,
1639,
14,
1014,
492,
8133,
2141,
398,
2644,
275,
291,
423,
2991,
267,
8297,
275,
291,
423,
5064,
63,
5586,
398,
327,
3101,
3158,
20065,
626,
6646,
13,
4625,
2356,
378,
365,
1686,
267,
327,
7252,
1564,
13,
1267,
508,
378,
2544,
32620,
267,
340,
291,
423,
1317,
63,
1267,
508,
378,
26,
288,
372,
8133,
2141,
8594,
2644,
29,
277,
423,
2991,
395,
6879,
24811,
342,
398,
327,
1666,
340,
1263,
402,
314,
8297,
5452,
10296,
402,
314,
6057,
14,
267,
327,
961,
6127,
18972,
8137,
340,
1929,
506,
14,
267,
367,
3016,
315,
8297,
26,
288,
754,
275,
3016,
14,
2479,
63,
1773,
63,
1210,
8,
277,
423,
1210,
63,
576,
12,
6343,
291,
423,
2024,
12,
6343,
291,
423,
1317,
63,
1267,
12,
6343,
291,
423,
9891,
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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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
] |
mdietrichc2c/OCB
|
addons/stock/wizard/stock_move.py
|
111
|
3844
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields, osv
from openerp.tools.translate import _
import openerp.addons.decimal_precision as dp
class stock_move_scrap(osv.osv_memory):
_name = "stock.move.scrap"
_description = "Scrap Products"
_columns = {
'product_id': fields.many2one('product.product', 'Product', required=True, select=True),
'product_qty': fields.float('Quantity', digits_compute=dp.get_precision('Product Unit of Measure'), required=True),
'product_uom': fields.many2one('product.uom', 'Product Unit of Measure', required=True),
'location_id': fields.many2one('stock.location', 'Location', required=True),
'restrict_lot_id': fields.many2one('stock.production.lot', 'Lot'),
}
_defaults = {
'location_id': lambda *x: False
}
def default_get(self, cr, uid, fields, context=None):
""" Get default values
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param fields: List of fields for default value
@param context: A standard dictionary
@return: default values of fields
"""
if context is None:
context = {}
res = super(stock_move_scrap, self).default_get(cr, uid, fields, context=context)
move = self.pool.get('stock.move').browse(cr, uid, context['active_id'], context=context)
location_obj = self.pool.get('stock.location')
scrap_location_id = location_obj.search(cr, uid, [('scrap_location','=',True)])
if 'product_id' in fields:
res.update({'product_id': move.product_id.id})
if 'product_uom' in fields:
res.update({'product_uom': move.product_uom.id})
if 'location_id' in fields:
if scrap_location_id:
res.update({'location_id': scrap_location_id[0]})
else:
res.update({'location_id': False})
return res
def move_scrap(self, cr, uid, ids, context=None):
""" To move scrapped products
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param ids: the ID or list of IDs if we want more than one
@param context: A standard dictionary
@return:
"""
if context is None:
context = {}
move_obj = self.pool.get('stock.move')
move_ids = context['active_ids']
for data in self.browse(cr, uid, ids):
move_obj.action_scrap(cr, uid, move_ids,
data.product_qty, data.location_id.id, restrict_lot_id=data.restrict_lot_id.id,
context=context)
return {'type': 'ir.actions.act_window_close'}
# 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,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
646,
5166,
14,
10788,
14,
6355,
63,
6833,
465,
12392,
4388,
199,
533,
10952,
63,
1185,
63,
551,
1330,
8,
4795,
14,
4795,
63,
4844,
304,
272,
485,
354,
275,
298,
6088,
14,
1185,
14,
551,
1330,
2,
272,
485,
1802,
275,
298,
7181,
1330,
32411,
2,
339,
485,
3406,
275,
469,
267,
283,
2558,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
2558,
14,
2558,
297,
283,
5884,
297,
1415,
29,
549,
12,
3504,
29,
549,
395,
267,
283,
2558,
63,
5643,
356,
1504,
14,
1609,
360,
19703,
297,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
5884,
12008,
402,
22933,
659,
1415,
29,
549,
395,
267,
283,
2558,
63,
7519,
356,
1504,
14,
3479,
18,
368,
360,
2558,
14,
7519,
297,
283,
5884,
12008,
402,
22933,
297,
1415,
29,
549,
395,
267,
283,
1985,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
6088,
14,
1985,
297,
283,
6592,
297,
1415,
29,
549,
395,
267,
283,
22188,
63,
1653,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
6088,
14,
10777,
14,
1653,
297,
283,
44,
357,
659,
272,
789,
339,
485,
4322,
275,
469,
267,
283,
1985,
63,
344,
356,
2400,
627,
88,
26,
756,
272,
789,
339,
347,
849,
63,
362,
8,
277,
12,
2467,
12,
1747,
12,
1504,
12,
1067,
29,
403,
304,
267,
408,
2372,
849,
1338,
267,
768,
635,
291,
26,
710,
909,
7849,
14,
267,
768,
635,
2467,
26,
437,
3050,
3920,
267,
768,
635,
1747,
26,
2870,
402,
314,
922,
5544,
10367,
315,
267,
768,
635,
1504,
26,
3820,
402,
1504,
367,
849,
574,
267,
768,
635,
1067,
26,
437,
4465,
2600,
267,
768,
1107,
26,
849,
1338,
402,
1504,
267,
408,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
522,
275,
1613,
8,
6088,
63,
1185,
63,
551,
1330,
12,
291,
680,
885,
63,
362,
8,
1556,
12,
1747,
12,
1504,
12,
1067,
29,
1100,
9,
267,
4057,
275,
291,
14,
2293,
14,
362,
360,
6088,
14,
1185,
1959,
4570,
8,
1556,
12,
1747,
12,
1067,
459,
2682,
63,
344,
995,
1067,
29,
1100,
9,
398,
2909,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
6088,
14,
1985,
358,
267,
4061,
1330,
63,
1985,
63,
344,
275,
2909,
63,
1113,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
551,
1330,
63,
1985,
18937,
549,
3948,
398,
340,
283,
2558,
63,
344,
7,
315,
1504,
26,
288,
522,
14,
873,
3252,
2558,
63,
344,
356,
4057,
14,
2558,
63,
344,
14,
344,
1552,
267,
340,
283,
2558,
63,
7519,
7,
315,
1504,
26,
288,
522,
14,
873,
3252,
2558,
63,
7519,
356,
4057,
14,
2558,
63,
7519,
14,
344,
1552,
267,
340,
283,
1985,
63,
344,
7,
315,
1504,
26,
288,
340,
4061,
1330,
63,
1985,
63,
344,
26,
355,
522,
14,
873,
3252,
1985,
63,
344,
356,
4061,
1330,
63,
1985,
63,
344,
59,
16,
13412,
288,
587,
26,
355,
522,
14,
873,
3252,
1985,
63,
344,
356,
756,
1552,
267,
372,
522,
339,
347,
4057,
63,
551,
1330,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
408,
4005,
4057,
4061,
1330,
1915,
7585,
267,
768,
635,
291,
26,
710,
909,
7849,
14,
267,
768,
635,
2467,
26,
437,
3050,
3920,
267,
768,
635,
1747,
26,
2870,
402,
314,
922,
5544,
10367,
315,
267,
768,
635,
2762,
26,
314,
2870,
503,
769,
402,
11449,
340,
781,
2934,
1655,
2419,
1373,
267,
768,
635,
1067,
26,
437,
4465,
2600,
267,
768,
1107,
26,
267,
408,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
4057,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
6088,
14,
1185,
358,
267,
4057,
63,
1580,
275,
1067,
459,
2682,
63,
1580,
418,
267,
367,
666,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
304,
288,
4057,
63,
1113,
14,
1287,
63,
551,
1330,
8,
1556,
12,
1747,
12,
4057,
63,
1580,
12,
2490,
666,
14,
2558,
63,
5643,
12,
666,
14,
1985,
63,
344,
14,
344,
12,
18152,
63,
1653,
63,
344,
29,
576,
14,
22188,
63,
1653,
63,
344,
14,
344,
12,
2490,
1067,
29,
1100,
9,
267,
372,
791,
466,
356,
283,
723,
14,
3723,
14,
2442,
63,
3806,
63,
1600,
936,
4388,
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
] |
[
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,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
646,
5166,
14,
10788,
14,
6355,
63,
6833,
465,
12392,
4388,
199,
533,
10952,
63,
1185,
63,
551,
1330,
8,
4795,
14,
4795,
63,
4844,
304,
272,
485,
354,
275,
298,
6088,
14,
1185,
14,
551,
1330,
2,
272,
485,
1802,
275,
298,
7181,
1330,
32411,
2,
339,
485,
3406,
275,
469,
267,
283,
2558,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
2558,
14,
2558,
297,
283,
5884,
297,
1415,
29,
549,
12,
3504,
29,
549,
395,
267,
283,
2558,
63,
5643,
356,
1504,
14,
1609,
360,
19703,
297,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
5884,
12008,
402,
22933,
659,
1415,
29,
549,
395,
267,
283,
2558,
63,
7519,
356,
1504,
14,
3479,
18,
368,
360,
2558,
14,
7519,
297,
283,
5884,
12008,
402,
22933,
297,
1415,
29,
549,
395,
267,
283,
1985,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
6088,
14,
1985,
297,
283,
6592,
297,
1415,
29,
549,
395,
267,
283,
22188,
63,
1653,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
6088,
14,
10777,
14,
1653,
297,
283,
44,
357,
659,
272,
789,
339,
485,
4322,
275,
469,
267,
283,
1985,
63,
344,
356,
2400,
627,
88,
26,
756,
272,
789,
339,
347,
849,
63,
362,
8,
277,
12,
2467,
12,
1747,
12,
1504,
12,
1067,
29,
403,
304,
267,
408,
2372,
849,
1338,
267,
768,
635,
291,
26,
710,
909,
7849,
14,
267,
768,
635,
2467,
26,
437,
3050,
3920,
267,
768,
635,
1747,
26,
2870,
402,
314,
922,
5544,
10367,
315,
267,
768,
635,
1504,
26,
3820,
402,
1504,
367,
849,
574,
267,
768,
635,
1067,
26,
437,
4465,
2600,
267,
768,
1107,
26,
849,
1338,
402,
1504,
267,
408,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
522,
275,
1613,
8,
6088,
63,
1185,
63,
551,
1330,
12,
291,
680,
885,
63,
362,
8,
1556,
12,
1747,
12,
1504,
12,
1067,
29,
1100,
9,
267,
4057,
275,
291,
14,
2293,
14,
362,
360,
6088,
14,
1185,
1959,
4570,
8,
1556,
12,
1747,
12,
1067,
459,
2682,
63,
344,
995,
1067,
29,
1100,
9,
398,
2909,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
6088,
14,
1985,
358,
267,
4061,
1330,
63,
1985,
63,
344,
275,
2909,
63,
1113,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
551,
1330,
63,
1985,
18937,
549,
3948,
398,
340,
283,
2558,
63,
344,
7,
315,
1504,
26,
288,
522,
14,
873,
3252,
2558,
63,
344,
356,
4057,
14,
2558,
63,
344,
14,
344,
1552,
267,
340,
283,
2558,
63,
7519,
7,
315,
1504,
26,
288,
522,
14,
873,
3252,
2558,
63,
7519,
356,
4057,
14,
2558,
63,
7519,
14,
344,
1552,
267,
340,
283,
1985,
63,
344,
7,
315,
1504,
26,
288,
340,
4061,
1330,
63,
1985,
63,
344,
26,
355,
522,
14,
873,
3252,
1985,
63,
344,
356,
4061,
1330,
63,
1985,
63,
344,
59,
16,
13412,
288,
587,
26,
355,
522,
14,
873,
3252,
1985,
63,
344,
356,
756,
1552,
267,
372,
522,
339,
347,
4057,
63,
551,
1330,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
408,
4005,
4057,
4061,
1330,
1915,
7585,
267,
768,
635,
291,
26,
710,
909,
7849,
14,
267,
768,
635,
2467,
26,
437,
3050,
3920,
267,
768,
635,
1747,
26,
2870,
402,
314,
922,
5544,
10367,
315,
267,
768,
635,
2762,
26,
314,
2870,
503,
769,
402,
11449,
340,
781,
2934,
1655,
2419,
1373,
267,
768,
635,
1067,
26,
437,
4465,
2600,
267,
768,
1107,
26,
267,
408,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
4057,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
6088,
14,
1185,
358,
267,
4057,
63,
1580,
275,
1067,
459,
2682,
63,
1580,
418,
267,
367,
666,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
304,
288,
4057,
63,
1113,
14,
1287,
63,
551,
1330,
8,
1556,
12,
1747,
12,
4057,
63,
1580,
12,
2490,
666,
14,
2558,
63,
5643,
12,
666,
14,
1985,
63,
344,
14,
344,
12,
18152,
63,
1653,
63,
344,
29,
576,
14,
22188,
63,
1653,
63,
344,
14,
344,
12,
2490,
1067,
29,
1100,
9,
267,
372,
791,
466,
356,
283,
723,
14,
3723,
14,
2442,
63,
3806,
63,
1600,
936,
4388,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
IndonesiaX/edx-platform
|
lms/djangoapps/student_account/test/test_views.py
|
20
|
20748
|
# -*- coding: utf-8 -*-
""" Tests for student account views. """
import re
from unittest import skipUnless
from urllib import urlencode
import json
import mock
import ddt
from django.conf import settings
from django.core.urlresolvers import reverse
from django.core import mail
from django.contrib import messages
from django.contrib.messages.middleware import MessageMiddleware
from django.test import TestCase
from django.test.utils import override_settings
from django.http import HttpRequest
from course_modes.models import CourseMode
from openedx.core.djangoapps.user_api.accounts.api import activate_account, create_account
from openedx.core.djangoapps.user_api.accounts import EMAIL_MAX_LENGTH
from openedx.core.lib.js_utils import escape_json_dumps
from student.tests.factories import UserFactory
from student_account.views import account_settings_context
from third_party_auth.tests.testutil import simulate_running_pipeline, ThirdPartyAuthTestMixin
from util.testing import UrlResetMixin
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
@ddt.ddt
class StudentAccountUpdateTest(UrlResetMixin, TestCase):
""" Tests for the student account views that update the user's account information. """
USERNAME = u"heisenberg"
ALTERNATE_USERNAME = u"walt"
OLD_PASSWORD = u"ḅḷüëṡḳÿ"
NEW_PASSWORD = u"🄱🄸🄶🄱🄻🅄🄴"
OLD_EMAIL = u"walter@graymattertech.com"
NEW_EMAIL = u"walt@savewalterwhite.com"
INVALID_ATTEMPTS = 100
INVALID_EMAILS = [
None,
u"",
u"a",
"no_domain",
"no+domain",
"@",
"@domain.com",
"test@no_extension",
# Long email -- subtract the length of the @domain
# except for one character (so we exceed the max length limit)
u"{user}@example.com".format(
user=(u'e' * (EMAIL_MAX_LENGTH - 11))
)
]
INVALID_KEY = u"123abc"
def setUp(self):
super(StudentAccountUpdateTest, self).setUp("student_account.urls")
# Create/activate a new account
activation_key = create_account(self.USERNAME, self.OLD_PASSWORD, self.OLD_EMAIL)
activate_account(activation_key)
# Login
result = self.client.login(username=self.USERNAME, password=self.OLD_PASSWORD)
self.assertTrue(result)
@skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in LMS')
def test_password_change(self):
# Request a password change while logged in, simulating
# use of the password reset link from the account page
response = self._change_password()
self.assertEqual(response.status_code, 200)
# Check that an email was sent
self.assertEqual(len(mail.outbox), 1)
# Retrieve the activation link from the email body
email_body = mail.outbox[0].body
result = re.search('(?P<url>https?://[^\s]+)', email_body)
self.assertIsNot(result, None)
activation_link = result.group('url')
# Visit the activation link
response = self.client.get(activation_link)
self.assertEqual(response.status_code, 200)
# Submit a new password and follow the redirect to the success page
response = self.client.post(
activation_link,
# These keys are from the form on the current password reset confirmation page.
{'new_password1': self.NEW_PASSWORD, 'new_password2': self.NEW_PASSWORD},
follow=True
)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Your password has been set.")
# Log the user out to clear session data
self.client.logout()
# Verify that the new password can be used to log in
result = self.client.login(username=self.USERNAME, password=self.NEW_PASSWORD)
self.assertTrue(result)
# Try reusing the activation link to change the password again
response = self.client.post(
activation_link,
{'new_password1': self.OLD_PASSWORD, 'new_password2': self.OLD_PASSWORD},
follow=True
)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "The password reset link was invalid, possibly because the link has already been used.")
self.client.logout()
# Verify that the old password cannot be used to log in
result = self.client.login(username=self.USERNAME, password=self.OLD_PASSWORD)
self.assertFalse(result)
# Verify that the new password continues to be valid
result = self.client.login(username=self.USERNAME, password=self.NEW_PASSWORD)
self.assertTrue(result)
@ddt.data(True, False)
def test_password_change_logged_out(self, send_email):
# Log the user out
self.client.logout()
# Request a password change while logged out, simulating
# use of the password reset link from the login page
if send_email:
response = self._change_password(email=self.OLD_EMAIL)
self.assertEqual(response.status_code, 200)
else:
# Don't send an email in the POST data, simulating
# its (potentially accidental) omission in the POST
# data sent from the login page
response = self._change_password()
self.assertEqual(response.status_code, 400)
def test_password_change_inactive_user(self):
# Log out the user created during test setup
self.client.logout()
# Create a second user, but do not activate it
create_account(self.ALTERNATE_USERNAME, self.OLD_PASSWORD, self.NEW_EMAIL)
# Send the view the email address tied to the inactive user
response = self._change_password(email=self.NEW_EMAIL)
# Expect that the activation email is still sent,
# since the user may have lost the original activation email.
self.assertEqual(response.status_code, 200)
self.assertEqual(len(mail.outbox), 1)
def test_password_change_no_user(self):
# Log out the user created during test setup
self.client.logout()
# Send the view an email address not tied to any user
response = self._change_password(email=self.NEW_EMAIL)
self.assertEqual(response.status_code, 400)
def test_password_change_rate_limited(self):
# Log out the user created during test setup, to prevent the view from
# selecting the logged-in user's email address over the email provided
# in the POST data
self.client.logout()
# Make many consecutive bad requests in an attempt to trigger the rate limiter
for attempt in xrange(self.INVALID_ATTEMPTS):
self._change_password(email=self.NEW_EMAIL)
response = self._change_password(email=self.NEW_EMAIL)
self.assertEqual(response.status_code, 403)
@ddt.data(
('post', 'password_change_request', []),
)
@ddt.unpack
def test_require_http_method(self, correct_method, url_name, args):
wrong_methods = {'get', 'put', 'post', 'head', 'options', 'delete'} - {correct_method}
url = reverse(url_name, args=args)
for method in wrong_methods:
response = getattr(self.client, method)(url)
self.assertEqual(response.status_code, 405)
def _change_password(self, email=None):
"""Request to change the user's password. """
data = {}
if email:
data['email'] = email
return self.client.post(path=reverse('password_change_request'), data=data)
@ddt.ddt
class StudentAccountLoginAndRegistrationTest(ThirdPartyAuthTestMixin, UrlResetMixin, ModuleStoreTestCase):
""" Tests for the student account views that update the user's account information. """
USERNAME = "bob"
EMAIL = "bob@example.com"
PASSWORD = "password"
@mock.patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self):
super(StudentAccountLoginAndRegistrationTest, self).setUp('embargo')
# For these tests, two third party auth providers are enabled by default:
self.configure_google_provider(enabled=True)
self.configure_facebook_provider(enabled=True)
@ddt.data(
("signin_user", "login"),
("register_user", "register"),
)
@ddt.unpack
def test_login_and_registration_form(self, url_name, initial_mode):
response = self.client.get(reverse(url_name))
expected_data = '"initial_mode": "{mode}"'.format(mode=initial_mode)
self.assertContains(response, expected_data)
@ddt.data("signin_user", "register_user")
def test_login_and_registration_form_already_authenticated(self, url_name):
# Create/activate a new account and log in
activation_key = create_account(self.USERNAME, self.PASSWORD, self.EMAIL)
activate_account(activation_key)
result = self.client.login(username=self.USERNAME, password=self.PASSWORD)
self.assertTrue(result)
# Verify that we're redirected to the dashboard
response = self.client.get(reverse(url_name))
self.assertRedirects(response, reverse("dashboard"))
@ddt.data(
(False, "signin_user"),
(False, "register_user"),
(True, "signin_user"),
(True, "register_user"),
)
@ddt.unpack
def test_login_and_registration_form_signin_preserves_params(self, is_edx_domain, url_name):
params = [
('course_id', 'edX/DemoX/Demo_Course'),
('enrollment_action', 'enroll'),
]
# The response should have a "Sign In" button with the URL
# that preserves the querystring params
with mock.patch.dict(settings.FEATURES, {'IS_EDX_DOMAIN': is_edx_domain}):
response = self.client.get(reverse(url_name), params)
expected_url = '/login?{}'.format(self._finish_auth_url_param(params + [('next', '/dashboard')]))
self.assertContains(response, expected_url)
# Add additional parameters:
params = [
('course_id', 'edX/DemoX/Demo_Course'),
('enrollment_action', 'enroll'),
('course_mode', CourseMode.DEFAULT_MODE_SLUG),
('email_opt_in', 'true'),
('next', '/custom/final/destination')
]
# Verify that this parameter is also preserved
with mock.patch.dict(settings.FEATURES, {'IS_EDX_DOMAIN': is_edx_domain}):
response = self.client.get(reverse(url_name), params)
expected_url = '/login?{}'.format(self._finish_auth_url_param(params))
self.assertContains(response, expected_url)
@mock.patch.dict(settings.FEATURES, {"ENABLE_THIRD_PARTY_AUTH": False})
@ddt.data("signin_user", "register_user")
def test_third_party_auth_disabled(self, url_name):
response = self.client.get(reverse(url_name))
self._assert_third_party_auth_data(response, None, None, [])
@ddt.data(
("signin_user", None, None),
("register_user", None, None),
("signin_user", "google-oauth2", "Google"),
("register_user", "google-oauth2", "Google"),
("signin_user", "facebook", "Facebook"),
("register_user", "facebook", "Facebook"),
)
@ddt.unpack
def test_third_party_auth(self, url_name, current_backend, current_provider):
params = [
('course_id', 'course-v1:Org+Course+Run'),
('enrollment_action', 'enroll'),
('course_mode', CourseMode.DEFAULT_MODE_SLUG),
('email_opt_in', 'true'),
('next', '/custom/final/destination'),
]
# Simulate a running pipeline
if current_backend is not None:
pipeline_target = "student_account.views.third_party_auth.pipeline"
with simulate_running_pipeline(pipeline_target, current_backend):
response = self.client.get(reverse(url_name), params)
# Do NOT simulate a running pipeline
else:
response = self.client.get(reverse(url_name), params)
# This relies on the THIRD_PARTY_AUTH configuration in the test settings
expected_providers = [
{
"id": "oa2-facebook",
"name": "Facebook",
"iconClass": "fa-facebook",
"loginUrl": self._third_party_login_url("facebook", "login", params),
"registerUrl": self._third_party_login_url("facebook", "register", params)
},
{
"id": "oa2-google-oauth2",
"name": "Google",
"iconClass": "fa-google-plus",
"loginUrl": self._third_party_login_url("google-oauth2", "login", params),
"registerUrl": self._third_party_login_url("google-oauth2", "register", params)
}
]
self._assert_third_party_auth_data(response, current_backend, current_provider, expected_providers)
def test_hinted_login(self):
params = [("next", "/courses/something/?tpa_hint=oa2-google-oauth2")]
response = self.client.get(reverse('signin_user'), params)
self.assertContains(response, '"third_party_auth_hint": "oa2-google-oauth2"')
@override_settings(SITE_NAME=settings.MICROSITE_TEST_HOSTNAME)
def test_microsite_uses_old_login_page(self):
# Retrieve the login page from a microsite domain
# and verify that we're served the old page.
resp = self.client.get(
reverse("signin_user"),
HTTP_HOST=settings.MICROSITE_TEST_HOSTNAME
)
self.assertContains(resp, "Log into your Test Microsite Account")
self.assertContains(resp, "login-form")
def test_microsite_uses_old_register_page(self):
# Retrieve the register page from a microsite domain
# and verify that we're served the old page.
resp = self.client.get(
reverse("register_user"),
HTTP_HOST=settings.MICROSITE_TEST_HOSTNAME
)
self.assertContains(resp, "Register for Test Microsite")
self.assertContains(resp, "register-form")
def test_login_registration_xframe_protected(self):
resp = self.client.get(
reverse("register_user"),
{},
HTTP_REFERER="http://localhost/iframe"
)
self.assertEqual(resp['X-Frame-Options'], 'DENY')
self.configure_lti_provider(name='Test', lti_hostname='localhost', lti_consumer_key='test_key', enabled=True)
resp = self.client.get(
reverse("register_user"),
HTTP_REFERER="http://localhost/iframe"
)
self.assertEqual(resp['X-Frame-Options'], 'ALLOW')
def _assert_third_party_auth_data(self, response, current_backend, current_provider, providers):
"""Verify that third party auth info is rendered correctly in a DOM data attribute. """
finish_auth_url = None
if current_backend:
finish_auth_url = reverse("social:complete", kwargs={"backend": current_backend}) + "?"
auth_info = {
"currentProvider": current_provider,
"providers": providers,
"secondaryProviders": [],
"finishAuthUrl": finish_auth_url,
"errorMessage": None,
}
auth_info = escape_json_dumps(auth_info)
expected_data = '"third_party_auth": {auth_info}'.format(
auth_info=auth_info
)
self.assertContains(response, expected_data)
def _third_party_login_url(self, backend_name, auth_entry, login_params):
"""Construct the login URL to start third party authentication. """
return u"{url}?auth_entry={auth_entry}&{param_str}".format(
url=reverse("social:begin", kwargs={"backend": backend_name}),
auth_entry=auth_entry,
param_str=self._finish_auth_url_param(login_params),
)
def _finish_auth_url_param(self, params):
"""
Make the next=... URL parameter that indicates where the user should go next.
>>> _finish_auth_url_param([('next', '/dashboard')])
'/account/finish_auth?next=%2Fdashboard'
"""
return urlencode({
'next': '/account/finish_auth?{}'.format(urlencode(params))
})
class AccountSettingsViewTest(ThirdPartyAuthTestMixin, TestCase):
""" Tests for the account settings view. """
USERNAME = 'student'
PASSWORD = 'password'
FIELDS = [
'country',
'gender',
'language',
'level_of_education',
'password',
'year_of_birth',
'preferred_language',
]
@mock.patch("django.conf.settings.MESSAGE_STORAGE", 'django.contrib.messages.storage.cookie.CookieStorage')
def setUp(self):
super(AccountSettingsViewTest, self).setUp()
self.user = UserFactory.create(username=self.USERNAME, password=self.PASSWORD)
self.client.login(username=self.USERNAME, password=self.PASSWORD)
self.request = HttpRequest()
self.request.user = self.user
# For these tests, two third party auth providers are enabled by default:
self.configure_google_provider(enabled=True)
self.configure_facebook_provider(enabled=True)
# Python-social saves auth failure notifcations in Django messages.
# See pipeline.get_duplicate_provider() for details.
self.request.COOKIES = {}
MessageMiddleware().process_request(self.request)
messages.error(self.request, 'Facebook is already in use.', extra_tags='Auth facebook')
def test_context(self):
context = account_settings_context(self.request)
user_accounts_api_url = reverse("accounts_api", kwargs={'username': self.user.username})
self.assertEqual(context['user_accounts_api_url'], user_accounts_api_url)
user_preferences_api_url = reverse('preferences_api', kwargs={'username': self.user.username})
self.assertEqual(context['user_preferences_api_url'], user_preferences_api_url)
for attribute in self.FIELDS:
self.assertIn(attribute, context['fields'])
self.assertEqual(
context['user_accounts_api_url'], reverse("accounts_api", kwargs={'username': self.user.username})
)
self.assertEqual(
context['user_preferences_api_url'], reverse('preferences_api', kwargs={'username': self.user.username})
)
self.assertEqual(context['duplicate_provider'], 'facebook')
self.assertEqual(context['auth']['providers'][0]['name'], 'Facebook')
self.assertEqual(context['auth']['providers'][1]['name'], 'Google')
def test_view(self):
view_path = reverse('account_settings')
response = self.client.get(path=view_path)
for attribute in self.FIELDS:
self.assertIn(attribute, response.content)
@override_settings(SITE_NAME=settings.MICROSITE_LOGISTRATION_HOSTNAME)
class MicrositeLogistrationTests(TestCase):
"""
Test to validate that microsites can display the logistration page
"""
def test_login_page(self):
"""
Make sure that we get the expected logistration page on our specialized
microsite
"""
resp = self.client.get(
reverse('signin_user'),
HTTP_HOST=settings.MICROSITE_LOGISTRATION_HOSTNAME
)
self.assertEqual(resp.status_code, 200)
self.assertIn('<div id="login-and-registration-container"', resp.content)
def test_registration_page(self):
"""
Make sure that we get the expected logistration page on our specialized
microsite
"""
resp = self.client.get(
reverse('register_user'),
HTTP_HOST=settings.MICROSITE_LOGISTRATION_HOSTNAME
)
self.assertEqual(resp.status_code, 200)
self.assertIn('<div id="login-and-registration-container"', resp.content)
@override_settings(SITE_NAME=settings.MICROSITE_TEST_HOSTNAME)
def test_no_override(self):
"""
Make sure we get the old style login/registration if we don't override
"""
resp = self.client.get(
reverse('signin_user'),
HTTP_HOST=settings.MICROSITE_TEST_HOSTNAME
)
self.assertEqual(resp.status_code, 200)
self.assertNotIn('<div id="login-and-registration-container"', resp.content)
resp = self.client.get(
reverse('register_user'),
HTTP_HOST=settings.MICROSITE_TEST_HOSTNAME
)
self.assertEqual(resp.status_code, 200)
self.assertNotIn('<div id="login-and-registration-container"', resp.content)
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
6496,
367,
6474,
2933,
6858,
14,
408,
199,
199,
646,
295,
199,
504,
2882,
492,
3372,
5524,
199,
504,
4011,
492,
16511,
199,
646,
2022,
199,
199,
646,
1683,
199,
646,
366,
3583,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1018,
492,
6016,
199,
504,
1639,
14,
2828,
492,
3788,
199,
504,
1639,
14,
2828,
14,
3431,
14,
5754,
492,
6430,
6608,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
504,
1639,
14,
1014,
492,
20730,
199,
199,
504,
2518,
63,
10433,
14,
992,
492,
27312,
199,
504,
22709,
14,
1018,
14,
16432,
14,
751,
63,
1246,
14,
8370,
14,
1246,
492,
15422,
63,
2048,
12,
1218,
63,
2048,
199,
504,
22709,
14,
1018,
14,
16432,
14,
751,
63,
1246,
14,
8370,
492,
32320,
63,
4283,
63,
9127,
199,
504,
22709,
14,
1018,
14,
773,
14,
3596,
63,
1208,
492,
4772,
63,
1001,
63,
4180,
199,
504,
6474,
14,
2219,
14,
15406,
492,
16047,
199,
504,
6474,
63,
2048,
14,
4196,
492,
2933,
63,
1751,
63,
1100,
199,
504,
10919,
63,
7522,
63,
1178,
14,
2219,
14,
396,
1974,
492,
20577,
63,
5720,
63,
7379,
12,
31079,
25233,
2817,
22060,
199,
504,
4884,
14,
4776,
492,
20503,
9637,
4256,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
17996,
1746,
421,
199,
32,
11138,
14,
11138,
199,
533,
17246,
6009,
4152,
774,
8,
6417,
9637,
4256,
12,
7640,
304,
272,
408,
6496,
367,
314,
6474,
2933,
6858,
626,
1678,
314,
922,
1159,
2933,
2556,
14,
408,
339,
13044,
2339,
275,
399,
2,
426,
572,
78,
14630,
2,
272,
12112,
7689,
1951,
63,
11958,
275,
399,
2,
87,
4478,
2,
272,
593,
6533,
63,
9032,
275,
399,
2,
158,
117,
228,
158,
117,
116,
17709,
128,
105,
158,
118,
95,
158,
117,
112,
128,
124,
2,
272,
18689,
63,
9032,
275,
399,
2,
173,
254,
227,
110,
173,
254,
227,
117,
173,
254,
227,
115,
173,
254,
227,
110,
173,
254,
227,
120,
173,
254,
228,
227,
173,
254,
227,
113,
2,
272,
593,
6533,
63,
10089,
275,
399,
2,
87,
11858,
32,
12150,
569,
351,
15970,
14,
957,
2,
272,
18689,
63,
10089,
275,
399,
2,
87,
4478,
32,
2117,
87,
11858,
7510,
14,
957,
2,
339,
29901,
63,
619,
12510,
9730,
275,
2948,
339,
29901,
63,
10089,
51,
275,
359,
267,
488,
12,
267,
399,
5151,
267,
399,
2,
65,
401,
267,
298,
889,
63,
2261,
401,
267,
298,
889,
11,
2261,
401,
267,
9244,
401,
267,
9244,
2261,
14,
957,
401,
267,
298,
396,
32,
889,
63,
3435,
401,
398,
327,
19944,
3031,
1553,
24129,
314,
2582,
402,
314,
768,
2261,
267,
327,
871,
367,
1373,
4528,
334,
1152,
781,
24068,
314,
1390,
2582,
2304,
9,
267,
399,
14381,
751,
93,
32,
2694,
14,
957,
1674,
908,
8,
288,
922,
2687,
85,
7,
69,
7,
627,
334,
10089,
63,
4283,
63,
9127,
446,
4119,
430,
267,
776,
272,
1622,
339,
29901,
63,
3078,
275,
399,
2,
4288,
3175,
2,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
18086,
6009,
4152,
774,
12,
291,
680,
5996,
480,
5500,
63,
2048,
14,
3603,
531,
398,
327,
2790,
15,
8222,
282,
892,
2933,
267,
10361,
63,
498,
275,
1218,
63,
2048,
8,
277,
14,
11958,
12,
291,
14,
5104,
63,
9032,
12,
291,
14,
5104,
63,
10089,
9,
267,
15422,
63,
2048,
8,
12312,
63,
498,
9,
398,
327,
16430,
267,
754,
275,
291,
14,
1258,
14,
2886,
8,
2473,
29,
277,
14,
11958,
12,
2505,
29,
277,
14,
5104,
63,
9032,
9,
267,
291,
14,
1815,
8,
1099,
9,
339,
768,
11278,
8,
1751,
14,
5441,
63,
18125,
508,
283,
15807,
14,
3603,
297,
283,
774,
1454,
1686,
315,
27540,
358,
272,
347,
511,
63,
2060,
63,
1461,
8,
277,
304,
267,
327,
4784,
282,
2505,
1570,
1830,
10367,
315,
12,
4389,
20529,
267,
327,
675,
402,
314,
2505,
5305,
2142,
687,
314,
2933,
2034,
267,
1177,
275,
291,
423,
1461,
63,
2060,
342,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
398,
327,
2670,
626,
376,
3031,
1990,
4847,
267,
291,
14,
629,
8,
552,
8,
1198,
14,
17244,
395,
413,
9,
398,
327,
13939,
314,
10361,
2142,
687,
314,
3031,
2396,
267,
3031,
63,
2030,
275,
6016,
14,
17244,
59,
16,
1055,
2030,
267,
754,
275,
295,
14,
1733,
28353,
48,
28,
633,
30,
2859,
14144,
16045,
83,
28798,
3031,
63,
2030,
9,
267,
291,
14,
9422,
8,
1099,
12,
488,
9,
267,
10361,
63,
1073,
275,
754,
14,
923,
360,
633,
358,
398,
327,
29614,
314,
10361,
2142,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
12312,
63,
1073,
9,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
398,
327,
28295,
282,
892,
2505,
436,
2035,
314,
4660,
370,
314,
3182,
2034,
267,
1177,
275,
291,
14,
1258,
14,
1932,
8,
288,
10361,
63,
1073,
12,
288,
327,
5723,
2883,
787,
687,
314,
1824,
641,
314,
1453,
2505,
5305,
18791,
2034,
14,
288,
791,
1222,
63,
2060,
17,
356,
291,
14,
11365,
63,
9032,
12,
283,
1222,
63,
2060,
18,
356,
291,
14,
11365,
63,
9032,
1386,
288,
2035,
29,
549,
267,
776,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
291,
14,
9535,
8,
1310,
12,
298,
14398,
2505,
965,
2757,
663,
2685,
398,
327,
5297,
314,
922,
734,
370,
5436,
2351,
666,
267,
291,
14,
1258,
14,
11646,
342,
398,
327,
7635,
626,
314,
892,
2505,
883,
506,
1202,
370,
943,
315,
267,
754,
275,
291,
14,
1258,
14,
2886,
8,
2473,
29,
277,
14,
11958,
12,
2505,
29,
277,
14,
11365,
63,
9032,
9,
267,
291,
14,
1815,
8,
1099,
9,
398,
327,
7649,
295,
4941,
314,
10361,
2142,
370,
1570,
314,
2505,
4020,
267,
1177,
275,
291,
14,
1258,
14,
1932,
8,
288,
10361,
63,
1073,
12,
288,
791,
1222,
63,
2060,
17,
356,
291,
14,
5104,
63,
9032,
12,
283,
1222
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
6496,
367,
6474,
2933,
6858,
14,
408,
199,
199,
646,
295,
199,
504,
2882,
492,
3372,
5524,
199,
504,
4011,
492,
16511,
199,
646,
2022,
199,
199,
646,
1683,
199,
646,
366,
3583,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1018,
492,
6016,
199,
504,
1639,
14,
2828,
492,
3788,
199,
504,
1639,
14,
2828,
14,
3431,
14,
5754,
492,
6430,
6608,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
504,
1639,
14,
1014,
492,
20730,
199,
199,
504,
2518,
63,
10433,
14,
992,
492,
27312,
199,
504,
22709,
14,
1018,
14,
16432,
14,
751,
63,
1246,
14,
8370,
14,
1246,
492,
15422,
63,
2048,
12,
1218,
63,
2048,
199,
504,
22709,
14,
1018,
14,
16432,
14,
751,
63,
1246,
14,
8370,
492,
32320,
63,
4283,
63,
9127,
199,
504,
22709,
14,
1018,
14,
773,
14,
3596,
63,
1208,
492,
4772,
63,
1001,
63,
4180,
199,
504,
6474,
14,
2219,
14,
15406,
492,
16047,
199,
504,
6474,
63,
2048,
14,
4196,
492,
2933,
63,
1751,
63,
1100,
199,
504,
10919,
63,
7522,
63,
1178,
14,
2219,
14,
396,
1974,
492,
20577,
63,
5720,
63,
7379,
12,
31079,
25233,
2817,
22060,
199,
504,
4884,
14,
4776,
492,
20503,
9637,
4256,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
17996,
1746,
421,
199,
32,
11138,
14,
11138,
199,
533,
17246,
6009,
4152,
774,
8,
6417,
9637,
4256,
12,
7640,
304,
272,
408,
6496,
367,
314,
6474,
2933,
6858,
626,
1678,
314,
922,
1159,
2933,
2556,
14,
408,
339,
13044,
2339,
275,
399,
2,
426,
572,
78,
14630,
2,
272,
12112,
7689,
1951,
63,
11958,
275,
399,
2,
87,
4478,
2,
272,
593,
6533,
63,
9032,
275,
399,
2,
158,
117,
228,
158,
117,
116,
17709,
128,
105,
158,
118,
95,
158,
117,
112,
128,
124,
2,
272,
18689,
63,
9032,
275,
399,
2,
173,
254,
227,
110,
173,
254,
227,
117,
173,
254,
227,
115,
173,
254,
227,
110,
173,
254,
227,
120,
173,
254,
228,
227,
173,
254,
227,
113,
2,
272,
593,
6533,
63,
10089,
275,
399,
2,
87,
11858,
32,
12150,
569,
351,
15970,
14,
957,
2,
272,
18689,
63,
10089,
275,
399,
2,
87,
4478,
32,
2117,
87,
11858,
7510,
14,
957,
2,
339,
29901,
63,
619,
12510,
9730,
275,
2948,
339,
29901,
63,
10089,
51,
275,
359,
267,
488,
12,
267,
399,
5151,
267,
399,
2,
65,
401,
267,
298,
889,
63,
2261,
401,
267,
298,
889,
11,
2261,
401,
267,
9244,
401,
267,
9244,
2261,
14,
957,
401,
267,
298,
396,
32,
889,
63,
3435,
401,
398,
327,
19944,
3031,
1553,
24129,
314,
2582,
402,
314,
768,
2261,
267,
327,
871,
367,
1373,
4528,
334,
1152,
781,
24068,
314,
1390,
2582,
2304,
9,
267,
399,
14381,
751,
93,
32,
2694,
14,
957,
1674,
908,
8,
288,
922,
2687,
85,
7,
69,
7,
627,
334,
10089,
63,
4283,
63,
9127,
446,
4119,
430,
267,
776,
272,
1622,
339,
29901,
63,
3078,
275,
399,
2,
4288,
3175,
2,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
18086,
6009,
4152,
774,
12,
291,
680,
5996,
480,
5500,
63,
2048,
14,
3603,
531,
398,
327,
2790,
15,
8222,
282,
892,
2933,
267,
10361,
63,
498,
275,
1218,
63,
2048,
8,
277,
14,
11958,
12,
291,
14,
5104,
63,
9032,
12,
291,
14,
5104,
63,
10089,
9,
267,
15422,
63,
2048,
8,
12312,
63,
498,
9,
398,
327,
16430,
267,
754,
275,
291,
14,
1258,
14,
2886,
8,
2473,
29,
277,
14,
11958,
12,
2505,
29,
277,
14,
5104,
63,
9032,
9,
267,
291,
14,
1815,
8,
1099,
9,
339,
768,
11278,
8,
1751,
14,
5441,
63,
18125,
508,
283,
15807,
14,
3603,
297,
283,
774,
1454,
1686,
315,
27540,
358,
272,
347,
511,
63,
2060,
63,
1461,
8,
277,
304,
267,
327,
4784,
282,
2505,
1570,
1830,
10367,
315,
12,
4389,
20529,
267,
327,
675,
402,
314,
2505,
5305,
2142,
687,
314,
2933,
2034,
267,
1177,
275,
291,
423,
1461,
63,
2060,
342,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
398,
327,
2670,
626,
376,
3031,
1990,
4847,
267,
291,
14,
629,
8,
552,
8,
1198,
14,
17244,
395,
413,
9,
398,
327,
13939,
314,
10361,
2142,
687,
314,
3031,
2396,
267,
3031,
63,
2030,
275,
6016,
14,
17244,
59,
16,
1055,
2030,
267,
754,
275,
295,
14,
1733,
28353,
48,
28,
633,
30,
2859,
14144,
16045,
83,
28798,
3031,
63,
2030,
9,
267,
291,
14,
9422,
8,
1099,
12,
488,
9,
267,
10361,
63,
1073,
275,
754,
14,
923,
360,
633,
358,
398,
327,
29614,
314,
10361,
2142,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
12312,
63,
1073,
9,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
398,
327,
28295,
282,
892,
2505,
436,
2035,
314,
4660,
370,
314,
3182,
2034,
267,
1177,
275,
291,
14,
1258,
14,
1932,
8,
288,
10361,
63,
1073,
12,
288,
327,
5723,
2883,
787,
687,
314,
1824,
641,
314,
1453,
2505,
5305,
18791,
2034,
14,
288,
791,
1222,
63,
2060,
17,
356,
291,
14,
11365,
63,
9032,
12,
283,
1222,
63,
2060,
18,
356,
291,
14,
11365,
63,
9032,
1386,
288,
2035,
29,
549,
267,
776,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
291,
14,
9535,
8,
1310,
12,
298,
14398,
2505,
965,
2757,
663,
2685,
398,
327,
5297,
314,
922,
734,
370,
5436,
2351,
666,
267,
291,
14,
1258,
14,
11646,
342,
398,
327,
7635,
626,
314,
892,
2505,
883,
506,
1202,
370,
943,
315,
267,
754,
275,
291,
14,
1258,
14,
2886,
8,
2473,
29,
277,
14,
11958,
12,
2505,
29,
277,
14,
11365,
63,
9032,
9,
267,
291,
14,
1815,
8,
1099,
9,
398,
327,
7649,
295,
4941,
314,
10361,
2142,
370,
1570,
314,
2505,
4020,
267,
1177,
275,
291,
14,
1258,
14,
1932,
8,
288,
10361,
63,
1073,
12,
288,
791,
1222,
63,
2060,
17,
356,
291,
14,
5104,
63,
9032,
12,
283,
1222,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
eddiep1101/django-oscar
|
tests/integration/offer/condition_tests.py
|
40
|
9458
|
from decimal import Decimal as D
from django.test import TestCase
import mock
from oscar.apps.offer import models
from oscar.test import factories
from oscar.test.basket import add_product
class TestCountCondition(TestCase):
def setUp(self):
self.range = models.Range.objects.create(
name="All products range", includes_all_products=True)
self.basket = factories.create_basket(empty=True)
self.condition = models.CountCondition(
range=self.range, type="Count", value=2)
self.offer = mock.Mock()
def test_is_not_satified_by_empty_basket(self):
self.assertFalse(self.condition.is_satisfied(self.offer, self.basket))
def test_not_discountable_product_fails_condition(self):
prod1, prod2 = factories.create_product(), factories.create_product()
prod2.is_discountable = False
prod2.save()
add_product(self.basket, product=prod1)
add_product(self.basket, product=prod2)
self.assertFalse(self.condition.is_satisfied(self.offer, self.basket))
def test_empty_basket_fails_partial_condition(self):
self.assertFalse(self.condition.is_partially_satisfied(self.offer, self.basket))
def test_smaller_quantity_basket_passes_partial_condition(self):
add_product(self.basket)
self.assertTrue(self.condition.is_partially_satisfied(self.offer, self.basket))
def test_smaller_quantity_basket_upsell_message(self):
add_product(self.basket)
self.assertTrue('Buy 1 more product from ' in
self.condition.get_upsell_message(self.offer, self.basket))
def test_matching_quantity_basket_fails_partial_condition(self):
add_product(self.basket, quantity=2)
self.assertFalse(self.condition.is_partially_satisfied(self.offer, self.basket))
def test_matching_quantity_basket_passes_condition(self):
add_product(self.basket, quantity=2)
self.assertTrue(self.condition.is_satisfied(self.offer, self.basket))
def test_greater_quantity_basket_passes_condition(self):
add_product(self.basket, quantity=3)
self.assertTrue(self.condition.is_satisfied(self.offer, self.basket))
def test_consumption(self):
add_product(self.basket, quantity=3)
self.condition.consume_items(self.offer, self.basket, [])
self.assertEqual(1, self.basket.all_lines()[0].quantity_without_discount)
def test_is_satisfied_accounts_for_consumed_items(self):
add_product(self.basket, quantity=3)
self.condition.consume_items(self.offer, self.basket, [])
self.assertFalse(self.condition.is_satisfied(self.offer, self.basket))
class ValueConditionTest(TestCase):
def setUp(self):
self.range = models.Range.objects.create(
name="All products range", includes_all_products=True)
self.basket = factories.create_basket(empty=True)
self.condition = models.ValueCondition(
range=self.range, type="Value", value=D('10.00'))
self.offer = mock.Mock()
self.item = factories.create_product(price=D('5.00'))
self.expensive_item = factories.create_product(price=D('15.00'))
def test_empty_basket_fails_condition(self):
self.assertFalse(self.condition.is_satisfied(self.offer, self.basket))
def test_empty_basket_fails_partial_condition(self):
self.assertFalse(self.condition.is_partially_satisfied(self.offer, self.basket))
def test_less_value_basket_fails_condition(self):
add_product(self.basket, D('5'))
self.assertFalse(self.condition.is_satisfied(self.offer, self.basket))
def test_not_discountable_item_fails_condition(self):
product = factories.create_product(is_discountable=False)
add_product(self.basket, D('15'), product=product)
self.assertFalse(self.condition.is_satisfied(self.offer, self.basket))
def test_upsell_message(self):
add_product(self.basket, D('5'))
self.assertTrue('Spend' in self.condition.get_upsell_message(self.offer, self.basket))
def test_matching_basket_fails_partial_condition(self):
add_product(self.basket, D('5'), 2)
self.assertFalse(self.condition.is_partially_satisfied(self.offer, self.basket))
def test_less_value_basket_passes_partial_condition(self):
add_product(self.basket, D('5'), 1)
self.assertTrue(self.condition.is_partially_satisfied(self.offer, self.basket))
def test_matching_basket_passes_condition(self):
add_product(self.basket, D('5'), 2)
self.assertTrue(self.condition.is_satisfied(self.offer, self.basket))
def test_greater_than_basket_passes_condition(self):
add_product(self.basket, D('5'), 3)
self.assertTrue(self.condition.is_satisfied(self.offer, self.basket))
def test_consumption(self):
add_product(self.basket, D('5'), 3)
self.condition.consume_items(self.offer, self.basket, [])
self.assertEqual(1, self.basket.all_lines()[0].quantity_without_discount)
def test_consumption_with_high_value_product(self):
add_product(self.basket, D('15'), 1)
self.condition.consume_items(self.offer, self.basket, [])
self.assertEqual(0, self.basket.all_lines()[0].quantity_without_discount)
def test_is_consumed_respects_quantity_consumed(self):
add_product(self.basket, D('15'), 1)
self.assertTrue(self.condition.is_satisfied(self.offer, self.basket))
self.condition.consume_items(self.offer, self.basket, [])
self.assertFalse(self.condition.is_satisfied(self.offer, self.basket))
class TestCoverageCondition(TestCase):
def setUp(self):
self.products = [factories.create_product(), factories.create_product()]
self.range = models.Range.objects.create(name="Some products")
for product in self.products:
self.range.add_product(product)
self.range.add_product(product)
self.basket = factories.create_basket(empty=True)
self.condition = models.CoverageCondition(
range=self.range, type="Coverage", value=2)
self.offer = mock.Mock()
def test_empty_basket_fails(self):
self.assertFalse(self.condition.is_satisfied(self.offer, self.basket))
def test_empty_basket_fails_partial_condition(self):
self.assertFalse(self.condition.is_partially_satisfied(self.offer, self.basket))
def test_single_item_fails(self):
add_product(self.basket, product=self.products[0])
self.assertFalse(self.condition.is_satisfied(self.offer, self.basket))
def test_not_discountable_item_fails(self):
self.products[0].is_discountable = False
self.products[0].save()
add_product(self.basket, product=self.products[0])
add_product(self.basket, product=self.products[1])
self.assertFalse(self.condition.is_satisfied(self.offer, self.basket))
def test_single_item_passes_partial_condition(self):
add_product(self.basket, product=self.products[0])
self.assertTrue(self.condition.is_partially_satisfied(self.offer, self.basket))
def test_upsell_message(self):
add_product(self.basket, product=self.products[0])
self.assertTrue(
'Buy 1 more' in self.condition.get_upsell_message(self.offer, self.basket))
def test_duplicate_item_fails(self):
add_product(self.basket, quantity=2, product=self.products[0])
self.assertFalse(self.condition.is_satisfied(self.offer, self.basket))
def test_duplicate_item_passes_partial_condition(self):
add_product(self.basket, quantity=2, product=self.products[0])
self.assertTrue(self.condition.is_partially_satisfied(self.offer, self.basket))
def test_covering_items_pass(self):
add_product(self.basket, product=self.products[0])
add_product(self.basket, product=self.products[1])
self.assertTrue(self.condition.is_satisfied(self.offer, self.basket))
def test_covering_items_fail_partial_condition(self):
add_product(self.basket, product=self.products[0])
add_product(self.basket, product=self.products[1])
self.assertFalse(self.condition.is_partially_satisfied(self.offer, self.basket))
def test_covering_items_are_consumed(self):
add_product(self.basket, product=self.products[0])
add_product(self.basket, product=self.products[1])
self.condition.consume_items(self.offer, self.basket, [])
self.assertEqual(0, self.basket.num_items_without_discount)
def test_consumed_items_checks_affected_items(self):
# Create new offer
range = models.Range.objects.create(name="All products", includes_all_products=True)
cond = models.CoverageCondition(range=range, type="Coverage", value=2)
# Get 4 distinct products in the basket
self.products.extend(
[factories.create_product(), factories.create_product()])
for product in self.products:
add_product(self.basket, product=product)
self.assertTrue(cond.is_satisfied(self.offer, self.basket))
cond.consume_items(self.offer, self.basket, [])
self.assertEqual(2, self.basket.num_items_without_discount)
self.assertTrue(cond.is_satisfied(self.offer, self.basket))
cond.consume_items(self.offer, self.basket, [])
self.assertEqual(0, self.basket.num_items_without_discount)
|
bsd-3-clause
|
[
504,
6107,
492,
6345,
465,
577,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
646,
1683,
199,
199,
504,
312,
22707,
14,
5181,
14,
12786,
492,
1709,
199,
504,
312,
22707,
14,
396,
492,
22115,
199,
504,
312,
22707,
14,
396,
14,
18136,
492,
1050,
63,
2558,
421,
199,
533,
1379,
2353,
9558,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1842,
275,
1709,
14,
4709,
14,
1462,
14,
981,
8,
288,
536,
628,
2422,
7585,
1425,
401,
6952,
63,
452,
63,
13336,
29,
549,
9,
267,
291,
14,
18136,
275,
22115,
14,
981,
63,
18136,
8,
1667,
29,
549,
9,
267,
291,
14,
5394,
275,
1709,
14,
2353,
9558,
8,
288,
1425,
29,
277,
14,
1842,
12,
730,
628,
2353,
401,
574,
29,
18,
9,
267,
291,
14,
12786,
275,
1683,
14,
3346,
342,
339,
347,
511,
63,
374,
63,
1397,
63,
83,
2159,
1290,
63,
991,
63,
1667,
63,
18136,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
5394,
14,
374,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
1397,
63,
15446,
461,
63,
2558,
63,
15762,
63,
5394,
8,
277,
304,
267,
12441,
17,
12,
12441,
18,
275,
22115,
14,
981,
63,
2558,
1062,
22115,
14,
981,
63,
2558,
342,
267,
12441,
18,
14,
374,
63,
15446,
461,
275,
756,
267,
12441,
18,
14,
2117,
342,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
3336,
29,
8788,
17,
9,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
3336,
29,
8788,
18,
9,
267,
291,
14,
3334,
8,
277,
14,
5394,
14,
374,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
1667,
63,
18136,
63,
15762,
63,
6672,
63,
5394,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
5394,
14,
374,
63,
462,
9406,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
24460,
1435,
63,
10577,
63,
18136,
63,
16027,
63,
6672,
63,
5394,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
9,
267,
291,
14,
1815,
8,
277,
14,
5394,
14,
374,
63,
462,
9406,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
24460,
1435,
63,
10577,
63,
18136,
63,
384,
23235,
63,
1188,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
9,
267,
291,
14,
1815,
360,
1713,
89,
413,
1655,
3336,
687,
283,
315,
717,
291,
14,
5394,
14,
362,
63,
384,
23235,
63,
1188,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
9467,
63,
10577,
63,
18136,
63,
15762,
63,
6672,
63,
5394,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
12524,
29,
18,
9,
267,
291,
14,
3334,
8,
277,
14,
5394,
14,
374,
63,
462,
9406,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
9467,
63,
10577,
63,
18136,
63,
16027,
63,
5394,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
12524,
29,
18,
9,
267,
291,
14,
1815,
8,
277,
14,
5394,
14,
374,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
13154,
63,
10577,
63,
18136,
63,
16027,
63,
5394,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
12524,
29,
19,
9,
267,
291,
14,
1815,
8,
277,
14,
5394,
14,
374,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
8704,
15052,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
12524,
29,
19,
9,
267,
291,
14,
5394,
14,
10235,
63,
1744,
8,
277,
14,
12786,
12,
291,
14,
18136,
12,
3073,
267,
291,
14,
629,
8,
17,
12,
291,
14,
18136,
14,
452,
63,
1278,
3430,
16,
1055,
10577,
63,
7395,
63,
15446,
9,
339,
347,
511,
63,
374,
63,
22878,
63,
8370,
63,
509,
63,
20688,
63,
1744,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
12524,
29,
19,
9,
267,
291,
14,
5394,
14,
10235,
63,
1744,
8,
277,
14,
12786,
12,
291,
14,
18136,
12,
3073,
267,
291,
14,
3334,
8,
277,
14,
5394,
14,
374,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
421,
199,
533,
1594,
9558,
774,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1842,
275,
1709,
14,
4709,
14,
1462,
14,
981,
8,
288,
536,
628,
2422,
7585,
1425,
401,
6952,
63,
452,
63,
13336,
29,
549,
9,
267,
291,
14,
18136,
275,
22115,
14,
981,
63,
18136,
8,
1667,
29,
549,
9,
267,
291,
14,
5394,
275,
1709,
14,
1110,
9558,
8,
288,
1425,
29,
277,
14,
1842,
12,
730,
628,
1110,
401,
574,
29,
36,
360,
709,
14,
383,
1333,
267,
291,
14,
12786,
275,
1683,
14,
3346,
342,
267,
291,
14,
1053,
275,
22115,
14,
981,
63,
2558,
8,
4777,
29,
36,
360,
21,
14,
383,
1333,
267,
291,
14,
476,
19947,
63,
1053,
275,
22115,
14,
981,
63,
2558,
8,
4777,
29,
36,
360,
1046,
14,
383,
1333,
339,
347,
511,
63,
1667,
63,
18136,
63,
15762,
63,
5394,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
5394,
14,
374,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
1667,
63,
18136,
63,
15762,
63,
6672,
63,
5394,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
5394,
14,
374,
63,
462,
9406,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
2003,
63,
585,
63,
18136,
63,
15762,
63,
5394,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
577,
360,
21,
1333,
267,
291,
14,
3334,
8,
277,
14,
5394,
14,
374,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
1397,
63,
15446,
461,
63,
1053,
63,
15762,
63,
5394,
8,
277,
304,
267,
3336,
275,
22115,
14,
981,
63,
2558,
8,
374,
63,
15446,
461,
29,
797,
9,
267,
1050,
63,
2558,
8,
277,
14
] |
[
6107,
492,
6345,
465,
577,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
646,
1683,
199,
199,
504,
312,
22707,
14,
5181,
14,
12786,
492,
1709,
199,
504,
312,
22707,
14,
396,
492,
22115,
199,
504,
312,
22707,
14,
396,
14,
18136,
492,
1050,
63,
2558,
421,
199,
533,
1379,
2353,
9558,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1842,
275,
1709,
14,
4709,
14,
1462,
14,
981,
8,
288,
536,
628,
2422,
7585,
1425,
401,
6952,
63,
452,
63,
13336,
29,
549,
9,
267,
291,
14,
18136,
275,
22115,
14,
981,
63,
18136,
8,
1667,
29,
549,
9,
267,
291,
14,
5394,
275,
1709,
14,
2353,
9558,
8,
288,
1425,
29,
277,
14,
1842,
12,
730,
628,
2353,
401,
574,
29,
18,
9,
267,
291,
14,
12786,
275,
1683,
14,
3346,
342,
339,
347,
511,
63,
374,
63,
1397,
63,
83,
2159,
1290,
63,
991,
63,
1667,
63,
18136,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
5394,
14,
374,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
1397,
63,
15446,
461,
63,
2558,
63,
15762,
63,
5394,
8,
277,
304,
267,
12441,
17,
12,
12441,
18,
275,
22115,
14,
981,
63,
2558,
1062,
22115,
14,
981,
63,
2558,
342,
267,
12441,
18,
14,
374,
63,
15446,
461,
275,
756,
267,
12441,
18,
14,
2117,
342,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
3336,
29,
8788,
17,
9,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
3336,
29,
8788,
18,
9,
267,
291,
14,
3334,
8,
277,
14,
5394,
14,
374,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
1667,
63,
18136,
63,
15762,
63,
6672,
63,
5394,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
5394,
14,
374,
63,
462,
9406,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
24460,
1435,
63,
10577,
63,
18136,
63,
16027,
63,
6672,
63,
5394,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
9,
267,
291,
14,
1815,
8,
277,
14,
5394,
14,
374,
63,
462,
9406,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
24460,
1435,
63,
10577,
63,
18136,
63,
384,
23235,
63,
1188,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
9,
267,
291,
14,
1815,
360,
1713,
89,
413,
1655,
3336,
687,
283,
315,
717,
291,
14,
5394,
14,
362,
63,
384,
23235,
63,
1188,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
9467,
63,
10577,
63,
18136,
63,
15762,
63,
6672,
63,
5394,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
12524,
29,
18,
9,
267,
291,
14,
3334,
8,
277,
14,
5394,
14,
374,
63,
462,
9406,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
9467,
63,
10577,
63,
18136,
63,
16027,
63,
5394,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
12524,
29,
18,
9,
267,
291,
14,
1815,
8,
277,
14,
5394,
14,
374,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
13154,
63,
10577,
63,
18136,
63,
16027,
63,
5394,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
12524,
29,
19,
9,
267,
291,
14,
1815,
8,
277,
14,
5394,
14,
374,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
8704,
15052,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
12524,
29,
19,
9,
267,
291,
14,
5394,
14,
10235,
63,
1744,
8,
277,
14,
12786,
12,
291,
14,
18136,
12,
3073,
267,
291,
14,
629,
8,
17,
12,
291,
14,
18136,
14,
452,
63,
1278,
3430,
16,
1055,
10577,
63,
7395,
63,
15446,
9,
339,
347,
511,
63,
374,
63,
22878,
63,
8370,
63,
509,
63,
20688,
63,
1744,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
12524,
29,
19,
9,
267,
291,
14,
5394,
14,
10235,
63,
1744,
8,
277,
14,
12786,
12,
291,
14,
18136,
12,
3073,
267,
291,
14,
3334,
8,
277,
14,
5394,
14,
374,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
421,
199,
533,
1594,
9558,
774,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1842,
275,
1709,
14,
4709,
14,
1462,
14,
981,
8,
288,
536,
628,
2422,
7585,
1425,
401,
6952,
63,
452,
63,
13336,
29,
549,
9,
267,
291,
14,
18136,
275,
22115,
14,
981,
63,
18136,
8,
1667,
29,
549,
9,
267,
291,
14,
5394,
275,
1709,
14,
1110,
9558,
8,
288,
1425,
29,
277,
14,
1842,
12,
730,
628,
1110,
401,
574,
29,
36,
360,
709,
14,
383,
1333,
267,
291,
14,
12786,
275,
1683,
14,
3346,
342,
267,
291,
14,
1053,
275,
22115,
14,
981,
63,
2558,
8,
4777,
29,
36,
360,
21,
14,
383,
1333,
267,
291,
14,
476,
19947,
63,
1053,
275,
22115,
14,
981,
63,
2558,
8,
4777,
29,
36,
360,
1046,
14,
383,
1333,
339,
347,
511,
63,
1667,
63,
18136,
63,
15762,
63,
5394,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
5394,
14,
374,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
1667,
63,
18136,
63,
15762,
63,
6672,
63,
5394,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
5394,
14,
374,
63,
462,
9406,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
2003,
63,
585,
63,
18136,
63,
15762,
63,
5394,
8,
277,
304,
267,
1050,
63,
2558,
8,
277,
14,
18136,
12,
577,
360,
21,
1333,
267,
291,
14,
3334,
8,
277,
14,
5394,
14,
374,
63,
22878,
8,
277,
14,
12786,
12,
291,
14,
18136,
430,
339,
347,
511,
63,
1397,
63,
15446,
461,
63,
1053,
63,
15762,
63,
5394,
8,
277,
304,
267,
3336,
275,
22115,
14,
981,
63,
2558,
8,
374,
63,
15446,
461,
29,
797,
9,
267,
1050,
63,
2558,
8,
277,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
a115027a/Openkore
|
src/scons-local-2.0.1/SCons/Tool/ilink.py
|
61
|
2134
|
"""SCons.Tool.ilink
Tool-specific initialization for the OS/2 ilink linker.
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 (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/Tool/ilink.py 5134 2010/08/16 23:02:40 bdeegan"
import SCons.Defaults
import SCons.Tool
import SCons.Util
def generate(env):
"""Add Builders and construction variables for ilink to an Environment."""
SCons.Tool.createProgBuilder(env)
env['LINK'] = 'ilink'
env['LINKFLAGS'] = SCons.Util.CLVar('')
env['LINKCOM'] = '$LINK $LINKFLAGS /O:$TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS'
env['LIBDIRPREFIX']='/LIBPATH:'
env['LIBDIRSUFFIX']=''
env['LIBLINKPREFIX']=''
env['LIBLINKSUFFIX']='$LIBSUFFIX'
def exists(env):
return env.Detect('ilink')
# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
|
gpl-2.0
|
[
624,
18521,
14,
5157,
14,
382,
2292,
199,
199,
5157,
13,
6100,
11097,
367,
314,
4403,
15,
18,
284,
1073,
17261,
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,
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,
5157,
15,
382,
2292,
14,
647,
959,
7582,
7129,
15,
2036,
15,
975,
6546,
26,
996,
26,
2167,
330,
271,
5902,
290,
2,
199,
199,
646,
8218,
14,
16986,
199,
646,
8218,
14,
5157,
199,
646,
8218,
14,
9562,
199,
199,
318,
3550,
8,
1813,
304,
272,
408,
1123,
19286,
83,
436,
14538,
2860,
367,
284,
1073,
370,
376,
9711,
1041,
272,
8218,
14,
5157,
14,
981,
919,
71,
6437,
8,
1813,
9,
2286,
2589,
459,
7916,
418,
263,
275,
283,
382,
2292,
7,
272,
2589,
459,
30388,
418,
257,
275,
8218,
14,
9562,
14,
1981,
5894,
8355,
272,
2589,
459,
7916,
11265,
418,
258,
275,
4505,
7916,
2672,
30388,
1182,
47,
26,
4,
9268,
2672,
25744,
2672,
63,
5617,
3022,
4831,
2672,
63,
5617,
4831,
7,
272,
2589,
459,
5617,
3022,
6351,
418,
8805,
32119,
4881,
272,
2589,
459,
5617,
3022,
12273,
418,
19070,
272,
2589,
459,
5617,
7916,
6351,
418,
19070,
272,
2589,
459,
5617,
7916,
12273,
418,
24269,
5617,
12273,
7,
199,
199,
318,
3495,
8,
1813,
304,
272,
372,
2589,
14,
20064,
360,
382,
2292,
358,
199,
199,
3,
10111,
17198,
26,
199,
3,
5174,
13,
2063,
26,
20,
199,
3,
4363,
13,
8741,
13,
632,
26,
20613,
199,
3,
9599,
26,
199,
3,
6695,
26,
663,
26414,
20849,
29,
20,
20105,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
382,
2292,
199,
199,
5157,
13,
6100,
11097,
367,
314,
4403,
15,
18,
284,
1073,
17261,
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,
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,
5157,
15,
382,
2292,
14,
647,
959,
7582,
7129,
15,
2036,
15,
975,
6546,
26,
996,
26,
2167,
330,
271,
5902,
290,
2,
199,
199,
646,
8218,
14,
16986,
199,
646,
8218,
14,
5157,
199,
646,
8218,
14,
9562,
199,
199,
318,
3550,
8,
1813,
304,
272,
408,
1123,
19286,
83,
436,
14538,
2860,
367,
284,
1073,
370,
376,
9711,
1041,
272,
8218,
14,
5157,
14,
981,
919,
71,
6437,
8,
1813,
9,
2286,
2589,
459,
7916,
418,
263,
275,
283,
382,
2292,
7,
272,
2589,
459,
30388,
418,
257,
275,
8218,
14,
9562,
14,
1981,
5894,
8355,
272,
2589,
459,
7916,
11265,
418,
258,
275,
4505,
7916,
2672,
30388,
1182,
47,
26,
4,
9268,
2672,
25744,
2672,
63,
5617,
3022,
4831,
2672,
63,
5617,
4831,
7,
272,
2589,
459,
5617,
3022,
6351,
418,
8805,
32119,
4881,
272,
2589,
459,
5617,
3022,
12273,
418,
19070,
272,
2589,
459,
5617,
7916,
6351,
418,
19070,
272,
2589,
459,
5617,
7916,
12273,
418,
24269,
5617,
12273,
7,
199,
199,
318,
3495,
8,
1813,
304,
272,
372,
2589,
14,
20064,
360,
382,
2292,
358,
199,
199,
3,
10111,
17198,
26,
199,
3,
5174,
13,
2063,
26,
20,
199,
3,
4363,
13,
8741,
13,
632,
26,
20613,
199,
3,
9599,
26,
199,
3,
6695,
26,
663,
26414,
20849,
29,
20,
20105,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
import os
import unittest
from itertools import chain
from operator import itemgetter
# Local imports
from lib2to3 import pygram, pytree, refactor, fixer_util
from lib2to3.tests import support
class FixerTestCase(support.TestCase):
# Other test cases can subclass this class and replace "fixer_pkg" with
# their own.
def setUp(self, fix_list=None, fixer_pkg="lib2to3", options=None):
if fix_list is None:
fix_list = [self.fixer]
self.refactor = support.get_refactorer(fixer_pkg, fix_list, options)
self.fixer_log = []
self.filename = u"<string>"
for fixer in chain(self.refactor.pre_order,
self.refactor.post_order):
fixer.log = self.fixer_log
def _check(self, before, after):
before = support.reformat(before)
after = support.reformat(after)
tree = self.refactor.refactor_string(before, self.filename)
self.assertEqual(after, unicode(tree))
return tree
def check(self, before, after, ignore_warnings=False):
tree = self._check(before, after)
self.assertTrue(tree.was_changed)
if not ignore_warnings:
self.assertEqual(self.fixer_log, [])
def warns(self, before, after, message, unchanged=False):
tree = self._check(before, after)
self.assertTrue(message in "".join(self.fixer_log))
if not unchanged:
self.assertTrue(tree.was_changed)
def warns_unchanged(self, before, message):
self.warns(before, before, message, unchanged=True)
def unchanged(self, before, ignore_warnings=False):
self._check(before, before)
if not ignore_warnings:
self.assertEqual(self.fixer_log, [])
def assert_runs_after(self, *names):
fixes = [self.fixer]
fixes.extend(names)
r = support.get_refactorer("lib2to3", fixes)
(pre, post) = r.get_fixers()
n = "fix_" + self.fixer
if post and post[-1].__class__.__module__.endswith(n):
# We're the last fixer to run
return
if pre and pre[-1].__class__.__module__.endswith(n) and not post:
# We're the last in pre and post is empty
return
self.fail("Fixer run order (%s) is incorrect; %s should be last."\
%(", ".join([x.__class__.__module__ for x in (pre+post)]), n))
class Test_ne(FixerTestCase):
fixer = "ne"
def test_basic(self):
b = """if x <> y:
pass"""
a = """if x != y:
pass"""
self.check(b, a)
def test_no_spaces(self):
b = """if x<>y:
pass"""
a = """if x!=y:
pass"""
self.check(b, a)
def test_chained(self):
b = """if x<>y<>z:
pass"""
a = """if x!=y!=z:
pass"""
self.check(b, a)
class Test_has_key(FixerTestCase):
fixer = "has_key"
def test_1(self):
b = """x = d.has_key("x") or d.has_key("y")"""
a = """x = "x" in d or "y" in d"""
self.check(b, a)
def test_2(self):
b = """x = a.b.c.d.has_key("x") ** 3"""
a = """x = ("x" in a.b.c.d) ** 3"""
self.check(b, a)
def test_3(self):
b = """x = a.b.has_key(1 + 2).__repr__()"""
a = """x = (1 + 2 in a.b).__repr__()"""
self.check(b, a)
def test_4(self):
b = """x = a.b.has_key(1 + 2).__repr__() ** -3 ** 4"""
a = """x = (1 + 2 in a.b).__repr__() ** -3 ** 4"""
self.check(b, a)
def test_5(self):
b = """x = a.has_key(f or g)"""
a = """x = (f or g) in a"""
self.check(b, a)
def test_6(self):
b = """x = a + b.has_key(c)"""
a = """x = a + (c in b)"""
self.check(b, a)
def test_7(self):
b = """x = a.has_key(lambda: 12)"""
a = """x = (lambda: 12) in a"""
self.check(b, a)
def test_8(self):
b = """x = a.has_key(a for a in b)"""
a = """x = (a for a in b) in a"""
self.check(b, a)
def test_9(self):
b = """if not a.has_key(b): pass"""
a = """if b not in a: pass"""
self.check(b, a)
def test_10(self):
b = """if not a.has_key(b).__repr__(): pass"""
a = """if not (b in a).__repr__(): pass"""
self.check(b, a)
def test_11(self):
b = """if not a.has_key(b) ** 2: pass"""
a = """if not (b in a) ** 2: pass"""
self.check(b, a)
class Test_apply(FixerTestCase):
fixer = "apply"
def test_1(self):
b = """x = apply(f, g + h)"""
a = """x = f(*g + h)"""
self.check(b, a)
def test_2(self):
b = """y = apply(f, g, h)"""
a = """y = f(*g, **h)"""
self.check(b, a)
def test_3(self):
b = """z = apply(fs[0], g or h, h or g)"""
a = """z = fs[0](*g or h, **h or g)"""
self.check(b, a)
def test_4(self):
b = """apply(f, (x, y) + t)"""
a = """f(*(x, y) + t)"""
self.check(b, a)
def test_5(self):
b = """apply(f, args,)"""
a = """f(*args)"""
self.check(b, a)
def test_6(self):
b = """apply(f, args, kwds,)"""
a = """f(*args, **kwds)"""
self.check(b, a)
# Test that complex functions are parenthesized
def test_complex_1(self):
b = """x = apply(f+g, args)"""
a = """x = (f+g)(*args)"""
self.check(b, a)
def test_complex_2(self):
b = """x = apply(f*g, args)"""
a = """x = (f*g)(*args)"""
self.check(b, a)
def test_complex_3(self):
b = """x = apply(f**g, args)"""
a = """x = (f**g)(*args)"""
self.check(b, a)
# But dotted names etc. not
def test_dotted_name(self):
b = """x = apply(f.g, args)"""
a = """x = f.g(*args)"""
self.check(b, a)
def test_subscript(self):
b = """x = apply(f[x], args)"""
a = """x = f[x](*args)"""
self.check(b, a)
def test_call(self):
b = """x = apply(f(), args)"""
a = """x = f()(*args)"""
self.check(b, a)
# Extreme case
def test_extreme(self):
b = """x = apply(a.b.c.d.e.f, args, kwds)"""
a = """x = a.b.c.d.e.f(*args, **kwds)"""
self.check(b, a)
# XXX Comments in weird places still get lost
def test_weird_comments(self):
b = """apply( # foo
f, # bar
args)"""
a = """f(*args)"""
self.check(b, a)
# These should *not* be touched
def test_unchanged_1(self):
s = """apply()"""
self.unchanged(s)
def test_unchanged_2(self):
s = """apply(f)"""
self.unchanged(s)
def test_unchanged_3(self):
s = """apply(f,)"""
self.unchanged(s)
def test_unchanged_4(self):
s = """apply(f, args, kwds, extras)"""
self.unchanged(s)
def test_unchanged_5(self):
s = """apply(f, *args, **kwds)"""
self.unchanged(s)
def test_unchanged_6(self):
s = """apply(f, *args)"""
self.unchanged(s)
def test_unchanged_7(self):
s = """apply(func=f, args=args, kwds=kwds)"""
self.unchanged(s)
def test_unchanged_8(self):
s = """apply(f, args=args, kwds=kwds)"""
self.unchanged(s)
def test_unchanged_9(self):
s = """apply(f, args, kwds=kwds)"""
self.unchanged(s)
def test_space_1(self):
a = """apply( f, args, kwds)"""
b = """f(*args, **kwds)"""
self.check(a, b)
def test_space_2(self):
a = """apply( f ,args,kwds )"""
b = """f(*args, **kwds)"""
self.check(a, b)
class Test_intern(FixerTestCase):
fixer = "intern"
def test_prefix_preservation(self):
b = """x = intern( a )"""
a = """import sys\nx = sys.intern( a )"""
self.check(b, a)
b = """y = intern("b" # test
)"""
a = """import sys\ny = sys.intern("b" # test
)"""
self.check(b, a)
b = """z = intern(a+b+c.d, )"""
a = """import sys\nz = sys.intern(a+b+c.d, )"""
self.check(b, a)
def test(self):
b = """x = intern(a)"""
a = """import sys\nx = sys.intern(a)"""
self.check(b, a)
b = """z = intern(a+b+c.d,)"""
a = """import sys\nz = sys.intern(a+b+c.d,)"""
self.check(b, a)
b = """intern("y%s" % 5).replace("y", "")"""
a = """import sys\nsys.intern("y%s" % 5).replace("y", "")"""
self.check(b, a)
# These should not be refactored
def test_unchanged(self):
s = """intern(a=1)"""
self.unchanged(s)
s = """intern(f, g)"""
self.unchanged(s)
s = """intern(*h)"""
self.unchanged(s)
s = """intern(**i)"""
self.unchanged(s)
s = """intern()"""
self.unchanged(s)
class Test_reduce(FixerTestCase):
fixer = "reduce"
def test_simple_call(self):
b = "reduce(a, b, c)"
a = "from functools import reduce\nreduce(a, b, c)"
self.check(b, a)
def test_bug_7253(self):
# fix_tuple_params was being bad and orphaning nodes in the tree.
b = "def x(arg): reduce(sum, [])"
a = "from functools import reduce\ndef x(arg): reduce(sum, [])"
self.check(b, a)
def test_call_with_lambda(self):
b = "reduce(lambda x, y: x + y, seq)"
a = "from functools import reduce\nreduce(lambda x, y: x + y, seq)"
self.check(b, a)
def test_unchanged(self):
s = "reduce(a)"
self.unchanged(s)
s = "reduce(a, b=42)"
self.unchanged(s)
s = "reduce(a, b, c, d)"
self.unchanged(s)
s = "reduce(**c)"
self.unchanged(s)
s = "reduce()"
self.unchanged(s)
class Test_print(FixerTestCase):
fixer = "print"
def test_prefix_preservation(self):
b = """print 1, 1+1, 1+1+1"""
a = """print(1, 1+1, 1+1+1)"""
self.check(b, a)
def test_idempotency(self):
s = """print()"""
self.unchanged(s)
s = """print('')"""
self.unchanged(s)
def test_idempotency_print_as_function(self):
self.refactor.driver.grammar = pygram.python_grammar_no_print_statement
s = """print(1, 1+1, 1+1+1)"""
self.unchanged(s)
s = """print()"""
self.unchanged(s)
s = """print('')"""
self.unchanged(s)
def test_1(self):
b = """print 1, 1+1, 1+1+1"""
a = """print(1, 1+1, 1+1+1)"""
self.check(b, a)
def test_2(self):
b = """print 1, 2"""
a = """print(1, 2)"""
self.check(b, a)
def test_3(self):
b = """print"""
a = """print()"""
self.check(b, a)
def test_4(self):
# from bug 3000
b = """print whatever; print"""
a = """print(whatever); print()"""
self.check(b, a)
def test_5(self):
b = """print; print whatever;"""
a = """print(); print(whatever);"""
self.check(b, a)
def test_tuple(self):
b = """print (a, b, c)"""
a = """print((a, b, c))"""
self.check(b, a)
# trailing commas
def test_trailing_comma_1(self):
b = """print 1, 2, 3,"""
a = """print(1, 2, 3, end=' ')"""
self.check(b, a)
def test_trailing_comma_2(self):
b = """print 1, 2,"""
a = """print(1, 2, end=' ')"""
self.check(b, a)
def test_trailing_comma_3(self):
b = """print 1,"""
a = """print(1, end=' ')"""
self.check(b, a)
# >> stuff
def test_vargs_without_trailing_comma(self):
b = """print >>sys.stderr, 1, 2, 3"""
a = """print(1, 2, 3, file=sys.stderr)"""
self.check(b, a)
def test_with_trailing_comma(self):
b = """print >>sys.stderr, 1, 2,"""
a = """print(1, 2, end=' ', file=sys.stderr)"""
self.check(b, a)
def test_no_trailing_comma(self):
b = """print >>sys.stderr, 1+1"""
a = """print(1+1, file=sys.stderr)"""
self.check(b, a)
def test_spaces_before_file(self):
b = """print >> sys.stderr"""
a = """print(file=sys.stderr)"""
self.check(b, a)
def test_with_future_print_function(self):
s = "from __future__ import print_function\n" \
"print('Hai!', end=' ')"
self.unchanged(s)
b = "print 'Hello, world!'"
a = "print('Hello, world!')"
self.check(b, a)
class Test_exec(FixerTestCase):
fixer = "exec"
def test_prefix_preservation(self):
b = """ exec code in ns1, ns2"""
a = """ exec(code, ns1, ns2)"""
self.check(b, a)
def test_basic(self):
b = """exec code"""
a = """exec(code)"""
self.check(b, a)
def test_with_globals(self):
b = """exec code in ns"""
a = """exec(code, ns)"""
self.check(b, a)
def test_with_globals_locals(self):
b = """exec code in ns1, ns2"""
a = """exec(code, ns1, ns2)"""
self.check(b, a)
def test_complex_1(self):
b = """exec (a.b()) in ns"""
a = """exec((a.b()), ns)"""
self.check(b, a)
def test_complex_2(self):
b = """exec a.b() + c in ns"""
a = """exec(a.b() + c, ns)"""
self.check(b, a)
# These should not be touched
def test_unchanged_1(self):
s = """exec(code)"""
self.unchanged(s)
def test_unchanged_2(self):
s = """exec (code)"""
self.unchanged(s)
def test_unchanged_3(self):
s = """exec(code, ns)"""
self.unchanged(s)
def test_unchanged_4(self):
s = """exec(code, ns1, ns2)"""
self.unchanged(s)
class Test_repr(FixerTestCase):
fixer = "repr"
def test_prefix_preservation(self):
b = """x = `1 + 2`"""
a = """x = repr(1 + 2)"""
self.check(b, a)
def test_simple_1(self):
b = """x = `1 + 2`"""
a = """x = repr(1 + 2)"""
self.check(b, a)
def test_simple_2(self):
b = """y = `x`"""
a = """y = repr(x)"""
self.check(b, a)
def test_complex(self):
b = """z = `y`.__repr__()"""
a = """z = repr(y).__repr__()"""
self.check(b, a)
def test_tuple(self):
b = """x = `1, 2, 3`"""
a = """x = repr((1, 2, 3))"""
self.check(b, a)
def test_nested(self):
b = """x = `1 + `2``"""
a = """x = repr(1 + repr(2))"""
self.check(b, a)
def test_nested_tuples(self):
b = """x = `1, 2 + `3, 4``"""
a = """x = repr((1, 2 + repr((3, 4))))"""
self.check(b, a)
class Test_except(FixerTestCase):
fixer = "except"
def test_prefix_preservation(self):
b = """
try:
pass
except (RuntimeError, ImportError), e:
pass"""
a = """
try:
pass
except (RuntimeError, ImportError) as e:
pass"""
self.check(b, a)
def test_simple(self):
b = """
try:
pass
except Foo, e:
pass"""
a = """
try:
pass
except Foo as e:
pass"""
self.check(b, a)
def test_simple_no_space_before_target(self):
b = """
try:
pass
except Foo,e:
pass"""
a = """
try:
pass
except Foo as e:
pass"""
self.check(b, a)
def test_tuple_unpack(self):
b = """
def foo():
try:
pass
except Exception, (f, e):
pass
except ImportError, e:
pass"""
a = """
def foo():
try:
pass
except Exception as xxx_todo_changeme:
(f, e) = xxx_todo_changeme.args
pass
except ImportError as e:
pass"""
self.check(b, a)
def test_multi_class(self):
b = """
try:
pass
except (RuntimeError, ImportError), e:
pass"""
a = """
try:
pass
except (RuntimeError, ImportError) as e:
pass"""
self.check(b, a)
def test_list_unpack(self):
b = """
try:
pass
except Exception, [a, b]:
pass"""
a = """
try:
pass
except Exception as xxx_todo_changeme:
[a, b] = xxx_todo_changeme.args
pass"""
self.check(b, a)
def test_weird_target_1(self):
b = """
try:
pass
except Exception, d[5]:
pass"""
a = """
try:
pass
except Exception as xxx_todo_changeme:
d[5] = xxx_todo_changeme
pass"""
self.check(b, a)
def test_weird_target_2(self):
b = """
try:
pass
except Exception, a.foo:
pass"""
a = """
try:
pass
except Exception as xxx_todo_changeme:
a.foo = xxx_todo_changeme
pass"""
self.check(b, a)
def test_weird_target_3(self):
b = """
try:
pass
except Exception, a().foo:
pass"""
a = """
try:
pass
except Exception as xxx_todo_changeme:
a().foo = xxx_todo_changeme
pass"""
self.check(b, a)
def test_bare_except(self):
b = """
try:
pass
except Exception, a:
pass
except:
pass"""
a = """
try:
pass
except Exception as a:
pass
except:
pass"""
self.check(b, a)
def test_bare_except_and_else_finally(self):
b = """
try:
pass
except Exception, a:
pass
except:
pass
else:
pass
finally:
pass"""
a = """
try:
pass
except Exception as a:
pass
except:
pass
else:
pass
finally:
pass"""
self.check(b, a)
def test_multi_fixed_excepts_before_bare_except(self):
b = """
try:
pass
except TypeError, b:
pass
except Exception, a:
pass
except:
pass"""
a = """
try:
pass
except TypeError as b:
pass
except Exception as a:
pass
except:
pass"""
self.check(b, a)
def test_one_line_suites(self):
b = """
try: raise TypeError
except TypeError, e:
pass
"""
a = """
try: raise TypeError
except TypeError as e:
pass
"""
self.check(b, a)
b = """
try:
raise TypeError
except TypeError, e: pass
"""
a = """
try:
raise TypeError
except TypeError as e: pass
"""
self.check(b, a)
b = """
try: raise TypeError
except TypeError, e: pass
"""
a = """
try: raise TypeError
except TypeError as e: pass
"""
self.check(b, a)
b = """
try: raise TypeError
except TypeError, e: pass
else: function()
finally: done()
"""
a = """
try: raise TypeError
except TypeError as e: pass
else: function()
finally: done()
"""
self.check(b, a)
# These should not be touched:
def test_unchanged_1(self):
s = """
try:
pass
except:
pass"""
self.unchanged(s)
def test_unchanged_2(self):
s = """
try:
pass
except Exception:
pass"""
self.unchanged(s)
def test_unchanged_3(self):
s = """
try:
pass
except (Exception, SystemExit):
pass"""
self.unchanged(s)
class Test_raise(FixerTestCase):
fixer = "raise"
def test_basic(self):
b = """raise Exception, 5"""
a = """raise Exception(5)"""
self.check(b, a)
def test_prefix_preservation(self):
b = """raise Exception,5"""
a = """raise Exception(5)"""
self.check(b, a)
b = """raise Exception, 5"""
a = """raise Exception(5)"""
self.check(b, a)
def test_with_comments(self):
b = """raise Exception, 5 # foo"""
a = """raise Exception(5) # foo"""
self.check(b, a)
b = """raise E, (5, 6) % (a, b) # foo"""
a = """raise E((5, 6) % (a, b)) # foo"""
self.check(b, a)
b = """def foo():
raise Exception, 5, 6 # foo"""
a = """def foo():
raise Exception(5).with_traceback(6) # foo"""
self.check(b, a)
def test_None_value(self):
b = """raise Exception(5), None, tb"""
a = """raise Exception(5).with_traceback(tb)"""
self.check(b, a)
def test_tuple_value(self):
b = """raise Exception, (5, 6, 7)"""
a = """raise Exception(5, 6, 7)"""
self.check(b, a)
def test_tuple_detection(self):
b = """raise E, (5, 6) % (a, b)"""
a = """raise E((5, 6) % (a, b))"""
self.check(b, a)
def test_tuple_exc_1(self):
b = """raise (((E1, E2), E3), E4), V"""
a = """raise E1(V)"""
self.check(b, a)
def test_tuple_exc_2(self):
b = """raise (E1, (E2, E3), E4), V"""
a = """raise E1(V)"""
self.check(b, a)
# These should produce a warning
def test_string_exc(self):
s = """raise 'foo'"""
self.warns_unchanged(s, "Python 3 does not support string exceptions")
def test_string_exc_val(self):
s = """raise "foo", 5"""
self.warns_unchanged(s, "Python 3 does not support string exceptions")
def test_string_exc_val_tb(self):
s = """raise "foo", 5, 6"""
self.warns_unchanged(s, "Python 3 does not support string exceptions")
# These should result in traceback-assignment
def test_tb_1(self):
b = """def foo():
raise Exception, 5, 6"""
a = """def foo():
raise Exception(5).with_traceback(6)"""
self.check(b, a)
def test_tb_2(self):
b = """def foo():
a = 5
raise Exception, 5, 6
b = 6"""
a = """def foo():
a = 5
raise Exception(5).with_traceback(6)
b = 6"""
self.check(b, a)
def test_tb_3(self):
b = """def foo():
raise Exception,5,6"""
a = """def foo():
raise Exception(5).with_traceback(6)"""
self.check(b, a)
def test_tb_4(self):
b = """def foo():
a = 5
raise Exception,5,6
b = 6"""
a = """def foo():
a = 5
raise Exception(5).with_traceback(6)
b = 6"""
self.check(b, a)
def test_tb_5(self):
b = """def foo():
raise Exception, (5, 6, 7), 6"""
a = """def foo():
raise Exception(5, 6, 7).with_traceback(6)"""
self.check(b, a)
def test_tb_6(self):
b = """def foo():
a = 5
raise Exception, (5, 6, 7), 6
b = 6"""
a = """def foo():
a = 5
raise Exception(5, 6, 7).with_traceback(6)
b = 6"""
self.check(b, a)
class Test_throw(FixerTestCase):
fixer = "throw"
def test_1(self):
b = """g.throw(Exception, 5)"""
a = """g.throw(Exception(5))"""
self.check(b, a)
def test_2(self):
b = """g.throw(Exception,5)"""
a = """g.throw(Exception(5))"""
self.check(b, a)
def test_3(self):
b = """g.throw(Exception, (5, 6, 7))"""
a = """g.throw(Exception(5, 6, 7))"""
self.check(b, a)
def test_4(self):
b = """5 + g.throw(Exception, 5)"""
a = """5 + g.throw(Exception(5))"""
self.check(b, a)
# These should produce warnings
def test_warn_1(self):
s = """g.throw("foo")"""
self.warns_unchanged(s, "Python 3 does not support string exceptions")
def test_warn_2(self):
s = """g.throw("foo", 5)"""
self.warns_unchanged(s, "Python 3 does not support string exceptions")
def test_warn_3(self):
s = """g.throw("foo", 5, 6)"""
self.warns_unchanged(s, "Python 3 does not support string exceptions")
# These should not be touched
def test_untouched_1(self):
s = """g.throw(Exception)"""
self.unchanged(s)
def test_untouched_2(self):
s = """g.throw(Exception(5, 6))"""
self.unchanged(s)
def test_untouched_3(self):
s = """5 + g.throw(Exception(5, 6))"""
self.unchanged(s)
# These should result in traceback-assignment
def test_tb_1(self):
b = """def foo():
g.throw(Exception, 5, 6)"""
a = """def foo():
g.throw(Exception(5).with_traceback(6))"""
self.check(b, a)
def test_tb_2(self):
b = """def foo():
a = 5
g.throw(Exception, 5, 6)
b = 6"""
a = """def foo():
a = 5
g.throw(Exception(5).with_traceback(6))
b = 6"""
self.check(b, a)
def test_tb_3(self):
b = """def foo():
g.throw(Exception,5,6)"""
a = """def foo():
g.throw(Exception(5).with_traceback(6))"""
self.check(b, a)
def test_tb_4(self):
b = """def foo():
a = 5
g.throw(Exception,5,6)
b = 6"""
a = """def foo():
a = 5
g.throw(Exception(5).with_traceback(6))
b = 6"""
self.check(b, a)
def test_tb_5(self):
b = """def foo():
g.throw(Exception, (5, 6, 7), 6)"""
a = """def foo():
g.throw(Exception(5, 6, 7).with_traceback(6))"""
self.check(b, a)
def test_tb_6(self):
b = """def foo():
a = 5
g.throw(Exception, (5, 6, 7), 6)
b = 6"""
a = """def foo():
a = 5
g.throw(Exception(5, 6, 7).with_traceback(6))
b = 6"""
self.check(b, a)
def test_tb_7(self):
b = """def foo():
a + g.throw(Exception, 5, 6)"""
a = """def foo():
a + g.throw(Exception(5).with_traceback(6))"""
self.check(b, a)
def test_tb_8(self):
b = """def foo():
a = 5
a + g.throw(Exception, 5, 6)
b = 6"""
a = """def foo():
a = 5
a + g.throw(Exception(5).with_traceback(6))
b = 6"""
self.check(b, a)
class Test_long(FixerTestCase):
fixer = "long"
def test_1(self):
b = """x = long(x)"""
a = """x = int(x)"""
self.check(b, a)
def test_2(self):
b = """y = isinstance(x, long)"""
a = """y = isinstance(x, int)"""
self.check(b, a)
def test_3(self):
b = """z = type(x) in (int, long)"""
a = """z = type(x) in (int, int)"""
self.check(b, a)
def test_unchanged(self):
s = """long = True"""
self.unchanged(s)
s = """s.long = True"""
self.unchanged(s)
s = """def long(): pass"""
self.unchanged(s)
s = """class long(): pass"""
self.unchanged(s)
s = """def f(long): pass"""
self.unchanged(s)
s = """def f(g, long): pass"""
self.unchanged(s)
s = """def f(x, long=True): pass"""
self.unchanged(s)
def test_prefix_preservation(self):
b = """x = long( x )"""
a = """x = int( x )"""
self.check(b, a)
class Test_execfile(FixerTestCase):
fixer = "execfile"
def test_conversion(self):
b = """execfile("fn")"""
a = """exec(compile(open("fn").read(), "fn", 'exec'))"""
self.check(b, a)
b = """execfile("fn", glob)"""
a = """exec(compile(open("fn").read(), "fn", 'exec'), glob)"""
self.check(b, a)
b = """execfile("fn", glob, loc)"""
a = """exec(compile(open("fn").read(), "fn", 'exec'), glob, loc)"""
self.check(b, a)
b = """execfile("fn", globals=glob)"""
a = """exec(compile(open("fn").read(), "fn", 'exec'), globals=glob)"""
self.check(b, a)
b = """execfile("fn", locals=loc)"""
a = """exec(compile(open("fn").read(), "fn", 'exec'), locals=loc)"""
self.check(b, a)
b = """execfile("fn", globals=glob, locals=loc)"""
a = """exec(compile(open("fn").read(), "fn", 'exec'), globals=glob, locals=loc)"""
self.check(b, a)
def test_spacing(self):
b = """execfile( "fn" )"""
a = """exec(compile(open( "fn" ).read(), "fn", 'exec'))"""
self.check(b, a)
b = """execfile("fn", globals = glob)"""
a = """exec(compile(open("fn").read(), "fn", 'exec'), globals = glob)"""
self.check(b, a)
class Test_isinstance(FixerTestCase):
fixer = "isinstance"
def test_remove_multiple_items(self):
b = """isinstance(x, (int, int, int))"""
a = """isinstance(x, int)"""
self.check(b, a)
b = """isinstance(x, (int, float, int, int, float))"""
a = """isinstance(x, (int, float))"""
self.check(b, a)
b = """isinstance(x, (int, float, int, int, float, str))"""
a = """isinstance(x, (int, float, str))"""
self.check(b, a)
b = """isinstance(foo() + bar(), (x(), y(), x(), int, int))"""
a = """isinstance(foo() + bar(), (x(), y(), x(), int))"""
self.check(b, a)
def test_prefix_preservation(self):
b = """if isinstance( foo(), ( bar, bar, baz )) : pass"""
a = """if isinstance( foo(), ( bar, baz )) : pass"""
self.check(b, a)
def test_unchanged(self):
self.unchanged("isinstance(x, (str, int))")
class Test_dict(FixerTestCase):
fixer = "dict"
def test_prefix_preservation(self):
b = "if d. keys ( ) : pass"
a = "if list(d. keys ( )) : pass"
self.check(b, a)
b = "if d. items ( ) : pass"
a = "if list(d. items ( )) : pass"
self.check(b, a)
b = "if d. iterkeys ( ) : pass"
a = "if iter(d. keys ( )) : pass"
self.check(b, a)
b = "[i for i in d. iterkeys( ) ]"
a = "[i for i in d. keys( ) ]"
self.check(b, a)
b = "if d. viewkeys ( ) : pass"
a = "if d. keys ( ) : pass"
self.check(b, a)
b = "[i for i in d. viewkeys( ) ]"
a = "[i for i in d. keys( ) ]"
self.check(b, a)
def test_trailing_comment(self):
b = "d.keys() # foo"
a = "list(d.keys()) # foo"
self.check(b, a)
b = "d.items() # foo"
a = "list(d.items()) # foo"
self.check(b, a)
b = "d.iterkeys() # foo"
a = "iter(d.keys()) # foo"
self.check(b, a)
b = """[i for i in d.iterkeys() # foo
]"""
a = """[i for i in d.keys() # foo
]"""
self.check(b, a)
b = """[i for i in d.iterkeys() # foo
]"""
a = """[i for i in d.keys() # foo
]"""
self.check(b, a)
b = "d.viewitems() # foo"
a = "d.items() # foo"
self.check(b, a)
def test_unchanged(self):
for wrapper in fixer_util.consuming_calls:
s = "s = %s(d.keys())" % wrapper
self.unchanged(s)
s = "s = %s(d.values())" % wrapper
self.unchanged(s)
s = "s = %s(d.items())" % wrapper
self.unchanged(s)
def test_01(self):
b = "d.keys()"
a = "list(d.keys())"
self.check(b, a)
b = "a[0].foo().keys()"
a = "list(a[0].foo().keys())"
self.check(b, a)
def test_02(self):
b = "d.items()"
a = "list(d.items())"
self.check(b, a)
def test_03(self):
b = "d.values()"
a = "list(d.values())"
self.check(b, a)
def test_04(self):
b = "d.iterkeys()"
a = "iter(d.keys())"
self.check(b, a)
def test_05(self):
b = "d.iteritems()"
a = "iter(d.items())"
self.check(b, a)
def test_06(self):
b = "d.itervalues()"
a = "iter(d.values())"
self.check(b, a)
def test_07(self):
s = "list(d.keys())"
self.unchanged(s)
def test_08(self):
s = "sorted(d.keys())"
self.unchanged(s)
def test_09(self):
b = "iter(d.keys())"
a = "iter(list(d.keys()))"
self.check(b, a)
def test_10(self):
b = "foo(d.keys())"
a = "foo(list(d.keys()))"
self.check(b, a)
def test_11(self):
b = "for i in d.keys(): print i"
a = "for i in list(d.keys()): print i"
self.check(b, a)
def test_12(self):
b = "for i in d.iterkeys(): print i"
a = "for i in d.keys(): print i"
self.check(b, a)
def test_13(self):
b = "[i for i in d.keys()]"
a = "[i for i in list(d.keys())]"
self.check(b, a)
def test_14(self):
b = "[i for i in d.iterkeys()]"
a = "[i for i in d.keys()]"
self.check(b, a)
def test_15(self):
b = "(i for i in d.keys())"
a = "(i for i in list(d.keys()))"
self.check(b, a)
def test_16(self):
b = "(i for i in d.iterkeys())"
a = "(i for i in d.keys())"
self.check(b, a)
def test_17(self):
b = "iter(d.iterkeys())"
a = "iter(d.keys())"
self.check(b, a)
def test_18(self):
b = "list(d.iterkeys())"
a = "list(d.keys())"
self.check(b, a)
def test_19(self):
b = "sorted(d.iterkeys())"
a = "sorted(d.keys())"
self.check(b, a)
def test_20(self):
b = "foo(d.iterkeys())"
a = "foo(iter(d.keys()))"
self.check(b, a)
def test_21(self):
b = "print h.iterkeys().next()"
a = "print iter(h.keys()).next()"
self.check(b, a)
def test_22(self):
b = "print h.keys()[0]"
a = "print list(h.keys())[0]"
self.check(b, a)
def test_23(self):
b = "print list(h.iterkeys().next())"
a = "print list(iter(h.keys()).next())"
self.check(b, a)
def test_24(self):
b = "for x in h.keys()[0]: print x"
a = "for x in list(h.keys())[0]: print x"
self.check(b, a)
def test_25(self):
b = "d.viewkeys()"
a = "d.keys()"
self.check(b, a)
def test_26(self):
b = "d.viewitems()"
a = "d.items()"
self.check(b, a)
def test_27(self):
b = "d.viewvalues()"
a = "d.values()"
self.check(b, a)
def test_14(self):
b = "[i for i in d.viewkeys()]"
a = "[i for i in d.keys()]"
self.check(b, a)
def test_15(self):
b = "(i for i in d.viewkeys())"
a = "(i for i in d.keys())"
self.check(b, a)
def test_17(self):
b = "iter(d.viewkeys())"
a = "iter(d.keys())"
self.check(b, a)
def test_18(self):
b = "list(d.viewkeys())"
a = "list(d.keys())"
self.check(b, a)
def test_19(self):
b = "sorted(d.viewkeys())"
a = "sorted(d.keys())"
self.check(b, a)
class Test_xrange(FixerTestCase):
fixer = "xrange"
def test_prefix_preservation(self):
b = """x = xrange( 10 )"""
a = """x = range( 10 )"""
self.check(b, a)
b = """x = xrange( 1 , 10 )"""
a = """x = range( 1 , 10 )"""
self.check(b, a)
b = """x = xrange( 0 , 10 , 2 )"""
a = """x = range( 0 , 10 , 2 )"""
self.check(b, a)
def test_single_arg(self):
b = """x = xrange(10)"""
a = """x = range(10)"""
self.check(b, a)
def test_two_args(self):
b = """x = xrange(1, 10)"""
a = """x = range(1, 10)"""
self.check(b, a)
def test_three_args(self):
b = """x = xrange(0, 10, 2)"""
a = """x = range(0, 10, 2)"""
self.check(b, a)
def test_wrap_in_list(self):
b = """x = range(10, 3, 9)"""
a = """x = list(range(10, 3, 9))"""
self.check(b, a)
b = """x = foo(range(10, 3, 9))"""
a = """x = foo(list(range(10, 3, 9)))"""
self.check(b, a)
b = """x = range(10, 3, 9) + [4]"""
a = """x = list(range(10, 3, 9)) + [4]"""
self.check(b, a)
b = """x = range(10)[::-1]"""
a = """x = list(range(10))[::-1]"""
self.check(b, a)
b = """x = range(10) [3]"""
a = """x = list(range(10)) [3]"""
self.check(b, a)
def test_xrange_in_for(self):
b = """for i in xrange(10):\n j=i"""
a = """for i in range(10):\n j=i"""
self.check(b, a)
b = """[i for i in xrange(10)]"""
a = """[i for i in range(10)]"""
self.check(b, a)
def test_range_in_for(self):
self.unchanged("for i in range(10): pass")
self.unchanged("[i for i in range(10)]")
def test_in_contains_test(self):
self.unchanged("x in range(10, 3, 9)")
def test_in_consuming_context(self):
for call in fixer_util.consuming_calls:
self.unchanged("a = %s(range(10))" % call)
class Test_xrange_with_reduce(FixerTestCase):
def setUp(self):
super(Test_xrange_with_reduce, self).setUp(["xrange", "reduce"])
def test_double_transform(self):
b = """reduce(x, xrange(5))"""
a = """from functools import reduce
reduce(x, range(5))"""
self.check(b, a)
class Test_raw_input(FixerTestCase):
fixer = "raw_input"
def test_prefix_preservation(self):
b = """x = raw_input( )"""
a = """x = input( )"""
self.check(b, a)
b = """x = raw_input( '' )"""
a = """x = input( '' )"""
self.check(b, a)
def test_1(self):
b = """x = raw_input()"""
a = """x = input()"""
self.check(b, a)
def test_2(self):
b = """x = raw_input('')"""
a = """x = input('')"""
self.check(b, a)
def test_3(self):
b = """x = raw_input('prompt')"""
a = """x = input('prompt')"""
self.check(b, a)
def test_4(self):
b = """x = raw_input(foo(a) + 6)"""
a = """x = input(foo(a) + 6)"""
self.check(b, a)
def test_5(self):
b = """x = raw_input(invite).split()"""
a = """x = input(invite).split()"""
self.check(b, a)
def test_6(self):
b = """x = raw_input(invite) . split ()"""
a = """x = input(invite) . split ()"""
self.check(b, a)
def test_8(self):
b = "x = int(raw_input())"
a = "x = int(input())"
self.check(b, a)
class Test_funcattrs(FixerTestCase):
fixer = "funcattrs"
attrs = ["closure", "doc", "name", "defaults", "code", "globals", "dict"]
def test(self):
for attr in self.attrs:
b = "a.func_%s" % attr
a = "a.__%s__" % attr
self.check(b, a)
b = "self.foo.func_%s.foo_bar" % attr
a = "self.foo.__%s__.foo_bar" % attr
self.check(b, a)
def test_unchanged(self):
for attr in self.attrs:
s = "foo(func_%s + 5)" % attr
self.unchanged(s)
s = "f(foo.__%s__)" % attr
self.unchanged(s)
s = "f(foo.__%s__.foo)" % attr
self.unchanged(s)
class Test_xreadlines(FixerTestCase):
fixer = "xreadlines"
def test_call(self):
b = "for x in f.xreadlines(): pass"
a = "for x in f: pass"
self.check(b, a)
b = "for x in foo().xreadlines(): pass"
a = "for x in foo(): pass"
self.check(b, a)
b = "for x in (5 + foo()).xreadlines(): pass"
a = "for x in (5 + foo()): pass"
self.check(b, a)
def test_attr_ref(self):
b = "foo(f.xreadlines + 5)"
a = "foo(f.__iter__ + 5)"
self.check(b, a)
b = "foo(f().xreadlines + 5)"
a = "foo(f().__iter__ + 5)"
self.check(b, a)
b = "foo((5 + f()).xreadlines + 5)"
a = "foo((5 + f()).__iter__ + 5)"
self.check(b, a)
def test_unchanged(self):
s = "for x in f.xreadlines(5): pass"
self.unchanged(s)
s = "for x in f.xreadlines(k=5): pass"
self.unchanged(s)
s = "for x in f.xreadlines(*k, **v): pass"
self.unchanged(s)
s = "foo(xreadlines)"
self.unchanged(s)
class ImportsFixerTests:
def test_import_module(self):
for old, new in self.modules.items():
b = "import %s" % old
a = "import %s" % new
self.check(b, a)
b = "import foo, %s, bar" % old
a = "import foo, %s, bar" % new
self.check(b, a)
def test_import_from(self):
for old, new in self.modules.items():
b = "from %s import foo" % old
a = "from %s import foo" % new
self.check(b, a)
b = "from %s import foo, bar" % old
a = "from %s import foo, bar" % new
self.check(b, a)
b = "from %s import (yes, no)" % old
a = "from %s import (yes, no)" % new
self.check(b, a)
def test_import_module_as(self):
for old, new in self.modules.items():
b = "import %s as foo_bar" % old
a = "import %s as foo_bar" % new
self.check(b, a)
b = "import %s as foo_bar" % old
a = "import %s as foo_bar" % new
self.check(b, a)
def test_import_from_as(self):
for old, new in self.modules.items():
b = "from %s import foo as bar" % old
a = "from %s import foo as bar" % new
self.check(b, a)
def test_star(self):
for old, new in self.modules.items():
b = "from %s import *" % old
a = "from %s import *" % new
self.check(b, a)
def test_import_module_usage(self):
for old, new in self.modules.items():
b = """
import %s
foo(%s.bar)
""" % (old, old)
a = """
import %s
foo(%s.bar)
""" % (new, new)
self.check(b, a)
b = """
from %s import x
%s = 23
""" % (old, old)
a = """
from %s import x
%s = 23
""" % (new, old)
self.check(b, a)
s = """
def f():
%s.method()
""" % (old,)
self.unchanged(s)
# test nested usage
b = """
import %s
%s.bar(%s.foo)
""" % (old, old, old)
a = """
import %s
%s.bar(%s.foo)
""" % (new, new, new)
self.check(b, a)
b = """
import %s
x.%s
""" % (old, old)
a = """
import %s
x.%s
""" % (new, old)
self.check(b, a)
class Test_imports(FixerTestCase, ImportsFixerTests):
fixer = "imports"
from ..fixes.fix_imports import MAPPING as modules
def test_multiple_imports(self):
b = """import urlparse, cStringIO"""
a = """import urllib.parse, io"""
self.check(b, a)
def test_multiple_imports_as(self):
b = """
import copy_reg as bar, HTMLParser as foo, urlparse
s = urlparse.spam(bar.foo())
"""
a = """
import copyreg as bar, html.parser as foo, urllib.parse
s = urllib.parse.spam(bar.foo())
"""
self.check(b, a)
class Test_imports2(FixerTestCase, ImportsFixerTests):
fixer = "imports2"
from ..fixes.fix_imports2 import MAPPING as modules
class Test_imports_fixer_order(FixerTestCase, ImportsFixerTests):
def setUp(self):
super(Test_imports_fixer_order, self).setUp(['imports', 'imports2'])
from ..fixes.fix_imports2 import MAPPING as mapping2
self.modules = mapping2.copy()
from ..fixes.fix_imports import MAPPING as mapping1
for key in ('dbhash', 'dumbdbm', 'dbm', 'gdbm'):
self.modules[key] = mapping1[key]
def test_after_local_imports_refactoring(self):
for fix in ("imports", "imports2"):
self.fixer = fix
self.assert_runs_after("import")
class Test_urllib(FixerTestCase):
fixer = "urllib"
from ..fixes.fix_urllib import MAPPING as modules
def test_import_module(self):
for old, changes in self.modules.items():
b = "import %s" % old
a = "import %s" % ", ".join(map(itemgetter(0), changes))
self.check(b, a)
def test_import_from(self):
for old, changes in self.modules.items():
all_members = []
for new, members in changes:
for member in members:
all_members.append(member)
b = "from %s import %s" % (old, member)
a = "from %s import %s" % (new, member)
self.check(b, a)
s = "from foo import %s" % member
self.unchanged(s)
b = "from %s import %s" % (old, ", ".join(members))
a = "from %s import %s" % (new, ", ".join(members))
self.check(b, a)
s = "from foo import %s" % ", ".join(members)
self.unchanged(s)
# test the breaking of a module into multiple replacements
b = "from %s import %s" % (old, ", ".join(all_members))
a = "\n".join(["from %s import %s" % (new, ", ".join(members))
for (new, members) in changes])
self.check(b, a)
def test_import_module_as(self):
for old in self.modules:
s = "import %s as foo" % old
self.warns_unchanged(s, "This module is now multiple modules")
def test_import_from_as(self):
for old, changes in self.modules.items():
for new, members in changes:
for member in members:
b = "from %s import %s as foo_bar" % (old, member)
a = "from %s import %s as foo_bar" % (new, member)
self.check(b, a)
b = "from %s import %s as blah, %s" % (old, member, member)
a = "from %s import %s as blah, %s" % (new, member, member)
self.check(b, a)
def test_star(self):
for old in self.modules:
s = "from %s import *" % old
self.warns_unchanged(s, "Cannot handle star imports")
def test_indented(self):
b = """
def foo():
from urllib import urlencode, urlopen
"""
a = """
def foo():
from urllib.parse import urlencode
from urllib.request import urlopen
"""
self.check(b, a)
b = """
def foo():
other()
from urllib import urlencode, urlopen
"""
a = """
def foo():
other()
from urllib.parse import urlencode
from urllib.request import urlopen
"""
self.check(b, a)
def test_import_module_usage(self):
for old, changes in self.modules.items():
for new, members in changes:
for member in members:
new_import = ", ".join([n for (n, mems)
in self.modules[old]])
b = """
import %s
foo(%s.%s)
""" % (old, old, member)
a = """
import %s
foo(%s.%s)
""" % (new_import, new, member)
self.check(b, a)
b = """
import %s
%s.%s(%s.%s)
""" % (old, old, member, old, member)
a = """
import %s
%s.%s(%s.%s)
""" % (new_import, new, member, new, member)
self.check(b, a)
class Test_input(FixerTestCase):
fixer = "input"
def test_prefix_preservation(self):
b = """x = input( )"""
a = """x = eval(input( ))"""
self.check(b, a)
b = """x = input( '' )"""
a = """x = eval(input( '' ))"""
self.check(b, a)
def test_trailing_comment(self):
b = """x = input() # foo"""
a = """x = eval(input()) # foo"""
self.check(b, a)
def test_idempotency(self):
s = """x = eval(input())"""
self.unchanged(s)
s = """x = eval(input(''))"""
self.unchanged(s)
s = """x = eval(input(foo(5) + 9))"""
self.unchanged(s)
def test_1(self):
b = """x = input()"""
a = """x = eval(input())"""
self.check(b, a)
def test_2(self):
b = """x = input('')"""
a = """x = eval(input(''))"""
self.check(b, a)
def test_3(self):
b = """x = input('prompt')"""
a = """x = eval(input('prompt'))"""
self.check(b, a)
def test_4(self):
b = """x = input(foo(5) + 9)"""
a = """x = eval(input(foo(5) + 9))"""
self.check(b, a)
class Test_tuple_params(FixerTestCase):
fixer = "tuple_params"
def test_unchanged_1(self):
s = """def foo(): pass"""
self.unchanged(s)
def test_unchanged_2(self):
s = """def foo(a, b, c): pass"""
self.unchanged(s)
def test_unchanged_3(self):
s = """def foo(a=3, b=4, c=5): pass"""
self.unchanged(s)
def test_1(self):
b = """
def foo(((a, b), c)):
x = 5"""
a = """
def foo(xxx_todo_changeme):
((a, b), c) = xxx_todo_changeme
x = 5"""
self.check(b, a)
def test_2(self):
b = """
def foo(((a, b), c), d):
x = 5"""
a = """
def foo(xxx_todo_changeme, d):
((a, b), c) = xxx_todo_changeme
x = 5"""
self.check(b, a)
def test_3(self):
b = """
def foo(((a, b), c), d) -> e:
x = 5"""
a = """
def foo(xxx_todo_changeme, d) -> e:
((a, b), c) = xxx_todo_changeme
x = 5"""
self.check(b, a)
def test_semicolon(self):
b = """
def foo(((a, b), c)): x = 5; y = 7"""
a = """
def foo(xxx_todo_changeme): ((a, b), c) = xxx_todo_changeme; x = 5; y = 7"""
self.check(b, a)
def test_keywords(self):
b = """
def foo(((a, b), c), d, e=5) -> z:
x = 5"""
a = """
def foo(xxx_todo_changeme, d, e=5) -> z:
((a, b), c) = xxx_todo_changeme
x = 5"""
self.check(b, a)
def test_varargs(self):
b = """
def foo(((a, b), c), d, *vargs, **kwargs) -> z:
x = 5"""
a = """
def foo(xxx_todo_changeme, d, *vargs, **kwargs) -> z:
((a, b), c) = xxx_todo_changeme
x = 5"""
self.check(b, a)
def test_multi_1(self):
b = """
def foo(((a, b), c), (d, e, f)) -> z:
x = 5"""
a = """
def foo(xxx_todo_changeme, xxx_todo_changeme1) -> z:
((a, b), c) = xxx_todo_changeme
(d, e, f) = xxx_todo_changeme1
x = 5"""
self.check(b, a)
def test_multi_2(self):
b = """
def foo(x, ((a, b), c), d, (e, f, g), y) -> z:
x = 5"""
a = """
def foo(x, xxx_todo_changeme, d, xxx_todo_changeme1, y) -> z:
((a, b), c) = xxx_todo_changeme
(e, f, g) = xxx_todo_changeme1
x = 5"""
self.check(b, a)
def test_docstring(self):
b = """
def foo(((a, b), c), (d, e, f)) -> z:
"foo foo foo foo"
x = 5"""
a = """
def foo(xxx_todo_changeme, xxx_todo_changeme1) -> z:
"foo foo foo foo"
((a, b), c) = xxx_todo_changeme
(d, e, f) = xxx_todo_changeme1
x = 5"""
self.check(b, a)
def test_lambda_no_change(self):
s = """lambda x: x + 5"""
self.unchanged(s)
def test_lambda_parens_single_arg(self):
b = """lambda (x): x + 5"""
a = """lambda x: x + 5"""
self.check(b, a)
b = """lambda(x): x + 5"""
a = """lambda x: x + 5"""
self.check(b, a)
b = """lambda ((((x)))): x + 5"""
a = """lambda x: x + 5"""
self.check(b, a)
b = """lambda((((x)))): x + 5"""
a = """lambda x: x + 5"""
self.check(b, a)
def test_lambda_simple(self):
b = """lambda (x, y): x + f(y)"""
a = """lambda x_y: x_y[0] + f(x_y[1])"""
self.check(b, a)
b = """lambda(x, y): x + f(y)"""
a = """lambda x_y: x_y[0] + f(x_y[1])"""
self.check(b, a)
b = """lambda (((x, y))): x + f(y)"""
a = """lambda x_y: x_y[0] + f(x_y[1])"""
self.check(b, a)
b = """lambda(((x, y))): x + f(y)"""
a = """lambda x_y: x_y[0] + f(x_y[1])"""
self.check(b, a)
def test_lambda_one_tuple(self):
b = """lambda (x,): x + f(x)"""
a = """lambda x1: x1[0] + f(x1[0])"""
self.check(b, a)
b = """lambda (((x,))): x + f(x)"""
a = """lambda x1: x1[0] + f(x1[0])"""
self.check(b, a)
def test_lambda_simple_multi_use(self):
b = """lambda (x, y): x + x + f(x) + x"""
a = """lambda x_y: x_y[0] + x_y[0] + f(x_y[0]) + x_y[0]"""
self.check(b, a)
def test_lambda_simple_reverse(self):
b = """lambda (x, y): y + x"""
a = """lambda x_y: x_y[1] + x_y[0]"""
self.check(b, a)
def test_lambda_nested(self):
b = """lambda (x, (y, z)): x + y + z"""
a = """lambda x_y_z: x_y_z[0] + x_y_z[1][0] + x_y_z[1][1]"""
self.check(b, a)
b = """lambda (((x, (y, z)))): x + y + z"""
a = """lambda x_y_z: x_y_z[0] + x_y_z[1][0] + x_y_z[1][1]"""
self.check(b, a)
def test_lambda_nested_multi_use(self):
b = """lambda (x, (y, z)): x + y + f(y)"""
a = """lambda x_y_z: x_y_z[0] + x_y_z[1][0] + f(x_y_z[1][0])"""
self.check(b, a)
class Test_methodattrs(FixerTestCase):
fixer = "methodattrs"
attrs = ["func", "self", "class"]
def test(self):
for attr in self.attrs:
b = "a.im_%s" % attr
if attr == "class":
a = "a.__self__.__class__"
else:
a = "a.__%s__" % attr
self.check(b, a)
b = "self.foo.im_%s.foo_bar" % attr
if attr == "class":
a = "self.foo.__self__.__class__.foo_bar"
else:
a = "self.foo.__%s__.foo_bar" % attr
self.check(b, a)
def test_unchanged(self):
for attr in self.attrs:
s = "foo(im_%s + 5)" % attr
self.unchanged(s)
s = "f(foo.__%s__)" % attr
self.unchanged(s)
s = "f(foo.__%s__.foo)" % attr
self.unchanged(s)
class Test_next(FixerTestCase):
fixer = "next"
def test_1(self):
b = """it.next()"""
a = """next(it)"""
self.check(b, a)
def test_2(self):
b = """a.b.c.d.next()"""
a = """next(a.b.c.d)"""
self.check(b, a)
def test_3(self):
b = """(a + b).next()"""
a = """next((a + b))"""
self.check(b, a)
def test_4(self):
b = """a().next()"""
a = """next(a())"""
self.check(b, a)
def test_5(self):
b = """a().next() + b"""
a = """next(a()) + b"""
self.check(b, a)
def test_6(self):
b = """c( a().next() + b)"""
a = """c( next(a()) + b)"""
self.check(b, a)
def test_prefix_preservation_1(self):
b = """
for a in b:
foo(a)
a.next()
"""
a = """
for a in b:
foo(a)
next(a)
"""
self.check(b, a)
def test_prefix_preservation_2(self):
b = """
for a in b:
foo(a) # abc
# def
a.next()
"""
a = """
for a in b:
foo(a) # abc
# def
next(a)
"""
self.check(b, a)
def test_prefix_preservation_3(self):
b = """
next = 5
for a in b:
foo(a)
a.next()
"""
a = """
next = 5
for a in b:
foo(a)
a.__next__()
"""
self.check(b, a, ignore_warnings=True)
def test_prefix_preservation_4(self):
b = """
next = 5
for a in b:
foo(a) # abc
# def
a.next()
"""
a = """
next = 5
for a in b:
foo(a) # abc
# def
a.__next__()
"""
self.check(b, a, ignore_warnings=True)
def test_prefix_preservation_5(self):
b = """
next = 5
for a in b:
foo(foo(a), # abc
a.next())
"""
a = """
next = 5
for a in b:
foo(foo(a), # abc
a.__next__())
"""
self.check(b, a, ignore_warnings=True)
def test_prefix_preservation_6(self):
b = """
for a in b:
foo(foo(a), # abc
a.next())
"""
a = """
for a in b:
foo(foo(a), # abc
next(a))
"""
self.check(b, a)
def test_method_1(self):
b = """
class A:
def next(self):
pass
"""
a = """
class A:
def __next__(self):
pass
"""
self.check(b, a)
def test_method_2(self):
b = """
class A(object):
def next(self):
pass
"""
a = """
class A(object):
def __next__(self):
pass
"""
self.check(b, a)
def test_method_3(self):
b = """
class A:
def next(x):
pass
"""
a = """
class A:
def __next__(x):
pass
"""
self.check(b, a)
def test_method_4(self):
b = """
class A:
def __init__(self, foo):
self.foo = foo
def next(self):
pass
def __iter__(self):
return self
"""
a = """
class A:
def __init__(self, foo):
self.foo = foo
def __next__(self):
pass
def __iter__(self):
return self
"""
self.check(b, a)
def test_method_unchanged(self):
s = """
class A:
def next(self, a, b):
pass
"""
self.unchanged(s)
def test_shadowing_assign_simple(self):
s = """
next = foo
class A:
def next(self, a, b):
pass
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_shadowing_assign_tuple_1(self):
s = """
(next, a) = foo
class A:
def next(self, a, b):
pass
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_shadowing_assign_tuple_2(self):
s = """
(a, (b, (next, c)), a) = foo
class A:
def next(self, a, b):
pass
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_shadowing_assign_list_1(self):
s = """
[next, a] = foo
class A:
def next(self, a, b):
pass
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_shadowing_assign_list_2(self):
s = """
[a, [b, [next, c]], a] = foo
class A:
def next(self, a, b):
pass
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_builtin_assign(self):
s = """
def foo():
__builtin__.next = foo
class A:
def next(self, a, b):
pass
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_builtin_assign_in_tuple(self):
s = """
def foo():
(a, __builtin__.next) = foo
class A:
def next(self, a, b):
pass
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_builtin_assign_in_list(self):
s = """
def foo():
[a, __builtin__.next] = foo
class A:
def next(self, a, b):
pass
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_assign_to_next(self):
s = """
def foo():
A.next = foo
class A:
def next(self, a, b):
pass
"""
self.unchanged(s)
def test_assign_to_next_in_tuple(self):
s = """
def foo():
(a, A.next) = foo
class A:
def next(self, a, b):
pass
"""
self.unchanged(s)
def test_assign_to_next_in_list(self):
s = """
def foo():
[a, A.next] = foo
class A:
def next(self, a, b):
pass
"""
self.unchanged(s)
def test_shadowing_import_1(self):
s = """
import foo.bar as next
class A:
def next(self, a, b):
pass
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_shadowing_import_2(self):
s = """
import bar, bar.foo as next
class A:
def next(self, a, b):
pass
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_shadowing_import_3(self):
s = """
import bar, bar.foo as next, baz
class A:
def next(self, a, b):
pass
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_shadowing_import_from_1(self):
s = """
from x import next
class A:
def next(self, a, b):
pass
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_shadowing_import_from_2(self):
s = """
from x.a import next
class A:
def next(self, a, b):
pass
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_shadowing_import_from_3(self):
s = """
from x import a, next, b
class A:
def next(self, a, b):
pass
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_shadowing_import_from_4(self):
s = """
from x.a import a, next, b
class A:
def next(self, a, b):
pass
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_shadowing_funcdef_1(self):
s = """
def next(a):
pass
class A:
def next(self, a, b):
pass
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_shadowing_funcdef_2(self):
b = """
def next(a):
pass
class A:
def next(self):
pass
it.next()
"""
a = """
def next(a):
pass
class A:
def __next__(self):
pass
it.__next__()
"""
self.warns(b, a, "Calls to builtin next() possibly shadowed")
def test_shadowing_global_1(self):
s = """
def f():
global next
next = 5
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_shadowing_global_2(self):
s = """
def f():
global a, next, b
next = 5
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_shadowing_for_simple(self):
s = """
for next in it():
pass
b = 5
c = 6
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_shadowing_for_tuple_1(self):
s = """
for next, b in it():
pass
b = 5
c = 6
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_shadowing_for_tuple_2(self):
s = """
for a, (next, c), b in it():
pass
b = 5
c = 6
"""
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
def test_noncall_access_1(self):
b = """gnext = g.next"""
a = """gnext = g.__next__"""
self.check(b, a)
def test_noncall_access_2(self):
b = """f(g.next + 5)"""
a = """f(g.__next__ + 5)"""
self.check(b, a)
def test_noncall_access_3(self):
b = """f(g().next + 5)"""
a = """f(g().__next__ + 5)"""
self.check(b, a)
class Test_nonzero(FixerTestCase):
fixer = "nonzero"
def test_1(self):
b = """
class A:
def __nonzero__(self):
pass
"""
a = """
class A:
def __bool__(self):
pass
"""
self.check(b, a)
def test_2(self):
b = """
class A(object):
def __nonzero__(self):
pass
"""
a = """
class A(object):
def __bool__(self):
pass
"""
self.check(b, a)
def test_unchanged_1(self):
s = """
class A(object):
def __bool__(self):
pass
"""
self.unchanged(s)
def test_unchanged_2(self):
s = """
class A(object):
def __nonzero__(self, a):
pass
"""
self.unchanged(s)
def test_unchanged_func(self):
s = """
def __nonzero__(self):
pass
"""
self.unchanged(s)
class Test_numliterals(FixerTestCase):
fixer = "numliterals"
def test_octal_1(self):
b = """0755"""
a = """0o755"""
self.check(b, a)
def test_long_int_1(self):
b = """a = 12L"""
a = """a = 12"""
self.check(b, a)
def test_long_int_2(self):
b = """a = 12l"""
a = """a = 12"""
self.check(b, a)
def test_long_hex(self):
b = """b = 0x12l"""
a = """b = 0x12"""
self.check(b, a)
def test_comments_and_spacing(self):
b = """b = 0x12L"""
a = """b = 0x12"""
self.check(b, a)
b = """b = 0755 # spam"""
a = """b = 0o755 # spam"""
self.check(b, a)
def test_unchanged_int(self):
s = """5"""
self.unchanged(s)
def test_unchanged_float(self):
s = """5.0"""
self.unchanged(s)
def test_unchanged_octal(self):
s = """0o755"""
self.unchanged(s)
def test_unchanged_hex(self):
s = """0xABC"""
self.unchanged(s)
def test_unchanged_exp(self):
s = """5.0e10"""
self.unchanged(s)
def test_unchanged_complex_int(self):
s = """5 + 4j"""
self.unchanged(s)
def test_unchanged_complex_float(self):
s = """5.4 + 4.9j"""
self.unchanged(s)
def test_unchanged_complex_bare(self):
s = """4j"""
self.unchanged(s)
s = """4.4j"""
self.unchanged(s)
class Test_renames(FixerTestCase):
fixer = "renames"
modules = {"sys": ("maxint", "maxsize"),
}
def test_import_from(self):
for mod, (old, new) in self.modules.items():
b = "from %s import %s" % (mod, old)
a = "from %s import %s" % (mod, new)
self.check(b, a)
s = "from foo import %s" % old
self.unchanged(s)
def test_import_from_as(self):
for mod, (old, new) in self.modules.items():
b = "from %s import %s as foo_bar" % (mod, old)
a = "from %s import %s as foo_bar" % (mod, new)
self.check(b, a)
def test_import_module_usage(self):
for mod, (old, new) in self.modules.items():
b = """
import %s
foo(%s, %s.%s)
""" % (mod, mod, mod, old)
a = """
import %s
foo(%s, %s.%s)
""" % (mod, mod, mod, new)
self.check(b, a)
def XXX_test_from_import_usage(self):
# not implemented yet
for mod, (old, new) in self.modules.items():
b = """
from %s import %s
foo(%s, %s)
""" % (mod, old, mod, old)
a = """
from %s import %s
foo(%s, %s)
""" % (mod, new, mod, new)
self.check(b, a)
class Test_unicode(FixerTestCase):
fixer = "unicode"
def test_whitespace(self):
b = """unicode( x)"""
a = """str( x)"""
self.check(b, a)
b = """ unicode(x )"""
a = """ str(x )"""
self.check(b, a)
b = """ u'h'"""
a = """ 'h'"""
self.check(b, a)
def test_unicode_call(self):
b = """unicode(x, y, z)"""
a = """str(x, y, z)"""
self.check(b, a)
def test_unichr(self):
b = """unichr(u'h')"""
a = """chr('h')"""
self.check(b, a)
def test_unicode_literal_1(self):
b = '''u"x"'''
a = '''"x"'''
self.check(b, a)
def test_unicode_literal_2(self):
b = """ur'x'"""
a = """r'x'"""
self.check(b, a)
def test_unicode_literal_3(self):
b = """UR'''x''' """
a = """R'''x''' """
self.check(b, a)
class Test_callable(FixerTestCase):
fixer = "callable"
def test_prefix_preservation(self):
b = """callable( x)"""
a = """import collections\nisinstance( x, collections.Callable)"""
self.check(b, a)
b = """if callable(x): pass"""
a = """import collections
if isinstance(x, collections.Callable): pass"""
self.check(b, a)
def test_callable_call(self):
b = """callable(x)"""
a = """import collections\nisinstance(x, collections.Callable)"""
self.check(b, a)
def test_global_import(self):
b = """
def spam(foo):
callable(foo)"""[1:]
a = """
import collections
def spam(foo):
isinstance(foo, collections.Callable)"""[1:]
self.check(b, a)
b = """
import collections
def spam(foo):
callable(foo)"""[1:]
# same output if it was already imported
self.check(b, a)
b = """
from collections import *
def spam(foo):
callable(foo)"""[1:]
a = """
from collections import *
import collections
def spam(foo):
isinstance(foo, collections.Callable)"""[1:]
self.check(b, a)
b = """
do_stuff()
do_some_other_stuff()
assert callable(do_stuff)"""[1:]
a = """
import collections
do_stuff()
do_some_other_stuff()
assert isinstance(do_stuff, collections.Callable)"""[1:]
self.check(b, a)
b = """
if isinstance(do_stuff, Callable):
assert callable(do_stuff)
do_stuff(do_stuff)
if not callable(do_stuff):
exit(1)
else:
assert callable(do_stuff)
else:
assert not callable(do_stuff)"""[1:]
a = """
import collections
if isinstance(do_stuff, Callable):
assert isinstance(do_stuff, collections.Callable)
do_stuff(do_stuff)
if not isinstance(do_stuff, collections.Callable):
exit(1)
else:
assert isinstance(do_stuff, collections.Callable)
else:
assert not isinstance(do_stuff, collections.Callable)"""[1:]
self.check(b, a)
def test_callable_should_not_change(self):
a = """callable(*x)"""
self.unchanged(a)
a = """callable(x, y)"""
self.unchanged(a)
a = """callable(x, kw=y)"""
self.unchanged(a)
a = """callable()"""
self.unchanged(a)
class Test_filter(FixerTestCase):
fixer = "filter"
def test_prefix_preservation(self):
b = """x = filter( foo, 'abc' )"""
a = """x = list(filter( foo, 'abc' ))"""
self.check(b, a)
b = """x = filter( None , 'abc' )"""
a = """x = [_f for _f in 'abc' if _f]"""
self.check(b, a)
def test_filter_basic(self):
b = """x = filter(None, 'abc')"""
a = """x = [_f for _f in 'abc' if _f]"""
self.check(b, a)
b = """x = len(filter(f, 'abc'))"""
a = """x = len(list(filter(f, 'abc')))"""
self.check(b, a)
b = """x = filter(lambda x: x%2 == 0, range(10))"""
a = """x = [x for x in range(10) if x%2 == 0]"""
self.check(b, a)
# Note the parens around x
b = """x = filter(lambda (x): x%2 == 0, range(10))"""
a = """x = [x for x in range(10) if x%2 == 0]"""
self.check(b, a)
# XXX This (rare) case is not supported
## b = """x = filter(f, 'abc')[0]"""
## a = """x = list(filter(f, 'abc'))[0]"""
## self.check(b, a)
def test_filter_nochange(self):
a = """b.join(filter(f, 'abc'))"""
self.unchanged(a)
a = """(a + foo(5)).join(filter(f, 'abc'))"""
self.unchanged(a)
a = """iter(filter(f, 'abc'))"""
self.unchanged(a)
a = """list(filter(f, 'abc'))"""
self.unchanged(a)
a = """list(filter(f, 'abc'))[0]"""
self.unchanged(a)
a = """set(filter(f, 'abc'))"""
self.unchanged(a)
a = """set(filter(f, 'abc')).pop()"""
self.unchanged(a)
a = """tuple(filter(f, 'abc'))"""
self.unchanged(a)
a = """any(filter(f, 'abc'))"""
self.unchanged(a)
a = """all(filter(f, 'abc'))"""
self.unchanged(a)
a = """sum(filter(f, 'abc'))"""
self.unchanged(a)
a = """sorted(filter(f, 'abc'))"""
self.unchanged(a)
a = """sorted(filter(f, 'abc'), key=blah)"""
self.unchanged(a)
a = """sorted(filter(f, 'abc'), key=blah)[0]"""
self.unchanged(a)
a = """for i in filter(f, 'abc'): pass"""
self.unchanged(a)
a = """[x for x in filter(f, 'abc')]"""
self.unchanged(a)
a = """(x for x in filter(f, 'abc'))"""
self.unchanged(a)
def test_future_builtins(self):
a = "from future_builtins import spam, filter; filter(f, 'ham')"
self.unchanged(a)
b = """from future_builtins import spam; x = filter(f, 'abc')"""
a = """from future_builtins import spam; x = list(filter(f, 'abc'))"""
self.check(b, a)
a = "from future_builtins import *; filter(f, 'ham')"
self.unchanged(a)
class Test_map(FixerTestCase):
fixer = "map"
def check(self, b, a):
self.unchanged("from future_builtins import map; " + b, a)
super(Test_map, self).check(b, a)
def test_prefix_preservation(self):
b = """x = map( f, 'abc' )"""
a = """x = list(map( f, 'abc' ))"""
self.check(b, a)
def test_trailing_comment(self):
b = """x = map(f, 'abc') # foo"""
a = """x = list(map(f, 'abc')) # foo"""
self.check(b, a)
def test_None_with_multiple_arguments(self):
s = """x = map(None, a, b, c)"""
self.warns_unchanged(s, "cannot convert map(None, ...) with "
"multiple arguments")
def test_map_basic(self):
b = """x = map(f, 'abc')"""
a = """x = list(map(f, 'abc'))"""
self.check(b, a)
b = """x = len(map(f, 'abc', 'def'))"""
a = """x = len(list(map(f, 'abc', 'def')))"""
self.check(b, a)
b = """x = map(None, 'abc')"""
a = """x = list('abc')"""
self.check(b, a)
b = """x = map(lambda x: x+1, range(4))"""
a = """x = [x+1 for x in range(4)]"""
self.check(b, a)
# Note the parens around x
b = """x = map(lambda (x): x+1, range(4))"""
a = """x = [x+1 for x in range(4)]"""
self.check(b, a)
b = """
foo()
# foo
map(f, x)
"""
a = """
foo()
# foo
list(map(f, x))
"""
self.warns(b, a, "You should use a for loop here")
# XXX This (rare) case is not supported
## b = """x = map(f, 'abc')[0]"""
## a = """x = list(map(f, 'abc'))[0]"""
## self.check(b, a)
def test_map_nochange(self):
a = """b.join(map(f, 'abc'))"""
self.unchanged(a)
a = """(a + foo(5)).join(map(f, 'abc'))"""
self.unchanged(a)
a = """iter(map(f, 'abc'))"""
self.unchanged(a)
a = """list(map(f, 'abc'))"""
self.unchanged(a)
a = """list(map(f, 'abc'))[0]"""
self.unchanged(a)
a = """set(map(f, 'abc'))"""
self.unchanged(a)
a = """set(map(f, 'abc')).pop()"""
self.unchanged(a)
a = """tuple(map(f, 'abc'))"""
self.unchanged(a)
a = """any(map(f, 'abc'))"""
self.unchanged(a)
a = """all(map(f, 'abc'))"""
self.unchanged(a)
a = """sum(map(f, 'abc'))"""
self.unchanged(a)
a = """sorted(map(f, 'abc'))"""
self.unchanged(a)
a = """sorted(map(f, 'abc'), key=blah)"""
self.unchanged(a)
a = """sorted(map(f, 'abc'), key=blah)[0]"""
self.unchanged(a)
a = """for i in map(f, 'abc'): pass"""
self.unchanged(a)
a = """[x for x in map(f, 'abc')]"""
self.unchanged(a)
a = """(x for x in map(f, 'abc'))"""
self.unchanged(a)
def test_future_builtins(self):
a = "from future_builtins import spam, map, eggs; map(f, 'ham')"
self.unchanged(a)
b = """from future_builtins import spam, eggs; x = map(f, 'abc')"""
a = """from future_builtins import spam, eggs; x = list(map(f, 'abc'))"""
self.check(b, a)
a = "from future_builtins import *; map(f, 'ham')"
self.unchanged(a)
class Test_zip(FixerTestCase):
fixer = "zip"
def check(self, b, a):
self.unchanged("from future_builtins import zip; " + b, a)
super(Test_zip, self).check(b, a)
def test_zip_basic(self):
b = """x = zip(a, b, c)"""
a = """x = list(zip(a, b, c))"""
self.check(b, a)
b = """x = len(zip(a, b))"""
a = """x = len(list(zip(a, b)))"""
self.check(b, a)
def test_zip_nochange(self):
a = """b.join(zip(a, b))"""
self.unchanged(a)
a = """(a + foo(5)).join(zip(a, b))"""
self.unchanged(a)
a = """iter(zip(a, b))"""
self.unchanged(a)
a = """list(zip(a, b))"""
self.unchanged(a)
a = """list(zip(a, b))[0]"""
self.unchanged(a)
a = """set(zip(a, b))"""
self.unchanged(a)
a = """set(zip(a, b)).pop()"""
self.unchanged(a)
a = """tuple(zip(a, b))"""
self.unchanged(a)
a = """any(zip(a, b))"""
self.unchanged(a)
a = """all(zip(a, b))"""
self.unchanged(a)
a = """sum(zip(a, b))"""
self.unchanged(a)
a = """sorted(zip(a, b))"""
self.unchanged(a)
a = """sorted(zip(a, b), key=blah)"""
self.unchanged(a)
a = """sorted(zip(a, b), key=blah)[0]"""
self.unchanged(a)
a = """for i in zip(a, b): pass"""
self.unchanged(a)
a = """[x for x in zip(a, b)]"""
self.unchanged(a)
a = """(x for x in zip(a, b))"""
self.unchanged(a)
def test_future_builtins(self):
a = "from future_builtins import spam, zip, eggs; zip(a, b)"
self.unchanged(a)
b = """from future_builtins import spam, eggs; x = zip(a, b)"""
a = """from future_builtins import spam, eggs; x = list(zip(a, b))"""
self.check(b, a)
a = "from future_builtins import *; zip(a, b)"
self.unchanged(a)
class Test_standarderror(FixerTestCase):
fixer = "standarderror"
def test(self):
b = """x = StandardError()"""
a = """x = Exception()"""
self.check(b, a)
b = """x = StandardError(a, b, c)"""
a = """x = Exception(a, b, c)"""
self.check(b, a)
b = """f(2 + StandardError(a, b, c))"""
a = """f(2 + Exception(a, b, c))"""
self.check(b, a)
class Test_types(FixerTestCase):
fixer = "types"
def test_basic_types_convert(self):
b = """types.StringType"""
a = """bytes"""
self.check(b, a)
b = """types.DictType"""
a = """dict"""
self.check(b, a)
b = """types . IntType"""
a = """int"""
self.check(b, a)
b = """types.ListType"""
a = """list"""
self.check(b, a)
b = """types.LongType"""
a = """int"""
self.check(b, a)
b = """types.NoneType"""
a = """type(None)"""
self.check(b, a)
class Test_idioms(FixerTestCase):
fixer = "idioms"
def test_while(self):
b = """while 1: foo()"""
a = """while True: foo()"""
self.check(b, a)
b = """while 1: foo()"""
a = """while True: foo()"""
self.check(b, a)
b = """
while 1:
foo()
"""
a = """
while True:
foo()
"""
self.check(b, a)
def test_while_unchanged(self):
s = """while 11: foo()"""
self.unchanged(s)
s = """while 0: foo()"""
self.unchanged(s)
s = """while foo(): foo()"""
self.unchanged(s)
s = """while []: foo()"""
self.unchanged(s)
def test_eq_simple(self):
b = """type(x) == T"""
a = """isinstance(x, T)"""
self.check(b, a)
b = """if type(x) == T: pass"""
a = """if isinstance(x, T): pass"""
self.check(b, a)
def test_eq_reverse(self):
b = """T == type(x)"""
a = """isinstance(x, T)"""
self.check(b, a)
b = """if T == type(x): pass"""
a = """if isinstance(x, T): pass"""
self.check(b, a)
def test_eq_expression(self):
b = """type(x+y) == d.get('T')"""
a = """isinstance(x+y, d.get('T'))"""
self.check(b, a)
b = """type( x + y) == d.get('T')"""
a = """isinstance(x + y, d.get('T'))"""
self.check(b, a)
def test_is_simple(self):
b = """type(x) is T"""
a = """isinstance(x, T)"""
self.check(b, a)
b = """if type(x) is T: pass"""
a = """if isinstance(x, T): pass"""
self.check(b, a)
def test_is_reverse(self):
b = """T is type(x)"""
a = """isinstance(x, T)"""
self.check(b, a)
b = """if T is type(x): pass"""
a = """if isinstance(x, T): pass"""
self.check(b, a)
def test_is_expression(self):
b = """type(x+y) is d.get('T')"""
a = """isinstance(x+y, d.get('T'))"""
self.check(b, a)
b = """type( x + y) is d.get('T')"""
a = """isinstance(x + y, d.get('T'))"""
self.check(b, a)
def test_is_not_simple(self):
b = """type(x) is not T"""
a = """not isinstance(x, T)"""
self.check(b, a)
b = """if type(x) is not T: pass"""
a = """if not isinstance(x, T): pass"""
self.check(b, a)
def test_is_not_reverse(self):
b = """T is not type(x)"""
a = """not isinstance(x, T)"""
self.check(b, a)
b = """if T is not type(x): pass"""
a = """if not isinstance(x, T): pass"""
self.check(b, a)
def test_is_not_expression(self):
b = """type(x+y) is not d.get('T')"""
a = """not isinstance(x+y, d.get('T'))"""
self.check(b, a)
b = """type( x + y) is not d.get('T')"""
a = """not isinstance(x + y, d.get('T'))"""
self.check(b, a)
def test_ne_simple(self):
b = """type(x) != T"""
a = """not isinstance(x, T)"""
self.check(b, a)
b = """if type(x) != T: pass"""
a = """if not isinstance(x, T): pass"""
self.check(b, a)
def test_ne_reverse(self):
b = """T != type(x)"""
a = """not isinstance(x, T)"""
self.check(b, a)
b = """if T != type(x): pass"""
a = """if not isinstance(x, T): pass"""
self.check(b, a)
def test_ne_expression(self):
b = """type(x+y) != d.get('T')"""
a = """not isinstance(x+y, d.get('T'))"""
self.check(b, a)
b = """type( x + y) != d.get('T')"""
a = """not isinstance(x + y, d.get('T'))"""
self.check(b, a)
def test_type_unchanged(self):
a = """type(x).__name__"""
self.unchanged(a)
def test_sort_list_call(self):
b = """
v = list(t)
v.sort()
foo(v)
"""
a = """
v = sorted(t)
foo(v)
"""
self.check(b, a)
b = """
v = list(foo(b) + d)
v.sort()
foo(v)
"""
a = """
v = sorted(foo(b) + d)
foo(v)
"""
self.check(b, a)
b = """
while x:
v = list(t)
v.sort()
foo(v)
"""
a = """
while x:
v = sorted(t)
foo(v)
"""
self.check(b, a)
b = """
v = list(t)
# foo
v.sort()
foo(v)
"""
a = """
v = sorted(t)
# foo
foo(v)
"""
self.check(b, a)
b = r"""
v = list( t)
v.sort()
foo(v)
"""
a = r"""
v = sorted( t)
foo(v)
"""
self.check(b, a)
b = r"""
try:
m = list(s)
m.sort()
except: pass
"""
a = r"""
try:
m = sorted(s)
except: pass
"""
self.check(b, a)
b = r"""
try:
m = list(s)
# foo
m.sort()
except: pass
"""
a = r"""
try:
m = sorted(s)
# foo
except: pass
"""
self.check(b, a)
b = r"""
m = list(s)
# more comments
m.sort()"""
a = r"""
m = sorted(s)
# more comments"""
self.check(b, a)
def test_sort_simple_expr(self):
b = """
v = t
v.sort()
foo(v)
"""
a = """
v = sorted(t)
foo(v)
"""
self.check(b, a)
b = """
v = foo(b)
v.sort()
foo(v)
"""
a = """
v = sorted(foo(b))
foo(v)
"""
self.check(b, a)
b = """
v = b.keys()
v.sort()
foo(v)
"""
a = """
v = sorted(b.keys())
foo(v)
"""
self.check(b, a)
b = """
v = foo(b) + d
v.sort()
foo(v)
"""
a = """
v = sorted(foo(b) + d)
foo(v)
"""
self.check(b, a)
b = """
while x:
v = t
v.sort()
foo(v)
"""
a = """
while x:
v = sorted(t)
foo(v)
"""
self.check(b, a)
b = """
v = t
# foo
v.sort()
foo(v)
"""
a = """
v = sorted(t)
# foo
foo(v)
"""
self.check(b, a)
b = r"""
v = t
v.sort()
foo(v)
"""
a = r"""
v = sorted(t)
foo(v)
"""
self.check(b, a)
def test_sort_unchanged(self):
s = """
v = list(t)
w.sort()
foo(w)
"""
self.unchanged(s)
s = """
v = list(t)
v.sort(u)
foo(v)
"""
self.unchanged(s)
class Test_basestring(FixerTestCase):
fixer = "basestring"
def test_basestring(self):
b = """isinstance(x, basestring)"""
a = """isinstance(x, str)"""
self.check(b, a)
class Test_buffer(FixerTestCase):
fixer = "buffer"
def test_buffer(self):
b = """x = buffer(y)"""
a = """x = memoryview(y)"""
self.check(b, a)
def test_slicing(self):
b = """buffer(y)[4:5]"""
a = """memoryview(y)[4:5]"""
self.check(b, a)
class Test_future(FixerTestCase):
fixer = "future"
def test_future(self):
b = """from __future__ import braces"""
a = """"""
self.check(b, a)
b = """# comment\nfrom __future__ import braces"""
a = """# comment\n"""
self.check(b, a)
b = """from __future__ import braces\n# comment"""
a = """\n# comment"""
self.check(b, a)
def test_run_order(self):
self.assert_runs_after('print')
class Test_itertools(FixerTestCase):
fixer = "itertools"
def checkall(self, before, after):
# Because we need to check with and without the itertools prefix
# and on each of the three functions, these loops make it all
# much easier
for i in ('itertools.', ''):
for f in ('map', 'filter', 'zip'):
b = before %(i+'i'+f)
a = after %(f)
self.check(b, a)
def test_0(self):
# A simple example -- test_1 covers exactly the same thing,
# but it's not quite as clear.
b = "itertools.izip(a, b)"
a = "zip(a, b)"
self.check(b, a)
def test_1(self):
b = """%s(f, a)"""
a = """%s(f, a)"""
self.checkall(b, a)
def test_qualified(self):
b = """itertools.ifilterfalse(a, b)"""
a = """itertools.filterfalse(a, b)"""
self.check(b, a)
b = """itertools.izip_longest(a, b)"""
a = """itertools.zip_longest(a, b)"""
self.check(b, a)
def test_2(self):
b = """ifilterfalse(a, b)"""
a = """filterfalse(a, b)"""
self.check(b, a)
b = """izip_longest(a, b)"""
a = """zip_longest(a, b)"""
self.check(b, a)
def test_space_1(self):
b = """ %s(f, a)"""
a = """ %s(f, a)"""
self.checkall(b, a)
def test_space_2(self):
b = """ itertools.ifilterfalse(a, b)"""
a = """ itertools.filterfalse(a, b)"""
self.check(b, a)
b = """ itertools.izip_longest(a, b)"""
a = """ itertools.zip_longest(a, b)"""
self.check(b, a)
def test_run_order(self):
self.assert_runs_after('map', 'zip', 'filter')
class Test_itertools_imports(FixerTestCase):
fixer = 'itertools_imports'
def test_reduced(self):
b = "from itertools import imap, izip, foo"
a = "from itertools import foo"
self.check(b, a)
b = "from itertools import bar, imap, izip, foo"
a = "from itertools import bar, foo"
self.check(b, a)
b = "from itertools import chain, imap, izip"
a = "from itertools import chain"
self.check(b, a)
def test_comments(self):
b = "#foo\nfrom itertools import imap, izip"
a = "#foo\n"
self.check(b, a)
def test_none(self):
b = "from itertools import imap, izip"
a = ""
self.check(b, a)
b = "from itertools import izip"
a = ""
self.check(b, a)
def test_import_as(self):
b = "from itertools import izip, bar as bang, imap"
a = "from itertools import bar as bang"
self.check(b, a)
b = "from itertools import izip as _zip, imap, bar"
a = "from itertools import bar"
self.check(b, a)
b = "from itertools import imap as _map"
a = ""
self.check(b, a)
b = "from itertools import imap as _map, izip as _zip"
a = ""
self.check(b, a)
s = "from itertools import bar as bang"
self.unchanged(s)
def test_ifilter_and_zip_longest(self):
for name in "filterfalse", "zip_longest":
b = "from itertools import i%s" % (name,)
a = "from itertools import %s" % (name,)
self.check(b, a)
b = "from itertools import imap, i%s, foo" % (name,)
a = "from itertools import %s, foo" % (name,)
self.check(b, a)
b = "from itertools import bar, i%s, foo" % (name,)
a = "from itertools import bar, %s, foo" % (name,)
self.check(b, a)
def test_import_star(self):
s = "from itertools import *"
self.unchanged(s)
def test_unchanged(self):
s = "from itertools import foo"
self.unchanged(s)
class Test_import(FixerTestCase):
fixer = "import"
def setUp(self):
super(Test_import, self).setUp()
# Need to replace fix_import's exists method
# so we can check that it's doing the right thing
self.files_checked = []
self.present_files = set()
self.always_exists = True
def fake_exists(name):
self.files_checked.append(name)
return self.always_exists or (name in self.present_files)
from lib2to3.fixes import fix_import
fix_import.exists = fake_exists
def tearDown(self):
from lib2to3.fixes import fix_import
fix_import.exists = os.path.exists
def check_both(self, b, a):
self.always_exists = True
super(Test_import, self).check(b, a)
self.always_exists = False
super(Test_import, self).unchanged(b)
def test_files_checked(self):
def p(path):
# Takes a unix path and returns a path with correct separators
return os.path.pathsep.join(path.split("/"))
self.always_exists = False
self.present_files = set(['__init__.py'])
expected_extensions = ('.py', os.path.sep, '.pyc', '.so', '.sl', '.pyd')
names_to_test = (p("/spam/eggs.py"), "ni.py", p("../../shrubbery.py"))
for name in names_to_test:
self.files_checked = []
self.filename = name
self.unchanged("import jam")
if os.path.dirname(name):
name = os.path.dirname(name) + '/jam'
else:
name = 'jam'
expected_checks = set(name + ext for ext in expected_extensions)
expected_checks.add("__init__.py")
self.assertEqual(set(self.files_checked), expected_checks)
def test_not_in_package(self):
s = "import bar"
self.always_exists = False
self.present_files = set(["bar.py"])
self.unchanged(s)
def test_with_absolute_import_enabled(self):
s = "from __future__ import absolute_import\nimport bar"
self.always_exists = False
self.present_files = set(["__init__.py", "bar.py"])
self.unchanged(s)
def test_in_package(self):
b = "import bar"
a = "from . import bar"
self.always_exists = False
self.present_files = set(["__init__.py", "bar.py"])
self.check(b, a)
def test_import_from_package(self):
b = "import bar"
a = "from . import bar"
self.always_exists = False
self.present_files = set(["__init__.py", "bar" + os.path.sep])
self.check(b, a)
def test_already_relative_import(self):
s = "from . import bar"
self.unchanged(s)
def test_comments_and_indent(self):
b = "import bar # Foo"
a = "from . import bar # Foo"
self.check(b, a)
def test_from(self):
b = "from foo import bar, baz"
a = "from .foo import bar, baz"
self.check_both(b, a)
b = "from foo import bar"
a = "from .foo import bar"
self.check_both(b, a)
b = "from foo import (bar, baz)"
a = "from .foo import (bar, baz)"
self.check_both(b, a)
def test_dotted_from(self):
b = "from green.eggs import ham"
a = "from .green.eggs import ham"
self.check_both(b, a)
def test_from_as(self):
b = "from green.eggs import ham as spam"
a = "from .green.eggs import ham as spam"
self.check_both(b, a)
def test_import(self):
b = "import foo"
a = "from . import foo"
self.check_both(b, a)
b = "import foo, bar"
a = "from . import foo, bar"
self.check_both(b, a)
b = "import foo, bar, x"
a = "from . import foo, bar, x"
self.check_both(b, a)
b = "import x, y, z"
a = "from . import x, y, z"
self.check_both(b, a)
def test_import_as(self):
b = "import foo as x"
a = "from . import foo as x"
self.check_both(b, a)
b = "import a as b, b as c, c as d"
a = "from . import a as b, b as c, c as d"
self.check_both(b, a)
def test_local_and_absolute(self):
self.always_exists = False
self.present_files = set(["foo.py", "__init__.py"])
s = "import foo, bar"
self.warns_unchanged(s, "absolute and local imports together")
def test_dotted_import(self):
b = "import foo.bar"
a = "from . import foo.bar"
self.check_both(b, a)
def test_dotted_import_as(self):
b = "import foo.bar as bang"
a = "from . import foo.bar as bang"
self.check_both(b, a)
def test_prefix(self):
b = """
# prefix
import foo.bar
"""
a = """
# prefix
from . import foo.bar
"""
self.check_both(b, a)
class Test_set_literal(FixerTestCase):
fixer = "set_literal"
def test_basic(self):
b = """set([1, 2, 3])"""
a = """{1, 2, 3}"""
self.check(b, a)
b = """set((1, 2, 3))"""
a = """{1, 2, 3}"""
self.check(b, a)
b = """set((1,))"""
a = """{1}"""
self.check(b, a)
b = """set([1])"""
self.check(b, a)
b = """set((a, b))"""
a = """{a, b}"""
self.check(b, a)
b = """set([a, b])"""
self.check(b, a)
b = """set((a*234, f(args=23)))"""
a = """{a*234, f(args=23)}"""
self.check(b, a)
b = """set([a*23, f(23)])"""
a = """{a*23, f(23)}"""
self.check(b, a)
b = """set([a-234**23])"""
a = """{a-234**23}"""
self.check(b, a)
def test_listcomps(self):
b = """set([x for x in y])"""
a = """{x for x in y}"""
self.check(b, a)
b = """set([x for x in y if x == m])"""
a = """{x for x in y if x == m}"""
self.check(b, a)
b = """set([x for x in y for a in b])"""
a = """{x for x in y for a in b}"""
self.check(b, a)
b = """set([f(x) - 23 for x in y])"""
a = """{f(x) - 23 for x in y}"""
self.check(b, a)
def test_whitespace(self):
b = """set( [1, 2])"""
a = """{1, 2}"""
self.check(b, a)
b = """set([1 , 2])"""
a = """{1 , 2}"""
self.check(b, a)
b = """set([ 1 ])"""
a = """{ 1 }"""
self.check(b, a)
b = """set( [1] )"""
a = """{1}"""
self.check(b, a)
b = """set([ 1, 2 ])"""
a = """{ 1, 2 }"""
self.check(b, a)
b = """set([x for x in y ])"""
a = """{x for x in y }"""
self.check(b, a)
b = """set(
[1, 2]
)
"""
a = """{1, 2}\n"""
self.check(b, a)
def test_comments(self):
b = """set((1, 2)) # Hi"""
a = """{1, 2} # Hi"""
self.check(b, a)
# This isn't optimal behavior, but the fixer is optional.
b = """
# Foo
set( # Bar
(1, 2)
)
"""
a = """
# Foo
{1, 2}
"""
self.check(b, a)
def test_unchanged(self):
s = """set()"""
self.unchanged(s)
s = """set(a)"""
self.unchanged(s)
s = """set(a, b, c)"""
self.unchanged(s)
# Don't transform generators because they might have to be lazy.
s = """set(x for x in y)"""
self.unchanged(s)
s = """set(x for x in y if z)"""
self.unchanged(s)
s = """set(a*823-23**2 + f(23))"""
self.unchanged(s)
class Test_sys_exc(FixerTestCase):
fixer = "sys_exc"
def test_0(self):
b = "sys.exc_type"
a = "sys.exc_info()[0]"
self.check(b, a)
def test_1(self):
b = "sys.exc_value"
a = "sys.exc_info()[1]"
self.check(b, a)
def test_2(self):
b = "sys.exc_traceback"
a = "sys.exc_info()[2]"
self.check(b, a)
def test_3(self):
b = "sys.exc_type # Foo"
a = "sys.exc_info()[0] # Foo"
self.check(b, a)
def test_4(self):
b = "sys. exc_type"
a = "sys. exc_info()[0]"
self.check(b, a)
def test_5(self):
b = "sys .exc_type"
a = "sys .exc_info()[0]"
self.check(b, a)
class Test_paren(FixerTestCase):
fixer = "paren"
def test_0(self):
b = """[i for i in 1, 2 ]"""
a = """[i for i in (1, 2) ]"""
self.check(b, a)
def test_1(self):
b = """[i for i in 1, 2, ]"""
a = """[i for i in (1, 2,) ]"""
self.check(b, a)
def test_2(self):
b = """[i for i in 1, 2 ]"""
a = """[i for i in (1, 2) ]"""
self.check(b, a)
def test_3(self):
b = """[i for i in 1, 2 if i]"""
a = """[i for i in (1, 2) if i]"""
self.check(b, a)
def test_4(self):
b = """[i for i in 1, 2 ]"""
a = """[i for i in (1, 2) ]"""
self.check(b, a)
def test_5(self):
b = """(i for i in 1, 2)"""
a = """(i for i in (1, 2))"""
self.check(b, a)
def test_6(self):
b = """(i for i in 1 ,2 if i)"""
a = """(i for i in (1 ,2) if i)"""
self.check(b, a)
def test_unchanged_0(self):
s = """[i for i in (1, 2)]"""
self.unchanged(s)
def test_unchanged_1(self):
s = """[i for i in foo()]"""
self.unchanged(s)
def test_unchanged_2(self):
s = """[i for i in (1, 2) if nothing]"""
self.unchanged(s)
def test_unchanged_3(self):
s = """(i for i in (1, 2))"""
self.unchanged(s)
def test_unchanged_4(self):
s = """[i for i in m]"""
self.unchanged(s)
class Test_metaclass(FixerTestCase):
fixer = 'metaclass'
def test_unchanged(self):
self.unchanged("class X(): pass")
self.unchanged("class X(object): pass")
self.unchanged("class X(object1, object2): pass")
self.unchanged("class X(object1, object2, object3): pass")
self.unchanged("class X(metaclass=Meta): pass")
self.unchanged("class X(b, arg=23, metclass=Meta): pass")
self.unchanged("class X(b, arg=23, metaclass=Meta, other=42): pass")
s = """
class X:
def __metaclass__(self): pass
"""
self.unchanged(s)
s = """
class X:
a[23] = 74
"""
self.unchanged(s)
def test_comments(self):
b = """
class X:
# hi
__metaclass__ = AppleMeta
"""
a = """
class X(metaclass=AppleMeta):
# hi
pass
"""
self.check(b, a)
b = """
class X:
__metaclass__ = Meta
# Bedtime!
"""
a = """
class X(metaclass=Meta):
pass
# Bedtime!
"""
self.check(b, a)
def test_meta(self):
# no-parent class, odd body
b = """
class X():
__metaclass__ = Q
pass
"""
a = """
class X(metaclass=Q):
pass
"""
self.check(b, a)
# one parent class, no body
b = """class X(object): __metaclass__ = Q"""
a = """class X(object, metaclass=Q): pass"""
self.check(b, a)
# one parent, simple body
b = """
class X(object):
__metaclass__ = Meta
bar = 7
"""
a = """
class X(object, metaclass=Meta):
bar = 7
"""
self.check(b, a)
b = """
class X:
__metaclass__ = Meta; x = 4; g = 23
"""
a = """
class X(metaclass=Meta):
x = 4; g = 23
"""
self.check(b, a)
# one parent, simple body, __metaclass__ last
b = """
class X(object):
bar = 7
__metaclass__ = Meta
"""
a = """
class X(object, metaclass=Meta):
bar = 7
"""
self.check(b, a)
# redefining __metaclass__
b = """
class X():
__metaclass__ = A
__metaclass__ = B
bar = 7
"""
a = """
class X(metaclass=B):
bar = 7
"""
self.check(b, a)
# multiple inheritance, simple body
b = """
class X(clsA, clsB):
__metaclass__ = Meta
bar = 7
"""
a = """
class X(clsA, clsB, metaclass=Meta):
bar = 7
"""
self.check(b, a)
# keywords in the class statement
b = """class m(a, arg=23): __metaclass__ = Meta"""
a = """class m(a, arg=23, metaclass=Meta): pass"""
self.check(b, a)
b = """
class X(expression(2 + 4)):
__metaclass__ = Meta
"""
a = """
class X(expression(2 + 4), metaclass=Meta):
pass
"""
self.check(b, a)
b = """
class X(expression(2 + 4), x**4):
__metaclass__ = Meta
"""
a = """
class X(expression(2 + 4), x**4, metaclass=Meta):
pass
"""
self.check(b, a)
b = """
class X:
__metaclass__ = Meta
save.py = 23
"""
a = """
class X(metaclass=Meta):
save.py = 23
"""
self.check(b, a)
class Test_getcwdu(FixerTestCase):
fixer = 'getcwdu'
def test_basic(self):
b = """os.getcwdu"""
a = """os.getcwd"""
self.check(b, a)
b = """os.getcwdu()"""
a = """os.getcwd()"""
self.check(b, a)
b = """meth = os.getcwdu"""
a = """meth = os.getcwd"""
self.check(b, a)
b = """os.getcwdu(args)"""
a = """os.getcwd(args)"""
self.check(b, a)
def test_comment(self):
b = """os.getcwdu() # Foo"""
a = """os.getcwd() # Foo"""
self.check(b, a)
def test_unchanged(self):
s = """os.getcwd()"""
self.unchanged(s)
s = """getcwdu()"""
self.unchanged(s)
s = """os.getcwdb()"""
self.unchanged(s)
def test_indentation(self):
b = """
if 1:
os.getcwdu()
"""
a = """
if 1:
os.getcwd()
"""
self.check(b, a)
def test_multilation(self):
b = """os .getcwdu()"""
a = """os .getcwd()"""
self.check(b, a)
b = """os. getcwdu"""
a = """os. getcwd"""
self.check(b, a)
b = """os.getcwdu ( )"""
a = """os.getcwd ( )"""
self.check(b, a)
class Test_operator(FixerTestCase):
fixer = "operator"
def test_operator_isCallable(self):
b = "operator.isCallable(x)"
a = "hasattr(x, '__call__')"
self.check(b, a)
def test_operator_sequenceIncludes(self):
b = "operator.sequenceIncludes(x, y)"
a = "operator.contains(x, y)"
self.check(b, a)
b = "operator .sequenceIncludes(x, y)"
a = "operator .contains(x, y)"
self.check(b, a)
b = "operator. sequenceIncludes(x, y)"
a = "operator. contains(x, y)"
self.check(b, a)
def test_operator_isSequenceType(self):
b = "operator.isSequenceType(x)"
a = "import collections\nisinstance(x, collections.Sequence)"
self.check(b, a)
def test_operator_isMappingType(self):
b = "operator.isMappingType(x)"
a = "import collections\nisinstance(x, collections.Mapping)"
self.check(b, a)
def test_operator_isNumberType(self):
b = "operator.isNumberType(x)"
a = "import numbers\nisinstance(x, numbers.Number)"
self.check(b, a)
def test_operator_repeat(self):
b = "operator.repeat(x, n)"
a = "operator.mul(x, n)"
self.check(b, a)
b = "operator .repeat(x, n)"
a = "operator .mul(x, n)"
self.check(b, a)
b = "operator. repeat(x, n)"
a = "operator. mul(x, n)"
self.check(b, a)
def test_operator_irepeat(self):
b = "operator.irepeat(x, n)"
a = "operator.imul(x, n)"
self.check(b, a)
b = "operator .irepeat(x, n)"
a = "operator .imul(x, n)"
self.check(b, a)
b = "operator. irepeat(x, n)"
a = "operator. imul(x, n)"
self.check(b, a)
def test_bare_isCallable(self):
s = "isCallable(x)"
t = "You should use 'hasattr(x, '__call__')' here."
self.warns_unchanged(s, t)
def test_bare_sequenceIncludes(self):
s = "sequenceIncludes(x, y)"
t = "You should use 'operator.contains(x, y)' here."
self.warns_unchanged(s, t)
def test_bare_operator_isSequenceType(self):
s = "isSequenceType(z)"
t = "You should use 'isinstance(z, collections.Sequence)' here."
self.warns_unchanged(s, t)
def test_bare_operator_isMappingType(self):
s = "isMappingType(x)"
t = "You should use 'isinstance(x, collections.Mapping)' here."
self.warns_unchanged(s, t)
def test_bare_operator_isNumberType(self):
s = "isNumberType(y)"
t = "You should use 'isinstance(y, numbers.Number)' here."
self.warns_unchanged(s, t)
def test_bare_operator_repeat(self):
s = "repeat(x, n)"
t = "You should use 'operator.mul(x, n)' here."
self.warns_unchanged(s, t)
def test_bare_operator_irepeat(self):
s = "irepeat(y, 187)"
t = "You should use 'operator.imul(y, 187)' here."
self.warns_unchanged(s, t)
class Test_exitfunc(FixerTestCase):
fixer = "exitfunc"
def test_simple(self):
b = """
import sys
sys.exitfunc = my_atexit
"""
a = """
import sys
import atexit
atexit.register(my_atexit)
"""
self.check(b, a)
def test_names_import(self):
b = """
import sys, crumbs
sys.exitfunc = my_func
"""
a = """
import sys, crumbs, atexit
atexit.register(my_func)
"""
self.check(b, a)
def test_complex_expression(self):
b = """
import sys
sys.exitfunc = do(d)/a()+complex(f=23, g=23)*expression
"""
a = """
import sys
import atexit
atexit.register(do(d)/a()+complex(f=23, g=23)*expression)
"""
self.check(b, a)
def test_comments(self):
b = """
import sys # Foo
sys.exitfunc = f # Blah
"""
a = """
import sys
import atexit # Foo
atexit.register(f) # Blah
"""
self.check(b, a)
b = """
import apples, sys, crumbs, larry # Pleasant comments
sys.exitfunc = func
"""
a = """
import apples, sys, crumbs, larry, atexit # Pleasant comments
atexit.register(func)
"""
self.check(b, a)
def test_in_a_function(self):
b = """
import sys
def f():
sys.exitfunc = func
"""
a = """
import sys
import atexit
def f():
atexit.register(func)
"""
self.check(b, a)
def test_no_sys_import(self):
b = """sys.exitfunc = f"""
a = """atexit.register(f)"""
msg = ("Can't find sys import; Please add an atexit import at the "
"top of your file.")
self.warns(b, a, msg)
def test_unchanged(self):
s = """f(sys.exitfunc)"""
self.unchanged(s)
|
mit
|
[
624,
1379,
5241,
367,
314,
24739,
4621,
408,
199,
199,
3,
2018,
8925,
199,
646,
747,
199,
646,
2882,
199,
504,
7975,
492,
6036,
199,
504,
4182,
492,
1242,
7416,
199,
199,
3,
10111,
8925,
199,
504,
1973,
18,
475,
19,
492,
1134,
1679,
12,
23353,
12,
24200,
12,
24739,
63,
1974,
199,
504,
1973,
18,
475,
19,
14,
2219,
492,
2291,
421,
199,
533,
14811,
281,
1746,
8,
4058,
14,
1746,
304,
339,
327,
5439,
511,
5560,
883,
5516,
642,
1021,
436,
3350,
298,
25973,
63,
4600,
2,
543,
272,
327,
3932,
5705,
14,
272,
347,
3613,
8,
277,
12,
5325,
63,
513,
29,
403,
12,
24739,
63,
4600,
628,
773,
18,
475,
19,
401,
1511,
29,
403,
304,
267,
340,
5325,
63,
513,
365,
488,
26,
288,
5325,
63,
513,
275,
359,
277,
14,
25973,
61,
267,
291,
14,
264,
4778,
275,
2291,
14,
362,
63,
264,
7783,
720,
82,
8,
25973,
63,
4600,
12,
5325,
63,
513,
12,
1511,
9,
267,
291,
14,
25973,
63,
793,
275,
942,
267,
291,
14,
1501,
275,
399,
17030,
875,
4335,
398,
367,
24739,
315,
6036,
8,
277,
14,
264,
4778,
14,
657,
63,
1648,
12,
2574,
291,
14,
264,
4778,
14,
1932,
63,
1648,
304,
288,
24739,
14,
793,
275,
291,
14,
25973,
63,
793,
339,
347,
485,
1074,
8,
277,
12,
2544,
12,
2410,
304,
267,
2544,
275,
2291,
14,
264,
908,
8,
5182,
9,
267,
2410,
275,
2291,
14,
264,
908,
8,
4399,
9,
267,
3123,
275,
291,
14,
264,
4778,
14,
264,
4778,
63,
875,
8,
5182,
12,
291,
14,
1501,
9,
267,
291,
14,
629,
8,
4399,
12,
2649,
8,
2350,
430,
267,
372,
3123,
339,
347,
1104,
8,
277,
12,
2544,
12,
2410,
12,
3686,
63,
5451,
29,
797,
304,
267,
3123,
275,
291,
423,
1074,
8,
5182,
12,
2410,
9,
267,
291,
14,
1815,
8,
2350,
14,
10274,
63,
2489,
9,
267,
340,
440,
3686,
63,
5451,
26,
288,
291,
14,
629,
8,
277,
14,
25973,
63,
793,
12,
3073,
339,
347,
3429,
561,
8,
277,
12,
2544,
12,
2410,
12,
1245,
12,
14874,
29,
797,
304,
267,
3123,
275,
291,
423,
1074,
8,
5182,
12,
2410,
9,
267,
291,
14,
1815,
8,
1188,
315,
10587,
904,
8,
277,
14,
25973,
63,
793,
430,
267,
340,
440,
14874,
26,
288,
291,
14,
1815,
8,
2350,
14,
10274,
63,
2489,
9,
339,
347,
3429,
561,
63,
16914,
8,
277,
12,
2544,
12,
1245,
304,
267,
291,
14,
19811,
8,
5182,
12,
2544,
12,
1245,
12,
14874,
29,
549,
9,
339,
347,
14874,
8,
277,
12,
2544,
12,
3686,
63,
5451,
29,
797,
304,
267,
291,
423,
1074,
8,
5182,
12,
2544,
9,
267,
340,
440,
3686,
63,
5451,
26,
288,
291,
14,
629,
8,
277,
14,
25973,
63,
793,
12,
3073,
339,
347,
702,
63,
10802,
63,
4399,
8,
277,
12,
627,
1247,
304,
267,
25079,
275,
359,
277,
14,
25973,
61,
267,
25079,
14,
2880,
8,
1247,
9,
267,
519,
275,
2291,
14,
362,
63,
264,
7783,
720,
82,
480,
773,
18,
475,
19,
401,
25079,
9,
267,
334,
657,
12,
2963,
9,
275,
519,
14,
362,
63,
970,
1192,
342,
267,
302,
275,
298,
970,
12172,
435,
291,
14,
25973,
267,
340,
2963,
436,
2963,
1988,
17,
17979,
533,
4914,
578,
4343,
4130,
8,
78,
304,
288,
327,
2136,
3984,
314,
2061,
24739,
370,
1255,
288,
372,
267,
340,
876,
436,
876,
1988,
17,
17979,
533,
4914,
578,
4343,
4130,
8,
78,
9,
436,
440,
2963,
26,
288,
327,
2136,
3984,
314,
2061,
315,
876,
436,
2963,
365,
2701,
288,
372,
267,
291,
14,
1633,
480,
11985,
281,
1255,
1865,
4366,
83,
9,
365,
8927,
27,
450,
83,
1077,
506,
2061,
2122,
60,
2049,
2818,
401,
3680,
904,
779,
88,
855,
533,
4914,
578,
363,
367,
671,
315,
334,
657,
11,
1932,
16636,
302,
430,
199,
199,
533,
1379,
63,
685,
8,
11985,
281,
1746,
304,
272,
24739,
275,
298,
685,
2,
339,
347,
511,
63,
4316,
8,
277,
304,
267,
330,
275,
408,
692,
671,
20941,
612,
26,
288,
986,
624,
398,
282,
275,
408,
692,
671,
1137,
612,
26,
288,
986,
624,
267,
291,
14,
1074,
8,
66,
12,
282,
9,
339,
347,
511,
63,
889,
63,
10749,
8,
277,
304,
267,
330,
275,
408,
692,
671,
16137,
89,
26,
288,
986,
624,
398,
282,
275,
408,
692,
671,
1111,
89,
26,
288,
986,
624,
267,
291,
14,
1074,
8,
66,
12,
282,
9,
339,
347,
511,
63,
4429,
379,
8,
277,
304,
267,
330,
275,
408,
692,
671,
16137,
89,
16137,
90,
26,
288,
986,
624,
398,
282,
275,
408,
692,
671,
1111,
89,
1111,
90,
26,
288,
986,
624,
267,
291,
14,
1074,
8,
66,
12,
282,
9,
199,
199,
533,
1379,
63,
1989,
63,
498,
8,
11985,
281,
1746,
304,
272,
24739,
275,
298,
1989,
63,
498,
2,
339,
347,
511,
63,
17,
8,
277,
304,
267,
330,
275,
408,
88,
275,
366,
14,
1989,
63,
498,
480,
88,
531,
503,
366,
14,
1989,
63,
498,
480,
89,
531,
624,
267,
282,
275,
408,
88,
275,
298,
88,
2,
315,
366,
503,
298,
89,
2,
315,
366,
624,
267,
291,
14,
1074,
8,
66,
12,
282,
9,
339,
347,
511,
63,
18,
8,
277,
304,
267,
330,
275,
408,
88,
275,
282,
14,
66,
14,
67,
14,
68,
14,
1989,
63,
498,
480,
88,
531,
1011,
650,
624,
267,
282,
275,
408,
88,
275,
1689,
88,
2,
315,
282,
14,
66,
14,
67,
14,
68,
9,
1011,
650,
624,
267,
291,
14,
1074,
8,
66,
12,
282,
9,
339,
347,
511,
63,
19,
8,
277,
304,
267,
330,
275,
408,
88,
275,
282,
14,
66,
14,
1989,
63,
498,
8,
17,
435,
499,
2843,
2722,
4533,
624,
267,
282,
275,
408,
88,
275,
334,
17,
435,
499,
315,
282,
14,
66,
2843,
2722,
4533,
624,
267,
291,
14,
1074,
8,
66,
12,
282,
9,
339,
347,
511,
63,
20,
8,
277,
304,
267,
330,
275,
408,
88,
275,
282,
14,
66,
14,
1989,
63,
498,
8,
17,
435,
499,
2843,
2722,
4533,
1011,
446,
19,
1011,
841,
624,
267,
282,
275,
408
] |
[
1379,
5241,
367,
314,
24739,
4621,
408,
199,
199,
3,
2018,
8925,
199,
646,
747,
199,
646,
2882,
199,
504,
7975,
492,
6036,
199,
504,
4182,
492,
1242,
7416,
199,
199,
3,
10111,
8925,
199,
504,
1973,
18,
475,
19,
492,
1134,
1679,
12,
23353,
12,
24200,
12,
24739,
63,
1974,
199,
504,
1973,
18,
475,
19,
14,
2219,
492,
2291,
421,
199,
533,
14811,
281,
1746,
8,
4058,
14,
1746,
304,
339,
327,
5439,
511,
5560,
883,
5516,
642,
1021,
436,
3350,
298,
25973,
63,
4600,
2,
543,
272,
327,
3932,
5705,
14,
272,
347,
3613,
8,
277,
12,
5325,
63,
513,
29,
403,
12,
24739,
63,
4600,
628,
773,
18,
475,
19,
401,
1511,
29,
403,
304,
267,
340,
5325,
63,
513,
365,
488,
26,
288,
5325,
63,
513,
275,
359,
277,
14,
25973,
61,
267,
291,
14,
264,
4778,
275,
2291,
14,
362,
63,
264,
7783,
720,
82,
8,
25973,
63,
4600,
12,
5325,
63,
513,
12,
1511,
9,
267,
291,
14,
25973,
63,
793,
275,
942,
267,
291,
14,
1501,
275,
399,
17030,
875,
4335,
398,
367,
24739,
315,
6036,
8,
277,
14,
264,
4778,
14,
657,
63,
1648,
12,
2574,
291,
14,
264,
4778,
14,
1932,
63,
1648,
304,
288,
24739,
14,
793,
275,
291,
14,
25973,
63,
793,
339,
347,
485,
1074,
8,
277,
12,
2544,
12,
2410,
304,
267,
2544,
275,
2291,
14,
264,
908,
8,
5182,
9,
267,
2410,
275,
2291,
14,
264,
908,
8,
4399,
9,
267,
3123,
275,
291,
14,
264,
4778,
14,
264,
4778,
63,
875,
8,
5182,
12,
291,
14,
1501,
9,
267,
291,
14,
629,
8,
4399,
12,
2649,
8,
2350,
430,
267,
372,
3123,
339,
347,
1104,
8,
277,
12,
2544,
12,
2410,
12,
3686,
63,
5451,
29,
797,
304,
267,
3123,
275,
291,
423,
1074,
8,
5182,
12,
2410,
9,
267,
291,
14,
1815,
8,
2350,
14,
10274,
63,
2489,
9,
267,
340,
440,
3686,
63,
5451,
26,
288,
291,
14,
629,
8,
277,
14,
25973,
63,
793,
12,
3073,
339,
347,
3429,
561,
8,
277,
12,
2544,
12,
2410,
12,
1245,
12,
14874,
29,
797,
304,
267,
3123,
275,
291,
423,
1074,
8,
5182,
12,
2410,
9,
267,
291,
14,
1815,
8,
1188,
315,
10587,
904,
8,
277,
14,
25973,
63,
793,
430,
267,
340,
440,
14874,
26,
288,
291,
14,
1815,
8,
2350,
14,
10274,
63,
2489,
9,
339,
347,
3429,
561,
63,
16914,
8,
277,
12,
2544,
12,
1245,
304,
267,
291,
14,
19811,
8,
5182,
12,
2544,
12,
1245,
12,
14874,
29,
549,
9,
339,
347,
14874,
8,
277,
12,
2544,
12,
3686,
63,
5451,
29,
797,
304,
267,
291,
423,
1074,
8,
5182,
12,
2544,
9,
267,
340,
440,
3686,
63,
5451,
26,
288,
291,
14,
629,
8,
277,
14,
25973,
63,
793,
12,
3073,
339,
347,
702,
63,
10802,
63,
4399,
8,
277,
12,
627,
1247,
304,
267,
25079,
275,
359,
277,
14,
25973,
61,
267,
25079,
14,
2880,
8,
1247,
9,
267,
519,
275,
2291,
14,
362,
63,
264,
7783,
720,
82,
480,
773,
18,
475,
19,
401,
25079,
9,
267,
334,
657,
12,
2963,
9,
275,
519,
14,
362,
63,
970,
1192,
342,
267,
302,
275,
298,
970,
12172,
435,
291,
14,
25973,
267,
340,
2963,
436,
2963,
1988,
17,
17979,
533,
4914,
578,
4343,
4130,
8,
78,
304,
288,
327,
2136,
3984,
314,
2061,
24739,
370,
1255,
288,
372,
267,
340,
876,
436,
876,
1988,
17,
17979,
533,
4914,
578,
4343,
4130,
8,
78,
9,
436,
440,
2963,
26,
288,
327,
2136,
3984,
314,
2061,
315,
876,
436,
2963,
365,
2701,
288,
372,
267,
291,
14,
1633,
480,
11985,
281,
1255,
1865,
4366,
83,
9,
365,
8927,
27,
450,
83,
1077,
506,
2061,
2122,
60,
2049,
2818,
401,
3680,
904,
779,
88,
855,
533,
4914,
578,
363,
367,
671,
315,
334,
657,
11,
1932,
16636,
302,
430,
199,
199,
533,
1379,
63,
685,
8,
11985,
281,
1746,
304,
272,
24739,
275,
298,
685,
2,
339,
347,
511,
63,
4316,
8,
277,
304,
267,
330,
275,
408,
692,
671,
20941,
612,
26,
288,
986,
624,
398,
282,
275,
408,
692,
671,
1137,
612,
26,
288,
986,
624,
267,
291,
14,
1074,
8,
66,
12,
282,
9,
339,
347,
511,
63,
889,
63,
10749,
8,
277,
304,
267,
330,
275,
408,
692,
671,
16137,
89,
26,
288,
986,
624,
398,
282,
275,
408,
692,
671,
1111,
89,
26,
288,
986,
624,
267,
291,
14,
1074,
8,
66,
12,
282,
9,
339,
347,
511,
63,
4429,
379,
8,
277,
304,
267,
330,
275,
408,
692,
671,
16137,
89,
16137,
90,
26,
288,
986,
624,
398,
282,
275,
408,
692,
671,
1111,
89,
1111,
90,
26,
288,
986,
624,
267,
291,
14,
1074,
8,
66,
12,
282,
9,
199,
199,
533,
1379,
63,
1989,
63,
498,
8,
11985,
281,
1746,
304,
272,
24739,
275,
298,
1989,
63,
498,
2,
339,
347,
511,
63,
17,
8,
277,
304,
267,
330,
275,
408,
88,
275,
366,
14,
1989,
63,
498,
480,
88,
531,
503,
366,
14,
1989,
63,
498,
480,
89,
531,
624,
267,
282,
275,
408,
88,
275,
298,
88,
2,
315,
366,
503,
298,
89,
2,
315,
366,
624,
267,
291,
14,
1074,
8,
66,
12,
282,
9,
339,
347,
511,
63,
18,
8,
277,
304,
267,
330,
275,
408,
88,
275,
282,
14,
66,
14,
67,
14,
68,
14,
1989,
63,
498,
480,
88,
531,
1011,
650,
624,
267,
282,
275,
408,
88,
275,
1689,
88,
2,
315,
282,
14,
66,
14,
67,
14,
68,
9,
1011,
650,
624,
267,
291,
14,
1074,
8,
66,
12,
282,
9,
339,
347,
511,
63,
19,
8,
277,
304,
267,
330,
275,
408,
88,
275,
282,
14,
66,
14,
1989,
63,
498,
8,
17,
435,
499,
2843,
2722,
4533,
624,
267,
282,
275,
408,
88,
275,
334,
17,
435,
499,
315,
282,
14,
66,
2843,
2722,
4533,
624,
267,
291,
14,
1074,
8,
66,
12,
282,
9,
339,
347,
511,
63,
20,
8,
277,
304,
267,
330,
275,
408,
88,
275,
282,
14,
66,
14,
1989,
63,
498,
8,
17,
435,
499,
2843,
2722,
4533,
1011,
446,
19,
1011,
841,
624,
267,
282,
275,
408,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
40223247/2015test2
|
static/Brython3.1.1-20150328-091302/Lib/urllib/parse.py
|
735
|
35170
|
"""Parse (absolute and relative) URLs.
urlparse module is based upon the following RFC specifications.
RFC 3986 (STD66): "Uniform Resource Identifiers" by T. Berners-Lee, R. Fielding
and L. Masinter, January 2005.
RFC 2732 : "Format for Literal IPv6 Addresses in URL's by R.Hinden, B.Carpenter
and L.Masinter, December 1999.
RFC 2396: "Uniform Resource Identifiers (URI)": Generic Syntax by T.
Berners-Lee, R. Fielding, and L. Masinter, August 1998.
RFC 2368: "The mailto URL scheme", by P.Hoffman , L Masinter, J. Zawinski, July 1998.
RFC 1808: "Relative Uniform Resource Locators", by R. Fielding, UC Irvine, June
1995.
RFC 1738: "Uniform Resource Locators (URL)" by T. Berners-Lee, L. Masinter, M.
McCahill, December 1994
RFC 3986 is considered the current standard and any future changes to
urlparse module should conform with it. The urlparse module is
currently not entirely compliant with this RFC due to defacto
scenarios for parsing, and for backward compatibility purposes, some
parsing quirks from older RFCs are retained. The testcases in
test_urlparse.py provides a good indicator of parsing behavior.
"""
import re
import sys
import collections
__all__ = ["urlparse", "urlunparse", "urljoin", "urldefrag",
"urlsplit", "urlunsplit", "urlencode", "parse_qs",
"parse_qsl", "quote", "quote_plus", "quote_from_bytes",
"unquote", "unquote_plus", "unquote_to_bytes"]
# A classification of schemes ('' means apply by default)
uses_relative = ['ftp', 'http', 'gopher', 'nntp', 'imap',
'wais', 'file', 'https', 'shttp', 'mms',
'prospero', 'rtsp', 'rtspu', '', 'sftp',
'svn', 'svn+ssh']
uses_netloc = ['ftp', 'http', 'gopher', 'nntp', 'telnet',
'imap', 'wais', 'file', 'mms', 'https', 'shttp',
'snews', 'prospero', 'rtsp', 'rtspu', 'rsync', '',
'svn', 'svn+ssh', 'sftp', 'nfs', 'git', 'git+ssh']
uses_params = ['ftp', 'hdl', 'prospero', 'http', 'imap',
'https', 'shttp', 'rtsp', 'rtspu', 'sip', 'sips',
'mms', '', 'sftp', 'tel']
# These are not actually used anymore, but should stay for backwards
# compatibility. (They are undocumented, but have a public-looking name.)
non_hierarchical = ['gopher', 'hdl', 'mailto', 'news',
'telnet', 'wais', 'imap', 'snews', 'sip', 'sips']
uses_query = ['http', 'wais', 'imap', 'https', 'shttp', 'mms',
'gopher', 'rtsp', 'rtspu', 'sip', 'sips', '']
uses_fragment = ['ftp', 'hdl', 'http', 'gopher', 'news',
'nntp', 'wais', 'https', 'shttp', 'snews',
'file', 'prospero', '']
# Characters valid in scheme names
scheme_chars = ('abcdefghijklmnopqrstuvwxyz'
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
'0123456789'
'+-.')
# XXX: Consider replacing with functools.lru_cache
MAX_CACHE_SIZE = 20
_parse_cache = {}
def clear_cache():
"""Clear the parse cache and the quoters cache."""
_parse_cache.clear()
_safe_quoters.clear()
# Helpers for bytes handling
# For 3.2, we deliberately require applications that
# handle improperly quoted URLs to do their own
# decoding and encoding. If valid use cases are
# presented, we may relax this by using latin-1
# decoding internally for 3.3
_implicit_encoding = 'ascii'
_implicit_errors = 'strict'
def _noop(obj):
return obj
def _encode_result(obj, encoding=_implicit_encoding,
errors=_implicit_errors):
return obj.encode(encoding, errors)
def _decode_args(args, encoding=_implicit_encoding,
errors=_implicit_errors):
return tuple(x.decode(encoding, errors) if x else '' for x in args)
def _coerce_args(*args):
# Invokes decode if necessary to create str args
# and returns the coerced inputs along with
# an appropriate result coercion function
# - noop for str inputs
# - encoding function otherwise
str_input = isinstance(args[0], str)
for arg in args[1:]:
# We special-case the empty string to support the
# "scheme=''" default argument to some functions
if arg and isinstance(arg, str) != str_input:
raise TypeError("Cannot mix str and non-str arguments")
if str_input:
return args + (_noop,)
return _decode_args(args) + (_encode_result,)
# Result objects are more helpful than simple tuples
class _ResultMixinStr(object):
"""Standard approach to encoding parsed results from str to bytes"""
__slots__ = ()
def encode(self, encoding='ascii', errors='strict'):
return self._encoded_counterpart(*(x.encode(encoding, errors) for x in self))
class _ResultMixinBytes(object):
"""Standard approach to decoding parsed results from bytes to str"""
__slots__ = ()
def decode(self, encoding='ascii', errors='strict'):
return self._decoded_counterpart(*(x.decode(encoding, errors) for x in self))
class _NetlocResultMixinBase(object):
"""Shared methods for the parsed result objects containing a netloc element"""
__slots__ = ()
@property
def username(self):
return self._userinfo[0]
@property
def password(self):
return self._userinfo[1]
@property
def hostname(self):
hostname = self._hostinfo[0]
if not hostname:
hostname = None
elif hostname is not None:
hostname = hostname.lower()
return hostname
@property
def port(self):
port = self._hostinfo[1]
if port is not None:
port = int(port, 10)
# Return None on an illegal port
if not ( 0 <= port <= 65535):
return None
return port
class _NetlocResultMixinStr(_NetlocResultMixinBase, _ResultMixinStr):
__slots__ = ()
@property
def _userinfo(self):
netloc = self.netloc
userinfo, have_info, hostinfo = netloc.rpartition('@')
if have_info:
username, have_password, password = userinfo.partition(':')
if not have_password:
password = None
else:
username = password = None
return username, password
@property
def _hostinfo(self):
netloc = self.netloc
_, _, hostinfo = netloc.rpartition('@')
_, have_open_br, bracketed = hostinfo.partition('[')
if have_open_br:
hostname, _, port = bracketed.partition(']')
_, have_port, port = port.partition(':')
else:
hostname, have_port, port = hostinfo.partition(':')
if not have_port:
port = None
return hostname, port
class _NetlocResultMixinBytes(_NetlocResultMixinBase, _ResultMixinBytes):
__slots__ = ()
@property
def _userinfo(self):
netloc = self.netloc
userinfo, have_info, hostinfo = netloc.rpartition(b'@')
if have_info:
username, have_password, password = userinfo.partition(b':')
if not have_password:
password = None
else:
username = password = None
return username, password
@property
def _hostinfo(self):
netloc = self.netloc
_, _, hostinfo = netloc.rpartition(b'@')
_, have_open_br, bracketed = hostinfo.partition(b'[')
if have_open_br:
hostname, _, port = bracketed.partition(b']')
_, have_port, port = port.partition(b':')
else:
hostname, have_port, port = hostinfo.partition(b':')
if not have_port:
port = None
return hostname, port
from collections import namedtuple
_DefragResultBase = namedtuple('DefragResult', 'url fragment')
_SplitResultBase = namedtuple('SplitResult', 'scheme netloc path query fragment')
_ParseResultBase = namedtuple('ParseResult', 'scheme netloc path params query fragment')
# For backwards compatibility, alias _NetlocResultMixinStr
# ResultBase is no longer part of the documented API, but it is
# retained since deprecating it isn't worth the hassle
ResultBase = _NetlocResultMixinStr
# Structured result objects for string data
class DefragResult(_DefragResultBase, _ResultMixinStr):
__slots__ = ()
def geturl(self):
if self.fragment:
return self.url + '#' + self.fragment
else:
return self.url
class SplitResult(_SplitResultBase, _NetlocResultMixinStr):
__slots__ = ()
def geturl(self):
return urlunsplit(self)
class ParseResult(_ParseResultBase, _NetlocResultMixinStr):
__slots__ = ()
def geturl(self):
return urlunparse(self)
# Structured result objects for bytes data
class DefragResultBytes(_DefragResultBase, _ResultMixinBytes):
__slots__ = ()
def geturl(self):
if self.fragment:
return self.url + b'#' + self.fragment
else:
return self.url
class SplitResultBytes(_SplitResultBase, _NetlocResultMixinBytes):
__slots__ = ()
def geturl(self):
return urlunsplit(self)
class ParseResultBytes(_ParseResultBase, _NetlocResultMixinBytes):
__slots__ = ()
def geturl(self):
return urlunparse(self)
# Set up the encode/decode result pairs
def _fix_result_transcoding():
_result_pairs = (
(DefragResult, DefragResultBytes),
(SplitResult, SplitResultBytes),
(ParseResult, ParseResultBytes),
)
for _decoded, _encoded in _result_pairs:
_decoded._encoded_counterpart = _encoded
_encoded._decoded_counterpart = _decoded
_fix_result_transcoding()
del _fix_result_transcoding
def urlparse(url, scheme='', allow_fragments=True):
"""Parse a URL into 6 components:
<scheme>://<netloc>/<path>;<params>?<query>#<fragment>
Return a 6-tuple: (scheme, netloc, path, params, query, fragment).
Note that we don't break the components up in smaller bits
(e.g. netloc is a single string) and we don't expand % escapes."""
url, scheme, _coerce_result = _coerce_args(url, scheme)
splitresult = urlsplit(url, scheme, allow_fragments)
scheme, netloc, url, query, fragment = splitresult
if scheme in uses_params and ';' in url:
url, params = _splitparams(url)
else:
params = ''
result = ParseResult(scheme, netloc, url, params, query, fragment)
return _coerce_result(result)
def _splitparams(url):
if '/' in url:
i = url.find(';', url.rfind('/'))
if i < 0:
return url, ''
else:
i = url.find(';')
return url[:i], url[i+1:]
def _splitnetloc(url, start=0):
delim = len(url) # position of end of domain part of url, default is end
for c in '/?#': # look for delimiters; the order is NOT important
wdelim = url.find(c, start) # find first of this delim
if wdelim >= 0: # if found
delim = min(delim, wdelim) # use earliest delim position
return url[start:delim], url[delim:] # return (domain, rest)
def urlsplit(url, scheme='', allow_fragments=True):
"""Parse a URL into 5 components:
<scheme>://<netloc>/<path>?<query>#<fragment>
Return a 5-tuple: (scheme, netloc, path, query, fragment).
Note that we don't break the components up in smaller bits
(e.g. netloc is a single string) and we don't expand % escapes."""
url, scheme, _coerce_result = _coerce_args(url, scheme)
allow_fragments = bool(allow_fragments)
key = url, scheme, allow_fragments, type(url), type(scheme)
cached = _parse_cache.get(key, None)
if cached:
return _coerce_result(cached)
if len(_parse_cache) >= MAX_CACHE_SIZE: # avoid runaway growth
clear_cache()
netloc = query = fragment = ''
i = url.find(':')
if i > 0:
if url[:i] == 'http': # optimize the common case
scheme = url[:i].lower()
url = url[i+1:]
if url[:2] == '//':
netloc, url = _splitnetloc(url, 2)
if (('[' in netloc and ']' not in netloc) or
(']' in netloc and '[' not in netloc)):
raise ValueError("Invalid IPv6 URL")
if allow_fragments and '#' in url:
url, fragment = url.split('#', 1)
if '?' in url:
url, query = url.split('?', 1)
v = SplitResult(scheme, netloc, url, query, fragment)
_parse_cache[key] = v
return _coerce_result(v)
for c in url[:i]:
if c not in scheme_chars:
break
else:
# make sure "url" is not actually a port number (in which case
# "scheme" is really part of the path)
rest = url[i+1:]
if not rest or any(c not in '0123456789' for c in rest):
# not a port number
scheme, url = url[:i].lower(), rest
if url[:2] == '//':
netloc, url = _splitnetloc(url, 2)
if (('[' in netloc and ']' not in netloc) or
(']' in netloc and '[' not in netloc)):
raise ValueError("Invalid IPv6 URL")
if allow_fragments and '#' in url:
url, fragment = url.split('#', 1)
if '?' in url:
url, query = url.split('?', 1)
v = SplitResult(scheme, netloc, url, query, fragment)
_parse_cache[key] = v
return _coerce_result(v)
def urlunparse(components):
"""Put a parsed URL back together again. This may result in a
slightly different, but equivalent URL, if the URL that was parsed
originally had redundant delimiters, e.g. a ? with an empty query
(the draft states that these are equivalent)."""
scheme, netloc, url, params, query, fragment, _coerce_result = (
_coerce_args(*components))
if params:
url = "%s;%s" % (url, params)
return _coerce_result(urlunsplit((scheme, netloc, url, query, fragment)))
def urlunsplit(components):
"""Combine the elements of a tuple as returned by urlsplit() into a
complete URL as a string. The data argument can be any five-item iterable.
This may result in a slightly different, but equivalent URL, if the URL that
was parsed originally had unnecessary delimiters (for example, a ? with an
empty query; the RFC states that these are equivalent)."""
scheme, netloc, url, query, fragment, _coerce_result = (
_coerce_args(*components))
if netloc or (scheme and scheme in uses_netloc and url[:2] != '//'):
if url and url[:1] != '/': url = '/' + url
url = '//' + (netloc or '') + url
if scheme:
url = scheme + ':' + url
if query:
url = url + '?' + query
if fragment:
url = url + '#' + fragment
return _coerce_result(url)
def urljoin(base, url, allow_fragments=True):
"""Join a base URL and a possibly relative URL to form an absolute
interpretation of the latter."""
if not base:
return url
if not url:
return base
base, url, _coerce_result = _coerce_args(base, url)
bscheme, bnetloc, bpath, bparams, bquery, bfragment = \
urlparse(base, '', allow_fragments)
scheme, netloc, path, params, query, fragment = \
urlparse(url, bscheme, allow_fragments)
if scheme != bscheme or scheme not in uses_relative:
return _coerce_result(url)
if scheme in uses_netloc:
if netloc:
return _coerce_result(urlunparse((scheme, netloc, path,
params, query, fragment)))
netloc = bnetloc
if path[:1] == '/':
return _coerce_result(urlunparse((scheme, netloc, path,
params, query, fragment)))
if not path and not params:
path = bpath
params = bparams
if not query:
query = bquery
return _coerce_result(urlunparse((scheme, netloc, path,
params, query, fragment)))
segments = bpath.split('/')[:-1] + path.split('/')
# XXX The stuff below is bogus in various ways...
if segments[-1] == '.':
segments[-1] = ''
while '.' in segments:
segments.remove('.')
while 1:
i = 1
n = len(segments) - 1
while i < n:
if (segments[i] == '..'
and segments[i-1] not in ('', '..')):
del segments[i-1:i+1]
break
i = i+1
else:
break
if segments == ['', '..']:
segments[-1] = ''
elif len(segments) >= 2 and segments[-1] == '..':
segments[-2:] = ['']
return _coerce_result(urlunparse((scheme, netloc, '/'.join(segments),
params, query, fragment)))
def urldefrag(url):
"""Removes any existing fragment from URL.
Returns a tuple of the defragmented URL and the fragment. If
the URL contained no fragments, the second element is the
empty string.
"""
url, _coerce_result = _coerce_args(url)
if '#' in url:
s, n, p, a, q, frag = urlparse(url)
defrag = urlunparse((s, n, p, a, q, ''))
else:
frag = ''
defrag = url
return _coerce_result(DefragResult(defrag, frag))
_hexdig = '0123456789ABCDEFabcdef'
_hextobyte = {(a + b).encode(): bytes([int(a + b, 16)])
for a in _hexdig for b in _hexdig}
def unquote_to_bytes(string):
"""unquote_to_bytes('abc%20def') -> b'abc def'."""
# Note: strings are encoded as UTF-8. This is only an issue if it contains
# unescaped non-ASCII characters, which URIs should not.
if not string:
# Is it a string-like object?
string.split
return b''
if isinstance(string, str):
string = string.encode('utf-8')
bits = string.split(b'%')
if len(bits) == 1:
return string
res = [bits[0]]
append = res.append
for item in bits[1:]:
try:
append(_hextobyte[item[:2]])
append(item[2:])
except KeyError:
append(b'%')
append(item)
return b''.join(res)
_asciire = re.compile('([\x00-\x7f]+)')
def unquote(string, encoding='utf-8', errors='replace'):
"""Replace %xx escapes by their single-character equivalent. The optional
encoding and errors parameters specify how to decode percent-encoded
sequences into Unicode characters, as accepted by the bytes.decode()
method.
By default, percent-encoded sequences are decoded with UTF-8, and invalid
sequences are replaced by a placeholder character.
unquote('abc%20def') -> 'abc def'.
"""
if '%' not in string:
string.split
return string
if encoding is None:
encoding = 'utf-8'
if errors is None:
errors = 'replace'
bits = _asciire.split(string)
res = [bits[0]]
append = res.append
for i in range(1, len(bits), 2):
append(unquote_to_bytes(bits[i]).decode(encoding, errors))
append(bits[i + 1])
return ''.join(res)
def parse_qs(qs, keep_blank_values=False, strict_parsing=False,
encoding='utf-8', errors='replace'):
"""Parse a query given as a string argument.
Arguments:
qs: percent-encoded query string to be parsed
keep_blank_values: flag indicating whether blank values in
percent-encoded queries should be treated as blank strings.
A true value indicates that blanks should be retained as
blank strings. The default false value indicates that
blank values are to be ignored and treated as if they were
not included.
strict_parsing: flag indicating what to do with parsing errors.
If false (the default), errors are silently ignored.
If true, errors raise a ValueError exception.
encoding and errors: specify how to decode percent-encoded sequences
into Unicode characters, as accepted by the bytes.decode() method.
"""
parsed_result = {}
pairs = parse_qsl(qs, keep_blank_values, strict_parsing,
encoding=encoding, errors=errors)
for name, value in pairs:
if name in parsed_result:
parsed_result[name].append(value)
else:
parsed_result[name] = [value]
return parsed_result
def parse_qsl(qs, keep_blank_values=False, strict_parsing=False,
encoding='utf-8', errors='replace'):
"""Parse a query given as a string argument.
Arguments:
qs: percent-encoded query string to be parsed
keep_blank_values: flag indicating whether blank values in
percent-encoded queries should be treated as blank strings. A
true value indicates that blanks should be retained as blank
strings. The default false value indicates that blank values
are to be ignored and treated as if they were not included.
strict_parsing: flag indicating what to do with parsing errors. If
false (the default), errors are silently ignored. If true,
errors raise a ValueError exception.
encoding and errors: specify how to decode percent-encoded sequences
into Unicode characters, as accepted by the bytes.decode() method.
Returns a list, as G-d intended.
"""
qs, _coerce_result = _coerce_args(qs)
pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')]
r = []
for name_value in pairs:
if not name_value and not strict_parsing:
continue
nv = name_value.split('=', 1)
if len(nv) != 2:
if strict_parsing:
raise ValueError("bad query field: %r" % (name_value,))
# Handle case of a control-name with no equal sign
if keep_blank_values:
nv.append('')
else:
continue
if len(nv[1]) or keep_blank_values:
name = nv[0].replace('+', ' ')
name = unquote(name, encoding=encoding, errors=errors)
name = _coerce_result(name)
value = nv[1].replace('+', ' ')
value = unquote(value, encoding=encoding, errors=errors)
value = _coerce_result(value)
r.append((name, value))
return r
def unquote_plus(string, encoding='utf-8', errors='replace'):
"""Like unquote(), but also replace plus signs by spaces, as required for
unquoting HTML form values.
unquote_plus('%7e/abc+def') -> '~/abc def'
"""
string = string.replace('+', ' ')
return unquote(string, encoding, errors)
_ALWAYS_SAFE = frozenset(b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
b'abcdefghijklmnopqrstuvwxyz'
b'0123456789'
b'_.-')
_ALWAYS_SAFE_BYTES = bytes(_ALWAYS_SAFE)
_safe_quoters = {}
class Quoter(collections.defaultdict):
"""A mapping from bytes (in range(0,256)) to strings.
String values are percent-encoded byte values, unless the key < 128, and
in the "safe" set (either the specified safe set, or default set).
"""
# Keeps a cache internally, using defaultdict, for efficiency (lookups
# of cached keys don't call Python code at all).
def __init__(self, safe):
"""safe: bytes object."""
self.safe = _ALWAYS_SAFE.union(safe)
def __repr__(self):
# Without this, will just display as a defaultdict
return "<Quoter %r>" % dict(self)
def __missing__(self, b):
# Handle a cache miss. Store quoted string in cache and return.
res = chr(b) if b in self.safe else '%{:02X}'.format(b)
self[b] = res
return res
def quote(string, safe='/', encoding=None, errors=None):
"""quote('abc def') -> 'abc%20def'
Each part of a URL, e.g. the path info, the query, etc., has a
different set of reserved characters that must be quoted.
RFC 2396 Uniform Resource Identifiers (URI): Generic Syntax lists
the following reserved characters.
reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
"$" | ","
Each of these characters is reserved in some component of a URL,
but not necessarily in all of them.
By default, the quote function is intended for quoting the path
section of a URL. Thus, it will not encode '/'. This character
is reserved, but in typical usage the quote function is being
called on a path where the existing slash characters are used as
reserved characters.
string and safe may be either str or bytes objects. encoding must
not be specified if string is a str.
The optional encoding and errors parameters specify how to deal with
non-ASCII characters, as accepted by the str.encode method.
By default, encoding='utf-8' (characters are encoded with UTF-8), and
errors='strict' (unsupported characters raise a UnicodeEncodeError).
"""
if isinstance(string, str):
if not string:
return string
if encoding is None:
encoding = 'utf-8'
if errors is None:
errors = 'strict'
string = string.encode(encoding, errors)
else:
if encoding is not None:
raise TypeError("quote() doesn't support 'encoding' for bytes")
if errors is not None:
raise TypeError("quote() doesn't support 'errors' for bytes")
return quote_from_bytes(string, safe)
def quote_plus(string, safe='', encoding=None, errors=None):
"""Like quote(), but also replace ' ' with '+', as required for quoting
HTML form values. Plus signs in the original string are escaped unless
they are included in safe. It also does not have safe default to '/'.
"""
# Check if ' ' in string, where string may either be a str or bytes. If
# there are no spaces, the regular quote will produce the right answer.
if ((isinstance(string, str) and ' ' not in string) or
(isinstance(string, bytes) and b' ' not in string)):
return quote(string, safe, encoding, errors)
if isinstance(safe, str):
space = ' '
else:
space = b' '
string = quote(string, safe + space, encoding, errors)
return string.replace(' ', '+')
def quote_from_bytes(bs, safe='/'):
"""Like quote(), but accepts a bytes object rather than a str, and does
not perform string-to-bytes encoding. It always returns an ASCII string.
quote_from_bytes(b'abc def\x3f') -> 'abc%20def%3f'
"""
if not isinstance(bs, (bytes, bytearray)):
raise TypeError("quote_from_bytes() expected bytes")
if not bs:
return ''
if isinstance(safe, str):
# Normalize 'safe' by converting to bytes and removing non-ASCII chars
safe = safe.encode('ascii', 'ignore')
else:
safe = bytes([c for c in safe if c < 128])
if not bs.rstrip(_ALWAYS_SAFE_BYTES + safe):
return bs.decode()
try:
quoter = _safe_quoters[safe]
except KeyError:
_safe_quoters[safe] = quoter = Quoter(safe).__getitem__
return ''.join([quoter(char) for char in bs])
def urlencode(query, doseq=False, safe='', encoding=None, errors=None):
"""Encode a sequence of two-element tuples or dictionary into a URL query string.
If any values in the query arg are sequences and doseq is true, each
sequence element is converted to a separate parameter.
If the query arg is a sequence of two-element tuples, the order of the
parameters in the output will match the order of parameters in the
input.
The query arg may be either a string or a bytes type. When query arg is a
string, the safe, encoding and error parameters are sent the quote_plus for
encoding.
"""
if hasattr(query, "items"):
query = query.items()
else:
# It's a bother at times that strings and string-like objects are
# sequences.
try:
# non-sequence items should not work with len()
# non-empty strings will fail this
if len(query) and not isinstance(query[0], tuple):
raise TypeError
# Zero-length sequences of all types will get here and succeed,
# but that's a minor nit. Since the original implementation
# allowed empty dicts that type of behavior probably should be
# preserved for consistency
except TypeError:
ty, va, tb = sys.exc_info()
raise TypeError("not a valid non-string sequence "
"or mapping object").with_traceback(tb)
l = []
if not doseq:
for k, v in query:
if isinstance(k, bytes):
k = quote_plus(k, safe)
else:
k = quote_plus(str(k), safe, encoding, errors)
if isinstance(v, bytes):
v = quote_plus(v, safe)
else:
v = quote_plus(str(v), safe, encoding, errors)
l.append(k + '=' + v)
else:
for k, v in query:
if isinstance(k, bytes):
k = quote_plus(k, safe)
else:
k = quote_plus(str(k), safe, encoding, errors)
if isinstance(v, bytes):
v = quote_plus(v, safe)
l.append(k + '=' + v)
elif isinstance(v, str):
v = quote_plus(v, safe, encoding, errors)
l.append(k + '=' + v)
else:
try:
# Is this a sufficient test for sequence-ness?
x = len(v)
except TypeError:
# not a sequence
v = quote_plus(str(v), safe, encoding, errors)
l.append(k + '=' + v)
else:
# loop over the sequence
for elt in v:
if isinstance(elt, bytes):
elt = quote_plus(elt, safe)
else:
elt = quote_plus(str(elt), safe, encoding, errors)
l.append(k + '=' + elt)
return '&'.join(l)
# Utilities to parse URLs (most of these return None for missing parts):
# unwrap('<URL:type://host/path>') --> 'type://host/path'
# splittype('type:opaquestring') --> 'type', 'opaquestring'
# splithost('//host[:port]/path') --> 'host[:port]', '/path'
# splituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 'host[:port]'
# splitpasswd('user:passwd') -> 'user', 'passwd'
# splitport('host:port') --> 'host', 'port'
# splitquery('/path?query') --> '/path', 'query'
# splittag('/path#tag') --> '/path', 'tag'
# splitattr('/path;attr1=value1;attr2=value2;...') ->
# '/path', ['attr1=value1', 'attr2=value2', ...]
# splitvalue('attr=value') --> 'attr', 'value'
# urllib.parse.unquote('abc%20def') -> 'abc def'
# quote('abc def') -> 'abc%20def')
def to_bytes(url):
"""to_bytes(u"URL") --> 'URL'."""
# Most URL schemes require ASCII. If that changes, the conversion
# can be relaxed.
# XXX get rid of to_bytes()
if isinstance(url, str):
try:
url = url.encode("ASCII").decode()
except UnicodeError:
raise UnicodeError("URL " + repr(url) +
" contains non-ASCII characters")
return url
def unwrap(url):
"""unwrap('<URL:type://host/path>') --> 'type://host/path'."""
url = str(url).strip()
if url[:1] == '<' and url[-1:] == '>':
url = url[1:-1].strip()
if url[:4] == 'URL:': url = url[4:].strip()
return url
_typeprog = None
def splittype(url):
"""splittype('type:opaquestring') --> 'type', 'opaquestring'."""
global _typeprog
if _typeprog is None:
import re
_typeprog = re.compile('^([^/:]+):')
match = _typeprog.match(url)
if match:
scheme = match.group(1)
return scheme.lower(), url[len(scheme) + 1:]
return None, url
_hostprog = None
def splithost(url):
"""splithost('//host[:port]/path') --> 'host[:port]', '/path'."""
global _hostprog
if _hostprog is None:
import re
_hostprog = re.compile('^//([^/?]*)(.*)$')
match = _hostprog.match(url)
if match:
host_port = match.group(1)
path = match.group(2)
if path and not path.startswith('/'):
path = '/' + path
return host_port, path
return None, url
_userprog = None
def splituser(host):
"""splituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 'host[:port]'."""
global _userprog
if _userprog is None:
import re
_userprog = re.compile('^(.*)@(.*)$')
match = _userprog.match(host)
if match: return match.group(1, 2)
return None, host
_passwdprog = None
def splitpasswd(user):
"""splitpasswd('user:passwd') -> 'user', 'passwd'."""
global _passwdprog
if _passwdprog is None:
import re
_passwdprog = re.compile('^([^:]*):(.*)$',re.S)
match = _passwdprog.match(user)
if match: return match.group(1, 2)
return user, None
# splittag('/path#tag') --> '/path', 'tag'
_portprog = None
def splitport(host):
"""splitport('host:port') --> 'host', 'port'."""
global _portprog
if _portprog is None:
import re
_portprog = re.compile('^(.*):([0-9]+)$')
match = _portprog.match(host)
if match: return match.group(1, 2)
return host, None
_nportprog = None
def splitnport(host, defport=-1):
"""Split host and port, returning numeric port.
Return given default port if no ':' found; defaults to -1.
Return numerical port if a valid number are found after ':'.
Return None if ':' but not a valid number."""
global _nportprog
if _nportprog is None:
import re
_nportprog = re.compile('^(.*):(.*)$')
match = _nportprog.match(host)
if match:
host, port = match.group(1, 2)
try:
if not port: raise ValueError("no digits")
nport = int(port)
except ValueError:
nport = None
return host, nport
return host, defport
_queryprog = None
def splitquery(url):
"""splitquery('/path?query') --> '/path', 'query'."""
global _queryprog
if _queryprog is None:
import re
_queryprog = re.compile('^(.*)\?([^?]*)$')
match = _queryprog.match(url)
if match: return match.group(1, 2)
return url, None
_tagprog = None
def splittag(url):
"""splittag('/path#tag') --> '/path', 'tag'."""
global _tagprog
if _tagprog is None:
import re
_tagprog = re.compile('^(.*)#([^#]*)$')
match = _tagprog.match(url)
if match: return match.group(1, 2)
return url, None
def splitattr(url):
"""splitattr('/path;attr1=value1;attr2=value2;...') ->
'/path', ['attr1=value1', 'attr2=value2', ...]."""
words = url.split(';')
return words[0], words[1:]
_valueprog = None
def splitvalue(attr):
"""splitvalue('attr=value') --> 'attr', 'value'."""
global _valueprog
if _valueprog is None:
import re
_valueprog = re.compile('^([^=]*)=(.*)$')
match = _valueprog.match(attr)
if match: return match.group(1, 2)
return attr, None
|
gpl-3.0
|
[
624,
4003,
334,
6116,
436,
3847,
9,
10867,
14,
199,
199,
10290,
859,
365,
4079,
12188,
314,
2569,
7329,
28754,
14,
199,
199,
14468,
10551,
1184,
334,
18472,
1272,
304,
298,
12421,
7337,
473,
8577,
2,
701,
377,
14,
23207,
8715,
13,
44,
1024,
12,
820,
14,
5024,
316,
199,
460,
491,
14,
221,
603,
305,
1058,
12,
17474,
20527,
11811,
14,
199,
199,
14468,
8087,
708,
520,
298,
3484,
367,
18271,
6509,
22,
2654,
4357,
315,
2851,
1159,
701,
820,
14,
40,
262,
848,
12,
699,
14,
16034,
897,
351,
199,
460,
491,
14,
45,
305,
1058,
12,
1487,
26381,
21300,
14,
199,
199,
14468,
499,
13443,
26,
221,
298,
12421,
7337,
473,
8577,
334,
7639,
9,
582,
8307,
18377,
701,
377,
14,
199,
24947,
8715,
13,
44,
1024,
12,
820,
14,
5024,
316,
12,
436,
491,
14,
603,
305,
1058,
12,
25298,
833,
19960,
14,
199,
199,
14468,
499,
10997,
26,
298,
1918,
6016,
475,
2851,
5687,
401,
701,
510,
14,
40,
1997,
1237,
2360,
491,
603,
305,
1058,
12,
1603,
14,
3107,
65,
2676,
10728,
12,
1603,
21797,
19960,
14,
199,
199,
14468,
413,
11292,
26,
298,
15277,
1910,
8241,
7337,
6263,
2750,
401,
701,
820,
14,
5024,
316,
12,
738,
35,
473,
6310,
1132,
12,
1603,
11474,
199,
7155,
21,
14,
199,
199,
14468,
5557,
1703,
26,
298,
12421,
7337,
6263,
2750,
334,
2632,
2924,
701,
377,
14,
23207,
8715,
13,
44,
1024,
12,
491,
14,
603,
305,
1058,
12,
603,
14,
199,
45,
67,
3630,
72,
778,
12,
1487,
26381,
9013,
20,
199,
199,
14468,
10551,
1184,
365,
8652,
314,
1453,
4465,
436,
1263,
6466,
4493,
370,
199,
10290,
859,
1077,
26449,
543,
652,
14,
221,
710,
7097,
859,
365,
199,
19767,
440,
21926,
1013,
22676,
543,
642,
7329,
7037,
370,
347,
2442,
79,
199,
32225,
367,
6057,
12,
436,
367,
13388,
7163,
12901,
12,
2005,
199,
11059,
2173,
723,
6080,
687,
12731,
7329,
83,
787,
30403,
14,
710,
511,
9403,
315,
199,
396,
63,
10290,
14,
647,
6571,
282,
6954,
16385,
402,
6057,
5953,
14,
199,
624,
199,
199,
646,
295,
199,
646,
984,
199,
646,
5055,
199,
199,
363,
452,
363,
275,
2097,
10290,
401,
298,
633,
18185,
401,
298,
17755,
401,
298,
633,
318,
2527,
401,
1779,
298,
29491,
401,
298,
633,
30038,
401,
298,
10738,
401,
298,
1122,
63,
6177,
401,
1779,
298,
1122,
63,
26714,
401,
298,
3513,
401,
298,
3513,
63,
6666,
401,
298,
3513,
63,
504,
63,
2394,
401,
1779,
298,
12240,
401,
298,
12240,
63,
6666,
401,
298,
12240,
63,
475,
63,
2394,
937,
199,
199,
3,
437,
12505,
402,
21149,
661,
7,
4910,
4838,
701,
849,
9,
199,
5589,
63,
6188,
275,
788,
8915,
297,
283,
1014,
297,
283,
71,
411,
2523,
297,
283,
78,
15893,
297,
283,
15311,
297,
326,
283,
758,
374,
297,
283,
493,
297,
283,
2859,
297,
283,
83,
1014,
297,
283,
596,
83,
297,
326,
283,
496,
83,
529,
79,
297,
283,
2591,
681,
297,
283,
2591,
681,
85,
297,
3260,
283,
25032,
297,
326,
283,
6836,
297,
283,
6836,
11,
5510,
418,
199,
5589,
63,
12652,
275,
788,
8915,
297,
283,
1014,
297,
283,
71,
411,
2523,
297,
283,
78,
15893,
297,
283,
31085,
297,
2049,
283,
15311,
297,
283,
758,
374,
297,
283,
493,
297,
283,
596,
83,
297,
283,
2859,
297,
283,
83,
1014,
297,
2049,
283,
83,
13224,
297,
283,
496,
83,
529,
79,
297,
283,
2591,
681,
297,
283,
2591,
681,
85,
297,
283,
27152,
297,
3260,
2049,
283,
6836,
297,
283,
6836,
11,
5510,
297,
283,
25032,
297,
283,
19591,
297,
283,
3187,
297,
283,
3187,
11,
5510,
418,
199,
5589,
63,
1162,
275,
788,
8915,
297,
283,
28738,
297,
283,
496,
83,
529,
79,
297,
283,
1014,
297,
283,
15311,
297,
2049,
283,
2859,
297,
283,
83,
1014,
297,
283,
2591,
681,
297,
283,
2591,
681,
85,
297,
283,
17839,
297,
283,
338,
1190,
297,
2049,
283,
596,
83,
297,
3260,
283,
25032,
297,
283,
14146,
418,
199,
199,
3,
5723,
787,
440,
5965,
1202,
20827,
12,
1325,
1077,
25578,
367,
8552,
199,
3,
7163,
14,
221,
334,
1918,
89,
787,
625,
29383,
12,
1325,
1172,
282,
4575,
13,
11660,
316,
536,
4959,
199,
2865,
63,
72,
16437,
275,
788,
71,
411,
2523,
297,
283,
28738,
297,
283,
26206,
297,
283,
13224,
297,
490,
283,
31085,
297,
283,
758,
374,
297,
283,
15311,
297,
283,
83,
13224,
297,
283,
17839,
297,
283,
338,
1190,
418,
199,
5589,
63,
1131,
275,
788,
1014,
297,
283,
758,
374,
297,
283,
15311,
297,
283,
2859,
297,
283,
83,
1014,
297,
283,
596,
83,
297,
1598,
283,
71,
411,
2523,
297,
283,
2591,
681,
297,
283,
2591,
681,
85,
297,
283,
17839,
297,
283,
338,
1190,
297,
28696,
199,
5589,
63,
7677,
275,
788,
8915,
297,
283,
28738,
297,
283,
1014,
297,
283,
71,
411,
2523,
297,
283,
13224,
297,
326,
283,
78,
15893,
297,
283,
758,
374,
297,
283,
2859,
297,
283,
83,
1014,
297,
283,
83,
13224,
297,
326,
283,
493,
297,
283,
496,
83,
529,
79,
297,
28696,
199,
199,
3,
6659,
7421,
1686,
315,
5687,
1561,
199,
5512,
63,
6574,
275,
661,
23459,
7,
355,
283,
28114,
7,
355,
283,
11371,
7,
355,
6681,
13,
2659,
199,
199,
3,
5787,
26,
24413,
15810,
543,
9143,
14,
25003,
63,
1637,
199,
4283,
63,
8677,
63,
4305,
275,
3388,
199,
63,
1122,
63,
1637,
275,
1052,
199,
199,
318,
5436,
63,
1637,
837,
272,
408,
9721,
314,
2198,
2581,
436,
314,
28419,
878,
2581,
1041,
272,
485,
1122,
63,
1637,
14,
3584,
342,
272,
485,
3489,
63,
14209,
878,
14,
3584,
342,
421,
199,
3,
11642,
83,
367,
2783,
7252,
199,
3,
2104,
650,
14,
18,
12,
781,
9122,
605,
13824,
4409,
13103,
626,
199,
3,
2429,
1742,
10567,
10999,
10867,
370,
886,
3932,
5705,
199,
3,
15952,
436,
2644,
14,
982,
1686,
675,
5560,
787,
199,
3,
26568,
12,
781,
1443,
13773,
88,
642,
701,
1808,
16899,
13,
17,
199,
3,
15952,
14448,
367,
650,
14,
19,
199,
63,
11886,
63,
2991,
275,
283,
4371,
7,
199,
63,
11886,
63,
2550,
275,
283,
4768,
7,
199,
199,
318,
485
] |
[
4003,
334,
6116,
436,
3847,
9,
10867,
14,
199,
199,
10290,
859,
365,
4079,
12188,
314,
2569,
7329,
28754,
14,
199,
199,
14468,
10551,
1184,
334,
18472,
1272,
304,
298,
12421,
7337,
473,
8577,
2,
701,
377,
14,
23207,
8715,
13,
44,
1024,
12,
820,
14,
5024,
316,
199,
460,
491,
14,
221,
603,
305,
1058,
12,
17474,
20527,
11811,
14,
199,
199,
14468,
8087,
708,
520,
298,
3484,
367,
18271,
6509,
22,
2654,
4357,
315,
2851,
1159,
701,
820,
14,
40,
262,
848,
12,
699,
14,
16034,
897,
351,
199,
460,
491,
14,
45,
305,
1058,
12,
1487,
26381,
21300,
14,
199,
199,
14468,
499,
13443,
26,
221,
298,
12421,
7337,
473,
8577,
334,
7639,
9,
582,
8307,
18377,
701,
377,
14,
199,
24947,
8715,
13,
44,
1024,
12,
820,
14,
5024,
316,
12,
436,
491,
14,
603,
305,
1058,
12,
25298,
833,
19960,
14,
199,
199,
14468,
499,
10997,
26,
298,
1918,
6016,
475,
2851,
5687,
401,
701,
510,
14,
40,
1997,
1237,
2360,
491,
603,
305,
1058,
12,
1603,
14,
3107,
65,
2676,
10728,
12,
1603,
21797,
19960,
14,
199,
199,
14468,
413,
11292,
26,
298,
15277,
1910,
8241,
7337,
6263,
2750,
401,
701,
820,
14,
5024,
316,
12,
738,
35,
473,
6310,
1132,
12,
1603,
11474,
199,
7155,
21,
14,
199,
199,
14468,
5557,
1703,
26,
298,
12421,
7337,
6263,
2750,
334,
2632,
2924,
701,
377,
14,
23207,
8715,
13,
44,
1024,
12,
491,
14,
603,
305,
1058,
12,
603,
14,
199,
45,
67,
3630,
72,
778,
12,
1487,
26381,
9013,
20,
199,
199,
14468,
10551,
1184,
365,
8652,
314,
1453,
4465,
436,
1263,
6466,
4493,
370,
199,
10290,
859,
1077,
26449,
543,
652,
14,
221,
710,
7097,
859,
365,
199,
19767,
440,
21926,
1013,
22676,
543,
642,
7329,
7037,
370,
347,
2442,
79,
199,
32225,
367,
6057,
12,
436,
367,
13388,
7163,
12901,
12,
2005,
199,
11059,
2173,
723,
6080,
687,
12731,
7329,
83,
787,
30403,
14,
710,
511,
9403,
315,
199,
396,
63,
10290,
14,
647,
6571,
282,
6954,
16385,
402,
6057,
5953,
14,
199,
624,
199,
199,
646,
295,
199,
646,
984,
199,
646,
5055,
199,
199,
363,
452,
363,
275,
2097,
10290,
401,
298,
633,
18185,
401,
298,
17755,
401,
298,
633,
318,
2527,
401,
1779,
298,
29491,
401,
298,
633,
30038,
401,
298,
10738,
401,
298,
1122,
63,
6177,
401,
1779,
298,
1122,
63,
26714,
401,
298,
3513,
401,
298,
3513,
63,
6666,
401,
298,
3513,
63,
504,
63,
2394,
401,
1779,
298,
12240,
401,
298,
12240,
63,
6666,
401,
298,
12240,
63,
475,
63,
2394,
937,
199,
199,
3,
437,
12505,
402,
21149,
661,
7,
4910,
4838,
701,
849,
9,
199,
5589,
63,
6188,
275,
788,
8915,
297,
283,
1014,
297,
283,
71,
411,
2523,
297,
283,
78,
15893,
297,
283,
15311,
297,
326,
283,
758,
374,
297,
283,
493,
297,
283,
2859,
297,
283,
83,
1014,
297,
283,
596,
83,
297,
326,
283,
496,
83,
529,
79,
297,
283,
2591,
681,
297,
283,
2591,
681,
85,
297,
3260,
283,
25032,
297,
326,
283,
6836,
297,
283,
6836,
11,
5510,
418,
199,
5589,
63,
12652,
275,
788,
8915,
297,
283,
1014,
297,
283,
71,
411,
2523,
297,
283,
78,
15893,
297,
283,
31085,
297,
2049,
283,
15311,
297,
283,
758,
374,
297,
283,
493,
297,
283,
596,
83,
297,
283,
2859,
297,
283,
83,
1014,
297,
2049,
283,
83,
13224,
297,
283,
496,
83,
529,
79,
297,
283,
2591,
681,
297,
283,
2591,
681,
85,
297,
283,
27152,
297,
3260,
2049,
283,
6836,
297,
283,
6836,
11,
5510,
297,
283,
25032,
297,
283,
19591,
297,
283,
3187,
297,
283,
3187,
11,
5510,
418,
199,
5589,
63,
1162,
275,
788,
8915,
297,
283,
28738,
297,
283,
496,
83,
529,
79,
297,
283,
1014,
297,
283,
15311,
297,
2049,
283,
2859,
297,
283,
83,
1014,
297,
283,
2591,
681,
297,
283,
2591,
681,
85,
297,
283,
17839,
297,
283,
338,
1190,
297,
2049,
283,
596,
83,
297,
3260,
283,
25032,
297,
283,
14146,
418,
199,
199,
3,
5723,
787,
440,
5965,
1202,
20827,
12,
1325,
1077,
25578,
367,
8552,
199,
3,
7163,
14,
221,
334,
1918,
89,
787,
625,
29383,
12,
1325,
1172,
282,
4575,
13,
11660,
316,
536,
4959,
199,
2865,
63,
72,
16437,
275,
788,
71,
411,
2523,
297,
283,
28738,
297,
283,
26206,
297,
283,
13224,
297,
490,
283,
31085,
297,
283,
758,
374,
297,
283,
15311,
297,
283,
83,
13224,
297,
283,
17839,
297,
283,
338,
1190,
418,
199,
5589,
63,
1131,
275,
788,
1014,
297,
283,
758,
374,
297,
283,
15311,
297,
283,
2859,
297,
283,
83,
1014,
297,
283,
596,
83,
297,
1598,
283,
71,
411,
2523,
297,
283,
2591,
681,
297,
283,
2591,
681,
85,
297,
283,
17839,
297,
283,
338,
1190,
297,
28696,
199,
5589,
63,
7677,
275,
788,
8915,
297,
283,
28738,
297,
283,
1014,
297,
283,
71,
411,
2523,
297,
283,
13224,
297,
326,
283,
78,
15893,
297,
283,
758,
374,
297,
283,
2859,
297,
283,
83,
1014,
297,
283,
83,
13224,
297,
326,
283,
493,
297,
283,
496,
83,
529,
79,
297,
28696,
199,
199,
3,
6659,
7421,
1686,
315,
5687,
1561,
199,
5512,
63,
6574,
275,
661,
23459,
7,
355,
283,
28114,
7,
355,
283,
11371,
7,
355,
6681,
13,
2659,
199,
199,
3,
5787,
26,
24413,
15810,
543,
9143,
14,
25003,
63,
1637,
199,
4283,
63,
8677,
63,
4305,
275,
3388,
199,
63,
1122,
63,
1637,
275,
1052,
199,
199,
318,
5436,
63,
1637,
837,
272,
408,
9721,
314,
2198,
2581,
436,
314,
28419,
878,
2581,
1041,
272,
485,
1122,
63,
1637,
14,
3584,
342,
272,
485,
3489,
63,
14209,
878,
14,
3584,
342,
421,
199,
3,
11642,
83,
367,
2783,
7252,
199,
3,
2104,
650,
14,
18,
12,
781,
9122,
605,
13824,
4409,
13103,
626,
199,
3,
2429,
1742,
10567,
10999,
10867,
370,
886,
3932,
5705,
199,
3,
15952,
436,
2644,
14,
982,
1686,
675,
5560,
787,
199,
3,
26568,
12,
781,
1443,
13773,
88,
642,
701,
1808,
16899,
13,
17,
199,
3,
15952,
14448,
367,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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
] |
InAnimaTe/CouchPotatoServer
|
libs/xmpp/transports.py
|
89
|
15453
|
## transports.py
##
## Copyright (C) 2003-2004 Alexey "Snake" Nezhdanov
##
## 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, 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.
# $Id: transports.py,v 1.35 2009/04/07 08:34:09 snakeru Exp $
"""
This module contains the low-level implementations of xmpppy connect methods or
(in other words) transports for xmpp-stanzas.
Currently here is three transports:
direct TCP connect - TCPsocket class
proxied TCP connect - HTTPPROXYsocket class (CONNECT proxies)
TLS connection - TLS class. Can be used for SSL connections also.
Transports are stackable so you - f.e. TLS use HTPPROXYsocket or TCPsocket as more low-level transport.
Also exception 'error' is defined to allow capture of this module specific exceptions.
"""
import socket, select, base64, dispatcher, sys
from simplexml import ustr
from client import PlugIn
from protocol import *
# determine which DNS resolution library is available
HAVE_DNSPYTHON = False
HAVE_PYDNS = False
try:
import dns.resolver # http://dnspython.org/
HAVE_DNSPYTHON = True
except ImportError:
try:
import DNS # http://pydns.sf.net/
HAVE_PYDNS = True
except ImportError:
pass
DATA_RECEIVED = 'DATA RECEIVED'
DATA_SENT = 'DATA SENT'
class error:
"""An exception to be raised in case of low-level errors in methods of 'transports' module."""
def __init__(self, comment):
"""Cache the descriptive string"""
self._comment = comment
def __str__(self):
"""Serialise exception into pre-cached descriptive string."""
return self._comment
BUFLEN = 1024
class TCPsocket(PlugIn):
""" This class defines direct TCP connection method. """
def __init__(self, server = None, use_srv = True):
""" Cache connection point 'server'. 'server' is the tuple of (host, port)
absolutely the same as standard tcp socket uses. However library will lookup for
('_xmpp-client._tcp.' + host) SRV record in DNS and connect to the found (if it is)
server instead
"""
PlugIn.__init__(self)
self.DBG_LINE = 'socket'
self._exported_methods = [self.send, self.disconnect]
self._server, self.use_srv = server, use_srv
def srv_lookup(self, server):
" SRV resolver. Takes server=(host, port) as argument. Returns new (host, port) pair "
if HAVE_DNSPYTHON or HAVE_PYDNS:
host, port = server
possible_queries = ['_xmpp-client._tcp.' + host]
for query in possible_queries:
try:
if HAVE_DNSPYTHON:
answers = [x for x in dns.resolver.query(query, 'SRV')]
if answers:
host = str(answers[0].target)
port = int(answers[0].port)
break
elif HAVE_PYDNS:
# ensure we haven't cached an old configuration
DNS.DiscoverNameServers()
response = DNS.Request().req(query, qtype = 'SRV')
answers = response.answers
if len(answers) > 0:
# ignore the priority and weight for now
_, _, port, host = answers[0]['data']
del _
port = int(port)
break
except:
self.DEBUG('An error occurred while looking up %s' % query, 'warn')
server = (host, port)
else:
self.DEBUG("Could not load one of the supported DNS libraries (dnspython or pydns). SRV records will not be queried and you may need to set custom hostname/port for some servers to be accessible.\n", 'warn')
# end of SRV resolver
return server
def plugin(self, owner):
""" Fire up connection. Return non-empty string on success.
Also registers self.disconnected method in the owner's dispatcher.
Called internally. """
if not self._server: self._server = (self._owner.Server, 5222)
if self.use_srv: server = self.srv_lookup(self._server)
else: server = self._server
if not self.connect(server): return
self._owner.Connection = self
self._owner.RegisterDisconnectHandler(self.disconnected)
return 'ok'
def getHost(self):
""" Return the 'host' value that is connection is [will be] made to."""
return self._server[0]
def getPort(self):
""" Return the 'port' value that is connection is [will be] made to."""
return self._server[1]
def connect(self, server = None):
""" Try to connect to the given host/port. Does not lookup for SRV record.
Returns non-empty string on success. """
try:
if not server: server = self._server
self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._sock.connect((server[0], int(server[1])))
self._send = self._sock.sendall
self._recv = self._sock.recv
self.DEBUG("Successfully connected to remote host %s" % `server`, 'start')
return 'ok'
except socket.error, (errno, strerror):
self.DEBUG("Failed to connect to remote host %s: %s (%s)" % (`server`, strerror, errno), 'error')
except: pass
def plugout(self):
""" Disconnect from the remote server and unregister self.disconnected method from
the owner's dispatcher. """
self._sock.close()
if self._owner.__dict__.has_key('Connection'):
del self._owner.Connection
self._owner.UnregisterDisconnectHandler(self.disconnected)
def receive(self):
""" Reads all pending incoming data.
In case of disconnection calls owner's disconnected() method and then raises IOError exception."""
try: received = self._recv(BUFLEN)
except socket.sslerror, e:
self._seen_data = 0
if e[0] == socket.SSL_ERROR_WANT_READ: return ''
if e[0] == socket.SSL_ERROR_WANT_WRITE: return ''
self.DEBUG('Socket error while receiving data', 'error')
sys.exc_clear()
self._owner.disconnected()
raise IOError("Disconnected from server")
except: received = ''
while self.pending_data(0):
try: add = self._recv(BUFLEN)
except: add = ''
received += add
if not add: break
if len(received): # length of 0 means disconnect
self._seen_data = 1
self.DEBUG(received, 'got')
if hasattr(self._owner, 'Dispatcher'):
self._owner.Dispatcher.Event('', DATA_RECEIVED, received)
else:
self.DEBUG('Socket error while receiving data', 'error')
self._owner.disconnected()
raise IOError("Disconnected from server")
return received
def send(self, raw_data):
""" Writes raw outgoing data. Blocks until done.
If supplied data is unicode string, encodes it to utf-8 before send."""
if type(raw_data) == type(u''): raw_data = raw_data.encode('utf-8')
elif type(raw_data) <> type(''): raw_data = ustr(raw_data).encode('utf-8')
try:
self._send(raw_data)
# Avoid printing messages that are empty keepalive packets.
if raw_data.strip():
self.DEBUG(raw_data, 'sent')
if hasattr(self._owner, 'Dispatcher'): # HTTPPROXYsocket will send data before we have a Dispatcher
self._owner.Dispatcher.Event('', DATA_SENT, raw_data)
except:
self.DEBUG("Socket error while sending data", 'error')
self._owner.disconnected()
def pending_data(self, timeout = 0):
""" Returns true if there is a data ready to be read. """
return select.select([self._sock], [], [], timeout)[0]
def disconnect(self):
""" Closes the socket. """
self.DEBUG("Closing socket", 'stop')
self._sock.close()
def disconnected(self):
""" Called when a Network Error or disconnection occurs.
Designed to be overidden. """
self.DEBUG("Socket operation failed", 'error')
DBG_CONNECT_PROXY = 'CONNECTproxy'
class HTTPPROXYsocket(TCPsocket):
""" HTTP (CONNECT) proxy connection class. Uses TCPsocket as the base class
redefines only connect method. Allows to use HTTP proxies like squid with
(optionally) simple authentication (using login and password). """
def __init__(self, proxy, server, use_srv = True):
""" Caches proxy and target addresses.
'proxy' argument is a dictionary with mandatory keys 'host' and 'port' (proxy address)
and optional keys 'user' and 'password' to use for authentication.
'server' argument is a tuple of host and port - just like TCPsocket uses. """
TCPsocket.__init__(self, server, use_srv)
self.DBG_LINE = DBG_CONNECT_PROXY
self._proxy = proxy
def plugin(self, owner):
""" Starts connection. Used interally. Returns non-empty string on success."""
owner.debug_flags.append(DBG_CONNECT_PROXY)
return TCPsocket.plugin(self, owner)
def connect(self, dupe = None):
""" Starts connection. Connects to proxy, supplies login and password to it
(if were specified while creating instance). Instructs proxy to make
connection to the target server. Returns non-empty sting on success. """
if not TCPsocket.connect(self, (self._proxy['host'], self._proxy['port'])): return
self.DEBUG("Proxy server contacted, performing authentification", 'start')
connector = ['CONNECT %s:%s HTTP/1.0' % self._server,
'Proxy-Connection: Keep-Alive',
'Pragma: no-cache',
'Host: %s:%s' % self._server,
'User-Agent: HTTPPROXYsocket/v0.1']
if self._proxy.has_key('user') and self._proxy.has_key('password'):
credentials = '%s:%s' % (self._proxy['user'], self._proxy['password'])
credentials = base64.encodestring(credentials).strip()
connector.append('Proxy-Authorization: Basic ' + credentials)
connector.append('\r\n')
self.send('\r\n'.join(connector))
try: reply = self.receive().replace('\r', '')
except IOError:
self.DEBUG('Proxy suddenly disconnected', 'error')
self._owner.disconnected()
return
try: proto, code, desc = reply.split('\n')[0].split(' ', 2)
except: raise error('Invalid proxy reply')
if code <> '200':
self.DEBUG('Invalid proxy reply: %s %s %s' % (proto, code, desc), 'error')
self._owner.disconnected()
return
while reply.find('\n\n') == -1:
try: reply += self.receive().replace('\r', '')
except IOError:
self.DEBUG('Proxy suddenly disconnected', 'error')
self._owner.disconnected()
return
self.DEBUG("Authentification successfull. Jabber server contacted.", 'ok')
return 'ok'
def DEBUG(self, text, severity):
"""Overwrites DEBUG tag to allow debug output be presented as "CONNECTproxy"."""
return self._owner.DEBUG(DBG_CONNECT_PROXY, text, severity)
class TLS(PlugIn):
""" TLS connection used to encrypts already estabilished tcp connection."""
def PlugIn(self, owner, now = 0):
""" If the 'now' argument is true then starts using encryption immidiatedly.
If 'now' in false then starts encryption as soon as TLS feature is
declared by the server (if it were already declared - it is ok).
"""
if owner.__dict__.has_key('TLS'): return # Already enabled.
PlugIn.PlugIn(self, owner)
DBG_LINE = 'TLS'
if now: return self._startSSL()
if self._owner.Dispatcher.Stream.features:
try: self.FeaturesHandler(self._owner.Dispatcher, self._owner.Dispatcher.Stream.features)
except NodeProcessed: pass
else: self._owner.RegisterHandlerOnce('features', self.FeaturesHandler, xmlns = NS_STREAMS)
self.starttls = None
def plugout(self, now = 0):
""" Unregisters TLS handler's from owner's dispatcher. Take note that encription
can not be stopped once started. You can only break the connection and start over."""
self._owner.UnregisterHandler('features', self.FeaturesHandler, xmlns = NS_STREAMS)
self._owner.UnregisterHandler('proceed', self.StartTLSHandler, xmlns = NS_TLS)
self._owner.UnregisterHandler('failure', self.StartTLSHandler, xmlns = NS_TLS)
def FeaturesHandler(self, conn, feats):
""" Used to analyse server <features/> tag for TLS support.
If TLS is supported starts the encryption negotiation. Used internally"""
if not feats.getTag('starttls', namespace = NS_TLS):
self.DEBUG("TLS unsupported by remote server.", 'warn')
return
self.DEBUG("TLS supported by remote server. Requesting TLS start.", 'ok')
self._owner.RegisterHandlerOnce('proceed', self.StartTLSHandler, xmlns = NS_TLS)
self._owner.RegisterHandlerOnce('failure', self.StartTLSHandler, xmlns = NS_TLS)
self._owner.Connection.send('<starttls xmlns="%s"/>' % NS_TLS)
raise NodeProcessed
def pending_data(self, timeout = 0):
""" Returns true if there possible is a data ready to be read. """
return self._tcpsock._seen_data or select.select([self._tcpsock._sock], [], [], timeout)[0]
def _startSSL(self):
""" Immidiatedly switch socket to TLS mode. Used internally."""
""" Here we should switch pending_data to hint mode."""
tcpsock = self._owner.Connection
tcpsock._sslObj = socket.ssl(tcpsock._sock, None, None)
tcpsock._sslIssuer = tcpsock._sslObj.issuer()
tcpsock._sslServer = tcpsock._sslObj.server()
tcpsock._recv = tcpsock._sslObj.read
tcpsock._send = tcpsock._sslObj.write
tcpsock._seen_data = 1
self._tcpsock = tcpsock
tcpsock.pending_data = self.pending_data
tcpsock._sock.setblocking(0)
self.starttls = 'success'
def StartTLSHandler(self, conn, starttls):
""" Handle server reply if TLS is allowed to process. Behaves accordingly.
Used internally."""
if starttls.getNamespace() <> NS_TLS: return
self.starttls = starttls.getName()
if self.starttls == 'failure':
self.DEBUG("Got starttls response: " + self.starttls, 'error')
return
self.DEBUG("Got starttls proceed response. Switching to TLS/SSL...", 'ok')
self._startSSL()
self._owner.Dispatcher.PlugOut()
dispatcher.Dispatcher().PlugIn(self._owner)
|
gpl-3.0
|
[
309,
257,
7773,
83,
14,
647,
199,
309,
199,
309,
257,
1898,
334,
35,
9,
13004,
13,
15431,
6832,
1845,
89,
298,
20821,
1728,
2,
5612,
3951,
68,
8143,
86,
199,
309,
199,
309,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
309,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
309,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
12,
503,
334,
292,
2195,
945,
9,
199,
309,
257,
1263,
2945,
1015,
14,
199,
309,
199,
309,
257,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
309,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
309,
257,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
3,
2672,
1304,
26,
7773,
83,
14,
647,
12,
86,
413,
14,
1276,
8937,
15,
966,
15,
1780,
19363,
26,
1082,
26,
1643,
6895,
12630,
85,
7910,
2672,
199,
199,
624,
199,
2765,
859,
3509,
314,
6465,
13,
1896,
12591,
402,
671,
17901,
647,
4907,
3102,
503,
199,
8,
262,
1163,
5932,
9,
7773,
83,
367,
671,
17901,
13,
9746,
90,
305,
14,
199,
31499,
2348,
365,
7795,
7773,
83,
26,
199,
2275,
13488,
4907,
446,
13488,
3450,
1021,
199,
8221,
5299,
13488,
4907,
446,
3101,
20026,
3450,
1021,
334,
14657,
14942,
9,
199,
10224,
1950,
446,
12213,
1021,
14,
6855,
506,
1202,
367,
7799,
6947,
2597,
14,
199,
199,
7836,
83,
787,
3464,
461,
880,
1265,
446,
289,
14,
69,
14,
12213,
675,
4102,
48,
20026,
3450,
503,
13488,
3450,
465,
1655,
6465,
13,
1896,
7773,
14,
199,
199,
31892,
1919,
283,
705,
7,
365,
3247,
370,
2040,
12296,
402,
642,
859,
2488,
4967,
14,
199,
624,
199,
199,
646,
2838,
12,
3504,
12,
1300,
772,
12,
17475,
12,
984,
199,
504,
3486,
1652,
492,
399,
495,
199,
504,
1890,
492,
7497,
1518,
607,
199,
504,
4113,
492,
627,
199,
199,
3,
6705,
1314,
10237,
12401,
3555,
365,
2808,
199,
10767,
63,
12323,
11720,
275,
756,
199,
10767,
63,
4521,
12323,
275,
756,
199,
893,
26,
272,
492,
6715,
14,
7717,
327,
1455,
921,
5797,
1548,
14,
1308,
15,
272,
25227,
63,
12323,
11720,
275,
715,
199,
2590,
3545,
26,
272,
862,
26,
267,
492,
10237,
327,
1455,
921,
647,
5797,
14,
7646,
14,
846,
15,
267,
25227,
63,
4521,
12323,
275,
715,
272,
871,
3545,
26,
267,
986,
199,
199,
3998,
63,
28467,
30487,
275,
283,
3998,
5363,
2089,
30487,
7,
199,
3998,
63,
32173,
275,
283,
3998,
428,
1309,
7,
199,
199,
533,
1125,
26,
272,
408,
2493,
1919,
370,
506,
4915,
315,
1930,
402,
6465,
13,
1896,
2552,
315,
3102,
402,
283,
5545,
83,
7,
859,
1041,
272,
347,
636,
826,
721,
277,
12,
3721,
304,
267,
408,
4437,
314,
30262,
1059,
624,
267,
291,
423,
3349,
275,
3721,
339,
347,
636,
495,
721,
277,
304,
267,
408,
3571,
572,
1919,
1901,
876,
13,
5245,
30262,
1059,
1041,
267,
372,
291,
423,
3349,
199,
199,
2910,
3143,
742,
275,
6619,
199,
533,
13488,
3450,
8,
19173,
607,
304,
272,
408,
961,
1021,
7890,
4125,
13488,
1950,
1083,
14,
408,
272,
347,
636,
826,
721,
277,
12,
1654,
275,
488,
12,
675,
63,
15165,
275,
715,
304,
267,
408,
11977,
1950,
2376,
283,
1000,
1370,
283,
1000,
7,
365,
314,
2008,
402,
334,
1102,
12,
1844,
9,
288,
3679,
590,
314,
2011,
465,
4465,
14719,
2838,
4440,
14,
9738,
3555,
911,
4237,
367,
7205,
12331,
26608,
13,
1258,
423,
8815,
3530,
435,
1591,
9,
12765,
54,
2777,
315,
10237,
436,
4907,
370,
314,
1911,
334,
692,
652,
365,
9,
288,
1654,
3140,
267,
408,
267,
7497,
1518,
607,
855,
826,
721,
277,
9,
267,
291,
14,
18165,
63,
6174,
275,
283,
3450,
7,
267,
291,
423,
23028,
63,
2474,
275,
359,
277,
14,
2254,
12,
291,
14,
10673,
61,
267,
291,
423,
1000,
12,
291,
14,
1180,
63,
15165,
275,
1654,
12,
675,
63,
15165,
339,
347,
20006,
63,
3892,
8,
277,
12,
1654,
304,
267,
298,
12765,
54,
15611,
14,
17415,
1654,
2687,
1102,
12,
1844,
9,
465,
1423,
14,
1803,
892,
334,
1102,
12,
1844,
9,
4092,
298,
267,
340,
25227,
63,
12323,
11720,
503,
25227,
63,
4521,
12323,
26,
288,
1591,
12,
1844,
275,
1654,
288,
3962,
63,
10590,
275,
4044,
26608,
13,
1258,
423,
8815,
3530,
435,
1591,
61,
953,
367,
1827,
315,
3962,
63,
10590,
26,
355,
862,
26,
490,
340,
25227,
63,
12323,
11720,
26,
717,
17133,
275,
359,
88,
367,
671,
315,
6715,
14,
7717,
14,
1131,
8,
1131,
12,
283,
31546,
5440,
717,
340,
17133,
26,
1169,
1591,
275,
620,
8,
13379,
59,
16,
1055,
1375,
9,
1169,
1844,
275,
1109,
8,
13379,
59,
16,
1055,
719,
9,
1169,
2059,
490,
916,
25227,
63,
4521,
12323,
26,
717,
327,
4868,
781,
19051,
1133,
6328,
376,
2269,
2897,
717,
10237,
14,
2825,
5899,
985,
23637,
342,
717,
1177,
275,
10237,
14,
2017,
1252,
2103,
8,
1131,
12,
1894,
466,
275,
283,
31546,
358,
717,
17133,
275,
1177,
14,
13379,
717,
340,
822,
8,
13379,
9,
690,
378,
26,
1169,
327,
3686,
314,
7464,
436,
5401,
367,
3063,
1169,
5501,
5501,
1844,
12,
1591,
275,
17133,
59,
16,
2733,
576,
418,
1169,
2150,
485,
1169,
1844,
275,
1109,
8,
719,
9,
1169,
2059,
355,
871,
26,
490,
291,
14,
5287,
360,
2493,
1125,
8920,
1830,
10023,
1536,
450,
83,
7,
450,
1827,
12,
283,
4050,
358,
288,
1654,
275,
334,
1102,
12,
1844,
9,
267,
587,
26,
288,
291,
14,
5287,
480,
6531,
440,
2248,
1373,
402,
314,
3748,
10237,
8363,
334,
5797,
1548,
503,
1134,
5797,
680,
12765,
54,
5767,
911,
440,
506,
30081,
436,
1265,
1443,
1929,
370,
663,
3537,
6246,
15,
719,
367,
2005,
8037,
370,
506,
17909,
3134,
78,
401,
283,
4050,
358,
267,
327,
1284,
402,
12765,
54,
15611,
267,
372,
1654,
339,
347,
3589,
8,
277,
12,
5771,
304,
267,
408,
15967,
1536,
1950,
14,
1432,
2222,
13,
1667,
1059,
641,
3182,
14,
288,
6121,
24493,
291,
14,
27476,
1083
] |
[
257,
7773,
83,
14,
647,
199,
309,
199,
309,
257,
1898,
334,
35,
9,
13004,
13,
15431,
6832,
1845,
89,
298,
20821,
1728,
2,
5612,
3951,
68,
8143,
86,
199,
309,
199,
309,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
309,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
309,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
12,
503,
334,
292,
2195,
945,
9,
199,
309,
257,
1263,
2945,
1015,
14,
199,
309,
199,
309,
257,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
309,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
309,
257,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
3,
2672,
1304,
26,
7773,
83,
14,
647,
12,
86,
413,
14,
1276,
8937,
15,
966,
15,
1780,
19363,
26,
1082,
26,
1643,
6895,
12630,
85,
7910,
2672,
199,
199,
624,
199,
2765,
859,
3509,
314,
6465,
13,
1896,
12591,
402,
671,
17901,
647,
4907,
3102,
503,
199,
8,
262,
1163,
5932,
9,
7773,
83,
367,
671,
17901,
13,
9746,
90,
305,
14,
199,
31499,
2348,
365,
7795,
7773,
83,
26,
199,
2275,
13488,
4907,
446,
13488,
3450,
1021,
199,
8221,
5299,
13488,
4907,
446,
3101,
20026,
3450,
1021,
334,
14657,
14942,
9,
199,
10224,
1950,
446,
12213,
1021,
14,
6855,
506,
1202,
367,
7799,
6947,
2597,
14,
199,
199,
7836,
83,
787,
3464,
461,
880,
1265,
446,
289,
14,
69,
14,
12213,
675,
4102,
48,
20026,
3450,
503,
13488,
3450,
465,
1655,
6465,
13,
1896,
7773,
14,
199,
199,
31892,
1919,
283,
705,
7,
365,
3247,
370,
2040,
12296,
402,
642,
859,
2488,
4967,
14,
199,
624,
199,
199,
646,
2838,
12,
3504,
12,
1300,
772,
12,
17475,
12,
984,
199,
504,
3486,
1652,
492,
399,
495,
199,
504,
1890,
492,
7497,
1518,
607,
199,
504,
4113,
492,
627,
199,
199,
3,
6705,
1314,
10237,
12401,
3555,
365,
2808,
199,
10767,
63,
12323,
11720,
275,
756,
199,
10767,
63,
4521,
12323,
275,
756,
199,
893,
26,
272,
492,
6715,
14,
7717,
327,
1455,
921,
5797,
1548,
14,
1308,
15,
272,
25227,
63,
12323,
11720,
275,
715,
199,
2590,
3545,
26,
272,
862,
26,
267,
492,
10237,
327,
1455,
921,
647,
5797,
14,
7646,
14,
846,
15,
267,
25227,
63,
4521,
12323,
275,
715,
272,
871,
3545,
26,
267,
986,
199,
199,
3998,
63,
28467,
30487,
275,
283,
3998,
5363,
2089,
30487,
7,
199,
3998,
63,
32173,
275,
283,
3998,
428,
1309,
7,
199,
199,
533,
1125,
26,
272,
408,
2493,
1919,
370,
506,
4915,
315,
1930,
402,
6465,
13,
1896,
2552,
315,
3102,
402,
283,
5545,
83,
7,
859,
1041,
272,
347,
636,
826,
721,
277,
12,
3721,
304,
267,
408,
4437,
314,
30262,
1059,
624,
267,
291,
423,
3349,
275,
3721,
339,
347,
636,
495,
721,
277,
304,
267,
408,
3571,
572,
1919,
1901,
876,
13,
5245,
30262,
1059,
1041,
267,
372,
291,
423,
3349,
199,
199,
2910,
3143,
742,
275,
6619,
199,
533,
13488,
3450,
8,
19173,
607,
304,
272,
408,
961,
1021,
7890,
4125,
13488,
1950,
1083,
14,
408,
272,
347,
636,
826,
721,
277,
12,
1654,
275,
488,
12,
675,
63,
15165,
275,
715,
304,
267,
408,
11977,
1950,
2376,
283,
1000,
1370,
283,
1000,
7,
365,
314,
2008,
402,
334,
1102,
12,
1844,
9,
288,
3679,
590,
314,
2011,
465,
4465,
14719,
2838,
4440,
14,
9738,
3555,
911,
4237,
367,
7205,
12331,
26608,
13,
1258,
423,
8815,
3530,
435,
1591,
9,
12765,
54,
2777,
315,
10237,
436,
4907,
370,
314,
1911,
334,
692,
652,
365,
9,
288,
1654,
3140,
267,
408,
267,
7497,
1518,
607,
855,
826,
721,
277,
9,
267,
291,
14,
18165,
63,
6174,
275,
283,
3450,
7,
267,
291,
423,
23028,
63,
2474,
275,
359,
277,
14,
2254,
12,
291,
14,
10673,
61,
267,
291,
423,
1000,
12,
291,
14,
1180,
63,
15165,
275,
1654,
12,
675,
63,
15165,
339,
347,
20006,
63,
3892,
8,
277,
12,
1654,
304,
267,
298,
12765,
54,
15611,
14,
17415,
1654,
2687,
1102,
12,
1844,
9,
465,
1423,
14,
1803,
892,
334,
1102,
12,
1844,
9,
4092,
298,
267,
340,
25227,
63,
12323,
11720,
503,
25227,
63,
4521,
12323,
26,
288,
1591,
12,
1844,
275,
1654,
288,
3962,
63,
10590,
275,
4044,
26608,
13,
1258,
423,
8815,
3530,
435,
1591,
61,
953,
367,
1827,
315,
3962,
63,
10590,
26,
355,
862,
26,
490,
340,
25227,
63,
12323,
11720,
26,
717,
17133,
275,
359,
88,
367,
671,
315,
6715,
14,
7717,
14,
1131,
8,
1131,
12,
283,
31546,
5440,
717,
340,
17133,
26,
1169,
1591,
275,
620,
8,
13379,
59,
16,
1055,
1375,
9,
1169,
1844,
275,
1109,
8,
13379,
59,
16,
1055,
719,
9,
1169,
2059,
490,
916,
25227,
63,
4521,
12323,
26,
717,
327,
4868,
781,
19051,
1133,
6328,
376,
2269,
2897,
717,
10237,
14,
2825,
5899,
985,
23637,
342,
717,
1177,
275,
10237,
14,
2017,
1252,
2103,
8,
1131,
12,
1894,
466,
275,
283,
31546,
358,
717,
17133,
275,
1177,
14,
13379,
717,
340,
822,
8,
13379,
9,
690,
378,
26,
1169,
327,
3686,
314,
7464,
436,
5401,
367,
3063,
1169,
5501,
5501,
1844,
12,
1591,
275,
17133,
59,
16,
2733,
576,
418,
1169,
2150,
485,
1169,
1844,
275,
1109,
8,
719,
9,
1169,
2059,
355,
871,
26,
490,
291,
14,
5287,
360,
2493,
1125,
8920,
1830,
10023,
1536,
450,
83,
7,
450,
1827,
12,
283,
4050,
358,
288,
1654,
275,
334,
1102,
12,
1844,
9,
267,
587,
26,
288,
291,
14,
5287,
480,
6531,
440,
2248,
1373,
402,
314,
3748,
10237,
8363,
334,
5797,
1548,
503,
1134,
5797,
680,
12765,
54,
5767,
911,
440,
506,
30081,
436,
1265,
1443,
1929,
370,
663,
3537,
6246,
15,
719,
367,
2005,
8037,
370,
506,
17909,
3134,
78,
401,
283,
4050,
358,
267,
327,
1284,
402,
12765,
54,
15611,
267,
372,
1654,
339,
347,
3589,
8,
277,
12,
5771,
304,
267,
408,
15967,
1536,
1950,
14,
1432,
2222,
13,
1667,
1059,
641,
3182,
14,
288,
6121,
24493,
291,
14,
27476,
1083,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
lambday/shogun
|
examples/undocumented/python/kernel_top.py
|
4
|
2523
|
#!/usr/bin/env python
from tools.load import LoadMatrix
import numpy as np
lm=LoadMatrix()
traindat = lm.load_dna('../data/fm_train_dna.dat')
testdat = lm.load_dna('../data/fm_test_dna.dat')
label_traindat = lm.load_labels('../data/label_train_dna.dat')
fm_hmm_pos=[traindat[i] for i in np.where([label_traindat==1])[1] ]
fm_hmm_neg=[traindat[i] for i in np.where([label_traindat==-1])[1] ]
parameter_list = [[traindat,testdat,label_traindat,1e-1,1,0,False,1], \
[traindat,testdat,label_traindat,1e-1,1,0,False,1 ]]
def kernel_top (fm_train_dna=traindat,fm_test_dna=testdat,label_train_dna=label_traindat,pseudo=1e-1,
order=1,gap=0,reverse=False,c=1):
from shogun import StringCharFeatures, StringWordFeatures, TOPFeatures, DNA
from shogun import HMM, BW_NORMAL
import shogun as sg
N=1 # toy HMM with 1 state
M=4 # 4 observations -> DNA
# train HMM for positive class
charfeat=StringCharFeatures(fm_hmm_pos, DNA)
hmm_pos_train=StringWordFeatures(charfeat.get_alphabet())
hmm_pos_train.obtain_from_char(charfeat, order-1, order, gap, reverse)
pos=HMM(hmm_pos_train, N, M, pseudo)
pos.baum_welch_viterbi_train(BW_NORMAL)
# train HMM for negative class
charfeat=StringCharFeatures(fm_hmm_neg, DNA)
hmm_neg_train=StringWordFeatures(charfeat.get_alphabet())
hmm_neg_train.obtain_from_char(charfeat, order-1, order, gap, reverse)
neg=HMM(hmm_neg_train, N, M, pseudo)
neg.baum_welch_viterbi_train(BW_NORMAL)
# Kernel training data
charfeat=StringCharFeatures(fm_train_dna, DNA)
wordfeats_train=StringWordFeatures(charfeat.get_alphabet())
wordfeats_train.obtain_from_char(charfeat, order-1, order, gap, reverse)
# Kernel testing data
charfeat=StringCharFeatures(fm_test_dna, DNA)
wordfeats_test=StringWordFeatures(charfeat.get_alphabet())
wordfeats_test.obtain_from_char(charfeat, order-1, order, gap, reverse)
# get kernel on training data
pos.set_observations(wordfeats_train)
neg.set_observations(wordfeats_train)
feats_train=TOPFeatures(10, pos, neg, False, False)
kernel=sg.kernel("PolyKernel", c=c)
kernel.init(feats_train, feats_train)
km_train=kernel.get_kernel_matrix()
# get kernel on testing data
pos_clone=HMM(pos)
neg_clone=HMM(neg)
pos_clone.set_observations(wordfeats_test)
neg_clone.set_observations(wordfeats_test)
feats_test=TOPFeatures(10, pos_clone, neg_clone, False, False)
kernel.init(feats_train, feats_test)
km_test=kernel.get_kernel_matrix()
return km_train,km_test,kernel
if __name__=='__main__':
print("TOP Kernel")
kernel_top(*parameter_list[0])
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
504,
7249,
14,
912,
492,
7190,
6443,
199,
646,
2680,
465,
980,
199,
14344,
29,
6200,
6443,
342,
199,
199,
1239,
688,
292,
275,
24546,
14,
912,
63,
21075,
24592,
576,
15,
10886,
63,
2834,
63,
21075,
14,
4616,
358,
199,
396,
4616,
275,
24546,
14,
912,
63,
21075,
24592,
576,
15,
10886,
63,
396,
63,
21075,
14,
4616,
358,
199,
1302,
63,
1239,
688,
292,
275,
24546,
14,
912,
63,
3512,
24592,
576,
15,
1302,
63,
2834,
63,
21075,
14,
4616,
358,
199,
199,
10886,
63,
72,
596,
63,
1712,
1524,
1239,
688,
292,
59,
73,
61,
367,
284,
315,
980,
14,
4509,
779,
1302,
63,
1239,
688,
292,
389,
17,
11057,
17,
61,
1622,
199,
10886,
63,
72,
596,
63,
8705,
1524,
1239,
688,
292,
59,
73,
61,
367,
284,
315,
980,
14,
4509,
779,
1302,
63,
1239,
688,
292,
389,
13,
17,
11057,
17,
61,
1622,
199,
199,
5329,
63,
513,
275,
3474,
1239,
688,
292,
12,
396,
4616,
12,
1302,
63,
1239,
688,
292,
12,
17,
69,
13,
17,
12,
17,
12,
16,
12,
797,
12,
17,
467,
971,
199,
59,
1239,
688,
292,
12,
396,
4616,
12,
1302,
63,
1239,
688,
292,
12,
17,
69,
13,
17,
12,
17,
12,
16,
12,
797,
12,
17,
1622,
61,
199,
199,
318,
5114,
63,
2119,
334,
10886,
63,
2834,
63,
21075,
29,
1239,
688,
292,
12,
10886,
63,
396,
63,
21075,
29,
396,
4616,
12,
1302,
63,
2834,
63,
21075,
29,
1302,
63,
1239,
688,
292,
12,
22490,
29,
17,
69,
13,
17,
12,
199,
198,
1648,
29,
17,
12,
15046,
29,
16,
12,
4471,
29,
797,
12,
67,
29,
17,
304,
199,
198,
504,
930,
17924,
492,
2624,
1610,
10807,
12,
2624,
10155,
10807,
12,
32582,
10807,
12,
577,
7170,
199,
198,
504,
930,
17924,
492,
869,
3218,
12,
699,
55,
63,
10765,
199,
198,
646,
930,
17924,
465,
12578,
421,
198,
46,
29,
17,
327,
31239,
869,
3218,
543,
413,
1174,
199,
198,
45,
29,
20,
327,
841,
19739,
1035,
577,
7170,
4388,
198,
3,
3560,
869,
3218,
367,
7317,
1021,
199,
198,
1560,
11873,
29,
1558,
1610,
10807,
8,
10886,
63,
72,
596,
63,
1712,
12,
577,
7170,
9,
199,
198,
72,
596,
63,
1712,
63,
2834,
29,
1558,
10155,
10807,
8,
1560,
11873,
14,
362,
63,
31884,
1012,
199,
198,
72,
596,
63,
1712,
63,
2834,
14,
2873,
877,
63,
504,
63,
1560,
8,
1560,
11873,
12,
1865,
13,
17,
12,
1865,
12,
16301,
12,
3837,
9,
199,
198,
1712,
29,
40,
3218,
8,
72,
596,
63,
1712,
63,
2834,
12,
653,
12,
603,
12,
15984,
9,
199,
198,
1712,
14,
2470,
453,
63,
87,
352,
335,
63,
433,
351,
4492,
63,
2834,
8,
18344,
63,
10765,
9,
421,
198,
3,
3560,
869,
3218,
367,
6946,
1021,
199,
198,
1560,
11873,
29,
1558,
1610,
10807,
8,
10886,
63,
72,
596,
63,
8705,
12,
577,
7170,
9,
199,
198,
72,
596,
63,
8705,
63,
2834,
29,
1558,
10155,
10807,
8,
1560,
11873,
14,
362,
63,
31884,
1012,
199,
198,
72,
596,
63,
8705,
63,
2834,
14,
2873,
877,
63,
504,
63,
1560,
8,
1560,
11873,
12,
1865,
13,
17,
12,
1865,
12,
16301,
12,
3837,
9,
199,
198,
8705,
29,
40,
3218,
8,
72,
596,
63,
8705,
63,
2834,
12,
653,
12,
603,
12,
15984,
9,
199,
198,
8705,
14,
2470,
453,
63,
87,
352,
335,
63,
433,
351,
4492,
63,
2834,
8,
18344,
63,
10765,
9,
421,
198,
3,
24901,
6093,
666,
199,
198,
1560,
11873,
29,
1558,
1610,
10807,
8,
10886,
63,
2834,
63,
21075,
12,
577,
7170,
9,
199,
198,
1027,
29255,
63,
2834,
29,
1558,
10155,
10807,
8,
1560,
11873,
14,
362,
63,
31884,
1012,
199,
198,
1027,
29255,
63,
2834,
14,
2873,
877,
63,
504,
63,
1560,
8,
1560,
11873,
12,
1865,
13,
17,
12,
1865,
12,
16301,
12,
3837,
9,
421,
198,
3,
24901,
5343,
666,
199,
198,
1560,
11873,
29,
1558,
1610,
10807,
8,
10886,
63,
396,
63,
21075,
12,
577,
7170,
9,
199,
198,
1027,
29255,
63,
396,
29,
1558,
10155,
10807,
8,
1560,
11873,
14,
362,
63,
31884,
1012,
199,
198,
1027,
29255,
63,
396,
14,
2873,
877,
63,
504,
63,
1560,
8,
1560,
11873,
12,
1865,
13,
17,
12,
1865,
12,
16301,
12,
3837,
9,
421,
198,
3,
664,
5114,
641,
6093,
666,
199,
198,
1712,
14,
409,
63,
2873,
12225,
8,
1027,
29255,
63,
2834,
9,
199,
198,
8705,
14,
409,
63,
2873,
12225,
8,
1027,
29255,
63,
2834,
9,
199,
198,
29255,
63,
2834,
29,
11422,
10807,
8,
709,
12,
2086,
12,
14158,
12,
756,
12,
756,
9,
199,
198,
4989,
29,
1226,
14,
4989,
480,
12747,
14127,
401,
286,
29,
67,
9,
199,
198,
4989,
14,
826,
8,
29255,
63,
2834,
12,
1964,
1956,
63,
2834,
9,
199,
198,
14595,
63,
2834,
29,
4989,
14,
362,
63,
4989,
63,
3642,
342,
421,
198,
3,
664,
5114,
641,
5343,
666,
199,
198,
1712,
63,
6311,
29,
40,
3218,
8,
1712,
9,
199,
198,
8705,
63,
6311,
29,
40,
3218,
8,
8705,
9,
199,
198,
1712,
63,
6311,
14,
409,
63,
2873,
12225,
8,
1027,
29255,
63,
396,
9,
199,
198,
8705,
63,
6311,
14,
409,
63,
2873,
12225,
8,
1027,
29255,
63,
396,
9,
199,
198,
29255,
63,
396,
29,
11422,
10807,
8,
709,
12,
2086,
63,
6311,
12,
14158,
63,
6311,
12,
756,
12,
756,
9,
199,
198,
4989,
14,
826,
8,
29255,
63,
2834,
12,
1964,
1956,
63,
396,
9,
199,
198,
14595,
63,
396,
29,
4989,
14,
362,
63,
4989,
63,
3642,
342,
199,
198,
1107,
16155,
63,
2834,
12,
14595,
63,
396,
12,
4989,
199,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
199,
198,
1361,
480,
11422,
24901,
531,
199,
198,
4989,
63,
2119,
2031,
5329,
63,
513,
59,
16,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
504,
7249,
14,
912,
492,
7190,
6443,
199,
646,
2680,
465,
980,
199,
14344,
29,
6200,
6443,
342,
199,
199,
1239,
688,
292,
275,
24546,
14,
912,
63,
21075,
24592,
576,
15,
10886,
63,
2834,
63,
21075,
14,
4616,
358,
199,
396,
4616,
275,
24546,
14,
912,
63,
21075,
24592,
576,
15,
10886,
63,
396,
63,
21075,
14,
4616,
358,
199,
1302,
63,
1239,
688,
292,
275,
24546,
14,
912,
63,
3512,
24592,
576,
15,
1302,
63,
2834,
63,
21075,
14,
4616,
358,
199,
199,
10886,
63,
72,
596,
63,
1712,
1524,
1239,
688,
292,
59,
73,
61,
367,
284,
315,
980,
14,
4509,
779,
1302,
63,
1239,
688,
292,
389,
17,
11057,
17,
61,
1622,
199,
10886,
63,
72,
596,
63,
8705,
1524,
1239,
688,
292,
59,
73,
61,
367,
284,
315,
980,
14,
4509,
779,
1302,
63,
1239,
688,
292,
389,
13,
17,
11057,
17,
61,
1622,
199,
199,
5329,
63,
513,
275,
3474,
1239,
688,
292,
12,
396,
4616,
12,
1302,
63,
1239,
688,
292,
12,
17,
69,
13,
17,
12,
17,
12,
16,
12,
797,
12,
17,
467,
971,
199,
59,
1239,
688,
292,
12,
396,
4616,
12,
1302,
63,
1239,
688,
292,
12,
17,
69,
13,
17,
12,
17,
12,
16,
12,
797,
12,
17,
1622,
61,
199,
199,
318,
5114,
63,
2119,
334,
10886,
63,
2834,
63,
21075,
29,
1239,
688,
292,
12,
10886,
63,
396,
63,
21075,
29,
396,
4616,
12,
1302,
63,
2834,
63,
21075,
29,
1302,
63,
1239,
688,
292,
12,
22490,
29,
17,
69,
13,
17,
12,
199,
198,
1648,
29,
17,
12,
15046,
29,
16,
12,
4471,
29,
797,
12,
67,
29,
17,
304,
199,
198,
504,
930,
17924,
492,
2624,
1610,
10807,
12,
2624,
10155,
10807,
12,
32582,
10807,
12,
577,
7170,
199,
198,
504,
930,
17924,
492,
869,
3218,
12,
699,
55,
63,
10765,
199,
198,
646,
930,
17924,
465,
12578,
421,
198,
46,
29,
17,
327,
31239,
869,
3218,
543,
413,
1174,
199,
198,
45,
29,
20,
327,
841,
19739,
1035,
577,
7170,
4388,
198,
3,
3560,
869,
3218,
367,
7317,
1021,
199,
198,
1560,
11873,
29,
1558,
1610,
10807,
8,
10886,
63,
72,
596,
63,
1712,
12,
577,
7170,
9,
199,
198,
72,
596,
63,
1712,
63,
2834,
29,
1558,
10155,
10807,
8,
1560,
11873,
14,
362,
63,
31884,
1012,
199,
198,
72,
596,
63,
1712,
63,
2834,
14,
2873,
877,
63,
504,
63,
1560,
8,
1560,
11873,
12,
1865,
13,
17,
12,
1865,
12,
16301,
12,
3837,
9,
199,
198,
1712,
29,
40,
3218,
8,
72,
596,
63,
1712,
63,
2834,
12,
653,
12,
603,
12,
15984,
9,
199,
198,
1712,
14,
2470,
453,
63,
87,
352,
335,
63,
433,
351,
4492,
63,
2834,
8,
18344,
63,
10765,
9,
421,
198,
3,
3560,
869,
3218,
367,
6946,
1021,
199,
198,
1560,
11873,
29,
1558,
1610,
10807,
8,
10886,
63,
72,
596,
63,
8705,
12,
577,
7170,
9,
199,
198,
72,
596,
63,
8705,
63,
2834,
29,
1558,
10155,
10807,
8,
1560,
11873,
14,
362,
63,
31884,
1012,
199,
198,
72,
596,
63,
8705,
63,
2834,
14,
2873,
877,
63,
504,
63,
1560,
8,
1560,
11873,
12,
1865,
13,
17,
12,
1865,
12,
16301,
12,
3837,
9,
199,
198,
8705,
29,
40,
3218,
8,
72,
596,
63,
8705,
63,
2834,
12,
653,
12,
603,
12,
15984,
9,
199,
198,
8705,
14,
2470,
453,
63,
87,
352,
335,
63,
433,
351,
4492,
63,
2834,
8,
18344,
63,
10765,
9,
421,
198,
3,
24901,
6093,
666,
199,
198,
1560,
11873,
29,
1558,
1610,
10807,
8,
10886,
63,
2834,
63,
21075,
12,
577,
7170,
9,
199,
198,
1027,
29255,
63,
2834,
29,
1558,
10155,
10807,
8,
1560,
11873,
14,
362,
63,
31884,
1012,
199,
198,
1027,
29255,
63,
2834,
14,
2873,
877,
63,
504,
63,
1560,
8,
1560,
11873,
12,
1865,
13,
17,
12,
1865,
12,
16301,
12,
3837,
9,
421,
198,
3,
24901,
5343,
666,
199,
198,
1560,
11873,
29,
1558,
1610,
10807,
8,
10886,
63,
396,
63,
21075,
12,
577,
7170,
9,
199,
198,
1027,
29255,
63,
396,
29,
1558,
10155,
10807,
8,
1560,
11873,
14,
362,
63,
31884,
1012,
199,
198,
1027,
29255,
63,
396,
14,
2873,
877,
63,
504,
63,
1560,
8,
1560,
11873,
12,
1865,
13,
17,
12,
1865,
12,
16301,
12,
3837,
9,
421,
198,
3,
664,
5114,
641,
6093,
666,
199,
198,
1712,
14,
409,
63,
2873,
12225,
8,
1027,
29255,
63,
2834,
9,
199,
198,
8705,
14,
409,
63,
2873,
12225,
8,
1027,
29255,
63,
2834,
9,
199,
198,
29255,
63,
2834,
29,
11422,
10807,
8,
709,
12,
2086,
12,
14158,
12,
756,
12,
756,
9,
199,
198,
4989,
29,
1226,
14,
4989,
480,
12747,
14127,
401,
286,
29,
67,
9,
199,
198,
4989,
14,
826,
8,
29255,
63,
2834,
12,
1964,
1956,
63,
2834,
9,
199,
198,
14595,
63,
2834,
29,
4989,
14,
362,
63,
4989,
63,
3642,
342,
421,
198,
3,
664,
5114,
641,
5343,
666,
199,
198,
1712,
63,
6311,
29,
40,
3218,
8,
1712,
9,
199,
198,
8705,
63,
6311,
29,
40,
3218,
8,
8705,
9,
199,
198,
1712,
63,
6311,
14,
409,
63,
2873,
12225,
8,
1027,
29255,
63,
396,
9,
199,
198,
8705,
63,
6311,
14,
409,
63,
2873,
12225,
8,
1027,
29255,
63,
396,
9,
199,
198,
29255,
63,
396,
29,
11422,
10807,
8,
709,
12,
2086,
63,
6311,
12,
14158,
63,
6311,
12,
756,
12,
756,
9,
199,
198,
4989,
14,
826,
8,
29255,
63,
2834,
12,
1964,
1956,
63,
396,
9,
199,
198,
14595,
63,
396,
29,
4989,
14,
362,
63,
4989,
63,
3642,
342,
199,
198,
1107,
16155,
63,
2834,
12,
14595,
63,
396,
12,
4989,
199,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
199,
198,
1361,
480,
11422,
24901,
531,
199,
198,
4989,
63,
2119,
2031,
5329,
63,
513,
59,
16,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
alaski/nova
|
nova/volume/encryptors/cryptsetup.py
|
4
|
6382
|
# Copyright (c) 2013 The Johns Hopkins University/Applied Physics Laboratory
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import binascii
import os
from oslo_concurrency import processutils
from oslo_log import log as logging
from nova import exception
from nova.i18n import _LW
from nova import utils
from nova.volume.encryptors import base
LOG = logging.getLogger(__name__)
class CryptsetupEncryptor(base.VolumeEncryptor):
"""A VolumeEncryptor based on dm-crypt.
This VolumeEncryptor uses dm-crypt to encrypt the specified volume.
"""
def __init__(self, connection_info, **kwargs):
super(CryptsetupEncryptor, self).__init__(connection_info, **kwargs)
# Fail if no device_path was set when connecting the volume, e.g. in
# the case of libvirt network volume drivers.
data = connection_info['data']
if not data.get('device_path'):
volume_id = data.get('volume_id') or connection_info.get('serial')
raise exception.VolumeEncryptionNotSupported(
volume_id=volume_id,
volume_type=connection_info['driver_volume_type'])
# the device's path as given to libvirt -- e.g., /dev/disk/by-path/...
self.symlink_path = connection_info['data']['device_path']
# a unique name for the volume -- e.g., the iSCSI participant name
self.dev_name = 'crypt-%s' % self.symlink_path.split('/')[-1]
# NOTE(tsekiyama): In older version of nova, dev_name was the same
# as the symlink name. Now it has 'crypt-' prefix to avoid conflict
# with multipath device symlink. To enable rolling update, we use the
# old name when the encrypted volume already exists.
old_dev_name = self.symlink_path.split('/')[-1]
wwn = data.get('multipath_id')
if self._is_crypt_device_available(old_dev_name):
self.dev_name = old_dev_name
LOG.debug("Using old encrypted volume name: %s", self.dev_name)
elif wwn and wwn != old_dev_name:
# FibreChannel device could be named '/dev/mapper/<WWN>'.
if self._is_crypt_device_available(wwn):
self.dev_name = wwn
LOG.debug("Using encrypted volume name from wwn: %s",
self.dev_name)
# the device's actual path on the compute host -- e.g., /dev/sd_
self.dev_path = os.path.realpath(self.symlink_path)
def _is_crypt_device_available(self, dev_name):
if not os.path.exists('/dev/mapper/%s' % dev_name):
return False
try:
utils.execute('cryptsetup', 'status', dev_name, run_as_root=True)
except processutils.ProcessExecutionError as e:
# If /dev/mapper/<dev_name> is a non-crypt block device (such as a
# normal disk or multipath device), exit_code will be 1. In the
# case, we will omit the warning message.
if e.exit_code != 1:
LOG.warning(_LW('cryptsetup status %(dev_name)s exited '
'abnormally (status %(exit_code)s): %(err)s'),
{"dev_name": dev_name, "exit_code": e.exit_code,
"err": e.stderr})
return False
return True
def _get_passphrase(self, key):
"""Convert raw key to string."""
return binascii.hexlify(key).decode('utf-8')
def _open_volume(self, passphrase, **kwargs):
"""Opens the LUKS partition on the volume using the specified
passphrase.
:param passphrase: the passphrase used to access the volume
"""
LOG.debug("opening encrypted volume %s", self.dev_path)
# NOTE(joel-coffman): cryptsetup will strip trailing newlines from
# input specified on stdin unless --key-file=- is specified.
cmd = ["cryptsetup", "create", "--key-file=-"]
cipher = kwargs.get("cipher", None)
if cipher is not None:
cmd.extend(["--cipher", cipher])
key_size = kwargs.get("key_size", None)
if key_size is not None:
cmd.extend(["--key-size", key_size])
cmd.extend([self.dev_name, self.dev_path])
utils.execute(*cmd, process_input=passphrase,
check_exit_code=True, run_as_root=True)
def attach_volume(self, context, **kwargs):
"""Shadows the device and passes an unencrypted version to the
instance.
Transparent disk encryption is achieved by mounting the volume via
dm-crypt and passing the resulting device to the instance. The
instance is unaware of the underlying encryption due to modifying the
original symbolic link to refer to the device mounted by dm-crypt.
"""
key = self._get_key(context).get_encoded()
passphrase = self._get_passphrase(key)
self._open_volume(passphrase, **kwargs)
# modify the original symbolic link to refer to the decrypted device
utils.execute('ln', '--symbolic', '--force',
'/dev/mapper/%s' % self.dev_name, self.symlink_path,
run_as_root=True, check_exit_code=True)
def _close_volume(self, **kwargs):
"""Closes the device (effectively removes the dm-crypt mapping)."""
LOG.debug("closing encrypted volume %s", self.dev_path)
# cryptsetup returns 4 when attempting to destroy a non-active
# dm-crypt device. We are going to ignore this error code to make
# nova deleting that instance successfully.
utils.execute('cryptsetup', 'remove', self.dev_name,
run_as_root=True, check_exit_code=[0, 4])
def detach_volume(self, **kwargs):
"""Removes the dm-crypt mapping for the device."""
self._close_volume(**kwargs)
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6171,
710,
7135,
25338,
869,
411,
75,
3617,
15904,
15,
2640,
1857,
24309,
17378,
16871,
31671,
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,
421,
199,
646,
14755,
199,
646,
747,
199,
199,
504,
11258,
63,
27518,
492,
2112,
1208,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
20145,
199,
504,
5913,
492,
3778,
199,
504,
5913,
14,
2405,
14,
11929,
1384,
492,
1300,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
445,
13656,
2758,
1327,
4997,
269,
8,
1095,
14,
6464,
1327,
4997,
269,
304,
272,
408,
33,
15018,
1327,
4997,
269,
4079,
641,
17547,
13,
4997,
14,
339,
961,
15018,
1327,
4997,
269,
4440,
17547,
13,
4997,
370,
14645,
314,
2013,
3301,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1950,
63,
815,
12,
1011,
958,
304,
267,
1613,
8,
35,
13656,
2758,
1327,
4997,
269,
12,
291,
2843,
826,
721,
2105,
63,
815,
12,
1011,
958,
9,
398,
327,
12176,
340,
949,
2243,
63,
515,
1990,
663,
1380,
18170,
314,
3301,
12,
325,
14,
71,
14,
315,
267,
327,
314,
1930,
402,
13108,
2784,
3301,
19016,
14,
267,
666,
275,
1950,
63,
815,
459,
576,
418,
267,
340,
440,
666,
14,
362,
360,
1782,
63,
515,
735,
288,
3301,
63,
344,
275,
666,
14,
362,
360,
2405,
63,
344,
358,
503,
1950,
63,
815,
14,
362,
360,
2171,
358,
288,
746,
1919,
14,
6464,
25687,
26077,
8,
355,
3301,
63,
344,
29,
2405,
63,
344,
12,
355,
3301,
63,
466,
29,
2105,
63,
815,
459,
3090,
63,
2405,
63,
466,
1105,
398,
327,
314,
2243,
1159,
931,
465,
1627,
370,
13108,
1553,
325,
14,
71,
2020,
1182,
2374,
15,
4032,
15,
991,
13,
515,
15,
1396,
267,
291,
14,
13380,
63,
515,
275,
1950,
63,
815,
459,
576,
2545,
1782,
63,
515,
418,
398,
327,
282,
3747,
536,
367,
314,
3301,
1553,
325,
14,
71,
2020,
314,
284,
16958,
623,
16448,
536,
267,
291,
14,
2374,
63,
354,
275,
283,
4997,
3295,
83,
7,
450,
291,
14,
13380,
63,
515,
14,
1294,
25804,
17,
61,
398,
327,
6944,
8,
84,
261,
8810,
11552,
391,
304,
1010,
12731,
1015,
402,
5913,
12,
4866,
63,
354,
1990,
314,
2011,
267,
327,
465,
314,
15296,
536,
14,
7356,
652,
965,
283,
4997,
15668,
2403,
370,
5126,
12395,
267,
327,
543,
3510,
515,
2243,
15296,
14,
4005,
4756,
882,
10564,
1678,
12,
781,
675,
314,
267,
327,
2269,
536,
1380,
314,
14862,
3301,
2575,
3495,
14,
267,
2269,
63,
2374,
63,
354,
275,
291,
14,
13380,
63,
515,
14,
1294,
25804,
17,
61,
267,
336,
3501,
275,
666,
14,
362,
360,
3029,
515,
63,
344,
358,
267,
340,
291,
423,
374,
63,
4997,
63,
1782,
63,
4561,
8,
1753,
63,
2374,
63,
354,
304,
288,
291,
14,
2374,
63,
354,
275,
2269,
63,
2374,
63,
354,
288,
5051,
14,
1757,
480,
10369,
2269,
14862,
3301,
536,
26,
450,
83,
401,
291,
14,
2374,
63,
354,
9,
267,
916,
336,
3501,
436,
336,
3501,
1137,
2269,
63,
2374,
63,
354,
26,
288,
327,
481,
1892,
264,
5358,
2243,
4293,
506,
4310,
1994,
2374,
15,
7153,
8316,
55,
3705,
22936,
288,
340,
291,
423,
374,
63,
4997,
63,
1782,
63,
4561,
8,
10988,
304,
355,
291,
14,
2374,
63,
354,
275,
336,
3501,
355,
5051,
14,
1757,
480,
10369,
14862,
3301,
536,
687,
336,
3501,
26,
450,
83,
401,
2079,
291,
14,
2374,
63,
354,
9,
398,
327,
314,
2243,
1159,
3503,
931,
641,
314,
4526,
1591,
1553,
325,
14,
71,
2020,
1182,
2374,
15,
3893,
63,
267,
291,
14,
2374,
63,
515,
275,
747,
14,
515,
14,
11091,
8,
277,
14,
13380,
63,
515,
9,
339,
347,
485,
374,
63,
4997,
63,
1782,
63,
4561,
8,
277,
12,
4866,
63,
354,
304,
267,
340,
440,
747,
14,
515,
14,
2444,
2336,
2374,
15,
7153,
3149,
83,
7,
450,
4866,
63,
354,
304,
288,
372,
756,
398,
862,
26,
288,
3778,
14,
2526,
360,
4997,
2758,
297,
283,
1205,
297,
4866,
63,
354,
12,
1255,
63,
305,
63,
1231,
29,
549,
9,
267,
871,
2112,
1208,
14,
3498,
32165,
465,
325,
26,
288,
327,
982,
1182,
2374,
15,
7153,
8316,
2374,
63,
354,
30,
365,
282,
2222,
13,
4997,
1853,
2243,
334,
10180,
465,
282,
288,
327,
3293,
4543,
503,
3510,
515,
2243,
395,
4458,
63,
600,
911,
506,
413,
14,
1010,
314,
288,
327,
1930,
12,
781,
911,
19413,
314,
5721,
1245,
14,
288,
340,
325,
14,
2224,
63,
600,
1137,
413,
26,
355,
5051,
14,
3764,
1547,
20145,
360,
4997,
2758,
2004,
2818,
2374,
63,
354,
9,
83,
22987,
283,
1816,
283,
371,
4791,
1183,
334,
1205,
2818,
2224,
63,
600,
9,
83,
304,
2818,
1508,
9,
83,
659,
1169,
2420,
2374,
63,
354,
582,
4866,
63,
354,
12,
298,
2224,
63,
600,
582,
325,
14,
2224,
63,
600,
12,
2490,
298,
1508,
582,
325,
14,
3083,
1552,
288,
372,
756,
267,
372,
715,
339,
347,
485,
362,
63,
25173,
8,
277,
12,
790,
304,
267,
408,
7306,
3066,
790,
370,
1059,
1041,
267,
372,
14755,
14,
20677,
8,
498,
680,
2708,
360,
1624,
13,
24,
358,
339,
347,
485,
1490,
63,
2405,
8,
277,
12,
22432,
12,
1011,
958
] |
[
1898,
334,
67,
9,
6171,
710,
7135,
25338,
869,
411,
75,
3617,
15904,
15,
2640,
1857,
24309,
17378,
16871,
31671,
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,
421,
199,
646,
14755,
199,
646,
747,
199,
199,
504,
11258,
63,
27518,
492,
2112,
1208,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
20145,
199,
504,
5913,
492,
3778,
199,
504,
5913,
14,
2405,
14,
11929,
1384,
492,
1300,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
445,
13656,
2758,
1327,
4997,
269,
8,
1095,
14,
6464,
1327,
4997,
269,
304,
272,
408,
33,
15018,
1327,
4997,
269,
4079,
641,
17547,
13,
4997,
14,
339,
961,
15018,
1327,
4997,
269,
4440,
17547,
13,
4997,
370,
14645,
314,
2013,
3301,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1950,
63,
815,
12,
1011,
958,
304,
267,
1613,
8,
35,
13656,
2758,
1327,
4997,
269,
12,
291,
2843,
826,
721,
2105,
63,
815,
12,
1011,
958,
9,
398,
327,
12176,
340,
949,
2243,
63,
515,
1990,
663,
1380,
18170,
314,
3301,
12,
325,
14,
71,
14,
315,
267,
327,
314,
1930,
402,
13108,
2784,
3301,
19016,
14,
267,
666,
275,
1950,
63,
815,
459,
576,
418,
267,
340,
440,
666,
14,
362,
360,
1782,
63,
515,
735,
288,
3301,
63,
344,
275,
666,
14,
362,
360,
2405,
63,
344,
358,
503,
1950,
63,
815,
14,
362,
360,
2171,
358,
288,
746,
1919,
14,
6464,
25687,
26077,
8,
355,
3301,
63,
344,
29,
2405,
63,
344,
12,
355,
3301,
63,
466,
29,
2105,
63,
815,
459,
3090,
63,
2405,
63,
466,
1105,
398,
327,
314,
2243,
1159,
931,
465,
1627,
370,
13108,
1553,
325,
14,
71,
2020,
1182,
2374,
15,
4032,
15,
991,
13,
515,
15,
1396,
267,
291,
14,
13380,
63,
515,
275,
1950,
63,
815,
459,
576,
2545,
1782,
63,
515,
418,
398,
327,
282,
3747,
536,
367,
314,
3301,
1553,
325,
14,
71,
2020,
314,
284,
16958,
623,
16448,
536,
267,
291,
14,
2374,
63,
354,
275,
283,
4997,
3295,
83,
7,
450,
291,
14,
13380,
63,
515,
14,
1294,
25804,
17,
61,
398,
327,
6944,
8,
84,
261,
8810,
11552,
391,
304,
1010,
12731,
1015,
402,
5913,
12,
4866,
63,
354,
1990,
314,
2011,
267,
327,
465,
314,
15296,
536,
14,
7356,
652,
965,
283,
4997,
15668,
2403,
370,
5126,
12395,
267,
327,
543,
3510,
515,
2243,
15296,
14,
4005,
4756,
882,
10564,
1678,
12,
781,
675,
314,
267,
327,
2269,
536,
1380,
314,
14862,
3301,
2575,
3495,
14,
267,
2269,
63,
2374,
63,
354,
275,
291,
14,
13380,
63,
515,
14,
1294,
25804,
17,
61,
267,
336,
3501,
275,
666,
14,
362,
360,
3029,
515,
63,
344,
358,
267,
340,
291,
423,
374,
63,
4997,
63,
1782,
63,
4561,
8,
1753,
63,
2374,
63,
354,
304,
288,
291,
14,
2374,
63,
354,
275,
2269,
63,
2374,
63,
354,
288,
5051,
14,
1757,
480,
10369,
2269,
14862,
3301,
536,
26,
450,
83,
401,
291,
14,
2374,
63,
354,
9,
267,
916,
336,
3501,
436,
336,
3501,
1137,
2269,
63,
2374,
63,
354,
26,
288,
327,
481,
1892,
264,
5358,
2243,
4293,
506,
4310,
1994,
2374,
15,
7153,
8316,
55,
3705,
22936,
288,
340,
291,
423,
374,
63,
4997,
63,
1782,
63,
4561,
8,
10988,
304,
355,
291,
14,
2374,
63,
354,
275,
336,
3501,
355,
5051,
14,
1757,
480,
10369,
14862,
3301,
536,
687,
336,
3501,
26,
450,
83,
401,
2079,
291,
14,
2374,
63,
354,
9,
398,
327,
314,
2243,
1159,
3503,
931,
641,
314,
4526,
1591,
1553,
325,
14,
71,
2020,
1182,
2374,
15,
3893,
63,
267,
291,
14,
2374,
63,
515,
275,
747,
14,
515,
14,
11091,
8,
277,
14,
13380,
63,
515,
9,
339,
347,
485,
374,
63,
4997,
63,
1782,
63,
4561,
8,
277,
12,
4866,
63,
354,
304,
267,
340,
440,
747,
14,
515,
14,
2444,
2336,
2374,
15,
7153,
3149,
83,
7,
450,
4866,
63,
354,
304,
288,
372,
756,
398,
862,
26,
288,
3778,
14,
2526,
360,
4997,
2758,
297,
283,
1205,
297,
4866,
63,
354,
12,
1255,
63,
305,
63,
1231,
29,
549,
9,
267,
871,
2112,
1208,
14,
3498,
32165,
465,
325,
26,
288,
327,
982,
1182,
2374,
15,
7153,
8316,
2374,
63,
354,
30,
365,
282,
2222,
13,
4997,
1853,
2243,
334,
10180,
465,
282,
288,
327,
3293,
4543,
503,
3510,
515,
2243,
395,
4458,
63,
600,
911,
506,
413,
14,
1010,
314,
288,
327,
1930,
12,
781,
911,
19413,
314,
5721,
1245,
14,
288,
340,
325,
14,
2224,
63,
600,
1137,
413,
26,
355,
5051,
14,
3764,
1547,
20145,
360,
4997,
2758,
2004,
2818,
2374,
63,
354,
9,
83,
22987,
283,
1816,
283,
371,
4791,
1183,
334,
1205,
2818,
2224,
63,
600,
9,
83,
304,
2818,
1508,
9,
83,
659,
1169,
2420,
2374,
63,
354,
582,
4866,
63,
354,
12,
298,
2224,
63,
600,
582,
325,
14,
2224,
63,
600,
12,
2490,
298,
1508,
582,
325,
14,
3083,
1552,
288,
372,
756,
267,
372,
715,
339,
347,
485,
362,
63,
25173,
8,
277,
12,
790,
304,
267,
408,
7306,
3066,
790,
370,
1059,
1041,
267,
372,
14755,
14,
20677,
8,
498,
680,
2708,
360,
1624,
13,
24,
358,
339,
347,
485,
1490,
63,
2405,
8,
277,
12,
22432,
12,
1011,
958,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
opnsense/core
|
src/opnsense/scripts/netflow/lib/flowparser.py
|
1
|
8475
|
"""
Copyright (c) 2019 Ad Schellevis <ad@opnsense.org>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------------
flowd log parser
"""
import struct
import syslog
from socket import inet_ntop, AF_INET, AF_INET6, ntohl
class FlowParser:
# fields in order of appearance, use bitmask compare
field_definition_order = [
'tag',
'recv_time',
'proto_flags_tos',
'agent_addr4',
'agent_addr6',
'src_addr4',
'src_addr6',
'dst_addr4',
'dst_addr6',
'gateway_addr4',
'gateway_addr6',
'srcdst_port',
'packets',
'octets',
'if_indices',
'agent_info',
'flow_times',
'as_info',
'flow_engine_info'
]
# extract definition, integer values are read as rawdata (not parsed)
field_definition = {
'tag': 'I',
'recv_time': '>II',
'proto_flags_tos': 'BBBB',
'agent_addr4': 4,
'agent_addr6': 16,
'src_addr4': 4,
'src_addr6': 16,
'dst_addr4': 4,
'dst_addr6': 16,
'gateway_addr4': 4,
'gateway_addr6': 16,
'srcdst_port': '>HH',
'packets': '>Q',
'octets': '>Q',
'if_indices': '>II',
'agent_info': '>IIIHH',
'flow_times': '>II',
'as_info': 'IIBBH',
'flow_engine_info': 'HHII'
}
def __init__(self, filename, recv_stamp=None):
self._filename = filename
self._recv_stamp = recv_stamp
# cache formatter vs byte length
self._fmt_cache = dict()
# pre-calculate powers of 2
self._pow = dict()
for idx in range(len(self.field_definition_order)):
self._pow[idx] = pow(2, idx)
def calculate_size(self, fmt):
if fmt not in self._fmt_cache:
fmts = {'B': 1, 'H': 2, 'I': 4, 'Q': 8}
self._fmt_cache[fmt] = 0
for key in fmt:
if key in fmts:
self._fmt_cache[fmt] += fmts[key]
return self._fmt_cache[fmt]
def _parse_binary(self, raw_data, data_fields):
""" parse binary record
:param raw_data: binary data record
:param data_fields: field bitmask, provided by header
:return: dict
"""
raw_data_idx = 0
raw_record = dict()
for idx in range(len(self.field_definition_order)):
if self._pow[idx] & data_fields:
fieldname = self.field_definition_order[idx]
if fieldname in self.field_definition:
if type(self.field_definition[fieldname]) is int:
fsize = self.field_definition[fieldname]
raw_record[fieldname] = raw_data[raw_data_idx:raw_data_idx + fsize]
else:
fsize = self.calculate_size(self.field_definition[fieldname])
try:
content = struct.unpack(
self.field_definition[fieldname],
raw_data[raw_data_idx:raw_data_idx + fsize]
)
raw_record[fieldname] = content[0] if len(content) == 1 else content
except struct.error as e:
# the flowd record doesn't appear to be as expected, log for now.
syslog.syslog(syslog.LOG_NOTICE, "flowparser failed to unpack %s (%s)" % (fieldname, e))
raw_data_idx += fsize
return raw_record
def __iter__(self):
""" iterate flowd log file
:return:
"""
# pre-compile address formatters to save time
with open(self._filename, 'rb') as flowh:
while True:
# header [version, len_words, reserved, fields]
hdata = flowh.read(8)
if hdata == b'':
break
header = struct.unpack('BBHI', hdata)
record = self._parse_binary(
raw_data=flowh.read(header[1] * 4),
data_fields=ntohl(header[3])
)
if 'recv_time' not in record or 'agent_info' not in record:
# XXX invalid (empty?) flow record.
continue
record['recv_sec'] = record['recv_time'][0]
if self._recv_stamp is not None and record['recv_sec'] < self._recv_stamp:
# self._recv_stamp can contain the last received timestamp, in which case
# we should not return older data. The exact timestamp will be returned, so the
# consumer knows it doesn't have to read other, older, flowd log files
continue
record['sys_uptime_ms'] = record['agent_info'][0]
record['netflow_ver'] = record['agent_info'][3]
record['recv'] = record['recv_sec']
record['recv_usec'] = record['recv_time'][1]
record['if_ndx_in'] = -1
record['if_ndx_out'] = -1
record['src_port'] = 0
record['dst_port'] = 0
record['protocol'] = 0
if 'proto_flags_tos' in record:
record['tcp_flags'] = record['proto_flags_tos'][0]
record['protocol'] = record['proto_flags_tos'][1]
record['tos'] = record['proto_flags_tos'][2]
if 'flow_times' in record:
record['flow_start'] = record['flow_times'][0]
record['flow_finish'] = record['flow_times'][1]
else:
record['flow_start'] = record['sys_uptime_ms']
record['flow_finish'] = record['sys_uptime_ms']
if 'if_indices' in record:
record['if_ndx_in'] = record['if_indices'][0]
record['if_ndx_out'] = record['if_indices'][1]
if 'srcdst_port' in record:
record['src_port'] = record['srcdst_port'][0]
record['dst_port'] = record['srcdst_port'][1]
# concat ipv4/v6 fields into field without [4,6]
for key in self.field_definition_order:
if key in record:
if key[-1] == '4':
record[key[:-1]] = inet_ntop(AF_INET, record[key])
elif key[-1] == '6':
record[key[:-1]] = inet_ntop(AF_INET6, record[key])
# calculated values
record['flow_end'] = record['recv_sec'] - (record['sys_uptime_ms'] - record['flow_finish']) / 1000.0
record['duration_ms'] = (record['flow_finish'] - record['flow_start'])
record['flow_start'] = record['flow_end'] - record['duration_ms'] / 1000.0
if 'packets' not in record or 'octets' not in record or 'src_addr' not in record or 'dst_addr' not in record:
# this can't be useful data, skip record
continue
yield record
|
bsd-2-clause
|
[
624,
272,
1898,
334,
67,
9,
20312,
4431,
22985,
352,
274,
5068,
665,
350,
32,
411,
78,
16517,
14,
1308,
30,
272,
2900,
4481,
4644,
14,
339,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
272,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
339,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
1362,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
339,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
1362,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
1362,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
339,
5749,
4141,
2281,
7049,
1124,
1179,
2281,
891,
2401,
1821,
7168,
1549,
5292,
2990,
12,
272,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
272,
2401,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
272,
17632,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
272,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
272,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
272,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
272,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
272,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
272,
9726,
1634,
9712,
9784,
14,
339,
5620,
777,
8648,
272,
6369,
68,
943,
1798,
199,
624,
199,
646,
2702,
199,
646,
22112,
199,
504,
2838,
492,
17260,
63,
343,
411,
12,
20089,
63,
11367,
12,
20089,
63,
11367,
22,
12,
302,
475,
15544,
421,
199,
533,
20823,
2842,
26,
272,
327,
1504,
315,
1865,
402,
7468,
554,
12,
675,
4546,
2629,
6540,
272,
901,
63,
7463,
63,
1648,
275,
359,
267,
283,
1450,
297,
267,
283,
7637,
63,
521,
297,
267,
283,
2625,
63,
2469,
63,
14543,
297,
267,
283,
4054,
63,
2697,
20,
297,
267,
283,
4054,
63,
2697,
22,
297,
267,
283,
2164,
63,
2697,
20,
297,
267,
283,
2164,
63,
2697,
22,
297,
267,
283,
5119,
63,
2697,
20,
297,
267,
283,
5119,
63,
2697,
22,
297,
267,
283,
7019,
63,
2697,
20,
297,
267,
283,
7019,
63,
2697,
22,
297,
267,
283,
2164,
5119,
63,
719,
297,
267,
283,
18853,
297,
267,
283,
679,
16476,
297,
267,
283,
692,
63,
4108,
297,
267,
283,
4054,
63,
815,
297,
267,
283,
1659,
63,
4508,
297,
267,
283,
305,
63,
815,
297,
267,
283,
1659,
63,
3908,
63,
815,
7,
272,
1622,
339,
327,
5536,
5492,
12,
3000,
1338,
787,
1586,
465,
15705,
334,
1397,
4565,
9,
272,
901,
63,
7463,
275,
469,
267,
283,
1450,
356,
283,
41,
297,
267,
283,
7637,
63,
521,
356,
12696,
8921,
297,
267,
283,
2625,
63,
2469,
63,
14543,
356,
283,
5342,
5342,
297,
267,
283,
4054,
63,
2697,
20,
356,
841,
12,
267,
283,
4054,
63,
2697,
22,
356,
3193,
12,
267,
283,
2164,
63,
2697,
20,
356,
841,
12,
267,
283,
2164,
63,
2697,
22,
356,
3193,
12,
267,
283,
5119,
63,
2697,
20,
356,
841,
12,
267,
283,
5119,
63,
2697,
22,
356,
3193,
12,
267,
283,
7019,
63,
2697,
20,
356,
841,
12,
267,
283,
7019,
63,
2697,
22,
356,
3193,
12,
267,
283,
2164,
5119,
63,
719,
356,
12696,
10213,
297,
267,
283,
18853,
356,
12696,
49,
297,
267,
283,
679,
16476,
356,
12696,
49,
297,
267,
283,
692,
63,
4108,
356,
12696,
8921,
297,
267,
283,
4054,
63,
815,
356,
12696,
30807,
10213,
297,
267,
283,
1659,
63,
4508,
356,
12696,
8921,
297,
267,
283,
305,
63,
815,
356,
283,
41,
2100,
29931,
297,
267,
283,
1659,
63,
3908,
63,
815,
356,
283,
10213,
8921,
7,
272,
789,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
11904,
63,
2359,
29,
403,
304,
267,
291,
423,
1501,
275,
1788,
267,
291,
423,
7637,
63,
2359,
275,
11904,
63,
2359,
267,
327,
2581,
9698,
8118,
3696,
2582,
267,
291,
423,
5045,
63,
1637,
275,
1211,
342,
267,
327,
876,
13,
12063,
13131,
1192,
402,
499,
267,
291,
423,
8278,
275,
1211,
342,
267,
367,
4280,
315,
1425,
8,
552,
8,
277,
14,
698,
63,
7463,
63,
1648,
2298,
288,
291,
423,
8278,
59,
2996,
61,
275,
13131,
8,
18,
12,
4280,
9,
339,
347,
8671,
63,
890,
8,
277,
12,
7104,
304,
267,
340,
7104,
440,
315,
291,
423,
5045,
63,
1637,
26,
288,
20831,
1086,
275,
791,
34,
356,
413,
12,
283,
40,
356,
499,
12,
283,
41,
356,
841,
12,
283,
49,
356,
1695,
93,
288,
291,
423,
5045,
63,
1637,
59,
5045,
61,
275,
378,
288,
367,
790,
315,
7104,
26,
355,
340,
790,
315,
20831,
1086,
26,
490,
291,
423,
5045,
63,
1637,
59,
5045,
61,
847,
20831,
1086,
59,
498,
61,
267,
372,
291,
423,
5045,
63,
1637,
59,
5045,
61,
339,
347,
485,
1122,
63,
3008,
8,
277,
12,
3066,
63,
576,
12,
666,
63,
955,
304,
267,
408,
2198,
3366,
2777,
267,
520,
635,
3066,
63,
576,
26,
3366,
666,
2777,
267,
520,
635,
666,
63,
955,
26,
901,
4546,
2629,
12,
2741,
701,
1406,
267,
520,
1107,
26,
1211,
267,
408,
267,
3066,
63,
576,
63,
2996,
275,
378,
267,
3066,
63,
3059,
275,
1211,
342,
267,
367,
4280,
315,
1425,
8,
552,
8,
277,
14,
698,
63,
7463,
63,
1648,
2298,
288,
340,
291,
423,
8278,
59,
2996,
61,
1253,
666,
63,
955,
26,
355,
18887,
275,
291,
14,
698,
63,
7463,
63,
1648,
59,
2996,
61,
355,
340,
18887,
315,
291,
14,
698,
63,
7463,
26,
490,
340,
730,
8,
277,
14,
698,
63,
7463,
59,
13646,
566,
365,
1109,
26,
717,
289,
890,
275,
291,
14,
698,
63,
7463,
59,
13646,
61,
717,
3066,
63,
3059,
59,
13646,
61,
275,
3066,
63,
576,
59,
1773,
63,
576,
63,
2996,
26,
1773,
63,
576,
63,
2996,
435,
289,
890,
61,
490,
587,
26,
717,
289,
890,
275,
291,
14,
12063,
63,
890,
8,
277,
14,
698,
63,
7463,
59
] |
[
272,
1898,
334,
67,
9,
20312,
4431,
22985,
352,
274,
5068,
665,
350,
32,
411,
78,
16517,
14,
1308,
30,
272,
2900,
4481,
4644,
14,
339,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
272,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
339,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
1362,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
339,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
1362,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
1362,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
339,
5749,
4141,
2281,
7049,
1124,
1179,
2281,
891,
2401,
1821,
7168,
1549,
5292,
2990,
12,
272,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
272,
2401,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
272,
17632,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
272,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
272,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
272,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
272,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
272,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
272,
9726,
1634,
9712,
9784,
14,
339,
5620,
777,
8648,
272,
6369,
68,
943,
1798,
199,
624,
199,
646,
2702,
199,
646,
22112,
199,
504,
2838,
492,
17260,
63,
343,
411,
12,
20089,
63,
11367,
12,
20089,
63,
11367,
22,
12,
302,
475,
15544,
421,
199,
533,
20823,
2842,
26,
272,
327,
1504,
315,
1865,
402,
7468,
554,
12,
675,
4546,
2629,
6540,
272,
901,
63,
7463,
63,
1648,
275,
359,
267,
283,
1450,
297,
267,
283,
7637,
63,
521,
297,
267,
283,
2625,
63,
2469,
63,
14543,
297,
267,
283,
4054,
63,
2697,
20,
297,
267,
283,
4054,
63,
2697,
22,
297,
267,
283,
2164,
63,
2697,
20,
297,
267,
283,
2164,
63,
2697,
22,
297,
267,
283,
5119,
63,
2697,
20,
297,
267,
283,
5119,
63,
2697,
22,
297,
267,
283,
7019,
63,
2697,
20,
297,
267,
283,
7019,
63,
2697,
22,
297,
267,
283,
2164,
5119,
63,
719,
297,
267,
283,
18853,
297,
267,
283,
679,
16476,
297,
267,
283,
692,
63,
4108,
297,
267,
283,
4054,
63,
815,
297,
267,
283,
1659,
63,
4508,
297,
267,
283,
305,
63,
815,
297,
267,
283,
1659,
63,
3908,
63,
815,
7,
272,
1622,
339,
327,
5536,
5492,
12,
3000,
1338,
787,
1586,
465,
15705,
334,
1397,
4565,
9,
272,
901,
63,
7463,
275,
469,
267,
283,
1450,
356,
283,
41,
297,
267,
283,
7637,
63,
521,
356,
12696,
8921,
297,
267,
283,
2625,
63,
2469,
63,
14543,
356,
283,
5342,
5342,
297,
267,
283,
4054,
63,
2697,
20,
356,
841,
12,
267,
283,
4054,
63,
2697,
22,
356,
3193,
12,
267,
283,
2164,
63,
2697,
20,
356,
841,
12,
267,
283,
2164,
63,
2697,
22,
356,
3193,
12,
267,
283,
5119,
63,
2697,
20,
356,
841,
12,
267,
283,
5119,
63,
2697,
22,
356,
3193,
12,
267,
283,
7019,
63,
2697,
20,
356,
841,
12,
267,
283,
7019,
63,
2697,
22,
356,
3193,
12,
267,
283,
2164,
5119,
63,
719,
356,
12696,
10213,
297,
267,
283,
18853,
356,
12696,
49,
297,
267,
283,
679,
16476,
356,
12696,
49,
297,
267,
283,
692,
63,
4108,
356,
12696,
8921,
297,
267,
283,
4054,
63,
815,
356,
12696,
30807,
10213,
297,
267,
283,
1659,
63,
4508,
356,
12696,
8921,
297,
267,
283,
305,
63,
815,
356,
283,
41,
2100,
29931,
297,
267,
283,
1659,
63,
3908,
63,
815,
356,
283,
10213,
8921,
7,
272,
789,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
11904,
63,
2359,
29,
403,
304,
267,
291,
423,
1501,
275,
1788,
267,
291,
423,
7637,
63,
2359,
275,
11904,
63,
2359,
267,
327,
2581,
9698,
8118,
3696,
2582,
267,
291,
423,
5045,
63,
1637,
275,
1211,
342,
267,
327,
876,
13,
12063,
13131,
1192,
402,
499,
267,
291,
423,
8278,
275,
1211,
342,
267,
367,
4280,
315,
1425,
8,
552,
8,
277,
14,
698,
63,
7463,
63,
1648,
2298,
288,
291,
423,
8278,
59,
2996,
61,
275,
13131,
8,
18,
12,
4280,
9,
339,
347,
8671,
63,
890,
8,
277,
12,
7104,
304,
267,
340,
7104,
440,
315,
291,
423,
5045,
63,
1637,
26,
288,
20831,
1086,
275,
791,
34,
356,
413,
12,
283,
40,
356,
499,
12,
283,
41,
356,
841,
12,
283,
49,
356,
1695,
93,
288,
291,
423,
5045,
63,
1637,
59,
5045,
61,
275,
378,
288,
367,
790,
315,
7104,
26,
355,
340,
790,
315,
20831,
1086,
26,
490,
291,
423,
5045,
63,
1637,
59,
5045,
61,
847,
20831,
1086,
59,
498,
61,
267,
372,
291,
423,
5045,
63,
1637,
59,
5045,
61,
339,
347,
485,
1122,
63,
3008,
8,
277,
12,
3066,
63,
576,
12,
666,
63,
955,
304,
267,
408,
2198,
3366,
2777,
267,
520,
635,
3066,
63,
576,
26,
3366,
666,
2777,
267,
520,
635,
666,
63,
955,
26,
901,
4546,
2629,
12,
2741,
701,
1406,
267,
520,
1107,
26,
1211,
267,
408,
267,
3066,
63,
576,
63,
2996,
275,
378,
267,
3066,
63,
3059,
275,
1211,
342,
267,
367,
4280,
315,
1425,
8,
552,
8,
277,
14,
698,
63,
7463,
63,
1648,
2298,
288,
340,
291,
423,
8278,
59,
2996,
61,
1253,
666,
63,
955,
26,
355,
18887,
275,
291,
14,
698,
63,
7463,
63,
1648,
59,
2996,
61,
355,
340,
18887,
315,
291,
14,
698,
63,
7463,
26,
490,
340,
730,
8,
277,
14,
698,
63,
7463,
59,
13646,
566,
365,
1109,
26,
717,
289,
890,
275,
291,
14,
698,
63,
7463,
59,
13646,
61,
717,
3066,
63,
3059,
59,
13646,
61,
275,
3066,
63,
576,
59,
1773,
63,
576,
63,
2996,
26,
1773,
63,
576,
63,
2996,
435,
289,
890,
61,
490,
587,
26,
717,
289,
890,
275,
291,
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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ArcherSys/ArcherSys
|
Lib/site-packages/past/types/oldstr.py
|
62
|
4300
|
"""
Pure-Python implementation of a Python 2-like str object for Python 3.
"""
from collections import Iterable
from numbers import Integral
from past.utils import PY2, with_metaclass
_builtin_bytes = bytes
class BaseOldStr(type):
def __instancecheck__(cls, instance):
return isinstance(instance, _builtin_bytes)
def unescape(s):
"""
Interprets strings with escape sequences
Example:
>>> s = unescape(r'abc\\def') # i.e. 'abc\\\\def'
>>> print(s)
'abc\def'
>>> s2 = unescape('abc\\ndef')
>>> len(s2)
8
>>> print(s2)
abc
def
"""
return s.encode().decode('unicode_escape')
class oldstr(with_metaclass(BaseOldStr, _builtin_bytes)):
"""
A forward port of the Python 2 8-bit string object to Py3
"""
# Python 2 strings have no __iter__ method:
@property
def __iter__(self):
raise AttributeError
def __dir__(self):
return [thing for thing in dir(_builtin_bytes) if thing != '__iter__']
# def __new__(cls, *args, **kwargs):
# """
# From the Py3 bytes docstring:
# bytes(iterable_of_ints) -> bytes
# bytes(string, encoding[, errors]) -> bytes
# bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer
# bytes(int) -> bytes object of size given by the parameter initialized with null bytes
# bytes() -> empty bytes object
#
# Construct an immutable array of bytes from:
# - an iterable yielding integers in range(256)
# - a text string encoded using the specified encoding
# - any object implementing the buffer API.
# - an integer
# """
#
# if len(args) == 0:
# return super(newbytes, cls).__new__(cls)
# # Was: elif isinstance(args[0], newbytes):
# # We use type() instead of the above because we're redefining
# # this to be True for all unicode string subclasses. Warning:
# # This may render newstr un-subclassable.
# elif type(args[0]) == newbytes:
# return args[0]
# elif isinstance(args[0], _builtin_bytes):
# value = args[0]
# elif isinstance(args[0], unicode):
# if 'encoding' not in kwargs:
# raise TypeError('unicode string argument without an encoding')
# ###
# # Was: value = args[0].encode(**kwargs)
# # Python 2.6 string encode() method doesn't take kwargs:
# # Use this instead:
# newargs = [kwargs['encoding']]
# if 'errors' in kwargs:
# newargs.append(kwargs['errors'])
# value = args[0].encode(*newargs)
# ###
# elif isinstance(args[0], Iterable):
# if len(args[0]) == 0:
# # What is this?
# raise ValueError('unknown argument type')
# elif len(args[0]) > 0 and isinstance(args[0][0], Integral):
# # It's a list of integers
# value = b''.join([chr(x) for x in args[0]])
# else:
# raise ValueError('item cannot be interpreted as an integer')
# elif isinstance(args[0], Integral):
# if args[0] < 0:
# raise ValueError('negative count')
# value = b'\x00' * args[0]
# else:
# value = args[0]
# return super(newbytes, cls).__new__(cls, value)
def __repr__(self):
s = super(oldstr, self).__repr__() # e.g. b'abc' on Py3, b'abc' on Py3
return s[1:]
def __str__(self):
s = super(oldstr, self).__str__() # e.g. "b'abc'" or "b'abc\\ndef'
# TODO: fix this:
assert s[:2] == "b'" and s[-1] == "'"
return unescape(s[2:-1]) # e.g. 'abc' or 'abc\ndef'
def __getitem__(self, y):
if isinstance(y, Integral):
return super(oldstr, self).__getitem__(slice(y, y+1))
else:
return super(oldstr, self).__getitem__(y)
def __getslice__(self, *args):
return self.__getitem__(slice(*args))
def __contains__(self, key):
if isinstance(key, int):
return False
def __native__(self):
return bytes(self)
__all__ = ['oldstr']
|
mit
|
[
624,
199,
28928,
13,
4718,
4514,
402,
282,
2018,
499,
13,
2930,
620,
909,
367,
2018,
650,
14,
199,
624,
199,
199,
504,
5055,
492,
19937,
199,
504,
5579,
492,
23095,
199,
199,
504,
13541,
14,
1208,
492,
7843,
18,
12,
543,
63,
6577,
421,
199,
63,
5351,
63,
2394,
275,
2783,
421,
199,
533,
3523,
16411,
2848,
8,
466,
304,
272,
347,
636,
842,
1074,
721,
1886,
12,
1256,
304,
267,
372,
1228,
8,
842,
12,
485,
5351,
63,
2394,
9,
421,
199,
318,
22221,
8,
83,
304,
272,
408,
272,
6551,
657,
1086,
3326,
543,
4772,
8013,
339,
5679,
26,
272,
1306,
308,
275,
22221,
8,
82,
7,
3175,
1103,
318,
358,
257,
327,
284,
14,
69,
14,
283,
3175,
8712,
318,
7,
272,
1306,
870,
8,
83,
9,
272,
283,
3175,
60,
318,
7,
272,
1306,
308,
18,
275,
22221,
360,
3175,
1103,
18467,
358,
272,
1306,
822,
8,
83,
18,
9,
272,
1695,
272,
1306,
870,
8,
83,
18,
9,
272,
13022,
272,
347,
272,
408,
272,
372,
308,
14,
2143,
1252,
2708,
360,
2975,
63,
3765,
358,
16872,
199,
533,
2269,
495,
8,
1045,
63,
6577,
8,
1563,
16411,
2848,
12,
485,
5351,
63,
2394,
2298,
272,
408,
272,
437,
7568,
1844,
402,
314,
2018,
499,
1695,
13,
2075,
1059,
909,
370,
1611,
19,
272,
408,
272,
327,
2018,
499,
3326,
1172,
949,
636,
1661,
363,
1083,
26,
272,
768,
1829,
272,
347,
636,
1661,
721,
277,
304,
267,
746,
4281,
339,
347,
636,
694,
721,
277,
304,
267,
372,
359,
2127,
367,
8377,
315,
2935,
1547,
5351,
63,
2394,
9,
340,
8377,
1137,
2560,
1661,
17501,
339,
327,
347,
636,
1222,
721,
1886,
12,
627,
589,
12,
1011,
958,
304,
272,
327,
258,
408,
272,
327,
258,
11606,
314,
1611,
19,
2783,
9214,
26,
339,
327,
258,
2783,
8,
8147,
63,
1618,
63,
13141,
9,
1035,
2783,
272,
327,
258,
2783,
8,
875,
12,
2644,
14675,
2552,
566,
1035,
2783,
272,
327,
258,
2783,
8,
2394,
63,
269,
63,
2738,
9,
1035,
17092,
1331,
402,
2783,
63,
269,
63,
2738,
272,
327,
258,
2783,
8,
442,
9,
1035,
2783,
909,
402,
1568,
1627,
701,
314,
2725,
10038,
543,
2973,
2783,
272,
327,
258,
2783,
342,
1035,
2701,
2783,
909,
272,
327,
420,
272,
327,
258,
9215,
376,
17092,
1625,
402,
2783,
687,
26,
272,
327,
755,
446,
376,
6076,
32035,
9446,
315,
1425,
8,
3912,
9,
272,
327,
755,
446,
282,
1318,
1059,
5737,
1808,
314,
2013,
2644,
272,
327,
755,
446,
1263,
909,
18234,
314,
3335,
3261,
14,
272,
327,
755,
446,
376,
3000,
272,
327,
258,
408,
272,
327,
420,
272,
327,
258,
340,
822,
8,
589,
9,
508,
378,
26,
272,
327,
260,
372,
1613,
8,
1222,
2394,
12,
843,
2843,
1222,
721,
1886,
9,
272,
327,
258,
327,
644,
305,
26,
916,
1228,
8,
589,
59,
16,
467,
892,
2394,
304,
272,
327,
258,
327,
2136,
675,
730,
342,
3140,
402,
314,
3432,
2952,
781,
3984,
295,
318,
7969,
272,
327,
258,
327,
642,
370,
506,
715,
367,
1006,
2649,
1059,
9180,
14,
15902,
26,
272,
327,
258,
327,
961,
1443,
3795,
892,
495,
625,
13,
6083,
461,
14,
272,
327,
258,
916,
730,
8,
589,
59,
16,
566,
508,
892,
2394,
26,
272,
327,
260,
372,
1249,
59,
16,
61,
272,
327,
258,
916,
1228,
8,
589,
59,
16,
467,
485,
5351,
63,
2394,
304,
272,
327,
260,
574,
275,
1249,
59,
16,
61,
272,
327,
258,
916,
1228,
8,
589,
59,
16,
467,
2649,
304,
272,
327,
260,
340,
283,
2991,
7,
440,
315,
2074,
26,
272,
327,
3777,
746,
3146,
360,
2975,
1059,
1423,
1928,
376,
2644,
358,
272,
327,
260,
6754,
272,
327,
260,
327,
644,
305,
26,
257,
574,
275,
1249,
59,
16,
1055,
2143,
3682,
958,
9,
272,
327,
260,
327,
2018,
499,
14,
22,
1059,
3752,
342,
1083,
3181,
1133,
5452,
2074,
26,
272,
327,
260,
327,
3645,
642,
3140,
26,
272,
327,
260,
892,
589,
275,
359,
958,
459,
2991,
6538,
272,
327,
260,
340,
283,
2550,
7,
315,
2074,
26,
272,
327,
3777,
892,
589,
14,
740,
8,
958,
459,
2550,
1105,
272,
327,
260,
574,
275,
1249,
59,
16,
1055,
2143,
2031,
1222,
589,
9,
272,
327,
260,
6754,
5591,
327,
258,
916,
1228,
8,
589,
59,
16,
467,
19937,
304,
272,
327,
260,
340,
822,
8,
589,
59,
16,
566,
508,
378,
26,
272,
327,
3777,
327,
14791,
365,
642,
31,
272,
327,
3777,
746,
1722,
360,
5187,
1423,
730,
358,
272,
327,
260,
916,
822,
8,
589,
59,
16,
566,
690,
378,
436,
1228,
8,
589,
59,
16,
1527,
16,
467,
23095,
304,
272,
327,
3777,
327,
2779,
1159,
282,
769,
402,
9446,
272,
327,
3777,
574,
275,
330,
17067,
904,
779,
10194,
8,
88,
9,
367,
671,
315,
1249,
59,
16,
3934,
272,
327,
260,
587,
26,
272,
327,
3777,
746,
1722,
360,
1053,
3913,
506,
11922,
465,
376,
3000,
358,
272,
327,
258,
916,
1228,
8,
589,
59,
16,
467,
23095,
304,
272,
327,
260,
340,
1249,
59,
16,
61,
665,
378,
26,
272,
327,
3777,
746,
1722,
360,
7371,
2338,
358,
272,
327,
260,
574,
275,
330,
1154,
88,
383,
7,
627,
1249,
59,
16,
61,
272,
327,
258,
587,
26,
272,
327,
260,
574,
275,
1249,
59,
16,
61,
272,
327,
258,
372,
1613,
8,
1222,
2394,
12,
843,
2843,
1222,
721,
1886,
12,
574,
9,
5493,
347,
636,
2722,
721,
277,
304,
267,
308,
275,
1613,
8,
1753,
495,
12,
291,
2843,
2722,
4533,
257,
327,
325,
14,
71,
14,
330,
7,
3175,
7,
641,
1611,
19,
12,
330,
7,
3175,
7,
641,
1611,
19,
267,
372,
308,
59,
17,
2938,
339,
347,
636,
495,
721,
277,
304,
267,
308,
275,
1613,
8,
1753,
495,
12,
291,
2843,
495,
4533,
257,
327,
325,
14,
71,
14,
298,
66,
7,
3175,
4065,
503,
298,
66,
7,
3175,
1103,
18467,
7,
267,
327,
3254,
26,
5325,
642,
26,
267,
702,
308,
1491,
18,
61,
508,
298,
66,
4065,
436,
308,
1988,
17,
61,
508,
21673,
267,
372,
22221,
8,
83,
59,
18,
6809,
17,
566,
3322,
327,
325,
14
] |
[
199,
28928,
13,
4718,
4514,
402,
282,
2018,
499,
13,
2930,
620,
909,
367,
2018,
650,
14,
199,
624,
199,
199,
504,
5055,
492,
19937,
199,
504,
5579,
492,
23095,
199,
199,
504,
13541,
14,
1208,
492,
7843,
18,
12,
543,
63,
6577,
421,
199,
63,
5351,
63,
2394,
275,
2783,
421,
199,
533,
3523,
16411,
2848,
8,
466,
304,
272,
347,
636,
842,
1074,
721,
1886,
12,
1256,
304,
267,
372,
1228,
8,
842,
12,
485,
5351,
63,
2394,
9,
421,
199,
318,
22221,
8,
83,
304,
272,
408,
272,
6551,
657,
1086,
3326,
543,
4772,
8013,
339,
5679,
26,
272,
1306,
308,
275,
22221,
8,
82,
7,
3175,
1103,
318,
358,
257,
327,
284,
14,
69,
14,
283,
3175,
8712,
318,
7,
272,
1306,
870,
8,
83,
9,
272,
283,
3175,
60,
318,
7,
272,
1306,
308,
18,
275,
22221,
360,
3175,
1103,
18467,
358,
272,
1306,
822,
8,
83,
18,
9,
272,
1695,
272,
1306,
870,
8,
83,
18,
9,
272,
13022,
272,
347,
272,
408,
272,
372,
308,
14,
2143,
1252,
2708,
360,
2975,
63,
3765,
358,
16872,
199,
533,
2269,
495,
8,
1045,
63,
6577,
8,
1563,
16411,
2848,
12,
485,
5351,
63,
2394,
2298,
272,
408,
272,
437,
7568,
1844,
402,
314,
2018,
499,
1695,
13,
2075,
1059,
909,
370,
1611,
19,
272,
408,
272,
327,
2018,
499,
3326,
1172,
949,
636,
1661,
363,
1083,
26,
272,
768,
1829,
272,
347,
636,
1661,
721,
277,
304,
267,
746,
4281,
339,
347,
636,
694,
721,
277,
304,
267,
372,
359,
2127,
367,
8377,
315,
2935,
1547,
5351,
63,
2394,
9,
340,
8377,
1137,
2560,
1661,
17501,
339,
327,
347,
636,
1222,
721,
1886,
12,
627,
589,
12,
1011,
958,
304,
272,
327,
258,
408,
272,
327,
258,
11606,
314,
1611,
19,
2783,
9214,
26,
339,
327,
258,
2783,
8,
8147,
63,
1618,
63,
13141,
9,
1035,
2783,
272,
327,
258,
2783,
8,
875,
12,
2644,
14675,
2552,
566,
1035,
2783,
272,
327,
258,
2783,
8,
2394,
63,
269,
63,
2738,
9,
1035,
17092,
1331,
402,
2783,
63,
269,
63,
2738,
272,
327,
258,
2783,
8,
442,
9,
1035,
2783,
909,
402,
1568,
1627,
701,
314,
2725,
10038,
543,
2973,
2783,
272,
327,
258,
2783,
342,
1035,
2701,
2783,
909,
272,
327,
420,
272,
327,
258,
9215,
376,
17092,
1625,
402,
2783,
687,
26,
272,
327,
755,
446,
376,
6076,
32035,
9446,
315,
1425,
8,
3912,
9,
272,
327,
755,
446,
282,
1318,
1059,
5737,
1808,
314,
2013,
2644,
272,
327,
755,
446,
1263,
909,
18234,
314,
3335,
3261,
14,
272,
327,
755,
446,
376,
3000,
272,
327,
258,
408,
272,
327,
420,
272,
327,
258,
340,
822,
8,
589,
9,
508,
378,
26,
272,
327,
260,
372,
1613,
8,
1222,
2394,
12,
843,
2843,
1222,
721,
1886,
9,
272,
327,
258,
327,
644,
305,
26,
916,
1228,
8,
589,
59,
16,
467,
892,
2394,
304,
272,
327,
258,
327,
2136,
675,
730,
342,
3140,
402,
314,
3432,
2952,
781,
3984,
295,
318,
7969,
272,
327,
258,
327,
642,
370,
506,
715,
367,
1006,
2649,
1059,
9180,
14,
15902,
26,
272,
327,
258,
327,
961,
1443,
3795,
892,
495,
625,
13,
6083,
461,
14,
272,
327,
258,
916,
730,
8,
589,
59,
16,
566,
508,
892,
2394,
26,
272,
327,
260,
372,
1249,
59,
16,
61,
272,
327,
258,
916,
1228,
8,
589,
59,
16,
467,
485,
5351,
63,
2394,
304,
272,
327,
260,
574,
275,
1249,
59,
16,
61,
272,
327,
258,
916,
1228,
8,
589,
59,
16,
467,
2649,
304,
272,
327,
260,
340,
283,
2991,
7,
440,
315,
2074,
26,
272,
327,
3777,
746,
3146,
360,
2975,
1059,
1423,
1928,
376,
2644,
358,
272,
327,
260,
6754,
272,
327,
260,
327,
644,
305,
26,
257,
574,
275,
1249,
59,
16,
1055,
2143,
3682,
958,
9,
272,
327,
260,
327,
2018,
499,
14,
22,
1059,
3752,
342,
1083,
3181,
1133,
5452,
2074,
26,
272,
327,
260,
327,
3645,
642,
3140,
26,
272,
327,
260,
892,
589,
275,
359,
958,
459,
2991,
6538,
272,
327,
260,
340,
283,
2550,
7,
315,
2074,
26,
272,
327,
3777,
892,
589,
14,
740,
8,
958,
459,
2550,
1105,
272,
327,
260,
574,
275,
1249,
59,
16,
1055,
2143,
2031,
1222,
589,
9,
272,
327,
260,
6754,
5591,
327,
258,
916,
1228,
8,
589,
59,
16,
467,
19937,
304,
272,
327,
260,
340,
822,
8,
589,
59,
16,
566,
508,
378,
26,
272,
327,
3777,
327,
14791,
365,
642,
31,
272,
327,
3777,
746,
1722,
360,
5187,
1423,
730,
358,
272,
327,
260,
916,
822,
8,
589,
59,
16,
566,
690,
378,
436,
1228,
8,
589,
59,
16,
1527,
16,
467,
23095,
304,
272,
327,
3777,
327,
2779,
1159,
282,
769,
402,
9446,
272,
327,
3777,
574,
275,
330,
17067,
904,
779,
10194,
8,
88,
9,
367,
671,
315,
1249,
59,
16,
3934,
272,
327,
260,
587,
26,
272,
327,
3777,
746,
1722,
360,
1053,
3913,
506,
11922,
465,
376,
3000,
358,
272,
327,
258,
916,
1228,
8,
589,
59,
16,
467,
23095,
304,
272,
327,
260,
340,
1249,
59,
16,
61,
665,
378,
26,
272,
327,
3777,
746,
1722,
360,
7371,
2338,
358,
272,
327,
260,
574,
275,
330,
1154,
88,
383,
7,
627,
1249,
59,
16,
61,
272,
327,
258,
587,
26,
272,
327,
260,
574,
275,
1249,
59,
16,
61,
272,
327,
258,
372,
1613,
8,
1222,
2394,
12,
843,
2843,
1222,
721,
1886,
12,
574,
9,
5493,
347,
636,
2722,
721,
277,
304,
267,
308,
275,
1613,
8,
1753,
495,
12,
291,
2843,
2722,
4533,
257,
327,
325,
14,
71,
14,
330,
7,
3175,
7,
641,
1611,
19,
12,
330,
7,
3175,
7,
641,
1611,
19,
267,
372,
308,
59,
17,
2938,
339,
347,
636,
495,
721,
277,
304,
267,
308,
275,
1613,
8,
1753,
495,
12,
291,
2843,
495,
4533,
257,
327,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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
JTarball/tetherbox
|
docker/app/app/backend/apps/_archive/blog_codewheel/views.py
|
4
|
11119
|
import logging
from itertools import chain
from django.shortcuts import HttpResponse
from django.shortcuts import render_to_response as render_to_resp
from django.template import RequestContext
from django.views.generic import ListView, DetailView, TemplateView, View
from django.contrib.auth.views import redirect_to_login
from django.contrib.auth.decorators import login_required
from django.conf import settings
from django.http import Http404
from django.core.exceptions import ObjectDoesNotExist
from project.views.mixins import JSONResponseMixin, AjaxResponseMixin, PjaxResponseMixin, SuperuserRequiredMixin, LoginRequiredMixin, StaffuserRequiredMixin, require_get, require_post
from blog.models import Post, PostNode, Comment
from blog.forms.forms import CommentForm
from blog.utils import cwmarkdown
logger = logging.getLogger('project_logger')
class NoPostMsgMixin(object):
no_post_message = 'Sorry, no posts found.'
def get_context_data(self, **kwargs):
""" Get the context for this view. Add No Post Message. """
context = super(NoPostMsgMixin, self).get_context_data(**kwargs)
context.update({'no_post_msg':self.no_post_message})
return context
class PublishedPostsMixin(NoPostMsgMixin):
model = Post
def get_queryset(self):
return self.model.objects.live()
class PublishedUserPostsMixin(NoPostMsgMixin):
no_post_message = 'Sorry, no posts found for user: '
model = Post
def get_queryset(self, **kwargs):
self.no_post_message += self.kwargs['username']
return self.model.objects.live_by_user(user=self.kwargs['username'])
class PublishedYearPostsMixin(NoPostMsgMixin):
no_post_message = 'Sorry, no posts found for year: '
model = Post
def get_queryset(self, **kwargs):
self.no_post_message += self.kwargs['year']
print self.no_post_message
return self.model.objects.live_by_year(year=self.kwargs['year'])
class PublishedCategoryPostsMixin(NoPostMsgMixin):
no_post_message = 'Sorry, no posts found for category: '
model = Post
def get_queryset(self, **kwargs):
self.no_post_message += self.kwargs['category']
return self.model.objects.live_by_category(category=self.kwargs['category'])
# ============ Views ===================== #
class PostDetailView(PublishedPostsMixin, DetailView):
pass
class PostListView(PublishedPostsMixin, ListView):
pass
class PostUserListView(PublishedUserPostsMixin, ListView):
pass
class PostYearListView(PublishedYearPostsMixin, ListView):
pass
class PostCategoryListView(PublishedCategoryPostsMixin, ListView):
pass
#
#
#
#
#
#
#
#
#
#
#
##############################################################################
from django.utils.decorators import method_decorator
class AjaxCompatibleLoginRequiredMixin(object):
"""
View mixin which verifies that the user has authenticated.
Ajax if not
NOTE: This should be the left-most mixin of a view.
"""
@method_decorator(login_required)
def dispatch(self, request, *args, **kwargs):
request_method = request.method.lower()
if request.is_ajax() and request_method in self.http_method_names:
handler = getattr(self, '%s_ajax' % request_method, self.http_method_not_allowed)
self.request = request
self.args = args
self.kwargs = kwargs
return handler(request, *args, **kwargs)
else:
return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs)
class AjaxCompatibleStaffuserRequiredMixin(object):
"""
View mixin which verifies that the user has authenticated.
Ajax if not
NOTE: This should be the left-most mixin of a view.
"""
login_url = settings.LOGIN_REDIRECT_URL # LOGIN_URL from project settings
raise_exception = False # Default whether to raise an exception to none
redirect_field_name = 'next' # Set by django.contrib.auth
def dispatch(self, request, *args, **kwargs):
if not request.user.is_staff: # If the request's user is not staff,
if self.raise_exception: # *and* if an exception was desired
raise PermissionDenied # return a forbidden response
else:
return redirect_to_login(request.get_full_path(),
self.login_url,
self.redirect_field_name)
return super(AjaxCompatibleStaffuserRequiredMixin, self).dispatch(request,
*args, **kwargs)
##############################################################################
# PostNode Views
##############################################################################
class PostNodeListMixin(ListView):
model = PostNode
def get(self, request, *args, **kwargs):
logger.info('%s, this is the get function from %s: %s' % (self.__class__.__name__, self.__module__, self.__doc__))
return super(PostNodeListMixin, self).get(self,**kwargs)
class PostNodeRootListView(PostNodeListMixin):
""" This is a view to list of all root nodes. """
def get_queryset(self, **kwargs):
return self.model.objects.filter(level=0)[0].get_root().get_siblings(include_self=True)
class PostNodeLanguageListView(PostNodeListMixin):
""" This is a view to list of languages. """
def get_queryset(self, **kwargs):
language = self.kwargs['language']
# Should be unique but lets be panoroid
return self.model.objects.filter(slug=language)[0].get_children()
class PostNodeListView(PostNodeListMixin):
""" This is a view to display a list of PostNodes. """
par_id = None
def get_context_data(self, **kwargs):
context = super(PostNodeListView, self).get_context_data(**kwargs)
post_list = Post.objects.filter(published=True, node__id=self.par_id)
context['post_list'] = post_list
return context
def get_queryset(self, **kwargs):
language = self.kwargs['language']
parent = self.kwargs['parent']
print language, parent
node_language = self.model.objects.get(slug=language)
par = self.model.objects.get(language=node_language.id, slug=parent)
self.par_id = par.id
return par.get_children()
##############################################################################
# Post
##############################################################################
class NoPostMsgMixin(object):
no_post_message = 'Sorry, no posts found.'
def get_context_data(self, **kwargs):
""" Get the context for this view. Add No Post Message. """
context = super(NoPostMsgMixin, self).get_context_data(**kwargs)
context.update({'no_post_msg':self.no_post_message})
return context
class PublishedPostsMixin(NoPostMsgMixin):
model = Post
def get_queryset(self):
print "PublishedPostsMixin"
return self.model.objects.live()
class PostDetailView(PublishedPostsMixin, DetailView):
# We need to override the object to take into account language etc
# def get_object(self, queryset=None):
# if queryset is None:
# queryset = self.get_queryset()
# slug = self.kwargs.get(self.slug_url_kwarg, None)
# slug_field = self.get_slug_field()
# queryset = queryset.filter(**{slug_field: slug})
# try:
# obj = queryset.get(node__slug=self.kwargs['parent'], node__language=self.kwargs['language'])
# except ObjectDoesNotExist:
# raise Http404(_(u"No %(verbose_name)s found matching the query") %
# {'verbose_name': queryset.model._meta.verbose_name})
# return obj
pass
class PostEditView(AjaxResponseMixin, View):
model = Post
template_name = 'blog/preview.html'
def get(self, request, *args, **kwargs):
logger.info('%s, this is the ajax_get function from %s' % (self.__class__.__name__, self.__module__))
#self.object = self.get_object()
#context = super(PostEditView, self).get_context_data(**kwargs)
content = request.GET.get('q')
print request.GET
print request.POST
print "content", content
preview = cwmarkdown(content)
print "preview", preview
return HttpResponse(preview)
return render_to_resp(self.template_name, context, context_instance=RequestContext(request), mimetype='application/javascript')
def post(self, request, *args, **kwargs):
logger.info('%s, this is the ajax_get function from %s' % (self.__class__.__name__, self.__module__))
#self.object = self.get_object()
#context = super(PostEditView, self).get_context_data(**kwargs)
content = request.POST.get('foo')
print request
print request.POST
print "content", content
preview = cwmarkdown(content)
print "preview", preview
return HttpResponse(preview)
return render_to_resp(self.template_name, context, context_instance=RequestContext(request), mimetype='application/javascript')
# views.py
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.core.urlresolvers import reverse_lazy
#https://docs.djangoproject.com/en/1.7/topics/class-based-views/generic-editing/
class CommentCreateView(CreateView):
model = Comment
form_class = CommentForm
fields = ['content']
class CommentUpdateView(UpdateView):
model = CommentForm
fields = ['content']
#class CommentDeleteView(DeleteView):
# model = Comment
# success_url = reverse_lazy('author-list')
class CommentListIDView(JSONResponseMixin, AjaxResponseMixin, View):
model = Comment
def get_queryset(self, **kwargs):
post = Post.object.get(pk=self.kwargs['pk'])
return post.comments.filter(idname=self.kwargs['idname'])
def get_ajax(self, request, *args, **kwargs):
logger.info('%s, this is the ajax_get function from %s' % (self.__class__.__name__, self.__module__))
#query = request.GET.get('q')
#logger.info("get_ajax, Search results: %s from query: %s" % (utils.search_redis(query), query))
#res = utils.search_redis(query)
#logger.info("get_ajax, create_context_from_search_results: %s" % utils.create_context_from_search_results(res))
#return self.render_json_response(utils.create_context_from_search_results(res))
class CommentListView(JSONResponseMixin, AjaxResponseMixin, View):
model = Comment
def get_queryset(self, **kwargs):
post = Post.object.get(pk=self.kwargs['pk'])
return post.comments
def get_ajax(self, request, *args, **kwargs):
logger.info('%s, this is the ajax_get function from %s' % (self.__class__.__name__, self.__module__))
# class AddCommentView(LoginRequiredMixin, View):
# def post_ajax(self, request, *args, **kwargs):
# logger.info('%s, this is the post_ajax function from %s' % (self.__class__.__name__, self.__module__))
# return HttpResponse()
|
isc
|
[
646,
2050,
199,
504,
7975,
492,
6036,
199,
199,
504,
1639,
14,
17469,
492,
6183,
199,
504,
1639,
14,
17469,
492,
3795,
63,
475,
63,
1310,
465,
3795,
63,
475,
63,
4518,
199,
504,
1639,
14,
1160,
492,
22538,
199,
504,
1639,
14,
4196,
14,
6767,
492,
3820,
2768,
12,
13302,
2768,
12,
5458,
2768,
12,
10935,
199,
504,
1639,
14,
2828,
14,
1178,
14,
4196,
492,
4660,
63,
475,
63,
2886,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
199,
199,
504,
2199,
14,
4196,
14,
30192,
492,
4840,
2364,
4256,
12,
437,
15863,
2364,
4256,
12,
510,
15863,
2364,
4256,
12,
17897,
751,
8030,
4256,
12,
16430,
8030,
4256,
12,
25910,
751,
8030,
4256,
12,
4409,
63,
362,
12,
4409,
63,
1932,
199,
504,
19936,
14,
992,
492,
7711,
12,
7711,
1716,
12,
6819,
199,
504,
19936,
14,
3351,
14,
3351,
492,
6819,
2821,
199,
504,
19936,
14,
1208,
492,
32422,
15653,
199,
199,
2921,
275,
2050,
14,
5572,
360,
1715,
63,
2921,
358,
421,
199,
533,
3091,
6564,
6173,
4256,
8,
785,
304,
272,
949,
63,
1932,
63,
1188,
275,
283,
27143,
12,
949,
22238,
1911,
3530,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
408,
2372,
314,
1067,
367,
642,
2455,
14,
2654,
3091,
7711,
6430,
14,
408,
267,
1067,
275,
1613,
8,
1944,
6564,
6173,
4256,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
958,
9,
267,
1067,
14,
873,
3252,
889,
63,
1932,
63,
1328,
356,
277,
14,
889,
63,
1932,
63,
1188,
1552,
267,
372,
1067,
421,
199,
533,
19952,
379,
6564,
83,
4256,
8,
1944,
6564,
6173,
4256,
304,
272,
1402,
275,
7711,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
372,
291,
14,
1238,
14,
1462,
14,
6442,
342,
421,
199,
533,
19952,
379,
1899,
6564,
83,
4256,
8,
1944,
6564,
6173,
4256,
304,
272,
949,
63,
1932,
63,
1188,
275,
283,
27143,
12,
949,
22238,
1911,
367,
922,
26,
283,
272,
1402,
275,
7711,
339,
347,
664,
63,
7924,
8,
277,
12,
1011,
958,
304,
267,
291,
14,
889,
63,
1932,
63,
1188,
847,
291,
14,
958,
459,
2473,
418,
267,
372,
291,
14,
1238,
14,
1462,
14,
6442,
63,
991,
63,
751,
8,
751,
29,
277,
14,
958,
459,
2473,
1105,
421,
199,
533,
19952,
379,
15731,
6564,
83,
4256,
8,
1944,
6564,
6173,
4256,
304,
272,
949,
63,
1932,
63,
1188,
275,
283,
27143,
12,
949,
22238,
1911,
367,
5361,
26,
283,
272,
1402,
275,
7711,
2378,
347,
664,
63,
7924,
8,
277,
12,
1011,
958,
304,
267,
291,
14,
889,
63,
1932,
63,
1188,
847,
291,
14,
958,
459,
3403,
418,
267,
870,
291,
14,
889,
63,
1932,
63,
1188,
267,
372,
291,
14,
1238,
14,
1462,
14,
6442,
63,
991,
63,
3403,
8,
3403,
29,
277,
14,
958,
459,
3403,
1105,
421,
199,
533,
19952,
379,
7841,
6564,
83,
4256,
8,
1944,
6564,
6173,
4256,
304,
272,
949,
63,
1932,
63,
1188,
275,
283,
27143,
12,
949,
22238,
1911,
367,
4637,
26,
283,
272,
1402,
275,
7711,
339,
347,
664,
63,
7924,
8,
277,
12,
1011,
958,
304,
267,
291,
14,
889,
63,
1932,
63,
1188,
847,
291,
14,
958,
459,
3710,
418,
267,
372,
291,
14,
1238,
14,
1462,
14,
6442,
63,
991,
63,
3710,
8,
3710,
29,
277,
14,
958,
459,
3710,
1105,
421,
199,
3,
275,
21326,
10935,
83,
16248,
532,
327,
199,
533,
7711,
28539,
8,
27862,
6564,
83,
4256,
12,
13302,
2768,
304,
272,
986,
421,
199,
533,
7711,
23239,
8,
27862,
6564,
83,
4256,
12,
3820,
2768,
304,
2043,
986,
421,
199,
533,
7711,
1899,
23239,
8,
27862,
1899,
6564,
83,
4256,
12,
3820,
2768,
304,
272,
986,
421,
199,
533,
7711,
15731,
23239,
8,
27862,
15731,
6564,
83,
4256,
12,
3820,
2768,
304,
272,
986,
421,
199,
533,
7711,
7841,
23239,
8,
27862,
7841,
6564,
83,
4256,
12,
3820,
2768,
304,
272,
986,
199,
199,
3,
199,
3,
199,
3,
199,
3,
199,
3,
199,
3,
199,
3,
199,
3,
199,
3,
199,
3,
199,
3,
199,
4605,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1083,
63,
11547,
199,
199,
533,
437,
15863,
25921,
8880,
8030,
4256,
8,
785,
304,
272,
408,
272,
10935,
20048,
1314,
22694,
626,
314,
922,
965,
15082,
14,
5591,
437,
15863,
340,
440,
339,
6944,
26,
961,
1077,
506,
314,
3602,
13,
2786,
20048,
402,
282,
2455,
14,
272,
408,
339,
768,
765,
63,
11547,
8,
2886,
63,
2427,
9,
272,
347,
7634,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
1056,
63,
765,
275,
1056,
14,
765,
14,
2325,
342,
398,
340,
1056,
14,
374,
63,
12774,
342,
436,
1056,
63,
765,
315,
291,
14,
1014,
63,
765,
63,
1247,
26,
288,
3016,
275,
2519,
8,
277,
12,
1543,
83,
63,
12774,
7,
450,
1056,
63,
765,
12,
291,
14,
1014,
63,
765,
63,
1397,
63,
6541,
9,
288,
291,
14,
1069,
275,
1056,
288,
291,
14,
589,
275,
1249,
288,
291,
14,
958,
275,
2074,
288,
372,
3016,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
267,
587,
26,
288,
372,
1613,
8,
8880,
8030,
4256,
12,
291,
680,
6052,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
421,
199,
533,
437,
15863,
25921,
18963,
751,
8030,
4256,
8,
785,
304,
272,
408,
272,
10935,
20048,
1314,
22694,
626,
314,
922,
965,
15082,
14,
5591,
437,
15863,
340,
440,
339,
6944,
26,
961,
1077,
506,
314,
3602,
13,
2786,
20048,
402,
282,
2455,
14,
272,
408,
272,
4676,
63,
633,
275,
2202,
14,
17208,
63,
19747,
63,
2632,
221,
327,
5051,
568,
63,
2632,
687,
2199,
2202,
272,
746,
63,
1971,
275,
756,
221,
327,
3758,
3775,
370,
746,
376,
1919,
370,
7179,
272,
4660,
63,
698,
63,
354,
275,
283,
2184,
7,
221,
327,
2494,
701,
1639,
14,
2828,
14,
1178,
339,
347,
7634,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
1056,
14,
751
] |
[
2050,
199,
504,
7975,
492,
6036,
199,
199,
504,
1639,
14,
17469,
492,
6183,
199,
504,
1639,
14,
17469,
492,
3795,
63,
475,
63,
1310,
465,
3795,
63,
475,
63,
4518,
199,
504,
1639,
14,
1160,
492,
22538,
199,
504,
1639,
14,
4196,
14,
6767,
492,
3820,
2768,
12,
13302,
2768,
12,
5458,
2768,
12,
10935,
199,
504,
1639,
14,
2828,
14,
1178,
14,
4196,
492,
4660,
63,
475,
63,
2886,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
199,
199,
504,
2199,
14,
4196,
14,
30192,
492,
4840,
2364,
4256,
12,
437,
15863,
2364,
4256,
12,
510,
15863,
2364,
4256,
12,
17897,
751,
8030,
4256,
12,
16430,
8030,
4256,
12,
25910,
751,
8030,
4256,
12,
4409,
63,
362,
12,
4409,
63,
1932,
199,
504,
19936,
14,
992,
492,
7711,
12,
7711,
1716,
12,
6819,
199,
504,
19936,
14,
3351,
14,
3351,
492,
6819,
2821,
199,
504,
19936,
14,
1208,
492,
32422,
15653,
199,
199,
2921,
275,
2050,
14,
5572,
360,
1715,
63,
2921,
358,
421,
199,
533,
3091,
6564,
6173,
4256,
8,
785,
304,
272,
949,
63,
1932,
63,
1188,
275,
283,
27143,
12,
949,
22238,
1911,
3530,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
408,
2372,
314,
1067,
367,
642,
2455,
14,
2654,
3091,
7711,
6430,
14,
408,
267,
1067,
275,
1613,
8,
1944,
6564,
6173,
4256,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
958,
9,
267,
1067,
14,
873,
3252,
889,
63,
1932,
63,
1328,
356,
277,
14,
889,
63,
1932,
63,
1188,
1552,
267,
372,
1067,
421,
199,
533,
19952,
379,
6564,
83,
4256,
8,
1944,
6564,
6173,
4256,
304,
272,
1402,
275,
7711,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
372,
291,
14,
1238,
14,
1462,
14,
6442,
342,
421,
199,
533,
19952,
379,
1899,
6564,
83,
4256,
8,
1944,
6564,
6173,
4256,
304,
272,
949,
63,
1932,
63,
1188,
275,
283,
27143,
12,
949,
22238,
1911,
367,
922,
26,
283,
272,
1402,
275,
7711,
339,
347,
664,
63,
7924,
8,
277,
12,
1011,
958,
304,
267,
291,
14,
889,
63,
1932,
63,
1188,
847,
291,
14,
958,
459,
2473,
418,
267,
372,
291,
14,
1238,
14,
1462,
14,
6442,
63,
991,
63,
751,
8,
751,
29,
277,
14,
958,
459,
2473,
1105,
421,
199,
533,
19952,
379,
15731,
6564,
83,
4256,
8,
1944,
6564,
6173,
4256,
304,
272,
949,
63,
1932,
63,
1188,
275,
283,
27143,
12,
949,
22238,
1911,
367,
5361,
26,
283,
272,
1402,
275,
7711,
2378,
347,
664,
63,
7924,
8,
277,
12,
1011,
958,
304,
267,
291,
14,
889,
63,
1932,
63,
1188,
847,
291,
14,
958,
459,
3403,
418,
267,
870,
291,
14,
889,
63,
1932,
63,
1188,
267,
372,
291,
14,
1238,
14,
1462,
14,
6442,
63,
991,
63,
3403,
8,
3403,
29,
277,
14,
958,
459,
3403,
1105,
421,
199,
533,
19952,
379,
7841,
6564,
83,
4256,
8,
1944,
6564,
6173,
4256,
304,
272,
949,
63,
1932,
63,
1188,
275,
283,
27143,
12,
949,
22238,
1911,
367,
4637,
26,
283,
272,
1402,
275,
7711,
339,
347,
664,
63,
7924,
8,
277,
12,
1011,
958,
304,
267,
291,
14,
889,
63,
1932,
63,
1188,
847,
291,
14,
958,
459,
3710,
418,
267,
372,
291,
14,
1238,
14,
1462,
14,
6442,
63,
991,
63,
3710,
8,
3710,
29,
277,
14,
958,
459,
3710,
1105,
421,
199,
3,
275,
21326,
10935,
83,
16248,
532,
327,
199,
533,
7711,
28539,
8,
27862,
6564,
83,
4256,
12,
13302,
2768,
304,
272,
986,
421,
199,
533,
7711,
23239,
8,
27862,
6564,
83,
4256,
12,
3820,
2768,
304,
2043,
986,
421,
199,
533,
7711,
1899,
23239,
8,
27862,
1899,
6564,
83,
4256,
12,
3820,
2768,
304,
272,
986,
421,
199,
533,
7711,
15731,
23239,
8,
27862,
15731,
6564,
83,
4256,
12,
3820,
2768,
304,
272,
986,
421,
199,
533,
7711,
7841,
23239,
8,
27862,
7841,
6564,
83,
4256,
12,
3820,
2768,
304,
272,
986,
199,
199,
3,
199,
3,
199,
3,
199,
3,
199,
3,
199,
3,
199,
3,
199,
3,
199,
3,
199,
3,
199,
3,
199,
4605,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1083,
63,
11547,
199,
199,
533,
437,
15863,
25921,
8880,
8030,
4256,
8,
785,
304,
272,
408,
272,
10935,
20048,
1314,
22694,
626,
314,
922,
965,
15082,
14,
5591,
437,
15863,
340,
440,
339,
6944,
26,
961,
1077,
506,
314,
3602,
13,
2786,
20048,
402,
282,
2455,
14,
272,
408,
339,
768,
765,
63,
11547,
8,
2886,
63,
2427,
9,
272,
347,
7634,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
1056,
63,
765,
275,
1056,
14,
765,
14,
2325,
342,
398,
340,
1056,
14,
374,
63,
12774,
342,
436,
1056,
63,
765,
315,
291,
14,
1014,
63,
765,
63,
1247,
26,
288,
3016,
275,
2519,
8,
277,
12,
1543,
83,
63,
12774,
7,
450,
1056,
63,
765,
12,
291,
14,
1014,
63,
765,
63,
1397,
63,
6541,
9,
288,
291,
14,
1069,
275,
1056,
288,
291,
14,
589,
275,
1249,
288,
291,
14,
958,
275,
2074,
288,
372,
3016,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
267,
587,
26,
288,
372,
1613,
8,
8880,
8030,
4256,
12,
291,
680,
6052,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
421,
199,
533,
437,
15863,
25921,
18963,
751,
8030,
4256,
8,
785,
304,
272,
408,
272,
10935,
20048,
1314,
22694,
626,
314,
922,
965,
15082,
14,
5591,
437,
15863,
340,
440,
339,
6944,
26,
961,
1077,
506,
314,
3602,
13,
2786,
20048,
402,
282,
2455,
14,
272,
408,
272,
4676,
63,
633,
275,
2202,
14,
17208,
63,
19747,
63,
2632,
221,
327,
5051,
568,
63,
2632,
687,
2199,
2202,
272,
746,
63,
1971,
275,
756,
221,
327,
3758,
3775,
370,
746,
376,
1919,
370,
7179,
272,
4660,
63,
698,
63,
354,
275,
283,
2184,
7,
221,
327,
2494,
701,
1639,
14,
2828,
14,
1178,
339,
347,
7634,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
1056,
14,
751,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pechatny/basic-flask-app
|
src/app/flask/lib/python2.7/site-packages/pip/util.py
|
343
|
24172
|
import sys
import shutil
import os
import stat
import re
import posixpath
import zipfile
import tarfile
import subprocess
import textwrap
from pip.exceptions import InstallationError, BadCommand, PipError
from pip.backwardcompat import(WindowsError, string_types, raw_input,
console_to_str, user_site, PermissionError)
from pip.locations import site_packages, running_under_virtualenv, virtualenv_no_global
from pip.log import logger
from pip._vendor import pkg_resources
from pip._vendor.distlib import version
__all__ = ['rmtree', 'display_path', 'backup_dir',
'find_command', 'ask', 'Inf',
'normalize_name', 'splitext',
'format_size', 'is_installable_dir',
'is_svn_page', 'file_contents',
'split_leading_dir', 'has_leading_dir',
'make_path_relative', 'normalize_path',
'renames', 'get_terminal_size', 'get_prog',
'unzip_file', 'untar_file', 'create_download_cache_folder',
'cache_download', 'unpack_file', 'call_subprocess']
def get_prog():
try:
if os.path.basename(sys.argv[0]) in ('__main__.py', '-c'):
return "%s -m pip" % sys.executable
except (AttributeError, TypeError, IndexError):
pass
return 'pip'
def rmtree(dir, ignore_errors=False):
shutil.rmtree(dir, ignore_errors=ignore_errors,
onerror=rmtree_errorhandler)
def rmtree_errorhandler(func, path, exc_info):
"""On Windows, the files in .svn are read-only, so when rmtree() tries to
remove them, an exception is thrown. We catch that here, remove the
read-only attribute, and hopefully continue without problems."""
exctype, value = exc_info[:2]
if not ((exctype is WindowsError and value.args[0] == 5) or #others
(exctype is OSError and value.args[0] == 13) or #python2.4
(exctype is PermissionError and value.args[3] == 5) #python3.3
):
raise
# file type should currently be read only
if ((os.stat(path).st_mode & stat.S_IREAD) != stat.S_IREAD):
raise
# convert to read/write
os.chmod(path, stat.S_IWRITE)
# use the original function to repeat the operation
func(path)
def display_path(path):
"""Gives the display value for a given path, making it relative to cwd
if possible."""
path = os.path.normcase(os.path.abspath(path))
if path.startswith(os.getcwd() + os.path.sep):
path = '.' + path[len(os.getcwd()):]
return path
def backup_dir(dir, ext='.bak'):
"""Figure out the name of a directory to back up the given dir to
(adding .bak, .bak2, etc)"""
n = 1
extension = ext
while os.path.exists(dir + extension):
n += 1
extension = ext + str(n)
return dir + extension
def find_command(cmd, paths=None, pathext=None):
"""Searches the PATH for the given command and returns its path"""
if paths is None:
paths = os.environ.get('PATH', '').split(os.pathsep)
if isinstance(paths, string_types):
paths = [paths]
# check if there are funny path extensions for executables, e.g. Windows
if pathext is None:
pathext = get_pathext()
pathext = [ext for ext in pathext.lower().split(os.pathsep) if len(ext)]
# don't use extensions if the command ends with one of them
if os.path.splitext(cmd)[1].lower() in pathext:
pathext = ['']
# check if we find the command on PATH
for path in paths:
# try without extension first
cmd_path = os.path.join(path, cmd)
for ext in pathext:
# then including the extension
cmd_path_ext = cmd_path + ext
if os.path.isfile(cmd_path_ext):
return cmd_path_ext
if os.path.isfile(cmd_path):
return cmd_path
raise BadCommand('Cannot find command %r' % cmd)
def get_pathext(default_pathext=None):
"""Returns the path extensions from environment or a default"""
if default_pathext is None:
default_pathext = os.pathsep.join(['.COM', '.EXE', '.BAT', '.CMD'])
pathext = os.environ.get('PATHEXT', default_pathext)
return pathext
def ask_path_exists(message, options):
for action in os.environ.get('PIP_EXISTS_ACTION', '').split():
if action in options:
return action
return ask(message, options)
def ask(message, options):
"""Ask the message interactively, with the given possible responses"""
while 1:
if os.environ.get('PIP_NO_INPUT'):
raise Exception('No input was expected ($PIP_NO_INPUT set); question: %s' % message)
response = raw_input(message)
response = response.strip().lower()
if response not in options:
print('Your response (%r) was not one of the expected responses: %s' % (
response, ', '.join(options)))
else:
return response
class _Inf(object):
"""I am bigger than everything!"""
def __eq__(self, other):
if self is other:
return True
else:
return False
def __ne__(self, other):
return not self.__eq__(other)
def __lt__(self, other):
return False
def __le__(self, other):
return False
def __gt__(self, other):
return True
def __ge__(self, other):
return True
def __repr__(self):
return 'Inf'
Inf = _Inf() #this object is not currently used as a sortable in our code
del _Inf
_normalize_re = re.compile(r'[^a-z]', re.I)
def normalize_name(name):
return _normalize_re.sub('-', name.lower())
def format_size(bytes):
if bytes > 1000*1000:
return '%.1fMB' % (bytes/1000.0/1000)
elif bytes > 10*1000:
return '%ikB' % (bytes/1000)
elif bytes > 1000:
return '%.1fkB' % (bytes/1000.0)
else:
return '%ibytes' % bytes
def is_installable_dir(path):
"""Return True if `path` is a directory containing a setup.py file."""
if not os.path.isdir(path):
return False
setup_py = os.path.join(path, 'setup.py')
if os.path.isfile(setup_py):
return True
return False
def is_svn_page(html):
"""Returns true if the page appears to be the index page of an svn repository"""
return (re.search(r'<title>[^<]*Revision \d+:', html)
and re.search(r'Powered by (?:<a[^>]*?>)?Subversion', html, re.I))
def file_contents(filename):
fp = open(filename, 'rb')
try:
return fp.read().decode('utf-8')
finally:
fp.close()
def split_leading_dir(path):
path = str(path)
path = path.lstrip('/').lstrip('\\')
if '/' in path and (('\\' in path and path.find('/') < path.find('\\'))
or '\\' not in path):
return path.split('/', 1)
elif '\\' in path:
return path.split('\\', 1)
else:
return path, ''
def has_leading_dir(paths):
"""Returns true if all the paths have the same leading path name
(i.e., everything is in one subdirectory in an archive)"""
common_prefix = None
for path in paths:
prefix, rest = split_leading_dir(path)
if not prefix:
return False
elif common_prefix is None:
common_prefix = prefix
elif prefix != common_prefix:
return False
return True
def make_path_relative(path, rel_to):
"""
Make a filename relative, where the filename path, and it is
relative to rel_to
>>> make_relative_path('/usr/share/something/a-file.pth',
... '/usr/share/another-place/src/Directory')
'../../../something/a-file.pth'
>>> make_relative_path('/usr/share/something/a-file.pth',
... '/home/user/src/Directory')
'../../../usr/share/something/a-file.pth'
>>> make_relative_path('/usr/share/a-file.pth', '/usr/share/')
'a-file.pth'
"""
path_filename = os.path.basename(path)
path = os.path.dirname(path)
path = os.path.normpath(os.path.abspath(path))
rel_to = os.path.normpath(os.path.abspath(rel_to))
path_parts = path.strip(os.path.sep).split(os.path.sep)
rel_to_parts = rel_to.strip(os.path.sep).split(os.path.sep)
while path_parts and rel_to_parts and path_parts[0] == rel_to_parts[0]:
path_parts.pop(0)
rel_to_parts.pop(0)
full_parts = ['..']*len(rel_to_parts) + path_parts + [path_filename]
if full_parts == ['']:
return '.' + os.path.sep
return os.path.sep.join(full_parts)
def normalize_path(path):
"""
Convert a path to its canonical, case-normalized, absolute version.
"""
return os.path.normcase(os.path.realpath(os.path.expanduser(path)))
def splitext(path):
"""Like os.path.splitext, but take off .tar too"""
base, ext = posixpath.splitext(path)
if base.lower().endswith('.tar'):
ext = base[-4:] + ext
base = base[:-4]
return base, ext
def renames(old, new):
"""Like os.renames(), but handles renaming across devices."""
# Implementation borrowed from os.renames().
head, tail = os.path.split(new)
if head and tail and not os.path.exists(head):
os.makedirs(head)
shutil.move(old, new)
head, tail = os.path.split(old)
if head and tail:
try:
os.removedirs(head)
except OSError:
pass
def is_local(path):
"""
Return True if path is within sys.prefix, if we're running in a virtualenv.
If we're not in a virtualenv, all paths are considered "local."
"""
if not running_under_virtualenv():
return True
return normalize_path(path).startswith(normalize_path(sys.prefix))
def dist_is_local(dist):
"""
Return True if given Distribution object is installed locally
(i.e. within current virtualenv).
Always True if we're not in a virtualenv.
"""
return is_local(dist_location(dist))
def dist_in_usersite(dist):
"""
Return True if given Distribution is installed in user site.
"""
if user_site:
return normalize_path(dist_location(dist)).startswith(normalize_path(user_site))
else:
return False
def dist_in_site_packages(dist):
"""
Return True if given Distribution is installed in distutils.sysconfig.get_python_lib().
"""
return normalize_path(dist_location(dist)).startswith(normalize_path(site_packages))
def dist_is_editable(dist):
"""Is distribution an editable install?"""
#TODO: factor out determining editableness out of FrozenRequirement
from pip import FrozenRequirement
req = FrozenRequirement.from_dist(dist, [])
return req.editable
def get_installed_distributions(local_only=True,
skip=('setuptools', 'pip', 'python', 'distribute'),
include_editables=True,
editables_only=False):
"""
Return a list of installed Distribution objects.
If ``local_only`` is True (default), only return installations
local to the current virtualenv, if in a virtualenv.
``skip`` argument is an iterable of lower-case project names to
ignore; defaults to ('setuptools', 'pip', 'python'). [FIXME also
skip virtualenv?]
If ``editables`` is False, don't report editables.
If ``editables_only`` is True , only report editables.
"""
if local_only:
local_test = dist_is_local
else:
local_test = lambda d: True
if include_editables:
editable_test = lambda d: True
else:
editable_test = lambda d: not dist_is_editable(d)
if editables_only:
editables_only_test = lambda d: dist_is_editable(d)
else:
editables_only_test = lambda d: True
return [d for d in pkg_resources.working_set
if local_test(d)
and d.key not in skip
and editable_test(d)
and editables_only_test(d)
]
def egg_link_path(dist):
"""
Return the path for the .egg-link file if it exists, otherwise, None.
There's 3 scenarios:
1) not in a virtualenv
try to find in site.USER_SITE, then site_packages
2) in a no-global virtualenv
try to find in site_packages
3) in a yes-global virtualenv
try to find in site_packages, then site.USER_SITE (don't look in global location)
For #1 and #3, there could be odd cases, where there's an egg-link in 2 locations.
This method will just return the first one found.
"""
sites = []
if running_under_virtualenv():
if virtualenv_no_global():
sites.append(site_packages)
else:
sites.append(site_packages)
if user_site:
sites.append(user_site)
else:
if user_site:
sites.append(user_site)
sites.append(site_packages)
for site in sites:
egglink = os.path.join(site, dist.project_name) + '.egg-link'
if os.path.isfile(egglink):
return egglink
def dist_location(dist):
"""
Get the site-packages location of this distribution. Generally
this is dist.location, except in the case of develop-installed
packages, where dist.location is the source code location, and we
want to know where the egg-link file is.
"""
egg_link = egg_link_path(dist)
if egg_link:
return egg_link
return dist.location
def get_terminal_size():
"""Returns a tuple (x, y) representing the width(x) and the height(x)
in characters of the terminal window."""
def ioctl_GWINSZ(fd):
try:
import fcntl
import termios
import struct
cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,
'1234'))
except:
return None
if cr == (0, 0):
return None
if cr == (0, 0):
return None
return cr
cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
if not cr:
try:
fd = os.open(os.ctermid(), os.O_RDONLY)
cr = ioctl_GWINSZ(fd)
os.close(fd)
except:
pass
if not cr:
cr = (os.environ.get('LINES', 25), os.environ.get('COLUMNS', 80))
return int(cr[1]), int(cr[0])
def current_umask():
"""Get the current umask which involves having to set it temporarily."""
mask = os.umask(0)
os.umask(mask)
return mask
def unzip_file(filename, location, flatten=True):
"""
Unzip the file (with path `filename`) to the destination `location`. All
files are written based on system defaults and umask (i.e. permissions are
not preserved), except that regular file members with any execute
permissions (user, group, or world) have "chmod +x" applied after being
written. Note that for windows, any execute changes using os.chmod are
no-ops per the python docs.
"""
if not os.path.exists(location):
os.makedirs(location)
zipfp = open(filename, 'rb')
try:
zip = zipfile.ZipFile(zipfp)
leading = has_leading_dir(zip.namelist()) and flatten
for info in zip.infolist():
name = info.filename
data = zip.read(name)
fn = name
if leading:
fn = split_leading_dir(name)[1]
fn = os.path.join(location, fn)
dir = os.path.dirname(fn)
if not os.path.exists(dir):
os.makedirs(dir)
if fn.endswith('/') or fn.endswith('\\'):
# A directory
if not os.path.exists(fn):
os.makedirs(fn)
else:
fp = open(fn, 'wb')
try:
fp.write(data)
finally:
fp.close()
mode = info.external_attr >> 16
# if mode and regular file and any execute permissions for user/group/world?
if mode and stat.S_ISREG(mode) and mode & 0o111:
# make dest file have execute for user/group/world (chmod +x)
# no-op on windows per python docs
os.chmod(fn, (0o777-current_umask() | 0o111))
finally:
zipfp.close()
def untar_file(filename, location):
"""
Untar the file (with path `filename`) to the destination `location`.
All files are written based on system defaults and umask (i.e. permissions
are not preserved), except that regular file members with any execute
permissions (user, group, or world) have "chmod +x" applied after being
written. Note that for windows, any execute changes using os.chmod are
no-ops per the python docs.
"""
if not os.path.exists(location):
os.makedirs(location)
if filename.lower().endswith('.gz') or filename.lower().endswith('.tgz'):
mode = 'r:gz'
elif filename.lower().endswith('.bz2') or filename.lower().endswith('.tbz'):
mode = 'r:bz2'
elif filename.lower().endswith('.tar'):
mode = 'r'
else:
logger.warn('Cannot determine compression type for file %s' % filename)
mode = 'r:*'
tar = tarfile.open(filename, mode)
try:
# note: python<=2.5 doesnt seem to know about pax headers, filter them
leading = has_leading_dir([
member.name for member in tar.getmembers()
if member.name != 'pax_global_header'
])
for member in tar.getmembers():
fn = member.name
if fn == 'pax_global_header':
continue
if leading:
fn = split_leading_dir(fn)[1]
path = os.path.join(location, fn)
if member.isdir():
if not os.path.exists(path):
os.makedirs(path)
elif member.issym():
try:
tar._extract_member(member, path)
except:
e = sys.exc_info()[1]
# Some corrupt tar files seem to produce this
# (specifically bad symlinks)
logger.warn(
'In the tar file %s the member %s is invalid: %s'
% (filename, member.name, e))
continue
else:
try:
fp = tar.extractfile(member)
except (KeyError, AttributeError):
e = sys.exc_info()[1]
# Some corrupt tar files seem to produce this
# (specifically bad symlinks)
logger.warn(
'In the tar file %s the member %s is invalid: %s'
% (filename, member.name, e))
continue
if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
destfp = open(path, 'wb')
try:
shutil.copyfileobj(fp, destfp)
finally:
destfp.close()
fp.close()
# member have any execute permissions for user/group/world?
if member.mode & 0o111:
# make dest file have execute for user/group/world
# no-op on windows per python docs
os.chmod(path, (0o777-current_umask() | 0o111))
finally:
tar.close()
def create_download_cache_folder(folder):
logger.indent -= 2
logger.notify('Creating supposed download cache at %s' % folder)
logger.indent += 2
os.makedirs(folder)
def cache_download(target_file, temp_location, content_type):
logger.notify('Storing download in cache at %s' % display_path(target_file))
shutil.copyfile(temp_location, target_file)
fp = open(target_file+'.content-type', 'w')
fp.write(content_type)
fp.close()
def unpack_file(filename, location, content_type, link):
filename = os.path.realpath(filename)
if (content_type == 'application/zip'
or filename.endswith('.zip')
or filename.endswith('.pybundle')
or filename.endswith('.whl')
or zipfile.is_zipfile(filename)):
unzip_file(filename, location, flatten=not filename.endswith(('.pybundle', '.whl')))
elif (content_type == 'application/x-gzip'
or tarfile.is_tarfile(filename)
or splitext(filename)[1].lower() in ('.tar', '.tar.gz', '.tar.bz2', '.tgz', '.tbz')):
untar_file(filename, location)
elif (content_type and content_type.startswith('text/html')
and is_svn_page(file_contents(filename))):
# We don't really care about this
from pip.vcs.subversion import Subversion
Subversion('svn+' + link.url).unpack(location)
else:
## FIXME: handle?
## FIXME: magic signatures?
logger.fatal('Cannot unpack file %s (downloaded from %s, content-type: %s); cannot detect archive format'
% (filename, location, content_type))
raise InstallationError('Cannot determine archive format of %s' % location)
def call_subprocess(cmd, show_stdout=True,
filter_stdout=None, cwd=None,
raise_on_returncode=True,
command_level=logger.DEBUG, command_desc=None,
extra_environ=None):
if command_desc is None:
cmd_parts = []
for part in cmd:
if ' ' in part or '\n' in part or '"' in part or "'" in part:
part = '"%s"' % part.replace('"', '\\"')
cmd_parts.append(part)
command_desc = ' '.join(cmd_parts)
if show_stdout:
stdout = None
else:
stdout = subprocess.PIPE
logger.log(command_level, "Running command %s" % command_desc)
env = os.environ.copy()
if extra_environ:
env.update(extra_environ)
try:
proc = subprocess.Popen(
cmd, stderr=subprocess.STDOUT, stdin=None, stdout=stdout,
cwd=cwd, env=env)
except Exception:
e = sys.exc_info()[1]
logger.fatal(
"Error %s while executing command %s" % (e, command_desc))
raise
all_output = []
if stdout is not None:
stdout = proc.stdout
while 1:
line = console_to_str(stdout.readline())
if not line:
break
line = line.rstrip()
all_output.append(line + '\n')
if filter_stdout:
level = filter_stdout(line)
if isinstance(level, tuple):
level, line = level
logger.log(level, line)
if not logger.stdout_level_matches(level):
logger.show_progress()
else:
logger.info(line)
else:
returned_stdout, returned_stderr = proc.communicate()
all_output = [returned_stdout or '']
proc.wait()
if proc.returncode:
if raise_on_returncode:
if all_output:
logger.notify('Complete output from command %s:' % command_desc)
logger.notify('\n'.join(all_output) + '\n----------------------------------------')
raise InstallationError(
"Command %s failed with error code %s in %s"
% (command_desc, proc.returncode, cwd))
else:
logger.warn(
"Command %s had error code %s in %s"
% (command_desc, proc.returncode, cwd))
if stdout is not None:
return ''.join(all_output)
def is_prerelease(vers):
"""
Attempt to determine if this is a pre-release using PEP386/PEP426 rules.
Will return True if it is a pre-release and False if not. Versions are
assumed to be a pre-release if they cannot be parsed.
"""
normalized = version._suggest_normalized_version(vers)
if normalized is None:
# Cannot normalize, assume it is a pre-release
return True
parsed = version._normalized_key(normalized)
return any([any([y in set(["a", "b", "c", "rc", "dev"]) for y in x]) for x in parsed])
|
mit
|
[
646,
984,
199,
646,
5145,
199,
646,
747,
199,
646,
5672,
199,
646,
295,
199,
646,
15454,
199,
646,
10392,
199,
646,
13608,
199,
646,
3873,
199,
646,
13390,
199,
199,
504,
7305,
14,
3924,
492,
26866,
547,
12,
8857,
3110,
12,
510,
711,
547,
199,
504,
7305,
14,
15457,
5819,
492,
8,
8647,
547,
12,
1059,
63,
1313,
12,
3066,
63,
1210,
12,
1816,
8559,
63,
475,
63,
495,
12,
922,
63,
2124,
12,
8779,
547,
9,
199,
504,
7305,
14,
8022,
492,
4770,
63,
5154,
12,
3879,
63,
7138,
63,
21611,
12,
19128,
63,
889,
63,
2966,
199,
504,
7305,
14,
793,
492,
2512,
199,
504,
7305,
423,
9884,
492,
5496,
63,
4435,
199,
504,
7305,
423,
9884,
14,
2686,
773,
492,
1015,
199,
199,
363,
452,
363,
275,
788,
9242,
297,
283,
2918,
63,
515,
297,
283,
5751,
63,
694,
297,
1779,
283,
1623,
63,
1531,
297,
283,
813,
297,
283,
17354,
297,
1779,
283,
7721,
63,
354,
297,
283,
7973,
297,
1779,
283,
908,
63,
890,
297,
283,
374,
63,
21762,
63,
694,
297,
1779,
283,
374,
63,
6836,
63,
1606,
297,
283,
493,
63,
4407,
297,
1779,
283,
1294,
63,
16812,
63,
694,
297,
283,
1989,
63,
16812,
63,
694,
297,
1779,
283,
1875,
63,
515,
63,
6188,
297,
283,
7721,
63,
515,
297,
1779,
283,
264,
1247,
297,
283,
362,
63,
12010,
63,
890,
297,
283,
362,
63,
6595,
297,
1779,
283,
26700,
63,
493,
297,
283,
638,
285,
63,
493,
297,
283,
981,
63,
4249,
63,
1637,
63,
3741,
297,
1779,
283,
1637,
63,
4249,
297,
283,
5301,
63,
493,
297,
283,
1250,
63,
5781,
418,
421,
199,
318,
664,
63,
6595,
837,
272,
862,
26,
267,
340,
747,
14,
515,
14,
4846,
8,
1274,
14,
3020,
59,
16,
566,
315,
25038,
973,
4343,
647,
297,
2475,
67,
735,
288,
372,
2071,
83,
446,
77,
7305,
2,
450,
984,
14,
5904,
272,
871,
334,
10227,
12,
3146,
12,
7888,
304,
267,
986,
272,
372,
283,
9983,
7,
421,
199,
318,
20978,
8,
694,
12,
3686,
63,
2550,
29,
797,
304,
272,
5145,
14,
9242,
8,
694,
12,
3686,
63,
2550,
29,
4247,
63,
2550,
12,
2116,
22852,
29,
9242,
63,
705,
2232,
9,
421,
199,
318,
20978,
63,
705,
2232,
8,
1532,
12,
931,
12,
3178,
63,
815,
304,
272,
408,
3314,
5417,
12,
314,
1584,
315,
1275,
6836,
787,
1586,
13,
2118,
12,
880,
1380,
20978,
342,
11275,
370,
272,
2813,
3062,
12,
376,
1919,
365,
14031,
14,
221,
2136,
8579,
626,
2348,
12,
2813,
314,
272,
1586,
13,
2118,
2225,
12,
436,
3661,
5836,
1980,
1928,
8826,
1041,
272,
444,
3667,
12,
574,
275,
3178,
63,
815,
1491,
18,
61,
272,
340,
440,
3666,
476,
3667,
365,
23950,
436,
574,
14,
589,
59,
16,
61,
508,
959,
9,
503,
327,
21714,
288,
334,
476,
3667,
365,
6440,
436,
574,
14,
589,
59,
16,
61,
508,
4944,
9,
503,
327,
1548,
18,
14,
20,
288,
334,
476,
3667,
365,
8779,
547,
436,
574,
14,
589,
59,
19,
61,
508,
959,
9,
327,
1548,
19,
14,
19,
288,
3461,
267,
746,
272,
327,
570,
730,
1077,
5544,
506,
1586,
1454,
272,
340,
3666,
736,
14,
3736,
8,
515,
680,
270,
63,
632,
1253,
5672,
14,
51,
63,
41,
5670,
9,
1137,
5672,
14,
51,
63,
41,
5670,
304,
267,
746,
272,
327,
3957,
370,
1586,
15,
952,
272,
747,
14,
11693,
8,
515,
12,
5672,
14,
51,
63,
41,
10387,
9,
272,
327,
675,
314,
3379,
805,
370,
11982,
314,
3439,
272,
2562,
8,
515,
9,
421,
199,
318,
2929,
63,
515,
8,
515,
304,
272,
408,
39,
7602,
314,
2929,
574,
367,
282,
1627,
931,
12,
10663,
652,
3847,
370,
8288,
272,
340,
3962,
1041,
272,
931,
275,
747,
14,
515,
14,
21288,
8,
736,
14,
515,
14,
4832,
8,
515,
430,
272,
340,
931,
14,
2460,
8,
736,
14,
9458,
342,
435,
747,
14,
515,
14,
4127,
304,
267,
931,
275,
7815,
435,
931,
59,
552,
8,
736,
14,
9458,
5109,
61,
272,
372,
931,
421,
199,
318,
6902,
63,
694,
8,
694,
12,
1599,
15637,
27162,
735,
272,
408,
25590,
734,
314,
536,
402,
282,
2082,
370,
1771,
1536,
314,
1627,
2935,
370,
272,
334,
4095,
1275,
27162,
12,
1275,
27162,
18,
12,
5423,
9471,
272,
302,
275,
413,
272,
3329,
275,
1599,
272,
1830,
747,
14,
515,
14,
2444,
8,
694,
435,
3329,
304,
267,
302,
847,
413,
267,
3329,
275,
1599,
435,
620,
8,
78,
9,
272,
372,
2935,
435,
3329,
421,
199,
318,
2342,
63,
1531,
8,
1760,
12,
3792,
29,
403,
12,
931,
832,
29,
403,
304,
272,
408,
5278,
397,
314,
15097,
367,
314,
1627,
1414,
436,
2529,
2399,
931,
624,
272,
340,
3792,
365,
488,
26,
267,
3792,
275,
747,
14,
2314,
14,
362,
360,
3243,
297,
12548,
1294,
8,
736,
14,
17843,
9,
272,
340,
1228,
8,
3771,
12,
1059,
63,
1313,
304,
267,
3792,
275,
359,
3771,
61,
272,
327,
1104,
340,
2337,
787,
9627,
9745,
931,
5478,
367,
31172,
12,
325,
14,
71,
14,
5417,
272,
340,
931,
832,
365,
488,
26,
267,
931,
832,
275,
664,
63,
515,
832,
342,
272,
931,
832,
275,
359,
832,
367,
1599,
315,
931,
832,
14,
2325,
1252,
1294,
8,
736,
14,
17843,
9,
340,
822,
8,
832,
1874,
272,
327,
2793,
1133,
675,
5478,
340,
314,
1414,
11187,
543,
1373,
402,
3062,
272,
340,
747,
14,
515,
14,
7973,
8,
1760,
2788,
17,
1055,
2325,
342,
315,
931,
832,
26,
267,
931,
832,
275,
24506,
272,
327,
1104,
340,
781,
2342,
314,
1414,
641,
15097,
272,
367,
931,
315,
3792,
26,
267,
327,
862,
1928,
3329,
1642,
267,
2088,
63,
515,
275,
747,
14,
515,
14,
904,
8,
515,
12,
2088,
9,
267,
367,
1599,
315,
931,
832,
26,
288,
327,
2066,
5893,
314,
3329,
288,
2088,
63,
515,
63,
832,
275,
2088,
63,
515,
435,
1599,
288,
340,
747,
14,
515,
14,
6292,
8,
1760,
63,
515,
63,
832,
304,
355,
372,
2088,
63,
515,
63,
832,
267,
340,
747,
14,
515,
14,
6292,
8,
1760,
63,
515,
304,
288,
372,
2088,
63,
515,
272,
746
] |
[
984,
199,
646,
5145,
199,
646,
747,
199,
646,
5672,
199,
646,
295,
199,
646,
15454,
199,
646,
10392,
199,
646,
13608,
199,
646,
3873,
199,
646,
13390,
199,
199,
504,
7305,
14,
3924,
492,
26866,
547,
12,
8857,
3110,
12,
510,
711,
547,
199,
504,
7305,
14,
15457,
5819,
492,
8,
8647,
547,
12,
1059,
63,
1313,
12,
3066,
63,
1210,
12,
1816,
8559,
63,
475,
63,
495,
12,
922,
63,
2124,
12,
8779,
547,
9,
199,
504,
7305,
14,
8022,
492,
4770,
63,
5154,
12,
3879,
63,
7138,
63,
21611,
12,
19128,
63,
889,
63,
2966,
199,
504,
7305,
14,
793,
492,
2512,
199,
504,
7305,
423,
9884,
492,
5496,
63,
4435,
199,
504,
7305,
423,
9884,
14,
2686,
773,
492,
1015,
199,
199,
363,
452,
363,
275,
788,
9242,
297,
283,
2918,
63,
515,
297,
283,
5751,
63,
694,
297,
1779,
283,
1623,
63,
1531,
297,
283,
813,
297,
283,
17354,
297,
1779,
283,
7721,
63,
354,
297,
283,
7973,
297,
1779,
283,
908,
63,
890,
297,
283,
374,
63,
21762,
63,
694,
297,
1779,
283,
374,
63,
6836,
63,
1606,
297,
283,
493,
63,
4407,
297,
1779,
283,
1294,
63,
16812,
63,
694,
297,
283,
1989,
63,
16812,
63,
694,
297,
1779,
283,
1875,
63,
515,
63,
6188,
297,
283,
7721,
63,
515,
297,
1779,
283,
264,
1247,
297,
283,
362,
63,
12010,
63,
890,
297,
283,
362,
63,
6595,
297,
1779,
283,
26700,
63,
493,
297,
283,
638,
285,
63,
493,
297,
283,
981,
63,
4249,
63,
1637,
63,
3741,
297,
1779,
283,
1637,
63,
4249,
297,
283,
5301,
63,
493,
297,
283,
1250,
63,
5781,
418,
421,
199,
318,
664,
63,
6595,
837,
272,
862,
26,
267,
340,
747,
14,
515,
14,
4846,
8,
1274,
14,
3020,
59,
16,
566,
315,
25038,
973,
4343,
647,
297,
2475,
67,
735,
288,
372,
2071,
83,
446,
77,
7305,
2,
450,
984,
14,
5904,
272,
871,
334,
10227,
12,
3146,
12,
7888,
304,
267,
986,
272,
372,
283,
9983,
7,
421,
199,
318,
20978,
8,
694,
12,
3686,
63,
2550,
29,
797,
304,
272,
5145,
14,
9242,
8,
694,
12,
3686,
63,
2550,
29,
4247,
63,
2550,
12,
2116,
22852,
29,
9242,
63,
705,
2232,
9,
421,
199,
318,
20978,
63,
705,
2232,
8,
1532,
12,
931,
12,
3178,
63,
815,
304,
272,
408,
3314,
5417,
12,
314,
1584,
315,
1275,
6836,
787,
1586,
13,
2118,
12,
880,
1380,
20978,
342,
11275,
370,
272,
2813,
3062,
12,
376,
1919,
365,
14031,
14,
221,
2136,
8579,
626,
2348,
12,
2813,
314,
272,
1586,
13,
2118,
2225,
12,
436,
3661,
5836,
1980,
1928,
8826,
1041,
272,
444,
3667,
12,
574,
275,
3178,
63,
815,
1491,
18,
61,
272,
340,
440,
3666,
476,
3667,
365,
23950,
436,
574,
14,
589,
59,
16,
61,
508,
959,
9,
503,
327,
21714,
288,
334,
476,
3667,
365,
6440,
436,
574,
14,
589,
59,
16,
61,
508,
4944,
9,
503,
327,
1548,
18,
14,
20,
288,
334,
476,
3667,
365,
8779,
547,
436,
574,
14,
589,
59,
19,
61,
508,
959,
9,
327,
1548,
19,
14,
19,
288,
3461,
267,
746,
272,
327,
570,
730,
1077,
5544,
506,
1586,
1454,
272,
340,
3666,
736,
14,
3736,
8,
515,
680,
270,
63,
632,
1253,
5672,
14,
51,
63,
41,
5670,
9,
1137,
5672,
14,
51,
63,
41,
5670,
304,
267,
746,
272,
327,
3957,
370,
1586,
15,
952,
272,
747,
14,
11693,
8,
515,
12,
5672,
14,
51,
63,
41,
10387,
9,
272,
327,
675,
314,
3379,
805,
370,
11982,
314,
3439,
272,
2562,
8,
515,
9,
421,
199,
318,
2929,
63,
515,
8,
515,
304,
272,
408,
39,
7602,
314,
2929,
574,
367,
282,
1627,
931,
12,
10663,
652,
3847,
370,
8288,
272,
340,
3962,
1041,
272,
931,
275,
747,
14,
515,
14,
21288,
8,
736,
14,
515,
14,
4832,
8,
515,
430,
272,
340,
931,
14,
2460,
8,
736,
14,
9458,
342,
435,
747,
14,
515,
14,
4127,
304,
267,
931,
275,
7815,
435,
931,
59,
552,
8,
736,
14,
9458,
5109,
61,
272,
372,
931,
421,
199,
318,
6902,
63,
694,
8,
694,
12,
1599,
15637,
27162,
735,
272,
408,
25590,
734,
314,
536,
402,
282,
2082,
370,
1771,
1536,
314,
1627,
2935,
370,
272,
334,
4095,
1275,
27162,
12,
1275,
27162,
18,
12,
5423,
9471,
272,
302,
275,
413,
272,
3329,
275,
1599,
272,
1830,
747,
14,
515,
14,
2444,
8,
694,
435,
3329,
304,
267,
302,
847,
413,
267,
3329,
275,
1599,
435,
620,
8,
78,
9,
272,
372,
2935,
435,
3329,
421,
199,
318,
2342,
63,
1531,
8,
1760,
12,
3792,
29,
403,
12,
931,
832,
29,
403,
304,
272,
408,
5278,
397,
314,
15097,
367,
314,
1627,
1414,
436,
2529,
2399,
931,
624,
272,
340,
3792,
365,
488,
26,
267,
3792,
275,
747,
14,
2314,
14,
362,
360,
3243,
297,
12548,
1294,
8,
736,
14,
17843,
9,
272,
340,
1228,
8,
3771,
12,
1059,
63,
1313,
304,
267,
3792,
275,
359,
3771,
61,
272,
327,
1104,
340,
2337,
787,
9627,
9745,
931,
5478,
367,
31172,
12,
325,
14,
71,
14,
5417,
272,
340,
931,
832,
365,
488,
26,
267,
931,
832,
275,
664,
63,
515,
832,
342,
272,
931,
832,
275,
359,
832,
367,
1599,
315,
931,
832,
14,
2325,
1252,
1294,
8,
736,
14,
17843,
9,
340,
822,
8,
832,
1874,
272,
327,
2793,
1133,
675,
5478,
340,
314,
1414,
11187,
543,
1373,
402,
3062,
272,
340,
747,
14,
515,
14,
7973,
8,
1760,
2788,
17,
1055,
2325,
342,
315,
931,
832,
26,
267,
931,
832,
275,
24506,
272,
327,
1104,
340,
781,
2342,
314,
1414,
641,
15097,
272,
367,
931,
315,
3792,
26,
267,
327,
862,
1928,
3329,
1642,
267,
2088,
63,
515,
275,
747,
14,
515,
14,
904,
8,
515,
12,
2088,
9,
267,
367,
1599,
315,
931,
832,
26,
288,
327,
2066,
5893,
314,
3329,
288,
2088,
63,
515,
63,
832,
275,
2088,
63,
515,
435,
1599,
288,
340,
747,
14,
515,
14,
6292,
8,
1760,
63,
515,
63,
832,
304,
355,
372,
2088,
63,
515,
63,
832,
267,
340,
747,
14,
515,
14,
6292,
8,
1760,
63,
515,
304,
288,
372,
2088,
63,
515,
272,
746,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kimjaejoong/nova
|
nova/tests/unit/api/openstack/compute/contrib/test_extended_volumes.py
|
33
|
6496
|
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from oslo_serialization import jsonutils
import webob
from nova.api.openstack.compute.plugins.v3 import (extended_volumes
as extended_volumes_v21)
from nova.api.openstack import wsgi as os_wsgi
from nova import compute
from nova import db
from nova import objects
from nova.objects import instance as instance_obj
from nova import test
from nova.tests.unit.api.openstack import fakes
from nova.tests.unit import fake_block_device
from nova.tests.unit import fake_instance
from nova import volume
UUID1 = '00000000-0000-0000-0000-000000000001'
UUID2 = '00000000-0000-0000-0000-000000000002'
UUID3 = '00000000-0000-0000-0000-000000000003'
def fake_compute_get(*args, **kwargs):
inst = fakes.stub_instance(1, uuid=UUID1)
return fake_instance.fake_instance_obj(args[1], **inst)
def fake_compute_get_all(*args, **kwargs):
db_list = [fakes.stub_instance(1), fakes.stub_instance(2)]
fields = instance_obj.INSTANCE_DEFAULT_FIELDS
return instance_obj._make_instance_list(args[1],
objects.InstanceList(),
db_list, fields)
def fake_bdms_get_all_by_instance(*args, **kwargs):
return [fake_block_device.FakeDbBlockDeviceDict(
{'volume_id': UUID1, 'source_type': 'volume',
'destination_type': 'volume', 'id': 1,
'delete_on_termination': True}),
fake_block_device.FakeDbBlockDeviceDict(
{'volume_id': UUID2, 'source_type': 'volume',
'destination_type': 'volume', 'id': 2,
'delete_on_termination': False})]
def fake_volume_get(*args, **kwargs):
pass
class ExtendedVolumesTestV21(test.TestCase):
content_type = 'application/json'
prefix = 'os-extended-volumes:'
exp_volumes = [{'id': UUID1}, {'id': UUID2}]
wsgi_api_version = os_wsgi.DEFAULT_API_VERSION
def setUp(self):
super(ExtendedVolumesTestV21, self).setUp()
fakes.stub_out_nw_api(self.stubs)
self.stubs.Set(compute.api.API, 'get', fake_compute_get)
self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all)
self.stubs.Set(db, 'block_device_mapping_get_all_by_instance',
fake_bdms_get_all_by_instance)
self._setUp()
self.app = self._setup_app()
return_server = fakes.fake_instance_get()
self.stubs.Set(db, 'instance_get_by_uuid', return_server)
def _setup_app(self):
return fakes.wsgi_app_v21(init_only=('os-extended-volumes',
'servers'))
def _setUp(self):
self.Controller = extended_volumes_v21.ExtendedVolumesController()
self.stubs.Set(volume.cinder.API, 'get', fake_volume_get)
self.action_url = "/%s/action" % UUID1
def _make_request(self, url, body=None):
req = webob.Request.blank('/v2/fake/servers' + url)
req.headers['Accept'] = self.content_type
req.headers = {os_wsgi.API_VERSION_REQUEST_HEADER:
self.wsgi_api_version}
if body:
req.body = jsonutils.dumps(body)
req.method = 'POST'
req.content_type = self.content_type
res = req.get_response(self.app)
return res
def _get_server(self, body):
return jsonutils.loads(body).get('server')
def _get_servers(self, body):
return jsonutils.loads(body).get('servers')
def test_show(self):
res = self._make_request('/%s' % UUID1)
self.assertEqual(200, res.status_int)
server = self._get_server(res.body)
actual = server.get('%svolumes_attached' % self.prefix)
self.assertEqual(self.exp_volumes, actual)
def test_detail(self):
res = self._make_request('/detail')
self.assertEqual(200, res.status_int)
for i, server in enumerate(self._get_servers(res.body)):
actual = server.get('%svolumes_attached' % self.prefix)
self.assertEqual(self.exp_volumes, actual)
class ExtendedVolumesTestV2(ExtendedVolumesTestV21):
def _setup_app(self):
return fakes.wsgi_app(init_only=('servers',))
def _setUp(self):
self.flags(
osapi_compute_extension=['nova.api.openstack.compute.'
'contrib.select_extensions'],
osapi_compute_ext_list=['Extended_volumes'])
class ExtendedVolumesTestV23(ExtendedVolumesTestV21):
exp_volumes = [{'id': UUID1, 'delete_on_termination': True},
{'id': UUID2, 'delete_on_termination': False}]
wsgi_api_version = '2.3'
class ExtendedVolumesEnforcementV21(test.NoDBTestCase):
def setUp(self):
super(ExtendedVolumesEnforcementV21, self).setUp()
self.controller = extended_volumes_v21.ExtendedVolumesController()
self.req = fakes.HTTPRequest.blank('')
@mock.patch.object(extended_volumes_v21.ExtendedVolumesController,
'_extend_server')
def test_extend_show_policy_failed(self, mock_extend):
rule_name = 'os_compute_api:os-extended-volumes'
self.policy.set_rules({rule_name: "project:non_fake"})
# Pass ResponseObj as None, the code shouldn't touch the None.
self.controller.show(self.req, None, fakes.FAKE_UUID)
self.assertFalse(mock_extend.called)
@mock.patch.object(extended_volumes_v21.ExtendedVolumesController,
'_extend_server')
def test_extend_detail_policy_failed(self, mock_extend):
rule_name = 'os_compute_api:os-extended-volumes'
self.policy.set_rules({rule_name: "project:non_fake"})
# Pass ResponseObj as None, the code shouldn't touch the None.
self.controller.detail(self.req, None)
self.assertFalse(mock_extend.called)
|
apache-2.0
|
[
3,
1898,
6171,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1683,
199,
504,
11258,
63,
12161,
492,
18705,
199,
646,
14568,
199,
199,
504,
5913,
14,
1246,
14,
8512,
14,
3357,
14,
5265,
14,
86,
19,
492,
334,
10525,
63,
8838,
8962,
465,
9243,
63,
8838,
63,
86,
2025,
9,
199,
504,
5913,
14,
1246,
14,
8512,
492,
12464,
465,
747,
63,
6508,
199,
504,
5913,
492,
4526,
199,
504,
5913,
492,
1592,
199,
504,
5913,
492,
2251,
199,
504,
5913,
14,
1462,
492,
1256,
465,
1256,
63,
1113,
199,
504,
5913,
492,
511,
199,
504,
5913,
14,
2219,
14,
3248,
14,
1246,
14,
8512,
492,
14063,
199,
504,
5913,
14,
2219,
14,
3248,
492,
4026,
63,
1457,
63,
1782,
199,
504,
5913,
14,
2219,
14,
3248,
492,
4026,
63,
842,
199,
504,
5913,
492,
3301,
199,
199,
8757,
17,
275,
283,
3607,
13,
993,
13,
993,
13,
993,
13,
20625,
614,
7,
199,
8757,
18,
275,
283,
3607,
13,
993,
13,
993,
13,
993,
13,
20625,
996,
7,
199,
8757,
19,
275,
283,
3607,
13,
993,
13,
993,
13,
993,
13,
3607,
16861,
7,
421,
199,
318,
4026,
63,
3357,
63,
362,
2031,
589,
12,
1011,
958,
304,
272,
2727,
275,
14063,
14,
5811,
63,
842,
8,
17,
12,
5377,
29,
8757,
17,
9,
272,
372,
4026,
63,
842,
14,
3183,
63,
842,
63,
1113,
8,
589,
59,
17,
467,
1011,
3615,
9,
421,
199,
318,
4026,
63,
3357,
63,
362,
63,
452,
2031,
589,
12,
1011,
958,
304,
272,
1592,
63,
513,
275,
359,
27443,
14,
5811,
63,
842,
8,
17,
395,
14063,
14,
5811,
63,
842,
8,
18,
1874,
272,
1504,
275,
1256,
63,
1113,
14,
18235,
63,
3472,
63,
12767,
272,
372,
1256,
63,
1113,
423,
1875,
63,
842,
63,
513,
8,
589,
59,
17,
467,
4490,
2251,
14,
3244,
1296,
1062,
4490,
1592,
63,
513,
12,
1504,
9,
421,
199,
318,
4026,
63,
3691,
706,
63,
362,
63,
452,
63,
991,
63,
842,
2031,
589,
12,
1011,
958,
304,
272,
372,
359,
3183,
63,
1457,
63,
1782,
14,
8249,
8882,
32442,
2141,
8,
288,
791,
2405,
63,
344,
356,
11134,
17,
12,
283,
1365,
63,
466,
356,
283,
2405,
297,
1467,
283,
6881,
63,
466,
356,
283,
2405,
297,
283,
344,
356,
413,
12,
1467,
283,
1807,
63,
265,
63,
20667,
356,
715,
8688,
288,
4026,
63,
1457,
63,
1782,
14,
8249,
8882,
32442,
2141,
8,
288,
791,
2405,
63,
344,
356,
11134,
18,
12,
283,
1365,
63,
466,
356,
283,
2405,
297,
1467,
283,
6881,
63,
466,
356,
283,
2405,
297,
283,
344,
356,
499,
12,
1467,
283,
1807,
63,
265,
63,
20667,
356,
756,
1552,
61,
421,
199,
318,
4026,
63,
2405,
63,
362,
2031,
589,
12,
1011,
958,
304,
272,
986,
421,
199,
533,
13706,
6464,
26935,
54,
2025,
8,
396,
14,
1746,
304,
272,
1564,
63,
466,
275,
283,
3578,
15,
1001,
7,
272,
2403,
275,
283,
736,
13,
10525,
13,
8838,
4881,
272,
1437,
63,
8838,
275,
9016,
344,
356,
11134,
17,
1386,
791,
344,
356,
11134,
18,
11049,
272,
12464,
63,
1246,
63,
1023,
275,
747,
63,
6508,
14,
3472,
63,
3735,
63,
4612,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
14107,
6464,
26935,
54,
2025,
12,
291,
680,
5996,
342,
267,
14063,
14,
5811,
63,
548,
63,
13100,
63,
1246,
8,
277,
14,
8957,
9,
267,
291,
14,
8957,
14,
1084,
8,
3357,
14,
1246,
14,
3735,
12,
283,
362,
297,
4026,
63,
3357,
63,
362,
9,
267,
291,
14,
8957,
14,
1084,
8,
3357,
14,
1246,
14,
3735,
12,
283,
362,
63,
452,
297,
4026,
63,
3357,
63,
362,
63,
452,
9,
267,
291,
14,
8957,
14,
1084,
8,
697,
12,
283,
1457,
63,
1782,
63,
4745,
63,
362,
63,
452,
63,
991,
63,
842,
297,
2432,
4026,
63,
3691,
706,
63,
362,
63,
452,
63,
991,
63,
842,
9,
267,
291,
423,
5996,
342,
267,
291,
14,
571,
275,
291,
423,
2758,
63,
571,
342,
267,
372,
63,
1000,
275,
14063,
14,
3183,
63,
842,
63,
362,
342,
267,
291,
14,
8957,
14,
1084,
8,
697,
12,
283,
842,
63,
362,
63,
991,
63,
2580,
297,
372,
63,
1000,
9,
339,
347,
485,
2758,
63,
571,
8,
277,
304,
267,
372,
14063,
14,
6508,
63,
571,
63,
86,
2025,
8,
826,
63,
2118,
7782,
736,
13,
10525,
13,
8838,
297,
6163,
283,
5871,
1333,
339,
347,
485,
5996,
8,
277,
304,
267,
291,
14,
7506,
275,
9243,
63,
8838,
63,
86,
2025,
14,
14107,
32480,
7506,
342,
267,
291,
14,
8957,
14,
1084,
8,
2405,
14,
12372,
14,
3735,
12,
283,
362,
297,
4026,
63,
2405,
63,
362,
9,
267,
291,
14,
1287,
63,
633,
275,
298,
3149,
83,
15,
1287,
2,
450,
11134,
17,
339,
347,
485,
1875,
63,
1069,
8,
277,
12,
1166,
12,
2396,
29,
403,
304,
267,
2648,
275,
14568,
14,
2017,
14,
2500,
2336,
86,
18,
15,
3183,
15,
5871,
7,
435,
1166,
9,
267,
2648,
14,
2139,
459,
8422,
418,
275,
291,
14,
1317,
63,
466,
267,
2648,
14,
2139,
275,
469,
736,
63,
6508,
14,
3735,
63,
4612,
63,
6780,
63,
7311,
26,
2432,
291,
14,
6508,
63,
1246,
63,
1023,
93,
267,
340,
2396,
26,
288,
2648,
14,
2030,
275,
18705,
14,
4180,
8,
2030,
9,
288
] |
[
1898,
6171,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1683,
199,
504,
11258,
63,
12161,
492,
18705,
199,
646,
14568,
199,
199,
504,
5913,
14,
1246,
14,
8512,
14,
3357,
14,
5265,
14,
86,
19,
492,
334,
10525,
63,
8838,
8962,
465,
9243,
63,
8838,
63,
86,
2025,
9,
199,
504,
5913,
14,
1246,
14,
8512,
492,
12464,
465,
747,
63,
6508,
199,
504,
5913,
492,
4526,
199,
504,
5913,
492,
1592,
199,
504,
5913,
492,
2251,
199,
504,
5913,
14,
1462,
492,
1256,
465,
1256,
63,
1113,
199,
504,
5913,
492,
511,
199,
504,
5913,
14,
2219,
14,
3248,
14,
1246,
14,
8512,
492,
14063,
199,
504,
5913,
14,
2219,
14,
3248,
492,
4026,
63,
1457,
63,
1782,
199,
504,
5913,
14,
2219,
14,
3248,
492,
4026,
63,
842,
199,
504,
5913,
492,
3301,
199,
199,
8757,
17,
275,
283,
3607,
13,
993,
13,
993,
13,
993,
13,
20625,
614,
7,
199,
8757,
18,
275,
283,
3607,
13,
993,
13,
993,
13,
993,
13,
20625,
996,
7,
199,
8757,
19,
275,
283,
3607,
13,
993,
13,
993,
13,
993,
13,
3607,
16861,
7,
421,
199,
318,
4026,
63,
3357,
63,
362,
2031,
589,
12,
1011,
958,
304,
272,
2727,
275,
14063,
14,
5811,
63,
842,
8,
17,
12,
5377,
29,
8757,
17,
9,
272,
372,
4026,
63,
842,
14,
3183,
63,
842,
63,
1113,
8,
589,
59,
17,
467,
1011,
3615,
9,
421,
199,
318,
4026,
63,
3357,
63,
362,
63,
452,
2031,
589,
12,
1011,
958,
304,
272,
1592,
63,
513,
275,
359,
27443,
14,
5811,
63,
842,
8,
17,
395,
14063,
14,
5811,
63,
842,
8,
18,
1874,
272,
1504,
275,
1256,
63,
1113,
14,
18235,
63,
3472,
63,
12767,
272,
372,
1256,
63,
1113,
423,
1875,
63,
842,
63,
513,
8,
589,
59,
17,
467,
4490,
2251,
14,
3244,
1296,
1062,
4490,
1592,
63,
513,
12,
1504,
9,
421,
199,
318,
4026,
63,
3691,
706,
63,
362,
63,
452,
63,
991,
63,
842,
2031,
589,
12,
1011,
958,
304,
272,
372,
359,
3183,
63,
1457,
63,
1782,
14,
8249,
8882,
32442,
2141,
8,
288,
791,
2405,
63,
344,
356,
11134,
17,
12,
283,
1365,
63,
466,
356,
283,
2405,
297,
1467,
283,
6881,
63,
466,
356,
283,
2405,
297,
283,
344,
356,
413,
12,
1467,
283,
1807,
63,
265,
63,
20667,
356,
715,
8688,
288,
4026,
63,
1457,
63,
1782,
14,
8249,
8882,
32442,
2141,
8,
288,
791,
2405,
63,
344,
356,
11134,
18,
12,
283,
1365,
63,
466,
356,
283,
2405,
297,
1467,
283,
6881,
63,
466,
356,
283,
2405,
297,
283,
344,
356,
499,
12,
1467,
283,
1807,
63,
265,
63,
20667,
356,
756,
1552,
61,
421,
199,
318,
4026,
63,
2405,
63,
362,
2031,
589,
12,
1011,
958,
304,
272,
986,
421,
199,
533,
13706,
6464,
26935,
54,
2025,
8,
396,
14,
1746,
304,
272,
1564,
63,
466,
275,
283,
3578,
15,
1001,
7,
272,
2403,
275,
283,
736,
13,
10525,
13,
8838,
4881,
272,
1437,
63,
8838,
275,
9016,
344,
356,
11134,
17,
1386,
791,
344,
356,
11134,
18,
11049,
272,
12464,
63,
1246,
63,
1023,
275,
747,
63,
6508,
14,
3472,
63,
3735,
63,
4612,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
14107,
6464,
26935,
54,
2025,
12,
291,
680,
5996,
342,
267,
14063,
14,
5811,
63,
548,
63,
13100,
63,
1246,
8,
277,
14,
8957,
9,
267,
291,
14,
8957,
14,
1084,
8,
3357,
14,
1246,
14,
3735,
12,
283,
362,
297,
4026,
63,
3357,
63,
362,
9,
267,
291,
14,
8957,
14,
1084,
8,
3357,
14,
1246,
14,
3735,
12,
283,
362,
63,
452,
297,
4026,
63,
3357,
63,
362,
63,
452,
9,
267,
291,
14,
8957,
14,
1084,
8,
697,
12,
283,
1457,
63,
1782,
63,
4745,
63,
362,
63,
452,
63,
991,
63,
842,
297,
2432,
4026,
63,
3691,
706,
63,
362,
63,
452,
63,
991,
63,
842,
9,
267,
291,
423,
5996,
342,
267,
291,
14,
571,
275,
291,
423,
2758,
63,
571,
342,
267,
372,
63,
1000,
275,
14063,
14,
3183,
63,
842,
63,
362,
342,
267,
291,
14,
8957,
14,
1084,
8,
697,
12,
283,
842,
63,
362,
63,
991,
63,
2580,
297,
372,
63,
1000,
9,
339,
347,
485,
2758,
63,
571,
8,
277,
304,
267,
372,
14063,
14,
6508,
63,
571,
63,
86,
2025,
8,
826,
63,
2118,
7782,
736,
13,
10525,
13,
8838,
297,
6163,
283,
5871,
1333,
339,
347,
485,
5996,
8,
277,
304,
267,
291,
14,
7506,
275,
9243,
63,
8838,
63,
86,
2025,
14,
14107,
32480,
7506,
342,
267,
291,
14,
8957,
14,
1084,
8,
2405,
14,
12372,
14,
3735,
12,
283,
362,
297,
4026,
63,
2405,
63,
362,
9,
267,
291,
14,
1287,
63,
633,
275,
298,
3149,
83,
15,
1287,
2,
450,
11134,
17,
339,
347,
485,
1875,
63,
1069,
8,
277,
12,
1166,
12,
2396,
29,
403,
304,
267,
2648,
275,
14568,
14,
2017,
14,
2500,
2336,
86,
18,
15,
3183,
15,
5871,
7,
435,
1166,
9,
267,
2648,
14,
2139,
459,
8422,
418,
275,
291,
14,
1317,
63,
466,
267,
2648,
14,
2139,
275,
469,
736,
63,
6508,
14,
3735,
63,
4612,
63,
6780,
63,
7311,
26,
2432,
291,
14,
6508,
63,
1246,
63,
1023,
93,
267,
340,
2396,
26,
288,
2648,
14,
2030,
275,
18705,
14,
4180,
8,
2030,
9,
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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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
] |
wkritzinger/asuswrt-merlin
|
release/src/router/samba36/lib/dnspython/dns/rdtypes/IN/NAPTR.py
|
248
|
4889
|
# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose with or without fee is hereby granted,
# provided that the above copyright notice and this permission notice
# appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import struct
import dns.exception
import dns.name
import dns.rdata
def _write_string(file, s):
l = len(s)
assert l < 256
byte = chr(l)
file.write(byte)
file.write(s)
class NAPTR(dns.rdata.Rdata):
"""NAPTR record
@ivar order: order
@type order: int
@ivar preference: preference
@type preference: int
@ivar flags: flags
@type flags: string
@ivar service: service
@type service: string
@ivar regexp: regular expression
@type regexp: string
@ivar replacement: replacement name
@type replacement: dns.name.Name object
@see: RFC 3403"""
__slots__ = ['order', 'preference', 'flags', 'service', 'regexp',
'replacement']
def __init__(self, rdclass, rdtype, order, preference, flags, service,
regexp, replacement):
super(NAPTR, self).__init__(rdclass, rdtype)
self.order = order
self.preference = preference
self.flags = flags
self.service = service
self.regexp = regexp
self.replacement = replacement
def to_text(self, origin=None, relativize=True, **kw):
replacement = self.replacement.choose_relativity(origin, relativize)
return '%d %d "%s" "%s" "%s" %s' % \
(self.order, self.preference,
dns.rdata._escapify(self.flags),
dns.rdata._escapify(self.service),
dns.rdata._escapify(self.regexp),
self.replacement)
def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
order = tok.get_uint16()
preference = tok.get_uint16()
flags = tok.get_string()
service = tok.get_string()
regexp = tok.get_string()
replacement = tok.get_name()
replacement = replacement.choose_relativity(origin, relativize)
tok.get_eol()
return cls(rdclass, rdtype, order, preference, flags, service,
regexp, replacement)
from_text = classmethod(from_text)
def to_wire(self, file, compress = None, origin = None):
two_ints = struct.pack("!HH", self.order, self.preference)
file.write(two_ints)
_write_string(file, self.flags)
_write_string(file, self.service)
_write_string(file, self.regexp)
self.replacement.to_wire(file, compress, origin)
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
(order, preference) = struct.unpack('!HH', wire[current : current + 4])
current += 4
rdlen -= 4
strings = []
for i in xrange(3):
l = ord(wire[current])
current += 1
rdlen -= 1
if l > rdlen or rdlen < 0:
raise dns.exception.FormError
s = wire[current : current + l]
current += l
rdlen -= l
strings.append(s)
(replacement, cused) = dns.name.from_wire(wire[: current + rdlen],
current)
if cused != rdlen:
raise dns.exception.FormError
if not origin is None:
replacement = replacement.relativize(origin)
return cls(rdclass, rdtype, order, preference, strings[0], strings[1],
strings[2], replacement)
from_wire = classmethod(from_wire)
def choose_relativity(self, origin = None, relativize = True):
self.replacement = self.replacement.choose_relativity(origin,
relativize)
def _cmp(self, other):
sp = struct.pack("!HH", self.order, self.preference)
op = struct.pack("!HH", other.order, other.preference)
v = cmp(sp, op)
if v == 0:
v = cmp(self.flags, other.flags)
if v == 0:
v = cmp(self.service, other.service)
if v == 0:
v = cmp(self.regexp, other.regexp)
if v == 0:
v = cmp(self.replacement, other.replacement)
return v
|
gpl-2.0
|
[
3,
1898,
334,
35,
9,
13004,
13,
9488,
12,
8937,
12,
7129,
653,
676,
262,
453,
12,
3277,
14,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
436,
2399,
199,
3,
3794,
367,
1263,
12016,
543,
503,
1928,
14751,
365,
11882,
10009,
12,
199,
3,
2741,
626,
314,
3432,
4248,
4245,
436,
642,
4983,
4245,
199,
3,
7468,
315,
1006,
6866,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
4825,
4896,
2639,
8990,
51,
11727,
2990,
199,
3,
1663,
14142,
7816,
2296,
5749,
4141,
6931,
11727,
5292,
2990,
1634,
199,
3,
3169,
2401,
3092,
14,
1621,
4825,
6461,
7000,
4825,
4896,
2639,
6262,
7024,
2381,
199,
3,
1821,
8820,
12,
8703,
12,
9168,
12,
1549,
9110,
6736,
1549,
1821,
6736,
199,
3,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
9612,
12,
7043,
5738,
199,
3,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
646,
2702,
199,
199,
646,
6715,
14,
1971,
199,
646,
6715,
14,
354,
199,
646,
6715,
14,
23203,
199,
199,
318,
485,
952,
63,
875,
8,
493,
12,
308,
304,
272,
634,
275,
822,
8,
83,
9,
272,
702,
634,
665,
7633,
272,
3696,
275,
8678,
8,
76,
9,
272,
570,
14,
952,
8,
4414,
9,
272,
570,
14,
952,
8,
83,
9,
199,
199,
533,
653,
1282,
1766,
8,
5797,
14,
23203,
14,
50,
576,
304,
272,
408,
46,
1282,
1766,
2777,
339,
768,
7725,
1865,
26,
1865,
272,
768,
466,
1865,
26,
1109,
272,
768,
7725,
16705,
26,
16705,
272,
768,
466,
16705,
26,
1109,
272,
768,
7725,
3285,
26,
3285,
272,
768,
466,
3285,
26,
1059,
272,
768,
7725,
2435,
26,
2435,
272,
768,
466,
2435,
26,
1059,
272,
768,
7725,
13156,
26,
5578,
3965,
272,
768,
466,
13156,
26,
1059,
272,
768,
7725,
8343,
26,
8343,
536,
272,
768,
466,
8343,
26,
6715,
14,
354,
14,
985,
909,
272,
768,
3239,
26,
7329,
8177,
1644,
624,
339,
636,
7257,
363,
275,
788,
1648,
297,
283,
14994,
297,
283,
2469,
297,
283,
1364,
297,
283,
11191,
297,
326,
283,
15895,
418,
2286,
347,
636,
826,
721,
277,
12,
29320,
12,
22764,
12,
1865,
12,
16705,
12,
3285,
12,
2435,
12,
326,
13156,
12,
8343,
304,
267,
1613,
8,
46,
1282,
1766,
12,
291,
2843,
826,
721,
30186,
12,
22764,
9,
267,
291,
14,
1648,
275,
1865,
267,
291,
14,
14994,
275,
16705,
267,
291,
14,
2469,
275,
3285,
267,
291,
14,
1364,
275,
2435,
267,
291,
14,
11191,
275,
13156,
267,
291,
14,
15895,
275,
8343,
339,
347,
370,
63,
505,
8,
277,
12,
6330,
29,
403,
12,
13773,
29282,
29,
549,
12,
1011,
829,
304,
267,
8343,
275,
291,
14,
15895,
14,
16143,
63,
17060,
4191,
8,
6493,
12,
13773,
29282,
9,
267,
372,
1543,
68,
450,
68,
2071,
83,
2,
2071,
83,
2,
2071,
83,
2,
450,
83,
7,
450,
971,
2049,
334,
277,
14,
1648,
12,
291,
14,
14994,
12,
355,
6715,
14,
23203,
423,
24698,
2021,
8,
277,
14,
2469,
395,
355,
6715,
14,
23203,
423,
24698,
2021,
8,
277,
14,
1364,
395,
355,
6715,
14,
23203,
423,
24698,
2021,
8,
277,
14,
11191,
395,
355,
291,
14,
15895,
9,
339,
347,
687,
63,
505,
8,
1886,
12,
29320,
12,
22764,
12,
8431,
12,
6330,
275,
488,
12,
13773,
29282,
275,
715,
304,
267,
1865,
275,
8431,
14,
362,
63,
1635,
975,
342,
267,
16705,
275,
8431,
14,
362,
63,
1635,
975,
342,
267,
3285,
275,
8431,
14,
362,
63,
875,
342,
267,
2435,
275,
8431,
14,
362,
63,
875,
342,
267,
13156,
275,
8431,
14,
362,
63,
875,
342,
267,
8343,
275,
8431,
14,
362,
63,
354,
342,
267,
8343,
275,
8343,
14,
16143,
63,
17060,
4191,
8,
6493,
12,
13773,
29282,
9,
267,
8431,
14,
362,
63,
20470,
342,
267,
372,
843,
8,
30186,
12,
22764,
12,
1865,
12,
16705,
12,
3285,
12,
2435,
12,
673,
13156,
12,
8343,
9,
2286,
687,
63,
505,
275,
18990,
8,
504,
63,
505,
9,
339,
347,
370,
63,
11239,
8,
277,
12,
570,
12,
11029,
275,
488,
12,
6330,
275,
488,
304,
267,
2877,
63,
13141,
275,
2702,
14,
1389,
19232,
10213,
401,
291,
14,
1648,
12,
291,
14,
14994,
9,
267,
570,
14,
952,
8,
5601,
63,
13141,
9,
267,
485,
952,
63,
875,
8,
493,
12,
291,
14,
2469,
9,
267,
485,
952,
63,
875,
8,
493,
12,
291,
14,
1364,
9,
267,
485,
952,
63,
875,
8,
493,
12,
291,
14,
11191,
9,
267,
291,
14,
15895,
14,
475,
63,
11239,
8,
493,
12,
11029,
12,
6330,
9,
5493,
347,
687,
63,
11239,
8,
1886,
12,
29320,
12,
22764,
12,
11799,
12,
1453,
12,
11517,
552,
12,
6330,
275,
488,
304,
267,
334,
1648,
12,
16705,
9,
275,
2702,
14,
5301,
16157,
10213,
297,
11799,
59,
1818,
520,
1453,
435,
841,
566,
267,
1453,
847,
841,
267,
11517,
552,
4862,
841,
267,
3326,
275,
942,
267,
367,
284,
315,
4945,
8,
19,
304,
288,
634,
275,
6206,
8,
11239,
59,
1818,
566,
288,
1453,
847,
413,
288,
11517,
552,
4862,
413,
288,
340,
634,
690,
11517,
552,
503,
11517,
552,
665,
378,
26,
355,
746,
6715,
14,
1971,
14,
2821,
547,
288,
308,
275,
11799,
59,
1818,
520,
1453,
435,
634,
61,
288,
1453,
847,
634,
288,
11517,
552,
4862,
634,
288,
3326,
14,
740,
8,
83,
9,
267,
334,
15895,
12,
286,
2972,
9,
275,
6715,
14,
354,
14,
504,
63,
11239,
8,
11239,
1491,
1453,
435,
11517,
552,
467,
8179,
1453,
9,
267,
340,
286,
2972,
1137,
11517,
552,
26,
288,
746,
6715,
14,
1971,
14,
2821,
547,
267,
340,
440,
6330,
365,
488,
26,
288,
8343,
275,
8343,
14,
17060,
29282,
8,
6493,
9,
267,
372,
843,
8,
30186,
12,
22764,
12,
1865,
12,
16705,
12,
3326,
59,
16,
467,
3326,
59,
17,
467,
673,
3326,
59,
18,
467,
8343,
9,
339,
687,
63,
11239,
275,
18990,
8,
504,
63,
11239,
9,
339,
347,
11496,
63
] |
[
1898,
334,
35,
9,
13004,
13,
9488,
12,
8937,
12,
7129,
653,
676,
262,
453,
12,
3277,
14,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
436,
2399,
199,
3,
3794,
367,
1263,
12016,
543,
503,
1928,
14751,
365,
11882,
10009,
12,
199,
3,
2741,
626,
314,
3432,
4248,
4245,
436,
642,
4983,
4245,
199,
3,
7468,
315,
1006,
6866,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
4825,
4896,
2639,
8990,
51,
11727,
2990,
199,
3,
1663,
14142,
7816,
2296,
5749,
4141,
6931,
11727,
5292,
2990,
1634,
199,
3,
3169,
2401,
3092,
14,
1621,
4825,
6461,
7000,
4825,
4896,
2639,
6262,
7024,
2381,
199,
3,
1821,
8820,
12,
8703,
12,
9168,
12,
1549,
9110,
6736,
1549,
1821,
6736,
199,
3,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
9612,
12,
7043,
5738,
199,
3,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
646,
2702,
199,
199,
646,
6715,
14,
1971,
199,
646,
6715,
14,
354,
199,
646,
6715,
14,
23203,
199,
199,
318,
485,
952,
63,
875,
8,
493,
12,
308,
304,
272,
634,
275,
822,
8,
83,
9,
272,
702,
634,
665,
7633,
272,
3696,
275,
8678,
8,
76,
9,
272,
570,
14,
952,
8,
4414,
9,
272,
570,
14,
952,
8,
83,
9,
199,
199,
533,
653,
1282,
1766,
8,
5797,
14,
23203,
14,
50,
576,
304,
272,
408,
46,
1282,
1766,
2777,
339,
768,
7725,
1865,
26,
1865,
272,
768,
466,
1865,
26,
1109,
272,
768,
7725,
16705,
26,
16705,
272,
768,
466,
16705,
26,
1109,
272,
768,
7725,
3285,
26,
3285,
272,
768,
466,
3285,
26,
1059,
272,
768,
7725,
2435,
26,
2435,
272,
768,
466,
2435,
26,
1059,
272,
768,
7725,
13156,
26,
5578,
3965,
272,
768,
466,
13156,
26,
1059,
272,
768,
7725,
8343,
26,
8343,
536,
272,
768,
466,
8343,
26,
6715,
14,
354,
14,
985,
909,
272,
768,
3239,
26,
7329,
8177,
1644,
624,
339,
636,
7257,
363,
275,
788,
1648,
297,
283,
14994,
297,
283,
2469,
297,
283,
1364,
297,
283,
11191,
297,
326,
283,
15895,
418,
2286,
347,
636,
826,
721,
277,
12,
29320,
12,
22764,
12,
1865,
12,
16705,
12,
3285,
12,
2435,
12,
326,
13156,
12,
8343,
304,
267,
1613,
8,
46,
1282,
1766,
12,
291,
2843,
826,
721,
30186,
12,
22764,
9,
267,
291,
14,
1648,
275,
1865,
267,
291,
14,
14994,
275,
16705,
267,
291,
14,
2469,
275,
3285,
267,
291,
14,
1364,
275,
2435,
267,
291,
14,
11191,
275,
13156,
267,
291,
14,
15895,
275,
8343,
339,
347,
370,
63,
505,
8,
277,
12,
6330,
29,
403,
12,
13773,
29282,
29,
549,
12,
1011,
829,
304,
267,
8343,
275,
291,
14,
15895,
14,
16143,
63,
17060,
4191,
8,
6493,
12,
13773,
29282,
9,
267,
372,
1543,
68,
450,
68,
2071,
83,
2,
2071,
83,
2,
2071,
83,
2,
450,
83,
7,
450,
971,
2049,
334,
277,
14,
1648,
12,
291,
14,
14994,
12,
355,
6715,
14,
23203,
423,
24698,
2021,
8,
277,
14,
2469,
395,
355,
6715,
14,
23203,
423,
24698,
2021,
8,
277,
14,
1364,
395,
355,
6715,
14,
23203,
423,
24698,
2021,
8,
277,
14,
11191,
395,
355,
291,
14,
15895,
9,
339,
347,
687,
63,
505,
8,
1886,
12,
29320,
12,
22764,
12,
8431,
12,
6330,
275,
488,
12,
13773,
29282,
275,
715,
304,
267,
1865,
275,
8431,
14,
362,
63,
1635,
975,
342,
267,
16705,
275,
8431,
14,
362,
63,
1635,
975,
342,
267,
3285,
275,
8431,
14,
362,
63,
875,
342,
267,
2435,
275,
8431,
14,
362,
63,
875,
342,
267,
13156,
275,
8431,
14,
362,
63,
875,
342,
267,
8343,
275,
8431,
14,
362,
63,
354,
342,
267,
8343,
275,
8343,
14,
16143,
63,
17060,
4191,
8,
6493,
12,
13773,
29282,
9,
267,
8431,
14,
362,
63,
20470,
342,
267,
372,
843,
8,
30186,
12,
22764,
12,
1865,
12,
16705,
12,
3285,
12,
2435,
12,
673,
13156,
12,
8343,
9,
2286,
687,
63,
505,
275,
18990,
8,
504,
63,
505,
9,
339,
347,
370,
63,
11239,
8,
277,
12,
570,
12,
11029,
275,
488,
12,
6330,
275,
488,
304,
267,
2877,
63,
13141,
275,
2702,
14,
1389,
19232,
10213,
401,
291,
14,
1648,
12,
291,
14,
14994,
9,
267,
570,
14,
952,
8,
5601,
63,
13141,
9,
267,
485,
952,
63,
875,
8,
493,
12,
291,
14,
2469,
9,
267,
485,
952,
63,
875,
8,
493,
12,
291,
14,
1364,
9,
267,
485,
952,
63,
875,
8,
493,
12,
291,
14,
11191,
9,
267,
291,
14,
15895,
14,
475,
63,
11239,
8,
493,
12,
11029,
12,
6330,
9,
5493,
347,
687,
63,
11239,
8,
1886,
12,
29320,
12,
22764,
12,
11799,
12,
1453,
12,
11517,
552,
12,
6330,
275,
488,
304,
267,
334,
1648,
12,
16705,
9,
275,
2702,
14,
5301,
16157,
10213,
297,
11799,
59,
1818,
520,
1453,
435,
841,
566,
267,
1453,
847,
841,
267,
11517,
552,
4862,
841,
267,
3326,
275,
942,
267,
367,
284,
315,
4945,
8,
19,
304,
288,
634,
275,
6206,
8,
11239,
59,
1818,
566,
288,
1453,
847,
413,
288,
11517,
552,
4862,
413,
288,
340,
634,
690,
11517,
552,
503,
11517,
552,
665,
378,
26,
355,
746,
6715,
14,
1971,
14,
2821,
547,
288,
308,
275,
11799,
59,
1818,
520,
1453,
435,
634,
61,
288,
1453,
847,
634,
288,
11517,
552,
4862,
634,
288,
3326,
14,
740,
8,
83,
9,
267,
334,
15895,
12,
286,
2972,
9,
275,
6715,
14,
354,
14,
504,
63,
11239,
8,
11239,
1491,
1453,
435,
11517,
552,
467,
8179,
1453,
9,
267,
340,
286,
2972,
1137,
11517,
552,
26,
288,
746,
6715,
14,
1971,
14,
2821,
547,
267,
340,
440,
6330,
365,
488,
26,
288,
8343,
275,
8343,
14,
17060,
29282,
8,
6493,
9,
267,
372,
843,
8,
30186,
12,
22764,
12,
1865,
12,
16705,
12,
3326,
59,
16,
467,
3326,
59,
17,
467,
673,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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
] |
moijes12/oh-mainline
|
vendor/packages/gdata/tests/gdata_tests/photos/service_test.py
|
128
|
2928
|
#!/usr/bin/python
#
# Copyright (C) 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__author__ = 'api.jscudder (Jeffrey Scudder)'
import getpass
import time
import unittest
import StringIO
import gdata.photos.service
import gdata.photos
import atom
username = ''
password = ''
test_image_location = '../../testimage.jpg'
test_image_name = 'testimage.jpg'
class PhotosServiceTest(unittest.TestCase):
def setUp(self):
# Initialize the client and create a new album for testing.
self.client = gdata.photos.service.PhotosService()
self.client.email = username
self.client.password = password
self.client.source = 'Photos Client Unit Tests'
self.client.ProgrammaticLogin()
# Give the album a unique title by appending the current time.
self.test_album = self.client.InsertAlbum(
'Python library test' + str(time.time()),
'A temporary test album.')
def testUploadGetAndDeletePhoto(self):
image_entry = self.client.InsertPhotoSimple(self.test_album,
'test', 'a pretty testing picture', test_image_location)
self.assert_(image_entry.title.text == 'test')
results_feed = self.client.SearchUserPhotos('test')
self.assert_(len(results_feed.entry) > 0)
self.client.Delete(image_entry)
def testInsertPhotoUpdateBlobAndDelete(self):
new_entry = gdata.photos.PhotoEntry()
new_entry.title = atom.Title(text='a_test_image')
new_entry.summary = atom.Summary(text='Just a test.')
new_entry.category.append(atom.Category(
scheme='http://schemas.google.com/g/2005#kind',
term='http://schemas.google.com/photos/2007#photo'))
entry = self.client.InsertPhoto(self.test_album, new_entry,
test_image_location, content_type='image/jpeg')
self.assert_(entry.id.text)
updated_entry = self.client.UpdatePhotoBlob(entry, test_image_location)
self.assert_(entry.GetEditLink().href != updated_entry.GetEditLink().href)
self.client.Delete(updated_entry)
def tearDown(self):
# Delete the test album.
test_album = self.client.GetEntry(self.test_album.GetSelfLink().href)
self.client.Delete(test_album)
if __name__ == '__main__':
print ('Google Photos test\nNOTE: Please run these tests only with a test '
'account. The tests may delete or update your data.')
username = raw_input('Please enter your username: ')
password = getpass.getpass()
unittest.main()
|
agpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
35,
9,
10219,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
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,
363,
2502,
363,
275,
283,
1246,
14,
74,
551,
1181,
424,
334,
42,
3609,
17885,
13916,
1181,
424,
3171,
199,
199,
646,
18354,
199,
646,
900,
199,
646,
2882,
199,
646,
5228,
199,
646,
11006,
14,
25211,
14,
1364,
199,
646,
11006,
14,
25211,
199,
646,
6222,
421,
199,
2473,
275,
2125,
199,
2060,
275,
2125,
199,
396,
63,
1569,
63,
1985,
275,
283,
9707,
396,
1569,
14,
8476,
7,
199,
396,
63,
1569,
63,
354,
275,
283,
396,
1569,
14,
8476,
7,
421,
199,
533,
510,
8885,
736,
3167,
774,
8,
2796,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
327,
11578,
314,
1890,
436,
1218,
282,
892,
16379,
367,
5343,
14,
272,
291,
14,
1258,
275,
11006,
14,
25211,
14,
1364,
14,
5663,
17278,
3167,
342,
272,
291,
14,
1258,
14,
2123,
275,
3434,
272,
291,
14,
1258,
14,
2060,
275,
2505,
272,
291,
14,
1258,
14,
1365,
275,
283,
5663,
17278,
6810,
12008,
6496,
7,
272,
291,
14,
1258,
14,
9184,
3889,
8880,
342,
339,
327,
25495,
314,
16379,
282,
3747,
2538,
701,
24373,
314,
1453,
900,
14,
272,
291,
14,
396,
63,
12110,
275,
291,
14,
1258,
14,
9971,
26369,
8,
267,
283,
4718,
3555,
511,
7,
435,
620,
8,
521,
14,
521,
4000,
4960,
283,
33,
7937,
511,
16379,
2659,
819,
347,
511,
10301,
1002,
3325,
5392,
21258,
8,
277,
304,
272,
1834,
63,
2373,
275,
291,
14,
1258,
14,
9971,
21258,
3184,
8,
277,
14,
396,
63,
12110,
12,
267,
283,
396,
297,
283,
65,
7268,
5343,
24945,
297,
511,
63,
1569,
63,
1985,
9,
272,
291,
14,
479,
2531,
1569,
63,
2373,
14,
1213,
14,
505,
508,
283,
396,
358,
272,
2058,
63,
3871,
275,
291,
14,
1258,
14,
5278,
1899,
5663,
17278,
360,
396,
358,
272,
291,
14,
479,
2531,
552,
8,
2604,
63,
3871,
14,
2373,
9,
690,
378,
9,
272,
291,
14,
1258,
14,
5392,
8,
1569,
63,
2373,
9,
819,
347,
511,
9971,
21258,
4152,
16799,
3325,
5392,
8,
277,
304,
272,
892,
63,
2373,
275,
11006,
14,
25211,
14,
21258,
3900,
342,
272,
892,
63,
2373,
14,
1213,
275,
6222,
14,
6888,
8,
505,
534,
65,
63,
396,
63,
1569,
358,
272,
892,
63,
2373,
14,
4705,
275,
6222,
14,
10407,
8,
505,
534,
22850,
282,
511,
2659,
272,
892,
63,
2373,
14,
3710,
14,
740,
8,
4188,
14,
7841,
8,
267,
5687,
534,
1014,
921,
9482,
14,
3098,
14,
957,
15,
71,
15,
9397,
3,
5091,
297,
4960,
6707,
534,
1014,
921,
9482,
14,
3098,
14,
957,
15,
25211,
15,
9488,
3,
13834,
1333,
272,
2397,
275,
291,
14,
1258,
14,
9971,
21258,
8,
277,
14,
396,
63,
12110,
12,
892,
63,
2373,
12,
4960,
511,
63,
1569,
63,
1985,
12,
1564,
63,
466,
534,
1569,
15,
14230,
358,
272,
291,
14,
479,
2531,
2373,
14,
344,
14,
505,
9,
272,
4588,
63,
2373,
275,
291,
14,
1258,
14,
4152,
21258,
16799,
8,
2373,
12,
511,
63,
1569,
63,
1985,
9,
272,
291,
14,
479,
2531,
2373,
14,
1002,
4685,
3834,
1252,
6399,
1137,
4588,
63,
2373,
14,
1002,
4685,
3834,
1252,
6399,
9,
272,
291,
14,
1258,
14,
5392,
8,
5334,
63,
2373,
9,
819,
347,
6766,
8,
277,
304,
272,
327,
8496,
314,
511,
16379,
14,
272,
511,
63,
12110,
275,
291,
14,
1258,
14,
1002,
3900,
8,
277,
14,
396,
63,
12110,
14,
1002,
12887,
3834,
1252,
6399,
9,
272,
291,
14,
1258,
14,
5392,
8,
396,
63,
12110,
9,
2043,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
870,
661,
13266,
510,
8885,
736,
511,
60,
78,
19855,
26,
7754,
1255,
3520,
2295,
1454,
543,
282,
511,
283,
268,
283,
2048,
14,
710,
2295,
1443,
3145,
503,
1678,
2195,
666,
2659,
523,
3434,
275,
3066,
63,
1210,
360,
8254,
9509,
2195,
3434,
26,
5320,
523,
2505,
275,
18354,
14,
27481,
342,
523,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
35,
9,
10219,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
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,
363,
2502,
363,
275,
283,
1246,
14,
74,
551,
1181,
424,
334,
42,
3609,
17885,
13916,
1181,
424,
3171,
199,
199,
646,
18354,
199,
646,
900,
199,
646,
2882,
199,
646,
5228,
199,
646,
11006,
14,
25211,
14,
1364,
199,
646,
11006,
14,
25211,
199,
646,
6222,
421,
199,
2473,
275,
2125,
199,
2060,
275,
2125,
199,
396,
63,
1569,
63,
1985,
275,
283,
9707,
396,
1569,
14,
8476,
7,
199,
396,
63,
1569,
63,
354,
275,
283,
396,
1569,
14,
8476,
7,
421,
199,
533,
510,
8885,
736,
3167,
774,
8,
2796,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
327,
11578,
314,
1890,
436,
1218,
282,
892,
16379,
367,
5343,
14,
272,
291,
14,
1258,
275,
11006,
14,
25211,
14,
1364,
14,
5663,
17278,
3167,
342,
272,
291,
14,
1258,
14,
2123,
275,
3434,
272,
291,
14,
1258,
14,
2060,
275,
2505,
272,
291,
14,
1258,
14,
1365,
275,
283,
5663,
17278,
6810,
12008,
6496,
7,
272,
291,
14,
1258,
14,
9184,
3889,
8880,
342,
339,
327,
25495,
314,
16379,
282,
3747,
2538,
701,
24373,
314,
1453,
900,
14,
272,
291,
14,
396,
63,
12110,
275,
291,
14,
1258,
14,
9971,
26369,
8,
267,
283,
4718,
3555,
511,
7,
435,
620,
8,
521,
14,
521,
4000,
4960,
283,
33,
7937,
511,
16379,
2659,
819,
347,
511,
10301,
1002,
3325,
5392,
21258,
8,
277,
304,
272,
1834,
63,
2373,
275,
291,
14,
1258,
14,
9971,
21258,
3184,
8,
277,
14,
396,
63,
12110,
12,
267,
283,
396,
297,
283,
65,
7268,
5343,
24945,
297,
511,
63,
1569,
63,
1985,
9,
272,
291,
14,
479,
2531,
1569,
63,
2373,
14,
1213,
14,
505,
508,
283,
396,
358,
272,
2058,
63,
3871,
275,
291,
14,
1258,
14,
5278,
1899,
5663,
17278,
360,
396,
358,
272,
291,
14,
479,
2531,
552,
8,
2604,
63,
3871,
14,
2373,
9,
690,
378,
9,
272,
291,
14,
1258,
14,
5392,
8,
1569,
63,
2373,
9,
819,
347,
511,
9971,
21258,
4152,
16799,
3325,
5392,
8,
277,
304,
272,
892,
63,
2373,
275,
11006,
14,
25211,
14,
21258,
3900,
342,
272,
892,
63,
2373,
14,
1213,
275,
6222,
14,
6888,
8,
505,
534,
65,
63,
396,
63,
1569,
358,
272,
892,
63,
2373,
14,
4705,
275,
6222,
14,
10407,
8,
505,
534,
22850,
282,
511,
2659,
272,
892,
63,
2373,
14,
3710,
14,
740,
8,
4188,
14,
7841,
8,
267,
5687,
534,
1014,
921,
9482,
14,
3098,
14,
957,
15,
71,
15,
9397,
3,
5091,
297,
4960,
6707,
534,
1014,
921,
9482,
14,
3098,
14,
957,
15,
25211,
15,
9488,
3,
13834,
1333,
272,
2397,
275,
291,
14,
1258,
14,
9971,
21258,
8,
277,
14,
396,
63,
12110,
12,
892,
63,
2373,
12,
4960,
511,
63,
1569,
63,
1985,
12,
1564,
63,
466,
534,
1569,
15,
14230,
358,
272,
291,
14,
479,
2531,
2373,
14,
344,
14,
505,
9,
272,
4588,
63,
2373,
275,
291,
14,
1258,
14,
4152,
21258,
16799,
8,
2373,
12,
511,
63,
1569,
63,
1985,
9,
272,
291,
14,
479,
2531,
2373,
14,
1002,
4685,
3834,
1252,
6399,
1137,
4588,
63,
2373,
14,
1002,
4685,
3834,
1252,
6399,
9,
272,
291,
14,
1258,
14,
5392,
8,
5334,
63,
2373,
9,
819,
347,
6766,
8,
277,
304,
272,
327,
8496,
314,
511,
16379,
14,
272,
511,
63,
12110,
275,
291,
14,
1258,
14,
1002,
3900,
8,
277,
14,
396,
63,
12110,
14,
1002,
12887,
3834,
1252,
6399,
9,
272,
291,
14,
1258,
14,
5392,
8,
396,
63,
12110,
9,
2043,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
870,
661,
13266,
510,
8885,
736,
511,
60,
78,
19855,
26,
7754,
1255,
3520,
2295,
1454,
543,
282,
511,
283,
268,
283,
2048,
14,
710,
2295,
1443,
3145,
503,
1678,
2195,
666,
2659,
523,
3434,
275,
3066,
63,
1210,
360,
8254,
9509,
2195,
3434,
26,
5320,
523,
2505,
275,
18354,
14,
27481,
342,
523,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
martynovp/edx-platform
|
common/test/acceptance/fixtures/certificates.py
|
80
|
1221
|
"""
Tools for creating certificates config fixture data.
"""
import json
from . import STUDIO_BASE_URL
from .base import StudioApiFixture
class CertificateConfigFixtureError(Exception):
"""
Error occurred while installing certificate config fixture.
"""
pass
class CertificateConfigFixture(StudioApiFixture):
"""
Fixture to create certificates configuration for a course
"""
certificates = []
def __init__(self, course_id, certificates_data):
self.course_id = course_id
self.certificates = certificates_data
super(CertificateConfigFixture, self).__init__()
def install(self):
"""
Push the certificates config data to certificate endpoint.
"""
response = self.session.post(
'{}/certificates/{}'.format(STUDIO_BASE_URL, self.course_id),
data=json.dumps(self.certificates),
headers=self.headers
)
if not response.ok:
raise CertificateConfigFixtureError(
"Could not create certificate {0}. Status was {1}".format(
json.dumps(self.certificates), response.status_code
)
)
return self
|
agpl-3.0
|
[
624,
199,
11654,
367,
6425,
14512,
1101,
10949,
666,
14,
199,
624,
199,
199,
646,
2022,
199,
199,
504,
1275,
492,
4384,
53,
19283,
63,
5825,
63,
2632,
199,
504,
1275,
1095,
492,
13225,
7394,
12812,
421,
199,
533,
12904,
2028,
12812,
547,
8,
1726,
304,
272,
408,
272,
4520,
8920,
1830,
22200,
5897,
1101,
10949,
14,
272,
408,
272,
986,
421,
199,
533,
12904,
2028,
12812,
8,
21025,
7394,
12812,
304,
272,
408,
272,
31574,
4167,
370,
1218,
14512,
2897,
367,
282,
2518,
272,
408,
272,
14512,
275,
942,
339,
347,
636,
826,
721,
277,
12,
2518,
63,
344,
12,
14512,
63,
576,
304,
267,
291,
14,
1972,
63,
344,
275,
2518,
63,
344,
267,
291,
14,
16159,
275,
14512,
63,
576,
267,
1613,
8,
11414,
2028,
12812,
12,
291,
2843,
826,
4533,
339,
347,
3907,
8,
277,
304,
267,
408,
267,
22643,
314,
14512,
1101,
666,
370,
5897,
6037,
14,
267,
408,
267,
1177,
275,
291,
14,
1730,
14,
1932,
8,
288,
9005,
15,
16159,
30837,
908,
8,
840,
53,
19283,
63,
5825,
63,
2632,
12,
291,
14,
1972,
63,
344,
395,
288,
666,
29,
1001,
14,
4180,
8,
277,
14,
16159,
395,
288,
2323,
29,
277,
14,
2139,
267,
776,
398,
340,
440,
1177,
14,
745,
26,
288,
746,
12904,
2028,
12812,
547,
8,
355,
298,
6531,
440,
1218,
5897,
469,
16,
5565,
221,
9795,
1990,
469,
17,
5469,
908,
8,
490,
2022,
14,
4180,
8,
277,
14,
16159,
395,
1177,
14,
1205,
63,
600,
355,
776,
288,
776,
398,
372,
291,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
11654,
367,
6425,
14512,
1101,
10949,
666,
14,
199,
624,
199,
199,
646,
2022,
199,
199,
504,
1275,
492,
4384,
53,
19283,
63,
5825,
63,
2632,
199,
504,
1275,
1095,
492,
13225,
7394,
12812,
421,
199,
533,
12904,
2028,
12812,
547,
8,
1726,
304,
272,
408,
272,
4520,
8920,
1830,
22200,
5897,
1101,
10949,
14,
272,
408,
272,
986,
421,
199,
533,
12904,
2028,
12812,
8,
21025,
7394,
12812,
304,
272,
408,
272,
31574,
4167,
370,
1218,
14512,
2897,
367,
282,
2518,
272,
408,
272,
14512,
275,
942,
339,
347,
636,
826,
721,
277,
12,
2518,
63,
344,
12,
14512,
63,
576,
304,
267,
291,
14,
1972,
63,
344,
275,
2518,
63,
344,
267,
291,
14,
16159,
275,
14512,
63,
576,
267,
1613,
8,
11414,
2028,
12812,
12,
291,
2843,
826,
4533,
339,
347,
3907,
8,
277,
304,
267,
408,
267,
22643,
314,
14512,
1101,
666,
370,
5897,
6037,
14,
267,
408,
267,
1177,
275,
291,
14,
1730,
14,
1932,
8,
288,
9005,
15,
16159,
30837,
908,
8,
840,
53,
19283,
63,
5825,
63,
2632,
12,
291,
14,
1972,
63,
344,
395,
288,
666,
29,
1001,
14,
4180,
8,
277,
14,
16159,
395,
288,
2323,
29,
277,
14,
2139,
267,
776,
398,
340,
440,
1177,
14,
745,
26,
288,
746,
12904,
2028,
12812,
547,
8,
355,
298,
6531,
440,
1218,
5897,
469,
16,
5565,
221,
9795,
1990,
469,
17,
5469,
908,
8,
490,
2022,
14,
4180,
8,
277,
14,
16159,
395,
1177,
14,
1205,
63,
600,
355,
776,
288,
776,
398,
372,
291,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
paulbersch/django-locus
|
locus/utils/location.py
|
1
|
1360
|
import math
# add back later
# import GeoIP
nauticalMilePerLat = 60.00721
nauticalMilePerLongitude = 60.10793
rad = math.pi / 180.0
milesPerNauticalMile = 1.15078
def calcDistance(lat1, lon1, lat2, lon2):
"""
Caclulate distance between two lat lons in NM
"""
lat1 = float(lat1)
lat2 = float(lat2)
lon1 = float(lon1)
lon2 = float(lon2)
yDistance = (lat2 - lat1) * nauticalMilePerLat
xDistance = (math.cos(lat1 * rad) + math.cos(lat2 * rad)) * (lon2 - lon1) * (nauticalMilePerLongitude / 2)
distance = math.sqrt( yDistance**2 + xDistance**2 )
return distance * milesPerNauticalMile
def milesBox( lat, lon, radius ):
"""
Returns two lat/lon pairs as (lat1, lon2, lat2, lon2) which define a box that exactly surrounds
a circle of radius of the given amount in miles.
"""
# this gives us a tuple of values that can easily be used to get a list of "possibly close"
# dealers. then we use the calcDistance function to check if it's ACTUALLY within the radius.
latRange = radius / ( milesPerNauticalMile * 60.0 )
lonRange = radius / ( math.cos(lat * rad) * milesPerNauticalMile * 60.0)
return ( lat - latRange, lon - lonRange, lat + latRange, lon + lonRange )
def revLookup(ip):
return False
"""
gi = GeoIP.open("/usr/local/share/GeoIP/GeoLiteCity.dat",GeoIP.GEOIP_STANDARD)
return gi.record_by_addr(ip)
"""
|
mit
|
[
646,
3473,
199,
3,
1050,
1771,
2945,
199,
3,
492,
18378,
199,
199,
3540,
85,
3294,
45,
441,
2623,
22510,
275,
5212,
14,
8255,
2025,
199,
3540,
85,
3294,
45,
441,
2623,
9551,
7779,
275,
5212,
14,
709,
26153,
199,
9525,
275,
3473,
14,
1038,
1182,
13576,
14,
16,
199,
77,
22894,
2623,
46,
3844,
3294,
45,
441,
275,
413,
14,
1046,
19226,
199,
199,
318,
12831,
10076,
8,
4452,
17,
12,
6132,
17,
12,
8396,
18,
12,
6132,
18,
304,
9668,
199,
198,
624,
199,
198,
3630,
429,
5434,
6033,
3382,
2877,
8396,
634,
4654,
315,
653,
45,
199,
198,
624,
199,
198,
4452,
17,
275,
2069,
8,
4452,
17,
9,
199,
198,
4452,
18,
275,
2069,
8,
4452,
18,
9,
199,
198,
5298,
17,
275,
2069,
8,
5298,
17,
9,
199,
198,
5298,
18,
275,
2069,
8,
5298,
18,
9,
199,
198,
89,
10076,
275,
334,
4452,
18,
446,
8396,
17,
9,
627,
302,
3844,
3294,
45,
441,
2623,
22510,
199,
198,
88,
10076,
275,
334,
3442,
14,
5197,
8,
4452,
17,
627,
28880,
9,
435,
3473,
14,
5197,
8,
4452,
18,
627,
28880,
430,
627,
334,
5298,
18,
446,
6132,
17,
9,
627,
334,
3540,
85,
3294,
45,
441,
2623,
9551,
7779,
1182,
499,
9,
421,
198,
5590,
275,
3473,
14,
5079,
8,
612,
10076,
538,
18,
435,
671,
10076,
538,
18,
776,
421,
198,
1107,
6033,
627,
333,
22894,
2623,
46,
3844,
3294,
45,
441,
199,
199,
318,
333,
22894,
3532,
8,
8396,
12,
6132,
12,
9362,
3461,
199,
198,
624,
199,
198,
3407,
2877,
8396,
15,
5298,
6342,
465,
334,
4452,
17,
12,
6132,
18,
12,
8396,
18,
12,
6132,
18,
9,
1314,
5627,
282,
5689,
626,
8840,
6296,
23171,
199,
198,
65,
17990,
402,
9362,
402,
314,
1627,
5982,
315,
333,
22894,
14,
199,
198,
624,
421,
198,
3,
642,
10557,
2739,
282,
2008,
402,
1338,
626,
883,
16174,
506,
1202,
370,
664,
282,
769,
402,
298,
19614,
4002,
2,
199,
198,
3,
477,
65,
29099,
14,
221,
2066,
781,
675,
314,
12831,
10076,
805,
370,
1104,
340,
652,
1159,
21401,
53,
28292,
4453,
314,
9362,
14,
199,
198,
4452,
4709,
275,
9362,
1182,
334,
333,
22894,
2623,
46,
3844,
3294,
45,
441,
627,
5212,
14,
16,
776,
199,
198,
5298,
4709,
275,
9362,
1182,
334,
3473,
14,
5197,
8,
4452,
627,
28880,
9,
627,
333,
22894,
2623,
46,
3844,
3294,
45,
441,
627,
5212,
14,
16,
9,
421,
198,
1107,
334,
8396,
446,
8396,
4709,
12,
6132,
446,
6132,
4709,
12,
8396,
435,
8396,
4709,
12,
6132,
435,
6132,
4709,
776,
421,
199,
318,
6822,
7521,
8,
711,
304,
272,
372,
756,
199,
199,
624,
199,
198,
6153,
275,
18378,
14,
1490,
4769,
2647,
15,
1832,
15,
6251,
15,
28848,
15,
10748,
19375,
17024,
14,
4616,
401,
28848,
14,
18120,
1772,
63,
19547,
9,
421,
198,
1107,
18895,
14,
3059,
63,
991,
63,
2697,
8,
711,
9,
199,
624,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3473,
199,
3,
1050,
1771,
2945,
199,
3,
492,
18378,
199,
199,
3540,
85,
3294,
45,
441,
2623,
22510,
275,
5212,
14,
8255,
2025,
199,
3540,
85,
3294,
45,
441,
2623,
9551,
7779,
275,
5212,
14,
709,
26153,
199,
9525,
275,
3473,
14,
1038,
1182,
13576,
14,
16,
199,
77,
22894,
2623,
46,
3844,
3294,
45,
441,
275,
413,
14,
1046,
19226,
199,
199,
318,
12831,
10076,
8,
4452,
17,
12,
6132,
17,
12,
8396,
18,
12,
6132,
18,
304,
9668,
199,
198,
624,
199,
198,
3630,
429,
5434,
6033,
3382,
2877,
8396,
634,
4654,
315,
653,
45,
199,
198,
624,
199,
198,
4452,
17,
275,
2069,
8,
4452,
17,
9,
199,
198,
4452,
18,
275,
2069,
8,
4452,
18,
9,
199,
198,
5298,
17,
275,
2069,
8,
5298,
17,
9,
199,
198,
5298,
18,
275,
2069,
8,
5298,
18,
9,
199,
198,
89,
10076,
275,
334,
4452,
18,
446,
8396,
17,
9,
627,
302,
3844,
3294,
45,
441,
2623,
22510,
199,
198,
88,
10076,
275,
334,
3442,
14,
5197,
8,
4452,
17,
627,
28880,
9,
435,
3473,
14,
5197,
8,
4452,
18,
627,
28880,
430,
627,
334,
5298,
18,
446,
6132,
17,
9,
627,
334,
3540,
85,
3294,
45,
441,
2623,
9551,
7779,
1182,
499,
9,
421,
198,
5590,
275,
3473,
14,
5079,
8,
612,
10076,
538,
18,
435,
671,
10076,
538,
18,
776,
421,
198,
1107,
6033,
627,
333,
22894,
2623,
46,
3844,
3294,
45,
441,
199,
199,
318,
333,
22894,
3532,
8,
8396,
12,
6132,
12,
9362,
3461,
199,
198,
624,
199,
198,
3407,
2877,
8396,
15,
5298,
6342,
465,
334,
4452,
17,
12,
6132,
18,
12,
8396,
18,
12,
6132,
18,
9,
1314,
5627,
282,
5689,
626,
8840,
6296,
23171,
199,
198,
65,
17990,
402,
9362,
402,
314,
1627,
5982,
315,
333,
22894,
14,
199,
198,
624,
421,
198,
3,
642,
10557,
2739,
282,
2008,
402,
1338,
626,
883,
16174,
506,
1202,
370,
664,
282,
769,
402,
298,
19614,
4002,
2,
199,
198,
3,
477,
65,
29099,
14,
221,
2066,
781,
675,
314,
12831,
10076,
805,
370,
1104,
340,
652,
1159,
21401,
53,
28292,
4453,
314,
9362,
14,
199,
198,
4452,
4709,
275,
9362,
1182,
334,
333,
22894,
2623,
46,
3844,
3294,
45,
441,
627,
5212,
14,
16,
776,
199,
198,
5298,
4709,
275,
9362,
1182,
334,
3473,
14,
5197,
8,
4452,
627,
28880,
9,
627,
333,
22894,
2623,
46,
3844,
3294,
45,
441,
627,
5212,
14,
16,
9,
421,
198,
1107,
334,
8396,
446,
8396,
4709,
12,
6132,
446,
6132,
4709,
12,
8396,
435,
8396,
4709,
12,
6132,
435,
6132,
4709,
776,
421,
199,
318,
6822,
7521,
8,
711,
304,
272,
372,
756,
199,
199,
624,
199,
198,
6153,
275,
18378,
14,
1490,
4769,
2647,
15,
1832,
15,
6251,
15,
28848,
15,
10748,
19375,
17024,
14,
4616,
401,
28848,
14,
18120,
1772,
63,
19547,
9,
421,
198,
1107,
18895,
14,
3059,
63,
991,
63,
2697,
8,
711,
9,
199,
624,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
etashjian/ECE757-final
|
configs/topologies/Cluster.py
|
41
|
4886
|
# Copyright (c) 2012 Advanced Micro Devices, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met: redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer;
# redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution;
# neither the name of the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Authors: Jason Power
from BaseTopology import BaseTopology
class Cluster(BaseTopology):
""" A cluster is a group of nodes which are all one hop from eachother
Clusters can also contain other clusters
When creating this kind of topology, return a single cluster (usually
the root cluster) from create_system in configs/ruby/<protocol>.py
"""
_num_int_links = 0
_num_ext_links = 0
_num_routers = 0
# Below methods for auto counting
@classmethod
def num_int_links(cls):
cls._num_int_links += 1
return cls._num_int_links - 1
@classmethod
def num_ext_links(cls):
cls._num_ext_links += 1
return cls._num_ext_links - 1
@classmethod
def num_routers(cls):
cls._num_routers += 1
return cls._num_routers - 1
def __init__(self, intBW=0, extBW=0, intLatency=0, extLatency=0):
""" internalBandwidth is bandwidth of all links within the cluster
externalBandwidth is bandwidth from this cluster to any cluster
connecting to it.
internal/externalLatency are similar
**** When creating a cluster with sub-clusters, the sub-cluster
external bandwidth overrides the internal bandwidth of the
super cluster
"""
self.nodes = []
self.router = None # created in makeTopology
self.intBW = intBW
self.extBW = extBW
self.intLatency = intLatency
self.extLatency = extLatency
def add(self, node):
self.nodes.append(node)
def makeTopology(self, options, network, IntLink, ExtLink, Router):
""" Recursively make all of the links and routers
"""
# make a router to connect all of the nodes
self.router = Router(router_id=self.num_routers())
network.routers.append(self.router)
for node in self.nodes:
if type(node) == Cluster:
node.makeTopology(options, network, IntLink, ExtLink, Router)
# connect this cluster to the router
link = IntLink(link_id=self.num_int_links(), node_a=self.router,
node_b=node.router)
if node.extBW:
link.bandwidth_factor = node.extBW
# if there is an interanl b/w for this node
# and no ext b/w to override
elif self.intBW:
link.bandwidth_factor = self.intBW
if node.extLatency:
link.latency = node.extLatency
elif self.intLatency:
link.latency = self.intLatency
network.int_links.append(link)
else:
# node is just a controller,
# connect it to the router via a ext_link
link = ExtLink(link_id=self.num_ext_links(), ext_node=node,
int_node=self.router)
if self.intBW:
link.bandwidth_factor = self.intBW
if self.intLatency:
link.latency = self.intLatency
network.ext_links.append(link)
def __len__(self):
return len([i for i in self.nodes if type(i) != Cluster]) + \
sum([len(i) for i in self.nodes if type(i) == Cluster])
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
6029,
32445,
27022,
12272,
83,
12,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
1603,
2660,
18879,
421,
199,
504,
3523,
15696,
492,
3523,
15696,
199,
199,
533,
16454,
8,
1563,
15696,
304,
272,
408,
437,
4350,
365,
282,
1572,
402,
3380,
1314,
787,
1006,
1373,
22377,
687,
1924,
1848,
267,
8465,
6811,
883,
2597,
1395,
1163,
13865,
267,
3979,
6425,
642,
4928,
402,
14611,
12,
372,
282,
2849,
4350,
334,
25118,
267,
314,
1738,
4350,
9,
687,
1218,
63,
2253,
315,
11585,
15,
21952,
8316,
3922,
10827,
647,
272,
408,
339,
485,
1507,
63,
442,
63,
4614,
275,
378,
272,
485,
1507,
63,
832,
63,
4614,
275,
378,
272,
485,
1507,
63,
17292,
275,
378,
339,
327,
6423,
674,
3102,
367,
2599,
23190,
272,
768,
3744,
272,
347,
1967,
63,
442,
63,
4614,
8,
1886,
304,
267,
843,
423,
1507,
63,
442,
63,
4614,
847,
413,
267,
372,
843,
423,
1507,
63,
442,
63,
4614,
446,
413,
272,
768,
3744,
272,
347,
1967,
63,
832,
63,
4614,
8,
1886,
304,
267,
843,
423,
1507,
63,
832,
63,
4614,
847,
413,
267,
372,
843,
423,
1507,
63,
832,
63,
4614,
446,
413,
272,
768,
3744,
272,
347,
1967,
63,
17292,
8,
1886,
304,
267,
843,
423,
1507,
63,
17292,
847,
413,
267,
372,
843,
423,
1507,
63,
17292,
446,
413,
339,
347,
636,
826,
721,
277,
12,
1109,
18344,
29,
16,
12,
1599,
18344,
29,
16,
12,
1109,
16500,
12501,
29,
16,
12,
1599,
16500,
12501,
29,
16,
304,
267,
408,
5007,
25859,
365,
20434,
402,
1006,
6220,
4453,
314,
4350,
288,
5957,
25859,
365,
20434,
687,
642,
4350,
370,
1263,
4350,
355,
18170,
370,
652,
14,
288,
5007,
15,
5159,
16500,
12501,
787,
8545,
288,
1011,
538,
3979,
6425,
282,
4350,
543,
1007,
13,
9170,
12,
314,
1007,
13,
4201,
326,
5957,
20434,
10580,
314,
5007,
20434,
402,
314,
326,
1613,
4350,
267,
408,
267,
291,
14,
2415,
275,
942,
267,
291,
14,
4995,
275,
488,
327,
2737,
315,
1852,
15696,
267,
291,
14,
442,
18344,
275,
1109,
18344,
267,
291,
14,
832,
18344,
275,
1599,
18344,
267,
291,
14,
442,
16500,
12501,
275,
1109,
16500,
12501,
267,
291,
14,
832,
16500,
12501,
275,
1599,
16500,
12501,
339,
347,
1050,
8,
277,
12,
1031,
304,
267,
291,
14,
2415,
14,
740,
8,
932,
9,
339,
347,
1852,
15696,
8,
277,
12,
1511,
12,
2784,
12,
9805,
3834,
12,
7255,
3834,
12,
22708,
304,
267,
408,
18306,
9840,
1852,
1006,
402,
314,
6220,
436,
24464,
267,
408,
398,
327,
1852,
282,
6197,
370,
4907,
1006,
402,
314,
3380,
267,
291,
14,
4995,
275,
22708,
8,
4995,
63,
344,
29,
277,
14,
1507,
63,
17292,
1012,
267,
2784,
14,
17292,
14,
740,
8,
277,
14,
4995,
9,
398,
367,
1031,
315,
291,
14,
2415,
26,
288,
340,
730,
8,
932,
9,
508,
16454,
26,
355,
1031,
14,
1875,
15696,
8,
1419,
12,
2784,
12,
9805,
3834,
12,
7255,
3834,
12,
22708,
9,
2234,
327,
4907,
642,
4350,
370,
314,
6197,
355,
2142,
275,
9805,
3834,
8,
1073,
63,
344,
29,
277,
14,
1507,
63,
442,
63,
4614,
1062,
1031,
63,
65,
29,
277,
14,
4995,
12,
717,
1031,
63,
66,
29,
932,
14,
4995,
9,
2234,
340,
1031,
14,
832,
18344,
26,
490,
2142,
14,
18358,
63,
4778,
275,
1031,
14,
832,
18344,
2234,
327,
340,
2337,
365,
376,
1640,
290,
76,
330,
15,
87,
367,
642,
1031,
355,
327,
436,
949,
1599,
330,
15,
87,
370,
4278,
355,
916,
291,
14,
442,
18344,
26,
490,
2142,
14,
18358,
63,
4778,
275,
291,
14,
442,
18344,
2234,
340,
1031,
14,
832,
16500,
12501,
26,
490,
2142,
14,
19645,
275,
1031,
14,
832,
16500,
12501,
355,
916,
291,
14,
442,
16500,
12501,
26,
490,
2142,
14,
19645,
275,
291,
14,
442,
16500,
12501,
2234,
2784,
14,
442,
63,
4614,
14,
740,
8,
1073,
9,
288,
587,
26,
355,
327,
1031,
365,
2951,
282,
7614,
12,
355,
327,
4907,
652,
370,
314,
6197,
4799,
282,
1599,
63,
1073,
355,
2142,
275,
7255,
3834,
8,
1073,
63,
344,
29,
277,
14,
1507,
63,
832,
63,
4614,
1062,
1599,
63,
932,
29,
932,
12,
717,
1109,
63,
932,
29,
277,
14,
4995,
9,
2234,
340,
291,
14,
442,
18344,
26,
490,
2142,
14,
18358,
63,
4778,
275,
291,
14,
442,
18344,
355,
340
] |
[
1898,
334,
67,
9,
6029,
32445,
27022,
12272,
83,
12,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
1603,
2660,
18879,
421,
199,
504,
3523,
15696,
492,
3523,
15696,
199,
199,
533,
16454,
8,
1563,
15696,
304,
272,
408,
437,
4350,
365,
282,
1572,
402,
3380,
1314,
787,
1006,
1373,
22377,
687,
1924,
1848,
267,
8465,
6811,
883,
2597,
1395,
1163,
13865,
267,
3979,
6425,
642,
4928,
402,
14611,
12,
372,
282,
2849,
4350,
334,
25118,
267,
314,
1738,
4350,
9,
687,
1218,
63,
2253,
315,
11585,
15,
21952,
8316,
3922,
10827,
647,
272,
408,
339,
485,
1507,
63,
442,
63,
4614,
275,
378,
272,
485,
1507,
63,
832,
63,
4614,
275,
378,
272,
485,
1507,
63,
17292,
275,
378,
339,
327,
6423,
674,
3102,
367,
2599,
23190,
272,
768,
3744,
272,
347,
1967,
63,
442,
63,
4614,
8,
1886,
304,
267,
843,
423,
1507,
63,
442,
63,
4614,
847,
413,
267,
372,
843,
423,
1507,
63,
442,
63,
4614,
446,
413,
272,
768,
3744,
272,
347,
1967,
63,
832,
63,
4614,
8,
1886,
304,
267,
843,
423,
1507,
63,
832,
63,
4614,
847,
413,
267,
372,
843,
423,
1507,
63,
832,
63,
4614,
446,
413,
272,
768,
3744,
272,
347,
1967,
63,
17292,
8,
1886,
304,
267,
843,
423,
1507,
63,
17292,
847,
413,
267,
372,
843,
423,
1507,
63,
17292,
446,
413,
339,
347,
636,
826,
721,
277,
12,
1109,
18344,
29,
16,
12,
1599,
18344,
29,
16,
12,
1109,
16500,
12501,
29,
16,
12,
1599,
16500,
12501,
29,
16,
304,
267,
408,
5007,
25859,
365,
20434,
402,
1006,
6220,
4453,
314,
4350,
288,
5957,
25859,
365,
20434,
687,
642,
4350,
370,
1263,
4350,
355,
18170,
370,
652,
14,
288,
5007,
15,
5159,
16500,
12501,
787,
8545,
288,
1011,
538,
3979,
6425,
282,
4350,
543,
1007,
13,
9170,
12,
314,
1007,
13,
4201,
326,
5957,
20434,
10580,
314,
5007,
20434,
402,
314,
326,
1613,
4350,
267,
408,
267,
291,
14,
2415,
275,
942,
267,
291,
14,
4995,
275,
488,
327,
2737,
315,
1852,
15696,
267,
291,
14,
442,
18344,
275,
1109,
18344,
267,
291,
14,
832,
18344,
275,
1599,
18344,
267,
291,
14,
442,
16500,
12501,
275,
1109,
16500,
12501,
267,
291,
14,
832,
16500,
12501,
275,
1599,
16500,
12501,
339,
347,
1050,
8,
277,
12,
1031,
304,
267,
291,
14,
2415,
14,
740,
8,
932,
9,
339,
347,
1852,
15696,
8,
277,
12,
1511,
12,
2784,
12,
9805,
3834,
12,
7255,
3834,
12,
22708,
304,
267,
408,
18306,
9840,
1852,
1006,
402,
314,
6220,
436,
24464,
267,
408,
398,
327,
1852,
282,
6197,
370,
4907,
1006,
402,
314,
3380,
267,
291,
14,
4995,
275,
22708,
8,
4995,
63,
344,
29,
277,
14,
1507,
63,
17292,
1012,
267,
2784,
14,
17292,
14,
740,
8,
277,
14,
4995,
9,
398,
367,
1031,
315,
291,
14,
2415,
26,
288,
340,
730,
8,
932,
9,
508,
16454,
26,
355,
1031,
14,
1875,
15696,
8,
1419,
12,
2784,
12,
9805,
3834,
12,
7255,
3834,
12,
22708,
9,
2234,
327,
4907,
642,
4350,
370,
314,
6197,
355,
2142,
275,
9805,
3834,
8,
1073,
63,
344,
29,
277,
14,
1507,
63,
442,
63,
4614,
1062,
1031,
63,
65,
29,
277,
14,
4995,
12,
717,
1031,
63,
66,
29,
932,
14,
4995,
9,
2234,
340,
1031,
14,
832,
18344,
26,
490,
2142,
14,
18358,
63,
4778,
275,
1031,
14,
832,
18344,
2234,
327,
340,
2337,
365,
376,
1640,
290,
76,
330,
15,
87,
367,
642,
1031,
355,
327,
436,
949,
1599,
330,
15,
87,
370,
4278,
355,
916,
291,
14,
442,
18344,
26,
490,
2142,
14,
18358,
63,
4778,
275,
291,
14,
442,
18344,
2234,
340,
1031,
14,
832,
16500,
12501,
26,
490,
2142,
14,
19645,
275,
1031,
14,
832,
16500,
12501,
355,
916,
291,
14,
442,
16500,
12501,
26,
490,
2142,
14,
19645,
275,
291,
14,
442,
16500,
12501,
2234,
2784,
14,
442,
63,
4614,
14,
740,
8,
1073,
9,
288,
587,
26,
355,
327,
1031,
365,
2951,
282,
7614,
12,
355,
327,
4907,
652,
370,
314,
6197,
4799,
282,
1599,
63,
1073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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
] |
KaranToor/MA450
|
google-cloud-sdk/platform/bq/ez_setup.py
|
38
|
8357
|
#!/usr/bin/env python
"""Bootstrap setuptools installation
If you want to use setuptools in your package's setup.py, just include this
file in the same directory with it, and add this to the top of your setup.py::
from ez_setup import use_setuptools
use_setuptools()
If you want to require a specific version of setuptools, set a download
mirror, or use an alternate download directory, you can do so by supplying
the appropriate options to ``use_setuptools()``.
This file can also be run as a script to install or upgrade setuptools.
"""
import sys
DEFAULT_VERSION = "0.6c11"
DEFAULT_URL = "http://pypi.python.org/packages/%s/s/setuptools/" % sys.version[:3]
md5_data = {
'setuptools-0.6c10-py2.3.egg': 'ce1e2ab5d3a0256456d9fc13800a7090',
'setuptools-0.6c10-py2.4.egg': '57d6d9d6e9b80772c59a53a8433a5dd4',
'setuptools-0.6c10-py2.5.egg': 'de46ac8b1c97c895572e5e8596aeb8c7',
'setuptools-0.6c10-py2.6.egg': '58ea40aef06da02ce641495523a0b7f5',
'setuptools-0.6c11-py2.3.egg': '2baeac6e13d414a9d28e7ba5b5a596de',
'setuptools-0.6c11-py2.4.egg': 'bd639f9b0eac4c42497034dec2ec0c2b',
'setuptools-0.6c11-py2.5.egg': '64c94f3bf7a72a13ec83e0b24f2749b2',
'setuptools-0.6c11-py2.6.egg': 'bfa92100bd772d5a213eedd356d64086',
'setuptools-0.6c8-py2.3.egg': '50759d29b349db8cfd807ba8303f1902',
'setuptools-0.6c8-py2.4.egg': 'cba38d74f7d483c06e9daa6070cce6de',
'setuptools-0.6c8-py2.5.egg': '1721747ee329dc150590a58b3e1ac95b',
'setuptools-0.6c9-py2.3.egg': 'a83c4020414807b496e4cfbe08507c03',
'setuptools-0.6c9-py2.4.egg': '260a2be2e5388d66bdaee06abec6342a',
'setuptools-0.6c9-py2.5.egg': 'fe67c3e5a17b12c0e7c541b7ea43a8e6',
'setuptools-0.6c9-py2.6.egg': 'ca37b1ff16fa2ede6e19383e7b59245a',
}
import sys, os
try: from hashlib import md5
except ImportError: from md5 import md5
def _validate_md5(egg_name, data):
if egg_name in md5_data:
digest = md5(data).hexdigest()
if digest != md5_data[egg_name]:
print >>sys.stderr, (
"md5 validation of %s failed! (Possible download problem?)"
% egg_name
)
sys.exit(2)
return data
def use_setuptools(
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
download_delay=15
):
"""Automatically find/download setuptools and make it available on sys.path
`version` should be a valid setuptools version number that is available
as an egg for download under the `download_base` URL (which should end with
a '/'). `to_dir` is the directory where setuptools will be downloaded, if
it is not already available. If `download_delay` is specified, it should
be the number of seconds that will be paused before initiating a download,
should one be required. If an older version of setuptools is installed,
this routine will print a message to ``sys.stderr`` and raise SystemExit in
an attempt to abort the calling script.
"""
was_imported = 'pkg_resources' in sys.modules or 'setuptools' in sys.modules
def do_download():
egg = download_setuptools(version, download_base, to_dir, download_delay)
sys.path.insert(0, egg)
import setuptools; setuptools.bootstrap_install_from = egg
try:
import pkg_resources
except ImportError:
return do_download()
try:
pkg_resources.require("setuptools>="+version); return
except pkg_resources.VersionConflict, e:
if was_imported:
print >>sys.stderr, (
"The required version of setuptools (>=%s) is not available, and\n"
"can't be installed while this script is running. Please install\n"
" a more recent version first, using 'easy_install -U setuptools'."
"\n\n(Currently using %r)"
) % (version, e.args[0])
sys.exit(2)
except pkg_resources.DistributionNotFound:
pass
del pkg_resources, sys.modules['pkg_resources'] # reload ok
return do_download()
def download_setuptools(
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
delay = 15
):
"""Download setuptools from a specified location and return its filename
`version` should be a valid setuptools version number that is available
as an egg for download under the `download_base` URL (which should end
with a '/'). `to_dir` is the directory where the egg will be downloaded.
`delay` is the number of seconds to pause before an actual download attempt.
"""
import urllib2, shutil
egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3])
url = download_base + egg_name
saveto = os.path.join(to_dir, egg_name)
src = dst = None
if not os.path.exists(saveto): # Avoid repeated downloads
try:
from distutils import log
if delay:
log.warn("""
---------------------------------------------------------------------------
This script requires setuptools version %s to run (even to display
help). I will attempt to download it for you (from
%s), but
you may need to enable firewall access for this script first.
I will start the download in %d seconds.
(Note: if this machine does not have network access, please obtain the file
%s
and place it in this directory before rerunning this script.)
---------------------------------------------------------------------------""",
version, download_base, delay, url
); from time import sleep; sleep(delay)
log.warn("Downloading %s", url)
src = urllib2.urlopen(url)
# Read/write all in one block, so we don't create a corrupt file
# if the download is interrupted.
data = _validate_md5(egg_name, src.read())
dst = open(saveto,"wb"); dst.write(data)
finally:
if src: src.close()
if dst: dst.close()
return os.path.realpath(saveto)
def main(argv, version=DEFAULT_VERSION):
"""Install or upgrade setuptools and EasyInstall"""
try:
import setuptools
except ImportError:
egg = None
try:
egg = download_setuptools(version, delay=0)
sys.path.insert(0,egg)
from setuptools.command.easy_install import main
return main(list(argv)+[egg]) # we're done here
finally:
if egg and os.path.exists(egg):
os.unlink(egg)
else:
if setuptools.__version__ == '0.0.1':
print >>sys.stderr, (
"You have an obsolete version of setuptools installed. Please\n"
"remove it from your system entirely before rerunning this script."
)
sys.exit(2)
req = "setuptools>="+version
import pkg_resources
try:
pkg_resources.require(req)
except pkg_resources.VersionConflict:
try:
from setuptools.command.easy_install import main
except ImportError:
from easy_install import main
main(list(argv)+[download_setuptools(delay=0)])
sys.exit(0) # try to force an exit
else:
if argv:
from setuptools.command.easy_install import main
main(argv)
else:
print "Setuptools version",version,"or greater has been installed."
print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)'
def update_md5(filenames):
"""Update our built-in md5 registry"""
import re
for name in filenames:
base = os.path.basename(name)
f = open(name,'rb')
md5_data[base] = md5(f.read()).hexdigest()
f.close()
data = [" %r: %r,\n" % it for it in md5_data.items()]
data.sort()
repl = "".join(data)
import inspect
srcfile = inspect.getsourcefile(sys.modules[__name__])
f = open(srcfile, 'rb'); src = f.read(); f.close()
match = re.search("\nmd5_data = {\n([^}]+)}", src)
if not match:
print >>sys.stderr, "Internal error!"
sys.exit(2)
src = src[:match.start(1)] + repl + src[match.end(1):]
f = open(srcfile,'w')
f.write(src)
f.close()
if __name__=='__main__':
if len(sys.argv)>2 and sys.argv[1]=='--md5update':
update_md5(sys.argv[2:])
else:
main(sys.argv[1:])
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
17989,
7868,
9116,
12096,
199,
199,
3917,
1265,
2934,
370,
675,
9116,
315,
2195,
2559,
1159,
3272,
14,
647,
12,
2951,
2387,
642,
199,
493,
315,
314,
2011,
2082,
543,
652,
12,
436,
1050,
642,
370,
314,
2746,
402,
2195,
3272,
14,
647,
447,
339,
687,
325,
90,
63,
2758,
492,
675,
63,
13623,
272,
675,
63,
13623,
342,
199,
199,
3917,
1265,
2934,
370,
4409,
282,
2488,
1015,
402,
9116,
12,
663,
282,
5235,
199,
12324,
12,
503,
675,
376,
18034,
5235,
2082,
12,
1265,
883,
886,
880,
701,
4973,
6670,
199,
1589,
5827,
1511,
370,
1124,
1180,
63,
13623,
28566,
199,
199,
2765,
570,
883,
2597,
506,
1255,
465,
282,
2884,
370,
3907,
503,
10754,
9116,
14,
199,
624,
199,
646,
984,
199,
3472,
63,
4612,
275,
298,
16,
14,
22,
67,
845,
2,
199,
3472,
63,
2632,
258,
275,
298,
1014,
921,
17343,
14,
1548,
14,
1308,
15,
5154,
3149,
83,
15,
83,
15,
13623,
6687,
450,
984,
14,
1023,
1491,
19,
61,
199,
199,
1064,
21,
63,
576,
275,
469,
272,
283,
13623,
13,
16,
14,
22,
67,
709,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
301,
17,
69,
18,
371,
21,
68,
19,
65,
18823,
772,
1367,
68,
25,
3003,
969,
6718,
65,
23,
18526,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
709,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
1641,
68,
22,
68,
25,
68,
22,
69,
25,
66,
1257,
19518,
67,
1427,
65,
2481,
65,
1349,
1153,
65,
21,
617,
20,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
709,
13,
647,
18,
14,
21,
14,
5799,
356,
283,
271,
2466,
645,
24,
66,
17,
67,
2576,
67,
1407,
1229,
2819,
69,
21,
69,
24,
15112,
65,
2871,
24,
67,
23,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
709,
13,
647,
18,
14,
22,
14,
5799,
356,
283,
2010,
4489,
2167,
65,
2829,
1690,
983,
996,
301,
772,
10721,
1229,
1789,
65,
16,
66,
23,
70,
21,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
845,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
18,
28363,
645,
22,
69,
969,
68,
25250,
65,
25,
68,
1651,
69,
23,
2470,
21,
66,
21,
65,
15112,
271,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
845,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
3691,
26723,
70,
25,
66,
16,
28870,
20,
67,
21089,
20598,
1082,
7778,
18,
825,
16,
67,
18,
66,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
845,
13,
647,
18,
14,
21,
14,
5799,
356,
283,
772,
67,
2635,
70,
19,
4361,
23,
65,
2819,
65,
969,
825,
2658,
69,
16,
66,
1194,
70,
9014,
25,
66,
18,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
845,
13,
647,
18,
14,
22,
14,
5799,
356,
283,
66,
667,
2942,
1960,
3691,
19518,
68,
21,
65,
14271,
69,
31151,
13251,
68,
12021,
1184,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
24,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
13583,
1427,
68,
1398,
66,
11991,
697,
24,
27901,
11369,
2470,
24,
11810,
70,
1167,
996,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
24,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
28995,
1703,
68,
1342,
70,
23,
68,
23946,
67,
1690,
69,
25,
30908,
16059,
16,
67,
301,
22,
271,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
24,
13,
647,
18,
14,
21,
14,
5799,
356,
283,
1196,
9335,
2417,
1024,
11685,
3833,
8251,
15458,
65,
2010,
66,
19,
69,
17,
645,
2720,
66,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
25,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
65,
2658,
67,
13314,
966,
1079,
11369,
66,
18105,
69,
20,
2177,
1235,
2036,
13583,
67,
1644,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
25,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
13085,
65,
18,
1235,
18,
69,
2481,
1299,
68,
1272,
66,
983,
1024,
1690,
371,
825,
22,
14519,
65,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
25,
13,
647,
18,
14,
21,
14,
5799,
356,
283,
771,
1822,
67,
19,
69,
21,
65,
1196,
66,
713,
67,
16,
69,
23,
67,
21278,
66,
23,
4489,
2824,
65,
24,
69,
22,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
25,
13,
647,
18,
14,
22,
14,
5799,
356,
283,
696,
1401,
66,
17,
556,
975,
667,
18,
69,
271,
22,
69,
1167,
15504,
69,
23,
66,
1427,
11677,
65,
297,
199,
93,
199,
199,
646,
984,
12,
747,
199,
893,
26,
687,
8337,
492,
6128,
21,
199,
2590,
3545,
26,
687,
6128,
21,
492,
6128,
21,
199,
199,
318,
485,
3502,
63,
1064,
21,
8,
5799,
63,
354,
12,
666,
304,
272,
340,
11393,
63,
354,
315,
6128,
21,
63,
576,
26,
267,
10017,
275,
6128,
21,
8,
576,
680,
11453,
342,
267,
340,
10017,
1137,
6128,
21,
63,
576,
59,
5799,
63,
354,
2189,
288,
870,
4331,
1274,
14,
3083,
12,
334,
355,
298,
1064,
21,
6411,
402,
450,
83,
3405,
1,
221,
334,
28096,
5235,
5160,
31,
2924,
355,
450,
11393,
63,
354,
288,
776,
288,
984,
14,
2224,
8,
18,
9,
272,
372,
666,
199,
199,
318,
675,
63,
13623,
8,
272,
1015,
29,
3472,
63,
4612,
12,
5235,
63,
1095,
29,
3472,
63,
2632,
12,
370,
63,
694,
29,
736,
14,
15594,
12,
272,
5235,
63,
5814,
29,
1046,
199,
304,
272,
408,
3358,
17174,
2342,
15,
4249,
9116,
436,
1852,
652,
2808,
641,
984,
14,
515,
339,
658,
1023,
64,
1077,
506,
282,
1686,
9116,
1015,
1329,
626,
365,
2808,
272,
465,
376,
11393,
367,
5235,
1334,
314,
658,
4249,
63,
1095,
64,
2851,
334,
6777,
1077,
1284,
543,
272,
282,
1994,
1959,
221,
658,
475,
63,
694,
64,
365,
314,
2082,
2382,
9116,
911,
506,
13557,
12,
340,
272,
652,
365,
440,
2575,
2808,
14,
221,
982,
658,
4249,
63,
5814,
64,
365,
2013,
12,
652,
1077,
272,
506,
314,
1329,
402,
4696,
626,
911,
506,
691,
2972,
2544,
11023,
1958,
282,
5235,
12,
272,
1077
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
17989,
7868,
9116,
12096,
199,
199,
3917,
1265,
2934,
370,
675,
9116,
315,
2195,
2559,
1159,
3272,
14,
647,
12,
2951,
2387,
642,
199,
493,
315,
314,
2011,
2082,
543,
652,
12,
436,
1050,
642,
370,
314,
2746,
402,
2195,
3272,
14,
647,
447,
339,
687,
325,
90,
63,
2758,
492,
675,
63,
13623,
272,
675,
63,
13623,
342,
199,
199,
3917,
1265,
2934,
370,
4409,
282,
2488,
1015,
402,
9116,
12,
663,
282,
5235,
199,
12324,
12,
503,
675,
376,
18034,
5235,
2082,
12,
1265,
883,
886,
880,
701,
4973,
6670,
199,
1589,
5827,
1511,
370,
1124,
1180,
63,
13623,
28566,
199,
199,
2765,
570,
883,
2597,
506,
1255,
465,
282,
2884,
370,
3907,
503,
10754,
9116,
14,
199,
624,
199,
646,
984,
199,
3472,
63,
4612,
275,
298,
16,
14,
22,
67,
845,
2,
199,
3472,
63,
2632,
258,
275,
298,
1014,
921,
17343,
14,
1548,
14,
1308,
15,
5154,
3149,
83,
15,
83,
15,
13623,
6687,
450,
984,
14,
1023,
1491,
19,
61,
199,
199,
1064,
21,
63,
576,
275,
469,
272,
283,
13623,
13,
16,
14,
22,
67,
709,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
301,
17,
69,
18,
371,
21,
68,
19,
65,
18823,
772,
1367,
68,
25,
3003,
969,
6718,
65,
23,
18526,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
709,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
1641,
68,
22,
68,
25,
68,
22,
69,
25,
66,
1257,
19518,
67,
1427,
65,
2481,
65,
1349,
1153,
65,
21,
617,
20,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
709,
13,
647,
18,
14,
21,
14,
5799,
356,
283,
271,
2466,
645,
24,
66,
17,
67,
2576,
67,
1407,
1229,
2819,
69,
21,
69,
24,
15112,
65,
2871,
24,
67,
23,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
709,
13,
647,
18,
14,
22,
14,
5799,
356,
283,
2010,
4489,
2167,
65,
2829,
1690,
983,
996,
301,
772,
10721,
1229,
1789,
65,
16,
66,
23,
70,
21,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
845,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
18,
28363,
645,
22,
69,
969,
68,
25250,
65,
25,
68,
1651,
69,
23,
2470,
21,
66,
21,
65,
15112,
271,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
845,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
3691,
26723,
70,
25,
66,
16,
28870,
20,
67,
21089,
20598,
1082,
7778,
18,
825,
16,
67,
18,
66,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
845,
13,
647,
18,
14,
21,
14,
5799,
356,
283,
772,
67,
2635,
70,
19,
4361,
23,
65,
2819,
65,
969,
825,
2658,
69,
16,
66,
1194,
70,
9014,
25,
66,
18,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
845,
13,
647,
18,
14,
22,
14,
5799,
356,
283,
66,
667,
2942,
1960,
3691,
19518,
68,
21,
65,
14271,
69,
31151,
13251,
68,
12021,
1184,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
24,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
13583,
1427,
68,
1398,
66,
11991,
697,
24,
27901,
11369,
2470,
24,
11810,
70,
1167,
996,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
24,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
28995,
1703,
68,
1342,
70,
23,
68,
23946,
67,
1690,
69,
25,
30908,
16059,
16,
67,
301,
22,
271,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
24,
13,
647,
18,
14,
21,
14,
5799,
356,
283,
1196,
9335,
2417,
1024,
11685,
3833,
8251,
15458,
65,
2010,
66,
19,
69,
17,
645,
2720,
66,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
25,
13,
647,
18,
14,
19,
14,
5799,
356,
283,
65,
2658,
67,
13314,
966,
1079,
11369,
66,
18105,
69,
20,
2177,
1235,
2036,
13583,
67,
1644,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
25,
13,
647,
18,
14,
20,
14,
5799,
356,
283,
13085,
65,
18,
1235,
18,
69,
2481,
1299,
68,
1272,
66,
983,
1024,
1690,
371,
825,
22,
14519,
65,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
25,
13,
647,
18,
14,
21,
14,
5799,
356,
283,
771,
1822,
67,
19,
69,
21,
65,
1196,
66,
713,
67,
16,
69,
23,
67,
21278,
66,
23,
4489,
2824,
65,
24,
69,
22,
297,
272,
283,
13623,
13,
16,
14,
22,
67,
25,
13,
647,
18,
14,
22,
14,
5799,
356,
283,
696,
1401,
66,
17,
556,
975,
667,
18,
69,
271,
22,
69,
1167,
15504,
69,
23,
66,
1427,
11677,
65,
297,
199,
93,
199,
199,
646,
984,
12,
747,
199,
893,
26,
687,
8337,
492,
6128,
21,
199,
2590,
3545,
26,
687,
6128,
21,
492,
6128,
21,
199,
199,
318,
485,
3502,
63,
1064,
21,
8,
5799,
63,
354,
12,
666,
304,
272,
340,
11393,
63,
354,
315,
6128,
21,
63,
576,
26,
267,
10017,
275,
6128,
21,
8,
576,
680,
11453,
342,
267,
340,
10017,
1137,
6128,
21,
63,
576,
59,
5799,
63,
354,
2189,
288,
870,
4331,
1274,
14,
3083,
12,
334,
355,
298,
1064,
21,
6411,
402,
450,
83,
3405,
1,
221,
334,
28096,
5235,
5160,
31,
2924,
355,
450,
11393,
63,
354,
288,
776,
288,
984,
14,
2224,
8,
18,
9,
272,
372,
666,
199,
199,
318,
675,
63,
13623,
8,
272,
1015,
29,
3472,
63,
4612,
12,
5235,
63,
1095,
29,
3472,
63,
2632,
12,
370,
63,
694,
29,
736,
14,
15594,
12,
272,
5235,
63,
5814,
29,
1046,
199,
304,
272,
408,
3358,
17174,
2342,
15,
4249,
9116,
436,
1852,
652,
2808,
641,
984,
14,
515,
339,
658,
1023,
64,
1077,
506,
282,
1686,
9116,
1015,
1329,
626,
365,
2808,
272,
465,
376,
11393,
367,
5235,
1334,
314,
658,
4249,
63,
1095,
64,
2851,
334,
6777,
1077,
1284,
543,
272,
282,
1994,
1959,
221,
658,
475,
63,
694,
64,
365,
314,
2082,
2382,
9116,
911,
506,
13557,
12,
340,
272,
652,
365,
440,
2575,
2808,
14,
221,
982,
658,
4249,
63,
5814,
64,
365,
2013,
12,
652,
1077,
272,
506,
314,
1329,
402,
4696,
626,
911,
506,
691,
2972,
2544,
11023,
1958,
282,
5235,
12,
272,
1077,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
svn2github/django
|
tests/modeltests/custom_pk/fields.py
|
93
|
1493
|
import random
import string
from django.db import models
class MyWrapper(object):
def __init__(self, value):
self.value = value
def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__, self.value)
def __unicode__(self):
return self.value
def __eq__(self, other):
if isinstance(other, self.__class__):
return self.value == other.value
return self.value == other
class MyAutoField(models.CharField):
__metaclass__ = models.SubfieldBase
def __init__(self, *args, **kwargs):
kwargs['max_length'] = 10
super(MyAutoField, self).__init__(*args, **kwargs)
def pre_save(self, instance, add):
value = getattr(instance, self.attname, None)
if not value:
value = MyWrapper(''.join(random.sample(string.lowercase, 10)))
setattr(instance, self.attname, value)
return value
def to_python(self, value):
if not value:
return
if not isinstance(value, MyWrapper):
value = MyWrapper(value)
return value
def get_db_prep_save(self, value, connection):
if not value:
return
if isinstance(value, MyWrapper):
return unicode(value)
return value
def get_db_prep_value(self, value, connection, prepared=False):
if not value:
return
if isinstance(value, MyWrapper):
return unicode(value)
return value
|
bsd-3-clause
|
[
646,
2196,
199,
646,
1059,
199,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
4932,
4590,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
574,
304,
267,
291,
14,
585,
275,
574,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
23054,
83,
26,
450,
83,
4335,
450,
334,
277,
855,
533,
4914,
354,
3108,
291,
14,
585,
9,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
291,
14,
585,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
340,
1228,
8,
1848,
12,
291,
855,
533,
18580,
288,
372,
291,
14,
585,
508,
1163,
14,
585,
267,
372,
291,
14,
585,
508,
1163,
199,
199,
533,
4932,
4378,
8,
992,
14,
2183,
304,
272,
636,
6577,
363,
275,
1709,
14,
2610,
698,
1563,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
2074,
459,
988,
63,
1267,
418,
275,
1616,
267,
1613,
8,
5713,
4378,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
876,
63,
2117,
8,
277,
12,
1256,
12,
1050,
304,
267,
574,
275,
2519,
8,
842,
12,
291,
14,
13651,
12,
488,
9,
267,
340,
440,
574,
26,
288,
574,
275,
4932,
4590,
17840,
904,
8,
2355,
14,
3271,
8,
875,
14,
21636,
12,
1616,
1724,
288,
5371,
8,
842,
12,
291,
14,
13651,
12,
574,
9,
267,
372,
574,
339,
347,
370,
63,
1548,
8,
277,
12,
574,
304,
267,
340,
440,
574,
26,
288,
372,
267,
340,
440,
1228,
8,
585,
12,
4932,
4590,
304,
288,
574,
275,
4932,
4590,
8,
585,
9,
267,
372,
574,
339,
347,
664,
63,
697,
63,
10837,
63,
2117,
8,
277,
12,
574,
12,
1950,
304,
267,
340,
440,
574,
26,
288,
372,
267,
340,
1228,
8,
585,
12,
4932,
4590,
304,
288,
372,
2649,
8,
585,
9,
267,
372,
574,
339,
347,
664,
63,
697,
63,
10837,
63,
585,
8,
277,
12,
574,
12,
1950,
12,
16318,
29,
797,
304,
267,
340,
440,
574,
26,
288,
372,
267,
340,
1228,
8,
585,
12,
4932,
4590,
304,
288,
372,
2649,
8,
585,
9,
267,
372,
574,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2196,
199,
646,
1059,
199,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
4932,
4590,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
574,
304,
267,
291,
14,
585,
275,
574,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
23054,
83,
26,
450,
83,
4335,
450,
334,
277,
855,
533,
4914,
354,
3108,
291,
14,
585,
9,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
291,
14,
585,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
340,
1228,
8,
1848,
12,
291,
855,
533,
18580,
288,
372,
291,
14,
585,
508,
1163,
14,
585,
267,
372,
291,
14,
585,
508,
1163,
199,
199,
533,
4932,
4378,
8,
992,
14,
2183,
304,
272,
636,
6577,
363,
275,
1709,
14,
2610,
698,
1563,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
2074,
459,
988,
63,
1267,
418,
275,
1616,
267,
1613,
8,
5713,
4378,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
876,
63,
2117,
8,
277,
12,
1256,
12,
1050,
304,
267,
574,
275,
2519,
8,
842,
12,
291,
14,
13651,
12,
488,
9,
267,
340,
440,
574,
26,
288,
574,
275,
4932,
4590,
17840,
904,
8,
2355,
14,
3271,
8,
875,
14,
21636,
12,
1616,
1724,
288,
5371,
8,
842,
12,
291,
14,
13651,
12,
574,
9,
267,
372,
574,
339,
347,
370,
63,
1548,
8,
277,
12,
574,
304,
267,
340,
440,
574,
26,
288,
372,
267,
340,
440,
1228,
8,
585,
12,
4932,
4590,
304,
288,
574,
275,
4932,
4590,
8,
585,
9,
267,
372,
574,
339,
347,
664,
63,
697,
63,
10837,
63,
2117,
8,
277,
12,
574,
12,
1950,
304,
267,
340,
440,
574,
26,
288,
372,
267,
340,
1228,
8,
585,
12,
4932,
4590,
304,
288,
372,
2649,
8,
585,
9,
267,
372,
574,
339,
347,
664,
63,
697,
63,
10837,
63,
585,
8,
277,
12,
574,
12,
1950,
12,
16318,
29,
797,
304,
267,
340,
440,
574,
26,
288,
372,
267,
340,
1228,
8,
585,
12,
4932,
4590,
304,
288,
372,
2649,
8,
585,
9,
267,
372,
574,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
dstrockis/outlook-autocategories
|
lib/google/auth/compute_engine/credentials.py
|
14
|
4516
|
# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Google Compute Engine credentials.
This module provides authentication for application running on Google Compute
Engine using the Compute Engine metadata server.
"""
from google.auth import credentials
from google.auth import exceptions
from google.auth.compute_engine import _metadata
class Credentials(credentials.Scoped, credentials.Credentials):
"""Compute Engine Credentials.
These credentials use the Google Compute Engine metadata server to obtain
OAuth 2.0 access tokens associated with the instance's service account.
For more information about Compute Engine authentication, including how
to configure scopes, see the `Compute Engine authentication
documentation`_.
.. note:: Compute Engine instances can be created with scopes and therefore
these credentials are considered to be 'scoped'. However, you can
not use :meth:`~google.auth.credentials.ScopedCredentials.with_scopes`
because it is not possible to change the scopes that the instance
has. Also note that
:meth:`~google.auth.credentials.ScopedCredentials.has_scopes` will not
work until the credentials have been refreshed.
.. _Compute Engine authentication documentation:
https://cloud.google.com/compute/docs/authentication#using
"""
def __init__(self, service_account_email='default'):
"""
Args:
service_account_email (str): The service account email to use, or
'default'. A Compute Engine instance may have multiple service
accounts.
"""
super(Credentials, self).__init__()
self._service_account_email = service_account_email
def _retrieve_info(self, request):
"""Retrieve information about the service account.
Updates the scopes and retrieves the full service account email.
Args:
request (google.auth.transport.Request): The object used to make
HTTP requests.
"""
info = _metadata.get_service_account_info(
request,
service_account=self._service_account_email)
self._service_account_email = info['email']
self._scopes = info['scopes']
def refresh(self, request):
"""Refresh the access token and scopes.
Args:
request (google.auth.transport.Request): The object used to make
HTTP requests.
Raises:
google.auth.exceptions.RefreshError: If the Compute Engine metadata
service can't be reached if if the instance has not
credentials.
"""
try:
self._retrieve_info(request)
self.token, self.expiry = _metadata.get_service_account_token(
request,
service_account=self._service_account_email)
except exceptions.TransportError as exc:
raise exceptions.RefreshError(exc)
@property
def service_account_email(self):
"""The service account email.
.. note: This is not guaranteed to be set until :meth`refresh` has been
called.
"""
return self._service_account_email
@property
def requires_scopes(self):
"""False: Compute Engine credentials can not be scoped."""
return False
def with_scopes(self, scopes):
"""Unavailable, Compute Engine credentials can not be scoped.
Scopes can only be set at Compute Engine instance creation time.
See the `Compute Engine authentication documentation`_ for details on
how to configure instance scopes.
.. _Compute Engine authentication documentation:
https://cloud.google.com/compute/docs/authentication#using
"""
raise NotImplementedError(
'Compute Engine credentials can not set scopes. Scopes must be '
'set when the Compute Engine instance is created.')
|
apache-2.0
|
[
3,
1898,
7800,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
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,
13266,
8354,
12580,
6235,
14,
199,
199,
2765,
859,
6571,
6299,
367,
4223,
3879,
641,
4475,
8354,
199,
8524,
1808,
314,
8354,
12580,
3341,
1654,
14,
199,
199,
624,
199,
199,
504,
6233,
14,
1178,
492,
6235,
199,
504,
6233,
14,
1178,
492,
4967,
199,
504,
6233,
14,
1178,
14,
3357,
63,
3908,
492,
485,
2343,
421,
199,
533,
23934,
8,
6942,
14,
7812,
68,
12,
6235,
14,
13428,
304,
272,
408,
8564,
12580,
23934,
14,
339,
5723,
6235,
675,
314,
4475,
8354,
12580,
3341,
1654,
370,
3332,
272,
11715,
499,
14,
16,
2879,
4645,
4568,
543,
314,
1256,
1159,
2435,
2933,
14,
339,
2104,
1655,
2556,
3595,
8354,
12580,
6299,
12,
5893,
4212,
272,
370,
7908,
14570,
12,
1937,
314,
658,
8564,
12580,
6299,
272,
3794,
32578,
339,
2508,
5317,
447,
8354,
12580,
4454,
883,
506,
2737,
543,
14570,
436,
16119,
267,
3520,
6235,
787,
8652,
370,
506,
283,
23254,
1370,
9738,
12,
1265,
883,
267,
440,
675,
520,
5247,
6054,
3098,
14,
1178,
14,
6942,
14,
7812,
68,
13428,
14,
1045,
63,
14129,
64,
267,
2952,
652,
365,
440,
3962,
370,
1570,
314,
14570,
626,
314,
1256,
267,
965,
14,
6121,
5317,
626,
267,
520,
5247,
6054,
3098,
14,
1178,
14,
6942,
14,
7812,
68,
13428,
14,
1989,
63,
14129,
64,
911,
440,
267,
1736,
5133,
314,
6235,
1172,
2757,
9236,
379,
14,
339,
2508,
485,
8564,
12580,
6299,
3794,
26,
267,
4178,
921,
4091,
14,
3098,
14,
957,
15,
3357,
15,
4757,
15,
11725,
3,
4941,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2435,
63,
2048,
63,
2123,
534,
885,
735,
267,
408,
267,
3033,
26,
288,
2435,
63,
2048,
63,
2123,
334,
495,
304,
710,
2435,
2933,
3031,
370,
675,
12,
503,
355,
283,
885,
1370,
437,
8354,
12580,
1256,
1443,
1172,
3663,
2435,
355,
12639,
14,
267,
408,
267,
1613,
8,
13428,
12,
291,
2843,
826,
4533,
267,
291,
423,
1364,
63,
2048,
63,
2123,
275,
2435,
63,
2048,
63,
2123,
339,
347,
485,
14270,
63,
815,
8,
277,
12,
1056,
304,
267,
408,
15310,
2556,
3595,
314,
2435,
2933,
14,
398,
24663,
314,
14570,
436,
9619,
2310,
314,
2615,
2435,
2933,
3031,
14,
398,
3033,
26,
288,
1056,
334,
3098,
14,
1178,
14,
5545,
14,
2017,
304,
710,
909,
1202,
370,
1852,
355,
3101,
4145,
14,
267,
408,
267,
2256,
275,
485,
2343,
14,
362,
63,
1364,
63,
2048,
63,
815,
8,
288,
1056,
12,
288,
2435,
63,
2048,
29,
277,
423,
1364,
63,
2048,
63,
2123,
9,
398,
291,
423,
1364,
63,
2048,
63,
2123,
275,
2256,
459,
2123,
418,
267,
291,
423,
14129,
275,
2256,
459,
14129,
418,
339,
347,
9236,
8,
277,
12,
1056,
304,
267,
408,
18730,
314,
2879,
1526,
436,
14570,
14,
398,
3033,
26,
288,
1056,
334,
3098,
14,
1178,
14,
5545,
14,
2017,
304,
710,
909,
1202,
370,
1852,
355,
3101,
4145,
14,
398,
6218,
26,
288,
6233,
14,
1178,
14,
3924,
14,
18730,
547,
26,
982,
314,
8354,
12580,
3341,
355,
2435,
883,
1133,
506,
13075,
340,
340,
314,
1256,
965,
440,
355,
6235,
14,
267,
408,
267,
862,
26,
288,
291,
423,
14270,
63,
815,
8,
1069,
9,
288,
291,
14,
1418,
12,
291,
14,
16844,
275,
485,
2343,
14,
362,
63,
1364,
63,
2048,
63,
1418,
8,
355,
1056,
12,
355,
2435,
63,
2048,
29,
277,
423,
1364,
63,
2048,
63,
2123,
9,
267,
871,
4967,
14,
7836,
547,
465,
3178,
26,
288,
746,
4967,
14,
18730,
547,
8,
2804,
9,
339,
768,
1829,
272,
347,
2435,
63,
2048,
63,
2123,
8,
277,
304,
267,
408,
1918,
2435,
2933,
3031,
14,
398,
2508,
5317,
26,
961,
365,
440,
17334,
370,
506,
663,
5133,
520,
5247,
64,
6635,
64,
965,
2757,
288,
2797,
14,
267,
408,
267,
372,
291,
423,
1364,
63,
2048,
63,
2123,
339,
768,
1829,
272,
347,
5074,
63,
14129,
8,
277,
304,
267,
408,
797,
26,
8354,
12580,
6235,
883,
440,
506,
27582,
1041,
267,
372,
756,
339,
347,
543,
63,
14129,
8,
277,
12,
14570,
304,
267,
408,
28049,
12,
8354,
12580,
6235,
883,
440,
506,
27582,
14,
398,
20488,
83,
883,
1454,
506,
663,
737,
8354,
12580,
1256,
7143,
900,
14,
267,
1666,
314,
658,
8564,
12580,
6299,
3794,
18417,
367,
2436,
641,
267,
4212,
370,
7908,
1256,
14570,
14,
398,
2508,
485,
8564,
12580,
6299,
3794,
26,
288,
4178,
921,
4091,
14,
3098,
14,
957,
15,
3357,
15,
4757,
15,
11725,
3,
4941,
267,
408,
267,
746,
4279,
8,
288,
283,
8564,
12580,
6235,
883,
440,
663,
14570,
14,
20488,
83,
1471,
506,
283,
288,
283,
409,
1380,
314,
8354,
12580,
1256,
365,
2737,
2659,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
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,
13266,
8354,
12580,
6235,
14,
199,
199,
2765,
859,
6571,
6299,
367,
4223,
3879,
641,
4475,
8354,
199,
8524,
1808,
314,
8354,
12580,
3341,
1654,
14,
199,
199,
624,
199,
199,
504,
6233,
14,
1178,
492,
6235,
199,
504,
6233,
14,
1178,
492,
4967,
199,
504,
6233,
14,
1178,
14,
3357,
63,
3908,
492,
485,
2343,
421,
199,
533,
23934,
8,
6942,
14,
7812,
68,
12,
6235,
14,
13428,
304,
272,
408,
8564,
12580,
23934,
14,
339,
5723,
6235,
675,
314,
4475,
8354,
12580,
3341,
1654,
370,
3332,
272,
11715,
499,
14,
16,
2879,
4645,
4568,
543,
314,
1256,
1159,
2435,
2933,
14,
339,
2104,
1655,
2556,
3595,
8354,
12580,
6299,
12,
5893,
4212,
272,
370,
7908,
14570,
12,
1937,
314,
658,
8564,
12580,
6299,
272,
3794,
32578,
339,
2508,
5317,
447,
8354,
12580,
4454,
883,
506,
2737,
543,
14570,
436,
16119,
267,
3520,
6235,
787,
8652,
370,
506,
283,
23254,
1370,
9738,
12,
1265,
883,
267,
440,
675,
520,
5247,
6054,
3098,
14,
1178,
14,
6942,
14,
7812,
68,
13428,
14,
1045,
63,
14129,
64,
267,
2952,
652,
365,
440,
3962,
370,
1570,
314,
14570,
626,
314,
1256,
267,
965,
14,
6121,
5317,
626,
267,
520,
5247,
6054,
3098,
14,
1178,
14,
6942,
14,
7812,
68,
13428,
14,
1989,
63,
14129,
64,
911,
440,
267,
1736,
5133,
314,
6235,
1172,
2757,
9236,
379,
14,
339,
2508,
485,
8564,
12580,
6299,
3794,
26,
267,
4178,
921,
4091,
14,
3098,
14,
957,
15,
3357,
15,
4757,
15,
11725,
3,
4941,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2435,
63,
2048,
63,
2123,
534,
885,
735,
267,
408,
267,
3033,
26,
288,
2435,
63,
2048,
63,
2123,
334,
495,
304,
710,
2435,
2933,
3031,
370,
675,
12,
503,
355,
283,
885,
1370,
437,
8354,
12580,
1256,
1443,
1172,
3663,
2435,
355,
12639,
14,
267,
408,
267,
1613,
8,
13428,
12,
291,
2843,
826,
4533,
267,
291,
423,
1364,
63,
2048,
63,
2123,
275,
2435,
63,
2048,
63,
2123,
339,
347,
485,
14270,
63,
815,
8,
277,
12,
1056,
304,
267,
408,
15310,
2556,
3595,
314,
2435,
2933,
14,
398,
24663,
314,
14570,
436,
9619,
2310,
314,
2615,
2435,
2933,
3031,
14,
398,
3033,
26,
288,
1056,
334,
3098,
14,
1178,
14,
5545,
14,
2017,
304,
710,
909,
1202,
370,
1852,
355,
3101,
4145,
14,
267,
408,
267,
2256,
275,
485,
2343,
14,
362,
63,
1364,
63,
2048,
63,
815,
8,
288,
1056,
12,
288,
2435,
63,
2048,
29,
277,
423,
1364,
63,
2048,
63,
2123,
9,
398,
291,
423,
1364,
63,
2048,
63,
2123,
275,
2256,
459,
2123,
418,
267,
291,
423,
14129,
275,
2256,
459,
14129,
418,
339,
347,
9236,
8,
277,
12,
1056,
304,
267,
408,
18730,
314,
2879,
1526,
436,
14570,
14,
398,
3033,
26,
288,
1056,
334,
3098,
14,
1178,
14,
5545,
14,
2017,
304,
710,
909,
1202,
370,
1852,
355,
3101,
4145,
14,
398,
6218,
26,
288,
6233,
14,
1178,
14,
3924,
14,
18730,
547,
26,
982,
314,
8354,
12580,
3341,
355,
2435,
883,
1133,
506,
13075,
340,
340,
314,
1256,
965,
440,
355,
6235,
14,
267,
408,
267,
862,
26,
288,
291,
423,
14270,
63,
815,
8,
1069,
9,
288,
291,
14,
1418,
12,
291,
14,
16844,
275,
485,
2343,
14,
362,
63,
1364,
63,
2048,
63,
1418,
8,
355,
1056,
12,
355,
2435,
63,
2048,
29,
277,
423,
1364,
63,
2048,
63,
2123,
9,
267,
871,
4967,
14,
7836,
547,
465,
3178,
26,
288,
746,
4967,
14,
18730,
547,
8,
2804,
9,
339,
768,
1829,
272,
347,
2435,
63,
2048,
63,
2123,
8,
277,
304,
267,
408,
1918,
2435,
2933,
3031,
14,
398,
2508,
5317,
26,
961,
365,
440,
17334,
370,
506,
663,
5133,
520,
5247,
64,
6635,
64,
965,
2757,
288,
2797,
14,
267,
408,
267,
372,
291,
423,
1364,
63,
2048,
63,
2123,
339,
768,
1829,
272,
347,
5074,
63,
14129,
8,
277,
304,
267,
408,
797,
26,
8354,
12580,
6235,
883,
440,
506,
27582,
1041,
267,
372,
756,
339,
347,
543,
63,
14129,
8,
277,
12,
14570,
304,
267,
408,
28049,
12,
8354,
12580,
6235,
883,
440,
506,
27582,
14,
398,
20488,
83,
883,
1454,
506,
663,
737,
8354,
12580,
1256,
7143,
900,
14,
267,
1666,
314,
658,
8564,
12580,
6299,
3794,
18417,
367,
2436,
641,
267,
4212,
370,
7908,
1256,
14570,
14,
398,
2508,
485,
8564,
12580,
6299,
3794,
26,
288,
4178,
921,
4091,
14,
3098,
14,
957,
15,
3357,
15,
4757,
15,
11725,
3,
4941,
267,
408,
267,
746,
4279,
8,
288,
283,
8564,
12580,
6235,
883,
440,
663,
14570,
14,
20488,
83,
1471,
506,
283,
288,
283,
409,
1380,
314,
8354,
12580,
1256,
365,
2737,
2659,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
jcpowermac/ansible
|
lib/ansible/modules/network/cloudengine/ce_snmp_location.py
|
22
|
6794
|
#!/usr/bin/python
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: ce_snmp_location
version_added: "2.4"
short_description: Manages SNMP location configuration on HUAWEI CloudEngine switches.
description:
- Manages SNMP location configurations on HUAWEI CloudEngine switches.
author:
- wangdezhuang (@CloudEngine-Ansible)
options:
location:
description:
- Location information.
required: true
default: null
state:
description:
- Manage the state of the resource.
required: false
default: present
choices: ['present','absent']
'''
EXAMPLES = '''
- name: CloudEngine snmp location test
hosts: cloudengine
connection: local
gather_facts: no
vars:
cli:
host: "{{ inventory_hostname }}"
port: "{{ ansible_ssh_port }}"
username: "{{ username }}"
password: "{{ password }}"
transport: cli
tasks:
- name: "Config SNMP location"
ce_snmp_location:
state: present
location: nanjing China
provider: "{{ cli }}"
- name: "Remove SNMP location"
ce_snmp_location:
state: absent
location: nanjing China
provider: "{{ cli }}"
'''
RETURN = '''
changed:
description: check to see if a change was made on the device
returned: always
type: boolean
sample: true
proposed:
description: k/v pairs of parameters passed into module
returned: always
type: dict
sample: {"location": "nanjing China",
"state": "present"}
existing:
description: k/v pairs of existing aaa server
returned: always
type: dict
sample: {}
end_state:
description: k/v pairs of aaa params after module execution
returned: always
type: dict
sample: {"location": "nanjing China"}
updates:
description: command sent to the device
returned: always
type: list
sample: ["snmp-agent sys-info location nanjing China"]
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.cloudengine.ce import get_config, load_config, ce_argument_spec
class SnmpLocation(object):
""" Manages SNMP location configuration """
def __init__(self, **kwargs):
""" Class init """
# module
argument_spec = kwargs["argument_spec"]
self.spec = argument_spec
self.module = AnsibleModule(argument_spec=self.spec, supports_check_mode=True)
# config
self.cur_cfg = dict()
# module args
self.state = self.module.params['state']
self.location = self.module.params['location']
# state
self.changed = False
self.updates_cmd = list()
self.results = dict()
self.proposed = dict()
self.existing = dict()
self.end_state = dict()
def check_args(self):
""" Check invalid args """
if self.location:
if len(self.location) > 255 or len(self.location) < 1:
self.module.fail_json(
msg='Error: The len of location %s is out of [1 - 255].' % self.location)
else:
self.module.fail_json(
msg='Error: The len of location is 0.')
def get_proposed(self):
""" Get proposed state """
self.proposed["state"] = self.state
if self.location:
self.proposed["location"] = self.location
def get_existing(self):
""" Get existing state """
tmp_cfg = self.cli_get_config()
if tmp_cfg:
temp_data = tmp_cfg.split(r"location ")
self.cur_cfg["location"] = temp_data[1]
self.existing["location"] = temp_data[1]
def get_end_state(self):
""" Get end state """
tmp_cfg = self.cli_get_config()
if tmp_cfg:
temp_data = tmp_cfg.split(r"location ")
self.end_state["location"] = temp_data[1]
def cli_load_config(self, commands):
""" Load config by cli """
if not self.module.check_mode:
load_config(self.module, commands)
def cli_get_config(self):
""" Get config by cli """
regular = "| include snmp | include location"
flags = list()
flags.append(regular)
tmp_cfg = get_config(self.module, flags)
return tmp_cfg
def set_config(self):
""" Set configure by cli """
cmd = "snmp-agent sys-info location %s" % self.location
self.updates_cmd.append(cmd)
cmds = list()
cmds.append(cmd)
self.cli_load_config(cmds)
self.changed = True
def undo_config(self):
""" Undo configure by cli """
cmd = "undo snmp-agent sys-info location"
self.updates_cmd.append(cmd)
cmds = list()
cmds.append(cmd)
self.cli_load_config(cmds)
self.changed = True
def work(self):
""" Main work function """
self.check_args()
self.get_proposed()
self.get_existing()
if self.state == "present":
if "location" in self.cur_cfg.keys() and self.location == self.cur_cfg["location"]:
pass
else:
self.set_config()
else:
if "location" in self.cur_cfg.keys() and self.location == self.cur_cfg["location"]:
self.undo_config()
self.get_end_state()
self.results['changed'] = self.changed
self.results['proposed'] = self.proposed
self.results['existing'] = self.existing
self.results['end_state'] = self.end_state
self.results['updates'] = self.updates_cmd
self.module.exit_json(**self.results)
def main():
""" Module main """
argument_spec = dict(
state=dict(choices=['present', 'absent'], default='present'),
location=dict(type='str', required=True)
)
argument_spec.update(ce_argument_spec)
module = SnmpLocation(argument_spec=argument_spec)
module.work()
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
10142,
63,
15523,
63,
1985,
199,
1023,
63,
3270,
26,
298,
18,
14,
20,
2,
199,
3612,
63,
1802,
26,
21612,
26549,
2909,
2897,
641,
869,
21659,
5408,
41,
8142,
8524,
24563,
14,
199,
1802,
26,
272,
446,
21612,
26549,
2909,
13422,
641,
869,
21659,
5408,
41,
8142,
8524,
24563,
14,
199,
2502,
26,
272,
446,
336,
621,
271,
3951,
85,
621,
8593,
9089,
8524,
13,
10047,
9,
199,
1419,
26,
272,
2909,
26,
267,
1369,
26,
288,
446,
12625,
2556,
14,
267,
1415,
26,
2549,
267,
849,
26,
2973,
272,
1174,
26,
267,
1369,
26,
288,
446,
14944,
314,
1174,
402,
314,
2073,
14,
267,
1415,
26,
3055,
267,
849,
26,
3451,
267,
3415,
26,
788,
1881,
1673,
5575,
418,
199,
2344,
199,
199,
8918,
275,
1449,
199,
199,
13,
536,
26,
8142,
8524,
20143,
2909,
511,
523,
7057,
26,
2463,
85,
848,
2598,
523,
1950,
26,
2257,
523,
13082,
63,
5047,
26,
949,
523,
6802,
26,
272,
5053,
26,
489,
1591,
26,
7370,
8200,
63,
4269,
7820,
489,
1844,
26,
7370,
3242,
63,
5510,
63,
719,
7820,
489,
3434,
26,
7370,
3434,
7820,
489,
2505,
26,
7370,
2505,
7820,
489,
7773,
26,
5053,
819,
6527,
26,
819,
446,
536,
26,
298,
2028,
26549,
2909,
2,
272,
10142,
63,
15523,
63,
1985,
26,
489,
1174,
26,
3451,
489,
2909,
26,
12055,
74,
316,
2799,
13765,
489,
5022,
26,
7370,
5053,
7820,
819,
446,
536,
26,
298,
5587,
26549,
2909,
2,
272,
10142,
63,
15523,
63,
1985,
26,
489,
1174,
26,
9552,
489,
2909,
26,
12055,
74,
316,
2799,
13765,
489,
5022,
26,
7370,
5053,
7820,
199,
2344,
199,
199,
9677,
275,
1449,
199,
2489,
26,
272,
1369,
26,
1104,
370,
1937,
340,
282,
1570,
1990,
6326,
641,
314,
2243,
272,
2138,
26,
3544,
272,
730,
26,
5046,
272,
2690,
26,
2549,
199,
15676,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
2633,
3032,
1901,
859,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
2420,
1985,
582,
298,
4304,
74,
316,
2799,
13765,
401,
1467,
298,
929,
582,
298,
1881,
3570,
199,
5952,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
3411,
32396,
1654,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
1052,
199,
500,
63,
929,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
32396,
1862,
2410,
859,
6451,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
2420,
1985,
582,
298,
4304,
74,
316,
2799,
13765,
3570,
199,
7618,
26,
272,
1369,
26,
1414,
4847,
370,
314,
2243,
272,
2138,
26,
3544,
272,
730,
26,
769,
272,
2690,
26,
2097,
15523,
13,
4054,
984,
13,
815,
2909,
12055,
74,
316,
2799,
13765,
937,
199,
2344,
421,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
1251,
85,
848,
2598,
14,
301,
492,
664,
63,
888,
12,
2248,
63,
888,
12,
10142,
63,
2094,
63,
1650,
421,
199,
533,
428,
78,
311,
6592,
8,
785,
304,
272,
408,
21612,
26549,
2909,
2897,
408,
339,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
408,
8089,
4205,
408,
398,
327,
859,
267,
1423,
63,
1650,
275,
2074,
905,
2094,
63,
1650,
937,
267,
291,
14,
1650,
275,
1423,
63,
1650,
267,
291,
14,
578,
275,
6953,
8,
2094,
63,
1650,
29,
277,
14,
1650,
12,
5171,
63,
1074,
63,
632,
29,
549,
9,
398,
327,
1101,
267,
291,
14,
895,
63,
4128,
275,
1211,
342,
398,
327,
859,
1249,
267,
291,
14,
929,
275,
291,
14,
578,
14,
1162,
459,
929,
418,
267,
291,
14,
1985,
275,
291,
14,
578,
14,
1162,
459,
1985,
418,
398,
327,
1174,
267,
291,
14,
2489,
275,
756,
267,
291,
14,
7618,
63,
1760,
275,
769,
342,
267,
291,
14,
2604,
275,
1211,
342,
267,
291,
14,
15676,
275,
1211,
342,
267,
291,
14,
5952,
275,
1211,
342,
267,
291,
14,
500,
63,
929,
275,
1211,
342,
339,
347,
1104,
63,
589,
8,
277,
304,
267,
408,
2670,
3866,
1249,
408,
398,
340,
291,
14,
1985,
26,
288,
340,
822,
8,
277,
14,
1985,
9,
690,
5450,
503,
822,
8,
277,
14,
1985,
9,
665,
413,
26,
355,
291,
14,
578,
14,
1633,
63,
1001,
8,
490,
1499,
534,
547,
26,
710,
822,
402,
2909,
450,
83,
365,
734,
402,
359,
17,
446,
5450,
1055,
7,
450,
291,
14,
1985,
9,
267,
587,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
8,
355,
1499,
534,
547,
26,
710,
822,
402,
2909,
365,
378,
2659,
339,
347,
664,
63,
15676,
8,
277,
304,
267,
408,
2372,
14075,
1174,
408,
398,
291,
14,
15676,
905,
929,
937,
275,
291,
14,
929,
398,
340,
291,
14,
1985,
26,
288,
291,
14,
15676,
905,
1985,
937,
275,
291,
14,
1985,
339,
347,
664,
63,
5952,
8,
277,
304,
267,
408,
2372,
3411,
1174,
408,
398,
3529,
63,
4128,
275
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
10142,
63,
15523,
63,
1985,
199,
1023,
63,
3270,
26,
298,
18,
14,
20,
2,
199,
3612,
63,
1802,
26,
21612,
26549,
2909,
2897,
641,
869,
21659,
5408,
41,
8142,
8524,
24563,
14,
199,
1802,
26,
272,
446,
21612,
26549,
2909,
13422,
641,
869,
21659,
5408,
41,
8142,
8524,
24563,
14,
199,
2502,
26,
272,
446,
336,
621,
271,
3951,
85,
621,
8593,
9089,
8524,
13,
10047,
9,
199,
1419,
26,
272,
2909,
26,
267,
1369,
26,
288,
446,
12625,
2556,
14,
267,
1415,
26,
2549,
267,
849,
26,
2973,
272,
1174,
26,
267,
1369,
26,
288,
446,
14944,
314,
1174,
402,
314,
2073,
14,
267,
1415,
26,
3055,
267,
849,
26,
3451,
267,
3415,
26,
788,
1881,
1673,
5575,
418,
199,
2344,
199,
199,
8918,
275,
1449,
199,
199,
13,
536,
26,
8142,
8524,
20143,
2909,
511,
523,
7057,
26,
2463,
85,
848,
2598,
523,
1950,
26,
2257,
523,
13082,
63,
5047,
26,
949,
523,
6802,
26,
272,
5053,
26,
489,
1591,
26,
7370,
8200,
63,
4269,
7820,
489,
1844,
26,
7370,
3242,
63,
5510,
63,
719,
7820,
489,
3434,
26,
7370,
3434,
7820,
489,
2505,
26,
7370,
2505,
7820,
489,
7773,
26,
5053,
819,
6527,
26,
819,
446,
536,
26,
298,
2028,
26549,
2909,
2,
272,
10142,
63,
15523,
63,
1985,
26,
489,
1174,
26,
3451,
489,
2909,
26,
12055,
74,
316,
2799,
13765,
489,
5022,
26,
7370,
5053,
7820,
819,
446,
536,
26,
298,
5587,
26549,
2909,
2,
272,
10142,
63,
15523,
63,
1985,
26,
489,
1174,
26,
9552,
489,
2909,
26,
12055,
74,
316,
2799,
13765,
489,
5022,
26,
7370,
5053,
7820,
199,
2344,
199,
199,
9677,
275,
1449,
199,
2489,
26,
272,
1369,
26,
1104,
370,
1937,
340,
282,
1570,
1990,
6326,
641,
314,
2243,
272,
2138,
26,
3544,
272,
730,
26,
5046,
272,
2690,
26,
2549,
199,
15676,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
2633,
3032,
1901,
859,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
2420,
1985,
582,
298,
4304,
74,
316,
2799,
13765,
401,
1467,
298,
929,
582,
298,
1881,
3570,
199,
5952,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
3411,
32396,
1654,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
1052,
199,
500,
63,
929,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
32396,
1862,
2410,
859,
6451,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
2420,
1985,
582,
298,
4304,
74,
316,
2799,
13765,
3570,
199,
7618,
26,
272,
1369,
26,
1414,
4847,
370,
314,
2243,
272,
2138,
26,
3544,
272,
730,
26,
769,
272,
2690,
26,
2097,
15523,
13,
4054,
984,
13,
815,
2909,
12055,
74,
316,
2799,
13765,
937,
199,
2344,
421,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
1251,
85,
848,
2598,
14,
301,
492,
664,
63,
888,
12,
2248,
63,
888,
12,
10142,
63,
2094,
63,
1650,
421,
199,
533,
428,
78,
311,
6592,
8,
785,
304,
272,
408,
21612,
26549,
2909,
2897,
408,
339,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
408,
8089,
4205,
408,
398,
327,
859,
267,
1423,
63,
1650,
275,
2074,
905,
2094,
63,
1650,
937,
267,
291,
14,
1650,
275,
1423,
63,
1650,
267,
291,
14,
578,
275,
6953,
8,
2094,
63,
1650,
29,
277,
14,
1650,
12,
5171,
63,
1074,
63,
632,
29,
549,
9,
398,
327,
1101,
267,
291,
14,
895,
63,
4128,
275,
1211,
342,
398,
327,
859,
1249,
267,
291,
14,
929,
275,
291,
14,
578,
14,
1162,
459,
929,
418,
267,
291,
14,
1985,
275,
291,
14,
578,
14,
1162,
459,
1985,
418,
398,
327,
1174,
267,
291,
14,
2489,
275,
756,
267,
291,
14,
7618,
63,
1760,
275,
769,
342,
267,
291,
14,
2604,
275,
1211,
342,
267,
291,
14,
15676,
275,
1211,
342,
267,
291,
14,
5952,
275,
1211,
342,
267,
291,
14,
500,
63,
929,
275,
1211,
342,
339,
347,
1104,
63,
589,
8,
277,
304,
267,
408,
2670,
3866,
1249,
408,
398,
340,
291,
14,
1985,
26,
288,
340,
822,
8,
277,
14,
1985,
9,
690,
5450,
503,
822,
8,
277,
14,
1985,
9,
665,
413,
26,
355,
291,
14,
578,
14,
1633,
63,
1001,
8,
490,
1499,
534,
547,
26,
710,
822,
402,
2909,
450,
83,
365,
734,
402,
359,
17,
446,
5450,
1055,
7,
450,
291,
14,
1985,
9,
267,
587,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
8,
355,
1499,
534,
547,
26,
710,
822,
402,
2909,
365,
378,
2659,
339,
347,
664,
63,
15676,
8,
277,
304,
267,
408,
2372,
14075,
1174,
408,
398,
291,
14,
15676,
905,
929,
937,
275,
291,
14,
929,
398,
340,
291,
14,
1985,
26,
288,
291,
14,
15676,
905,
1985,
937,
275,
291,
14,
1985,
339,
347,
664,
63,
5952,
8,
277,
304,
267,
408,
2372,
3411,
1174,
408,
398,
3529,
63,
4128,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wylieswanson/agilepyfs
|
fs/tests/__init__.py
|
3
|
43565
|
#!/usr/bin/env python
"""
fs.tests: testcases for the fs module
"""
from __future__ import with_statement
# Send any output from the logging module to stdout, so it will
# be captured by nose and reported appropriately
import sys
import logging
#logging.basicConfig(level=logging.ERROR, stream=sys.stdout)
from fs.base import *
from fs.path import *
from fs.errors import *
from fs.filelike import StringIO
import datetime
import unittest
import os, os.path
import pickle
import random
import copy
import time
try:
import threading
except ImportError:
import dummy_threading as threading
import six
from six import PY3, b
class FSTestCases(object):
"""Base suite of testcases for filesystem implementations.
Any FS subclass should be capable of passing all of these tests.
To apply the tests to your own FS implementation, simply use FSTestCase
as a mixin for your own unittest.TestCase subclass and have the setUp
method set self.fs to an instance of your FS implementation.
NB. The Filesystem being tested must have a capacity of at least 3MB.
This class is designed as a mixin so that it's not detected by test
loading tools such as nose.
"""
def check(self, p):
"""Check that a file exists within self.fs"""
return self.fs.exists(p)
def test_meta(self):
"""Checks getmeta / hasmeta are functioning"""
# getmeta / hasmeta are hard to test, since there is no way to validate
# the implementations response
meta_names = ["read_only",
"network",
"unicode_paths"]
stupid_meta = 'thismetashouldnotexist!"r$$%^&&*()_+'
self.assertRaises(NoMetaError, self.fs.getmeta, stupid_meta)
self.assertFalse(self.fs.hasmeta(stupid_meta))
self.assertEquals(None, self.fs.getmeta(stupid_meta, None))
self.assertEquals(3.14, self.fs.getmeta(stupid_meta, 3.14))
for meta_name in meta_names:
try:
meta = self.fs.getmeta(meta_name)
self.assertTrue(self.fs.hasmeta(meta_name))
except NoMetaError:
self.assertFalse(self.fs.hasmeta(meta_name))
def test_root_dir(self):
self.assertTrue(self.fs.isdir(""))
self.assertTrue(self.fs.isdir("/"))
# These may be false (e.g. empty dict) but mustn't raise errors
self.fs.getinfo("")
self.assertTrue(self.fs.getinfo("/") is not None)
def test_getsyspath(self):
try:
syspath = self.fs.getsyspath("/")
except NoSysPathError:
pass
else:
self.assertTrue(isinstance(syspath,unicode))
syspath = self.fs.getsyspath("/",allow_none=True)
if syspath is not None:
self.assertTrue(isinstance(syspath,unicode))
def test_debug(self):
str(self.fs)
repr(self.fs)
self.assert_(hasattr(self.fs, 'desc'))
def test_open_on_directory(self):
self.fs.makedir("testdir")
try:
f = self.fs.open("testdir")
except ResourceInvalidError:
pass
except Exception:
raise
ecls = sys.exc_info()[0]
assert False, "%s raised instead of ResourceInvalidError" % (ecls,)
else:
f.close()
assert False, "ResourceInvalidError was not raised"
def test_writefile(self):
self.assertRaises(ResourceNotFoundError,self.fs.open,"test1.txt")
f = self.fs.open("test1.txt","wb")
f.write(b("testing"))
f.close()
self.assertTrue(self.check("test1.txt"))
f = self.fs.open("test1.txt","rb")
self.assertEquals(f.read(),b("testing"))
f.close()
f = self.fs.open("test1.txt","wb")
f.write(b("test file overwrite"))
f.close()
self.assertTrue(self.check("test1.txt"))
f = self.fs.open("test1.txt","rb")
self.assertEquals(f.read(),b("test file overwrite"))
f.close()
def test_setcontents(self):
# setcontents() should accept both a string...
self.fs.setcontents("hello",b("world"))
self.assertEquals(self.fs.getcontents("hello", "rb"),b("world"))
# ...and a file-like object
self.fs.setcontents("hello",StringIO(b("to you, good sir!")))
self.assertEquals(self.fs.getcontents("hello", "rb"),b("to you, good sir!"))
# setcontents() should accept both a string...
self.fs.setcontents("hello",b("world"), chunk_size=2)
self.assertEquals(self.fs.getcontents("hello", "rb"),b("world"))
# ...and a file-like object
self.fs.setcontents("hello",StringIO(b("to you, good sir!")), chunk_size=2)
self.assertEquals(self.fs.getcontents("hello", "rb"),b("to you, good sir!"))
def test_setcontents_async(self):
# setcontents() should accept both a string...
self.fs.setcontents_async("hello", b("world")).wait()
self.assertEquals(self.fs.getcontents("hello", "rb"), b("world"))
# ...and a file-like object
self.fs.setcontents_async("hello",StringIO(b("to you, good sir!"))).wait()
self.assertEquals(self.fs.getcontents("hello"), b("to you, good sir!"))
self.fs.setcontents_async("hello", b("world"), chunk_size=2).wait()
self.assertEquals(self.fs.getcontents("hello", "rb"), b("world"))
# ...and a file-like object
self.fs.setcontents_async("hello", StringIO(b("to you, good sir!")), chunk_size=2).wait()
self.assertEquals(self.fs.getcontents("hello", "rb"), b("to you, good sir!"))
def test_isdir_isfile(self):
self.assertFalse(self.fs.exists("dir1"))
self.assertFalse(self.fs.isdir("dir1"))
self.assertFalse(self.fs.isfile("a.txt"))
self.fs.setcontents("a.txt", b(''))
self.assertFalse(self.fs.isdir("dir1"))
self.assertTrue(self.fs.exists("a.txt"))
self.assertTrue(self.fs.isfile("a.txt"))
self.assertFalse(self.fs.exists("a.txt/thatsnotadir"))
self.fs.makedir("dir1")
self.assertTrue(self.fs.isdir("dir1"))
self.assertTrue(self.fs.exists("dir1"))
self.assertTrue(self.fs.exists("a.txt"))
self.fs.remove("a.txt")
self.assertFalse(self.fs.exists("a.txt"))
def test_listdir(self):
def check_unicode(items):
for item in items:
self.assertTrue(isinstance(item,unicode))
self.fs.setcontents(u"a", b(''))
self.fs.setcontents("b", b(''))
self.fs.setcontents("foo", b(''))
self.fs.setcontents("bar", b(''))
# Test listing of the root directory
d1 = self.fs.listdir()
self.assertEqual(len(d1), 4)
self.assertEqual(sorted(d1), [u"a", u"b", u"bar", u"foo"])
check_unicode(d1)
d1 = self.fs.listdir("")
self.assertEqual(len(d1), 4)
self.assertEqual(sorted(d1), [u"a", u"b", u"bar", u"foo"])
check_unicode(d1)
d1 = self.fs.listdir("/")
self.assertEqual(len(d1), 4)
check_unicode(d1)
# Test listing absolute paths
d2 = self.fs.listdir(absolute=True)
self.assertEqual(len(d2), 4)
self.assertEqual(sorted(d2), [u"/a", u"/b", u"/bar", u"/foo"])
check_unicode(d2)
# Create some deeper subdirectories, to make sure their
# contents are not inadvertantly included
self.fs.makedir("p/1/2/3",recursive=True)
self.fs.setcontents("p/1/2/3/a", b(''))
self.fs.setcontents("p/1/2/3/b", b(''))
self.fs.setcontents("p/1/2/3/foo", b(''))
self.fs.setcontents("p/1/2/3/bar", b(''))
self.fs.makedir("q")
# Test listing just files, just dirs, and wildcards
dirs_only = self.fs.listdir(dirs_only=True)
files_only = self.fs.listdir(files_only=True)
contains_a = self.fs.listdir(wildcard="*a*")
self.assertEqual(sorted(dirs_only), [u"p", u"q"])
self.assertEqual(sorted(files_only), [u"a", u"b", u"bar", u"foo"])
self.assertEqual(sorted(contains_a), [u"a",u"bar"])
check_unicode(dirs_only)
check_unicode(files_only)
check_unicode(contains_a)
# Test listing a subdirectory
d3 = self.fs.listdir("p/1/2/3")
self.assertEqual(len(d3), 4)
self.assertEqual(sorted(d3), [u"a", u"b", u"bar", u"foo"])
check_unicode(d3)
# Test listing a subdirectory with absoliute and full paths
d4 = self.fs.listdir("p/1/2/3", absolute=True)
self.assertEqual(len(d4), 4)
self.assertEqual(sorted(d4), [u"/p/1/2/3/a", u"/p/1/2/3/b", u"/p/1/2/3/bar", u"/p/1/2/3/foo"])
check_unicode(d4)
d4 = self.fs.listdir("p/1/2/3", full=True)
self.assertEqual(len(d4), 4)
self.assertEqual(sorted(d4), [u"p/1/2/3/a", u"p/1/2/3/b", u"p/1/2/3/bar", u"p/1/2/3/foo"])
check_unicode(d4)
# Test that appropriate errors are raised
self.assertRaises(ResourceNotFoundError,self.fs.listdir,"zebra")
self.assertRaises(ResourceInvalidError,self.fs.listdir,"foo")
def test_listdirinfo(self):
def check_unicode(items):
for (nm,info) in items:
self.assertTrue(isinstance(nm,unicode))
def check_equal(items,target):
names = [nm for (nm,info) in items]
self.assertEqual(sorted(names),sorted(target))
self.fs.setcontents(u"a", b(''))
self.fs.setcontents("b", b(''))
self.fs.setcontents("foo", b(''))
self.fs.setcontents("bar", b(''))
# Test listing of the root directory
d1 = self.fs.listdirinfo()
self.assertEqual(len(d1), 4)
check_equal(d1, [u"a", u"b", u"bar", u"foo"])
check_unicode(d1)
d1 = self.fs.listdirinfo("")
self.assertEqual(len(d1), 4)
check_equal(d1, [u"a", u"b", u"bar", u"foo"])
check_unicode(d1)
d1 = self.fs.listdirinfo("/")
self.assertEqual(len(d1), 4)
check_equal(d1, [u"a", u"b", u"bar", u"foo"])
check_unicode(d1)
# Test listing absolute paths
d2 = self.fs.listdirinfo(absolute=True)
self.assertEqual(len(d2), 4)
check_equal(d2, [u"/a", u"/b", u"/bar", u"/foo"])
check_unicode(d2)
# Create some deeper subdirectories, to make sure their
# contents are not inadvertantly included
self.fs.makedir("p/1/2/3",recursive=True)
self.fs.setcontents("p/1/2/3/a", b(''))
self.fs.setcontents("p/1/2/3/b", b(''))
self.fs.setcontents("p/1/2/3/foo", b(''))
self.fs.setcontents("p/1/2/3/bar", b(''))
self.fs.makedir("q")
# Test listing just files, just dirs, and wildcards
dirs_only = self.fs.listdirinfo(dirs_only=True)
files_only = self.fs.listdirinfo(files_only=True)
contains_a = self.fs.listdirinfo(wildcard="*a*")
check_equal(dirs_only, [u"p", u"q"])
check_equal(files_only, [u"a", u"b", u"bar", u"foo"])
check_equal(contains_a, [u"a",u"bar"])
check_unicode(dirs_only)
check_unicode(files_only)
check_unicode(contains_a)
# Test listing a subdirectory
d3 = self.fs.listdirinfo("p/1/2/3")
self.assertEqual(len(d3), 4)
check_equal(d3, [u"a", u"b", u"bar", u"foo"])
check_unicode(d3)
# Test listing a subdirectory with absoliute and full paths
d4 = self.fs.listdirinfo("p/1/2/3", absolute=True)
self.assertEqual(len(d4), 4)
check_equal(d4, [u"/p/1/2/3/a", u"/p/1/2/3/b", u"/p/1/2/3/bar", u"/p/1/2/3/foo"])
check_unicode(d4)
d4 = self.fs.listdirinfo("p/1/2/3", full=True)
self.assertEqual(len(d4), 4)
check_equal(d4, [u"p/1/2/3/a", u"p/1/2/3/b", u"p/1/2/3/bar", u"p/1/2/3/foo"])
check_unicode(d4)
# Test that appropriate errors are raised
self.assertRaises(ResourceNotFoundError,self.fs.listdirinfo,"zebra")
self.assertRaises(ResourceInvalidError,self.fs.listdirinfo,"foo")
def test_walk(self):
self.fs.setcontents('a.txt', b('hello'))
self.fs.setcontents('b.txt', b('world'))
self.fs.makeopendir('foo').setcontents('c', b('123'))
sorted_walk = sorted([(d,sorted(fs)) for (d,fs) in self.fs.walk()])
self.assertEquals(sorted_walk,
[("/",["a.txt","b.txt"]),
("/foo",["c"])])
# When searching breadth-first, shallow entries come first
found_a = False
for _,files in self.fs.walk(search="breadth"):
if "a.txt" in files:
found_a = True
if "c" in files:
break
assert found_a, "breadth search order was wrong"
# When searching depth-first, deep entries come first
found_c = False
for _,files in self.fs.walk(search="depth"):
if "c" in files:
found_c = True
if "a.txt" in files:
break
assert found_c, "depth search order was wrong: " + str(list(self.fs.walk(search="depth")))
def test_walk_wildcard(self):
self.fs.setcontents('a.txt', b('hello'))
self.fs.setcontents('b.txt', b('world'))
self.fs.makeopendir('foo').setcontents('c', b('123'))
self.fs.makeopendir('.svn').setcontents('ignored', b(''))
for dir_path, paths in self.fs.walk(wildcard='*.txt'):
for path in paths:
self.assert_(path.endswith('.txt'))
for dir_path, paths in self.fs.walk(wildcard=lambda fn:fn.endswith('.txt')):
for path in paths:
self.assert_(path.endswith('.txt'))
def test_walk_dir_wildcard(self):
self.fs.setcontents('a.txt', b('hello'))
self.fs.setcontents('b.txt', b('world'))
self.fs.makeopendir('foo').setcontents('c', b('123'))
self.fs.makeopendir('.svn').setcontents('ignored', b(''))
for dir_path, paths in self.fs.walk(dir_wildcard=lambda fn:not fn.endswith('.svn')):
for path in paths:
self.assert_('.svn' not in path)
def test_walkfiles(self):
self.fs.makeopendir('bar').setcontents('a.txt', b('123'))
self.fs.makeopendir('foo').setcontents('b', b('123'))
self.assertEquals(sorted(self.fs.walkfiles()),["/bar/a.txt","/foo/b"])
self.assertEquals(sorted(self.fs.walkfiles(dir_wildcard="*foo*")),["/foo/b"])
self.assertEquals(sorted(self.fs.walkfiles(wildcard="*.txt")),["/bar/a.txt"])
def test_walkdirs(self):
self.fs.makeopendir('bar').setcontents('a.txt', b('123'))
self.fs.makeopendir('foo').makeopendir("baz").setcontents('b', b('123'))
self.assertEquals(sorted(self.fs.walkdirs()),["/","/bar","/foo","/foo/baz"])
self.assertEquals(sorted(self.fs.walkdirs(wildcard="*foo*")),["/","/foo","/foo/baz"])
def test_unicode(self):
alpha = u"\N{GREEK SMALL LETTER ALPHA}"
beta = u"\N{GREEK SMALL LETTER BETA}"
self.fs.makedir(alpha)
self.fs.setcontents(alpha+"/a", b(''))
self.fs.setcontents(alpha+"/"+beta, b(''))
self.assertTrue(self.check(alpha))
self.assertEquals(sorted(self.fs.listdir(alpha)),["a",beta])
def test_makedir(self):
check = self.check
self.fs.makedir("a")
self.assertTrue(check("a"))
self.assertRaises(ParentDirectoryMissingError,self.fs.makedir,"a/b/c")
self.fs.makedir("a/b/c", recursive=True)
self.assert_(check("a/b/c"))
self.fs.makedir("foo/bar/baz", recursive=True)
self.assert_(check("foo/bar/baz"))
self.fs.makedir("a/b/child")
self.assert_(check("a/b/child"))
self.assertRaises(DestinationExistsError,self.fs.makedir,"/a/b")
self.fs.makedir("/a/b",allow_recreate=True)
self.fs.setcontents("/a/file", b(''))
self.assertRaises(ResourceInvalidError,self.fs.makedir,"a/file")
def test_remove(self):
self.fs.setcontents("a.txt", b(''))
self.assertTrue(self.check("a.txt"))
self.fs.remove("a.txt")
self.assertFalse(self.check("a.txt"))
self.assertRaises(ResourceNotFoundError,self.fs.remove,"a.txt")
self.fs.makedir("dir1")
self.assertRaises(ResourceInvalidError,self.fs.remove,"dir1")
self.fs.setcontents("/dir1/a.txt", b(''))
self.assertTrue(self.check("dir1/a.txt"))
self.fs.remove("dir1/a.txt")
self.assertFalse(self.check("/dir1/a.txt"))
def test_removedir(self):
check = self.check
self.fs.makedir("a")
self.assert_(check("a"))
self.fs.removedir("a")
self.assertRaises(ResourceNotFoundError, self.fs.removedir, "a")
self.assert_(not check("a"))
self.fs.makedir("a/b/c/d", recursive=True)
self.assertRaises(DirectoryNotEmptyError, self.fs.removedir, "a/b")
self.fs.removedir("a/b/c/d")
self.assert_(not check("a/b/c/d"))
self.fs.removedir("a/b/c")
self.assert_(not check("a/b/c"))
self.fs.removedir("a/b")
self.assert_(not check("a/b"))
# Test recursive removal of empty parent dirs
self.fs.makedir("foo/bar/baz", recursive=True)
self.fs.removedir("foo/bar/baz", recursive=True)
self.assert_(not check("foo/bar/baz"))
self.assert_(not check("foo/bar"))
self.assert_(not check("foo"))
self.fs.makedir("foo/bar/baz", recursive=True)
self.fs.setcontents("foo/file.txt", b("please don't delete me"))
self.fs.removedir("foo/bar/baz", recursive=True)
self.assert_(not check("foo/bar/baz"))
self.assert_(not check("foo/bar"))
# Ensure that force=True works as expected
self.fs.makedir("frollic/waggle", recursive=True)
self.fs.setcontents("frollic/waddle.txt",b("waddlewaddlewaddle"))
self.assertRaises(DirectoryNotEmptyError,self.fs.removedir,"frollic")
self.assertRaises(ResourceInvalidError,self.fs.removedir,"frollic/waddle.txt")
self.fs.removedir("frollic",force=True)
self.assert_(not check("frollic"))
# Test removing unicode dirs
kappa = u"\N{GREEK CAPITAL LETTER KAPPA}"
self.fs.makedir(kappa)
self.assert_(self.fs.isdir(kappa))
self.fs.removedir(kappa)
self.assertRaises(ResourceNotFoundError, self.fs.removedir, kappa)
self.assert_(not self.fs.isdir(kappa))
self.fs.makedir(pathjoin("test",kappa),recursive=True)
self.assert_(check(pathjoin("test",kappa)))
self.fs.removedir("test",force=True)
self.assert_(not check("test"))
def test_rename(self):
check = self.check
# test renaming a file in the same directory
self.fs.setcontents("foo.txt",b("Hello, World!"))
self.assert_(check("foo.txt"))
self.fs.rename("foo.txt", "bar.txt")
self.assert_(check("bar.txt"))
self.assert_(not check("foo.txt"))
# test renaming a directory in the same directory
self.fs.makedir("dir_a")
self.fs.setcontents("dir_a/test.txt",b("testerific"))
self.assert_(check("dir_a"))
self.fs.rename("dir_a","dir_b")
self.assert_(check("dir_b"))
self.assert_(check("dir_b/test.txt"))
self.assert_(not check("dir_a/test.txt"))
self.assert_(not check("dir_a"))
# test renaming a file into a different directory
self.fs.makedir("dir_a")
self.fs.rename("dir_b/test.txt","dir_a/test.txt")
self.assert_(not check("dir_b/test.txt"))
self.assert_(check("dir_a/test.txt"))
# test renaming a file into a non-existent directory
self.assertRaises(ParentDirectoryMissingError,self.fs.rename,"dir_a/test.txt","nonexistent/test.txt")
def test_info(self):
test_str = b("Hello, World!")
self.fs.setcontents("info.txt",test_str)
info = self.fs.getinfo("info.txt")
self.assertEqual(info['size'], len(test_str))
self.fs.desc("info.txt")
self.assertRaises(ResourceNotFoundError,self.fs.getinfo,"notafile")
self.assertRaises(ResourceNotFoundError,self.fs.getinfo,"info.txt/inval")
def test_getsize(self):
test_str = b("*")*23
self.fs.setcontents("info.txt",test_str)
size = self.fs.getsize("info.txt")
self.assertEqual(size, len(test_str))
def test_movefile(self):
check = self.check
contents = b("If the implementation is hard to explain, it's a bad idea.")
def makefile(path):
self.fs.setcontents(path,contents)
def checkcontents(path):
check_contents = self.fs.getcontents(path, "rb")
self.assertEqual(check_contents,contents)
return contents == check_contents
self.fs.makedir("foo/bar", recursive=True)
makefile("foo/bar/a.txt")
self.assert_(check("foo/bar/a.txt"))
self.assert_(checkcontents("foo/bar/a.txt"))
self.fs.move("foo/bar/a.txt", "foo/b.txt")
self.assert_(not check("foo/bar/a.txt"))
self.assert_(check("foo/b.txt"))
self.assert_(checkcontents("foo/b.txt"))
self.fs.move("foo/b.txt", "c.txt")
self.assert_(not check("foo/b.txt"))
self.assert_(check("/c.txt"))
self.assert_(checkcontents("/c.txt"))
makefile("foo/bar/a.txt")
self.assertRaises(DestinationExistsError,self.fs.move,"foo/bar/a.txt","/c.txt")
self.assert_(check("foo/bar/a.txt"))
self.assert_(check("/c.txt"))
self.fs.move("foo/bar/a.txt","/c.txt",overwrite=True)
self.assert_(not check("foo/bar/a.txt"))
self.assert_(check("/c.txt"))
def test_movedir(self):
check = self.check
contents = b("If the implementation is hard to explain, it's a bad idea.")
def makefile(path):
self.fs.setcontents(path, contents)
self.assertRaises(ResourceNotFoundError,self.fs.movedir,"a","b")
self.fs.makedir("a")
self.fs.makedir("b")
makefile("a/1.txt")
makefile("a/2.txt")
makefile("a/3.txt")
self.fs.makedir("a/foo/bar", recursive=True)
makefile("a/foo/bar/baz.txt")
self.fs.movedir("a", "copy of a")
self.assert_(self.fs.isdir("copy of a"))
self.assert_(check("copy of a/1.txt"))
self.assert_(check("copy of a/2.txt"))
self.assert_(check("copy of a/3.txt"))
self.assert_(check("copy of a/foo/bar/baz.txt"))
self.assert_(not check("a/1.txt"))
self.assert_(not check("a/2.txt"))
self.assert_(not check("a/3.txt"))
self.assert_(not check("a/foo/bar/baz.txt"))
self.assert_(not check("a/foo/bar"))
self.assert_(not check("a/foo"))
self.assert_(not check("a"))
self.fs.makedir("a")
self.assertRaises(DestinationExistsError,self.fs.movedir,"copy of a","a")
self.fs.movedir("copy of a","a",overwrite=True)
self.assert_(not check("copy of a"))
self.assert_(check("a/1.txt"))
self.assert_(check("a/2.txt"))
self.assert_(check("a/3.txt"))
self.assert_(check("a/foo/bar/baz.txt"))
def test_cant_copy_from_os(self):
sys_executable = os.path.abspath(os.path.realpath(sys.executable))
self.assertRaises(FSError,self.fs.copy,sys_executable,"py.exe")
def test_copyfile(self):
check = self.check
contents = b("If the implementation is hard to explain, it's a bad idea.")
def makefile(path,contents=contents):
self.fs.setcontents(path,contents)
def checkcontents(path,contents=contents):
check_contents = self.fs.getcontents(path, "rb")
self.assertEqual(check_contents,contents)
return contents == check_contents
self.fs.makedir("foo/bar", recursive=True)
makefile("foo/bar/a.txt")
self.assert_(check("foo/bar/a.txt"))
self.assert_(checkcontents("foo/bar/a.txt"))
#import rpdb2; rpdb2.start_embedded_debugger('password');
self.fs.copy("foo/bar/a.txt", "foo/b.txt")
self.assert_(check("foo/bar/a.txt"))
self.assert_(check("foo/b.txt"))
self.assert_(checkcontents("foo/bar/a.txt"))
self.assert_(checkcontents("foo/b.txt"))
self.fs.copy("foo/b.txt", "c.txt")
self.assert_(check("foo/b.txt"))
self.assert_(check("/c.txt"))
self.assert_(checkcontents("/c.txt"))
makefile("foo/bar/a.txt",b("different contents"))
self.assert_(checkcontents("foo/bar/a.txt",b("different contents")))
self.assertRaises(DestinationExistsError,self.fs.copy,"foo/bar/a.txt","/c.txt")
self.assert_(checkcontents("/c.txt"))
self.fs.copy("foo/bar/a.txt","/c.txt",overwrite=True)
self.assert_(checkcontents("foo/bar/a.txt",b("different contents")))
self.assert_(checkcontents("/c.txt",b("different contents")))
def test_copydir(self):
check = self.check
contents = b("If the implementation is hard to explain, it's a bad idea.")
def makefile(path):
self.fs.setcontents(path,contents)
def checkcontents(path):
check_contents = self.fs.getcontents(path)
self.assertEqual(check_contents,contents)
return contents == check_contents
self.fs.makedir("a")
self.fs.makedir("b")
makefile("a/1.txt")
makefile("a/2.txt")
makefile("a/3.txt")
self.fs.makedir("a/foo/bar", recursive=True)
makefile("a/foo/bar/baz.txt")
self.fs.copydir("a", "copy of a")
self.assert_(check("copy of a/1.txt"))
self.assert_(check("copy of a/2.txt"))
self.assert_(check("copy of a/3.txt"))
self.assert_(check("copy of a/foo/bar/baz.txt"))
checkcontents("copy of a/1.txt")
self.assert_(check("a/1.txt"))
self.assert_(check("a/2.txt"))
self.assert_(check("a/3.txt"))
self.assert_(check("a/foo/bar/baz.txt"))
checkcontents("a/1.txt")
self.assertRaises(DestinationExistsError,self.fs.copydir,"a","b")
self.fs.copydir("a","b",overwrite=True)
self.assert_(check("b/1.txt"))
self.assert_(check("b/2.txt"))
self.assert_(check("b/3.txt"))
self.assert_(check("b/foo/bar/baz.txt"))
checkcontents("b/1.txt")
def test_copydir_with_dotfile(self):
check = self.check
contents = b("If the implementation is hard to explain, it's a bad idea.")
def makefile(path):
self.fs.setcontents(path,contents)
self.fs.makedir("a")
makefile("a/1.txt")
makefile("a/2.txt")
makefile("a/.hidden.txt")
self.fs.copydir("a", "copy of a")
self.assert_(check("copy of a/1.txt"))
self.assert_(check("copy of a/2.txt"))
self.assert_(check("copy of a/.hidden.txt"))
self.assert_(check("a/1.txt"))
self.assert_(check("a/2.txt"))
self.assert_(check("a/.hidden.txt"))
def test_readwriteappendseek(self):
def checkcontents(path, check_contents):
read_contents = self.fs.getcontents(path, "rb")
self.assertEqual(read_contents,check_contents)
return read_contents == check_contents
test_strings = [b("Beautiful is better than ugly."),
b("Explicit is better than implicit."),
b("Simple is better than complex.")]
all_strings = b("").join(test_strings)
self.assertRaises(ResourceNotFoundError, self.fs.open, "a.txt", "r")
self.assert_(not self.fs.exists("a.txt"))
f1 = self.fs.open("a.txt", "wb")
pos = 0
for s in test_strings:
f1.write(s)
pos += len(s)
self.assertEqual(pos, f1.tell())
f1.close()
self.assert_(self.fs.exists("a.txt"))
self.assert_(checkcontents("a.txt", all_strings))
f2 = self.fs.open("b.txt", "wb")
f2.write(test_strings[0])
f2.close()
self.assert_(checkcontents("b.txt", test_strings[0]))
f3 = self.fs.open("b.txt", "ab")
# On win32, tell() gives zero until you actually write to the file
#self.assertEquals(f3.tell(),len(test_strings[0]))
f3.write(test_strings[1])
self.assertEquals(f3.tell(),len(test_strings[0])+len(test_strings[1]))
f3.write(test_strings[2])
self.assertEquals(f3.tell(),len(all_strings))
f3.close()
self.assert_(checkcontents("b.txt", all_strings))
f4 = self.fs.open("b.txt", "wb")
f4.write(test_strings[2])
f4.close()
self.assert_(checkcontents("b.txt", test_strings[2]))
f5 = self.fs.open("c.txt", "wb")
for s in test_strings:
f5.write(s+b("\n"))
f5.close()
f6 = self.fs.open("c.txt", "rb")
for s, t in zip(f6, test_strings):
self.assertEqual(s, t+b("\n"))
f6.close()
f7 = self.fs.open("c.txt", "rb")
f7.seek(13)
word = f7.read(6)
self.assertEqual(word, b("better"))
f7.seek(1, os.SEEK_CUR)
word = f7.read(4)
self.assertEqual(word, b("than"))
f7.seek(-9, os.SEEK_END)
word = f7.read(7)
self.assertEqual(word, b("complex"))
f7.close()
self.assertEqual(self.fs.getcontents("a.txt", "rb"), all_strings)
def test_truncate(self):
def checkcontents(path, check_contents):
read_contents = self.fs.getcontents(path, "rb")
self.assertEqual(read_contents,check_contents)
return read_contents == check_contents
self.fs.setcontents("hello",b("world"))
checkcontents("hello",b("world"))
self.fs.setcontents("hello",b("hi"))
checkcontents("hello",b("hi"))
self.fs.setcontents("hello",b("1234567890"))
checkcontents("hello",b("1234567890"))
with self.fs.open("hello","rb+") as f:
f.truncate(7)
checkcontents("hello",b("1234567"))
with self.fs.open("hello","rb+") as f:
f.seek(5)
f.truncate()
checkcontents("hello",b("12345"))
def test_truncate_to_larger_size(self):
with self.fs.open("hello","wb") as f:
f.truncate(30)
self.assertEquals(self.fs.getsize("hello"), 30)
# Some file systems (FTPFS) don't support both reading and writing
if self.fs.getmeta('file.read_and_write', True):
with self.fs.open("hello","rb+") as f:
f.seek(25)
f.write(b("123456"))
with self.fs.open("hello","rb") as f:
f.seek(25)
self.assertEquals(f.read(),b("123456"))
def test_write_past_end_of_file(self):
if self.fs.getmeta('file.read_and_write', True):
with self.fs.open("write_at_end","wb") as f:
f.seek(25)
f.write(b("EOF"))
with self.fs.open("write_at_end","rb") as f:
self.assertEquals(f.read(),b("\x00")*25 + b("EOF"))
def test_with_statement(self):
# This is a little tricky since 'with' is actually new syntax.
# We use eval() to make this method safe for old python versions.
import sys
if sys.version_info[0] >= 2 and sys.version_info[1] >= 5:
# A successful 'with' statement
contents = "testing the with statement"
code = "from __future__ import with_statement\n"
code += "with self.fs.open('f.txt','wb-') as testfile:\n"
code += " testfile.write(contents)\n"
code += "self.assertEquals(self.fs.getcontents('f.txt', 'rb'),contents)"
code = compile(code,"<string>",'exec')
eval(code)
# A 'with' statement raising an error
contents = "testing the with statement"
code = "from __future__ import with_statement\n"
code += "with self.fs.open('f.txt','wb-') as testfile:\n"
code += " testfile.write(contents)\n"
code += " raise ValueError\n"
code = compile(code,"<string>",'exec')
self.assertRaises(ValueError,eval,code,globals(),locals())
self.assertEquals(self.fs.getcontents('f.txt', 'rb'),contents)
def test_pickling(self):
if self.fs.getmeta('pickle_contents', True):
self.fs.setcontents("test1",b("hello world"))
fs2 = pickle.loads(pickle.dumps(self.fs))
self.assert_(fs2.isfile("test1"))
fs3 = pickle.loads(pickle.dumps(self.fs,-1))
self.assert_(fs3.isfile("test1"))
else:
# Just make sure it doesn't throw an exception
fs2 = pickle.loads(pickle.dumps(self.fs))
def test_big_file(self):
"""Test handling of a big file (1MB)"""
chunk_size = 1024 * 256
num_chunks = 4
def chunk_stream():
"""Generate predictable-but-randomy binary content."""
r = random.Random(0)
randint = r.randint
int2byte = six.int2byte
for _i in xrange(num_chunks):
c = b("").join(int2byte(randint(0,255)) for _j in xrange(chunk_size//8))
yield c * 8
f = self.fs.open("bigfile","wb")
try:
for chunk in chunk_stream():
f.write(chunk)
finally:
f.close()
chunks = chunk_stream()
f = self.fs.open("bigfile","rb")
try:
try:
while True:
if chunks.next() != f.read(chunk_size):
assert False, "bigfile was corrupted"
except StopIteration:
if f.read() != b(""):
assert False, "bigfile was corrupted"
finally:
f.close()
def test_settimes(self):
def cmp_datetimes(d1, d2):
"""Test datetime objects are the same to within the timestamp accuracy"""
dts1 = time.mktime(d1.timetuple())
dts2 = time.mktime(d2.timetuple())
return int(dts1) == int(dts2)
d1 = datetime.datetime(2010, 6, 20, 11, 0, 9, 987699)
d2 = datetime.datetime(2010, 7, 5, 11, 0, 9, 500000)
self.fs.setcontents('/dates.txt', b('check dates'))
# If the implementation supports settimes, check that the times
# can be set and then retrieved
try:
self.fs.settimes('/dates.txt', d1, d2)
except UnsupportedError:
pass
else:
info = self.fs.getinfo('/dates.txt')
self.assertTrue(cmp_datetimes(d1, info['accessed_time']))
self.assertTrue(cmp_datetimes(d2, info['modified_time']))
def test_removeroot(self):
self.assertRaises(RemoveRootError, self.fs.removedir, "/")
# May be disabled - see end of file
class ThreadingTestCases(object):
"""Testcases for thread-safety of FS implementations."""
# These are either too slow to be worth repeating,
# or cannot possibly break cross-thread.
_dont_retest = ("test_pickling","test_multiple_overwrite",)
__lock = threading.RLock()
def _yield(self):
#time.sleep(0.001)
# Yields without a delay
time.sleep(0)
def _lock(self):
self.__lock.acquire()
def _unlock(self):
self.__lock.release()
def _makeThread(self,func,errors):
def runThread():
try:
func()
except Exception:
errors.append(sys.exc_info())
thread = threading.Thread(target=runThread)
thread.daemon = True
return thread
def _runThreads(self,*funcs):
check_interval = sys.getcheckinterval()
sys.setcheckinterval(1)
try:
errors = []
threads = [self._makeThread(f,errors) for f in funcs]
for t in threads:
t.start()
for t in threads:
t.join()
for (c,e,t) in errors:
raise c,e,t
finally:
sys.setcheckinterval(check_interval)
def test_setcontents_threaded(self):
def setcontents(name,contents):
f = self.fs.open(name,"wb")
self._yield()
try:
f.write(contents)
self._yield()
finally:
f.close()
def thread1():
c = b("thread1 was 'ere")
setcontents("thread1.txt",c)
self.assertEquals(self.fs.getcontents("thread1.txt", 'rb'),c)
def thread2():
c = b("thread2 was 'ere")
setcontents("thread2.txt",c)
self.assertEquals(self.fs.getcontents("thread2.txt", 'rb'),c)
self._runThreads(thread1,thread2)
def test_setcontents_threaded_samefile(self):
def setcontents(name,contents):
f = self.fs.open(name,"wb")
self._yield()
try:
f.write(contents)
self._yield()
finally:
f.close()
def thread1():
c = b("thread1 was 'ere")
setcontents("threads.txt",c)
self._yield()
self.assertEquals(self.fs.listdir("/"),["threads.txt"])
def thread2():
c = b("thread2 was 'ere")
setcontents("threads.txt",c)
self._yield()
self.assertEquals(self.fs.listdir("/"),["threads.txt"])
def thread3():
c = b("thread3 was 'ere")
setcontents("threads.txt",c)
self._yield()
self.assertEquals(self.fs.listdir("/"),["threads.txt"])
try:
self._runThreads(thread1,thread2,thread3)
except ResourceLockedError:
# that's ok, some implementations don't support concurrent writes
pass
def test_cases_in_separate_dirs(self):
class TestCases_in_subdir(self.__class__,unittest.TestCase):
"""Run all testcases against a subdir of self.fs"""
def __init__(this,subdir):
super(TestCases_in_subdir, this).__init__("test_listdir")
this.subdir = subdir
for meth in dir(this):
if not meth.startswith("test_"):
continue
if meth in self._dont_retest:
continue
if not hasattr(FSTestCases,meth):
continue
if self.fs.exists(subdir):
self.fs.removedir(subdir,force=True)
self.assertFalse(self.fs.isdir(subdir))
self.assertTrue(self.fs.isdir("/"))
self.fs.makedir(subdir)
self._yield()
getattr(this,meth)()
@property
def fs(this):
return self.fs.opendir(this.subdir)
def check(this,p):
return self.check(pathjoin(this.subdir,relpath(p)))
def thread1():
TestCases_in_subdir("thread1")
def thread2():
TestCases_in_subdir("thread2")
def thread3():
TestCases_in_subdir("thread3")
self._runThreads(thread1,thread2,thread3)
def test_makedir_winner(self):
errors = []
def makedir():
try:
self.fs.makedir("testdir")
except DestinationExistsError, e:
errors.append(e)
def makedir_noerror():
try:
self.fs.makedir("testdir",allow_recreate=True)
except DestinationExistsError, e:
errors.append(e)
def removedir():
try:
self.fs.removedir("testdir")
except (ResourceNotFoundError,ResourceLockedError), e:
errors.append(e)
# One thread should succeed, one should error
self._runThreads(makedir,makedir)
self.assertEquals(len(errors),1)
self.fs.removedir("testdir")
# One thread should succeed, two should error
errors = []
self._runThreads(makedir,makedir,makedir)
if len(errors) != 2:
raise AssertionError(errors)
self.fs.removedir("testdir")
# All threads should succeed
errors = []
self._runThreads(makedir_noerror,makedir_noerror,makedir_noerror)
self.assertEquals(len(errors),0)
self.assertTrue(self.fs.isdir("testdir"))
self.fs.removedir("testdir")
# makedir() can beat removedir() and vice-versa
errors = []
self._runThreads(makedir,removedir)
if self.fs.isdir("testdir"):
self.assertEquals(len(errors),1)
self.assertFalse(isinstance(errors[0],DestinationExistsError))
self.fs.removedir("testdir")
else:
self.assertEquals(len(errors),0)
def test_concurrent_copydir(self):
self.fs.makedir("a")
self.fs.makedir("a/b")
self.fs.setcontents("a/hello.txt",b("hello world"))
self.fs.setcontents("a/guido.txt",b("is a space alien"))
self.fs.setcontents("a/b/parrot.txt",b("pining for the fiords"))
def copydir():
self._yield()
self.fs.copydir("a","copy of a")
def copydir_overwrite():
self._yield()
self.fs.copydir("a","copy of a",overwrite=True)
# This should error out since we're not overwriting
self.assertRaises(DestinationExistsError,self._runThreads,copydir,copydir)
# This should run to completion and give a valid state, unless
# files get locked when written to.
try:
self._runThreads(copydir_overwrite,copydir_overwrite)
except ResourceLockedError:
pass
self.assertTrue(self.fs.isdir("copy of a"))
self.assertTrue(self.fs.isdir("copy of a/b"))
self.assertEqual(self.fs.getcontents("copy of a/b/parrot.txt", 'rb'),b("pining for the fiords"))
self.assertEqual(self.fs.getcontents("copy of a/hello.txt", 'rb'),b("hello world"))
self.assertEqual(self.fs.getcontents("copy of a/guido.txt", 'rb'),b("is a space alien"))
def test_multiple_overwrite(self):
contents = [b("contents one"),b("contents the second"),b("number three")]
def thread1():
for i in xrange(30):
for c in contents:
self.fs.setcontents("thread1.txt",c)
self.assertEquals(self.fs.getsize("thread1.txt"),len(c))
self.assertEquals(self.fs.getcontents("thread1.txt", 'rb'),c)
def thread2():
for i in xrange(30):
for c in contents:
self.fs.setcontents("thread2.txt",c)
self.assertEquals(self.fs.getsize("thread2.txt"),len(c))
self.assertEquals(self.fs.getcontents("thread2.txt", 'rb'),c)
self._runThreads(thread1,thread2)
# Uncomment to temporarily disable threading tests
#class ThreadingTestCases(object):
# _dont_retest = ()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
819,
7449,
14,
2219,
26,
221,
511,
9403,
367,
314,
7449,
859,
199,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
3,
221,
10217,
1263,
1072,
687,
314,
2050,
859,
370,
3839,
12,
880,
652,
911,
199,
3,
221,
506,
17487,
701,
11354,
436,
14581,
22497,
199,
646,
984,
199,
646,
2050,
199,
3,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
3170,
12,
2547,
29,
1274,
14,
2703,
9,
199,
199,
504,
7449,
14,
1095,
492,
627,
199,
504,
7449,
14,
515,
492,
627,
199,
504,
7449,
14,
2550,
492,
627,
199,
504,
7449,
14,
493,
2930,
492,
5228,
199,
199,
646,
2197,
199,
646,
2882,
199,
646,
747,
12,
747,
14,
515,
199,
646,
5927,
199,
646,
2196,
199,
646,
1331,
199,
199,
646,
900,
199,
893,
26,
272,
492,
5796,
199,
2590,
3545,
26,
272,
492,
7283,
63,
12562,
465,
5796,
199,
199,
646,
3816,
199,
504,
3816,
492,
7843,
19,
12,
330,
199,
199,
533,
27500,
19346,
8,
785,
304,
272,
408,
1563,
5241,
402,
511,
9403,
367,
10036,
12591,
14,
339,
6184,
27500,
5516,
1077,
506,
4021,
461,
402,
9476,
1006,
402,
3520,
2295,
14,
272,
4005,
4838,
314,
2295,
370,
2195,
5705,
27500,
4514,
12,
9329,
675,
27500,
1746,
272,
465,
282,
20048,
367,
2195,
5705,
2882,
14,
1746,
5516,
436,
1172,
314,
3613,
272,
1083,
663,
291,
14,
2319,
370,
376,
1256,
402,
2195,
27500,
4514,
14,
2286,
25377,
14,
710,
3814,
2253,
3769,
12470,
1471,
1172,
282,
14893,
402,
737,
5210,
650,
4567,
14,
339,
961,
1021,
365,
19829,
465,
282,
20048,
880,
626,
652,
1159,
440,
10501,
701,
511,
272,
8697,
7249,
4066,
465,
11354,
14,
272,
408,
339,
347,
1104,
8,
277,
12,
299,
304,
267,
408,
1799,
626,
282,
570,
3495,
4453,
291,
14,
2319,
624,
267,
372,
291,
14,
2319,
14,
2444,
8,
80,
9,
339,
347,
511,
63,
2024,
8,
277,
304,
267,
408,
11834,
664,
2024,
1182,
965,
2024,
787,
805,
316,
624,
267,
327,
664,
2024,
1182,
965,
2024,
787,
7508,
370,
511,
12,
3967,
2337,
365,
949,
4340,
370,
4107,
267,
327,
314,
12591,
1177,
267,
3404,
63,
1247,
275,
2097,
739,
63,
2118,
401,
1993,
298,
1200,
401,
1993,
298,
2975,
63,
3771,
937,
267,
410,
31596,
63,
2024,
275,
283,
3749,
10207,
305,
3772,
889,
3858,
631,
9539,
82,
4,
22074,
62,
12574,
10,
342,
63,
4786,
267,
291,
14,
1855,
8,
1944,
3396,
547,
12,
291,
14,
2319,
14,
362,
2024,
12,
410,
31596,
63,
2024,
9,
267,
291,
14,
3334,
8,
277,
14,
2319,
14,
1989,
2024,
8,
270,
31596,
63,
2024,
430,
267,
291,
14,
2947,
8,
403,
12,
291,
14,
2319,
14,
362,
2024,
8,
270,
31596,
63,
2024,
12,
488,
430,
267,
291,
14,
2947,
8,
19,
14,
1079,
12,
291,
14,
2319,
14,
362,
2024,
8,
270,
31596,
63,
2024,
12,
650,
14,
1079,
430,
267,
367,
3404,
63,
354,
315,
3404,
63,
1247,
26,
288,
862,
26,
355,
3404,
275,
291,
14,
2319,
14,
362,
2024,
8,
2024,
63,
354,
9,
355,
291,
14,
1815,
8,
277,
14,
2319,
14,
1989,
2024,
8,
2024,
63,
354,
430,
288,
871,
3091,
3396,
547,
26,
355,
291,
14,
3334,
8,
277,
14,
2319,
14,
1989,
2024,
8,
2024,
63,
354,
430,
268,
339,
347,
511,
63,
1231,
63,
694,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
2319,
14,
6027,
31348,
267,
291,
14,
1815,
8,
277,
14,
2319,
14,
6027,
4769,
2237,
267,
327,
5723,
1443,
506,
3055,
334,
69,
14,
71,
14,
2701,
1211,
9,
1325,
1471,
78,
1133,
746,
2552,
267,
291,
14,
2319,
14,
32286,
10804,
267,
291,
14,
1815,
8,
277,
14,
2319,
14,
32286,
19031,
365,
440,
488,
9,
339,
347,
511,
63,
362,
1274,
515,
8,
277,
304,
267,
862,
26,
288,
984,
515,
275,
291,
14,
2319,
14,
362,
1274,
515,
19031,
267,
871,
3091,
11319,
2042,
547,
26,
288,
986,
267,
587,
26,
288,
291,
14,
1815,
8,
6074,
8,
1274,
515,
12,
2975,
430,
267,
984,
515,
275,
291,
14,
2319,
14,
362,
1274,
515,
27374,
3306,
63,
3592,
29,
549,
9,
267,
340,
984,
515,
365,
440,
488,
26,
288,
291,
14,
1815,
8,
6074,
8,
1274,
515,
12,
2975,
430,
339,
347,
511,
63,
1757,
8,
277,
304,
267,
620,
8,
277,
14,
2319,
9,
267,
4700,
8,
277,
14,
2319,
9,
267,
291,
14,
479,
2531,
11161,
8,
277,
14,
2319,
12,
283,
3257,
1333,
339,
347,
511,
63,
1490,
63,
265,
63,
3619,
8,
277,
304,
267,
291,
14,
2319,
14,
1875,
694,
480,
16634,
531,
267,
862,
26,
288,
289,
275,
291,
14,
2319,
14,
1490,
480,
16634,
531,
267,
871,
7337,
3364,
547,
26,
288,
986,
267,
871,
2186,
26,
288,
746,
288,
325,
1886,
275,
984,
14,
2804,
63,
815,
3430,
16,
61,
288,
702,
756,
12,
2071,
83,
4915,
3140,
402,
7337,
3364,
547,
2,
450,
334,
69,
1886,
4258,
267,
587,
26,
288,
289,
14,
1600,
342,
288,
702,
756,
12,
298,
4031,
3364,
547,
1990,
440,
4915,
2,
2126,
272,
347,
511,
63,
952,
493,
8,
277,
304,
267,
291,
14,
1855,
8,
4031,
10870,
12,
277,
14,
2319,
14,
1490,
4589,
396,
17,
14,
2424,
531,
267,
289,
275,
291,
14,
2319,
14,
1490,
480,
396,
17,
14,
2424,
2266,
6603,
531,
267,
289,
14,
952,
8,
66,
480,
4776,
2237,
267,
289,
14,
1600,
342,
267,
291,
14,
1815,
8,
277,
14,
1074,
480,
396,
17,
14,
2424,
2237,
267,
289,
275,
291,
14,
2319,
14,
1490,
480,
396,
17,
14,
2424,
2266,
4848,
531,
267,
291,
14,
2947,
8,
70,
14,
739,
1062,
66,
480,
4776,
2237,
267,
289,
14,
1600,
342,
267,
289,
275,
291,
14,
2319,
14,
1490,
480,
396,
17,
14,
2424,
2266,
6603,
531,
267,
289,
14,
952,
8,
66,
480,
396,
570,
8970,
2237,
267,
289,
14,
1600,
342,
267,
291,
14,
1815,
8,
277,
14,
1074,
480,
396,
17,
14,
2424,
2237,
267,
289,
275,
291,
14,
2319,
14,
1490,
480,
396,
17,
14,
2424
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
819,
7449,
14,
2219,
26,
221,
511,
9403,
367,
314,
7449,
859,
199,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
3,
221,
10217,
1263,
1072,
687,
314,
2050,
859,
370,
3839,
12,
880,
652,
911,
199,
3,
221,
506,
17487,
701,
11354,
436,
14581,
22497,
199,
646,
984,
199,
646,
2050,
199,
3,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
3170,
12,
2547,
29,
1274,
14,
2703,
9,
199,
199,
504,
7449,
14,
1095,
492,
627,
199,
504,
7449,
14,
515,
492,
627,
199,
504,
7449,
14,
2550,
492,
627,
199,
504,
7449,
14,
493,
2930,
492,
5228,
199,
199,
646,
2197,
199,
646,
2882,
199,
646,
747,
12,
747,
14,
515,
199,
646,
5927,
199,
646,
2196,
199,
646,
1331,
199,
199,
646,
900,
199,
893,
26,
272,
492,
5796,
199,
2590,
3545,
26,
272,
492,
7283,
63,
12562,
465,
5796,
199,
199,
646,
3816,
199,
504,
3816,
492,
7843,
19,
12,
330,
199,
199,
533,
27500,
19346,
8,
785,
304,
272,
408,
1563,
5241,
402,
511,
9403,
367,
10036,
12591,
14,
339,
6184,
27500,
5516,
1077,
506,
4021,
461,
402,
9476,
1006,
402,
3520,
2295,
14,
272,
4005,
4838,
314,
2295,
370,
2195,
5705,
27500,
4514,
12,
9329,
675,
27500,
1746,
272,
465,
282,
20048,
367,
2195,
5705,
2882,
14,
1746,
5516,
436,
1172,
314,
3613,
272,
1083,
663,
291,
14,
2319,
370,
376,
1256,
402,
2195,
27500,
4514,
14,
2286,
25377,
14,
710,
3814,
2253,
3769,
12470,
1471,
1172,
282,
14893,
402,
737,
5210,
650,
4567,
14,
339,
961,
1021,
365,
19829,
465,
282,
20048,
880,
626,
652,
1159,
440,
10501,
701,
511,
272,
8697,
7249,
4066,
465,
11354,
14,
272,
408,
339,
347,
1104,
8,
277,
12,
299,
304,
267,
408,
1799,
626,
282,
570,
3495,
4453,
291,
14,
2319,
624,
267,
372,
291,
14,
2319,
14,
2444,
8,
80,
9,
339,
347,
511,
63,
2024,
8,
277,
304,
267,
408,
11834,
664,
2024,
1182,
965,
2024,
787,
805,
316,
624,
267,
327,
664,
2024,
1182,
965,
2024,
787,
7508,
370,
511,
12,
3967,
2337,
365,
949,
4340,
370,
4107,
267,
327,
314,
12591,
1177,
267,
3404,
63,
1247,
275,
2097,
739,
63,
2118,
401,
1993,
298,
1200,
401,
1993,
298,
2975,
63,
3771,
937,
267,
410,
31596,
63,
2024,
275,
283,
3749,
10207,
305,
3772,
889,
3858,
631,
9539,
82,
4,
22074,
62,
12574,
10,
342,
63,
4786,
267,
291,
14,
1855,
8,
1944,
3396,
547,
12,
291,
14,
2319,
14,
362,
2024,
12,
410,
31596,
63,
2024,
9,
267,
291,
14,
3334,
8,
277,
14,
2319,
14,
1989,
2024,
8,
270,
31596,
63,
2024,
430,
267,
291,
14,
2947,
8,
403,
12,
291,
14,
2319,
14,
362,
2024,
8,
270,
31596,
63,
2024,
12,
488,
430,
267,
291,
14,
2947,
8,
19,
14,
1079,
12,
291,
14,
2319,
14,
362,
2024,
8,
270,
31596,
63,
2024,
12,
650,
14,
1079,
430,
267,
367,
3404,
63,
354,
315,
3404,
63,
1247,
26,
288,
862,
26,
355,
3404,
275,
291,
14,
2319,
14,
362,
2024,
8,
2024,
63,
354,
9,
355,
291,
14,
1815,
8,
277,
14,
2319,
14,
1989,
2024,
8,
2024,
63,
354,
430,
288,
871,
3091,
3396,
547,
26,
355,
291,
14,
3334,
8,
277,
14,
2319,
14,
1989,
2024,
8,
2024,
63,
354,
430,
268,
339,
347,
511,
63,
1231,
63,
694,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
2319,
14,
6027,
31348,
267,
291,
14,
1815,
8,
277,
14,
2319,
14,
6027,
4769,
2237,
267,
327,
5723,
1443,
506,
3055,
334,
69,
14,
71,
14,
2701,
1211,
9,
1325,
1471,
78,
1133,
746,
2552,
267,
291,
14,
2319,
14,
32286,
10804,
267,
291,
14,
1815,
8,
277,
14,
2319,
14,
32286,
19031,
365,
440,
488,
9,
339,
347,
511,
63,
362,
1274,
515,
8,
277,
304,
267,
862,
26,
288,
984,
515,
275,
291,
14,
2319,
14,
362,
1274,
515,
19031,
267,
871,
3091,
11319,
2042,
547,
26,
288,
986,
267,
587,
26,
288,
291,
14,
1815,
8,
6074,
8,
1274,
515,
12,
2975,
430,
267,
984,
515,
275,
291,
14,
2319,
14,
362,
1274,
515,
27374,
3306,
63,
3592,
29,
549,
9,
267,
340,
984,
515,
365,
440,
488,
26,
288,
291,
14,
1815,
8,
6074,
8,
1274,
515,
12,
2975,
430,
339,
347,
511,
63,
1757,
8,
277,
304,
267,
620,
8,
277,
14,
2319,
9,
267,
4700,
8,
277,
14,
2319,
9,
267,
291,
14,
479,
2531,
11161,
8,
277,
14,
2319,
12,
283,
3257,
1333,
339,
347,
511,
63,
1490,
63,
265,
63,
3619,
8,
277,
304,
267,
291,
14,
2319,
14,
1875,
694,
480,
16634,
531,
267,
862,
26,
288,
289,
275,
291,
14,
2319,
14,
1490,
480,
16634,
531,
267,
871,
7337,
3364,
547,
26,
288,
986,
267,
871,
2186,
26,
288,
746,
288,
325,
1886,
275,
984,
14,
2804,
63,
815,
3430,
16,
61,
288,
702,
756,
12,
2071,
83,
4915,
3140,
402,
7337,
3364,
547,
2,
450,
334,
69,
1886,
4258,
267,
587,
26,
288,
289,
14,
1600,
342,
288,
702,
756,
12,
298,
4031,
3364,
547,
1990,
440,
4915,
2,
2126,
272,
347,
511,
63,
952,
493,
8,
277,
304,
267,
291,
14,
1855,
8,
4031,
10870,
12,
277,
14,
2319,
14,
1490,
4589,
396,
17,
14,
2424,
531,
267,
289,
275,
291,
14,
2319,
14,
1490,
480,
396,
17,
14,
2424,
2266,
6603,
531,
267,
289,
14,
952,
8,
66,
480,
4776,
2237,
267,
289,
14,
1600,
342,
267,
291,
14,
1815,
8,
277,
14,
1074,
480,
396,
17,
14,
2424,
2237,
267,
289,
275,
291,
14,
2319,
14,
1490,
480,
396,
17,
14,
2424,
2266,
4848,
531,
267,
291,
14,
2947,
8,
70,
14,
739,
1062,
66,
480,
4776,
2237,
267,
289,
14,
1600,
342,
267,
289,
275,
291,
14,
2319,
14,
1490,
480,
396,
17,
14,
2424,
2266,
6603,
531,
267,
289,
14,
952,
8,
66,
480,
396,
570,
8970,
2237,
267,
289,
14,
1600,
342,
267,
291,
14,
1815,
8,
277,
14,
1074,
480,
396,
17,
14,
2424,
2237,
267,
289,
275,
291,
14,
2319,
14,
1490,
480,
396,
17,
14,
2424,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mancoast/CPythonPyc_test
|
fail/332_test_getargs2.py
|
28
|
21610
|
import unittest
from test import support
from _testcapi import getargs_keywords, getargs_keyword_only
"""
> How about the following counterproposal. This also changes some of
> the other format codes to be a little more regular.
>
> Code C type Range check
>
> b unsigned char 0..UCHAR_MAX
> h signed short SHRT_MIN..SHRT_MAX
> B unsigned char none **
> H unsigned short none **
> k * unsigned long none
> I * unsigned int 0..UINT_MAX
> i int INT_MIN..INT_MAX
> l long LONG_MIN..LONG_MAX
> K * unsigned long long none
> L long long LLONG_MIN..LLONG_MAX
> Notes:
>
> * New format codes.
>
> ** Changed from previous "range-and-a-half" to "none"; the
> range-and-a-half checking wasn't particularly useful.
Plus a C API or two, e.g. PyInt_AsLongMask() ->
unsigned long and PyInt_AsLongLongMask() -> unsigned
long long (if that exists).
"""
LARGE = 0x7FFFFFFF
VERY_LARGE = 0xFF0000121212121212121242
from _testcapi import UCHAR_MAX, USHRT_MAX, UINT_MAX, ULONG_MAX, INT_MAX, \
INT_MIN, LONG_MIN, LONG_MAX, PY_SSIZE_T_MIN, PY_SSIZE_T_MAX, \
SHRT_MIN, SHRT_MAX
# fake, they are not defined in Python's header files
LLONG_MAX = 2**63-1
LLONG_MIN = -2**63
ULLONG_MAX = 2**64-1
class Int:
def __int__(self):
return 99
class Unsigned_TestCase(unittest.TestCase):
def test_b(self):
from _testcapi import getargs_b
# b returns 'unsigned char', and does range checking (0 ... UCHAR_MAX)
self.assertRaises(TypeError, getargs_b, 3.14)
self.assertEqual(99, getargs_b(Int()))
self.assertRaises(OverflowError, getargs_b, -1)
self.assertEqual(0, getargs_b(0))
self.assertEqual(UCHAR_MAX, getargs_b(UCHAR_MAX))
self.assertRaises(OverflowError, getargs_b, UCHAR_MAX + 1)
self.assertEqual(42, getargs_b(42))
self.assertRaises(OverflowError, getargs_b, VERY_LARGE)
def test_B(self):
from _testcapi import getargs_B
# B returns 'unsigned char', no range checking
self.assertRaises(TypeError, getargs_B, 3.14)
self.assertEqual(99, getargs_B(Int()))
self.assertEqual(UCHAR_MAX, getargs_B(-1))
self.assertEqual(0, getargs_B(0))
self.assertEqual(UCHAR_MAX, getargs_B(UCHAR_MAX))
self.assertEqual(0, getargs_B(UCHAR_MAX+1))
self.assertEqual(42, getargs_B(42))
self.assertEqual(UCHAR_MAX & VERY_LARGE, getargs_B(VERY_LARGE))
def test_H(self):
from _testcapi import getargs_H
# H returns 'unsigned short', no range checking
self.assertRaises(TypeError, getargs_H, 3.14)
self.assertEqual(99, getargs_H(Int()))
self.assertEqual(USHRT_MAX, getargs_H(-1))
self.assertEqual(0, getargs_H(0))
self.assertEqual(USHRT_MAX, getargs_H(USHRT_MAX))
self.assertEqual(0, getargs_H(USHRT_MAX+1))
self.assertEqual(42, getargs_H(42))
self.assertEqual(VERY_LARGE & USHRT_MAX, getargs_H(VERY_LARGE))
def test_I(self):
from _testcapi import getargs_I
# I returns 'unsigned int', no range checking
self.assertRaises(TypeError, getargs_I, 3.14)
self.assertEqual(99, getargs_I(Int()))
self.assertEqual(UINT_MAX, getargs_I(-1))
self.assertEqual(0, getargs_I(0))
self.assertEqual(UINT_MAX, getargs_I(UINT_MAX))
self.assertEqual(0, getargs_I(UINT_MAX+1))
self.assertEqual(42, getargs_I(42))
self.assertEqual(VERY_LARGE & UINT_MAX, getargs_I(VERY_LARGE))
def test_k(self):
from _testcapi import getargs_k
# k returns 'unsigned long', no range checking
# it does not accept float, or instances with __int__
self.assertRaises(TypeError, getargs_k, 3.14)
self.assertRaises(TypeError, getargs_k, Int())
self.assertEqual(ULONG_MAX, getargs_k(-1))
self.assertEqual(0, getargs_k(0))
self.assertEqual(ULONG_MAX, getargs_k(ULONG_MAX))
self.assertEqual(0, getargs_k(ULONG_MAX+1))
self.assertEqual(42, getargs_k(42))
self.assertEqual(VERY_LARGE & ULONG_MAX, getargs_k(VERY_LARGE))
class Signed_TestCase(unittest.TestCase):
def test_h(self):
from _testcapi import getargs_h
# h returns 'short', and does range checking (SHRT_MIN ... SHRT_MAX)
self.assertRaises(TypeError, getargs_h, 3.14)
self.assertEqual(99, getargs_h(Int()))
self.assertRaises(OverflowError, getargs_h, SHRT_MIN-1)
self.assertEqual(SHRT_MIN, getargs_h(SHRT_MIN))
self.assertEqual(SHRT_MAX, getargs_h(SHRT_MAX))
self.assertRaises(OverflowError, getargs_h, SHRT_MAX+1)
self.assertEqual(42, getargs_h(42))
self.assertRaises(OverflowError, getargs_h, VERY_LARGE)
def test_i(self):
from _testcapi import getargs_i
# i returns 'int', and does range checking (INT_MIN ... INT_MAX)
self.assertRaises(TypeError, getargs_i, 3.14)
self.assertEqual(99, getargs_i(Int()))
self.assertRaises(OverflowError, getargs_i, INT_MIN-1)
self.assertEqual(INT_MIN, getargs_i(INT_MIN))
self.assertEqual(INT_MAX, getargs_i(INT_MAX))
self.assertRaises(OverflowError, getargs_i, INT_MAX+1)
self.assertEqual(42, getargs_i(42))
self.assertRaises(OverflowError, getargs_i, VERY_LARGE)
def test_l(self):
from _testcapi import getargs_l
# l returns 'long', and does range checking (LONG_MIN ... LONG_MAX)
self.assertRaises(TypeError, getargs_l, 3.14)
self.assertEqual(99, getargs_l(Int()))
self.assertRaises(OverflowError, getargs_l, LONG_MIN-1)
self.assertEqual(LONG_MIN, getargs_l(LONG_MIN))
self.assertEqual(LONG_MAX, getargs_l(LONG_MAX))
self.assertRaises(OverflowError, getargs_l, LONG_MAX+1)
self.assertEqual(42, getargs_l(42))
self.assertRaises(OverflowError, getargs_l, VERY_LARGE)
def test_n(self):
from _testcapi import getargs_n
# n returns 'Py_ssize_t', and does range checking
# (PY_SSIZE_T_MIN ... PY_SSIZE_T_MAX)
self.assertRaises(TypeError, getargs_n, 3.14)
self.assertRaises(TypeError, getargs_n, Int())
self.assertRaises(OverflowError, getargs_n, PY_SSIZE_T_MIN-1)
self.assertEqual(PY_SSIZE_T_MIN, getargs_n(PY_SSIZE_T_MIN))
self.assertEqual(PY_SSIZE_T_MAX, getargs_n(PY_SSIZE_T_MAX))
self.assertRaises(OverflowError, getargs_n, PY_SSIZE_T_MAX+1)
self.assertEqual(42, getargs_n(42))
self.assertRaises(OverflowError, getargs_n, VERY_LARGE)
class LongLong_TestCase(unittest.TestCase):
def test_L(self):
from _testcapi import getargs_L
# L returns 'long long', and does range checking (LLONG_MIN
# ... LLONG_MAX)
self.assertRaises(TypeError, getargs_L, 3.14)
self.assertRaises(TypeError, getargs_L, "Hello")
self.assertEqual(99, getargs_L(Int()))
self.assertRaises(OverflowError, getargs_L, LLONG_MIN-1)
self.assertEqual(LLONG_MIN, getargs_L(LLONG_MIN))
self.assertEqual(LLONG_MAX, getargs_L(LLONG_MAX))
self.assertRaises(OverflowError, getargs_L, LLONG_MAX+1)
self.assertEqual(42, getargs_L(42))
self.assertRaises(OverflowError, getargs_L, VERY_LARGE)
def test_K(self):
from _testcapi import getargs_K
# K return 'unsigned long long', no range checking
self.assertRaises(TypeError, getargs_K, 3.14)
self.assertRaises(TypeError, getargs_K, Int())
self.assertEqual(ULLONG_MAX, getargs_K(ULLONG_MAX))
self.assertEqual(0, getargs_K(0))
self.assertEqual(0, getargs_K(ULLONG_MAX+1))
self.assertEqual(42, getargs_K(42))
self.assertEqual(VERY_LARGE & ULLONG_MAX, getargs_K(VERY_LARGE))
class Paradox:
"This statement is false."
def __bool__(self):
raise NotImplementedError
class Boolean_TestCase(unittest.TestCase):
def test_p(self):
from _testcapi import getargs_p
self.assertEqual(0, getargs_p(False))
self.assertEqual(0, getargs_p(None))
self.assertEqual(0, getargs_p(0))
self.assertEqual(0, getargs_p(0.0))
self.assertEqual(0, getargs_p(0j))
self.assertEqual(0, getargs_p(''))
self.assertEqual(0, getargs_p(()))
self.assertEqual(0, getargs_p([]))
self.assertEqual(0, getargs_p({}))
self.assertEqual(1, getargs_p(True))
self.assertEqual(1, getargs_p(1))
self.assertEqual(1, getargs_p(1.0))
self.assertEqual(1, getargs_p(1j))
self.assertEqual(1, getargs_p('x'))
self.assertEqual(1, getargs_p((1,)))
self.assertEqual(1, getargs_p([1]))
self.assertEqual(1, getargs_p({1:2}))
self.assertEqual(1, getargs_p(unittest.TestCase))
self.assertRaises(NotImplementedError, getargs_p, Paradox())
class Tuple_TestCase(unittest.TestCase):
def test_tuple(self):
from _testcapi import getargs_tuple
ret = getargs_tuple(1, (2, 3))
self.assertEqual(ret, (1,2,3))
# make sure invalid tuple arguments are handled correctly
class seq:
def __len__(self):
return 2
def __getitem__(self, n):
raise ValueError
self.assertRaises(TypeError, getargs_tuple, 1, seq())
class Keywords_TestCase(unittest.TestCase):
def test_positional_args(self):
# using all positional args
self.assertEqual(
getargs_keywords((1,2), 3, (4,(5,6)), (7,8,9), 10),
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
)
def test_mixed_args(self):
# positional and keyword args
self.assertEqual(
getargs_keywords((1,2), 3, (4,(5,6)), arg4=(7,8,9), arg5=10),
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
)
def test_keyword_args(self):
# all keywords
self.assertEqual(
getargs_keywords(arg1=(1,2), arg2=3, arg3=(4,(5,6)), arg4=(7,8,9), arg5=10),
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
)
def test_optional_args(self):
# missing optional keyword args, skipping tuples
self.assertEqual(
getargs_keywords(arg1=(1,2), arg2=3, arg5=10),
(1, 2, 3, -1, -1, -1, -1, -1, -1, 10)
)
def test_required_args(self):
# required arg missing
try:
getargs_keywords(arg1=(1,2))
except TypeError as err:
self.assertEqual(str(err), "Required argument 'arg2' (pos 2) not found")
else:
self.fail('TypeError should have been raised')
def test_too_many_args(self):
try:
getargs_keywords((1,2),3,(4,(5,6)),(7,8,9),10,111)
except TypeError as err:
self.assertEqual(str(err), "function takes at most 5 arguments (6 given)")
else:
self.fail('TypeError should have been raised')
def test_invalid_keyword(self):
# extraneous keyword arg
try:
getargs_keywords((1,2),3,arg5=10,arg666=666)
except TypeError as err:
self.assertEqual(str(err), "'arg666' is an invalid keyword argument for this function")
else:
self.fail('TypeError should have been raised')
def test_surrogate_keyword(self):
try:
getargs_keywords((1,2), 3, (4,(5,6)), (7,8,9), **{'\uDC80': 10})
except TypeError as err:
self.assertEqual(str(err), "'\udc80' is an invalid keyword argument for this function")
else:
self.fail('TypeError should have been raised')
class KeywordOnly_TestCase(unittest.TestCase):
def test_positional_args(self):
# using all possible positional args
self.assertEqual(
getargs_keyword_only(1, 2),
(1, 2, -1)
)
def test_mixed_args(self):
# positional and keyword args
self.assertEqual(
getargs_keyword_only(1, 2, keyword_only=3),
(1, 2, 3)
)
def test_keyword_args(self):
# all keywords
self.assertEqual(
getargs_keyword_only(required=1, optional=2, keyword_only=3),
(1, 2, 3)
)
def test_optional_args(self):
# missing optional keyword args, skipping tuples
self.assertEqual(
getargs_keyword_only(required=1, optional=2),
(1, 2, -1)
)
self.assertEqual(
getargs_keyword_only(required=1, keyword_only=3),
(1, -1, 3)
)
def test_required_args(self):
self.assertEqual(
getargs_keyword_only(1),
(1, -1, -1)
)
self.assertEqual(
getargs_keyword_only(required=1),
(1, -1, -1)
)
# required arg missing
with self.assertRaisesRegex(TypeError,
"Required argument 'required' \(pos 1\) not found"):
getargs_keyword_only(optional=2)
with self.assertRaisesRegex(TypeError,
"Required argument 'required' \(pos 1\) not found"):
getargs_keyword_only(keyword_only=3)
def test_too_many_args(self):
with self.assertRaisesRegex(TypeError,
"Function takes at most 2 positional arguments \(3 given\)"):
getargs_keyword_only(1, 2, 3)
with self.assertRaisesRegex(TypeError,
"function takes at most 3 arguments \(4 given\)"):
getargs_keyword_only(1, 2, 3, keyword_only=5)
def test_invalid_keyword(self):
# extraneous keyword arg
with self.assertRaisesRegex(TypeError,
"'monster' is an invalid keyword argument for this function"):
getargs_keyword_only(1, 2, monster=666)
def test_surrogate_keyword(self):
with self.assertRaisesRegex(TypeError,
"'\udc80' is an invalid keyword argument for this function"):
getargs_keyword_only(1, 2, **{'\uDC80': 10})
class Bytes_TestCase(unittest.TestCase):
def test_c(self):
from _testcapi import getargs_c
self.assertRaises(TypeError, getargs_c, b'abc') # len > 1
self.assertEqual(getargs_c(b'a'), b'a')
self.assertEqual(getargs_c(bytearray(b'a')), b'a')
self.assertRaises(TypeError, getargs_c, memoryview(b'a'))
self.assertRaises(TypeError, getargs_c, 's')
self.assertRaises(TypeError, getargs_c, None)
def test_s(self):
from _testcapi import getargs_s
self.assertEqual(getargs_s('abc\xe9'), b'abc\xc3\xa9')
self.assertRaises(TypeError, getargs_s, 'nul:\0')
self.assertRaises(TypeError, getargs_s, b'bytes')
self.assertRaises(TypeError, getargs_s, bytearray(b'bytearray'))
self.assertRaises(TypeError, getargs_s, memoryview(b'memoryview'))
self.assertRaises(TypeError, getargs_s, None)
def test_s_star(self):
from _testcapi import getargs_s_star
self.assertEqual(getargs_s_star('abc\xe9'), b'abc\xc3\xa9')
self.assertEqual(getargs_s_star('nul:\0'), b'nul:\0')
self.assertEqual(getargs_s_star(b'bytes'), b'bytes')
self.assertEqual(getargs_s_star(bytearray(b'bytearray')), b'bytearray')
self.assertEqual(getargs_s_star(memoryview(b'memoryview')), b'memoryview')
self.assertRaises(TypeError, getargs_s_star, None)
def test_s_hash(self):
from _testcapi import getargs_s_hash
self.assertEqual(getargs_s_hash('abc\xe9'), b'abc\xc3\xa9')
self.assertEqual(getargs_s_hash('nul:\0'), b'nul:\0')
self.assertEqual(getargs_s_hash(b'bytes'), b'bytes')
self.assertRaises(TypeError, getargs_s_hash, bytearray(b'bytearray'))
self.assertRaises(TypeError, getargs_s_hash, memoryview(b'memoryview'))
self.assertRaises(TypeError, getargs_s_hash, None)
def test_z(self):
from _testcapi import getargs_z
self.assertEqual(getargs_z('abc\xe9'), b'abc\xc3\xa9')
self.assertRaises(TypeError, getargs_z, 'nul:\0')
self.assertRaises(TypeError, getargs_z, b'bytes')
self.assertRaises(TypeError, getargs_z, bytearray(b'bytearray'))
self.assertRaises(TypeError, getargs_z, memoryview(b'memoryview'))
self.assertIsNone(getargs_z(None))
def test_z_star(self):
from _testcapi import getargs_z_star
self.assertEqual(getargs_z_star('abc\xe9'), b'abc\xc3\xa9')
self.assertEqual(getargs_z_star('nul:\0'), b'nul:\0')
self.assertEqual(getargs_z_star(b'bytes'), b'bytes')
self.assertEqual(getargs_z_star(bytearray(b'bytearray')), b'bytearray')
self.assertEqual(getargs_z_star(memoryview(b'memoryview')), b'memoryview')
self.assertIsNone(getargs_z_star(None))
def test_z_hash(self):
from _testcapi import getargs_z_hash
self.assertEqual(getargs_z_hash('abc\xe9'), b'abc\xc3\xa9')
self.assertEqual(getargs_z_hash('nul:\0'), b'nul:\0')
self.assertEqual(getargs_z_hash(b'bytes'), b'bytes')
self.assertRaises(TypeError, getargs_z_hash, bytearray(b'bytearray'))
self.assertRaises(TypeError, getargs_z_hash, memoryview(b'memoryview'))
self.assertIsNone(getargs_z_hash(None))
def test_y(self):
from _testcapi import getargs_y
self.assertRaises(TypeError, getargs_y, 'abc\xe9')
self.assertEqual(getargs_y(b'bytes'), b'bytes')
self.assertRaises(TypeError, getargs_y, b'nul:\0')
self.assertRaises(TypeError, getargs_y, bytearray(b'bytearray'))
self.assertRaises(TypeError, getargs_y, memoryview(b'memoryview'))
self.assertRaises(TypeError, getargs_y, None)
def test_y_star(self):
from _testcapi import getargs_y_star
self.assertRaises(TypeError, getargs_y_star, 'abc\xe9')
self.assertEqual(getargs_y_star(b'bytes'), b'bytes')
self.assertEqual(getargs_y_star(b'nul:\0'), b'nul:\0')
self.assertEqual(getargs_y_star(bytearray(b'bytearray')), b'bytearray')
self.assertEqual(getargs_y_star(memoryview(b'memoryview')), b'memoryview')
self.assertRaises(TypeError, getargs_y_star, None)
def test_y_hash(self):
from _testcapi import getargs_y_hash
self.assertRaises(TypeError, getargs_y_hash, 'abc\xe9')
self.assertEqual(getargs_y_hash(b'bytes'), b'bytes')
self.assertEqual(getargs_y_hash(b'nul:\0'), b'nul:\0')
self.assertRaises(TypeError, getargs_y_hash, bytearray(b'bytearray'))
self.assertRaises(TypeError, getargs_y_hash, memoryview(b'memoryview'))
self.assertRaises(TypeError, getargs_y_hash, None)
def test_w_star(self):
# getargs_w_star() modifies first and last byte
from _testcapi import getargs_w_star
self.assertRaises(TypeError, getargs_w_star, 'abc\xe9')
self.assertRaises(TypeError, getargs_w_star, b'bytes')
self.assertRaises(TypeError, getargs_w_star, b'nul:\0')
self.assertRaises(TypeError, getargs_w_star, memoryview(b'bytes'))
self.assertEqual(getargs_w_star(bytearray(b'bytearray')), b'[ytearra]')
self.assertEqual(getargs_w_star(memoryview(bytearray(b'memoryview'))),
b'[emoryvie]')
self.assertRaises(TypeError, getargs_w_star, None)
class Unicode_TestCase(unittest.TestCase):
def test_u(self):
from _testcapi import getargs_u
self.assertEqual(getargs_u('abc\xe9'), 'abc\xe9')
self.assertRaises(TypeError, getargs_u, 'nul:\0')
self.assertRaises(TypeError, getargs_u, b'bytes')
self.assertRaises(TypeError, getargs_u, bytearray(b'bytearray'))
self.assertRaises(TypeError, getargs_u, memoryview(b'memoryview'))
self.assertRaises(TypeError, getargs_u, None)
def test_u_hash(self):
from _testcapi import getargs_u_hash
self.assertEqual(getargs_u_hash('abc\xe9'), 'abc\xe9')
self.assertEqual(getargs_u_hash('nul:\0'), 'nul:\0')
self.assertRaises(TypeError, getargs_u_hash, b'bytes')
self.assertRaises(TypeError, getargs_u_hash, bytearray(b'bytearray'))
self.assertRaises(TypeError, getargs_u_hash, memoryview(b'memoryview'))
self.assertRaises(TypeError, getargs_u_hash, None)
def test_Z(self):
from _testcapi import getargs_Z
self.assertEqual(getargs_Z('abc\xe9'), 'abc\xe9')
self.assertRaises(TypeError, getargs_Z, 'nul:\0')
self.assertRaises(TypeError, getargs_Z, b'bytes')
self.assertRaises(TypeError, getargs_Z, bytearray(b'bytearray'))
self.assertRaises(TypeError, getargs_Z, memoryview(b'memoryview'))
self.assertIsNone(getargs_Z(None))
def test_Z_hash(self):
from _testcapi import getargs_Z_hash
self.assertEqual(getargs_Z_hash('abc\xe9'), 'abc\xe9')
self.assertEqual(getargs_Z_hash('nul:\0'), 'nul:\0')
self.assertRaises(TypeError, getargs_Z_hash, b'bytes')
self.assertRaises(TypeError, getargs_Z_hash, bytearray(b'bytearray'))
self.assertRaises(TypeError, getargs_Z_hash, memoryview(b'memoryview'))
self.assertIsNone(getargs_Z_hash(None))
def test_main():
tests = [
Signed_TestCase,
Unsigned_TestCase,
Boolean_TestCase,
Tuple_TestCase,
Keywords_TestCase,
KeywordOnly_TestCase,
Bytes_TestCase,
Unicode_TestCase,
]
try:
from _testcapi import getargs_L, getargs_K
except ImportError:
pass # PY_LONG_LONG not available
else:
tests.append(LongLong_TestCase)
support.run_unittest(*tests)
if __name__ == "__main__":
test_main()
|
gpl-3.0
|
[
646,
2882,
199,
504,
511,
492,
2291,
199,
504,
485,
396,
14145,
492,
31677,
63,
7511,
12,
31677,
63,
6691,
63,
2118,
199,
199,
624,
199,
30,
7494,
3595,
314,
2569,
7055,
25700,
14,
961,
2597,
4493,
2005,
402,
199,
30,
314,
1163,
1475,
9479,
370,
506,
282,
12050,
1655,
5578,
14,
199,
30,
199,
30,
5495,
445,
730,
13114,
1104,
199,
30,
199,
30,
330,
7381,
1495,
378,
703,
53,
5901,
63,
4283,
199,
30,
394,
10514,
3974,
4410,
11876,
63,
4896,
703,
3234,
11876,
63,
4283,
199,
30,
699,
7381,
1495,
7179,
1011,
199,
30,
869,
7381,
3974,
7179,
1011,
199,
30,
1022,
627,
7381,
1846,
7179,
199,
30,
473,
627,
7381,
1109,
378,
703,
17459,
63,
4283,
421,
199,
30,
284,
1109,
16429,
63,
4896,
703,
2919,
63,
4283,
199,
30,
634,
1846,
26594,
63,
4896,
703,
12375,
63,
4283,
199,
199,
30,
1804,
627,
7381,
1846,
1846,
7179,
199,
30,
491,
1846,
1846,
491,
12375,
63,
4896,
703,
4464,
7770,
63,
4283,
199,
199,
30,
8144,
26,
199,
30,
199,
30,
627,
7053,
1475,
9479,
14,
199,
30,
199,
30,
1011,
25649,
687,
4136,
298,
1842,
13,
460,
13,
65,
13,
10220,
2,
370,
298,
3592,
11436,
314,
199,
30,
1425,
13,
460,
13,
65,
13,
10220,
7907,
17373,
1133,
6770,
590,
2997,
14,
199,
199,
25800,
282,
445,
3261,
503,
2877,
12,
325,
14,
71,
14,
1611,
3241,
63,
2822,
9551,
5144,
342,
1035,
199,
2244,
1846,
436,
1611,
3241,
63,
2822,
9551,
9551,
5144,
342,
1035,
7381,
199,
2809,
1846,
334,
692,
626,
3495,
680,
199,
624,
199,
199,
15806,
275,
378,
88,
23,
6968,
24254,
199,
2111,
57,
63,
15806,
275,
378,
9039,
993,
25481,
25481,
25481,
25481,
2260,
199,
199,
504,
485,
396,
14145,
492,
738,
5901,
63,
4283,
12,
738,
3234,
11876,
63,
4283,
12,
30151,
63,
4283,
12,
738,
12375,
63,
4283,
12,
16429,
63,
4283,
12,
971,
1362,
16429,
63,
4896,
12,
26594,
63,
4896,
12,
26594,
63,
4283,
12,
7843,
63,
2300,
11025,
63,
52,
63,
4896,
12,
7843,
63,
2300,
11025,
63,
52,
63,
4283,
12,
971,
1362,
4410,
11876,
63,
4896,
12,
4410,
11876,
63,
4283,
199,
199,
3,
4026,
12,
2985,
787,
440,
3247,
315,
2018,
1159,
1406,
1584,
199,
4464,
7770,
63,
4283,
275,
499,
538,
2766,
13,
17,
199,
4464,
7770,
63,
4896,
275,
446,
18,
538,
2766,
199,
3785,
7770,
63,
4283,
275,
499,
538,
772,
13,
17,
199,
199,
533,
9805,
26,
272,
347,
636,
442,
721,
277,
304,
267,
372,
8806,
199,
199,
533,
1910,
1737,
63,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
66,
8,
277,
304,
267,
687,
485,
396,
14145,
492,
31677,
63,
66,
267,
327,
330,
2529,
283,
2244,
1495,
297,
436,
1630,
1425,
7907,
334,
16,
2263,
738,
5901,
63,
4283,
9,
267,
291,
14,
1855,
8,
4333,
12,
31677,
63,
66,
12,
650,
14,
1079,
9,
267,
291,
14,
629,
8,
1020,
12,
31677,
63,
66,
8,
3241,
4059,
398,
291,
14,
1855,
8,
21821,
12,
31677,
63,
66,
12,
446,
17,
9,
267,
291,
14,
629,
8,
16,
12,
31677,
63,
66,
8,
16,
430,
267,
291,
14,
629,
8,
53,
5901,
63,
4283,
12,
31677,
63,
66,
8,
53,
5901,
63,
4283,
430,
267,
291,
14,
1855,
8,
21821,
12,
31677,
63,
66,
12,
738,
5901,
63,
4283,
435,
413,
9,
398,
291,
14,
629,
8,
2260,
12,
31677,
63,
66,
8,
2260,
430,
267,
291,
14,
1855,
8,
21821,
12,
31677,
63,
66,
12,
812,
9418,
63,
15806,
9,
339,
347,
511,
63,
34,
8,
277,
304,
267,
687,
485,
396,
14145,
492,
31677,
63,
34,
267,
327,
699,
2529,
283,
2244,
1495,
297,
949,
1425,
7907,
267,
291,
14,
1855,
8,
4333,
12,
31677,
63,
34,
12,
650,
14,
1079,
9,
267,
291,
14,
629,
8,
1020,
12,
31677,
63,
34,
8,
3241,
4059,
398,
291,
14,
629,
8,
53,
5901,
63,
4283,
12,
31677,
63,
34,
2801,
17,
430,
267,
291,
14,
629,
8,
16,
12,
31677,
63,
34,
8,
16,
430,
267,
291,
14,
629,
8,
53,
5901,
63,
4283,
12,
31677,
63,
34,
8,
53,
5901,
63,
4283,
430,
267,
291,
14,
629,
8,
16,
12,
31677,
63,
34,
8,
53,
5901,
63,
4283,
11,
17,
430,
398,
291,
14,
629,
8,
2260,
12,
31677,
63,
34,
8,
2260,
430,
267,
291,
14,
629,
8,
53,
5901,
63,
4283,
1253,
812,
9418,
63,
15806,
12,
31677,
63,
34,
8,
2111,
57,
63,
15806,
430,
339,
347,
511,
63,
40,
8,
277,
304,
267,
687,
485,
396,
14145,
492,
31677,
63,
40,
267,
327,
869,
2529,
283,
2244,
3974,
297,
949,
1425,
7907,
267,
291,
14,
1855,
8,
4333,
12,
31677,
63,
40,
12,
650,
14,
1079,
9,
267,
291,
14,
629,
8,
1020,
12,
31677,
63,
40,
8,
3241,
4059,
398,
291,
14,
629,
8,
14527,
11876,
63,
4283,
12,
31677,
63,
40,
2801,
17,
430,
267,
291,
14,
629,
8,
16,
12,
31677,
63,
40,
8,
16,
430,
267,
291,
14,
629,
8,
14527,
11876,
63,
4283,
12,
31677,
63,
40,
8,
14527,
11876,
63,
4283,
430,
267,
291,
14,
629,
8,
16,
12,
31677,
63,
40,
8,
14527,
11876,
63,
4283,
11,
17,
430,
398,
291,
14,
629,
8,
2260,
12,
31677,
63,
40,
8,
2260,
430,
398,
291,
14,
629,
8,
2111,
57,
63,
15806,
1253,
738,
3234,
11876,
63,
4283,
12,
31677,
63,
40,
8,
2111,
57,
63,
15806,
430,
339,
347,
511,
63,
41,
8,
277,
304,
267,
687,
485,
396,
14145,
492,
31677,
63,
41,
267,
327,
473,
2529,
283,
2244,
1109,
297,
949,
1425,
7907,
267,
291,
14,
1855,
8,
4333,
12,
31677,
63,
41,
12,
650,
14,
1079,
9,
267,
291,
14,
629,
8,
1020,
12,
31677,
63,
41,
8,
3241,
4059,
398,
291,
14,
629,
8,
17459,
63,
4283,
12,
31677,
63,
41,
2801,
17,
430,
267,
291,
14,
629,
8,
16,
12,
31677,
63,
41,
8,
16,
430,
267,
291,
14,
629,
8,
17459,
63,
4283,
12,
31677,
63,
41,
8,
17459,
63,
4283,
430,
267,
291,
14,
629,
8,
16,
12,
31677,
63,
41,
8,
17459,
63
] |
[
2882,
199,
504,
511,
492,
2291,
199,
504,
485,
396,
14145,
492,
31677,
63,
7511,
12,
31677,
63,
6691,
63,
2118,
199,
199,
624,
199,
30,
7494,
3595,
314,
2569,
7055,
25700,
14,
961,
2597,
4493,
2005,
402,
199,
30,
314,
1163,
1475,
9479,
370,
506,
282,
12050,
1655,
5578,
14,
199,
30,
199,
30,
5495,
445,
730,
13114,
1104,
199,
30,
199,
30,
330,
7381,
1495,
378,
703,
53,
5901,
63,
4283,
199,
30,
394,
10514,
3974,
4410,
11876,
63,
4896,
703,
3234,
11876,
63,
4283,
199,
30,
699,
7381,
1495,
7179,
1011,
199,
30,
869,
7381,
3974,
7179,
1011,
199,
30,
1022,
627,
7381,
1846,
7179,
199,
30,
473,
627,
7381,
1109,
378,
703,
17459,
63,
4283,
421,
199,
30,
284,
1109,
16429,
63,
4896,
703,
2919,
63,
4283,
199,
30,
634,
1846,
26594,
63,
4896,
703,
12375,
63,
4283,
199,
199,
30,
1804,
627,
7381,
1846,
1846,
7179,
199,
30,
491,
1846,
1846,
491,
12375,
63,
4896,
703,
4464,
7770,
63,
4283,
199,
199,
30,
8144,
26,
199,
30,
199,
30,
627,
7053,
1475,
9479,
14,
199,
30,
199,
30,
1011,
25649,
687,
4136,
298,
1842,
13,
460,
13,
65,
13,
10220,
2,
370,
298,
3592,
11436,
314,
199,
30,
1425,
13,
460,
13,
65,
13,
10220,
7907,
17373,
1133,
6770,
590,
2997,
14,
199,
199,
25800,
282,
445,
3261,
503,
2877,
12,
325,
14,
71,
14,
1611,
3241,
63,
2822,
9551,
5144,
342,
1035,
199,
2244,
1846,
436,
1611,
3241,
63,
2822,
9551,
9551,
5144,
342,
1035,
7381,
199,
2809,
1846,
334,
692,
626,
3495,
680,
199,
624,
199,
199,
15806,
275,
378,
88,
23,
6968,
24254,
199,
2111,
57,
63,
15806,
275,
378,
9039,
993,
25481,
25481,
25481,
25481,
2260,
199,
199,
504,
485,
396,
14145,
492,
738,
5901,
63,
4283,
12,
738,
3234,
11876,
63,
4283,
12,
30151,
63,
4283,
12,
738,
12375,
63,
4283,
12,
16429,
63,
4283,
12,
971,
1362,
16429,
63,
4896,
12,
26594,
63,
4896,
12,
26594,
63,
4283,
12,
7843,
63,
2300,
11025,
63,
52,
63,
4896,
12,
7843,
63,
2300,
11025,
63,
52,
63,
4283,
12,
971,
1362,
4410,
11876,
63,
4896,
12,
4410,
11876,
63,
4283,
199,
199,
3,
4026,
12,
2985,
787,
440,
3247,
315,
2018,
1159,
1406,
1584,
199,
4464,
7770,
63,
4283,
275,
499,
538,
2766,
13,
17,
199,
4464,
7770,
63,
4896,
275,
446,
18,
538,
2766,
199,
3785,
7770,
63,
4283,
275,
499,
538,
772,
13,
17,
199,
199,
533,
9805,
26,
272,
347,
636,
442,
721,
277,
304,
267,
372,
8806,
199,
199,
533,
1910,
1737,
63,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
66,
8,
277,
304,
267,
687,
485,
396,
14145,
492,
31677,
63,
66,
267,
327,
330,
2529,
283,
2244,
1495,
297,
436,
1630,
1425,
7907,
334,
16,
2263,
738,
5901,
63,
4283,
9,
267,
291,
14,
1855,
8,
4333,
12,
31677,
63,
66,
12,
650,
14,
1079,
9,
267,
291,
14,
629,
8,
1020,
12,
31677,
63,
66,
8,
3241,
4059,
398,
291,
14,
1855,
8,
21821,
12,
31677,
63,
66,
12,
446,
17,
9,
267,
291,
14,
629,
8,
16,
12,
31677,
63,
66,
8,
16,
430,
267,
291,
14,
629,
8,
53,
5901,
63,
4283,
12,
31677,
63,
66,
8,
53,
5901,
63,
4283,
430,
267,
291,
14,
1855,
8,
21821,
12,
31677,
63,
66,
12,
738,
5901,
63,
4283,
435,
413,
9,
398,
291,
14,
629,
8,
2260,
12,
31677,
63,
66,
8,
2260,
430,
267,
291,
14,
1855,
8,
21821,
12,
31677,
63,
66,
12,
812,
9418,
63,
15806,
9,
339,
347,
511,
63,
34,
8,
277,
304,
267,
687,
485,
396,
14145,
492,
31677,
63,
34,
267,
327,
699,
2529,
283,
2244,
1495,
297,
949,
1425,
7907,
267,
291,
14,
1855,
8,
4333,
12,
31677,
63,
34,
12,
650,
14,
1079,
9,
267,
291,
14,
629,
8,
1020,
12,
31677,
63,
34,
8,
3241,
4059,
398,
291,
14,
629,
8,
53,
5901,
63,
4283,
12,
31677,
63,
34,
2801,
17,
430,
267,
291,
14,
629,
8,
16,
12,
31677,
63,
34,
8,
16,
430,
267,
291,
14,
629,
8,
53,
5901,
63,
4283,
12,
31677,
63,
34,
8,
53,
5901,
63,
4283,
430,
267,
291,
14,
629,
8,
16,
12,
31677,
63,
34,
8,
53,
5901,
63,
4283,
11,
17,
430,
398,
291,
14,
629,
8,
2260,
12,
31677,
63,
34,
8,
2260,
430,
267,
291,
14,
629,
8,
53,
5901,
63,
4283,
1253,
812,
9418,
63,
15806,
12,
31677,
63,
34,
8,
2111,
57,
63,
15806,
430,
339,
347,
511,
63,
40,
8,
277,
304,
267,
687,
485,
396,
14145,
492,
31677,
63,
40,
267,
327,
869,
2529,
283,
2244,
3974,
297,
949,
1425,
7907,
267,
291,
14,
1855,
8,
4333,
12,
31677,
63,
40,
12,
650,
14,
1079,
9,
267,
291,
14,
629,
8,
1020,
12,
31677,
63,
40,
8,
3241,
4059,
398,
291,
14,
629,
8,
14527,
11876,
63,
4283,
12,
31677,
63,
40,
2801,
17,
430,
267,
291,
14,
629,
8,
16,
12,
31677,
63,
40,
8,
16,
430,
267,
291,
14,
629,
8,
14527,
11876,
63,
4283,
12,
31677,
63,
40,
8,
14527,
11876,
63,
4283,
430,
267,
291,
14,
629,
8,
16,
12,
31677,
63,
40,
8,
14527,
11876,
63,
4283,
11,
17,
430,
398,
291,
14,
629,
8,
2260,
12,
31677,
63,
40,
8,
2260,
430,
398,
291,
14,
629,
8,
2111,
57,
63,
15806,
1253,
738,
3234,
11876,
63,
4283,
12,
31677,
63,
40,
8,
2111,
57,
63,
15806,
430,
339,
347,
511,
63,
41,
8,
277,
304,
267,
687,
485,
396,
14145,
492,
31677,
63,
41,
267,
327,
473,
2529,
283,
2244,
1109,
297,
949,
1425,
7907,
267,
291,
14,
1855,
8,
4333,
12,
31677,
63,
41,
12,
650,
14,
1079,
9,
267,
291,
14,
629,
8,
1020,
12,
31677,
63,
41,
8,
3241,
4059,
398,
291,
14,
629,
8,
17459,
63,
4283,
12,
31677,
63,
41,
2801,
17,
430,
267,
291,
14,
629,
8,
16,
12,
31677,
63,
41,
8,
16,
430,
267,
291,
14,
629,
8,
17459,
63,
4283,
12,
31677,
63,
41,
8,
17459,
63,
4283,
430,
267,
291,
14,
629,
8,
16,
12,
31677,
63,
41,
8,
17459,
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,
1
] |
kantlove/flask-simple-page
|
Lib/site-packages/jinja2/constants.py
|
1169
|
1626
|
# -*- coding: utf-8 -*-
"""
jinja.constants
~~~~~~~~~~~~~~~
Various constants.
:copyright: (c) 2010 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
#: list of lorem ipsum words used by the lipsum() helper function
LOREM_IPSUM_WORDS = u'''\
a ac accumsan ad adipiscing aenean aliquam aliquet amet ante aptent arcu at
auctor augue bibendum blandit class commodo condimentum congue consectetuer
consequat conubia convallis cras cubilia cum curabitur curae cursus dapibus
diam dictum dictumst dignissim dis dolor donec dui duis egestas eget eleifend
elementum elit enim erat eros est et etiam eu euismod facilisi facilisis fames
faucibus felis fermentum feugiat fringilla fusce gravida habitant habitasse hac
hendrerit hymenaeos iaculis id imperdiet in inceptos integer interdum ipsum
justo lacinia lacus laoreet lectus leo libero ligula litora lobortis lorem
luctus maecenas magna magnis malesuada massa mattis mauris metus mi molestie
mollis montes morbi mus nam nascetur natoque nec neque netus nibh nisi nisl non
nonummy nostra nulla nullam nunc odio orci ornare parturient pede pellentesque
penatibus per pharetra phasellus placerat platea porta porttitor posuere
potenti praesent pretium primis proin pulvinar purus quam quis quisque rhoncus
ridiculus risus rutrum sagittis sapien scelerisque sed sem semper senectus sit
sociis sociosqu sodales sollicitudin suscipit suspendisse taciti tellus tempor
tempus tincidunt torquent tortor tristique turpis ullamcorper ultrices
ultricies urna ut varius vehicula vel velit venenatis vestibulum vitae vivamus
viverra volutpat vulputate'''
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10321,
14,
5559,
272,
32202,
23597,
339,
21107,
1785,
5262,
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,
421,
199,
12573,
769,
402,
560,
13179,
15017,
453,
5932,
1202,
701,
314,
1212,
1190,
453,
342,
5922,
805,
199,
44,
726,
2769,
63,
12346,
2639,
63,
19984,
275,
399,
891,
1154,
199,
65,
1066,
11162,
18904,
1503,
282,
21846,
374,
4477,
282,
6349,
290,
21165,
392,
455,
741,
2029,
84,
282,
10207,
376,
266,
2771,
767,
14972,
85,
737,
199,
3844,
630,
18336,
310,
11314,
500,
453,
330,
1502,
1741,
1021,
1923,
19657,
406,
328,
434,
453,
406,
71,
310,
406,
3321,
10288,
14262,
199,
388,
261,
32467,
406,
456,
4674,
406,
637,
14392,
2467,
305,
22217,
1638,
65,
17303,
1094,
30299,
300,
1094,
3624,
18809,
527,
366,
1246,
5610,
199,
328,
455,
1211,
453,
1211,
453,
270,
487,
784,
374,
5206,
2153,
366,
393,
269,
4224,
67,
366,
1907,
15776,
374,
325,
3199,
305,
325,
362,
12993,
692,
500,
199,
2108,
453,
325,
1051,
655,
1017,
9266,
292,
9266,
736,
4347,
10844,
325,
280,
455,
325,
85,
325,
85,
374,
1494,
30242,
317,
338,
30242,
317,
2316,
289,
14015,
199,
667,
85,
559,
5610,
1964,
14392,
289,
281,
434,
453,
1964,
1518,
73,
292,
289,
5985,
6165,
289,
527,
301,
1999,
5017,
65,
394,
30299,
867,
394,
30299,
305,
261,
394,
645,
199,
72,
500,
264,
11133,
7188,
1410,
3624,
736,
284,
645,
13987,
83,
1305,
1742,
281,
328,
386,
315,
315,
301,
5816,
83,
3000,
1640,
27512,
15017,
453,
199,
4764,
79,
1127,
67,
2730,
65,
1127,
67,
527,
1127,
720,
386,
1026,
319,
527,
1026,
79,
1212,
605,
79,
1212,
71,
7586,
28649,
11131,
560,
31938,
16753,
560,
13179,
199,
76,
918,
527,
610,
825,
287,
305,
15916,
65,
15916,
374,
610,
2978,
8346,
65,
12250,
65,
2530,
16753,
610,
17656,
7647,
527,
10684,
1303,
14899,
1873,
199,
16924,
14392,
3485,
744,
21333,
4492,
333,
527,
302,
455,
302,
305,
301,
16218,
302,
11318,
544,
302,
825,
1279,
544,
1851,
527,
302,
1892,
72,
302,
29022,
302,
374,
76,
2222,
199,
2865,
3323,
302,
941,
345,
302,
348,
416,
302,
348,
17984,
302,
1097,
312,
3006,
503,
559,
503,
78,
1530,
1777,
2302,
484,
4837,
271,
299,
352,
552,
744,
544,
199,
897,
2159,
5610,
1126,
3945,
1530,
1239,
7669,
914,
527,
299,
416,
2247,
292,
299,
750,
65,
1844,
65,
1844,
6403,
269,
2086,
310,
264,
199,
555,
724,
280,
299,
345,
69,
1150,
876,
280,
453,
1979,
1292,
557,
262,
25239,
11908,
285,
5861,
527,
2173,
455,
2173,
374,
2173,
374,
544,
26006,
265,
67,
527,
199,
322,
328,
3119,
527,
221,
5719,
527,
519,
337,
28430,
308,
643,
390,
16753,
308,
1246,
287,
308,
15421,
5719,
544,
542,
68,
26298,
542,
311,
281,
4334,
449,
527,
13867,
199,
1152,
559,
374,
880,
559,
736,
392,
308,
364,
7098,
8597,
3137,
1181,
262,
308,
527,
6237,
390,
308,
527,
897,
2297,
261,
3052,
559,
280,
11480,
527,
16457,
199,
808,
527,
307,
6559,
344,
638,
11095,
9333,
307,
361,
269,
3229,
270,
2029,
307,
300,
80,
374,
12581,
17984,
989,
529,
221,
427,
9355,
199,
427,
322,
2578,
221,
349,
65,
11430,
4172,
527,
11199,
12089,
7586,
373,
352,
11199,
1051,
373,
287,
287,
9369,
373,
597,
1892,
348,
453,
373,
390,
3624,
373,
1003,
455,
527,
199,
433,
422,
345,
5236,
337,
10853,
373,
348,
524,
323,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10321,
14,
5559,
272,
32202,
23597,
339,
21107,
1785,
5262,
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,
421,
199,
12573,
769,
402,
560,
13179,
15017,
453,
5932,
1202,
701,
314,
1212,
1190,
453,
342,
5922,
805,
199,
44,
726,
2769,
63,
12346,
2639,
63,
19984,
275,
399,
891,
1154,
199,
65,
1066,
11162,
18904,
1503,
282,
21846,
374,
4477,
282,
6349,
290,
21165,
392,
455,
741,
2029,
84,
282,
10207,
376,
266,
2771,
767,
14972,
85,
737,
199,
3844,
630,
18336,
310,
11314,
500,
453,
330,
1502,
1741,
1021,
1923,
19657,
406,
328,
434,
453,
406,
71,
310,
406,
3321,
10288,
14262,
199,
388,
261,
32467,
406,
456,
4674,
406,
637,
14392,
2467,
305,
22217,
1638,
65,
17303,
1094,
30299,
300,
1094,
3624,
18809,
527,
366,
1246,
5610,
199,
328,
455,
1211,
453,
1211,
453,
270,
487,
784,
374,
5206,
2153,
366,
393,
269,
4224,
67,
366,
1907,
15776,
374,
325,
3199,
305,
325,
362,
12993,
692,
500,
199,
2108,
453,
325,
1051,
655,
1017,
9266,
292,
9266,
736,
4347,
10844,
325,
280,
455,
325,
85,
325,
85,
374,
1494,
30242,
317,
338,
30242,
317,
2316,
289,
14015,
199,
667,
85,
559,
5610,
1964,
14392,
289,
281,
434,
453,
1964,
1518,
73,
292,
289,
5985,
6165,
289,
527,
301,
1999,
5017,
65,
394,
30299,
867,
394,
30299,
305,
261,
394,
645,
199,
72,
500,
264,
11133,
7188,
1410,
3624,
736,
284,
645,
13987,
83,
1305,
1742,
281,
328,
386,
315,
315,
301,
5816,
83,
3000,
1640,
27512,
15017,
453,
199,
4764,
79,
1127,
67,
2730,
65,
1127,
67,
527,
1127,
720,
386,
1026,
319,
527,
1026,
79,
1212,
605,
79,
1212,
71,
7586,
28649,
11131,
560,
31938,
16753,
560,
13179,
199,
76,
918,
527,
610,
825,
287,
305,
15916,
65,
15916,
374,
610,
2978,
8346,
65,
12250,
65,
2530,
16753,
610,
17656,
7647,
527,
10684,
1303,
14899,
1873,
199,
16924,
14392,
3485,
744,
21333,
4492,
333,
527,
302,
455,
302,
305,
301,
16218,
302,
11318,
544,
302,
825,
1279,
544,
1851,
527,
302,
1892,
72,
302,
29022,
302,
374,
76,
2222,
199,
2865,
3323,
302,
941,
345,
302,
348,
416,
302,
348,
17984,
302,
1097,
312,
3006,
503,
559,
503,
78,
1530,
1777,
2302,
484,
4837,
271,
299,
352,
552,
744,
544,
199,
897,
2159,
5610,
1126,
3945,
1530,
1239,
7669,
914,
527,
299,
416,
2247,
292,
299,
750,
65,
1844,
65,
1844,
6403,
269,
2086,
310,
264,
199,
555,
724,
280,
299,
345,
69,
1150,
876,
280,
453,
1979,
1292,
557,
262,
25239,
11908,
285,
5861,
527,
2173,
455,
2173,
374,
2173,
374,
544,
26006,
265,
67,
527,
199,
322,
328,
3119,
527,
221,
5719,
527,
519,
337,
28430,
308,
643,
390,
16753,
308,
1246,
287,
308,
15421,
5719,
544,
542,
68,
26298,
542,
311,
281,
4334,
449,
527,
13867,
199,
1152,
559,
374,
880,
559,
736,
392,
308,
364,
7098,
8597,
3137,
1181,
262,
308,
527,
6237,
390,
308,
527,
897,
2297,
261,
3052,
559,
280,
11480,
527,
16457,
199,
808,
527,
307,
6559,
344,
638,
11095,
9333,
307,
361,
269,
3229,
270,
2029,
307,
300,
80,
374,
12581,
17984,
989,
529,
221,
427,
9355,
199,
427,
322,
2578,
221,
349,
65,
11430,
4172,
527,
11199,
12089,
7586,
373,
352,
11199,
1051,
373,
287,
287,
9369,
373,
597,
1892,
348,
453,
373,
390,
3624,
373,
1003,
455,
527,
199,
433,
422,
345,
5236,
337,
10853,
373,
348,
524,
323,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
MinoMino/minqlx
|
python/minqlx/_handlers.py
|
1
|
18535
|
# minqlx - Extends Quake Live's dedicated server with extra functionality and scripting.
# Copyright (C) 2015 Mino <mino@minomino.org>
# This file is part of minqlx.
# minqlx 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.
# minqlx 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 minqlx. If not, see <http://www.gnu.org/licenses/>.
import minqlx
import collections
import sched
import re
# ====================================================================
# REGULAR EXPRESSIONS
# ====================================================================
_re_say = re.compile(r"^say +\"?(?P<msg>.+)\"?$", flags=re.IGNORECASE)
_re_say_team = re.compile(r"^say_team +\"?(?P<msg>.+)\"?$", flags=re.IGNORECASE)
_re_callvote = re.compile(r"^(?:cv|callvote) +(?P<cmd>[^ ]+)(?: \"?(?P<args>.+?)\"?)?$", flags=re.IGNORECASE)
_re_vote = re.compile(r"^vote +(?P<arg>.)", flags=re.IGNORECASE)
_re_team = re.compile(r"^team +(?P<arg>.)", flags=re.IGNORECASE)
_re_vote_ended = re.compile(r"^print \"Vote (?P<result>passed|failed).\n\"$")
_re_userinfo = re.compile(r"^userinfo \"(?P<vars>.+)\"$")
# ====================================================================
# LOW-LEVEL HANDLERS
# These are all called by the C code, not within Python.
# ====================================================================
def handle_rcon(cmd):
"""Console commands that are to be processed as regular pyminqlx
commands as if the owner executes it. This allows the owner to
interact with the Python part of minqlx without having to connect.
"""
try:
minqlx.COMMANDS.handle_input(minqlx.RconDummyPlayer(), cmd, minqlx.CONSOLE_CHANNEL)
except:
minqlx.log_exception()
return True
def handle_client_command(client_id, cmd):
"""Client commands are commands such as "say", "say_team", "scores",
"disconnect" and so on. This function parses those and passes it
on to the event dispatcher.
:param client_id: The client identifier.
:type client_id: int
:param cmd: The command being ran by the client.
:type cmd: str
"""
try:
# Dispatch the "client_command" event before further processing.
player = minqlx.Player(client_id)
retval = minqlx.EVENT_DISPATCHERS["client_command"].dispatch(player, cmd)
if retval is False:
return False
elif isinstance(retval, str):
# Allow plugins to modify the command before passing it on.
cmd = retval
res = _re_say.match(cmd)
if res:
msg = res.group("msg").replace("\"", "")
channel = minqlx.CHAT_CHANNEL
if minqlx.EVENT_DISPATCHERS["chat"].dispatch(player, msg, channel) is False:
return False
return cmd
res = _re_say_team.match(cmd)
if res:
msg = res.group("msg").replace("\"", "")
if player.team == "free": # I haven't tried this, but I don't think it's even possible.
channel = minqlx.FREE_CHAT_CHANNEL
elif player.team == "red":
channel = minqlx.RED_TEAM_CHAT_CHANNEL
elif player.team == "blue":
channel = minqlx.BLUE_TEAM_CHAT_CHANNEL
else:
channel = minqlx.SPECTATOR_CHAT_CHANNEL
if minqlx.EVENT_DISPATCHERS["chat"].dispatch(player, msg, channel) is False:
return False
return cmd
res = _re_callvote.match(cmd)
if res and not minqlx.Plugin.is_vote_active():
vote = res.group("cmd")
args = res.group("args") if res.group("args") else ""
# Set the caller for vote_started in case the vote goes through.
minqlx.EVENT_DISPATCHERS["vote_started"].caller(player)
if minqlx.EVENT_DISPATCHERS["vote_called"].dispatch(player, vote, args) is False:
return False
return cmd
res = _re_vote.match(cmd)
if res and minqlx.Plugin.is_vote_active():
arg = res.group("arg").lower()
if arg == "y" or arg == "1":
if minqlx.EVENT_DISPATCHERS["vote"].dispatch(player, True) is False:
return False
elif arg == "n" or arg == "2":
if minqlx.EVENT_DISPATCHERS["vote"].dispatch(player, False) is False:
return False
return cmd
res = _re_team.match(cmd)
if res:
arg = res.group("arg").lower()
target_team = ""
if arg == player.team[0]:
# Don't trigger if player is joining the same team.
return cmd
elif arg == "f":
target_team = "free"
elif arg == "r":
target_team = "red"
elif arg == "b":
target_team = "blue"
elif arg == "s":
target_team = "spectator"
elif arg == "a":
target_team = "any"
if target_team:
if minqlx.EVENT_DISPATCHERS["team_switch_attempt"].dispatch(player, player.team, target_team) is False:
return False
return cmd
res = _re_userinfo.match(cmd)
if res:
new_info = minqlx.parse_variables(res.group("vars"), ordered=True)
old_info = player.cvars
changed = {}
for key in new_info:
if key not in old_info or (key in old_info and new_info[key] != old_info[key]):
changed[key] = new_info[key]
if changed:
ret = minqlx.EVENT_DISPATCHERS["userinfo"].dispatch(player, changed)
if ret is False:
return False
elif isinstance(ret, dict):
for key in ret:
new_info[key] = ret[key]
cmd = "userinfo \"{}\"".format("".join(["\\{}\\{}".format(key, new_info[key]) for key in new_info]))
return cmd
except:
minqlx.log_exception()
return True
def handle_server_command(client_id, cmd):
try:
# Dispatch the "server_command" event before further processing.
try:
player = minqlx.Player(client_id) if client_id >= 0 else None
except minqlx.NonexistentPlayerError:
return True
retval = minqlx.EVENT_DISPATCHERS["server_command"].dispatch(player, cmd)
if retval is False:
return False
elif isinstance(retval, str):
cmd = retval
res = _re_vote_ended.match(cmd)
if res:
if res.group("result") == "passed":
minqlx.EVENT_DISPATCHERS["vote_ended"].dispatch(True)
else:
minqlx.EVENT_DISPATCHERS["vote_ended"].dispatch(False)
return cmd
except:
minqlx.log_exception()
return True
# Executing tasks right before a frame, by the main thread, will often be desirable to avoid
# weird behavior if you were to use threading. This list will act as a task queue.
# Tasks can be added by simply adding the @minqlx.next_frame decorator to functions.
frame_tasks = sched.scheduler()
next_frame_tasks = collections.deque()
def handle_frame():
"""This will be called every frame. To allow threads to call stuff from the
main thread, tasks can be scheduled using the :func:`minqlx.next_frame` decorator
and have it be executed here.
"""
while True:
# This will run all tasks that are currently scheduled.
# If one of the tasks throw an exception, it'll log it
# and continue execution of the next tasks if any.
try:
frame_tasks.run(blocking=False)
break
except:
minqlx.log_exception()
continue
try:
minqlx.EVENT_DISPATCHERS["frame"].dispatch()
except:
minqlx.log_exception()
return True
try:
while True:
func, args, kwargs = next_frame_tasks.popleft()
frame_tasks.enter(0, 0, func, args, kwargs)
except IndexError:
pass
_zmq_warning_issued = False
_first_game = True
_ad_round_number = 0
def handle_new_game(is_restart):
# This is called early in the launch process, so it's a good place to initialize
# minqlx stuff that needs QLDS to be initialized.
global _first_game
if _first_game:
minqlx.late_init()
_first_game = False
# A good place to warn the owner if ZMQ stats are disabled.
global _zmq_warning_issued
if not bool(int(minqlx.get_cvar("zmq_stats_enable"))) and not _zmq_warning_issued:
logger = minqlx.get_logger()
logger.warning("Some events will not work because ZMQ stats is not enabled. "
"Launch the server with \"zmq_stats_enable 1\"")
_zmq_warning_issued = True
minqlx.set_map_subtitles()
if not is_restart:
try:
minqlx.EVENT_DISPATCHERS["map"].dispatch(
minqlx.get_cvar("mapname"),
minqlx.get_cvar("g_factory"))
except:
minqlx.log_exception()
return True
try:
minqlx.EVENT_DISPATCHERS["new_game"].dispatch()
except:
minqlx.log_exception()
return True
def handle_set_configstring(index, value):
"""Called whenever the server tries to set a configstring. Can return
False to stop the event.
"""
global _ad_round_number
try:
res = minqlx.EVENT_DISPATCHERS["set_configstring"].dispatch(index, value)
if res is False:
return False
elif isinstance(res, str):
value = res
# VOTES
if index == 9 and value:
cmd = value.split()
vote = cmd[0] if cmd else ""
args = " ".join(cmd[1:]) if len(cmd) > 1 else ""
minqlx.EVENT_DISPATCHERS["vote_started"].dispatch(vote, args)
return
# GAME STATE CHANGES
elif index == 0:
old_cs = minqlx.parse_variables(minqlx.get_configstring(index))
if not old_cs:
return
new_cs = minqlx.parse_variables(value)
old_state = old_cs["g_gameState"]
new_state = new_cs["g_gameState"]
if old_state != new_state:
if old_state == "PRE_GAME" and new_state == "IN_PROGRESS":
pass
elif old_state == "PRE_GAME" and new_state == "COUNT_DOWN":
_ad_round_number = 1
minqlx.EVENT_DISPATCHERS["game_countdown"].dispatch()
elif old_state == "COUNT_DOWN" and new_state == "IN_PROGRESS":
pass
#minqlx.EVENT_DISPATCHERS["game_start"].dispatch()
elif old_state == "IN_PROGRESS" and new_state == "PRE_GAME":
pass
elif old_state == "COUNT_DOWN" and new_state == "PRE_GAME":
pass
else:
logger = minqlx.get_logger()
logger.warning("UNKNOWN GAME STATES: {} - {}".format(old_state, new_state))
# ROUND COUNTDOWN AND START
elif index == 661:
cvars = minqlx.parse_variables(value)
if cvars:
if "turn" in cvars:
# it is A&D
if int(cvars["state"]) == 0:
return
# round cvar appears only on round countdown
# and first round is 0, not 1
try:
round_number = int(cvars["round"]) * 2 + 1 + int(cvars["turn"])
_ad_round_number = round_number
except KeyError:
round_number = _ad_round_number
else:
# it is CA
round_number = int(cvars["round"])
if round_number and "time" in cvars:
minqlx.EVENT_DISPATCHERS["round_countdown"].dispatch(round_number)
return
elif round_number:
minqlx.EVENT_DISPATCHERS["round_start"].dispatch(round_number)
return
return res
except:
minqlx.log_exception()
return True
def handle_player_connect(client_id, is_bot):
"""This will be called whenever a player tries to connect. If the dispatcher
returns False, it will not allow the player to connect and instead show them
a message explaining why. The default message is "You are banned from this
server.", but it can be set with :func:`minqlx.set_ban_message`.
:param client_id: The client identifier.
:type client_id: int
:param is_bot: Whether or not the player is a bot.
:type is_bot: bool
"""
try:
player = minqlx.Player(client_id)
return minqlx.EVENT_DISPATCHERS["player_connect"].dispatch(player)
except:
minqlx.log_exception()
return True
def handle_player_loaded(client_id):
"""This will be called whenever a player has connected and finished loading,
meaning it'll go off a bit later than the usual "X connected" messages.
This will not trigger on bots.
:param client_id: The client identifier.
:type client_id: int
"""
try:
player = minqlx.Player(client_id)
return minqlx.EVENT_DISPATCHERS["player_loaded"].dispatch(player)
except:
minqlx.log_exception()
return True
def handle_player_disconnect(client_id, reason):
"""This will be called whenever a player disconnects.
:param client_id: The client identifier.
:type client_id: int
"""
try:
player = minqlx.Player(client_id)
return minqlx.EVENT_DISPATCHERS["player_disconnect"].dispatch(player, reason)
except:
minqlx.log_exception()
return True
def handle_player_spawn(client_id):
"""Called when a player spawns. Note that a spectator going in free spectate mode
makes the client spawn, so you'll want to check for that if you only want "actual"
spawns.
"""
try:
player = minqlx.Player(client_id)
return minqlx.EVENT_DISPATCHERS["player_spawn"].dispatch(player)
except:
minqlx.log_exception()
return True
def handle_kamikaze_use(client_id):
"""This will be called whenever player uses kamikaze item.
:param client_id: The client identifier.
:type client_id: int
"""
try:
player = minqlx.Player(client_id)
return minqlx.EVENT_DISPATCHERS["kamikaze_use"].dispatch(player)
except:
minqlx.log_exception()
return True
def handle_kamikaze_explode(client_id, is_used_on_demand):
"""This will be called whenever kamikaze explodes.
:param client_id: The client identifier.
:type client_id: int
:param is_used_on_demand: Non-zero if kamikaze is used on demand.
:type is_used_on_demand: int
"""
try:
player = minqlx.Player(client_id)
return minqlx.EVENT_DISPATCHERS["kamikaze_explode"].dispatch(player, True if is_used_on_demand else False)
except:
minqlx.log_exception()
return True
def handle_console_print(text):
"""Called whenever the server prints something to the console and when rcon is used."""
try:
if not text:
return
# Log console output. Removes the need to have stdout logs in addition to minqlx.log.
minqlx.get_logger().debug(text.rstrip("\n"))
res = minqlx.EVENT_DISPATCHERS["console_print"].dispatch(text)
if res is False:
return False
if _print_redirection:
global _print_buffer
_print_buffer += text
if isinstance(res, str):
return res
return text
except:
minqlx.log_exception()
return True
_print_redirection = None
_print_buffer = ""
def redirect_print(channel):
"""Redirects print output to a channel. Useful for commands that execute console commands
and want to redirect the output to the channel instead of letting it go to the console.
To use it, use the return value with the "with" statement.
.. code-block:: python
def cmd_echo(self, player, msg, channel):
with minqlx.redirect_print(channel):
minqlx.console_command("echo {}".format(" ".join(msg)))
"""
class PrintRedirector:
def __init__(self, channel):
if not isinstance(channel, minqlx.AbstractChannel):
raise ValueError("The redirection channel must be an instance of minqlx.AbstractChannel.")
self.channel = channel
def __enter__(self):
global _print_redirection
_print_redirection = self.channel
def __exit__(self, exc_type, exc_val, exc_tb):
global _print_redirection
self.flush()
_print_redirection = None
def flush(self):
global _print_buffer
self.channel.reply(_print_buffer)
_print_buffer = ""
return PrintRedirector(channel)
def register_handlers():
minqlx.register_handler("rcon", handle_rcon)
minqlx.register_handler("client_command", handle_client_command)
minqlx.register_handler("server_command", handle_server_command)
minqlx.register_handler("frame", handle_frame)
minqlx.register_handler("new_game", handle_new_game)
minqlx.register_handler("set_configstring", handle_set_configstring)
minqlx.register_handler("player_connect", handle_player_connect)
minqlx.register_handler("player_loaded", handle_player_loaded)
minqlx.register_handler("player_disconnect", handle_player_disconnect)
minqlx.register_handler("player_spawn", handle_player_spawn)
minqlx.register_handler("console_print", handle_console_print)
minqlx.register_handler("kamikaze_use", handle_kamikaze_use)
minqlx.register_handler("kamikaze_explode", handle_kamikaze_explode)
|
gpl-3.0
|
[
3,
1748,
1710,
88,
446,
11524,
795,
1413,
1458,
415,
24683,
1159,
29711,
1654,
543,
2402,
9330,
436,
2884,
316,
14,
199,
3,
1898,
334,
35,
9,
6900,
603,
10175,
665,
827,
79,
32,
827,
676,
10175,
14,
1308,
30,
199,
199,
3,
961,
570,
365,
1777,
402,
1748,
1710,
88,
14,
199,
199,
3,
1748,
1710,
88,
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,
199,
3,
1748,
1710,
88,
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,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
1748,
1710,
88,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
1748,
1710,
88,
199,
646,
5055,
199,
646,
10286,
199,
646,
295,
199,
199,
3,
7819,
5918,
199,
3,
12788,
14142,
3038,
7168,
2823,
199,
3,
7819,
5918,
199,
199,
63,
264,
63,
19787,
275,
295,
14,
2014,
8,
82,
16136,
19787,
435,
4451,
31,
2229,
48,
28,
1328,
31411,
2862,
14863,
11918,
3285,
29,
264,
14,
15434,
9,
199,
63,
264,
63,
19787,
63,
5969,
275,
295,
14,
2014,
8,
82,
16136,
19787,
63,
5969,
435,
4451,
31,
2229,
48,
28,
1328,
31411,
2862,
14863,
11918,
3285,
29,
264,
14,
15434,
9,
199,
63,
264,
63,
1250,
14317,
275,
295,
14,
2014,
8,
82,
16136,
5169,
5107,
92,
1250,
14317,
9,
435,
2229,
48,
28,
1760,
13489,
1622,
8771,
5169,
8441,
31,
2229,
48,
28,
589,
29587,
2862,
14863,
5547,
11918,
3285,
29,
264,
14,
15434,
9,
199,
63,
264,
63,
14317,
275,
295,
14,
2014,
8,
82,
16136,
14317,
435,
2229,
48,
28,
1273,
10827,
4186,
3285,
29,
264,
14,
15434,
9,
199,
63,
264,
63,
5969,
275,
295,
14,
2014,
8,
82,
16136,
5969,
435,
2229,
48,
28,
1273,
10827,
4186,
3285,
29,
264,
14,
15434,
9,
199,
63,
264,
63,
14317,
63,
8960,
275,
295,
14,
2014,
8,
82,
16136,
1361,
8441,
54,
1583,
7558,
48,
28,
1099,
30,
12070,
92,
4892,
12013,
78,
4451,
22550,
199,
63,
264,
63,
751,
815,
275,
295,
14,
2014,
8,
82,
16136,
751,
815,
8441,
2229,
48,
28,
2936,
31411,
2862,
2,
22550,
199,
199,
3,
7819,
5918,
199,
3,
12793,
21359,
13,
11817,
23276,
28778,
199,
3,
263,
5723,
787,
1006,
2797,
701,
314,
445,
1233,
12,
440,
4453,
2018,
14,
199,
3,
7819,
5918,
199,
199,
318,
2429,
63,
82,
388,
8,
1760,
304,
272,
408,
9270,
3718,
626,
787,
370,
506,
7686,
465,
5578,
1134,
827,
1710,
88,
272,
3718,
465,
340,
314,
5771,
24956,
652,
14,
961,
6127,
314,
5771,
370,
272,
17232,
543,
314,
2018,
1777,
402,
1748,
1710,
88,
1928,
9445,
370,
4907,
14,
339,
408,
272,
862,
26,
267,
1748,
1710,
88,
14,
28442,
14,
2479,
63,
1210,
8,
827,
1710,
88,
14,
50,
388,
11324,
10921,
1062,
2088,
12,
1748,
1710,
88,
14,
31774,
63,
14833,
9,
272,
871,
26,
267,
1748,
1710,
88,
14,
793,
63,
1971,
342,
267,
372,
715,
199,
199,
318,
2429,
63,
1258,
63,
1531,
8,
1258,
63,
344,
12,
2088,
304,
272,
408,
3041,
3718,
787,
3718,
4066,
465,
298,
19787,
401,
298,
19787,
63,
5969,
401,
298,
7107,
401,
272,
298,
10673,
2,
436,
880,
641,
14,
961,
805,
19953,
5204,
436,
14933,
652,
272,
641,
370,
314,
1566,
17475,
14,
339,
520,
635,
1890,
63,
344,
26,
710,
1890,
5148,
14,
272,
520,
466,
1890,
63,
344,
26,
1109,
272,
520,
635,
2088,
26,
710,
1414,
3769,
21471,
701,
314,
1890,
14,
272,
520,
466,
2088,
26,
620,
339,
408,
272,
862,
26,
267,
327,
28626,
314,
298,
1258,
63,
1531,
2,
1566,
2544,
9848,
6661,
14,
267,
7748,
275,
1748,
1710,
88,
14,
10921,
8,
1258,
63,
344,
9,
267,
9151,
275,
1748,
1710,
88,
14,
8193,
63,
32550,
3960,
905,
1258,
63,
1531,
4140,
6052,
8,
6147,
12,
2088,
9,
267,
340,
9151,
365,
756,
26,
288,
372,
756,
267,
916,
1228,
8,
18476,
12,
620,
304,
288,
327,
9812,
8963,
370,
2811,
314,
1414,
2544,
9476,
652,
641,
14,
288,
2088,
275,
9151,
398,
522,
275,
485,
264,
63,
19787,
14,
1431,
8,
1760,
9,
267,
340,
522,
26,
288,
1499,
275,
522,
14,
923,
480,
1328,
3471,
1814,
4582,
5151,
6899,
288,
3623,
275,
1748,
1710,
88,
14,
1244,
619,
63,
14833,
288,
340,
1748,
1710,
88,
14,
8193,
63,
32550,
3960,
905,
10289,
4140,
6052,
8,
6147,
12,
1499,
12,
3623,
9,
365,
756,
26,
355,
372,
756,
288,
372,
2088,
398,
522,
275,
485,
264,
63,
19787,
63,
5969,
14,
1431,
8,
1760,
9,
267,
340,
522,
26,
288,
1499,
275,
522,
14,
923,
480,
1328,
3471,
1814,
4582,
5151,
6899,
288,
340,
7748,
14,
5969,
508,
298,
4624,
582,
327,
473,
19051,
1133,
16416,
642,
12,
1325,
473,
2793,
1133,
13516,
652,
1159,
2755,
3962,
14,
355,
3623,
275,
1748,
1710,
88,
14,
28170,
63,
1244,
619,
63,
14833,
288,
916,
7748,
14,
5969,
508,
298,
581,
582,
355,
3623,
275,
1748,
1710,
88,
14,
7387,
63,
3727,
1156,
63,
1244,
619,
63,
14833,
288,
916,
7748,
14,
5969,
508,
298,
6304,
582,
355,
3623,
275,
1748,
1710,
88,
14,
23536,
63,
3727,
1156,
63,
1244,
619,
63,
14833,
288,
587,
26,
355,
3623,
275,
1748,
1710,
88,
14,
51,
11401,
6467,
63,
1244,
619,
63,
14833,
288,
340,
1748,
1710,
88,
14,
8193,
63,
32550,
3960,
905,
10289,
4140,
6052,
8,
6147,
12,
1499,
12,
3623,
9,
365,
756,
26,
355,
372,
756,
288,
372,
2088,
398,
522,
275,
485,
264,
63,
1250,
14317,
14,
1431,
8,
1760,
9,
267,
340,
522,
436,
440
] |
[
1748,
1710,
88,
446,
11524,
795,
1413,
1458,
415,
24683,
1159,
29711,
1654,
543,
2402,
9330,
436,
2884,
316,
14,
199,
3,
1898,
334,
35,
9,
6900,
603,
10175,
665,
827,
79,
32,
827,
676,
10175,
14,
1308,
30,
199,
199,
3,
961,
570,
365,
1777,
402,
1748,
1710,
88,
14,
199,
199,
3,
1748,
1710,
88,
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,
199,
3,
1748,
1710,
88,
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,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
1748,
1710,
88,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
1748,
1710,
88,
199,
646,
5055,
199,
646,
10286,
199,
646,
295,
199,
199,
3,
7819,
5918,
199,
3,
12788,
14142,
3038,
7168,
2823,
199,
3,
7819,
5918,
199,
199,
63,
264,
63,
19787,
275,
295,
14,
2014,
8,
82,
16136,
19787,
435,
4451,
31,
2229,
48,
28,
1328,
31411,
2862,
14863,
11918,
3285,
29,
264,
14,
15434,
9,
199,
63,
264,
63,
19787,
63,
5969,
275,
295,
14,
2014,
8,
82,
16136,
19787,
63,
5969,
435,
4451,
31,
2229,
48,
28,
1328,
31411,
2862,
14863,
11918,
3285,
29,
264,
14,
15434,
9,
199,
63,
264,
63,
1250,
14317,
275,
295,
14,
2014,
8,
82,
16136,
5169,
5107,
92,
1250,
14317,
9,
435,
2229,
48,
28,
1760,
13489,
1622,
8771,
5169,
8441,
31,
2229,
48,
28,
589,
29587,
2862,
14863,
5547,
11918,
3285,
29,
264,
14,
15434,
9,
199,
63,
264,
63,
14317,
275,
295,
14,
2014,
8,
82,
16136,
14317,
435,
2229,
48,
28,
1273,
10827,
4186,
3285,
29,
264,
14,
15434,
9,
199,
63,
264,
63,
5969,
275,
295,
14,
2014,
8,
82,
16136,
5969,
435,
2229,
48,
28,
1273,
10827,
4186,
3285,
29,
264,
14,
15434,
9,
199,
63,
264,
63,
14317,
63,
8960,
275,
295,
14,
2014,
8,
82,
16136,
1361,
8441,
54,
1583,
7558,
48,
28,
1099,
30,
12070,
92,
4892,
12013,
78,
4451,
22550,
199,
63,
264,
63,
751,
815,
275,
295,
14,
2014,
8,
82,
16136,
751,
815,
8441,
2229,
48,
28,
2936,
31411,
2862,
2,
22550,
199,
199,
3,
7819,
5918,
199,
3,
12793,
21359,
13,
11817,
23276,
28778,
199,
3,
263,
5723,
787,
1006,
2797,
701,
314,
445,
1233,
12,
440,
4453,
2018,
14,
199,
3,
7819,
5918,
199,
199,
318,
2429,
63,
82,
388,
8,
1760,
304,
272,
408,
9270,
3718,
626,
787,
370,
506,
7686,
465,
5578,
1134,
827,
1710,
88,
272,
3718,
465,
340,
314,
5771,
24956,
652,
14,
961,
6127,
314,
5771,
370,
272,
17232,
543,
314,
2018,
1777,
402,
1748,
1710,
88,
1928,
9445,
370,
4907,
14,
339,
408,
272,
862,
26,
267,
1748,
1710,
88,
14,
28442,
14,
2479,
63,
1210,
8,
827,
1710,
88,
14,
50,
388,
11324,
10921,
1062,
2088,
12,
1748,
1710,
88,
14,
31774,
63,
14833,
9,
272,
871,
26,
267,
1748,
1710,
88,
14,
793,
63,
1971,
342,
267,
372,
715,
199,
199,
318,
2429,
63,
1258,
63,
1531,
8,
1258,
63,
344,
12,
2088,
304,
272,
408,
3041,
3718,
787,
3718,
4066,
465,
298,
19787,
401,
298,
19787,
63,
5969,
401,
298,
7107,
401,
272,
298,
10673,
2,
436,
880,
641,
14,
961,
805,
19953,
5204,
436,
14933,
652,
272,
641,
370,
314,
1566,
17475,
14,
339,
520,
635,
1890,
63,
344,
26,
710,
1890,
5148,
14,
272,
520,
466,
1890,
63,
344,
26,
1109,
272,
520,
635,
2088,
26,
710,
1414,
3769,
21471,
701,
314,
1890,
14,
272,
520,
466,
2088,
26,
620,
339,
408,
272,
862,
26,
267,
327,
28626,
314,
298,
1258,
63,
1531,
2,
1566,
2544,
9848,
6661,
14,
267,
7748,
275,
1748,
1710,
88,
14,
10921,
8,
1258,
63,
344,
9,
267,
9151,
275,
1748,
1710,
88,
14,
8193,
63,
32550,
3960,
905,
1258,
63,
1531,
4140,
6052,
8,
6147,
12,
2088,
9,
267,
340,
9151,
365,
756,
26,
288,
372,
756,
267,
916,
1228,
8,
18476,
12,
620,
304,
288,
327,
9812,
8963,
370,
2811,
314,
1414,
2544,
9476,
652,
641,
14,
288,
2088,
275,
9151,
398,
522,
275,
485,
264,
63,
19787,
14,
1431,
8,
1760,
9,
267,
340,
522,
26,
288,
1499,
275,
522,
14,
923,
480,
1328,
3471,
1814,
4582,
5151,
6899,
288,
3623,
275,
1748,
1710,
88,
14,
1244,
619,
63,
14833,
288,
340,
1748,
1710,
88,
14,
8193,
63,
32550,
3960,
905,
10289,
4140,
6052,
8,
6147,
12,
1499,
12,
3623,
9,
365,
756,
26,
355,
372,
756,
288,
372,
2088,
398,
522,
275,
485,
264,
63,
19787,
63,
5969,
14,
1431,
8,
1760,
9,
267,
340,
522,
26,
288,
1499,
275,
522,
14,
923,
480,
1328,
3471,
1814,
4582,
5151,
6899,
288,
340,
7748,
14,
5969,
508,
298,
4624,
582,
327,
473,
19051,
1133,
16416,
642,
12,
1325,
473,
2793,
1133,
13516,
652,
1159,
2755,
3962,
14,
355,
3623,
275,
1748,
1710,
88,
14,
28170,
63,
1244,
619,
63,
14833,
288,
916,
7748,
14,
5969,
508,
298,
581,
582,
355,
3623,
275,
1748,
1710,
88,
14,
7387,
63,
3727,
1156,
63,
1244,
619,
63,
14833,
288,
916,
7748,
14,
5969,
508,
298,
6304,
582,
355,
3623,
275,
1748,
1710,
88,
14,
23536,
63,
3727,
1156,
63,
1244,
619,
63,
14833,
288,
587,
26,
355,
3623,
275,
1748,
1710,
88,
14,
51,
11401,
6467,
63,
1244,
619,
63,
14833,
288,
340,
1748,
1710,
88,
14,
8193,
63,
32550,
3960,
905,
10289,
4140,
6052,
8,
6147,
12,
1499,
12,
3623,
9,
365,
756,
26,
355,
372,
756,
288,
372,
2088,
398,
522,
275,
485,
264,
63,
1250,
14317,
14,
1431,
8,
1760,
9,
267,
340,
522,
436,
440,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bhargav2408/python-for-android
|
python-modules/twisted/twisted/trial/test/test_warning.py
|
60
|
14755
|
# Copyright (c) 2008-2009 Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Tests for Trial's interaction with the Python warning system.
"""
import sys, warnings
from StringIO import StringIO
from twisted.python.filepath import FilePath
from twisted.trial.unittest import TestCase, _collectWarnings
from twisted.trial.reporter import TestResult
class Mask(object):
"""
Hide a L{TestCase} definition from trial's automatic discovery mechanism.
"""
class MockTests(TestCase):
"""
A test case which is used by L{FlushWarningsTests} to verify behavior
which cannot be verified by code inside a single test method.
"""
message = "some warning text"
category = UserWarning
def test_unflushed(self):
"""
Generate a warning and don't flush it.
"""
warnings.warn(self.message, self.category)
def test_flushed(self):
"""
Generate a warning and flush it.
"""
warnings.warn(self.message, self.category)
self.assertEqual(len(self.flushWarnings()), 1)
class FlushWarningsTests(TestCase):
"""
Tests for L{TestCase.flushWarnings}, an API for examining the warnings
emitted so far in a test.
"""
def assertDictSubset(self, set, subset):
"""
Assert that all the keys present in C{subset} are also present in
C{set} and that the corresponding values are equal.
"""
for k, v in subset.iteritems():
self.assertEqual(set[k], v)
def assertDictSubsets(self, sets, subsets):
"""
For each pair of corresponding elements in C{sets} and C{subsets},
assert that the element from C{subsets} is a subset of the element from
C{sets}.
"""
self.assertEqual(len(sets), len(subsets))
for a, b in zip(sets, subsets):
self.assertDictSubset(a, b)
def test_none(self):
"""
If no warnings are emitted by a test, L{TestCase.flushWarnings} returns
an empty list.
"""
self.assertEqual(self.flushWarnings(), [])
def test_several(self):
"""
If several warnings are emitted by a test, L{TestCase.flushWarnings}
returns a list containing all of them.
"""
firstMessage = "first warning message"
firstCategory = UserWarning
warnings.warn(message=firstMessage, category=firstCategory)
secondMessage = "second warning message"
secondCategory = RuntimeWarning
warnings.warn(message=secondMessage, category=secondCategory)
self.assertDictSubsets(
self.flushWarnings(),
[{'category': firstCategory, 'message': firstMessage},
{'category': secondCategory, 'message': secondMessage}])
def test_repeated(self):
"""
The same warning triggered twice from the same place is included twice
in the list returned by L{TestCase.flushWarnings}.
"""
message = "the message"
category = RuntimeWarning
for i in range(2):
warnings.warn(message=message, category=category)
self.assertDictSubsets(
self.flushWarnings(),
[{'category': category, 'message': message}] * 2)
def test_cleared(self):
"""
After a particular warning event has been returned by
L{TestCase.flushWarnings}, it is not returned by subsequent calls.
"""
message = "the message"
category = RuntimeWarning
warnings.warn(message=message, category=category)
self.assertDictSubsets(
self.flushWarnings(),
[{'category': category, 'message': message}])
self.assertEqual(self.flushWarnings(), [])
def test_unflushed(self):
"""
Any warnings emitted by a test which are not flushed are emitted to the
Python warning system.
"""
result = TestResult()
case = Mask.MockTests('test_unflushed')
case.run(result)
warningsShown = self.flushWarnings([Mask.MockTests.test_unflushed])
self.assertEqual(warningsShown[0]['message'], 'some warning text')
self.assertIdentical(warningsShown[0]['category'], UserWarning)
where = case.test_unflushed.im_func.func_code
filename = where.co_filename
# If someone edits MockTests.test_unflushed, the value added to
# firstlineno might need to change.
lineno = where.co_firstlineno + 4
self.assertEqual(warningsShown[0]['filename'], filename)
self.assertEqual(warningsShown[0]['lineno'], lineno)
self.assertEqual(len(warningsShown), 1)
def test_flushed(self):
"""
Any warnings emitted by a test which are flushed are not emitted to the
Python warning system.
"""
result = TestResult()
case = Mask.MockTests('test_flushed')
output = StringIO()
monkey = self.patch(sys, 'stdout', output)
case.run(result)
monkey.restore()
self.assertEqual(output.getvalue(), "")
def test_warningsConfiguredAsErrors(self):
"""
If a warnings filter has been installed which turns warnings into
exceptions, tests have an error added to the reporter for them for each
unflushed warning.
"""
class CustomWarning(Warning):
pass
result = TestResult()
case = Mask.MockTests('test_unflushed')
case.category = CustomWarning
originalWarnings = warnings.filters[:]
try:
warnings.simplefilter('error')
case.run(result)
self.assertEqual(len(result.errors), 1)
self.assertIdentical(result.errors[0][0], case)
result.errors[0][1].trap(CustomWarning)
finally:
warnings.filters[:] = originalWarnings
def test_flushedWarningsConfiguredAsErrors(self):
"""
If a warnings filter has been installed which turns warnings into
exceptions, tests which emit those warnings but flush them do not have
an error added to the reporter.
"""
class CustomWarning(Warning):
pass
result = TestResult()
case = Mask.MockTests('test_flushed')
case.category = CustomWarning
originalWarnings = warnings.filters[:]
try:
warnings.simplefilter('error')
case.run(result)
self.assertEqual(result.errors, [])
finally:
warnings.filters[:] = originalWarnings
def test_multipleFlushes(self):
"""
Any warnings emitted after a call to L{TestCase.flushWarnings} can be
flushed by another call to L{TestCase.flushWarnings}.
"""
warnings.warn("first message")
self.assertEqual(len(self.flushWarnings()), 1)
warnings.warn("second message")
self.assertEqual(len(self.flushWarnings()), 1)
def test_filterOnOffendingFunction(self):
"""
The list returned by L{TestCase.flushWarnings} includes only those
warnings which refer to the source of the function passed as the value
for C{offendingFunction}, if a value is passed for that parameter.
"""
firstMessage = "first warning text"
firstCategory = UserWarning
def one():
warnings.warn(firstMessage, firstCategory, stacklevel=1)
secondMessage = "some text"
secondCategory = RuntimeWarning
def two():
warnings.warn(secondMessage, secondCategory, stacklevel=1)
one()
two()
self.assertDictSubsets(
self.flushWarnings(offendingFunctions=[one]),
[{'category': firstCategory, 'message': firstMessage}])
self.assertDictSubsets(
self.flushWarnings(offendingFunctions=[two]),
[{'category': secondCategory, 'message': secondMessage}])
def test_functionBoundaries(self):
"""
Verify that warnings emitted at the very edges of a function are still
determined to be emitted from that function.
"""
def warner():
warnings.warn("first line warning")
warnings.warn("internal line warning")
warnings.warn("last line warning")
warner()
self.assertEqual(
len(self.flushWarnings(offendingFunctions=[warner])), 3)
def test_invalidFilter(self):
"""
If an object which is neither a function nor a method is included in
the C{offendingFunctions} list, L{TestCase.flushWarnings} raises
L{ValueError}. Such a call flushes no warnings.
"""
warnings.warn("oh no")
self.assertRaises(ValueError, self.flushWarnings, [None])
self.assertEqual(len(self.flushWarnings()), 1)
def test_missingSource(self):
"""
Warnings emitted by a function the source code of which is not
available can still be flushed.
"""
package = FilePath(self.mktemp()).child('twisted_private_helper')
package.makedirs()
package.child('__init__.py').setContent('')
package.child('missingsourcefile.py').setContent('''
import warnings
def foo():
warnings.warn("oh no")
''')
sys.path.insert(0, package.parent().path)
self.addCleanup(sys.path.remove, package.parent().path)
from twisted_private_helper import missingsourcefile
self.addCleanup(sys.modules.pop, 'twisted_private_helper')
self.addCleanup(sys.modules.pop, missingsourcefile.__name__)
package.child('missingsourcefile.py').remove()
missingsourcefile.foo()
self.assertEqual(len(self.flushWarnings([missingsourcefile.foo])), 1)
def test_renamedSource(self):
"""
Warnings emitted by a function defined in a file which has been renamed
since it was initially compiled can still be flushed.
This is testing the code which specifically supports working around the
unfortunate behavior of CPython to write a .py source file name into
the .pyc files it generates and then trust that it is correct in
various places. If source files are renamed, .pyc files may not be
regenerated, but they will contain incorrect filenames.
"""
package = FilePath(self.mktemp()).child('twisted_private_helper')
package.makedirs()
package.child('__init__.py').setContent('')
package.child('module.py').setContent('''
import warnings
def foo():
warnings.warn("oh no")
''')
sys.path.insert(0, package.parent().path)
self.addCleanup(sys.path.remove, package.parent().path)
# Import it to cause pycs to be generated
from twisted_private_helper import module
# Clean up the state resulting from that import; we're not going to use
# this module, so it should go away.
del sys.modules['twisted_private_helper']
del sys.modules[module.__name__]
# Rename the source directory
package.moveTo(package.sibling('twisted_renamed_helper'))
# Import the newly renamed version
from twisted_renamed_helper import module
self.addCleanup(sys.modules.pop, 'twisted_renamed_helper')
self.addCleanup(sys.modules.pop, module.__name__)
# Generate the warning
module.foo()
# Flush it
self.assertEqual(len(self.flushWarnings([module.foo])), 1)
class FakeWarning(Warning):
pass
class CollectWarningsTests(TestCase):
"""
Tests for L{_collectWarnings}.
"""
def test_callsObserver(self):
"""
L{_collectWarnings} calls the observer with each emitted warning.
"""
firstMessage = "dummy calls observer warning"
secondMessage = firstMessage[::-1]
events = []
def f():
events.append('call')
warnings.warn(firstMessage)
warnings.warn(secondMessage)
events.append('returning')
_collectWarnings(events.append, f)
self.assertEqual(events[0], 'call')
self.assertEqual(events[1].message, firstMessage)
self.assertEqual(events[2].message, secondMessage)
self.assertEqual(events[3], 'returning')
self.assertEqual(len(events), 4)
def test_suppresses(self):
"""
Any warnings emitted by a call to a function passed to
L{_collectWarnings} are not actually emitted to the warning system.
"""
output = StringIO()
self.patch(sys, 'stdout', output)
_collectWarnings(lambda x: None, warnings.warn, "text")
self.assertEqual(output.getvalue(), "")
def test_callsFunction(self):
"""
L{_collectWarnings} returns the result of calling the callable passed to
it with the parameters given.
"""
arguments = []
value = object()
def f(*args, **kwargs):
arguments.append((args, kwargs))
return value
result = _collectWarnings(lambda x: None, f, 1, 'a', b=2, c='d')
self.assertEqual(arguments, [((1, 'a'), {'b': 2, 'c': 'd'})])
self.assertIdentical(result, value)
def test_duplicateWarningCollected(self):
"""
Subsequent emissions of a warning from a particular source site can be
collected by L{_collectWarnings}. In particular, the per-module
emitted-warning cache should be bypassed (I{__warningregistry__}).
"""
# Make sure the worst case is tested: if __warningregistry__ isn't in a
# module's globals, then the warning system will add it and start using
# it to avoid emitting duplicate warnings. Delete __warningregistry__
# to ensure that even modules which are first imported as a test is
# running still interact properly with the warning system.
global __warningregistry__
del __warningregistry__
def f():
warnings.warn("foo")
warnings.simplefilter('default')
f()
events = []
_collectWarnings(events.append, f)
self.assertEqual(len(events), 1)
self.assertEqual(events[0].message, "foo")
self.assertEqual(len(self.flushWarnings()), 1)
def test_immutableObject(self):
"""
L{_collectWarnings}'s behavior is not altered by the presence of an
object which cannot have attributes set on it as a value in
C{sys.modules}.
"""
key = object()
sys.modules[key] = key
self.addCleanup(sys.modules.pop, key)
self.test_duplicateWarningCollected()
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
9079,
13,
8664,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
2925,
367,
377,
1383,
1159,
18752,
543,
314,
2018,
5721,
2656,
14,
199,
624,
199,
199,
646,
984,
12,
3598,
199,
504,
5228,
492,
5228,
199,
199,
504,
7390,
14,
1548,
14,
7218,
492,
27961,
199,
504,
7390,
14,
14443,
14,
2796,
492,
7640,
12,
485,
7112,
15921,
199,
504,
7390,
14,
14443,
14,
12222,
492,
23795,
199,
199,
533,
17581,
8,
785,
304,
272,
408,
272,
869,
2655,
282,
491,
91,
1746,
93,
5492,
687,
16324,
1159,
4834,
13172,
14729,
14,
272,
408,
272,
1021,
4420,
2925,
8,
1746,
304,
267,
408,
267,
437,
511,
1930,
1314,
365,
1202,
701,
491,
91,
20053,
15921,
2925,
93,
370,
4911,
5953,
267,
1314,
3913,
506,
16317,
701,
1233,
6272,
282,
2849,
511,
1083,
14,
267,
408,
267,
1245,
275,
298,
3972,
5721,
1318,
2,
267,
4637,
275,
2876,
3849,
398,
347,
511,
63,
324,
4939,
379,
8,
277,
304,
288,
408,
288,
7958,
282,
5721,
436,
2793,
1133,
8976,
652,
14,
288,
408,
288,
3598,
14,
4050,
8,
277,
14,
1188,
12,
291,
14,
3710,
9,
7318,
347,
511,
63,
4939,
379,
8,
277,
304,
288,
408,
288,
7958,
282,
5721,
436,
8976,
652,
14,
288,
408,
288,
3598,
14,
4050,
8,
277,
14,
1188,
12,
291,
14,
3710,
9,
288,
291,
14,
629,
8,
552,
8,
277,
14,
4939,
15921,
4000,
413,
9,
4388,
199,
533,
11040,
2084,
15921,
2925,
8,
1746,
304,
272,
408,
272,
6496,
367,
491,
91,
1746,
14,
4939,
15921,
1386,
376,
3261,
367,
15735,
7969,
314,
3598,
272,
19515,
880,
12474,
315,
282,
511,
14,
272,
408,
339,
347,
702,
2141,
20113,
8,
277,
12,
663,
12,
10026,
304,
267,
408,
267,
10716,
626,
1006,
314,
2883,
3451,
315,
445,
91,
9401,
93,
787,
2597,
3451,
315,
267,
445,
91,
409,
93,
436,
626,
314,
5226,
1338,
787,
4472,
14,
267,
408,
267,
367,
1022,
12,
373,
315,
10026,
14,
4611,
837,
288,
291,
14,
629,
8,
409,
59,
75,
467,
373,
9,
2378,
347,
702,
2141,
2610,
2193,
8,
277,
12,
5951,
12,
30767,
304,
267,
408,
267,
2104,
1924,
4092,
402,
5226,
4008,
315,
445,
91,
2193,
93,
436,
445,
91,
23060,
1386,
267,
702,
626,
314,
1819,
687,
445,
91,
23060,
93,
365,
282,
10026,
402,
314,
1819,
687,
267,
445,
91,
2193,
5565,
267,
408,
267,
291,
14,
629,
8,
552,
8,
2193,
395,
822,
8,
23060,
430,
267,
367,
282,
12,
330,
315,
3482,
8,
2193,
12,
30767,
304,
288,
291,
14,
16443,
20113,
8,
65,
12,
330,
9,
2378,
347,
511,
63,
3592,
8,
277,
304,
267,
408,
267,
982,
949,
3598,
787,
19515,
701,
282,
511,
12,
491,
91,
1746,
14,
4939,
15921,
93,
2529,
267,
376,
2701,
769,
14,
267,
408,
267,
291,
14,
629,
8,
277,
14,
4939,
15921,
1062,
3073,
2378,
347,
511,
63,
261,
422,
279,
8,
277,
304,
267,
408,
267,
982,
9978,
3598,
787,
19515,
701,
282,
511,
12,
491,
91,
1746,
14,
4939,
15921,
93,
267,
2529,
282,
769,
3035,
1006,
402,
3062,
14,
267,
408,
267,
1642,
2209,
275,
298,
2246,
5721,
1245,
2,
267,
1642,
7841,
275,
2876,
3849,
267,
3598,
14,
4050,
8,
1188,
29,
2246,
2209,
12,
4637,
29,
2246,
7841,
9,
398,
3499,
2209,
275,
298,
4375,
5721,
1245,
2,
267,
3499,
7841,
275,
25178,
267,
3598,
14,
4050,
8,
1188,
29,
4375,
2209,
12,
4637,
29,
4375,
7841,
9,
398,
291,
14,
16443,
2610,
2193,
8,
288,
291,
14,
4939,
15921,
1062,
288,
9016,
3710,
356,
1642,
7841,
12,
283,
1188,
356,
1642,
2209,
1386,
1467,
791,
3710,
356,
3499,
7841,
12,
283,
1188,
356,
3499,
2209,
29810,
2378,
347,
511,
63,
7593,
8,
277,
304,
267,
408,
267,
710,
2011,
5721,
15572,
13373,
687,
314,
2011,
4192,
365,
5120,
13373,
267,
315,
314,
769,
2138,
701,
491,
91,
1746,
14,
4939,
15921,
5565,
267,
408,
267,
1245,
275,
298,
1589,
1245,
2,
267,
4637,
275,
25178,
267,
367,
284,
315,
1425,
8,
18,
304,
288,
3598,
14,
4050,
8,
1188,
29,
1188,
12,
4637,
29,
3710,
9,
398,
291,
14,
16443,
2610,
2193,
8,
288,
291,
14,
4939,
15921,
1062,
288,
9016,
3710,
356,
4637,
12,
283,
1188,
356,
1245,
11049,
627,
499,
9,
2378,
347,
511,
63,
2265,
2899,
8,
277,
304,
267,
408,
267,
12836,
282,
6770,
5721,
1566,
965,
2757,
2138,
701,
267,
491,
91,
1746,
14,
4939,
15921,
1386,
652,
365,
440,
2138,
701,
13372,
4882,
14,
267,
408,
267,
1245,
275,
298,
1589,
1245,
2,
267,
4637,
275,
25178,
267,
3598,
14,
4050,
8,
1188,
29,
1188,
12,
4637,
29,
3710,
9,
267,
291,
14,
16443,
2610,
2193,
8,
288,
291,
14,
4939,
15921,
1062,
288,
9016,
3710,
356,
4637,
12,
283,
1188,
356,
1245,
29810,
267,
291,
14,
629,
8,
277,
14,
4939,
15921,
1062,
3073,
2378,
347,
511,
63,
324,
4939,
379,
8,
277,
304,
267,
408,
267,
6184,
3598,
19515,
701,
282,
511,
1314,
787,
440,
8976,
379,
787,
19515,
370,
314,
267,
2018,
5721,
2656,
14,
267,
408,
267,
754,
275,
23795,
342,
267,
1930,
275,
17581,
14,
3346,
2925,
360,
396,
63,
324,
4939,
379,
358,
267,
1930,
14,
1065,
8,
1099,
9,
267,
3598,
6824,
78,
275,
291,
14,
4939,
15921,
779,
5144,
14,
3346,
2925,
14,
396,
63,
324,
4939,
379,
566,
267,
291,
14,
629,
8,
5451,
6824,
78,
59,
16,
2733,
1188,
995,
283,
3972,
5721,
1318,
358,
267,
291,
14,
479,
22469,
8,
5451,
6824,
78,
59,
16,
2733,
3710,
995,
2876,
3849,
9,
398,
2382,
275,
1930,
14,
396,
63,
324,
4939,
379,
14,
1017,
63,
1532,
14,
1532,
63,
600,
267,
1788,
275,
2382,
14,
331,
63,
1501,
267,
327,
982,
17122,
7860,
1086,
4420,
2925,
14,
396,
63,
324,
4939,
379,
12,
314,
574,
3483,
370,
267,
327,
1642,
3469,
5594,
1929,
370,
1570,
14,
267,
5874,
275,
2382,
14,
331,
63,
30114,
435,
841,
398,
291,
14,
629,
8,
5451,
6824,
78,
59,
16,
2733,
1501,
995,
1788,
9,
267,
291,
14,
629,
8,
5451,
6824
] |
[
1898,
334,
67,
9,
9079,
13,
8664,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
2925,
367,
377,
1383,
1159,
18752,
543,
314,
2018,
5721,
2656,
14,
199,
624,
199,
199,
646,
984,
12,
3598,
199,
504,
5228,
492,
5228,
199,
199,
504,
7390,
14,
1548,
14,
7218,
492,
27961,
199,
504,
7390,
14,
14443,
14,
2796,
492,
7640,
12,
485,
7112,
15921,
199,
504,
7390,
14,
14443,
14,
12222,
492,
23795,
199,
199,
533,
17581,
8,
785,
304,
272,
408,
272,
869,
2655,
282,
491,
91,
1746,
93,
5492,
687,
16324,
1159,
4834,
13172,
14729,
14,
272,
408,
272,
1021,
4420,
2925,
8,
1746,
304,
267,
408,
267,
437,
511,
1930,
1314,
365,
1202,
701,
491,
91,
20053,
15921,
2925,
93,
370,
4911,
5953,
267,
1314,
3913,
506,
16317,
701,
1233,
6272,
282,
2849,
511,
1083,
14,
267,
408,
267,
1245,
275,
298,
3972,
5721,
1318,
2,
267,
4637,
275,
2876,
3849,
398,
347,
511,
63,
324,
4939,
379,
8,
277,
304,
288,
408,
288,
7958,
282,
5721,
436,
2793,
1133,
8976,
652,
14,
288,
408,
288,
3598,
14,
4050,
8,
277,
14,
1188,
12,
291,
14,
3710,
9,
7318,
347,
511,
63,
4939,
379,
8,
277,
304,
288,
408,
288,
7958,
282,
5721,
436,
8976,
652,
14,
288,
408,
288,
3598,
14,
4050,
8,
277,
14,
1188,
12,
291,
14,
3710,
9,
288,
291,
14,
629,
8,
552,
8,
277,
14,
4939,
15921,
4000,
413,
9,
4388,
199,
533,
11040,
2084,
15921,
2925,
8,
1746,
304,
272,
408,
272,
6496,
367,
491,
91,
1746,
14,
4939,
15921,
1386,
376,
3261,
367,
15735,
7969,
314,
3598,
272,
19515,
880,
12474,
315,
282,
511,
14,
272,
408,
339,
347,
702,
2141,
20113,
8,
277,
12,
663,
12,
10026,
304,
267,
408,
267,
10716,
626,
1006,
314,
2883,
3451,
315,
445,
91,
9401,
93,
787,
2597,
3451,
315,
267,
445,
91,
409,
93,
436,
626,
314,
5226,
1338,
787,
4472,
14,
267,
408,
267,
367,
1022,
12,
373,
315,
10026,
14,
4611,
837,
288,
291,
14,
629,
8,
409,
59,
75,
467,
373,
9,
2378,
347,
702,
2141,
2610,
2193,
8,
277,
12,
5951,
12,
30767,
304,
267,
408,
267,
2104,
1924,
4092,
402,
5226,
4008,
315,
445,
91,
2193,
93,
436,
445,
91,
23060,
1386,
267,
702,
626,
314,
1819,
687,
445,
91,
23060,
93,
365,
282,
10026,
402,
314,
1819,
687,
267,
445,
91,
2193,
5565,
267,
408,
267,
291,
14,
629,
8,
552,
8,
2193,
395,
822,
8,
23060,
430,
267,
367,
282,
12,
330,
315,
3482,
8,
2193,
12,
30767,
304,
288,
291,
14,
16443,
20113,
8,
65,
12,
330,
9,
2378,
347,
511,
63,
3592,
8,
277,
304,
267,
408,
267,
982,
949,
3598,
787,
19515,
701,
282,
511,
12,
491,
91,
1746,
14,
4939,
15921,
93,
2529,
267,
376,
2701,
769,
14,
267,
408,
267,
291,
14,
629,
8,
277,
14,
4939,
15921,
1062,
3073,
2378,
347,
511,
63,
261,
422,
279,
8,
277,
304,
267,
408,
267,
982,
9978,
3598,
787,
19515,
701,
282,
511,
12,
491,
91,
1746,
14,
4939,
15921,
93,
267,
2529,
282,
769,
3035,
1006,
402,
3062,
14,
267,
408,
267,
1642,
2209,
275,
298,
2246,
5721,
1245,
2,
267,
1642,
7841,
275,
2876,
3849,
267,
3598,
14,
4050,
8,
1188,
29,
2246,
2209,
12,
4637,
29,
2246,
7841,
9,
398,
3499,
2209,
275,
298,
4375,
5721,
1245,
2,
267,
3499,
7841,
275,
25178,
267,
3598,
14,
4050,
8,
1188,
29,
4375,
2209,
12,
4637,
29,
4375,
7841,
9,
398,
291,
14,
16443,
2610,
2193,
8,
288,
291,
14,
4939,
15921,
1062,
288,
9016,
3710,
356,
1642,
7841,
12,
283,
1188,
356,
1642,
2209,
1386,
1467,
791,
3710,
356,
3499,
7841,
12,
283,
1188,
356,
3499,
2209,
29810,
2378,
347,
511,
63,
7593,
8,
277,
304,
267,
408,
267,
710,
2011,
5721,
15572,
13373,
687,
314,
2011,
4192,
365,
5120,
13373,
267,
315,
314,
769,
2138,
701,
491,
91,
1746,
14,
4939,
15921,
5565,
267,
408,
267,
1245,
275,
298,
1589,
1245,
2,
267,
4637,
275,
25178,
267,
367,
284,
315,
1425,
8,
18,
304,
288,
3598,
14,
4050,
8,
1188,
29,
1188,
12,
4637,
29,
3710,
9,
398,
291,
14,
16443,
2610,
2193,
8,
288,
291,
14,
4939,
15921,
1062,
288,
9016,
3710,
356,
4637,
12,
283,
1188,
356,
1245,
11049,
627,
499,
9,
2378,
347,
511,
63,
2265,
2899,
8,
277,
304,
267,
408,
267,
12836,
282,
6770,
5721,
1566,
965,
2757,
2138,
701,
267,
491,
91,
1746,
14,
4939,
15921,
1386,
652,
365,
440,
2138,
701,
13372,
4882,
14,
267,
408,
267,
1245,
275,
298,
1589,
1245,
2,
267,
4637,
275,
25178,
267,
3598,
14,
4050,
8,
1188,
29,
1188,
12,
4637,
29,
3710,
9,
267,
291,
14,
16443,
2610,
2193,
8,
288,
291,
14,
4939,
15921,
1062,
288,
9016,
3710,
356,
4637,
12,
283,
1188,
356,
1245,
29810,
267,
291,
14,
629,
8,
277,
14,
4939,
15921,
1062,
3073,
2378,
347,
511,
63,
324,
4939,
379,
8,
277,
304,
267,
408,
267,
6184,
3598,
19515,
701,
282,
511,
1314,
787,
440,
8976,
379,
787,
19515,
370,
314,
267,
2018,
5721,
2656,
14,
267,
408,
267,
754,
275,
23795,
342,
267,
1930,
275,
17581,
14,
3346,
2925,
360,
396,
63,
324,
4939,
379,
358,
267,
1930,
14,
1065,
8,
1099,
9,
267,
3598,
6824,
78,
275,
291,
14,
4939,
15921,
779,
5144,
14,
3346,
2925,
14,
396,
63,
324,
4939,
379,
566,
267,
291,
14,
629,
8,
5451,
6824,
78,
59,
16,
2733,
1188,
995,
283,
3972,
5721,
1318,
358,
267,
291,
14,
479,
22469,
8,
5451,
6824,
78,
59,
16,
2733,
3710,
995,
2876,
3849,
9,
398,
2382,
275,
1930,
14,
396,
63,
324,
4939,
379,
14,
1017,
63,
1532,
14,
1532,
63,
600,
267,
1788,
275,
2382,
14,
331,
63,
1501,
267,
327,
982,
17122,
7860,
1086,
4420,
2925,
14,
396,
63,
324,
4939,
379,
12,
314,
574,
3483,
370,
267,
327,
1642,
3469,
5594,
1929,
370,
1570,
14,
267,
5874,
275,
2382,
14,
331,
63,
30114,
435,
841,
398,
291,
14,
629,
8,
5451,
6824,
78,
59,
16,
2733,
1501,
995,
1788,
9,
267,
291,
14,
629,
8,
5451,
6824,
0
] |
[
1,
1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jordan/services
|
src/codecoverage/bot/code_coverage_bot/codecov.py
|
1
|
7319
|
# -*- coding: utf-8 -*-
import json
import os
import tempfile
from datetime import datetime
from datetime import timedelta
import hglib
import requests
from cli_common.log import get_logger
from cli_common.taskcluster import get_service
from cli_common.utils import ThreadPoolExecutorResult
from code_coverage_bot import chunk_mapping
from code_coverage_bot import grcov
from code_coverage_bot import suite_reports
from code_coverage_bot import taskcluster
from code_coverage_bot import uploader
from code_coverage_bot.artifacts import ArtifactsHandler
from code_coverage_bot.github import GitHubUtils
from code_coverage_bot.notifier import Notifier
from code_coverage_bot.phabricator import PhabricatorUploader
from code_coverage_bot.secrets import secrets
from code_coverage_bot.zero_coverage import ZeroCov
logger = get_logger(__name__)
class CodeCov(object):
def __init__(self, revision, cache_root, client_id, access_token):
# List of test-suite, sorted alphabetically.
# This way, the index of a suite in the array should be stable enough.
self.suites = [
'web-platform-tests',
]
self.cache_root = cache_root
assert os.path.isdir(cache_root), 'Cache root {} is not a dir.'.format(cache_root)
self.repo_dir = os.path.join(cache_root, 'mozilla-central')
temp_dir = tempfile.mkdtemp()
self.artifacts_dir = os.path.join(temp_dir, 'ccov-artifacts')
self.ccov_reports_dir = os.path.join(temp_dir, 'code-coverage-reports')
self.client_id = client_id
self.access_token = access_token
self.index_service = get_service('index', client_id, access_token)
self.githubUtils = GitHubUtils(cache_root, client_id, access_token)
if revision is None:
# Retrieve revision of latest codecov build
self.github_revision = uploader.get_latest_codecov()
self.revision = self.githubUtils.git_to_mercurial(self.github_revision)
self.from_pulse = False
else:
self.github_revision = None
self.revision = revision
self.from_pulse = True
self.notifier = Notifier(self.repo_dir, revision, client_id, access_token)
logger.info('Mercurial revision', revision=self.revision)
task_ids = {
'linux': taskcluster.get_task('mozilla-central', self.revision, 'linux'),
'windows': taskcluster.get_task('mozilla-central', self.revision, 'win'),
'android-test': taskcluster.get_task('mozilla-central', self.revision, 'android-test'),
'android-emulator': taskcluster.get_task('mozilla-central', self.revision, 'android-emulator'),
}
self.artifactsHandler = ArtifactsHandler(task_ids, self.artifacts_dir)
def clone_mozilla_central(self, revision):
shared_dir = self.repo_dir + '-shared'
cmd = hglib.util.cmdbuilder('robustcheckout',
'https://hg.mozilla.org/mozilla-central',
self.repo_dir,
purge=True,
sharebase=shared_dir,
revision=revision,
networkattempts=7)
cmd.insert(0, hglib.HGPATH)
proc = hglib.util.popen(cmd)
out, err = proc.communicate()
if proc.returncode:
raise hglib.error.CommandError(cmd, proc.returncode, out, err)
logger.info('mozilla-central cloned')
def go(self):
if self.from_pulse:
commit_sha = self.githubUtils.mercurial_to_git(self.revision)
try:
uploader.get_codecov(commit_sha)
logger.warn('Build was already injested')
return
except requests.exceptions.HTTPError:
pass
with ThreadPoolExecutorResult(max_workers=2) as executor:
# Thread 1 - Download coverage artifacts.
executor.submit(self.artifactsHandler.download_all)
# Thread 2 - Clone mozilla-central.
executor.submit(self.clone_mozilla_central, self.revision)
if self.from_pulse:
self.githubUtils.update_geckodev_repo()
logger.info('GitHub revision', revision=commit_sha)
self.githubUtils.post_github_status(commit_sha)
r = requests.get('https://hg.mozilla.org/mozilla-central/json-rev/%s' % self.revision)
r.raise_for_status()
push_id = r.json()['pushid']
output = grcov.report(
self.artifactsHandler.get(),
source_dir=self.repo_dir,
service_number=push_id,
commit_sha=commit_sha,
token=secrets[secrets.COVERALLS_TOKEN]
)
logger.info('Report generated successfully')
with ThreadPoolExecutorResult(max_workers=2) as executor:
executor.submit(uploader.coveralls, output)
executor.submit(uploader.codecov, output, commit_sha)
logger.info('Upload changeset coverage data to Phabricator')
phabricatorUploader = PhabricatorUploader(self.repo_dir, self.revision)
phabricatorUploader.upload(json.loads(output))
logger.info('Waiting for build to be ingested by Codecov...')
# Wait until the build has been ingested by Codecov.
if uploader.codecov_wait(commit_sha):
logger.info('Build ingested by codecov.io')
self.notifier.notify()
else:
logger.error('codecov.io took too much time to ingest data.')
else:
logger.info('Generating suite reports')
os.makedirs(self.ccov_reports_dir, exist_ok=True)
suite_reports.generate(self.suites, self.artifactsHandler, self.ccov_reports_dir, self.repo_dir)
logger.info('Generating zero coverage reports')
zc = ZeroCov(self.repo_dir)
zc.generate(self.artifactsHandler.get(), self.revision, self.github_revision)
logger.info('Generating chunk mapping')
chunk_mapping.generate(self.repo_dir, self.revision, self.artifactsHandler)
# Index the task in the TaskCluster index at the given revision and as "latest".
# Given that all tasks have the same rank, the latest task that finishes will
# overwrite the "latest" entry.
namespaces = [
'project.releng.services.project.{}.code_coverage_bot.{}'.format(secrets[secrets.APP_CHANNEL], self.revision),
'project.releng.services.project.{}.code_coverage_bot.latest'.format(secrets[secrets.APP_CHANNEL]),
]
for namespace in namespaces:
self.index_service.insertTask(
namespace,
{
'taskId': os.environ['TASK_ID'],
'rank': 0,
'data': {},
'expires': (datetime.utcnow() + timedelta(180)).strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
}
)
os.chdir(self.ccov_reports_dir)
self.githubUtils.update_codecoveragereports_repo()
|
mpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
2022,
199,
646,
747,
199,
646,
5549,
199,
504,
2197,
492,
2197,
199,
504,
2197,
492,
6871,
199,
199,
646,
18016,
773,
199,
646,
4145,
199,
199,
504,
5053,
63,
2330,
14,
793,
492,
664,
63,
2921,
199,
504,
5053,
63,
2330,
14,
1765,
4201,
492,
664,
63,
1364,
199,
504,
5053,
63,
2330,
14,
1208,
492,
11086,
5453,
16752,
2889,
199,
504,
1233,
63,
10828,
63,
3018,
492,
3728,
63,
4745,
199,
504,
1233,
63,
10828,
63,
3018,
492,
7192,
8695,
199,
504,
1233,
63,
10828,
63,
3018,
492,
5241,
63,
15629,
199,
504,
1233,
63,
10828,
63,
3018,
492,
2120,
4201,
199,
504,
1233,
63,
10828,
63,
3018,
492,
25257,
199,
504,
1233,
63,
10828,
63,
3018,
14,
30129,
492,
1952,
17530,
2461,
199,
504,
1233,
63,
10828,
63,
3018,
14,
5031,
492,
25141,
7535,
199,
504,
1233,
63,
10828,
63,
3018,
14,
18031,
492,
3091,
11612,
199,
504,
1233,
63,
10828,
63,
3018,
14,
838,
2129,
707,
492,
11308,
2129,
707,
1721,
3422,
199,
504,
1233,
63,
10828,
63,
3018,
14,
16153,
492,
25563,
199,
504,
1233,
63,
10828,
63,
3018,
14,
4262,
63,
10828,
492,
15708,
967,
86,
199,
199,
2921,
275,
664,
63,
2921,
3460,
354,
3368,
421,
199,
533,
5495,
967,
86,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
6974,
12,
2581,
63,
1231,
12,
1890,
63,
344,
12,
2879,
63,
1418,
304,
267,
327,
3820,
402,
511,
13,
5768,
12,
3355,
23331,
17269,
14,
267,
327,
961,
4340,
12,
314,
1478,
402,
282,
5241,
315,
314,
1625,
1077,
506,
17830,
8321,
14,
267,
291,
14,
27034,
275,
359,
288,
283,
2520,
13,
3246,
13,
2219,
297,
267,
1622,
398,
291,
14,
1637,
63,
1231,
275,
2581,
63,
1231,
398,
702,
747,
14,
515,
14,
6027,
8,
1637,
63,
1231,
395,
283,
4437,
1738,
1052,
365,
440,
282,
2935,
17374,
908,
8,
1637,
63,
1231,
9,
267,
291,
14,
3417,
63,
694,
275,
747,
14,
515,
14,
904,
8,
1637,
63,
1231,
12,
283,
12102,
13,
16067,
358,
267,
2388,
63,
694,
275,
5549,
14,
11983,
342,
267,
291,
14,
30129,
63,
694,
275,
747,
14,
515,
14,
904,
8,
808,
63,
694,
12,
283,
67,
8695,
13,
30129,
358,
267,
291,
14,
67,
8695,
63,
15629,
63,
694,
275,
747,
14,
515,
14,
904,
8,
808,
63,
694,
12,
283,
600,
13,
10828,
13,
15629,
358,
398,
291,
14,
1258,
63,
344,
275,
1890,
63,
344,
267,
291,
14,
2732,
63,
1418,
275,
2879,
63,
1418,
398,
291,
14,
1080,
63,
1364,
275,
664,
63,
1364,
360,
1080,
297,
1890,
63,
344,
12,
2879,
63,
1418,
9,
398,
291,
14,
5031,
7535,
275,
25141,
7535,
8,
1637,
63,
1231,
12,
1890,
63,
344,
12,
2879,
63,
1418,
9,
398,
340,
6974,
365,
488,
26,
288,
327,
13939,
6974,
402,
8839,
1233,
8695,
1900,
288,
291,
14,
5031,
63,
5792,
275,
25257,
14,
362,
63,
7410,
63,
600,
8695,
342,
288,
291,
14,
5792,
275,
291,
14,
5031,
7535,
14,
3187,
63,
475,
63,
2626,
18977,
8,
277,
14,
5031,
63,
5792,
9,
288,
291,
14,
504,
63,
19538,
275,
756,
267,
587,
26,
288,
291,
14,
5031,
63,
5792,
275,
488,
288,
291,
14,
5792,
275,
6974,
288,
291,
14,
504,
63,
19538,
275,
715,
288,
291,
14,
18031,
275,
3091,
11612,
8,
277,
14,
3417,
63,
694,
12,
6974,
12,
1890,
63,
344,
12,
2879,
63,
1418,
9,
398,
2512,
14,
815,
360,
16797,
18977,
6974,
297,
6974,
29,
277,
14,
5792,
9,
398,
2120,
63,
1580,
275,
469,
288,
283,
5135,
356,
2120,
4201,
14,
362,
63,
1765,
360,
12102,
13,
16067,
297,
291,
14,
5792,
12,
283,
5135,
659,
288,
283,
8258,
356,
2120,
4201,
14,
362,
63,
1765,
360,
12102,
13,
16067,
297,
291,
14,
5792,
12,
283,
2676,
659,
288,
283,
6238,
13,
396,
356,
2120,
4201,
14,
362,
63,
1765,
360,
12102,
13,
16067,
297,
291,
14,
5792,
12,
283,
6238,
13,
396,
659,
288,
283,
6238,
13,
29809,
707,
356,
2120,
4201,
14,
362,
63,
1765,
360,
12102,
13,
16067,
297,
291,
14,
5792,
12,
283,
6238,
13,
29809,
707,
659,
267,
789,
398,
291,
14,
30129,
2461,
275,
1952,
17530,
2461,
8,
1765,
63,
1580,
12,
291,
14,
30129,
63,
694,
9,
339,
347,
7289,
63,
12102,
63,
16067,
8,
277,
12,
6974,
304,
267,
5709,
63,
694,
275,
291,
14,
3417,
63,
694,
435,
2475,
5555,
7,
267,
2088,
275,
18016,
773,
14,
1974,
14,
1760,
5649,
360,
293,
15549,
12891,
297,
2511,
283,
2859,
921,
9208,
14,
12102,
14,
1308,
15,
12102,
13,
16067,
297,
2511,
291,
14,
3417,
63,
694,
12,
2511,
18503,
29,
549,
12,
2511,
8663,
1095,
29,
5555,
63,
694,
12,
2511,
6974,
29,
5792,
12,
2511,
2784,
13143,
29,
23,
9,
398,
2088,
14,
3176,
8,
16,
12,
18016,
773,
14,
31442,
3243,
9,
398,
6499,
275,
18016,
773,
14,
1974,
14,
12207,
8,
1760,
9,
267,
734,
12,
2329,
275,
6499,
14,
10664,
342,
267,
340,
6499,
14,
9913,
26,
288,
746,
18016,
773,
14,
705,
14,
31542,
8,
1760,
12,
6499,
14,
9913,
12,
734,
12,
2329,
9,
398,
2512,
14,
815,
360,
12102,
13,
16067,
26210,
358,
339,
347,
2621,
8,
277,
304,
267,
340,
291,
14,
504,
63,
19538,
26,
288,
5532,
63,
4835,
275,
291,
14,
5031,
7535,
14,
2626,
18977,
63,
475,
63,
3187,
8,
277,
14,
5792,
9,
288,
862,
26,
355,
25257,
14,
362,
63,
600,
8695,
8,
3543,
63,
4835,
9,
355,
2512,
14,
4050,
360,
3425,
1990,
2575,
315,
74,
3505,
358,
355,
372,
288,
871,
4145,
14,
3924,
14,
12815,
26,
355,
986,
398,
543,
11086,
5453,
16752,
2889,
8,
988,
63,
11009,
29,
18,
9,
465,
13270,
26,
288,
327,
11086,
413,
446,
17955,
11745,
27990,
14,
288,
13270,
14,
7275,
8,
277,
14,
30129,
2461,
14,
4249,
63,
452,
9,
953,
327,
11086,
499,
446,
8465,
368,
1303,
6956,
13,
16067,
14,
288,
13270,
14,
7275,
8,
277,
14,
6311,
63,
12102,
63,
16067,
12,
291,
14,
5792,
9,
398,
340,
291,
14,
504,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
2022,
199,
646,
747,
199,
646,
5549,
199,
504,
2197,
492,
2197,
199,
504,
2197,
492,
6871,
199,
199,
646,
18016,
773,
199,
646,
4145,
199,
199,
504,
5053,
63,
2330,
14,
793,
492,
664,
63,
2921,
199,
504,
5053,
63,
2330,
14,
1765,
4201,
492,
664,
63,
1364,
199,
504,
5053,
63,
2330,
14,
1208,
492,
11086,
5453,
16752,
2889,
199,
504,
1233,
63,
10828,
63,
3018,
492,
3728,
63,
4745,
199,
504,
1233,
63,
10828,
63,
3018,
492,
7192,
8695,
199,
504,
1233,
63,
10828,
63,
3018,
492,
5241,
63,
15629,
199,
504,
1233,
63,
10828,
63,
3018,
492,
2120,
4201,
199,
504,
1233,
63,
10828,
63,
3018,
492,
25257,
199,
504,
1233,
63,
10828,
63,
3018,
14,
30129,
492,
1952,
17530,
2461,
199,
504,
1233,
63,
10828,
63,
3018,
14,
5031,
492,
25141,
7535,
199,
504,
1233,
63,
10828,
63,
3018,
14,
18031,
492,
3091,
11612,
199,
504,
1233,
63,
10828,
63,
3018,
14,
838,
2129,
707,
492,
11308,
2129,
707,
1721,
3422,
199,
504,
1233,
63,
10828,
63,
3018,
14,
16153,
492,
25563,
199,
504,
1233,
63,
10828,
63,
3018,
14,
4262,
63,
10828,
492,
15708,
967,
86,
199,
199,
2921,
275,
664,
63,
2921,
3460,
354,
3368,
421,
199,
533,
5495,
967,
86,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
6974,
12,
2581,
63,
1231,
12,
1890,
63,
344,
12,
2879,
63,
1418,
304,
267,
327,
3820,
402,
511,
13,
5768,
12,
3355,
23331,
17269,
14,
267,
327,
961,
4340,
12,
314,
1478,
402,
282,
5241,
315,
314,
1625,
1077,
506,
17830,
8321,
14,
267,
291,
14,
27034,
275,
359,
288,
283,
2520,
13,
3246,
13,
2219,
297,
267,
1622,
398,
291,
14,
1637,
63,
1231,
275,
2581,
63,
1231,
398,
702,
747,
14,
515,
14,
6027,
8,
1637,
63,
1231,
395,
283,
4437,
1738,
1052,
365,
440,
282,
2935,
17374,
908,
8,
1637,
63,
1231,
9,
267,
291,
14,
3417,
63,
694,
275,
747,
14,
515,
14,
904,
8,
1637,
63,
1231,
12,
283,
12102,
13,
16067,
358,
267,
2388,
63,
694,
275,
5549,
14,
11983,
342,
267,
291,
14,
30129,
63,
694,
275,
747,
14,
515,
14,
904,
8,
808,
63,
694,
12,
283,
67,
8695,
13,
30129,
358,
267,
291,
14,
67,
8695,
63,
15629,
63,
694,
275,
747,
14,
515,
14,
904,
8,
808,
63,
694,
12,
283,
600,
13,
10828,
13,
15629,
358,
398,
291,
14,
1258,
63,
344,
275,
1890,
63,
344,
267,
291,
14,
2732,
63,
1418,
275,
2879,
63,
1418,
398,
291,
14,
1080,
63,
1364,
275,
664,
63,
1364,
360,
1080,
297,
1890,
63,
344,
12,
2879,
63,
1418,
9,
398,
291,
14,
5031,
7535,
275,
25141,
7535,
8,
1637,
63,
1231,
12,
1890,
63,
344,
12,
2879,
63,
1418,
9,
398,
340,
6974,
365,
488,
26,
288,
327,
13939,
6974,
402,
8839,
1233,
8695,
1900,
288,
291,
14,
5031,
63,
5792,
275,
25257,
14,
362,
63,
7410,
63,
600,
8695,
342,
288,
291,
14,
5792,
275,
291,
14,
5031,
7535,
14,
3187,
63,
475,
63,
2626,
18977,
8,
277,
14,
5031,
63,
5792,
9,
288,
291,
14,
504,
63,
19538,
275,
756,
267,
587,
26,
288,
291,
14,
5031,
63,
5792,
275,
488,
288,
291,
14,
5792,
275,
6974,
288,
291,
14,
504,
63,
19538,
275,
715,
288,
291,
14,
18031,
275,
3091,
11612,
8,
277,
14,
3417,
63,
694,
12,
6974,
12,
1890,
63,
344,
12,
2879,
63,
1418,
9,
398,
2512,
14,
815,
360,
16797,
18977,
6974,
297,
6974,
29,
277,
14,
5792,
9,
398,
2120,
63,
1580,
275,
469,
288,
283,
5135,
356,
2120,
4201,
14,
362,
63,
1765,
360,
12102,
13,
16067,
297,
291,
14,
5792,
12,
283,
5135,
659,
288,
283,
8258,
356,
2120,
4201,
14,
362,
63,
1765,
360,
12102,
13,
16067,
297,
291,
14,
5792,
12,
283,
2676,
659,
288,
283,
6238,
13,
396,
356,
2120,
4201,
14,
362,
63,
1765,
360,
12102,
13,
16067,
297,
291,
14,
5792,
12,
283,
6238,
13,
396,
659,
288,
283,
6238,
13,
29809,
707,
356,
2120,
4201,
14,
362,
63,
1765,
360,
12102,
13,
16067,
297,
291,
14,
5792,
12,
283,
6238,
13,
29809,
707,
659,
267,
789,
398,
291,
14,
30129,
2461,
275,
1952,
17530,
2461,
8,
1765,
63,
1580,
12,
291,
14,
30129,
63,
694,
9,
339,
347,
7289,
63,
12102,
63,
16067,
8,
277,
12,
6974,
304,
267,
5709,
63,
694,
275,
291,
14,
3417,
63,
694,
435,
2475,
5555,
7,
267,
2088,
275,
18016,
773,
14,
1974,
14,
1760,
5649,
360,
293,
15549,
12891,
297,
2511,
283,
2859,
921,
9208,
14,
12102,
14,
1308,
15,
12102,
13,
16067,
297,
2511,
291,
14,
3417,
63,
694,
12,
2511,
18503,
29,
549,
12,
2511,
8663,
1095,
29,
5555,
63,
694,
12,
2511,
6974,
29,
5792,
12,
2511,
2784,
13143,
29,
23,
9,
398,
2088,
14,
3176,
8,
16,
12,
18016,
773,
14,
31442,
3243,
9,
398,
6499,
275,
18016,
773,
14,
1974,
14,
12207,
8,
1760,
9,
267,
734,
12,
2329,
275,
6499,
14,
10664,
342,
267,
340,
6499,
14,
9913,
26,
288,
746,
18016,
773,
14,
705,
14,
31542,
8,
1760,
12,
6499,
14,
9913,
12,
734,
12,
2329,
9,
398,
2512,
14,
815,
360,
12102,
13,
16067,
26210,
358,
339,
347,
2621,
8,
277,
304,
267,
340,
291,
14,
504,
63,
19538,
26,
288,
5532,
63,
4835,
275,
291,
14,
5031,
7535,
14,
2626,
18977,
63,
475,
63,
3187,
8,
277,
14,
5792,
9,
288,
862,
26,
355,
25257,
14,
362,
63,
600,
8695,
8,
3543,
63,
4835,
9,
355,
2512,
14,
4050,
360,
3425,
1990,
2575,
315,
74,
3505,
358,
355,
372,
288,
871,
4145,
14,
3924,
14,
12815,
26,
355,
986,
398,
543,
11086,
5453,
16752,
2889,
8,
988,
63,
11009,
29,
18,
9,
465,
13270,
26,
288,
327,
11086,
413,
446,
17955,
11745,
27990,
14,
288,
13270,
14,
7275,
8,
277,
14,
30129,
2461,
14,
4249,
63,
452,
9,
953,
327,
11086,
499,
446,
8465,
368,
1303,
6956,
13,
16067,
14,
288,
13270,
14,
7275,
8,
277,
14,
6311,
63,
12102,
63,
16067,
12,
291,
14,
5792,
9,
398,
340,
291,
14,
504,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mediatum/mediatum
|
utils/hash.py
|
1
|
1599
|
"""
mediatum - a multimedia content repository
Copyright (C) 2007 Arne Seifert <seiferta@in.tum.de>
Copyright (C) 2007 Matthias Kramm <kramm@in.tum.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import logging
import os
import hashlib
from core import db
q = db.query
logg = logging.getLogger(__name__)
def calcChecksum(filename, method):
if os.path.exists(filename):
f = open(filename)
if method == "SHA-1":
h = hashlib.sha1()
else:
h = hashlib.new('ripemd160')
h.update(f.read())
f.close()
return h.hexdigest()
else:
return ""
def calcChecksumFromMetadata(node):
h = hashlib.sha1()
h.update(str(node.id)) # h.update requires string or buffer as argument
h.update(node.getName())
def attributesToString(node):
string = ""
for item in node.attrs.items():
string += item[0] + item[1]
return string
h.update(attributesToString(node))
return h.hexdigest()
|
gpl-3.0
|
[
624,
199,
25796,
5729,
446,
282,
19207,
521,
2391,
1564,
7611,
421,
1898,
334,
35,
9,
10219,
1952,
685,
3240,
692,
15299,
665,
261,
692,
281,
502,
32,
262,
14,
84,
453,
14,
271,
30,
199,
1898,
334,
35,
9,
10219,
18619,
273,
2241,
1804,
345,
596,
665,
75,
345,
596,
32,
262,
14,
84,
453,
14,
271,
30,
421,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
421,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
421,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
624,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
8337,
199,
504,
6170,
492,
1592,
199,
199,
81,
275,
1592,
14,
1131,
199,
793,
71,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
12831,
17394,
8,
1501,
12,
1083,
304,
272,
340,
747,
14,
515,
14,
2444,
8,
1501,
304,
267,
289,
275,
1551,
8,
1501,
9,
267,
340,
1083,
508,
298,
8461,
13,
17,
582,
288,
394,
275,
8337,
14,
4835,
17,
342,
267,
587,
26,
288,
394,
275,
8337,
14,
1222,
360,
322,
321,
1064,
8488,
358,
267,
394,
14,
873,
8,
70,
14,
739,
1012,
267,
289,
14,
1600,
342,
267,
372,
394,
14,
11453,
342,
272,
587,
26,
267,
372,
3087,
421,
199,
318,
12831,
17394,
2532,
5142,
8,
932,
304,
272,
394,
275,
8337,
14,
4835,
17,
342,
272,
394,
14,
873,
8,
495,
8,
932,
14,
344,
430,
221,
327,
394,
14,
873,
5074,
1059,
503,
3335,
465,
1423,
272,
394,
14,
873,
8,
932,
14,
16405,
1012,
339,
347,
3004,
7756,
8,
932,
304,
267,
1059,
275,
3087,
267,
367,
1242,
315,
1031,
14,
3288,
14,
1744,
837,
288,
1059,
847,
1242,
59,
16,
61,
435,
1242,
59,
17,
61,
267,
372,
1059,
339,
394,
14,
873,
8,
2987,
7756,
8,
932,
430,
339,
372,
394,
14,
11453,
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
] |
[
199,
25796,
5729,
446,
282,
19207,
521,
2391,
1564,
7611,
421,
1898,
334,
35,
9,
10219,
1952,
685,
3240,
692,
15299,
665,
261,
692,
281,
502,
32,
262,
14,
84,
453,
14,
271,
30,
199,
1898,
334,
35,
9,
10219,
18619,
273,
2241,
1804,
345,
596,
665,
75,
345,
596,
32,
262,
14,
84,
453,
14,
271,
30,
421,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
421,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
421,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
624,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
8337,
199,
504,
6170,
492,
1592,
199,
199,
81,
275,
1592,
14,
1131,
199,
793,
71,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
12831,
17394,
8,
1501,
12,
1083,
304,
272,
340,
747,
14,
515,
14,
2444,
8,
1501,
304,
267,
289,
275,
1551,
8,
1501,
9,
267,
340,
1083,
508,
298,
8461,
13,
17,
582,
288,
394,
275,
8337,
14,
4835,
17,
342,
267,
587,
26,
288,
394,
275,
8337,
14,
1222,
360,
322,
321,
1064,
8488,
358,
267,
394,
14,
873,
8,
70,
14,
739,
1012,
267,
289,
14,
1600,
342,
267,
372,
394,
14,
11453,
342,
272,
587,
26,
267,
372,
3087,
421,
199,
318,
12831,
17394,
2532,
5142,
8,
932,
304,
272,
394,
275,
8337,
14,
4835,
17,
342,
272,
394,
14,
873,
8,
495,
8,
932,
14,
344,
430,
221,
327,
394,
14,
873,
5074,
1059,
503,
3335,
465,
1423,
272,
394,
14,
873,
8,
932,
14,
16405,
1012,
339,
347,
3004,
7756,
8,
932,
304,
267,
1059,
275,
3087,
267,
367,
1242,
315,
1031,
14,
3288,
14,
1744,
837,
288,
1059,
847,
1242,
59,
16,
61,
435,
1242,
59,
17,
61,
267,
372,
1059,
339,
394,
14,
873,
8,
2987,
7756,
8,
932,
430,
339,
372,
394,
14,
11453,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
antepsis/anteplahmacun
|
sympy/functions/special/tests/test_zeta_functions.py
|
29
|
6569
|
from sympy import (Symbol, zeta, nan, Rational, Float, pi, dirichlet_eta, log,
zoo, expand_func, polylog, lerchphi, S, exp, sqrt, I,
exp_polar, polar_lift, O, stieltjes)
from sympy.utilities.randtest import (test_derivative_numerically as td,
random_complex_number as randcplx, verify_numerically as tn)
x = Symbol('x')
a = Symbol('a')
b = Symbol('b', negative=True)
z = Symbol('z')
s = Symbol('s')
def test_zeta_eval():
assert zeta(nan) == nan
assert zeta(x, nan) == nan
assert zeta(0) == Rational(-1, 2)
assert zeta(0, x) == Rational(1, 2) - x
assert zeta(0, b) == Rational(1, 2) - b
assert zeta(1) == zoo
assert zeta(1, 2) == zoo
assert zeta(1, -7) == zoo
assert zeta(1, x) == zoo
assert zeta(2, 1) == pi**2/6
assert zeta(2) == pi**2/6
assert zeta(4) == pi**4/90
assert zeta(6) == pi**6/945
assert zeta(2, 2) == pi**2/6 - 1
assert zeta(4, 3) == pi**4/90 - Rational(17, 16)
assert zeta(6, 4) == pi**6/945 - Rational(47449, 46656)
assert zeta(2, -2) == pi**2/6 + Rational(5, 4)
assert zeta(4, -3) == pi**4/90 + Rational(1393, 1296)
assert zeta(6, -4) == pi**6/945 + Rational(3037465, 2985984)
assert zeta(-1) == -Rational(1, 12)
assert zeta(-2) == 0
assert zeta(-3) == Rational(1, 120)
assert zeta(-4) == 0
assert zeta(-5) == -Rational(1, 252)
assert zeta(-1, 3) == -Rational(37, 12)
assert zeta(-1, 7) == -Rational(253, 12)
assert zeta(-1, -4) == Rational(119, 12)
assert zeta(-1, -9) == Rational(539, 12)
assert zeta(-4, 3) == -17
assert zeta(-4, -8) == 8772
assert zeta(0, 1) == -Rational(1, 2)
assert zeta(0, -1) == Rational(3, 2)
assert zeta(0, 2) == -Rational(3, 2)
assert zeta(0, -2) == Rational(5, 2)
assert zeta(
3).evalf(20).epsilon_eq(Float("1.2020569031595942854", 20), 1e-19)
def test_zeta_series():
assert zeta(x, a).series(a, 0, 2) == \
zeta(x, 0) - x*a*zeta(x + 1, 0) + O(a**2)
def test_dirichlet_eta_eval():
assert dirichlet_eta(0) == Rational(1, 2)
assert dirichlet_eta(-1) == Rational(1, 4)
assert dirichlet_eta(1) == log(2)
assert dirichlet_eta(2) == pi**2/12
assert dirichlet_eta(4) == pi**4*Rational(7, 720)
def test_rewriting():
assert dirichlet_eta(x).rewrite(zeta) == (1 - 2**(1 - x))*zeta(x)
assert zeta(x).rewrite(dirichlet_eta) == dirichlet_eta(x)/(1 - 2**(1 - x))
assert tn(dirichlet_eta(x), dirichlet_eta(x).rewrite(zeta), x)
assert tn(zeta(x), zeta(x).rewrite(dirichlet_eta), x)
assert zeta(x, a).rewrite(lerchphi) == lerchphi(1, x, a)
assert polylog(s, z).rewrite(lerchphi) == lerchphi(z, s, 1)*z
assert lerchphi(1, x, a).rewrite(zeta) == zeta(x, a)
assert z*lerchphi(z, s, 1).rewrite(polylog) == polylog(s, z)
def test_derivatives():
from sympy import Derivative
assert zeta(x, a).diff(x) == Derivative(zeta(x, a), x)
assert zeta(x, a).diff(a) == -x*zeta(x + 1, a)
assert lerchphi(
z, s, a).diff(z) == (lerchphi(z, s - 1, a) - a*lerchphi(z, s, a))/z
assert lerchphi(z, s, a).diff(a) == -s*lerchphi(z, s + 1, a)
assert polylog(s, z).diff(z) == polylog(s - 1, z)/z
b = randcplx()
c = randcplx()
assert td(zeta(b, x), x)
assert td(polylog(b, z), z)
assert td(lerchphi(c, b, x), x)
assert td(lerchphi(x, b, c), x)
def myexpand(func, target):
expanded = expand_func(func)
if target is not None:
return expanded == target
if expanded == func: # it didn't expand
return False
# check to see that the expanded and original evaluate to the same value
subs = {}
for a in func.free_symbols:
subs[a] = randcplx()
return abs(func.subs(subs).n()
- expanded.replace(exp_polar, exp).subs(subs).n()) < 1e-10
def test_polylog_expansion():
from sympy import log
assert polylog(s, 0) == 0
assert polylog(s, 1) == zeta(s)
assert polylog(s, -1) == -dirichlet_eta(s)
assert myexpand(polylog(1, z), -log(1 + exp_polar(-I*pi)*z))
assert myexpand(polylog(0, z), z/(1 - z))
assert myexpand(polylog(-1, z), z**2/(1 - z)**2 + z/(1 - z))
assert myexpand(polylog(-5, z), None)
def test_lerchphi_expansion():
assert myexpand(lerchphi(1, s, a), zeta(s, a))
assert myexpand(lerchphi(z, s, 1), polylog(s, z)/z)
# direct summation
assert myexpand(lerchphi(z, -1, a), a/(1 - z) + z/(1 - z)**2)
assert myexpand(lerchphi(z, -3, a), None)
# polylog reduction
assert myexpand(lerchphi(z, s, S(1)/2),
2**(s - 1)*(polylog(s, sqrt(z))/sqrt(z)
- polylog(s, polar_lift(-1)*sqrt(z))/sqrt(z)))
assert myexpand(lerchphi(z, s, 2), -1/z + polylog(s, z)/z**2)
assert myexpand(lerchphi(z, s, S(3)/2), None)
assert myexpand(lerchphi(z, s, S(7)/3), None)
assert myexpand(lerchphi(z, s, -S(1)/3), None)
assert myexpand(lerchphi(z, s, -S(5)/2), None)
# hurwitz zeta reduction
assert myexpand(lerchphi(-1, s, a),
2**(-s)*zeta(s, a/2) - 2**(-s)*zeta(s, (a + 1)/2))
assert myexpand(lerchphi(I, s, a), None)
assert myexpand(lerchphi(-I, s, a), None)
assert myexpand(lerchphi(exp(2*I*pi/5), s, a), None)
def test_stieltjes():
assert isinstance(stieltjes(x), stieltjes)
assert isinstance(stieltjes(x, a), stieltjes)
# Zero'th constant EulerGamma
assert stieltjes(0) == S.EulerGamma
assert stieltjes(0, 1) == S.EulerGamma
# Not defined
assert stieltjes(nan) == nan
assert stieltjes(0, nan) == nan
assert stieltjes(-1) == S.ComplexInfinity
assert stieltjes(1.5) == S.ComplexInfinity
assert stieltjes(z, 0) == S.ComplexInfinity
assert stieltjes(z, -1) == S.ComplexInfinity
def test_stieltjes_evalf():
assert abs(stieltjes(0).evalf() - 0.577215664) < 1E-9
assert abs(stieltjes(0, 0.5).evalf() - 1.963510026) < 1E-9
assert abs(stieltjes(1, 2).evalf() + 0.072815845 ) < 1E-9
def test_issue_10475():
a = Symbol('a', real=True)
b = Symbol('b', positive=True)
s = Symbol('s', zero=False)
assert zeta(2 + I).is_finite
assert zeta(1).is_finite is False
assert zeta(x).is_finite is None
assert zeta(x + I).is_finite is None
assert zeta(a).is_finite is None
assert zeta(b).is_finite is None
assert zeta(-b).is_finite is True
assert zeta(b**2 - 2*b + 1).is_finite is None
assert zeta(a + I).is_finite is True
assert zeta(b + 1).is_finite is True
assert zeta(s + 1).is_finite is True
|
bsd-3-clause
|
[
504,
5840,
492,
334,
8169,
12,
1315,
1841,
12,
12055,
12,
20164,
12,
11140,
12,
6682,
12,
487,
19683,
63,
1841,
12,
943,
12,
673,
1315,
1534,
12,
6544,
63,
1532,
12,
8446,
793,
12,
1026,
82,
335,
10909,
12,
428,
12,
1437,
12,
7452,
12,
473,
12,
673,
1437,
63,
19830,
12,
29167,
63,
30133,
12,
593,
12,
410,
14769,
84,
74,
397,
9,
199,
504,
5840,
14,
16355,
14,
3759,
396,
492,
334,
396,
63,
26851,
63,
6677,
1183,
465,
12749,
12,
1993,
2196,
63,
5254,
63,
1955,
465,
10261,
67,
1168,
88,
12,
4911,
63,
6677,
1183,
465,
22762,
9,
199,
199,
88,
275,
10080,
360,
88,
358,
199,
65,
275,
10080,
360,
65,
358,
199,
66,
275,
10080,
360,
66,
297,
6946,
29,
549,
9,
199,
90,
275,
10080,
360,
90,
358,
199,
83,
275,
10080,
360,
83,
358,
421,
199,
318,
511,
63,
90,
1841,
63,
2579,
837,
339,
702,
1315,
1841,
8,
4304,
9,
508,
12055,
272,
702,
1315,
1841,
8,
88,
12,
12055,
9,
508,
12055,
339,
702,
1315,
1841,
8,
16,
9,
508,
20164,
2801,
17,
12,
499,
9,
272,
702,
1315,
1841,
8,
16,
12,
671,
9,
508,
20164,
8,
17,
12,
499,
9,
446,
671,
272,
702,
1315,
1841,
8,
16,
12,
330,
9,
508,
20164,
8,
17,
12,
499,
9,
446,
330,
339,
702,
1315,
1841,
8,
17,
9,
508,
1315,
1534,
272,
702,
1315,
1841,
8,
17,
12,
499,
9,
508,
1315,
1534,
272,
702,
1315,
1841,
8,
17,
12,
446,
23,
9,
508,
1315,
1534,
272,
702,
1315,
1841,
8,
17,
12,
671,
9,
508,
1315,
1534,
339,
702,
1315,
1841,
8,
18,
12,
413,
9,
508,
6682,
538,
18,
15,
22,
339,
702,
1315,
1841,
8,
18,
9,
508,
6682,
538,
18,
15,
22,
272,
702,
1315,
1841,
8,
20,
9,
508,
6682,
538,
20,
15,
2710,
272,
702,
1315,
1841,
8,
22,
9,
508,
6682,
538,
22,
15,
25,
2322,
339,
702,
1315,
1841,
8,
18,
12,
499,
9,
508,
6682,
538,
18,
15,
22,
446,
413,
272,
702,
1315,
1841,
8,
20,
12,
650,
9,
508,
6682,
538,
20,
15,
2710,
446,
20164,
8,
1196,
12,
3193,
9,
272,
702,
1315,
1841,
8,
22,
12,
841,
9,
508,
6682,
538,
22,
15,
25,
2322,
446,
20164,
8,
13818,
1887,
12,
841,
1272,
1367,
9,
339,
702,
1315,
1841,
8,
18,
12,
446,
18,
9,
508,
6682,
538,
18,
15,
22,
435,
20164,
8,
21,
12,
841,
9,
272,
702,
1315,
1841,
8,
20,
12,
446,
19,
9,
508,
6682,
538,
20,
15,
2710,
435,
20164,
8,
969,
3129,
12,
413,
11700,
9,
272,
702,
1315,
1841,
8,
22,
12,
446,
20,
9,
508,
6682,
538,
22,
15,
25,
2322,
435,
20164,
8,
1216,
9880,
2182,
12,
499,
2905,
1427,
1349,
9,
339,
702,
1315,
1841,
2801,
17,
9,
508,
446,
20248,
8,
17,
12,
3144,
9,
272,
702,
1315,
1841,
2801,
18,
9,
508,
378,
272,
702,
1315,
1841,
2801,
19,
9,
508,
20164,
8,
17,
12,
13960,
9,
272,
702,
1315,
1841,
2801,
20,
9,
508,
378,
272,
702,
1315,
1841,
2801,
21,
9,
508,
446,
20248,
8,
17,
12,
27210,
9,
339,
702,
1315,
1841,
2801,
17,
12,
650,
9,
508,
446,
20248,
8,
1401,
12,
3144,
9,
272,
702,
1315,
1841,
2801,
17,
12,
1520,
9,
508,
446,
20248,
8,
3781,
12,
3144,
9,
272,
702,
1315,
1841,
2801,
17,
12,
446,
20,
9,
508,
20164,
8,
7119,
12,
3144,
9,
272,
702,
1315,
1841,
2801,
17,
12,
446,
25,
9,
508,
20164,
8,
25391,
12,
3144,
9,
339,
702,
1315,
1841,
2801,
20,
12,
650,
9,
508,
446,
1196,
272,
702,
1315,
1841,
2801,
20,
12,
446,
24,
9,
508,
1695,
19518,
339,
702,
1315,
1841,
8,
16,
12,
413,
9,
508,
446,
20248,
8,
17,
12,
499,
9,
272,
702,
1315,
1841,
8,
16,
12,
446,
17,
9,
508,
20164,
8,
19,
12,
499,
9,
339,
702,
1315,
1841,
8,
16,
12,
499,
9,
508,
446,
20248,
8,
19,
12,
499,
9,
272,
702,
1315,
1841,
8,
16,
12,
446,
18,
9,
508,
20164,
8,
21,
12,
499,
9,
339,
702,
1315,
1841,
8,
267,
650,
680,
26782,
276,
8,
1165,
680,
15761,
63,
4077,
8,
5136,
480,
17,
14,
13934,
15143,
1644,
9327,
15667,
1651,
1477,
401,
3388,
395,
413,
69,
13,
1167,
9,
421,
199,
318,
511,
63,
90,
1841,
63,
5602,
837,
272,
702,
1315,
1841,
8,
88,
12,
282,
680,
5602,
8,
65,
12,
378,
12,
499,
9,
508,
971,
267,
1315,
1841,
8,
88,
12,
378,
9,
446,
671,
10,
65,
10,
90,
1841,
8,
88,
435,
413,
12,
378,
9,
435,
593,
8,
65,
538,
18,
9,
421,
199,
318,
511,
63,
328,
19683,
63,
1841,
63,
2579,
837,
339,
702,
487,
19683,
63,
1841,
8,
16,
9,
508,
20164,
8,
17,
12,
499,
9,
272,
702,
487,
19683,
63,
1841,
2801,
17,
9,
508,
20164,
8,
17,
12,
841,
9,
272,
702,
487,
19683,
63,
1841,
8,
17,
9,
508,
943,
8,
18,
9,
272,
702,
487,
19683,
63,
1841,
8,
18,
9,
508,
6682,
538,
18,
15,
713,
272,
702,
487,
19683,
63,
1841,
8,
20,
9,
508,
6682,
538,
20,
10,
20248,
8,
23,
12,
29692,
9,
421,
199,
318,
511,
63,
264,
14827,
837,
272,
702,
487,
19683,
63,
1841,
8,
88,
680,
14366,
8,
90,
1841,
9,
508,
334,
17,
446,
499,
14192,
17,
446,
671,
19198,
90,
1841,
8,
88,
9,
272,
702,
1315,
1841,
8,
88,
680,
14366,
8,
328,
19683,
63,
1841,
9,
508,
487,
19683,
63,
1841,
8,
88,
15136,
17,
446,
499,
14192,
17,
446,
671,
430,
272,
702,
22762,
8,
328,
19683,
63,
1841,
8,
88,
395,
487,
19683,
63,
1841,
8,
88,
680,
14366,
8,
90,
1841,
395,
671,
9,
272,
702,
22762,
8,
90,
1841,
8,
88,
395,
1315,
1841,
8,
88,
680,
14366,
8,
328,
19683,
63,
1841,
395,
671,
9,
339,
702,
1315,
1841,
8,
88,
12,
282,
680,
14366,
8,
1435,
335,
10909,
9,
508,
1026,
82,
335,
10909,
8,
17,
12,
671,
12,
282,
9,
272,
702,
8446,
793,
8
] |
[
5840,
492,
334,
8169,
12,
1315,
1841,
12,
12055,
12,
20164,
12,
11140,
12,
6682,
12,
487,
19683,
63,
1841,
12,
943,
12,
673,
1315,
1534,
12,
6544,
63,
1532,
12,
8446,
793,
12,
1026,
82,
335,
10909,
12,
428,
12,
1437,
12,
7452,
12,
473,
12,
673,
1437,
63,
19830,
12,
29167,
63,
30133,
12,
593,
12,
410,
14769,
84,
74,
397,
9,
199,
504,
5840,
14,
16355,
14,
3759,
396,
492,
334,
396,
63,
26851,
63,
6677,
1183,
465,
12749,
12,
1993,
2196,
63,
5254,
63,
1955,
465,
10261,
67,
1168,
88,
12,
4911,
63,
6677,
1183,
465,
22762,
9,
199,
199,
88,
275,
10080,
360,
88,
358,
199,
65,
275,
10080,
360,
65,
358,
199,
66,
275,
10080,
360,
66,
297,
6946,
29,
549,
9,
199,
90,
275,
10080,
360,
90,
358,
199,
83,
275,
10080,
360,
83,
358,
421,
199,
318,
511,
63,
90,
1841,
63,
2579,
837,
339,
702,
1315,
1841,
8,
4304,
9,
508,
12055,
272,
702,
1315,
1841,
8,
88,
12,
12055,
9,
508,
12055,
339,
702,
1315,
1841,
8,
16,
9,
508,
20164,
2801,
17,
12,
499,
9,
272,
702,
1315,
1841,
8,
16,
12,
671,
9,
508,
20164,
8,
17,
12,
499,
9,
446,
671,
272,
702,
1315,
1841,
8,
16,
12,
330,
9,
508,
20164,
8,
17,
12,
499,
9,
446,
330,
339,
702,
1315,
1841,
8,
17,
9,
508,
1315,
1534,
272,
702,
1315,
1841,
8,
17,
12,
499,
9,
508,
1315,
1534,
272,
702,
1315,
1841,
8,
17,
12,
446,
23,
9,
508,
1315,
1534,
272,
702,
1315,
1841,
8,
17,
12,
671,
9,
508,
1315,
1534,
339,
702,
1315,
1841,
8,
18,
12,
413,
9,
508,
6682,
538,
18,
15,
22,
339,
702,
1315,
1841,
8,
18,
9,
508,
6682,
538,
18,
15,
22,
272,
702,
1315,
1841,
8,
20,
9,
508,
6682,
538,
20,
15,
2710,
272,
702,
1315,
1841,
8,
22,
9,
508,
6682,
538,
22,
15,
25,
2322,
339,
702,
1315,
1841,
8,
18,
12,
499,
9,
508,
6682,
538,
18,
15,
22,
446,
413,
272,
702,
1315,
1841,
8,
20,
12,
650,
9,
508,
6682,
538,
20,
15,
2710,
446,
20164,
8,
1196,
12,
3193,
9,
272,
702,
1315,
1841,
8,
22,
12,
841,
9,
508,
6682,
538,
22,
15,
25,
2322,
446,
20164,
8,
13818,
1887,
12,
841,
1272,
1367,
9,
339,
702,
1315,
1841,
8,
18,
12,
446,
18,
9,
508,
6682,
538,
18,
15,
22,
435,
20164,
8,
21,
12,
841,
9,
272,
702,
1315,
1841,
8,
20,
12,
446,
19,
9,
508,
6682,
538,
20,
15,
2710,
435,
20164,
8,
969,
3129,
12,
413,
11700,
9,
272,
702,
1315,
1841,
8,
22,
12,
446,
20,
9,
508,
6682,
538,
22,
15,
25,
2322,
435,
20164,
8,
1216,
9880,
2182,
12,
499,
2905,
1427,
1349,
9,
339,
702,
1315,
1841,
2801,
17,
9,
508,
446,
20248,
8,
17,
12,
3144,
9,
272,
702,
1315,
1841,
2801,
18,
9,
508,
378,
272,
702,
1315,
1841,
2801,
19,
9,
508,
20164,
8,
17,
12,
13960,
9,
272,
702,
1315,
1841,
2801,
20,
9,
508,
378,
272,
702,
1315,
1841,
2801,
21,
9,
508,
446,
20248,
8,
17,
12,
27210,
9,
339,
702,
1315,
1841,
2801,
17,
12,
650,
9,
508,
446,
20248,
8,
1401,
12,
3144,
9,
272,
702,
1315,
1841,
2801,
17,
12,
1520,
9,
508,
446,
20248,
8,
3781,
12,
3144,
9,
272,
702,
1315,
1841,
2801,
17,
12,
446,
20,
9,
508,
20164,
8,
7119,
12,
3144,
9,
272,
702,
1315,
1841,
2801,
17,
12,
446,
25,
9,
508,
20164,
8,
25391,
12,
3144,
9,
339,
702,
1315,
1841,
2801,
20,
12,
650,
9,
508,
446,
1196,
272,
702,
1315,
1841,
2801,
20,
12,
446,
24,
9,
508,
1695,
19518,
339,
702,
1315,
1841,
8,
16,
12,
413,
9,
508,
446,
20248,
8,
17,
12,
499,
9,
272,
702,
1315,
1841,
8,
16,
12,
446,
17,
9,
508,
20164,
8,
19,
12,
499,
9,
339,
702,
1315,
1841,
8,
16,
12,
499,
9,
508,
446,
20248,
8,
19,
12,
499,
9,
272,
702,
1315,
1841,
8,
16,
12,
446,
18,
9,
508,
20164,
8,
21,
12,
499,
9,
339,
702,
1315,
1841,
8,
267,
650,
680,
26782,
276,
8,
1165,
680,
15761,
63,
4077,
8,
5136,
480,
17,
14,
13934,
15143,
1644,
9327,
15667,
1651,
1477,
401,
3388,
395,
413,
69,
13,
1167,
9,
421,
199,
318,
511,
63,
90,
1841,
63,
5602,
837,
272,
702,
1315,
1841,
8,
88,
12,
282,
680,
5602,
8,
65,
12,
378,
12,
499,
9,
508,
971,
267,
1315,
1841,
8,
88,
12,
378,
9,
446,
671,
10,
65,
10,
90,
1841,
8,
88,
435,
413,
12,
378,
9,
435,
593,
8,
65,
538,
18,
9,
421,
199,
318,
511,
63,
328,
19683,
63,
1841,
63,
2579,
837,
339,
702,
487,
19683,
63,
1841,
8,
16,
9,
508,
20164,
8,
17,
12,
499,
9,
272,
702,
487,
19683,
63,
1841,
2801,
17,
9,
508,
20164,
8,
17,
12,
841,
9,
272,
702,
487,
19683,
63,
1841,
8,
17,
9,
508,
943,
8,
18,
9,
272,
702,
487,
19683,
63,
1841,
8,
18,
9,
508,
6682,
538,
18,
15,
713,
272,
702,
487,
19683,
63,
1841,
8,
20,
9,
508,
6682,
538,
20,
10,
20248,
8,
23,
12,
29692,
9,
421,
199,
318,
511,
63,
264,
14827,
837,
272,
702,
487,
19683,
63,
1841,
8,
88,
680,
14366,
8,
90,
1841,
9,
508,
334,
17,
446,
499,
14192,
17,
446,
671,
19198,
90,
1841,
8,
88,
9,
272,
702,
1315,
1841,
8,
88,
680,
14366,
8,
328,
19683,
63,
1841,
9,
508,
487,
19683,
63,
1841,
8,
88,
15136,
17,
446,
499,
14192,
17,
446,
671,
430,
272,
702,
22762,
8,
328,
19683,
63,
1841,
8,
88,
395,
487,
19683,
63,
1841,
8,
88,
680,
14366,
8,
90,
1841,
395,
671,
9,
272,
702,
22762,
8,
90,
1841,
8,
88,
395,
1315,
1841,
8,
88,
680,
14366,
8,
328,
19683,
63,
1841,
395,
671,
9,
339,
702,
1315,
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
] |
doismellburning/tox
|
tests/test_z_cmdline.py
|
1
|
20318
|
import tox
import py
import pytest
from tox._pytestplugin import ReportExpectMock
try:
import json
except ImportError:
import simplejson as json
pytest_plugins = "pytester"
from tox._cmdline import Session
from tox._config import parseconfig
def test_report_protocol(newconfig):
config = newconfig([], """
[testenv:mypython]
deps=xy
""")
class Popen:
def __init__(self, *args, **kwargs):
pass
def communicate(self):
return "", ""
def wait(self):
pass
session = Session(config, popen=Popen,
Report=ReportExpectMock)
report = session.report
report.expect("using")
venv = session.getvenv("mypython")
venv.update()
report.expect("logpopen")
def test__resolve_pkg(tmpdir, mocksession):
distshare = tmpdir.join("distshare")
spec = distshare.join("pkg123-*")
py.test.raises(tox.exception.MissingDirectory,
'mocksession._resolve_pkg(spec)')
distshare.ensure(dir=1)
py.test.raises(tox.exception.MissingDependency,
'mocksession._resolve_pkg(spec)')
distshare.ensure("pkg123-1.3.5.zip")
p = distshare.ensure("pkg123-1.4.5.zip")
mocksession.report.clear()
result = mocksession._resolve_pkg(spec)
assert result == p
mocksession.report.expect("info", "determin*pkg123*")
distshare.ensure("pkg123-1.4.7dev.zip")
mocksession._clearmocks()
result = mocksession._resolve_pkg(spec)
mocksession.report.expect("warning", "*1.4.7*")
assert result == p
mocksession._clearmocks()
distshare.ensure("pkg123-1.4.5a1.tar.gz")
result = mocksession._resolve_pkg(spec)
assert result == p
def test__resolve_pkg_doubledash(tmpdir, mocksession):
distshare = tmpdir.join("distshare")
p = distshare.ensure("pkg-mine-1.3.0.zip")
res = mocksession._resolve_pkg(distshare.join("pkg-mine*"))
assert res == p
distshare.ensure("pkg-mine-1.3.0a1.zip")
res = mocksession._resolve_pkg(distshare.join("pkg-mine*"))
assert res == p
class TestSession:
def test_make_sdist(self, initproj):
initproj("example123-0.5", filedefs={
'tests': {'test_hello.py': "def test_hello(): pass"},
'tox.ini': '''
'''
})
config = parseconfig([])
session = Session(config)
sdist = session.sdist()
assert sdist.check()
assert sdist.ext == ".zip"
assert sdist == config.distdir.join(sdist.basename)
sdist2 = session.sdist()
assert sdist2 == sdist
sdist.write("hello")
assert sdist.stat().size < 10
sdist_new = Session(config).sdist()
assert sdist_new == sdist
assert sdist_new.stat().size > 10
def test_make_sdist_distshare(self, tmpdir, initproj):
distshare = tmpdir.join("distshare")
initproj("example123-0.6", filedefs={
'tests': {'test_hello.py': "def test_hello(): pass"},
'tox.ini': '''
[tox]
distshare=%s
''' % distshare
})
config = parseconfig([])
session = Session(config)
sdist = session.sdist()
assert sdist.check()
assert sdist.ext == ".zip"
assert sdist == config.distdir.join(sdist.basename)
sdist_share = config.distshare.join(sdist.basename)
assert sdist_share.check()
assert sdist_share.read("rb") == sdist.read("rb"), (sdist_share, sdist)
def test_log_pcall(self, mocksession):
mocksession.config.logdir.ensure(dir=1)
assert not mocksession.config.logdir.listdir()
action = mocksession.newaction(None, "something")
action.popen(["echo", ])
match = mocksession.report.getnext("logpopen")
assert match[1].outpath.relto(mocksession.config.logdir)
assert match[1].shell == False
def test_summary_status(self, initproj, capfd):
initproj("logexample123-0.5", filedefs={
'tests': {'test_hello.py': "def test_hello(): pass"},
'tox.ini': '''
[testenv:hello]
[testenv:world]
'''
})
config = parseconfig([])
session = Session(config)
envs = session.venvlist
assert len(envs) == 2
env1, env2 = envs
env1.status = "FAIL XYZ"
assert env1.status
env2.status = 0
assert not env2.status
session._summary()
out, err = capfd.readouterr()
exp = "%s: FAIL XYZ" % env1.envconfig.envname
assert exp in out
exp = "%s: commands succeeded" % env2.envconfig.envname
assert exp in out
def test_getvenv(self, initproj, capfd):
initproj("logexample123-0.5", filedefs={
'tests': {'test_hello.py': "def test_hello(): pass"},
'tox.ini': '''
[testenv:hello]
[testenv:world]
'''
})
config = parseconfig([])
session = Session(config)
venv1 = session.getvenv("hello")
venv2 = session.getvenv("hello")
assert venv1 is venv2
venv1 = session.getvenv("world")
venv2 = session.getvenv("world")
assert venv1 is venv2
pytest.raises(LookupError, lambda: session.getvenv("qwe"))
# not sure we want this option ATM
def XXX_test_package(cmd, initproj):
initproj("myproj-0.6", filedefs={
'tests': {'test_hello.py': "def test_hello(): pass"},
'MANIFEST.in': """
include doc
include myproj
""",
'tox.ini': ''
})
result = cmd.run("tox", "package")
assert not result.ret
result.stdout.fnmatch_lines([
"*created sdist package at*",
])
def test_minversion(cmd, initproj):
initproj("interp123-0.5", filedefs={
'tests': {'test_hello.py': "def test_hello(): pass"},
'tox.ini': '''
[tox]
minversion = 6.0
'''
})
result = cmd.run("tox", "-v")
result.stdout.fnmatch_lines([
"*ERROR*tox version is * required is at least 6.0*"
])
assert result.ret
def test_run_custom_install_command_error(cmd, initproj):
initproj("interp123-0.5", filedefs={
'tox.ini': '''
[testenv]
install_command=./tox.ini {opts} {packages}
'''
})
result = cmd.run("tox")
result.stdout.fnmatch_lines([
"ERROR: invocation failed (errno *), args: ['*/tox.ini*",
])
assert result.ret
def test_unknown_interpreter_and_env(cmd, initproj):
initproj("interp123-0.5", filedefs={
'tests': {'test_hello.py': "def test_hello(): pass"},
'tox.ini': '''
[testenv:python]
basepython=xyz_unknown_interpreter
[testenv]
changedir=tests
'''
})
result = cmd.run("tox")
assert result.ret
result.stdout.fnmatch_lines([
"*ERROR*InterpreterNotFound*xyz_unknown_interpreter*",
])
result = cmd.run("tox", "-exyz")
assert result.ret
result.stdout.fnmatch_lines([
"*ERROR*unknown*",
])
def test_unknown_interpreter(cmd, initproj):
initproj("interp123-0.5", filedefs={
'tests': {'test_hello.py': "def test_hello(): pass"},
'tox.ini': '''
[testenv:python]
basepython=xyz_unknown_interpreter
[testenv]
changedir=tests
'''
})
result = cmd.run("tox")
assert result.ret
result.stdout.fnmatch_lines([
"*ERROR*InterpreterNotFound*xyz_unknown_interpreter*",
])
def test_skip_unknown_interpreter(cmd, initproj):
initproj("interp123-0.5", filedefs={
'tests': {'test_hello.py': "def test_hello(): pass"},
'tox.ini': '''
[testenv:python]
basepython=xyz_unknown_interpreter
[testenv]
changedir=tests
'''
})
result = cmd.run("tox", "--skip-missing-interpreters")
assert not result.ret
result.stdout.fnmatch_lines([
"*SKIPPED*InterpreterNotFound*xyz_unknown_interpreter*",
])
def test_unknown_dep(cmd, initproj):
initproj("dep123-0.7", filedefs={
'tests': {'test_hello.py': "def test_hello(): pass"},
'tox.ini': '''
[testenv]
deps=qweqwe123
changedir=tests
'''
})
result = cmd.run("tox", )
assert result.ret
result.stdout.fnmatch_lines([
"*ERROR*could not install*qweqwe123*",
])
def test_unknown_environment(cmd, initproj):
initproj("env123-0.7", filedefs={
'tox.ini': ''
})
result = cmd.run("tox", "-e", "qpwoei")
assert result.ret
result.stdout.fnmatch_lines([
"*ERROR*unknown*environment*qpwoei*",
])
def test_skip_sdist(cmd, initproj):
initproj("pkg123-0.7", filedefs={
'tests': {'test_hello.py': "def test_hello(): pass"},
'setup.py': """
syntax error
"""
,
'tox.ini': '''
[tox]
skipsdist=True
[testenv]
commands=python -c "print('done')"
'''
})
result = cmd.run("tox", )
assert result.ret == 0
def test_minimal_setup_py_empty(cmd, initproj):
initproj("pkg123-0.7", filedefs={
'tests': {'test_hello.py': "def test_hello(): pass"},
'setup.py': """
"""
,
'tox.ini': ''
})
result = cmd.run("tox", )
assert result.ret == 1
result.stdout.fnmatch_lines([
"*ERROR*empty*",
])
def test_minimal_setup_py_comment_only(cmd, initproj):
initproj("pkg123-0.7", filedefs={
'tests': {'test_hello.py': "def test_hello(): pass"},
'setup.py': """\n# some comment
"""
,
'tox.ini': ''
})
result = cmd.run("tox", )
assert result.ret == 1
result.stdout.fnmatch_lines([
"*ERROR*empty*",
])
def test_minimal_setup_py_non_functional(cmd, initproj):
initproj("pkg123-0.7", filedefs={
'tests': {'test_hello.py': "def test_hello(): pass"},
'setup.py': """
import sys
"""
,
'tox.ini': ''
})
result = cmd.run("tox", )
assert result.ret == 1
result.stdout.fnmatch_lines([
"*ERROR*check setup.py*",
])
def test_sdist_fails(cmd, initproj):
initproj("pkg123-0.7", filedefs={
'tests': {'test_hello.py': "def test_hello(): pass"},
'setup.py': """
syntax error
"""
,
'tox.ini': '',
})
result = cmd.run("tox", )
assert result.ret
result.stdout.fnmatch_lines([
"*FAIL*could not package project*",
])
def test_package_install_fails(cmd, initproj):
initproj("pkg123-0.7", filedefs={
'tests': {'test_hello.py': "def test_hello(): pass"},
'setup.py': """
from setuptools import setup
setup(
name='pkg123',
description='pkg123 project',
version='0.7',
license='MIT',
platforms=['unix', 'win32'],
packages=['pkg123',],
install_requires=['qweqwe123'],
)
"""
,
'tox.ini': '',
})
result = cmd.run("tox", )
assert result.ret
result.stdout.fnmatch_lines([
"*InvocationError*",
])
class TestToxRun:
@pytest.fixture
def example123(self, initproj):
initproj("example123-0.5", filedefs={
'tests': {'test_hello.py': """
def test_hello(pytestconfig):
pass
""",
},
'tox.ini': '''
[testenv]
changedir=tests
commands= py.test --basetemp={envtmpdir} \
--junitxml=junit-{envname}.xml
deps=pytest
'''
})
def test_toxuone_env(self, cmd, example123):
result = cmd.run("tox")
assert not result.ret
result.stdout.fnmatch_lines([
"*junit-python.xml*",
"*1 passed*",
])
result = cmd.run("tox", "-epython", )
assert not result.ret
result.stdout.fnmatch_lines([
"*1 passed*",
"*summary*",
"*python: commands succeeded"
])
def test_different_config_cwd(self, cmd, example123, monkeypatch):
# see that things work with a different CWD
monkeypatch.chdir(cmd.tmpdir)
result = cmd.run("tox", "-c", "example123/tox.ini")
assert not result.ret
result.stdout.fnmatch_lines([
"*1 passed*",
"*summary*",
"*python: commands succeeded"
])
def test_json(self, cmd, example123):
# see that tests can also fail and retcode is correct
testfile = py.path.local("tests").join("test_hello.py")
assert testfile.check()
testfile.write("def test_fail(): assert 0")
jsonpath = cmd.tmpdir.join("res.json")
result = cmd.run("tox", "--result-json", jsonpath)
assert result.ret == 1
data = json.load(jsonpath.open("r"))
verify_json_report_format(data)
result.stdout.fnmatch_lines([
"*1 failed*",
"*summary*",
"*python: *failed*",
])
def test_develop(initproj, cmd):
initproj("example123", filedefs={'tox.ini': """
"""})
result = cmd.run("tox", "-vv", "--develop")
assert not result.ret
assert "sdist-make" not in result.stdout.str()
def test_usedevelop(initproj, cmd):
initproj("example123", filedefs={'tox.ini': """
[testenv]
usedevelop=True
"""})
result = cmd.run("tox", "-vv")
assert not result.ret
assert "sdist-make" not in result.stdout.str()
def test_usedevelop_mixed(initproj, cmd):
initproj("example123", filedefs={'tox.ini': """
[testenv:devenv]
usedevelop=True
[testenv:nondev]
usedevelop=False
"""})
# running only 'devenv' should not do sdist
result = cmd.run("tox", "-vv", "-e", "devenv")
assert not result.ret
assert "sdist-make" not in result.stdout.str()
# running all envs should do sdist
result = cmd.run("tox", "-vv")
assert not result.ret
assert "sdist-make" in result.stdout.str()
def test_test_usedevelop(cmd, initproj):
initproj("example123-0.5", filedefs={
'tests': {'test_hello.py': """
def test_hello(pytestconfig):
pass
""",
},
'tox.ini': '''
[testenv]
usedevelop=True
changedir=tests
commands=
py.test --basetemp={envtmpdir} --junitxml=junit-{envname}.xml []
deps=pytest
'''
})
result = cmd.run("tox", "-v")
assert not result.ret
result.stdout.fnmatch_lines([
"*junit-python.xml*",
"*1 passed*",
])
assert "sdist-make" not in result.stdout.str()
result = cmd.run("tox", "-epython", )
assert not result.ret
result.stdout.fnmatch_lines([
"*1 passed*",
"*summary*",
"*python: commands succeeded"
])
# see that things work with a different CWD
old = cmd.tmpdir.chdir()
result = cmd.run("tox", "-c", "example123/tox.ini")
assert not result.ret
result.stdout.fnmatch_lines([
"*1 passed*",
"*summary*",
"*python: commands succeeded"
])
old.chdir()
# see that tests can also fail and retcode is correct
testfile = py.path.local("tests").join("test_hello.py")
assert testfile.check()
testfile.write("def test_fail(): assert 0")
result = cmd.run("tox", )
assert result.ret
result.stdout.fnmatch_lines([
"*1 failed*",
"*summary*",
"*python: *failed*",
])
def test_test_piphelp(initproj, cmd):
initproj("example123", filedefs={'tox.ini': """
# content of: tox.ini
[testenv]
commands=pip -h
[testenv:py26]
basepython=python
[testenv:py27]
basepython=python
"""})
result = cmd.run("tox")
assert not result.ret
def test_notest(initproj, cmd):
initproj("example123", filedefs={'tox.ini': """
# content of: tox.ini
[testenv:py26]
basepython=python
"""})
result = cmd.run("tox", "-v", "--notest")
assert not result.ret
result.stdout.fnmatch_lines([
"*summary*",
"*py26*skipped tests*",
])
result = cmd.run("tox", "-v", "--notest", "-epy26")
assert not result.ret
result.stdout.fnmatch_lines([
"*py26*reusing*",
])
def test_PYC(initproj, cmd, monkeypatch):
initproj("example123", filedefs={'tox.ini': ''})
monkeypatch.setenv("PYTHONDOWNWRITEBYTECODE", 1)
result = cmd.run("tox", "-v", "--notest")
assert not result.ret
result.stdout.fnmatch_lines([
"*create*",
])
def test_env_VIRTUALENV_PYTHON(initproj, cmd, monkeypatch):
initproj("example123", filedefs={'tox.ini': ''})
monkeypatch.setenv("VIRTUALENV_PYTHON", '/FOO')
result = cmd.run("tox", "-v", "--notest")
assert not result.ret, result.stdout.lines
result.stdout.fnmatch_lines([
"*create*",
])
def test_sdistonly(initproj, cmd):
initproj("example123", filedefs={'tox.ini': """
"""})
result = cmd.run("tox", "-v", "--sdistonly")
assert not result.ret
result.stdout.fnmatch_lines([
"*sdist-make*setup.py*",
])
assert "-mvirtualenv" not in result.stdout.str()
def test_separate_sdist_no_sdistfile(cmd, initproj):
distshare = cmd.tmpdir.join("distshare")
initproj("pkg123-0.7", filedefs={
'tox.ini': """
[tox]
distshare=%s
""" % distshare
})
result = cmd.run("tox", "--sdistonly")
assert not result.ret
l = distshare.listdir()
assert len(l) == 1
sdistfile = l[0]
assert 'pkg123-0.7.zip' in str(sdistfile)
def test_separate_sdist(cmd, initproj):
distshare = cmd.tmpdir.join("distshare")
initproj("pkg123-0.7", filedefs={
'tox.ini': """
[tox]
distshare=%s
sdistsrc={distshare}/pkg123-0.7.zip
""" % distshare
})
result = cmd.run("tox", "--sdistonly")
assert not result.ret
l = distshare.listdir()
assert len(l) == 1
sdistfile = l[0]
result = cmd.run("tox", "-v", "--notest")
assert not result.ret
result.stdout.fnmatch_lines([
"*inst*%s*" % sdistfile,
])
def test_sdist_latest(tmpdir, newconfig):
distshare = tmpdir.join("distshare")
config = newconfig([], """
[tox]
distshare=%s
sdistsrc={distshare}/pkg123-*
""" % distshare)
p = distshare.ensure("pkg123-1.4.5.zip")
distshare.ensure("pkg123-1.4.5a1.zip")
session = Session(config)
sdist_path = session.sdist()
assert sdist_path == p
def test_installpkg(tmpdir, newconfig):
p = tmpdir.ensure("pkg123-1.0.zip")
config = newconfig(["--installpkg=%s" % p], "")
session = Session(config)
sdist_path = session.sdist()
assert sdist_path == p
@pytest.mark.xfail("sys.platform == 'win32' and sys.version_info < (2,6)",
reason="test needs better impl")
def test_envsitepackagesdir(cmd, initproj):
initproj("pkg512-0.0.5", filedefs={
'tox.ini': """
[testenv]
commands=
python -c "print(r'X:{envsitepackagesdir}')"
"""})
result = cmd.run("tox")
assert result.ret == 0
result.stdout.fnmatch_lines("""
X:*tox*site-packages*
""")
def verify_json_report_format(data, testenvs=True):
assert data["reportversion"] == "1"
assert data["toxversion"] == tox.__version__
if testenvs:
for envname, envdata in data["testenvs"].items():
for commandtype in ("setup", "test"):
if commandtype not in envdata:
continue
for command in envdata[commandtype]:
assert command["output"]
assert command["retcode"]
pyinfo = envdata["python"]
assert isinstance(pyinfo["version_info"], list)
assert pyinfo["version"]
assert pyinfo["executable"]
|
mit
|
[
646,
370,
88,
199,
646,
1134,
199,
646,
4613,
199,
504,
370,
88,
423,
4462,
2718,
492,
11774,
13495,
3346,
199,
893,
26,
272,
492,
2022,
199,
2590,
3545,
26,
272,
492,
13804,
465,
2022,
199,
199,
4462,
63,
5265,
275,
298,
647,
8234,
2,
199,
199,
504,
370,
88,
423,
15612,
492,
8596,
199,
504,
370,
88,
423,
888,
492,
2198,
888,
199,
199,
318,
511,
63,
3070,
63,
3922,
8,
1222,
888,
304,
272,
1101,
275,
892,
888,
8798,
408,
288,
359,
744,
9072,
26,
1662,
1548,
61,
288,
10140,
29,
1702,
272,
7857,
272,
1021,
13995,
26,
267,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
288,
986,
267,
347,
26808,
8,
277,
304,
288,
372,
4873,
3087,
267,
347,
3618,
8,
277,
304,
288,
986,
339,
2351,
275,
8596,
8,
888,
12,
17758,
29,
7942,
12,
288,
11774,
29,
7457,
13495,
3346,
9,
272,
3622,
275,
2351,
14,
3070,
272,
3622,
14,
4921,
480,
4941,
531,
272,
373,
1813,
275,
2351,
14,
362,
23195,
480,
1662,
1548,
531,
272,
373,
1813,
14,
873,
342,
272,
3622,
14,
4921,
480,
793,
12207,
531,
199,
199,
318,
511,
363,
6983,
63,
4600,
8,
8616,
12,
1683,
1730,
304,
272,
2917,
6251,
275,
12885,
14,
904,
480,
2686,
6251,
531,
272,
3158,
275,
2917,
6251,
14,
904,
480,
4600,
4288,
13,
10,
531,
272,
1134,
14,
396,
14,
3536,
8,
475,
88,
14,
1971,
14,
7718,
6231,
12,
267,
283,
1805,
1730,
423,
6983,
63,
4600,
8,
1650,
5942,
272,
2917,
6251,
14,
7505,
8,
694,
29,
17,
9,
272,
1134,
14,
396,
14,
3536,
8,
475,
88,
14,
1971,
14,
7718,
14403,
12,
267,
283,
1805,
1730,
423,
6983,
63,
4600,
8,
1650,
5942,
272,
2917,
6251,
14,
7505,
480,
4600,
4288,
13,
17,
14,
19,
14,
21,
14,
3065,
531,
272,
299,
275,
2917,
6251,
14,
7505,
480,
4600,
4288,
13,
17,
14,
20,
14,
21,
14,
3065,
531,
339,
1683,
1730,
14,
3070,
14,
3584,
342,
272,
754,
275,
1683,
1730,
423,
6983,
63,
4600,
8,
1650,
9,
272,
702,
754,
508,
299,
272,
1683,
1730,
14,
3070,
14,
4921,
480,
815,
401,
298,
17061,
10,
4600,
4288,
10,
531,
272,
2917,
6251,
14,
7505,
480,
4600,
4288,
13,
17,
14,
20,
14,
23,
2374,
14,
3065,
531,
272,
1683,
1730,
423,
3584,
25191,
342,
272,
754,
275,
1683,
1730,
423,
6983,
63,
4600,
8,
1650,
9,
272,
1683,
1730,
14,
3070,
14,
4921,
480,
3764,
401,
8969,
17,
14,
20,
14,
23,
10,
531,
272,
702,
754,
508,
299,
272,
1683,
1730,
423,
3584,
25191,
342,
272,
2917,
6251,
14,
7505,
480,
4600,
4288,
13,
17,
14,
20,
14,
21,
65,
17,
14,
5369,
14,
6838,
531,
272,
754,
275,
1683,
1730,
423,
6983,
63,
4600,
8,
1650,
9,
272,
702,
754,
508,
299,
199,
199,
318,
511,
363,
6983,
63,
4600,
63,
1117,
456,
1146,
1119,
8,
8616,
12,
1683,
1730,
304,
272,
2917,
6251,
275,
12885,
14,
904,
480,
2686,
6251,
531,
272,
299,
275,
2917,
6251,
14,
7505,
480,
4600,
13,
19153,
13,
17,
14,
19,
14,
16,
14,
3065,
531,
272,
522,
275,
1683,
1730,
423,
6983,
63,
4600,
8,
2686,
6251,
14,
904,
480,
4600,
13,
19153,
10,
2237,
272,
702,
522,
508,
299,
272,
2917,
6251,
14,
7505,
480,
4600,
13,
19153,
13,
17,
14,
19,
14,
16,
65,
17,
14,
3065,
531,
272,
522,
275,
1683,
1730,
423,
6983,
63,
4600,
8,
2686,
6251,
14,
904,
480,
4600,
13,
19153,
10,
2237,
272,
702,
522,
508,
299,
4388,
199,
533,
1379,
4434,
26,
272,
347,
511,
63,
1875,
63,
25147,
8,
277,
12,
4205,
5468,
304,
267,
4205,
5468,
480,
2694,
4288,
13,
16,
14,
21,
401,
570,
8710,
3126,
288,
283,
2219,
356,
791,
396,
63,
5006,
14,
647,
356,
298,
318,
511,
63,
5006,
837,
986,
6018,
288,
283,
475,
88,
14,
2730,
356,
1449,
288,
1449,
267,
3828,
267,
1101,
275,
2198,
888,
4157,
267,
2351,
275,
8596,
8,
888,
9,
267,
26644,
275,
2351,
14,
25147,
342,
267,
702,
26644,
14,
1074,
342,
267,
702,
26644,
14,
832,
508,
3680,
3065,
2,
267,
702,
26644,
508,
1101,
14,
2686,
694,
14,
904,
8,
25147,
14,
4846,
9,
267,
26644,
18,
275,
2351,
14,
25147,
342,
267,
702,
26644,
18,
508,
26644,
267,
26644,
14,
952,
480,
5006,
531,
267,
702,
26644,
14,
3736,
1252,
890,
665,
1616,
267,
26644,
63,
1222,
275,
8596,
8,
888,
680,
25147,
342,
267,
702,
26644,
63,
1222,
508,
26644,
267,
702,
26644,
63,
1222,
14,
3736,
1252,
890,
690,
1616,
339,
347,
511,
63,
1875,
63,
25147,
63,
2686,
6251,
8,
277,
12,
12885,
12,
4205,
5468,
304,
267,
2917,
6251,
275,
12885,
14,
904,
480,
2686,
6251,
531,
267,
4205,
5468,
480,
2694,
4288,
13,
16,
14,
22,
401,
570,
8710,
3126,
288,
283,
2219,
356,
791,
396,
63,
5006,
14,
647,
356,
298,
318,
511,
63,
5006,
837,
986,
6018,
288,
283,
475,
88,
14,
2730,
356,
1449,
288,
359,
475,
88,
61,
288,
2917,
6251,
2458,
83,
288,
1449,
450,
2917,
6251,
267,
3828,
267,
1101,
275,
2198,
888,
4157,
267,
2351,
275,
8596,
8,
888,
9,
267,
26644,
275,
2351,
14,
25147,
342,
267,
702,
26644,
14,
1074,
342,
267,
702,
26644,
14,
832,
508,
3680,
3065,
2,
267,
702,
26644,
508,
1101,
14,
2686,
694,
14,
904,
8,
25147,
14,
4846,
9,
267,
26644,
63,
6251,
275,
1101,
14,
2686,
6251,
14,
904,
8,
25147,
14,
4846,
9,
267,
702,
26644,
63,
6251,
14,
1074,
342,
267,
702,
26644,
63,
6251,
14,
739,
480,
4848,
531,
508,
26644,
14,
739,
480,
4848,
1288,
334,
25147,
63,
6251,
12,
26644,
9,
339,
347,
511,
63,
793,
63,
80,
1250,
8,
277,
12,
1683,
1730,
304,
267,
1683,
1730,
14,
888,
14,
22222,
14,
7505,
8,
694,
29,
17,
9,
267,
702,
440,
1683,
1730,
14,
888,
14,
22222,
14,
7374,
342,
267,
1595,
275,
1683,
1730,
14,
1222,
1287,
8,
403,
12,
298,
10297,
531,
267,
1595,
14,
12207,
5234,
7878,
401,
4794,
267,
1336,
275,
1683,
1730,
14,
3070,
14,
362,
2184,
480
] |
[
370,
88,
199,
646,
1134,
199,
646,
4613,
199,
504,
370,
88,
423,
4462,
2718,
492,
11774,
13495,
3346,
199,
893,
26,
272,
492,
2022,
199,
2590,
3545,
26,
272,
492,
13804,
465,
2022,
199,
199,
4462,
63,
5265,
275,
298,
647,
8234,
2,
199,
199,
504,
370,
88,
423,
15612,
492,
8596,
199,
504,
370,
88,
423,
888,
492,
2198,
888,
199,
199,
318,
511,
63,
3070,
63,
3922,
8,
1222,
888,
304,
272,
1101,
275,
892,
888,
8798,
408,
288,
359,
744,
9072,
26,
1662,
1548,
61,
288,
10140,
29,
1702,
272,
7857,
272,
1021,
13995,
26,
267,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
288,
986,
267,
347,
26808,
8,
277,
304,
288,
372,
4873,
3087,
267,
347,
3618,
8,
277,
304,
288,
986,
339,
2351,
275,
8596,
8,
888,
12,
17758,
29,
7942,
12,
288,
11774,
29,
7457,
13495,
3346,
9,
272,
3622,
275,
2351,
14,
3070,
272,
3622,
14,
4921,
480,
4941,
531,
272,
373,
1813,
275,
2351,
14,
362,
23195,
480,
1662,
1548,
531,
272,
373,
1813,
14,
873,
342,
272,
3622,
14,
4921,
480,
793,
12207,
531,
199,
199,
318,
511,
363,
6983,
63,
4600,
8,
8616,
12,
1683,
1730,
304,
272,
2917,
6251,
275,
12885,
14,
904,
480,
2686,
6251,
531,
272,
3158,
275,
2917,
6251,
14,
904,
480,
4600,
4288,
13,
10,
531,
272,
1134,
14,
396,
14,
3536,
8,
475,
88,
14,
1971,
14,
7718,
6231,
12,
267,
283,
1805,
1730,
423,
6983,
63,
4600,
8,
1650,
5942,
272,
2917,
6251,
14,
7505,
8,
694,
29,
17,
9,
272,
1134,
14,
396,
14,
3536,
8,
475,
88,
14,
1971,
14,
7718,
14403,
12,
267,
283,
1805,
1730,
423,
6983,
63,
4600,
8,
1650,
5942,
272,
2917,
6251,
14,
7505,
480,
4600,
4288,
13,
17,
14,
19,
14,
21,
14,
3065,
531,
272,
299,
275,
2917,
6251,
14,
7505,
480,
4600,
4288,
13,
17,
14,
20,
14,
21,
14,
3065,
531,
339,
1683,
1730,
14,
3070,
14,
3584,
342,
272,
754,
275,
1683,
1730,
423,
6983,
63,
4600,
8,
1650,
9,
272,
702,
754,
508,
299,
272,
1683,
1730,
14,
3070,
14,
4921,
480,
815,
401,
298,
17061,
10,
4600,
4288,
10,
531,
272,
2917,
6251,
14,
7505,
480,
4600,
4288,
13,
17,
14,
20,
14,
23,
2374,
14,
3065,
531,
272,
1683,
1730,
423,
3584,
25191,
342,
272,
754,
275,
1683,
1730,
423,
6983,
63,
4600,
8,
1650,
9,
272,
1683,
1730,
14,
3070,
14,
4921,
480,
3764,
401,
8969,
17,
14,
20,
14,
23,
10,
531,
272,
702,
754,
508,
299,
272,
1683,
1730,
423,
3584,
25191,
342,
272,
2917,
6251,
14,
7505,
480,
4600,
4288,
13,
17,
14,
20,
14,
21,
65,
17,
14,
5369,
14,
6838,
531,
272,
754,
275,
1683,
1730,
423,
6983,
63,
4600,
8,
1650,
9,
272,
702,
754,
508,
299,
199,
199,
318,
511,
363,
6983,
63,
4600,
63,
1117,
456,
1146,
1119,
8,
8616,
12,
1683,
1730,
304,
272,
2917,
6251,
275,
12885,
14,
904,
480,
2686,
6251,
531,
272,
299,
275,
2917,
6251,
14,
7505,
480,
4600,
13,
19153,
13,
17,
14,
19,
14,
16,
14,
3065,
531,
272,
522,
275,
1683,
1730,
423,
6983,
63,
4600,
8,
2686,
6251,
14,
904,
480,
4600,
13,
19153,
10,
2237,
272,
702,
522,
508,
299,
272,
2917,
6251,
14,
7505,
480,
4600,
13,
19153,
13,
17,
14,
19,
14,
16,
65,
17,
14,
3065,
531,
272,
522,
275,
1683,
1730,
423,
6983,
63,
4600,
8,
2686,
6251,
14,
904,
480,
4600,
13,
19153,
10,
2237,
272,
702,
522,
508,
299,
4388,
199,
533,
1379,
4434,
26,
272,
347,
511,
63,
1875,
63,
25147,
8,
277,
12,
4205,
5468,
304,
267,
4205,
5468,
480,
2694,
4288,
13,
16,
14,
21,
401,
570,
8710,
3126,
288,
283,
2219,
356,
791,
396,
63,
5006,
14,
647,
356,
298,
318,
511,
63,
5006,
837,
986,
6018,
288,
283,
475,
88,
14,
2730,
356,
1449,
288,
1449,
267,
3828,
267,
1101,
275,
2198,
888,
4157,
267,
2351,
275,
8596,
8,
888,
9,
267,
26644,
275,
2351,
14,
25147,
342,
267,
702,
26644,
14,
1074,
342,
267,
702,
26644,
14,
832,
508,
3680,
3065,
2,
267,
702,
26644,
508,
1101,
14,
2686,
694,
14,
904,
8,
25147,
14,
4846,
9,
267,
26644,
18,
275,
2351,
14,
25147,
342,
267,
702,
26644,
18,
508,
26644,
267,
26644,
14,
952,
480,
5006,
531,
267,
702,
26644,
14,
3736,
1252,
890,
665,
1616,
267,
26644,
63,
1222,
275,
8596,
8,
888,
680,
25147,
342,
267,
702,
26644,
63,
1222,
508,
26644,
267,
702,
26644,
63,
1222,
14,
3736,
1252,
890,
690,
1616,
339,
347,
511,
63,
1875,
63,
25147,
63,
2686,
6251,
8,
277,
12,
12885,
12,
4205,
5468,
304,
267,
2917,
6251,
275,
12885,
14,
904,
480,
2686,
6251,
531,
267,
4205,
5468,
480,
2694,
4288,
13,
16,
14,
22,
401,
570,
8710,
3126,
288,
283,
2219,
356,
791,
396,
63,
5006,
14,
647,
356,
298,
318,
511,
63,
5006,
837,
986,
6018,
288,
283,
475,
88,
14,
2730,
356,
1449,
288,
359,
475,
88,
61,
288,
2917,
6251,
2458,
83,
288,
1449,
450,
2917,
6251,
267,
3828,
267,
1101,
275,
2198,
888,
4157,
267,
2351,
275,
8596,
8,
888,
9,
267,
26644,
275,
2351,
14,
25147,
342,
267,
702,
26644,
14,
1074,
342,
267,
702,
26644,
14,
832,
508,
3680,
3065,
2,
267,
702,
26644,
508,
1101,
14,
2686,
694,
14,
904,
8,
25147,
14,
4846,
9,
267,
26644,
63,
6251,
275,
1101,
14,
2686,
6251,
14,
904,
8,
25147,
14,
4846,
9,
267,
702,
26644,
63,
6251,
14,
1074,
342,
267,
702,
26644,
63,
6251,
14,
739,
480,
4848,
531,
508,
26644,
14,
739,
480,
4848,
1288,
334,
25147,
63,
6251,
12,
26644,
9,
339,
347,
511,
63,
793,
63,
80,
1250,
8,
277,
12,
1683,
1730,
304,
267,
1683,
1730,
14,
888,
14,
22222,
14,
7505,
8,
694,
29,
17,
9,
267,
702,
440,
1683,
1730,
14,
888,
14,
22222,
14,
7374,
342,
267,
1595,
275,
1683,
1730,
14,
1222,
1287,
8,
403,
12,
298,
10297,
531,
267,
1595,
14,
12207,
5234,
7878,
401,
4794,
267,
1336,
275,
1683,
1730,
14,
3070,
14,
362,
2184,
480,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
baseclue/django-rest-test
|
tests/test_compare.py
|
1
|
15578
|
import unittest
from rest_test import compare
class DictTestCase(unittest.TestCase):
def test_basic(self):
data = dict(
a=1,
b='2'
)
expected_data = dict(
b='2',
a=1
)
assert compare(data, expected_data)
def test_basic_false(self):
data = dict(
a=1,
b='2'
)
expected_data = dict(
b=2,
a=1
)
self.assertFalse(compare(data, expected_data))
def test_deep(self):
data = dict(
a=1,
b=dict(
b=dict(
a='test'
),
a=2,
c=''
)
)
expected_data = dict(
a=1,
b=dict(
a=2,
b=dict(
a='test'
),
c=''
)
)
assert compare(data, expected_data)
def test_deep_false(self):
data = dict(
a=1,
b=dict(
b=dict(
a='test'
),
a=2,
c=''
)
)
expected_data = dict(
a=1,
b=dict(
a=2,
b=dict(
b=1
),
c=''
)
)
self.assertFalse(compare(data, expected_data))
class ItemEllipsisTestCase(unittest.TestCase):
def test_basic(self):
data = dict(
a=1,
b='2'
)
expected_data = dict(
b='2',
a=...
)
assert compare(data, expected_data)
def test_basic_false(self):
data = dict(
a=1,
b='2'
)
expected_data = dict(
b=2,
a=...
)
self.assertFalse(compare(data, expected_data))
def test_deep(self):
data = dict(
a=1,
b=dict(
b=dict(
a='test'
),
a=2,
c=''
)
)
expected_data = dict(
a=1,
b=dict(
a=2,
b=...,
c=''
)
)
assert compare(data, expected_data)
def test_deep_false(self):
data = dict(
a=1,
b=dict(
b=dict(
a='test'
),
a=2,
c=''
)
)
expected_data = dict(
a=1,
b=dict(
a=3,
b=...,
c=''
)
)
self.assertFalse(compare(data, expected_data))
def test_missing_basic_false(self):
data = dict(
a=1,
b='2'
)
expected_data = dict(
a=...
)
self.assertFalse(compare(data, expected_data))
def test_moreover_basic_false(self):
data = dict(
a=1,
b='2'
)
expected_data = dict(
b=2,
a=...,
c='test'
)
self.assertFalse(compare(data, expected_data))
def test_missing_deep_false(self):
data = dict(
a=1,
b=dict(
b=dict(
a='test'
),
a=2,
c=''
)
)
expected_data = dict(
a=1,
b=dict(
a=2,
b=...,
)
)
self.assertFalse(compare(data, expected_data))
def test_moreover_deep_false(self):
data = dict(
a=1,
b=dict(
b=dict(
a='test'
),
a=2,
c=''
)
)
expected_data = dict(
a=1,
b=dict(
a=3,
b=...,
c='',
d='test'
)
)
self.assertFalse(compare(data, expected_data))
class DictEllipsisTestCase(unittest.TestCase):
def test_empty(self):
data = dict(
)
expected_data = {
...: ...
}
assert compare(data, expected_data)
def test_basic(self):
data = dict(
a=1,
b='2'
)
expected_data = {
...: ...
}
assert compare(data, expected_data)
def test_basic_more(self):
data = {
'a': 1,
'b': '2',
'c': 3
}
expected_data = {
...: ...,
'b': '2'
}
assert compare(data, expected_data)
def test_basic_false(self):
data = dict(
a=1,
b='2'
)
expected_data = {
'b': 2,
...: ...
}
self.assertFalse(compare(data, expected_data))
def test_deep(self):
data = dict(
a=1,
b=dict(
b=dict(
a='test'
),
a=2,
c=''
)
)
expected_data = dict(
a=1,
b={
'a': 2,
...: ...,
'c': ''
}
)
assert compare(data, expected_data)
def test_deep_false(self):
data = dict(
a=1,
b=dict(
b=dict(
a='test'
),
a=2,
c=''
)
)
expected_data = dict(
a=1,
b={
'a': 3,
...: ...,
'c': ''
}
)
self.assertFalse(compare(data, expected_data))
def test_moreover_basic_false(self):
data = dict(
a=1,
b='2'
)
expected_data = {
'b': 2,
...: ...,
'c': 'test'
}
self.assertFalse(compare(data, expected_data))
def test_missing_deep_false(self):
data = dict(
a=1,
b=dict(
b=dict(
a='test'
),
a=2,
c=''
)
)
expected_data = dict(
a=1,
b={
'a': 2,
...: ...
}
)
assert compare(data, expected_data)
def test_moreover_deep_false(self):
data = dict(
a=1,
b=dict(
b=dict(
a='test'
),
a=2,
c=''
)
)
expected_data = dict(
a=1,
b={
'a': 3,
...: ...,
'c': '',
'd': 'test'
}
)
self.assertFalse(compare(data, expected_data))
def test_bad_usage(self):
data = dict(
a=1,
b=dict(
b=dict(
a='test'
),
a=2,
c=''
)
)
expected_data = {
'a': 1,
...: dict(
b=dict(
a='test'
),
a=2,
c=''
)
}
with self.assertRaises(TypeError):
compare(data, expected_data)
class ListTestCase(unittest.TestCase):
def test_basic(self):
data = [
1,
'2'
]
expected_data = [
1,
'2'
]
assert compare(data, expected_data)
def test_basic_false(self):
data = [
1,
2
]
expected_data = [
2,
1
]
self.assertFalse(compare(data, expected_data))
def test_combination(self):
data = [
dict(
a=1,
b=dict(
b=dict(
a='test'
),
a=2,
c=''
)
),
dict(
a=2,
b=dict(
b=dict(
a='test'
),
a=2,
c=''
)
)
]
expected_data = [
dict(
a=1,
b=dict(
b=dict(
a='test'
),
a=2,
c=''
)
),
dict(
a=2,
b=dict(
b=dict(
a='test'
),
a=2,
c=''
)
)
]
assert compare(data, expected_data)
class ListEllipsisTestCase(unittest.TestCase):
def test_empty(self):
data = [
'1',
{},
3
]
expected_data = [
...
]
assert compare(data, expected_data)
def test_start(self):
data = [
'1',
{},
3
]
expected_data = [
...,
3
]
assert compare(data, expected_data)
def test_multiple(self):
data = [
'1',
2,
3,
'4',
5
]
expected_data = [
...,
2,
...
]
assert compare(data, expected_data)
def test_end(self):
data = [
1,
2,
3,
4,
5
]
expected_data = [
1,
...
]
assert compare(data, expected_data)
def test_multiple_in(self):
data = [
1,
2,
3,
4,
5,
6,
7
]
expected_data = [
...,
2,
...,
5,
...
]
assert compare(data, expected_data)
def test_start_false(self):
data = [
1,
2,
3
]
expected_data = [
...,
4
]
self.assertFalse(compare(data, expected_data))
def test_multiple_false(self):
data = [
1,
2,
3,
4,
5
]
expected_data = [
...,
6,
...
]
self.assertFalse(compare(data, expected_data))
def test_end_false(self):
data = [
1,
2,
3,
4,
5
]
expected_data = [
2,
...
]
self.assertFalse(compare(data, expected_data))
def test_multiple_in_optional(self):
data = [
1,
2,
3,
4,
5,
6,
7
]
expected_data = [
...,
2,
...,
3,
...
]
assert compare(data, expected_data)
def test_multiple_in_optional_between(self):
data = [
2,
3,
]
expected_data = [
...,
2,
...,
3,
...
]
assert compare(data, expected_data)
def test_bad_usage(self):
data = [
1,
2,
3,
4,
5,
6,
7
]
expected_data = [
...,
...,
7
]
with self.assertRaises(TypeError):
compare(data, expected_data)
def test_one(self):
data = [1]
expected_data = [..., 1, ...]
assert compare(data, expected_data)
class CombinationEllipsisTestCase(unittest.TestCase):
def test_combination(self):
data = [
{
'foo': 1,
'bar': 2,
'zoo': 3,
}
]
expected_data = [
...,
{
...: ...,
'bar': 2
},
...
]
assert compare(data, expected_data)
def test_combination_empty(self):
data = [
{
}
]
expected_data = [
...,
{
...: ...,
},
...
]
assert compare(data, expected_data)
class TypeTestCase(unittest.TestCase):
def test_list(self):
data = [
'1',
{},
3
]
expected_data = list
assert compare(data, expected_data)
def test_dict(self):
data = {
'1': 2,
2: 3,
3: 2
}
expected_data = dict
assert compare(data, expected_data)
def test_list_with_dict(self):
data = [
'1',
{'test': 'test_value'},
3
]
expected_data = [
'1',
dict,
3
]
assert compare(data, expected_data)
def test_dict_with_list(self):
data = {
'1': 2,
'test_key': [1, 2, 'u'],
3: 2
}
expected_data = {
'1': 2,
'test_key': list,
3: 2
}
assert compare(data, expected_data)
def test_different_types_in_list(self):
data = [
'1',
{},
3
]
expected_data = [
str,
dict,
int
]
assert compare(data, expected_data)
def test_different_types_in_dict(self):
data = {
'1': 2,
2: 'test',
3: [1, 2, 3]
}
expected_data = {
'1': int,
2: str,
3: list
}
assert compare(data, expected_data)
def test_different_types_in_dict_in_deep(self):
data = [
'1',
{
'1': 2,
2: 'test',
3: [1, 2, 3]
},
3
]
expected_data = [
'1',
{
'1': int,
2: str,
3: list
},
3
]
assert compare(data, expected_data)
class CombinationTypeEllipsisTestCase(unittest.TestCase):
def test_combination(self):
data = [
{
'foo': 1,
'bar': 2,
'zoo': 3,
},
{
'test_foo': '1',
'test_bar': 2,
'test_zoo': [1, 2, 3],
},
]
expected_data = [
...,
{
...: ...,
'bar': int
},
...,
{
'test_foo': str,
'test_bar': 2,
'test_zoo': list,
}
]
assert compare(data, expected_data)
if __name__ == '__main__':
unittest.main()
|
apache-2.0
|
[
646,
2882,
199,
504,
4618,
63,
396,
492,
6540,
421,
199,
533,
7448,
1746,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
4316,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
534,
18,
7,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
330,
534,
18,
297,
288,
282,
29,
17,
267,
776,
398,
702,
6540,
8,
576,
12,
1420,
63,
576,
9,
339,
347,
511,
63,
4316,
63,
3910,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
534,
18,
7,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
330,
29,
18,
12,
288,
282,
29,
17,
267,
776,
398,
291,
14,
3334,
8,
5785,
8,
576,
12,
1420,
63,
576,
430,
339,
347,
511,
63,
16131,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
330,
29,
807,
8,
490,
282,
534,
396,
7,
355,
2318,
355,
282,
29,
18,
12,
355,
286,
19070,
288,
776,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
282,
29,
18,
12,
355,
330,
29,
807,
8,
490,
282,
534,
396,
7,
355,
2318,
355,
286,
19070,
288,
776,
267,
776,
267,
702,
6540,
8,
576,
12,
1420,
63,
576,
9,
339,
347,
511,
63,
16131,
63,
3910,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
330,
29,
807,
8,
490,
282,
534,
396,
7,
355,
2318,
355,
282,
29,
18,
12,
355,
286,
19070,
288,
776,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
282,
29,
18,
12,
355,
330,
29,
807,
8,
490,
330,
29,
17,
355,
2318,
355,
286,
19070,
288,
776,
267,
776,
398,
291,
14,
3334,
8,
5785,
8,
576,
12,
1420,
63,
576,
430,
421,
199,
533,
7020,
23525,
2316,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
4316,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
534,
18,
7,
267,
776,
398,
1420,
63,
576,
275,
1211,
8,
288,
330,
534,
18,
297,
288,
282,
29,
1396,
267,
776,
398,
702,
6540,
8,
576,
12,
1420,
63,
576,
9,
339,
347,
511,
63,
4316,
63,
3910,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
534,
18,
7,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
330,
29,
18,
12,
288,
282,
29,
1396,
267,
776,
398,
291,
14,
3334,
8,
5785,
8,
576,
12,
1420,
63,
576,
430,
339,
347,
511,
63,
16131,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
330,
29,
807,
8,
490,
282,
534,
396,
7,
355,
2318,
355,
282,
29,
18,
12,
355,
286,
19070,
288,
776,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
282,
29,
18,
12,
355,
330,
29,
11577,
355,
286,
19070,
288,
776,
267,
776,
267,
702,
6540,
8,
576,
12,
1420,
63,
576,
9,
339,
347,
511,
63,
16131,
63,
3910,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
330,
29,
807,
8,
490,
282,
534,
396,
7,
355,
2318,
355,
282,
29,
18,
12,
355,
286,
19070,
288,
776,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
282,
29,
19,
12,
355,
330,
29,
11577,
355,
286,
19070,
288,
776,
267,
776,
398,
291,
14,
3334,
8,
5785,
8,
576,
12,
1420,
63,
576,
430,
339,
347,
511,
63,
4752,
63,
4316,
63,
3910,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
534,
18,
7,
267,
776,
398,
1420,
63,
576,
275,
1211,
8,
288,
282,
29,
1396,
267,
776,
267,
291,
14,
3334,
8,
5785,
8,
576,
12,
1420,
63,
576,
430,
339,
347,
511,
63,
6878,
1883,
63,
4316,
63,
3910,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
534,
18,
7,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
330,
29,
18,
12,
288,
282,
29,
11577,
288,
286,
534,
396,
7,
267,
776,
398,
291,
14,
3334,
8,
5785,
8,
576,
12,
1420,
63,
576,
430,
339,
347,
511,
63,
4752,
63,
16131,
63,
3910,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
330,
29,
807,
8,
490,
282,
534,
396,
7,
355,
2318,
355,
282,
29,
18,
12,
355,
286,
19070,
288,
776,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
282,
29,
18,
12,
355,
330,
29,
11577,
288,
776,
267,
776,
267,
291,
14,
3334,
8,
5785,
8,
576,
12,
1420,
63,
576,
430,
339,
347,
511,
63,
6878,
1883,
63,
16131,
63,
3910,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
330,
29,
807,
8,
490,
282,
534,
396,
7,
355,
2318,
355,
282,
29,
18,
12,
355,
286,
19070,
288,
776,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
282,
29,
19,
12,
355,
330,
29,
11577,
355,
286,
4581,
355,
366,
534,
396,
7,
288,
776,
267,
776,
398,
291,
14,
3334,
8,
5785,
8,
576,
12,
1420,
63,
576,
430,
421,
199,
533,
7448,
23525,
2316,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
1667,
8,
277,
304,
267,
666,
275,
1211,
8,
267,
776,
398,
1420,
63,
576,
275,
469,
288,
2263,
26,
2263,
267,
789,
398,
702,
6540,
8,
576,
12,
1420,
63,
576,
9,
339,
347,
511,
63,
4316,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288
] |
[
2882,
199,
504,
4618,
63,
396,
492,
6540,
421,
199,
533,
7448,
1746,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
4316,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
534,
18,
7,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
330,
534,
18,
297,
288,
282,
29,
17,
267,
776,
398,
702,
6540,
8,
576,
12,
1420,
63,
576,
9,
339,
347,
511,
63,
4316,
63,
3910,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
534,
18,
7,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
330,
29,
18,
12,
288,
282,
29,
17,
267,
776,
398,
291,
14,
3334,
8,
5785,
8,
576,
12,
1420,
63,
576,
430,
339,
347,
511,
63,
16131,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
330,
29,
807,
8,
490,
282,
534,
396,
7,
355,
2318,
355,
282,
29,
18,
12,
355,
286,
19070,
288,
776,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
282,
29,
18,
12,
355,
330,
29,
807,
8,
490,
282,
534,
396,
7,
355,
2318,
355,
286,
19070,
288,
776,
267,
776,
267,
702,
6540,
8,
576,
12,
1420,
63,
576,
9,
339,
347,
511,
63,
16131,
63,
3910,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
330,
29,
807,
8,
490,
282,
534,
396,
7,
355,
2318,
355,
282,
29,
18,
12,
355,
286,
19070,
288,
776,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
282,
29,
18,
12,
355,
330,
29,
807,
8,
490,
330,
29,
17,
355,
2318,
355,
286,
19070,
288,
776,
267,
776,
398,
291,
14,
3334,
8,
5785,
8,
576,
12,
1420,
63,
576,
430,
421,
199,
533,
7020,
23525,
2316,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
4316,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
534,
18,
7,
267,
776,
398,
1420,
63,
576,
275,
1211,
8,
288,
330,
534,
18,
297,
288,
282,
29,
1396,
267,
776,
398,
702,
6540,
8,
576,
12,
1420,
63,
576,
9,
339,
347,
511,
63,
4316,
63,
3910,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
534,
18,
7,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
330,
29,
18,
12,
288,
282,
29,
1396,
267,
776,
398,
291,
14,
3334,
8,
5785,
8,
576,
12,
1420,
63,
576,
430,
339,
347,
511,
63,
16131,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
330,
29,
807,
8,
490,
282,
534,
396,
7,
355,
2318,
355,
282,
29,
18,
12,
355,
286,
19070,
288,
776,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
282,
29,
18,
12,
355,
330,
29,
11577,
355,
286,
19070,
288,
776,
267,
776,
267,
702,
6540,
8,
576,
12,
1420,
63,
576,
9,
339,
347,
511,
63,
16131,
63,
3910,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
330,
29,
807,
8,
490,
282,
534,
396,
7,
355,
2318,
355,
282,
29,
18,
12,
355,
286,
19070,
288,
776,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
282,
29,
19,
12,
355,
330,
29,
11577,
355,
286,
19070,
288,
776,
267,
776,
398,
291,
14,
3334,
8,
5785,
8,
576,
12,
1420,
63,
576,
430,
339,
347,
511,
63,
4752,
63,
4316,
63,
3910,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
534,
18,
7,
267,
776,
398,
1420,
63,
576,
275,
1211,
8,
288,
282,
29,
1396,
267,
776,
267,
291,
14,
3334,
8,
5785,
8,
576,
12,
1420,
63,
576,
430,
339,
347,
511,
63,
6878,
1883,
63,
4316,
63,
3910,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
534,
18,
7,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
330,
29,
18,
12,
288,
282,
29,
11577,
288,
286,
534,
396,
7,
267,
776,
398,
291,
14,
3334,
8,
5785,
8,
576,
12,
1420,
63,
576,
430,
339,
347,
511,
63,
4752,
63,
16131,
63,
3910,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
330,
29,
807,
8,
490,
282,
534,
396,
7,
355,
2318,
355,
282,
29,
18,
12,
355,
286,
19070,
288,
776,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
282,
29,
18,
12,
355,
330,
29,
11577,
288,
776,
267,
776,
267,
291,
14,
3334,
8,
5785,
8,
576,
12,
1420,
63,
576,
430,
339,
347,
511,
63,
6878,
1883,
63,
16131,
63,
3910,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
330,
29,
807,
8,
490,
282,
534,
396,
7,
355,
2318,
355,
282,
29,
18,
12,
355,
286,
19070,
288,
776,
267,
776,
267,
1420,
63,
576,
275,
1211,
8,
288,
282,
29,
17,
12,
288,
330,
29,
807,
8,
355,
282,
29,
19,
12,
355,
330,
29,
11577,
355,
286,
4581,
355,
366,
534,
396,
7,
288,
776,
267,
776,
398,
291,
14,
3334,
8,
5785,
8,
576,
12,
1420,
63,
576,
430,
421,
199,
533,
7448,
23525,
2316,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
1667,
8,
277,
304,
267,
666,
275,
1211,
8,
267,
776,
398,
1420,
63,
576,
275,
469,
288,
2263,
26,
2263,
267,
789,
398,
702,
6540,
8,
576,
12,
1420,
63,
576,
9,
339,
347,
511,
63,
4316,
8,
277,
304,
267,
666,
275,
1211,
8,
288,
282,
29,
17,
12,
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,
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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
] |
brainwane/zulip
|
zerver/tests/test_subdomains.py
|
5
|
2460
|
from typing import Any, Mapping, Sequence
from unittest import mock
from zerver.lib.subdomains import get_subdomain
from zerver.lib.test_classes import ZulipTestCase
from zerver.models import Realm
class SubdomainsTest(ZulipTestCase):
def test_get_subdomain(self) -> None:
def request_mock(host: str) -> Any:
request = mock.Mock(spec=['get_host'])
request.attach_mock(mock.Mock(return_value=host), 'get_host')
return request
def test(expected: str, host: str, *, plusport: bool=True,
external_host: str='example.org',
realm_hosts: Mapping[str, str]={},
root_aliases: Sequence[str]=[]) -> None:
with self.settings(EXTERNAL_HOST=external_host,
REALM_HOSTS=realm_hosts,
ROOT_SUBDOMAIN_ALIASES=root_aliases):
self.assertEqual(get_subdomain(request_mock(host)), expected)
if plusport and ':' not in host:
self.assertEqual(get_subdomain(request_mock(host + ':443')),
expected)
ROOT = Realm.SUBDOMAIN_FOR_ROOT_DOMAIN
# Basics
test(ROOT, 'example.org')
test('foo', 'foo.example.org')
test(ROOT, 'www.example.org', root_aliases=['www'])
# Unrecognized patterns fall back to root
test(ROOT, 'arbitrary.com')
test(ROOT, 'foo.example.org.evil.com')
# REALM_HOSTS adds a name,
test('bar', 'chat.barbar.com', realm_hosts={'bar': 'chat.barbar.com'})
# ... exactly, ...
test(ROOT, 'surchat.barbar.com', realm_hosts={'bar': 'chat.barbar.com'})
test(ROOT, 'foo.chat.barbar.com', realm_hosts={'bar': 'chat.barbar.com'})
# ... and leaves the subdomain in place too.
test('bar', 'bar.example.org', realm_hosts={'bar': 'chat.barbar.com'})
# Any port is fine in Host if there's none in EXTERNAL_HOST, ...
test('foo', 'foo.example.org:443', external_host='example.org')
test('foo', 'foo.example.org:12345', external_host='example.org')
# ... but an explicit port in EXTERNAL_HOST must be explicitly matched in Host.
test(ROOT, 'foo.example.org', external_host='example.org:12345')
test(ROOT, 'foo.example.org', external_host='example.org:443', plusport=False)
test('foo', 'foo.example.org:443', external_host='example.org:443')
|
apache-2.0
|
[
504,
14090,
492,
6184,
12,
12340,
12,
10975,
199,
504,
2882,
492,
1683,
199,
199,
504,
19959,
14,
773,
14,
954,
9756,
492,
664,
63,
22806,
199,
504,
19959,
14,
773,
14,
396,
63,
2888,
492,
3107,
11294,
1746,
199,
504,
19959,
14,
992,
492,
27715,
421,
199,
533,
4804,
9756,
774,
8,
58,
11294,
1746,
304,
272,
347,
511,
63,
362,
63,
22806,
8,
277,
9,
1035,
488,
26,
398,
347,
1056,
63,
1805,
8,
1102,
26,
620,
9,
1035,
6184,
26,
288,
1056,
275,
1683,
14,
3346,
8,
1650,
2968,
362,
63,
1102,
1105,
288,
1056,
14,
5040,
63,
1805,
8,
1805,
14,
3346,
8,
1107,
63,
585,
29,
1102,
395,
283,
362,
63,
1102,
358,
288,
372,
1056,
398,
347,
511,
8,
2062,
26,
620,
12,
1591,
26,
620,
12,
9889,
12254,
719,
26,
2155,
29,
549,
12,
326,
5957,
63,
1102,
26,
620,
534,
2694,
14,
1308,
297,
326,
10482,
63,
5146,
26,
12340,
59,
495,
12,
620,
61,
10324,
326,
1738,
63,
8602,
26,
10975,
59,
495,
61,
14285,
1035,
488,
26,
288,
543,
291,
14,
1751,
8,
21043,
63,
5449,
29,
5159,
63,
1102,
12,
3044,
5363,
748,
45,
63,
23775,
29,
7728,
63,
5146,
12,
3044,
16547,
63,
6348,
7378,
63,
12644,
654,
29,
1231,
63,
8602,
304,
355,
291,
14,
629,
8,
362,
63,
22806,
8,
1069,
63,
1805,
8,
1102,
1826,
1420,
9,
355,
340,
12254,
719,
436,
10871,
440,
315,
1591,
26,
490,
291,
14,
629,
8,
362,
63,
22806,
8,
1069,
63,
1805,
8,
1102,
435,
7596,
16284,
3855,
3660,
1420,
9,
398,
16547,
275,
27715,
14,
6348,
7378,
63,
2707,
63,
5441,
63,
7378,
398,
327,
10082,
83,
267,
511,
8,
5441,
12,
283,
2694,
14,
1308,
358,
267,
511,
360,
1421,
297,
283,
1421,
14,
2694,
14,
1308,
358,
267,
511,
8,
5441,
12,
283,
1544,
14,
2694,
14,
1308,
297,
1738,
63,
8602,
2968,
1544,
1105,
398,
327,
1910,
13221,
7970,
11264,
1771,
370,
1738,
267,
511,
8,
5441,
12,
283,
285,
8734,
14,
957,
358,
267,
511,
8,
5441,
12,
283,
1421,
14,
2694,
14,
1308,
14,
6857,
382,
14,
957,
358,
398,
327,
5363,
748,
45,
63,
23775,
9584,
282,
536,
12,
267,
511,
360,
1700,
297,
283,
10289,
14,
1700,
1700,
14,
957,
297,
10482,
63,
5146,
3713,
1700,
356,
283,
10289,
14,
1700,
1700,
14,
957,
3071,
267,
327,
2263,
8840,
12,
2263,
267,
511,
8,
5441,
12,
283,
5105,
10289,
14,
1700,
1700,
14,
957,
297,
10482,
63,
5146,
3713,
1700,
356,
283,
10289,
14,
1700,
1700,
14,
957,
3071,
267,
511,
8,
5441,
12,
283,
1421,
14,
10289,
14,
1700,
1700,
14,
957,
297,
10482,
63,
5146,
3713,
1700,
356,
283,
10289,
14,
1700,
1700,
14,
957,
3071,
267,
327,
2263,
436,
16733,
314,
23301,
315,
4192,
4634,
14,
267,
511,
360,
1700,
297,
283,
1700,
14,
2694,
14,
1308,
297,
10482,
63,
5146,
3713,
1700,
356,
283,
10289,
14,
1700,
1700,
14,
957,
3071,
398,
327,
6184,
1844,
365,
15701,
315,
10891,
340,
2337,
1159,
7179,
315,
3651,
17071,
63,
5449,
12,
2263,
267,
511,
360,
1421,
297,
283,
1421,
14,
2694,
14,
1308,
26,
16284,
297,
5957,
63,
1102,
534,
2694,
14,
1308,
358,
267,
511,
360,
1421,
297,
283,
1421,
14,
2694,
14,
1308,
26,
13261,
297,
5957,
63,
1102,
534,
2694,
14,
1308,
358,
267,
327,
2263,
1325,
376,
5027,
1844,
315,
3651,
17071,
63,
5449,
1471,
506,
7662,
7838,
315,
10891,
14,
267,
511,
8,
5441,
12,
283,
1421,
14,
2694,
14,
1308,
297,
5957,
63,
1102,
534,
2694,
14,
1308,
26,
13261,
358,
267,
511,
8,
5441,
12,
283,
1421,
14,
2694,
14,
1308,
297,
5957,
63,
1102,
534,
2694,
14,
1308,
26,
16284,
297,
12254,
719,
29,
797,
9,
267,
511,
360,
1421,
297,
283,
1421,
14,
2694,
14,
1308,
26,
16284,
297,
5957,
63,
1102,
534,
2694,
14,
1308,
26,
16284,
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
] |
[
14090,
492,
6184,
12,
12340,
12,
10975,
199,
504,
2882,
492,
1683,
199,
199,
504,
19959,
14,
773,
14,
954,
9756,
492,
664,
63,
22806,
199,
504,
19959,
14,
773,
14,
396,
63,
2888,
492,
3107,
11294,
1746,
199,
504,
19959,
14,
992,
492,
27715,
421,
199,
533,
4804,
9756,
774,
8,
58,
11294,
1746,
304,
272,
347,
511,
63,
362,
63,
22806,
8,
277,
9,
1035,
488,
26,
398,
347,
1056,
63,
1805,
8,
1102,
26,
620,
9,
1035,
6184,
26,
288,
1056,
275,
1683,
14,
3346,
8,
1650,
2968,
362,
63,
1102,
1105,
288,
1056,
14,
5040,
63,
1805,
8,
1805,
14,
3346,
8,
1107,
63,
585,
29,
1102,
395,
283,
362,
63,
1102,
358,
288,
372,
1056,
398,
347,
511,
8,
2062,
26,
620,
12,
1591,
26,
620,
12,
9889,
12254,
719,
26,
2155,
29,
549,
12,
326,
5957,
63,
1102,
26,
620,
534,
2694,
14,
1308,
297,
326,
10482,
63,
5146,
26,
12340,
59,
495,
12,
620,
61,
10324,
326,
1738,
63,
8602,
26,
10975,
59,
495,
61,
14285,
1035,
488,
26,
288,
543,
291,
14,
1751,
8,
21043,
63,
5449,
29,
5159,
63,
1102,
12,
3044,
5363,
748,
45,
63,
23775,
29,
7728,
63,
5146,
12,
3044,
16547,
63,
6348,
7378,
63,
12644,
654,
29,
1231,
63,
8602,
304,
355,
291,
14,
629,
8,
362,
63,
22806,
8,
1069,
63,
1805,
8,
1102,
1826,
1420,
9,
355,
340,
12254,
719,
436,
10871,
440,
315,
1591,
26,
490,
291,
14,
629,
8,
362,
63,
22806,
8,
1069,
63,
1805,
8,
1102,
435,
7596,
16284,
3855,
3660,
1420,
9,
398,
16547,
275,
27715,
14,
6348,
7378,
63,
2707,
63,
5441,
63,
7378,
398,
327,
10082,
83,
267,
511,
8,
5441,
12,
283,
2694,
14,
1308,
358,
267,
511,
360,
1421,
297,
283,
1421,
14,
2694,
14,
1308,
358,
267,
511,
8,
5441,
12,
283,
1544,
14,
2694,
14,
1308,
297,
1738,
63,
8602,
2968,
1544,
1105,
398,
327,
1910,
13221,
7970,
11264,
1771,
370,
1738,
267,
511,
8,
5441,
12,
283,
285,
8734,
14,
957,
358,
267,
511,
8,
5441,
12,
283,
1421,
14,
2694,
14,
1308,
14,
6857,
382,
14,
957,
358,
398,
327,
5363,
748,
45,
63,
23775,
9584,
282,
536,
12,
267,
511,
360,
1700,
297,
283,
10289,
14,
1700,
1700,
14,
957,
297,
10482,
63,
5146,
3713,
1700,
356,
283,
10289,
14,
1700,
1700,
14,
957,
3071,
267,
327,
2263,
8840,
12,
2263,
267,
511,
8,
5441,
12,
283,
5105,
10289,
14,
1700,
1700,
14,
957,
297,
10482,
63,
5146,
3713,
1700,
356,
283,
10289,
14,
1700,
1700,
14,
957,
3071,
267,
511,
8,
5441,
12,
283,
1421,
14,
10289,
14,
1700,
1700,
14,
957,
297,
10482,
63,
5146,
3713,
1700,
356,
283,
10289,
14,
1700,
1700,
14,
957,
3071,
267,
327,
2263,
436,
16733,
314,
23301,
315,
4192,
4634,
14,
267,
511,
360,
1700,
297,
283,
1700,
14,
2694,
14,
1308,
297,
10482,
63,
5146,
3713,
1700,
356,
283,
10289,
14,
1700,
1700,
14,
957,
3071,
398,
327,
6184,
1844,
365,
15701,
315,
10891,
340,
2337,
1159,
7179,
315,
3651,
17071,
63,
5449,
12,
2263,
267,
511,
360,
1421,
297,
283,
1421,
14,
2694,
14,
1308,
26,
16284,
297,
5957,
63,
1102,
534,
2694,
14,
1308,
358,
267,
511,
360,
1421,
297,
283,
1421,
14,
2694,
14,
1308,
26,
13261,
297,
5957,
63,
1102,
534,
2694,
14,
1308,
358,
267,
327,
2263,
1325,
376,
5027,
1844,
315,
3651,
17071,
63,
5449,
1471,
506,
7662,
7838,
315,
10891,
14,
267,
511,
8,
5441,
12,
283,
1421,
14,
2694,
14,
1308,
297,
5957,
63,
1102,
534,
2694,
14,
1308,
26,
13261,
358,
267,
511,
8,
5441,
12,
283,
1421,
14,
2694,
14,
1308,
297,
5957,
63,
1102,
534,
2694,
14,
1308,
26,
16284,
297,
12254,
719,
29,
797,
9,
267,
511,
360,
1421,
297,
283,
1421,
14,
2694,
14,
1308,
26,
16284,
297,
5957,
63,
1102,
534,
2694,
14,
1308,
26,
16284,
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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0,
0,
0
] |
stromnet/agocontrol
|
devices/squeezebox/pylmslibrary.py
|
5
|
17886
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
PyLMS: Python Wrapper for Logitech Media Server CLI (Telnet) Interface
Copyright (C) 2013 Tang <tanguy [dot] bonneau [at] gmail [dot] com>
LMSServer class is based on JingleManSweep <jinglemansweep [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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
from pylmsserver import LMSServer
import threading
import os
import logging
import urllib
class CacheCovers(threading.Thread):
"""cache covers for thumbnails"""
def __init__(self, server_ip, server_port, cover_path, albums, end_callback=None):
"""init"""
threading.Thread.__init__(self)
self.logger = logging.getLogger("CacheCovers")
self.albums = albums
self.cover_path = cover_path
self.server_port = server_port
self.server_ip = server_ip
self.running = True
self.end_callback = end_callback
def stop(self):
"""stop process"""
self.running = False
def start(self):
"""start process"""
self.logger.debug('CacheCovers started')
for album in self.albums:
if not album.has_key('id'):
self.logger.warning('Album has no Id !?!?')
elif not album.has_key('artwork_track_id'):
self.logger.warning('Album "%s" has no artwork_track_id field' % album['id'])
else:
url = 'http://%s:%d/music/%s/cover_100x100.png' % (self.server_ip, self.server_port, album['artwork_track_id'])
path = os.path.join(self.cover_path, '%s_%s.png' % (album['id'], album['artwork_track_id']))
#self.logger.debug('New cover : url=%s cover=%s' % (url, path))
if not os.path.exists(path):
#cover not exists
fil = open(path, 'wb')
bin = urllib.urlopen(url)
fil.write(bin.read())
fil.close()
#stop statement?
if not self.running:
break
self.logger.debug('CacheCovers stopped')
class LMSLibrary():
LIBRARY_EMPTY = 0
LIBRARY_UPTODATE = 1
LIBRARY_UPDATING = 2
def __init__(self, server_ip, server_port=9090, server_user='', server_password=''):
"""constructor"""
#init
self.logger = logging.getLogger("Library")
#members
self.server_ip = server_ip
self.server_port = server_port
self.__cover_path = os.path.join(os.path.expanduser('~'), '.squeezedesktop', 'cache')
if not os.path.exists(self.__cover_path):
#create cache directory
os.makedirs(self.__cover_path)
self.__server_infos_path = os.path.join(os.path.expanduser('~'), '.squeezedesktop', 'server.conf')
self.__albums_count = 0
self.__artists_count = 0
self.__genres_count = 0
self.__years_count = 0
#objects
self.server = LMSServer(server_ip, server_port, server_user, server_password)
self.server.connect()
self.cache_covers = None
def __del__(self):
"""destructor"""
#only stop threads if runnings
if self.cache_covers:
self.cache_covers.stop()
def get_albums(self):
"""return all albums"""
# id Album ID. Item delimiter.
#l album Album name, including the server's added "(N of M)" if the server is set to group multi disc albums together. See tag "title" for the unmodified value.
#y year Album year. This is determined by the server based on the album tracks.
#j artwork_track_id Identifier of one of the album tracks, used by the server to display the album's artwork.
#t title "Raw" album title as found in the album tracks ID3 tags, as opposed to "album". Note that "title" and "album" are identical if the server is set to group discs together.
#i disc Disc number of this album. Only if the server is not set to group multi-disc albums together.
#q disccount Number of discs for this album. Only if known.
#w compilation 1 if this album is a compilation.
#a artist The album artist (depends on server configuration).
#S artist_id The album artist id (depends on server configuration).
#s textkey The album's "textkey" is the first letter of the sorting key.
#X album_replay_gain The album's replay-gain.
#need at least j tag to find associated cover in cache
count, items, error = self.server.request_with_results('albums 0 %d tags:lj' % self.__albums_count)
if error:
return None
else:
return items
def get_album(self, id):
"""return album infos"""
if id!=None:
count, items, error = self.server.request_with_results('albums 0 1 album_id:%d tags:ljyS' % id)
if error:
return None
else:
return items
else:
return None
def get_album_songs(self, id):
"""return all songs from specified album id"""
# rescan Returned with value 1 if the server is still scanning the database. The results may therefore be incomplete. Not returned if no scan is in progress.
# count Number of results returned by the query, that is, total number of elements to return for this song.
# id Track ID.
# title Song title
#a artist Artist name.
#A <role> For every artist role (one of "artist", "composer", "conductor", "band", "albumartist" or "trackartist"), a comma separated list of names.
#B buttons A hash with button definitions. Only available for certain plugins such as Pandora.
#c coverid coverid to use when constructing an artwork URL, such as /music/$coverid/cover.jpg
#C compilation 1 if the album this track belongs to is a compilation
#d duration Song duration in seconds.
#e album_id Album ID. Only if known.
#f filesize Song file length in bytes. Only if known.
#g genre Genre name. Only if known.
#G genres Genre names, separated by commas (only useful if the server is set to handle multiple items in tags).
#i disc Disc number. Only if known.
#I samplesize Song sample size (in bits)
#j coverart 1 if coverart is available for this song. Not listed otherwise.
#J artwork_track_id Identifier of the album track used by the server to display the album's artwork. Not listed if artwork is not available for this album.
#k comment Song comments, if any.
#K artwork_url A full URL to remote artwork. Only available for certain plugins such as Pandora and Rhapsody.
#l album Album name. Only if known.
#L info_link A custom link to use for trackinfo. Only available for certain plugins such as Pandora.
#m bpm Beats per minute. Only if known.
#M musicmagic_mixable 1 if track is mixable, otherwise 0.
#n modificationTime Date and time song file was last changed on disk.
#N remote_title Title of the internet radio station.
#o type Content type. Only if known.
#p genre_id Genre ID. Only if known.
#P genre_ids Genre IDs, separated by commas (only useful if the server is set to handle multiple items in tags).
#D addedTime Date and time song file was first added to the database.
#U lastUpdated Date and time song file was last updated in the database.
#q disccount Number of discs. Only if known.
#r bitrate Song bitrate. Only if known.
#R rating Song rating, if known and greater than 0.
#s artist_id Artist ID.
#S <role>_ids For each role as defined above, the list of ids.
#t tracknum Track number. Only if known.
#T samplerate Song sample rate (in KHz)
#u url Song file url.
#v tagversion Version of tag information in song file. Only if known.
#w lyrics Lyrics. Only if known.
#x remote If 1, this is a remote track.
#X album_replay_gain Replay gain of the album (in dB), if any
#y year Song year. Only if known.
#Y replay_gain Replay gain (in dB), if any
if id!=None:
count, items, error = self.server.request_with_results('songs 0 200 album_id:%deJ' % id)
if error:
return None
else:
return items
else:
return None
def get_artists(self):
"""return all artists"""
# id Artist ID. Item delimiter.
# artist Artist name.
#s textkey The artist's "textkey" is the first letter of the sorting key.
count, items, error = self.server.request_with_results('artists 0 %d' % self.__artists_count)
if error:
return None
else:
return items
def get_artist(self, id):
"""return artist infos"""
if id!=None:
count, items, error = self.server.request_with_results('artists 0 1 artist_id:%d' % id)
if error:
return None
else:
return items
else:
return None
def get_artist_albums(self, id):
"""return albums from specified artist id"""
if id!=None:
count, items, error = self.server.request_with_results('albums 0 %d artist_id:%d tags:ljyS' % (self.__albums_count, id))
if error:
return None
else:
return items
else:
return None
def get_genres(self):
"""return all genres"""
count, items, error = self.server.request_with_results('genres 0 %d' % self.__genres_count)
if error:
return None
else:
return items
def get_genre(self, id):
"""return genre infos"""
if id!=None:
count, items, error = self.server.request_with_results('genre 0 1 genre_id:%d' % id)
if error:
return None
else:
return items
else:
return None
def get_genre_albums(self, id):
"""return albums from specified genre id"""
if id!=None:
count, items, error = self.server.request_with_results('albums 0 %d genre_id:%d tags:ljyS' % (self.__albums_count, id))
if error:
return None
else:
return items
else:
return None
def get_years(self):
"""return all years"""
count, items, error = self.server.request_with_results('years 0 %d' % self.__years_count)
if error:
return None
else:
return items
def get_year_albums(self, id):
"""return albums from specified year id"""
if id!=None:
count, items, error = self.server.request_with_results('albums 0 %d year:%d tags:ljyS' % (self.__albums_count, id))
if error:
return None
else:
return items
else:
return None
def get_song_infos(self, id):
"""return full song infos"""
if id!=None:
count, items, error = self.server.request_with_results('songinfo 0 50 track_id:%d tags:adefgIJlnortTuvyY' % id)
if not error and count==1:
return items[0]
else:
return None
else:
return None
def get_song_infos_by_url(self, url):
"""return full song infos"""
if id!=None:
count, items, error = self.server.request_with_results('songinfo 0 50 url:%s tags:adefgIJlnortTuvyY' % url)
self.logger.debug('count=%d' % count)
self.logger.debug('items=%s' % str(items))
self.logger.debug('error=%s' % str(error))
if not error and count==1:
return items[0]
else:
return None
else:
return None
def get_cover_path(self, album_id, artwork_track_id):
"""return cover"""
cover_path = None
if album_id and artwork_track_id:
cover_path = os.path.join(self.__cover_path, '%s_%s.png' % (album_id, artwork_track_id))
self.logger.debug('Cover path:%s' % cover_path)
if not os.path.exists(cover_path):
#cover doesn't exists
self.logger.debug('Cover doesn\'t exist!')
cover_path = None
return cover_path
def search(self, term):
"""search something on database"""
#TODO
pass
def check_update(self):
"""check if library needs update, return True if database needs update followed by number of albums, artists, and genres"""
#get stats
lms_genres_count = int(self.server.request('info total genres ?'))
self.__genres_count = lms_genres_count
lms_artists_count = int(self.server.request('info total artists ?'))
self.__artists_count = lms_artists_count
lms_albums_count = int(self.server.request('info total albums ?'))
self.__albums_count = lms_albums_count
self.logger.debug('LMS total artists=%d albums=%d genres=%d' % (lms_artists_count, lms_albums_count, lms_genres_count))
#check if fresh install
if not os.path.exists(self.__server_infos_path):
#conf file doesn't exist create empty one
conf = open(self.__server_infos_path, 'w')
conf.write('albums:0\nartists:0\ngenres:0')
local_genres_count = 0
local_artists_count = 0
local_albums_count = 0
else:
#read from file
conf = open(self.__server_infos_path, 'r')
for line in conf.readlines():
if line.startswith('artists'):
try:
local_artists_count = int(line.split(':')[1].strip())
except:
local_artists_count = 0
elif line.startswith('albums'):
try:
local_albums_count = int(line.split(':')[1].strip())
except:
local_albums_count = 0
elif line.startswith('genres'):
try:
local_genres_count = int(line.split(':')[1].strip())
except:
local_genres_count = 0
#compare results
self.logger.debug('%d==%d %d==%d %d==%d' % (lms_genres_count, local_genres_count, lms_artists_count, local_artists_count, lms_albums_count, local_albums_count))
if lms_genres_count!=local_genres_count or lms_artists_count!=local_artists_count or lms_albums_count!=local_albums_count:
#need update
self.logger.debug('Need update')
self.__cache_covers(lms_albums_count)
def __cache_covers(self, albums_count):
"""cache covers for thumbnails"""
count, albums, error = self.server.request_with_results('albums 0 %d tags:j' % albums_count)
if not error:
self.logger.debug('Updating...')
self.cache_covers = CacheCovers(self.server_ip, self.server_port, self.__cover_path, albums)
self.cache_covers.start()
else:
#error
self.logger.error('Unable to get albums list')
"""TESTS"""
if __name__=="__main__":
import gobject; gobject.threads_init()
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
console_sh = logging.StreamHandler()
console_sh.setLevel(logging.DEBUG)
console_sh.setFormatter(logging.Formatter('%(asctime)s %(name)-20s %(levelname)-8s %(message)s'))
logger.addHandler(console_sh)
try:
lib = LMSLibrary('192.168.1.53', 9090)
infos = lib.get_song_infos_by_url('file:///media/raid/mp3/J/Joseph%20Arthur%20-%202013%20-%20Ballad%20Of%20Boogie%20Christ/03%20-%20The%20Ballad%20Of%20Boogie%20Christ.mp3')
logger.info(infos)
#lib.check_update()
#mainloop = gobject.MainLoop()
#mainloop.run()
except KeyboardInterrupt:
logger.debug('====> KEYBOARD INTERRUPT <====')
logger.debug('Waiting for threads to stop...')
#mainloop.quit()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
202,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
2999,
199,
624,
202,
199,
2713,
44,
3053,
26,
2018,
21947,
367,
5297,
1175,
335,
12300,
7146,
14214,
334,
52,
352,
846,
9,
14816,
10292,
202,
199,
7384,
334,
35,
9,
6171,
377,
621,
665,
84,
621,
29514,
359,
3287,
61,
23672,
685,
3844,
359,
292,
61,
29712,
359,
3287,
61,
2414,
30,
10292,
202,
199,
44,
3053,
3120,
1021,
365,
4079,
641,
1603,
2361,
2395,
10941,
7840,
665,
74,
2361,
77,
796,
87,
7840,
359,
292,
61,
29712,
359,
3287,
61,
2414,
30,
2999,
199,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
202,
199,
8951,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
202,
199,
305,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
202,
199,
1618,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
2999,
199,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
202,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
202,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
202,
199,
17732,
1696,
1684,
844,
367,
1655,
2436,
14,
2999,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
202,
199,
21632,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
202,
199,
30216,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
12,
8217,
14,
202,
199,
624,
2999,
199,
504,
1134,
15807,
1000,
492,
27540,
3120,
202,
199,
646,
5796,
202,
199,
646,
747,
202,
199,
646,
2050,
202,
199,
646,
4011,
2999,
199,
533,
11977,
967,
14895,
8,
12562,
14,
4436,
304,
1128,
408,
1637,
25858,
367,
10062,
83,
624,
2958,
347,
636,
826,
721,
277,
12,
1654,
63,
711,
12,
1654,
63,
719,
12,
8486,
63,
515,
12,
16379,
83,
12,
1284,
63,
3058,
29,
403,
304,
1039,
408,
826,
624,
1039,
5796,
14,
4436,
855,
826,
721,
277,
9,
1039,
291,
14,
2921,
275,
2050,
14,
5572,
480,
4437,
967,
14895,
531,
1039,
291,
14,
12110,
83,
275,
16379,
83,
1039,
291,
14,
5899,
63,
515,
275,
8486,
63,
515,
1039,
291,
14,
1000,
63,
719,
275,
1654,
63,
719,
1039,
291,
14,
1000,
63,
711,
275,
1654,
63,
711,
1039,
291,
14,
5720,
275,
715,
1039,
291,
14,
500,
63,
3058,
275,
1284,
63,
3058,
26016,
347,
3631,
8,
277,
304,
1039,
408,
2379,
2112,
624,
1039,
291,
14,
5720,
275,
756,
26016,
347,
1343,
8,
277,
304,
1039,
408,
928,
2112,
624,
1039,
291,
14,
2921,
14,
1757,
360,
4437,
967,
14895,
8239,
358,
1039,
367,
16379,
315,
291,
14,
12110,
83,
26,
1675,
340,
440,
16379,
14,
1989,
63,
498,
360,
344,
735,
2628,
291,
14,
2921,
14,
3764,
360,
26369,
965,
949,
15418,
8546,
31,
1,
18478,
1675,
916,
440,
16379,
14,
1989,
63,
498,
360,
580,
800,
63,
3885,
63,
344,
735,
2628,
291,
14,
2921,
14,
3764,
360,
26369,
2071,
83,
2,
965,
949,
24701,
800,
63,
3885,
63,
344,
901,
7,
450,
16379,
459,
344,
1105,
1675,
587,
26,
2628,
1166,
275,
283,
1014,
13827,
83,
2689,
68,
15,
20544,
3149,
83,
15,
5899,
63,
1960,
88,
1960,
14,
4524,
7,
450,
334,
277,
14,
1000,
63,
711,
12,
291,
14,
1000,
63,
719,
12,
16379,
459,
580,
800,
63,
3885,
63,
344,
1105,
2628,
931,
275,
747,
14,
515,
14,
904,
8,
277,
14,
5899,
63,
515,
12,
1543,
83,
4970,
83,
14,
4524,
7,
450,
334,
12110,
459,
344,
995,
16379,
459,
580,
800,
63,
3885,
63,
344,
5156,
2628,
327,
277,
14,
2921,
14,
1757,
360,
4665,
8486,
520,
1166,
2458,
83,
8486,
2458,
83,
7,
450,
334,
633,
12,
931,
430,
2628,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
304,
4906,
327,
5899,
440,
3495,
4906,
1794,
275,
1551,
8,
515,
12,
283,
6603,
358,
4906,
2517,
275,
4011,
14,
10890,
8,
633,
9,
4906,
1794,
14,
952,
8,
1393,
14,
739,
1012,
4906,
1794,
14,
1600,
342,
17554,
1675,
327,
2379,
5164,
31,
1675,
340,
440,
291,
14,
5720,
26,
2628,
2059,
1039,
291,
14,
2921,
14,
1757,
360,
4437,
967,
14895,
15248,
358,
2999,
268,
1039,
8740,
8740,
8740,
8740,
202,
199,
533,
27540,
7424,
837,
1128,
25764,
50,
4392,
63,
13993,
275,
378,
1128,
25764,
50,
4392,
63,
2160,
2566,
5390,
275,
413,
1128,
25764,
50,
4392,
63,
23612,
1206,
275,
499,
2958,
347,
636,
826,
721,
277,
12,
1654,
63,
711,
12,
1654,
63,
719,
29,
25,
18526,
12,
1654,
63,
751,
4581,
1654,
63,
2060,
9280,
1039,
408,
1880,
624,
1039,
327,
826,
1039,
291,
14,
2921,
275,
2050,
14,
5572,
480,
7424,
531,
13594,
327,
6334,
1039,
291,
14,
1000,
63,
711,
275,
1654,
63,
711,
1039,
291,
14,
1000,
63,
719,
275,
1654,
63,
719,
1039,
291,
855,
5899,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
12131,
21114,
659,
1987,
16597,
14487,
297,
283,
1637,
358,
1039,
340,
440,
747,
14,
515,
14,
2444,
8,
277,
855,
5899,
63,
515,
304,
1675,
327,
981,
2581,
2082,
1675,
747,
14,
8347,
8,
277,
855,
5899,
63,
515,
9,
1039,
291,
855,
1000,
63,
14195,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
12131,
21114,
659,
1987,
16597,
14487,
297,
283,
1000,
14,
2190,
358,
1039,
291,
855,
12110,
83,
63,
835,
275,
378,
1039,
291,
855,
11215,
83,
63,
835,
275,
378,
1039,
291,
855,
2268,
470,
63,
835,
275,
378,
1039,
291,
855,
18431,
63,
835,
275,
378,
13594,
327,
1462,
1039,
291,
14,
1000,
275,
27540,
3120,
8,
1000,
63,
711,
12,
1654,
63,
719,
12,
1654,
63,
751,
12,
1654,
63,
2060,
9,
1039,
291,
14,
1000,
14,
2242,
342,
1039,
291,
14,
1637,
63,
5899,
83,
275,
488,
26016,
347,
636,
2264,
721,
277,
304,
1039,
408,
271,
1426,
624,
1039,
327,
2118,
3631,
7183,
340,
1255,
78,
780,
1039,
340,
291,
14,
1637,
63,
5899,
83,
26,
1675,
291,
14
] |
[
2647,
15,
1393,
15,
1548,
202,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
2999,
199,
624,
202,
199,
2713,
44,
3053,
26,
2018,
21947,
367,
5297,
1175,
335,
12300,
7146,
14214,
334,
52,
352,
846,
9,
14816,
10292,
202,
199,
7384,
334,
35,
9,
6171,
377,
621,
665,
84,
621,
29514,
359,
3287,
61,
23672,
685,
3844,
359,
292,
61,
29712,
359,
3287,
61,
2414,
30,
10292,
202,
199,
44,
3053,
3120,
1021,
365,
4079,
641,
1603,
2361,
2395,
10941,
7840,
665,
74,
2361,
77,
796,
87,
7840,
359,
292,
61,
29712,
359,
3287,
61,
2414,
30,
2999,
199,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
202,
199,
8951,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
202,
199,
305,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
202,
199,
1618,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
2999,
199,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
202,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
202,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
202,
199,
17732,
1696,
1684,
844,
367,
1655,
2436,
14,
2999,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
202,
199,
21632,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
202,
199,
30216,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
12,
8217,
14,
202,
199,
624,
2999,
199,
504,
1134,
15807,
1000,
492,
27540,
3120,
202,
199,
646,
5796,
202,
199,
646,
747,
202,
199,
646,
2050,
202,
199,
646,
4011,
2999,
199,
533,
11977,
967,
14895,
8,
12562,
14,
4436,
304,
1128,
408,
1637,
25858,
367,
10062,
83,
624,
2958,
347,
636,
826,
721,
277,
12,
1654,
63,
711,
12,
1654,
63,
719,
12,
8486,
63,
515,
12,
16379,
83,
12,
1284,
63,
3058,
29,
403,
304,
1039,
408,
826,
624,
1039,
5796,
14,
4436,
855,
826,
721,
277,
9,
1039,
291,
14,
2921,
275,
2050,
14,
5572,
480,
4437,
967,
14895,
531,
1039,
291,
14,
12110,
83,
275,
16379,
83,
1039,
291,
14,
5899,
63,
515,
275,
8486,
63,
515,
1039,
291,
14,
1000,
63,
719,
275,
1654,
63,
719,
1039,
291,
14,
1000,
63,
711,
275,
1654,
63,
711,
1039,
291,
14,
5720,
275,
715,
1039,
291,
14,
500,
63,
3058,
275,
1284,
63,
3058,
26016,
347,
3631,
8,
277,
304,
1039,
408,
2379,
2112,
624,
1039,
291,
14,
5720,
275,
756,
26016,
347,
1343,
8,
277,
304,
1039,
408,
928,
2112,
624,
1039,
291,
14,
2921,
14,
1757,
360,
4437,
967,
14895,
8239,
358,
1039,
367,
16379,
315,
291,
14,
12110,
83,
26,
1675,
340,
440,
16379,
14,
1989,
63,
498,
360,
344,
735,
2628,
291,
14,
2921,
14,
3764,
360,
26369,
965,
949,
15418,
8546,
31,
1,
18478,
1675,
916,
440,
16379,
14,
1989,
63,
498,
360,
580,
800,
63,
3885,
63,
344,
735,
2628,
291,
14,
2921,
14,
3764,
360,
26369,
2071,
83,
2,
965,
949,
24701,
800,
63,
3885,
63,
344,
901,
7,
450,
16379,
459,
344,
1105,
1675,
587,
26,
2628,
1166,
275,
283,
1014,
13827,
83,
2689,
68,
15,
20544,
3149,
83,
15,
5899,
63,
1960,
88,
1960,
14,
4524,
7,
450,
334,
277,
14,
1000,
63,
711,
12,
291,
14,
1000,
63,
719,
12,
16379,
459,
580,
800,
63,
3885,
63,
344,
1105,
2628,
931,
275,
747,
14,
515,
14,
904,
8,
277,
14,
5899,
63,
515,
12,
1543,
83,
4970,
83,
14,
4524,
7,
450,
334,
12110,
459,
344,
995,
16379,
459,
580,
800,
63,
3885,
63,
344,
5156,
2628,
327,
277,
14,
2921,
14,
1757,
360,
4665,
8486,
520,
1166,
2458,
83,
8486,
2458,
83,
7,
450,
334,
633,
12,
931,
430,
2628,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
304,
4906,
327,
5899,
440,
3495,
4906,
1794,
275,
1551,
8,
515,
12,
283,
6603,
358,
4906,
2517,
275,
4011,
14,
10890,
8,
633,
9,
4906,
1794,
14,
952,
8,
1393,
14,
739,
1012,
4906,
1794,
14,
1600,
342,
17554,
1675,
327,
2379,
5164,
31,
1675,
340,
440,
291,
14,
5720,
26,
2628,
2059,
1039,
291,
14,
2921,
14,
1757,
360,
4437,
967,
14895,
15248,
358,
2999,
268,
1039,
8740,
8740,
8740,
8740,
202,
199,
533,
27540,
7424,
837,
1128,
25764,
50,
4392,
63,
13993,
275,
378,
1128,
25764,
50,
4392,
63,
2160,
2566,
5390,
275,
413,
1128,
25764,
50,
4392,
63,
23612,
1206,
275,
499,
2958,
347,
636,
826,
721,
277,
12,
1654,
63,
711,
12,
1654,
63,
719,
29,
25,
18526,
12,
1654,
63,
751,
4581,
1654,
63,
2060,
9280,
1039,
408,
1880,
624,
1039,
327,
826,
1039,
291,
14,
2921,
275,
2050,
14,
5572,
480,
7424,
531,
13594,
327,
6334,
1039,
291,
14,
1000,
63,
711,
275,
1654,
63,
711,
1039,
291,
14,
1000,
63,
719,
275,
1654,
63,
719,
1039,
291,
855,
5899,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
12131,
21114,
659,
1987,
16597,
14487,
297,
283,
1637,
358,
1039,
340,
440,
747,
14,
515,
14,
2444,
8,
277,
855,
5899,
63,
515,
304,
1675,
327,
981,
2581,
2082,
1675,
747,
14,
8347,
8,
277,
855,
5899,
63,
515,
9,
1039,
291,
855,
1000,
63,
14195,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
12131,
21114,
659,
1987,
16597,
14487,
297,
283,
1000,
14,
2190,
358,
1039,
291,
855,
12110,
83,
63,
835,
275,
378,
1039,
291,
855,
11215,
83,
63,
835,
275,
378,
1039,
291,
855,
2268,
470,
63,
835,
275,
378,
1039,
291,
855,
18431,
63,
835,
275,
378,
13594,
327,
1462,
1039,
291,
14,
1000,
275,
27540,
3120,
8,
1000,
63,
711,
12,
1654,
63,
719,
12,
1654,
63,
751,
12,
1654,
63,
2060,
9,
1039,
291,
14,
1000,
14,
2242,
342,
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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
] |
apeyrard/sjtu-work
|
DIP/exercises/ex3/ex3.py
|
1
|
3652
|
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import sys
from PIL import Image
import numpy as np
import math
import argparse
def getMatrix(image):
data = list(image.getdata())
width, height = image.size
matrix = np.array(data).reshape(height,width)
return matrix
def getData(matrix):
data = list(matrix.reshape(matrix.shape[0]*matrix.shape[1]))
return data
def preprocessing(matrix):
newMat = matrix.copy()
for y in range(newMat.shape[1]):
for x in range(newMat.shape[0]):
newMat[x][y] = newMat[x][y]*(-1)**(x+y)
return newMat
def postprocessing(matrix):
return preprocessing(matrix)
def ideal(matrix, cutoff, function):
newMat = matrix.copy()
center = (math.floor(newMat.shape[0]/2), math.floor(newMat.shape[1]/2))
for y in range(newMat.shape[1]):
for x in range(newMat.shape[0]):
dist = math.sqrt((x-center[0])**2+(y-center[1])**2)
if function == 'low':
if dist > cutoff:
newMat[x][y] = 0+0j
if function == 'high':
if dist < cutoff:
newMat[x][y] = 0+0j
return newMat
def butter(matrix, order, cutoff, function):
if order is None:
print("Order must be specified for butterworth filter")
sys.exit(1)
newMat = matrix.copy()
center = (math.floor(newMat.shape[0]/2), math.floor(newMat.shape[1]/2))
for y in range(newMat.shape[1]):
for x in range(newMat.shape[0]):
dist = math.sqrt((x-center[0])**2+(y-center[1])**2)
if function == 'low':
newMat[x][y] = newMat[x][y] * (1/(1+(dist/cutoff)**(2*order)))
if function == 'high':
newMat[x][y] = newMat[x][y] * (1-(1/(1+(dist/cutoff)**(2*order))))
return newMat
def gauss(matrix, cutoff, function):
newMat = matrix.copy()
center = (math.floor(newMat.shape[0]/2), math.floor(newMat.shape[1]/2))
for y in range(newMat.shape[1]):
for x in range(newMat.shape[0]):
dist = math.sqrt((x-center[0])**2+(y-center[1])**2)
if function == 'low':
newMat[x][y] = newMat[x][y] * (math.exp(-(dist**2)/(2*(cutoff**2))))
if function == 'high':
newMat[x][y] = newMat[x][y] * (1- (math.exp(-(dist**2)/(2*(cutoff**2)))))
return newMat
parser = argparse.ArgumentParser(description='Filtering in frequency domain')
parser.add_argument('--ideal', action='store_true')
parser.add_argument('--butterworth', action='store_true')
parser.add_argument('--gaussian', action='store_true')
parser.add_argument('--highpass', action='store_true')
parser.add_argument('--lowpass', action='store_true')
parser.add_argument('cutoff', type=float)
parser.add_argument('--order', type=float)
parser.add_argument('image')
args = parser.parse_args()
try:
with Image.open(args.image) as im:
if args.lowpass:
filtering = 'low'
else:
filtering = 'high'
imNew = Image.new(im.mode, im.size)
matrix = getMatrix(im)
prepMat = preprocessing(matrix)
fourierMat = np.fft.fft2(prepMat)
if args.ideal:
imageF = ideal(fourierMat, args.cutoff, filtering)
elif args.butterworth:
imageF = butter(fourierMat, args.order, args.cutoff, filtering)
else:
imageF = gauss(fourierMat, args.cutoff, filtering)
newImage = np.fft.ifft2(imageF)
postNew = postprocessing(newImage)
imNew.putdata(getData(postNew))
imNew.show()
except FileNotFoundError as e:
sys.exit("Error : file not found")
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1882,
2803,
26,
9094,
13,
24,
1882,
199,
199,
646,
984,
199,
199,
504,
14937,
492,
6047,
199,
646,
2680,
465,
980,
199,
646,
3473,
199,
646,
7534,
199,
199,
318,
664,
6443,
8,
1569,
304,
272,
666,
275,
769,
8,
1569,
14,
29160,
1012,
272,
3462,
12,
4569,
275,
1834,
14,
890,
272,
3634,
275,
980,
14,
1144,
8,
576,
680,
5217,
8,
3333,
12,
2063,
9,
272,
372,
3634,
199,
199,
318,
664,
1451,
8,
3642,
304,
272,
666,
275,
769,
8,
3642,
14,
5217,
8,
3642,
14,
1392,
59,
16,
3672,
3642,
14,
1392,
59,
17,
2459,
272,
372,
666,
199,
199,
318,
26471,
8,
3642,
304,
272,
892,
14817,
275,
3634,
14,
1574,
342,
272,
367,
612,
315,
1425,
8,
1222,
14817,
14,
1392,
59,
17,
4682,
267,
367,
671,
315,
1425,
8,
1222,
14817,
14,
1392,
59,
16,
4682,
288,
892,
14817,
59,
88,
1527,
89,
61,
275,
892,
14817,
59,
88,
1527,
89,
3672,
2801,
17,
25288,
88,
11,
89,
9,
272,
372,
892,
14817,
199,
199,
318,
2963,
6338,
8,
3642,
304,
272,
372,
26471,
8,
3642,
9,
199,
199,
318,
28264,
8,
3642,
12,
17875,
12,
805,
304,
272,
892,
14817,
275,
3634,
14,
1574,
342,
272,
8126,
275,
334,
3442,
14,
11289,
8,
1222,
14817,
14,
1392,
59,
16,
12978,
18,
395,
3473,
14,
11289,
8,
1222,
14817,
14,
1392,
59,
17,
12978,
18,
430,
272,
367,
612,
315,
1425,
8,
1222,
14817,
14,
1392,
59,
17,
4682,
267,
367,
671,
315,
1425,
8,
1222,
14817,
14,
1392,
59,
16,
4682,
288,
2917,
275,
3473,
14,
5079,
1332,
88,
13,
4218,
59,
16,
566,
538,
18,
15622,
89,
13,
4218,
59,
17,
566,
538,
18,
9,
288,
340,
805,
508,
283,
674,
356,
355,
340,
2917,
690,
17875,
26,
490,
892,
14817,
59,
88,
1527,
89,
61,
275,
378,
11,
16,
74,
288,
340,
805,
508,
283,
6260,
356,
355,
340,
2917,
665,
17875,
26,
490,
892,
14817,
59,
88,
1527,
89,
61,
275,
378,
11,
16,
74,
272,
372,
892,
14817,
199,
199,
318,
1325,
351,
8,
3642,
12,
1865,
12,
17875,
12,
805,
304,
272,
340,
1865,
365,
488,
26,
267,
870,
480,
4738,
1471,
506,
2013,
367,
1325,
351,
584,
273,
2457,
531,
267,
984,
14,
2224,
8,
17,
9,
272,
892,
14817,
275,
3634,
14,
1574,
342,
272,
8126,
275,
334,
3442,
14,
11289,
8,
1222,
14817,
14,
1392,
59,
16,
12978,
18,
395,
3473,
14,
11289,
8,
1222,
14817,
14,
1392,
59,
17,
12978,
18,
430,
272,
367,
612,
315,
1425,
8,
1222,
14817,
14,
1392,
59,
17,
4682,
267,
367,
671,
315,
1425,
8,
1222,
14817,
14,
1392,
59,
16,
4682,
288,
2917,
275,
3473,
14,
5079,
1332,
88,
13,
4218,
59,
16,
566,
538,
18,
15622,
89,
13,
4218,
59,
17,
566,
538,
18,
9,
288,
340,
805,
508,
283,
674,
356,
355,
892,
14817,
59,
88,
1527,
89,
61,
275,
892,
14817,
59,
88,
1527,
89,
61,
627,
334,
17,
7985,
17,
15622,
2686,
15,
17708,
25288,
18,
10,
1648,
1724,
953,
340,
805,
508,
283,
6260,
356,
355,
892,
14817,
59,
88,
1527,
89,
61,
275,
892,
14817,
59,
88,
1527,
89,
61,
627,
334,
17,
15426,
17,
7985,
17,
15622,
2686,
15,
17708,
25288,
18,
10,
1648,
7845,
272,
372,
892,
14817,
199,
199,
318,
486,
23822,
8,
3642,
12,
17875,
12,
805,
304,
272,
892,
14817,
275,
3634,
14,
1574,
342,
272,
8126,
275,
334,
3442,
14,
11289,
8,
1222,
14817,
14,
1392,
59,
16,
12978,
18,
395,
3473,
14,
11289,
8,
1222,
14817,
14,
1392,
59,
17,
12978,
18,
430,
272,
367,
612,
315,
1425,
8,
1222,
14817,
14,
1392,
59,
17,
4682,
267,
367,
671,
315,
1425,
8,
1222,
14817,
14,
1392,
59,
16,
4682,
288,
2917,
275,
3473,
14,
5079,
1332,
88,
13,
4218,
59,
16,
566,
538,
18,
15622,
89,
13,
4218,
59,
17,
566,
538,
18,
9,
288,
340,
805,
508,
283,
674,
356,
355,
892,
14817,
59,
88,
1527,
89,
61,
275,
892,
14817,
59,
88,
1527,
89,
61,
627,
334,
3442,
14,
1474,
2801,
8,
2686,
538,
18,
15136,
18,
5830,
17708,
538,
18,
7845,
288,
340,
805,
508,
283,
6260,
356,
355,
892,
14817,
59,
88,
1527,
89,
61,
275,
892,
14817,
59,
88,
1527,
89,
61,
627,
334,
17,
13,
334,
3442,
14,
1474,
2801,
8,
2686,
538,
18,
15136,
18,
5830,
17708,
538,
18,
430,
1724,
272,
372,
892,
14817,
199,
199,
2087,
275,
7534,
14,
10730,
8,
1802,
534,
4131,
316,
315,
9857,
2881,
358,
199,
2087,
14,
525,
63,
2094,
4517,
32564,
297,
1595,
534,
1617,
63,
2052,
358,
199,
2087,
14,
525,
63,
2094,
4517,
7911,
351,
584,
273,
297,
1595,
534,
1617,
63,
2052,
358,
199,
2087,
14,
525,
63,
2094,
4517,
22911,
297,
1595,
534,
1617,
63,
2052,
358,
199,
2087,
14,
525,
63,
2094,
4517,
6260,
1529,
297,
1595,
534,
1617,
63,
2052,
358,
199,
2087,
14,
525,
63,
2094,
4517,
674,
1529,
297,
1595,
534,
1617,
63,
2052,
358,
199,
2087,
14,
525,
63,
2094,
360,
17708,
297,
730,
29,
1609,
9,
199,
2087,
14,
525,
63,
2094,
4517,
1648,
297,
730,
29,
1609,
9,
199,
2087,
14,
525,
63,
2094,
360,
1569,
358,
199,
199,
589,
275,
221,
1798,
14,
1122,
63,
589,
342,
199,
199,
893,
26,
272,
543,
6047,
14,
1490,
8,
589,
14,
1569,
9,
465,
3416,
26,
267,
340,
1249,
14,
674,
1529,
26,
288,
14545,
275,
283,
674,
7,
267,
587,
26,
288,
14545,
275,
283,
6260,
7,
267,
3416,
4665,
275,
6047,
14,
1222,
8,
1017,
14,
632,
12,
3416,
14,
890,
9,
398,
3634,
275,
664,
6443,
8,
1017,
9,
398,
19986,
14817,
275,
26471,
8,
3642,
9,
267,
11648,
4446,
14817,
275,
980,
14,
9996,
14,
9996,
18,
8,
10837,
14817,
9,
398,
340,
1249,
14,
32564,
26,
288,
1834,
38,
275,
28264,
8,
545,
2302,
281,
14817,
12,
1249,
14,
17708,
12,
14545,
9,
267,
916,
1249,
14,
7911,
351,
584,
273,
26,
288,
1834,
38,
275,
1325,
351,
8,
545,
2302,
281,
14817,
12,
1249,
14
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1882,
2803,
26,
9094,
13,
24,
1882,
199,
199,
646,
984,
199,
199,
504,
14937,
492,
6047,
199,
646,
2680,
465,
980,
199,
646,
3473,
199,
646,
7534,
199,
199,
318,
664,
6443,
8,
1569,
304,
272,
666,
275,
769,
8,
1569,
14,
29160,
1012,
272,
3462,
12,
4569,
275,
1834,
14,
890,
272,
3634,
275,
980,
14,
1144,
8,
576,
680,
5217,
8,
3333,
12,
2063,
9,
272,
372,
3634,
199,
199,
318,
664,
1451,
8,
3642,
304,
272,
666,
275,
769,
8,
3642,
14,
5217,
8,
3642,
14,
1392,
59,
16,
3672,
3642,
14,
1392,
59,
17,
2459,
272,
372,
666,
199,
199,
318,
26471,
8,
3642,
304,
272,
892,
14817,
275,
3634,
14,
1574,
342,
272,
367,
612,
315,
1425,
8,
1222,
14817,
14,
1392,
59,
17,
4682,
267,
367,
671,
315,
1425,
8,
1222,
14817,
14,
1392,
59,
16,
4682,
288,
892,
14817,
59,
88,
1527,
89,
61,
275,
892,
14817,
59,
88,
1527,
89,
3672,
2801,
17,
25288,
88,
11,
89,
9,
272,
372,
892,
14817,
199,
199,
318,
2963,
6338,
8,
3642,
304,
272,
372,
26471,
8,
3642,
9,
199,
199,
318,
28264,
8,
3642,
12,
17875,
12,
805,
304,
272,
892,
14817,
275,
3634,
14,
1574,
342,
272,
8126,
275,
334,
3442,
14,
11289,
8,
1222,
14817,
14,
1392,
59,
16,
12978,
18,
395,
3473,
14,
11289,
8,
1222,
14817,
14,
1392,
59,
17,
12978,
18,
430,
272,
367,
612,
315,
1425,
8,
1222,
14817,
14,
1392,
59,
17,
4682,
267,
367,
671,
315,
1425,
8,
1222,
14817,
14,
1392,
59,
16,
4682,
288,
2917,
275,
3473,
14,
5079,
1332,
88,
13,
4218,
59,
16,
566,
538,
18,
15622,
89,
13,
4218,
59,
17,
566,
538,
18,
9,
288,
340,
805,
508,
283,
674,
356,
355,
340,
2917,
690,
17875,
26,
490,
892,
14817,
59,
88,
1527,
89,
61,
275,
378,
11,
16,
74,
288,
340,
805,
508,
283,
6260,
356,
355,
340,
2917,
665,
17875,
26,
490,
892,
14817,
59,
88,
1527,
89,
61,
275,
378,
11,
16,
74,
272,
372,
892,
14817,
199,
199,
318,
1325,
351,
8,
3642,
12,
1865,
12,
17875,
12,
805,
304,
272,
340,
1865,
365,
488,
26,
267,
870,
480,
4738,
1471,
506,
2013,
367,
1325,
351,
584,
273,
2457,
531,
267,
984,
14,
2224,
8,
17,
9,
272,
892,
14817,
275,
3634,
14,
1574,
342,
272,
8126,
275,
334,
3442,
14,
11289,
8,
1222,
14817,
14,
1392,
59,
16,
12978,
18,
395,
3473,
14,
11289,
8,
1222,
14817,
14,
1392,
59,
17,
12978,
18,
430,
272,
367,
612,
315,
1425,
8,
1222,
14817,
14,
1392,
59,
17,
4682,
267,
367,
671,
315,
1425,
8,
1222,
14817,
14,
1392,
59,
16,
4682,
288,
2917,
275,
3473,
14,
5079,
1332,
88,
13,
4218,
59,
16,
566,
538,
18,
15622,
89,
13,
4218,
59,
17,
566,
538,
18,
9,
288,
340,
805,
508,
283,
674,
356,
355,
892,
14817,
59,
88,
1527,
89,
61,
275,
892,
14817,
59,
88,
1527,
89,
61,
627,
334,
17,
7985,
17,
15622,
2686,
15,
17708,
25288,
18,
10,
1648,
1724,
953,
340,
805,
508,
283,
6260,
356,
355,
892,
14817,
59,
88,
1527,
89,
61,
275,
892,
14817,
59,
88,
1527,
89,
61,
627,
334,
17,
15426,
17,
7985,
17,
15622,
2686,
15,
17708,
25288,
18,
10,
1648,
7845,
272,
372,
892,
14817,
199,
199,
318,
486,
23822,
8,
3642,
12,
17875,
12,
805,
304,
272,
892,
14817,
275,
3634,
14,
1574,
342,
272,
8126,
275,
334,
3442,
14,
11289,
8,
1222,
14817,
14,
1392,
59,
16,
12978,
18,
395,
3473,
14,
11289,
8,
1222,
14817,
14,
1392,
59,
17,
12978,
18,
430,
272,
367,
612,
315,
1425,
8,
1222,
14817,
14,
1392,
59,
17,
4682,
267,
367,
671,
315,
1425,
8,
1222,
14817,
14,
1392,
59,
16,
4682,
288,
2917,
275,
3473,
14,
5079,
1332,
88,
13,
4218,
59,
16,
566,
538,
18,
15622,
89,
13,
4218,
59,
17,
566,
538,
18,
9,
288,
340,
805,
508,
283,
674,
356,
355,
892,
14817,
59,
88,
1527,
89,
61,
275,
892,
14817,
59,
88,
1527,
89,
61,
627,
334,
3442,
14,
1474,
2801,
8,
2686,
538,
18,
15136,
18,
5830,
17708,
538,
18,
7845,
288,
340,
805,
508,
283,
6260,
356,
355,
892,
14817,
59,
88,
1527,
89,
61,
275,
892,
14817,
59,
88,
1527,
89,
61,
627,
334,
17,
13,
334,
3442,
14,
1474,
2801,
8,
2686,
538,
18,
15136,
18,
5830,
17708,
538,
18,
430,
1724,
272,
372,
892,
14817,
199,
199,
2087,
275,
7534,
14,
10730,
8,
1802,
534,
4131,
316,
315,
9857,
2881,
358,
199,
2087,
14,
525,
63,
2094,
4517,
32564,
297,
1595,
534,
1617,
63,
2052,
358,
199,
2087,
14,
525,
63,
2094,
4517,
7911,
351,
584,
273,
297,
1595,
534,
1617,
63,
2052,
358,
199,
2087,
14,
525,
63,
2094,
4517,
22911,
297,
1595,
534,
1617,
63,
2052,
358,
199,
2087,
14,
525,
63,
2094,
4517,
6260,
1529,
297,
1595,
534,
1617,
63,
2052,
358,
199,
2087,
14,
525,
63,
2094,
4517,
674,
1529,
297,
1595,
534,
1617,
63,
2052,
358,
199,
2087,
14,
525,
63,
2094,
360,
17708,
297,
730,
29,
1609,
9,
199,
2087,
14,
525,
63,
2094,
4517,
1648,
297,
730,
29,
1609,
9,
199,
2087,
14,
525,
63,
2094,
360,
1569,
358,
199,
199,
589,
275,
221,
1798,
14,
1122,
63,
589,
342,
199,
199,
893,
26,
272,
543,
6047,
14,
1490,
8,
589,
14,
1569,
9,
465,
3416,
26,
267,
340,
1249,
14,
674,
1529,
26,
288,
14545,
275,
283,
674,
7,
267,
587,
26,
288,
14545,
275,
283,
6260,
7,
267,
3416,
4665,
275,
6047,
14,
1222,
8,
1017,
14,
632,
12,
3416,
14,
890,
9,
398,
3634,
275,
664,
6443,
8,
1017,
9,
398,
19986,
14817,
275,
26471,
8,
3642,
9,
267,
11648,
4446,
14817,
275,
980,
14,
9996,
14,
9996,
18,
8,
10837,
14817,
9,
398,
340,
1249,
14,
32564,
26,
288,
1834,
38,
275,
28264,
8,
545,
2302,
281,
14817,
12,
1249,
14,
17708,
12,
14545,
9,
267,
916,
1249,
14,
7911,
351,
584,
273,
26,
288,
1834,
38,
275,
1325,
351,
8,
545,
2302,
281,
14817,
12,
1249,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
luk156/minimo
|
minimo/documento/migrations/0004_auto__add_unitamisura__add_field_riga_unita.py
|
1
|
10331
|
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding model 'UnitaMisura'
db.create_table(u'documento_unitamisura', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('nome', self.gf('django.db.models.fields.CharField')(default='Numero', max_length=30)),
('sigla', self.gf('django.db.models.fields.CharField')(default='N', max_length=4)),
('stato', self.gf('django.db.models.fields.BooleanField')(default=True)),
))
db.send_create_signal(u'documento', ['UnitaMisura'])
# Adding field 'Riga.unita'
db.add_column(u'documento_riga', 'unita',
self.gf('django.db.models.fields.related.ForeignKey')(default=None, to=orm['documento.UnitaMisura'], null=True, blank=True),
keep_default=False)
def backwards(self, orm):
# Deleting model 'UnitaMisura'
db.delete_table(u'documento_unitamisura')
# Deleting field 'Riga.unita'
db.delete_column(u'documento_riga', 'unita_id')
models = {
u'auth.group': {
'Meta': {'object_name': 'Group'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
u'auth.permission': {
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
u'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
u'documento.documento': {
'Meta': {'ordering': "['data']", 'object_name': 'Documento'},
'bollo': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'}),
'cap': ('django.db.models.fields.CharField', [], {'max_length': '6', 'null': 'True', 'blank': 'True'}),
'citta': ('django.db.models.fields.CharField', [], {'max_length': '70', 'null': 'True', 'blank': 'True'}),
'cod_fiscale': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True', 'blank': 'True'}),
'data': ('django.db.models.fields.DateField', [], {}),
'data_consegna': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
'descrizione_ritenuta': ('django.db.models.fields.CharField', [], {'max_length': '70', 'null': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'importo_residuo': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
'note': ('django.db.models.fields.TextField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
'numero': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'p_iva': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'}),
'pagamento': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['documento.Pagamento']", 'null': 'True', 'blank': 'True'}),
'provincia': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}),
'ragione_sociale': ('django.db.models.fields.CharField', [], {'max_length': '70', 'null': 'True', 'blank': 'True'}),
'riferimento': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['documento.Documento']", 'null': 'True', 'blank': 'True'}),
'ritenuta': ('django.db.models.fields.IntegerField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
'sconto': ('django.db.models.fields.IntegerField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
'stato': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'template': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'documento_template'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': u"orm['template.TemplateDocumento']"}),
'tipo': ('django.db.models.fields.CharField', [], {'max_length': '5'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
'valore_bollo': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
'via': ('django.db.models.fields.CharField', [], {'max_length': '70', 'null': 'True', 'blank': 'True'})
},
u'documento.pagamento': {
'Meta': {'object_name': 'Pagamento'},
'giorni': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'iban': ('django.db.models.fields.CharField', [], {'max_length': '70', 'null': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'intestazione': ('django.db.models.fields.CharField', [], {'max_length': '70', 'null': 'True', 'blank': 'True'}),
'istituto': ('django.db.models.fields.CharField', [], {'max_length': '70', 'null': 'True', 'blank': 'True'}),
'nome': ('django.db.models.fields.CharField', [], {'max_length': '30'}),
'stato': ('django.db.models.fields.BooleanField', [], {'default': 'True'})
},
u'documento.riga': {
'Meta': {'object_name': 'Riga'},
'codice': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '70', 'null': 'True', 'blank': 'True'}),
'descrizione': ('django.db.models.fields.TextField', [], {}),
'descrizione_imposta': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '70', 'null': 'True', 'blank': 'True'}),
'documento': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['documento.Documento']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'importo_unitario': ('django.db.models.fields.FloatField', [], {'default': '1'}),
'imposta': ('django.db.models.fields.IntegerField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
'quantita': ('django.db.models.fields.FloatField', [], {}),
'unita': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': u"orm['documento.UnitaMisura']", 'null': 'True', 'blank': 'True'})
},
u'documento.unitamisura': {
'Meta': {'object_name': 'UnitaMisura'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'nome': ('django.db.models.fields.CharField', [], {'default': "'Numero'", 'max_length': '30'}),
'sigla': ('django.db.models.fields.CharField', [], {'default': "'N'", 'max_length': '4'}),
'stato': ('django.db.models.fields.BooleanField', [], {'default': 'True'})
},
u'template.templatedocumento': {
'Meta': {'object_name': 'TemplateDocumento'},
'descrizione': ('django.db.models.fields.CharField', [], {'max_length': '70', 'null': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'nome': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '70'}),
'template': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"})
}
}
complete_apps = ['documento']
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
12934,
1402,
283,
5072,
65,
5829,
12417,
7,
267,
1592,
14,
981,
63,
1224,
8,
85,
5121,
679,
760,
79,
63,
3248,
455,
374,
12417,
297,
334,
288,
334,
85,
7,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
7533,
3327,
63,
498,
29,
549,
1826,
288,
661,
29897,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
885,
534,
46,
940,
293,
297,
1390,
63,
1267,
29,
1216,
1826,
288,
661,
4093,
416,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
885,
534,
46,
297,
1390,
63,
1267,
29,
20,
1826,
288,
661,
3736,
79,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
7533,
885,
29,
549,
1826,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
8,
85,
5121,
679,
760,
79,
297,
788,
5072,
65,
5829,
12417,
1105,
398,
327,
12934,
901,
283,
50,
29055,
14,
3248,
65,
7,
267,
1592,
14,
525,
63,
2301,
8,
85,
5121,
679,
760,
79,
63,
322,
5294,
297,
283,
3248,
65,
297,
1993,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
885,
29,
403,
12,
370,
29,
1025,
459,
3554,
79,
14,
5072,
65,
5829,
12417,
995,
2973,
29,
549,
12,
4596,
29,
549,
395,
1993,
4215,
63,
885,
29,
797,
9,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
15920,
1402,
283,
5072,
65,
5829,
12417,
7,
267,
1592,
14,
1807,
63,
1224,
8,
85,
5121,
679,
760,
79,
63,
3248,
455,
374,
12417,
358,
398,
327,
15920,
901,
283,
50,
29055,
14,
3248,
65,
7,
267,
1592,
14,
1807,
63,
2301,
8,
85,
5121,
679,
760,
79,
63,
322,
5294,
297,
283,
3248,
65,
63,
344,
358,
2378,
1709,
275,
469,
267,
399,
7,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
399,
7,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
7340,
85,
7,
1317,
63,
466,
363,
571,
63,
1302,
297,
399,
7,
1317,
63,
466,
363,
1238,
297,
399,
7,
11879,
18106,
283,
3235,
63,
6314,
356,
298,
1332,
85,
7,
1317,
63,
466,
297,
399,
7,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
10778,
14,
11282,
6097,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
399,
7,
1178,
14,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
988,
63,
1267,
356,
283,
2194,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2634,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1178,
14,
2448,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
2682,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
374,
63,
7018,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
374,
63,
11434,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
2019,
63,
2886,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2019,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
3933,
1604,
288,
283,
751,
63,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
12934,
1402,
283,
5072,
65,
5829,
12417,
7,
267,
1592,
14,
981,
63,
1224,
8,
85,
5121,
679,
760,
79,
63,
3248,
455,
374,
12417,
297,
334,
288,
334,
85,
7,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
7533,
3327,
63,
498,
29,
549,
1826,
288,
661,
29897,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
885,
534,
46,
940,
293,
297,
1390,
63,
1267,
29,
1216,
1826,
288,
661,
4093,
416,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
885,
534,
46,
297,
1390,
63,
1267,
29,
20,
1826,
288,
661,
3736,
79,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
7533,
885,
29,
549,
1826,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
8,
85,
5121,
679,
760,
79,
297,
788,
5072,
65,
5829,
12417,
1105,
398,
327,
12934,
901,
283,
50,
29055,
14,
3248,
65,
7,
267,
1592,
14,
525,
63,
2301,
8,
85,
5121,
679,
760,
79,
63,
322,
5294,
297,
283,
3248,
65,
297,
1993,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
885,
29,
403,
12,
370,
29,
1025,
459,
3554,
79,
14,
5072,
65,
5829,
12417,
995,
2973,
29,
549,
12,
4596,
29,
549,
395,
1993,
4215,
63,
885,
29,
797,
9,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
15920,
1402,
283,
5072,
65,
5829,
12417,
7,
267,
1592,
14,
1807,
63,
1224,
8,
85,
5121,
679,
760,
79,
63,
3248,
455,
374,
12417,
358,
398,
327,
15920,
901,
283,
50,
29055,
14,
3248,
65,
7,
267,
1592,
14,
1807,
63,
2301,
8,
85,
5121,
679,
760,
79,
63,
322,
5294,
297,
283,
3248,
65,
63,
344,
358,
2378,
1709,
275,
469,
267,
399,
7,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
399,
7,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
7340,
85,
7,
1317,
63,
466,
363,
571,
63,
1302,
297,
399,
7,
1317,
63,
466,
363,
1238,
297,
399,
7,
11879,
18106,
283,
3235,
63,
6314,
356,
298,
1332,
85,
7,
1317,
63,
466,
297,
399,
7,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
10778,
14,
11282,
6097,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
399,
7,
1178,
14,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
988,
63,
1267,
356,
283,
2194,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2634,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1178,
14,
2448,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
2682,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
374,
63,
7018,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
374,
63,
11434,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
2019,
63,
2886,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2019,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
3933,
1604,
288,
283,
751,
63,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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argparse
import copy
import multiprocessing as mp
import os
import sys
import statistics
import time
import chainer
from chainer import links as L
from chainer import functions as F
import cv2
import numpy as np
import a3c
import random_seed
import async
from prepare_output_dir import prepare_output_dir
def eval_performance(process_idx, make_env, model, phi, n_runs):
assert n_runs > 1, 'Computing stdev requires at least two runs'
scores = []
for i in range(n_runs):
model.reset_state()
env = make_env(process_idx, test=True)
obs = env.reset()
done = False
test_r = 0
while not done:
s = chainer.Variable(np.expand_dims(phi(obs), 0))
pout, _ = model.pi_and_v(s)
a = pout.action_indices[0]
obs, r, done, info = env.step(a)
test_r += r
scores.append(test_r)
print('test_{}:'.format(i), test_r)
mean = statistics.mean(scores)
median = statistics.median(scores)
stdev = statistics.stdev(scores)
return mean, median, stdev
def train_loop(process_idx, counter, make_env, max_score, args, agent, env,
start_time, outdir):
try:
total_r = 0
episode_r = 0
global_t = 0
local_t = 0
obs = env.reset()
r = 0
done = False
while True:
# Get and increment the global counter
with counter.get_lock():
counter.value += 1
global_t = counter.value
local_t += 1
if global_t > args.steps:
break
agent.optimizer.lr = (
args.steps - global_t - 1) / args.steps * args.lr
total_r += r
episode_r += r
a = agent.act(obs, r, done)
if done:
if process_idx == 0:
print('{} global_t:{} local_t:{} lr:{} r:{}'.format(
outdir, global_t, local_t, agent.optimizer.lr,
episode_r))
episode_r = 0
obs = env.reset()
r = 0
done = False
else:
obs, r, done, info = env.step(a)
if global_t % args.eval_frequency == 0:
# Evaluation
# We must use a copy of the model because test runs can change
# the hidden states of the model
test_model = copy.deepcopy(agent.model)
test_model.reset_state()
mean, median, stdev = eval_performance(
process_idx, make_env, test_model, agent.phi,
args.eval_n_runs)
with open(os.path.join(outdir, 'scores.txt'), 'a+') as f:
elapsed = time.time() - start_time
record = (global_t, elapsed, mean, median, stdev)
print('\t'.join(str(x) for x in record), file=f)
with max_score.get_lock():
if mean > max_score.value:
# Save the best model so far
print('The best score is updated {} -> {}'.format(
max_score.value, mean))
filename = os.path.join(
outdir, '{}.h5'.format(global_t))
agent.save_model(filename)
print('Saved the current best model to {}'.format(
filename))
max_score.value = mean
except KeyboardInterrupt:
if process_idx == 0:
# Save the current model before being killed
agent.save_model(os.path.join(
outdir, '{}_keyboardinterrupt.h5'.format(global_t)))
print('Saved the current model to {}'.format(
outdir), file=sys.stderr)
raise
if global_t == args.steps + 1:
# Save the final model
agent.save_model(
os.path.join(args.outdir, '{}_finish.h5'.format(args.steps)))
print('Saved the final model to {}'.format(args.outdir))
def train_loop_with_profile(process_idx, counter, make_env, max_score, args,
agent, env, start_time, outdir):
import cProfile
cmd = 'train_loop(process_idx, counter, make_env, max_score, args, ' \
'agent, env, start_time)'
cProfile.runctx(cmd, globals(), locals(),
'profile-{}.out'.format(os.getpid()))
def run_a3c(processes, make_env, model_opt, phi, t_max=1, beta=1e-2,
profile=False, steps=8 * 10 ** 7, eval_frequency=10 ** 6,
eval_n_runs=10, args={}):
# Prevent numpy from using multiple threads
os.environ['OMP_NUM_THREADS'] = '1'
outdir = prepare_output_dir(args, None)
print('Output files are saved in {}'.format(outdir))
n_actions = 20 * 20
model, opt = model_opt()
shared_params = async.share_params_as_shared_arrays(model)
shared_states = async.share_states_as_shared_arrays(opt)
max_score = mp.Value('f', np.finfo(np.float32).min)
counter = mp.Value('l', 0)
start_time = time.time()
# Write a header line first
with open(os.path.join(outdir, 'scores.txt'), 'a+') as f:
column_names = ('steps', 'elapsed', 'mean', 'median', 'stdev')
print('\t'.join(column_names), file=f)
def run_func(process_idx):
env = make_env(process_idx, test=False)
model, opt = model_opt()
async.set_shared_params(model, shared_params)
async.set_shared_states(opt, shared_states)
agent = a3c.A3C(model, opt, t_max, 0.99, beta=beta,
process_idx=process_idx, phi=phi)
if profile:
train_loop_with_profile(process_idx, counter, make_env, max_score,
args, agent, env, start_time,
outdir=outdir)
else:
train_loop(process_idx, counter, make_env, max_score,
args, agent, env, start_time, outdir=outdir)
async.run_async(processes, run_func)
|
mit
|
[
646,
7534,
199,
646,
1331,
199,
646,
12866,
465,
6118,
199,
646,
747,
199,
646,
984,
199,
646,
11076,
199,
646,
900,
199,
199,
646,
20333,
199,
504,
20333,
492,
6220,
465,
491,
199,
504,
20333,
492,
3423,
465,
481,
199,
646,
6277,
18,
199,
646,
2680,
465,
980,
199,
199,
646,
282,
19,
67,
199,
646,
2196,
63,
5176,
199,
646,
5316,
199,
504,
9275,
63,
1199,
63,
694,
492,
9275,
63,
1199,
63,
694,
421,
199,
318,
3468,
63,
20576,
8,
1412,
63,
2996,
12,
1852,
63,
1813,
12,
1402,
12,
14524,
12,
302,
63,
10802,
304,
272,
702,
302,
63,
10802,
690,
413,
12,
283,
2404,
4655,
410,
2374,
5074,
737,
5210,
2877,
7858,
7,
272,
9342,
275,
942,
272,
367,
284,
315,
1425,
8,
78,
63,
10802,
304,
267,
1402,
14,
3958,
63,
929,
342,
267,
2589,
275,
1852,
63,
1813,
8,
1412,
63,
2996,
12,
511,
29,
549,
9,
267,
16087,
275,
2589,
14,
3958,
342,
267,
4224,
275,
756,
267,
511,
63,
82,
275,
378,
267,
1830,
440,
4224,
26,
288,
308,
275,
20333,
14,
2773,
8,
1590,
14,
4441,
63,
5380,
8,
10909,
8,
11226,
395,
378,
430,
288,
299,
548,
12,
485,
275,
1402,
14,
1038,
63,
460,
63,
86,
8,
83,
9,
288,
282,
275,
299,
548,
14,
1287,
63,
4108,
59,
16,
61,
288,
16087,
12,
519,
12,
4224,
12,
2256,
275,
2589,
14,
2926,
8,
65,
9,
288,
511,
63,
82,
847,
519,
267,
9342,
14,
740,
8,
396,
63,
82,
9,
267,
870,
360,
396,
24306,
26,
1370,
908,
8,
73,
395,
511,
63,
82,
9,
272,
4615,
275,
11076,
14,
3670,
8,
7107,
9,
272,
17312,
275,
11076,
14,
13106,
8,
7107,
9,
272,
410,
2374,
275,
11076,
14,
270,
2374,
8,
7107,
9,
272,
372,
4615,
12,
17312,
12,
410,
2374,
421,
199,
318,
3560,
63,
3813,
8,
1412,
63,
2996,
12,
7055,
12,
1852,
63,
1813,
12,
1390,
63,
3397,
12,
1249,
12,
6631,
12,
2589,
12,
2049,
1343,
63,
521,
12,
24670,
304,
272,
862,
26,
398,
3141,
63,
82,
275,
378,
267,
11052,
63,
82,
275,
378,
267,
2288,
63,
84,
275,
378,
267,
2257,
63,
84,
275,
378,
267,
16087,
275,
2589,
14,
3958,
342,
267,
519,
275,
378,
267,
4224,
275,
756,
398,
1830,
715,
26,
953,
327,
2372,
436,
11609,
314,
2288,
7055,
288,
543,
7055,
14,
362,
63,
831,
837,
355,
7055,
14,
585,
847,
413,
355,
2288,
63,
84,
275,
7055,
14,
585,
288,
2257,
63,
84,
847,
413,
953,
340,
2288,
63,
84,
690,
1249,
14,
5895,
26,
355,
2059,
953,
6631,
14,
12290,
14,
7493,
275,
334,
355,
1249,
14,
5895,
446,
2288,
63,
84,
446,
413,
9,
1182,
1249,
14,
5895,
627,
1249,
14,
7493,
953,
3141,
63,
82,
847,
519,
288,
11052,
63,
82,
847,
519,
953,
282,
275,
6631,
14,
2442,
8,
11226,
12,
519,
12,
4224,
9,
953,
340,
4224,
26,
355,
340,
2112,
63,
2996,
508,
378,
26,
490,
870,
17519,
2288,
63,
84,
29930,
2257,
63,
84,
29930,
13645,
29930,
519,
26,
11123,
908,
8,
717,
24670,
12,
2288,
63,
84,
12,
2257,
63,
84,
12,
6631,
14,
12290,
14,
7493,
12,
717,
11052,
63,
82,
430,
355,
11052,
63,
82,
275,
378,
355,
16087,
275,
2589,
14,
3958,
342,
355,
519,
275,
378,
355,
4224,
275,
756,
288,
587,
26,
355,
16087,
12,
519,
12,
4224,
12,
2256,
275,
2589,
14,
2926,
8,
65,
9,
953,
340,
2288,
63,
84,
450,
1249,
14,
2579,
63,
11132,
508,
378,
26,
355,
327,
16494,
4086,
2234,
327,
2136,
1471,
675,
282,
1331,
402,
314,
1402,
2952,
511,
7858,
883,
1570,
355,
327,
314,
8752,
6363,
402,
314,
1402,
355,
511,
63,
1238,
275,
1331,
14,
8293,
8,
4054,
14,
1238,
9,
355,
511,
63,
1238,
14,
3958,
63,
929,
342,
2234,
4615,
12,
17312,
12,
410,
2374,
275,
3468,
63,
20576,
8,
490,
2112,
63,
2996,
12,
1852,
63,
1813,
12,
511,
63,
1238,
12,
6631,
14,
10909,
12,
490,
1249,
14,
2579,
63,
78,
63,
10802,
9,
355,
543,
1551,
8,
736,
14,
515,
14,
904,
8,
18091,
12,
283,
7107,
14,
2424,
659,
283,
65,
13854,
465,
289,
26,
490,
14439,
275,
900,
14,
521,
342,
446,
1343,
63,
521,
490,
2777,
275,
334,
2966,
63,
84,
12,
14439,
12,
4615,
12,
17312,
12,
410,
2374,
9,
490,
870,
2258,
84,
1370,
904,
8,
495,
8,
88,
9,
367,
671,
315,
2777,
395,
570,
29,
70,
9,
355,
543,
1390,
63,
3397,
14,
362,
63,
831,
837,
490,
340,
4615,
690,
1390,
63,
3397,
14,
585,
26,
717,
327,
11063,
314,
5526,
1402,
880,
12474,
717,
870,
360,
1918,
5526,
5396,
365,
4588,
1052,
1035,
9499,
908,
8,
1169,
1390,
63,
3397,
14,
585,
12,
4615,
430,
717,
1788,
275,
747,
14,
515,
14,
904,
8,
1169,
24670,
12,
9005,
14,
72,
21,
1370,
908,
8,
2966,
63,
84,
430,
717,
6631,
14,
2117,
63,
1238,
8,
1501,
9,
717,
870,
360,
21969,
314,
1453,
5526,
1402,
370,
9499,
908,
8,
1169,
1788,
430,
717,
1390,
63,
3397,
14,
585,
275,
4615,
339,
871,
13483,
26,
267,
340,
2112,
63,
2996,
508,
378,
26,
288,
327,
11063,
314,
1453,
1402,
2544,
3769,
26659,
288,
6631,
14,
2117,
63,
1238,
8,
736,
14,
515,
14,
904,
8,
355,
24670,
12,
9005,
63,
19553,
20172,
14,
72,
21,
1370,
908,
8,
2966,
63,
84,
1724,
288,
870,
360,
21969,
314,
1453,
1402,
370,
9499,
908,
8,
355,
24670,
395,
570,
29,
1274,
14,
3083,
9,
267,
746,
339,
340,
2288,
63,
84,
508,
1249,
14,
5895,
435,
413,
26,
267,
327,
11063,
314,
4242,
1402,
267,
6631,
14,
2117,
63,
1238,
8,
288,
747,
14,
515,
14,
904,
8,
589,
14,
18091,
12,
9005,
63,
8192,
14,
72,
21,
1370,
908,
8,
589,
14,
5895,
1724,
267,
870,
360,
21969,
314,
4242,
1402,
370,
9499,
908,
8,
589,
14,
18091,
430,
421,
199,
318,
3560,
63,
3813,
63,
1045,
63,
2913,
8,
1412,
63,
2996,
12,
7055,
12,
1852,
63,
1813,
12,
1390,
63,
3397,
12,
1249,
12,
1169,
6631,
12,
2589,
12,
1343,
63
] |
[
7534,
199,
646,
1331,
199,
646,
12866,
465,
6118,
199,
646,
747,
199,
646,
984,
199,
646,
11076,
199,
646,
900,
199,
199,
646,
20333,
199,
504,
20333,
492,
6220,
465,
491,
199,
504,
20333,
492,
3423,
465,
481,
199,
646,
6277,
18,
199,
646,
2680,
465,
980,
199,
199,
646,
282,
19,
67,
199,
646,
2196,
63,
5176,
199,
646,
5316,
199,
504,
9275,
63,
1199,
63,
694,
492,
9275,
63,
1199,
63,
694,
421,
199,
318,
3468,
63,
20576,
8,
1412,
63,
2996,
12,
1852,
63,
1813,
12,
1402,
12,
14524,
12,
302,
63,
10802,
304,
272,
702,
302,
63,
10802,
690,
413,
12,
283,
2404,
4655,
410,
2374,
5074,
737,
5210,
2877,
7858,
7,
272,
9342,
275,
942,
272,
367,
284,
315,
1425,
8,
78,
63,
10802,
304,
267,
1402,
14,
3958,
63,
929,
342,
267,
2589,
275,
1852,
63,
1813,
8,
1412,
63,
2996,
12,
511,
29,
549,
9,
267,
16087,
275,
2589,
14,
3958,
342,
267,
4224,
275,
756,
267,
511,
63,
82,
275,
378,
267,
1830,
440,
4224,
26,
288,
308,
275,
20333,
14,
2773,
8,
1590,
14,
4441,
63,
5380,
8,
10909,
8,
11226,
395,
378,
430,
288,
299,
548,
12,
485,
275,
1402,
14,
1038,
63,
460,
63,
86,
8,
83,
9,
288,
282,
275,
299,
548,
14,
1287,
63,
4108,
59,
16,
61,
288,
16087,
12,
519,
12,
4224,
12,
2256,
275,
2589,
14,
2926,
8,
65,
9,
288,
511,
63,
82,
847,
519,
267,
9342,
14,
740,
8,
396,
63,
82,
9,
267,
870,
360,
396,
24306,
26,
1370,
908,
8,
73,
395,
511,
63,
82,
9,
272,
4615,
275,
11076,
14,
3670,
8,
7107,
9,
272,
17312,
275,
11076,
14,
13106,
8,
7107,
9,
272,
410,
2374,
275,
11076,
14,
270,
2374,
8,
7107,
9,
272,
372,
4615,
12,
17312,
12,
410,
2374,
421,
199,
318,
3560,
63,
3813,
8,
1412,
63,
2996,
12,
7055,
12,
1852,
63,
1813,
12,
1390,
63,
3397,
12,
1249,
12,
6631,
12,
2589,
12,
2049,
1343,
63,
521,
12,
24670,
304,
272,
862,
26,
398,
3141,
63,
82,
275,
378,
267,
11052,
63,
82,
275,
378,
267,
2288,
63,
84,
275,
378,
267,
2257,
63,
84,
275,
378,
267,
16087,
275,
2589,
14,
3958,
342,
267,
519,
275,
378,
267,
4224,
275,
756,
398,
1830,
715,
26,
953,
327,
2372,
436,
11609,
314,
2288,
7055,
288,
543,
7055,
14,
362,
63,
831,
837,
355,
7055,
14,
585,
847,
413,
355,
2288,
63,
84,
275,
7055,
14,
585,
288,
2257,
63,
84,
847,
413,
953,
340,
2288,
63,
84,
690,
1249,
14,
5895,
26,
355,
2059,
953,
6631,
14,
12290,
14,
7493,
275,
334,
355,
1249,
14,
5895,
446,
2288,
63,
84,
446,
413,
9,
1182,
1249,
14,
5895,
627,
1249,
14,
7493,
953,
3141,
63,
82,
847,
519,
288,
11052,
63,
82,
847,
519,
953,
282,
275,
6631,
14,
2442,
8,
11226,
12,
519,
12,
4224,
9,
953,
340,
4224,
26,
355,
340,
2112,
63,
2996,
508,
378,
26,
490,
870,
17519,
2288,
63,
84,
29930,
2257,
63,
84,
29930,
13645,
29930,
519,
26,
11123,
908,
8,
717,
24670,
12,
2288,
63,
84,
12,
2257,
63,
84,
12,
6631,
14,
12290,
14,
7493,
12,
717,
11052,
63,
82,
430,
355,
11052,
63,
82,
275,
378,
355,
16087,
275,
2589,
14,
3958,
342,
355,
519,
275,
378,
355,
4224,
275,
756,
288,
587,
26,
355,
16087,
12,
519,
12,
4224,
12,
2256,
275,
2589,
14,
2926,
8,
65,
9,
953,
340,
2288,
63,
84,
450,
1249,
14,
2579,
63,
11132,
508,
378,
26,
355,
327,
16494,
4086,
2234,
327,
2136,
1471,
675,
282,
1331,
402,
314,
1402,
2952,
511,
7858,
883,
1570,
355,
327,
314,
8752,
6363,
402,
314,
1402,
355,
511,
63,
1238,
275,
1331,
14,
8293,
8,
4054,
14,
1238,
9,
355,
511,
63,
1238,
14,
3958,
63,
929,
342,
2234,
4615,
12,
17312,
12,
410,
2374,
275,
3468,
63,
20576,
8,
490,
2112,
63,
2996,
12,
1852,
63,
1813,
12,
511,
63,
1238,
12,
6631,
14,
10909,
12,
490,
1249,
14,
2579,
63,
78,
63,
10802,
9,
355,
543,
1551,
8,
736,
14,
515,
14,
904,
8,
18091,
12,
283,
7107,
14,
2424,
659,
283,
65,
13854,
465,
289,
26,
490,
14439,
275,
900,
14,
521,
342,
446,
1343,
63,
521,
490,
2777,
275,
334,
2966,
63,
84,
12,
14439,
12,
4615,
12,
17312,
12,
410,
2374,
9,
490,
870,
2258,
84,
1370,
904,
8,
495,
8,
88,
9,
367,
671,
315,
2777,
395,
570,
29,
70,
9,
355,
543,
1390,
63,
3397,
14,
362,
63,
831,
837,
490,
340,
4615,
690,
1390,
63,
3397,
14,
585,
26,
717,
327,
11063,
314,
5526,
1402,
880,
12474,
717,
870,
360,
1918,
5526,
5396,
365,
4588,
1052,
1035,
9499,
908,
8,
1169,
1390,
63,
3397,
14,
585,
12,
4615,
430,
717,
1788,
275,
747,
14,
515,
14,
904,
8,
1169,
24670,
12,
9005,
14,
72,
21,
1370,
908,
8,
2966,
63,
84,
430,
717,
6631,
14,
2117,
63,
1238,
8,
1501,
9,
717,
870,
360,
21969,
314,
1453,
5526,
1402,
370,
9499,
908,
8,
1169,
1788,
430,
717,
1390,
63,
3397,
14,
585,
275,
4615,
339,
871,
13483,
26,
267,
340,
2112,
63,
2996,
508,
378,
26,
288,
327,
11063,
314,
1453,
1402,
2544,
3769,
26659,
288,
6631,
14,
2117,
63,
1238,
8,
736,
14,
515,
14,
904,
8,
355,
24670,
12,
9005,
63,
19553,
20172,
14,
72,
21,
1370,
908,
8,
2966,
63,
84,
1724,
288,
870,
360,
21969,
314,
1453,
1402,
370,
9499,
908,
8,
355,
24670,
395,
570,
29,
1274,
14,
3083,
9,
267,
746,
339,
340,
2288,
63,
84,
508,
1249,
14,
5895,
435,
413,
26,
267,
327,
11063,
314,
4242,
1402,
267,
6631,
14,
2117,
63,
1238,
8,
288,
747,
14,
515,
14,
904,
8,
589,
14,
18091,
12,
9005,
63,
8192,
14,
72,
21,
1370,
908,
8,
589,
14,
5895,
1724,
267,
870,
360,
21969,
314,
4242,
1402,
370,
9499,
908,
8,
589,
14,
18091,
430,
421,
199,
318,
3560,
63,
3813,
63,
1045,
63,
2913,
8,
1412,
63,
2996,
12,
7055,
12,
1852,
63,
1813,
12,
1390,
63,
3397,
12,
1249,
12,
1169,
6631,
12,
2589,
12,
1343,
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,
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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
] |
darthbhyrava/pywikibot-local
|
tests/timestamp_tests.py
|
4
|
3470
|
# -*- coding: utf-8 -*-
"""Tests for the Timestamp class."""
#
# (C) Pywikibot team, 2014
#
# Distributed under the terms of the MIT license.
#
from __future__ import absolute_import, unicode_literals
__version__ = '$Id$'
import calendar
import datetime
from pywikibot import Timestamp as T
from tests.aspects import unittest, TestCase
class TestTimestamp(TestCase):
"""Test Timestamp class comparisons."""
net = False
def test_clone(self):
"""Test cloning a Timestamp instance."""
t1 = T.utcnow()
t2 = t1.clone()
self.assertEqual(t1, t2)
self.assertIsInstance(t2, T)
def test_instantiate_from_instance(self):
"""Test passing instance to factory methods works."""
t1 = T.utcnow()
self.assertIsNot(t1, T.fromISOformat(t1))
self.assertEqual(t1, T.fromISOformat(t1))
self.assertIsInstance(T.fromISOformat(t1), T)
self.assertIsNot(t1, T.fromtimestampformat(t1))
self.assertEqual(t1, T.fromtimestampformat(t1))
self.assertIsInstance(T.fromtimestampformat(t1), T)
def test_iso_format(self):
"""Test conversion from and to ISO format."""
t1 = T.utcnow()
ts1 = t1.isoformat()
t2 = T.fromISOformat(ts1)
ts2 = t2.isoformat()
# MediaWiki ISO format doesn't include microseconds
self.assertNotEqual(t1, t2)
t1 = t1.replace(microsecond=0)
self.assertEqual(t1, t2)
self.assertEqual(ts1, ts2)
def test_mediawiki_format(self):
"""Test conversion from and to timestamp format."""
t1 = T.utcnow()
ts1 = t1.totimestampformat()
t2 = T.fromtimestampformat(ts1)
ts2 = t2.totimestampformat()
# MediaWiki timestamp format doesn't include microseconds
self.assertNotEqual(t1, t2)
t1 = t1.replace(microsecond=0)
self.assertEqual(t1, t2)
self.assertEqual(ts1, ts2)
def test_add_timedelta(self):
"""Test addin a timedelta to a Timestamp."""
t1 = T.utcnow()
t2 = t1 + datetime.timedelta(days=1)
if t1.month != t2.month:
self.assertEqual(1, t2.day)
else:
self.assertEqual(t1.day + 1, t2.day)
self.assertIsInstance(t2, T)
def test_add_timedate(self):
"""Test unsupported additions raise NotImplemented."""
t1 = datetime.datetime.utcnow()
t2 = t1 + datetime.timedelta(days=1)
t3 = t1.__add__(t2)
self.assertIs(t3, NotImplemented)
# Now check that the pywikibot sub-class behaves the same way
t1 = T.utcnow()
t2 = t1 + datetime.timedelta(days=1)
t3 = t1.__add__(t2)
self.assertIs(t3, NotImplemented)
def test_sub_timedelta(self):
"""Test substracting a timedelta from a Timestamp."""
t1 = T.utcnow()
t2 = t1 - datetime.timedelta(days=1)
if t1.month != t2.month:
self.assertEqual(calendar.monthrange(t2.year, t2.month)[1], t2.day)
else:
self.assertEqual(t1.day - 1, t2.day)
self.assertIsInstance(t2, T)
def test_sub_timedate(self):
"""Test subtracting two timestamps."""
t1 = T.utcnow()
t2 = t1 - datetime.timedelta(days=1)
td = t1 - t2
self.assertIsInstance(td, datetime.timedelta)
self.assertEqual(t2 + td, t1)
if __name__ == '__main__':
try:
unittest.main()
except SystemExit:
pass
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
221,
1882,
199,
624,
2925,
367,
314,
18267,
1021,
1041,
199,
3,
199,
3,
334,
35,
9,
1611,
26540,
8099,
12,
6927,
199,
3,
199,
3,
17484,
1334,
314,
2895,
402,
314,
10697,
4190,
14,
199,
3,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
199,
363,
1023,
363,
275,
4505,
1304,
12913,
199,
199,
646,
11234,
199,
646,
2197,
199,
199,
504,
29624,
492,
18267,
465,
377,
199,
199,
504,
2295,
14,
18658,
83,
492,
2882,
12,
7640,
421,
199,
533,
1379,
10239,
8,
1746,
304,
339,
408,
774,
18267,
1021,
20448,
1041,
339,
1851,
275,
756,
339,
347,
511,
63,
6311,
8,
277,
304,
267,
408,
774,
824,
19718,
282,
18267,
1256,
1041,
267,
307,
17,
275,
377,
14,
10779,
342,
267,
307,
18,
275,
307,
17,
14,
6311,
342,
267,
291,
14,
629,
8,
84,
17,
12,
307,
18,
9,
267,
291,
14,
6926,
8,
84,
18,
12,
377,
9,
339,
347,
511,
63,
3615,
18973,
63,
504,
63,
842,
8,
277,
304,
267,
408,
774,
9476,
1256,
370,
6434,
3102,
5419,
1041,
267,
307,
17,
275,
377,
14,
10779,
342,
267,
291,
14,
9422,
8,
84,
17,
12,
377,
14,
504,
7336,
908,
8,
84,
17,
430,
267,
291,
14,
629,
8,
84,
17,
12,
377,
14,
504,
7336,
908,
8,
84,
17,
430,
267,
291,
14,
6926,
8,
52,
14,
504,
7336,
908,
8,
84,
17,
395,
377,
9,
267,
291,
14,
9422,
8,
84,
17,
12,
377,
14,
18531,
908,
8,
84,
17,
430,
267,
291,
14,
629,
8,
84,
17,
12,
377,
14,
18531,
908,
8,
84,
17,
430,
267,
291,
14,
6926,
8,
52,
14,
18531,
908,
8,
84,
17,
395,
377,
9,
339,
347,
511,
63,
4595,
63,
908,
8,
277,
304,
267,
408,
774,
8603,
687,
436,
370,
9055,
1475,
1041,
267,
307,
17,
275,
377,
14,
10779,
342,
267,
6714,
17,
275,
307,
17,
14,
17070,
342,
267,
307,
18,
275,
377,
14,
504,
7336,
908,
8,
1086,
17,
9,
267,
6714,
18,
275,
307,
18,
14,
17070,
342,
267,
327,
12300,
26198,
9055,
1475,
3181,
1133,
2387,
21574,
267,
291,
14,
7418,
8,
84,
17,
12,
307,
18,
9,
267,
307,
17,
275,
307,
17,
14,
1814,
8,
16627,
29,
16,
9,
267,
291,
14,
629,
8,
84,
17,
12,
307,
18,
9,
267,
291,
14,
629,
8,
1086,
17,
12,
6714,
18,
9,
339,
347,
511,
63,
4603,
6797,
63,
908,
8,
277,
304,
267,
408,
774,
8603,
687,
436,
370,
4913,
1475,
1041,
267,
307,
17,
275,
377,
14,
10779,
342,
267,
6714,
17,
275,
307,
17,
14,
475,
3954,
908,
342,
267,
307,
18,
275,
377,
14,
18531,
908,
8,
1086,
17,
9,
267,
6714,
18,
275,
307,
18,
14,
475,
3954,
908,
342,
267,
327,
12300,
26198,
4913,
1475,
3181,
1133,
2387,
21574,
267,
291,
14,
7418,
8,
84,
17,
12,
307,
18,
9,
267,
307,
17,
275,
307,
17,
14,
1814,
8,
16627,
29,
16,
9,
267,
291,
14,
629,
8,
84,
17,
12,
307,
18,
9,
267,
291,
14,
629,
8,
1086,
17,
12,
6714,
18,
9,
339,
347,
511,
63,
525,
63,
7473,
8,
277,
304,
267,
408,
774,
1050,
262,
282,
6871,
370,
282,
18267,
1041,
267,
307,
17,
275,
377,
14,
10779,
342,
267,
307,
18,
275,
307,
17,
435,
2197,
14,
7473,
8,
4899,
29,
17,
9,
267,
340,
307,
17,
14,
4482,
1137,
307,
18,
14,
4482,
26,
288,
291,
14,
629,
8,
17,
12,
307,
18,
14,
2977,
9,
267,
587,
26,
288,
291,
14,
629,
8,
84,
17,
14,
2977,
435,
413,
12,
307,
18,
14,
2977,
9,
267,
291,
14,
6926,
8,
84,
18,
12,
377,
9,
339,
347,
511,
63,
525,
63,
521,
602,
8,
277,
304,
267,
408,
774,
16313,
32113,
746,
3784,
1041,
267,
307,
17,
275,
2197,
14,
2083,
14,
10779,
342,
267,
307,
18,
275,
307,
17,
435,
2197,
14,
7473,
8,
4899,
29,
17,
9,
267,
307,
19,
275,
307,
17,
855,
525,
721,
84,
18,
9,
267,
291,
14,
3436,
8,
84,
19,
12,
3784,
9,
398,
327,
7356,
1104,
626,
314,
29624,
1007,
13,
533,
25113,
314,
2011,
4340,
267,
307,
17,
275,
377,
14,
10779,
342,
267,
307,
18,
275,
307,
17,
435,
2197,
14,
7473,
8,
4899,
29,
17,
9,
267,
307,
19,
275,
307,
17,
855,
525,
721,
84,
18,
9,
267,
291,
14,
3436,
8,
84,
19,
12,
3784,
9,
339,
347,
511,
63,
954,
63,
7473,
8,
277,
304,
267,
408,
774,
1007,
3525,
316,
282,
6871,
687,
282,
18267,
1041,
267,
307,
17,
275,
377,
14,
10779,
342,
267,
307,
18,
275,
307,
17,
446,
2197,
14,
7473,
8,
4899,
29,
17,
9,
267,
340,
307,
17,
14,
4482,
1137,
307,
18,
14,
4482,
26,
288,
291,
14,
629,
8,
8183,
14,
4482,
1842,
8,
84,
18,
14,
3403,
12,
307,
18,
14,
4482,
2788,
17,
467,
307,
18,
14,
2977,
9,
267,
587,
26,
288,
291,
14,
629,
8,
84,
17,
14,
2977,
446,
413,
12,
307,
18,
14,
2977,
9,
267,
291,
14,
6926,
8,
84,
18,
12,
377,
9,
339,
347,
511,
63,
954,
63,
521,
602,
8,
277,
304,
267,
408,
774,
24129,
316,
2877,
22496,
1041,
267,
307,
17,
275,
377,
14,
10779,
342,
267,
307,
18,
275,
307,
17,
446,
2197,
14,
7473,
8,
4899,
29,
17,
9,
267,
12749,
275,
307,
17,
446,
307,
18,
267,
291,
14,
6926,
8,
2076,
12,
2197,
14,
7473,
9,
267,
291,
14,
629,
8,
84,
18,
435,
12749,
12,
307,
17,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
862,
26,
267,
2882,
14,
973,
342,
272,
871,
14838,
26,
267,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
221,
1882,
199,
624,
2925,
367,
314,
18267,
1021,
1041,
199,
3,
199,
3,
334,
35,
9,
1611,
26540,
8099,
12,
6927,
199,
3,
199,
3,
17484,
1334,
314,
2895,
402,
314,
10697,
4190,
14,
199,
3,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
199,
363,
1023,
363,
275,
4505,
1304,
12913,
199,
199,
646,
11234,
199,
646,
2197,
199,
199,
504,
29624,
492,
18267,
465,
377,
199,
199,
504,
2295,
14,
18658,
83,
492,
2882,
12,
7640,
421,
199,
533,
1379,
10239,
8,
1746,
304,
339,
408,
774,
18267,
1021,
20448,
1041,
339,
1851,
275,
756,
339,
347,
511,
63,
6311,
8,
277,
304,
267,
408,
774,
824,
19718,
282,
18267,
1256,
1041,
267,
307,
17,
275,
377,
14,
10779,
342,
267,
307,
18,
275,
307,
17,
14,
6311,
342,
267,
291,
14,
629,
8,
84,
17,
12,
307,
18,
9,
267,
291,
14,
6926,
8,
84,
18,
12,
377,
9,
339,
347,
511,
63,
3615,
18973,
63,
504,
63,
842,
8,
277,
304,
267,
408,
774,
9476,
1256,
370,
6434,
3102,
5419,
1041,
267,
307,
17,
275,
377,
14,
10779,
342,
267,
291,
14,
9422,
8,
84,
17,
12,
377,
14,
504,
7336,
908,
8,
84,
17,
430,
267,
291,
14,
629,
8,
84,
17,
12,
377,
14,
504,
7336,
908,
8,
84,
17,
430,
267,
291,
14,
6926,
8,
52,
14,
504,
7336,
908,
8,
84,
17,
395,
377,
9,
267,
291,
14,
9422,
8,
84,
17,
12,
377,
14,
18531,
908,
8,
84,
17,
430,
267,
291,
14,
629,
8,
84,
17,
12,
377,
14,
18531,
908,
8,
84,
17,
430,
267,
291,
14,
6926,
8,
52,
14,
18531,
908,
8,
84,
17,
395,
377,
9,
339,
347,
511,
63,
4595,
63,
908,
8,
277,
304,
267,
408,
774,
8603,
687,
436,
370,
9055,
1475,
1041,
267,
307,
17,
275,
377,
14,
10779,
342,
267,
6714,
17,
275,
307,
17,
14,
17070,
342,
267,
307,
18,
275,
377,
14,
504,
7336,
908,
8,
1086,
17,
9,
267,
6714,
18,
275,
307,
18,
14,
17070,
342,
267,
327,
12300,
26198,
9055,
1475,
3181,
1133,
2387,
21574,
267,
291,
14,
7418,
8,
84,
17,
12,
307,
18,
9,
267,
307,
17,
275,
307,
17,
14,
1814,
8,
16627,
29,
16,
9,
267,
291,
14,
629,
8,
84,
17,
12,
307,
18,
9,
267,
291,
14,
629,
8,
1086,
17,
12,
6714,
18,
9,
339,
347,
511,
63,
4603,
6797,
63,
908,
8,
277,
304,
267,
408,
774,
8603,
687,
436,
370,
4913,
1475,
1041,
267,
307,
17,
275,
377,
14,
10779,
342,
267,
6714,
17,
275,
307,
17,
14,
475,
3954,
908,
342,
267,
307,
18,
275,
377,
14,
18531,
908,
8,
1086,
17,
9,
267,
6714,
18,
275,
307,
18,
14,
475,
3954,
908,
342,
267,
327,
12300,
26198,
4913,
1475,
3181,
1133,
2387,
21574,
267,
291,
14,
7418,
8,
84,
17,
12,
307,
18,
9,
267,
307,
17,
275,
307,
17,
14,
1814,
8,
16627,
29,
16,
9,
267,
291,
14,
629,
8,
84,
17,
12,
307,
18,
9,
267,
291,
14,
629,
8,
1086,
17,
12,
6714,
18,
9,
339,
347,
511,
63,
525,
63,
7473,
8,
277,
304,
267,
408,
774,
1050,
262,
282,
6871,
370,
282,
18267,
1041,
267,
307,
17,
275,
377,
14,
10779,
342,
267,
307,
18,
275,
307,
17,
435,
2197,
14,
7473,
8,
4899,
29,
17,
9,
267,
340,
307,
17,
14,
4482,
1137,
307,
18,
14,
4482,
26,
288,
291,
14,
629,
8,
17,
12,
307,
18,
14,
2977,
9,
267,
587,
26,
288,
291,
14,
629,
8,
84,
17,
14,
2977,
435,
413,
12,
307,
18,
14,
2977,
9,
267,
291,
14,
6926,
8,
84,
18,
12,
377,
9,
339,
347,
511,
63,
525,
63,
521,
602,
8,
277,
304,
267,
408,
774,
16313,
32113,
746,
3784,
1041,
267,
307,
17,
275,
2197,
14,
2083,
14,
10779,
342,
267,
307,
18,
275,
307,
17,
435,
2197,
14,
7473,
8,
4899,
29,
17,
9,
267,
307,
19,
275,
307,
17,
855,
525,
721,
84,
18,
9,
267,
291,
14,
3436,
8,
84,
19,
12,
3784,
9,
398,
327,
7356,
1104,
626,
314,
29624,
1007,
13,
533,
25113,
314,
2011,
4340,
267,
307,
17,
275,
377,
14,
10779,
342,
267,
307,
18,
275,
307,
17,
435,
2197,
14,
7473,
8,
4899,
29,
17,
9,
267,
307,
19,
275,
307,
17,
855,
525,
721,
84,
18,
9,
267,
291,
14,
3436,
8,
84,
19,
12,
3784,
9,
339,
347,
511,
63,
954,
63,
7473,
8,
277,
304,
267,
408,
774,
1007,
3525,
316,
282,
6871,
687,
282,
18267,
1041,
267,
307,
17,
275,
377,
14,
10779,
342,
267,
307,
18,
275,
307,
17,
446,
2197,
14,
7473,
8,
4899,
29,
17,
9,
267,
340,
307,
17,
14,
4482,
1137,
307,
18,
14,
4482,
26,
288,
291,
14,
629,
8,
8183,
14,
4482,
1842,
8,
84,
18,
14,
3403,
12,
307,
18,
14,
4482,
2788,
17,
467,
307,
18,
14,
2977,
9,
267,
587,
26,
288,
291,
14,
629,
8,
84,
17,
14,
2977,
446,
413,
12,
307,
18,
14,
2977,
9,
267,
291,
14,
6926,
8,
84,
18,
12,
377,
9,
339,
347,
511,
63,
954,
63,
521,
602,
8,
277,
304,
267,
408,
774,
24129,
316,
2877,
22496,
1041,
267,
307,
17,
275,
377,
14,
10779,
342,
267,
307,
18,
275,
307,
17,
446,
2197,
14,
7473,
8,
4899,
29,
17,
9,
267,
12749,
275,
307,
17,
446,
307,
18,
267,
291,
14,
6926,
8,
2076,
12,
2197,
14,
7473,
9,
267,
291,
14,
629,
8,
84,
18,
435,
12749,
12,
307,
17,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
862,
26,
267,
2882,
14,
973,
342,
272,
871,
14838,
26,
267,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
waytai/networkx
|
networkx/algorithms/link_prediction.py
|
40
|
16527
|
"""
Link prediction algorithms.
"""
from __future__ import division
import math
import networkx as nx
from networkx.utils.decorators import *
__all__ = ['resource_allocation_index',
'jaccard_coefficient',
'adamic_adar_index',
'preferential_attachment',
'cn_soundarajan_hopcroft',
'ra_index_soundarajan_hopcroft',
'within_inter_cluster']
@not_implemented_for('directed')
@not_implemented_for('multigraph')
def resource_allocation_index(G, ebunch=None):
r"""Compute the resource allocation index of all node pairs in ebunch.
Resource allocation index of `u` and `v` is defined as
.. math::
\sum_{w \in \Gamma(u) \cap \Gamma(v)} \frac{1}{|\Gamma(w)|}
where :math:`\Gamma(u)` denotes the set of neighbors of `u`.
Parameters
----------
G : graph
A NetworkX undirected graph.
ebunch : iterable of node pairs, optional (default = None)
Resource allocation index will be computed for each pair of
nodes given in the iterable. The pairs must be given as
2-tuples (u, v) where u and v are nodes in the graph. If ebunch
is None then all non-existent edges in the graph will be used.
Default value: None.
Returns
-------
piter : iterator
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a
pair of nodes and p is their resource allocation index.
Examples
--------
>>> import networkx as nx
>>> G = nx.complete_graph(5)
>>> preds = nx.resource_allocation_index(G, [(0, 1), (2, 3)])
>>> for u, v, p in preds:
... '(%d, %d) -> %.8f' % (u, v, p)
...
'(0, 1) -> 0.75000000'
'(2, 3) -> 0.75000000'
References
----------
.. [1] T. Zhou, L. Lu, Y.-C. Zhang.
Predicting missing links via local information.
Eur. Phys. J. B 71 (2009) 623.
http://arxiv.org/pdf/0901.0553.pdf
"""
if ebunch is None:
ebunch = nx.non_edges(G)
def predict(u, v):
return sum(1 / G.degree(w) for w in nx.common_neighbors(G, u, v))
return ((u, v, predict(u, v)) for u, v in ebunch)
@not_implemented_for('directed')
@not_implemented_for('multigraph')
def jaccard_coefficient(G, ebunch=None):
r"""Compute the Jaccard coefficient of all node pairs in ebunch.
Jaccard coefficient of nodes `u` and `v` is defined as
.. math::
\frac{|\Gamma(u) \cap \Gamma(v)|}{|\Gamma(u) \cup \Gamma(v)|}
where :math:`\Gamma(u)` denotes the set of neighbors of `u`.
Parameters
----------
G : graph
A NetworkX undirected graph.
ebunch : iterable of node pairs, optional (default = None)
Jaccard coefficient will be computed for each pair of nodes
given in the iterable. The pairs must be given as 2-tuples
(u, v) where u and v are nodes in the graph. If ebunch is None
then all non-existent edges in the graph will be used.
Default value: None.
Returns
-------
piter : iterator
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a
pair of nodes and p is their Jaccard coefficient.
Examples
--------
>>> import networkx as nx
>>> G = nx.complete_graph(5)
>>> preds = nx.jaccard_coefficient(G, [(0, 1), (2, 3)])
>>> for u, v, p in preds:
... '(%d, %d) -> %.8f' % (u, v, p)
...
'(0, 1) -> 0.60000000'
'(2, 3) -> 0.60000000'
References
----------
.. [1] D. Liben-Nowell, J. Kleinberg.
The Link Prediction Problem for Social Networks (2004).
http://www.cs.cornell.edu/home/kleinber/link-pred.pdf
"""
if ebunch is None:
ebunch = nx.non_edges(G)
def predict(u, v):
cnbors = list(nx.common_neighbors(G, u, v))
union_size = len(set(G[u]) | set(G[v]))
if union_size == 0:
return 0
else:
return len(cnbors) / union_size
return ((u, v, predict(u, v)) for u, v in ebunch)
@not_implemented_for('directed')
@not_implemented_for('multigraph')
def adamic_adar_index(G, ebunch=None):
r"""Compute the Adamic-Adar index of all node pairs in ebunch.
Adamic-Adar index of `u` and `v` is defined as
.. math::
\sum_{w \in \Gamma(u) \cap \Gamma(v)} \frac{1}{\log |\Gamma(w)|}
where :math:`\Gamma(u)` denotes the set of neighbors of `u`.
Parameters
----------
G : graph
NetworkX undirected graph.
ebunch : iterable of node pairs, optional (default = None)
Adamic-Adar index will be computed for each pair of nodes given
in the iterable. The pairs must be given as 2-tuples (u, v)
where u and v are nodes in the graph. If ebunch is None then all
non-existent edges in the graph will be used.
Default value: None.
Returns
-------
piter : iterator
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a
pair of nodes and p is their Adamic-Adar index.
Examples
--------
>>> import networkx as nx
>>> G = nx.complete_graph(5)
>>> preds = nx.adamic_adar_index(G, [(0, 1), (2, 3)])
>>> for u, v, p in preds:
... '(%d, %d) -> %.8f' % (u, v, p)
...
'(0, 1) -> 2.16404256'
'(2, 3) -> 2.16404256'
References
----------
.. [1] D. Liben-Nowell, J. Kleinberg.
The Link Prediction Problem for Social Networks (2004).
http://www.cs.cornell.edu/home/kleinber/link-pred.pdf
"""
if ebunch is None:
ebunch = nx.non_edges(G)
def predict(u, v):
return sum(1 / math.log(G.degree(w))
for w in nx.common_neighbors(G, u, v))
return ((u, v, predict(u, v)) for u, v in ebunch)
@not_implemented_for('directed')
@not_implemented_for('multigraph')
def preferential_attachment(G, ebunch=None):
r"""Compute the preferential attachment score of all node pairs in ebunch.
Preferential attachment score of `u` and `v` is defined as
.. math::
|\Gamma(u)| |\Gamma(v)|
where :math:`\Gamma(u)` denotes the set of neighbors of `u`.
Parameters
----------
G : graph
NetworkX undirected graph.
ebunch : iterable of node pairs, optional (default = None)
Preferential attachment score will be computed for each pair of
nodes given in the iterable. The pairs must be given as
2-tuples (u, v) where u and v are nodes in the graph. If ebunch
is None then all non-existent edges in the graph will be used.
Default value: None.
Returns
-------
piter : iterator
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a
pair of nodes and p is their preferential attachment score.
Examples
--------
>>> import networkx as nx
>>> G = nx.complete_graph(5)
>>> preds = nx.preferential_attachment(G, [(0, 1), (2, 3)])
>>> for u, v, p in preds:
... '(%d, %d) -> %d' % (u, v, p)
...
'(0, 1) -> 16'
'(2, 3) -> 16'
References
----------
.. [1] D. Liben-Nowell, J. Kleinberg.
The Link Prediction Problem for Social Networks (2004).
http://www.cs.cornell.edu/home/kleinber/link-pred.pdf
"""
if ebunch is None:
ebunch = nx.non_edges(G)
return ((u, v, G.degree(u) * G.degree(v)) for u, v in ebunch)
@not_implemented_for('directed')
@not_implemented_for('multigraph')
def cn_soundarajan_hopcroft(G, ebunch=None, community='community'):
r"""Count the number of common neighbors of all node pairs in ebunch
using community information.
For two nodes `u` and `v`, this function computes the number of
common neighbors and bonus one for each common neighbor belonging to
the same community as `u` and `v`. Mathematically,
.. math::
|\Gamma(u) \cap \Gamma(v)| + \sum_{w \in \Gamma(u) \cap \Gamma(v)} f(w)
where `f(w)` equals 1 if `w` belongs to the same community as `u`
and `v` or 0 otherwise and :math:`\Gamma(u)` denotes the set of
neighbors of `u`.
Parameters
----------
G : graph
A NetworkX undirected graph.
ebunch : iterable of node pairs, optional (default = None)
The score will be computed for each pair of nodes given in the
iterable. The pairs must be given as 2-tuples (u, v) where u
and v are nodes in the graph. If ebunch is None then all
non-existent edges in the graph will be used.
Default value: None.
community : string, optional (default = 'community')
Nodes attribute name containing the community information.
G[u][community] identifies which community u belongs to. Each
node belongs to at most one community. Default value: 'community'.
Returns
-------
piter : iterator
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a
pair of nodes and p is their score.
Examples
--------
>>> import networkx as nx
>>> G = nx.path_graph(3)
>>> G.node[0]['community'] = 0
>>> G.node[1]['community'] = 0
>>> G.node[2]['community'] = 0
>>> preds = nx.cn_soundarajan_hopcroft(G, [(0, 2)])
>>> for u, v, p in preds:
... '(%d, %d) -> %d' % (u, v, p)
...
'(0, 2) -> 2'
References
----------
.. [1] Sucheta Soundarajan and John Hopcroft.
Using community information to improve the precision of link
prediction methods.
In Proceedings of the 21st international conference companion on
World Wide Web (WWW '12 Companion). ACM, New York, NY, USA, 607-608.
http://doi.acm.org/10.1145/2187980.2188150
"""
if ebunch is None:
ebunch = nx.non_edges(G)
def predict(u, v):
Cu = _community(G, u, community)
Cv = _community(G, v, community)
cnbors = list(nx.common_neighbors(G, u, v))
if Cu == Cv:
return len(cnbors) + sum(_community(G, w, community) == Cu
for w in cnbors)
else:
return len(cnbors)
return ((u, v, predict(u, v)) for u, v in ebunch)
@not_implemented_for('directed')
@not_implemented_for('multigraph')
def ra_index_soundarajan_hopcroft(G, ebunch=None, community='community'):
r"""Compute the resource allocation index of all node pairs in
ebunch using community information.
For two nodes `u` and `v`, this function computes the resource
allocation index considering only common neighbors belonging to the
same community as `u` and `v`. Mathematically,
.. math::
\sum_{w \in \Gamma(u) \cap \Gamma(v)} \frac{f(w)}{|\Gamma(w)|}
where `f(w)` equals 1 if `w` belongs to the same community as `u`
and `v` or 0 otherwise and :math:`\Gamma(u)` denotes the set of
neighbors of `u`.
Parameters
----------
G : graph
A NetworkX undirected graph.
ebunch : iterable of node pairs, optional (default = None)
The score will be computed for each pair of nodes given in the
iterable. The pairs must be given as 2-tuples (u, v) where u
and v are nodes in the graph. If ebunch is None then all
non-existent edges in the graph will be used.
Default value: None.
community : string, optional (default = 'community')
Nodes attribute name containing the community information.
G[u][community] identifies which community u belongs to. Each
node belongs to at most one community. Default value: 'community'.
Returns
-------
piter : iterator
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a
pair of nodes and p is their score.
Examples
--------
>>> import networkx as nx
>>> G = nx.Graph()
>>> G.add_edges_from([(0, 1), (0, 2), (1, 3), (2, 3)])
>>> G.node[0]['community'] = 0
>>> G.node[1]['community'] = 0
>>> G.node[2]['community'] = 1
>>> G.node[3]['community'] = 0
>>> preds = nx.ra_index_soundarajan_hopcroft(G, [(0, 3)])
>>> for u, v, p in preds:
... '(%d, %d) -> %.8f' % (u, v, p)
...
'(0, 3) -> 0.50000000'
References
----------
.. [1] Sucheta Soundarajan and John Hopcroft.
Using community information to improve the precision of link
prediction methods.
In Proceedings of the 21st international conference companion on
World Wide Web (WWW '12 Companion). ACM, New York, NY, USA, 607-608.
http://doi.acm.org/10.1145/2187980.2188150
"""
if ebunch is None:
ebunch = nx.non_edges(G)
def predict(u, v):
Cu = _community(G, u, community)
Cv = _community(G, v, community)
if Cu == Cv:
cnbors = nx.common_neighbors(G, u, v)
return sum(1 / G.degree(w) for w in cnbors
if _community(G, w, community) == Cu)
else:
return 0
return ((u, v, predict(u, v)) for u, v in ebunch)
@not_implemented_for('directed')
@not_implemented_for('multigraph')
def within_inter_cluster(G, ebunch=None, delta=0.001, community='community'):
"""Compute the ratio of within- and inter-cluster common neighbors
of all node pairs in ebunch.
For two nodes `u` and `v`, if a common neighbor `w` belongs to the
same community as them, `w` is considered as within-cluster common
neighbor of `u` and `v`. Otherwise, it is considered as
inter-cluster common neighbor of `u` and `v`. The ratio between the
size of the set of within- and inter-cluster common neighbors is
defined as the WIC measure. [1]_
Parameters
----------
G : graph
A NetworkX undirected graph.
ebunch : iterable of node pairs, optional (default = None)
The WIC measure will be computed for each pair of nodes given in
the iterable. The pairs must be given as 2-tuples (u, v) where
u and v are nodes in the graph. If ebunch is None then all
non-existent edges in the graph will be used.
Default value: None.
delta : float, optional (default = 0.001)
Value to prevent division by zero in case there is no
inter-cluster common neighbor between two nodes. See [1]_ for
details. Default value: 0.001.
community : string, optional (default = 'community')
Nodes attribute name containing the community information.
G[u][community] identifies which community u belongs to. Each
node belongs to at most one community. Default value: 'community'.
Returns
-------
piter : iterator
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a
pair of nodes and p is their WIC measure.
Examples
--------
>>> import networkx as nx
>>> G = nx.Graph()
>>> G.add_edges_from([(0, 1), (0, 2), (0, 3), (1, 4), (2, 4), (3, 4)])
>>> G.node[0]['community'] = 0
>>> G.node[1]['community'] = 1
>>> G.node[2]['community'] = 0
>>> G.node[3]['community'] = 0
>>> G.node[4]['community'] = 0
>>> preds = nx.within_inter_cluster(G, [(0, 4)])
>>> for u, v, p in preds:
... '(%d, %d) -> %.8f' % (u, v, p)
...
'(0, 4) -> 1.99800200'
>>> preds = nx.within_inter_cluster(G, [(0, 4)], delta=0.5)
>>> for u, v, p in preds:
... '(%d, %d) -> %.8f' % (u, v, p)
...
'(0, 4) -> 1.33333333'
References
----------
.. [1] Jorge Carlos Valverde-Rebaza and Alneu de Andrade Lopes.
Link prediction in complex networks based on cluster information.
In Proceedings of the 21st Brazilian conference on Advances in
Artificial Intelligence (SBIA'12)
http://dx.doi.org/10.1007/978-3-642-34459-6_10
"""
if delta <= 0:
raise nx.NetworkXAlgorithmError('Delta must be greater than zero')
if ebunch is None:
ebunch = nx.non_edges(G)
def predict(u, v):
Cu = _community(G, u, community)
Cv = _community(G, v, community)
if Cu == Cv:
cnbors = set(nx.common_neighbors(G, u, v))
within = set(w for w in cnbors
if _community(G, w, community) == Cu)
inter = cnbors - within
return len(within) / (len(inter) + delta)
else:
return 0
return ((u, v, predict(u, v)) for u, v in ebunch)
def _community(G, u, community):
"""Get the community of the given node."""
node_u = G.node[u]
try:
return node_u[community]
except KeyError:
raise nx.NetworkXAlgorithmError('No community information')
|
bsd-3-clause
|
[
624,
199,
3834,
12044,
18036,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
3473,
199,
199,
646,
24313,
465,
8484,
199,
504,
24313,
14,
1208,
14,
11582,
492,
627,
199,
199,
363,
452,
363,
275,
788,
1927,
63,
14940,
63,
1080,
297,
1779,
283,
74,
5470,
1005,
63,
21329,
297,
1779,
283,
27679,
530,
63,
350,
285,
63,
1080,
297,
1779,
283,
657,
1485,
1009,
63,
8905,
297,
1779,
283,
6413,
63,
14990,
285,
9091,
290,
63,
13376,
67,
293,
856,
297,
1779,
283,
345,
63,
1080,
63,
14990,
285,
9091,
290,
63,
13376,
67,
293,
856,
297,
1779,
283,
12541,
63,
1058,
63,
4201,
418,
421,
199,
32,
1397,
63,
13825,
63,
509,
360,
12080,
358,
199,
32,
1397,
63,
13825,
63,
509,
360,
3029,
2180,
358,
199,
318,
2073,
63,
14940,
63,
1080,
8,
39,
12,
26669,
4689,
29,
403,
304,
272,
519,
624,
8564,
314,
2073,
18723,
1478,
402,
1006,
1031,
6342,
315,
26669,
4689,
14,
339,
7337,
18723,
1478,
402,
658,
85,
64,
436,
658,
86,
64,
365,
3247,
465,
339,
2508,
3473,
447,
398,
971,
1838,
7348,
87,
971,
262,
971,
15091,
8,
85,
9,
971,
2874,
971,
15091,
8,
86,
6769,
971,
10865,
91,
17,
8847,
6113,
15091,
8,
87,
8636,
93,
339,
2382,
520,
3442,
1705,
60,
15091,
8,
85,
12544,
477,
5983,
314,
663,
402,
15845,
402,
658,
85,
2313,
339,
3897,
272,
4143,
272,
598,
520,
3343,
267,
437,
7220,
56,
625,
12080,
3343,
14,
339,
26669,
4689,
520,
6076,
402,
1031,
6342,
12,
2716,
334,
885,
275,
488,
9,
267,
7337,
18723,
1478,
911,
506,
9235,
367,
1924,
4092,
402,
267,
3380,
1627,
315,
314,
6076,
14,
710,
6342,
1471,
506,
1627,
465,
267,
499,
13,
11760,
334,
85,
12,
373,
9,
2382,
399,
436,
373,
787,
3380,
315,
314,
3343,
14,
982,
26669,
4689,
267,
365,
488,
2066,
1006,
2222,
13,
15025,
8207,
315,
314,
3343,
911,
506,
1202,
14,
267,
3758,
574,
26,
488,
14,
339,
1803,
272,
5514,
272,
299,
1661,
520,
6122,
267,
1626,
6122,
402,
650,
13,
11760,
315,
314,
1824,
334,
85,
12,
373,
12,
299,
9,
2382,
334,
85,
12,
373,
9,
365,
282,
267,
4092,
402,
3380,
436,
299,
365,
3932,
2073,
18723,
1478,
14,
339,
6058,
272,
3001,
272,
1306,
492,
24313,
465,
8484,
272,
1306,
598,
275,
8484,
14,
4883,
63,
2180,
8,
21,
9,
272,
1306,
24960,
275,
8484,
14,
1927,
63,
14940,
63,
1080,
8,
39,
12,
3842,
16,
12,
413,
395,
334,
18,
12,
650,
3948,
272,
1306,
367,
399,
12,
373,
12,
299,
315,
24960,
26,
272,
2263,
258,
25676,
68,
12,
450,
68,
9,
1035,
10536,
24,
70,
7,
450,
334,
85,
12,
373,
12,
299,
9,
272,
2263,
272,
8189,
16,
12,
413,
9,
1035,
378,
14,
2194,
3273,
7,
272,
8189,
18,
12,
650,
9,
1035,
378,
14,
2194,
3273,
7,
339,
14504,
272,
4143,
272,
2508,
359,
17,
61,
377,
14,
3107,
11586,
12,
491,
14,
30936,
12,
1488,
23683,
35,
14,
3107,
27304,
14,
2126,
5543,
807,
316,
4124,
6220,
4799,
2257,
2556,
14,
2126,
662,
300,
14,
11308,
588,
14,
1603,
14,
699,
17245,
334,
8664,
9,
1227,
1789,
14,
2126,
1455,
921,
27290,
14,
1308,
15,
5607,
15,
1643,
614,
14,
16458,
19,
14,
5607,
272,
408,
272,
340,
26669,
4689,
365,
488,
26,
267,
26669,
4689,
275,
8484,
14,
2865,
63,
6929,
8,
39,
9,
339,
347,
12610,
8,
85,
12,
373,
304,
267,
372,
3089,
8,
17,
1182,
598,
14,
10956,
8,
87,
9,
367,
336,
315,
8484,
14,
2330,
63,
11113,
8,
39,
12,
399,
12,
373,
430,
339,
372,
3666,
85,
12,
373,
12,
12610,
8,
85,
12,
373,
430,
367,
399,
12,
373,
315,
26669,
4689,
9,
421,
199,
32,
1397,
63,
13825,
63,
509,
360,
12080,
358,
199,
32,
1397,
63,
13825,
63,
509,
360,
3029,
2180,
358,
199,
318,
1335,
5470,
1005,
63,
21329,
8,
39,
12,
26669,
4689,
29,
403,
304,
272,
519,
624,
8564,
314,
1603,
5470,
1005,
9421,
402,
1006,
1031,
6342,
315,
26669,
4689,
14,
339,
1603,
5470,
1005,
9421,
402,
3380,
658,
85,
64,
436,
658,
86,
64,
365,
3247,
465,
339,
2508,
3473,
447,
398,
971,
10865,
91,
6113,
15091,
8,
85,
9,
971,
2874,
971,
15091,
8,
86,
8636,
8847,
6113,
15091,
8,
85,
9,
971,
17500,
971,
15091,
8,
86,
8636,
93,
339,
2382,
520,
3442,
1705,
60,
15091,
8,
85,
12544,
477,
5983,
314,
663,
402,
15845,
402,
658,
85,
2313,
339,
3897,
272,
4143,
272,
598,
520,
3343,
267,
437,
7220,
56,
625,
12080,
3343,
14,
339,
26669,
4689,
520,
6076,
402,
1031,
6342,
12,
2716,
334,
885,
275,
488,
9,
267,
1603,
5470,
1005,
9421,
911,
506,
9235,
367,
1924,
4092,
402,
3380,
267,
1627,
315,
314,
6076,
14,
710,
6342,
1471,
506,
1627,
465,
499,
13,
11760,
267,
334,
85,
12,
373,
9,
2382,
399,
436,
373,
787,
3380,
315,
314,
3343,
14,
982,
26669,
4689,
365,
488,
267,
2066,
1006,
2222,
13,
15025,
8207,
315,
314,
3343,
911,
506,
1202,
14,
267,
3758,
574,
26,
488,
14,
339,
1803,
272,
5514,
272,
299,
1661,
520,
6122,
267,
1626,
6122,
402,
650,
13,
11760,
315,
314,
1824,
334,
85,
12,
373,
12,
299,
9,
2382,
334,
85,
12,
373,
9,
365,
282,
267,
4092,
402,
3380,
436,
299,
365,
3932,
1603,
5470,
1005,
9421,
14,
339,
6058,
272,
3001,
272,
1306,
492,
24313,
465,
8484,
272,
1306,
598,
275,
8484,
14,
4883,
63,
2180,
8,
21,
9,
272,
1306,
24960,
275,
8484,
14,
74,
5470,
1005,
63,
21329,
8,
39,
12,
3842,
16,
12,
413,
395,
334,
18,
12,
650,
3948,
272,
1306,
367,
399,
12,
373,
12,
299,
315,
24960,
26,
272,
2263,
258,
25676,
68,
12,
450,
68,
9,
1035,
10536,
24,
70,
7,
450,
334,
85,
12,
373,
12,
299,
9,
272,
2263,
272,
8189,
16,
12,
413,
9,
1035,
378,
14,
22,
9084,
7,
272,
8189,
18,
12,
650,
9,
1035,
378,
14,
22,
9084,
7,
339,
14504,
272,
4143,
272,
2508,
359,
17,
61,
577,
14,
8003,
287,
13,
14351,
1697,
12,
1603
] |
[
199,
3834,
12044,
18036,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
3473,
199,
199,
646,
24313,
465,
8484,
199,
504,
24313,
14,
1208,
14,
11582,
492,
627,
199,
199,
363,
452,
363,
275,
788,
1927,
63,
14940,
63,
1080,
297,
1779,
283,
74,
5470,
1005,
63,
21329,
297,
1779,
283,
27679,
530,
63,
350,
285,
63,
1080,
297,
1779,
283,
657,
1485,
1009,
63,
8905,
297,
1779,
283,
6413,
63,
14990,
285,
9091,
290,
63,
13376,
67,
293,
856,
297,
1779,
283,
345,
63,
1080,
63,
14990,
285,
9091,
290,
63,
13376,
67,
293,
856,
297,
1779,
283,
12541,
63,
1058,
63,
4201,
418,
421,
199,
32,
1397,
63,
13825,
63,
509,
360,
12080,
358,
199,
32,
1397,
63,
13825,
63,
509,
360,
3029,
2180,
358,
199,
318,
2073,
63,
14940,
63,
1080,
8,
39,
12,
26669,
4689,
29,
403,
304,
272,
519,
624,
8564,
314,
2073,
18723,
1478,
402,
1006,
1031,
6342,
315,
26669,
4689,
14,
339,
7337,
18723,
1478,
402,
658,
85,
64,
436,
658,
86,
64,
365,
3247,
465,
339,
2508,
3473,
447,
398,
971,
1838,
7348,
87,
971,
262,
971,
15091,
8,
85,
9,
971,
2874,
971,
15091,
8,
86,
6769,
971,
10865,
91,
17,
8847,
6113,
15091,
8,
87,
8636,
93,
339,
2382,
520,
3442,
1705,
60,
15091,
8,
85,
12544,
477,
5983,
314,
663,
402,
15845,
402,
658,
85,
2313,
339,
3897,
272,
4143,
272,
598,
520,
3343,
267,
437,
7220,
56,
625,
12080,
3343,
14,
339,
26669,
4689,
520,
6076,
402,
1031,
6342,
12,
2716,
334,
885,
275,
488,
9,
267,
7337,
18723,
1478,
911,
506,
9235,
367,
1924,
4092,
402,
267,
3380,
1627,
315,
314,
6076,
14,
710,
6342,
1471,
506,
1627,
465,
267,
499,
13,
11760,
334,
85,
12,
373,
9,
2382,
399,
436,
373,
787,
3380,
315,
314,
3343,
14,
982,
26669,
4689,
267,
365,
488,
2066,
1006,
2222,
13,
15025,
8207,
315,
314,
3343,
911,
506,
1202,
14,
267,
3758,
574,
26,
488,
14,
339,
1803,
272,
5514,
272,
299,
1661,
520,
6122,
267,
1626,
6122,
402,
650,
13,
11760,
315,
314,
1824,
334,
85,
12,
373,
12,
299,
9,
2382,
334,
85,
12,
373,
9,
365,
282,
267,
4092,
402,
3380,
436,
299,
365,
3932,
2073,
18723,
1478,
14,
339,
6058,
272,
3001,
272,
1306,
492,
24313,
465,
8484,
272,
1306,
598,
275,
8484,
14,
4883,
63,
2180,
8,
21,
9,
272,
1306,
24960,
275,
8484,
14,
1927,
63,
14940,
63,
1080,
8,
39,
12,
3842,
16,
12,
413,
395,
334,
18,
12,
650,
3948,
272,
1306,
367,
399,
12,
373,
12,
299,
315,
24960,
26,
272,
2263,
258,
25676,
68,
12,
450,
68,
9,
1035,
10536,
24,
70,
7,
450,
334,
85,
12,
373,
12,
299,
9,
272,
2263,
272,
8189,
16,
12,
413,
9,
1035,
378,
14,
2194,
3273,
7,
272,
8189,
18,
12,
650,
9,
1035,
378,
14,
2194,
3273,
7,
339,
14504,
272,
4143,
272,
2508,
359,
17,
61,
377,
14,
3107,
11586,
12,
491,
14,
30936,
12,
1488,
23683,
35,
14,
3107,
27304,
14,
2126,
5543,
807,
316,
4124,
6220,
4799,
2257,
2556,
14,
2126,
662,
300,
14,
11308,
588,
14,
1603,
14,
699,
17245,
334,
8664,
9,
1227,
1789,
14,
2126,
1455,
921,
27290,
14,
1308,
15,
5607,
15,
1643,
614,
14,
16458,
19,
14,
5607,
272,
408,
272,
340,
26669,
4689,
365,
488,
26,
267,
26669,
4689,
275,
8484,
14,
2865,
63,
6929,
8,
39,
9,
339,
347,
12610,
8,
85,
12,
373,
304,
267,
372,
3089,
8,
17,
1182,
598,
14,
10956,
8,
87,
9,
367,
336,
315,
8484,
14,
2330,
63,
11113,
8,
39,
12,
399,
12,
373,
430,
339,
372,
3666,
85,
12,
373,
12,
12610,
8,
85,
12,
373,
430,
367,
399,
12,
373,
315,
26669,
4689,
9,
421,
199,
32,
1397,
63,
13825,
63,
509,
360,
12080,
358,
199,
32,
1397,
63,
13825,
63,
509,
360,
3029,
2180,
358,
199,
318,
1335,
5470,
1005,
63,
21329,
8,
39,
12,
26669,
4689,
29,
403,
304,
272,
519,
624,
8564,
314,
1603,
5470,
1005,
9421,
402,
1006,
1031,
6342,
315,
26669,
4689,
14,
339,
1603,
5470,
1005,
9421,
402,
3380,
658,
85,
64,
436,
658,
86,
64,
365,
3247,
465,
339,
2508,
3473,
447,
398,
971,
10865,
91,
6113,
15091,
8,
85,
9,
971,
2874,
971,
15091,
8,
86,
8636,
8847,
6113,
15091,
8,
85,
9,
971,
17500,
971,
15091,
8,
86,
8636,
93,
339,
2382,
520,
3442,
1705,
60,
15091,
8,
85,
12544,
477,
5983,
314,
663,
402,
15845,
402,
658,
85,
2313,
339,
3897,
272,
4143,
272,
598,
520,
3343,
267,
437,
7220,
56,
625,
12080,
3343,
14,
339,
26669,
4689,
520,
6076,
402,
1031,
6342,
12,
2716,
334,
885,
275,
488,
9,
267,
1603,
5470,
1005,
9421,
911,
506,
9235,
367,
1924,
4092,
402,
3380,
267,
1627,
315,
314,
6076,
14,
710,
6342,
1471,
506,
1627,
465,
499,
13,
11760,
267,
334,
85,
12,
373,
9,
2382,
399,
436,
373,
787,
3380,
315,
314,
3343,
14,
982,
26669,
4689,
365,
488,
267,
2066,
1006,
2222,
13,
15025,
8207,
315,
314,
3343,
911,
506,
1202,
14,
267,
3758,
574,
26,
488,
14,
339,
1803,
272,
5514,
272,
299,
1661,
520,
6122,
267,
1626,
6122,
402,
650,
13,
11760,
315,
314,
1824,
334,
85,
12,
373,
12,
299,
9,
2382,
334,
85,
12,
373,
9,
365,
282,
267,
4092,
402,
3380,
436,
299,
365,
3932,
1603,
5470,
1005,
9421,
14,
339,
6058,
272,
3001,
272,
1306,
492,
24313,
465,
8484,
272,
1306,
598,
275,
8484,
14,
4883,
63,
2180,
8,
21,
9,
272,
1306,
24960,
275,
8484,
14,
74,
5470,
1005,
63,
21329,
8,
39,
12,
3842,
16,
12,
413,
395,
334,
18,
12,
650,
3948,
272,
1306,
367,
399,
12,
373,
12,
299,
315,
24960,
26,
272,
2263,
258,
25676,
68,
12,
450,
68,
9,
1035,
10536,
24,
70,
7,
450,
334,
85,
12,
373,
12,
299,
9,
272,
2263,
272,
8189,
16,
12,
413,
9,
1035,
378,
14,
22,
9084,
7,
272,
8189,
18,
12,
650,
9,
1035,
378,
14,
22,
9084,
7,
339,
14504,
272,
4143,
272,
2508,
359,
17,
61,
577,
14,
8003,
287,
13,
14351,
1697,
12,
1603,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
zouzou73/Lazarus
|
src/lazarus/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py
|
2485
|
5536
|
# This file comes from
# https://github.com/martine/ninja/blob/master/misc/ninja_syntax.py
# Do not edit! Edit the upstream one instead.
"""Python module for generating .ninja files.
Note that this is emphatically not a required piece of Ninja; it's
just a helpful utility for build-file-generation systems that already
use Python.
"""
import textwrap
import re
def escape_path(word):
return word.replace('$ ','$$ ').replace(' ','$ ').replace(':', '$:')
class Writer(object):
def __init__(self, output, width=78):
self.output = output
self.width = width
def newline(self):
self.output.write('\n')
def comment(self, text):
for line in textwrap.wrap(text, self.width - 2):
self.output.write('# ' + line + '\n')
def variable(self, key, value, indent=0):
if value is None:
return
if isinstance(value, list):
value = ' '.join(filter(None, value)) # Filter out empty strings.
self._line('%s = %s' % (key, value), indent)
def pool(self, name, depth):
self._line('pool %s' % name)
self.variable('depth', depth, indent=1)
def rule(self, name, command, description=None, depfile=None,
generator=False, pool=None, restat=False, rspfile=None,
rspfile_content=None, deps=None):
self._line('rule %s' % name)
self.variable('command', command, indent=1)
if description:
self.variable('description', description, indent=1)
if depfile:
self.variable('depfile', depfile, indent=1)
if generator:
self.variable('generator', '1', indent=1)
if pool:
self.variable('pool', pool, indent=1)
if restat:
self.variable('restat', '1', indent=1)
if rspfile:
self.variable('rspfile', rspfile, indent=1)
if rspfile_content:
self.variable('rspfile_content', rspfile_content, indent=1)
if deps:
self.variable('deps', deps, indent=1)
def build(self, outputs, rule, inputs=None, implicit=None, order_only=None,
variables=None):
outputs = self._as_list(outputs)
all_inputs = self._as_list(inputs)[:]
out_outputs = list(map(escape_path, outputs))
all_inputs = list(map(escape_path, all_inputs))
if implicit:
implicit = map(escape_path, self._as_list(implicit))
all_inputs.append('|')
all_inputs.extend(implicit)
if order_only:
order_only = map(escape_path, self._as_list(order_only))
all_inputs.append('||')
all_inputs.extend(order_only)
self._line('build %s: %s' % (' '.join(out_outputs),
' '.join([rule] + all_inputs)))
if variables:
if isinstance(variables, dict):
iterator = iter(variables.items())
else:
iterator = iter(variables)
for key, val in iterator:
self.variable(key, val, indent=1)
return outputs
def include(self, path):
self._line('include %s' % path)
def subninja(self, path):
self._line('subninja %s' % path)
def default(self, paths):
self._line('default %s' % ' '.join(self._as_list(paths)))
def _count_dollars_before_index(self, s, i):
"""Returns the number of '$' characters right in front of s[i]."""
dollar_count = 0
dollar_index = i - 1
while dollar_index > 0 and s[dollar_index] == '$':
dollar_count += 1
dollar_index -= 1
return dollar_count
def _line(self, text, indent=0):
"""Write 'text' word-wrapped at self.width characters."""
leading_space = ' ' * indent
while len(leading_space) + len(text) > self.width:
# The text is too wide; wrap if possible.
# Find the rightmost space that would obey our width constraint and
# that's not an escaped space.
available_space = self.width - len(leading_space) - len(' $')
space = available_space
while True:
space = text.rfind(' ', 0, space)
if space < 0 or \
self._count_dollars_before_index(text, space) % 2 == 0:
break
if space < 0:
# No such space; just use the first unescaped space we can find.
space = available_space - 1
while True:
space = text.find(' ', space + 1)
if space < 0 or \
self._count_dollars_before_index(text, space) % 2 == 0:
break
if space < 0:
# Give up on breaking.
break
self.output.write(leading_space + text[0:space] + ' $\n')
text = text[space+1:]
# Subsequent lines are continuations, so indent them.
leading_space = ' ' * (indent+2)
self.output.write(leading_space + text + '\n')
def _as_list(self, input):
if input is None:
return []
if isinstance(input, list):
return input
return [input]
def escape(string):
"""Escape a string such that it can be embedded into a Ninja file without
further interpretation."""
assert '\n' not in string, 'Ninja syntax does not allow newlines'
# We only have one special metacharacter: '$'.
return string.replace('$', '$$')
|
mit
|
[
3,
961,
570,
12477,
687,
199,
3,
257,
4178,
921,
5031,
14,
957,
15,
77,
580,
1132,
15,
8675,
15,
6582,
15,
4133,
15,
9923,
15,
8675,
63,
7093,
14,
647,
199,
3,
4226,
440,
5283,
1,
221,
16407,
314,
18932,
1373,
3140,
14,
199,
199,
624,
4718,
859,
367,
12999,
1275,
8675,
1584,
14,
199,
199,
7443,
626,
642,
365,
9052,
2411,
17269,
440,
282,
1415,
14854,
402,
653,
4135,
27,
652,
1159,
199,
4764,
282,
24606,
11420,
367,
1900,
13,
493,
13,
15043,
10460,
626,
2575,
199,
1180,
2018,
14,
199,
624,
199,
199,
646,
13390,
199,
646,
295,
199,
199,
318,
4772,
63,
515,
8,
1027,
304,
272,
372,
4349,
14,
1814,
14676,
13647,
23174,
27274,
1814,
360,
13647,
4,
27274,
1814,
16451,
4505,
10993,
199,
199,
533,
24441,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1072,
12,
3462,
29,
2277,
304,
267,
291,
14,
1199,
275,
1072,
267,
291,
14,
2063,
275,
3462,
339,
347,
8057,
8,
277,
304,
267,
291,
14,
1199,
14,
952,
2258,
78,
358,
339,
347,
3721,
8,
277,
12,
1318,
304,
267,
367,
1004,
315,
13390,
14,
3823,
8,
505,
12,
291,
14,
2063,
446,
499,
304,
288,
291,
14,
1199,
14,
952,
7863,
283,
435,
1004,
435,
1557,
78,
358,
339,
347,
1750,
8,
277,
12,
790,
12,
574,
12,
4363,
29,
16,
304,
267,
340,
574,
365,
488,
26,
288,
372,
267,
340,
1228,
8,
585,
12,
769,
304,
288,
574,
275,
283,
1987,
904,
8,
1541,
8,
403,
12,
574,
430,
221,
327,
9388,
734,
2701,
3326,
14,
267,
291,
423,
604,
3508,
83,
275,
450,
83,
7,
450,
334,
498,
12,
574,
395,
4363,
9,
339,
347,
4203,
8,
277,
12,
536,
12,
5818,
304,
267,
291,
423,
604,
360,
2293,
450,
83,
7,
450,
536,
9,
267,
291,
14,
1975,
360,
4631,
297,
5818,
12,
4363,
29,
17,
9,
339,
347,
2332,
8,
277,
12,
536,
12,
1414,
12,
1369,
29,
403,
12,
2657,
493,
29,
403,
12,
1467,
4306,
29,
797,
12,
4203,
29,
403,
12,
295,
3736,
29,
797,
12,
25938,
29,
403,
12,
1467,
25938,
63,
1317,
29,
403,
12,
10140,
29,
403,
304,
267,
291,
423,
604,
360,
2200,
450,
83,
7,
450,
536,
9,
267,
291,
14,
1975,
360,
1531,
297,
1414,
12,
4363,
29,
17,
9,
267,
340,
1369,
26,
288,
291,
14,
1975,
360,
1802,
297,
1369,
12,
4363,
29,
17,
9,
267,
340,
2657,
493,
26,
288,
291,
14,
1975,
360,
2601,
493,
297,
2657,
493,
12,
4363,
29,
17,
9,
267,
340,
4306,
26,
288,
291,
14,
1975,
360,
4679,
297,
283,
17,
297,
4363,
29,
17,
9,
267,
340,
4203,
26,
288,
291,
14,
1975,
360,
2293,
297,
4203,
12,
4363,
29,
17,
9,
267,
340,
295,
3736,
26,
288,
291,
14,
1975,
360,
264,
3736,
297,
283,
17,
297,
4363,
29,
17,
9,
267,
340,
25938,
26,
288,
291,
14,
1975,
360,
15642,
493,
297,
25938,
12,
4363,
29,
17,
9,
267,
340,
25938,
63,
1317,
26,
288,
291,
14,
1975,
360,
15642,
493,
63,
1317,
297,
25938,
63,
1317,
12,
4363,
29,
17,
9,
267,
340,
10140,
26,
288,
291,
14,
1975,
360,
5846,
297,
10140,
12,
4363,
29,
17,
9,
339,
347,
1900,
8,
277,
12,
4704,
12,
2332,
12,
4153,
29,
403,
12,
9227,
29,
403,
12,
1865,
63,
2118,
29,
403,
12,
1598,
2860,
29,
403,
304,
267,
4704,
275,
291,
423,
305,
63,
513,
8,
4467,
9,
267,
1006,
63,
3711,
275,
291,
423,
305,
63,
513,
8,
3711,
9,
5873,
267,
734,
63,
4467,
275,
769,
8,
1130,
8,
3765,
63,
515,
12,
4704,
430,
267,
1006,
63,
3711,
275,
769,
8,
1130,
8,
3765,
63,
515,
12,
1006,
63,
3711,
430,
398,
340,
9227,
26,
288,
9227,
275,
2341,
8,
3765,
63,
515,
12,
291,
423,
305,
63,
513,
8,
11886,
430,
288,
1006,
63,
3711,
14,
740,
20137,
358,
288,
1006,
63,
3711,
14,
2880,
8,
11886,
9,
267,
340,
1865,
63,
2118,
26,
288,
1865,
63,
2118,
275,
2341,
8,
3765,
63,
515,
12,
291,
423,
305,
63,
513,
8,
1648,
63,
2118,
430,
288,
1006,
63,
3711,
14,
740,
360,
10644,
358,
288,
1006,
63,
3711,
14,
2880,
8,
1648,
63,
2118,
9,
398,
291,
423,
604,
360,
1506,
450,
83,
26,
450,
83,
7,
450,
661,
1987,
904,
8,
548,
63,
4467,
395,
3147,
283,
1987,
904,
779,
2200,
61,
435,
1006,
63,
3711,
1724,
398,
340,
2860,
26,
288,
340,
1228,
8,
3669,
12,
1211,
304,
355,
6122,
275,
2740,
8,
3669,
14,
1744,
1012,
288,
587,
26,
355,
6122,
275,
2740,
8,
3669,
9,
953,
367,
790,
12,
1139,
315,
6122,
26,
355,
291,
14,
1975,
8,
498,
12,
1139,
12,
4363,
29,
17,
9,
398,
372,
4704,
339,
347,
2387,
8,
277,
12,
931,
304,
267,
291,
423,
604,
360,
2613,
450,
83,
7,
450,
931,
9,
339,
347,
1007,
8675,
8,
277,
12,
931,
304,
267,
291,
423,
604,
360,
954,
8675,
450,
83,
7,
450,
931,
9,
339,
347,
849,
8,
277,
12,
3792,
304,
267,
291,
423,
604,
360,
885,
450,
83,
7,
450,
283,
1987,
904,
8,
277,
423,
305,
63,
513,
8,
3771,
1724,
339,
347,
485,
835,
63,
68,
14385,
4291,
63,
5182,
63,
1080,
8,
277,
12,
308,
12,
284,
304,
489,
408,
3407,
314,
1329,
402,
25271,
4110,
2451,
315,
13738,
402,
308,
59,
73,
61,
1041,
489,
366,
25317,
63,
835,
275,
378,
489,
366,
25317,
63,
1080,
275,
284,
446,
413,
489,
1830,
366,
25317,
63,
1080,
690,
378,
436,
308,
59,
68,
25317,
63,
1080,
61,
508,
4505,
356,
267,
366,
25317,
63,
835,
847,
413,
267,
366,
25317,
63,
1080,
4862,
413,
489,
372,
366,
25317,
63,
835,
339,
347,
485,
604,
8,
277,
12,
1318,
12,
4363,
29,
16,
304,
267,
408,
3534,
283,
505,
7,
4349,
13,
9130,
737,
291,
14,
2063,
4110,
1041,
267,
9186,
63,
2638,
275,
283,
221,
283,
627,
4363,
267,
1830,
822,
8,
16812,
63,
2638,
9,
435,
822,
8,
505,
9,
690,
291,
14,
2063,
26,
288,
327,
710,
1318,
365,
4634
] |
[
961,
570,
12477,
687,
199,
3,
257,
4178,
921,
5031,
14,
957,
15,
77,
580,
1132,
15,
8675,
15,
6582,
15,
4133,
15,
9923,
15,
8675,
63,
7093,
14,
647,
199,
3,
4226,
440,
5283,
1,
221,
16407,
314,
18932,
1373,
3140,
14,
199,
199,
624,
4718,
859,
367,
12999,
1275,
8675,
1584,
14,
199,
199,
7443,
626,
642,
365,
9052,
2411,
17269,
440,
282,
1415,
14854,
402,
653,
4135,
27,
652,
1159,
199,
4764,
282,
24606,
11420,
367,
1900,
13,
493,
13,
15043,
10460,
626,
2575,
199,
1180,
2018,
14,
199,
624,
199,
199,
646,
13390,
199,
646,
295,
199,
199,
318,
4772,
63,
515,
8,
1027,
304,
272,
372,
4349,
14,
1814,
14676,
13647,
23174,
27274,
1814,
360,
13647,
4,
27274,
1814,
16451,
4505,
10993,
199,
199,
533,
24441,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1072,
12,
3462,
29,
2277,
304,
267,
291,
14,
1199,
275,
1072,
267,
291,
14,
2063,
275,
3462,
339,
347,
8057,
8,
277,
304,
267,
291,
14,
1199,
14,
952,
2258,
78,
358,
339,
347,
3721,
8,
277,
12,
1318,
304,
267,
367,
1004,
315,
13390,
14,
3823,
8,
505,
12,
291,
14,
2063,
446,
499,
304,
288,
291,
14,
1199,
14,
952,
7863,
283,
435,
1004,
435,
1557,
78,
358,
339,
347,
1750,
8,
277,
12,
790,
12,
574,
12,
4363,
29,
16,
304,
267,
340,
574,
365,
488,
26,
288,
372,
267,
340,
1228,
8,
585,
12,
769,
304,
288,
574,
275,
283,
1987,
904,
8,
1541,
8,
403,
12,
574,
430,
221,
327,
9388,
734,
2701,
3326,
14,
267,
291,
423,
604,
3508,
83,
275,
450,
83,
7,
450,
334,
498,
12,
574,
395,
4363,
9,
339,
347,
4203,
8,
277,
12,
536,
12,
5818,
304,
267,
291,
423,
604,
360,
2293,
450,
83,
7,
450,
536,
9,
267,
291,
14,
1975,
360,
4631,
297,
5818,
12,
4363,
29,
17,
9,
339,
347,
2332,
8,
277,
12,
536,
12,
1414,
12,
1369,
29,
403,
12,
2657,
493,
29,
403,
12,
1467,
4306,
29,
797,
12,
4203,
29,
403,
12,
295,
3736,
29,
797,
12,
25938,
29,
403,
12,
1467,
25938,
63,
1317,
29,
403,
12,
10140,
29,
403,
304,
267,
291,
423,
604,
360,
2200,
450,
83,
7,
450,
536,
9,
267,
291,
14,
1975,
360,
1531,
297,
1414,
12,
4363,
29,
17,
9,
267,
340,
1369,
26,
288,
291,
14,
1975,
360,
1802,
297,
1369,
12,
4363,
29,
17,
9,
267,
340,
2657,
493,
26,
288,
291,
14,
1975,
360,
2601,
493,
297,
2657,
493,
12,
4363,
29,
17,
9,
267,
340,
4306,
26,
288,
291,
14,
1975,
360,
4679,
297,
283,
17,
297,
4363,
29,
17,
9,
267,
340,
4203,
26,
288,
291,
14,
1975,
360,
2293,
297,
4203,
12,
4363,
29,
17,
9,
267,
340,
295,
3736,
26,
288,
291,
14,
1975,
360,
264,
3736,
297,
283,
17,
297,
4363,
29,
17,
9,
267,
340,
25938,
26,
288,
291,
14,
1975,
360,
15642,
493,
297,
25938,
12,
4363,
29,
17,
9,
267,
340,
25938,
63,
1317,
26,
288,
291,
14,
1975,
360,
15642,
493,
63,
1317,
297,
25938,
63,
1317,
12,
4363,
29,
17,
9,
267,
340,
10140,
26,
288,
291,
14,
1975,
360,
5846,
297,
10140,
12,
4363,
29,
17,
9,
339,
347,
1900,
8,
277,
12,
4704,
12,
2332,
12,
4153,
29,
403,
12,
9227,
29,
403,
12,
1865,
63,
2118,
29,
403,
12,
1598,
2860,
29,
403,
304,
267,
4704,
275,
291,
423,
305,
63,
513,
8,
4467,
9,
267,
1006,
63,
3711,
275,
291,
423,
305,
63,
513,
8,
3711,
9,
5873,
267,
734,
63,
4467,
275,
769,
8,
1130,
8,
3765,
63,
515,
12,
4704,
430,
267,
1006,
63,
3711,
275,
769,
8,
1130,
8,
3765,
63,
515,
12,
1006,
63,
3711,
430,
398,
340,
9227,
26,
288,
9227,
275,
2341,
8,
3765,
63,
515,
12,
291,
423,
305,
63,
513,
8,
11886,
430,
288,
1006,
63,
3711,
14,
740,
20137,
358,
288,
1006,
63,
3711,
14,
2880,
8,
11886,
9,
267,
340,
1865,
63,
2118,
26,
288,
1865,
63,
2118,
275,
2341,
8,
3765,
63,
515,
12,
291,
423,
305,
63,
513,
8,
1648,
63,
2118,
430,
288,
1006,
63,
3711,
14,
740,
360,
10644,
358,
288,
1006,
63,
3711,
14,
2880,
8,
1648,
63,
2118,
9,
398,
291,
423,
604,
360,
1506,
450,
83,
26,
450,
83,
7,
450,
661,
1987,
904,
8,
548,
63,
4467,
395,
3147,
283,
1987,
904,
779,
2200,
61,
435,
1006,
63,
3711,
1724,
398,
340,
2860,
26,
288,
340,
1228,
8,
3669,
12,
1211,
304,
355,
6122,
275,
2740,
8,
3669,
14,
1744,
1012,
288,
587,
26,
355,
6122,
275,
2740,
8,
3669,
9,
953,
367,
790,
12,
1139,
315,
6122,
26,
355,
291,
14,
1975,
8,
498,
12,
1139,
12,
4363,
29,
17,
9,
398,
372,
4704,
339,
347,
2387,
8,
277,
12,
931,
304,
267,
291,
423,
604,
360,
2613,
450,
83,
7,
450,
931,
9,
339,
347,
1007,
8675,
8,
277,
12,
931,
304,
267,
291,
423,
604,
360,
954,
8675,
450,
83,
7,
450,
931,
9,
339,
347,
849,
8,
277,
12,
3792,
304,
267,
291,
423,
604,
360,
885,
450,
83,
7,
450,
283,
1987,
904,
8,
277,
423,
305,
63,
513,
8,
3771,
1724,
339,
347,
485,
835,
63,
68,
14385,
4291,
63,
5182,
63,
1080,
8,
277,
12,
308,
12,
284,
304,
489,
408,
3407,
314,
1329,
402,
25271,
4110,
2451,
315,
13738,
402,
308,
59,
73,
61,
1041,
489,
366,
25317,
63,
835,
275,
378,
489,
366,
25317,
63,
1080,
275,
284,
446,
413,
489,
1830,
366,
25317,
63,
1080,
690,
378,
436,
308,
59,
68,
25317,
63,
1080,
61,
508,
4505,
356,
267,
366,
25317,
63,
835,
847,
413,
267,
366,
25317,
63,
1080,
4862,
413,
489,
372,
366,
25317,
63,
835,
339,
347,
485,
604,
8,
277,
12,
1318,
12,
4363,
29,
16,
304,
267,
408,
3534,
283,
505,
7,
4349,
13,
9130,
737,
291,
14,
2063,
4110,
1041,
267,
9186,
63,
2638,
275,
283,
221,
283,
627,
4363,
267,
1830,
822,
8,
16812,
63,
2638,
9,
435,
822,
8,
505,
9,
690,
291,
14,
2063,
26,
288,
327,
710,
1318,
365,
4634,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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cyrillic.py
|
93
|
14017
|
""" Python Character Mapping Codec mac_cyrillic generated from 'MAPPINGS/VENDORS/APPLE/CYRILLIC.TXT' with gencodec.py.
"""#"
import codecs
### Codec APIs
class Codec(codecs.Codec):
def encode(self,input,errors='strict'):
return codecs.charmap_encode(input,errors,encoding_table)
def decode(self,input,errors='strict'):
return codecs.charmap_decode(input,errors,decoding_table)
class IncrementalEncoder(codecs.IncrementalEncoder):
def encode(self, input, final=False):
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
class IncrementalDecoder(codecs.IncrementalDecoder):
def decode(self, input, final=False):
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
class StreamWriter(Codec,codecs.StreamWriter):
pass
class StreamReader(Codec,codecs.StreamReader):
pass
### encodings module API
def getregentry():
return codecs.CodecInfo(
name='mac-cyrillic',
encode=Codec().encode,
decode=Codec().decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
)
### Decoding Table
decoding_table = (
u'\x00' # 0x00 -> CONTROL CHARACTER
u'\x01' # 0x01 -> CONTROL CHARACTER
u'\x02' # 0x02 -> CONTROL CHARACTER
u'\x03' # 0x03 -> CONTROL CHARACTER
u'\x04' # 0x04 -> CONTROL CHARACTER
u'\x05' # 0x05 -> CONTROL CHARACTER
u'\x06' # 0x06 -> CONTROL CHARACTER
u'\x07' # 0x07 -> CONTROL CHARACTER
u'\x08' # 0x08 -> CONTROL CHARACTER
u'\t' # 0x09 -> CONTROL CHARACTER
u'\n' # 0x0A -> CONTROL CHARACTER
u'\x0b' # 0x0B -> CONTROL CHARACTER
u'\x0c' # 0x0C -> CONTROL CHARACTER
u'\r' # 0x0D -> CONTROL CHARACTER
u'\x0e' # 0x0E -> CONTROL CHARACTER
u'\x0f' # 0x0F -> CONTROL CHARACTER
u'\x10' # 0x10 -> CONTROL CHARACTER
u'\x11' # 0x11 -> CONTROL CHARACTER
u'\x12' # 0x12 -> CONTROL CHARACTER
u'\x13' # 0x13 -> CONTROL CHARACTER
u'\x14' # 0x14 -> CONTROL CHARACTER
u'\x15' # 0x15 -> CONTROL CHARACTER
u'\x16' # 0x16 -> CONTROL CHARACTER
u'\x17' # 0x17 -> CONTROL CHARACTER
u'\x18' # 0x18 -> CONTROL CHARACTER
u'\x19' # 0x19 -> CONTROL CHARACTER
u'\x1a' # 0x1A -> CONTROL CHARACTER
u'\x1b' # 0x1B -> CONTROL CHARACTER
u'\x1c' # 0x1C -> CONTROL CHARACTER
u'\x1d' # 0x1D -> CONTROL CHARACTER
u'\x1e' # 0x1E -> CONTROL CHARACTER
u'\x1f' # 0x1F -> CONTROL CHARACTER
u' ' # 0x20 -> SPACE
u'!' # 0x21 -> EXCLAMATION MARK
u'"' # 0x22 -> QUOTATION MARK
u'#' # 0x23 -> NUMBER SIGN
u'$' # 0x24 -> DOLLAR SIGN
u'%' # 0x25 -> PERCENT SIGN
u'&' # 0x26 -> AMPERSAND
u"'" # 0x27 -> APOSTROPHE
u'(' # 0x28 -> LEFT PARENTHESIS
u')' # 0x29 -> RIGHT PARENTHESIS
u'*' # 0x2A -> ASTERISK
u'+' # 0x2B -> PLUS SIGN
u',' # 0x2C -> COMMA
u'-' # 0x2D -> HYPHEN-MINUS
u'.' # 0x2E -> FULL STOP
u'/' # 0x2F -> SOLIDUS
u'0' # 0x30 -> DIGIT ZERO
u'1' # 0x31 -> DIGIT ONE
u'2' # 0x32 -> DIGIT TWO
u'3' # 0x33 -> DIGIT THREE
u'4' # 0x34 -> DIGIT FOUR
u'5' # 0x35 -> DIGIT FIVE
u'6' # 0x36 -> DIGIT SIX
u'7' # 0x37 -> DIGIT SEVEN
u'8' # 0x38 -> DIGIT EIGHT
u'9' # 0x39 -> DIGIT NINE
u':' # 0x3A -> COLON
u';' # 0x3B -> SEMICOLON
u'<' # 0x3C -> LESS-THAN SIGN
u'=' # 0x3D -> EQUALS SIGN
u'>' # 0x3E -> GREATER-THAN SIGN
u'?' # 0x3F -> QUESTION MARK
u'@' # 0x40 -> COMMERCIAL AT
u'A' # 0x41 -> LATIN CAPITAL LETTER A
u'B' # 0x42 -> LATIN CAPITAL LETTER B
u'C' # 0x43 -> LATIN CAPITAL LETTER C
u'D' # 0x44 -> LATIN CAPITAL LETTER D
u'E' # 0x45 -> LATIN CAPITAL LETTER E
u'F' # 0x46 -> LATIN CAPITAL LETTER F
u'G' # 0x47 -> LATIN CAPITAL LETTER G
u'H' # 0x48 -> LATIN CAPITAL LETTER H
u'I' # 0x49 -> LATIN CAPITAL LETTER I
u'J' # 0x4A -> LATIN CAPITAL LETTER J
u'K' # 0x4B -> LATIN CAPITAL LETTER K
u'L' # 0x4C -> LATIN CAPITAL LETTER L
u'M' # 0x4D -> LATIN CAPITAL LETTER M
u'N' # 0x4E -> LATIN CAPITAL LETTER N
u'O' # 0x4F -> LATIN CAPITAL LETTER O
u'P' # 0x50 -> LATIN CAPITAL LETTER P
u'Q' # 0x51 -> LATIN CAPITAL LETTER Q
u'R' # 0x52 -> LATIN CAPITAL LETTER R
u'S' # 0x53 -> LATIN CAPITAL LETTER S
u'T' # 0x54 -> LATIN CAPITAL LETTER T
u'U' # 0x55 -> LATIN CAPITAL LETTER U
u'V' # 0x56 -> LATIN CAPITAL LETTER V
u'W' # 0x57 -> LATIN CAPITAL LETTER W
u'X' # 0x58 -> LATIN CAPITAL LETTER X
u'Y' # 0x59 -> LATIN CAPITAL LETTER Y
u'Z' # 0x5A -> LATIN CAPITAL LETTER Z
u'[' # 0x5B -> LEFT SQUARE BRACKET
u'\\' # 0x5C -> REVERSE SOLIDUS
u']' # 0x5D -> RIGHT SQUARE BRACKET
u'^' # 0x5E -> CIRCUMFLEX ACCENT
u'_' # 0x5F -> LOW LINE
u'`' # 0x60 -> GRAVE ACCENT
u'a' # 0x61 -> LATIN SMALL LETTER A
u'b' # 0x62 -> LATIN SMALL LETTER B
u'c' # 0x63 -> LATIN SMALL LETTER C
u'd' # 0x64 -> LATIN SMALL LETTER D
u'e' # 0x65 -> LATIN SMALL LETTER E
u'f' # 0x66 -> LATIN SMALL LETTER F
u'g' # 0x67 -> LATIN SMALL LETTER G
u'h' # 0x68 -> LATIN SMALL LETTER H
u'i' # 0x69 -> LATIN SMALL LETTER I
u'j' # 0x6A -> LATIN SMALL LETTER J
u'k' # 0x6B -> LATIN SMALL LETTER K
u'l' # 0x6C -> LATIN SMALL LETTER L
u'm' # 0x6D -> LATIN SMALL LETTER M
u'n' # 0x6E -> LATIN SMALL LETTER N
u'o' # 0x6F -> LATIN SMALL LETTER O
u'p' # 0x70 -> LATIN SMALL LETTER P
u'q' # 0x71 -> LATIN SMALL LETTER Q
u'r' # 0x72 -> LATIN SMALL LETTER R
u's' # 0x73 -> LATIN SMALL LETTER S
u't' # 0x74 -> LATIN SMALL LETTER T
u'u' # 0x75 -> LATIN SMALL LETTER U
u'v' # 0x76 -> LATIN SMALL LETTER V
u'w' # 0x77 -> LATIN SMALL LETTER W
u'x' # 0x78 -> LATIN SMALL LETTER X
u'y' # 0x79 -> LATIN SMALL LETTER Y
u'z' # 0x7A -> LATIN SMALL LETTER Z
u'{' # 0x7B -> LEFT CURLY BRACKET
u'|' # 0x7C -> VERTICAL LINE
u'}' # 0x7D -> RIGHT CURLY BRACKET
u'~' # 0x7E -> TILDE
u'\x7f' # 0x7F -> CONTROL CHARACTER
u'\u0410' # 0x80 -> CYRILLIC CAPITAL LETTER A
u'\u0411' # 0x81 -> CYRILLIC CAPITAL LETTER BE
u'\u0412' # 0x82 -> CYRILLIC CAPITAL LETTER VE
u'\u0413' # 0x83 -> CYRILLIC CAPITAL LETTER GHE
u'\u0414' # 0x84 -> CYRILLIC CAPITAL LETTER DE
u'\u0415' # 0x85 -> CYRILLIC CAPITAL LETTER IE
u'\u0416' # 0x86 -> CYRILLIC CAPITAL LETTER ZHE
u'\u0417' # 0x87 -> CYRILLIC CAPITAL LETTER ZE
u'\u0418' # 0x88 -> CYRILLIC CAPITAL LETTER I
u'\u0419' # 0x89 -> CYRILLIC CAPITAL LETTER SHORT I
u'\u041a' # 0x8A -> CYRILLIC CAPITAL LETTER KA
u'\u041b' # 0x8B -> CYRILLIC CAPITAL LETTER EL
u'\u041c' # 0x8C -> CYRILLIC CAPITAL LETTER EM
u'\u041d' # 0x8D -> CYRILLIC CAPITAL LETTER EN
u'\u041e' # 0x8E -> CYRILLIC CAPITAL LETTER O
u'\u041f' # 0x8F -> CYRILLIC CAPITAL LETTER PE
u'\u0420' # 0x90 -> CYRILLIC CAPITAL LETTER ER
u'\u0421' # 0x91 -> CYRILLIC CAPITAL LETTER ES
u'\u0422' # 0x92 -> CYRILLIC CAPITAL LETTER TE
u'\u0423' # 0x93 -> CYRILLIC CAPITAL LETTER U
u'\u0424' # 0x94 -> CYRILLIC CAPITAL LETTER EF
u'\u0425' # 0x95 -> CYRILLIC CAPITAL LETTER HA
u'\u0426' # 0x96 -> CYRILLIC CAPITAL LETTER TSE
u'\u0427' # 0x97 -> CYRILLIC CAPITAL LETTER CHE
u'\u0428' # 0x98 -> CYRILLIC CAPITAL LETTER SHA
u'\u0429' # 0x99 -> CYRILLIC CAPITAL LETTER SHCHA
u'\u042a' # 0x9A -> CYRILLIC CAPITAL LETTER HARD SIGN
u'\u042b' # 0x9B -> CYRILLIC CAPITAL LETTER YERU
u'\u042c' # 0x9C -> CYRILLIC CAPITAL LETTER SOFT SIGN
u'\u042d' # 0x9D -> CYRILLIC CAPITAL LETTER E
u'\u042e' # 0x9E -> CYRILLIC CAPITAL LETTER YU
u'\u042f' # 0x9F -> CYRILLIC CAPITAL LETTER YA
u'\u2020' # 0xA0 -> DAGGER
u'\xb0' # 0xA1 -> DEGREE SIGN
u'\u0490' # 0xA2 -> CYRILLIC CAPITAL LETTER GHE WITH UPTURN
u'\xa3' # 0xA3 -> POUND SIGN
u'\xa7' # 0xA4 -> SECTION SIGN
u'\u2022' # 0xA5 -> BULLET
u'\xb6' # 0xA6 -> PILCROW SIGN
u'\u0406' # 0xA7 -> CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I
u'\xae' # 0xA8 -> REGISTERED SIGN
u'\xa9' # 0xA9 -> COPYRIGHT SIGN
u'\u2122' # 0xAA -> TRADE MARK SIGN
u'\u0402' # 0xAB -> CYRILLIC CAPITAL LETTER DJE
u'\u0452' # 0xAC -> CYRILLIC SMALL LETTER DJE
u'\u2260' # 0xAD -> NOT EQUAL TO
u'\u0403' # 0xAE -> CYRILLIC CAPITAL LETTER GJE
u'\u0453' # 0xAF -> CYRILLIC SMALL LETTER GJE
u'\u221e' # 0xB0 -> INFINITY
u'\xb1' # 0xB1 -> PLUS-MINUS SIGN
u'\u2264' # 0xB2 -> LESS-THAN OR EQUAL TO
u'\u2265' # 0xB3 -> GREATER-THAN OR EQUAL TO
u'\u0456' # 0xB4 -> CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I
u'\xb5' # 0xB5 -> MICRO SIGN
u'\u0491' # 0xB6 -> CYRILLIC SMALL LETTER GHE WITH UPTURN
u'\u0408' # 0xB7 -> CYRILLIC CAPITAL LETTER JE
u'\u0404' # 0xB8 -> CYRILLIC CAPITAL LETTER UKRAINIAN IE
u'\u0454' # 0xB9 -> CYRILLIC SMALL LETTER UKRAINIAN IE
u'\u0407' # 0xBA -> CYRILLIC CAPITAL LETTER YI
u'\u0457' # 0xBB -> CYRILLIC SMALL LETTER YI
u'\u0409' # 0xBC -> CYRILLIC CAPITAL LETTER LJE
u'\u0459' # 0xBD -> CYRILLIC SMALL LETTER LJE
u'\u040a' # 0xBE -> CYRILLIC CAPITAL LETTER NJE
u'\u045a' # 0xBF -> CYRILLIC SMALL LETTER NJE
u'\u0458' # 0xC0 -> CYRILLIC SMALL LETTER JE
u'\u0405' # 0xC1 -> CYRILLIC CAPITAL LETTER DZE
u'\xac' # 0xC2 -> NOT SIGN
u'\u221a' # 0xC3 -> SQUARE ROOT
u'\u0192' # 0xC4 -> LATIN SMALL LETTER F WITH HOOK
u'\u2248' # 0xC5 -> ALMOST EQUAL TO
u'\u2206' # 0xC6 -> INCREMENT
u'\xab' # 0xC7 -> LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
u'\xbb' # 0xC8 -> RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
u'\u2026' # 0xC9 -> HORIZONTAL ELLIPSIS
u'\xa0' # 0xCA -> NO-BREAK SPACE
u'\u040b' # 0xCB -> CYRILLIC CAPITAL LETTER TSHE
u'\u045b' # 0xCC -> CYRILLIC SMALL LETTER TSHE
u'\u040c' # 0xCD -> CYRILLIC CAPITAL LETTER KJE
u'\u045c' # 0xCE -> CYRILLIC SMALL LETTER KJE
u'\u0455' # 0xCF -> CYRILLIC SMALL LETTER DZE
u'\u2013' # 0xD0 -> EN DASH
u'\u2014' # 0xD1 -> EM DASH
u'\u201c' # 0xD2 -> LEFT DOUBLE QUOTATION MARK
u'\u201d' # 0xD3 -> RIGHT DOUBLE QUOTATION MARK
u'\u2018' # 0xD4 -> LEFT SINGLE QUOTATION MARK
u'\u2019' # 0xD5 -> RIGHT SINGLE QUOTATION MARK
u'\xf7' # 0xD6 -> DIVISION SIGN
u'\u201e' # 0xD7 -> DOUBLE LOW-9 QUOTATION MARK
u'\u040e' # 0xD8 -> CYRILLIC CAPITAL LETTER SHORT U
u'\u045e' # 0xD9 -> CYRILLIC SMALL LETTER SHORT U
u'\u040f' # 0xDA -> CYRILLIC CAPITAL LETTER DZHE
u'\u045f' # 0xDB -> CYRILLIC SMALL LETTER DZHE
u'\u2116' # 0xDC -> NUMERO SIGN
u'\u0401' # 0xDD -> CYRILLIC CAPITAL LETTER IO
u'\u0451' # 0xDE -> CYRILLIC SMALL LETTER IO
u'\u044f' # 0xDF -> CYRILLIC SMALL LETTER YA
u'\u0430' # 0xE0 -> CYRILLIC SMALL LETTER A
u'\u0431' # 0xE1 -> CYRILLIC SMALL LETTER BE
u'\u0432' # 0xE2 -> CYRILLIC SMALL LETTER VE
u'\u0433' # 0xE3 -> CYRILLIC SMALL LETTER GHE
u'\u0434' # 0xE4 -> CYRILLIC SMALL LETTER DE
u'\u0435' # 0xE5 -> CYRILLIC SMALL LETTER IE
u'\u0436' # 0xE6 -> CYRILLIC SMALL LETTER ZHE
u'\u0437' # 0xE7 -> CYRILLIC SMALL LETTER ZE
u'\u0438' # 0xE8 -> CYRILLIC SMALL LETTER I
u'\u0439' # 0xE9 -> CYRILLIC SMALL LETTER SHORT I
u'\u043a' # 0xEA -> CYRILLIC SMALL LETTER KA
u'\u043b' # 0xEB -> CYRILLIC SMALL LETTER EL
u'\u043c' # 0xEC -> CYRILLIC SMALL LETTER EM
u'\u043d' # 0xED -> CYRILLIC SMALL LETTER EN
u'\u043e' # 0xEE -> CYRILLIC SMALL LETTER O
u'\u043f' # 0xEF -> CYRILLIC SMALL LETTER PE
u'\u0440' # 0xF0 -> CYRILLIC SMALL LETTER ER
u'\u0441' # 0xF1 -> CYRILLIC SMALL LETTER ES
u'\u0442' # 0xF2 -> CYRILLIC SMALL LETTER TE
u'\u0443' # 0xF3 -> CYRILLIC SMALL LETTER U
u'\u0444' # 0xF4 -> CYRILLIC SMALL LETTER EF
u'\u0445' # 0xF5 -> CYRILLIC SMALL LETTER HA
u'\u0446' # 0xF6 -> CYRILLIC SMALL LETTER TSE
u'\u0447' # 0xF7 -> CYRILLIC SMALL LETTER CHE
u'\u0448' # 0xF8 -> CYRILLIC SMALL LETTER SHA
u'\u0449' # 0xF9 -> CYRILLIC SMALL LETTER SHCHA
u'\u044a' # 0xFA -> CYRILLIC SMALL LETTER HARD SIGN
u'\u044b' # 0xFB -> CYRILLIC SMALL LETTER YERU
u'\u044c' # 0xFC -> CYRILLIC SMALL LETTER SOFT SIGN
u'\u044d' # 0xFD -> CYRILLIC SMALL LETTER E
u'\u044e' # 0xFE -> CYRILLIC SMALL LETTER YU
u'\u20ac' # 0xFF -> EURO SIGN
)
### Encoding table
encoding_table=codecs.charmap_build(decoding_table)
|
apache-2.0
|
[
624,
2018,
17660,
12340,
13732,
4497,
63,
17405,
4046,
687,
283,
32362,
15,
27839,
4149,
15,
31683,
15,
35,
6191,
14,
17715,
7,
543,
486,
2143,
67,
14,
647,
14,
2999,
199,
624,
23662,
2999,
199,
646,
6010,
2999,
199,
5680,
13732,
15913,
2999,
199,
533,
13732,
8,
8933,
14,
8818,
304,
2958,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
1039,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
2550,
12,
2991,
63,
1224,
9,
2958,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
1039,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
2550,
12,
12796,
63,
1224,
9,
2999,
199,
533,
24350,
8,
8933,
14,
17016,
304,
1128,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
1039,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
277,
14,
2550,
12,
2991,
63,
1224,
2788,
16,
61,
2999,
199,
533,
24385,
8,
8933,
14,
16703,
304,
1128,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
1039,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
277,
14,
2550,
12,
12796,
63,
1224,
2788,
16,
61,
2999,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
1128,
986,
2999,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
1128,
986,
2999,
199,
5680,
14134,
859,
3261,
2999,
199,
318,
26116,
837,
1128,
372,
6010,
14,
26375,
8,
1039,
536,
534,
3088,
13,
17405,
297,
1039,
3752,
29,
8818,
1252,
2143,
12,
1039,
4849,
29,
8818,
1252,
2708,
12,
1039,
26329,
29,
17016,
12,
1039,
26317,
29,
16703,
12,
1039,
26101,
29,
16132,
12,
1039,
26112,
29,
16551,
12,
1128,
776,
8065,
199,
5680,
27368,
6957,
2999,
199,
12796,
63,
1224,
275,
334,
1128,
399,
1154,
88,
383,
7,
258,
327,
221,
378,
88,
383,
1035,
8098,
9502,
1128,
399,
1154,
88,
614,
7,
258,
327,
221,
378,
88,
614,
1035,
8098,
9502,
1128,
399,
1154,
88,
996,
7,
258,
327,
221,
378,
88,
996,
1035,
8098,
9502,
1128,
399,
1154,
88,
1644,
7,
258,
327,
221,
378,
88,
1644,
1035,
8098,
9502,
1128,
399,
1154,
88,
966,
7,
258,
327,
221,
378,
88,
966,
1035,
8098,
9502,
1128,
399,
1154,
88,
1717,
7,
258,
327,
221,
378,
88,
1717,
1035,
8098,
9502,
1128,
399,
1154,
88,
1690,
7,
258,
327,
221,
378,
88,
1690,
1035,
8098,
9502,
1128,
399,
1154,
88,
1780,
7,
258,
327,
221,
378,
88,
1780,
1035,
8098,
9502,
1128,
399,
1154,
88,
2036,
7,
258,
327,
221,
378,
88,
2036,
1035,
8098,
9502,
1128,
399,
1154,
84,
7,
755,
327,
221,
378,
88,
1643,
1035,
8098,
9502,
1128,
399,
1154,
78,
7,
755,
327,
221,
378,
88,
16,
33,
1035,
8098,
9502,
1128,
399,
1154,
88,
16,
66,
7,
258,
327,
221,
378,
88,
16,
34,
1035,
8098,
9502,
1128,
399,
1154,
88,
16,
67,
7,
258,
327,
221,
378,
88,
16,
35,
1035,
8098,
9502,
1128,
399,
1154,
82,
7,
755,
327,
221,
378,
88,
16,
36,
1035,
8098,
9502,
1128,
399,
1154,
88,
16,
69,
7,
258,
327,
221,
378,
88,
16,
37,
1035,
8098,
9502,
1128,
399,
1154,
88,
16,
70,
7,
258,
327,
221,
378,
88,
16,
38,
1035,
8098,
9502,
1128,
399,
1154,
88,
709,
7,
258,
327,
221,
378,
88,
709,
1035,
8098,
9502,
1128,
399,
1154,
88,
845,
7,
258,
327,
221,
378,
88,
845,
1035,
8098,
9502,
1128,
399,
1154,
88,
713,
7,
258,
327,
221,
378,
88,
713,
1035,
8098,
9502,
1128,
399,
1154,
88,
969,
7,
258,
327,
221,
378,
88,
969,
1035,
8098,
9502,
1128,
399,
1154,
88,
1079,
7,
258,
327,
221,
378,
88,
1079,
1035,
8098,
9502,
1128,
399,
1154,
88,
1046,
7,
258,
327,
221,
378,
88,
1046,
1035,
8098,
9502,
1128,
399,
1154,
88,
975,
7,
258,
327,
221,
378,
88,
975,
1035,
8098,
9502,
1128,
399,
1154,
88,
1196,
7,
258,
327,
221,
378,
88,
1196,
1035,
8098,
9502,
1128,
399,
1154,
88,
1085,
7,
258,
327,
221,
378,
88,
1085,
1035,
8098,
9502,
1128,
399,
1154,
88,
1167,
7,
258,
327,
221,
378,
88,
1167,
1035,
8098,
9502,
1128,
399,
1154,
88,
17,
65,
7,
258,
327,
221,
378,
88,
17,
33,
1035,
8098,
9502,
1128,
399,
1154,
88,
17,
66,
7,
258,
327,
221,
378,
88,
17,
34,
1035,
8098,
9502,
1128,
399,
1154,
88,
17,
67,
7,
258,
327,
221,
378,
88,
17,
35,
1035,
8098,
9502,
1128,
399,
1154,
88,
17,
68,
7,
258,
327,
221,
378,
88,
17,
36,
1035,
8098,
9502,
1128,
399,
1154,
88,
17,
69,
7,
258,
327,
221,
378,
88,
17,
37,
1035,
8098,
9502,
1128,
399,
1154,
88,
17,
70,
7,
258,
327,
221,
378,
88,
17,
38,
1035,
8098,
9502,
1128,
399,
7,
283,
263,
327,
221,
378,
88,
1165,
1035,
16796,
1128,
399,
7,
11213,
263,
327,
221,
378,
88,
2025,
1035,
24232,
8132,
1128,
399,
30385,
263,
327,
221,
378,
88,
1081,
1035,
11830,
8132,
1128,
399,
11525,
7,
263,
327,
221,
378,
88,
1789,
1035,
18122,
5056,
1128,
399,
7,
12913,
263,
327,
221,
378,
88,
1194,
1035,
30857,
5056,
1128,
399,
5956,
7,
263,
327,
221,
378,
88,
821,
1035,
26684,
5056,
1128,
399,
21840,
7,
263,
327,
221,
378,
88,
1479,
1035,
30602,
1128,
399,
2,
4065,
263,
327,
221,
378,
88,
1465,
1035,
30876,
1128,
399,
7,
360,
263,
327,
221,
378,
88,
1651,
1035,
6578,
20570,
1128,
399,
358,
7,
263,
327,
221,
378,
88,
1398,
1035,
7052,
20570,
1128,
399,
7,
10223,
263,
327,
221,
378,
88,
18,
33,
1035,
29725,
1128,
399,
30269,
263,
327,
221,
378,
88,
18,
34,
1035,
18807,
5056,
1128,
399,
1673,
263,
327,
221,
378,
88,
18,
35,
1035,
22849,
1128,
399,
12418,
7,
263,
327,
221,
378,
88,
18,
36,
1035,
22553,
13,
18004,
1128,
399,
30484,
263,
327,
221,
378,
88,
18,
37,
1035,
18530,
22348,
1128,
399,
29957,
263,
327,
221,
378,
88,
18,
38,
1035,
20585,
1128,
399,
7,
16,
7,
263,
327,
221,
378,
88,
1216,
1035,
7298,
20348,
1128,
399,
7,
17,
7,
263,
327,
221,
378,
88,
2192,
1035,
7298,
13051,
1128,
399,
7,
18,
7
] |
[
2018,
17660,
12340,
13732,
4497,
63,
17405,
4046,
687,
283,
32362,
15,
27839,
4149,
15,
31683,
15,
35,
6191,
14,
17715,
7,
543,
486,
2143,
67,
14,
647,
14,
2999,
199,
624,
23662,
2999,
199,
646,
6010,
2999,
199,
5680,
13732,
15913,
2999,
199,
533,
13732,
8,
8933,
14,
8818,
304,
2958,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
1039,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
2550,
12,
2991,
63,
1224,
9,
2958,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
1039,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
2550,
12,
12796,
63,
1224,
9,
2999,
199,
533,
24350,
8,
8933,
14,
17016,
304,
1128,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
1039,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
277,
14,
2550,
12,
2991,
63,
1224,
2788,
16,
61,
2999,
199,
533,
24385,
8,
8933,
14,
16703,
304,
1128,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
1039,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
277,
14,
2550,
12,
12796,
63,
1224,
2788,
16,
61,
2999,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
1128,
986,
2999,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
1128,
986,
2999,
199,
5680,
14134,
859,
3261,
2999,
199,
318,
26116,
837,
1128,
372,
6010,
14,
26375,
8,
1039,
536,
534,
3088,
13,
17405,
297,
1039,
3752,
29,
8818,
1252,
2143,
12,
1039,
4849,
29,
8818,
1252,
2708,
12,
1039,
26329,
29,
17016,
12,
1039,
26317,
29,
16703,
12,
1039,
26101,
29,
16132,
12,
1039,
26112,
29,
16551,
12,
1128,
776,
8065,
199,
5680,
27368,
6957,
2999,
199,
12796,
63,
1224,
275,
334,
1128,
399,
1154,
88,
383,
7,
258,
327,
221,
378,
88,
383,
1035,
8098,
9502,
1128,
399,
1154,
88,
614,
7,
258,
327,
221,
378,
88,
614,
1035,
8098,
9502,
1128,
399,
1154,
88,
996,
7,
258,
327,
221,
378,
88,
996,
1035,
8098,
9502,
1128,
399,
1154,
88,
1644,
7,
258,
327,
221,
378,
88,
1644,
1035,
8098,
9502,
1128,
399,
1154,
88,
966,
7,
258,
327,
221,
378,
88,
966,
1035,
8098,
9502,
1128,
399,
1154,
88,
1717,
7,
258,
327,
221,
378,
88,
1717,
1035,
8098,
9502,
1128,
399,
1154,
88,
1690,
7,
258,
327,
221,
378,
88,
1690,
1035,
8098,
9502,
1128,
399,
1154,
88,
1780,
7,
258,
327,
221,
378,
88,
1780,
1035,
8098,
9502,
1128,
399,
1154,
88,
2036,
7,
258,
327,
221,
378,
88,
2036,
1035,
8098,
9502,
1128,
399,
1154,
84,
7,
755,
327,
221,
378,
88,
1643,
1035,
8098,
9502,
1128,
399,
1154,
78,
7,
755,
327,
221,
378,
88,
16,
33,
1035,
8098,
9502,
1128,
399,
1154,
88,
16,
66,
7,
258,
327,
221,
378,
88,
16,
34,
1035,
8098,
9502,
1128,
399,
1154,
88,
16,
67,
7,
258,
327,
221,
378,
88,
16,
35,
1035,
8098,
9502,
1128,
399,
1154,
82,
7,
755,
327,
221,
378,
88,
16,
36,
1035,
8098,
9502,
1128,
399,
1154,
88,
16,
69,
7,
258,
327,
221,
378,
88,
16,
37,
1035,
8098,
9502,
1128,
399,
1154,
88,
16,
70,
7,
258,
327,
221,
378,
88,
16,
38,
1035,
8098,
9502,
1128,
399,
1154,
88,
709,
7,
258,
327,
221,
378,
88,
709,
1035,
8098,
9502,
1128,
399,
1154,
88,
845,
7,
258,
327,
221,
378,
88,
845,
1035,
8098,
9502,
1128,
399,
1154,
88,
713,
7,
258,
327,
221,
378,
88,
713,
1035,
8098,
9502,
1128,
399,
1154,
88,
969,
7,
258,
327,
221,
378,
88,
969,
1035,
8098,
9502,
1128,
399,
1154,
88,
1079,
7,
258,
327,
221,
378,
88,
1079,
1035,
8098,
9502,
1128,
399,
1154,
88,
1046,
7,
258,
327,
221,
378,
88,
1046,
1035,
8098,
9502,
1128,
399,
1154,
88,
975,
7,
258,
327,
221,
378,
88,
975,
1035,
8098,
9502,
1128,
399,
1154,
88,
1196,
7,
258,
327,
221,
378,
88,
1196,
1035,
8098,
9502,
1128,
399,
1154,
88,
1085,
7,
258,
327,
221,
378,
88,
1085,
1035,
8098,
9502,
1128,
399,
1154,
88,
1167,
7,
258,
327,
221,
378,
88,
1167,
1035,
8098,
9502,
1128,
399,
1154,
88,
17,
65,
7,
258,
327,
221,
378,
88,
17,
33,
1035,
8098,
9502,
1128,
399,
1154,
88,
17,
66,
7,
258,
327,
221,
378,
88,
17,
34,
1035,
8098,
9502,
1128,
399,
1154,
88,
17,
67,
7,
258,
327,
221,
378,
88,
17,
35,
1035,
8098,
9502,
1128,
399,
1154,
88,
17,
68,
7,
258,
327,
221,
378,
88,
17,
36,
1035,
8098,
9502,
1128,
399,
1154,
88,
17,
69,
7,
258,
327,
221,
378,
88,
17,
37,
1035,
8098,
9502,
1128,
399,
1154,
88,
17,
70,
7,
258,
327,
221,
378,
88,
17,
38,
1035,
8098,
9502,
1128,
399,
7,
283,
263,
327,
221,
378,
88,
1165,
1035,
16796,
1128,
399,
7,
11213,
263,
327,
221,
378,
88,
2025,
1035,
24232,
8132,
1128,
399,
30385,
263,
327,
221,
378,
88,
1081,
1035,
11830,
8132,
1128,
399,
11525,
7,
263,
327,
221,
378,
88,
1789,
1035,
18122,
5056,
1128,
399,
7,
12913,
263,
327,
221,
378,
88,
1194,
1035,
30857,
5056,
1128,
399,
5956,
7,
263,
327,
221,
378,
88,
821,
1035,
26684,
5056,
1128,
399,
21840,
7,
263,
327,
221,
378,
88,
1479,
1035,
30602,
1128,
399,
2,
4065,
263,
327,
221,
378,
88,
1465,
1035,
30876,
1128,
399,
7,
360,
263,
327,
221,
378,
88,
1651,
1035,
6578,
20570,
1128,
399,
358,
7,
263,
327,
221,
378,
88,
1398,
1035,
7052,
20570,
1128,
399,
7,
10223,
263,
327,
221,
378,
88,
18,
33,
1035,
29725,
1128,
399,
30269,
263,
327,
221,
378,
88,
18,
34,
1035,
18807,
5056,
1128,
399,
1673,
263,
327,
221,
378,
88,
18,
35,
1035,
22849,
1128,
399,
12418,
7,
263,
327,
221,
378,
88,
18,
36,
1035,
22553,
13,
18004,
1128,
399,
30484,
263,
327,
221,
378,
88,
18,
37,
1035,
18530,
22348,
1128,
399,
29957,
263,
327,
221,
378,
88,
18,
38,
1035,
20585,
1128,
399,
7,
16,
7,
263,
327,
221,
378,
88,
1216,
1035,
7298,
20348,
1128,
399,
7,
17,
7,
263,
327,
221,
378,
88,
2192,
1035,
7298,
13051,
1128,
399,
7,
18,
7,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
imankulov/sentry
|
tests/sentry/interfaces/test_user.py
|
11
|
1423
|
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import mock
from exam import fixture
from sentry.testutils import TestCase
from sentry.interfaces.user import User
from sentry.models import Event
class UserTest(TestCase):
@fixture
def event(self):
return mock.Mock(spec=Event())
@fixture
def interface(self):
return User.to_python(dict(
id=1,
email='lol@example.com',
favorite_color='brown',
))
def test_path(self):
assert self.interface.get_path() == 'sentry.interfaces.User'
def test_serialize_behavior(self):
assert self.interface.to_json() == {
'id': '1',
'email': 'lol@example.com',
'data': {'favorite_color': 'brown'}
}
def test_invalid_ip_address(self):
with self.assertRaises(Exception):
User.to_python(dict(
ip_address='abc',
))
def test_invalid_email_address(self):
with self.assertRaises(Exception):
User.to_python(dict(
email=1,
))
with self.assertRaises(Exception):
User.to_python(dict(
email='foo',
))
def test_serialize_unserialize_behavior(self):
result = type(self.interface).to_python(self.interface.to_json())
assert result.to_json() == self.interface.to_json()
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
1683,
199,
504,
15735,
492,
10949,
199,
199,
504,
26230,
14,
396,
1208,
492,
7640,
199,
504,
26230,
14,
7436,
14,
751,
492,
2876,
199,
504,
26230,
14,
992,
492,
6763,
421,
199,
533,
2876,
774,
8,
1746,
304,
272,
768,
5997,
272,
347,
1566,
8,
277,
304,
267,
372,
1683,
14,
3346,
8,
1650,
29,
2390,
1012,
339,
768,
5997,
272,
347,
3217,
8,
277,
304,
267,
372,
2876,
14,
475,
63,
1548,
8,
807,
8,
288,
1305,
29,
17,
12,
288,
3031,
534,
320,
76,
32,
2694,
14,
957,
297,
288,
17914,
1175,
63,
2326,
534,
27133,
297,
267,
5082,
339,
347,
511,
63,
515,
8,
277,
304,
267,
702,
291,
14,
3266,
14,
362,
63,
515,
342,
508,
283,
3870,
14,
7436,
14,
1899,
7,
339,
347,
511,
63,
3549,
63,
17537,
8,
277,
304,
267,
702,
291,
14,
3266,
14,
475,
63,
1001,
342,
508,
469,
288,
283,
344,
356,
283,
17,
297,
288,
283,
2123,
356,
283,
320,
76,
32,
2694,
14,
957,
297,
288,
283,
576,
356,
791,
23874,
63,
2326,
356,
283,
27133,
936,
267,
789,
339,
347,
511,
63,
3197,
63,
711,
63,
1562,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
1726,
304,
288,
2876,
14,
475,
63,
1548,
8,
807,
8,
355,
3384,
63,
1562,
534,
3175,
297,
288,
5082,
339,
347,
511,
63,
3197,
63,
2123,
63,
1562,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
1726,
304,
288,
2876,
14,
475,
63,
1548,
8,
807,
8,
355,
3031,
29,
17,
12,
288,
5082,
398,
543,
291,
14,
1855,
8,
1726,
304,
288,
2876,
14,
475,
63,
1548,
8,
807,
8,
355,
3031,
534,
1421,
297,
288,
5082,
339,
347,
511,
63,
3549,
63,
324,
3549,
63,
17537,
8,
277,
304,
267,
754,
275,
730,
8,
277,
14,
3266,
680,
475,
63,
1548,
8,
277,
14,
3266,
14,
475,
63,
1001,
1012,
267,
702,
754,
14,
475,
63,
1001,
342,
508,
291,
14,
3266,
14,
475,
63,
1001,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
1683,
199,
504,
15735,
492,
10949,
199,
199,
504,
26230,
14,
396,
1208,
492,
7640,
199,
504,
26230,
14,
7436,
14,
751,
492,
2876,
199,
504,
26230,
14,
992,
492,
6763,
421,
199,
533,
2876,
774,
8,
1746,
304,
272,
768,
5997,
272,
347,
1566,
8,
277,
304,
267,
372,
1683,
14,
3346,
8,
1650,
29,
2390,
1012,
339,
768,
5997,
272,
347,
3217,
8,
277,
304,
267,
372,
2876,
14,
475,
63,
1548,
8,
807,
8,
288,
1305,
29,
17,
12,
288,
3031,
534,
320,
76,
32,
2694,
14,
957,
297,
288,
17914,
1175,
63,
2326,
534,
27133,
297,
267,
5082,
339,
347,
511,
63,
515,
8,
277,
304,
267,
702,
291,
14,
3266,
14,
362,
63,
515,
342,
508,
283,
3870,
14,
7436,
14,
1899,
7,
339,
347,
511,
63,
3549,
63,
17537,
8,
277,
304,
267,
702,
291,
14,
3266,
14,
475,
63,
1001,
342,
508,
469,
288,
283,
344,
356,
283,
17,
297,
288,
283,
2123,
356,
283,
320,
76,
32,
2694,
14,
957,
297,
288,
283,
576,
356,
791,
23874,
63,
2326,
356,
283,
27133,
936,
267,
789,
339,
347,
511,
63,
3197,
63,
711,
63,
1562,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
1726,
304,
288,
2876,
14,
475,
63,
1548,
8,
807,
8,
355,
3384,
63,
1562,
534,
3175,
297,
288,
5082,
339,
347,
511,
63,
3197,
63,
2123,
63,
1562,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
1726,
304,
288,
2876,
14,
475,
63,
1548,
8,
807,
8,
355,
3031,
29,
17,
12,
288,
5082,
398,
543,
291,
14,
1855,
8,
1726,
304,
288,
2876,
14,
475,
63,
1548,
8,
807,
8,
355,
3031,
534,
1421,
297,
288,
5082,
339,
347,
511,
63,
3549,
63,
324,
3549,
63,
17537,
8,
277,
304,
267,
754,
275,
730,
8,
277,
14,
3266,
680,
475,
63,
1548,
8,
277,
14,
3266,
14,
475,
63,
1001,
1012,
267,
702,
754,
14,
475,
63,
1001,
342,
508,
291,
14,
3266,
14,
475,
63,
1001,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
belokop/indico_bare
|
migrations/versions/201510221159_1d741fc6586c_backup_old_transaction_table.py
|
2
|
2600
|
"""Backup old transaction table
Revision ID: 1d741fc6586c
Revises: f9bb2a03ceb
Create Date: 2015-10-22 11:59:18.116917
"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
from indico.core.db.sqlalchemy import PyIntEnum
from indico.core.db.sqlalchemy import UTCDateTime
from indico.core.db.sqlalchemy.util.bulk_rename import _rename_constraint
from indico.modules.events.payment.models.transactions import TransactionStatus
# revision identifiers, used by Alembic.
revision = '1d741fc6586c'
down_revision = 'f9bb2a03ceb'
def upgrade():
op.rename_table('payment_transactions', 'payment_transactions_old', schema='events')
op.execute(_rename_constraint('events', 'payment_transactions_old',
'pk_payment_transactions', 'pk_payment_transactions_old'))
op.execute("ALTER SEQUENCE events.payment_transactions_id_seq RENAME TO payment_transactions_old_id_seq")
op.create_table(
'payment_transactions',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('registration_id', sa.Integer(), nullable=False, index=True),
sa.Column('status', PyIntEnum(TransactionStatus), nullable=False),
sa.Column('amount', sa.Numeric(precision=8, scale=2), nullable=False),
sa.Column('currency', sa.String(), nullable=False),
sa.Column('provider', sa.String(), nullable=False),
sa.Column('timestamp', UTCDateTime, nullable=False),
sa.Column('data', postgresql.JSON(), nullable=False),
sa.CheckConstraint('amount > 0', name='positive_amount'),
sa.ForeignKeyConstraint(['registration_id'], ['event_registration.registrations.id']),
sa.PrimaryKeyConstraint('id'),
schema='events'
)
op.create_foreign_key(None,
'registrations', 'payment_transactions',
['transaction_id'], ['id'],
source_schema='event_registration', referent_schema='events')
def downgrade():
op.drop_constraint(op.f('fk_registrations_transaction_id_payment_transactions'), 'registrations',
schema='event_registration')
op.drop_table('payment_transactions', schema='events')
op.execute("ALTER SEQUENCE events.payment_transactions_old_id_seq RENAME TO payment_transactions_id_seq")
op.execute(_rename_constraint('events', 'payment_transactions_old',
'pk_payment_transactions_old', 'pk_payment_transactions'))
op.rename_table('payment_transactions_old', 'payment_transactions', schema='events')
|
gpl-3.0
|
[
624,
16559,
2269,
6008,
1817,
199,
199,
12714,
2870,
26,
413,
68,
21996,
3003,
2182,
1184,
67,
199,
497,
433,
874,
26,
289,
25,
2501,
18,
65,
1644,
301,
66,
199,
2499,
6148,
26,
6900,
13,
709,
13,
1081,
4119,
26,
1427,
26,
1085,
14,
845,
1876,
1196,
199,
624,
199,
199,
646,
8335,
465,
2937,
199,
504,
30960,
20596,
492,
1687,
199,
504,
8335,
14,
11072,
83,
492,
25951,
199,
199,
504,
2539,
331,
14,
1018,
14,
697,
14,
14536,
492,
1611,
3241,
5081,
199,
504,
2539,
331,
14,
1018,
14,
697,
14,
14536,
492,
12174,
3926,
199,
504,
2539,
331,
14,
1018,
14,
697,
14,
14536,
14,
1974,
14,
9377,
63,
8165,
492,
485,
8165,
63,
5631,
199,
504,
2539,
331,
14,
3112,
14,
4368,
14,
7948,
14,
992,
14,
13754,
492,
18244,
3694,
421,
199,
3,
6974,
14154,
12,
1202,
701,
6832,
20596,
14,
199,
5792,
275,
283,
17,
68,
21996,
3003,
2182,
1184,
67,
7,
199,
2110,
63,
5792,
275,
283,
70,
25,
2501,
18,
65,
1644,
301,
66,
7,
421,
199,
318,
10754,
837,
272,
1687,
14,
8165,
63,
1224,
360,
7948,
63,
13754,
297,
283,
7948,
63,
13754,
63,
1753,
297,
4177,
534,
4368,
358,
272,
1687,
14,
2526,
1547,
8165,
63,
5631,
360,
4368,
297,
283,
7948,
63,
13754,
63,
1753,
297,
3303,
283,
2051,
63,
7948,
63,
13754,
297,
283,
2051,
63,
7948,
63,
13754,
63,
1753,
1333,
272,
1687,
14,
2526,
480,
19350,
31042,
4474,
14,
7948,
63,
13754,
63,
344,
63,
3610,
820,
11536,
2296,
11628,
63,
13754,
63,
1753,
63,
344,
63,
3610,
531,
272,
1687,
14,
981,
63,
1224,
8,
267,
283,
7948,
63,
13754,
297,
267,
2937,
14,
4547,
360,
344,
297,
2937,
14,
2674,
1062,
7854,
29,
797,
395,
267,
2937,
14,
4547,
360,
8054,
63,
344,
297,
2937,
14,
2674,
1062,
7854,
29,
797,
12,
1478,
29,
549,
395,
267,
2937,
14,
4547,
360,
1205,
297,
1611,
3241,
5081,
8,
10161,
3694,
395,
7854,
29,
797,
395,
267,
2937,
14,
4547,
360,
4606,
297,
2937,
14,
14687,
8,
6833,
29,
24,
12,
4666,
29,
18,
395,
7854,
29,
797,
395,
267,
2937,
14,
4547,
360,
4968,
297,
2937,
14,
1558,
1062,
7854,
29,
797,
395,
267,
2937,
14,
4547,
360,
3780,
297,
2937,
14,
1558,
1062,
7854,
29,
797,
395,
267,
2937,
14,
4547,
360,
3954,
297,
12174,
3926,
12,
7854,
29,
797,
395,
267,
2937,
14,
4547,
360,
576,
297,
25951,
14,
6243,
1062,
7854,
29,
797,
395,
267,
2937,
14,
1799,
8463,
360,
4606,
690,
378,
297,
536,
534,
8965,
63,
4606,
659,
267,
2937,
14,
3190,
8463,
2941,
8054,
63,
344,
995,
788,
1430,
63,
8054,
14,
29440,
14,
344,
3815,
267,
2937,
14,
29457,
8463,
360,
344,
659,
267,
4177,
534,
4368,
7,
272,
776,
272,
1687,
14,
981,
63,
6846,
63,
498,
8,
403,
12,
2079,
283,
29440,
297,
283,
7948,
63,
13754,
297,
2079,
788,
5945,
63,
344,
995,
788,
344,
995,
2079,
1350,
63,
3629,
534,
1430,
63,
8054,
297,
295,
771,
640,
63,
3629,
534,
4368,
358,
421,
199,
318,
32498,
837,
272,
1687,
14,
4824,
63,
5631,
8,
411,
14,
70,
360,
9010,
63,
29440,
63,
5945,
63,
344,
63,
7948,
63,
13754,
659,
283,
29440,
297,
2432,
4177,
534,
1430,
63,
8054,
358,
272,
1687,
14,
4824,
63,
1224,
360,
7948,
63,
13754,
297,
4177,
534,
4368,
358,
272,
1687,
14,
2526,
480,
19350,
31042,
4474,
14,
7948,
63,
13754,
63,
1753,
63,
344,
63,
3610,
820,
11536,
2296,
11628,
63,
13754,
63,
344,
63,
3610,
531,
272,
1687,
14,
2526,
1547,
8165,
63,
5631,
360,
4368,
297,
283,
7948,
63,
13754,
63,
1753,
297,
3303,
283,
2051,
63,
7948,
63,
13754,
63,
1753,
297,
283,
2051,
63,
7948,
63,
13754,
1333,
272,
1687,
14,
8165,
63,
1224,
360,
7948,
63,
13754,
63,
1753,
297,
283,
7948,
63,
13754,
297,
4177,
534,
4368,
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
] |
[
16559,
2269,
6008,
1817,
199,
199,
12714,
2870,
26,
413,
68,
21996,
3003,
2182,
1184,
67,
199,
497,
433,
874,
26,
289,
25,
2501,
18,
65,
1644,
301,
66,
199,
2499,
6148,
26,
6900,
13,
709,
13,
1081,
4119,
26,
1427,
26,
1085,
14,
845,
1876,
1196,
199,
624,
199,
199,
646,
8335,
465,
2937,
199,
504,
30960,
20596,
492,
1687,
199,
504,
8335,
14,
11072,
83,
492,
25951,
199,
199,
504,
2539,
331,
14,
1018,
14,
697,
14,
14536,
492,
1611,
3241,
5081,
199,
504,
2539,
331,
14,
1018,
14,
697,
14,
14536,
492,
12174,
3926,
199,
504,
2539,
331,
14,
1018,
14,
697,
14,
14536,
14,
1974,
14,
9377,
63,
8165,
492,
485,
8165,
63,
5631,
199,
504,
2539,
331,
14,
3112,
14,
4368,
14,
7948,
14,
992,
14,
13754,
492,
18244,
3694,
421,
199,
3,
6974,
14154,
12,
1202,
701,
6832,
20596,
14,
199,
5792,
275,
283,
17,
68,
21996,
3003,
2182,
1184,
67,
7,
199,
2110,
63,
5792,
275,
283,
70,
25,
2501,
18,
65,
1644,
301,
66,
7,
421,
199,
318,
10754,
837,
272,
1687,
14,
8165,
63,
1224,
360,
7948,
63,
13754,
297,
283,
7948,
63,
13754,
63,
1753,
297,
4177,
534,
4368,
358,
272,
1687,
14,
2526,
1547,
8165,
63,
5631,
360,
4368,
297,
283,
7948,
63,
13754,
63,
1753,
297,
3303,
283,
2051,
63,
7948,
63,
13754,
297,
283,
2051,
63,
7948,
63,
13754,
63,
1753,
1333,
272,
1687,
14,
2526,
480,
19350,
31042,
4474,
14,
7948,
63,
13754,
63,
344,
63,
3610,
820,
11536,
2296,
11628,
63,
13754,
63,
1753,
63,
344,
63,
3610,
531,
272,
1687,
14,
981,
63,
1224,
8,
267,
283,
7948,
63,
13754,
297,
267,
2937,
14,
4547,
360,
344,
297,
2937,
14,
2674,
1062,
7854,
29,
797,
395,
267,
2937,
14,
4547,
360,
8054,
63,
344,
297,
2937,
14,
2674,
1062,
7854,
29,
797,
12,
1478,
29,
549,
395,
267,
2937,
14,
4547,
360,
1205,
297,
1611,
3241,
5081,
8,
10161,
3694,
395,
7854,
29,
797,
395,
267,
2937,
14,
4547,
360,
4606,
297,
2937,
14,
14687,
8,
6833,
29,
24,
12,
4666,
29,
18,
395,
7854,
29,
797,
395,
267,
2937,
14,
4547,
360,
4968,
297,
2937,
14,
1558,
1062,
7854,
29,
797,
395,
267,
2937,
14,
4547,
360,
3780,
297,
2937,
14,
1558,
1062,
7854,
29,
797,
395,
267,
2937,
14,
4547,
360,
3954,
297,
12174,
3926,
12,
7854,
29,
797,
395,
267,
2937,
14,
4547,
360,
576,
297,
25951,
14,
6243,
1062,
7854,
29,
797,
395,
267,
2937,
14,
1799,
8463,
360,
4606,
690,
378,
297,
536,
534,
8965,
63,
4606,
659,
267,
2937,
14,
3190,
8463,
2941,
8054,
63,
344,
995,
788,
1430,
63,
8054,
14,
29440,
14,
344,
3815,
267,
2937,
14,
29457,
8463,
360,
344,
659,
267,
4177,
534,
4368,
7,
272,
776,
272,
1687,
14,
981,
63,
6846,
63,
498,
8,
403,
12,
2079,
283,
29440,
297,
283,
7948,
63,
13754,
297,
2079,
788,
5945,
63,
344,
995,
788,
344,
995,
2079,
1350,
63,
3629,
534,
1430,
63,
8054,
297,
295,
771,
640,
63,
3629,
534,
4368,
358,
421,
199,
318,
32498,
837,
272,
1687,
14,
4824,
63,
5631,
8,
411,
14,
70,
360,
9010,
63,
29440,
63,
5945,
63,
344,
63,
7948,
63,
13754,
659,
283,
29440,
297,
2432,
4177,
534,
1430,
63,
8054,
358,
272,
1687,
14,
4824,
63,
1224,
360,
7948,
63,
13754,
297,
4177,
534,
4368,
358,
272,
1687,
14,
2526,
480,
19350,
31042,
4474,
14,
7948,
63,
13754,
63,
1753,
63,
344,
63,
3610,
820,
11536,
2296,
11628,
63,
13754,
63,
344,
63,
3610,
531,
272,
1687,
14,
2526,
1547,
8165,
63,
5631,
360,
4368,
297,
283,
7948,
63,
13754,
63,
1753,
297,
3303,
283,
2051,
63,
7948,
63,
13754,
63,
1753,
297,
283,
2051,
63,
7948,
63,
13754,
1333,
272,
1687,
14,
8165,
63,
1224,
360,
7948,
63,
13754,
63,
1753,
297,
283,
7948,
63,
13754,
297,
4177,
534,
4368,
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,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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
] |
fzimmermann89/pyload
|
module/plugins/hoster/FastixRu.py
|
1
|
1366
|
# -*- coding: utf-8 -*-
import re
import urllib
from module.plugins.internal.MultiHoster import MultiHoster, create_getInfo
from module.plugins.internal.utils import json
class FastixRu(MultiHoster):
__name__ = "FastixRu"
__type__ = "hoster"
__version__ = "0.17"
__status__ = "testing"
__pattern__ = r'http://(?:www\.)?fastix\.(ru|it)/file/\w{24}'
__config__ = [("activated", "bool", "Activated", True),
("use_premium" , "bool", "Use premium account if available" , True),
("revertfailed", "bool", "Revert to standard download if fails", True)]
__description__ = """Fastix multi-hoster plugin"""
__license__ = "GPLv3"
__authors__ = [("Massimo Rosamilia", "max@spiritix.eu")]
def setup(self):
self.chunk_limit = 3
def handle_premium(self, pyfile):
self.html = self.load("http://fastix.ru/api_v2/",
get={'apikey': self.account.get_data('apikey'),
'sub' : "getdirectlink",
'link' : pyfile.url})
data = json.loads(self.html)
self.log_debug("Json data", data)
if "error\":true" in self.html:
self.offline()
else:
self.link = data['downloadlink']
getInfo = create_getInfo(FastixRu)
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
295,
199,
646,
4011,
199,
199,
504,
859,
14,
5265,
14,
4672,
14,
3947,
40,
29895,
492,
6879,
40,
29895,
12,
1218,
63,
362,
2354,
199,
504,
859,
14,
5265,
14,
4672,
14,
1208,
492,
2022,
421,
199,
533,
22613,
1148,
50,
85,
8,
3947,
40,
29895,
304,
272,
636,
354,
363,
259,
275,
298,
16976,
1148,
50,
85,
2,
272,
636,
466,
363,
259,
275,
298,
526,
11652,
2,
272,
636,
1023,
363,
275,
298,
16,
14,
1196,
2,
272,
636,
1205,
363,
221,
275,
298,
4776,
2,
339,
636,
3401,
363,
275,
519,
7,
1014,
921,
5169,
1544,
20316,
7015,
1148,
4537,
8,
6558,
92,
390,
2447,
493,
6307,
87,
91,
1194,
6834,
272,
636,
888,
363,
221,
275,
10003,
18218,
401,
298,
2245,
401,
298,
13767,
12529,
401,
715,
395,
673,
1689,
1180,
63,
657,
23481,
2,
2360,
298,
2245,
401,
298,
6119,
876,
23481,
2933,
340,
2808,
2,
259,
2360,
715,
395,
673,
1689,
19092,
4892,
401,
298,
2245,
401,
298,
497,
1884,
370,
4465,
5235,
340,
6918,
401,
715,
1874,
339,
636,
1802,
363,
275,
408,
16976,
1148,
3510,
13,
526,
11652,
3589,
624,
272,
636,
1682,
363,
258,
275,
298,
28863,
19,
2,
272,
636,
8149,
363,
258,
275,
10003,
45,
2608,
573,
820,
736,
455,
1638,
65,
401,
298,
988,
32,
8721,
322,
31625,
14,
16913,
11323,
2378,
347,
3272,
8,
277,
304,
267,
291,
14,
4604,
63,
3097,
275,
650,
2378,
347,
2429,
63,
657,
23481,
8,
277,
12,
1134,
493,
304,
267,
291,
14,
1360,
275,
291,
14,
912,
480,
1014,
921,
7015,
1148,
14,
6558,
15,
1246,
63,
86,
18,
10665,
2892,
664,
3713,
28181,
356,
291,
14,
2048,
14,
362,
63,
576,
360,
28181,
659,
3521,
283,
954,
7,
257,
520,
298,
362,
2275,
1073,
401,
3521,
283,
1073,
7,
221,
520,
1134,
493,
14,
633,
1552,
267,
666,
275,
2022,
14,
3640,
8,
277,
14,
1360,
9,
398,
291,
14,
793,
63,
1757,
480,
9653,
666,
401,
666,
9,
398,
340,
298,
705,
19354,
2052,
2,
315,
291,
14,
1360,
26,
288,
291,
14,
18430,
342,
267,
587,
26,
288,
291,
14,
1073,
275,
666,
459,
4249,
1073,
418,
421,
199,
362,
2354,
275,
1218,
63,
362,
2354,
8,
16976,
1148,
50,
85,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
295,
199,
646,
4011,
199,
199,
504,
859,
14,
5265,
14,
4672,
14,
3947,
40,
29895,
492,
6879,
40,
29895,
12,
1218,
63,
362,
2354,
199,
504,
859,
14,
5265,
14,
4672,
14,
1208,
492,
2022,
421,
199,
533,
22613,
1148,
50,
85,
8,
3947,
40,
29895,
304,
272,
636,
354,
363,
259,
275,
298,
16976,
1148,
50,
85,
2,
272,
636,
466,
363,
259,
275,
298,
526,
11652,
2,
272,
636,
1023,
363,
275,
298,
16,
14,
1196,
2,
272,
636,
1205,
363,
221,
275,
298,
4776,
2,
339,
636,
3401,
363,
275,
519,
7,
1014,
921,
5169,
1544,
20316,
7015,
1148,
4537,
8,
6558,
92,
390,
2447,
493,
6307,
87,
91,
1194,
6834,
272,
636,
888,
363,
221,
275,
10003,
18218,
401,
298,
2245,
401,
298,
13767,
12529,
401,
715,
395,
673,
1689,
1180,
63,
657,
23481,
2,
2360,
298,
2245,
401,
298,
6119,
876,
23481,
2933,
340,
2808,
2,
259,
2360,
715,
395,
673,
1689,
19092,
4892,
401,
298,
2245,
401,
298,
497,
1884,
370,
4465,
5235,
340,
6918,
401,
715,
1874,
339,
636,
1802,
363,
275,
408,
16976,
1148,
3510,
13,
526,
11652,
3589,
624,
272,
636,
1682,
363,
258,
275,
298,
28863,
19,
2,
272,
636,
8149,
363,
258,
275,
10003,
45,
2608,
573,
820,
736,
455,
1638,
65,
401,
298,
988,
32,
8721,
322,
31625,
14,
16913,
11323,
2378,
347,
3272,
8,
277,
304,
267,
291,
14,
4604,
63,
3097,
275,
650,
2378,
347,
2429,
63,
657,
23481,
8,
277,
12,
1134,
493,
304,
267,
291,
14,
1360,
275,
291,
14,
912,
480,
1014,
921,
7015,
1148,
14,
6558,
15,
1246,
63,
86,
18,
10665,
2892,
664,
3713,
28181,
356,
291,
14,
2048,
14,
362,
63,
576,
360,
28181,
659,
3521,
283,
954,
7,
257,
520,
298,
362,
2275,
1073,
401,
3521,
283,
1073,
7,
221,
520,
1134,
493,
14,
633,
1552,
267,
666,
275,
2022,
14,
3640,
8,
277,
14,
1360,
9,
398,
291,
14,
793,
63,
1757,
480,
9653,
666,
401,
666,
9,
398,
340,
298,
705,
19354,
2052,
2,
315,
291,
14,
1360,
26,
288,
291,
14,
18430,
342,
267,
587,
26,
288,
291,
14,
1073,
275,
666,
459,
4249,
1073,
418,
421,
199,
362,
2354,
275,
1218,
63,
362,
2354,
8,
16976,
1148,
50,
85,
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,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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
] |
Purg/kwiver
|
vital/bindings/python/vital/types/landmark_map.py
|
1
|
4829
|
"""
ckwg +31
Copyright 2016 by Kitware, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither name of Kitware, Inc. nor the names of any contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
==============================================================================
vital::landmark_map interface
"""
import ctypes
from vital.types import Landmark
from vital.util import VitalObject, free_void_ptr
class LandmarkMap (VitalObject):
@classmethod
def from_dict(cls, id_lm_d):
"""
Create a new instance of LandmarkMap using the given dictionary mapping
integer IDs to Landmark instances.
:param id_lm_d: dictionary mapping integer IDs to Landmark instances
:type id_lm_d: dict[int|long, vital.types.Landmark]
:return: New landmark map instance containing a copy of the input map.
:rtype: LandmarkMap
"""
s = len(id_lm_d)
t_lm_ids = (ctypes.c_int64 * s)
t_lm_landmarks = (Landmark.c_ptr_type() * s)
lm_ids = t_lm_ids()
lm_landmarks = t_lm_landmarks()
i = 0
for k, l in id_lm_d.iteritems():
lm_ids[i] = k
lm_landmarks[i] = l.c_pointer
i += 1
lm_cptr = cls._call_cfunc(
'vital_landmark_map_new',
[t_lm_landmarks, t_lm_ids, ctypes.c_size_t],
[lm_landmarks, lm_ids, s],
cls.c_ptr_type()
)
return cls(lm_cptr)
def __init__(self, from_cptr=None):
"""
Create and empty map, or initialize from and existing C instance pointer
:param from_cptr: Optional existing landmark map C pointer
"""
super(LandmarkMap, self).__init__(from_cptr)
def _new(self):
return self._call_cfunc(
'vital_landmark_map_new_empty',
restype=self.C_TYPE_PTR
)
def _destroy(self):
self._call_cfunc(
'vital_landmark_map_destroy', [self.C_TYPE_PTR], [self]
)
def __eq__(self, other):
return (
isinstance(other, LandmarkMap) and
self.as_dict() == other.as_dict()
)
def __ne__(self, other):
return not (self == other)
def __len__(self):
return self.size
@property
def size(self):
"""
Get the size of this map
:return: the size of this map
:rtype: int
"""
return self._call_cfunc(
'vital_landmark_map_size',
[self.C_TYPE_PTR], [self],
ctypes.c_size_t
)
def as_dict(self):
"""
Get a copy of this map as a python dictionary
:return: Dictionary mapping landmark IDs to Landmark instances
:rtype: dict[int|long, vital.types.Landmark]
"""
t_lm_ids = ctypes.POINTER(ctypes.c_int64)
t_lm_landmarks = ctypes.POINTER(Landmark.c_ptr_type())
lm_ids = t_lm_ids()
lm_landmarks = t_lm_landmarks()
self._call_cfunc(
'vital_landmark_map_landmarks',
[self.C_TYPE_PTR, ctypes.POINTER(t_lm_ids), ctypes.POINTER(t_lm_landmarks)],
[self, ctypes.byref(lm_ids), ctypes.byref(lm_landmarks)]
)
d = {}
s = self.size
for i in xrange(s):
# Need to copy ctypes pointer object
l_cptr = Landmark.c_ptr_type()(lm_landmarks[i].contents)
d[lm_ids[i]] = Landmark(from_cptr=l_cptr)
free_void_ptr(lm_ids)
free_void_ptr(lm_landmarks)
return d
|
bsd-3-clause
|
[
624,
199,
346,
23596,
435,
2192,
199,
7384,
7800,
701,
1804,
390,
1068,
12,
3277,
14,
199,
2422,
4481,
4644,
14,
199,
199,
497,
4972,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
20945,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
421,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
2043,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
421,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
2043,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
2043,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
421,
627,
11443,
536,
402,
1804,
390,
1068,
12,
3277,
14,
6590,
314,
1561,
402,
1263,
8417,
1443,
506,
1202,
2043,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
1928,
2488,
2043,
6791,
5313,
4983,
14,
199,
199,
24571,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
1124,
1179,
2281,
891,
199,
3649,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
8947,
5177,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
8693,
9706,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
6483,
6262,
7024,
2381,
199,
8974,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
199,
36,
1156,
5383,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
199,
3279,
8670,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3263,
8558,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
199,
726,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3359,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
5695,
17224,
199,
199,
86,
6910,
447,
9688,
1657,
63,
1130,
3217,
199,
199,
624,
199,
646,
5577,
199,
199,
504,
373,
6910,
14,
1313,
492,
491,
460,
1657,
199,
504,
373,
6910,
14,
1974,
492,
812,
6910,
1692,
12,
2867,
63,
1647,
63,
4695,
421,
199,
533,
491,
460,
1657,
2956,
334,
54,
6910,
1692,
304,
339,
768,
3744,
272,
347,
687,
63,
807,
8,
1886,
12,
1305,
63,
14344,
63,
68,
304,
267,
408,
267,
2790,
282,
892,
1256,
402,
491,
460,
1657,
2956,
1808,
314,
1627,
2600,
4412,
267,
3000,
11449,
370,
491,
460,
1657,
4454,
14,
398,
520,
635,
1305,
63,
14344,
63,
68,
26,
2600,
4412,
3000,
11449,
370,
491,
460,
1657,
4454,
267,
520,
466,
1305,
63,
14344,
63,
68,
26,
1211,
59,
442,
92,
2809,
12,
373,
6910,
14,
1313,
14,
44,
460,
1657,
61,
398,
520,
1107,
26,
7053,
20078,
1657,
2341,
1256,
3035,
282,
1331,
402,
314,
1324,
2341,
14,
267,
520,
4500,
26,
491,
460,
1657,
2956,
398,
408,
267,
308,
275,
822,
8,
344,
63,
14344,
63,
68,
9,
267,
307,
63,
14344,
63,
1580,
275,
334,
9798,
14,
67,
63,
442,
772,
627,
308,
9,
267,
307,
63,
14344,
63,
9688,
10375,
275,
334,
44,
460,
1657,
14,
67,
63,
4695,
63,
466,
342,
627,
308,
9,
398,
24546,
63,
1580,
275,
307,
63,
14344,
63,
1580,
342,
267,
24546,
63,
9688,
10375,
275,
307,
63,
14344,
63,
9688,
10375,
342,
267,
284,
275,
378,
267,
367,
1022,
12,
634,
315,
1305,
63,
14344,
63,
68,
14,
4611,
837,
288,
24546,
63,
1580,
59,
73,
61,
275,
1022,
288,
24546,
63,
9688,
10375,
59,
73,
61,
275,
634,
14,
67,
63,
3929,
288,
284,
847,
413,
398,
24546,
63,
1850,
454,
275,
843,
423,
1250,
63,
67,
1532,
8,
288,
283,
86,
6910,
63,
9688,
1657,
63,
1130,
63,
1222,
297,
288,
359,
84,
63,
14344,
63,
9688,
10375,
12,
307,
63,
14344,
63,
1580,
12,
5577,
14,
67,
63,
890,
63,
84,
467,
288,
359,
14344,
63,
9688,
10375,
12,
24546,
63,
1580,
12,
308,
467,
288,
843,
14,
67,
63,
4695,
63,
466,
342,
267,
776,
267,
372,
843,
8,
14344,
63,
1850,
454,
9,
339,
347,
636,
826,
721,
277,
12,
687,
63,
1850,
454,
29,
403,
304,
267,
408,
267,
2790,
436,
2701,
2341,
12,
503,
8265,
687,
436,
3411,
445,
1256,
7849,
267,
520,
635,
687,
63,
1850,
454,
26,
4879,
3411,
20078,
1657,
2341,
445,
7849,
267,
408,
267,
1613,
8,
44,
460,
1657,
2956,
12,
291,
2843,
826,
721,
504,
63,
1850,
454,
9,
339,
347,
485,
1222,
8,
277,
304,
267,
372,
291,
423,
1250,
63,
67,
1532,
8,
288,
283,
86,
6910,
63,
9688,
1657,
63,
1130,
63,
1222,
63,
1667,
297,
288,
4618,
514,
29,
277,
14,
35,
63,
2711,
63,
14528,
267,
776,
339,
347,
485,
7237,
8,
277,
304,
267,
291,
423,
1250,
63,
67,
1532,
8,
288,
283,
86,
6910,
63,
9688,
1657,
63,
1130,
63,
7237,
297,
359,
277,
14,
35,
63,
2711,
63,
14528,
467,
359,
277,
61,
267,
776,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
334,
288,
1228,
8,
1848,
12,
491,
460,
1657,
2956,
9,
436,
288,
291,
14,
305,
63,
807,
342,
508,
1163,
14,
305,
63,
807,
342,
267,
776,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
334,
277,
508,
1163,
9,
339,
347,
636,
552,
721,
277,
304,
267,
372,
291,
14,
890,
339,
768,
1829,
272,
347,
1568,
8,
277,
304,
267,
408,
267,
2372,
314,
1568,
402,
642,
2341,
398,
520,
1107,
26,
314,
1568,
402,
642,
2341,
267,
520,
4500,
26,
1109,
398,
408,
267,
372,
291,
423,
1250,
63,
67,
1532,
8,
288,
283,
86,
6910,
63,
9688,
1657,
63,
1130,
63,
890,
297,
288,
359,
277,
14,
35,
63,
2711,
63,
14528,
467,
359,
277,
467,
288,
5577,
14,
67,
63,
890,
63,
84,
267,
776,
339,
347,
465,
63,
807,
8,
277,
304,
267,
408,
267,
2372,
282,
1331,
402,
642,
2341,
465,
282,
2366,
2600,
398,
520,
1107,
26,
11932,
4412,
20078,
1657,
11449,
370,
491,
460,
1657,
4454,
267,
520,
4500,
26,
1211,
59,
442,
92,
2809,
12,
373,
6910,
14,
1313,
14,
44,
460,
1657,
61,
398,
408,
398
] |
[
199,
346,
23596,
435,
2192,
199,
7384,
7800,
701,
1804,
390,
1068,
12,
3277,
14,
199,
2422,
4481,
4644,
14,
199,
199,
497,
4972,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
20945,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
421,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
2043,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
421,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
2043,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
2043,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
421,
627,
11443,
536,
402,
1804,
390,
1068,
12,
3277,
14,
6590,
314,
1561,
402,
1263,
8417,
1443,
506,
1202,
2043,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
1928,
2488,
2043,
6791,
5313,
4983,
14,
199,
199,
24571,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
1124,
1179,
2281,
891,
199,
3649,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
8947,
5177,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
8693,
9706,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
6483,
6262,
7024,
2381,
199,
8974,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
199,
36,
1156,
5383,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
199,
3279,
8670,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3263,
8558,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
199,
726,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3359,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
5695,
17224,
199,
199,
86,
6910,
447,
9688,
1657,
63,
1130,
3217,
199,
199,
624,
199,
646,
5577,
199,
199,
504,
373,
6910,
14,
1313,
492,
491,
460,
1657,
199,
504,
373,
6910,
14,
1974,
492,
812,
6910,
1692,
12,
2867,
63,
1647,
63,
4695,
421,
199,
533,
491,
460,
1657,
2956,
334,
54,
6910,
1692,
304,
339,
768,
3744,
272,
347,
687,
63,
807,
8,
1886,
12,
1305,
63,
14344,
63,
68,
304,
267,
408,
267,
2790,
282,
892,
1256,
402,
491,
460,
1657,
2956,
1808,
314,
1627,
2600,
4412,
267,
3000,
11449,
370,
491,
460,
1657,
4454,
14,
398,
520,
635,
1305,
63,
14344,
63,
68,
26,
2600,
4412,
3000,
11449,
370,
491,
460,
1657,
4454,
267,
520,
466,
1305,
63,
14344,
63,
68,
26,
1211,
59,
442,
92,
2809,
12,
373,
6910,
14,
1313,
14,
44,
460,
1657,
61,
398,
520,
1107,
26,
7053,
20078,
1657,
2341,
1256,
3035,
282,
1331,
402,
314,
1324,
2341,
14,
267,
520,
4500,
26,
491,
460,
1657,
2956,
398,
408,
267,
308,
275,
822,
8,
344,
63,
14344,
63,
68,
9,
267,
307,
63,
14344,
63,
1580,
275,
334,
9798,
14,
67,
63,
442,
772,
627,
308,
9,
267,
307,
63,
14344,
63,
9688,
10375,
275,
334,
44,
460,
1657,
14,
67,
63,
4695,
63,
466,
342,
627,
308,
9,
398,
24546,
63,
1580,
275,
307,
63,
14344,
63,
1580,
342,
267,
24546,
63,
9688,
10375,
275,
307,
63,
14344,
63,
9688,
10375,
342,
267,
284,
275,
378,
267,
367,
1022,
12,
634,
315,
1305,
63,
14344,
63,
68,
14,
4611,
837,
288,
24546,
63,
1580,
59,
73,
61,
275,
1022,
288,
24546,
63,
9688,
10375,
59,
73,
61,
275,
634,
14,
67,
63,
3929,
288,
284,
847,
413,
398,
24546,
63,
1850,
454,
275,
843,
423,
1250,
63,
67,
1532,
8,
288,
283,
86,
6910,
63,
9688,
1657,
63,
1130,
63,
1222,
297,
288,
359,
84,
63,
14344,
63,
9688,
10375,
12,
307,
63,
14344,
63,
1580,
12,
5577,
14,
67,
63,
890,
63,
84,
467,
288,
359,
14344,
63,
9688,
10375,
12,
24546,
63,
1580,
12,
308,
467,
288,
843,
14,
67,
63,
4695,
63,
466,
342,
267,
776,
267,
372,
843,
8,
14344,
63,
1850,
454,
9,
339,
347,
636,
826,
721,
277,
12,
687,
63,
1850,
454,
29,
403,
304,
267,
408,
267,
2790,
436,
2701,
2341,
12,
503,
8265,
687,
436,
3411,
445,
1256,
7849,
267,
520,
635,
687,
63,
1850,
454,
26,
4879,
3411,
20078,
1657,
2341,
445,
7849,
267,
408,
267,
1613,
8,
44,
460,
1657,
2956,
12,
291,
2843,
826,
721,
504,
63,
1850,
454,
9,
339,
347,
485,
1222,
8,
277,
304,
267,
372,
291,
423,
1250,
63,
67,
1532,
8,
288,
283,
86,
6910,
63,
9688,
1657,
63,
1130,
63,
1222,
63,
1667,
297,
288,
4618,
514,
29,
277,
14,
35,
63,
2711,
63,
14528,
267,
776,
339,
347,
485,
7237,
8,
277,
304,
267,
291,
423,
1250,
63,
67,
1532,
8,
288,
283,
86,
6910,
63,
9688,
1657,
63,
1130,
63,
7237,
297,
359,
277,
14,
35,
63,
2711,
63,
14528,
467,
359,
277,
61,
267,
776,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
334,
288,
1228,
8,
1848,
12,
491,
460,
1657,
2956,
9,
436,
288,
291,
14,
305,
63,
807,
342,
508,
1163,
14,
305,
63,
807,
342,
267,
776,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
334,
277,
508,
1163,
9,
339,
347,
636,
552,
721,
277,
304,
267,
372,
291,
14,
890,
339,
768,
1829,
272,
347,
1568,
8,
277,
304,
267,
408,
267,
2372,
314,
1568,
402,
642,
2341,
398,
520,
1107,
26,
314,
1568,
402,
642,
2341,
267,
520,
4500,
26,
1109,
398,
408,
267,
372,
291,
423,
1250,
63,
67,
1532,
8,
288,
283,
86,
6910,
63,
9688,
1657,
63,
1130,
63,
890,
297,
288,
359,
277,
14,
35,
63,
2711,
63,
14528,
467,
359,
277,
467,
288,
5577,
14,
67,
63,
890,
63,
84,
267,
776,
339,
347,
465,
63,
807,
8,
277,
304,
267,
408,
267,
2372,
282,
1331,
402,
642,
2341,
465,
282,
2366,
2600,
398,
520,
1107,
26,
11932,
4412,
20078,
1657,
11449,
370,
491,
460,
1657,
4454,
267,
520,
4500,
26,
1211,
59,
442,
92,
2809,
12,
373,
6910,
14,
1313,
14,
44,
460,
1657,
61,
398,
408,
398,
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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8 -*-
#
# Copyright (c) 2011-2015 Slack
#
# 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.
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
7760,
13,
7806,
428,
5143,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
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,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
7760,
13,
7806,
428,
5143,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
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,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
Linusp/shadowsocks
|
shadowsocks/shell.py
|
652
|
12736
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright 2015 clowwindy
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import absolute_import, division, print_function, \
with_statement
import os
import json
import sys
import getopt
import logging
from shadowsocks.common import to_bytes, to_str, IPNetwork
from shadowsocks import encrypt
VERBOSE_LEVEL = 5
verbose = 0
def check_python():
info = sys.version_info
if info[0] == 2 and not info[1] >= 6:
print('Python 2.6+ required')
sys.exit(1)
elif info[0] == 3 and not info[1] >= 3:
print('Python 3.3+ required')
sys.exit(1)
elif info[0] not in [2, 3]:
print('Python version not supported')
sys.exit(1)
def print_exception(e):
global verbose
logging.error(e)
if verbose > 0:
import traceback
traceback.print_exc()
def print_shadowsocks():
version = ''
try:
import pkg_resources
version = pkg_resources.get_distribution('shadowsocks').version
except Exception:
pass
print('Shadowsocks %s' % version)
def find_config():
config_path = 'config.json'
if os.path.exists(config_path):
return config_path
config_path = os.path.join(os.path.dirname(__file__), '../', 'config.json')
if os.path.exists(config_path):
return config_path
return None
def check_config(config, is_local):
if config.get('daemon', None) == 'stop':
# no need to specify configuration for daemon stop
return
if is_local and not config.get('password', None):
logging.error('password not specified')
print_help(is_local)
sys.exit(2)
if not is_local and not config.get('password', None) \
and not config.get('port_password', None) \
and not config.get('manager_address'):
logging.error('password or port_password not specified')
print_help(is_local)
sys.exit(2)
if 'local_port' in config:
config['local_port'] = int(config['local_port'])
if config.get('server_port', None) and type(config['server_port']) != list:
config['server_port'] = int(config['server_port'])
if config.get('local_address', '') in [b'0.0.0.0']:
logging.warn('warning: local set to listen on 0.0.0.0, it\'s not safe')
if config.get('server', '') in ['127.0.0.1', 'localhost']:
logging.warn('warning: server set to listen on %s:%s, are you sure?' %
(to_str(config['server']), config['server_port']))
if (config.get('method', '') or '').lower() == 'table':
logging.warn('warning: table is not safe; please use a safer cipher, '
'like AES-256-CFB')
if (config.get('method', '') or '').lower() == 'rc4':
logging.warn('warning: RC4 is not safe; please use a safer cipher, '
'like AES-256-CFB')
if config.get('timeout', 300) < 100:
logging.warn('warning: your timeout %d seems too short' %
int(config.get('timeout')))
if config.get('timeout', 300) > 600:
logging.warn('warning: your timeout %d seems too long' %
int(config.get('timeout')))
if config.get('password') in [b'mypassword']:
logging.error('DON\'T USE DEFAULT PASSWORD! Please change it in your '
'config.json!')
sys.exit(1)
if config.get('user', None) is not None:
if os.name != 'posix':
logging.error('user can be used only on Unix')
sys.exit(1)
encrypt.try_cipher(config['password'], config['method'])
def get_config(is_local):
global verbose
logging.basicConfig(level=logging.INFO,
format='%(levelname)-s: %(message)s')
if is_local:
shortopts = 'hd:s:b:p:k:l:m:c:t:vq'
longopts = ['help', 'fast-open', 'pid-file=', 'log-file=', 'user=',
'version']
else:
shortopts = 'hd:s:p:k:m:c:t:vq'
longopts = ['help', 'fast-open', 'pid-file=', 'log-file=', 'workers=',
'forbidden-ip=', 'user=', 'manager-address=', 'version']
try:
config_path = find_config()
optlist, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
for key, value in optlist:
if key == '-c':
config_path = value
if config_path:
logging.info('loading config from %s' % config_path)
with open(config_path, 'rb') as f:
try:
config = parse_json_in_str(f.read().decode('utf8'))
except ValueError as e:
logging.error('found an error in config.json: %s',
e.message)
sys.exit(1)
else:
config = {}
v_count = 0
for key, value in optlist:
if key == '-p':
config['server_port'] = int(value)
elif key == '-k':
config['password'] = to_bytes(value)
elif key == '-l':
config['local_port'] = int(value)
elif key == '-s':
config['server'] = to_str(value)
elif key == '-m':
config['method'] = to_str(value)
elif key == '-b':
config['local_address'] = to_str(value)
elif key == '-v':
v_count += 1
# '-vv' turns on more verbose mode
config['verbose'] = v_count
elif key == '-t':
config['timeout'] = int(value)
elif key == '--fast-open':
config['fast_open'] = True
elif key == '--workers':
config['workers'] = int(value)
elif key == '--manager-address':
config['manager_address'] = value
elif key == '--user':
config['user'] = to_str(value)
elif key == '--forbidden-ip':
config['forbidden_ip'] = to_str(value).split(',')
elif key in ('-h', '--help'):
if is_local:
print_local_help()
else:
print_server_help()
sys.exit(0)
elif key == '--version':
print_shadowsocks()
sys.exit(0)
elif key == '-d':
config['daemon'] = to_str(value)
elif key == '--pid-file':
config['pid-file'] = to_str(value)
elif key == '--log-file':
config['log-file'] = to_str(value)
elif key == '-q':
v_count -= 1
config['verbose'] = v_count
except getopt.GetoptError as e:
print(e, file=sys.stderr)
print_help(is_local)
sys.exit(2)
if not config:
logging.error('config not specified')
print_help(is_local)
sys.exit(2)
config['password'] = to_bytes(config.get('password', b''))
config['method'] = to_str(config.get('method', 'aes-256-cfb'))
config['port_password'] = config.get('port_password', None)
config['timeout'] = int(config.get('timeout', 300))
config['fast_open'] = config.get('fast_open', False)
config['workers'] = config.get('workers', 1)
config['pid-file'] = config.get('pid-file', '/var/run/shadowsocks.pid')
config['log-file'] = config.get('log-file', '/var/log/shadowsocks.log')
config['verbose'] = config.get('verbose', False)
config['local_address'] = to_str(config.get('local_address', '127.0.0.1'))
config['local_port'] = config.get('local_port', 1080)
if is_local:
if config.get('server', None) is None:
logging.error('server addr not specified')
print_local_help()
sys.exit(2)
else:
config['server'] = to_str(config['server'])
else:
config['server'] = to_str(config.get('server', '0.0.0.0'))
try:
config['forbidden_ip'] = \
IPNetwork(config.get('forbidden_ip', '127.0.0.0/8,::1/128'))
except Exception as e:
logging.error(e)
sys.exit(2)
config['server_port'] = config.get('server_port', None)
logging.getLogger('').handlers = []
logging.addLevelName(VERBOSE_LEVEL, 'VERBOSE')
if config['verbose'] >= 2:
level = VERBOSE_LEVEL
elif config['verbose'] == 1:
level = logging.DEBUG
elif config['verbose'] == -1:
level = logging.WARN
elif config['verbose'] <= -2:
level = logging.ERROR
else:
level = logging.INFO
verbose = config['verbose']
logging.basicConfig(level=level,
format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
check_config(config, is_local)
return config
def print_help(is_local):
if is_local:
print_local_help()
else:
print_server_help()
def print_local_help():
print('''usage: sslocal [OPTION]...
A fast tunnel proxy that helps you bypass firewalls.
You can supply configurations via either config file or command line arguments.
Proxy options:
-c CONFIG path to config file
-s SERVER_ADDR server address
-p SERVER_PORT server port, default: 8388
-b LOCAL_ADDR local binding address, default: 127.0.0.1
-l LOCAL_PORT local port, default: 1080
-k PASSWORD password
-m METHOD encryption method, default: aes-256-cfb
-t TIMEOUT timeout in seconds, default: 300
--fast-open use TCP_FASTOPEN, requires Linux 3.7+
General options:
-h, --help show this help message and exit
-d start/stop/restart daemon mode
--pid-file PID_FILE pid file for daemon mode
--log-file LOG_FILE log file for daemon mode
--user USER username to run as
-v, -vv verbose mode
-q, -qq quiet mode, only show warnings/errors
--version show version information
Online help: <https://github.com/shadowsocks/shadowsocks>
''')
def print_server_help():
print('''usage: ssserver [OPTION]...
A fast tunnel proxy that helps you bypass firewalls.
You can supply configurations via either config file or command line arguments.
Proxy options:
-c CONFIG path to config file
-s SERVER_ADDR server address, default: 0.0.0.0
-p SERVER_PORT server port, default: 8388
-k PASSWORD password
-m METHOD encryption method, default: aes-256-cfb
-t TIMEOUT timeout in seconds, default: 300
--fast-open use TCP_FASTOPEN, requires Linux 3.7+
--workers WORKERS number of workers, available on Unix/Linux
--forbidden-ip IPLIST comma seperated IP list forbidden to connect
--manager-address ADDR optional server manager UDP address, see wiki
General options:
-h, --help show this help message and exit
-d start/stop/restart daemon mode
--pid-file PID_FILE pid file for daemon mode
--log-file LOG_FILE log file for daemon mode
--user USER username to run as
-v, -vv verbose mode
-q, -qq quiet mode, only show warnings/errors
--version show version information
Online help: <https://github.com/shadowsocks/shadowsocks>
''')
def _decode_list(data):
rv = []
for item in data:
if hasattr(item, 'encode'):
item = item.encode('utf-8')
elif isinstance(item, list):
item = _decode_list(item)
elif isinstance(item, dict):
item = _decode_dict(item)
rv.append(item)
return rv
def _decode_dict(data):
rv = {}
for key, value in data.items():
if hasattr(value, 'encode'):
value = value.encode('utf-8')
elif isinstance(value, list):
value = _decode_list(value)
elif isinstance(value, dict):
value = _decode_dict(value)
rv[key] = value
return rv
def parse_json_in_str(data):
# parse json and convert everything from unicode to str
return json.loads(data, object_hook=_decode_dict)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
6900,
286,
674,
11530,
89,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
971,
272,
543,
63,
6242,
199,
199,
646,
747,
199,
646,
2022,
199,
646,
984,
199,
646,
12733,
199,
646,
2050,
199,
504,
15084,
21234,
14,
2330,
492,
370,
63,
2394,
12,
370,
63,
495,
12,
3531,
4491,
199,
504,
15084,
21234,
492,
14645,
421,
199,
16075,
63,
11817,
275,
959,
199,
199,
3832,
275,
378,
421,
199,
318,
1104,
63,
1548,
837,
272,
2256,
275,
984,
14,
1023,
63,
815,
272,
340,
2256,
59,
16,
61,
508,
499,
436,
440,
2256,
59,
17,
61,
2356,
1227,
26,
267,
870,
360,
4718,
499,
14,
22,
11,
1415,
358,
267,
984,
14,
2224,
8,
17,
9,
272,
916,
2256,
59,
16,
61,
508,
650,
436,
440,
2256,
59,
17,
61,
2356,
650,
26,
267,
870,
360,
4718,
650,
14,
19,
11,
1415,
358,
267,
984,
14,
2224,
8,
17,
9,
272,
916,
2256,
59,
16,
61,
440,
315,
359,
18,
12,
650,
2189,
267,
870,
360,
4718,
1015,
440,
3748,
358,
267,
984,
14,
2224,
8,
17,
9,
421,
199,
318,
870,
63,
1971,
8,
69,
304,
272,
2288,
3376,
272,
2050,
14,
705,
8,
69,
9,
272,
340,
3376,
690,
378,
26,
267,
492,
5190,
267,
5190,
14,
1361,
63,
2804,
342,
421,
199,
318,
870,
63,
14714,
21234,
837,
272,
1015,
275,
2125,
272,
862,
26,
267,
492,
5496,
63,
4435,
267,
1015,
275,
5496,
63,
4435,
14,
362,
63,
4972,
360,
14714,
21234,
1959,
1023,
272,
871,
2186,
26,
267,
986,
272,
870,
360,
23574,
21234,
450,
83,
7,
450,
1015,
9,
421,
199,
318,
2342,
63,
888,
837,
272,
1101,
63,
515,
275,
283,
888,
14,
1001,
7,
272,
340,
747,
14,
515,
14,
2444,
8,
888,
63,
515,
304,
267,
372,
1101,
63,
515,
272,
1101,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
11541,
3678,
283,
888,
14,
1001,
358,
272,
340,
747,
14,
515,
14,
2444,
8,
888,
63,
515,
304,
267,
372,
1101,
63,
515,
272,
372,
488,
421,
199,
318,
1104,
63,
888,
8,
888,
12,
365,
63,
1832,
304,
272,
340,
1101,
14,
362,
360,
10824,
297,
488,
9,
508,
283,
2379,
356,
267,
327,
949,
1929,
370,
4165,
2897,
367,
11128,
3631,
267,
372,
339,
340,
365,
63,
1832,
436,
440,
1101,
14,
362,
360,
2060,
297,
488,
304,
267,
2050,
14,
705,
360,
2060,
440,
2013,
358,
267,
870,
63,
3437,
8,
374,
63,
1832,
9,
267,
984,
14,
2224,
8,
18,
9,
339,
340,
440,
365,
63,
1832,
436,
440,
1101,
14,
362,
360,
2060,
297,
488,
9,
971,
288,
436,
440,
1101,
14,
362,
360,
719,
63,
2060,
297,
488,
9,
971,
288,
436,
440,
1101,
14,
362,
360,
2609,
63,
1562,
735,
267,
2050,
14,
705,
360,
2060,
503,
1844,
63,
2060,
440,
2013,
358,
267,
870,
63,
3437,
8,
374,
63,
1832,
9,
267,
984,
14,
2224,
8,
18,
9,
339,
340,
283,
1832,
63,
719,
7,
315,
1101,
26,
267,
1101,
459,
1832,
63,
719,
418,
275,
1109,
8,
888,
459,
1832,
63,
719,
1105,
339,
340,
1101,
14,
362,
360,
1000,
63,
719,
297,
488,
9,
436,
730,
8,
888,
459,
1000,
63,
719,
1105,
1137,
769,
26,
267,
1101,
459,
1000,
63,
719,
418,
275,
1109,
8,
888,
459,
1000,
63,
719,
1105,
339,
340,
1101,
14,
362,
360,
1832,
63,
1562,
297,
4074,
315,
359,
66,
7,
16,
14,
16,
14,
16,
14,
16,
2565,
267,
2050,
14,
4050,
360,
3764,
26,
2257,
663,
370,
6938,
641,
378,
14,
16,
14,
16,
14,
16,
12,
652,
3985,
83,
440,
5048,
358,
272,
340,
1101,
14,
362,
360,
1000,
297,
4074,
315,
788,
4195,
14,
16,
14,
16,
14,
17,
297,
283,
5967,
2565,
267,
2050,
14,
4050,
360,
3764,
26,
1654,
663,
370,
6938,
641,
450,
83,
2689,
83,
12,
787,
1265,
3238,
14069,
450,
2151,
334,
475,
63,
495,
8,
888,
459,
1000,
3815,
1101,
459,
1000,
63,
719,
5156,
272,
340,
334,
888,
14,
362,
360,
765,
297,
4074,
503,
12548,
2325,
342,
508,
283,
1224,
356,
267,
2050,
14,
4050,
360,
3764,
26,
1817,
365,
440,
5048,
27,
8749,
675,
282,
2937,
2412,
10830,
12,
283,
2151,
283,
2930,
19093,
13,
3912,
13,
5487,
34,
358,
272,
340,
334,
888,
14,
362,
360,
765,
297,
4074,
503,
12548,
2325,
342,
508,
283,
1195,
20,
356,
267,
2050,
14,
4050,
360,
3764,
26,
29256,
20,
365,
440,
5048,
27,
8749,
675,
282,
2937,
2412,
10830,
12,
283,
2151,
283,
2930,
19093,
13,
3912,
13,
5487,
34,
358,
272,
340,
1101,
14,
362,
360,
2593,
297,
9601,
9,
665,
2948,
26,
267,
2050,
14,
4050,
360,
3764,
26,
2195,
2653,
450,
68,
12237,
4634,
3974,
7,
450,
2151,
1109,
8,
888,
14,
362,
360,
2593,
7058,
272,
340,
1101,
14,
362,
360,
2593,
297,
9601,
9,
690,
11624,
26,
267,
2050,
14,
4050,
360,
3764,
26,
2195,
2653,
450,
68,
12237,
4634,
1846,
7,
450,
2151,
1109,
8,
888,
14,
362,
360,
2593,
7058,
272,
340,
1101,
14,
362,
360,
2060,
358,
315,
359,
66,
6704,
89,
2060,
2565,
267,
2050,
14
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
6900,
286,
674,
11530,
89,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
971,
272,
543,
63,
6242,
199,
199,
646,
747,
199,
646,
2022,
199,
646,
984,
199,
646,
12733,
199,
646,
2050,
199,
504,
15084,
21234,
14,
2330,
492,
370,
63,
2394,
12,
370,
63,
495,
12,
3531,
4491,
199,
504,
15084,
21234,
492,
14645,
421,
199,
16075,
63,
11817,
275,
959,
199,
199,
3832,
275,
378,
421,
199,
318,
1104,
63,
1548,
837,
272,
2256,
275,
984,
14,
1023,
63,
815,
272,
340,
2256,
59,
16,
61,
508,
499,
436,
440,
2256,
59,
17,
61,
2356,
1227,
26,
267,
870,
360,
4718,
499,
14,
22,
11,
1415,
358,
267,
984,
14,
2224,
8,
17,
9,
272,
916,
2256,
59,
16,
61,
508,
650,
436,
440,
2256,
59,
17,
61,
2356,
650,
26,
267,
870,
360,
4718,
650,
14,
19,
11,
1415,
358,
267,
984,
14,
2224,
8,
17,
9,
272,
916,
2256,
59,
16,
61,
440,
315,
359,
18,
12,
650,
2189,
267,
870,
360,
4718,
1015,
440,
3748,
358,
267,
984,
14,
2224,
8,
17,
9,
421,
199,
318,
870,
63,
1971,
8,
69,
304,
272,
2288,
3376,
272,
2050,
14,
705,
8,
69,
9,
272,
340,
3376,
690,
378,
26,
267,
492,
5190,
267,
5190,
14,
1361,
63,
2804,
342,
421,
199,
318,
870,
63,
14714,
21234,
837,
272,
1015,
275,
2125,
272,
862,
26,
267,
492,
5496,
63,
4435,
267,
1015,
275,
5496,
63,
4435,
14,
362,
63,
4972,
360,
14714,
21234,
1959,
1023,
272,
871,
2186,
26,
267,
986,
272,
870,
360,
23574,
21234,
450,
83,
7,
450,
1015,
9,
421,
199,
318,
2342,
63,
888,
837,
272,
1101,
63,
515,
275,
283,
888,
14,
1001,
7,
272,
340,
747,
14,
515,
14,
2444,
8,
888,
63,
515,
304,
267,
372,
1101,
63,
515,
272,
1101,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
11541,
3678,
283,
888,
14,
1001,
358,
272,
340,
747,
14,
515,
14,
2444,
8,
888,
63,
515,
304,
267,
372,
1101,
63,
515,
272,
372,
488,
421,
199,
318,
1104,
63,
888,
8,
888,
12,
365,
63,
1832,
304,
272,
340,
1101,
14,
362,
360,
10824,
297,
488,
9,
508,
283,
2379,
356,
267,
327,
949,
1929,
370,
4165,
2897,
367,
11128,
3631,
267,
372,
339,
340,
365,
63,
1832,
436,
440,
1101,
14,
362,
360,
2060,
297,
488,
304,
267,
2050,
14,
705,
360,
2060,
440,
2013,
358,
267,
870,
63,
3437,
8,
374,
63,
1832,
9,
267,
984,
14,
2224,
8,
18,
9,
339,
340,
440,
365,
63,
1832,
436,
440,
1101,
14,
362,
360,
2060,
297,
488,
9,
971,
288,
436,
440,
1101,
14,
362,
360,
719,
63,
2060,
297,
488,
9,
971,
288,
436,
440,
1101,
14,
362,
360,
2609,
63,
1562,
735,
267,
2050,
14,
705,
360,
2060,
503,
1844,
63,
2060,
440,
2013,
358,
267,
870,
63,
3437,
8,
374,
63,
1832,
9,
267,
984,
14,
2224,
8,
18,
9,
339,
340,
283,
1832,
63,
719,
7,
315,
1101,
26,
267,
1101,
459,
1832,
63,
719,
418,
275,
1109,
8,
888,
459,
1832,
63,
719,
1105,
339,
340,
1101,
14,
362,
360,
1000,
63,
719,
297,
488,
9,
436,
730,
8,
888,
459,
1000,
63,
719,
1105,
1137,
769,
26,
267,
1101,
459,
1000,
63,
719,
418,
275,
1109,
8,
888,
459,
1000,
63,
719,
1105,
339,
340,
1101,
14,
362,
360,
1832,
63,
1562,
297,
4074,
315,
359,
66,
7,
16,
14,
16,
14,
16,
14,
16,
2565,
267,
2050,
14,
4050,
360,
3764,
26,
2257,
663,
370,
6938,
641,
378,
14,
16,
14,
16,
14,
16,
12,
652,
3985,
83,
440,
5048,
358,
272,
340,
1101,
14,
362,
360,
1000,
297,
4074,
315,
788,
4195,
14,
16,
14,
16,
14,
17,
297,
283,
5967,
2565,
267,
2050,
14,
4050,
360,
3764,
26,
1654,
663,
370,
6938,
641,
450,
83,
2689,
83,
12,
787,
1265,
3238,
14069,
450,
2151,
334,
475,
63,
495,
8,
888,
459,
1000,
3815,
1101,
459,
1000,
63,
719,
5156,
272,
340,
334,
888,
14,
362,
360,
765,
297,
4074,
503,
12548,
2325,
342,
508,
283,
1224,
356,
267,
2050,
14,
4050,
360,
3764,
26,
1817,
365,
440,
5048,
27,
8749,
675,
282,
2937,
2412,
10830,
12,
283,
2151,
283,
2930,
19093,
13,
3912,
13,
5487,
34,
358,
272,
340,
334,
888,
14,
362,
360,
765,
297,
4074,
503,
12548,
2325,
342,
508,
283,
1195,
20,
356,
267,
2050,
14,
4050,
360,
3764,
26,
29256,
20,
365,
440,
5048,
27,
8749,
675,
282,
2937,
2412,
10830,
12,
283,
2151,
283,
2930,
19093,
13,
3912,
13,
5487,
34,
358,
272,
340,
1101,
14,
362,
360,
2593,
297,
9601,
9,
665,
2948,
26,
267,
2050,
14,
4050,
360,
3764,
26,
2195,
2653,
450,
68,
12237,
4634,
3974,
7,
450,
2151,
1109,
8,
888,
14,
362,
360,
2593,
7058,
272,
340,
1101,
14,
362,
360,
2593,
297,
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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
] |
hatwar/Das_erpnext
|
erpnext/setup/doctype/backup_manager/backup_dropbox.py
|
33
|
4924
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
# SETUP:
# install pip install --upgrade dropbox
#
# Create new Dropbox App
#
# in conf.py, set oauth2 settings
# dropbox_access_key
# dropbox_access_secret
from __future__ import unicode_literals
import os
import frappe
from frappe.utils import get_request_site_address, cstr
from frappe import _
ignore_list = [".DS_Store"]
@frappe.whitelist()
def get_dropbox_authorize_url():
sess = get_dropbox_session()
request_token = sess.obtain_request_token()
return_address = get_request_site_address(True) \
+ "?cmd=erpnext.setup.doctype.backup_manager.backup_dropbox.dropbox_callback"
url = sess.build_authorize_url(request_token, return_address)
return {
"url": url,
"key": request_token.key,
"secret": request_token.secret,
}
@frappe.whitelist(allow_guest=True)
def dropbox_callback(oauth_token=None, not_approved=False):
from dropbox import client
if not not_approved:
if frappe.db.get_value("Backup Manager", None, "dropbox_access_key")==oauth_token:
allowed = 1
message = "Dropbox access allowed."
sess = get_dropbox_session()
sess.set_request_token(frappe.db.get_value("Backup Manager", None, "dropbox_access_key"),
frappe.db.get_value("Backup Manager", None, "dropbox_access_secret"))
access_token = sess.obtain_access_token()
frappe.db.set_value("Backup Manager", "Backup Manager", "dropbox_access_key", access_token.key)
frappe.db.set_value("Backup Manager", "Backup Manager", "dropbox_access_secret", access_token.secret)
frappe.db.set_value("Backup Manager", "Backup Manager", "dropbox_access_allowed", allowed)
frappe.db.set_value("Backup Manager", "Backup Manager", "send_backups_to_dropbox", 1)
dropbox_client = client.DropboxClient(sess)
try:
dropbox_client.file_create_folder("files")
except:
pass
else:
allowed = 0
message = "Illegal Access Token Please try again."
else:
allowed = 0
message = "Dropbox Access not approved."
frappe.local.message_title = "Dropbox Approval"
frappe.local.message = "<h3>%s</h3><p>Please close this window.</p>" % message
if allowed:
frappe.local.message_success = True
frappe.db.commit()
frappe.response['type'] = 'page'
frappe.response['page_name'] = 'message.html'
def backup_to_dropbox():
from dropbox import client, session
from frappe.utils.backups import new_backup
from frappe.utils import get_files_path, get_backups_path
if not frappe.db:
frappe.connect()
sess = session.DropboxSession(frappe.conf.dropbox_access_key, frappe.conf.dropbox_secret_key, "app_folder")
sess.set_token(frappe.db.get_value("Backup Manager", None, "dropbox_access_key"),
frappe.db.get_value("Backup Manager", None, "dropbox_access_secret"))
dropbox_client = client.DropboxClient(sess)
# upload database
backup = new_backup()
filename = os.path.join(get_backups_path(), os.path.basename(backup.backup_path_db))
upload_file_to_dropbox(filename, "/database", dropbox_client)
frappe.db.close()
response = dropbox_client.metadata("/files")
# upload files to files folder
did_not_upload = []
error_log = []
path = get_files_path()
for filename in os.listdir(path):
filename = cstr(filename)
if filename in ignore_list:
continue
found = False
filepath = os.path.join(path, filename)
for file_metadata in response["contents"]:
if os.path.basename(filepath) == os.path.basename(file_metadata["path"]) and os.stat(filepath).st_size == int(file_metadata["bytes"]):
found = True
break
if not found:
try:
upload_file_to_dropbox(filepath, "/files", dropbox_client)
except Exception:
did_not_upload.append(filename)
error_log.append(frappe.get_traceback())
frappe.connect()
return did_not_upload, list(set(error_log))
def get_dropbox_session():
try:
from dropbox import session
except:
frappe.msgprint(_("Please install dropbox python module"), raise_exception=1)
if not (frappe.conf.dropbox_access_key or frappe.conf.dropbox_secret_key):
frappe.throw(_("Please set Dropbox access keys in your site config"))
sess = session.DropboxSession(frappe.conf.dropbox_access_key, frappe.conf.dropbox_secret_key, "app_folder")
return sess
def upload_file_to_dropbox(filename, folder, dropbox_client):
from dropbox import rest
size = os.stat(filename).st_size
with open(filename, 'r') as f:
# if max packet size reached, use chunked uploader
max_packet_size = 4194304
if size > max_packet_size:
uploader = dropbox_client.get_chunked_uploader(f, size)
while uploader.offset < size:
try:
uploader.upload_chunked()
uploader.finish(folder + "/" + os.path.basename(filename), overwrite=True)
except rest.ErrorResponse:
pass
else:
dropbox_client.put_file(folder + "/" + os.path.basename(filename), f, overwrite=True)
if __name__=="__main__":
backup_to_dropbox()
|
agpl-3.0
|
[
3,
1898,
334,
67,
9,
6900,
12,
481,
5034,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
844,
26,
1664,
1696,
1684,
844,
373,
19,
14,
1666,
4190,
14,
2424,
199,
199,
3,
11543,
2160,
26,
199,
3,
3907,
7305,
3907,
1553,
9375,
5978,
1977,
199,
3,
199,
3,
2790,
892,
18110,
1977,
4693,
199,
3,
199,
3,
315,
3743,
14,
647,
12,
663,
9725,
18,
2202,
199,
3,
5978,
1977,
63,
2732,
63,
498,
199,
3,
5978,
1977,
63,
2732,
63,
4731,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
747,
199,
646,
6950,
199,
504,
6950,
14,
1208,
492,
664,
63,
1069,
63,
2124,
63,
1562,
12,
286,
495,
199,
504,
6950,
492,
485,
199,
199,
4247,
63,
513,
275,
359,
1674,
3177,
63,
5502,
937,
199,
199,
32,
9098,
14,
14189,
342,
199,
318,
664,
63,
32118,
63,
14204,
63,
633,
837,
199,
198,
5480,
275,
664,
63,
32118,
63,
1730,
342,
199,
198,
1069,
63,
1418,
275,
4043,
14,
2873,
877,
63,
1069,
63,
1418,
342,
199,
198,
1107,
63,
1562,
275,
664,
63,
1069,
63,
2124,
63,
1562,
8,
549,
9,
971,
507,
198,
11,
23665,
1760,
29,
281,
23416,
14,
2758,
14,
6356,
14,
5751,
63,
2609,
14,
5751,
63,
32118,
14,
32118,
63,
3058,
2,
421,
198,
633,
275,
4043,
14,
1506,
63,
14204,
63,
633,
8,
1069,
63,
1418,
12,
372,
63,
1562,
9,
421,
198,
1107,
469,
507,
198,
2,
633,
582,
1166,
12,
507,
198,
2,
498,
582,
1056,
63,
1418,
14,
498,
12,
507,
198,
2,
4731,
582,
1056,
63,
1418,
14,
4731,
12,
199,
198,
93,
199,
199,
32,
9098,
14,
14189,
8,
3306,
63,
10409,
29,
549,
9,
199,
318,
5978,
1977,
63,
3058,
8,
6126,
63,
1418,
29,
403,
12,
440,
63,
21556,
29,
797,
304,
199,
198,
504,
5978,
1977,
492,
1890,
199,
198,
692,
440,
440,
63,
21556,
26,
507,
198,
692,
6950,
14,
697,
14,
362,
63,
585,
480,
16559,
13537,
401,
488,
12,
298,
32118,
63,
2732,
63,
498,
531,
389,
6126,
63,
1418,
26,
686,
198,
6541,
275,
413,
686,
198,
1188,
275,
298,
11070,
1977,
2879,
4370,
2122,
6319,
198,
5480,
275,
664,
63,
32118,
63,
1730,
342,
686,
198,
5480,
14,
409,
63,
1069,
63,
1418,
8,
9098,
14,
697,
14,
362,
63,
585,
480,
16559,
13537,
401,
488,
12,
298,
32118,
63,
2732,
63,
498,
1288,
1585,
198,
9098,
14,
697,
14,
362,
63,
585,
480,
16559,
13537,
401,
488,
12,
298,
32118,
63,
2732,
63,
4731,
2237,
686,
198,
2732,
63,
1418,
275,
4043,
14,
2873,
877,
63,
2732,
63,
1418,
342,
686,
198,
9098,
14,
697,
14,
409,
63,
585,
480,
16559,
13537,
401,
298,
16559,
13537,
401,
298,
32118,
63,
2732,
63,
498,
401,
2879,
63,
1418,
14,
498,
9,
686,
198,
9098,
14,
697,
14,
409,
63,
585,
480,
16559,
13537,
401,
298,
16559,
13537,
401,
298,
32118,
63,
2732,
63,
4731,
401,
2879,
63,
1418,
14,
4731,
9,
686,
198,
9098,
14,
697,
14,
409,
63,
585,
480,
16559,
13537,
401,
298,
16559,
13537,
401,
298,
32118,
63,
2732,
63,
6541,
401,
4370,
9,
686,
198,
9098,
14,
697,
14,
409,
63,
585,
480,
16559,
13537,
401,
298,
16559,
13537,
401,
298,
2254,
63,
27376,
63,
475,
63,
32118,
401,
413,
9,
686,
198,
32118,
63,
1258,
275,
1890,
14,
11070,
1977,
3041,
8,
5480,
9,
686,
198,
893,
26,
1585,
198,
32118,
63,
1258,
14,
493,
63,
981,
63,
3741,
480,
1725,
531,
686,
198,
2590,
26,
1585,
198,
1529,
2742,
198,
2836,
26,
686,
198,
6541,
275,
378,
686,
198,
1188,
275,
298,
25501,
11003,
8767,
7754,
862,
4020,
2122,
199,
198,
2836,
26,
507,
198,
6541,
275,
378,
507,
198,
1188,
275,
298,
11070,
1977,
11003,
440,
30055,
2122,
421,
198,
9098,
14,
1832,
14,
1188,
63,
1213,
275,
298,
11070,
1977,
19615,
637,
2,
199,
198,
9098,
14,
1832,
14,
1188,
275,
3886,
72,
19,
6598,
83,
1108,
72,
19,
2535,
80,
30,
8254,
4002,
642,
4353,
9758,
80,
4335,
450,
1245,
421,
198,
692,
4370,
26,
507,
198,
9098,
14,
1832,
14,
1188,
63,
3742,
275,
715,
421,
198,
9098,
14,
697,
14,
3543,
342,
199,
198,
9098,
14,
1310,
459,
466,
418,
275,
283,
1606,
7,
199,
198,
9098,
14,
1310,
459,
1606,
63,
354,
418,
275,
283,
1188,
14,
1360,
7,
199,
199,
318,
6902,
63,
475,
63,
32118,
837,
199,
198,
504,
5978,
1977,
492,
1890,
12,
2351,
199,
198,
504,
6950,
14,
1208,
14,
27376,
492,
892,
63,
5751,
199,
198,
504,
6950,
14,
1208,
492,
664,
63,
1725,
63,
515,
12,
664,
63,
27376,
63,
515,
199,
198,
692,
440,
6950,
14,
697,
26,
507,
198,
9098,
14,
2242,
342,
421,
198,
5480,
275,
2351,
14,
11070,
1977,
4434,
8,
9098,
14,
2190,
14,
32118,
63,
2732,
63,
498,
12,
6950,
14,
2190,
14,
32118,
63,
4731,
63,
498,
12,
298,
571,
63,
3741,
531,
421,
198,
5480,
14,
409,
63,
1418,
8,
9098,
14,
697,
14,
362,
63,
585,
480,
16559,
13537,
401,
488,
12,
298,
32118,
63,
2732,
63,
498,
1288,
507,
198,
9098,
14,
697,
14,
362,
63,
585,
480,
16559,
13537,
401,
488,
12,
298,
32118,
63,
2732,
63,
4731,
2237,
421,
198,
32118,
63,
1258,
275,
1890,
14,
11070,
1977,
3041,
8,
5480,
9,
421,
198,
3,
5802,
3050,
199,
198,
5751,
275,
892,
63,
5751,
342,
199,
198,
1501,
275,
747,
14,
515,
14,
904,
8,
362,
63,
27376,
63,
515,
1062,
747,
14,
515,
14,
4846,
8,
5751,
14,
5751,
63,
515,
63,
697,
430,
199,
198,
5064,
63,
493,
63,
475,
63,
32118,
8,
1501,
12,
3286,
4659,
401,
5978,
1977,
63,
1258,
9,
421,
198,
9098,
14,
697,
14,
1600,
342,
199,
198,
1310,
275,
5978,
1977,
63,
1258,
14,
2343,
4769,
1725,
531,
421,
198,
3,
5802,
1584,
370,
1584,
4922,
199,
198,
14887,
63,
1397,
63,
5064,
275,
942,
199,
198,
705,
63,
793,
275,
942,
199,
198,
515,
275,
664,
63,
1725,
63,
515,
342,
199,
198,
509,
1788,
315,
747,
14,
7374,
8,
515,
304,
507,
198,
1501,
275
] |
[
1898,
334,
67,
9,
6900,
12,
481,
5034,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
844,
26,
1664,
1696,
1684,
844,
373,
19,
14,
1666,
4190,
14,
2424,
199,
199,
3,
11543,
2160,
26,
199,
3,
3907,
7305,
3907,
1553,
9375,
5978,
1977,
199,
3,
199,
3,
2790,
892,
18110,
1977,
4693,
199,
3,
199,
3,
315,
3743,
14,
647,
12,
663,
9725,
18,
2202,
199,
3,
5978,
1977,
63,
2732,
63,
498,
199,
3,
5978,
1977,
63,
2732,
63,
4731,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
747,
199,
646,
6950,
199,
504,
6950,
14,
1208,
492,
664,
63,
1069,
63,
2124,
63,
1562,
12,
286,
495,
199,
504,
6950,
492,
485,
199,
199,
4247,
63,
513,
275,
359,
1674,
3177,
63,
5502,
937,
199,
199,
32,
9098,
14,
14189,
342,
199,
318,
664,
63,
32118,
63,
14204,
63,
633,
837,
199,
198,
5480,
275,
664,
63,
32118,
63,
1730,
342,
199,
198,
1069,
63,
1418,
275,
4043,
14,
2873,
877,
63,
1069,
63,
1418,
342,
199,
198,
1107,
63,
1562,
275,
664,
63,
1069,
63,
2124,
63,
1562,
8,
549,
9,
971,
507,
198,
11,
23665,
1760,
29,
281,
23416,
14,
2758,
14,
6356,
14,
5751,
63,
2609,
14,
5751,
63,
32118,
14,
32118,
63,
3058,
2,
421,
198,
633,
275,
4043,
14,
1506,
63,
14204,
63,
633,
8,
1069,
63,
1418,
12,
372,
63,
1562,
9,
421,
198,
1107,
469,
507,
198,
2,
633,
582,
1166,
12,
507,
198,
2,
498,
582,
1056,
63,
1418,
14,
498,
12,
507,
198,
2,
4731,
582,
1056,
63,
1418,
14,
4731,
12,
199,
198,
93,
199,
199,
32,
9098,
14,
14189,
8,
3306,
63,
10409,
29,
549,
9,
199,
318,
5978,
1977,
63,
3058,
8,
6126,
63,
1418,
29,
403,
12,
440,
63,
21556,
29,
797,
304,
199,
198,
504,
5978,
1977,
492,
1890,
199,
198,
692,
440,
440,
63,
21556,
26,
507,
198,
692,
6950,
14,
697,
14,
362,
63,
585,
480,
16559,
13537,
401,
488,
12,
298,
32118,
63,
2732,
63,
498,
531,
389,
6126,
63,
1418,
26,
686,
198,
6541,
275,
413,
686,
198,
1188,
275,
298,
11070,
1977,
2879,
4370,
2122,
6319,
198,
5480,
275,
664,
63,
32118,
63,
1730,
342,
686,
198,
5480,
14,
409,
63,
1069,
63,
1418,
8,
9098,
14,
697,
14,
362,
63,
585,
480,
16559,
13537,
401,
488,
12,
298,
32118,
63,
2732,
63,
498,
1288,
1585,
198,
9098,
14,
697,
14,
362,
63,
585,
480,
16559,
13537,
401,
488,
12,
298,
32118,
63,
2732,
63,
4731,
2237,
686,
198,
2732,
63,
1418,
275,
4043,
14,
2873,
877,
63,
2732,
63,
1418,
342,
686,
198,
9098,
14,
697,
14,
409,
63,
585,
480,
16559,
13537,
401,
298,
16559,
13537,
401,
298,
32118,
63,
2732,
63,
498,
401,
2879,
63,
1418,
14,
498,
9,
686,
198,
9098,
14,
697,
14,
409,
63,
585,
480,
16559,
13537,
401,
298,
16559,
13537,
401,
298,
32118,
63,
2732,
63,
4731,
401,
2879,
63,
1418,
14,
4731,
9,
686,
198,
9098,
14,
697,
14,
409,
63,
585,
480,
16559,
13537,
401,
298,
16559,
13537,
401,
298,
32118,
63,
2732,
63,
6541,
401,
4370,
9,
686,
198,
9098,
14,
697,
14,
409,
63,
585,
480,
16559,
13537,
401,
298,
16559,
13537,
401,
298,
2254,
63,
27376,
63,
475,
63,
32118,
401,
413,
9,
686,
198,
32118,
63,
1258,
275,
1890,
14,
11070,
1977,
3041,
8,
5480,
9,
686,
198,
893,
26,
1585,
198,
32118,
63,
1258,
14,
493,
63,
981,
63,
3741,
480,
1725,
531,
686,
198,
2590,
26,
1585,
198,
1529,
2742,
198,
2836,
26,
686,
198,
6541,
275,
378,
686,
198,
1188,
275,
298,
25501,
11003,
8767,
7754,
862,
4020,
2122,
199,
198,
2836,
26,
507,
198,
6541,
275,
378,
507,
198,
1188,
275,
298,
11070,
1977,
11003,
440,
30055,
2122,
421,
198,
9098,
14,
1832,
14,
1188,
63,
1213,
275,
298,
11070,
1977,
19615,
637,
2,
199,
198,
9098,
14,
1832,
14,
1188,
275,
3886,
72,
19,
6598,
83,
1108,
72,
19,
2535,
80,
30,
8254,
4002,
642,
4353,
9758,
80,
4335,
450,
1245,
421,
198,
692,
4370,
26,
507,
198,
9098,
14,
1832,
14,
1188,
63,
3742,
275,
715,
421,
198,
9098,
14,
697,
14,
3543,
342,
199,
198,
9098,
14,
1310,
459,
466,
418,
275,
283,
1606,
7,
199,
198,
9098,
14,
1310,
459,
1606,
63,
354,
418,
275,
283,
1188,
14,
1360,
7,
199,
199,
318,
6902,
63,
475,
63,
32118,
837,
199,
198,
504,
5978,
1977,
492,
1890,
12,
2351,
199,
198,
504,
6950,
14,
1208,
14,
27376,
492,
892,
63,
5751,
199,
198,
504,
6950,
14,
1208,
492,
664,
63,
1725,
63,
515,
12,
664,
63,
27376,
63,
515,
199,
198,
692,
440,
6950,
14,
697,
26,
507,
198,
9098,
14,
2242,
342,
421,
198,
5480,
275,
2351,
14,
11070,
1977,
4434,
8,
9098,
14,
2190,
14,
32118,
63,
2732,
63,
498,
12,
6950,
14,
2190,
14,
32118,
63,
4731,
63,
498,
12,
298,
571,
63,
3741,
531,
421,
198,
5480,
14,
409,
63,
1418,
8,
9098,
14,
697,
14,
362,
63,
585,
480,
16559,
13537,
401,
488,
12,
298,
32118,
63,
2732,
63,
498,
1288,
507,
198,
9098,
14,
697,
14,
362,
63,
585,
480,
16559,
13537,
401,
488,
12,
298,
32118,
63,
2732,
63,
4731,
2237,
421,
198,
32118,
63,
1258,
275,
1890,
14,
11070,
1977,
3041,
8,
5480,
9,
421,
198,
3,
5802,
3050,
199,
198,
5751,
275,
892,
63,
5751,
342,
199,
198,
1501,
275,
747,
14,
515,
14,
904,
8,
362,
63,
27376,
63,
515,
1062,
747,
14,
515,
14,
4846,
8,
5751,
14,
5751,
63,
515,
63,
697,
430,
199,
198,
5064,
63,
493,
63,
475,
63,
32118,
8,
1501,
12,
3286,
4659,
401,
5978,
1977,
63,
1258,
9,
421,
198,
9098,
14,
697,
14,
1600,
342,
199,
198,
1310,
275,
5978,
1977,
63,
1258,
14,
2343,
4769,
1725,
531,
421,
198,
3,
5802,
1584,
370,
1584,
4922,
199,
198,
14887,
63,
1397,
63,
5064,
275,
942,
199,
198,
705,
63,
793,
275,
942,
199,
198,
515,
275,
664,
63,
1725,
63,
515,
342,
199,
198,
509,
1788,
315,
747,
14,
7374,
8,
515,
304,
507,
198,
1501,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
zhumingliang1209/Ardupilot
|
ardupilot/modules/waf/waflib/extras/pep8.py
|
5
|
3477
|
#! /usr/bin/env python
# encoding: utf-8
#
# written by Sylvain Rouquette, 2011
'''
Install pep8 module:
$ easy_install pep8
or
$ pip install pep8
To add the boost tool to the waf file:
$ ./waf-light --tools=compat15,pep8
or, if you have waf >= 1.6.2
$ ./waf update --files=pep8
Then add this to your wscript:
[at]extension('.py', 'wscript')
def run_pep8(self, node):
self.create_task('Pep8', node)
'''
import threading
from waflib import Task, Options
pep8 = __import__('pep8')
class Pep8(Task.Task):
color = 'PINK'
lock = threading.Lock()
def check_options(self):
if pep8.options:
return
pep8.options = Options.options
pep8.options.prog = 'pep8'
excl = pep8.options.exclude.split(',')
pep8.options.exclude = [s.rstrip('/') for s in excl]
if pep8.options.filename:
pep8.options.filename = pep8.options.filename.split(',')
if pep8.options.select:
pep8.options.select = pep8.options.select.split(',')
else:
pep8.options.select = []
if pep8.options.ignore:
pep8.options.ignore = pep8.options.ignore.split(',')
elif pep8.options.select:
# Ignore all checks which are not explicitly selected
pep8.options.ignore = ['']
elif pep8.options.testsuite or pep8.options.doctest:
# For doctest and testsuite, all checks are required
pep8.options.ignore = []
else:
# The default choice: ignore controversial checks
pep8.options.ignore = pep8.DEFAULT_IGNORE.split(',')
pep8.options.physical_checks = pep8.find_checks('physical_line')
pep8.options.logical_checks = pep8.find_checks('logical_line')
pep8.options.counters = dict.fromkeys(pep8.BENCHMARK_KEYS, 0)
pep8.options.messages = {}
def run(self):
with Pep8.lock:
self.check_options()
pep8.input_file(self.inputs[0].abspath())
return 0 if not pep8.get_count() else -1
def options(opt):
opt.add_option('-q', '--quiet', default=0, action='count',
help="report only file names, or nothing with -qq")
opt.add_option('-r', '--repeat', action='store_true',
help="show all occurrences of the same error")
opt.add_option('--exclude', metavar='patterns',
default=pep8.DEFAULT_EXCLUDE,
help="exclude files or directories which match these "
"comma separated patterns (default: %s)" %
pep8.DEFAULT_EXCLUDE,
dest='exclude')
opt.add_option('--filename', metavar='patterns', default='*.py',
help="when parsing directories, only check filenames "
"matching these comma separated patterns (default: "
"*.py)")
opt.add_option('--select', metavar='errors', default='',
help="select errors and warnings (e.g. E,W6)")
opt.add_option('--ignore', metavar='errors', default='',
help="skip errors and warnings (e.g. E4,W)")
opt.add_option('--show-source', action='store_true',
help="show source code for each error")
opt.add_option('--show-pep8', action='store_true',
help="show text of PEP 8 for each error")
opt.add_option('--statistics', action='store_true',
help="count errors and warnings")
opt.add_option('--count', action='store_true',
help="print total number of errors and warnings "
"to standard error and set exit code to 1 if "
"total is not null")
opt.add_option('--benchmark', action='store_true',
help="measure processing speed")
opt.add_option('--testsuite', metavar='dir',
help="run regression tests from dir")
opt.add_option('--doctest', action='store_true',
help="run doctest on myself")
|
gpl-3.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
3,
199,
3,
5313,
701,
5515,
6371,
1581,
19776,
544,
14586,
12,
7760,
199,
199,
2344,
199,
8154,
22602,
24,
859,
26,
199,
4,
8837,
63,
3174,
22602,
24,
199,
198,
269,
199,
4,
7305,
3907,
22602,
24,
199,
199,
1378,
1050,
314,
20198,
4744,
370,
314,
25782,
570,
26,
199,
4,
16605,
21500,
13,
4040,
1553,
2537,
29,
5819,
1046,
12,
12636,
24,
199,
198,
269,
12,
340,
1265,
1172,
25782,
2356,
413,
14,
22,
14,
18,
199,
4,
16605,
21500,
1678,
1553,
1725,
29,
12636,
24,
421,
199,
28226,
1050,
642,
370,
2195,
336,
1579,
26,
199,
199,
59,
292,
61,
3435,
5175,
647,
297,
283,
87,
1579,
358,
199,
318,
1255,
63,
12636,
24,
8,
277,
12,
1031,
304,
199,
198,
277,
14,
981,
63,
1765,
360,
48,
1545,
24,
297,
1031,
9,
199,
199,
2344,
199,
199,
646,
5796,
199,
504,
31380,
492,
8495,
12,
8394,
199,
199,
12636,
24,
275,
636,
646,
19734,
12636,
24,
358,
421,
199,
533,
510,
1545,
24,
8,
4476,
14,
4476,
304,
199,
198,
2326,
275,
283,
48,
12394,
7,
199,
198,
831,
275,
5796,
14,
6432,
342,
421,
198,
318,
1104,
63,
1419,
8,
277,
304,
507,
198,
692,
22602,
24,
14,
1419,
26,
686,
198,
1107,
507,
198,
12636,
24,
14,
1419,
275,
8394,
14,
1419,
507,
198,
12636,
24,
14,
1419,
14,
6595,
275,
283,
12636,
24,
7,
507,
198,
476,
429,
275,
22602,
24,
14,
1419,
14,
5473,
14,
1294,
11917,
507,
198,
12636,
24,
14,
1419,
14,
5473,
275,
359,
83,
14,
6735,
7825,
367,
308,
315,
444,
429,
61,
507,
198,
692,
22602,
24,
14,
1419,
14,
1501,
26,
686,
198,
12636,
24,
14,
1419,
14,
1501,
275,
22602,
24,
14,
1419,
14,
1501,
14,
1294,
11917,
507,
198,
692,
22602,
24,
14,
1419,
14,
2416,
26,
686,
198,
12636,
24,
14,
1419,
14,
2416,
275,
22602,
24,
14,
1419,
14,
2416,
14,
1294,
11917,
507,
198,
2836,
26,
686,
198,
12636,
24,
14,
1419,
14,
2416,
275,
942,
507,
198,
692,
22602,
24,
14,
1419,
14,
4247,
26,
686,
198,
12636,
24,
14,
1419,
14,
4247,
275,
22602,
24,
14,
1419,
14,
4247,
14,
1294,
11917,
507,
198,
4164,
22602,
24,
14,
1419,
14,
2416,
26,
686,
198,
3,
14092,
1006,
5920,
1314,
787,
440,
7662,
4895,
686,
198,
12636,
24,
14,
1419,
14,
4247,
275,
24506,
507,
198,
4164,
22602,
24,
14,
1419,
14,
14239,
503,
22602,
24,
14,
1419,
14,
11390,
26,
686,
198,
3,
2104,
8868,
436,
2295,
2577,
12,
1006,
5920,
787,
1415,
686,
198,
12636,
24,
14,
1419,
14,
4247,
275,
942,
507,
198,
2836,
26,
686,
198,
3,
710,
849,
7141,
26,
3686,
25516,
422,
338,
279,
5920,
686,
198,
12636,
24,
14,
1419,
14,
4247,
275,
22602,
24,
14,
3472,
63,
11209,
14,
1294,
11917,
507,
198,
12636,
24,
14,
1419,
14,
15020,
63,
8625,
275,
22602,
24,
14,
1623,
63,
8625,
360,
15020,
63,
604,
358,
507,
198,
12636,
24,
14,
1419,
14,
7954,
63,
8625,
275,
22602,
24,
14,
1623,
63,
8625,
360,
7954,
63,
604,
358,
507,
198,
12636,
24,
14,
1419,
14,
16558,
275,
1211,
14,
19164,
8,
12636,
24,
14,
34,
742,
1244,
10520,
63,
17434,
12,
378,
9,
507,
198,
12636,
24,
14,
1419,
14,
3431,
275,
1052,
421,
198,
318,
1255,
8,
277,
304,
507,
198,
1045,
510,
1545,
24,
14,
831,
26,
686,
198,
277,
14,
1074,
63,
1419,
342,
507,
198,
12636,
24,
14,
1210,
63,
493,
8,
277,
14,
3711,
59,
16,
1055,
4832,
1012,
507,
198,
1107,
378,
340,
440,
22602,
24,
14,
362,
63,
835,
342,
587,
446,
17,
421,
199,
318,
1511,
8,
2992,
304,
199,
198,
2992,
14,
525,
63,
1422,
3654,
81,
297,
2850,
10243,
297,
849,
29,
16,
12,
1595,
534,
835,
297,
1871,
257,
1720,
628,
3070,
1454,
570,
1561,
12,
503,
6548,
543,
446,
16672,
531,
199,
198,
2992,
14,
525,
63,
1422,
3654,
82,
297,
2850,
8755,
297,
1595,
534,
1617,
63,
2052,
297,
1871,
257,
1720,
628,
2384,
1006,
22099,
402,
314,
2011,
1125,
531,
199,
198,
2992,
14,
525,
63,
1422,
4517,
5473,
297,
8214,
534,
7435,
297,
1871,
257,
849,
29,
12636,
24,
14,
3472,
63,
1438,
13958,
12,
1871,
257,
1720,
628,
5473,
1584,
503,
6602,
1314,
1336,
3520,
298,
1871,
257,
298,
13184,
11673,
7970,
334,
885,
26,
450,
83,
2924,
450,
1871,
257,
22602,
24,
14,
3472,
63,
1438,
13958,
12,
1871,
257,
2053,
534,
5473,
358,
199,
198,
2992,
14,
525,
63,
1422,
4517,
1501,
297,
8214,
534,
7435,
297,
849,
534,
4856,
647,
297,
1871,
257,
1720,
628,
6526,
6057,
6602,
12,
1454,
1104,
6203,
298,
1871,
257,
298,
9467,
3520,
10029,
11673,
7970,
334,
885,
26,
298,
1871,
257,
298,
4856,
647,
6320,
199,
198,
2992,
14,
525,
63,
1422,
4517,
2416,
297,
8214,
534,
2550,
297,
849,
4581,
1871,
257,
1720,
628,
2416,
2552,
436,
3598,
334,
69,
14,
71,
14,
662,
12,
55,
22,
6320,
199,
198,
2992,
14,
525,
63,
1422,
4517,
4247,
297,
8214,
534,
2550,
297,
849,
4581,
1871,
257,
1720,
628,
2759,
2552,
436,
3598,
334,
69,
14,
71,
14,
662,
20,
12,
55,
6320,
199,
198,
2992,
14,
525,
63,
1422,
4517,
2384,
13,
1365,
297,
1595,
534,
1617,
63,
2052,
297,
1871,
257,
1720,
628,
2384,
1350,
1233,
367,
1924,
1125,
531,
199,
198,
2992,
14,
525,
63,
1422,
4517,
2384,
13,
12636,
24,
297,
1595,
534,
1617,
63,
2052,
297,
1871,
257,
1720,
628,
2384,
1318,
402,
13663,
1695,
367,
1924,
1125,
531,
199,
198,
2992,
14,
525,
63,
1422,
4517,
13724,
297,
1595,
534,
1617,
63,
2052,
297,
1871,
257,
1720,
628,
835,
2552,
436,
3598,
531,
199,
198,
2992,
14,
525,
63,
1422,
4517,
835,
297,
1595,
534,
1617,
63,
2052,
297,
1871,
257,
1720,
628,
1361,
3141,
1329,
402,
2552,
436,
3598,
298,
1871,
257,
298,
475,
4465,
1125,
436,
663,
4458,
1233,
370,
413,
340,
298,
1871,
257,
298,
2923,
365,
440,
2973,
531,
199,
198,
2992,
14,
525,
63,
1422,
4517,
11861
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
3,
199,
3,
5313,
701,
5515,
6371,
1581,
19776,
544,
14586,
12,
7760,
199,
199,
2344,
199,
8154,
22602,
24,
859,
26,
199,
4,
8837,
63,
3174,
22602,
24,
199,
198,
269,
199,
4,
7305,
3907,
22602,
24,
199,
199,
1378,
1050,
314,
20198,
4744,
370,
314,
25782,
570,
26,
199,
4,
16605,
21500,
13,
4040,
1553,
2537,
29,
5819,
1046,
12,
12636,
24,
199,
198,
269,
12,
340,
1265,
1172,
25782,
2356,
413,
14,
22,
14,
18,
199,
4,
16605,
21500,
1678,
1553,
1725,
29,
12636,
24,
421,
199,
28226,
1050,
642,
370,
2195,
336,
1579,
26,
199,
199,
59,
292,
61,
3435,
5175,
647,
297,
283,
87,
1579,
358,
199,
318,
1255,
63,
12636,
24,
8,
277,
12,
1031,
304,
199,
198,
277,
14,
981,
63,
1765,
360,
48,
1545,
24,
297,
1031,
9,
199,
199,
2344,
199,
199,
646,
5796,
199,
504,
31380,
492,
8495,
12,
8394,
199,
199,
12636,
24,
275,
636,
646,
19734,
12636,
24,
358,
421,
199,
533,
510,
1545,
24,
8,
4476,
14,
4476,
304,
199,
198,
2326,
275,
283,
48,
12394,
7,
199,
198,
831,
275,
5796,
14,
6432,
342,
421,
198,
318,
1104,
63,
1419,
8,
277,
304,
507,
198,
692,
22602,
24,
14,
1419,
26,
686,
198,
1107,
507,
198,
12636,
24,
14,
1419,
275,
8394,
14,
1419,
507,
198,
12636,
24,
14,
1419,
14,
6595,
275,
283,
12636,
24,
7,
507,
198,
476,
429,
275,
22602,
24,
14,
1419,
14,
5473,
14,
1294,
11917,
507,
198,
12636,
24,
14,
1419,
14,
5473,
275,
359,
83,
14,
6735,
7825,
367,
308,
315,
444,
429,
61,
507,
198,
692,
22602,
24,
14,
1419,
14,
1501,
26,
686,
198,
12636,
24,
14,
1419,
14,
1501,
275,
22602,
24,
14,
1419,
14,
1501,
14,
1294,
11917,
507,
198,
692,
22602,
24,
14,
1419,
14,
2416,
26,
686,
198,
12636,
24,
14,
1419,
14,
2416,
275,
22602,
24,
14,
1419,
14,
2416,
14,
1294,
11917,
507,
198,
2836,
26,
686,
198,
12636,
24,
14,
1419,
14,
2416,
275,
942,
507,
198,
692,
22602,
24,
14,
1419,
14,
4247,
26,
686,
198,
12636,
24,
14,
1419,
14,
4247,
275,
22602,
24,
14,
1419,
14,
4247,
14,
1294,
11917,
507,
198,
4164,
22602,
24,
14,
1419,
14,
2416,
26,
686,
198,
3,
14092,
1006,
5920,
1314,
787,
440,
7662,
4895,
686,
198,
12636,
24,
14,
1419,
14,
4247,
275,
24506,
507,
198,
4164,
22602,
24,
14,
1419,
14,
14239,
503,
22602,
24,
14,
1419,
14,
11390,
26,
686,
198,
3,
2104,
8868,
436,
2295,
2577,
12,
1006,
5920,
787,
1415,
686,
198,
12636,
24,
14,
1419,
14,
4247,
275,
942,
507,
198,
2836,
26,
686,
198,
3,
710,
849,
7141,
26,
3686,
25516,
422,
338,
279,
5920,
686,
198,
12636,
24,
14,
1419,
14,
4247,
275,
22602,
24,
14,
3472,
63,
11209,
14,
1294,
11917,
507,
198,
12636,
24,
14,
1419,
14,
15020,
63,
8625,
275,
22602,
24,
14,
1623,
63,
8625,
360,
15020,
63,
604,
358,
507,
198,
12636,
24,
14,
1419,
14,
7954,
63,
8625,
275,
22602,
24,
14,
1623,
63,
8625,
360,
7954,
63,
604,
358,
507,
198,
12636,
24,
14,
1419,
14,
16558,
275,
1211,
14,
19164,
8,
12636,
24,
14,
34,
742,
1244,
10520,
63,
17434,
12,
378,
9,
507,
198,
12636,
24,
14,
1419,
14,
3431,
275,
1052,
421,
198,
318,
1255,
8,
277,
304,
507,
198,
1045,
510,
1545,
24,
14,
831,
26,
686,
198,
277,
14,
1074,
63,
1419,
342,
507,
198,
12636,
24,
14,
1210,
63,
493,
8,
277,
14,
3711,
59,
16,
1055,
4832,
1012,
507,
198,
1107,
378,
340,
440,
22602,
24,
14,
362,
63,
835,
342,
587,
446,
17,
421,
199,
318,
1511,
8,
2992,
304,
199,
198,
2992,
14,
525,
63,
1422,
3654,
81,
297,
2850,
10243,
297,
849,
29,
16,
12,
1595,
534,
835,
297,
1871,
257,
1720,
628,
3070,
1454,
570,
1561,
12,
503,
6548,
543,
446,
16672,
531,
199,
198,
2992,
14,
525,
63,
1422,
3654,
82,
297,
2850,
8755,
297,
1595,
534,
1617,
63,
2052,
297,
1871,
257,
1720,
628,
2384,
1006,
22099,
402,
314,
2011,
1125,
531,
199,
198,
2992,
14,
525,
63,
1422,
4517,
5473,
297,
8214,
534,
7435,
297,
1871,
257,
849,
29,
12636,
24,
14,
3472,
63,
1438,
13958,
12,
1871,
257,
1720,
628,
5473,
1584,
503,
6602,
1314,
1336,
3520,
298,
1871,
257,
298,
13184,
11673,
7970,
334,
885,
26,
450,
83,
2924,
450,
1871,
257,
22602,
24,
14,
3472,
63,
1438,
13958,
12,
1871,
257,
2053,
534,
5473,
358,
199,
198,
2992,
14,
525,
63,
1422,
4517,
1501,
297,
8214,
534,
7435,
297,
849,
534,
4856,
647,
297,
1871,
257,
1720,
628,
6526,
6057,
6602,
12,
1454,
1104,
6203,
298,
1871,
257,
298,
9467,
3520,
10029,
11673,
7970,
334,
885,
26,
298,
1871,
257,
298,
4856,
647,
6320,
199,
198,
2992,
14,
525,
63,
1422,
4517,
2416,
297,
8214,
534,
2550,
297,
849,
4581,
1871,
257,
1720,
628,
2416,
2552,
436,
3598,
334,
69,
14,
71,
14,
662,
12,
55,
22,
6320,
199,
198,
2992,
14,
525,
63,
1422,
4517,
4247,
297,
8214,
534,
2550,
297,
849,
4581,
1871,
257,
1720,
628,
2759,
2552,
436,
3598,
334,
69,
14,
71,
14,
662,
20,
12,
55,
6320,
199,
198,
2992,
14,
525,
63,
1422,
4517,
2384,
13,
1365,
297,
1595,
534,
1617,
63,
2052,
297,
1871,
257,
1720,
628,
2384,
1350,
1233,
367,
1924,
1125,
531,
199,
198,
2992,
14,
525,
63,
1422,
4517,
2384,
13,
12636,
24,
297,
1595,
534,
1617,
63,
2052,
297,
1871,
257,
1720,
628,
2384,
1318,
402,
13663,
1695,
367,
1924,
1125,
531,
199,
198,
2992,
14,
525,
63,
1422,
4517,
13724,
297,
1595,
534,
1617,
63,
2052,
297,
1871,
257,
1720,
628,
835,
2552,
436,
3598,
531,
199,
198,
2992,
14,
525,
63,
1422,
4517,
835,
297,
1595,
534,
1617,
63,
2052,
297,
1871,
257,
1720,
628,
1361,
3141,
1329,
402,
2552,
436,
3598,
298,
1871,
257,
298,
475,
4465,
1125,
436,
663,
4458,
1233,
370,
413,
340,
298,
1871,
257,
298,
2923,
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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
qmarlats/pyquizz
|
env-3/lib/python3.5/site-packages/pip/wheel.py
|
78
|
32216
|
"""
Support for installing and building the "wheel" binary package format.
"""
from __future__ import absolute_import
import compileall
import csv
import errno
import functools
import hashlib
import logging
import os
import os.path
import re
import shutil
import stat
import sys
import tempfile
import warnings
from base64 import urlsafe_b64encode
from email.parser import Parser
from pip._vendor.six import StringIO
import pip
from pip.compat import expanduser
from pip.download import path_to_url, unpack_url
from pip.exceptions import (
InstallationError, InvalidWheelFilename, UnsupportedWheel)
from pip.locations import distutils_scheme, PIP_DELETE_MARKER_FILENAME
from pip import pep425tags
from pip.utils import (
call_subprocess, ensure_dir, captured_stdout, rmtree, read_chunks,
)
from pip.utils.ui import open_spinner
from pip.utils.logging import indent_log
from pip.utils.setuptools_build import SETUPTOOLS_SHIM
from pip._vendor.distlib.scripts import ScriptMaker
from pip._vendor import pkg_resources
from pip._vendor.packaging.utils import canonicalize_name
from pip._vendor.six.moves import configparser
wheel_ext = '.whl'
VERSION_COMPATIBLE = (1, 0)
logger = logging.getLogger(__name__)
class WheelCache(object):
"""A cache of wheels for future installs."""
def __init__(self, cache_dir, format_control):
"""Create a wheel cache.
:param cache_dir: The root of the cache.
:param format_control: A pip.index.FormatControl object to limit
binaries being read from the cache.
"""
self._cache_dir = expanduser(cache_dir) if cache_dir else None
self._format_control = format_control
def cached_wheel(self, link, package_name):
return cached_wheel(
self._cache_dir, link, self._format_control, package_name)
def _cache_for_link(cache_dir, link):
"""
Return a directory to store cached wheels in for link.
Because there are M wheels for any one sdist, we provide a directory
to cache them in, and then consult that directory when looking up
cache hits.
We only insert things into the cache if they have plausible version
numbers, so that we don't contaminate the cache with things that were not
unique. E.g. ./package might have dozens of installs done for it and build
a version of 0.0...and if we built and cached a wheel, we'd end up using
the same wheel even if the source has been edited.
:param cache_dir: The cache_dir being used by pip.
:param link: The link of the sdist for which this will cache wheels.
"""
# We want to generate an url to use as our cache key, we don't want to just
# re-use the URL because it might have other items in the fragment and we
# don't care about those.
key_parts = [link.url_without_fragment]
if link.hash_name is not None and link.hash is not None:
key_parts.append("=".join([link.hash_name, link.hash]))
key_url = "#".join(key_parts)
# Encode our key url with sha224, we'll use this because it has similar
# security properties to sha256, but with a shorter total output (and thus
# less secure). However the differences don't make a lot of difference for
# our use case here.
hashed = hashlib.sha224(key_url.encode()).hexdigest()
# We want to nest the directories some to prevent having a ton of top level
# directories where we might run out of sub directories on some FS.
parts = [hashed[:2], hashed[2:4], hashed[4:6], hashed[6:]]
# Inside of the base location for cached wheels, expand our parts and join
# them all together.
return os.path.join(cache_dir, "wheels", *parts)
def cached_wheel(cache_dir, link, format_control, package_name):
if not cache_dir:
return link
if not link:
return link
if link.is_wheel:
return link
if not link.is_artifact:
return link
if not package_name:
return link
canonical_name = canonicalize_name(package_name)
formats = pip.index.fmt_ctl_formats(format_control, canonical_name)
if "binary" not in formats:
return link
root = _cache_for_link(cache_dir, link)
try:
wheel_names = os.listdir(root)
except OSError as e:
if e.errno in (errno.ENOENT, errno.ENOTDIR):
return link
raise
candidates = []
for wheel_name in wheel_names:
try:
wheel = Wheel(wheel_name)
except InvalidWheelFilename:
continue
if not wheel.supported():
# Built for a different python/arch/etc
continue
candidates.append((wheel.support_index_min(), wheel_name))
if not candidates:
return link
candidates.sort()
path = os.path.join(root, candidates[0][1])
return pip.index.Link(path_to_url(path))
def rehash(path, algo='sha256', blocksize=1 << 20):
"""Return (hash, length) for path using hashlib.new(algo)"""
h = hashlib.new(algo)
length = 0
with open(path, 'rb') as f:
for block in read_chunks(f, size=blocksize):
length += len(block)
h.update(block)
digest = 'sha256=' + urlsafe_b64encode(
h.digest()
).decode('latin1').rstrip('=')
return (digest, length)
def open_for_csv(name, mode):
if sys.version_info[0] < 3:
nl = {}
bin = 'b'
else:
nl = {'newline': ''}
bin = ''
return open(name, mode + bin, **nl)
def fix_script(path):
"""Replace #!python with #!/path/to/python
Return True if file was changed."""
# XXX RECORD hashes will need to be updated
if os.path.isfile(path):
with open(path, 'rb') as script:
firstline = script.readline()
if not firstline.startswith(b'#!python'):
return False
exename = sys.executable.encode(sys.getfilesystemencoding())
firstline = b'#!' + exename + os.linesep.encode("ascii")
rest = script.read()
with open(path, 'wb') as script:
script.write(firstline)
script.write(rest)
return True
dist_info_re = re.compile(r"""^(?P<namever>(?P<name>.+?)(-(?P<ver>\d.+?))?)
\.dist-info$""", re.VERBOSE)
def root_is_purelib(name, wheeldir):
"""
Return True if the extracted wheel in wheeldir should go into purelib.
"""
name_folded = name.replace("-", "_")
for item in os.listdir(wheeldir):
match = dist_info_re.match(item)
if match and match.group('name') == name_folded:
with open(os.path.join(wheeldir, item, 'WHEEL')) as wheel:
for line in wheel:
line = line.lower().rstrip()
if line == "root-is-purelib: true":
return True
return False
def get_entrypoints(filename):
if not os.path.exists(filename):
return {}, {}
# This is done because you can pass a string to entry_points wrappers which
# means that they may or may not be valid INI files. The attempt here is to
# strip leading and trailing whitespace in order to make them valid INI
# files.
with open(filename) as fp:
data = StringIO()
for line in fp:
data.write(line.strip())
data.write("\n")
data.seek(0)
cp = configparser.RawConfigParser()
cp.optionxform = lambda option: option
cp.readfp(data)
console = {}
gui = {}
if cp.has_section('console_scripts'):
console = dict(cp.items('console_scripts'))
if cp.has_section('gui_scripts'):
gui = dict(cp.items('gui_scripts'))
return console, gui
def move_wheel_files(name, req, wheeldir, user=False, home=None, root=None,
pycompile=True, scheme=None, isolated=False, prefix=None):
"""Install a wheel"""
if not scheme:
scheme = distutils_scheme(
name, user=user, home=home, root=root, isolated=isolated,
prefix=prefix,
)
if root_is_purelib(name, wheeldir):
lib_dir = scheme['purelib']
else:
lib_dir = scheme['platlib']
info_dir = []
data_dirs = []
source = wheeldir.rstrip(os.path.sep) + os.path.sep
# Record details of the files moved
# installed = files copied from the wheel to the destination
# changed = files changed while installing (scripts #! line typically)
# generated = files newly generated during the install (script wrappers)
installed = {}
changed = set()
generated = []
# Compile all of the pyc files that we're going to be installing
if pycompile:
with captured_stdout() as stdout:
with warnings.catch_warnings():
warnings.filterwarnings('ignore')
compileall.compile_dir(source, force=True, quiet=True)
logger.debug(stdout.getvalue())
def normpath(src, p):
return os.path.relpath(src, p).replace(os.path.sep, '/')
def record_installed(srcfile, destfile, modified=False):
"""Map archive RECORD paths to installation RECORD paths."""
oldpath = normpath(srcfile, wheeldir)
newpath = normpath(destfile, lib_dir)
installed[oldpath] = newpath
if modified:
changed.add(destfile)
def clobber(source, dest, is_base, fixer=None, filter=None):
ensure_dir(dest) # common for the 'include' path
for dir, subdirs, files in os.walk(source):
basedir = dir[len(source):].lstrip(os.path.sep)
destdir = os.path.join(dest, basedir)
if is_base and basedir.split(os.path.sep, 1)[0].endswith('.data'):
continue
for s in subdirs:
destsubdir = os.path.join(dest, basedir, s)
if is_base and basedir == '' and destsubdir.endswith('.data'):
data_dirs.append(s)
continue
elif (is_base and
s.endswith('.dist-info') and
# is self.req.project_name case preserving?
s.lower().startswith(
req.name.replace('-', '_').lower())):
assert not info_dir, ('Multiple .dist-info directories: ' +
destsubdir + ', ' +
', '.join(info_dir))
info_dir.append(destsubdir)
for f in files:
# Skip unwanted files
if filter and filter(f):
continue
srcfile = os.path.join(dir, f)
destfile = os.path.join(dest, basedir, f)
# directory creation is lazy and after the file filtering above
# to ensure we don't install empty dirs; empty dirs can't be
# uninstalled.
ensure_dir(destdir)
# We use copyfile (not move, copy, or copy2) to be extra sure
# that we are not moving directories over (copyfile fails for
# directories) as well as to ensure that we are not copying
# over any metadata because we want more control over what
# metadata we actually copy over.
shutil.copyfile(srcfile, destfile)
# Copy over the metadata for the file, currently this only
# includes the atime and mtime.
st = os.stat(srcfile)
if hasattr(os, "utime"):
os.utime(destfile, (st.st_atime, st.st_mtime))
# If our file is executable, then make our destination file
# executable.
if os.access(srcfile, os.X_OK):
st = os.stat(srcfile)
permissions = (
st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
)
os.chmod(destfile, permissions)
changed = False
if fixer:
changed = fixer(destfile)
record_installed(srcfile, destfile, changed)
clobber(source, lib_dir, True)
assert info_dir, "%s .dist-info directory not found" % req
# Get the defined entry points
ep_file = os.path.join(info_dir[0], 'entry_points.txt')
console, gui = get_entrypoints(ep_file)
def is_entrypoint_wrapper(name):
# EP, EP.exe and EP-script.py are scripts generated for
# entry point EP by setuptools
if name.lower().endswith('.exe'):
matchname = name[:-4]
elif name.lower().endswith('-script.py'):
matchname = name[:-10]
elif name.lower().endswith(".pya"):
matchname = name[:-4]
else:
matchname = name
# Ignore setuptools-generated scripts
return (matchname in console or matchname in gui)
for datadir in data_dirs:
fixer = None
filter = None
for subdir in os.listdir(os.path.join(wheeldir, datadir)):
fixer = None
if subdir == 'scripts':
fixer = fix_script
filter = is_entrypoint_wrapper
source = os.path.join(wheeldir, datadir, subdir)
dest = scheme[subdir]
clobber(source, dest, False, fixer=fixer, filter=filter)
maker = ScriptMaker(None, scheme['scripts'])
# Ensure old scripts are overwritten.
# See https://github.com/pypa/pip/issues/1800
maker.clobber = True
# Ensure we don't generate any variants for scripts because this is almost
# never what somebody wants.
# See https://bitbucket.org/pypa/distlib/issue/35/
maker.variants = set(('', ))
# This is required because otherwise distlib creates scripts that are not
# executable.
# See https://bitbucket.org/pypa/distlib/issue/32/
maker.set_mode = True
# Simplify the script and fix the fact that the default script swallows
# every single stack trace.
# See https://bitbucket.org/pypa/distlib/issue/34/
# See https://bitbucket.org/pypa/distlib/issue/33/
def _get_script_text(entry):
if entry.suffix is None:
raise InstallationError(
"Invalid script entry point: %s for req: %s - A callable "
"suffix is required. Cf https://packaging.python.org/en/"
"latest/distributing.html#console-scripts for more "
"information." % (entry, req)
)
return maker.script_template % {
"module": entry.prefix,
"import_name": entry.suffix.split(".")[0],
"func": entry.suffix,
}
maker._get_script_text = _get_script_text
maker.script_template = """# -*- coding: utf-8 -*-
import re
import sys
from %(module)s import %(import_name)s
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(%(func)s())
"""
# Special case pip and setuptools to generate versioned wrappers
#
# The issue is that some projects (specifically, pip and setuptools) use
# code in setup.py to create "versioned" entry points - pip2.7 on Python
# 2.7, pip3.3 on Python 3.3, etc. But these entry points are baked into
# the wheel metadata at build time, and so if the wheel is installed with
# a *different* version of Python the entry points will be wrong. The
# correct fix for this is to enhance the metadata to be able to describe
# such versioned entry points, but that won't happen till Metadata 2.0 is
# available.
# In the meantime, projects using versioned entry points will either have
# incorrect versioned entry points, or they will not be able to distribute
# "universal" wheels (i.e., they will need a wheel per Python version).
#
# Because setuptools and pip are bundled with _ensurepip and virtualenv,
# we need to use universal wheels. So, as a stopgap until Metadata 2.0, we
# override the versioned entry points in the wheel and generate the
# correct ones. This code is purely a short-term measure until Metadat 2.0
# is available.
#
# To add the level of hack in this section of code, in order to support
# ensurepip this code will look for an ``ENSUREPIP_OPTIONS`` environment
# variable which will control which version scripts get installed.
#
# ENSUREPIP_OPTIONS=altinstall
# - Only pipX.Y and easy_install-X.Y will be generated and installed
# ENSUREPIP_OPTIONS=install
# - pipX.Y, pipX, easy_install-X.Y will be generated and installed. Note
# that this option is technically if ENSUREPIP_OPTIONS is set and is
# not altinstall
# DEFAULT
# - The default behavior is to install pip, pipX, pipX.Y, easy_install
# and easy_install-X.Y.
pip_script = console.pop('pip', None)
if pip_script:
if "ENSUREPIP_OPTIONS" not in os.environ:
spec = 'pip = ' + pip_script
generated.extend(maker.make(spec))
if os.environ.get("ENSUREPIP_OPTIONS", "") != "altinstall":
spec = 'pip%s = %s' % (sys.version[:1], pip_script)
generated.extend(maker.make(spec))
spec = 'pip%s = %s' % (sys.version[:3], pip_script)
generated.extend(maker.make(spec))
# Delete any other versioned pip entry points
pip_ep = [k for k in console if re.match(r'pip(\d(\.\d)?)?$', k)]
for k in pip_ep:
del console[k]
easy_install_script = console.pop('easy_install', None)
if easy_install_script:
if "ENSUREPIP_OPTIONS" not in os.environ:
spec = 'easy_install = ' + easy_install_script
generated.extend(maker.make(spec))
spec = 'easy_install-%s = %s' % (sys.version[:3], easy_install_script)
generated.extend(maker.make(spec))
# Delete any other versioned easy_install entry points
easy_install_ep = [
k for k in console if re.match(r'easy_install(-\d\.\d)?$', k)
]
for k in easy_install_ep:
del console[k]
# Generate the console and GUI entry points specified in the wheel
if len(console) > 0:
generated.extend(
maker.make_multiple(['%s = %s' % kv for kv in console.items()])
)
if len(gui) > 0:
generated.extend(
maker.make_multiple(
['%s = %s' % kv for kv in gui.items()],
{'gui': True}
)
)
# Record pip as the installer
installer = os.path.join(info_dir[0], 'INSTALLER')
temp_installer = os.path.join(info_dir[0], 'INSTALLER.pip')
with open(temp_installer, 'wb') as installer_file:
installer_file.write(b'pip\n')
shutil.move(temp_installer, installer)
generated.append(installer)
# Record details of all files installed
record = os.path.join(info_dir[0], 'RECORD')
temp_record = os.path.join(info_dir[0], 'RECORD.pip')
with open_for_csv(record, 'r') as record_in:
with open_for_csv(temp_record, 'w+') as record_out:
reader = csv.reader(record_in)
writer = csv.writer(record_out)
for row in reader:
row[0] = installed.pop(row[0], row[0])
if row[0] in changed:
row[1], row[2] = rehash(row[0])
writer.writerow(row)
for f in generated:
h, l = rehash(f)
writer.writerow((normpath(f, lib_dir), h, l))
for f in installed:
writer.writerow((installed[f], '', ''))
shutil.move(temp_record, record)
def _unique(fn):
@functools.wraps(fn)
def unique(*args, **kw):
seen = set()
for item in fn(*args, **kw):
if item not in seen:
seen.add(item)
yield item
return unique
# TODO: this goes somewhere besides the wheel module
@_unique
def uninstallation_paths(dist):
"""
Yield all the uninstallation paths for dist based on RECORD-without-.pyc
Yield paths to all the files in RECORD. For each .py file in RECORD, add
the .pyc in the same directory.
UninstallPathSet.add() takes care of the __pycache__ .pyc.
"""
from pip.utils import FakeFile # circular import
r = csv.reader(FakeFile(dist.get_metadata_lines('RECORD')))
for row in r:
path = os.path.join(dist.location, row[0])
yield path
if path.endswith('.py'):
dn, fn = os.path.split(path)
base = fn[:-3]
path = os.path.join(dn, base + '.pyc')
yield path
def wheel_version(source_dir):
"""
Return the Wheel-Version of an extracted wheel, if possible.
Otherwise, return False if we couldn't parse / extract it.
"""
try:
dist = [d for d in pkg_resources.find_on_path(None, source_dir)][0]
wheel_data = dist.get_metadata('WHEEL')
wheel_data = Parser().parsestr(wheel_data)
version = wheel_data['Wheel-Version'].strip()
version = tuple(map(int, version.split('.')))
return version
except:
return False
def check_compatibility(version, name):
"""
Raises errors or warns if called with an incompatible Wheel-Version.
Pip should refuse to install a Wheel-Version that's a major series
ahead of what it's compatible with (e.g 2.0 > 1.1); and warn when
installing a version only minor version ahead (e.g 1.2 > 1.1).
version: a 2-tuple representing a Wheel-Version (Major, Minor)
name: name of wheel or package to raise exception about
:raises UnsupportedWheel: when an incompatible Wheel-Version is given
"""
if not version:
raise UnsupportedWheel(
"%s is in an unsupported or invalid wheel" % name
)
if version[0] > VERSION_COMPATIBLE[0]:
raise UnsupportedWheel(
"%s's Wheel-Version (%s) is not compatible with this version "
"of pip" % (name, '.'.join(map(str, version)))
)
elif version > VERSION_COMPATIBLE:
logger.warning(
'Installing from a newer Wheel-Version (%s)',
'.'.join(map(str, version)),
)
class Wheel(object):
"""A wheel file"""
# TODO: maybe move the install code into this class
wheel_file_re = re.compile(
r"""^(?P<namever>(?P<name>.+?)-(?P<ver>\d.*?))
((-(?P<build>\d.*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)
\.whl|\.dist-info)$""",
re.VERBOSE
)
def __init__(self, filename):
"""
:raises InvalidWheelFilename: when the filename is invalid for a wheel
"""
wheel_info = self.wheel_file_re.match(filename)
if not wheel_info:
raise InvalidWheelFilename(
"%s is not a valid wheel filename." % filename
)
self.filename = filename
self.name = wheel_info.group('name').replace('_', '-')
# we'll assume "_" means "-" due to wheel naming scheme
# (https://github.com/pypa/pip/issues/1150)
self.version = wheel_info.group('ver').replace('_', '-')
self.pyversions = wheel_info.group('pyver').split('.')
self.abis = wheel_info.group('abi').split('.')
self.plats = wheel_info.group('plat').split('.')
# All the tag combinations from this file
self.file_tags = set(
(x, y, z) for x in self.pyversions
for y in self.abis for z in self.plats
)
def support_index_min(self, tags=None):
"""
Return the lowest index that one of the wheel's file_tag combinations
achieves in the supported_tags list e.g. if there are 8 supported tags,
and one of the file tags is first in the list, then return 0. Returns
None is the wheel is not supported.
"""
if tags is None: # for mock
tags = pep425tags.supported_tags
indexes = [tags.index(c) for c in self.file_tags if c in tags]
return min(indexes) if indexes else None
def supported(self, tags=None):
"""Is this wheel supported on this system?"""
if tags is None: # for mock
tags = pep425tags.supported_tags
return bool(set(tags).intersection(self.file_tags))
class WheelBuilder(object):
"""Build wheels from a RequirementSet."""
def __init__(self, requirement_set, finder, build_options=None,
global_options=None):
self.requirement_set = requirement_set
self.finder = finder
self._cache_root = requirement_set._wheel_cache._cache_dir
self._wheel_dir = requirement_set.wheel_download_dir
self.build_options = build_options or []
self.global_options = global_options or []
def _build_one(self, req, output_dir, python_tag=None):
"""Build one wheel.
:return: The filename of the built wheel, or None if the build failed.
"""
tempd = tempfile.mkdtemp('pip-wheel-')
try:
if self.__build_one(req, tempd, python_tag=python_tag):
try:
wheel_name = os.listdir(tempd)[0]
wheel_path = os.path.join(output_dir, wheel_name)
shutil.move(os.path.join(tempd, wheel_name), wheel_path)
logger.info('Stored in directory: %s', output_dir)
return wheel_path
except:
pass
# Ignore return, we can't do anything else useful.
self._clean_one(req)
return None
finally:
rmtree(tempd)
def _base_setup_args(self, req):
return [
sys.executable, "-u", '-c',
SETUPTOOLS_SHIM % req.setup_py
] + list(self.global_options)
def __build_one(self, req, tempd, python_tag=None):
base_args = self._base_setup_args(req)
spin_message = 'Running setup.py bdist_wheel for %s' % (req.name,)
with open_spinner(spin_message) as spinner:
logger.debug('Destination directory: %s', tempd)
wheel_args = base_args + ['bdist_wheel', '-d', tempd] \
+ self.build_options
if python_tag is not None:
wheel_args += ["--python-tag", python_tag]
try:
call_subprocess(wheel_args, cwd=req.setup_py_dir,
show_stdout=False, spinner=spinner)
return True
except:
spinner.finish("error")
logger.error('Failed building wheel for %s', req.name)
return False
def _clean_one(self, req):
base_args = self._base_setup_args(req)
logger.info('Running setup.py clean for %s', req.name)
clean_args = base_args + ['clean', '--all']
try:
call_subprocess(clean_args, cwd=req.source_dir, show_stdout=False)
return True
except:
logger.error('Failed cleaning build dir for %s', req.name)
return False
def build(self, autobuilding=False):
"""Build wheels.
:param unpack: If True, replace the sdist we built from with the
newly built wheel, in preparation for installation.
:return: True if all the wheels built correctly.
"""
assert self._wheel_dir or (autobuilding and self._cache_root)
# unpack sdists and constructs req set
self.requirement_set.prepare_files(self.finder)
reqset = self.requirement_set.requirements.values()
buildset = []
for req in reqset:
if req.constraint:
continue
if req.is_wheel:
if not autobuilding:
logger.info(
'Skipping %s, due to already being wheel.', req.name)
elif req.editable:
if not autobuilding:
logger.info(
'Skipping bdist_wheel for %s, due to being editable',
req.name)
elif autobuilding and req.link and not req.link.is_artifact:
pass
elif autobuilding and not req.source_dir:
pass
else:
if autobuilding:
link = req.link
base, ext = link.splitext()
if pip.index.egg_info_matches(base, None, link) is None:
# Doesn't look like a package - don't autobuild a wheel
# because we'll have no way to lookup the result sanely
continue
if "binary" not in pip.index.fmt_ctl_formats(
self.finder.format_control,
canonicalize_name(req.name)):
logger.info(
"Skipping bdist_wheel for %s, due to binaries "
"being disabled for it.", req.name)
continue
buildset.append(req)
if not buildset:
return True
# Build the wheels.
logger.info(
'Building wheels for collected packages: %s',
', '.join([req.name for req in buildset]),
)
with indent_log():
build_success, build_failure = [], []
for req in buildset:
python_tag = None
if autobuilding:
python_tag = pep425tags.implementation_tag
output_dir = _cache_for_link(self._cache_root, req.link)
try:
ensure_dir(output_dir)
except OSError as e:
logger.warning("Building wheel for %s failed: %s",
req.name, e)
build_failure.append(req)
continue
else:
output_dir = self._wheel_dir
wheel_file = self._build_one(
req, output_dir,
python_tag=python_tag,
)
if wheel_file:
build_success.append(req)
if autobuilding:
# XXX: This is mildly duplicative with prepare_files,
# but not close enough to pull out to a single common
# method.
# The code below assumes temporary source dirs -
# prevent it doing bad things.
if req.source_dir and not os.path.exists(os.path.join(
req.source_dir, PIP_DELETE_MARKER_FILENAME)):
raise AssertionError(
"bad source dir - missing marker")
# Delete the source we built the wheel from
req.remove_temporary_source()
# set the build directory again - name is known from
# the work prepare_files did.
req.source_dir = req.build_location(
self.requirement_set.build_dir)
# Update the link for this.
req.link = pip.index.Link(
path_to_url(wheel_file))
assert req.link.is_wheel
# extract the wheel into the dir
unpack_url(
req.link, req.source_dir, None, False,
session=self.requirement_set.session)
else:
build_failure.append(req)
# notify success/failure
if build_success:
logger.info(
'Successfully built %s',
' '.join([req.name for req in build_success]),
)
if build_failure:
logger.info(
'Failed to build %s',
' '.join([req.name for req in build_failure]),
)
# Return True if all builds were successful
return len(build_failure) == 0
|
gpl-3.0
|
[
624,
199,
11532,
367,
22200,
436,
10015,
314,
298,
11798,
2,
3366,
2559,
1475,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
6555,
452,
199,
646,
7392,
199,
646,
7554,
199,
646,
9143,
199,
646,
8337,
199,
646,
2050,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
5145,
199,
646,
5672,
199,
646,
984,
199,
646,
5549,
199,
646,
3598,
199,
199,
504,
1300,
772,
492,
8187,
6504,
63,
66,
772,
2143,
199,
504,
3031,
14,
2087,
492,
10191,
199,
199,
504,
7305,
423,
9884,
14,
4174,
492,
5228,
199,
199,
646,
7305,
199,
504,
7305,
14,
5819,
492,
6544,
751,
199,
504,
7305,
14,
4249,
492,
931,
63,
475,
63,
633,
12,
7787,
63,
633,
199,
504,
7305,
14,
3924,
492,
334,
272,
26866,
547,
12,
6378,
25663,
8117,
12,
19022,
25663,
9,
199,
504,
7305,
14,
8022,
492,
7065,
63,
5512,
12,
510,
1772,
63,
7014,
63,
18997,
63,
15440,
199,
504,
7305,
492,
22602,
24398,
2969,
199,
504,
7305,
14,
1208,
492,
334,
272,
1240,
63,
5781,
12,
4868,
63,
694,
12,
17487,
63,
2703,
12,
20978,
12,
1586,
63,
10660,
12,
199,
9,
199,
504,
7305,
14,
1208,
14,
1907,
492,
1551,
63,
681,
5216,
199,
504,
7305,
14,
1208,
14,
4806,
492,
4363,
63,
793,
199,
504,
7305,
14,
1208,
14,
13623,
63,
1506,
492,
11543,
2160,
20261,
63,
3234,
1469,
199,
504,
7305,
423,
9884,
14,
2686,
773,
14,
6429,
492,
14914,
23560,
199,
504,
7305,
423,
9884,
492,
5496,
63,
4435,
199,
504,
7305,
423,
9884,
14,
27796,
14,
1208,
492,
11358,
794,
63,
354,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
492,
21230,
421,
199,
11798,
63,
832,
275,
1987,
2191,
76,
7,
199,
199,
4612,
63,
29720,
7187,
275,
334,
17,
12,
378,
9,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
26161,
4437,
8,
785,
304,
272,
408,
33,
2581,
402,
28300,
367,
6466,
25801,
1041,
339,
347,
636,
826,
721,
277,
12,
2581,
63,
694,
12,
1475,
63,
2785,
304,
267,
408,
2499,
282,
9989,
2581,
14,
398,
520,
635,
2581,
63,
694,
26,
710,
1738,
402,
314,
2581,
14,
267,
520,
635,
1475,
63,
2785,
26,
437,
7305,
14,
1080,
14,
3484,
3717,
909,
370,
2304,
288,
21984,
3769,
1586,
687,
314,
2581,
14,
267,
408,
267,
291,
423,
1637,
63,
694,
275,
6544,
751,
8,
1637,
63,
694,
9,
340,
2581,
63,
694,
587,
488,
267,
291,
423,
908,
63,
2785,
275,
1475,
63,
2785,
339,
347,
6328,
63,
11798,
8,
277,
12,
2142,
12,
2559,
63,
354,
304,
267,
372,
6328,
63,
11798,
8,
288,
291,
423,
1637,
63,
694,
12,
2142,
12,
291,
423,
908,
63,
2785,
12,
2559,
63,
354,
9,
421,
199,
318,
485,
1637,
63,
509,
63,
1073,
8,
1637,
63,
694,
12,
2142,
304,
272,
408,
272,
1432,
282,
2082,
370,
3877,
6328,
28300,
315,
367,
2142,
14,
339,
13821,
2337,
787,
603,
28300,
367,
1263,
1373,
26644,
12,
781,
5647,
282,
2082,
272,
370,
2581,
3062,
315,
12,
436,
2066,
13447,
427,
626,
2082,
1380,
10023,
1536,
272,
2581,
19745,
14,
339,
2136,
1454,
5518,
7645,
1901,
314,
2581,
340,
2985,
1172,
299,
416,
85,
1164,
1015,
272,
5579,
12,
880,
626,
781,
2793,
1133,
13770,
455,
23043,
314,
2581,
543,
7645,
626,
4898,
440,
272,
3747,
14,
662,
14,
71,
14,
16605,
2491,
5594,
1172,
886,
5193,
83,
402,
25801,
4224,
367,
652,
436,
1900,
272,
282,
1015,
402,
378,
14,
16,
1396,
460,
340,
781,
6137,
436,
6328,
282,
9989,
12,
781,
5121,
1284,
1536,
1808,
272,
314,
2011,
9989,
2755,
340,
314,
1350,
965,
2757,
21062,
14,
339,
520,
635,
2581,
63,
694,
26,
710,
2581,
63,
694,
3769,
1202,
701,
7305,
14,
272,
520,
635,
2142,
26,
710,
2142,
402,
314,
26644,
367,
1314,
642,
911,
2581,
28300,
14,
272,
408,
339,
327,
2136,
2934,
370,
3550,
376,
1166,
370,
675,
465,
4154,
2581,
790,
12,
781,
2793,
1133,
2934,
370,
2951,
272,
327,
295,
13,
1180,
314,
2851,
2952,
652,
5594,
1172,
1163,
2974,
315,
314,
7956,
436,
781,
272,
327,
2793,
1133,
10296,
3595,
5204,
14,
272,
790,
63,
4181,
275,
359,
1073,
14,
633,
63,
7395,
63,
7677,
61,
272,
340,
2142,
14,
2227,
63,
354,
365,
440,
488,
436,
2142,
14,
2227,
365,
440,
488,
26,
267,
790,
63,
4181,
14,
740,
480,
25356,
904,
779,
1073,
14,
2227,
63,
354,
12,
2142,
14,
2227,
2459,
272,
790,
63,
633,
275,
5426,
1674,
904,
8,
498,
63,
4181,
9,
339,
327,
19244,
4154,
790,
1166,
543,
7793,
8731,
12,
781,
7171,
675,
642,
2952,
652,
965,
8545,
272,
327,
6391,
4382,
370,
7793,
3912,
12,
1325,
543,
282,
18299,
3141,
1072,
334,
460,
12850,
272,
327,
6656,
11153,
680,
9738,
314,
15109,
2793,
1133,
1852,
282,
13918,
402,
8865,
367,
272,
327,
4154,
675,
1930,
2348,
14,
272,
19871,
275,
8337,
14,
4835,
8731,
8,
498,
63,
633,
14,
2143,
8801,
11453,
342,
339,
327,
2136,
2934,
370,
10715,
314,
6602,
2005,
370,
7981,
9445,
282,
307,
265,
402,
2746,
2166,
272,
327,
6602,
2382,
781,
5594,
1255,
734,
402,
1007,
6602,
641,
2005,
27500,
14,
272,
4184,
275,
359,
26368,
1491,
18,
467,
19871,
59,
18,
26,
20,
467,
19871,
59,
20,
26,
22,
467,
19871,
59,
22,
21316,
339,
327,
1010,
2441,
402,
314,
1300,
2909,
367,
6328,
28300,
12,
6544,
4154,
4184,
436,
4263,
272,
327,
3062,
1006,
10451,
14,
272,
372,
747,
14,
515,
14,
904,
8,
1637,
63,
694,
12,
298,
11798,
83,
401,
627,
4181,
9,
421,
199,
318,
6328,
63,
11798,
8,
1637,
63,
694,
12,
2142,
12,
1475,
63,
2785,
12,
2559,
63,
354,
304,
272,
340,
440,
2581,
63,
694,
26,
267,
372,
2142,
272,
340,
440,
2142,
26,
267,
372,
2142,
272,
340,
2142,
14,
374,
63,
11798,
26,
267,
372,
2142,
272,
340,
440,
2142,
14,
374,
63,
16154,
26,
267,
372,
2142,
272,
340,
440,
2559,
63,
354,
26,
267,
372,
2142,
272,
11358,
63,
354,
275,
11358,
794,
63,
354,
8,
2491,
63,
354
] |
[
199,
11532,
367,
22200,
436,
10015,
314,
298,
11798,
2,
3366,
2559,
1475,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
6555,
452,
199,
646,
7392,
199,
646,
7554,
199,
646,
9143,
199,
646,
8337,
199,
646,
2050,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
5145,
199,
646,
5672,
199,
646,
984,
199,
646,
5549,
199,
646,
3598,
199,
199,
504,
1300,
772,
492,
8187,
6504,
63,
66,
772,
2143,
199,
504,
3031,
14,
2087,
492,
10191,
199,
199,
504,
7305,
423,
9884,
14,
4174,
492,
5228,
199,
199,
646,
7305,
199,
504,
7305,
14,
5819,
492,
6544,
751,
199,
504,
7305,
14,
4249,
492,
931,
63,
475,
63,
633,
12,
7787,
63,
633,
199,
504,
7305,
14,
3924,
492,
334,
272,
26866,
547,
12,
6378,
25663,
8117,
12,
19022,
25663,
9,
199,
504,
7305,
14,
8022,
492,
7065,
63,
5512,
12,
510,
1772,
63,
7014,
63,
18997,
63,
15440,
199,
504,
7305,
492,
22602,
24398,
2969,
199,
504,
7305,
14,
1208,
492,
334,
272,
1240,
63,
5781,
12,
4868,
63,
694,
12,
17487,
63,
2703,
12,
20978,
12,
1586,
63,
10660,
12,
199,
9,
199,
504,
7305,
14,
1208,
14,
1907,
492,
1551,
63,
681,
5216,
199,
504,
7305,
14,
1208,
14,
4806,
492,
4363,
63,
793,
199,
504,
7305,
14,
1208,
14,
13623,
63,
1506,
492,
11543,
2160,
20261,
63,
3234,
1469,
199,
504,
7305,
423,
9884,
14,
2686,
773,
14,
6429,
492,
14914,
23560,
199,
504,
7305,
423,
9884,
492,
5496,
63,
4435,
199,
504,
7305,
423,
9884,
14,
27796,
14,
1208,
492,
11358,
794,
63,
354,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
492,
21230,
421,
199,
11798,
63,
832,
275,
1987,
2191,
76,
7,
199,
199,
4612,
63,
29720,
7187,
275,
334,
17,
12,
378,
9,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
26161,
4437,
8,
785,
304,
272,
408,
33,
2581,
402,
28300,
367,
6466,
25801,
1041,
339,
347,
636,
826,
721,
277,
12,
2581,
63,
694,
12,
1475,
63,
2785,
304,
267,
408,
2499,
282,
9989,
2581,
14,
398,
520,
635,
2581,
63,
694,
26,
710,
1738,
402,
314,
2581,
14,
267,
520,
635,
1475,
63,
2785,
26,
437,
7305,
14,
1080,
14,
3484,
3717,
909,
370,
2304,
288,
21984,
3769,
1586,
687,
314,
2581,
14,
267,
408,
267,
291,
423,
1637,
63,
694,
275,
6544,
751,
8,
1637,
63,
694,
9,
340,
2581,
63,
694,
587,
488,
267,
291,
423,
908,
63,
2785,
275,
1475,
63,
2785,
339,
347,
6328,
63,
11798,
8,
277,
12,
2142,
12,
2559,
63,
354,
304,
267,
372,
6328,
63,
11798,
8,
288,
291,
423,
1637,
63,
694,
12,
2142,
12,
291,
423,
908,
63,
2785,
12,
2559,
63,
354,
9,
421,
199,
318,
485,
1637,
63,
509,
63,
1073,
8,
1637,
63,
694,
12,
2142,
304,
272,
408,
272,
1432,
282,
2082,
370,
3877,
6328,
28300,
315,
367,
2142,
14,
339,
13821,
2337,
787,
603,
28300,
367,
1263,
1373,
26644,
12,
781,
5647,
282,
2082,
272,
370,
2581,
3062,
315,
12,
436,
2066,
13447,
427,
626,
2082,
1380,
10023,
1536,
272,
2581,
19745,
14,
339,
2136,
1454,
5518,
7645,
1901,
314,
2581,
340,
2985,
1172,
299,
416,
85,
1164,
1015,
272,
5579,
12,
880,
626,
781,
2793,
1133,
13770,
455,
23043,
314,
2581,
543,
7645,
626,
4898,
440,
272,
3747,
14,
662,
14,
71,
14,
16605,
2491,
5594,
1172,
886,
5193,
83,
402,
25801,
4224,
367,
652,
436,
1900,
272,
282,
1015,
402,
378,
14,
16,
1396,
460,
340,
781,
6137,
436,
6328,
282,
9989,
12,
781,
5121,
1284,
1536,
1808,
272,
314,
2011,
9989,
2755,
340,
314,
1350,
965,
2757,
21062,
14,
339,
520,
635,
2581,
63,
694,
26,
710,
2581,
63,
694,
3769,
1202,
701,
7305,
14,
272,
520,
635,
2142,
26,
710,
2142,
402,
314,
26644,
367,
1314,
642,
911,
2581,
28300,
14,
272,
408,
339,
327,
2136,
2934,
370,
3550,
376,
1166,
370,
675,
465,
4154,
2581,
790,
12,
781,
2793,
1133,
2934,
370,
2951,
272,
327,
295,
13,
1180,
314,
2851,
2952,
652,
5594,
1172,
1163,
2974,
315,
314,
7956,
436,
781,
272,
327,
2793,
1133,
10296,
3595,
5204,
14,
272,
790,
63,
4181,
275,
359,
1073,
14,
633,
63,
7395,
63,
7677,
61,
272,
340,
2142,
14,
2227,
63,
354,
365,
440,
488,
436,
2142,
14,
2227,
365,
440,
488,
26,
267,
790,
63,
4181,
14,
740,
480,
25356,
904,
779,
1073,
14,
2227,
63,
354,
12,
2142,
14,
2227,
2459,
272,
790,
63,
633,
275,
5426,
1674,
904,
8,
498,
63,
4181,
9,
339,
327,
19244,
4154,
790,
1166,
543,
7793,
8731,
12,
781,
7171,
675,
642,
2952,
652,
965,
8545,
272,
327,
6391,
4382,
370,
7793,
3912,
12,
1325,
543,
282,
18299,
3141,
1072,
334,
460,
12850,
272,
327,
6656,
11153,
680,
9738,
314,
15109,
2793,
1133,
1852,
282,
13918,
402,
8865,
367,
272,
327,
4154,
675,
1930,
2348,
14,
272,
19871,
275,
8337,
14,
4835,
8731,
8,
498,
63,
633,
14,
2143,
8801,
11453,
342,
339,
327,
2136,
2934,
370,
10715,
314,
6602,
2005,
370,
7981,
9445,
282,
307,
265,
402,
2746,
2166,
272,
327,
6602,
2382,
781,
5594,
1255,
734,
402,
1007,
6602,
641,
2005,
27500,
14,
272,
4184,
275,
359,
26368,
1491,
18,
467,
19871,
59,
18,
26,
20,
467,
19871,
59,
20,
26,
22,
467,
19871,
59,
22,
21316,
339,
327,
1010,
2441,
402,
314,
1300,
2909,
367,
6328,
28300,
12,
6544,
4154,
4184,
436,
4263,
272,
327,
3062,
1006,
10451,
14,
272,
372,
747,
14,
515,
14,
904,
8,
1637,
63,
694,
12,
298,
11798,
83,
401,
627,
4181,
9,
421,
199,
318,
6328,
63,
11798,
8,
1637,
63,
694,
12,
2142,
12,
1475,
63,
2785,
12,
2559,
63,
354,
304,
272,
340,
440,
2581,
63,
694,
26,
267,
372,
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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
] |
tectronics/openmalaria-git
|
util/compareOutput.py
|
1
|
7178
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# This file is part of OpenMalaria.
#
# Copyright (C) 2005-2010 Swiss Tropical Institute and Liverpool School Of Tropical Medicine
#
# OpenMalaria is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import sys
import math
from optparse import OptionParser
from approxEqual import ApproxSame
from readOutput import readEntries
REL_PRECISION=1e-6
ABS_PRECISION=1e-6
def charEqual (fn1,fn2):
MAX=10*1024
f1 = open(fn1,'r')
f2 = open(fn2,'r')
while True:
s1 = f1.read(MAX)
s2 = f2.read(MAX)
if (len(s1)==0) or (len(s2)==0):
# end of one or both files; equal if it's the end of both
return len(s1) == len(s2)
if s1 != s2:
return False
def main(fn1,fn2,maxDiffsToPrint=6):
"""Takes names of the two files to compare and optionally an argument describing
the maximum number of differences to print directly (note: order is not intuitive).
Returns a tuple ret,ident; ret is 0 if test passes (output considered near-enough equal),
ident is 1 if files are binary-equal."""
ret=0
opt=""
if REL_PRECISION!=1e-6:
opt+=" --rel-prescision="+str(REL_PRECISION)
if ABS_PRECISION!=1e-6:
opt+=" --abs-prescision="+str(ABS_PRECISION)
print "\033[1;34m compareOutput.py"+opt+" "+fn1+" "+fn2+" "+str(maxDiffsToPrint)+"\033[0;0m"
# Read both files and combine into a map of key to pairs (v1, v2)
try:
if charEqual (fn1,fn2):
print "output.txt files are identical"
return 0,True
print "output.txt files aren't binary-equal"
values1=readEntries(fn1)
values2=readEntries(fn2)
# python 3000 syntax is "except IOError as e", backported to 2.6 but not always supported. Old syntax:
except IOError, e:
print str(e)
return 1,False
values=dict()
for (k,v1) in values1.iteritems():
v2=None
if (k in values2):
v2=values2[k]
del values2[k]
values[k] = (v1,v2)
for (k,v2) in values2.iteritems():
values[k] = (None,v2)
# Go through all values:
numPrinted=0
numDiffs=0
numMissing1=0
numMissing2=0
perMeasureNum = dict()
perMeasureTotal1 = dict()
perMeasureTotal2 = dict()
perMeasureNumDiff = dict()
perMeasureDiffSum = dict()
perMeasureDiffAbsSum = dict()
approxSame = ApproxSame(REL_PRECISION, ABS_PRECISION)
for (k,(v1,v2)) in values.iteritems():
if v1==None:
numMissing1 += 1
elif v2==None:
numMissing2 += 1
else:
perMeasureNum[k.a] = perMeasureNum.get(k.a, 0) + 1
perMeasureTotal1[k.a] = perMeasureTotal1.get(k.a, 0.0) + v1
perMeasureTotal2[k.a] = perMeasureTotal2.get(k.a, 0.0) + v2
# Compare with relative precision
if approxSame (v1, v2):
continue
numDiffs += 1
# Sum up total difference per measure
perMeasureDiffSum[k.a] = perMeasureDiffSum.get(k.a,0.0) + v2 - v1
perMeasureDiffAbsSum[k.a] = perMeasureDiffAbsSum.get(k.a,0.0) + math.fabs(v2-v1)
numPrinted += 1
perMeasureNumDiff[k.a] = perMeasureNumDiff.get(k.a,0) + 1;
if (numPrinted <= maxDiffsToPrint):
print "survey "+str(k.b)+", group "+str(k.c)+", measure "+str(k.a)+": "+str(v1)+" -> "+str(v2)
if (numPrinted == maxDiffsToPrint):
print "[won't print any more line-by-line diffs]"
if (numMissing1 > 0) or (numMissing2 > 0):
print str(numMissing1) + " entries missing from first file, " + str(numMissing2) +" from second"
ret = 3
maxDiffSum=0.0
maxAbsDiffSum=0.0
for (k.a,absDiff) in perMeasureDiffAbsSum.iteritems():
if not (absDiff <= 1e-6): # handle NANs
# standard division throws on divide-by-zero, which I don't want
def div(x,y):
try:
return x/y
except ZeroDivisionError:
return 1e400 * 0 # nan
diff=perMeasureDiffSum[k.a]
sum1=perMeasureTotal1[k.a]
sum2=perMeasureTotal2[k.a]
diffSum=div(diff,sum1)
maxDiffSum=max(maxDiffSum,math.fabs(diffSum))
absDiffSum=div(absDiff,sum1)
maxAbsDiffSum=max(maxAbsDiffSum,absDiffSum)
print "for measure "+str(k.a)+":\tsum(1st file):"+str(sum1)+"\tsum(2nd file):"+str(sum2)+"\tdiff/sum: "+str(diffSum)+"\t(abs diff)/sum: "+str(absDiffSum)
if maxDiffSum>0 or maxAbsDiffSum>0:
print "Max diff/sum:",maxDiffSum,"max (abs diff)/sum:",maxAbsDiffSum
if numDiffs == 0:
print "No significant differences (total relative diff: "+str(approxSame.getTotalRelDiff())+"), ok."
return ret,False
else:
print "\033[1;31m"+str(numDiffs)+" significant differences (total relative diff: "+str(approxSame.getTotalRelDiff())+ ")!\033[0;0m"
return 1,False
# Test for options
def evalOptions (args):
parser = OptionParser(usage="Usage: %prog [options] logfile1 logfile2 [max different lines to print]",
# damn reformatting into a single paragraph: this doesn't get printed very nicely when --help is invoked
description="""Compare logfile1 and logfile2 for differences, returning a measure of difference.
See http://code.google.com/p/openmalaria/wiki/UtilsRunScripts#compareOutput.py for details on output.""")
parser.add_option("-R","--rel-precision",
action="store", dest="rel_precision", type="float",
help="Set relative precision (default: 1.0e-6)")
parser.add_option("-A","--abs-precision",
action="store", dest="abs_precision", type="float",
help="Set absolute precision (default: 1.0e-6)")
(options, others) = parser.parse_args(args=args)
return options,others
if __name__ == '__main__':
(options,others) = evalOptions (sys.argv[1:])
if options.rel_precision:
REL_PRECISION=options.rel_precision
if options.abs_precision:
ABS_PRECISION=options.abs_precision
if (len(others) == 3):
ret,ident = main (others[0],others[1],int(others[2]))
elif (len(others) == 2):
ret,ident = main (others[0],others[1])
else:
print "Usage: "+sys.argv[0]+" logfile1 logfile2 [max different lines to print]"
ret=-1
sys.exit(ret)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
961,
570,
365,
1777,
402,
3232,
31147,
27957,
14,
199,
3,
221,
199,
3,
1898,
334,
35,
9,
11811,
13,
6542,
16666,
19857,
377,
2675,
2652,
1010,
25585,
436,
491,
4380,
2293,
428,
15089,
24545,
377,
2675,
2652,
3194,
5000,
1132,
199,
3,
221,
199,
3,
3232,
31147,
27957,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
199,
3,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
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,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
199,
646,
984,
199,
646,
3473,
199,
504,
8691,
492,
13491,
199,
504,
14106,
591,
492,
13450,
8221,
8479,
199,
504,
1586,
2959,
492,
1586,
17816,
199,
199,
13604,
63,
14246,
30011,
29,
17,
69,
13,
22,
199,
27851,
63,
14246,
30011,
29,
17,
69,
13,
22,
199,
199,
318,
1495,
591,
334,
2324,
17,
12,
2324,
18,
304,
272,
9141,
29,
709,
10,
7727,
272,
289,
17,
275,
1551,
8,
2324,
17,
2584,
82,
358,
272,
289,
18,
275,
1551,
8,
2324,
18,
2584,
82,
358,
272,
1830,
715,
26,
267,
308,
17,
275,
289,
17,
14,
739,
8,
4283,
9,
267,
308,
18,
275,
289,
18,
14,
739,
8,
4283,
9,
267,
340,
334,
552,
8,
83,
17,
12694,
16,
9,
503,
334,
552,
8,
83,
18,
12694,
16,
304,
288,
327,
1284,
402,
1373,
503,
3865,
1584,
27,
4472,
340,
652,
1159,
314,
1284,
402,
3865,
288,
372,
822,
8,
83,
17,
9,
508,
822,
8,
83,
18,
9,
267,
340,
308,
17,
1137,
308,
18,
26,
288,
372,
756,
199,
199,
318,
2446,
8,
2324,
17,
12,
2324,
18,
12,
988,
10746,
83,
1378,
5375,
29,
22,
304,
272,
408,
32488,
1561,
402,
314,
2877,
1584,
370,
6540,
436,
14190,
376,
1423,
13660,
199,
1589,
5696,
1329,
402,
15109,
370,
870,
5370,
334,
4610,
26,
1865,
365,
440,
1109,
1907,
857,
680,
199,
3407,
282,
2008,
2203,
12,
5425,
27,
2203,
365,
378,
340,
511,
14933,
334,
1199,
8652,
17429,
13,
30881,
4472,
395,
199,
5425,
365,
413,
340,
1584,
787,
3366,
13,
1452,
1041,
272,
2203,
29,
16,
272,
2450,
9287,
272,
340,
820,
2901,
63,
14246,
30011,
1111,
17,
69,
13,
22,
26,
267,
2450,
11,
628,
1553,
3369,
13,
24919,
3688,
16368,
495,
8,
13604,
63,
14246,
30011,
9,
272,
340,
437,
11087,
63,
14246,
30011,
1111,
17,
69,
13,
22,
26,
267,
2450,
11,
628,
1553,
2101,
13,
24919,
3688,
16368,
495,
8,
27851,
63,
14246,
30011,
9,
272,
870,
1867,
8762,
59,
17,
27,
1082,
77,
221,
6540,
2959,
14,
647,
7709,
2992,
5207,
7210,
2324,
17,
5207,
7210,
2324,
18,
5207,
7210,
495,
8,
988,
10746,
83,
1378,
5375,
6393,
3212,
8762,
59,
16,
27,
16,
77,
2,
2286,
327,
5574,
3865,
1584,
436,
13323,
1901,
282,
2341,
402,
790,
370,
6342,
334,
86,
17,
12,
373,
18,
9,
272,
862,
26,
267,
340,
1495,
591,
334,
2324,
17,
12,
2324,
18,
304,
288,
870,
298,
1199,
14,
2424,
1584,
787,
13130,
2,
288,
372,
378,
12,
549,
267,
870,
298,
1199,
14,
2424,
1584,
10621,
1133,
3366,
13,
1452,
2,
2728,
1338,
17,
29,
739,
17816,
8,
2324,
17,
9,
267,
1338,
18,
29,
739,
17816,
8,
2324,
18,
9,
272,
327,
2366,
29664,
6302,
365,
298,
2590,
5925,
465,
325,
401,
1771,
2315,
370,
499,
14,
22,
1325,
440,
3544,
3748,
14,
21238,
6302,
26,
272,
871,
5925,
12,
325,
26,
267,
870,
620,
8,
69,
9,
267,
372,
413,
12,
797,
272,
1338,
29,
807,
342,
272,
367,
334,
75,
12,
86,
17,
9,
315,
1338,
17,
14,
4611,
837,
267,
373,
18,
29,
403,
267,
340,
334,
75,
315,
1338,
18,
304,
288,
373,
18,
29,
1459,
18,
59,
75,
61,
288,
2150,
1338,
18,
59,
75,
61,
267,
1338,
59,
75,
61,
275,
334,
86,
17,
12,
86,
18,
9,
272,
367,
334,
75,
12,
86,
18,
9,
315,
1338,
18,
14,
4611,
837,
267,
1338,
59,
75,
61,
275,
334,
403,
12,
86,
18,
9,
2286,
327,
3971,
4012,
1006,
1338,
26,
272,
1967,
9779,
9082,
29,
16,
272,
1967,
10746,
83,
29,
16,
272,
1967,
7718,
17,
29,
16,
272,
1967,
7718,
18,
29,
16,
272,
1126,
18611,
5667,
275,
1211,
342,
272,
1126,
18611,
7316,
17,
275,
1211,
342,
272,
1126,
18611,
7316,
18,
275,
1211,
342,
272,
1126,
18611,
5667,
10746,
275,
1211,
342,
272,
1126,
18611,
10746,
6959,
275,
1211,
342,
272,
1126,
18611,
10746,
15447,
6959,
275,
1211,
342,
272,
14106,
8479,
275,
13450,
8221,
8479,
8,
13604,
63,
14246,
30011,
12,
437,
11087,
63,
14246,
30011,
9,
2286,
367,
334,
75,
12803,
86,
17,
12,
86,
18,
430,
315,
1338,
14,
4611,
837,
267,
340,
373,
17,
389,
403,
26,
288,
1967,
7718,
17,
847,
413,
267,
916,
373,
18,
389,
403,
26,
288,
1967,
7718,
18,
847,
413,
267,
587,
26,
288,
1126,
18611,
5667,
59,
75,
14,
65,
61,
275,
1126,
18611,
5667,
14,
362,
8,
75,
14,
65,
12,
378,
9,
435,
413,
288,
1126,
18611,
7316,
17,
59,
75,
14,
65,
61,
275,
1126,
18611,
7316,
17,
14,
362,
8,
75,
14,
65,
12,
378,
14,
16,
9,
435,
373,
17,
288,
1126,
18611,
7316,
18,
59,
75,
14,
65,
61,
275,
1126,
18611,
7316,
18,
14,
362,
8
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
961,
570,
365,
1777,
402,
3232,
31147,
27957,
14,
199,
3,
221,
199,
3,
1898,
334,
35,
9,
11811,
13,
6542,
16666,
19857,
377,
2675,
2652,
1010,
25585,
436,
491,
4380,
2293,
428,
15089,
24545,
377,
2675,
2652,
3194,
5000,
1132,
199,
3,
221,
199,
3,
3232,
31147,
27957,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
199,
3,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
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,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
199,
646,
984,
199,
646,
3473,
199,
504,
8691,
492,
13491,
199,
504,
14106,
591,
492,
13450,
8221,
8479,
199,
504,
1586,
2959,
492,
1586,
17816,
199,
199,
13604,
63,
14246,
30011,
29,
17,
69,
13,
22,
199,
27851,
63,
14246,
30011,
29,
17,
69,
13,
22,
199,
199,
318,
1495,
591,
334,
2324,
17,
12,
2324,
18,
304,
272,
9141,
29,
709,
10,
7727,
272,
289,
17,
275,
1551,
8,
2324,
17,
2584,
82,
358,
272,
289,
18,
275,
1551,
8,
2324,
18,
2584,
82,
358,
272,
1830,
715,
26,
267,
308,
17,
275,
289,
17,
14,
739,
8,
4283,
9,
267,
308,
18,
275,
289,
18,
14,
739,
8,
4283,
9,
267,
340,
334,
552,
8,
83,
17,
12694,
16,
9,
503,
334,
552,
8,
83,
18,
12694,
16,
304,
288,
327,
1284,
402,
1373,
503,
3865,
1584,
27,
4472,
340,
652,
1159,
314,
1284,
402,
3865,
288,
372,
822,
8,
83,
17,
9,
508,
822,
8,
83,
18,
9,
267,
340,
308,
17,
1137,
308,
18,
26,
288,
372,
756,
199,
199,
318,
2446,
8,
2324,
17,
12,
2324,
18,
12,
988,
10746,
83,
1378,
5375,
29,
22,
304,
272,
408,
32488,
1561,
402,
314,
2877,
1584,
370,
6540,
436,
14190,
376,
1423,
13660,
199,
1589,
5696,
1329,
402,
15109,
370,
870,
5370,
334,
4610,
26,
1865,
365,
440,
1109,
1907,
857,
680,
199,
3407,
282,
2008,
2203,
12,
5425,
27,
2203,
365,
378,
340,
511,
14933,
334,
1199,
8652,
17429,
13,
30881,
4472,
395,
199,
5425,
365,
413,
340,
1584,
787,
3366,
13,
1452,
1041,
272,
2203,
29,
16,
272,
2450,
9287,
272,
340,
820,
2901,
63,
14246,
30011,
1111,
17,
69,
13,
22,
26,
267,
2450,
11,
628,
1553,
3369,
13,
24919,
3688,
16368,
495,
8,
13604,
63,
14246,
30011,
9,
272,
340,
437,
11087,
63,
14246,
30011,
1111,
17,
69,
13,
22,
26,
267,
2450,
11,
628,
1553,
2101,
13,
24919,
3688,
16368,
495,
8,
27851,
63,
14246,
30011,
9,
272,
870,
1867,
8762,
59,
17,
27,
1082,
77,
221,
6540,
2959,
14,
647,
7709,
2992,
5207,
7210,
2324,
17,
5207,
7210,
2324,
18,
5207,
7210,
495,
8,
988,
10746,
83,
1378,
5375,
6393,
3212,
8762,
59,
16,
27,
16,
77,
2,
2286,
327,
5574,
3865,
1584,
436,
13323,
1901,
282,
2341,
402,
790,
370,
6342,
334,
86,
17,
12,
373,
18,
9,
272,
862,
26,
267,
340,
1495,
591,
334,
2324,
17,
12,
2324,
18,
304,
288,
870,
298,
1199,
14,
2424,
1584,
787,
13130,
2,
288,
372,
378,
12,
549,
267,
870,
298,
1199,
14,
2424,
1584,
10621,
1133,
3366,
13,
1452,
2,
2728,
1338,
17,
29,
739,
17816,
8,
2324,
17,
9,
267,
1338,
18,
29,
739,
17816,
8,
2324,
18,
9,
272,
327,
2366,
29664,
6302,
365,
298,
2590,
5925,
465,
325,
401,
1771,
2315,
370,
499,
14,
22,
1325,
440,
3544,
3748,
14,
21238,
6302,
26,
272,
871,
5925,
12,
325,
26,
267,
870,
620,
8,
69,
9,
267,
372,
413,
12,
797,
272,
1338,
29,
807,
342,
272,
367,
334,
75,
12,
86,
17,
9,
315,
1338,
17,
14,
4611,
837,
267,
373,
18,
29,
403,
267,
340,
334,
75,
315,
1338,
18,
304,
288,
373,
18,
29,
1459,
18,
59,
75,
61,
288,
2150,
1338,
18,
59,
75,
61,
267,
1338,
59,
75,
61,
275,
334,
86,
17,
12,
86,
18,
9,
272,
367,
334,
75,
12,
86,
18,
9,
315,
1338,
18,
14,
4611,
837,
267,
1338,
59,
75,
61,
275,
334,
403,
12,
86,
18,
9,
2286,
327,
3971,
4012,
1006,
1338,
26,
272,
1967,
9779,
9082,
29,
16,
272,
1967,
10746,
83,
29,
16,
272,
1967,
7718,
17,
29,
16,
272,
1967,
7718,
18,
29,
16,
272,
1126,
18611,
5667,
275,
1211,
342,
272,
1126,
18611,
7316,
17,
275,
1211,
342,
272,
1126,
18611,
7316,
18,
275,
1211,
342,
272,
1126,
18611,
5667,
10746,
275,
1211,
342,
272,
1126,
18611,
10746,
6959,
275,
1211,
342,
272,
1126,
18611,
10746,
15447,
6959,
275,
1211,
342,
272,
14106,
8479,
275,
13450,
8221,
8479,
8,
13604,
63,
14246,
30011,
12,
437,
11087,
63,
14246,
30011,
9,
2286,
367,
334,
75,
12803,
86,
17,
12,
86,
18,
430,
315,
1338,
14,
4611,
837,
267,
340,
373,
17,
389,
403,
26,
288,
1967,
7718,
17,
847,
413,
267,
916,
373,
18,
389,
403,
26,
288,
1967,
7718,
18,
847,
413,
267,
587,
26,
288,
1126,
18611,
5667,
59,
75,
14,
65,
61,
275,
1126,
18611,
5667,
14,
362,
8,
75,
14,
65,
12,
378,
9,
435,
413,
288,
1126,
18611,
7316,
17,
59,
75,
14,
65,
61,
275,
1126,
18611,
7316,
17,
14,
362,
8,
75,
14,
65,
12,
378,
14,
16,
9,
435,
373,
17,
288,
1126,
18611,
7316,
18,
59,
75,
14,
65,
61,
275,
1126,
18611,
7316,
18,
14,
362,
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,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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
] |
devs1991/test_edx_docmode
|
venv/lib/python2.7/site-packages/scipy/signal/tests/test_savitzky_golay.py
|
18
|
9463
|
from __future__ import division, print_function, absolute_import
import numpy as np
from numpy.testing import (run_module_suite, assert_allclose, assert_equal,
assert_almost_equal, assert_array_equal)
from scipy.ndimage import convolve1d
from scipy.signal import savgol_coeffs, savgol_filter
from scipy.signal._savitzky_golay import _polyder
def check_polyder(p, m, expected):
dp = _polyder(p, m)
assert_array_equal(dp, expected)
def test_polyder():
cases = [
([5], 0, [5]),
([5], 1, [0]),
([3, 2, 1], 0, [3, 2, 1]),
([3, 2, 1], 1, [6, 2]),
([3, 2, 1], 2, [6]),
([3, 2, 1], 3, [0]),
([[3, 2, 1], [5, 6, 7]], 0, [[3, 2, 1], [5, 6, 7]]),
([[3, 2, 1], [5, 6, 7]], 1, [[6, 2], [10, 6]]),
([[3, 2, 1], [5, 6, 7]], 2, [[6], [10]]),
([[3, 2, 1], [5, 6, 7]], 3, [[0], [0]]),
]
for p, m, expected in cases:
yield check_polyder, np.array(p).T, m, np.array(expected).T
#--------------------------------------------------------------------
# savgol_coeffs tests
#--------------------------------------------------------------------
def alt_sg_coeffs(window_length, polyorder, pos):
"""This is an alternative implementation of the SG coefficients.
It uses numpy.polyfit and numpy.polyval. The results should be
equivalent to those of savgol_coeffs(), but this implementation
is slower.
window_length should be odd.
"""
if pos is None:
pos = window_length // 2
t = np.arange(window_length)
unit = (t == pos).astype(int)
h = np.polyval(np.polyfit(t, unit, polyorder), t)
return h
def test_sg_coeffs_trivial():
# Test a trivial case of savgol_coeffs: polyorder = window_length - 1
h = savgol_coeffs(1, 0)
assert_allclose(h, [1])
h = savgol_coeffs(3, 2)
assert_allclose(h, [0, 1, 0], atol=1e-10)
h = savgol_coeffs(5, 4)
assert_allclose(h, [0, 0, 1, 0, 0], atol=1e-10)
h = savgol_coeffs(5, 4, pos=1)
assert_allclose(h, [0, 0, 0, 1, 0], atol=1e-10)
h = savgol_coeffs(5, 4, pos=1, use='dot')
assert_allclose(h, [0, 1, 0, 0, 0], atol=1e-10)
def compare_coeffs_to_alt(window_length, order):
# For the given window_length and order, compare the results
# of savgol_coeffs and alt_sg_coeffs for pos from 0 to window_length - 1.
# Also include pos=None.
for pos in [None] + list(range(window_length)):
h1 = savgol_coeffs(window_length, order, pos=pos, use='dot')
h2 = alt_sg_coeffs(window_length, order, pos=pos)
assert_allclose(h1, h2, atol=1e-10,
err_msg=("window_length = %d, order = %d, pos = %s" %
(window_length, order, pos)))
def test_sg_coeffs_compare():
# Compare savgol_coeffs() to alt_sg_coeffs().
for window_length in range(1, 8, 2):
for order in range(window_length):
yield compare_coeffs_to_alt, window_length, order
def test_sg_coeffs_exact():
polyorder = 4
window_length = 9
halflen = window_length // 2
x = np.linspace(0, 21, 43)
delta = x[1] - x[0]
# The data is a cubic polynomial. We'll use an order 4
# SG filter, so the filtered values should equal the input data
# (except within half window_length of the edges).
y = 0.5 * x ** 3 - x
h = savgol_coeffs(window_length, polyorder)
y0 = convolve1d(y, h)
assert_allclose(y0[halflen:-halflen], y[halflen:-halflen])
# Check the same input, but use deriv=1. dy is the exact result.
dy = 1.5 * x ** 2 - 1
h = savgol_coeffs(window_length, polyorder, deriv=1, delta=delta)
y1 = convolve1d(y, h)
assert_allclose(y1[halflen:-halflen], dy[halflen:-halflen])
# Check the same input, but use deriv=2. d2y is the exact result.
d2y = 3.0 * x
h = savgol_coeffs(window_length, polyorder, deriv=2, delta=delta)
y2 = convolve1d(y, h)
assert_allclose(y2[halflen:-halflen], d2y[halflen:-halflen])
def test_sg_coeffs_deriv():
# The data in `x` is a sampled parabola, so using savgol_coeffs with an
# order 2 or higher polynomial should give exact results.
i = np.array([-2.0, 0.0, 2.0, 4.0, 6.0])
x = i ** 2 / 4
dx = i / 2
d2x = 0.5 * np.ones_like(i)
for pos in range(x.size):
coeffs0 = savgol_coeffs(5, 3, pos=pos, delta=2.0, use='dot')
assert_allclose(coeffs0.dot(x), x[pos], atol=1e-10)
coeffs1 = savgol_coeffs(5, 3, pos=pos, delta=2.0, use='dot', deriv=1)
assert_allclose(coeffs1.dot(x), dx[pos], atol=1e-10)
coeffs2 = savgol_coeffs(5, 3, pos=pos, delta=2.0, use='dot', deriv=2)
assert_allclose(coeffs2.dot(x), d2x[pos], atol=1e-10)
#--------------------------------------------------------------------
# savgol_filter tests
#--------------------------------------------------------------------
def test_sg_filter_trivial():
""" Test some trivial edge cases for savgol_filter()."""
x = np.array([1.0])
y = savgol_filter(x, 1, 0)
assert_equal(y, [1.0])
# Input is a single value. With a window length of 3 and polyorder 1,
# the value in y is from the straight-line fit of (-1,0), (0,3) and
# (1, 0) at 0. This is just the average of the three values, hence 1.0.
x = np.array([3.0])
y = savgol_filter(x, 3, 1, mode='constant')
assert_almost_equal(y, [1.0], decimal=15)
x = np.array([3.0])
y = savgol_filter(x, 3, 1, mode='nearest')
assert_almost_equal(y, [3.0], decimal=15)
x = np.array([1.0] * 3)
y = savgol_filter(x, 3, 1, mode='wrap')
assert_almost_equal(y, [1.0, 1.0, 1.0], decimal=15)
def test_sg_filter_basic():
# Some basic test cases for savgol_filter().
x = np.array([1.0, 2.0, 1.0])
y = savgol_filter(x, 3, 1, mode='constant')
assert_allclose(y, [1.0, 4.0 / 3, 1.0])
y = savgol_filter(x, 3, 1, mode='mirror')
assert_allclose(y, [5.0 / 3, 4.0 / 3, 5.0 / 3])
y = savgol_filter(x, 3, 1, mode='wrap')
assert_allclose(y, [4.0 / 3, 4.0 / 3, 4.0 / 3])
def test_sg_filter_2d():
x = np.array([[1.0, 2.0, 1.0],
[2.0, 4.0, 2.0]])
expected = np.array([[1.0, 4.0 / 3, 1.0],
[2.0, 8.0 / 3, 2.0]])
y = savgol_filter(x, 3, 1, mode='constant')
assert_allclose(y, expected)
y = savgol_filter(x.T, 3, 1, mode='constant', axis=0)
assert_allclose(y, expected.T)
def test_sg_filter_interp_edges():
# Another test with low degree polynomial data, for which we can easily
# give the exact results. In this test, we use mode='interp', so
# savgol_filter should match the exact solution for the entire data set,
# including the edges.
t = np.linspace(-5, 5, 21)
delta = t[1] - t[0]
# Polynomial test data.
x = np.array([t,
3 * t ** 2,
t ** 3 - t])
dx = np.array([np.ones_like(t),
6 * t,
3 * t ** 2 - 1.0])
d2x = np.array([np.zeros_like(t),
6 * np.ones_like(t),
6 * t])
window_length = 7
y = savgol_filter(x, window_length, 3, axis=-1, mode='interp')
assert_allclose(y, x, atol=1e-12)
y1 = savgol_filter(x, window_length, 3, axis=-1, mode='interp',
deriv=1, delta=delta)
assert_allclose(y1, dx, atol=1e-12)
y2 = savgol_filter(x, window_length, 3, axis=-1, mode='interp',
deriv=2, delta=delta)
assert_allclose(y2, d2x, atol=1e-12)
# Transpose everything, and test again with axis=0.
x = x.T
dx = dx.T
d2x = d2x.T
y = savgol_filter(x, window_length, 3, axis=0, mode='interp')
assert_allclose(y, x, atol=1e-12)
y1 = savgol_filter(x, window_length, 3, axis=0, mode='interp',
deriv=1, delta=delta)
assert_allclose(y1, dx, atol=1e-12)
y2 = savgol_filter(x, window_length, 3, axis=0, mode='interp',
deriv=2, delta=delta)
assert_allclose(y2, d2x, atol=1e-12)
def test_sg_filter_interp_edges_3d():
# Test mode='interp' with a 3-D array.
t = np.linspace(-5, 5, 21)
delta = t[1] - t[0]
x1 = np.array([t, -t])
x2 = np.array([t ** 2, 3 * t ** 2 + 5])
x3 = np.array([t ** 3, 2 * t ** 3 + t ** 2 - 0.5 * t])
dx1 = np.array([np.ones_like(t), -np.ones_like(t)])
dx2 = np.array([2 * t, 6 * t])
dx3 = np.array([3 * t ** 2, 6 * t ** 2 + 2 * t - 0.5])
# z has shape (3, 2, 21)
z = np.array([x1, x2, x3])
dz = np.array([dx1, dx2, dx3])
y = savgol_filter(z, 7, 3, axis=-1, mode='interp', delta=delta)
assert_allclose(y, z, atol=1e-10)
dy = savgol_filter(z, 7, 3, axis=-1, mode='interp', deriv=1, delta=delta)
assert_allclose(dy, dz, atol=1e-10)
# z has shape (3, 21, 2)
z = np.array([x1.T, x2.T, x3.T])
dz = np.array([dx1.T, dx2.T, dx3.T])
y = savgol_filter(z, 7, 3, axis=1, mode='interp', delta=delta)
assert_allclose(y, z, atol=1e-10)
dy = savgol_filter(z, 7, 3, axis=1, mode='interp', deriv=1, delta=delta)
assert_allclose(dy, dz, atol=1e-10)
# z has shape (21, 3, 2)
z = z.swapaxes(0, 1).copy()
dz = dz.swapaxes(0, 1).copy()
y = savgol_filter(z, 7, 3, axis=0, mode='interp', delta=delta)
assert_allclose(y, z, atol=1e-10)
dy = savgol_filter(z, 7, 3, axis=0, mode='interp', deriv=1, delta=delta)
assert_allclose(dy, dz, atol=1e-10)
if __name__ == "__main__":
run_module_suite()
|
agpl-3.0
|
[
504,
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
12,
3679,
63,
646,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
334,
1065,
63,
578,
63,
5768,
12,
702,
63,
7520,
12,
702,
63,
1452,
12,
2574,
702,
63,
4398,
63,
1452,
12,
702,
63,
1144,
63,
1452,
9,
199,
199,
504,
7026,
14,
78,
23335,
492,
8260,
3344,
17,
68,
199,
199,
504,
7026,
14,
4653,
492,
308,
8595,
393,
63,
15958,
12,
308,
8595,
393,
63,
1541,
199,
504,
7026,
14,
4653,
423,
23374,
23751,
10562,
63,
71,
393,
1187,
492,
485,
6023,
424,
421,
199,
318,
1104,
63,
6023,
424,
8,
80,
12,
333,
12,
1420,
304,
272,
12392,
275,
485,
6023,
424,
8,
80,
12,
333,
9,
272,
702,
63,
1144,
63,
1452,
8,
5780,
12,
1420,
9,
421,
199,
318,
511,
63,
6023,
424,
837,
272,
5560,
275,
359,
267,
7287,
21,
467,
378,
12,
359,
21,
2522,
267,
7287,
21,
467,
413,
12,
359,
16,
2522,
267,
7287,
19,
12,
499,
12,
413,
467,
378,
12,
359,
19,
12,
499,
12,
413,
2522,
267,
7287,
19,
12,
499,
12,
413,
467,
413,
12,
359,
22,
12,
499,
2522,
267,
7287,
19,
12,
499,
12,
413,
467,
499,
12,
359,
22,
2522,
267,
7287,
19,
12,
499,
12,
413,
467,
650,
12,
359,
16,
2522,
267,
7287,
59,
19,
12,
499,
12,
413,
467,
359,
21,
12,
1227,
12,
1520,
2365,
378,
12,
3474,
19,
12,
499,
12,
413,
467,
359,
21,
12,
1227,
12,
1520,
13925,
267,
7287,
59,
19,
12,
499,
12,
413,
467,
359,
21,
12,
1227,
12,
1520,
2365,
413,
12,
3474,
22,
12,
499,
467,
359,
709,
12,
1227,
13925,
267,
7287,
59,
19,
12,
499,
12,
413,
467,
359,
21,
12,
1227,
12,
1520,
2365,
499,
12,
3474,
22,
467,
359,
709,
13925,
267,
7287,
59,
19,
12,
499,
12,
413,
467,
359,
21,
12,
1227,
12,
1520,
2365,
650,
12,
3474,
16,
467,
359,
16,
13925,
272,
1622,
272,
367,
299,
12,
333,
12,
1420,
315,
5560,
26,
267,
1995,
1104,
63,
6023,
424,
12,
980,
14,
1144,
8,
80,
680,
52,
12,
333,
12,
980,
14,
1144,
8,
2062,
680,
52,
421,
199,
7656,
375,
199,
3,
308,
8595,
393,
63,
15958,
2295,
199,
7656,
375,
199,
199,
318,
8791,
63,
1226,
63,
15958,
8,
3806,
63,
1267,
12,
8446,
1648,
12,
2086,
304,
272,
408,
2765,
365,
376,
13943,
4514,
402,
314,
18868,
12343,
14,
339,
2779,
4440,
2680,
14,
6023,
3269,
436,
2680,
14,
6023,
637,
14,
221,
710,
2058,
1077,
506,
272,
7353,
370,
5204,
402,
308,
8595,
393,
63,
15958,
1062,
1325,
642,
4514,
272,
365,
26200,
14,
339,
4353,
63,
1267,
1077,
506,
16699,
14,
339,
408,
272,
340,
2086,
365,
488,
26,
267,
2086,
275,
4353,
63,
1267,
5001,
499,
272,
307,
275,
980,
14,
5605,
8,
3806,
63,
1267,
9,
272,
4137,
275,
334,
84,
508,
2086,
680,
6041,
8,
442,
9,
272,
394,
275,
980,
14,
6023,
637,
8,
1590,
14,
6023,
3269,
8,
84,
12,
4137,
12,
8446,
1648,
395,
307,
9,
272,
372,
394,
421,
199,
318,
511,
63,
1226,
63,
15958,
63,
23844,
837,
272,
327,
1379,
282,
28586,
1930,
402,
308,
8595,
393,
63,
15958,
26,
8446,
1648,
275,
4353,
63,
1267,
446,
413,
272,
394,
275,
308,
8595,
393,
63,
15958,
8,
17,
12,
378,
9,
272,
702,
63,
7520,
8,
72,
12,
359,
17,
566,
339,
394,
275,
308,
8595,
393,
63,
15958,
8,
19,
12,
499,
9,
272,
702,
63,
7520,
8,
72,
12,
359,
16,
12,
413,
12,
378,
467,
9543,
29,
17,
69,
13,
709,
9,
339,
394,
275,
308,
8595,
393,
63,
15958,
8,
21,
12,
841,
9,
272,
702,
63,
7520,
8,
72,
12,
359,
16,
12,
378,
12,
413,
12,
378,
12,
378,
467,
9543,
29,
17,
69,
13,
709,
9,
339,
394,
275,
308,
8595,
393,
63,
15958,
8,
21,
12,
841,
12,
2086,
29,
17,
9,
272,
702,
63,
7520,
8,
72,
12,
359,
16,
12,
378,
12,
378,
12,
413,
12,
378,
467,
9543,
29,
17,
69,
13,
709,
9,
339,
394,
275,
308,
8595,
393,
63,
15958,
8,
21,
12,
841,
12,
2086,
29,
17,
12,
675,
534,
3287,
358,
272,
702,
63,
7520,
8,
72,
12,
359,
16,
12,
413,
12,
378,
12,
378,
12,
378,
467,
9543,
29,
17,
69,
13,
709,
9,
421,
199,
318,
6540,
63,
15958,
63,
475,
63,
4478,
8,
3806,
63,
1267,
12,
1865,
304,
272,
327,
2104,
314,
1627,
4353,
63,
1267,
436,
1865,
12,
6540,
314,
2058,
272,
327,
402,
308,
8595,
393,
63,
15958,
436,
8791,
63,
1226,
63,
15958,
367,
2086,
687,
378,
370,
4353,
63,
1267,
446,
413,
14,
272,
327,
6121,
2387,
2086,
29,
403,
14,
272,
367,
2086,
315,
359,
403,
61,
435,
769,
8,
1842,
8,
3806,
63,
1267,
2298,
267,
394,
17,
275,
308,
8595,
393,
63,
15958,
8,
3806,
63,
1267,
12,
1865,
12,
2086,
29,
1712,
12,
675,
534,
3287,
358,
267,
394,
18,
275,
8791,
63,
1226,
63,
15958,
8,
3806,
63,
1267,
12,
1865,
12,
2086,
29,
1712,
9,
267,
702,
63,
7520,
8,
72,
17,
12,
394,
18,
12,
9543,
29,
17,
69,
13,
709,
12,
717,
2329,
63,
1328,
15387,
3806,
63,
1267,
275,
450,
68,
12,
1865,
275,
450,
68,
12,
2086,
275,
450,
83,
2,
450,
639,
334,
3806,
63,
1267,
12,
1865,
12,
2086,
1724,
421,
199,
318,
511,
63,
1226,
63,
15958,
63,
5785,
837,
272,
327,
18955,
308,
8595,
393,
63,
15958,
342,
370,
8791,
63,
1226,
63,
15958,
1252,
272,
367,
4353,
63,
1267,
315,
1425,
8,
17,
12,
1695,
12,
499,
304,
267,
367,
1865,
315,
1425,
8,
3806,
63,
1267,
304,
288,
1995,
6540,
63,
15958,
63,
475,
63,
4478,
12,
4353,
63,
1267,
12,
1865,
421,
199,
318,
511,
63,
1226,
63,
15958,
63,
7327,
837,
272,
8446,
1648,
275,
841,
272,
4353,
63,
1267,
275,
1749,
272,
12995,
552,
275,
4353,
63,
1267,
5001,
499,
339,
671,
275,
980,
14,
11649,
8,
16,
12,
7829,
12,
11851,
9,
272,
5762
] |
[
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
12,
3679,
63,
646,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
334,
1065,
63,
578,
63,
5768,
12,
702,
63,
7520,
12,
702,
63,
1452,
12,
2574,
702,
63,
4398,
63,
1452,
12,
702,
63,
1144,
63,
1452,
9,
199,
199,
504,
7026,
14,
78,
23335,
492,
8260,
3344,
17,
68,
199,
199,
504,
7026,
14,
4653,
492,
308,
8595,
393,
63,
15958,
12,
308,
8595,
393,
63,
1541,
199,
504,
7026,
14,
4653,
423,
23374,
23751,
10562,
63,
71,
393,
1187,
492,
485,
6023,
424,
421,
199,
318,
1104,
63,
6023,
424,
8,
80,
12,
333,
12,
1420,
304,
272,
12392,
275,
485,
6023,
424,
8,
80,
12,
333,
9,
272,
702,
63,
1144,
63,
1452,
8,
5780,
12,
1420,
9,
421,
199,
318,
511,
63,
6023,
424,
837,
272,
5560,
275,
359,
267,
7287,
21,
467,
378,
12,
359,
21,
2522,
267,
7287,
21,
467,
413,
12,
359,
16,
2522,
267,
7287,
19,
12,
499,
12,
413,
467,
378,
12,
359,
19,
12,
499,
12,
413,
2522,
267,
7287,
19,
12,
499,
12,
413,
467,
413,
12,
359,
22,
12,
499,
2522,
267,
7287,
19,
12,
499,
12,
413,
467,
499,
12,
359,
22,
2522,
267,
7287,
19,
12,
499,
12,
413,
467,
650,
12,
359,
16,
2522,
267,
7287,
59,
19,
12,
499,
12,
413,
467,
359,
21,
12,
1227,
12,
1520,
2365,
378,
12,
3474,
19,
12,
499,
12,
413,
467,
359,
21,
12,
1227,
12,
1520,
13925,
267,
7287,
59,
19,
12,
499,
12,
413,
467,
359,
21,
12,
1227,
12,
1520,
2365,
413,
12,
3474,
22,
12,
499,
467,
359,
709,
12,
1227,
13925,
267,
7287,
59,
19,
12,
499,
12,
413,
467,
359,
21,
12,
1227,
12,
1520,
2365,
499,
12,
3474,
22,
467,
359,
709,
13925,
267,
7287,
59,
19,
12,
499,
12,
413,
467,
359,
21,
12,
1227,
12,
1520,
2365,
650,
12,
3474,
16,
467,
359,
16,
13925,
272,
1622,
272,
367,
299,
12,
333,
12,
1420,
315,
5560,
26,
267,
1995,
1104,
63,
6023,
424,
12,
980,
14,
1144,
8,
80,
680,
52,
12,
333,
12,
980,
14,
1144,
8,
2062,
680,
52,
421,
199,
7656,
375,
199,
3,
308,
8595,
393,
63,
15958,
2295,
199,
7656,
375,
199,
199,
318,
8791,
63,
1226,
63,
15958,
8,
3806,
63,
1267,
12,
8446,
1648,
12,
2086,
304,
272,
408,
2765,
365,
376,
13943,
4514,
402,
314,
18868,
12343,
14,
339,
2779,
4440,
2680,
14,
6023,
3269,
436,
2680,
14,
6023,
637,
14,
221,
710,
2058,
1077,
506,
272,
7353,
370,
5204,
402,
308,
8595,
393,
63,
15958,
1062,
1325,
642,
4514,
272,
365,
26200,
14,
339,
4353,
63,
1267,
1077,
506,
16699,
14,
339,
408,
272,
340,
2086,
365,
488,
26,
267,
2086,
275,
4353,
63,
1267,
5001,
499,
272,
307,
275,
980,
14,
5605,
8,
3806,
63,
1267,
9,
272,
4137,
275,
334,
84,
508,
2086,
680,
6041,
8,
442,
9,
272,
394,
275,
980,
14,
6023,
637,
8,
1590,
14,
6023,
3269,
8,
84,
12,
4137,
12,
8446,
1648,
395,
307,
9,
272,
372,
394,
421,
199,
318,
511,
63,
1226,
63,
15958,
63,
23844,
837,
272,
327,
1379,
282,
28586,
1930,
402,
308,
8595,
393,
63,
15958,
26,
8446,
1648,
275,
4353,
63,
1267,
446,
413,
272,
394,
275,
308,
8595,
393,
63,
15958,
8,
17,
12,
378,
9,
272,
702,
63,
7520,
8,
72,
12,
359,
17,
566,
339,
394,
275,
308,
8595,
393,
63,
15958,
8,
19,
12,
499,
9,
272,
702,
63,
7520,
8,
72,
12,
359,
16,
12,
413,
12,
378,
467,
9543,
29,
17,
69,
13,
709,
9,
339,
394,
275,
308,
8595,
393,
63,
15958,
8,
21,
12,
841,
9,
272,
702,
63,
7520,
8,
72,
12,
359,
16,
12,
378,
12,
413,
12,
378,
12,
378,
467,
9543,
29,
17,
69,
13,
709,
9,
339,
394,
275,
308,
8595,
393,
63,
15958,
8,
21,
12,
841,
12,
2086,
29,
17,
9,
272,
702,
63,
7520,
8,
72,
12,
359,
16,
12,
378,
12,
378,
12,
413,
12,
378,
467,
9543,
29,
17,
69,
13,
709,
9,
339,
394,
275,
308,
8595,
393,
63,
15958,
8,
21,
12,
841,
12,
2086,
29,
17,
12,
675,
534,
3287,
358,
272,
702,
63,
7520,
8,
72,
12,
359,
16,
12,
413,
12,
378,
12,
378,
12,
378,
467,
9543,
29,
17,
69,
13,
709,
9,
421,
199,
318,
6540,
63,
15958,
63,
475,
63,
4478,
8,
3806,
63,
1267,
12,
1865,
304,
272,
327,
2104,
314,
1627,
4353,
63,
1267,
436,
1865,
12,
6540,
314,
2058,
272,
327,
402,
308,
8595,
393,
63,
15958,
436,
8791,
63,
1226,
63,
15958,
367,
2086,
687,
378,
370,
4353,
63,
1267,
446,
413,
14,
272,
327,
6121,
2387,
2086,
29,
403,
14,
272,
367,
2086,
315,
359,
403,
61,
435,
769,
8,
1842,
8,
3806,
63,
1267,
2298,
267,
394,
17,
275,
308,
8595,
393,
63,
15958,
8,
3806,
63,
1267,
12,
1865,
12,
2086,
29,
1712,
12,
675,
534,
3287,
358,
267,
394,
18,
275,
8791,
63,
1226,
63,
15958,
8,
3806,
63,
1267,
12,
1865,
12,
2086,
29,
1712,
9,
267,
702,
63,
7520,
8,
72,
17,
12,
394,
18,
12,
9543,
29,
17,
69,
13,
709,
12,
717,
2329,
63,
1328,
15387,
3806,
63,
1267,
275,
450,
68,
12,
1865,
275,
450,
68,
12,
2086,
275,
450,
83,
2,
450,
639,
334,
3806,
63,
1267,
12,
1865,
12,
2086,
1724,
421,
199,
318,
511,
63,
1226,
63,
15958,
63,
5785,
837,
272,
327,
18955,
308,
8595,
393,
63,
15958,
342,
370,
8791,
63,
1226,
63,
15958,
1252,
272,
367,
4353,
63,
1267,
315,
1425,
8,
17,
12,
1695,
12,
499,
304,
267,
367,
1865,
315,
1425,
8,
3806,
63,
1267,
304,
288,
1995,
6540,
63,
15958,
63,
475,
63,
4478,
12,
4353,
63,
1267,
12,
1865,
421,
199,
318,
511,
63,
1226,
63,
15958,
63,
7327,
837,
272,
8446,
1648,
275,
841,
272,
4353,
63,
1267,
275,
1749,
272,
12995,
552,
275,
4353,
63,
1267,
5001,
499,
339,
671,
275,
980,
14,
11649,
8,
16,
12,
7829,
12,
11851,
9,
272,
5762,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tomasdubec/openstack-cinder
|
cinder/scheduler/chance.py
|
2
|
2660
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (c) 2010 OpenStack, LLC.
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# 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.
"""
Chance (Random) Scheduler implementation
"""
import random
from cinder import exception
from cinder import flags
from cinder.scheduler import driver
FLAGS = flags.FLAGS
class ChanceScheduler(driver.Scheduler):
"""Implements Scheduler as a random node selector."""
def _filter_hosts(self, request_spec, hosts, **kwargs):
"""Filter a list of hosts based on request_spec."""
filter_properties = kwargs.get('filter_properties', {})
ignore_hosts = filter_properties.get('ignore_hosts', [])
hosts = [host for host in hosts if host not in ignore_hosts]
return hosts
def _schedule(self, context, topic, request_spec, **kwargs):
"""Picks a host that is up at random."""
elevated = context.elevated()
hosts = self.hosts_up(elevated, topic)
if not hosts:
msg = _("Is the appropriate service running?")
raise exception.NoValidHost(reason=msg)
hosts = self._filter_hosts(request_spec, hosts, **kwargs)
if not hosts:
msg = _("Could not find another host")
raise exception.NoValidHost(reason=msg)
return hosts[int(random.random() * len(hosts))]
def schedule_create_volume(self, context, request_spec, filter_properties):
"""Picks a host that is up at random."""
topic = FLAGS.volume_topic
host = self._schedule(context, topic, request_spec,
filter_properties=filter_properties)
volume_id = request_spec['volume_id']
snapshot_id = request_spec['snapshot_id']
image_id = request_spec['image_id']
updated_volume = driver.volume_update_db(context, volume_id, host)
self.volume_rpcapi.create_volume(context, updated_volume, host,
snapshot_id, image_id)
|
apache-2.0
|
[
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
334,
67,
9,
7129,
14260,
12,
20376,
14,
199,
3,
1898,
7129,
1910,
5703,
24230,
598,
27639,
465,
11159,
701,
314,
199,
3,
30660,
402,
314,
20548,
437,
281,
265,
3844,
7769,
436,
19326,
9516,
4633,
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,
624,
199,
1049,
554,
334,
3883,
9,
32051,
4514,
199,
624,
199,
199,
646,
2196,
199,
199,
504,
13069,
492,
1919,
199,
504,
13069,
492,
3285,
199,
504,
13069,
14,
8874,
492,
5253,
421,
199,
4831,
275,
3285,
14,
4831,
421,
199,
533,
2799,
554,
11251,
8,
3090,
14,
11251,
304,
272,
408,
29452,
32051,
465,
282,
2196,
1031,
9759,
1041,
339,
347,
485,
1541,
63,
5146,
8,
277,
12,
1056,
63,
1650,
12,
7057,
12,
1011,
958,
304,
267,
408,
4131,
282,
769,
402,
7057,
4079,
641,
1056,
63,
1650,
1041,
398,
2457,
63,
3282,
275,
2074,
14,
362,
360,
1541,
63,
3282,
297,
5009,
267,
3686,
63,
5146,
275,
2457,
63,
3282,
14,
362,
360,
4247,
63,
5146,
297,
3073,
267,
7057,
275,
359,
1102,
367,
1591,
315,
7057,
340,
1591,
440,
315,
3686,
63,
5146,
61,
267,
372,
7057,
339,
347,
485,
7211,
8,
277,
12,
1067,
12,
7482,
12,
1056,
63,
1650,
12,
1011,
958,
304,
267,
408,
8587,
83,
282,
1591,
626,
365,
1536,
737,
2196,
1041,
398,
325,
6972,
972,
275,
1067,
14,
32168,
342,
267,
7057,
275,
291,
14,
5146,
63,
384,
8,
32168,
12,
7482,
9,
267,
340,
440,
7057,
26,
288,
1499,
275,
3824,
1831,
314,
5827,
2435,
3879,
18582,
288,
746,
1919,
14,
1944,
3490,
4965,
8,
5764,
29,
1328,
9,
398,
7057,
275,
291,
423,
1541,
63,
5146,
8,
1069,
63,
1650,
12,
7057,
12,
1011,
958,
9,
267,
340,
440,
7057,
26,
288,
1499,
275,
3824,
6531,
440,
2342,
4573,
1591,
531,
288,
746,
1919,
14,
1944,
3490,
4965,
8,
5764,
29,
1328,
9,
398,
372,
7057,
59,
442,
8,
2355,
14,
2355,
342,
627,
822,
8,
5146,
10524,
339,
347,
8732,
63,
981,
63,
2405,
8,
277,
12,
1067,
12,
1056,
63,
1650,
12,
2457,
63,
3282,
304,
267,
408,
8587,
83,
282,
1591,
626,
365,
1536,
737,
2196,
1041,
267,
7482,
275,
12846,
14,
2405,
63,
5746,
267,
1591,
275,
291,
423,
7211,
8,
1100,
12,
7482,
12,
1056,
63,
1650,
12,
2892,
2457,
63,
3282,
29,
1541,
63,
3282,
9,
267,
3301,
63,
344,
275,
1056,
63,
1650,
459,
2405,
63,
344,
418,
267,
5740,
63,
344,
275,
1056,
63,
1650,
459,
4753,
63,
344,
418,
267,
1834,
63,
344,
275,
1056,
63,
1650,
459,
1569,
63,
344,
418,
398,
4588,
63,
2405,
275,
5253,
14,
2405,
63,
873,
63,
697,
8,
1100,
12,
3301,
63,
344,
12,
1591,
9,
267,
291,
14,
2405,
63,
20776,
14,
981,
63,
2405,
8,
1100,
12,
4588,
63,
2405,
12,
1591,
12,
1460,
5740,
63,
344,
12,
1834,
63,
344,
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
] |
[
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
334,
67,
9,
7129,
14260,
12,
20376,
14,
199,
3,
1898,
7129,
1910,
5703,
24230,
598,
27639,
465,
11159,
701,
314,
199,
3,
30660,
402,
314,
20548,
437,
281,
265,
3844,
7769,
436,
19326,
9516,
4633,
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,
624,
199,
1049,
554,
334,
3883,
9,
32051,
4514,
199,
624,
199,
199,
646,
2196,
199,
199,
504,
13069,
492,
1919,
199,
504,
13069,
492,
3285,
199,
504,
13069,
14,
8874,
492,
5253,
421,
199,
4831,
275,
3285,
14,
4831,
421,
199,
533,
2799,
554,
11251,
8,
3090,
14,
11251,
304,
272,
408,
29452,
32051,
465,
282,
2196,
1031,
9759,
1041,
339,
347,
485,
1541,
63,
5146,
8,
277,
12,
1056,
63,
1650,
12,
7057,
12,
1011,
958,
304,
267,
408,
4131,
282,
769,
402,
7057,
4079,
641,
1056,
63,
1650,
1041,
398,
2457,
63,
3282,
275,
2074,
14,
362,
360,
1541,
63,
3282,
297,
5009,
267,
3686,
63,
5146,
275,
2457,
63,
3282,
14,
362,
360,
4247,
63,
5146,
297,
3073,
267,
7057,
275,
359,
1102,
367,
1591,
315,
7057,
340,
1591,
440,
315,
3686,
63,
5146,
61,
267,
372,
7057,
339,
347,
485,
7211,
8,
277,
12,
1067,
12,
7482,
12,
1056,
63,
1650,
12,
1011,
958,
304,
267,
408,
8587,
83,
282,
1591,
626,
365,
1536,
737,
2196,
1041,
398,
325,
6972,
972,
275,
1067,
14,
32168,
342,
267,
7057,
275,
291,
14,
5146,
63,
384,
8,
32168,
12,
7482,
9,
267,
340,
440,
7057,
26,
288,
1499,
275,
3824,
1831,
314,
5827,
2435,
3879,
18582,
288,
746,
1919,
14,
1944,
3490,
4965,
8,
5764,
29,
1328,
9,
398,
7057,
275,
291,
423,
1541,
63,
5146,
8,
1069,
63,
1650,
12,
7057,
12,
1011,
958,
9,
267,
340,
440,
7057,
26,
288,
1499,
275,
3824,
6531,
440,
2342,
4573,
1591,
531,
288,
746,
1919,
14,
1944,
3490,
4965,
8,
5764,
29,
1328,
9,
398,
372,
7057,
59,
442,
8,
2355,
14,
2355,
342,
627,
822,
8,
5146,
10524,
339,
347,
8732,
63,
981,
63,
2405,
8,
277,
12,
1067,
12,
1056,
63,
1650,
12,
2457,
63,
3282,
304,
267,
408,
8587,
83,
282,
1591,
626,
365,
1536,
737,
2196,
1041,
267,
7482,
275,
12846,
14,
2405,
63,
5746,
267,
1591,
275,
291,
423,
7211,
8,
1100,
12,
7482,
12,
1056,
63,
1650,
12,
2892,
2457,
63,
3282,
29,
1541,
63,
3282,
9,
267,
3301,
63,
344,
275,
1056,
63,
1650,
459,
2405,
63,
344,
418,
267,
5740,
63,
344,
275,
1056,
63,
1650,
459,
4753,
63,
344,
418,
267,
1834,
63,
344,
275,
1056,
63,
1650,
459,
1569,
63,
344,
418,
398,
4588,
63,
2405,
275,
5253,
14,
2405,
63,
873,
63,
697,
8,
1100,
12,
3301,
63,
344,
12,
1591,
9,
267,
291,
14,
2405,
63,
20776,
14,
981,
63,
2405,
8,
1100,
12,
4588,
63,
2405,
12,
1591,
12,
1460,
5740,
63,
344,
12,
1834,
63,
344,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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python2.7/site-packages/scipy/optimize/optimize.py
|
9
|
100323
|
#__docformat__ = "restructuredtext en"
# ******NOTICE***************
# optimize.py module by Travis E. Oliphant
#
# You may copy and use this module as you see fit with no
# guarantee implied provided you keep this notice in all copies.
# *****END NOTICE************
# A collection of optimization algorithms. Version 0.5
# CHANGES
# Added fminbound (July 2001)
# Added brute (Aug. 2002)
# Finished line search satisfying strong Wolfe conditions (Mar. 2004)
# Updated strong Wolfe conditions line search to use
# cubic-interpolation (Mar. 2004)
from __future__ import division, print_function, absolute_import
# Minimization routines
__all__ = ['fmin', 'fmin_powell', 'fmin_bfgs', 'fmin_ncg', 'fmin_cg',
'fminbound', 'brent', 'golden', 'bracket', 'rosen', 'rosen_der',
'rosen_hess', 'rosen_hess_prod', 'brute', 'approx_fprime',
'line_search', 'check_grad', 'OptimizeResult', 'show_options',
'OptimizeWarning']
__docformat__ = "restructuredtext en"
import warnings
import sys
import numpy
from scipy._lib.six import callable, xrange
from numpy import (atleast_1d, eye, mgrid, argmin, zeros, shape, squeeze,
vectorize, asarray, sqrt, Inf, asfarray, isinf)
import numpy as np
from .linesearch import (line_search_wolfe1, line_search_wolfe2,
line_search_wolfe2 as line_search,
LineSearchWarning)
from scipy._lib._util import getargspec_no_self as _getargspec
# standard status messages of optimizers
_status_message = {'success': 'Optimization terminated successfully.',
'maxfev': 'Maximum number of function evaluations has '
'been exceeded.',
'maxiter': 'Maximum number of iterations has been '
'exceeded.',
'pr_loss': 'Desired error not necessarily achieved due '
'to precision loss.'}
class MemoizeJac(object):
""" Decorator that caches the value gradient of function each time it
is called. """
def __init__(self, fun):
self.fun = fun
self.jac = None
self.x = None
def __call__(self, x, *args):
self.x = numpy.asarray(x).copy()
fg = self.fun(x, *args)
self.jac = fg[1]
return fg[0]
def derivative(self, x, *args):
if self.jac is not None and numpy.alltrue(x == self.x):
return self.jac
else:
self(x, *args)
return self.jac
class OptimizeResult(dict):
""" Represents the optimization result.
Attributes
----------
x : ndarray
The solution of the optimization.
success : bool
Whether or not the optimizer exited successfully.
status : int
Termination status of the optimizer. Its value depends on the
underlying solver. Refer to `message` for details.
message : str
Description of the cause of the termination.
fun, jac, hess: ndarray
Values of objective function, its Jacobian and its Hessian (if
available). The Hessians may be approximations, see the documentation
of the function in question.
hess_inv : object
Inverse of the objective function's Hessian; may be an approximation.
Not available for all solvers. The type of this attribute may be
either np.ndarray or scipy.sparse.linalg.LinearOperator.
nfev, njev, nhev : int
Number of evaluations of the objective functions and of its
Jacobian and Hessian.
nit : int
Number of iterations performed by the optimizer.
maxcv : float
The maximum constraint violation.
Notes
-----
There may be additional attributes not listed above depending of the
specific solver. Since this class is essentially a subclass of dict
with attribute accessors, one can see which attributes are available
using the `keys()` method.
"""
def __getattr__(self, name):
try:
return self[name]
except KeyError:
raise AttributeError(name)
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__
def __repr__(self):
if self.keys():
m = max(map(len, list(self.keys()))) + 1
return '\n'.join([k.rjust(m) + ': ' + repr(v)
for k, v in sorted(self.items())])
else:
return self.__class__.__name__ + "()"
def __dir__(self):
return list(self.keys())
class OptimizeWarning(UserWarning):
pass
def _check_unknown_options(unknown_options):
if unknown_options:
msg = ", ".join(map(str, unknown_options.keys()))
# Stack level 4: this is called from _minimize_*, which is
# called from another function in Scipy. Level 4 is the first
# level in user code.
warnings.warn("Unknown solver options: %s" % msg, OptimizeWarning, 4)
def is_array_scalar(x):
"""Test whether `x` is either a scalar or an array scalar.
"""
return np.size(x) == 1
_epsilon = sqrt(numpy.finfo(float).eps)
def vecnorm(x, ord=2):
if ord == Inf:
return numpy.amax(numpy.abs(x))
elif ord == -Inf:
return numpy.amin(numpy.abs(x))
else:
return numpy.sum(numpy.abs(x)**ord, axis=0)**(1.0 / ord)
def rosen(x):
"""
The Rosenbrock function.
The function computed is::
sum(100.0*(x[1:] - x[:-1]**2.0)**2.0 + (1 - x[:-1])**2.0)
Parameters
----------
x : array_like
1-D array of points at which the Rosenbrock function is to be computed.
Returns
-------
f : float
The value of the Rosenbrock function.
See Also
--------
rosen_der, rosen_hess, rosen_hess_prod
"""
x = asarray(x)
r = numpy.sum(100.0 * (x[1:] - x[:-1]**2.0)**2.0 + (1 - x[:-1])**2.0,
axis=0)
return r
def rosen_der(x):
"""
The derivative (i.e. gradient) of the Rosenbrock function.
Parameters
----------
x : array_like
1-D array of points at which the derivative is to be computed.
Returns
-------
rosen_der : (N,) ndarray
The gradient of the Rosenbrock function at `x`.
See Also
--------
rosen, rosen_hess, rosen_hess_prod
"""
x = asarray(x)
xm = x[1:-1]
xm_m1 = x[:-2]
xm_p1 = x[2:]
der = numpy.zeros_like(x)
der[1:-1] = (200 * (xm - xm_m1**2) -
400 * (xm_p1 - xm**2) * xm - 2 * (1 - xm))
der[0] = -400 * x[0] * (x[1] - x[0]**2) - 2 * (1 - x[0])
der[-1] = 200 * (x[-1] - x[-2]**2)
return der
def rosen_hess(x):
"""
The Hessian matrix of the Rosenbrock function.
Parameters
----------
x : array_like
1-D array of points at which the Hessian matrix is to be computed.
Returns
-------
rosen_hess : ndarray
The Hessian matrix of the Rosenbrock function at `x`.
See Also
--------
rosen, rosen_der, rosen_hess_prod
"""
x = atleast_1d(x)
H = numpy.diag(-400 * x[:-1], 1) - numpy.diag(400 * x[:-1], -1)
diagonal = numpy.zeros(len(x), dtype=x.dtype)
diagonal[0] = 1200 * x[0]**2 - 400 * x[1] + 2
diagonal[-1] = 200
diagonal[1:-1] = 202 + 1200 * x[1:-1]**2 - 400 * x[2:]
H = H + numpy.diag(diagonal)
return H
def rosen_hess_prod(x, p):
"""
Product of the Hessian matrix of the Rosenbrock function with a vector.
Parameters
----------
x : array_like
1-D array of points at which the Hessian matrix is to be computed.
p : array_like
1-D array, the vector to be multiplied by the Hessian matrix.
Returns
-------
rosen_hess_prod : ndarray
The Hessian matrix of the Rosenbrock function at `x` multiplied
by the vector `p`.
See Also
--------
rosen, rosen_der, rosen_hess
"""
x = atleast_1d(x)
Hp = numpy.zeros(len(x), dtype=x.dtype)
Hp[0] = (1200 * x[0]**2 - 400 * x[1] + 2) * p[0] - 400 * x[0] * p[1]
Hp[1:-1] = (-400 * x[:-2] * p[:-2] +
(202 + 1200 * x[1:-1]**2 - 400 * x[2:]) * p[1:-1] -
400 * x[1:-1] * p[2:])
Hp[-1] = -400 * x[-2] * p[-2] + 200*p[-1]
return Hp
def wrap_function(function, args):
ncalls = [0]
if function is None:
return ncalls, None
def function_wrapper(*wrapper_args):
ncalls[0] += 1
return function(*(wrapper_args + args))
return ncalls, function_wrapper
def fmin(func, x0, args=(), xtol=1e-4, ftol=1e-4, maxiter=None, maxfun=None,
full_output=0, disp=1, retall=0, callback=None, initial_simplex=None):
"""
Minimize a function using the downhill simplex algorithm.
This algorithm only uses function values, not derivatives or second
derivatives.
Parameters
----------
func : callable func(x,*args)
The objective function to be minimized.
x0 : ndarray
Initial guess.
args : tuple, optional
Extra arguments passed to func, i.e. ``f(x,*args)``.
xtol : float, optional
Absolute error in xopt between iterations that is acceptable for
convergence.
ftol : number, optional
Absolute error in func(xopt) between iterations that is acceptable for
convergence.
maxiter : int, optional
Maximum number of iterations to perform.
maxfun : number, optional
Maximum number of function evaluations to make.
full_output : bool, optional
Set to True if fopt and warnflag outputs are desired.
disp : bool, optional
Set to True to print convergence messages.
retall : bool, optional
Set to True to return list of solutions at each iteration.
callback : callable, optional
Called after each iteration, as callback(xk), where xk is the
current parameter vector.
initial_simplex : array_like of shape (N + 1, N), optional
Initial simplex. If given, overrides `x0`.
``initial_simplex[j,:]`` should contain the coordinates of
the j-th vertex of the ``N+1`` vertices in the simplex, where
``N`` is the dimension.
Returns
-------
xopt : ndarray
Parameter that minimizes function.
fopt : float
Value of function at minimum: ``fopt = func(xopt)``.
iter : int
Number of iterations performed.
funcalls : int
Number of function calls made.
warnflag : int
1 : Maximum number of function evaluations made.
2 : Maximum number of iterations reached.
allvecs : list
Solution at each iteration.
See also
--------
minimize: Interface to minimization algorithms for multivariate
functions. See the 'Nelder-Mead' `method` in particular.
Notes
-----
Uses a Nelder-Mead simplex algorithm to find the minimum of function of
one or more variables.
This algorithm has a long history of successful use in applications.
But it will usually be slower than an algorithm that uses first or
second derivative information. In practice it can have poor
performance in high-dimensional problems and is not robust to
minimizing complicated functions. Additionally, there currently is no
complete theory describing when the algorithm will successfully
converge to the minimum, or how fast it will if it does. Both the ftol and
xtol criteria must be met for convergence.
References
----------
.. [1] Nelder, J.A. and Mead, R. (1965), "A simplex method for function
minimization", The Computer Journal, 7, pp. 308-313
.. [2] Wright, M.H. (1996), "Direct Search Methods: Once Scorned, Now
Respectable", in Numerical Analysis 1995, Proceedings of the
1995 Dundee Biennial Conference in Numerical Analysis, D.F.
Griffiths and G.A. Watson (Eds.), Addison Wesley Longman,
Harlow, UK, pp. 191-208.
"""
opts = {'xatol': xtol,
'fatol': ftol,
'maxiter': maxiter,
'maxfev': maxfun,
'disp': disp,
'return_all': retall,
'initial_simplex': initial_simplex}
res = _minimize_neldermead(func, x0, args, callback=callback, **opts)
if full_output:
retlist = res['x'], res['fun'], res['nit'], res['nfev'], res['status']
if retall:
retlist += (res['allvecs'], )
return retlist
else:
if retall:
return res['x'], res['allvecs']
else:
return res['x']
def _minimize_neldermead(func, x0, args=(), callback=None,
maxiter=None, maxfev=None, disp=False,
return_all=False, initial_simplex=None,
xatol=1e-4, fatol=1e-4, **unknown_options):
"""
Minimization of scalar function of one or more variables using the
Nelder-Mead algorithm.
Options
-------
disp : bool
Set to True to print convergence messages.
maxiter, maxfev : int
Maximum allowed number of iterations and function evaluations.
Will default to ``N*200``, where ``N`` is the number of
variables, if neither `maxiter` or `maxfev` is set. If both
`maxiter` and `maxfev` are set, minimization will stop at the
first reached.
initial_simplex : array_like of shape (N + 1, N)
Initial simplex. If given, overrides `x0`.
``initial_simplex[j,:]`` should contain the coordinates of
the j-th vertex of the ``N+1`` vertices in the simplex, where
``N`` is the dimension.
xatol : float, optional
Absolute error in xopt between iterations that is acceptable for
convergence.
fatol : number, optional
Absolute error in func(xopt) between iterations that is acceptable for
convergence.
"""
if 'ftol' in unknown_options:
warnings.warn("ftol is deprecated for Nelder-Mead,"
" use fatol instead. If you specified both, only"
" fatol is used.",
DeprecationWarning)
if (np.isclose(fatol, 1e-4) and
not np.isclose(unknown_options['ftol'], 1e-4)):
# only ftol was probably specified, use it.
fatol = unknown_options['ftol']
unknown_options.pop('ftol')
if 'xtol' in unknown_options:
warnings.warn("xtol is deprecated for Nelder-Mead,"
" use xatol instead. If you specified both, only"
" xatol is used.",
DeprecationWarning)
if (np.isclose(xatol, 1e-4) and
not np.isclose(unknown_options['xtol'], 1e-4)):
# only xtol was probably specified, use it.
xatol = unknown_options['xtol']
unknown_options.pop('xtol')
_check_unknown_options(unknown_options)
maxfun = maxfev
retall = return_all
fcalls, func = wrap_function(func, args)
rho = 1
chi = 2
psi = 0.5
sigma = 0.5
nonzdelt = 0.05
zdelt = 0.00025
x0 = asfarray(x0).flatten()
if initial_simplex is None:
N = len(x0)
sim = numpy.zeros((N + 1, N), dtype=x0.dtype)
sim[0] = x0
for k in range(N):
y = numpy.array(x0, copy=True)
if y[k] != 0:
y[k] = (1 + nonzdelt)*y[k]
else:
y[k] = zdelt
sim[k + 1] = y
else:
sim = np.asfarray(initial_simplex).copy()
if sim.ndim != 2 or sim.shape[0] != sim.shape[1] + 1:
raise ValueError("`initial_simplex` should be an array of shape (N+1,N)")
if len(x0) != sim.shape[1]:
raise ValueError("Size of `initial_simplex` is not consistent with `x0`")
N = sim.shape[1]
if retall:
allvecs = [sim[0]]
# If neither are set, then set both to default
if maxiter is None and maxfun is None:
maxiter = N * 200
maxfun = N * 200
elif maxiter is None:
# Convert remaining Nones, to np.inf, unless the other is np.inf, in
# which case use the default to avoid unbounded iteration
if maxfun == np.inf:
maxiter = N * 200
else:
maxiter = np.inf
elif maxfun is None:
if maxiter == np.inf:
maxfun = N * 200
else:
maxfun = np.inf
one2np1 = list(range(1, N + 1))
fsim = numpy.zeros((N + 1,), float)
for k in range(N + 1):
fsim[k] = func(sim[k])
ind = numpy.argsort(fsim)
fsim = numpy.take(fsim, ind, 0)
# sort so sim[0,:] has the lowest function value
sim = numpy.take(sim, ind, 0)
iterations = 1
while (fcalls[0] < maxfun and iterations < maxiter):
if (numpy.max(numpy.ravel(numpy.abs(sim[1:] - sim[0]))) <= xatol and
numpy.max(numpy.abs(fsim[0] - fsim[1:])) <= fatol):
break
xbar = numpy.add.reduce(sim[:-1], 0) / N
xr = (1 + rho) * xbar - rho * sim[-1]
fxr = func(xr)
doshrink = 0
if fxr < fsim[0]:
xe = (1 + rho * chi) * xbar - rho * chi * sim[-1]
fxe = func(xe)
if fxe < fxr:
sim[-1] = xe
fsim[-1] = fxe
else:
sim[-1] = xr
fsim[-1] = fxr
else: # fsim[0] <= fxr
if fxr < fsim[-2]:
sim[-1] = xr
fsim[-1] = fxr
else: # fxr >= fsim[-2]
# Perform contraction
if fxr < fsim[-1]:
xc = (1 + psi * rho) * xbar - psi * rho * sim[-1]
fxc = func(xc)
if fxc <= fxr:
sim[-1] = xc
fsim[-1] = fxc
else:
doshrink = 1
else:
# Perform an inside contraction
xcc = (1 - psi) * xbar + psi * sim[-1]
fxcc = func(xcc)
if fxcc < fsim[-1]:
sim[-1] = xcc
fsim[-1] = fxcc
else:
doshrink = 1
if doshrink:
for j in one2np1:
sim[j] = sim[0] + sigma * (sim[j] - sim[0])
fsim[j] = func(sim[j])
ind = numpy.argsort(fsim)
sim = numpy.take(sim, ind, 0)
fsim = numpy.take(fsim, ind, 0)
if callback is not None:
callback(sim[0])
iterations += 1
if retall:
allvecs.append(sim[0])
x = sim[0]
fval = numpy.min(fsim)
warnflag = 0
if fcalls[0] >= maxfun:
warnflag = 1
msg = _status_message['maxfev']
if disp:
print('Warning: ' + msg)
elif iterations >= maxiter:
warnflag = 2
msg = _status_message['maxiter']
if disp:
print('Warning: ' + msg)
else:
msg = _status_message['success']
if disp:
print(msg)
print(" Current function value: %f" % fval)
print(" Iterations: %d" % iterations)
print(" Function evaluations: %d" % fcalls[0])
result = OptimizeResult(fun=fval, nit=iterations, nfev=fcalls[0],
status=warnflag, success=(warnflag == 0),
message=msg, x=x, final_simplex=(sim, fsim))
if retall:
result['allvecs'] = allvecs
return result
def _approx_fprime_helper(xk, f, epsilon, args=(), f0=None):
"""
See ``approx_fprime``. An optional initial function value arg is added.
"""
if f0 is None:
f0 = f(*((xk,) + args))
grad = numpy.zeros((len(xk),), float)
ei = numpy.zeros((len(xk),), float)
for k in range(len(xk)):
ei[k] = 1.0
d = epsilon * ei
grad[k] = (f(*((xk + d,) + args)) - f0) / d[k]
ei[k] = 0.0
return grad
def approx_fprime(xk, f, epsilon, *args):
"""Finite-difference approximation of the gradient of a scalar function.
Parameters
----------
xk : array_like
The coordinate vector at which to determine the gradient of `f`.
f : callable
The function of which to determine the gradient (partial derivatives).
Should take `xk` as first argument, other arguments to `f` can be
supplied in ``*args``. Should return a scalar, the value of the
function at `xk`.
epsilon : array_like
Increment to `xk` to use for determining the function gradient.
If a scalar, uses the same finite difference delta for all partial
derivatives. If an array, should contain one value per element of
`xk`.
\\*args : args, optional
Any other arguments that are to be passed to `f`.
Returns
-------
grad : ndarray
The partial derivatives of `f` to `xk`.
See Also
--------
check_grad : Check correctness of gradient function against approx_fprime.
Notes
-----
The function gradient is determined by the forward finite difference
formula::
f(xk[i] + epsilon[i]) - f(xk[i])
f'[i] = ---------------------------------
epsilon[i]
The main use of `approx_fprime` is in scalar function optimizers like
`fmin_bfgs`, to determine numerically the Jacobian of a function.
Examples
--------
>>> from scipy import optimize
>>> def func(x, c0, c1):
... "Coordinate vector `x` should be an array of size two."
... return c0 * x[0]**2 + c1*x[1]**2
>>> x = np.ones(2)
>>> c0, c1 = (1, 200)
>>> eps = np.sqrt(np.finfo(float).eps)
>>> optimize.approx_fprime(x, func, [eps, np.sqrt(200) * eps], c0, c1)
array([ 2. , 400.00004198])
"""
return _approx_fprime_helper(xk, f, epsilon, args=args)
def check_grad(func, grad, x0, *args, **kwargs):
"""Check the correctness of a gradient function by comparing it against a
(forward) finite-difference approximation of the gradient.
Parameters
----------
func : callable ``func(x0, *args)``
Function whose derivative is to be checked.
grad : callable ``grad(x0, *args)``
Gradient of `func`.
x0 : ndarray
Points to check `grad` against forward difference approximation of grad
using `func`.
args : \\*args, optional
Extra arguments passed to `func` and `grad`.
epsilon : float, optional
Step size used for the finite difference approximation. It defaults to
``sqrt(numpy.finfo(float).eps)``, which is approximately 1.49e-08.
Returns
-------
err : float
The square root of the sum of squares (i.e. the 2-norm) of the
difference between ``grad(x0, *args)`` and the finite difference
approximation of `grad` using func at the points `x0`.
See Also
--------
approx_fprime
Examples
--------
>>> def func(x):
... return x[0]**2 - 0.5 * x[1]**3
>>> def grad(x):
... return [2 * x[0], -1.5 * x[1]**2]
>>> from scipy.optimize import check_grad
>>> check_grad(func, grad, [1.5, -1.5])
2.9802322387695312e-08
"""
step = kwargs.pop('epsilon', _epsilon)
if kwargs:
raise ValueError("Unknown keyword arguments: %r" %
(list(kwargs.keys()),))
return sqrt(sum((grad(x0, *args) -
approx_fprime(x0, func, step, *args))**2))
def approx_fhess_p(x0, p, fprime, epsilon, *args):
f2 = fprime(*((x0 + epsilon*p,) + args))
f1 = fprime(*((x0,) + args))
return (f2 - f1) / epsilon
class _LineSearchError(RuntimeError):
pass
def _line_search_wolfe12(f, fprime, xk, pk, gfk, old_fval, old_old_fval,
**kwargs):
"""
Same as line_search_wolfe1, but fall back to line_search_wolfe2 if
suitable step length is not found, and raise an exception if a
suitable step length is not found.
Raises
------
_LineSearchError
If no suitable step size is found
"""
ret = line_search_wolfe1(f, fprime, xk, pk, gfk,
old_fval, old_old_fval,
**kwargs)
if ret[0] is None:
# line search failed: try different one.
with warnings.catch_warnings():
warnings.simplefilter('ignore', LineSearchWarning)
ret = line_search_wolfe2(f, fprime, xk, pk, gfk,
old_fval, old_old_fval)
if ret[0] is None:
raise _LineSearchError()
return ret
def fmin_bfgs(f, x0, fprime=None, args=(), gtol=1e-5, norm=Inf,
epsilon=_epsilon, maxiter=None, full_output=0, disp=1,
retall=0, callback=None):
"""
Minimize a function using the BFGS algorithm.
Parameters
----------
f : callable f(x,*args)
Objective function to be minimized.
x0 : ndarray
Initial guess.
fprime : callable f'(x,*args), optional
Gradient of f.
args : tuple, optional
Extra arguments passed to f and fprime.
gtol : float, optional
Gradient norm must be less than gtol before successful termination.
norm : float, optional
Order of norm (Inf is max, -Inf is min)
epsilon : int or ndarray, optional
If fprime is approximated, use this value for the step size.
callback : callable, optional
An optional user-supplied function to call after each
iteration. Called as callback(xk), where xk is the
current parameter vector.
maxiter : int, optional
Maximum number of iterations to perform.
full_output : bool, optional
If True,return fopt, func_calls, grad_calls, and warnflag
in addition to xopt.
disp : bool, optional
Print convergence message if True.
retall : bool, optional
Return a list of results at each iteration if True.
Returns
-------
xopt : ndarray
Parameters which minimize f, i.e. f(xopt) == fopt.
fopt : float
Minimum value.
gopt : ndarray
Value of gradient at minimum, f'(xopt), which should be near 0.
Bopt : ndarray
Value of 1/f''(xopt), i.e. the inverse hessian matrix.
func_calls : int
Number of function_calls made.
grad_calls : int
Number of gradient calls made.
warnflag : integer
1 : Maximum number of iterations exceeded.
2 : Gradient and/or function calls not changing.
allvecs : list
`OptimizeResult` at each iteration. Only returned if retall is True.
See also
--------
minimize: Interface to minimization algorithms for multivariate
functions. See the 'BFGS' `method` in particular.
Notes
-----
Optimize the function, f, whose gradient is given by fprime
using the quasi-Newton method of Broyden, Fletcher, Goldfarb,
and Shanno (BFGS)
References
----------
Wright, and Nocedal 'Numerical Optimization', 1999, pg. 198.
"""
opts = {'gtol': gtol,
'norm': norm,
'eps': epsilon,
'disp': disp,
'maxiter': maxiter,
'return_all': retall}
res = _minimize_bfgs(f, x0, args, fprime, callback=callback, **opts)
if full_output:
retlist = (res['x'], res['fun'], res['jac'], res['hess_inv'],
res['nfev'], res['njev'], res['status'])
if retall:
retlist += (res['allvecs'], )
return retlist
else:
if retall:
return res['x'], res['allvecs']
else:
return res['x']
def _minimize_bfgs(fun, x0, args=(), jac=None, callback=None,
gtol=1e-5, norm=Inf, eps=_epsilon, maxiter=None,
disp=False, return_all=False,
**unknown_options):
"""
Minimization of scalar function of one or more variables using the
BFGS algorithm.
Options
-------
disp : bool
Set to True to print convergence messages.
maxiter : int
Maximum number of iterations to perform.
gtol : float
Gradient norm must be less than `gtol` before successful
termination.
norm : float
Order of norm (Inf is max, -Inf is min).
eps : float or ndarray
If `jac` is approximated, use this value for the step size.
"""
_check_unknown_options(unknown_options)
f = fun
fprime = jac
epsilon = eps
retall = return_all
x0 = asarray(x0).flatten()
if x0.ndim == 0:
x0.shape = (1,)
if maxiter is None:
maxiter = len(x0) * 200
func_calls, f = wrap_function(f, args)
if fprime is None:
grad_calls, myfprime = wrap_function(approx_fprime, (f, epsilon))
else:
grad_calls, myfprime = wrap_function(fprime, args)
gfk = myfprime(x0)
k = 0
N = len(x0)
I = numpy.eye(N, dtype=int)
Hk = I
# Sets the initial step guess to dx ~ 1
old_fval = f(x0)
old_old_fval = old_fval + np.linalg.norm(gfk) / 2
xk = x0
if retall:
allvecs = [x0]
sk = [2 * gtol]
warnflag = 0
gnorm = vecnorm(gfk, ord=norm)
while (gnorm > gtol) and (k < maxiter):
pk = -numpy.dot(Hk, gfk)
try:
alpha_k, fc, gc, old_fval, old_old_fval, gfkp1 = \
_line_search_wolfe12(f, myfprime, xk, pk, gfk,
old_fval, old_old_fval, amin=1e-100, amax=1e100)
except _LineSearchError:
# Line search failed to find a better solution.
warnflag = 2
break
xkp1 = xk + alpha_k * pk
if retall:
allvecs.append(xkp1)
sk = xkp1 - xk
xk = xkp1
if gfkp1 is None:
gfkp1 = myfprime(xkp1)
yk = gfkp1 - gfk
gfk = gfkp1
if callback is not None:
callback(xk)
k += 1
gnorm = vecnorm(gfk, ord=norm)
if (gnorm <= gtol):
break
if not numpy.isfinite(old_fval):
# We correctly found +-Inf as optimal value, or something went
# wrong.
warnflag = 2
break
try: # this was handled in numeric, let it remaines for more safety
rhok = 1.0 / (numpy.dot(yk, sk))
except ZeroDivisionError:
rhok = 1000.0
if disp:
print("Divide-by-zero encountered: rhok assumed large")
if isinf(rhok): # this is patch for numpy
rhok = 1000.0
if disp:
print("Divide-by-zero encountered: rhok assumed large")
A1 = I - sk[:, numpy.newaxis] * yk[numpy.newaxis, :] * rhok
A2 = I - yk[:, numpy.newaxis] * sk[numpy.newaxis, :] * rhok
Hk = numpy.dot(A1, numpy.dot(Hk, A2)) + (rhok * sk[:, numpy.newaxis] *
sk[numpy.newaxis, :])
fval = old_fval
if np.isnan(fval):
# This can happen if the first call to f returned NaN;
# the loop is then never entered.
warnflag = 2
if warnflag == 2:
msg = _status_message['pr_loss']
if disp:
print("Warning: " + msg)
print(" Current function value: %f" % fval)
print(" Iterations: %d" % k)
print(" Function evaluations: %d" % func_calls[0])
print(" Gradient evaluations: %d" % grad_calls[0])
elif k >= maxiter:
warnflag = 1
msg = _status_message['maxiter']
if disp:
print("Warning: " + msg)
print(" Current function value: %f" % fval)
print(" Iterations: %d" % k)
print(" Function evaluations: %d" % func_calls[0])
print(" Gradient evaluations: %d" % grad_calls[0])
else:
msg = _status_message['success']
if disp:
print(msg)
print(" Current function value: %f" % fval)
print(" Iterations: %d" % k)
print(" Function evaluations: %d" % func_calls[0])
print(" Gradient evaluations: %d" % grad_calls[0])
result = OptimizeResult(fun=fval, jac=gfk, hess_inv=Hk, nfev=func_calls[0],
njev=grad_calls[0], status=warnflag,
success=(warnflag == 0), message=msg, x=xk,
nit=k)
if retall:
result['allvecs'] = allvecs
return result
def fmin_cg(f, x0, fprime=None, args=(), gtol=1e-5, norm=Inf, epsilon=_epsilon,
maxiter=None, full_output=0, disp=1, retall=0, callback=None):
"""
Minimize a function using a nonlinear conjugate gradient algorithm.
Parameters
----------
f : callable, ``f(x, *args)``
Objective function to be minimized. Here `x` must be a 1-D array of
the variables that are to be changed in the search for a minimum, and
`args` are the other (fixed) parameters of `f`.
x0 : ndarray
A user-supplied initial estimate of `xopt`, the optimal value of `x`.
It must be a 1-D array of values.
fprime : callable, ``fprime(x, *args)``, optional
A function that returns the gradient of `f` at `x`. Here `x` and `args`
are as described above for `f`. The returned value must be a 1-D array.
Defaults to None, in which case the gradient is approximated
numerically (see `epsilon`, below).
args : tuple, optional
Parameter values passed to `f` and `fprime`. Must be supplied whenever
additional fixed parameters are needed to completely specify the
functions `f` and `fprime`.
gtol : float, optional
Stop when the norm of the gradient is less than `gtol`.
norm : float, optional
Order to use for the norm of the gradient
(``-np.Inf`` is min, ``np.Inf`` is max).
epsilon : float or ndarray, optional
Step size(s) to use when `fprime` is approximated numerically. Can be a
scalar or a 1-D array. Defaults to ``sqrt(eps)``, with eps the
floating point machine precision. Usually ``sqrt(eps)`` is about
1.5e-8.
maxiter : int, optional
Maximum number of iterations to perform. Default is ``200 * len(x0)``.
full_output : bool, optional
If True, return `fopt`, `func_calls`, `grad_calls`, and `warnflag` in
addition to `xopt`. See the Returns section below for additional
information on optional return values.
disp : bool, optional
If True, return a convergence message, followed by `xopt`.
retall : bool, optional
If True, add to the returned values the results of each iteration.
callback : callable, optional
An optional user-supplied function, called after each iteration.
Called as ``callback(xk)``, where ``xk`` is the current value of `x0`.
Returns
-------
xopt : ndarray
Parameters which minimize f, i.e. ``f(xopt) == fopt``.
fopt : float, optional
Minimum value found, f(xopt). Only returned if `full_output` is True.
func_calls : int, optional
The number of function_calls made. Only returned if `full_output`
is True.
grad_calls : int, optional
The number of gradient calls made. Only returned if `full_output` is
True.
warnflag : int, optional
Integer value with warning status, only returned if `full_output` is
True.
0 : Success.
1 : The maximum number of iterations was exceeded.
2 : Gradient and/or function calls were not changing. May indicate
that precision was lost, i.e., the routine did not converge.
allvecs : list of ndarray, optional
List of arrays, containing the results at each iteration.
Only returned if `retall` is True.
See Also
--------
minimize : common interface to all `scipy.optimize` algorithms for
unconstrained and constrained minimization of multivariate
functions. It provides an alternative way to call
``fmin_cg``, by specifying ``method='CG'``.
Notes
-----
This conjugate gradient algorithm is based on that of Polak and Ribiere
[1]_.
Conjugate gradient methods tend to work better when:
1. `f` has a unique global minimizing point, and no local minima or
other stationary points,
2. `f` is, at least locally, reasonably well approximated by a
quadratic function of the variables,
3. `f` is continuous and has a continuous gradient,
4. `fprime` is not too large, e.g., has a norm less than 1000,
5. The initial guess, `x0`, is reasonably close to `f` 's global
minimizing point, `xopt`.
References
----------
.. [1] Wright & Nocedal, "Numerical Optimization", 1999, pp. 120-122.
Examples
--------
Example 1: seek the minimum value of the expression
``a*u**2 + b*u*v + c*v**2 + d*u + e*v + f`` for given values
of the parameters and an initial guess ``(u, v) = (0, 0)``.
>>> args = (2, 3, 7, 8, 9, 10) # parameter values
>>> def f(x, *args):
... u, v = x
... a, b, c, d, e, f = args
... return a*u**2 + b*u*v + c*v**2 + d*u + e*v + f
>>> def gradf(x, *args):
... u, v = x
... a, b, c, d, e, f = args
... gu = 2*a*u + b*v + d # u-component of the gradient
... gv = b*u + 2*c*v + e # v-component of the gradient
... return np.asarray((gu, gv))
>>> x0 = np.asarray((0, 0)) # Initial guess.
>>> from scipy import optimize
>>> res1 = optimize.fmin_cg(f, x0, fprime=gradf, args=args)
Optimization terminated successfully.
Current function value: 1.617021
Iterations: 4
Function evaluations: 8
Gradient evaluations: 8
>>> res1
array([-1.80851064, -0.25531915])
Example 2: solve the same problem using the `minimize` function.
(This `myopts` dictionary shows all of the available options,
although in practice only non-default values would be needed.
The returned value will be a dictionary.)
>>> opts = {'maxiter' : None, # default value.
... 'disp' : True, # non-default value.
... 'gtol' : 1e-5, # default value.
... 'norm' : np.inf, # default value.
... 'eps' : 1.4901161193847656e-08} # default value.
>>> res2 = optimize.minimize(f, x0, jac=gradf, args=args,
... method='CG', options=opts)
Optimization terminated successfully.
Current function value: 1.617021
Iterations: 4
Function evaluations: 8
Gradient evaluations: 8
>>> res2.x # minimum found
array([-1.80851064, -0.25531915])
"""
opts = {'gtol': gtol,
'norm': norm,
'eps': epsilon,
'disp': disp,
'maxiter': maxiter,
'return_all': retall}
res = _minimize_cg(f, x0, args, fprime, callback=callback, **opts)
if full_output:
retlist = res['x'], res['fun'], res['nfev'], res['njev'], res['status']
if retall:
retlist += (res['allvecs'], )
return retlist
else:
if retall:
return res['x'], res['allvecs']
else:
return res['x']
def _minimize_cg(fun, x0, args=(), jac=None, callback=None,
gtol=1e-5, norm=Inf, eps=_epsilon, maxiter=None,
disp=False, return_all=False,
**unknown_options):
"""
Minimization of scalar function of one or more variables using the
conjugate gradient algorithm.
Options
-------
disp : bool
Set to True to print convergence messages.
maxiter : int
Maximum number of iterations to perform.
gtol : float
Gradient norm must be less than `gtol` before successful
termination.
norm : float
Order of norm (Inf is max, -Inf is min).
eps : float or ndarray
If `jac` is approximated, use this value for the step size.
"""
_check_unknown_options(unknown_options)
f = fun
fprime = jac
epsilon = eps
retall = return_all
x0 = asarray(x0).flatten()
if maxiter is None:
maxiter = len(x0) * 200
func_calls, f = wrap_function(f, args)
if fprime is None:
grad_calls, myfprime = wrap_function(approx_fprime, (f, epsilon))
else:
grad_calls, myfprime = wrap_function(fprime, args)
gfk = myfprime(x0)
k = 0
xk = x0
# Sets the initial step guess to dx ~ 1
old_fval = f(xk)
old_old_fval = old_fval + np.linalg.norm(gfk) / 2
if retall:
allvecs = [xk]
warnflag = 0
pk = -gfk
gnorm = vecnorm(gfk, ord=norm)
while (gnorm > gtol) and (k < maxiter):
deltak = numpy.dot(gfk, gfk)
try:
alpha_k, fc, gc, old_fval, old_old_fval, gfkp1 = \
_line_search_wolfe12(f, myfprime, xk, pk, gfk, old_fval,
old_old_fval, c2=0.4, amin=1e-100, amax=1e100)
except _LineSearchError:
# Line search failed to find a better solution.
warnflag = 2
break
xk = xk + alpha_k * pk
if retall:
allvecs.append(xk)
if gfkp1 is None:
gfkp1 = myfprime(xk)
yk = gfkp1 - gfk
beta_k = max(0, numpy.dot(yk, gfkp1) / deltak)
pk = -gfkp1 + beta_k * pk
gfk = gfkp1
gnorm = vecnorm(gfk, ord=norm)
if callback is not None:
callback(xk)
k += 1
fval = old_fval
if warnflag == 2:
msg = _status_message['pr_loss']
if disp:
print("Warning: " + msg)
print(" Current function value: %f" % fval)
print(" Iterations: %d" % k)
print(" Function evaluations: %d" % func_calls[0])
print(" Gradient evaluations: %d" % grad_calls[0])
elif k >= maxiter:
warnflag = 1
msg = _status_message['maxiter']
if disp:
print("Warning: " + msg)
print(" Current function value: %f" % fval)
print(" Iterations: %d" % k)
print(" Function evaluations: %d" % func_calls[0])
print(" Gradient evaluations: %d" % grad_calls[0])
else:
msg = _status_message['success']
if disp:
print(msg)
print(" Current function value: %f" % fval)
print(" Iterations: %d" % k)
print(" Function evaluations: %d" % func_calls[0])
print(" Gradient evaluations: %d" % grad_calls[0])
result = OptimizeResult(fun=fval, jac=gfk, nfev=func_calls[0],
njev=grad_calls[0], status=warnflag,
success=(warnflag == 0), message=msg, x=xk,
nit=k)
if retall:
result['allvecs'] = allvecs
return result
def fmin_ncg(f, x0, fprime, fhess_p=None, fhess=None, args=(), avextol=1e-5,
epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0,
callback=None):
"""
Unconstrained minimization of a function using the Newton-CG method.
Parameters
----------
f : callable ``f(x, *args)``
Objective function to be minimized.
x0 : ndarray
Initial guess.
fprime : callable ``f'(x, *args)``
Gradient of f.
fhess_p : callable ``fhess_p(x, p, *args)``, optional
Function which computes the Hessian of f times an
arbitrary vector, p.
fhess : callable ``fhess(x, *args)``, optional
Function to compute the Hessian matrix of f.
args : tuple, optional
Extra arguments passed to f, fprime, fhess_p, and fhess
(the same set of extra arguments is supplied to all of
these functions).
epsilon : float or ndarray, optional
If fhess is approximated, use this value for the step size.
callback : callable, optional
An optional user-supplied function which is called after
each iteration. Called as callback(xk), where xk is the
current parameter vector.
avextol : float, optional
Convergence is assumed when the average relative error in
the minimizer falls below this amount.
maxiter : int, optional
Maximum number of iterations to perform.
full_output : bool, optional
If True, return the optional outputs.
disp : bool, optional
If True, print convergence message.
retall : bool, optional
If True, return a list of results at each iteration.
Returns
-------
xopt : ndarray
Parameters which minimize f, i.e. ``f(xopt) == fopt``.
fopt : float
Value of the function at xopt, i.e. ``fopt = f(xopt)``.
fcalls : int
Number of function calls made.
gcalls : int
Number of gradient calls made.
hcalls : int
Number of hessian calls made.
warnflag : int
Warnings generated by the algorithm.
1 : Maximum number of iterations exceeded.
allvecs : list
The result at each iteration, if retall is True (see below).
See also
--------
minimize: Interface to minimization algorithms for multivariate
functions. See the 'Newton-CG' `method` in particular.
Notes
-----
Only one of `fhess_p` or `fhess` need to be given. If `fhess`
is provided, then `fhess_p` will be ignored. If neither `fhess`
nor `fhess_p` is provided, then the hessian product will be
approximated using finite differences on `fprime`. `fhess_p`
must compute the hessian times an arbitrary vector. If it is not
given, finite-differences on `fprime` are used to compute
it.
Newton-CG methods are also called truncated Newton methods. This
function differs from scipy.optimize.fmin_tnc because
1. scipy.optimize.fmin_ncg is written purely in python using numpy
and scipy while scipy.optimize.fmin_tnc calls a C function.
2. scipy.optimize.fmin_ncg is only for unconstrained minimization
while scipy.optimize.fmin_tnc is for unconstrained minimization
or box constrained minimization. (Box constraints give
lower and upper bounds for each variable separately.)
References
----------
Wright & Nocedal, 'Numerical Optimization', 1999, pg. 140.
"""
opts = {'xtol': avextol,
'eps': epsilon,
'maxiter': maxiter,
'disp': disp,
'return_all': retall}
res = _minimize_newtoncg(f, x0, args, fprime, fhess, fhess_p,
callback=callback, **opts)
if full_output:
retlist = (res['x'], res['fun'], res['nfev'], res['njev'],
res['nhev'], res['status'])
if retall:
retlist += (res['allvecs'], )
return retlist
else:
if retall:
return res['x'], res['allvecs']
else:
return res['x']
def _minimize_newtoncg(fun, x0, args=(), jac=None, hess=None, hessp=None,
callback=None, xtol=1e-5, eps=_epsilon, maxiter=None,
disp=False, return_all=False,
**unknown_options):
"""
Minimization of scalar function of one or more variables using the
Newton-CG algorithm.
Note that the `jac` parameter (Jacobian) is required.
Options
-------
disp : bool
Set to True to print convergence messages.
xtol : float
Average relative error in solution `xopt` acceptable for
convergence.
maxiter : int
Maximum number of iterations to perform.
eps : float or ndarray
If `jac` is approximated, use this value for the step size.
"""
_check_unknown_options(unknown_options)
if jac is None:
raise ValueError('Jacobian is required for Newton-CG method')
f = fun
fprime = jac
fhess_p = hessp
fhess = hess
avextol = xtol
epsilon = eps
retall = return_all
def terminate(warnflag, msg):
if disp:
print(msg)
print(" Current function value: %f" % old_fval)
print(" Iterations: %d" % k)
print(" Function evaluations: %d" % fcalls[0])
print(" Gradient evaluations: %d" % gcalls[0])
print(" Hessian evaluations: %d" % hcalls)
fval = old_fval
result = OptimizeResult(fun=fval, jac=gfk, nfev=fcalls[0],
njev=gcalls[0], nhev=hcalls, status=warnflag,
success=(warnflag == 0), message=msg, x=xk,
nit=k)
if retall:
result['allvecs'] = allvecs
return result
x0 = asarray(x0).flatten()
fcalls, f = wrap_function(f, args)
gcalls, fprime = wrap_function(fprime, args)
hcalls = 0
if maxiter is None:
maxiter = len(x0)*200
cg_maxiter = 20*len(x0)
xtol = len(x0) * avextol
update = [2 * xtol]
xk = x0
if retall:
allvecs = [xk]
k = 0
old_fval = f(x0)
old_old_fval = None
float64eps = numpy.finfo(numpy.float64).eps
while numpy.add.reduce(numpy.abs(update)) > xtol:
if k >= maxiter:
msg = "Warning: " + _status_message['maxiter']
return terminate(1, msg)
# Compute a search direction pk by applying the CG method to
# del2 f(xk) p = - grad f(xk) starting from 0.
b = -fprime(xk)
maggrad = numpy.add.reduce(numpy.abs(b))
eta = numpy.min([0.5, numpy.sqrt(maggrad)])
termcond = eta * maggrad
xsupi = zeros(len(x0), dtype=x0.dtype)
ri = -b
psupi = -ri
i = 0
dri0 = numpy.dot(ri, ri)
if fhess is not None: # you want to compute hessian once.
A = fhess(*(xk,) + args)
hcalls = hcalls + 1
for k2 in xrange(cg_maxiter):
if numpy.add.reduce(numpy.abs(ri)) <= termcond:
break
if fhess is None:
if fhess_p is None:
Ap = approx_fhess_p(xk, psupi, fprime, epsilon)
else:
Ap = fhess_p(xk, psupi, *args)
hcalls = hcalls + 1
else:
Ap = numpy.dot(A, psupi)
# check curvature
Ap = asarray(Ap).squeeze() # get rid of matrices...
curv = numpy.dot(psupi, Ap)
if 0 <= curv <= 3 * float64eps:
break
elif curv < 0:
if (i > 0):
break
else:
# fall back to steepest descent direction
xsupi = dri0 / (-curv) * b
break
alphai = dri0 / curv
xsupi = xsupi + alphai * psupi
ri = ri + alphai * Ap
dri1 = numpy.dot(ri, ri)
betai = dri1 / dri0
psupi = -ri + betai * psupi
i = i + 1
dri0 = dri1 # update numpy.dot(ri,ri) for next time.
else:
# curvature keeps increasing, bail out
msg = ("Warning: CG iterations didn't converge. The Hessian is not "
"positive definite.")
return terminate(3, msg)
pk = xsupi # search direction is solution to system.
gfk = -b # gradient at xk
try:
alphak, fc, gc, old_fval, old_old_fval, gfkp1 = \
_line_search_wolfe12(f, fprime, xk, pk, gfk,
old_fval, old_old_fval)
except _LineSearchError:
# Line search failed to find a better solution.
msg = "Warning: " + _status_message['pr_loss']
return terminate(2, msg)
update = alphak * pk
xk = xk + update # upcast if necessary
if callback is not None:
callback(xk)
if retall:
allvecs.append(xk)
k += 1
else:
msg = _status_message['success']
return terminate(0, msg)
def fminbound(func, x1, x2, args=(), xtol=1e-5, maxfun=500,
full_output=0, disp=1):
"""Bounded minimization for scalar functions.
Parameters
----------
func : callable f(x,*args)
Objective function to be minimized (must accept and return scalars).
x1, x2 : float or array scalar
The optimization bounds.
args : tuple, optional
Extra arguments passed to function.
xtol : float, optional
The convergence tolerance.
maxfun : int, optional
Maximum number of function evaluations allowed.
full_output : bool, optional
If True, return optional outputs.
disp : int, optional
If non-zero, print messages.
0 : no message printing.
1 : non-convergence notification messages only.
2 : print a message on convergence too.
3 : print iteration results.
Returns
-------
xopt : ndarray
Parameters (over given interval) which minimize the
objective function.
fval : number
The function value at the minimum point.
ierr : int
An error flag (0 if converged, 1 if maximum number of
function calls reached).
numfunc : int
The number of function calls made.
See also
--------
minimize_scalar: Interface to minimization algorithms for scalar
univariate functions. See the 'Bounded' `method` in particular.
Notes
-----
Finds a local minimizer of the scalar function `func` in the
interval x1 < xopt < x2 using Brent's method. (See `brent`
for auto-bracketing).
"""
options = {'xatol': xtol,
'maxiter': maxfun,
'disp': disp}
res = _minimize_scalar_bounded(func, (x1, x2), args, **options)
if full_output:
return res['x'], res['fun'], res['status'], res['nfev']
else:
return res['x']
def _minimize_scalar_bounded(func, bounds, args=(),
xatol=1e-5, maxiter=500, disp=0,
**unknown_options):
"""
Options
-------
maxiter : int
Maximum number of iterations to perform.
disp : bool
Set to True to print convergence messages.
xatol : float
Absolute error in solution `xopt` acceptable for convergence.
"""
_check_unknown_options(unknown_options)
maxfun = maxiter
# Test bounds are of correct form
if len(bounds) != 2:
raise ValueError('bounds must have two elements.')
x1, x2 = bounds
if not (is_array_scalar(x1) and is_array_scalar(x2)):
raise ValueError("Optimisation bounds must be scalars"
" or array scalars.")
if x1 > x2:
raise ValueError("The lower bound exceeds the upper bound.")
flag = 0
header = ' Func-count x f(x) Procedure'
step = ' initial'
sqrt_eps = sqrt(2.2e-16)
golden_mean = 0.5 * (3.0 - sqrt(5.0))
a, b = x1, x2
fulc = a + golden_mean * (b - a)
nfc, xf = fulc, fulc
rat = e = 0.0
x = xf
fx = func(x, *args)
num = 1
fmin_data = (1, xf, fx)
ffulc = fnfc = fx
xm = 0.5 * (a + b)
tol1 = sqrt_eps * numpy.abs(xf) + xatol / 3.0
tol2 = 2.0 * tol1
if disp > 2:
print(" ")
print(header)
print("%5.0f %12.6g %12.6g %s" % (fmin_data + (step,)))
while (numpy.abs(xf - xm) > (tol2 - 0.5 * (b - a))):
golden = 1
# Check for parabolic fit
if numpy.abs(e) > tol1:
golden = 0
r = (xf - nfc) * (fx - ffulc)
q = (xf - fulc) * (fx - fnfc)
p = (xf - fulc) * q - (xf - nfc) * r
q = 2.0 * (q - r)
if q > 0.0:
p = -p
q = numpy.abs(q)
r = e
e = rat
# Check for acceptability of parabola
if ((numpy.abs(p) < numpy.abs(0.5*q*r)) and (p > q*(a - xf)) and
(p < q * (b - xf))):
rat = (p + 0.0) / q
x = xf + rat
step = ' parabolic'
if ((x - a) < tol2) or ((b - x) < tol2):
si = numpy.sign(xm - xf) + ((xm - xf) == 0)
rat = tol1 * si
else: # do a golden section step
golden = 1
if golden: # Do a golden-section step
if xf >= xm:
e = a - xf
else:
e = b - xf
rat = golden_mean*e
step = ' golden'
si = numpy.sign(rat) + (rat == 0)
x = xf + si * numpy.max([numpy.abs(rat), tol1])
fu = func(x, *args)
num += 1
fmin_data = (num, x, fu)
if disp > 2:
print("%5.0f %12.6g %12.6g %s" % (fmin_data + (step,)))
if fu <= fx:
if x >= xf:
a = xf
else:
b = xf
fulc, ffulc = nfc, fnfc
nfc, fnfc = xf, fx
xf, fx = x, fu
else:
if x < xf:
a = x
else:
b = x
if (fu <= fnfc) or (nfc == xf):
fulc, ffulc = nfc, fnfc
nfc, fnfc = x, fu
elif (fu <= ffulc) or (fulc == xf) or (fulc == nfc):
fulc, ffulc = x, fu
xm = 0.5 * (a + b)
tol1 = sqrt_eps * numpy.abs(xf) + xatol / 3.0
tol2 = 2.0 * tol1
if num >= maxfun:
flag = 1
break
fval = fx
if disp > 0:
_endprint(x, flag, fval, maxfun, xatol, disp)
result = OptimizeResult(fun=fval, status=flag, success=(flag == 0),
message={0: 'Solution found.',
1: 'Maximum number of function calls '
'reached.'}.get(flag, ''),
x=xf, nfev=num)
return result
class Brent:
#need to rethink design of __init__
def __init__(self, func, args=(), tol=1.48e-8, maxiter=500,
full_output=0):
self.func = func
self.args = args
self.tol = tol
self.maxiter = maxiter
self._mintol = 1.0e-11
self._cg = 0.3819660
self.xmin = None
self.fval = None
self.iter = 0
self.funcalls = 0
# need to rethink design of set_bracket (new options, etc)
def set_bracket(self, brack=None):
self.brack = brack
def get_bracket_info(self):
#set up
func = self.func
args = self.args
brack = self.brack
### BEGIN core bracket_info code ###
### carefully DOCUMENT any CHANGES in core ##
if brack is None:
xa, xb, xc, fa, fb, fc, funcalls = bracket(func, args=args)
elif len(brack) == 2:
xa, xb, xc, fa, fb, fc, funcalls = bracket(func, xa=brack[0],
xb=brack[1], args=args)
elif len(brack) == 3:
xa, xb, xc = brack
if (xa > xc): # swap so xa < xc can be assumed
xc, xa = xa, xc
if not ((xa < xb) and (xb < xc)):
raise ValueError("Not a bracketing interval.")
fa = func(*((xa,) + args))
fb = func(*((xb,) + args))
fc = func(*((xc,) + args))
if not ((fb < fa) and (fb < fc)):
raise ValueError("Not a bracketing interval.")
funcalls = 3
else:
raise ValueError("Bracketing interval must be "
"length 2 or 3 sequence.")
### END core bracket_info code ###
return xa, xb, xc, fa, fb, fc, funcalls
def optimize(self):
# set up for optimization
func = self.func
xa, xb, xc, fa, fb, fc, funcalls = self.get_bracket_info()
_mintol = self._mintol
_cg = self._cg
#################################
#BEGIN CORE ALGORITHM
#################################
x = w = v = xb
fw = fv = fx = func(*((x,) + self.args))
if (xa < xc):
a = xa
b = xc
else:
a = xc
b = xa
deltax = 0.0
funcalls = 1
iter = 0
while (iter < self.maxiter):
tol1 = self.tol * numpy.abs(x) + _mintol
tol2 = 2.0 * tol1
xmid = 0.5 * (a + b)
# check for convergence
if numpy.abs(x - xmid) < (tol2 - 0.5 * (b - a)):
break
# XXX In the first iteration, rat is only bound in the true case
# of this conditional. This used to cause an UnboundLocalError
# (gh-4140). It should be set before the if (but to what?).
if (numpy.abs(deltax) <= tol1):
if (x >= xmid):
deltax = a - x # do a golden section step
else:
deltax = b - x
rat = _cg * deltax
else: # do a parabolic step
tmp1 = (x - w) * (fx - fv)
tmp2 = (x - v) * (fx - fw)
p = (x - v) * tmp2 - (x - w) * tmp1
tmp2 = 2.0 * (tmp2 - tmp1)
if (tmp2 > 0.0):
p = -p
tmp2 = numpy.abs(tmp2)
dx_temp = deltax
deltax = rat
# check parabolic fit
if ((p > tmp2 * (a - x)) and (p < tmp2 * (b - x)) and
(numpy.abs(p) < numpy.abs(0.5 * tmp2 * dx_temp))):
rat = p * 1.0 / tmp2 # if parabolic step is useful.
u = x + rat
if ((u - a) < tol2 or (b - u) < tol2):
if xmid - x >= 0:
rat = tol1
else:
rat = -tol1
else:
if (x >= xmid):
deltax = a - x # if it's not do a golden section step
else:
deltax = b - x
rat = _cg * deltax
if (numpy.abs(rat) < tol1): # update by at least tol1
if rat >= 0:
u = x + tol1
else:
u = x - tol1
else:
u = x + rat
fu = func(*((u,) + self.args)) # calculate new output value
funcalls += 1
if (fu > fx): # if it's bigger than current
if (u < x):
a = u
else:
b = u
if (fu <= fw) or (w == x):
v = w
w = u
fv = fw
fw = fu
elif (fu <= fv) or (v == x) or (v == w):
v = u
fv = fu
else:
if (u >= x):
a = x
else:
b = x
v = w
w = x
x = u
fv = fw
fw = fx
fx = fu
iter += 1
#################################
#END CORE ALGORITHM
#################################
self.xmin = x
self.fval = fx
self.iter = iter
self.funcalls = funcalls
def get_result(self, full_output=False):
if full_output:
return self.xmin, self.fval, self.iter, self.funcalls
else:
return self.xmin
def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500):
"""
Given a function of one-variable and a possible bracketing interval,
return the minimum of the function isolated to a fractional precision of
tol.
Parameters
----------
func : callable f(x,*args)
Objective function.
args : tuple, optional
Additional arguments (if present).
brack : tuple, optional
Either a triple (xa,xb,xc) where xa<xb<xc and func(xb) <
func(xa), func(xc) or a pair (xa,xb) which are used as a
starting interval for a downhill bracket search (see
`bracket`). Providing the pair (xa,xb) does not always mean
the obtained solution will satisfy xa<=x<=xb.
tol : float, optional
Stop if between iteration change is less than `tol`.
full_output : bool, optional
If True, return all output args (xmin, fval, iter,
funcalls).
maxiter : int, optional
Maximum number of iterations in solution.
Returns
-------
xmin : ndarray
Optimum point.
fval : float
Optimum value.
iter : int
Number of iterations.
funcalls : int
Number of objective function evaluations made.
See also
--------
minimize_scalar: Interface to minimization algorithms for scalar
univariate functions. See the 'Brent' `method` in particular.
Notes
-----
Uses inverse parabolic interpolation when possible to speed up
convergence of golden section method.
"""
options = {'xtol': tol,
'maxiter': maxiter}
res = _minimize_scalar_brent(func, brack, args, **options)
if full_output:
return res['x'], res['fun'], res['nit'], res['nfev']
else:
return res['x']
def _minimize_scalar_brent(func, brack=None, args=(),
xtol=1.48e-8, maxiter=500,
**unknown_options):
"""
Options
-------
maxiter : int
Maximum number of iterations to perform.
xtol : float
Relative error in solution `xopt` acceptable for convergence.
Notes
-----
Uses inverse parabolic interpolation when possible to speed up
convergence of golden section method.
"""
_check_unknown_options(unknown_options)
tol = xtol
if tol < 0:
raise ValueError('tolerance should be >= 0, got %r' % tol)
brent = Brent(func=func, args=args, tol=tol,
full_output=True, maxiter=maxiter)
brent.set_bracket(brack)
brent.optimize()
x, fval, nit, nfev = brent.get_result(full_output=True)
return OptimizeResult(fun=fval, x=x, nit=nit, nfev=nfev,
success=nit < maxiter)
def golden(func, args=(), brack=None, tol=_epsilon,
full_output=0, maxiter=5000):
"""
Return the minimum of a function of one variable.
Given a function of one variable and a possible bracketing interval,
return the minimum of the function isolated to a fractional precision of
tol.
Parameters
----------
func : callable func(x,*args)
Objective function to minimize.
args : tuple, optional
Additional arguments (if present), passed to func.
brack : tuple, optional
Triple (a,b,c), where (a<b<c) and func(b) <
func(a),func(c). If bracket consists of two numbers (a,
c), then they are assumed to be a starting interval for a
downhill bracket search (see `bracket`); it doesn't always
mean that obtained solution will satisfy a<=x<=c.
tol : float, optional
x tolerance stop criterion
full_output : bool, optional
If True, return optional outputs.
maxiter : int
Maximum number of iterations to perform.
See also
--------
minimize_scalar: Interface to minimization algorithms for scalar
univariate functions. See the 'Golden' `method` in particular.
Notes
-----
Uses analog of bisection method to decrease the bracketed
interval.
"""
options = {'xtol': tol, 'maxiter': maxiter}
res = _minimize_scalar_golden(func, brack, args, **options)
if full_output:
return res['x'], res['fun'], res['nfev']
else:
return res['x']
def _minimize_scalar_golden(func, brack=None, args=(),
xtol=_epsilon, maxiter=5000, **unknown_options):
"""
Options
-------
maxiter : int
Maximum number of iterations to perform.
xtol : float
Relative error in solution `xopt` acceptable for convergence.
"""
_check_unknown_options(unknown_options)
tol = xtol
if brack is None:
xa, xb, xc, fa, fb, fc, funcalls = bracket(func, args=args)
elif len(brack) == 2:
xa, xb, xc, fa, fb, fc, funcalls = bracket(func, xa=brack[0],
xb=brack[1], args=args)
elif len(brack) == 3:
xa, xb, xc = brack
if (xa > xc): # swap so xa < xc can be assumed
xc, xa = xa, xc
if not ((xa < xb) and (xb < xc)):
raise ValueError("Not a bracketing interval.")
fa = func(*((xa,) + args))
fb = func(*((xb,) + args))
fc = func(*((xc,) + args))
if not ((fb < fa) and (fb < fc)):
raise ValueError("Not a bracketing interval.")
funcalls = 3
else:
raise ValueError("Bracketing interval must be length 2 or 3 sequence.")
_gR = 0.61803399 # golden ratio conjugate: 2.0/(1.0+sqrt(5.0))
_gC = 1.0 - _gR
x3 = xc
x0 = xa
if (numpy.abs(xc - xb) > numpy.abs(xb - xa)):
x1 = xb
x2 = xb + _gC * (xc - xb)
else:
x2 = xb
x1 = xb - _gC * (xb - xa)
f1 = func(*((x1,) + args))
f2 = func(*((x2,) + args))
funcalls += 2
nit = 0
for i in xrange(maxiter):
if numpy.abs(x3 - x0) <= tol * (numpy.abs(x1) + numpy.abs(x2)):
break
if (f2 < f1):
x0 = x1
x1 = x2
x2 = _gR * x1 + _gC * x3
f1 = f2
f2 = func(*((x2,) + args))
else:
x3 = x2
x2 = x1
x1 = _gR * x2 + _gC * x0
f2 = f1
f1 = func(*((x1,) + args))
funcalls += 1
nit += 1
if (f1 < f2):
xmin = x1
fval = f1
else:
xmin = x2
fval = f2
return OptimizeResult(fun=fval, nfev=funcalls, x=xmin, nit=nit,
success=nit < maxiter)
def bracket(func, xa=0.0, xb=1.0, args=(), grow_limit=110.0, maxiter=1000):
"""
Bracket the minimum of the function.
Given a function and distinct initial points, search in the
downhill direction (as defined by the initital points) and return
new points xa, xb, xc that bracket the minimum of the function
f(xa) > f(xb) < f(xc). It doesn't always mean that obtained
solution will satisfy xa<=x<=xb
Parameters
----------
func : callable f(x,*args)
Objective function to minimize.
xa, xb : float, optional
Bracketing interval. Defaults `xa` to 0.0, and `xb` to 1.0.
args : tuple, optional
Additional arguments (if present), passed to `func`.
grow_limit : float, optional
Maximum grow limit. Defaults to 110.0
maxiter : int, optional
Maximum number of iterations to perform. Defaults to 1000.
Returns
-------
xa, xb, xc : float
Bracket.
fa, fb, fc : float
Objective function values in bracket.
funcalls : int
Number of function evaluations made.
"""
_gold = 1.618034 # golden ratio: (1.0+sqrt(5.0))/2.0
_verysmall_num = 1e-21
fa = func(*(xa,) + args)
fb = func(*(xb,) + args)
if (fa < fb): # Switch so fa > fb
xa, xb = xb, xa
fa, fb = fb, fa
xc = xb + _gold * (xb - xa)
fc = func(*((xc,) + args))
funcalls = 3
iter = 0
while (fc < fb):
tmp1 = (xb - xa) * (fb - fc)
tmp2 = (xb - xc) * (fb - fa)
val = tmp2 - tmp1
if numpy.abs(val) < _verysmall_num:
denom = 2.0 * _verysmall_num
else:
denom = 2.0 * val
w = xb - ((xb - xc) * tmp2 - (xb - xa) * tmp1) / denom
wlim = xb + grow_limit * (xc - xb)
if iter > maxiter:
raise RuntimeError("Too many iterations.")
iter += 1
if (w - xc) * (xb - w) > 0.0:
fw = func(*((w,) + args))
funcalls += 1
if (fw < fc):
xa = xb
xb = w
fa = fb
fb = fw
return xa, xb, xc, fa, fb, fc, funcalls
elif (fw > fb):
xc = w
fc = fw
return xa, xb, xc, fa, fb, fc, funcalls
w = xc + _gold * (xc - xb)
fw = func(*((w,) + args))
funcalls += 1
elif (w - wlim)*(wlim - xc) >= 0.0:
w = wlim
fw = func(*((w,) + args))
funcalls += 1
elif (w - wlim)*(xc - w) > 0.0:
fw = func(*((w,) + args))
funcalls += 1
if (fw < fc):
xb = xc
xc = w
w = xc + _gold * (xc - xb)
fb = fc
fc = fw
fw = func(*((w,) + args))
funcalls += 1
else:
w = xc + _gold * (xc - xb)
fw = func(*((w,) + args))
funcalls += 1
xa = xb
xb = xc
xc = w
fa = fb
fb = fc
fc = fw
return xa, xb, xc, fa, fb, fc, funcalls
def _linesearch_powell(func, p, xi, tol=1e-3):
"""Line-search algorithm using fminbound.
Find the minimium of the function ``func(x0+ alpha*direc)``.
"""
def myfunc(alpha):
return func(p + alpha*xi)
alpha_min, fret, iter, num = brent(myfunc, full_output=1, tol=tol)
xi = alpha_min*xi
return squeeze(fret), p + xi, xi
def fmin_powell(func, x0, args=(), xtol=1e-4, ftol=1e-4, maxiter=None,
maxfun=None, full_output=0, disp=1, retall=0, callback=None,
direc=None):
"""
Minimize a function using modified Powell's method. This method
only uses function values, not derivatives.
Parameters
----------
func : callable f(x,*args)
Objective function to be minimized.
x0 : ndarray
Initial guess.
args : tuple, optional
Extra arguments passed to func.
callback : callable, optional
An optional user-supplied function, called after each
iteration. Called as ``callback(xk)``, where ``xk`` is the
current parameter vector.
direc : ndarray, optional
Initial direction set.
xtol : float, optional
Line-search error tolerance.
ftol : float, optional
Relative error in ``func(xopt)`` acceptable for convergence.
maxiter : int, optional
Maximum number of iterations to perform.
maxfun : int, optional
Maximum number of function evaluations to make.
full_output : bool, optional
If True, fopt, xi, direc, iter, funcalls, and
warnflag are returned.
disp : bool, optional
If True, print convergence messages.
retall : bool, optional
If True, return a list of the solution at each iteration.
Returns
-------
xopt : ndarray
Parameter which minimizes `func`.
fopt : number
Value of function at minimum: ``fopt = func(xopt)``.
direc : ndarray
Current direction set.
iter : int
Number of iterations.
funcalls : int
Number of function calls made.
warnflag : int
Integer warning flag:
1 : Maximum number of function evaluations.
2 : Maximum number of iterations.
allvecs : list
List of solutions at each iteration.
See also
--------
minimize: Interface to unconstrained minimization algorithms for
multivariate functions. See the 'Powell' `method` in particular.
Notes
-----
Uses a modification of Powell's method to find the minimum of
a function of N variables. Powell's method is a conjugate
direction method.
The algorithm has two loops. The outer loop
merely iterates over the inner loop. The inner loop minimizes
over each current direction in the direction set. At the end
of the inner loop, if certain conditions are met, the direction
that gave the largest decrease is dropped and replaced with
the difference between the current estimated x and the estimated
x from the beginning of the inner-loop.
The technical conditions for replacing the direction of greatest
increase amount to checking that
1. No further gain can be made along the direction of greatest increase
from that iteration.
2. The direction of greatest increase accounted for a large sufficient
fraction of the decrease in the function value from that iteration of
the inner loop.
References
----------
Powell M.J.D. (1964) An efficient method for finding the minimum of a
function of several variables without calculating derivatives,
Computer Journal, 7 (2):155-162.
Press W., Teukolsky S.A., Vetterling W.T., and Flannery B.P.:
Numerical Recipes (any edition), Cambridge University Press
"""
opts = {'xtol': xtol,
'ftol': ftol,
'maxiter': maxiter,
'maxfev': maxfun,
'disp': disp,
'direc': direc,
'return_all': retall}
res = _minimize_powell(func, x0, args, callback=callback, **opts)
if full_output:
retlist = (res['x'], res['fun'], res['direc'], res['nit'],
res['nfev'], res['status'])
if retall:
retlist += (res['allvecs'], )
return retlist
else:
if retall:
return res['x'], res['allvecs']
else:
return res['x']
def _minimize_powell(func, x0, args=(), callback=None,
xtol=1e-4, ftol=1e-4, maxiter=None, maxfev=None,
disp=False, direc=None, return_all=False,
**unknown_options):
"""
Minimization of scalar function of one or more variables using the
modified Powell algorithm.
Options
-------
disp : bool
Set to True to print convergence messages.
xtol : float
Relative error in solution `xopt` acceptable for convergence.
ftol : float
Relative error in ``fun(xopt)`` acceptable for convergence.
maxiter, maxfev : int
Maximum allowed number of iterations and function evaluations.
Will default to ``N*1000``, where ``N`` is the number of
variables, if neither `maxiter` or `maxfev` is set. If both
`maxiter` and `maxfev` are set, minimization will stop at the
first reached.
direc : ndarray
Initial set of direction vectors for the Powell method.
"""
_check_unknown_options(unknown_options)
maxfun = maxfev
retall = return_all
# we need to use a mutable object here that we can update in the
# wrapper function
fcalls, func = wrap_function(func, args)
x = asarray(x0).flatten()
if retall:
allvecs = [x]
N = len(x)
# If neither are set, then set both to default
if maxiter is None and maxfun is None:
maxiter = N * 1000
maxfun = N * 1000
elif maxiter is None:
# Convert remaining Nones, to np.inf, unless the other is np.inf, in
# which case use the default to avoid unbounded iteration
if maxfun == np.inf:
maxiter = N * 1000
else:
maxiter = np.inf
elif maxfun is None:
if maxiter == np.inf:
maxfun = N * 1000
else:
maxfun = np.inf
if direc is None:
direc = eye(N, dtype=float)
else:
direc = asarray(direc, dtype=float)
fval = squeeze(func(x))
x1 = x.copy()
iter = 0
ilist = list(range(N))
while True:
fx = fval
bigind = 0
delta = 0.0
for i in ilist:
direc1 = direc[i]
fx2 = fval
fval, x, direc1 = _linesearch_powell(func, x, direc1,
tol=xtol * 100)
if (fx2 - fval) > delta:
delta = fx2 - fval
bigind = i
iter += 1
if callback is not None:
callback(x)
if retall:
allvecs.append(x)
bnd = ftol * (numpy.abs(fx) + numpy.abs(fval)) + 1e-20
if 2.0 * (fx - fval) <= bnd:
break
if fcalls[0] >= maxfun:
break
if iter >= maxiter:
break
# Construct the extrapolated point
direc1 = x - x1
x2 = 2*x - x1
x1 = x.copy()
fx2 = squeeze(func(x2))
if (fx > fx2):
t = 2.0*(fx + fx2 - 2.0*fval)
temp = (fx - fval - delta)
t *= temp*temp
temp = fx - fx2
t -= delta*temp*temp
if t < 0.0:
fval, x, direc1 = _linesearch_powell(func, x, direc1,
tol=xtol*100)
direc[bigind] = direc[-1]
direc[-1] = direc1
warnflag = 0
if fcalls[0] >= maxfun:
warnflag = 1
msg = _status_message['maxfev']
if disp:
print("Warning: " + msg)
elif iter >= maxiter:
warnflag = 2
msg = _status_message['maxiter']
if disp:
print("Warning: " + msg)
else:
msg = _status_message['success']
if disp:
print(msg)
print(" Current function value: %f" % fval)
print(" Iterations: %d" % iter)
print(" Function evaluations: %d" % fcalls[0])
x = squeeze(x)
result = OptimizeResult(fun=fval, direc=direc, nit=iter, nfev=fcalls[0],
status=warnflag, success=(warnflag == 0),
message=msg, x=x)
if retall:
result['allvecs'] = allvecs
return result
def _endprint(x, flag, fval, maxfun, xtol, disp):
if flag == 0:
if disp > 1:
print("\nOptimization terminated successfully;\n"
"The returned value satisfies the termination criteria\n"
"(using xtol = ", xtol, ")")
if flag == 1:
if disp:
print("\nMaximum number of function evaluations exceeded --- "
"increase maxfun argument.\n")
return
def brute(func, ranges, args=(), Ns=20, full_output=0, finish=fmin,
disp=False):
"""Minimize a function over a given range by brute force.
Uses the "brute force" method, i.e. computes the function's value
at each point of a multidimensional grid of points, to find the global
minimum of the function.
The function is evaluated everywhere in the range with the datatype of the
first call to the function, as enforced by the ``vectorize`` NumPy
function. The value and type of the function evaluation returned when
``full_output=True`` are affected in addition by the ``finish`` argument
(see Notes).
Parameters
----------
func : callable
The objective function to be minimized. Must be in the
form ``f(x, *args)``, where ``x`` is the argument in
the form of a 1-D array and ``args`` is a tuple of any
additional fixed parameters needed to completely specify
the function.
ranges : tuple
Each component of the `ranges` tuple must be either a
"slice object" or a range tuple of the form ``(low, high)``.
The program uses these to create the grid of points on which
the objective function will be computed. See `Note 2` for
more detail.
args : tuple, optional
Any additional fixed parameters needed to completely specify
the function.
Ns : int, optional
Number of grid points along the axes, if not otherwise
specified. See `Note2`.
full_output : bool, optional
If True, return the evaluation grid and the objective function's
values on it.
finish : callable, optional
An optimization function that is called with the result of brute force
minimization as initial guess. `finish` should take `func` and
the initial guess as positional arguments, and take `args` as
keyword arguments. It may additionally take `full_output`
and/or `disp` as keyword arguments. Use None if no "polishing"
function is to be used. See Notes for more details.
disp : bool, optional
Set to True to print convergence messages.
Returns
-------
x0 : ndarray
A 1-D array containing the coordinates of a point at which the
objective function had its minimum value. (See `Note 1` for
which point is returned.)
fval : float
Function value at the point `x0`. (Returned when `full_output` is
True.)
grid : tuple
Representation of the evaluation grid. It has the same
length as `x0`. (Returned when `full_output` is True.)
Jout : ndarray
Function values at each point of the evaluation
grid, `i.e.`, ``Jout = func(*grid)``. (Returned
when `full_output` is True.)
See Also
--------
basinhopping, differential_evolution
Notes
-----
*Note 1*: The program finds the gridpoint at which the lowest value
of the objective function occurs. If `finish` is None, that is the
point returned. When the global minimum occurs within (or not very far
outside) the grid's boundaries, and the grid is fine enough, that
point will be in the neighborhood of the global minimum.
However, users often employ some other optimization program to
"polish" the gridpoint values, `i.e.`, to seek a more precise
(local) minimum near `brute's` best gridpoint.
The `brute` function's `finish` option provides a convenient way to do
that. Any polishing program used must take `brute's` output as its
initial guess as a positional argument, and take `brute's` input values
for `args` as keyword arguments, otherwise an error will be raised.
It may additionally take `full_output` and/or `disp` as keyword arguments.
`brute` assumes that the `finish` function returns either an
`OptimizeResult` object or a tuple in the form:
``(xmin, Jmin, ... , statuscode)``, where ``xmin`` is the minimizing
value of the argument, ``Jmin`` is the minimum value of the objective
function, "..." may be some other returned values (which are not used
by `brute`), and ``statuscode`` is the status code of the `finish` program.
Note that when `finish` is not None, the values returned are those
of the `finish` program, *not* the gridpoint ones. Consequently,
while `brute` confines its search to the input grid points,
the `finish` program's results usually will not coincide with any
gridpoint, and may fall outside the grid's boundary. Thus, if a
minimum only needs to be found over the provided grid points, make
sure to pass in `finish=None`.
*Note 2*: The grid of points is a `numpy.mgrid` object.
For `brute` the `ranges` and `Ns` inputs have the following effect.
Each component of the `ranges` tuple can be either a slice object or a
two-tuple giving a range of values, such as (0, 5). If the component is a
slice object, `brute` uses it directly. If the component is a two-tuple
range, `brute` internally converts it to a slice object that interpolates
`Ns` points from its low-value to its high-value, inclusive.
Examples
--------
We illustrate the use of `brute` to seek the global minimum of a function
of two variables that is given as the sum of a positive-definite
quadratic and two deep "Gaussian-shaped" craters. Specifically, define
the objective function `f` as the sum of three other functions,
``f = f1 + f2 + f3``. We suppose each of these has a signature
``(z, *params)``, where ``z = (x, y)``, and ``params`` and the functions
are as defined below.
>>> params = (2, 3, 7, 8, 9, 10, 44, -1, 2, 26, 1, -2, 0.5)
>>> def f1(z, *params):
... x, y = z
... a, b, c, d, e, f, g, h, i, j, k, l, scale = params
... return (a * x**2 + b * x * y + c * y**2 + d*x + e*y + f)
>>> def f2(z, *params):
... x, y = z
... a, b, c, d, e, f, g, h, i, j, k, l, scale = params
... return (-g*np.exp(-((x-h)**2 + (y-i)**2) / scale))
>>> def f3(z, *params):
... x, y = z
... a, b, c, d, e, f, g, h, i, j, k, l, scale = params
... return (-j*np.exp(-((x-k)**2 + (y-l)**2) / scale))
>>> def f(z, *params):
... return f1(z, *params) + f2(z, *params) + f3(z, *params)
Thus, the objective function may have local minima near the minimum
of each of the three functions of which it is composed. To
use `fmin` to polish its gridpoint result, we may then continue as
follows:
>>> rranges = (slice(-4, 4, 0.25), slice(-4, 4, 0.25))
>>> from scipy import optimize
>>> resbrute = optimize.brute(f, rranges, args=params, full_output=True,
... finish=optimize.fmin)
>>> resbrute[0] # global minimum
array([-1.05665192, 1.80834843])
>>> resbrute[1] # function value at global minimum
-3.4085818767
Note that if `finish` had been set to None, we would have gotten the
gridpoint [-1.0 1.75] where the rounded function value is -2.892.
"""
N = len(ranges)
if N > 40:
raise ValueError("Brute Force not possible with more "
"than 40 variables.")
lrange = list(ranges)
for k in range(N):
if type(lrange[k]) is not type(slice(None)):
if len(lrange[k]) < 3:
lrange[k] = tuple(lrange[k]) + (complex(Ns),)
lrange[k] = slice(*lrange[k])
if (N == 1):
lrange = lrange[0]
def _scalarfunc(*params):
params = squeeze(asarray(params))
return func(params, *args)
vecfunc = vectorize(_scalarfunc)
grid = mgrid[lrange]
if (N == 1):
grid = (grid,)
Jout = vecfunc(*grid)
Nshape = shape(Jout)
indx = argmin(Jout.ravel(), axis=-1)
Nindx = zeros(N, int)
xmin = zeros(N, float)
for k in range(N - 1, -1, -1):
thisN = Nshape[k]
Nindx[k] = indx % Nshape[k]
indx = indx // thisN
for k in range(N):
xmin[k] = grid[k][tuple(Nindx)]
Jmin = Jout[tuple(Nindx)]
if (N == 1):
grid = grid[0]
xmin = xmin[0]
if callable(finish):
# set up kwargs for `finish` function
finish_args = _getargspec(finish).args
finish_kwargs = dict()
if 'full_output' in finish_args:
finish_kwargs['full_output'] = 1
if 'disp' in finish_args:
finish_kwargs['disp'] = disp
elif 'options' in finish_args:
# pass 'disp' as `options`
# (e.g. if `finish` is `minimize`)
finish_kwargs['options'] = {'disp': disp}
# run minimizer
res = finish(func, xmin, args=args, **finish_kwargs)
if isinstance(res, OptimizeResult):
xmin = res.x
Jmin = res.fun
success = res.success
else:
xmin = res[0]
Jmin = res[1]
success = res[-1] == 0
if not success:
if disp:
print("Warning: Either final optimization did not succeed "
"or `finish` does not return `statuscode` as its last "
"argument.")
if full_output:
return xmin, Jmin, grid, Jout
else:
return xmin
def show_options(solver=None, method=None, disp=True):
"""
Show documentation for additional options of optimization solvers.
These are method-specific options that can be supplied through the
``options`` dict.
Parameters
----------
solver : str
Type of optimization solver. One of 'minimize', 'minimize_scalar',
'root', or 'linprog'.
method : str, optional
If not given, shows all methods of the specified solver. Otherwise,
show only the options for the specified method. Valid values
corresponds to methods' names of respective solver (e.g. 'BFGS' for
'minimize').
disp : bool, optional
Whether to print the result rather than returning it.
Returns
-------
text
Either None (for disp=False) or the text string (disp=True)
Notes
-----
The solver-specific methods are:
`scipy.optimize.minimize`
- :ref:`Nelder-Mead <optimize.minimize-neldermead>`
- :ref:`Powell <optimize.minimize-powell>`
- :ref:`CG <optimize.minimize-cg>`
- :ref:`BFGS <optimize.minimize-bfgs>`
- :ref:`Newton-CG <optimize.minimize-newtoncg>`
- :ref:`L-BFGS-B <optimize.minimize-lbfgsb>`
- :ref:`TNC <optimize.minimize-tnc>`
- :ref:`COBYLA <optimize.minimize-cobyla>`
- :ref:`SLSQP <optimize.minimize-slsqp>`
- :ref:`dogleg <optimize.minimize-dogleg>`
- :ref:`trust-ncg <optimize.minimize-trustncg>`
`scipy.optimize.root`
- :ref:`hybr <optimize.root-hybr>`
- :ref:`lm <optimize.root-lm>`
- :ref:`broyden1 <optimize.root-broyden1>`
- :ref:`broyden2 <optimize.root-broyden2>`
- :ref:`anderson <optimize.root-anderson>`
- :ref:`linearmixing <optimize.root-linearmixing>`
- :ref:`diagbroyden <optimize.root-diagbroyden>`
- :ref:`excitingmixing <optimize.root-excitingmixing>`
- :ref:`krylov <optimize.root-krylov>`
- :ref:`df-sane <optimize.root-dfsane>`
`scipy.optimize.minimize_scalar`
- :ref:`brent <optimize.minimize_scalar-brent>`
- :ref:`golden <optimize.minimize_scalar-golden>`
- :ref:`bounded <optimize.minimize_scalar-bounded>`
`scipy.optimize.linprog`
- :ref:`simplex <optimize.linprog-simplex>`
"""
import textwrap
doc_routines = {
'minimize': (
('bfgs', 'scipy.optimize.optimize._minimize_bfgs'),
('cg', 'scipy.optimize.optimize._minimize_cg'),
('cobyla', 'scipy.optimize.cobyla._minimize_cobyla'),
('dogleg', 'scipy.optimize._trustregion_dogleg._minimize_dogleg'),
('l-bfgs-b', 'scipy.optimize.lbfgsb._minimize_lbfgsb'),
('nelder-mead', 'scipy.optimize.optimize._minimize_neldermead'),
('newtoncg', 'scipy.optimize.optimize._minimize_newtoncg'),
('powell', 'scipy.optimize.optimize._minimize_powell'),
('slsqp', 'scipy.optimize.slsqp._minimize_slsqp'),
('tnc', 'scipy.optimize.tnc._minimize_tnc'),
('trust-ncg', 'scipy.optimize._trustregion_ncg._minimize_trust_ncg'),
),
'root': (
('hybr', 'scipy.optimize.minpack._root_hybr'),
('lm', 'scipy.optimize._root._root_leastsq'),
('broyden1', 'scipy.optimize._root._root_broyden1_doc'),
('broyden2', 'scipy.optimize._root._root_broyden2_doc'),
('anderson', 'scipy.optimize._root._root_anderson_doc'),
('diagbroyden', 'scipy.optimize._root._root_diagbroyden_doc'),
('excitingmixing', 'scipy.optimize._root._root_excitingmixing_doc'),
('linearmixing', 'scipy.optimize._root._root_linearmixing_doc'),
('krylov', 'scipy.optimize._root._root_krylov_doc'),
('df-sane', 'scipy.optimize._spectral._root_df_sane'),
),
'linprog': (
('simplex', 'scipy.optimize._linprog._linprog_simplex'),
),
'minimize_scalar': (
('brent', 'scipy.optimize.optimize._minimize_scalar_brent'),
('bounded', 'scipy.optimize.optimize._minimize_scalar_bounded'),
('golden', 'scipy.optimize.optimize._minimize_scalar_golden'),
),
}
if solver is None:
text = ["\n\n\n========\n", "minimize\n", "========\n"]
text.append(show_options('minimize', disp=False))
text.extend(["\n\n===============\n", "minimize_scalar\n",
"===============\n"])
text.append(show_options('minimize_scalar', disp=False))
text.extend(["\n\n\n====\n", "root\n",
"====\n"])
text.append(show_options('root', disp=False))
text.extend(['\n\n\n=======\n', 'linprog\n',
'=======\n'])
text.append(show_options('linprog', disp=False))
text = "".join(text)
else:
solver = solver.lower()
if solver not in doc_routines:
raise ValueError('Unknown solver %r' % (solver,))
if method is None:
text = []
for name, _ in doc_routines[solver]:
text.extend(["\n\n" + name, "\n" + "="*len(name) + "\n\n"])
text.append(show_options(solver, name, disp=False))
text = "".join(text)
else:
methods = dict(doc_routines[solver])
if method not in methods:
raise ValueError("Unknown method %r" % (method,))
name = methods[method]
# Import function object
parts = name.split('.')
mod_name = ".".join(parts[:-1])
__import__(mod_name)
obj = getattr(sys.modules[mod_name], parts[-1])
# Get doc
doc = obj.__doc__
if doc is not None:
text = textwrap.dedent(doc).strip()
else:
text = ""
if disp:
print(text)
return
else:
return text
def main():
import time
times = []
algor = []
x0 = [0.8, 1.2, 0.7]
print("Nelder-Mead Simplex")
print("===================")
start = time.time()
x = fmin(rosen, x0)
print(x)
times.append(time.time() - start)
algor.append('Nelder-Mead Simplex\t')
print()
print("Powell Direction Set Method")
print("===========================")
start = time.time()
x = fmin_powell(rosen, x0)
print(x)
times.append(time.time() - start)
algor.append('Powell Direction Set Method.')
print()
print("Nonlinear CG")
print("============")
start = time.time()
x = fmin_cg(rosen, x0, fprime=rosen_der, maxiter=200)
print(x)
times.append(time.time() - start)
algor.append('Nonlinear CG \t')
print()
print("BFGS Quasi-Newton")
print("=================")
start = time.time()
x = fmin_bfgs(rosen, x0, fprime=rosen_der, maxiter=80)
print(x)
times.append(time.time() - start)
algor.append('BFGS Quasi-Newton\t')
print()
print("BFGS approximate gradient")
print("=========================")
start = time.time()
x = fmin_bfgs(rosen, x0, gtol=1e-4, maxiter=100)
print(x)
times.append(time.time() - start)
algor.append('BFGS without gradient\t')
print()
print("Newton-CG with Hessian product")
print("==============================")
start = time.time()
x = fmin_ncg(rosen, x0, rosen_der, fhess_p=rosen_hess_prod, maxiter=80)
print(x)
times.append(time.time() - start)
algor.append('Newton-CG with hessian product')
print()
print("Newton-CG with full Hessian")
print("===========================")
start = time.time()
x = fmin_ncg(rosen, x0, rosen_der, fhess=rosen_hess, maxiter=80)
print(x)
times.append(time.time() - start)
algor.append('Newton-CG with full hessian')
print()
print("\nMinimizing the Rosenbrock function of order 3\n")
print(" Algorithm \t\t\t Seconds")
print("===========\t\t\t =========")
for k in range(len(algor)):
print(algor[k], "\t -- ", times[k])
if __name__ == "__main__":
main()
|
apache-2.0
|
[
3,
363,
21841,
363,
275,
298,
26854,
655,
2,
199,
3,
1011,
1116,
4609,
4047,
1801,
1116,
9153,
199,
3,
13497,
14,
647,
859,
701,
12643,
5068,
662,
14,
593,
317,
838,
867,
199,
3,
199,
3,
2047,
1443,
1331,
436,
675,
642,
859,
465,
1265,
1937,
5542,
543,
949,
199,
3,
24197,
2478,
2741,
1265,
4215,
642,
4245,
315,
1006,
6866,
14,
199,
3,
1011,
9153,
3902,
12840,
1801,
1116,
199,
199,
3,
437,
3245,
402,
13712,
18036,
14,
221,
3394,
378,
14,
21,
199,
3,
6624,
3986,
654,
199,
3,
221,
16230,
289,
827,
3556,
334,
42,
21797,
12521,
9,
199,
3,
221,
16230,
11665,
938,
334,
21640,
14,
14790,
9,
199,
3,
221,
11711,
4387,
1004,
2754,
23082,
316,
16925,
644,
79,
276,
69,
3704,
334,
10570,
14,
8353,
9,
199,
3,
221,
6162,
68,
16925,
644,
79,
276,
69,
3704,
1004,
2754,
370,
675,
199,
3,
420,
22217,
530,
13,
21080,
334,
10570,
14,
8353,
9,
199,
199,
504,
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
12,
3679,
63,
646,
421,
199,
3,
10195,
1017,
2072,
14975,
199,
199,
363,
452,
363,
275,
788,
70,
827,
297,
283,
70,
827,
63,
8278,
1697,
297,
283,
70,
827,
63,
31372,
297,
283,
70,
827,
63,
7966,
71,
297,
283,
70,
827,
63,
12595,
297,
1779,
283,
70,
827,
3556,
297,
283,
66,
640,
297,
283,
19440,
297,
283,
14594,
297,
283,
293,
2464,
297,
283,
293,
2464,
63,
424,
297,
1779,
283,
293,
2464,
63,
31421,
297,
283,
293,
2464,
63,
31421,
63,
8788,
297,
283,
3289,
938,
297,
283,
16815,
63,
70,
12446,
297,
1779,
283,
604,
63,
1733,
297,
283,
1074,
63,
6017,
297,
283,
30474,
2889,
297,
283,
2384,
63,
1419,
297,
1779,
283,
30474,
3849,
418,
199,
199,
363,
21841,
363,
275,
298,
26854,
655,
2,
199,
199,
646,
3598,
199,
646,
984,
199,
646,
2680,
199,
504,
7026,
423,
773,
14,
4174,
492,
4550,
12,
4945,
199,
504,
2680,
492,
334,
22900,
63,
17,
68,
12,
25892,
12,
333,
3825,
12,
1680,
827,
12,
10136,
12,
2215,
12,
308,
14167,
12,
673,
5477,
794,
12,
24144,
12,
7452,
12,
1010,
70,
12,
465,
70,
1144,
12,
365,
4904,
9,
199,
646,
2680,
465,
980,
199,
504,
1275,
604,
1733,
492,
334,
604,
63,
1733,
63,
28070,
69,
17,
12,
1004,
63,
1733,
63,
28070,
69,
18,
12,
586,
1004,
63,
1733,
63,
28070,
69,
18,
465,
1004,
63,
1733,
12,
586,
7030,
5278,
3849,
9,
199,
504,
7026,
423,
773,
423,
1974,
492,
664,
15644,
63,
889,
63,
277,
465,
485,
29836,
421,
199,
3,
4465,
2004,
3788,
402,
5323,
6315,
199,
63,
1205,
63,
1188,
275,
791,
3742,
356,
283,
30661,
15745,
8792,
3130,
673,
283,
988,
30070,
356,
283,
10915,
1329,
402,
805,
8031,
1298,
965,
283,
2892,
283,
1235,
287,
22007,
3130,
673,
283,
988,
1661,
356,
283,
10915,
1329,
402,
10615,
965,
2757,
283,
2892,
283,
476,
19750,
3130,
673,
283,
2700,
63,
4358,
356,
283,
872,
5381,
1125,
440,
20513,
22175,
1354,
7037,
283,
2892,
283,
475,
7151,
5621,
14,
936,
421,
199,
533,
3194,
573,
794,
42,
645,
8,
785,
304,
272,
408,
30684,
626,
18014,
314,
574,
6709,
402,
805,
1924,
900,
652,
272,
365,
2797,
14,
408,
272,
347,
636,
826,
721,
277,
12,
9627,
304,
267,
291,
14,
7036,
275,
9627,
267,
291,
14,
9299,
275,
488,
267,
291,
14,
88,
275,
488,
339,
347,
636,
1250,
721,
277,
12,
671,
12,
627,
589,
304,
267,
291,
14,
88,
275,
2680,
14,
8748,
8,
88,
680,
1574,
342,
267,
16587,
275,
291,
14,
7036,
8,
88,
12,
627,
589,
9,
267,
291,
14,
9299,
275,
16587,
59,
17,
61,
267,
372,
16587,
59,
16,
61,
339,
347,
18883,
8,
277,
12,
671,
12,
627,
589,
304,
267,
340,
291,
14,
9299,
365,
440,
488,
436,
2680,
14,
452,
2052,
8,
88,
508,
291,
14,
88,
304,
288,
372,
291,
14,
9299,
267,
587,
26,
288,
291,
8,
88,
12,
627,
589,
9,
288,
372,
291,
14,
9299,
421,
199,
533,
19246,
794,
2889,
8,
807,
304,
272,
408,
21591,
314,
13712,
754,
14,
339,
9382,
272,
4143,
272,
671,
520,
6800,
267,
710,
8744,
402,
314,
13712,
14,
272,
3182,
520,
2155,
267,
7480,
503,
440,
314,
10736,
22987,
8792,
14,
272,
2004,
520,
1109,
267,
20429,
425,
2004,
402,
314,
10736,
14,
22940,
574,
8350,
641,
314,
267,
8793,
10196,
14,
21751,
370,
658,
1188,
64,
367,
2436,
14,
272,
1245,
520,
620,
267,
11994,
402,
314,
7675,
402,
314,
23868,
14,
272,
9627,
12,
21664,
12,
946,
385,
26,
6800,
267,
13468,
402,
20632,
805,
12,
2399,
30633,
436,
2399,
869,
21663,
334,
692,
267,
2808,
680,
710,
869,
28601,
796,
1443,
506,
4286,
6865,
21953,
12,
1937,
314,
3794,
267,
402,
314,
805,
315,
7894,
14,
272,
946,
385,
63,
5350,
520,
909,
267,
1010,
2077,
402,
314,
20632,
805,
1159,
869,
21663,
27,
1443,
506,
376,
22772,
14,
267,
2832,
2808,
367,
1006,
10196,
83,
14,
710,
730,
402,
642,
2225,
1443,
506,
267,
1902,
980,
14,
8237,
503,
7026,
14,
4421,
14,
10096,
14,
26463,
14,
272,
302,
30070,
12,
302,
6532,
86,
12,
302,
23511,
520,
1109,
267,
4860,
402,
8031,
1298,
402,
314,
20632,
3423,
436,
402,
2399,
267,
30633,
436,
869,
21663,
14,
272,
302,
390,
520,
1109,
267,
4860,
402,
10615,
10585,
701,
314,
10736,
14,
272,
1390,
5107,
520,
2069,
267,
710,
5696,
5828,
1321,
10410,
14,
339,
8144,
272,
9063,
272,
6006,
1443,
506,
4722,
3004,
440,
10532,
3432,
10298,
402,
314,
272,
2488,
10196,
14,
9336,
642,
1021,
365,
28891,
282,
5516,
402,
1211,
272,
543,
2225,
31908,
12,
1373,
883,
1937,
1314,
3004,
787,
2808,
272,
1808,
314,
658,
1612,
11995,
1083,
14,
272,
408,
272,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
862,
26,
288,
372,
291,
59,
354,
61,
267,
871,
4067,
26,
288,
746,
4281,
8,
354,
9,
339,
636,
10202,
363,
275,
1211,
855,
8617,
363,
272,
636,
30831,
363,
275,
1211,
855,
13228,
363,
339,
347,
636,
2722,
721,
277,
304,
267,
340,
291,
14
] |
[
363,
21841,
363,
275,
298,
26854,
655,
2,
199,
3,
1011,
1116,
4609,
4047,
1801,
1116,
9153,
199,
3,
13497,
14,
647,
859,
701,
12643,
5068,
662,
14,
593,
317,
838,
867,
199,
3,
199,
3,
2047,
1443,
1331,
436,
675,
642,
859,
465,
1265,
1937,
5542,
543,
949,
199,
3,
24197,
2478,
2741,
1265,
4215,
642,
4245,
315,
1006,
6866,
14,
199,
3,
1011,
9153,
3902,
12840,
1801,
1116,
199,
199,
3,
437,
3245,
402,
13712,
18036,
14,
221,
3394,
378,
14,
21,
199,
3,
6624,
3986,
654,
199,
3,
221,
16230,
289,
827,
3556,
334,
42,
21797,
12521,
9,
199,
3,
221,
16230,
11665,
938,
334,
21640,
14,
14790,
9,
199,
3,
221,
11711,
4387,
1004,
2754,
23082,
316,
16925,
644,
79,
276,
69,
3704,
334,
10570,
14,
8353,
9,
199,
3,
221,
6162,
68,
16925,
644,
79,
276,
69,
3704,
1004,
2754,
370,
675,
199,
3,
420,
22217,
530,
13,
21080,
334,
10570,
14,
8353,
9,
199,
199,
504,
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
12,
3679,
63,
646,
421,
199,
3,
10195,
1017,
2072,
14975,
199,
199,
363,
452,
363,
275,
788,
70,
827,
297,
283,
70,
827,
63,
8278,
1697,
297,
283,
70,
827,
63,
31372,
297,
283,
70,
827,
63,
7966,
71,
297,
283,
70,
827,
63,
12595,
297,
1779,
283,
70,
827,
3556,
297,
283,
66,
640,
297,
283,
19440,
297,
283,
14594,
297,
283,
293,
2464,
297,
283,
293,
2464,
63,
424,
297,
1779,
283,
293,
2464,
63,
31421,
297,
283,
293,
2464,
63,
31421,
63,
8788,
297,
283,
3289,
938,
297,
283,
16815,
63,
70,
12446,
297,
1779,
283,
604,
63,
1733,
297,
283,
1074,
63,
6017,
297,
283,
30474,
2889,
297,
283,
2384,
63,
1419,
297,
1779,
283,
30474,
3849,
418,
199,
199,
363,
21841,
363,
275,
298,
26854,
655,
2,
199,
199,
646,
3598,
199,
646,
984,
199,
646,
2680,
199,
504,
7026,
423,
773,
14,
4174,
492,
4550,
12,
4945,
199,
504,
2680,
492,
334,
22900,
63,
17,
68,
12,
25892,
12,
333,
3825,
12,
1680,
827,
12,
10136,
12,
2215,
12,
308,
14167,
12,
673,
5477,
794,
12,
24144,
12,
7452,
12,
1010,
70,
12,
465,
70,
1144,
12,
365,
4904,
9,
199,
646,
2680,
465,
980,
199,
504,
1275,
604,
1733,
492,
334,
604,
63,
1733,
63,
28070,
69,
17,
12,
1004,
63,
1733,
63,
28070,
69,
18,
12,
586,
1004,
63,
1733,
63,
28070,
69,
18,
465,
1004,
63,
1733,
12,
586,
7030,
5278,
3849,
9,
199,
504,
7026,
423,
773,
423,
1974,
492,
664,
15644,
63,
889,
63,
277,
465,
485,
29836,
421,
199,
3,
4465,
2004,
3788,
402,
5323,
6315,
199,
63,
1205,
63,
1188,
275,
791,
3742,
356,
283,
30661,
15745,
8792,
3130,
673,
283,
988,
30070,
356,
283,
10915,
1329,
402,
805,
8031,
1298,
965,
283,
2892,
283,
1235,
287,
22007,
3130,
673,
283,
988,
1661,
356,
283,
10915,
1329,
402,
10615,
965,
2757,
283,
2892,
283,
476,
19750,
3130,
673,
283,
2700,
63,
4358,
356,
283,
872,
5381,
1125,
440,
20513,
22175,
1354,
7037,
283,
2892,
283,
475,
7151,
5621,
14,
936,
421,
199,
533,
3194,
573,
794,
42,
645,
8,
785,
304,
272,
408,
30684,
626,
18014,
314,
574,
6709,
402,
805,
1924,
900,
652,
272,
365,
2797,
14,
408,
272,
347,
636,
826,
721,
277,
12,
9627,
304,
267,
291,
14,
7036,
275,
9627,
267,
291,
14,
9299,
275,
488,
267,
291,
14,
88,
275,
488,
339,
347,
636,
1250,
721,
277,
12,
671,
12,
627,
589,
304,
267,
291,
14,
88,
275,
2680,
14,
8748,
8,
88,
680,
1574,
342,
267,
16587,
275,
291,
14,
7036,
8,
88,
12,
627,
589,
9,
267,
291,
14,
9299,
275,
16587,
59,
17,
61,
267,
372,
16587,
59,
16,
61,
339,
347,
18883,
8,
277,
12,
671,
12,
627,
589,
304,
267,
340,
291,
14,
9299,
365,
440,
488,
436,
2680,
14,
452,
2052,
8,
88,
508,
291,
14,
88,
304,
288,
372,
291,
14,
9299,
267,
587,
26,
288,
291,
8,
88,
12,
627,
589,
9,
288,
372,
291,
14,
9299,
421,
199,
533,
19246,
794,
2889,
8,
807,
304,
272,
408,
21591,
314,
13712,
754,
14,
339,
9382,
272,
4143,
272,
671,
520,
6800,
267,
710,
8744,
402,
314,
13712,
14,
272,
3182,
520,
2155,
267,
7480,
503,
440,
314,
10736,
22987,
8792,
14,
272,
2004,
520,
1109,
267,
20429,
425,
2004,
402,
314,
10736,
14,
22940,
574,
8350,
641,
314,
267,
8793,
10196,
14,
21751,
370,
658,
1188,
64,
367,
2436,
14,
272,
1245,
520,
620,
267,
11994,
402,
314,
7675,
402,
314,
23868,
14,
272,
9627,
12,
21664,
12,
946,
385,
26,
6800,
267,
13468,
402,
20632,
805,
12,
2399,
30633,
436,
2399,
869,
21663,
334,
692,
267,
2808,
680,
710,
869,
28601,
796,
1443,
506,
4286,
6865,
21953,
12,
1937,
314,
3794,
267,
402,
314,
805,
315,
7894,
14,
272,
946,
385,
63,
5350,
520,
909,
267,
1010,
2077,
402,
314,
20632,
805,
1159,
869,
21663,
27,
1443,
506,
376,
22772,
14,
267,
2832,
2808,
367,
1006,
10196,
83,
14,
710,
730,
402,
642,
2225,
1443,
506,
267,
1902,
980,
14,
8237,
503,
7026,
14,
4421,
14,
10096,
14,
26463,
14,
272,
302,
30070,
12,
302,
6532,
86,
12,
302,
23511,
520,
1109,
267,
4860,
402,
8031,
1298,
402,
314,
20632,
3423,
436,
402,
2399,
267,
30633,
436,
869,
21663,
14,
272,
302,
390,
520,
1109,
267,
4860,
402,
10615,
10585,
701,
314,
10736,
14,
272,
1390,
5107,
520,
2069,
267,
710,
5696,
5828,
1321,
10410,
14,
339,
8144,
272,
9063,
272,
6006,
1443,
506,
4722,
3004,
440,
10532,
3432,
10298,
402,
314,
272,
2488,
10196,
14,
9336,
642,
1021,
365,
28891,
282,
5516,
402,
1211,
272,
543,
2225,
31908,
12,
1373,
883,
1937,
1314,
3004,
787,
2808,
272,
1808,
314,
658,
1612,
11995,
1083,
14,
272,
408,
272,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
862,
26,
288,
372,
291,
59,
354,
61,
267,
871,
4067,
26,
288,
746,
4281,
8,
354,
9,
339,
636,
10202,
363,
275,
1211,
855,
8617,
363,
272,
636,
30831,
363,
275,
1211,
855,
13228,
363,
339,
347,
636,
2722,
721,
277,
304,
267,
340,
291,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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details.
from odoo import api, fields, models, _
from odoo.exceptions import UserError
class StockPicking(models.Model):
_inherit = 'stock.picking'
purchase_id = fields.Many2one('purchase.order', related='move_lines.purchase_line_id.order_id',
string="Purchase Orders", readonly=True)
@api.model
def _prepare_values_extra_move(self, op, product, remaining_qty):
res = super(StockPicking, self)._prepare_values_extra_move(op, product, remaining_qty)
for m in op.linked_move_operation_ids:
if m.move_id.purchase_line_id and m.move_id.product_id == product:
res['purchase_line_id'] = m.move_id.purchase_line_id.id
break
return res
@api.model
def _create_backorder(self, backorder_moves=[]):
res = super(StockPicking, self)._create_backorder(backorder_moves)
for picking in self:
if picking.picking_type_id.code == 'incoming':
backorder = self.search([('backorder_id', '=', picking.id)])
backorder.message_post_with_view('mail.message_origin_link',
values={'self': backorder, 'origin': backorder.purchase_id},
subtype_id=self.env.ref('mail.mt_note').id)
return res
class StockMove(models.Model):
_inherit = 'stock.move'
purchase_line_id = fields.Many2one('purchase.order.line',
'Purchase Order Line', ondelete='set null', index=True, readonly=True)
@api.multi
def get_price_unit(self):
""" Returns the unit price to store on the quant """
if self.purchase_line_id:
order = self.purchase_line_id.order_id
#if the currency of the PO is different than the company one, the price_unit on the move must be reevaluated
#(was created at the rate of the PO confirmation, but must be valuated at the rate of stock move execution)
if order.currency_id != self.company_id.currency_id:
#we don't pass the move.date in the compute() for the currency rate on purpose because
# 1) get_price_unit() is supposed to be called only through move.action_done(),
# 2) the move hasn't yet the correct date (currently it is the expected date, after
# completion of action_done() it will be now() )
price_unit = self.purchase_line_id._get_stock_move_price_unit()
self.write({'price_unit': price_unit})
return price_unit
return self.price_unit
return super(StockMove, self).get_price_unit()
@api.multi
def copy(self, default=None):
self.ensure_one()
default = default or {}
if not default.get('split_from'):
#we don't want to propagate the link to the purchase order line except in case of move split
default['purchase_line_id'] = False
return super(StockMove, self).copy(default)
class StockWarehouse(models.Model):
_inherit = 'stock.warehouse'
buy_to_resupply = fields.Boolean('Purchase to resupply this warehouse', default=True,
help="When products are bought, they can be delivered to this warehouse")
buy_pull_id = fields.Many2one('procurement.rule', 'Buy rule')
@api.multi
def _get_buy_pull_rule(self):
try:
buy_route_id = self.env['ir.model.data'].get_object_reference('purchase', 'route_warehouse0_buy')[1]
except:
buy_route_id = self.env['stock.location.route'].search([('name', 'like', _('Buy'))])
buy_route_id = buy_route_id[0].id if buy_route_id else False
if not buy_route_id:
raise UserError(_("Can't find any generic Buy route."))
return {
'name': self._format_routename(_(' Buy')),
'location_id': self.in_type_id.default_location_dest_id.id,
'route_id': buy_route_id,
'action': 'buy',
'picking_type_id': self.in_type_id.id,
'warehouse_id': self.id,
'group_propagation_option': 'none',
}
@api.multi
def create_routes(self):
res = super(StockWarehouse, self).create_routes() # super applies ensure_one()
if self.buy_to_resupply:
buy_pull_vals = self._get_buy_pull_rule()
buy_pull = self.env['procurement.rule'].create(buy_pull_vals)
res['buy_pull_id'] = buy_pull.id
return res
@api.multi
def write(self, vals):
if 'buy_to_resupply' in vals:
if vals.get("buy_to_resupply"):
for warehouse in self:
if not warehouse.buy_pull_id:
buy_pull_vals = self._get_buy_pull_rule()
buy_pull = self.env['procurement.rule'].create(buy_pull_vals)
vals['buy_pull_id'] = buy_pull.id
else:
for warehouse in self:
if warehouse.buy_pull_id:
warehouse.buy_pull_id.unlink()
return super(StockWarehouse, self).write(vals)
@api.multi
def _get_all_routes(self):
routes = super(StockWarehouse, self).get_all_routes_for_wh()
routes |= self.filtered(lambda self: self.buy_to_resupply and self.buy_pull_id and self.buy_pull_id.route_id).mapped('buy_pull_id').mapped('route_id')
return routes
@api.multi
def _update_name_and_code(self, name, code):
res = super(StockWarehouse, self)._update_name_and_code(name, code)
warehouse = self[0]
#change the buy procurement rule name
if warehouse.buy_pull_id and name:
warehouse.buy_pull_id.write({'name': warehouse.buy_pull_id.name.replace(warehouse.name, name, 1)})
return res
@api.multi
def _update_routes(self):
res = super(StockWarehouse, self)._update_routes()
for warehouse in self:
if warehouse.in_type_id.default_location_dest_id != warehouse.buy_pull_id.location_id:
warehouse.buy_pull_id.write({'location_id': warehouse.in_type_id.default_location_dest_id.id})
return res
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
14320,
402,
28935,
14,
1666,
5113,
570,
367,
2615,
4248,
436,
32572,
2436,
14,
199,
199,
504,
28811,
492,
2986,
12,
1504,
12,
1709,
12,
485,
199,
504,
28811,
14,
3924,
492,
29908,
421,
199,
533,
28406,
8587,
316,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
6088,
14,
11463,
7,
339,
15932,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
9533,
14,
1648,
297,
4048,
534,
1185,
63,
1278,
14,
9533,
63,
604,
63,
344,
14,
1648,
63,
344,
297,
267,
1059,
628,
20486,
4236,
7735,
401,
6863,
29,
549,
9,
339,
768,
1246,
14,
1238,
272,
347,
485,
6726,
63,
1459,
63,
2911,
63,
1185,
8,
277,
12,
1687,
12,
3336,
12,
7971,
63,
5643,
304,
267,
522,
275,
1613,
8,
17103,
8587,
316,
12,
291,
10445,
6726,
63,
1459,
63,
2911,
63,
1185,
8,
411,
12,
3336,
12,
7971,
63,
5643,
9,
267,
367,
333,
315,
1687,
14,
12751,
63,
1185,
63,
5735,
63,
1580,
26,
288,
340,
333,
14,
1185,
63,
344,
14,
9533,
63,
604,
63,
344,
436,
333,
14,
1185,
63,
344,
14,
2558,
63,
344,
508,
3336,
26,
355,
522,
459,
9533,
63,
604,
63,
344,
418,
275,
333,
14,
1185,
63,
344,
14,
9533,
63,
604,
63,
344,
14,
344,
355,
2059,
267,
372,
522,
339,
768,
1246,
14,
1238,
272,
347,
485,
981,
63,
894,
1648,
8,
277,
12,
1771,
1648,
63,
4912,
17894,
267,
522,
275,
1613,
8,
17103,
8587,
316,
12,
291,
10445,
981,
63,
894,
1648,
8,
894,
1648,
63,
4912,
9,
267,
367,
12433,
315,
291,
26,
288,
340,
12433,
14,
11463,
63,
466,
63,
344,
14,
600,
508,
283,
15994,
356,
355,
1771,
1648,
275,
291,
14,
1733,
8318,
894,
1648,
63,
344,
297,
6291,
12433,
14,
344,
3948,
355,
1771,
1648,
14,
1188,
63,
1932,
63,
1045,
63,
1345,
360,
1198,
14,
1188,
63,
6493,
63,
1073,
297,
490,
1338,
3713,
277,
356,
1771,
1648,
12,
283,
6493,
356,
1771,
1648,
14,
9533,
63,
344,
1386,
490,
15686,
63,
344,
29,
277,
14,
1813,
14,
1121,
360,
1198,
14,
2037,
63,
4610,
1959,
344,
9,
267,
372,
522,
421,
199,
533,
28406,
10370,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
6088,
14,
1185,
7,
339,
15932,
63,
604,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
9533,
14,
1648,
14,
604,
297,
267,
283,
20486,
9240,
7030,
297,
16549,
534,
409,
2973,
297,
1478,
29,
549,
12,
6863,
29,
549,
9,
339,
768,
1246,
14,
3029,
272,
347,
664,
63,
4777,
63,
3248,
8,
277,
304,
267,
408,
1803,
314,
4137,
8033,
370,
3877,
641,
314,
15381,
408,
267,
340,
291,
14,
9533,
63,
604,
63,
344,
26,
288,
1865,
275,
291,
14,
9533,
63,
604,
63,
344,
14,
1648,
63,
344,
288,
327,
692,
314,
9952,
402,
314,
3625,
365,
3365,
2419,
314,
7233,
1373,
12,
314,
8033,
63,
3248,
641,
314,
4057,
1471,
506,
295,
2579,
23130,
288,
21571,
10274,
2737,
737,
314,
6634,
402,
314,
3625,
18791,
12,
1325,
1471,
506,
1139,
23130,
737,
314,
6634,
402,
10952,
4057,
6451,
9,
288,
340,
1865,
14,
4968,
63,
344,
1137,
291,
14,
4627,
63,
344,
14,
4968,
63,
344,
26,
355,
327,
1129,
2793,
1133,
986,
314,
4057,
14,
602,
315,
314,
4526,
342,
367,
314,
9952,
6634,
641,
12016,
2952,
355,
327,
413,
9,
664,
63,
4777,
63,
3248,
342,
365,
20042,
370,
506,
2797,
1454,
4012,
4057,
14,
1287,
63,
4456,
1062,
355,
327,
499,
9,
314,
4057,
18699,
1133,
5966,
314,
3211,
1434,
334,
19767,
652,
365,
314,
1420,
1434,
12,
2410,
355,
327,
259,
13659,
402,
1595,
63,
4456,
342,
652,
911,
506,
3063,
342,
776,
355,
8033,
63,
3248,
275,
291,
14,
9533,
63,
604,
63,
344,
423,
362,
63,
6088,
63,
1185,
63,
4777,
63,
3248,
342,
355,
291,
14,
952,
3252,
4777,
63,
3248,
356,
8033,
63,
3248,
1552,
355,
372,
8033,
63,
3248,
288,
372,
291,
14,
4777,
63,
3248,
267,
372,
1613,
8,
17103,
10370,
12,
291,
680,
362,
63,
4777,
63,
3248,
342,
339,
768,
1246,
14,
3029,
272,
347,
1331,
8,
277,
12,
849,
29,
403,
304,
267,
291,
14,
7505,
63,
368,
342,
267,
849,
275,
849,
503,
1052,
267,
340,
440,
849,
14,
362,
360,
1294,
63,
504,
735,
288,
327,
1129,
2793,
1133,
2934,
370,
19843,
314,
2142,
370,
314,
15932,
1865,
1004,
871,
315,
1930,
402,
4057,
3715,
288,
849,
459,
9533,
63,
604,
63,
344,
418,
275,
756,
267,
372,
1613,
8,
17103,
10370,
12,
291,
680,
1574,
8,
885,
9,
421,
199,
533,
28406,
55,
11499,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
6088,
14,
12806,
7,
339,
1032,
89,
63,
475,
63,
470,
384,
19786,
275,
1504,
14,
4082,
360,
20486,
370,
522,
384,
19786,
642,
13782,
297,
849,
29,
549,
12,
3660,
1720,
628,
11423,
7585,
787,
330,
20816,
12,
2985,
883,
506,
28218,
370,
642,
13782,
531,
272,
1032,
89,
63,
9302,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
18546,
14,
2200,
297,
283,
1713,
89,
2332,
358,
339,
768,
1246,
14,
3029,
272,
347,
485,
362,
63,
31240,
63,
9302,
63,
2200,
8,
277,
304,
267,
862,
26,
288,
1032,
89,
63,
4449,
63,
344,
275,
291,
14,
1813,
459,
723,
14,
1238,
14,
576,
2278,
362,
63,
785,
63,
4443,
360,
9533,
297,
283,
4449,
63,
12806,
16,
63,
31240,
5832,
17,
61,
267,
871,
26,
288,
1032,
89,
63,
4449,
63,
344,
275,
291,
14,
1813,
459,
6088,
14,
1985,
14,
4449,
2278,
1733,
8318,
354,
297,
283,
2930,
297,
4018,
1713,
89,
1333,
566,
288,
1032,
89,
63,
4449,
63,
344,
275,
1032,
89,
63,
4449,
63,
344,
59,
16,
1055,
344,
340,
1032,
89,
63,
4449,
63,
344,
587,
756,
267,
340,
440,
1032,
89,
63,
4449,
63,
344,
26,
288,
746,
29908,
6115,
6049,
1133,
2342,
1263,
7809,
4779,
89,
7475,
13853,
398,
372,
469,
288,
283,
354,
356,
291,
423,
908,
63,
4449,
354,
6723,
4779,
89,
3855,
288,
283,
1985,
63,
344,
356,
291,
14,
262,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
14320,
402,
28935,
14,
1666,
5113,
570,
367,
2615,
4248,
436,
32572,
2436,
14,
199,
199,
504,
28811,
492,
2986,
12,
1504,
12,
1709,
12,
485,
199,
504,
28811,
14,
3924,
492,
29908,
421,
199,
533,
28406,
8587,
316,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
6088,
14,
11463,
7,
339,
15932,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
9533,
14,
1648,
297,
4048,
534,
1185,
63,
1278,
14,
9533,
63,
604,
63,
344,
14,
1648,
63,
344,
297,
267,
1059,
628,
20486,
4236,
7735,
401,
6863,
29,
549,
9,
339,
768,
1246,
14,
1238,
272,
347,
485,
6726,
63,
1459,
63,
2911,
63,
1185,
8,
277,
12,
1687,
12,
3336,
12,
7971,
63,
5643,
304,
267,
522,
275,
1613,
8,
17103,
8587,
316,
12,
291,
10445,
6726,
63,
1459,
63,
2911,
63,
1185,
8,
411,
12,
3336,
12,
7971,
63,
5643,
9,
267,
367,
333,
315,
1687,
14,
12751,
63,
1185,
63,
5735,
63,
1580,
26,
288,
340,
333,
14,
1185,
63,
344,
14,
9533,
63,
604,
63,
344,
436,
333,
14,
1185,
63,
344,
14,
2558,
63,
344,
508,
3336,
26,
355,
522,
459,
9533,
63,
604,
63,
344,
418,
275,
333,
14,
1185,
63,
344,
14,
9533,
63,
604,
63,
344,
14,
344,
355,
2059,
267,
372,
522,
339,
768,
1246,
14,
1238,
272,
347,
485,
981,
63,
894,
1648,
8,
277,
12,
1771,
1648,
63,
4912,
17894,
267,
522,
275,
1613,
8,
17103,
8587,
316,
12,
291,
10445,
981,
63,
894,
1648,
8,
894,
1648,
63,
4912,
9,
267,
367,
12433,
315,
291,
26,
288,
340,
12433,
14,
11463,
63,
466,
63,
344,
14,
600,
508,
283,
15994,
356,
355,
1771,
1648,
275,
291,
14,
1733,
8318,
894,
1648,
63,
344,
297,
6291,
12433,
14,
344,
3948,
355,
1771,
1648,
14,
1188,
63,
1932,
63,
1045,
63,
1345,
360,
1198,
14,
1188,
63,
6493,
63,
1073,
297,
490,
1338,
3713,
277,
356,
1771,
1648,
12,
283,
6493,
356,
1771,
1648,
14,
9533,
63,
344,
1386,
490,
15686,
63,
344,
29,
277,
14,
1813,
14,
1121,
360,
1198,
14,
2037,
63,
4610,
1959,
344,
9,
267,
372,
522,
421,
199,
533,
28406,
10370,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
6088,
14,
1185,
7,
339,
15932,
63,
604,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
9533,
14,
1648,
14,
604,
297,
267,
283,
20486,
9240,
7030,
297,
16549,
534,
409,
2973,
297,
1478,
29,
549,
12,
6863,
29,
549,
9,
339,
768,
1246,
14,
3029,
272,
347,
664,
63,
4777,
63,
3248,
8,
277,
304,
267,
408,
1803,
314,
4137,
8033,
370,
3877,
641,
314,
15381,
408,
267,
340,
291,
14,
9533,
63,
604,
63,
344,
26,
288,
1865,
275,
291,
14,
9533,
63,
604,
63,
344,
14,
1648,
63,
344,
288,
327,
692,
314,
9952,
402,
314,
3625,
365,
3365,
2419,
314,
7233,
1373,
12,
314,
8033,
63,
3248,
641,
314,
4057,
1471,
506,
295,
2579,
23130,
288,
21571,
10274,
2737,
737,
314,
6634,
402,
314,
3625,
18791,
12,
1325,
1471,
506,
1139,
23130,
737,
314,
6634,
402,
10952,
4057,
6451,
9,
288,
340,
1865,
14,
4968,
63,
344,
1137,
291,
14,
4627,
63,
344,
14,
4968,
63,
344,
26,
355,
327,
1129,
2793,
1133,
986,
314,
4057,
14,
602,
315,
314,
4526,
342,
367,
314,
9952,
6634,
641,
12016,
2952,
355,
327,
413,
9,
664,
63,
4777,
63,
3248,
342,
365,
20042,
370,
506,
2797,
1454,
4012,
4057,
14,
1287,
63,
4456,
1062,
355,
327,
499,
9,
314,
4057,
18699,
1133,
5966,
314,
3211,
1434,
334,
19767,
652,
365,
314,
1420,
1434,
12,
2410,
355,
327,
259,
13659,
402,
1595,
63,
4456,
342,
652,
911,
506,
3063,
342,
776,
355,
8033,
63,
3248,
275,
291,
14,
9533,
63,
604,
63,
344,
423,
362,
63,
6088,
63,
1185,
63,
4777,
63,
3248,
342,
355,
291,
14,
952,
3252,
4777,
63,
3248,
356,
8033,
63,
3248,
1552,
355,
372,
8033,
63,
3248,
288,
372,
291,
14,
4777,
63,
3248,
267,
372,
1613,
8,
17103,
10370,
12,
291,
680,
362,
63,
4777,
63,
3248,
342,
339,
768,
1246,
14,
3029,
272,
347,
1331,
8,
277,
12,
849,
29,
403,
304,
267,
291,
14,
7505,
63,
368,
342,
267,
849,
275,
849,
503,
1052,
267,
340,
440,
849,
14,
362,
360,
1294,
63,
504,
735,
288,
327,
1129,
2793,
1133,
2934,
370,
19843,
314,
2142,
370,
314,
15932,
1865,
1004,
871,
315,
1930,
402,
4057,
3715,
288,
849,
459,
9533,
63,
604,
63,
344,
418,
275,
756,
267,
372,
1613,
8,
17103,
10370,
12,
291,
680,
1574,
8,
885,
9,
421,
199,
533,
28406,
55,
11499,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
6088,
14,
12806,
7,
339,
1032,
89,
63,
475,
63,
470,
384,
19786,
275,
1504,
14,
4082,
360,
20486,
370,
522,
384,
19786,
642,
13782,
297,
849,
29,
549,
12,
3660,
1720,
628,
11423,
7585,
787,
330,
20816,
12,
2985,
883,
506,
28218,
370,
642,
13782,
531,
272,
1032,
89,
63,
9302,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
18546,
14,
2200,
297,
283,
1713,
89,
2332,
358,
339,
768,
1246,
14,
3029,
272,
347,
485,
362,
63,
31240,
63,
9302,
63,
2200,
8,
277,
304,
267,
862,
26,
288,
1032,
89,
63,
4449,
63,
344,
275,
291,
14,
1813,
459,
723,
14,
1238,
14,
576,
2278,
362,
63,
785,
63,
4443,
360,
9533,
297,
283,
4449,
63,
12806,
16,
63,
31240,
5832,
17,
61,
267,
871,
26,
288,
1032,
89,
63,
4449,
63,
344,
275,
291,
14,
1813,
459,
6088,
14,
1985,
14,
4449,
2278,
1733,
8318,
354,
297,
283,
2930,
297,
4018,
1713,
89,
1333,
566,
288,
1032,
89,
63,
4449,
63,
344,
275,
1032,
89,
63,
4449,
63,
344,
59,
16,
1055,
344,
340,
1032,
89,
63,
4449,
63,
344,
587,
756,
267,
340,
440,
1032,
89,
63,
4449,
63,
344,
26,
288,
746,
29908,
6115,
6049,
1133,
2342,
1263,
7809,
4779,
89,
7475,
13853,
398,
372,
469,
288,
283,
354,
356,
291,
423,
908,
63,
4449,
354,
6723,
4779,
89,
3855,
288,
283,
1985,
63,
344,
356,
291,
14,
262,
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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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
] |
nara-l/foursquared
|
util/oget.py
|
262
|
3416
|
#!/usr/bin/python
"""
Pull a oAuth protected page from foursquare.
Expects ~/.oget to contain (one on each line):
CONSUMER_KEY
CONSUMER_KEY_SECRET
USERNAME
PASSWORD
Don't forget to chmod 600 the file!
"""
import httplib
import os
import re
import sys
import urllib
import urllib2
import urlparse
import user
from xml.dom import pulldom
from xml.dom import minidom
import oauth
"""From: http://groups.google.com/group/foursquare-api/web/oauth
@consumer = OAuth::Consumer.new("consumer_token","consumer_secret", {
:site => "http://foursquare.com",
:scheme => :header,
:http_method => :post,
:request_token_path => "/oauth/request_token",
:access_token_path => "/oauth/access_token",
:authorize_path => "/oauth/authorize"
})
"""
SERVER = 'api.foursquare.com:80'
CONTENT_TYPE_HEADER = {'Content-Type' :'application/x-www-form-urlencoded'}
SIGNATURE_METHOD = oauth.OAuthSignatureMethod_HMAC_SHA1()
AUTHEXCHANGE_URL = 'http://api.foursquare.com/v1/authexchange'
def parse_auth_response(auth_response):
return (
re.search('<oauth_token>(.*)</oauth_token>', auth_response).groups()[0],
re.search('<oauth_token_secret>(.*)</oauth_token_secret>',
auth_response).groups()[0]
)
def create_signed_oauth_request(username, password, consumer):
oauth_request = oauth.OAuthRequest.from_consumer_and_token(
consumer, http_method='POST', http_url=AUTHEXCHANGE_URL,
parameters=dict(fs_username=username, fs_password=password))
oauth_request.sign_request(SIGNATURE_METHOD, consumer, None)
return oauth_request
def main():
url = urlparse.urlparse(sys.argv[1])
# Nevermind that the query can have repeated keys.
parameters = dict(urlparse.parse_qsl(url.query))
password_file = open(os.path.join(user.home, '.oget'))
lines = [line.strip() for line in password_file.readlines()]
if len(lines) == 4:
cons_key, cons_key_secret, username, password = lines
access_token = None
else:
cons_key, cons_key_secret, username, password, token, secret = lines
access_token = oauth.OAuthToken(token, secret)
consumer = oauth.OAuthConsumer(cons_key, cons_key_secret)
if not access_token:
oauth_request = create_signed_oauth_request(username, password, consumer)
connection = httplib.HTTPConnection(SERVER)
headers = {'Content-Type' :'application/x-www-form-urlencoded'}
connection.request(oauth_request.http_method, AUTHEXCHANGE_URL,
body=oauth_request.to_postdata(), headers=headers)
auth_response = connection.getresponse().read()
token = parse_auth_response(auth_response)
access_token = oauth.OAuthToken(*token)
open(os.path.join(user.home, '.oget'), 'w').write('\n'.join((
cons_key, cons_key_secret, username, password, token[0], token[1])))
oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer,
access_token, http_method='POST', http_url=url.geturl(),
parameters=parameters)
oauth_request.sign_request(SIGNATURE_METHOD, consumer, access_token)
connection = httplib.HTTPConnection(SERVER)
connection.request(oauth_request.http_method, oauth_request.to_url(),
body=oauth_request.to_postdata(), headers=CONTENT_TYPE_HEADER)
print connection.getresponse().read()
#print minidom.parse(connection.getresponse()).toprettyxml(indent=' ')
if __name__ == '__main__':
main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
624,
199,
27318,
282,
312,
2817,
17819,
2034,
687,
11648,
9646,
14,
199,
199,
13495,
83,
25975,
79,
362,
370,
1395,
334,
368,
641,
1924,
1004,
304,
199,
1864,
13285,
540,
63,
3078,
199,
1864,
13285,
540,
63,
3078,
63,
12961,
199,
11958,
199,
9032,
199,
199,
16932,
1133,
19459,
370,
30106,
11624,
314,
570,
1,
199,
624,
199,
199,
646,
8809,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
646,
4011,
199,
646,
4011,
18,
199,
646,
7097,
199,
646,
922,
199,
504,
2748,
14,
4556,
492,
10299,
4556,
199,
504,
2748,
14,
4556,
492,
19165,
199,
199,
646,
9725,
199,
199,
624,
2532,
26,
1455,
921,
2634,
14,
3098,
14,
957,
15,
923,
15,
13672,
9646,
13,
1246,
15,
2520,
15,
6126,
199,
199,
32,
8542,
275,
11715,
447,
18186,
14,
1222,
480,
8542,
63,
1418,
2266,
8542,
63,
4731,
401,
469,
2126,
520,
2124,
5185,
9265,
298,
1014,
921,
13672,
9646,
14,
957,
401,
2126,
520,
5512,
3777,
9265,
520,
1291,
12,
2126,
520,
1014,
63,
765,
263,
9265,
520,
1932,
12,
2126,
520,
1069,
63,
1418,
63,
515,
9265,
3286,
6126,
15,
1069,
63,
1418,
401,
2126,
520,
2732,
63,
1418,
63,
515,
221,
9265,
3286,
6126,
15,
2732,
63,
1418,
401,
2126,
520,
14204,
63,
515,
258,
9265,
3286,
6126,
15,
14204,
2,
489,
3828,
199,
624,
199,
199,
6613,
275,
283,
1246,
14,
13672,
9646,
14,
957,
26,
1257,
7,
199,
199,
9663,
63,
2711,
63,
7311,
275,
791,
2714,
13,
804,
7,
520,
7,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
936,
199,
199,
26588,
63,
9977,
275,
9725,
14,
12906,
10014,
3767,
63,
23034,
63,
8461,
17,
342,
199,
199,
5580,
1438,
16062,
63,
2632,
275,
283,
1014,
921,
1246,
14,
13672,
9646,
14,
957,
15,
86,
17,
15,
1178,
14197,
7,
421,
199,
318,
2198,
63,
1178,
63,
1310,
8,
1178,
63,
1310,
304,
523,
372,
334,
489,
295,
14,
1733,
4827,
6126,
63,
1418,
13661,
12432,
1108,
6126,
63,
1418,
4206,
1790,
63,
1310,
680,
2634,
3430,
16,
467,
489,
295,
14,
1733,
4827,
6126,
63,
1418,
63,
4731,
13661,
12432,
1108,
6126,
63,
1418,
63,
4731,
4206,
267,
1790,
63,
1310,
680,
2634,
3430,
16,
61,
523,
776,
421,
199,
318,
1218,
63,
1737,
63,
6126,
63,
1069,
8,
2473,
12,
2505,
12,
9790,
304,
523,
9725,
63,
1069,
275,
9725,
14,
12906,
2017,
14,
504,
63,
8542,
63,
460,
63,
1418,
8,
489,
9790,
12,
1455,
63,
765,
534,
4030,
297,
1455,
63,
633,
29,
5580,
1438,
16062,
63,
2632,
12,
489,
2633,
29,
807,
8,
2319,
63,
2473,
29,
2473,
12,
7449,
63,
2060,
29,
2060,
430,
819,
9725,
63,
1069,
14,
1037,
63,
1069,
8,
26588,
63,
9977,
12,
9790,
12,
488,
9,
523,
372,
9725,
63,
1069,
421,
199,
318,
2446,
837,
523,
1166,
275,
7097,
14,
10290,
8,
1274,
14,
3020,
59,
17,
566,
523,
327,
5612,
422,
77,
688,
626,
314,
1827,
883,
1172,
10877,
2883,
14,
523,
2633,
275,
1211,
8,
10290,
14,
1122,
63,
26714,
8,
633,
14,
1131,
430,
819,
2505,
63,
493,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
751,
14,
4219,
12,
1987,
79,
362,
1333,
523,
2385,
275,
359,
604,
14,
1913,
342,
367,
1004,
315,
2505,
63,
493,
14,
9684,
5106,
819,
340,
822,
8,
1278,
9,
508,
841,
26,
272,
13447,
63,
498,
12,
13447,
63,
498,
63,
4731,
12,
3434,
12,
2505,
275,
2385,
272,
2879,
63,
1418,
275,
488,
523,
587,
26,
272,
13447,
63,
498,
12,
13447,
63,
498,
63,
4731,
12,
3434,
12,
2505,
12,
1526,
12,
7565,
275,
2385,
272,
2879,
63,
1418,
275,
9725,
14,
12906,
3264,
8,
1418,
12,
7565,
9,
819,
9790,
275,
9725,
14,
12906,
18186,
8,
8704,
63,
498,
12,
13447,
63,
498,
63,
4731,
9,
819,
340,
440,
2879,
63,
1418,
26,
272,
9725,
63,
1069,
275,
1218,
63,
1737,
63,
6126,
63,
1069,
8,
2473,
12,
2505,
12,
9790,
9,
339,
1950,
275,
8809,
14,
19114,
8,
6613,
9,
339,
2323,
275,
791,
2714,
13,
804,
7,
520,
7,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
936,
272,
1950,
14,
1069,
8,
6126,
63,
1069,
14,
1014,
63,
765,
12,
7560,
1438,
16062,
63,
2632,
12,
267,
2396,
29,
6126,
63,
1069,
14,
475,
63,
1932,
576,
1062,
2323,
29,
2139,
9,
339,
1790,
63,
1310,
275,
1950,
14,
25006,
1252,
739,
342,
272,
1526,
275,
2198,
63,
1178,
63,
1310,
8,
1178,
63,
1310,
9,
272,
2879,
63,
1418,
275,
9725,
14,
12906,
3264,
2031,
1418,
9,
272,
1551,
8,
736,
14,
515,
14,
904,
8,
751,
14,
4219,
12,
1987,
79,
362,
659,
283,
87,
1959,
952,
2258,
78,
1370,
904,
1332,
489,
13447,
63,
498,
12,
13447,
63,
498,
63,
4731,
12,
3434,
12,
2505,
12,
1526,
59,
16,
467,
1526,
59,
17,
11845,
819,
9725,
63,
1069,
275,
9725,
14,
12906,
2017,
14,
504,
63,
8542,
63,
460,
63,
1418,
8,
8542,
12,
489,
2879,
63,
1418,
12,
1455,
63,
765,
534,
4030,
297,
1455,
63,
633,
29,
633,
14,
32130,
1062,
489,
2633,
29,
3214,
9,
523,
9725,
63,
1069,
14,
1037,
63,
1069,
8,
26588,
63,
9977,
12,
9790,
12,
2879,
63,
1418,
9,
819,
1950,
275,
8809,
14,
19114,
8,
6613,
9,
523,
1950,
14,
1069,
8,
6126,
63,
1069,
14,
1014,
63,
765,
12,
9725,
63,
1069,
14,
475,
63,
633,
1062,
489,
2396,
29,
6126,
63,
1069,
14,
475,
63,
1932,
576,
1062,
2323,
29,
9663,
63,
2711,
63,
7311,
9,
819,
870,
1950,
14,
25006,
1252,
739,
342,
523,
327,
1361,
19165,
14,
1122,
8,
2105,
14,
25006,
8801,
2119,
21958,
1652,
8,
3724,
534,
221,
5320,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
624,
199,
27318,
282,
312,
2817,
17819,
2034,
687,
11648,
9646,
14,
199,
199,
13495,
83,
25975,
79,
362,
370,
1395,
334,
368,
641,
1924,
1004,
304,
199,
1864,
13285,
540,
63,
3078,
199,
1864,
13285,
540,
63,
3078,
63,
12961,
199,
11958,
199,
9032,
199,
199,
16932,
1133,
19459,
370,
30106,
11624,
314,
570,
1,
199,
624,
199,
199,
646,
8809,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
646,
4011,
199,
646,
4011,
18,
199,
646,
7097,
199,
646,
922,
199,
504,
2748,
14,
4556,
492,
10299,
4556,
199,
504,
2748,
14,
4556,
492,
19165,
199,
199,
646,
9725,
199,
199,
624,
2532,
26,
1455,
921,
2634,
14,
3098,
14,
957,
15,
923,
15,
13672,
9646,
13,
1246,
15,
2520,
15,
6126,
199,
199,
32,
8542,
275,
11715,
447,
18186,
14,
1222,
480,
8542,
63,
1418,
2266,
8542,
63,
4731,
401,
469,
2126,
520,
2124,
5185,
9265,
298,
1014,
921,
13672,
9646,
14,
957,
401,
2126,
520,
5512,
3777,
9265,
520,
1291,
12,
2126,
520,
1014,
63,
765,
263,
9265,
520,
1932,
12,
2126,
520,
1069,
63,
1418,
63,
515,
9265,
3286,
6126,
15,
1069,
63,
1418,
401,
2126,
520,
2732,
63,
1418,
63,
515,
221,
9265,
3286,
6126,
15,
2732,
63,
1418,
401,
2126,
520,
14204,
63,
515,
258,
9265,
3286,
6126,
15,
14204,
2,
489,
3828,
199,
624,
199,
199,
6613,
275,
283,
1246,
14,
13672,
9646,
14,
957,
26,
1257,
7,
199,
199,
9663,
63,
2711,
63,
7311,
275,
791,
2714,
13,
804,
7,
520,
7,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
936,
199,
199,
26588,
63,
9977,
275,
9725,
14,
12906,
10014,
3767,
63,
23034,
63,
8461,
17,
342,
199,
199,
5580,
1438,
16062,
63,
2632,
275,
283,
1014,
921,
1246,
14,
13672,
9646,
14,
957,
15,
86,
17,
15,
1178,
14197,
7,
421,
199,
318,
2198,
63,
1178,
63,
1310,
8,
1178,
63,
1310,
304,
523,
372,
334,
489,
295,
14,
1733,
4827,
6126,
63,
1418,
13661,
12432,
1108,
6126,
63,
1418,
4206,
1790,
63,
1310,
680,
2634,
3430,
16,
467,
489,
295,
14,
1733,
4827,
6126,
63,
1418,
63,
4731,
13661,
12432,
1108,
6126,
63,
1418,
63,
4731,
4206,
267,
1790,
63,
1310,
680,
2634,
3430,
16,
61,
523,
776,
421,
199,
318,
1218,
63,
1737,
63,
6126,
63,
1069,
8,
2473,
12,
2505,
12,
9790,
304,
523,
9725,
63,
1069,
275,
9725,
14,
12906,
2017,
14,
504,
63,
8542,
63,
460,
63,
1418,
8,
489,
9790,
12,
1455,
63,
765,
534,
4030,
297,
1455,
63,
633,
29,
5580,
1438,
16062,
63,
2632,
12,
489,
2633,
29,
807,
8,
2319,
63,
2473,
29,
2473,
12,
7449,
63,
2060,
29,
2060,
430,
819,
9725,
63,
1069,
14,
1037,
63,
1069,
8,
26588,
63,
9977,
12,
9790,
12,
488,
9,
523,
372,
9725,
63,
1069,
421,
199,
318,
2446,
837,
523,
1166,
275,
7097,
14,
10290,
8,
1274,
14,
3020,
59,
17,
566,
523,
327,
5612,
422,
77,
688,
626,
314,
1827,
883,
1172,
10877,
2883,
14,
523,
2633,
275,
1211,
8,
10290,
14,
1122,
63,
26714,
8,
633,
14,
1131,
430,
819,
2505,
63,
493,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
751,
14,
4219,
12,
1987,
79,
362,
1333,
523,
2385,
275,
359,
604,
14,
1913,
342,
367,
1004,
315,
2505,
63,
493,
14,
9684,
5106,
819,
340,
822,
8,
1278,
9,
508,
841,
26,
272,
13447,
63,
498,
12,
13447,
63,
498,
63,
4731,
12,
3434,
12,
2505,
275,
2385,
272,
2879,
63,
1418,
275,
488,
523,
587,
26,
272,
13447,
63,
498,
12,
13447,
63,
498,
63,
4731,
12,
3434,
12,
2505,
12,
1526,
12,
7565,
275,
2385,
272,
2879,
63,
1418,
275,
9725,
14,
12906,
3264,
8,
1418,
12,
7565,
9,
819,
9790,
275,
9725,
14,
12906,
18186,
8,
8704,
63,
498,
12,
13447,
63,
498,
63,
4731,
9,
819,
340,
440,
2879,
63,
1418,
26,
272,
9725,
63,
1069,
275,
1218,
63,
1737,
63,
6126,
63,
1069,
8,
2473,
12,
2505,
12,
9790,
9,
339,
1950,
275,
8809,
14,
19114,
8,
6613,
9,
339,
2323,
275,
791,
2714,
13,
804,
7,
520,
7,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
936,
272,
1950,
14,
1069,
8,
6126,
63,
1069,
14,
1014,
63,
765,
12,
7560,
1438,
16062,
63,
2632,
12,
267,
2396,
29,
6126,
63,
1069,
14,
475,
63,
1932,
576,
1062,
2323,
29,
2139,
9,
339,
1790,
63,
1310,
275,
1950,
14,
25006,
1252,
739,
342,
272,
1526,
275,
2198,
63,
1178,
63,
1310,
8,
1178,
63,
1310,
9,
272,
2879,
63,
1418,
275,
9725,
14,
12906,
3264,
2031,
1418,
9,
272,
1551,
8,
736,
14,
515,
14,
904,
8,
751,
14,
4219,
12,
1987,
79,
362,
659,
283,
87,
1959,
952,
2258,
78,
1370,
904,
1332,
489,
13447,
63,
498,
12,
13447,
63,
498,
63,
4731,
12,
3434,
12,
2505,
12,
1526,
59,
16,
467,
1526,
59,
17,
11845,
819,
9725,
63,
1069,
275,
9725,
14,
12906,
2017,
14,
504,
63,
8542,
63,
460,
63,
1418,
8,
8542,
12,
489,
2879,
63,
1418,
12,
1455,
63,
765,
534,
4030,
297,
1455,
63,
633,
29,
633,
14,
32130,
1062,
489,
2633,
29,
3214,
9,
523,
9725,
63,
1069,
14,
1037,
63,
1069,
8,
26588,
63,
9977,
12,
9790,
12,
2879,
63,
1418,
9,
819,
1950,
275,
8809,
14,
19114,
8,
6613,
9,
523,
1950,
14,
1069,
8,
6126,
63,
1069,
14,
1014,
63,
765,
12,
9725,
63,
1069,
14,
475,
63,
633,
1062,
489,
2396,
29,
6126,
63,
1069,
14,
475,
63,
1932,
576,
1062,
2323,
29,
9663,
63,
2711,
63,
7311,
9,
819,
870,
1950,
14,
25006,
1252,
739,
342,
523,
327,
1361,
19165,
14,
1122,
8,
2105,
14,
25006,
8801,
2119,
21958,
1652,
8,
3724,
534,
221,
5320,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
analurandis/Tur
|
backend/venv/Lib/site-packages/unidecode/x093.py
|
252
|
4666
|
data = (
'Lun ', # 0x00
'Kua ', # 0x01
'Ling ', # 0x02
'Bei ', # 0x03
'Lu ', # 0x04
'Li ', # 0x05
'Qiang ', # 0x06
'Pou ', # 0x07
'Juan ', # 0x08
'Min ', # 0x09
'Zui ', # 0x0a
'Peng ', # 0x0b
'An ', # 0x0c
'Pi ', # 0x0d
'Xian ', # 0x0e
'Ya ', # 0x0f
'Zhui ', # 0x10
'Lei ', # 0x11
'A ', # 0x12
'Kong ', # 0x13
'Ta ', # 0x14
'Kun ', # 0x15
'Du ', # 0x16
'Wei ', # 0x17
'Chui ', # 0x18
'Zi ', # 0x19
'Zheng ', # 0x1a
'Ben ', # 0x1b
'Nie ', # 0x1c
'Cong ', # 0x1d
'Qun ', # 0x1e
'Tan ', # 0x1f
'Ding ', # 0x20
'Qi ', # 0x21
'Qian ', # 0x22
'Zhuo ', # 0x23
'Qi ', # 0x24
'Yu ', # 0x25
'Jin ', # 0x26
'Guan ', # 0x27
'Mao ', # 0x28
'Chang ', # 0x29
'Tian ', # 0x2a
'Xi ', # 0x2b
'Lian ', # 0x2c
'Tao ', # 0x2d
'Gu ', # 0x2e
'Cuo ', # 0x2f
'Shu ', # 0x30
'Zhen ', # 0x31
'Lu ', # 0x32
'Meng ', # 0x33
'Lu ', # 0x34
'Hua ', # 0x35
'Biao ', # 0x36
'Ga ', # 0x37
'Lai ', # 0x38
'Ken ', # 0x39
'Kazari ', # 0x3a
'Bu ', # 0x3b
'Nai ', # 0x3c
'Wan ', # 0x3d
'Zan ', # 0x3e
'[?] ', # 0x3f
'De ', # 0x40
'Xian ', # 0x41
'[?] ', # 0x42
'Huo ', # 0x43
'Liang ', # 0x44
'[?] ', # 0x45
'Men ', # 0x46
'Kai ', # 0x47
'Ying ', # 0x48
'Di ', # 0x49
'Lian ', # 0x4a
'Guo ', # 0x4b
'Xian ', # 0x4c
'Du ', # 0x4d
'Tu ', # 0x4e
'Wei ', # 0x4f
'Cong ', # 0x50
'Fu ', # 0x51
'Rou ', # 0x52
'Ji ', # 0x53
'E ', # 0x54
'Rou ', # 0x55
'Chen ', # 0x56
'Ti ', # 0x57
'Zha ', # 0x58
'Hong ', # 0x59
'Yang ', # 0x5a
'Duan ', # 0x5b
'Xia ', # 0x5c
'Yu ', # 0x5d
'Keng ', # 0x5e
'Xing ', # 0x5f
'Huang ', # 0x60
'Wei ', # 0x61
'Fu ', # 0x62
'Zhao ', # 0x63
'Cha ', # 0x64
'Qie ', # 0x65
'She ', # 0x66
'Hong ', # 0x67
'Kui ', # 0x68
'Tian ', # 0x69
'Mou ', # 0x6a
'Qiao ', # 0x6b
'Qiao ', # 0x6c
'Hou ', # 0x6d
'Tou ', # 0x6e
'Cong ', # 0x6f
'Huan ', # 0x70
'Ye ', # 0x71
'Min ', # 0x72
'Jian ', # 0x73
'Duan ', # 0x74
'Jian ', # 0x75
'Song ', # 0x76
'Kui ', # 0x77
'Hu ', # 0x78
'Xuan ', # 0x79
'Duo ', # 0x7a
'Jie ', # 0x7b
'Zhen ', # 0x7c
'Bian ', # 0x7d
'Zhong ', # 0x7e
'Zi ', # 0x7f
'Xiu ', # 0x80
'Ye ', # 0x81
'Mei ', # 0x82
'Pai ', # 0x83
'Ai ', # 0x84
'Jie ', # 0x85
'[?] ', # 0x86
'Mei ', # 0x87
'Chuo ', # 0x88
'Ta ', # 0x89
'Bang ', # 0x8a
'Xia ', # 0x8b
'Lian ', # 0x8c
'Suo ', # 0x8d
'Xi ', # 0x8e
'Liu ', # 0x8f
'Zu ', # 0x90
'Ye ', # 0x91
'Nou ', # 0x92
'Weng ', # 0x93
'Rong ', # 0x94
'Tang ', # 0x95
'Suo ', # 0x96
'Qiang ', # 0x97
'Ge ', # 0x98
'Shuo ', # 0x99
'Chui ', # 0x9a
'Bo ', # 0x9b
'Pan ', # 0x9c
'Sa ', # 0x9d
'Bi ', # 0x9e
'Sang ', # 0x9f
'Gang ', # 0xa0
'Zi ', # 0xa1
'Wu ', # 0xa2
'Ying ', # 0xa3
'Huang ', # 0xa4
'Tiao ', # 0xa5
'Liu ', # 0xa6
'Kai ', # 0xa7
'Sun ', # 0xa8
'Sha ', # 0xa9
'Sou ', # 0xaa
'Wan ', # 0xab
'Hao ', # 0xac
'Zhen ', # 0xad
'Zhen ', # 0xae
'Luo ', # 0xaf
'Yi ', # 0xb0
'Yuan ', # 0xb1
'Tang ', # 0xb2
'Nie ', # 0xb3
'Xi ', # 0xb4
'Jia ', # 0xb5
'Ge ', # 0xb6
'Ma ', # 0xb7
'Juan ', # 0xb8
'Kasugai ', # 0xb9
'Habaki ', # 0xba
'Suo ', # 0xbb
'[?] ', # 0xbc
'[?] ', # 0xbd
'[?] ', # 0xbe
'Na ', # 0xbf
'Lu ', # 0xc0
'Suo ', # 0xc1
'Ou ', # 0xc2
'Zu ', # 0xc3
'Tuan ', # 0xc4
'Xiu ', # 0xc5
'Guan ', # 0xc6
'Xuan ', # 0xc7
'Lian ', # 0xc8
'Shou ', # 0xc9
'Ao ', # 0xca
'Man ', # 0xcb
'Mo ', # 0xcc
'Luo ', # 0xcd
'Bi ', # 0xce
'Wei ', # 0xcf
'Liu ', # 0xd0
'Di ', # 0xd1
'Qiao ', # 0xd2
'Cong ', # 0xd3
'Yi ', # 0xd4
'Lu ', # 0xd5
'Ao ', # 0xd6
'Keng ', # 0xd7
'Qiang ', # 0xd8
'Cui ', # 0xd9
'Qi ', # 0xda
'Chang ', # 0xdb
'Tang ', # 0xdc
'Man ', # 0xdd
'Yong ', # 0xde
'Chan ', # 0xdf
'Feng ', # 0xe0
'Jing ', # 0xe1
'Biao ', # 0xe2
'Shu ', # 0xe3
'Lou ', # 0xe4
'Xiu ', # 0xe5
'Cong ', # 0xe6
'Long ', # 0xe7
'Zan ', # 0xe8
'Jian ', # 0xe9
'Cao ', # 0xea
'Li ', # 0xeb
'Xia ', # 0xec
'Xi ', # 0xed
'Kang ', # 0xee
'[?] ', # 0xef
'Beng ', # 0xf0
'[?] ', # 0xf1
'[?] ', # 0xf2
'Zheng ', # 0xf3
'Lu ', # 0xf4
'Hua ', # 0xf5
'Ji ', # 0xf6
'Pu ', # 0xf7
'Hui ', # 0xf8
'Qiang ', # 0xf9
'Po ', # 0xfa
'Lin ', # 0xfb
'Suo ', # 0xfc
'Xiu ', # 0xfd
'San ', # 0xfe
'Cheng ', # 0xff
)
|
mit
|
[
576,
275,
334,
199,
7,
44,
324,
1656,
259,
327,
378,
88,
383,
199,
7,
43,
1458,
1656,
259,
327,
378,
88,
614,
199,
7,
44,
316,
1656,
259,
327,
378,
88,
996,
199,
7,
3655,
73,
1656,
259,
327,
378,
88,
1644,
199,
7,
18176,
1656,
259,
327,
378,
88,
966,
199,
7,
13009,
1656,
259,
327,
378,
88,
1717,
199,
7,
19910,
621,
1656,
259,
327,
378,
88,
1690,
199,
7,
48,
810,
1656,
259,
327,
378,
88,
1780,
199,
7,
42,
7856,
1656,
259,
327,
378,
88,
2036,
199,
7,
4649,
1656,
259,
327,
378,
88,
1643,
199,
7,
58,
1907,
1656,
259,
327,
378,
88,
16,
65,
199,
7,
48,
7420,
1656,
259,
327,
378,
88,
16,
66,
199,
7,
2493,
1656,
259,
327,
378,
88,
16,
67,
199,
7,
10542,
1656,
259,
327,
378,
88,
16,
68,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
16,
69,
199,
7,
28786,
1656,
259,
327,
378,
88,
16,
70,
199,
7,
12674,
1907,
1656,
259,
327,
378,
88,
709,
199,
7,
2553,
73,
1656,
259,
327,
378,
88,
845,
199,
7,
33,
1656,
259,
327,
378,
88,
713,
199,
7,
43,
951,
1656,
259,
327,
378,
88,
969,
199,
7,
22620,
1656,
259,
327,
378,
88,
1079,
199,
7,
43,
324,
1656,
259,
327,
378,
88,
1046,
199,
7,
36,
85,
1656,
259,
327,
378,
88,
975,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
1196,
199,
7,
1049,
1907,
1656,
259,
327,
378,
88,
1085,
199,
7,
22534,
1656,
259,
327,
378,
88,
1167,
199,
7,
12674,
7420,
1656,
259,
327,
378,
88,
17,
65,
199,
7,
31231,
1656,
259,
327,
378,
88,
17,
66,
199,
7,
46,
1873,
1656,
259,
327,
378,
88,
17,
67,
199,
7,
714,
71,
1656,
259,
327,
378,
88,
17,
68,
199,
7,
49,
324,
1656,
259,
327,
378,
88,
17,
69,
199,
7,
52,
290,
1656,
259,
327,
378,
88,
17,
70,
199,
7,
36,
316,
1656,
259,
327,
378,
88,
1165,
199,
7,
19910,
1656,
259,
327,
378,
88,
2025,
199,
7,
49,
5653,
1656,
259,
327,
378,
88,
1081,
199,
7,
31183,
79,
1656,
259,
327,
378,
88,
1789,
199,
7,
19910,
1656,
259,
327,
378,
88,
1194,
199,
7,
24388,
1656,
259,
327,
378,
88,
821,
199,
7,
42,
262,
1656,
259,
327,
378,
88,
1479,
199,
7,
39,
7856,
1656,
259,
327,
378,
88,
1465,
199,
7,
45,
8035,
1656,
259,
327,
378,
88,
1651,
199,
7,
1049,
621,
1656,
259,
327,
378,
88,
1398,
199,
7,
52,
5653,
1656,
259,
327,
378,
88,
18,
65,
199,
7,
14828,
1656,
259,
327,
378,
88,
18,
66,
199,
7,
44,
5653,
1656,
259,
327,
378,
88,
18,
67,
199,
7,
52,
8035,
1656,
259,
327,
378,
88,
18,
68,
199,
7,
11548,
1656,
259,
327,
378,
88,
18,
69,
199,
7,
35,
13780,
1656,
259,
327,
378,
88,
18,
70,
199,
7,
2662,
85,
1656,
259,
327,
378,
88,
1216,
199,
7,
12674,
287,
1656,
259,
327,
378,
88,
2192,
199,
7,
18176,
1656,
259,
327,
378,
88,
708,
199,
7,
45,
7420,
1656,
259,
327,
378,
88,
1153,
199,
7,
18176,
1656,
259,
327,
378,
88,
1082,
199,
7,
40,
1458,
1656,
259,
327,
378,
88,
1276,
199,
7,
34,
18939,
1656,
259,
327,
378,
88,
1344,
199,
7,
17295,
1656,
259,
327,
378,
88,
1401,
199,
7,
44,
5789,
1656,
259,
327,
378,
88,
1703,
199,
7,
43,
287,
1656,
259,
327,
378,
88,
1355,
199,
7,
43,
4651,
759,
1656,
259,
327,
378,
88,
19,
65,
199,
7,
1713,
1656,
259,
327,
378,
88,
19,
66,
199,
7,
46,
5789,
1656,
259,
327,
378,
88,
19,
67,
199,
7,
55,
290,
1656,
259,
327,
378,
88,
19,
68,
199,
7,
58,
290,
1656,
259,
327,
378,
88,
19,
69,
199,
17892,
1656,
259,
327,
378,
88,
19,
70,
199,
7,
872,
1656,
259,
327,
378,
88,
2167,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
2953,
199,
17892,
1656,
259,
327,
378,
88,
2260,
199,
7,
40,
13780,
1656,
259,
327,
378,
88,
2824,
199,
7,
13009,
621,
1656,
259,
327,
378,
88,
1602,
199,
17892,
1656,
259,
327,
378,
88,
2322,
199,
7,
29230,
1656,
259,
327,
378,
88,
2466,
199,
7,
43,
5789,
1656,
259,
327,
378,
88,
2417,
199,
7,
57,
316,
1656,
259,
327,
378,
88,
2006,
199,
7,
1341,
1656,
259,
327,
378,
88,
1887,
199,
7,
44,
5653,
1656,
259,
327,
378,
88,
20,
65,
199,
7,
11548,
79,
1656,
259,
327,
378,
88,
20,
66,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
20,
67,
199,
7,
36,
85,
1656,
259,
327,
378,
88,
20,
68,
199,
7,
30669,
1656,
259,
327,
378,
88,
20,
69,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
20,
70,
199,
7,
714,
71,
1656,
259,
327,
378,
88,
1400,
199,
7,
19590,
1656,
259,
327,
378,
88,
2869,
199,
7,
5407,
1656,
259,
327,
378,
88,
2528,
199,
7,
16911,
1656,
259,
327,
378,
88,
2481,
199,
7,
37,
1656,
259,
327,
378,
88,
1477,
199,
7,
5407,
1656,
259,
327,
378,
88,
1229,
199,
7,
1049,
287,
1656,
259,
327,
378,
88,
1367,
199,
7,
22731,
1656,
259,
327,
378,
88,
1641,
199,
7,
58,
2411,
1656,
259,
327,
378,
88,
2010,
199,
7,
40,
951,
1656,
259,
327,
378,
88,
1427,
199,
7,
57,
621,
1656,
259,
327,
378,
88,
21,
65,
199,
7,
36,
7856,
1656,
259,
327,
378,
88,
21,
66,
199,
7,
56,
4674,
1656,
259,
327,
378,
88,
21,
67,
199,
7,
24388,
1656,
259,
327,
378,
88,
21,
68,
199,
7,
43,
7420,
1656,
259,
327,
378,
88,
21,
69,
199,
7,
56,
316,
1656,
259,
327,
378,
88,
21,
70,
199,
7,
25542,
621,
1656,
259,
327,
378,
88,
2259,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
2976,
199,
7,
19590,
1656,
259,
327,
378,
88,
2789,
199,
7,
58,
2411,
79,
1656,
259,
327,
378,
88,
2766,
199,
7,
1049,
65,
1656,
259,
327,
378,
88,
772,
199,
7,
49,
1873,
1656,
259,
327,
378,
88,
2182
] |
[
275,
334,
199,
7,
44,
324,
1656,
259,
327,
378,
88,
383,
199,
7,
43,
1458,
1656,
259,
327,
378,
88,
614,
199,
7,
44,
316,
1656,
259,
327,
378,
88,
996,
199,
7,
3655,
73,
1656,
259,
327,
378,
88,
1644,
199,
7,
18176,
1656,
259,
327,
378,
88,
966,
199,
7,
13009,
1656,
259,
327,
378,
88,
1717,
199,
7,
19910,
621,
1656,
259,
327,
378,
88,
1690,
199,
7,
48,
810,
1656,
259,
327,
378,
88,
1780,
199,
7,
42,
7856,
1656,
259,
327,
378,
88,
2036,
199,
7,
4649,
1656,
259,
327,
378,
88,
1643,
199,
7,
58,
1907,
1656,
259,
327,
378,
88,
16,
65,
199,
7,
48,
7420,
1656,
259,
327,
378,
88,
16,
66,
199,
7,
2493,
1656,
259,
327,
378,
88,
16,
67,
199,
7,
10542,
1656,
259,
327,
378,
88,
16,
68,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
16,
69,
199,
7,
28786,
1656,
259,
327,
378,
88,
16,
70,
199,
7,
12674,
1907,
1656,
259,
327,
378,
88,
709,
199,
7,
2553,
73,
1656,
259,
327,
378,
88,
845,
199,
7,
33,
1656,
259,
327,
378,
88,
713,
199,
7,
43,
951,
1656,
259,
327,
378,
88,
969,
199,
7,
22620,
1656,
259,
327,
378,
88,
1079,
199,
7,
43,
324,
1656,
259,
327,
378,
88,
1046,
199,
7,
36,
85,
1656,
259,
327,
378,
88,
975,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
1196,
199,
7,
1049,
1907,
1656,
259,
327,
378,
88,
1085,
199,
7,
22534,
1656,
259,
327,
378,
88,
1167,
199,
7,
12674,
7420,
1656,
259,
327,
378,
88,
17,
65,
199,
7,
31231,
1656,
259,
327,
378,
88,
17,
66,
199,
7,
46,
1873,
1656,
259,
327,
378,
88,
17,
67,
199,
7,
714,
71,
1656,
259,
327,
378,
88,
17,
68,
199,
7,
49,
324,
1656,
259,
327,
378,
88,
17,
69,
199,
7,
52,
290,
1656,
259,
327,
378,
88,
17,
70,
199,
7,
36,
316,
1656,
259,
327,
378,
88,
1165,
199,
7,
19910,
1656,
259,
327,
378,
88,
2025,
199,
7,
49,
5653,
1656,
259,
327,
378,
88,
1081,
199,
7,
31183,
79,
1656,
259,
327,
378,
88,
1789,
199,
7,
19910,
1656,
259,
327,
378,
88,
1194,
199,
7,
24388,
1656,
259,
327,
378,
88,
821,
199,
7,
42,
262,
1656,
259,
327,
378,
88,
1479,
199,
7,
39,
7856,
1656,
259,
327,
378,
88,
1465,
199,
7,
45,
8035,
1656,
259,
327,
378,
88,
1651,
199,
7,
1049,
621,
1656,
259,
327,
378,
88,
1398,
199,
7,
52,
5653,
1656,
259,
327,
378,
88,
18,
65,
199,
7,
14828,
1656,
259,
327,
378,
88,
18,
66,
199,
7,
44,
5653,
1656,
259,
327,
378,
88,
18,
67,
199,
7,
52,
8035,
1656,
259,
327,
378,
88,
18,
68,
199,
7,
11548,
1656,
259,
327,
378,
88,
18,
69,
199,
7,
35,
13780,
1656,
259,
327,
378,
88,
18,
70,
199,
7,
2662,
85,
1656,
259,
327,
378,
88,
1216,
199,
7,
12674,
287,
1656,
259,
327,
378,
88,
2192,
199,
7,
18176,
1656,
259,
327,
378,
88,
708,
199,
7,
45,
7420,
1656,
259,
327,
378,
88,
1153,
199,
7,
18176,
1656,
259,
327,
378,
88,
1082,
199,
7,
40,
1458,
1656,
259,
327,
378,
88,
1276,
199,
7,
34,
18939,
1656,
259,
327,
378,
88,
1344,
199,
7,
17295,
1656,
259,
327,
378,
88,
1401,
199,
7,
44,
5789,
1656,
259,
327,
378,
88,
1703,
199,
7,
43,
287,
1656,
259,
327,
378,
88,
1355,
199,
7,
43,
4651,
759,
1656,
259,
327,
378,
88,
19,
65,
199,
7,
1713,
1656,
259,
327,
378,
88,
19,
66,
199,
7,
46,
5789,
1656,
259,
327,
378,
88,
19,
67,
199,
7,
55,
290,
1656,
259,
327,
378,
88,
19,
68,
199,
7,
58,
290,
1656,
259,
327,
378,
88,
19,
69,
199,
17892,
1656,
259,
327,
378,
88,
19,
70,
199,
7,
872,
1656,
259,
327,
378,
88,
2167,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
2953,
199,
17892,
1656,
259,
327,
378,
88,
2260,
199,
7,
40,
13780,
1656,
259,
327,
378,
88,
2824,
199,
7,
13009,
621,
1656,
259,
327,
378,
88,
1602,
199,
17892,
1656,
259,
327,
378,
88,
2322,
199,
7,
29230,
1656,
259,
327,
378,
88,
2466,
199,
7,
43,
5789,
1656,
259,
327,
378,
88,
2417,
199,
7,
57,
316,
1656,
259,
327,
378,
88,
2006,
199,
7,
1341,
1656,
259,
327,
378,
88,
1887,
199,
7,
44,
5653,
1656,
259,
327,
378,
88,
20,
65,
199,
7,
11548,
79,
1656,
259,
327,
378,
88,
20,
66,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
20,
67,
199,
7,
36,
85,
1656,
259,
327,
378,
88,
20,
68,
199,
7,
30669,
1656,
259,
327,
378,
88,
20,
69,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
20,
70,
199,
7,
714,
71,
1656,
259,
327,
378,
88,
1400,
199,
7,
19590,
1656,
259,
327,
378,
88,
2869,
199,
7,
5407,
1656,
259,
327,
378,
88,
2528,
199,
7,
16911,
1656,
259,
327,
378,
88,
2481,
199,
7,
37,
1656,
259,
327,
378,
88,
1477,
199,
7,
5407,
1656,
259,
327,
378,
88,
1229,
199,
7,
1049,
287,
1656,
259,
327,
378,
88,
1367,
199,
7,
22731,
1656,
259,
327,
378,
88,
1641,
199,
7,
58,
2411,
1656,
259,
327,
378,
88,
2010,
199,
7,
40,
951,
1656,
259,
327,
378,
88,
1427,
199,
7,
57,
621,
1656,
259,
327,
378,
88,
21,
65,
199,
7,
36,
7856,
1656,
259,
327,
378,
88,
21,
66,
199,
7,
56,
4674,
1656,
259,
327,
378,
88,
21,
67,
199,
7,
24388,
1656,
259,
327,
378,
88,
21,
68,
199,
7,
43,
7420,
1656,
259,
327,
378,
88,
21,
69,
199,
7,
56,
316,
1656,
259,
327,
378,
88,
21,
70,
199,
7,
25542,
621,
1656,
259,
327,
378,
88,
2259,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
2976,
199,
7,
19590,
1656,
259,
327,
378,
88,
2789,
199,
7,
58,
2411,
79,
1656,
259,
327,
378,
88,
2766,
199,
7,
1049,
65,
1656,
259,
327,
378,
88,
772,
199,
7,
49,
1873,
1656,
259,
327,
378,
88,
2182,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ludia/moto
|
moto/sts/models.py
|
19
|
1400
|
from __future__ import unicode_literals
import datetime
from moto.core import BaseBackend
from moto.core.utils import iso_8601_datetime_with_milliseconds
class Token(object):
def __init__(self, duration, name=None, policy=None):
now = datetime.datetime.now()
self.expiration = now + datetime.timedelta(seconds=duration)
self.name = name
self.policy = None
@property
def expiration_ISO8601(self):
return iso_8601_datetime_with_milliseconds(self.expiration)
class AssumedRole(object):
def __init__(self, role_session_name, role_arn, policy, duration, external_id):
self.session_name = role_session_name
self.arn = role_arn
self.policy = policy
now = datetime.datetime.now()
self.expiration = now + datetime.timedelta(seconds=duration)
self.external_id = external_id
@property
def expiration_ISO8601(self):
return iso_8601_datetime_with_milliseconds(self.expiration)
class STSBackend(BaseBackend):
def get_session_token(self, duration):
token = Token(duration=duration)
return token
def get_federation_token(self, name, duration, policy):
token = Token(duration=duration, name=name, policy=policy)
return token
def assume_role(self, **kwargs):
role = AssumedRole(**kwargs)
return role
sts_backend = STSBackend()
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
2197,
199,
504,
333,
3459,
14,
1018,
492,
3523,
8447,
199,
504,
333,
3459,
14,
1018,
14,
1208,
492,
11601,
63,
15363,
63,
2083,
63,
1045,
63,
19579,
4515,
421,
199,
533,
8767,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
7373,
12,
536,
29,
403,
12,
4592,
29,
403,
304,
267,
3063,
275,
2197,
14,
2083,
14,
2131,
342,
267,
291,
14,
15469,
275,
3063,
435,
2197,
14,
7473,
8,
4515,
29,
5553,
9,
267,
291,
14,
354,
275,
536,
267,
291,
14,
3185,
275,
488,
339,
768,
1829,
272,
347,
15399,
63,
7336,
15363,
8,
277,
304,
267,
372,
11601,
63,
15363,
63,
2083,
63,
1045,
63,
19579,
4515,
8,
277,
14,
15469,
9,
421,
199,
533,
16269,
68,
7422,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
4719,
63,
1730,
63,
354,
12,
4719,
63,
1060,
12,
4592,
12,
7373,
12,
5957,
63,
344,
304,
267,
291,
14,
1730,
63,
354,
275,
4719,
63,
1730,
63,
354,
267,
291,
14,
1060,
275,
4719,
63,
1060,
267,
291,
14,
3185,
275,
4592,
267,
3063,
275,
2197,
14,
2083,
14,
2131,
342,
267,
291,
14,
15469,
275,
3063,
435,
2197,
14,
7473,
8,
4515,
29,
5553,
9,
267,
291,
14,
5159,
63,
344,
275,
5957,
63,
344,
339,
768,
1829,
272,
347,
15399,
63,
7336,
15363,
8,
277,
304,
267,
372,
11601,
63,
15363,
63,
2083,
63,
1045,
63,
19579,
4515,
8,
277,
14,
15469,
9,
421,
199,
533,
4384,
51,
8447,
8,
1563,
8447,
304,
272,
347,
664,
63,
1730,
63,
1418,
8,
277,
12,
7373,
304,
267,
1526,
275,
8767,
8,
5553,
29,
5553,
9,
267,
372,
1526,
339,
347,
664,
63,
771,
32643,
63,
1418,
8,
277,
12,
536,
12,
7373,
12,
4592,
304,
267,
1526,
275,
8767,
8,
5553,
29,
5553,
12,
536,
29,
354,
12,
4592,
29,
3185,
9,
267,
372,
1526,
339,
347,
5534,
63,
3756,
8,
277,
12,
1011,
958,
304,
267,
4719,
275,
16269,
68,
7422,
3682,
958,
9,
267,
372,
4719,
199,
199,
10329,
63,
4620,
275,
4384,
51,
8447,
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
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
2197,
199,
504,
333,
3459,
14,
1018,
492,
3523,
8447,
199,
504,
333,
3459,
14,
1018,
14,
1208,
492,
11601,
63,
15363,
63,
2083,
63,
1045,
63,
19579,
4515,
421,
199,
533,
8767,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
7373,
12,
536,
29,
403,
12,
4592,
29,
403,
304,
267,
3063,
275,
2197,
14,
2083,
14,
2131,
342,
267,
291,
14,
15469,
275,
3063,
435,
2197,
14,
7473,
8,
4515,
29,
5553,
9,
267,
291,
14,
354,
275,
536,
267,
291,
14,
3185,
275,
488,
339,
768,
1829,
272,
347,
15399,
63,
7336,
15363,
8,
277,
304,
267,
372,
11601,
63,
15363,
63,
2083,
63,
1045,
63,
19579,
4515,
8,
277,
14,
15469,
9,
421,
199,
533,
16269,
68,
7422,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
4719,
63,
1730,
63,
354,
12,
4719,
63,
1060,
12,
4592,
12,
7373,
12,
5957,
63,
344,
304,
267,
291,
14,
1730,
63,
354,
275,
4719,
63,
1730,
63,
354,
267,
291,
14,
1060,
275,
4719,
63,
1060,
267,
291,
14,
3185,
275,
4592,
267,
3063,
275,
2197,
14,
2083,
14,
2131,
342,
267,
291,
14,
15469,
275,
3063,
435,
2197,
14,
7473,
8,
4515,
29,
5553,
9,
267,
291,
14,
5159,
63,
344,
275,
5957,
63,
344,
339,
768,
1829,
272,
347,
15399,
63,
7336,
15363,
8,
277,
304,
267,
372,
11601,
63,
15363,
63,
2083,
63,
1045,
63,
19579,
4515,
8,
277,
14,
15469,
9,
421,
199,
533,
4384,
51,
8447,
8,
1563,
8447,
304,
272,
347,
664,
63,
1730,
63,
1418,
8,
277,
12,
7373,
304,
267,
1526,
275,
8767,
8,
5553,
29,
5553,
9,
267,
372,
1526,
339,
347,
664,
63,
771,
32643,
63,
1418,
8,
277,
12,
536,
12,
7373,
12,
4592,
304,
267,
1526,
275,
8767,
8,
5553,
29,
5553,
12,
536,
29,
354,
12,
4592,
29,
3185,
9,
267,
372,
1526,
339,
347,
5534,
63,
3756,
8,
277,
12,
1011,
958,
304,
267,
4719,
275,
16269,
68,
7422,
3682,
958,
9,
267,
372,
4719,
199,
199,
10329,
63,
4620,
275,
4384,
51,
8447,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
robhudson/django
|
tests/generic_relations/tests.py
|
45
|
28522
|
from __future__ import unicode_literals
from django import forms
from django.contrib.contenttypes.forms import generic_inlineformset_factory
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import FieldError
from django.db import IntegrityError
from django.db.models import Q
from django.test import SimpleTestCase, TestCase
from django.utils import six
from .models import (
AllowsNullGFK, Animal, Comparison, ConcreteRelatedModel,
ForConcreteModelModel, ForProxyModelModel, Gecko, ManualPK, Mineral,
ProxyRelatedModel, Rock, TaggedItem, ValuableTaggedItem, Vegetable,
)
class GenericRelationsTests(TestCase):
def setUp(self):
self.lion = Animal.objects.create(
common_name="Lion", latin_name="Panthera leo")
self.platypus = Animal.objects.create(
common_name="Platypus", latin_name="Ornithorhynchus anatinus")
Vegetable.objects.create(name="Eggplant", is_yucky=True)
self.bacon = Vegetable.objects.create(name="Bacon", is_yucky=False)
self.quartz = Mineral.objects.create(name="Quartz", hardness=7)
# Tagging stuff.
self.bacon.tags.create(tag="fatty")
self.bacon.tags.create(tag="salty")
self.lion.tags.create(tag="yellow")
self.lion.tags.create(tag="hairy")
# Original list of tags:
self.comp_func = lambda obj: (
obj.tag, obj.content_type.model_class(), obj.object_id
)
def test_generic_update_or_create_when_created(self):
"""
Should be able to use update_or_create from the generic related manager
to create a tag. Refs #23611.
"""
count = self.bacon.tags.count()
tag, created = self.bacon.tags.update_or_create(tag='stinky')
self.assertTrue(created)
self.assertEqual(count + 1, self.bacon.tags.count())
def test_generic_update_or_create_when_updated(self):
"""
Should be able to use update_or_create from the generic related manager
to update a tag. Refs #23611.
"""
count = self.bacon.tags.count()
tag = self.bacon.tags.create(tag='stinky')
self.assertEqual(count + 1, self.bacon.tags.count())
tag, created = self.bacon.tags.update_or_create(defaults={'tag': 'juicy'}, id=tag.id)
self.assertFalse(created)
self.assertEqual(count + 1, self.bacon.tags.count())
self.assertEqual(tag.tag, 'juicy')
def test_generic_get_or_create_when_created(self):
"""
Should be able to use get_or_create from the generic related manager
to create a tag. Refs #23611.
"""
count = self.bacon.tags.count()
tag, created = self.bacon.tags.get_or_create(tag='stinky')
self.assertTrue(created)
self.assertEqual(count + 1, self.bacon.tags.count())
def test_generic_get_or_create_when_exists(self):
"""
Should be able to use get_or_create from the generic related manager
to get a tag. Refs #23611.
"""
count = self.bacon.tags.count()
tag = self.bacon.tags.create(tag="stinky")
self.assertEqual(count + 1, self.bacon.tags.count())
tag, created = self.bacon.tags.get_or_create(id=tag.id, defaults={'tag': 'juicy'})
self.assertFalse(created)
self.assertEqual(count + 1, self.bacon.tags.count())
# shouldn't had changed the tag
self.assertEqual(tag.tag, 'stinky')
def test_generic_relations_m2m_mimic(self):
"""
Objects with declared GenericRelations can be tagged directly -- the
API mimics the many-to-many API.
"""
self.assertQuerysetEqual(self.lion.tags.all(), [
"<TaggedItem: hairy>",
"<TaggedItem: yellow>"
])
self.assertQuerysetEqual(self.bacon.tags.all(), [
"<TaggedItem: fatty>",
"<TaggedItem: salty>"
])
def test_access_content_object(self):
"""
Test accessing the content object like a foreign key.
"""
tagged_item = TaggedItem.objects.get(tag="salty")
self.assertEqual(tagged_item.content_object, self.bacon)
def test_query_content_object(self):
qs = TaggedItem.objects.filter(
animal__isnull=False).order_by('animal__common_name', 'tag')
self.assertQuerysetEqual(
qs, ["<TaggedItem: hairy>", "<TaggedItem: yellow>"]
)
mpk = ManualPK.objects.create(id=1)
mpk.tags.create(tag='mpk')
qs = TaggedItem.objects.filter(
Q(animal__isnull=False) | Q(manualpk__id=1)).order_by('tag')
self.assertQuerysetEqual(
qs, ["hairy", "mpk", "yellow"], lambda x: x.tag)
def test_exclude_generic_relations(self):
"""
Test lookups over an object without GenericRelations.
"""
# Recall that the Mineral class doesn't have an explicit GenericRelation
# defined. That's OK, because you can create TaggedItems explicitly.
# However, excluding GenericRelations means your lookups have to be a
# bit more explicit.
TaggedItem.objects.create(content_object=self.quartz, tag="shiny")
TaggedItem.objects.create(content_object=self.quartz, tag="clearish")
ctype = ContentType.objects.get_for_model(self.quartz)
q = TaggedItem.objects.filter(
content_type__pk=ctype.id, object_id=self.quartz.id
)
self.assertQuerysetEqual(q, [
"<TaggedItem: clearish>",
"<TaggedItem: shiny>"
])
def test_access_via_content_type(self):
"""
Test lookups through content type.
"""
self.lion.delete()
self.platypus.tags.create(tag="fatty")
ctype = ContentType.objects.get_for_model(self.platypus)
self.assertQuerysetEqual(
Animal.objects.filter(tags__content_type=ctype),
["<Animal: Platypus>"])
def test_set_foreign_key(self):
"""
You can set a generic foreign key in the way you'd expect.
"""
tag1 = TaggedItem.objects.create(content_object=self.quartz, tag="shiny")
tag1.content_object = self.platypus
tag1.save()
self.assertQuerysetEqual(
self.platypus.tags.all(),
["<TaggedItem: shiny>"])
def test_queries_across_generic_relations(self):
"""
Queries across generic relations respect the content types. Even though
there are two TaggedItems with a tag of "fatty", this query only pulls
out the one with the content type related to Animals.
"""
self.assertQuerysetEqual(Animal.objects.order_by('common_name'), [
"<Animal: Lion>",
"<Animal: Platypus>"
])
def test_queries_content_type_restriction(self):
"""
Create another fatty tagged instance with different PK to ensure there
is a content type restriction in the generated queries below.
"""
mpk = ManualPK.objects.create(id=self.lion.pk)
mpk.tags.create(tag="fatty")
self.platypus.tags.create(tag="fatty")
self.assertQuerysetEqual(
Animal.objects.filter(tags__tag='fatty'), ["<Animal: Platypus>"])
self.assertQuerysetEqual(
Animal.objects.exclude(tags__tag='fatty'), ["<Animal: Lion>"])
def test_object_deletion_with_generic_relation(self):
"""
If you delete an object with an explicit Generic relation, the related
objects are deleted when the source object is deleted.
"""
self.assertQuerysetEqual(TaggedItem.objects.all(), [
('fatty', Vegetable, self.bacon.pk),
('hairy', Animal, self.lion.pk),
('salty', Vegetable, self.bacon.pk),
('yellow', Animal, self.lion.pk)
],
self.comp_func
)
self.lion.delete()
self.assertQuerysetEqual(TaggedItem.objects.all(), [
('fatty', Vegetable, self.bacon.pk),
('salty', Vegetable, self.bacon.pk),
],
self.comp_func
)
def test_object_deletion_without_generic_relation(self):
"""
If Generic Relation is not explicitly defined, any related objects
remain after deletion of the source object.
"""
TaggedItem.objects.create(content_object=self.quartz, tag="clearish")
quartz_pk = self.quartz.pk
self.quartz.delete()
self.assertQuerysetEqual(TaggedItem.objects.all(), [
('clearish', Mineral, quartz_pk),
('fatty', Vegetable, self.bacon.pk),
('hairy', Animal, self.lion.pk),
('salty', Vegetable, self.bacon.pk),
('yellow', Animal, self.lion.pk),
],
self.comp_func
)
def test_tag_deletion_related_objects_unaffected(self):
"""
If you delete a tag, the objects using the tag are unaffected (other
than losing a tag).
"""
ctype = ContentType.objects.get_for_model(self.lion)
tag = TaggedItem.objects.get(
content_type__pk=ctype.id, object_id=self.lion.id, tag="hairy")
tag.delete()
self.assertQuerysetEqual(self.lion.tags.all(), ["<TaggedItem: yellow>"])
self.assertQuerysetEqual(TaggedItem.objects.all(), [
('fatty', Vegetable, self.bacon.pk),
('salty', Vegetable, self.bacon.pk),
('yellow', Animal, self.lion.pk)
],
self.comp_func
)
def test_add_bulk(self):
bacon = Vegetable.objects.create(name="Bacon", is_yucky=False)
t1 = TaggedItem.objects.create(content_object=self.quartz, tag="shiny")
t2 = TaggedItem.objects.create(content_object=self.quartz, tag="clearish")
# One update() query.
with self.assertNumQueries(1):
bacon.tags.add(t1, t2)
self.assertEqual(t1.content_object, bacon)
self.assertEqual(t2.content_object, bacon)
def test_add_bulk_false(self):
bacon = Vegetable.objects.create(name="Bacon", is_yucky=False)
t1 = TaggedItem.objects.create(content_object=self.quartz, tag="shiny")
t2 = TaggedItem.objects.create(content_object=self.quartz, tag="clearish")
# One save() for each object.
with self.assertNumQueries(2):
bacon.tags.add(t1, t2, bulk=False)
self.assertEqual(t1.content_object, bacon)
self.assertEqual(t2.content_object, bacon)
def test_add_rejects_unsaved_objects(self):
t1 = TaggedItem(content_object=self.quartz, tag="shiny")
msg = "<TaggedItem: shiny> instance isn't saved. Use bulk=False or save the object first."
with self.assertRaisesMessage(ValueError, msg):
self.bacon.tags.add(t1)
def test_set(self):
bacon = Vegetable.objects.create(name="Bacon", is_yucky=False)
fatty = bacon.tags.create(tag="fatty")
salty = bacon.tags.create(tag="salty")
bacon.tags.set([fatty, salty])
self.assertQuerysetEqual(bacon.tags.all(), [
"<TaggedItem: fatty>",
"<TaggedItem: salty>",
])
bacon.tags.set([fatty])
self.assertQuerysetEqual(bacon.tags.all(), [
"<TaggedItem: fatty>",
])
bacon.tags.set([])
self.assertQuerysetEqual(bacon.tags.all(), [])
bacon.tags.set([fatty, salty], bulk=False, clear=True)
self.assertQuerysetEqual(bacon.tags.all(), [
"<TaggedItem: fatty>",
"<TaggedItem: salty>",
])
bacon.tags.set([fatty], bulk=False, clear=True)
self.assertQuerysetEqual(bacon.tags.all(), [
"<TaggedItem: fatty>",
])
bacon.tags.set([], clear=True)
self.assertQuerysetEqual(bacon.tags.all(), [])
def test_assign(self):
bacon = Vegetable.objects.create(name="Bacon", is_yucky=False)
fatty = bacon.tags.create(tag="fatty")
salty = bacon.tags.create(tag="salty")
bacon.tags = [fatty, salty]
self.assertQuerysetEqual(bacon.tags.all(), [
"<TaggedItem: fatty>",
"<TaggedItem: salty>",
])
bacon.tags = [fatty]
self.assertQuerysetEqual(bacon.tags.all(), [
"<TaggedItem: fatty>",
])
bacon.tags = []
self.assertQuerysetEqual(bacon.tags.all(), [])
def test_assign_with_queryset(self):
# Ensure that querysets used in reverse GFK assignments are pre-evaluated
# so their value isn't affected by the clearing operation in
# ManyToManyDescriptor.__set__. Refs #19816.
bacon = Vegetable.objects.create(name="Bacon", is_yucky=False)
bacon.tags.create(tag="fatty")
bacon.tags.create(tag="salty")
self.assertEqual(2, bacon.tags.count())
qs = bacon.tags.filter(tag="fatty")
bacon.tags = qs
self.assertEqual(1, bacon.tags.count())
self.assertEqual(1, qs.count())
def test_generic_relation_related_name_default(self):
# Test that GenericRelation by default isn't usable from
# the reverse side.
with self.assertRaises(FieldError):
TaggedItem.objects.filter(vegetable__isnull=True)
def test_multiple_gfk(self):
# Simple tests for multiple GenericForeignKeys
# only uses one model, since the above tests should be sufficient.
tiger = Animal.objects.create(common_name="tiger")
cheetah = Animal.objects.create(common_name="cheetah")
bear = Animal.objects.create(common_name="bear")
# Create directly
Comparison.objects.create(
first_obj=cheetah, other_obj=tiger, comparative="faster"
)
Comparison.objects.create(
first_obj=tiger, other_obj=cheetah, comparative="cooler"
)
# Create using GenericRelation
tiger.comparisons.create(other_obj=bear, comparative="cooler")
tiger.comparisons.create(other_obj=cheetah, comparative="stronger")
self.assertQuerysetEqual(cheetah.comparisons.all(), [
"<Comparison: cheetah is faster than tiger>"
])
# Filtering works
self.assertQuerysetEqual(tiger.comparisons.filter(comparative="cooler"), [
"<Comparison: tiger is cooler than cheetah>",
"<Comparison: tiger is cooler than bear>",
], ordered=False)
# Filtering and deleting works
subjective = ["cooler"]
tiger.comparisons.filter(comparative__in=subjective).delete()
self.assertQuerysetEqual(Comparison.objects.all(), [
"<Comparison: cheetah is faster than tiger>",
"<Comparison: tiger is stronger than cheetah>"
], ordered=False)
# If we delete cheetah, Comparisons with cheetah as 'first_obj' will be
# deleted since Animal has an explicit GenericRelation to Comparison
# through first_obj. Comparisons with cheetah as 'other_obj' will not
# be deleted.
cheetah.delete()
self.assertQuerysetEqual(Comparison.objects.all(), [
"<Comparison: tiger is stronger than None>"
])
def test_gfk_subclasses(self):
# GenericForeignKey should work with subclasses (see #8309)
quartz = Mineral.objects.create(name="Quartz", hardness=7)
valuedtag = ValuableTaggedItem.objects.create(
content_object=quartz, tag="shiny", value=10
)
self.assertEqual(valuedtag.content_object, quartz)
def test_generic_inline_formsets(self):
GenericFormSet = generic_inlineformset_factory(TaggedItem, extra=1)
formset = GenericFormSet()
self.assertHTMLEqual(
''.join(form.as_p() for form in formset.forms),
"""<p><label for="id_generic_relations-taggeditem-content_type-object_id-0-tag">
Tag:</label> <input id="id_generic_relations-taggeditem-content_type-object_id-0-tag" type="text"
name="generic_relations-taggeditem-content_type-object_id-0-tag" maxlength="50" /></p>
<p><label for="id_generic_relations-taggeditem-content_type-object_id-0-DELETE">Delete:</label>
<input type="checkbox" name="generic_relations-taggeditem-content_type-object_id-0-DELETE"
id="id_generic_relations-taggeditem-content_type-object_id-0-DELETE" />
<input type="hidden" name="generic_relations-taggeditem-content_type-object_id-0-id"
id="id_generic_relations-taggeditem-content_type-object_id-0-id" /></p>"""
)
formset = GenericFormSet(instance=Animal())
self.assertHTMLEqual(
''.join(form.as_p() for form in formset.forms),
"""<p><label for="id_generic_relations-taggeditem-content_type-object_id-0-tag">
Tag:</label> <input id="id_generic_relations-taggeditem-content_type-object_id-0-tag"
type="text" name="generic_relations-taggeditem-content_type-object_id-0-tag" maxlength="50" /></p>
<p><label for="id_generic_relations-taggeditem-content_type-object_id-0-DELETE">Delete:</label>
<input type="checkbox" name="generic_relations-taggeditem-content_type-object_id-0-DELETE"
id="id_generic_relations-taggeditem-content_type-object_id-0-DELETE" /><input type="hidden"
name="generic_relations-taggeditem-content_type-object_id-0-id"
id="id_generic_relations-taggeditem-content_type-object_id-0-id" /></p>"""
)
platypus = Animal.objects.create(
common_name="Platypus", latin_name="Ornithorhynchus anatinus"
)
platypus.tags.create(tag="shiny")
GenericFormSet = generic_inlineformset_factory(TaggedItem, extra=1)
formset = GenericFormSet(instance=platypus)
tagged_item_id = TaggedItem.objects.get(
tag='shiny', object_id=platypus.id
).id
self.assertHTMLEqual(
''.join(form.as_p() for form in formset.forms),
"""<p><label for="id_generic_relations-taggeditem-content_type-object_id-0-tag">Tag:</label>
<input id="id_generic_relations-taggeditem-content_type-object_id-0-tag" type="text"
name="generic_relations-taggeditem-content_type-object_id-0-tag" value="shiny" maxlength="50" /></p>
<p><label for="id_generic_relations-taggeditem-content_type-object_id-0-DELETE">Delete:</label>
<input type="checkbox" name="generic_relations-taggeditem-content_type-object_id-0-DELETE"
id="id_generic_relations-taggeditem-content_type-object_id-0-DELETE" />
<input type="hidden" name="generic_relations-taggeditem-content_type-object_id-0-id"
value="%s" id="id_generic_relations-taggeditem-content_type-object_id-0-id" /></p>
<p><label for="id_generic_relations-taggeditem-content_type-object_id-1-tag">Tag:</label>
<input id="id_generic_relations-taggeditem-content_type-object_id-1-tag" type="text"
name="generic_relations-taggeditem-content_type-object_id-1-tag" maxlength="50" /></p>
<p><label for="id_generic_relations-taggeditem-content_type-object_id-1-DELETE">Delete:</label>
<input type="checkbox" name="generic_relations-taggeditem-content_type-object_id-1-DELETE"
id="id_generic_relations-taggeditem-content_type-object_id-1-DELETE" />
<input type="hidden" name="generic_relations-taggeditem-content_type-object_id-1-id"
id="id_generic_relations-taggeditem-content_type-object_id-1-id" /></p>""" % tagged_item_id
)
lion = Animal.objects.create(common_name="Lion", latin_name="Panthera leo")
formset = GenericFormSet(instance=lion, prefix='x')
self.assertHTMLEqual(
''.join(form.as_p() for form in formset.forms),
"""<p><label for="id_x-0-tag">Tag:</label>
<input id="id_x-0-tag" type="text" name="x-0-tag" maxlength="50" /></p>
<p><label for="id_x-0-DELETE">Delete:</label> <input type="checkbox" name="x-0-DELETE" id="id_x-0-DELETE" />
<input type="hidden" name="x-0-id" id="id_x-0-id" /></p>"""
)
def test_gfk_manager(self):
# GenericForeignKey should not use the default manager (which may filter objects) #16048
tailless = Gecko.objects.create(has_tail=False)
tag = TaggedItem.objects.create(content_object=tailless, tag="lizard")
self.assertEqual(tag.content_object, tailless)
def test_subclasses_with_gen_rel(self):
"""
Test that concrete model subclasses with generic relations work
correctly (ticket 11263).
"""
granite = Rock.objects.create(name='granite', hardness=5)
TaggedItem.objects.create(content_object=granite, tag="countertop")
self.assertEqual(Rock.objects.filter(tags__tag="countertop").count(), 1)
def test_generic_inline_formsets_initial(self):
"""
Test for #17927 Initial values support for BaseGenericInlineFormSet.
"""
quartz = Mineral.objects.create(name="Quartz", hardness=7)
GenericFormSet = generic_inlineformset_factory(TaggedItem, extra=1)
ctype = ContentType.objects.get_for_model(quartz)
initial_data = [{
'tag': 'lizard',
'content_type': ctype.pk,
'object_id': quartz.pk,
}]
formset = GenericFormSet(initial=initial_data)
self.assertEqual(formset.forms[0].initial, initial_data[0])
def test_get_or_create(self):
# get_or_create should work with virtual fields (content_object)
quartz = Mineral.objects.create(name="Quartz", hardness=7)
tag, created = TaggedItem.objects.get_or_create(tag="shiny",
defaults={'content_object': quartz})
self.assertTrue(created)
self.assertEqual(tag.tag, "shiny")
self.assertEqual(tag.content_object.id, quartz.id)
def test_update_or_create_defaults(self):
# update_or_create should work with virtual fields (content_object)
quartz = Mineral.objects.create(name="Quartz", hardness=7)
diamond = Mineral.objects.create(name="Diamond", hardness=7)
tag, created = TaggedItem.objects.update_or_create(tag="shiny",
defaults={'content_object': quartz})
self.assertTrue(created)
self.assertEqual(tag.content_object.id, quartz.id)
tag, created = TaggedItem.objects.update_or_create(tag="shiny",
defaults={'content_object': diamond})
self.assertFalse(created)
self.assertEqual(tag.content_object.id, diamond.id)
def test_query_content_type(self):
msg = "Field 'content_object' does not generate an automatic reverse relation"
with self.assertRaisesMessage(FieldError, msg):
TaggedItem.objects.get(content_object='')
def test_unsaved_instance_on_generic_foreign_key(self):
"""
Assigning an unsaved object to GenericForeignKey should raise an
exception on model.save().
"""
quartz = Mineral(name="Quartz", hardness=7)
with self.assertRaises(IntegrityError):
TaggedItem.objects.create(tag="shiny", content_object=quartz)
class CustomWidget(forms.TextInput):
pass
class TaggedItemForm(forms.ModelForm):
class Meta:
model = TaggedItem
fields = '__all__'
widgets = {'tag': CustomWidget}
class GenericInlineFormsetTest(TestCase):
def test_generic_inlineformset_factory(self):
"""
Regression for #14572: Using base forms with widgets
defined in Meta should not raise errors.
"""
Formset = generic_inlineformset_factory(TaggedItem, TaggedItemForm)
form = Formset().forms[0]
self.assertIsInstance(form['tag'].field.widget, CustomWidget)
def test_save_new_uses_form_save(self):
"""
Regression for #16260: save_new should call form.save()
"""
class SaveTestForm(forms.ModelForm):
def save(self, *args, **kwargs):
self.instance.saved_by = "custom method"
return super(SaveTestForm, self).save(*args, **kwargs)
Formset = generic_inlineformset_factory(
ForProxyModelModel, fields='__all__', form=SaveTestForm)
instance = ProxyRelatedModel.objects.create()
data = {
'form-TOTAL_FORMS': '1',
'form-INITIAL_FORMS': '0',
'form-MAX_NUM_FORMS': '',
'form-0-title': 'foo',
}
formset = Formset(data, instance=instance, prefix='form')
self.assertTrue(formset.is_valid())
new_obj = formset.save()[0]
self.assertEqual(new_obj.saved_by, "custom method")
def test_save_new_for_proxy(self):
Formset = generic_inlineformset_factory(ForProxyModelModel,
fields='__all__', for_concrete_model=False)
instance = ProxyRelatedModel.objects.create()
data = {
'form-TOTAL_FORMS': '1',
'form-INITIAL_FORMS': '0',
'form-MAX_NUM_FORMS': '',
'form-0-title': 'foo',
}
formset = Formset(data, instance=instance, prefix='form')
self.assertTrue(formset.is_valid())
new_obj, = formset.save()
self.assertEqual(new_obj.obj, instance)
def test_save_new_for_concrete(self):
Formset = generic_inlineformset_factory(ForProxyModelModel,
fields='__all__', for_concrete_model=True)
instance = ProxyRelatedModel.objects.create()
data = {
'form-TOTAL_FORMS': '1',
'form-INITIAL_FORMS': '0',
'form-MAX_NUM_FORMS': '',
'form-0-title': 'foo',
}
formset = Formset(data, instance=instance, prefix='form')
self.assertTrue(formset.is_valid())
new_obj, = formset.save()
self.assertNotIsInstance(new_obj.obj, ProxyRelatedModel)
class ProxyRelatedModelTest(TestCase):
def test_default_behavior(self):
"""
The default for for_concrete_model should be True
"""
base = ForConcreteModelModel()
base.obj = rel = ProxyRelatedModel.objects.create()
base.save()
base = ForConcreteModelModel.objects.get(pk=base.pk)
rel = ConcreteRelatedModel.objects.get(pk=rel.pk)
self.assertEqual(base.obj, rel)
def test_works_normally(self):
"""
When for_concrete_model is False, we should still be able to get
an instance of the concrete class.
"""
base = ForProxyModelModel()
base.obj = rel = ConcreteRelatedModel.objects.create()
base.save()
base = ForProxyModelModel.objects.get(pk=base.pk)
self.assertEqual(base.obj, rel)
def test_proxy_is_returned(self):
"""
Instances of the proxy should be returned when
for_concrete_model is False.
"""
base = ForProxyModelModel()
base.obj = ProxyRelatedModel.objects.create()
base.save()
base = ForProxyModelModel.objects.get(pk=base.pk)
self.assertIsInstance(base.obj, ProxyRelatedModel)
def test_query(self):
base = ForProxyModelModel()
base.obj = rel = ConcreteRelatedModel.objects.create()
base.save()
self.assertEqual(rel, ConcreteRelatedModel.objects.get(bases__id=base.id))
def test_query_proxy(self):
base = ForProxyModelModel()
base.obj = rel = ProxyRelatedModel.objects.create()
base.save()
self.assertEqual(rel, ProxyRelatedModel.objects.get(bases__id=base.id))
def test_generic_relation(self):
base = ForProxyModelModel()
base.obj = ProxyRelatedModel.objects.create()
base.save()
base = ForProxyModelModel.objects.get(pk=base.pk)
rel = ProxyRelatedModel.objects.get(pk=base.obj.pk)
self.assertEqual(base, rel.bases.get())
def test_generic_relation_set(self):
base = ForProxyModelModel()
base.obj = ConcreteRelatedModel.objects.create()
base.save()
newrel = ConcreteRelatedModel.objects.create()
newrel.bases = [base]
newrel = ConcreteRelatedModel.objects.get(pk=newrel.pk)
self.assertEqual(base, newrel.bases.get())
class TestInitWithNoneArgument(SimpleTestCase):
def test_none_not_allowed(self):
# TaggedItem requires a content_type, initializing with None should
# raise a ValueError.
with six.assertRaisesRegex(self, ValueError,
'Cannot assign None: "TaggedItem.content_type" does not allow null values'):
TaggedItem(content_object=None)
def test_none_allowed(self):
# AllowsNullGFK doesn't require a content_type, so None argument should
# also be allowed.
AllowsNullGFK(content_object=None)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
492,
4513,
199,
504,
1639,
14,
2828,
14,
10778,
14,
3351,
492,
7809,
63,
6460,
10724,
63,
3702,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
504,
1639,
14,
1018,
14,
3924,
492,
27691,
199,
504,
1639,
14,
697,
492,
26864,
199,
504,
1639,
14,
697,
14,
992,
492,
1413,
199,
504,
1639,
14,
396,
492,
24424,
12,
7640,
199,
504,
1639,
14,
1208,
492,
3816,
199,
199,
504,
1275,
992,
492,
334,
272,
22819,
8849,
17395,
43,
12,
1626,
7265,
12,
3599,
5447,
12,
1448,
7564,
13885,
1685,
12,
272,
2104,
714,
7564,
1685,
1685,
12,
2104,
4936,
1685,
1685,
12,
30506,
12,
30247,
8884,
12,
10195,
281,
279,
12,
272,
12373,
13885,
1685,
12,
820,
766,
12,
32121,
2081,
12,
26263,
85,
461,
26403,
2081,
12,
25777,
362,
461,
12,
199,
9,
421,
199,
533,
8307,
5640,
1298,
2925,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
29025,
275,
1626,
7265,
14,
1462,
14,
981,
8,
288,
2863,
63,
354,
628,
44,
1636,
401,
16899,
63,
354,
628,
19266,
728,
65,
1026,
79,
531,
267,
291,
14,
14156,
2279,
527,
275,
1626,
7265,
14,
1462,
14,
981,
8,
288,
2863,
63,
354,
628,
3714,
292,
2279,
527,
401,
16899,
63,
354,
628,
2844,
78,
448,
269,
72,
5654,
527,
376,
14667,
527,
531,
267,
25777,
362,
461,
14,
1462,
14,
981,
8,
354,
628,
37,
2721,
31655,
401,
365,
63,
89,
10112,
89,
29,
549,
9,
267,
291,
14,
2470,
388,
275,
25777,
362,
461,
14,
1462,
14,
981,
8,
354,
628,
13864,
388,
401,
365,
63,
89,
10112,
89,
29,
797,
9,
267,
291,
14,
392,
28124,
275,
10195,
281,
279,
14,
1462,
14,
981,
8,
354,
628,
2371,
28124,
401,
7508,
4171,
29,
23,
9,
398,
327,
8053,
1540,
8292,
14,
267,
291,
14,
2470,
388,
14,
2969,
14,
981,
8,
1450,
628,
70,
16623,
531,
267,
291,
14,
2470,
388,
14,
2969,
14,
981,
8,
1450,
628,
6327,
369,
531,
267,
291,
14,
29025,
14,
2969,
14,
981,
8,
1450,
628,
14514,
531,
267,
291,
14,
29025,
14,
2969,
14,
981,
8,
1450,
628,
17945,
651,
531,
398,
327,
12769,
769,
402,
3762,
26,
267,
291,
14,
863,
63,
1532,
275,
2400,
1559,
26,
334,
288,
1559,
14,
1450,
12,
1559,
14,
1317,
63,
466,
14,
1238,
63,
533,
1062,
1559,
14,
785,
63,
344,
267,
776,
339,
347,
511,
63,
6767,
63,
873,
63,
269,
63,
981,
63,
6526,
63,
3966,
8,
277,
304,
267,
408,
267,
7719,
506,
7688,
370,
675,
1678,
63,
269,
63,
981,
687,
314,
7809,
4048,
5256,
267,
370,
1218,
282,
1947,
14,
22165,
327,
10008,
845,
14,
267,
408,
267,
2338,
275,
291,
14,
2470,
388,
14,
2969,
14,
835,
342,
267,
1947,
12,
2737,
275,
291,
14,
2470,
388,
14,
2969,
14,
873,
63,
269,
63,
981,
8,
1450,
534,
270,
2292,
89,
358,
267,
291,
14,
1815,
8,
3966,
9,
267,
291,
14,
629,
8,
835,
435,
413,
12,
291,
14,
2470,
388,
14,
2969,
14,
835,
1012,
339,
347,
511,
63,
6767,
63,
873,
63,
269,
63,
981,
63,
6526,
63,
5334,
8,
277,
304,
267,
408,
267,
7719,
506,
7688,
370,
675,
1678,
63,
269,
63,
981,
687,
314,
7809,
4048,
5256,
267,
370,
1678,
282,
1947,
14,
22165,
327,
10008,
845,
14,
267,
408,
267,
2338,
275,
291,
14,
2470,
388,
14,
2969,
14,
835,
342,
267,
1947,
275,
291,
14,
2470,
388,
14,
2969,
14,
981,
8,
1450,
534,
270,
2292,
89,
358,
267,
291,
14,
629,
8,
835,
435,
413,
12,
291,
14,
2470,
388,
14,
2969,
14,
835,
1012,
267,
1947,
12,
2737,
275,
291,
14,
2470,
388,
14,
2969,
14,
873,
63,
269,
63,
981,
8,
4322,
3713,
1450,
356,
283,
27764,
530,
89,
2267,
1305,
29,
1450,
14,
344,
9,
267,
291,
14,
3334,
8,
3966,
9,
267,
291,
14,
629,
8,
835,
435,
413,
12,
291,
14,
2470,
388,
14,
2969,
14,
835,
1012,
267,
291,
14,
629,
8,
1450,
14,
1450,
12,
283,
27764,
530,
89,
358,
339,
347,
511,
63,
6767,
63,
362,
63,
269,
63,
981,
63,
6526,
63,
3966,
8,
277,
304,
267,
408,
267,
7719,
506,
7688,
370,
675,
664,
63,
269,
63,
981,
687,
314,
7809,
4048,
5256,
267,
370,
1218,
282,
1947,
14,
22165,
327,
10008,
845,
14,
267,
408,
267,
2338,
275,
291,
14,
2470,
388,
14,
2969,
14,
835,
342,
267,
1947,
12,
2737,
275,
291,
14,
2470,
388,
14,
2969,
14,
362,
63,
269,
63,
981,
8,
1450,
534,
270,
2292,
89,
358,
267,
291,
14,
1815,
8,
3966,
9,
267,
291,
14,
629,
8,
835,
435,
413,
12,
291,
14,
2470,
388,
14,
2969,
14,
835,
1012,
339,
347,
511,
63,
6767,
63,
362,
63,
269,
63,
981,
63,
6526,
63,
2444,
8,
277,
304,
267,
408,
267,
7719,
506,
7688,
370,
675,
664,
63,
269,
63,
981,
687,
314,
7809,
4048,
5256,
267,
370,
664,
282,
1947,
14,
22165,
327,
10008,
845,
14,
267,
408,
267,
2338,
275,
291,
14,
2470,
388,
14,
2969,
14,
835,
342,
267,
1947,
275,
291,
14,
2470,
388,
14,
2969,
14,
981,
8,
1450,
628,
270,
2292,
89,
531,
267,
291,
14,
629,
8,
835,
435,
413,
12,
291,
14,
2470,
388,
14,
2969,
14,
835,
1012,
267,
1947,
12,
2737,
275,
291,
14,
2470,
388,
14,
2969,
14,
362,
63,
269,
63,
981,
8,
344,
29,
1450,
14,
344,
12,
4243,
3713,
1450,
356,
283,
27764,
530,
89,
3071,
267,
291,
14,
3334,
8,
3966,
9,
267,
291,
14,
629,
8,
835,
435,
413,
12,
291,
14,
2470,
388,
14,
2969,
14,
835,
1012,
267,
327,
9296,
1133,
10530,
2896,
314,
1947,
267,
291,
14,
629,
8,
1450,
14,
1450,
12,
283,
270,
2292,
89,
358,
339,
347,
511,
63,
6767,
63,
15741,
63,
77,
18,
77,
63,
77,
1017,
530,
8,
277,
304,
267,
408,
267,
26794,
543,
14290,
8307,
5640,
1298,
883,
506,
20018,
5370,
1553,
314,
267,
3261,
24102,
2932,
314,
5002,
13,
475,
13,
3479,
3261,
14,
267
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
492,
4513,
199,
504,
1639,
14,
2828,
14,
10778,
14,
3351,
492,
7809,
63,
6460,
10724,
63,
3702,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
504,
1639,
14,
1018,
14,
3924,
492,
27691,
199,
504,
1639,
14,
697,
492,
26864,
199,
504,
1639,
14,
697,
14,
992,
492,
1413,
199,
504,
1639,
14,
396,
492,
24424,
12,
7640,
199,
504,
1639,
14,
1208,
492,
3816,
199,
199,
504,
1275,
992,
492,
334,
272,
22819,
8849,
17395,
43,
12,
1626,
7265,
12,
3599,
5447,
12,
1448,
7564,
13885,
1685,
12,
272,
2104,
714,
7564,
1685,
1685,
12,
2104,
4936,
1685,
1685,
12,
30506,
12,
30247,
8884,
12,
10195,
281,
279,
12,
272,
12373,
13885,
1685,
12,
820,
766,
12,
32121,
2081,
12,
26263,
85,
461,
26403,
2081,
12,
25777,
362,
461,
12,
199,
9,
421,
199,
533,
8307,
5640,
1298,
2925,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
29025,
275,
1626,
7265,
14,
1462,
14,
981,
8,
288,
2863,
63,
354,
628,
44,
1636,
401,
16899,
63,
354,
628,
19266,
728,
65,
1026,
79,
531,
267,
291,
14,
14156,
2279,
527,
275,
1626,
7265,
14,
1462,
14,
981,
8,
288,
2863,
63,
354,
628,
3714,
292,
2279,
527,
401,
16899,
63,
354,
628,
2844,
78,
448,
269,
72,
5654,
527,
376,
14667,
527,
531,
267,
25777,
362,
461,
14,
1462,
14,
981,
8,
354,
628,
37,
2721,
31655,
401,
365,
63,
89,
10112,
89,
29,
549,
9,
267,
291,
14,
2470,
388,
275,
25777,
362,
461,
14,
1462,
14,
981,
8,
354,
628,
13864,
388,
401,
365,
63,
89,
10112,
89,
29,
797,
9,
267,
291,
14,
392,
28124,
275,
10195,
281,
279,
14,
1462,
14,
981,
8,
354,
628,
2371,
28124,
401,
7508,
4171,
29,
23,
9,
398,
327,
8053,
1540,
8292,
14,
267,
291,
14,
2470,
388,
14,
2969,
14,
981,
8,
1450,
628,
70,
16623,
531,
267,
291,
14,
2470,
388,
14,
2969,
14,
981,
8,
1450,
628,
6327,
369,
531,
267,
291,
14,
29025,
14,
2969,
14,
981,
8,
1450,
628,
14514,
531,
267,
291,
14,
29025,
14,
2969,
14,
981,
8,
1450,
628,
17945,
651,
531,
398,
327,
12769,
769,
402,
3762,
26,
267,
291,
14,
863,
63,
1532,
275,
2400,
1559,
26,
334,
288,
1559,
14,
1450,
12,
1559,
14,
1317,
63,
466,
14,
1238,
63,
533,
1062,
1559,
14,
785,
63,
344,
267,
776,
339,
347,
511,
63,
6767,
63,
873,
63,
269,
63,
981,
63,
6526,
63,
3966,
8,
277,
304,
267,
408,
267,
7719,
506,
7688,
370,
675,
1678,
63,
269,
63,
981,
687,
314,
7809,
4048,
5256,
267,
370,
1218,
282,
1947,
14,
22165,
327,
10008,
845,
14,
267,
408,
267,
2338,
275,
291,
14,
2470,
388,
14,
2969,
14,
835,
342,
267,
1947,
12,
2737,
275,
291,
14,
2470,
388,
14,
2969,
14,
873,
63,
269,
63,
981,
8,
1450,
534,
270,
2292,
89,
358,
267,
291,
14,
1815,
8,
3966,
9,
267,
291,
14,
629,
8,
835,
435,
413,
12,
291,
14,
2470,
388,
14,
2969,
14,
835,
1012,
339,
347,
511,
63,
6767,
63,
873,
63,
269,
63,
981,
63,
6526,
63,
5334,
8,
277,
304,
267,
408,
267,
7719,
506,
7688,
370,
675,
1678,
63,
269,
63,
981,
687,
314,
7809,
4048,
5256,
267,
370,
1678,
282,
1947,
14,
22165,
327,
10008,
845,
14,
267,
408,
267,
2338,
275,
291,
14,
2470,
388,
14,
2969,
14,
835,
342,
267,
1947,
275,
291,
14,
2470,
388,
14,
2969,
14,
981,
8,
1450,
534,
270,
2292,
89,
358,
267,
291,
14,
629,
8,
835,
435,
413,
12,
291,
14,
2470,
388,
14,
2969,
14,
835,
1012,
267,
1947,
12,
2737,
275,
291,
14,
2470,
388,
14,
2969,
14,
873,
63,
269,
63,
981,
8,
4322,
3713,
1450,
356,
283,
27764,
530,
89,
2267,
1305,
29,
1450,
14,
344,
9,
267,
291,
14,
3334,
8,
3966,
9,
267,
291,
14,
629,
8,
835,
435,
413,
12,
291,
14,
2470,
388,
14,
2969,
14,
835,
1012,
267,
291,
14,
629,
8,
1450,
14,
1450,
12,
283,
27764,
530,
89,
358,
339,
347,
511,
63,
6767,
63,
362,
63,
269,
63,
981,
63,
6526,
63,
3966,
8,
277,
304,
267,
408,
267,
7719,
506,
7688,
370,
675,
664,
63,
269,
63,
981,
687,
314,
7809,
4048,
5256,
267,
370,
1218,
282,
1947,
14,
22165,
327,
10008,
845,
14,
267,
408,
267,
2338,
275,
291,
14,
2470,
388,
14,
2969,
14,
835,
342,
267,
1947,
12,
2737,
275,
291,
14,
2470,
388,
14,
2969,
14,
362,
63,
269,
63,
981,
8,
1450,
534,
270,
2292,
89,
358,
267,
291,
14,
1815,
8,
3966,
9,
267,
291,
14,
629,
8,
835,
435,
413,
12,
291,
14,
2470,
388,
14,
2969,
14,
835,
1012,
339,
347,
511,
63,
6767,
63,
362,
63,
269,
63,
981,
63,
6526,
63,
2444,
8,
277,
304,
267,
408,
267,
7719,
506,
7688,
370,
675,
664,
63,
269,
63,
981,
687,
314,
7809,
4048,
5256,
267,
370,
664,
282,
1947,
14,
22165,
327,
10008,
845,
14,
267,
408,
267,
2338,
275,
291,
14,
2470,
388,
14,
2969,
14,
835,
342,
267,
1947,
275,
291,
14,
2470,
388,
14,
2969,
14,
981,
8,
1450,
628,
270,
2292,
89,
531,
267,
291,
14,
629,
8,
835,
435,
413,
12,
291,
14,
2470,
388,
14,
2969,
14,
835,
1012,
267,
1947,
12,
2737,
275,
291,
14,
2470,
388,
14,
2969,
14,
362,
63,
269,
63,
981,
8,
344,
29,
1450,
14,
344,
12,
4243,
3713,
1450,
356,
283,
27764,
530,
89,
3071,
267,
291,
14,
3334,
8,
3966,
9,
267,
291,
14,
629,
8,
835,
435,
413,
12,
291,
14,
2470,
388,
14,
2969,
14,
835,
1012,
267,
327,
9296,
1133,
10530,
2896,
314,
1947,
267,
291,
14,
629,
8,
1450,
14,
1450,
12,
283,
270,
2292,
89,
358,
339,
347,
511,
63,
6767,
63,
15741,
63,
77,
18,
77,
63,
77,
1017,
530,
8,
277,
304,
267,
408,
267,
26794,
543,
14290,
8307,
5640,
1298,
883,
506,
20018,
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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
] |
linyc74/CaMNIST
|
view.py
|
1
|
12377
|
import numpy as np
import cv2, time, sys, threading, json, os
from PyQt4 import QtCore, QtGui
from controller import *
class CamnistGUI(QtGui.QMainWindow):
def __init__(self, controller_obj):
super(CamnistGUI, self).__init__()
self.controller = controller_obj
pkg_dir = os.path.dirname(__file__)
path = os.path.join(pkg_dir, 'parameters/gui.json')
gui_parms = json.loads(open(path, 'r').read())
w = gui_parms['monitor_width']
h = gui_parms['monitor_height']
self.setWindowTitle('CaMNIST')
self.setWindowIcon(QtGui.QIcon('icons/cool.png'))
self.setGeometry(100, 100, w, h)
self.setFixedSize(w, h)
self.setMouseTracking(True)
self.monitor = QtGui.QLabel(self)
self.monitor.setGeometry(0, 0, w, h)
self.monitor.setAlignment(QtCore.Qt.AlignCenter)
self.toolbar = QtGui.QToolBar('Tool Bar')
self.toolbar.setMovable(True)
self.toolbar.setStyleSheet("QToolBar { background:white; }")
self.toolbar.setIconSize(QtCore.QSize(30, 45))
self.addToolBar(QtCore.Qt.LeftToolBarArea, self.toolbar)
self.info_window = TextWindow()
self.camera_tuner_window = CameraTunerWindow( controller_obj = self.controller )
self.__init__toolbtns()
def __init__toolbtns(self):
# Each action has a unique key and a name
# key = icon filename = method name
# name = text of the action/button
# ( keys , names )
K = [('snapshot' , 'Snapshot' ),
('toggle_recording' , 'Record Video' ),
('open_info' , 'Show Real-time Info' ),
('open_camera_tuner', 'Adjust Camera Parameters' )]
self.actions = {}
self.toolbtns = {}
# Create actions and tool buttons
for key, name in K:
pkg_dir = os.path.dirname(__file__)
path = os.path.join(pkg_dir, 'icons/' + key + '.png')
icon = QtGui.QIcon(path)
self.actions[key] = QtGui.QAction(icon, name, self)
self.toolbtns[key] = self.toolbar.addAction(self.actions[key])
# For actions that needs to be connected to the core object,
K = ['snapshot', 'toggle_recording']
# In this loop I defined a standard way of
# connecting each action to a method in the core object via the controller object.
for key in K:
# Get a argument-less method from the controller object.
# Note that the method_name = key.
method = self.controller.get_method( method_name = key )
# The get_method() returns None
# if a particular method is not found in the core object.
if not method is None:
# Connect the action to the method in the controller object
self.actions[key].triggered.connect(method)
# For actions that needs to be connected to the self gui object,
keys = ['open_info', 'open_camera_tuner']
for key in keys:
try:
method = getattr(self, key)
self.actions[key].triggered.connect(method)
except Exception as exception_inst:
print(exception_inst)
def open_info(self):
if not self.info_window.isVisible():
self.info_window.show()
def open_camera_tuner(self):
self.camera_tuner_window.show()
def wheelEvent(self, event):
if event.delta() > 0:
self.controller.call_method('zoom_in')
else:
self.controller.call_method('zoom_out')
def closeEvent(self, event):
reply = QtGui.QMessageBox.question(self,
'CaMNIST',
'Are you sure you want to quit CaMNIST?',
QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
self.controller.call_method('close')
self.info_window.close()
self.camera_tuner_window.close()
event.accept()
else:
event.ignore()
# Methods for incoming signals
def connect_signals(self, thread, signal_name):
'Called by an external object to connect signals.'
# The suffix '(PyQt_PyObject)' means the argument to be transferred
# could be any type of python objects,
# not limited to Qt objects.
signal = signal_name + '(PyQt_PyObject)'
# The method name to be called upon signal arrival = the signal name
try:
method = getattr(self, signal_name)
self.connect(thread, QtCore.SIGNAL(signal), method)
except Exception as exception_inst:
print("Try to connect PyQt signal '{}'".format(signal_name))
print(exception_inst + '\n')
def progress_update(self, text_value):
self.progress_bar.progress_update(text_value)
def display_image(self, image):
# convert from BGR to RGB for latter QImage
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
height, width, bytesPerComponent = image.shape
bytesPerLine = bytesPerComponent * width
# convert cv2 image to QImage
Q_img = QtGui.QImage(image,
width, height, bytesPerLine,
QtGui.QImage.Format_RGB888)
# Convert QImage to QPixmap
Q_pixmap = QtGui.QPixmap.fromImage(Q_img)
# Set the QLabel to display the QPixmap
self.monitor.setPixmap(Q_pixmap)
def recording_starts(self):
self.actions['toggle_recording'].setIcon(QtGui.QIcon('icons/stop_recording.png'))
self.actions['toggle_recording'].setText('Stop')
def recording_ends(self):
self.actions['toggle_recording'].setIcon(QtGui.QIcon('icons/toggle_recording.png'))
self.actions['toggle_recording'].setText('Record Video')
def set_info_text(self, text):
self.info_window.setText(text)
def display_topography(self, vertices):
self.gl_window.gl_widget.updateObject(vertices)
class SliderWidget(QtGui.QWidget):
'''
This widget wraps a single parameter in the TunerWindow.
Name, value, min, max, interval are stored in this object.
Three gui elements are included to display the information of the parameter:
1) QLabel showing name
2) QLabel showing value
3) QSlider
'''
def __init__(self, parent, name, min, max, value, interval):
super(SliderWidget, self).__init__(parent)
self.name = name
self.min = min
self.max = max
self.value = value
self.interval = interval
self.hbox = QtGui.QHBoxLayout()
self.QLabel_name = QtGui.QLabel(self)
self.QLabel_value = QtGui.QLabel(self)
self.QSlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
self.setLayout(self.hbox)
self.hbox.addWidget(self.QLabel_name)
self.hbox.addWidget(self.QLabel_value)
self.hbox.addWidget(self.QSlider)
self.QLabel_name.setText(name)
self.QLabel_value.setText(str(value))
self.QSlider.setMinimum(min)
self.QSlider.setMaximum(max)
self.QSlider.setValue(value)
self.QSlider.setSingleStep(interval)
self.QSlider.setTickInterval(interval)
self.QSlider.setTickPosition(QtGui.QSlider.TicksBelow)
self.QSlider.valueChanged.connect(self.setValue)
def setValue(self, value):
# Round the value to fit the interval
value = value - self.min
value = round( value / float(self.interval) ) * self.interval
value = int( value + self.min )
self.value = value
self.QSlider.setValue(value)
self.QLabel_value.setText(str(value))
class TextWindow(QtGui.QWidget):
def __init__(self):
super(TextWindow, self).__init__()
self.setWindowTitle('Info')
self.setWindowIcon(QtGui.QIcon('icons/cool.png'))
self.setGeometry(150, 150, 512, 256)
self.setFixedSize(512, 256)
self.font = QtGui.QFont()
self.font.setFamily('Segoe UI')
self.font.setBold(False)
self.font.setPixelSize(14)
self.textbox = QtGui.QLabel(self)
self.textbox.setGeometry(0, 0, 512, 256)
self.textbox.setAlignment(QtCore.Qt.AlignLeft)
self.textbox.setFont(self.font)
def setText(self, text):
self.textbox.setText(text)
class TunerWindow(QtGui.QWidget):
'''
A gui template window for tuning parameters.
This class does not contain any business logic.
All it does is to provide an interface to adjust parameters through gui.
Each parameter is wrapped in a 'block' of SliderWidget object.
Properties (name, min, max, value, interval)
of each parameter is stored in the SliderWidget object.
'''
def __init__(self):
super(TunerWindow, self).__init__()
# self.setMinimumWidth(600)
# self.setMaximumWidth(600)
self.main_vbox = QtGui.QVBoxLayout()
self.setLayout(self.main_vbox)
self.btn_hbox = QtGui.QHBoxLayout()
self.main_vbox.addLayout(self.btn_hbox)
K = [('ok' ,'OK' ),
('cancel','Cancel'),
('apply' ,'Apply' )]
self.btn = {}
for key, name in K:
self.btn[key] = QtGui.QPushButton(name, self)
self.btn[key].clicked.connect(getattr(self, key))
self.btn_hbox.addWidget( self.btn[key] )
self.parameters = []
def apply_parameter(self):
'''
Supposed to be overridden.
Defines what to do when ok() or apply() are called.
'''
pass
def ok(self):
self.apply_parameter()
self.hide()
def cancel(self):
self.hide()
def apply(self):
self.apply_parameter()
def add_parameter(self, name, min, max, value, interval):
'''
Add a new SliderWidget object holding all information of the new parameter.
'''
widget = SliderWidget(parent = self,
name = name,
min = min,
max = max,
value = value,
interval = interval)
self.parameters.append(widget)
self.main_vbox.insertWidget(len(self.main_vbox)-1, widget)
class CameraTunerWindow(TunerWindow):
'''
Inherits from the TunerWindow class.
The business logics for the camera imaging parameters
is specified in this class.
This class also manages the transfer of camera parameters
to the core object.
'''
def __init__(self, controller_obj):
super(CameraTunerWindow, self).__init__()
self.controller = controller_obj
self.setWindowIcon(QtGui.QIcon('icons/cool.png'))
self.setWindowTitle('Stereo Depth Parameters')
self.setMinimumWidth(600)
self.add_parameter(name='brightness' , min=0 , max=255 , value=150 , interval=5 )
self.add_parameter(name='contrast' , min=0 , max=255 , value=64 , interval=5 )
self.add_parameter(name='saturation' , min=0 , max=255 , value=80 , interval=5 )
self.add_parameter(name='gain' , min=0 , max=255 , value=50 , interval=5 )
self.add_parameter(name='exposure' , min=-7 , max=-1 , value=-4 , interval=1 )
self.add_parameter(name='white_balance' , min=3000, max=6500, value=5000, interval=100)
self.add_parameter(name='focus' , min=0 , max=255 , value=0 , interval=5 )
def apply_parameter(self):
'''
Transfers parameters to the core object via the controller.
'''
parms = {}
for p in self.parameters:
parms[p.name] = p.value
self.controller.call_method( method_name = 'apply_camera_parameters',
arg = parms )
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
gui = CamnistGUI( controller_obj = MockController() )
gui.show()
sys.exit(app.exec_())
|
mit
|
[
646,
2680,
465,
980,
199,
646,
6277,
18,
12,
900,
12,
984,
12,
5796,
12,
2022,
12,
747,
199,
504,
14084,
20,
492,
10565,
12,
5928,
199,
504,
7614,
492,
627,
4388,
199,
533,
445,
455,
78,
631,
14438,
8,
10604,
14,
49,
16031,
304,
272,
347,
636,
826,
721,
277,
12,
7614,
63,
1113,
304,
267,
1613,
8,
30524,
78,
631,
14438,
12,
291,
2843,
826,
4533,
267,
291,
14,
5538,
275,
7614,
63,
1113,
398,
5496,
63,
694,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
267,
931,
275,
747,
14,
515,
14,
904,
8,
4600,
63,
694,
12,
283,
3214,
15,
5885,
14,
1001,
358,
267,
11621,
63,
28899,
275,
2022,
14,
3640,
8,
1490,
8,
515,
12,
283,
82,
1959,
739,
1012,
267,
336,
275,
11621,
63,
28899,
459,
7157,
63,
2063,
418,
267,
394,
275,
11621,
63,
28899,
459,
7157,
63,
3333,
418,
398,
291,
14,
30601,
360,
3630,
16237,
6225,
358,
267,
291,
14,
25666,
8954,
8,
10604,
14,
26196,
360,
16471,
15,
18499,
14,
4524,
1333,
267,
291,
14,
25559,
8,
1960,
12,
2948,
12,
336,
12,
394,
9,
267,
291,
14,
409,
9515,
2320,
8,
87,
12,
394,
9,
267,
291,
14,
409,
17141,
23785,
8,
549,
9,
398,
291,
14,
7157,
275,
5928,
14,
19890,
8,
277,
9,
267,
291,
14,
7157,
14,
25559,
8,
16,
12,
378,
12,
336,
12,
394,
9,
267,
291,
14,
7157,
14,
409,
16613,
8,
10901,
14,
4238,
14,
9497,
13551,
9,
398,
291,
14,
13951,
275,
5928,
14,
49,
5157,
5281,
360,
5157,
12377,
358,
267,
291,
14,
13951,
14,
409,
3716,
30456,
8,
549,
9,
267,
291,
14,
13951,
14,
31091,
16715,
480,
49,
5157,
5281,
469,
8020,
26,
7510,
27,
789,
531,
267,
291,
14,
13951,
14,
27668,
2320,
8,
10901,
14,
15531,
8,
1216,
12,
10416,
430,
267,
291,
14,
525,
5157,
5281,
8,
10901,
14,
4238,
14,
8185,
5157,
5281,
11043,
12,
291,
14,
13951,
9,
398,
291,
14,
815,
63,
3806,
275,
4516,
4301,
342,
267,
291,
14,
11928,
63,
10032,
281,
63,
3806,
275,
445,
7122,
22664,
281,
4301,
8,
7614,
63,
1113,
275,
291,
14,
5538,
776,
398,
291,
855,
826,
363,
3557,
13061,
561,
342,
339,
347,
636,
826,
363,
3557,
13061,
561,
8,
277,
304,
267,
327,
7048,
1595,
965,
282,
3747,
790,
436,
282,
536,
267,
327,
790,
275,
7016,
1788,
275,
1083,
536,
267,
327,
536,
275,
1318,
402,
314,
1595,
15,
3887,
398,
327,
259,
334,
259,
2883,
3698,
2360,
257,
1561,
12793,
776,
267,
1804,
275,
4274,
4753,
7,
260,
2360,
283,
12038,
7,
10473,
2318,
1467,
661,
13396,
63,
24616,
7,
2360,
283,
5433,
15709,
7,
8295,
2318,
1467,
661,
1490,
63,
815,
7,
263,
2360,
283,
6824,
14849,
13,
521,
10332,
7,
3698,
2318,
1467,
661,
1490,
63,
11928,
63,
10032,
281,
297,
283,
17977,
445,
7122,
3897,
7,
420,
776,
61,
398,
291,
14,
3723,
275,
1052,
267,
291,
14,
3557,
13061,
561,
275,
1052,
398,
327,
2790,
5445,
436,
4744,
15766,
267,
367,
790,
12,
536,
315,
1804,
26,
288,
5496,
63,
694,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
288,
931,
275,
747,
14,
515,
14,
904,
8,
4600,
63,
694,
12,
283,
16471,
4805,
435,
790,
435,
1987,
4524,
358,
288,
7016,
275,
5928,
14,
26196,
8,
515,
9,
288,
291,
14,
3723,
59,
498,
61,
275,
5928,
14,
49,
3310,
8,
4677,
12,
536,
12,
291,
9,
288,
291,
14,
3557,
13061,
561,
59,
498,
61,
275,
291,
14,
13951,
14,
19006,
8,
277,
14,
3723,
59,
498,
566,
398,
327,
2104,
5445,
626,
4839,
370,
506,
8539,
370,
314,
6170,
909,
12,
267,
1804,
275,
788,
4753,
297,
283,
13396,
63,
24616,
418,
398,
327,
1010,
642,
4438,
473,
3247,
282,
4465,
4340,
402,
267,
327,
18170,
1924,
1595,
370,
282,
1083,
315,
314,
6170,
909,
4799,
314,
7614,
909,
14,
267,
367,
790,
315,
1804,
26,
288,
327,
2372,
282,
1423,
13,
2003,
1083,
687,
314,
7614,
909,
14,
288,
327,
3390,
626,
314,
1083,
63,
354,
275,
790,
14,
288,
1083,
275,
291,
14,
5538,
14,
362,
63,
765,
8,
1083,
63,
354,
275,
790,
776,
288,
327,
710,
664,
63,
765,
342,
2529,
488,
288,
327,
340,
282,
6770,
1083,
365,
440,
1911,
315,
314,
6170,
909,
14,
288,
340,
440,
1083,
365,
488,
26,
355,
327,
15175,
314,
1595,
370,
314,
1083,
315,
314,
7614,
909,
355,
291,
14,
3723,
59,
498,
1055,
21142,
14,
2242,
8,
765,
9,
398,
327,
2104,
5445,
626,
4839,
370,
506,
8539,
370,
314,
291,
11621,
909,
12,
267,
2883,
275,
788,
1490,
63,
815,
297,
283,
1490,
63,
11928,
63,
10032,
281,
418,
267,
367,
790,
315,
2883,
26,
288,
862,
26,
355,
1083,
275,
2519,
8,
277,
12,
790,
9,
355,
291,
14,
3723,
59,
498,
1055,
21142,
14,
2242,
8,
765,
9,
288,
871,
2186,
465,
1919,
63,
3615,
26,
355,
870,
8,
1971,
63,
3615,
9,
339,
347,
1551,
63,
815,
8,
277,
304,
267,
340,
440,
291,
14,
815,
63,
3806,
14,
374,
14917,
837,
288,
291,
14,
815,
63,
3806,
14,
2384,
342,
339,
347,
1551,
63,
11928,
63,
10032,
281,
8,
277,
304,
267,
291,
14,
11928,
63,
10032,
281,
63,
3806,
14,
2384,
342,
339,
347,
9989,
2390,
8,
277,
12,
1566,
304,
267,
340,
1566,
14,
3136,
342,
690,
378,
26,
288,
291,
14,
5538,
14,
1250,
63,
765,
360,
10598,
63,
262,
358,
267,
587,
26,
288,
291,
14,
5538,
14,
1250,
63,
765,
360,
10598,
63,
548,
358,
339,
347,
4002,
2390,
8,
277,
12,
1566,
304,
267,
9351,
275,
5928,
14,
30798,
14,
4790,
8,
277,
12,
5644,
283,
3630,
16237,
6225,
297,
5644,
283,
17683,
1265,
3238,
1265,
2934,
370,
17242,
8790,
16237,
6225,
7044,
5644,
5928,
14,
30798,
14,
12555,
12,
5928,
14,
30798,
14,
1944,
9,
398,
340,
9351,
508,
5928,
14,
30798,
14,
12555,
26,
288,
291,
14,
5538,
14,
1250,
63,
765,
360,
1600,
358,
288,
291,
14,
815,
63,
3806,
14,
1600,
342,
288,
291,
14,
11928,
63,
10032,
281,
63,
3806,
14,
1600,
342,
288
] |
[
2680,
465,
980,
199,
646,
6277,
18,
12,
900,
12,
984,
12,
5796,
12,
2022,
12,
747,
199,
504,
14084,
20,
492,
10565,
12,
5928,
199,
504,
7614,
492,
627,
4388,
199,
533,
445,
455,
78,
631,
14438,
8,
10604,
14,
49,
16031,
304,
272,
347,
636,
826,
721,
277,
12,
7614,
63,
1113,
304,
267,
1613,
8,
30524,
78,
631,
14438,
12,
291,
2843,
826,
4533,
267,
291,
14,
5538,
275,
7614,
63,
1113,
398,
5496,
63,
694,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
267,
931,
275,
747,
14,
515,
14,
904,
8,
4600,
63,
694,
12,
283,
3214,
15,
5885,
14,
1001,
358,
267,
11621,
63,
28899,
275,
2022,
14,
3640,
8,
1490,
8,
515,
12,
283,
82,
1959,
739,
1012,
267,
336,
275,
11621,
63,
28899,
459,
7157,
63,
2063,
418,
267,
394,
275,
11621,
63,
28899,
459,
7157,
63,
3333,
418,
398,
291,
14,
30601,
360,
3630,
16237,
6225,
358,
267,
291,
14,
25666,
8954,
8,
10604,
14,
26196,
360,
16471,
15,
18499,
14,
4524,
1333,
267,
291,
14,
25559,
8,
1960,
12,
2948,
12,
336,
12,
394,
9,
267,
291,
14,
409,
9515,
2320,
8,
87,
12,
394,
9,
267,
291,
14,
409,
17141,
23785,
8,
549,
9,
398,
291,
14,
7157,
275,
5928,
14,
19890,
8,
277,
9,
267,
291,
14,
7157,
14,
25559,
8,
16,
12,
378,
12,
336,
12,
394,
9,
267,
291,
14,
7157,
14,
409,
16613,
8,
10901,
14,
4238,
14,
9497,
13551,
9,
398,
291,
14,
13951,
275,
5928,
14,
49,
5157,
5281,
360,
5157,
12377,
358,
267,
291,
14,
13951,
14,
409,
3716,
30456,
8,
549,
9,
267,
291,
14,
13951,
14,
31091,
16715,
480,
49,
5157,
5281,
469,
8020,
26,
7510,
27,
789,
531,
267,
291,
14,
13951,
14,
27668,
2320,
8,
10901,
14,
15531,
8,
1216,
12,
10416,
430,
267,
291,
14,
525,
5157,
5281,
8,
10901,
14,
4238,
14,
8185,
5157,
5281,
11043,
12,
291,
14,
13951,
9,
398,
291,
14,
815,
63,
3806,
275,
4516,
4301,
342,
267,
291,
14,
11928,
63,
10032,
281,
63,
3806,
275,
445,
7122,
22664,
281,
4301,
8,
7614,
63,
1113,
275,
291,
14,
5538,
776,
398,
291,
855,
826,
363,
3557,
13061,
561,
342,
339,
347,
636,
826,
363,
3557,
13061,
561,
8,
277,
304,
267,
327,
7048,
1595,
965,
282,
3747,
790,
436,
282,
536,
267,
327,
790,
275,
7016,
1788,
275,
1083,
536,
267,
327,
536,
275,
1318,
402,
314,
1595,
15,
3887,
398,
327,
259,
334,
259,
2883,
3698,
2360,
257,
1561,
12793,
776,
267,
1804,
275,
4274,
4753,
7,
260,
2360,
283,
12038,
7,
10473,
2318,
1467,
661,
13396,
63,
24616,
7,
2360,
283,
5433,
15709,
7,
8295,
2318,
1467,
661,
1490,
63,
815,
7,
263,
2360,
283,
6824,
14849,
13,
521,
10332,
7,
3698,
2318,
1467,
661,
1490,
63,
11928,
63,
10032,
281,
297,
283,
17977,
445,
7122,
3897,
7,
420,
776,
61,
398,
291,
14,
3723,
275,
1052,
267,
291,
14,
3557,
13061,
561,
275,
1052,
398,
327,
2790,
5445,
436,
4744,
15766,
267,
367,
790,
12,
536,
315,
1804,
26,
288,
5496,
63,
694,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
288,
931,
275,
747,
14,
515,
14,
904,
8,
4600,
63,
694,
12,
283,
16471,
4805,
435,
790,
435,
1987,
4524,
358,
288,
7016,
275,
5928,
14,
26196,
8,
515,
9,
288,
291,
14,
3723,
59,
498,
61,
275,
5928,
14,
49,
3310,
8,
4677,
12,
536,
12,
291,
9,
288,
291,
14,
3557,
13061,
561,
59,
498,
61,
275,
291,
14,
13951,
14,
19006,
8,
277,
14,
3723,
59,
498,
566,
398,
327,
2104,
5445,
626,
4839,
370,
506,
8539,
370,
314,
6170,
909,
12,
267,
1804,
275,
788,
4753,
297,
283,
13396,
63,
24616,
418,
398,
327,
1010,
642,
4438,
473,
3247,
282,
4465,
4340,
402,
267,
327,
18170,
1924,
1595,
370,
282,
1083,
315,
314,
6170,
909,
4799,
314,
7614,
909,
14,
267,
367,
790,
315,
1804,
26,
288,
327,
2372,
282,
1423,
13,
2003,
1083,
687,
314,
7614,
909,
14,
288,
327,
3390,
626,
314,
1083,
63,
354,
275,
790,
14,
288,
1083,
275,
291,
14,
5538,
14,
362,
63,
765,
8,
1083,
63,
354,
275,
790,
776,
288,
327,
710,
664,
63,
765,
342,
2529,
488,
288,
327,
340,
282,
6770,
1083,
365,
440,
1911,
315,
314,
6170,
909,
14,
288,
340,
440,
1083,
365,
488,
26,
355,
327,
15175,
314,
1595,
370,
314,
1083,
315,
314,
7614,
909,
355,
291,
14,
3723,
59,
498,
1055,
21142,
14,
2242,
8,
765,
9,
398,
327,
2104,
5445,
626,
4839,
370,
506,
8539,
370,
314,
291,
11621,
909,
12,
267,
2883,
275,
788,
1490,
63,
815,
297,
283,
1490,
63,
11928,
63,
10032,
281,
418,
267,
367,
790,
315,
2883,
26,
288,
862,
26,
355,
1083,
275,
2519,
8,
277,
12,
790,
9,
355,
291,
14,
3723,
59,
498,
1055,
21142,
14,
2242,
8,
765,
9,
288,
871,
2186,
465,
1919,
63,
3615,
26,
355,
870,
8,
1971,
63,
3615,
9,
339,
347,
1551,
63,
815,
8,
277,
304,
267,
340,
440,
291,
14,
815,
63,
3806,
14,
374,
14917,
837,
288,
291,
14,
815,
63,
3806,
14,
2384,
342,
339,
347,
1551,
63,
11928,
63,
10032,
281,
8,
277,
304,
267,
291,
14,
11928,
63,
10032,
281,
63,
3806,
14,
2384,
342,
339,
347,
9989,
2390,
8,
277,
12,
1566,
304,
267,
340,
1566,
14,
3136,
342,
690,
378,
26,
288,
291,
14,
5538,
14,
1250,
63,
765,
360,
10598,
63,
262,
358,
267,
587,
26,
288,
291,
14,
5538,
14,
1250,
63,
765,
360,
10598,
63,
548,
358,
339,
347,
4002,
2390,
8,
277,
12,
1566,
304,
267,
9351,
275,
5928,
14,
30798,
14,
4790,
8,
277,
12,
5644,
283,
3630,
16237,
6225,
297,
5644,
283,
17683,
1265,
3238,
1265,
2934,
370,
17242,
8790,
16237,
6225,
7044,
5644,
5928,
14,
30798,
14,
12555,
12,
5928,
14,
30798,
14,
1944,
9,
398,
340,
9351,
508,
5928,
14,
30798,
14,
12555,
26,
288,
291,
14,
5538,
14,
1250,
63,
765,
360,
1600,
358,
288,
291,
14,
815,
63,
3806,
14,
1600,
342,
288,
291,
14,
11928,
63,
10032,
281,
63,
3806,
14,
1600,
342,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,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/python/lib/python2.7/lib2to3/fixes/fix_filter.py
|
7
|
2082
|
# Copyright 2007 Google, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""Fixer that changes filter(F, X) into list(filter(F, X)).
We avoid the transformation if the filter() call is directly contained
in iter(<>), list(<>), tuple(<>), sorted(<>), ...join(<>), or
for V in <>:.
NOTE: This is still not correct if the original code was depending on
filter(F, X) to return a string if X is a string and a tuple if X is a
tuple. That would require type inference, which we don't do. Let
Python 2.6 figure it out.
"""
# Local imports
from ..pgen2 import token
from .. import fixer_base
from ..fixer_util import Name, Call, ListComp, in_special_context
class FixFilter(fixer_base.ConditionalFix):
PATTERN = """
filter_lambda=power<
'filter'
trailer<
'('
arglist<
lambdef< 'lambda'
(fp=NAME | vfpdef< '(' fp=NAME ')'> ) ':' xp=any
>
','
it=any
>
')'
>
>
|
power<
'filter'
trailer< '(' arglist< none='None' ',' seq=any > ')' >
>
|
power<
'filter'
args=trailer< '(' [any] ')' >
>
"""
skip_on = "future_builtins.filter"
def transform(self, node, results):
if self.should_skip(node):
return
if "filter_lambda" in results:
new = ListComp(results.get("fp").clone(),
results.get("fp").clone(),
results.get("it").clone(),
results.get("xp").clone())
elif "none" in results:
new = ListComp(Name(u"_f"),
Name(u"_f"),
results["seq"].clone(),
Name(u"_f"))
else:
if in_special_context(node):
return None
new = node.clone()
new.prefix = u""
new = Call(Name(u"list"), [new])
new.prefix = node.prefix
return new
|
apache-2.0
|
[
3,
1898,
10219,
4475,
12,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
624,
11985,
281,
626,
4493,
2457,
8,
38,
12,
1323,
9,
1901,
769,
8,
1541,
8,
38,
12,
1323,
4992,
199,
199,
6004,
5126,
314,
13315,
340,
314,
2457,
342,
1240,
365,
5370,
10470,
199,
262,
2740,
8,
16137,
395,
769,
8,
16137,
395,
2008,
8,
16137,
395,
3355,
8,
16137,
395,
2263,
904,
8,
16137,
395,
503,
199,
509,
812,
315,
20941,
14010,
199,
199,
19855,
26,
961,
365,
5139,
440,
3211,
340,
314,
3379,
1233,
1990,
10298,
641,
199,
1541,
8,
38,
12,
1323,
9,
370,
372,
282,
1059,
340,
1323,
365,
282,
1059,
436,
282,
2008,
340,
1323,
365,
282,
199,
2960,
14,
221,
10314,
3955,
4409,
730,
17353,
12,
1314,
781,
2793,
1133,
886,
14,
221,
12230,
199,
4718,
499,
14,
22,
9658,
652,
734,
14,
199,
624,
199,
199,
3,
10111,
8925,
199,
504,
2508,
80,
2268,
18,
492,
1526,
199,
504,
2508,
492,
24739,
63,
1095,
199,
504,
2508,
25973,
63,
1974,
492,
2812,
12,
6523,
12,
3820,
2404,
12,
315,
63,
6664,
63,
1100,
199,
199,
533,
14811,
4131,
8,
25973,
63,
1095,
14,
21321,
11985,
304,
339,
31467,
7689,
275,
408,
272,
2457,
63,
2734,
29,
5652,
28,
267,
283,
1541,
7,
267,
17357,
28,
288,
16746,
288,
24660,
28,
355,
27593,
318,
28,
283,
2734,
7,
586,
334,
3997,
29,
2339,
1204,
373,
3997,
318,
28,
16746,
4090,
29,
2339,
16107,
30,
776,
10871,
21499,
29,
1629,
355,
690,
355,
13647,
355,
652,
29,
1629,
288,
690,
288,
16107,
267,
690,
272,
690,
272,
1204,
272,
7074,
28,
267,
283,
1541,
7,
267,
17357,
28,
16746,
24660,
28,
7179,
534,
403,
7,
13647,
5412,
29,
1629,
690,
16107,
690,
272,
690,
272,
1204,
272,
7074,
28,
267,
283,
1541,
7,
267,
1249,
29,
21606,
28,
16746,
359,
1629,
61,
16107,
690,
272,
690,
272,
408,
339,
3372,
63,
265,
275,
298,
2443,
63,
10372,
14,
1541,
2,
339,
347,
5793,
8,
277,
12,
1031,
12,
2058,
304,
267,
340,
291,
14,
5626,
63,
2759,
8,
932,
304,
288,
372,
398,
340,
298,
1541,
63,
2734,
2,
315,
2058,
26,
288,
892,
275,
3820,
2404,
8,
2604,
14,
362,
480,
3997,
3471,
6311,
1062,
2574,
2058,
14,
362,
480,
3997,
3471,
6311,
1062,
2574,
2058,
14,
362,
480,
390,
3471,
6311,
1062,
2574,
2058,
14,
362,
480,
9290,
3471,
6311,
1012,
398,
916,
298,
3592,
2,
315,
2058,
26,
288,
892,
275,
3820,
2404,
8,
985,
8,
85,
2,
63,
70,
1288,
2574,
2812,
8,
85,
2,
63,
70,
1288,
2574,
2058,
905,
3610,
4140,
6311,
1062,
2574,
2812,
8,
85,
2,
63,
70,
2237,
398,
587,
26,
288,
340,
315,
63,
6664,
63,
1100,
8,
932,
304,
355,
372,
488,
288,
892,
275,
1031,
14,
6311,
342,
288,
892,
14,
1861,
275,
399,
341,
288,
892,
275,
6523,
8,
985,
8,
85,
2,
513,
1288,
359,
1222,
566,
267,
892,
14,
1861,
275,
1031,
14,
1861,
267,
372,
892,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
10219,
4475,
12,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
624,
11985,
281,
626,
4493,
2457,
8,
38,
12,
1323,
9,
1901,
769,
8,
1541,
8,
38,
12,
1323,
4992,
199,
199,
6004,
5126,
314,
13315,
340,
314,
2457,
342,
1240,
365,
5370,
10470,
199,
262,
2740,
8,
16137,
395,
769,
8,
16137,
395,
2008,
8,
16137,
395,
3355,
8,
16137,
395,
2263,
904,
8,
16137,
395,
503,
199,
509,
812,
315,
20941,
14010,
199,
199,
19855,
26,
961,
365,
5139,
440,
3211,
340,
314,
3379,
1233,
1990,
10298,
641,
199,
1541,
8,
38,
12,
1323,
9,
370,
372,
282,
1059,
340,
1323,
365,
282,
1059,
436,
282,
2008,
340,
1323,
365,
282,
199,
2960,
14,
221,
10314,
3955,
4409,
730,
17353,
12,
1314,
781,
2793,
1133,
886,
14,
221,
12230,
199,
4718,
499,
14,
22,
9658,
652,
734,
14,
199,
624,
199,
199,
3,
10111,
8925,
199,
504,
2508,
80,
2268,
18,
492,
1526,
199,
504,
2508,
492,
24739,
63,
1095,
199,
504,
2508,
25973,
63,
1974,
492,
2812,
12,
6523,
12,
3820,
2404,
12,
315,
63,
6664,
63,
1100,
199,
199,
533,
14811,
4131,
8,
25973,
63,
1095,
14,
21321,
11985,
304,
339,
31467,
7689,
275,
408,
272,
2457,
63,
2734,
29,
5652,
28,
267,
283,
1541,
7,
267,
17357,
28,
288,
16746,
288,
24660,
28,
355,
27593,
318,
28,
283,
2734,
7,
586,
334,
3997,
29,
2339,
1204,
373,
3997,
318,
28,
16746,
4090,
29,
2339,
16107,
30,
776,
10871,
21499,
29,
1629,
355,
690,
355,
13647,
355,
652,
29,
1629,
288,
690,
288,
16107,
267,
690,
272,
690,
272,
1204,
272,
7074,
28,
267,
283,
1541,
7,
267,
17357,
28,
16746,
24660,
28,
7179,
534,
403,
7,
13647,
5412,
29,
1629,
690,
16107,
690,
272,
690,
272,
1204,
272,
7074,
28,
267,
283,
1541,
7,
267,
1249,
29,
21606,
28,
16746,
359,
1629,
61,
16107,
690,
272,
690,
272,
408,
339,
3372,
63,
265,
275,
298,
2443,
63,
10372,
14,
1541,
2,
339,
347,
5793,
8,
277,
12,
1031,
12,
2058,
304,
267,
340,
291,
14,
5626,
63,
2759,
8,
932,
304,
288,
372,
398,
340,
298,
1541,
63,
2734,
2,
315,
2058,
26,
288,
892,
275,
3820,
2404,
8,
2604,
14,
362,
480,
3997,
3471,
6311,
1062,
2574,
2058,
14,
362,
480,
3997,
3471,
6311,
1062,
2574,
2058,
14,
362,
480,
390,
3471,
6311,
1062,
2574,
2058,
14,
362,
480,
9290,
3471,
6311,
1012,
398,
916,
298,
3592,
2,
315,
2058,
26,
288,
892,
275,
3820,
2404,
8,
985,
8,
85,
2,
63,
70,
1288,
2574,
2812,
8,
85,
2,
63,
70,
1288,
2574,
2058,
905,
3610,
4140,
6311,
1062,
2574,
2812,
8,
85,
2,
63,
70,
2237,
398,
587,
26,
288,
340,
315,
63,
6664,
63,
1100,
8,
932,
304,
355,
372,
488,
288,
892,
275,
1031,
14,
6311,
342,
288,
892,
14,
1861,
275,
399,
341,
288,
892,
275,
6523,
8,
985,
8,
85,
2,
513,
1288,
359,
1222,
566,
267,
892,
14,
1861,
275,
1031,
14,
1861,
267,
372,
892,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
JamesMGreene/phantomjs
|
src/qt/qtwebkit/Tools/Scripts/webkitpy/thirdparty/ordered_dict.py
|
131
|
2984
|
# Copyright (c) 2009 Raymond Hettinger.
#
# 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.
# This code is obtained from http://code.activestate.com/recipes/576669/
from collections import MutableMapping
class OrderedDict(dict, MutableMapping):
# Methods with direct access to underlying attributes
def __init__(self, *args, **kwds):
if len(args) > 1:
raise TypeError('expected at 1 argument, got %d', len(args))
if not hasattr(self, '_keys'):
self._keys = []
self.update(*args, **kwds)
def clear(self):
del self._keys[:]
dict.clear(self)
def __setitem__(self, key, value):
if key not in self:
self._keys.append(key)
dict.__setitem__(self, key, value)
def __delitem__(self, key):
dict.__delitem__(self, key)
self._keys.remove(key)
def __iter__(self):
return iter(self._keys)
def __reversed__(self):
return reversed(self._keys)
def popitem(self):
if not self:
raise KeyError
key = self._keys.pop()
value = dict.pop(self, key)
return key, value
def __reduce__(self):
items = [[k, self[k]] for k in self]
inst_dict = vars(self).copy()
inst_dict.pop('_keys', None)
return (self.__class__, (items,), inst_dict)
# Methods with indirect access via the above methods
setdefault = MutableMapping.setdefault
update = MutableMapping.update
pop = MutableMapping.pop
keys = MutableMapping.keys
values = MutableMapping.values
items = MutableMapping.items
def __repr__(self):
pairs = ', '.join(map('%r: %r'.__mod__, self.items()))
return '%s({%s})' % (self.__class__.__name__, pairs)
def copy(self):
return self.__class__(self)
@classmethod
def fromkeys(cls, iterable, value=None):
d = cls()
for key in iterable:
d[key] = value
return d
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
8937,
30703,
2106,
68,
869,
386,
1337,
281,
14,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
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,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
199,
3,
961,
1233,
365,
15884,
687,
1455,
921,
600,
14,
32595,
14,
957,
15,
25200,
15,
1641,
1272,
1876,
15,
199,
199,
504,
5055,
492,
29396,
199,
199,
533,
8773,
8,
807,
12,
29396,
304,
339,
327,
17653,
543,
4125,
2879,
370,
8793,
3004,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
10340,
304,
267,
340,
822,
8,
589,
9,
690,
413,
26,
288,
746,
3146,
360,
2062,
737,
413,
1423,
12,
4788,
450,
68,
297,
822,
8,
589,
430,
267,
340,
440,
2688,
8,
277,
12,
2513,
1612,
735,
288,
291,
423,
1612,
275,
942,
267,
291,
14,
873,
2031,
589,
12,
1011,
10340,
9,
339,
347,
5436,
8,
277,
304,
267,
2150,
291,
423,
1612,
5873,
267,
1211,
14,
3584,
8,
277,
9,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
340,
790,
440,
315,
291,
26,
288,
291,
423,
1612,
14,
740,
8,
498,
9,
267,
1211,
855,
8617,
721,
277,
12,
790,
12,
574,
9,
339,
347,
636,
13228,
721,
277,
12,
790,
304,
267,
1211,
855,
13228,
721,
277,
12,
790,
9,
267,
291,
423,
1612,
14,
2168,
8,
498,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
423,
1612,
9,
339,
347,
636,
13501,
721,
277,
304,
267,
372,
10822,
8,
277,
423,
1612,
9,
339,
347,
4560,
1053,
8,
277,
304,
267,
340,
440,
291,
26,
288,
746,
4067,
267,
790,
275,
291,
423,
1612,
14,
1935,
342,
267,
574,
275,
1211,
14,
1935,
8,
277,
12,
790,
9,
267,
372,
790,
12,
574,
339,
347,
636,
5270,
721,
277,
304,
267,
2974,
275,
3474,
75,
12,
291,
59,
75,
2677,
367,
1022,
315,
291,
61,
267,
2727,
63,
807,
275,
6802,
8,
277,
680,
1574,
342,
267,
2727,
63,
807,
14,
1935,
6412,
1612,
297,
488,
9,
267,
372,
334,
277,
855,
533,
3108,
334,
1744,
4706,
2727,
63,
807,
9,
339,
327,
17653,
543,
19458,
2879,
4799,
314,
3432,
3102,
339,
29408,
275,
29396,
14,
5486,
272,
1678,
275,
29396,
14,
873,
272,
4560,
275,
29396,
14,
1935,
272,
2883,
275,
29396,
14,
1612,
272,
1338,
275,
29396,
14,
1459,
272,
2974,
275,
29396,
14,
1744,
339,
347,
636,
2722,
721,
277,
304,
267,
6342,
275,
1656,
1987,
904,
8,
1130,
3508,
82,
26,
450,
82,
7,
855,
1494,
3108,
291,
14,
1744,
4059,
267,
372,
1543,
83,
2561,
5,
83,
29668,
450,
334,
277,
855,
533,
4914,
354,
3108,
6342,
9,
339,
347,
1331,
8,
277,
304,
267,
372,
291,
855,
533,
721,
277,
9,
339,
768,
3744,
272,
347,
687,
1612,
8,
1886,
12,
6076,
12,
574,
29,
403,
304,
267,
366,
275,
843,
342,
267,
367,
790,
315,
6076,
26,
288,
366,
59,
498,
61,
275,
574,
267,
372,
366,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
8937,
30703,
2106,
68,
869,
386,
1337,
281,
14,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
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,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
199,
3,
961,
1233,
365,
15884,
687,
1455,
921,
600,
14,
32595,
14,
957,
15,
25200,
15,
1641,
1272,
1876,
15,
199,
199,
504,
5055,
492,
29396,
199,
199,
533,
8773,
8,
807,
12,
29396,
304,
339,
327,
17653,
543,
4125,
2879,
370,
8793,
3004,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
10340,
304,
267,
340,
822,
8,
589,
9,
690,
413,
26,
288,
746,
3146,
360,
2062,
737,
413,
1423,
12,
4788,
450,
68,
297,
822,
8,
589,
430,
267,
340,
440,
2688,
8,
277,
12,
2513,
1612,
735,
288,
291,
423,
1612,
275,
942,
267,
291,
14,
873,
2031,
589,
12,
1011,
10340,
9,
339,
347,
5436,
8,
277,
304,
267,
2150,
291,
423,
1612,
5873,
267,
1211,
14,
3584,
8,
277,
9,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
340,
790,
440,
315,
291,
26,
288,
291,
423,
1612,
14,
740,
8,
498,
9,
267,
1211,
855,
8617,
721,
277,
12,
790,
12,
574,
9,
339,
347,
636,
13228,
721,
277,
12,
790,
304,
267,
1211,
855,
13228,
721,
277,
12,
790,
9,
267,
291,
423,
1612,
14,
2168,
8,
498,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
423,
1612,
9,
339,
347,
636,
13501,
721,
277,
304,
267,
372,
10822,
8,
277,
423,
1612,
9,
339,
347,
4560,
1053,
8,
277,
304,
267,
340,
440,
291,
26,
288,
746,
4067,
267,
790,
275,
291,
423,
1612,
14,
1935,
342,
267,
574,
275,
1211,
14,
1935,
8,
277,
12,
790,
9,
267,
372,
790,
12,
574,
339,
347,
636,
5270,
721,
277,
304,
267,
2974,
275,
3474,
75,
12,
291,
59,
75,
2677,
367,
1022,
315,
291,
61,
267,
2727,
63,
807,
275,
6802,
8,
277,
680,
1574,
342,
267,
2727,
63,
807,
14,
1935,
6412,
1612,
297,
488,
9,
267,
372,
334,
277,
855,
533,
3108,
334,
1744,
4706,
2727,
63,
807,
9,
339,
327,
17653,
543,
19458,
2879,
4799,
314,
3432,
3102,
339,
29408,
275,
29396,
14,
5486,
272,
1678,
275,
29396,
14,
873,
272,
4560,
275,
29396,
14,
1935,
272,
2883,
275,
29396,
14,
1612,
272,
1338,
275,
29396,
14,
1459,
272,
2974,
275,
29396,
14,
1744,
339,
347,
636,
2722,
721,
277,
304,
267,
6342,
275,
1656,
1987,
904,
8,
1130,
3508,
82,
26,
450,
82,
7,
855,
1494,
3108,
291,
14,
1744,
4059,
267,
372,
1543,
83,
2561,
5,
83,
29668,
450,
334,
277,
855,
533,
4914,
354,
3108,
6342,
9,
339,
347,
1331,
8,
277,
304,
267,
372,
291,
855,
533,
721,
277,
9,
339,
768,
3744,
272,
347,
687,
1612,
8,
1886,
12,
6076,
12,
574,
29,
403,
304,
267,
366,
275,
843,
342,
267,
367,
790,
315,
6076,
26,
288,
366,
59,
498,
61,
275,
574,
267,
372,
366,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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