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
|
|---|---|---|---|---|---|---|---|---|
sharkykh/SickRage
|
lib/ndg/httpsclient/test/test_https.py
|
57
|
4359
|
"""unit tests module for ndg.httpsclient.https.HTTPSconnection class
PyOpenSSL utility to make a httplib-like interface suitable for use with
urllib2
"""
__author__ = "P J Kershaw (STFC)"
__date__ = "06/01/12"
__copyright__ = "(C) 2012 Science and Technology Facilities Council"
__license__ = "BSD - see LICENSE file in top-level directory"
__contact__ = "Philip.Kershaw@stfc.ac.uk"
__revision__ = '$Id$'
import logging
logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(__name__)
import unittest
import socket
from OpenSSL import SSL
from ndg.httpsclient.test import Constants
from ndg.httpsclient.https import HTTPSConnection
from ndg.httpsclient.ssl_peer_verification import ServerSSLCertVerification
class TestHTTPSConnection(unittest.TestCase):
'''Test ndg HTTPS client HTTPSConnection class'''
def test01_open(self):
conn = HTTPSConnection(Constants.HOSTNAME, port=Constants.PORT)
conn.connect()
conn.request('GET', '/')
resp = conn.getresponse()
print('Response = %s' % resp.read())
conn.close()
def test02_open_fails(self):
conn = HTTPSConnection(Constants.HOSTNAME, port=Constants.PORT2)
self.failUnlessRaises(socket.error, conn.connect)
def test03_ssl_verification_of_peer_fails(self):
ctx = SSL.Context(SSL.SSLv3_METHOD)
def verify_callback(conn, x509, errnum, errdepth, preverify_ok):
log.debug('SSL peer certificate verification failed for %r',
x509.get_subject())
return preverify_ok
ctx.set_verify(SSL.VERIFY_PEER, verify_callback)
ctx.set_verify_depth(9)
# Set bad location - unit test dir has no CA certs to verify with
ctx.load_verify_locations(None, Constants.UNITTEST_DIR)
conn = HTTPSConnection(Constants.HOSTNAME, port=Constants.PORT,
ssl_context=ctx)
conn.connect()
self.failUnlessRaises(SSL.Error, conn.request, 'GET', '/')
def test03_ssl_verification_of_peer_succeeds(self):
ctx = SSL.Context(SSL.SSLv3_METHOD)
verify_callback = lambda conn, x509, errnum, errdepth, preverify_ok: \
preverify_ok
ctx.set_verify(SSL.VERIFY_PEER, verify_callback)
ctx.set_verify_depth(9)
# Set correct location for CA certs to verify with
ctx.load_verify_locations(None, Constants.CACERT_DIR)
conn = HTTPSConnection(Constants.HOSTNAME, port=Constants.PORT,
ssl_context=ctx)
conn.connect()
conn.request('GET', '/')
resp = conn.getresponse()
print('Response = %s' % resp.read())
def test04_ssl_verification_with_subj_alt_name(self):
ctx = SSL.Context(SSL.SSLv3_METHOD)
verify_callback = ServerSSLCertVerification(hostname='localhost')
ctx.set_verify(SSL.VERIFY_PEER, verify_callback)
ctx.set_verify_depth(9)
# Set correct location for CA certs to verify with
ctx.load_verify_locations(None, Constants.CACERT_DIR)
conn = HTTPSConnection(Constants.HOSTNAME, port=Constants.PORT,
ssl_context=ctx)
conn.connect()
conn.request('GET', '/')
resp = conn.getresponse()
print('Response = %s' % resp.read())
def test04_ssl_verification_with_subj_common_name(self):
ctx = SSL.Context(SSL.SSLv3_METHOD)
# Explicitly set verification of peer hostname using peer certificate
# subject common name
verify_callback = ServerSSLCertVerification(hostname='localhost',
subj_alt_name_match=False)
ctx.set_verify(SSL.VERIFY_PEER, verify_callback)
ctx.set_verify_depth(9)
# Set correct location for CA certs to verify with
ctx.load_verify_locations(None, Constants.CACERT_DIR)
conn = HTTPSConnection(Constants.HOSTNAME, port=Constants.PORT,
ssl_context=ctx)
conn.connect()
conn.request('GET', '/')
resp = conn.getresponse()
print('Response = %s' % resp.read())
if __name__ == "__main__":
unittest.main()
|
gpl-3.0
|
[
624,
3248,
2295,
859,
367,
5222,
71,
14,
1014,
551,
864,
14,
2859,
14,
14921,
2105,
1021,
199,
199,
2713,
22791,
11420,
370,
1852,
282,
8809,
13,
2930,
3217,
11233,
367,
675,
543,
221,
199,
4078,
18,
199,
624,
199,
363,
2502,
363,
275,
298,
48,
1603,
1804,
281,
4835,
87,
334,
840,
4161,
2924,
199,
363,
602,
363,
275,
298,
1690,
15,
614,
15,
713,
2,
199,
363,
7307,
363,
275,
7340,
35,
9,
6029,
27491,
436,
21580,
10859,
559,
7999,
1849,
1097,
382,
2,
199,
363,
1682,
363,
275,
298,
15400,
446,
1937,
5113,
570,
315,
2746,
13,
1896,
2082,
2,
199,
363,
7811,
363,
275,
298,
5663,
1638,
80,
14,
43,
281,
4835,
87,
32,
270,
3003,
14,
645,
14,
3210,
2,
199,
363,
5792,
363,
275,
4505,
1304,
12913,
199,
646,
2050,
199,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
5287,
9,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
646,
2882,
199,
646,
2838,
199,
199,
504,
14296,
492,
7799,
199,
199,
504,
5222,
71,
14,
1014,
551,
864,
14,
396,
492,
22296,
199,
504,
5222,
71,
14,
1014,
551,
864,
14,
2859,
492,
14147,
3225,
199,
504,
5222,
71,
14,
1014,
551,
864,
14,
4266,
63,
7866,
63,
16257,
492,
7146,
5413,
14768,
22595,
421,
199,
533,
1379,
27945,
8,
2796,
14,
1746,
304,
272,
1449,
774,
5222,
71,
14147,
1890,
14147,
3225,
1021,
2344,
339,
347,
511,
614,
63,
1490,
8,
277,
304,
267,
2557,
275,
14147,
3225,
8,
22185,
14,
22647,
12,
1844,
29,
22185,
14,
3657,
9,
267,
2557,
14,
2242,
342,
267,
2557,
14,
1069,
360,
2970,
297,
15107,
267,
3085,
275,
2557,
14,
25006,
342,
267,
870,
360,
2364,
275,
450,
83,
7,
450,
3085,
14,
739,
1012,
267,
2557,
14,
1600,
342,
339,
347,
511,
996,
63,
1490,
63,
15762,
8,
277,
304,
267,
2557,
275,
14147,
3225,
8,
22185,
14,
22647,
12,
1844,
29,
22185,
14,
3657,
18,
9,
267,
291,
14,
7589,
1811,
8,
3450,
14,
705,
12,
2557,
14,
2242,
9,
339,
347,
511,
1644,
63,
4266,
63,
16257,
63,
1618,
63,
7866,
63,
15762,
8,
277,
304,
267,
4027,
275,
7799,
14,
2998,
8,
5413,
14,
21082,
19,
63,
9977,
9,
2728,
347,
4911,
63,
3058,
8,
1631,
12,
671,
6576,
12,
2329,
1507,
12,
2329,
4631,
12,
876,
4712,
63,
745,
304,
7205,
943,
14,
1757,
360,
5413,
9104,
5897,
14786,
3405,
367,
450,
82,
297,
1993,
671,
6576,
14,
362,
63,
5875,
1012,
288,
372,
876,
4712,
63,
745,
221,
10631,
4027,
14,
409,
63,
4712,
8,
5413,
14,
22443,
63,
31560,
12,
4911,
63,
3058,
9,
267,
4027,
14,
409,
63,
4712,
63,
4631,
8,
25,
9,
2728,
327,
2494,
4875,
2909,
446,
4137,
511,
2935,
965,
949,
7240,
25949,
370,
4911,
543,
267,
4027,
14,
912,
63,
4712,
63,
8022,
8,
403,
12,
22296,
14,
15505,
2864,
63,
3022,
9,
2728,
2557,
275,
14147,
3225,
8,
22185,
14,
22647,
12,
1844,
29,
22185,
14,
3657,
12,
3044,
6149,
63,
1100,
29,
3799,
9,
267,
2557,
14,
2242,
342,
18418,
291,
14,
7589,
1811,
8,
5413,
14,
547,
12,
2557,
14,
1069,
12,
283,
2970,
297,
15107,
339,
347,
511,
1644,
63,
4266,
63,
16257,
63,
1618,
63,
7866,
63,
14301,
5923,
8,
277,
304,
267,
4027,
275,
7799,
14,
2998,
8,
5413,
14,
21082,
19,
63,
9977,
9,
2728,
4911,
63,
3058,
275,
2400,
2557,
12,
671,
6576,
12,
2329,
1507,
12,
2329,
4631,
12,
876,
4712,
63,
745,
26,
971,
288,
876,
4712,
63,
745,
221,
10631,
4027,
14,
409,
63,
4712,
8,
5413,
14,
22443,
63,
31560,
12,
4911,
63,
3058,
9,
267,
4027,
14,
409,
63,
4712,
63,
4631,
8,
25,
9,
2728,
327,
2494,
3211,
2909,
367,
7240,
25949,
370,
4911,
543,
267,
4027,
14,
912,
63,
4712,
63,
8022,
8,
403,
12,
22296,
14,
29154,
5397,
63,
3022,
9,
2728,
2557,
275,
14147,
3225,
8,
22185,
14,
22647,
12,
1844,
29,
22185,
14,
3657,
12,
3044,
6149,
63,
1100,
29,
3799,
9,
267,
2557,
14,
2242,
342,
267,
2557,
14,
1069,
360,
2970,
297,
15107,
267,
3085,
275,
2557,
14,
25006,
342,
267,
870,
360,
2364,
275,
450,
83,
7,
450,
3085,
14,
739,
1012,
339,
347,
511,
966,
63,
4266,
63,
16257,
63,
1045,
63,
954,
74,
63,
4478,
63,
354,
8,
277,
304,
267,
4027,
275,
7799,
14,
2998,
8,
5413,
14,
21082,
19,
63,
9977,
9,
2728,
4911,
63,
3058,
275,
7146,
5413,
14768,
22595,
8,
4269,
534,
5967,
358,
10631,
4027,
14,
409,
63,
4712,
8,
5413,
14,
22443,
63,
31560,
12,
4911,
63,
3058,
9,
267,
4027,
14,
409,
63,
4712,
63,
4631,
8,
25,
9,
2728,
327,
2494,
3211,
2909,
367,
7240,
25949,
370,
4911,
543,
267,
4027,
14,
912,
63,
4712,
63,
8022,
8,
403,
12,
22296,
14,
29154,
5397,
63,
3022,
9,
2728,
2557,
275,
14147,
3225,
8,
22185,
14,
22647,
12,
1844,
29,
22185,
14,
3657,
12,
3044,
6149,
63,
1100,
29,
3799,
9,
267,
2557,
14,
2242,
342,
267,
2557,
14,
1069,
360,
2970,
297,
15107,
267,
3085,
275,
2557,
14,
25006,
342,
267,
870,
360,
2364,
275,
450,
83,
7,
450,
3085,
14,
739,
1012,
339,
347,
511,
966,
63,
4266,
63,
16257,
63,
1045,
63,
954,
74,
63,
2330,
63,
354,
8,
277,
304,
267,
4027,
275,
7799,
14,
2998,
8,
5413,
14,
21082,
19,
63,
9977,
9,
2728,
327,
23872,
590,
663,
14786,
402,
9104,
6246,
1808,
9104,
5897,
267,
327,
5420,
2863,
536,
267,
4911,
63,
3058,
275,
7146,
5413,
14768,
22595,
8,
4269,
534,
5967,
297,
8105,
1007,
74,
63,
4478,
63,
354,
63,
1431,
29,
797,
9,
398,
4027,
14,
409,
63,
4712,
8,
5413,
14,
22443,
63,
31560,
12,
4911,
63,
3058,
9,
267,
4027,
14,
409,
63,
4712,
63,
4631,
8,
25,
9,
2728,
327,
2494,
3211,
2909,
367,
7240,
25949,
370,
4911,
543,
267,
4027,
14,
912,
63,
4712,
63,
8022,
8,
403,
12,
22296,
14,
29154,
5397,
63,
3022,
9,
2728,
2557,
275,
14147,
3225,
8,
22185,
14,
22647,
12,
1844,
29,
22185,
14,
3657,
12,
3044,
6149,
63,
1100,
29,
3799,
9,
267,
2557,
14
] |
[
3248,
2295,
859,
367,
5222,
71,
14,
1014,
551,
864,
14,
2859,
14,
14921,
2105,
1021,
199,
199,
2713,
22791,
11420,
370,
1852,
282,
8809,
13,
2930,
3217,
11233,
367,
675,
543,
221,
199,
4078,
18,
199,
624,
199,
363,
2502,
363,
275,
298,
48,
1603,
1804,
281,
4835,
87,
334,
840,
4161,
2924,
199,
363,
602,
363,
275,
298,
1690,
15,
614,
15,
713,
2,
199,
363,
7307,
363,
275,
7340,
35,
9,
6029,
27491,
436,
21580,
10859,
559,
7999,
1849,
1097,
382,
2,
199,
363,
1682,
363,
275,
298,
15400,
446,
1937,
5113,
570,
315,
2746,
13,
1896,
2082,
2,
199,
363,
7811,
363,
275,
298,
5663,
1638,
80,
14,
43,
281,
4835,
87,
32,
270,
3003,
14,
645,
14,
3210,
2,
199,
363,
5792,
363,
275,
4505,
1304,
12913,
199,
646,
2050,
199,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
5287,
9,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
646,
2882,
199,
646,
2838,
199,
199,
504,
14296,
492,
7799,
199,
199,
504,
5222,
71,
14,
1014,
551,
864,
14,
396,
492,
22296,
199,
504,
5222,
71,
14,
1014,
551,
864,
14,
2859,
492,
14147,
3225,
199,
504,
5222,
71,
14,
1014,
551,
864,
14,
4266,
63,
7866,
63,
16257,
492,
7146,
5413,
14768,
22595,
421,
199,
533,
1379,
27945,
8,
2796,
14,
1746,
304,
272,
1449,
774,
5222,
71,
14147,
1890,
14147,
3225,
1021,
2344,
339,
347,
511,
614,
63,
1490,
8,
277,
304,
267,
2557,
275,
14147,
3225,
8,
22185,
14,
22647,
12,
1844,
29,
22185,
14,
3657,
9,
267,
2557,
14,
2242,
342,
267,
2557,
14,
1069,
360,
2970,
297,
15107,
267,
3085,
275,
2557,
14,
25006,
342,
267,
870,
360,
2364,
275,
450,
83,
7,
450,
3085,
14,
739,
1012,
267,
2557,
14,
1600,
342,
339,
347,
511,
996,
63,
1490,
63,
15762,
8,
277,
304,
267,
2557,
275,
14147,
3225,
8,
22185,
14,
22647,
12,
1844,
29,
22185,
14,
3657,
18,
9,
267,
291,
14,
7589,
1811,
8,
3450,
14,
705,
12,
2557,
14,
2242,
9,
339,
347,
511,
1644,
63,
4266,
63,
16257,
63,
1618,
63,
7866,
63,
15762,
8,
277,
304,
267,
4027,
275,
7799,
14,
2998,
8,
5413,
14,
21082,
19,
63,
9977,
9,
2728,
347,
4911,
63,
3058,
8,
1631,
12,
671,
6576,
12,
2329,
1507,
12,
2329,
4631,
12,
876,
4712,
63,
745,
304,
7205,
943,
14,
1757,
360,
5413,
9104,
5897,
14786,
3405,
367,
450,
82,
297,
1993,
671,
6576,
14,
362,
63,
5875,
1012,
288,
372,
876,
4712,
63,
745,
221,
10631,
4027,
14,
409,
63,
4712,
8,
5413,
14,
22443,
63,
31560,
12,
4911,
63,
3058,
9,
267,
4027,
14,
409,
63,
4712,
63,
4631,
8,
25,
9,
2728,
327,
2494,
4875,
2909,
446,
4137,
511,
2935,
965,
949,
7240,
25949,
370,
4911,
543,
267,
4027,
14,
912,
63,
4712,
63,
8022,
8,
403,
12,
22296,
14,
15505,
2864,
63,
3022,
9,
2728,
2557,
275,
14147,
3225,
8,
22185,
14,
22647,
12,
1844,
29,
22185,
14,
3657,
12,
3044,
6149,
63,
1100,
29,
3799,
9,
267,
2557,
14,
2242,
342,
18418,
291,
14,
7589,
1811,
8,
5413,
14,
547,
12,
2557,
14,
1069,
12,
283,
2970,
297,
15107,
339,
347,
511,
1644,
63,
4266,
63,
16257,
63,
1618,
63,
7866,
63,
14301,
5923,
8,
277,
304,
267,
4027,
275,
7799,
14,
2998,
8,
5413,
14,
21082,
19,
63,
9977,
9,
2728,
4911,
63,
3058,
275,
2400,
2557,
12,
671,
6576,
12,
2329,
1507,
12,
2329,
4631,
12,
876,
4712,
63,
745,
26,
971,
288,
876,
4712,
63,
745,
221,
10631,
4027,
14,
409,
63,
4712,
8,
5413,
14,
22443,
63,
31560,
12,
4911,
63,
3058,
9,
267,
4027,
14,
409,
63,
4712,
63,
4631,
8,
25,
9,
2728,
327,
2494,
3211,
2909,
367,
7240,
25949,
370,
4911,
543,
267,
4027,
14,
912,
63,
4712,
63,
8022,
8,
403,
12,
22296,
14,
29154,
5397,
63,
3022,
9,
2728,
2557,
275,
14147,
3225,
8,
22185,
14,
22647,
12,
1844,
29,
22185,
14,
3657,
12,
3044,
6149,
63,
1100,
29,
3799,
9,
267,
2557,
14,
2242,
342,
267,
2557,
14,
1069,
360,
2970,
297,
15107,
267,
3085,
275,
2557,
14,
25006,
342,
267,
870,
360,
2364,
275,
450,
83,
7,
450,
3085,
14,
739,
1012,
339,
347,
511,
966,
63,
4266,
63,
16257,
63,
1045,
63,
954,
74,
63,
4478,
63,
354,
8,
277,
304,
267,
4027,
275,
7799,
14,
2998,
8,
5413,
14,
21082,
19,
63,
9977,
9,
2728,
4911,
63,
3058,
275,
7146,
5413,
14768,
22595,
8,
4269,
534,
5967,
358,
10631,
4027,
14,
409,
63,
4712,
8,
5413,
14,
22443,
63,
31560,
12,
4911,
63,
3058,
9,
267,
4027,
14,
409,
63,
4712,
63,
4631,
8,
25,
9,
2728,
327,
2494,
3211,
2909,
367,
7240,
25949,
370,
4911,
543,
267,
4027,
14,
912,
63,
4712,
63,
8022,
8,
403,
12,
22296,
14,
29154,
5397,
63,
3022,
9,
2728,
2557,
275,
14147,
3225,
8,
22185,
14,
22647,
12,
1844,
29,
22185,
14,
3657,
12,
3044,
6149,
63,
1100,
29,
3799,
9,
267,
2557,
14,
2242,
342,
267,
2557,
14,
1069,
360,
2970,
297,
15107,
267,
3085,
275,
2557,
14,
25006,
342,
267,
870,
360,
2364,
275,
450,
83,
7,
450,
3085,
14,
739,
1012,
339,
347,
511,
966,
63,
4266,
63,
16257,
63,
1045,
63,
954,
74,
63,
2330,
63,
354,
8,
277,
304,
267,
4027,
275,
7799,
14,
2998,
8,
5413,
14,
21082,
19,
63,
9977,
9,
2728,
327,
23872,
590,
663,
14786,
402,
9104,
6246,
1808,
9104,
5897,
267,
327,
5420,
2863,
536,
267,
4911,
63,
3058,
275,
7146,
5413,
14768,
22595,
8,
4269,
534,
5967,
297,
8105,
1007,
74,
63,
4478,
63,
354,
63,
1431,
29,
797,
9,
398,
4027,
14,
409,
63,
4712,
8,
5413,
14,
22443,
63,
31560,
12,
4911,
63,
3058,
9,
267,
4027,
14,
409,
63,
4712,
63,
4631,
8,
25,
9,
2728,
327,
2494,
3211,
2909,
367,
7240,
25949,
370,
4911,
543,
267,
4027,
14,
912,
63,
4712,
63,
8022,
8,
403,
12,
22296,
14,
29154,
5397,
63,
3022,
9,
2728,
2557,
275,
14147,
3225,
8,
22185,
14,
22647,
12,
1844,
29,
22185,
14,
3657,
12,
3044,
6149,
63,
1100,
29,
3799,
9,
267,
2557,
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,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
DirkdeDraak/easybuild-framework
|
easybuild/toolchains/__init__.py
|
9
|
1310
|
##
# Copyright 2012-2015 Ghent University
#
# This file is part of EasyBuild,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
# with support of Ghent University (http://ugent.be/hpc),
# the Flemish Supercomputer Centre (VSC) (https://vscentrum.be/nl/en),
# the Hercules foundation (http://www.herculesstichting.be/in_English)
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
#
# http://github.com/hpcugent/easybuild
#
# EasyBuild 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 v2.
#
# EasyBuild 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 EasyBuild. If not, see <http://www.gnu.org/licenses/>.
##
"""
Declaration of toolchains namespace.
@author: Stijn De Weirdt (Ghent University)
@author: Kenneth Hoste (Ghent University)
"""
from pkgutil import extend_path
# we're not the only ones in this namespace
__path__ = extend_path(__path__, __name__)
|
gpl-2.0
|
[
309,
199,
3,
1898,
6029,
13,
7806,
598,
72,
484,
15904,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
30025,
12,
199,
3,
20657,
2737,
701,
314,
869,
4222,
8099,
402,
598,
72,
484,
15904,
334,
1014,
921,
1518,
484,
14,
1235,
15,
72,
2352,
15,
287,
395,
199,
3,
543,
2291,
402,
598,
72,
484,
15904,
334,
1014,
921,
1518,
484,
14,
1235,
15,
72,
2352,
395,
199,
3,
314,
481,
274,
1292,
72,
17897,
23805,
30610,
264,
334,
54,
5153,
9,
334,
2859,
921,
86,
10845,
454,
453,
14,
1235,
15,
7530,
15,
287,
395,
199,
3,
314,
18769,
67,
443,
83,
1911,
425,
334,
1014,
921,
1544,
14,
2523,
67,
443,
83,
270,
1158,
1337,
14,
1235,
15,
262,
63,
19410,
9,
199,
3,
436,
314,
1487,
12493,
402,
662,
25129,
89,
12,
27491,
436,
1010,
889,
4255,
334,
37,
18759,
9,
334,
1014,
921,
1544,
14,
546,
73,
13,
86,
416,
290,
271,
828,
14,
1235,
15,
287,
680,
199,
3,
199,
3,
1455,
921,
5031,
14,
957,
15,
72,
2352,
1518,
484,
15,
13581,
1506,
199,
3,
199,
3,
30025,
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,
373,
18,
14,
199,
3,
199,
3,
30025,
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,
30025,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
309,
199,
624,
199,
17737,
402,
4744,
17419,
3231,
14,
199,
199,
32,
2502,
26,
428,
280,
24016,
1487,
2136,
723,
3583,
334,
39,
72,
484,
15904,
9,
199,
32,
2502,
26,
1804,
287,
685,
273,
869,
736,
266,
334,
39,
72,
484,
15904,
9,
199,
624,
199,
504,
28728,
492,
12247,
63,
515,
199,
199,
3,
781,
3984,
440,
314,
1454,
7869,
315,
642,
3231,
199,
363,
515,
363,
275,
12247,
63,
515,
3460,
515,
3108,
636,
354,
3368,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
1898,
6029,
13,
7806,
598,
72,
484,
15904,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
30025,
12,
199,
3,
20657,
2737,
701,
314,
869,
4222,
8099,
402,
598,
72,
484,
15904,
334,
1014,
921,
1518,
484,
14,
1235,
15,
72,
2352,
15,
287,
395,
199,
3,
543,
2291,
402,
598,
72,
484,
15904,
334,
1014,
921,
1518,
484,
14,
1235,
15,
72,
2352,
395,
199,
3,
314,
481,
274,
1292,
72,
17897,
23805,
30610,
264,
334,
54,
5153,
9,
334,
2859,
921,
86,
10845,
454,
453,
14,
1235,
15,
7530,
15,
287,
395,
199,
3,
314,
18769,
67,
443,
83,
1911,
425,
334,
1014,
921,
1544,
14,
2523,
67,
443,
83,
270,
1158,
1337,
14,
1235,
15,
262,
63,
19410,
9,
199,
3,
436,
314,
1487,
12493,
402,
662,
25129,
89,
12,
27491,
436,
1010,
889,
4255,
334,
37,
18759,
9,
334,
1014,
921,
1544,
14,
546,
73,
13,
86,
416,
290,
271,
828,
14,
1235,
15,
287,
680,
199,
3,
199,
3,
1455,
921,
5031,
14,
957,
15,
72,
2352,
1518,
484,
15,
13581,
1506,
199,
3,
199,
3,
30025,
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,
373,
18,
14,
199,
3,
199,
3,
30025,
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,
30025,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
309,
199,
624,
199,
17737,
402,
4744,
17419,
3231,
14,
199,
199,
32,
2502,
26,
428,
280,
24016,
1487,
2136,
723,
3583,
334,
39,
72,
484,
15904,
9,
199,
32,
2502,
26,
1804,
287,
685,
273,
869,
736,
266,
334,
39,
72,
484,
15904,
9,
199,
624,
199,
504,
28728,
492,
12247,
63,
515,
199,
199,
3,
781,
3984,
440,
314,
1454,
7869,
315,
642,
3231,
199,
363,
515,
363,
275,
12247,
63,
515,
3460,
515,
3108,
636,
354,
3368,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
22rostislav/xhtml2pdf
|
ez_setup.py
|
164
|
12155
|
#!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 os
import shutil
import sys
import tempfile
import tarfile
import optparse
import subprocess
import platform
from distutils import log
try:
from site import USER_SITE
except ImportError:
USER_SITE = None
DEFAULT_VERSION = "1.4.2"
DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/"
def _python_cmd(*args):
args = (sys.executable,) + args
return subprocess.call(args) == 0
def _check_call_py24(cmd, *args, **kwargs):
res = subprocess.call(cmd, *args, **kwargs)
class CalledProcessError(Exception):
pass
if not res == 0:
msg = "Command '%s' return non-zero exit status %d" % (cmd, res)
raise CalledProcessError(msg)
vars(subprocess).setdefault('check_call', _check_call_py24)
def _install(tarball, install_args=()):
# extracting the tarball
tmpdir = tempfile.mkdtemp()
log.warn('Extracting in %s', tmpdir)
old_wd = os.getcwd()
try:
os.chdir(tmpdir)
tar = tarfile.open(tarball)
_extractall(tar)
tar.close()
# going in the directory
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
os.chdir(subdir)
log.warn('Now working in %s', subdir)
# installing
log.warn('Installing Setuptools')
if not _python_cmd('setup.py', 'install', *install_args):
log.warn('Something went wrong during the installation.')
log.warn('See the error message above.')
# exitcode will be 2
return 2
finally:
os.chdir(old_wd)
shutil.rmtree(tmpdir)
def _build_egg(egg, tarball, to_dir):
# extracting the tarball
tmpdir = tempfile.mkdtemp()
log.warn('Extracting in %s', tmpdir)
old_wd = os.getcwd()
try:
os.chdir(tmpdir)
tar = tarfile.open(tarball)
_extractall(tar)
tar.close()
# going in the directory
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
os.chdir(subdir)
log.warn('Now working in %s', subdir)
# building an egg
log.warn('Building a Setuptools egg in %s', to_dir)
_python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir)
finally:
os.chdir(old_wd)
shutil.rmtree(tmpdir)
# returning the result
log.warn(egg)
if not os.path.exists(egg):
raise IOError('Could not build the egg.')
def _do_download(version, download_base, to_dir, download_delay):
egg = os.path.join(to_dir, 'setuptools-%s-py%d.%d.egg'
% (version, sys.version_info[0], sys.version_info[1]))
if not os.path.exists(egg):
tarball = download_setuptools(version, download_base,
to_dir, download_delay)
_build_egg(egg, tarball, to_dir)
sys.path.insert(0, egg)
# Remove previously-imported pkg_resources if present (see
# https://bitbucket.org/pypa/setuptools/pull-request/7/ for details).
if 'pkg_resources' in sys.modules:
del sys.modules['pkg_resources']
import setuptools
setuptools.bootstrap_install_from = egg
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
to_dir=os.curdir, download_delay=15):
# making sure we use the absolute path
to_dir = os.path.abspath(to_dir)
was_imported = 'pkg_resources' in sys.modules or \
'setuptools' in sys.modules
try:
import pkg_resources
except ImportError:
return _do_download(version, download_base, to_dir, download_delay)
try:
pkg_resources.require("setuptools>=" + version)
return
except pkg_resources.VersionConflict:
e = sys.exc_info()[1]
if was_imported:
sys.stderr.write(
"The required version of setuptools (>=%s) is not available,\n"
"and can't be installed while this script is running. Please\n"
"install a more recent version first, using\n"
"'easy_install -U setuptools'."
"\n\n(Currently using %r)\n" % (version, e.args[0]))
sys.exit(2)
else:
del pkg_resources, sys.modules['pkg_resources'] # reload ok
return _do_download(version, download_base, to_dir,
download_delay)
except pkg_resources.DistributionNotFound:
return _do_download(version, download_base, to_dir,
download_delay)
def _clean_check(cmd, target):
"""
Run the command to download target. If the command fails, clean up before
re-raising the error.
"""
try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError:
if os.access(target, os.F_OK):
os.unlink(target)
raise
def download_file_powershell(url, target):
"""
Download the file at url to target using Powershell (which will validate
trust). Raise an exception if the command cannot complete.
"""
target = os.path.abspath(target)
cmd = [
'powershell',
'-Command',
"(new-object System.Net.WebClient).DownloadFile(%(url)r, %(target)r)" % vars(),
]
_clean_check(cmd, target)
def has_powershell():
if platform.system() != 'Windows':
return False
cmd = ['powershell', '-Command', 'echo test']
devnull = open(os.path.devnull, 'wb')
try:
try:
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
except:
return False
finally:
devnull.close()
return True
download_file_powershell.viable = has_powershell
def download_file_curl(url, target):
cmd = ['curl', url, '--silent', '--output', target]
_clean_check(cmd, target)
def has_curl():
cmd = ['curl', '--version']
devnull = open(os.path.devnull, 'wb')
try:
try:
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
except:
return False
finally:
devnull.close()
return True
download_file_curl.viable = has_curl
def download_file_wget(url, target):
cmd = ['wget', url, '--quiet', '--output-document', target]
_clean_check(cmd, target)
def has_wget():
cmd = ['wget', '--version']
devnull = open(os.path.devnull, 'wb')
try:
try:
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
except:
return False
finally:
devnull.close()
return True
download_file_wget.viable = has_wget
def download_file_insecure(url, target):
"""
Use Python to download the file, even though it cannot authenticate the
connection.
"""
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
src = dst = None
try:
src = urlopen(url)
# Read/write all in one block, so we don't create a corrupt file
# if the download is interrupted.
data = src.read()
dst = open(target, "wb")
dst.write(data)
finally:
if src:
src.close()
if dst:
dst.close()
download_file_insecure.viable = lambda: True
def get_best_downloader():
downloaders = [
download_file_powershell,
download_file_curl,
download_file_wget,
download_file_insecure,
]
for dl in downloaders:
if dl.viable():
return dl
def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
to_dir=os.curdir, delay=15,
downloader_factory=get_best_downloader):
"""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.
``downloader_factory`` should be a function taking no arguments and
returning a function for downloading a URL to a target.
"""
# making sure we use the absolute path
to_dir = os.path.abspath(to_dir)
tgz_name = "setuptools-%s.tar.gz" % version
url = download_base + tgz_name
saveto = os.path.join(to_dir, tgz_name)
if not os.path.exists(saveto): # Avoid repeated downloads
log.warn("Downloading %s", url)
downloader = downloader_factory()
downloader(url, saveto)
return os.path.realpath(saveto)
def _extractall(self, path=".", members=None):
"""Extract all members from the archive to the current working
directory and set owner, modification time and permissions on
directories afterwards. `path' specifies a different directory
to extract to. `members' is optional and must be a subset of the
list returned by getmembers().
"""
import copy
import operator
from tarfile import ExtractError
directories = []
if members is None:
members = self
for tarinfo in members:
if tarinfo.isdir():
# Extract directories with a safe mode.
directories.append(tarinfo)
tarinfo = copy.copy(tarinfo)
tarinfo.mode = 448 # decimal for oct 0700
self.extract(tarinfo, path)
# Reverse sort directories.
if sys.version_info < (2, 4):
def sorter(dir1, dir2):
return cmp(dir1.name, dir2.name)
directories.sort(sorter)
directories.reverse()
else:
directories.sort(key=operator.attrgetter('name'), reverse=True)
# Set correct owner, mtime and filemode on directories.
for tarinfo in directories:
dirpath = os.path.join(path, tarinfo.name)
try:
self.chown(tarinfo, dirpath)
self.utime(tarinfo, dirpath)
self.chmod(tarinfo, dirpath)
except ExtractError:
e = sys.exc_info()[1]
if self.errorlevel > 1:
raise
else:
self._dbg(1, "tarfile: %s" % e)
def _build_install_args(options):
"""
Build the arguments to 'python setup.py install' on the setuptools package
"""
install_args = []
if options.user_install:
if sys.version_info < (2, 6):
log.warn("--user requires Python 2.6 or later")
raise SystemExit(1)
install_args.append('--user')
return install_args
def _parse_args():
"""
Parse the command line for options
"""
parser = optparse.OptionParser()
parser.add_option(
'--user', dest='user_install', action='store_true', default=False,
help='install in user site package (requires Python 2.6 or later)')
parser.add_option(
'--download-base', dest='download_base', metavar="URL",
default=DEFAULT_URL,
help='alternative URL from where to download the setuptools package')
parser.add_option(
'--insecure', dest='downloader_factory', action='store_const',
const=lambda: download_file_insecure, default=get_best_downloader,
help='Use internal, non-validating downloader'
)
options, args = parser.parse_args()
# positional arguments are ignored
return options
def main(version=DEFAULT_VERSION):
"""Install or upgrade setuptools and EasyInstall"""
options = _parse_args()
tarball = download_setuptools(download_base=options.download_base,
downloader_factory=options.downloader_factory)
return _install(tarball, _build_install_args(options))
if __name__ == '__main__':
sys.exit(main())
|
apache-2.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,
747,
199,
646,
5145,
199,
646,
984,
199,
646,
5549,
199,
646,
13608,
199,
646,
8691,
199,
646,
3873,
199,
646,
4298,
199,
199,
504,
7065,
492,
943,
199,
199,
893,
26,
272,
687,
4770,
492,
13044,
63,
7917,
199,
2590,
3545,
26,
272,
13044,
63,
7917,
275,
488,
199,
199,
3472,
63,
4612,
275,
298,
17,
14,
20,
14,
18,
2,
199,
3472,
63,
2632,
275,
298,
2859,
921,
17343,
14,
1548,
14,
1308,
15,
5154,
15,
1365,
15,
83,
15,
13623,
6687,
199,
199,
318,
485,
1548,
63,
1760,
2031,
589,
304,
272,
1249,
275,
334,
1274,
14,
5904,
4258,
435,
1249,
272,
372,
3873,
14,
1250,
8,
589,
9,
508,
378,
199,
199,
318,
485,
1074,
63,
1250,
63,
647,
1194,
8,
1760,
12,
627,
589,
12,
1011,
958,
304,
272,
522,
275,
3873,
14,
1250,
8,
1760,
12,
627,
589,
12,
1011,
958,
9,
272,
1021,
12295,
19148,
8,
1726,
304,
267,
986,
272,
340,
440,
522,
508,
378,
26,
267,
1499,
275,
298,
3110,
1543,
83,
7,
372,
2222,
13,
4262,
4458,
2004,
450,
68,
2,
450,
334,
1760,
12,
522,
9,
267,
746,
12295,
19148,
8,
1328,
9,
199,
2936,
8,
5781,
680,
5486,
360,
1074,
63,
1250,
297,
485,
1074,
63,
1250,
63,
647,
1194,
9,
199,
199,
318,
485,
3174,
8,
18829,
12,
3907,
63,
589,
23603,
272,
327,
30137,
314,
17641,
272,
12885,
275,
5549,
14,
11983,
342,
272,
943,
14,
4050,
360,
12147,
316,
315,
450,
83,
297,
12885,
9,
272,
2269,
63,
2989,
275,
747,
14,
9458,
342,
272,
862,
26,
267,
747,
14,
8563,
8,
8616,
9,
267,
5330,
275,
13608,
14,
1490,
8,
18829,
9,
267,
485,
5005,
452,
8,
5369,
9,
267,
5330,
14,
1600,
342,
398,
327,
9995,
315,
314,
2082,
267,
15488,
275,
747,
14,
515,
14,
904,
8,
8616,
12,
747,
14,
7374,
8,
8616,
2788,
16,
566,
267,
747,
14,
8563,
8,
10622,
9,
267,
943,
14,
4050,
360,
14351,
6449,
315,
450,
83,
297,
15488,
9,
398,
327,
22200,
267,
943,
14,
4050,
360,
31376,
12439,
2537,
358,
267,
340,
440,
485,
1548,
63,
1760,
360,
2758,
14,
647,
297,
283,
3174,
297,
627,
3174,
63,
589,
304,
288,
943,
14,
4050,
360,
20641,
22396,
6835,
5309,
314,
12096,
2659,
288,
943,
14,
4050,
360,
9295,
314,
1125,
1245,
3432,
2659,
288,
327,
4458,
600,
911,
506,
499,
288,
372,
499,
272,
3753,
26,
267,
747,
14,
8563,
8,
1753,
63,
2989,
9,
267,
5145,
14,
9242,
8,
8616,
9,
421,
199,
318,
485,
1506,
63,
5799,
8,
5799,
12,
17641,
12,
370,
63,
694,
304,
272,
327,
30137,
314,
17641,
272,
12885,
275,
5549,
14,
11983,
342,
272,
943,
14,
4050,
360,
12147,
316,
315,
450,
83,
297,
12885,
9,
272,
2269,
63,
2989,
275,
747,
14,
9458,
342,
272,
862,
26,
267,
747,
14,
8563,
8,
8616,
9,
267,
5330,
275,
13608,
14,
1490,
8,
18829,
9,
267,
485,
5005,
452,
8,
5369,
9,
267,
5330,
14,
1600,
342,
398,
327,
9995,
315,
314,
2082,
267,
15488,
275,
747,
14,
515,
14,
904,
8,
8616,
12,
747,
14,
7374,
8,
8616,
2788,
16,
566,
267,
747,
14,
8563,
8,
10622,
9,
267,
943,
14,
4050,
360,
14351,
6449,
315,
450,
83,
297,
15488,
9,
398,
327,
10015,
376,
11393,
267,
943,
14,
4050,
360,
16461,
282,
12439,
2537,
11393,
315,
450,
83,
297,
370,
63,
694,
9,
267,
485,
1548,
63,
1760,
360,
2758,
14,
647,
297,
2475,
81,
297,
283,
17403,
63,
5799,
297,
2850,
2686,
13,
694,
297,
370,
63,
694,
9,
339,
3753,
26,
267,
747,
14,
8563,
8,
1753,
63,
2989,
9,
267,
5145,
14,
9242,
8,
8616,
9,
272,
327,
8152,
314,
754,
272,
943,
14,
4050,
8,
5799,
9,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
5799,
304,
267,
746,
5925,
360,
6531,
440,
1900,
314,
11393,
2659,
421,
199,
318,
485,
1117,
63,
4249,
8,
1023,
12,
5235,
63,
1095,
12,
370,
63,
694,
12,
5235,
63,
5814,
304,
272,
11393,
275,
747,
14,
515,
14,
904,
8,
475,
63,
694,
12,
283,
13623,
3295,
83,
13,
647,
5,
68,
4111,
68,
14,
5799,
7,
2432,
450,
334,
1023,
12,
984,
14,
1023,
63,
815,
59,
16,
467,
984,
14,
1023,
63,
815,
59,
17,
2459,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
5799,
304,
267,
17641,
275,
5235,
63,
13623,
8,
1023,
12,
5235,
63,
1095,
12,
4228,
370,
63,
694,
12,
5235,
63,
5814,
9,
267,
485,
1506,
63,
5799,
8,
5799,
12,
17641,
12,
370,
63,
694,
9,
272,
984,
14,
515,
14,
3176,
8,
16,
12,
11393,
9,
339,
327,
5852,
10889,
13,
17932,
5496,
63,
4435,
340,
3451,
334,
3239,
272,
327,
4178,
921,
25668,
14,
1308,
15,
647,
387,
15,
13623,
15,
9302,
13,
1069,
15,
23,
15,
367,
2436,
680,
272,
340,
283,
4600,
63,
4435,
7,
315,
984,
14,
3112,
26,
267,
2150,
984,
14,
3112,
459,
4600,
63,
4435,
418,
339,
492,
9116,
272,
9116,
14,
11146,
63,
3174,
63,
504,
275,
11393,
421,
199,
318,
675,
63,
13623,
8,
1023,
29,
3472,
63,
4612,
12,
5235,
63,
1095,
29,
3472,
63,
2632,
12,
673,
370,
63,
694,
29,
736,
14,
15594,
12,
5235,
63,
5814,
29,
1046,
304,
272,
327,
10663,
3238,
781,
675,
314,
3679,
931,
272,
370,
63,
694,
275,
747,
14,
515
] |
[
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,
747,
199,
646,
5145,
199,
646,
984,
199,
646,
5549,
199,
646,
13608,
199,
646,
8691,
199,
646,
3873,
199,
646,
4298,
199,
199,
504,
7065,
492,
943,
199,
199,
893,
26,
272,
687,
4770,
492,
13044,
63,
7917,
199,
2590,
3545,
26,
272,
13044,
63,
7917,
275,
488,
199,
199,
3472,
63,
4612,
275,
298,
17,
14,
20,
14,
18,
2,
199,
3472,
63,
2632,
275,
298,
2859,
921,
17343,
14,
1548,
14,
1308,
15,
5154,
15,
1365,
15,
83,
15,
13623,
6687,
199,
199,
318,
485,
1548,
63,
1760,
2031,
589,
304,
272,
1249,
275,
334,
1274,
14,
5904,
4258,
435,
1249,
272,
372,
3873,
14,
1250,
8,
589,
9,
508,
378,
199,
199,
318,
485,
1074,
63,
1250,
63,
647,
1194,
8,
1760,
12,
627,
589,
12,
1011,
958,
304,
272,
522,
275,
3873,
14,
1250,
8,
1760,
12,
627,
589,
12,
1011,
958,
9,
272,
1021,
12295,
19148,
8,
1726,
304,
267,
986,
272,
340,
440,
522,
508,
378,
26,
267,
1499,
275,
298,
3110,
1543,
83,
7,
372,
2222,
13,
4262,
4458,
2004,
450,
68,
2,
450,
334,
1760,
12,
522,
9,
267,
746,
12295,
19148,
8,
1328,
9,
199,
2936,
8,
5781,
680,
5486,
360,
1074,
63,
1250,
297,
485,
1074,
63,
1250,
63,
647,
1194,
9,
199,
199,
318,
485,
3174,
8,
18829,
12,
3907,
63,
589,
23603,
272,
327,
30137,
314,
17641,
272,
12885,
275,
5549,
14,
11983,
342,
272,
943,
14,
4050,
360,
12147,
316,
315,
450,
83,
297,
12885,
9,
272,
2269,
63,
2989,
275,
747,
14,
9458,
342,
272,
862,
26,
267,
747,
14,
8563,
8,
8616,
9,
267,
5330,
275,
13608,
14,
1490,
8,
18829,
9,
267,
485,
5005,
452,
8,
5369,
9,
267,
5330,
14,
1600,
342,
398,
327,
9995,
315,
314,
2082,
267,
15488,
275,
747,
14,
515,
14,
904,
8,
8616,
12,
747,
14,
7374,
8,
8616,
2788,
16,
566,
267,
747,
14,
8563,
8,
10622,
9,
267,
943,
14,
4050,
360,
14351,
6449,
315,
450,
83,
297,
15488,
9,
398,
327,
22200,
267,
943,
14,
4050,
360,
31376,
12439,
2537,
358,
267,
340,
440,
485,
1548,
63,
1760,
360,
2758,
14,
647,
297,
283,
3174,
297,
627,
3174,
63,
589,
304,
288,
943,
14,
4050,
360,
20641,
22396,
6835,
5309,
314,
12096,
2659,
288,
943,
14,
4050,
360,
9295,
314,
1125,
1245,
3432,
2659,
288,
327,
4458,
600,
911,
506,
499,
288,
372,
499,
272,
3753,
26,
267,
747,
14,
8563,
8,
1753,
63,
2989,
9,
267,
5145,
14,
9242,
8,
8616,
9,
421,
199,
318,
485,
1506,
63,
5799,
8,
5799,
12,
17641,
12,
370,
63,
694,
304,
272,
327,
30137,
314,
17641,
272,
12885,
275,
5549,
14,
11983,
342,
272,
943,
14,
4050,
360,
12147,
316,
315,
450,
83,
297,
12885,
9,
272,
2269,
63,
2989,
275,
747,
14,
9458,
342,
272,
862,
26,
267,
747,
14,
8563,
8,
8616,
9,
267,
5330,
275,
13608,
14,
1490,
8,
18829,
9,
267,
485,
5005,
452,
8,
5369,
9,
267,
5330,
14,
1600,
342,
398,
327,
9995,
315,
314,
2082,
267,
15488,
275,
747,
14,
515,
14,
904,
8,
8616,
12,
747,
14,
7374,
8,
8616,
2788,
16,
566,
267,
747,
14,
8563,
8,
10622,
9,
267,
943,
14,
4050,
360,
14351,
6449,
315,
450,
83,
297,
15488,
9,
398,
327,
10015,
376,
11393,
267,
943,
14,
4050,
360,
16461,
282,
12439,
2537,
11393,
315,
450,
83,
297,
370,
63,
694,
9,
267,
485,
1548,
63,
1760,
360,
2758,
14,
647,
297,
2475,
81,
297,
283,
17403,
63,
5799,
297,
2850,
2686,
13,
694,
297,
370,
63,
694,
9,
339,
3753,
26,
267,
747,
14,
8563,
8,
1753,
63,
2989,
9,
267,
5145,
14,
9242,
8,
8616,
9,
272,
327,
8152,
314,
754,
272,
943,
14,
4050,
8,
5799,
9,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
5799,
304,
267,
746,
5925,
360,
6531,
440,
1900,
314,
11393,
2659,
421,
199,
318,
485,
1117,
63,
4249,
8,
1023,
12,
5235,
63,
1095,
12,
370,
63,
694,
12,
5235,
63,
5814,
304,
272,
11393,
275,
747,
14,
515,
14,
904,
8,
475,
63,
694,
12,
283,
13623,
3295,
83,
13,
647,
5,
68,
4111,
68,
14,
5799,
7,
2432,
450,
334,
1023,
12,
984,
14,
1023,
63,
815,
59,
16,
467,
984,
14,
1023,
63,
815,
59,
17,
2459,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
5799,
304,
267,
17641,
275,
5235,
63,
13623,
8,
1023,
12,
5235,
63,
1095,
12,
4228,
370,
63,
694,
12,
5235,
63,
5814,
9,
267,
485,
1506,
63,
5799,
8,
5799,
12,
17641,
12,
370,
63,
694,
9,
272,
984,
14,
515,
14,
3176,
8,
16,
12,
11393,
9,
339,
327,
5852,
10889,
13,
17932,
5496,
63,
4435,
340,
3451,
334,
3239,
272,
327,
4178,
921,
25668,
14,
1308,
15,
647,
387,
15,
13623,
15,
9302,
13,
1069,
15,
23,
15,
367,
2436,
680,
272,
340,
283,
4600,
63,
4435,
7,
315,
984,
14,
3112,
26,
267,
2150,
984,
14,
3112,
459,
4600,
63,
4435,
418,
339,
492,
9116,
272,
9116,
14,
11146,
63,
3174,
63,
504,
275,
11393,
421,
199,
318,
675,
63,
13623,
8,
1023,
29,
3472,
63,
4612,
12,
5235,
63,
1095,
29,
3472,
63,
2632,
12,
673,
370,
63,
694,
29,
736,
14,
15594,
12,
5235,
63,
5814,
29,
1046,
304,
272,
327,
10663,
3238,
781,
675,
314,
3679,
931,
272,
370,
63,
694,
275,
747,
14,
515,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wxkdesky/phantomjs
|
src/qt/qtwebkit/Tools/Scripts/webkitpy/common/thread/threadedmessagequeue_unittest.py
|
124
|
2423
|
# Copyright (C) 2010 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import unittest2 as unittest
from webkitpy.common.thread.threadedmessagequeue import ThreadedMessageQueue
class ThreadedMessageQueueTest(unittest.TestCase):
def test_basic(self):
queue = ThreadedMessageQueue()
queue.post("Hello")
queue.post("There")
(messages, is_running) = queue.take_all()
self.assertEqual(messages, ["Hello", "There"])
self.assertTrue(is_running)
(messages, is_running) = queue.take_all()
self.assertEqual(messages, [])
self.assertTrue(is_running)
queue.post("More")
queue.stop()
queue.post("Messages")
(messages, is_running) = queue.take_all()
self.assertEqual(messages, ["More", "Messages"])
self.assertFalse(is_running)
(messages, is_running) = queue.take_all()
self.assertEqual(messages, [])
self.assertFalse(is_running)
|
bsd-3-clause
|
[
3,
1898,
334,
35,
9,
7129,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
259,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
2882,
18,
465,
2882,
199,
199,
504,
18007,
14,
2330,
14,
2671,
14,
19710,
1188,
1825,
492,
3868,
11698,
2209,
3737,
199,
199,
533,
3868,
11698,
2209,
3737,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
4316,
8,
277,
304,
267,
4126,
275,
3868,
11698,
2209,
3737,
342,
267,
4126,
14,
1932,
480,
6257,
531,
267,
4126,
14,
1932,
480,
10924,
531,
267,
334,
3431,
12,
365,
63,
5720,
9,
275,
4126,
14,
11066,
63,
452,
342,
267,
291,
14,
629,
8,
3431,
12,
2097,
6257,
401,
298,
10924,
3135,
267,
291,
14,
1815,
8,
374,
63,
5720,
9,
267,
334,
3431,
12,
365,
63,
5720,
9,
275,
4126,
14,
11066,
63,
452,
342,
267,
291,
14,
629,
8,
3431,
12,
3073,
267,
291,
14,
1815,
8,
374,
63,
5720,
9,
267,
4126,
14,
1932,
480,
11053,
531,
267,
4126,
14,
2379,
342,
267,
4126,
14,
1932,
480,
14508,
531,
267,
334,
3431,
12,
365,
63,
5720,
9,
275,
4126,
14,
11066,
63,
452,
342,
267,
291,
14,
629,
8,
3431,
12,
2097,
11053,
401,
298,
14508,
3135,
267,
291,
14,
3334,
8,
374,
63,
5720,
9,
267,
334,
3431,
12,
365,
63,
5720,
9,
275,
4126,
14,
11066,
63,
452,
342,
267,
291,
14,
629,
8,
3431,
12,
3073,
267,
291,
14,
3334,
8,
374,
63,
5720,
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
] |
[
1898,
334,
35,
9,
7129,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
259,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
2882,
18,
465,
2882,
199,
199,
504,
18007,
14,
2330,
14,
2671,
14,
19710,
1188,
1825,
492,
3868,
11698,
2209,
3737,
199,
199,
533,
3868,
11698,
2209,
3737,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
4316,
8,
277,
304,
267,
4126,
275,
3868,
11698,
2209,
3737,
342,
267,
4126,
14,
1932,
480,
6257,
531,
267,
4126,
14,
1932,
480,
10924,
531,
267,
334,
3431,
12,
365,
63,
5720,
9,
275,
4126,
14,
11066,
63,
452,
342,
267,
291,
14,
629,
8,
3431,
12,
2097,
6257,
401,
298,
10924,
3135,
267,
291,
14,
1815,
8,
374,
63,
5720,
9,
267,
334,
3431,
12,
365,
63,
5720,
9,
275,
4126,
14,
11066,
63,
452,
342,
267,
291,
14,
629,
8,
3431,
12,
3073,
267,
291,
14,
1815,
8,
374,
63,
5720,
9,
267,
4126,
14,
1932,
480,
11053,
531,
267,
4126,
14,
2379,
342,
267,
4126,
14,
1932,
480,
14508,
531,
267,
334,
3431,
12,
365,
63,
5720,
9,
275,
4126,
14,
11066,
63,
452,
342,
267,
291,
14,
629,
8,
3431,
12,
2097,
11053,
401,
298,
14508,
3135,
267,
291,
14,
3334,
8,
374,
63,
5720,
9,
267,
334,
3431,
12,
365,
63,
5720,
9,
275,
4126,
14,
11066,
63,
452,
342,
267,
291,
14,
629,
8,
3431,
12,
3073,
267,
291,
14,
3334,
8,
374,
63,
5720,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nzavagli/UnrealPy
|
UnrealPyEmbed/Development/Python/2015.08.07-Python2710-x64-Source-vs2015/Python27/Source/Python-2.7.10/Lib/idlelib/HyperParser.py
|
36
|
10496
|
"""Provide advanced parsing abilities for ParenMatch and other extensions.
HyperParser uses PyParser. PyParser mostly gives information on the
proper indentation of code. HyperParser gives additional information on
the structure of code.
"""
import string
import keyword
from idlelib import PyParse
class HyperParser:
def __init__(self, editwin, index):
"To initialize, analyze the surroundings of the given index."
self.editwin = editwin
self.text = text = editwin.text
parser = PyParse.Parser(editwin.indentwidth, editwin.tabwidth)
def index2line(index):
return int(float(index))
lno = index2line(text.index(index))
if not editwin.context_use_ps1:
for context in editwin.num_context_lines:
startat = max(lno - context, 1)
startatindex = repr(startat) + ".0"
stopatindex = "%d.end" % lno
# We add the newline because PyParse requires a newline
# at end. We add a space so that index won't be at end
# of line, so that its status will be the same as the
# char before it, if should.
parser.set_str(text.get(startatindex, stopatindex)+' \n')
bod = parser.find_good_parse_start(
editwin._build_char_in_string_func(startatindex))
if bod is not None or startat == 1:
break
parser.set_lo(bod or 0)
else:
r = text.tag_prevrange("console", index)
if r:
startatindex = r[1]
else:
startatindex = "1.0"
stopatindex = "%d.end" % lno
# We add the newline because PyParse requires it. We add a
# space so that index won't be at end of line, so that its
# status will be the same as the char before it, if should.
parser.set_str(text.get(startatindex, stopatindex)+' \n')
parser.set_lo(0)
# We want what the parser has, minus the last newline and space.
self.rawtext = parser.str[:-2]
# Parser.str apparently preserves the statement we are in, so
# that stopatindex can be used to synchronize the string with
# the text box indices.
self.stopatindex = stopatindex
self.bracketing = parser.get_last_stmt_bracketing()
# find which pairs of bracketing are openers. These always
# correspond to a character of rawtext.
self.isopener = [i>0 and self.bracketing[i][1] >
self.bracketing[i-1][1]
for i in range(len(self.bracketing))]
self.set_index(index)
def set_index(self, index):
"""Set the index to which the functions relate.
The index must be in the same statement.
"""
indexinrawtext = (len(self.rawtext) -
len(self.text.get(index, self.stopatindex)))
if indexinrawtext < 0:
raise ValueError("Index %s precedes the analyzed statement"
% index)
self.indexinrawtext = indexinrawtext
# find the rightmost bracket to which index belongs
self.indexbracket = 0
while (self.indexbracket < len(self.bracketing)-1 and
self.bracketing[self.indexbracket+1][0] < self.indexinrawtext):
self.indexbracket += 1
if (self.indexbracket < len(self.bracketing)-1 and
self.bracketing[self.indexbracket+1][0] == self.indexinrawtext and
not self.isopener[self.indexbracket+1]):
self.indexbracket += 1
def is_in_string(self):
"""Is the index given to the HyperParser in a string?"""
# The bracket to which we belong should be an opener.
# If it's an opener, it has to have a character.
return (self.isopener[self.indexbracket] and
self.rawtext[self.bracketing[self.indexbracket][0]]
in ('"', "'"))
def is_in_code(self):
"""Is the index given to the HyperParser in normal code?"""
return (not self.isopener[self.indexbracket] or
self.rawtext[self.bracketing[self.indexbracket][0]]
not in ('#', '"', "'"))
def get_surrounding_brackets(self, openers='([{', mustclose=False):
"""Return bracket indexes or None.
If the index given to the HyperParser is surrounded by a
bracket defined in openers (or at least has one before it),
return the indices of the opening bracket and the closing
bracket (or the end of line, whichever comes first).
If it is not surrounded by brackets, or the end of line comes
before the closing bracket and mustclose is True, returns None.
"""
bracketinglevel = self.bracketing[self.indexbracket][1]
before = self.indexbracket
while (not self.isopener[before] or
self.rawtext[self.bracketing[before][0]] not in openers or
self.bracketing[before][1] > bracketinglevel):
before -= 1
if before < 0:
return None
bracketinglevel = min(bracketinglevel, self.bracketing[before][1])
after = self.indexbracket + 1
while (after < len(self.bracketing) and
self.bracketing[after][1] >= bracketinglevel):
after += 1
beforeindex = self.text.index("%s-%dc" %
(self.stopatindex, len(self.rawtext)-self.bracketing[before][0]))
if (after >= len(self.bracketing) or
self.bracketing[after][0] > len(self.rawtext)):
if mustclose:
return None
afterindex = self.stopatindex
else:
# We are after a real char, so it is a ')' and we give the
# index before it.
afterindex = self.text.index(
"%s-%dc" % (self.stopatindex,
len(self.rawtext)-(self.bracketing[after][0]-1)))
return beforeindex, afterindex
# Ascii chars that may be in a white space
_whitespace_chars = " \t\n\\"
# Ascii chars that may be in an identifier
_id_chars = string.ascii_letters + string.digits + "_"
# Ascii chars that may be the first char of an identifier
_id_first_chars = string.ascii_letters + "_"
# Given a string and pos, return the number of chars in the
# identifier which ends at pos, or 0 if there is no such one. Saved
# words are not identifiers.
def _eat_identifier(self, str, limit, pos):
i = pos
while i > limit and str[i-1] in self._id_chars:
i -= 1
if (i < pos and (str[i] not in self._id_first_chars or
keyword.iskeyword(str[i:pos]))):
i = pos
return pos - i
def get_expression(self):
"""Return a string with the Python expression which ends at the
given index, which is empty if there is no real one.
"""
if not self.is_in_code():
raise ValueError("get_expression should only be called"
"if index is inside a code.")
rawtext = self.rawtext
bracketing = self.bracketing
brck_index = self.indexbracket
brck_limit = bracketing[brck_index][0]
pos = self.indexinrawtext
last_identifier_pos = pos
postdot_phase = True
while 1:
# Eat whitespaces, comments, and if postdot_phase is False - a dot
while 1:
if pos>brck_limit and rawtext[pos-1] in self._whitespace_chars:
# Eat a whitespace
pos -= 1
elif (not postdot_phase and
pos > brck_limit and rawtext[pos-1] == '.'):
# Eat a dot
pos -= 1
postdot_phase = True
# The next line will fail if we are *inside* a comment,
# but we shouldn't be.
elif (pos == brck_limit and brck_index > 0 and
rawtext[bracketing[brck_index-1][0]] == '#'):
# Eat a comment
brck_index -= 2
brck_limit = bracketing[brck_index][0]
pos = bracketing[brck_index+1][0]
else:
# If we didn't eat anything, quit.
break
if not postdot_phase:
# We didn't find a dot, so the expression end at the
# last identifier pos.
break
ret = self._eat_identifier(rawtext, brck_limit, pos)
if ret:
# There is an identifier to eat
pos = pos - ret
last_identifier_pos = pos
# Now, to continue the search, we must find a dot.
postdot_phase = False
# (the loop continues now)
elif pos == brck_limit:
# We are at a bracketing limit. If it is a closing
# bracket, eat the bracket, otherwise, stop the search.
level = bracketing[brck_index][1]
while brck_index > 0 and bracketing[brck_index-1][1] > level:
brck_index -= 1
if bracketing[brck_index][0] == brck_limit:
# We were not at the end of a closing bracket
break
pos = bracketing[brck_index][0]
brck_index -= 1
brck_limit = bracketing[brck_index][0]
last_identifier_pos = pos
if rawtext[pos] in "([":
# [] and () may be used after an identifier, so we
# continue. postdot_phase is True, so we don't allow a dot.
pass
else:
# We can't continue after other types of brackets
if rawtext[pos] in "'\"":
# Scan a string prefix
while pos > 0 and rawtext[pos - 1] in "rRbBuU":
pos -= 1
last_identifier_pos = pos
break
else:
# We've found an operator or something.
break
return rawtext[last_identifier_pos:self.indexinrawtext]
if __name__ == '__main__':
import unittest
unittest.main('idlelib.idle_test.test_hyperparser', verbosity=2)
|
mit
|
[
624,
25107,
19472,
6057,
2236,
5462,
367,
10164,
828,
4486,
436,
1163,
5478,
14,
199,
199,
18727,
2842,
4440,
1611,
2842,
14,
221,
1611,
2842,
19762,
10557,
2556,
641,
314,
199,
28314,
14311,
402,
1233,
14,
221,
21344,
2842,
10557,
4722,
2556,
641,
199,
1589,
5523,
402,
1233,
14,
199,
624,
199,
199,
646,
1059,
199,
646,
4252,
199,
504,
15072,
773,
492,
1611,
4003,
199,
199,
533,
21344,
2842,
26,
339,
347,
636,
826,
721,
277,
12,
5283,
2676,
12,
1478,
304,
267,
298,
1378,
8265,
12,
19897,
314,
6296,
2363,
780,
402,
314,
1627,
1478,
2122,
398,
291,
14,
3773,
2676,
275,
5283,
2676,
267,
291,
14,
505,
275,
1318,
275,
5283,
2676,
14,
505,
398,
1798,
275,
1611,
4003,
14,
2842,
8,
3773,
2676,
14,
3724,
2063,
12,
5283,
2676,
14,
2902,
2063,
9,
398,
347,
1478,
18,
604,
8,
1080,
304,
288,
372,
1109,
8,
1609,
8,
1080,
430,
267,
634,
889,
275,
1478,
18,
604,
8,
505,
14,
1080,
8,
1080,
430,
398,
340,
440,
5283,
2676,
14,
1100,
63,
1180,
63,
1190,
17,
26,
288,
367,
1067,
315,
5283,
2676,
14,
1507,
63,
1100,
63,
1278,
26,
355,
1343,
292,
275,
1390,
8,
76,
889,
446,
1067,
12,
413,
9,
355,
1343,
292,
1080,
275,
4700,
8,
928,
292,
9,
435,
3680,
16,
2,
355,
3631,
292,
1080,
275,
2071,
68,
14,
500,
2,
450,
634,
889,
355,
327,
2136,
1050,
314,
8057,
2952,
1611,
4003,
5074,
282,
8057,
355,
327,
737,
1284,
14,
2136,
1050,
282,
4601,
880,
626,
1478,
7859,
1133,
506,
737,
1284,
355,
327,
402,
1004,
12,
880,
626,
2399,
2004,
911,
506,
314,
2011,
465,
314,
355,
327,
1495,
2544,
652,
12,
340,
1077,
14,
355,
1798,
14,
409,
63,
495,
8,
505,
14,
362,
8,
928,
292,
1080,
12,
3631,
292,
1080,
20731,
971,
78,
358,
355,
330,
364,
275,
1798,
14,
1623,
63,
8302,
63,
1122,
63,
928,
8,
2079,
5283,
2676,
423,
1506,
63,
1560,
63,
262,
63,
875,
63,
1532,
8,
928,
292,
1080,
430,
355,
340,
330,
364,
365,
440,
488,
503,
1343,
292,
508,
413,
26,
490,
2059,
288,
1798,
14,
409,
63,
320,
8,
66,
364,
503,
378,
9,
267,
587,
26,
288,
519,
275,
1318,
14,
1450,
63,
5701,
1842,
480,
6614,
401,
1478,
9,
288,
340,
519,
26,
355,
1343,
292,
1080,
275,
519,
59,
17,
61,
288,
587,
26,
355,
1343,
292,
1080,
275,
298,
17,
14,
16,
2,
288,
3631,
292,
1080,
275,
2071,
68,
14,
500,
2,
450,
634,
889,
288,
327,
2136,
1050,
314,
8057,
2952,
1611,
4003,
5074,
652,
14,
2136,
1050,
282,
288,
327,
4601,
880,
626,
1478,
7859,
1133,
506,
737,
1284,
402,
1004,
12,
880,
626,
2399,
288,
327,
2004,
911,
506,
314,
2011,
465,
314,
1495,
2544,
652,
12,
340,
1077,
14,
288,
1798,
14,
409,
63,
495,
8,
505,
14,
362,
8,
928,
292,
1080,
12,
3631,
292,
1080,
20731,
971,
78,
358,
288,
1798,
14,
409,
63,
320,
8,
16,
9,
398,
327,
2136,
2934,
4052,
314,
1798,
965,
12,
21357,
314,
2061,
8057,
436,
4601,
14,
267,
291,
14,
1773,
505,
275,
1798,
14,
495,
4439,
18,
61,
267,
327,
10191,
14,
495,
27241,
590,
876,
20603,
314,
5164,
781,
787,
315,
12,
880,
267,
327,
626,
3631,
292,
1080,
883,
506,
1202,
370,
31021,
314,
1059,
543,
267,
327,
314,
1318,
5689,
4918,
14,
267,
291,
14,
2379,
292,
1080,
275,
3631,
292,
1080,
267,
291,
14,
14594,
316,
275,
1798,
14,
362,
63,
2019,
63,
9649,
63,
14594,
316,
342,
267,
327,
2342,
1314,
6342,
402,
14540,
316,
787,
16088,
83,
14,
5723,
3544,
267,
327,
17118,
370,
282,
4528,
402,
3066,
505,
14,
267,
291,
14,
374,
11637,
275,
359,
73,
30,
16,
436,
291,
14,
14594,
316,
59,
73,
1527,
17,
61,
690,
586,
291,
14,
14594,
316,
59,
73,
13,
17,
1527,
17,
61,
586,
367,
284,
315,
1425,
8,
552,
8,
277,
14,
14594,
316,
10524,
398,
291,
14,
409,
63,
1080,
8,
1080,
9,
339,
347,
663,
63,
1080,
8,
277,
12,
1478,
304,
267,
408,
1084,
314,
1478,
370,
1314,
314,
3423,
295,
750,
14,
398,
710,
1478,
1471,
506,
315,
314,
2011,
5164,
14,
267,
408,
267,
1478,
262,
1773,
505,
275,
334,
552,
8,
277,
14,
1773,
505,
9,
446,
2079,
822,
8,
277,
14,
505,
14,
362,
8,
1080,
12,
291,
14,
2379,
292,
1080,
1724,
267,
340,
1478,
262,
1773,
505,
665,
378,
26,
288,
746,
1722,
480,
2681,
450,
83,
9222,
3424,
314,
5909,
7068,
5164,
2,
2490,
450,
1478,
9,
267,
291,
14,
1080,
262,
1773,
505,
275,
1478,
262,
1773,
505,
267,
327,
2342,
314,
2451,
2786,
14540,
370,
1314,
1478,
15006,
267,
291,
14,
1080,
14594,
275,
378,
267,
1830,
334,
277,
14,
1080,
14594,
665,
822,
8,
277,
14,
14594,
316,
7216,
17,
436,
2049,
291,
14,
14594,
316,
59,
277,
14,
1080,
14594,
11,
17,
1527,
16,
61,
665,
291,
14,
1080,
262,
1773,
505,
304,
288,
291,
14,
1080,
14594,
847,
413,
267,
340,
334,
277,
14,
1080,
14594,
665,
822,
8,
277,
14,
14594,
316,
7216,
17,
436,
288,
291,
14,
14594,
316,
59,
277,
14,
1080,
14594,
11,
17,
1527,
16,
61,
508,
291,
14,
1080,
262,
1773,
505,
436,
1779,
440,
291,
14,
374,
11637,
59,
277,
14,
1080,
14594,
11,
17,
4682,
288,
291,
14,
1080,
14594,
847,
413,
339,
347,
365,
63,
262,
63,
875,
8,
277,
304,
267,
408,
1831,
314,
1478,
1627,
370,
314,
21344,
2842,
315,
282,
1059,
30196,
267,
327,
710,
14540,
370,
1314,
781,
13511,
1077,
506,
376,
16088,
14,
267,
327,
982,
652,
1159,
376,
16088,
12,
652,
965,
370,
1172,
282,
4528,
14,
267,
372,
334,
277,
14,
374,
11637,
59,
277,
14,
1080,
14594,
61,
436,
355,
291,
14,
1773,
505,
59,
277,
14,
14594,
316,
59,
277,
14,
1080,
14594,
1527,
16,
2677,
355,
315,
661,
6949,
3546,
2237,
339,
347,
365,
63,
262,
63,
600,
8,
277,
304,
267,
408,
1831,
314,
1478,
1627,
370,
314,
21344,
2842,
315,
3293,
1233,
30196,
267,
372,
334,
1397,
291,
14
] |
[
25107,
19472,
6057,
2236,
5462,
367,
10164,
828,
4486,
436,
1163,
5478,
14,
199,
199,
18727,
2842,
4440,
1611,
2842,
14,
221,
1611,
2842,
19762,
10557,
2556,
641,
314,
199,
28314,
14311,
402,
1233,
14,
221,
21344,
2842,
10557,
4722,
2556,
641,
199,
1589,
5523,
402,
1233,
14,
199,
624,
199,
199,
646,
1059,
199,
646,
4252,
199,
504,
15072,
773,
492,
1611,
4003,
199,
199,
533,
21344,
2842,
26,
339,
347,
636,
826,
721,
277,
12,
5283,
2676,
12,
1478,
304,
267,
298,
1378,
8265,
12,
19897,
314,
6296,
2363,
780,
402,
314,
1627,
1478,
2122,
398,
291,
14,
3773,
2676,
275,
5283,
2676,
267,
291,
14,
505,
275,
1318,
275,
5283,
2676,
14,
505,
398,
1798,
275,
1611,
4003,
14,
2842,
8,
3773,
2676,
14,
3724,
2063,
12,
5283,
2676,
14,
2902,
2063,
9,
398,
347,
1478,
18,
604,
8,
1080,
304,
288,
372,
1109,
8,
1609,
8,
1080,
430,
267,
634,
889,
275,
1478,
18,
604,
8,
505,
14,
1080,
8,
1080,
430,
398,
340,
440,
5283,
2676,
14,
1100,
63,
1180,
63,
1190,
17,
26,
288,
367,
1067,
315,
5283,
2676,
14,
1507,
63,
1100,
63,
1278,
26,
355,
1343,
292,
275,
1390,
8,
76,
889,
446,
1067,
12,
413,
9,
355,
1343,
292,
1080,
275,
4700,
8,
928,
292,
9,
435,
3680,
16,
2,
355,
3631,
292,
1080,
275,
2071,
68,
14,
500,
2,
450,
634,
889,
355,
327,
2136,
1050,
314,
8057,
2952,
1611,
4003,
5074,
282,
8057,
355,
327,
737,
1284,
14,
2136,
1050,
282,
4601,
880,
626,
1478,
7859,
1133,
506,
737,
1284,
355,
327,
402,
1004,
12,
880,
626,
2399,
2004,
911,
506,
314,
2011,
465,
314,
355,
327,
1495,
2544,
652,
12,
340,
1077,
14,
355,
1798,
14,
409,
63,
495,
8,
505,
14,
362,
8,
928,
292,
1080,
12,
3631,
292,
1080,
20731,
971,
78,
358,
355,
330,
364,
275,
1798,
14,
1623,
63,
8302,
63,
1122,
63,
928,
8,
2079,
5283,
2676,
423,
1506,
63,
1560,
63,
262,
63,
875,
63,
1532,
8,
928,
292,
1080,
430,
355,
340,
330,
364,
365,
440,
488,
503,
1343,
292,
508,
413,
26,
490,
2059,
288,
1798,
14,
409,
63,
320,
8,
66,
364,
503,
378,
9,
267,
587,
26,
288,
519,
275,
1318,
14,
1450,
63,
5701,
1842,
480,
6614,
401,
1478,
9,
288,
340,
519,
26,
355,
1343,
292,
1080,
275,
519,
59,
17,
61,
288,
587,
26,
355,
1343,
292,
1080,
275,
298,
17,
14,
16,
2,
288,
3631,
292,
1080,
275,
2071,
68,
14,
500,
2,
450,
634,
889,
288,
327,
2136,
1050,
314,
8057,
2952,
1611,
4003,
5074,
652,
14,
2136,
1050,
282,
288,
327,
4601,
880,
626,
1478,
7859,
1133,
506,
737,
1284,
402,
1004,
12,
880,
626,
2399,
288,
327,
2004,
911,
506,
314,
2011,
465,
314,
1495,
2544,
652,
12,
340,
1077,
14,
288,
1798,
14,
409,
63,
495,
8,
505,
14,
362,
8,
928,
292,
1080,
12,
3631,
292,
1080,
20731,
971,
78,
358,
288,
1798,
14,
409,
63,
320,
8,
16,
9,
398,
327,
2136,
2934,
4052,
314,
1798,
965,
12,
21357,
314,
2061,
8057,
436,
4601,
14,
267,
291,
14,
1773,
505,
275,
1798,
14,
495,
4439,
18,
61,
267,
327,
10191,
14,
495,
27241,
590,
876,
20603,
314,
5164,
781,
787,
315,
12,
880,
267,
327,
626,
3631,
292,
1080,
883,
506,
1202,
370,
31021,
314,
1059,
543,
267,
327,
314,
1318,
5689,
4918,
14,
267,
291,
14,
2379,
292,
1080,
275,
3631,
292,
1080,
267,
291,
14,
14594,
316,
275,
1798,
14,
362,
63,
2019,
63,
9649,
63,
14594,
316,
342,
267,
327,
2342,
1314,
6342,
402,
14540,
316,
787,
16088,
83,
14,
5723,
3544,
267,
327,
17118,
370,
282,
4528,
402,
3066,
505,
14,
267,
291,
14,
374,
11637,
275,
359,
73,
30,
16,
436,
291,
14,
14594,
316,
59,
73,
1527,
17,
61,
690,
586,
291,
14,
14594,
316,
59,
73,
13,
17,
1527,
17,
61,
586,
367,
284,
315,
1425,
8,
552,
8,
277,
14,
14594,
316,
10524,
398,
291,
14,
409,
63,
1080,
8,
1080,
9,
339,
347,
663,
63,
1080,
8,
277,
12,
1478,
304,
267,
408,
1084,
314,
1478,
370,
1314,
314,
3423,
295,
750,
14,
398,
710,
1478,
1471,
506,
315,
314,
2011,
5164,
14,
267,
408,
267,
1478,
262,
1773,
505,
275,
334,
552,
8,
277,
14,
1773,
505,
9,
446,
2079,
822,
8,
277,
14,
505,
14,
362,
8,
1080,
12,
291,
14,
2379,
292,
1080,
1724,
267,
340,
1478,
262,
1773,
505,
665,
378,
26,
288,
746,
1722,
480,
2681,
450,
83,
9222,
3424,
314,
5909,
7068,
5164,
2,
2490,
450,
1478,
9,
267,
291,
14,
1080,
262,
1773,
505,
275,
1478,
262,
1773,
505,
267,
327,
2342,
314,
2451,
2786,
14540,
370,
1314,
1478,
15006,
267,
291,
14,
1080,
14594,
275,
378,
267,
1830,
334,
277,
14,
1080,
14594,
665,
822,
8,
277,
14,
14594,
316,
7216,
17,
436,
2049,
291,
14,
14594,
316,
59,
277,
14,
1080,
14594,
11,
17,
1527,
16,
61,
665,
291,
14,
1080,
262,
1773,
505,
304,
288,
291,
14,
1080,
14594,
847,
413,
267,
340,
334,
277,
14,
1080,
14594,
665,
822,
8,
277,
14,
14594,
316,
7216,
17,
436,
288,
291,
14,
14594,
316,
59,
277,
14,
1080,
14594,
11,
17,
1527,
16,
61,
508,
291,
14,
1080,
262,
1773,
505,
436,
1779,
440,
291,
14,
374,
11637,
59,
277,
14,
1080,
14594,
11,
17,
4682,
288,
291,
14,
1080,
14594,
847,
413,
339,
347,
365,
63,
262,
63,
875,
8,
277,
304,
267,
408,
1831,
314,
1478,
1627,
370,
314,
21344,
2842,
315,
282,
1059,
30196,
267,
327,
710,
14540,
370,
1314,
781,
13511,
1077,
506,
376,
16088,
14,
267,
327,
982,
652,
1159,
376,
16088,
12,
652,
965,
370,
1172,
282,
4528,
14,
267,
372,
334,
277,
14,
374,
11637,
59,
277,
14,
1080,
14594,
61,
436,
355,
291,
14,
1773,
505,
59,
277,
14,
14594,
316,
59,
277,
14,
1080,
14594,
1527,
16,
2677,
355,
315,
661,
6949,
3546,
2237,
339,
347,
365,
63,
262,
63,
600,
8,
277,
304,
267,
408,
1831,
314,
1478,
1627,
370,
314,
21344,
2842,
315,
3293,
1233,
30196,
267,
372,
334,
1397,
291,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
aaronorosen/horizon-congress
|
openstack_dashboard/dashboards/admin/instances/panel.py
|
46
|
1091
|
# Copyright 2012 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
# Copyright 2012 Nebula, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.utils.translation import ugettext_lazy as _
import horizon
from openstack_dashboard.dashboards.admin import dashboard
class Instances(horizon.Panel):
name = _("Instances")
slug = 'instances'
permissions = ('openstack.roles.admin', 'openstack.services.compute')
dashboard.Admin.register(Instances)
|
apache-2.0
|
[
3,
1898,
6029,
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,
1898,
6029,
653,
2871,
7586,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
646,
21726,
199,
199,
504,
13869,
63,
9743,
14,
30424,
14,
2113,
492,
17216,
421,
199,
533,
10066,
83,
8,
16561,
14,
10185,
304,
272,
536,
275,
3824,
18194,
531,
272,
8889,
275,
283,
5990,
7,
272,
3443,
275,
661,
8512,
14,
8050,
14,
2113,
297,
283,
8512,
14,
5950,
14,
3357,
358,
421,
199,
9743,
14,
4880,
14,
2683,
8,
18194,
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
] |
[
1898,
6029,
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,
1898,
6029,
653,
2871,
7586,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
646,
21726,
199,
199,
504,
13869,
63,
9743,
14,
30424,
14,
2113,
492,
17216,
421,
199,
533,
10066,
83,
8,
16561,
14,
10185,
304,
272,
536,
275,
3824,
18194,
531,
272,
8889,
275,
283,
5990,
7,
272,
3443,
275,
661,
8512,
14,
8050,
14,
2113,
297,
283,
8512,
14,
5950,
14,
3357,
358,
421,
199,
9743,
14,
4880,
14,
2683,
8,
18194,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
matthiasplappert/motion_classification
|
src/toolkit/util.py
|
1
|
2470
|
import numpy as np
from sklearn.utils.validation import check_array
class NotFittedError(ValueError, AttributeError):
pass
def check_feature_array(array, n_features=None):
array = check_array(array, ensure_2d=True, allow_nd=False)
if n_features is not None and array.shape[1] != n_features:
raise ValueError('feature array must have exactly %d features' % n_features)
return array
def check_is_fitted(estimator, attributes, msg=None, all_or_any=all):
# Based on sklearn.util.validation.check_is_fitted but also ensures
# that the attribute is not None
if msg is None:
msg = ("This %(name)s instance is not fitted yet. Call 'fit' with "
"appropriate arguments before using this method.")
if not hasattr(estimator, 'fit'):
raise TypeError("%s is not an estimator instance." % estimator)
if not isinstance(attributes, (list, tuple)):
attributes = [attributes]
if not all_or_any([hasattr(estimator, attr) for attr in attributes]):
raise NotFittedError(msg % {'name': type(estimator).__name__})
if not all_or_any([getattr(estimator, attr) for attr in attributes]):
raise NotFittedError(msg % {'name': type(estimator).__name__})
def check_multilabel_array(array, n_labels=None, force_binary=True):
array = check_array(array, ensure_2d=True, allow_nd=False, dtype=int)
if n_labels is not None and array.shape[1] != n_labels:
raise ValueError('multilabel array must have exactly %d labels' % n_labels)
if force_binary:
count_ones = np.count_nonzero(array == 1)
count_zeros = np.count_nonzero(array == 0)
if np.size(array) != count_ones + count_zeros:
raise ValueError('multilabel array must be binary')
return array
def pad_sequences(X):
# Find longest sequence
n_samples_max = 0
for X_curr in X:
n_samples_curr = X_curr.shape[0]
if n_samples_curr > n_samples_max:
n_samples_max = n_samples_curr
# Adjust length of all sequences to be equal
for idx, X_curr in enumerate(X):
n_samples_curr = X_curr.shape[0]
delta_samples = n_samples_max - n_samples_curr
assert delta_samples >= 0
if delta_samples > 0:
fill_array = np.zeros((delta_samples, X_curr.shape[1]))
X[idx] = np.append(X_curr, fill_array, axis=0)
assert X[idx].shape[0] == n_samples_max
X = np.asarray(X)
return X
|
mit
|
[
646,
2680,
465,
980,
199,
504,
6357,
14,
1208,
14,
6136,
492,
1104,
63,
1144,
421,
199,
533,
2832,
13776,
471,
547,
8,
3393,
12,
4281,
304,
272,
986,
421,
199,
318,
1104,
63,
4445,
63,
1144,
8,
1144,
12,
302,
63,
3179,
29,
403,
304,
272,
1625,
275,
1104,
63,
1144,
8,
1144,
12,
4868,
63,
18,
68,
29,
549,
12,
2040,
63,
977,
29,
797,
9,
272,
340,
302,
63,
3179,
365,
440,
488,
436,
1625,
14,
1392,
59,
17,
61,
1137,
302,
63,
3179,
26,
267,
746,
1722,
360,
4445,
1625,
1471,
1172,
8840,
450,
68,
4534,
7,
450,
302,
63,
3179,
9,
272,
372,
1625,
421,
199,
318,
1104,
63,
374,
63,
21903,
8,
8627,
12,
3004,
12,
1499,
29,
403,
12,
1006,
63,
269,
63,
1629,
29,
452,
304,
272,
327,
21311,
641,
6357,
14,
1974,
14,
6136,
14,
1074,
63,
374,
63,
21903,
1325,
2597,
15620,
272,
327,
626,
314,
2225,
365,
440,
488,
272,
340,
1499,
365,
488,
26,
267,
1499,
275,
1689,
2765,
2818,
354,
9,
83,
1256,
365,
440,
26093,
5966,
14,
6523,
283,
3269,
7,
543,
298,
2049,
298,
11227,
5655,
2368,
2544,
1808,
642,
1083,
2685,
339,
340,
440,
2688,
8,
8627,
12,
283,
3269,
735,
267,
746,
3146,
3647,
83,
365,
440,
376,
8943,
1256,
2122,
450,
8943,
9,
339,
340,
440,
1228,
8,
2987,
12,
334,
513,
12,
2008,
2298,
267,
3004,
275,
359,
2987,
61,
339,
340,
440,
1006,
63,
269,
63,
1629,
779,
11161,
8,
8627,
12,
1921,
9,
367,
1921,
315,
3004,
4682,
267,
746,
2832,
13776,
471,
547,
8,
1328,
450,
791,
354,
356,
730,
8,
8627,
2843,
354,
363,
1552,
339,
340,
440,
1006,
63,
269,
63,
1629,
779,
5675,
8,
8627,
12,
1921,
9,
367,
1921,
315,
3004,
4682,
267,
746,
2832,
13776,
471,
547,
8,
1328,
450,
791,
354,
356,
730,
8,
8627,
2843,
354,
363,
1552,
421,
199,
318,
1104,
63,
3029,
1302,
63,
1144,
8,
1144,
12,
302,
63,
3512,
29,
403,
12,
3542,
63,
3008,
29,
549,
304,
272,
1625,
275,
1104,
63,
1144,
8,
1144,
12,
4868,
63,
18,
68,
29,
549,
12,
2040,
63,
977,
29,
797,
12,
2152,
29,
442,
9,
272,
340,
302,
63,
3512,
365,
440,
488,
436,
1625,
14,
1392,
59,
17,
61,
1137,
302,
63,
3512,
26,
267,
746,
1722,
360,
3029,
1302,
1625,
1471,
1172,
8840,
450,
68,
3628,
7,
450,
302,
63,
3512,
9,
272,
340,
3542,
63,
3008,
26,
267,
2338,
63,
4548,
275,
980,
14,
835,
63,
10262,
8,
1144,
508,
413,
9,
267,
2338,
63,
4250,
275,
980,
14,
835,
63,
10262,
8,
1144,
508,
378,
9,
267,
340,
980,
14,
890,
8,
1144,
9,
1137,
2338,
63,
4548,
435,
2338,
63,
4250,
26,
288,
746,
1722,
360,
3029,
1302,
1625,
1471,
506,
3366,
358,
272,
372,
1625,
421,
199,
318,
6567,
63,
13436,
8,
56,
304,
272,
327,
6668,
21303,
3414,
272,
302,
63,
3356,
63,
988,
275,
378,
272,
367,
1323,
63,
9808,
315,
1323,
26,
267,
302,
63,
3356,
63,
9808,
275,
1323,
63,
9808,
14,
1392,
59,
16,
61,
267,
340,
302,
63,
3356,
63,
9808,
690,
302,
63,
3356,
63,
988,
26,
288,
302,
63,
3356,
63,
988,
275,
302,
63,
3356,
63,
9808,
339,
327,
26412,
2582,
402,
1006,
8013,
370,
506,
4472,
272,
367,
4280,
12,
1323,
63,
9808,
315,
3874,
8,
56,
304,
267,
302,
63,
3356,
63,
9808,
275,
1323,
63,
9808,
14,
1392,
59,
16,
61,
267,
5762,
63,
3356,
275,
302,
63,
3356,
63,
988,
446,
302,
63,
3356,
63,
9808,
267,
702,
5762,
63,
3356,
2356,
378,
267,
340,
5762,
63,
3356,
690,
378,
26,
288,
5554,
63,
1144,
275,
980,
14,
4250,
1332,
3136,
63,
3356,
12,
1323,
63,
9808,
14,
1392,
59,
17,
2459,
288,
1323,
59,
2996,
61,
275,
980,
14,
740,
8,
56,
63,
9808,
12,
5554,
63,
1144,
12,
3114,
29,
16,
9,
288,
702,
1323,
59,
2996,
1055,
1392,
59,
16,
61,
508,
302,
63,
3356,
63,
988,
272,
1323,
275,
980,
14,
8748,
8,
56,
9,
272,
372,
1323,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2680,
465,
980,
199,
504,
6357,
14,
1208,
14,
6136,
492,
1104,
63,
1144,
421,
199,
533,
2832,
13776,
471,
547,
8,
3393,
12,
4281,
304,
272,
986,
421,
199,
318,
1104,
63,
4445,
63,
1144,
8,
1144,
12,
302,
63,
3179,
29,
403,
304,
272,
1625,
275,
1104,
63,
1144,
8,
1144,
12,
4868,
63,
18,
68,
29,
549,
12,
2040,
63,
977,
29,
797,
9,
272,
340,
302,
63,
3179,
365,
440,
488,
436,
1625,
14,
1392,
59,
17,
61,
1137,
302,
63,
3179,
26,
267,
746,
1722,
360,
4445,
1625,
1471,
1172,
8840,
450,
68,
4534,
7,
450,
302,
63,
3179,
9,
272,
372,
1625,
421,
199,
318,
1104,
63,
374,
63,
21903,
8,
8627,
12,
3004,
12,
1499,
29,
403,
12,
1006,
63,
269,
63,
1629,
29,
452,
304,
272,
327,
21311,
641,
6357,
14,
1974,
14,
6136,
14,
1074,
63,
374,
63,
21903,
1325,
2597,
15620,
272,
327,
626,
314,
2225,
365,
440,
488,
272,
340,
1499,
365,
488,
26,
267,
1499,
275,
1689,
2765,
2818,
354,
9,
83,
1256,
365,
440,
26093,
5966,
14,
6523,
283,
3269,
7,
543,
298,
2049,
298,
11227,
5655,
2368,
2544,
1808,
642,
1083,
2685,
339,
340,
440,
2688,
8,
8627,
12,
283,
3269,
735,
267,
746,
3146,
3647,
83,
365,
440,
376,
8943,
1256,
2122,
450,
8943,
9,
339,
340,
440,
1228,
8,
2987,
12,
334,
513,
12,
2008,
2298,
267,
3004,
275,
359,
2987,
61,
339,
340,
440,
1006,
63,
269,
63,
1629,
779,
11161,
8,
8627,
12,
1921,
9,
367,
1921,
315,
3004,
4682,
267,
746,
2832,
13776,
471,
547,
8,
1328,
450,
791,
354,
356,
730,
8,
8627,
2843,
354,
363,
1552,
339,
340,
440,
1006,
63,
269,
63,
1629,
779,
5675,
8,
8627,
12,
1921,
9,
367,
1921,
315,
3004,
4682,
267,
746,
2832,
13776,
471,
547,
8,
1328,
450,
791,
354,
356,
730,
8,
8627,
2843,
354,
363,
1552,
421,
199,
318,
1104,
63,
3029,
1302,
63,
1144,
8,
1144,
12,
302,
63,
3512,
29,
403,
12,
3542,
63,
3008,
29,
549,
304,
272,
1625,
275,
1104,
63,
1144,
8,
1144,
12,
4868,
63,
18,
68,
29,
549,
12,
2040,
63,
977,
29,
797,
12,
2152,
29,
442,
9,
272,
340,
302,
63,
3512,
365,
440,
488,
436,
1625,
14,
1392,
59,
17,
61,
1137,
302,
63,
3512,
26,
267,
746,
1722,
360,
3029,
1302,
1625,
1471,
1172,
8840,
450,
68,
3628,
7,
450,
302,
63,
3512,
9,
272,
340,
3542,
63,
3008,
26,
267,
2338,
63,
4548,
275,
980,
14,
835,
63,
10262,
8,
1144,
508,
413,
9,
267,
2338,
63,
4250,
275,
980,
14,
835,
63,
10262,
8,
1144,
508,
378,
9,
267,
340,
980,
14,
890,
8,
1144,
9,
1137,
2338,
63,
4548,
435,
2338,
63,
4250,
26,
288,
746,
1722,
360,
3029,
1302,
1625,
1471,
506,
3366,
358,
272,
372,
1625,
421,
199,
318,
6567,
63,
13436,
8,
56,
304,
272,
327,
6668,
21303,
3414,
272,
302,
63,
3356,
63,
988,
275,
378,
272,
367,
1323,
63,
9808,
315,
1323,
26,
267,
302,
63,
3356,
63,
9808,
275,
1323,
63,
9808,
14,
1392,
59,
16,
61,
267,
340,
302,
63,
3356,
63,
9808,
690,
302,
63,
3356,
63,
988,
26,
288,
302,
63,
3356,
63,
988,
275,
302,
63,
3356,
63,
9808,
339,
327,
26412,
2582,
402,
1006,
8013,
370,
506,
4472,
272,
367,
4280,
12,
1323,
63,
9808,
315,
3874,
8,
56,
304,
267,
302,
63,
3356,
63,
9808,
275,
1323,
63,
9808,
14,
1392,
59,
16,
61,
267,
5762,
63,
3356,
275,
302,
63,
3356,
63,
988,
446,
302,
63,
3356,
63,
9808,
267,
702,
5762,
63,
3356,
2356,
378,
267,
340,
5762,
63,
3356,
690,
378,
26,
288,
5554,
63,
1144,
275,
980,
14,
4250,
1332,
3136,
63,
3356,
12,
1323,
63,
9808,
14,
1392,
59,
17,
2459,
288,
1323,
59,
2996,
61,
275,
980,
14,
740,
8,
56,
63,
9808,
12,
5554,
63,
1144,
12,
3114,
29,
16,
9,
288,
702,
1323,
59,
2996,
1055,
1392,
59,
16,
61,
508,
302,
63,
3356,
63,
988,
272,
1323,
275,
980,
14,
8748,
8,
56,
9,
272,
372,
1323,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
Makeystreet/makeystreet
|
woot/apps/catalog/migrations/0035_fix_sequence_problem.py
|
1
|
26017
|
# -*- coding: utf-8 -*-
from south.utils import datetime_utils as datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
def increase_sequence(dbName):
highest_number = db.execute('select id from '+dbName+' order by id desc limit 1;')[0][0]
db.execute('alter sequence '+dbName+'_id_seq restart with %s;' % (highest_number+1))
class Migration(SchemaMigration):
def forwards(self, orm):
sequences = ['catalog_basemodel', 'catalog_emailcollect', 'catalog_liketutorial', 'catalog_list_access', 'catalog_list_items', 'catalog_listgroup_lists', 'catalog_logidenticalproduct', 'catalog_makey_collaborators', 'catalog_makey_comments', 'catalog_makey_documentations', 'catalog_makey_images', 'catalog_makey_notes', 'catalog_product_makeys', 'catalog_product_tutorials', 'catalog_searchlog', 'catalog_shop_images', 'catalog_toindexstore', 'catalog_tutorial_images']
for table in sequences:
try:
increase_sequence(table)
print("Done with "+table)
except Exception as e:
print(e)
def backwards(self, orm):
pass
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'})
},
'catalog.abstractlike': {
'Meta': {'object_name': 'AbstractLike', '_ormbases': ['catalog.BaseModel']},
u'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
'liked_time': ('django.db.models.fields.DateTimeField', [], {}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['django_facebook.FacebookCustomUser']"})
},
'catalog.abstracttop': {
'Meta': {'object_name': 'AbstractTop', '_ormbases': ['catalog.BaseModel']},
u'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
'recorded_time': ('django.db.models.fields.DateTimeField', [], {})
},
'catalog.basemodel': {
'Meta': {'object_name': 'BaseModel'},
'added_time': ('django.db.models.fields.DateTimeField', [], {}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_enabled': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'score': ('django.db.models.fields.IntegerField', [], {'default': '0'})
},
'catalog.comment': {
'Meta': {'object_name': 'Comment', '_ormbases': ['catalog.BaseModel']},
u'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
'body': ('django.db.models.fields.CharField', [], {'max_length': '1000'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['django_facebook.FacebookCustomUser']"})
},
'catalog.documentation': {
'Meta': {'object_name': 'Documentation', '_ormbases': ['catalog.BaseModel']},
u'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
'url': ('django.db.models.fields.URLField', [], {'max_length': '1000'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['django_facebook.FacebookCustomUser']", 'null': 'True', 'blank': 'True'})
},
'catalog.emailcollect': {
'Meta': {'object_name': 'EmailCollect'},
'email': ('django.db.models.fields.EmailField', [], {'max_length': '30'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'catalog.image': {
'Meta': {'object_name': 'Image', '_ormbases': ['catalog.BaseModel']},
u'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
'large_url': ('django.db.models.fields.URLField', [], {'max_length': '1000'}),
'small_url': ('django.db.models.fields.URLField', [], {'max_length': '1000', 'null': 'True', 'blank': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'images'", 'null': 'True', 'to': u"orm['django_facebook.FacebookCustomUser']"})
},
'catalog.like': {
'Meta': {'object_name': 'Like', '_ormbases': ['catalog.AbstractLike']},
u'abstractlike_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.AbstractLike']", 'unique': 'True', 'primary_key': 'True'})
},
'catalog.likemakey': {
'Meta': {'object_name': 'LikeMakey', '_ormbases': ['catalog.AbstractLike']},
u'abstractlike_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.AbstractLike']", 'unique': 'True', 'primary_key': 'True'}),
'makey': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalog.Makey']"})
},
'catalog.likeproduct': {
'Meta': {'object_name': 'LikeProduct', '_ormbases': ['catalog.AbstractLike']},
u'abstractlike_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.AbstractLike']", 'unique': 'True', 'primary_key': 'True'}),
'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalog.Product']"})
},
'catalog.likeproductdescription': {
'Meta': {'object_name': 'LikeProductDescription', '_ormbases': ['catalog.AbstractLike']},
u'abstractlike_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.AbstractLike']", 'unique': 'True', 'primary_key': 'True'}),
'product_description': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalog.ProductDescription']"})
},
'catalog.likeproductimage': {
'Meta': {'object_name': 'LikeProductImage', '_ormbases': ['catalog.AbstractLike']},
u'abstractlike_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.AbstractLike']", 'unique': 'True', 'primary_key': 'True'}),
'image': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalog.ProductImage']"}),
'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalog.Product']"})
},
'catalog.likeproducttutorial': {
'Meta': {'object_name': 'LikeProductTutorial', '_ormbases': ['catalog.AbstractLike']},
u'abstractlike_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.AbstractLike']", 'unique': 'True', 'primary_key': 'True'}),
'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalog.Product']"}),
'tutorial': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalog.Tutorial']"})
},
'catalog.likeshop': {
'Meta': {'object_name': 'LikeShop', '_ormbases': ['catalog.AbstractLike']},
u'abstractlike_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.AbstractLike']", 'unique': 'True', 'primary_key': 'True'}),
'shop': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalog.Shop']"})
},
'catalog.list': {
'Meta': {'object_name': 'List', '_ormbases': ['catalog.BaseModel']},
'access': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'access'", 'symmetrical': 'False', 'to': u"orm['django_facebook.FacebookCustomUser']"}),
u'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
'is_private': ('django.db.models.fields.BooleanField', [], {}),
'items': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['catalog.ListItem']", 'symmetrical': 'False'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'owner': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'owner'", 'to': u"orm['django_facebook.FacebookCustomUser']"})
},
'catalog.listgroup': {
'Meta': {'object_name': 'ListGroup', '_ormbases': ['catalog.BaseModel']},
u'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
'lists': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['catalog.List']", 'symmetrical': 'False'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'catalog.listitem': {
'Meta': {'object_name': 'ListItem', '_ormbases': ['catalog.BaseModel']},
u'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
'createdby': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['django_facebook.FacebookCustomUser']"}),
'note': ('django.db.models.fields.CharField', [], {'max_length': '500'}),
'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalog.Product']"})
},
'catalog.location': {
'Meta': {'object_name': 'Location', '_ormbases': ['catalog.BaseModel']},
u'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'catalog.logidenticalproduct': {
'Meta': {'object_name': 'LogIdenticalProduct'},
'added_time': ('django.db.models.fields.DateTimeField', [], {}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'product1': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'product1'", 'to': "orm['catalog.Product']"}),
'product2': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'product2'", 'to': "orm['catalog.Product']"}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['django_facebook.FacebookCustomUser']"})
},
'catalog.makey': {
'Meta': {'object_name': 'Makey', '_ormbases': ['catalog.BaseModel']},
u'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
'collaborators': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'collaborators'", 'null': 'True', 'symmetrical': 'False', 'to': u"orm['django_facebook.FacebookCustomUser']"}),
'comments': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'makeycomments'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['catalog.Comment']"}),
'description': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
'documentations': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'makeydocumentations'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['catalog.Documentation']"}),
'images': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'makeyimages'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['catalog.Image']"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
'notes': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'makeynotes'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['catalog.Note']"}),
'url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['django_facebook.FacebookCustomUser']", 'null': 'True', 'blank': 'True'})
},
'catalog.note': {
'Meta': {'object_name': 'Note', '_ormbases': ['catalog.BaseModel']},
u'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
'body': ('django.db.models.fields.CharField', [], {'max_length': '1000'}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '140'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['django_facebook.FacebookCustomUser']"})
},
'catalog.product': {
'Meta': {'object_name': 'Product', '_ormbases': ['catalog.BaseModel']},
u'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
'identicalto': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalog.Product']", 'null': 'True', 'blank': 'True'}),
'makeys': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'partsused'", 'blank': 'True', 'to': "orm['catalog.Makey']"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
'sku': ('django.db.models.fields.IntegerField', [], {}),
'tutorials': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['catalog.Tutorial']", 'symmetrical': 'False', 'blank': 'True'})
},
'catalog.productdescription': {
'Meta': {'object_name': 'ProductDescription', '_ormbases': ['catalog.BaseModel']},
u'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
'description': ('django.db.models.fields.CharField', [], {'max_length': '100000'}),
'product': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'productdescriptions'", 'to': "orm['catalog.Product']"}),
'shop': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalog.Shop']", 'blank': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['django_facebook.FacebookCustomUser']", 'blank': 'True'}),
'user_or_shop': ('django.db.models.fields.BooleanField', [], {})
},
'catalog.productimage': {
'Meta': {'object_name': 'ProductImage', '_ormbases': ['catalog.BaseModel']},
u'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
'product': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'productimages'", 'to': "orm['catalog.Product']"}),
'shop': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalog.Shop']", 'null': 'True', 'blank': 'True'}),
'url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['django_facebook.FacebookCustomUser']", 'null': 'True', 'blank': 'True'})
},
'catalog.productshopurl': {
'Meta': {'object_name': 'ProductShopUrl', '_ormbases': ['catalog.BaseModel']},
u'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
'product': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'productshopurls'", 'to': "orm['catalog.Product']"}),
'shop': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalog.Shop']"}),
'url': ('django.db.models.fields.URLField', [], {'max_length': '200'})
},
'catalog.searchlog': {
'Meta': {'object_name': 'SearchLog'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'term': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'time': ('django.db.models.fields.DateTimeField', [], {}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['django_facebook.FacebookCustomUser']", 'null': 'True', 'blank': 'True'})
},
'catalog.shop': {
'Meta': {'object_name': 'Shop', '_ormbases': ['catalog.BaseModel']},
u'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
'description': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}),
'images': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'shopimages'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['catalog.Image']"}),
'location': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalog.Location']"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
'url': ('django.db.models.fields.URLField', [], {'max_length': '200'})
},
'catalog.toindexstore': {
'Meta': {'object_name': 'ToIndexStore'},
'added_time': ('django.db.models.fields.DateTimeField', [], {}),
'description': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'location': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalog.Location']"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
'url': ('django.db.models.fields.URLField', [], {'max_length': '200'})
},
'catalog.topmakeys': {
'Meta': {'object_name': 'TopMakeys', '_ormbases': ['catalog.AbstractTop']},
u'abstracttop_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.AbstractTop']", 'unique': 'True', 'primary_key': 'True'}),
'makey': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalog.Makey']"})
},
'catalog.topproducts': {
'Meta': {'object_name': 'TopProducts', '_ormbases': ['catalog.AbstractTop']},
u'abstracttop_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.AbstractTop']", 'unique': 'True', 'primary_key': 'True'}),
'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalog.Product']"})
},
'catalog.topshops': {
'Meta': {'object_name': 'TopShops', '_ormbases': ['catalog.AbstractTop']},
u'abstracttop_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.AbstractTop']", 'unique': 'True', 'primary_key': 'True'}),
'shop': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalog.Shop']"})
},
'catalog.toptutorials': {
'Meta': {'object_name': 'TopTutorials', '_ormbases': ['catalog.AbstractTop']},
u'abstracttop_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.AbstractTop']", 'unique': 'True', 'primary_key': 'True'}),
'tutorial': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalog.Tutorial']"})
},
'catalog.topusers': {
'Meta': {'object_name': 'TopUsers', '_ormbases': ['catalog.AbstractTop']},
u'abstracttop_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.AbstractTop']", 'unique': 'True', 'primary_key': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['django_facebook.FacebookCustomUser']"})
},
'catalog.tutorial': {
'Meta': {'object_name': 'Tutorial', '_ormbases': ['catalog.BaseModel']},
u'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['catalog.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
'description': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
'images': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'tutorialimages'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['catalog.Image']"}),
'url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['django_facebook.FacebookCustomUser']", 'null': 'True', 'blank': 'True'})
},
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'django_facebook.facebookcustomuser': {
'Meta': {'object_name': 'FacebookCustomUser'},
'about_me': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'access_token': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'blog_url': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'date_of_birth': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'facebook_id': ('django.db.models.fields.BigIntegerField', [], {'unique': 'True', 'null': 'True', 'blank': 'True'}),
'facebook_name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
'facebook_open_graph': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}),
'facebook_profile_url': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'gender': ('django.db.models.fields.CharField', [], {'max_length': '1', 'null': 'True', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Group']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'image': ('django.db.models.fields.files.ImageField', [], {'max_length': '255', 'null': 'True', 'blank': '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'}),
'new_token_required': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'raw_data': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'state': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Permission']"}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}),
'website_url': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'})
}
}
complete_apps = ['catalog']
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
12919,
14,
1208,
492,
2197,
63,
1208,
465,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
199,
199,
318,
19781,
63,
4041,
8,
697,
985,
304,
272,
15356,
63,
1955,
275,
1592,
14,
2526,
360,
2416,
1305,
687,
6681,
697,
985,
4786,
1865,
701,
1305,
4328,
2304,
413,
27,
5832,
16,
1527,
16,
61,
272,
1592,
14,
2526,
360,
11858,
3414,
6681,
697,
985,
28323,
344,
63,
3610,
11004,
543,
450,
83,
8942,
450,
334,
31381,
63,
1955,
11,
17,
430,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
8013,
275,
788,
7959,
63,
1095,
1238,
297,
283,
7959,
63,
2123,
7112,
297,
283,
7959,
63,
317,
75,
386,
15888,
297,
283,
7959,
63,
513,
63,
2732,
297,
283,
7959,
63,
513,
63,
1744,
297,
283,
7959,
63,
513,
923,
63,
6717,
297,
283,
7959,
63,
793,
14576,
2558,
297,
283,
7959,
63,
391,
498,
63,
761,
5561,
269,
2750,
297,
283,
7959,
63,
391,
498,
63,
6223,
297,
283,
7959,
63,
391,
498,
63,
3554,
1298,
297,
283,
7959,
63,
391,
498,
63,
4782,
297,
283,
7959,
63,
391,
498,
63,
5983,
297,
283,
7959,
63,
2558,
63,
391,
1612,
297,
283,
7959,
63,
2558,
63,
23561,
83,
297,
283,
7959,
63,
1733,
793,
297,
283,
7959,
63,
10568,
63,
4782,
297,
283,
7959,
63,
475,
1080,
1617,
297,
283,
7959,
63,
23561,
63,
4782,
418,
2728,
367,
1817,
315,
8013,
26,
6722,
862,
26,
355,
19781,
63,
4041,
8,
1224,
9,
355,
870,
480,
10759,
543,
7210,
1224,
9,
288,
871,
2186,
465,
325,
26,
355,
870,
8,
69,
9,
339,
347,
8552,
8,
277,
12,
9813,
304,
267,
986,
339,
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,
283,
7959,
14,
6198,
2930,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
8458,
12545,
297,
2513,
31525,
356,
788,
7959,
14,
27687,
14949,
288,
399,
7,
1095,
1238,
63,
4695,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
297,
990,
791,
475,
356,
298,
1025,
459,
7959,
14,
27687,
6256,
283,
3235,
356,
283,
549,
297,
283,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
317,
25503,
63,
521,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
8613,
288,
283,
751,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1176,
63,
16652,
14,
13414,
2706,
31482,
13687,
267,
1660,
267,
283,
7959,
14,
6198,
2119,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
8458,
6105,
297,
2513,
31525,
356,
788,
7959,
14,
27687,
14949,
288,
399,
7,
1095,
1238,
63,
4695,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
297,
990,
791,
475,
356,
298,
1025,
459,
7959,
14,
27687,
6256,
283,
3235,
356,
283,
549,
297,
283,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
264,
15402,
63,
521,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
5009,
267,
1660,
267,
283,
7959,
14,
1095,
1238,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
27687,
2267,
288,
283,
3270,
63,
521,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
8613,
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,
3827,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
3397,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
885,
356,
283,
16,
3071,
267,
1660,
267,
283,
7959,
14,
3349,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
7488,
297,
2513,
31525,
356,
788,
7959,
14,
27687,
14949,
288,
399,
7,
1095,
1238,
63,
4695,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
297,
990,
791,
475,
356,
298,
1025,
459,
7959,
14,
27687,
6256,
283,
3235,
356,
283,
549,
297,
283,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
2030,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
12919,
14,
1208,
492,
2197,
63,
1208,
465,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
199,
199,
318,
19781,
63,
4041,
8,
697,
985,
304,
272,
15356,
63,
1955,
275,
1592,
14,
2526,
360,
2416,
1305,
687,
6681,
697,
985,
4786,
1865,
701,
1305,
4328,
2304,
413,
27,
5832,
16,
1527,
16,
61,
272,
1592,
14,
2526,
360,
11858,
3414,
6681,
697,
985,
28323,
344,
63,
3610,
11004,
543,
450,
83,
8942,
450,
334,
31381,
63,
1955,
11,
17,
430,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
8013,
275,
788,
7959,
63,
1095,
1238,
297,
283,
7959,
63,
2123,
7112,
297,
283,
7959,
63,
317,
75,
386,
15888,
297,
283,
7959,
63,
513,
63,
2732,
297,
283,
7959,
63,
513,
63,
1744,
297,
283,
7959,
63,
513,
923,
63,
6717,
297,
283,
7959,
63,
793,
14576,
2558,
297,
283,
7959,
63,
391,
498,
63,
761,
5561,
269,
2750,
297,
283,
7959,
63,
391,
498,
63,
6223,
297,
283,
7959,
63,
391,
498,
63,
3554,
1298,
297,
283,
7959,
63,
391,
498,
63,
4782,
297,
283,
7959,
63,
391,
498,
63,
5983,
297,
283,
7959,
63,
2558,
63,
391,
1612,
297,
283,
7959,
63,
2558,
63,
23561,
83,
297,
283,
7959,
63,
1733,
793,
297,
283,
7959,
63,
10568,
63,
4782,
297,
283,
7959,
63,
475,
1080,
1617,
297,
283,
7959,
63,
23561,
63,
4782,
418,
2728,
367,
1817,
315,
8013,
26,
6722,
862,
26,
355,
19781,
63,
4041,
8,
1224,
9,
355,
870,
480,
10759,
543,
7210,
1224,
9,
288,
871,
2186,
465,
325,
26,
355,
870,
8,
69,
9,
339,
347,
8552,
8,
277,
12,
9813,
304,
267,
986,
339,
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,
283,
7959,
14,
6198,
2930,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
8458,
12545,
297,
2513,
31525,
356,
788,
7959,
14,
27687,
14949,
288,
399,
7,
1095,
1238,
63,
4695,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
297,
990,
791,
475,
356,
298,
1025,
459,
7959,
14,
27687,
6256,
283,
3235,
356,
283,
549,
297,
283,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
317,
25503,
63,
521,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
8613,
288,
283,
751,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1176,
63,
16652,
14,
13414,
2706,
31482,
13687,
267,
1660,
267,
283,
7959,
14,
6198,
2119,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
8458,
6105,
297,
2513,
31525,
356,
788,
7959,
14,
27687,
14949,
288,
399,
7,
1095,
1238,
63,
4695,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
297,
990,
791,
475,
356,
298,
1025,
459,
7959,
14,
27687,
6256,
283,
3235,
356,
283,
549,
297,
283,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
264,
15402,
63,
521,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
5009,
267,
1660,
267,
283,
7959,
14,
1095,
1238,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
27687,
2267,
288,
283,
3270,
63,
521,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
8613,
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,
3827,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
3397,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
885,
356,
283,
16,
3071,
267,
1660,
267,
283,
7959,
14,
3349,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
7488,
297,
2513,
31525,
356,
788,
7959,
14,
27687,
14949,
288,
399,
7,
1095,
1238,
63,
4695,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
297,
990,
791,
475,
356,
298,
1025,
459,
7959,
14,
27687,
6256,
283,
3235,
356,
283,
549,
297,
283,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
2030,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Zhaoyanzhang/-myflasky
|
venv/lib/python2.7/site-packages/pip/utils/__init__.py
|
323
|
27187
|
from __future__ import absolute_import
from collections import deque
import contextlib
import errno
import io
import locale
# we have a submodule named 'logging' which would shadow this if we used the
# regular name:
import logging as std_logging
import re
import os
import posixpath
import shutil
import stat
import subprocess
import sys
import tarfile
import zipfile
from pip.exceptions import InstallationError
from pip.compat import console_to_str, expanduser, stdlib_pkgs
from pip.locations import (
site_packages, user_site, running_under_virtualenv, virtualenv_no_global,
write_delete_marker_file,
)
from pip._vendor import pkg_resources
from pip._vendor.six.moves import input
from pip._vendor.six import PY2
from pip._vendor.retrying import retry
if PY2:
from io import BytesIO as StringIO
else:
from io import StringIO
__all__ = ['rmtree', 'display_path', 'backup_dir',
'ask', 'splitext',
'format_size', 'is_installable_dir',
'is_svn_page', 'file_contents',
'split_leading_dir', 'has_leading_dir',
'normalize_path',
'renames', 'get_terminal_size', 'get_prog',
'unzip_file', 'untar_file', 'unpack_file', 'call_subprocess',
'captured_stdout', 'ensure_dir',
'ARCHIVE_EXTENSIONS', 'SUPPORTED_EXTENSIONS',
'get_installed_version']
logger = std_logging.getLogger(__name__)
BZ2_EXTENSIONS = ('.tar.bz2', '.tbz')
XZ_EXTENSIONS = ('.tar.xz', '.txz', '.tlz', '.tar.lz', '.tar.lzma')
ZIP_EXTENSIONS = ('.zip', '.whl')
TAR_EXTENSIONS = ('.tar.gz', '.tgz', '.tar')
ARCHIVE_EXTENSIONS = (
ZIP_EXTENSIONS + BZ2_EXTENSIONS + TAR_EXTENSIONS + XZ_EXTENSIONS)
SUPPORTED_EXTENSIONS = ZIP_EXTENSIONS + TAR_EXTENSIONS
try:
import bz2 # noqa
SUPPORTED_EXTENSIONS += BZ2_EXTENSIONS
except ImportError:
logger.debug('bz2 module is not available')
try:
# Only for Python 3.3+
import lzma # noqa
SUPPORTED_EXTENSIONS += XZ_EXTENSIONS
except ImportError:
logger.debug('lzma module is not available')
def import_or_raise(pkg_or_module_string, ExceptionType, *args, **kwargs):
try:
return __import__(pkg_or_module_string)
except ImportError:
raise ExceptionType(*args, **kwargs)
def ensure_dir(path):
"""os.path.makedirs without EEXIST."""
try:
os.makedirs(path)
except OSError as e:
if e.errno != errno.EEXIST:
raise
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'
# Retry every half second for up to 3 seconds
@retry(stop_max_delay=3000, wait_fixed=500)
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."""
# if file type currently read only
if os.stat(path).st_mode & stat.S_IREAD:
# convert to read/write
os.chmod(path, stat.S_IWRITE)
# use the original function to repeat the operation
func(path)
return
else:
raise
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 sys.version_info[0] == 2:
path = path.decode(sys.getfilesystemencoding(), 'replace')
path = path.encode(sys.getdefaultencoding(), 'replace')
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 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 = 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
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):
with open(filename, 'rb') as fp:
return fp.read().decode('utf-8')
def read_chunks(file, size=io.DEFAULT_BUFFER_SIZE):
"""Yield pieces of data from a file-like object until EOF."""
while True:
chunk = file.read(size)
if not chunk:
break
yield chunk
def split_leading_dir(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 normalize_path(path, resolve_symlinks=True):
"""
Convert a path to its canonical, case-normalized, absolute version.
"""
path = expanduser(path)
if resolve_symlinks:
path = os.path.realpath(path)
else:
path = os.path.abspath(path)
return os.path.normcase(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.
"""
norm_path = normalize_path(dist_location(dist))
return norm_path.startswith(normalize_path(user_site))
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?"""
for path_item in sys.path:
egg_link = os.path.join(path_item, dist.project_name + '.egg-link')
if os.path.isfile(egg_link):
return True
return False
def get_installed_distributions(local_only=True,
skip=stdlib_pkgs,
include_editables=True,
editables_only=False,
user_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 stdlib_pkgs
If ``editables`` is False, don't report editables.
If ``editables_only`` is True , only report editables.
If ``user_only`` is True , only report installations in the user
site directory.
"""
if local_only:
local_test = dist_is_local
else:
def local_test(d):
return True
if include_editables:
def editable_test(d):
return True
else:
def editable_test(d):
return not dist_is_editable(d)
if editables_only:
def editables_only_test(d):
return dist_is_editable(d)
else:
def editables_only_test(d):
return True
if user_only:
user_test = dist_in_usersite
else:
def user_test(d):
return 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) and
user_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
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.
"""
ensure_dir(location)
zipfp = open(filename, 'rb')
try:
zip = zipfile.ZipFile(zipfp, allowZip64=True)
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 fn.endswith('/') or fn.endswith('\\'):
# A directory
ensure_dir(fn)
else:
ensure_dir(dir)
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.
"""
ensure_dir(location)
if filename.lower().endswith('.gz') or filename.lower().endswith('.tgz'):
mode = 'r:gz'
elif filename.lower().endswith(BZ2_EXTENSIONS):
mode = 'r:bz2'
elif filename.lower().endswith(XZ_EXTENSIONS):
mode = 'r:xz'
elif filename.lower().endswith('.tar'):
mode = 'r'
else:
logger.warning(
'Cannot determine compression type for file %s', filename,
)
mode = 'r:*'
tar = tarfile.open(filename, mode)
try:
# note: python<=2.5 doesn't 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():
ensure_dir(path)
elif member.issym():
try:
tar._extract_member(member, path)
except Exception as exc:
# Some corrupt tar files seem to produce this
# (specifically bad symlinks)
logger.warning(
'In the tar file %s the member %s is invalid: %s',
filename, member.name, exc,
)
continue
else:
try:
fp = tar.extractfile(member)
except (KeyError, AttributeError) as exc:
# Some corrupt tar files seem to produce this
# (specifically bad symlinks)
logger.warning(
'In the tar file %s the member %s is invalid: %s',
filename, member.name, exc,
)
continue
ensure_dir(os.path.dirname(path))
with open(path, 'wb') as destfp:
shutil.copyfileobj(fp, destfp)
fp.close()
# Update the timestamp (useful for cython compiled files)
tar.utime(member, path)
# 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 unpack_file(filename, location, content_type, link):
filename = os.path.realpath(filename)
if (content_type == 'application/zip' or
filename.lower().endswith(ZIP_EXTENSIONS) or
zipfile.is_zipfile(filename)):
unzip_file(
filename,
location,
flatten=not filename.endswith('.whl')
)
elif (content_type == 'application/x-gzip' or
tarfile.is_tarfile(filename) or
filename.lower().endswith(
TAR_EXTENSIONS + BZ2_EXTENSIONS + XZ_EXTENSIONS)):
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.critical(
'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, cwd=None,
on_returncode='raise',
command_desc=None,
extra_environ=None, spinner=None):
# This function's handling of subprocess output is confusing and I
# previously broke it terribly, so as penance I will write a long comment
# explaining things.
#
# The obvious thing that affects output is the show_stdout=
# kwarg. show_stdout=True means, let the subprocess write directly to our
# stdout. Even though it is nominally the default, it is almost never used
# inside pip (and should not be used in new code without a very good
# reason); as of 2016-02-22 it is only used in a few places inside the VCS
# wrapper code. Ideally we should get rid of it entirely, because it
# creates a lot of complexity here for a rarely used feature.
#
# Most places in pip set show_stdout=False. What this means is:
# - We connect the child stdout to a pipe, which we read.
# - By default, we hide the output but show a spinner -- unless the
# subprocess exits with an error, in which case we show the output.
# - If the --verbose option was passed (= loglevel is DEBUG), then we show
# the output unconditionally. (But in this case we don't want to show
# the output a second time if it turns out that there was an error.)
#
# stderr is always merged with stdout (even if show_stdout=True).
if show_stdout:
stdout = None
else:
stdout = subprocess.PIPE
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)
logger.debug("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 as exc:
logger.critical(
"Error %s while executing command %s", exc, command_desc,
)
raise
if stdout is not None:
all_output = []
while True:
line = console_to_str(proc.stdout.readline())
if not line:
break
line = line.rstrip()
all_output.append(line + '\n')
if logger.getEffectiveLevel() <= std_logging.DEBUG:
# Show the line immediately
logger.debug(line)
else:
# Update the spinner
if spinner is not None:
spinner.spin()
proc.wait()
if spinner is not None:
if proc.returncode:
spinner.finish("error")
else:
spinner.finish("done")
if proc.returncode:
if on_returncode == 'raise':
if (logger.getEffectiveLevel() > std_logging.DEBUG and
not show_stdout):
logger.info(
'Complete output from command %s:', command_desc,
)
logger.info(
''.join(all_output) +
'\n----------------------------------------'
)
raise InstallationError(
'Command "%s" failed with error code %s in %s'
% (command_desc, proc.returncode, cwd))
elif on_returncode == 'warn':
logger.warning(
'Command "%s" had error code %s in %s',
command_desc, proc.returncode, cwd,
)
elif on_returncode == 'ignore':
pass
else:
raise ValueError('Invalid value: on_returncode=%s' %
repr(on_returncode))
if not show_stdout:
return ''.join(all_output)
def read_text_file(filename):
"""Return the contents of *filename*.
Try to decode the file contents with utf-8, the preferred system encoding
(e.g., cp1252 on some Windows machines), and latin1, in that order.
Decoding a byte string with latin1 will never raise an error. In the worst
case, the returned string will contain some garbage characters.
"""
with open(filename, 'rb') as fp:
data = fp.read()
encodings = ['utf-8', locale.getpreferredencoding(False), 'latin1']
for enc in encodings:
try:
data = data.decode(enc)
except UnicodeDecodeError:
continue
break
assert type(data) != bytes # Latin1 should have worked.
return data
def _make_build_dir(build_dir):
os.makedirs(build_dir)
write_delete_marker_file(build_dir)
class FakeFile(object):
"""Wrap a list of lines in an object with readline() to make
ConfigParser happy."""
def __init__(self, lines):
self._gen = (l for l in lines)
def readline(self):
try:
try:
return next(self._gen)
except NameError:
return self._gen.next()
except StopIteration:
return ''
def __iter__(self):
return self._gen
class StreamWrapper(StringIO):
@classmethod
def from_stream(cls, orig_stream):
cls.orig_stream = orig_stream
return cls()
# compileall.compile_dir() needs stdout.encoding to print to stdout
@property
def encoding(self):
return self.orig_stream.encoding
@contextlib.contextmanager
def captured_output(stream_name):
"""Return a context manager used by captured_stdout/stdin/stderr
that temporarily replaces the sys stream *stream_name* with a StringIO.
Taken from Lib/support/__init__.py in the CPython repo.
"""
orig_stdout = getattr(sys, stream_name)
setattr(sys, stream_name, StreamWrapper.from_stream(orig_stdout))
try:
yield getattr(sys, stream_name)
finally:
setattr(sys, stream_name, orig_stdout)
def captured_stdout():
"""Capture the output of sys.stdout:
with captured_stdout() as stdout:
print('hello')
self.assertEqual(stdout.getvalue(), 'hello\n')
Taken from Lib/support/__init__.py in the CPython repo.
"""
return captured_output('stdout')
class cached_property(object):
"""A property that is only computed once per instance and then replaces
itself with an ordinary attribute. Deleting the attribute resets the
property.
Source: https://github.com/bottlepy/bottle/blob/0.11.5/bottle.py#L175
"""
def __init__(self, func):
self.__doc__ = getattr(func, '__doc__')
self.func = func
def __get__(self, obj, cls):
if obj is None:
# We're being accessed from the class itself, not from an object
return self
value = obj.__dict__[self.func.__name__] = self.func(obj)
return value
def get_installed_version(dist_name, lookup_dirs=None):
"""Get the installed version of dist_name avoiding pkg_resources cache"""
# Create a requirement that we'll look for inside of setuptools.
req = pkg_resources.Requirement.parse(dist_name)
# We want to avoid having this cached, so we need to construct a new
# working set each time.
if lookup_dirs is None:
working_set = pkg_resources.WorkingSet()
else:
working_set = pkg_resources.WorkingSet(lookup_dirs)
# Get the installed distribution from our working set
dist = working_set.find(req)
# Check to see if we got an installed distribution or not, if we did
# we want to return it's version.
return dist.version if dist else None
def consume(iterator):
"""Consume an iterable at C speed."""
deque(iterator, maxlen=0)
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
5055,
492,
15782,
199,
646,
15502,
199,
646,
7554,
199,
646,
5890,
199,
646,
5867,
199,
3,
781,
1172,
282,
22988,
4310,
283,
4806,
7,
1314,
3955,
15084,
642,
340,
781,
1202,
314,
199,
3,
5578,
536,
26,
199,
646,
2050,
465,
2418,
63,
4806,
199,
646,
295,
199,
646,
747,
199,
646,
15454,
199,
646,
5145,
199,
646,
5672,
199,
646,
3873,
199,
646,
984,
199,
646,
13608,
199,
646,
10392,
199,
199,
504,
7305,
14,
3924,
492,
26866,
547,
199,
504,
7305,
14,
5819,
492,
8559,
63,
475,
63,
495,
12,
6544,
751,
12,
26678,
63,
16624,
199,
504,
7305,
14,
8022,
492,
334,
272,
4770,
63,
5154,
12,
922,
63,
2124,
12,
3879,
63,
7138,
63,
21611,
12,
19128,
63,
889,
63,
2966,
12,
272,
2218,
63,
1807,
63,
4211,
63,
493,
12,
199,
9,
199,
504,
7305,
423,
9884,
492,
5496,
63,
4435,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
492,
1324,
199,
504,
7305,
423,
9884,
14,
4174,
492,
7843,
18,
199,
504,
7305,
423,
9884,
14,
7154,
316,
492,
7269,
199,
199,
692,
7843,
18,
26,
272,
687,
5890,
492,
11808,
465,
5228,
199,
2836,
26,
272,
687,
5890,
492,
5228,
199,
199,
363,
452,
363,
275,
788,
9242,
297,
283,
2918,
63,
515,
297,
283,
5751,
63,
694,
297,
1779,
283,
813,
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,
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,
5301,
63,
493,
297,
283,
1250,
63,
5781,
297,
1779,
283,
28345,
63,
2703,
297,
283,
7505,
63,
694,
297,
1779,
283,
28800,
63,
18451,
297,
283,
15925,
63,
18451,
297,
1779,
283,
362,
63,
7657,
63,
1023,
418,
421,
199,
2921,
275,
2418,
63,
4806,
14,
5572,
3460,
354,
3368,
199,
199,
21338,
18,
63,
18451,
275,
23500,
5369,
14,
10582,
18,
297,
1987,
5842,
90,
358,
199,
56,
58,
63,
18451,
275,
23500,
5369,
14,
19196,
297,
1987,
2347,
90,
297,
1987,
5019,
90,
297,
1987,
5369,
14,
28997,
297,
1987,
5369,
14,
28997,
391,
358,
199,
16977,
63,
18451,
275,
23500,
3065,
297,
1987,
2191,
76,
358,
199,
52,
689,
63,
18451,
275,
23500,
5369,
14,
6838,
297,
1987,
27220,
297,
1987,
5369,
358,
199,
28800,
63,
18451,
275,
334,
272,
18402,
63,
18451,
435,
32402,
18,
63,
18451,
435,
377,
689,
63,
18451,
435,
1323,
58,
63,
18451,
9,
199,
15925,
63,
18451,
275,
18402,
63,
18451,
435,
377,
689,
63,
18451,
199,
893,
26,
272,
492,
15055,
18,
221,
327,
8151,
272,
32501,
63,
18451,
847,
32402,
18,
63,
18451,
199,
2590,
3545,
26,
272,
2512,
14,
1757,
360,
10582,
18,
859,
365,
440,
2808,
358,
199,
199,
893,
26,
272,
327,
5972,
367,
2018,
650,
14,
19,
11,
272,
492,
634,
90,
391,
221,
327,
8151,
272,
32501,
63,
18451,
847,
1323,
58,
63,
18451,
199,
2590,
3545,
26,
272,
2512,
14,
1757,
360,
28997,
391,
859,
365,
440,
2808,
358,
421,
199,
318,
492,
63,
269,
63,
3730,
8,
4600,
63,
269,
63,
578,
63,
875,
12,
2186,
804,
12,
627,
589,
12,
1011,
958,
304,
272,
862,
26,
267,
372,
636,
646,
721,
4600,
63,
269,
63,
578,
63,
875,
9,
272,
871,
3545,
26,
267,
746,
2186,
804,
2031,
589,
12,
1011,
958,
9,
421,
199,
318,
4868,
63,
694,
8,
515,
304,
272,
408,
736,
14,
515,
14,
8347,
1928,
662,
13301,
1041,
272,
862,
26,
267,
747,
14,
8347,
8,
515,
9,
272,
871,
6440,
465,
325,
26,
267,
340,
325,
14,
7931,
1137,
7554,
14,
28596,
26,
288,
746,
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,
3,
20506,
4036,
12995,
3499,
367,
1536,
370,
650,
4696,
199,
32,
7154,
8,
2379,
63,
988,
63,
5814,
29,
19962,
12,
3618,
63,
5964,
29,
5783,
9,
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,
327,
340,
570,
730,
5544,
1586,
1454,
272,
340,
747,
14,
3736,
8,
515,
680,
270,
63,
632,
1253,
5672,
14,
51,
63,
41,
5670,
26,
267,
327,
3957,
370,
1586,
15,
952,
267,
747,
14,
11693,
8,
515,
12,
5672,
14,
51,
63,
41,
10387,
9,
267,
327,
675,
314,
3379,
805,
370,
11982,
314,
3439,
267,
2562,
8,
515,
9,
267,
372,
272,
587,
26,
267,
746,
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,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
499,
26,
267,
931,
275,
931,
14,
2708,
8,
1274,
14,
23462,
32255,
1062,
283,
1814,
358,
267,
931,
275,
931,
14,
2143,
8,
1274,
14,
362,
27205,
28139,
1062,
283,
1814,
358,
272,
340,
931,
14,
2460,
8
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
5055,
492,
15782,
199,
646,
15502,
199,
646,
7554,
199,
646,
5890,
199,
646,
5867,
199,
3,
781,
1172,
282,
22988,
4310,
283,
4806,
7,
1314,
3955,
15084,
642,
340,
781,
1202,
314,
199,
3,
5578,
536,
26,
199,
646,
2050,
465,
2418,
63,
4806,
199,
646,
295,
199,
646,
747,
199,
646,
15454,
199,
646,
5145,
199,
646,
5672,
199,
646,
3873,
199,
646,
984,
199,
646,
13608,
199,
646,
10392,
199,
199,
504,
7305,
14,
3924,
492,
26866,
547,
199,
504,
7305,
14,
5819,
492,
8559,
63,
475,
63,
495,
12,
6544,
751,
12,
26678,
63,
16624,
199,
504,
7305,
14,
8022,
492,
334,
272,
4770,
63,
5154,
12,
922,
63,
2124,
12,
3879,
63,
7138,
63,
21611,
12,
19128,
63,
889,
63,
2966,
12,
272,
2218,
63,
1807,
63,
4211,
63,
493,
12,
199,
9,
199,
504,
7305,
423,
9884,
492,
5496,
63,
4435,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
492,
1324,
199,
504,
7305,
423,
9884,
14,
4174,
492,
7843,
18,
199,
504,
7305,
423,
9884,
14,
7154,
316,
492,
7269,
199,
199,
692,
7843,
18,
26,
272,
687,
5890,
492,
11808,
465,
5228,
199,
2836,
26,
272,
687,
5890,
492,
5228,
199,
199,
363,
452,
363,
275,
788,
9242,
297,
283,
2918,
63,
515,
297,
283,
5751,
63,
694,
297,
1779,
283,
813,
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,
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,
5301,
63,
493,
297,
283,
1250,
63,
5781,
297,
1779,
283,
28345,
63,
2703,
297,
283,
7505,
63,
694,
297,
1779,
283,
28800,
63,
18451,
297,
283,
15925,
63,
18451,
297,
1779,
283,
362,
63,
7657,
63,
1023,
418,
421,
199,
2921,
275,
2418,
63,
4806,
14,
5572,
3460,
354,
3368,
199,
199,
21338,
18,
63,
18451,
275,
23500,
5369,
14,
10582,
18,
297,
1987,
5842,
90,
358,
199,
56,
58,
63,
18451,
275,
23500,
5369,
14,
19196,
297,
1987,
2347,
90,
297,
1987,
5019,
90,
297,
1987,
5369,
14,
28997,
297,
1987,
5369,
14,
28997,
391,
358,
199,
16977,
63,
18451,
275,
23500,
3065,
297,
1987,
2191,
76,
358,
199,
52,
689,
63,
18451,
275,
23500,
5369,
14,
6838,
297,
1987,
27220,
297,
1987,
5369,
358,
199,
28800,
63,
18451,
275,
334,
272,
18402,
63,
18451,
435,
32402,
18,
63,
18451,
435,
377,
689,
63,
18451,
435,
1323,
58,
63,
18451,
9,
199,
15925,
63,
18451,
275,
18402,
63,
18451,
435,
377,
689,
63,
18451,
199,
893,
26,
272,
492,
15055,
18,
221,
327,
8151,
272,
32501,
63,
18451,
847,
32402,
18,
63,
18451,
199,
2590,
3545,
26,
272,
2512,
14,
1757,
360,
10582,
18,
859,
365,
440,
2808,
358,
199,
199,
893,
26,
272,
327,
5972,
367,
2018,
650,
14,
19,
11,
272,
492,
634,
90,
391,
221,
327,
8151,
272,
32501,
63,
18451,
847,
1323,
58,
63,
18451,
199,
2590,
3545,
26,
272,
2512,
14,
1757,
360,
28997,
391,
859,
365,
440,
2808,
358,
421,
199,
318,
492,
63,
269,
63,
3730,
8,
4600,
63,
269,
63,
578,
63,
875,
12,
2186,
804,
12,
627,
589,
12,
1011,
958,
304,
272,
862,
26,
267,
372,
636,
646,
721,
4600,
63,
269,
63,
578,
63,
875,
9,
272,
871,
3545,
26,
267,
746,
2186,
804,
2031,
589,
12,
1011,
958,
9,
421,
199,
318,
4868,
63,
694,
8,
515,
304,
272,
408,
736,
14,
515,
14,
8347,
1928,
662,
13301,
1041,
272,
862,
26,
267,
747,
14,
8347,
8,
515,
9,
272,
871,
6440,
465,
325,
26,
267,
340,
325,
14,
7931,
1137,
7554,
14,
28596,
26,
288,
746,
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,
3,
20506,
4036,
12995,
3499,
367,
1536,
370,
650,
4696,
199,
32,
7154,
8,
2379,
63,
988,
63,
5814,
29,
19962,
12,
3618,
63,
5964,
29,
5783,
9,
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,
327,
340,
570,
730,
5544,
1586,
1454,
272,
340,
747,
14,
3736,
8,
515,
680,
270,
63,
632,
1253,
5672,
14,
51,
63,
41,
5670,
26,
267,
327,
3957,
370,
1586,
15,
952,
267,
747,
14,
11693,
8,
515,
12,
5672,
14,
51,
63,
41,
10387,
9,
267,
327,
675,
314,
3379,
805,
370,
11982,
314,
3439,
267,
2562,
8,
515,
9,
267,
372,
272,
587,
26,
267,
746,
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,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
499,
26,
267,
931,
275,
931,
14,
2708,
8,
1274,
14,
23462,
32255,
1062,
283,
1814,
358,
267,
931,
275,
931,
14,
2143,
8,
1274,
14,
362,
27205,
28139,
1062,
283,
1814,
358,
272,
340,
931,
14,
2460,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
zephg/parallel-ssh
|
psshlib/task.py
|
63
|
10081
|
# Copyright (c) 2009-2012, Andrew McNabb
from errno import EINTR
from subprocess import Popen, PIPE
import os
import signal
import sys
import time
import traceback
from psshlib import askpass_client
from psshlib import color
BUFFER_SIZE = 1 << 16
try:
bytes
except NameError:
bytes = str
class Task(object):
"""Starts a process and manages its input and output.
Upon completion, the `exitstatus` attribute is set to the exit status
of the process.
"""
def __init__(self, host, port, user, cmd, opts, stdin=None):
self.exitstatus = None
self.host = host
self.pretty_host = host
self.port = port
self.cmd = cmd
if user != opts.user:
self.pretty_host = '@'.join((user, self.pretty_host))
if port:
self.pretty_host = ':'.join((self.pretty_host, port))
self.proc = None
self.writer = None
self.timestamp = None
self.failures = []
self.killed = False
self.inputbuffer = stdin
self.byteswritten = 0
self.outputbuffer = bytes()
self.errorbuffer = bytes()
self.stdin = None
self.stdout = None
self.stderr = None
self.outfile = None
self.errfile = None
# Set options.
self.verbose = opts.verbose
try:
self.print_out = bool(opts.print_out)
except AttributeError:
self.print_out = False
try:
self.inline = bool(opts.inline)
except AttributeError:
self.inline = False
try:
self.inline_stdout = bool(opts.inline_stdout)
except AttributeError:
self.inline_stdout = False
def start(self, nodenum, iomap, writer, askpass_socket=None):
"""Starts the process and registers files with the IOMap."""
self.writer = writer
if writer:
self.outfile, self.errfile = writer.open_files(self.pretty_host)
# Set up the environment.
environ = dict(os.environ)
environ['PSSH_NODENUM'] = str(nodenum)
environ['PSSH_HOST'] = self.host
# Disable the GNOME pop-up password dialog and allow ssh to use
# askpass.py to get a provided password. If the module file is
# askpass.pyc, we replace the extension.
environ['SSH_ASKPASS'] = askpass_client.executable_path()
if askpass_socket:
environ['PSSH_ASKPASS_SOCKET'] = askpass_socket
if self.verbose:
environ['PSSH_ASKPASS_VERBOSE'] = '1'
# Work around a mis-feature in ssh where it won't call SSH_ASKPASS
# if DISPLAY is unset.
if 'DISPLAY' not in environ:
environ['DISPLAY'] = 'pssh-gibberish'
# Create the subprocess. Since we carefully call set_cloexec() on
# all open files, we specify close_fds=False.
self.proc = Popen(self.cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
close_fds=False, preexec_fn=os.setsid, env=environ)
self.timestamp = time.time()
if self.inputbuffer:
self.stdin = self.proc.stdin
iomap.register_write(self.stdin.fileno(), self.handle_stdin)
else:
self.proc.stdin.close()
self.stdout = self.proc.stdout
iomap.register_read(self.stdout.fileno(), self.handle_stdout)
self.stderr = self.proc.stderr
iomap.register_read(self.stderr.fileno(), self.handle_stderr)
def _kill(self):
"""Signals the process to terminate."""
if self.proc:
try:
os.kill(-self.proc.pid, signal.SIGKILL)
except OSError:
# If the kill fails, then just assume the process is dead.
pass
self.killed = True
def timedout(self):
"""Kills the process and registers a timeout error."""
if not self.killed:
self._kill()
self.failures.append('Timed out')
def interrupted(self):
"""Kills the process and registers an keyboard interrupt error."""
if not self.killed:
self._kill()
self.failures.append('Interrupted')
def cancel(self):
"""Stops a task that has not started."""
self.failures.append('Cancelled')
def elapsed(self):
"""Finds the time in seconds since the process was started."""
return time.time() - self.timestamp
def running(self):
"""Finds if the process has terminated and saves the return code."""
if self.stdin or self.stdout or self.stderr:
return True
if self.proc:
self.exitstatus = self.proc.poll()
if self.exitstatus is None:
if self.killed:
# Set the exitstatus to what it would be if we waited.
self.exitstatus = -signal.SIGKILL
return False
else:
return True
else:
if self.exitstatus < 0:
message = 'Killed by signal %s' % (-self.exitstatus)
self.failures.append(message)
elif self.exitstatus > 0:
message = 'Exited with error code %s' % self.exitstatus
self.failures.append(message)
self.proc = None
return False
def handle_stdin(self, fd, iomap):
"""Called when the process's standard input is ready for writing."""
try:
start = self.byteswritten
if start < len(self.inputbuffer):
chunk = self.inputbuffer[start:start+BUFFER_SIZE]
self.byteswritten = start + os.write(fd, chunk)
else:
self.close_stdin(iomap)
except (OSError, IOError):
_, e, _ = sys.exc_info()
if e.errno != EINTR:
self.close_stdin(iomap)
self.log_exception(e)
def close_stdin(self, iomap):
if self.stdin:
iomap.unregister(self.stdin.fileno())
self.stdin.close()
self.stdin = None
def handle_stdout(self, fd, iomap):
"""Called when the process's standard output is ready for reading."""
try:
buf = os.read(fd, BUFFER_SIZE)
if buf:
if self.inline or self.inline_stdout:
self.outputbuffer += buf
if self.outfile:
self.writer.write(self.outfile, buf)
if self.print_out:
sys.stdout.write('%s: %s' % (self.host, buf))
if buf[-1] != '\n':
sys.stdout.write('\n')
else:
self.close_stdout(iomap)
except (OSError, IOError):
_, e, _ = sys.exc_info()
if e.errno != EINTR:
self.close_stdout(iomap)
self.log_exception(e)
def close_stdout(self, iomap):
if self.stdout:
iomap.unregister(self.stdout.fileno())
self.stdout.close()
self.stdout = None
if self.outfile:
self.writer.close(self.outfile)
self.outfile = None
def handle_stderr(self, fd, iomap):
"""Called when the process's standard error is ready for reading."""
try:
buf = os.read(fd, BUFFER_SIZE)
if buf:
if self.inline:
self.errorbuffer += buf
if self.errfile:
self.writer.write(self.errfile, buf)
else:
self.close_stderr(iomap)
except (OSError, IOError):
_, e, _ = sys.exc_info()
if e.errno != EINTR:
self.close_stderr(iomap)
self.log_exception(e)
def close_stderr(self, iomap):
if self.stderr:
iomap.unregister(self.stderr.fileno())
self.stderr.close()
self.stderr = None
if self.errfile:
self.writer.close(self.errfile)
self.errfile = None
def log_exception(self, e):
"""Saves a record of the most recent exception for error reporting."""
if self.verbose:
exc_type, exc_value, exc_traceback = sys.exc_info()
exc = ("Exception: %s, %s, %s" %
(exc_type, exc_value, traceback.format_tb(exc_traceback)))
else:
exc = str(e)
self.failures.append(exc)
def report(self, n):
"""Pretty prints a status report after the Task completes."""
error = ', '.join(self.failures)
tstamp = time.asctime().split()[3] # Current time
if color.has_colors(sys.stdout):
progress = color.c("[%s]" % color.B(n))
success = color.g("[%s]" % color.B("SUCCESS"))
failure = color.r("[%s]" % color.B("FAILURE"))
stderr = color.r("Stderr: ")
error = color.r(color.B(error))
else:
progress = "[%s]" % n
success = "[SUCCESS]"
failure = "[FAILURE]"
stderr = "Stderr: "
host = self.pretty_host
if self.failures:
print(' '.join((progress, tstamp, failure, host, error)))
else:
print(' '.join((progress, tstamp, success, host)))
# NOTE: The extra flushes are to ensure that the data is output in
# the correct order with the C implementation of io.
if self.outputbuffer:
sys.stdout.flush()
try:
sys.stdout.buffer.write(self.outputbuffer)
sys.stdout.flush()
except AttributeError:
sys.stdout.write(self.outputbuffer)
if self.errorbuffer:
sys.stdout.write(stderr)
# Flush the TextIOWrapper before writing to the binary buffer.
sys.stdout.flush()
try:
sys.stdout.buffer.write(self.errorbuffer)
except AttributeError:
sys.stdout.write(self.errorbuffer)
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
8937,
13,
7409,
12,
6061,
5257,
22895,
46,
12198,
199,
199,
504,
7554,
492,
662,
19652,
199,
504,
3873,
492,
13995,
12,
22773,
199,
646,
747,
199,
646,
4673,
199,
646,
984,
199,
646,
900,
199,
646,
5190,
199,
199,
504,
299,
5510,
773,
492,
7198,
1529,
63,
1258,
199,
504,
299,
5510,
773,
492,
3164,
199,
199,
10960,
63,
4305,
275,
413,
5213,
3193,
199,
199,
893,
26,
272,
2783,
199,
2590,
12746,
26,
272,
2783,
275,
620,
421,
199,
533,
8495,
8,
785,
304,
272,
408,
32142,
282,
2112,
436,
31965,
2399,
1324,
436,
1072,
14,
339,
738,
678,
13659,
12,
314,
658,
2224,
1205,
64,
2225,
365,
663,
370,
314,
4458,
2004,
272,
402,
314,
2112,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1591,
12,
1844,
12,
922,
12,
2088,
12,
3999,
12,
9009,
29,
403,
304,
267,
291,
14,
2224,
1205,
275,
488,
398,
291,
14,
1102,
275,
1591,
267,
291,
14,
9118,
63,
1102,
275,
1591,
267,
291,
14,
719,
275,
1844,
267,
291,
14,
1760,
275,
2088,
398,
340,
922,
1137,
3999,
14,
751,
26,
288,
291,
14,
9118,
63,
1102,
275,
10267,
1370,
904,
1332,
751,
12,
291,
14,
9118,
63,
1102,
430,
267,
340,
1844,
26,
288,
291,
14,
9118,
63,
1102,
275,
29010,
904,
1332,
277,
14,
9118,
63,
1102,
12,
1844,
430,
398,
291,
14,
4687,
275,
488,
267,
291,
14,
5491,
275,
488,
267,
291,
14,
3954,
275,
488,
267,
291,
14,
9968,
275,
942,
267,
291,
14,
75,
14535,
275,
756,
267,
291,
14,
1210,
2738,
275,
9009,
267,
291,
14,
2394,
8938,
275,
378,
267,
291,
14,
1199,
2738,
275,
2783,
342,
267,
291,
14,
705,
2738,
275,
2783,
342,
398,
291,
14,
6626,
275,
488,
267,
291,
14,
2703,
275,
488,
267,
291,
14,
3083,
275,
488,
267,
291,
14,
4984,
275,
488,
267,
291,
14,
1508,
493,
275,
488,
398,
327,
2494,
1511,
14,
267,
291,
14,
3832,
275,
3999,
14,
3832,
267,
862,
26,
288,
291,
14,
1361,
63,
548,
275,
2155,
8,
3291,
14,
1361,
63,
548,
9,
267,
871,
4281,
26,
288,
291,
14,
1361,
63,
548,
275,
756,
267,
862,
26,
288,
291,
14,
6460,
275,
2155,
8,
3291,
14,
6460,
9,
267,
871,
4281,
26,
288,
291,
14,
6460,
275,
756,
267,
862,
26,
288,
291,
14,
6460,
63,
2703,
275,
2155,
8,
3291,
14,
6460,
63,
2703,
9,
267,
871,
4281,
26,
288,
291,
14,
6460,
63,
2703,
275,
756,
339,
347,
1343,
8,
277,
12,
1031,
1507,
12,
5890,
1130,
12,
7060,
12,
7198,
1529,
63,
3450,
29,
403,
304,
267,
408,
32142,
314,
2112,
436,
24493,
1584,
543,
314,
5004,
2956,
1041,
267,
291,
14,
5491,
275,
7060,
398,
340,
7060,
26,
288,
291,
14,
4984,
12,
291,
14,
1508,
493,
275,
7060,
14,
1490,
63,
1725,
8,
277,
14,
9118,
63,
1102,
9,
398,
327,
2494,
1536,
314,
3734,
14,
267,
6160,
275,
1211,
8,
736,
14,
2314,
9,
267,
6160,
459,
48,
13716,
63,
2826,
36,
17563,
418,
275,
620,
8,
932,
1507,
9,
267,
6160,
459,
48,
13716,
63,
5449,
418,
275,
291,
14,
1102,
267,
327,
17534,
314,
598,
2826,
3635,
4560,
13,
384,
2505,
9592,
436,
2040,
8635,
370,
675,
267,
327,
7198,
1529,
14,
647,
370,
664,
282,
2741,
2505,
14,
221,
982,
314,
859,
570,
365,
267,
327,
7198,
1529,
14,
11357,
12,
781,
3350,
314,
3329,
14,
267,
6160,
459,
13716,
63,
7946,
6909,
418,
275,
7198,
1529,
63,
1258,
14,
5904,
63,
515,
342,
267,
340,
7198,
1529,
63,
3450,
26,
288,
6160,
459,
48,
13716,
63,
7946,
6909,
63,
17462,
418,
275,
7198,
1529,
63,
3450,
267,
340,
291,
14,
3832,
26,
288,
6160,
459,
48,
13716,
63,
7946,
6909,
63,
16075,
418,
275,
283,
17,
7,
267,
327,
9361,
6818,
282,
3201,
13,
4445,
315,
8635,
2382,
652,
7859,
1133,
1240,
12027,
63,
7946,
6909,
267,
327,
340,
7587,
11625,
365,
15376,
14,
267,
340,
283,
20993,
7,
440,
315,
6160,
26,
288,
6160,
459,
20993,
418,
275,
283,
80,
5510,
13,
71,
1892,
605,
2453,
7,
398,
327,
2790,
314,
3873,
14,
221,
9336,
781,
21191,
8525,
1240,
663,
63,
1251,
1628,
342,
641,
267,
327,
1006,
1551,
1584,
12,
781,
4165,
4002,
63,
14240,
29,
797,
14,
267,
291,
14,
4687,
275,
13995,
8,
277,
14,
1760,
12,
9009,
29,
6089,
12,
3839,
29,
6089,
12,
4635,
29,
6089,
12,
355,
4002,
63,
14240,
29,
797,
12,
876,
1628,
63,
2324,
29,
736,
14,
409,
4148,
12,
2589,
29,
2314,
9,
267,
291,
14,
3954,
275,
900,
14,
521,
342,
267,
340,
291,
14,
1210,
2738,
26,
288,
291,
14,
6626,
275,
291,
14,
4687,
14,
6626,
288,
5890,
1130,
14,
2683,
63,
952,
8,
277,
14,
6626,
14,
9843,
1062,
291,
14,
2479,
63,
6626,
9,
267,
587,
26,
288,
291,
14,
4687,
14,
6626,
14,
1600,
342,
267,
291,
14,
2703,
275,
291,
14,
4687,
14,
2703,
267,
5890,
1130,
14,
2683,
63,
739,
8,
277,
14,
2703,
14,
9843,
1062,
291,
14,
2479,
63,
2703,
9,
267,
291,
14,
3083,
275,
291,
14,
4687,
14,
3083,
267,
5890,
1130,
14,
2683,
63,
739,
8,
277,
14,
3083,
14,
9843,
1062,
291,
14,
2479,
63,
3083,
9,
339,
347,
485,
8997,
8,
277,
304,
267,
408,
28536,
314,
2112,
370,
15095,
1041,
267,
340,
291,
14,
4687,
26,
288,
862,
26,
355,
747,
14,
8997,
2801,
277,
14,
4687,
14,
3150,
12,
4673,
14,
7864,
30691,
9,
288,
871,
6440,
26,
355,
327,
982,
314,
14561,
6918,
12,
2066,
2951,
5534,
314,
2112,
365,
12314,
14,
355,
986,
288,
291,
14,
75,
14535,
275,
715,
339,
347,
18590,
548,
8,
277,
304,
267,
408,
43,
15350,
314,
2112,
436,
24493,
282,
2653,
1125,
1041,
267,
340,
440,
291,
14,
75,
14535,
26,
288,
291,
423,
8997,
342,
288,
291,
14,
9968,
14,
740,
360,
28682,
734,
358,
339,
347,
31366,
8,
277,
304,
267,
408,
43,
15350,
314,
2112,
436,
24493,
376,
18716,
26791,
1125,
1041,
267,
340,
440,
291,
14,
75,
14535,
26,
288,
291,
423,
8997
] |
[
1898,
334,
67,
9,
8937,
13,
7409,
12,
6061,
5257,
22895,
46,
12198,
199,
199,
504,
7554,
492,
662,
19652,
199,
504,
3873,
492,
13995,
12,
22773,
199,
646,
747,
199,
646,
4673,
199,
646,
984,
199,
646,
900,
199,
646,
5190,
199,
199,
504,
299,
5510,
773,
492,
7198,
1529,
63,
1258,
199,
504,
299,
5510,
773,
492,
3164,
199,
199,
10960,
63,
4305,
275,
413,
5213,
3193,
199,
199,
893,
26,
272,
2783,
199,
2590,
12746,
26,
272,
2783,
275,
620,
421,
199,
533,
8495,
8,
785,
304,
272,
408,
32142,
282,
2112,
436,
31965,
2399,
1324,
436,
1072,
14,
339,
738,
678,
13659,
12,
314,
658,
2224,
1205,
64,
2225,
365,
663,
370,
314,
4458,
2004,
272,
402,
314,
2112,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1591,
12,
1844,
12,
922,
12,
2088,
12,
3999,
12,
9009,
29,
403,
304,
267,
291,
14,
2224,
1205,
275,
488,
398,
291,
14,
1102,
275,
1591,
267,
291,
14,
9118,
63,
1102,
275,
1591,
267,
291,
14,
719,
275,
1844,
267,
291,
14,
1760,
275,
2088,
398,
340,
922,
1137,
3999,
14,
751,
26,
288,
291,
14,
9118,
63,
1102,
275,
10267,
1370,
904,
1332,
751,
12,
291,
14,
9118,
63,
1102,
430,
267,
340,
1844,
26,
288,
291,
14,
9118,
63,
1102,
275,
29010,
904,
1332,
277,
14,
9118,
63,
1102,
12,
1844,
430,
398,
291,
14,
4687,
275,
488,
267,
291,
14,
5491,
275,
488,
267,
291,
14,
3954,
275,
488,
267,
291,
14,
9968,
275,
942,
267,
291,
14,
75,
14535,
275,
756,
267,
291,
14,
1210,
2738,
275,
9009,
267,
291,
14,
2394,
8938,
275,
378,
267,
291,
14,
1199,
2738,
275,
2783,
342,
267,
291,
14,
705,
2738,
275,
2783,
342,
398,
291,
14,
6626,
275,
488,
267,
291,
14,
2703,
275,
488,
267,
291,
14,
3083,
275,
488,
267,
291,
14,
4984,
275,
488,
267,
291,
14,
1508,
493,
275,
488,
398,
327,
2494,
1511,
14,
267,
291,
14,
3832,
275,
3999,
14,
3832,
267,
862,
26,
288,
291,
14,
1361,
63,
548,
275,
2155,
8,
3291,
14,
1361,
63,
548,
9,
267,
871,
4281,
26,
288,
291,
14,
1361,
63,
548,
275,
756,
267,
862,
26,
288,
291,
14,
6460,
275,
2155,
8,
3291,
14,
6460,
9,
267,
871,
4281,
26,
288,
291,
14,
6460,
275,
756,
267,
862,
26,
288,
291,
14,
6460,
63,
2703,
275,
2155,
8,
3291,
14,
6460,
63,
2703,
9,
267,
871,
4281,
26,
288,
291,
14,
6460,
63,
2703,
275,
756,
339,
347,
1343,
8,
277,
12,
1031,
1507,
12,
5890,
1130,
12,
7060,
12,
7198,
1529,
63,
3450,
29,
403,
304,
267,
408,
32142,
314,
2112,
436,
24493,
1584,
543,
314,
5004,
2956,
1041,
267,
291,
14,
5491,
275,
7060,
398,
340,
7060,
26,
288,
291,
14,
4984,
12,
291,
14,
1508,
493,
275,
7060,
14,
1490,
63,
1725,
8,
277,
14,
9118,
63,
1102,
9,
398,
327,
2494,
1536,
314,
3734,
14,
267,
6160,
275,
1211,
8,
736,
14,
2314,
9,
267,
6160,
459,
48,
13716,
63,
2826,
36,
17563,
418,
275,
620,
8,
932,
1507,
9,
267,
6160,
459,
48,
13716,
63,
5449,
418,
275,
291,
14,
1102,
267,
327,
17534,
314,
598,
2826,
3635,
4560,
13,
384,
2505,
9592,
436,
2040,
8635,
370,
675,
267,
327,
7198,
1529,
14,
647,
370,
664,
282,
2741,
2505,
14,
221,
982,
314,
859,
570,
365,
267,
327,
7198,
1529,
14,
11357,
12,
781,
3350,
314,
3329,
14,
267,
6160,
459,
13716,
63,
7946,
6909,
418,
275,
7198,
1529,
63,
1258,
14,
5904,
63,
515,
342,
267,
340,
7198,
1529,
63,
3450,
26,
288,
6160,
459,
48,
13716,
63,
7946,
6909,
63,
17462,
418,
275,
7198,
1529,
63,
3450,
267,
340,
291,
14,
3832,
26,
288,
6160,
459,
48,
13716,
63,
7946,
6909,
63,
16075,
418,
275,
283,
17,
7,
267,
327,
9361,
6818,
282,
3201,
13,
4445,
315,
8635,
2382,
652,
7859,
1133,
1240,
12027,
63,
7946,
6909,
267,
327,
340,
7587,
11625,
365,
15376,
14,
267,
340,
283,
20993,
7,
440,
315,
6160,
26,
288,
6160,
459,
20993,
418,
275,
283,
80,
5510,
13,
71,
1892,
605,
2453,
7,
398,
327,
2790,
314,
3873,
14,
221,
9336,
781,
21191,
8525,
1240,
663,
63,
1251,
1628,
342,
641,
267,
327,
1006,
1551,
1584,
12,
781,
4165,
4002,
63,
14240,
29,
797,
14,
267,
291,
14,
4687,
275,
13995,
8,
277,
14,
1760,
12,
9009,
29,
6089,
12,
3839,
29,
6089,
12,
4635,
29,
6089,
12,
355,
4002,
63,
14240,
29,
797,
12,
876,
1628,
63,
2324,
29,
736,
14,
409,
4148,
12,
2589,
29,
2314,
9,
267,
291,
14,
3954,
275,
900,
14,
521,
342,
267,
340,
291,
14,
1210,
2738,
26,
288,
291,
14,
6626,
275,
291,
14,
4687,
14,
6626,
288,
5890,
1130,
14,
2683,
63,
952,
8,
277,
14,
6626,
14,
9843,
1062,
291,
14,
2479,
63,
6626,
9,
267,
587,
26,
288,
291,
14,
4687,
14,
6626,
14,
1600,
342,
267,
291,
14,
2703,
275,
291,
14,
4687,
14,
2703,
267,
5890,
1130,
14,
2683,
63,
739,
8,
277,
14,
2703,
14,
9843,
1062,
291,
14,
2479,
63,
2703,
9,
267,
291,
14,
3083,
275,
291,
14,
4687,
14,
3083,
267,
5890,
1130,
14,
2683,
63,
739,
8,
277,
14,
3083,
14,
9843,
1062,
291,
14,
2479,
63,
3083,
9,
339,
347,
485,
8997,
8,
277,
304,
267,
408,
28536,
314,
2112,
370,
15095,
1041,
267,
340,
291,
14,
4687,
26,
288,
862,
26,
355,
747,
14,
8997,
2801,
277,
14,
4687,
14,
3150,
12,
4673,
14,
7864,
30691,
9,
288,
871,
6440,
26,
355,
327,
982,
314,
14561,
6918,
12,
2066,
2951,
5534,
314,
2112,
365,
12314,
14,
355,
986,
288,
291,
14,
75,
14535,
275,
715,
339,
347,
18590,
548,
8,
277,
304,
267,
408,
43,
15350,
314,
2112,
436,
24493,
282,
2653,
1125,
1041,
267,
340,
440,
291,
14,
75,
14535,
26,
288,
291,
423,
8997,
342,
288,
291,
14,
9968,
14,
740,
360,
28682,
734,
358,
339,
347,
31366,
8,
277,
304,
267,
408,
43,
15350,
314,
2112,
436,
24493,
376,
18716,
26791,
1125,
1041,
267,
340,
440,
291,
14,
75,
14535,
26,
288,
291,
423,
8997,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Chedi/airflow
|
airflow/operators/sqlite_operator.py
|
9
|
1088
|
import logging
from airflow.hooks import SqliteHook
from airflow.models import BaseOperator
from airflow.utils import apply_defaults
class SqliteOperator(BaseOperator):
"""
Executes sql code in a specific Sqlite database
:param sqlite_conn_id: reference to a specific sqlite database
:type sqlite_conn_id: string
:param sql: the sql code to be executed
:type sql: string or string pointing to a template file. File must have
a '.sql' extensions.
"""
template_fields = ('sql',)
template_ext = ('.sql',)
ui_color = '#cdaaed'
@apply_defaults
def __init__(
self, sql, sqlite_conn_id='sqlite_default', parameters=None,
*args, **kwargs):
super(SqliteOperator, self).__init__(*args, **kwargs)
self.sqlite_conn_id = sqlite_conn_id
self.sql = sql
self.parameters = parameters or []
def execute(self, context):
logging.info('Executing: ' + self.sql)
hook = SqliteHook(sqlite_conn_id=self.sqlite_conn_id)
hook.run(self.sql, parameters=self.parameters)
|
apache-2.0
|
[
646,
2050,
199,
199,
504,
16321,
14,
7922,
492,
428,
29498,
8481,
199,
504,
16321,
14,
992,
492,
3523,
7961,
199,
504,
16321,
14,
1208,
492,
4838,
63,
4322,
421,
199,
533,
428,
29498,
7961,
8,
1563,
7961,
304,
272,
408,
272,
9434,
3862,
3875,
1233,
315,
282,
2488,
428,
29498,
3050,
339,
520,
635,
11723,
63,
1631,
63,
344,
26,
3659,
370,
282,
2488,
11723,
3050,
272,
520,
466,
11723,
63,
1631,
63,
344,
26,
1059,
272,
520,
635,
3875,
26,
314,
3875,
1233,
370,
506,
7934,
272,
520,
466,
3875,
26,
1059,
503,
1059,
20686,
370,
282,
1978,
570,
14,
3814,
1471,
1172,
267,
282,
1987,
3009,
7,
5478,
14,
272,
408,
339,
1978,
63,
955,
275,
661,
3009,
9538,
272,
1978,
63,
832,
275,
23500,
3009,
9538,
272,
8574,
63,
2326,
275,
3943,
67,
30908,
379,
7,
339,
768,
4998,
63,
4322,
272,
347,
636,
826,
721,
288,
291,
12,
3875,
12,
11723,
63,
1631,
63,
344,
534,
10659,
63,
885,
297,
2633,
29,
403,
12,
288,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
24614,
5333,
7961,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
10659,
63,
1631,
63,
344,
275,
11723,
63,
1631,
63,
344,
267,
291,
14,
3009,
275,
3875,
267,
291,
14,
3214,
275,
2633,
503,
942,
339,
347,
5341,
8,
277,
12,
1067,
304,
267,
2050,
14,
815,
360,
4858,
4655,
26,
283,
435,
291,
14,
3009,
9,
267,
5759,
275,
428,
29498,
8481,
8,
10659,
63,
1631,
63,
344,
29,
277,
14,
10659,
63,
1631,
63,
344,
9,
267,
5759,
14,
1065,
8,
277,
14,
3009,
12,
2633,
29,
277,
14,
3214,
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
] |
[
2050,
199,
199,
504,
16321,
14,
7922,
492,
428,
29498,
8481,
199,
504,
16321,
14,
992,
492,
3523,
7961,
199,
504,
16321,
14,
1208,
492,
4838,
63,
4322,
421,
199,
533,
428,
29498,
7961,
8,
1563,
7961,
304,
272,
408,
272,
9434,
3862,
3875,
1233,
315,
282,
2488,
428,
29498,
3050,
339,
520,
635,
11723,
63,
1631,
63,
344,
26,
3659,
370,
282,
2488,
11723,
3050,
272,
520,
466,
11723,
63,
1631,
63,
344,
26,
1059,
272,
520,
635,
3875,
26,
314,
3875,
1233,
370,
506,
7934,
272,
520,
466,
3875,
26,
1059,
503,
1059,
20686,
370,
282,
1978,
570,
14,
3814,
1471,
1172,
267,
282,
1987,
3009,
7,
5478,
14,
272,
408,
339,
1978,
63,
955,
275,
661,
3009,
9538,
272,
1978,
63,
832,
275,
23500,
3009,
9538,
272,
8574,
63,
2326,
275,
3943,
67,
30908,
379,
7,
339,
768,
4998,
63,
4322,
272,
347,
636,
826,
721,
288,
291,
12,
3875,
12,
11723,
63,
1631,
63,
344,
534,
10659,
63,
885,
297,
2633,
29,
403,
12,
288,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
24614,
5333,
7961,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
10659,
63,
1631,
63,
344,
275,
11723,
63,
1631,
63,
344,
267,
291,
14,
3009,
275,
3875,
267,
291,
14,
3214,
275,
2633,
503,
942,
339,
347,
5341,
8,
277,
12,
1067,
304,
267,
2050,
14,
815,
360,
4858,
4655,
26,
283,
435,
291,
14,
3009,
9,
267,
5759,
275,
428,
29498,
8481,
8,
10659,
63,
1631,
63,
344,
29,
277,
14,
10659,
63,
1631,
63,
344,
9,
267,
5759,
14,
1065,
8,
277,
14,
3009,
12,
2633,
29,
277,
14,
3214,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
scieloorg/processing
|
publication/documents_dates.py
|
1
|
9255
|
# coding: utf-8
"""
Este processamento gera uma tabulação de datas do artigo (publicação, submissão,
aceite, entrada no scieloe atualização no scielo)
"""
import argparse
import logging
import codecs
import datetime
import xylose.scielodocument
import utils
import choices
logger = logging.getLogger(__name__)
def _config_logging(logging_level='INFO', logging_file=None):
allowed_levels = {
'DEBUG': logging.DEBUG,
'INFO': logging.INFO,
'WARNING': logging.WARNING,
'ERROR': logging.ERROR,
'CRITICAL': logging.CRITICAL
}
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger.setLevel(allowed_levels.get(logging_level, 'INFO'))
if logging_file:
hl = logging.FileHandler(logging_file, mode='a')
else:
hl = logging.StreamHandler()
hl.setFormatter(formatter)
hl.setLevel(allowed_levels.get(logging_level, 'INFO'))
logger.addHandler(hl)
return logger
class Dumper(object):
def __init__(self, collection, issns=None, output_file=None):
self._ratchet = utils.ratchet_server()
self._articlemeta = utils.articlemeta_server()
self.collection = collection
self.issns = issns
self.output_file = codecs.open(output_file, 'w', encoding='utf-8') if output_file else output_file
header = []
header.append(u"extraction date")
header.append(u"study unit")
header.append(u"collection")
header.append(u"ISSN SciELO")
header.append(u"ISSN\'s")
header.append(u"title at SciELO")
header.append(u"title thematic areas")
for area in choices.THEMATIC_AREAS:
header.append(u"title is %s" % area.lower())
header.append(u"title is multidisciplinary")
header.append(u"title current status")
header.append(u"document publishing ID (PID SciELO)")
header.append(u"document publishing year")
header.append(u"document type")
header.append(u"document is citable")
header.append(u"document submitted at")
header.append(u"document submitted at year")
header.append(u"document submitted at month")
header.append(u"document submitted at day")
header.append(u"document accepted at")
header.append(u"document accepted at year")
header.append(u"document accepted at month")
header.append(u"document accepted at day")
header.append(u"document reviewed at")
header.append(u"document reviewed at year")
header.append(u"document reviewed at month")
header.append(u"document reviewed at day")
header.append(u"document published as ahead of print at")
header.append(u"document published as ahead of print at year")
header.append(u"document published as ahead of print at month")
header.append(u"document published as ahead of print at day")
header.append(u"document published at")
header.append(u"document published at year")
header.append(u"document published at month")
header.append(u"document published at day")
header.append(u"document published in SciELO at")
header.append(u"document published in SciELO at year")
header.append(u"document published in SciELO at month")
header.append(u"document published in SciELO at day")
header.append(u"document updated in SciELO at")
header.append(u"document updated in SciELO at year")
header.append(u"document updated in SciELO at month")
header.append(u"document updated in SciELO at day")
self.write(u','.join([u'"%s"' % i.replace(u'"', u'""') for i in header]))
def write(self, line):
if not self.output_file:
print(line.encode('utf-8'))
else:
self.output_file.write('%s\r\n' % line)
def run(self):
for item in self.items():
self.write(item)
logger.info('Export finished')
def items(self):
if not self.issns:
self.issns = [None]
for issn in self.issns:
for data in self._articlemeta.documents(collection=self.collection, issn=issn):
logger.debug('Reading document: %s' % data.publisher_id)
yield self.fmt_csv(data)
def fmt_csv(self, data):
document_publication_date = (
data.document_publication_date or
data.creation_date or
data.update_date or
''
)
document_publication_date_splitted = utils.split_date(
document_publication_date)
issue_publication_date = data.issue_publication_date
issue_publication_date_splitted = utils.split_date(
issue_publication_date)
issns = []
if data.journal.print_issn:
issns.append(data.journal.print_issn)
if data.journal.electronic_issn:
issns.append(data.journal.electronic_issn)
line = []
line.append(datetime.datetime.now().isoformat()[0:10])
line.append(u'document')
line.append(data.collection_acronym)
line.append(data.journal.scielo_issn)
line.append(u';'.join(issns))
line.append(data.journal.title)
line.append(u';'.join(data.journal.subject_areas or []))
for area in choices.THEMATIC_AREAS:
if area.lower() in [i.lower() for i in data.journal.subject_areas or []]:
line.append(u'1')
else:
line.append(u'0')
line.append('1' if len(data.journal.subject_areas or []) > 2 else '0')
line.append(data.journal.current_status)
line.append(data.publisher_id)
line.append(document_publication_date_splitted[0])
line.append(data.document_type)
line.append(u'1' if data.document_type.lower() in choices.CITABLE_DOCUMENT_TYPES else '0')
line.append(data.receive_date or '')
receive_splited = utils.split_date(data.receive_date or '')
line.append(receive_splited[0]) # year
line.append(receive_splited[1]) # month
line.append(receive_splited[2]) # day
line.append(data.acceptance_date or '')
acceptance_splited = utils.split_date(data.acceptance_date or '')
line.append(acceptance_splited[0]) # year
line.append(acceptance_splited[1]) # month
line.append(acceptance_splited[2]) # day
line.append(data.review_date or '')
review_splited = utils.split_date(data.review_date or '')
line.append(review_splited[0]) # year
line.append(review_splited[1]) # month
line.append(review_splited[2]) # day
try:
aop_pubdate = data.ahead_publication_date or ''
except xylose.scielodocument.UnavailableMetadataException:
aop_pubdate = ''
line.append(aop_pubdate)
ahead_publication_date_splited = utils.split_date(aop_pubdate)
line.append(ahead_publication_date_splited[0]) # year
line.append(ahead_publication_date_splited[1]) # month
line.append(ahead_publication_date_splited[2]) # day
# u"document published at" (collection ou issue)
line.append(issue_publication_date)
line.append(issue_publication_date_splitted[0]) # year
line.append(issue_publication_date_splitted[1]) # month
line.append(issue_publication_date_splitted[2]) # day
#u"document published in SciELO at" (pub, ou creation, ou last update)
line.append(document_publication_date)
line.append(document_publication_date_splitted[0]) # year
line.append(document_publication_date_splitted[1]) # month
line.append(document_publication_date_splitted[2]) # day
line.append(data.update_date or '')
update_splited = utils.split_date(data.update_date or '')
line.append(update_splited[0]) # year
line.append(update_splited[1]) # month
line.append(update_splited[2]) # day
joined_line = ','.join(['"%s"' % i.replace('"', '""') for i in line])
return joined_line
def main():
parser = argparse.ArgumentParser(
description='Dump article dates'
)
parser.add_argument(
'issns',
nargs='*',
help='ISSN\'s separated by spaces'
)
parser.add_argument(
'--collection',
'-c',
help='Collection Acronym'
)
parser.add_argument(
'--output_file',
'-r',
help='File to receive the dumped data'
)
parser.add_argument(
'--logging_file',
'-o',
help='Full path to the log file'
)
parser.add_argument(
'--logging_level',
'-l',
default='DEBUG',
choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
help='Logggin level'
)
args = parser.parse_args()
_config_logging(args.logging_level, args.logging_file)
logger.info('Dumping data for: %s' % args.collection)
issns = None
if len(args.issns) > 0:
issns = utils.ckeck_given_issns(args.issns)
dumper = Dumper(args.collection, issns, args.output_file)
dumper.run()
|
bsd-2-clause
|
[
3,
2803,
26,
2774,
13,
24,
199,
624,
199,
37,
1597,
2112,
14040,
79,
486,
32311,
399,
391,
5174,
7586,
22723,
477,
15012,
886,
601,
280,
1939,
334,
3455,
65,
22723,
12,
1007,
18420,
16299,
12,
272,
282,
301,
1175,
12,
15992,
345,
983,
949,
6276,
69,
320,
69,
737,
1061,
565,
65,
22723,
949,
6276,
69,
320,
9,
199,
624,
199,
646,
7534,
199,
646,
2050,
199,
646,
6010,
199,
646,
2197,
199,
199,
646,
13222,
22641,
14,
551,
1873,
320,
3554,
199,
199,
646,
3778,
199,
646,
3415,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
485,
888,
63,
4806,
8,
4806,
63,
1896,
534,
4531,
297,
2050,
63,
493,
29,
403,
304,
339,
4370,
63,
11402,
275,
469,
267,
283,
5287,
356,
2050,
14,
5287,
12,
267,
283,
4531,
356,
2050,
14,
4531,
12,
267,
283,
9171,
356,
2050,
14,
9171,
12,
267,
283,
3170,
356,
2050,
14,
3170,
12,
267,
283,
21539,
356,
2050,
14,
21539,
272,
789,
339,
9698,
275,
2050,
14,
7772,
24713,
18331,
9,
83,
446,
2818,
354,
9,
83,
446,
2818,
20056,
9,
83,
446,
2818,
1188,
9,
83,
358,
339,
2512,
14,
13548,
8,
6541,
63,
11402,
14,
362,
8,
4806,
63,
1896,
12,
283,
4531,
1333,
339,
340,
2050,
63,
493,
26,
267,
27768,
275,
2050,
14,
21982,
8,
4806,
63,
493,
12,
818,
534,
65,
358,
272,
587,
26,
267,
27768,
275,
2050,
14,
22482,
342,
339,
27768,
14,
26076,
8,
8911,
9,
272,
27768,
14,
13548,
8,
6541,
63,
11402,
14,
362,
8,
4806,
63,
1896,
12,
283,
4531,
1333,
339,
2512,
14,
18826,
8,
15544,
9,
339,
372,
2512,
421,
199,
533,
19460,
281,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
3245,
12,
365,
83,
561,
29,
403,
12,
1072,
63,
493,
29,
403,
304,
398,
291,
423,
82,
693,
386,
275,
3778,
14,
82,
693,
386,
63,
1000,
342,
267,
291,
423,
6934,
2024,
275,
3778,
14,
6934,
2024,
63,
1000,
342,
267,
291,
14,
3627,
275,
3245,
267,
291,
14,
19857,
561,
275,
365,
83,
561,
267,
291,
14,
1199,
63,
493,
275,
6010,
14,
1490,
8,
1199,
63,
493,
12,
283,
87,
297,
2644,
534,
1624,
13,
24,
358,
340,
1072,
63,
493,
587,
1072,
63,
493,
267,
1406,
275,
942,
267,
1406,
14,
740,
8,
85,
2,
24020,
1434,
531,
267,
1406,
14,
740,
8,
85,
2,
22851,
4137,
531,
267,
1406,
14,
740,
8,
85,
2,
3627,
531,
267,
1406,
14,
740,
8,
85,
2,
1311,
8199,
16578,
37,
1484,
531,
267,
1406,
14,
740,
8,
85,
2,
1311,
8199,
3985,
83,
531,
267,
1406,
14,
740,
8,
85,
2,
1213,
737,
16578,
37,
1484,
531,
267,
1406,
14,
740,
8,
85,
2,
1213,
314,
3889,
787,
305,
531,
267,
367,
9150,
315,
3415,
14,
18061,
16996,
948,
63,
8693,
1179,
26,
288,
1406,
14,
740,
8,
85,
2,
1213,
365,
450,
83,
2,
450,
9150,
14,
2325,
1012,
267,
1406,
14,
740,
8,
85,
2,
1213,
365,
3510,
6409,
711,
472,
695,
531,
267,
1406,
14,
740,
8,
85,
2,
1213,
1453,
2004,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
2780,
316,
2870,
334,
16098,
16578,
37,
1484,
6320,
267,
1406,
14,
740,
8,
85,
2,
3554,
2780,
316,
5361,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
730,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
365,
286,
390,
461,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
16930,
737,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
16930,
737,
5361,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
16930,
737,
5794,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
16930,
737,
5382,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
10226,
737,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
10226,
737,
5361,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
10226,
737,
5794,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
10226,
737,
5382,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
11248,
379,
737,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
11248,
379,
737,
5361,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
11248,
379,
737,
5794,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
11248,
379,
737,
5382,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
465,
23417,
402,
870,
737,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
465,
23417,
402,
870,
737,
5361,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
465,
23417,
402,
870,
737,
5794,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
465,
23417,
402,
870,
737,
5382,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
737,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
737,
5361,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
737,
5794,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
737,
5382,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
315,
16578,
37,
1484,
737,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
315,
16578,
37,
1484,
737,
5361,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
315,
16578,
37,
1484,
737,
5794,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
315,
16578,
37,
1484,
737,
5382,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
4588,
315,
16578,
37,
1484,
737,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
4588,
315,
16578,
37,
1484,
737,
5361,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
4588,
315,
16578,
37,
1484,
737,
5794,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
4588,
315,
16578,
37,
1484,
737,
5382,
531,
398,
291,
14,
952,
8,
85,
26409,
904,
779,
85,
4065,
5,
83,
4507,
450,
284,
14,
1814,
8,
85,
24487,
399,
7,
341,
358,
367,
284,
315,
1406,
2459,
339,
347,
2218,
8,
277,
12,
1004,
304,
267,
340,
440,
291,
14,
1199,
63,
493,
26,
288,
870,
8,
604,
14,
2143,
360,
1624,
13,
24,
1333,
267,
587,
26,
288,
291,
14,
1199,
63,
493,
14,
952,
3508
] |
[
2803,
26,
2774,
13,
24,
199,
624,
199,
37,
1597,
2112,
14040,
79,
486,
32311,
399,
391,
5174,
7586,
22723,
477,
15012,
886,
601,
280,
1939,
334,
3455,
65,
22723,
12,
1007,
18420,
16299,
12,
272,
282,
301,
1175,
12,
15992,
345,
983,
949,
6276,
69,
320,
69,
737,
1061,
565,
65,
22723,
949,
6276,
69,
320,
9,
199,
624,
199,
646,
7534,
199,
646,
2050,
199,
646,
6010,
199,
646,
2197,
199,
199,
646,
13222,
22641,
14,
551,
1873,
320,
3554,
199,
199,
646,
3778,
199,
646,
3415,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
485,
888,
63,
4806,
8,
4806,
63,
1896,
534,
4531,
297,
2050,
63,
493,
29,
403,
304,
339,
4370,
63,
11402,
275,
469,
267,
283,
5287,
356,
2050,
14,
5287,
12,
267,
283,
4531,
356,
2050,
14,
4531,
12,
267,
283,
9171,
356,
2050,
14,
9171,
12,
267,
283,
3170,
356,
2050,
14,
3170,
12,
267,
283,
21539,
356,
2050,
14,
21539,
272,
789,
339,
9698,
275,
2050,
14,
7772,
24713,
18331,
9,
83,
446,
2818,
354,
9,
83,
446,
2818,
20056,
9,
83,
446,
2818,
1188,
9,
83,
358,
339,
2512,
14,
13548,
8,
6541,
63,
11402,
14,
362,
8,
4806,
63,
1896,
12,
283,
4531,
1333,
339,
340,
2050,
63,
493,
26,
267,
27768,
275,
2050,
14,
21982,
8,
4806,
63,
493,
12,
818,
534,
65,
358,
272,
587,
26,
267,
27768,
275,
2050,
14,
22482,
342,
339,
27768,
14,
26076,
8,
8911,
9,
272,
27768,
14,
13548,
8,
6541,
63,
11402,
14,
362,
8,
4806,
63,
1896,
12,
283,
4531,
1333,
339,
2512,
14,
18826,
8,
15544,
9,
339,
372,
2512,
421,
199,
533,
19460,
281,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
3245,
12,
365,
83,
561,
29,
403,
12,
1072,
63,
493,
29,
403,
304,
398,
291,
423,
82,
693,
386,
275,
3778,
14,
82,
693,
386,
63,
1000,
342,
267,
291,
423,
6934,
2024,
275,
3778,
14,
6934,
2024,
63,
1000,
342,
267,
291,
14,
3627,
275,
3245,
267,
291,
14,
19857,
561,
275,
365,
83,
561,
267,
291,
14,
1199,
63,
493,
275,
6010,
14,
1490,
8,
1199,
63,
493,
12,
283,
87,
297,
2644,
534,
1624,
13,
24,
358,
340,
1072,
63,
493,
587,
1072,
63,
493,
267,
1406,
275,
942,
267,
1406,
14,
740,
8,
85,
2,
24020,
1434,
531,
267,
1406,
14,
740,
8,
85,
2,
22851,
4137,
531,
267,
1406,
14,
740,
8,
85,
2,
3627,
531,
267,
1406,
14,
740,
8,
85,
2,
1311,
8199,
16578,
37,
1484,
531,
267,
1406,
14,
740,
8,
85,
2,
1311,
8199,
3985,
83,
531,
267,
1406,
14,
740,
8,
85,
2,
1213,
737,
16578,
37,
1484,
531,
267,
1406,
14,
740,
8,
85,
2,
1213,
314,
3889,
787,
305,
531,
267,
367,
9150,
315,
3415,
14,
18061,
16996,
948,
63,
8693,
1179,
26,
288,
1406,
14,
740,
8,
85,
2,
1213,
365,
450,
83,
2,
450,
9150,
14,
2325,
1012,
267,
1406,
14,
740,
8,
85,
2,
1213,
365,
3510,
6409,
711,
472,
695,
531,
267,
1406,
14,
740,
8,
85,
2,
1213,
1453,
2004,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
2780,
316,
2870,
334,
16098,
16578,
37,
1484,
6320,
267,
1406,
14,
740,
8,
85,
2,
3554,
2780,
316,
5361,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
730,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
365,
286,
390,
461,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
16930,
737,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
16930,
737,
5361,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
16930,
737,
5794,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
16930,
737,
5382,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
10226,
737,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
10226,
737,
5361,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
10226,
737,
5794,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
10226,
737,
5382,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
11248,
379,
737,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
11248,
379,
737,
5361,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
11248,
379,
737,
5794,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
11248,
379,
737,
5382,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
465,
23417,
402,
870,
737,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
465,
23417,
402,
870,
737,
5361,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
465,
23417,
402,
870,
737,
5794,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
465,
23417,
402,
870,
737,
5382,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
737,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
737,
5361,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
737,
5794,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
737,
5382,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
315,
16578,
37,
1484,
737,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
315,
16578,
37,
1484,
737,
5361,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
315,
16578,
37,
1484,
737,
5794,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
3267,
315,
16578,
37,
1484,
737,
5382,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
4588,
315,
16578,
37,
1484,
737,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
4588,
315,
16578,
37,
1484,
737,
5361,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
4588,
315,
16578,
37,
1484,
737,
5794,
531,
267,
1406,
14,
740,
8,
85,
2,
3554,
4588,
315,
16578,
37,
1484,
737,
5382,
531,
398,
291,
14,
952,
8,
85,
26409,
904,
779,
85,
4065,
5,
83,
4507,
450,
284,
14,
1814,
8,
85,
24487,
399,
7,
341,
358,
367,
284,
315,
1406,
2459,
339,
347,
2218,
8,
277,
12,
1004,
304,
267,
340,
440,
291,
14,
1199,
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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
bparafina/shadowsocks
|
tests/test.py
|
1016
|
5029
|
#!/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 sys
import os
import signal
import select
import time
import argparse
from subprocess import Popen, PIPE
python = ['python']
default_url = 'http://localhost/'
parser = argparse.ArgumentParser(description='test Shadowsocks')
parser.add_argument('-c', '--client-conf', type=str, default=None)
parser.add_argument('-s', '--server-conf', type=str, default=None)
parser.add_argument('-a', '--client-args', type=str, default=None)
parser.add_argument('-b', '--server-args', type=str, default=None)
parser.add_argument('--with-coverage', action='store_true', default=None)
parser.add_argument('--should-fail', action='store_true', default=None)
parser.add_argument('--tcp-only', action='store_true', default=None)
parser.add_argument('--url', type=str, default=default_url)
parser.add_argument('--dns', type=str, default='8.8.8.8')
config = parser.parse_args()
if config.with_coverage:
python = ['coverage', 'run', '-p', '-a']
client_args = python + ['shadowsocks/local.py', '-v']
server_args = python + ['shadowsocks/server.py', '-v']
if config.client_conf:
client_args.extend(['-c', config.client_conf])
if config.server_conf:
server_args.extend(['-c', config.server_conf])
else:
server_args.extend(['-c', config.client_conf])
if config.client_args:
client_args.extend(config.client_args.split())
if config.server_args:
server_args.extend(config.server_args.split())
else:
server_args.extend(config.client_args.split())
if config.url == default_url:
server_args.extend(['--forbidden-ip', ''])
p1 = Popen(server_args, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
p2 = Popen(client_args, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
p3 = None
p4 = None
p3_fin = False
p4_fin = False
# 1 shadowsocks started
# 2 curl started
# 3 curl finished
# 4 dig started
# 5 dig finished
stage = 1
try:
local_ready = False
server_ready = False
fdset = [p1.stdout, p2.stdout, p1.stderr, p2.stderr]
while True:
r, w, e = select.select(fdset, [], fdset)
if e:
break
for fd in r:
line = fd.readline()
if not line:
if stage == 2 and fd == p3.stdout:
stage = 3
if stage == 4 and fd == p4.stdout:
stage = 5
if bytes != str:
line = str(line, 'utf8')
sys.stderr.write(line)
if line.find('starting local') >= 0:
local_ready = True
if line.find('starting server') >= 0:
server_ready = True
if stage == 1:
time.sleep(2)
p3 = Popen(['curl', config.url, '-v', '-L',
'--socks5-hostname', '127.0.0.1:1081',
'-m', '15', '--connect-timeout', '10'],
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
if p3 is not None:
fdset.append(p3.stdout)
fdset.append(p3.stderr)
stage = 2
else:
sys.exit(1)
if stage == 3 and p3 is not None:
fdset.remove(p3.stdout)
fdset.remove(p3.stderr)
r = p3.wait()
if config.should_fail:
if r == 0:
sys.exit(1)
else:
if r != 0:
sys.exit(1)
if config.tcp_only:
break
p4 = Popen(['socksify', 'dig', '@%s' % config.dns,
'www.google.com'],
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
if p4 is not None:
fdset.append(p4.stdout)
fdset.append(p4.stderr)
stage = 4
else:
sys.exit(1)
if stage == 5:
r = p4.wait()
if config.should_fail:
if r == 0:
sys.exit(1)
print('test passed (expecting failure)')
else:
if r != 0:
sys.exit(1)
print('test passed')
break
finally:
for p in [p1, p2]:
try:
os.kill(p.pid, signal.SIGINT)
os.waitpid(p.pid, 0)
except OSError:
pass
|
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,
984,
199,
646,
747,
199,
646,
4673,
199,
646,
3504,
199,
646,
900,
199,
646,
7534,
199,
504,
3873,
492,
13995,
12,
22773,
199,
199,
1548,
275,
788,
1548,
418,
199,
199,
885,
63,
633,
275,
283,
1014,
921,
5967,
4805,
199,
199,
2087,
275,
7534,
14,
10730,
8,
1802,
534,
396,
5244,
8369,
21234,
358,
199,
2087,
14,
525,
63,
2094,
3654,
67,
297,
2850,
1258,
13,
2190,
297,
730,
29,
495,
12,
849,
29,
403,
9,
199,
2087,
14,
525,
63,
2094,
3654,
83,
297,
2850,
1000,
13,
2190,
297,
730,
29,
495,
12,
849,
29,
403,
9,
199,
2087,
14,
525,
63,
2094,
3654,
65,
297,
2850,
1258,
13,
589,
297,
730,
29,
495,
12,
849,
29,
403,
9,
199,
2087,
14,
525,
63,
2094,
3654,
66,
297,
2850,
1000,
13,
589,
297,
730,
29,
495,
12,
849,
29,
403,
9,
199,
2087,
14,
525,
63,
2094,
4517,
1045,
13,
10828,
297,
1595,
534,
1617,
63,
2052,
297,
849,
29,
403,
9,
199,
2087,
14,
525,
63,
2094,
4517,
5626,
13,
1633,
297,
1595,
534,
1617,
63,
2052,
297,
849,
29,
403,
9,
199,
2087,
14,
525,
63,
2094,
4517,
8815,
13,
2118,
297,
1595,
534,
1617,
63,
2052,
297,
849,
29,
403,
9,
199,
2087,
14,
525,
63,
2094,
4517,
633,
297,
730,
29,
495,
12,
849,
29,
885,
63,
633,
9,
199,
2087,
14,
525,
63,
2094,
4517,
5797,
297,
730,
29,
495,
12,
849,
534,
24,
14,
24,
14,
24,
14,
24,
358,
199,
199,
888,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
692,
1101,
14,
1045,
63,
10828,
26,
272,
2366,
275,
788,
10828,
297,
283,
1065,
297,
2475,
80,
297,
2475,
65,
418,
199,
199,
1258,
63,
589,
275,
2366,
435,
788,
14714,
21234,
15,
1832,
14,
647,
297,
2475,
86,
418,
199,
1000,
63,
589,
275,
2366,
435,
788,
14714,
21234,
15,
1000,
14,
647,
297,
2475,
86,
418,
199,
199,
692,
1101,
14,
1258,
63,
2190,
26,
272,
1890,
63,
589,
14,
2880,
24829,
67,
297,
1101,
14,
1258,
63,
2190,
566,
272,
340,
1101,
14,
1000,
63,
2190,
26,
267,
1654,
63,
589,
14,
2880,
24829,
67,
297,
1101,
14,
1000,
63,
2190,
566,
272,
587,
26,
267,
1654,
63,
589,
14,
2880,
24829,
67,
297,
1101,
14,
1258,
63,
2190,
566,
199,
692,
1101,
14,
1258,
63,
589,
26,
272,
1890,
63,
589,
14,
2880,
8,
888,
14,
1258,
63,
589,
14,
1294,
1012,
272,
340,
1101,
14,
1000,
63,
589,
26,
267,
1654,
63,
589,
14,
2880,
8,
888,
14,
1000,
63,
589,
14,
1294,
1012,
272,
587,
26,
267,
1654,
63,
589,
14,
2880,
8,
888,
14,
1258,
63,
589,
14,
1294,
1012,
199,
692,
1101,
14,
633,
508,
849,
63,
633,
26,
272,
1654,
63,
589,
14,
2880,
18510,
29293,
13,
711,
297,
283,
1105,
199,
199,
80,
17,
275,
13995,
8,
1000,
63,
589,
12,
9009,
29,
6089,
12,
3839,
29,
6089,
12,
4635,
29,
6089,
12,
4002,
63,
14240,
29,
549,
9,
199,
80,
18,
275,
13995,
8,
1258,
63,
589,
12,
9009,
29,
6089,
12,
3839,
29,
6089,
12,
4635,
29,
6089,
12,
4002,
63,
14240,
29,
549,
9,
199,
80,
19,
275,
488,
199,
80,
20,
275,
488,
199,
80,
19,
63,
2408,
275,
756,
199,
80,
20,
63,
2408,
275,
756,
199,
199,
3,
413,
15084,
21234,
8239,
199,
3,
499,
26145,
8239,
199,
3,
650,
26145,
9158,
199,
3,
841,
31190,
8239,
199,
3,
959,
31190,
9158,
199,
8614,
275,
413,
199,
199,
893,
26,
272,
2257,
63,
2179,
275,
756,
272,
1654,
63,
2179,
275,
756,
272,
6111,
409,
275,
359,
80,
17,
14,
2703,
12,
299,
18,
14,
2703,
12,
299,
17,
14,
3083,
12,
299,
18,
14,
3083,
61,
272,
1830,
715,
26,
267,
519,
12,
336,
12,
325,
275,
3504,
14,
2416,
8,
2592,
409,
12,
990,
6111,
409,
9,
267,
340,
325,
26,
288,
2059,
398,
367,
6111,
315,
519,
26,
288,
1004,
275,
6111,
14,
6407,
342,
288,
340,
440,
1004,
26,
355,
340,
9546,
508,
499,
436,
6111,
508,
299,
19,
14,
2703,
26,
490,
9546,
275,
650,
355,
340,
9546,
508,
841,
436,
6111,
508,
299,
20,
14,
2703,
26,
490,
9546,
275,
959,
288,
340,
2783,
1137,
620,
26,
355,
1004,
275,
620,
8,
604,
12,
283,
1624,
24,
358,
288,
984,
14,
3083,
14,
952,
8,
604,
9,
288,
340,
1004,
14,
1623,
360,
15769,
2257,
358,
2356,
378,
26,
355,
2257,
63,
2179,
275,
715,
288,
340,
1004,
14,
1623,
360,
15769,
1654,
358,
2356,
378,
26,
355,
1654,
63,
2179,
275,
715,
398,
340,
9546,
508,
413,
26,
288,
900,
14,
4532,
8,
18,
9,
953,
299,
19,
275,
13995,
2941,
17096,
297,
1101,
14,
633,
12,
2475,
86,
297,
2475,
44,
297,
717,
2850,
21234,
21,
13,
4269,
297,
283,
4195,
14,
16,
14,
16,
14,
17,
26,
709,
2835,
297,
717,
2475,
77,
297,
283,
1046,
297,
2850,
2242,
13,
2593,
297,
283,
709,
995,
2432,
9009,
29,
6089,
12,
3839,
29,
6089,
12,
4635,
29
] |
[
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,
984,
199,
646,
747,
199,
646,
4673,
199,
646,
3504,
199,
646,
900,
199,
646,
7534,
199,
504,
3873,
492,
13995,
12,
22773,
199,
199,
1548,
275,
788,
1548,
418,
199,
199,
885,
63,
633,
275,
283,
1014,
921,
5967,
4805,
199,
199,
2087,
275,
7534,
14,
10730,
8,
1802,
534,
396,
5244,
8369,
21234,
358,
199,
2087,
14,
525,
63,
2094,
3654,
67,
297,
2850,
1258,
13,
2190,
297,
730,
29,
495,
12,
849,
29,
403,
9,
199,
2087,
14,
525,
63,
2094,
3654,
83,
297,
2850,
1000,
13,
2190,
297,
730,
29,
495,
12,
849,
29,
403,
9,
199,
2087,
14,
525,
63,
2094,
3654,
65,
297,
2850,
1258,
13,
589,
297,
730,
29,
495,
12,
849,
29,
403,
9,
199,
2087,
14,
525,
63,
2094,
3654,
66,
297,
2850,
1000,
13,
589,
297,
730,
29,
495,
12,
849,
29,
403,
9,
199,
2087,
14,
525,
63,
2094,
4517,
1045,
13,
10828,
297,
1595,
534,
1617,
63,
2052,
297,
849,
29,
403,
9,
199,
2087,
14,
525,
63,
2094,
4517,
5626,
13,
1633,
297,
1595,
534,
1617,
63,
2052,
297,
849,
29,
403,
9,
199,
2087,
14,
525,
63,
2094,
4517,
8815,
13,
2118,
297,
1595,
534,
1617,
63,
2052,
297,
849,
29,
403,
9,
199,
2087,
14,
525,
63,
2094,
4517,
633,
297,
730,
29,
495,
12,
849,
29,
885,
63,
633,
9,
199,
2087,
14,
525,
63,
2094,
4517,
5797,
297,
730,
29,
495,
12,
849,
534,
24,
14,
24,
14,
24,
14,
24,
358,
199,
199,
888,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
692,
1101,
14,
1045,
63,
10828,
26,
272,
2366,
275,
788,
10828,
297,
283,
1065,
297,
2475,
80,
297,
2475,
65,
418,
199,
199,
1258,
63,
589,
275,
2366,
435,
788,
14714,
21234,
15,
1832,
14,
647,
297,
2475,
86,
418,
199,
1000,
63,
589,
275,
2366,
435,
788,
14714,
21234,
15,
1000,
14,
647,
297,
2475,
86,
418,
199,
199,
692,
1101,
14,
1258,
63,
2190,
26,
272,
1890,
63,
589,
14,
2880,
24829,
67,
297,
1101,
14,
1258,
63,
2190,
566,
272,
340,
1101,
14,
1000,
63,
2190,
26,
267,
1654,
63,
589,
14,
2880,
24829,
67,
297,
1101,
14,
1000,
63,
2190,
566,
272,
587,
26,
267,
1654,
63,
589,
14,
2880,
24829,
67,
297,
1101,
14,
1258,
63,
2190,
566,
199,
692,
1101,
14,
1258,
63,
589,
26,
272,
1890,
63,
589,
14,
2880,
8,
888,
14,
1258,
63,
589,
14,
1294,
1012,
272,
340,
1101,
14,
1000,
63,
589,
26,
267,
1654,
63,
589,
14,
2880,
8,
888,
14,
1000,
63,
589,
14,
1294,
1012,
272,
587,
26,
267,
1654,
63,
589,
14,
2880,
8,
888,
14,
1258,
63,
589,
14,
1294,
1012,
199,
692,
1101,
14,
633,
508,
849,
63,
633,
26,
272,
1654,
63,
589,
14,
2880,
18510,
29293,
13,
711,
297,
283,
1105,
199,
199,
80,
17,
275,
13995,
8,
1000,
63,
589,
12,
9009,
29,
6089,
12,
3839,
29,
6089,
12,
4635,
29,
6089,
12,
4002,
63,
14240,
29,
549,
9,
199,
80,
18,
275,
13995,
8,
1258,
63,
589,
12,
9009,
29,
6089,
12,
3839,
29,
6089,
12,
4635,
29,
6089,
12,
4002,
63,
14240,
29,
549,
9,
199,
80,
19,
275,
488,
199,
80,
20,
275,
488,
199,
80,
19,
63,
2408,
275,
756,
199,
80,
20,
63,
2408,
275,
756,
199,
199,
3,
413,
15084,
21234,
8239,
199,
3,
499,
26145,
8239,
199,
3,
650,
26145,
9158,
199,
3,
841,
31190,
8239,
199,
3,
959,
31190,
9158,
199,
8614,
275,
413,
199,
199,
893,
26,
272,
2257,
63,
2179,
275,
756,
272,
1654,
63,
2179,
275,
756,
272,
6111,
409,
275,
359,
80,
17,
14,
2703,
12,
299,
18,
14,
2703,
12,
299,
17,
14,
3083,
12,
299,
18,
14,
3083,
61,
272,
1830,
715,
26,
267,
519,
12,
336,
12,
325,
275,
3504,
14,
2416,
8,
2592,
409,
12,
990,
6111,
409,
9,
267,
340,
325,
26,
288,
2059,
398,
367,
6111,
315,
519,
26,
288,
1004,
275,
6111,
14,
6407,
342,
288,
340,
440,
1004,
26,
355,
340,
9546,
508,
499,
436,
6111,
508,
299,
19,
14,
2703,
26,
490,
9546,
275,
650,
355,
340,
9546,
508,
841,
436,
6111,
508,
299,
20,
14,
2703,
26,
490,
9546,
275,
959,
288,
340,
2783,
1137,
620,
26,
355,
1004,
275,
620,
8,
604,
12,
283,
1624,
24,
358,
288,
984,
14,
3083,
14,
952,
8,
604,
9,
288,
340,
1004,
14,
1623,
360,
15769,
2257,
358,
2356,
378,
26,
355,
2257,
63,
2179,
275,
715,
288,
340,
1004,
14,
1623,
360,
15769,
1654,
358,
2356,
378,
26,
355,
1654,
63,
2179,
275,
715,
398,
340,
9546,
508,
413,
26,
288,
900,
14,
4532,
8,
18,
9,
953,
299,
19,
275,
13995,
2941,
17096,
297,
1101,
14,
633,
12,
2475,
86,
297,
2475,
44,
297,
717,
2850,
21234,
21,
13,
4269,
297,
283,
4195,
14,
16,
14,
16,
14,
17,
26,
709,
2835,
297,
717,
2475,
77,
297,
283,
1046,
297,
2850,
2242,
13,
2593,
297,
283,
709,
995,
2432,
9009,
29,
6089,
12,
3839,
29,
6089,
12,
4635,
29,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
offtools/linux-show-player
|
lisp/ui/settings/settings_page.py
|
3
|
1283
|
# -*- coding: utf-8 -*-
#
# This file is part of Linux Show Player
#
# Copyright 2012-2016 Francesco Ceruti <ceppofrancy@gmail.com>
#
# Linux Show Player 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.
#
# Linux Show Player 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 Linux Show Player. If not, see <http://www.gnu.org/licenses/>.
from PyQt5.QtWidgets import QWidget
class SettingsPage(QWidget):
Name = 'Page'
def enable_check(self, enabled):
"""Enable option check"""
def get_settings(self):
"""Return the current settings."""
return {}
def load_settings(self, settings):
"""Load the settings."""
class CueSettingsPage(SettingsPage):
Name = 'Cue page'
def __init__(self, cue_class, **kwargs):
super().__init__(**kwargs)
self._cue_class = cue_class
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
10130,
12968,
25610,
199,
3,
199,
3,
1898,
6029,
13,
9261,
481,
82,
13236,
331,
11002,
935,
665,
28448,
555,
70,
1312,
1480,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
10130,
12968,
25610,
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,
10130,
12968,
25610,
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,
10130,
12968,
25610,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
14084,
21,
14,
29081,
492,
1413,
3339,
421,
199,
533,
13303,
3276,
8,
23894,
304,
272,
2812,
275,
283,
3276,
7,
339,
347,
4756,
63,
1074,
8,
277,
12,
5223,
304,
267,
408,
6476,
945,
1104,
624,
339,
347,
664,
63,
1751,
8,
277,
304,
267,
408,
1767,
314,
1453,
2202,
1041,
267,
372,
1052,
339,
347,
2248,
63,
1751,
8,
277,
12,
2202,
304,
267,
408,
6200,
314,
2202,
1041,
421,
199,
533,
445,
310,
5268,
3276,
8,
5268,
3276,
304,
272,
2812,
275,
283,
35,
310,
2034,
7,
339,
347,
636,
826,
721,
277,
12,
286,
310,
63,
533,
12,
1011,
958,
304,
267,
1613,
11027,
826,
14155,
958,
9,
398,
291,
423,
14932,
63,
533,
275,
286,
310,
63,
533,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
10130,
12968,
25610,
199,
3,
199,
3,
1898,
6029,
13,
9261,
481,
82,
13236,
331,
11002,
935,
665,
28448,
555,
70,
1312,
1480,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
10130,
12968,
25610,
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,
10130,
12968,
25610,
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,
10130,
12968,
25610,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
14084,
21,
14,
29081,
492,
1413,
3339,
421,
199,
533,
13303,
3276,
8,
23894,
304,
272,
2812,
275,
283,
3276,
7,
339,
347,
4756,
63,
1074,
8,
277,
12,
5223,
304,
267,
408,
6476,
945,
1104,
624,
339,
347,
664,
63,
1751,
8,
277,
304,
267,
408,
1767,
314,
1453,
2202,
1041,
267,
372,
1052,
339,
347,
2248,
63,
1751,
8,
277,
12,
2202,
304,
267,
408,
6200,
314,
2202,
1041,
421,
199,
533,
445,
310,
5268,
3276,
8,
5268,
3276,
304,
272,
2812,
275,
283,
35,
310,
2034,
7,
339,
347,
636,
826,
721,
277,
12,
286,
310,
63,
533,
12,
1011,
958,
304,
267,
1613,
11027,
826,
14155,
958,
9,
398,
291,
423,
14932,
63,
533,
275,
286,
310,
63,
533,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
JVillella/tensorflow
|
tensorflow/contrib/keras/python/keras/preprocessing/text_test.py
|
17
|
2522
|
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for text data preprocessing utils."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
from tensorflow.contrib.keras.python import keras
from tensorflow.python.platform import test
class TestText(test.TestCase):
def test_one_hot(self):
text = 'The cat sat on the mat.'
encoded = keras.preprocessing.text.one_hot(text, 5)
self.assertEqual(len(encoded), 6)
self.assertLessEqual(np.max(encoded), 4)
self.assertGreaterEqual(np.min(encoded), 0)
def test_tokenizer(self):
texts = [
'The cat sat on the mat.',
'The dog sat on the log.',
'Dogs and cats living together.'
]
tokenizer = keras.preprocessing.text.Tokenizer(num_words=10)
tokenizer.fit_on_texts(texts)
sequences = []
for seq in tokenizer.texts_to_sequences_generator(texts):
sequences.append(seq)
self.assertLess(np.max(np.max(sequences)), 10)
self.assertEqual(np.min(np.min(sequences)), 1)
tokenizer.fit_on_sequences(sequences)
for mode in ['binary', 'count', 'tfidf', 'freq']:
matrix = tokenizer.texts_to_matrix(texts, mode)
self.assertEqual(matrix.shape, (3, 10))
def test_hashing_trick_hash(self):
text = 'The cat sat on the mat.'
encoded = keras.preprocessing.text.hashing_trick(text, 5)
self.assertEqual(len(encoded), 6)
self.assertLessEqual(np.max(encoded), 4)
self.assertGreaterEqual(np.min(encoded), 1)
def test_hashing_trick_md5(self):
text = 'The cat sat on the mat.'
encoded = keras.preprocessing.text.hashing_trick(
text, 5, hash_function='md5')
self.assertEqual(len(encoded), 6)
self.assertLessEqual(np.max(encoded), 4)
self.assertGreaterEqual(np.min(encoded), 1)
if __name__ == '__main__':
test.main()
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
1318,
666,
26471,
3778,
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,
2680,
465,
980,
199,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
492,
11708,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
1379,
1872,
8,
396,
14,
1746,
304,
819,
347,
511,
63,
368,
63,
8885,
8,
277,
304,
272,
1318,
275,
283,
1918,
6230,
21845,
641,
314,
2530,
3530,
272,
5737,
275,
11708,
14,
21402,
14,
505,
14,
368,
63,
8885,
8,
505,
12,
959,
9,
272,
291,
14,
629,
8,
552,
8,
8167,
395,
1227,
9,
272,
291,
14,
15625,
591,
8,
1590,
14,
988,
8,
8167,
395,
841,
9,
272,
291,
14,
26875,
8,
1590,
14,
827,
8,
8167,
395,
378,
9,
819,
347,
511,
63,
13771,
8,
277,
304,
272,
24857,
275,
359,
267,
283,
1918,
6230,
21845,
641,
314,
2530,
3130,
267,
283,
1918,
23454,
21845,
641,
314,
943,
3130,
267,
283,
2585,
458,
436,
286,
1956,
1212,
4007,
10451,
3530,
272,
1622,
272,
14803,
275,
11708,
14,
21402,
14,
505,
14,
21782,
8,
1507,
63,
3148,
29,
709,
9,
272,
14803,
14,
3269,
63,
265,
63,
19517,
8,
19517,
9,
339,
8013,
275,
942,
272,
367,
5412,
315,
14803,
14,
19517,
63,
475,
63,
13436,
63,
4679,
8,
19517,
304,
489,
8013,
14,
740,
8,
3610,
9,
272,
291,
14,
15625,
8,
1590,
14,
988,
8,
1590,
14,
988,
8,
13436,
1826,
1616,
9,
272,
291,
14,
629,
8,
1590,
14,
827,
8,
1590,
14,
827,
8,
13436,
1826,
413,
9,
339,
14803,
14,
3269,
63,
265,
63,
13436,
8,
13436,
9,
339,
367,
818,
315,
788,
3008,
297,
283,
835,
297,
283,
84,
23274,
297,
283,
5646,
2565,
489,
3634,
275,
14803,
14,
19517,
63,
475,
63,
3642,
8,
19517,
12,
818,
9,
489,
291,
14,
629,
8,
3642,
14,
1392,
12,
334,
19,
12,
1616,
430,
819,
347,
511,
63,
2227,
316,
63,
599,
346,
63,
2227,
8,
277,
304,
272,
1318,
275,
283,
1918,
6230,
21845,
641,
314,
2530,
3530,
272,
5737,
275,
11708,
14,
21402,
14,
505,
14,
2227,
316,
63,
599,
346,
8,
505,
12,
959,
9,
272,
291,
14,
629,
8,
552,
8,
8167,
395,
1227,
9,
272,
291,
14,
15625,
591,
8,
1590,
14,
988,
8,
8167,
395,
841,
9,
272,
291,
14,
26875,
8,
1590,
14,
827,
8,
8167,
395,
413,
9,
819,
347,
511,
63,
2227,
316,
63,
599,
346,
63,
1064,
21,
8,
277,
304,
272,
1318,
275,
283,
1918,
6230,
21845,
641,
314,
2530,
3530,
272,
5737,
275,
11708,
14,
21402,
14,
505,
14,
2227,
316,
63,
599,
346,
8,
267,
1318,
12,
959,
12,
2631,
63,
1593,
534,
1064,
21,
358,
272,
291,
14,
629,
8,
552,
8,
8167,
395,
1227,
9,
272,
291,
14,
15625,
591,
8,
1590,
14,
988,
8,
8167,
395,
841,
9,
272,
291,
14,
26875,
8,
1590,
14,
827,
8,
8167,
395,
413,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
511,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
1318,
666,
26471,
3778,
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,
2680,
465,
980,
199,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
492,
11708,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
1379,
1872,
8,
396,
14,
1746,
304,
819,
347,
511,
63,
368,
63,
8885,
8,
277,
304,
272,
1318,
275,
283,
1918,
6230,
21845,
641,
314,
2530,
3530,
272,
5737,
275,
11708,
14,
21402,
14,
505,
14,
368,
63,
8885,
8,
505,
12,
959,
9,
272,
291,
14,
629,
8,
552,
8,
8167,
395,
1227,
9,
272,
291,
14,
15625,
591,
8,
1590,
14,
988,
8,
8167,
395,
841,
9,
272,
291,
14,
26875,
8,
1590,
14,
827,
8,
8167,
395,
378,
9,
819,
347,
511,
63,
13771,
8,
277,
304,
272,
24857,
275,
359,
267,
283,
1918,
6230,
21845,
641,
314,
2530,
3130,
267,
283,
1918,
23454,
21845,
641,
314,
943,
3130,
267,
283,
2585,
458,
436,
286,
1956,
1212,
4007,
10451,
3530,
272,
1622,
272,
14803,
275,
11708,
14,
21402,
14,
505,
14,
21782,
8,
1507,
63,
3148,
29,
709,
9,
272,
14803,
14,
3269,
63,
265,
63,
19517,
8,
19517,
9,
339,
8013,
275,
942,
272,
367,
5412,
315,
14803,
14,
19517,
63,
475,
63,
13436,
63,
4679,
8,
19517,
304,
489,
8013,
14,
740,
8,
3610,
9,
272,
291,
14,
15625,
8,
1590,
14,
988,
8,
1590,
14,
988,
8,
13436,
1826,
1616,
9,
272,
291,
14,
629,
8,
1590,
14,
827,
8,
1590,
14,
827,
8,
13436,
1826,
413,
9,
339,
14803,
14,
3269,
63,
265,
63,
13436,
8,
13436,
9,
339,
367,
818,
315,
788,
3008,
297,
283,
835,
297,
283,
84,
23274,
297,
283,
5646,
2565,
489,
3634,
275,
14803,
14,
19517,
63,
475,
63,
3642,
8,
19517,
12,
818,
9,
489,
291,
14,
629,
8,
3642,
14,
1392,
12,
334,
19,
12,
1616,
430,
819,
347,
511,
63,
2227,
316,
63,
599,
346,
63,
2227,
8,
277,
304,
272,
1318,
275,
283,
1918,
6230,
21845,
641,
314,
2530,
3530,
272,
5737,
275,
11708,
14,
21402,
14,
505,
14,
2227,
316,
63,
599,
346,
8,
505,
12,
959,
9,
272,
291,
14,
629,
8,
552,
8,
8167,
395,
1227,
9,
272,
291,
14,
15625,
591,
8,
1590,
14,
988,
8,
8167,
395,
841,
9,
272,
291,
14,
26875,
8,
1590,
14,
827,
8,
8167,
395,
413,
9,
819,
347,
511,
63,
2227,
316,
63,
599,
346,
63,
1064,
21,
8,
277,
304,
272,
1318,
275,
283,
1918,
6230,
21845,
641,
314,
2530,
3530,
272,
5737,
275,
11708,
14,
21402,
14,
505,
14,
2227,
316,
63,
599,
346,
8,
267,
1318,
12,
959,
12,
2631,
63,
1593,
534,
1064,
21,
358,
272,
291,
14,
629,
8,
552,
8,
8167,
395,
1227,
9,
272,
291,
14,
15625,
591,
8,
1590,
14,
988,
8,
8167,
395,
841,
9,
272,
291,
14,
26875,
8,
1590,
14,
827,
8,
8167,
395,
413,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
511,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
piotrek-golda/CivilHubIndependantCopy
|
projects/views/forum.py
|
3
|
7098
|
# -*- coding: utf-8 -*-
from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404
from django.views.generic import ListView
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from places_core.mixins import LoginRequiredMixin
from places_core.permissions import is_moderator
from .mixins import ProjectContextMixin
from ..forms import DiscussionAnswerForm, SocialForumCreateForm,\
SocialForumUpdateForm
from ..models import SocialForumTopic, SocialForumEntry, SocialProject
from ..permissions import check_access
class ProjectForumContextMixin(ProjectContextMixin):
""" A mixin for discussion subpages for this project. """
def get_context_data(self, form=None, **kwargs):
context = super(ProjectForumContextMixin, self).get_context_data()
project_slug = self.kwargs.get('project_slug')
if project_slug is not None:
context['object'] = get_object_or_404(SocialProject,
slug=project_slug)
context['location'] = context['object'].location
context['is_moderator'] = is_moderator(self.request.user,
context['location'])
if form is not None:
context['form'] = form
discussion_slug = self.kwargs.get('discussion_slug')
if discussion_slug is not None:
context['discussion'] = get_object_or_404(SocialForumTopic,
slug=discussion_slug)
return context
class ProjectForumUpdateMixin(LoginRequiredMixin, UpdateView,
ProjectForumContextMixin):
""" A mixin for discussion edition forms and discussion entries. """
def permission_check_(self):
if not check_access(self.get_object(), self.request.user):
raise PermissionDenied
def get(self, request, project_slug=None, discussion_slug=None, pk=None):
self.permission_check_()
return super(ProjectForumUpdateMixin, self).get(request, project_slug,
discussion_slug)
def post(self, request, project_slug=None, discussion_slug=None, pk=None):
self.permission_check_()
return super(ProjectForumUpdateMixin, self).post(request, project_slug,
discussion_slug)
class ProjectForumListView(ProjectForumContextMixin, ListView):
""" A list of discussions within one project. """
model = SocialForumTopic
paginate_by = 25
def get_queryset(self):
qs = super(ProjectForumListView, self).get_queryset()
project_slug = self.kwargs.get('project_slug')
if project_slug is not None:
qs = qs.filter(project__slug=project_slug)
return qs
class ProjectForumDetailView(ProjectForumContextMixin, ListView):
""" One discussion with answers. """
model = SocialForumEntry
paginate_by = 25
def get_queryset(self):
qs = super(ProjectForumDetailView, self).get_queryset()
discussion_slug = self.kwargs.get('discussion_slug')
if discussion_slug is not None:
qs = qs.filter(topic__slug=discussion_slug)
return qs
def get_context_data(self):
context = super(ProjectForumDetailView, self).get_context_data()
discussion_slug = self.kwargs.get('discussion_slug')
if discussion_slug is not None:
context['answer_form'] = DiscussionAnswerForm(initial={
'topic': context['discussion'],
'creator': self.request.user,
})
context['project_access'] = check_access(
context['discussion'].project, self.request.user)
return context
class ProjectForumCreateView(LoginRequiredMixin, CreateView,
ProjectForumContextMixin):
""" New discussion creation within a project. """
model = SocialForumTopic
form_class = SocialForumCreateForm
def get_success_url(self):
return self.object.get_absolute_url()
def form_valid(self, form):
form.instance.creator = self.request.user
project_slug = self.kwargs.get('project_slug')
if project_slug is not None:
form.instance.project = get_object_or_404(SocialProject,
slug=project_slug)
return super(ProjectForumCreateView, self).form_valid(form)
class ProjectForumUpdateView(ProjectForumUpdateMixin):
""" Existing discussion edition. """
model = SocialForumTopic
form_class = SocialForumUpdateForm
slug_url_kwarg = 'discussion_slug'
class ProjectForumDeleteView(LoginRequiredMixin, DeleteView,
ProjectForumContextMixin):
""" Discussion deletion - only for admins and mods! """
model = SocialForumTopic
def get_success_url(self):
return reverse('projects:discussions',
kwargs={'project_slug': self.object.project.slug})
def post(self, request, pk=None):
if not is_moderator(request.user, self.get_object().project.location):
raise PermissionDenied
return super(ProjectForumDeleteView, self).post(request, pk)
class ProjectForumAnswerCreateView(LoginRequiredMixin, CreateView,
ProjectForumContextMixin):
""" Discussion answer. """
model = SocialForumEntry
form_class = DiscussionAnswerForm
def get_success_url(self):
return self.object.topic.get_absolute_url()
def get_initial(self):
initial = super(ProjectForumAnswerCreateView, self).get_initial()
discussion_slug = self.kwargs.get('discussion_slug')
if discussion_slug is not None:
initial['topic'] = get_object_or_404(SocialForumTopic,
slug=discussion_slug)
initial['creator'] = self.request.user
return initial
def form_valid(self, form):
form.instance.creator = self.request.user
return super(ProjectForumAnswerCreateView, self).form_valid(form)
class ProjectForumAnswerUpdateView(ProjectForumUpdateMixin):
""" Edition of your own discussion answers, possibly for admins. """
model = SocialForumEntry
form_class = DiscussionAnswerForm
def get_success_url(self):
return self.object.topic.get_absolute_url()
class ProjectForumAnswerDeleteView(LoginRequiredMixin, DeleteView,
ProjectForumContextMixin):
""" Discussion entries deletion - admins, mods and project owners. """
model = SocialForumEntry
def get_success_url(self):
return self.object.topic.get_absolute_url()
def post(self, request, pk=None):
if not check_access(self.get_object().topic.project, request.user):
raise PermissionDenied
return super(ProjectForumAnswerDeleteView, self).post(request, pk)
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
1639,
14,
1018,
14,
3924,
492,
23724,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
17469,
492,
664,
63,
785,
63,
269,
63,
5188,
199,
504,
1639,
14,
4196,
14,
6767,
492,
3820,
2768,
199,
504,
1639,
14,
4196,
14,
6767,
14,
3773,
492,
2790,
2768,
12,
8496,
2768,
12,
6162,
2768,
199,
199,
504,
9825,
63,
1018,
14,
30192,
492,
16430,
8030,
4256,
199,
504,
9825,
63,
1018,
14,
6060,
492,
365,
63,
25597,
199,
199,
504,
1275,
30192,
492,
7290,
2998,
4256,
199,
504,
2508,
3351,
492,
5289,
67,
8817,
19104,
2821,
12,
2002,
7180,
1858,
453,
2499,
2821,
4202,
490,
2002,
7180,
1858,
453,
4152,
2821,
199,
504,
2508,
992,
492,
2002,
7180,
1858,
453,
12157,
12,
2002,
7180,
1858,
453,
3900,
12,
2002,
7180,
4761,
199,
504,
2508,
6060,
492,
1104,
63,
2732,
421,
199,
533,
7290,
1858,
453,
2998,
4256,
8,
4761,
2998,
4256,
304,
272,
408,
437,
20048,
367,
16582,
1007,
5856,
367,
642,
2199,
14,
408,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1824,
29,
403,
12,
1011,
958,
304,
267,
1067,
275,
1613,
8,
4761,
1858,
453,
2998,
4256,
12,
291,
680,
362,
63,
1100,
63,
576,
342,
267,
2199,
63,
5464,
275,
291,
14,
958,
14,
362,
360,
1715,
63,
5464,
358,
267,
340,
2199,
63,
5464,
365,
440,
488,
26,
288,
1067,
459,
785,
418,
275,
664,
63,
785,
63,
269,
63,
5188,
8,
31356,
4761,
12,
8179,
8889,
29,
1715,
63,
5464,
9,
288,
1067,
459,
1985,
418,
275,
1067,
459,
785,
2278,
1985,
288,
1067,
459,
374,
63,
25597,
418,
275,
365,
63,
25597,
8,
277,
14,
1069,
14,
751,
12,
8962,
1067,
459,
1985,
1105,
267,
340,
1824,
365,
440,
488,
26,
288,
1067,
459,
964,
418,
275,
1824,
267,
16582,
63,
5464,
275,
291,
14,
958,
14,
362,
360,
14410,
63,
5464,
358,
267,
340,
16582,
63,
5464,
365,
440,
488,
26,
288,
1067,
459,
14410,
418,
275,
664,
63,
785,
63,
269,
63,
5188,
8,
31356,
1858,
453,
12157,
12,
10028,
8889,
29,
14410,
63,
5464,
9,
267,
372,
1067,
421,
199,
533,
7290,
1858,
453,
4152,
4256,
8,
8880,
8030,
4256,
12,
6162,
2768,
12,
2892,
7290,
1858,
453,
2998,
4256,
304,
272,
408,
437,
20048,
367,
16582,
325,
1671,
4513,
436,
16582,
4811,
14,
408,
339,
347,
4983,
63,
1074,
2531,
277,
304,
267,
340,
440,
1104,
63,
2732,
8,
277,
14,
362,
63,
785,
1062,
291,
14,
1069,
14,
751,
304,
288,
746,
23724,
339,
347,
664,
8,
277,
12,
1056,
12,
2199,
63,
5464,
29,
403,
12,
16582,
63,
5464,
29,
403,
12,
3803,
29,
403,
304,
267,
291,
14,
5693,
63,
1074,
12798,
267,
372,
1613,
8,
4761,
1858,
453,
4152,
4256,
12,
291,
680,
362,
8,
1069,
12,
2199,
63,
5464,
12,
9144,
16582,
63,
5464,
9,
339,
347,
2963,
8,
277,
12,
1056,
12,
2199,
63,
5464,
29,
403,
12,
16582,
63,
5464,
29,
403,
12,
3803,
29,
403,
304,
267,
291,
14,
5693,
63,
1074,
12798,
267,
372,
1613,
8,
4761,
1858,
453,
4152,
4256,
12,
291,
680,
1932,
8,
1069,
12,
2199,
63,
5464,
12,
12740,
16582,
63,
5464,
9,
421,
199,
533,
7290,
1858,
453,
23239,
8,
4761,
1858,
453,
2998,
4256,
12,
3820,
2768,
304,
272,
408,
437,
769,
402,
4339,
527,
1356,
4453,
1373,
2199,
14,
408,
272,
1402,
275,
2002,
7180,
1858,
453,
12157,
272,
9881,
23043,
63,
991,
275,
5661,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
6377,
275,
1613,
8,
4761,
1858,
453,
23239,
12,
291,
680,
362,
63,
7924,
342,
267,
2199,
63,
5464,
275,
291,
14,
958,
14,
362,
360,
1715,
63,
5464,
358,
267,
340,
2199,
63,
5464,
365,
440,
488,
26,
288,
6377,
275,
6377,
14,
1541,
8,
1715,
363,
5464,
29,
1715,
63,
5464,
9,
267,
372,
6377,
421,
199,
533,
7290,
1858,
453,
28539,
8,
4761,
1858,
453,
2998,
4256,
12,
3820,
2768,
304,
272,
408,
7309,
16582,
543,
17133,
14,
408,
272,
1402,
275,
2002,
7180,
1858,
453,
3900,
272,
9881,
23043,
63,
991,
275,
5661,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
6377,
275,
1613,
8,
4761,
1858,
453,
28539,
12,
291,
680,
362,
63,
7924,
342,
267,
16582,
63,
5464,
275,
291,
14,
958,
14,
362,
360,
14410,
63,
5464,
358,
267,
340,
16582,
63,
5464,
365,
440,
488,
26,
288,
6377,
275,
6377,
14,
1541,
8,
5746,
363,
5464,
29,
14410,
63,
5464,
9,
267,
372,
6377,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
304,
267,
1067,
275,
1613,
8,
4761,
1858,
453,
28539,
12,
291,
680,
362,
63,
1100,
63,
576,
342,
267,
16582,
63,
5464,
275,
291,
14,
958,
14,
362,
360,
14410,
63,
5464,
358,
267,
340,
16582,
63,
5464,
365,
440,
488,
26,
288,
1067,
459,
5934,
63,
964,
418,
275,
5289,
67,
8817,
19104,
2821,
8,
2747,
3126,
355,
283,
5746,
356,
1067,
459,
14410,
995,
355,
283,
9986,
356,
291,
14,
1069,
14,
751,
12,
288,
3828,
288,
1067,
459,
1715,
63,
2732,
418,
275,
1104,
63,
2732,
8,
355,
1067,
459,
14410,
2278,
1715,
12,
291,
14,
1069,
14,
751,
9,
267,
372,
1067,
421,
199,
533,
7290,
1858,
453,
2499,
2768,
8,
8880,
8030,
4256,
12,
2790,
2768,
12,
2490,
7290,
1858,
453,
2998,
4256,
304,
272,
408,
7053,
16582,
7143,
4453,
282,
2199,
14,
408,
272,
1402,
275,
2002,
7180,
1858,
453,
12157,
272,
1824,
63,
533,
275,
2002,
7180,
1858,
453,
2499,
2821,
339,
347,
664,
63,
3742,
63,
633,
8,
277,
304,
267,
372,
291,
14,
785,
14,
362,
63,
6116,
63,
633,
342,
339,
347,
1824,
63,
1078,
8,
277,
12,
1824,
304,
267,
1824,
14,
842,
14,
9986,
275,
291,
14,
1069,
14,
751,
267,
2199,
63,
5464,
275,
291,
14,
958,
14,
362,
360,
1715,
63,
5464,
358,
267,
340,
2199,
63,
5464,
365,
440,
488,
26,
288,
1824,
14,
842,
14,
1715,
275,
664,
63,
785,
63,
269,
63,
5188,
8,
31356,
4761,
12,
10028,
8889,
29,
1715,
63,
5464,
9,
267,
372,
1613,
8
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
1639,
14,
1018,
14,
3924,
492,
23724,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
17469,
492,
664,
63,
785,
63,
269,
63,
5188,
199,
504,
1639,
14,
4196,
14,
6767,
492,
3820,
2768,
199,
504,
1639,
14,
4196,
14,
6767,
14,
3773,
492,
2790,
2768,
12,
8496,
2768,
12,
6162,
2768,
199,
199,
504,
9825,
63,
1018,
14,
30192,
492,
16430,
8030,
4256,
199,
504,
9825,
63,
1018,
14,
6060,
492,
365,
63,
25597,
199,
199,
504,
1275,
30192,
492,
7290,
2998,
4256,
199,
504,
2508,
3351,
492,
5289,
67,
8817,
19104,
2821,
12,
2002,
7180,
1858,
453,
2499,
2821,
4202,
490,
2002,
7180,
1858,
453,
4152,
2821,
199,
504,
2508,
992,
492,
2002,
7180,
1858,
453,
12157,
12,
2002,
7180,
1858,
453,
3900,
12,
2002,
7180,
4761,
199,
504,
2508,
6060,
492,
1104,
63,
2732,
421,
199,
533,
7290,
1858,
453,
2998,
4256,
8,
4761,
2998,
4256,
304,
272,
408,
437,
20048,
367,
16582,
1007,
5856,
367,
642,
2199,
14,
408,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1824,
29,
403,
12,
1011,
958,
304,
267,
1067,
275,
1613,
8,
4761,
1858,
453,
2998,
4256,
12,
291,
680,
362,
63,
1100,
63,
576,
342,
267,
2199,
63,
5464,
275,
291,
14,
958,
14,
362,
360,
1715,
63,
5464,
358,
267,
340,
2199,
63,
5464,
365,
440,
488,
26,
288,
1067,
459,
785,
418,
275,
664,
63,
785,
63,
269,
63,
5188,
8,
31356,
4761,
12,
8179,
8889,
29,
1715,
63,
5464,
9,
288,
1067,
459,
1985,
418,
275,
1067,
459,
785,
2278,
1985,
288,
1067,
459,
374,
63,
25597,
418,
275,
365,
63,
25597,
8,
277,
14,
1069,
14,
751,
12,
8962,
1067,
459,
1985,
1105,
267,
340,
1824,
365,
440,
488,
26,
288,
1067,
459,
964,
418,
275,
1824,
267,
16582,
63,
5464,
275,
291,
14,
958,
14,
362,
360,
14410,
63,
5464,
358,
267,
340,
16582,
63,
5464,
365,
440,
488,
26,
288,
1067,
459,
14410,
418,
275,
664,
63,
785,
63,
269,
63,
5188,
8,
31356,
1858,
453,
12157,
12,
10028,
8889,
29,
14410,
63,
5464,
9,
267,
372,
1067,
421,
199,
533,
7290,
1858,
453,
4152,
4256,
8,
8880,
8030,
4256,
12,
6162,
2768,
12,
2892,
7290,
1858,
453,
2998,
4256,
304,
272,
408,
437,
20048,
367,
16582,
325,
1671,
4513,
436,
16582,
4811,
14,
408,
339,
347,
4983,
63,
1074,
2531,
277,
304,
267,
340,
440,
1104,
63,
2732,
8,
277,
14,
362,
63,
785,
1062,
291,
14,
1069,
14,
751,
304,
288,
746,
23724,
339,
347,
664,
8,
277,
12,
1056,
12,
2199,
63,
5464,
29,
403,
12,
16582,
63,
5464,
29,
403,
12,
3803,
29,
403,
304,
267,
291,
14,
5693,
63,
1074,
12798,
267,
372,
1613,
8,
4761,
1858,
453,
4152,
4256,
12,
291,
680,
362,
8,
1069,
12,
2199,
63,
5464,
12,
9144,
16582,
63,
5464,
9,
339,
347,
2963,
8,
277,
12,
1056,
12,
2199,
63,
5464,
29,
403,
12,
16582,
63,
5464,
29,
403,
12,
3803,
29,
403,
304,
267,
291,
14,
5693,
63,
1074,
12798,
267,
372,
1613,
8,
4761,
1858,
453,
4152,
4256,
12,
291,
680,
1932,
8,
1069,
12,
2199,
63,
5464,
12,
12740,
16582,
63,
5464,
9,
421,
199,
533,
7290,
1858,
453,
23239,
8,
4761,
1858,
453,
2998,
4256,
12,
3820,
2768,
304,
272,
408,
437,
769,
402,
4339,
527,
1356,
4453,
1373,
2199,
14,
408,
272,
1402,
275,
2002,
7180,
1858,
453,
12157,
272,
9881,
23043,
63,
991,
275,
5661,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
6377,
275,
1613,
8,
4761,
1858,
453,
23239,
12,
291,
680,
362,
63,
7924,
342,
267,
2199,
63,
5464,
275,
291,
14,
958,
14,
362,
360,
1715,
63,
5464,
358,
267,
340,
2199,
63,
5464,
365,
440,
488,
26,
288,
6377,
275,
6377,
14,
1541,
8,
1715,
363,
5464,
29,
1715,
63,
5464,
9,
267,
372,
6377,
421,
199,
533,
7290,
1858,
453,
28539,
8,
4761,
1858,
453,
2998,
4256,
12,
3820,
2768,
304,
272,
408,
7309,
16582,
543,
17133,
14,
408,
272,
1402,
275,
2002,
7180,
1858,
453,
3900,
272,
9881,
23043,
63,
991,
275,
5661,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
6377,
275,
1613,
8,
4761,
1858,
453,
28539,
12,
291,
680,
362,
63,
7924,
342,
267,
16582,
63,
5464,
275,
291,
14,
958,
14,
362,
360,
14410,
63,
5464,
358,
267,
340,
16582,
63,
5464,
365,
440,
488,
26,
288,
6377,
275,
6377,
14,
1541,
8,
5746,
363,
5464,
29,
14410,
63,
5464,
9,
267,
372,
6377,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
304,
267,
1067,
275,
1613,
8,
4761,
1858,
453,
28539,
12,
291,
680,
362,
63,
1100,
63,
576,
342,
267,
16582,
63,
5464,
275,
291,
14,
958,
14,
362,
360,
14410,
63,
5464,
358,
267,
340,
16582,
63,
5464,
365,
440,
488,
26,
288,
1067,
459,
5934,
63,
964,
418,
275,
5289,
67,
8817,
19104,
2821,
8,
2747,
3126,
355,
283,
5746,
356,
1067,
459,
14410,
995,
355,
283,
9986,
356,
291,
14,
1069,
14,
751,
12,
288,
3828,
288,
1067,
459,
1715,
63,
2732,
418,
275,
1104,
63,
2732,
8,
355,
1067,
459,
14410,
2278,
1715,
12,
291,
14,
1069,
14,
751,
9,
267,
372,
1067,
421,
199,
533,
7290,
1858,
453,
2499,
2768,
8,
8880,
8030,
4256,
12,
2790,
2768,
12,
2490,
7290,
1858,
453,
2998,
4256,
304,
272,
408,
7053,
16582,
7143,
4453,
282,
2199,
14,
408,
272,
1402,
275,
2002,
7180,
1858,
453,
12157,
272,
1824,
63,
533,
275,
2002,
7180,
1858,
453,
2499,
2821,
339,
347,
664,
63,
3742,
63,
633,
8,
277,
304,
267,
372,
291,
14,
785,
14,
362,
63,
6116,
63,
633,
342,
339,
347,
1824,
63,
1078,
8,
277,
12,
1824,
304,
267,
1824,
14,
842,
14,
9986,
275,
291,
14,
1069,
14,
751,
267,
2199,
63,
5464,
275,
291,
14,
958,
14,
362,
360,
1715,
63,
5464,
358,
267,
340,
2199,
63,
5464,
365,
440,
488,
26,
288,
1824,
14,
842,
14,
1715,
275,
664,
63,
785,
63,
269,
63,
5188,
8,
31356,
4761,
12,
10028,
8889,
29,
1715,
63,
5464,
9,
267,
372,
1613,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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patterns.
fnmatch(FILENAME, PATTERN) matches according to the local convention.
fnmatchcase(FILENAME, PATTERN) always takes case in account.
The functions operate by translating the pattern into a regular
expression. They cache the compiled regular expressions for speed.
The function translate(PATTERN) returns a regular expression
corresponding to PATTERN. (It does not compile it.)
"""
import os
import posixpath
import re
import functools
__all__ = ["filter", "fnmatch", "fnmatchcase", "translate"]
def fnmatch(name, pat):
"""Test whether FILENAME matches PATTERN.
Patterns are Unix shell style:
* matches everything
? matches any single character
[seq] matches any character in seq
[!seq] matches any char not in seq
An initial period in FILENAME is not special.
Both FILENAME and PATTERN are first case-normalized
if the operating system requires it.
If you don't want this, use fnmatchcase(FILENAME, PATTERN).
"""
name = os.path.normcase(name)
pat = os.path.normcase(pat)
return fnmatchcase(name, pat)
@functools.lru_cache(maxsize=256, typed=True)
def _compile_pattern(pat):
if isinstance(pat, bytes):
pat_str = str(pat, 'ISO-8859-1')
res_str = translate(pat_str)
res = bytes(res_str, 'ISO-8859-1')
else:
res = translate(pat)
return re.compile(res).match
def filter(names, pat):
"""Return the subset of the list NAMES that match PAT."""
result = []
pat = os.path.normcase(pat)
match = _compile_pattern(pat)
if os.path is posixpath:
# normcase on posix is NOP. Optimize it away from the loop.
for name in names:
if match(name):
result.append(name)
else:
for name in names:
if match(os.path.normcase(name)):
result.append(name)
return result
def fnmatchcase(name, pat):
"""Test whether FILENAME matches PATTERN, including case.
This is a version of fnmatch() which doesn't case-normalize
its arguments.
"""
match = _compile_pattern(pat)
return match(name) is not None
def translate(pat):
"""Translate a shell PATTERN to a regular expression.
There is no way to quote meta-characters.
"""
i, n = 0, len(pat)
res = ''
while i < n:
c = pat[i]
i = i+1
if c == '*':
res = res + '.*'
elif c == '?':
res = res + '.'
elif c == '[':
j = i
if j < n and pat[j] == '!':
j = j+1
if j < n and pat[j] == ']':
j = j+1
while j < n and pat[j] != ']':
j = j+1
if j >= n:
res = res + '\\['
else:
stuff = pat[i:j].replace('\\','\\\\')
i = j+1
if stuff[0] == '!':
stuff = '^' + stuff[1:]
elif stuff[0] == '^':
stuff = '\\' + stuff
res = '%s[%s]' % (res, stuff)
else:
res = res + re.escape(c)
return res + '\Z(?ms)'
|
gpl-3.0
|
[
624,
8117,
4877,
543,
5218,
7970,
14,
199,
199,
15359,
8,
15440,
12,
31467,
7689,
9,
4450,
7182,
370,
314,
2257,
16129,
14,
199,
15359,
2546,
8,
15440,
12,
31467,
7689,
9,
3544,
6181,
1930,
315,
2933,
14,
199,
199,
1918,
3423,
19218,
701,
1752,
24615,
314,
3851,
1901,
282,
5578,
199,
5599,
14,
221,
9322,
2581,
314,
10311,
5578,
8455,
367,
8112,
14,
199,
199,
1918,
805,
9028,
8,
10764,
9,
2529,
282,
5578,
3965,
199,
989,
31137,
370,
31467,
7689,
14,
221,
334,
7940,
1630,
440,
6555,
652,
4959,
199,
624,
199,
646,
747,
199,
646,
15454,
199,
646,
295,
199,
646,
9143,
199,
199,
363,
452,
363,
275,
2097,
1541,
401,
298,
15359,
401,
298,
15359,
2546,
401,
298,
5275,
937,
199,
199,
318,
15951,
8,
354,
12,
12713,
304,
272,
408,
774,
3775,
16444,
11536,
4450,
31467,
7689,
14,
339,
510,
4823,
787,
13074,
5218,
3449,
26,
339,
627,
755,
4450,
8137,
272,
5805,
755,
4450,
1263,
2849,
4528,
272,
359,
3610,
61,
257,
4450,
1263,
4528,
315,
5412,
272,
359,
1,
3610,
61,
221,
4450,
1263,
1495,
440,
315,
5412,
339,
1626,
2536,
6247,
315,
16444,
11536,
365,
440,
4539,
14,
272,
17650,
16444,
11536,
436,
31467,
7689,
787,
1642,
1930,
13,
12916,
272,
340,
314,
17406,
2656,
5074,
652,
14,
272,
982,
1265,
2793,
1133,
2934,
642,
12,
675,
15951,
2546,
8,
15440,
12,
31467,
7689,
680,
272,
408,
272,
536,
275,
747,
14,
515,
14,
21288,
8,
354,
9,
272,
12713,
275,
747,
14,
515,
14,
21288,
8,
10853,
9,
272,
372,
15951,
2546,
8,
354,
12,
12713,
9,
199,
199,
32,
17869,
14,
25003,
63,
1637,
8,
13634,
29,
3912,
12,
20041,
29,
549,
9,
199,
318,
485,
2014,
63,
3401,
8,
10853,
304,
272,
340,
1228,
8,
10853,
12,
2783,
304,
267,
12713,
63,
495,
275,
620,
8,
10853,
12,
283,
7336,
13,
4830,
13,
17,
358,
267,
522,
63,
495,
275,
9028,
8,
10853,
63,
495,
9,
267,
522,
275,
2783,
8,
470,
63,
495,
12,
283,
7336,
13,
4830,
13,
17,
358,
272,
587,
26,
267,
522,
275,
9028,
8,
10853,
9,
272,
372,
295,
14,
2014,
8,
470,
680,
1431,
199,
199,
318,
2457,
8,
1247,
12,
12713,
304,
272,
408,
1767,
314,
10026,
402,
314,
769,
26149,
654,
626,
1336,
31467,
1041,
272,
754,
275,
942,
272,
12713,
275,
747,
14,
515,
14,
21288,
8,
10853,
9,
272,
1336,
275,
485,
2014,
63,
3401,
8,
10853,
9,
272,
340,
747,
14,
515,
365,
15454,
26,
267,
327,
6316,
2546,
641,
10694,
365,
653,
1938,
14,
19246,
794,
652,
13437,
687,
314,
4438,
14,
267,
367,
536,
315,
1561,
26,
288,
340,
1336,
8,
354,
304,
355,
754,
14,
740,
8,
354,
9,
272,
587,
26,
267,
367,
536,
315,
1561,
26,
288,
340,
1336,
8,
736,
14,
515,
14,
21288,
8,
354,
2298,
355,
754,
14,
740,
8,
354,
9,
272,
372,
754,
199,
199,
318,
15951,
2546,
8,
354,
12,
12713,
304,
272,
408,
774,
3775,
16444,
11536,
4450,
31467,
7689,
12,
5893,
1930,
14,
339,
961,
365,
282,
1015,
402,
15951,
342,
1314,
3181,
1133,
1930,
13,
7721,
272,
2399,
2368,
14,
272,
408,
272,
1336,
275,
485,
2014,
63,
3401,
8,
10853,
9,
272,
372,
1336,
8,
354,
9,
365,
440,
488,
421,
199,
318,
9028,
8,
10853,
304,
272,
408,
18355,
282,
5218,
31467,
7689,
370,
282,
5578,
3965,
14,
339,
6006,
365,
949,
4340,
370,
6313,
3404,
13,
16516,
14,
272,
408,
339,
284,
12,
302,
275,
378,
12,
822,
8,
10853,
9,
272,
522,
275,
2125,
272,
1830,
284,
665,
302,
26,
267,
286,
275,
12713,
59,
73,
61,
267,
284,
275,
284,
11,
17,
267,
340,
286,
508,
22969,
288,
522,
275,
522,
435,
1987,
10223,
267,
916,
286,
508,
8720,
356,
288,
522,
275,
522,
435,
7815,
267,
916,
286,
508,
6730,
356,
288,
1335,
275,
284,
288,
340,
1335,
665,
302,
436,
12713,
59,
74,
61,
508,
14597,
356,
355,
1335,
275,
1335,
11,
17,
288,
340,
1335,
665,
302,
436,
12713,
59,
74,
61,
508,
24710,
356,
355,
1335,
275,
1335,
11,
17,
288,
1830,
1335,
665,
302,
436,
12713,
59,
74,
61,
1137,
24710,
356,
355,
1335,
275,
1335,
11,
17,
288,
340,
1335,
2356,
302,
26,
355,
522,
275,
522,
435,
6468,
459,
288,
587,
26,
355,
8292,
275,
12713,
59,
73,
26,
74,
1055,
1814,
11671,
1673,
8712,
358,
355,
284,
275,
1335,
11,
17,
355,
340,
8292,
59,
16,
61,
508,
14597,
356,
490,
8292,
275,
14452,
7,
435,
8292,
59,
17,
2938,
355,
916,
8292,
59,
16,
61,
508,
14452,
356,
490,
8292,
275,
22548,
435,
8292,
355,
522,
275,
1543,
83,
9722,
83,
6616,
450,
334,
470,
12,
8292,
9,
267,
587,
26,
288,
522,
275,
522,
435,
295,
14,
3765,
8,
67,
9,
272,
372,
522,
435,
1557,
58,
2229,
706,
3171,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
8117,
4877,
543,
5218,
7970,
14,
199,
199,
15359,
8,
15440,
12,
31467,
7689,
9,
4450,
7182,
370,
314,
2257,
16129,
14,
199,
15359,
2546,
8,
15440,
12,
31467,
7689,
9,
3544,
6181,
1930,
315,
2933,
14,
199,
199,
1918,
3423,
19218,
701,
1752,
24615,
314,
3851,
1901,
282,
5578,
199,
5599,
14,
221,
9322,
2581,
314,
10311,
5578,
8455,
367,
8112,
14,
199,
199,
1918,
805,
9028,
8,
10764,
9,
2529,
282,
5578,
3965,
199,
989,
31137,
370,
31467,
7689,
14,
221,
334,
7940,
1630,
440,
6555,
652,
4959,
199,
624,
199,
646,
747,
199,
646,
15454,
199,
646,
295,
199,
646,
9143,
199,
199,
363,
452,
363,
275,
2097,
1541,
401,
298,
15359,
401,
298,
15359,
2546,
401,
298,
5275,
937,
199,
199,
318,
15951,
8,
354,
12,
12713,
304,
272,
408,
774,
3775,
16444,
11536,
4450,
31467,
7689,
14,
339,
510,
4823,
787,
13074,
5218,
3449,
26,
339,
627,
755,
4450,
8137,
272,
5805,
755,
4450,
1263,
2849,
4528,
272,
359,
3610,
61,
257,
4450,
1263,
4528,
315,
5412,
272,
359,
1,
3610,
61,
221,
4450,
1263,
1495,
440,
315,
5412,
339,
1626,
2536,
6247,
315,
16444,
11536,
365,
440,
4539,
14,
272,
17650,
16444,
11536,
436,
31467,
7689,
787,
1642,
1930,
13,
12916,
272,
340,
314,
17406,
2656,
5074,
652,
14,
272,
982,
1265,
2793,
1133,
2934,
642,
12,
675,
15951,
2546,
8,
15440,
12,
31467,
7689,
680,
272,
408,
272,
536,
275,
747,
14,
515,
14,
21288,
8,
354,
9,
272,
12713,
275,
747,
14,
515,
14,
21288,
8,
10853,
9,
272,
372,
15951,
2546,
8,
354,
12,
12713,
9,
199,
199,
32,
17869,
14,
25003,
63,
1637,
8,
13634,
29,
3912,
12,
20041,
29,
549,
9,
199,
318,
485,
2014,
63,
3401,
8,
10853,
304,
272,
340,
1228,
8,
10853,
12,
2783,
304,
267,
12713,
63,
495,
275,
620,
8,
10853,
12,
283,
7336,
13,
4830,
13,
17,
358,
267,
522,
63,
495,
275,
9028,
8,
10853,
63,
495,
9,
267,
522,
275,
2783,
8,
470,
63,
495,
12,
283,
7336,
13,
4830,
13,
17,
358,
272,
587,
26,
267,
522,
275,
9028,
8,
10853,
9,
272,
372,
295,
14,
2014,
8,
470,
680,
1431,
199,
199,
318,
2457,
8,
1247,
12,
12713,
304,
272,
408,
1767,
314,
10026,
402,
314,
769,
26149,
654,
626,
1336,
31467,
1041,
272,
754,
275,
942,
272,
12713,
275,
747,
14,
515,
14,
21288,
8,
10853,
9,
272,
1336,
275,
485,
2014,
63,
3401,
8,
10853,
9,
272,
340,
747,
14,
515,
365,
15454,
26,
267,
327,
6316,
2546,
641,
10694,
365,
653,
1938,
14,
19246,
794,
652,
13437,
687,
314,
4438,
14,
267,
367,
536,
315,
1561,
26,
288,
340,
1336,
8,
354,
304,
355,
754,
14,
740,
8,
354,
9,
272,
587,
26,
267,
367,
536,
315,
1561,
26,
288,
340,
1336,
8,
736,
14,
515,
14,
21288,
8,
354,
2298,
355,
754,
14,
740,
8,
354,
9,
272,
372,
754,
199,
199,
318,
15951,
2546,
8,
354,
12,
12713,
304,
272,
408,
774,
3775,
16444,
11536,
4450,
31467,
7689,
12,
5893,
1930,
14,
339,
961,
365,
282,
1015,
402,
15951,
342,
1314,
3181,
1133,
1930,
13,
7721,
272,
2399,
2368,
14,
272,
408,
272,
1336,
275,
485,
2014,
63,
3401,
8,
10853,
9,
272,
372,
1336,
8,
354,
9,
365,
440,
488,
421,
199,
318,
9028,
8,
10853,
304,
272,
408,
18355,
282,
5218,
31467,
7689,
370,
282,
5578,
3965,
14,
339,
6006,
365,
949,
4340,
370,
6313,
3404,
13,
16516,
14,
272,
408,
339,
284,
12,
302,
275,
378,
12,
822,
8,
10853,
9,
272,
522,
275,
2125,
272,
1830,
284,
665,
302,
26,
267,
286,
275,
12713,
59,
73,
61,
267,
284,
275,
284,
11,
17,
267,
340,
286,
508,
22969,
288,
522,
275,
522,
435,
1987,
10223,
267,
916,
286,
508,
8720,
356,
288,
522,
275,
522,
435,
7815,
267,
916,
286,
508,
6730,
356,
288,
1335,
275,
284,
288,
340,
1335,
665,
302,
436,
12713,
59,
74,
61,
508,
14597,
356,
355,
1335,
275,
1335,
11,
17,
288,
340,
1335,
665,
302,
436,
12713,
59,
74,
61,
508,
24710,
356,
355,
1335,
275,
1335,
11,
17,
288,
1830,
1335,
665,
302,
436,
12713,
59,
74,
61,
1137,
24710,
356,
355,
1335,
275,
1335,
11,
17,
288,
340,
1335,
2356,
302,
26,
355,
522,
275,
522,
435,
6468,
459,
288,
587,
26,
355,
8292,
275,
12713,
59,
73,
26,
74,
1055,
1814,
11671,
1673,
8712,
358,
355,
284,
275,
1335,
11,
17,
355,
340,
8292,
59,
16,
61,
508,
14597,
356,
490,
8292,
275,
14452,
7,
435,
8292,
59,
17,
2938,
355,
916,
8292,
59,
16,
61,
508,
14452,
356,
490,
8292,
275,
22548,
435,
8292,
355,
522,
275,
1543,
83,
9722,
83,
6616,
450,
334,
470,
12,
8292,
9,
267,
587,
26,
288,
522,
275,
522,
435,
295,
14,
3765,
8,
67,
9,
272,
372,
522,
435,
1557,
58,
2229,
706,
3171,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
raildo/nova
|
nova/api/openstack/compute/networks.py
|
33
|
7369
|
# Copyright 2011 Grid Dynamics
# Copyright 2011 OpenStack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import netaddr
from webob import exc
from nova.api.openstack import common
from nova.api.openstack.compute.schemas import networks as schema
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.api import validation
from nova import exception
from nova.i18n import _
from nova import network
from nova.objects import base as base_obj
from nova.objects import fields as obj_fields
ALIAS = 'os-networks'
authorize = extensions.os_compute_authorizer(ALIAS)
def network_dict(context, network):
fields = ('id', 'cidr', 'netmask', 'gateway', 'broadcast', 'dns1', 'dns2',
'cidr_v6', 'gateway_v6', 'label', 'netmask_v6')
admin_fields = ('created_at', 'updated_at', 'deleted_at', 'deleted',
'injected', 'bridge', 'vlan', 'vpn_public_address',
'vpn_public_port', 'vpn_private_address', 'dhcp_start',
'project_id', 'host', 'bridge_interface', 'multi_host',
'priority', 'rxtx_base', 'mtu', 'dhcp_server',
'enable_dhcp', 'share_address')
if network:
# NOTE(mnaser): We display a limited set of fields so users can know
# what networks are available, extra system-only fields
# are only visible if they are an admin.
if context.is_admin:
fields += admin_fields
# TODO(mriedem): Remove the NovaObject type check once the
# network.create API is returning objects.
is_obj = isinstance(network, base_obj.NovaObject)
result = {}
for field in fields:
# NOTE(mriedem): If network is an object, IPAddress fields need to
# be cast to a string so they look the same in the response as
# before the objects conversion.
if is_obj and isinstance(network.fields[field].AUTO_TYPE,
obj_fields.IPAddress):
# NOTE(danms): Here, network should be an object, which could
# have come from neutron and thus be missing most of the
# attributes. Providing a default to get() avoids trying to
# lazy-load missing attributes.
val = network.get(field, None)
if val is not None:
result[field] = str(val)
else:
result[field] = val
else:
# It's either not an object or it's not an IPAddress field.
result[field] = network.get(field, None)
uuid = network.get('uuid')
if uuid:
result['id'] = uuid
return result
else:
return {}
class NetworkController(wsgi.Controller):
def __init__(self, network_api=None):
self.network_api = network_api or network.API(skip_policy_check=True)
@extensions.expected_errors(())
def index(self, req):
context = req.environ['nova.context']
authorize(context, action='view')
networks = self.network_api.get_all(context)
result = [network_dict(context, net_ref) for net_ref in networks]
return {'networks': result}
@wsgi.response(202)
@extensions.expected_errors((404, 501))
@wsgi.action("disassociate")
def _disassociate_host_and_project(self, req, id, body):
context = req.environ['nova.context']
authorize(context)
try:
self.network_api.associate(context, id, host=None, project=None)
except exception.NetworkNotFound:
msg = _("Network not found")
raise exc.HTTPNotFound(explanation=msg)
except NotImplementedError:
common.raise_feature_not_supported()
@extensions.expected_errors(404)
def show(self, req, id):
context = req.environ['nova.context']
authorize(context, action='view')
try:
network = self.network_api.get(context, id)
except exception.NetworkNotFound:
msg = _("Network not found")
raise exc.HTTPNotFound(explanation=msg)
return {'network': network_dict(context, network)}
@wsgi.response(202)
@extensions.expected_errors((404, 409))
def delete(self, req, id):
context = req.environ['nova.context']
authorize(context)
try:
self.network_api.delete(context, id)
except exception.NetworkInUse as e:
raise exc.HTTPConflict(explanation=e.format_message())
except exception.NetworkNotFound:
msg = _("Network not found")
raise exc.HTTPNotFound(explanation=msg)
@extensions.expected_errors((400, 409, 501))
@validation.schema(schema.create)
def create(self, req, body):
context = req.environ['nova.context']
authorize(context)
params = body["network"]
cidr = params.get("cidr") or params.get("cidr_v6")
params["num_networks"] = 1
params["network_size"] = netaddr.IPNetwork(cidr).size
try:
network = self.network_api.create(context, **params)[0]
except (exception.InvalidCidr,
exception.InvalidIntValue,
exception.InvalidAddress,
exception.NetworkNotCreated) as ex:
raise exc.HTTPBadRequest(explanation=ex.format_message)
except exception.CidrConflict as ex:
raise exc.HTTPConflict(explanation=ex.format_message())
return {"network": network_dict(context, network)}
@wsgi.response(202)
@extensions.expected_errors((400, 501))
@validation.schema(schema.add_network_to_project)
def add(self, req, body):
context = req.environ['nova.context']
authorize(context)
network_id = body['id']
project_id = context.project_id
try:
self.network_api.add_network_to_project(
context, project_id, network_id)
except NotImplementedError:
common.raise_feature_not_supported()
except (exception.NoMoreNetworks,
exception.NetworkNotFoundForUUID) as e:
raise exc.HTTPBadRequest(explanation=e.format_message())
class Networks(extensions.V21APIExtensionBase):
"""Admin-only Network Management Extension."""
name = "Networks"
alias = ALIAS
version = 1
def get_resources(self):
member_actions = {'action': 'POST'}
collection_actions = {'add': 'POST'}
res = extensions.ResourceExtension(
ALIAS, NetworkController(),
member_actions=member_actions,
collection_actions=collection_actions)
return [res]
def get_controller_extensions(self):
return []
|
apache-2.0
|
[
3,
1898,
7760,
16386,
577,
4019,
2932,
199,
3,
1898,
7760,
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,
25798,
199,
504,
14568,
492,
3178,
199,
199,
504,
5913,
14,
1246,
14,
8512,
492,
2863,
199,
504,
5913,
14,
1246,
14,
8512,
14,
3357,
14,
9482,
492,
11759,
465,
4177,
199,
504,
5913,
14,
1246,
14,
8512,
492,
5478,
199,
504,
5913,
14,
1246,
14,
8512,
492,
12464,
199,
504,
5913,
14,
1246,
492,
6411,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
199,
504,
5913,
492,
2784,
199,
504,
5913,
14,
1462,
492,
1300,
465,
1300,
63,
1113,
199,
504,
5913,
14,
1462,
492,
1504,
465,
1559,
63,
955,
199,
199,
12644,
275,
283,
736,
13,
7642,
7,
199,
14204,
275,
5478,
14,
736,
63,
3357,
63,
2502,
1793,
8,
12644,
9,
421,
199,
318,
2784,
63,
807,
8,
1100,
12,
2784,
304,
272,
1504,
275,
661,
344,
297,
283,
10509,
297,
283,
14588,
297,
283,
7019,
297,
283,
10786,
297,
283,
5797,
17,
297,
283,
5797,
18,
297,
1598,
283,
10509,
63,
86,
22,
297,
283,
7019,
63,
86,
22,
297,
283,
1302,
297,
283,
14588,
63,
86,
22,
358,
272,
4628,
63,
955,
275,
661,
3966,
63,
292,
297,
283,
5334,
63,
292,
297,
283,
6062,
63,
292,
297,
283,
6062,
297,
490,
283,
30785,
297,
283,
9528,
297,
283,
7175,
297,
283,
9702,
63,
3455,
63,
1562,
297,
490,
283,
9702,
63,
3455,
63,
719,
297,
283,
9702,
63,
4239,
63,
1562,
297,
283,
10801,
63,
928,
297,
490,
283,
1715,
63,
344,
297,
283,
1102,
297,
283,
9528,
63,
3266,
297,
283,
3029,
63,
1102,
297,
490,
283,
6693,
297,
283,
82,
400,
88,
63,
1095,
297,
283,
17696,
297,
283,
10801,
63,
1000,
297,
490,
283,
4296,
63,
10801,
297,
283,
6251,
63,
1562,
358,
272,
340,
2784,
26,
267,
327,
6944,
8,
77,
3540,
332,
304,
2136,
2929,
282,
13988,
663,
402,
1504,
880,
4390,
883,
5715,
267,
327,
5185,
4052,
11759,
787,
2808,
12,
2402,
2656,
13,
2118,
1504,
267,
327,
5185,
787,
1454,
8917,
340,
2985,
787,
376,
4628,
14,
267,
340,
1067,
14,
374,
63,
2113,
26,
288,
1504,
847,
4628,
63,
955,
267,
327,
3254,
8,
77,
11317,
23522,
304,
5852,
314,
28184,
1692,
730,
1104,
5403,
314,
267,
327,
2784,
14,
981,
3261,
365,
8152,
2251,
14,
267,
365,
63,
1113,
275,
1228,
8,
1200,
12,
1300,
63,
1113,
14,
19884,
1692,
9,
267,
754,
275,
1052,
267,
367,
901,
315,
1504,
26,
288,
327,
6944,
8,
77,
11317,
23522,
304,
982,
2784,
365,
376,
909,
12,
3531,
1476,
1504,
1929,
370,
288,
327,
506,
9106,
370,
282,
1059,
880,
2985,
3648,
314,
2011,
315,
314,
1177,
465,
288,
327,
2544,
314,
2251,
8603,
14,
288,
340,
365,
63,
1113,
436,
1228,
8,
1200,
14,
955,
59,
698,
1055,
13883,
63,
2711,
12,
3660,
1559,
63,
955,
14,
14955,
304,
355,
327,
6944,
8,
24863,
706,
304,
11842,
12,
2784,
1077,
506,
376,
909,
12,
1314,
4293,
355,
327,
1172,
11492,
687,
8224,
436,
12850,
506,
4124,
4750,
402,
314,
355,
327,
3004,
14,
2165,
11604,
282,
849,
370,
664,
342,
23674,
9936,
370,
355,
327,
9617,
13,
912,
4124,
3004,
14,
355,
1139,
275,
2784,
14,
362,
8,
698,
12,
488,
9,
355,
340,
1139,
365,
440,
488,
26,
490,
754,
59,
698,
61,
275,
620,
8,
637,
9,
355,
587,
26,
490,
754,
59,
698,
61,
275,
1139,
288,
587,
26,
355,
327,
2779,
1159,
1902,
440,
376,
909,
503,
652,
1159,
440,
376,
3531,
1476,
901,
14,
355,
754,
59,
698,
61,
275,
2784,
14,
362,
8,
698,
12,
488,
9,
267,
5377,
275,
2784,
14,
362,
360,
2580,
358,
267,
340,
5377,
26,
288,
754,
459,
344,
418,
275,
5377,
267,
372,
754,
272,
587,
26,
267,
372,
1052,
421,
199,
533,
7220,
7506,
8,
6508,
14,
7506,
304,
339,
347,
636,
826,
721,
277,
12,
2784,
63,
1246,
29,
403,
304,
267,
291,
14,
1200,
63,
1246,
275,
2784,
63,
1246,
503,
2784,
14,
3735,
8,
2759,
63,
3185,
63,
1074,
29,
549,
9,
339,
768,
5359,
14,
2062,
63,
2550,
30812,
272,
347,
1478,
8,
277,
12,
2648,
304,
267,
1067,
275,
2648,
14,
2314,
459,
6765,
14,
1100,
418,
267,
20210,
8,
1100,
12,
1595,
534,
1345,
358,
267,
11759,
275,
291,
14,
1200,
63,
1246,
14,
362,
63,
452,
8,
1100,
9,
267,
754,
275,
359,
1200,
63,
807,
8,
1100,
12,
1851,
63,
1121,
9,
367,
1851,
63,
1121,
315,
11759,
61,
267,
372,
791,
7642,
356,
754,
93,
339,
768,
6508,
14,
1310,
8,
4999,
9,
272,
768,
5359,
14,
2062,
63,
2550,
1332,
5188,
12,
28606,
430,
272,
768,
6508,
14,
1287,
480,
2297,
16021,
531,
272,
347,
485,
2297,
16021,
63,
1102,
63,
460,
63,
1715,
8,
277,
12,
2648,
12,
1305,
12,
2396,
304,
267,
1067,
275,
2648,
14,
2314,
459,
6765,
14,
1100,
418,
267,
20210,
8,
1100,
9,
398,
862,
26,
288,
291,
14,
1200,
63,
1246,
14,
16021,
8,
1100,
12,
1305,
12,
1591,
29,
403,
12,
2199,
29,
403,
9,
267,
871,
1919,
14,
4491,
4667,
26,
288,
1499,
275,
3824,
4491,
440,
1911,
531,
288,
746,
3178,
14,
26553,
8,
15228,
29,
1328,
9,
267,
871
] |
[
1898,
7760,
16386,
577,
4019,
2932,
199,
3,
1898,
7760,
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,
25798,
199,
504,
14568,
492,
3178,
199,
199,
504,
5913,
14,
1246,
14,
8512,
492,
2863,
199,
504,
5913,
14,
1246,
14,
8512,
14,
3357,
14,
9482,
492,
11759,
465,
4177,
199,
504,
5913,
14,
1246,
14,
8512,
492,
5478,
199,
504,
5913,
14,
1246,
14,
8512,
492,
12464,
199,
504,
5913,
14,
1246,
492,
6411,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
199,
504,
5913,
492,
2784,
199,
504,
5913,
14,
1462,
492,
1300,
465,
1300,
63,
1113,
199,
504,
5913,
14,
1462,
492,
1504,
465,
1559,
63,
955,
199,
199,
12644,
275,
283,
736,
13,
7642,
7,
199,
14204,
275,
5478,
14,
736,
63,
3357,
63,
2502,
1793,
8,
12644,
9,
421,
199,
318,
2784,
63,
807,
8,
1100,
12,
2784,
304,
272,
1504,
275,
661,
344,
297,
283,
10509,
297,
283,
14588,
297,
283,
7019,
297,
283,
10786,
297,
283,
5797,
17,
297,
283,
5797,
18,
297,
1598,
283,
10509,
63,
86,
22,
297,
283,
7019,
63,
86,
22,
297,
283,
1302,
297,
283,
14588,
63,
86,
22,
358,
272,
4628,
63,
955,
275,
661,
3966,
63,
292,
297,
283,
5334,
63,
292,
297,
283,
6062,
63,
292,
297,
283,
6062,
297,
490,
283,
30785,
297,
283,
9528,
297,
283,
7175,
297,
283,
9702,
63,
3455,
63,
1562,
297,
490,
283,
9702,
63,
3455,
63,
719,
297,
283,
9702,
63,
4239,
63,
1562,
297,
283,
10801,
63,
928,
297,
490,
283,
1715,
63,
344,
297,
283,
1102,
297,
283,
9528,
63,
3266,
297,
283,
3029,
63,
1102,
297,
490,
283,
6693,
297,
283,
82,
400,
88,
63,
1095,
297,
283,
17696,
297,
283,
10801,
63,
1000,
297,
490,
283,
4296,
63,
10801,
297,
283,
6251,
63,
1562,
358,
272,
340,
2784,
26,
267,
327,
6944,
8,
77,
3540,
332,
304,
2136,
2929,
282,
13988,
663,
402,
1504,
880,
4390,
883,
5715,
267,
327,
5185,
4052,
11759,
787,
2808,
12,
2402,
2656,
13,
2118,
1504,
267,
327,
5185,
787,
1454,
8917,
340,
2985,
787,
376,
4628,
14,
267,
340,
1067,
14,
374,
63,
2113,
26,
288,
1504,
847,
4628,
63,
955,
267,
327,
3254,
8,
77,
11317,
23522,
304,
5852,
314,
28184,
1692,
730,
1104,
5403,
314,
267,
327,
2784,
14,
981,
3261,
365,
8152,
2251,
14,
267,
365,
63,
1113,
275,
1228,
8,
1200,
12,
1300,
63,
1113,
14,
19884,
1692,
9,
267,
754,
275,
1052,
267,
367,
901,
315,
1504,
26,
288,
327,
6944,
8,
77,
11317,
23522,
304,
982,
2784,
365,
376,
909,
12,
3531,
1476,
1504,
1929,
370,
288,
327,
506,
9106,
370,
282,
1059,
880,
2985,
3648,
314,
2011,
315,
314,
1177,
465,
288,
327,
2544,
314,
2251,
8603,
14,
288,
340,
365,
63,
1113,
436,
1228,
8,
1200,
14,
955,
59,
698,
1055,
13883,
63,
2711,
12,
3660,
1559,
63,
955,
14,
14955,
304,
355,
327,
6944,
8,
24863,
706,
304,
11842,
12,
2784,
1077,
506,
376,
909,
12,
1314,
4293,
355,
327,
1172,
11492,
687,
8224,
436,
12850,
506,
4124,
4750,
402,
314,
355,
327,
3004,
14,
2165,
11604,
282,
849,
370,
664,
342,
23674,
9936,
370,
355,
327,
9617,
13,
912,
4124,
3004,
14,
355,
1139,
275,
2784,
14,
362,
8,
698,
12,
488,
9,
355,
340,
1139,
365,
440,
488,
26,
490,
754,
59,
698,
61,
275,
620,
8,
637,
9,
355,
587,
26,
490,
754,
59,
698,
61,
275,
1139,
288,
587,
26,
355,
327,
2779,
1159,
1902,
440,
376,
909,
503,
652,
1159,
440,
376,
3531,
1476,
901,
14,
355,
754,
59,
698,
61,
275,
2784,
14,
362,
8,
698,
12,
488,
9,
267,
5377,
275,
2784,
14,
362,
360,
2580,
358,
267,
340,
5377,
26,
288,
754,
459,
344,
418,
275,
5377,
267,
372,
754,
272,
587,
26,
267,
372,
1052,
421,
199,
533,
7220,
7506,
8,
6508,
14,
7506,
304,
339,
347,
636,
826,
721,
277,
12,
2784,
63,
1246,
29,
403,
304,
267,
291,
14,
1200,
63,
1246,
275,
2784,
63,
1246,
503,
2784,
14,
3735,
8,
2759,
63,
3185,
63,
1074,
29,
549,
9,
339,
768,
5359,
14,
2062,
63,
2550,
30812,
272,
347,
1478,
8,
277,
12,
2648,
304,
267,
1067,
275,
2648,
14,
2314,
459,
6765,
14,
1100,
418,
267,
20210,
8,
1100,
12,
1595,
534,
1345,
358,
267,
11759,
275,
291,
14,
1200,
63,
1246,
14,
362,
63,
452,
8,
1100,
9,
267,
754,
275,
359,
1200,
63,
807,
8,
1100,
12,
1851,
63,
1121,
9,
367,
1851,
63,
1121,
315,
11759,
61,
267,
372,
791,
7642,
356,
754,
93,
339,
768,
6508,
14,
1310,
8,
4999,
9,
272,
768,
5359,
14,
2062,
63,
2550,
1332,
5188,
12,
28606,
430,
272,
768,
6508,
14,
1287,
480,
2297,
16021,
531,
272,
347,
485,
2297,
16021,
63,
1102,
63,
460,
63,
1715,
8,
277,
12,
2648,
12,
1305,
12,
2396,
304,
267,
1067,
275,
2648,
14,
2314,
459,
6765,
14,
1100,
418,
267,
20210,
8,
1100,
9,
398,
862,
26,
288,
291,
14,
1200,
63,
1246,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Maximilian-Reuter/SickRage-1
|
lib/stevedore/driver.py
|
21
|
5496
|
from .exception import NoMatches, MultipleMatches
from .named import NamedExtensionManager
class DriverManager(NamedExtensionManager):
"""Load a single plugin with a given name from the namespace.
:param namespace: The namespace for the entry points.
:type namespace: str
:param name: The name of the driver to load.
:type name: str
:param invoke_on_load: Boolean controlling whether to invoke the
object returned by the entry point after the driver is loaded.
:type invoke_on_load: bool
:param invoke_args: Positional arguments to pass when invoking
the object returned by the entry point. Only used if invoke_on_load
is True.
:type invoke_args: tuple
:param invoke_kwds: Named arguments to pass when invoking
the object returned by the entry point. Only used if invoke_on_load
is True.
:type invoke_kwds: dict
:param on_load_failure_callback: Callback function that will be called when
a entrypoint can not be loaded. The arguments that will be provided
when this is called (when an entrypoint fails to load) are
(manager, entrypoint, exception)
:type on_load_failure_callback: function
:param verify_requirements: Use setuptools to enforce the
dependencies of the plugin(s) being loaded. Defaults to False.
:type verify_requirements: bool
"""
def __init__(self, namespace, name,
invoke_on_load=False, invoke_args=(), invoke_kwds={},
on_load_failure_callback=None,
verify_requirements=False):
on_load_failure_callback = on_load_failure_callback \
or self._default_on_load_failure
super(DriverManager, self).__init__(
namespace=namespace,
names=[name],
invoke_on_load=invoke_on_load,
invoke_args=invoke_args,
invoke_kwds=invoke_kwds,
on_load_failure_callback=on_load_failure_callback,
verify_requirements=verify_requirements,
)
@staticmethod
def _default_on_load_failure(drivermanager, ep, err):
raise
@classmethod
def make_test_instance(cls, extension, namespace='TESTING',
propagate_map_exceptions=False,
on_load_failure_callback=None,
verify_requirements=False):
"""Construct a test DriverManager
Test instances are passed a list of extensions to work from rather
than loading them from entry points.
:param extension: Pre-configured Extension instance
:type extension: :class:`~stevedore.extension.Extension`
:param namespace: The namespace for the manager; used only for
identification since the extensions are passed in.
:type namespace: str
:param propagate_map_exceptions: Boolean controlling whether exceptions
are propagated up through the map call or whether they are logged
and then ignored
:type propagate_map_exceptions: bool
:param on_load_failure_callback: Callback function that will
be called when a entrypoint can not be loaded. The
arguments that will be provided when this is called (when
an entrypoint fails to load) are (manager, entrypoint,
exception)
:type on_load_failure_callback: function
:param verify_requirements: Use setuptools to enforce the
dependencies of the plugin(s) being loaded. Defaults to False.
:type verify_requirements: bool
:return: The manager instance, initialized for testing
"""
o = super(DriverManager, cls).make_test_instance(
[extension], namespace=namespace,
propagate_map_exceptions=propagate_map_exceptions,
on_load_failure_callback=on_load_failure_callback,
verify_requirements=verify_requirements)
return o
def _init_plugins(self, extensions):
super(DriverManager, self)._init_plugins(extensions)
if not self.extensions:
name = self._names[0]
raise NoMatches('No %r driver found, looking for %r' %
(self.namespace, name))
if len(self.extensions) > 1:
discovered_drivers = ','.join(e.entry_point_target
for e in self.extensions)
raise MultipleMatches('Multiple %r drivers found: %s' %
(self.namespace, discovered_drivers))
def __call__(self, func, *args, **kwds):
"""Invokes func() for the single loaded extension.
The signature for func() should be::
def func(ext, *args, **kwds):
pass
The first argument to func(), 'ext', is the
:class:`~stevedore.extension.Extension` instance.
Exceptions raised from within func() are logged and ignored.
:param func: Callable to invoke for each extension.
:param args: Variable arguments to pass to func()
:param kwds: Keyword arguments to pass to func()
:returns: List of values returned from func()
"""
results = self.map(func, *args, **kwds)
if results:
return results[0]
@property
def driver(self):
"""Returns the driver being used by this manager.
"""
ext = self.extensions[0]
return ext.obj if ext.obj else ext.plugin
|
gpl-3.0
|
[
504,
1275,
1971,
492,
3091,
12962,
12,
14326,
12962,
199,
504,
1275,
4579,
492,
16198,
6382,
2988,
421,
199,
533,
19447,
2988,
8,
7989,
6382,
2988,
304,
272,
408,
6200,
282,
2849,
3589,
543,
282,
1627,
536,
687,
314,
3231,
14,
339,
520,
635,
3231,
26,
710,
3231,
367,
314,
2397,
4501,
14,
272,
520,
466,
3231,
26,
620,
272,
520,
635,
536,
26,
710,
536,
402,
314,
5253,
370,
2248,
14,
272,
520,
466,
536,
26,
620,
272,
520,
635,
12677,
63,
265,
63,
912,
26,
9411,
30350,
3775,
370,
12677,
314,
267,
909,
2138,
701,
314,
2397,
2376,
2410,
314,
5253,
365,
6511,
14,
272,
520,
466,
12677,
63,
265,
63,
912,
26,
2155,
272,
520,
635,
12677,
63,
589,
26,
15483,
279,
2368,
370,
986,
1380,
26750,
267,
314,
909,
2138,
701,
314,
2397,
2376,
14,
5972,
1202,
340,
12677,
63,
265,
63,
912,
267,
365,
715,
14,
272,
520,
466,
12677,
63,
589,
26,
2008,
272,
520,
635,
12677,
63,
10340,
26,
16198,
2368,
370,
986,
1380,
26750,
267,
314,
909,
2138,
701,
314,
2397,
2376,
14,
5972,
1202,
340,
12677,
63,
265,
63,
912,
267,
365,
715,
14,
272,
520,
466,
12677,
63,
10340,
26,
1211,
272,
520,
635,
641,
63,
912,
63,
5328,
63,
3058,
26,
17555,
805,
626,
911,
506,
2797,
1380,
267,
282,
2397,
1403,
883,
440,
506,
6511,
14,
710,
2368,
626,
911,
506,
2741,
267,
1380,
642,
365,
2797,
334,
6526,
376,
2397,
1403,
6918,
370,
2248,
9,
787,
267,
334,
2609,
12,
2397,
1403,
12,
1919,
9,
272,
520,
466,
641,
63,
912,
63,
5328,
63,
3058,
26,
805,
272,
520,
635,
4911,
63,
7538,
26,
3645,
9116,
370,
15814,
314,
267,
5124,
402,
314,
3589,
8,
83,
9,
3769,
6511,
14,
7827,
370,
756,
14,
272,
520,
466,
4911,
63,
7538,
26,
2155,
272,
408,
339,
347,
636,
826,
721,
277,
12,
3231,
12,
536,
12,
326,
12677,
63,
265,
63,
912,
29,
797,
12,
12677,
63,
589,
16729,
12677,
63,
10340,
10324,
326,
641,
63,
912,
63,
5328,
63,
3058,
29,
403,
12,
326,
4911,
63,
7538,
29,
797,
304,
267,
641,
63,
912,
63,
5328,
63,
3058,
275,
641,
63,
912,
63,
5328,
63,
3058,
971,
288,
503,
291,
423,
885,
63,
265,
63,
912,
63,
5328,
267,
1613,
8,
6158,
2988,
12,
291,
2843,
826,
721,
288,
3231,
29,
3251,
12,
288,
1561,
1524,
354,
467,
288,
12677,
63,
265,
63,
912,
29,
15195,
63,
265,
63,
912,
12,
288,
12677,
63,
589,
29,
15195,
63,
589,
12,
288,
12677,
63,
10340,
29,
15195,
63,
10340,
12,
288,
641,
63,
912,
63,
5328,
63,
3058,
29,
265,
63,
912,
63,
5328,
63,
3058,
12,
288,
4911,
63,
7538,
29,
4712,
63,
7538,
12,
267,
776,
339,
768,
4639,
272,
347,
485,
885,
63,
265,
63,
912,
63,
5328,
8,
3090,
2609,
12,
5442,
12,
2329,
304,
267,
746,
339,
768,
3744,
272,
347,
1852,
63,
396,
63,
842,
8,
1886,
12,
3329,
12,
3231,
534,
2864,
1206,
297,
2574,
19843,
63,
1130,
63,
3924,
29,
797,
12,
2574,
641,
63,
912,
63,
5328,
63,
3058,
29,
403,
12,
2574,
4911,
63,
7538,
29,
797,
304,
267,
408,
11493,
282,
511,
19447,
2988,
398,
1379,
4454,
787,
3032,
282,
769,
402,
5478,
370,
1736,
687,
7830,
267,
2419,
8697,
3062,
687,
2397,
4501,
14,
398,
520,
635,
3329,
26,
5543,
13,
11786,
13282,
1256,
267,
520,
466,
3329,
26,
520,
533,
6054,
1597,
1354,
720,
14,
3435,
14,
6382,
64,
267,
520,
635,
3231,
26,
710,
3231,
367,
314,
5256,
27,
1202,
1454,
367,
288,
29193,
3967,
314,
5478,
787,
3032,
315,
14,
267,
520,
466,
3231,
26,
620,
267,
520,
635,
19843,
63,
1130,
63,
3924,
26,
9411,
30350,
3775,
4967,
288,
787,
25350,
1536,
4012,
314,
2341,
1240,
503,
3775,
2985,
787,
10367,
288,
436,
2066,
5525,
267,
520,
466,
19843,
63,
1130,
63,
3924,
26,
2155,
267,
520,
635,
641,
63,
912,
63,
5328,
63,
3058,
26,
17555,
805,
626,
911,
288,
506,
2797,
1380,
282,
2397,
1403,
883,
440,
506,
6511,
14,
710,
288,
2368,
626,
911,
506,
2741,
1380,
642,
365,
2797,
334,
6526,
288,
376,
2397,
1403,
6918,
370,
2248,
9,
787,
334,
2609,
12,
2397,
1403,
12,
288,
1919,
9,
267,
520,
466,
641,
63,
912,
63,
5328,
63,
3058,
26,
805,
267,
520,
635,
4911,
63,
7538,
26,
3645,
9116,
370,
15814,
314,
288,
5124,
402,
314,
3589,
8,
83,
9,
3769,
6511,
14,
7827,
370,
756,
14,
267,
520,
466,
4911,
63,
7538,
26,
2155,
267,
520,
1107,
26,
710,
5256,
1256,
12,
10038,
367,
5343,
398,
408,
398,
312,
275,
1613,
8,
6158,
2988,
12,
843,
680,
1875,
63,
396,
63,
842,
8,
288,
359,
3435,
467,
3231,
29,
3251,
12,
288,
19843,
63,
1130,
63,
3924,
29,
19432,
63,
1130,
63,
3924,
12,
288,
641,
63,
912,
63,
5328,
63,
3058,
29,
265,
63,
912,
63,
5328,
63,
3058,
12,
288,
4911,
63,
7538,
29,
4712,
63,
7538,
9,
267,
372,
312,
339,
347,
485,
826,
63,
5265,
8,
277,
12,
5478,
304,
267,
1613,
8,
6158,
2988,
12,
291,
10445,
826,
63,
5265,
8,
5359,
9,
398,
340,
440,
291,
14,
5359,
26,
288,
536,
275,
291,
423,
1247,
59,
16,
61,
288,
746,
3091,
12962,
360,
1944,
450,
82,
5253,
1911,
12,
10023,
367,
450,
82,
7,
450,
1169,
334,
277,
14,
3251,
12,
536,
430,
267,
340,
822,
8,
277,
14,
5359,
9,
690,
413,
26,
288,
24983,
63,
13337,
275,
12814,
904,
8,
69,
14,
2373,
63,
1403,
63,
1375,
5101,
367,
325,
315,
291,
14,
5359,
9,
953,
746,
14326,
12962,
360,
8433,
450,
82,
19016,
1911,
26,
450,
83,
7,
450,
3303,
334,
277,
14,
3251,
12,
24983,
63,
13337,
430,
339,
347,
636,
1250,
721,
277,
12,
2562,
12,
627,
589,
12,
1011,
10340,
304,
267,
408,
14883,
22652,
2562,
342,
367,
314,
2849,
6511,
3329,
14,
398,
710,
4955,
367,
2562,
342,
1077,
506,
447,
953,
347,
2562,
8,
832,
12,
627,
589,
12,
1011,
10340,
304,
355,
986,
398,
710,
1642,
1423,
370,
2562,
1062,
283,
832,
297,
365,
314
] |
[
1275,
1971,
492,
3091,
12962,
12,
14326,
12962,
199,
504,
1275,
4579,
492,
16198,
6382,
2988,
421,
199,
533,
19447,
2988,
8,
7989,
6382,
2988,
304,
272,
408,
6200,
282,
2849,
3589,
543,
282,
1627,
536,
687,
314,
3231,
14,
339,
520,
635,
3231,
26,
710,
3231,
367,
314,
2397,
4501,
14,
272,
520,
466,
3231,
26,
620,
272,
520,
635,
536,
26,
710,
536,
402,
314,
5253,
370,
2248,
14,
272,
520,
466,
536,
26,
620,
272,
520,
635,
12677,
63,
265,
63,
912,
26,
9411,
30350,
3775,
370,
12677,
314,
267,
909,
2138,
701,
314,
2397,
2376,
2410,
314,
5253,
365,
6511,
14,
272,
520,
466,
12677,
63,
265,
63,
912,
26,
2155,
272,
520,
635,
12677,
63,
589,
26,
15483,
279,
2368,
370,
986,
1380,
26750,
267,
314,
909,
2138,
701,
314,
2397,
2376,
14,
5972,
1202,
340,
12677,
63,
265,
63,
912,
267,
365,
715,
14,
272,
520,
466,
12677,
63,
589,
26,
2008,
272,
520,
635,
12677,
63,
10340,
26,
16198,
2368,
370,
986,
1380,
26750,
267,
314,
909,
2138,
701,
314,
2397,
2376,
14,
5972,
1202,
340,
12677,
63,
265,
63,
912,
267,
365,
715,
14,
272,
520,
466,
12677,
63,
10340,
26,
1211,
272,
520,
635,
641,
63,
912,
63,
5328,
63,
3058,
26,
17555,
805,
626,
911,
506,
2797,
1380,
267,
282,
2397,
1403,
883,
440,
506,
6511,
14,
710,
2368,
626,
911,
506,
2741,
267,
1380,
642,
365,
2797,
334,
6526,
376,
2397,
1403,
6918,
370,
2248,
9,
787,
267,
334,
2609,
12,
2397,
1403,
12,
1919,
9,
272,
520,
466,
641,
63,
912,
63,
5328,
63,
3058,
26,
805,
272,
520,
635,
4911,
63,
7538,
26,
3645,
9116,
370,
15814,
314,
267,
5124,
402,
314,
3589,
8,
83,
9,
3769,
6511,
14,
7827,
370,
756,
14,
272,
520,
466,
4911,
63,
7538,
26,
2155,
272,
408,
339,
347,
636,
826,
721,
277,
12,
3231,
12,
536,
12,
326,
12677,
63,
265,
63,
912,
29,
797,
12,
12677,
63,
589,
16729,
12677,
63,
10340,
10324,
326,
641,
63,
912,
63,
5328,
63,
3058,
29,
403,
12,
326,
4911,
63,
7538,
29,
797,
304,
267,
641,
63,
912,
63,
5328,
63,
3058,
275,
641,
63,
912,
63,
5328,
63,
3058,
971,
288,
503,
291,
423,
885,
63,
265,
63,
912,
63,
5328,
267,
1613,
8,
6158,
2988,
12,
291,
2843,
826,
721,
288,
3231,
29,
3251,
12,
288,
1561,
1524,
354,
467,
288,
12677,
63,
265,
63,
912,
29,
15195,
63,
265,
63,
912,
12,
288,
12677,
63,
589,
29,
15195,
63,
589,
12,
288,
12677,
63,
10340,
29,
15195,
63,
10340,
12,
288,
641,
63,
912,
63,
5328,
63,
3058,
29,
265,
63,
912,
63,
5328,
63,
3058,
12,
288,
4911,
63,
7538,
29,
4712,
63,
7538,
12,
267,
776,
339,
768,
4639,
272,
347,
485,
885,
63,
265,
63,
912,
63,
5328,
8,
3090,
2609,
12,
5442,
12,
2329,
304,
267,
746,
339,
768,
3744,
272,
347,
1852,
63,
396,
63,
842,
8,
1886,
12,
3329,
12,
3231,
534,
2864,
1206,
297,
2574,
19843,
63,
1130,
63,
3924,
29,
797,
12,
2574,
641,
63,
912,
63,
5328,
63,
3058,
29,
403,
12,
2574,
4911,
63,
7538,
29,
797,
304,
267,
408,
11493,
282,
511,
19447,
2988,
398,
1379,
4454,
787,
3032,
282,
769,
402,
5478,
370,
1736,
687,
7830,
267,
2419,
8697,
3062,
687,
2397,
4501,
14,
398,
520,
635,
3329,
26,
5543,
13,
11786,
13282,
1256,
267,
520,
466,
3329,
26,
520,
533,
6054,
1597,
1354,
720,
14,
3435,
14,
6382,
64,
267,
520,
635,
3231,
26,
710,
3231,
367,
314,
5256,
27,
1202,
1454,
367,
288,
29193,
3967,
314,
5478,
787,
3032,
315,
14,
267,
520,
466,
3231,
26,
620,
267,
520,
635,
19843,
63,
1130,
63,
3924,
26,
9411,
30350,
3775,
4967,
288,
787,
25350,
1536,
4012,
314,
2341,
1240,
503,
3775,
2985,
787,
10367,
288,
436,
2066,
5525,
267,
520,
466,
19843,
63,
1130,
63,
3924,
26,
2155,
267,
520,
635,
641,
63,
912,
63,
5328,
63,
3058,
26,
17555,
805,
626,
911,
288,
506,
2797,
1380,
282,
2397,
1403,
883,
440,
506,
6511,
14,
710,
288,
2368,
626,
911,
506,
2741,
1380,
642,
365,
2797,
334,
6526,
288,
376,
2397,
1403,
6918,
370,
2248,
9,
787,
334,
2609,
12,
2397,
1403,
12,
288,
1919,
9,
267,
520,
466,
641,
63,
912,
63,
5328,
63,
3058,
26,
805,
267,
520,
635,
4911,
63,
7538,
26,
3645,
9116,
370,
15814,
314,
288,
5124,
402,
314,
3589,
8,
83,
9,
3769,
6511,
14,
7827,
370,
756,
14,
267,
520,
466,
4911,
63,
7538,
26,
2155,
267,
520,
1107,
26,
710,
5256,
1256,
12,
10038,
367,
5343,
398,
408,
398,
312,
275,
1613,
8,
6158,
2988,
12,
843,
680,
1875,
63,
396,
63,
842,
8,
288,
359,
3435,
467,
3231,
29,
3251,
12,
288,
19843,
63,
1130,
63,
3924,
29,
19432,
63,
1130,
63,
3924,
12,
288,
641,
63,
912,
63,
5328,
63,
3058,
29,
265,
63,
912,
63,
5328,
63,
3058,
12,
288,
4911,
63,
7538,
29,
4712,
63,
7538,
9,
267,
372,
312,
339,
347,
485,
826,
63,
5265,
8,
277,
12,
5478,
304,
267,
1613,
8,
6158,
2988,
12,
291,
10445,
826,
63,
5265,
8,
5359,
9,
398,
340,
440,
291,
14,
5359,
26,
288,
536,
275,
291,
423,
1247,
59,
16,
61,
288,
746,
3091,
12962,
360,
1944,
450,
82,
5253,
1911,
12,
10023,
367,
450,
82,
7,
450,
1169,
334,
277,
14,
3251,
12,
536,
430,
267,
340,
822,
8,
277,
14,
5359,
9,
690,
413,
26,
288,
24983,
63,
13337,
275,
12814,
904,
8,
69,
14,
2373,
63,
1403,
63,
1375,
5101,
367,
325,
315,
291,
14,
5359,
9,
953,
746,
14326,
12962,
360,
8433,
450,
82,
19016,
1911,
26,
450,
83,
7,
450,
3303,
334,
277,
14,
3251,
12,
24983,
63,
13337,
430,
339,
347,
636,
1250,
721,
277,
12,
2562,
12,
627,
589,
12,
1011,
10340,
304,
267,
408,
14883,
22652,
2562,
342,
367,
314,
2849,
6511,
3329,
14,
398,
710,
4955,
367,
2562,
342,
1077,
506,
447,
953,
347,
2562,
8,
832,
12,
627,
589,
12,
1011,
10340,
304,
355,
986,
398,
710,
1642,
1423,
370,
2562,
1062,
283,
832,
297,
365,
314,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
davidjb/sqlalchemy
|
test/ext/test_baked.py
|
17
|
23722
|
from sqlalchemy.orm import Session, subqueryload, \
mapper, relationship, lazyload, clear_mappers
from sqlalchemy.testing import eq_, is_, is_not_, assert_raises
from sqlalchemy import testing
from test.orm import _fixtures
from sqlalchemy.ext.baked import BakedQuery, baked_lazyload, BakedLazyLoader
from sqlalchemy.ext import baked
from sqlalchemy import bindparam, func
from sqlalchemy.orm import exc as orm_exc
import itertools
from sqlalchemy.testing import mock
class BakedTest(_fixtures.FixtureTest):
run_setup_mappers = 'once'
run_inserts = 'once'
run_deletes = None
def setup(self):
self.bakery = baked.bakery()
class StateChangeTest(BakedTest):
@classmethod
def setup_mappers(cls):
User = cls.classes.User
mapper(User, cls.tables.users)
def _assert_cache_key(self, key, elements):
eq_(
key,
tuple(elem.__code__ for elem in elements)
)
def test_initial_key(self):
User = self.classes.User
session = Session()
l1 = lambda: session.query(User)
q1 = self.bakery(l1)
self._assert_cache_key(
q1._cache_key,
[l1]
)
eq_(q1.steps, [l1])
def test_inplace_add(self):
User = self.classes.User
session = Session()
l1 = lambda: session.query(User)
l2 = lambda q: q.filter(User.name == bindparam('name'))
q1 = self.bakery(l1)
self._assert_cache_key(
q1._cache_key,
[l1]
)
eq_(q1.steps, [l1])
q2 = q1.add_criteria(l2)
is_(q2, q1)
self._assert_cache_key(
q1._cache_key,
[l1, l2]
)
eq_(q1.steps, [l1, l2])
def test_inplace_add_operator(self):
User = self.classes.User
session = Session()
l1 = lambda: session.query(User)
l2 = lambda q: q.filter(User.name == bindparam('name'))
q1 = self.bakery(l1)
self._assert_cache_key(
q1._cache_key,
[l1]
)
q1 += l2
self._assert_cache_key(
q1._cache_key,
[l1, l2]
)
def test_chained_add(self):
User = self.classes.User
session = Session()
l1 = lambda: session.query(User)
l2 = lambda q: q.filter(User.name == bindparam('name'))
q1 = self.bakery(l1)
q2 = q1.with_criteria(l2)
is_not_(q2, q1)
self._assert_cache_key(
q1._cache_key,
[l1]
)
self._assert_cache_key(
q2._cache_key,
[l1, l2]
)
def test_chained_add_operator(self):
User = self.classes.User
session = Session()
l1 = lambda: session.query(User)
l2 = lambda q: q.filter(User.name == bindparam('name'))
q1 = self.bakery(l1)
q2 = q1 + l2
is_not_(q2, q1)
self._assert_cache_key(
q1._cache_key,
[l1]
)
self._assert_cache_key(
q2._cache_key,
[l1, l2]
)
class LikeQueryTest(BakedTest):
@classmethod
def setup_mappers(cls):
User = cls.classes.User
mapper(User, cls.tables.users)
def test_first_no_result(self):
User = self.classes.User
bq = self.bakery(lambda s: s.query(User))
bq += lambda q: q.filter(User.name == 'asdf')
eq_(
bq(Session()).first(),
None
)
def test_first_multiple_result(self):
User = self.classes.User
bq = self.bakery(lambda s: s.query(User.id))
bq += lambda q: q.filter(User.name.like('%ed%')).order_by(User.id)
eq_(
bq(Session()).first(),
(8, )
)
def test_one_no_result(self):
User = self.classes.User
bq = self.bakery(lambda s: s.query(User))
bq += lambda q: q.filter(User.name == 'asdf')
assert_raises(
orm_exc.NoResultFound,
bq(Session()).one
)
def test_one_multiple_result(self):
User = self.classes.User
bq = self.bakery(lambda s: s.query(User))
bq += lambda q: q.filter(User.name.like('%ed%'))
assert_raises(
orm_exc.MultipleResultsFound,
bq(Session()).one
)
def test_get(self):
User = self.classes.User
bq = self.bakery(lambda s: s.query(User))
sess = Session()
def go():
u1 = bq(sess).get(7)
eq_(u1.name, 'jack')
self.assert_sql_count(testing.db, go, 1)
u1 = sess.query(User).get(7) # noqa
def go():
u2 = bq(sess).get(7)
eq_(u2.name, 'jack')
self.assert_sql_count(testing.db, go, 0)
def go():
u2 = bq(sess).get(8)
eq_(u2.name, 'ed')
self.assert_sql_count(testing.db, go, 1)
def test_get_pk_w_null(self):
"""test the re-implementation of logic to do get with IS NULL."""
class AddressUser(object):
pass
mapper(
AddressUser,
self.tables.users.outerjoin(self.tables.addresses),
properties={
"id": self.tables.users.c.id,
"address_id": self.tables.addresses.c.id
}
)
bq = self.bakery(lambda s: s.query(AddressUser))
sess = Session()
def go():
u1 = bq(sess).get((10, None))
eq_(u1.name, 'chuck')
self.assert_sql_count(testing.db, go, 1)
u1 = sess.query(AddressUser).get((10, None)) # noqa
def go():
u2 = bq(sess).get((10, None))
eq_(u2.name, 'chuck')
self.assert_sql_count(testing.db, go, 0)
class ResultTest(BakedTest):
__backend__ = True
@classmethod
def setup_mappers(cls):
User = cls.classes.User
Address = cls.classes.Address
mapper(User, cls.tables.users, properties={
"addresses": relationship(
Address, order_by=cls.tables.addresses.c.id)
})
mapper(Address, cls.tables.addresses)
def test_cachekeys_on_constructor(self):
User = self.classes.User
queue = [7, 8]
fn = lambda s: s.query(User.id).filter_by(id=queue.pop(0))
bq1 = self.bakery(fn, 7)
bq2 = self.bakery(fn, 8)
for i in range(3):
session = Session(autocommit=True)
eq_(
bq1(session).all(),
[(7,)]
)
eq_(
bq2(session).all(),
[(8,)]
)
def test_no_steps(self):
User = self.classes.User
bq = self.bakery(
lambda s: s.query(User.id, User.name).order_by(User.id))
for i in range(3):
session = Session(autocommit=True)
eq_(
bq(session).all(),
[(7, 'jack'), (8, 'ed'), (9, 'fred'), (10, 'chuck')]
)
def test_different_limits(self):
User = self.classes.User
bq = self.bakery(
lambda s: s.query(User.id, User.name).order_by(User.id))
bq += lambda q: q.limit(bindparam('limit')).offset(bindparam('offset'))
session = Session(autocommit=True)
for i in range(4):
for limit, offset, exp in [
(2, 1, [(8, 'ed'), (9, 'fred')]),
(3, 0, [(7, 'jack'), (8, 'ed'), (9, 'fred')]),
(1, 2, [(9, 'fred')])
]:
eq_(
bq(session).params(limit=limit, offset=offset).all(),
exp
)
def test_spoiled_full_w_params(self):
User = self.classes.User
canary = mock.Mock()
def fn1(s):
canary.fn1()
return s.query(User.id, User.name).order_by(User.id)
def fn2(q):
canary.fn2()
return q.filter(User.id == bindparam('id'))
def fn3(q):
canary.fn3()
return q
for x in range(3):
bq = self.bakery(fn1)
bq += fn2
sess = Session(autocommit=True)
eq_(
bq.spoil(full=True).add_criteria(fn3)(sess).params(id=7).all(),
[(7, 'jack')]
)
eq_(
canary.mock_calls,
[mock.call.fn1(), mock.call.fn2(), mock.call.fn3(),
mock.call.fn1(), mock.call.fn2(), mock.call.fn3(),
mock.call.fn1(), mock.call.fn2(), mock.call.fn3()]
)
def test_spoiled_half_w_params(self):
User = self.classes.User
canary = mock.Mock()
def fn1(s):
canary.fn1()
return s.query(User.id, User.name).order_by(User.id)
def fn2(q):
canary.fn2()
return q.filter(User.id == bindparam('id'))
def fn3(q):
canary.fn3()
return q
bq = self.bakery(fn1)
bq += fn2
for x in range(3):
bq = self.bakery(fn1)
bq += fn2
sess = Session(autocommit=True)
eq_(
bq.spoil().add_criteria(fn3)(sess).params(id=7).all(),
[(7, 'jack')]
)
eq_(
canary.mock_calls,
[mock.call.fn1(), mock.call.fn2(),
mock.call.fn3(), mock.call.fn3(), mock.call.fn3()]
)
def test_w_new_entities(self):
"""Test that the query can have its entities modified in
an arbitrary callable, and that this new entity list is preserved
when the query is invoked.
"""
User = self.classes.User
bq = self.bakery(
lambda s: s.query(User.id, User.name))
bq += lambda q: q.from_self().with_entities(
func.count(User.id))
for i in range(3):
session = Session(autocommit=True)
eq_(
bq(session).all(),
[(4, )]
)
def test_conditional_step(self):
"""Test a large series of conditionals and assert that
results remain correct between all of them within a series
of loops.
"""
User = self.classes.User
base_bq = self.bakery(
lambda s: s.query(User.id, User.name))
base_bq += lambda q: q.order_by(User.id)
for i in range(4):
for cond1, cond2, cond3, cond4 in itertools.product(
*[(False, True) for j in range(4)]):
bq = base_bq._clone()
if cond1:
bq += lambda q: q.filter(User.name != 'jack')
if cond2:
bq += lambda q: q.join(User.addresses)
else:
bq += lambda q: q.outerjoin(User.addresses)
elif cond3:
bq += lambda q: q.filter(User.name.like('%ed%'))
else:
bq += lambda q: q.filter(User.name == 'jack')
if cond4:
bq += lambda q: q.from_self().with_entities(
func.count(User.id))
sess = Session(autocommit=True)
result = bq(sess).all()
if cond4:
if cond1:
if cond2:
eq_(result, [(4,)])
else:
eq_(result, [(5,)])
elif cond3:
eq_(result, [(2,)])
else:
eq_(result, [(1,)])
else:
if cond1:
if cond2:
eq_(
result,
[(8, 'ed'), (8, 'ed'), (8, 'ed'),
(9, 'fred')]
)
else:
eq_(
result,
[(8, 'ed'), (8, 'ed'), (8, 'ed'),
(9, 'fred'), (10, 'chuck')]
)
elif cond3:
eq_(result, [(8, 'ed'), (9, 'fred')])
else:
eq_(result, [(7, 'jack')])
sess.close()
def test_conditional_step_oneline(self):
User = self.classes.User
base_bq = self.bakery(
lambda s: s.query(User.id, User.name))
base_bq += lambda q: q.order_by(User.id)
for i in range(4):
for cond1 in (False, True):
bq = base_bq._clone()
# we were using (filename, firstlineno) as cache key,
# which fails for this kind of thing!
bq += (lambda q: q.filter(User.name != 'jack')) if cond1 else (lambda q: q.filter(User.name == 'jack')) # noqa
sess = Session(autocommit=True)
result = bq(sess).all()
if cond1:
eq_(result, [(8, u'ed'), (9, u'fred'), (10, u'chuck')])
else:
eq_(result, [(7, 'jack')])
sess.close()
def test_subquery_eagerloading(self):
User = self.classes.User
Address = self.classes.Address
base_bq = self.bakery(
lambda s: s.query(User))
base_bq += lambda q: q.options(subqueryload(User.addresses))
base_bq += lambda q: q.order_by(User.id)
assert_result = [
User(id=7, addresses=[
Address(id=1, email_address='jack@bean.com')]),
User(id=8, addresses=[
Address(id=2, email_address='ed@wood.com'),
Address(id=3, email_address='ed@bettyboop.com'),
Address(id=4, email_address='ed@lala.com'),
]),
User(id=9, addresses=[
Address(id=5)
]),
User(id=10, addresses=[])
]
for i in range(4):
for cond1, cond2 in itertools.product(
*[(False, True) for j in range(2)]):
bq = base_bq._clone()
sess = Session()
if cond1:
bq += lambda q: q.filter(User.name == 'jack')
else:
bq += lambda q: q.filter(User.name.like('%ed%'))
if cond2:
ct = func.count(Address.id).label('count')
subq = sess.query(
ct,
Address.user_id).group_by(Address.user_id).\
having(ct > 2).subquery()
bq += lambda q: q.join(subq)
if cond2:
if cond1:
def go():
result = bq(sess).all()
eq_([], result)
self.assert_sql_count(testing.db, go, 1)
else:
def go():
result = bq(sess).all()
eq_(assert_result[1:2], result)
self.assert_sql_count(testing.db, go, 2)
else:
if cond1:
def go():
result = bq(sess).all()
eq_(assert_result[0:1], result)
self.assert_sql_count(testing.db, go, 2)
else:
def go():
result = bq(sess).all()
eq_(assert_result[1:3], result)
self.assert_sql_count(testing.db, go, 2)
sess.close()
class LazyLoaderTest(BakedTest):
run_setup_mappers = 'each'
def _o2m_fixture(self, lazy="select"):
User = self.classes.User
Address = self.classes.Address
mapper(User, self.tables.users, properties={
'addresses': relationship(
Address, order_by=self.tables.addresses.c.id,
lazy=lazy)
})
mapper(Address, self.tables.addresses)
return User, Address
def _m2o_fixture(self):
User = self.classes.User
Address = self.classes.Address
mapper(User, self.tables.users)
mapper(Address, self.tables.addresses, properties={
'user': relationship(User)
})
return User, Address
def test_strategy_lookup(self):
"""test that the lazy loader strategies aren't getting mixed up
with BakedLazyLoader as a subclass.
"""
User, Address = self._o2m_fixture()
ll = User.addresses.property._get_strategy((('lazy', 'select'),))
assert not isinstance(ll, BakedLazyLoader)
eq_(ll._strategy_keys, [(('lazy', 'select'),), (('lazy', True),)])
ll = User.addresses.property._get_strategy((('lazy', True),))
assert not isinstance(ll, BakedLazyLoader)
eq_(ll._strategy_keys, [(('lazy', 'select'),), (('lazy', True),)])
bl = User.addresses.property._get_strategy((('lazy', 'baked_select'),))
assert isinstance(bl, BakedLazyLoader)
eq_(bl._strategy_keys, [(('lazy', 'baked_select'),)])
def test_invocation_per_state(self):
"""test that BakedLazyLoader is getting invoked with the
baked_lazyload() loader.
"""
User, Address = self._o2m_fixture()
sess = Session()
q = sess.query(User)
with mock.patch.object(BakedLazyLoader, "_emit_lazyload") as el:
u1 = q.first()
u1.addresses
# not invoked
eq_(el.mock_calls, [])
sess = Session()
q = sess.query(User).options(baked_lazyload(User.addresses))
with mock.patch.object(BakedLazyLoader, "_emit_lazyload") as el:
u1 = q.first()
u1.addresses
# invoked
is_(
el.mock_calls[0][1][1],
u1._sa_instance_state
)
def test_invocation_per_mapper(self):
"""test that BakedLazyLoader is getting invoked with the
"baked_select" lazy setting.
"""
User, Address = self._o2m_fixture(lazy="baked_select")
sess = Session()
q = sess.query(User).options(lazyload(User.addresses))
with mock.patch.object(BakedLazyLoader, "_emit_lazyload") as el:
u1 = q.first()
u1.addresses
# not invoked
eq_(el.mock_calls, [])
sess = Session()
q = sess.query(User)
with mock.patch.object(BakedLazyLoader, "_emit_lazyload") as el:
u1 = q.first()
u1.addresses
# invoked
is_(
el.mock_calls[0][1][1],
u1._sa_instance_state
)
def test_invocation_systemwide_loaders(self):
baked.bake_lazy_loaders()
try:
User, Address = self._o2m_fixture()
sess = Session()
q = sess.query(User).options(lazyload(User.addresses))
with mock.patch.object(BakedLazyLoader, "_emit_lazyload") as el:
u1 = q.first()
u1.addresses
# invoked
is_(
el.mock_calls[0][1][1],
u1._sa_instance_state
)
finally:
baked.unbake_lazy_loaders()
clear_mappers()
User, Address = self._o2m_fixture()
sess = Session()
q = sess.query(User).options(lazyload(User.addresses))
with mock.patch.object(BakedLazyLoader, "_emit_lazyload") as el:
u1 = q.first()
u1.addresses
# not invoked
eq_(el.mock_calls, [])
def test_baked_lazy_loading_option_o2m(self):
User, Address = self._o2m_fixture()
self._test_baked_lazy_loading(set_option=True)
def test_baked_lazy_loading_mapped_o2m(self):
User, Address = self._o2m_fixture(lazy="baked_select")
self._test_baked_lazy_loading(set_option=False)
def _test_baked_lazy_loading(self, set_option):
User, Address = self.classes.User, self.classes.Address
base_bq = self.bakery(
lambda s: s.query(User))
if set_option:
base_bq += lambda q: q.options(baked_lazyload(User.addresses))
base_bq += lambda q: q.order_by(User.id)
assert_result = self.static.user_address_result
for i in range(4):
for cond1, cond2 in itertools.product(
*[(False, True) for j in range(2)]):
bq = base_bq._clone()
sess = Session()
if cond1:
bq += lambda q: q.filter(User.name == 'jack')
else:
bq += lambda q: q.filter(User.name.like('%ed%'))
if cond2:
ct = func.count(Address.id).label('count')
subq = sess.query(
ct,
Address.user_id).group_by(Address.user_id).\
having(ct > 2).subquery()
bq += lambda q: q.join(subq)
if cond2:
if cond1:
def go():
result = bq(sess).all()
eq_([], result)
self.assert_sql_count(testing.db, go, 1)
else:
def go():
result = bq(sess).all()
eq_(assert_result[1:2], result)
self.assert_sql_count(testing.db, go, 2)
else:
if cond1:
def go():
result = bq(sess).all()
eq_(assert_result[0:1], result)
self.assert_sql_count(testing.db, go, 2)
else:
def go():
result = bq(sess).all()
eq_(assert_result[1:3], result)
self.assert_sql_count(testing.db, go, 3)
sess.close()
def test_baked_lazy_loading_m2o(self):
User, Address = self._m2o_fixture()
base_bq = self.bakery(
lambda s: s.query(Address))
base_bq += lambda q: q.options(baked_lazyload(Address.user))
base_bq += lambda q: q.order_by(Address.id)
assert_result = self.static.address_user_result
for i in range(4):
for cond1 in (False, True):
bq = base_bq._clone()
sess = Session()
if cond1:
bq += lambda q: q.filter(
Address.email_address == 'jack@bean.com')
else:
bq += lambda q: q.filter(
Address.email_address.like('ed@%'))
if cond1:
def go():
result = bq(sess).all()
eq_(assert_result[0:1], result)
self.assert_sql_count(testing.db, go, 2)
else:
def go():
result = bq(sess).all()
eq_(assert_result[1:4], result)
self.assert_sql_count(testing.db, go, 2)
sess.close()
# additional tests:
# 1. m2m w lazyload
# 2. o2m lazyload where m2o backrefs have an eager load, test
# that eager load is canceled out
# 3. uselist = False, uselist=False assertion
|
mit
|
[
504,
8335,
14,
1025,
492,
8596,
12,
25935,
912,
12,
971,
272,
7796,
12,
8931,
12,
29667,
3125,
12,
5436,
63,
24469,
199,
504,
8335,
14,
4776,
492,
3850,
3131,
365,
3131,
365,
63,
1397,
3131,
702,
63,
3536,
199,
504,
8335,
492,
5343,
199,
504,
511,
14,
1025,
492,
485,
8769,
199,
504,
8335,
14,
832,
14,
66,
16702,
492,
699,
16702,
3227,
12,
330,
16702,
63,
416,
90,
3125,
12,
699,
16702,
14269,
5455,
199,
504,
8335,
14,
832,
492,
330,
16702,
199,
504,
8335,
492,
5398,
635,
12,
2562,
199,
504,
8335,
14,
1025,
492,
3178,
465,
9813,
63,
2804,
199,
646,
7975,
199,
504,
8335,
14,
4776,
492,
1683,
421,
199,
533,
699,
16702,
774,
1547,
8769,
14,
12812,
774,
304,
272,
1255,
63,
2758,
63,
24469,
275,
283,
5089,
7,
272,
1255,
63,
3176,
83,
275,
283,
5089,
7,
272,
1255,
63,
26289,
275,
488,
339,
347,
3272,
8,
277,
304,
267,
291,
14,
27162,
994,
275,
330,
16702,
14,
27162,
994,
342,
421,
199,
533,
8511,
4001,
774,
8,
34,
16702,
774,
304,
272,
768,
3744,
272,
347,
3272,
63,
24469,
8,
1886,
304,
267,
2876,
275,
843,
14,
2888,
14,
1899,
398,
7796,
8,
1899,
12,
843,
14,
5987,
14,
3707,
9,
339,
347,
485,
479,
63,
1637,
63,
498,
8,
277,
12,
790,
12,
4008,
304,
267,
3850,
2531,
288,
790,
12,
288,
2008,
8,
6086,
855,
600,
363,
367,
6193,
315,
4008,
9,
267,
776,
339,
347,
511,
63,
2747,
63,
498,
8,
277,
304,
267,
2876,
275,
291,
14,
2888,
14,
1899,
267,
2351,
275,
8596,
342,
267,
634,
17,
275,
2400,
26,
2351,
14,
1131,
8,
1899,
9,
267,
1894,
17,
275,
291,
14,
27162,
994,
8,
76,
17,
9,
267,
291,
423,
479,
63,
1637,
63,
498,
8,
288,
1894,
17,
423,
1637,
63,
498,
12,
288,
359,
76,
17,
61,
267,
776,
267,
3850,
2531,
81,
17,
14,
5895,
12,
359,
76,
17,
566,
339,
347,
511,
63,
15008,
63,
525,
8,
277,
304,
267,
2876,
275,
291,
14,
2888,
14,
1899,
267,
2351,
275,
8596,
342,
267,
634,
17,
275,
2400,
26,
2351,
14,
1131,
8,
1899,
9,
267,
634,
18,
275,
2400,
1894,
26,
1894,
14,
1541,
8,
1899,
14,
354,
508,
5398,
635,
360,
354,
1333,
267,
1894,
17,
275,
291,
14,
27162,
994,
8,
76,
17,
9,
267,
291,
423,
479,
63,
1637,
63,
498,
8,
288,
1894,
17,
423,
1637,
63,
498,
12,
288,
359,
76,
17,
61,
267,
776,
267,
3850,
2531,
81,
17,
14,
5895,
12,
359,
76,
17,
566,
398,
1894,
18,
275,
1894,
17,
14,
525,
63,
20525,
8,
76,
18,
9,
267,
365,
2531,
81,
18,
12,
1894,
17,
9,
398,
291,
423,
479,
63,
1637,
63,
498,
8,
288,
1894,
17,
423,
1637,
63,
498,
12,
288,
359,
76,
17,
12,
634,
18,
61,
267,
776,
267,
3850,
2531,
81,
17,
14,
5895,
12,
359,
76,
17,
12,
634,
18,
566,
339,
347,
511,
63,
15008,
63,
525,
63,
3856,
8,
277,
304,
267,
2876,
275,
291,
14,
2888,
14,
1899,
267,
2351,
275,
8596,
342,
267,
634,
17,
275,
2400,
26,
2351,
14,
1131,
8,
1899,
9,
267,
634,
18,
275,
2400,
1894,
26,
1894,
14,
1541,
8,
1899,
14,
354,
508,
5398,
635,
360,
354,
1333,
267,
1894,
17,
275,
291,
14,
27162,
994,
8,
76,
17,
9,
267,
291,
423,
479,
63,
1637,
63,
498,
8,
288,
1894,
17,
423,
1637,
63,
498,
12,
288,
359,
76,
17,
61,
267,
776,
398,
1894,
17,
847,
634,
18,
398,
291,
423,
479,
63,
1637,
63,
498,
8,
288,
1894,
17,
423,
1637,
63,
498,
12,
288,
359,
76,
17,
12,
634,
18,
61,
267,
776,
339,
347,
511,
63,
4429,
379,
63,
525,
8,
277,
304,
267,
2876,
275,
291,
14,
2888,
14,
1899,
267,
2351,
275,
8596,
342,
267,
634,
17,
275,
2400,
26,
2351,
14,
1131,
8,
1899,
9,
267,
634,
18,
275,
2400,
1894,
26,
1894,
14,
1541,
8,
1899,
14,
354,
508,
5398,
635,
360,
354,
1333,
267,
1894,
17,
275,
291,
14,
27162,
994,
8,
76,
17,
9,
398,
1894,
18,
275,
1894,
17,
14,
1045,
63,
20525,
8,
76,
18,
9,
267,
365,
63,
1397,
2531,
81,
18,
12,
1894,
17,
9,
398,
291,
423,
479,
63,
1637,
63,
498,
8,
288,
1894,
17,
423,
1637,
63,
498,
12,
288,
359,
76,
17,
61,
267,
776,
267,
291,
423,
479,
63,
1637,
63,
498,
8,
288,
1894,
18,
423,
1637,
63,
498,
12,
288,
359,
76,
17,
12,
634,
18,
61,
267,
776,
339,
347,
511,
63,
4429,
379,
63,
525,
63,
3856,
8,
277,
304,
267,
2876,
275,
291,
14,
2888,
14,
1899,
267,
2351,
275,
8596,
342,
267,
634,
17,
275,
2400,
26,
2351,
14,
1131,
8,
1899,
9,
267,
634,
18,
275,
2400,
1894,
26,
1894,
14,
1541,
8,
1899,
14,
354,
508,
5398,
635,
360,
354,
1333,
267,
1894,
17,
275,
291,
14,
27162,
994,
8,
76,
17,
9,
398,
1894,
18,
275,
1894,
17,
435,
634,
18,
267,
365,
63,
1397,
2531,
81,
18,
12,
1894,
17,
9,
398,
291,
423,
479,
63,
1637,
63,
498,
8,
288,
1894,
17,
423,
1637,
63,
498,
12,
288,
359,
76,
17,
61,
267,
776,
267,
291,
423,
479,
63,
1637,
63,
498,
8,
288,
1894,
18,
423,
1637,
63,
498,
12,
288,
359,
76,
17,
12,
634,
18,
61,
267,
776,
421,
199,
533,
16485,
3227,
774,
8,
34,
16702,
774,
304,
272,
768,
3744,
272,
347,
3272,
63,
24469,
8,
1886,
304,
267,
2876,
275,
843,
14,
2888,
14,
1899,
398,
7796,
8,
1899,
12,
843,
14,
5987,
14,
3707,
9,
339,
347,
511,
63,
2246,
63,
889,
63,
1099,
8,
277,
304,
267,
2876,
275,
291,
14,
2888,
14,
1899,
398,
330,
81,
275,
291,
14,
27162,
994,
8,
2734,
308,
26,
308,
14,
1131,
8,
1899,
430,
267,
330,
81,
847,
2400,
1894,
26,
1894,
14,
1541,
8,
1899,
14,
354,
508,
283,
18196,
358,
398,
3850,
2531,
288,
330,
81,
8,
4434,
8801,
2246,
1062,
288,
488,
267,
776,
339,
347,
511,
63,
2246,
63
] |
[
8335,
14,
1025,
492,
8596,
12,
25935,
912,
12,
971,
272,
7796,
12,
8931,
12,
29667,
3125,
12,
5436,
63,
24469,
199,
504,
8335,
14,
4776,
492,
3850,
3131,
365,
3131,
365,
63,
1397,
3131,
702,
63,
3536,
199,
504,
8335,
492,
5343,
199,
504,
511,
14,
1025,
492,
485,
8769,
199,
504,
8335,
14,
832,
14,
66,
16702,
492,
699,
16702,
3227,
12,
330,
16702,
63,
416,
90,
3125,
12,
699,
16702,
14269,
5455,
199,
504,
8335,
14,
832,
492,
330,
16702,
199,
504,
8335,
492,
5398,
635,
12,
2562,
199,
504,
8335,
14,
1025,
492,
3178,
465,
9813,
63,
2804,
199,
646,
7975,
199,
504,
8335,
14,
4776,
492,
1683,
421,
199,
533,
699,
16702,
774,
1547,
8769,
14,
12812,
774,
304,
272,
1255,
63,
2758,
63,
24469,
275,
283,
5089,
7,
272,
1255,
63,
3176,
83,
275,
283,
5089,
7,
272,
1255,
63,
26289,
275,
488,
339,
347,
3272,
8,
277,
304,
267,
291,
14,
27162,
994,
275,
330,
16702,
14,
27162,
994,
342,
421,
199,
533,
8511,
4001,
774,
8,
34,
16702,
774,
304,
272,
768,
3744,
272,
347,
3272,
63,
24469,
8,
1886,
304,
267,
2876,
275,
843,
14,
2888,
14,
1899,
398,
7796,
8,
1899,
12,
843,
14,
5987,
14,
3707,
9,
339,
347,
485,
479,
63,
1637,
63,
498,
8,
277,
12,
790,
12,
4008,
304,
267,
3850,
2531,
288,
790,
12,
288,
2008,
8,
6086,
855,
600,
363,
367,
6193,
315,
4008,
9,
267,
776,
339,
347,
511,
63,
2747,
63,
498,
8,
277,
304,
267,
2876,
275,
291,
14,
2888,
14,
1899,
267,
2351,
275,
8596,
342,
267,
634,
17,
275,
2400,
26,
2351,
14,
1131,
8,
1899,
9,
267,
1894,
17,
275,
291,
14,
27162,
994,
8,
76,
17,
9,
267,
291,
423,
479,
63,
1637,
63,
498,
8,
288,
1894,
17,
423,
1637,
63,
498,
12,
288,
359,
76,
17,
61,
267,
776,
267,
3850,
2531,
81,
17,
14,
5895,
12,
359,
76,
17,
566,
339,
347,
511,
63,
15008,
63,
525,
8,
277,
304,
267,
2876,
275,
291,
14,
2888,
14,
1899,
267,
2351,
275,
8596,
342,
267,
634,
17,
275,
2400,
26,
2351,
14,
1131,
8,
1899,
9,
267,
634,
18,
275,
2400,
1894,
26,
1894,
14,
1541,
8,
1899,
14,
354,
508,
5398,
635,
360,
354,
1333,
267,
1894,
17,
275,
291,
14,
27162,
994,
8,
76,
17,
9,
267,
291,
423,
479,
63,
1637,
63,
498,
8,
288,
1894,
17,
423,
1637,
63,
498,
12,
288,
359,
76,
17,
61,
267,
776,
267,
3850,
2531,
81,
17,
14,
5895,
12,
359,
76,
17,
566,
398,
1894,
18,
275,
1894,
17,
14,
525,
63,
20525,
8,
76,
18,
9,
267,
365,
2531,
81,
18,
12,
1894,
17,
9,
398,
291,
423,
479,
63,
1637,
63,
498,
8,
288,
1894,
17,
423,
1637,
63,
498,
12,
288,
359,
76,
17,
12,
634,
18,
61,
267,
776,
267,
3850,
2531,
81,
17,
14,
5895,
12,
359,
76,
17,
12,
634,
18,
566,
339,
347,
511,
63,
15008,
63,
525,
63,
3856,
8,
277,
304,
267,
2876,
275,
291,
14,
2888,
14,
1899,
267,
2351,
275,
8596,
342,
267,
634,
17,
275,
2400,
26,
2351,
14,
1131,
8,
1899,
9,
267,
634,
18,
275,
2400,
1894,
26,
1894,
14,
1541,
8,
1899,
14,
354,
508,
5398,
635,
360,
354,
1333,
267,
1894,
17,
275,
291,
14,
27162,
994,
8,
76,
17,
9,
267,
291,
423,
479,
63,
1637,
63,
498,
8,
288,
1894,
17,
423,
1637,
63,
498,
12,
288,
359,
76,
17,
61,
267,
776,
398,
1894,
17,
847,
634,
18,
398,
291,
423,
479,
63,
1637,
63,
498,
8,
288,
1894,
17,
423,
1637,
63,
498,
12,
288,
359,
76,
17,
12,
634,
18,
61,
267,
776,
339,
347,
511,
63,
4429,
379,
63,
525,
8,
277,
304,
267,
2876,
275,
291,
14,
2888,
14,
1899,
267,
2351,
275,
8596,
342,
267,
634,
17,
275,
2400,
26,
2351,
14,
1131,
8,
1899,
9,
267,
634,
18,
275,
2400,
1894,
26,
1894,
14,
1541,
8,
1899,
14,
354,
508,
5398,
635,
360,
354,
1333,
267,
1894,
17,
275,
291,
14,
27162,
994,
8,
76,
17,
9,
398,
1894,
18,
275,
1894,
17,
14,
1045,
63,
20525,
8,
76,
18,
9,
267,
365,
63,
1397,
2531,
81,
18,
12,
1894,
17,
9,
398,
291,
423,
479,
63,
1637,
63,
498,
8,
288,
1894,
17,
423,
1637,
63,
498,
12,
288,
359,
76,
17,
61,
267,
776,
267,
291,
423,
479,
63,
1637,
63,
498,
8,
288,
1894,
18,
423,
1637,
63,
498,
12,
288,
359,
76,
17,
12,
634,
18,
61,
267,
776,
339,
347,
511,
63,
4429,
379,
63,
525,
63,
3856,
8,
277,
304,
267,
2876,
275,
291,
14,
2888,
14,
1899,
267,
2351,
275,
8596,
342,
267,
634,
17,
275,
2400,
26,
2351,
14,
1131,
8,
1899,
9,
267,
634,
18,
275,
2400,
1894,
26,
1894,
14,
1541,
8,
1899,
14,
354,
508,
5398,
635,
360,
354,
1333,
267,
1894,
17,
275,
291,
14,
27162,
994,
8,
76,
17,
9,
398,
1894,
18,
275,
1894,
17,
435,
634,
18,
267,
365,
63,
1397,
2531,
81,
18,
12,
1894,
17,
9,
398,
291,
423,
479,
63,
1637,
63,
498,
8,
288,
1894,
17,
423,
1637,
63,
498,
12,
288,
359,
76,
17,
61,
267,
776,
267,
291,
423,
479,
63,
1637,
63,
498,
8,
288,
1894,
18,
423,
1637,
63,
498,
12,
288,
359,
76,
17,
12,
634,
18,
61,
267,
776,
421,
199,
533,
16485,
3227,
774,
8,
34,
16702,
774,
304,
272,
768,
3744,
272,
347,
3272,
63,
24469,
8,
1886,
304,
267,
2876,
275,
843,
14,
2888,
14,
1899,
398,
7796,
8,
1899,
12,
843,
14,
5987,
14,
3707,
9,
339,
347,
511,
63,
2246,
63,
889,
63,
1099,
8,
277,
304,
267,
2876,
275,
291,
14,
2888,
14,
1899,
398,
330,
81,
275,
291,
14,
27162,
994,
8,
2734,
308,
26,
308,
14,
1131,
8,
1899,
430,
267,
330,
81,
847,
2400,
1894,
26,
1894,
14,
1541,
8,
1899,
14,
354,
508,
283,
18196,
358,
398,
3850,
2531,
288,
330,
81,
8,
4434,
8801,
2246,
1062,
288,
488,
267,
776,
339,
347,
511,
63,
2246,
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,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Fusion-Rom/android_external_chromium_org
|
tools/telemetry/telemetry/value/histogram.py
|
35
|
4090
|
# 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.
import json
from telemetry import value as value_module
from telemetry import perf_tests_helper
from telemetry.value import histogram_util
class HistogramValueBucket(object):
def __init__(self, low, high, count=0):
self.low = low
self.high = high
self.count = count
def AsDict(self):
return {
'low': self.low,
'high': self.high,
'count': self.count
}
def ToJSONString(self):
return '{%s}' % ', '.join([
'"low": %i' % self.low,
'"high": %i' % self.high,
'"count": %i' % self.count])
class HistogramValue(value_module.Value):
def __init__(self, page, name, units,
raw_value=None, raw_value_json=None, important=True,
description=None):
super(HistogramValue, self).__init__(page, name, units, important,
description)
if raw_value_json:
assert raw_value == None, \
'Don\'t specify both raw_value and raw_value_json'
raw_value = json.loads(raw_value_json)
if raw_value:
assert 'buckets' in raw_value
assert isinstance(raw_value['buckets'], list)
self.buckets = []
for bucket in raw_value['buckets']:
self.buckets.append(HistogramValueBucket(
low=bucket['low'],
high=bucket['high'],
count=bucket['count']))
else:
self.buckets = []
def __repr__(self):
if self.page:
page_name = self.page.url
else:
page_name = None
return ('HistogramValue(%s, %s, %s, raw_json_string="%s", '
'important=%s, description=%s') % (
page_name,
self.name, self.units,
self.ToJSONString(),
self.important,
self.description)
def GetBuildbotDataType(self, output_context):
if self._IsImportantGivenOutputIntent(output_context):
return 'histogram'
return 'unimportant-histogram'
def GetBuildbotValue(self):
# More buildbot insanity: perf_tests_results_helper requires the histogram
# to be an array of size one.
return [self.ToJSONString()]
def ToJSONString(self):
# This has to hand-JSONify the histogram to ensure the order of keys
# produced is stable across different systems.
#
# This is done because the buildbot unittests are string equality
# assertions. Thus, tests that contain histograms require stable
# stringification of the histogram.
#
# Sigh, buildbot, Y U gotta be that way.
return '{"buckets": [%s]}' % (
', '.join([b.ToJSONString() for b in self.buckets]))
def GetRepresentativeNumber(self):
(mean, _) = perf_tests_helper.GeomMeanAndStdDevFromHistogram(
self.ToJSONString())
return mean
def GetRepresentativeString(self):
return self.GetBuildbotValue()
@staticmethod
def GetJSONTypeName():
return 'histogram'
def AsDict(self):
d = super(HistogramValue, self).AsDict()
d['buckets'] = [b.AsDict() for b in self.buckets]
return d
@staticmethod
def FromDict(value_dict, page_dict):
kwargs = value_module.Value.GetConstructorKwArgs(value_dict, page_dict)
kwargs['raw_value'] = value_dict
return HistogramValue(**kwargs)
@classmethod
def MergeLikeValuesFromSamePage(cls, values):
assert len(values) > 0
v0 = values[0]
return HistogramValue(
v0.page, v0.name, v0.units,
raw_value_json=histogram_util.AddHistograms(
[v.ToJSONString() for v in values]),
important=v0.important)
@classmethod
def MergeLikeValuesFromDifferentPages(cls, values,
group_by_name_suffix=False):
# Histograms cannot be merged across pages, at least for now. It should be
# theoretically possible, just requires more work. Instead, return None.
# This signals to the merging code that the data is unmergable and it will
# cope accordingly.
return None
|
bsd-3-clause
|
[
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,
646,
2022,
199,
199,
504,
17298,
492,
574,
465,
574,
63,
578,
199,
504,
17298,
492,
8582,
63,
2219,
63,
3676,
199,
504,
17298,
14,
585,
492,
15379,
63,
1974,
199,
199,
533,
869,
8543,
1110,
12311,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
6465,
12,
4721,
12,
2338,
29,
16,
304,
272,
291,
14,
674,
275,
6465,
272,
291,
14,
6260,
275,
4721,
272,
291,
14,
835,
275,
2338,
819,
347,
3709,
2141,
8,
277,
304,
272,
372,
469,
489,
283,
674,
356,
291,
14,
674,
12,
489,
283,
6260,
356,
291,
14,
6260,
12,
489,
283,
835,
356,
291,
14,
835,
272,
789,
819,
347,
4005,
6243,
1558,
8,
277,
304,
272,
372,
12100,
83,
6834,
450,
1656,
1987,
904,
779,
489,
5522,
674,
582,
450,
73,
7,
450,
291,
14,
674,
12,
489,
5522,
6260,
582,
450,
73,
7,
450,
291,
14,
6260,
12,
489,
5522,
835,
582,
450,
73,
7,
450,
291,
14,
835,
566,
199,
199,
533,
869,
8543,
1110,
8,
585,
63,
578,
14,
1110,
304,
523,
347,
636,
826,
721,
277,
12,
2034,
12,
536,
12,
6204,
12,
2049,
3066,
63,
585,
29,
403,
12,
3066,
63,
585,
63,
1001,
29,
403,
12,
11012,
29,
549,
12,
2049,
1369,
29,
403,
304,
272,
1613,
8,
25055,
1110,
12,
291,
2843,
826,
721,
1606,
12,
536,
12,
6204,
12,
11012,
12,
1460,
1369,
9,
272,
340,
3066,
63,
585,
63,
1001,
26,
489,
702,
3066,
63,
585,
508,
488,
12,
971,
1467,
283,
16932,
3985,
84,
4165,
3865,
3066,
63,
585,
436,
3066,
63,
585,
63,
1001,
7,
489,
3066,
63,
585,
275,
2022,
14,
3640,
8,
1773,
63,
585,
63,
1001,
9,
272,
340,
3066,
63,
585,
26,
489,
702,
283,
15065,
7,
315,
3066,
63,
585,
489,
702,
1228,
8,
1773,
63,
585,
459,
15065,
995,
769,
9,
489,
291,
14,
15065,
275,
942,
489,
367,
5315,
315,
3066,
63,
585,
459,
15065,
2565,
267,
291,
14,
15065,
14,
740,
8,
25055,
1110,
12311,
8,
881,
6465,
29,
4623,
459,
674,
995,
881,
4721,
29,
4623,
459,
6260,
995,
881,
2338,
29,
4623,
459,
835,
5156,
272,
587,
26,
489,
291,
14,
15065,
275,
942,
819,
347,
636,
2722,
721,
277,
304,
272,
340,
291,
14,
1606,
26,
489,
2034,
63,
354,
275,
291,
14,
1606,
14,
633,
272,
587,
26,
489,
2034,
63,
354,
275,
488,
272,
372,
661,
25055,
1110,
4042,
83,
12,
450,
83,
12,
450,
83,
12,
3066,
63,
1001,
63,
875,
5961,
83,
401,
283,
288,
283,
19559,
2458,
83,
12,
1369,
2458,
83,
358,
450,
334,
1598,
2034,
63,
354,
12,
1598,
291,
14,
354,
12,
291,
14,
5260,
12,
1598,
291,
14,
1378,
6243,
1558,
1062,
1598,
291,
14,
19559,
12,
1598,
291,
14,
1802,
9,
819,
347,
2372,
3425,
3018,
23516,
8,
277,
12,
1072,
63,
1100,
304,
272,
340,
291,
423,
1831,
6295,
867,
13735,
2959,
607,
767,
8,
1199,
63,
1100,
304,
489,
372,
283,
14805,
7,
272,
372,
283,
324,
19559,
13,
14805,
7,
819,
347,
2372,
3425,
3018,
1110,
8,
277,
304,
272,
327,
16917,
21306,
5261,
8945,
26,
8582,
63,
2219,
63,
2604,
63,
3676,
5074,
314,
15379,
272,
327,
370,
506,
376,
1625,
402,
1568,
1373,
14,
272,
372,
359,
277,
14,
1378,
6243,
1558,
5106,
819,
347,
4005,
6243,
1558,
8,
277,
304,
272,
327,
961,
965,
370,
4926,
13,
6243,
2021,
314,
15379,
370,
4868,
314,
1865,
402,
2883,
272,
327,
13584,
365,
17830,
9371,
3365,
10460,
14,
272,
327,
272,
327,
961,
365,
4224,
2952,
314,
21306,
2882,
83,
787,
1059,
16612,
272,
327,
22835,
14,
20227,
12,
2295,
626,
1395,
394,
22137,
4409,
17830,
272,
327,
1059,
7313,
402,
314,
15379,
14,
272,
327,
272,
327,
428,
2056,
12,
21306,
12,
1488,
738,
4788,
502,
506,
626,
4340,
14,
272,
372,
17137,
15065,
582,
8978,
83,
61,
6834,
450,
334,
489,
1656,
1987,
904,
779,
66,
14,
1378,
6243,
1558,
342,
367,
330,
315,
291,
14,
15065,
2459,
819,
347,
2372,
10755,
1905,
3259,
8,
277,
304,
272,
334,
3670,
12,
20795,
275,
8582,
63,
2219,
63,
3676,
14,
13427,
14825,
3325,
11976,
12680,
2532,
25055,
8,
267,
291,
14,
1378,
6243,
1558,
1012,
272,
372,
4615,
819,
347,
2372,
10755,
1905,
1558,
8,
277,
304,
272,
372,
291,
14,
1002,
3425,
3018,
1110,
342,
819,
768,
4639,
523,
347,
2372,
6243,
23059,
837,
272,
372,
283,
14805,
7,
819,
347,
3709,
2141,
8,
277,
304,
272,
366,
275,
1613,
8,
25055,
1110,
12,
291,
680,
2822,
2141,
342,
272,
366,
459,
15065,
418,
275,
359,
66,
14,
2822,
2141,
342,
367,
330,
315,
291,
14,
15065,
61,
272,
372,
366,
819,
768,
4639,
523,
347,
11606,
2141,
8,
585,
63,
807,
12,
2034,
63,
807,
304,
272,
2074,
275,
574,
63,
578,
14,
1110,
14,
1002,
11447,
26643,
6213,
8,
585,
63,
807,
12,
2034,
63,
807,
9,
272,
2074,
459,
1773,
63,
585,
418,
275,
574,
63,
807,
339,
372,
869,
8543,
1110,
3682,
958,
9,
819,
768,
3744,
523,
347,
14076,
12545,
6550,
2532,
8479,
3276,
8,
1886,
12,
1338,
304,
272,
702,
822,
8,
1459,
9,
690,
378,
272,
373,
16,
275,
1338,
59,
16,
61,
272,
372,
869,
8543,
1110,
8,
267,
373,
16,
14,
1606,
12,
373,
16,
14,
354,
12,
373,
16,
14,
5260,
12,
267,
3066,
63,
585,
63,
1001,
29,
14805,
63,
1974,
14,
1123,
40,
22137,
8,
288,
359,
86,
14,
1378,
6243,
1558,
342,
367,
373,
315,
1338,
2522,
267,
11012,
29,
86,
16,
14,
19559,
9,
819,
768,
3744,
523,
347,
14076,
12545,
6550,
2532,
31409,
17773,
8,
1886,
12,
1338,
12,
3147,
1572,
63,
991,
63,
354,
63,
4511,
29,
797,
304,
272,
327,
869,
22137,
3913,
506,
9545,
9371,
6497,
12,
737,
5210,
367,
3063,
14,
2779,
1077,
506,
272,
327,
314,
720,
17269,
3962,
12,
2951,
5074,
1655,
1736,
14,
15345,
12
] |
[
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,
646,
2022,
199,
199,
504,
17298,
492,
574,
465,
574,
63,
578,
199,
504,
17298,
492,
8582,
63,
2219,
63,
3676,
199,
504,
17298,
14,
585,
492,
15379,
63,
1974,
199,
199,
533,
869,
8543,
1110,
12311,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
6465,
12,
4721,
12,
2338,
29,
16,
304,
272,
291,
14,
674,
275,
6465,
272,
291,
14,
6260,
275,
4721,
272,
291,
14,
835,
275,
2338,
819,
347,
3709,
2141,
8,
277,
304,
272,
372,
469,
489,
283,
674,
356,
291,
14,
674,
12,
489,
283,
6260,
356,
291,
14,
6260,
12,
489,
283,
835,
356,
291,
14,
835,
272,
789,
819,
347,
4005,
6243,
1558,
8,
277,
304,
272,
372,
12100,
83,
6834,
450,
1656,
1987,
904,
779,
489,
5522,
674,
582,
450,
73,
7,
450,
291,
14,
674,
12,
489,
5522,
6260,
582,
450,
73,
7,
450,
291,
14,
6260,
12,
489,
5522,
835,
582,
450,
73,
7,
450,
291,
14,
835,
566,
199,
199,
533,
869,
8543,
1110,
8,
585,
63,
578,
14,
1110,
304,
523,
347,
636,
826,
721,
277,
12,
2034,
12,
536,
12,
6204,
12,
2049,
3066,
63,
585,
29,
403,
12,
3066,
63,
585,
63,
1001,
29,
403,
12,
11012,
29,
549,
12,
2049,
1369,
29,
403,
304,
272,
1613,
8,
25055,
1110,
12,
291,
2843,
826,
721,
1606,
12,
536,
12,
6204,
12,
11012,
12,
1460,
1369,
9,
272,
340,
3066,
63,
585,
63,
1001,
26,
489,
702,
3066,
63,
585,
508,
488,
12,
971,
1467,
283,
16932,
3985,
84,
4165,
3865,
3066,
63,
585,
436,
3066,
63,
585,
63,
1001,
7,
489,
3066,
63,
585,
275,
2022,
14,
3640,
8,
1773,
63,
585,
63,
1001,
9,
272,
340,
3066,
63,
585,
26,
489,
702,
283,
15065,
7,
315,
3066,
63,
585,
489,
702,
1228,
8,
1773,
63,
585,
459,
15065,
995,
769,
9,
489,
291,
14,
15065,
275,
942,
489,
367,
5315,
315,
3066,
63,
585,
459,
15065,
2565,
267,
291,
14,
15065,
14,
740,
8,
25055,
1110,
12311,
8,
881,
6465,
29,
4623,
459,
674,
995,
881,
4721,
29,
4623,
459,
6260,
995,
881,
2338,
29,
4623,
459,
835,
5156,
272,
587,
26,
489,
291,
14,
15065,
275,
942,
819,
347,
636,
2722,
721,
277,
304,
272,
340,
291,
14,
1606,
26,
489,
2034,
63,
354,
275,
291,
14,
1606,
14,
633,
272,
587,
26,
489,
2034,
63,
354,
275,
488,
272,
372,
661,
25055,
1110,
4042,
83,
12,
450,
83,
12,
450,
83,
12,
3066,
63,
1001,
63,
875,
5961,
83,
401,
283,
288,
283,
19559,
2458,
83,
12,
1369,
2458,
83,
358,
450,
334,
1598,
2034,
63,
354,
12,
1598,
291,
14,
354,
12,
291,
14,
5260,
12,
1598,
291,
14,
1378,
6243,
1558,
1062,
1598,
291,
14,
19559,
12,
1598,
291,
14,
1802,
9,
819,
347,
2372,
3425,
3018,
23516,
8,
277,
12,
1072,
63,
1100,
304,
272,
340,
291,
423,
1831,
6295,
867,
13735,
2959,
607,
767,
8,
1199,
63,
1100,
304,
489,
372,
283,
14805,
7,
272,
372,
283,
324,
19559,
13,
14805,
7,
819,
347,
2372,
3425,
3018,
1110,
8,
277,
304,
272,
327,
16917,
21306,
5261,
8945,
26,
8582,
63,
2219,
63,
2604,
63,
3676,
5074,
314,
15379,
272,
327,
370,
506,
376,
1625,
402,
1568,
1373,
14,
272,
372,
359,
277,
14,
1378,
6243,
1558,
5106,
819,
347,
4005,
6243,
1558,
8,
277,
304,
272,
327,
961,
965,
370,
4926,
13,
6243,
2021,
314,
15379,
370,
4868,
314,
1865,
402,
2883,
272,
327,
13584,
365,
17830,
9371,
3365,
10460,
14,
272,
327,
272,
327,
961,
365,
4224,
2952,
314,
21306,
2882,
83,
787,
1059,
16612,
272,
327,
22835,
14,
20227,
12,
2295,
626,
1395,
394,
22137,
4409,
17830,
272,
327,
1059,
7313,
402,
314,
15379,
14,
272,
327,
272,
327,
428,
2056,
12,
21306,
12,
1488,
738,
4788,
502,
506,
626,
4340,
14,
272,
372,
17137,
15065,
582,
8978,
83,
61,
6834,
450,
334,
489,
1656,
1987,
904,
779,
66,
14,
1378,
6243,
1558,
342,
367,
330,
315,
291,
14,
15065,
2459,
819,
347,
2372,
10755,
1905,
3259,
8,
277,
304,
272,
334,
3670,
12,
20795,
275,
8582,
63,
2219,
63,
3676,
14,
13427,
14825,
3325,
11976,
12680,
2532,
25055,
8,
267,
291,
14,
1378,
6243,
1558,
1012,
272,
372,
4615,
819,
347,
2372,
10755,
1905,
1558,
8,
277,
304,
272,
372,
291,
14,
1002,
3425,
3018,
1110,
342,
819,
768,
4639,
523,
347,
2372,
6243,
23059,
837,
272,
372,
283,
14805,
7,
819,
347,
3709,
2141,
8,
277,
304,
272,
366,
275,
1613,
8,
25055,
1110,
12,
291,
680,
2822,
2141,
342,
272,
366,
459,
15065,
418,
275,
359,
66,
14,
2822,
2141,
342,
367,
330,
315,
291,
14,
15065,
61,
272,
372,
366,
819,
768,
4639,
523,
347,
11606,
2141,
8,
585,
63,
807,
12,
2034,
63,
807,
304,
272,
2074,
275,
574,
63,
578,
14,
1110,
14,
1002,
11447,
26643,
6213,
8,
585,
63,
807,
12,
2034,
63,
807,
9,
272,
2074,
459,
1773,
63,
585,
418,
275,
574,
63,
807,
339,
372,
869,
8543,
1110,
3682,
958,
9,
819,
768,
3744,
523,
347,
14076,
12545,
6550,
2532,
8479,
3276,
8,
1886,
12,
1338,
304,
272,
702,
822,
8,
1459,
9,
690,
378,
272,
373,
16,
275,
1338,
59,
16,
61,
272,
372,
869,
8543,
1110,
8,
267,
373,
16,
14,
1606,
12,
373,
16,
14,
354,
12,
373,
16,
14,
5260,
12,
267,
3066,
63,
585,
63,
1001,
29,
14805,
63,
1974,
14,
1123,
40,
22137,
8,
288,
359,
86,
14,
1378,
6243,
1558,
342,
367,
373,
315,
1338,
2522,
267,
11012,
29,
86,
16,
14,
19559,
9,
819,
768,
3744,
523,
347,
14076,
12545,
6550,
2532,
31409,
17773,
8,
1886,
12,
1338,
12,
3147,
1572,
63,
991,
63,
354,
63,
4511,
29,
797,
304,
272,
327,
869,
22137,
3913,
506,
9545,
9371,
6497,
12,
737,
5210,
367,
3063,
14,
2779,
1077,
506,
272,
327,
314,
720,
17269,
3962,
12,
2951,
5074,
1655,
1736,
14,
15345,
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,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
jbaiter/beets
|
test/test_art.py
|
5
|
11519
|
# This file is part of beets.
# Copyright 2013, Adrian Sampson.
#
# 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.
"""Tests for the album art fetchers."""
import _common
from _common import unittest
from beetsplug import fetchart
from beets.autotag import AlbumInfo, AlbumMatch
from beets import library
from beets import importer
from beets import config
import os
import shutil
import StringIO
class MockHeaders(object):
def __init__(self, typeval):
self.typeval = typeval
def gettype(self):
return self.typeval
class MockUrlRetrieve(object):
def __init__(self, typeval, pathval='fetched_path'):
self.pathval = pathval
self.headers = MockHeaders(typeval)
self.fetched = None
def __call__(self, url, filename=None):
self.fetched = url
return filename or self.pathval, self.headers
class FetchImageTest(unittest.TestCase):
def test_invalid_type_returns_none(self):
fetchart.urllib.urlretrieve = MockUrlRetrieve('')
artpath = fetchart._fetch_image('http://example.com')
self.assertEqual(artpath, None)
def test_jpeg_type_returns_path(self):
fetchart.urllib.urlretrieve = MockUrlRetrieve('image/jpeg')
artpath = fetchart._fetch_image('http://example.com')
self.assertNotEqual(artpath, None)
class FSArtTest(_common.TestCase):
def setUp(self):
super(FSArtTest, self).setUp()
self.dpath = os.path.join(self.temp_dir, 'arttest')
os.mkdir(self.dpath)
def test_finds_jpg_in_directory(self):
_common.touch(os.path.join(self.dpath, 'a.jpg'))
fn = fetchart.art_in_path(self.dpath, ('art',), False)
self.assertEqual(fn, os.path.join(self.dpath, 'a.jpg'))
def test_appropriately_named_file_takes_precedence(self):
_common.touch(os.path.join(self.dpath, 'a.jpg'))
_common.touch(os.path.join(self.dpath, 'art.jpg'))
fn = fetchart.art_in_path(self.dpath, ('art',), False)
self.assertEqual(fn, os.path.join(self.dpath, 'art.jpg'))
def test_non_image_file_not_identified(self):
_common.touch(os.path.join(self.dpath, 'a.txt'))
fn = fetchart.art_in_path(self.dpath, ('art',), False)
self.assertEqual(fn, None)
def test_cautious_skips_fallback(self):
_common.touch(os.path.join(self.dpath, 'a.jpg'))
fn = fetchart.art_in_path(self.dpath, ('art',), True)
self.assertEqual(fn, None)
def test_empty_dir(self):
fn = fetchart.art_in_path(self.dpath, ('art',), True)
self.assertEqual(fn, None)
class CombinedTest(_common.TestCase):
def setUp(self):
super(CombinedTest, self).setUp()
self.dpath = os.path.join(self.temp_dir, 'arttest')
os.mkdir(self.dpath)
self.old_urlopen = fetchart.urllib.urlopen
fetchart.urllib.urlopen = self._urlopen
self.page_text = ""
self.urlopen_called = False
# Set up configuration.
fetchart.FetchArtPlugin()
def tearDown(self):
super(CombinedTest, self).tearDown()
fetchart.urllib.urlopen = self.old_urlopen
def _urlopen(self, url):
self.urlopen_called = True
self.fetched_url = url
return StringIO.StringIO(self.page_text)
def test_main_interface_returns_amazon_art(self):
fetchart.urllib.urlretrieve = MockUrlRetrieve('image/jpeg')
album = _common.Bag(asin='xxxx')
artpath = fetchart.art_for_album(album, None)
self.assertNotEqual(artpath, None)
def test_main_interface_returns_none_for_missing_asin_and_path(self):
album = _common.Bag()
artpath = fetchart.art_for_album(album, None)
self.assertEqual(artpath, None)
def test_main_interface_gives_precedence_to_fs_art(self):
_common.touch(os.path.join(self.dpath, 'art.jpg'))
fetchart.urllib.urlretrieve = MockUrlRetrieve('image/jpeg')
album = _common.Bag(asin='xxxx')
artpath = fetchart.art_for_album(album, [self.dpath])
self.assertEqual(artpath, os.path.join(self.dpath, 'art.jpg'))
def test_main_interface_falls_back_to_amazon(self):
fetchart.urllib.urlretrieve = MockUrlRetrieve('image/jpeg')
album = _common.Bag(asin='xxxx')
artpath = fetchart.art_for_album(album, [self.dpath])
self.assertNotEqual(artpath, None)
self.assertFalse(artpath.startswith(self.dpath))
def test_main_interface_tries_amazon_before_aao(self):
fetchart.urllib.urlretrieve = MockUrlRetrieve('image/jpeg')
album = _common.Bag(asin='xxxx')
fetchart.art_for_album(album, [self.dpath])
self.assertFalse(self.urlopen_called)
def test_main_interface_falls_back_to_aao(self):
fetchart.urllib.urlretrieve = MockUrlRetrieve('text/html')
album = _common.Bag(asin='xxxx')
fetchart.art_for_album(album, [self.dpath])
self.assertTrue(self.urlopen_called)
def test_main_interface_uses_caa_when_mbid_available(self):
mock_retrieve = MockUrlRetrieve('image/jpeg')
fetchart.urllib.urlretrieve = mock_retrieve
album = _common.Bag(mb_albumid='releaseid', asin='xxxx')
artpath = fetchart.art_for_album(album, None)
self.assertNotEqual(artpath, None)
self.assertTrue('coverartarchive.org' in mock_retrieve.fetched)
def test_local_only_does_not_access_network(self):
mock_retrieve = MockUrlRetrieve('image/jpeg')
fetchart.urllib.urlretrieve = mock_retrieve
album = _common.Bag(mb_albumid='releaseid', asin='xxxx')
artpath = fetchart.art_for_album(album, [self.dpath], local_only=True)
self.assertEqual(artpath, None)
self.assertFalse(self.urlopen_called)
self.assertFalse(mock_retrieve.fetched)
def test_local_only_gets_fs_image(self):
_common.touch(os.path.join(self.dpath, 'art.jpg'))
mock_retrieve = MockUrlRetrieve('image/jpeg')
fetchart.urllib.urlretrieve = mock_retrieve
album = _common.Bag(mb_albumid='releaseid', asin='xxxx')
artpath = fetchart.art_for_album(album, [self.dpath], None, local_only=True)
self.assertEqual(artpath, os.path.join(self.dpath, 'art.jpg'))
self.assertFalse(self.urlopen_called)
self.assertFalse(mock_retrieve.fetched)
class AAOTest(unittest.TestCase):
def setUp(self):
self.old_urlopen = fetchart.urllib.urlopen
fetchart.urllib.urlopen = self._urlopen
self.page_text = ''
def tearDown(self):
fetchart.urllib.urlopen = self.old_urlopen
def _urlopen(self, url):
return StringIO.StringIO(self.page_text)
def test_aao_scraper_finds_image(self):
self.page_text = """
<br />
<a href="TARGET_URL" title="View larger image" class="thickbox" style="color: #7E9DA2; text-decoration:none;">
<img src="http://www.albumart.org/images/zoom-icon.jpg" alt="View larger image" width="17" height="15" border="0"/></a>
"""
res = fetchart.aao_art('x')
self.assertEqual(res, 'TARGET_URL')
def test_aao_scraper_returns_none_when_no_image_present(self):
self.page_text = "blah blah"
res = fetchart.aao_art('x')
self.assertEqual(res, None)
class ArtImporterTest(_common.TestCase):
def setUp(self):
super(ArtImporterTest, self).setUp()
# Mock the album art fetcher to always return our test file.
self.art_file = os.path.join(self.temp_dir, 'tmpcover.jpg')
_common.touch(self.art_file)
self.old_afa = fetchart.art_for_album
self.afa_response = self.art_file
def art_for_album(i, p, maxwidth=None, local_only=False):
return self.afa_response
fetchart.art_for_album = art_for_album
# Test library.
self.libpath = os.path.join(self.temp_dir, 'tmplib.blb')
self.libdir = os.path.join(self.temp_dir, 'tmplib')
os.mkdir(self.libdir)
os.mkdir(os.path.join(self.libdir, 'album'))
itempath = os.path.join(self.libdir, 'album', 'test.mp3')
shutil.copyfile(os.path.join(_common.RSRC, 'full.mp3'), itempath)
self.lib = library.Library(self.libpath)
self.i = _common.item()
self.i.path = itempath
self.album = self.lib.add_album([self.i])
self.lib._connection().commit()
# The plugin and import configuration.
self.plugin = fetchart.FetchArtPlugin()
self.session = _common.import_session(self.lib)
# Import task for the coroutine.
self.task = importer.ImportTask(None, None, [self.i])
self.task.is_album = True
self.task.album_id = self.album.id
info = AlbumInfo(
album = 'some album',
album_id = 'albumid',
artist = 'some artist',
artist_id = 'artistid',
tracks = [],
)
self.task.set_choice(AlbumMatch(0, info, {}, set(), set()))
def tearDown(self):
super(ArtImporterTest, self).tearDown()
fetchart.art_for_album = self.old_afa
def _fetch_art(self, should_exist):
"""Execute the fetch_art coroutine for the task and return the
album's resulting artpath. ``should_exist`` specifies whether to
assert that art path was set (to the correct value) or or that
the path was not set.
"""
# Execute the two relevant parts of the importer.
self.plugin.fetch_art(self.session, self.task)
self.plugin.assign_art(self.session, self.task)
artpath = self.lib.albums()[0].artpath
if should_exist:
self.assertEqual(artpath,
os.path.join(os.path.dirname(self.i.path), 'cover.jpg'))
self.assertExists(artpath)
else:
self.assertEqual(artpath, None)
return artpath
def test_fetch_art(self):
assert not self.lib.albums()[0].artpath
self._fetch_art(True)
def test_art_not_found(self):
self.afa_response = None
self._fetch_art(False)
def test_no_art_for_singleton(self):
self.task.is_album = False
self._fetch_art(False)
def test_leave_original_file_in_place(self):
self._fetch_art(True)
self.assertExists(self.art_file)
def test_delete_original_file(self):
config['import']['delete'] = True
self._fetch_art(True)
self.assertNotExists(self.art_file)
def test_move_original_file(self):
config['import']['move'] = True
self._fetch_art(True)
self.assertNotExists(self.art_file)
def test_do_not_delete_original_if_already_in_place(self):
artdest = os.path.join(os.path.dirname(self.i.path), 'cover.jpg')
shutil.copyfile(self.art_file, artdest)
self.afa_response = artdest
self._fetch_art(True)
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)
if __name__ == '__main__':
unittest.main(defaultTest='suite')
|
mit
|
[
3,
961,
570,
365,
1777,
402,
506,
8716,
14,
199,
3,
1898,
6171,
12,
4431,
18429,
428,
5282,
834,
14,
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,
199,
3,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
624,
2925,
367,
314,
16379,
24701,
5267,
1192,
1041,
199,
199,
646,
485,
2330,
199,
504,
485,
2330,
492,
2882,
199,
504,
506,
386,
15276,
1518,
492,
5267,
580,
199,
504,
506,
8716,
14,
6898,
357,
643,
492,
4580,
7767,
2354,
12,
4580,
7767,
4486,
199,
504,
506,
8716,
492,
3555,
199,
504,
506,
8716,
492,
13479,
199,
504,
506,
8716,
492,
1101,
199,
646,
747,
199,
646,
5145,
199,
646,
5228,
199,
199,
533,
4420,
9883,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
730,
637,
304,
267,
291,
14,
466,
637,
275,
730,
637,
272,
347,
664,
466,
8,
277,
304,
267,
372,
291,
14,
466,
637,
199,
533,
4420,
6417,
15310,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
730,
637,
12,
931,
637,
534,
27236,
63,
515,
735,
267,
291,
14,
515,
637,
275,
931,
637,
267,
291,
14,
2139,
275,
4420,
9883,
8,
466,
637,
9,
267,
291,
14,
27236,
275,
488,
272,
347,
636,
1250,
721,
277,
12,
1166,
12,
1788,
29,
403,
304,
267,
291,
14,
27236,
275,
1166,
267,
372,
1788,
503,
291,
14,
515,
637,
12,
291,
14,
2139,
199,
199,
533,
16347,
3491,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
3197,
63,
466,
63,
5808,
63,
3592,
8,
277,
304,
267,
5267,
580,
14,
4078,
14,
633,
14270,
275,
4420,
6417,
15310,
8355,
267,
24701,
515,
275,
5267,
580,
423,
3535,
63,
1569,
360,
1014,
921,
2694,
14,
957,
358,
267,
291,
14,
629,
8,
580,
515,
12,
488,
9,
339,
347,
511,
63,
14230,
63,
466,
63,
5808,
63,
515,
8,
277,
304,
267,
5267,
580,
14,
4078,
14,
633,
14270,
275,
4420,
6417,
15310,
360,
1569,
15,
14230,
358,
267,
24701,
515,
275,
5267,
580,
423,
3535,
63,
1569,
360,
1014,
921,
2694,
14,
957,
358,
267,
291,
14,
7418,
8,
580,
515,
12,
488,
9,
199,
199,
533,
27500,
28922,
774,
1547,
2330,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
7079,
28922,
774,
12,
291,
680,
5996,
342,
267,
291,
14,
68,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
808,
63,
694,
12,
283,
580,
396,
358,
267,
747,
14,
8215,
8,
277,
14,
68,
515,
9,
339,
347,
511,
63,
1623,
83,
63,
8476,
63,
262,
63,
3619,
8,
277,
304,
267,
485,
2330,
14,
12376,
8,
736,
14,
515,
14,
904,
8,
277,
14,
68,
515,
12,
283,
65,
14,
8476,
1333,
267,
4325,
275,
5267,
580,
14,
580,
63,
262,
63,
515,
8,
277,
14,
68,
515,
12,
661,
580,
5529,
756,
9,
267,
291,
14,
629,
8,
2324,
12,
747,
14,
515,
14,
904,
8,
277,
14,
68,
515,
12,
283,
65,
14,
8476,
1333,
339,
347,
511,
63,
11227,
5655,
590,
63,
4579,
63,
493,
63,
31613,
63,
19571,
8,
277,
304,
267,
485,
2330,
14,
12376,
8,
736,
14,
515,
14,
904,
8,
277,
14,
68,
515,
12,
283,
65,
14,
8476,
1333,
267,
485,
2330,
14,
12376,
8,
736,
14,
515,
14,
904,
8,
277,
14,
68,
515,
12,
283,
580,
14,
8476,
1333,
267,
4325,
275,
5267,
580,
14,
580,
63,
262,
63,
515,
8,
277,
14,
68,
515,
12,
661,
580,
5529,
756,
9,
267,
291,
14,
629,
8,
2324,
12,
747,
14,
515,
14,
904,
8,
277,
14,
68,
515,
12,
283,
580,
14,
8476,
1333,
339,
347,
511,
63,
2865,
63,
1569,
63,
493,
63,
1397,
63,
9281,
8981,
8,
277,
304,
267,
485,
2330,
14,
12376,
8,
736,
14,
515,
14,
904,
8,
277,
14,
68,
515,
12,
283,
65,
14,
2424,
1333,
267,
4325,
275,
5267,
580,
14,
580,
63,
262,
63,
515,
8,
277,
14,
68,
515,
12,
661,
580,
5529,
756,
9,
267,
291,
14,
629,
8,
2324,
12,
488,
9,
339,
347,
511,
63,
696,
935,
1785,
63,
2759,
83,
63,
10538,
8,
277,
304,
267,
485,
2330,
14,
12376,
8,
736,
14,
515,
14,
904,
8,
277,
14,
68,
515,
12,
283,
65,
14,
8476,
1333,
267,
4325,
275,
5267,
580,
14,
580,
63,
262,
63,
515,
8,
277,
14,
68,
515,
12,
661,
580,
5529,
715,
9,
267,
291,
14,
629,
8,
2324,
12,
488,
9,
339,
347,
511,
63,
1667,
63,
694,
8,
277,
304,
267,
4325,
275,
5267,
580,
14,
580,
63,
262,
63,
515,
8,
277,
14,
68,
515,
12,
661,
580,
5529,
715,
9,
267,
291,
14,
629,
8,
2324,
12,
488,
9,
199,
199,
533,
22170,
379,
774,
1547,
2330,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
26444,
774,
12,
291,
680,
5996,
342,
398,
291,
14,
68,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
808,
63,
694,
12,
283,
580,
396,
358,
267,
747,
14,
8215,
8,
277,
14,
68,
515,
9,
267,
291,
14,
1753,
63,
10890,
275,
5267,
580,
14,
4078,
14,
10890,
267,
5267,
580,
14,
4078,
14,
10890,
275,
291,
423,
10890,
267,
291,
14,
1606,
63,
505,
275,
3087,
267,
291,
14,
10890,
63,
3527,
275,
756,
398,
327,
2494,
1536,
2897,
14,
267,
5267,
580,
14,
11135,
28922,
5061,
342,
339,
347,
6766,
8,
277,
304,
267,
1613,
8,
26444,
774,
12,
291,
680,
12336,
342,
267,
5267,
580
] |
[
961,
570,
365,
1777,
402,
506,
8716,
14,
199,
3,
1898,
6171,
12,
4431,
18429,
428,
5282,
834,
14,
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,
199,
3,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
624,
2925,
367,
314,
16379,
24701,
5267,
1192,
1041,
199,
199,
646,
485,
2330,
199,
504,
485,
2330,
492,
2882,
199,
504,
506,
386,
15276,
1518,
492,
5267,
580,
199,
504,
506,
8716,
14,
6898,
357,
643,
492,
4580,
7767,
2354,
12,
4580,
7767,
4486,
199,
504,
506,
8716,
492,
3555,
199,
504,
506,
8716,
492,
13479,
199,
504,
506,
8716,
492,
1101,
199,
646,
747,
199,
646,
5145,
199,
646,
5228,
199,
199,
533,
4420,
9883,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
730,
637,
304,
267,
291,
14,
466,
637,
275,
730,
637,
272,
347,
664,
466,
8,
277,
304,
267,
372,
291,
14,
466,
637,
199,
533,
4420,
6417,
15310,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
730,
637,
12,
931,
637,
534,
27236,
63,
515,
735,
267,
291,
14,
515,
637,
275,
931,
637,
267,
291,
14,
2139,
275,
4420,
9883,
8,
466,
637,
9,
267,
291,
14,
27236,
275,
488,
272,
347,
636,
1250,
721,
277,
12,
1166,
12,
1788,
29,
403,
304,
267,
291,
14,
27236,
275,
1166,
267,
372,
1788,
503,
291,
14,
515,
637,
12,
291,
14,
2139,
199,
199,
533,
16347,
3491,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
3197,
63,
466,
63,
5808,
63,
3592,
8,
277,
304,
267,
5267,
580,
14,
4078,
14,
633,
14270,
275,
4420,
6417,
15310,
8355,
267,
24701,
515,
275,
5267,
580,
423,
3535,
63,
1569,
360,
1014,
921,
2694,
14,
957,
358,
267,
291,
14,
629,
8,
580,
515,
12,
488,
9,
339,
347,
511,
63,
14230,
63,
466,
63,
5808,
63,
515,
8,
277,
304,
267,
5267,
580,
14,
4078,
14,
633,
14270,
275,
4420,
6417,
15310,
360,
1569,
15,
14230,
358,
267,
24701,
515,
275,
5267,
580,
423,
3535,
63,
1569,
360,
1014,
921,
2694,
14,
957,
358,
267,
291,
14,
7418,
8,
580,
515,
12,
488,
9,
199,
199,
533,
27500,
28922,
774,
1547,
2330,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
7079,
28922,
774,
12,
291,
680,
5996,
342,
267,
291,
14,
68,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
808,
63,
694,
12,
283,
580,
396,
358,
267,
747,
14,
8215,
8,
277,
14,
68,
515,
9,
339,
347,
511,
63,
1623,
83,
63,
8476,
63,
262,
63,
3619,
8,
277,
304,
267,
485,
2330,
14,
12376,
8,
736,
14,
515,
14,
904,
8,
277,
14,
68,
515,
12,
283,
65,
14,
8476,
1333,
267,
4325,
275,
5267,
580,
14,
580,
63,
262,
63,
515,
8,
277,
14,
68,
515,
12,
661,
580,
5529,
756,
9,
267,
291,
14,
629,
8,
2324,
12,
747,
14,
515,
14,
904,
8,
277,
14,
68,
515,
12,
283,
65,
14,
8476,
1333,
339,
347,
511,
63,
11227,
5655,
590,
63,
4579,
63,
493,
63,
31613,
63,
19571,
8,
277,
304,
267,
485,
2330,
14,
12376,
8,
736,
14,
515,
14,
904,
8,
277,
14,
68,
515,
12,
283,
65,
14,
8476,
1333,
267,
485,
2330,
14,
12376,
8,
736,
14,
515,
14,
904,
8,
277,
14,
68,
515,
12,
283,
580,
14,
8476,
1333,
267,
4325,
275,
5267,
580,
14,
580,
63,
262,
63,
515,
8,
277,
14,
68,
515,
12,
661,
580,
5529,
756,
9,
267,
291,
14,
629,
8,
2324,
12,
747,
14,
515,
14,
904,
8,
277,
14,
68,
515,
12,
283,
580,
14,
8476,
1333,
339,
347,
511,
63,
2865,
63,
1569,
63,
493,
63,
1397,
63,
9281,
8981,
8,
277,
304,
267,
485,
2330,
14,
12376,
8,
736,
14,
515,
14,
904,
8,
277,
14,
68,
515,
12,
283,
65,
14,
2424,
1333,
267,
4325,
275,
5267,
580,
14,
580,
63,
262,
63,
515,
8,
277,
14,
68,
515,
12,
661,
580,
5529,
756,
9,
267,
291,
14,
629,
8,
2324,
12,
488,
9,
339,
347,
511,
63,
696,
935,
1785,
63,
2759,
83,
63,
10538,
8,
277,
304,
267,
485,
2330,
14,
12376,
8,
736,
14,
515,
14,
904,
8,
277,
14,
68,
515,
12,
283,
65,
14,
8476,
1333,
267,
4325,
275,
5267,
580,
14,
580,
63,
262,
63,
515,
8,
277,
14,
68,
515,
12,
661,
580,
5529,
715,
9,
267,
291,
14,
629,
8,
2324,
12,
488,
9,
339,
347,
511,
63,
1667,
63,
694,
8,
277,
304,
267,
4325,
275,
5267,
580,
14,
580,
63,
262,
63,
515,
8,
277,
14,
68,
515,
12,
661,
580,
5529,
715,
9,
267,
291,
14,
629,
8,
2324,
12,
488,
9,
199,
199,
533,
22170,
379,
774,
1547,
2330,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
26444,
774,
12,
291,
680,
5996,
342,
398,
291,
14,
68,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
808,
63,
694,
12,
283,
580,
396,
358,
267,
747,
14,
8215,
8,
277,
14,
68,
515,
9,
267,
291,
14,
1753,
63,
10890,
275,
5267,
580,
14,
4078,
14,
10890,
267,
5267,
580,
14,
4078,
14,
10890,
275,
291,
423,
10890,
267,
291,
14,
1606,
63,
505,
275,
3087,
267,
291,
14,
10890,
63,
3527,
275,
756,
398,
327,
2494,
1536,
2897,
14,
267,
5267,
580,
14,
11135,
28922,
5061,
342,
339,
347,
6766,
8,
277,
304,
267,
1613,
8,
26444,
774,
12,
291,
680,
12336,
342,
267,
5267,
580,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Phdntom/NLCpyro
|
cluster.py
|
1
|
13290
|
from constants import *
from class_lib import *
import numpy as np
#from collections import deque
class Cluster:
def __init__(self,unit,num,links,file_ext):
self.nodes = []
self.edges = []
self.sites = []
self.bonds = []
if unit == "site":
self.nodes.append( Site(links) )
self.sites.append( (self.nodes[0].site[0],links) )
"""
tetra_map = []
tetra_map.append( (0,0) )
map_name = "tetra"+str(file_ext)
map_file = open(map_name,"w")
np.savez(map_file,tetra_map)
map_file.close()
"""
elif unit == "tetra":
"""
nodes: tetrahedrons embedded onto a diamond lattice
contains Tetra Objects
edges: undirected paths between nodes in the diamond lattice
contains 3tuples, (bond type, start node, end node)
sites: points in cluster on the pyrochlore lattice
conatins 2tuples, (site label, site type)
bonds: undirected paths between sites in the pyrochlore lattice
contains 2lists, [start site, end site]
"""
print "start cluster process"
tetra_map = []
#build num tetrahedrons
for n in range(num):
self.nodes.append( Tetra(n) )
#append the 1st one into the supercluster
# n = 0
for s in range(4):
self.sites.append( (self.nodes[0].site[s],self.nodes[0].site[s]) )
tetra_map.append( (s,s) )
for b in range(6):
self.bonds.append( self.nodes[0].bond[b] )
#append the remaining via the articulation list, links
for n in range(1,num):
shift = 3*n+1
maps = []
self.edges.append( (links[n-1][2],links[n-1][0],links[n-1][1]) )
for s in range(4):
if s != links[n-1][2]:
#finds the site of links, shifts the rest
maps.append( (self.nodes[n].site[s],shift) )
tetra_map.append( (self.nodes[n].site[s],shift) )
self.sites.append( (shift,self.nodes[n].site[s]) )
self.nodes[n].site[s] = shift
shift += 1
else:
maps.append( (self.nodes[n].site[s], self.nodes[ links[n-1][0] ].site[s] ) )
tetra_map.append( (self.nodes[n].site[s], self.nodes[ links[n-1][0] ].site[s] ) )
for b in range(6):
for s in range(4):
if self.nodes[n].bond[b][0] == maps[s][0]:
self.nodes[n].bond[b][0] = maps[s][1]
if self.nodes[n].bond[b][1] == maps[s][0]:
self.nodes[n].bond[b][1] = maps[s][1]
self.bonds.append(self.nodes[n].bond[b])
"""
print "map:"
print maps
"""
"""
map_name = "tetra"+str(file_ext)
map_file = open(map_name,"w")
np.savez(map_file,tetra_map)
map_file.close()
"""
"""
print "nodes"
for i in range(len(self.nodes)):
print self.nodes[i]
print
print "edges"
print self.edges
"""
print "tetra_map"
print tetra_map
#if it's a tetrahedron based cluster
else:
print 'Error'
#else it's an error
print "sites"
print self.sites
print "bonds"
print self.bonds
def BuildHamiltonian(self,h_field):
bond_count = len(self.bonds)
site_count = len(self.sites)
N = 2**site_count
H = np.zeros((N,N), dtype = complex)
for k in range(N):
for b in range(bond_count):
s = self.bonds[b][0]
t = self.bonds[b][1]
s_ty = self.sites[s][1]
t_ty = self.sites[t][1]
spin_s = (k >> s) & 1
spin_t = (k >> t) & 1
H[k,k] += .25 * Jzz * (2*spin_s-1) * (2*spin_t-1)
if spin_s ^ spin_t:
l = k + (spin_s - spin_t) * 2**t + (spin_t - spin_s) * 2**s
H[k,l] += -Jpm
if spin_s == 0 and spin_t == 0:
l = k + 2**s + 2**t
H[k,l] += Jpmpm * gamma[s_ty,t_ty]
if spin_s == 1 and spin_t == 1:
l = k - 2**s - 2**t
H[k,l] += Jpmpm * (-zeta[s_ty,t_ty])
if spin_t == 0:
l = k + 2**t
H[k,l] += .5 * (2*spin_s-1) * Jzpm * zeta[s_ty,t_ty]
if spin_t == 1:
l = k - 2**t
H[k,l] += .5 * (2*spin_s-1) * Jzpm * (-gamma[s_ty,t_ty])
if spin_s == 0:
l = k + 2**s
H[k,l] += .5 * (2*spin_t-1) * Jzpm * zeta[t_ty,s_ty]
if spin_s == 1:
l = k - 2**s
H[k,l] += .5 * (2*spin_t-1) * Jzpm * (-gamma[t_ty,s_ty])
### for b bonds
for s in range(site_count):
spin_s = (k >> s) & 1
s_ty = self.sites[s][1]
h = np.dot(R[s_ty],field_dir)
H[k,k] -= h_field*h[2]*gz*.5*(2*spin_s-1)
if spin_s == 0:
l = k + 2**s
H[k,l] -= h_field*.5*gxy*(h[0]-h[1]*1j)
elif spin_s == 1:
l = k - 2**s
H[k,l] -= h_field*.5*gxy*(h[0]+h[1]*1j)
### for s sites
### for k states
return H
def Diagonalize(self,code_ext,wf_switch):
field_list = [field_mag,field_mag+.0001]
eigen_list = []
N = 2**(len(self.sites))
for h_ext in field_list:
H = self.BuildHamiltonian(h_ext/h_meV)
#print "hamiltonian constructed."
#dir_str = str(field_dir[0])+str(field_dir[1])+str(field_dir[2])
if wf_switch == True :
eigen_w,eigen_v = np.linalg.eigh(H)
#print "diagonalization completed."
eigen_list.append( eigen_w )
if print_eigen_switch:
print eigen_w
print eigen_v
filename = "J_{0:.3f}_{1:.3f}_{2:.3f}_{3:.3f}_h_{4:.6f}_d_{5:}".format(Jzz,Jpm,Jpmpm,Jzpm,h_ext,dir_str)
eigen_out = open(filename+"_"+code_ext+"_eval","w")
eigenwf = open(filename+"_"+code_ext+"_wf","w")
np.savez(eigen_out,eigen_w)
np.savez(eigenwf,eigen_v)
eigenwf.close()
eigen_out.close()
##if print_eigen_switch == True
###if wf_switch == True
else: #wf_switch == False
eigen_w = np.linalg.eigvalsh(H)
#print "diagonalization completed."
#print eigen_w
eigen_list.append( eigen_w )
if print_eigen_switch:
print eigen_w
filename = "J_{0:.3f}_{1:.3f}_{2:.3f}_{3:.3f}_h_{4:.6f}_d_{5:}".format(Jzz,Jpm,Jpmpm,Jzpm,h_ext,dir_str)
eigen_out = open(filename+"_"+code_ext+"_eval","w")
np.savez(eigen_out,eigen_w)
eigen_out.close()
##if print_eigen_switch
###else wf_switch == False
###for h_ext
return eigen_list
def PropertyCSM(self,code,h1,eigen_w):
h2 = h1 + .0001
N = 2**len(self.sites)
"""
J = "J_{0:.3f}_{1:.3f}_{2:.3f}_{3:.3f}".format(Jzz,Jpm,Jpmpm,Jzpm)
print code
print h1
print h2
hstring1 = "_h_{0:.6f}".format(h1)
hstring2 = "_h_{0:.6f}".format(h2)
filename1 = J + hstring1 + "_d_" + dir_str + "_" + code+"_eval"
filename2 = J + hstring2 + "_d_" + dir_str + "_" + code+"_eval"
npzfile = np.load(filename1)
eigen1_w = npzfile['arr_0']
npzfile = np.load(filename2)
eigen2_w = npzfile['arr_0']
"""
#print eigen_w[0]
min_level1 = 0
min_level2 = 0
for E_j in eigen_w[0]:
if E_j.real < min_level1:
min_level1 = E_j.real
for E_j in eigen_w[1]:
if E_j.real < min_level2:
min_level2 = E_j.real
#print min_level
C = np.zeros( (T_POINTS), float)
S = np.zeros( (T_POINTS), float)
M = np.zeros( (T_POINTS), float)
for t in range(T_POINTS):
Z = 0
Z_up = 0
E = 0
E2 = 0
for j in range(N):
E_j = eigen_w[0][j].real - min_level1
if E_j / T[t] < 300:
Boltzmann = np.exp(-E_j / T[t])
Z += Boltzmann
E += E_j * Boltzmann
E2 += E_j * E_j * Boltzmann
E_j = eigen_w[1][j].real - min_level2
if E_j / T[t] < 300:
Boltzmann = np.exp(-E_j / T[t])
Z_up += Boltzmann
## for j
E /= Z
E2 /= Z
C[t] = (E2 - E*E) / (T[t] * T[t])
S[t] = E / T[t] + np.log(Z)
Z *= np.exp( -min_level1 / T[t])
Z_up *= np.exp( -min_level2 / T[t])
M[t] = -(-T[t]*np.log(Z_up) + T[t]*np.log(Z))/(h2-h1)
#Z *= np.exp( -min_level1 / T[t])
#Z_up *= np.exp( -min_level2 / T[t])
#M[t] = -(-T[t]*np.log(Z_up) + T[t]*np.log(Z))/dh
## for t
return [C,S,M]
def Weight(self,prop,code,W0,W1,W2,W3,C1,C2,C3,C4s,C4y):
#print code
#print sites
#print t1
#print t2
#print t3
#print t4s
#print t4y
WC = np.zeros( (T_POINTS), float)
WS = np.zeros( (T_POINTS), float)
WM = np.zeros( (T_POINTS), float)
W = [WC,WS,WM]
for p in range(3):
#print "begin sub"
if code in C1 :
for t in range(T_POINTS):
W[p][t] = prop[0][p][t]
for c in range(4):
W[p][t] -= W0[c][p][t]
## if 1 tetra
elif code in C2:
for c in range( len(C2) ):
if code == C2[c]:
index2 = c
#print "loop found this index"
#print index2
for t in range(T_POINTS):
W[p][t] = prop[index2][p][t]
W[p][t] -= 2*W0[0][p][t]
W[p][t] -= 2*W0[1][p][t]
W[p][t] -= 2*W0[2][p][t]
W[p][t] -= 2*W0[3][p][t]
W[p][t] += W0[index2][p][t]
W[p][t] -= 2*W1[0][p][t]
## if 2 tetra cluster
elif code in C3:
for c in range( len(C3) ):
if code == C3[c]:
index3 = c
#print index3
c1 = code[2]
c2 = code[3]
for c in range( len(C2) ):
if "t2"+c1 == C2[c]:
i1 = c
if "t2"+c2 == C2[c]:
i2 = c
for t in range(T_POINTS):
W[p][t] = prop[index3][p][t]
W[p][t] -= 3*W0[0][p][t]
W[p][t] -= 3*W0[1][p][t]
W[p][t] -= 3*W0[2][p][t]
W[p][t] -= 3*W0[3][p][t]
W[p][t] += W0[i1][p][t]
W[p][t] += W0[i2][p][t]
W[p][t] -= 3*W1[0][p][t]
W[p][t] -= W2[i1][p][t]
W[p][t] -= W2[i2][p][t]
## if 3 tetra
elif code in C4s:
for c in range( len(C4s) ):
if code == C4s[c]:
index4 = c
c1 = code[3]
c2 = code[4]
c3 = code[5]
for c in range( len(C2) ):
if "t2"+c1 == C2[c]:
i1 = c
if "t2"+c2 == C2[c]:
i2 = c
if "t2"+c3 == C2[c]:
i3 = c
"""
print c1
print c2
print c3
print i1
print i2
print i3
"""
#build string codes
if c1 < c2:
c10 = c1+c2
else:
c10 = c2+c1
if c2 < c3:
c20 = c2+c3
else:
c20 = c3+c2
#print c10
#print c20
for c in range( len(C3) ):
if "t3"+c10 == C3[c]:
j10 = c
if "t3"+c20 == C3[c]:
j20 = c
#print j10
#print j20
for t in range(T_POINTS):
W[p][t] = prop[index4][p][t]
W[p][t] -= 4*W0[0][p][t]
W[p][t] -= 4*W0[1][p][t]
W[p][t] -= 4*W0[2][p][t]
W[p][t] -= 4*W0[3][p][t]
W[p][t] += W0[i1][p][t]
W[p][t] += W0[i2][p][t]
W[p][t] += W0[i3][p][t]
W[p][t] -= 4*W1[0][p][t]
W[p][t] -= W2[i1][p][t]
W[p][t] -= W2[i2][p][t]
W[p][t] -= W2[i3][p][t]
W[p][t] -= W3[j10][p][t]
W[p][t] -= W3[j20][p][t]
## 4 tetrahedron string
elif code in C4y:
for c in range( len(C4y) ):
if code == C4y[c]:
index5 = c
c1 = code[3]
c2 = code[4]
c3 = code[5]
for c in range( len(C2) ):
if "t2"+c1 == C2[c]:
i1 = c
if "t2"+c2 == C2[c]:
i2 = c
if "t2"+c3 == C2[c]:
i3 = c
"""
print c1
print c2
print c3
print i1
print i2
print i3
"""
#build string codes
if c1 < c2:
c10 = c1+c2
else:
c10 = c2+c1
if c2 < c3:
c20 = c2+c3
else:
c20 = c3+c2
if c1 < c3:
c30 = c1+c3
else:
c30 = c3+c11
#contrast to t4s types which only have 2 three tetra subgraphs
#print c10
#print c20
#print c30
for c in range( len(C3) ):
if "t3"+c10 == C3[c]:
j10 = c
if "t3"+c20 == C3[c]:
j20 = c
if "t3"+c30 == C3[c]:
j30 = c
#print j10
#print j20
#print j30
for t in range(T_POINTS):
W[p][t] = prop[index5][p][t]
W[p][t] -= 4*W0[0][p][t]
W[p][t] -= 4*W0[1][p][t]
W[p][t] -= 4*W0[2][p][t]
W[p][t] -= 4*W0[3][p][t]
W[p][t] += W0[i1][p][t]
W[p][t] += W0[i2][p][t]
W[p][t] += W0[i3][p][t]
W[p][t] -= 4*W1[0][p][t]
W[p][t] -= W2[i1][p][t]
W[p][t] -= W2[i2][p][t]
W[p][t] -= W2[i3][p][t]
W[p][t] -= W3[j10][p][t]
W[p][t] -= W3[j20][p][t]
W[p][t] -= W3[j30][p][t]
## 4 tetrahedron y
return W
|
mit
|
[
199,
504,
5262,
492,
627,
199,
504,
1021,
63,
773,
492,
627,
199,
646,
2680,
465,
980,
199,
3,
504,
5055,
492,
15782,
199,
199,
533,
16454,
26,
819,
347,
636,
826,
721,
277,
12,
3248,
12,
1507,
12,
4614,
12,
493,
63,
832,
304,
272,
291,
14,
2415,
275,
942,
272,
291,
14,
6929,
275,
942,
272,
291,
14,
8619,
275,
942,
272,
291,
14,
27816,
275,
942,
339,
340,
4137,
508,
298,
2124,
582,
489,
291,
14,
2415,
14,
740,
8,
11666,
8,
4614,
9,
776,
489,
291,
14,
8619,
14,
740,
8,
334,
277,
14,
2415,
59,
16,
1055,
2124,
59,
16,
467,
4614,
9,
776,
489,
408,
489,
1565,
1239,
63,
1130,
275,
942,
489,
1565,
1239,
63,
1130,
14,
740,
8,
334,
16,
12,
16,
9,
776,
489,
2341,
63,
354,
275,
298,
266,
1239,
7709,
495,
8,
493,
63,
832,
9,
489,
2341,
63,
493,
275,
1551,
8,
1130,
63,
354,
4589,
87,
531,
489,
980,
14,
2117,
90,
8,
1130,
63,
493,
12,
266,
1239,
63,
1130,
9,
489,
2341,
63,
493,
14,
1600,
342,
489,
408,
339,
916,
4137,
508,
298,
266,
1239,
582,
489,
408,
267,
3380,
26,
1565,
1239,
19985,
2641,
83,
12169,
14602,
282,
487,
24940,
30952,
881,
3509,
377,
386,
345,
26794,
267,
8207,
26,
625,
12080,
3792,
3382,
3380,
315,
314,
487,
24940,
30952,
881,
3509,
650,
11760,
12,
334,
21410,
730,
12,
1343,
1031,
12,
1284,
1031,
9,
267,
15424,
26,
4501,
315,
4350,
641,
314,
1134,
293,
335,
28037,
30952,
881,
406,
292,
3617,
499,
11760,
12,
334,
2124,
1768,
12,
4770,
730,
9,
267,
23672,
795,
26,
625,
12080,
3792,
3382,
15424,
315,
314,
1134,
293,
335,
28037,
30952,
881,
3509,
499,
6717,
12,
359,
928,
4770,
12,
1284,
4770,
61,
489,
408,
489,
870,
298,
928,
4350,
2112,
2,
489,
1565,
1239,
63,
1130,
275,
942,
489,
327,
1506,
1967,
1565,
1239,
19985,
2641,
83,
489,
367,
302,
315,
1425,
8,
1507,
304,
267,
291,
14,
2415,
14,
740,
8,
377,
386,
345,
8,
78,
9,
776,
2541,
327,
740,
314,
413,
270,
1373,
1901,
314,
1613,
4201,
489,
327,
302,
275,
378,
489,
367,
308,
315,
1425,
8,
20,
304,
267,
291,
14,
8619,
14,
740,
8,
334,
277,
14,
2415,
59,
16,
1055,
2124,
59,
83,
467,
277,
14,
2415,
59,
16,
1055,
2124,
59,
83,
566,
776,
267,
1565,
1239,
63,
1130,
14,
740,
8,
334,
83,
12,
83,
9,
776,
489,
367,
330,
315,
1425,
8,
22,
304,
267,
291,
14,
27816,
14,
740,
8,
291,
14,
2415,
59,
16,
1055,
21410,
59,
66,
61,
776,
2541,
327,
740,
314,
7971,
4799,
314,
601,
764,
5332,
769,
12,
6220,
489,
367,
302,
315,
1425,
8,
17,
12,
1507,
304,
267,
7706,
275,
650,
10,
78,
11,
17,
267,
9033,
275,
942,
267,
291,
14,
6929,
14,
740,
8,
334,
4614,
59,
78,
13,
17,
1527,
18,
467,
4614,
59,
78,
13,
17,
1527,
16,
467,
4614,
59,
78,
13,
17,
1527,
17,
566,
776,
267,
367,
308,
315,
1425,
8,
20,
304,
881,
340,
308,
1137,
6220,
59,
78,
13,
17,
1527,
18,
2189,
288,
327,
1623,
83,
314,
4770,
402,
6220,
12,
20863,
1086,
314,
4618,
288,
9033,
14,
740,
8,
334,
277,
14,
2415,
59,
78,
1055,
2124,
59,
83,
467,
4723,
9,
776,
288,
1565,
1239,
63,
1130,
14,
740,
8,
334,
277,
14,
2415,
59,
78,
1055,
2124,
59,
83,
467,
4723,
9,
776,
953,
291,
14,
8619,
14,
740,
8,
334,
4723,
12,
277,
14,
2415,
59,
78,
1055,
2124,
59,
83,
566,
776,
288,
291,
14,
2415,
59,
78,
1055,
2124,
59,
83,
61,
275,
7706,
288,
7706,
847,
413,
881,
587,
26,
288,
9033,
14,
740,
8,
334,
277,
14,
2415,
59,
78,
1055,
2124,
59,
83,
467,
291,
14,
2415,
59,
6220,
59,
78,
13,
17,
1527,
16,
61,
221,
1055,
2124,
59,
83,
61,
776,
776,
288,
1565,
1239,
63,
1130,
14,
740,
8,
334,
277,
14,
2415,
59,
78,
1055,
2124,
59,
83,
467,
291,
14,
2415,
59,
6220,
59,
78,
13,
17,
1527,
16,
61,
221,
1055,
2124,
59,
83,
61,
776,
776,
267,
367,
330,
315,
1425,
8,
22,
304,
881,
367,
308,
315,
1425,
8,
20,
304,
288,
340,
291,
14,
2415,
59,
78,
1055,
21410,
59,
66,
1527,
16,
61,
508,
9033,
59,
83,
1527,
16,
2189,
1598,
291,
14,
2415,
59,
78,
1055,
21410,
59,
66,
1527,
16,
61,
275,
9033,
59,
83,
1527,
17,
61,
288,
340,
291,
14,
2415,
59,
78,
1055,
21410,
59,
66,
1527,
17,
61,
508,
9033,
59,
83,
1527,
16,
2189,
1598,
291,
14,
2415,
59,
78,
1055,
21410,
59,
66,
1527,
17,
61,
275,
9033,
59,
83,
1527,
17,
61,
881,
291,
14,
27816,
14,
740,
8,
277,
14,
2415,
59,
78,
1055,
21410,
59,
66,
566,
267,
408,
267,
870,
298,
1130,
5424,
267,
870,
9033,
267,
408,
489,
408,
489,
2341,
63,
354,
275,
298,
266,
1239,
7709,
495,
8,
493,
63,
832,
9,
489,
2341,
63,
493,
275,
1551,
8,
1130,
63,
354,
4589,
87,
531,
489,
980,
14,
2117,
90,
8,
1130,
63,
493,
12,
266,
1239,
63,
1130,
9,
489,
2341,
63,
493,
14,
1600,
342,
489,
408,
489,
408,
489,
870,
298,
2415,
2,
489,
367,
284,
315,
1425,
8,
552,
8,
277,
14,
2415,
2298,
267,
870,
291,
14,
2415,
59,
73,
61,
489,
870,
489,
870,
298,
6929,
2,
489,
870,
291,
14,
6929,
489,
408,
489,
870,
298,
266,
1239,
63,
1130,
2,
489,
870,
1565,
1239,
63,
1130,
339,
327,
692,
652,
1159,
282,
1565,
1239,
19985,
2641,
4079,
4350,
272,
587,
26,
489,
870,
283,
547,
7,
272,
327,
2836,
652,
1159,
376,
1125,
339,
870,
298,
8619,
2,
272,
870,
291,
14,
8619,
339,
870,
298,
27816,
2,
272,
870,
291,
14,
27816,
819,
347,
6516,
40,
455,
382,
1860,
5653,
8,
277,
12,
72,
63,
698,
304,
272,
23119,
63,
835,
275,
822,
8,
277,
14,
27816,
9,
272,
4770,
63,
835,
275,
822,
8,
277,
14,
8619,
9,
339,
653,
275,
499,
538,
2124,
63,
835,
272
] |
[
504,
5262,
492,
627,
199,
504,
1021,
63,
773,
492,
627,
199,
646,
2680,
465,
980,
199,
3,
504,
5055,
492,
15782,
199,
199,
533,
16454,
26,
819,
347,
636,
826,
721,
277,
12,
3248,
12,
1507,
12,
4614,
12,
493,
63,
832,
304,
272,
291,
14,
2415,
275,
942,
272,
291,
14,
6929,
275,
942,
272,
291,
14,
8619,
275,
942,
272,
291,
14,
27816,
275,
942,
339,
340,
4137,
508,
298,
2124,
582,
489,
291,
14,
2415,
14,
740,
8,
11666,
8,
4614,
9,
776,
489,
291,
14,
8619,
14,
740,
8,
334,
277,
14,
2415,
59,
16,
1055,
2124,
59,
16,
467,
4614,
9,
776,
489,
408,
489,
1565,
1239,
63,
1130,
275,
942,
489,
1565,
1239,
63,
1130,
14,
740,
8,
334,
16,
12,
16,
9,
776,
489,
2341,
63,
354,
275,
298,
266,
1239,
7709,
495,
8,
493,
63,
832,
9,
489,
2341,
63,
493,
275,
1551,
8,
1130,
63,
354,
4589,
87,
531,
489,
980,
14,
2117,
90,
8,
1130,
63,
493,
12,
266,
1239,
63,
1130,
9,
489,
2341,
63,
493,
14,
1600,
342,
489,
408,
339,
916,
4137,
508,
298,
266,
1239,
582,
489,
408,
267,
3380,
26,
1565,
1239,
19985,
2641,
83,
12169,
14602,
282,
487,
24940,
30952,
881,
3509,
377,
386,
345,
26794,
267,
8207,
26,
625,
12080,
3792,
3382,
3380,
315,
314,
487,
24940,
30952,
881,
3509,
650,
11760,
12,
334,
21410,
730,
12,
1343,
1031,
12,
1284,
1031,
9,
267,
15424,
26,
4501,
315,
4350,
641,
314,
1134,
293,
335,
28037,
30952,
881,
406,
292,
3617,
499,
11760,
12,
334,
2124,
1768,
12,
4770,
730,
9,
267,
23672,
795,
26,
625,
12080,
3792,
3382,
15424,
315,
314,
1134,
293,
335,
28037,
30952,
881,
3509,
499,
6717,
12,
359,
928,
4770,
12,
1284,
4770,
61,
489,
408,
489,
870,
298,
928,
4350,
2112,
2,
489,
1565,
1239,
63,
1130,
275,
942,
489,
327,
1506,
1967,
1565,
1239,
19985,
2641,
83,
489,
367,
302,
315,
1425,
8,
1507,
304,
267,
291,
14,
2415,
14,
740,
8,
377,
386,
345,
8,
78,
9,
776,
2541,
327,
740,
314,
413,
270,
1373,
1901,
314,
1613,
4201,
489,
327,
302,
275,
378,
489,
367,
308,
315,
1425,
8,
20,
304,
267,
291,
14,
8619,
14,
740,
8,
334,
277,
14,
2415,
59,
16,
1055,
2124,
59,
83,
467,
277,
14,
2415,
59,
16,
1055,
2124,
59,
83,
566,
776,
267,
1565,
1239,
63,
1130,
14,
740,
8,
334,
83,
12,
83,
9,
776,
489,
367,
330,
315,
1425,
8,
22,
304,
267,
291,
14,
27816,
14,
740,
8,
291,
14,
2415,
59,
16,
1055,
21410,
59,
66,
61,
776,
2541,
327,
740,
314,
7971,
4799,
314,
601,
764,
5332,
769,
12,
6220,
489,
367,
302,
315,
1425,
8,
17,
12,
1507,
304,
267,
7706,
275,
650,
10,
78,
11,
17,
267,
9033,
275,
942,
267,
291,
14,
6929,
14,
740,
8,
334,
4614,
59,
78,
13,
17,
1527,
18,
467,
4614,
59,
78,
13,
17,
1527,
16,
467,
4614,
59,
78,
13,
17,
1527,
17,
566,
776,
267,
367,
308,
315,
1425,
8,
20,
304,
881,
340,
308,
1137,
6220,
59,
78,
13,
17,
1527,
18,
2189,
288,
327,
1623,
83,
314,
4770,
402,
6220,
12,
20863,
1086,
314,
4618,
288,
9033,
14,
740,
8,
334,
277,
14,
2415,
59,
78,
1055,
2124,
59,
83,
467,
4723,
9,
776,
288,
1565,
1239,
63,
1130,
14,
740,
8,
334,
277,
14,
2415,
59,
78,
1055,
2124,
59,
83,
467,
4723,
9,
776,
953,
291,
14,
8619,
14,
740,
8,
334,
4723,
12,
277,
14,
2415,
59,
78,
1055,
2124,
59,
83,
566,
776,
288,
291,
14,
2415,
59,
78,
1055,
2124,
59,
83,
61,
275,
7706,
288,
7706,
847,
413,
881,
587,
26,
288,
9033,
14,
740,
8,
334,
277,
14,
2415,
59,
78,
1055,
2124,
59,
83,
467,
291,
14,
2415,
59,
6220,
59,
78,
13,
17,
1527,
16,
61,
221,
1055,
2124,
59,
83,
61,
776,
776,
288,
1565,
1239,
63,
1130,
14,
740,
8,
334,
277,
14,
2415,
59,
78,
1055,
2124,
59,
83,
467,
291,
14,
2415,
59,
6220,
59,
78,
13,
17,
1527,
16,
61,
221,
1055,
2124,
59,
83,
61,
776,
776,
267,
367,
330,
315,
1425,
8,
22,
304,
881,
367,
308,
315,
1425,
8,
20,
304,
288,
340,
291,
14,
2415,
59,
78,
1055,
21410,
59,
66,
1527,
16,
61,
508,
9033,
59,
83,
1527,
16,
2189,
1598,
291,
14,
2415,
59,
78,
1055,
21410,
59,
66,
1527,
16,
61,
275,
9033,
59,
83,
1527,
17,
61,
288,
340,
291,
14,
2415,
59,
78,
1055,
21410,
59,
66,
1527,
17,
61,
508,
9033,
59,
83,
1527,
16,
2189,
1598,
291,
14,
2415,
59,
78,
1055,
21410,
59,
66,
1527,
17,
61,
275,
9033,
59,
83,
1527,
17,
61,
881,
291,
14,
27816,
14,
740,
8,
277,
14,
2415,
59,
78,
1055,
21410,
59,
66,
566,
267,
408,
267,
870,
298,
1130,
5424,
267,
870,
9033,
267,
408,
489,
408,
489,
2341,
63,
354,
275,
298,
266,
1239,
7709,
495,
8,
493,
63,
832,
9,
489,
2341,
63,
493,
275,
1551,
8,
1130,
63,
354,
4589,
87,
531,
489,
980,
14,
2117,
90,
8,
1130,
63,
493,
12,
266,
1239,
63,
1130,
9,
489,
2341,
63,
493,
14,
1600,
342,
489,
408,
489,
408,
489,
870,
298,
2415,
2,
489,
367,
284,
315,
1425,
8,
552,
8,
277,
14,
2415,
2298,
267,
870,
291,
14,
2415,
59,
73,
61,
489,
870,
489,
870,
298,
6929,
2,
489,
870,
291,
14,
6929,
489,
408,
489,
870,
298,
266,
1239,
63,
1130,
2,
489,
870,
1565,
1239,
63,
1130,
339,
327,
692,
652,
1159,
282,
1565,
1239,
19985,
2641,
4079,
4350,
272,
587,
26,
489,
870,
283,
547,
7,
272,
327,
2836,
652,
1159,
376,
1125,
339,
870,
298,
8619,
2,
272,
870,
291,
14,
8619,
339,
870,
298,
27816,
2,
272,
870,
291,
14,
27816,
819,
347,
6516,
40,
455,
382,
1860,
5653,
8,
277,
12,
72,
63,
698,
304,
272,
23119,
63,
835,
275,
822,
8,
277,
14,
27816,
9,
272,
4770,
63,
835,
275,
822,
8,
277,
14,
8619,
9,
339,
653,
275,
499,
538,
2124,
63,
835,
272,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
defance/edx-platform
|
common/lib/capa/capa/util.py
|
47
|
7335
|
"""
Utility functions for capa.
"""
import bleach
from decimal import Decimal
from calc import evaluator
from cmath import isinf, isnan
import re
from lxml import etree
#-----------------------------------------------------------------------------
#
# Utility functions used in CAPA responsetypes
default_tolerance = '0.001%'
def compare_with_tolerance(student_complex, instructor_complex, tolerance=default_tolerance, relative_tolerance=False):
"""
Compare student_complex to instructor_complex with maximum tolerance tolerance.
- student_complex : student result (float complex number)
- instructor_complex : instructor result (float complex number)
- tolerance : float, or string (representing a float or a percentage)
- relative_tolerance: bool, to explicitly use passed tolerance as relative
Note: when a tolerance is a percentage (i.e. '10%'), it will compute that
percentage of the instructor result and yield a number.
If relative_tolerance is set to False, it will use that value and the
instructor result to define the bounds of valid student result:
instructor_complex = 10, tolerance = '10%' will give [9.0, 11.0].
If relative_tolerance is set to True, it will use that value and both
instructor result and student result to define the bounds of valid student
result:
instructor_complex = 10, student_complex = 20, tolerance = '10%' will give
[8.0, 12.0].
This is typically used internally to compare float, with a
default_tolerance = '0.001%'.
Default tolerance of 1e-3% is added to compare two floats for
near-equality (to handle machine representation errors).
Default tolerance is relative, as the acceptable difference between two
floats depends on the magnitude of the floats.
(http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/)
Examples:
In [183]: 0.000016 - 1.6*10**-5
Out[183]: -3.3881317890172014e-21
In [212]: 1.9e24 - 1.9*10**24
Out[212]: 268435456.0
"""
if isinstance(tolerance, str):
if tolerance == default_tolerance:
relative_tolerance = True
if tolerance.endswith('%'):
tolerance = evaluator(dict(), dict(), tolerance[:-1]) * 0.01
if not relative_tolerance:
tolerance = tolerance * abs(instructor_complex)
else:
tolerance = evaluator(dict(), dict(), tolerance)
if relative_tolerance:
tolerance = tolerance * max(abs(student_complex), abs(instructor_complex))
if isinf(student_complex) or isinf(instructor_complex):
# If an input is infinite, we can end up with `abs(student_complex-instructor_complex)` and
# `tolerance` both equal to infinity. Then, below we would have
# `inf <= inf` which is a fail. Instead, compare directly.
return student_complex == instructor_complex
# because student_complex and instructor_complex are not necessarily
# complex here, we enforce it here:
student_complex = complex(student_complex)
instructor_complex = complex(instructor_complex)
# if both the instructor and student input are real,
# compare them as Decimals to avoid rounding errors
if not (instructor_complex.imag or student_complex.imag):
# if either of these are not a number, short circuit and return False
if isnan(instructor_complex.real) or isnan(student_complex.real):
return False
student_decimal = Decimal(str(student_complex.real))
instructor_decimal = Decimal(str(instructor_complex.real))
tolerance_decimal = Decimal(str(tolerance))
return abs(student_decimal - instructor_decimal) <= tolerance_decimal
else:
# v1 and v2 are, in general, complex numbers:
# there are some notes about backward compatibility issue: see responsetypes.get_staff_ans()).
return abs(student_complex - instructor_complex) <= tolerance
def contextualize_text(text, context): # private
"""
Takes a string with variables. E.g. $a+$b.
Does a substitution of those variables from the context
"""
if not text:
return text
for key in sorted(context, lambda x, y: cmp(len(y), len(x))):
# TODO (vshnayder): This whole replacement thing is a big hack
# right now--context contains not just the vars defined in the
# program, but also e.g. a reference to the numpy module.
# Should be a separate dict of variables that should be
# replaced.
if '$' + key in text:
try:
s = str(context[key])
except UnicodeEncodeError:
s = context[key].encode('utf8', errors='ignore')
text = text.replace('$' + key, s)
return text
def convert_files_to_filenames(answers):
"""
Check for File objects in the dict of submitted answers,
convert File objects to their filename (string)
"""
new_answers = dict()
for answer_id in answers.keys():
answer = answers[answer_id]
# Files are stored as a list, even if one file
if is_list_of_files(answer):
new_answers[answer_id] = [f.name for f in answer]
else:
new_answers[answer_id] = answers[answer_id]
return new_answers
def is_list_of_files(files):
return isinstance(files, list) and all(is_file(f) for f in files)
def is_file(file_to_test):
"""
Duck typing to check if 'file_to_test' is a File object
"""
return all(hasattr(file_to_test, method) for method in ['read', 'name'])
def find_with_default(node, path, default):
"""
Look for a child of node using , and return its text if found.
Otherwise returns default.
Arguments:
node: lxml node
path: xpath search expression
default: value to return if nothing found
Returns:
node.find(path).text if the find succeeds, default otherwise.
"""
v = node.find(path)
if v is not None:
return v.text
else:
return default
def sanitize_html(html_code):
"""
Sanitize html_code for safe embed on LMS pages.
Used to sanitize XQueue responses from Matlab.
"""
attributes = bleach.ALLOWED_ATTRIBUTES.copy()
# Yuck! but bleach does not offer the option of passing in allowed_protocols,
# and matlab uses data urls for images
if u'data' not in bleach.BleachSanitizer.allowed_protocols:
bleach.BleachSanitizer.allowed_protocols.append(u'data')
attributes.update({
'*': ['class', 'style', 'id'],
'audio': ['controls', 'autobuffer', 'autoplay', 'src'],
'img': ['src', 'width', 'height', 'class']
})
output = bleach.clean(
html_code,
tags=bleach.ALLOWED_TAGS + ['div', 'p', 'audio', 'pre', 'img', 'span'],
styles=['white-space'],
attributes=attributes
)
return output
def get_inner_html_from_xpath(xpath_node):
"""
Returns inner html as string from xpath node.
"""
# returns string from xpath node
html = etree.tostring(xpath_node).strip()
# strips outer tag from html string
inner_html = re.sub('(?ms)<%s[^>]*>(.*)</%s>' % (xpath_node.tag, xpath_node.tag), '\\1', html)
return inner_html.strip()
|
agpl-3.0
|
[
624,
199,
17505,
3423,
367,
28068,
14,
199,
624,
199,
646,
29603,
1225,
199,
504,
6107,
492,
6345,
199,
199,
504,
12831,
492,
29207,
199,
504,
286,
3442,
492,
365,
4904,
12,
365,
4304,
199,
646,
295,
199,
504,
14490,
492,
7559,
199,
18045,
199,
3,
199,
3,
20511,
3423,
1202,
315,
445,
1282,
33,
1177,
1313,
199,
885,
63,
16312,
275,
283,
16,
14,
4587,
5,
7,
421,
199,
318,
6540,
63,
1045,
63,
16312,
8,
5500,
63,
5254,
12,
17724,
63,
5254,
12,
13464,
29,
885,
63,
16312,
12,
3847,
63,
16312,
29,
797,
304,
272,
408,
272,
18955,
6474,
63,
5254,
370,
17724,
63,
5254,
543,
5696,
13464,
13464,
14,
10813,
446,
6474,
63,
5254,
259,
520,
221,
6474,
754,
334,
1609,
6114,
1329,
9,
1362,
446,
17724,
63,
5254,
259,
520,
221,
17724,
754,
334,
1609,
6114,
1329,
9,
1362,
446,
13464,
257,
520,
221,
2069,
12,
503,
1059,
334,
13063,
316,
282,
2069,
503,
282,
16327,
9,
1362,
446,
3847,
63,
16312,
26,
2155,
12,
370,
7662,
675,
3032,
13464,
465,
3847,
10813,
3390,
26,
1380,
282,
13464,
365,
282,
16327,
334,
73,
14,
69,
14,
283,
709,
5,
659,
652,
911,
4526,
626,
1362,
16327,
402,
314,
17724,
754,
436,
1995,
282,
1329,
14,
10813,
982,
3847,
63,
16312,
365,
663,
370,
756,
12,
652,
911,
675,
626,
574,
436,
314,
1362,
17724,
754,
370,
5627,
314,
10461,
402,
1686,
6474,
754,
26,
1362,
17724,
63,
5254,
275,
1616,
12,
13464,
275,
283,
709,
5,
7,
911,
8120,
359,
25,
14,
16,
12,
4119,
14,
16,
1055,
10813,
982,
3847,
63,
16312,
365,
663,
370,
715,
12,
652,
911,
675,
626,
574,
436,
3865,
1362,
17724,
754,
436,
6474,
754,
370,
5627,
314,
10461,
402,
1686,
6474,
1362,
754,
26,
1362,
17724,
63,
5254,
275,
1616,
12,
6474,
63,
5254,
275,
3388,
12,
13464,
275,
283,
709,
5,
7,
911,
8120,
1362,
359,
24,
14,
16,
12,
3144,
14,
16,
1055,
1362,
961,
365,
13609,
1202,
14448,
370,
6540,
2069,
12,
543,
282,
1362,
849,
63,
16312,
275,
283,
16,
14,
4587,
5,
1370,
10813,
3758,
13464,
402,
413,
69,
13,
19,
5,
365,
3483,
370,
6540,
2877,
15657,
367,
1362,
17429,
13,
20982,
334,
475,
2429,
6844,
6025,
2552,
680,
1362,
3758,
13464,
365,
3847,
12,
465,
314,
14712,
8865,
3382,
2877,
1362,
15657,
8350,
641,
314,
22877,
402,
314,
15657,
14,
1362,
334,
1014,
921,
2355,
4371,
14,
1027,
2915,
14,
957,
15,
7409,
15,
996,
15,
821,
15,
863,
9332,
13,
7774,
13,
1403,
13,
10548,
13,
7409,
13,
69,
1671,
24793,
1362,
6058,
26,
267,
1010,
359,
12363,
2189,
378,
14,
993,
975,
446,
413,
14,
22,
10,
709,
25376,
21,
267,
6219,
59,
12363,
2189,
446,
19,
14,
11403,
969,
1196,
1407,
9570,
7280,
69,
13,
2025,
267,
1010,
359,
11722,
2189,
413,
14,
25,
69,
1194,
446,
413,
14,
25,
10,
709,
538,
1194,
267,
6219,
59,
11722,
2189,
7875,
1349,
1276,
11419,
14,
16,
272,
408,
272,
340,
1228,
8,
16312,
12,
620,
304,
267,
340,
13464,
508,
849,
63,
16312,
26,
288,
3847,
63,
16312,
275,
715,
267,
340,
13464,
14,
4130,
3508,
735,
288,
13464,
275,
29207,
8,
807,
1062,
1211,
1062,
13464,
4439,
17,
566,
627,
378,
14,
614,
288,
340,
440,
3847,
63,
16312,
26,
355,
13464,
275,
13464,
627,
2853,
8,
14891,
63,
5254,
9,
267,
587,
26,
288,
13464,
275,
29207,
8,
807,
1062,
1211,
1062,
13464,
9,
339,
340,
3847,
63,
16312,
26,
267,
13464,
275,
13464,
627,
1390,
8,
2101,
8,
5500,
63,
5254,
395,
2853,
8,
14891,
63,
5254,
430,
339,
340,
365,
4904,
8,
5500,
63,
5254,
9,
503,
365,
4904,
8,
14891,
63,
5254,
304,
267,
327,
982,
376,
1324,
365,
15258,
12,
781,
883,
1284,
1536,
543,
658,
2101,
8,
5500,
63,
5254,
13,
14891,
63,
5254,
12544,
436,
267,
327,
658,
16312,
64,
3865,
4472,
370,
23573,
14,
9442,
12,
5084,
781,
3955,
1172,
267,
327,
658,
4904,
2695,
10739,
64,
1314,
365,
282,
2449,
14,
15345,
12,
6540,
5370,
14,
267,
372,
6474,
63,
5254,
508,
17724,
63,
5254,
339,
327,
2952,
6474,
63,
5254,
436,
17724,
63,
5254,
787,
440,
20513,
272,
327,
6114,
2348,
12,
781,
15814,
652,
2348,
26,
272,
6474,
63,
5254,
275,
6114,
8,
5500,
63,
5254,
9,
272,
17724,
63,
5254,
275,
6114,
8,
14891,
63,
5254,
9,
339,
327,
340,
3865,
314,
17724,
436,
6474,
1324,
787,
3363,
12,
272,
327,
6540,
3062,
465,
6345,
83,
370,
5126,
18100,
2552,
272,
340,
440,
334,
14891,
63,
5254,
14,
14688,
503,
6474,
63,
5254,
14,
14688,
304,
267,
327,
340,
1902,
402,
3520,
787,
440,
282,
1329,
12,
3974,
20304,
436,
372,
756,
267,
340,
365,
4304,
8,
14891,
63,
5254,
14,
3093,
9,
503,
365,
4304,
8,
5500,
63,
5254,
14,
3093,
304,
288,
372,
756,
267,
6474,
63,
6355,
275,
6345,
8,
495,
8,
5500,
63,
5254,
14,
3093,
430,
267,
17724,
63,
6355,
275,
6345,
8,
495,
8,
14891,
63,
5254,
14,
3093,
430,
267,
13464,
63,
6355,
275,
6345,
8,
495,
8,
16312,
430,
267,
372,
2853,
8,
5500,
63,
6355,
446,
17724,
63,
6355,
9,
2695,
13464,
63,
6355,
339,
587,
26,
267,
327,
373,
17,
436,
373,
18,
787,
12,
315,
8605,
12,
6114,
5579,
26,
267,
327,
2337,
787,
2005,
12681,
3595,
13388,
7163,
4976,
26,
1937,
1177,
1313,
14,
362,
63,
7018,
63,
796,
8801,
267,
372,
2853,
8,
5500,
63,
5254,
446,
17724,
63,
5254,
9,
2695,
13464,
421,
199,
318,
1067,
1061,
794,
63,
505,
8,
505,
12,
1067,
304,
221,
327,
5726,
272,
408,
272,
17415,
282,
1059,
543,
2860,
14,
662,
14,
71,
14,
2672,
65,
11,
4,
66,
14,
272,
12078,
282,
20584,
402,
5204,
2860,
687,
314,
1067,
272,
408,
272,
340,
440,
1318,
26,
267,
372,
1318,
272,
367,
790,
315,
3355,
8,
1100,
12,
2400,
671,
12,
612,
26,
10467,
8,
552,
8,
89,
395,
822,
8,
88,
15206,
267,
327,
3254,
334,
86,
609,
78,
1187,
424,
304,
961,
8852,
8343,
8377,
365,
282,
7282,
11176,
267,
327,
2451,
3063,
306,
1100,
3509,
440
] |
[
199,
17505,
3423,
367,
28068,
14,
199,
624,
199,
646,
29603,
1225,
199,
504,
6107,
492,
6345,
199,
199,
504,
12831,
492,
29207,
199,
504,
286,
3442,
492,
365,
4904,
12,
365,
4304,
199,
646,
295,
199,
504,
14490,
492,
7559,
199,
18045,
199,
3,
199,
3,
20511,
3423,
1202,
315,
445,
1282,
33,
1177,
1313,
199,
885,
63,
16312,
275,
283,
16,
14,
4587,
5,
7,
421,
199,
318,
6540,
63,
1045,
63,
16312,
8,
5500,
63,
5254,
12,
17724,
63,
5254,
12,
13464,
29,
885,
63,
16312,
12,
3847,
63,
16312,
29,
797,
304,
272,
408,
272,
18955,
6474,
63,
5254,
370,
17724,
63,
5254,
543,
5696,
13464,
13464,
14,
10813,
446,
6474,
63,
5254,
259,
520,
221,
6474,
754,
334,
1609,
6114,
1329,
9,
1362,
446,
17724,
63,
5254,
259,
520,
221,
17724,
754,
334,
1609,
6114,
1329,
9,
1362,
446,
13464,
257,
520,
221,
2069,
12,
503,
1059,
334,
13063,
316,
282,
2069,
503,
282,
16327,
9,
1362,
446,
3847,
63,
16312,
26,
2155,
12,
370,
7662,
675,
3032,
13464,
465,
3847,
10813,
3390,
26,
1380,
282,
13464,
365,
282,
16327,
334,
73,
14,
69,
14,
283,
709,
5,
659,
652,
911,
4526,
626,
1362,
16327,
402,
314,
17724,
754,
436,
1995,
282,
1329,
14,
10813,
982,
3847,
63,
16312,
365,
663,
370,
756,
12,
652,
911,
675,
626,
574,
436,
314,
1362,
17724,
754,
370,
5627,
314,
10461,
402,
1686,
6474,
754,
26,
1362,
17724,
63,
5254,
275,
1616,
12,
13464,
275,
283,
709,
5,
7,
911,
8120,
359,
25,
14,
16,
12,
4119,
14,
16,
1055,
10813,
982,
3847,
63,
16312,
365,
663,
370,
715,
12,
652,
911,
675,
626,
574,
436,
3865,
1362,
17724,
754,
436,
6474,
754,
370,
5627,
314,
10461,
402,
1686,
6474,
1362,
754,
26,
1362,
17724,
63,
5254,
275,
1616,
12,
6474,
63,
5254,
275,
3388,
12,
13464,
275,
283,
709,
5,
7,
911,
8120,
1362,
359,
24,
14,
16,
12,
3144,
14,
16,
1055,
1362,
961,
365,
13609,
1202,
14448,
370,
6540,
2069,
12,
543,
282,
1362,
849,
63,
16312,
275,
283,
16,
14,
4587,
5,
1370,
10813,
3758,
13464,
402,
413,
69,
13,
19,
5,
365,
3483,
370,
6540,
2877,
15657,
367,
1362,
17429,
13,
20982,
334,
475,
2429,
6844,
6025,
2552,
680,
1362,
3758,
13464,
365,
3847,
12,
465,
314,
14712,
8865,
3382,
2877,
1362,
15657,
8350,
641,
314,
22877,
402,
314,
15657,
14,
1362,
334,
1014,
921,
2355,
4371,
14,
1027,
2915,
14,
957,
15,
7409,
15,
996,
15,
821,
15,
863,
9332,
13,
7774,
13,
1403,
13,
10548,
13,
7409,
13,
69,
1671,
24793,
1362,
6058,
26,
267,
1010,
359,
12363,
2189,
378,
14,
993,
975,
446,
413,
14,
22,
10,
709,
25376,
21,
267,
6219,
59,
12363,
2189,
446,
19,
14,
11403,
969,
1196,
1407,
9570,
7280,
69,
13,
2025,
267,
1010,
359,
11722,
2189,
413,
14,
25,
69,
1194,
446,
413,
14,
25,
10,
709,
538,
1194,
267,
6219,
59,
11722,
2189,
7875,
1349,
1276,
11419,
14,
16,
272,
408,
272,
340,
1228,
8,
16312,
12,
620,
304,
267,
340,
13464,
508,
849,
63,
16312,
26,
288,
3847,
63,
16312,
275,
715,
267,
340,
13464,
14,
4130,
3508,
735,
288,
13464,
275,
29207,
8,
807,
1062,
1211,
1062,
13464,
4439,
17,
566,
627,
378,
14,
614,
288,
340,
440,
3847,
63,
16312,
26,
355,
13464,
275,
13464,
627,
2853,
8,
14891,
63,
5254,
9,
267,
587,
26,
288,
13464,
275,
29207,
8,
807,
1062,
1211,
1062,
13464,
9,
339,
340,
3847,
63,
16312,
26,
267,
13464,
275,
13464,
627,
1390,
8,
2101,
8,
5500,
63,
5254,
395,
2853,
8,
14891,
63,
5254,
430,
339,
340,
365,
4904,
8,
5500,
63,
5254,
9,
503,
365,
4904,
8,
14891,
63,
5254,
304,
267,
327,
982,
376,
1324,
365,
15258,
12,
781,
883,
1284,
1536,
543,
658,
2101,
8,
5500,
63,
5254,
13,
14891,
63,
5254,
12544,
436,
267,
327,
658,
16312,
64,
3865,
4472,
370,
23573,
14,
9442,
12,
5084,
781,
3955,
1172,
267,
327,
658,
4904,
2695,
10739,
64,
1314,
365,
282,
2449,
14,
15345,
12,
6540,
5370,
14,
267,
372,
6474,
63,
5254,
508,
17724,
63,
5254,
339,
327,
2952,
6474,
63,
5254,
436,
17724,
63,
5254,
787,
440,
20513,
272,
327,
6114,
2348,
12,
781,
15814,
652,
2348,
26,
272,
6474,
63,
5254,
275,
6114,
8,
5500,
63,
5254,
9,
272,
17724,
63,
5254,
275,
6114,
8,
14891,
63,
5254,
9,
339,
327,
340,
3865,
314,
17724,
436,
6474,
1324,
787,
3363,
12,
272,
327,
6540,
3062,
465,
6345,
83,
370,
5126,
18100,
2552,
272,
340,
440,
334,
14891,
63,
5254,
14,
14688,
503,
6474,
63,
5254,
14,
14688,
304,
267,
327,
340,
1902,
402,
3520,
787,
440,
282,
1329,
12,
3974,
20304,
436,
372,
756,
267,
340,
365,
4304,
8,
14891,
63,
5254,
14,
3093,
9,
503,
365,
4304,
8,
5500,
63,
5254,
14,
3093,
304,
288,
372,
756,
267,
6474,
63,
6355,
275,
6345,
8,
495,
8,
5500,
63,
5254,
14,
3093,
430,
267,
17724,
63,
6355,
275,
6345,
8,
495,
8,
14891,
63,
5254,
14,
3093,
430,
267,
13464,
63,
6355,
275,
6345,
8,
495,
8,
16312,
430,
267,
372,
2853,
8,
5500,
63,
6355,
446,
17724,
63,
6355,
9,
2695,
13464,
63,
6355,
339,
587,
26,
267,
327,
373,
17,
436,
373,
18,
787,
12,
315,
8605,
12,
6114,
5579,
26,
267,
327,
2337,
787,
2005,
12681,
3595,
13388,
7163,
4976,
26,
1937,
1177,
1313,
14,
362,
63,
7018,
63,
796,
8801,
267,
372,
2853,
8,
5500,
63,
5254,
446,
17724,
63,
5254,
9,
2695,
13464,
421,
199,
318,
1067,
1061,
794,
63,
505,
8,
505,
12,
1067,
304,
221,
327,
5726,
272,
408,
272,
17415,
282,
1059,
543,
2860,
14,
662,
14,
71,
14,
2672,
65,
11,
4,
66,
14,
272,
12078,
282,
20584,
402,
5204,
2860,
687,
314,
1067,
272,
408,
272,
340,
440,
1318,
26,
267,
372,
1318,
272,
367,
790,
315,
3355,
8,
1100,
12,
2400,
671,
12,
612,
26,
10467,
8,
552,
8,
89,
395,
822,
8,
88,
15206,
267,
327,
3254,
334,
86,
609,
78,
1187,
424,
304,
961,
8852,
8343,
8377,
365,
282,
7282,
11176,
267,
327,
2451,
3063,
306,
1100,
3509,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ikassi/menpo
|
menpo/rasterize/opengl.py
|
2
|
10884
|
import numpy as np
from menpo.rasterize.copengl import COpenGLRasterizer
from menpo.image import MaskedImage
# noinspection PyProtectedMember
from menpo.rasterize.base import TextureRasterInfo
class GLRasterizer(object):
def __init__(self, width=1024, height=768, model_matrix=None,
view_matrix=None, projection_matrix=None):
r"""Offscreen OpenGL rasterize of fixed width and height.
Parameters
----------
width : int
The width of the rasterize target
height: int
The height of hte rasterize target
Notes
-----
For a given vertex v = (x, y, z, 1), it's position in image space
v' = (s, t) is calculated from
v' = P * V * M * v
where:
M is the model matrix
V is the view matrix (view the world from the position of the camera)
P is the projection matrix (usually an orthographic or perspective
matrix)
All matrices are 4x4 floats, as in OpenGL all points are treated as
homogeneous.
Note that this is the raw code written in the shader. The usual
pipeline of OpenGL applies - perspective division is performed to
form a clip space, and z-buffering is used to mask pixels
appropriately.
Texture information in the form of a texture map and normalized
per-vertex texture coordinates) are used to source colour values.
An arbitrary float 3-vector (f3v) can also be set on each vertex.
This value is passed through the same pipeline and interpolated but
note that the MATRICES ABOVE ARE NOT APPLIED TO THIS DATA.
This can be useful for example for passing through the shape
information of
the object into the rendered image domain. Note that because of the
above statement, the shape information rendered would be in the
objects original space, not in camera space (i.e. the z value will
not correlate to a depth buffer).
"""
self._opengl = COpenGLRasterizer(width, height)
if model_matrix is not None:
self.set_model_matrix(model_matrix)
if view_matrix is not None:
self.set_view_matrix(view_matrix)
if projection_matrix is not None:
self.set_projection_matrix(projection_matrix)
@property
def width(self):
return self._opengl.get_width()
@property
def height(self):
return self._opengl.get_height()
@property
def model_matrix(self):
return self._opengl.get_model_matrix()
@property
def view_matrix(self):
return self._opengl.get_view_matrix()
@property
def projection_matrix(self):
return self._opengl.get_projection_matrix()
def set_model_matrix(self, value):
value = _verify_opengl_homogeneous_matrix(value)
self._opengl.set_model_matrix(value)
def set_view_matrix(self, value):
value = _verify_opengl_homogeneous_matrix(value)
self._opengl.set_view_matrix(value)
def set_projection_matrix(self, value):
value = _verify_opengl_homogeneous_matrix(value)
self._opengl.set_projection_matrix(value)
def rasterize_mesh_with_f3v_interpolant(self, rasterizable,
per_vertex_f3v=None):
r"""Rasterize the object to an image and generate an interpolated
3-float image from a per vertex float 3 vector.
If no per_vertex_f3v is provided, the model's shape is used (making
this method equivalent to rasterize_mesh_with_shape_image)
Parameters
----------
rasterizable : object implementing the Rasterizable interface.
Will be queried for some state to rasterize via the Rasterizable
interface. Note that currently, color mesh rasterizations are
not supported.
per_vertex_f3v : optional, ndarray (n_points, 3)
A per-vertex 3 vector of floats that will be interpolated across
the image.
Returns
-------
rgb_image : 3 channel MaskedImage of shape (width, height)
The result of the rasterization. Mask is true iff the pixel was
rendered to by OpenGL.
interp_image: 3 channel MaskedImage of shape (width, height)
The result of interpolating the per_vertex_f3v across the
visible primitives.
"""
if rasterizable._rasterize_type_texture:
# request the textured info for rasterizing
r = rasterizable._rasterize_generate_textured_mesh()
return self._rasterize_texture_with_interp(
r, per_vertex_f3v=per_vertex_f3v)
elif rasterizable._rasterize_type_colour:
#TODO: This should use a different shader!
# But I'm hacking it here to work quickly.
colour_r = rasterizable._rasterize_generate_color_mesh()
# Fake some texture coordinates and a texture as required by the
# shader
fake_tcoords = np.random.randn(colour_r.points.shape[0], 2)
fake_texture = np.zeros([2, 2, 3])
r = TextureRasterInfo(colour_r.points, colour_r.trilist,
fake_tcoords, fake_texture)
# The RGB image is going to be broken due to the fake texture
# information we passed in
_, rgb_image = self._rasterize_texture_with_interp(
r, per_vertex_f3v=colour_r.colours)
_, f3v_image = self._rasterize_texture_with_interp(
r, per_vertex_f3v=per_vertex_f3v)
return rgb_image, f3v_image
def rasterize_mesh_with_shape_image(self, rasterizable):
r"""Rasterize the object to an image and generate an interpolated
3-float image from the shape information on the rasterizable object.
Parameters
----------
rasterizable : object implementing the Rasterizable interface.
Will be queried for some state to rasterize via the Rasterizable
interface. Note that currently, color mesh rasterizations are
not supported.
Returns
-------
rgb_image : 3 channel MaskedImage of shape (width, height)
The result of the rasterization. Mask is true iff the pixel was
rendered to by OpenGL.
shape_image: 3 channel MaskedImage of shape (width, height)
The result of interpolating the spatial information of each vertex
across the visible primitives. Note that the shape information
is *NOT* adjusted by the P,V,M matrices, and so the resulting
shape image is always in the original objects reference shape
(i.e. the z value will not necessarily correspond to a depth
buffer).
"""
return self.rasterize_mesh_with_f3v_interpolant(rasterizable)
def rasterize_mesh(self, rasterizable):
r"""Rasterize the object to an image and generate an interpolated
3-float image from the shape information on the rasterizable object.
Parameters
----------
rasterizable : object implementing the Rasterizable interface.
Will be queried for some state to rasterize via the Rasterizable
interface. Note that currently, color mesh rasterizations are
not supported.
Returns
-------
rgb_image : 3 channel MaskedImage of shape (width, height)
The result of the rasterization. Mask is true iff the pixel was
rendered to by OpenGL.
shape_image: 3 channel MaskedImage of shape (width, height)
The result of interpolating the spatial information of each vertex
across the visible primitives. Note that the shape information
is *NOT* adjusted by the P,V,M matrices, and so the resulting
shape image is always in the original objects reference shape
(i.e. the z value will not necessarily correspond to a depth
buffer).
"""
return self.rasterize_mesh_with_shape_image(rasterizable)[0]
def _rasterize_texture_with_interp(self, r, per_vertex_f3v=None):
r"""Rasterizes a textured mesh along with it's interpolant data
through OpenGL.
Parameters
----------
r : object
Any object with fields named 'points', 'trilist', 'texture' and
'tcoords' specifying the data that will be used to render. Such
objects are handed out by the
_rasterize_generate_textured_mesh method on Rasterizable
subclasses
per_vertex_f3v: ndarray, shape (n_points, 3)
A matrix specifying arbitrary 3 floating point numbers per
vertex. This data will be linearly interpolated across triangles
and returned in the f3v image. If none, the shape information is
used
Returns
-------
image : MaskedImage
The rasterized image returned from OpenGL. Note that the
behavior of the rasterization is governed by the projection,
rotation and view matrices that may be set on this class,
as well as the width and height of the rasterization, which is
determined on the creation of this class. The mask is True if a
triangle is visible at that pixel in the output, and False if not.
f3v_image : MaskedImage
The rasterized image returned from OpenGL. Note that the
behavior of the rasterization is governed by the projection,
rotation and view matrices that may be set on this class,
as well as the width and height of the rasterization, which is
determined on the creation of this class.
"""
points = np.require(r.points, dtype=np.float32, requirements='c')
trilist = np.require(r.trilist, dtype=np.uint32, requirements='c')
texture = np.require(r.texture, dtype=np.float32, requirements='c')
tcoords = np.require(r.tcoords, dtype=np.float32, requirements='c')
if per_vertex_f3v is None:
per_vertex_f3v = points
interp = np.require(per_vertex_f3v, dtype=np.float32, requirements='c')
rgb_fb, f3v_fb = self._opengl.render_offscreen_rgb(
points, interp, trilist, tcoords, texture)
mask_array = rgb_fb[..., 3].astype(np.bool)
return (MaskedImage(rgb_fb[..., :3].copy(), mask=mask_array),
MaskedImage(f3v_fb.copy(), mask=mask_array))
def _verify_opengl_homogeneous_matrix(matrix):
if matrix.shape != (4, 4):
raise ValueError("OpenGL matrices must have shape (4,4)")
return np.require(matrix, dtype=np.float32, requirements='C')
|
bsd-3-clause
|
[
646,
2680,
465,
980,
199,
504,
12953,
555,
14,
6360,
6236,
806,
14,
331,
897,
3528,
492,
445,
4299,
2226,
50,
305,
6236,
2282,
199,
504,
12953,
555,
14,
1569,
492,
17581,
379,
3491,
421,
199,
3,
30870,
1611,
919,
4530,
7021,
199,
504,
12953,
555,
14,
6360,
6236,
806,
14,
1095,
492,
4516,
608,
13284,
2354,
421,
199,
533,
3563,
50,
305,
6236,
2282,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
3462,
29,
7727,
12,
4569,
29,
14408,
12,
1402,
63,
3642,
29,
403,
12,
326,
2455,
63,
3642,
29,
403,
12,
14777,
63,
3642,
29,
403,
304,
267,
519,
624,
5195,
5410,
24374,
519,
305,
6236,
806,
402,
6317,
3462,
436,
4569,
14,
398,
3897,
267,
4143,
398,
3462,
520,
1109,
288,
710,
3462,
402,
314,
519,
305,
6236,
806,
1347,
398,
4569,
26,
1109,
288,
710,
4569,
402,
394,
266,
519,
305,
6236,
806,
1347,
7318,
8144,
267,
9063,
398,
2104,
282,
1627,
12759,
373,
275,
334,
88,
12,
612,
12,
1315,
12,
413,
395,
652,
1159,
3421,
315,
1834,
4601,
267,
373,
7,
275,
334,
83,
12,
307,
9,
365,
12950,
687,
398,
373,
7,
275,
510,
627,
812,
627,
603,
627,
373,
398,
2382,
26,
398,
603,
365,
314,
1402,
3634,
267,
812,
365,
314,
2455,
3634,
334,
1345,
314,
6701,
687,
314,
3421,
402,
314,
15177,
9,
267,
510,
365,
314,
14777,
3634,
334,
25118,
376,
19425,
79,
9770,
503,
1126,
16657,
267,
3634,
9,
398,
2900,
12627,
787,
841,
88,
20,
15657,
12,
465,
315,
24374,
1006,
4501,
787,
10184,
465,
267,
2636,
23748,
14,
398,
3390,
626,
642,
365,
314,
3066,
1233,
5313,
315,
314,
25958,
14,
710,
20195,
267,
7679,
402,
24374,
12966,
446,
1126,
16657,
4629,
365,
10585,
370,
267,
1824,
282,
11353,
4601,
12,
436,
1315,
13,
2738,
316,
365,
1202,
370,
3656,
11094,
267,
22497,
14,
398,
4516,
608,
2556,
315,
314,
1824,
402,
282,
14855,
2341,
436,
9657,
267,
1126,
13,
11417,
14855,
8983,
9,
787,
1202,
370,
1350,
15706,
1338,
14,
398,
1626,
9697,
2069,
650,
13,
4106,
334,
70,
19,
86,
9,
883,
2597,
506,
663,
641,
1924,
12759,
14,
267,
961,
574,
365,
3032,
4012,
314,
2011,
7679,
436,
23005,
972,
1325,
267,
5317,
626,
314,
603,
619,
50,
7040,
16054,
9315,
2845,
19525,
5177,
2296,
5749,
7126,
14,
398,
961,
883,
506,
2997,
367,
2893,
367,
9476,
4012,
314,
2215,
267,
2556,
402,
267,
314,
909,
1901,
314,
8018,
1834,
2881,
14,
3390,
626,
2952,
402,
314,
267,
3432,
5164,
12,
314,
2215,
2556,
8018,
3955,
506,
315,
314,
267,
2251,
3379,
4601,
12,
440,
315,
15177,
4601,
334,
73,
14,
69,
14,
314,
1315,
574,
911,
267,
440,
1970,
17322,
370,
282,
5818,
3335,
680,
398,
408,
267,
291,
423,
32477,
275,
445,
4299,
2226,
50,
305,
6236,
2282,
8,
2063,
12,
4569,
9,
267,
340,
1402,
63,
3642,
365,
440,
488,
26,
288,
291,
14,
409,
63,
1238,
63,
3642,
8,
1238,
63,
3642,
9,
267,
340,
2455,
63,
3642,
365,
440,
488,
26,
288,
291,
14,
409,
63,
1345,
63,
3642,
8,
1345,
63,
3642,
9,
267,
340,
14777,
63,
3642,
365,
440,
488,
26,
288,
291,
14,
409,
63,
16539,
63,
3642,
8,
16539,
63,
3642,
9,
339,
768,
1829,
272,
347,
3462,
8,
277,
304,
267,
372,
291,
423,
32477,
14,
362,
63,
2063,
342,
339,
768,
1829,
272,
347,
4569,
8,
277,
304,
267,
372,
291,
423,
32477,
14,
362,
63,
3333,
342,
339,
768,
1829,
272,
347,
1402,
63,
3642,
8,
277,
304,
267,
372,
291,
423,
32477,
14,
362,
63,
1238,
63,
3642,
342,
339,
768,
1829,
272,
347,
2455,
63,
3642,
8,
277,
304,
267,
372,
291,
423,
32477,
14,
362,
63,
1345,
63,
3642,
342,
339,
768,
1829,
272,
347,
14777,
63,
3642,
8,
277,
304,
267,
372,
291,
423,
32477,
14,
362,
63,
16539,
63,
3642,
342,
339,
347,
663,
63,
1238,
63,
3642,
8,
277,
12,
574,
304,
267,
574,
275,
485,
4712,
63,
32477,
63,
526,
23748,
63,
3642,
8,
585,
9,
267,
291,
423,
32477,
14,
409,
63,
1238,
63,
3642,
8,
585,
9,
339,
347,
663,
63,
1345,
63,
3642,
8,
277,
12,
574,
304,
267,
574,
275,
485,
4712,
63,
32477,
63,
526,
23748,
63,
3642,
8,
585,
9,
267,
291,
423,
32477,
14,
409,
63,
1345,
63,
3642,
8,
585,
9,
339,
347,
663,
63,
16539,
63,
3642,
8,
277,
12,
574,
304,
267,
574,
275,
485,
4712,
63,
32477,
63,
526,
23748,
63,
3642,
8,
585,
9,
267,
291,
423,
32477,
14,
409,
63,
16539,
63,
3642,
8,
585,
9,
339,
347,
519,
305,
6236,
806,
63,
6480,
63,
1045,
63,
70,
19,
86,
63,
29690,
867,
8,
277,
12,
519,
305,
6236,
90,
461,
12,
4490,
1126,
63,
11417,
63,
70,
19,
86,
29,
403,
304,
267,
519,
624,
50,
305,
6236,
806,
314,
909,
370,
376,
1834,
436,
3550,
376,
23005,
972,
267,
650,
13,
1609,
1834,
687,
282,
1126,
12759,
2069,
650,
5477,
14,
398,
982,
949,
1126,
63,
11417,
63,
70,
19,
86,
365,
2741,
12,
314,
1402,
1159,
2215,
365,
1202,
334,
391,
17443,
267,
642,
1083,
7353,
370,
519,
305,
6236,
806,
63,
6480,
63,
1045,
63,
1392,
63,
1569,
9,
398,
3897,
267,
4143,
267,
519,
305,
6236,
90,
461,
520,
909,
18234,
314,
820,
305,
6236,
90,
461,
3217,
14,
288,
12823,
506,
30081,
367,
2005,
1174,
370,
519,
305,
6236,
806,
4799,
314,
820,
305,
6236,
90,
461,
288,
3217,
14,
3390,
626,
5544,
12,
3164,
9364,
519,
305,
6236,
90,
1298,
787,
288,
440,
3748,
14,
398,
1126,
63,
11417,
63,
70,
19,
86,
520,
2716,
12,
6800,
334,
78,
63,
3438,
12,
650,
9,
288,
437,
1126,
13,
11417,
650,
5477,
402,
15657,
626,
911,
506,
23005,
972,
9371,
288,
314,
1834,
14,
7318,
1803,
267,
5514,
267,
15180,
63,
1569,
520,
650,
3623,
17581,
379,
3491,
402,
2215,
334,
2063,
12,
4569,
9,
288,
710,
754,
402,
314,
519,
305,
6236,
13362,
14,
17581,
365,
2549,
17963,
314,
7148,
1990,
288,
8018,
370,
701,
24374,
14,
398,
23716,
63,
1569,
26,
650,
3623,
17581
] |
[
2680,
465,
980,
199,
504,
12953,
555,
14,
6360,
6236,
806,
14,
331,
897,
3528,
492,
445,
4299,
2226,
50,
305,
6236,
2282,
199,
504,
12953,
555,
14,
1569,
492,
17581,
379,
3491,
421,
199,
3,
30870,
1611,
919,
4530,
7021,
199,
504,
12953,
555,
14,
6360,
6236,
806,
14,
1095,
492,
4516,
608,
13284,
2354,
421,
199,
533,
3563,
50,
305,
6236,
2282,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
3462,
29,
7727,
12,
4569,
29,
14408,
12,
1402,
63,
3642,
29,
403,
12,
326,
2455,
63,
3642,
29,
403,
12,
14777,
63,
3642,
29,
403,
304,
267,
519,
624,
5195,
5410,
24374,
519,
305,
6236,
806,
402,
6317,
3462,
436,
4569,
14,
398,
3897,
267,
4143,
398,
3462,
520,
1109,
288,
710,
3462,
402,
314,
519,
305,
6236,
806,
1347,
398,
4569,
26,
1109,
288,
710,
4569,
402,
394,
266,
519,
305,
6236,
806,
1347,
7318,
8144,
267,
9063,
398,
2104,
282,
1627,
12759,
373,
275,
334,
88,
12,
612,
12,
1315,
12,
413,
395,
652,
1159,
3421,
315,
1834,
4601,
267,
373,
7,
275,
334,
83,
12,
307,
9,
365,
12950,
687,
398,
373,
7,
275,
510,
627,
812,
627,
603,
627,
373,
398,
2382,
26,
398,
603,
365,
314,
1402,
3634,
267,
812,
365,
314,
2455,
3634,
334,
1345,
314,
6701,
687,
314,
3421,
402,
314,
15177,
9,
267,
510,
365,
314,
14777,
3634,
334,
25118,
376,
19425,
79,
9770,
503,
1126,
16657,
267,
3634,
9,
398,
2900,
12627,
787,
841,
88,
20,
15657,
12,
465,
315,
24374,
1006,
4501,
787,
10184,
465,
267,
2636,
23748,
14,
398,
3390,
626,
642,
365,
314,
3066,
1233,
5313,
315,
314,
25958,
14,
710,
20195,
267,
7679,
402,
24374,
12966,
446,
1126,
16657,
4629,
365,
10585,
370,
267,
1824,
282,
11353,
4601,
12,
436,
1315,
13,
2738,
316,
365,
1202,
370,
3656,
11094,
267,
22497,
14,
398,
4516,
608,
2556,
315,
314,
1824,
402,
282,
14855,
2341,
436,
9657,
267,
1126,
13,
11417,
14855,
8983,
9,
787,
1202,
370,
1350,
15706,
1338,
14,
398,
1626,
9697,
2069,
650,
13,
4106,
334,
70,
19,
86,
9,
883,
2597,
506,
663,
641,
1924,
12759,
14,
267,
961,
574,
365,
3032,
4012,
314,
2011,
7679,
436,
23005,
972,
1325,
267,
5317,
626,
314,
603,
619,
50,
7040,
16054,
9315,
2845,
19525,
5177,
2296,
5749,
7126,
14,
398,
961,
883,
506,
2997,
367,
2893,
367,
9476,
4012,
314,
2215,
267,
2556,
402,
267,
314,
909,
1901,
314,
8018,
1834,
2881,
14,
3390,
626,
2952,
402,
314,
267,
3432,
5164,
12,
314,
2215,
2556,
8018,
3955,
506,
315,
314,
267,
2251,
3379,
4601,
12,
440,
315,
15177,
4601,
334,
73,
14,
69,
14,
314,
1315,
574,
911,
267,
440,
1970,
17322,
370,
282,
5818,
3335,
680,
398,
408,
267,
291,
423,
32477,
275,
445,
4299,
2226,
50,
305,
6236,
2282,
8,
2063,
12,
4569,
9,
267,
340,
1402,
63,
3642,
365,
440,
488,
26,
288,
291,
14,
409,
63,
1238,
63,
3642,
8,
1238,
63,
3642,
9,
267,
340,
2455,
63,
3642,
365,
440,
488,
26,
288,
291,
14,
409,
63,
1345,
63,
3642,
8,
1345,
63,
3642,
9,
267,
340,
14777,
63,
3642,
365,
440,
488,
26,
288,
291,
14,
409,
63,
16539,
63,
3642,
8,
16539,
63,
3642,
9,
339,
768,
1829,
272,
347,
3462,
8,
277,
304,
267,
372,
291,
423,
32477,
14,
362,
63,
2063,
342,
339,
768,
1829,
272,
347,
4569,
8,
277,
304,
267,
372,
291,
423,
32477,
14,
362,
63,
3333,
342,
339,
768,
1829,
272,
347,
1402,
63,
3642,
8,
277,
304,
267,
372,
291,
423,
32477,
14,
362,
63,
1238,
63,
3642,
342,
339,
768,
1829,
272,
347,
2455,
63,
3642,
8,
277,
304,
267,
372,
291,
423,
32477,
14,
362,
63,
1345,
63,
3642,
342,
339,
768,
1829,
272,
347,
14777,
63,
3642,
8,
277,
304,
267,
372,
291,
423,
32477,
14,
362,
63,
16539,
63,
3642,
342,
339,
347,
663,
63,
1238,
63,
3642,
8,
277,
12,
574,
304,
267,
574,
275,
485,
4712,
63,
32477,
63,
526,
23748,
63,
3642,
8,
585,
9,
267,
291,
423,
32477,
14,
409,
63,
1238,
63,
3642,
8,
585,
9,
339,
347,
663,
63,
1345,
63,
3642,
8,
277,
12,
574,
304,
267,
574,
275,
485,
4712,
63,
32477,
63,
526,
23748,
63,
3642,
8,
585,
9,
267,
291,
423,
32477,
14,
409,
63,
1345,
63,
3642,
8,
585,
9,
339,
347,
663,
63,
16539,
63,
3642,
8,
277,
12,
574,
304,
267,
574,
275,
485,
4712,
63,
32477,
63,
526,
23748,
63,
3642,
8,
585,
9,
267,
291,
423,
32477,
14,
409,
63,
16539,
63,
3642,
8,
585,
9,
339,
347,
519,
305,
6236,
806,
63,
6480,
63,
1045,
63,
70,
19,
86,
63,
29690,
867,
8,
277,
12,
519,
305,
6236,
90,
461,
12,
4490,
1126,
63,
11417,
63,
70,
19,
86,
29,
403,
304,
267,
519,
624,
50,
305,
6236,
806,
314,
909,
370,
376,
1834,
436,
3550,
376,
23005,
972,
267,
650,
13,
1609,
1834,
687,
282,
1126,
12759,
2069,
650,
5477,
14,
398,
982,
949,
1126,
63,
11417,
63,
70,
19,
86,
365,
2741,
12,
314,
1402,
1159,
2215,
365,
1202,
334,
391,
17443,
267,
642,
1083,
7353,
370,
519,
305,
6236,
806,
63,
6480,
63,
1045,
63,
1392,
63,
1569,
9,
398,
3897,
267,
4143,
267,
519,
305,
6236,
90,
461,
520,
909,
18234,
314,
820,
305,
6236,
90,
461,
3217,
14,
288,
12823,
506,
30081,
367,
2005,
1174,
370,
519,
305,
6236,
806,
4799,
314,
820,
305,
6236,
90,
461,
288,
3217,
14,
3390,
626,
5544,
12,
3164,
9364,
519,
305,
6236,
90,
1298,
787,
288,
440,
3748,
14,
398,
1126,
63,
11417,
63,
70,
19,
86,
520,
2716,
12,
6800,
334,
78,
63,
3438,
12,
650,
9,
288,
437,
1126,
13,
11417,
650,
5477,
402,
15657,
626,
911,
506,
23005,
972,
9371,
288,
314,
1834,
14,
7318,
1803,
267,
5514,
267,
15180,
63,
1569,
520,
650,
3623,
17581,
379,
3491,
402,
2215,
334,
2063,
12,
4569,
9,
288,
710,
754,
402,
314,
519,
305,
6236,
13362,
14,
17581,
365,
2549,
17963,
314,
7148,
1990,
288,
8018,
370,
701,
24374,
14,
398,
23716,
63,
1569,
26,
650,
3623,
17581,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
RAtechntukan/CouchPotatoServer
|
libs/chardet/mbcsgroupprober.py
|
236
|
1889
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Universal charset detector code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 2001
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - port to Python
# Shy Shalom - original C code
# Proofpoint, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
from charsetgroupprober import CharSetGroupProber
from utf8prober import UTF8Prober
from sjisprober import SJISProber
from eucjpprober import EUCJPProber
from gb2312prober import GB2312Prober
from euckrprober import EUCKRProber
from big5prober import Big5Prober
from euctwprober import EUCTWProber
class MBCSGroupProber(CharSetGroupProber):
def __init__(self):
CharSetGroupProber.__init__(self)
self._mProbers = [ \
UTF8Prober(),
SJISProber(),
EUCJPProber(),
GB2312Prober(),
EUCKRProber(),
Big5Prober(),
EUCTWProber()]
self.reset()
|
gpl-3.0
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
29347,
5960,
17842,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
12521,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
257,
428,
3577,
5244,
279,
676,
446,
3379,
445,
1233,
199,
3,
257,
2165,
1618,
1403,
12,
3277,
14,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
5960,
923,
19903,
492,
6659,
1084,
2448,
8029,
199,
504,
2774,
24,
19903,
492,
9094,
24,
8029,
199,
504,
308,
18941,
19903,
492,
428,
22290,
8029,
199,
504,
325,
947,
11538,
19903,
492,
662,
13371,
15819,
8029,
199,
504,
25411,
16909,
19903,
492,
18553,
16909,
8029,
199,
504,
325,
10112,
82,
19903,
492,
26007,
27373,
8029,
199,
504,
7282,
21,
19903,
492,
13123,
21,
8029,
199,
504,
325,
918,
87,
19903,
492,
662,
27120,
8029,
199,
199,
533,
19487,
3298,
2448,
8029,
8,
1610,
1084,
2448,
8029,
304,
272,
347,
636,
826,
721,
277,
304,
267,
6659,
1084,
2448,
8029,
855,
826,
721,
277,
9,
267,
291,
423,
77,
8029,
83,
275,
359,
971,
288,
9094,
24,
8029,
1062,
288,
428,
22290,
8029,
1062,
288,
662,
13371,
15819,
8029,
1062,
288,
18553,
16909,
8029,
1062,
288,
26007,
27373,
8029,
1062,
288,
13123,
21,
8029,
1062,
288,
662,
27120,
8029,
5106,
267,
291,
14,
3958,
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
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
29347,
5960,
17842,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
12521,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
257,
428,
3577,
5244,
279,
676,
446,
3379,
445,
1233,
199,
3,
257,
2165,
1618,
1403,
12,
3277,
14,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
5960,
923,
19903,
492,
6659,
1084,
2448,
8029,
199,
504,
2774,
24,
19903,
492,
9094,
24,
8029,
199,
504,
308,
18941,
19903,
492,
428,
22290,
8029,
199,
504,
325,
947,
11538,
19903,
492,
662,
13371,
15819,
8029,
199,
504,
25411,
16909,
19903,
492,
18553,
16909,
8029,
199,
504,
325,
10112,
82,
19903,
492,
26007,
27373,
8029,
199,
504,
7282,
21,
19903,
492,
13123,
21,
8029,
199,
504,
325,
918,
87,
19903,
492,
662,
27120,
8029,
199,
199,
533,
19487,
3298,
2448,
8029,
8,
1610,
1084,
2448,
8029,
304,
272,
347,
636,
826,
721,
277,
304,
267,
6659,
1084,
2448,
8029,
855,
826,
721,
277,
9,
267,
291,
423,
77,
8029,
83,
275,
359,
971,
288,
9094,
24,
8029,
1062,
288,
428,
22290,
8029,
1062,
288,
662,
13371,
15819,
8029,
1062,
288,
18553,
16909,
8029,
1062,
288,
26007,
27373,
8029,
1062,
288,
13123,
21,
8029,
1062,
288,
662,
27120,
8029,
5106,
267,
291,
14,
3958,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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def get_type():
return "LIBRARY"
def get_desc():
return "clang generic lib c++"
def get_licence():
return "bsd-like"
def get_compagny_type():
return "com"
def get_compagny_name():
return "University of Illinois"
def get_maintainer():
return ["LLVM Team"]
def get_version():
return [3,4]
def create(target, module_name):
my_module = module.Module(__file__, module_name, get_type())
my_module.add_src_file([
'cxx/src/algorithm.cpp',
'cxx/src/bind.cpp',
'cxx/src/chrono.cpp',
'cxx/src/condition_variable.cpp',
'cxx/src/debug.cpp',
'cxx/src/exception.cpp',
'cxx/src/future.cpp',
'cxx/src/hash.cpp',
'cxx/src/ios.cpp',
'cxx/src/iostream.cpp',
'cxx/src/locale.cpp',
'cxx/src/memory.cpp',
'cxx/src/mutex.cpp',
'cxx/src/new.cpp',
'cxx/src/optional.cpp',
'cxx/src/random.cpp',
'cxx/src/regex.cpp',
'cxx/src/shared_mutex.cpp',
'cxx/src/stdexcept.cpp',
'cxx/src/string.cpp',
'cxx/src/strstream.cpp',
'cxx/src/system_error.cpp',
'cxx/src/thread.cpp',
'cxx/src/typeinfo.cpp',
'cxx/src/utility.cpp',
'cxx/src/valarray.cpp'
])
if target.name=="Windows":
my_module.add_src_file([
'src/support/win32/support.cpp',
'src/support/win32/locale_win32.cpp'
])
my_module.compile_version("c++", 2011)
my_module.compile_flags('c++', [
"-nostdinc++",
"-std=c++11",
"-fstrict-aliasing",
"-Wall",
"-Wextra",
"-Wshadow",
"-Wconversion",
"-Wpadded",
"-Wstrict-aliasing=2",
"-Wstrict-overflow=4"
])
# add local include path to build
my_module.add_path(os.path.join(tools.get_current_path(__file__), "cxx/include"))
my_module.add_header_file([
'cxx/include/*'
],
destination_path=""
)
my_module.add_header_file([
'cxx/include/experimental/*',
],
destination_path="experimental")
if target.name=="Windows":
my_module.add_header_file([
'cxx/include/support/win32/*',
],
destination_path="include/support/win32")
# export flag that we use LLVM C++ lib
my_module.add_export_flag("c++", ["-D__STDCPP_LLVM__", "-nostdinc++"])
# remove some exception in linux system ...
my_module.compile_flags("c++", ["-D__GLIBCXX__"])
# dev add basic lib supc used for allocation and basic c++ environement ==> todo: set a basic constructor (-lSystem for MacOS)
my_module.add_export_flag("link", [target.stdlib_name_libsupc])
return my_module
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
646,
634,
337,
262,
14,
578,
465,
859,
199,
646,
634,
337,
262,
14,
2537,
465,
7249,
199,
646,
634,
337,
262,
14,
1757,
465,
3105,
199,
646,
747,
421,
199,
318,
664,
63,
466,
837,
199,
198,
1107,
298,
16983,
2,
199,
199,
318,
664,
63,
3257,
837,
199,
198,
1107,
298,
16066,
7809,
1973,
286,
4176,
2,
199,
199,
318,
664,
63,
606,
4894,
837,
199,
198,
1107,
298,
15746,
13,
2930,
2,
199,
199,
318,
664,
63,
863,
643,
9745,
63,
466,
837,
199,
198,
1107,
298,
957,
2,
199,
199,
318,
664,
63,
863,
643,
9745,
63,
354,
837,
199,
198,
1107,
298,
1358,
14111,
402,
473,
76,
472,
79,
374,
2,
199,
199,
318,
664,
63,
26665,
837,
199,
198,
1107,
2097,
4464,
6849,
11682,
937,
199,
199,
318,
664,
63,
1023,
837,
199,
198,
1107,
359,
19,
12,
20,
61,
199,
199,
318,
1218,
8,
1375,
12,
859,
63,
354,
304,
199,
198,
1662,
63,
578,
275,
859,
14,
2377,
3460,
493,
3108,
859,
63,
354,
12,
664,
63,
466,
1012,
199,
198,
1662,
63,
578,
14,
525,
63,
2164,
63,
493,
779,
507,
198,
7,
9634,
15,
2164,
15,
8833,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
3409,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
31649,
79,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
5394,
63,
1975,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
1757,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
1971,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
2443,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
2227,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
9207,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
73,
9015,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
5508,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
4844,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
19078,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
1222,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
4144,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
2355,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
3821,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
5555,
63,
19078,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
270,
731,
716,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
875,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
495,
1745,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
2253,
63,
705,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
2671,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
466,
815,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
16877,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
637,
1144,
14,
5910,
7,
507,
198,
566,
199,
198,
692,
1347,
14,
354,
11800,
8647,
582,
507,
198,
1662,
63,
578,
14,
525,
63,
2164,
63,
493,
779,
686,
198,
1159,
1195,
15,
4058,
15,
2676,
708,
15,
4058,
14,
5910,
297,
686,
198,
1159,
1195,
15,
4058,
15,
2676,
708,
15,
5508,
63,
2676,
708,
14,
5910,
7,
686,
198,
566,
199,
198,
1662,
63,
578,
14,
2014,
63,
1023,
480,
67,
4176,
401,
7760,
9,
199,
198,
1662,
63,
578,
14,
2014,
63,
2469,
360,
67,
31249,
359,
507,
198,
32095,
889,
1516,
6559,
4176,
401,
507,
198,
32095,
1516,
29,
67,
4176,
845,
401,
507,
198,
32095,
70,
4768,
13,
3620,
316,
401,
507,
198,
32095,
18018,
401,
507,
198,
32095,
55,
2911,
401,
507,
198,
32095,
55,
14714,
401,
507,
198,
32095,
55,
15083,
401,
507,
198,
32095,
55,
25201,
401,
507,
198,
32095,
55,
4768,
13,
3620,
316,
29,
18,
401,
507,
198,
32095,
55,
4768,
13,
14108,
29,
20,
2,
507,
198,
566,
199,
198,
3,
1050,
2257,
2387,
931,
370,
1900,
199,
198,
1662,
63,
578,
14,
525,
63,
515,
8,
736,
14,
515,
14,
904,
8,
2537,
14,
362,
63,
1818,
63,
515,
3460,
493,
10139,
298,
9634,
15,
2613,
2237,
199,
198,
1662,
63,
578,
14,
525,
63,
1291,
63,
493,
779,
507,
198,
7,
9634,
15,
2613,
6331,
7,
507,
198,
467,
507,
198,
6881,
63,
515,
9287,
507,
198,
9,
199,
198,
1662,
63,
578,
14,
525,
63,
1291,
63,
493,
779,
507,
198,
7,
9634,
15,
2613,
15,
18924,
6331,
297,
507,
198,
467,
507,
198,
6881,
63,
515,
628,
18924,
531,
8299,
198,
692,
1347,
14,
354,
11800,
8647,
582,
507,
198,
1662,
63,
578,
14,
525,
63,
1291,
63,
493,
779,
686,
198,
7,
9634,
15,
2613,
15,
4058,
15,
2676,
708,
6331,
297,
686,
198,
467,
686,
198,
6881,
63,
515,
628,
2613,
15,
4058,
15,
2676,
708,
531,
199,
198,
3,
4843,
3305,
626,
781,
675,
491,
28631,
445,
4176,
1973,
199,
198,
1662,
63,
578,
14,
525,
63,
3790,
63,
4173,
480,
67,
4176,
401,
16984,
36,
363,
18472,
14533,
63,
4464,
6849,
13915,
3905,
889,
1516,
6559,
4176,
3135,
199,
198,
3,
2813,
2005,
1919,
315,
18369,
2656,
2263,
199,
198,
1662,
63,
578,
14,
2014,
63,
2469,
480,
67,
4176,
401,
16984,
36,
363,
2226,
2100,
12206,
363,
3135,
199,
198,
3,
4866,
1050,
5678,
1973,
1029,
67,
1202,
367,
18723,
436,
5678,
286,
4176,
655,
1042,
368,
434,
25375,
11386,
26,
663,
282,
5678,
3787,
5868,
76,
3989,
367,
10444,
3100,
9,
199,
198,
1662,
63,
578,
14,
525,
63,
3790,
63,
4173,
480,
1073,
401,
359,
1375,
14,
28683,
63,
354,
63,
773,
1961,
67,
566,
199,
198,
1107,
3002,
63,
578,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
646,
634,
337,
262,
14,
578,
465,
859,
199,
646,
634,
337,
262,
14,
2537,
465,
7249,
199,
646,
634,
337,
262,
14,
1757,
465,
3105,
199,
646,
747,
421,
199,
318,
664,
63,
466,
837,
199,
198,
1107,
298,
16983,
2,
199,
199,
318,
664,
63,
3257,
837,
199,
198,
1107,
298,
16066,
7809,
1973,
286,
4176,
2,
199,
199,
318,
664,
63,
606,
4894,
837,
199,
198,
1107,
298,
15746,
13,
2930,
2,
199,
199,
318,
664,
63,
863,
643,
9745,
63,
466,
837,
199,
198,
1107,
298,
957,
2,
199,
199,
318,
664,
63,
863,
643,
9745,
63,
354,
837,
199,
198,
1107,
298,
1358,
14111,
402,
473,
76,
472,
79,
374,
2,
199,
199,
318,
664,
63,
26665,
837,
199,
198,
1107,
2097,
4464,
6849,
11682,
937,
199,
199,
318,
664,
63,
1023,
837,
199,
198,
1107,
359,
19,
12,
20,
61,
199,
199,
318,
1218,
8,
1375,
12,
859,
63,
354,
304,
199,
198,
1662,
63,
578,
275,
859,
14,
2377,
3460,
493,
3108,
859,
63,
354,
12,
664,
63,
466,
1012,
199,
198,
1662,
63,
578,
14,
525,
63,
2164,
63,
493,
779,
507,
198,
7,
9634,
15,
2164,
15,
8833,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
3409,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
31649,
79,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
5394,
63,
1975,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
1757,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
1971,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
2443,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
2227,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
9207,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
73,
9015,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
5508,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
4844,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
19078,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
1222,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
4144,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
2355,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
3821,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
5555,
63,
19078,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
270,
731,
716,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
875,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
495,
1745,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
2253,
63,
705,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
2671,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
466,
815,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
16877,
14,
5910,
297,
507,
198,
7,
9634,
15,
2164,
15,
637,
1144,
14,
5910,
7,
507,
198,
566,
199,
198,
692,
1347,
14,
354,
11800,
8647,
582,
507,
198,
1662,
63,
578,
14,
525,
63,
2164,
63,
493,
779,
686,
198,
1159,
1195,
15,
4058,
15,
2676,
708,
15,
4058,
14,
5910,
297,
686,
198,
1159,
1195,
15,
4058,
15,
2676,
708,
15,
5508,
63,
2676,
708,
14,
5910,
7,
686,
198,
566,
199,
198,
1662,
63,
578,
14,
2014,
63,
1023,
480,
67,
4176,
401,
7760,
9,
199,
198,
1662,
63,
578,
14,
2014,
63,
2469,
360,
67,
31249,
359,
507,
198,
32095,
889,
1516,
6559,
4176,
401,
507,
198,
32095,
1516,
29,
67,
4176,
845,
401,
507,
198,
32095,
70,
4768,
13,
3620,
316,
401,
507,
198,
32095,
18018,
401,
507,
198,
32095,
55,
2911,
401,
507,
198,
32095,
55,
14714,
401,
507,
198,
32095,
55,
15083,
401,
507,
198,
32095,
55,
25201,
401,
507,
198,
32095,
55,
4768,
13,
3620,
316,
29,
18,
401,
507,
198,
32095,
55,
4768,
13,
14108,
29,
20,
2,
507,
198,
566,
199,
198,
3,
1050,
2257,
2387,
931,
370,
1900,
199,
198,
1662,
63,
578,
14,
525,
63,
515,
8,
736,
14,
515,
14,
904,
8,
2537,
14,
362,
63,
1818,
63,
515,
3460,
493,
10139,
298,
9634,
15,
2613,
2237,
199,
198,
1662,
63,
578,
14,
525,
63,
1291,
63,
493,
779,
507,
198,
7,
9634,
15,
2613,
6331,
7,
507,
198,
467,
507,
198,
6881,
63,
515,
9287,
507,
198,
9,
199,
198,
1662,
63,
578,
14,
525,
63,
1291,
63,
493,
779,
507,
198,
7,
9634,
15,
2613,
15,
18924,
6331,
297,
507,
198,
467,
507,
198,
6881,
63,
515,
628,
18924,
531,
8299,
198,
692,
1347,
14,
354,
11800,
8647,
582,
507,
198,
1662,
63,
578,
14,
525,
63,
1291,
63,
493,
779,
686,
198,
7,
9634,
15,
2613,
15,
4058,
15,
2676,
708,
6331,
297,
686,
198,
467,
686,
198,
6881,
63,
515,
628,
2613,
15,
4058,
15,
2676,
708,
531,
199,
198,
3,
4843,
3305,
626,
781,
675,
491,
28631,
445,
4176,
1973,
199,
198,
1662,
63,
578,
14,
525,
63,
3790,
63,
4173,
480,
67,
4176,
401,
16984,
36,
363,
18472,
14533,
63,
4464,
6849,
13915,
3905,
889,
1516,
6559,
4176,
3135,
199,
198,
3,
2813,
2005,
1919,
315,
18369,
2656,
2263,
199,
198,
1662,
63,
578,
14,
2014,
63,
2469,
480,
67,
4176,
401,
16984,
36,
363,
2226,
2100,
12206,
363,
3135,
199,
198,
3,
4866,
1050,
5678,
1973,
1029,
67,
1202,
367,
18723,
436,
5678,
286,
4176,
655,
1042,
368,
434,
25375,
11386,
26,
663,
282,
5678,
3787,
5868,
76,
3989,
367,
10444,
3100,
9,
199,
198,
1662,
63,
578,
14,
525,
63,
3790,
63,
4173,
480,
1073,
401,
359,
1375,
14,
28683,
63,
354,
63,
773,
1961,
67,
566,
199,
198,
1107,
3002,
63,
578,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
azureplus/swftools
|
wx/viewers/technoargia.py
|
6
|
21233
|
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# gpdf2swf.py
# graphical user interface for pdf2swf
#
# Part of the swftools package.
#
# Copyright (c) 2008,2009 Matthias Kramm <kramm@quiss.org>
#
# 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 gui.fields import Choose, ChooseAndInt, Hidden
order = 1
type = "custom"
name = u"technoargia Viewer"
desc = (u"<p>Simple viewer with home link from Laurent Lalanne.</p>"
u"<br>Visit <a href=\"http://technoargia.free.fr/swftools/"
u"examples/viewer_home/viewer_home.html\">Website</a>")
swf_options = [
Hidden("flashversion", 6),
]
viewer_options = [
Choose("html", u"Save HTML:",
(u"no", False, u"yes", True, ), True),
ChooseAndInt('width', 'Width:',
('same as PDF', -2, 'fullscreen', -1, 'custom', 0), 1, 2, 600),
ChooseAndInt('height', 'Height:',
('same as PDF', -2, 'fullscreen', -1, 'custom', 0), 1, 2, 800),
Choose('zoomtype', 'Initial zoom level:',
('Original resolution', 1,
'Show all', 2,
'Maximum width/height', 3), 2),
]
html_template = """<html>
<body style="padding: 0px; margin: 0px">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
width="%(width)s"
height="%(height)s"
codebase="http://active.macromedia.com/flash5/cabs/swflash.cab#version=%(version)d,0,0,0">
<param name="MOVIE" value="%(swffilename)s">
<param name="PLAY" value="true">
<param name="LOOP" value="true">
<param name="QUALITY" value="high">
<param name="FLASHVARS" value="%(flashvars)s">
<embed src="%(swffilename)s" width="%(width)s" height="%(height)s"
play="true" ALIGN="" loop="true" quality="high"
type="application/x-shockwave-flash"
flashvars="%(flashvars)s"
pluginspage="http://get.adobe.com/flashplayer/">
</embed>
</object>
</body>
</html>
"""
from gui.plugin import Plugin
import os, sys
class Technoargia(Plugin):
def __init__(self, swf, filename):
self.__swf = swf
self.__filename = filename
for opt in swf_options:
swf.setparameter(opt.name, str(opt.value))
setattr(self, "_%s" % opt.name, opt.value)
for opt in viewer_options:
setattr(self, "_%s" % opt.name, opt.value)
def after_save(self, page):
basedir = GPDF2SWF_BASEDIR
viewerfilename = os.path.join(basedir,
"viewers",
"technoargia.swf")
self.swfcombine(
u"%s" % viewerfilename,
u"viewport=%s" % self.__filename,
u"-o", u"%s" % self.__filename,
)
if not self._html:
return
if self._width == -1:
width = "100%"
elif self._width == -2:
width = page.width+40
else:
width = self._width
if self._height == -1:
height = "100%"
elif self._height == -2:
height = page.height+70
else:
height = self._height
template_vars = {
'width': width,
'height': height,
'version': self._flashversion,
'flashvars': "zoomtype=%s" % self._zoomtype,
'swffilename': os.path.basename(self.__filename),
}
htmlfilename = self._swap_extension(self.__filename, "html")
f = open(htmlfilename, "wb")
f.write(html_template % template_vars)
f.close()
def init(swf, filename):
return Technoargia(swf, filename)
from lib.embeddedimage import PyEmbeddedImage
preview = PyEmbeddedImage(
"iVBORw0KGgoAAAANSUhEUgAAAGYAAABmCAYAAAA53+RiAAAABHNCSVQICAgIfAhkiAAAIABJ"
"REFUeJztfXl4FUXW/nv6XiABFGWN7IGwhG1ARHlQNhlBNgkIPIAjiw6bKMig4oZ+IOgnOCCL"
"gowyMOqgDojIjOACyBpERoiKGLYQAyGGQHaSu9X5/XG76lbX7RucVfk9Xz/PTXfXcuq8p06d"
"c6q6ukPMzKv5JLKoDBYDIWIEmQFC5GD7TFe4Jq28Xt/tYO36SnTltVs9sz2Gkx+Tl18YFgLg"
"AcFDBAZQiytjMiWBXuXjfA5lTCB4mXAraqM1roUI1yKwAZE08mz/Za1pUwjkKhadyTAFWTt8"
"ZpUHI5cdYtCBOrvOLPULxSLAyEYZ9iEPBQjAIsL1qET0NH/NALgZqmECmrlrWOQ+0rB5xNI4"
"Z2p0nYq1OlLvSiPBfUy5txMRFbvQ+dmwfIhz+AIX4QGR12KgKnnDnWI3+8e3vsfpsyEMvP16"
"6npzfd6+4wxZBO7Qrh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liKfMzEycPn2aZJT55ptvYu1adyc0AAAMAUlEQVTa"
"tXTHHXfoI44g38JU8xjhuroshBAiGAyKjz76SCxdupSZI5v0EhMTRVFRkZg5c6a4dOmSGDJk"
"iFi2bJkYMWKEGDt2rDh79qycmXOPHj3EJ598ImbNmiWmTp0qXnjhBbFgwQJRtWpV0b59e5Gf"
"n++M6ZnFokWLOCEhQYwcOVK8/fbbYvny5WL48OFCrgY0atRI3H777aJy5coiJSWFe/Xqxcws"
"unXrJt599121QZCZxfjx48W9994r1q5dKz744APx1FNPcUpKitizZ48YNGiQ2L9/v0hKShJj"
"xowRBw8eVPX+9re/iTp16oiHH35Y5Obmih49ejAzi7vvvlvk5uaKYcOGiQ8++EAkJCSIUCgk"
"gsGgyMvLEwDEs88+K7p16yYKCgpE//79efLkyaJatWoiLy9PJCcni1GjRol9+/ZF5j3aPMac"
"YLLROSq8aNGihQomZsyYwR9//DHffffdXFpaKhYsWMAPP/wwjxkzhps3b87MzH/4wx/EunXr"
"uGHDhvyXv/yFn3/+ee7evTuPGzdO9OzZk5mZp0yZwqWlpVxWVsahUEgPBJmZxaOPPso7d+7k"
"goICXrhwoejWrRszs9iwYYPYuXOnuOWWW5jtJRRm5r59+/KiRYvEsGHDRMuWLbm0tFSB3rNn"
"D3ft2lXcd999XFhYyI8++ii3bdtWrF69mn/9618zM/PEiRNFfn5+hAGbn65duyrGZNnhw4fz"
"d999J5o0acK33HILL1myhJnD26IuXLggJk6cyMzMrVu35qlTpwr5js+vfvUrZmbx0EMPyfdr"
"IuJ27MQkZTqUfZTDSk7q1q5di8mTJwMIb6hesGAB+vXrhxUrViA/Px/5+flo164dqlWrhvT0"
"dNx7773o168fjRs3Dp9//jlGjBiBUaNGoUmTJujZsyd99tlnGD9+PICw75Gv7Jkxvd/vR0JC"
"AoqLi5GXl0dVq1bFnj17aN26ddSxY0ekpaUBALKyskiay+TkZKpSpQrS09MlzwSAMjIykJqa"
"SkePHoXX68WiRYuwePFizJ8/H0OGDFHYys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map = preview.GetBitmap
getpreviewIcon = preview.GetIcon
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
9094,
13,
24,
1882,
199,
3,
199,
3,
486,
5607,
18,
20426,
14,
647,
199,
3,
3343,
2652,
922,
3217,
367,
11249,
18,
20426,
199,
3,
199,
3,
14320,
402,
314,
5584,
70,
2537,
2559,
14,
199,
3,
221,
199,
3,
1898,
334,
67,
9,
9079,
12,
8664,
18619,
273,
2241,
1804,
345,
596,
665,
75,
345,
596,
32,
392,
19857,
14,
1308,
30,
221,
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,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
11589,
199,
199,
504,
11621,
14,
955,
492,
29826,
12,
29826,
3325,
3241,
12,
26401,
199,
199,
1648,
275,
413,
199,
466,
275,
298,
4229,
2,
199,
354,
275,
399,
2,
266,
10575,
1273,
4674,
10935,
281,
2,
199,
3257,
275,
334,
85,
17030,
80,
30,
3184,
27354,
543,
5629,
2142,
687,
7964,
608,
343,
491,
279,
290,
685,
9758,
80,
4335,
267,
399,
17030,
3289,
30,
15087,
665,
65,
4369,
8178,
1014,
921,
266,
10575,
1273,
4674,
14,
4624,
14,
4391,
15,
20426,
2537,
6687,
267,
399,
2,
8589,
15,
16645,
63,
4219,
15,
16645,
63,
4219,
14,
1360,
60,
1743,
26354,
1108,
65,
9579,
199,
199,
20426,
63,
1419,
275,
359,
272,
26401,
480,
11331,
1023,
401,
1227,
395,
199,
61,
199,
199,
16645,
63,
1419,
275,
359,
272,
29826,
480,
1360,
401,
399,
2,
8229,
4163,
6783,
1779,
334,
85,
2,
889,
401,
756,
12,
399,
2,
5066,
401,
715,
12,
2318,
715,
395,
272,
29826,
3325,
3241,
360,
2063,
297,
283,
6216,
6536,
2116,
661,
7191,
465,
15537,
297,
446,
18,
12,
283,
28418,
4463,
297,
446,
17,
12,
283,
4229,
297,
378,
395,
413,
12,
499,
12,
11624,
395,
272,
29826,
3325,
3241,
360,
3333,
297,
283,
8436,
6536,
2116,
661,
7191,
465,
15537,
297,
446,
18,
12,
283,
28418,
4463,
297,
446,
17,
12,
283,
4229,
297,
378,
395,
413,
12,
499,
12,
23466,
395,
272,
29826,
360,
10598,
466,
297,
283,
5733,
16935,
2166,
6536,
288,
661,
17286,
12401,
297,
413,
12,
1467,
283,
6824,
1006,
297,
499,
12,
1467,
283,
10915,
3462,
15,
3333,
297,
650,
395,
499,
395,
199,
61,
421,
199,
1360,
63,
1160,
275,
8894,
1360,
30,
199,
28,
2030,
3449,
628,
8358,
26,
378,
5326,
27,
11042,
26,
378,
5326,
1743,
199,
28,
785,
11534,
68,
628,
429,
4148,
26,
36,
1465,
35,
2846,
22,
37,
13,
12500,
22,
36,
13,
845,
2177,
13,
2534,
34,
24,
13,
1602,
13267,
12967,
993,
2,
267,
3462,
17662,
2063,
9,
83,
2,
267,
4569,
17662,
3333,
9,
83,
2,
267,
1233,
1095,
628,
1014,
921,
2682,
14,
11300,
4603,
14,
957,
15,
11331,
21,
15,
67,
2101,
15,
3519,
11331,
14,
26481,
3,
1023,
15438,
1023,
9,
68,
12,
16,
12,
16,
12,
16,
1743,
267,
665,
635,
536,
628,
24321,
4332,
2,
574,
17662,
20426,
1501,
9,
83,
1743,
267,
665,
635,
536,
628,
11625,
2,
574,
628,
2052,
1743,
267,
665,
635,
536,
628,
26573,
2,
574,
628,
2052,
1743,
267,
665,
635,
536,
628,
9283,
1922,
2,
574,
628,
6260,
1743,
267,
665,
635,
536,
628,
3143,
8100,
21367,
2,
574,
17662,
11331,
2936,
9,
83,
1743,
881,
665,
6427,
2928,
17662,
20426,
1501,
9,
83,
2,
3462,
17662,
2063,
9,
83,
2,
4569,
17662,
3333,
9,
83,
2,
326,
5232,
628,
2052,
2,
12112,
3203,
9287,
4438,
628,
2052,
2,
11030,
628,
6260,
2,
326,
730,
628,
3578,
15,
88,
13,
13927,
346,
10024,
13,
11331,
2,
326,
14775,
2936,
17662,
11331,
2936,
9,
83,
2,
326,
8963,
1606,
628,
1014,
921,
362,
14,
5129,
1235,
14,
957,
15,
11331,
6147,
26049,
881,
3068,
6427,
30,
199,
1108,
785,
30,
199,
1108,
2030,
30,
199,
1108,
1360,
30,
199,
624,
199,
199,
504,
11621,
14,
2718,
492,
11349,
199,
646,
747,
12,
984,
199,
199,
533,
13622,
1273,
4674,
8,
5061,
304,
272,
347,
636,
826,
721,
277,
12,
5584,
70,
12,
1788,
304,
267,
291,
855,
20426,
275,
5584,
70,
267,
291,
855,
1501,
275,
1788,
398,
367,
2450,
315,
5584,
70,
63,
1419,
26,
288,
5584,
70,
14,
409,
5329,
8,
2992,
14,
354,
12,
620,
8,
2992,
14,
585,
430,
288,
5371,
8,
277,
12,
2668,
5,
83,
2,
450,
2450,
14,
354,
12,
2450,
14,
585,
9,
398,
367,
2450,
315,
27354,
63,
1419,
26,
288,
5371,
8,
277,
12,
2668,
5,
83,
2,
450,
2450,
14,
354,
12,
2450,
14,
585,
9,
339,
347,
2410,
63,
2117,
8,
277,
12,
2034,
304,
267,
19380,
275,
598,
7638,
18,
8745,
38,
63,
5825,
3022,
267,
27354,
1501,
275,
747,
14,
515,
14,
904,
8,
12484,
12,
4228,
298,
1345,
1192,
401,
4228,
298,
266,
10575,
1273,
4674,
14,
20426,
531,
398,
291,
14,
20426,
13307,
8,
2049,
399,
6808,
83,
2,
450,
27354,
1501,
12,
2049,
399,
2,
25484,
2458,
83,
2,
450,
291,
855,
1501,
12,
2049,
399,
32095,
79,
401,
399,
6808,
83,
2,
450,
291,
855,
1501,
12,
267,
776,
398,
340,
440,
291,
423,
1360,
26,
288,
372,
398,
340,
291,
423,
2063,
508,
446,
17,
26,
288,
3462,
275,
298,
1960,
5,
2,
267,
916,
291,
423,
2063,
508,
446,
18,
26,
288,
3462,
275,
2034,
14,
2063,
11
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
9094,
13,
24,
1882,
199,
3,
199,
3,
486,
5607,
18,
20426,
14,
647,
199,
3,
3343,
2652,
922,
3217,
367,
11249,
18,
20426,
199,
3,
199,
3,
14320,
402,
314,
5584,
70,
2537,
2559,
14,
199,
3,
221,
199,
3,
1898,
334,
67,
9,
9079,
12,
8664,
18619,
273,
2241,
1804,
345,
596,
665,
75,
345,
596,
32,
392,
19857,
14,
1308,
30,
221,
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,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
11589,
199,
199,
504,
11621,
14,
955,
492,
29826,
12,
29826,
3325,
3241,
12,
26401,
199,
199,
1648,
275,
413,
199,
466,
275,
298,
4229,
2,
199,
354,
275,
399,
2,
266,
10575,
1273,
4674,
10935,
281,
2,
199,
3257,
275,
334,
85,
17030,
80,
30,
3184,
27354,
543,
5629,
2142,
687,
7964,
608,
343,
491,
279,
290,
685,
9758,
80,
4335,
267,
399,
17030,
3289,
30,
15087,
665,
65,
4369,
8178,
1014,
921,
266,
10575,
1273,
4674,
14,
4624,
14,
4391,
15,
20426,
2537,
6687,
267,
399,
2,
8589,
15,
16645,
63,
4219,
15,
16645,
63,
4219,
14,
1360,
60,
1743,
26354,
1108,
65,
9579,
199,
199,
20426,
63,
1419,
275,
359,
272,
26401,
480,
11331,
1023,
401,
1227,
395,
199,
61,
199,
199,
16645,
63,
1419,
275,
359,
272,
29826,
480,
1360,
401,
399,
2,
8229,
4163,
6783,
1779,
334,
85,
2,
889,
401,
756,
12,
399,
2,
5066,
401,
715,
12,
2318,
715,
395,
272,
29826,
3325,
3241,
360,
2063,
297,
283,
6216,
6536,
2116,
661,
7191,
465,
15537,
297,
446,
18,
12,
283,
28418,
4463,
297,
446,
17,
12,
283,
4229,
297,
378,
395,
413,
12,
499,
12,
11624,
395,
272,
29826,
3325,
3241,
360,
3333,
297,
283,
8436,
6536,
2116,
661,
7191,
465,
15537,
297,
446,
18,
12,
283,
28418,
4463,
297,
446,
17,
12,
283,
4229,
297,
378,
395,
413,
12,
499,
12,
23466,
395,
272,
29826,
360,
10598,
466,
297,
283,
5733,
16935,
2166,
6536,
288,
661,
17286,
12401,
297,
413,
12,
1467,
283,
6824,
1006,
297,
499,
12,
1467,
283,
10915,
3462,
15,
3333,
297,
650,
395,
499,
395,
199,
61,
421,
199,
1360,
63,
1160,
275,
8894,
1360,
30,
199,
28,
2030,
3449,
628,
8358,
26,
378,
5326,
27,
11042,
26,
378,
5326,
1743,
199,
28,
785,
11534,
68,
628,
429,
4148,
26,
36,
1465,
35,
2846,
22,
37,
13,
12500,
22,
36,
13,
845,
2177,
13,
2534,
34,
24,
13,
1602,
13267,
12967,
993,
2,
267,
3462,
17662,
2063,
9,
83,
2,
267,
4569,
17662,
3333,
9,
83,
2,
267,
1233,
1095,
628,
1014,
921,
2682,
14,
11300,
4603,
14,
957,
15,
11331,
21,
15,
67,
2101,
15,
3519,
11331,
14,
26481,
3,
1023,
15438,
1023,
9,
68,
12,
16,
12,
16,
12,
16,
1743,
267,
665,
635,
536,
628,
24321,
4332,
2,
574,
17662,
20426,
1501,
9,
83,
1743,
267,
665,
635,
536,
628,
11625,
2,
574,
628,
2052,
1743,
267,
665,
635,
536,
628,
26573,
2,
574,
628,
2052,
1743,
267,
665,
635,
536,
628,
9283,
1922,
2,
574,
628,
6260,
1743,
267,
665,
635,
536,
628,
3143,
8100,
21367,
2,
574,
17662,
11331,
2936,
9,
83,
1743,
881,
665,
6427,
2928,
17662,
20426,
1501,
9,
83,
2,
3462,
17662,
2063,
9,
83,
2,
4569,
17662,
3333,
9,
83,
2,
326,
5232,
628,
2052,
2,
12112,
3203,
9287,
4438,
628,
2052,
2,
11030,
628,
6260,
2,
326,
730,
628,
3578,
15,
88,
13,
13927,
346,
10024,
13,
11331,
2,
326,
14775,
2936,
17662,
11331,
2936,
9,
83,
2,
326,
8963,
1606,
628,
1014,
921,
362,
14,
5129,
1235,
14,
957,
15,
11331,
6147,
26049,
881,
3068,
6427,
30,
199,
1108,
785,
30,
199,
1108,
2030,
30,
199,
1108,
1360,
30,
199,
624,
199,
199,
504,
11621,
14,
2718,
492,
11349,
199,
646,
747,
12,
984,
199,
199,
533,
13622,
1273,
4674,
8,
5061,
304,
272,
347,
636,
826,
721,
277,
12,
5584,
70,
12,
1788,
304,
267,
291,
855,
20426,
275,
5584,
70,
267,
291,
855,
1501,
275,
1788,
398,
367,
2450,
315,
5584,
70,
63,
1419,
26,
288,
5584,
70,
14,
409,
5329,
8,
2992,
14,
354,
12,
620,
8,
2992,
14,
585,
430,
288,
5371,
8,
277,
12,
2668,
5,
83,
2,
450,
2450,
14,
354,
12,
2450,
14,
585,
9,
398,
367,
2450,
315,
27354,
63,
1419,
26,
288,
5371,
8,
277,
12,
2668,
5,
83,
2,
450,
2450,
14,
354,
12,
2450,
14,
585,
9,
339,
347,
2410,
63,
2117,
8,
277,
12,
2034,
304,
267,
19380,
275,
598,
7638,
18,
8745,
38,
63,
5825,
3022,
267,
27354,
1501,
275,
747,
14,
515,
14,
904,
8,
12484,
12,
4228,
298,
1345,
1192,
401,
4228,
298,
266,
10575,
1273,
4674,
14,
20426,
531,
398,
291,
14,
20426,
13307,
8,
2049,
399,
6808,
83,
2,
450,
27354,
1501,
12,
2049,
399,
2,
25484,
2458,
83,
2,
450,
291,
855,
1501,
12,
2049,
399,
32095,
79,
401,
399,
6808,
83,
2,
450,
291,
855,
1501,
12,
267,
776,
398,
340,
440,
291,
423,
1360,
26,
288,
372,
398,
340,
291,
423,
2063,
508,
446,
17,
26,
288,
3462,
275,
298,
1960,
5,
2,
267,
916,
291,
423,
2063,
508,
446,
18,
26,
288,
3462,
275,
2034,
14,
2063,
11,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
peerster/CouchPotatoServer
|
libs/xmpp/protocol.py
|
199
|
51362
|
## protocol.py
##
## Copyright (C) 2003-2005 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: protocol.py,v 1.60 2009/04/07 11:14:28 snakeru Exp $
"""
Protocol module contains tools that is needed for processing of
xmpp-related data structures.
"""
from simplexml import Node,ustr
import time
NS_ACTIVITY ='http://jabber.org/protocol/activity' # XEP-0108
NS_ADDRESS ='http://jabber.org/protocol/address' # XEP-0033
NS_ADMIN ='http://jabber.org/protocol/admin' # XEP-0133
NS_ADMIN_ADD_USER =NS_ADMIN+'#add-user' # XEP-0133
NS_ADMIN_DELETE_USER =NS_ADMIN+'#delete-user' # XEP-0133
NS_ADMIN_DISABLE_USER =NS_ADMIN+'#disable-user' # XEP-0133
NS_ADMIN_REENABLE_USER =NS_ADMIN+'#reenable-user' # XEP-0133
NS_ADMIN_END_USER_SESSION =NS_ADMIN+'#end-user-session' # XEP-0133
NS_ADMIN_GET_USER_PASSWORD =NS_ADMIN+'#get-user-password' # XEP-0133
NS_ADMIN_CHANGE_USER_PASSWORD =NS_ADMIN+'#change-user-password' # XEP-0133
NS_ADMIN_GET_USER_ROSTER =NS_ADMIN+'#get-user-roster' # XEP-0133
NS_ADMIN_GET_USER_LASTLOGIN =NS_ADMIN+'#get-user-lastlogin' # XEP-0133
NS_ADMIN_USER_STATS =NS_ADMIN+'#user-stats' # XEP-0133
NS_ADMIN_EDIT_BLACKLIST =NS_ADMIN+'#edit-blacklist' # XEP-0133
NS_ADMIN_EDIT_WHITELIST =NS_ADMIN+'#edit-whitelist' # XEP-0133
NS_ADMIN_REGISTERED_USERS_NUM =NS_ADMIN+'#get-registered-users-num' # XEP-0133
NS_ADMIN_DISABLED_USERS_NUM =NS_ADMIN+'#get-disabled-users-num' # XEP-0133
NS_ADMIN_ONLINE_USERS_NUM =NS_ADMIN+'#get-online-users-num' # XEP-0133
NS_ADMIN_ACTIVE_USERS_NUM =NS_ADMIN+'#get-active-users-num' # XEP-0133
NS_ADMIN_IDLE_USERS_NUM =NS_ADMIN+'#get-idle-users-num' # XEP-0133
NS_ADMIN_REGISTERED_USERS_LIST =NS_ADMIN+'#get-registered-users-list' # XEP-0133
NS_ADMIN_DISABLED_USERS_LIST =NS_ADMIN+'#get-disabled-users-list' # XEP-0133
NS_ADMIN_ONLINE_USERS_LIST =NS_ADMIN+'#get-online-users-list' # XEP-0133
NS_ADMIN_ACTIVE_USERS_LIST =NS_ADMIN+'#get-active-users-list' # XEP-0133
NS_ADMIN_IDLE_USERS_LIST =NS_ADMIN+'#get-idle-users-list' # XEP-0133
NS_ADMIN_ANNOUNCE =NS_ADMIN+'#announce' # XEP-0133
NS_ADMIN_SET_MOTD =NS_ADMIN+'#set-motd' # XEP-0133
NS_ADMIN_EDIT_MOTD =NS_ADMIN+'#edit-motd' # XEP-0133
NS_ADMIN_DELETE_MOTD =NS_ADMIN+'#delete-motd' # XEP-0133
NS_ADMIN_SET_WELCOME =NS_ADMIN+'#set-welcome' # XEP-0133
NS_ADMIN_DELETE_WELCOME =NS_ADMIN+'#delete-welcome' # XEP-0133
NS_ADMIN_EDIT_ADMIN =NS_ADMIN+'#edit-admin' # XEP-0133
NS_ADMIN_RESTART =NS_ADMIN+'#restart' # XEP-0133
NS_ADMIN_SHUTDOWN =NS_ADMIN+'#shutdown' # XEP-0133
NS_AGENTS ='jabber:iq:agents' # XEP-0094 (historical)
NS_AMP ='http://jabber.org/protocol/amp' # XEP-0079
NS_AMP_ERRORS =NS_AMP+'#errors' # XEP-0079
NS_AUTH ='jabber:iq:auth' # XEP-0078
NS_AVATAR ='jabber:iq:avatar' # XEP-0008 (historical)
NS_BIND ='urn:ietf:params:xml:ns:xmpp-bind' # RFC 3920
NS_BROWSE ='jabber:iq:browse' # XEP-0011 (historical)
NS_BYTESTREAM ='http://jabber.org/protocol/bytestreams' # XEP-0065
NS_CAPS ='http://jabber.org/protocol/caps' # XEP-0115
NS_CHATSTATES ='http://jabber.org/protocol/chatstates' # XEP-0085
NS_CLIENT ='jabber:client' # RFC 3921
NS_COMMANDS ='http://jabber.org/protocol/commands' # XEP-0050
NS_COMPONENT_ACCEPT ='jabber:component:accept' # XEP-0114
NS_COMPONENT_1 ='http://jabberd.jabberstudio.org/ns/component/1.0' # Jabberd2
NS_COMPRESS ='http://jabber.org/protocol/compress' # XEP-0138
NS_DATA ='jabber:x:data' # XEP-0004
NS_DATA_LAYOUT ='http://jabber.org/protocol/xdata-layout' # XEP-0141
NS_DATA_VALIDATE ='http://jabber.org/protocol/xdata-validate' # XEP-0122
NS_DELAY ='jabber:x:delay' # XEP-0091 (deprecated)
NS_DIALBACK ='jabber:server:dialback' # RFC 3921
NS_DISCO ='http://jabber.org/protocol/disco' # XEP-0030
NS_DISCO_INFO =NS_DISCO+'#info' # XEP-0030
NS_DISCO_ITEMS =NS_DISCO+'#items' # XEP-0030
NS_ENCRYPTED ='jabber:x:encrypted' # XEP-0027
NS_EVENT ='jabber:x:event' # XEP-0022 (deprecated)
NS_FEATURE ='http://jabber.org/protocol/feature-neg' # XEP-0020
NS_FILE ='http://jabber.org/protocol/si/profile/file-transfer' # XEP-0096
NS_GATEWAY ='jabber:iq:gateway' # XEP-0100
NS_GEOLOC ='http://jabber.org/protocol/geoloc' # XEP-0080
NS_GROUPCHAT ='gc-1.0' # XEP-0045
NS_HTTP_BIND ='http://jabber.org/protocol/httpbind' # XEP-0124
NS_IBB ='http://jabber.org/protocol/ibb' # XEP-0047
NS_INVISIBLE ='presence-invisible' # Jabberd2
NS_IQ ='iq' # Jabberd2
NS_LAST ='jabber:iq:last' # XEP-0012
NS_MESSAGE ='message' # Jabberd2
NS_MOOD ='http://jabber.org/protocol/mood' # XEP-0107
NS_MUC ='http://jabber.org/protocol/muc' # XEP-0045
NS_MUC_ADMIN =NS_MUC+'#admin' # XEP-0045
NS_MUC_OWNER =NS_MUC+'#owner' # XEP-0045
NS_MUC_UNIQUE =NS_MUC+'#unique' # XEP-0045
NS_MUC_USER =NS_MUC+'#user' # XEP-0045
NS_MUC_REGISTER =NS_MUC+'#register' # XEP-0045
NS_MUC_REQUEST =NS_MUC+'#request' # XEP-0045
NS_MUC_ROOMCONFIG =NS_MUC+'#roomconfig' # XEP-0045
NS_MUC_ROOMINFO =NS_MUC+'#roominfo' # XEP-0045
NS_MUC_ROOMS =NS_MUC+'#rooms' # XEP-0045
NS_MUC_TRAFIC =NS_MUC+'#traffic' # XEP-0045
NS_NICK ='http://jabber.org/protocol/nick' # XEP-0172
NS_OFFLINE ='http://jabber.org/protocol/offline' # XEP-0013
NS_PHYSLOC ='http://jabber.org/protocol/physloc' # XEP-0112
NS_PRESENCE ='presence' # Jabberd2
NS_PRIVACY ='jabber:iq:privacy' # RFC 3921
NS_PRIVATE ='jabber:iq:private' # XEP-0049
NS_PUBSUB ='http://jabber.org/protocol/pubsub' # XEP-0060
NS_REGISTER ='jabber:iq:register' # XEP-0077
NS_RC ='http://jabber.org/protocol/rc' # XEP-0146
NS_ROSTER ='jabber:iq:roster' # RFC 3921
NS_ROSTERX ='http://jabber.org/protocol/rosterx' # XEP-0144
NS_RPC ='jabber:iq:rpc' # XEP-0009
NS_SASL ='urn:ietf:params:xml:ns:xmpp-sasl' # RFC 3920
NS_SEARCH ='jabber:iq:search' # XEP-0055
NS_SERVER ='jabber:server' # RFC 3921
NS_SESSION ='urn:ietf:params:xml:ns:xmpp-session' # RFC 3921
NS_SI ='http://jabber.org/protocol/si' # XEP-0096
NS_SI_PUB ='http://jabber.org/protocol/sipub' # XEP-0137
NS_SIGNED ='jabber:x:signed' # XEP-0027
NS_STANZAS ='urn:ietf:params:xml:ns:xmpp-stanzas' # RFC 3920
NS_STREAMS ='http://etherx.jabber.org/streams' # RFC 3920
NS_TIME ='jabber:iq:time' # XEP-0090 (deprecated)
NS_TLS ='urn:ietf:params:xml:ns:xmpp-tls' # RFC 3920
NS_VACATION ='http://jabber.org/protocol/vacation' # XEP-0109
NS_VCARD ='vcard-temp' # XEP-0054
NS_VCARD_UPDATE ='vcard-temp:x:update' # XEP-0153
NS_VERSION ='jabber:iq:version' # XEP-0092
NS_WAITINGLIST ='http://jabber.org/protocol/waitinglist' # XEP-0130
NS_XHTML_IM ='http://jabber.org/protocol/xhtml-im' # XEP-0071
NS_XMPP_STREAMS ='urn:ietf:params:xml:ns:xmpp-streams' # RFC 3920
xmpp_stream_error_conditions="""
bad-format -- -- -- The entity has sent XML that cannot be processed.
bad-namespace-prefix -- -- -- The entity has sent a namespace prefix that is unsupported, or has sent no namespace prefix on an element that requires such a prefix.
conflict -- -- -- The server is closing the active stream for this entity because a new stream has been initiated that conflicts with the existing stream.
connection-timeout -- -- -- The entity has not generated any traffic over the stream for some period of time.
host-gone -- -- -- The value of the 'to' attribute provided by the initiating entity in the stream header corresponds to a hostname that is no longer hosted by the server.
host-unknown -- -- -- The value of the 'to' attribute provided by the initiating entity in the stream header does not correspond to a hostname that is hosted by the server.
improper-addressing -- -- -- A stanza sent between two servers lacks a 'to' or 'from' attribute (or the attribute has no value).
internal-server-error -- -- -- The server has experienced a misconfiguration or an otherwise-undefined internal error that prevents it from servicing the stream.
invalid-from -- cancel -- -- The JID or hostname provided in a 'from' address does not match an authorized JID or validated domain negotiated between servers via SASL or dialback, or between a client and a server via authentication and resource authorization.
invalid-id -- -- -- The stream ID or dialback ID is invalid or does not match an ID previously provided.
invalid-namespace -- -- -- The streams namespace name is something other than "http://etherx.jabber.org/streams" or the dialback namespace name is something other than "jabber:server:dialback".
invalid-xml -- -- -- The entity has sent invalid XML over the stream to a server that performs validation.
not-authorized -- -- -- The entity has attempted to send data before the stream has been authenticated, or otherwise is not authorized to perform an action related to stream negotiation.
policy-violation -- -- -- The entity has violated some local service policy.
remote-connection-failed -- -- -- The server is unable to properly connect to a remote resource that is required for authentication or authorization.
resource-constraint -- -- -- The server lacks the system resources necessary to service the stream.
restricted-xml -- -- -- The entity has attempted to send restricted XML features such as a comment, processing instruction, DTD, entity reference, or unescaped character.
see-other-host -- -- -- The server will not provide service to the initiating entity but is redirecting traffic to another host.
system-shutdown -- -- -- The server is being shut down and all active streams are being closed.
undefined-condition -- -- -- The error condition is not one of those defined by the other conditions in this list.
unsupported-encoding -- -- -- The initiating entity has encoded the stream in an encoding that is not supported by the server.
unsupported-stanza-type -- -- -- The initiating entity has sent a first-level child of the stream that is not supported by the server.
unsupported-version -- -- -- The value of the 'version' attribute provided by the initiating entity in the stream header specifies a version of XMPP that is not supported by the server.
xml-not-well-formed -- -- -- The initiating entity has sent XML that is not well-formed."""
xmpp_stanza_error_conditions="""
bad-request -- 400 -- modify -- The sender has sent XML that is malformed or that cannot be processed.
conflict -- 409 -- cancel -- Access cannot be granted because an existing resource or session exists with the same name or address.
feature-not-implemented -- 501 -- cancel -- The feature requested is not implemented by the recipient or server and therefore cannot be processed.
forbidden -- 403 -- auth -- The requesting entity does not possess the required permissions to perform the action.
gone -- 302 -- modify -- The recipient or server can no longer be contacted at this address.
internal-server-error -- 500 -- wait -- The server could not process the stanza because of a misconfiguration or an otherwise-undefined internal server error.
item-not-found -- 404 -- cancel -- The addressed JID or item requested cannot be found.
jid-malformed -- 400 -- modify -- The value of the 'to' attribute in the sender's stanza does not adhere to the syntax defined in Addressing Scheme.
not-acceptable -- 406 -- cancel -- The recipient or server understands the request but is refusing to process it because it does not meet criteria defined by the recipient or server.
not-allowed -- 405 -- cancel -- The recipient or server does not allow any entity to perform the action.
not-authorized -- 401 -- auth -- The sender must provide proper credentials before being allowed to perform the action, or has provided improper credentials.
payment-required -- 402 -- auth -- The requesting entity is not authorized to access the requested service because payment is required.
recipient-unavailable -- 404 -- wait -- The intended recipient is temporarily unavailable.
redirect -- 302 -- modify -- The recipient or server is redirecting requests for this information to another entity.
registration-required -- 407 -- auth -- The requesting entity is not authorized to access the requested service because registration is required.
remote-server-not-found -- 404 -- cancel -- A remote server or service specified as part or all of the JID of the intended recipient does not exist.
remote-server-timeout -- 504 -- wait -- A remote server or service specified as part or all of the JID of the intended recipient could not be contacted within a reasonable amount of time.
resource-constraint -- 500 -- wait -- The server or recipient lacks the system resources necessary to service the request.
service-unavailable -- 503 -- cancel -- The server or recipient does not currently provide the requested service.
subscription-required -- 407 -- auth -- The requesting entity is not authorized to access the requested service because a subscription is required.
undefined-condition -- 500 -- --
unexpected-request -- 400 -- wait -- The recipient or server understood the request but was not expecting it at this time (e.g., the request was out of order)."""
sasl_error_conditions="""
aborted -- -- -- The receiving entity acknowledges an <abort/> element sent by the initiating entity; sent in reply to the <abort/> element.
incorrect-encoding -- -- -- The data provided by the initiating entity could not be processed because the [BASE64]Josefsson, S., The Base16, Base32, and Base64 Data Encodings, July 2003. encoding is incorrect (e.g., because the encoding does not adhere to the definition in Section 3 of [BASE64]Josefsson, S., The Base16, Base32, and Base64 Data Encodings, July 2003.); sent in reply to a <response/> element or an <auth/> element with initial response data.
invalid-authzid -- -- -- The authzid provided by the initiating entity is invalid, either because it is incorrectly formatted or because the initiating entity does not have permissions to authorize that ID; sent in reply to a <response/> element or an <auth/> element with initial response data.
invalid-mechanism -- -- -- The initiating entity did not provide a mechanism or requested a mechanism that is not supported by the receiving entity; sent in reply to an <auth/> element.
mechanism-too-weak -- -- -- The mechanism requested by the initiating entity is weaker than server policy permits for that initiating entity; sent in reply to a <response/> element or an <auth/> element with initial response data.
not-authorized -- -- -- The authentication failed because the initiating entity did not provide valid credentials (this includes but is not limited to the case of an unknown username); sent in reply to a <response/> element or an <auth/> element with initial response data.
temporary-auth-failure -- -- -- The authentication failed because of a temporary error condition within the receiving entity; sent in reply to an <auth/> element or <response/> element."""
ERRORS,_errorcodes={},{}
for ns,errname,errpool in [(NS_XMPP_STREAMS,'STREAM',xmpp_stream_error_conditions),
(NS_STANZAS ,'ERR' ,xmpp_stanza_error_conditions),
(NS_SASL ,'SASL' ,sasl_error_conditions)]:
for err in errpool.split('\n')[1:]:
cond,code,typ,text=err.split(' -- ')
name=errname+'_'+cond.upper().replace('-','_')
locals()[name]=ns+' '+cond
ERRORS[ns+' '+cond]=[code,typ,text]
if code: _errorcodes[code]=cond
del ns,errname,errpool,err,cond,code,typ,text
def isResultNode(node):
""" Returns true if the node is a positive reply. """
return node and node.getType()=='result'
def isErrorNode(node):
""" Returns true if the node is a negative reply. """
return node and node.getType()=='error'
class NodeProcessed(Exception):
""" Exception that should be raised by handler when the handling should be stopped. """
class StreamError(Exception):
""" Base exception class for stream errors."""
class BadFormat(StreamError): pass
class BadNamespacePrefix(StreamError): pass
class Conflict(StreamError): pass
class ConnectionTimeout(StreamError): pass
class HostGone(StreamError): pass
class HostUnknown(StreamError): pass
class ImproperAddressing(StreamError): pass
class InternalServerError(StreamError): pass
class InvalidFrom(StreamError): pass
class InvalidID(StreamError): pass
class InvalidNamespace(StreamError): pass
class InvalidXML(StreamError): pass
class NotAuthorized(StreamError): pass
class PolicyViolation(StreamError): pass
class RemoteConnectionFailed(StreamError): pass
class ResourceConstraint(StreamError): pass
class RestrictedXML(StreamError): pass
class SeeOtherHost(StreamError): pass
class SystemShutdown(StreamError): pass
class UndefinedCondition(StreamError): pass
class UnsupportedEncoding(StreamError): pass
class UnsupportedStanzaType(StreamError): pass
class UnsupportedVersion(StreamError): pass
class XMLNotWellFormed(StreamError): pass
stream_exceptions = {'bad-format': BadFormat,
'bad-namespace-prefix': BadNamespacePrefix,
'conflict': Conflict,
'connection-timeout': ConnectionTimeout,
'host-gone': HostGone,
'host-unknown': HostUnknown,
'improper-addressing': ImproperAddressing,
'internal-server-error': InternalServerError,
'invalid-from': InvalidFrom,
'invalid-id': InvalidID,
'invalid-namespace': InvalidNamespace,
'invalid-xml': InvalidXML,
'not-authorized': NotAuthorized,
'policy-violation': PolicyViolation,
'remote-connection-failed': RemoteConnectionFailed,
'resource-constraint': ResourceConstraint,
'restricted-xml': RestrictedXML,
'see-other-host': SeeOtherHost,
'system-shutdown': SystemShutdown,
'undefined-condition': UndefinedCondition,
'unsupported-encoding': UnsupportedEncoding,
'unsupported-stanza-type': UnsupportedStanzaType,
'unsupported-version': UnsupportedVersion,
'xml-not-well-formed': XMLNotWellFormed}
class JID:
""" JID object. JID can be built from string, modified, compared, serialised into string. """
def __init__(self, jid=None, node='', domain='', resource=''):
""" Constructor. JID can be specified as string (jid argument) or as separate parts.
Examples:
JID('node@domain/resource')
JID(node='node',domain='domain.org')
"""
if not jid and not domain: raise ValueError('JID must contain at least domain name')
elif type(jid)==type(self): self.node,self.domain,self.resource=jid.node,jid.domain,jid.resource
elif domain: self.node,self.domain,self.resource=node,domain,resource
else:
if jid.find('@')+1: self.node,jid=jid.split('@',1)
else: self.node=''
if jid.find('/')+1: self.domain,self.resource=jid.split('/',1)
else: self.domain,self.resource=jid,''
def getNode(self):
""" Return the node part of the JID """
return self.node
def setNode(self,node):
""" Set the node part of the JID to new value. Specify None to remove the node part."""
self.node=node.lower()
def getDomain(self):
""" Return the domain part of the JID """
return self.domain
def setDomain(self,domain):
""" Set the domain part of the JID to new value."""
self.domain=domain.lower()
def getResource(self):
""" Return the resource part of the JID """
return self.resource
def setResource(self,resource):
""" Set the resource part of the JID to new value. Specify None to remove the resource part."""
self.resource=resource
def getStripped(self):
""" Return the bare representation of JID. I.e. string value w/o resource. """
return self.__str__(0)
def __eq__(self, other):
""" Compare the JID to another instance or to string for equality. """
try: other=JID(other)
except ValueError: return 0
return self.resource==other.resource and self.__str__(0) == other.__str__(0)
def __ne__(self, other):
""" Compare the JID to another instance or to string for non-equality. """
return not self.__eq__(other)
def bareMatch(self, other):
""" Compare the node and domain parts of the JID's for equality. """
return self.__str__(0) == JID(other).__str__(0)
def __str__(self,wresource=1):
""" Serialise JID into string. """
if self.node: jid=self.node+'@'+self.domain
else: jid=self.domain
if wresource and self.resource: return jid+'/'+self.resource
return jid
def __hash__(self):
""" Produce hash of the JID, Allows to use JID objects as keys of the dictionary. """
return hash(self.__str__())
class Protocol(Node):
""" A "stanza" object class. Contains methods that are common for presences, iqs and messages. """
def __init__(self, name=None, to=None, typ=None, frm=None, attrs={}, payload=[], timestamp=None, xmlns=None, node=None):
""" Constructor, name is the name of the stanza i.e. 'message' or 'presence' or 'iq'.
to is the value of 'to' attribure, 'typ' - 'type' attribute
frn - from attribure, attrs - other attributes mapping, payload - same meaning as for simplexml payload definition
timestamp - the time value that needs to be stamped over stanza
xmlns - namespace of top stanza node
node - parsed or unparsed stana to be taken as prototype.
"""
if not attrs: attrs={}
if to: attrs['to']=to
if frm: attrs['from']=frm
if typ: attrs['type']=typ
Node.__init__(self, tag=name, attrs=attrs, payload=payload, node=node)
if not node and xmlns: self.setNamespace(xmlns)
if self['to']: self.setTo(self['to'])
if self['from']: self.setFrom(self['from'])
if node and type(self)==type(node) and self.__class__==node.__class__ and self.attrs.has_key('id'): del self.attrs['id']
self.timestamp=None
for x in self.getTags('x',namespace=NS_DELAY):
try:
if not self.getTimestamp() or x.getAttr('stamp')<self.getTimestamp(): self.setTimestamp(x.getAttr('stamp'))
except: pass
if timestamp is not None: self.setTimestamp(timestamp) # To auto-timestamp stanza just pass timestamp=''
def getTo(self):
""" Return value of the 'to' attribute. """
try: return self['to']
except: return None
def getFrom(self):
""" Return value of the 'from' attribute. """
try: return self['from']
except: return None
def getTimestamp(self):
""" Return the timestamp in the 'yyyymmddThhmmss' format. """
return self.timestamp
def getID(self):
""" Return the value of the 'id' attribute. """
return self.getAttr('id')
def setTo(self,val):
""" Set the value of the 'to' attribute. """
self.setAttr('to', JID(val))
def getType(self):
""" Return the value of the 'type' attribute. """
return self.getAttr('type')
def setFrom(self,val):
""" Set the value of the 'from' attribute. """
self.setAttr('from', JID(val))
def setType(self,val):
""" Set the value of the 'type' attribute. """
self.setAttr('type', val)
def setID(self,val):
""" Set the value of the 'id' attribute. """
self.setAttr('id', val)
def getError(self):
""" Return the error-condition (if present) or the textual description of the error (otherwise). """
errtag=self.getTag('error')
if errtag:
for tag in errtag.getChildren():
if tag.getName()<>'text': return tag.getName()
return errtag.getData()
def getErrorCode(self):
""" Return the error code. Obsolette. """
return self.getTagAttr('error','code')
def setError(self,error,code=None):
""" Set the error code. Obsolette. Use error-conditions instead. """
if code:
if str(code) in _errorcodes.keys(): error=ErrorNode(_errorcodes[str(code)],text=error)
else: error=ErrorNode(ERR_UNDEFINED_CONDITION,code=code,typ='cancel',text=error)
elif type(error) in [type(''),type(u'')]: error=ErrorNode(error)
self.setType('error')
self.addChild(node=error)
def setTimestamp(self,val=None):
"""Set the timestamp. timestamp should be the yyyymmddThhmmss string."""
if not val: val=time.strftime('%Y%m%dT%H:%M:%S', time.gmtime())
self.timestamp=val
self.setTag('x',{'stamp':self.timestamp},namespace=NS_DELAY)
def getProperties(self):
""" Return the list of namespaces to which belongs the direct childs of element"""
props=[]
for child in self.getChildren():
prop=child.getNamespace()
if prop not in props: props.append(prop)
return props
def __setitem__(self,item,val):
""" Set the item 'item' to the value 'val'."""
if item in ['to','from']: val=JID(val)
return self.setAttr(item,val)
class Message(Protocol):
""" XMPP Message stanza - "push" mechanism."""
def __init__(self, to=None, body=None, typ=None, subject=None, attrs={}, frm=None, payload=[], timestamp=None, xmlns=NS_CLIENT, node=None):
""" Create message object. You can specify recipient, text of message, type of message
any additional attributes, sender of the message, any additional payload (f.e. jabber:x:delay element) and namespace in one go.
Alternatively you can pass in the other XML object as the 'node' parameted to replicate it as message. """
Protocol.__init__(self, 'message', to=to, typ=typ, attrs=attrs, frm=frm, payload=payload, timestamp=timestamp, xmlns=xmlns, node=node)
if body: self.setBody(body)
if subject: self.setSubject(subject)
def getBody(self):
""" Returns text of the message. """
return self.getTagData('body')
def getSubject(self):
""" Returns subject of the message. """
return self.getTagData('subject')
def getThread(self):
""" Returns thread of the message. """
return self.getTagData('thread')
def setBody(self,val):
""" Sets the text of the message. """
self.setTagData('body',val)
def setSubject(self,val):
""" Sets the subject of the message. """
self.setTagData('subject',val)
def setThread(self,val):
""" Sets the thread of the message. """
self.setTagData('thread',val)
def buildReply(self,text=None):
""" Builds and returns another message object with specified text.
The to, from and thread properties of new message are pre-set as reply to this message. """
m=Message(to=self.getFrom(),frm=self.getTo(),body=text)
th=self.getThread()
if th: m.setThread(th)
return m
class Presence(Protocol):
""" XMPP Presence object."""
def __init__(self, to=None, typ=None, priority=None, show=None, status=None, attrs={}, frm=None, timestamp=None, payload=[], xmlns=NS_CLIENT, node=None):
""" Create presence object. You can specify recipient, type of message, priority, show and status values
any additional attributes, sender of the presence, timestamp, any additional payload (f.e. jabber:x:delay element) and namespace in one go.
Alternatively you can pass in the other XML object as the 'node' parameted to replicate it as presence. """
Protocol.__init__(self, 'presence', to=to, typ=typ, attrs=attrs, frm=frm, payload=payload, timestamp=timestamp, xmlns=xmlns, node=node)
if priority: self.setPriority(priority)
if show: self.setShow(show)
if status: self.setStatus(status)
def getPriority(self):
""" Returns the priority of the message. """
return self.getTagData('priority')
def getShow(self):
""" Returns the show value of the message. """
return self.getTagData('show')
def getStatus(self):
""" Returns the status string of the message. """
return self.getTagData('status')
def setPriority(self,val):
""" Sets the priority of the message. """
self.setTagData('priority',val)
def setShow(self,val):
""" Sets the show value of the message. """
self.setTagData('show',val)
def setStatus(self,val):
""" Sets the status string of the message. """
self.setTagData('status',val)
def _muc_getItemAttr(self,tag,attr):
for xtag in self.getTags('x'):
for child in xtag.getTags(tag):
return child.getAttr(attr)
def _muc_getSubTagDataAttr(self,tag,attr):
for xtag in self.getTags('x'):
for child in xtag.getTags('item'):
for cchild in child.getTags(tag):
return cchild.getData(),cchild.getAttr(attr)
return None,None
def getRole(self):
"""Returns the presence role (for groupchat)"""
return self._muc_getItemAttr('item','role')
def getAffiliation(self):
"""Returns the presence affiliation (for groupchat)"""
return self._muc_getItemAttr('item','affiliation')
def getNick(self):
"""Returns the nick value (for nick change in groupchat)"""
return self._muc_getItemAttr('item','nick')
def getJid(self):
"""Returns the presence jid (for groupchat)"""
return self._muc_getItemAttr('item','jid')
def getReason(self):
"""Returns the reason of the presence (for groupchat)"""
return self._muc_getSubTagDataAttr('reason','')[0]
def getActor(self):
"""Returns the reason of the presence (for groupchat)"""
return self._muc_getSubTagDataAttr('actor','jid')[1]
def getStatusCode(self):
"""Returns the status code of the presence (for groupchat)"""
return self._muc_getItemAttr('status','code')
class Iq(Protocol):
""" XMPP Iq object - get/set dialog mechanism. """
def __init__(self, typ=None, queryNS=None, attrs={}, to=None, frm=None, payload=[], xmlns=NS_CLIENT, node=None):
""" Create Iq object. You can specify type, query namespace
any additional attributes, recipient of the iq, sender of the iq, any additional payload (f.e. jabber:x:data node) and namespace in one go.
Alternatively you can pass in the other XML object as the 'node' parameted to replicate it as an iq. """
Protocol.__init__(self, 'iq', to=to, typ=typ, attrs=attrs, frm=frm, xmlns=xmlns, node=node)
if payload: self.setQueryPayload(payload)
if queryNS: self.setQueryNS(queryNS)
def getQueryNS(self):
""" Return the namespace of the 'query' child element."""
tag=self.getTag('query')
if tag: return tag.getNamespace()
def getQuerynode(self):
""" Return the 'node' attribute value of the 'query' child element."""
return self.getTagAttr('query','node')
def getQueryPayload(self):
""" Return the 'query' child element payload."""
tag=self.getTag('query')
if tag: return tag.getPayload()
def getQueryChildren(self):
""" Return the 'query' child element child nodes."""
tag=self.getTag('query')
if tag: return tag.getChildren()
def setQueryNS(self,namespace):
""" Set the namespace of the 'query' child element."""
self.setTag('query').setNamespace(namespace)
def setQueryPayload(self,payload):
""" Set the 'query' child element payload."""
self.setTag('query').setPayload(payload)
def setQuerynode(self,node):
""" Set the 'node' attribute value of the 'query' child element."""
self.setTagAttr('query','node',node)
def buildReply(self,typ):
""" Builds and returns another Iq object of specified type.
The to, from and query child node of new Iq are pre-set as reply to this Iq. """
iq=Iq(typ,to=self.getFrom(),frm=self.getTo(),attrs={'id':self.getID()})
if self.getTag('query'): iq.setQueryNS(self.getQueryNS())
return iq
class ErrorNode(Node):
""" XMPP-style error element.
In the case of stanza error should be attached to XMPP stanza.
In the case of stream-level errors should be used separately. """
def __init__(self,name,code=None,typ=None,text=None):
""" Create new error node object.
Mandatory parameter: name - name of error condition.
Optional parameters: code, typ, text. Used for backwards compartibility with older jabber protocol."""
if ERRORS.has_key(name):
cod,type,txt=ERRORS[name]
ns=name.split()[0]
else: cod,ns,type,txt='500',NS_STANZAS,'cancel',''
if typ: type=typ
if code: cod=code
if text: txt=text
Node.__init__(self,'error',{},[Node(name)])
if type: self.setAttr('type',type)
if not cod: self.setName('stream:error')
if txt: self.addChild(node=Node(ns+' text',{},[txt]))
if cod: self.setAttr('code',cod)
class Error(Protocol):
""" Used to quickly transform received stanza into error reply."""
def __init__(self,node,error,reply=1):
""" Create error reply basing on the received 'node' stanza and the 'error' error condition.
If the 'node' is not the received stanza but locally created ('to' and 'from' fields needs not swapping)
specify the 'reply' argument as false."""
if reply: Protocol.__init__(self,to=node.getFrom(),frm=node.getTo(),node=node)
else: Protocol.__init__(self,node=node)
self.setError(error)
if node.getType()=='error': self.__str__=self.__dupstr__
def __dupstr__(self,dup1=None,dup2=None):
""" Dummy function used as preventor of creating error node in reply to error node.
I.e. you will not be able to serialise "double" error into string.
"""
return ''
class DataField(Node):
""" This class is used in the DataForm class to describe the single data item.
If you are working with jabber:x:data (XEP-0004, XEP-0068, XEP-0122)
then you will need to work with instances of this class. """
def __init__(self,name=None,value=None,typ=None,required=0,label=None,desc=None,options=[],node=None):
""" Create new data field of specified name,value and type.
Also 'required','desc' and 'options' fields can be set.
Alternatively other XML object can be passed in as the 'node' parameted to replicate it as a new datafiled.
"""
Node.__init__(self,'field',node=node)
if name: self.setVar(name)
if type(value) in [list,tuple]: self.setValues(value)
elif value: self.setValue(value)
if typ: self.setType(typ)
elif not typ and not node: self.setType('text-single')
if required: self.setRequired(required)
if label: self.setLabel(label)
if desc: self.setDesc(desc)
if options: self.setOptions(options)
def setRequired(self,req=1):
""" Change the state of the 'required' flag. """
if req: self.setTag('required')
else:
try: self.delChild('required')
except ValueError: return
def isRequired(self):
""" Returns in this field a required one. """
return self.getTag('required')
def setLabel(self,label):
""" Set the label of this field. """
self.setAttr('label',label)
def getLabel(self):
""" Return the label of this field. """
return self.getAttr('label')
def setDesc(self,desc):
""" Set the description of this field. """
self.setTagData('desc',desc)
def getDesc(self):
""" Return the description of this field. """
return self.getTagData('desc')
def setValue(self,val):
""" Set the value of this field. """
self.setTagData('value',val)
def getValue(self):
return self.getTagData('value')
def setValues(self,lst):
""" Set the values of this field as values-list.
Replaces all previous filed values! If you need to just add a value - use addValue method."""
while self.getTag('value'): self.delChild('value')
for val in lst: self.addValue(val)
def addValue(self,val):
""" Add one more value to this field. Used in 'get' iq's or such."""
self.addChild('value',{},[val])
def getValues(self):
""" Return the list of values associated with this field."""
ret=[]
for tag in self.getTags('value'): ret.append(tag.getData())
return ret
def getOptions(self):
""" Return label-option pairs list associated with this field."""
ret=[]
for tag in self.getTags('option'): ret.append([tag.getAttr('label'),tag.getTagData('value')])
return ret
def setOptions(self,lst):
""" Set label-option pairs list associated with this field."""
while self.getTag('option'): self.delChild('option')
for opt in lst: self.addOption(opt)
def addOption(self,opt):
""" Add one more label-option pair to this field."""
if type(opt) in [str,unicode]: self.addChild('option').setTagData('value',opt)
else: self.addChild('option',{'label':opt[0]}).setTagData('value',opt[1])
def getType(self):
""" Get type of this field. """
return self.getAttr('type')
def setType(self,val):
""" Set type of this field. """
return self.setAttr('type',val)
def getVar(self):
""" Get 'var' attribute value of this field. """
return self.getAttr('var')
def setVar(self,val):
""" Set 'var' attribute value of this field. """
return self.setAttr('var',val)
class DataReported(Node):
""" This class is used in the DataForm class to describe the 'reported data field' data items which are used in
'multiple item form results' (as described in XEP-0004).
Represents the fields that will be returned from a search. This information is useful when
you try to use the jabber:iq:search namespace to return dynamic form information.
"""
def __init__(self,node=None):
""" Create new empty 'reported data' field. However, note that, according XEP-0004:
* It MUST contain one or more DataFields.
* Contained DataFields SHOULD possess a 'type' and 'label' attribute in addition to 'var' attribute
* Contained DataFields SHOULD NOT contain a <value/> element.
Alternatively other XML object can be passed in as the 'node' parameted to replicate it as a new
dataitem.
"""
Node.__init__(self,'reported',node=node)
if node:
newkids=[]
for n in self.getChildren():
if n.getName()=='field': newkids.append(DataField(node=n))
else: newkids.append(n)
self.kids=newkids
def getField(self,name):
""" Return the datafield object with name 'name' (if exists). """
return self.getTag('field',attrs={'var':name})
def setField(self,name,typ=None,label=None):
""" Create if nessessary or get the existing datafield object with name 'name' and return it.
If created, attributes 'type' and 'label' are applied to new datafield."""
f=self.getField(name)
if f: return f
return self.addChild(node=DataField(name,None,typ,0,label))
def asDict(self):
""" Represent dataitem as simple dictionary mapping of datafield names to their values."""
ret={}
for field in self.getTags('field'):
name=field.getAttr('var')
typ=field.getType()
if isinstance(typ,(str,unicode)) and typ[-6:]=='-multi':
val=[]
for i in field.getTags('value'): val.append(i.getData())
else: val=field.getTagData('value')
ret[name]=val
if self.getTag('instructions'): ret['instructions']=self.getInstructions()
return ret
def __getitem__(self,name):
""" Simple dictionary interface for getting datafields values by their names."""
item=self.getField(name)
if item: return item.getValue()
raise IndexError('No such field')
def __setitem__(self,name,val):
""" Simple dictionary interface for setting datafields values by their names."""
return self.setField(name).setValue(val)
class DataItem(Node):
""" This class is used in the DataForm class to describe data items which are used in 'multiple
item form results' (as described in XEP-0004).
"""
def __init__(self,node=None):
""" Create new empty data item. However, note that, according XEP-0004, DataItem MUST contain ALL
DataFields described in DataReported.
Alternatively other XML object can be passed in as the 'node' parameted to replicate it as a new
dataitem.
"""
Node.__init__(self,'item',node=node)
if node:
newkids=[]
for n in self.getChildren():
if n.getName()=='field': newkids.append(DataField(node=n))
else: newkids.append(n)
self.kids=newkids
def getField(self,name):
""" Return the datafield object with name 'name' (if exists). """
return self.getTag('field',attrs={'var':name})
def setField(self,name):
""" Create if nessessary or get the existing datafield object with name 'name' and return it. """
f=self.getField(name)
if f: return f
return self.addChild(node=DataField(name))
def asDict(self):
""" Represent dataitem as simple dictionary mapping of datafield names to their values."""
ret={}
for field in self.getTags('field'):
name=field.getAttr('var')
typ=field.getType()
if isinstance(typ,(str,unicode)) and typ[-6:]=='-multi':
val=[]
for i in field.getTags('value'): val.append(i.getData())
else: val=field.getTagData('value')
ret[name]=val
if self.getTag('instructions'): ret['instructions']=self.getInstructions()
return ret
def __getitem__(self,name):
""" Simple dictionary interface for getting datafields values by their names."""
item=self.getField(name)
if item: return item.getValue()
raise IndexError('No such field')
def __setitem__(self,name,val):
""" Simple dictionary interface for setting datafields values by their names."""
return self.setField(name).setValue(val)
class DataForm(Node):
""" DataForm class. Used for manipulating dataforms in XMPP.
Relevant XEPs: 0004, 0068, 0122.
Can be used in disco, pub-sub and many other applications."""
def __init__(self, typ=None, data=[], title=None, node=None):
"""
Create new dataform of type 'typ'; 'data' is the list of DataReported,
DataItem and DataField instances that this dataform contains; 'title'
is the title string.
You can specify the 'node' argument as the other node to be used as
base for constructing this dataform.
title and instructions is optional and SHOULD NOT contain newlines.
Several instructions MAY be present.
'typ' can be one of ('form' | 'submit' | 'cancel' | 'result' )
'typ' of reply iq can be ( 'result' | 'set' | 'set' | 'result' ) respectively.
'cancel' form can not contain any fields. All other forms contains AT LEAST one field.
'title' MAY be included in forms of type "form" and "result"
"""
Node.__init__(self,'x',node=node)
if node:
newkids=[]
for n in self.getChildren():
if n.getName()=='field': newkids.append(DataField(node=n))
elif n.getName()=='item': newkids.append(DataItem(node=n))
elif n.getName()=='reported': newkids.append(DataReported(node=n))
else: newkids.append(n)
self.kids=newkids
if typ: self.setType(typ)
self.setNamespace(NS_DATA)
if title: self.setTitle(title)
if type(data)==type({}):
newdata=[]
for name in data.keys(): newdata.append(DataField(name,data[name]))
data=newdata
for child in data:
if type(child) in [type(''),type(u'')]: self.addInstructions(child)
elif child.__class__.__name__=='DataField': self.kids.append(child)
elif child.__class__.__name__=='DataItem': self.kids.append(child)
elif child.__class__.__name__=='DataReported': self.kids.append(child)
else: self.kids.append(DataField(node=child))
def getType(self):
""" Return the type of dataform. """
return self.getAttr('type')
def setType(self,typ):
""" Set the type of dataform. """
self.setAttr('type',typ)
def getTitle(self):
""" Return the title of dataform. """
return self.getTagData('title')
def setTitle(self,text):
""" Set the title of dataform. """
self.setTagData('title',text)
def getInstructions(self):
""" Return the instructions of dataform. """
return self.getTagData('instructions')
def setInstructions(self,text):
""" Set the instructions of dataform. """
self.setTagData('instructions',text)
def addInstructions(self,text):
""" Add one more instruction to the dataform. """
self.addChild('instructions',{},[text])
def getField(self,name):
""" Return the datafield object with name 'name' (if exists). """
return self.getTag('field',attrs={'var':name})
def setField(self,name):
""" Create if nessessary or get the existing datafield object with name 'name' and return it. """
f=self.getField(name)
if f: return f
return self.addChild(node=DataField(name))
def asDict(self):
""" Represent dataform as simple dictionary mapping of datafield names to their values."""
ret={}
for field in self.getTags('field'):
name=field.getAttr('var')
typ=field.getType()
if isinstance(typ,(str,unicode)) and typ[-6:]=='-multi':
val=[]
for i in field.getTags('value'): val.append(i.getData())
else: val=field.getTagData('value')
ret[name]=val
if self.getTag('instructions'): ret['instructions']=self.getInstructions()
return ret
def __getitem__(self,name):
""" Simple dictionary interface for getting datafields values by their names."""
item=self.getField(name)
if item: return item.getValue()
raise IndexError('No such field')
def __setitem__(self,name,val):
""" Simple dictionary interface for setting datafields values by their names."""
return self.setField(name).setValue(val)
|
gpl-3.0
|
[
309,
257,
4113,
14,
647,
221,
199,
309,
199,
309,
257,
1898,
334,
35,
9,
13004,
13,
9397,
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,
4113,
14,
647,
12,
86,
413,
14,
2259,
8937,
15,
966,
15,
1780,
4119,
26,
1079,
26,
1651,
6895,
12630,
85,
7910,
2672,
199,
199,
624,
199,
3658,
859,
3509,
7249,
626,
365,
4346,
367,
6661,
402,
221,
199,
26608,
13,
2407,
666,
13955,
14,
199,
624,
199,
199,
504,
3486,
1652,
492,
5013,
12,
11409,
199,
646,
900,
199,
2709,
63,
20425,
1922,
260,
275,
7,
1014,
921,
25075,
14,
1308,
15,
3922,
15,
8240,
7,
8295,
327,
1323,
6102,
13,
614,
2036,
199,
2709,
63,
12368,
3515,
275,
7,
1014,
921,
25075,
14,
1308,
15,
3922,
15,
1562,
7,
7861,
327,
1323,
6102,
13,
31152,
199,
2709,
63,
14288,
3322,
275,
7,
1014,
921,
25075,
14,
1308,
15,
3922,
15,
2113,
7,
9326,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
9732,
63,
3791,
5185,
275,
2709,
63,
14288,
4786,
3,
525,
13,
751,
7,
9668,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
7014,
63,
3791,
3322,
275,
2709,
63,
14288,
4786,
3,
1807,
13,
751,
7,
8540,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
13052,
63,
3791,
3698,
275,
2709,
63,
14288,
4786,
3,
5993,
13,
751,
7,
7861,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
907,
8898,
63,
3791,
3515,
275,
2709,
63,
14288,
4786,
3,
3441,
461,
13,
751,
7,
8295,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
3902,
63,
3791,
63,
12763,
755,
275,
2709,
63,
14288,
4786,
3,
500,
13,
751,
13,
1730,
7,
5185,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
2970,
63,
3791,
63,
9032,
420,
275,
2709,
63,
14288,
4786,
3,
362,
13,
751,
13,
2060,
7,
4519,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
16062,
63,
3791,
63,
9032,
257,
275,
2709,
63,
14288,
4786,
3,
1461,
13,
751,
13,
2060,
7,
3698,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
2970,
63,
3791,
63,
1092,
14471,
263,
275,
2709,
63,
14288,
4786,
3,
362,
13,
751,
13,
4796,
351,
7,
4483,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
2970,
63,
3791,
63,
16901,
17208,
258,
275,
2709,
63,
14288,
4786,
3,
362,
13,
751,
13,
2019,
2886,
7,
3777,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
3791,
63,
19202,
3777,
275,
2709,
63,
14288,
4786,
3,
751,
13,
3200,
7,
9326,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
17929,
63,
23113,
4924,
260,
275,
2709,
63,
14288,
4786,
3,
3773,
13,
22126,
7,
463,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
17929,
63,
18817,
4924,
260,
275,
2709,
63,
14288,
4786,
3,
3773,
13,
14189,
7,
463,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
23986,
1149,
63,
28164,
63,
7125,
257,
275,
2709,
63,
14288,
4786,
3,
362,
13,
11616,
13,
3707,
13,
1507,
7,
755,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
16205,
63,
28164,
63,
7125,
258,
275,
2709,
63,
14288,
4786,
3,
362,
13,
7011,
13,
3707,
13,
1507,
7,
260,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
615,
6174,
63,
28164,
63,
7125,
755,
275,
2709,
63,
14288,
4786,
3,
362,
13,
15178,
13,
3707,
13,
1507,
7,
3698,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
10401,
63,
28164,
63,
7125,
755,
275,
2709,
63,
14288,
4786,
3,
362,
13,
2682,
13,
3707,
13,
1507,
7,
3698,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
23715,
63,
28164,
63,
7125,
260,
275,
2709,
63,
14288,
4786,
3,
362,
13,
12000,
13,
3707,
13,
1507,
7,
3777,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
23986,
1149,
63,
28164,
63,
4924,
221,
275,
2709,
63,
14288,
4786,
3,
362,
13,
11616,
13,
3707,
13,
513,
7,
420,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
16205,
63,
28164,
63,
4924,
259,
275,
2709,
63,
14288,
4786,
3,
362,
13,
7011,
13,
3707,
13,
513,
7,
263,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
615,
6174,
63,
28164,
63,
4924,
420,
275,
2709,
63,
14288,
4786,
3,
362,
13,
15178,
13,
3707,
13,
513,
7,
3515,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
10401,
63,
28164,
63,
4924,
420,
275,
2709,
63,
14288,
4786,
3,
362,
13,
2682,
13,
3707,
13,
513,
7,
3515,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
23715,
63,
28164,
63,
4924,
263,
275,
2709,
63,
14288,
4786,
3,
362,
13,
12000,
13,
3707,
13,
513,
7,
3322,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
879,
2826,
1734,
2089,
5185,
275,
2709,
63,
14288,
4786,
3,
17803,
7,
9668,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
3597,
63,
27235,
36,
5185,
275,
2709,
63,
14288,
4786,
3,
409,
13,
30034,
68,
7,
9668,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
17929,
63,
27235,
36,
4519,
275,
2709,
63,
14288,
4786,
3,
3773,
13,
30034,
68,
7,
10473,
327
] |
[
257,
4113,
14,
647,
221,
199,
309,
199,
309,
257,
1898,
334,
35,
9,
13004,
13,
9397,
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,
4113,
14,
647,
12,
86,
413,
14,
2259,
8937,
15,
966,
15,
1780,
4119,
26,
1079,
26,
1651,
6895,
12630,
85,
7910,
2672,
199,
199,
624,
199,
3658,
859,
3509,
7249,
626,
365,
4346,
367,
6661,
402,
221,
199,
26608,
13,
2407,
666,
13955,
14,
199,
624,
199,
199,
504,
3486,
1652,
492,
5013,
12,
11409,
199,
646,
900,
199,
2709,
63,
20425,
1922,
260,
275,
7,
1014,
921,
25075,
14,
1308,
15,
3922,
15,
8240,
7,
8295,
327,
1323,
6102,
13,
614,
2036,
199,
2709,
63,
12368,
3515,
275,
7,
1014,
921,
25075,
14,
1308,
15,
3922,
15,
1562,
7,
7861,
327,
1323,
6102,
13,
31152,
199,
2709,
63,
14288,
3322,
275,
7,
1014,
921,
25075,
14,
1308,
15,
3922,
15,
2113,
7,
9326,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
9732,
63,
3791,
5185,
275,
2709,
63,
14288,
4786,
3,
525,
13,
751,
7,
9668,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
7014,
63,
3791,
3322,
275,
2709,
63,
14288,
4786,
3,
1807,
13,
751,
7,
8540,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
13052,
63,
3791,
3698,
275,
2709,
63,
14288,
4786,
3,
5993,
13,
751,
7,
7861,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
907,
8898,
63,
3791,
3515,
275,
2709,
63,
14288,
4786,
3,
3441,
461,
13,
751,
7,
8295,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
3902,
63,
3791,
63,
12763,
755,
275,
2709,
63,
14288,
4786,
3,
500,
13,
751,
13,
1730,
7,
5185,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
2970,
63,
3791,
63,
9032,
420,
275,
2709,
63,
14288,
4786,
3,
362,
13,
751,
13,
2060,
7,
4519,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
16062,
63,
3791,
63,
9032,
257,
275,
2709,
63,
14288,
4786,
3,
1461,
13,
751,
13,
2060,
7,
3698,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
2970,
63,
3791,
63,
1092,
14471,
263,
275,
2709,
63,
14288,
4786,
3,
362,
13,
751,
13,
4796,
351,
7,
4483,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
2970,
63,
3791,
63,
16901,
17208,
258,
275,
2709,
63,
14288,
4786,
3,
362,
13,
751,
13,
2019,
2886,
7,
3777,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
3791,
63,
19202,
3777,
275,
2709,
63,
14288,
4786,
3,
751,
13,
3200,
7,
9326,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
17929,
63,
23113,
4924,
260,
275,
2709,
63,
14288,
4786,
3,
3773,
13,
22126,
7,
463,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
17929,
63,
18817,
4924,
260,
275,
2709,
63,
14288,
4786,
3,
3773,
13,
14189,
7,
463,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
23986,
1149,
63,
28164,
63,
7125,
257,
275,
2709,
63,
14288,
4786,
3,
362,
13,
11616,
13,
3707,
13,
1507,
7,
755,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
16205,
63,
28164,
63,
7125,
258,
275,
2709,
63,
14288,
4786,
3,
362,
13,
7011,
13,
3707,
13,
1507,
7,
260,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
615,
6174,
63,
28164,
63,
7125,
755,
275,
2709,
63,
14288,
4786,
3,
362,
13,
15178,
13,
3707,
13,
1507,
7,
3698,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
10401,
63,
28164,
63,
7125,
755,
275,
2709,
63,
14288,
4786,
3,
362,
13,
2682,
13,
3707,
13,
1507,
7,
3698,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
23715,
63,
28164,
63,
7125,
260,
275,
2709,
63,
14288,
4786,
3,
362,
13,
12000,
13,
3707,
13,
1507,
7,
3777,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
23986,
1149,
63,
28164,
63,
4924,
221,
275,
2709,
63,
14288,
4786,
3,
362,
13,
11616,
13,
3707,
13,
513,
7,
420,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
16205,
63,
28164,
63,
4924,
259,
275,
2709,
63,
14288,
4786,
3,
362,
13,
7011,
13,
3707,
13,
513,
7,
263,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
615,
6174,
63,
28164,
63,
4924,
420,
275,
2709,
63,
14288,
4786,
3,
362,
13,
15178,
13,
3707,
13,
513,
7,
3515,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
10401,
63,
28164,
63,
4924,
420,
275,
2709,
63,
14288,
4786,
3,
362,
13,
2682,
13,
3707,
13,
513,
7,
3515,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
23715,
63,
28164,
63,
4924,
263,
275,
2709,
63,
14288,
4786,
3,
362,
13,
12000,
13,
3707,
13,
513,
7,
3322,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
879,
2826,
1734,
2089,
5185,
275,
2709,
63,
14288,
4786,
3,
17803,
7,
9668,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
3597,
63,
27235,
36,
5185,
275,
2709,
63,
14288,
4786,
3,
409,
13,
30034,
68,
7,
9668,
327,
1323,
6102,
13,
614,
1153,
199,
2709,
63,
14288,
63,
17929,
63,
27235,
36,
4519,
275,
2709,
63,
14288,
4786,
3,
3773,
13,
30034,
68,
7,
10473,
327,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ewandor/home-assistant
|
homeassistant/components/cover/lutron_caseta.py
|
8
|
2336
|
"""
Support for Lutron Caseta shades.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/cover.lutron_caseta/
"""
import asyncio
import logging
from homeassistant.components.cover import (
CoverDevice, SUPPORT_OPEN, SUPPORT_CLOSE, SUPPORT_SET_POSITION,
ATTR_POSITION, DOMAIN)
from homeassistant.components.lutron_caseta import (
LUTRON_CASETA_SMARTBRIDGE, LutronCasetaDevice)
_LOGGER = logging.getLogger(__name__)
DEPENDENCIES = ['lutron_caseta']
# pylint: disable=unused-argument
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
"""Set up the Lutron Caseta shades as a cover device."""
devs = []
bridge = hass.data[LUTRON_CASETA_SMARTBRIDGE]
cover_devices = bridge.get_devices_by_domain(DOMAIN)
for cover_device in cover_devices:
dev = LutronCasetaCover(cover_device, bridge)
devs.append(dev)
async_add_devices(devs, True)
class LutronCasetaCover(LutronCasetaDevice, CoverDevice):
"""Representation of a Lutron shade."""
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION
@property
def is_closed(self):
"""Return if the cover is closed."""
return self._state['current_state'] < 1
@property
def current_cover_position(self):
"""Return the current position of cover."""
return self._state['current_state']
@asyncio.coroutine
def async_close_cover(self, **kwargs):
"""Close the cover."""
self._smartbridge.set_value(self._device_id, 0)
@asyncio.coroutine
def async_open_cover(self, **kwargs):
"""Open the cover."""
self._smartbridge.set_value(self._device_id, 100)
@asyncio.coroutine
def async_set_cover_position(self, **kwargs):
"""Move the shade to a specific position."""
if ATTR_POSITION in kwargs:
position = kwargs[ATTR_POSITION]
self._smartbridge.set_value(self._device_id, position)
@asyncio.coroutine
def async_update(self):
"""Call when forcing a refresh of the device."""
self._state = self._smartbridge.get_device_by_id(self._device_id)
_LOGGER.debug(self._state)
|
apache-2.0
|
[
624,
199,
11532,
367,
491,
5373,
8790,
409,
65,
7793,
3424,
14,
199,
199,
1858,
1655,
2436,
3595,
642,
4298,
12,
8749,
10618,
370,
314,
3794,
737,
199,
2859,
921,
4219,
13,
7310,
14,
2308,
15,
4608,
15,
5899,
14,
76,
5373,
63,
696,
409,
65,
15,
199,
624,
199,
646,
16195,
199,
646,
2050,
199,
199,
504,
8846,
14,
4608,
14,
5899,
492,
334,
272,
1849,
422,
2510,
12,
13756,
63,
9935,
12,
13756,
63,
18219,
12,
13756,
63,
3597,
63,
15717,
12,
272,
10762,
63,
15717,
12,
15265,
9,
199,
504,
8846,
14,
4608,
14,
76,
5373,
63,
696,
409,
65,
492,
334,
272,
491,
934,
12758,
63,
9777,
15808,
63,
4029,
2294,
7184,
998,
4962,
12,
491,
5373,
3630,
409,
65,
2510,
9,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
25743,
9415,
2563,
275,
788,
76,
5373,
63,
696,
409,
65,
418,
421,
199,
3,
4287,
26,
3507,
29,
8618,
13,
2094,
199,
32,
19343,
14,
16675,
199,
318,
5316,
63,
2758,
63,
3246,
8,
5387,
12,
1101,
12,
5316,
63,
525,
63,
6410,
12,
13172,
63,
815,
29,
403,
304,
272,
408,
1084,
1536,
314,
491,
5373,
8790,
409,
65,
7793,
3424,
465,
282,
8486,
2243,
1041,
272,
477,
3122,
275,
942,
272,
13928,
275,
6298,
14,
576,
59,
44,
934,
12758,
63,
9777,
15808,
63,
4029,
2294,
7184,
998,
4962,
61,
272,
8486,
63,
6410,
275,
13928,
14,
362,
63,
6410,
63,
991,
63,
2261,
8,
7378,
9,
272,
367,
8486,
63,
1782,
315,
8486,
63,
6410,
26,
267,
4866,
275,
491,
5373,
3630,
409,
65,
31048,
8,
5899,
63,
1782,
12,
13928,
9,
267,
477,
3122,
14,
740,
8,
2374,
9,
339,
5316,
63,
525,
63,
6410,
8,
18804,
12,
715,
9,
421,
199,
533,
491,
5373,
3630,
409,
65,
31048,
8,
44,
5373,
3630,
409,
65,
2510,
12,
1849,
422,
2510,
304,
272,
408,
20609,
402,
282,
491,
5373,
32250,
1041,
339,
768,
1829,
272,
347,
3748,
63,
3179,
8,
277,
304,
267,
408,
5318,
3748,
4534,
1041,
267,
372,
13756,
63,
9935,
1204,
13756,
63,
18219,
1204,
13756,
63,
3597,
63,
15717,
339,
768,
1829,
272,
347,
365,
63,
5938,
8,
277,
304,
267,
408,
1767,
340,
314,
8486,
365,
6876,
1041,
267,
372,
291,
423,
929,
459,
1818,
63,
929,
418,
665,
413,
339,
768,
1829,
272,
347,
1453,
63,
5899,
63,
3124,
8,
277,
304,
267,
408,
1767,
314,
1453,
3421,
402,
8486,
1041,
267,
372,
291,
423,
929,
459,
1818,
63,
929,
418,
339,
768,
19343,
14,
16675,
272,
347,
5316,
63,
1600,
63,
5899,
8,
277,
12,
1011,
958,
304,
267,
408,
4724,
314,
8486,
1041,
267,
291,
423,
7853,
9528,
14,
409,
63,
585,
8,
277,
423,
1782,
63,
344,
12,
378,
9,
339,
768,
19343,
14,
16675,
272,
347,
5316,
63,
1490,
63,
5899,
8,
277,
12,
1011,
958,
304,
267,
408,
4299,
314,
8486,
1041,
267,
291,
423,
7853,
9528,
14,
409,
63,
585,
8,
277,
423,
1782,
63,
344,
12,
2948,
9,
339,
768,
19343,
14,
16675,
272,
347,
5316,
63,
409,
63,
5899,
63,
3124,
8,
277,
12,
1011,
958,
304,
267,
408,
10370,
314,
32250,
370,
282,
2488,
3421,
1041,
267,
340,
10762,
63,
15717,
315,
2074,
26,
288,
3421,
275,
2074,
59,
5280,
63,
15717,
61,
288,
291,
423,
7853,
9528,
14,
409,
63,
585,
8,
277,
423,
1782,
63,
344,
12,
3421,
9,
339,
768,
19343,
14,
16675,
272,
347,
5316,
63,
873,
8,
277,
304,
267,
408,
2176,
1380,
31070,
282,
9236,
402,
314,
2243,
1041,
267,
291,
423,
929,
275,
291,
423,
7853,
9528,
14,
362,
63,
1782,
63,
991,
63,
344,
8,
277,
423,
1782,
63,
344,
9,
267,
485,
10186,
14,
1757,
8,
277,
423,
929,
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
] |
[
199,
11532,
367,
491,
5373,
8790,
409,
65,
7793,
3424,
14,
199,
199,
1858,
1655,
2436,
3595,
642,
4298,
12,
8749,
10618,
370,
314,
3794,
737,
199,
2859,
921,
4219,
13,
7310,
14,
2308,
15,
4608,
15,
5899,
14,
76,
5373,
63,
696,
409,
65,
15,
199,
624,
199,
646,
16195,
199,
646,
2050,
199,
199,
504,
8846,
14,
4608,
14,
5899,
492,
334,
272,
1849,
422,
2510,
12,
13756,
63,
9935,
12,
13756,
63,
18219,
12,
13756,
63,
3597,
63,
15717,
12,
272,
10762,
63,
15717,
12,
15265,
9,
199,
504,
8846,
14,
4608,
14,
76,
5373,
63,
696,
409,
65,
492,
334,
272,
491,
934,
12758,
63,
9777,
15808,
63,
4029,
2294,
7184,
998,
4962,
12,
491,
5373,
3630,
409,
65,
2510,
9,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
25743,
9415,
2563,
275,
788,
76,
5373,
63,
696,
409,
65,
418,
421,
199,
3,
4287,
26,
3507,
29,
8618,
13,
2094,
199,
32,
19343,
14,
16675,
199,
318,
5316,
63,
2758,
63,
3246,
8,
5387,
12,
1101,
12,
5316,
63,
525,
63,
6410,
12,
13172,
63,
815,
29,
403,
304,
272,
408,
1084,
1536,
314,
491,
5373,
8790,
409,
65,
7793,
3424,
465,
282,
8486,
2243,
1041,
272,
477,
3122,
275,
942,
272,
13928,
275,
6298,
14,
576,
59,
44,
934,
12758,
63,
9777,
15808,
63,
4029,
2294,
7184,
998,
4962,
61,
272,
8486,
63,
6410,
275,
13928,
14,
362,
63,
6410,
63,
991,
63,
2261,
8,
7378,
9,
272,
367,
8486,
63,
1782,
315,
8486,
63,
6410,
26,
267,
4866,
275,
491,
5373,
3630,
409,
65,
31048,
8,
5899,
63,
1782,
12,
13928,
9,
267,
477,
3122,
14,
740,
8,
2374,
9,
339,
5316,
63,
525,
63,
6410,
8,
18804,
12,
715,
9,
421,
199,
533,
491,
5373,
3630,
409,
65,
31048,
8,
44,
5373,
3630,
409,
65,
2510,
12,
1849,
422,
2510,
304,
272,
408,
20609,
402,
282,
491,
5373,
32250,
1041,
339,
768,
1829,
272,
347,
3748,
63,
3179,
8,
277,
304,
267,
408,
5318,
3748,
4534,
1041,
267,
372,
13756,
63,
9935,
1204,
13756,
63,
18219,
1204,
13756,
63,
3597,
63,
15717,
339,
768,
1829,
272,
347,
365,
63,
5938,
8,
277,
304,
267,
408,
1767,
340,
314,
8486,
365,
6876,
1041,
267,
372,
291,
423,
929,
459,
1818,
63,
929,
418,
665,
413,
339,
768,
1829,
272,
347,
1453,
63,
5899,
63,
3124,
8,
277,
304,
267,
408,
1767,
314,
1453,
3421,
402,
8486,
1041,
267,
372,
291,
423,
929,
459,
1818,
63,
929,
418,
339,
768,
19343,
14,
16675,
272,
347,
5316,
63,
1600,
63,
5899,
8,
277,
12,
1011,
958,
304,
267,
408,
4724,
314,
8486,
1041,
267,
291,
423,
7853,
9528,
14,
409,
63,
585,
8,
277,
423,
1782,
63,
344,
12,
378,
9,
339,
768,
19343,
14,
16675,
272,
347,
5316,
63,
1490,
63,
5899,
8,
277,
12,
1011,
958,
304,
267,
408,
4299,
314,
8486,
1041,
267,
291,
423,
7853,
9528,
14,
409,
63,
585,
8,
277,
423,
1782,
63,
344,
12,
2948,
9,
339,
768,
19343,
14,
16675,
272,
347,
5316,
63,
409,
63,
5899,
63,
3124,
8,
277,
12,
1011,
958,
304,
267,
408,
10370,
314,
32250,
370,
282,
2488,
3421,
1041,
267,
340,
10762,
63,
15717,
315,
2074,
26,
288,
3421,
275,
2074,
59,
5280,
63,
15717,
61,
288,
291,
423,
7853,
9528,
14,
409,
63,
585,
8,
277,
423,
1782,
63,
344,
12,
3421,
9,
339,
768,
19343,
14,
16675,
272,
347,
5316,
63,
873,
8,
277,
304,
267,
408,
2176,
1380,
31070,
282,
9236,
402,
314,
2243,
1041,
267,
291,
423,
929,
275,
291,
423,
7853,
9528,
14,
362,
63,
1782,
63,
991,
63,
344,
8,
277,
423,
1782,
63,
344,
9,
267,
485,
10186,
14,
1757,
8,
277,
423,
929,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
40223205/w16b_test-
|
static/Brython3.1.3-20150514-095342/Lib/site-packages/pygame/locals.py
|
603
|
1141
|
## pygame - Python Game Library
## Copyright (C) 2000-2003 Pete Shinners
##
## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Library General Public
## License as published by the Free Software Foundation; either
## version 2 of the License, or (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## Library General Public License for more details.
##
## You should have received a copy of the GNU Library General Public
## License along with this library; if not, write to the Free
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
## Pete Shinners
## pete@shinners.org
"""Set of functions from PyGame that are handy to have in
the local namespace for your module"""
from pygame.constants import *
from pygame.rect import Rect
import pygame.color as color
Color = color.Color
|
agpl-3.0
|
[
309,
259,
9193,
446,
2018,
25132,
11243,
221,
199,
309,
259,
1898,
334,
35,
9,
12293,
13,
17919,
221,
11379,
266,
5244,
262,
8715,
221,
199,
309,
221,
199,
309,
259,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
221,
199,
309,
259,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
11243,
1696,
1684,
221,
199,
309,
259,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
221,
199,
309,
259,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
221,
199,
309,
221,
199,
309,
259,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
221,
199,
309,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
221,
199,
309,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
221,
199,
309,
259,
11243,
1696,
1684,
844,
367,
1655,
2436,
14,
221,
199,
309,
221,
199,
309,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
11243,
1696,
1684,
221,
199,
309,
259,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
221,
199,
309,
259,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
221,
199,
309,
221,
199,
309,
259,
11379,
266,
5244,
262,
8715,
221,
199,
309,
259,
4837,
266,
32,
609,
262,
8715,
14,
1308,
5591,
272,
272,
199,
624,
1084,
402,
3423,
687,
1611,
11454,
626,
787,
4926,
89,
370,
1172,
315,
5591,
314,
2257,
3231,
367,
2195,
859,
624,
5591,
199,
504,
9193,
14,
5559,
492,
627,
221,
199,
504,
9193,
14,
1201,
492,
21536,
221,
199,
646,
9193,
14,
2326,
465,
3164,
221,
199,
4117,
275,
3164,
14,
4117,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
259,
9193,
446,
2018,
25132,
11243,
221,
199,
309,
259,
1898,
334,
35,
9,
12293,
13,
17919,
221,
11379,
266,
5244,
262,
8715,
221,
199,
309,
221,
199,
309,
259,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
221,
199,
309,
259,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
11243,
1696,
1684,
221,
199,
309,
259,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
221,
199,
309,
259,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
221,
199,
309,
221,
199,
309,
259,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
221,
199,
309,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
221,
199,
309,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
221,
199,
309,
259,
11243,
1696,
1684,
844,
367,
1655,
2436,
14,
221,
199,
309,
221,
199,
309,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
11243,
1696,
1684,
221,
199,
309,
259,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
221,
199,
309,
259,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
221,
199,
309,
221,
199,
309,
259,
11379,
266,
5244,
262,
8715,
221,
199,
309,
259,
4837,
266,
32,
609,
262,
8715,
14,
1308,
5591,
272,
272,
199,
624,
1084,
402,
3423,
687,
1611,
11454,
626,
787,
4926,
89,
370,
1172,
315,
5591,
314,
2257,
3231,
367,
2195,
859,
624,
5591,
199,
504,
9193,
14,
5559,
492,
627,
221,
199,
504,
9193,
14,
1201,
492,
21536,
221,
199,
646,
9193,
14,
2326,
465,
3164,
221,
199,
4117,
275,
3164,
14,
4117,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
kismatic/kubernetes
|
build/json-extractor.py
|
62
|
2091
|
#!/usr/bin/env python
# Copyright 2014 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This is a very simple utility that reads a JSON document from stdin, parses it
# and returns the specified value. The value is described using a simple dot
# notation. If any errors are encountered along the way, an error is output and
# a failure value is returned.
from __future__ import print_function
import json
import sys
def PrintError(*err):
print(*err, file=sys.stderr)
def main():
try:
obj = json.load(sys.stdin)
except Exception, e:
PrintError("Error loading JSON: {0}".format(str(e)))
if len(sys.argv) == 1:
# if we don't have a query string, return success
return 0
elif len(sys.argv) > 2:
PrintError("Usage: {0} <json query>".format(sys.args[0]))
return 1
query_list = sys.argv[1].split('.')
for q in query_list:
if isinstance(obj, dict):
if q not in obj:
PrintError("Couldn't find '{0}' in dict".format(q))
return 1
obj = obj[q]
elif isinstance(obj, list):
try:
index = int(q)
except:
PrintError("Can't use '{0}' to index into array".format(q))
return 1
if index >= len(obj):
PrintError("Index ({0}) is greater than length of list ({1})".format(q, len(obj)))
return 1
obj = obj[index]
else:
PrintError("Trying to query non-queryable object: {0}".format(q))
return 1
if isinstance(obj, str):
print(obj)
else:
print(json.dumps(obj, indent=2))
if __name__ == "__main__":
sys.exit(main())
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6927,
710,
28723,
6642,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
3,
961,
365,
282,
7437,
3486,
11420,
626,
11597,
282,
4840,
2213,
687,
9009,
12,
19953,
652,
199,
3,
436,
2529,
314,
2013,
574,
14,
221,
710,
574,
365,
11736,
1808,
282,
3486,
6308,
199,
3,
15843,
14,
221,
982,
1263,
2552,
787,
14556,
3180,
314,
4340,
12,
376,
1125,
365,
1072,
436,
199,
3,
282,
5988,
574,
365,
2138,
14,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2022,
199,
646,
984,
199,
199,
318,
9101,
547,
2031,
1508,
304,
523,
870,
2031,
1508,
12,
570,
29,
1274,
14,
3083,
9,
199,
199,
318,
2446,
837,
523,
862,
26,
272,
1559,
275,
2022,
14,
912,
8,
1274,
14,
6626,
9,
523,
871,
2186,
12,
325,
26,
272,
9101,
547,
480,
547,
8697,
4840,
26,
469,
16,
5469,
908,
8,
495,
8,
69,
1724,
819,
340,
822,
8,
1274,
14,
3020,
9,
508,
413,
26,
272,
327,
340,
781,
2793,
1133,
1172,
282,
1827,
1059,
12,
372,
3182,
272,
372,
378,
523,
916,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
272,
9101,
547,
480,
7692,
26,
469,
16,
93,
665,
1001,
1827,
23167,
908,
8,
1274,
14,
589,
59,
16,
2459,
272,
372,
413,
819,
1827,
63,
513,
275,
984,
14,
3020,
59,
17,
1055,
1294,
7563,
523,
367,
1894,
315,
1827,
63,
513,
26,
272,
340,
1228,
8,
1113,
12,
1211,
304,
489,
340,
1894,
440,
315,
1559,
26,
267,
9101,
547,
480,
20485,
1133,
2342,
5041,
16,
6834,
315,
1211,
1674,
908,
8,
81,
430,
267,
372,
413,
489,
1559,
275,
1559,
59,
81,
61,
272,
916,
1228,
8,
1113,
12,
769,
304,
489,
862,
26,
267,
1478,
275,
1109,
8,
81,
9,
489,
871,
26,
267,
9101,
547,
480,
6049,
1133,
675,
5041,
16,
6834,
370,
1478,
1901,
1625,
1674,
908,
8,
81,
430,
267,
372,
413,
489,
340,
1478,
2356,
822,
8,
1113,
304,
267,
9101,
547,
480,
2681,
11459,
16,
1552,
365,
8932,
2419,
2582,
402,
769,
11459,
17,
25974,
908,
8,
81,
12,
822,
8,
1113,
1724,
267,
372,
413,
489,
1559,
275,
1559,
59,
1080,
61,
272,
587,
26,
489,
9101,
547,
480,
27693,
370,
1827,
2222,
13,
1131,
461,
909,
26,
469,
16,
5469,
908,
8,
81,
430,
489,
372,
413,
819,
340,
1228,
8,
1113,
12,
620,
304,
272,
870,
8,
1113,
9,
523,
587,
26,
272,
870,
8,
1001,
14,
4180,
8,
1113,
12,
4363,
29,
18,
430,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
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,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6927,
710,
28723,
6642,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
3,
961,
365,
282,
7437,
3486,
11420,
626,
11597,
282,
4840,
2213,
687,
9009,
12,
19953,
652,
199,
3,
436,
2529,
314,
2013,
574,
14,
221,
710,
574,
365,
11736,
1808,
282,
3486,
6308,
199,
3,
15843,
14,
221,
982,
1263,
2552,
787,
14556,
3180,
314,
4340,
12,
376,
1125,
365,
1072,
436,
199,
3,
282,
5988,
574,
365,
2138,
14,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2022,
199,
646,
984,
199,
199,
318,
9101,
547,
2031,
1508,
304,
523,
870,
2031,
1508,
12,
570,
29,
1274,
14,
3083,
9,
199,
199,
318,
2446,
837,
523,
862,
26,
272,
1559,
275,
2022,
14,
912,
8,
1274,
14,
6626,
9,
523,
871,
2186,
12,
325,
26,
272,
9101,
547,
480,
547,
8697,
4840,
26,
469,
16,
5469,
908,
8,
495,
8,
69,
1724,
819,
340,
822,
8,
1274,
14,
3020,
9,
508,
413,
26,
272,
327,
340,
781,
2793,
1133,
1172,
282,
1827,
1059,
12,
372,
3182,
272,
372,
378,
523,
916,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
272,
9101,
547,
480,
7692,
26,
469,
16,
93,
665,
1001,
1827,
23167,
908,
8,
1274,
14,
589,
59,
16,
2459,
272,
372,
413,
819,
1827,
63,
513,
275,
984,
14,
3020,
59,
17,
1055,
1294,
7563,
523,
367,
1894,
315,
1827,
63,
513,
26,
272,
340,
1228,
8,
1113,
12,
1211,
304,
489,
340,
1894,
440,
315,
1559,
26,
267,
9101,
547,
480,
20485,
1133,
2342,
5041,
16,
6834,
315,
1211,
1674,
908,
8,
81,
430,
267,
372,
413,
489,
1559,
275,
1559,
59,
81,
61,
272,
916,
1228,
8,
1113,
12,
769,
304,
489,
862,
26,
267,
1478,
275,
1109,
8,
81,
9,
489,
871,
26,
267,
9101,
547,
480,
6049,
1133,
675,
5041,
16,
6834,
370,
1478,
1901,
1625,
1674,
908,
8,
81,
430,
267,
372,
413,
489,
340,
1478,
2356,
822,
8,
1113,
304,
267,
9101,
547,
480,
2681,
11459,
16,
1552,
365,
8932,
2419,
2582,
402,
769,
11459,
17,
25974,
908,
8,
81,
12,
822,
8,
1113,
1724,
267,
372,
413,
489,
1559,
275,
1559,
59,
1080,
61,
272,
587,
26,
489,
9101,
547,
480,
27693,
370,
1827,
2222,
13,
1131,
461,
909,
26,
469,
16,
5469,
908,
8,
81,
430,
489,
372,
413,
819,
340,
1228,
8,
1113,
12,
620,
304,
272,
870,
8,
1113,
9,
523,
587,
26,
272,
870,
8,
1001,
14,
4180,
8,
1113,
12,
4363,
29,
18,
430,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
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,
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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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
] |
pangwong11/jumpball
|
bd_analyze/nba_season_stats_analyzer.py
|
1
|
5069
|
#!/usr/bin/python
import numpy as np
import matplotlib.pyplot as pyplot
from datetime import datetime
import os
import glob
import sys
import re
import argparse
import cv2
import random
import ast
# Argument parsing
#parser = argparse.ArgumentParser(description='Jumpball analyze')
#parser.add_argument('-s', '--season', action='store', help='Season in year', dest="year_season", required=True)
#parser.add_argument('-n', '--next-season', action='store', help='Season in year', dest="next_year_season", required=True)
#args = parser.parse_args()
#
#season = args.year_season
#next_season = args.next_year_season
#data_directory = "./nba_data"
team_stat_path = './nba_data/*.csv'
team_stat_files = glob.glob(team_stat_path)
data_types = ['Height', 'Weight', 'WL_PERC']
num_data_types = len(data_types)
def readTeamStats(file_name):
dtypes = np.dtype({ 'names' : ('team', 'Height', 'Weight', 'WL_PERC'),
'formats' : ['S10', np.float, np.float, np.float] })
data = np.loadtxt(file_name, delimiter=',', skiprows=1,
usecols=(0,2,3,4), dtype=dtypes)
#data_list = list(data)
return data
def readTeamRecord(file_name):
dtypes = np.dtype({ 'names' : ('team', 'WL_PERC'),
'formats' : ['S10', np.float] })
data = np.loadtxt(file_name, delimiter=',', skiprows=1,
usecols=(0,3), dtype=dtypes)
return data
# Iterate through each NBA team stats file and output find the mean for each teams weight and height
def analyzeTeamStats(season):
data_set=[]
team_labels_set = []
data_directory = ("/Users/aidan.wong/Documents/mystuff/cs454/jumpball/bd_collect/nba_data/%s/" % season)
for root, dirs, files in os.walk(data_directory):
for f in files:
if f.endswith("agg_data.csv"):
teamStats = readTeamStats(data_directory + f)
teamStats_list = zip(*teamStats)
team = teamStats_list[0][0]
ht_mean = np.array(teamStats_list[1], dtype=float).mean()
wt_mean = np.array(teamStats_list[2], dtype=float).mean()
wl_perc = teamStats_list[3][0]
data = [ht_mean, wt_mean,wl_perc]
data_set.append(data)
team_labels_set.append(team)
#print data_set
#print "--------------"
return data_set,team_labels_set
season = "2011"
next_year_season = "2012"
trainData_1, teamData_1 = analyzeTeamStats(season)
trainData_2, teamData_2 = analyzeTeamStats(next_year_season)
#print trainData_2
#print trainData_2[3]
print "------------------------"
print teamData_1
print teamData_2
#print teamData_2[3]
# This variable is to defined the new sample team to run K-NN with and the number should range from 0 to 30
new_team_index = 3
trainData_array = np.array(trainData_1).astype(np.float32)
newData_array = np.array(trainData_2)
#print trainData_array
#print newData_array
#print newData_array[0]
#print trainData_array
labels = np.array(np.arange(30))
#print labels
#labels = array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29])
for label, x, y in zip(teamData_1,trainData_array[:,0],trainData_array[:,1]):
pyplot.annotate(label,xy =(x,y), xytext=(-20,20),textcoords = 'offset points',
ha ='right', va = 'bottom',bbox = dict(boxstyle = 'round,pad=0.5', fc = 'yellow',
alpha = 0.5),arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))
for i in range(0,30):
r = lambda: random.randint(0,255)
color = '#%02X%02X%02X' % (r(),r(),r())
team_data = trainData_array[labels.ravel()==i]
pyplot.scatter(team_data[:,0],team_data[:,1],marker = 'o',s = team_data[:,2]*4500,c = color,cmap = pyplot.get_cmap('Spectral'))
#print newData_array[labels.ravel()==1]
#for i in range(1,2):
new_team_data = newData_array[labels.ravel()==new_team_index]
print "new_team_data =", new_team_data
pyplot.scatter(new_team_data[:,0],new_team_data[:,1],marker = '^',s = new_team_data[:,2]*4500,c = color,cmap = pyplot.get_cmap('Spectral'))
i = 0
for label, x, y in zip(teamData_2[:new_team_index+1],newData_array[:,0],newData_array[:,1]):
if i < new_team_index:
print i
i += 1
continue
print zip(teamData_2[:new_team_index+1],newData_array[:,0],newData_array[:,1])
print (label,x,y)
# print type(label)
pyplot.annotate(label,xy =(x,y), xytext=(-20,20),textcoords = 'offset points',
ha ='right', va = 'bottom',bbox = dict(boxstyle = 'round,pad=0.5', fc = 'blue',
alpha = 0.5),arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))
knn = cv2.KNearest()
#print trainData_array
#
#
#knn.train(trainData_array,labels)
knn.train(trainData_array,np.array(labels).astype(np.float32))
ret, results, neighbours ,dist = knn.find_nearest((new_team_data).astype(np.float32), 1)
print (ret, results, neighbours, dist)
#
print "result: ", results,"\n"
print "neighbours: ", neighbours,"\n"
print "distance: ", dist
pyplot.show()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
1134,
2798,
199,
504,
2197,
492,
2197,
199,
646,
747,
199,
646,
5739,
199,
646,
984,
221,
199,
646,
295,
199,
646,
7534,
199,
646,
6277,
18,
199,
646,
2196,
199,
646,
6073,
421,
199,
3,
5886,
6057,
199,
3,
2087,
275,
7534,
14,
10730,
8,
1802,
534,
42,
1220,
8571,
19897,
358,
199,
3,
2087,
14,
525,
63,
2094,
3654,
83,
297,
2850,
12605,
297,
1595,
534,
1617,
297,
1720,
534,
28905,
315,
5361,
297,
2053,
628,
3403,
63,
12605,
401,
1415,
29,
549,
9,
199,
3,
2087,
14,
525,
63,
2094,
3654,
78,
297,
2850,
2184,
13,
12605,
297,
1595,
534,
1617,
297,
1720,
534,
28905,
315,
5361,
297,
2053,
628,
2184,
63,
3403,
63,
12605,
401,
1415,
29,
549,
9,
199,
3,
589,
275,
1798,
14,
1122,
63,
589,
342,
199,
3,
199,
3,
12605,
275,
1249,
14,
3403,
63,
12605,
199,
3,
2184,
63,
12605,
275,
1249,
14,
2184,
63,
3403,
63,
12605,
199,
199,
3,
576,
63,
3619,
275,
26069,
78,
2470,
63,
576,
2,
199,
5969,
63,
3736,
63,
515,
275,
21526,
78,
2470,
63,
576,
20362,
4737,
7,
199,
5969,
63,
3736,
63,
1725,
275,
5739,
14,
6463,
8,
5969,
63,
3736,
63,
515,
9,
199,
199,
576,
63,
1313,
275,
788,
8436,
297,
283,
16359,
297,
283,
55,
44,
63,
4227,
35,
418,
199,
1507,
63,
576,
63,
1313,
275,
822,
8,
576,
63,
1313,
9,
199,
199,
318,
1586,
13126,
8257,
8,
493,
63,
354,
304,
272,
6674,
275,
980,
14,
2271,
2561,
283,
1247,
7,
520,
661,
5969,
297,
283,
8436,
297,
283,
16359,
297,
283,
55,
44,
63,
4227,
35,
659,
717,
283,
6321,
7,
520,
788,
51,
709,
297,
980,
14,
1609,
12,
980,
14,
1609,
12,
980,
14,
1609,
61,
3828,
339,
666,
275,
980,
14,
27992,
8,
493,
63,
354,
12,
11172,
4009,
297,
2386,
73,
496,
3569,
29,
17,
12,
1779,
675,
4574,
2687,
16,
12,
18,
12,
19,
12,
20,
395,
2152,
29,
5717,
9,
339,
327,
576,
63,
513,
275,
769,
8,
576,
9,
339,
372,
666,
421,
199,
318,
1586,
13126,
5433,
8,
493,
63,
354,
304,
272,
6674,
275,
980,
14,
2271,
2561,
283,
1247,
7,
520,
661,
5969,
297,
283,
55,
44,
63,
4227,
35,
659,
717,
283,
6321,
7,
520,
788,
51,
709,
297,
980,
14,
1609,
61,
3828,
339,
666,
275,
980,
14,
27992,
8,
493,
63,
354,
12,
11172,
4009,
297,
2386,
73,
496,
3569,
29,
17,
12,
1779,
675,
4574,
2687,
16,
12,
19,
395,
2152,
29,
5717,
9,
339,
372,
666,
421,
199,
3,
23989,
4012,
1924,
653,
4134,
8099,
5020,
570,
436,
1072,
2342,
314,
4615,
367,
1924,
25823,
5401,
436,
4569,
199,
318,
19897,
13126,
8257,
8,
12605,
304,
339,
666,
63,
409,
9811,
272,
8099,
63,
3512,
63,
409,
275,
942,
2286,
666,
63,
3619,
275,
1689,
15,
12117,
15,
21745,
290,
14,
87,
951,
15,
26872,
15,
1662,
14573,
15,
1259,
12383,
15,
11126,
8571,
15,
3691,
63,
7112,
15,
78,
2470,
63,
576,
3149,
83,
6687,
450,
14718,
9,
339,
367,
1738,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
576,
63,
3619,
304,
267,
367,
289,
315,
1584,
26,
288,
340,
289,
14,
4130,
480,
13452,
63,
576,
14,
4737,
2349,
355,
8099,
8257,
275,
1586,
13126,
8257,
8,
576,
63,
3619,
435,
289,
9,
14977,
8099,
8257,
63,
513,
275,
221,
3482,
2031,
5969,
8257,
9,
355,
8099,
275,
8099,
8257,
63,
513,
59,
16,
1527,
16,
61,
355,
1243,
63,
3670,
275,
980,
14,
1144,
8,
5969,
8257,
63,
513,
59,
17,
467,
2152,
29,
1609,
680,
3670,
342,
355,
24756,
63,
3670,
275,
980,
14,
1144,
8,
5969,
8257,
63,
513,
59,
18,
467,
2152,
29,
1609,
680,
3670,
342,
355,
336,
76,
63,
27293,
275,
8099,
8257,
63,
513,
59,
19,
1527,
16,
61,
1362,
355,
666,
275,
359,
517,
63,
3670,
12,
24756,
63,
3670,
12,
20159,
63,
27293,
61,
355,
666,
63,
409,
14,
740,
8,
576,
9,
355,
8099,
63,
3512,
63,
409,
14,
740,
8,
5969,
9,
272,
327,
1361,
666,
63,
409,
272,
327,
1361,
298,
10965,
2,
272,
372,
666,
63,
409,
12,
5969,
63,
3512,
63,
409,
199,
199,
12605,
275,
298,
8128,
2,
199,
2184,
63,
3403,
63,
12605,
275,
298,
7409,
2,
199,
2834,
1451,
63,
17,
12,
8099,
1451,
63,
17,
275,
19897,
13126,
8257,
8,
12605,
9,
199,
2834,
1451,
63,
18,
12,
8099,
1451,
63,
18,
275,
19897,
13126,
8257,
8,
2184,
63,
3403,
63,
12605,
9,
199,
3,
1361,
3560,
1451,
63,
18,
199,
3,
1361,
3560,
1451,
63,
18,
59,
19,
61,
199,
1361,
298,
777,
518,
2,
199,
1361,
8099,
1451,
63,
17,
199,
1361,
8099,
1451,
63,
18,
199,
3,
1361,
8099,
1451,
63,
18,
59,
19,
61,
199,
199,
3,
961,
1750,
365,
370,
3247,
314,
892,
2690,
8099,
370,
1255,
1804,
13,
7178,
543,
436,
314,
1329,
1077,
1425,
687,
378,
370,
4233,
199,
1222,
63,
5969,
63,
1080,
275,
650,
199,
2834,
1451,
63,
1144,
275,
980,
14,
1144,
8,
2834,
1451,
63,
17,
680,
6041,
8,
1590,
14,
1609,
708,
9,
199,
1222,
1451,
63,
1144,
275,
980,
14,
1144,
8,
2834,
1451,
63,
18,
9,
199,
3,
1361,
3560,
1451,
63,
1144,
199,
3,
1361,
892,
1451,
63,
1144,
199,
3,
1361,
892,
1451,
63,
1144,
59,
16,
61,
199,
199,
3,
1361,
3560,
1451,
63,
1144,
199,
199,
3512,
275,
980,
14,
1144,
8,
1590,
14,
5605,
8,
1216,
430,
199,
3,
1361,
3628,
199,
3,
3512,
275,
1625,
779,
16,
12,
413,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
12,
1520,
12,
1695,
12,
1749,
12,
1616,
12,
4119,
12,
3144,
12,
4944,
12,
4329,
12,
4114,
12,
3193,
12,
5557,
12,
6155,
12,
5851,
12,
3388,
12,
7829,
12,
6928,
12,
6546,
12,
5504,
12,
5661,
12,
7875,
12,
8087,
12,
7294,
12,
7349,
566,
199,
199,
509,
1768,
12,
671,
12,
612,
315,
3482,
8,
5969,
1451,
63,
17,
12,
2834,
1451
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
1134,
2798,
199,
504,
2197,
492,
2197,
199,
646,
747,
199,
646,
5739,
199,
646,
984,
221,
199,
646,
295,
199,
646,
7534,
199,
646,
6277,
18,
199,
646,
2196,
199,
646,
6073,
421,
199,
3,
5886,
6057,
199,
3,
2087,
275,
7534,
14,
10730,
8,
1802,
534,
42,
1220,
8571,
19897,
358,
199,
3,
2087,
14,
525,
63,
2094,
3654,
83,
297,
2850,
12605,
297,
1595,
534,
1617,
297,
1720,
534,
28905,
315,
5361,
297,
2053,
628,
3403,
63,
12605,
401,
1415,
29,
549,
9,
199,
3,
2087,
14,
525,
63,
2094,
3654,
78,
297,
2850,
2184,
13,
12605,
297,
1595,
534,
1617,
297,
1720,
534,
28905,
315,
5361,
297,
2053,
628,
2184,
63,
3403,
63,
12605,
401,
1415,
29,
549,
9,
199,
3,
589,
275,
1798,
14,
1122,
63,
589,
342,
199,
3,
199,
3,
12605,
275,
1249,
14,
3403,
63,
12605,
199,
3,
2184,
63,
12605,
275,
1249,
14,
2184,
63,
3403,
63,
12605,
199,
199,
3,
576,
63,
3619,
275,
26069,
78,
2470,
63,
576,
2,
199,
5969,
63,
3736,
63,
515,
275,
21526,
78,
2470,
63,
576,
20362,
4737,
7,
199,
5969,
63,
3736,
63,
1725,
275,
5739,
14,
6463,
8,
5969,
63,
3736,
63,
515,
9,
199,
199,
576,
63,
1313,
275,
788,
8436,
297,
283,
16359,
297,
283,
55,
44,
63,
4227,
35,
418,
199,
1507,
63,
576,
63,
1313,
275,
822,
8,
576,
63,
1313,
9,
199,
199,
318,
1586,
13126,
8257,
8,
493,
63,
354,
304,
272,
6674,
275,
980,
14,
2271,
2561,
283,
1247,
7,
520,
661,
5969,
297,
283,
8436,
297,
283,
16359,
297,
283,
55,
44,
63,
4227,
35,
659,
717,
283,
6321,
7,
520,
788,
51,
709,
297,
980,
14,
1609,
12,
980,
14,
1609,
12,
980,
14,
1609,
61,
3828,
339,
666,
275,
980,
14,
27992,
8,
493,
63,
354,
12,
11172,
4009,
297,
2386,
73,
496,
3569,
29,
17,
12,
1779,
675,
4574,
2687,
16,
12,
18,
12,
19,
12,
20,
395,
2152,
29,
5717,
9,
339,
327,
576,
63,
513,
275,
769,
8,
576,
9,
339,
372,
666,
421,
199,
318,
1586,
13126,
5433,
8,
493,
63,
354,
304,
272,
6674,
275,
980,
14,
2271,
2561,
283,
1247,
7,
520,
661,
5969,
297,
283,
55,
44,
63,
4227,
35,
659,
717,
283,
6321,
7,
520,
788,
51,
709,
297,
980,
14,
1609,
61,
3828,
339,
666,
275,
980,
14,
27992,
8,
493,
63,
354,
12,
11172,
4009,
297,
2386,
73,
496,
3569,
29,
17,
12,
1779,
675,
4574,
2687,
16,
12,
19,
395,
2152,
29,
5717,
9,
339,
372,
666,
421,
199,
3,
23989,
4012,
1924,
653,
4134,
8099,
5020,
570,
436,
1072,
2342,
314,
4615,
367,
1924,
25823,
5401,
436,
4569,
199,
318,
19897,
13126,
8257,
8,
12605,
304,
339,
666,
63,
409,
9811,
272,
8099,
63,
3512,
63,
409,
275,
942,
2286,
666,
63,
3619,
275,
1689,
15,
12117,
15,
21745,
290,
14,
87,
951,
15,
26872,
15,
1662,
14573,
15,
1259,
12383,
15,
11126,
8571,
15,
3691,
63,
7112,
15,
78,
2470,
63,
576,
3149,
83,
6687,
450,
14718,
9,
339,
367,
1738,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
576,
63,
3619,
304,
267,
367,
289,
315,
1584,
26,
288,
340,
289,
14,
4130,
480,
13452,
63,
576,
14,
4737,
2349,
355,
8099,
8257,
275,
1586,
13126,
8257,
8,
576,
63,
3619,
435,
289,
9,
14977,
8099,
8257,
63,
513,
275,
221,
3482,
2031,
5969,
8257,
9,
355,
8099,
275,
8099,
8257,
63,
513,
59,
16,
1527,
16,
61,
355,
1243,
63,
3670,
275,
980,
14,
1144,
8,
5969,
8257,
63,
513,
59,
17,
467,
2152,
29,
1609,
680,
3670,
342,
355,
24756,
63,
3670,
275,
980,
14,
1144,
8,
5969,
8257,
63,
513,
59,
18,
467,
2152,
29,
1609,
680,
3670,
342,
355,
336,
76,
63,
27293,
275,
8099,
8257,
63,
513,
59,
19,
1527,
16,
61,
1362,
355,
666,
275,
359,
517,
63,
3670,
12,
24756,
63,
3670,
12,
20159,
63,
27293,
61,
355,
666,
63,
409,
14,
740,
8,
576,
9,
355,
8099,
63,
3512,
63,
409,
14,
740,
8,
5969,
9,
272,
327,
1361,
666,
63,
409,
272,
327,
1361,
298,
10965,
2,
272,
372,
666,
63,
409,
12,
5969,
63,
3512,
63,
409,
199,
199,
12605,
275,
298,
8128,
2,
199,
2184,
63,
3403,
63,
12605,
275,
298,
7409,
2,
199,
2834,
1451,
63,
17,
12,
8099,
1451,
63,
17,
275,
19897,
13126,
8257,
8,
12605,
9,
199,
2834,
1451,
63,
18,
12,
8099,
1451,
63,
18,
275,
19897,
13126,
8257,
8,
2184,
63,
3403,
63,
12605,
9,
199,
3,
1361,
3560,
1451,
63,
18,
199,
3,
1361,
3560,
1451,
63,
18,
59,
19,
61,
199,
1361,
298,
777,
518,
2,
199,
1361,
8099,
1451,
63,
17,
199,
1361,
8099,
1451,
63,
18,
199,
3,
1361,
8099,
1451,
63,
18,
59,
19,
61,
199,
199,
3,
961,
1750,
365,
370,
3247,
314,
892,
2690,
8099,
370,
1255,
1804,
13,
7178,
543,
436,
314,
1329,
1077,
1425,
687,
378,
370,
4233,
199,
1222,
63,
5969,
63,
1080,
275,
650,
199,
2834,
1451,
63,
1144,
275,
980,
14,
1144,
8,
2834,
1451,
63,
17,
680,
6041,
8,
1590,
14,
1609,
708,
9,
199,
1222,
1451,
63,
1144,
275,
980,
14,
1144,
8,
2834,
1451,
63,
18,
9,
199,
3,
1361,
3560,
1451,
63,
1144,
199,
3,
1361,
892,
1451,
63,
1144,
199,
3,
1361,
892,
1451,
63,
1144,
59,
16,
61,
199,
199,
3,
1361,
3560,
1451,
63,
1144,
199,
199,
3512,
275,
980,
14,
1144,
8,
1590,
14,
5605,
8,
1216,
430,
199,
3,
1361,
3628,
199,
3,
3512,
275,
1625,
779,
16,
12,
413,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
12,
1520,
12,
1695,
12,
1749,
12,
1616,
12,
4119,
12,
3144,
12,
4944,
12,
4329,
12,
4114,
12,
3193,
12,
5557,
12,
6155,
12,
5851,
12,
3388,
12,
7829,
12,
6928,
12,
6546,
12,
5504,
12,
5661,
12,
7875,
12,
8087,
12,
7294,
12,
7349,
566,
199,
199,
509,
1768,
12,
671,
12,
612,
315,
3482,
8,
5969,
1451,
63,
17,
12,
2834,
1451,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
evamwangi/bc-7-Todo_List
|
venv/Lib/site-packages/sqlalchemy/processors.py
|
36
|
5220
|
# sqlalchemy/processors.py
# Copyright (C) 2010-2016 the SQLAlchemy authors and contributors
# <see AUTHORS file>
# Copyright (C) 2010 Gaetan de Menten gdementen@gmail.com
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
"""defines generic type conversion functions, as used in bind and result
processors.
They all share one common characteristic: None is passed through unchanged.
"""
import codecs
import re
import datetime
from . import util
def str_to_datetime_processor_factory(regexp, type_):
rmatch = regexp.match
# Even on python2.6 datetime.strptime is both slower than this code
# and it does not support microseconds.
has_named_groups = bool(regexp.groupindex)
def process(value):
if value is None:
return None
else:
try:
m = rmatch(value)
except TypeError:
raise ValueError("Couldn't parse %s string '%r' "
"- value is not a string." %
(type_.__name__, value))
if m is None:
raise ValueError("Couldn't parse %s string: "
"'%s'" % (type_.__name__, value))
if has_named_groups:
groups = m.groupdict(0)
return type_(**dict(list(zip(
iter(groups.keys()),
list(map(int, iter(groups.values())))
))))
else:
return type_(*list(map(int, m.groups(0))))
return process
def boolean_to_int(value):
if value is None:
return None
else:
return int(value)
def py_fallback():
def to_unicode_processor_factory(encoding, errors=None):
decoder = codecs.getdecoder(encoding)
def process(value):
if value is None:
return None
else:
# decoder returns a tuple: (value, len). Simply dropping the
# len part is safe: it is done that way in the normal
# 'xx'.decode(encoding) code path.
return decoder(value, errors)[0]
return process
def to_conditional_unicode_processor_factory(encoding, errors=None):
decoder = codecs.getdecoder(encoding)
def process(value):
if value is None:
return None
elif isinstance(value, util.text_type):
return value
else:
# decoder returns a tuple: (value, len). Simply dropping the
# len part is safe: it is done that way in the normal
# 'xx'.decode(encoding) code path.
return decoder(value, errors)[0]
return process
def to_decimal_processor_factory(target_class, scale):
fstring = "%%.%df" % scale
def process(value):
if value is None:
return None
else:
return target_class(fstring % value)
return process
def to_float(value):
if value is None:
return None
else:
return float(value)
def to_str(value):
if value is None:
return None
else:
return str(value)
def int_to_boolean(value):
if value is None:
return None
else:
return value and True or False
DATETIME_RE = re.compile(
"(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)(?:\.(\d+))?")
TIME_RE = re.compile("(\d+):(\d+):(\d+)(?:\.(\d+))?")
DATE_RE = re.compile("(\d+)-(\d+)-(\d+)")
str_to_datetime = str_to_datetime_processor_factory(DATETIME_RE,
datetime.datetime)
str_to_time = str_to_datetime_processor_factory(TIME_RE, datetime.time)
str_to_date = str_to_datetime_processor_factory(DATE_RE, datetime.date)
return locals()
try:
from sqlalchemy.cprocessors import UnicodeResultProcessor, \
DecimalResultProcessor, \
to_float, to_str, int_to_boolean, \
str_to_datetime, str_to_time, \
str_to_date
def to_unicode_processor_factory(encoding, errors=None):
if errors is not None:
return UnicodeResultProcessor(encoding, errors).process
else:
return UnicodeResultProcessor(encoding).process
def to_conditional_unicode_processor_factory(encoding, errors=None):
if errors is not None:
return UnicodeResultProcessor(encoding, errors).conditional_process
else:
return UnicodeResultProcessor(encoding).conditional_process
def to_decimal_processor_factory(target_class, scale):
# Note that the scale argument is not taken into account for integer
# values in the C implementation while it is in the Python one.
# For example, the Python implementation might return
# Decimal('5.00000') whereas the C implementation will
# return Decimal('5'). These are equivalent of course.
return DecimalResultProcessor(target_class, "%%.%df" % scale).process
except ImportError:
globals().update(py_fallback())
|
mit
|
[
3,
8335,
15,
10547,
14,
647,
199,
3,
1898,
334,
35,
9,
7129,
13,
9261,
314,
14303,
11462,
436,
8417,
199,
3,
665,
3239,
10610,
570,
30,
199,
3,
1898,
334,
35,
9,
7129,
9647,
386,
290,
477,
603,
287,
724,
486,
271,
1410,
724,
32,
6799,
14,
957,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
624,
14334,
7809,
730,
8603,
3423,
12,
465,
1202,
315,
5398,
436,
754,
199,
10547,
14,
199,
199,
1918,
89,
1006,
8663,
1373,
2863,
2735,
6236,
11108,
26,
488,
365,
3032,
4012,
14874,
14,
199,
199,
624,
199,
199,
646,
6010,
199,
646,
295,
199,
646,
2197,
199,
504,
1275,
492,
4884,
421,
199,
318,
620,
63,
475,
63,
2083,
63,
6459,
63,
3702,
8,
11191,
12,
730,
7822,
272,
519,
1431,
275,
13156,
14,
1431,
272,
327,
22207,
641,
2366,
18,
14,
22,
2197,
14,
9866,
365,
3865,
26200,
2419,
642,
1233,
272,
327,
436,
652,
1630,
440,
2291,
21574,
14,
272,
965,
63,
4579,
63,
2634,
275,
2155,
8,
11191,
14,
923,
1080,
9,
339,
347,
2112,
8,
585,
304,
267,
340,
574,
365,
488,
26,
288,
372,
488,
267,
587,
26,
288,
862,
26,
355,
333,
275,
519,
1431,
8,
585,
9,
288,
871,
3146,
26,
355,
746,
1722,
480,
20485,
1133,
2198,
450,
83,
1059,
1543,
82,
7,
298,
639,
3905,
574,
365,
440,
282,
1059,
2122,
450,
639,
334,
466,
63,
855,
354,
3108,
574,
430,
288,
340,
333,
365,
488,
26,
355,
746,
1722,
480,
20485,
1133,
2198,
450,
83,
1059,
26,
298,
639,
17648,
83,
4065,
450,
334,
466,
63,
855,
354,
3108,
574,
430,
288,
340,
965,
63,
4579,
63,
2634,
26,
355,
4652,
275,
333,
14,
20567,
8,
16,
9,
355,
372,
730,
2531,
538,
807,
8,
513,
8,
3065,
8,
490,
2740,
8,
2634,
14,
1612,
4000,
490,
769,
8,
1130,
8,
442,
12,
2740,
8,
2634,
14,
1459,
16890,
355,
5082,
430,
288,
587,
26,
355,
372,
730,
63,
2031,
513,
8,
1130,
8,
442,
12,
333,
14,
2634,
8,
16,
7845,
272,
372,
2112,
421,
199,
318,
5046,
63,
475,
63,
442,
8,
585,
304,
272,
340,
574,
365,
488,
26,
267,
372,
488,
272,
587,
26,
267,
372,
1109,
8,
585,
9,
421,
199,
318,
1134,
63,
10538,
837,
272,
347,
370,
63,
2975,
63,
6459,
63,
3702,
8,
2991,
12,
2552,
29,
403,
304,
267,
10334,
275,
6010,
14,
362,
8813,
8,
2991,
9,
398,
347,
2112,
8,
585,
304,
288,
340,
574,
365,
488,
26,
355,
372,
488,
288,
587,
26,
355,
327,
10334,
2529,
282,
2008,
26,
334,
585,
12,
822,
680,
29094,
590,
366,
20148,
314,
355,
327,
822,
1777,
365,
5048,
26,
652,
365,
4224,
626,
4340,
315,
314,
3293,
355,
327,
283,
2154,
1370,
2708,
8,
2991,
9,
1233,
931,
14,
355,
372,
10334,
8,
585,
12,
2552,
2788,
16,
61,
267,
372,
2112,
339,
347,
370,
63,
14353,
63,
2975,
63,
6459,
63,
3702,
8,
2991,
12,
2552,
29,
403,
304,
267,
10334,
275,
6010,
14,
362,
8813,
8,
2991,
9,
398,
347,
2112,
8,
585,
304,
288,
340,
574,
365,
488,
26,
355,
372,
488,
288,
916,
1228,
8,
585,
12,
4884,
14,
505,
63,
466,
304,
355,
372,
574,
288,
587,
26,
355,
327,
10334,
2529,
282,
2008,
26,
334,
585,
12,
822,
680,
29094,
590,
366,
20148,
314,
355,
327,
822,
1777,
365,
5048,
26,
652,
365,
4224,
626,
4340,
315,
314,
3293,
355,
327,
283,
2154,
1370,
2708,
8,
2991,
9,
1233,
931,
14,
355,
372,
10334,
8,
585,
12,
2552,
2788,
16,
61,
267,
372,
2112,
339,
347,
370,
63,
6355,
63,
6459,
63,
3702,
8,
1375,
63,
533,
12,
4666,
304,
267,
289,
875,
275,
2071,
5,
4111,
1587,
2,
450,
4666,
398,
347,
2112,
8,
585,
304,
288,
340,
574,
365,
488,
26,
355,
372,
488,
288,
587,
26,
355,
372,
1347,
63,
533,
8,
70,
875,
450,
574,
9,
267,
372,
2112,
339,
347,
370,
63,
1609,
8,
585,
304,
267,
340,
574,
365,
488,
26,
288,
372,
488,
267,
587,
26,
288,
372,
2069,
8,
585,
9,
339,
347,
370,
63,
495,
8,
585,
304,
267,
340,
574,
365,
488,
26,
288,
372,
488,
267,
587,
26,
288,
372,
620,
8,
585,
9,
339,
347,
1109,
63,
475,
63,
4871,
8,
585,
304,
267,
340,
574,
365,
488,
26,
288,
372,
488,
267,
587,
26,
288,
372,
574,
436,
715,
503,
756,
339,
17971,
10931,
63,
907,
275,
295,
14,
2014,
8,
267,
298,
2961,
68,
11,
7216,
2961,
68,
11,
7216,
2961,
68,
8771,
14749,
68,
11,
304,
2961,
68,
11,
304,
2961,
68,
8771,
15840,
14,
2961,
68,
11,
430,
18582,
272,
17032,
63,
907,
275,
295,
14,
2014,
480,
2961,
68,
11,
304,
2961,
68,
11,
304,
2961,
68,
8771,
15840,
14,
2961,
68,
11,
430,
18582,
272,
30131,
63,
907,
275,
295,
14,
2014,
480,
2961,
68,
11,
7216,
2961,
68,
11,
7216,
2961,
68,
11,
6320,
339,
620,
63,
475,
63,
2083,
275,
620,
63,
475,
63,
2083,
63,
6459,
63,
3702,
8,
12488,
63,
907,
12,
9144,
2197,
14,
2083,
9,
272,
620,
63,
475,
63,
521,
275,
620,
63,
475,
63,
2083,
63,
6459,
63,
3702,
8,
4961,
63,
907,
12,
2197,
14,
521,
9,
272,
620,
63,
475,
63,
602,
275,
620,
63,
475,
63,
2083,
63,
6459,
63,
3702,
8,
5390,
63,
907,
12,
2197,
14,
602,
9,
272,
372,
9480,
342,
199,
199,
893,
26,
272,
687,
8335,
14,
67,
10547,
492,
6140,
2889,
10438,
12,
971,
267,
6345,
2889,
10438,
12,
971,
267,
370,
63,
1609,
12,
370,
63,
495,
12,
1109,
63,
475,
63,
4871,
12,
971,
267,
620,
63,
475,
63,
2083,
12,
620,
63,
475,
63,
521,
12,
971,
267,
620,
63,
475,
63,
602,
339,
347,
370,
63,
2975,
63,
6459,
63,
3702,
8,
2991,
12,
2552,
29,
403,
304,
267,
340,
2552,
365,
440,
488,
26,
288,
372,
6140,
2889,
10438,
8,
2991
] |
[
8335,
15,
10547,
14,
647,
199,
3,
1898,
334,
35,
9,
7129,
13,
9261,
314,
14303,
11462,
436,
8417,
199,
3,
665,
3239,
10610,
570,
30,
199,
3,
1898,
334,
35,
9,
7129,
9647,
386,
290,
477,
603,
287,
724,
486,
271,
1410,
724,
32,
6799,
14,
957,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
624,
14334,
7809,
730,
8603,
3423,
12,
465,
1202,
315,
5398,
436,
754,
199,
10547,
14,
199,
199,
1918,
89,
1006,
8663,
1373,
2863,
2735,
6236,
11108,
26,
488,
365,
3032,
4012,
14874,
14,
199,
199,
624,
199,
199,
646,
6010,
199,
646,
295,
199,
646,
2197,
199,
504,
1275,
492,
4884,
421,
199,
318,
620,
63,
475,
63,
2083,
63,
6459,
63,
3702,
8,
11191,
12,
730,
7822,
272,
519,
1431,
275,
13156,
14,
1431,
272,
327,
22207,
641,
2366,
18,
14,
22,
2197,
14,
9866,
365,
3865,
26200,
2419,
642,
1233,
272,
327,
436,
652,
1630,
440,
2291,
21574,
14,
272,
965,
63,
4579,
63,
2634,
275,
2155,
8,
11191,
14,
923,
1080,
9,
339,
347,
2112,
8,
585,
304,
267,
340,
574,
365,
488,
26,
288,
372,
488,
267,
587,
26,
288,
862,
26,
355,
333,
275,
519,
1431,
8,
585,
9,
288,
871,
3146,
26,
355,
746,
1722,
480,
20485,
1133,
2198,
450,
83,
1059,
1543,
82,
7,
298,
639,
3905,
574,
365,
440,
282,
1059,
2122,
450,
639,
334,
466,
63,
855,
354,
3108,
574,
430,
288,
340,
333,
365,
488,
26,
355,
746,
1722,
480,
20485,
1133,
2198,
450,
83,
1059,
26,
298,
639,
17648,
83,
4065,
450,
334,
466,
63,
855,
354,
3108,
574,
430,
288,
340,
965,
63,
4579,
63,
2634,
26,
355,
4652,
275,
333,
14,
20567,
8,
16,
9,
355,
372,
730,
2531,
538,
807,
8,
513,
8,
3065,
8,
490,
2740,
8,
2634,
14,
1612,
4000,
490,
769,
8,
1130,
8,
442,
12,
2740,
8,
2634,
14,
1459,
16890,
355,
5082,
430,
288,
587,
26,
355,
372,
730,
63,
2031,
513,
8,
1130,
8,
442,
12,
333,
14,
2634,
8,
16,
7845,
272,
372,
2112,
421,
199,
318,
5046,
63,
475,
63,
442,
8,
585,
304,
272,
340,
574,
365,
488,
26,
267,
372,
488,
272,
587,
26,
267,
372,
1109,
8,
585,
9,
421,
199,
318,
1134,
63,
10538,
837,
272,
347,
370,
63,
2975,
63,
6459,
63,
3702,
8,
2991,
12,
2552,
29,
403,
304,
267,
10334,
275,
6010,
14,
362,
8813,
8,
2991,
9,
398,
347,
2112,
8,
585,
304,
288,
340,
574,
365,
488,
26,
355,
372,
488,
288,
587,
26,
355,
327,
10334,
2529,
282,
2008,
26,
334,
585,
12,
822,
680,
29094,
590,
366,
20148,
314,
355,
327,
822,
1777,
365,
5048,
26,
652,
365,
4224,
626,
4340,
315,
314,
3293,
355,
327,
283,
2154,
1370,
2708,
8,
2991,
9,
1233,
931,
14,
355,
372,
10334,
8,
585,
12,
2552,
2788,
16,
61,
267,
372,
2112,
339,
347,
370,
63,
14353,
63,
2975,
63,
6459,
63,
3702,
8,
2991,
12,
2552,
29,
403,
304,
267,
10334,
275,
6010,
14,
362,
8813,
8,
2991,
9,
398,
347,
2112,
8,
585,
304,
288,
340,
574,
365,
488,
26,
355,
372,
488,
288,
916,
1228,
8,
585,
12,
4884,
14,
505,
63,
466,
304,
355,
372,
574,
288,
587,
26,
355,
327,
10334,
2529,
282,
2008,
26,
334,
585,
12,
822,
680,
29094,
590,
366,
20148,
314,
355,
327,
822,
1777,
365,
5048,
26,
652,
365,
4224,
626,
4340,
315,
314,
3293,
355,
327,
283,
2154,
1370,
2708,
8,
2991,
9,
1233,
931,
14,
355,
372,
10334,
8,
585,
12,
2552,
2788,
16,
61,
267,
372,
2112,
339,
347,
370,
63,
6355,
63,
6459,
63,
3702,
8,
1375,
63,
533,
12,
4666,
304,
267,
289,
875,
275,
2071,
5,
4111,
1587,
2,
450,
4666,
398,
347,
2112,
8,
585,
304,
288,
340,
574,
365,
488,
26,
355,
372,
488,
288,
587,
26,
355,
372,
1347,
63,
533,
8,
70,
875,
450,
574,
9,
267,
372,
2112,
339,
347,
370,
63,
1609,
8,
585,
304,
267,
340,
574,
365,
488,
26,
288,
372,
488,
267,
587,
26,
288,
372,
2069,
8,
585,
9,
339,
347,
370,
63,
495,
8,
585,
304,
267,
340,
574,
365,
488,
26,
288,
372,
488,
267,
587,
26,
288,
372,
620,
8,
585,
9,
339,
347,
1109,
63,
475,
63,
4871,
8,
585,
304,
267,
340,
574,
365,
488,
26,
288,
372,
488,
267,
587,
26,
288,
372,
574,
436,
715,
503,
756,
339,
17971,
10931,
63,
907,
275,
295,
14,
2014,
8,
267,
298,
2961,
68,
11,
7216,
2961,
68,
11,
7216,
2961,
68,
8771,
14749,
68,
11,
304,
2961,
68,
11,
304,
2961,
68,
8771,
15840,
14,
2961,
68,
11,
430,
18582,
272,
17032,
63,
907,
275,
295,
14,
2014,
480,
2961,
68,
11,
304,
2961,
68,
11,
304,
2961,
68,
8771,
15840,
14,
2961,
68,
11,
430,
18582,
272,
30131,
63,
907,
275,
295,
14,
2014,
480,
2961,
68,
11,
7216,
2961,
68,
11,
7216,
2961,
68,
11,
6320,
339,
620,
63,
475,
63,
2083,
275,
620,
63,
475,
63,
2083,
63,
6459,
63,
3702,
8,
12488,
63,
907,
12,
9144,
2197,
14,
2083,
9,
272,
620,
63,
475,
63,
521,
275,
620,
63,
475,
63,
2083,
63,
6459,
63,
3702,
8,
4961,
63,
907,
12,
2197,
14,
521,
9,
272,
620,
63,
475,
63,
602,
275,
620,
63,
475,
63,
2083,
63,
6459,
63,
3702,
8,
5390,
63,
907,
12,
2197,
14,
602,
9,
272,
372,
9480,
342,
199,
199,
893,
26,
272,
687,
8335,
14,
67,
10547,
492,
6140,
2889,
10438,
12,
971,
267,
6345,
2889,
10438,
12,
971,
267,
370,
63,
1609,
12,
370,
63,
495,
12,
1109,
63,
475,
63,
4871,
12,
971,
267,
620,
63,
475,
63,
2083,
12,
620,
63,
475,
63,
521,
12,
971,
267,
620,
63,
475,
63,
602,
339,
347,
370,
63,
2975,
63,
6459,
63,
3702,
8,
2991,
12,
2552,
29,
403,
304,
267,
340,
2552,
365,
440,
488,
26,
288,
372,
6140,
2889,
10438,
8,
2991,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
DavidLP/home-assistant
|
homeassistant/components/mold_indicator/sensor.py
|
7
|
11783
|
"""Calculates mold growth indication from temperature and humidity."""
import logging
import math
import voluptuous as vol
from homeassistant import util
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.core import callback
from homeassistant.const import (
ATTR_UNIT_OF_MEASUREMENT, EVENT_HOMEASSISTANT_START, STATE_UNKNOWN,
TEMP_CELSIUS, TEMP_FAHRENHEIT, CONF_NAME)
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.event import async_track_state_change
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
ATTR_CRITICAL_TEMP = 'estimated_critical_temp'
ATTR_DEWPOINT = 'dewpoint'
CONF_CALIBRATION_FACTOR = 'calibration_factor'
CONF_INDOOR_HUMIDITY = 'indoor_humidity_sensor'
CONF_INDOOR_TEMP = 'indoor_temp_sensor'
CONF_OUTDOOR_TEMP = 'outdoor_temp_sensor'
DEFAULT_NAME = 'Mold Indicator'
MAGNUS_K2 = 17.62
MAGNUS_K3 = 243.12
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_INDOOR_TEMP): cv.entity_id,
vol.Required(CONF_OUTDOOR_TEMP): cv.entity_id,
vol.Required(CONF_INDOOR_HUMIDITY): cv.entity_id,
vol.Optional(CONF_CALIBRATION_FACTOR): vol.Coerce(float),
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
})
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up MoldIndicator sensor."""
name = config.get(CONF_NAME, DEFAULT_NAME)
indoor_temp_sensor = config.get(CONF_INDOOR_TEMP)
outdoor_temp_sensor = config.get(CONF_OUTDOOR_TEMP)
indoor_humidity_sensor = config.get(CONF_INDOOR_HUMIDITY)
calib_factor = config.get(CONF_CALIBRATION_FACTOR)
async_add_entities([MoldIndicator(
name, hass.config.units.is_metric, indoor_temp_sensor,
outdoor_temp_sensor, indoor_humidity_sensor, calib_factor)], False)
class MoldIndicator(Entity):
"""Represents a MoldIndication sensor."""
def __init__(self, name, is_metric, indoor_temp_sensor,
outdoor_temp_sensor, indoor_humidity_sensor, calib_factor):
"""Initialize the sensor."""
self._state = None
self._name = name
self._indoor_temp_sensor = indoor_temp_sensor
self._indoor_humidity_sensor = indoor_humidity_sensor
self._outdoor_temp_sensor = outdoor_temp_sensor
self._calib_factor = calib_factor
self._is_metric = is_metric
self._available = False
self._entities = set([self._indoor_temp_sensor,
self._indoor_humidity_sensor,
self._outdoor_temp_sensor])
self._dewpoint = None
self._indoor_temp = None
self._outdoor_temp = None
self._indoor_hum = None
self._crit_temp = None
async def async_added_to_hass(self):
"""Register callbacks."""
@callback
def mold_indicator_sensors_state_listener(entity, old_state,
new_state):
"""Handle for state changes for dependent sensors."""
_LOGGER.debug("Sensor state change for %s that had old state %s "
"and new state %s", entity, old_state, new_state)
if self._update_sensor(entity, old_state, new_state):
self.async_schedule_update_ha_state(True)
@callback
def mold_indicator_startup(event):
"""Add listeners and get 1st state."""
_LOGGER.debug("Startup for %s", self.entity_id)
async_track_state_change(self.hass, self._entities,
mold_indicator_sensors_state_listener)
# Read initial state
indoor_temp = self.hass.states.get(self._indoor_temp_sensor)
outdoor_temp = self.hass.states.get(self._outdoor_temp_sensor)
indoor_hum = self.hass.states.get(self._indoor_humidity_sensor)
schedule_update = self._update_sensor(self._indoor_temp_sensor,
None, indoor_temp)
schedule_update = False if not self._update_sensor(
self._outdoor_temp_sensor, None, outdoor_temp) else\
schedule_update
schedule_update = False if not self._update_sensor(
self._indoor_humidity_sensor, None, indoor_hum) else\
schedule_update
if schedule_update:
self.async_schedule_update_ha_state(True)
self.hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_START, mold_indicator_startup)
def _update_sensor(self, entity, old_state, new_state):
"""Update information based on new sensor states."""
_LOGGER.debug("Sensor update for %s", entity)
if new_state is None:
return False
# If old_state is not set and new state is unknown then it means
# that the sensor just started up
if old_state is None and new_state.state == STATE_UNKNOWN:
return False
if entity == self._indoor_temp_sensor:
self._indoor_temp = MoldIndicator._update_temp_sensor(new_state)
elif entity == self._outdoor_temp_sensor:
self._outdoor_temp = MoldIndicator._update_temp_sensor(new_state)
elif entity == self._indoor_humidity_sensor:
self._indoor_hum = MoldIndicator._update_hum_sensor(new_state)
return True
@staticmethod
def _update_temp_sensor(state):
"""Parse temperature sensor value."""
_LOGGER.debug("Updating temp sensor with value %s", state.state)
# Return an error if the sensor change its state to Unknown.
if state.state == STATE_UNKNOWN:
_LOGGER.error("Unable to parse temperature sensor %s with state:"
" %s", state.entity_id, state.state)
return None
unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
temp = util.convert(state.state, float)
if temp is None:
_LOGGER.error("Unable to parse temperature sensor %s with state:"
" %s", state.entity_id, state.state)
return None
# convert to celsius if necessary
if unit == TEMP_FAHRENHEIT:
return util.temperature.fahrenheit_to_celsius(temp)
if unit == TEMP_CELSIUS:
return temp
_LOGGER.error("Temp sensor %s has unsupported unit: %s (allowed: %s, "
"%s)", state.entity_id, unit, TEMP_CELSIUS,
TEMP_FAHRENHEIT)
return None
@staticmethod
def _update_hum_sensor(state):
"""Parse humidity sensor value."""
_LOGGER.debug("Updating humidity sensor with value %s", state.state)
# Return an error if the sensor change its state to Unknown.
if state.state == STATE_UNKNOWN:
_LOGGER.error('Unable to parse humidity sensor %s, state: %s',
state.entity_id, state.state)
return None
unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
hum = util.convert(state.state, float)
if hum is None:
_LOGGER.error("Unable to parse humidity sensor %s, state: %s",
state.entity_id, state.state)
return None
if unit != '%':
_LOGGER.error("Humidity sensor %s has unsupported unit: %s %s",
state.entity_id, unit, " (allowed: %)")
return None
if hum > 100 or hum < 0:
_LOGGER.error("Humidity sensor %s is out of range: %s %s",
state.entity_id, hum, "(allowed: 0-100%)")
return None
return hum
async def async_update(self):
"""Calculate latest state."""
_LOGGER.debug("Update state for %s", self.entity_id)
# check all sensors
if None in (self._indoor_temp, self._indoor_hum, self._outdoor_temp):
self._available = False
self._dewpoint = None
self._crit_temp = None
return
# re-calculate dewpoint and mold indicator
self._calc_dewpoint()
self._calc_moldindicator()
if self._state is None:
self._available = False
self._dewpoint = None
self._crit_temp = None
else:
self._available = True
def _calc_dewpoint(self):
"""Calculate the dewpoint for the indoor air."""
# Use magnus approximation to calculate the dew point
alpha = MAGNUS_K2 * self._indoor_temp / (MAGNUS_K3 + self._indoor_temp)
beta = MAGNUS_K2 * MAGNUS_K3 / (MAGNUS_K3 + self._indoor_temp)
if self._indoor_hum == 0:
self._dewpoint = -50 # not defined, assume very low value
else:
self._dewpoint = \
MAGNUS_K3 * (alpha + math.log(self._indoor_hum / 100.0)) / \
(beta - math.log(self._indoor_hum / 100.0))
_LOGGER.debug("Dewpoint: %f %s", self._dewpoint, TEMP_CELSIUS)
def _calc_moldindicator(self):
"""Calculate the humidity at the (cold) calibration point."""
if None in (self._dewpoint, self._calib_factor) or \
self._calib_factor == 0:
_LOGGER.debug("Invalid inputs - dewpoint: %s,"
" calibration-factor: %s",
self._dewpoint, self._calib_factor)
self._state = None
self._available = False
self._crit_temp = None
return
# first calculate the approximate temperature at the calibration point
self._crit_temp = \
self._outdoor_temp + (self._indoor_temp - self._outdoor_temp) / \
self._calib_factor
_LOGGER.debug("Estimated Critical Temperature: %f %s",
self._crit_temp, TEMP_CELSIUS)
# Then calculate the humidity at this point
alpha = MAGNUS_K2 * self._crit_temp / (MAGNUS_K3 + self._crit_temp)
beta = MAGNUS_K2 * MAGNUS_K3 / (MAGNUS_K3 + self._crit_temp)
crit_humidity = \
math.exp(
(self._dewpoint * beta - MAGNUS_K3 * alpha) /
(self._dewpoint + MAGNUS_K3)) * 100.0
# check bounds and format
if crit_humidity > 100:
self._state = '100'
elif crit_humidity < 0:
self._state = '0'
else:
self._state = '{0:d}'.format(int(crit_humidity))
_LOGGER.debug("Mold indicator humidity: %s", self._state)
@property
def should_poll(self):
"""Return the polling state."""
return False
@property
def name(self):
"""Return the name."""
return self._name
@property
def unit_of_measurement(self):
"""Return the unit of measurement."""
return '%'
@property
def state(self):
"""Return the state of the entity."""
return self._state
@property
def available(self):
"""Return the availability of this sensor."""
return self._available
@property
def device_state_attributes(self):
"""Return the state attributes."""
if self._is_metric:
return {
ATTR_DEWPOINT: self._dewpoint,
ATTR_CRITICAL_TEMP: self._crit_temp,
}
dewpoint = util.temperature.celsius_to_fahrenheit(self._dewpoint) \
if self._dewpoint is not None else None
crit_temp = util.temperature.celsius_to_fahrenheit(self._crit_temp) \
if self._crit_temp is not None else None
return {
ATTR_DEWPOINT:
dewpoint,
ATTR_CRITICAL_TEMP:
crit_temp,
}
|
apache-2.0
|
[
624,
13862,
2335,
333,
1753,
20772,
273,
2539,
1063,
687,
14843,
436,
394,
21704,
1041,
199,
646,
2050,
199,
646,
3473,
199,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
492,
4884,
199,
504,
8846,
14,
4608,
14,
8956,
492,
21966,
63,
10926,
199,
504,
8846,
14,
1018,
492,
3233,
199,
504,
8846,
14,
1297,
492,
334,
272,
10762,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
12,
6461,
63,
9524,
16435,
840,
1441,
63,
7363,
12,
11377,
63,
11588,
12,
272,
24314,
63,
21595,
2684,
1668,
12,
24314,
63,
2078,
14784,
742,
1645,
649,
12,
6392,
63,
2339,
9,
199,
504,
8846,
14,
7546,
14,
4502,
492,
17680,
199,
504,
8846,
14,
7546,
14,
1430,
492,
5316,
63,
3885,
63,
929,
63,
1461,
199,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
5280,
63,
21539,
63,
12510,
275,
283,
597,
12754,
63,
13138,
63,
808,
7,
199,
5280,
63,
1093,
55,
7217,
275,
283,
271,
87,
1403,
7,
199,
199,
3103,
63,
13329,
2100,
23743,
63,
26393,
275,
283,
25851,
63,
4778,
7,
199,
3103,
63,
568,
1649,
726,
63,
40,
2639,
998,
1922,
275,
283,
688,
79,
269,
63,
31812,
63,
8956,
7,
199,
3103,
63,
568,
1649,
726,
63,
12510,
275,
283,
688,
79,
269,
63,
808,
63,
8956,
7,
199,
3103,
63,
1877,
1649,
726,
63,
12510,
275,
283,
548,
20842,
63,
808,
63,
8956,
7,
199,
199,
3472,
63,
2339,
275,
283,
45,
1753,
1010,
5000,
707,
7,
199,
199,
45,
1254,
1440,
51,
63,
43,
18,
275,
5557,
14,
2789,
199,
45,
1254,
1440,
51,
63,
43,
19,
275,
499,
2824,
14,
713,
199,
199,
17805,
63,
10926,
275,
21966,
63,
10926,
14,
2880,
2561,
272,
5236,
14,
8030,
8,
3103,
63,
568,
1649,
726,
63,
12510,
304,
6277,
14,
4502,
63,
344,
12,
272,
5236,
14,
8030,
8,
3103,
63,
1877,
1649,
726,
63,
12510,
304,
6277,
14,
4502,
63,
344,
12,
272,
5236,
14,
8030,
8,
3103,
63,
568,
1649,
726,
63,
40,
2639,
998,
1922,
304,
6277,
14,
4502,
63,
344,
12,
272,
5236,
14,
7012,
8,
3103,
63,
13329,
2100,
23743,
63,
26393,
304,
5236,
14,
967,
9810,
8,
1609,
395,
272,
5236,
14,
7012,
8,
3103,
63,
2339,
12,
849,
29,
3472,
63,
2339,
304,
6277,
14,
875,
12,
199,
1552,
421,
199,
4146,
347,
5316,
63,
2758,
63,
3246,
8,
5387,
12,
1101,
12,
5316,
63,
525,
63,
8327,
12,
3044,
13172,
63,
815,
29,
403,
304,
272,
408,
1084,
1536,
603,
1753,
24000,
8778,
1041,
272,
536,
275,
1101,
14,
362,
8,
3103,
63,
2339,
12,
6186,
63,
2339,
9,
272,
315,
20842,
63,
808,
63,
8956,
275,
1101,
14,
362,
8,
3103,
63,
568,
1649,
726,
63,
12510,
9,
272,
734,
20842,
63,
808,
63,
8956,
275,
1101,
14,
362,
8,
3103,
63,
1877,
1649,
726,
63,
12510,
9,
272,
315,
20842,
63,
31812,
63,
8956,
275,
1101,
14,
362,
8,
3103,
63,
568,
1649,
726,
63,
40,
2639,
998,
1922,
9,
272,
12855,
63,
4778,
275,
1101,
14,
362,
8,
3103,
63,
13329,
2100,
23743,
63,
26393,
9,
339,
5316,
63,
525,
63,
8327,
779,
45,
1753,
24000,
8,
267,
536,
12,
6298,
14,
888,
14,
5260,
14,
374,
63,
5165,
12,
315,
20842,
63,
808,
63,
8956,
12,
267,
734,
20842,
63,
808,
63,
8956,
12,
315,
20842,
63,
31812,
63,
8956,
12,
12855,
63,
4778,
4360,
756,
9,
421,
199,
533,
603,
1753,
24000,
8,
7302,
304,
272,
408,
18089,
282,
603,
1753,
607,
21171,
8778,
1041,
339,
347,
636,
826,
721,
277,
12,
536,
12,
365,
63,
5165,
12,
315,
20842,
63,
808,
63,
8956,
12,
326,
734,
20842,
63,
808,
63,
8956,
12,
315,
20842,
63,
31812,
63,
8956,
12,
12855,
63,
4778,
304,
267,
408,
9345,
314,
8778,
1041,
267,
291,
423,
929,
275,
488,
267,
291,
423,
354,
275,
536,
267,
291,
423,
688,
79,
269,
63,
808,
63,
8956,
275,
315,
20842,
63,
808,
63,
8956,
267,
291,
423,
688,
79,
269,
63,
31812,
63,
8956,
275,
315,
20842,
63,
31812,
63,
8956,
267,
291,
423,
548,
20842,
63,
808,
63,
8956,
275,
734,
20842,
63,
808,
63,
8956,
267,
291,
423,
15737,
63,
4778,
275,
12855,
63,
4778,
267,
291,
423,
374,
63,
5165,
275,
365,
63,
5165,
267,
291,
423,
4561,
275,
756,
267,
291,
423,
8327,
275,
663,
779,
277,
423,
688,
79,
269,
63,
808,
63,
8956,
12,
2892,
291,
423,
688,
79,
269,
63,
31812,
63,
8956,
12,
2892,
291,
423,
548,
20842,
63,
808,
63,
8956,
566,
398,
291,
423,
271,
87,
1403,
275,
488,
267,
291,
423,
688,
79,
269,
63,
808,
275,
488,
267,
291,
423,
548,
20842,
63,
808,
275,
488,
267,
291,
423,
688,
79,
269,
63,
72,
453,
275,
488,
267,
291,
423,
29506,
63,
808,
275,
488,
339,
5316,
347,
5316,
63,
3270,
63,
475,
63,
5387,
8,
277,
304,
267,
408,
7099,
13484,
1041,
267,
768,
3058,
267,
347,
333,
1753,
63,
15785,
63,
22675,
63,
929,
63,
9799,
8,
4502,
12,
2269,
63,
929,
12,
8179,
892,
63,
929,
304,
288,
408,
5940,
367,
1174,
4493,
367,
11410,
19678,
1041,
288,
485,
10186,
14,
1757,
480,
10160,
1174,
1570,
367,
450,
83,
626,
10530,
2269,
1174,
450,
83,
298,
2079,
298,
460,
892,
1174,
450,
83,
401,
4642,
12,
2269,
63,
929,
12,
892,
63,
929,
9,
953,
340,
291,
423,
873,
63,
8956,
8,
4502,
12,
2269,
63,
929,
12,
892,
63,
929,
304,
355,
291,
14,
4146,
63,
7211,
63,
873,
63,
2411,
63,
929,
8,
549,
9,
398,
768,
3058,
267,
347,
333,
1753,
63,
15785,
63,
16480,
8,
1430,
304,
288,
408,
1123,
19946,
436,
664,
413,
270,
1174,
1041,
288,
485,
10186,
14,
1757,
480,
18515,
367,
450,
83,
401,
291,
14,
4502,
63,
344,
9,
953,
5316,
63,
3885,
63,
929,
63,
1461,
8,
277,
14,
5387,
12,
291,
423,
8327,
12,
3660,
333,
1753,
63,
15785,
63,
22675,
63,
929,
63,
9799,
9,
953,
327,
5574,
2536,
1174,
288,
315,
20842,
63,
808,
275
] |
[
13862,
2335,
333,
1753,
20772,
273,
2539,
1063,
687,
14843,
436,
394,
21704,
1041,
199,
646,
2050,
199,
646,
3473,
199,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
492,
4884,
199,
504,
8846,
14,
4608,
14,
8956,
492,
21966,
63,
10926,
199,
504,
8846,
14,
1018,
492,
3233,
199,
504,
8846,
14,
1297,
492,
334,
272,
10762,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
12,
6461,
63,
9524,
16435,
840,
1441,
63,
7363,
12,
11377,
63,
11588,
12,
272,
24314,
63,
21595,
2684,
1668,
12,
24314,
63,
2078,
14784,
742,
1645,
649,
12,
6392,
63,
2339,
9,
199,
504,
8846,
14,
7546,
14,
4502,
492,
17680,
199,
504,
8846,
14,
7546,
14,
1430,
492,
5316,
63,
3885,
63,
929,
63,
1461,
199,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
5280,
63,
21539,
63,
12510,
275,
283,
597,
12754,
63,
13138,
63,
808,
7,
199,
5280,
63,
1093,
55,
7217,
275,
283,
271,
87,
1403,
7,
199,
199,
3103,
63,
13329,
2100,
23743,
63,
26393,
275,
283,
25851,
63,
4778,
7,
199,
3103,
63,
568,
1649,
726,
63,
40,
2639,
998,
1922,
275,
283,
688,
79,
269,
63,
31812,
63,
8956,
7,
199,
3103,
63,
568,
1649,
726,
63,
12510,
275,
283,
688,
79,
269,
63,
808,
63,
8956,
7,
199,
3103,
63,
1877,
1649,
726,
63,
12510,
275,
283,
548,
20842,
63,
808,
63,
8956,
7,
199,
199,
3472,
63,
2339,
275,
283,
45,
1753,
1010,
5000,
707,
7,
199,
199,
45,
1254,
1440,
51,
63,
43,
18,
275,
5557,
14,
2789,
199,
45,
1254,
1440,
51,
63,
43,
19,
275,
499,
2824,
14,
713,
199,
199,
17805,
63,
10926,
275,
21966,
63,
10926,
14,
2880,
2561,
272,
5236,
14,
8030,
8,
3103,
63,
568,
1649,
726,
63,
12510,
304,
6277,
14,
4502,
63,
344,
12,
272,
5236,
14,
8030,
8,
3103,
63,
1877,
1649,
726,
63,
12510,
304,
6277,
14,
4502,
63,
344,
12,
272,
5236,
14,
8030,
8,
3103,
63,
568,
1649,
726,
63,
40,
2639,
998,
1922,
304,
6277,
14,
4502,
63,
344,
12,
272,
5236,
14,
7012,
8,
3103,
63,
13329,
2100,
23743,
63,
26393,
304,
5236,
14,
967,
9810,
8,
1609,
395,
272,
5236,
14,
7012,
8,
3103,
63,
2339,
12,
849,
29,
3472,
63,
2339,
304,
6277,
14,
875,
12,
199,
1552,
421,
199,
4146,
347,
5316,
63,
2758,
63,
3246,
8,
5387,
12,
1101,
12,
5316,
63,
525,
63,
8327,
12,
3044,
13172,
63,
815,
29,
403,
304,
272,
408,
1084,
1536,
603,
1753,
24000,
8778,
1041,
272,
536,
275,
1101,
14,
362,
8,
3103,
63,
2339,
12,
6186,
63,
2339,
9,
272,
315,
20842,
63,
808,
63,
8956,
275,
1101,
14,
362,
8,
3103,
63,
568,
1649,
726,
63,
12510,
9,
272,
734,
20842,
63,
808,
63,
8956,
275,
1101,
14,
362,
8,
3103,
63,
1877,
1649,
726,
63,
12510,
9,
272,
315,
20842,
63,
31812,
63,
8956,
275,
1101,
14,
362,
8,
3103,
63,
568,
1649,
726,
63,
40,
2639,
998,
1922,
9,
272,
12855,
63,
4778,
275,
1101,
14,
362,
8,
3103,
63,
13329,
2100,
23743,
63,
26393,
9,
339,
5316,
63,
525,
63,
8327,
779,
45,
1753,
24000,
8,
267,
536,
12,
6298,
14,
888,
14,
5260,
14,
374,
63,
5165,
12,
315,
20842,
63,
808,
63,
8956,
12,
267,
734,
20842,
63,
808,
63,
8956,
12,
315,
20842,
63,
31812,
63,
8956,
12,
12855,
63,
4778,
4360,
756,
9,
421,
199,
533,
603,
1753,
24000,
8,
7302,
304,
272,
408,
18089,
282,
603,
1753,
607,
21171,
8778,
1041,
339,
347,
636,
826,
721,
277,
12,
536,
12,
365,
63,
5165,
12,
315,
20842,
63,
808,
63,
8956,
12,
326,
734,
20842,
63,
808,
63,
8956,
12,
315,
20842,
63,
31812,
63,
8956,
12,
12855,
63,
4778,
304,
267,
408,
9345,
314,
8778,
1041,
267,
291,
423,
929,
275,
488,
267,
291,
423,
354,
275,
536,
267,
291,
423,
688,
79,
269,
63,
808,
63,
8956,
275,
315,
20842,
63,
808,
63,
8956,
267,
291,
423,
688,
79,
269,
63,
31812,
63,
8956,
275,
315,
20842,
63,
31812,
63,
8956,
267,
291,
423,
548,
20842,
63,
808,
63,
8956,
275,
734,
20842,
63,
808,
63,
8956,
267,
291,
423,
15737,
63,
4778,
275,
12855,
63,
4778,
267,
291,
423,
374,
63,
5165,
275,
365,
63,
5165,
267,
291,
423,
4561,
275,
756,
267,
291,
423,
8327,
275,
663,
779,
277,
423,
688,
79,
269,
63,
808,
63,
8956,
12,
2892,
291,
423,
688,
79,
269,
63,
31812,
63,
8956,
12,
2892,
291,
423,
548,
20842,
63,
808,
63,
8956,
566,
398,
291,
423,
271,
87,
1403,
275,
488,
267,
291,
423,
688,
79,
269,
63,
808,
275,
488,
267,
291,
423,
548,
20842,
63,
808,
275,
488,
267,
291,
423,
688,
79,
269,
63,
72,
453,
275,
488,
267,
291,
423,
29506,
63,
808,
275,
488,
339,
5316,
347,
5316,
63,
3270,
63,
475,
63,
5387,
8,
277,
304,
267,
408,
7099,
13484,
1041,
267,
768,
3058,
267,
347,
333,
1753,
63,
15785,
63,
22675,
63,
929,
63,
9799,
8,
4502,
12,
2269,
63,
929,
12,
8179,
892,
63,
929,
304,
288,
408,
5940,
367,
1174,
4493,
367,
11410,
19678,
1041,
288,
485,
10186,
14,
1757,
480,
10160,
1174,
1570,
367,
450,
83,
626,
10530,
2269,
1174,
450,
83,
298,
2079,
298,
460,
892,
1174,
450,
83,
401,
4642,
12,
2269,
63,
929,
12,
892,
63,
929,
9,
953,
340,
291,
423,
873,
63,
8956,
8,
4502,
12,
2269,
63,
929,
12,
892,
63,
929,
304,
355,
291,
14,
4146,
63,
7211,
63,
873,
63,
2411,
63,
929,
8,
549,
9,
398,
768,
3058,
267,
347,
333,
1753,
63,
15785,
63,
16480,
8,
1430,
304,
288,
408,
1123,
19946,
436,
664,
413,
270,
1174,
1041,
288,
485,
10186,
14,
1757,
480,
18515,
367,
450,
83,
401,
291,
14,
4502,
63,
344,
9,
953,
5316,
63,
3885,
63,
929,
63,
1461,
8,
277,
14,
5387,
12,
291,
423,
8327,
12,
3660,
333,
1753,
63,
15785,
63,
22675,
63,
929,
63,
9799,
9,
953,
327,
5574,
2536,
1174,
288,
315,
20842,
63,
808,
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,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
emedinaa/contentbox
|
third_party/yawdadmin/admin.py
|
6
|
9802
|
import json
from django.conf.urls import patterns, url
from django.contrib import admin
from django.contrib.admin.options import InlineModelAdmin
from django.contrib.admin.util import unquote, get_deleted_objects
from django.core.exceptions import PermissionDenied
from django.db import router
from django.http import Http404
from django.forms.widgets import HiddenInput
from django.template.response import TemplateResponse, HttpResponse
from django.utils.encoding import force_text
from django.utils.html import escape, escapejs
from django.utils.translation import ugettext as _
from templatetags.yawdadmin_tags import inline_items_for_result
from forms import PopupInlineFormSet
try: #django 1.6 and above
from django.contrib.admin.options import IS_POPUP_VAR #@UnresolvedImport
except:
IS_POPUP_VAR = '_popup'
class PopupInline(InlineModelAdmin):
extra = 1
formset = PopupInlineFormSet
list_display = []
sortable = False
sortable_order_field = 'order'
template = 'admin/edit_inline/popup.html'
class PopupModelAdmin(admin.ModelAdmin):
linked_inline = None
popup_only = False
def add_view(self, request, form_url='', extra_context=None):
if self.popup_only and not IS_POPUP_VAR in request.REQUEST:
raise Http404
return super(PopupModelAdmin, self).add_view(request, form_url, extra_context)
def ajaxdelete_view(self, request, object_id):
"The 'delete' admin view for this model."
opts = self.model._meta
app_label = opts.app_label
obj = self.get_object(request, unquote(object_id))
if not self.has_delete_permission(request, obj):
raise PermissionDenied
if obj is None:
raise Http404(
_('%(name)s object with primary key %(key)r does not exist.') %
{'name': force_text(opts.verbose_name), 'key': escape(object_id)}
)
using = router.db_for_write(self.model)
# Populate deleted_objects, a data structure of all related objects that
# will also be deleted.
(deleted_objects, perms_needed, protected) = get_deleted_objects(
[obj], opts, request.user, self.admin_site, using)
if perms_needed:
return PermissionDenied
obj_display = force_text(obj)
self.log_deletion(request, obj, obj_display)
self.delete_model(request, obj)
return HttpResponse('<html><body>OK</body></html>')
def change_view(self, request, object_id, form_url='', extra_context=None):
if self.popup_only and not IS_POPUP_VAR in request.REQUEST:
raise Http404
return super(PopupModelAdmin, self).change_view(request, object_id,
form_url, extra_context)
def formfield_for_dbfield(self, db_field, **kwargs):
"""
Override foreignkey widget if popup and field matches fk_name
"""
formfield = super(PopupModelAdmin, self).formfield_for_dbfield(db_field,
**kwargs)
request = kwargs.pop("request", None)
fk_name = request.GET.get('fk_name')
fk_id = request.GET.get('fk_id')
if IS_POPUP_VAR in request.REQUEST and db_field.name == fk_name:
formfield.widget = HiddenInput()
formfield.popup_fk = True
if fk_id:
formfield.initial = fk_id
return formfield
def get_urls(self):
"""
Override get_urls to include the ajax delete url
"""
urls = super(PopupModelAdmin, self).get_urls()
info = self.model._meta.app_label, self.model._meta.module_name
my_urls = patterns('',
url(r'^(.+)/ajax/delete/$',
self.admin_site.admin_view(self.ajaxdelete_view),
name="%s_%s_deleteit" % info),
url(r'^ajax/reorder/$',
self.admin_site.admin_view(self.inline_reorder),
name="%s_%s_inlinereorder" % info),
)
return my_urls + urls
def inline_reorder(self, request):
if not self.linked_inline or not self.linked_inline.sortable or \
not self.linked_inline.sortable_order_field:
raise Http404
if not request.POST.get('data'):
raise PermissionDenied
for obj in json.loads(request.POST['data']):
model_obj = self.model.objects.get(pk=int(obj['pk']))
setattr(model_obj, self.linked_inline.sortable_order_field,
int(obj['order']))
model_obj.save()
return HttpResponse('<html><body>OK</body></html>')
def response_add(self, request, obj, post_url_continue=None):
"""
Override add response to handle the PopupInline case
"""
if IS_POPUP_VAR in request.POST and request.GET.get('fk_name'):
return HttpResponse(
'<!DOCTYPE html><html><head><title></title></head><body>'
'<script type="text/javascript">parent.dismissAddAnotherPopupInline'
'(window, "%s", "%s", "%s");</script></body></html>' % \
# escape() calls force_text.
(escape(obj.pk),
escapejs(inline_items_for_result(self.linked_inline, obj) \
if self.linked_inline else obj),
'true' if self.linked_inline.can_delete else 'false'))
return super(PopupModelAdmin, self).response_add(request, obj,
post_url_continue)
def response_change(self, request, obj):
"""
Override change response to handle the PopupInline case
"""
if IS_POPUP_VAR in request.POST and request.GET.get('fk_name'):
return HttpResponse(
'<!DOCTYPE html><html><head><title></title></head><body>'
'<script type="text/javascript">parent.dismissEditPopupInline'
'(window, "%s", "%s");</script></body></html>' % \
# escape() calls force_text.
(escape(obj.pk),
escapejs(inline_items_for_result(self.linked_inline, obj) \
if self.linked_inline else obj)))
return super(PopupModelAdmin, self).response_change(request, obj)
class SortableModelAdmin(admin.ModelAdmin):
sortable = True
sortable_order_field = 'order'
sortable_mptt = False
def get_urls(self):
"""
Override get_urls to include the sortable views
for the specified language
"""
urls = super(SortableModelAdmin, self).get_urls()
info = self.model._meta.app_label, self.model._meta.module_name
my_urls = patterns('',
url(r'^sortables/$',
self.admin_site.admin_view(self.sortables),
name="%s_%s_sortables" % info),
url(r'^sortables/reorder/$',
self.admin_site.admin_view(self.reorder),
name="%s_%s_reorder" % info),
url(r'^ajax/$',
self.admin_site.admin_view(self.partial_changelist_view),
name="%s_%s_partial_changelist" % info),
)
return my_urls + urls
def _reorder(self, data, request):
data = dict([(str(d['pk']), d) for d in data])
data_objects = self.model.objects.filter(pk__in=data.keys())
for item in data_objects:
data[str(item.pk)]['object'] = item
for d in data.itervalues():
if self.sortable_mptt:
parent = data[str(d['parent'])]['object'] if 'parent' in d else None
setattr(d['object'],
d['object']._mptt_meta.parent_attr,
parent)
setattr(d['object'], self.sortable_order_field, int(d['order']))
d['object'].save()
if self.sortable_mptt:
self.model.objects.rebuild()
def sortables_ordered(self, queryset):
"""
Should return a queryset that orders the objects properly
(e.g. for nested categories the queryset should return:
Parent1, Paren1Child1, Parent1Child2, Parent2, Parent2Child1 etc)
"""
return queryset
def sortables(self, request):
return TemplateResponse(request, 'admin/sortables/mptt_list.html' if self.sortable_mptt \
else 'admin/sortables/list.html',
{'mptt': self.sortable_mptt,
'objects': self.sortables_ordered(self.queryset(request))})
def reorder(self, request):
if not request.POST.get('data', None):
return HttpResponse(json.dumps({'message': _('No data sent with the request')}))
try:
self._reorder(json.loads(request.POST.get('data', None)), request)
except:
return HttpResponse(json.dumps({'message': _('Unable to reorder objects')}))
return HttpResponse(json.dumps({'message': _('The order was saved')}))
def partial_changelist_view(self, request):
template = self.change_list_template
self.change_list_template = 'admin/sortables/partial_change_list.html'
try: #revert state even on exception
response = super(SortableModelAdmin, self).changelist_view(request)
finally:
self.change_list_template = template
return response
class OneToOneInline(admin.StackedInline):
template = 'admin/edit_inline/one-to-one-inline.html'
can_delete = False
one_to_one = True
show_title = True
|
apache-2.0
|
[
646,
2022,
199,
504,
1639,
14,
2190,
14,
3603,
492,
7970,
12,
1166,
199,
504,
1639,
14,
2828,
492,
4628,
199,
504,
1639,
14,
2828,
14,
2113,
14,
1419,
492,
24789,
12976,
221,
199,
504,
1639,
14,
2828,
14,
2113,
14,
1974,
492,
14342,
12,
664,
63,
6062,
63,
1462,
199,
504,
1639,
14,
1018,
14,
3924,
492,
23724,
199,
504,
1639,
14,
697,
492,
6197,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
199,
504,
1639,
14,
3351,
14,
8583,
492,
26401,
3205,
199,
504,
1639,
14,
1160,
14,
1310,
492,
29264,
12,
6183,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
1360,
492,
4772,
12,
4772,
3596,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1978,
2969,
14,
11552,
2989,
2113,
63,
2969,
492,
8308,
63,
1744,
63,
509,
63,
1099,
199,
504,
4513,
492,
13244,
384,
10307,
14736,
421,
199,
893,
26,
327,
1176,
413,
14,
22,
436,
3432,
272,
687,
1639,
14,
2828,
14,
2113,
14,
1419,
492,
2281,
63,
13531,
2160,
63,
5568,
9213,
1358,
13697,
6295,
199,
2590,
26,
272,
2281,
63,
13531,
2160,
63,
5568,
275,
2513,
16020,
7,
421,
199,
533,
13244,
384,
10307,
8,
10307,
12976,
304,
272,
2402,
275,
413,
272,
11068,
275,
13244,
384,
10307,
14736,
272,
769,
63,
2918,
275,
942,
272,
4069,
461,
275,
756,
272,
4069,
461,
63,
1648,
63,
698,
275,
283,
1648,
7,
272,
1978,
275,
283,
2113,
15,
3773,
63,
6460,
15,
16020,
14,
1360,
7,
421,
199,
533,
13244,
384,
12976,
8,
2113,
14,
12976,
304,
272,
10632,
63,
6460,
275,
488,
272,
22365,
63,
2118,
275,
756,
2286,
347,
1050,
63,
1345,
8,
277,
12,
1056,
12,
1824,
63,
633,
4581,
2402,
63,
1100,
29,
403,
304,
267,
340,
291,
14,
16020,
63,
2118,
436,
440,
2281,
63,
13531,
2160,
63,
5568,
315,
1056,
14,
6780,
26,
288,
746,
4760,
5188,
2728,
372,
1613,
8,
26168,
12976,
12,
291,
680,
525,
63,
1345,
8,
1069,
12,
1824,
63,
633,
12,
2402,
63,
1100,
9,
339,
347,
25930,
1807,
63,
1345,
8,
277,
12,
1056,
12,
909,
63,
344,
304,
267,
298,
1918,
283,
1807,
7,
4628,
2455,
367,
642,
1402,
2122,
267,
3999,
275,
291,
14,
1238,
423,
2024,
267,
1145,
63,
1302,
275,
3999,
14,
571,
63,
1302,
398,
1559,
275,
291,
14,
362,
63,
785,
8,
1069,
12,
14342,
8,
785,
63,
344,
430,
398,
340,
440,
291,
14,
1989,
63,
1807,
63,
5693,
8,
1069,
12,
1559,
304,
288,
746,
23724,
398,
340,
1559,
365,
488,
26,
288,
746,
4760,
5188,
8,
355,
4018,
2840,
354,
9,
83,
909,
543,
5062,
790,
2818,
498,
9,
82,
1630,
440,
2187,
2659,
450,
490,
791,
354,
356,
3542,
63,
505,
8,
3291,
14,
3832,
63,
354,
395,
283,
498,
356,
4772,
8,
785,
63,
344,
6769,
288,
776,
398,
1808,
275,
6197,
14,
697,
63,
509,
63,
952,
8,
277,
14,
1238,
9,
398,
327,
31731,
5463,
63,
1462,
12,
282,
666,
5523,
402,
1006,
4048,
2251,
626,
267,
327,
911,
2597,
506,
5463,
14,
267,
334,
6062,
63,
1462,
12,
17340,
63,
11368,
12,
17819,
9,
275,
664,
63,
6062,
63,
1462,
8,
288,
359,
1113,
467,
3999,
12,
1056,
14,
751,
12,
291,
14,
2113,
63,
2124,
12,
1808,
9,
398,
340,
17340,
63,
11368,
26,
288,
372,
23724,
398,
1559,
63,
2918,
275,
3542,
63,
505,
8,
1113,
9,
267,
291,
14,
793,
63,
14281,
8,
1069,
12,
1559,
12,
1559,
63,
2918,
9,
267,
291,
14,
1807,
63,
1238,
8,
1069,
12,
1559,
9,
398,
372,
6183,
4827,
1360,
2535,
2030,
30,
3593,
1108,
2030,
2957,
1360,
5971,
2286,
347,
1570,
63,
1345,
8,
277,
12,
1056,
12,
909,
63,
344,
12,
1824,
63,
633,
4581,
2402,
63,
1100,
29,
403,
304,
267,
340,
291,
14,
16020,
63,
2118,
436,
440,
2281,
63,
13531,
2160,
63,
5568,
315,
1056,
14,
6780,
26,
288,
746,
4760,
5188,
2728,
372,
1613,
8,
26168,
12976,
12,
291,
680,
1461,
63,
1345,
8,
1069,
12,
909,
63,
344,
12,
221,
9144,
1824,
63,
633,
12,
2402,
63,
1100,
9,
339,
347,
21388,
63,
509,
63,
697,
698,
8,
277,
12,
1592,
63,
698,
12,
1011,
958,
304,
267,
408,
267,
11041,
11608,
498,
3938,
340,
22365,
436,
901,
4450,
14830,
63,
354,
267,
408,
267,
21388,
275,
1613,
8,
26168,
12976,
12,
291,
680,
20015,
63,
509,
63,
697,
698,
8,
697,
63,
698,
12,
6684,
755,
1011,
958,
9,
398,
1056,
275,
2074,
14,
1935,
480,
1069,
401,
488,
9,
267,
14830,
63,
354,
275,
1056,
14,
2970,
14,
362,
360,
9010,
63,
354,
358,
267,
14830,
63,
344,
275,
1056,
14,
2970,
14,
362,
360,
9010,
63,
344,
358,
398,
340,
2281,
63,
13531,
2160,
63,
5568,
315,
1056,
14,
6780,
436,
1592,
63,
698,
14,
354,
508,
14830,
63,
354,
26,
288,
21388,
14,
3440,
275,
26401,
3205,
342,
288,
21388,
14,
16020,
63,
9010,
275,
715,
288,
340,
14830,
63,
344,
26,
355,
21388,
14,
2747,
275,
14830,
63,
344,
267,
372,
21388,
339,
347,
664,
63,
3603,
8,
277,
304,
267,
408,
267,
11041,
664,
63,
3603,
370,
2387,
314,
25930,
3145,
1166,
267,
408,
267,
8187,
275,
1613,
8,
26168,
12976,
12,
291,
680,
362,
63,
3603,
342,
398,
2256,
275,
291,
14,
1238,
423,
2024,
14,
571,
63,
1302,
12,
291,
14,
1238,
423,
2024,
14,
578,
63,
354,
267,
3002,
63,
3603,
275,
7970,
8594,
288,
1166,
8,
82,
31996,
6977,
2447,
12774,
15,
1807,
10884,
355,
291,
14,
2113,
63,
2124,
14,
2113,
63,
1345,
8,
277,
14,
12774,
1807,
63,
1345,
395,
355,
536,
5961,
83,
4970,
83,
63,
1807,
390,
2,
450,
2256,
395,
288,
1166,
8,
82,
4289,
12774,
15,
29463,
10884,
355,
291,
14,
2113,
63,
2124,
14,
2113,
63,
1345,
8,
277,
14,
6460,
63,
29463,
395,
355,
536,
5961,
83,
4970,
83,
63,
6460,
29463,
2,
450,
2256,
395,
267,
776,
267,
372,
3002,
63,
3603,
435,
8187,
339,
347,
8308,
63,
29463,
8,
277,
12,
1056,
304,
267,
340,
440,
291,
14,
12751,
63
] |
[
2022,
199,
504,
1639,
14,
2190,
14,
3603,
492,
7970,
12,
1166,
199,
504,
1639,
14,
2828,
492,
4628,
199,
504,
1639,
14,
2828,
14,
2113,
14,
1419,
492,
24789,
12976,
221,
199,
504,
1639,
14,
2828,
14,
2113,
14,
1974,
492,
14342,
12,
664,
63,
6062,
63,
1462,
199,
504,
1639,
14,
1018,
14,
3924,
492,
23724,
199,
504,
1639,
14,
697,
492,
6197,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
199,
504,
1639,
14,
3351,
14,
8583,
492,
26401,
3205,
199,
504,
1639,
14,
1160,
14,
1310,
492,
29264,
12,
6183,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
1360,
492,
4772,
12,
4772,
3596,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1978,
2969,
14,
11552,
2989,
2113,
63,
2969,
492,
8308,
63,
1744,
63,
509,
63,
1099,
199,
504,
4513,
492,
13244,
384,
10307,
14736,
421,
199,
893,
26,
327,
1176,
413,
14,
22,
436,
3432,
272,
687,
1639,
14,
2828,
14,
2113,
14,
1419,
492,
2281,
63,
13531,
2160,
63,
5568,
9213,
1358,
13697,
6295,
199,
2590,
26,
272,
2281,
63,
13531,
2160,
63,
5568,
275,
2513,
16020,
7,
421,
199,
533,
13244,
384,
10307,
8,
10307,
12976,
304,
272,
2402,
275,
413,
272,
11068,
275,
13244,
384,
10307,
14736,
272,
769,
63,
2918,
275,
942,
272,
4069,
461,
275,
756,
272,
4069,
461,
63,
1648,
63,
698,
275,
283,
1648,
7,
272,
1978,
275,
283,
2113,
15,
3773,
63,
6460,
15,
16020,
14,
1360,
7,
421,
199,
533,
13244,
384,
12976,
8,
2113,
14,
12976,
304,
272,
10632,
63,
6460,
275,
488,
272,
22365,
63,
2118,
275,
756,
2286,
347,
1050,
63,
1345,
8,
277,
12,
1056,
12,
1824,
63,
633,
4581,
2402,
63,
1100,
29,
403,
304,
267,
340,
291,
14,
16020,
63,
2118,
436,
440,
2281,
63,
13531,
2160,
63,
5568,
315,
1056,
14,
6780,
26,
288,
746,
4760,
5188,
2728,
372,
1613,
8,
26168,
12976,
12,
291,
680,
525,
63,
1345,
8,
1069,
12,
1824,
63,
633,
12,
2402,
63,
1100,
9,
339,
347,
25930,
1807,
63,
1345,
8,
277,
12,
1056,
12,
909,
63,
344,
304,
267,
298,
1918,
283,
1807,
7,
4628,
2455,
367,
642,
1402,
2122,
267,
3999,
275,
291,
14,
1238,
423,
2024,
267,
1145,
63,
1302,
275,
3999,
14,
571,
63,
1302,
398,
1559,
275,
291,
14,
362,
63,
785,
8,
1069,
12,
14342,
8,
785,
63,
344,
430,
398,
340,
440,
291,
14,
1989,
63,
1807,
63,
5693,
8,
1069,
12,
1559,
304,
288,
746,
23724,
398,
340,
1559,
365,
488,
26,
288,
746,
4760,
5188,
8,
355,
4018,
2840,
354,
9,
83,
909,
543,
5062,
790,
2818,
498,
9,
82,
1630,
440,
2187,
2659,
450,
490,
791,
354,
356,
3542,
63,
505,
8,
3291,
14,
3832,
63,
354,
395,
283,
498,
356,
4772,
8,
785,
63,
344,
6769,
288,
776,
398,
1808,
275,
6197,
14,
697,
63,
509,
63,
952,
8,
277,
14,
1238,
9,
398,
327,
31731,
5463,
63,
1462,
12,
282,
666,
5523,
402,
1006,
4048,
2251,
626,
267,
327,
911,
2597,
506,
5463,
14,
267,
334,
6062,
63,
1462,
12,
17340,
63,
11368,
12,
17819,
9,
275,
664,
63,
6062,
63,
1462,
8,
288,
359,
1113,
467,
3999,
12,
1056,
14,
751,
12,
291,
14,
2113,
63,
2124,
12,
1808,
9,
398,
340,
17340,
63,
11368,
26,
288,
372,
23724,
398,
1559,
63,
2918,
275,
3542,
63,
505,
8,
1113,
9,
267,
291,
14,
793,
63,
14281,
8,
1069,
12,
1559,
12,
1559,
63,
2918,
9,
267,
291,
14,
1807,
63,
1238,
8,
1069,
12,
1559,
9,
398,
372,
6183,
4827,
1360,
2535,
2030,
30,
3593,
1108,
2030,
2957,
1360,
5971,
2286,
347,
1570,
63,
1345,
8,
277,
12,
1056,
12,
909,
63,
344,
12,
1824,
63,
633,
4581,
2402,
63,
1100,
29,
403,
304,
267,
340,
291,
14,
16020,
63,
2118,
436,
440,
2281,
63,
13531,
2160,
63,
5568,
315,
1056,
14,
6780,
26,
288,
746,
4760,
5188,
2728,
372,
1613,
8,
26168,
12976,
12,
291,
680,
1461,
63,
1345,
8,
1069,
12,
909,
63,
344,
12,
221,
9144,
1824,
63,
633,
12,
2402,
63,
1100,
9,
339,
347,
21388,
63,
509,
63,
697,
698,
8,
277,
12,
1592,
63,
698,
12,
1011,
958,
304,
267,
408,
267,
11041,
11608,
498,
3938,
340,
22365,
436,
901,
4450,
14830,
63,
354,
267,
408,
267,
21388,
275,
1613,
8,
26168,
12976,
12,
291,
680,
20015,
63,
509,
63,
697,
698,
8,
697,
63,
698,
12,
6684,
755,
1011,
958,
9,
398,
1056,
275,
2074,
14,
1935,
480,
1069,
401,
488,
9,
267,
14830,
63,
354,
275,
1056,
14,
2970,
14,
362,
360,
9010,
63,
354,
358,
267,
14830,
63,
344,
275,
1056,
14,
2970,
14,
362,
360,
9010,
63,
344,
358,
398,
340,
2281,
63,
13531,
2160,
63,
5568,
315,
1056,
14,
6780,
436,
1592,
63,
698,
14,
354,
508,
14830,
63,
354,
26,
288,
21388,
14,
3440,
275,
26401,
3205,
342,
288,
21388,
14,
16020,
63,
9010,
275,
715,
288,
340,
14830,
63,
344,
26,
355,
21388,
14,
2747,
275,
14830,
63,
344,
267,
372,
21388,
339,
347,
664,
63,
3603,
8,
277,
304,
267,
408,
267,
11041,
664,
63,
3603,
370,
2387,
314,
25930,
3145,
1166,
267,
408,
267,
8187,
275,
1613,
8,
26168,
12976,
12,
291,
680,
362,
63,
3603,
342,
398,
2256,
275,
291,
14,
1238,
423,
2024,
14,
571,
63,
1302,
12,
291,
14,
1238,
423,
2024,
14,
578,
63,
354,
267,
3002,
63,
3603,
275,
7970,
8594,
288,
1166,
8,
82,
31996,
6977,
2447,
12774,
15,
1807,
10884,
355,
291,
14,
2113,
63,
2124,
14,
2113,
63,
1345,
8,
277,
14,
12774,
1807,
63,
1345,
395,
355,
536,
5961,
83,
4970,
83,
63,
1807,
390,
2,
450,
2256,
395,
288,
1166,
8,
82,
4289,
12774,
15,
29463,
10884,
355,
291,
14,
2113,
63,
2124,
14,
2113,
63,
1345,
8,
277,
14,
6460,
63,
29463,
395,
355,
536,
5961,
83,
4970,
83,
63,
6460,
29463,
2,
450,
2256,
395,
267,
776,
267,
372,
3002,
63,
3603,
435,
8187,
339,
347,
8308,
63,
29463,
8,
277,
12,
1056,
304,
267,
340,
440,
291,
14,
12751,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
devigned/autorest
|
src/generator/AutoRest.Python.Azure.Tests/Expected/AcceptanceTests/Lro/autorestlongrunningoperationtestservice/models/resource.py
|
32
|
1506
|
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from msrest.serialization import Model
class Resource(Model):
"""Resource.
Variables are only populated by the server, and will be ignored when
sending a request.
:ivar id: Resource Id
:vartype id: str
:ivar type: Resource Type
:vartype type: str
:param tags:
:type tags: dict
:param location: Resource Location
:type location: str
:ivar name: Resource Name
:vartype name: str
"""
_validation = {
'id': {'readonly': True},
'type': {'readonly': True},
'name': {'readonly': True},
}
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
'tags': {'key': 'tags', 'type': '{str}'},
'location': {'key': 'location', 'type': 'str'},
'name': {'key': 'name', 'type': 'str'},
}
def __init__(self, tags=None, location=None):
self.id = None
self.type = None
self.tags = tags
self.location = location
self.name = None
|
mit
|
[
3,
2803,
29,
1624,
13,
24,
199,
3,
24775,
199,
3,
1898,
334,
67,
9,
15332,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
3909,
1334,
314,
10697,
844,
14,
1666,
844,
14,
2424,
315,
314,
2199,
1738,
367,
199,
3,
4190,
2556,
14,
199,
3,
199,
3,
5495,
4046,
701,
15332,
334,
50,
9,
9195,
13726,
5495,
15042,
14,
199,
3,
18784,
1443,
7675,
8927,
5953,
436,
911,
506,
14669,
340,
314,
1233,
365,
199,
3,
31904,
14,
199,
3,
24775,
199,
199,
504,
6605,
3911,
14,
12161,
492,
5822,
421,
199,
533,
7337,
8,
1685,
304,
272,
408,
4031,
14,
339,
17198,
787,
1454,
16460,
701,
314,
1654,
12,
436,
911,
506,
5525,
1380,
272,
10209,
282,
1056,
14,
339,
520,
7725,
1305,
26,
7337,
15418,
272,
520,
19729,
1305,
26,
620,
272,
520,
7725,
730,
26,
7337,
2434,
272,
520,
19729,
730,
26,
620,
272,
520,
635,
3762,
26,
272,
520,
466,
3762,
26,
1211,
272,
520,
635,
2909,
26,
7337,
12625,
272,
520,
466,
2909,
26,
620,
272,
520,
7725,
536,
26,
7337,
2812,
272,
520,
19729,
536,
26,
620,
272,
408,
339,
485,
6136,
275,
469,
267,
283,
344,
356,
791,
6753,
356,
715,
1386,
267,
283,
466,
356,
791,
6753,
356,
715,
1386,
267,
283,
354,
356,
791,
6753,
356,
715,
1386,
272,
789,
339,
485,
3215,
63,
1130,
275,
469,
267,
283,
344,
356,
791,
498,
356,
283,
344,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
466,
356,
791,
498,
356,
283,
466,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
2969,
356,
791,
498,
356,
283,
2969,
297,
283,
466,
356,
5041,
495,
93,
2267,
267,
283,
1985,
356,
791,
498,
356,
283,
1985,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
354,
356,
791,
498,
356,
283,
354,
297,
283,
466,
356,
283,
495,
2267,
272,
789,
339,
347,
636,
826,
721,
277,
12,
3762,
29,
403,
12,
2909,
29,
403,
304,
267,
291,
14,
344,
275,
488,
267,
291,
14,
466,
275,
488,
267,
291,
14,
2969,
275,
3762,
267,
291,
14,
1985,
275,
2909,
267,
291,
14,
354,
275,
488,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2803,
29,
1624,
13,
24,
199,
3,
24775,
199,
3,
1898,
334,
67,
9,
15332,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
3909,
1334,
314,
10697,
844,
14,
1666,
844,
14,
2424,
315,
314,
2199,
1738,
367,
199,
3,
4190,
2556,
14,
199,
3,
199,
3,
5495,
4046,
701,
15332,
334,
50,
9,
9195,
13726,
5495,
15042,
14,
199,
3,
18784,
1443,
7675,
8927,
5953,
436,
911,
506,
14669,
340,
314,
1233,
365,
199,
3,
31904,
14,
199,
3,
24775,
199,
199,
504,
6605,
3911,
14,
12161,
492,
5822,
421,
199,
533,
7337,
8,
1685,
304,
272,
408,
4031,
14,
339,
17198,
787,
1454,
16460,
701,
314,
1654,
12,
436,
911,
506,
5525,
1380,
272,
10209,
282,
1056,
14,
339,
520,
7725,
1305,
26,
7337,
15418,
272,
520,
19729,
1305,
26,
620,
272,
520,
7725,
730,
26,
7337,
2434,
272,
520,
19729,
730,
26,
620,
272,
520,
635,
3762,
26,
272,
520,
466,
3762,
26,
1211,
272,
520,
635,
2909,
26,
7337,
12625,
272,
520,
466,
2909,
26,
620,
272,
520,
7725,
536,
26,
7337,
2812,
272,
520,
19729,
536,
26,
620,
272,
408,
339,
485,
6136,
275,
469,
267,
283,
344,
356,
791,
6753,
356,
715,
1386,
267,
283,
466,
356,
791,
6753,
356,
715,
1386,
267,
283,
354,
356,
791,
6753,
356,
715,
1386,
272,
789,
339,
485,
3215,
63,
1130,
275,
469,
267,
283,
344,
356,
791,
498,
356,
283,
344,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
466,
356,
791,
498,
356,
283,
466,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
2969,
356,
791,
498,
356,
283,
2969,
297,
283,
466,
356,
5041,
495,
93,
2267,
267,
283,
1985,
356,
791,
498,
356,
283,
1985,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
354,
356,
791,
498,
356,
283,
354,
297,
283,
466,
356,
283,
495,
2267,
272,
789,
339,
347,
636,
826,
721,
277,
12,
3762,
29,
403,
12,
2909,
29,
403,
304,
267,
291,
14,
344,
275,
488,
267,
291,
14,
466,
275,
488,
267,
291,
14,
2969,
275,
3762,
267,
291,
14,
1985,
275,
2909,
267,
291,
14,
354,
275,
488,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mrcslws/nupic.research
|
nupic/research/frameworks/dynamic_sparse/networks/__init__.py
|
3
|
1101
|
# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2019, Numenta, Inc. Unless you have an agreement
# with Numenta, Inc., for a separate license for this software code, the
# following terms and conditions apply:
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero Public License for more details.
#
# You should have received a copy of the GNU Affero Public License
# along with this program. If not, see http://www.gnu.org/licenses.
#
# http://numenta.org/licenses/
#
from .gsc import *
from .hebbian import *
from .hebbian_v0 import GSCHeb as GSCHeb_v0
from .layers import *
from .main import *
from .utils import *
from .wideresnet import *
from nupic.research.frameworks.pytorch.models.resnets import resnet18,resnet50
|
agpl-3.0
|
[
3,
221,
22783,
16078,
367,
8883,
24024,
27799,
334,
21988,
26769,
9,
199,
3,
221,
1898,
334,
35,
9,
20312,
12,
22783,
12,
3277,
14,
221,
4158,
1265,
1172,
376,
25025,
199,
3,
221,
543,
22783,
12,
3277,
2020,
367,
282,
7396,
4190,
367,
642,
2032,
1233,
12,
314,
199,
3,
221,
2569,
2895,
436,
3704,
4838,
26,
199,
3,
199,
3,
221,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
221,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1684,
844,
1015,
650,
465,
199,
3,
221,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
221,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
221,
1666,
314,
1664,
4265,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1684,
844,
199,
3,
221,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
199,
3,
221,
1455,
921,
78,
18952,
14,
1308,
15,
2383,
15,
199,
3,
199,
199,
504,
1275,
458,
67,
492,
627,
199,
504,
1275,
426,
2501,
5653,
492,
627,
199,
504,
1275,
426,
2501,
5653,
63,
86,
16,
492,
598,
13900,
2871,
465,
598,
13900,
2871,
63,
86,
16,
199,
504,
1275,
4359,
492,
627,
199,
504,
1275,
973,
492,
627,
199,
504,
1275,
1208,
492,
627,
199,
504,
1275,
13062,
28998,
492,
627,
199,
504,
26084,
14,
31788,
14,
32037,
14,
647,
29676,
14,
992,
14,
470,
20490,
492,
522,
846,
1085,
12,
28998,
1400,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
221,
22783,
16078,
367,
8883,
24024,
27799,
334,
21988,
26769,
9,
199,
3,
221,
1898,
334,
35,
9,
20312,
12,
22783,
12,
3277,
14,
221,
4158,
1265,
1172,
376,
25025,
199,
3,
221,
543,
22783,
12,
3277,
2020,
367,
282,
7396,
4190,
367,
642,
2032,
1233,
12,
314,
199,
3,
221,
2569,
2895,
436,
3704,
4838,
26,
199,
3,
199,
3,
221,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
221,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1684,
844,
1015,
650,
465,
199,
3,
221,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
221,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
221,
1666,
314,
1664,
4265,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1684,
844,
199,
3,
221,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
199,
3,
221,
1455,
921,
78,
18952,
14,
1308,
15,
2383,
15,
199,
3,
199,
199,
504,
1275,
458,
67,
492,
627,
199,
504,
1275,
426,
2501,
5653,
492,
627,
199,
504,
1275,
426,
2501,
5653,
63,
86,
16,
492,
598,
13900,
2871,
465,
598,
13900,
2871,
63,
86,
16,
199,
504,
1275,
4359,
492,
627,
199,
504,
1275,
973,
492,
627,
199,
504,
1275,
1208,
492,
627,
199,
504,
1275,
13062,
28998,
492,
627,
199,
504,
26084,
14,
31788,
14,
32037,
14,
647,
29676,
14,
992,
14,
470,
20490,
492,
522,
846,
1085,
12,
28998,
1400,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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join multiple binary files into single file and generate JSON snippet with offsets
-------------------------------------
How to use
-------------------------------------
python join_ctm.py -i "part_*.ctm" -o joined.ctm [-j offsets.js]
Will read multiple files following wildcard pattern (ordered lexicographically):
part_000.ctm
part_001.ctm
part_002.ctm
...
part_XXX.ctm
And generate single concatenated files:
joined.ctm
offsets.js (optional, offsets are also dumped to standard output)
"""
import getopt
import glob
import sys
import os
# #####################################################
# Templates
# #####################################################
TEMPLATE_JSON = u"""\
"offsets": [ %(offsets)s ],
"""
# #############################################################################
# Helpers
# #############################################################################
def usage():
print 'Usage: %s -i "filename_*.ctm" -o filename.ctm [-j offsets.js]' % os.path.basename(sys.argv[0])
# #####################################################
# Main
# #####################################################
if __name__ == "__main__":
# get parameters from the command line
try:
opts, args = getopt.getopt(sys.argv[1:], "hi:o:j:", ["help", "input=", "output=", "json="])
except getopt.GetoptError:
usage()
sys.exit(2)
inpattern = ""
outname = ""
jsonname = ""
for o, a in opts:
if o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-i", "--input"):
inpattern = a
elif o in ("-o", "--output"):
outname = a
elif o in ("-j", "--json"):
jsonname = a
# quit if required parameters are missing
if inpattern == "" or outname == "":
usage()
sys.exit(2)
outfile = open(outname, "wb")
matches = glob.glob(inpattern)
matches.sort()
total = 0
offsets = []
for filename in matches:
filesize = os.path.getsize(filename)
offsets.append(total)
total += filesize
print filename, filesize
infile = open(filename, "rb")
buffer = infile.read()
outfile.write(buffer)
infile.close()
outfile.close()
json_str = TEMPLATE_JSON % {
"offsets" : ", ".join(["%d" % o for o in offsets])
}
print json_str
if jsonname:
jsonfile = open(jsonname, "w")
jsonfile.write(json_str)
jsonfile.close()
|
mit
|
[
624,
13005,
3663,
3366,
1584,
1901,
2849,
570,
436,
3550,
4840,
17440,
543,
15340,
199,
199,
1444,
9858,
199,
18335,
370,
675,
199,
1444,
9858,
199,
199,
1548,
4263,
63,
319,
77,
14,
647,
446,
73,
298,
2064,
63,
4856,
319,
77,
2,
446,
79,
16538,
14,
319,
77,
5243,
74,
15340,
14,
3596,
61,
199,
199,
20326,
1586,
3663,
1584,
2569,
16792,
3851,
334,
8235,
1026,
30077,
25537,
304,
199,
199,
2064,
63,
1493,
14,
319,
77,
199,
2064,
63,
4587,
14,
319,
77,
199,
2064,
63,
7432,
14,
319,
77,
199,
199,
1396,
199,
199,
2064,
63,
13933,
14,
319,
77,
199,
199,
3325,
3550,
2849,
26271,
1584,
26,
199,
199,
11806,
14,
319,
77,
199,
14253,
14,
3596,
334,
4144,
12,
15340,
787,
2597,
31374,
370,
4465,
1072,
9,
199,
199,
624,
199,
199,
646,
12733,
199,
646,
5739,
199,
646,
984,
199,
646,
747,
199,
199,
3,
26915,
199,
3,
31273,
199,
3,
26915,
199,
7433,
63,
6243,
275,
399,
19659,
199,
2,
14253,
582,
359,
2818,
14253,
9,
83,
2156,
199,
624,
199,
199,
3,
23441,
8776,
199,
3,
11642,
83,
199,
3,
23441,
8776,
199,
318,
4503,
837,
272,
870,
283,
7692,
26,
450,
83,
446,
73,
298,
1501,
63,
4856,
319,
77,
2,
446,
79,
1788,
14,
319,
77,
5243,
74,
15340,
14,
3596,
6616,
450,
747,
14,
515,
14,
4846,
8,
1274,
14,
3020,
59,
16,
566,
199,
199,
3,
26915,
199,
3,
11298,
199,
3,
26915,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
339,
327,
664,
2633,
687,
314,
1414,
1004,
339,
862,
26,
267,
3999,
12,
1249,
275,
12733,
14,
18907,
8,
1274,
14,
3020,
59,
17,
8429,
298,
5812,
26,
79,
26,
74,
6783,
2097,
3437,
401,
298,
1210,
11107,
298,
1199,
11107,
298,
1001,
628,
566,
339,
871,
12733,
14,
1002,
29368,
26,
267,
4503,
342,
267,
984,
14,
2224,
8,
18,
9,
2378,
315,
3401,
275,
3087,
272,
734,
354,
275,
3087,
272,
2022,
354,
275,
3087,
339,
367,
312,
12,
282,
315,
3999,
26,
267,
340,
312,
315,
19372,
72,
401,
4320,
3437,
2349,
288,
4503,
342,
288,
984,
14,
2224,
342,
398,
916,
312,
315,
19372,
73,
401,
4320,
1210,
2349,
288,
315,
3401,
275,
282,
398,
916,
312,
315,
19372,
79,
401,
4320,
1199,
2349,
288,
734,
354,
275,
282,
398,
916,
312,
315,
19372,
74,
401,
4320,
1001,
2349,
288,
2022,
354,
275,
282,
339,
327,
17242,
340,
1415,
2633,
787,
4124,
339,
340,
315,
3401,
508,
3087,
503,
734,
354,
508,
10812,
267,
4503,
342,
267,
984,
14,
2224,
8,
18,
9,
339,
4386,
275,
1551,
8,
548,
354,
12,
298,
6603,
531,
339,
4450,
275,
5739,
14,
6463,
8,
262,
3401,
9,
272,
4450,
14,
3191,
342,
339,
3141,
275,
378,
272,
15340,
275,
942,
339,
367,
1788,
315,
4450,
26,
267,
23858,
275,
747,
14,
515,
14,
20733,
8,
1501,
9,
267,
15340,
14,
740,
8,
2923,
9,
267,
3141,
847,
23858,
398,
870,
1788,
12,
23858,
398,
14734,
275,
1551,
8,
1501,
12,
298,
4848,
531,
267,
3335,
275,
14734,
14,
739,
342,
267,
4386,
14,
952,
8,
2738,
9,
267,
14734,
14,
1600,
342,
339,
4386,
14,
1600,
342,
339,
2022,
63,
495,
275,
24877,
63,
6243,
450,
469,
272,
298,
14253,
2,
520,
3872,
3680,
904,
30387,
68,
2,
450,
312,
367,
312,
315,
15340,
566,
272,
789,
339,
870,
2022,
63,
495,
339,
340,
2022,
354,
26,
267,
2022,
493,
275,
1551,
8,
1001,
354,
12,
298,
87,
531,
267,
2022,
493,
14,
952,
8,
1001,
63,
495,
9,
267,
2022,
493,
14,
1600,
342,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
13005,
3663,
3366,
1584,
1901,
2849,
570,
436,
3550,
4840,
17440,
543,
15340,
199,
199,
1444,
9858,
199,
18335,
370,
675,
199,
1444,
9858,
199,
199,
1548,
4263,
63,
319,
77,
14,
647,
446,
73,
298,
2064,
63,
4856,
319,
77,
2,
446,
79,
16538,
14,
319,
77,
5243,
74,
15340,
14,
3596,
61,
199,
199,
20326,
1586,
3663,
1584,
2569,
16792,
3851,
334,
8235,
1026,
30077,
25537,
304,
199,
199,
2064,
63,
1493,
14,
319,
77,
199,
2064,
63,
4587,
14,
319,
77,
199,
2064,
63,
7432,
14,
319,
77,
199,
199,
1396,
199,
199,
2064,
63,
13933,
14,
319,
77,
199,
199,
3325,
3550,
2849,
26271,
1584,
26,
199,
199,
11806,
14,
319,
77,
199,
14253,
14,
3596,
334,
4144,
12,
15340,
787,
2597,
31374,
370,
4465,
1072,
9,
199,
199,
624,
199,
199,
646,
12733,
199,
646,
5739,
199,
646,
984,
199,
646,
747,
199,
199,
3,
26915,
199,
3,
31273,
199,
3,
26915,
199,
7433,
63,
6243,
275,
399,
19659,
199,
2,
14253,
582,
359,
2818,
14253,
9,
83,
2156,
199,
624,
199,
199,
3,
23441,
8776,
199,
3,
11642,
83,
199,
3,
23441,
8776,
199,
318,
4503,
837,
272,
870,
283,
7692,
26,
450,
83,
446,
73,
298,
1501,
63,
4856,
319,
77,
2,
446,
79,
1788,
14,
319,
77,
5243,
74,
15340,
14,
3596,
6616,
450,
747,
14,
515,
14,
4846,
8,
1274,
14,
3020,
59,
16,
566,
199,
199,
3,
26915,
199,
3,
11298,
199,
3,
26915,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
339,
327,
664,
2633,
687,
314,
1414,
1004,
339,
862,
26,
267,
3999,
12,
1249,
275,
12733,
14,
18907,
8,
1274,
14,
3020,
59,
17,
8429,
298,
5812,
26,
79,
26,
74,
6783,
2097,
3437,
401,
298,
1210,
11107,
298,
1199,
11107,
298,
1001,
628,
566,
339,
871,
12733,
14,
1002,
29368,
26,
267,
4503,
342,
267,
984,
14,
2224,
8,
18,
9,
2378,
315,
3401,
275,
3087,
272,
734,
354,
275,
3087,
272,
2022,
354,
275,
3087,
339,
367,
312,
12,
282,
315,
3999,
26,
267,
340,
312,
315,
19372,
72,
401,
4320,
3437,
2349,
288,
4503,
342,
288,
984,
14,
2224,
342,
398,
916,
312,
315,
19372,
73,
401,
4320,
1210,
2349,
288,
315,
3401,
275,
282,
398,
916,
312,
315,
19372,
79,
401,
4320,
1199,
2349,
288,
734,
354,
275,
282,
398,
916,
312,
315,
19372,
74,
401,
4320,
1001,
2349,
288,
2022,
354,
275,
282,
339,
327,
17242,
340,
1415,
2633,
787,
4124,
339,
340,
315,
3401,
508,
3087,
503,
734,
354,
508,
10812,
267,
4503,
342,
267,
984,
14,
2224,
8,
18,
9,
339,
4386,
275,
1551,
8,
548,
354,
12,
298,
6603,
531,
339,
4450,
275,
5739,
14,
6463,
8,
262,
3401,
9,
272,
4450,
14,
3191,
342,
339,
3141,
275,
378,
272,
15340,
275,
942,
339,
367,
1788,
315,
4450,
26,
267,
23858,
275,
747,
14,
515,
14,
20733,
8,
1501,
9,
267,
15340,
14,
740,
8,
2923,
9,
267,
3141,
847,
23858,
398,
870,
1788,
12,
23858,
398,
14734,
275,
1551,
8,
1501,
12,
298,
4848,
531,
267,
3335,
275,
14734,
14,
739,
342,
267,
4386,
14,
952,
8,
2738,
9,
267,
14734,
14,
1600,
342,
339,
4386,
14,
1600,
342,
339,
2022,
63,
495,
275,
24877,
63,
6243,
450,
469,
272,
298,
14253,
2,
520,
3872,
3680,
904,
30387,
68,
2,
450,
312,
367,
312,
315,
15340,
566,
272,
789,
339,
870,
2022,
63,
495,
339,
340,
2022,
354,
26,
267,
2022,
493,
275,
1551,
8,
1001,
354,
12,
298,
87,
531,
267,
2022,
493,
14,
952,
8,
1001,
63,
495,
9,
267,
2022,
493,
14,
1600,
342,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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
] |
BaladiDogGames/baladidoggames.github.io
|
mingw/bin/lib/xml/sax/expatreader.py
|
72
|
14565
|
"""
SAX driver for the pyexpat C module. This driver works with
pyexpat.__version__ == '2.22'.
"""
version = "0.20"
from xml.sax._exceptions import *
from xml.sax.handler import feature_validation, feature_namespaces
from xml.sax.handler import feature_namespace_prefixes
from xml.sax.handler import feature_external_ges, feature_external_pes
from xml.sax.handler import feature_string_interning
from xml.sax.handler import property_xml_string, property_interning_dict
# xml.parsers.expat does not raise ImportError in Jython
import sys
if sys.platform[:4] == "java":
raise SAXReaderNotAvailable("expat not available in Java", None)
del sys
try:
from xml.parsers import expat
except ImportError:
raise SAXReaderNotAvailable("expat not supported", None)
else:
if not hasattr(expat, "ParserCreate"):
raise SAXReaderNotAvailable("expat not supported", None)
from xml.sax import xmlreader, saxutils, handler
AttributesImpl = xmlreader.AttributesImpl
AttributesNSImpl = xmlreader.AttributesNSImpl
# If we're using a sufficiently recent version of Python, we can use
# weak references to avoid cycles between the parser and content
# handler, otherwise we'll just have to pretend.
try:
import _weakref
except ImportError:
def _mkproxy(o):
return o
else:
import weakref
_mkproxy = weakref.proxy
del weakref, _weakref
# --- ExpatLocator
class ExpatLocator(xmlreader.Locator):
"""Locator for use with the ExpatParser class.
This uses a weak reference to the parser object to avoid creating
a circular reference between the parser and the content handler.
"""
def __init__(self, parser):
self._ref = _mkproxy(parser)
def getColumnNumber(self):
parser = self._ref
if parser._parser is None:
return None
return parser._parser.ErrorColumnNumber
def getLineNumber(self):
parser = self._ref
if parser._parser is None:
return 1
return parser._parser.ErrorLineNumber
def getPublicId(self):
parser = self._ref
if parser is None:
return None
return parser._source.getPublicId()
def getSystemId(self):
parser = self._ref
if parser is None:
return None
return parser._source.getSystemId()
# --- ExpatParser
class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
"""SAX driver for the pyexpat C module."""
def __init__(self, namespaceHandling=0, bufsize=2**16-20):
xmlreader.IncrementalParser.__init__(self, bufsize)
self._source = xmlreader.InputSource()
self._parser = None
self._namespaces = namespaceHandling
self._lex_handler_prop = None
self._parsing = 0
self._entity_stack = []
self._external_ges = 1
self._interning = None
# XMLReader methods
def parse(self, source):
"Parse an XML document from a URL or an InputSource."
source = saxutils.prepare_input_source(source)
self._source = source
self.reset()
self._cont_handler.setDocumentLocator(ExpatLocator(self))
xmlreader.IncrementalParser.parse(self, source)
def prepareParser(self, source):
if source.getSystemId() is not None:
self._parser.SetBase(source.getSystemId())
# Redefined setContentHandler to allow changing handlers during parsing
def setContentHandler(self, handler):
xmlreader.IncrementalParser.setContentHandler(self, handler)
if self._parsing:
self._reset_cont_handler()
def getFeature(self, name):
if name == feature_namespaces:
return self._namespaces
elif name == feature_string_interning:
return self._interning is not None
elif name in (feature_validation, feature_external_pes,
feature_namespace_prefixes):
return 0
elif name == feature_external_ges:
return self._external_ges
raise SAXNotRecognizedException("Feature '%s' not recognized" % name)
def setFeature(self, name, state):
if self._parsing:
raise SAXNotSupportedException("Cannot set features while parsing")
if name == feature_namespaces:
self._namespaces = state
elif name == feature_external_ges:
self._external_ges = state
elif name == feature_string_interning:
if state:
if self._interning is None:
self._interning = {}
else:
self._interning = None
elif name == feature_validation:
if state:
raise SAXNotSupportedException(
"expat does not support validation")
elif name == feature_external_pes:
if state:
raise SAXNotSupportedException(
"expat does not read external parameter entities")
elif name == feature_namespace_prefixes:
if state:
raise SAXNotSupportedException(
"expat does not report namespace prefixes")
else:
raise SAXNotRecognizedException(
"Feature '%s' not recognized" % name)
def getProperty(self, name):
if name == handler.property_lexical_handler:
return self._lex_handler_prop
elif name == property_interning_dict:
return self._interning
elif name == property_xml_string:
if self._parser:
if hasattr(self._parser, "GetInputContext"):
return self._parser.GetInputContext()
else:
raise SAXNotRecognizedException(
"This version of expat does not support getting"
" the XML string")
else:
raise SAXNotSupportedException(
"XML string cannot be returned when not parsing")
raise SAXNotRecognizedException("Property '%s' not recognized" % name)
def setProperty(self, name, value):
if name == handler.property_lexical_handler:
self._lex_handler_prop = value
if self._parsing:
self._reset_lex_handler_prop()
elif name == property_interning_dict:
self._interning = value
elif name == property_xml_string:
raise SAXNotSupportedException("Property '%s' cannot be set" %
name)
else:
raise SAXNotRecognizedException("Property '%s' not recognized" %
name)
# IncrementalParser methods
def feed(self, data, isFinal = 0):
if not self._parsing:
self.reset()
self._parsing = 1
self._cont_handler.startDocument()
try:
# The isFinal parameter is internal to the expat reader.
# If it is set to true, expat will check validity of the entire
# document. When feeding chunks, they are not normally final -
# except when invoked from close.
self._parser.Parse(data, isFinal)
except expat.error, e:
exc = SAXParseException(expat.ErrorString(e.code), e, self)
# FIXME: when to invoke error()?
self._err_handler.fatalError(exc)
def close(self):
if self._entity_stack:
# If we are completing an external entity, do nothing here
return
self.feed("", isFinal = 1)
self._cont_handler.endDocument()
self._parsing = 0
# break cycle created by expat handlers pointing to our methods
self._parser = None
def _reset_cont_handler(self):
self._parser.ProcessingInstructionHandler = \
self._cont_handler.processingInstruction
self._parser.CharacterDataHandler = self._cont_handler.characters
def _reset_lex_handler_prop(self):
lex = self._lex_handler_prop
parser = self._parser
if lex is None:
parser.CommentHandler = None
parser.StartCdataSectionHandler = None
parser.EndCdataSectionHandler = None
parser.StartDoctypeDeclHandler = None
parser.EndDoctypeDeclHandler = None
else:
parser.CommentHandler = lex.comment
parser.StartCdataSectionHandler = lex.startCDATA
parser.EndCdataSectionHandler = lex.endCDATA
parser.StartDoctypeDeclHandler = self.start_doctype_decl
parser.EndDoctypeDeclHandler = lex.endDTD
def reset(self):
if self._namespaces:
self._parser = expat.ParserCreate(self._source.getEncoding(), " ",
intern=self._interning)
self._parser.namespace_prefixes = 1
self._parser.StartElementHandler = self.start_element_ns
self._parser.EndElementHandler = self.end_element_ns
else:
self._parser = expat.ParserCreate(self._source.getEncoding(),
intern = self._interning)
self._parser.StartElementHandler = self.start_element
self._parser.EndElementHandler = self.end_element
self._reset_cont_handler()
self._parser.UnparsedEntityDeclHandler = self.unparsed_entity_decl
self._parser.NotationDeclHandler = self.notation_decl
self._parser.StartNamespaceDeclHandler = self.start_namespace_decl
self._parser.EndNamespaceDeclHandler = self.end_namespace_decl
self._decl_handler_prop = None
if self._lex_handler_prop:
self._reset_lex_handler_prop()
# self._parser.DefaultHandler =
# self._parser.DefaultHandlerExpand =
# self._parser.NotStandaloneHandler =
self._parser.ExternalEntityRefHandler = self.external_entity_ref
try:
self._parser.SkippedEntityHandler = self.skipped_entity_handler
except AttributeError:
# This pyexpat does not support SkippedEntity
pass
self._parser.SetParamEntityParsing(
expat.XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE)
self._parsing = 0
self._entity_stack = []
# Locator methods
def getColumnNumber(self):
if self._parser is None:
return None
return self._parser.ErrorColumnNumber
def getLineNumber(self):
if self._parser is None:
return 1
return self._parser.ErrorLineNumber
def getPublicId(self):
return self._source.getPublicId()
def getSystemId(self):
return self._source.getSystemId()
# event handlers
def start_element(self, name, attrs):
self._cont_handler.startElement(name, AttributesImpl(attrs))
def end_element(self, name):
self._cont_handler.endElement(name)
def start_element_ns(self, name, attrs):
pair = name.split()
if len(pair) == 1:
# no namespace
pair = (None, name)
elif len(pair) == 3:
pair = pair[0], pair[1]
else:
# default namespace
pair = tuple(pair)
newattrs = {}
qnames = {}
for (aname, value) in attrs.items():
parts = aname.split()
length = len(parts)
if length == 1:
# no namespace
qname = aname
apair = (None, aname)
elif length == 3:
qname = "%s:%s" % (parts[2], parts[1])
apair = parts[0], parts[1]
else:
# default namespace
qname = parts[1]
apair = tuple(parts)
newattrs[apair] = value
qnames[apair] = qname
self._cont_handler.startElementNS(pair, None,
AttributesNSImpl(newattrs, qnames))
def end_element_ns(self, name):
pair = name.split()
if len(pair) == 1:
pair = (None, name)
elif len(pair) == 3:
pair = pair[0], pair[1]
else:
pair = tuple(pair)
self._cont_handler.endElementNS(pair, None)
# this is not used (call directly to ContentHandler)
def processing_instruction(self, target, data):
self._cont_handler.processingInstruction(target, data)
# this is not used (call directly to ContentHandler)
def character_data(self, data):
self._cont_handler.characters(data)
def start_namespace_decl(self, prefix, uri):
self._cont_handler.startPrefixMapping(prefix, uri)
def end_namespace_decl(self, prefix):
self._cont_handler.endPrefixMapping(prefix)
def start_doctype_decl(self, name, sysid, pubid, has_internal_subset):
self._lex_handler_prop.startDTD(name, pubid, sysid)
def unparsed_entity_decl(self, name, base, sysid, pubid, notation_name):
self._dtd_handler.unparsedEntityDecl(name, pubid, sysid, notation_name)
def notation_decl(self, name, base, sysid, pubid):
self._dtd_handler.notationDecl(name, pubid, sysid)
def external_entity_ref(self, context, base, sysid, pubid):
if not self._external_ges:
return 1
source = self._ent_handler.resolveEntity(pubid, sysid)
source = saxutils.prepare_input_source(source,
self._source.getSystemId() or
"")
self._entity_stack.append((self._parser, self._source))
self._parser = self._parser.ExternalEntityParserCreate(context)
self._source = source
try:
xmlreader.IncrementalParser.parse(self, source)
except:
return 0 # FIXME: save error info here?
(self._parser, self._source) = self._entity_stack[-1]
del self._entity_stack[-1]
return 1
def skipped_entity_handler(self, name, is_pe):
if is_pe:
# The SAX spec requires to report skipped PEs with a '%'
name = '%'+name
self._cont_handler.skippedEntity(name)
# ---
def create_parser(*args, **kwargs):
return ExpatParser(*args, **kwargs)
# ---
if __name__ == "__main__":
import xml.sax.saxutils
p = create_parser()
p.setContentHandler(xml.sax.saxutils.XMLGenerator())
p.setErrorHandler(xml.sax.ErrorHandler())
p.parse("http://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml")
|
mit
|
[
624,
199,
4251,
56,
5253,
367,
314,
1134,
27098,
445,
859,
14,
221,
961,
5253,
5419,
543,
199,
647,
27098,
855,
1023,
363,
508,
283,
18,
14,
1081,
1370,
199,
624,
199,
199,
1023,
275,
298,
16,
14,
1165,
2,
199,
199,
504,
2748,
14,
14338,
423,
3924,
492,
627,
199,
504,
2748,
14,
14338,
14,
2232,
492,
3878,
63,
6136,
12,
3878,
63,
9247,
199,
504,
2748,
14,
14338,
14,
2232,
492,
3878,
63,
3251,
63,
14124,
199,
504,
2748,
14,
14338,
14,
2232,
492,
3878,
63,
5159,
63,
3389,
12,
3878,
63,
5159,
63,
22020,
199,
504,
2748,
14,
14338,
14,
2232,
492,
3878,
63,
875,
63,
1058,
1835,
199,
504,
2748,
14,
14338,
14,
2232,
492,
3324,
63,
1652,
63,
875,
12,
3324,
63,
1058,
1835,
63,
807,
199,
199,
3,
2748,
14,
11531,
14,
27098,
1630,
440,
746,
3545,
315,
25333,
199,
646,
984,
199,
692,
984,
14,
3246,
1491,
20,
61,
508,
298,
6138,
582,
272,
746,
19310,
5929,
1763,
11464,
480,
27098,
440,
2808,
315,
9586,
401,
488,
9,
199,
2264,
984,
199,
199,
893,
26,
272,
687,
2748,
14,
11531,
492,
31905,
199,
2590,
3545,
26,
272,
746,
19310,
5929,
1763,
11464,
480,
27098,
440,
3748,
401,
488,
9,
199,
2836,
26,
272,
340,
440,
2688,
8,
27098,
12,
298,
2842,
2499,
2349,
267,
746,
19310,
5929,
1763,
11464,
480,
27098,
440,
3748,
401,
488,
9,
199,
504,
2748,
14,
14338,
492,
2748,
5503,
12,
308,
1219,
1208,
12,
3016,
199,
199,
5379,
4748,
275,
2748,
5503,
14,
5379,
4748,
199,
5379,
46,
2684,
2421,
275,
2748,
5503,
14,
5379,
46,
2684,
2421,
199,
199,
3,
982,
781,
3984,
1808,
282,
19258,
590,
8058,
1015,
402,
2018,
12,
781,
883,
675,
199,
3,
9282,
6941,
370,
5126,
19001,
3382,
314,
1798,
436,
1564,
199,
3,
3016,
12,
4257,
781,
7171,
2951,
1172,
370,
27830,
14,
199,
893,
26,
272,
492,
485,
21330,
199,
2590,
3545,
26,
272,
347,
485,
3880,
3280,
8,
79,
304,
267,
372,
312,
199,
2836,
26,
272,
492,
13852,
272,
485,
3880,
3280,
275,
13852,
14,
3280,
272,
2150,
13852,
12,
485,
21330,
199,
199,
3,
10894,
7910,
292,
10725,
199,
199,
533,
7910,
292,
10725,
8,
1652,
5503,
14,
10725,
304,
272,
408,
10725,
367,
675,
543,
314,
7910,
292,
2842,
1021,
14,
339,
961,
4440,
282,
9282,
3659,
370,
314,
1798,
909,
370,
5126,
6425,
272,
282,
15032,
3659,
3382,
314,
1798,
436,
314,
1564,
3016,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1798,
304,
267,
291,
423,
1121,
275,
485,
3880,
3280,
8,
2087,
9,
339,
347,
664,
4547,
3259,
8,
277,
304,
267,
1798,
275,
291,
423,
1121,
267,
340,
1798,
423,
2087,
365,
488,
26,
288,
372,
488,
267,
372,
1798,
423,
2087,
14,
547,
4547,
3259,
339,
347,
664,
3049,
3259,
8,
277,
304,
267,
1798,
275,
291,
423,
1121,
267,
340,
1798,
423,
2087,
365,
488,
26,
288,
372,
413,
267,
372,
1798,
423,
2087,
14,
547,
3049,
3259,
339,
347,
664,
9885,
1304,
8,
277,
304,
267,
1798,
275,
291,
423,
1121,
267,
340,
1798,
365,
488,
26,
288,
372,
488,
267,
372,
1798,
423,
1365,
14,
362,
9885,
1304,
342,
339,
347,
664,
28440,
8,
277,
304,
267,
1798,
275,
291,
423,
1121,
267,
340,
1798,
365,
488,
26,
288,
372,
488,
267,
372,
1798,
423,
1365,
14,
362,
28440,
342,
421,
199,
3,
10894,
7910,
292,
2842,
199,
199,
533,
7910,
292,
2842,
8,
1652,
5503,
14,
10287,
2842,
12,
2748,
5503,
14,
10725,
304,
272,
408,
4251,
56,
5253,
367,
314,
1134,
27098,
445,
859,
1041,
339,
347,
636,
826,
721,
277,
12,
3231,
26443,
29,
16,
12,
17080,
29,
18,
538,
975,
13,
1165,
304,
267,
2748,
5503,
14,
10287,
2842,
855,
826,
721,
277,
12,
17080,
9,
267,
291,
423,
1365,
275,
2748,
5503,
14,
3205,
2980,
342,
267,
291,
423,
2087,
275,
488,
267,
291,
423,
9247,
275,
3231,
26443,
267,
291,
423,
3113,
63,
2232,
63,
4469,
275,
488,
267,
291,
423,
11059,
275,
378,
267,
291,
423,
4502,
63,
2340,
275,
942,
267,
291,
423,
5159,
63,
3389,
275,
413,
267,
291,
423,
1058,
1835,
275,
488,
339,
327,
4692,
5929,
3102,
339,
347,
2198,
8,
277,
12,
1350,
304,
267,
298,
4003,
376,
4692,
2213,
687,
282,
2851,
503,
376,
6924,
2980,
2122,
267,
1350,
275,
308,
1219,
1208,
14,
6726,
63,
1210,
63,
1365,
8,
1365,
9,
398,
291,
423,
1365,
275,
1350,
267,
291,
14,
3958,
342,
267,
291,
423,
11096,
63,
2232,
14,
409,
5564,
10725,
8,
4527,
292,
10725,
8,
277,
430,
267,
2748,
5503,
14,
10287,
2842,
14,
1122,
8,
277,
12,
1350,
9,
339,
347,
9275,
2842,
8,
277,
12,
1350,
304,
267,
340,
1350,
14,
362,
28440,
342,
365,
440,
488,
26,
288,
291,
423,
2087,
14,
1084,
1563,
8,
1365,
14,
362,
28440,
1012,
339,
327,
799,
4037,
663,
2714,
2461,
370,
2040,
13729,
8297,
5309,
6057,
339,
347,
663,
2714,
2461,
8,
277,
12,
3016,
304,
267,
2748,
5503,
14,
10287,
2842,
14,
28680,
2461,
8,
277,
12,
3016,
9,
267,
340,
291,
423,
11059,
26,
288,
291,
423,
3958,
63,
11096,
63,
2232,
342,
339,
347,
664,
5968,
8,
277,
12,
536,
304,
267,
340,
536,
508,
3878,
63,
9247,
26,
288,
372,
291,
423,
9247,
267,
916,
536,
508,
3878,
63,
875,
63,
1058,
1835,
26,
288,
372,
291,
423,
1058,
1835,
365,
440,
488,
267,
916,
536,
315,
334,
4445,
63,
6136,
12,
3878,
63,
5159,
63,
22020,
12,
1993,
3878,
63,
3251,
63,
14124,
304,
288,
372,
378,
267,
916,
536,
508,
3878,
63,
5159,
63,
3389,
26,
288,
372,
291,
423,
5159,
63,
3389,
267,
746,
19310,
1763,
497,
9659,
1726,
480,
5968,
1543,
83,
7,
440,
18054,
2,
450,
536,
9,
339,
347,
663,
5968,
8,
277,
12,
536,
12,
1174,
304,
267,
340,
291,
423,
11059,
26,
288,
746,
19310,
26077,
1726,
480,
6612,
663,
4534,
1830,
6057,
531,
398,
340,
536,
508,
3878,
63,
9247,
26,
288,
291,
423,
9247,
275,
1174,
267,
916,
536,
508,
3878,
63,
5159,
63,
3389,
26,
288,
291,
423,
5159
] |
[
199,
4251,
56,
5253,
367,
314,
1134,
27098,
445,
859,
14,
221,
961,
5253,
5419,
543,
199,
647,
27098,
855,
1023,
363,
508,
283,
18,
14,
1081,
1370,
199,
624,
199,
199,
1023,
275,
298,
16,
14,
1165,
2,
199,
199,
504,
2748,
14,
14338,
423,
3924,
492,
627,
199,
504,
2748,
14,
14338,
14,
2232,
492,
3878,
63,
6136,
12,
3878,
63,
9247,
199,
504,
2748,
14,
14338,
14,
2232,
492,
3878,
63,
3251,
63,
14124,
199,
504,
2748,
14,
14338,
14,
2232,
492,
3878,
63,
5159,
63,
3389,
12,
3878,
63,
5159,
63,
22020,
199,
504,
2748,
14,
14338,
14,
2232,
492,
3878,
63,
875,
63,
1058,
1835,
199,
504,
2748,
14,
14338,
14,
2232,
492,
3324,
63,
1652,
63,
875,
12,
3324,
63,
1058,
1835,
63,
807,
199,
199,
3,
2748,
14,
11531,
14,
27098,
1630,
440,
746,
3545,
315,
25333,
199,
646,
984,
199,
692,
984,
14,
3246,
1491,
20,
61,
508,
298,
6138,
582,
272,
746,
19310,
5929,
1763,
11464,
480,
27098,
440,
2808,
315,
9586,
401,
488,
9,
199,
2264,
984,
199,
199,
893,
26,
272,
687,
2748,
14,
11531,
492,
31905,
199,
2590,
3545,
26,
272,
746,
19310,
5929,
1763,
11464,
480,
27098,
440,
3748,
401,
488,
9,
199,
2836,
26,
272,
340,
440,
2688,
8,
27098,
12,
298,
2842,
2499,
2349,
267,
746,
19310,
5929,
1763,
11464,
480,
27098,
440,
3748,
401,
488,
9,
199,
504,
2748,
14,
14338,
492,
2748,
5503,
12,
308,
1219,
1208,
12,
3016,
199,
199,
5379,
4748,
275,
2748,
5503,
14,
5379,
4748,
199,
5379,
46,
2684,
2421,
275,
2748,
5503,
14,
5379,
46,
2684,
2421,
199,
199,
3,
982,
781,
3984,
1808,
282,
19258,
590,
8058,
1015,
402,
2018,
12,
781,
883,
675,
199,
3,
9282,
6941,
370,
5126,
19001,
3382,
314,
1798,
436,
1564,
199,
3,
3016,
12,
4257,
781,
7171,
2951,
1172,
370,
27830,
14,
199,
893,
26,
272,
492,
485,
21330,
199,
2590,
3545,
26,
272,
347,
485,
3880,
3280,
8,
79,
304,
267,
372,
312,
199,
2836,
26,
272,
492,
13852,
272,
485,
3880,
3280,
275,
13852,
14,
3280,
272,
2150,
13852,
12,
485,
21330,
199,
199,
3,
10894,
7910,
292,
10725,
199,
199,
533,
7910,
292,
10725,
8,
1652,
5503,
14,
10725,
304,
272,
408,
10725,
367,
675,
543,
314,
7910,
292,
2842,
1021,
14,
339,
961,
4440,
282,
9282,
3659,
370,
314,
1798,
909,
370,
5126,
6425,
272,
282,
15032,
3659,
3382,
314,
1798,
436,
314,
1564,
3016,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1798,
304,
267,
291,
423,
1121,
275,
485,
3880,
3280,
8,
2087,
9,
339,
347,
664,
4547,
3259,
8,
277,
304,
267,
1798,
275,
291,
423,
1121,
267,
340,
1798,
423,
2087,
365,
488,
26,
288,
372,
488,
267,
372,
1798,
423,
2087,
14,
547,
4547,
3259,
339,
347,
664,
3049,
3259,
8,
277,
304,
267,
1798,
275,
291,
423,
1121,
267,
340,
1798,
423,
2087,
365,
488,
26,
288,
372,
413,
267,
372,
1798,
423,
2087,
14,
547,
3049,
3259,
339,
347,
664,
9885,
1304,
8,
277,
304,
267,
1798,
275,
291,
423,
1121,
267,
340,
1798,
365,
488,
26,
288,
372,
488,
267,
372,
1798,
423,
1365,
14,
362,
9885,
1304,
342,
339,
347,
664,
28440,
8,
277,
304,
267,
1798,
275,
291,
423,
1121,
267,
340,
1798,
365,
488,
26,
288,
372,
488,
267,
372,
1798,
423,
1365,
14,
362,
28440,
342,
421,
199,
3,
10894,
7910,
292,
2842,
199,
199,
533,
7910,
292,
2842,
8,
1652,
5503,
14,
10287,
2842,
12,
2748,
5503,
14,
10725,
304,
272,
408,
4251,
56,
5253,
367,
314,
1134,
27098,
445,
859,
1041,
339,
347,
636,
826,
721,
277,
12,
3231,
26443,
29,
16,
12,
17080,
29,
18,
538,
975,
13,
1165,
304,
267,
2748,
5503,
14,
10287,
2842,
855,
826,
721,
277,
12,
17080,
9,
267,
291,
423,
1365,
275,
2748,
5503,
14,
3205,
2980,
342,
267,
291,
423,
2087,
275,
488,
267,
291,
423,
9247,
275,
3231,
26443,
267,
291,
423,
3113,
63,
2232,
63,
4469,
275,
488,
267,
291,
423,
11059,
275,
378,
267,
291,
423,
4502,
63,
2340,
275,
942,
267,
291,
423,
5159,
63,
3389,
275,
413,
267,
291,
423,
1058,
1835,
275,
488,
339,
327,
4692,
5929,
3102,
339,
347,
2198,
8,
277,
12,
1350,
304,
267,
298,
4003,
376,
4692,
2213,
687,
282,
2851,
503,
376,
6924,
2980,
2122,
267,
1350,
275,
308,
1219,
1208,
14,
6726,
63,
1210,
63,
1365,
8,
1365,
9,
398,
291,
423,
1365,
275,
1350,
267,
291,
14,
3958,
342,
267,
291,
423,
11096,
63,
2232,
14,
409,
5564,
10725,
8,
4527,
292,
10725,
8,
277,
430,
267,
2748,
5503,
14,
10287,
2842,
14,
1122,
8,
277,
12,
1350,
9,
339,
347,
9275,
2842,
8,
277,
12,
1350,
304,
267,
340,
1350,
14,
362,
28440,
342,
365,
440,
488,
26,
288,
291,
423,
2087,
14,
1084,
1563,
8,
1365,
14,
362,
28440,
1012,
339,
327,
799,
4037,
663,
2714,
2461,
370,
2040,
13729,
8297,
5309,
6057,
339,
347,
663,
2714,
2461,
8,
277,
12,
3016,
304,
267,
2748,
5503,
14,
10287,
2842,
14,
28680,
2461,
8,
277,
12,
3016,
9,
267,
340,
291,
423,
11059,
26,
288,
291,
423,
3958,
63,
11096,
63,
2232,
342,
339,
347,
664,
5968,
8,
277,
12,
536,
304,
267,
340,
536,
508,
3878,
63,
9247,
26,
288,
372,
291,
423,
9247,
267,
916,
536,
508,
3878,
63,
875,
63,
1058,
1835,
26,
288,
372,
291,
423,
1058,
1835,
365,
440,
488,
267,
916,
536,
315,
334,
4445,
63,
6136,
12,
3878,
63,
5159,
63,
22020,
12,
1993,
3878,
63,
3251,
63,
14124,
304,
288,
372,
378,
267,
916,
536,
508,
3878,
63,
5159,
63,
3389,
26,
288,
372,
291,
423,
5159,
63,
3389,
267,
746,
19310,
1763,
497,
9659,
1726,
480,
5968,
1543,
83,
7,
440,
18054,
2,
450,
536,
9,
339,
347,
663,
5968,
8,
277,
12,
536,
12,
1174,
304,
267,
340,
291,
423,
11059,
26,
288,
746,
19310,
26077,
1726,
480,
6612,
663,
4534,
1830,
6057,
531,
398,
340,
536,
508,
3878,
63,
9247,
26,
288,
291,
423,
9247,
275,
1174,
267,
916,
536,
508,
3878,
63,
5159,
63,
3389,
26,
288,
291,
423,
5159,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
RohitDas/cubeproject
|
lib/django/contrib/gis/db/models/proxy.py
|
164
|
2605
|
"""
The GeometryProxy object, allows for lazy-geometries. The proxy uses
Python descriptors for instantiating and setting Geometry objects
corresponding to geographic model fields.
Thanks to Robert Coup for providing this functionality (see #4322).
"""
from django.utils import six
class GeometryProxy(object):
def __init__(self, klass, field):
"""
Proxy initializes on the given Geometry class (not an instance) and
the GeometryField.
"""
self._field = field
self._klass = klass
def __get__(self, obj, type=None):
"""
This accessor retrieves the geometry, initializing it using the geometry
class specified during initialization and the HEXEWKB value of the field.
Currently, only GEOS or OGR geometries are supported.
"""
if obj is None:
# Accessed on a class, not an instance
return self
# Getting the value of the field.
geom_value = obj.__dict__[self._field.attname]
if isinstance(geom_value, self._klass):
geom = geom_value
elif (geom_value is None) or (geom_value == ''):
geom = None
else:
# Otherwise, a Geometry object is built using the field's contents,
# and the model's corresponding attribute is set.
geom = self._klass(geom_value)
setattr(obj, self._field.attname, geom)
return geom
def __set__(self, obj, value):
"""
This accessor sets the proxied geometry with the geometry class
specified during initialization. Values of None, HEXEWKB, or WKT may
be used to set the geometry as well.
"""
# The OGC Geometry type of the field.
gtype = self._field.geom_type
# The geometry type must match that of the field -- unless the
# general GeometryField is used.
if isinstance(value, self._klass) and (str(value.geom_type).upper() == gtype or gtype == 'GEOMETRY'):
# Assigning the SRID to the geometry.
if value.srid is None:
value.srid = self._field.srid
elif value is None or isinstance(value, six.string_types + (six.memoryview,)):
# Set with None, WKT, HEX, or WKB
pass
else:
raise TypeError('Cannot set %s GeometryProxy (%s) with value of type: %s' % (
obj.__class__.__name__, gtype, type(value)))
# Setting the objects dictionary with the value, and returning.
obj.__dict__[self._field.attname] = value
return value
|
bsd-3-clause
|
[
624,
199,
1918,
10579,
4936,
909,
12,
6127,
367,
9617,
13,
21626,
14,
221,
710,
4566,
4440,
199,
4718,
15428,
367,
9034,
1958,
436,
4260,
10579,
2251,
199,
989,
31137,
370,
25637,
1402,
1504,
14,
199,
199,
2719,
25088,
370,
6848,
12504,
1849,
384,
367,
13070,
642,
9330,
334,
3239,
327,
10657,
18,
680,
199,
624,
199,
504,
1639,
14,
1208,
492,
3816,
421,
199,
533,
10579,
4936,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
8531,
12,
901,
304,
267,
408,
267,
12373,
2536,
6491,
641,
314,
1627,
10579,
1021,
334,
1397,
376,
1256,
9,
436,
267,
314,
30490,
14,
267,
408,
267,
291,
423,
698,
275,
901,
267,
291,
423,
11645,
275,
8531,
339,
347,
636,
362,
721,
277,
12,
1559,
12,
730,
29,
403,
304,
267,
408,
267,
961,
19474,
9619,
2310,
314,
3400,
12,
29141,
652,
1808,
314,
3400,
267,
1021,
2013,
5309,
11097,
436,
314,
869,
23017,
28328,
574,
402,
314,
901,
14,
267,
13550,
12,
1454,
11920,
503,
10904,
24883,
787,
3748,
14,
267,
408,
267,
340,
1559,
365,
488,
26,
288,
327,
4473,
4234,
641,
282,
1021,
12,
440,
376,
1256,
288,
372,
291,
398,
327,
20703,
314,
574,
402,
314,
901,
14,
267,
9671,
63,
585,
275,
1559,
855,
807,
12298,
277,
423,
698,
14,
13651,
61,
398,
340,
1228,
8,
6481,
63,
585,
12,
291,
423,
11645,
304,
288,
9671,
275,
9671,
63,
585,
267,
916,
334,
6481,
63,
585,
365,
488,
9,
503,
334,
6481,
63,
585,
508,
21019,
288,
9671,
275,
488,
267,
587,
26,
288,
327,
6630,
12,
282,
10579,
909,
365,
6137,
1808,
314,
901,
1159,
4072,
12,
288,
327,
436,
314,
1402,
1159,
5226,
2225,
365,
663,
14,
288,
9671,
275,
291,
423,
11645,
8,
6481,
63,
585,
9,
288,
5371,
8,
1113,
12,
291,
423,
698,
14,
13651,
12,
9671,
9,
267,
372,
9671,
339,
347,
636,
409,
721,
277,
12,
1559,
12,
574,
304,
267,
408,
267,
961,
19474,
5951,
314,
10645,
5299,
3400,
543,
314,
3400,
1021,
267,
2013,
5309,
11097,
14,
221,
13468,
402,
488,
12,
869,
23017,
28328,
12,
503,
22561,
1443,
267,
506,
1202,
370,
663,
314,
3400,
465,
5521,
14,
267,
408,
267,
327,
710,
593,
7484,
10579,
730,
402,
314,
901,
14,
267,
486,
466,
275,
291,
423,
698,
14,
6481,
63,
466,
398,
327,
710,
3400,
730,
1471,
1336,
626,
402,
314,
901,
1553,
7444,
314,
267,
327,
8605,
30490,
365,
1202,
14,
267,
340,
1228,
8,
585,
12,
291,
423,
11645,
9,
436,
334,
495,
8,
585,
14,
6481,
63,
466,
680,
4142,
342,
508,
486,
466,
503,
486,
466,
508,
283,
28472,
735,
288,
327,
16927,
316,
314,
22425,
370,
314,
3400,
14,
288,
340,
574,
14,
10498,
365,
488,
26,
355,
574,
14,
10498,
275,
291,
423,
698,
14,
10498,
267,
916,
574,
365,
488,
503,
1228,
8,
585,
12,
3816,
14,
875,
63,
1313,
435,
334,
4174,
14,
31519,
12,
2298,
288,
327,
2494,
543,
488,
12,
22561,
12,
29467,
12,
503,
644,
12780,
288,
986,
267,
587,
26,
288,
746,
3146,
360,
6612,
663,
450,
83,
10579,
4936,
4366,
83,
9,
543,
574,
402,
730,
26,
450,
83,
7,
450,
334,
355,
1559,
855,
533,
4914,
354,
3108,
486,
466,
12,
730,
8,
585,
1724,
398,
327,
13510,
314,
2251,
2600,
543,
314,
574,
12,
436,
8152,
14,
267,
1559,
855,
807,
12298,
277,
423,
698,
14,
13651,
61,
275,
574,
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
] |
[
199,
1918,
10579,
4936,
909,
12,
6127,
367,
9617,
13,
21626,
14,
221,
710,
4566,
4440,
199,
4718,
15428,
367,
9034,
1958,
436,
4260,
10579,
2251,
199,
989,
31137,
370,
25637,
1402,
1504,
14,
199,
199,
2719,
25088,
370,
6848,
12504,
1849,
384,
367,
13070,
642,
9330,
334,
3239,
327,
10657,
18,
680,
199,
624,
199,
504,
1639,
14,
1208,
492,
3816,
421,
199,
533,
10579,
4936,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
8531,
12,
901,
304,
267,
408,
267,
12373,
2536,
6491,
641,
314,
1627,
10579,
1021,
334,
1397,
376,
1256,
9,
436,
267,
314,
30490,
14,
267,
408,
267,
291,
423,
698,
275,
901,
267,
291,
423,
11645,
275,
8531,
339,
347,
636,
362,
721,
277,
12,
1559,
12,
730,
29,
403,
304,
267,
408,
267,
961,
19474,
9619,
2310,
314,
3400,
12,
29141,
652,
1808,
314,
3400,
267,
1021,
2013,
5309,
11097,
436,
314,
869,
23017,
28328,
574,
402,
314,
901,
14,
267,
13550,
12,
1454,
11920,
503,
10904,
24883,
787,
3748,
14,
267,
408,
267,
340,
1559,
365,
488,
26,
288,
327,
4473,
4234,
641,
282,
1021,
12,
440,
376,
1256,
288,
372,
291,
398,
327,
20703,
314,
574,
402,
314,
901,
14,
267,
9671,
63,
585,
275,
1559,
855,
807,
12298,
277,
423,
698,
14,
13651,
61,
398,
340,
1228,
8,
6481,
63,
585,
12,
291,
423,
11645,
304,
288,
9671,
275,
9671,
63,
585,
267,
916,
334,
6481,
63,
585,
365,
488,
9,
503,
334,
6481,
63,
585,
508,
21019,
288,
9671,
275,
488,
267,
587,
26,
288,
327,
6630,
12,
282,
10579,
909,
365,
6137,
1808,
314,
901,
1159,
4072,
12,
288,
327,
436,
314,
1402,
1159,
5226,
2225,
365,
663,
14,
288,
9671,
275,
291,
423,
11645,
8,
6481,
63,
585,
9,
288,
5371,
8,
1113,
12,
291,
423,
698,
14,
13651,
12,
9671,
9,
267,
372,
9671,
339,
347,
636,
409,
721,
277,
12,
1559,
12,
574,
304,
267,
408,
267,
961,
19474,
5951,
314,
10645,
5299,
3400,
543,
314,
3400,
1021,
267,
2013,
5309,
11097,
14,
221,
13468,
402,
488,
12,
869,
23017,
28328,
12,
503,
22561,
1443,
267,
506,
1202,
370,
663,
314,
3400,
465,
5521,
14,
267,
408,
267,
327,
710,
593,
7484,
10579,
730,
402,
314,
901,
14,
267,
486,
466,
275,
291,
423,
698,
14,
6481,
63,
466,
398,
327,
710,
3400,
730,
1471,
1336,
626,
402,
314,
901,
1553,
7444,
314,
267,
327,
8605,
30490,
365,
1202,
14,
267,
340,
1228,
8,
585,
12,
291,
423,
11645,
9,
436,
334,
495,
8,
585,
14,
6481,
63,
466,
680,
4142,
342,
508,
486,
466,
503,
486,
466,
508,
283,
28472,
735,
288,
327,
16927,
316,
314,
22425,
370,
314,
3400,
14,
288,
340,
574,
14,
10498,
365,
488,
26,
355,
574,
14,
10498,
275,
291,
423,
698,
14,
10498,
267,
916,
574,
365,
488,
503,
1228,
8,
585,
12,
3816,
14,
875,
63,
1313,
435,
334,
4174,
14,
31519,
12,
2298,
288,
327,
2494,
543,
488,
12,
22561,
12,
29467,
12,
503,
644,
12780,
288,
986,
267,
587,
26,
288,
746,
3146,
360,
6612,
663,
450,
83,
10579,
4936,
4366,
83,
9,
543,
574,
402,
730,
26,
450,
83,
7,
450,
334,
355,
1559,
855,
533,
4914,
354,
3108,
486,
466,
12,
730,
8,
585,
1724,
398,
327,
13510,
314,
2251,
2600,
543,
314,
574,
12,
436,
8152,
14,
267,
1559,
855,
807,
12298,
277,
423,
698,
14,
13651,
61,
275,
574,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sstjohn/pox
|
pox/messenger/__init__.py
|
25
|
19645
|
# Copyright 2011,2012 James McCauley
#
# This file is part of POX.
#
# POX 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.
#
# POX 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 POX. If not, see <http://www.gnu.org/licenses/>.
"""
The POX Messenger system.
The Messenger system is a way to build services in POX that can be
consumed by external clients.
Sometimes a controller might need to interact with the outside world.
Sometimes you need to integrate with an existing piece of software and
maybe you don't get to choose how you communicate with it. Other times,
you have the opportunity and burden of rolling your own. The Messenger
system is meant to help you with the latter case.
In short, channels are a system for communicating between POX and
external programs by exchanging messages encoded in JSON. It is intended
to be quite general, both in the communication models it supports and in
the transports is supports (as of this writing, it supports a
straightforward TCP socket transport and an HTTP transport). Any
service written to use the Messenger should theoretically be usable via
any transport.
*Connections* are somehow established when a client connects via some
*Transport*. The server can individually send messages to a specific client.
A client can send messages to a *Channel* on the server. A client can also
become a member of a channel, after which it will receive any messages
the server sends to that channel. There is always a default channel with
no name.
Channels can either be permanent or temporary. Temporary channels are
automatically destroyed when they no longer contain any members.
"""
from pox.lib.revent.revent import *
from pox.core import core as core
import json
import time
import random
import hashlib
from base64 import b32encode
log = core.getLogger()
# JSON decoder used by default
defaultDecoder = json.JSONDecoder()
class ChannelJoin (Event):
""" Fired on a channel when a client joins. """
def __init__ (self, connection, channel, msg = {}):
Event.__init__(self)
self.con = connection
self.channel = channel
self.msg = msg
class ConnectionClosed (Event):
""" Fired on a connection when it closes. """
def __init__ (self, connection):
Event.__init__(self)
self.con = connection
class ChannelLeave (Event):
""" Fired on a channel when a client leaves. """
def __init__ (self, connection, channel):
Event.__init__(self)
self.con = connection
self.channel = channel
class ChannelCreate (Event):
""" Fired on a Nexus when a channel is created. """
def __init__ (self, channel):
Event.__init__(self)
self.channel = channel
class ChannelDestroy (Event):
"""
Fired on the channel and its Nexus right before a channel is destroyed.
Set .keep = True to keep the channel after all.
"""
def __init__ (self, channel):
Event.__init__(self)
self.channel = channel
self.keep = False
class ChannelDestroyed (Event):
"""
Fired on the channel and its Nexus right after a channel is destroyed.
"""
def __init__ (self, channel):
Event.__init__(self)
self.channel = channel
class MissingChannel (Event):
"""
Fired on a Nexus when a message has been received to a non-existant channel.
You can create the channel in response to this.
"""
def __init__ (self, connection, channel_name, msg):
Event.__init__(self)
self.con = connection
self.channel_name = channel_name
self.msg = msg
class MessageReceived (Event):
"""
Fired by a channel when a message has been receieved.
Always fired on the Connection itself. Also fired on the corresponding
Channel object as specified by the CHANNEL key.
The listener looks like:
def _handle_MessageReceived (event, msg):
"""
def __init__ (self, connection, channel, msg):
Event.__init__(self)
self.con = connection
self.msg = msg
self.channel = channel
def is_to_channel (self, channel):
"""
Returns True if this message is to the given channel
"""
if isinstance(channel, Channel):
channel = channel.name
if channel == self.channel: return True
if channel in self.channel: return True
return False
def _invoke (self, handler, *args, **kw):
# Special handling -- pass the message
return handler(self, self.msg, *args, **kw)
def _get_nexus (nexus):
if nexus is None: nexus = "MessengerNexus"
if isinstance(nexus, str):
if not core.hasComponent(nexus):
#TODO: Wait for channel Nexus
s = "MessengerNexus %s is not available" % (nexus,)
log.error(s)
raise RuntimeError(s)
return getattr(core, nexus)
assert isinstance(nexus, MessengerNexus)
return nexus
class Transport (object):
def __init__ (self, nexus):
self._nexus = _get_nexus(nexus)
def _forget (self, connection):
""" Forget about a connection """
raise RuntimeError("Not implemented")
class Connection (EventMixin):
"""
Superclass for Connections.
This could actually be a bit thinner, if someone wants to clean it up.
Maintains the state and handles message parsing and dispatch for a
single connection.
"""
_eventMixin_events = set([
MessageReceived,
ConnectionClosed,
])
def __init__ (self, transport):
"""
transport is the source of the connection (e.g, TCPTransport).
"""
EventMixin.__init__(self)
self._is_connected = True
self._transport = transport
self._newlines = False
# Transports that don't do their own encapsulation can use _recv_raw(),
# which uses this. (Such should probably be broken into a subclass.)
self._buf = bytes()
key,num = self._transport._nexus.generate_session()
self._session_id,self._session_num = key,num
def _send_welcome (self):
"""
Send a message to a client so they know they're connected
"""
self.send({"CHANNEL":"","cmd":"welcome","session_id":self._session_id})
def _close (self):
"""
Called internally to shut the connection down.
"""
if self._is_connected is False: return
self._transport._forget(self)
self._is_connected = False
for name,chan in self._transport._nexus._channels.items():
chan._remove_member(self)
self.raiseEventNoErrors(ConnectionClosed, self)
#self._transport._nexus.raiseEventNoErrors(ConnectionClosed, self)
def send (self, whatever):
"""
Send data over the connection.
It will first be encoded into JSON, and optionally followed with
a newline. Ultimately, it will be passed to send_raw() to actually
be sent.
"""
if self._is_connected is False: return False
s = json.dumps(whatever, default=str)
if self._newlines: s += "\n"
self.send_raw(s)
return True
def send_raw (self, data):
"""
This method should actually send data out over the connection.
Subclasses need to implement this.
"""
raise RuntimeError("Not implemented")
@property
def is_connected (self):
"""
True if this Connection is still connected.
"""
return self._is_connected
def _rx_message (self, msg):
"""
Raises events when a complete message is available.
Subclasses may want to call this when they have a new message
available. See _recv_raw().
"""
e = self.raiseEventNoErrors(MessageReceived,self,msg.get('CHANNEL'),msg)
self._transport._nexus._rx_message(self, msg)
def _rx_raw (self, data):
"""
If your subclass receives a stream instead of discrete messages, this
method can parse out individual messages and call _recv_msg() when
it has full messages.
"""
if len(data) == 0: return
if len(self._buf) == 0:
if data[0].isspace():
self._buf = data.lstrip()
else:
self._buf = data
else:
self._buf += data
while len(self._buf) > 0:
try:
msg, l = defaultDecoder.raw_decode(self._buf)
except:
# Need more data before it's a valid message
# (.. or the stream is corrupt and things will never be okay
# ever again)
return
self._buf = self._buf[l:]
if len(self._buf) != 0 and self._buf[0].isspace():
self._buf = self._buf.lstrip()
self._rx_message(msg)
def __str__ (self):
"""
Subclasses should implement better versions of this.
"""
return "<%s/%s/%i>" % (self.__class__.__name__, self._session_id,
self._session_num)
def close (self):
"""
Close the connection.
"""
self._close()
class Channel (EventMixin):
"""
Allows one to easily listen to only messages that have a CHANNEL key
with a specific name.
Generally you will not create these classes directly, but by calling
getChannel() on the ChannelNexus.
"""
_eventMixin_events = set([
MessageReceived,
ChannelJoin, # Immedaitely when a connection goes up
ChannelLeave, # When a connection goes down
ChannelDestroy,
ChannelDestroyed,
])
def __init__ (self, name, nexus = None, temporary = False):
"""
name is the name for the channel (i.e., the value for the messages'
CHANNEL key).
nexus is the specific MessengerNexus with which this channel is to be
associated (defaults to core.MessengerNexus).
"""
EventMixin.__init__(self)
assert isinstance(name, basestring)
self._name = name
self._nexus = _get_nexus(nexus)
self._nexus._channels[name] = self
self.temporary = temporary
self._members = set() # Member Connections
@property
def name (self):
return self._name
def _destroy (self):
""" Remove channel """
e = self.raiseEvent(ChannelDestroy, self)
if e:
if e.keep: return False
self._nexus.raiseEvent(e)
if e.keep: return False
del self._nexus._channels[self._name]
# We can't just do the follow because then listeners
# can't tell if the channel is now empty...
#for sub in set(self._members):
# sub.raiseEvent(ChannelLeave, sub, self)
#
#self._members.clear()
# .. so do the following really straightforward...
for sub in set(self._members):
self._remove_member(sub, allow_destroy = False)
e = ChannelDestroyed(self)
self.raiseEvent(e)
self._nexus.raiseEvent(e)
def _add_member (self, con, msg = {}):
if con in self._members: return
self._members.add(con)
self.raiseEvent(ChannelJoin, con, self, msg)
def _remove_member (self, con, allow_destroy = True):
if con not in self._members: return
self._members.remove(con)
self.raiseEvent(ChannelLeave, con, self)
if not allow_destroy: return
if self.temporary is True:
if len(self._members) == 0:
self._destroy()
def send (self, msg):
d = dict(msg)
d['CHANNEL'] = self._name
for r in self._members:
if not r.is_connected: continue
r.send(d)
def __str__ (self):
return "<Channel " + self.name + ">"
def reply (_msg, **kw):
if not isinstance(_msg, dict):
# We'll also take an event...
_msg = _msg.msg
kw['CHANNEL'] = _msg.get('CHANNEL')
if 'XID' in _msg: kw['XID'] = _msg.get('XID')
return kw
class ChannelBot (object):
"""
A very simple framework for writing "bots" that respond to messages
on a channel.
"""
def __str__ (self):
return "<%s@%s>" % (self.__class__.__name__, self.channel)
def __init__ (self, channel, nexus = None, weak = False, extra = {}):
self._startup(channel, nexus, weak, extra)
def _startup (self, channel, nexus = None, weak = False, extra = {}):
self._nexus = _get_nexus(nexus)
if isinstance(channel, Channel):
self.channel = channel
else:
self.channel = self._nexus.get_channel(channel, create=True)
self.listeners = self.channel.addListeners(self, weak = weak)
self.prefixes = None
self._init(extra)
if self.prefixes is None:
self.prefixes = []
for n in dir(self):
if n.startswith("_exec_"):
n = n.split("_")[2]
self.prefixes.append(n)
def _handle_ChannelDestroyed (self, event):
self.channel.removeListeners(self.listeners)
self._destroyed()
def _handle_ChannelJoin (self, event):
self._join(event, event.con, event.msg)
def _handle_ChannelLeave (self, event):
self._leave(event.con, len(self.channel._members) == 0)
def _handle_MessageReceived (self, event, msg):
for prefix in self.prefixes:
if prefix in event.msg:
cmd = "_exec_%s_%s" % (prefix, str(event.msg[prefix]))
if hasattr(self, cmd):
getattr(self, cmd)(event)
return #TODO: Return val?
for prefix in self.prefixes:
if prefix in event.msg:
cmd = "_exec_" + prefix
if hasattr(self, cmd):
getattr(self, cmd)(event, msg[prefix])
return #TODO: Return val?
self._unhandled(event)
def _unhandled (self, event):
""" Called when no command found """
pass
def _join (self, event, connection, msg):
""" Called when a connection joins """
pass
def _leave (self, connection, empty):
"""
Called when a connection leaves
If channel now has no members, empty is True
"""
pass
def _destroyed (self):
""" Called when channel is destroyed """
pass
def _init (self, extra):
"""
Called during initialization
'extra' is any additional information passed in when initializing
the bot. In particular, this may be the message that goes along
with its invitation into a channel.
"""
pass
def reply (__self, __event, **kw):
"""
Unicast reply to a specific message.
"""
__event.con.send(reply(__event, **kw))
def send (__self, __msg={}, **kw):
"""
Send a message to all members of this channel.
"""
m = {}
m.update(__msg)
m.update(kw)
__self.channel.send(m)
class DefaultChannelBot (ChannelBot):
def _init (self, extra):
self._bots = {}
def add_bot (self, bot, name = None):
"""
Registers a bot (an instance of ChannelBot) so that it can be
invited to other channels.
"""
assert issubclass(bot, ChannelBot)
if name is None:
name = bot.__name__
self._bots[name] = bot
def _exec_newlines_False (self, event):
event.con._newlines = False
def _exec_newlines_True (self, event):
event.con._newlines = True
def _exec_cmd_invite (self, event):
"""
Invites a bot that has been registered with add_bot() to a channel.
Note that you can invite a bot to an empty (new) temporary channel.
It will stay until the first member leaves.
"""
botname = event.msg.get('bot')
botclass = self._bots.get(botname)
channel = event.msg.get('channel')
new_channel = False
if channel is None:
new_channel = True
channel = self._gen_channel_name(event.msg.get("prefix", "temp"))
chan = self._nexus.get_channel(channel, create=True, temporary=True)
if chan is None:
#TODO: send an error
log.warning("A bot was invited to a nonexistent channel (%s)"
% (channel,))
return
if botclass is None:
#TODO: send an error
log.warning("A nonexistent bot (%s) was invited to a channel"
% (botname,))
return
bot = botclass(channel, self._nexus)
if new_channel:
self.reply(event, new_channel = new_channel)
def _unhandled (self, event):
log.warn("Default channel got unknown command: "
+ str(event.msg.get('cmd')))
def _gen_channel_name (self, prefix = "temp"):
""" Makes up a channel name """
prefix += "_"
import random
while True:
# Sloppy
r = random.randint(1, 100000)
n = prefix + str(r)
if r not in self._nexus._channels:
break
return n
def _exec_cmd_new_channel (self, event):
""" Generates a new channel with random name """
prefix = event.msg.get('prefix', 'temp')
n = self._gen_channel_name(prefix)
ch = self._nexus.get_channel(n, create=True, temporary=True)
ch._add_member(event.con, event.msg)
self.reply(event, new_channel = n)
def _exec_cmd_join_channel (self, event):
""" Joins/creates a channel """
temp = event.msg.get('temporary', True) # Default temporary!
ch = self._nexus.get_channel(event.msg['channel'], temporary=temp)
if ch is None: return
ch._add_member(event.con, event.msg)
def _exec_cmd_leave_channel (self, event):
ch = self._nexus.get_channel(event.msg['channel'])
if ch is None: return
ch._remove_member(event.con)
def _exec_test (self, event, value):
log.info("Default channel got: " + str(value))
self.reply(event, test = value.upper())
class MessengerNexus (EventMixin):
"""
Transports, Channels, etc. are all associated with a MessengerNexus.
Typically, there is only one, and it is registered as
pox.core.MessengerNexus
"""
_eventMixin_events = set([
MissingChannel, # When a msg arrives to nonexistent channel
ChannelDestroy,
ChannelDestroyed,
ChannelCreate,
])
def __init__ (self):
EventMixin.__init__(self)
self._channels = {} # name -> Channel
self.default_bot = DefaultChannelBot("", self)
self._next_ses = 1
self._session_salt = str(time.time())
def generate_session (self):
"""
Return a new session ID tuple (key, num)
The key is a unique and not-trivial-to-guess alphanumeric value
associated with the session.
The num is a unique numerical value associated with the session.
"""
r = self._next_ses
self._next_ses += 1
key = str(random.random()) + str(time.time()) + str(r)
key += str(id(key)) + self._session_salt
key = b32encode(hashlib.md5(key).digest()).upper().replace('=','')
def alphahex (r):
""" base 16 on digits 'a' through 'p' """
r=hex(r)[2:].lower()
return ''.join(chr((10 if ord(x) >= 97 else 49) + ord(x)) for x in r)
key = alphahex(r) + key
return key,r
def get_channel (self, name, create = True, temporary = False):
if name is None: name = ""
if name in self._channels:
return self._channels[name]
elif create:
c = Channel(name, self, temporary = temporary)
self.raiseEvent(ChannelCreate, c)
return c
else:
return None
def _rx_message (self, con, msg):
"""
Dispatches messages to listeners of this nexus and to its Channels.
Called by Connections.
"""
ret = False
assert isinstance(msg, dict)
if isinstance(msg, dict):
channels = msg.get('CHANNEL')
if channels is None:
channels = [""]
if not isinstance(channels, list):
channels = [channels]
for cname in channels:
channel = self.get_channel(cname, create=False)
if channel is None:
e = self.raiseEvent(MissingChannel, con, cname, msg)
if e is not None: cname = e.channel_name
channel = self.get_channel(cname, create=False)
if channel is not None:
#print "raise on", channel
channel.raiseEvent(MessageReceived, con, channel, msg)
ret = True
return ret
def launch ():
core.registerNew(MessengerNexus)
|
gpl-3.0
|
[
3,
1898,
7760,
12,
7409,
1603,
14015,
22895,
3630,
443,
89,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
3625,
56,
14,
199,
3,
199,
3,
3625,
56,
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,
3625,
56,
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,
3625,
56,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
257,
199,
1918,
3625,
56,
603,
397,
23444,
2656,
14,
421,
199,
1918,
603,
397,
23444,
2656,
365,
282,
4340,
370,
1900,
8500,
315,
3625,
56,
626,
883,
506,
199,
20688,
701,
5957,
13431,
14,
199,
199,
7700,
4508,
282,
7614,
5594,
1929,
370,
17232,
543,
314,
9682,
6701,
14,
199,
7700,
4508,
1265,
1929,
370,
21494,
543,
376,
3411,
14854,
402,
2032,
436,
199,
11853,
1265,
2793,
1133,
664,
370,
11496,
4212,
1265,
26808,
543,
652,
14,
221,
5439,
5431,
12,
199,
13297,
1172,
314,
30914,
436,
330,
300,
848,
402,
882,
10564,
2195,
5705,
14,
221,
710,
603,
397,
23444,
221,
199,
2253,
365,
18329,
370,
1720,
1265,
543,
314,
19045,
1930,
14,
199,
199,
607,
3974,
12,
9245,
787,
282,
2656,
367,
13882,
1958,
3382,
3625,
56,
436,
199,
5159,
18572,
701,
444,
29131,
3788,
5737,
315,
4840,
14,
221,
2779,
365,
11619,
199,
475,
506,
18794,
8605,
12,
3865,
315,
314,
23506,
1709,
652,
5171,
436,
315,
199,
1589,
7773,
83,
365,
5171,
334,
305,
402,
642,
3575,
12,
652,
5171,
282,
199,
14183,
1070,
6688,
13488,
2838,
7773,
436,
376,
3101,
7773,
680,
221,
6184,
199,
1364,
5313,
370,
675,
314,
603,
397,
23444,
1077,
314,
720,
17269,
506,
18025,
4799,
199,
1629,
7773,
14,
199,
199,
10,
22122,
10,
787,
29437,
23594,
1380,
282,
1890,
4907,
83,
4799,
2005,
199,
10,
7836,
4856,
221,
710,
1654,
883,
7814,
3163,
3222,
3788,
370,
282,
2488,
1890,
14,
199,
33,
1890,
883,
3222,
3788,
370,
282,
627,
5358,
10,
641,
314,
1654,
14,
221,
437,
1890,
883,
2597,
199,
13970,
282,
3653,
402,
282,
3623,
12,
2410,
1314,
652,
911,
9128,
1263,
3788,
199,
1589,
1654,
16178,
370,
626,
3623,
14,
221,
6006,
365,
3544,
282,
849,
3623,
543,
199,
889,
536,
14,
199,
199,
27138,
883,
1902,
506,
19860,
503,
7937,
14,
221,
21791,
9245,
787,
199,
2495,
17174,
28924,
1380,
2985,
949,
8088,
1395,
1263,
7556,
14,
199,
624,
199,
199,
504,
1115,
88,
14,
773,
14,
264,
782,
14,
264,
782,
492,
627,
199,
504,
1115,
88,
14,
1018,
492,
6170,
465,
6170,
199,
646,
2022,
199,
646,
900,
199,
646,
2196,
199,
646,
8337,
199,
504,
1300,
772,
492,
330,
708,
2143,
199,
199,
793,
275,
6170,
14,
5572,
342,
199,
199,
3,
4840,
10334,
1202,
701,
849,
199,
885,
8326,
275,
2022,
14,
6243,
8326,
342,
421,
199,
533,
17270,
13005,
334,
2390,
304,
523,
408,
481,
16139,
641,
282,
3623,
1380,
282,
1890,
18266,
14,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
3623,
12,
1499,
275,
1052,
304,
272,
6763,
855,
826,
721,
277,
9,
272,
291,
14,
388,
275,
1950,
272,
291,
14,
2775,
275,
3623,
272,
291,
14,
1328,
275,
1499,
199,
199,
533,
8113,
15190,
334,
2390,
304,
523,
408,
481,
16139,
641,
282,
1950,
1380,
652,
27811,
14,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
304,
272,
6763,
855,
826,
721,
277,
9,
272,
291,
14,
388,
275,
1950,
199,
199,
533,
17270,
23679,
334,
2390,
304,
523,
408,
481,
16139,
641,
282,
3623,
1380,
282,
1890,
16733,
14,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
3623,
304,
272,
6763,
855,
826,
721,
277,
9,
272,
291,
14,
388,
275,
1950,
272,
291,
14,
2775,
275,
3623,
199,
199,
533,
17270,
2499,
334,
2390,
304,
523,
408,
481,
16139,
641,
282,
653,
476,
527,
1380,
282,
3623,
365,
2737,
14,
408,
523,
347,
636,
826,
363,
334,
277,
12,
3623,
304,
272,
6763,
855,
826,
721,
277,
9,
272,
291,
14,
2775,
275,
3623,
199,
199,
533,
17270,
14704,
334,
2390,
304,
523,
408,
523,
481,
16139,
641,
314,
3623,
436,
2399,
653,
476,
527,
2451,
2544,
282,
3623,
365,
28924,
14,
523,
2494,
1275,
3250,
275,
715,
370,
4215,
314,
3623,
2410,
1006,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
3623,
304,
272,
6763,
855,
826,
721,
277,
9,
272,
291,
14,
2775,
275,
3623,
272,
291,
14,
3250,
275,
756,
199,
199,
533,
17270,
14704,
379,
334,
2390,
304,
523,
408,
523,
481,
16139,
641,
314,
3623,
436,
2399,
653,
476,
527,
2451,
2410,
282,
3623,
365,
28924,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
3623,
304,
272,
6763,
855,
826,
721,
277,
9,
272,
291,
14,
2775,
275,
3623,
199,
199,
533,
15626,
5358,
334,
2390,
304,
523,
408,
523,
481,
16139,
641,
282,
653,
476,
527,
1380,
282,
1245,
965,
2757,
3086,
370,
282,
2222,
13,
4494,
867,
3623,
14,
523,
2047,
883,
1218,
314,
3623,
315,
1177,
370,
642,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
3623,
63,
354,
12,
1499,
304,
272,
6763,
855,
826,
721,
277,
9,
272,
291,
14,
388,
275,
1950,
272,
291,
14,
2775,
63,
354,
275,
3623,
63,
354,
272,
291,
14,
1328,
275,
1499,
199,
199,
533,
6430,
9392,
334,
2390,
304,
523,
408,
523,
481,
16139,
701,
282,
3623,
1380,
282,
1245,
965,
2757,
295,
301,
1873,
1354,
14,
819,
16763,
31974,
641,
314,
8113
] |
[
1898,
7760,
12,
7409,
1603,
14015,
22895,
3630,
443,
89,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
3625,
56,
14,
199,
3,
199,
3,
3625,
56,
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,
3625,
56,
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,
3625,
56,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
257,
199,
1918,
3625,
56,
603,
397,
23444,
2656,
14,
421,
199,
1918,
603,
397,
23444,
2656,
365,
282,
4340,
370,
1900,
8500,
315,
3625,
56,
626,
883,
506,
199,
20688,
701,
5957,
13431,
14,
199,
199,
7700,
4508,
282,
7614,
5594,
1929,
370,
17232,
543,
314,
9682,
6701,
14,
199,
7700,
4508,
1265,
1929,
370,
21494,
543,
376,
3411,
14854,
402,
2032,
436,
199,
11853,
1265,
2793,
1133,
664,
370,
11496,
4212,
1265,
26808,
543,
652,
14,
221,
5439,
5431,
12,
199,
13297,
1172,
314,
30914,
436,
330,
300,
848,
402,
882,
10564,
2195,
5705,
14,
221,
710,
603,
397,
23444,
221,
199,
2253,
365,
18329,
370,
1720,
1265,
543,
314,
19045,
1930,
14,
199,
199,
607,
3974,
12,
9245,
787,
282,
2656,
367,
13882,
1958,
3382,
3625,
56,
436,
199,
5159,
18572,
701,
444,
29131,
3788,
5737,
315,
4840,
14,
221,
2779,
365,
11619,
199,
475,
506,
18794,
8605,
12,
3865,
315,
314,
23506,
1709,
652,
5171,
436,
315,
199,
1589,
7773,
83,
365,
5171,
334,
305,
402,
642,
3575,
12,
652,
5171,
282,
199,
14183,
1070,
6688,
13488,
2838,
7773,
436,
376,
3101,
7773,
680,
221,
6184,
199,
1364,
5313,
370,
675,
314,
603,
397,
23444,
1077,
314,
720,
17269,
506,
18025,
4799,
199,
1629,
7773,
14,
199,
199,
10,
22122,
10,
787,
29437,
23594,
1380,
282,
1890,
4907,
83,
4799,
2005,
199,
10,
7836,
4856,
221,
710,
1654,
883,
7814,
3163,
3222,
3788,
370,
282,
2488,
1890,
14,
199,
33,
1890,
883,
3222,
3788,
370,
282,
627,
5358,
10,
641,
314,
1654,
14,
221,
437,
1890,
883,
2597,
199,
13970,
282,
3653,
402,
282,
3623,
12,
2410,
1314,
652,
911,
9128,
1263,
3788,
199,
1589,
1654,
16178,
370,
626,
3623,
14,
221,
6006,
365,
3544,
282,
849,
3623,
543,
199,
889,
536,
14,
199,
199,
27138,
883,
1902,
506,
19860,
503,
7937,
14,
221,
21791,
9245,
787,
199,
2495,
17174,
28924,
1380,
2985,
949,
8088,
1395,
1263,
7556,
14,
199,
624,
199,
199,
504,
1115,
88,
14,
773,
14,
264,
782,
14,
264,
782,
492,
627,
199,
504,
1115,
88,
14,
1018,
492,
6170,
465,
6170,
199,
646,
2022,
199,
646,
900,
199,
646,
2196,
199,
646,
8337,
199,
504,
1300,
772,
492,
330,
708,
2143,
199,
199,
793,
275,
6170,
14,
5572,
342,
199,
199,
3,
4840,
10334,
1202,
701,
849,
199,
885,
8326,
275,
2022,
14,
6243,
8326,
342,
421,
199,
533,
17270,
13005,
334,
2390,
304,
523,
408,
481,
16139,
641,
282,
3623,
1380,
282,
1890,
18266,
14,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
3623,
12,
1499,
275,
1052,
304,
272,
6763,
855,
826,
721,
277,
9,
272,
291,
14,
388,
275,
1950,
272,
291,
14,
2775,
275,
3623,
272,
291,
14,
1328,
275,
1499,
199,
199,
533,
8113,
15190,
334,
2390,
304,
523,
408,
481,
16139,
641,
282,
1950,
1380,
652,
27811,
14,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
304,
272,
6763,
855,
826,
721,
277,
9,
272,
291,
14,
388,
275,
1950,
199,
199,
533,
17270,
23679,
334,
2390,
304,
523,
408,
481,
16139,
641,
282,
3623,
1380,
282,
1890,
16733,
14,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
3623,
304,
272,
6763,
855,
826,
721,
277,
9,
272,
291,
14,
388,
275,
1950,
272,
291,
14,
2775,
275,
3623,
199,
199,
533,
17270,
2499,
334,
2390,
304,
523,
408,
481,
16139,
641,
282,
653,
476,
527,
1380,
282,
3623,
365,
2737,
14,
408,
523,
347,
636,
826,
363,
334,
277,
12,
3623,
304,
272,
6763,
855,
826,
721,
277,
9,
272,
291,
14,
2775,
275,
3623,
199,
199,
533,
17270,
14704,
334,
2390,
304,
523,
408,
523,
481,
16139,
641,
314,
3623,
436,
2399,
653,
476,
527,
2451,
2544,
282,
3623,
365,
28924,
14,
523,
2494,
1275,
3250,
275,
715,
370,
4215,
314,
3623,
2410,
1006,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
3623,
304,
272,
6763,
855,
826,
721,
277,
9,
272,
291,
14,
2775,
275,
3623,
272,
291,
14,
3250,
275,
756,
199,
199,
533,
17270,
14704,
379,
334,
2390,
304,
523,
408,
523,
481,
16139,
641,
314,
3623,
436,
2399,
653,
476,
527,
2451,
2410,
282,
3623,
365,
28924,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
3623,
304,
272,
6763,
855,
826,
721,
277,
9,
272,
291,
14,
2775,
275,
3623,
199,
199,
533,
15626,
5358,
334,
2390,
304,
523,
408,
523,
481,
16139,
641,
282,
653,
476,
527,
1380,
282,
1245,
965,
2757,
3086,
370,
282,
2222,
13,
4494,
867,
3623,
14,
523,
2047,
883,
1218,
314,
3623,
315,
1177,
370,
642,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
3623,
63,
354,
12,
1499,
304,
272,
6763,
855,
826,
721,
277,
9,
272,
291,
14,
388,
275,
1950,
272,
291,
14,
2775,
63,
354,
275,
3623,
63,
354,
272,
291,
14,
1328,
275,
1499,
199,
199,
533,
6430,
9392,
334,
2390,
304,
523,
408,
523,
481,
16139,
701,
282,
3623,
1380,
282,
1245,
965,
2757,
295,
301,
1873,
1354,
14,
819,
16763,
31974,
641,
314,
8113,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
devGregA/code
|
build/lib.linux-x86_64-2.7/scrapy/commands/check.py
|
3
|
3900
|
from __future__ import print_function
import time
import sys
from collections import defaultdict
from unittest import TextTestRunner, TextTestResult as _TextTestResult
from scrapy.command import ScrapyCommand
from scrapy.contracts import ContractsManager
from scrapy.utils.misc import load_object
from scrapy.utils.conf import build_component_list
class TextTestResult(_TextTestResult):
def printSummary(self, start, stop):
write = self.stream.write
writeln = self.stream.writeln
run = self.testsRun
plural = "s" if run != 1 else ""
writeln(self.separator2)
writeln("Ran %d contract%s in %.3fs" % (run, plural, stop - start))
writeln()
infos = []
if not self.wasSuccessful():
write("FAILED")
failed, errored = map(len, (self.failures, self.errors))
if failed:
infos.append("failures=%d" % failed)
if errored:
infos.append("errors=%d" % errored)
else:
write("OK")
if infos:
writeln(" (%s)" % (", ".join(infos),))
else:
write("\n")
class Command(ScrapyCommand):
requires_project = True
default_settings = {'LOG_ENABLED': False}
def syntax(self):
return "[options] <spider>"
def short_desc(self):
return "Check spider contracts"
def add_options(self, parser):
ScrapyCommand.add_options(self, parser)
parser.add_option("-l", "--list", dest="list", action="store_true",
help="only list contracts, without checking them")
parser.add_option("-v", "--verbose", dest="verbose", default=False, action='store_true',
help="print contract tests for all spiders")
def run(self, args, opts):
# load contracts
contracts = build_component_list(
self.settings['SPIDER_CONTRACTS_BASE'],
self.settings['SPIDER_CONTRACTS'],
)
conman = ContractsManager([load_object(c) for c in contracts])
runner = TextTestRunner(verbosity=2 if opts.verbose else 1)
result = TextTestResult(runner.stream, runner.descriptions, runner.verbosity)
# contract requests
contract_reqs = defaultdict(list)
spman_cls = load_object(self.settings['SPIDER_MANAGER_CLASS'])
spiders = spman_cls.from_settings(self.settings)
for spider in args or spiders.list():
spider = spiders.create(spider)
requests = self.get_requests(spider, conman, result)
contract_reqs[spider.name] = []
if opts.list:
for req in requests:
contract_reqs[spider.name].append(req.callback.__name__)
elif requests:
crawler = self.crawler_process.create_crawler(spider.name)
crawler.crawl(spider, requests)
# start checks
if opts.list:
for spider, methods in sorted(contract_reqs.items()):
if not methods and not opts.verbose:
continue
print(spider)
for method in sorted(methods):
print(' * %s' % method)
else:
start = time.time()
self.crawler_process.start()
stop = time.time()
result.printErrors()
result.printSummary(start, stop)
self.exitcode = int(not result.wasSuccessful())
def get_requests(self, spider, conman, result):
requests = []
for key, value in vars(type(spider)).items():
if callable(value) and value.__doc__:
bound_method = value.__get__(spider, type(spider))
request = conman.from_method(bound_method, result)
if request:
requests.append(request)
return requests
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
900,
199,
646,
984,
199,
504,
5055,
492,
10018,
199,
504,
2882,
492,
4516,
13649,
12,
4516,
13120,
465,
485,
1872,
13120,
199,
199,
504,
18918,
14,
1531,
492,
13916,
345,
647,
3110,
199,
504,
18918,
14,
17926,
3021,
492,
1448,
1239,
3021,
2988,
199,
504,
18918,
14,
1208,
14,
9923,
492,
2248,
63,
785,
199,
504,
18918,
14,
1208,
14,
2190,
492,
1900,
63,
3173,
63,
513,
421,
199,
533,
4516,
13120,
1547,
1872,
13120,
304,
272,
347,
870,
10407,
8,
277,
12,
1343,
12,
3631,
304,
267,
2218,
275,
291,
14,
1745,
14,
952,
267,
2218,
6066,
275,
291,
14,
1745,
14,
21768,
398,
1255,
275,
291,
14,
30680,
267,
11718,
275,
298,
83,
2,
340,
1255,
1137,
413,
587,
3087,
398,
2218,
6066,
8,
277,
14,
9896,
18,
9,
267,
2218,
6066,
480,
50,
290,
450,
68,
16077,
5,
83,
315,
10536,
19,
2319,
2,
450,
334,
1065,
12,
11718,
12,
3631,
446,
1343,
430,
267,
2218,
6066,
342,
398,
24485,
275,
942,
267,
340,
440,
291,
14,
10274,
20839,
837,
288,
2218,
480,
12299,
531,
288,
3405,
12,
9266,
20878,
275,
2341,
8,
552,
12,
334,
277,
14,
9968,
12,
291,
14,
2550,
430,
288,
340,
3405,
26,
355,
24485,
14,
740,
480,
9968,
2458,
68,
2,
450,
3405,
9,
288,
340,
9266,
20878,
26,
355,
24485,
14,
740,
480,
2550,
2458,
68,
2,
450,
9266,
20878,
9,
267,
587,
26,
288,
2218,
480,
3593,
531,
398,
340,
24485,
26,
288,
2218,
6066,
480,
4366,
83,
2924,
450,
334,
401,
3680,
904,
8,
14195,
18399,
267,
587,
26,
288,
2218,
4582,
78,
531,
421,
199,
533,
5817,
8,
7181,
345,
647,
3110,
304,
272,
5074,
63,
1715,
275,
715,
272,
849,
63,
1751,
275,
791,
4947,
63,
15704,
356,
756,
93,
339,
347,
6302,
8,
277,
304,
267,
372,
7369,
1419,
61,
665,
12856,
4335,
339,
347,
3974,
63,
3257,
8,
277,
304,
267,
372,
298,
1799,
18094,
18782,
3021,
2,
339,
347,
1050,
63,
1419,
8,
277,
12,
1798,
304,
267,
13916,
345,
647,
3110,
14,
525,
63,
1419,
8,
277,
12,
1798,
9,
267,
1798,
14,
525,
63,
1422,
6096,
76,
401,
4320,
513,
401,
2053,
628,
513,
401,
1595,
628,
1617,
63,
2052,
401,
2079,
1720,
628,
2118,
769,
18782,
3021,
12,
1928,
7907,
3062,
531,
267,
1798,
14,
525,
63,
1422,
6096,
86,
401,
4320,
3832,
401,
2053,
628,
3832,
401,
849,
29,
797,
12,
1595,
534,
1617,
63,
2052,
297,
2079,
1720,
628,
1361,
16077,
2295,
367,
1006,
19441,
7735,
531,
339,
347,
1255,
8,
277,
12,
1249,
12,
3999,
304,
267,
327,
2248,
18782,
3021,
267,
18782,
3021,
275,
1900,
63,
3173,
63,
513,
8,
288,
291,
14,
1751,
459,
5763,
998,
540,
63,
1864,
22280,
51,
63,
5825,
995,
288,
291,
14,
1751,
459,
5763,
998,
540,
63,
1864,
22280,
51,
995,
267,
776,
267,
406,
1237,
275,
1448,
1239,
3021,
2988,
779,
912,
63,
785,
8,
67,
9,
367,
286,
315,
18782,
3021,
566,
267,
7876,
275,
4516,
13649,
8,
9833,
29,
18,
340,
3999,
14,
3832,
587,
413,
9,
267,
754,
275,
4516,
13120,
8,
5933,
14,
1745,
12,
7876,
14,
21713,
12,
7876,
14,
9833,
9,
398,
327,
16077,
4145,
267,
16077,
63,
12720,
275,
10018,
8,
513,
9,
398,
2249,
1237,
63,
1886,
275,
2248,
63,
785,
8,
277,
14,
1751,
459,
5763,
998,
540,
63,
28541,
63,
6885,
1105,
267,
19441,
7735,
275,
2249,
1237,
63,
1886,
14,
504,
63,
1751,
8,
277,
14,
1751,
9,
398,
367,
18094,
315,
1249,
503,
19441,
7735,
14,
513,
837,
288,
18094,
275,
19441,
7735,
14,
981,
8,
12856,
9,
288,
4145,
275,
291,
14,
362,
63,
6615,
8,
12856,
12,
406,
1237,
12,
754,
9,
288,
16077,
63,
12720,
59,
12856,
14,
354,
61,
275,
942,
953,
340,
3999,
14,
513,
26,
355,
367,
2648,
315,
4145,
26,
490,
16077,
63,
12720,
59,
12856,
14,
354,
1055,
740,
8,
2103,
14,
3058,
855,
354,
3368,
288,
916,
4145,
26,
355,
29550,
275,
291,
14,
23972,
63,
1412,
14,
981,
63,
23972,
8,
12856,
14,
354,
9,
355,
29550,
14,
67,
22910,
8,
12856,
12,
4145,
9,
398,
327,
1343,
5920,
267,
340,
3999,
14,
513,
26,
288,
367,
18094,
12,
3102,
315,
3355,
8,
14624,
63,
12720,
14,
1744,
5109,
355,
340,
440,
3102,
436,
440,
3999,
14,
3832,
26,
490,
1980,
355,
870,
8,
12856,
9,
355,
367,
1083,
315,
3355,
8,
2474,
304,
490,
870,
360,
221,
627,
450,
83,
7,
450,
1083,
9,
267,
587,
26,
288,
1343,
275,
900,
14,
521,
342,
288,
291,
14,
23972,
63,
1412,
14,
928,
342,
288,
3631,
275,
900,
14,
521,
342,
953,
754,
14,
1361,
9298,
342,
288,
754,
14,
1361,
10407,
8,
928,
12,
3631,
9,
288,
291,
14,
2224,
600,
275,
1109,
8,
1397,
754,
14,
10274,
20839,
1012,
339,
347,
664,
63,
6615,
8,
277,
12,
18094,
12,
406,
1237,
12,
754,
304,
267,
4145,
275,
942,
398,
367,
790,
12,
574,
315,
6802,
8,
466,
8,
12856,
4992,
1744,
837,
288,
340,
4550,
8,
585,
9,
436,
574,
855,
1301,
10651,
355,
3914,
63,
765,
275,
574,
855,
362,
721,
12856,
12,
730,
8,
12856,
430,
355,
1056,
275,
406,
1237,
14,
504,
63,
765,
8,
3556,
63,
765,
12,
754,
9,
2234,
340,
1056,
26,
490,
4145,
14,
740,
8,
1069,
9,
398,
372,
4145,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
870,
63,
1593,
199,
646,
900,
199,
646,
984,
199,
504,
5055,
492,
10018,
199,
504,
2882,
492,
4516,
13649,
12,
4516,
13120,
465,
485,
1872,
13120,
199,
199,
504,
18918,
14,
1531,
492,
13916,
345,
647,
3110,
199,
504,
18918,
14,
17926,
3021,
492,
1448,
1239,
3021,
2988,
199,
504,
18918,
14,
1208,
14,
9923,
492,
2248,
63,
785,
199,
504,
18918,
14,
1208,
14,
2190,
492,
1900,
63,
3173,
63,
513,
421,
199,
533,
4516,
13120,
1547,
1872,
13120,
304,
272,
347,
870,
10407,
8,
277,
12,
1343,
12,
3631,
304,
267,
2218,
275,
291,
14,
1745,
14,
952,
267,
2218,
6066,
275,
291,
14,
1745,
14,
21768,
398,
1255,
275,
291,
14,
30680,
267,
11718,
275,
298,
83,
2,
340,
1255,
1137,
413,
587,
3087,
398,
2218,
6066,
8,
277,
14,
9896,
18,
9,
267,
2218,
6066,
480,
50,
290,
450,
68,
16077,
5,
83,
315,
10536,
19,
2319,
2,
450,
334,
1065,
12,
11718,
12,
3631,
446,
1343,
430,
267,
2218,
6066,
342,
398,
24485,
275,
942,
267,
340,
440,
291,
14,
10274,
20839,
837,
288,
2218,
480,
12299,
531,
288,
3405,
12,
9266,
20878,
275,
2341,
8,
552,
12,
334,
277,
14,
9968,
12,
291,
14,
2550,
430,
288,
340,
3405,
26,
355,
24485,
14,
740,
480,
9968,
2458,
68,
2,
450,
3405,
9,
288,
340,
9266,
20878,
26,
355,
24485,
14,
740,
480,
2550,
2458,
68,
2,
450,
9266,
20878,
9,
267,
587,
26,
288,
2218,
480,
3593,
531,
398,
340,
24485,
26,
288,
2218,
6066,
480,
4366,
83,
2924,
450,
334,
401,
3680,
904,
8,
14195,
18399,
267,
587,
26,
288,
2218,
4582,
78,
531,
421,
199,
533,
5817,
8,
7181,
345,
647,
3110,
304,
272,
5074,
63,
1715,
275,
715,
272,
849,
63,
1751,
275,
791,
4947,
63,
15704,
356,
756,
93,
339,
347,
6302,
8,
277,
304,
267,
372,
7369,
1419,
61,
665,
12856,
4335,
339,
347,
3974,
63,
3257,
8,
277,
304,
267,
372,
298,
1799,
18094,
18782,
3021,
2,
339,
347,
1050,
63,
1419,
8,
277,
12,
1798,
304,
267,
13916,
345,
647,
3110,
14,
525,
63,
1419,
8,
277,
12,
1798,
9,
267,
1798,
14,
525,
63,
1422,
6096,
76,
401,
4320,
513,
401,
2053,
628,
513,
401,
1595,
628,
1617,
63,
2052,
401,
2079,
1720,
628,
2118,
769,
18782,
3021,
12,
1928,
7907,
3062,
531,
267,
1798,
14,
525,
63,
1422,
6096,
86,
401,
4320,
3832,
401,
2053,
628,
3832,
401,
849,
29,
797,
12,
1595,
534,
1617,
63,
2052,
297,
2079,
1720,
628,
1361,
16077,
2295,
367,
1006,
19441,
7735,
531,
339,
347,
1255,
8,
277,
12,
1249,
12,
3999,
304,
267,
327,
2248,
18782,
3021,
267,
18782,
3021,
275,
1900,
63,
3173,
63,
513,
8,
288,
291,
14,
1751,
459,
5763,
998,
540,
63,
1864,
22280,
51,
63,
5825,
995,
288,
291,
14,
1751,
459,
5763,
998,
540,
63,
1864,
22280,
51,
995,
267,
776,
267,
406,
1237,
275,
1448,
1239,
3021,
2988,
779,
912,
63,
785,
8,
67,
9,
367,
286,
315,
18782,
3021,
566,
267,
7876,
275,
4516,
13649,
8,
9833,
29,
18,
340,
3999,
14,
3832,
587,
413,
9,
267,
754,
275,
4516,
13120,
8,
5933,
14,
1745,
12,
7876,
14,
21713,
12,
7876,
14,
9833,
9,
398,
327,
16077,
4145,
267,
16077,
63,
12720,
275,
10018,
8,
513,
9,
398,
2249,
1237,
63,
1886,
275,
2248,
63,
785,
8,
277,
14,
1751,
459,
5763,
998,
540,
63,
28541,
63,
6885,
1105,
267,
19441,
7735,
275,
2249,
1237,
63,
1886,
14,
504,
63,
1751,
8,
277,
14,
1751,
9,
398,
367,
18094,
315,
1249,
503,
19441,
7735,
14,
513,
837,
288,
18094,
275,
19441,
7735,
14,
981,
8,
12856,
9,
288,
4145,
275,
291,
14,
362,
63,
6615,
8,
12856,
12,
406,
1237,
12,
754,
9,
288,
16077,
63,
12720,
59,
12856,
14,
354,
61,
275,
942,
953,
340,
3999,
14,
513,
26,
355,
367,
2648,
315,
4145,
26,
490,
16077,
63,
12720,
59,
12856,
14,
354,
1055,
740,
8,
2103,
14,
3058,
855,
354,
3368,
288,
916,
4145,
26,
355,
29550,
275,
291,
14,
23972,
63,
1412,
14,
981,
63,
23972,
8,
12856,
14,
354,
9,
355,
29550,
14,
67,
22910,
8,
12856,
12,
4145,
9,
398,
327,
1343,
5920,
267,
340,
3999,
14,
513,
26,
288,
367,
18094,
12,
3102,
315,
3355,
8,
14624,
63,
12720,
14,
1744,
5109,
355,
340,
440,
3102,
436,
440,
3999,
14,
3832,
26,
490,
1980,
355,
870,
8,
12856,
9,
355,
367,
1083,
315,
3355,
8,
2474,
304,
490,
870,
360,
221,
627,
450,
83,
7,
450,
1083,
9,
267,
587,
26,
288,
1343,
275,
900,
14,
521,
342,
288,
291,
14,
23972,
63,
1412,
14,
928,
342,
288,
3631,
275,
900,
14,
521,
342,
953,
754,
14,
1361,
9298,
342,
288,
754,
14,
1361,
10407,
8,
928,
12,
3631,
9,
288,
291,
14,
2224,
600,
275,
1109,
8,
1397,
754,
14,
10274,
20839,
1012,
339,
347,
664,
63,
6615,
8,
277,
12,
18094,
12,
406,
1237,
12,
754,
304,
267,
4145,
275,
942,
398,
367,
790,
12,
574,
315,
6802,
8,
466,
8,
12856,
4992,
1744,
837,
288,
340,
4550,
8,
585,
9,
436,
574,
855,
1301,
10651,
355,
3914,
63,
765,
275,
574,
855,
362,
721,
12856,
12,
730,
8,
12856,
430,
355,
1056,
275,
406,
1237,
14,
504,
63,
765,
8,
3556,
63,
765,
12,
754,
9,
2234,
340,
1056,
26,
490,
4145,
14,
740,
8,
1069,
9,
398,
372,
4145,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
arhangel6/RecipeWizard
|
Server/views.py
|
1
|
4673
|
#Apache2 Python server
from __future__ import print_function
from django.shortcuts import render
import time
from django.http import HttpResponse
import smtplib
import MySQLdb
import sys
import os
import xmpp
def mytest(request):
if request.GET:
value = request.GET
form=value['form']
form = str(form).split("!!")
types = form[0]
#return HttpResponse(rez)
if types =='c':
# Open database connection
db = MySQLdb.connect("localhost","root","udine66798","MySQLtest" )
# prepare a cursor object using cursor() method
cursor = db.cursor()
sql = "SELECT name FROM RECIPE ;"
try:
# Execute the SQL command
cursor.execute(sql)
results = cursor.fetchall()
return HttpResponse(results)
except:
db.close()
return HttpResponse('xkcd')
if types =='w':
ingredients = form[1]
ingredients=ingredients.split("[")
db = MySQLdb.connect("localhost","root","udine66798","MySQLtest" )
cursor = db.cursor()
sql = "select rname, rqty, rrecipe, rserving from (select ri.id_recipe as recipe_id, r.name as rname, r.quantity_ingredients as rqty, r.recipe_content as rrecipe, r.serving as rserving from RECIPE r, INGREDIENT i, RECIPE_INGREDIENT ri where r.id=ri.id_recipe and i.id=ri.id_ingredient and (";
for row in ingredients:
row =' i.name="'+row+'" '
ingredients= '" or i.name="'.join(ingredients)
ingredients='i.name="'+ingredients
end = '")) as my_query group by rname order by count(recipe_id) desc';
sql=sql+ingredients+end
# return HttpResponse(sql)
try:
# Execute the SQL command
cursor.execute(sql)
results = cursor.fetchall()
result=""
for row in results:
result=result+"!!"+str(row[0])+"!!"+str(row[1])+"!!"+str(row[2])+"!!"+str(row[3])+"&&"
return HttpResponse(str(result))
except:
return HttpResponse( "xkcd")
if types =='r':
db = MySQLdb.connect("localhost","root","udine66798","MySQLtest" )
cursor = db.cursor()
sql = "SELECT name FROM INGREDIENT ;"
try:
cursor.execute(sql)
results = cursor.fetchall()
return HttpResponse(results)
except:
db.close()
return HttpResponse('xkcd')
if types =='h':
ingredients = form[1]
ingredients=ingredients.split("[")
db = MySQLdb.connect("localhost","root","udine66798","MySQLtest" )
cursor = db.cursor()
sql = "SELECT id FROM RECIPE where name ='%s' ;" % (ingredients[1],)
try:
cursor.execute(sql)
id_rec = int( cursor.fetchall()[0][0])
except:
db.close()
return HttpResponse('none found1')
db = MySQLdb.connect("localhost","root","udine66798","MySQLtest" )
cursor = db.cursor()
sql = "SELECT id FROM USER where user_name ='%s' ;" % (ingredients[0],)
try:
cursor.execute(sql)
id_usr = int( cursor.fetchall()[0][0])
except:
db.close()
return HttpResponse('none found2')
#return HttpResponse(id_usr)
db = MySQLdb.connect("localhost","root","udine66798","MySQLtest" )
cursor = db.cursor()
try:
cursor.execute( "insert into HISTORY (id_user, id_recipe) values (%i, %i);" % (id_usr,id_rec))
db.commit()
except:
db.close()
return HttpResponse('none found3')
return HttpResponse('cool cool cool')
if types =='y':
ingredients = form[1]
db = MySQLdb.connect("localhost","root","udine66798","MySQLtest" )
cursor = db.cursor()
sql = "SELECT id FROM USER where user_name ='%s' ;" % (ingredients,)
try:
cursor.execute(sql)
id_usr = int( cursor.fetchall()[0][0])
except:
db.close()
return HttpResponse('user not found')
db = MySQLdb.connect("localhost","root","udine66798","MySQLtest" )
cursor = db.cursor()
try:
cursor.execute("""SELECT a.name,a.quantity_ingredients ,a.recipe_content,a.serving FROM `RECIPE` a, `HISTORY` b WHERE a.id=b.id_recipe and b.id_user = %i """ % (int(id_usr),))
results = cursor.fetchall()
result=""
for row in results:
result=result+"!!"+str(row[0])+"!!"+str(row[1])+"!!"+str(row[2])+"!!"+str(row[3])+"&&"
return HttpResponse(str(result))
except:
db.close()
return HttpResponse('history selector error')
return HttpResponse('history error')
if types =='p':
ingredients = form[1]
ingredients=ingredients.split("[")
db = MySQLdb.connect("localhost","root","udine66798","MySQLtest" )
cursor = db.cursor()
try:
cursor.execute( "insert into USER (USER_NAME,PASS) values (%s, %s);" % (ingredients[0],ingredients[1]))
db.commit()
except:
db.close()
return HttpResponse('insert error')
return HttpResponse('registration error')
return HttpResponse('general error')
|
mit
|
[
3,
28993,
18,
2018,
1654,
20712,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
202,
199,
504,
1639,
14,
17469,
492,
3795,
202,
199,
646,
900,
202,
199,
504,
1639,
14,
1014,
492,
6183,
202,
199,
646,
30475,
202,
199,
646,
25709,
2999,
199,
646,
984,
202,
199,
646,
747,
202,
199,
646,
671,
17901,
10060,
8065,
199,
318,
3002,
396,
8,
1069,
304,
1223,
340,
1056,
14,
2970,
26,
10292,
574,
275,
1056,
14,
2970,
10292,
1824,
29,
585,
459,
964,
418,
10292,
1824,
275,
620,
8,
964,
680,
1294,
480,
3480,
531,
15497,
10292,
2943,
275,
1824,
59,
16,
61,
10292,
10292,
327,
1107,
6183,
8,
25409,
9,
10292,
340,
2943,
508,
7,
67,
356,
1223,
198,
3,
3232,
3050,
1950,
1223,
198,
697,
275,
25709,
14,
2242,
480,
5967,
2266,
1231,
2266,
1181,
1132,
1272,
16564,
2266,
20784,
396,
2,
776,
1223,
198,
3,
9275,
282,
3920,
909,
1808,
3920,
342,
1083,
1223,
198,
3937,
275,
1592,
14,
3937,
342,
1223,
198,
3009,
275,
298,
4859,
536,
4442,
5363,
3553,
1510,
8700,
2,
221,
1223,
198,
893,
26,
1223,
198,
3,
17009,
314,
5385,
1414,
4122,
3920,
14,
2526,
8,
3009,
9,
4122,
4122,
2058,
275,
3920,
14,
10174,
342,
4122,
4122,
372,
6183,
8,
2604,
9,
28111,
198,
2590,
26,
4122,
1592,
14,
1600,
342,
4122,
372,
6183,
360,
28351,
2866,
358,
10292,
340,
2943,
508,
7,
87,
356,
15497,
198,
315,
9157,
3766,
83,
221,
275,
1824,
59,
17,
61,
15497,
198,
15497,
198,
315,
9157,
3766,
83,
29,
316,
264,
3766,
83,
14,
1294,
10994,
531,
15497,
198,
221,
15497,
198,
1592,
275,
25709,
14,
2242,
480,
5967,
2266,
1231,
2266,
1181,
1132,
1272,
16564,
2266,
20784,
396,
2,
776,
4122,
3920,
275,
1592,
14,
3937,
342,
4122,
3875,
275,
298,
2416,
519,
354,
12,
519,
5643,
12,
519,
13191,
12,
519,
14717,
687,
334,
2416,
8012,
14,
344,
63,
13191,
465,
17121,
63,
344,
12,
519,
14,
354,
465,
519,
354,
12,
519,
14,
10577,
63,
316,
264,
3766,
83,
465,
519,
5643,
12,
519,
14,
13191,
63,
1317,
465,
519,
13191,
12,
519,
14,
14717,
465,
519,
14717,
687,
5363,
3553,
1510,
519,
12,
1621,
39,
907,
1914,
1309,
284,
12,
5363,
3553,
1510,
63,
1206,
907,
1914,
1309,
8012,
2382,
519,
14,
344,
29,
322,
14,
344,
63,
13191,
436,
284,
14,
344,
29,
322,
14,
344,
63,
316,
264,
3766,
436,
1689,
27,
4122,
367,
1962,
315,
315,
9157,
3766,
83,
26,
4122,
198,
1143,
275,
7,
284,
14,
354,
628,
6828,
1143,
11,
4065,
283,
26045,
315,
9157,
3766,
83,
29,
5522,
503,
284,
14,
354,
628,
1370,
904,
8,
316,
264,
3766,
83,
9,
4122,
315,
9157,
3766,
83,
534,
73,
14,
354,
628,
6828,
316,
264,
3766,
83,
4122,
1284,
275,
283,
2237,
465,
3002,
63,
1131,
1572,
701,
519,
354,
1865,
701,
2338,
8,
13191,
63,
344,
9,
4328,
13619,
4122,
3875,
29,
3009,
11,
316,
264,
3766,
83,
11,
500,
1223,
198,
3,
372,
6183,
8,
3009,
9,
4122,
862,
26,
1223,
198,
3,
17009,
314,
5385,
1414,
4122,
221,
3920,
14,
2526,
8,
3009,
9,
4122,
221,
2058,
275,
3920,
14,
10174,
342,
4122,
221,
754,
9287,
4122,
221,
367,
1962,
315,
2058,
26,
4122,
257,
198,
1099,
29,
1099,
5207,
3480,
7709,
495,
8,
1143,
59,
16,
566,
5207,
3480,
7709,
495,
8,
1143,
59,
17,
566,
5207,
3480,
7709,
495,
8,
1143,
59,
18,
566,
5207,
3480,
7709,
495,
8,
1143,
59,
19,
566,
5207,
12574,
2,
4122,
221,
372,
6183,
8,
495,
8,
1099,
430,
4122,
4122,
871,
26,
221,
4122,
257,
372,
6183,
8,
298,
28351,
2866,
531,
10060,
257,
198,
10292,
340,
2943,
508,
7,
82,
356,
15497,
198,
697,
275,
25709,
14,
2242,
480,
5967,
2266,
1231,
2266,
1181,
1132,
1272,
16564,
2266,
20784,
396,
2,
776,
1223,
198,
3937,
275,
1592,
14,
3937,
342,
1223,
198,
3009,
275,
298,
4859,
536,
4442,
1621,
39,
907,
1914,
1309,
8700,
2,
221,
1223,
198,
893,
26,
4122,
4122,
3920,
14,
2526,
8,
3009,
9,
26045,
2058,
275,
3920,
14,
10174,
342,
4122,
4122,
372,
6183,
8,
2604,
9,
28111,
198,
2590,
26,
4122,
1592,
14,
1600,
342,
4122,
372,
6183,
360,
28351,
2866,
358,
10292,
340,
2943,
508,
7,
72,
356,
15497,
198,
316,
264,
3766,
83,
221,
275,
1824,
59,
17,
61,
15497,
198,
15497,
198,
316,
264,
3766,
83,
29,
316,
264,
3766,
83,
14,
1294,
10994,
531,
15497,
198,
697,
275,
25709,
14,
2242,
480,
5967,
2266,
1231,
2266,
1181,
1132,
1272,
16564,
2266,
20784,
396,
2,
776,
1223,
198,
3937,
275,
1592,
14,
3937,
342,
1223,
198,
3009,
275,
298,
4859,
1305,
4442,
5363,
3553,
1510,
2382,
536,
275,
5956,
83,
7,
8700,
2,
450,
334,
316,
264,
3766,
83,
59,
17,
467,
9,
221,
1223,
198,
893,
26,
4122,
3920,
14,
2526,
8,
3009,
9,
4122,
1305,
63,
2761,
275,
1109,
8,
3920,
14,
10174,
3430,
16,
1527,
16,
566,
28111,
198,
2590,
26,
4122,
1592,
14,
1600,
342,
4122,
372,
6183,
360,
3592,
1911,
17,
358,
10060,
198,
697,
275,
25709,
14,
2242,
480,
5967,
2266,
1231,
2266,
1181,
1132,
1272,
16564,
2266,
20784,
396,
2,
776,
1223,
198,
3937,
275,
1592,
14,
3937,
342,
1223,
198,
3009,
275,
298,
4859,
1305,
4442,
13044,
2382,
922,
63,
354,
275,
5956,
83,
7,
8700,
2,
450,
334,
316,
264,
3766,
83,
59,
16,
467,
9,
221,
1223,
198,
893,
26,
4122,
3920,
14,
2526,
8,
3009,
9,
4122,
1305,
63,
2647,
275,
1109,
8,
3920,
14,
10174,
3430,
16,
1527,
16,
566,
28111,
198,
2590,
26,
4122,
1592,
14,
1600,
342,
4122,
372,
6183,
360,
3592,
1911,
18,
358,
1223,
198,
3,
1107,
6183,
8,
344,
63,
2647,
9,
1223,
198,
697,
275,
25709,
14,
2242,
480,
5967,
2266,
1231,
2266,
1181,
1132,
1272,
16564,
2266,
20784,
396,
2,
776,
1223,
198,
3937,
275,
1592,
14,
3937,
342,
1223,
198,
893,
26,
4122,
4122,
3920,
14,
2526,
8,
298,
3176,
1901,
869,
6225,
5347,
334,
344,
63,
751,
12,
1305,
63,
13191,
9,
1338,
4366,
73,
12,
450,
73,
27556,
450,
334,
344,
63,
2647,
12,
344
] |
[
28993,
18,
2018,
1654,
20712,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
202,
199,
504,
1639,
14,
17469,
492,
3795,
202,
199,
646,
900,
202,
199,
504,
1639,
14,
1014,
492,
6183,
202,
199,
646,
30475,
202,
199,
646,
25709,
2999,
199,
646,
984,
202,
199,
646,
747,
202,
199,
646,
671,
17901,
10060,
8065,
199,
318,
3002,
396,
8,
1069,
304,
1223,
340,
1056,
14,
2970,
26,
10292,
574,
275,
1056,
14,
2970,
10292,
1824,
29,
585,
459,
964,
418,
10292,
1824,
275,
620,
8,
964,
680,
1294,
480,
3480,
531,
15497,
10292,
2943,
275,
1824,
59,
16,
61,
10292,
10292,
327,
1107,
6183,
8,
25409,
9,
10292,
340,
2943,
508,
7,
67,
356,
1223,
198,
3,
3232,
3050,
1950,
1223,
198,
697,
275,
25709,
14,
2242,
480,
5967,
2266,
1231,
2266,
1181,
1132,
1272,
16564,
2266,
20784,
396,
2,
776,
1223,
198,
3,
9275,
282,
3920,
909,
1808,
3920,
342,
1083,
1223,
198,
3937,
275,
1592,
14,
3937,
342,
1223,
198,
3009,
275,
298,
4859,
536,
4442,
5363,
3553,
1510,
8700,
2,
221,
1223,
198,
893,
26,
1223,
198,
3,
17009,
314,
5385,
1414,
4122,
3920,
14,
2526,
8,
3009,
9,
4122,
4122,
2058,
275,
3920,
14,
10174,
342,
4122,
4122,
372,
6183,
8,
2604,
9,
28111,
198,
2590,
26,
4122,
1592,
14,
1600,
342,
4122,
372,
6183,
360,
28351,
2866,
358,
10292,
340,
2943,
508,
7,
87,
356,
15497,
198,
315,
9157,
3766,
83,
221,
275,
1824,
59,
17,
61,
15497,
198,
15497,
198,
315,
9157,
3766,
83,
29,
316,
264,
3766,
83,
14,
1294,
10994,
531,
15497,
198,
221,
15497,
198,
1592,
275,
25709,
14,
2242,
480,
5967,
2266,
1231,
2266,
1181,
1132,
1272,
16564,
2266,
20784,
396,
2,
776,
4122,
3920,
275,
1592,
14,
3937,
342,
4122,
3875,
275,
298,
2416,
519,
354,
12,
519,
5643,
12,
519,
13191,
12,
519,
14717,
687,
334,
2416,
8012,
14,
344,
63,
13191,
465,
17121,
63,
344,
12,
519,
14,
354,
465,
519,
354,
12,
519,
14,
10577,
63,
316,
264,
3766,
83,
465,
519,
5643,
12,
519,
14,
13191,
63,
1317,
465,
519,
13191,
12,
519,
14,
14717,
465,
519,
14717,
687,
5363,
3553,
1510,
519,
12,
1621,
39,
907,
1914,
1309,
284,
12,
5363,
3553,
1510,
63,
1206,
907,
1914,
1309,
8012,
2382,
519,
14,
344,
29,
322,
14,
344,
63,
13191,
436,
284,
14,
344,
29,
322,
14,
344,
63,
316,
264,
3766,
436,
1689,
27,
4122,
367,
1962,
315,
315,
9157,
3766,
83,
26,
4122,
198,
1143,
275,
7,
284,
14,
354,
628,
6828,
1143,
11,
4065,
283,
26045,
315,
9157,
3766,
83,
29,
5522,
503,
284,
14,
354,
628,
1370,
904,
8,
316,
264,
3766,
83,
9,
4122,
315,
9157,
3766,
83,
534,
73,
14,
354,
628,
6828,
316,
264,
3766,
83,
4122,
1284,
275,
283,
2237,
465,
3002,
63,
1131,
1572,
701,
519,
354,
1865,
701,
2338,
8,
13191,
63,
344,
9,
4328,
13619,
4122,
3875,
29,
3009,
11,
316,
264,
3766,
83,
11,
500,
1223,
198,
3,
372,
6183,
8,
3009,
9,
4122,
862,
26,
1223,
198,
3,
17009,
314,
5385,
1414,
4122,
221,
3920,
14,
2526,
8,
3009,
9,
4122,
221,
2058,
275,
3920,
14,
10174,
342,
4122,
221,
754,
9287,
4122,
221,
367,
1962,
315,
2058,
26,
4122,
257,
198,
1099,
29,
1099,
5207,
3480,
7709,
495,
8,
1143,
59,
16,
566,
5207,
3480,
7709,
495,
8,
1143,
59,
17,
566,
5207,
3480,
7709,
495,
8,
1143,
59,
18,
566,
5207,
3480,
7709,
495,
8,
1143,
59,
19,
566,
5207,
12574,
2,
4122,
221,
372,
6183,
8,
495,
8,
1099,
430,
4122,
4122,
871,
26,
221,
4122,
257,
372,
6183,
8,
298,
28351,
2866,
531,
10060,
257,
198,
10292,
340,
2943,
508,
7,
82,
356,
15497,
198,
697,
275,
25709,
14,
2242,
480,
5967,
2266,
1231,
2266,
1181,
1132,
1272,
16564,
2266,
20784,
396,
2,
776,
1223,
198,
3937,
275,
1592,
14,
3937,
342,
1223,
198,
3009,
275,
298,
4859,
536,
4442,
1621,
39,
907,
1914,
1309,
8700,
2,
221,
1223,
198,
893,
26,
4122,
4122,
3920,
14,
2526,
8,
3009,
9,
26045,
2058,
275,
3920,
14,
10174,
342,
4122,
4122,
372,
6183,
8,
2604,
9,
28111,
198,
2590,
26,
4122,
1592,
14,
1600,
342,
4122,
372,
6183,
360,
28351,
2866,
358,
10292,
340,
2943,
508,
7,
72,
356,
15497,
198,
316,
264,
3766,
83,
221,
275,
1824,
59,
17,
61,
15497,
198,
15497,
198,
316,
264,
3766,
83,
29,
316,
264,
3766,
83,
14,
1294,
10994,
531,
15497,
198,
697,
275,
25709,
14,
2242,
480,
5967,
2266,
1231,
2266,
1181,
1132,
1272,
16564,
2266,
20784,
396,
2,
776,
1223,
198,
3937,
275,
1592,
14,
3937,
342,
1223,
198,
3009,
275,
298,
4859,
1305,
4442,
5363,
3553,
1510,
2382,
536,
275,
5956,
83,
7,
8700,
2,
450,
334,
316,
264,
3766,
83,
59,
17,
467,
9,
221,
1223,
198,
893,
26,
4122,
3920,
14,
2526,
8,
3009,
9,
4122,
1305,
63,
2761,
275,
1109,
8,
3920,
14,
10174,
3430,
16,
1527,
16,
566,
28111,
198,
2590,
26,
4122,
1592,
14,
1600,
342,
4122,
372,
6183,
360,
3592,
1911,
17,
358,
10060,
198,
697,
275,
25709,
14,
2242,
480,
5967,
2266,
1231,
2266,
1181,
1132,
1272,
16564,
2266,
20784,
396,
2,
776,
1223,
198,
3937,
275,
1592,
14,
3937,
342,
1223,
198,
3009,
275,
298,
4859,
1305,
4442,
13044,
2382,
922,
63,
354,
275,
5956,
83,
7,
8700,
2,
450,
334,
316,
264,
3766,
83,
59,
16,
467,
9,
221,
1223,
198,
893,
26,
4122,
3920,
14,
2526,
8,
3009,
9,
4122,
1305,
63,
2647,
275,
1109,
8,
3920,
14,
10174,
3430,
16,
1527,
16,
566,
28111,
198,
2590,
26,
4122,
1592,
14,
1600,
342,
4122,
372,
6183,
360,
3592,
1911,
18,
358,
1223,
198,
3,
1107,
6183,
8,
344,
63,
2647,
9,
1223,
198,
697,
275,
25709,
14,
2242,
480,
5967,
2266,
1231,
2266,
1181,
1132,
1272,
16564,
2266,
20784,
396,
2,
776,
1223,
198,
3937,
275,
1592,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
RichDijk/eXe
|
twisted/pb/call.py
|
14
|
19649
|
try:
import cStringIO as StringIO
except ImportError:
import StringIO
from twisted.python import failure, log
from twisted.python.components import registerAdapter
from twisted.internet import defer
from twisted.pb import remoteinterface, copyable, slicer, schema, tokens
from tokens import BananaError, Violation, ISlicer
class PendingRequest(object):
active = True
methodName = None # for debugging
def __init__(self, reqID, rref=None):
self.reqID = reqID
self.rref = rref # keep it alive
self.broker = None # if set, the broker knows about us
self.deferred = defer.Deferred()
self.constraint = None # this constrains the results
def setConstraint(self, constraint):
self.constraint = constraint
def complete(self, res):
if self.broker:
self.broker.removeRequest(self)
if self.active:
self.active = False
self.deferred.callback(res)
else:
log.msg("PendingRequest.complete called on an inactive request")
def fail(self, why):
if self.active:
if self.broker:
self.broker.removeRequest(self)
self.active = False
self.failure = why
# TODO: this is a bit verbose, only enable it when debugging
log.msg("a callRemote(reqID=%d, rref=%s, methname=%s) failed" \
% (self.reqID, self.rref, self.methodName))
log.msg(" the failure is: %s" % (why,))
self.deferred.errback(why)
else:
log.msg("multiple failures")
log.msg("first one was:", self.failure)
log.msg("this one was:", why)
log.err("multiple failures indicate a problem")
class CallSlicer(slicer.ScopedSlicer):
opentype = ('call',)
def __init__(self, reqID, clid, methodname, args):
slicer.ScopedSlicer.__init__(self, None)
self.reqID = reqID
self.clid = clid
self.methodname = methodname
self.args = args
def sliceBody(self, streamable, banana):
yield self.reqID
yield self.clid
yield self.methodname
keys = self.args.keys()
keys.sort()
for argname in keys:
yield argname
yield self.args[argname]
def describe(self):
return "<call-%s-%s-%s>" % (self.reqID, self.clid, self.methodname)
class CallUnslicer(slicer.ScopedUnslicer):
# 0:reqID, 1:objID, 2:methodname, 3: [(argname/value)]..
stage = 0
reqID = None
obj = None
interface = None
methodname = None
methodSchema = None # will be a MethodArgumentsConstraint
argname = None
argConstraint = None
def start(self, count):
self.args = {}
self.deferred = defer.Deferred()
self.num_unreferenceable_children = 0
self.num_unready_children = 0
def checkToken(self, typebyte, size):
# TODO: limit strings by returning a number instead of None
if self.stage == 0:
if typebyte != tokens.INT:
raise BananaError("request ID must be an INT")
elif self.stage == 1:
if typebyte not in (tokens.INT, tokens.NEG):
raise BananaError("object ID must be an INT/NEG")
elif self.stage == 2:
if typebyte not in (tokens.STRING, tokens.VOCAB):
raise BananaError("method name must be a STRING")
# TODO: limit to longest method name of self.obj in the interface
elif self.stage == 3:
if self.argname == None:
if typebyte not in (tokens.STRING, tokens.VOCAB):
raise BananaError("argument name must be a STRING")
# TODO: limit to the longest argname in the method
else:
if self.argConstraint:
self.argConstraint.checkToken(typebyte, size)
def doOpen(self, opentype):
# checkToken insures that this can only happen when we're receiving
# an argument value, so we don't have to bother checking self.stage
# or self.argname
if self.argConstraint:
self.argConstraint.checkOpentype(opentype)
unslicer = self.open(opentype)
if unslicer:
if self.argConstraint:
unslicer.setConstraint(self.argConstraint)
return unslicer
def reportViolation(self, f):
# if the Violation is because we received an ABORT, then we know
# that the sender knows there was a problem, so don't respond.
if f.value.args[0] == "ABORT received":
return f
# if the Violation was raised after we know the reqID, we can send
# back an Error.
if self.stage > 0:
self.broker.callFailed(f, self.reqID)
return f # give up our sequence
def receiveChild(self, token, ready_deferred=None):
if self.stage < 3:
assert not isinstance(token, defer.Deferred)
assert ready_deferred is None
#print "CallUnslicer.receiveChild [s%d]" % self.stage, repr(token)
# TODO: if possible, return an error to the other side
if self.stage == 0: # reqID
# we don't yet know which reqID to send any failure to
self.reqID = token
self.stage += 1
assert not self.broker.activeLocalCalls.get(self.reqID)
self.broker.activeLocalCalls[self.reqID] = self
return
if self.stage == 1: # objID
# this might raise an exception if objID is invalid
self.objID = token
self.obj = self.broker.getMyReferenceByCLID(token)
#iface = self.broker.getRemoteInterfaceByName(token)
if self.objID < 0:
self.interface = None
else:
self.interface = self.obj.getInterface()
self.stage = 2
return
if self.stage == 2: # methodname
# validate the methodname, get the schema. This may raise an
# exception for unknown methods
if self.objID < 0:
# the target is a bound method
self.methodSchema = getattr(self.obj, "methodSchema", None)
self.methodname = None # TODO: give it something useful
if self.broker.requireSchema and not self.methodSchema:
why = "This broker does not accept unconstrained " + \
"method calls"
raise Violation(why)
self.stage = 3
return
methodname = token
# must find the schema, using the interfaces
# TODO: getSchema should probably be in an adapter instead of in
# a pb.Referenceable base class. Old-style (unconstrained)
# flavors.Referenceable should be adapted to something which
# always returns None
# TODO: make this faster. A likely optimization is to take a
# tuple of components.getInterfaces(obj) and use it as a cache
# key. It would be even faster to use obj.__class__, but that
# would probably violate the expectation that instances can
# define their own __implements__ (independently from their
# class). If this expectation were to go away, a quick
# obj.__class__ -> RemoteReferenceSchema cache could be built.
ms = None
if self.interface:
# they are calling an interface+method pair
ms = self.interface.get(methodname)
if not ms:
why = "method '%s' not defined in %s" % \
(methodname, self.interface.__remote_name__)
raise Violation(why)
self.methodSchema = ms
self.methodname = methodname
if self.broker.requireSchema and not self.methodSchema:
why = "This broker does not accept unconstrained method calls"
raise Violation(why)
self.stage = 3
return
if self.stage == 3: # argname/value pairs
if self.argname == None:
assert not isinstance(token, defer.Deferred)
assert ready_deferred is None
argname = token
if self.args.has_key(argname):
raise BananaError("duplicate argument '%s'" % argname)
ms = self.methodSchema
if ms:
# if the argname is invalid, this may raise Violation
accept, self.argConstraint = ms.getArgConstraint(argname)
assert accept # TODO: discard if not
self.argname = argname
else:
argvalue = token
if isinstance(argvalue, defer.Deferred):
self.num_unreferenceable_children += 1
argvalue.addCallback(self.update, self.argname)
argvalue.addErrback(self.explode)
self.args[self.argname] = argvalue
self.argname = None
if ready_deferred:
self.num_unready_children += 1
ready_deferred.addCallback(self.ready)
def update(self, obj, argname):
self.args[argname] = obj
self.num_unreferenceable_children -= 1
self.checkComplete()
return obj
def ready(self, obj):
self.num_unready_children -= 1
self.checkComplete()
return obj
def receiveClose(self):
if self.stage != 3 or self.argname != None:
raise BananaError("'call' sequence ended too early")
self.stage = 4
return self.checkComplete()
def checkComplete(self):
if self.stage != 4:
return
if self.num_unreferenceable_children or self.num_unready_children:
# not finished yet
return self.deferred, None
# all our args are available
if self.methodSchema:
# ask them again so they can look for missing arguments
self.methodSchema.checkArgs(self.args)
# this is where we actually call the method. doCall must now take
# responsibility for the request (specifically for catching any
# exceptions and doing callFailed)
self.broker.doCall(self.reqID, self.obj, self.methodname,
self.args, self.methodSchema)
self.deferred.callback(None)
return None, None
def describe(self):
s = "<methodcall"
if self.stage == 0:
pass
if self.stage == 1:
s += " reqID=%d" % self.reqID
if self.stage == 2:
s += " obj=%s" % (self.obj,)
ifacename = "[none]"
if self.interface:
ifacename = self.interface.__remote_name__
s += " iface=%s" % ifacename
if self.stage == 3:
s += " .%s" % self.methodname
if self.argname != None:
s += " arg[%s]" % self.argname
if self.stage == 4:
s += " .close"
s += ">"
return s
class AnswerSlicer(slicer.ScopedSlicer):
opentype = ('answer',)
def __init__(self, reqID, results):
slicer.ScopedSlicer.__init__(self, None)
self.reqID = reqID
self.results = results
def sliceBody(self, streamable, banana):
yield self.reqID
yield self.results
def describe(self):
return "<answer-%s>" % self.reqID
class AnswerUnslicer(slicer.ScopedUnslicer):
request = None
resultConstraint = None
haveResults = False
def checkToken(self, typebyte, size):
if self.request is None:
if typebyte != tokens.INT:
raise BananaError("request ID must be an INT")
elif not self.haveResults:
if self.resultConstraint:
try:
self.resultConstraint.checkToken(typebyte, size)
except Violation, v:
# improve the error message
if v.args:
# this += gives me a TypeError "object doesn't
# support item assignment", which confuses me
#v.args[0] += " in inbound method results"
why = v.args[0] + " in inbound method results"
v.args = why,
else:
v.args = ("in inbound method results",)
raise v # this will errback the request
else:
raise BananaError("stop sending me stuff!")
def doOpen(self, opentype):
if self.resultConstraint:
self.resultConstraint.checkOpentype(opentype)
# TODO: improve the error message
unslicer = self.open(opentype)
if unslicer:
if self.resultConstraint:
unslicer.setConstraint(self.resultConstraint)
return unslicer
def receiveChild(self, token, ready_deferred=None):
assert not isinstance(token, defer.Deferred)
assert ready_deferred is None
if self.request == None:
reqID = token
# may raise Violation for bad reqIDs
self.request = self.broker.getRequest(reqID)
self.resultConstraint = self.request.constraint
else:
self.results = token
self.haveResults = True
def reportViolation(self, f):
# if the Violation was received after we got the reqID, we can tell
# the broker it was an error
if self.request != None:
self.request.fail(f)
return f # give up our sequence
def receiveClose(self):
self.request.complete(self.results)
return None, None
def describe(self):
if self.request:
return "Answer(req=%s)" % self.request.reqID
return "Answer(req=?)"
class ErrorSlicer(slicer.ScopedSlicer):
opentype = ('error',)
def __init__(self, reqID, f):
slicer.ScopedSlicer.__init__(self, None)
assert isinstance(f, failure.Failure)
self.reqID = reqID
self.f = f
def sliceBody(self, streamable, banana):
yield self.reqID
yield self.f
def describe(self):
return "<error-%s>" % self.reqID
class ErrorUnslicer(slicer.ScopedUnslicer):
request = None
fConstraint = schema.FailureConstraint()
gotFailure = False
def checkToken(self, typebyte, size):
if self.request == None:
if typebyte != tokens.INT:
raise BananaError("request ID must be an INT")
elif not self.gotFailure:
self.fConstraint.checkToken(typebyte, size)
else:
raise BananaError("stop sending me stuff!")
def doOpen(self, opentype):
self.fConstraint.checkOpentype(opentype)
unslicer = self.open(opentype)
if unslicer:
unslicer.setConstraint(self.fConstraint)
return unslicer
def reportViolation(self, f):
# a failure while receiving the failure. A bit daft, really.
if self.request != None:
self.request.fail(f)
return f # give up our sequence
def receiveChild(self, token, ready_deferred=None):
assert not isinstance(token, defer.Deferred)
assert ready_deferred is None
if self.request == None:
reqID = token
# may raise BananaError for bad reqIDs
self.request = self.broker.getRequest(reqID)
else:
self.failure = token
self.gotFailure = True
def receiveClose(self):
self.request.fail(self.failure)
return None, None
def describe(self):
if self.request is None:
return "<error-?>"
return "<error-%s>" % self.request.reqID
# failures are sent as Copyables
class FailureSlicer(slicer.BaseSlicer):
slices = failure.Failure
classname = "twisted.python.failure.Failure"
def slice(self, streamable, banana):
self.streamable = streamable
yield 'copyable'
yield self.classname
state = self.getStateToCopy(self.obj, banana)
for k,v in state.iteritems():
yield k
yield v
def describe(self):
return "<%s>" % self.classname
def getStateToCopy(self, obj, broker):
#state = obj.__dict__.copy()
#state['tb'] = None
#state['frames'] = []
#state['stack'] = []
state = {}
if isinstance(obj.value, failure.Failure):
# TODO: how can this happen? I got rid of failure2Copyable, so
# if this case is possible, something needs to replace it
raise RuntimeError("not implemented yet")
#state['value'] = failure2Copyable(obj.value, banana.unsafeTracebacks)
else:
state['value'] = str(obj.value) # Exception instance
state['type'] = str(obj.type) # Exception class
if broker.unsafeTracebacks:
io = StringIO.StringIO()
obj.printTraceback(io)
state['traceback'] = io.getvalue()
# TODO: provide something with globals and locals and HTML and
# all that cool stuff
else:
state['traceback'] = 'Traceback unavailable\n'
if len(state['traceback']) > 1900:
state['traceback'] = (state['traceback'][:1900] +
"\n\n-- TRACEBACK TRUNCATED --\n")
state['parents'] = obj.parents
return state
class CopiedFailure(failure.Failure, copyable.RemoteCopyOldStyle):
# this is a RemoteCopyOldStyle because you can't raise new-style
# instances as exceptions.
"""I am a shadow of some remote Failure instance. I contain less
information than the original did.
You can still extract a (brief) printable traceback from me. My .parents
attribute is a list of strings describing the class of the exception
that I contain, just like the real Failure had, so my trap() and check()
methods work fine. My .type and .value attributes are string
representations of the original exception class and exception instance,
respectively. The most significant effect is that you cannot access
f.value.args, and should instead just use f.value .
My .frames and .stack attributes are empty, although this may change in
the future (and with the cooperation of the sender).
"""
nonCyclic = True
stateSchema = schema.FailureConstraint()
def __init__(self):
copyable.RemoteCopyOldStyle.__init__(self)
def setCopyableState(self, state):
#self.__dict__.update(state)
self.__dict__ = state
# state includes: type, value, traceback, parents
#self.type = state['type']
#self.value = state['value']
#self.traceback = state['traceback']
#self.parents = state['parents']
self.tb = None
self.frames = []
self.stack = []
def __str__(self):
return "[CopiedFailure instance: %s]" % self.getBriefTraceback()
pickled = 1
def printTraceback(self, file=None, elideFrameworkCode=0,
detail='default'):
if not file: file = log.logfile
file.write("Traceback from remote host -- ")
file.write(self.traceback)
printBriefTraceback = printTraceback
printDetailedTraceback = printTraceback
copyable.registerRemoteCopy(FailureSlicer.classname, CopiedFailure)
|
gpl-2.0
|
[
199,
893,
26,
272,
492,
15073,
465,
5228,
199,
2590,
3545,
26,
272,
492,
5228,
199,
199,
504,
7390,
14,
1548,
492,
5988,
12,
943,
199,
504,
7390,
14,
1548,
14,
4608,
492,
2274,
10200,
199,
504,
7390,
14,
4901,
492,
10133,
199,
199,
504,
7390,
14,
3317,
492,
3982,
3266,
12,
1331,
461,
12,
308,
27975,
12,
4177,
12,
4645,
199,
504,
4645,
492,
699,
290,
6738,
547,
12,
6561,
10410,
12,
2281,
27975,
421,
199,
533,
29216,
2017,
8,
785,
304,
272,
4702,
275,
715,
272,
23352,
275,
488,
327,
367,
10201,
339,
347,
636,
826,
721,
277,
12,
2648,
998,
12,
519,
1121,
29,
403,
304,
267,
291,
14,
2103,
998,
275,
2648,
998,
267,
291,
14,
82,
1121,
275,
519,
1121,
327,
4215,
652,
19708,
267,
291,
14,
16620,
275,
488,
327,
340,
663,
12,
314,
15416,
19428,
3595,
2739,
267,
291,
14,
12116,
275,
10133,
14,
9937,
342,
267,
291,
14,
5631,
275,
488,
327,
642,
950,
345,
3617,
314,
2058,
339,
347,
663,
8463,
8,
277,
12,
5828,
304,
267,
291,
14,
5631,
275,
5828,
339,
347,
4890,
8,
277,
12,
522,
304,
267,
340,
291,
14,
16620,
26,
288,
291,
14,
16620,
14,
2168,
2017,
8,
277,
9,
267,
340,
291,
14,
2682,
26,
288,
291,
14,
2682,
275,
756,
288,
291,
14,
12116,
14,
3058,
8,
470,
9,
267,
587,
26,
288,
943,
14,
1328,
480,
15960,
2017,
14,
4883,
2797,
641,
376,
21325,
1056,
531,
339,
347,
2449,
8,
277,
12,
10842,
304,
267,
340,
291,
14,
2682,
26,
288,
340,
291,
14,
16620,
26,
355,
291,
14,
16620,
14,
2168,
2017,
8,
277,
9,
288,
291,
14,
2682,
275,
756,
288,
291,
14,
5328,
275,
10842,
288,
327,
3254,
26,
642,
365,
282,
4546,
3376,
12,
1454,
4756,
652,
1380,
10201,
288,
943,
14,
1328,
480,
65,
1240,
6713,
8,
2103,
998,
2458,
68,
12,
519,
1121,
2458,
83,
12,
12750,
354,
2458,
83,
9,
3405,
2,
971,
490,
450,
334,
277,
14,
2103,
998,
12,
291,
14,
82,
1121,
12,
291,
14,
765,
985,
430,
288,
943,
14,
1328,
480,
314,
5988,
365,
26,
450,
83,
2,
450,
334,
26460,
4641,
288,
291,
14,
12116,
14,
28940,
8,
26460,
9,
267,
587,
26,
288,
943,
14,
1328,
480,
6048,
9081,
531,
288,
943,
14,
1328,
480,
2246,
1373,
1990,
6783,
291,
14,
5328,
9,
288,
943,
14,
1328,
480,
3749,
1373,
1990,
6783,
10842,
9,
288,
943,
14,
1508,
480,
6048,
9081,
6623,
282,
5160,
531,
421,
199,
533,
6523,
51,
27975,
8,
83,
27975,
14,
7812,
68,
51,
27975,
304,
272,
1551,
466,
275,
661,
1250,
9538,
339,
347,
636,
826,
721,
277,
12,
2648,
998,
12,
5053,
68,
12,
28009,
12,
1249,
304,
267,
308,
27975,
14,
7812,
68,
51,
27975,
855,
826,
721,
277,
12,
488,
9,
267,
291,
14,
2103,
998,
275,
2648,
998,
267,
291,
14,
2764,
68,
275,
5053,
68,
267,
291,
14,
765,
354,
275,
28009,
267,
291,
14,
589,
275,
1249,
339,
347,
6014,
8173,
8,
277,
12,
2547,
461,
12,
30354,
6738,
304,
267,
1995,
291,
14,
2103,
998,
267,
1995,
291,
14,
2764,
68,
267,
1995,
291,
14,
765,
354,
267,
2883,
275,
291,
14,
589,
14,
1612,
342,
267,
2883,
14,
3191,
342,
267,
367,
1680,
354,
315,
2883,
26,
288,
1995,
1680,
354,
288,
1995,
291,
14,
589,
59,
1273,
354,
61,
339,
347,
13743,
8,
277,
304,
267,
372,
3886,
1250,
3295,
83,
3295,
83,
3295,
83,
4335,
450,
334,
277,
14,
2103,
998,
12,
291,
14,
2764,
68,
12,
291,
14,
765,
354,
9,
199,
199,
533,
6523,
9251,
27975,
8,
83,
27975,
14,
7812,
68,
9251,
27975,
304,
272,
327,
378,
26,
2103,
998,
12,
413,
26,
1113,
998,
12,
499,
26,
765,
354,
12,
650,
26,
3842,
1273,
354,
15,
585,
1874,
703,
272,
9546,
275,
378,
272,
2648,
998,
275,
488,
272,
1559,
275,
488,
272,
3217,
275,
488,
272,
28009,
275,
488,
272,
1083,
6700,
275,
488,
327,
911,
506,
282,
9075,
14517,
8463,
272,
1680,
354,
275,
488,
272,
1680,
8463,
275,
488,
339,
347,
1343,
8,
277,
12,
2338,
304,
267,
291,
14,
589,
275,
1052,
267,
291,
14,
12116,
275,
10133,
14,
9937,
342,
267,
291,
14,
1507,
63,
324,
4443,
461,
63,
3223,
275,
378,
267,
291,
14,
1507,
63,
324,
2179,
63,
3223,
275,
378,
339,
347,
1104,
3264,
8,
277,
12,
730,
4414,
12,
1568,
304,
267,
327,
3254,
26,
2304,
3326,
701,
8152,
282,
1329,
3140,
402,
488,
267,
340,
291,
14,
8614,
508,
378,
26,
288,
340,
730,
4414,
1137,
4645,
14,
2919,
26,
355,
746,
699,
290,
6738,
547,
480,
1069,
2870,
1471,
506,
376,
16429,
531,
267,
916,
291,
14,
8614,
508,
413,
26,
288,
340,
730,
4414,
440,
315,
334,
4504,
14,
2919,
12,
4645,
14,
31254,
304,
355,
746,
699,
290,
6738,
547,
480,
785,
2870,
1471,
506,
376,
16429,
15,
31254,
531,
267,
916,
291,
14,
8614,
508,
499,
26,
288,
340,
730,
4414,
440,
315,
334,
4504,
14,
5353,
12,
4645,
14,
10662,
35,
1217,
304,
355,
746,
699,
290,
6738,
547,
480,
765,
536,
1471,
506,
282,
18661,
531,
288,
327,
3254,
26,
2304,
370,
21303,
1083,
536,
402,
291,
14,
1113,
315,
314,
3217,
267,
916,
291,
14,
8614,
508,
650,
26,
288,
340,
291,
14,
1273,
354,
508,
488,
26,
355,
340,
730,
4414,
440,
315,
334,
4504,
14,
5353,
12,
4645,
14,
10662,
35,
1217,
304,
490,
746,
699,
290,
6738,
547,
480,
2094,
536,
1471,
506,
282,
18661,
531,
355,
327,
3254,
26,
2304,
370,
314,
21303,
1680,
354,
315,
314,
1083,
288,
587,
26,
355,
340,
291,
14,
1273,
8463,
26,
490,
291,
14,
1273,
8463,
14,
1074,
3264,
8,
466,
4414,
12,
1568,
9,
339,
347,
886,
4299,
8,
277,
12,
1551,
466,
304,
267,
327,
1104,
3264,
5261,
1482,
626,
642,
883,
1454,
5992,
1380,
781,
3984,
18390,
267,
327,
376,
1423,
574,
12,
880,
781,
2793,
1133,
1172,
370,
26962,
7907,
291,
14,
8614,
267,
327,
503,
291,
14,
1273,
354,
267,
340,
291,
14,
1273,
8463,
26,
288,
291,
14,
1273
] |
[
893,
26,
272,
492,
15073,
465,
5228,
199,
2590,
3545,
26,
272,
492,
5228,
199,
199,
504,
7390,
14,
1548,
492,
5988,
12,
943,
199,
504,
7390,
14,
1548,
14,
4608,
492,
2274,
10200,
199,
504,
7390,
14,
4901,
492,
10133,
199,
199,
504,
7390,
14,
3317,
492,
3982,
3266,
12,
1331,
461,
12,
308,
27975,
12,
4177,
12,
4645,
199,
504,
4645,
492,
699,
290,
6738,
547,
12,
6561,
10410,
12,
2281,
27975,
421,
199,
533,
29216,
2017,
8,
785,
304,
272,
4702,
275,
715,
272,
23352,
275,
488,
327,
367,
10201,
339,
347,
636,
826,
721,
277,
12,
2648,
998,
12,
519,
1121,
29,
403,
304,
267,
291,
14,
2103,
998,
275,
2648,
998,
267,
291,
14,
82,
1121,
275,
519,
1121,
327,
4215,
652,
19708,
267,
291,
14,
16620,
275,
488,
327,
340,
663,
12,
314,
15416,
19428,
3595,
2739,
267,
291,
14,
12116,
275,
10133,
14,
9937,
342,
267,
291,
14,
5631,
275,
488,
327,
642,
950,
345,
3617,
314,
2058,
339,
347,
663,
8463,
8,
277,
12,
5828,
304,
267,
291,
14,
5631,
275,
5828,
339,
347,
4890,
8,
277,
12,
522,
304,
267,
340,
291,
14,
16620,
26,
288,
291,
14,
16620,
14,
2168,
2017,
8,
277,
9,
267,
340,
291,
14,
2682,
26,
288,
291,
14,
2682,
275,
756,
288,
291,
14,
12116,
14,
3058,
8,
470,
9,
267,
587,
26,
288,
943,
14,
1328,
480,
15960,
2017,
14,
4883,
2797,
641,
376,
21325,
1056,
531,
339,
347,
2449,
8,
277,
12,
10842,
304,
267,
340,
291,
14,
2682,
26,
288,
340,
291,
14,
16620,
26,
355,
291,
14,
16620,
14,
2168,
2017,
8,
277,
9,
288,
291,
14,
2682,
275,
756,
288,
291,
14,
5328,
275,
10842,
288,
327,
3254,
26,
642,
365,
282,
4546,
3376,
12,
1454,
4756,
652,
1380,
10201,
288,
943,
14,
1328,
480,
65,
1240,
6713,
8,
2103,
998,
2458,
68,
12,
519,
1121,
2458,
83,
12,
12750,
354,
2458,
83,
9,
3405,
2,
971,
490,
450,
334,
277,
14,
2103,
998,
12,
291,
14,
82,
1121,
12,
291,
14,
765,
985,
430,
288,
943,
14,
1328,
480,
314,
5988,
365,
26,
450,
83,
2,
450,
334,
26460,
4641,
288,
291,
14,
12116,
14,
28940,
8,
26460,
9,
267,
587,
26,
288,
943,
14,
1328,
480,
6048,
9081,
531,
288,
943,
14,
1328,
480,
2246,
1373,
1990,
6783,
291,
14,
5328,
9,
288,
943,
14,
1328,
480,
3749,
1373,
1990,
6783,
10842,
9,
288,
943,
14,
1508,
480,
6048,
9081,
6623,
282,
5160,
531,
421,
199,
533,
6523,
51,
27975,
8,
83,
27975,
14,
7812,
68,
51,
27975,
304,
272,
1551,
466,
275,
661,
1250,
9538,
339,
347,
636,
826,
721,
277,
12,
2648,
998,
12,
5053,
68,
12,
28009,
12,
1249,
304,
267,
308,
27975,
14,
7812,
68,
51,
27975,
855,
826,
721,
277,
12,
488,
9,
267,
291,
14,
2103,
998,
275,
2648,
998,
267,
291,
14,
2764,
68,
275,
5053,
68,
267,
291,
14,
765,
354,
275,
28009,
267,
291,
14,
589,
275,
1249,
339,
347,
6014,
8173,
8,
277,
12,
2547,
461,
12,
30354,
6738,
304,
267,
1995,
291,
14,
2103,
998,
267,
1995,
291,
14,
2764,
68,
267,
1995,
291,
14,
765,
354,
267,
2883,
275,
291,
14,
589,
14,
1612,
342,
267,
2883,
14,
3191,
342,
267,
367,
1680,
354,
315,
2883,
26,
288,
1995,
1680,
354,
288,
1995,
291,
14,
589,
59,
1273,
354,
61,
339,
347,
13743,
8,
277,
304,
267,
372,
3886,
1250,
3295,
83,
3295,
83,
3295,
83,
4335,
450,
334,
277,
14,
2103,
998,
12,
291,
14,
2764,
68,
12,
291,
14,
765,
354,
9,
199,
199,
533,
6523,
9251,
27975,
8,
83,
27975,
14,
7812,
68,
9251,
27975,
304,
272,
327,
378,
26,
2103,
998,
12,
413,
26,
1113,
998,
12,
499,
26,
765,
354,
12,
650,
26,
3842,
1273,
354,
15,
585,
1874,
703,
272,
9546,
275,
378,
272,
2648,
998,
275,
488,
272,
1559,
275,
488,
272,
3217,
275,
488,
272,
28009,
275,
488,
272,
1083,
6700,
275,
488,
327,
911,
506,
282,
9075,
14517,
8463,
272,
1680,
354,
275,
488,
272,
1680,
8463,
275,
488,
339,
347,
1343,
8,
277,
12,
2338,
304,
267,
291,
14,
589,
275,
1052,
267,
291,
14,
12116,
275,
10133,
14,
9937,
342,
267,
291,
14,
1507,
63,
324,
4443,
461,
63,
3223,
275,
378,
267,
291,
14,
1507,
63,
324,
2179,
63,
3223,
275,
378,
339,
347,
1104,
3264,
8,
277,
12,
730,
4414,
12,
1568,
304,
267,
327,
3254,
26,
2304,
3326,
701,
8152,
282,
1329,
3140,
402,
488,
267,
340,
291,
14,
8614,
508,
378,
26,
288,
340,
730,
4414,
1137,
4645,
14,
2919,
26,
355,
746,
699,
290,
6738,
547,
480,
1069,
2870,
1471,
506,
376,
16429,
531,
267,
916,
291,
14,
8614,
508,
413,
26,
288,
340,
730,
4414,
440,
315,
334,
4504,
14,
2919,
12,
4645,
14,
31254,
304,
355,
746,
699,
290,
6738,
547,
480,
785,
2870,
1471,
506,
376,
16429,
15,
31254,
531,
267,
916,
291,
14,
8614,
508,
499,
26,
288,
340,
730,
4414,
440,
315,
334,
4504,
14,
5353,
12,
4645,
14,
10662,
35,
1217,
304,
355,
746,
699,
290,
6738,
547,
480,
765,
536,
1471,
506,
282,
18661,
531,
288,
327,
3254,
26,
2304,
370,
21303,
1083,
536,
402,
291,
14,
1113,
315,
314,
3217,
267,
916,
291,
14,
8614,
508,
650,
26,
288,
340,
291,
14,
1273,
354,
508,
488,
26,
355,
340,
730,
4414,
440,
315,
334,
4504,
14,
5353,
12,
4645,
14,
10662,
35,
1217,
304,
490,
746,
699,
290,
6738,
547,
480,
2094,
536,
1471,
506,
282,
18661,
531,
355,
327,
3254,
26,
2304,
370,
314,
21303,
1680,
354,
315,
314,
1083,
288,
587,
26,
355,
340,
291,
14,
1273,
8463,
26,
490,
291,
14,
1273,
8463,
14,
1074,
3264,
8,
466,
4414,
12,
1568,
9,
339,
347,
886,
4299,
8,
277,
12,
1551,
466,
304,
267,
327,
1104,
3264,
5261,
1482,
626,
642,
883,
1454,
5992,
1380,
781,
3984,
18390,
267,
327,
376,
1423,
574,
12,
880,
781,
2793,
1133,
1172,
370,
26962,
7907,
291,
14,
8614,
267,
327,
503,
291,
14,
1273,
354,
267,
340,
291,
14,
1273,
8463,
26,
288,
291,
14,
1273,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
scs/uclinux
|
user/samba/samba-3.0.25a/source/stf/strings.py
|
55
|
5889
|
#! /usr/bin/python
# Comfychair test cases for Samba string functions.
# Copyright (C) 2003 by Martin Pool <mbp@samba.org>
#
# 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
# XXX: All this code assumes that the Unix character set is UTF-8,
# which is the most common setting. I guess it would be better to
# force it to that value while running the tests. I'm not sure of the
# best way to do that yet.
#
# Note that this is NOT the case in C code until the loadparm table is
# intialized -- the default seems to be ASCII, which rather lets Samba
# off the hook. :-) The best way seems to be to put this in the test
# harnesses:
#
# lp_load("/dev/null", True, False, False);
#
# -- mbp
import sys, re, comfychair
from unicodenames import *
def signum(a):
if a < 0:
return -1
elif a > 0:
return +1
else:
return 0
class PushUCS2_Tests(comfychair.TestCase):
"""Conversion to/from UCS2"""
def runtest(self):
OE = LATIN_CAPITAL_LETTER_O_WITH_DIARESIS
oe = LATIN_CAPITAL_LETTER_O_WITH_DIARESIS
cases = ['hello',
'hello world',
'g' + OE + OE + 'gomobile',
'g' + OE + oe + 'gomobile',
u'foo\u0100',
KATAKANA_LETTER_A * 20,
]
for u8str in cases:
out, err = self.runcmd("t_push_ucs2 \"%s\"" % u8str.encode('utf-8'))
self.assert_equal(out, "0\n")
class StrCaseCmp(comfychair.TestCase):
"""String comparisons in simple ASCII"""
def run_strcmp(self, a, b, expect):
out, err = self.runcmd('t_strcmp \"%s\" \"%s\"' % (a.encode('utf-8'), b.encode('utf-8')))
if signum(int(out)) != expect:
self.fail("comparison failed:\n"
" a=%s\n"
" b=%s\n"
" expected=%s\n"
" result=%s\n" % (`a`, `b`, `expect`, `out`))
def runtest(self):
# A, B, strcasecmp(A, B)
cases = [('hello', 'hello', 0),
('hello', 'goodbye', +1),
('goodbye', 'hello', -1),
('hell', 'hello', -1),
('', '', 0),
('a', '', +1),
('', 'a', -1),
('a', 'A', 0),
('aa', 'aA', 0),
('Aa', 'aa', 0),
('longstring ' * 100, 'longstring ' * 100, 0),
('longstring ' * 100, 'longstring ' * 100 + 'a', -1),
('longstring ' * 100 + 'a', 'longstring ' * 100, +1),
(KATAKANA_LETTER_A, KATAKANA_LETTER_A, 0),
(KATAKANA_LETTER_A, 'a', 1),
]
for a, b, expect in cases:
self.run_strcmp(a, b, expect)
class strstr_m(comfychair.TestCase):
"""String comparisons in simple ASCII"""
def run_strstr(self, a, b, expect):
out, err = self.runcmd('t_strstr \"%s\" \"%s\"' % (a.encode('utf-8'), b.encode('utf-8')))
if (out != (expect + '\n').encode('utf-8')):
self.fail("comparison failed:\n"
" a=%s\n"
" b=%s\n"
" expected=%s\n"
" result=%s\n" % (`a`, `b`, `expect+'\n'`, `out`))
def runtest(self):
# A, B, strstr_m(A, B)
cases = [('hello', 'hello', 'hello'),
('hello', 'goodbye', '(null)'),
('goodbye', 'hello', '(null)'),
('hell', 'hello', '(null)'),
('hello', 'hell', 'hello'),
('', '', ''),
('a', '', 'a'),
('', 'a', '(null)'),
('a', 'A', '(null)'),
('aa', 'aA', '(null)'),
('Aa', 'aa', '(null)'),
('%v foo', '%v', '%v foo'),
('foo %v foo', '%v', '%v foo'),
('foo %v', '%v', '%v'),
('longstring ' * 100, 'longstring ' * 99, 'longstring ' * 100),
('longstring ' * 99, 'longstring ' * 100, '(null)'),
('longstring a' * 99, 'longstring ' * 100 + 'a', '(null)'),
('longstring ' * 100 + 'a', 'longstring ' * 100, 'longstring ' * 100 + 'a'),
(KATAKANA_LETTER_A, KATAKANA_LETTER_A + 'bcd', '(null)'),
(KATAKANA_LETTER_A + 'bcde', KATAKANA_LETTER_A + 'bcd', KATAKANA_LETTER_A + 'bcde'),
('d'+KATAKANA_LETTER_A + 'bcd', KATAKANA_LETTER_A + 'bcd', KATAKANA_LETTER_A + 'bcd'),
('d'+KATAKANA_LETTER_A + 'bd', KATAKANA_LETTER_A + 'bcd', '(null)'),
('e'+KATAKANA_LETTER_A + 'bcdf', KATAKANA_LETTER_A + 'bcd', KATAKANA_LETTER_A + 'bcdf'),
(KATAKANA_LETTER_A, KATAKANA_LETTER_A + 'bcd', '(null)'),
(KATAKANA_LETTER_A*3, 'a', '(null)'),
]
for a, b, expect in cases:
self.run_strstr(a, b, expect)
# Define the tests exported by this module
tests = [StrCaseCmp,
strstr_m,
PushUCS2_Tests]
# Handle execution of this file as a main program
if __name__ == '__main__':
comfychair.main(tests)
# Local variables:
# coding: utf-8
# End:
|
gpl-2.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1548,
420,
199,
199,
3,
5429,
1399,
335,
8387,
511,
5560,
367,
428,
14310,
1059,
3423,
14,
199,
199,
3,
1898,
334,
35,
9,
13004,
701,
603,
26788,
15553,
665,
887,
80,
32,
21693,
14,
1308,
30,
199,
3,
221,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
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,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
199,
3,
8217,
199,
199,
3,
5787,
26,
2900,
642,
1233,
15194,
626,
314,
13074,
4528,
663,
365,
9094,
13,
24,
12,
199,
3,
1314,
365,
314,
4750,
2863,
4260,
14,
221,
473,
9519,
652,
3955,
506,
8034,
370,
199,
3,
3542,
652,
370,
626,
574,
1830,
3879,
314,
2295,
14,
221,
473,
6704,
440,
3238,
402,
314,
199,
3,
5526,
4340,
370,
886,
626,
5966,
14,
199,
3,
221,
199,
3,
3390,
626,
642,
365,
2845,
314,
1930,
315,
445,
1233,
5133,
314,
2248,
22176,
1817,
365,
199,
3,
315,
1009,
1759,
1553,
314,
849,
12237,
370,
506,
10485,
12,
1314,
7830,
19083,
428,
14310,
199,
3,
2331,
314,
5759,
14,
22901,
9,
710,
5526,
4340,
12237,
370,
506,
370,
5324,
642,
315,
314,
511,
199,
3,
394,
1060,
397,
874,
26,
199,
3,
199,
3,
755,
13204,
63,
912,
4769,
2374,
15,
2307,
401,
715,
12,
756,
12,
756,
2736,
199,
3,
199,
3,
1553,
333,
10913,
199,
199,
646,
984,
12,
295,
12,
2414,
1399,
335,
8387,
199,
504,
2649,
1247,
492,
627,
199,
199,
318,
2070,
453,
8,
65,
304,
272,
340,
282,
665,
378,
26,
267,
372,
446,
17,
272,
916,
282,
690,
378,
26,
267,
372,
435,
17,
272,
587,
26,
267,
372,
378,
421,
199,
533,
22643,
21269,
18,
63,
2925,
8,
957,
1399,
335,
8387,
14,
1746,
304,
272,
408,
20403,
370,
15,
504,
21884,
18,
624,
272,
347,
1255,
396,
8,
277,
304,
267,
593,
37,
275,
1948,
63,
35,
2669,
63,
44,
1573,
63,
47,
63,
9139,
63,
1914,
689,
8202,
267,
312,
69,
275,
1948,
63,
35,
2669,
63,
44,
1573,
63,
47,
63,
9139,
63,
1914,
689,
8202,
267,
5560,
275,
788,
5006,
297,
326,
283,
5006,
6701,
297,
326,
283,
71,
7,
435,
593,
37,
435,
593,
37,
435,
283,
1939,
11375,
297,
20169,
283,
71,
7,
435,
593,
37,
435,
312,
69,
435,
283,
1939,
11375,
297,
20169,
399,
7,
1421,
60,
85,
16569,
297,
326,
1804,
2751,
43,
879,
33,
63,
44,
1573,
63,
33,
627,
3388,
12,
326,
1622,
267,
367,
399,
24,
495,
315,
5560,
26,
288,
734,
12,
2329,
275,
291,
14,
1065,
1760,
480,
84,
63,
5335,
63,
23880,
18,
18321,
83,
18781,
450,
399,
24,
495,
14,
2143,
360,
1624,
13,
24,
1333,
288,
291,
14,
479,
63,
1452,
8,
548,
12,
298,
16,
60,
78,
531,
16872,
199,
533,
8303,
1538,
31207,
8,
957,
1399,
335,
8387,
14,
1746,
304,
272,
408,
1558,
20448,
315,
3486,
10485,
624,
5591,
347,
1255,
63,
495,
5730,
8,
277,
12,
282,
12,
330,
12,
4282,
304,
267,
734,
12,
2329,
275,
291,
14,
1065,
1760,
360,
84,
63,
495,
5730,
18321,
83,
4451,
18321,
83,
4451,
7,
450,
334,
65,
14,
2143,
360,
1624,
13,
24,
659,
330,
14,
2143,
360,
1624,
13,
24,
7058,
267,
340,
2070,
453,
8,
442,
8,
548,
430,
1137,
4282,
26,
288,
291,
14,
1633,
480,
8547,
3405,
3427,
78,
2,
1993,
298,
221,
282,
2458,
83,
60,
78,
2,
1993,
298,
221,
330,
2458,
83,
60,
78,
2,
1993,
298,
221,
1420,
2458,
83,
60,
78,
2,
1993,
298,
221,
754,
2458,
83,
60,
78,
2,
450,
13493,
65,
3559,
658,
66,
3559,
658,
4921,
3559,
658,
548,
64,
430,
339,
347,
1255,
396,
8,
277,
304,
267,
327,
437,
12,
699,
12,
620,
2546,
5730,
8,
33,
12,
699,
9,
267,
5560,
275,
4274,
5006,
297,
283,
5006,
297,
378,
395,
326,
661,
5006,
297,
283,
8302,
16481,
297,
435,
17,
395,
326,
661,
8302,
16481,
297,
283,
5006,
297,
446,
17,
395,
326,
661,
72,
1697,
297,
283,
5006,
297,
446,
17,
395,
326,
13134,
3260,
378,
395,
326,
661,
65,
297,
3260,
435,
17,
395,
326,
13134,
283,
65,
297,
446,
17,
395,
326,
661,
65,
297,
283,
33,
297,
378,
395,
326,
661,
2158,
297,
283,
65,
33,
297,
378,
395,
326,
661,
33,
65,
297,
283,
2158,
297,
378,
395,
326,
661,
2809,
875,
283,
627,
2948,
12,
283,
2809,
875,
283,
627,
2948,
12,
378,
395,
326,
661,
2809,
875,
283,
627,
2948,
12,
283,
2809,
875,
283,
627,
2948,
435,
283,
65,
297,
446,
17,
395,
326,
661,
2809,
875,
283,
627,
2948,
435,
283,
65,
297,
283,
2809,
875,
283,
627,
2948,
12,
435,
17,
395,
326,
334,
43,
2751,
43,
879,
33,
63,
44,
1573,
63,
33,
12,
1804,
2751,
43,
879,
33,
63,
44,
1573,
63,
33,
12,
378,
395,
326,
334,
43,
2751,
43,
879,
33,
63,
44,
1573,
63,
33,
12,
283,
65,
297,
413,
395,
326,
1622,
267,
367,
282,
12,
330,
12,
4282,
315,
5560,
26,
288,
291,
14,
1065,
63,
495,
5730,
8,
65,
12,
330,
12,
4282,
9,
268,
199,
533,
620,
495,
63,
77,
8,
957,
1399,
335,
8387,
14,
1746,
304,
272,
408,
1558,
20448,
315,
3486,
10485,
624,
5591,
347,
1255,
63
] |
[
1182,
2647,
15,
1393,
15,
1548,
420,
199,
199,
3,
5429,
1399,
335,
8387,
511,
5560,
367,
428,
14310,
1059,
3423,
14,
199,
199,
3,
1898,
334,
35,
9,
13004,
701,
603,
26788,
15553,
665,
887,
80,
32,
21693,
14,
1308,
30,
199,
3,
221,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
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,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
199,
3,
8217,
199,
199,
3,
5787,
26,
2900,
642,
1233,
15194,
626,
314,
13074,
4528,
663,
365,
9094,
13,
24,
12,
199,
3,
1314,
365,
314,
4750,
2863,
4260,
14,
221,
473,
9519,
652,
3955,
506,
8034,
370,
199,
3,
3542,
652,
370,
626,
574,
1830,
3879,
314,
2295,
14,
221,
473,
6704,
440,
3238,
402,
314,
199,
3,
5526,
4340,
370,
886,
626,
5966,
14,
199,
3,
221,
199,
3,
3390,
626,
642,
365,
2845,
314,
1930,
315,
445,
1233,
5133,
314,
2248,
22176,
1817,
365,
199,
3,
315,
1009,
1759,
1553,
314,
849,
12237,
370,
506,
10485,
12,
1314,
7830,
19083,
428,
14310,
199,
3,
2331,
314,
5759,
14,
22901,
9,
710,
5526,
4340,
12237,
370,
506,
370,
5324,
642,
315,
314,
511,
199,
3,
394,
1060,
397,
874,
26,
199,
3,
199,
3,
755,
13204,
63,
912,
4769,
2374,
15,
2307,
401,
715,
12,
756,
12,
756,
2736,
199,
3,
199,
3,
1553,
333,
10913,
199,
199,
646,
984,
12,
295,
12,
2414,
1399,
335,
8387,
199,
504,
2649,
1247,
492,
627,
199,
199,
318,
2070,
453,
8,
65,
304,
272,
340,
282,
665,
378,
26,
267,
372,
446,
17,
272,
916,
282,
690,
378,
26,
267,
372,
435,
17,
272,
587,
26,
267,
372,
378,
421,
199,
533,
22643,
21269,
18,
63,
2925,
8,
957,
1399,
335,
8387,
14,
1746,
304,
272,
408,
20403,
370,
15,
504,
21884,
18,
624,
272,
347,
1255,
396,
8,
277,
304,
267,
593,
37,
275,
1948,
63,
35,
2669,
63,
44,
1573,
63,
47,
63,
9139,
63,
1914,
689,
8202,
267,
312,
69,
275,
1948,
63,
35,
2669,
63,
44,
1573,
63,
47,
63,
9139,
63,
1914,
689,
8202,
267,
5560,
275,
788,
5006,
297,
326,
283,
5006,
6701,
297,
326,
283,
71,
7,
435,
593,
37,
435,
593,
37,
435,
283,
1939,
11375,
297,
20169,
283,
71,
7,
435,
593,
37,
435,
312,
69,
435,
283,
1939,
11375,
297,
20169,
399,
7,
1421,
60,
85,
16569,
297,
326,
1804,
2751,
43,
879,
33,
63,
44,
1573,
63,
33,
627,
3388,
12,
326,
1622,
267,
367,
399,
24,
495,
315,
5560,
26,
288,
734,
12,
2329,
275,
291,
14,
1065,
1760,
480,
84,
63,
5335,
63,
23880,
18,
18321,
83,
18781,
450,
399,
24,
495,
14,
2143,
360,
1624,
13,
24,
1333,
288,
291,
14,
479,
63,
1452,
8,
548,
12,
298,
16,
60,
78,
531,
16872,
199,
533,
8303,
1538,
31207,
8,
957,
1399,
335,
8387,
14,
1746,
304,
272,
408,
1558,
20448,
315,
3486,
10485,
624,
5591,
347,
1255,
63,
495,
5730,
8,
277,
12,
282,
12,
330,
12,
4282,
304,
267,
734,
12,
2329,
275,
291,
14,
1065,
1760,
360,
84,
63,
495,
5730,
18321,
83,
4451,
18321,
83,
4451,
7,
450,
334,
65,
14,
2143,
360,
1624,
13,
24,
659,
330,
14,
2143,
360,
1624,
13,
24,
7058,
267,
340,
2070,
453,
8,
442,
8,
548,
430,
1137,
4282,
26,
288,
291,
14,
1633,
480,
8547,
3405,
3427,
78,
2,
1993,
298,
221,
282,
2458,
83,
60,
78,
2,
1993,
298,
221,
330,
2458,
83,
60,
78,
2,
1993,
298,
221,
1420,
2458,
83,
60,
78,
2,
1993,
298,
221,
754,
2458,
83,
60,
78,
2,
450,
13493,
65,
3559,
658,
66,
3559,
658,
4921,
3559,
658,
548,
64,
430,
339,
347,
1255,
396,
8,
277,
304,
267,
327,
437,
12,
699,
12,
620,
2546,
5730,
8,
33,
12,
699,
9,
267,
5560,
275,
4274,
5006,
297,
283,
5006,
297,
378,
395,
326,
661,
5006,
297,
283,
8302,
16481,
297,
435,
17,
395,
326,
661,
8302,
16481,
297,
283,
5006,
297,
446,
17,
395,
326,
661,
72,
1697,
297,
283,
5006,
297,
446,
17,
395,
326,
13134,
3260,
378,
395,
326,
661,
65,
297,
3260,
435,
17,
395,
326,
13134,
283,
65,
297,
446,
17,
395,
326,
661,
65,
297,
283,
33,
297,
378,
395,
326,
661,
2158,
297,
283,
65,
33,
297,
378,
395,
326,
661,
33,
65,
297,
283,
2158,
297,
378,
395,
326,
661,
2809,
875,
283,
627,
2948,
12,
283,
2809,
875,
283,
627,
2948,
12,
378,
395,
326,
661,
2809,
875,
283,
627,
2948,
12,
283,
2809,
875,
283,
627,
2948,
435,
283,
65,
297,
446,
17,
395,
326,
661,
2809,
875,
283,
627,
2948,
435,
283,
65,
297,
283,
2809,
875,
283,
627,
2948,
12,
435,
17,
395,
326,
334,
43,
2751,
43,
879,
33,
63,
44,
1573,
63,
33,
12,
1804,
2751,
43,
879,
33,
63,
44,
1573,
63,
33,
12,
378,
395,
326,
334,
43,
2751,
43,
879,
33,
63,
44,
1573,
63,
33,
12,
283,
65,
297,
413,
395,
326,
1622,
267,
367,
282,
12,
330,
12,
4282,
315,
5560,
26,
288,
291,
14,
1065,
63,
495,
5730,
8,
65,
12,
330,
12,
4282,
9,
268,
199,
533,
620,
495,
63,
77,
8,
957,
1399,
335,
8387,
14,
1746,
304,
272,
408,
1558,
20448,
315,
3486,
10485,
624,
5591,
347,
1255,
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,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
hanlind/nova
|
nova/tests/unit/virt/fakelibosinfo.py
|
21
|
2989
|
# Copyright 2016 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
def match_item(obj, fltr):
key, val = list(fltr._filter.items())[0]
if key == 'class':
key = '_class'
elif key == 'short-id':
key = 'short_id'
return getattr(obj, key, None) == val
class Loader(object):
def process_default_path(self):
pass
def get_db(self):
return Db()
class Db(object):
def __init__(self):
# Generate test devices
self.devs = []
self.oslist = None
net = Device()
net._class = 'net'
net.name = 'virtio-net'
self.devs.append(net)
net = Device()
net._class = 'block'
net.name = 'virtio-block'
self.devs.append(net)
devlist = DeviceList()
devlist.devices = self.devs
fedora = Os()
fedora.name = 'Fedora 22'
fedora.id = 'http://fedoraproject.org/fedora/22'
fedora.short_id = 'fedora22'
fedora.dev_list = devlist
self.oslist = OsList()
self.oslist.os_list = [fedora]
def get_os_list(self):
return self.oslist
class Filter(object):
def __init__(self):
self._filter = {}
@classmethod
def new(cls):
return cls()
def add_constraint(self, flt_key, val):
self._filter[flt_key] = val
class OsList(object):
def __init__(self):
self.os_list = []
def new_filtered(self, fltr):
new_list = OsList()
new_list.os_list = [os for os in self.os_list if match_item(os, fltr)]
return new_list
def get_length(self):
return len(self.os_list)
def get_nth(self, index):
return self.os_list[index]
class Os(object):
def __init__(self):
self.name = None
self.short_id = None
self.id = None
self.dev_list = None
def get_all_devices(self, fltr):
new_list = DeviceList()
new_list.devices = [dev for dev in self.dev_list.devices
if match_item(dev, fltr)]
return new_list
def get_name(self):
return self.name
class DeviceList(object):
def __init__(self):
self.devices = []
def get_length(self):
return len(self.devices)
def get_nth(self, index):
return self.devices[index]
class Device(object):
def __init__(self):
self.name = None
self._class = None
def get_name(self):
return self.name
|
apache-2.0
|
[
3,
1898,
7800,
9572,
13002,
12,
3277,
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,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
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,
421,
199,
318,
1336,
63,
1053,
8,
1113,
12,
2717,
454,
304,
272,
790,
12,
1139,
275,
769,
8,
2327,
454,
423,
1541,
14,
1744,
18756,
16,
61,
272,
340,
790,
508,
283,
533,
356,
267,
790,
275,
2513,
533,
7,
272,
916,
790,
508,
283,
3612,
13,
344,
356,
267,
790,
275,
283,
3612,
63,
344,
7,
272,
372,
2519,
8,
1113,
12,
790,
12,
488,
9,
508,
1139,
421,
199,
533,
22865,
8,
785,
304,
339,
347,
2112,
63,
885,
63,
515,
8,
277,
304,
267,
986,
339,
347,
664,
63,
697,
8,
277,
304,
267,
372,
28822,
342,
421,
199,
533,
28822,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
327,
7958,
511,
7256,
267,
291,
14,
18804,
275,
942,
267,
291,
14,
736,
513,
275,
488,
398,
1851,
275,
12272,
342,
267,
1851,
423,
533,
275,
283,
846,
7,
267,
1851,
14,
354,
275,
283,
1042,
4538,
13,
846,
7,
267,
291,
14,
18804,
14,
740,
8,
846,
9,
398,
1851,
275,
12272,
342,
267,
1851,
423,
533,
275,
283,
1457,
7,
267,
1851,
14,
354,
275,
283,
1042,
4538,
13,
1457,
7,
267,
291,
14,
18804,
14,
740,
8,
846,
9,
398,
4866,
513,
275,
12272,
1296,
342,
267,
4866,
513,
14,
6410,
275,
291,
14,
18804,
398,
23036,
11131,
275,
593,
83,
342,
267,
23036,
11131,
14,
354,
275,
283,
38,
379,
11131,
6928,
7,
267,
23036,
11131,
14,
344,
275,
283,
1014,
921,
15800,
269,
30204,
963,
14,
1308,
15,
28803,
15,
1081,
7,
267,
23036,
11131,
14,
3612,
63,
344,
275,
283,
28803,
1081,
7,
267,
23036,
11131,
14,
2374,
63,
513,
275,
4866,
513,
398,
291,
14,
736,
513,
275,
593,
83,
1296,
342,
267,
291,
14,
736,
513,
14,
736,
63,
513,
275,
359,
28803,
61,
339,
347,
664,
63,
736,
63,
513,
8,
277,
304,
267,
372,
291,
14,
736,
513,
421,
199,
533,
9388,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
1541,
275,
1052,
339,
768,
3744,
272,
347,
892,
8,
1886,
304,
267,
372,
843,
342,
339,
347,
1050,
63,
5631,
8,
277,
12,
17166,
63,
498,
12,
1139,
304,
267,
291,
423,
1541,
59,
26057,
63,
498,
61,
275,
1139,
421,
199,
533,
593,
83,
1296,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
736,
63,
513,
275,
942,
339,
347,
892,
63,
11142,
8,
277,
12,
2717,
454,
304,
267,
892,
63,
513,
275,
593,
83,
1296,
342,
267,
892,
63,
513,
14,
736,
63,
513,
275,
359,
736,
367,
747,
315,
291,
14,
736,
63,
513,
340,
1336,
63,
1053,
8,
736,
12,
2717,
454,
1874,
267,
372,
892,
63,
513,
339,
347,
664,
63,
1267,
8,
277,
304,
267,
372,
822,
8,
277,
14,
736,
63,
513,
9,
339,
347,
664,
63,
16621,
8,
277,
12,
1478,
304,
267,
372,
291,
14,
736,
63,
513,
59,
1080,
61,
421,
199,
533,
593,
83,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
354,
275,
488,
267,
291,
14,
3612,
63,
344,
275,
488,
267,
291,
14,
344,
275,
488,
267,
291,
14,
2374,
63,
513,
275,
488,
339,
347,
664,
63,
452,
63,
6410,
8,
277,
12,
2717,
454,
304,
267,
892,
63,
513,
275,
12272,
1296,
342,
267,
892,
63,
513,
14,
6410,
275,
359,
2374,
367,
4866,
315,
291,
14,
2374,
63,
513,
14,
6410,
1169,
340,
1336,
63,
1053,
8,
2374,
12,
2717,
454,
1874,
267,
372,
892,
63,
513,
339,
347,
664,
63,
354,
8,
277,
304,
267,
372,
291,
14,
354,
421,
199,
533,
12272,
1296,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
6410,
275,
942,
339,
347,
664,
63,
1267,
8,
277,
304,
267,
372,
822,
8,
277,
14,
6410,
9,
339,
347,
664,
63,
16621,
8,
277,
12,
1478,
304,
267,
372,
291,
14,
6410,
59,
1080,
61,
421,
199,
533,
12272,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
354,
275,
488,
267,
291,
423,
533,
275,
488,
339,
347,
664,
63,
354,
8,
277,
304,
267,
372,
291,
14,
354,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
7800,
9572,
13002,
12,
3277,
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,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
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,
421,
199,
318,
1336,
63,
1053,
8,
1113,
12,
2717,
454,
304,
272,
790,
12,
1139,
275,
769,
8,
2327,
454,
423,
1541,
14,
1744,
18756,
16,
61,
272,
340,
790,
508,
283,
533,
356,
267,
790,
275,
2513,
533,
7,
272,
916,
790,
508,
283,
3612,
13,
344,
356,
267,
790,
275,
283,
3612,
63,
344,
7,
272,
372,
2519,
8,
1113,
12,
790,
12,
488,
9,
508,
1139,
421,
199,
533,
22865,
8,
785,
304,
339,
347,
2112,
63,
885,
63,
515,
8,
277,
304,
267,
986,
339,
347,
664,
63,
697,
8,
277,
304,
267,
372,
28822,
342,
421,
199,
533,
28822,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
327,
7958,
511,
7256,
267,
291,
14,
18804,
275,
942,
267,
291,
14,
736,
513,
275,
488,
398,
1851,
275,
12272,
342,
267,
1851,
423,
533,
275,
283,
846,
7,
267,
1851,
14,
354,
275,
283,
1042,
4538,
13,
846,
7,
267,
291,
14,
18804,
14,
740,
8,
846,
9,
398,
1851,
275,
12272,
342,
267,
1851,
423,
533,
275,
283,
1457,
7,
267,
1851,
14,
354,
275,
283,
1042,
4538,
13,
1457,
7,
267,
291,
14,
18804,
14,
740,
8,
846,
9,
398,
4866,
513,
275,
12272,
1296,
342,
267,
4866,
513,
14,
6410,
275,
291,
14,
18804,
398,
23036,
11131,
275,
593,
83,
342,
267,
23036,
11131,
14,
354,
275,
283,
38,
379,
11131,
6928,
7,
267,
23036,
11131,
14,
344,
275,
283,
1014,
921,
15800,
269,
30204,
963,
14,
1308,
15,
28803,
15,
1081,
7,
267,
23036,
11131,
14,
3612,
63,
344,
275,
283,
28803,
1081,
7,
267,
23036,
11131,
14,
2374,
63,
513,
275,
4866,
513,
398,
291,
14,
736,
513,
275,
593,
83,
1296,
342,
267,
291,
14,
736,
513,
14,
736,
63,
513,
275,
359,
28803,
61,
339,
347,
664,
63,
736,
63,
513,
8,
277,
304,
267,
372,
291,
14,
736,
513,
421,
199,
533,
9388,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
1541,
275,
1052,
339,
768,
3744,
272,
347,
892,
8,
1886,
304,
267,
372,
843,
342,
339,
347,
1050,
63,
5631,
8,
277,
12,
17166,
63,
498,
12,
1139,
304,
267,
291,
423,
1541,
59,
26057,
63,
498,
61,
275,
1139,
421,
199,
533,
593,
83,
1296,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
736,
63,
513,
275,
942,
339,
347,
892,
63,
11142,
8,
277,
12,
2717,
454,
304,
267,
892,
63,
513,
275,
593,
83,
1296,
342,
267,
892,
63,
513,
14,
736,
63,
513,
275,
359,
736,
367,
747,
315,
291,
14,
736,
63,
513,
340,
1336,
63,
1053,
8,
736,
12,
2717,
454,
1874,
267,
372,
892,
63,
513,
339,
347,
664,
63,
1267,
8,
277,
304,
267,
372,
822,
8,
277,
14,
736,
63,
513,
9,
339,
347,
664,
63,
16621,
8,
277,
12,
1478,
304,
267,
372,
291,
14,
736,
63,
513,
59,
1080,
61,
421,
199,
533,
593,
83,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
354,
275,
488,
267,
291,
14,
3612,
63,
344,
275,
488,
267,
291,
14,
344,
275,
488,
267,
291,
14,
2374,
63,
513,
275,
488,
339,
347,
664,
63,
452,
63,
6410,
8,
277,
12,
2717,
454,
304,
267,
892,
63,
513,
275,
12272,
1296,
342,
267,
892,
63,
513,
14,
6410,
275,
359,
2374,
367,
4866,
315,
291,
14,
2374,
63,
513,
14,
6410,
1169,
340,
1336,
63,
1053,
8,
2374,
12,
2717,
454,
1874,
267,
372,
892,
63,
513,
339,
347,
664,
63,
354,
8,
277,
304,
267,
372,
291,
14,
354,
421,
199,
533,
12272,
1296,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
6410,
275,
942,
339,
347,
664,
63,
1267,
8,
277,
304,
267,
372,
822,
8,
277,
14,
6410,
9,
339,
347,
664,
63,
16621,
8,
277,
12,
1478,
304,
267,
372,
291,
14,
6410,
59,
1080,
61,
421,
199,
533,
12272,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
354,
275,
488,
267,
291,
423,
533,
275,
488,
339,
347,
664,
63,
354,
8,
277,
304,
267,
372,
291,
14,
354,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hortonworks/hortonworks-sandbox
|
desktop/core/ext-py/eventlet-0.9.14/tests/timer_test.py
|
8
|
1261
|
from unittest import TestCase, main
import eventlet
from eventlet import hubs
from eventlet.hubs import timer
class TestTimer(TestCase):
def test_copy(self):
t = timer.Timer(0, lambda: None)
t2 = t.copy()
assert t.seconds == t2.seconds
assert t.tpl == t2.tpl
assert t.called == t2.called
def test_schedule(self):
hub = hubs.get_hub()
# clean up the runloop, preventing side effects from previous tests
# on this thread
if hub.running:
hub.abort()
eventlet.sleep(0)
called = []
#t = timer.Timer(0, lambda: (called.append(True), hub.abort()))
#t.schedule()
# let's have a timer somewhere in the future; make sure abort() still works
# (for pyevent, its dispatcher() does not exit if there is something scheduled)
# XXX pyevent handles this, other hubs do not
#hubs.get_hub().schedule_call_global(10000, lambda: (called.append(True), hub.abort()))
hubs.get_hub().schedule_call_global(0, lambda: (called.append(True), hub.abort()))
hub.default_sleep = lambda: 0.0
hub.switch()
assert called
assert not hub.running
if __name__ == '__main__':
main()
|
apache-2.0
|
[
504,
2882,
492,
7640,
12,
2446,
199,
199,
646,
21819,
199,
504,
21819,
492,
26726,
83,
199,
504,
21819,
14,
16560,
83,
492,
9715,
199,
199,
533,
1379,
7929,
8,
1746,
304,
272,
347,
511,
63,
1574,
8,
277,
304,
267,
307,
275,
9715,
14,
7929,
8,
16,
12,
2400,
26,
488,
9,
267,
307,
18,
275,
307,
14,
1574,
342,
267,
702,
307,
14,
4515,
508,
307,
18,
14,
4515,
267,
702,
307,
14,
15436,
508,
307,
18,
14,
15436,
267,
702,
307,
14,
3527,
508,
307,
18,
14,
3527,
339,
347,
511,
63,
7211,
8,
277,
304,
267,
26726,
275,
26726,
83,
14,
362,
63,
16560,
342,
267,
327,
3633,
1536,
314,
1255,
3813,
12,
7981,
316,
5366,
22414,
687,
4136,
2295,
267,
327,
641,
642,
2462,
267,
340,
26726,
14,
5720,
26,
288,
26726,
14,
13845,
342,
288,
21819,
14,
4532,
8,
16,
9,
267,
2797,
275,
942,
267,
327,
84,
275,
9715,
14,
7929,
8,
16,
12,
2400,
26,
334,
3527,
14,
740,
8,
549,
395,
26726,
14,
13845,
4059,
267,
327,
84,
14,
7211,
342,
267,
327,
4691,
1159,
1172,
282,
9715,
23430,
315,
314,
6466,
27,
1852,
3238,
12004,
342,
5139,
5419,
267,
327,
334,
509,
1134,
1430,
12,
2399,
17475,
342,
1630,
440,
4458,
340,
2337,
365,
6020,
18416,
9,
267,
327,
5787,
1134,
1430,
10022,
642,
12,
1163,
26726,
83,
886,
440,
267,
327,
16560,
83,
14,
362,
63,
16560,
1252,
7211,
63,
1250,
63,
2966,
8,
9943,
12,
2400,
26,
334,
3527,
14,
740,
8,
549,
395,
26726,
14,
13845,
4059,
267,
26726,
83,
14,
362,
63,
16560,
1252,
7211,
63,
1250,
63,
2966,
8,
16,
12,
2400,
26,
334,
3527,
14,
740,
8,
549,
395,
26726,
14,
13845,
4059,
267,
26726,
14,
885,
63,
4532,
275,
2400,
26,
378,
14,
16,
267,
26726,
14,
5656,
342,
267,
702,
2797,
267,
702,
440,
26726,
14,
5720,
27844,
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
] |
[
2882,
492,
7640,
12,
2446,
199,
199,
646,
21819,
199,
504,
21819,
492,
26726,
83,
199,
504,
21819,
14,
16560,
83,
492,
9715,
199,
199,
533,
1379,
7929,
8,
1746,
304,
272,
347,
511,
63,
1574,
8,
277,
304,
267,
307,
275,
9715,
14,
7929,
8,
16,
12,
2400,
26,
488,
9,
267,
307,
18,
275,
307,
14,
1574,
342,
267,
702,
307,
14,
4515,
508,
307,
18,
14,
4515,
267,
702,
307,
14,
15436,
508,
307,
18,
14,
15436,
267,
702,
307,
14,
3527,
508,
307,
18,
14,
3527,
339,
347,
511,
63,
7211,
8,
277,
304,
267,
26726,
275,
26726,
83,
14,
362,
63,
16560,
342,
267,
327,
3633,
1536,
314,
1255,
3813,
12,
7981,
316,
5366,
22414,
687,
4136,
2295,
267,
327,
641,
642,
2462,
267,
340,
26726,
14,
5720,
26,
288,
26726,
14,
13845,
342,
288,
21819,
14,
4532,
8,
16,
9,
267,
2797,
275,
942,
267,
327,
84,
275,
9715,
14,
7929,
8,
16,
12,
2400,
26,
334,
3527,
14,
740,
8,
549,
395,
26726,
14,
13845,
4059,
267,
327,
84,
14,
7211,
342,
267,
327,
4691,
1159,
1172,
282,
9715,
23430,
315,
314,
6466,
27,
1852,
3238,
12004,
342,
5139,
5419,
267,
327,
334,
509,
1134,
1430,
12,
2399,
17475,
342,
1630,
440,
4458,
340,
2337,
365,
6020,
18416,
9,
267,
327,
5787,
1134,
1430,
10022,
642,
12,
1163,
26726,
83,
886,
440,
267,
327,
16560,
83,
14,
362,
63,
16560,
1252,
7211,
63,
1250,
63,
2966,
8,
9943,
12,
2400,
26,
334,
3527,
14,
740,
8,
549,
395,
26726,
14,
13845,
4059,
267,
26726,
83,
14,
362,
63,
16560,
1252,
7211,
63,
1250,
63,
2966,
8,
16,
12,
2400,
26,
334,
3527,
14,
740,
8,
549,
395,
26726,
14,
13845,
4059,
267,
26726,
14,
885,
63,
4532,
275,
2400,
26,
378,
14,
16,
267,
26726,
14,
5656,
342,
267,
702,
2797,
267,
702,
440,
26726,
14,
5720,
27844,
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,
1,
1,
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
] |
danielpalomino/gem5
|
tests/configs/memtest-ruby.py
|
8
|
4121
|
# Copyright (c) 2006-2007 The Regents of The University of Michigan
# Copyright (c) 2010 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: Ron Dreslinski
import m5
from m5.objects import *
from m5.defines import buildEnv
from m5.util import addToPath
import os, optparse, sys
# Get paths we might need
config_path = os.path.dirname(os.path.abspath(__file__))
config_root = os.path.dirname(config_path)
m5_root = os.path.dirname(config_root)
addToPath(config_root+'/configs/common')
addToPath(config_root+'/configs/ruby')
addToPath(config_root+'/configs/topologies')
import Ruby
import Options
parser = optparse.OptionParser()
Options.addCommonOptions(parser)
# Add the ruby specific and protocol specific options
Ruby.define_options(parser)
(options, args) = parser.parse_args()
#
# Set the default cache size and associativity to be very small to encourage
# races between requests and writebacks.
#
options.l1d_size="256B"
options.l1i_size="256B"
options.l2_size="512B"
options.l3_size="1kB"
options.l1d_assoc=2
options.l1i_assoc=2
options.l2_assoc=2
options.l3_assoc=2
#MAX CORES IS 8 with the fals sharing method
nb_cores = 8
# ruby does not support atomic, functional, or uncacheable accesses
cpus = [ MemTest(atomic=False, percent_functional=50,
percent_uncacheable=0, suppress_func_warnings=True) \
for i in xrange(nb_cores) ]
# overwrite options.num_cpus with the nb_cores value
options.num_cpus = nb_cores
# system simulated
system = System(cpu = cpus,
funcmem = SimpleMemory(in_addr_map = False),
funcbus = NoncoherentBus(),
physmem = SimpleMemory())
Ruby.create_system(options, system)
assert(len(cpus) == len(system.ruby._cpu_ruby_ports))
for (i, ruby_port) in enumerate(system.ruby._cpu_ruby_ports):
#
# Tie the cpu test and functional ports to the ruby cpu ports and
# physmem, respectively
#
cpus[i].test = ruby_port.slave
cpus[i].functional = system.funcbus.slave
#
# Since the memtester is incredibly bursty, increase the deadlock
# threshold to 1 million cycles
#
ruby_port.deadlock_threshold = 1000000
#
# Ruby doesn't need the backing image of memory when running with
# the tester.
#
ruby_port.access_phys_mem = False
# connect reference memory to funcbus
system.funcmem.port = system.funcbus.master
# -----------------------
# run simulation
# -----------------------
root = Root(full_system = False, system = system)
root.system.mem_mode = 'timing'
# Not much point in this being higher than the L1 latency
m5.ticks.setGlobalFrequency('1ns')
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
8315,
13,
9488,
710,
5044,
24871,
402,
710,
15904,
402,
603,
1158,
528,
290,
199,
3,
1898,
334,
67,
9,
7129,
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,
32472,
577,
470,
472,
10728,
199,
199,
646,
333,
21,
199,
504,
333,
21,
14,
1462,
492,
627,
199,
504,
333,
21,
14,
14334,
492,
1900,
7744,
199,
504,
333,
21,
14,
1974,
492,
1050,
1378,
2042,
199,
646,
747,
12,
8691,
12,
984,
199,
199,
3,
2372,
3792,
781,
5594,
1929,
199,
888,
63,
515,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
888,
63,
1231,
275,
747,
14,
515,
14,
3475,
8,
888,
63,
515,
9,
199,
77,
21,
63,
1231,
275,
747,
14,
515,
14,
3475,
8,
888,
63,
1231,
9,
199,
525,
1378,
2042,
8,
888,
63,
1231,
23164,
7532,
15,
2330,
358,
199,
525,
1378,
2042,
8,
888,
63,
1231,
23164,
7532,
15,
21952,
358,
199,
525,
1378,
2042,
8,
888,
63,
1231,
23164,
7532,
15,
16851,
15241,
358,
199,
199,
646,
820,
10972,
199,
646,
8394,
199,
199,
2087,
275,
8691,
14,
14553,
342,
199,
4558,
14,
525,
7844,
4558,
8,
2087,
9,
199,
199,
3,
2654,
314,
31855,
2488,
436,
4113,
2488,
1511,
199,
50,
10972,
14,
4640,
63,
1419,
8,
2087,
9,
199,
199,
8,
1419,
12,
1249,
9,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
3,
199,
3,
2494,
314,
849,
2581,
1568,
436,
4035,
2159,
18936,
370,
506,
7437,
7425,
370,
655,
25715,
474,
199,
3,
660,
823,
3382,
4145,
436,
2218,
894,
83,
14,
199,
3,
199,
1419,
14,
76,
17,
68,
63,
890,
628,
3912,
34,
2,
199,
1419,
14,
76,
17,
73,
63,
890,
628,
3912,
34,
2,
199,
1419,
14,
76,
18,
63,
890,
628,
7736,
34,
2,
199,
1419,
14,
76,
19,
63,
890,
628,
17,
75,
34,
2,
199,
1419,
14,
76,
17,
68,
63,
16824,
29,
18,
199,
1419,
14,
76,
17,
73,
63,
16824,
29,
18,
199,
1419,
14,
76,
18,
63,
16824,
29,
18,
199,
1419,
14,
76,
19,
63,
16824,
29,
18,
199,
199,
3,
4283,
18886,
654,
2281,
1695,
543,
314,
289,
2551,
26994,
1083,
199,
4994,
63,
4630,
275,
1695,
199,
199,
3,
31855,
1630,
440,
2291,
15374,
12,
22380,
12,
503,
625,
1637,
461,
1066,
5804,
199,
8896,
275,
359,
30465,
774,
8,
10910,
29,
797,
12,
8878,
63,
15481,
29,
1400,
12,
326,
8878,
63,
324,
1637,
461,
29,
16,
12,
15678,
63,
1532,
63,
5451,
29,
549,
9,
971,
268,
367,
284,
315,
4945,
8,
4994,
63,
4630,
9,
1622,
199,
199,
3,
8970,
1511,
14,
1507,
63,
8896,
543,
314,
8526,
63,
4630,
574,
199,
1419,
14,
1507,
63,
8896,
275,
8526,
63,
4630,
523,
199,
3,
2656,
4389,
8097,
199,
2253,
275,
6187,
8,
3541,
275,
24174,
12,
355,
2562,
5286,
275,
5870,
8628,
8,
262,
63,
2697,
63,
1130,
275,
756,
395,
355,
2562,
5610,
275,
10172,
331,
426,
640,
12106,
1062,
355,
3945,
588,
5286,
275,
5870,
8628,
1012,
199,
199,
50,
10972,
14,
981,
63,
2253,
8,
1419,
12,
2656,
9,
199,
199,
479,
8,
552,
8,
8896,
9,
508,
822,
8,
2253,
14,
21952,
423,
3541,
63,
21952,
63,
5203,
430,
199,
199,
509,
334,
73,
12,
31855,
63,
719,
9,
315,
3874,
8,
2253,
14,
21952,
423,
3541,
63,
21952,
63,
5203,
304,
1362,
327,
1362,
327,
377,
1873,
314,
5033,
511,
436,
22380,
8873,
370,
314,
31855,
5033,
8873,
436,
1362,
327,
3945,
588,
5286,
12,
17342,
1362,
327,
1362,
24174,
59,
73,
1055,
396,
275,
31855,
63,
719,
14,
12384,
1362,
24174,
59,
73,
1055,
15481,
275,
2656,
14,
1532,
5610,
14,
12384,
489,
1362,
327,
1362,
327,
9336,
314,
7573,
8234,
365,
10035,
328,
66,
590,
330,
13305,
89,
12,
19781,
314,
12314,
831,
1362,
327,
8765,
370,
413,
15949,
265,
19001,
1362,
327,
1362,
31855,
63,
719,
14,
10957,
831,
63,
7227,
275,
19492,
10813,
327,
1362,
327,
820,
10972,
3181,
1133,
1929,
314,
21094,
1834,
402,
4402,
1380,
3879,
543,
1362,
327,
314,
17570,
14,
1362,
327,
1362,
31855,
63,
719,
14,
2732,
63,
26827,
63,
5286,
275,
756,
199,
199,
3,
4907,
3659,
4402,
370,
2562,
5610,
199,
2253,
14,
1532,
5286,
14,
719,
275,
2656
] |
[
1898,
334,
67,
9,
8315,
13,
9488,
710,
5044,
24871,
402,
710,
15904,
402,
603,
1158,
528,
290,
199,
3,
1898,
334,
67,
9,
7129,
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,
32472,
577,
470,
472,
10728,
199,
199,
646,
333,
21,
199,
504,
333,
21,
14,
1462,
492,
627,
199,
504,
333,
21,
14,
14334,
492,
1900,
7744,
199,
504,
333,
21,
14,
1974,
492,
1050,
1378,
2042,
199,
646,
747,
12,
8691,
12,
984,
199,
199,
3,
2372,
3792,
781,
5594,
1929,
199,
888,
63,
515,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
888,
63,
1231,
275,
747,
14,
515,
14,
3475,
8,
888,
63,
515,
9,
199,
77,
21,
63,
1231,
275,
747,
14,
515,
14,
3475,
8,
888,
63,
1231,
9,
199,
525,
1378,
2042,
8,
888,
63,
1231,
23164,
7532,
15,
2330,
358,
199,
525,
1378,
2042,
8,
888,
63,
1231,
23164,
7532,
15,
21952,
358,
199,
525,
1378,
2042,
8,
888,
63,
1231,
23164,
7532,
15,
16851,
15241,
358,
199,
199,
646,
820,
10972,
199,
646,
8394,
199,
199,
2087,
275,
8691,
14,
14553,
342,
199,
4558,
14,
525,
7844,
4558,
8,
2087,
9,
199,
199,
3,
2654,
314,
31855,
2488,
436,
4113,
2488,
1511,
199,
50,
10972,
14,
4640,
63,
1419,
8,
2087,
9,
199,
199,
8,
1419,
12,
1249,
9,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
3,
199,
3,
2494,
314,
849,
2581,
1568,
436,
4035,
2159,
18936,
370,
506,
7437,
7425,
370,
655,
25715,
474,
199,
3,
660,
823,
3382,
4145,
436,
2218,
894,
83,
14,
199,
3,
199,
1419,
14,
76,
17,
68,
63,
890,
628,
3912,
34,
2,
199,
1419,
14,
76,
17,
73,
63,
890,
628,
3912,
34,
2,
199,
1419,
14,
76,
18,
63,
890,
628,
7736,
34,
2,
199,
1419,
14,
76,
19,
63,
890,
628,
17,
75,
34,
2,
199,
1419,
14,
76,
17,
68,
63,
16824,
29,
18,
199,
1419,
14,
76,
17,
73,
63,
16824,
29,
18,
199,
1419,
14,
76,
18,
63,
16824,
29,
18,
199,
1419,
14,
76,
19,
63,
16824,
29,
18,
199,
199,
3,
4283,
18886,
654,
2281,
1695,
543,
314,
289,
2551,
26994,
1083,
199,
4994,
63,
4630,
275,
1695,
199,
199,
3,
31855,
1630,
440,
2291,
15374,
12,
22380,
12,
503,
625,
1637,
461,
1066,
5804,
199,
8896,
275,
359,
30465,
774,
8,
10910,
29,
797,
12,
8878,
63,
15481,
29,
1400,
12,
326,
8878,
63,
324,
1637,
461,
29,
16,
12,
15678,
63,
1532,
63,
5451,
29,
549,
9,
971,
268,
367,
284,
315,
4945,
8,
4994,
63,
4630,
9,
1622,
199,
199,
3,
8970,
1511,
14,
1507,
63,
8896,
543,
314,
8526,
63,
4630,
574,
199,
1419,
14,
1507,
63,
8896,
275,
8526,
63,
4630,
523,
199,
3,
2656,
4389,
8097,
199,
2253,
275,
6187,
8,
3541,
275,
24174,
12,
355,
2562,
5286,
275,
5870,
8628,
8,
262,
63,
2697,
63,
1130,
275,
756,
395,
355,
2562,
5610,
275,
10172,
331,
426,
640,
12106,
1062,
355,
3945,
588,
5286,
275,
5870,
8628,
1012,
199,
199,
50,
10972,
14,
981,
63,
2253,
8,
1419,
12,
2656,
9,
199,
199,
479,
8,
552,
8,
8896,
9,
508,
822,
8,
2253,
14,
21952,
423,
3541,
63,
21952,
63,
5203,
430,
199,
199,
509,
334,
73,
12,
31855,
63,
719,
9,
315,
3874,
8,
2253,
14,
21952,
423,
3541,
63,
21952,
63,
5203,
304,
1362,
327,
1362,
327,
377,
1873,
314,
5033,
511,
436,
22380,
8873,
370,
314,
31855,
5033,
8873,
436,
1362,
327,
3945,
588,
5286,
12,
17342,
1362,
327,
1362,
24174,
59,
73,
1055,
396,
275,
31855,
63,
719,
14,
12384,
1362,
24174,
59,
73,
1055,
15481,
275,
2656,
14,
1532,
5610,
14,
12384,
489,
1362,
327,
1362,
327,
9336,
314,
7573,
8234,
365,
10035,
328,
66,
590,
330,
13305,
89,
12,
19781,
314,
12314,
831,
1362,
327,
8765,
370,
413,
15949,
265,
19001,
1362,
327,
1362,
31855,
63,
719,
14,
10957,
831,
63,
7227,
275,
19492,
10813,
327,
1362,
327,
820,
10972,
3181,
1133,
1929,
314,
21094,
1834,
402,
4402,
1380,
3879,
543,
1362,
327,
314,
17570,
14,
1362,
327,
1362,
31855,
63,
719,
14,
2732,
63,
26827,
63,
5286,
275,
756,
199,
199,
3,
4907,
3659,
4402,
370,
2562,
5610,
199,
2253,
14,
1532,
5286,
14,
719,
275,
2656,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dhruve/spark
|
examples/src/main/python/mllib/ranking_metrics_example.py
|
100
|
2197
|
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# $example on$
from pyspark.mllib.recommendation import ALS, Rating
from pyspark.mllib.evaluation import RegressionMetrics, RankingMetrics
# $example off$
from pyspark import SparkContext
if __name__ == "__main__":
sc = SparkContext(appName="Ranking Metrics Example")
# Several of the methods available in scala are currently missing from pyspark
# $example on$
# Read in the ratings data
lines = sc.textFile("data/mllib/sample_movielens_data.txt")
def parseLine(line):
fields = line.split("::")
return Rating(int(fields[0]), int(fields[1]), float(fields[2]) - 2.5)
ratings = lines.map(lambda r: parseLine(r))
# Train a model on to predict user-product ratings
model = ALS.train(ratings, 10, 10, 0.01)
# Get predicted ratings on all existing user-product pairs
testData = ratings.map(lambda p: (p.user, p.product))
predictions = model.predictAll(testData).map(lambda r: ((r.user, r.product), r.rating))
ratingsTuple = ratings.map(lambda r: ((r.user, r.product), r.rating))
scoreAndLabels = predictions.join(ratingsTuple).map(lambda tup: tup[1])
# Instantiate regression metrics to compare predicted and actual ratings
metrics = RegressionMetrics(scoreAndLabels)
# Root mean squared error
print("RMSE = %s" % metrics.rootMeanSquaredError)
# R-squared
print("R-squared = %s" % metrics.r2)
# $example off$
|
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,
3,
2672,
2694,
641,
4,
199,
504,
15847,
14,
25598,
14,
264,
22105,
492,
437,
5296,
12,
820,
1958,
199,
504,
15847,
14,
25598,
14,
19154,
492,
13262,
17213,
12,
31536,
316,
17213,
199,
3,
2672,
2694,
2331,
4,
199,
504,
15847,
492,
21769,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
4061,
275,
21769,
8,
571,
985,
628,
19486,
316,
10072,
11818,
5679,
531,
339,
327,
3240,
422,
279,
402,
314,
3102,
2808,
315,
5269,
65,
787,
5544,
4124,
687,
15847,
272,
327,
2672,
2694,
641,
4,
272,
327,
5574,
315,
314,
32026,
780,
666,
272,
2385,
275,
4061,
14,
505,
1173,
480,
576,
15,
25598,
15,
3271,
63,
10888,
25057,
63,
576,
14,
2424,
531,
339,
347,
2198,
3049,
8,
604,
304,
267,
1504,
275,
1004,
14,
1294,
480,
447,
531,
267,
372,
820,
1958,
8,
442,
8,
955,
59,
16,
2522,
1109,
8,
955,
59,
17,
2522,
2069,
8,
955,
59,
18,
566,
446,
499,
14,
21,
9,
272,
32026,
780,
275,
2385,
14,
1130,
8,
2734,
519,
26,
2198,
3049,
8,
82,
430,
339,
327,
16732,
282,
1402,
641,
370,
12610,
922,
13,
2558,
32026,
780,
272,
1402,
275,
437,
5296,
14,
2834,
8,
17565,
780,
12,
1616,
12,
1616,
12,
378,
14,
614,
9,
339,
327,
2372,
14746,
32026,
780,
641,
1006,
3411,
922,
13,
2558,
6342,
272,
511,
1451,
275,
32026,
780,
14,
1130,
8,
2734,
299,
26,
334,
80,
14,
751,
12,
299,
14,
2558,
430,
272,
7914,
275,
1402,
14,
6892,
2422,
8,
396,
1451,
680,
1130,
8,
2734,
519,
26,
3666,
82,
14,
751,
12,
519,
14,
2558,
395,
519,
14,
10417,
430,
339,
32026,
780,
7075,
275,
32026,
780,
14,
1130,
8,
2734,
519,
26,
3666,
82,
14,
751,
12,
519,
14,
2558,
395,
519,
14,
10417,
430,
272,
5396,
3325,
14016,
275,
7914,
14,
904,
8,
17565,
780,
7075,
680,
1130,
8,
2734,
16477,
26,
16477,
59,
17,
566,
339,
327,
32092,
10864,
7186,
370,
6540,
14746,
436,
3503,
32026,
780,
272,
7186,
275,
13262,
17213,
8,
3397,
3325,
14016,
9,
339,
327,
12826,
4615,
20478,
1125,
272,
870,
480,
11026,
899,
275,
450,
83,
2,
450,
7186,
14,
1231,
14825,
51,
30458,
547,
9,
339,
327,
820,
13,
12973,
272,
870,
480,
50,
13,
12973,
275,
450,
83,
2,
450,
7186,
14,
82,
18,
9,
272,
327,
2672,
2694,
2331,
4,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
3,
2672,
2694,
641,
4,
199,
504,
15847,
14,
25598,
14,
264,
22105,
492,
437,
5296,
12,
820,
1958,
199,
504,
15847,
14,
25598,
14,
19154,
492,
13262,
17213,
12,
31536,
316,
17213,
199,
3,
2672,
2694,
2331,
4,
199,
504,
15847,
492,
21769,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
4061,
275,
21769,
8,
571,
985,
628,
19486,
316,
10072,
11818,
5679,
531,
339,
327,
3240,
422,
279,
402,
314,
3102,
2808,
315,
5269,
65,
787,
5544,
4124,
687,
15847,
272,
327,
2672,
2694,
641,
4,
272,
327,
5574,
315,
314,
32026,
780,
666,
272,
2385,
275,
4061,
14,
505,
1173,
480,
576,
15,
25598,
15,
3271,
63,
10888,
25057,
63,
576,
14,
2424,
531,
339,
347,
2198,
3049,
8,
604,
304,
267,
1504,
275,
1004,
14,
1294,
480,
447,
531,
267,
372,
820,
1958,
8,
442,
8,
955,
59,
16,
2522,
1109,
8,
955,
59,
17,
2522,
2069,
8,
955,
59,
18,
566,
446,
499,
14,
21,
9,
272,
32026,
780,
275,
2385,
14,
1130,
8,
2734,
519,
26,
2198,
3049,
8,
82,
430,
339,
327,
16732,
282,
1402,
641,
370,
12610,
922,
13,
2558,
32026,
780,
272,
1402,
275,
437,
5296,
14,
2834,
8,
17565,
780,
12,
1616,
12,
1616,
12,
378,
14,
614,
9,
339,
327,
2372,
14746,
32026,
780,
641,
1006,
3411,
922,
13,
2558,
6342,
272,
511,
1451,
275,
32026,
780,
14,
1130,
8,
2734,
299,
26,
334,
80,
14,
751,
12,
299,
14,
2558,
430,
272,
7914,
275,
1402,
14,
6892,
2422,
8,
396,
1451,
680,
1130,
8,
2734,
519,
26,
3666,
82,
14,
751,
12,
519,
14,
2558,
395,
519,
14,
10417,
430,
339,
32026,
780,
7075,
275,
32026,
780,
14,
1130,
8,
2734,
519,
26,
3666,
82,
14,
751,
12,
519,
14,
2558,
395,
519,
14,
10417,
430,
272,
5396,
3325,
14016,
275,
7914,
14,
904,
8,
17565,
780,
7075,
680,
1130,
8,
2734,
16477,
26,
16477,
59,
17,
566,
339,
327,
32092,
10864,
7186,
370,
6540,
14746,
436,
3503,
32026,
780,
272,
7186,
275,
13262,
17213,
8,
3397,
3325,
14016,
9,
339,
327,
12826,
4615,
20478,
1125,
272,
870,
480,
11026,
899,
275,
450,
83,
2,
450,
7186,
14,
1231,
14825,
51,
30458,
547,
9,
339,
327,
820,
13,
12973,
272,
870,
480,
50,
13,
12973,
275,
450,
83,
2,
450,
7186,
14,
82,
18,
9,
272,
327,
2672,
2694,
2331,
4,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
levibostian/myBlanky
|
googleAppEngine/google/appengine/api/capabilities/__init__.py
|
15
|
5930
|
#!/usr/bin/env python
#
# Copyright 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.
#
"""Allows applications to identify API outages and scheduled downtime.
Some examples:
def StoreUploadedProfileImage(self):
uploaded_image = self.request.get('img')
# If the images API is unavailable, we'll just skip the resize.
if CapabilitySet('images').is_enabled():
uploaded_image = images.resize(uploaded_image, 64, 64)
store(uploaded_image)
def RenderHTMLForm(self):
datastore_readonly = CapabilitySet('datastore_v3', capabilities=['write'])
if datastore_readonly.is_enabled():
# ...render form normally...
else:
# self.response.out('<p>Not accepting submissions right now: %s</p>' %
datastore_readonly.admin_message())
# ...render form with form elements disabled...
Individual API wrapper modules should expose CapabilitySet objects
for users rather than relying on users to create them. They may
also create convenience methods (e.g. db.IsReadOnly()) that delegate
to the relevant CapabilitySet.
Classes defined here:
CapabilitySet: encapsulates one or more capabilities, allows introspection.
UnknownCapabilityError: thrown when an unknown capability is requested.
"""
import warnings
from google.appengine.api.capabilities import capability_service_pb
from google.appengine.base import capabilities_pb
from google.appengine.api import apiproxy_stub_map
IsEnabledRequest = capability_service_pb.IsEnabledRequest
IsEnabledResponse = capability_service_pb.IsEnabledResponse
CapabilityConfig = capabilities_pb.CapabilityConfig
class UnknownCapabilityError(Exception):
"""An unknown capability was requested."""
class CapabilitySet(object):
"""Encapsulates one or more capabilities.
Capabilities can either be named explicitly, or inferred from the
list of methods provided. If no capabilities or methods are
provided, this will check whether the entire package is enabled.
"""
def __init__(self, package, capabilities=None, methods=None,
stub_map=apiproxy_stub_map):
"""Constructor.
Args:
capabilities: list of strings
methods: list of strings
"""
if capabilities is None:
capabilities = []
if methods is None:
methods = []
self._package = package
self._capabilities = ['*'] + capabilities
self._methods = methods
self._stub_map = stub_map
def is_enabled(self):
"""Tests whether the capabilities is currently enabled.
Returns:
True if API calls that require these capabillities will succeed.
Raises:
UnknownCapabilityError, if a specified capability was not recognized.
"""
config = self._get_status()
return config.summary_status() in (IsEnabledResponse.ENABLED,
IsEnabledResponse.SCHEDULED_FUTURE,
IsEnabledResponse.SCHEDULED_NOW)
def will_remain_enabled_for(self, time=60):
"""Returns true if it will remain enabled for the specified amount of time.
DEPRECATED: this method was never fully implemented and is
considered deprecated. Use is_enabled() instead.
Args:
time: Number of seconds in the future to look when checking for scheduled
downtime.
Returns:
True if there is no scheduled downtime for the specified capability
within the amount of time specified.
Raises:
UnknownCapabilityError, if a specified capability was not recognized.
"""
warnings.warn('will_remain_enabled_for() is deprecated: '
'use is_enabled instead.',
DeprecationWarning,
stacklevel=2)
config = self._get_status()
status = config.summary_status()
if status == IsEnabledResponse.ENABLED:
return True
elif status == IsEnabledResponse.SCHEDULED_NOW:
return False
elif status == IsEnabledResponse.SCHEDULED_FUTURE:
if config.has_time_until_scheduled():
return config.time_until_scheduled() >= time
else:
return True
elif status == IsEnabledResponse.DISABLED:
return False
else:
return False
def admin_message(self):
"""Get any administrator notice messages for these capabilities.
Returns:
A string containing one or more admin messages, or an empty string.
Raises:
UnknownCapabilityError, if a specified capability was not recognized.
"""
message_list = []
for config in self._get_status().config_list():
message = config.admin_message()
if message and message not in message_list:
message_list.append(message)
return ' '.join(message_list)
def _get_status(self):
"""Get an IsEnabledResponse for the capabilities listed.
Returns:
IsEnabledResponse for the specified capabilities.
Raises:
UnknownCapabilityError: If an unknown capability was requested.
"""
req = IsEnabledRequest()
req.set_package(self._package)
for capability in self._capabilities:
req.add_capability(capability)
for method in self._methods:
req.add_call(method)
resp = capability_service_pb.IsEnabledResponse()
self._stub_map.MakeSyncCall('capability_service', 'IsEnabled', req, resp)
if resp.summary_status() == IsEnabledResponse.UNKNOWN:
raise UnknownCapabilityError()
return resp
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
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,
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,
6905,
199,
624,
19780,
13103,
370,
10405,
3261,
734,
7441,
436,
18416,
3224,
521,
14,
199,
199,
7700,
7251,
26,
523,
347,
13874,
21145,
5736,
3491,
8,
277,
304,
272,
14238,
63,
1569,
275,
291,
14,
1069,
14,
362,
360,
4060,
358,
272,
327,
982,
314,
5935,
3261,
365,
18735,
12,
781,
7171,
2951,
3372,
314,
15210,
14,
272,
340,
22516,
3616,
1084,
360,
4782,
1959,
374,
63,
3827,
837,
489,
14238,
63,
1569,
275,
5935,
14,
8709,
8,
19044,
63,
1569,
12,
5049,
12,
5049,
9,
272,
3877,
8,
19044,
63,
1569,
9,
819,
347,
17769,
4943,
2821,
8,
277,
304,
272,
12007,
63,
6753,
275,
22516,
3616,
1084,
360,
11450,
63,
86,
19,
297,
14918,
2968,
952,
1105,
272,
340,
12007,
63,
6753,
14,
374,
63,
3827,
837,
489,
327,
2263,
3352,
1824,
12252,
1396,
272,
587,
26,
489,
327,
291,
14,
1310,
14,
548,
4827,
80,
30,
1763,
32163,
30399,
2451,
3063,
26,
450,
83,
1108,
80,
3524,
450,
2079,
12007,
63,
6753,
14,
2113,
63,
1188,
1012,
489,
327,
2263,
3352,
1824,
543,
1824,
4008,
6980,
1396,
819,
1010,
15067,
3261,
4975,
4621,
1077,
23705,
22516,
3616,
1084,
2251,
523,
367,
4390,
7830,
2419,
295,
6670,
641,
4390,
370,
1218,
3062,
14,
221,
9322,
1443,
523,
2597,
1218,
16777,
3102,
334,
69,
14,
71,
14,
1592,
14,
1831,
22210,
1012,
626,
13080,
523,
370,
314,
12082,
22516,
3616,
1084,
14,
199,
199,
15711,
3247,
2348,
26,
523,
22516,
3616,
1084,
26,
22667,
15409,
1373,
503,
1655,
14918,
12,
6127,
1109,
14254,
14,
523,
14831,
24512,
547,
26,
14031,
1380,
376,
5809,
19854,
365,
5839,
14,
199,
624,
6905,
28154,
199,
646,
3598,
199,
199,
504,
6233,
14,
15358,
14,
1246,
14,
10732,
492,
19854,
63,
1364,
63,
3317,
199,
504,
6233,
14,
15358,
14,
1095,
492,
14918,
63,
3317,
199,
504,
6233,
14,
15358,
14,
1246,
492,
2986,
3280,
63,
5811,
63,
1130,
421,
199,
1831,
6589,
2017,
221,
275,
19854,
63,
1364,
63,
3317,
14,
1831,
6589,
2017,
199,
1831,
6589,
2364,
275,
19854,
63,
1364,
63,
3317,
14,
1831,
6589,
2364,
199,
24512,
2028,
221,
275,
14918,
63,
3317,
14,
24512,
2028,
421,
199,
533,
14831,
24512,
547,
8,
1726,
304,
523,
408,
2493,
5809,
19854,
1990,
5839,
1041,
421,
199,
533,
22516,
3616,
1084,
8,
785,
304,
523,
408,
1327,
12029,
15409,
1373,
503,
1655,
14918,
14,
819,
22516,
5807,
883,
1902,
506,
4310,
7662,
12,
503,
22515,
687,
314,
523,
769,
402,
3102,
2741,
14,
221,
982,
949,
14918,
503,
3102,
787,
523,
2741,
12,
642,
911,
1104,
3775,
314,
8039,
2559,
365,
5223,
14,
523,
408,
523,
347,
636,
826,
721,
277,
12,
2559,
12,
14918,
29,
403,
12,
3102,
29,
403,
12,
2049,
10098,
63,
1130,
29,
1246,
3280,
63,
5811,
63,
1130,
304,
272,
408,
11447,
14,
339,
3033,
26,
489,
14918,
26,
769,
402,
3326,
489,
3102,
26,
769,
402,
3326,
272,
408,
272,
340,
14918,
365,
488,
26,
489,
14918,
275,
942,
272,
340,
3102,
365,
488,
26,
489,
3102,
275,
942,
272,
291,
423,
2491,
275,
2559,
272,
291,
423,
10732,
275,
788,
10,
418,
435,
14918,
272,
291,
423,
2474,
275,
3102,
272,
291,
423,
5811,
63,
1130,
275,
10098,
63,
1130,
819,
347,
365,
63,
3827,
8,
277,
304,
272,
408,
2925,
3775,
314,
14918,
365,
5544,
5223,
14,
339,
1803,
26,
489,
715,
340,
3261,
4882,
626,
4409,
3520,
4021,
371,
382,
7999,
911,
17961,
14,
339,
6218,
26,
489,
14831,
24512,
547,
12,
340,
282,
2013,
19854,
1990,
440,
18054,
14,
272,
408,
272,
1101,
275,
291,
423,
362,
63,
1205,
342,
272,
372,
1101,
14,
4705,
63,
1205,
342,
315,
334,
1831,
6589,
2364,
14,
15704,
12,
4318,
6596,
6589,
2364,
14,
27944,
53,
5290,
63,
20254,
3942,
12,
4318,
6596,
6589,
2364,
14,
27944,
53,
5290,
63,
14283,
9,
819,
347,
911,
63,
8902,
63,
3827,
63,
509,
8,
277,
12,
900,
29,
2259,
304,
272,
408,
3407,
2549,
340,
652,
911,
5706,
5223,
367,
314,
2013,
5982,
402,
900,
14,
339,
31404,
26,
642,
1083,
1990,
7078,
9999,
6366,
436,
365,
272,
8652,
5906,
14,
221,
3645,
365,
63,
3827,
342,
3140,
14,
339,
3033,
26,
489,
900,
26,
4860,
402,
4696,
315,
314,
6466,
370,
3648,
1380,
7907,
367,
18416,
267,
3224,
521,
14,
339,
1803,
26,
489,
715,
340,
2337,
365,
949,
18416,
3224,
521,
367,
314,
2013,
19854,
489,
4453,
314,
5982,
402,
900,
2013,
14,
339,
6218,
26,
489,
14831,
24512,
547,
12,
340,
282,
2013,
19854,
1990,
440,
18054,
14,
272,
408,
272,
3598,
14,
4050,
360,
14117,
63,
8902,
63,
3827,
63,
509,
342,
365,
5906,
26,
283,
2116,
283,
1180,
365,
63,
3827,
3140,
3130,
2116,
13413,
12,
2116,
13232,
29,
18,
9,
272,
1101,
275,
291,
423,
362,
63,
1205,
342,
339,
2004,
275,
1101,
14,
4705,
63,
1205,
342,
272,
340,
2004,
508,
6596,
6589,
2364,
14,
15704,
26,
489,
372,
715,
272,
916,
2004,
508,
6596,
6589,
2364,
14,
27944,
53,
5290,
63,
14283,
26,
489,
372,
756,
272,
916,
2004,
508,
6596,
6589,
2364,
14,
27944,
53,
5290,
63,
20254,
3942,
26,
489,
340,
1101,
14,
1989,
63,
521,
63,
8111,
63,
19274,
837,
267,
372,
1101,
14,
521,
63,
8111,
63,
19274
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
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,
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,
6905,
199,
624,
19780,
13103,
370,
10405,
3261,
734,
7441,
436,
18416,
3224,
521,
14,
199,
199,
7700,
7251,
26,
523,
347,
13874,
21145,
5736,
3491,
8,
277,
304,
272,
14238,
63,
1569,
275,
291,
14,
1069,
14,
362,
360,
4060,
358,
272,
327,
982,
314,
5935,
3261,
365,
18735,
12,
781,
7171,
2951,
3372,
314,
15210,
14,
272,
340,
22516,
3616,
1084,
360,
4782,
1959,
374,
63,
3827,
837,
489,
14238,
63,
1569,
275,
5935,
14,
8709,
8,
19044,
63,
1569,
12,
5049,
12,
5049,
9,
272,
3877,
8,
19044,
63,
1569,
9,
819,
347,
17769,
4943,
2821,
8,
277,
304,
272,
12007,
63,
6753,
275,
22516,
3616,
1084,
360,
11450,
63,
86,
19,
297,
14918,
2968,
952,
1105,
272,
340,
12007,
63,
6753,
14,
374,
63,
3827,
837,
489,
327,
2263,
3352,
1824,
12252,
1396,
272,
587,
26,
489,
327,
291,
14,
1310,
14,
548,
4827,
80,
30,
1763,
32163,
30399,
2451,
3063,
26,
450,
83,
1108,
80,
3524,
450,
2079,
12007,
63,
6753,
14,
2113,
63,
1188,
1012,
489,
327,
2263,
3352,
1824,
543,
1824,
4008,
6980,
1396,
819,
1010,
15067,
3261,
4975,
4621,
1077,
23705,
22516,
3616,
1084,
2251,
523,
367,
4390,
7830,
2419,
295,
6670,
641,
4390,
370,
1218,
3062,
14,
221,
9322,
1443,
523,
2597,
1218,
16777,
3102,
334,
69,
14,
71,
14,
1592,
14,
1831,
22210,
1012,
626,
13080,
523,
370,
314,
12082,
22516,
3616,
1084,
14,
199,
199,
15711,
3247,
2348,
26,
523,
22516,
3616,
1084,
26,
22667,
15409,
1373,
503,
1655,
14918,
12,
6127,
1109,
14254,
14,
523,
14831,
24512,
547,
26,
14031,
1380,
376,
5809,
19854,
365,
5839,
14,
199,
624,
6905,
28154,
199,
646,
3598,
199,
199,
504,
6233,
14,
15358,
14,
1246,
14,
10732,
492,
19854,
63,
1364,
63,
3317,
199,
504,
6233,
14,
15358,
14,
1095,
492,
14918,
63,
3317,
199,
504,
6233,
14,
15358,
14,
1246,
492,
2986,
3280,
63,
5811,
63,
1130,
421,
199,
1831,
6589,
2017,
221,
275,
19854,
63,
1364,
63,
3317,
14,
1831,
6589,
2017,
199,
1831,
6589,
2364,
275,
19854,
63,
1364,
63,
3317,
14,
1831,
6589,
2364,
199,
24512,
2028,
221,
275,
14918,
63,
3317,
14,
24512,
2028,
421,
199,
533,
14831,
24512,
547,
8,
1726,
304,
523,
408,
2493,
5809,
19854,
1990,
5839,
1041,
421,
199,
533,
22516,
3616,
1084,
8,
785,
304,
523,
408,
1327,
12029,
15409,
1373,
503,
1655,
14918,
14,
819,
22516,
5807,
883,
1902,
506,
4310,
7662,
12,
503,
22515,
687,
314,
523,
769,
402,
3102,
2741,
14,
221,
982,
949,
14918,
503,
3102,
787,
523,
2741,
12,
642,
911,
1104,
3775,
314,
8039,
2559,
365,
5223,
14,
523,
408,
523,
347,
636,
826,
721,
277,
12,
2559,
12,
14918,
29,
403,
12,
3102,
29,
403,
12,
2049,
10098,
63,
1130,
29,
1246,
3280,
63,
5811,
63,
1130,
304,
272,
408,
11447,
14,
339,
3033,
26,
489,
14918,
26,
769,
402,
3326,
489,
3102,
26,
769,
402,
3326,
272,
408,
272,
340,
14918,
365,
488,
26,
489,
14918,
275,
942,
272,
340,
3102,
365,
488,
26,
489,
3102,
275,
942,
272,
291,
423,
2491,
275,
2559,
272,
291,
423,
10732,
275,
788,
10,
418,
435,
14918,
272,
291,
423,
2474,
275,
3102,
272,
291,
423,
5811,
63,
1130,
275,
10098,
63,
1130,
819,
347,
365,
63,
3827,
8,
277,
304,
272,
408,
2925,
3775,
314,
14918,
365,
5544,
5223,
14,
339,
1803,
26,
489,
715,
340,
3261,
4882,
626,
4409,
3520,
4021,
371,
382,
7999,
911,
17961,
14,
339,
6218,
26,
489,
14831,
24512,
547,
12,
340,
282,
2013,
19854,
1990,
440,
18054,
14,
272,
408,
272,
1101,
275,
291,
423,
362,
63,
1205,
342,
272,
372,
1101,
14,
4705,
63,
1205,
342,
315,
334,
1831,
6589,
2364,
14,
15704,
12,
4318,
6596,
6589,
2364,
14,
27944,
53,
5290,
63,
20254,
3942,
12,
4318,
6596,
6589,
2364,
14,
27944,
53,
5290,
63,
14283,
9,
819,
347,
911,
63,
8902,
63,
3827,
63,
509,
8,
277,
12,
900,
29,
2259,
304,
272,
408,
3407,
2549,
340,
652,
911,
5706,
5223,
367,
314,
2013,
5982,
402,
900,
14,
339,
31404,
26,
642,
1083,
1990,
7078,
9999,
6366,
436,
365,
272,
8652,
5906,
14,
221,
3645,
365,
63,
3827,
342,
3140,
14,
339,
3033,
26,
489,
900,
26,
4860,
402,
4696,
315,
314,
6466,
370,
3648,
1380,
7907,
367,
18416,
267,
3224,
521,
14,
339,
1803,
26,
489,
715,
340,
2337,
365,
949,
18416,
3224,
521,
367,
314,
2013,
19854,
489,
4453,
314,
5982,
402,
900,
2013,
14,
339,
6218,
26,
489,
14831,
24512,
547,
12,
340,
282,
2013,
19854,
1990,
440,
18054,
14,
272,
408,
272,
3598,
14,
4050,
360,
14117,
63,
8902,
63,
3827,
63,
509,
342,
365,
5906,
26,
283,
2116,
283,
1180,
365,
63,
3827,
3140,
3130,
2116,
13413,
12,
2116,
13232,
29,
18,
9,
272,
1101,
275,
291,
423,
362,
63,
1205,
342,
339,
2004,
275,
1101,
14,
4705,
63,
1205,
342,
272,
340,
2004,
508,
6596,
6589,
2364,
14,
15704,
26,
489,
372,
715,
272,
916,
2004,
508,
6596,
6589,
2364,
14,
27944,
53,
5290,
63,
14283,
26,
489,
372,
756,
272,
916,
2004,
508,
6596,
6589,
2364,
14,
27944,
53,
5290,
63,
20254,
3942,
26,
489,
340,
1101,
14,
1989,
63,
521,
63,
8111,
63,
19274,
837,
267,
372,
1101,
14,
521,
63,
8111,
63,
19274,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
andymckay/olympia
|
src/olympia/editors/sql_table.py
|
24
|
1966
|
from django_tables.base import BaseTable, Rows, TableOptions
__all__ = ('SQLTable',)
class SQLTableOptions(TableOptions):
def __init__(self, options=None):
super(SQLTableOptions, self).__init__(options)
self.columns = getattr(options, 'columns', None)
# Exclude is not currently supported:
self.exclude = getattr(options, 'exclude', None)
class SQLRows(Rows):
def __init__(self, *args, **kwargs):
super(SQLRows, self).__init__(*args, **kwargs)
def _reset(self):
self._length = None
def __len__(self):
"""Use the queryset count() method to get the length, instead of
loading all results into memory. This allows, for example,
smart paginators that use len() to perform better.
"""
if getattr(self, '_length', None) is None:
self._length = self.table.data.count()
return self._length
# for compatibility with QuerySetPaginator
count = __len__
class SQLTable(BaseTable):
rows_class = SQLRows
def __init__(self, data=None, *args, **kwargs):
if data is None:
raise ValueError("Table must be instantiated with data=queryset")
else:
self.queryset = data
super(SQLTable, self).__init__(self.queryset, *args, **kwargs)
def _validate_column_name(self, name, purpose):
# Kind of overkill to ensure that the column is in the
# query cursor. You'll get an error, don't worry.
return True
def _build_snapshot(self):
"""Overridden. The snapshot in this case is simply a queryset
with the necessary filters etc. attached.
"""
# reset caches
self._columns._reset()
self._rows._reset()
qs = self.queryset
if self.order_by:
actual_order_by = self._resolve_sort_directions(self.order_by)
qs = qs.order_by(*self._cols_to_fields(actual_order_by))
return qs
|
bsd-3-clause
|
[
504,
1639,
63,
5987,
14,
1095,
492,
3523,
3186,
12,
15231,
83,
12,
6957,
4558,
421,
199,
363,
452,
363,
275,
661,
4657,
3186,
9538,
421,
199,
533,
5385,
3186,
4558,
8,
3186,
4558,
304,
272,
347,
636,
826,
721,
277,
12,
1511,
29,
403,
304,
267,
1613,
8,
4657,
3186,
4558,
12,
291,
2843,
826,
721,
1419,
9,
267,
291,
14,
3406,
275,
2519,
8,
1419,
12,
283,
3406,
297,
488,
9,
267,
327,
28554,
365,
440,
5544,
3748,
26,
267,
291,
14,
5473,
275,
2519,
8,
1419,
12,
283,
5473,
297,
488,
9,
421,
199,
533,
5385,
13405,
8,
13405,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
4657,
13405,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
485,
3958,
8,
277,
304,
267,
291,
423,
1267,
275,
488,
339,
347,
636,
552,
721,
277,
304,
267,
408,
6119,
314,
7594,
2338,
342,
1083,
370,
664,
314,
2582,
12,
3140,
402,
267,
8697,
1006,
2058,
1901,
4402,
14,
961,
6127,
12,
367,
2893,
12,
267,
11179,
9881,
262,
2750,
626,
675,
822,
342,
370,
5147,
8034,
14,
267,
408,
267,
340,
2519,
8,
277,
12,
2513,
1267,
297,
488,
9,
365,
488,
26,
288,
291,
423,
1267,
275,
291,
14,
1224,
14,
576,
14,
835,
342,
267,
372,
291,
423,
1267,
339,
327,
367,
7163,
543,
18397,
23862,
8566,
272,
2338,
275,
636,
552,
363,
421,
199,
533,
5385,
3186,
8,
1563,
3186,
304,
272,
4730,
63,
533,
275,
5385,
13405,
339,
347,
636,
826,
721,
277,
12,
666,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
666,
365,
488,
26,
288,
746,
1722,
480,
3186,
1471,
506,
17544,
543,
666,
29,
7924,
531,
267,
587,
26,
288,
291,
14,
7924,
275,
666,
267,
1613,
8,
4657,
3186,
12,
291,
2843,
826,
721,
277,
14,
7924,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
485,
3502,
63,
2301,
63,
354,
8,
277,
12,
536,
12,
12016,
304,
267,
327,
1804,
688,
402,
1806,
8997,
370,
4868,
626,
314,
2763,
365,
315,
314,
267,
327,
1827,
3920,
14,
2047,
7171,
664,
376,
1125,
12,
2793,
1133,
30944,
14,
267,
372,
715,
339,
347,
485,
1506,
63,
4753,
8,
277,
304,
267,
408,
5674,
8639,
14,
710,
5740,
315,
642,
1930,
365,
9329,
282,
7594,
267,
543,
314,
5784,
4766,
5423,
14,
10102,
14,
267,
408,
267,
327,
5305,
18014,
267,
291,
423,
3406,
423,
3958,
342,
267,
291,
423,
3838,
423,
3958,
342,
267,
6377,
275,
291,
14,
7924,
267,
340,
291,
14,
1648,
63,
991,
26,
288,
3503,
63,
1648,
63,
991,
275,
291,
423,
6983,
63,
3191,
63,
27917,
8,
277,
14,
1648,
63,
991,
9,
288,
6377,
275,
6377,
14,
1648,
63,
991,
2031,
277,
423,
4574,
63,
475,
63,
955,
8,
6514,
63,
1648,
63,
991,
430,
267,
372,
6377,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
63,
5987,
14,
1095,
492,
3523,
3186,
12,
15231,
83,
12,
6957,
4558,
421,
199,
363,
452,
363,
275,
661,
4657,
3186,
9538,
421,
199,
533,
5385,
3186,
4558,
8,
3186,
4558,
304,
272,
347,
636,
826,
721,
277,
12,
1511,
29,
403,
304,
267,
1613,
8,
4657,
3186,
4558,
12,
291,
2843,
826,
721,
1419,
9,
267,
291,
14,
3406,
275,
2519,
8,
1419,
12,
283,
3406,
297,
488,
9,
267,
327,
28554,
365,
440,
5544,
3748,
26,
267,
291,
14,
5473,
275,
2519,
8,
1419,
12,
283,
5473,
297,
488,
9,
421,
199,
533,
5385,
13405,
8,
13405,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
4657,
13405,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
485,
3958,
8,
277,
304,
267,
291,
423,
1267,
275,
488,
339,
347,
636,
552,
721,
277,
304,
267,
408,
6119,
314,
7594,
2338,
342,
1083,
370,
664,
314,
2582,
12,
3140,
402,
267,
8697,
1006,
2058,
1901,
4402,
14,
961,
6127,
12,
367,
2893,
12,
267,
11179,
9881,
262,
2750,
626,
675,
822,
342,
370,
5147,
8034,
14,
267,
408,
267,
340,
2519,
8,
277,
12,
2513,
1267,
297,
488,
9,
365,
488,
26,
288,
291,
423,
1267,
275,
291,
14,
1224,
14,
576,
14,
835,
342,
267,
372,
291,
423,
1267,
339,
327,
367,
7163,
543,
18397,
23862,
8566,
272,
2338,
275,
636,
552,
363,
421,
199,
533,
5385,
3186,
8,
1563,
3186,
304,
272,
4730,
63,
533,
275,
5385,
13405,
339,
347,
636,
826,
721,
277,
12,
666,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
666,
365,
488,
26,
288,
746,
1722,
480,
3186,
1471,
506,
17544,
543,
666,
29,
7924,
531,
267,
587,
26,
288,
291,
14,
7924,
275,
666,
267,
1613,
8,
4657,
3186,
12,
291,
2843,
826,
721,
277,
14,
7924,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
485,
3502,
63,
2301,
63,
354,
8,
277,
12,
536,
12,
12016,
304,
267,
327,
1804,
688,
402,
1806,
8997,
370,
4868,
626,
314,
2763,
365,
315,
314,
267,
327,
1827,
3920,
14,
2047,
7171,
664,
376,
1125,
12,
2793,
1133,
30944,
14,
267,
372,
715,
339,
347,
485,
1506,
63,
4753,
8,
277,
304,
267,
408,
5674,
8639,
14,
710,
5740,
315,
642,
1930,
365,
9329,
282,
7594,
267,
543,
314,
5784,
4766,
5423,
14,
10102,
14,
267,
408,
267,
327,
5305,
18014,
267,
291,
423,
3406,
423,
3958,
342,
267,
291,
423,
3838,
423,
3958,
342,
267,
6377,
275,
291,
14,
7924,
267,
340,
291,
14,
1648,
63,
991,
26,
288,
3503,
63,
1648,
63,
991,
275,
291,
423,
6983,
63,
3191,
63,
27917,
8,
277,
14,
1648,
63,
991,
9,
288,
6377,
275,
6377,
14,
1648,
63,
991,
2031,
277,
423,
4574,
63,
475,
63,
955,
8,
6514,
63,
1648,
63,
991,
430,
267,
372,
6377,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
ryanafolk/ambitus
|
ambitus_bayestraitscontroller.py
|
1
|
3039
|
#!/usr/bin/env python3
import subprocess # To call on bash
import sys # To process arguments
from ambitus_main import shell_call as shell_call
def bayesproc(commandargs):
processID = commandargs[0]
bootnum = commandargs[1]
runID = commandargs[2]
bootlabel = "_boot{0}".format(bootnum)
print("Variable {0}, PNO sample {1}: Running continuous character model MCMC... ".format(processID,bootnum))
shell_call("sed 's/SaveModels Ancestral.bin/SaveModels .\/temp\/Ancestral{0}{1}{2}.bin/' model.command > ./temp/model{0}{1}{2}.command".format(processID,bootlabel,runID)) # Creates a command file for a given run; needed to prevent clashing writes to the .bin file
shell_call("./BayesTraitsV2 tree.tre ./temp/character{0}{1}{2}.txt < ./temp/model{0}{1}{2}.command > /dev/null".format(processID,bootlabel,runID)) # Run MCMC of model; throws away output but this could be useful for some
shell_call("mv ./temp/character{0}{1}{2}.txt.log.txt ./output/character{0}{1}{2}.MODEL.log".format(processID,bootlabel,runID)) # Save log output; will be overwritten without this step
shell_call("mv ./temp/character{0}{1}{2}.txt.log.txt.Schedule.txt ./output/character{0}{1}{2}.MODEL_ACCEPTANCE.log".format(processID,bootlabel,runID)) # Save log output; will be overwritten without this step
print("Variable {0}, PNO sample {1}: Running ancestral reconstruction MCMC...".format(processID,bootnum))
shell_call("sed 's/LoadModels Ancestral.bin/LoadModels .\/temp\/Ancestral{0}{1}{2}.bin/' reconstruction.command > ./temp/reconstruction{0}{1}{2}.command".format(processID,bootlabel,runID)) # Creates a command file for a given run; needed to prevent clashing writes to the .bin file
shell_call("./BayesTraitsV2 tree.tre ./temp/character{0}{1}{2}.txt < ./temp/reconstruction{0}{1}{2}.command > ./temp/reconstruction{0}{1}{2}.out".format(processID,bootlabel,runID)) # Run MCMC of ancestral character reconstruction
shell_call("mv ./temp/character{0}{1}{2}.txt.log.txt ./output/character{0}{1}{2}.RECONSTRUCTION.log".format(processID,bootlabel,runID)) # Save log output; will be overwritten without this step
shell_call("mv ./temp/character{0}{1}{2}.txt.log.txt.Schedule.txt ./output/character{0}{1}{2}.RECONSTRUCTION_ACCEPTANCE.log".format(processID,bootlabel,runID)) # Save log output; will be overwritten without this step
shell_call("sed '1,/.*Harmonic Mean.*/ d' ./temp/reconstruction{0}{1}{2}.out | sed '$ d' > ./temp/reconstructionclean{0}{1}{2}.out".format(processID,bootlabel,runID)) # Trim output of BayesTraits to just the tab-delimited MCMC
print("Variable {0}, PNO sample {1}: Done.".format(processID,bootnum))
print("Cleaning up output.")
shell_call("rm ./temp/model{0}{1}{2}.command ./temp/character{0}{1}{2}.txt ./temp/Ancestral{0}{1}{2}.bin ./temp/reconstruction{0}{1}{2}.command ./temp/reconstruction{0}{1}{2}.out".format(processID,bootlabel,runID)) # Remove all intermediate files not needed for later steps, except the reconstruction log output; comment out to examine output if you are experiencing problems with BayesTraits
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
646,
3873,
327,
4005,
1240,
641,
20387,
199,
646,
984,
327,
4005,
2112,
2368,
199,
504,
16353,
390,
527,
63,
973,
492,
5218,
63,
1250,
465,
5218,
63,
1250,
199,
199,
318,
30933,
397,
4687,
8,
1531,
589,
304,
199,
198,
1412,
998,
275,
1414,
589,
59,
16,
61,
199,
198,
4930,
1507,
275,
1414,
589,
59,
17,
61,
199,
198,
1065,
998,
275,
1414,
589,
59,
18,
61,
199,
198,
4930,
1302,
275,
2668,
4930,
91,
16,
5469,
908,
8,
4930,
1507,
9,
199,
198,
1361,
480,
2773,
469,
16,
1386,
510,
2826,
2690,
469,
17,
9160,
26848,
19922,
4528,
1402,
32685,
7608,
1396,
3680,
908,
8,
1412,
998,
12,
4930,
1507,
430,
199,
198,
5641,
63,
1250,
480,
939,
283,
83,
15,
8229,
20474,
1626,
301,
31943,
14,
1393,
15,
8229,
20474,
1275,
19814,
808,
19814,
28942,
31943,
91,
16,
8847,
17,
8847,
18,
5565,
1393,
4805,
1402,
14,
1531,
690,
16605,
808,
15,
1238,
91,
16,
8847,
17,
8847,
18,
5565,
1531,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
10560,
282,
1414,
570,
367,
282,
1627,
1255,
27,
4346,
370,
7981,
30109,
316,
14511,
370,
314,
1275,
1393,
570,
199,
198,
5641,
63,
1250,
28615,
29115,
397,
31116,
54,
18,
3123,
14,
18468,
16605,
808,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
2424,
665,
16605,
808,
15,
1238,
91,
16,
8847,
17,
8847,
18,
5565,
1531,
690,
1182,
2374,
15,
2307,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
3378,
32685,
7608,
402,
1402,
27,
24266,
13437,
1072,
1325,
642,
4293,
506,
2997,
367,
2005,
199,
198,
5641,
63,
1250,
480,
12393,
16605,
808,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
2424,
14,
793,
14,
2424,
16605,
1199,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
11429,
14,
793,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
11063,
943,
1072,
27,
911,
506,
20200,
1928,
642,
3650,
199,
198,
5641,
63,
1250,
480,
12393,
16605,
808,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
2424,
14,
793,
14,
2424,
14,
15535,
14,
2424,
16605,
1199,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
11429,
63,
13089,
7140,
14,
793,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
11063,
943,
1072,
27,
911,
506,
20200,
1928,
642,
3650,
199,
198,
1361,
480,
2773,
469,
16,
1386,
510,
2826,
2690,
469,
17,
9160,
26848,
12294,
31943,
295,
12708,
32685,
7608,
1396,
1674,
908,
8,
1412,
998,
12,
4930,
1507,
430,
199,
198,
5641,
63,
1250,
480,
939,
283,
83,
15,
6200,
20474,
1626,
301,
31943,
14,
1393,
15,
6200,
20474,
1275,
19814,
808,
19814,
28942,
31943,
91,
16,
8847,
17,
8847,
18,
5565,
1393,
4805,
295,
12708,
14,
1531,
690,
16605,
808,
15,
264,
12708,
91,
16,
8847,
17,
8847,
18,
5565,
1531,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
10560,
282,
1414,
570,
367,
282,
1627,
1255,
27,
4346,
370,
7981,
30109,
316,
14511,
370,
314,
1275,
1393,
570,
199,
198,
5641,
63,
1250,
28615,
29115,
397,
31116,
54,
18,
3123,
14,
18468,
16605,
808,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
2424,
665,
16605,
808,
15,
264,
12708,
91,
16,
8847,
17,
8847,
18,
5565,
1531,
690,
16605,
808,
15,
264,
12708,
91,
16,
8847,
17,
8847,
18,
5565,
548,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
3378,
32685,
7608,
402,
12294,
31943,
4528,
295,
12708,
199,
198,
5641,
63,
1250,
480,
12393,
16605,
808,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
2424,
14,
793,
14,
2424,
16605,
1199,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
907,
1864,
3027,
53,
5430,
14,
793,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
11063,
943,
1072,
27,
911,
506,
20200,
1928,
642,
3650,
199,
198,
5641,
63,
1250,
480,
12393,
16605,
808,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
2424,
14,
793,
14,
2424,
14,
15535,
14,
2424,
16605,
1199,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
907,
1864,
3027,
53,
5430,
63,
13089,
7140,
14,
793,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
11063,
943,
1072,
27,
911,
506,
20200,
1928,
642,
3650,
199,
198,
5641,
63,
1250,
480,
939,
283,
17,
12,
15,
2795,
18248,
16082,
25136,
2795,
15,
366,
7,
16605,
808,
15,
264,
12708,
91,
16,
8847,
17,
8847,
18,
5565,
548,
1204,
542,
68,
4505,
366,
7,
690,
16605,
808,
15,
264,
12708,
3118,
91,
16,
8847,
17,
8847,
18,
5565,
548,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
12480,
77,
1072,
402,
29434,
397,
31116,
370,
2951,
314,
5174,
13,
25672,
32685,
7608,
199,
198,
1361,
480,
2773,
469,
16,
1386,
510,
2826,
2690,
469,
17,
9160,
23541,
15848,
908,
8,
1412,
998,
12,
4930,
1507,
430,
199,
198,
1361,
480,
6580,
316,
1536,
1072,
2685,
199,
198,
5641,
63,
1250,
480,
5682,
16605,
808,
15,
1238,
91,
16,
8847,
17,
8847,
18,
5565,
1531,
16605,
808,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
2424,
16605,
808,
15,
28942,
31943,
91,
16,
8847,
17,
8847,
18,
5565,
1393,
16605,
808,
15,
264,
12708,
91,
16,
8847,
17,
8847,
18,
5565,
1531,
16605,
808,
15,
264,
12708,
91,
16,
8847,
17,
8847,
18,
5565,
548,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
5852,
1006,
13197,
1584,
440,
4346,
367,
2945,
7124,
12,
871,
314,
295,
12708,
943,
1072,
27,
3721,
734,
370,
31758,
1072,
340,
1265,
787,
444,
5490,
287,
4477,
8826,
543,
29434,
397,
31116,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
646,
3873,
327,
4005,
1240,
641,
20387,
199,
646,
984,
327,
4005,
2112,
2368,
199,
504,
16353,
390,
527,
63,
973,
492,
5218,
63,
1250,
465,
5218,
63,
1250,
199,
199,
318,
30933,
397,
4687,
8,
1531,
589,
304,
199,
198,
1412,
998,
275,
1414,
589,
59,
16,
61,
199,
198,
4930,
1507,
275,
1414,
589,
59,
17,
61,
199,
198,
1065,
998,
275,
1414,
589,
59,
18,
61,
199,
198,
4930,
1302,
275,
2668,
4930,
91,
16,
5469,
908,
8,
4930,
1507,
9,
199,
198,
1361,
480,
2773,
469,
16,
1386,
510,
2826,
2690,
469,
17,
9160,
26848,
19922,
4528,
1402,
32685,
7608,
1396,
3680,
908,
8,
1412,
998,
12,
4930,
1507,
430,
199,
198,
5641,
63,
1250,
480,
939,
283,
83,
15,
8229,
20474,
1626,
301,
31943,
14,
1393,
15,
8229,
20474,
1275,
19814,
808,
19814,
28942,
31943,
91,
16,
8847,
17,
8847,
18,
5565,
1393,
4805,
1402,
14,
1531,
690,
16605,
808,
15,
1238,
91,
16,
8847,
17,
8847,
18,
5565,
1531,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
10560,
282,
1414,
570,
367,
282,
1627,
1255,
27,
4346,
370,
7981,
30109,
316,
14511,
370,
314,
1275,
1393,
570,
199,
198,
5641,
63,
1250,
28615,
29115,
397,
31116,
54,
18,
3123,
14,
18468,
16605,
808,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
2424,
665,
16605,
808,
15,
1238,
91,
16,
8847,
17,
8847,
18,
5565,
1531,
690,
1182,
2374,
15,
2307,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
3378,
32685,
7608,
402,
1402,
27,
24266,
13437,
1072,
1325,
642,
4293,
506,
2997,
367,
2005,
199,
198,
5641,
63,
1250,
480,
12393,
16605,
808,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
2424,
14,
793,
14,
2424,
16605,
1199,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
11429,
14,
793,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
11063,
943,
1072,
27,
911,
506,
20200,
1928,
642,
3650,
199,
198,
5641,
63,
1250,
480,
12393,
16605,
808,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
2424,
14,
793,
14,
2424,
14,
15535,
14,
2424,
16605,
1199,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
11429,
63,
13089,
7140,
14,
793,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
11063,
943,
1072,
27,
911,
506,
20200,
1928,
642,
3650,
199,
198,
1361,
480,
2773,
469,
16,
1386,
510,
2826,
2690,
469,
17,
9160,
26848,
12294,
31943,
295,
12708,
32685,
7608,
1396,
1674,
908,
8,
1412,
998,
12,
4930,
1507,
430,
199,
198,
5641,
63,
1250,
480,
939,
283,
83,
15,
6200,
20474,
1626,
301,
31943,
14,
1393,
15,
6200,
20474,
1275,
19814,
808,
19814,
28942,
31943,
91,
16,
8847,
17,
8847,
18,
5565,
1393,
4805,
295,
12708,
14,
1531,
690,
16605,
808,
15,
264,
12708,
91,
16,
8847,
17,
8847,
18,
5565,
1531,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
10560,
282,
1414,
570,
367,
282,
1627,
1255,
27,
4346,
370,
7981,
30109,
316,
14511,
370,
314,
1275,
1393,
570,
199,
198,
5641,
63,
1250,
28615,
29115,
397,
31116,
54,
18,
3123,
14,
18468,
16605,
808,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
2424,
665,
16605,
808,
15,
264,
12708,
91,
16,
8847,
17,
8847,
18,
5565,
1531,
690,
16605,
808,
15,
264,
12708,
91,
16,
8847,
17,
8847,
18,
5565,
548,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
3378,
32685,
7608,
402,
12294,
31943,
4528,
295,
12708,
199,
198,
5641,
63,
1250,
480,
12393,
16605,
808,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
2424,
14,
793,
14,
2424,
16605,
1199,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
907,
1864,
3027,
53,
5430,
14,
793,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
11063,
943,
1072,
27,
911,
506,
20200,
1928,
642,
3650,
199,
198,
5641,
63,
1250,
480,
12393,
16605,
808,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
2424,
14,
793,
14,
2424,
14,
15535,
14,
2424,
16605,
1199,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
907,
1864,
3027,
53,
5430,
63,
13089,
7140,
14,
793,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
11063,
943,
1072,
27,
911,
506,
20200,
1928,
642,
3650,
199,
198,
5641,
63,
1250,
480,
939,
283,
17,
12,
15,
2795,
18248,
16082,
25136,
2795,
15,
366,
7,
16605,
808,
15,
264,
12708,
91,
16,
8847,
17,
8847,
18,
5565,
548,
1204,
542,
68,
4505,
366,
7,
690,
16605,
808,
15,
264,
12708,
3118,
91,
16,
8847,
17,
8847,
18,
5565,
548,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
12480,
77,
1072,
402,
29434,
397,
31116,
370,
2951,
314,
5174,
13,
25672,
32685,
7608,
199,
198,
1361,
480,
2773,
469,
16,
1386,
510,
2826,
2690,
469,
17,
9160,
23541,
15848,
908,
8,
1412,
998,
12,
4930,
1507,
430,
199,
198,
1361,
480,
6580,
316,
1536,
1072,
2685,
199,
198,
5641,
63,
1250,
480,
5682,
16605,
808,
15,
1238,
91,
16,
8847,
17,
8847,
18,
5565,
1531,
16605,
808,
15,
10856,
91,
16,
8847,
17,
8847,
18,
5565,
2424,
16605,
808,
15,
28942,
31943,
91,
16,
8847,
17,
8847,
18,
5565,
1393,
16605,
808,
15,
264,
12708,
91,
16,
8847,
17,
8847,
18,
5565,
1531,
16605,
808,
15,
264,
12708,
91,
16,
8847,
17,
8847,
18,
5565,
548,
1674,
908,
8,
1412,
998,
12,
4930,
1302,
12,
1065,
998,
430,
327,
5852,
1006,
13197,
1584,
440,
4346,
367,
2945,
7124,
12,
871,
314,
295,
12708,
943,
1072,
27,
3721,
734,
370,
31758,
1072,
340,
1265,
787,
444,
5490,
287,
4477,
8826,
543,
29434,
397,
31116,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import str
from builtins import range
from builtins import *
import IPython.display as idisp
import html as hgen
def inline_map(map):
"""
Embeds the HTML source of the map directly into the IPython notebook.
This method will not work if the map depends on any files (json data). Also this uses
the HTML5 srcdoc attribute, which may not be supported in all browsers.
"""
map._build_map()
return idisp.HTML('<iframe srcdoc="{srcdoc}" style="width: 100%; height: 510px; border: none"></iframe>'.format(srcdoc=map.HTML.replace('"', '"')))
def inline_maps(map_list):
"""
Embeds the HTML source of the map_list directly into the IPython notebook.
This method will not work if the map depends on any files (json data). Also this uses
the HTML5 srcdoc attribute, which may not be supported in all browsers.
map_list: 2-D array of maps. dimensions should be [nRows][nCols]. The method will throw a RuntimeError if not
nRows: Number of rows
nCols: Number of columns
"""
nRows = len(map_list)
# nCols = max([len(row) for row in map_list])
hb = hgen.HTML()
t = hb.table(width="100%")
for r in range(nRows):
row = t.tr
for c in range(len(map_list[r])):
currMap = map_list[r][c]
currMap._build_map()
row.td('<iframe srcdoc="{srcdoc}" style="width: 100%; height: 510px; border: none"></iframe>'.format(srcdoc=currMap.HTML.replace('"', '"')))
return idisp.HTML('<iframe srcdoc="{srcdoc}" style="width: 100%; height: {ht}px; border: none"></iframe>'.format(srcdoc=str(t).replace('"', '"'), ht=510*nRows))
def embed_map(map, path="map.html"):
"""
Embeds a linked iframe to the map into the IPython notebook.
Note: this method will not capture the source of the map into the notebook.
This method should work for all maps (as long as they use relative urls).
"""
map.create_map(path=path)
return idisp.IFrame(src="files/{path}".format(path=path), width="100%", height="510")
|
bsd-3-clause
|
[
624,
199,
4433,
3423,
626,
883,
2929,
11747,
2723,
9033,
8308,
315,
376,
284,
1548,
20751,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
6466,
492,
4465,
63,
4342,
199,
6807,
63,
4342,
14,
3174,
63,
8602,
342,
199,
504,
12963,
492,
620,
199,
504,
12963,
492,
1425,
199,
504,
12963,
492,
627,
199,
646,
16243,
14,
2918,
465,
284,
13654,
199,
646,
3517,
465,
394,
2268,
523,
199,
318,
8308,
63,
1130,
8,
1130,
304,
272,
408,
272,
24297,
83,
314,
4163,
1350,
402,
314,
2341,
5370,
1901,
314,
16243,
20751,
14,
2286,
961,
1083,
911,
440,
1736,
340,
314,
2341,
8350,
641,
1263,
1584,
334,
1001,
666,
680,
6121,
642,
4440,
272,
314,
4163,
21,
2928,
1301,
2225,
12,
1314,
1443,
440,
506,
3748,
315,
1006,
23776,
14,
272,
408,
272,
2341,
423,
1506,
63,
1130,
342,
272,
372,
284,
13654,
14,
4943,
4827,
20052,
2928,
1301,
18448,
2164,
1301,
7063,
3449,
628,
2063,
26,
2948,
5,
27,
4569,
26,
959,
709,
5326,
27,
9162,
26,
7179,
10070,
20052,
22936,
908,
8,
2164,
1301,
29,
1130,
14,
4943,
14,
1814,
20630,
7673,
5184,
27,
7058,
199,
199,
318,
8308,
63,
8919,
8,
1130,
63,
513,
304,
272,
408,
272,
24297,
83,
314,
4163,
1350,
402,
314,
2341,
63,
513,
5370,
1901,
314,
16243,
20751,
14,
2286,
961,
1083,
911,
440,
1736,
340,
314,
2341,
8350,
641,
1263,
1584,
334,
1001,
666,
680,
6121,
642,
4440,
272,
314,
4163,
21,
2928,
1301,
2225,
12,
1314,
1443,
440,
506,
3748,
315,
1006,
23776,
14,
339,
2341,
63,
513,
26,
499,
13,
36,
1625,
402,
9033,
14,
7365,
1077,
506,
359,
78,
13405,
1527,
78,
17203,
1055,
710,
1083,
911,
7978,
282,
6064,
340,
440,
272,
302,
13405,
26,
4860,
402,
4730,
272,
302,
17203,
26,
4860,
402,
4362,
272,
408,
272,
302,
13405,
275,
822,
8,
1130,
63,
513,
9,
272,
327,
302,
17203,
275,
1390,
779,
552,
8,
1143,
9,
367,
1962,
315,
2341,
63,
513,
566,
272,
394,
66,
275,
394,
2268,
14,
4943,
342,
272,
307,
275,
394,
66,
14,
1224,
8,
2063,
628,
1960,
5,
531,
272,
367,
519,
315,
1425,
8,
78,
13405,
304,
267,
1962,
275,
307,
14,
454,
267,
367,
286,
315,
1425,
8,
552,
8,
1130,
63,
513,
59,
82,
18710,
288,
8230,
2956,
275,
2341,
63,
513,
59,
82,
1527,
67,
61,
288,
8230,
2956,
423,
1506,
63,
1130,
342,
288,
1962,
14,
2076,
4827,
20052,
2928,
1301,
18448,
2164,
1301,
7063,
3449,
628,
2063,
26,
2948,
5,
27,
4569,
26,
959,
709,
5326,
27,
9162,
26,
7179,
10070,
20052,
22936,
908,
8,
2164,
1301,
29,
9808,
2956,
14,
4943,
14,
1814,
20630,
7673,
5184,
27,
7058,
272,
372,
284,
13654,
14,
4943,
4827,
20052,
2928,
1301,
18448,
2164,
1301,
7063,
3449,
628,
2063,
26,
2948,
5,
27,
4569,
26,
469,
517,
93,
5326,
27,
9162,
26,
7179,
10070,
20052,
22936,
908,
8,
2164,
1301,
29,
495,
8,
84,
680,
1814,
20630,
7673,
5184,
27,
659,
1243,
29,
27161,
10,
78,
13405,
430,
523,
199,
318,
6441,
63,
1130,
8,
1130,
12,
931,
628,
1130,
14,
1360,
2349,
272,
408,
272,
24297,
83,
282,
10632,
340,
1186,
370,
314,
2341,
1901,
314,
16243,
20751,
14,
2286,
3390,
26,
642,
1083,
911,
440,
12296,
314,
1350,
402,
314,
2341,
1901,
314,
20751,
14,
272,
961,
1083,
1077,
1736,
367,
1006,
9033,
334,
305,
1846,
465,
2985,
675,
3847,
8187,
680,
272,
408,
272,
2341,
14,
981,
63,
1130,
8,
515,
29,
515,
9,
272,
372,
284,
13654,
14,
41,
3160,
8,
2164,
628,
1725,
5321,
515,
5469,
908,
8,
515,
29,
515,
395,
3462,
628,
1960,
31181,
4569,
628,
27161,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
4433,
3423,
626,
883,
2929,
11747,
2723,
9033,
8308,
315,
376,
284,
1548,
20751,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
6466,
492,
4465,
63,
4342,
199,
6807,
63,
4342,
14,
3174,
63,
8602,
342,
199,
504,
12963,
492,
620,
199,
504,
12963,
492,
1425,
199,
504,
12963,
492,
627,
199,
646,
16243,
14,
2918,
465,
284,
13654,
199,
646,
3517,
465,
394,
2268,
523,
199,
318,
8308,
63,
1130,
8,
1130,
304,
272,
408,
272,
24297,
83,
314,
4163,
1350,
402,
314,
2341,
5370,
1901,
314,
16243,
20751,
14,
2286,
961,
1083,
911,
440,
1736,
340,
314,
2341,
8350,
641,
1263,
1584,
334,
1001,
666,
680,
6121,
642,
4440,
272,
314,
4163,
21,
2928,
1301,
2225,
12,
1314,
1443,
440,
506,
3748,
315,
1006,
23776,
14,
272,
408,
272,
2341,
423,
1506,
63,
1130,
342,
272,
372,
284,
13654,
14,
4943,
4827,
20052,
2928,
1301,
18448,
2164,
1301,
7063,
3449,
628,
2063,
26,
2948,
5,
27,
4569,
26,
959,
709,
5326,
27,
9162,
26,
7179,
10070,
20052,
22936,
908,
8,
2164,
1301,
29,
1130,
14,
4943,
14,
1814,
20630,
7673,
5184,
27,
7058,
199,
199,
318,
8308,
63,
8919,
8,
1130,
63,
513,
304,
272,
408,
272,
24297,
83,
314,
4163,
1350,
402,
314,
2341,
63,
513,
5370,
1901,
314,
16243,
20751,
14,
2286,
961,
1083,
911,
440,
1736,
340,
314,
2341,
8350,
641,
1263,
1584,
334,
1001,
666,
680,
6121,
642,
4440,
272,
314,
4163,
21,
2928,
1301,
2225,
12,
1314,
1443,
440,
506,
3748,
315,
1006,
23776,
14,
339,
2341,
63,
513,
26,
499,
13,
36,
1625,
402,
9033,
14,
7365,
1077,
506,
359,
78,
13405,
1527,
78,
17203,
1055,
710,
1083,
911,
7978,
282,
6064,
340,
440,
272,
302,
13405,
26,
4860,
402,
4730,
272,
302,
17203,
26,
4860,
402,
4362,
272,
408,
272,
302,
13405,
275,
822,
8,
1130,
63,
513,
9,
272,
327,
302,
17203,
275,
1390,
779,
552,
8,
1143,
9,
367,
1962,
315,
2341,
63,
513,
566,
272,
394,
66,
275,
394,
2268,
14,
4943,
342,
272,
307,
275,
394,
66,
14,
1224,
8,
2063,
628,
1960,
5,
531,
272,
367,
519,
315,
1425,
8,
78,
13405,
304,
267,
1962,
275,
307,
14,
454,
267,
367,
286,
315,
1425,
8,
552,
8,
1130,
63,
513,
59,
82,
18710,
288,
8230,
2956,
275,
2341,
63,
513,
59,
82,
1527,
67,
61,
288,
8230,
2956,
423,
1506,
63,
1130,
342,
288,
1962,
14,
2076,
4827,
20052,
2928,
1301,
18448,
2164,
1301,
7063,
3449,
628,
2063,
26,
2948,
5,
27,
4569,
26,
959,
709,
5326,
27,
9162,
26,
7179,
10070,
20052,
22936,
908,
8,
2164,
1301,
29,
9808,
2956,
14,
4943,
14,
1814,
20630,
7673,
5184,
27,
7058,
272,
372,
284,
13654,
14,
4943,
4827,
20052,
2928,
1301,
18448,
2164,
1301,
7063,
3449,
628,
2063,
26,
2948,
5,
27,
4569,
26,
469,
517,
93,
5326,
27,
9162,
26,
7179,
10070,
20052,
22936,
908,
8,
2164,
1301,
29,
495,
8,
84,
680,
1814,
20630,
7673,
5184,
27,
659,
1243,
29,
27161,
10,
78,
13405,
430,
523,
199,
318,
6441,
63,
1130,
8,
1130,
12,
931,
628,
1130,
14,
1360,
2349,
272,
408,
272,
24297,
83,
282,
10632,
340,
1186,
370,
314,
2341,
1901,
314,
16243,
20751,
14,
2286,
3390,
26,
642,
1083,
911,
440,
12296,
314,
1350,
402,
314,
2341,
1901,
314,
20751,
14,
272,
961,
1083,
1077,
1736,
367,
1006,
9033,
334,
305,
1846,
465,
2985,
675,
3847,
8187,
680,
272,
408,
272,
2341,
14,
981,
63,
1130,
8,
515,
29,
515,
9,
272,
372,
284,
13654,
14,
41,
3160,
8,
2164,
628,
1725,
5321,
515,
5469,
908,
8,
515,
29,
515,
395,
3462,
628,
1960,
31181,
4569,
628,
27161,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
flashycud/timestack
|
djangoappengine/management/commands/runserver.py
|
14
|
3475
|
#!/usr/bin/python2.4
#
# Copyright 2008 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.
import logging
import sys
from django.db import connections
from ...boot import PROJECT_DIR
from ...db.base import DatabaseWrapper
from django.core.management.base import BaseCommand
from django.core.exceptions import ImproperlyConfigured
def start_dev_appserver(argv):
"""Starts the App Engine dev_appserver program for the Django project.
The appserver is run with default parameters. If you need to pass any special
parameters to the dev_appserver you will have to invoke it manually.
"""
from google.appengine.tools import dev_appserver_main
progname = argv[0]
args = []
# hack __main__ so --help in dev_appserver_main works OK.
sys.modules['__main__'] = dev_appserver_main
# Set bind ip/port if specified.
addr, port = None, '8000'
if len(argv) > 2:
if not argv[2].startswith('-'):
addrport = argv[2]
try:
addr, port = addrport.split(":")
except ValueError:
addr = addrport
else:
args.append(argv[2])
args.extend(argv[3:])
if addr:
args.extend(["--address", addr])
if port:
args.extend(["--port", port])
# Add email settings
from django.conf import settings
if '--smtp_host' not in args and '--enable_sendmail' not in args:
args.extend(['--smtp_host', settings.EMAIL_HOST,
'--smtp_port', str(settings.EMAIL_PORT),
'--smtp_user', settings.EMAIL_HOST_USER,
'--smtp_password', settings.EMAIL_HOST_PASSWORD])
# Pass the application specific datastore location to the server.
for name in connections:
connection = connections[name]
if isinstance(connection, DatabaseWrapper):
p = connection._get_paths()
if '--datastore_path' not in args:
args.extend(['--datastore_path', p[0]])
if '--blobstore_path' not in args:
args.extend(['--blobstore_path', p[1]])
if '--history_path' not in args:
args.extend(['--history_path', p[2]])
break
# Reset logging level to INFO as dev_appserver will spew tons of debug logs
logging.getLogger().setLevel(logging.INFO)
# Append the current working directory to the arguments.
dev_appserver_main.main([progname] + args + [PROJECT_DIR])
class Command(BaseCommand):
"""Overrides the default Django runserver command.
Instead of starting the default Django development server this command
fires up a copy of the full fledged App Engine dev_appserver that emulates
the live environment your application will be deployed to.
"""
help = 'Runs a copy of the App Engine development server.'
args = '[optional port number, or ipaddr:port]'
def run_from_argv(self, argv):
start_dev_appserver(argv)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
18,
14,
20,
199,
3,
199,
3,
1898,
9079,
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,
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,
421,
199,
646,
2050,
199,
646,
984,
199,
199,
504,
1639,
14,
697,
492,
6947,
199,
504,
2263,
4930,
492,
21915,
63,
3022,
199,
504,
2263,
697,
14,
1095,
492,
8692,
4590,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
421,
199,
318,
1343,
63,
2374,
63,
571,
1000,
8,
3020,
304,
272,
408,
32142,
314,
4693,
12580,
4866,
63,
571,
1000,
2240,
367,
314,
5634,
2199,
14,
339,
710,
1145,
1000,
365,
1255,
543,
849,
2633,
14,
982,
1265,
1929,
370,
986,
1263,
4539,
272,
2633,
370,
314,
4866,
63,
571,
1000,
1265,
911,
1172,
370,
12677,
652,
10250,
14,
272,
408,
272,
687,
6233,
14,
15358,
14,
2537,
492,
4866,
63,
571,
1000,
63,
973,
272,
13205,
354,
275,
9238,
59,
16,
61,
272,
1249,
275,
942,
272,
327,
11176,
636,
973,
363,
880,
1553,
3437,
315,
4866,
63,
571,
1000,
63,
973,
5419,
9949,
14,
272,
984,
14,
3112,
13742,
973,
17501,
275,
4866,
63,
571,
1000,
63,
973,
272,
327,
2494,
5398,
3384,
15,
719,
340,
2013,
14,
272,
5552,
12,
1844,
275,
488,
12,
283,
15214,
7,
272,
340,
822,
8,
3020,
9,
690,
499,
26,
267,
340,
440,
9238,
59,
18,
1055,
2460,
3654,
735,
288,
5552,
719,
275,
9238,
59,
18,
61,
288,
862,
26,
355,
5552,
12,
1844,
275,
5552,
719,
14,
1294,
20063,
288,
871,
1722,
26,
355,
5552,
275,
5552,
719,
267,
587,
26,
288,
1249,
14,
740,
8,
3020,
59,
18,
566,
267,
1249,
14,
2880,
8,
3020,
59,
19,
5728,
272,
340,
5552,
26,
267,
1249,
14,
2880,
5234,
306,
1562,
401,
5552,
566,
272,
340,
1844,
26,
267,
1249,
14,
2880,
5234,
306,
719,
401,
1844,
566,
272,
327,
2654,
3031,
2202,
272,
687,
1639,
14,
2190,
492,
2202,
272,
340,
2850,
15592,
63,
1102,
7,
440,
315,
1249,
436,
2850,
4296,
63,
2254,
1198,
7,
440,
315,
1249,
26,
267,
1249,
14,
2880,
18510,
15592,
63,
1102,
297,
2202,
14,
10089,
63,
5449,
12,
2151,
2850,
15592,
63,
719,
297,
620,
8,
1751,
14,
10089,
63,
3657,
395,
2151,
2850,
15592,
63,
751,
297,
2202,
14,
10089,
63,
5449,
63,
3791,
12,
2151,
2850,
15592,
63,
2060,
297,
2202,
14,
10089,
63,
5449,
63,
9032,
566,
339,
327,
8325,
314,
4223,
2488,
12007,
2909,
370,
314,
1654,
14,
272,
367,
536,
315,
6947,
26,
267,
1950,
275,
6947,
59,
354,
61,
267,
340,
1228,
8,
2105,
12,
8692,
4590,
304,
288,
299,
275,
1950,
423,
362,
63,
3771,
342,
288,
340,
2850,
11450,
63,
515,
7,
440,
315,
1249,
26,
355,
1249,
14,
2880,
18510,
11450,
63,
515,
297,
299,
59,
16,
3934,
288,
340,
2850,
6582,
1617,
63,
515,
7,
440,
315,
1249,
26,
355,
1249,
14,
2880,
18510,
6582,
1617,
63,
515,
297,
299,
59,
17,
3934,
288,
340,
2850,
5570,
63,
515,
7,
440,
315,
1249,
26,
355,
1249,
14,
2880,
18510,
5570,
63,
515,
297,
299,
59,
18,
3934,
288,
2059,
339,
327,
15510,
2050,
2166,
370,
24008,
465,
4866,
63,
571,
1000,
911,
14475,
87,
307,
4654,
402,
3105,
9610,
272,
2050,
14,
5572,
1252,
13548,
8,
4806,
14,
4531,
9,
339,
327,
18726,
314,
1453,
6449,
2082,
370,
314,
2368,
14,
272,
4866,
63,
571,
1000,
63,
973,
14,
973,
779,
6595,
354,
61,
435,
1249,
435,
359,
10797,
63,
3022,
566,
199,
199,
533,
5817,
8,
25150,
304,
272,
408,
27586,
314,
849,
5634,
1255,
1000,
1414,
14,
339,
15345,
402,
6617,
314,
849,
5634,
16367,
1654,
642,
1414,
272,
28887,
1536,
282,
1331,
402,
314,
2615,
289,
1146,
3046,
4693,
12580,
4866,
63,
571,
1000,
626,
17423,
2335,
272,
314,
12166,
3734,
2195,
4223,
911,
506,
26181,
370,
14,
272,
408,
272,
1720,
275,
283,
16291,
282,
1331,
402,
314,
4693,
12580,
16367,
1654,
3530,
272,
1249,
275,
6730,
4144,
1844,
1329,
12,
503,
21249,
26,
719,
6616,
339,
347,
1255,
63,
504,
63,
3020,
8,
277,
12,
9238,
304,
267,
1343,
63,
2374,
63,
571,
1000,
8,
3020,
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
] |
[
2647,
15,
1393,
15,
1548,
18,
14,
20,
199,
3,
199,
3,
1898,
9079,
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,
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,
421,
199,
646,
2050,
199,
646,
984,
199,
199,
504,
1639,
14,
697,
492,
6947,
199,
504,
2263,
4930,
492,
21915,
63,
3022,
199,
504,
2263,
697,
14,
1095,
492,
8692,
4590,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
421,
199,
318,
1343,
63,
2374,
63,
571,
1000,
8,
3020,
304,
272,
408,
32142,
314,
4693,
12580,
4866,
63,
571,
1000,
2240,
367,
314,
5634,
2199,
14,
339,
710,
1145,
1000,
365,
1255,
543,
849,
2633,
14,
982,
1265,
1929,
370,
986,
1263,
4539,
272,
2633,
370,
314,
4866,
63,
571,
1000,
1265,
911,
1172,
370,
12677,
652,
10250,
14,
272,
408,
272,
687,
6233,
14,
15358,
14,
2537,
492,
4866,
63,
571,
1000,
63,
973,
272,
13205,
354,
275,
9238,
59,
16,
61,
272,
1249,
275,
942,
272,
327,
11176,
636,
973,
363,
880,
1553,
3437,
315,
4866,
63,
571,
1000,
63,
973,
5419,
9949,
14,
272,
984,
14,
3112,
13742,
973,
17501,
275,
4866,
63,
571,
1000,
63,
973,
272,
327,
2494,
5398,
3384,
15,
719,
340,
2013,
14,
272,
5552,
12,
1844,
275,
488,
12,
283,
15214,
7,
272,
340,
822,
8,
3020,
9,
690,
499,
26,
267,
340,
440,
9238,
59,
18,
1055,
2460,
3654,
735,
288,
5552,
719,
275,
9238,
59,
18,
61,
288,
862,
26,
355,
5552,
12,
1844,
275,
5552,
719,
14,
1294,
20063,
288,
871,
1722,
26,
355,
5552,
275,
5552,
719,
267,
587,
26,
288,
1249,
14,
740,
8,
3020,
59,
18,
566,
267,
1249,
14,
2880,
8,
3020,
59,
19,
5728,
272,
340,
5552,
26,
267,
1249,
14,
2880,
5234,
306,
1562,
401,
5552,
566,
272,
340,
1844,
26,
267,
1249,
14,
2880,
5234,
306,
719,
401,
1844,
566,
272,
327,
2654,
3031,
2202,
272,
687,
1639,
14,
2190,
492,
2202,
272,
340,
2850,
15592,
63,
1102,
7,
440,
315,
1249,
436,
2850,
4296,
63,
2254,
1198,
7,
440,
315,
1249,
26,
267,
1249,
14,
2880,
18510,
15592,
63,
1102,
297,
2202,
14,
10089,
63,
5449,
12,
2151,
2850,
15592,
63,
719,
297,
620,
8,
1751,
14,
10089,
63,
3657,
395,
2151,
2850,
15592,
63,
751,
297,
2202,
14,
10089,
63,
5449,
63,
3791,
12,
2151,
2850,
15592,
63,
2060,
297,
2202,
14,
10089,
63,
5449,
63,
9032,
566,
339,
327,
8325,
314,
4223,
2488,
12007,
2909,
370,
314,
1654,
14,
272,
367,
536,
315,
6947,
26,
267,
1950,
275,
6947,
59,
354,
61,
267,
340,
1228,
8,
2105,
12,
8692,
4590,
304,
288,
299,
275,
1950,
423,
362,
63,
3771,
342,
288,
340,
2850,
11450,
63,
515,
7,
440,
315,
1249,
26,
355,
1249,
14,
2880,
18510,
11450,
63,
515,
297,
299,
59,
16,
3934,
288,
340,
2850,
6582,
1617,
63,
515,
7,
440,
315,
1249,
26,
355,
1249,
14,
2880,
18510,
6582,
1617,
63,
515,
297,
299,
59,
17,
3934,
288,
340,
2850,
5570,
63,
515,
7,
440,
315,
1249,
26,
355,
1249,
14,
2880,
18510,
5570,
63,
515,
297,
299,
59,
18,
3934,
288,
2059,
339,
327,
15510,
2050,
2166,
370,
24008,
465,
4866,
63,
571,
1000,
911,
14475,
87,
307,
4654,
402,
3105,
9610,
272,
2050,
14,
5572,
1252,
13548,
8,
4806,
14,
4531,
9,
339,
327,
18726,
314,
1453,
6449,
2082,
370,
314,
2368,
14,
272,
4866,
63,
571,
1000,
63,
973,
14,
973,
779,
6595,
354,
61,
435,
1249,
435,
359,
10797,
63,
3022,
566,
199,
199,
533,
5817,
8,
25150,
304,
272,
408,
27586,
314,
849,
5634,
1255,
1000,
1414,
14,
339,
15345,
402,
6617,
314,
849,
5634,
16367,
1654,
642,
1414,
272,
28887,
1536,
282,
1331,
402,
314,
2615,
289,
1146,
3046,
4693,
12580,
4866,
63,
571,
1000,
626,
17423,
2335,
272,
314,
12166,
3734,
2195,
4223,
911,
506,
26181,
370,
14,
272,
408,
272,
1720,
275,
283,
16291,
282,
1331,
402,
314,
4693,
12580,
16367,
1654,
3530,
272,
1249,
275,
6730,
4144,
1844,
1329,
12,
503,
21249,
26,
719,
6616,
339,
347,
1255,
63,
504,
63,
3020,
8,
277,
12,
9238,
304,
267,
1343,
63,
2374,
63,
571,
1000,
8,
3020,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jcpowermac/ansible
|
lib/ansible/utils/module_docs_fragments/aireos.py
|
131
|
2742
|
#
# (c) 2017, James Mighion <@jmighion>
#
# 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/>.
class ModuleDocFragment(object):
# Standard files documentation fragment
DOCUMENTATION = """
options:
provider:
description:
- A dict object containing connection details.
default: null
suboptions:
host:
description:
- Specifies the DNS host name or address for connecting to the remote
device over the specified transport. The value of host is used as
the destination address for the transport.
required: true
port:
description:
- Specifies the port to use when building the connection to the remote.
device.
default: 22
username:
description:
- Configures the username to use to authenticate the connection to
the remote device. This value is used to authenticate
the SSH session. If the value is not specified in the task, the
value of environment variable C(ANSIBLE_NET_USERNAME) will be used instead.
password:
description:
- Specifies the password to use to authenticate the connection to
the remote device. This value is used to authenticate
the SSH session. If the value is not specified in the task, the
value of environment variable C(ANSIBLE_NET_PASSWORD) will be used instead.
default: null
timeout:
description:
- Specifies the timeout in seconds for communicating with the network device
for either connecting or sending commands. If the timeout is
exceeded before the operation is completed, the module will error.
default: 10
ssh_keyfile:
description:
- Specifies the SSH key to use to authenticate the connection to
the remote device. This value is the path to the
key used to authenticate the SSH session. If the value is not specified
in the task, the value of environment variable C(ANSIBLE_NET_SSH_KEYFILE)
will be used instead.
"""
|
gpl-3.0
|
[
3,
199,
3,
334,
67,
9,
9708,
12,
1603,
14015,
603,
2056,
1636,
665,
32,
74,
77,
2056,
1636,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
533,
5673,
3768,
11080,
8,
785,
304,
339,
327,
9739,
1584,
3794,
7956,
272,
29970,
2594,
275,
408,
199,
1419,
26,
523,
5022,
26,
272,
1369,
26,
489,
446,
437,
1211,
909,
3035,
1950,
2436,
14,
272,
849,
26,
2973,
272,
26265,
26,
489,
1591,
26,
267,
1369,
26,
881,
446,
11015,
314,
10237,
1591,
536,
503,
2287,
367,
18170,
370,
314,
3982,
288,
2243,
1806,
314,
2013,
7773,
14,
221,
710,
574,
402,
1591,
365,
1202,
465,
288,
314,
5724,
2287,
367,
314,
7773,
14,
267,
1415,
26,
2549,
489,
1844,
26,
267,
1369,
26,
881,
446,
11015,
314,
1844,
370,
675,
1380,
10015,
314,
1950,
370,
314,
3982,
14,
288,
2243,
14,
267,
849,
26,
6928,
489,
3434,
26,
267,
1369,
26,
881,
446,
4094,
1482,
314,
3434,
370,
675,
370,
12895,
314,
1950,
370,
288,
314,
3982,
2243,
14,
221,
961,
574,
365,
1202,
370,
12895,
288,
314,
12027,
2351,
14,
982,
314,
574,
365,
440,
2013,
315,
314,
2120,
12,
314,
288,
574,
402,
3734,
1750,
445,
8,
8490,
63,
7278,
63,
11958,
9,
911,
506,
1202,
3140,
14,
489,
2505,
26,
267,
1369,
26,
881,
446,
11015,
314,
2505,
370,
675,
370,
12895,
314,
1950,
370,
288,
314,
3982,
2243,
14,
257,
961,
574,
365,
1202,
370,
12895,
288,
314,
12027,
2351,
14,
982,
314,
574,
365,
440,
2013,
315,
314,
2120,
12,
314,
288,
574,
402,
3734,
1750,
445,
8,
8490,
63,
7278,
63,
9032,
9,
911,
506,
1202,
3140,
14,
267,
849,
26,
2973,
489,
2653,
26,
267,
1369,
26,
881,
446,
11015,
314,
2653,
315,
4696,
367,
13882,
1958,
543,
314,
2784,
2243,
288,
367,
1902,
18170,
503,
10209,
3718,
14,
221,
982,
314,
2653,
365,
288,
22007,
2544,
314,
3439,
365,
9709,
12,
314,
859,
911,
1125,
14,
267,
849,
26,
1616,
489,
8635,
63,
21856,
26,
267,
1369,
26,
881,
446,
11015,
314,
12027,
790,
370,
675,
370,
12895,
314,
1950,
370,
288,
314,
3982,
2243,
14,
257,
961,
574,
365,
314,
931,
370,
314,
288,
790,
1202,
370,
12895,
314,
12027,
2351,
14,
982,
314,
574,
365,
440,
2013,
288,
315,
314,
2120,
12,
314,
574,
402,
3734,
1750,
445,
8,
8490,
63,
7278,
63,
13716,
63,
3078,
3817,
9,
288,
911,
506,
1202,
3140,
14,
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
] |
[
199,
3,
334,
67,
9,
9708,
12,
1603,
14015,
603,
2056,
1636,
665,
32,
74,
77,
2056,
1636,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
533,
5673,
3768,
11080,
8,
785,
304,
339,
327,
9739,
1584,
3794,
7956,
272,
29970,
2594,
275,
408,
199,
1419,
26,
523,
5022,
26,
272,
1369,
26,
489,
446,
437,
1211,
909,
3035,
1950,
2436,
14,
272,
849,
26,
2973,
272,
26265,
26,
489,
1591,
26,
267,
1369,
26,
881,
446,
11015,
314,
10237,
1591,
536,
503,
2287,
367,
18170,
370,
314,
3982,
288,
2243,
1806,
314,
2013,
7773,
14,
221,
710,
574,
402,
1591,
365,
1202,
465,
288,
314,
5724,
2287,
367,
314,
7773,
14,
267,
1415,
26,
2549,
489,
1844,
26,
267,
1369,
26,
881,
446,
11015,
314,
1844,
370,
675,
1380,
10015,
314,
1950,
370,
314,
3982,
14,
288,
2243,
14,
267,
849,
26,
6928,
489,
3434,
26,
267,
1369,
26,
881,
446,
4094,
1482,
314,
3434,
370,
675,
370,
12895,
314,
1950,
370,
288,
314,
3982,
2243,
14,
221,
961,
574,
365,
1202,
370,
12895,
288,
314,
12027,
2351,
14,
982,
314,
574,
365,
440,
2013,
315,
314,
2120,
12,
314,
288,
574,
402,
3734,
1750,
445,
8,
8490,
63,
7278,
63,
11958,
9,
911,
506,
1202,
3140,
14,
489,
2505,
26,
267,
1369,
26,
881,
446,
11015,
314,
2505,
370,
675,
370,
12895,
314,
1950,
370,
288,
314,
3982,
2243,
14,
257,
961,
574,
365,
1202,
370,
12895,
288,
314,
12027,
2351,
14,
982,
314,
574,
365,
440,
2013,
315,
314,
2120,
12,
314,
288,
574,
402,
3734,
1750,
445,
8,
8490,
63,
7278,
63,
9032,
9,
911,
506,
1202,
3140,
14,
267,
849,
26,
2973,
489,
2653,
26,
267,
1369,
26,
881,
446,
11015,
314,
2653,
315,
4696,
367,
13882,
1958,
543,
314,
2784,
2243,
288,
367,
1902,
18170,
503,
10209,
3718,
14,
221,
982,
314,
2653,
365,
288,
22007,
2544,
314,
3439,
365,
9709,
12,
314,
859,
911,
1125,
14,
267,
849,
26,
1616,
489,
8635,
63,
21856,
26,
267,
1369,
26,
881,
446,
11015,
314,
12027,
790,
370,
675,
370,
12895,
314,
1950,
370,
288,
314,
3982,
2243,
14,
257,
961,
574,
365,
314,
931,
370,
314,
288,
790,
1202,
370,
12895,
314,
12027,
2351,
14,
982,
314,
574,
365,
440,
2013,
288,
315,
314,
2120,
12,
314,
574,
402,
3734,
1750,
445,
8,
8490,
63,
7278,
63,
13716,
63,
3078,
3817,
9,
288,
911,
506,
1202,
3140,
14,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
samatt/OpenWPM
|
automation/DataAggregator/LevelDBAggregator.py
|
1
|
3112
|
from ..SocketInterface import serversocket
from ..MPLogger import loggingclient
import plyvel
import pyhash
import zlib
import time
import os
def LevelDBAggregator(manager_params, status_queue, batch_size=100):
"""
Receives <key, value> pairs from other processes and writes them to the central database.
Executes queries until being told to die (then it will finish work and shut down).
This process should never be terminated un-gracefully.
<manager_params> TaskManager configuration parameters
<status_queue> is a queue connect to the TaskManager used for communication
<batch_size> is the size of the write batch
"""
# sets up logging connection
logger = loggingclient(*manager_params['logger_address'])
# sets up the serversocket to start accepting connections
sock = serversocket()
status_queue.put(sock.sock.getsockname()) # let TM know location
sock.start_accepting()
# sets up DB connection
db_path = os.path.join(manager_params['data_directory'], 'javascript.ldb')
db = plyvel.DB(db_path,
create_if_missing = True,
lru_cache_size = 10**9,
write_buffer_size = 128*10**4,
compression = None)
batch = db.write_batch()
counter = 0 # number of executions made since last write
commit_time = 0 # keep track of time since last write
while True:
# received KILL command from TaskManager
if not status_queue.empty():
status_queue.get()
sock.close()
drain_queue(sock.queue, batch, db, counter, logger)
break
# no command for now -> sleep to avoid pegging CPU on blocking get
if sock.queue.empty():
time.sleep(0.1)
# commit every five seconds to avoid blocking the db for too long
if counter > 0 and time.time() - commit_time > 5:
batch.write()
batch = db.write_batch()
continue
# process record
script = sock.queue.get()
counter = process_script(script, batch, db, counter, logger)
# batch commit if necessary
if counter >= batch_size:
counter = 0
commit_time = time.time()
batch.write()
batch = db.write_batch()
# finishes work and gracefully stops
batch.write()
db.close()
def process_script(script, batch, db, counter, logger):
"""
adds a script to the batch
"""
# Hash script for deduplication on disk
hasher = pyhash.murmur3_x64_128()
script_hash = str(hasher(script) >> 64)
if db.get(script_hash) is not None:
return counter
compressed_script = zlib.compress(script)
batch.put(script_hash, compressed_script)
return counter + 1
def drain_queue(sock_queue, batch, db, counter, logger):
""" Ensures queue is empty before closing """
time.sleep(3) # TODO: the socket needs a better way of closing
while not sock_queue.empty():
script = sock_queue.get()
counter = process_script(script, batch, db, counter, logger)
|
gpl-3.0
|
[
504,
2508,
3869,
4267,
492,
1654,
3450,
199,
504,
2508,
1658,
4455,
492,
2050,
1258,
199,
646,
299,
590,
1090,
199,
646,
1134,
2227,
199,
646,
12472,
199,
646,
900,
199,
646,
747,
421,
199,
318,
20400,
2846,
23933,
8,
2609,
63,
1162,
12,
2004,
63,
1825,
12,
3522,
63,
890,
29,
1960,
304,
272,
408,
1362,
799,
2375,
397,
665,
498,
12,
574,
30,
6342,
687,
1163,
10358,
436,
14511,
3062,
370,
314,
18796,
3050,
14,
1362,
9434,
3862,
9212,
5133,
3769,
370,
1447,
370,
18833,
334,
12726,
652,
911,
9578,
1736,
436,
24761,
3224,
680,
1362,
961,
2112,
1077,
7078,
506,
15745,
625,
13,
20631,
5836,
14,
10813,
665,
2609,
63,
1162,
30,
8495,
2988,
2897,
2633,
1362,
665,
1205,
63,
1825,
30,
365,
282,
4126,
4907,
370,
314,
8495,
2988,
1202,
367,
23506,
1362,
665,
2912,
63,
890,
30,
365,
314,
1568,
402,
314,
2218,
3522,
272,
408,
339,
327,
5951,
1536,
2050,
1950,
272,
2512,
275,
2050,
1258,
2031,
2609,
63,
1162,
459,
2921,
63,
1562,
1105,
339,
327,
5951,
1536,
314,
1654,
3450,
370,
1343,
32163,
6947,
272,
6771,
275,
1654,
3450,
342,
272,
2004,
63,
1825,
14,
524,
8,
5096,
14,
5096,
14,
27886,
1012,
221,
327,
4691,
377,
45,
5715,
2909,
272,
6771,
14,
928,
63,
5694,
316,
342,
339,
327,
5951,
1536,
6249,
1950,
272,
1592,
63,
515,
275,
747,
14,
515,
14,
904,
8,
2609,
63,
1162,
459,
576,
63,
3619,
995,
283,
9554,
14,
15793,
358,
272,
1592,
275,
299,
590,
1090,
14,
2846,
8,
697,
63,
515,
12,
288,
1218,
63,
692,
63,
4752,
275,
715,
12,
288,
634,
6558,
63,
1637,
63,
890,
275,
1616,
538,
25,
12,
288,
2218,
63,
2738,
63,
890,
275,
7960,
10,
709,
538,
20,
12,
288,
10291,
275,
488,
9,
272,
3522,
275,
1592,
14,
952,
63,
2912,
342,
339,
7055,
275,
378,
221,
327,
1329,
402,
2146,
8653,
6326,
3967,
2061,
2218,
272,
5532,
63,
521,
275,
378,
221,
327,
4215,
4426,
402,
900,
3967,
2061,
2218,
272,
1830,
715,
26,
267,
327,
3086,
1804,
14961,
1414,
687,
8495,
2988,
267,
340,
440,
2004,
63,
1825,
14,
1667,
837,
288,
2004,
63,
1825,
14,
362,
342,
288,
6771,
14,
1600,
342,
288,
366,
6322,
63,
1825,
8,
5096,
14,
1825,
12,
3522,
12,
1592,
12,
7055,
12,
2512,
9,
288,
2059,
398,
327,
949,
1414,
367,
3063,
1035,
9435,
370,
5126,
4837,
71,
1540,
11952,
641,
14592,
664,
267,
340,
6771,
14,
1825,
14,
1667,
837,
288,
900,
14,
4532,
8,
16,
14,
17,
9,
953,
327,
5532,
4036,
24187,
4696,
370,
5126,
14592,
314,
1592,
367,
4634,
1846,
288,
340,
7055,
690,
378,
436,
900,
14,
521,
342,
446,
5532,
63,
521,
690,
959,
26,
355,
3522,
14,
952,
342,
355,
3522,
275,
1592,
14,
952,
63,
2912,
342,
288,
1980,
398,
327,
2112,
2777,
267,
2884,
275,
6771,
14,
1825,
14,
362,
342,
267,
7055,
275,
2112,
63,
1579,
8,
1579,
12,
3522,
12,
1592,
12,
7055,
12,
2512,
9,
398,
327,
3522,
5532,
340,
5784,
267,
340,
7055,
2356,
3522,
63,
890,
26,
288,
7055,
275,
378,
288,
5532,
63,
521,
275,
900,
14,
521,
342,
288,
3522,
14,
952,
342,
288,
3522,
275,
1592,
14,
952,
63,
2912,
342,
339,
327,
9578,
397,
1736,
436,
19756,
5836,
20922,
272,
3522,
14,
952,
342,
272,
1592,
14,
1600,
342,
199,
199,
318,
2112,
63,
1579,
8,
1579,
12,
3522,
12,
1592,
12,
7055,
12,
2512,
304,
272,
408,
272,
9584,
282,
2884,
370,
314,
3522,
272,
408,
272,
327,
16101,
2884,
367,
477,
11048,
1863,
641,
4543,
272,
19009,
275,
1134,
2227,
14,
31006,
19,
63,
88,
772,
63,
3933,
342,
272,
2884,
63,
2227,
275,
620,
8,
28885,
8,
1579,
9,
4331,
5049,
9,
339,
340,
1592,
14,
362,
8,
1579,
63,
2227,
9,
365,
440,
488,
26,
267,
372,
7055,
339,
12335,
63,
1579,
275,
12472,
14,
6447,
8,
1579,
9,
339,
3522,
14,
524,
8,
1579,
63,
2227,
12,
12335,
63,
1579,
9,
272,
372,
7055,
435,
413,
199,
199,
318,
366,
6322,
63,
1825,
8,
5096,
63,
1825,
12,
3522,
12,
1592,
12,
7055,
12,
2512,
304,
272,
408,
29652,
4126,
365,
2701,
2544,
11261,
408,
272,
900,
14,
4532,
8,
19,
9,
221,
327,
3254,
26,
314,
2838,
4839,
282,
8034,
4340,
402,
11261,
272,
1830,
440,
6771,
63,
1825,
14,
1667,
837,
267,
2884,
275,
6771,
63,
1825,
14,
362,
342,
267,
7055,
275,
2112,
63,
1579,
8,
1579,
12,
3522,
12,
1592,
12,
7055,
12,
2512,
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
] |
[
2508,
3869,
4267,
492,
1654,
3450,
199,
504,
2508,
1658,
4455,
492,
2050,
1258,
199,
646,
299,
590,
1090,
199,
646,
1134,
2227,
199,
646,
12472,
199,
646,
900,
199,
646,
747,
421,
199,
318,
20400,
2846,
23933,
8,
2609,
63,
1162,
12,
2004,
63,
1825,
12,
3522,
63,
890,
29,
1960,
304,
272,
408,
1362,
799,
2375,
397,
665,
498,
12,
574,
30,
6342,
687,
1163,
10358,
436,
14511,
3062,
370,
314,
18796,
3050,
14,
1362,
9434,
3862,
9212,
5133,
3769,
370,
1447,
370,
18833,
334,
12726,
652,
911,
9578,
1736,
436,
24761,
3224,
680,
1362,
961,
2112,
1077,
7078,
506,
15745,
625,
13,
20631,
5836,
14,
10813,
665,
2609,
63,
1162,
30,
8495,
2988,
2897,
2633,
1362,
665,
1205,
63,
1825,
30,
365,
282,
4126,
4907,
370,
314,
8495,
2988,
1202,
367,
23506,
1362,
665,
2912,
63,
890,
30,
365,
314,
1568,
402,
314,
2218,
3522,
272,
408,
339,
327,
5951,
1536,
2050,
1950,
272,
2512,
275,
2050,
1258,
2031,
2609,
63,
1162,
459,
2921,
63,
1562,
1105,
339,
327,
5951,
1536,
314,
1654,
3450,
370,
1343,
32163,
6947,
272,
6771,
275,
1654,
3450,
342,
272,
2004,
63,
1825,
14,
524,
8,
5096,
14,
5096,
14,
27886,
1012,
221,
327,
4691,
377,
45,
5715,
2909,
272,
6771,
14,
928,
63,
5694,
316,
342,
339,
327,
5951,
1536,
6249,
1950,
272,
1592,
63,
515,
275,
747,
14,
515,
14,
904,
8,
2609,
63,
1162,
459,
576,
63,
3619,
995,
283,
9554,
14,
15793,
358,
272,
1592,
275,
299,
590,
1090,
14,
2846,
8,
697,
63,
515,
12,
288,
1218,
63,
692,
63,
4752,
275,
715,
12,
288,
634,
6558,
63,
1637,
63,
890,
275,
1616,
538,
25,
12,
288,
2218,
63,
2738,
63,
890,
275,
7960,
10,
709,
538,
20,
12,
288,
10291,
275,
488,
9,
272,
3522,
275,
1592,
14,
952,
63,
2912,
342,
339,
7055,
275,
378,
221,
327,
1329,
402,
2146,
8653,
6326,
3967,
2061,
2218,
272,
5532,
63,
521,
275,
378,
221,
327,
4215,
4426,
402,
900,
3967,
2061,
2218,
272,
1830,
715,
26,
267,
327,
3086,
1804,
14961,
1414,
687,
8495,
2988,
267,
340,
440,
2004,
63,
1825,
14,
1667,
837,
288,
2004,
63,
1825,
14,
362,
342,
288,
6771,
14,
1600,
342,
288,
366,
6322,
63,
1825,
8,
5096,
14,
1825,
12,
3522,
12,
1592,
12,
7055,
12,
2512,
9,
288,
2059,
398,
327,
949,
1414,
367,
3063,
1035,
9435,
370,
5126,
4837,
71,
1540,
11952,
641,
14592,
664,
267,
340,
6771,
14,
1825,
14,
1667,
837,
288,
900,
14,
4532,
8,
16,
14,
17,
9,
953,
327,
5532,
4036,
24187,
4696,
370,
5126,
14592,
314,
1592,
367,
4634,
1846,
288,
340,
7055,
690,
378,
436,
900,
14,
521,
342,
446,
5532,
63,
521,
690,
959,
26,
355,
3522,
14,
952,
342,
355,
3522,
275,
1592,
14,
952,
63,
2912,
342,
288,
1980,
398,
327,
2112,
2777,
267,
2884,
275,
6771,
14,
1825,
14,
362,
342,
267,
7055,
275,
2112,
63,
1579,
8,
1579,
12,
3522,
12,
1592,
12,
7055,
12,
2512,
9,
398,
327,
3522,
5532,
340,
5784,
267,
340,
7055,
2356,
3522,
63,
890,
26,
288,
7055,
275,
378,
288,
5532,
63,
521,
275,
900,
14,
521,
342,
288,
3522,
14,
952,
342,
288,
3522,
275,
1592,
14,
952,
63,
2912,
342,
339,
327,
9578,
397,
1736,
436,
19756,
5836,
20922,
272,
3522,
14,
952,
342,
272,
1592,
14,
1600,
342,
199,
199,
318,
2112,
63,
1579,
8,
1579,
12,
3522,
12,
1592,
12,
7055,
12,
2512,
304,
272,
408,
272,
9584,
282,
2884,
370,
314,
3522,
272,
408,
272,
327,
16101,
2884,
367,
477,
11048,
1863,
641,
4543,
272,
19009,
275,
1134,
2227,
14,
31006,
19,
63,
88,
772,
63,
3933,
342,
272,
2884,
63,
2227,
275,
620,
8,
28885,
8,
1579,
9,
4331,
5049,
9,
339,
340,
1592,
14,
362,
8,
1579,
63,
2227,
9,
365,
440,
488,
26,
267,
372,
7055,
339,
12335,
63,
1579,
275,
12472,
14,
6447,
8,
1579,
9,
339,
3522,
14,
524,
8,
1579,
63,
2227,
12,
12335,
63,
1579,
9,
272,
372,
7055,
435,
413,
199,
199,
318,
366,
6322,
63,
1825,
8,
5096,
63,
1825,
12,
3522,
12,
1592,
12,
7055,
12,
2512,
304,
272,
408,
29652,
4126,
365,
2701,
2544,
11261,
408,
272,
900,
14,
4532,
8,
19,
9,
221,
327,
3254,
26,
314,
2838,
4839,
282,
8034,
4340,
402,
11261,
272,
1830,
440,
6771,
63,
1825,
14,
1667,
837,
267,
2884,
275,
6771,
63,
1825,
14,
362,
342,
267,
7055,
275,
2112,
63,
1579,
8,
1579,
12,
3522,
12,
1592,
12,
7055,
12,
2512,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
philippjfr/bokeh
|
bokeh/models/graphs.py
|
4
|
3109
|
from ..core.has_props import abstract
from ..core.properties import Any, Dict, Either, Int, Seq, String
from ..model import Model
from ..models.sources import ColumnDataSource
@abstract
class LayoutProvider(Model):
'''
'''
pass
class StaticLayoutProvider(LayoutProvider):
'''
'''
graph_layout = Dict(Either(String, Int), Seq(Any), default={}, help="""
The coordinates of the graph nodes in cartesian space. The dictionary
keys correspond to a node index and the values are a two element sequence
containing the x and y coordinates of the node.
.. code-block:: python
{
0 : [0.5, 0.5],
1 : [1.0, 0.86],
2 : [0.86, 1],
}
""")
def from_networkx(graph, layout_function, **kwargs):
'''
Generate a GraphRenderer from a networkx.Graph object and networkx
layout function. Any keyword arguments will be passed to the
layout function.
Args:
graph (networkx.Graph) : a networkx graph to render
layout_function (function) : a networkx layout function
Returns:
instance (GraphRenderer)
.. warning::
Only two dimensional layouts are currently supported.
'''
# inline import to prevent circular imports
from ..models.renderers import GraphRenderer
from ..models.graphs import StaticLayoutProvider
# Handles nx 1.x vs 2.x data structure change
nodes = list(graph.nodes())
edges = list(graph.edges())
edges_start = [edge[0] for edge in edges]
edges_end = [edge[1] for edge in edges]
node_source = ColumnDataSource(data=dict(index=nodes))
edge_source = ColumnDataSource(data=dict(
start=edges_start,
end=edges_end
))
graph_renderer = GraphRenderer()
graph_renderer.node_renderer.data_source.data = node_source.data
graph_renderer.edge_renderer.data_source.data = edge_source.data
graph_layout = layout_function(graph, **kwargs)
graph_renderer.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)
return graph_renderer
@abstract
class GraphHitTestPolicy(Model):
'''
'''
pass
class NodesOnly(GraphHitTestPolicy):
'''
With the NodesOnly policy, only graph nodes are able to be selected and
inspected. There is no selection or inspection of graph edges.
'''
pass
class NodesAndLinkedEdges(GraphHitTestPolicy):
'''
With the NodesAndLinkedEdges policy, inspection or selection of graph
nodes will result in the inspection or selection of the node and of the
linked graph edges. There is no direct selection or inspection of graph
edges.
'''
pass
class EdgesAndLinkedNodes(GraphHitTestPolicy):
'''
With the EdgesAndLinkedNodes policy, inspection or selection of graph
edges will result in the inspection or selection of the edge and of the
linked graph nodes. There is no direct selection or inspection of graph
nodes.
'''
pass
|
bsd-3-clause
|
[
504,
2508,
1018,
14,
1989,
63,
6750,
492,
9006,
199,
504,
2508,
1018,
14,
3282,
492,
6184,
12,
7448,
12,
13083,
12,
9805,
12,
28534,
12,
2624,
199,
504,
2508,
1238,
492,
5822,
199,
504,
2508,
992,
14,
4553,
492,
4996,
16693,
421,
199,
32,
6198,
199,
533,
25604,
6663,
8,
1685,
304,
272,
1449,
339,
1449,
339,
986,
421,
199,
533,
13599,
4798,
6663,
8,
4798,
6663,
304,
272,
1449,
339,
1449,
339,
3343,
63,
4209,
275,
7448,
8,
37,
1711,
8,
1558,
12,
9805,
395,
28534,
8,
9874,
395,
849,
10324,
1720,
11916,
272,
710,
8983,
402,
314,
3343,
3380,
315,
9590,
19157,
4601,
14,
710,
2600,
272,
2883,
17118,
370,
282,
1031,
1478,
436,
314,
1338,
787,
282,
2877,
1819,
3414,
272,
3035,
314,
671,
436,
612,
8983,
402,
314,
1031,
14,
339,
2508,
1233,
13,
1457,
447,
2366,
398,
469,
288,
378,
520,
359,
16,
14,
21,
12,
378,
14,
21,
467,
288,
413,
520,
359,
17,
14,
16,
12,
378,
14,
1184,
467,
288,
499,
520,
359,
16,
14,
1184,
12,
413,
467,
267,
789,
272,
7857,
199,
199,
318,
687,
63,
1200,
88,
8,
2180,
12,
7054,
63,
1593,
12,
1011,
958,
304,
267,
1449,
267,
7958,
282,
11513,
11355,
687,
282,
24313,
14,
4578,
909,
436,
24313,
267,
7054,
805,
14,
6184,
4252,
2368,
911,
506,
3032,
370,
314,
267,
7054,
805,
14,
398,
3033,
26,
288,
3343,
334,
1200,
88,
14,
4578,
9,
520,
282,
24313,
3343,
370,
3795,
288,
7054,
63,
1593,
334,
1593,
9,
520,
282,
24313,
7054,
805,
398,
1803,
26,
288,
1256,
334,
4578,
11355,
9,
398,
2508,
5721,
447,
288,
5972,
2877,
28341,
7054,
83,
787,
5544,
3748,
14,
398,
1449,
398,
327,
8308,
492,
370,
7981,
15032,
8925,
267,
687,
2508,
992,
14,
828,
26529,
492,
11513,
11355,
267,
687,
2508,
992,
14,
16670,
492,
13599,
4798,
6663,
398,
327,
23873,
8484,
413,
14,
88,
8118,
499,
14,
88,
666,
5523,
1570,
267,
3380,
275,
769,
8,
2180,
14,
2415,
1012,
267,
8207,
275,
769,
8,
2180,
14,
6929,
1012,
398,
8207,
63,
928,
275,
359,
5173,
59,
16,
61,
367,
6275,
315,
8207,
61,
267,
8207,
63,
500,
275,
359,
5173,
59,
17,
61,
367,
6275,
315,
8207,
61,
398,
1031,
63,
1365,
275,
4996,
16693,
8,
576,
29,
807,
8,
1080,
29,
2415,
430,
267,
6275,
63,
1365,
275,
4996,
16693,
8,
576,
29,
807,
8,
288,
1343,
29,
6929,
63,
928,
12,
288,
1284,
29,
6929,
63,
500,
267,
5082,
398,
3343,
63,
12471,
275,
11513,
11355,
342,
267,
3343,
63,
12471,
14,
932,
63,
12471,
14,
576,
63,
1365,
14,
576,
275,
1031,
63,
1365,
14,
576,
267,
3343,
63,
12471,
14,
5173,
63,
12471,
14,
576,
63,
1365,
14,
576,
275,
6275,
63,
1365,
14,
576,
398,
3343,
63,
4209,
275,
7054,
63,
1593,
8,
2180,
12,
1011,
958,
9,
267,
3343,
63,
12471,
14,
4209,
63,
3780,
275,
13599,
4798,
6663,
8,
2180,
63,
4209,
29,
2180,
63,
4209,
9,
398,
372,
3343,
63,
12471,
421,
199,
32,
6198,
199,
533,
11513,
26852,
774,
4845,
8,
1685,
304,
272,
1449,
339,
1449,
339,
986,
421,
199,
533,
23836,
5903,
8,
4578,
26852,
774,
4845,
304,
272,
1449,
272,
8777,
314,
23836,
5903,
4592,
12,
1454,
3343,
3380,
787,
7688,
370,
506,
4895,
436,
272,
5261,
1043,
14,
6006,
365,
949,
7267,
503,
5261,
10303,
402,
3343,
8207,
14,
339,
1449,
339,
986,
199,
199,
533,
23836,
3325,
26748,
24121,
8,
4578,
26852,
774,
4845,
304,
272,
1449,
272,
8777,
314,
23836,
3325,
26748,
24121,
4592,
12,
5261,
10303,
503,
7267,
402,
3343,
272,
3380,
911,
754,
315,
314,
5261,
10303,
503,
7267,
402,
314,
1031,
436,
402,
314,
272,
10632,
3343,
8207,
14,
6006,
365,
949,
4125,
7267,
503,
5261,
10303,
402,
3343,
272,
8207,
14,
339,
1449,
339,
986,
199,
199,
533,
17379,
3389,
3325,
26748,
6300,
8,
4578,
26852,
774,
4845,
304,
272,
1449,
272,
8777,
314,
17379,
3389,
3325,
26748,
6300,
4592,
12,
5261,
10303,
503,
7267,
402,
3343,
272,
8207,
911,
754,
315,
314,
5261,
10303,
503,
7267,
402,
314,
6275,
436,
402,
314,
272,
10632,
3343,
3380,
14,
6006,
365,
949,
4125,
7267,
503,
5261,
10303,
402,
3343,
272,
3380,
14,
339,
1449,
339,
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
] |
[
2508,
1018,
14,
1989,
63,
6750,
492,
9006,
199,
504,
2508,
1018,
14,
3282,
492,
6184,
12,
7448,
12,
13083,
12,
9805,
12,
28534,
12,
2624,
199,
504,
2508,
1238,
492,
5822,
199,
504,
2508,
992,
14,
4553,
492,
4996,
16693,
421,
199,
32,
6198,
199,
533,
25604,
6663,
8,
1685,
304,
272,
1449,
339,
1449,
339,
986,
421,
199,
533,
13599,
4798,
6663,
8,
4798,
6663,
304,
272,
1449,
339,
1449,
339,
3343,
63,
4209,
275,
7448,
8,
37,
1711,
8,
1558,
12,
9805,
395,
28534,
8,
9874,
395,
849,
10324,
1720,
11916,
272,
710,
8983,
402,
314,
3343,
3380,
315,
9590,
19157,
4601,
14,
710,
2600,
272,
2883,
17118,
370,
282,
1031,
1478,
436,
314,
1338,
787,
282,
2877,
1819,
3414,
272,
3035,
314,
671,
436,
612,
8983,
402,
314,
1031,
14,
339,
2508,
1233,
13,
1457,
447,
2366,
398,
469,
288,
378,
520,
359,
16,
14,
21,
12,
378,
14,
21,
467,
288,
413,
520,
359,
17,
14,
16,
12,
378,
14,
1184,
467,
288,
499,
520,
359,
16,
14,
1184,
12,
413,
467,
267,
789,
272,
7857,
199,
199,
318,
687,
63,
1200,
88,
8,
2180,
12,
7054,
63,
1593,
12,
1011,
958,
304,
267,
1449,
267,
7958,
282,
11513,
11355,
687,
282,
24313,
14,
4578,
909,
436,
24313,
267,
7054,
805,
14,
6184,
4252,
2368,
911,
506,
3032,
370,
314,
267,
7054,
805,
14,
398,
3033,
26,
288,
3343,
334,
1200,
88,
14,
4578,
9,
520,
282,
24313,
3343,
370,
3795,
288,
7054,
63,
1593,
334,
1593,
9,
520,
282,
24313,
7054,
805,
398,
1803,
26,
288,
1256,
334,
4578,
11355,
9,
398,
2508,
5721,
447,
288,
5972,
2877,
28341,
7054,
83,
787,
5544,
3748,
14,
398,
1449,
398,
327,
8308,
492,
370,
7981,
15032,
8925,
267,
687,
2508,
992,
14,
828,
26529,
492,
11513,
11355,
267,
687,
2508,
992,
14,
16670,
492,
13599,
4798,
6663,
398,
327,
23873,
8484,
413,
14,
88,
8118,
499,
14,
88,
666,
5523,
1570,
267,
3380,
275,
769,
8,
2180,
14,
2415,
1012,
267,
8207,
275,
769,
8,
2180,
14,
6929,
1012,
398,
8207,
63,
928,
275,
359,
5173,
59,
16,
61,
367,
6275,
315,
8207,
61,
267,
8207,
63,
500,
275,
359,
5173,
59,
17,
61,
367,
6275,
315,
8207,
61,
398,
1031,
63,
1365,
275,
4996,
16693,
8,
576,
29,
807,
8,
1080,
29,
2415,
430,
267,
6275,
63,
1365,
275,
4996,
16693,
8,
576,
29,
807,
8,
288,
1343,
29,
6929,
63,
928,
12,
288,
1284,
29,
6929,
63,
500,
267,
5082,
398,
3343,
63,
12471,
275,
11513,
11355,
342,
267,
3343,
63,
12471,
14,
932,
63,
12471,
14,
576,
63,
1365,
14,
576,
275,
1031,
63,
1365,
14,
576,
267,
3343,
63,
12471,
14,
5173,
63,
12471,
14,
576,
63,
1365,
14,
576,
275,
6275,
63,
1365,
14,
576,
398,
3343,
63,
4209,
275,
7054,
63,
1593,
8,
2180,
12,
1011,
958,
9,
267,
3343,
63,
12471,
14,
4209,
63,
3780,
275,
13599,
4798,
6663,
8,
2180,
63,
4209,
29,
2180,
63,
4209,
9,
398,
372,
3343,
63,
12471,
421,
199,
32,
6198,
199,
533,
11513,
26852,
774,
4845,
8,
1685,
304,
272,
1449,
339,
1449,
339,
986,
421,
199,
533,
23836,
5903,
8,
4578,
26852,
774,
4845,
304,
272,
1449,
272,
8777,
314,
23836,
5903,
4592,
12,
1454,
3343,
3380,
787,
7688,
370,
506,
4895,
436,
272,
5261,
1043,
14,
6006,
365,
949,
7267,
503,
5261,
10303,
402,
3343,
8207,
14,
339,
1449,
339,
986,
199,
199,
533,
23836,
3325,
26748,
24121,
8,
4578,
26852,
774,
4845,
304,
272,
1449,
272,
8777,
314,
23836,
3325,
26748,
24121,
4592,
12,
5261,
10303,
503,
7267,
402,
3343,
272,
3380,
911,
754,
315,
314,
5261,
10303,
503,
7267,
402,
314,
1031,
436,
402,
314,
272,
10632,
3343,
8207,
14,
6006,
365,
949,
4125,
7267,
503,
5261,
10303,
402,
3343,
272,
8207,
14,
339,
1449,
339,
986,
199,
199,
533,
17379,
3389,
3325,
26748,
6300,
8,
4578,
26852,
774,
4845,
304,
272,
1449,
272,
8777,
314,
17379,
3389,
3325,
26748,
6300,
4592,
12,
5261,
10303,
503,
7267,
402,
3343,
272,
8207,
911,
754,
315,
314,
5261,
10303,
503,
7267,
402,
314,
6275,
436,
402,
314,
272,
10632,
3343,
3380,
14,
6006,
365,
949,
4125,
7267,
503,
5261,
10303,
402,
3343,
272,
3380,
14,
339,
1449,
339,
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,
0
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,
0
] |
petteyg/intellij-community
|
python/helpers/pydev/third_party/wrapped_for_pydev/ctypes/macholib/framework.py
|
320
|
2201
|
"""
Generic framework path manipulation
"""
import re
__all__ = ['framework_info']
STRICT_FRAMEWORK_RE = re.compile(r"""(?x)
(?P<location>^.*)(?:^|/)
(?P<name>
(?P<shortname>\w+).framework/
(?:Versions/(?P<version>[^/]+)/)?
(?P=shortname)
(?:_(?P<suffix>[^_]+))?
)$
""")
def framework_info(filename):
"""
A framework name can take one of the following four forms:
Location/Name.framework/Versions/SomeVersion/Name_Suffix
Location/Name.framework/Versions/SomeVersion/Name
Location/Name.framework/Name_Suffix
Location/Name.framework/Name
returns None if not found, or a mapping equivalent to:
dict(
location='Location',
name='Name.framework/Versions/SomeVersion/Name_Suffix',
shortname='Name',
version='SomeVersion',
suffix='Suffix',
)
Note that SomeVersion and Suffix are optional and may be None
if not present
"""
is_framework = STRICT_FRAMEWORK_RE.match(filename)
if not is_framework:
return None
return is_framework.groupdict()
def test_framework_info():
def d(location=None, name=None, shortname=None, version=None, suffix=None):
return dict(
location=location,
name=name,
shortname=shortname,
version=version,
suffix=suffix
)
assert framework_info('completely/invalid') is None
assert framework_info('completely/invalid/_debug') is None
assert framework_info('P/F.framework') is None
assert framework_info('P/F.framework/_debug') is None
assert framework_info('P/F.framework/F') == d('P', 'F.framework/F', 'F')
assert framework_info('P/F.framework/F_debug') == d('P', 'F.framework/F_debug', 'F', suffix='debug')
assert framework_info('P/F.framework/Versions') is None
assert framework_info('P/F.framework/Versions/A') is None
assert framework_info('P/F.framework/Versions/A/F') == d('P', 'F.framework/Versions/A/F', 'F', 'A')
assert framework_info('P/F.framework/Versions/A/F_debug') == d('P', 'F.framework/Versions/A/F_debug', 'F', 'A', 'debug')
if __name__ == '__main__':
test_framework_info()
|
apache-2.0
|
[
624,
199,
9417,
10059,
931,
26212,
199,
624,
199,
199,
646,
295,
199,
199,
363,
452,
363,
275,
788,
4857,
63,
815,
418,
199,
199,
3027,
6196,
63,
12683,
8406,
63,
907,
275,
295,
14,
2014,
8,
82,
624,
2229,
88,
9,
199,
2229,
48,
28,
1985,
30,
62,
12432,
5169,
62,
92,
24793,
199,
2229,
48,
28,
354,
30,
272,
7558,
48,
28,
3612,
354,
3072,
87,
11,
680,
4857,
15,
272,
16697,
21167,
9448,
48,
28,
1023,
26906,
2447,
5547,
272,
7558,
48,
29,
3612,
354,
9,
272,
16697,
63,
2229,
48,
28,
4511,
13489,
22155,
22119,
199,
9,
4,
199,
6141,
199,
199,
318,
10059,
63,
815,
8,
1501,
304,
272,
408,
272,
437,
10059,
536,
883,
5452,
1373,
402,
314,
2569,
11648,
4513,
26,
267,
12625,
15,
985,
14,
4857,
15,
21167,
15,
7700,
3353,
15,
985,
63,
20126,
267,
12625,
15,
985,
14,
4857,
15,
21167,
15,
7700,
3353,
15,
985,
267,
12625,
15,
985,
14,
4857,
15,
985,
63,
20126,
267,
12625,
15,
985,
14,
4857,
15,
985,
339,
2529,
488,
340,
440,
1911,
12,
503,
282,
4412,
7353,
370,
26,
267,
1211,
8,
288,
2909,
534,
6592,
297,
288,
536,
534,
985,
14,
4857,
15,
21167,
15,
7700,
3353,
15,
985,
63,
20126,
297,
288,
3974,
354,
534,
985,
297,
288,
1015,
534,
7700,
3353,
297,
288,
4739,
534,
20126,
297,
267,
776,
339,
3390,
626,
6601,
3353,
436,
428,
2875,
787,
2716,
436,
1443,
506,
488,
272,
340,
440,
3451,
272,
408,
272,
365,
63,
4857,
275,
9644,
63,
12683,
8406,
63,
907,
14,
1431,
8,
1501,
9,
272,
340,
440,
365,
63,
4857,
26,
267,
372,
488,
272,
372,
365,
63,
4857,
14,
20567,
342,
199,
199,
318,
511,
63,
4857,
63,
815,
837,
272,
347,
366,
8,
1985,
29,
403,
12,
536,
29,
403,
12,
3974,
354,
29,
403,
12,
1015,
29,
403,
12,
4739,
29,
403,
304,
267,
372,
1211,
8,
288,
2909,
29,
1985,
12,
288,
536,
29,
354,
12,
288,
3974,
354,
29,
3612,
354,
12,
288,
1015,
29,
1023,
12,
288,
4739,
29,
4511,
267,
776,
272,
702,
10059,
63,
815,
360,
4883,
590,
15,
3197,
358,
365,
488,
272,
702,
10059,
63,
815,
360,
4883,
590,
15,
3197,
15607,
1757,
358,
365,
488,
272,
702,
10059,
63,
815,
360,
48,
15,
38,
14,
4857,
358,
365,
488,
272,
702,
10059,
63,
815,
360,
48,
15,
38,
14,
4857,
15607,
1757,
358,
365,
488,
272,
702,
10059,
63,
815,
360,
48,
15,
38,
14,
4857,
15,
38,
358,
508,
366,
360,
48,
297,
283,
38,
14,
4857,
15,
38,
297,
283,
38,
358,
272,
702,
10059,
63,
815,
360,
48,
15,
38,
14,
4857,
15,
38,
63,
1757,
358,
508,
366,
360,
48,
297,
283,
38,
14,
4857,
15,
38,
63,
1757,
297,
283,
38,
297,
4739,
534,
1757,
358,
272,
702,
10059,
63,
815,
360,
48,
15,
38,
14,
4857,
15,
21167,
358,
365,
488,
272,
702,
10059,
63,
815,
360,
48,
15,
38,
14,
4857,
15,
21167,
15,
33,
358,
365,
488,
272,
702,
10059,
63,
815,
360,
48,
15,
38,
14,
4857,
15,
21167,
15,
33,
15,
38,
358,
508,
366,
360,
48,
297,
283,
38,
14,
4857,
15,
21167,
15,
33,
15,
38,
297,
283,
38,
297,
283,
33,
358,
272,
702,
10059,
63,
815,
360,
48,
15,
38,
14,
4857,
15,
21167,
15,
33,
15,
38,
63,
1757,
358,
508,
366,
360,
48,
297,
283,
38,
14,
4857,
15,
21167,
15,
33,
15,
38,
63,
1757,
297,
283,
38,
297,
283,
33,
297,
283,
1757,
358,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
511,
63,
4857,
63,
815,
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
] |
[
199,
9417,
10059,
931,
26212,
199,
624,
199,
199,
646,
295,
199,
199,
363,
452,
363,
275,
788,
4857,
63,
815,
418,
199,
199,
3027,
6196,
63,
12683,
8406,
63,
907,
275,
295,
14,
2014,
8,
82,
624,
2229,
88,
9,
199,
2229,
48,
28,
1985,
30,
62,
12432,
5169,
62,
92,
24793,
199,
2229,
48,
28,
354,
30,
272,
7558,
48,
28,
3612,
354,
3072,
87,
11,
680,
4857,
15,
272,
16697,
21167,
9448,
48,
28,
1023,
26906,
2447,
5547,
272,
7558,
48,
29,
3612,
354,
9,
272,
16697,
63,
2229,
48,
28,
4511,
13489,
22155,
22119,
199,
9,
4,
199,
6141,
199,
199,
318,
10059,
63,
815,
8,
1501,
304,
272,
408,
272,
437,
10059,
536,
883,
5452,
1373,
402,
314,
2569,
11648,
4513,
26,
267,
12625,
15,
985,
14,
4857,
15,
21167,
15,
7700,
3353,
15,
985,
63,
20126,
267,
12625,
15,
985,
14,
4857,
15,
21167,
15,
7700,
3353,
15,
985,
267,
12625,
15,
985,
14,
4857,
15,
985,
63,
20126,
267,
12625,
15,
985,
14,
4857,
15,
985,
339,
2529,
488,
340,
440,
1911,
12,
503,
282,
4412,
7353,
370,
26,
267,
1211,
8,
288,
2909,
534,
6592,
297,
288,
536,
534,
985,
14,
4857,
15,
21167,
15,
7700,
3353,
15,
985,
63,
20126,
297,
288,
3974,
354,
534,
985,
297,
288,
1015,
534,
7700,
3353,
297,
288,
4739,
534,
20126,
297,
267,
776,
339,
3390,
626,
6601,
3353,
436,
428,
2875,
787,
2716,
436,
1443,
506,
488,
272,
340,
440,
3451,
272,
408,
272,
365,
63,
4857,
275,
9644,
63,
12683,
8406,
63,
907,
14,
1431,
8,
1501,
9,
272,
340,
440,
365,
63,
4857,
26,
267,
372,
488,
272,
372,
365,
63,
4857,
14,
20567,
342,
199,
199,
318,
511,
63,
4857,
63,
815,
837,
272,
347,
366,
8,
1985,
29,
403,
12,
536,
29,
403,
12,
3974,
354,
29,
403,
12,
1015,
29,
403,
12,
4739,
29,
403,
304,
267,
372,
1211,
8,
288,
2909,
29,
1985,
12,
288,
536,
29,
354,
12,
288,
3974,
354,
29,
3612,
354,
12,
288,
1015,
29,
1023,
12,
288,
4739,
29,
4511,
267,
776,
272,
702,
10059,
63,
815,
360,
4883,
590,
15,
3197,
358,
365,
488,
272,
702,
10059,
63,
815,
360,
4883,
590,
15,
3197,
15607,
1757,
358,
365,
488,
272,
702,
10059,
63,
815,
360,
48,
15,
38,
14,
4857,
358,
365,
488,
272,
702,
10059,
63,
815,
360,
48,
15,
38,
14,
4857,
15607,
1757,
358,
365,
488,
272,
702,
10059,
63,
815,
360,
48,
15,
38,
14,
4857,
15,
38,
358,
508,
366,
360,
48,
297,
283,
38,
14,
4857,
15,
38,
297,
283,
38,
358,
272,
702,
10059,
63,
815,
360,
48,
15,
38,
14,
4857,
15,
38,
63,
1757,
358,
508,
366,
360,
48,
297,
283,
38,
14,
4857,
15,
38,
63,
1757,
297,
283,
38,
297,
4739,
534,
1757,
358,
272,
702,
10059,
63,
815,
360,
48,
15,
38,
14,
4857,
15,
21167,
358,
365,
488,
272,
702,
10059,
63,
815,
360,
48,
15,
38,
14,
4857,
15,
21167,
15,
33,
358,
365,
488,
272,
702,
10059,
63,
815,
360,
48,
15,
38,
14,
4857,
15,
21167,
15,
33,
15,
38,
358,
508,
366,
360,
48,
297,
283,
38,
14,
4857,
15,
21167,
15,
33,
15,
38,
297,
283,
38,
297,
283,
33,
358,
272,
702,
10059,
63,
815,
360,
48,
15,
38,
14,
4857,
15,
21167,
15,
33,
15,
38,
63,
1757,
358,
508,
366,
360,
48,
297,
283,
38,
14,
4857,
15,
21167,
15,
33,
15,
38,
63,
1757,
297,
283,
38,
297,
283,
33,
297,
283,
1757,
358,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
511,
63,
4857,
63,
815,
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,
32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
0,
0,
0,
0,
0,
0,
0
] |
bradsk88/WinkHouse
|
lib/jinja2/filters.py
|
329
|
30115
|
# -*- coding: utf-8 -*-
"""
jinja2.filters
~~~~~~~~~~~~~~
Bundled jinja filters.
:copyright: (c) 2010 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
import re
import math
from random import choice
from operator import itemgetter
from itertools import groupby
from jinja2.utils import Markup, escape, pformat, urlize, soft_unicode, \
unicode_urlencode
from jinja2.runtime import Undefined
from jinja2.exceptions import FilterArgumentError
from jinja2._compat import imap, string_types, text_type, iteritems
_word_re = re.compile(r'\w+(?u)')
def contextfilter(f):
"""Decorator for marking context dependent filters. The current
:class:`Context` will be passed as first argument.
"""
f.contextfilter = True
return f
def evalcontextfilter(f):
"""Decorator for marking eval-context dependent filters. An eval
context object is passed as first argument. For more information
about the eval context, see :ref:`eval-context`.
.. versionadded:: 2.4
"""
f.evalcontextfilter = True
return f
def environmentfilter(f):
"""Decorator for marking evironment dependent filters. The current
:class:`Environment` is passed to the filter as first argument.
"""
f.environmentfilter = True
return f
def make_attrgetter(environment, attribute):
"""Returns a callable that looks up the given attribute from a
passed object with the rules of the environment. Dots are allowed
to access attributes of attributes. Integer parts in paths are
looked up as integers.
"""
if not isinstance(attribute, string_types) \
or ('.' not in attribute and not attribute.isdigit()):
return lambda x: environment.getitem(x, attribute)
attribute = attribute.split('.')
def attrgetter(item):
for part in attribute:
if part.isdigit():
part = int(part)
item = environment.getitem(item, part)
return item
return attrgetter
def do_forceescape(value):
"""Enforce HTML escaping. This will probably double escape variables."""
if hasattr(value, '__html__'):
value = value.__html__()
return escape(text_type(value))
def do_urlencode(value):
"""Escape strings for use in URLs (uses UTF-8 encoding). It accepts both
dictionaries and regular strings as well as pairwise iterables.
.. versionadded:: 2.7
"""
itemiter = None
if isinstance(value, dict):
itemiter = iteritems(value)
elif not isinstance(value, string_types):
try:
itemiter = iter(value)
except TypeError:
pass
if itemiter is None:
return unicode_urlencode(value)
return u'&'.join(unicode_urlencode(k) + '=' +
unicode_urlencode(v, for_qs=True)
for k, v in itemiter)
@evalcontextfilter
def do_replace(eval_ctx, s, old, new, count=None):
"""Return a copy of the value with all occurrences of a substring
replaced with a new one. The first argument is the substring
that should be replaced, the second is the replacement string.
If the optional third argument ``count`` is given, only the first
``count`` occurrences are replaced:
.. sourcecode:: jinja
{{ "Hello World"|replace("Hello", "Goodbye") }}
-> Goodbye World
{{ "aaaaargh"|replace("a", "d'oh, ", 2) }}
-> d'oh, d'oh, aaargh
"""
if count is None:
count = -1
if not eval_ctx.autoescape:
return text_type(s).replace(text_type(old), text_type(new), count)
if hasattr(old, '__html__') or hasattr(new, '__html__') and \
not hasattr(s, '__html__'):
s = escape(s)
else:
s = soft_unicode(s)
return s.replace(soft_unicode(old), soft_unicode(new), count)
def do_upper(s):
"""Convert a value to uppercase."""
return soft_unicode(s).upper()
def do_lower(s):
"""Convert a value to lowercase."""
return soft_unicode(s).lower()
@evalcontextfilter
def do_xmlattr(_eval_ctx, d, autospace=True):
"""Create an SGML/XML attribute string based on the items in a dict.
All values that are neither `none` nor `undefined` are automatically
escaped:
.. sourcecode:: html+jinja
<ul{{ {'class': 'my_list', 'missing': none,
'id': 'list-%d'|format(variable)}|xmlattr }}>
...
</ul>
Results in something like this:
.. sourcecode:: html
<ul class="my_list" id="list-42">
...
</ul>
As you can see it automatically prepends a space in front of the item
if the filter returned something unless the second parameter is false.
"""
rv = u' '.join(
u'%s="%s"' % (escape(key), escape(value))
for key, value in iteritems(d)
if value is not None and not isinstance(value, Undefined)
)
if autospace and rv:
rv = u' ' + rv
if _eval_ctx.autoescape:
rv = Markup(rv)
return rv
def do_capitalize(s):
"""Capitalize a value. The first character will be uppercase, all others
lowercase.
"""
return soft_unicode(s).capitalize()
def do_title(s):
"""Return a titlecased version of the value. I.e. words will start with
uppercase letters, all remaining characters are lowercase.
"""
rv = []
for item in re.compile(r'([-\s]+)(?u)').split(soft_unicode(s)):
if not item:
continue
rv.append(item[0].upper() + item[1:].lower())
return ''.join(rv)
def do_dictsort(value, case_sensitive=False, by='key'):
"""Sort a dict and yield (key, value) pairs. Because python dicts are
unsorted you may want to use this function to order them by either
key or value:
.. sourcecode:: jinja
{% for item in mydict|dictsort %}
sort the dict by key, case insensitive
{% for item in mydict|dictsort(true) %}
sort the dict by key, case sensitive
{% for item in mydict|dictsort(false, 'value') %}
sort the dict by value, case insensitive
"""
if by == 'key':
pos = 0
elif by == 'value':
pos = 1
else:
raise FilterArgumentError('You can only sort by either '
'"key" or "value"')
def sort_func(item):
value = item[pos]
if isinstance(value, string_types) and not case_sensitive:
value = value.lower()
return value
return sorted(value.items(), key=sort_func)
@environmentfilter
def do_sort(environment, value, reverse=False, case_sensitive=False,
attribute=None):
"""Sort an iterable. Per default it sorts ascending, if you pass it
true as first argument it will reverse the sorting.
If the iterable is made of strings the third parameter can be used to
control the case sensitiveness of the comparison which is disabled by
default.
.. sourcecode:: jinja
{% for item in iterable|sort %}
...
{% endfor %}
It is also possible to sort by an attribute (for example to sort
by the date of an object) by specifying the `attribute` parameter:
.. sourcecode:: jinja
{% for item in iterable|sort(attribute='date') %}
...
{% endfor %}
.. versionchanged:: 2.6
The `attribute` parameter was added.
"""
if not case_sensitive:
def sort_func(item):
if isinstance(item, string_types):
item = item.lower()
return item
else:
sort_func = None
if attribute is not None:
getter = make_attrgetter(environment, attribute)
def sort_func(item, processor=sort_func or (lambda x: x)):
return processor(getter(item))
return sorted(value, key=sort_func, reverse=reverse)
def do_default(value, default_value=u'', boolean=False):
"""If the value is undefined it will return the passed default value,
otherwise the value of the variable:
.. sourcecode:: jinja
{{ my_variable|default('my_variable is not defined') }}
This will output the value of ``my_variable`` if the variable was
defined, otherwise ``'my_variable is not defined'``. If you want
to use default with variables that evaluate to false you have to
set the second parameter to `true`:
.. sourcecode:: jinja
{{ ''|default('the string was empty', true) }}
"""
if isinstance(value, Undefined) or (boolean and not value):
return default_value
return value
@evalcontextfilter
def do_join(eval_ctx, value, d=u'', attribute=None):
"""Return a string which is the concatenation of the strings in the
sequence. The separator between elements is an empty string per
default, you can define it with the optional parameter:
.. sourcecode:: jinja
{{ [1, 2, 3]|join('|') }}
-> 1|2|3
{{ [1, 2, 3]|join }}
-> 123
It is also possible to join certain attributes of an object:
.. sourcecode:: jinja
{{ users|join(', ', attribute='username') }}
.. versionadded:: 2.6
The `attribute` parameter was added.
"""
if attribute is not None:
value = imap(make_attrgetter(eval_ctx.environment, attribute), value)
# no automatic escaping? joining is a lot eaiser then
if not eval_ctx.autoescape:
return text_type(d).join(imap(text_type, value))
# if the delimiter doesn't have an html representation we check
# if any of the items has. If yes we do a coercion to Markup
if not hasattr(d, '__html__'):
value = list(value)
do_escape = False
for idx, item in enumerate(value):
if hasattr(item, '__html__'):
do_escape = True
else:
value[idx] = text_type(item)
if do_escape:
d = escape(d)
else:
d = text_type(d)
return d.join(value)
# no html involved, to normal joining
return soft_unicode(d).join(imap(soft_unicode, value))
def do_center(value, width=80):
"""Centers the value in a field of a given width."""
return text_type(value).center(width)
@environmentfilter
def do_first(environment, seq):
"""Return the first item of a sequence."""
try:
return next(iter(seq))
except StopIteration:
return environment.undefined('No first item, sequence was empty.')
@environmentfilter
def do_last(environment, seq):
"""Return the last item of a sequence."""
try:
return next(iter(reversed(seq)))
except StopIteration:
return environment.undefined('No last item, sequence was empty.')
@environmentfilter
def do_random(environment, seq):
"""Return a random item from the sequence."""
try:
return choice(seq)
except IndexError:
return environment.undefined('No random item, sequence was empty.')
def do_filesizeformat(value, binary=False):
"""Format the value like a 'human-readable' file size (i.e. 13 kB,
4.1 MB, 102 Bytes, etc). Per default decimal prefixes are used (Mega,
Giga, etc.), if the second parameter is set to `True` the binary
prefixes are used (Mebi, Gibi).
"""
bytes = float(value)
base = binary and 1024 or 1000
prefixes = [
(binary and 'KiB' or 'kB'),
(binary and 'MiB' or 'MB'),
(binary and 'GiB' or 'GB'),
(binary and 'TiB' or 'TB'),
(binary and 'PiB' or 'PB'),
(binary and 'EiB' or 'EB'),
(binary and 'ZiB' or 'ZB'),
(binary and 'YiB' or 'YB')
]
if bytes == 1:
return '1 Byte'
elif bytes < base:
return '%d Bytes' % bytes
else:
for i, prefix in enumerate(prefixes):
unit = base ** (i + 2)
if bytes < unit:
return '%.1f %s' % ((base * bytes / unit), prefix)
return '%.1f %s' % ((base * bytes / unit), prefix)
def do_pprint(value, verbose=False):
"""Pretty print a variable. Useful for debugging.
With Jinja 1.2 onwards you can pass it a parameter. If this parameter
is truthy the output will be more verbose (this requires `pretty`)
"""
return pformat(value, verbose=verbose)
@evalcontextfilter
def do_urlize(eval_ctx, value, trim_url_limit=None, nofollow=False,
target=None):
"""Converts URLs in plain text into clickable links.
If you pass the filter an additional integer it will shorten the urls
to that number. Also a third argument exists that makes the urls
"nofollow":
.. sourcecode:: jinja
{{ mytext|urlize(40, true) }}
links are shortened to 40 chars and defined with rel="nofollow"
If *target* is specified, the ``target`` attribute will be added to the
``<a>`` tag:
.. sourcecode:: jinja
{{ mytext|urlize(40, target='_blank') }}
.. versionchanged:: 2.8+
The *target* parameter was added.
"""
rv = urlize(value, trim_url_limit, nofollow, target)
if eval_ctx.autoescape:
rv = Markup(rv)
return rv
def do_indent(s, width=4, indentfirst=False):
"""Return a copy of the passed string, each line indented by
4 spaces. The first line is not indented. If you want to
change the number of spaces or indent the first line too
you can pass additional parameters to the filter:
.. sourcecode:: jinja
{{ mytext|indent(2, true) }}
indent by two spaces and indent the first line too.
"""
indention = u' ' * width
rv = (u'\n' + indention).join(s.splitlines())
if indentfirst:
rv = indention + rv
return rv
def do_truncate(s, length=255, killwords=False, end='...'):
"""Return a truncated copy of the string. The length is specified
with the first parameter which defaults to ``255``. If the second
parameter is ``true`` the filter will cut the text at length. Otherwise
it will discard the last word. If the text was in fact
truncated it will append an ellipsis sign (``"..."``). If you want a
different ellipsis sign than ``"..."`` you can specify it using the
third parameter.
.. sourcecode:: jinja
{{ "foo bar baz"|truncate(9) }}
-> "foo ..."
{{ "foo bar baz"|truncate(9, True) }}
-> "foo ba..."
"""
if len(s) <= length:
return s
elif killwords:
return s[:length - len(end)] + end
result = s[:length - len(end)].rsplit(' ', 1)[0]
if len(result) < length:
result += ' '
return result + end
@environmentfilter
def do_wordwrap(environment, s, width=79, break_long_words=True,
wrapstring=None):
"""
Return a copy of the string passed to the filter wrapped after
``79`` characters. You can override this default using the first
parameter. If you set the second parameter to `false` Jinja will not
split words apart if they are longer than `width`. By default, the newlines
will be the default newlines for the environment, but this can be changed
using the wrapstring keyword argument.
.. versionadded:: 2.7
Added support for the `wrapstring` parameter.
"""
if not wrapstring:
wrapstring = environment.newline_sequence
import textwrap
return wrapstring.join(textwrap.wrap(s, width=width, expand_tabs=False,
replace_whitespace=False,
break_long_words=break_long_words))
def do_wordcount(s):
"""Count the words in that string."""
return len(_word_re.findall(s))
def do_int(value, default=0, base=10):
"""Convert the value into an integer. If the
conversion doesn't work it will return ``0``. You can
override this default using the first parameter. You
can also override the default base (10) in the second
parameter, which handles input with prefixes such as
0b, 0o and 0x for bases 2, 8 and 16 respectively.
"""
try:
return int(value, base)
except (TypeError, ValueError):
# this quirk is necessary so that "42.23"|int gives 42.
try:
return int(float(value))
except (TypeError, ValueError):
return default
def do_float(value, default=0.0):
"""Convert the value into a floating point number. If the
conversion doesn't work it will return ``0.0``. You can
override this default using the first parameter.
"""
try:
return float(value)
except (TypeError, ValueError):
return default
def do_format(value, *args, **kwargs):
"""
Apply python string formatting on an object:
.. sourcecode:: jinja
{{ "%s - %s"|format("Hello?", "Foo!") }}
-> Hello? - Foo!
"""
if args and kwargs:
raise FilterArgumentError('can\'t handle positional and keyword '
'arguments at the same time')
return soft_unicode(value) % (kwargs or args)
def do_trim(value):
"""Strip leading and trailing whitespace."""
return soft_unicode(value).strip()
def do_striptags(value):
"""Strip SGML/XML tags and replace adjacent whitespace by one space.
"""
if hasattr(value, '__html__'):
value = value.__html__()
return Markup(text_type(value)).striptags()
def do_slice(value, slices, fill_with=None):
"""Slice an iterator and return a list of lists containing
those items. Useful if you want to create a div containing
three ul tags that represent columns:
.. sourcecode:: html+jinja
<div class="columwrapper">
{%- for column in items|slice(3) %}
<ul class="column-{{ loop.index }}">
{%- for item in column %}
<li>{{ item }}</li>
{%- endfor %}
</ul>
{%- endfor %}
</div>
If you pass it a second argument it's used to fill missing
values on the last iteration.
"""
seq = list(value)
length = len(seq)
items_per_slice = length // slices
slices_with_extra = length % slices
offset = 0
for slice_number in range(slices):
start = offset + slice_number * items_per_slice
if slice_number < slices_with_extra:
offset += 1
end = offset + (slice_number + 1) * items_per_slice
tmp = seq[start:end]
if fill_with is not None and slice_number >= slices_with_extra:
tmp.append(fill_with)
yield tmp
def do_batch(value, linecount, fill_with=None):
"""
A filter that batches items. It works pretty much like `slice`
just the other way round. It returns a list of lists with the
given number of items. If you provide a second parameter this
is used to fill up missing items. See this example:
.. sourcecode:: html+jinja
<table>
{%- for row in items|batch(3, ' ') %}
<tr>
{%- for column in row %}
<td>{{ column }}</td>
{%- endfor %}
</tr>
{%- endfor %}
</table>
"""
tmp = []
for item in value:
if len(tmp) == linecount:
yield tmp
tmp = []
tmp.append(item)
if tmp:
if fill_with is not None and len(tmp) < linecount:
tmp += [fill_with] * (linecount - len(tmp))
yield tmp
def do_round(value, precision=0, method='common'):
"""Round the number to a given precision. The first
parameter specifies the precision (default is ``0``), the
second the rounding method:
- ``'common'`` rounds either up or down
- ``'ceil'`` always rounds up
- ``'floor'`` always rounds down
If you don't specify a method ``'common'`` is used.
.. sourcecode:: jinja
{{ 42.55|round }}
-> 43.0
{{ 42.55|round(1, 'floor') }}
-> 42.5
Note that even if rounded to 0 precision, a float is returned. If
you need a real integer, pipe it through `int`:
.. sourcecode:: jinja
{{ 42.55|round|int }}
-> 43
"""
if not method in ('common', 'ceil', 'floor'):
raise FilterArgumentError('method must be common, ceil or floor')
if method == 'common':
return round(value, precision)
func = getattr(math, method)
return func(value * (10 ** precision)) / (10 ** precision)
@environmentfilter
def do_groupby(environment, value, attribute):
"""Group a sequence of objects by a common attribute.
If you for example have a list of dicts or objects that represent persons
with `gender`, `first_name` and `last_name` attributes and you want to
group all users by genders you can do something like the following
snippet:
.. sourcecode:: html+jinja
<ul>
{% for group in persons|groupby('gender') %}
<li>{{ group.grouper }}<ul>
{% for person in group.list %}
<li>{{ person.first_name }} {{ person.last_name }}</li>
{% endfor %}</ul></li>
{% endfor %}
</ul>
Additionally it's possible to use tuple unpacking for the grouper and
list:
.. sourcecode:: html+jinja
<ul>
{% for grouper, list in persons|groupby('gender') %}
...
{% endfor %}
</ul>
As you can see the item we're grouping by is stored in the `grouper`
attribute and the `list` contains all the objects that have this grouper
in common.
.. versionchanged:: 2.6
It's now possible to use dotted notation to group by the child
attribute of another attribute.
"""
expr = make_attrgetter(environment, attribute)
return sorted(map(_GroupTuple, groupby(sorted(value, key=expr), expr)))
class _GroupTuple(tuple):
__slots__ = ()
grouper = property(itemgetter(0))
list = property(itemgetter(1))
def __new__(cls, xxx_todo_changeme):
(key, value) = xxx_todo_changeme
return tuple.__new__(cls, (key, list(value)))
@environmentfilter
def do_sum(environment, iterable, attribute=None, start=0):
"""Returns the sum of a sequence of numbers plus the value of parameter
'start' (which defaults to 0). When the sequence is empty it returns
start.
It is also possible to sum up only certain attributes:
.. sourcecode:: jinja
Total: {{ items|sum(attribute='price') }}
.. versionchanged:: 2.6
The `attribute` parameter was added to allow suming up over
attributes. Also the `start` parameter was moved on to the right.
"""
if attribute is not None:
iterable = imap(make_attrgetter(environment, attribute), iterable)
return sum(iterable, start)
def do_list(value):
"""Convert the value into a list. If it was a string the returned list
will be a list of characters.
"""
return list(value)
def do_mark_safe(value):
"""Mark the value as safe which means that in an environment with automatic
escaping enabled this variable will not be escaped.
"""
return Markup(value)
def do_mark_unsafe(value):
"""Mark a value as unsafe. This is the reverse operation for :func:`safe`."""
return text_type(value)
def do_reverse(value):
"""Reverse the object or return an iterator that iterates over it the other
way round.
"""
if isinstance(value, string_types):
return value[::-1]
try:
return reversed(value)
except TypeError:
try:
rv = list(value)
rv.reverse()
return rv
except TypeError:
raise FilterArgumentError('argument must be iterable')
@environmentfilter
def do_attr(environment, obj, name):
"""Get an attribute of an object. ``foo|attr("bar")`` works like
``foo.bar`` just that always an attribute is returned and items are not
looked up.
See :ref:`Notes on subscriptions <notes-on-subscriptions>` for more details.
"""
try:
name = str(name)
except UnicodeError:
pass
else:
try:
value = getattr(obj, name)
except AttributeError:
pass
else:
if environment.sandboxed and not \
environment.is_safe_attribute(obj, name, value):
return environment.unsafe_undefined(obj, name)
return value
return environment.undefined(obj=obj, name=name)
@contextfilter
def do_map(*args, **kwargs):
"""Applies a filter on a sequence of objects or looks up an attribute.
This is useful when dealing with lists of objects but you are really
only interested in a certain value of it.
The basic usage is mapping on an attribute. Imagine you have a list
of users but you are only interested in a list of usernames:
.. sourcecode:: jinja
Users on this page: {{ users|map(attribute='username')|join(', ') }}
Alternatively you can let it invoke a filter by passing the name of the
filter and the arguments afterwards. A good example would be applying a
text conversion filter on a sequence:
.. sourcecode:: jinja
Users on this page: {{ titles|map('lower')|join(', ') }}
.. versionadded:: 2.7
"""
context = args[0]
seq = args[1]
if len(args) == 2 and 'attribute' in kwargs:
attribute = kwargs.pop('attribute')
if kwargs:
raise FilterArgumentError('Unexpected keyword argument %r' %
next(iter(kwargs)))
func = make_attrgetter(context.environment, attribute)
else:
try:
name = args[2]
args = args[3:]
except LookupError:
raise FilterArgumentError('map requires a filter argument')
func = lambda item: context.environment.call_filter(
name, item, args, kwargs, context=context)
if seq:
for item in seq:
yield func(item)
@contextfilter
def do_select(*args, **kwargs):
"""Filters a sequence of objects by applying a test to the object and only
selecting the ones with the test succeeding.
Example usage:
.. sourcecode:: jinja
{{ numbers|select("odd") }}
{{ numbers|select("odd") }}
.. versionadded:: 2.7
"""
return _select_or_reject(args, kwargs, lambda x: x, False)
@contextfilter
def do_reject(*args, **kwargs):
"""Filters a sequence of objects by applying a test to the object and
rejecting the ones with the test succeeding.
Example usage:
.. sourcecode:: jinja
{{ numbers|reject("odd") }}
.. versionadded:: 2.7
"""
return _select_or_reject(args, kwargs, lambda x: not x, False)
@contextfilter
def do_selectattr(*args, **kwargs):
"""Filters a sequence of objects by applying a test to an attribute of an
object and only selecting the ones with the test succeeding.
Example usage:
.. sourcecode:: jinja
{{ users|selectattr("is_active") }}
{{ users|selectattr("email", "none") }}
.. versionadded:: 2.7
"""
return _select_or_reject(args, kwargs, lambda x: x, True)
@contextfilter
def do_rejectattr(*args, **kwargs):
"""Filters a sequence of objects by applying a test to an attribute of an
object or the attribute and rejecting the ones with the test succeeding.
.. sourcecode:: jinja
{{ users|rejectattr("is_active") }}
{{ users|rejectattr("email", "none") }}
.. versionadded:: 2.7
"""
return _select_or_reject(args, kwargs, lambda x: not x, True)
def _select_or_reject(args, kwargs, modfunc, lookup_attr):
context = args[0]
seq = args[1]
if lookup_attr:
try:
attr = args[2]
except LookupError:
raise FilterArgumentError('Missing parameter for attribute name')
transfunc = make_attrgetter(context.environment, attr)
off = 1
else:
off = 0
transfunc = lambda x: x
try:
name = args[2 + off]
args = args[3 + off:]
func = lambda item: context.environment.call_test(
name, item, args, kwargs)
except LookupError:
func = bool
if seq:
for item in seq:
if modfunc(func(transfunc(item))):
yield item
FILTERS = {
'abs': abs,
'attr': do_attr,
'batch': do_batch,
'capitalize': do_capitalize,
'center': do_center,
'count': len,
'd': do_default,
'default': do_default,
'dictsort': do_dictsort,
'e': escape,
'escape': escape,
'filesizeformat': do_filesizeformat,
'first': do_first,
'float': do_float,
'forceescape': do_forceescape,
'format': do_format,
'groupby': do_groupby,
'indent': do_indent,
'int': do_int,
'join': do_join,
'last': do_last,
'length': len,
'list': do_list,
'lower': do_lower,
'map': do_map,
'pprint': do_pprint,
'random': do_random,
'reject': do_reject,
'rejectattr': do_rejectattr,
'replace': do_replace,
'reverse': do_reverse,
'round': do_round,
'safe': do_mark_safe,
'select': do_select,
'selectattr': do_selectattr,
'slice': do_slice,
'sort': do_sort,
'string': soft_unicode,
'striptags': do_striptags,
'sum': do_sum,
'title': do_title,
'trim': do_trim,
'truncate': do_truncate,
'upper': do_upper,
'urlencode': do_urlencode,
'urlize': do_urlize,
'wordcount': do_wordcount,
'wordwrap': do_wordwrap,
'xmlattr': do_xmlattr,
}
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10321,
18,
14,
4273,
272,
32202,
1714,
339,
699,
725,
1146,
10321,
4766,
14,
339,
520,
7307,
26,
334,
67,
9,
7129,
701,
314,
17300,
11682,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
646,
295,
199,
646,
3473,
199,
199,
504,
2196,
492,
7141,
199,
504,
4182,
492,
1242,
7416,
199,
504,
7975,
492,
20371,
199,
504,
10321,
18,
14,
1208,
492,
17504,
12,
4772,
12,
30843,
12,
7629,
13559,
12,
11620,
63,
2975,
12,
971,
1362,
2649,
63,
10738,
199,
504,
10321,
18,
14,
7726,
492,
25868,
199,
504,
10321,
18,
14,
3924,
492,
9388,
17042,
199,
504,
10321,
18,
423,
5819,
492,
23646,
12,
1059,
63,
1313,
12,
1318,
63,
466,
12,
10849,
421,
199,
63,
1027,
63,
264,
275,
295,
14,
2014,
8,
82,
1154,
87,
11,
2229,
85,
5942,
421,
199,
318,
1067,
1541,
8,
70,
304,
272,
408,
14946,
367,
31318,
1067,
11410,
4766,
14,
710,
1453,
272,
520,
533,
1705,
2998,
64,
911,
506,
3032,
465,
1642,
1423,
14,
272,
408,
272,
289,
14,
1100,
1541,
275,
715,
272,
372,
289,
421,
199,
318,
3468,
1100,
1541,
8,
70,
304,
272,
408,
14946,
367,
31318,
3468,
13,
1100,
11410,
4766,
14,
221,
1626,
3468,
272,
1067,
909,
365,
3032,
465,
1642,
1423,
14,
221,
2104,
1655,
2556,
272,
3595,
314,
3468,
1067,
12,
1937,
520,
1121,
1705,
2579,
13,
1100,
2313,
339,
2508,
7445,
447,
499,
14,
20,
272,
408,
272,
289,
14,
2579,
1100,
1541,
275,
715,
272,
372,
289,
421,
199,
318,
3734,
1541,
8,
70,
304,
272,
408,
14946,
367,
31318,
325,
2920,
11410,
4766,
14,
221,
710,
1453,
272,
520,
533,
1705,
8263,
64,
365,
3032,
370,
314,
2457,
465,
1642,
1423,
14,
272,
408,
272,
289,
14,
5418,
1541,
275,
715,
272,
372,
289,
421,
199,
318,
1852,
63,
18600,
8,
5418,
12,
2225,
304,
272,
408,
3407,
282,
4550,
626,
10734,
1536,
314,
1627,
2225,
687,
282,
272,
3032,
909,
543,
314,
4713,
402,
314,
3734,
14,
221,
577,
16673,
787,
4370,
272,
370,
2879,
3004,
402,
3004,
14,
221,
7225,
4184,
315,
3792,
787,
272,
21182,
1536,
465,
9446,
14,
272,
408,
272,
340,
440,
1228,
8,
3215,
12,
1059,
63,
1313,
9,
971,
2126,
503,
661,
3530,
440,
315,
2225,
436,
440,
2225,
14,
13896,
5109,
267,
372,
2400,
671,
26,
3734,
14,
6095,
8,
88,
12,
2225,
9,
272,
2225,
275,
2225,
14,
1294,
7563,
272,
347,
21829,
8,
1053,
304,
267,
367,
1777,
315,
2225,
26,
288,
340,
1777,
14,
13896,
837,
355,
1777,
275,
1109,
8,
2064,
9,
288,
1242,
275,
3734,
14,
6095,
8,
1053,
12,
1777,
9,
267,
372,
1242,
272,
372,
21829,
421,
199,
318,
886,
63,
3990,
3765,
8,
585,
304,
272,
408,
1327,
3990,
4163,
21375,
14,
221,
961,
911,
8646,
4270,
4772,
2860,
1041,
272,
340,
2688,
8,
585,
12,
2560,
1360,
12168,
267,
574,
275,
574,
855,
1360,
4533,
272,
372,
4772,
8,
505,
63,
466,
8,
585,
430,
421,
199,
318,
886,
63,
10738,
8,
585,
304,
272,
408,
10260,
3326,
367,
675,
315,
10867,
334,
5589,
9094,
13,
24,
2644,
680,
221,
2779,
11479,
3865,
272,
11196,
436,
5578,
3326,
465,
5521,
465,
24859,
6076,
83,
14,
339,
2508,
7445,
447,
499,
14,
23,
272,
408,
272,
1242,
1661,
275,
488,
272,
340,
1228,
8,
585,
12,
1211,
304,
267,
1242,
1661,
275,
10849,
8,
585,
9,
272,
916,
440,
1228,
8,
585,
12,
1059,
63,
1313,
304,
267,
862,
26,
288,
1242,
1661,
275,
2740,
8,
585,
9,
267,
871,
3146,
26,
288,
986,
272,
340,
1242,
1661,
365,
488,
26,
267,
372,
2649,
63,
10738,
8,
585,
9,
272,
372,
399,
21840,
1370,
904,
8,
2975,
63,
10738,
8,
75,
9,
435,
14051,
435,
2151,
2649,
63,
10738,
8,
86,
12,
367,
63,
6177,
29,
549,
9,
2151,
367,
1022,
12,
373,
315,
1242,
1661,
9,
421,
199,
32,
2579,
1100,
1541,
199,
318,
886,
63,
1814,
8,
2579,
63,
3799,
12,
308,
12,
2269,
12,
892,
12,
2338,
29,
403,
304,
272,
408,
1767,
282,
1331,
402,
314,
574,
543,
1006,
22099,
402,
282,
20597,
272,
8717,
543,
282,
892,
1373,
14,
710,
1642,
1423,
365,
314,
20597,
272,
626,
1077,
506,
8717,
12,
314,
3499,
365,
314,
8343,
1059,
14,
272,
982,
314,
2716,
10919,
1423,
1124,
835,
1040,
365,
1627,
12,
1454,
314,
1642,
272,
1124,
835,
1040,
22099,
787,
8717,
26,
339,
2508,
25468,
447,
10321,
398,
8448,
298,
6257,
13064,
29617,
1814,
480,
6257,
401,
298,
20652,
16481,
531,
3586,
288,
1035,
22311,
16481,
13064,
398,
8448,
298,
6000,
1273,
72,
29617,
1814,
480,
65,
401,
298,
68,
7,
19194,
12,
3872,
499,
9,
3586,
288,
1035,
366,
7,
19194,
12,
366,
7,
19194,
12,
18319,
1273,
72,
272,
408,
272,
340,
2338,
365,
488,
26,
267,
2338,
275,
446,
17,
272,
340,
440,
3468,
63,
3799,
14,
15818,
26,
267,
372,
1318,
63,
466,
8,
83,
680,
1814,
8,
505,
63,
466,
8,
1753,
395,
1318,
63,
466,
8,
1222,
395,
2338,
9,
272,
340,
2688,
8,
1753,
12,
2560,
1360,
13766,
503,
2688,
8,
1222,
12,
2560,
1360,
13766,
436,
971,
2126,
440,
2688,
8,
83,
12,
2560,
1360,
12168,
267,
308,
275,
4772,
8,
83,
9,
272,
587,
26,
267,
308,
275,
11620,
63,
2975,
8,
83,
9,
272,
372,
308,
14,
1814,
8,
4617,
63,
2975,
8,
1753,
395,
11620,
63,
2975,
8,
1222,
395,
2338,
9,
421,
199,
318,
886,
63,
4142,
8,
83,
304,
272,
408,
7306,
282,
574,
370,
22681,
1041,
272,
372,
11620,
63,
2975,
8,
83,
680,
4142,
342,
421,
199,
318,
886,
63,
2325,
8,
83,
304,
272,
408,
7306,
282,
574,
370,
12141,
1041,
272,
372,
11620,
63,
2975,
8,
83,
680,
2325,
342,
421,
199,
32,
2579,
1100,
1541,
199,
318,
886,
63,
1652,
962,
1547,
2579,
63,
3799,
12,
366,
12,
6384,
17601,
29,
549,
304,
272,
408,
2499,
376,
18868,
1698,
15,
4317,
2225,
1059,
4079,
641,
314,
2974,
315,
282,
1211,
14,
272,
2900,
1338,
626
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10321,
18,
14,
4273,
272,
32202,
1714,
339,
699,
725,
1146,
10321,
4766,
14,
339,
520,
7307,
26,
334,
67,
9,
7129,
701,
314,
17300,
11682,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
646,
295,
199,
646,
3473,
199,
199,
504,
2196,
492,
7141,
199,
504,
4182,
492,
1242,
7416,
199,
504,
7975,
492,
20371,
199,
504,
10321,
18,
14,
1208,
492,
17504,
12,
4772,
12,
30843,
12,
7629,
13559,
12,
11620,
63,
2975,
12,
971,
1362,
2649,
63,
10738,
199,
504,
10321,
18,
14,
7726,
492,
25868,
199,
504,
10321,
18,
14,
3924,
492,
9388,
17042,
199,
504,
10321,
18,
423,
5819,
492,
23646,
12,
1059,
63,
1313,
12,
1318,
63,
466,
12,
10849,
421,
199,
63,
1027,
63,
264,
275,
295,
14,
2014,
8,
82,
1154,
87,
11,
2229,
85,
5942,
421,
199,
318,
1067,
1541,
8,
70,
304,
272,
408,
14946,
367,
31318,
1067,
11410,
4766,
14,
710,
1453,
272,
520,
533,
1705,
2998,
64,
911,
506,
3032,
465,
1642,
1423,
14,
272,
408,
272,
289,
14,
1100,
1541,
275,
715,
272,
372,
289,
421,
199,
318,
3468,
1100,
1541,
8,
70,
304,
272,
408,
14946,
367,
31318,
3468,
13,
1100,
11410,
4766,
14,
221,
1626,
3468,
272,
1067,
909,
365,
3032,
465,
1642,
1423,
14,
221,
2104,
1655,
2556,
272,
3595,
314,
3468,
1067,
12,
1937,
520,
1121,
1705,
2579,
13,
1100,
2313,
339,
2508,
7445,
447,
499,
14,
20,
272,
408,
272,
289,
14,
2579,
1100,
1541,
275,
715,
272,
372,
289,
421,
199,
318,
3734,
1541,
8,
70,
304,
272,
408,
14946,
367,
31318,
325,
2920,
11410,
4766,
14,
221,
710,
1453,
272,
520,
533,
1705,
8263,
64,
365,
3032,
370,
314,
2457,
465,
1642,
1423,
14,
272,
408,
272,
289,
14,
5418,
1541,
275,
715,
272,
372,
289,
421,
199,
318,
1852,
63,
18600,
8,
5418,
12,
2225,
304,
272,
408,
3407,
282,
4550,
626,
10734,
1536,
314,
1627,
2225,
687,
282,
272,
3032,
909,
543,
314,
4713,
402,
314,
3734,
14,
221,
577,
16673,
787,
4370,
272,
370,
2879,
3004,
402,
3004,
14,
221,
7225,
4184,
315,
3792,
787,
272,
21182,
1536,
465,
9446,
14,
272,
408,
272,
340,
440,
1228,
8,
3215,
12,
1059,
63,
1313,
9,
971,
2126,
503,
661,
3530,
440,
315,
2225,
436,
440,
2225,
14,
13896,
5109,
267,
372,
2400,
671,
26,
3734,
14,
6095,
8,
88,
12,
2225,
9,
272,
2225,
275,
2225,
14,
1294,
7563,
272,
347,
21829,
8,
1053,
304,
267,
367,
1777,
315,
2225,
26,
288,
340,
1777,
14,
13896,
837,
355,
1777,
275,
1109,
8,
2064,
9,
288,
1242,
275,
3734,
14,
6095,
8,
1053,
12,
1777,
9,
267,
372,
1242,
272,
372,
21829,
421,
199,
318,
886,
63,
3990,
3765,
8,
585,
304,
272,
408,
1327,
3990,
4163,
21375,
14,
221,
961,
911,
8646,
4270,
4772,
2860,
1041,
272,
340,
2688,
8,
585,
12,
2560,
1360,
12168,
267,
574,
275,
574,
855,
1360,
4533,
272,
372,
4772,
8,
505,
63,
466,
8,
585,
430,
421,
199,
318,
886,
63,
10738,
8,
585,
304,
272,
408,
10260,
3326,
367,
675,
315,
10867,
334,
5589,
9094,
13,
24,
2644,
680,
221,
2779,
11479,
3865,
272,
11196,
436,
5578,
3326,
465,
5521,
465,
24859,
6076,
83,
14,
339,
2508,
7445,
447,
499,
14,
23,
272,
408,
272,
1242,
1661,
275,
488,
272,
340,
1228,
8,
585,
12,
1211,
304,
267,
1242,
1661,
275,
10849,
8,
585,
9,
272,
916,
440,
1228,
8,
585,
12,
1059,
63,
1313,
304,
267,
862,
26,
288,
1242,
1661,
275,
2740,
8,
585,
9,
267,
871,
3146,
26,
288,
986,
272,
340,
1242,
1661,
365,
488,
26,
267,
372,
2649,
63,
10738,
8,
585,
9,
272,
372,
399,
21840,
1370,
904,
8,
2975,
63,
10738,
8,
75,
9,
435,
14051,
435,
2151,
2649,
63,
10738,
8,
86,
12,
367,
63,
6177,
29,
549,
9,
2151,
367,
1022,
12,
373,
315,
1242,
1661,
9,
421,
199,
32,
2579,
1100,
1541,
199,
318,
886,
63,
1814,
8,
2579,
63,
3799,
12,
308,
12,
2269,
12,
892,
12,
2338,
29,
403,
304,
272,
408,
1767,
282,
1331,
402,
314,
574,
543,
1006,
22099,
402,
282,
20597,
272,
8717,
543,
282,
892,
1373,
14,
710,
1642,
1423,
365,
314,
20597,
272,
626,
1077,
506,
8717,
12,
314,
3499,
365,
314,
8343,
1059,
14,
272,
982,
314,
2716,
10919,
1423,
1124,
835,
1040,
365,
1627,
12,
1454,
314,
1642,
272,
1124,
835,
1040,
22099,
787,
8717,
26,
339,
2508,
25468,
447,
10321,
398,
8448,
298,
6257,
13064,
29617,
1814,
480,
6257,
401,
298,
20652,
16481,
531,
3586,
288,
1035,
22311,
16481,
13064,
398,
8448,
298,
6000,
1273,
72,
29617,
1814,
480,
65,
401,
298,
68,
7,
19194,
12,
3872,
499,
9,
3586,
288,
1035,
366,
7,
19194,
12,
366,
7,
19194,
12,
18319,
1273,
72,
272,
408,
272,
340,
2338,
365,
488,
26,
267,
2338,
275,
446,
17,
272,
340,
440,
3468,
63,
3799,
14,
15818,
26,
267,
372,
1318,
63,
466,
8,
83,
680,
1814,
8,
505,
63,
466,
8,
1753,
395,
1318,
63,
466,
8,
1222,
395,
2338,
9,
272,
340,
2688,
8,
1753,
12,
2560,
1360,
13766,
503,
2688,
8,
1222,
12,
2560,
1360,
13766,
436,
971,
2126,
440,
2688,
8,
83,
12,
2560,
1360,
12168,
267,
308,
275,
4772,
8,
83,
9,
272,
587,
26,
267,
308,
275,
11620,
63,
2975,
8,
83,
9,
272,
372,
308,
14,
1814,
8,
4617,
63,
2975,
8,
1753,
395,
11620,
63,
2975,
8,
1222,
395,
2338,
9,
421,
199,
318,
886,
63,
4142,
8,
83,
304,
272,
408,
7306,
282,
574,
370,
22681,
1041,
272,
372,
11620,
63,
2975,
8,
83,
680,
4142,
342,
421,
199,
318,
886,
63,
2325,
8,
83,
304,
272,
408,
7306,
282,
574,
370,
12141,
1041,
272,
372,
11620,
63,
2975,
8,
83,
680,
2325,
342,
421,
199,
32,
2579,
1100,
1541,
199,
318,
886,
63,
1652,
962,
1547,
2579,
63,
3799,
12,
366,
12,
6384,
17601,
29,
549,
304,
272,
408,
2499,
376,
18868,
1698,
15,
4317,
2225,
1059,
4079,
641,
314,
2974,
315,
282,
1211,
14,
272,
2900,
1338,
626,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
zhufangxing/ndnCDN
|
src/fd-net-device/bindings/modulegen_customizations.py
|
128
|
1118
|
import os
def post_register_types(root_module):
enabled_features = os.environ['NS3_ENABLED_FEATURES'].split(',')
if 'EmuFdNetDevice' not in enabled_features:
if 'ns3::EmuFdNetDeviceHelper'in root_module:
root_module.classes.remove(root_module['ns3::EmuFdNetDeviceHelper'])
if 'TapFdNetDevice' not in enabled_features:
if 'ns3::TapFdNetDeviceHelper'in root_module:
root_module.classes.remove(root_module['ns3::TapFdNetDeviceHelper'])
if 'PlanetLabFdNetDevice' not in enabled_features:
if 'ns3::PlanetLabFdNetDeviceHelper'in root_module:
root_module.classes.remove(root_module['ns3::PlanetLabFdNetDeviceHelper'])
if 'FdNetDevice' not in enabled_features:
for clsname in ['FdNetDevice', 'FdNetDeviceHelper', 'FdNetDeviceFdReader']:
if 'ns3::%s' % clsname in root_module:
root_module.classes.remove(root_module['ns3::%s' % clsname])
if 'ns3::FdNetDeviceHelper::EncapsulationMode' in root_module:
root_module.enums.remove(root_module['ns3::FdNetDeviceHelper::EncapsulationMode'])
|
gpl-2.0
|
[
646,
747,
199,
199,
318,
2963,
63,
2683,
63,
1313,
8,
1231,
63,
578,
304,
272,
5223,
63,
3179,
275,
747,
14,
2314,
459,
2709,
19,
63,
15704,
63,
13313,
2278,
1294,
11917,
339,
340,
283,
37,
6553,
20689,
4351,
7,
440,
315,
5223,
63,
3179,
26,
267,
340,
283,
561,
19,
447,
37,
6553,
20689,
4351,
4433,
7,
262,
1738,
63,
578,
26,
288,
1738,
63,
578,
14,
2888,
14,
2168,
8,
1231,
63,
578,
459,
561,
19,
447,
37,
6553,
20689,
4351,
4433,
1105,
339,
340,
283,
27746,
20689,
4351,
7,
440,
315,
5223,
63,
3179,
26,
267,
340,
283,
561,
19,
447,
27746,
20689,
4351,
4433,
7,
262,
1738,
63,
578,
26,
288,
1738,
63,
578,
14,
2888,
14,
2168,
8,
1231,
63,
578,
459,
561,
19,
447,
27746,
20689,
4351,
4433,
1105,
339,
340,
283,
13375,
386,
22511,
20689,
4351,
7,
440,
315,
5223,
63,
3179,
26,
267,
340,
283,
561,
19,
447,
13375,
386,
22511,
20689,
4351,
4433,
7,
262,
1738,
63,
578,
26,
288,
1738,
63,
578,
14,
2888,
14,
2168,
8,
1231,
63,
578,
459,
561,
19,
447,
13375,
386,
22511,
20689,
4351,
4433,
1105,
339,
340,
283,
20689,
4351,
7,
440,
315,
5223,
63,
3179,
26,
267,
367,
843,
354,
315,
788,
20689,
4351,
297,
283,
20689,
4351,
4433,
297,
283,
20689,
4351,
20689,
5929,
2565,
7205,
340,
283,
561,
19,
447,
5,
83,
7,
450,
843,
354,
315,
1738,
63,
578,
26,
355,
1738,
63,
578,
14,
2888,
14,
2168,
8,
1231,
63,
578,
459,
561,
19,
447,
5,
83,
7,
450,
843,
354,
566,
267,
340,
283,
561,
19,
447,
20689,
4351,
4433,
447,
1327,
12029,
5332,
1385,
7,
315,
1738,
63,
578,
26,
288,
1738,
63,
578,
14,
19921,
14,
2168,
8,
1231,
63,
578,
459,
561,
19,
447,
20689,
4351,
4433,
447,
1327,
12029,
5332,
1385,
1105,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
747,
199,
199,
318,
2963,
63,
2683,
63,
1313,
8,
1231,
63,
578,
304,
272,
5223,
63,
3179,
275,
747,
14,
2314,
459,
2709,
19,
63,
15704,
63,
13313,
2278,
1294,
11917,
339,
340,
283,
37,
6553,
20689,
4351,
7,
440,
315,
5223,
63,
3179,
26,
267,
340,
283,
561,
19,
447,
37,
6553,
20689,
4351,
4433,
7,
262,
1738,
63,
578,
26,
288,
1738,
63,
578,
14,
2888,
14,
2168,
8,
1231,
63,
578,
459,
561,
19,
447,
37,
6553,
20689,
4351,
4433,
1105,
339,
340,
283,
27746,
20689,
4351,
7,
440,
315,
5223,
63,
3179,
26,
267,
340,
283,
561,
19,
447,
27746,
20689,
4351,
4433,
7,
262,
1738,
63,
578,
26,
288,
1738,
63,
578,
14,
2888,
14,
2168,
8,
1231,
63,
578,
459,
561,
19,
447,
27746,
20689,
4351,
4433,
1105,
339,
340,
283,
13375,
386,
22511,
20689,
4351,
7,
440,
315,
5223,
63,
3179,
26,
267,
340,
283,
561,
19,
447,
13375,
386,
22511,
20689,
4351,
4433,
7,
262,
1738,
63,
578,
26,
288,
1738,
63,
578,
14,
2888,
14,
2168,
8,
1231,
63,
578,
459,
561,
19,
447,
13375,
386,
22511,
20689,
4351,
4433,
1105,
339,
340,
283,
20689,
4351,
7,
440,
315,
5223,
63,
3179,
26,
267,
367,
843,
354,
315,
788,
20689,
4351,
297,
283,
20689,
4351,
4433,
297,
283,
20689,
4351,
20689,
5929,
2565,
7205,
340,
283,
561,
19,
447,
5,
83,
7,
450,
843,
354,
315,
1738,
63,
578,
26,
355,
1738,
63,
578,
14,
2888,
14,
2168,
8,
1231,
63,
578,
459,
561,
19,
447,
5,
83,
7,
450,
843,
354,
566,
267,
340,
283,
561,
19,
447,
20689,
4351,
4433,
447,
1327,
12029,
5332,
1385,
7,
315,
1738,
63,
578,
26,
288,
1738,
63,
578,
14,
19921,
14,
2168,
8,
1231,
63,
578,
459,
561,
19,
447,
20689,
4351,
4433,
447,
1327,
12029,
5332,
1385,
1105,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mariosky/evo-drawings
|
venv/lib/python2.7/site-packages/pip/vendor/html5lib/trie/py.py
|
80
|
1774
|
from __future__ import absolute_import, division, unicode_literals
from pip.vendor.six import text_type
from bisect import bisect_left
from ._base import Trie as ABCTrie
class Trie(ABCTrie):
def __init__(self, data):
if not all(isinstance(x, text_type) for x in data.keys()):
raise TypeError("All keys must be strings")
self._data = data
self._keys = sorted(data.keys())
self._cachestr = ""
self._cachepoints = (0, len(data))
def __contains__(self, key):
return key in self._data
def __len__(self):
return len(self._data)
def __iter__(self):
return iter(self._data)
def __getitem__(self, key):
return self._data[key]
def keys(self, prefix=None):
if prefix is None or prefix == "" or not self._keys:
return set(self._keys)
if prefix.startswith(self._cachestr):
lo, hi = self._cachepoints
start = i = bisect_left(self._keys, prefix, lo, hi)
else:
start = i = bisect_left(self._keys, prefix)
keys = set()
if start == len(self._keys):
return keys
while self._keys[i].startswith(prefix):
keys.add(self._keys[i])
i += 1
self._cachestr = prefix
self._cachepoints = (start, i)
return keys
def has_keys_with_prefix(self, prefix):
if prefix in self._data:
return True
if prefix.startswith(self._cachestr):
lo, hi = self._cachepoints
i = bisect_left(self._keys, prefix, lo, hi)
else:
i = bisect_left(self._keys, prefix)
if i == len(self._keys):
return False
return self._keys[i].startswith(prefix)
|
agpl-3.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
504,
7305,
14,
9884,
14,
4174,
492,
1318,
63,
466,
199,
199,
504,
19063,
492,
19063,
63,
3039,
199,
199,
504,
13653,
1095,
492,
377,
11317,
465,
14840,
1028,
11317,
421,
199,
533,
377,
11317,
8,
1217,
1028,
11317,
304,
272,
347,
636,
826,
721,
277,
12,
666,
304,
267,
340,
440,
1006,
8,
6074,
8,
88,
12,
1318,
63,
466,
9,
367,
671,
315,
666,
14,
1612,
5109,
288,
746,
3146,
480,
2422,
2883,
1471,
506,
3326,
531,
398,
291,
423,
576,
275,
666,
267,
291,
423,
1612,
275,
3355,
8,
576,
14,
1612,
1012,
267,
291,
423,
1637,
495,
275,
3087,
267,
291,
423,
1637,
3438,
275,
334,
16,
12,
822,
8,
576,
430,
339,
347,
636,
6134,
721,
277,
12,
790,
304,
267,
372,
790,
315,
291,
423,
576,
339,
347,
636,
552,
721,
277,
304,
267,
372,
822,
8,
277,
423,
576,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
423,
576,
9,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
372,
291,
423,
576,
59,
498,
61,
339,
347,
2883,
8,
277,
12,
2403,
29,
403,
304,
267,
340,
2403,
365,
488,
503,
2403,
508,
3087,
503,
440,
291,
423,
1612,
26,
288,
372,
663,
8,
277,
423,
1612,
9,
398,
340,
2403,
14,
2460,
8,
277,
423,
1637,
495,
304,
288,
560,
12,
13759,
275,
291,
423,
1637,
3438,
288,
1343,
275,
284,
275,
19063,
63,
3039,
8,
277,
423,
1612,
12,
2403,
12,
560,
12,
13759,
9,
267,
587,
26,
288,
1343,
275,
284,
275,
19063,
63,
3039,
8,
277,
423,
1612,
12,
2403,
9,
398,
2883,
275,
663,
342,
267,
340,
1343,
508,
822,
8,
277,
423,
1612,
304,
288,
372,
2883,
398,
1830,
291,
423,
1612,
59,
73,
1055,
2460,
8,
1861,
304,
288,
2883,
14,
525,
8,
277,
423,
1612,
59,
73,
566,
288,
284,
847,
413,
398,
291,
423,
1637,
495,
275,
2403,
267,
291,
423,
1637,
3438,
275,
334,
928,
12,
284,
9,
398,
372,
2883,
339,
347,
965,
63,
1612,
63,
1045,
63,
1861,
8,
277,
12,
2403,
304,
267,
340,
2403,
315,
291,
423,
576,
26,
288,
372,
715,
398,
340,
2403,
14,
2460,
8,
277,
423,
1637,
495,
304,
288,
560,
12,
13759,
275,
291,
423,
1637,
3438,
288,
284,
275,
19063,
63,
3039,
8,
277,
423,
1612,
12,
2403,
12,
560,
12,
13759,
9,
267,
587,
26,
288,
284,
275,
19063,
63,
3039,
8,
277,
423,
1612,
12,
2403,
9,
398,
340,
284,
508,
822,
8,
277,
423,
1612,
304,
288,
372,
756,
398,
372,
291,
423,
1612,
59,
73,
1055,
2460,
8,
1861,
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
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
504,
7305,
14,
9884,
14,
4174,
492,
1318,
63,
466,
199,
199,
504,
19063,
492,
19063,
63,
3039,
199,
199,
504,
13653,
1095,
492,
377,
11317,
465,
14840,
1028,
11317,
421,
199,
533,
377,
11317,
8,
1217,
1028,
11317,
304,
272,
347,
636,
826,
721,
277,
12,
666,
304,
267,
340,
440,
1006,
8,
6074,
8,
88,
12,
1318,
63,
466,
9,
367,
671,
315,
666,
14,
1612,
5109,
288,
746,
3146,
480,
2422,
2883,
1471,
506,
3326,
531,
398,
291,
423,
576,
275,
666,
267,
291,
423,
1612,
275,
3355,
8,
576,
14,
1612,
1012,
267,
291,
423,
1637,
495,
275,
3087,
267,
291,
423,
1637,
3438,
275,
334,
16,
12,
822,
8,
576,
430,
339,
347,
636,
6134,
721,
277,
12,
790,
304,
267,
372,
790,
315,
291,
423,
576,
339,
347,
636,
552,
721,
277,
304,
267,
372,
822,
8,
277,
423,
576,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
423,
576,
9,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
372,
291,
423,
576,
59,
498,
61,
339,
347,
2883,
8,
277,
12,
2403,
29,
403,
304,
267,
340,
2403,
365,
488,
503,
2403,
508,
3087,
503,
440,
291,
423,
1612,
26,
288,
372,
663,
8,
277,
423,
1612,
9,
398,
340,
2403,
14,
2460,
8,
277,
423,
1637,
495,
304,
288,
560,
12,
13759,
275,
291,
423,
1637,
3438,
288,
1343,
275,
284,
275,
19063,
63,
3039,
8,
277,
423,
1612,
12,
2403,
12,
560,
12,
13759,
9,
267,
587,
26,
288,
1343,
275,
284,
275,
19063,
63,
3039,
8,
277,
423,
1612,
12,
2403,
9,
398,
2883,
275,
663,
342,
267,
340,
1343,
508,
822,
8,
277,
423,
1612,
304,
288,
372,
2883,
398,
1830,
291,
423,
1612,
59,
73,
1055,
2460,
8,
1861,
304,
288,
2883,
14,
525,
8,
277,
423,
1612,
59,
73,
566,
288,
284,
847,
413,
398,
291,
423,
1637,
495,
275,
2403,
267,
291,
423,
1637,
3438,
275,
334,
928,
12,
284,
9,
398,
372,
2883,
339,
347,
965,
63,
1612,
63,
1045,
63,
1861,
8,
277,
12,
2403,
304,
267,
340,
2403,
315,
291,
423,
576,
26,
288,
372,
715,
398,
340,
2403,
14,
2460,
8,
277,
423,
1637,
495,
304,
288,
560,
12,
13759,
275,
291,
423,
1637,
3438,
288,
284,
275,
19063,
63,
3039,
8,
277,
423,
1612,
12,
2403,
12,
560,
12,
13759,
9,
267,
587,
26,
288,
284,
275,
19063,
63,
3039,
8,
277,
423,
1612,
12,
2403,
9,
398,
340,
284,
508,
822,
8,
277,
423,
1612,
304,
288,
372,
756,
398,
372,
291,
423,
1612,
59,
73,
1055,
2460,
8,
1861,
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,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
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
rlkelly/Lasagne
|
lasagne/layers/base.py
|
1
|
10847
|
from collections import OrderedDict
from .. import utils
__all__ = [
"Layer",
"MergeLayer",
]
# Layer base class
class Layer(object):
"""
The :class:`Layer` class represents a single layer of a neural network. It
should be subclassed when implementing new types of layers.
Because each layer can keep track of the layer(s) feeding into it, a
network's output :class:`Layer` instance can double as a handle to the full
network.
"""
def __init__(self, incoming, name=None):
"""
Instantiates the layer.
Parameters
----------
incoming : a :class:`Layer` instance or a tuple
The layer feeding into this layer, or the expected input shape.
name : a string or None
An optional name to attach to this layer.
"""
if isinstance(incoming, tuple):
self.input_shape = incoming
self.input_layer = None
else:
self.input_shape = incoming.output_shape
self.input_layer = incoming
self.name = name
self.params = OrderedDict()
if any(d is not None and d <= 0 for d in self.input_shape):
raise ValueError((
"Cannot create Layer with a non-positive input_shape "
"dimension. input_shape=%r, self.name=%r") % (
self.input_shape, self.name))
@property
def output_shape(self):
return self.get_output_shape_for(self.input_shape)
def get_params(self, **tags):
"""
Returns a list of all the Theano variables that parameterize the layer.
By default, all parameters that participate in the forward pass will be
returned (in the order they were registered in the Layer's constructor
via :meth:`add_param()`). The list can optionally be filtered by
specifying tags as keyword arguments. For example, ``trainable=True``
will only return trainable parameters, and ``regularizable=True``
will only return parameters that can be regularized (e.g., by L2
decay).
Parameters
----------
**tags (optional)
tags can be specified to filter the list. Specifying ``tag1=True``
will limit the list to parameters that are tagged with ``tag1``.
Specifying ``tag1=False`` will limit the list to parameters that
are not tagged with ``tag1``. Commonly used tags are
``regularizable`` and ``trainable``.
Returns
-------
list of Theano shared variables
A list of variables that parameterize the layer
Notes
-----
For layers without any parameters, this will return an empty list.
"""
result = list(self.params.keys())
only = set(tag for tag, value in tags.items() if value)
if only:
# retain all parameters that have all of the tags in `only`
result = [param for param in result
if not (only - self.params[param])]
exclude = set(tag for tag, value in tags.items() if not value)
if exclude:
# retain all parameters that have none of the tags in `exclude`
result = [param for param in result
if not (self.params[param] & exclude)]
return result
def get_output_shape_for(self, input_shape):
"""
Computes the output shape of this layer, given an input shape.
Parameters
----------
input_shape : tuple
A tuple representing the shape of the input. The tuple should have
as many elements as there are input dimensions, and the elements
should be integers or `None`.
Returns
-------
tuple
A tuple representing the shape of the output of this layer. The
tuple has as many elements as there are output dimensions, and the
elements are all either integers or `None`.
Notes
-----
This method will typically be overridden when implementing a new
:class:`Layer` class. By default it simply returns the input
shape. This means that a layer that does not modify the shape
(e.g. because it applies an elementwise operation) does not need
to override this method.
"""
return input_shape
def get_output_for(self, input, **kwargs):
"""
Propagates the given input through this layer (and only this layer).
Parameters
----------
input : Theano expression
The expression to propagate through this layer.
Returns
-------
output : Theano expression
The output of this layer given the input to this layer.
Notes
-----
This is called by the base :meth:`lasagne.layers.get_output()`
to propagate data through a network.
This method should be overridden when implementing a new
:class:`Layer` class. By default it raises `NotImplementedError`.
"""
raise NotImplementedError
def add_param(self, spec, shape, name=None, **tags):
"""
Register and initialize a Theano shared variable containing parameters
associated with the layer.
When defining a new layer, this method can be used in the constructor
to define which parameters the layer has, what their shapes are, how
they should be initialized and what tags are associated with them.
All parameter variables associated with the layer can be retrieved
using :meth:`Layer.get_params()`.
Parameters
----------
spec : Theano shared variable, numpy array or callable
an initializer for this parameter variable. This should initialize
the variable with an array of the specified shape. See
:func:`lasagne.utils.create_param` for more information.
shape : tuple of int
a tuple of integers representing the desired shape of the
parameter array.
name : str (optional)
the name of the parameter variable. This will be passed to
``theano.shared`` when the variable is created. If ``spec`` is
already a shared variable, this parameter will be ignored to avoid
overwriting an existing name. If the layer itself has a name,
the name of the parameter variable will be prefixed with it and it
will be of the form 'layer_name.param_name'.
**tags (optional)
tags associated with the parameter variable can be specified as
keyword arguments.
To associate the tag ``tag1`` with the variable, pass
``tag1=True``.
By default, the tags ``regularizable`` and ``trainable`` are
associated with the parameter variable. Pass
``regularizable=False`` or ``trainable=False`` respectively to
prevent this.
Returns
-------
Theano shared variable
the resulting parameter variable
Notes
-----
It is recommend to assign the resulting parameter variable to an
attribute of the layer, so it can be accessed easily, for example:
>>> self.W = self.add_param(W, (2, 3), name='W') #doctest: +SKIP
"""
# prefix the param name with the layer name if it exists
if name is not None:
if self.name is not None:
name = "%s.%s" % (self.name, name)
param = utils.create_param(spec, shape, name)
# parameters should be trainable and regularizable by default
tags['trainable'] = tags.get('trainable', True)
tags['regularizable'] = tags.get('regularizable', True)
self.params[param] = set(tag for tag, value in tags.items() if value)
return param
class MergeLayer(Layer):
"""
This class represents a layer that aggregates input from multiple layers.
It should be subclassed when implementing new types of layers that obtain
their input from multiple layers.
"""
def __init__(self, incomings, name=None):
"""
Instantiates the layer.
Parameters
----------
incomings : a list of :class:`Layer` instances or tuples
The layers feeding into this layer, or expected input shapes.
name : a string or None
An optional name to attach to this layer.
"""
self.input_shapes = [incoming if isinstance(incoming, tuple)
else incoming.output_shape
for incoming in incomings]
self.input_layers = [None if isinstance(incoming, tuple)
else incoming
for incoming in incomings]
self.name = name
self.params = OrderedDict()
@Layer.output_shape.getter
def output_shape(self):
return self.get_output_shape_for(self.input_shapes)
def get_output_shape_for(self, input_shapes):
"""
Computes the output shape of this layer, given a list of input shapes.
Parameters
----------
input_shape : list of tuple
A list of tuples, with each tuple representing the shape of one of
the inputs (in the correct order). These tuples should have as many
elements as there are input dimensions, and the elements should be
integers or `None`.
Returns
-------
tuple
A tuple representing the shape of the output of this layer. The
tuple has as many elements as there are output dimensions, and the
elements are all either integers or `None`.
Notes
-----
This method must be overridden when implementing a new
:class:`Layer` class with multiple inputs. By default it raises
`NotImplementedError`.
"""
raise NotImplementedError
def get_output_for(self, inputs, **kwargs):
"""
Propagates the given inputs through this layer (and only this layer).
Parameters
----------
inputs : list of Theano expressions
The Theano expressions to propagate through this layer.
Returns
-------
Theano expressions
The output of this layer given the inputs to this layer.
Notes
-----
This is called by the base :meth:`lasagne.layers.get_output()`
to propagate data through a network.
This method should be overridden when implementing a new
:class:`Layer` class with multiple inputs. By default it raises
`NotImplementedError`.
"""
raise NotImplementedError
|
mit
|
[
504,
5055,
492,
8773,
199,
199,
504,
2508,
492,
3778,
421,
199,
363,
452,
363,
275,
359,
272,
298,
5003,
401,
272,
298,
11359,
5003,
401,
199,
61,
421,
199,
3,
11915,
1300,
1021,
199,
199,
533,
11915,
8,
785,
304,
272,
408,
272,
710,
520,
533,
1705,
5003,
64,
1021,
8469,
282,
2849,
4045,
402,
282,
1279,
4889,
2784,
14,
2779,
272,
1077,
506,
1007,
28271,
1380,
18234,
892,
2943,
402,
9393,
14,
339,
13821,
1924,
4045,
883,
4215,
4426,
402,
314,
4045,
8,
83,
9,
4733,
316,
1901,
652,
12,
282,
272,
2784,
1159,
1072,
520,
533,
1705,
5003,
64,
1256,
883,
4270,
465,
282,
2429,
370,
314,
2615,
272,
2784,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
12467,
12,
536,
29,
403,
304,
267,
408,
267,
14089,
4466,
2335,
314,
4045,
14,
398,
3897,
267,
4143,
267,
12467,
520,
282,
520,
533,
1705,
5003,
64,
1256,
503,
282,
2008,
288,
710,
4045,
4733,
316,
1901,
642,
4045,
12,
503,
314,
1420,
1324,
2215,
14,
267,
536,
520,
282,
1059,
503,
488,
288,
1626,
2716,
536,
370,
6554,
370,
642,
4045,
14,
267,
408,
267,
340,
1228,
8,
15994,
12,
2008,
304,
288,
291,
14,
1210,
63,
1392,
275,
12467,
288,
291,
14,
1210,
63,
1897,
275,
488,
267,
587,
26,
288,
291,
14,
1210,
63,
1392,
275,
12467,
14,
1199,
63,
1392,
288,
291,
14,
1210,
63,
1897,
275,
12467,
398,
291,
14,
354,
275,
536,
267,
291,
14,
1162,
275,
8773,
342,
398,
340,
1263,
8,
68,
365,
440,
488,
436,
366,
2695,
378,
367,
366,
315,
291,
14,
1210,
63,
1392,
304,
288,
746,
1722,
1332,
355,
298,
6612,
1218,
11915,
543,
282,
2222,
13,
8965,
1324,
63,
1392,
298,
355,
298,
7430,
14,
1324,
63,
1392,
2458,
82,
12,
291,
14,
354,
2458,
82,
531,
450,
334,
490,
291,
14,
1210,
63,
1392,
12,
291,
14,
354,
430,
339,
768,
1829,
272,
347,
1072,
63,
1392,
8,
277,
304,
267,
372,
291,
14,
362,
63,
1199,
63,
1392,
63,
509,
8,
277,
14,
1210,
63,
1392,
9,
339,
347,
664,
63,
1162,
8,
277,
12,
1011,
2969,
304,
267,
408,
267,
1803,
282,
769,
402,
1006,
314,
710,
8143,
2860,
626,
18117,
6236,
806,
314,
4045,
14,
398,
4885,
849,
12,
1006,
2633,
626,
623,
10479,
323,
315,
314,
7568,
986,
911,
506,
267,
2138,
334,
262,
314,
1865,
2985,
4898,
7264,
315,
314,
11915,
1159,
3787,
267,
4799,
520,
5247,
1705,
525,
63,
635,
11995,
680,
710,
769,
883,
14190,
506,
9806,
701,
267,
9176,
3762,
465,
4252,
2368,
14,
2104,
2893,
12,
1124,
18575,
29,
549,
1040,
267,
911,
1454,
372,
17029,
2633,
12,
436,
1124,
7898,
14065,
29,
549,
1040,
267,
911,
1454,
372,
2633,
626,
883,
506,
5578,
1759,
334,
69,
14,
71,
2020,
701,
491,
18,
267,
16696,
680,
398,
3897,
267,
4143,
267,
1011,
2969,
334,
4144,
9,
288,
3762,
883,
506,
2013,
370,
2457,
314,
769,
14,
13327,
316,
1124,
1450,
17,
29,
549,
1040,
288,
911,
2304,
314,
769,
370,
2633,
626,
787,
20018,
543,
1124,
1450,
17,
4345,
288,
13327,
316,
1124,
1450,
17,
29,
797,
1040,
911,
2304,
314,
769,
370,
2633,
626,
288,
787,
440,
20018,
543,
1124,
1450,
17,
4345,
7046,
2118,
1202,
3762,
787,
288,
1124,
7898,
14065,
1040,
436,
1124,
18575,
4345,
398,
1803,
267,
5514,
267,
769,
402,
710,
8143,
5709,
2860,
288,
437,
769,
402,
2860,
626,
18117,
6236,
806,
314,
4045,
398,
8144,
267,
9063,
267,
2104,
9393,
1928,
1263,
2633,
12,
642,
911,
372,
376,
2701,
769,
14,
267,
408,
267,
754,
275,
769,
8,
277,
14,
1162,
14,
1612,
1012,
398,
1454,
275,
663,
8,
1450,
367,
1947,
12,
574,
315,
3762,
14,
1744,
342,
340,
574,
9,
267,
340,
1454,
26,
288,
327,
8074,
1006,
2633,
626,
1172,
1006,
402,
314,
3762,
315,
658,
2118,
64,
288,
754,
275,
359,
635,
367,
1215,
315,
754,
1993,
340,
440,
334,
2118,
446,
291,
14,
1162,
59,
635,
12457,
398,
5760,
275,
663,
8,
1450,
367,
1947,
12,
574,
315,
3762,
14,
1744,
342,
340,
440,
574,
9,
267,
340,
5760,
26,
288,
327,
8074,
1006,
2633,
626,
1172,
7179,
402,
314,
3762,
315,
658,
5473,
64,
288,
754,
275,
359,
635,
367,
1215,
315,
754,
1993,
340,
440,
334,
277,
14,
1162,
59,
635,
61,
1253,
5760,
1874,
398,
372,
754,
339,
347,
664,
63,
1199,
63,
1392,
63,
509,
8,
277,
12,
1324,
63,
1392,
304,
267,
408,
267,
28040,
314,
1072,
2215,
402,
642,
4045,
12,
1627,
376,
1324,
2215,
14,
398,
3897,
267,
4143,
267,
1324,
63,
1392,
520,
2008,
288,
437,
2008,
6144,
314,
2215,
402,
314,
1324,
14,
710,
2008,
1077,
1172,
288,
465,
5002,
4008,
465,
2337,
787,
1324,
7365,
12,
436,
314,
4008,
288,
1077,
506,
9446,
503,
658,
403,
2313,
398,
1803,
267,
5514,
267,
2008,
288,
437,
2008,
6144,
314,
2215,
402,
314,
1072,
402,
642,
4045,
14,
710,
288,
2008,
965,
465,
5002,
4008,
465,
2337,
787,
1072,
7365,
12,
436,
314,
288,
4008,
787,
1006,
1902,
9446,
503,
658,
403,
2313,
398,
8144,
267,
9063,
267,
961,
1083,
911,
13609,
506,
10087,
1380,
18234,
282,
892,
267,
520,
533,
1705,
5003,
64,
1021,
14,
4885,
849,
652,
9329,
2529,
314,
1324,
267,
2215,
14,
961,
4910,
626,
282,
4045,
626,
1630,
440,
2811,
314,
2215,
267,
334,
69,
14,
71,
14,
2952,
652,
12966,
376,
1819,
2605,
3439,
9,
1630,
440,
1929,
267,
370,
4278,
642,
1083,
14,
267,
408,
267,
372,
1324,
63,
1392,
339,
347,
664,
63,
1199,
63,
509,
8,
277,
12,
1324,
12,
1011,
958,
304,
267,
408,
267,
2165,
15351,
2335,
314,
1627,
1324,
4012,
642,
4045,
334,
460,
1454,
642,
4045,
680,
398,
3897,
267,
4143,
267,
1324,
520,
710,
8143,
3965,
288,
710,
3965,
370,
19843,
4012,
642,
4045,
14,
398,
1803,
267,
5514,
267,
1072,
520,
710,
8143,
3965,
288,
710,
1072,
402,
642,
4045,
1627,
314,
1324,
370,
642,
4045,
14,
7318,
8144,
267,
9063,
267,
961,
365,
2797,
701,
314,
1300,
520,
5247,
1705,
12536,
29575,
14,
4359,
14,
362,
63,
1199,
11995,
267,
370
] |
[
5055,
492,
8773,
199,
199,
504,
2508,
492,
3778,
421,
199,
363,
452,
363,
275,
359,
272,
298,
5003,
401,
272,
298,
11359,
5003,
401,
199,
61,
421,
199,
3,
11915,
1300,
1021,
199,
199,
533,
11915,
8,
785,
304,
272,
408,
272,
710,
520,
533,
1705,
5003,
64,
1021,
8469,
282,
2849,
4045,
402,
282,
1279,
4889,
2784,
14,
2779,
272,
1077,
506,
1007,
28271,
1380,
18234,
892,
2943,
402,
9393,
14,
339,
13821,
1924,
4045,
883,
4215,
4426,
402,
314,
4045,
8,
83,
9,
4733,
316,
1901,
652,
12,
282,
272,
2784,
1159,
1072,
520,
533,
1705,
5003,
64,
1256,
883,
4270,
465,
282,
2429,
370,
314,
2615,
272,
2784,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
12467,
12,
536,
29,
403,
304,
267,
408,
267,
14089,
4466,
2335,
314,
4045,
14,
398,
3897,
267,
4143,
267,
12467,
520,
282,
520,
533,
1705,
5003,
64,
1256,
503,
282,
2008,
288,
710,
4045,
4733,
316,
1901,
642,
4045,
12,
503,
314,
1420,
1324,
2215,
14,
267,
536,
520,
282,
1059,
503,
488,
288,
1626,
2716,
536,
370,
6554,
370,
642,
4045,
14,
267,
408,
267,
340,
1228,
8,
15994,
12,
2008,
304,
288,
291,
14,
1210,
63,
1392,
275,
12467,
288,
291,
14,
1210,
63,
1897,
275,
488,
267,
587,
26,
288,
291,
14,
1210,
63,
1392,
275,
12467,
14,
1199,
63,
1392,
288,
291,
14,
1210,
63,
1897,
275,
12467,
398,
291,
14,
354,
275,
536,
267,
291,
14,
1162,
275,
8773,
342,
398,
340,
1263,
8,
68,
365,
440,
488,
436,
366,
2695,
378,
367,
366,
315,
291,
14,
1210,
63,
1392,
304,
288,
746,
1722,
1332,
355,
298,
6612,
1218,
11915,
543,
282,
2222,
13,
8965,
1324,
63,
1392,
298,
355,
298,
7430,
14,
1324,
63,
1392,
2458,
82,
12,
291,
14,
354,
2458,
82,
531,
450,
334,
490,
291,
14,
1210,
63,
1392,
12,
291,
14,
354,
430,
339,
768,
1829,
272,
347,
1072,
63,
1392,
8,
277,
304,
267,
372,
291,
14,
362,
63,
1199,
63,
1392,
63,
509,
8,
277,
14,
1210,
63,
1392,
9,
339,
347,
664,
63,
1162,
8,
277,
12,
1011,
2969,
304,
267,
408,
267,
1803,
282,
769,
402,
1006,
314,
710,
8143,
2860,
626,
18117,
6236,
806,
314,
4045,
14,
398,
4885,
849,
12,
1006,
2633,
626,
623,
10479,
323,
315,
314,
7568,
986,
911,
506,
267,
2138,
334,
262,
314,
1865,
2985,
4898,
7264,
315,
314,
11915,
1159,
3787,
267,
4799,
520,
5247,
1705,
525,
63,
635,
11995,
680,
710,
769,
883,
14190,
506,
9806,
701,
267,
9176,
3762,
465,
4252,
2368,
14,
2104,
2893,
12,
1124,
18575,
29,
549,
1040,
267,
911,
1454,
372,
17029,
2633,
12,
436,
1124,
7898,
14065,
29,
549,
1040,
267,
911,
1454,
372,
2633,
626,
883,
506,
5578,
1759,
334,
69,
14,
71,
2020,
701,
491,
18,
267,
16696,
680,
398,
3897,
267,
4143,
267,
1011,
2969,
334,
4144,
9,
288,
3762,
883,
506,
2013,
370,
2457,
314,
769,
14,
13327,
316,
1124,
1450,
17,
29,
549,
1040,
288,
911,
2304,
314,
769,
370,
2633,
626,
787,
20018,
543,
1124,
1450,
17,
4345,
288,
13327,
316,
1124,
1450,
17,
29,
797,
1040,
911,
2304,
314,
769,
370,
2633,
626,
288,
787,
440,
20018,
543,
1124,
1450,
17,
4345,
7046,
2118,
1202,
3762,
787,
288,
1124,
7898,
14065,
1040,
436,
1124,
18575,
4345,
398,
1803,
267,
5514,
267,
769,
402,
710,
8143,
5709,
2860,
288,
437,
769,
402,
2860,
626,
18117,
6236,
806,
314,
4045,
398,
8144,
267,
9063,
267,
2104,
9393,
1928,
1263,
2633,
12,
642,
911,
372,
376,
2701,
769,
14,
267,
408,
267,
754,
275,
769,
8,
277,
14,
1162,
14,
1612,
1012,
398,
1454,
275,
663,
8,
1450,
367,
1947,
12,
574,
315,
3762,
14,
1744,
342,
340,
574,
9,
267,
340,
1454,
26,
288,
327,
8074,
1006,
2633,
626,
1172,
1006,
402,
314,
3762,
315,
658,
2118,
64,
288,
754,
275,
359,
635,
367,
1215,
315,
754,
1993,
340,
440,
334,
2118,
446,
291,
14,
1162,
59,
635,
12457,
398,
5760,
275,
663,
8,
1450,
367,
1947,
12,
574,
315,
3762,
14,
1744,
342,
340,
440,
574,
9,
267,
340,
5760,
26,
288,
327,
8074,
1006,
2633,
626,
1172,
7179,
402,
314,
3762,
315,
658,
5473,
64,
288,
754,
275,
359,
635,
367,
1215,
315,
754,
1993,
340,
440,
334,
277,
14,
1162,
59,
635,
61,
1253,
5760,
1874,
398,
372,
754,
339,
347,
664,
63,
1199,
63,
1392,
63,
509,
8,
277,
12,
1324,
63,
1392,
304,
267,
408,
267,
28040,
314,
1072,
2215,
402,
642,
4045,
12,
1627,
376,
1324,
2215,
14,
398,
3897,
267,
4143,
267,
1324,
63,
1392,
520,
2008,
288,
437,
2008,
6144,
314,
2215,
402,
314,
1324,
14,
710,
2008,
1077,
1172,
288,
465,
5002,
4008,
465,
2337,
787,
1324,
7365,
12,
436,
314,
4008,
288,
1077,
506,
9446,
503,
658,
403,
2313,
398,
1803,
267,
5514,
267,
2008,
288,
437,
2008,
6144,
314,
2215,
402,
314,
1072,
402,
642,
4045,
14,
710,
288,
2008,
965,
465,
5002,
4008,
465,
2337,
787,
1072,
7365,
12,
436,
314,
288,
4008,
787,
1006,
1902,
9446,
503,
658,
403,
2313,
398,
8144,
267,
9063,
267,
961,
1083,
911,
13609,
506,
10087,
1380,
18234,
282,
892,
267,
520,
533,
1705,
5003,
64,
1021,
14,
4885,
849,
652,
9329,
2529,
314,
1324,
267,
2215,
14,
961,
4910,
626,
282,
4045,
626,
1630,
440,
2811,
314,
2215,
267,
334,
69,
14,
71,
14,
2952,
652,
12966,
376,
1819,
2605,
3439,
9,
1630,
440,
1929,
267,
370,
4278,
642,
1083,
14,
267,
408,
267,
372,
1324,
63,
1392,
339,
347,
664,
63,
1199,
63,
509,
8,
277,
12,
1324,
12,
1011,
958,
304,
267,
408,
267,
2165,
15351,
2335,
314,
1627,
1324,
4012,
642,
4045,
334,
460,
1454,
642,
4045,
680,
398,
3897,
267,
4143,
267,
1324,
520,
710,
8143,
3965,
288,
710,
3965,
370,
19843,
4012,
642,
4045,
14,
398,
1803,
267,
5514,
267,
1072,
520,
710,
8143,
3965,
288,
710,
1072,
402,
642,
4045,
1627,
314,
1324,
370,
642,
4045,
14,
7318,
8144,
267,
9063,
267,
961,
365,
2797,
701,
314,
1300,
520,
5247,
1705,
12536,
29575,
14,
4359,
14,
362,
63,
1199,
11995,
267,
370,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
adamjerickson/namerizer
|
node_modules/grunt-sass/node_modules/node-sass/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py
|
2698
|
3270
|
#!/usr/bin/env python
# Copyright (c) 2011 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
""" Unit tests for the easy_xml.py file. """
import gyp.easy_xml as easy_xml
import unittest
import StringIO
class TestSequenceFunctions(unittest.TestCase):
def setUp(self):
self.stderr = StringIO.StringIO()
def test_EasyXml_simple(self):
self.assertEqual(
easy_xml.XmlToString(['test']),
'<?xml version="1.0" encoding="utf-8"?><test/>')
self.assertEqual(
easy_xml.XmlToString(['test'], encoding='Windows-1252'),
'<?xml version="1.0" encoding="Windows-1252"?><test/>')
def test_EasyXml_simple_with_attributes(self):
self.assertEqual(
easy_xml.XmlToString(['test2', {'a': 'value1', 'b': 'value2'}]),
'<?xml version="1.0" encoding="utf-8"?><test2 a="value1" b="value2"/>')
def test_EasyXml_escaping(self):
original = '<test>\'"\r&\nfoo'
converted = '<test>\'"
&
foo'
converted_apos = converted.replace("'", ''')
self.assertEqual(
easy_xml.XmlToString(['test3', {'a': original}, original]),
'<?xml version="1.0" encoding="utf-8"?><test3 a="%s">%s</test3>' %
(converted, converted_apos))
def test_EasyXml_pretty(self):
self.assertEqual(
easy_xml.XmlToString(
['test3',
['GrandParent',
['Parent1',
['Child']
],
['Parent2']
]
],
pretty=True),
'<?xml version="1.0" encoding="utf-8"?>\n'
'<test3>\n'
' <GrandParent>\n'
' <Parent1>\n'
' <Child/>\n'
' </Parent1>\n'
' <Parent2/>\n'
' </GrandParent>\n'
'</test3>\n')
def test_EasyXml_complex(self):
# We want to create:
target = (
'<?xml version="1.0" encoding="utf-8"?>'
'<Project>'
'<PropertyGroup Label="Globals">'
'<ProjectGuid>{D2250C20-3A94-4FB9-AF73-11BC5B73884B}</ProjectGuid>'
'<Keyword>Win32Proj</Keyword>'
'<RootNamespace>automated_ui_tests</RootNamespace>'
'</PropertyGroup>'
'<Import Project="$(VCTargetsPath)\\Microsoft.Cpp.props"/>'
'<PropertyGroup '
'Condition="\'$(Configuration)|$(Platform)\'=='
'\'Debug|Win32\'" Label="Configuration">'
'<ConfigurationType>Application</ConfigurationType>'
'<CharacterSet>Unicode</CharacterSet>'
'</PropertyGroup>'
'</Project>')
xml = easy_xml.XmlToString(
['Project',
['PropertyGroup', {'Label': 'Globals'},
['ProjectGuid', '{D2250C20-3A94-4FB9-AF73-11BC5B73884B}'],
['Keyword', 'Win32Proj'],
['RootNamespace', 'automated_ui_tests']
],
['Import', {'Project': '$(VCTargetsPath)\\Microsoft.Cpp.props'}],
['PropertyGroup',
{'Condition': "'$(Configuration)|$(Platform)'=='Debug|Win32'",
'Label': 'Configuration'},
['ConfigurationType', 'Application'],
['CharacterSet', 'Unicode']
]
])
self.assertEqual(xml, target)
if __name__ == '__main__':
unittest.main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
7760,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
12008,
2295,
367,
314,
8837,
63,
1652,
14,
647,
570,
14,
408,
199,
199,
646,
4902,
14,
13581,
63,
1652,
465,
8837,
63,
1652,
199,
646,
2882,
199,
646,
5228,
421,
199,
533,
1379,
5826,
13967,
8,
2796,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
291,
14,
3083,
275,
5228,
14,
6424,
342,
819,
347,
511,
63,
28326,
8672,
63,
4129,
8,
277,
304,
272,
291,
14,
629,
8,
489,
8837,
63,
1652,
14,
8672,
7756,
2941,
396,
3815,
489,
2650,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
1624,
13,
24,
14863,
2535,
396,
3133,
358,
339,
291,
14,
629,
8,
489,
8837,
63,
1652,
14,
8672,
7756,
2941,
396,
995,
2644,
534,
8647,
13,
19364,
659,
489,
2650,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
8647,
13,
19364,
14863,
2535,
396,
3133,
358,
819,
347,
511,
63,
28326,
8672,
63,
4129,
63,
1045,
63,
2987,
8,
277,
304,
272,
291,
14,
629,
8,
489,
8837,
63,
1652,
14,
8672,
7756,
2941,
396,
18,
297,
791,
65,
356,
283,
585,
17,
297,
283,
66,
356,
283,
585,
18,
936,
2522,
489,
2650,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
1624,
13,
24,
14863,
2535,
396,
18,
282,
628,
585,
17,
2,
330,
628,
585,
18,
7897,
358,
819,
347,
511,
63,
28326,
8672,
63,
26306,
8,
277,
304,
272,
3379,
275,
2650,
396,
3072,
7,
3212,
82,
28103,
78,
1421,
7,
272,
6702,
275,
7673,
4116,
27,
396,
6,
3308,
3779,
21840,
5184,
14328,
8313,
15337,
5282,
14328,
7471,
27,
1421,
7,
272,
6702,
63,
439,
736,
275,
6702,
14,
1814,
27769,
7673,
439,
736,
10784,
272,
291,
14,
629,
8,
489,
8837,
63,
1652,
14,
8672,
7756,
2941,
396,
19,
297,
791,
65,
356,
3379,
1386,
3379,
2522,
489,
2650,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
1624,
13,
24,
14863,
2535,
396,
19,
282,
5961,
83,
14423,
83,
1108,
396,
19,
3524,
450,
489,
334,
22818,
12,
6702,
63,
439,
736,
430,
819,
347,
511,
63,
28326,
8672,
63,
9118,
8,
277,
304,
272,
291,
14,
629,
8,
489,
8837,
63,
1652,
14,
8672,
7756,
8,
881,
788,
396,
19,
297,
288,
788,
39,
3759,
6652,
297,
1598,
788,
6652,
17,
297,
355,
788,
3493,
418,
1598,
2156,
1598,
788,
6652,
18,
418,
288,
1622,
881,
2156,
881,
7268,
29,
549,
395,
489,
2650,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
1624,
13,
24,
14863,
3072,
78,
7,
489,
2650,
396,
19,
3072,
78,
7,
489,
283,
221,
665,
39,
3759,
6652,
3072,
78,
7,
489,
283,
259,
665,
6652,
17,
3072,
78,
7,
489,
283,
420,
665,
3493,
15,
3072,
78,
7,
489,
283,
259,
3068,
6652,
17,
3072,
78,
7,
489,
283,
259,
665,
6652,
18,
15,
3072,
78,
7,
489,
283,
221,
3068,
39,
3759,
6652,
3072,
78,
7,
489,
11936,
396,
19,
3072,
78,
358,
8330,
347,
511,
63,
28326,
8672,
63,
5254,
8,
277,
304,
272,
327,
2136,
2934,
370,
1218,
26,
272,
1347,
275,
334,
489,
2650,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
1624,
13,
24,
14863,
3524,
489,
2650,
4761,
3524,
267,
2650,
3697,
2448,
10354,
628,
21675,
15603,
881,
2650,
4761,
18834,
22266,
36,
18,
7991,
35,
1165,
13,
19,
33,
2635,
13,
20,
8223,
25,
13,
5699,
2898,
13,
845,
6265,
21,
34,
2898,
16303,
34,
17890,
4761,
18834,
3524,
881,
2650,
10650,
30,
8886,
708,
23657,
1108,
10650,
3524,
881,
2650,
6405,
8814,
30,
6898,
23513,
63,
1907,
63,
2219,
1108,
6405,
8814,
3524,
267,
11936,
3697,
2448,
3524,
267,
2650,
6295,
7290,
628,
6629,
54,
32380,
83,
2042,
22532,
12940,
14,
19705,
14,
6750,
7897,
7,
267,
2650,
3697,
2448,
283,
288,
283,
9558,
628,
3985,
6629,
5688,
8636,
6629,
10397,
2862,
7,
6803,
2432,
32496,
7084,
92,
8886,
708,
3985,
2,
10354,
628,
5688,
15603,
881,
2650,
5688,
804,
30,
5039,
1108,
5688,
804,
3524,
881,
2650,
14852,
1084,
30,
7087,
1108,
14852,
1084,
3524,
267,
11936,
3697,
2448,
3524,
489,
11936,
4761,
5971,
339,
2748,
275,
8837,
63,
1652,
14,
8672,
7756,
8,
267,
788,
4761,
297,
881,
788,
3697,
2448,
297,
791,
4314,
356,
283,
21675,
2267,
288,
788,
4761,
18834,
297,
5041,
36,
18,
7991,
35,
1165,
13,
19,
33,
2635,
13,
20,
8223,
25,
13,
5699,
2898,
13,
845,
6265,
21,
34,
2898,
16303,
34,
93,
995,
288,
788,
10650,
297,
283,
8886,
708,
23657,
995,
288,
788,
6405,
8814,
297,
283,
6898,
23513,
63,
1907,
63,
2219,
418,
881,
2156,
881,
788,
6295,
297,
791,
4761,
356,
9774,
54,
32380,
83,
2042,
22532,
12940,
14,
19705,
14,
6750,
24371,
881,
788,
3697,
2448,
297,
288,
791,
9558,
356,
3546,
6629,
5688,
8636,
6629,
10397,
3171,
6803,
7084,
92,
8886,
708,
4662,
1467,
283,
4314,
356,
283,
5688,
2267,
288,
788,
5688,
804,
297,
283,
5039,
995,
288,
788,
14852,
1084,
297,
283,
7087,
418,
881,
1622,
267,
4794,
272,
291,
14,
629,
8,
1652,
12,
1347,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
7760,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
12008,
2295,
367,
314,
8837,
63,
1652,
14,
647,
570,
14,
408,
199,
199,
646,
4902,
14,
13581,
63,
1652,
465,
8837,
63,
1652,
199,
646,
2882,
199,
646,
5228,
421,
199,
533,
1379,
5826,
13967,
8,
2796,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
291,
14,
3083,
275,
5228,
14,
6424,
342,
819,
347,
511,
63,
28326,
8672,
63,
4129,
8,
277,
304,
272,
291,
14,
629,
8,
489,
8837,
63,
1652,
14,
8672,
7756,
2941,
396,
3815,
489,
2650,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
1624,
13,
24,
14863,
2535,
396,
3133,
358,
339,
291,
14,
629,
8,
489,
8837,
63,
1652,
14,
8672,
7756,
2941,
396,
995,
2644,
534,
8647,
13,
19364,
659,
489,
2650,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
8647,
13,
19364,
14863,
2535,
396,
3133,
358,
819,
347,
511,
63,
28326,
8672,
63,
4129,
63,
1045,
63,
2987,
8,
277,
304,
272,
291,
14,
629,
8,
489,
8837,
63,
1652,
14,
8672,
7756,
2941,
396,
18,
297,
791,
65,
356,
283,
585,
17,
297,
283,
66,
356,
283,
585,
18,
936,
2522,
489,
2650,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
1624,
13,
24,
14863,
2535,
396,
18,
282,
628,
585,
17,
2,
330,
628,
585,
18,
7897,
358,
819,
347,
511,
63,
28326,
8672,
63,
26306,
8,
277,
304,
272,
3379,
275,
2650,
396,
3072,
7,
3212,
82,
28103,
78,
1421,
7,
272,
6702,
275,
7673,
4116,
27,
396,
6,
3308,
3779,
21840,
5184,
14328,
8313,
15337,
5282,
14328,
7471,
27,
1421,
7,
272,
6702,
63,
439,
736,
275,
6702,
14,
1814,
27769,
7673,
439,
736,
10784,
272,
291,
14,
629,
8,
489,
8837,
63,
1652,
14,
8672,
7756,
2941,
396,
19,
297,
791,
65,
356,
3379,
1386,
3379,
2522,
489,
2650,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
1624,
13,
24,
14863,
2535,
396,
19,
282,
5961,
83,
14423,
83,
1108,
396,
19,
3524,
450,
489,
334,
22818,
12,
6702,
63,
439,
736,
430,
819,
347,
511,
63,
28326,
8672,
63,
9118,
8,
277,
304,
272,
291,
14,
629,
8,
489,
8837,
63,
1652,
14,
8672,
7756,
8,
881,
788,
396,
19,
297,
288,
788,
39,
3759,
6652,
297,
1598,
788,
6652,
17,
297,
355,
788,
3493,
418,
1598,
2156,
1598,
788,
6652,
18,
418,
288,
1622,
881,
2156,
881,
7268,
29,
549,
395,
489,
2650,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
1624,
13,
24,
14863,
3072,
78,
7,
489,
2650,
396,
19,
3072,
78,
7,
489,
283,
221,
665,
39,
3759,
6652,
3072,
78,
7,
489,
283,
259,
665,
6652,
17,
3072,
78,
7,
489,
283,
420,
665,
3493,
15,
3072,
78,
7,
489,
283,
259,
3068,
6652,
17,
3072,
78,
7,
489,
283,
259,
665,
6652,
18,
15,
3072,
78,
7,
489,
283,
221,
3068,
39,
3759,
6652,
3072,
78,
7,
489,
11936,
396,
19,
3072,
78,
358,
8330,
347,
511,
63,
28326,
8672,
63,
5254,
8,
277,
304,
272,
327,
2136,
2934,
370,
1218,
26,
272,
1347,
275,
334,
489,
2650,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
1624,
13,
24,
14863,
3524,
489,
2650,
4761,
3524,
267,
2650,
3697,
2448,
10354,
628,
21675,
15603,
881,
2650,
4761,
18834,
22266,
36,
18,
7991,
35,
1165,
13,
19,
33,
2635,
13,
20,
8223,
25,
13,
5699,
2898,
13,
845,
6265,
21,
34,
2898,
16303,
34,
17890,
4761,
18834,
3524,
881,
2650,
10650,
30,
8886,
708,
23657,
1108,
10650,
3524,
881,
2650,
6405,
8814,
30,
6898,
23513,
63,
1907,
63,
2219,
1108,
6405,
8814,
3524,
267,
11936,
3697,
2448,
3524,
267,
2650,
6295,
7290,
628,
6629,
54,
32380,
83,
2042,
22532,
12940,
14,
19705,
14,
6750,
7897,
7,
267,
2650,
3697,
2448,
283,
288,
283,
9558,
628,
3985,
6629,
5688,
8636,
6629,
10397,
2862,
7,
6803,
2432,
32496,
7084,
92,
8886,
708,
3985,
2,
10354,
628,
5688,
15603,
881,
2650,
5688,
804,
30,
5039,
1108,
5688,
804,
3524,
881,
2650,
14852,
1084,
30,
7087,
1108,
14852,
1084,
3524,
267,
11936,
3697,
2448,
3524,
489,
11936,
4761,
5971,
339,
2748,
275,
8837,
63,
1652,
14,
8672,
7756,
8,
267,
788,
4761,
297,
881,
788,
3697,
2448,
297,
791,
4314,
356,
283,
21675,
2267,
288,
788,
4761,
18834,
297,
5041,
36,
18,
7991,
35,
1165,
13,
19,
33,
2635,
13,
20,
8223,
25,
13,
5699,
2898,
13,
845,
6265,
21,
34,
2898,
16303,
34,
93,
995,
288,
788,
10650,
297,
283,
8886,
708,
23657,
995,
288,
788,
6405,
8814,
297,
283,
6898,
23513,
63,
1907,
63,
2219,
418,
881,
2156,
881,
788,
6295,
297,
791,
4761,
356,
9774,
54,
32380,
83,
2042,
22532,
12940,
14,
19705,
14,
6750,
24371,
881,
788,
3697,
2448,
297,
288,
791,
9558,
356,
3546,
6629,
5688,
8636,
6629,
10397,
3171,
6803,
7084,
92,
8886,
708,
4662,
1467,
283,
4314,
356,
283,
5688,
2267,
288,
788,
5688,
804,
297,
283,
5039,
995,
288,
788,
14852,
1084,
297,
283,
7087,
418,
881,
1622,
267,
4794,
272,
291,
14,
629,
8,
1652,
12,
1347,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
evankroske/broken_link_reporter
|
third_party/gtest-1.7.0/scripts/pump.py
|
2471
|
23673
|
#!/usr/bin/env python
#
# Copyright 2008, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""pump v0.2.0 - Pretty Useful for Meta Programming.
A tool for preprocessor meta programming. Useful for generating
repetitive boilerplate code. Especially useful for writing C++
classes, functions, macros, and templates that need to work with
various number of arguments.
USAGE:
pump.py SOURCE_FILE
EXAMPLES:
pump.py foo.cc.pump
Converts foo.cc.pump to foo.cc.
GRAMMAR:
CODE ::= ATOMIC_CODE*
ATOMIC_CODE ::= $var ID = EXPRESSION
| $var ID = [[ CODE ]]
| $range ID EXPRESSION..EXPRESSION
| $for ID SEPARATOR [[ CODE ]]
| $($)
| $ID
| $(EXPRESSION)
| $if EXPRESSION [[ CODE ]] ELSE_BRANCH
| [[ CODE ]]
| RAW_CODE
SEPARATOR ::= RAW_CODE | EMPTY
ELSE_BRANCH ::= $else [[ CODE ]]
| $elif EXPRESSION [[ CODE ]] ELSE_BRANCH
| EMPTY
EXPRESSION has Python syntax.
"""
__author__ = 'wan@google.com (Zhanyong Wan)'
import os
import re
import sys
TOKEN_TABLE = [
(re.compile(r'\$var\s+'), '$var'),
(re.compile(r'\$elif\s+'), '$elif'),
(re.compile(r'\$else\s+'), '$else'),
(re.compile(r'\$for\s+'), '$for'),
(re.compile(r'\$if\s+'), '$if'),
(re.compile(r'\$range\s+'), '$range'),
(re.compile(r'\$[_A-Za-z]\w*'), '$id'),
(re.compile(r'\$\(\$\)'), '$($)'),
(re.compile(r'\$'), '$'),
(re.compile(r'\[\[\n?'), '[['),
(re.compile(r'\]\]\n?'), ']]'),
]
class Cursor:
"""Represents a position (line and column) in a text file."""
def __init__(self, line=-1, column=-1):
self.line = line
self.column = column
def __eq__(self, rhs):
return self.line == rhs.line and self.column == rhs.column
def __ne__(self, rhs):
return not self == rhs
def __lt__(self, rhs):
return self.line < rhs.line or (
self.line == rhs.line and self.column < rhs.column)
def __le__(self, rhs):
return self < rhs or self == rhs
def __gt__(self, rhs):
return rhs < self
def __ge__(self, rhs):
return rhs <= self
def __str__(self):
if self == Eof():
return 'EOF'
else:
return '%s(%s)' % (self.line + 1, self.column)
def __add__(self, offset):
return Cursor(self.line, self.column + offset)
def __sub__(self, offset):
return Cursor(self.line, self.column - offset)
def Clone(self):
"""Returns a copy of self."""
return Cursor(self.line, self.column)
# Special cursor to indicate the end-of-file.
def Eof():
"""Returns the special cursor to denote the end-of-file."""
return Cursor(-1, -1)
class Token:
"""Represents a token in a Pump source file."""
def __init__(self, start=None, end=None, value=None, token_type=None):
if start is None:
self.start = Eof()
else:
self.start = start
if end is None:
self.end = Eof()
else:
self.end = end
self.value = value
self.token_type = token_type
def __str__(self):
return 'Token @%s: \'%s\' type=%s' % (
self.start, self.value, self.token_type)
def Clone(self):
"""Returns a copy of self."""
return Token(self.start.Clone(), self.end.Clone(), self.value,
self.token_type)
def StartsWith(lines, pos, string):
"""Returns True iff the given position in lines starts with 'string'."""
return lines[pos.line][pos.column:].startswith(string)
def FindFirstInLine(line, token_table):
best_match_start = -1
for (regex, token_type) in token_table:
m = regex.search(line)
if m:
# We found regex in lines
if best_match_start < 0 or m.start() < best_match_start:
best_match_start = m.start()
best_match_length = m.end() - m.start()
best_match_token_type = token_type
if best_match_start < 0:
return None
return (best_match_start, best_match_length, best_match_token_type)
def FindFirst(lines, token_table, cursor):
"""Finds the first occurrence of any string in strings in lines."""
start = cursor.Clone()
cur_line_number = cursor.line
for line in lines[start.line:]:
if cur_line_number == start.line:
line = line[start.column:]
m = FindFirstInLine(line, token_table)
if m:
# We found a regex in line.
(start_column, length, token_type) = m
if cur_line_number == start.line:
start_column += start.column
found_start = Cursor(cur_line_number, start_column)
found_end = found_start + length
return MakeToken(lines, found_start, found_end, token_type)
cur_line_number += 1
# We failed to find str in lines
return None
def SubString(lines, start, end):
"""Returns a substring in lines."""
if end == Eof():
end = Cursor(len(lines) - 1, len(lines[-1]))
if start >= end:
return ''
if start.line == end.line:
return lines[start.line][start.column:end.column]
result_lines = ([lines[start.line][start.column:]] +
lines[start.line + 1:end.line] +
[lines[end.line][:end.column]])
return ''.join(result_lines)
def StripMetaComments(str):
"""Strip meta comments from each line in the given string."""
# First, completely remove lines containing nothing but a meta
# comment, including the trailing \n.
str = re.sub(r'^\s*\$\$.*\n', '', str)
# Then, remove meta comments from contentful lines.
return re.sub(r'\s*\$\$.*', '', str)
def MakeToken(lines, start, end, token_type):
"""Creates a new instance of Token."""
return Token(start, end, SubString(lines, start, end), token_type)
def ParseToken(lines, pos, regex, token_type):
line = lines[pos.line][pos.column:]
m = regex.search(line)
if m and not m.start():
return MakeToken(lines, pos, pos + m.end(), token_type)
else:
print 'ERROR: %s expected at %s.' % (token_type, pos)
sys.exit(1)
ID_REGEX = re.compile(r'[_A-Za-z]\w*')
EQ_REGEX = re.compile(r'=')
REST_OF_LINE_REGEX = re.compile(r'.*?(?=$|\$\$)')
OPTIONAL_WHITE_SPACES_REGEX = re.compile(r'\s*')
WHITE_SPACE_REGEX = re.compile(r'\s')
DOT_DOT_REGEX = re.compile(r'\.\.')
def Skip(lines, pos, regex):
line = lines[pos.line][pos.column:]
m = re.search(regex, line)
if m and not m.start():
return pos + m.end()
else:
return pos
def SkipUntil(lines, pos, regex, token_type):
line = lines[pos.line][pos.column:]
m = re.search(regex, line)
if m:
return pos + m.start()
else:
print ('ERROR: %s expected on line %s after column %s.' %
(token_type, pos.line + 1, pos.column))
sys.exit(1)
def ParseExpTokenInParens(lines, pos):
def ParseInParens(pos):
pos = Skip(lines, pos, OPTIONAL_WHITE_SPACES_REGEX)
pos = Skip(lines, pos, r'\(')
pos = Parse(pos)
pos = Skip(lines, pos, r'\)')
return pos
def Parse(pos):
pos = SkipUntil(lines, pos, r'\(|\)', ')')
if SubString(lines, pos, pos + 1) == '(':
pos = Parse(pos + 1)
pos = Skip(lines, pos, r'\)')
return Parse(pos)
else:
return pos
start = pos.Clone()
pos = ParseInParens(pos)
return MakeToken(lines, start, pos, 'exp')
def RStripNewLineFromToken(token):
if token.value.endswith('\n'):
return Token(token.start, token.end, token.value[:-1], token.token_type)
else:
return token
def TokenizeLines(lines, pos):
while True:
found = FindFirst(lines, TOKEN_TABLE, pos)
if not found:
yield MakeToken(lines, pos, Eof(), 'code')
return
if found.start == pos:
prev_token = None
prev_token_rstripped = None
else:
prev_token = MakeToken(lines, pos, found.start, 'code')
prev_token_rstripped = RStripNewLineFromToken(prev_token)
if found.token_type == '$var':
if prev_token_rstripped:
yield prev_token_rstripped
yield found
id_token = ParseToken(lines, found.end, ID_REGEX, 'id')
yield id_token
pos = Skip(lines, id_token.end, OPTIONAL_WHITE_SPACES_REGEX)
eq_token = ParseToken(lines, pos, EQ_REGEX, '=')
yield eq_token
pos = Skip(lines, eq_token.end, r'\s*')
if SubString(lines, pos, pos + 2) != '[[':
exp_token = ParseToken(lines, pos, REST_OF_LINE_REGEX, 'exp')
yield exp_token
pos = Cursor(exp_token.end.line + 1, 0)
elif found.token_type == '$for':
if prev_token_rstripped:
yield prev_token_rstripped
yield found
id_token = ParseToken(lines, found.end, ID_REGEX, 'id')
yield id_token
pos = Skip(lines, id_token.end, WHITE_SPACE_REGEX)
elif found.token_type == '$range':
if prev_token_rstripped:
yield prev_token_rstripped
yield found
id_token = ParseToken(lines, found.end, ID_REGEX, 'id')
yield id_token
pos = Skip(lines, id_token.end, OPTIONAL_WHITE_SPACES_REGEX)
dots_pos = SkipUntil(lines, pos, DOT_DOT_REGEX, '..')
yield MakeToken(lines, pos, dots_pos, 'exp')
yield MakeToken(lines, dots_pos, dots_pos + 2, '..')
pos = dots_pos + 2
new_pos = Cursor(pos.line + 1, 0)
yield MakeToken(lines, pos, new_pos, 'exp')
pos = new_pos
elif found.token_type == '$':
if prev_token:
yield prev_token
yield found
exp_token = ParseExpTokenInParens(lines, found.end)
yield exp_token
pos = exp_token.end
elif (found.token_type == ']]' or found.token_type == '$if' or
found.token_type == '$elif' or found.token_type == '$else'):
if prev_token_rstripped:
yield prev_token_rstripped
yield found
pos = found.end
else:
if prev_token:
yield prev_token
yield found
pos = found.end
def Tokenize(s):
"""A generator that yields the tokens in the given string."""
if s != '':
lines = s.splitlines(True)
for token in TokenizeLines(lines, Cursor(0, 0)):
yield token
class CodeNode:
def __init__(self, atomic_code_list=None):
self.atomic_code = atomic_code_list
class VarNode:
def __init__(self, identifier=None, atomic_code=None):
self.identifier = identifier
self.atomic_code = atomic_code
class RangeNode:
def __init__(self, identifier=None, exp1=None, exp2=None):
self.identifier = identifier
self.exp1 = exp1
self.exp2 = exp2
class ForNode:
def __init__(self, identifier=None, sep=None, code=None):
self.identifier = identifier
self.sep = sep
self.code = code
class ElseNode:
def __init__(self, else_branch=None):
self.else_branch = else_branch
class IfNode:
def __init__(self, exp=None, then_branch=None, else_branch=None):
self.exp = exp
self.then_branch = then_branch
self.else_branch = else_branch
class RawCodeNode:
def __init__(self, token=None):
self.raw_code = token
class LiteralDollarNode:
def __init__(self, token):
self.token = token
class ExpNode:
def __init__(self, token, python_exp):
self.token = token
self.python_exp = python_exp
def PopFront(a_list):
head = a_list[0]
a_list[:1] = []
return head
def PushFront(a_list, elem):
a_list[:0] = [elem]
def PopToken(a_list, token_type=None):
token = PopFront(a_list)
if token_type is not None and token.token_type != token_type:
print 'ERROR: %s expected at %s' % (token_type, token.start)
print 'ERROR: %s found instead' % (token,)
sys.exit(1)
return token
def PeekToken(a_list):
if not a_list:
return None
return a_list[0]
def ParseExpNode(token):
python_exp = re.sub(r'([_A-Za-z]\w*)', r'self.GetValue("\1")', token.value)
return ExpNode(token, python_exp)
def ParseElseNode(tokens):
def Pop(token_type=None):
return PopToken(tokens, token_type)
next = PeekToken(tokens)
if not next:
return None
if next.token_type == '$else':
Pop('$else')
Pop('[[')
code_node = ParseCodeNode(tokens)
Pop(']]')
return code_node
elif next.token_type == '$elif':
Pop('$elif')
exp = Pop('code')
Pop('[[')
code_node = ParseCodeNode(tokens)
Pop(']]')
inner_else_node = ParseElseNode(tokens)
return CodeNode([IfNode(ParseExpNode(exp), code_node, inner_else_node)])
elif not next.value.strip():
Pop('code')
return ParseElseNode(tokens)
else:
return None
def ParseAtomicCodeNode(tokens):
def Pop(token_type=None):
return PopToken(tokens, token_type)
head = PopFront(tokens)
t = head.token_type
if t == 'code':
return RawCodeNode(head)
elif t == '$var':
id_token = Pop('id')
Pop('=')
next = PeekToken(tokens)
if next.token_type == 'exp':
exp_token = Pop()
return VarNode(id_token, ParseExpNode(exp_token))
Pop('[[')
code_node = ParseCodeNode(tokens)
Pop(']]')
return VarNode(id_token, code_node)
elif t == '$for':
id_token = Pop('id')
next_token = PeekToken(tokens)
if next_token.token_type == 'code':
sep_token = next_token
Pop('code')
else:
sep_token = None
Pop('[[')
code_node = ParseCodeNode(tokens)
Pop(']]')
return ForNode(id_token, sep_token, code_node)
elif t == '$if':
exp_token = Pop('code')
Pop('[[')
code_node = ParseCodeNode(tokens)
Pop(']]')
else_node = ParseElseNode(tokens)
return IfNode(ParseExpNode(exp_token), code_node, else_node)
elif t == '$range':
id_token = Pop('id')
exp1_token = Pop('exp')
Pop('..')
exp2_token = Pop('exp')
return RangeNode(id_token, ParseExpNode(exp1_token),
ParseExpNode(exp2_token))
elif t == '$id':
return ParseExpNode(Token(head.start + 1, head.end, head.value[1:], 'id'))
elif t == '$($)':
return LiteralDollarNode(head)
elif t == '$':
exp_token = Pop('exp')
return ParseExpNode(exp_token)
elif t == '[[':
code_node = ParseCodeNode(tokens)
Pop(']]')
return code_node
else:
PushFront(tokens, head)
return None
def ParseCodeNode(tokens):
atomic_code_list = []
while True:
if not tokens:
break
atomic_code_node = ParseAtomicCodeNode(tokens)
if atomic_code_node:
atomic_code_list.append(atomic_code_node)
else:
break
return CodeNode(atomic_code_list)
def ParseToAST(pump_src_text):
"""Convert the given Pump source text into an AST."""
tokens = list(Tokenize(pump_src_text))
code_node = ParseCodeNode(tokens)
return code_node
class Env:
def __init__(self):
self.variables = []
self.ranges = []
def Clone(self):
clone = Env()
clone.variables = self.variables[:]
clone.ranges = self.ranges[:]
return clone
def PushVariable(self, var, value):
# If value looks like an int, store it as an int.
try:
int_value = int(value)
if ('%s' % int_value) == value:
value = int_value
except Exception:
pass
self.variables[:0] = [(var, value)]
def PopVariable(self):
self.variables[:1] = []
def PushRange(self, var, lower, upper):
self.ranges[:0] = [(var, lower, upper)]
def PopRange(self):
self.ranges[:1] = []
def GetValue(self, identifier):
for (var, value) in self.variables:
if identifier == var:
return value
print 'ERROR: meta variable %s is undefined.' % (identifier,)
sys.exit(1)
def EvalExp(self, exp):
try:
result = eval(exp.python_exp)
except Exception, e:
print 'ERROR: caught exception %s: %s' % (e.__class__.__name__, e)
print ('ERROR: failed to evaluate meta expression %s at %s' %
(exp.python_exp, exp.token.start))
sys.exit(1)
return result
def GetRange(self, identifier):
for (var, lower, upper) in self.ranges:
if identifier == var:
return (lower, upper)
print 'ERROR: range %s is undefined.' % (identifier,)
sys.exit(1)
class Output:
def __init__(self):
self.string = ''
def GetLastLine(self):
index = self.string.rfind('\n')
if index < 0:
return ''
return self.string[index + 1:]
def Append(self, s):
self.string += s
def RunAtomicCode(env, node, output):
if isinstance(node, VarNode):
identifier = node.identifier.value.strip()
result = Output()
RunAtomicCode(env.Clone(), node.atomic_code, result)
value = result.string
env.PushVariable(identifier, value)
elif isinstance(node, RangeNode):
identifier = node.identifier.value.strip()
lower = int(env.EvalExp(node.exp1))
upper = int(env.EvalExp(node.exp2))
env.PushRange(identifier, lower, upper)
elif isinstance(node, ForNode):
identifier = node.identifier.value.strip()
if node.sep is None:
sep = ''
else:
sep = node.sep.value
(lower, upper) = env.GetRange(identifier)
for i in range(lower, upper + 1):
new_env = env.Clone()
new_env.PushVariable(identifier, i)
RunCode(new_env, node.code, output)
if i != upper:
output.Append(sep)
elif isinstance(node, RawCodeNode):
output.Append(node.raw_code.value)
elif isinstance(node, IfNode):
cond = env.EvalExp(node.exp)
if cond:
RunCode(env.Clone(), node.then_branch, output)
elif node.else_branch is not None:
RunCode(env.Clone(), node.else_branch, output)
elif isinstance(node, ExpNode):
value = env.EvalExp(node)
output.Append('%s' % (value,))
elif isinstance(node, LiteralDollarNode):
output.Append('$')
elif isinstance(node, CodeNode):
RunCode(env.Clone(), node, output)
else:
print 'BAD'
print node
sys.exit(1)
def RunCode(env, code_node, output):
for atomic_code in code_node.atomic_code:
RunAtomicCode(env, atomic_code, output)
def IsSingleLineComment(cur_line):
return '//' in cur_line
def IsInPreprocessorDirective(prev_lines, cur_line):
if cur_line.lstrip().startswith('#'):
return True
return prev_lines and prev_lines[-1].endswith('\\')
def WrapComment(line, output):
loc = line.find('//')
before_comment = line[:loc].rstrip()
if before_comment == '':
indent = loc
else:
output.append(before_comment)
indent = len(before_comment) - len(before_comment.lstrip())
prefix = indent*' ' + '// '
max_len = 80 - len(prefix)
comment = line[loc + 2:].strip()
segs = [seg for seg in re.split(r'(\w+\W*)', comment) if seg != '']
cur_line = ''
for seg in segs:
if len((cur_line + seg).rstrip()) < max_len:
cur_line += seg
else:
if cur_line.strip() != '':
output.append(prefix + cur_line.rstrip())
cur_line = seg.lstrip()
if cur_line.strip() != '':
output.append(prefix + cur_line.strip())
def WrapCode(line, line_concat, output):
indent = len(line) - len(line.lstrip())
prefix = indent*' ' # Prefix of the current line
max_len = 80 - indent - len(line_concat) # Maximum length of the current line
new_prefix = prefix + 4*' ' # Prefix of a continuation line
new_max_len = max_len - 4 # Maximum length of a continuation line
# Prefers to wrap a line after a ',' or ';'.
segs = [seg for seg in re.split(r'([^,;]+[,;]?)', line.strip()) if seg != '']
cur_line = '' # The current line without leading spaces.
for seg in segs:
# If the line is still too long, wrap at a space.
while cur_line == '' and len(seg.strip()) > max_len:
seg = seg.lstrip()
split_at = seg.rfind(' ', 0, max_len)
output.append(prefix + seg[:split_at].strip() + line_concat)
seg = seg[split_at + 1:]
prefix = new_prefix
max_len = new_max_len
if len((cur_line + seg).rstrip()) < max_len:
cur_line = (cur_line + seg).lstrip()
else:
output.append(prefix + cur_line.rstrip() + line_concat)
prefix = new_prefix
max_len = new_max_len
cur_line = seg.lstrip()
if cur_line.strip() != '':
output.append(prefix + cur_line.strip())
def WrapPreprocessorDirective(line, output):
WrapCode(line, ' \\', output)
def WrapPlainCode(line, output):
WrapCode(line, '', output)
def IsMultiLineIWYUPragma(line):
return re.search(r'/\* IWYU pragma: ', line)
def IsHeaderGuardIncludeOrOneLineIWYUPragma(line):
return (re.match(r'^#(ifndef|define|endif\s*//)\s*[\w_]+\s*$', line) or
re.match(r'^#include\s', line) or
# Don't break IWYU pragmas, either; that causes iwyu.py problems.
re.search(r'// IWYU pragma: ', line))
def WrapLongLine(line, output):
line = line.rstrip()
if len(line) <= 80:
output.append(line)
elif IsSingleLineComment(line):
if IsHeaderGuardIncludeOrOneLineIWYUPragma(line):
# The style guide made an exception to allow long header guard lines,
# includes and IWYU pragmas.
output.append(line)
else:
WrapComment(line, output)
elif IsInPreprocessorDirective(output, line):
if IsHeaderGuardIncludeOrOneLineIWYUPragma(line):
# The style guide made an exception to allow long header guard lines,
# includes and IWYU pragmas.
output.append(line)
else:
WrapPreprocessorDirective(line, output)
elif IsMultiLineIWYUPragma(line):
output.append(line)
else:
WrapPlainCode(line, output)
def BeautifyCode(string):
lines = string.splitlines()
output = []
for line in lines:
WrapLongLine(line, output)
output2 = [line.rstrip() for line in output]
return '\n'.join(output2) + '\n'
def ConvertFromPumpSource(src_text):
"""Return the text generated from the given Pump source text."""
ast = ParseToAST(StripMetaComments(src_text))
output = Output()
RunCode(Env(), ast, output)
return BeautifyCode(output.string)
def main(argv):
if len(argv) == 1:
print __doc__
sys.exit(1)
file_path = argv[-1]
output_str = ConvertFromPumpSource(file(file_path, 'r').read())
if file_path.endswith('.pump'):
output_file_path = file_path[:-5]
else:
output_file_path = '-'
if output_file_path == '-':
print output_str,
else:
output_file = file(output_file_path, 'w')
output_file.write('// This file was GENERATED by command:\n')
output_file.write('// %s %s\n' %
(os.path.basename(__file__), os.path.basename(file_path)))
output_file.write('// DO NOT EDIT BY HAND!!!\n\n')
output_file.write(output_str)
output_file.close()
if __name__ == '__main__':
main(sys.argv)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
9079,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
29547,
373,
16,
14,
18,
14,
16,
446,
31651,
18491,
367,
6288,
2165,
9258,
14,
199,
199,
33,
4744,
367,
22335,
3404,
31768,
14,
221,
18491,
367,
12999,
199,
5028,
280,
857,
1234,
27025,
1233,
14,
221,
662,
22568,
2997,
367,
3575,
445,
4176,
199,
2888,
12,
3423,
12,
16954,
12,
436,
7009,
626,
1929,
370,
1736,
543,
199,
3808,
1785,
1329,
402,
2368,
14,
199,
199,
20274,
26,
2126,
31741,
14,
647,
25470,
63,
3817,
199,
199,
8918,
26,
2126,
31741,
14,
647,
3925,
14,
2055,
14,
29547,
268,
19107,
3925,
14,
2055,
14,
29547,
370,
3925,
14,
2055,
14,
199,
199,
10896,
45,
689,
26,
2126,
22547,
11351,
437,
2566,
17233,
63,
6012,
10,
2126,
437,
2566,
17233,
63,
6012,
11351,
2672,
1391,
2870,
275,
7168,
1075,
1779,
1204,
2672,
1391,
2870,
275,
3474,
22547,
1622,
61,
1779,
1204,
2672,
1842,
2870,
7168,
1075,
703,
1438,
5786,
1075,
1779,
1204,
2672,
509,
2870,
14782,
3474,
22547,
1622,
61,
1779,
1204,
7714,
4,
9,
1779,
1204,
2672,
998,
1779,
1204,
7714,
1438,
5786,
1075,
9,
1779,
1204,
2672,
692,
7168,
1075,
3474,
22547,
1622,
61,
22325,
899,
63,
24776,
1779,
1204,
3474,
22547,
1622,
61,
1779,
1204,
820,
15088,
63,
6012,
2126,
14782,
11351,
820,
15088,
63,
6012,
1204,
16589,
2126,
22325,
899,
63,
24776,
11351,
2672,
2836,
3474,
22547,
1622,
61,
1779,
1204,
2672,
4164,
7168,
1075,
3474,
22547,
1622,
61,
22325,
899,
63,
24776,
1779,
1204,
16589,
2126,
7168,
1075,
965,
2018,
6302,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
20444,
32,
3098,
14,
957,
334,
12674,
1629,
951,
644,
290,
3171,
199,
199,
646,
747,
199,
646,
295,
199,
646,
984,
421,
199,
8803,
63,
8723,
275,
359,
272,
334,
264,
14,
2014,
8,
82,
1154,
4,
1391,
60,
83,
11,
659,
4505,
1391,
659,
272,
334,
264,
14,
2014,
8,
82,
1154,
4,
4164,
60,
83,
11,
659,
4505,
4164,
659,
272,
334,
264,
14,
2014,
8,
82,
1154,
4,
2836,
60,
83,
11,
659,
4505,
2836,
659,
272,
334,
264,
14,
2014,
8,
82,
1154,
4,
509,
60,
83,
11,
659,
4505,
509,
659,
272,
334,
264,
14,
2014,
8,
82,
1154,
4,
692,
60,
83,
11,
659,
4505,
692,
659,
272,
334,
264,
14,
2014,
8,
82,
1154,
4,
1842,
60,
83,
11,
659,
4505,
1842,
659,
272,
334,
264,
14,
2014,
8,
82,
1154,
4,
13040,
33,
13,
13163,
13,
90,
7272,
87,
10,
659,
4505,
344,
659,
272,
334,
264,
14,
2014,
8,
82,
1154,
16827,
2961,
16827,
11218,
9774,
4,
11218,
272,
334,
264,
14,
2014,
8,
82,
1154,
26712,
4505,
659,
272,
334,
264,
14,
2014,
8,
82,
1154,
7023,
7023,
78,
31,
659,
6730,
59,
659,
272,
334,
264,
14,
2014,
8,
82,
1154,
7272,
7272,
78,
31,
659,
283,
2677,
659,
272,
1622,
421,
199,
533,
20385,
26,
523,
408,
18089,
282,
3421,
334,
604,
436,
2763,
9,
315,
282,
1318,
570,
1041,
819,
347,
636,
826,
721,
277,
12,
1004,
4022,
17,
12,
2763,
4022,
17,
304,
272,
291,
14,
604,
275,
1004,
272,
291,
14,
2301,
275,
2763,
819,
347,
636,
4077,
721,
277,
12,
9085,
304,
272,
372,
291,
14,
604,
508,
9085,
14,
604,
436,
291,
14,
2301,
508,
9085,
14,
2301,
819,
347,
636,
685,
721,
277,
12,
9085,
304,
272,
372,
440,
291,
508,
9085,
819,
347,
636,
4116,
721,
277,
12,
9085,
304,
272,
372,
291,
14,
604,
665,
9085,
14,
604,
503,
334,
267,
291,
14,
604,
508,
9085,
14,
604,
436,
291,
14,
2301,
665,
9085,
14,
2301,
9,
819,
347,
636,
274,
721,
277,
12,
9085,
304,
272,
372,
291,
665,
9085,
503,
291,
508,
9085,
819,
347,
636,
3308,
721,
277,
12,
9085,
304,
272,
372,
9085,
665,
291,
819,
347,
636,
303,
721,
277,
12,
9085,
304,
272,
372,
9085,
2695,
291,
819,
347,
636,
495,
721,
277,
304,
272,
340,
291,
508,
662,
1618,
837,
489,
372,
283,
13178,
7,
272,
587,
26,
489,
372,
1543,
83,
4042,
83,
3171,
450,
334,
277,
14,
604,
435,
413,
12,
291,
14,
2301,
9,
819,
347,
636,
525,
721,
277,
12,
3268,
304,
272
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
9079,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
29547,
373,
16,
14,
18,
14,
16,
446,
31651,
18491,
367,
6288,
2165,
9258,
14,
199,
199,
33,
4744,
367,
22335,
3404,
31768,
14,
221,
18491,
367,
12999,
199,
5028,
280,
857,
1234,
27025,
1233,
14,
221,
662,
22568,
2997,
367,
3575,
445,
4176,
199,
2888,
12,
3423,
12,
16954,
12,
436,
7009,
626,
1929,
370,
1736,
543,
199,
3808,
1785,
1329,
402,
2368,
14,
199,
199,
20274,
26,
2126,
31741,
14,
647,
25470,
63,
3817,
199,
199,
8918,
26,
2126,
31741,
14,
647,
3925,
14,
2055,
14,
29547,
268,
19107,
3925,
14,
2055,
14,
29547,
370,
3925,
14,
2055,
14,
199,
199,
10896,
45,
689,
26,
2126,
22547,
11351,
437,
2566,
17233,
63,
6012,
10,
2126,
437,
2566,
17233,
63,
6012,
11351,
2672,
1391,
2870,
275,
7168,
1075,
1779,
1204,
2672,
1391,
2870,
275,
3474,
22547,
1622,
61,
1779,
1204,
2672,
1842,
2870,
7168,
1075,
703,
1438,
5786,
1075,
1779,
1204,
2672,
509,
2870,
14782,
3474,
22547,
1622,
61,
1779,
1204,
7714,
4,
9,
1779,
1204,
2672,
998,
1779,
1204,
7714,
1438,
5786,
1075,
9,
1779,
1204,
2672,
692,
7168,
1075,
3474,
22547,
1622,
61,
22325,
899,
63,
24776,
1779,
1204,
3474,
22547,
1622,
61,
1779,
1204,
820,
15088,
63,
6012,
2126,
14782,
11351,
820,
15088,
63,
6012,
1204,
16589,
2126,
22325,
899,
63,
24776,
11351,
2672,
2836,
3474,
22547,
1622,
61,
1779,
1204,
2672,
4164,
7168,
1075,
3474,
22547,
1622,
61,
22325,
899,
63,
24776,
1779,
1204,
16589,
2126,
7168,
1075,
965,
2018,
6302,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
20444,
32,
3098,
14,
957,
334,
12674,
1629,
951,
644,
290,
3171,
199,
199,
646,
747,
199,
646,
295,
199,
646,
984,
421,
199,
8803,
63,
8723,
275,
359,
272,
334,
264,
14,
2014,
8,
82,
1154,
4,
1391,
60,
83,
11,
659,
4505,
1391,
659,
272,
334,
264,
14,
2014,
8,
82,
1154,
4,
4164,
60,
83,
11,
659,
4505,
4164,
659,
272,
334,
264,
14,
2014,
8,
82,
1154,
4,
2836,
60,
83,
11,
659,
4505,
2836,
659,
272,
334,
264,
14,
2014,
8,
82,
1154,
4,
509,
60,
83,
11,
659,
4505,
509,
659,
272,
334,
264,
14,
2014,
8,
82,
1154,
4,
692,
60,
83,
11,
659,
4505,
692,
659,
272,
334,
264,
14,
2014,
8,
82,
1154,
4,
1842,
60,
83,
11,
659,
4505,
1842,
659,
272,
334,
264,
14,
2014,
8,
82,
1154,
4,
13040,
33,
13,
13163,
13,
90,
7272,
87,
10,
659,
4505,
344,
659,
272,
334,
264,
14,
2014,
8,
82,
1154,
16827,
2961,
16827,
11218,
9774,
4,
11218,
272,
334,
264,
14,
2014,
8,
82,
1154,
26712,
4505,
659,
272,
334,
264,
14,
2014,
8,
82,
1154,
7023,
7023,
78,
31,
659,
6730,
59,
659,
272,
334,
264,
14,
2014,
8,
82,
1154,
7272,
7272,
78,
31,
659,
283,
2677,
659,
272,
1622,
421,
199,
533,
20385,
26,
523,
408,
18089,
282,
3421,
334,
604,
436,
2763,
9,
315,
282,
1318,
570,
1041,
819,
347,
636,
826,
721,
277,
12,
1004,
4022,
17,
12,
2763,
4022,
17,
304,
272,
291,
14,
604,
275,
1004,
272,
291,
14,
2301,
275,
2763,
819,
347,
636,
4077,
721,
277,
12,
9085,
304,
272,
372,
291,
14,
604,
508,
9085,
14,
604,
436,
291,
14,
2301,
508,
9085,
14,
2301,
819,
347,
636,
685,
721,
277,
12,
9085,
304,
272,
372,
440,
291,
508,
9085,
819,
347,
636,
4116,
721,
277,
12,
9085,
304,
272,
372,
291,
14,
604,
665,
9085,
14,
604,
503,
334,
267,
291,
14,
604,
508,
9085,
14,
604,
436,
291,
14,
2301,
665,
9085,
14,
2301,
9,
819,
347,
636,
274,
721,
277,
12,
9085,
304,
272,
372,
291,
665,
9085,
503,
291,
508,
9085,
819,
347,
636,
3308,
721,
277,
12,
9085,
304,
272,
372,
9085,
665,
291,
819,
347,
636,
303,
721,
277,
12,
9085,
304,
272,
372,
9085,
2695,
291,
819,
347,
636,
495,
721,
277,
304,
272,
340,
291,
508,
662,
1618,
837,
489,
372,
283,
13178,
7,
272,
587,
26,
489,
372,
1543,
83,
4042,
83,
3171,
450,
334,
277,
14,
604,
435,
413,
12,
291,
14,
2301,
9,
819,
347,
636,
525,
721,
277,
12,
3268,
304,
272,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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/lib/remote_server.py
|
4
|
7302
|
import logging
import urllib
from typing import Any, Dict, List, Mapping, Tuple, Union
import orjson
import requests
from django.conf import settings
from django.forms.models import model_to_dict
from django.utils.translation import ugettext as _
from analytics.models import InstallationCount, RealmCount
from version import ZULIP_VERSION
from zerver.lib.exceptions import JsonableError
from zerver.lib.export import floatify_datetime_fields
from zerver.models import RealmAuditLog
class PushNotificationBouncerException(Exception):
pass
class PushNotificationBouncerRetryLaterError(JsonableError):
http_status_code = 502
def send_to_push_bouncer(
method: str,
endpoint: str,
post_data: Union[bytes, Mapping[str, Union[str, bytes]]],
extra_headers: Mapping[str, str] = {},
) -> Dict[str, object]:
"""While it does actually send the notice, this function has a lot of
code and comments around error handling for the push notifications
bouncer. There are several classes of failures, each with its own
potential solution:
* Network errors with requests.request. We raise an exception to signal
it to the callers.
* 500 errors from the push bouncer or other unexpected responses;
we don't try to parse the response, but do make clear the cause.
* 400 errors from the push bouncer. Here there are 2 categories:
Our server failed to connect to the push bouncer (should throw)
vs. client-side errors like and invalid token.
"""
url = urllib.parse.urljoin(settings.PUSH_NOTIFICATION_BOUNCER_URL,
'/api/v1/remotes/' + endpoint)
api_auth = requests.auth.HTTPBasicAuth(settings.ZULIP_ORG_ID,
settings.ZULIP_ORG_KEY)
headers = {"User-agent": f"ZulipServer/{ZULIP_VERSION}"}
headers.update(extra_headers)
try:
res = requests.request(method,
url,
data=post_data,
auth=api_auth,
timeout=30,
verify=True,
headers=headers)
except (requests.exceptions.Timeout, requests.exceptions.SSLError,
requests.exceptions.ConnectionError) as e:
raise PushNotificationBouncerRetryLaterError(
f"{e.__class__.__name__} while trying to connect to push notification bouncer")
if res.status_code >= 500:
# 500s should be resolved by the people who run the push
# notification bouncer service, and they'll get an appropriate
# error notification from the server. We raise an exception to signal
# to the callers that the attempt failed and they can retry.
error_msg = "Received 500 from push notification bouncer"
logging.warning(error_msg)
raise PushNotificationBouncerRetryLaterError(error_msg)
elif res.status_code >= 400:
# If JSON parsing errors, just let that exception happen
result_dict = orjson.loads(res.content)
msg = result_dict['msg']
if 'code' in result_dict and result_dict['code'] == 'INVALID_ZULIP_SERVER':
# Invalid Zulip server credentials should email this server's admins
raise PushNotificationBouncerException(
_("Push notifications bouncer error: {}").format(msg))
else:
# But most other errors coming from the push bouncer
# server are client errors (e.g. never-registered token)
# and should be handled as such.
raise JsonableError(msg)
elif res.status_code != 200:
# Anything else is unexpected and likely suggests a bug in
# this version of Zulip, so we throw an exception that will
# email the server admins.
raise PushNotificationBouncerException(
f"Push notification bouncer returned unexpected status code {res.status_code}")
# If we don't throw an exception, it's a successful bounce!
return orjson.loads(res.content)
def send_json_to_push_bouncer(method: str, endpoint: str, post_data: Mapping[str, object]) -> None:
send_to_push_bouncer(
method,
endpoint,
orjson.dumps(post_data),
extra_headers={"Content-type": "application/json"},
)
REALMAUDITLOG_PUSHED_FIELDS = ['id', 'realm', 'event_time', 'backfilled', 'extra_data', 'event_type']
def build_analytics_data(realm_count_query: Any,
installation_count_query: Any,
realmauditlog_query: Any) -> Tuple[List[Dict[str, Any]],
List[Dict[str, Any]],
List[Dict[str, Any]]]:
# We limit the batch size on the client side to avoid OOM kills timeouts, etc.
MAX_CLIENT_BATCH_SIZE = 10000
data = {}
data['analytics_realmcount'] = [
model_to_dict(row) for row in
realm_count_query.order_by("id")[0:MAX_CLIENT_BATCH_SIZE]
]
data['analytics_installationcount'] = [
model_to_dict(row) for row in
installation_count_query.order_by("id")[0:MAX_CLIENT_BATCH_SIZE]
]
data['zerver_realmauditlog'] = [
model_to_dict(row, fields=REALMAUDITLOG_PUSHED_FIELDS) for row in
realmauditlog_query.order_by("id")[0:MAX_CLIENT_BATCH_SIZE]
]
floatify_datetime_fields(data, 'analytics_realmcount')
floatify_datetime_fields(data, 'analytics_installationcount')
floatify_datetime_fields(data, 'zerver_realmauditlog')
return (data['analytics_realmcount'], data['analytics_installationcount'],
data['zerver_realmauditlog'])
def send_analytics_to_remote_server() -> None:
# first, check what's latest
try:
result = send_to_push_bouncer("GET", "server/analytics/status", {})
except PushNotificationBouncerRetryLaterError as e:
logging.warning(e.msg)
return
last_acked_realm_count_id = result['last_realm_count_id']
last_acked_installation_count_id = result['last_installation_count_id']
last_acked_realmauditlog_id = result['last_realmauditlog_id']
(realm_count_data, installation_count_data, realmauditlog_data) = build_analytics_data(
realm_count_query=RealmCount.objects.filter(
id__gt=last_acked_realm_count_id),
installation_count_query=InstallationCount.objects.filter(
id__gt=last_acked_installation_count_id),
realmauditlog_query=RealmAuditLog.objects.filter(
event_type__in=RealmAuditLog.SYNCED_BILLING_EVENTS,
id__gt=last_acked_realmauditlog_id))
if len(realm_count_data) + len(installation_count_data) + len(realmauditlog_data) == 0:
return
request = {
'realm_counts': orjson.dumps(realm_count_data).decode(),
'installation_counts': orjson.dumps(installation_count_data).decode(),
'realmauditlog_rows': orjson.dumps(realmauditlog_data).decode(),
'version': orjson.dumps(ZULIP_VERSION).decode(),
}
# Gather only entries with an ID greater than last_realm_count_id
try:
send_to_push_bouncer("POST", "server/analytics", request)
except JsonableError as e:
logging.warning(e.msg)
|
apache-2.0
|
[
646,
2050,
199,
646,
4011,
199,
504,
14090,
492,
6184,
12,
7448,
12,
3820,
12,
12340,
12,
11634,
12,
15961,
199,
199,
646,
503,
1001,
199,
646,
4145,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
3351,
14,
992,
492,
1402,
63,
475,
63,
807,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
199,
504,
30159,
14,
992,
492,
26866,
2353,
12,
27715,
2353,
199,
504,
1015,
492,
3107,
1293,
1772,
63,
4612,
199,
504,
19959,
14,
773,
14,
3924,
492,
14587,
461,
547,
199,
504,
19959,
14,
773,
14,
3790,
492,
289,
320,
2159,
1399,
63,
2083,
63,
955,
199,
504,
19959,
14,
992,
492,
27715,
23601,
2445,
421,
199,
533,
22643,
11598,
2208,
31794,
1726,
8,
1726,
304,
272,
986,
199,
199,
533,
22643,
11598,
2208,
31794,
12989,
22028,
547,
8,
9653,
461,
547,
304,
272,
1455,
63,
1205,
63,
600,
275,
959,
996,
199,
199,
318,
3222,
63,
475,
63,
5335,
63,
656,
31794,
8,
272,
1083,
26,
620,
12,
272,
6037,
26,
620,
12,
272,
2963,
63,
576,
26,
15961,
59,
2394,
12,
12340,
59,
495,
12,
15961,
59,
495,
12,
2783,
15559,
272,
2402,
63,
2139,
26,
12340,
59,
495,
12,
620,
61,
275,
5479,
199,
9,
1035,
7448,
59,
495,
12,
909,
2189,
272,
408,
25215,
652,
1630,
5965,
3222,
314,
4245,
12,
642,
805,
965,
282,
13918,
402,
272,
1233,
436,
6786,
6818,
1125,
7252,
367,
314,
6675,
13116,
272,
1234,
31794,
14,
221,
6006,
787,
9978,
3992,
402,
9081,
12,
1924,
543,
2399,
5705,
272,
12330,
8744,
26,
339,
627,
7220,
2552,
543,
4145,
14,
1069,
14,
221,
2136,
746,
376,
1919,
370,
4673,
489,
652,
370,
314,
24194,
14,
339,
627,
6891,
2552,
687,
314,
6675,
1234,
31794,
503,
1163,
10537,
9320,
27,
489,
781,
2793,
1133,
862,
370,
2198,
314,
1177,
12,
1325,
886,
1852,
5436,
314,
7675,
14,
339,
627,
8290,
2552,
687,
314,
6675,
1234,
31794,
14,
221,
11842,
2337,
787,
499,
9695,
26,
489,
25119,
1654,
3405,
370,
4907,
370,
314,
6675,
1234,
31794,
334,
5626,
7978,
9,
489,
8118,
14,
1890,
13,
2441,
2552,
2839,
436,
3866,
1526,
14,
339,
408,
272,
1166,
275,
4011,
14,
1122,
14,
17755,
8,
1751,
14,
21378,
63,
22839,
2594,
63,
3973,
17192,
540,
63,
2632,
12,
3044,
1994,
1246,
15,
86,
17,
15,
21420,
744,
4805,
435,
6037,
9,
272,
2986,
63,
1178,
275,
4145,
14,
1178,
14,
2856,
6845,
2817,
8,
1751,
14,
58,
1293,
1772,
63,
25797,
63,
998,
12,
5644,
2202,
14,
58,
1293,
1772,
63,
25797,
63,
3078,
9,
339,
2323,
275,
2420,
1899,
13,
4054,
582,
289,
2,
58,
11294,
3120,
5321,
58,
1293,
1772,
63,
4612,
93,
3570,
272,
2323,
14,
873,
8,
2911,
63,
2139,
9,
339,
862,
26,
267,
522,
275,
4145,
14,
1069,
8,
765,
12,
3044,
1166,
12,
3044,
666,
29,
1932,
63,
576,
12,
3044,
1790,
29,
1246,
63,
1178,
12,
3044,
2653,
29,
1216,
12,
3044,
4911,
29,
549,
12,
3044,
2323,
29,
2139,
9,
272,
871,
334,
6615,
14,
3924,
14,
6372,
12,
4145,
14,
3924,
14,
27102,
12,
288,
4145,
14,
3924,
14,
20349,
9,
465,
325,
26,
267,
746,
22643,
11598,
2208,
31794,
12989,
22028,
547,
8,
288,
289,
14381,
69,
855,
533,
4914,
354,
363,
93,
1830,
9936,
370,
4907,
370,
6675,
6955,
1234,
31794,
531,
339,
340,
522,
14,
1205,
63,
600,
2356,
6891,
26,
267,
327,
6891,
83,
1077,
506,
12152,
701,
314,
13135,
3963,
1255,
314,
6675,
267,
327,
6955,
1234,
31794,
2435,
12,
436,
2985,
7171,
664,
376,
5827,
267,
327,
1125,
6955,
687,
314,
1654,
14,
2136,
746,
376,
1919,
370,
4673,
267,
327,
370,
314,
24194,
626,
314,
7427,
3405,
436,
2985,
883,
7269,
14,
267,
1125,
63,
1328,
275,
298,
9392,
6891,
687,
6675,
6955,
1234,
31794,
2,
267,
2050,
14,
3764,
8,
705,
63,
1328,
9,
267,
746,
22643,
11598,
2208,
31794,
12989,
22028,
547,
8,
705,
63,
1328,
9,
272,
916,
522,
14,
1205,
63,
600,
2356,
8290,
26,
267,
327,
982,
4840,
6057,
2552,
12,
2951,
4691,
626,
1919,
5992,
267,
754,
63,
807,
275,
503,
1001,
14,
3640,
8,
470,
14,
1317,
9,
267,
1499,
275,
754,
63,
807,
459,
1328,
418,
267,
340,
283,
600,
7,
315,
754,
63,
807,
436,
754,
63,
807,
459,
600,
418,
508,
283,
9692,
63,
58,
1293,
1772,
63,
6613,
356,
288,
327,
6378,
3107,
11294,
1654,
6235,
1077,
3031,
642,
1654,
1159,
4628,
83,
288,
746,
22643,
11598,
2208,
31794,
1726,
8,
355,
3824,
10731,
13116,
1234,
31794,
1125,
26,
1052,
3471,
908,
8,
1328,
430,
267,
587,
26,
288,
327,
11017,
4750,
1163,
2552,
17262,
687,
314,
6675,
1234,
31794,
288,
327,
1654,
787,
1890,
2552,
334,
69,
14,
71,
14,
7078,
13,
11616,
1526,
9,
288,
327,
436,
1077,
506,
8860,
465,
4066,
14,
288,
746,
14587,
461,
547,
8,
1328,
9,
272,
916,
522,
14,
1205,
63,
600,
1137,
1926,
26,
267,
327,
6184,
2127,
587,
365,
10537,
436,
12060,
18453,
83,
282,
6519,
315,
267,
327,
642,
1015,
402,
3107,
11294,
12,
880,
781,
7978,
376,
1919,
626,
911,
267,
327,
3031,
314,
1654,
4628,
83,
14,
267,
746,
22643,
11598,
2208,
31794,
1726,
8,
288,
289,
2,
10731,
6955,
1234,
31794,
2138,
10537,
2004,
1233,
469,
470,
14,
1205,
63,
600,
15412,
339,
327,
982,
781,
2793,
1133,
7978,
376,
1919,
12,
652,
1159,
282,
9512,
1234,
10222,
1,
272,
372,
503,
1001,
14,
3640,
8,
470,
14,
1317,
9,
199,
199,
318,
3222,
63,
1001,
63,
475,
63,
5335,
63,
656,
31794,
8,
765,
26,
620,
12,
6037,
26,
620,
12,
2963,
63,
576,
26,
12340,
59,
495,
12,
909,
566,
1035,
488,
26,
272,
3222,
63,
475,
63,
5335,
63,
656,
31794,
8,
267,
1083,
12,
267,
6037,
12,
267,
503,
1001,
14,
4180,
8,
1932,
63,
576,
395,
267,
2402,
63,
2139,
8871,
2714,
13,
466,
582,
298,
3578,
15,
1001,
6018,
272,
776,
199,
199,
15508,
2054,
3383,
649,
4947,
63,
21378,
1149,
63,
12767,
275,
788,
344,
297,
283,
7728,
297,
283,
1430,
63,
521,
297,
283,
894,
17647,
297,
283
] |
[
2050,
199,
646,
4011,
199,
504,
14090,
492,
6184,
12,
7448,
12,
3820,
12,
12340,
12,
11634,
12,
15961,
199,
199,
646,
503,
1001,
199,
646,
4145,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
3351,
14,
992,
492,
1402,
63,
475,
63,
807,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
199,
504,
30159,
14,
992,
492,
26866,
2353,
12,
27715,
2353,
199,
504,
1015,
492,
3107,
1293,
1772,
63,
4612,
199,
504,
19959,
14,
773,
14,
3924,
492,
14587,
461,
547,
199,
504,
19959,
14,
773,
14,
3790,
492,
289,
320,
2159,
1399,
63,
2083,
63,
955,
199,
504,
19959,
14,
992,
492,
27715,
23601,
2445,
421,
199,
533,
22643,
11598,
2208,
31794,
1726,
8,
1726,
304,
272,
986,
199,
199,
533,
22643,
11598,
2208,
31794,
12989,
22028,
547,
8,
9653,
461,
547,
304,
272,
1455,
63,
1205,
63,
600,
275,
959,
996,
199,
199,
318,
3222,
63,
475,
63,
5335,
63,
656,
31794,
8,
272,
1083,
26,
620,
12,
272,
6037,
26,
620,
12,
272,
2963,
63,
576,
26,
15961,
59,
2394,
12,
12340,
59,
495,
12,
15961,
59,
495,
12,
2783,
15559,
272,
2402,
63,
2139,
26,
12340,
59,
495,
12,
620,
61,
275,
5479,
199,
9,
1035,
7448,
59,
495,
12,
909,
2189,
272,
408,
25215,
652,
1630,
5965,
3222,
314,
4245,
12,
642,
805,
965,
282,
13918,
402,
272,
1233,
436,
6786,
6818,
1125,
7252,
367,
314,
6675,
13116,
272,
1234,
31794,
14,
221,
6006,
787,
9978,
3992,
402,
9081,
12,
1924,
543,
2399,
5705,
272,
12330,
8744,
26,
339,
627,
7220,
2552,
543,
4145,
14,
1069,
14,
221,
2136,
746,
376,
1919,
370,
4673,
489,
652,
370,
314,
24194,
14,
339,
627,
6891,
2552,
687,
314,
6675,
1234,
31794,
503,
1163,
10537,
9320,
27,
489,
781,
2793,
1133,
862,
370,
2198,
314,
1177,
12,
1325,
886,
1852,
5436,
314,
7675,
14,
339,
627,
8290,
2552,
687,
314,
6675,
1234,
31794,
14,
221,
11842,
2337,
787,
499,
9695,
26,
489,
25119,
1654,
3405,
370,
4907,
370,
314,
6675,
1234,
31794,
334,
5626,
7978,
9,
489,
8118,
14,
1890,
13,
2441,
2552,
2839,
436,
3866,
1526,
14,
339,
408,
272,
1166,
275,
4011,
14,
1122,
14,
17755,
8,
1751,
14,
21378,
63,
22839,
2594,
63,
3973,
17192,
540,
63,
2632,
12,
3044,
1994,
1246,
15,
86,
17,
15,
21420,
744,
4805,
435,
6037,
9,
272,
2986,
63,
1178,
275,
4145,
14,
1178,
14,
2856,
6845,
2817,
8,
1751,
14,
58,
1293,
1772,
63,
25797,
63,
998,
12,
5644,
2202,
14,
58,
1293,
1772,
63,
25797,
63,
3078,
9,
339,
2323,
275,
2420,
1899,
13,
4054,
582,
289,
2,
58,
11294,
3120,
5321,
58,
1293,
1772,
63,
4612,
93,
3570,
272,
2323,
14,
873,
8,
2911,
63,
2139,
9,
339,
862,
26,
267,
522,
275,
4145,
14,
1069,
8,
765,
12,
3044,
1166,
12,
3044,
666,
29,
1932,
63,
576,
12,
3044,
1790,
29,
1246,
63,
1178,
12,
3044,
2653,
29,
1216,
12,
3044,
4911,
29,
549,
12,
3044,
2323,
29,
2139,
9,
272,
871,
334,
6615,
14,
3924,
14,
6372,
12,
4145,
14,
3924,
14,
27102,
12,
288,
4145,
14,
3924,
14,
20349,
9,
465,
325,
26,
267,
746,
22643,
11598,
2208,
31794,
12989,
22028,
547,
8,
288,
289,
14381,
69,
855,
533,
4914,
354,
363,
93,
1830,
9936,
370,
4907,
370,
6675,
6955,
1234,
31794,
531,
339,
340,
522,
14,
1205,
63,
600,
2356,
6891,
26,
267,
327,
6891,
83,
1077,
506,
12152,
701,
314,
13135,
3963,
1255,
314,
6675,
267,
327,
6955,
1234,
31794,
2435,
12,
436,
2985,
7171,
664,
376,
5827,
267,
327,
1125,
6955,
687,
314,
1654,
14,
2136,
746,
376,
1919,
370,
4673,
267,
327,
370,
314,
24194,
626,
314,
7427,
3405,
436,
2985,
883,
7269,
14,
267,
1125,
63,
1328,
275,
298,
9392,
6891,
687,
6675,
6955,
1234,
31794,
2,
267,
2050,
14,
3764,
8,
705,
63,
1328,
9,
267,
746,
22643,
11598,
2208,
31794,
12989,
22028,
547,
8,
705,
63,
1328,
9,
272,
916,
522,
14,
1205,
63,
600,
2356,
8290,
26,
267,
327,
982,
4840,
6057,
2552,
12,
2951,
4691,
626,
1919,
5992,
267,
754,
63,
807,
275,
503,
1001,
14,
3640,
8,
470,
14,
1317,
9,
267,
1499,
275,
754,
63,
807,
459,
1328,
418,
267,
340,
283,
600,
7,
315,
754,
63,
807,
436,
754,
63,
807,
459,
600,
418,
508,
283,
9692,
63,
58,
1293,
1772,
63,
6613,
356,
288,
327,
6378,
3107,
11294,
1654,
6235,
1077,
3031,
642,
1654,
1159,
4628,
83,
288,
746,
22643,
11598,
2208,
31794,
1726,
8,
355,
3824,
10731,
13116,
1234,
31794,
1125,
26,
1052,
3471,
908,
8,
1328,
430,
267,
587,
26,
288,
327,
11017,
4750,
1163,
2552,
17262,
687,
314,
6675,
1234,
31794,
288,
327,
1654,
787,
1890,
2552,
334,
69,
14,
71,
14,
7078,
13,
11616,
1526,
9,
288,
327,
436,
1077,
506,
8860,
465,
4066,
14,
288,
746,
14587,
461,
547,
8,
1328,
9,
272,
916,
522,
14,
1205,
63,
600,
1137,
1926,
26,
267,
327,
6184,
2127,
587,
365,
10537,
436,
12060,
18453,
83,
282,
6519,
315,
267,
327,
642,
1015,
402,
3107,
11294,
12,
880,
781,
7978,
376,
1919,
626,
911,
267,
327,
3031,
314,
1654,
4628,
83,
14,
267,
746,
22643,
11598,
2208,
31794,
1726,
8,
288,
289,
2,
10731,
6955,
1234,
31794,
2138,
10537,
2004,
1233,
469,
470,
14,
1205,
63,
600,
15412,
339,
327,
982,
781,
2793,
1133,
7978,
376,
1919,
12,
652,
1159,
282,
9512,
1234,
10222,
1,
272,
372,
503,
1001,
14,
3640,
8,
470,
14,
1317,
9,
199,
199,
318,
3222,
63,
1001,
63,
475,
63,
5335,
63,
656,
31794,
8,
765,
26,
620,
12,
6037,
26,
620,
12,
2963,
63,
576,
26,
12340,
59,
495,
12,
909,
566,
1035,
488,
26,
272,
3222,
63,
475,
63,
5335,
63,
656,
31794,
8,
267,
1083,
12,
267,
6037,
12,
267,
503,
1001,
14,
4180,
8,
1932,
63,
576,
395,
267,
2402,
63,
2139,
8871,
2714,
13,
466,
582,
298,
3578,
15,
1001,
6018,
272,
776,
199,
199,
15508,
2054,
3383,
649,
4947,
63,
21378,
1149,
63,
12767,
275,
788,
344,
297,
283,
7728,
297,
283,
1430,
63,
521,
297,
283,
894,
17647,
297,
283,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
anomaly/prestans
|
tests/rest/test_error_response.py
|
1
|
1721
|
import unittest
from prestans import exception
from prestans.http import STATUS
from prestans.rest import ErrorResponse
from prestans.serializer import JSON
class ErrorResponseTest(unittest.TestCase):
def test_init(self):
raised_exception = exception.NoEndpointError()
json_serializer = JSON()
error_response = ErrorResponse(raised_exception, json_serializer)
self.assertEqual(error_response._exception, raised_exception)
def test_call_default(self):
raised_exception = exception.NoEndpointError()
json_serializer = JSON()
error_response = ErrorResponse(raised_exception, json_serializer)
def start_response(status, headers):
pass
environ = {}
self.assertEqual(
error_response(environ, start_response),
[b'{"code": 404, "message": "API does not provide this end-point", "trace": []}']
)
def test_call_custom(self):
from prestans import types
class CustomModel(types.Model):
custom_message = types.String()
custom_error = CustomModel()
custom_error.custom_message = "custom"
class CustomError(exception.ResponseException):
def __init__(self, response_model=None):
super(CustomError, self).__init__(STATUS.FORBIDDEN, "custom", response_model)
raised_exception = CustomError(custom_error)
json_serializer = JSON()
error_response = ErrorResponse(raised_exception, json_serializer)
def start_response(status, headers):
pass
environ = {}
self.assertEqual(error_response(environ, start_response), [b'{"custom_message": "custom"}'])
|
bsd-3-clause
|
[
646,
2882,
199,
199,
504,
876,
270,
796,
492,
1919,
199,
504,
876,
270,
796,
14,
1014,
492,
18460,
199,
504,
876,
270,
796,
14,
3911,
492,
4520,
2364,
199,
504,
876,
270,
796,
14,
8349,
492,
4840,
421,
199,
533,
4520,
2364,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
826,
8,
277,
304,
267,
4915,
63,
1971,
275,
1919,
14,
1944,
11442,
547,
342,
267,
2022,
63,
8349,
275,
4840,
342,
398,
1125,
63,
1310,
275,
4520,
2364,
8,
21597,
63,
1971,
12,
2022,
63,
8349,
9,
267,
291,
14,
629,
8,
705,
63,
1310,
423,
1971,
12,
4915,
63,
1971,
9,
339,
347,
511,
63,
1250,
63,
885,
8,
277,
304,
267,
4915,
63,
1971,
275,
1919,
14,
1944,
11442,
547,
342,
267,
2022,
63,
8349,
275,
4840,
342,
398,
1125,
63,
1310,
275,
4520,
2364,
8,
21597,
63,
1971,
12,
2022,
63,
8349,
9,
398,
347,
1343,
63,
1310,
8,
1205,
12,
2323,
304,
288,
986,
398,
6160,
275,
1052,
398,
291,
14,
629,
8,
288,
1125,
63,
1310,
8,
2314,
12,
1343,
63,
1310,
395,
288,
359,
66,
7,
6641,
600,
582,
7901,
12,
298,
1188,
582,
298,
3735,
1630,
440,
5647,
642,
1284,
13,
1403,
401,
298,
3446,
582,
23455,
418,
267,
776,
339,
347,
511,
63,
1250,
63,
4229,
8,
277,
304,
267,
687,
876,
270,
796,
492,
2943,
398,
1021,
8388,
1685,
8,
1313,
14,
1685,
304,
288,
3537,
63,
1188,
275,
2943,
14,
1558,
342,
398,
3537,
63,
705,
275,
8388,
1685,
342,
267,
3537,
63,
705,
14,
4229,
63,
1188,
275,
298,
4229,
2,
398,
1021,
8388,
547,
8,
1971,
14,
2364,
1726,
304,
953,
347,
636,
826,
721,
277,
12,
1177,
63,
1238,
29,
403,
304,
355,
1613,
8,
7223,
547,
12,
291,
2843,
826,
721,
6305,
14,
2707,
34,
22436,
12,
298,
4229,
401,
1177,
63,
1238,
9,
398,
4915,
63,
1971,
275,
8388,
547,
8,
4229,
63,
705,
9,
267,
2022,
63,
8349,
275,
4840,
342,
398,
1125,
63,
1310,
275,
4520,
2364,
8,
21597,
63,
1971,
12,
2022,
63,
8349,
9,
398,
347,
1343,
63,
1310,
8,
1205,
12,
2323,
304,
288,
986,
398,
6160,
275,
1052,
398,
291,
14,
629,
8,
705,
63,
1310,
8,
2314,
12,
1343,
63,
1310,
395,
359,
66,
7,
6641,
4229,
63,
1188,
582,
298,
4229,
3570,
1105,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2882,
199,
199,
504,
876,
270,
796,
492,
1919,
199,
504,
876,
270,
796,
14,
1014,
492,
18460,
199,
504,
876,
270,
796,
14,
3911,
492,
4520,
2364,
199,
504,
876,
270,
796,
14,
8349,
492,
4840,
421,
199,
533,
4520,
2364,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
826,
8,
277,
304,
267,
4915,
63,
1971,
275,
1919,
14,
1944,
11442,
547,
342,
267,
2022,
63,
8349,
275,
4840,
342,
398,
1125,
63,
1310,
275,
4520,
2364,
8,
21597,
63,
1971,
12,
2022,
63,
8349,
9,
267,
291,
14,
629,
8,
705,
63,
1310,
423,
1971,
12,
4915,
63,
1971,
9,
339,
347,
511,
63,
1250,
63,
885,
8,
277,
304,
267,
4915,
63,
1971,
275,
1919,
14,
1944,
11442,
547,
342,
267,
2022,
63,
8349,
275,
4840,
342,
398,
1125,
63,
1310,
275,
4520,
2364,
8,
21597,
63,
1971,
12,
2022,
63,
8349,
9,
398,
347,
1343,
63,
1310,
8,
1205,
12,
2323,
304,
288,
986,
398,
6160,
275,
1052,
398,
291,
14,
629,
8,
288,
1125,
63,
1310,
8,
2314,
12,
1343,
63,
1310,
395,
288,
359,
66,
7,
6641,
600,
582,
7901,
12,
298,
1188,
582,
298,
3735,
1630,
440,
5647,
642,
1284,
13,
1403,
401,
298,
3446,
582,
23455,
418,
267,
776,
339,
347,
511,
63,
1250,
63,
4229,
8,
277,
304,
267,
687,
876,
270,
796,
492,
2943,
398,
1021,
8388,
1685,
8,
1313,
14,
1685,
304,
288,
3537,
63,
1188,
275,
2943,
14,
1558,
342,
398,
3537,
63,
705,
275,
8388,
1685,
342,
267,
3537,
63,
705,
14,
4229,
63,
1188,
275,
298,
4229,
2,
398,
1021,
8388,
547,
8,
1971,
14,
2364,
1726,
304,
953,
347,
636,
826,
721,
277,
12,
1177,
63,
1238,
29,
403,
304,
355,
1613,
8,
7223,
547,
12,
291,
2843,
826,
721,
6305,
14,
2707,
34,
22436,
12,
298,
4229,
401,
1177,
63,
1238,
9,
398,
4915,
63,
1971,
275,
8388,
547,
8,
4229,
63,
705,
9,
267,
2022,
63,
8349,
275,
4840,
342,
398,
1125,
63,
1310,
275,
4520,
2364,
8,
21597,
63,
1971,
12,
2022,
63,
8349,
9,
398,
347,
1343,
63,
1310,
8,
1205,
12,
2323,
304,
288,
986,
398,
6160,
275,
1052,
398,
291,
14,
629,
8,
705,
63,
1310,
8,
2314,
12,
1343,
63,
1310,
395,
359,
66,
7,
6641,
4229,
63,
1188,
582,
298,
4229,
3570,
1105,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
stuarteberg/numpy
|
numpy/f2py/f90mod_rules.py
|
122
|
9850
|
#!/usr/bin/env python
"""
Build F90 module support for f2py2e.
Copyright 2000 Pearu Peterson all rights reserved,
Pearu Peterson <pearu@ioc.ee>
Permission to use, modify, and distribute this software is given under the
terms of the NumPy License.
NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
$Date: 2005/02/03 19:30:23 $
Pearu Peterson
"""
from __future__ import division, absolute_import, print_function
__version__ = "$Revision: 1.27 $"[10:-1]
f2py_version = 'See `f2py -v`'
import numpy as np
from . import capi_maps
from . import func2subr
from .crackfortran import undo_rmbadname, undo_rmbadname1
# The eviroment provided by auxfuncs.py is needed for some calls to eval.
# As the needed functions cannot be determined by static inspection of the
# code, it is safest to use import * pending a major refactoring of f2py.
from .auxfuncs import *
options = {}
def findf90modules(m):
if ismodule(m):
return [m]
if not hasbody(m):
return []
ret = []
for b in m['body']:
if ismodule(b):
ret.append(b)
else:
ret = ret + findf90modules(b)
return ret
fgetdims1 = """\
external f2pysetdata
logical ns
integer r,i
integer(%d) s(*)
ns = .FALSE.
if (allocated(d)) then
do i=1,r
if ((size(d,i).ne.s(i)).and.(s(i).ge.0)) then
ns = .TRUE.
end if
end do
if (ns) then
deallocate(d)
end if
end if
if ((.not.allocated(d)).and.(s(1).ge.1)) then""" % np.intp().itemsize
fgetdims2 = """\
end if
if (allocated(d)) then
do i=1,r
s(i) = size(d,i)
end do
end if
flag = 1
call f2pysetdata(d,allocated(d))"""
fgetdims2_sa = """\
end if
if (allocated(d)) then
do i=1,r
s(i) = size(d,i)
end do
!s(r) must be equal to len(d(1))
end if
flag = 2
call f2pysetdata(d,allocated(d))"""
def buildhooks(pymod):
global fgetdims1, fgetdims2
from . import rules
ret = {'f90modhooks': [], 'initf90modhooks': [], 'body': [],
'need': ['F_FUNC', 'arrayobject.h'],
'separatorsfor': {'includes0': '\n', 'includes': '\n'},
'docs': ['"Fortran 90/95 modules:\\n"'],
'latexdoc': []}
fhooks = ['']
def fadd(line, s=fhooks):
s[0] = '%s\n %s' % (s[0], line)
doc = ['']
def dadd(line, s=doc):
s[0] = '%s\n%s' % (s[0], line)
for m in findf90modules(pymod):
sargs, fargs, efargs, modobjs, notvars, onlyvars = [], [], [], [], [
m['name']], []
sargsp = []
ifargs = []
mfargs = []
if hasbody(m):
for b in m['body']:
notvars.append(b['name'])
for n in m['vars'].keys():
var = m['vars'][n]
if (n not in notvars) and (not l_or(isintent_hide, isprivate)(var)):
onlyvars.append(n)
mfargs.append(n)
outmess('\t\tConstructing F90 module support for "%s"...\n' %
(m['name']))
if onlyvars:
outmess('\t\t Variables: %s\n' % (' '.join(onlyvars)))
chooks = ['']
def cadd(line, s=chooks):
s[0] = '%s\n%s' % (s[0], line)
ihooks = ['']
def iadd(line, s=ihooks):
s[0] = '%s\n%s' % (s[0], line)
vrd = capi_maps.modsign2map(m)
cadd('static FortranDataDef f2py_%s_def[] = {' % (m['name']))
dadd('\\subsection{Fortran 90/95 module \\texttt{%s}}\n' % (m['name']))
if hasnote(m):
note = m['note']
if isinstance(note, list):
note = '\n'.join(note)
dadd(note)
if onlyvars:
dadd('\\begin{description}')
for n in onlyvars:
var = m['vars'][n]
modobjs.append(n)
ct = capi_maps.getctype(var)
at = capi_maps.c2capi_map[ct]
dm = capi_maps.getarrdims(n, var)
dms = dm['dims'].replace('*', '-1').strip()
dms = dms.replace(':', '-1').strip()
if not dms:
dms = '-1'
use_fgetdims2 = fgetdims2
if isstringarray(var):
if 'charselector' in var and 'len' in var['charselector']:
cadd('\t{"%s",%s,{{%s,%s}},%s},'
% (undo_rmbadname1(n), dm['rank'], dms, var['charselector']['len'], at))
use_fgetdims2 = fgetdims2_sa
else:
cadd('\t{"%s",%s,{{%s}},%s},' %
(undo_rmbadname1(n), dm['rank'], dms, at))
else:
cadd('\t{"%s",%s,{{%s}},%s},' %
(undo_rmbadname1(n), dm['rank'], dms, at))
dadd('\\item[]{{}\\verb@%s@{}}' %
(capi_maps.getarrdocsign(n, var)))
if hasnote(var):
note = var['note']
if isinstance(note, list):
note = '\n'.join(note)
dadd('--- %s' % (note))
if isallocatable(var):
fargs.append('f2py_%s_getdims_%s' % (m['name'], n))
efargs.append(fargs[-1])
sargs.append(
'void (*%s)(int*,int*,void(*)(char*,int*),int*)' % (n))
sargsp.append('void (*)(int*,int*,void(*)(char*,int*),int*)')
iadd('\tf2py_%s_def[i_f2py++].func = %s;' % (m['name'], n))
fadd('subroutine %s(r,s,f2pysetdata,flag)' % (fargs[-1]))
fadd('use %s, only: d => %s\n' %
(m['name'], undo_rmbadname1(n)))
fadd('integer flag\n')
fhooks[0] = fhooks[0] + fgetdims1
dms = eval('range(1,%s+1)' % (dm['rank']))
fadd(' allocate(d(%s))\n' %
(','.join(['s(%s)' % i for i in dms])))
fhooks[0] = fhooks[0] + use_fgetdims2
fadd('end subroutine %s' % (fargs[-1]))
else:
fargs.append(n)
sargs.append('char *%s' % (n))
sargsp.append('char*')
iadd('\tf2py_%s_def[i_f2py++].data = %s;' % (m['name'], n))
if onlyvars:
dadd('\\end{description}')
if hasbody(m):
for b in m['body']:
if not isroutine(b):
print('Skipping', b['block'], b['name'])
continue
modobjs.append('%s()' % (b['name']))
b['modulename'] = m['name']
api, wrap = rules.buildapi(b)
if isfunction(b):
fhooks[0] = fhooks[0] + wrap
fargs.append('f2pywrap_%s_%s' % (m['name'], b['name']))
ifargs.append(func2subr.createfuncwrapper(b, signature=1))
else:
if wrap:
fhooks[0] = fhooks[0] + wrap
fargs.append('f2pywrap_%s_%s' % (m['name'], b['name']))
ifargs.append(
func2subr.createsubrwrapper(b, signature=1))
else:
fargs.append(b['name'])
mfargs.append(fargs[-1])
api['externroutines'] = []
ar = applyrules(api, vrd)
ar['docs'] = []
ar['docshort'] = []
ret = dictappend(ret, ar)
cadd('\t{"%s",-1,{{-1}},0,NULL,(void *)f2py_rout_#modulename#_%s_%s,doc_f2py_rout_#modulename#_%s_%s},' %
(b['name'], m['name'], b['name'], m['name'], b['name']))
sargs.append('char *%s' % (b['name']))
sargsp.append('char *')
iadd('\tf2py_%s_def[i_f2py++].data = %s;' %
(m['name'], b['name']))
cadd('\t{NULL}\n};\n')
iadd('}')
ihooks[0] = 'static void f2py_setup_%s(%s) {\n\tint i_f2py=0;%s' % (
m['name'], ','.join(sargs), ihooks[0])
if '_' in m['name']:
F_FUNC = 'F_FUNC_US'
else:
F_FUNC = 'F_FUNC'
iadd('extern void %s(f2pyinit%s,F2PYINIT%s)(void (*)(%s));'
% (F_FUNC, m['name'], m['name'].upper(), ','.join(sargsp)))
iadd('static void f2py_init_%s(void) {' % (m['name']))
iadd('\t%s(f2pyinit%s,F2PYINIT%s)(f2py_setup_%s);'
% (F_FUNC, m['name'], m['name'].upper(), m['name']))
iadd('}\n')
ret['f90modhooks'] = ret['f90modhooks'] + chooks + ihooks
ret['initf90modhooks'] = ['\tPyDict_SetItemString(d, "%s", PyFortranObject_New(f2py_%s_def,f2py_init_%s));' % (
m['name'], m['name'], m['name'])] + ret['initf90modhooks']
fadd('')
fadd('subroutine f2pyinit%s(f2pysetupfunc)' % (m['name']))
if mfargs:
for a in undo_rmbadname(mfargs):
fadd('use %s, only : %s' % (m['name'], a))
if ifargs:
fadd(' '.join(['interface'] + ifargs))
fadd('end interface')
fadd('external f2pysetupfunc')
if efargs:
for a in undo_rmbadname(efargs):
fadd('external %s' % (a))
fadd('call f2pysetupfunc(%s)' % (','.join(undo_rmbadname(fargs))))
fadd('end subroutine f2pyinit%s\n' % (m['name']))
dadd('\n'.join(ret['latexdoc']).replace(
r'\subsection{', r'\subsubsection{'))
ret['latexdoc'] = []
ret['docs'].append('"\t%s --- %s"' % (m['name'],
','.join(undo_rmbadname(modobjs))))
ret['routine_defs'] = ''
ret['doc'] = []
ret['docshort'] = []
ret['latexdoc'] = doc[0]
if len(ret['docs']) <= 1:
ret['docs'] = ''
return ret, fhooks[0]
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
199,
3425,
481,
2710,
859,
2291,
367,
289,
18,
647,
18,
69,
14,
199,
199,
7384,
12293,
510,
2210,
85,
22912,
834,
1006,
4481,
4644,
12,
199,
48,
2210,
85,
22912,
834,
665,
16343,
85,
32,
73,
679,
14,
1024,
30,
199,
7980,
370,
675,
12,
2811,
12,
436,
11207,
642,
2032,
365,
1627,
1334,
314,
199,
9187,
402,
314,
20602,
844,
14,
199,
199,
2826,
3408,
2281,
3651,
14956,
10934,
1549,
5292,
14,
221,
4815,
15059,
1488,
11237,
593,
3705,
820,
22481,
14,
199,
4,
2506,
26,
11811,
15,
996,
15,
1644,
5851,
26,
1216,
26,
1789,
2672,
199,
48,
2210,
85,
22912,
834,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
363,
1023,
363,
275,
7880,
12714,
26,
413,
14,
1465,
2672,
22774,
709,
6809,
17,
61,
199,
199,
70,
18,
647,
63,
1023,
275,
283,
9295,
658,
70,
18,
647,
446,
86,
19097,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
1275,
492,
13648,
63,
8919,
199,
504,
1275,
492,
2562,
18,
954,
82,
199,
504,
1275,
67,
8085,
18496,
492,
18172,
63,
82,
887,
350,
354,
12,
18172,
63,
82,
887,
350,
354,
17,
199,
199,
3,
710,
24656,
293,
434,
2741,
701,
11593,
9204,
14,
647,
365,
4346,
367,
2005,
4882,
370,
3468,
14,
199,
3,
3709,
314,
4346,
3423,
3913,
506,
12037,
701,
2955,
5261,
10303,
402,
314,
199,
3,
1233,
12,
652,
365,
17925,
597,
370,
675,
492,
627,
9413,
282,
12160,
24200,
316,
402,
289,
18,
647,
14,
199,
504,
1275,
10962,
9204,
492,
627,
199,
199,
1419,
275,
1052,
421,
199,
318,
2342,
70,
2710,
3112,
8,
77,
304,
272,
340,
365,
578,
8,
77,
304,
267,
372,
359,
77,
61,
272,
340,
440,
965,
2030,
8,
77,
304,
267,
372,
942,
272,
2203,
275,
942,
272,
367,
330,
315,
333,
459,
2030,
2565,
267,
340,
365,
578,
8,
66,
304,
288,
2203,
14,
740,
8,
66,
9,
267,
587,
26,
288,
2203,
275,
2203,
435,
2342,
70,
2710,
3112,
8,
66,
9,
272,
372,
2203,
199,
199,
27823,
5380,
17,
275,
9638,
489,
5957,
289,
18,
647,
409,
576,
489,
11461,
700,
489,
3000,
519,
12,
73,
489,
3000,
4042,
68,
9,
308,
21565,
489,
700,
275,
1275,
19823,
14,
489,
340,
334,
19570,
8,
68,
430,
2066,
268,
886,
284,
29,
17,
12,
82,
288,
340,
3666,
890,
8,
68,
12,
73,
680,
685,
14,
83,
8,
73,
4992,
460,
14,
8,
83,
8,
73,
680,
303,
14,
16,
430,
2066,
2049,
700,
275,
1275,
15064,
14,
288,
1284,
340,
268,
1284,
886,
268,
340,
334,
561,
9,
2066,
288,
7962,
6280,
8,
68,
9,
268,
1284,
340,
489,
1284,
340,
489,
340,
3666,
14,
1397,
14,
19570,
8,
68,
4992,
460,
14,
8,
83,
8,
17,
680,
303,
14,
17,
430,
2066,
624,
450,
980,
14,
25319,
1252,
21210,
199,
199,
27823,
5380,
18,
275,
9638,
489,
1284,
340,
489,
340,
334,
19570,
8,
68,
430,
2066,
268,
886,
284,
29,
17,
12,
82,
288,
308,
8,
73,
9,
275,
1568,
8,
68,
12,
73,
9,
268,
1284,
886,
489,
1284,
340,
489,
3305,
275,
413,
489,
1240,
289,
18,
647,
409,
576,
8,
68,
12,
19570,
8,
68,
430,
624,
199,
199,
27823,
5380,
18,
63,
2231,
275,
9638,
489,
1284,
340,
489,
340,
334,
19570,
8,
68,
430,
2066,
268,
886,
284,
29,
17,
12,
82,
288,
308,
8,
73,
9,
275,
1568,
8,
68,
12,
73,
9,
268,
1284,
886,
268,
8546,
83,
8,
82,
9,
1471,
506,
4472,
370,
822,
8,
68,
8,
17,
430,
489,
1284,
340,
489,
3305,
275,
499,
489,
1240,
289,
18,
647,
409,
576,
8,
68,
12,
19570,
8,
68,
430,
624,
421,
199,
318,
1900,
7922,
8,
647,
1494,
304,
272,
2288,
289,
362,
5380,
17,
12,
289,
362,
5380,
18,
272,
687,
1275,
492,
4713,
272,
2203,
275,
791,
70,
2710,
1494,
7922,
356,
990,
283,
826,
70,
2710,
1494,
7922,
356,
990,
283,
2030,
356,
990,
1779,
283,
9321,
356,
788,
38,
63,
19587,
297,
283,
1144,
785,
14,
72,
995,
1779,
283,
29862,
509,
356,
791,
9441,
16,
356,
1557,
78,
297,
283,
9441,
356,
1557,
78,
2267,
1779,
283,
4757,
356,
788,
2,
38,
14522,
9137,
15,
2720,
4621,
18589,
78,
2,
995,
1779,
283,
7572,
1301,
356,
23455,
272,
289,
7922,
275,
24506,
339,
347,
289,
525,
8,
604,
12,
308,
29,
70,
7922,
304,
267,
308,
59,
16,
61,
275,
1543,
83,
60,
78,
420,
450,
83,
7,
450,
334,
83,
59,
16,
467,
1004,
9,
272,
1382,
275,
24506,
339,
347,
366,
525,
8,
604,
12,
308,
29,
1301,
304,
267,
308,
59,
16,
61,
275,
1543,
83,
60,
78,
5,
83,
7,
450,
334,
83,
59,
16,
467,
1004,
9,
272,
367,
333,
315,
2342,
70,
2710,
3112,
8,
647,
1494,
304,
267,
308,
589,
12,
289,
589,
12,
9530,
589,
12,
3413,
8718,
12,
440,
2936,
12,
1454,
2936,
275,
990,
990,
990,
990,
359,
288,
333,
459,
354,
2157,
942,
267,
308,
589,
80,
275,
942,
267,
340,
589,
275,
942,
267,
19751,
589,
275,
942,
267,
340,
965,
2030,
8,
77,
304,
288,
367,
330,
315,
333,
459,
2030,
2565,
355,
440,
2936,
14,
740,
8,
66,
459,
354,
1105,
267,
367,
302,
315,
333,
459,
2936,
2278,
1612,
837,
288,
2729,
275,
333,
459,
2936,
3488,
78,
61,
288,
340,
334,
78,
440,
315,
440,
2936,
9,
436,
334,
1397,
634,
63,
269,
8,
374,
17456,
63,
8191,
12,
365,
4239,
5130,
1391,
2298,
355,
1454,
2936,
14,
740,
8,
78,
9,
355,
19751,
589,
14,
740,
8,
78,
9,
267,
734,
17091,
2258,
84,
60,
84,
11493,
316,
481,
2710,
859,
2291,
367,
2071,
83,
2,
29279,
78,
7,
450,
355,
334,
77,
459,
354,
5156,
267,
340,
1454,
2936,
26,
288,
734,
17091,
2258,
84,
60,
84,
221,
17198,
26,
450,
83,
60,
78,
7,
450,
661,
1987,
904,
8,
2118,
2936,
1724,
267,
2468,
745,
83,
275,
24506,
398,
347,
286,
525,
8,
604
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
199,
3425,
481,
2710,
859,
2291,
367,
289,
18,
647,
18,
69,
14,
199,
199,
7384,
12293,
510,
2210,
85,
22912,
834,
1006,
4481,
4644,
12,
199,
48,
2210,
85,
22912,
834,
665,
16343,
85,
32,
73,
679,
14,
1024,
30,
199,
7980,
370,
675,
12,
2811,
12,
436,
11207,
642,
2032,
365,
1627,
1334,
314,
199,
9187,
402,
314,
20602,
844,
14,
199,
199,
2826,
3408,
2281,
3651,
14956,
10934,
1549,
5292,
14,
221,
4815,
15059,
1488,
11237,
593,
3705,
820,
22481,
14,
199,
4,
2506,
26,
11811,
15,
996,
15,
1644,
5851,
26,
1216,
26,
1789,
2672,
199,
48,
2210,
85,
22912,
834,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
363,
1023,
363,
275,
7880,
12714,
26,
413,
14,
1465,
2672,
22774,
709,
6809,
17,
61,
199,
199,
70,
18,
647,
63,
1023,
275,
283,
9295,
658,
70,
18,
647,
446,
86,
19097,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
1275,
492,
13648,
63,
8919,
199,
504,
1275,
492,
2562,
18,
954,
82,
199,
504,
1275,
67,
8085,
18496,
492,
18172,
63,
82,
887,
350,
354,
12,
18172,
63,
82,
887,
350,
354,
17,
199,
199,
3,
710,
24656,
293,
434,
2741,
701,
11593,
9204,
14,
647,
365,
4346,
367,
2005,
4882,
370,
3468,
14,
199,
3,
3709,
314,
4346,
3423,
3913,
506,
12037,
701,
2955,
5261,
10303,
402,
314,
199,
3,
1233,
12,
652,
365,
17925,
597,
370,
675,
492,
627,
9413,
282,
12160,
24200,
316,
402,
289,
18,
647,
14,
199,
504,
1275,
10962,
9204,
492,
627,
199,
199,
1419,
275,
1052,
421,
199,
318,
2342,
70,
2710,
3112,
8,
77,
304,
272,
340,
365,
578,
8,
77,
304,
267,
372,
359,
77,
61,
272,
340,
440,
965,
2030,
8,
77,
304,
267,
372,
942,
272,
2203,
275,
942,
272,
367,
330,
315,
333,
459,
2030,
2565,
267,
340,
365,
578,
8,
66,
304,
288,
2203,
14,
740,
8,
66,
9,
267,
587,
26,
288,
2203,
275,
2203,
435,
2342,
70,
2710,
3112,
8,
66,
9,
272,
372,
2203,
199,
199,
27823,
5380,
17,
275,
9638,
489,
5957,
289,
18,
647,
409,
576,
489,
11461,
700,
489,
3000,
519,
12,
73,
489,
3000,
4042,
68,
9,
308,
21565,
489,
700,
275,
1275,
19823,
14,
489,
340,
334,
19570,
8,
68,
430,
2066,
268,
886,
284,
29,
17,
12,
82,
288,
340,
3666,
890,
8,
68,
12,
73,
680,
685,
14,
83,
8,
73,
4992,
460,
14,
8,
83,
8,
73,
680,
303,
14,
16,
430,
2066,
2049,
700,
275,
1275,
15064,
14,
288,
1284,
340,
268,
1284,
886,
268,
340,
334,
561,
9,
2066,
288,
7962,
6280,
8,
68,
9,
268,
1284,
340,
489,
1284,
340,
489,
340,
3666,
14,
1397,
14,
19570,
8,
68,
4992,
460,
14,
8,
83,
8,
17,
680,
303,
14,
17,
430,
2066,
624,
450,
980,
14,
25319,
1252,
21210,
199,
199,
27823,
5380,
18,
275,
9638,
489,
1284,
340,
489,
340,
334,
19570,
8,
68,
430,
2066,
268,
886,
284,
29,
17,
12,
82,
288,
308,
8,
73,
9,
275,
1568,
8,
68,
12,
73,
9,
268,
1284,
886,
489,
1284,
340,
489,
3305,
275,
413,
489,
1240,
289,
18,
647,
409,
576,
8,
68,
12,
19570,
8,
68,
430,
624,
199,
199,
27823,
5380,
18,
63,
2231,
275,
9638,
489,
1284,
340,
489,
340,
334,
19570,
8,
68,
430,
2066,
268,
886,
284,
29,
17,
12,
82,
288,
308,
8,
73,
9,
275,
1568,
8,
68,
12,
73,
9,
268,
1284,
886,
268,
8546,
83,
8,
82,
9,
1471,
506,
4472,
370,
822,
8,
68,
8,
17,
430,
489,
1284,
340,
489,
3305,
275,
499,
489,
1240,
289,
18,
647,
409,
576,
8,
68,
12,
19570,
8,
68,
430,
624,
421,
199,
318,
1900,
7922,
8,
647,
1494,
304,
272,
2288,
289,
362,
5380,
17,
12,
289,
362,
5380,
18,
272,
687,
1275,
492,
4713,
272,
2203,
275,
791,
70,
2710,
1494,
7922,
356,
990,
283,
826,
70,
2710,
1494,
7922,
356,
990,
283,
2030,
356,
990,
1779,
283,
9321,
356,
788,
38,
63,
19587,
297,
283,
1144,
785,
14,
72,
995,
1779,
283,
29862,
509,
356,
791,
9441,
16,
356,
1557,
78,
297,
283,
9441,
356,
1557,
78,
2267,
1779,
283,
4757,
356,
788,
2,
38,
14522,
9137,
15,
2720,
4621,
18589,
78,
2,
995,
1779,
283,
7572,
1301,
356,
23455,
272,
289,
7922,
275,
24506,
339,
347,
289,
525,
8,
604,
12,
308,
29,
70,
7922,
304,
267,
308,
59,
16,
61,
275,
1543,
83,
60,
78,
420,
450,
83,
7,
450,
334,
83,
59,
16,
467,
1004,
9,
272,
1382,
275,
24506,
339,
347,
366,
525,
8,
604,
12,
308,
29,
1301,
304,
267,
308,
59,
16,
61,
275,
1543,
83,
60,
78,
5,
83,
7,
450,
334,
83,
59,
16,
467,
1004,
9,
272,
367,
333,
315,
2342,
70,
2710,
3112,
8,
647,
1494,
304,
267,
308,
589,
12,
289,
589,
12,
9530,
589,
12,
3413,
8718,
12,
440,
2936,
12,
1454,
2936,
275,
990,
990,
990,
990,
359,
288,
333,
459,
354,
2157,
942,
267,
308,
589,
80,
275,
942,
267,
340,
589,
275,
942,
267,
19751,
589,
275,
942,
267,
340,
965,
2030,
8,
77,
304,
288,
367,
330,
315,
333,
459,
2030,
2565,
355,
440,
2936,
14,
740,
8,
66,
459,
354,
1105,
267,
367,
302,
315,
333,
459,
2936,
2278,
1612,
837,
288,
2729,
275,
333,
459,
2936,
3488,
78,
61,
288,
340,
334,
78,
440,
315,
440,
2936,
9,
436,
334,
1397,
634,
63,
269,
8,
374,
17456,
63,
8191,
12,
365,
4239,
5130,
1391,
2298,
355,
1454,
2936,
14,
740,
8,
78,
9,
355,
19751,
589,
14,
740,
8,
78,
9,
267,
734,
17091,
2258,
84,
60,
84,
11493,
316,
481,
2710,
859,
2291,
367,
2071,
83,
2,
29279,
78,
7,
450,
355,
334,
77,
459,
354,
5156,
267,
340,
1454,
2936,
26,
288,
734,
17091,
2258,
84,
60,
84,
221,
17198,
26,
450,
83,
60,
78,
7,
450,
661,
1987,
904,
8,
2118,
2936,
1724,
267,
2468,
745,
83,
275,
24506,
398,
347,
286,
525,
8,
604,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sjpadgett/lepan-griffin-kernel
|
tools/perf/scripts/python/sctop.py
|
11180
|
1924
|
# system call top
# (c) 2010, Tom Zanussi <tzanussi@gmail.com>
# Licensed under the terms of the GNU GPL License version 2
#
# Periodically displays system-wide system call totals, broken down by
# syscall. If a [comm] arg is specified, only syscalls called by
# [comm] are displayed. If an [interval] arg is specified, the display
# will be refreshed every [interval] seconds. The default interval is
# 3 seconds.
import os, sys, thread, time
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from Core import *
from Util import *
usage = "perf script -s sctop.py [comm] [interval]\n";
for_comm = None
default_interval = 3
interval = default_interval
if len(sys.argv) > 3:
sys.exit(usage)
if len(sys.argv) > 2:
for_comm = sys.argv[1]
interval = int(sys.argv[2])
elif len(sys.argv) > 1:
try:
interval = int(sys.argv[1])
except ValueError:
for_comm = sys.argv[1]
interval = default_interval
syscalls = autodict()
def trace_begin():
thread.start_new_thread(print_syscall_totals, (interval,))
pass
def raw_syscalls__sys_enter(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
id, args):
if for_comm is not None:
if common_comm != for_comm:
return
try:
syscalls[id] += 1
except TypeError:
syscalls[id] = 1
def print_syscall_totals(interval):
while 1:
clear_term()
if for_comm is not None:
print "\nsyscall events for %s:\n\n" % (for_comm),
else:
print "\nsyscall events:\n\n",
print "%-40s %10s\n" % ("event", "count"),
print "%-40s %10s\n" % ("----------------------------------------", \
"----------"),
for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \
reverse = True):
try:
print "%-40s %10d\n" % (syscall_name(id), val),
except TypeError:
pass
syscalls.clear()
time.sleep(interval)
|
gpl-2.0
|
[
3,
2656,
1240,
2746,
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,
3492,
11273,
1183,
17561,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
199,
3,
18901,
14,
221,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
199,
3,
359,
1404,
61,
787,
9080,
14,
982,
376,
359,
4284,
61,
1680,
365,
2013,
12,
314,
2929,
199,
3,
911,
506,
9236,
379,
4036,
359,
4284,
61,
4696,
14,
221,
710,
849,
6252,
365,
199,
3,
650,
4696,
14,
199,
199,
646,
747,
12,
984,
12,
2462,
12,
900,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
627,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
308,
319,
411,
14,
647,
359,
1404,
61,
359,
4284,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
885,
63,
4284,
275,
650,
199,
4284,
275,
849,
63,
4284,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
650,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
198,
4284,
275,
1109,
8,
1274,
14,
3020,
59,
18,
566,
199,
4164,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
893,
26,
507,
198,
4284,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
198,
2590,
1722,
26,
507,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
507,
198,
4284,
275,
849,
63,
4284,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
2671,
14,
928,
63,
1222,
63,
2671,
8,
1361,
63,
19444,
63,
17552,
12,
334,
4284,
4641,
199,
198,
1529,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
199,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
507,
198,
692,
2863,
63,
1404,
1137,
367,
63,
1404,
26,
686,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
8,
4284,
304,
199,
198,
6710,
413,
26,
507,
198,
3584,
63,
5125,
342,
507,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
686,
198,
1361,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
507,
198,
2836,
26,
686,
198,
1361,
1867,
26605,
4474,
3427,
78,
60,
78,
401,
2742,
198,
1361,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
507,
198,
1361,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
5264,
298,
9460,
1288,
2742,
198,
509,
1305,
12,
1139,
315,
3355,
8,
14507,
14,
4611,
1062,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
971,
4671,
420,
3837,
275,
715,
304,
686,
198,
893,
26,
1585,
198,
1361,
18301,
2167,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
686,
198,
2590,
3146,
26,
1585,
198,
1529,
507,
198,
14507,
14,
3584,
342,
507,
198,
521,
14,
4532,
8,
4284,
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
] |
[
2656,
1240,
2746,
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,
3492,
11273,
1183,
17561,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
199,
3,
18901,
14,
221,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
199,
3,
359,
1404,
61,
787,
9080,
14,
982,
376,
359,
4284,
61,
1680,
365,
2013,
12,
314,
2929,
199,
3,
911,
506,
9236,
379,
4036,
359,
4284,
61,
4696,
14,
221,
710,
849,
6252,
365,
199,
3,
650,
4696,
14,
199,
199,
646,
747,
12,
984,
12,
2462,
12,
900,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
627,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
308,
319,
411,
14,
647,
359,
1404,
61,
359,
4284,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
885,
63,
4284,
275,
650,
199,
4284,
275,
849,
63,
4284,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
650,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
198,
4284,
275,
1109,
8,
1274,
14,
3020,
59,
18,
566,
199,
4164,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
893,
26,
507,
198,
4284,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
198,
2590,
1722,
26,
507,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
507,
198,
4284,
275,
849,
63,
4284,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
2671,
14,
928,
63,
1222,
63,
2671,
8,
1361,
63,
19444,
63,
17552,
12,
334,
4284,
4641,
199,
198,
1529,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
199,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
507,
198,
692,
2863,
63,
1404,
1137,
367,
63,
1404,
26,
686,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
8,
4284,
304,
199,
198,
6710,
413,
26,
507,
198,
3584,
63,
5125,
342,
507,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
686,
198,
1361,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
507,
198,
2836,
26,
686,
198,
1361,
1867,
26605,
4474,
3427,
78,
60,
78,
401,
2742,
198,
1361,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
507,
198,
1361,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
5264,
298,
9460,
1288,
2742,
198,
509,
1305,
12,
1139,
315,
3355,
8,
14507,
14,
4611,
1062,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
971,
4671,
420,
3837,
275,
715,
304,
686,
198,
893,
26,
1585,
198,
1361,
18301,
2167,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
686,
198,
2590,
3146,
26,
1585,
198,
1529,
507,
198,
14507,
14,
3584,
342,
507,
198,
521,
14,
4532,
8,
4284,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
biospi/seamass-windeps
|
src/boost_1_57_0/libs/python/test/extract.py
|
46
|
2497
|
# Copyright David Abrahams 2004. Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
'''
>>> from extract_ext import *
Just about anything has a truth value in Python
>>> assert check_bool(None)
>>> extract_bool(None)
0
>>> assert check_bool(2)
>>> extract_bool(2)
1
>>> assert not check_bool('')
Check that object manager types work properly. These are a different
case because they wrap Python objects instead of being wrapped by them.
>>> assert not check_list(2)
>>> try: x = extract_list(2)
... except TypeError, x:
... if str(x) != 'Expecting an object of type list; got an object of type int instead':
... print x
... else:
... print 'expected an exception, got', x, 'instead'
Can't extract a list from a tuple. Use list(x) to convert a sequence
to a list:
>>> assert not check_list((1, 2, 3))
>>> assert check_list([1, 2, 3])
>>> extract_list([1, 2, 3])
[1, 2, 3]
Can get a char const* from a Python string:
>>> assert check_cstring('hello')
>>> extract_cstring('hello')
'hello'
Can't get a char const* from a Python int:
>>> assert not check_cstring(1)
>>> try: x = extract_cstring(1)
... except TypeError: pass
... else:
... print 'expected an exception, got', x, 'instead'
Extract an std::string (class) rvalue from a native Python type
>>> assert check_string('hello')
>>> extract_string('hello')
'hello'
Constant references are not treated as rvalues for the purposes of
extract:
>>> assert not check_string_cref('hello')
We can extract lvalues where appropriate:
>>> x = X(42)
>>> check_X(x)
1
>>> extract_X(x)
X(42)
>>> check_X_ptr(x)
1
>>> extract_X_ptr(x)
X(42)
>>> extract_X_ref(x)
X(42)
Demonstrate that double-extraction of an rvalue works, and all created
copies of the object are destroyed:
>>> n = count_Xs()
>>> double_X(333)
666
>>> count_Xs() - n
0
General check for cleanliness:
>>> del x
>>> count_Xs()
0
'''
def run(args = None):
import sys
import doctest
if args is not None:
sys.argv = args
return doctest.testmod(sys.modules.get(__name__))
if __name__ == '__main__':
print "running..."
import sys
status = run()[0]
if (status == 0): print "Done."
sys.exit(status)
|
apache-2.0
|
[
3,
1898,
20232,
437,
7828,
10670,
83,
8353,
14,
17484,
1334,
314,
30470,
199,
3,
2290,
844,
12,
3394,
413,
14,
16,
14,
334,
9295,
23073,
199,
3,
570,
5113,
63,
17,
63,
16,
14,
2424,
503,
1331,
737,
1455,
921,
1544,
14,
15589,
14,
1308,
15,
3961,
63,
17,
63,
16,
14,
2424,
9,
199,
2344,
272,
1306,
687,
5536,
63,
832,
492,
627,
199,
199,
22850,
3595,
7003,
965,
282,
16865,
574,
315,
2018,
339,
1306,
702,
1104,
63,
2245,
8,
403,
9,
272,
1306,
5536,
63,
2245,
8,
403,
9,
272,
378,
339,
1306,
702,
1104,
63,
2245,
8,
18,
9,
272,
1306,
5536,
63,
2245,
8,
18,
9,
272,
413,
339,
1306,
702,
440,
1104,
63,
2245,
8355,
199,
199,
1799,
626,
909,
5256,
2943,
1736,
7684,
14,
5723,
787,
282,
3365,
199,
2546,
2952,
2985,
4816,
2018,
2251,
3140,
402,
3769,
8072,
701,
3062,
14,
339,
1306,
702,
440,
1104,
63,
513,
8,
18,
9,
272,
1306,
862,
26,
671,
275,
5536,
63,
513,
8,
18,
9,
272,
2263,
871,
3146,
12,
671,
26,
272,
2263,
258,
340,
620,
8,
88,
9,
1137,
283,
28864,
376,
909,
402,
730,
769,
27,
4788,
376,
909,
402,
730,
1109,
3140,
356,
272,
2263,
260,
870,
671,
272,
2263,
587,
26,
272,
2263,
258,
870,
283,
2062,
376,
1919,
12,
4788,
297,
671,
12,
283,
23145,
7,
199,
199,
6049,
1133,
5536,
282,
769,
687,
282,
2008,
14,
3645,
769,
8,
88,
9,
370,
3957,
282,
3414,
199,
475,
282,
769,
26,
2286,
1306,
702,
440,
1104,
63,
513,
1332,
17,
12,
499,
12,
650,
430,
272,
1306,
702,
1104,
63,
513,
779,
17,
12,
499,
12,
650,
566,
272,
1306,
5536,
63,
513,
779,
17,
12,
499,
12,
650,
566,
272,
359,
17,
12,
499,
12,
650,
61,
199,
199,
6049,
664,
282,
1495,
950,
10,
687,
282,
2018,
1059,
26,
339,
1306,
702,
1104,
63,
67,
875,
360,
5006,
358,
272,
1306,
5536,
63,
67,
875,
360,
5006,
358,
272,
283,
5006,
7,
199,
199,
6049,
1133,
664,
282,
1495,
950,
10,
687,
282,
2018,
1109,
26,
2286,
1306,
702,
440,
1104,
63,
67,
875,
8,
17,
9,
272,
1306,
862,
26,
671,
275,
5536,
63,
67,
875,
8,
17,
9,
272,
2263,
871,
3146,
26,
986,
272,
2263,
587,
26,
272,
2263,
258,
870,
283,
2062,
376,
1919,
12,
4788,
297,
671,
12,
283,
23145,
7,
199,
199,
12147,
376,
2418,
447,
875,
334,
533,
9,
519,
585,
687,
282,
5438,
2018,
730,
339,
1306,
702,
1104,
63,
875,
360,
5006,
358,
272,
1306,
5536,
63,
875,
360,
5006,
358,
272,
283,
5006,
7,
199,
199,
9737,
6941,
787,
440,
10184,
465,
519,
1459,
367,
314,
12901,
402,
199,
5005,
26,
339,
1306,
702,
440,
1104,
63,
875,
63,
67,
1121,
360,
5006,
358,
199,
199,
6004,
883,
5536,
634,
1459,
2382,
5827,
26,
339,
1306,
671,
275,
1323,
8,
2260,
9,
272,
1306,
1104,
63,
56,
8,
88,
9,
272,
413,
272,
1306,
5536,
63,
56,
8,
88,
9,
272,
1323,
8,
2260,
9,
339,
1306,
1104,
63,
56,
63,
4695,
8,
88,
9,
272,
413,
272,
1306,
5536,
63,
56,
63,
4695,
8,
88,
9,
272,
1323,
8,
2260,
9,
272,
1306,
5536,
63,
56,
63,
1121,
8,
88,
9,
272,
1323,
8,
2260,
9,
199,
199,
872,
2106,
18161,
626,
4270,
13,
24020,
402,
376,
519,
585,
5419,
12,
436,
1006,
2737,
199,
16847,
402,
314,
909,
787,
28924,
26,
339,
1306,
302,
275,
2338,
63,
56,
83,
342,
272,
1306,
4270,
63,
56,
8,
11769,
9,
272,
1227,
1272,
272,
1306,
2338,
63,
56,
83,
342,
446,
302,
272,
378,
199,
199,
14109,
1104,
367,
3633,
604,
385,
26,
339,
1306,
2150,
671,
272,
1306,
2338,
63,
56,
83,
342,
272,
378,
199,
2344,
199,
199,
318,
1255,
8,
589,
275,
488,
304,
272,
492,
984,
272,
492,
8868,
339,
340,
1249,
365,
440,
488,
26,
267,
984,
14,
3020,
275,
1249,
272,
372,
8868,
14,
29446,
8,
1274,
14,
3112,
14,
362,
3460,
354,
8964,
1362,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
870,
298,
5720,
11500,
272,
492,
984,
272,
2004,
275,
1255,
3430,
16,
61,
272,
340,
334,
1205,
508,
378,
304,
870,
298,
10759,
2122,
272,
984,
14,
2224,
8,
1205,
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
] |
[
1898,
20232,
437,
7828,
10670,
83,
8353,
14,
17484,
1334,
314,
30470,
199,
3,
2290,
844,
12,
3394,
413,
14,
16,
14,
334,
9295,
23073,
199,
3,
570,
5113,
63,
17,
63,
16,
14,
2424,
503,
1331,
737,
1455,
921,
1544,
14,
15589,
14,
1308,
15,
3961,
63,
17,
63,
16,
14,
2424,
9,
199,
2344,
272,
1306,
687,
5536,
63,
832,
492,
627,
199,
199,
22850,
3595,
7003,
965,
282,
16865,
574,
315,
2018,
339,
1306,
702,
1104,
63,
2245,
8,
403,
9,
272,
1306,
5536,
63,
2245,
8,
403,
9,
272,
378,
339,
1306,
702,
1104,
63,
2245,
8,
18,
9,
272,
1306,
5536,
63,
2245,
8,
18,
9,
272,
413,
339,
1306,
702,
440,
1104,
63,
2245,
8355,
199,
199,
1799,
626,
909,
5256,
2943,
1736,
7684,
14,
5723,
787,
282,
3365,
199,
2546,
2952,
2985,
4816,
2018,
2251,
3140,
402,
3769,
8072,
701,
3062,
14,
339,
1306,
702,
440,
1104,
63,
513,
8,
18,
9,
272,
1306,
862,
26,
671,
275,
5536,
63,
513,
8,
18,
9,
272,
2263,
871,
3146,
12,
671,
26,
272,
2263,
258,
340,
620,
8,
88,
9,
1137,
283,
28864,
376,
909,
402,
730,
769,
27,
4788,
376,
909,
402,
730,
1109,
3140,
356,
272,
2263,
260,
870,
671,
272,
2263,
587,
26,
272,
2263,
258,
870,
283,
2062,
376,
1919,
12,
4788,
297,
671,
12,
283,
23145,
7,
199,
199,
6049,
1133,
5536,
282,
769,
687,
282,
2008,
14,
3645,
769,
8,
88,
9,
370,
3957,
282,
3414,
199,
475,
282,
769,
26,
2286,
1306,
702,
440,
1104,
63,
513,
1332,
17,
12,
499,
12,
650,
430,
272,
1306,
702,
1104,
63,
513,
779,
17,
12,
499,
12,
650,
566,
272,
1306,
5536,
63,
513,
779,
17,
12,
499,
12,
650,
566,
272,
359,
17,
12,
499,
12,
650,
61,
199,
199,
6049,
664,
282,
1495,
950,
10,
687,
282,
2018,
1059,
26,
339,
1306,
702,
1104,
63,
67,
875,
360,
5006,
358,
272,
1306,
5536,
63,
67,
875,
360,
5006,
358,
272,
283,
5006,
7,
199,
199,
6049,
1133,
664,
282,
1495,
950,
10,
687,
282,
2018,
1109,
26,
2286,
1306,
702,
440,
1104,
63,
67,
875,
8,
17,
9,
272,
1306,
862,
26,
671,
275,
5536,
63,
67,
875,
8,
17,
9,
272,
2263,
871,
3146,
26,
986,
272,
2263,
587,
26,
272,
2263,
258,
870,
283,
2062,
376,
1919,
12,
4788,
297,
671,
12,
283,
23145,
7,
199,
199,
12147,
376,
2418,
447,
875,
334,
533,
9,
519,
585,
687,
282,
5438,
2018,
730,
339,
1306,
702,
1104,
63,
875,
360,
5006,
358,
272,
1306,
5536,
63,
875,
360,
5006,
358,
272,
283,
5006,
7,
199,
199,
9737,
6941,
787,
440,
10184,
465,
519,
1459,
367,
314,
12901,
402,
199,
5005,
26,
339,
1306,
702,
440,
1104,
63,
875,
63,
67,
1121,
360,
5006,
358,
199,
199,
6004,
883,
5536,
634,
1459,
2382,
5827,
26,
339,
1306,
671,
275,
1323,
8,
2260,
9,
272,
1306,
1104,
63,
56,
8,
88,
9,
272,
413,
272,
1306,
5536,
63,
56,
8,
88,
9,
272,
1323,
8,
2260,
9,
339,
1306,
1104,
63,
56,
63,
4695,
8,
88,
9,
272,
413,
272,
1306,
5536,
63,
56,
63,
4695,
8,
88,
9,
272,
1323,
8,
2260,
9,
272,
1306,
5536,
63,
56,
63,
1121,
8,
88,
9,
272,
1323,
8,
2260,
9,
199,
199,
872,
2106,
18161,
626,
4270,
13,
24020,
402,
376,
519,
585,
5419,
12,
436,
1006,
2737,
199,
16847,
402,
314,
909,
787,
28924,
26,
339,
1306,
302,
275,
2338,
63,
56,
83,
342,
272,
1306,
4270,
63,
56,
8,
11769,
9,
272,
1227,
1272,
272,
1306,
2338,
63,
56,
83,
342,
446,
302,
272,
378,
199,
199,
14109,
1104,
367,
3633,
604,
385,
26,
339,
1306,
2150,
671,
272,
1306,
2338,
63,
56,
83,
342,
272,
378,
199,
2344,
199,
199,
318,
1255,
8,
589,
275,
488,
304,
272,
492,
984,
272,
492,
8868,
339,
340,
1249,
365,
440,
488,
26,
267,
984,
14,
3020,
275,
1249,
272,
372,
8868,
14,
29446,
8,
1274,
14,
3112,
14,
362,
3460,
354,
8964,
1362,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
870,
298,
5720,
11500,
272,
492,
984,
272,
2004,
275,
1255,
3430,
16,
61,
272,
340,
334,
1205,
508,
378,
304,
870,
298,
10759,
2122,
272,
984,
14,
2224,
8,
1205,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
rcharp/toyota-flask
|
numpy/numpy/polynomial/tests/test_classes.py
|
122
|
17714
|
"""Test inter-conversion of different polynomial classes.
This tests the convert and cast methods of all the polynomial classes.
"""
from __future__ import division, absolute_import, print_function
import operator as op
from numbers import Number
import numpy as np
from numpy.polynomial import (
Polynomial, Legendre, Chebyshev, Laguerre, Hermite, HermiteE)
from numpy.testing import (
assert_almost_equal, assert_raises, assert_equal, assert_,
run_module_suite)
from numpy.compat import long
classes = (
Polynomial, Legendre, Chebyshev, Laguerre,
Hermite, HermiteE)
def test_class_methods():
for Poly1 in classes:
for Poly2 in classes:
yield check_conversion, Poly1, Poly2
yield check_cast, Poly1, Poly2
for Poly in classes:
yield check_call, Poly
yield check_identity, Poly
yield check_basis, Poly
yield check_fromroots, Poly
yield check_fit, Poly
yield check_equal, Poly
yield check_not_equal, Poly
yield check_add, Poly
yield check_sub, Poly
yield check_mul, Poly
yield check_floordiv, Poly
yield check_truediv, Poly
yield check_mod, Poly
yield check_divmod, Poly
yield check_pow, Poly
yield check_integ, Poly
yield check_deriv, Poly
yield check_roots, Poly
yield check_linspace, Poly
yield check_mapparms, Poly
yield check_degree, Poly
yield check_copy, Poly
yield check_cutdeg, Poly
yield check_truncate, Poly
yield check_trim, Poly
#
# helper functions
#
random = np.random.random
def assert_poly_almost_equal(p1, p2, msg=""):
try:
assert_(np.all(p1.domain == p2.domain))
assert_(np.all(p1.window == p2.window))
assert_almost_equal(p1.coef, p2.coef)
except AssertionError:
msg = "Result: %s\nTarget: %s", (p1, p2)
raise AssertionError(msg)
#
# conversion methods that depend on two classes
#
def check_conversion(Poly1, Poly2):
x = np.linspace(0, 1, 10)
coef = random((3,))
d1 = Poly1.domain + random((2,))*.25
w1 = Poly1.window + random((2,))*.25
p1 = Poly1(coef, domain=d1, window=w1)
d2 = Poly2.domain + random((2,))*.25
w2 = Poly2.window + random((2,))*.25
p2 = p1.convert(kind=Poly2, domain=d2, window=w2)
assert_almost_equal(p2.domain, d2)
assert_almost_equal(p2.window, w2)
assert_almost_equal(p2(x), p1(x))
def check_cast(Poly1, Poly2):
x = np.linspace(0, 1, 10)
coef = random((3,))
d1 = Poly1.domain + random((2,))*.25
w1 = Poly1.window + random((2,))*.25
p1 = Poly1(coef, domain=d1, window=w1)
d2 = Poly2.domain + random((2,))*.25
w2 = Poly2.window + random((2,))*.25
p2 = Poly2.cast(p1, domain=d2, window=w2)
assert_almost_equal(p2.domain, d2)
assert_almost_equal(p2.window, w2)
assert_almost_equal(p2(x), p1(x))
#
# methods that depend on one class
#
def check_identity(Poly):
d = Poly.domain + random((2,))*.25
w = Poly.window + random((2,))*.25
x = np.linspace(d[0], d[1], 11)
p = Poly.identity(domain=d, window=w)
assert_equal(p.domain, d)
assert_equal(p.window, w)
assert_almost_equal(p(x), x)
def check_basis(Poly):
d = Poly.domain + random((2,))*.25
w = Poly.window + random((2,))*.25
p = Poly.basis(5, domain=d, window=w)
assert_equal(p.domain, d)
assert_equal(p.window, w)
assert_equal(p.coef, [0]*5 + [1])
def check_fromroots(Poly):
# check that requested roots are zeros of a polynomial
# of correct degree, domain, and window.
d = Poly.domain + random((2,))*.25
w = Poly.window + random((2,))*.25
r = random((5,))
p1 = Poly.fromroots(r, domain=d, window=w)
assert_equal(p1.degree(), len(r))
assert_equal(p1.domain, d)
assert_equal(p1.window, w)
assert_almost_equal(p1(r), 0)
# check that polynomial is monic
pdom = Polynomial.domain
pwin = Polynomial.window
p2 = Polynomial.cast(p1, domain=pdom, window=pwin)
assert_almost_equal(p2.coef[-1], 1)
def check_fit(Poly):
def f(x):
return x*(x - 1)*(x - 2)
x = np.linspace(0, 3)
y = f(x)
# check default value of domain and window
p = Poly.fit(x, y, 3)
assert_almost_equal(p.domain, [0, 3])
assert_almost_equal(p(x), y)
assert_equal(p.degree(), 3)
# check with given domains and window
d = Poly.domain + random((2,))*.25
w = Poly.window + random((2,))*.25
p = Poly.fit(x, y, 3, domain=d, window=w)
assert_almost_equal(p(x), y)
assert_almost_equal(p.domain, d)
assert_almost_equal(p.window, w)
# check with class domain default
p = Poly.fit(x, y, 3, [])
assert_equal(p.domain, Poly.domain)
assert_equal(p.window, Poly.window)
# check that fit accepts weights.
w = np.zeros_like(x)
z = y + random(y.shape)*.25
w[::2] = 1
p1 = Poly.fit(x[::2], z[::2], 3)
p2 = Poly.fit(x, z, 3, w=w)
assert_almost_equal(p1(x), p2(x))
def check_equal(Poly):
p1 = Poly([1, 2, 3], domain=[0, 1], window=[2, 3])
p2 = Poly([1, 1, 1], domain=[0, 1], window=[2, 3])
p3 = Poly([1, 2, 3], domain=[1, 2], window=[2, 3])
p4 = Poly([1, 2, 3], domain=[0, 1], window=[1, 2])
assert_(p1 == p1)
assert_(not p1 == p2)
assert_(not p1 == p3)
assert_(not p1 == p4)
def check_not_equal(Poly):
p1 = Poly([1, 2, 3], domain=[0, 1], window=[2, 3])
p2 = Poly([1, 1, 1], domain=[0, 1], window=[2, 3])
p3 = Poly([1, 2, 3], domain=[1, 2], window=[2, 3])
p4 = Poly([1, 2, 3], domain=[0, 1], window=[1, 2])
assert_(not p1 != p1)
assert_(p1 != p2)
assert_(p1 != p3)
assert_(p1 != p4)
def check_add(Poly):
# This checks commutation, not numerical correctness
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = p1 + p2
assert_poly_almost_equal(p2 + p1, p3)
assert_poly_almost_equal(p1 + c2, p3)
assert_poly_almost_equal(c2 + p1, p3)
assert_poly_almost_equal(p1 + tuple(c2), p3)
assert_poly_almost_equal(tuple(c2) + p1, p3)
assert_poly_almost_equal(p1 + np.array(c2), p3)
assert_poly_almost_equal(np.array(c2) + p1, p3)
assert_raises(TypeError, op.add, p1, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, op.add, p1, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, op.add, p1, Chebyshev([0]))
else:
assert_raises(TypeError, op.add, p1, Polynomial([0]))
def check_sub(Poly):
# This checks commutation, not numerical correctness
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = p1 - p2
assert_poly_almost_equal(p2 - p1, -p3)
assert_poly_almost_equal(p1 - c2, p3)
assert_poly_almost_equal(c2 - p1, -p3)
assert_poly_almost_equal(p1 - tuple(c2), p3)
assert_poly_almost_equal(tuple(c2) - p1, -p3)
assert_poly_almost_equal(p1 - np.array(c2), p3)
assert_poly_almost_equal(np.array(c2) - p1, -p3)
assert_raises(TypeError, op.sub, p1, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, op.sub, p1, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, op.sub, p1, Chebyshev([0]))
else:
assert_raises(TypeError, op.sub, p1, Polynomial([0]))
def check_mul(Poly):
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = p1 * p2
assert_poly_almost_equal(p2 * p1, p3)
assert_poly_almost_equal(p1 * c2, p3)
assert_poly_almost_equal(c2 * p1, p3)
assert_poly_almost_equal(p1 * tuple(c2), p3)
assert_poly_almost_equal(tuple(c2) * p1, p3)
assert_poly_almost_equal(p1 * np.array(c2), p3)
assert_poly_almost_equal(np.array(c2) * p1, p3)
assert_poly_almost_equal(p1 * 2, p1 * Poly([2]))
assert_poly_almost_equal(2 * p1, p1 * Poly([2]))
assert_raises(TypeError, op.mul, p1, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, op.mul, p1, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, op.mul, p1, Chebyshev([0]))
else:
assert_raises(TypeError, op.mul, p1, Polynomial([0]))
def check_floordiv(Poly):
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
c3 = list(random((2,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = Poly(c3)
p4 = p1 * p2 + p3
c4 = list(p4.coef)
assert_poly_almost_equal(p4 // p2, p1)
assert_poly_almost_equal(p4 // c2, p1)
assert_poly_almost_equal(c4 // p2, p1)
assert_poly_almost_equal(p4 // tuple(c2), p1)
assert_poly_almost_equal(tuple(c4) // p2, p1)
assert_poly_almost_equal(p4 // np.array(c2), p1)
assert_poly_almost_equal(np.array(c4) // p2, p1)
assert_poly_almost_equal(2 // p2, Poly([0]))
assert_poly_almost_equal(p2 // 2, 0.5*p2)
assert_raises(
TypeError, op.floordiv, p1, Poly([0], domain=Poly.domain + 1))
assert_raises(
TypeError, op.floordiv, p1, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, op.floordiv, p1, Chebyshev([0]))
else:
assert_raises(TypeError, op.floordiv, p1, Polynomial([0]))
def check_truediv(Poly):
# true division is valid only if the denominator is a Number and
# not a python bool.
p1 = Poly([1,2,3])
p2 = p1 * 5
for stype in np.ScalarType:
if not issubclass(stype, Number) or issubclass(stype, bool):
continue
s = stype(5)
assert_poly_almost_equal(op.truediv(p2, s), p1)
assert_raises(TypeError, op.truediv, s, p2)
for stype in (int, long, float):
s = stype(5)
assert_poly_almost_equal(op.truediv(p2, s), p1)
assert_raises(TypeError, op.truediv, s, p2)
for stype in [complex]:
s = stype(5, 0)
assert_poly_almost_equal(op.truediv(p2, s), p1)
assert_raises(TypeError, op.truediv, s, p2)
for s in [tuple(), list(), dict(), bool(), np.array([1])]:
assert_raises(TypeError, op.truediv, p2, s)
assert_raises(TypeError, op.truediv, s, p2)
for ptype in classes:
assert_raises(TypeError, op.truediv, p2, ptype(1))
def check_mod(Poly):
# This checks commutation, not numerical correctness
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
c3 = list(random((2,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = Poly(c3)
p4 = p1 * p2 + p3
c4 = list(p4.coef)
assert_poly_almost_equal(p4 % p2, p3)
assert_poly_almost_equal(p4 % c2, p3)
assert_poly_almost_equal(c4 % p2, p3)
assert_poly_almost_equal(p4 % tuple(c2), p3)
assert_poly_almost_equal(tuple(c4) % p2, p3)
assert_poly_almost_equal(p4 % np.array(c2), p3)
assert_poly_almost_equal(np.array(c4) % p2, p3)
assert_poly_almost_equal(2 % p2, Poly([2]))
assert_poly_almost_equal(p2 % 2, Poly([0]))
assert_raises(TypeError, op.mod, p1, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, op.mod, p1, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, op.mod, p1, Chebyshev([0]))
else:
assert_raises(TypeError, op.mod, p1, Polynomial([0]))
def check_divmod(Poly):
# This checks commutation, not numerical correctness
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
c3 = list(random((2,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = Poly(c3)
p4 = p1 * p2 + p3
c4 = list(p4.coef)
quo, rem = divmod(p4, p2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(p4, c2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(c4, p2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(p4, tuple(c2))
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(tuple(c4), p2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(p4, np.array(c2))
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(np.array(c4), p2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(p2, 2)
assert_poly_almost_equal(quo, 0.5*p2)
assert_poly_almost_equal(rem, Poly([0]))
quo, rem = divmod(2, p2)
assert_poly_almost_equal(quo, Poly([0]))
assert_poly_almost_equal(rem, Poly([2]))
assert_raises(TypeError, divmod, p1, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, divmod, p1, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, divmod, p1, Chebyshev([0]))
else:
assert_raises(TypeError, divmod, p1, Polynomial([0]))
def check_roots(Poly):
d = Poly.domain + random((2,))*.25
w = Poly.window + random((2,))*.25
tgt = np.sort(random((5,)))
res = np.sort(Poly.fromroots(tgt, domain=d, window=w).roots())
assert_almost_equal(res, tgt)
# default domain and window
res = np.sort(Poly.fromroots(tgt).roots())
assert_almost_equal(res, tgt)
def check_degree(Poly):
p = Poly.basis(5)
assert_equal(p.degree(), 5)
def check_copy(Poly):
p1 = Poly.basis(5)
p2 = p1.copy()
assert_(p1 == p2)
assert_(p1 is not p2)
assert_(p1.coef is not p2.coef)
assert_(p1.domain is not p2.domain)
assert_(p1.window is not p2.window)
def check_integ(Poly):
P = Polynomial
# Check defaults
p0 = Poly.cast(P([1*2, 2*3, 3*4]))
p1 = P.cast(p0.integ())
p2 = P.cast(p0.integ(2))
assert_poly_almost_equal(p1, P([0, 2, 3, 4]))
assert_poly_almost_equal(p2, P([0, 0, 1, 1, 1]))
# Check with k
p0 = Poly.cast(P([1*2, 2*3, 3*4]))
p1 = P.cast(p0.integ(k=1))
p2 = P.cast(p0.integ(2, k=[1, 1]))
assert_poly_almost_equal(p1, P([1, 2, 3, 4]))
assert_poly_almost_equal(p2, P([1, 1, 1, 1, 1]))
# Check with lbnd
p0 = Poly.cast(P([1*2, 2*3, 3*4]))
p1 = P.cast(p0.integ(lbnd=1))
p2 = P.cast(p0.integ(2, lbnd=1))
assert_poly_almost_equal(p1, P([-9, 2, 3, 4]))
assert_poly_almost_equal(p2, P([6, -9, 1, 1, 1]))
# Check scaling
d = 2*Poly.domain
p0 = Poly.cast(P([1*2, 2*3, 3*4]), domain=d)
p1 = P.cast(p0.integ())
p2 = P.cast(p0.integ(2))
assert_poly_almost_equal(p1, P([0, 2, 3, 4]))
assert_poly_almost_equal(p2, P([0, 0, 1, 1, 1]))
def check_deriv(Poly):
# Check that the derivative is the inverse of integration. It is
# assumes that the integration has been checked elsewhere.
d = Poly.domain + random((2,))*.25
w = Poly.window + random((2,))*.25
p1 = Poly([1, 2, 3], domain=d, window=w)
p2 = p1.integ(2, k=[1, 2])
p3 = p1.integ(1, k=[1])
assert_almost_equal(p2.deriv(1).coef, p3.coef)
assert_almost_equal(p2.deriv(2).coef, p1.coef)
# default domain and window
p1 = Poly([1, 2, 3])
p2 = p1.integ(2, k=[1, 2])
p3 = p1.integ(1, k=[1])
assert_almost_equal(p2.deriv(1).coef, p3.coef)
assert_almost_equal(p2.deriv(2).coef, p1.coef)
def check_linspace(Poly):
d = Poly.domain + random((2,))*.25
w = Poly.window + random((2,))*.25
p = Poly([1, 2, 3], domain=d, window=w)
# check default domain
xtgt = np.linspace(d[0], d[1], 20)
ytgt = p(xtgt)
xres, yres = p.linspace(20)
assert_almost_equal(xres, xtgt)
assert_almost_equal(yres, ytgt)
# check specified domain
xtgt = np.linspace(0, 2, 20)
ytgt = p(xtgt)
xres, yres = p.linspace(20, domain=[0, 2])
assert_almost_equal(xres, xtgt)
assert_almost_equal(yres, ytgt)
def check_pow(Poly):
d = Poly.domain + random((2,))*.25
w = Poly.window + random((2,))*.25
tgt = Poly([1], domain=d, window=w)
tst = Poly([1, 2, 3], domain=d, window=w)
for i in range(5):
assert_poly_almost_equal(tst**i, tgt)
tgt = tgt * tst
# default domain and window
tgt = Poly([1])
tst = Poly([1, 2, 3])
for i in range(5):
assert_poly_almost_equal(tst**i, tgt)
tgt = tgt * tst
# check error for invalid powers
assert_raises(ValueError, op.pow, tgt, 1.5)
assert_raises(ValueError, op.pow, tgt, -1)
def check_call(Poly):
P = Polynomial
d = Poly.domain
x = np.linspace(d[0], d[1], 11)
# Check defaults
p = Poly.cast(P([1, 2, 3]))
tgt = 1 + x*(2 + 3*x)
res = p(x)
assert_almost_equal(res, tgt)
def check_cutdeg(Poly):
p = Poly([1, 2, 3])
assert_raises(ValueError, p.cutdeg, .5)
assert_raises(ValueError, p.cutdeg, -1)
assert_equal(len(p.cutdeg(3)), 3)
assert_equal(len(p.cutdeg(2)), 3)
assert_equal(len(p.cutdeg(1)), 2)
assert_equal(len(p.cutdeg(0)), 1)
def check_truncate(Poly):
p = Poly([1, 2, 3])
assert_raises(ValueError, p.truncate, .5)
assert_raises(ValueError, p.truncate, 0)
assert_equal(len(p.truncate(4)), 3)
assert_equal(len(p.truncate(3)), 3)
assert_equal(len(p.truncate(2)), 2)
assert_equal(len(p.truncate(1)), 1)
def check_trim(Poly):
c = [1, 1e-6, 1e-12, 0]
p = Poly(c)
assert_equal(p.trim().coef, c[:3])
assert_equal(p.trim(1e-10).coef, c[:2])
assert_equal(p.trim(1e-5).coef, c[:1])
def check_mapparms(Poly):
# check with defaults. Should be identity.
d = Poly.domain
w = Poly.window
p = Poly([1], domain=d, window=w)
assert_almost_equal([0, 1], p.mapparms())
#
w = 2*d + 1
p = Poly([1], domain=d, window=w)
assert_almost_equal([1, 2], p.mapparms())
if __name__ == "__main__":
run_module_suite()
|
apache-2.0
|
[
624,
774,
1640,
13,
15083,
402,
3365,
11849,
3992,
14,
199,
199,
2765,
2295,
314,
3957,
436,
9106,
3102,
402,
1006,
314,
11849,
3992,
14,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
4182,
465,
1687,
199,
504,
5579,
492,
4860,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
22104,
492,
334,
272,
8467,
8887,
12,
29420,
12,
445,
9260,
27185,
12,
491,
643,
32302,
12,
26526,
12,
26526,
37,
9,
199,
504,
2680,
14,
4776,
492,
334,
272,
702,
63,
4398,
63,
1452,
12,
702,
63,
3536,
12,
702,
63,
1452,
12,
702,
3131,
272,
1255,
63,
578,
63,
5768,
9,
199,
504,
2680,
14,
5819,
492,
1846,
421,
199,
2888,
275,
334,
272,
8467,
8887,
12,
29420,
12,
445,
9260,
27185,
12,
491,
643,
32302,
12,
272,
26526,
12,
26526,
37,
9,
421,
199,
318,
511,
63,
533,
63,
2474,
837,
272,
367,
16869,
17,
315,
3992,
26,
267,
367,
16869,
18,
315,
3992,
26,
288,
1995,
1104,
63,
15083,
12,
16869,
17,
12,
16869,
18,
288,
1995,
1104,
63,
2931,
12,
16869,
17,
12,
16869,
18,
272,
367,
16869,
315,
3992,
26,
267,
1995,
1104,
63,
1250,
12,
16869,
267,
1995,
1104,
63,
5582,
12,
16869,
267,
1995,
1104,
63,
19220,
12,
16869,
267,
1995,
1104,
63,
504,
12065,
12,
16869,
267,
1995,
1104,
63,
3269,
12,
16869,
267,
1995,
1104,
63,
1452,
12,
16869,
267,
1995,
1104,
63,
1397,
63,
1452,
12,
16869,
267,
1995,
1104,
63,
525,
12,
16869,
267,
1995,
1104,
63,
954,
12,
16869,
267,
1995,
1104,
63,
3703,
12,
16869,
267,
1995,
1104,
63,
30835,
12,
16869,
267,
1995,
1104,
63,
22062,
12,
16869,
267,
1995,
1104,
63,
1494,
12,
16869,
267,
1995,
1104,
63,
26997,
12,
16869,
267,
1995,
1104,
63,
8278,
12,
16869,
267,
1995,
1104,
63,
5707,
71,
12,
16869,
267,
1995,
1104,
63,
17922,
12,
16869,
267,
1995,
1104,
63,
12065,
12,
16869,
267,
1995,
1104,
63,
11649,
12,
16869,
267,
1995,
1104,
63,
1130,
28899,
12,
16869,
267,
1995,
1104,
63,
10956,
12,
16869,
267,
1995,
1104,
63,
1574,
12,
16869,
267,
1995,
1104,
63,
5919,
6458,
12,
16869,
267,
1995,
1104,
63,
12517,
12,
16869,
267,
1995,
1104,
63,
12263,
12,
16869,
421,
199,
3,
199,
3,
5922,
3423,
199,
3,
199,
2355,
275,
980,
14,
2355,
14,
2355,
421,
199,
318,
702,
63,
6023,
63,
4398,
63,
1452,
8,
80,
17,
12,
299,
18,
12,
1499,
17364,
272,
862,
26,
267,
702,
2531,
1590,
14,
452,
8,
80,
17,
14,
2261,
508,
299,
18,
14,
2261,
430,
267,
702,
2531,
1590,
14,
452,
8,
80,
17,
14,
3806,
508,
299,
18,
14,
3806,
430,
267,
702,
63,
4398,
63,
1452,
8,
80,
17,
14,
8009,
12,
299,
18,
14,
8009,
9,
272,
871,
9070,
26,
267,
1499,
275,
298,
2889,
26,
450,
83,
60,
78,
4277,
26,
450,
83,
401,
334,
80,
17,
12,
299,
18,
9,
267,
746,
9070,
8,
1328,
9,
421,
199,
3,
199,
3,
8603,
3102,
626,
11687,
641,
2877,
3992,
199,
3,
421,
199,
318,
1104,
63,
15083,
8,
12747,
17,
12,
16869,
18,
304,
272,
671,
275,
980,
14,
11649,
8,
16,
12,
413,
12,
1616,
9,
272,
7355,
275,
2196,
1332,
19,
4641,
339,
366,
17,
275,
16869,
17,
14,
2261,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
336,
17,
275,
16869,
17,
14,
3806,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
299,
17,
275,
16869,
17,
8,
8009,
12,
2881,
29,
68,
17,
12,
4353,
29,
87,
17,
9,
339,
366,
18,
275,
16869,
18,
14,
2261,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
336,
18,
275,
16869,
18,
14,
3806,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
299,
18,
275,
299,
17,
14,
3916,
8,
5091,
29,
12747,
18,
12,
2881,
29,
68,
18,
12,
4353,
29,
87,
18,
9,
339,
702,
63,
4398,
63,
1452,
8,
80,
18,
14,
2261,
12,
366,
18,
9,
272,
702,
63,
4398,
63,
1452,
8,
80,
18,
14,
3806,
12,
336,
18,
9,
272,
702,
63,
4398,
63,
1452,
8,
80,
18,
8,
88,
395,
299,
17,
8,
88,
430,
421,
199,
318,
1104,
63,
2931,
8,
12747,
17,
12,
16869,
18,
304,
272,
671,
275,
980,
14,
11649,
8,
16,
12,
413,
12,
1616,
9,
272,
7355,
275,
2196,
1332,
19,
4641,
339,
366,
17,
275,
16869,
17,
14,
2261,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
336,
17,
275,
16869,
17,
14,
3806,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
299,
17,
275,
16869,
17,
8,
8009,
12,
2881,
29,
68,
17,
12,
4353,
29,
87,
17,
9,
339,
366,
18,
275,
16869,
18,
14,
2261,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
336,
18,
275,
16869,
18,
14,
3806,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
299,
18,
275,
16869,
18,
14,
2931,
8,
80,
17,
12,
2881,
29,
68,
18,
12,
4353,
29,
87,
18,
9,
339,
702,
63,
4398,
63,
1452,
8,
80,
18,
14,
2261,
12,
366,
18,
9,
272,
702,
63,
4398,
63,
1452,
8,
80,
18,
14,
3806,
12,
336,
18,
9,
272,
702,
63,
4398,
63,
1452,
8,
80,
18,
8,
88,
395,
299,
17,
8,
88,
430,
421,
199,
3,
199,
3,
3102,
626,
11687,
641,
1373,
1021,
199,
3,
421,
199,
318,
1104,
63,
5582,
8,
12747,
304,
272,
366,
275,
16869,
14,
2261,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
336,
275,
16869,
14,
3806,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
671,
275,
980,
14,
11649,
8,
68,
59,
16,
467,
366,
59,
17,
467,
4119,
9,
272,
299,
275,
16869,
14,
5582,
8,
2261,
29,
68,
12,
4353,
29,
87,
9,
272,
702,
63,
1452,
8,
80,
14,
2261,
12,
366,
9,
272,
702,
63,
1452,
8,
80,
14,
3806,
12,
336,
9,
272,
702,
63,
4398,
63,
1452,
8,
80,
8,
88,
395,
671,
9,
421,
199,
318,
1104,
63,
19220,
8,
12747,
304,
272,
366,
275,
16869,
14,
2261,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
336,
275,
16869,
14,
3806
] |
[
774,
1640,
13,
15083,
402,
3365,
11849,
3992,
14,
199,
199,
2765,
2295,
314,
3957,
436,
9106,
3102,
402,
1006,
314,
11849,
3992,
14,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
4182,
465,
1687,
199,
504,
5579,
492,
4860,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
22104,
492,
334,
272,
8467,
8887,
12,
29420,
12,
445,
9260,
27185,
12,
491,
643,
32302,
12,
26526,
12,
26526,
37,
9,
199,
504,
2680,
14,
4776,
492,
334,
272,
702,
63,
4398,
63,
1452,
12,
702,
63,
3536,
12,
702,
63,
1452,
12,
702,
3131,
272,
1255,
63,
578,
63,
5768,
9,
199,
504,
2680,
14,
5819,
492,
1846,
421,
199,
2888,
275,
334,
272,
8467,
8887,
12,
29420,
12,
445,
9260,
27185,
12,
491,
643,
32302,
12,
272,
26526,
12,
26526,
37,
9,
421,
199,
318,
511,
63,
533,
63,
2474,
837,
272,
367,
16869,
17,
315,
3992,
26,
267,
367,
16869,
18,
315,
3992,
26,
288,
1995,
1104,
63,
15083,
12,
16869,
17,
12,
16869,
18,
288,
1995,
1104,
63,
2931,
12,
16869,
17,
12,
16869,
18,
272,
367,
16869,
315,
3992,
26,
267,
1995,
1104,
63,
1250,
12,
16869,
267,
1995,
1104,
63,
5582,
12,
16869,
267,
1995,
1104,
63,
19220,
12,
16869,
267,
1995,
1104,
63,
504,
12065,
12,
16869,
267,
1995,
1104,
63,
3269,
12,
16869,
267,
1995,
1104,
63,
1452,
12,
16869,
267,
1995,
1104,
63,
1397,
63,
1452,
12,
16869,
267,
1995,
1104,
63,
525,
12,
16869,
267,
1995,
1104,
63,
954,
12,
16869,
267,
1995,
1104,
63,
3703,
12,
16869,
267,
1995,
1104,
63,
30835,
12,
16869,
267,
1995,
1104,
63,
22062,
12,
16869,
267,
1995,
1104,
63,
1494,
12,
16869,
267,
1995,
1104,
63,
26997,
12,
16869,
267,
1995,
1104,
63,
8278,
12,
16869,
267,
1995,
1104,
63,
5707,
71,
12,
16869,
267,
1995,
1104,
63,
17922,
12,
16869,
267,
1995,
1104,
63,
12065,
12,
16869,
267,
1995,
1104,
63,
11649,
12,
16869,
267,
1995,
1104,
63,
1130,
28899,
12,
16869,
267,
1995,
1104,
63,
10956,
12,
16869,
267,
1995,
1104,
63,
1574,
12,
16869,
267,
1995,
1104,
63,
5919,
6458,
12,
16869,
267,
1995,
1104,
63,
12517,
12,
16869,
267,
1995,
1104,
63,
12263,
12,
16869,
421,
199,
3,
199,
3,
5922,
3423,
199,
3,
199,
2355,
275,
980,
14,
2355,
14,
2355,
421,
199,
318,
702,
63,
6023,
63,
4398,
63,
1452,
8,
80,
17,
12,
299,
18,
12,
1499,
17364,
272,
862,
26,
267,
702,
2531,
1590,
14,
452,
8,
80,
17,
14,
2261,
508,
299,
18,
14,
2261,
430,
267,
702,
2531,
1590,
14,
452,
8,
80,
17,
14,
3806,
508,
299,
18,
14,
3806,
430,
267,
702,
63,
4398,
63,
1452,
8,
80,
17,
14,
8009,
12,
299,
18,
14,
8009,
9,
272,
871,
9070,
26,
267,
1499,
275,
298,
2889,
26,
450,
83,
60,
78,
4277,
26,
450,
83,
401,
334,
80,
17,
12,
299,
18,
9,
267,
746,
9070,
8,
1328,
9,
421,
199,
3,
199,
3,
8603,
3102,
626,
11687,
641,
2877,
3992,
199,
3,
421,
199,
318,
1104,
63,
15083,
8,
12747,
17,
12,
16869,
18,
304,
272,
671,
275,
980,
14,
11649,
8,
16,
12,
413,
12,
1616,
9,
272,
7355,
275,
2196,
1332,
19,
4641,
339,
366,
17,
275,
16869,
17,
14,
2261,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
336,
17,
275,
16869,
17,
14,
3806,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
299,
17,
275,
16869,
17,
8,
8009,
12,
2881,
29,
68,
17,
12,
4353,
29,
87,
17,
9,
339,
366,
18,
275,
16869,
18,
14,
2261,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
336,
18,
275,
16869,
18,
14,
3806,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
299,
18,
275,
299,
17,
14,
3916,
8,
5091,
29,
12747,
18,
12,
2881,
29,
68,
18,
12,
4353,
29,
87,
18,
9,
339,
702,
63,
4398,
63,
1452,
8,
80,
18,
14,
2261,
12,
366,
18,
9,
272,
702,
63,
4398,
63,
1452,
8,
80,
18,
14,
3806,
12,
336,
18,
9,
272,
702,
63,
4398,
63,
1452,
8,
80,
18,
8,
88,
395,
299,
17,
8,
88,
430,
421,
199,
318,
1104,
63,
2931,
8,
12747,
17,
12,
16869,
18,
304,
272,
671,
275,
980,
14,
11649,
8,
16,
12,
413,
12,
1616,
9,
272,
7355,
275,
2196,
1332,
19,
4641,
339,
366,
17,
275,
16869,
17,
14,
2261,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
336,
17,
275,
16869,
17,
14,
3806,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
299,
17,
275,
16869,
17,
8,
8009,
12,
2881,
29,
68,
17,
12,
4353,
29,
87,
17,
9,
339,
366,
18,
275,
16869,
18,
14,
2261,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
336,
18,
275,
16869,
18,
14,
3806,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
299,
18,
275,
16869,
18,
14,
2931,
8,
80,
17,
12,
2881,
29,
68,
18,
12,
4353,
29,
87,
18,
9,
339,
702,
63,
4398,
63,
1452,
8,
80,
18,
14,
2261,
12,
366,
18,
9,
272,
702,
63,
4398,
63,
1452,
8,
80,
18,
14,
3806,
12,
336,
18,
9,
272,
702,
63,
4398,
63,
1452,
8,
80,
18,
8,
88,
395,
299,
17,
8,
88,
430,
421,
199,
3,
199,
3,
3102,
626,
11687,
641,
1373,
1021,
199,
3,
421,
199,
318,
1104,
63,
5582,
8,
12747,
304,
272,
366,
275,
16869,
14,
2261,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
336,
275,
16869,
14,
3806,
435,
2196,
1332,
18,
4641,
4856,
821,
272,
671,
275,
980,
14,
11649,
8,
68,
59,
16,
467,
366,
59,
17,
467,
4119,
9,
272,
299,
275,
16869,
14,
5582,
8,
2261,
29,
68,
12,
4353,
29,
87,
9,
272,
702,
63,
1452,
8,
80,
14,
2261,
12,
366,
9,
272,
702,
63,
1452,
8,
80,
14,
3806,
12,
336,
9,
272,
702,
63,
4398,
63,
1452,
8,
80,
8,
88,
395,
671,
9,
421,
199,
318,
1104,
63,
19220,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Dhivyap/ansible
|
lib/ansible/modules/network/avi/avi_networksecuritypolicy.py
|
28
|
4329
|
#!/usr/bin/python
#
# @author: Gaurav Rastogi (grastogi@avinetworks.com)
# Eric Anderson (eanderson@avinetworks.com)
# module_check: supported
# Avi Version: 17.1.1
#
# Copyright: (c) 2017 Gaurav Rastogi, <grastogi@avinetworks.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: avi_networksecuritypolicy
author: Gaurav Rastogi (@grastogi23) <grastogi@avinetworks.com>
short_description: Module for setup of NetworkSecurityPolicy Avi RESTful Object
description:
- This module is used to configure NetworkSecurityPolicy object
- more examples at U(https://github.com/avinetworks/devops)
requirements: [ avisdk ]
version_added: "2.4"
options:
state:
description:
- The state that should be applied on the entity.
default: present
choices: ["absent", "present"]
avi_api_update_method:
description:
- Default method for object update is HTTP PUT.
- Setting to patch will override that behavior to use HTTP PATCH.
version_added: "2.5"
default: put
choices: ["put", "patch"]
avi_api_patch_op:
description:
- Patch operation to use when using avi_api_update_method as patch.
version_added: "2.5"
choices: ["add", "replace", "delete"]
cloud_config_cksum:
description:
- Checksum of cloud configuration for network sec policy.
- Internally set by cloud connector.
created_by:
description:
- Creator name.
description:
description:
- User defined description for the object.
name:
description:
- Name of the object.
rules:
description:
- List of networksecurityrule.
tenant_ref:
description:
- It is a reference to an object of type tenant.
url:
description:
- Avi controller URL of the object.
uuid:
description:
- Unique object identifier of the object.
extends_documentation_fragment:
- avi
'''
EXAMPLES = """
- name: Create a network security policy to block clients represented by ip group known_attackers
avi_networksecuritypolicy:
controller: '{{ controller }}'
username: '{{ username }}'
password: '{{ password }}'
name: vs-gurutest-ns
rules:
- action: NETWORK_SECURITY_POLICY_ACTION_TYPE_DENY
age: 0
enable: true
index: 1
log: false
match:
client_ip:
group_refs:
- Demo:known_attackers
match_criteria: IS_IN
name: Rule 1
tenant_ref: Demo
"""
RETURN = '''
obj:
description: NetworkSecurityPolicy (api/networksecuritypolicy) object
returned: success, changed
type: dict
'''
from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.network.avi.avi import (
avi_common_argument_spec, avi_ansible_api, HAS_AVI)
except ImportError:
HAS_AVI = False
def main():
argument_specs = dict(
state=dict(default='present',
choices=['absent', 'present']),
avi_api_update_method=dict(default='put',
choices=['put', 'patch']),
avi_api_patch_op=dict(choices=['add', 'replace', 'delete']),
cloud_config_cksum=dict(type='str',),
created_by=dict(type='str',),
description=dict(type='str',),
name=dict(type='str',),
rules=dict(type='list',),
tenant_ref=dict(type='str',),
url=dict(type='str',),
uuid=dict(type='str',),
)
argument_specs.update(avi_common_argument_spec())
module = AnsibleModule(
argument_spec=argument_specs, supports_check_mode=True)
if not HAS_AVI:
return module.fail_json(msg=(
'Avi python API SDK (avisdk>=17.1) or requests is not installed. '
'For more details visit https://github.com/avinetworks/sdk.'))
return avi_ansible_api(module, 'networksecuritypolicy',
set([]))
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
768,
2502,
26,
9647,
300,
1214,
820,
1810,
31114,
334,
926,
270,
31114,
32,
31808,
14,
957,
9,
199,
3,
3515,
662,
1567,
1626,
424,
834,
334,
69,
11438,
834,
32,
31808,
14,
957,
9,
199,
3,
859,
63,
1074,
26,
3748,
199,
3,
21710,
3394,
26,
5557,
14,
17,
14,
17,
199,
3,
199,
3,
1898,
26,
334,
67,
9,
9708,
9647,
300,
1214,
820,
1810,
31114,
12,
665,
926,
270,
31114,
32,
31808,
14,
957,
30,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
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,
21661,
63,
1200,
4416,
3185,
199,
2502,
26,
9647,
300,
1214,
820,
1810,
31114,
8593,
926,
270,
31114,
1789,
9,
665,
926,
270,
31114,
32,
31808,
14,
957,
30,
199,
199,
3612,
63,
1802,
26,
5673,
367,
3272,
402,
7220,
7676,
4845,
21710,
14880,
1893,
6935,
199,
1802,
26,
272,
446,
961,
859,
365,
1202,
370,
7908,
7220,
7676,
4845,
909,
272,
446,
1655,
7251,
737,
738,
8,
2859,
921,
5031,
14,
957,
15,
31808,
15,
2374,
1483,
9,
199,
7538,
26,
359,
2289,
374,
6341,
1622,
199,
1023,
63,
3270,
26,
298,
18,
14,
20,
2,
199,
1419,
26,
272,
1174,
26,
267,
1369,
26,
288,
446,
710,
1174,
626,
1077,
506,
6781,
641,
314,
4642,
14,
267,
849,
26,
3451,
267,
3415,
26,
2097,
5575,
401,
298,
1881,
937,
272,
21661,
63,
1246,
63,
873,
63,
765,
26,
267,
1369,
26,
288,
446,
3758,
1083,
367,
909,
1678,
365,
3101,
18337,
14,
288,
446,
13510,
370,
3371,
911,
4278,
626,
5953,
370,
675,
3101,
510,
8078,
14,
267,
1015,
63,
3270,
26,
298,
18,
14,
21,
2,
267,
849,
26,
5324,
267,
3415,
26,
2097,
524,
401,
298,
2068,
937,
272,
21661,
63,
1246,
63,
2068,
63,
411,
26,
267,
1369,
26,
288,
446,
19292,
3439,
370,
675,
1380,
1808,
21661,
63,
1246,
63,
873,
63,
765,
465,
3371,
14,
267,
1015,
63,
3270,
26,
298,
18,
14,
21,
2,
267,
3415,
26,
2097,
525,
401,
298,
1814,
401,
298,
1807,
937,
272,
8002,
63,
888,
63,
346,
1838,
26,
267,
1369,
26,
288,
446,
2670,
1838,
402,
8002,
2897,
367,
2784,
6513,
4592,
14,
288,
446,
1010,
1203,
1183,
663,
701,
8002,
13252,
14,
272,
2737,
63,
991,
26,
267,
1369,
26,
288,
446,
9750,
707,
536,
14,
272,
1369,
26,
267,
1369,
26,
288,
446,
2876,
3247,
1369,
367,
314,
909,
14,
272,
536,
26,
267,
1369,
26,
288,
446,
2812,
402,
314,
909,
14,
272,
4713,
26,
267,
1369,
26,
288,
446,
3820,
402,
2784,
4416,
2200,
14,
272,
8261,
63,
1121,
26,
267,
1369,
26,
288,
446,
2779,
365,
282,
3659,
370,
376,
909,
402,
730,
8261,
14,
272,
1166,
26,
267,
1369,
26,
288,
446,
21710,
7614,
2851,
402,
314,
909,
14,
272,
5377,
26,
267,
1369,
26,
288,
446,
18276,
909,
5148,
402,
314,
909,
14,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
21661,
199,
2344,
199,
199,
8918,
275,
408,
523,
446,
536,
26,
2790,
282,
2784,
6391,
4592,
370,
1853,
13431,
11159,
701,
3384,
1572,
6040,
63,
24171,
1192,
272,
21661,
63,
1200,
4416,
3185,
26,
489,
7614,
26,
11400,
7614,
16339,
489,
3434,
26,
11400,
3434,
16339,
489,
2505,
26,
11400,
2505,
16339,
489,
536,
26,
8118,
13,
71,
300,
85,
396,
13,
561,
489,
4713,
26,
489,
446,
1595,
26,
18340,
8406,
63,
13554,
63,
15976,
63,
10052,
63,
2711,
63,
23282,
57,
267,
11437,
26,
378,
267,
4756,
26,
2549,
267,
1478,
26,
413,
267,
943,
26,
3055,
267,
1336,
26,
881,
1890,
63,
711,
26,
288,
1572,
63,
7655,
26,
288,
446,
28939,
26,
3159,
63,
24171,
1192,
288,
1336,
63,
20525,
26,
2281,
63,
568,
267,
536,
26,
11949,
413,
489,
8261,
63,
1121,
26,
28939,
199,
624,
199,
199,
9677,
275,
1449,
199,
1113,
26,
272,
1369,
26,
7220,
7676,
4845,
334,
1246,
15,
1200,
4416,
3185,
9,
909,
272,
2138,
26,
3182,
12,
2896,
272,
730,
26,
1211,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
893,
26,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
7194,
14,
7194,
492,
334,
267,
21661,
63,
2330,
63,
2094,
63,
1650,
12,
21661,
63,
4853,
63,
1246,
12,
7509,
63,
32636,
9,
199,
2590,
3545,
26,
272,
7509,
63,
32636,
275,
756,
421,
199,
318,
2446,
837,
272,
1423,
63,
7273,
275,
1211,
8,
267,
1174,
29,
807,
8,
885,
534,
1881,
297,
673,
3415,
2968,
5575,
297,
283,
1881,
3815,
267,
21661,
63,
1246,
63,
873,
63,
765,
29,
807,
8,
885,
534,
524,
297,
3521,
3415,
2968,
524,
297,
283,
2068,
3815,
267,
21661,
63,
1246,
63,
2068,
63,
411,
29,
807,
8,
4577,
2968,
525,
297,
283,
1814,
297,
283,
1807,
3815,
267,
8002,
63,
888,
63,
346,
1838,
29,
807,
8,
466,
534,
495,
5529,
267,
2737,
63,
991,
29,
807,
8,
466,
534,
495,
5529,
267,
1369,
29,
807,
8,
466,
534,
495,
5529,
267,
536,
29,
807,
8,
466,
534,
495,
5529,
267,
4713,
29,
807,
8,
466,
534,
513,
5529,
267,
8261,
63,
1121,
29,
807,
8,
466,
534,
495,
5529,
267,
1166,
29,
807,
8,
466,
534,
495,
5529,
267,
5377,
29,
807,
8,
466,
534,
495,
5529,
272,
776,
272,
1423,
63,
7273,
14,
873,
8,
7194,
63,
2330,
63,
2094,
63,
1650,
1012,
272,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
2094,
63,
7273,
12,
5171,
63,
1074,
63,
632,
29,
549,
9,
272,
340,
440,
7509,
63,
32636,
26,
267,
372,
859,
14,
1633,
63,
1001,
8,
1328,
2687,
288,
283,
33,
433,
2366,
3261,
15610,
334,
1214,
374,
6341,
8119,
1196,
14,
17,
9,
503,
4145,
365,
440,
4903
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
768,
2502,
26,
9647,
300,
1214,
820,
1810,
31114,
334,
926,
270,
31114,
32,
31808,
14,
957,
9,
199,
3,
3515,
662,
1567,
1626,
424,
834,
334,
69,
11438,
834,
32,
31808,
14,
957,
9,
199,
3,
859,
63,
1074,
26,
3748,
199,
3,
21710,
3394,
26,
5557,
14,
17,
14,
17,
199,
3,
199,
3,
1898,
26,
334,
67,
9,
9708,
9647,
300,
1214,
820,
1810,
31114,
12,
665,
926,
270,
31114,
32,
31808,
14,
957,
30,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
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,
21661,
63,
1200,
4416,
3185,
199,
2502,
26,
9647,
300,
1214,
820,
1810,
31114,
8593,
926,
270,
31114,
1789,
9,
665,
926,
270,
31114,
32,
31808,
14,
957,
30,
199,
199,
3612,
63,
1802,
26,
5673,
367,
3272,
402,
7220,
7676,
4845,
21710,
14880,
1893,
6935,
199,
1802,
26,
272,
446,
961,
859,
365,
1202,
370,
7908,
7220,
7676,
4845,
909,
272,
446,
1655,
7251,
737,
738,
8,
2859,
921,
5031,
14,
957,
15,
31808,
15,
2374,
1483,
9,
199,
7538,
26,
359,
2289,
374,
6341,
1622,
199,
1023,
63,
3270,
26,
298,
18,
14,
20,
2,
199,
1419,
26,
272,
1174,
26,
267,
1369,
26,
288,
446,
710,
1174,
626,
1077,
506,
6781,
641,
314,
4642,
14,
267,
849,
26,
3451,
267,
3415,
26,
2097,
5575,
401,
298,
1881,
937,
272,
21661,
63,
1246,
63,
873,
63,
765,
26,
267,
1369,
26,
288,
446,
3758,
1083,
367,
909,
1678,
365,
3101,
18337,
14,
288,
446,
13510,
370,
3371,
911,
4278,
626,
5953,
370,
675,
3101,
510,
8078,
14,
267,
1015,
63,
3270,
26,
298,
18,
14,
21,
2,
267,
849,
26,
5324,
267,
3415,
26,
2097,
524,
401,
298,
2068,
937,
272,
21661,
63,
1246,
63,
2068,
63,
411,
26,
267,
1369,
26,
288,
446,
19292,
3439,
370,
675,
1380,
1808,
21661,
63,
1246,
63,
873,
63,
765,
465,
3371,
14,
267,
1015,
63,
3270,
26,
298,
18,
14,
21,
2,
267,
3415,
26,
2097,
525,
401,
298,
1814,
401,
298,
1807,
937,
272,
8002,
63,
888,
63,
346,
1838,
26,
267,
1369,
26,
288,
446,
2670,
1838,
402,
8002,
2897,
367,
2784,
6513,
4592,
14,
288,
446,
1010,
1203,
1183,
663,
701,
8002,
13252,
14,
272,
2737,
63,
991,
26,
267,
1369,
26,
288,
446,
9750,
707,
536,
14,
272,
1369,
26,
267,
1369,
26,
288,
446,
2876,
3247,
1369,
367,
314,
909,
14,
272,
536,
26,
267,
1369,
26,
288,
446,
2812,
402,
314,
909,
14,
272,
4713,
26,
267,
1369,
26,
288,
446,
3820,
402,
2784,
4416,
2200,
14,
272,
8261,
63,
1121,
26,
267,
1369,
26,
288,
446,
2779,
365,
282,
3659,
370,
376,
909,
402,
730,
8261,
14,
272,
1166,
26,
267,
1369,
26,
288,
446,
21710,
7614,
2851,
402,
314,
909,
14,
272,
5377,
26,
267,
1369,
26,
288,
446,
18276,
909,
5148,
402,
314,
909,
14,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
21661,
199,
2344,
199,
199,
8918,
275,
408,
523,
446,
536,
26,
2790,
282,
2784,
6391,
4592,
370,
1853,
13431,
11159,
701,
3384,
1572,
6040,
63,
24171,
1192,
272,
21661,
63,
1200,
4416,
3185,
26,
489,
7614,
26,
11400,
7614,
16339,
489,
3434,
26,
11400,
3434,
16339,
489,
2505,
26,
11400,
2505,
16339,
489,
536,
26,
8118,
13,
71,
300,
85,
396,
13,
561,
489,
4713,
26,
489,
446,
1595,
26,
18340,
8406,
63,
13554,
63,
15976,
63,
10052,
63,
2711,
63,
23282,
57,
267,
11437,
26,
378,
267,
4756,
26,
2549,
267,
1478,
26,
413,
267,
943,
26,
3055,
267,
1336,
26,
881,
1890,
63,
711,
26,
288,
1572,
63,
7655,
26,
288,
446,
28939,
26,
3159,
63,
24171,
1192,
288,
1336,
63,
20525,
26,
2281,
63,
568,
267,
536,
26,
11949,
413,
489,
8261,
63,
1121,
26,
28939,
199,
624,
199,
199,
9677,
275,
1449,
199,
1113,
26,
272,
1369,
26,
7220,
7676,
4845,
334,
1246,
15,
1200,
4416,
3185,
9,
909,
272,
2138,
26,
3182,
12,
2896,
272,
730,
26,
1211,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
893,
26,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
7194,
14,
7194,
492,
334,
267,
21661,
63,
2330,
63,
2094,
63,
1650,
12,
21661,
63,
4853,
63,
1246,
12,
7509,
63,
32636,
9,
199,
2590,
3545,
26,
272,
7509,
63,
32636,
275,
756,
421,
199,
318,
2446,
837,
272,
1423,
63,
7273,
275,
1211,
8,
267,
1174,
29,
807,
8,
885,
534,
1881,
297,
673,
3415,
2968,
5575,
297,
283,
1881,
3815,
267,
21661,
63,
1246,
63,
873,
63,
765,
29,
807,
8,
885,
534,
524,
297,
3521,
3415,
2968,
524,
297,
283,
2068,
3815,
267,
21661,
63,
1246,
63,
2068,
63,
411,
29,
807,
8,
4577,
2968,
525,
297,
283,
1814,
297,
283,
1807,
3815,
267,
8002,
63,
888,
63,
346,
1838,
29,
807,
8,
466,
534,
495,
5529,
267,
2737,
63,
991,
29,
807,
8,
466,
534,
495,
5529,
267,
1369,
29,
807,
8,
466,
534,
495,
5529,
267,
536,
29,
807,
8,
466,
534,
495,
5529,
267,
4713,
29,
807,
8,
466,
534,
513,
5529,
267,
8261,
63,
1121,
29,
807,
8,
466,
534,
495,
5529,
267,
1166,
29,
807,
8,
466,
534,
495,
5529,
267,
5377,
29,
807,
8,
466,
534,
495,
5529,
272,
776,
272,
1423,
63,
7273,
14,
873,
8,
7194,
63,
2330,
63,
2094,
63,
1650,
1012,
272,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
2094,
63,
7273,
12,
5171,
63,
1074,
63,
632,
29,
549,
9,
272,
340,
440,
7509,
63,
32636,
26,
267,
372,
859,
14,
1633,
63,
1001,
8,
1328,
2687,
288,
283,
33,
433,
2366,
3261,
15610,
334,
1214,
374,
6341,
8119,
1196,
14,
17,
9,
503,
4145,
365,
440,
4903,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
aam-at/tensorflow
|
tensorflow/python/keras/layers/noise.py
|
9
|
7052
|
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Layers that operate regularization via the addition of noise."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
from tensorflow.python.keras import backend as K
from tensorflow.python.keras.engine.base_layer import Layer
from tensorflow.python.keras.utils import tf_utils
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.util.tf_export import keras_export
@keras_export('keras.layers.GaussianNoise')
class GaussianNoise(Layer):
"""Apply additive zero-centered Gaussian noise.
This is useful to mitigate overfitting
(you could see it as a form of random data augmentation).
Gaussian Noise (GS) is a natural choice as corruption process
for real valued inputs.
As it is a regularization layer, it is only active at training time.
Arguments:
stddev: Float, standard deviation of the noise distribution.
Call arguments:
inputs: Input tensor (of any rank).
training: Python boolean indicating whether the layer should behave in
training mode (adding noise) or in inference mode (doing nothing).
Input shape:
Arbitrary. Use the keyword argument `input_shape`
(tuple of integers, does not include the samples axis)
when using this layer as the first layer in a model.
Output shape:
Same shape as input.
"""
def __init__(self, stddev, **kwargs):
super(GaussianNoise, self).__init__(**kwargs)
self.supports_masking = True
self.stddev = stddev
def call(self, inputs, training=None):
def noised():
return inputs + K.random_normal(
shape=array_ops.shape(inputs),
mean=0.,
stddev=self.stddev,
dtype=inputs.dtype)
return K.in_train_phase(noised, inputs, training=training)
def get_config(self):
config = {'stddev': self.stddev}
base_config = super(GaussianNoise, self).get_config()
return dict(list(base_config.items()) + list(config.items()))
@tf_utils.shape_type_conversion
def compute_output_shape(self, input_shape):
return input_shape
@keras_export('keras.layers.GaussianDropout')
class GaussianDropout(Layer):
"""Apply multiplicative 1-centered Gaussian noise.
As it is a regularization layer, it is only active at training time.
Arguments:
rate: Float, drop probability (as with `Dropout`).
The multiplicative noise will have
standard deviation `sqrt(rate / (1 - rate))`.
Call arguments:
inputs: Input tensor (of any rank).
training: Python boolean indicating whether the layer should behave in
training mode (adding dropout) or in inference mode (doing nothing).
Input shape:
Arbitrary. Use the keyword argument `input_shape`
(tuple of integers, does not include the samples axis)
when using this layer as the first layer in a model.
Output shape:
Same shape as input.
"""
def __init__(self, rate, **kwargs):
super(GaussianDropout, self).__init__(**kwargs)
self.supports_masking = True
self.rate = rate
def call(self, inputs, training=None):
if 0 < self.rate < 1:
def noised():
stddev = np.sqrt(self.rate / (1.0 - self.rate))
return inputs * K.random_normal(
shape=array_ops.shape(inputs),
mean=1.0,
stddev=stddev,
dtype=inputs.dtype)
return K.in_train_phase(noised, inputs, training=training)
return inputs
def get_config(self):
config = {'rate': self.rate}
base_config = super(GaussianDropout, self).get_config()
return dict(list(base_config.items()) + list(config.items()))
@tf_utils.shape_type_conversion
def compute_output_shape(self, input_shape):
return input_shape
@keras_export('keras.layers.AlphaDropout')
class AlphaDropout(Layer):
"""Applies Alpha Dropout to the input.
Alpha Dropout is a `Dropout` that keeps mean and variance of inputs
to their original values, in order to ensure the self-normalizing property
even after this dropout.
Alpha Dropout fits well to Scaled Exponential Linear Units
by randomly setting activations to the negative saturation value.
Arguments:
rate: float, drop probability (as with `Dropout`).
The multiplicative noise will have
standard deviation `sqrt(rate / (1 - rate))`.
seed: A Python integer to use as random seed.
Call arguments:
inputs: Input tensor (of any rank).
training: Python boolean indicating whether the layer should behave in
training mode (adding dropout) or in inference mode (doing nothing).
Input shape:
Arbitrary. Use the keyword argument `input_shape`
(tuple of integers, does not include the samples axis)
when using this layer as the first layer in a model.
Output shape:
Same shape as input.
"""
def __init__(self, rate, noise_shape=None, seed=None, **kwargs):
super(AlphaDropout, self).__init__(**kwargs)
self.rate = rate
self.noise_shape = noise_shape
self.seed = seed
self.supports_masking = True
def _get_noise_shape(self, inputs):
return self.noise_shape if self.noise_shape else array_ops.shape(inputs)
def call(self, inputs, training=None):
if 0. < self.rate < 1.:
noise_shape = self._get_noise_shape(inputs)
def dropped_inputs(inputs=inputs, rate=self.rate, seed=self.seed): # pylint: disable=missing-docstring
alpha = 1.6732632423543772848170429916717
scale = 1.0507009873554804934193349852946
alpha_p = -alpha * scale
kept_idx = math_ops.greater_equal(
K.random_uniform(noise_shape, seed=seed), rate)
kept_idx = math_ops.cast(kept_idx, inputs.dtype)
# Get affine transformation params
a = ((1 - rate) * (1 + rate * alpha_p**2))**-0.5
b = -a * alpha_p * rate
# Apply mask
x = inputs * kept_idx + alpha_p * (1 - kept_idx)
# Do affine transformation
return a * x + b
return K.in_train_phase(dropped_inputs, inputs, training=training)
return inputs
def get_config(self):
config = {'rate': self.rate}
base_config = super(AlphaDropout, self).get_config()
return dict(list(base_config.items()) + list(config.items()))
@tf_utils.shape_type_conversion
def compute_output_shape(self, input_shape):
return input_shape
|
apache-2.0
|
[
3,
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
16862,
626,
19218,
21095,
4799,
314,
10234,
402,
11145,
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,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
14,
8811,
492,
4865,
465,
1804,
199,
504,
3228,
14,
1548,
14,
8811,
14,
3908,
14,
1095,
63,
1897,
492,
11915,
199,
504,
3228,
14,
1548,
14,
8811,
14,
1208,
492,
2833,
63,
1208,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1974,
14,
3249,
63,
3790,
492,
11708,
63,
3790,
421,
199,
32,
8811,
63,
3790,
360,
8811,
14,
4359,
14,
26756,
21446,
358,
199,
533,
17131,
21446,
8,
5003,
304,
523,
408,
16581,
1503,
30844,
4697,
13,
20080,
17131,
11145,
14,
819,
961,
365,
2997,
370,
333,
5277,
3237,
1806,
3269,
1337,
523,
334,
13297,
4293,
1937,
652,
465,
282,
1824,
402,
2196,
666,
18336,
3117,
680,
523,
17131,
3091,
572,
334,
8021,
9,
365,
282,
19981,
7141,
465,
1970,
5505,
296,
2112,
523,
367,
3363,
574,
68,
4153,
14,
819,
3709,
652,
365,
282,
21095,
4045,
12,
652,
365,
1454,
4702,
737,
6093,
900,
14,
819,
7628,
26,
272,
28052,
26,
11140,
12,
4465,
18458,
402,
314,
11145,
4084,
14,
819,
6523,
2368,
26,
272,
4153,
26,
6924,
2345,
334,
1618,
1263,
6915,
680,
272,
6093,
26,
2018,
5046,
9297,
3775,
314,
4045,
1077,
24062,
315,
489,
6093,
818,
334,
4095,
11145,
9,
503,
315,
17353,
818,
334,
1117,
316,
6548,
680,
819,
6924,
2215,
26,
272,
1952,
8734,
14,
3645,
314,
4252,
1423,
658,
1210,
63,
1392,
64,
272,
334,
2960,
402,
9446,
12,
1630,
440,
2387,
314,
5845,
3114,
9,
272,
1380,
1808,
642,
4045,
465,
314,
1642,
4045,
315,
282,
1402,
14,
819,
7242,
2215,
26,
272,
14766,
2215,
465,
1324,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
28052,
12,
1011,
958,
304,
272,
1613,
8,
26756,
21446,
12,
291,
2843,
826,
14155,
958,
9,
272,
291,
14,
9823,
63,
2629,
316,
275,
715,
272,
291,
14,
21672,
275,
28052,
819,
347,
1240,
8,
277,
12,
4153,
12,
6093,
29,
403,
304,
339,
347,
949,
9096,
837,
489,
372,
4153,
435,
1804,
14,
2355,
63,
3302,
8,
881,
2215,
29,
1144,
63,
1483,
14,
1392,
8,
3711,
395,
881,
4615,
29,
16,
2020,
881,
28052,
29,
277,
14,
21672,
12,
881,
2152,
29,
3711,
14,
2271,
9,
339,
372,
1804,
14,
262,
63,
2834,
63,
6971,
8,
889,
9096,
12,
4153,
12,
6093,
29,
7588,
9,
819,
347,
664,
63,
888,
8,
277,
304,
272,
1101,
275,
791,
21672,
356,
291,
14,
21672,
93,
272,
1300,
63,
888,
275,
1613,
8,
26756,
21446,
12,
291,
680,
362,
63,
888,
342,
272,
372,
1211,
8,
513,
8,
1095,
63,
888,
14,
1744,
1012,
435,
769,
8,
888,
14,
1744,
4059,
819,
768,
3249,
63,
1208,
14,
1392,
63,
466,
63,
15083,
523,
347,
4526,
63,
1199,
63,
1392,
8,
277,
12,
1324,
63,
1392,
304,
272,
372,
1324,
63,
1392,
421,
199,
32,
8811,
63,
3790,
360,
8811,
14,
4359,
14,
26756,
30662,
358,
199,
533,
17131,
30662,
8,
5003,
304,
523,
408,
16581,
8897,
606,
1905,
413,
13,
20080,
17131,
11145,
14,
819,
3709,
652,
365,
282,
21095,
4045,
12,
652,
365,
1454,
4702,
737,
6093,
900,
14,
819,
7628,
26,
272,
6634,
26,
11140,
12,
5978,
12224,
334,
305,
543,
658,
30662,
14963,
489,
710,
8897,
606,
1905,
11145,
911,
1172,
489,
4465,
18458,
658,
5079,
8,
1866,
1182,
334,
17,
446,
6634,
430,
2313,
819,
6523,
2368,
26,
272,
4153,
26,
6924,
2345,
334,
1618,
1263,
6915,
680,
272,
6093,
26,
2018,
5046,
9297,
3775,
314,
4045,
1077,
24062,
315,
489,
6093,
818,
334,
4095,
19795,
9,
503,
315,
17353,
818,
334,
1117,
316,
6548,
680,
819,
6924,
2215,
26,
272,
1952,
8734,
14,
3645,
314,
4252,
1423,
658,
1210,
63,
1392,
64,
272,
334,
2960,
402,
9446,
12,
1630,
440,
2387,
314,
5845,
3114,
9,
272,
1380,
1808,
642,
4045,
465,
314,
1642,
4045,
315,
282,
1402,
14,
819,
7242,
2215,
26,
272,
14766,
2215,
465,
1324,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
6634,
12,
1011,
958,
304,
272,
1613,
8,
26756,
30662,
12,
291,
2843,
826,
14155,
958,
9,
272,
291,
14,
9823,
63,
2629,
316,
275,
715,
272,
291,
14,
1866,
275,
6634,
819,
347,
1240,
8,
277,
12,
4153,
12,
6093,
29,
403,
304,
272,
340,
378,
665,
291,
14,
1866,
665,
413,
26,
2541,
347,
949,
9096,
837,
267,
28052,
275,
980,
14,
5079,
8,
277,
14,
1866,
1182,
334,
17,
14,
16,
446,
291,
14,
1866,
430,
267,
372,
4153,
627,
1804,
14,
2355,
63,
3302,
8,
288,
2215,
29,
1144,
63,
1483,
14,
1392,
8,
3711,
395,
288,
4615,
29,
17,
14,
16,
12,
288,
28052,
29,
21672,
12,
288,
2152,
29,
3711,
14,
2271,
9,
2541,
372,
1804,
14,
262,
63,
2834,
63,
6971,
8,
889,
9096,
12,
4153,
12,
6093,
29,
7588,
9,
272,
372,
4153,
819,
347,
664,
63,
888,
8,
277,
304,
272,
1101,
275,
791,
1866,
356,
291,
14,
1866,
93,
272
] |
[
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
16862,
626,
19218,
21095,
4799,
314,
10234,
402,
11145,
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,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
14,
8811,
492,
4865,
465,
1804,
199,
504,
3228,
14,
1548,
14,
8811,
14,
3908,
14,
1095,
63,
1897,
492,
11915,
199,
504,
3228,
14,
1548,
14,
8811,
14,
1208,
492,
2833,
63,
1208,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1974,
14,
3249,
63,
3790,
492,
11708,
63,
3790,
421,
199,
32,
8811,
63,
3790,
360,
8811,
14,
4359,
14,
26756,
21446,
358,
199,
533,
17131,
21446,
8,
5003,
304,
523,
408,
16581,
1503,
30844,
4697,
13,
20080,
17131,
11145,
14,
819,
961,
365,
2997,
370,
333,
5277,
3237,
1806,
3269,
1337,
523,
334,
13297,
4293,
1937,
652,
465,
282,
1824,
402,
2196,
666,
18336,
3117,
680,
523,
17131,
3091,
572,
334,
8021,
9,
365,
282,
19981,
7141,
465,
1970,
5505,
296,
2112,
523,
367,
3363,
574,
68,
4153,
14,
819,
3709,
652,
365,
282,
21095,
4045,
12,
652,
365,
1454,
4702,
737,
6093,
900,
14,
819,
7628,
26,
272,
28052,
26,
11140,
12,
4465,
18458,
402,
314,
11145,
4084,
14,
819,
6523,
2368,
26,
272,
4153,
26,
6924,
2345,
334,
1618,
1263,
6915,
680,
272,
6093,
26,
2018,
5046,
9297,
3775,
314,
4045,
1077,
24062,
315,
489,
6093,
818,
334,
4095,
11145,
9,
503,
315,
17353,
818,
334,
1117,
316,
6548,
680,
819,
6924,
2215,
26,
272,
1952,
8734,
14,
3645,
314,
4252,
1423,
658,
1210,
63,
1392,
64,
272,
334,
2960,
402,
9446,
12,
1630,
440,
2387,
314,
5845,
3114,
9,
272,
1380,
1808,
642,
4045,
465,
314,
1642,
4045,
315,
282,
1402,
14,
819,
7242,
2215,
26,
272,
14766,
2215,
465,
1324,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
28052,
12,
1011,
958,
304,
272,
1613,
8,
26756,
21446,
12,
291,
2843,
826,
14155,
958,
9,
272,
291,
14,
9823,
63,
2629,
316,
275,
715,
272,
291,
14,
21672,
275,
28052,
819,
347,
1240,
8,
277,
12,
4153,
12,
6093,
29,
403,
304,
339,
347,
949,
9096,
837,
489,
372,
4153,
435,
1804,
14,
2355,
63,
3302,
8,
881,
2215,
29,
1144,
63,
1483,
14,
1392,
8,
3711,
395,
881,
4615,
29,
16,
2020,
881,
28052,
29,
277,
14,
21672,
12,
881,
2152,
29,
3711,
14,
2271,
9,
339,
372,
1804,
14,
262,
63,
2834,
63,
6971,
8,
889,
9096,
12,
4153,
12,
6093,
29,
7588,
9,
819,
347,
664,
63,
888,
8,
277,
304,
272,
1101,
275,
791,
21672,
356,
291,
14,
21672,
93,
272,
1300,
63,
888,
275,
1613,
8,
26756,
21446,
12,
291,
680,
362,
63,
888,
342,
272,
372,
1211,
8,
513,
8,
1095,
63,
888,
14,
1744,
1012,
435,
769,
8,
888,
14,
1744,
4059,
819,
768,
3249,
63,
1208,
14,
1392,
63,
466,
63,
15083,
523,
347,
4526,
63,
1199,
63,
1392,
8,
277,
12,
1324,
63,
1392,
304,
272,
372,
1324,
63,
1392,
421,
199,
32,
8811,
63,
3790,
360,
8811,
14,
4359,
14,
26756,
30662,
358,
199,
533,
17131,
30662,
8,
5003,
304,
523,
408,
16581,
8897,
606,
1905,
413,
13,
20080,
17131,
11145,
14,
819,
3709,
652,
365,
282,
21095,
4045,
12,
652,
365,
1454,
4702,
737,
6093,
900,
14,
819,
7628,
26,
272,
6634,
26,
11140,
12,
5978,
12224,
334,
305,
543,
658,
30662,
14963,
489,
710,
8897,
606,
1905,
11145,
911,
1172,
489,
4465,
18458,
658,
5079,
8,
1866,
1182,
334,
17,
446,
6634,
430,
2313,
819,
6523,
2368,
26,
272,
4153,
26,
6924,
2345,
334,
1618,
1263,
6915,
680,
272,
6093,
26,
2018,
5046,
9297,
3775,
314,
4045,
1077,
24062,
315,
489,
6093,
818,
334,
4095,
19795,
9,
503,
315,
17353,
818,
334,
1117,
316,
6548,
680,
819,
6924,
2215,
26,
272,
1952,
8734,
14,
3645,
314,
4252,
1423,
658,
1210,
63,
1392,
64,
272,
334,
2960,
402,
9446,
12,
1630,
440,
2387,
314,
5845,
3114,
9,
272,
1380,
1808,
642,
4045,
465,
314,
1642,
4045,
315,
282,
1402,
14,
819,
7242,
2215,
26,
272,
14766,
2215,
465,
1324,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
6634,
12,
1011,
958,
304,
272,
1613,
8,
26756,
30662,
12,
291,
2843,
826,
14155,
958,
9,
272,
291,
14,
9823,
63,
2629,
316,
275,
715,
272,
291,
14,
1866,
275,
6634,
819,
347,
1240,
8,
277,
12,
4153,
12,
6093,
29,
403,
304,
272,
340,
378,
665,
291,
14,
1866,
665,
413,
26,
2541,
347,
949,
9096,
837,
267,
28052,
275,
980,
14,
5079,
8,
277,
14,
1866,
1182,
334,
17,
14,
16,
446,
291,
14,
1866,
430,
267,
372,
4153,
627,
1804,
14,
2355,
63,
3302,
8,
288,
2215,
29,
1144,
63,
1483,
14,
1392,
8,
3711,
395,
288,
4615,
29,
17,
14,
16,
12,
288,
28052,
29,
21672,
12,
288,
2152,
29,
3711,
14,
2271,
9,
2541,
372,
1804,
14,
262,
63,
2834,
63,
6971,
8,
889,
9096,
12,
4153,
12,
6093,
29,
7588,
9,
272,
372,
4153,
819,
347,
664,
63,
888,
8,
277,
304,
272,
1101,
275,
791,
1866,
356,
291,
14,
1866,
93,
272,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
unicri/edx-platform
|
cms/djangoapps/contentstore/views/assets.py
|
25
|
14681
|
import logging
from functools import partial
import math
import json
from django.http import HttpResponseBadRequest
from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_http_methods
from django_future.csrf import ensure_csrf_cookie
from django.views.decorators.http import require_POST
from django.conf import settings
from edxmako.shortcuts import render_to_response
from cache_toolbox.core import del_cached_content
from contentstore.utils import reverse_course_url
from xmodule.contentstore.django import contentstore
from xmodule.modulestore.django import modulestore
from xmodule.contentstore.content import StaticContent
from xmodule.exceptions import NotFoundError
from django.core.exceptions import PermissionDenied
from opaque_keys.edx.keys import CourseKey, AssetKey
from util.date_utils import get_default_time_display
from util.json_request import JsonResponse
from django.http import HttpResponseNotFound
from django.utils.translation import ugettext as _
from pymongo import ASCENDING, DESCENDING
from student.auth import has_course_author_access
from xmodule.modulestore.exceptions import ItemNotFoundError
__all__ = ['assets_handler']
# pylint: disable=unused-argument
@login_required
@ensure_csrf_cookie
def assets_handler(request, course_key_string=None, asset_key_string=None):
"""
The restful handler for assets.
It allows retrieval of all the assets (as an HTML page), as well as uploading new assets,
deleting assets, and changing the "locked" state of an asset.
GET
html: return an html page which will show all course assets. Note that only the asset container
is returned and that the actual assets are filled in with a client-side request.
json: returns a page of assets. The following parameters are supported:
page: the desired page of results (defaults to 0)
page_size: the number of items per page (defaults to 50)
sort: the asset field to sort by (defaults to "date_added")
direction: the sort direction (defaults to "descending")
POST
json: create (or update?) an asset. The only updating that can be done is changing the lock state.
PUT
json: update the locked state of an asset
DELETE
json: delete an asset
"""
course_key = CourseKey.from_string(course_key_string)
if not has_course_author_access(request.user, course_key):
raise PermissionDenied()
response_format = request.REQUEST.get('format', 'html')
if response_format == 'json' or 'application/json' in request.META.get('HTTP_ACCEPT', 'application/json'):
if request.method == 'GET':
return _assets_json(request, course_key)
else:
asset_key = AssetKey.from_string(asset_key_string) if asset_key_string else None
return _update_asset(request, course_key, asset_key)
elif request.method == 'GET': # assume html
return _asset_index(request, course_key)
else:
return HttpResponseNotFound()
def _asset_index(request, course_key):
"""
Display an editable asset library.
Supports start (0-based index into the list of assets) and max query parameters.
"""
course_module = modulestore().get_course(course_key)
return render_to_response('asset_index.html', {
'context_course': course_module,
'max_file_size_in_mbs': settings.MAX_ASSET_UPLOAD_FILE_SIZE_IN_MB,
'chunk_size_in_mbs': settings.UPLOAD_CHUNK_SIZE_IN_MB,
'max_file_size_redirect_url': settings.MAX_ASSET_UPLOAD_FILE_SIZE_URL,
'asset_callback_url': reverse_course_url('assets_handler', course_key)
})
def _assets_json(request, course_key):
"""
Display an editable asset library.
Supports start (0-based index into the list of assets) and max query parameters.
"""
requested_page = int(request.REQUEST.get('page', 0))
requested_page_size = int(request.REQUEST.get('page_size', 50))
requested_sort = request.REQUEST.get('sort', 'date_added')
requested_filter = request.REQUEST.get('asset_type', '')
requested_file_types = settings.FILES_AND_UPLOAD_TYPE_FILTERS.get(
requested_filter, None)
filter_params = None
if requested_filter:
if requested_filter == 'OTHER':
all_filters = settings.FILES_AND_UPLOAD_TYPE_FILTERS
where = []
for all_filter in all_filters:
extension_filters = all_filters[all_filter]
where.extend(
["JSON.stringify(this.contentType).toUpperCase() != JSON.stringify('{}').toUpperCase()".format(
extension_filter) for extension_filter in extension_filters])
filter_params = {
"$where": ' && '.join(where),
}
else:
where = ["JSON.stringify(this.contentType).toUpperCase() == JSON.stringify('{}').toUpperCase()".format(
req_filter) for req_filter in requested_file_types]
filter_params = {
"$where": ' || '.join(where),
}
sort_direction = DESCENDING
if request.REQUEST.get('direction', '').lower() == 'asc':
sort_direction = ASCENDING
# Convert the field name to the Mongo name
if requested_sort == 'date_added':
requested_sort = 'uploadDate'
elif requested_sort == 'display_name':
requested_sort = 'displayname'
sort = [(requested_sort, sort_direction)]
current_page = max(requested_page, 0)
start = current_page * requested_page_size
options = {
'current_page': current_page,
'page_size': requested_page_size,
'sort': sort,
'filter_params': filter_params
}
assets, total_count = _get_assets_for_page(request, course_key, options)
end = start + len(assets)
# If the query is beyond the final page, then re-query the final page so
# that at least one asset is returned
if requested_page > 0 and start >= total_count:
options['current_page'] = current_page = int(math.floor((total_count - 1) / requested_page_size))
start = current_page * requested_page_size
assets, total_count = _get_assets_for_page(request, course_key, options)
end = start + len(assets)
asset_json = []
for asset in assets:
asset_location = asset['asset_key']
# note, due to the schema change we may not have a 'thumbnail_location'
# in the result set
thumbnail_location = asset.get('thumbnail_location', None)
if thumbnail_location:
thumbnail_location = course_key.make_asset_key(
'thumbnail', thumbnail_location[4])
asset_locked = asset.get('locked', False)
asset_json.append(_get_asset_json(
asset['displayname'],
asset['contentType'],
asset['uploadDate'],
asset_location,
thumbnail_location,
asset_locked
))
return JsonResponse({
'start': start,
'end': end,
'page': current_page,
'pageSize': requested_page_size,
'totalCount': total_count,
'assets': asset_json,
'sort': requested_sort,
})
def _get_assets_for_page(request, course_key, options):
"""
Returns the list of assets for the specified page and page size.
"""
current_page = options['current_page']
page_size = options['page_size']
sort = options['sort']
filter_params = options['filter_params'] if options['filter_params'] else None
start = current_page * page_size
return contentstore().get_all_content_for_course(
course_key, start=start, maxresults=page_size, sort=sort, filter_params=filter_params
)
def get_file_size(upload_file):
"""
Helper method for getting file size of an upload file.
Can be used for mocking test file sizes.
"""
return upload_file.size
@require_POST
@ensure_csrf_cookie
@login_required
def _upload_asset(request, course_key):
'''
This method allows for POST uploading of files into the course asset
library, which will be supported by GridFS in MongoDB.
'''
# Does the course actually exist?!? Get anything from it to prove its
# existence
try:
modulestore().get_course(course_key)
except ItemNotFoundError:
# no return it as a Bad Request response
logging.error("Could not find course: %s", course_key)
return HttpResponseBadRequest()
# compute a 'filename' which is similar to the location formatting, we're
# using the 'filename' nomenclature since we're using a FileSystem paradigm
# here. We're just imposing the Location string formatting expectations to
# keep things a bit more consistent
upload_file = request.FILES['file']
filename = upload_file.name
mime_type = upload_file.content_type
size = get_file_size(upload_file)
# If file is greater than a specified size, reject the upload
# request and send a message to the user. Note that since
# the front-end may batch large file uploads in smaller chunks,
# we validate the file-size on the front-end in addition to
# validating on the backend. (see cms/static/js/views/assets.js)
max_file_size_in_bytes = settings.MAX_ASSET_UPLOAD_FILE_SIZE_IN_MB * 1000 ** 2
if size > max_file_size_in_bytes:
return JsonResponse({
'error': _(
'File {filename} exceeds maximum size of '
'{size_mb} MB. Please follow the instructions here '
'to upload a file elsewhere and link to it instead: '
'{faq_url}'
).format(
filename=filename,
size_mb=settings.MAX_ASSET_UPLOAD_FILE_SIZE_IN_MB,
faq_url=settings.MAX_ASSET_UPLOAD_FILE_SIZE_URL,
)
}, status=413)
content_loc = StaticContent.compute_location(course_key, filename)
chunked = upload_file.multiple_chunks()
sc_partial = partial(StaticContent, content_loc, filename, mime_type)
if chunked:
content = sc_partial(upload_file.chunks())
tempfile_path = upload_file.temporary_file_path()
else:
content = sc_partial(upload_file.read())
tempfile_path = None
# first let's see if a thumbnail can be created
(thumbnail_content, thumbnail_location) = contentstore().generate_thumbnail(
content,
tempfile_path=tempfile_path,
)
# delete cached thumbnail even if one couldn't be created this time (else
# the old thumbnail will continue to show)
del_cached_content(thumbnail_location)
# now store thumbnail location only if we could create it
if thumbnail_content is not None:
content.thumbnail_location = thumbnail_location
# then commit the content
contentstore().save(content)
del_cached_content(content.location)
# readback the saved content - we need the database timestamp
readback = contentstore().find(content.location)
locked = getattr(content, 'locked', False)
response_payload = {
'asset': _get_asset_json(
content.name,
content.content_type,
readback.last_modified_at,
content.location,
content.thumbnail_location,
locked
),
'msg': _('Upload completed')
}
return JsonResponse(response_payload)
@require_http_methods(("DELETE", "POST", "PUT"))
@login_required
@ensure_csrf_cookie
def _update_asset(request, course_key, asset_key):
"""
restful CRUD operations for a course asset.
Currently only DELETE, POST, and PUT methods are implemented.
asset_path_encoding: the odd /c4x/org/course/category/name repr of the asset (used by Backbone as the id)
"""
if request.method == 'DELETE':
# Make sure the item to delete actually exists.
try:
content = contentstore().find(asset_key)
except NotFoundError:
return JsonResponse(status=404)
# ok, save the content into the trashcan
contentstore('trashcan').save(content)
# see if there is a thumbnail as well, if so move that as well
if content.thumbnail_location is not None:
# We are ignoring the value of the thumbnail_location-- we only care whether
# or not a thumbnail has been stored, and we can now easily create the correct path.
thumbnail_location = course_key.make_asset_key('thumbnail', asset_key.name)
try:
thumbnail_content = contentstore().find(thumbnail_location)
contentstore('trashcan').save(thumbnail_content)
# hard delete thumbnail from origin
contentstore().delete(thumbnail_content.get_id())
# remove from any caching
del_cached_content(thumbnail_location)
except:
logging.warning('Could not delete thumbnail: %s', thumbnail_location)
# delete the original
contentstore().delete(content.get_id())
# remove from cache
del_cached_content(content.location)
return JsonResponse()
elif request.method in ('PUT', 'POST'):
if 'file' in request.FILES:
return _upload_asset(request, course_key)
else:
# Update existing asset
try:
modified_asset = json.loads(request.body)
except ValueError:
return HttpResponseBadRequest()
contentstore().set_attr(asset_key, 'locked', modified_asset['locked'])
# Delete the asset from the cache so we check the lock status the next time it is requested.
del_cached_content(asset_key)
return JsonResponse(modified_asset, status=201)
def _get_asset_json(display_name, content_type, date, location, thumbnail_location, locked):
"""
Helper method for formatting the asset information to send to client.
"""
asset_url = StaticContent.serialize_asset_key_with_slash(location)
external_url = settings.LMS_BASE + asset_url
return {
'display_name': display_name,
'content_type': content_type,
'date_added': get_default_time_display(date),
'url': asset_url,
'external_url': external_url,
'portable_url': StaticContent.get_static_path_from_location(location),
'thumbnail': StaticContent.serialize_asset_key_with_slash(thumbnail_location) if thumbnail_location else None,
'locked': locked,
# Needed for Backbone delete/update.
'id': unicode(location)
}
|
agpl-3.0
|
[
646,
2050,
199,
504,
9143,
492,
7417,
199,
646,
3473,
199,
646,
2022,
199,
199,
504,
1639,
14,
1014,
492,
6183,
12380,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1014,
492,
4409,
63,
1014,
63,
2474,
199,
504,
1639,
63,
2443,
14,
10088,
492,
4868,
63,
10088,
63,
5306,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1014,
492,
4409,
63,
4030,
199,
504,
1639,
14,
2190,
492,
2202,
199,
199,
504,
22435,
19491,
14,
17469,
492,
3795,
63,
475,
63,
1310,
199,
504,
2581,
63,
3557,
1977,
14,
1018,
492,
2150,
63,
5245,
63,
1317,
199,
199,
504,
23061,
14,
1208,
492,
3837,
63,
1972,
63,
633,
199,
504,
9872,
14,
28160,
14,
1176,
492,
23061,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
9872,
14,
28160,
14,
1317,
492,
13599,
2714,
199,
504,
9872,
14,
3924,
492,
21909,
547,
199,
504,
1639,
14,
1018,
14,
3924,
492,
23724,
199,
504,
15058,
63,
1612,
14,
8268,
14,
1612,
492,
22574,
12,
25670,
1197,
199,
199,
504,
4884,
14,
602,
63,
1208,
492,
664,
63,
885,
63,
521,
63,
2918,
199,
504,
4884,
14,
1001,
63,
1069,
492,
21072,
199,
504,
1639,
14,
1014,
492,
6183,
4667,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
21878,
492,
20955,
15219,
12,
23915,
15219,
199,
504,
6474,
14,
1178,
492,
965,
63,
1972,
63,
2502,
63,
2732,
199,
504,
9872,
14,
10012,
14,
3924,
492,
7020,
10870,
199,
199,
363,
452,
363,
275,
788,
12186,
63,
2232,
418,
199,
199,
3,
4287,
26,
3507,
29,
8618,
13,
2094,
421,
199,
32,
2886,
63,
2427,
199,
32,
7505,
63,
10088,
63,
5306,
199,
318,
17202,
63,
2232,
8,
1069,
12,
2518,
63,
498,
63,
875,
29,
403,
12,
8977,
63,
498,
63,
875,
29,
403,
304,
272,
408,
272,
710,
4618,
1893,
3016,
367,
17202,
14,
272,
2779,
6127,
27157,
402,
1006,
314,
17202,
334,
305,
376,
4163,
2034,
395,
465,
5521,
465,
24349,
892,
17202,
12,
272,
13794,
17202,
12,
436,
13729,
314,
298,
9325,
2,
1174,
402,
376,
8977,
14,
339,
9576,
267,
3517,
26,
372,
376,
3517,
2034,
1314,
911,
2498,
1006,
2518,
17202,
14,
3390,
626,
1454,
314,
8977,
3970,
288,
365,
2138,
436,
626,
314,
3503,
17202,
787,
13457,
315,
543,
282,
1890,
13,
2441,
1056,
14,
267,
2022,
26,
2529,
282,
2034,
402,
17202,
14,
710,
2569,
2633,
787,
3748,
26,
288,
2034,
26,
314,
6387,
2034,
402,
2058,
334,
4322,
370,
378,
9,
288,
2034,
63,
890,
26,
314,
1329,
402,
2974,
1126,
2034,
334,
4322,
370,
5238,
9,
288,
4069,
26,
314,
8977,
901,
370,
4069,
701,
334,
4322,
370,
298,
602,
63,
3270,
531,
288,
7581,
26,
314,
4069,
7581,
334,
4322,
370,
298,
3257,
3219,
531,
272,
8761,
267,
2022,
26,
1218,
334,
269,
1678,
17076,
376,
8977,
14,
710,
1454,
12928,
626,
883,
506,
4224,
365,
13729,
314,
4650,
1174,
14,
272,
18337,
267,
2022,
26,
1678,
314,
14233,
1174,
402,
376,
8977,
272,
15137,
267,
2022,
26,
3145,
376,
8977,
272,
408,
272,
2518,
63,
498,
275,
22574,
14,
504,
63,
875,
8,
1972,
63,
498,
63,
875,
9,
272,
340,
440,
965,
63,
1972,
63,
2502,
63,
2732,
8,
1069,
14,
751,
12,
2518,
63,
498,
304,
267,
746,
23724,
342,
339,
1177,
63,
908,
275,
1056,
14,
6780,
14,
362,
360,
908,
297,
283,
1360,
358,
272,
340,
1177,
63,
908,
508,
283,
1001,
7,
503,
283,
3578,
15,
1001,
7,
315,
1056,
14,
10614,
14,
362,
360,
2856,
63,
13089,
297,
283,
3578,
15,
1001,
735,
267,
340,
1056,
14,
765,
508,
283,
2970,
356,
288,
372,
485,
12186,
63,
1001,
8,
1069,
12,
2518,
63,
498,
9,
267,
587,
26,
288,
8977,
63,
498,
275,
25670,
1197,
14,
504,
63,
875,
8,
6562,
63,
498,
63,
875,
9,
340,
8977,
63,
498,
63,
875,
587,
488,
288,
372,
485,
873,
63,
6562,
8,
1069,
12,
2518,
63,
498,
12,
8977,
63,
498,
9,
272,
916,
1056,
14,
765,
508,
283,
2970,
356,
221,
327,
5534,
3517,
267,
372,
485,
6562,
63,
1080,
8,
1069,
12,
2518,
63,
498,
9,
272,
587,
26,
267,
372,
6183,
4667,
342,
421,
199,
318,
485,
6562,
63,
1080,
8,
1069,
12,
2518,
63,
498,
304,
272,
408,
272,
12175,
376,
14783,
8977,
3555,
14,
339,
32090,
1343,
334,
16,
13,
6788,
1478,
1901,
314,
769,
402,
17202,
9,
436,
1390,
1827,
2633,
14,
272,
408,
272,
2518,
63,
578,
275,
10996,
1252,
362,
63,
1972,
8,
1972,
63,
498,
9,
339,
372,
3795,
63,
475,
63,
1310,
360,
6562,
63,
1080,
14,
1360,
297,
469,
267,
283,
1100,
63,
1972,
356,
2518,
63,
578,
12,
267,
283,
988,
63,
493,
63,
890,
63,
262,
63,
887,
83,
356,
2202,
14,
4283,
63,
1179,
3597,
63,
16418,
63,
3817,
63,
4305,
63,
568,
63,
4567,
12,
267,
283,
4604,
63,
890,
63,
262,
63,
887,
83,
356,
2202,
14,
16418,
63,
20512,
63,
4305,
63,
568,
63,
4567,
12,
267,
283,
988,
63,
493,
63,
890,
63,
4876,
63,
633,
356,
2202,
14,
4283,
63,
1179,
3597,
63,
16418,
63,
3817,
63,
4305,
63,
2632,
12,
267,
283,
6562,
63,
3058,
63,
633,
356,
3837,
63,
1972,
63,
633,
360,
12186,
63,
2232,
297,
2518,
63,
498,
9,
272,
3828,
421,
199,
318,
485,
12186,
63,
1001,
8,
1069,
12,
2518,
63,
498,
304,
272,
408,
272,
12175,
376,
14783,
8977,
3555,
14,
339,
32090,
1343,
334,
16,
13,
6788,
1478,
1901,
314,
769,
402,
17202,
9,
436,
1390,
1827,
2633,
14,
272,
408,
272,
5839,
63,
1606,
275,
1109,
8,
1069,
14,
6780,
14,
362,
360,
1606,
297,
378,
430,
272,
5839,
63,
1606,
63,
890,
275,
1109,
8,
1069,
14,
6780,
14,
362,
360,
1606,
63,
890,
297,
5238,
430,
272,
5839,
63,
3191,
275,
1056,
14,
6780,
14,
362,
360,
3191,
297,
283,
602,
63,
3270,
358,
272,
5839,
63,
1541,
275,
1056,
14,
6780,
14,
362,
360,
6562,
63,
466,
297,
4074,
272,
5839,
63,
493,
63,
1313,
275,
2202
] |
[
2050,
199,
504,
9143,
492,
7417,
199,
646,
3473,
199,
646,
2022,
199,
199,
504,
1639,
14,
1014,
492,
6183,
12380,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1014,
492,
4409,
63,
1014,
63,
2474,
199,
504,
1639,
63,
2443,
14,
10088,
492,
4868,
63,
10088,
63,
5306,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1014,
492,
4409,
63,
4030,
199,
504,
1639,
14,
2190,
492,
2202,
199,
199,
504,
22435,
19491,
14,
17469,
492,
3795,
63,
475,
63,
1310,
199,
504,
2581,
63,
3557,
1977,
14,
1018,
492,
2150,
63,
5245,
63,
1317,
199,
199,
504,
23061,
14,
1208,
492,
3837,
63,
1972,
63,
633,
199,
504,
9872,
14,
28160,
14,
1176,
492,
23061,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
9872,
14,
28160,
14,
1317,
492,
13599,
2714,
199,
504,
9872,
14,
3924,
492,
21909,
547,
199,
504,
1639,
14,
1018,
14,
3924,
492,
23724,
199,
504,
15058,
63,
1612,
14,
8268,
14,
1612,
492,
22574,
12,
25670,
1197,
199,
199,
504,
4884,
14,
602,
63,
1208,
492,
664,
63,
885,
63,
521,
63,
2918,
199,
504,
4884,
14,
1001,
63,
1069,
492,
21072,
199,
504,
1639,
14,
1014,
492,
6183,
4667,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
21878,
492,
20955,
15219,
12,
23915,
15219,
199,
504,
6474,
14,
1178,
492,
965,
63,
1972,
63,
2502,
63,
2732,
199,
504,
9872,
14,
10012,
14,
3924,
492,
7020,
10870,
199,
199,
363,
452,
363,
275,
788,
12186,
63,
2232,
418,
199,
199,
3,
4287,
26,
3507,
29,
8618,
13,
2094,
421,
199,
32,
2886,
63,
2427,
199,
32,
7505,
63,
10088,
63,
5306,
199,
318,
17202,
63,
2232,
8,
1069,
12,
2518,
63,
498,
63,
875,
29,
403,
12,
8977,
63,
498,
63,
875,
29,
403,
304,
272,
408,
272,
710,
4618,
1893,
3016,
367,
17202,
14,
272,
2779,
6127,
27157,
402,
1006,
314,
17202,
334,
305,
376,
4163,
2034,
395,
465,
5521,
465,
24349,
892,
17202,
12,
272,
13794,
17202,
12,
436,
13729,
314,
298,
9325,
2,
1174,
402,
376,
8977,
14,
339,
9576,
267,
3517,
26,
372,
376,
3517,
2034,
1314,
911,
2498,
1006,
2518,
17202,
14,
3390,
626,
1454,
314,
8977,
3970,
288,
365,
2138,
436,
626,
314,
3503,
17202,
787,
13457,
315,
543,
282,
1890,
13,
2441,
1056,
14,
267,
2022,
26,
2529,
282,
2034,
402,
17202,
14,
710,
2569,
2633,
787,
3748,
26,
288,
2034,
26,
314,
6387,
2034,
402,
2058,
334,
4322,
370,
378,
9,
288,
2034,
63,
890,
26,
314,
1329,
402,
2974,
1126,
2034,
334,
4322,
370,
5238,
9,
288,
4069,
26,
314,
8977,
901,
370,
4069,
701,
334,
4322,
370,
298,
602,
63,
3270,
531,
288,
7581,
26,
314,
4069,
7581,
334,
4322,
370,
298,
3257,
3219,
531,
272,
8761,
267,
2022,
26,
1218,
334,
269,
1678,
17076,
376,
8977,
14,
710,
1454,
12928,
626,
883,
506,
4224,
365,
13729,
314,
4650,
1174,
14,
272,
18337,
267,
2022,
26,
1678,
314,
14233,
1174,
402,
376,
8977,
272,
15137,
267,
2022,
26,
3145,
376,
8977,
272,
408,
272,
2518,
63,
498,
275,
22574,
14,
504,
63,
875,
8,
1972,
63,
498,
63,
875,
9,
272,
340,
440,
965,
63,
1972,
63,
2502,
63,
2732,
8,
1069,
14,
751,
12,
2518,
63,
498,
304,
267,
746,
23724,
342,
339,
1177,
63,
908,
275,
1056,
14,
6780,
14,
362,
360,
908,
297,
283,
1360,
358,
272,
340,
1177,
63,
908,
508,
283,
1001,
7,
503,
283,
3578,
15,
1001,
7,
315,
1056,
14,
10614,
14,
362,
360,
2856,
63,
13089,
297,
283,
3578,
15,
1001,
735,
267,
340,
1056,
14,
765,
508,
283,
2970,
356,
288,
372,
485,
12186,
63,
1001,
8,
1069,
12,
2518,
63,
498,
9,
267,
587,
26,
288,
8977,
63,
498,
275,
25670,
1197,
14,
504,
63,
875,
8,
6562,
63,
498,
63,
875,
9,
340,
8977,
63,
498,
63,
875,
587,
488,
288,
372,
485,
873,
63,
6562,
8,
1069,
12,
2518,
63,
498,
12,
8977,
63,
498,
9,
272,
916,
1056,
14,
765,
508,
283,
2970,
356,
221,
327,
5534,
3517,
267,
372,
485,
6562,
63,
1080,
8,
1069,
12,
2518,
63,
498,
9,
272,
587,
26,
267,
372,
6183,
4667,
342,
421,
199,
318,
485,
6562,
63,
1080,
8,
1069,
12,
2518,
63,
498,
304,
272,
408,
272,
12175,
376,
14783,
8977,
3555,
14,
339,
32090,
1343,
334,
16,
13,
6788,
1478,
1901,
314,
769,
402,
17202,
9,
436,
1390,
1827,
2633,
14,
272,
408,
272,
2518,
63,
578,
275,
10996,
1252,
362,
63,
1972,
8,
1972,
63,
498,
9,
339,
372,
3795,
63,
475,
63,
1310,
360,
6562,
63,
1080,
14,
1360,
297,
469,
267,
283,
1100,
63,
1972,
356,
2518,
63,
578,
12,
267,
283,
988,
63,
493,
63,
890,
63,
262,
63,
887,
83,
356,
2202,
14,
4283,
63,
1179,
3597,
63,
16418,
63,
3817,
63,
4305,
63,
568,
63,
4567,
12,
267,
283,
4604,
63,
890,
63,
262,
63,
887,
83,
356,
2202,
14,
16418,
63,
20512,
63,
4305,
63,
568,
63,
4567,
12,
267,
283,
988,
63,
493,
63,
890,
63,
4876,
63,
633,
356,
2202,
14,
4283,
63,
1179,
3597,
63,
16418,
63,
3817,
63,
4305,
63,
2632,
12,
267,
283,
6562,
63,
3058,
63,
633,
356,
3837,
63,
1972,
63,
633,
360,
12186,
63,
2232,
297,
2518,
63,
498,
9,
272,
3828,
421,
199,
318,
485,
12186,
63,
1001,
8,
1069,
12,
2518,
63,
498,
304,
272,
408,
272,
12175,
376,
14783,
8977,
3555,
14,
339,
32090,
1343,
334,
16,
13,
6788,
1478,
1901,
314,
769,
402,
17202,
9,
436,
1390,
1827,
2633,
14,
272,
408,
272,
5839,
63,
1606,
275,
1109,
8,
1069,
14,
6780,
14,
362,
360,
1606,
297,
378,
430,
272,
5839,
63,
1606,
63,
890,
275,
1109,
8,
1069,
14,
6780,
14,
362,
360,
1606,
63,
890,
297,
5238,
430,
272,
5839,
63,
3191,
275,
1056,
14,
6780,
14,
362,
360,
3191,
297,
283,
602,
63,
3270,
358,
272,
5839,
63,
1541,
275,
1056,
14,
6780,
14,
362,
360,
6562,
63,
466,
297,
4074,
272,
5839,
63,
493,
63,
1313,
275,
2202,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hoatle/odoo
|
addons/account_followup/account_followup.py
|
94
|
29520
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import api
from openerp.osv import fields, osv
from lxml import etree
from openerp.tools.translate import _
class followup(osv.osv):
_name = 'account_followup.followup'
_description = 'Account Follow-up'
_rec_name = 'name'
_columns = {
'followup_line': fields.one2many('account_followup.followup.line', 'followup_id', 'Follow-up', copy=True),
'company_id': fields.many2one('res.company', 'Company', required=True),
'name': fields.related('company_id', 'name', string = "Name", readonly=True, type="char"),
}
_defaults = {
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'account_followup.followup', context=c),
}
_sql_constraints = [('company_uniq', 'unique(company_id)', 'Only one follow-up per company is allowed')]
class followup_line(osv.osv):
def _get_default_template(self, cr, uid, ids, context=None):
try:
return self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_followup', 'email_template_account_followup_default')[1]
except ValueError:
return False
_name = 'account_followup.followup.line'
_description = 'Follow-up Criteria'
_columns = {
'name': fields.char('Follow-Up Action', required=True),
'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of follow-up lines."),
'delay': fields.integer('Due Days', help="The number of days after the due date of the invoice to wait before sending the reminder. Could be negative if you want to send a polite alert beforehand.", required=True),
'followup_id': fields.many2one('account_followup.followup', 'Follow Ups', required=True, ondelete="cascade"),
'description': fields.text('Printed Message', translate=True),
'send_email':fields.boolean('Send an Email', help="When processing, it will send an email"),
'send_letter':fields.boolean('Send a Letter', help="When processing, it will print a letter"),
'manual_action':fields.boolean('Manual Action', help="When processing, it will set the manual action to be taken for that customer. "),
'manual_action_note':fields.text('Action To Do', placeholder="e.g. Give a phone call, check with others , ..."),
'manual_action_responsible_id':fields.many2one('res.users', 'Assign a Responsible', ondelete='set null'),
'email_template_id':fields.many2one('email.template', 'Email Template', ondelete='set null'),
}
_order = 'delay'
_sql_constraints = [('days_uniq', 'unique(followup_id, delay)', 'Days of the follow-up levels must be different')]
_defaults = {
'send_email': True,
'send_letter': True,
'manual_action':False,
'description': """
Dear %(partner_name)s,
Exception made if there was a mistake of ours, it seems that the following amount stays unpaid. Please, take appropriate measures in order to carry out this payment in the next 8 days.
Would your payment have been carried out after this mail was sent, please ignore this message. Do not hesitate to contact our accounting department.
Best Regards,
""",
'email_template_id': _get_default_template,
}
def _check_description(self, cr, uid, ids, context=None):
for line in self.browse(cr, uid, ids, context=context):
if line.description:
try:
line.description % {'partner_name': '', 'date':'', 'user_signature': '', 'company_name': ''}
except:
return False
return True
_constraints = [
(_check_description, 'Your description is invalid, use the right legend or %% if you want to use the percent character.', ['description']),
]
class account_move_line(osv.osv):
def _get_result(self, cr, uid, ids, name, arg, context=None):
res = {}
for aml in self.browse(cr, uid, ids, context=context):
res[aml.id] = aml.debit - aml.credit
return res
_inherit = 'account.move.line'
_columns = {
'followup_line_id': fields.many2one('account_followup.followup.line', 'Follow-up Level',
ondelete='restrict'), #restrict deletion of the followup line
'followup_date': fields.date('Latest Follow-up', select=True),
'result':fields.function(_get_result, type='float', method=True,
string="Balance") #'balance' field is not the same
}
class res_partner(osv.osv):
def fields_view_get(self, cr, uid, view_id=None, view_type=None, context=None, toolbar=False, submenu=False):
res = super(res_partner, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context,
toolbar=toolbar, submenu=submenu)
context = context or {}
if view_type == 'form' and context.get('Followupfirst'):
doc = etree.XML(res['arch'], parser=None, base_url=None)
first_node = doc.xpath("//page[@name='followup_tab']")
root = first_node[0].getparent()
root.insert(0, first_node[0])
res['arch'] = etree.tostring(doc, encoding="utf-8")
return res
def _get_latest(self, cr, uid, ids, names, arg, context=None, company_id=None):
res={}
if company_id == None:
company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id
else:
company = self.pool.get('res.company').browse(cr, uid, company_id, context=context)
for partner in self.browse(cr, uid, ids, context=context):
amls = partner.unreconciled_aml_ids
latest_date = False
latest_level = False
latest_days = False
latest_level_without_lit = False
latest_days_without_lit = False
for aml in amls:
if (aml.company_id == company) and (aml.followup_line_id != False) and (not latest_days or latest_days < aml.followup_line_id.delay):
latest_days = aml.followup_line_id.delay
latest_level = aml.followup_line_id.id
if (aml.company_id == company) and (not latest_date or latest_date < aml.followup_date):
latest_date = aml.followup_date
if (aml.company_id == company) and (aml.blocked == False) and (aml.followup_line_id != False and
(not latest_days_without_lit or latest_days_without_lit < aml.followup_line_id.delay)):
latest_days_without_lit = aml.followup_line_id.delay
latest_level_without_lit = aml.followup_line_id.id
res[partner.id] = {'latest_followup_date': latest_date,
'latest_followup_level_id': latest_level,
'latest_followup_level_id_without_lit': latest_level_without_lit}
return res
@api.cr_uid_ids_context
def do_partner_manual_action(self, cr, uid, partner_ids, context=None):
#partner_ids -> res.partner
for partner in self.browse(cr, uid, partner_ids, context=context):
#Check action: check if the action was not empty, if not add
action_text= ""
if partner.payment_next_action:
action_text = (partner.payment_next_action or '') + "\n" + (partner.latest_followup_level_id_without_lit.manual_action_note or '')
else:
action_text = partner.latest_followup_level_id_without_lit.manual_action_note or ''
#Check date: only change when it did not exist already
action_date = partner.payment_next_action_date or fields.date.context_today(self, cr, uid, context=context)
# Check responsible: if partner has not got a responsible already, take from follow-up
responsible_id = False
if partner.payment_responsible_id:
responsible_id = partner.payment_responsible_id.id
else:
p = partner.latest_followup_level_id_without_lit.manual_action_responsible_id
responsible_id = p and p.id or False
self.write(cr, uid, [partner.id], {'payment_next_action_date': action_date,
'payment_next_action': action_text,
'payment_responsible_id': responsible_id})
def do_partner_print(self, cr, uid, wizard_partner_ids, data, context=None):
#wizard_partner_ids are ids from special view, not from res.partner
if not wizard_partner_ids:
return {}
data['partner_ids'] = wizard_partner_ids
datas = {
'ids': wizard_partner_ids,
'model': 'account_followup.followup',
'form': data
}
return self.pool['report'].get_action(cr, uid, [], 'account_followup.report_followup', data=datas, context=context)
@api.cr_uid_ids_context
def do_partner_mail(self, cr, uid, partner_ids, context=None):
if context is None:
context = {}
ctx = context.copy()
ctx['followup'] = True
#partner_ids are res.partner ids
# If not defined by latest follow-up level, it will be the default template if it can find it
mtp = self.pool.get('email.template')
unknown_mails = 0
for partner in self.browse(cr, uid, partner_ids, context=ctx):
partners_to_email = [child for child in partner.child_ids if child.type == 'invoice' and child.email]
if not partners_to_email and partner.email:
partners_to_email = [partner]
if partners_to_email:
level = partner.latest_followup_level_id_without_lit
for partner_to_email in partners_to_email:
if level and level.send_email and level.email_template_id and level.email_template_id.id:
mtp.send_mail(cr, uid, level.email_template_id.id, partner_to_email.id, context=ctx)
else:
mail_template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid,
'account_followup', 'email_template_account_followup_default')
mtp.send_mail(cr, uid, mail_template_id[1], partner_to_email.id, context=ctx)
if partner not in partners_to_email:
self.message_post(cr, uid, [partner.id], body=_('Overdue email sent to %s' % ', '.join(['%s <%s>' % (partner.name, partner.email) for partner in partners_to_email])), context=context)
else:
unknown_mails = unknown_mails + 1
action_text = _("Email not sent because of email address of partner not filled in")
if partner.payment_next_action_date:
payment_action_date = min(fields.date.context_today(self, cr, uid, context=ctx), partner.payment_next_action_date)
else:
payment_action_date = fields.date.context_today(self, cr, uid, context=ctx)
if partner.payment_next_action:
payment_next_action = partner.payment_next_action + " \n " + action_text
else:
payment_next_action = action_text
self.write(cr, uid, [partner.id], {'payment_next_action_date': payment_action_date,
'payment_next_action': payment_next_action}, context=ctx)
return unknown_mails
def get_followup_table_html(self, cr, uid, ids, context=None):
""" Build the html tables to be included in emails send to partners,
when reminding them their overdue invoices.
:param ids: [id] of the partner for whom we are building the tables
:rtype: string
"""
from report import account_followup_print
assert len(ids) == 1
if context is None:
context = {}
partner = self.browse(cr, uid, ids[0], context=context).commercial_partner_id
#copy the context to not change global context. Overwrite it because _() looks for the lang in local variable 'context'.
#Set the language to use = the partner language
context = dict(context, lang=partner.lang)
followup_table = ''
if partner.unreconciled_aml_ids:
company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id
current_date = fields.date.context_today(self, cr, uid, context=context)
rml_parse = account_followup_print.report_rappel(cr, uid, "followup_rml_parser")
final_res = rml_parse._lines_get_with_partner(partner, company.id)
for currency_dict in final_res:
currency = currency_dict.get('line', [{'currency_id': company.currency_id}])[0]['currency_id']
followup_table += '''
<table border="2" width=100%%>
<tr>
<td>''' + _("Invoice Date") + '''</td>
<td>''' + _("Description") + '''</td>
<td>''' + _("Reference") + '''</td>
<td>''' + _("Due Date") + '''</td>
<td>''' + _("Amount") + " (%s)" % (currency.symbol) + '''</td>
<td>''' + _("Lit.") + '''</td>
</tr>
'''
total = 0
for aml in currency_dict['line']:
block = aml['blocked'] and 'X' or ' '
total += aml['balance']
strbegin = "<TD>"
strend = "</TD>"
date = aml['date_maturity'] or aml['date']
if date <= current_date and aml['balance'] > 0:
strbegin = "<TD><B>"
strend = "</B></TD>"
followup_table +="<TR>" + strbegin + str(aml['date']) + strend + strbegin + aml['name'] + strend + strbegin + (aml['ref'] or '') + strend + strbegin + str(date) + strend + strbegin + str(aml['balance']) + strend + strbegin + block + strend + "</TR>"
total = reduce(lambda x, y: x+y['balance'], currency_dict['line'], 0.00)
total = rml_parse.formatLang(total, dp='Account', currency_obj=currency)
followup_table += '''<tr> </tr>
</table>
<center>''' + _("Amount due") + ''' : %s </center>''' % (total)
return followup_table
def write(self, cr, uid, ids, vals, context=None):
if vals.get("payment_responsible_id", False):
for part in self.browse(cr, uid, ids, context=context):
if part.payment_responsible_id <> vals["payment_responsible_id"]:
#Find partner_id of user put as responsible
responsible_partner_id = self.pool.get("res.users").browse(cr, uid, vals['payment_responsible_id'], context=context).partner_id.id
self.pool.get("mail.thread").message_post(cr, uid, 0,
body = _("You became responsible to do the next action for the payment follow-up of") + " <b><a href='#id=" + str(part.id) + "&view_type=form&model=res.partner'> " + part.name + " </a></b>",
type = 'comment',
subtype = "mail.mt_comment", context = context,
model = 'res.partner', res_id = part.id,
partner_ids = [responsible_partner_id])
return super(res_partner, self).write(cr, uid, ids, vals, context=context)
def action_done(self, cr, uid, ids, context=None):
return self.write(cr, uid, ids, {'payment_next_action_date': False, 'payment_next_action':'', 'payment_responsible_id': False}, context=context)
def do_button_print(self, cr, uid, ids, context=None):
assert(len(ids) == 1)
company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
#search if the partner has accounting entries to print. If not, it may not be present in the
#psql view the report is based on, so we need to stop the user here.
if not self.pool.get('account.move.line').search(cr, uid, [
('partner_id', '=', ids[0]),
('account_id.type', '=', 'receivable'),
('reconcile_id', '=', False),
('state', '!=', 'draft'),
('company_id', '=', company_id),
'|', ('date_maturity', '=', False), ('date_maturity', '<=', fields.date.context_today(self, cr, uid)),
], context=context):
raise osv.except_osv(_('Error!'),_("The partner does not have any accounting entries to print in the overdue report for the current company."))
self.message_post(cr, uid, [ids[0]], body=_('Printed overdue payments report'), context=context)
#build the id of this partner in the psql view. Could be replaced by a search with [('company_id', '=', company_id),('partner_id', '=', ids[0])]
wizard_partner_ids = [ids[0] * 10000 + company_id]
followup_ids = self.pool.get('account_followup.followup').search(cr, uid, [('company_id', '=', company_id)], context=context)
if not followup_ids:
raise osv.except_osv(_('Error!'),_("There is no followup plan defined for the current company."))
data = {
'date': fields.date.today(),
'followup_id': followup_ids[0],
}
#call the print overdue report on this partner
return self.do_partner_print(cr, uid, wizard_partner_ids, data, context=context)
def _get_amounts_and_date(self, cr, uid, ids, name, arg, context=None):
'''
Function that computes values for the followup functional fields. Note that 'payment_amount_due'
is similar to 'credit' field on res.partner except it filters on user's company.
'''
res = {}
company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id
current_date = fields.date.context_today(self, cr, uid, context=context)
for partner in self.browse(cr, uid, ids, context=context):
worst_due_date = False
amount_due = amount_overdue = 0.0
for aml in partner.unreconciled_aml_ids:
if (aml.company_id == company):
date_maturity = aml.date_maturity or aml.date
if not worst_due_date or date_maturity < worst_due_date:
worst_due_date = date_maturity
amount_due += aml.result
if (date_maturity <= current_date):
amount_overdue += aml.result
res[partner.id] = {'payment_amount_due': amount_due,
'payment_amount_overdue': amount_overdue,
'payment_earliest_due_date': worst_due_date}
return res
def _get_followup_overdue_query(self, cr, uid, args, overdue_only=False, context=None):
'''
This function is used to build the query and arguments to use when making a search on functional fields
* payment_amount_due
* payment_amount_overdue
Basically, the query is exactly the same except that for overdue there is an extra clause in the WHERE.
:param args: arguments given to the search in the usual domain notation (list of tuples)
:param overdue_only: option to add the extra argument to filter on overdue accounting entries or not
:returns: a tuple with
* the query to execute as first element
* the arguments for the execution of this query
:rtype: (string, [])
'''
company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
having_where_clause = ' AND '.join(map(lambda x: '(SUM(bal2) %s %%s)' % (x[1]), args))
having_values = [x[2] for x in args]
query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
overdue_only_str = overdue_only and 'AND date_maturity <= NOW()' or ''
return ('''SELECT pid AS partner_id, SUM(bal2) FROM
(SELECT CASE WHEN bal IS NOT NULL THEN bal
ELSE 0.0 END AS bal2, p.id as pid FROM
(SELECT (debit-credit) AS bal, partner_id
FROM account_move_line l
WHERE account_id IN
(SELECT id FROM account_account
WHERE type=\'receivable\' AND active)
''' + overdue_only_str + '''
AND reconcile_id IS NULL
AND company_id = %s
AND ''' + query + ''') AS l
RIGHT JOIN res_partner p
ON p.id = partner_id ) AS pl
GROUP BY pid HAVING ''' + having_where_clause, [company_id] + having_values)
def _payment_overdue_search(self, cr, uid, obj, name, args, context=None):
if not args:
return []
query, query_args = self._get_followup_overdue_query(cr, uid, args, overdue_only=True, context=context)
cr.execute(query, query_args)
res = cr.fetchall()
if not res:
return [('id','=','0')]
return [('id','in', [x[0] for x in res])]
def _payment_earliest_date_search(self, cr, uid, obj, name, args, context=None):
if not args:
return []
company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
having_where_clause = ' AND '.join(map(lambda x: '(MIN(l.date_maturity) %s %%s)' % (x[1]), args))
having_values = [x[2] for x in args]
query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
cr.execute('SELECT partner_id FROM account_move_line l '\
'WHERE account_id IN '\
'(SELECT id FROM account_account '\
'WHERE type=\'receivable\' AND active) '\
'AND l.company_id = %s '
'AND reconcile_id IS NULL '\
'AND '+query+' '\
'AND partner_id IS NOT NULL '\
'GROUP BY partner_id HAVING '+ having_where_clause,
[company_id] + having_values)
res = cr.fetchall()
if not res:
return [('id','=','0')]
return [('id','in', [x[0] for x in res])]
def _payment_due_search(self, cr, uid, obj, name, args, context=None):
if not args:
return []
query, query_args = self._get_followup_overdue_query(cr, uid, args, overdue_only=False, context=context)
cr.execute(query, query_args)
res = cr.fetchall()
if not res:
return [('id','=','0')]
return [('id','in', [x[0] for x in res])]
def _get_partners(self, cr, uid, ids, context=None):
#this function search for the partners linked to all account.move.line 'ids' that have been changed
partners = set()
for aml in self.browse(cr, uid, ids, context=context):
if aml.partner_id:
partners.add(aml.partner_id.id)
return list(partners)
_inherit = "res.partner"
_columns = {
'payment_responsible_id':fields.many2one('res.users', ondelete='set null', string='Follow-up Responsible',
help="Optionally you can assign a user to this field, which will make him responsible for the action.",
track_visibility="onchange", copy=False),
'payment_note':fields.text('Customer Payment Promise', help="Payment Note", track_visibility="onchange", copy=False),
'payment_next_action':fields.text('Next Action', copy=False,
help="This is the next action to be taken. It will automatically be set when the partner gets a follow-up level that requires a manual action. ",
track_visibility="onchange"),
'payment_next_action_date': fields.date('Next Action Date', copy=False,
help="This is when the manual follow-up is needed. "
"The date will be set to the current date when the partner "
"gets a follow-up level that requires a manual action. "
"Can be practical to set manually e.g. to see if he keeps "
"his promises."),
'unreconciled_aml_ids':fields.one2many('account.move.line', 'partner_id', domain=['&', ('reconcile_id', '=', False), '&',
('account_id.active','=', True), '&', ('account_id.type', '=', 'receivable'), ('state', '!=', 'draft')]),
'latest_followup_date':fields.function(_get_latest, method=True, type='date', string="Latest Follow-up Date",
help="Latest date that the follow-up level of the partner was changed",
store=False, multi="latest"),
'latest_followup_level_id':fields.function(_get_latest, method=True,
type='many2one', relation='account_followup.followup.line', string="Latest Follow-up Level",
help="The maximum follow-up level",
store={
'res.partner': (lambda self, cr, uid, ids, c: ids,[],10),
'account.move.line': (_get_partners, ['followup_line_id'], 10),
},
multi="latest"),
'latest_followup_level_id_without_lit':fields.function(_get_latest, method=True,
type='many2one', relation='account_followup.followup.line', string="Latest Follow-up Level without litigation",
help="The maximum follow-up level without taking into account the account move lines with litigation",
store={
'res.partner': (lambda self, cr, uid, ids, c: ids,[],10),
'account.move.line': (_get_partners, ['followup_line_id'], 10),
},
multi="latest"),
'payment_amount_due':fields.function(_get_amounts_and_date,
type='float', string="Amount Due",
store = False, multi="followup",
fnct_search=_payment_due_search),
'payment_amount_overdue':fields.function(_get_amounts_and_date,
type='float', string="Amount Overdue",
store = False, multi="followup",
fnct_search = _payment_overdue_search),
'payment_earliest_due_date':fields.function(_get_amounts_and_date,
type='date',
string = "Worst Due Date",
multi="followup",
fnct_search=_payment_earliest_date_search),
}
class account_config_settings(osv.TransientModel):
_name = 'account.config.settings'
_inherit = 'account.config.settings'
def open_followup_level_form(self, cr, uid, ids, context=None):
res_ids = self.pool.get('account_followup.followup').search(cr, uid, [], context=context)
return {
'type': 'ir.actions.act_window',
'name': 'Payment Follow-ups',
'res_model': 'account_followup.followup',
'res_id': res_ids and res_ids[0] or False,
'view_mode': 'form,tree',
}
# 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,
492,
2986,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
504,
14490,
492,
7559,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
199,
533,
2035,
384,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
283,
2048,
63,
25872,
14,
25872,
7,
272,
485,
1802,
275,
283,
6009,
21876,
13,
384,
7,
272,
485,
2761,
63,
354,
275,
283,
354,
7,
272,
485,
3406,
275,
469,
267,
283,
25872,
63,
604,
356,
1504,
14,
368,
18,
3479,
360,
2048,
63,
25872,
14,
25872,
14,
604,
297,
283,
25872,
63,
344,
297,
283,
18696,
13,
384,
297,
1331,
29,
549,
395,
267,
283,
4627,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
4627,
297,
283,
16063,
297,
1415,
29,
549,
395,
267,
283,
354,
356,
1504,
14,
2407,
360,
4627,
63,
344,
297,
283,
354,
297,
1059,
275,
298,
985,
401,
6863,
29,
549,
12,
730,
628,
1560,
1288,
272,
789,
272,
485,
4322,
275,
469,
267,
283,
4627,
63,
344,
356,
2400,
308,
12,
2467,
12,
1747,
12,
286,
26,
308,
14,
2293,
14,
362,
360,
470,
14,
4627,
31238,
4627,
63,
885,
63,
362,
8,
1556,
12,
1747,
12,
283,
2048,
63,
25872,
14,
25872,
297,
1067,
29,
67,
395,
272,
789,
272,
485,
3009,
63,
9882,
275,
4274,
4627,
63,
22484,
297,
283,
3235,
8,
4627,
63,
344,
3196,
283,
5903,
1373,
2035,
13,
384,
1126,
7233,
365,
4370,
5440,
221,
421,
199,
533,
2035,
384,
63,
604,
8,
4795,
14,
4795,
304,
339,
347,
485,
362,
63,
885,
63,
1160,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
862,
26,
288,
372,
291,
14,
2293,
14,
362,
360,
723,
14,
1238,
14,
576,
1959,
362,
63,
785,
63,
4443,
8,
1556,
12,
1747,
12,
283,
2048,
63,
25872,
297,
283,
2123,
63,
1160,
63,
2048,
63,
25872,
63,
885,
5832,
17,
61,
267,
871,
1722,
26,
288,
372,
756,
339,
485,
354,
275,
283,
2048,
63,
25872,
14,
25872,
14,
604,
7,
272,
485,
1802,
275,
283,
18696,
13,
384,
445,
7527,
65,
7,
272,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
18696,
13,
1721,
10033,
297,
1415,
29,
549,
395,
267,
283,
4041,
356,
1504,
14,
4115,
360,
5826,
297,
1720,
628,
39,
7602,
314,
3414,
1865,
1380,
20589,
282,
769,
402,
2035,
13,
384,
2385,
7651,
267,
283,
5814,
356,
1504,
14,
4115,
360,
36,
310,
577,
5758,
297,
1720,
628,
1918,
1329,
402,
7609,
2410,
314,
7037,
1434,
402,
314,
8485,
370,
3618,
2544,
10209,
314,
295,
24820,
14,
221,
18615,
506,
6946,
340,
1265,
2934,
370,
3222,
282,
1115,
5333,
10459,
2544,
6868,
4765,
1415,
29,
549,
395,
267,
283,
25872,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
2048,
63,
25872,
14,
25872,
297,
283,
18696,
738,
1190,
297,
1415,
29,
549,
12,
16549,
628,
15377,
1288,
267,
283,
1802,
356,
1504,
14,
505,
360,
9779,
9082,
6430,
297,
9028,
29,
549,
395,
267,
283,
2254,
63,
2123,
356,
955,
14,
4871,
360,
6795,
376,
11426,
297,
1720,
628,
11423,
6661,
12,
652,
911,
3222,
376,
3031,
1288,
267,
283,
2254,
63,
9269,
356,
955,
14,
4871,
360,
6795,
282,
12230,
351,
297,
1720,
628,
11423,
6661,
12,
652,
911,
870,
282,
8082,
1288,
267,
283,
9285,
63,
1287,
356,
955,
14,
4871,
360,
22382,
10033,
297,
1720,
628,
11423,
6661,
12,
652,
911,
663,
314,
8722,
1595,
370,
506,
9394,
367,
626,
15229,
14,
26261,
267,
283,
9285,
63,
1287,
63,
4610,
356,
955,
14,
505,
360,
3310,
4005,
4226,
297,
10069,
628,
69,
14,
71,
14,
25495,
282,
14617,
1240,
12,
1104,
543,
11789,
2360,
2263,
1288,
267,
283,
9285,
63,
1287,
63,
3853,
1164,
63,
344,
356,
955,
14,
3479,
18,
368,
360,
470,
14,
3707,
297,
283,
9595,
282,
3591,
678,
1164,
297,
16549,
534,
409,
2973,
659,
267,
283,
2123,
63,
1160,
63,
344,
356,
955,
14,
3479,
18,
368,
360,
2123,
14,
1160,
297,
283,
7035,
5458,
297,
16549,
534,
409,
2973,
659,
272,
789,
272,
485,
1648,
275,
283,
5814,
7,
272,
485,
3009,
63,
9882,
275,
4274,
4899,
63,
22484,
297,
283,
3235,
8,
25872,
63,
344,
12,
7339,
3196,
283,
25589,
402,
314,
2035,
13,
384,
11106,
1471,
506,
3365,
5440,
272,
485,
4322,
275,
469,
267,
283,
2254,
63,
2123,
356,
715,
12,
267,
283,
2254,
63,
9269,
356,
715,
12,
267,
283,
9285,
63,
1287,
356,
797,
12,
267,
283,
1802,
356,
408,
267,
1487,
285,
2818,
3899,
63,
354,
9,
83,
12,
199,
199,
1726,
6326,
340,
2337,
1990,
282,
27572,
1728,
402,
4154,
83,
12,
652,
12237,
626,
314,
2569,
5982,
2612,
588,
625,
16555,
14,
7754,
12,
5452,
5827,
17616,
1482,
315,
1865,
370,
25176,
734,
642,
11628,
315,
314,
2163,
1695,
7609,
14,
199,
199,
55,
3857,
2195,
11628,
1172
] |
[
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,
492,
2986,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
504,
14490,
492,
7559,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
199,
533,
2035,
384,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
283,
2048,
63,
25872,
14,
25872,
7,
272,
485,
1802,
275,
283,
6009,
21876,
13,
384,
7,
272,
485,
2761,
63,
354,
275,
283,
354,
7,
272,
485,
3406,
275,
469,
267,
283,
25872,
63,
604,
356,
1504,
14,
368,
18,
3479,
360,
2048,
63,
25872,
14,
25872,
14,
604,
297,
283,
25872,
63,
344,
297,
283,
18696,
13,
384,
297,
1331,
29,
549,
395,
267,
283,
4627,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
4627,
297,
283,
16063,
297,
1415,
29,
549,
395,
267,
283,
354,
356,
1504,
14,
2407,
360,
4627,
63,
344,
297,
283,
354,
297,
1059,
275,
298,
985,
401,
6863,
29,
549,
12,
730,
628,
1560,
1288,
272,
789,
272,
485,
4322,
275,
469,
267,
283,
4627,
63,
344,
356,
2400,
308,
12,
2467,
12,
1747,
12,
286,
26,
308,
14,
2293,
14,
362,
360,
470,
14,
4627,
31238,
4627,
63,
885,
63,
362,
8,
1556,
12,
1747,
12,
283,
2048,
63,
25872,
14,
25872,
297,
1067,
29,
67,
395,
272,
789,
272,
485,
3009,
63,
9882,
275,
4274,
4627,
63,
22484,
297,
283,
3235,
8,
4627,
63,
344,
3196,
283,
5903,
1373,
2035,
13,
384,
1126,
7233,
365,
4370,
5440,
221,
421,
199,
533,
2035,
384,
63,
604,
8,
4795,
14,
4795,
304,
339,
347,
485,
362,
63,
885,
63,
1160,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
862,
26,
288,
372,
291,
14,
2293,
14,
362,
360,
723,
14,
1238,
14,
576,
1959,
362,
63,
785,
63,
4443,
8,
1556,
12,
1747,
12,
283,
2048,
63,
25872,
297,
283,
2123,
63,
1160,
63,
2048,
63,
25872,
63,
885,
5832,
17,
61,
267,
871,
1722,
26,
288,
372,
756,
339,
485,
354,
275,
283,
2048,
63,
25872,
14,
25872,
14,
604,
7,
272,
485,
1802,
275,
283,
18696,
13,
384,
445,
7527,
65,
7,
272,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
18696,
13,
1721,
10033,
297,
1415,
29,
549,
395,
267,
283,
4041,
356,
1504,
14,
4115,
360,
5826,
297,
1720,
628,
39,
7602,
314,
3414,
1865,
1380,
20589,
282,
769,
402,
2035,
13,
384,
2385,
7651,
267,
283,
5814,
356,
1504,
14,
4115,
360,
36,
310,
577,
5758,
297,
1720,
628,
1918,
1329,
402,
7609,
2410,
314,
7037,
1434,
402,
314,
8485,
370,
3618,
2544,
10209,
314,
295,
24820,
14,
221,
18615,
506,
6946,
340,
1265,
2934,
370,
3222,
282,
1115,
5333,
10459,
2544,
6868,
4765,
1415,
29,
549,
395,
267,
283,
25872,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
2048,
63,
25872,
14,
25872,
297,
283,
18696,
738,
1190,
297,
1415,
29,
549,
12,
16549,
628,
15377,
1288,
267,
283,
1802,
356,
1504,
14,
505,
360,
9779,
9082,
6430,
297,
9028,
29,
549,
395,
267,
283,
2254,
63,
2123,
356,
955,
14,
4871,
360,
6795,
376,
11426,
297,
1720,
628,
11423,
6661,
12,
652,
911,
3222,
376,
3031,
1288,
267,
283,
2254,
63,
9269,
356,
955,
14,
4871,
360,
6795,
282,
12230,
351,
297,
1720,
628,
11423,
6661,
12,
652,
911,
870,
282,
8082,
1288,
267,
283,
9285,
63,
1287,
356,
955,
14,
4871,
360,
22382,
10033,
297,
1720,
628,
11423,
6661,
12,
652,
911,
663,
314,
8722,
1595,
370,
506,
9394,
367,
626,
15229,
14,
26261,
267,
283,
9285,
63,
1287,
63,
4610,
356,
955,
14,
505,
360,
3310,
4005,
4226,
297,
10069,
628,
69,
14,
71,
14,
25495,
282,
14617,
1240,
12,
1104,
543,
11789,
2360,
2263,
1288,
267,
283,
9285,
63,
1287,
63,
3853,
1164,
63,
344,
356,
955,
14,
3479,
18,
368,
360,
470,
14,
3707,
297,
283,
9595,
282,
3591,
678,
1164,
297,
16549,
534,
409,
2973,
659,
267,
283,
2123,
63,
1160,
63,
344,
356,
955,
14,
3479,
18,
368,
360,
2123,
14,
1160,
297,
283,
7035,
5458,
297,
16549,
534,
409,
2973,
659,
272,
789,
272,
485,
1648,
275,
283,
5814,
7,
272,
485,
3009,
63,
9882,
275,
4274,
4899,
63,
22484,
297,
283,
3235,
8,
25872,
63,
344,
12,
7339,
3196,
283,
25589,
402,
314,
2035,
13,
384,
11106,
1471,
506,
3365,
5440,
272,
485,
4322,
275,
469,
267,
283,
2254,
63,
2123,
356,
715,
12,
267,
283,
2254,
63,
9269,
356,
715,
12,
267,
283,
9285,
63,
1287,
356,
797,
12,
267,
283,
1802,
356,
408,
267,
1487,
285,
2818,
3899,
63,
354,
9,
83,
12,
199,
199,
1726,
6326,
340,
2337,
1990,
282,
27572,
1728,
402,
4154,
83,
12,
652,
12237,
626,
314,
2569,
5982,
2612,
588,
625,
16555,
14,
7754,
12,
5452,
5827,
17616,
1482,
315,
1865,
370,
25176,
734,
642,
11628,
315,
314,
2163,
1695,
7609,
14,
199,
199,
55,
3857,
2195,
11628,
1172,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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py
|
321
|
13786
|
# Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
# Pgen imports
from . import grammar, token, tokenize
class PgenGrammar(grammar.Grammar):
pass
class ParserGenerator(object):
def __init__(self, filename, stream=None):
close_stream = None
if stream is None:
stream = open(filename)
close_stream = stream.close
self.filename = filename
self.stream = stream
self.generator = tokenize.generate_tokens(stream.readline)
self.gettoken() # Initialize lookahead
self.dfas, self.startsymbol = self.parse()
if close_stream is not None:
close_stream()
self.first = {} # map from symbol name to set of tokens
self.addfirstsets()
def make_grammar(self):
c = PgenGrammar()
names = self.dfas.keys()
names.sort()
names.remove(self.startsymbol)
names.insert(0, self.startsymbol)
for name in names:
i = 256 + len(c.symbol2number)
c.symbol2number[name] = i
c.number2symbol[i] = name
for name in names:
dfa = self.dfas[name]
states = []
for state in dfa:
arcs = []
for label, next in state.arcs.iteritems():
arcs.append((self.make_label(c, label), dfa.index(next)))
if state.isfinal:
arcs.append((0, dfa.index(state)))
states.append(arcs)
c.states.append(states)
c.dfas[c.symbol2number[name]] = (states, self.make_first(c, name))
c.start = c.symbol2number[self.startsymbol]
return c
def make_first(self, c, name):
rawfirst = self.first[name]
first = {}
for label in rawfirst:
ilabel = self.make_label(c, label)
##assert ilabel not in first # XXX failed on <> ... !=
first[ilabel] = 1
return first
def make_label(self, c, label):
# XXX Maybe this should be a method on a subclass of converter?
ilabel = len(c.labels)
if label[0].isalpha():
# Either a symbol name or a named token
if label in c.symbol2number:
# A symbol name (a non-terminal)
if label in c.symbol2label:
return c.symbol2label[label]
else:
c.labels.append((c.symbol2number[label], None))
c.symbol2label[label] = ilabel
return ilabel
else:
# A named token (NAME, NUMBER, STRING)
itoken = getattr(token, label, None)
assert isinstance(itoken, int), label
assert itoken in token.tok_name, label
if itoken in c.tokens:
return c.tokens[itoken]
else:
c.labels.append((itoken, None))
c.tokens[itoken] = ilabel
return ilabel
else:
# Either a keyword or an operator
assert label[0] in ('"', "'"), label
value = eval(label)
if value[0].isalpha():
# A keyword
if value in c.keywords:
return c.keywords[value]
else:
c.labels.append((token.NAME, value))
c.keywords[value] = ilabel
return ilabel
else:
# An operator (any non-numeric token)
itoken = grammar.opmap[value] # Fails if unknown token
if itoken in c.tokens:
return c.tokens[itoken]
else:
c.labels.append((itoken, None))
c.tokens[itoken] = ilabel
return ilabel
def addfirstsets(self):
names = self.dfas.keys()
names.sort()
for name in names:
if name not in self.first:
self.calcfirst(name)
#print name, self.first[name].keys()
def calcfirst(self, name):
dfa = self.dfas[name]
self.first[name] = None # dummy to detect left recursion
state = dfa[0]
totalset = {}
overlapcheck = {}
for label, next in state.arcs.iteritems():
if label in self.dfas:
if label in self.first:
fset = self.first[label]
if fset is None:
raise ValueError("recursion for rule %r" % name)
else:
self.calcfirst(label)
fset = self.first[label]
totalset.update(fset)
overlapcheck[label] = fset
else:
totalset[label] = 1
overlapcheck[label] = {label: 1}
inverse = {}
for label, itsfirst in overlapcheck.iteritems():
for symbol in itsfirst:
if symbol in inverse:
raise ValueError("rule %s is ambiguous; %s is in the"
" first sets of %s as well as %s" %
(name, symbol, label, inverse[symbol]))
inverse[symbol] = label
self.first[name] = totalset
def parse(self):
dfas = {}
startsymbol = None
# MSTART: (NEWLINE | RULE)* ENDMARKER
while self.type != token.ENDMARKER:
while self.type == token.NEWLINE:
self.gettoken()
# RULE: NAME ':' RHS NEWLINE
name = self.expect(token.NAME)
self.expect(token.OP, ":")
a, z = self.parse_rhs()
self.expect(token.NEWLINE)
#self.dump_nfa(name, a, z)
dfa = self.make_dfa(a, z)
#self.dump_dfa(name, dfa)
oldlen = len(dfa)
self.simplify_dfa(dfa)
newlen = len(dfa)
dfas[name] = dfa
#print name, oldlen, newlen
if startsymbol is None:
startsymbol = name
return dfas, startsymbol
def make_dfa(self, start, finish):
# To turn an NFA into a DFA, we define the states of the DFA
# to correspond to *sets* of states of the NFA. Then do some
# state reduction. Let's represent sets as dicts with 1 for
# values.
assert isinstance(start, NFAState)
assert isinstance(finish, NFAState)
def closure(state):
base = {}
addclosure(state, base)
return base
def addclosure(state, base):
assert isinstance(state, NFAState)
if state in base:
return
base[state] = 1
for label, next in state.arcs:
if label is None:
addclosure(next, base)
states = [DFAState(closure(start), finish)]
for state in states: # NB states grows while we're iterating
arcs = {}
for nfastate in state.nfaset:
for label, next in nfastate.arcs:
if label is not None:
addclosure(next, arcs.setdefault(label, {}))
for label, nfaset in arcs.iteritems():
for st in states:
if st.nfaset == nfaset:
break
else:
st = DFAState(nfaset, finish)
states.append(st)
state.addarc(st, label)
return states # List of DFAState instances; first one is start
def dump_nfa(self, name, start, finish):
print "Dump of NFA for", name
todo = [start]
for i, state in enumerate(todo):
print " State", i, state is finish and "(final)" or ""
for label, next in state.arcs:
if next in todo:
j = todo.index(next)
else:
j = len(todo)
todo.append(next)
if label is None:
print " -> %d" % j
else:
print " %s -> %d" % (label, j)
def dump_dfa(self, name, dfa):
print "Dump of DFA for", name
for i, state in enumerate(dfa):
print " State", i, state.isfinal and "(final)" or ""
for label, next in state.arcs.iteritems():
print " %s -> %d" % (label, dfa.index(next))
def simplify_dfa(self, dfa):
# This is not theoretically optimal, but works well enough.
# Algorithm: repeatedly look for two states that have the same
# set of arcs (same labels pointing to the same nodes) and
# unify them, until things stop changing.
# dfa is a list of DFAState instances
changes = True
while changes:
changes = False
for i, state_i in enumerate(dfa):
for j in range(i+1, len(dfa)):
state_j = dfa[j]
if state_i == state_j:
#print " unify", i, j
del dfa[j]
for state in dfa:
state.unifystate(state_j, state_i)
changes = True
break
def parse_rhs(self):
# RHS: ALT ('|' ALT)*
a, z = self.parse_alt()
if self.value != "|":
return a, z
else:
aa = NFAState()
zz = NFAState()
aa.addarc(a)
z.addarc(zz)
while self.value == "|":
self.gettoken()
a, z = self.parse_alt()
aa.addarc(a)
z.addarc(zz)
return aa, zz
def parse_alt(self):
# ALT: ITEM+
a, b = self.parse_item()
while (self.value in ("(", "[") or
self.type in (token.NAME, token.STRING)):
c, d = self.parse_item()
b.addarc(c)
b = d
return a, b
def parse_item(self):
# ITEM: '[' RHS ']' | ATOM ['+' | '*']
if self.value == "[":
self.gettoken()
a, z = self.parse_rhs()
self.expect(token.OP, "]")
a.addarc(z)
return a, z
else:
a, z = self.parse_atom()
value = self.value
if value not in ("+", "*"):
return a, z
self.gettoken()
z.addarc(a)
if value == "+":
return a, z
else:
return a, a
def parse_atom(self):
# ATOM: '(' RHS ')' | NAME | STRING
if self.value == "(":
self.gettoken()
a, z = self.parse_rhs()
self.expect(token.OP, ")")
return a, z
elif self.type in (token.NAME, token.STRING):
a = NFAState()
z = NFAState()
a.addarc(z, self.value)
self.gettoken()
return a, z
else:
self.raise_error("expected (...) or NAME or STRING, got %s/%s",
self.type, self.value)
def expect(self, type, value=None):
if self.type != type or (value is not None and self.value != value):
self.raise_error("expected %s/%s, got %s/%s",
type, value, self.type, self.value)
value = self.value
self.gettoken()
return value
def gettoken(self):
tup = self.generator.next()
while tup[0] in (tokenize.COMMENT, tokenize.NL):
tup = self.generator.next()
self.type, self.value, self.begin, self.end, self.line = tup
#print token.tok_name[self.type], repr(self.value)
def raise_error(self, msg, *args):
if args:
try:
msg = msg % args
except:
msg = " ".join([msg] + map(str, args))
raise SyntaxError(msg, (self.filename, self.end[0],
self.end[1], self.line))
class NFAState(object):
def __init__(self):
self.arcs = [] # list of (label, NFAState) pairs
def addarc(self, next, label=None):
assert label is None or isinstance(label, str)
assert isinstance(next, NFAState)
self.arcs.append((label, next))
class DFAState(object):
def __init__(self, nfaset, final):
assert isinstance(nfaset, dict)
assert isinstance(iter(nfaset).next(), NFAState)
assert isinstance(final, NFAState)
self.nfaset = nfaset
self.isfinal = final in nfaset
self.arcs = {} # map from label to DFAState
def addarc(self, next, label):
assert isinstance(label, str)
assert label not in self.arcs
assert isinstance(next, DFAState)
self.arcs[label] = next
def unifystate(self, old, new):
for label, next in self.arcs.iteritems():
if next is old:
self.arcs[label] = new
def __eq__(self, other):
# Equality test -- ignore the nfaset instance variable
assert isinstance(other, DFAState)
if self.isfinal != other.isfinal:
return False
# Can't just return self.arcs == other.arcs, because that
# would invoke this method recursively, with cycles...
if len(self.arcs) != len(other.arcs):
return False
for label, next in self.arcs.iteritems():
if next is not other.arcs.get(label):
return False
return True
__hash__ = None # For Py3 compatibility.
def generate_grammar(filename="Grammar.txt"):
p = ParserGenerator(filename)
return p.make_grammar()
|
gpl-3.0
|
[
3,
1898,
8353,
13,
9397,
6566,
279,
13863,
12,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
3,
510,
2268,
8925,
199,
504,
1275,
492,
12528,
12,
1526,
12,
13343,
199,
199,
533,
510,
2268,
27119,
8,
15239,
14,
27119,
304,
272,
986,
199,
199,
533,
10191,
7599,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
2547,
29,
403,
304,
267,
4002,
63,
1745,
275,
488,
267,
340,
2547,
365,
488,
26,
288,
2547,
275,
1551,
8,
1501,
9,
288,
4002,
63,
1745,
275,
2547,
14,
1600,
267,
291,
14,
1501,
275,
1788,
267,
291,
14,
1745,
275,
2547,
267,
291,
14,
4679,
275,
13343,
14,
4208,
63,
4504,
8,
1745,
14,
6407,
9,
267,
291,
14,
362,
1418,
342,
327,
11578,
16076,
267,
291,
14,
1587,
305,
12,
291,
14,
928,
5155,
275,
291,
14,
1122,
342,
267,
340,
4002,
63,
1745,
365,
440,
488,
26,
288,
4002,
63,
1745,
342,
267,
291,
14,
2246,
275,
1052,
327,
2341,
687,
5272,
536,
370,
663,
402,
4645,
267,
291,
14,
525,
2246,
2193,
342,
339,
347,
1852,
63,
15239,
8,
277,
304,
267,
286,
275,
510,
2268,
27119,
342,
267,
1561,
275,
291,
14,
1587,
305,
14,
1612,
342,
267,
1561,
14,
3191,
342,
267,
1561,
14,
2168,
8,
277,
14,
928,
5155,
9,
267,
1561,
14,
3176,
8,
16,
12,
291,
14,
928,
5155,
9,
267,
367,
536,
315,
1561,
26,
288,
284,
275,
7633,
435,
822,
8,
67,
14,
5155,
18,
1955,
9,
288,
286,
14,
5155,
18,
1955,
59,
354,
61,
275,
284,
288,
286,
14,
1955,
18,
5155,
59,
73,
61,
275,
536,
267,
367,
536,
315,
1561,
26,
288,
366,
667,
275,
291,
14,
1587,
305,
59,
354,
61,
288,
6363,
275,
942,
288,
367,
1174,
315,
366,
667,
26,
355,
601,
1259,
275,
942,
355,
367,
1768,
12,
2163,
315,
1174,
14,
20672,
14,
4611,
837,
490,
601,
1259,
14,
740,
1332,
277,
14,
1875,
63,
1302,
8,
67,
12,
1768,
395,
366,
667,
14,
1080,
8,
2184,
1724,
355,
340,
1174,
14,
374,
5094,
26,
490,
601,
1259,
14,
740,
1332,
16,
12,
366,
667,
14,
1080,
8,
929,
1724,
355,
6363,
14,
740,
8,
20672,
9,
288,
286,
14,
4981,
14,
740,
8,
4981,
9,
288,
286,
14,
1587,
305,
59,
67,
14,
5155,
18,
1955,
59,
354,
2677,
275,
334,
4981,
12,
291,
14,
1875,
63,
2246,
8,
67,
12,
536,
430,
267,
286,
14,
928,
275,
286,
14,
5155,
18,
1955,
59,
277,
14,
928,
5155,
61,
267,
372,
286,
339,
347,
1852,
63,
2246,
8,
277,
12,
286,
12,
536,
304,
267,
3066,
2246,
275,
291,
14,
2246,
59,
354,
61,
267,
1642,
275,
1052,
267,
367,
1768,
315,
3066,
2246,
26,
288,
284,
1302,
275,
291,
14,
1875,
63,
1302,
8,
67,
12,
1768,
9,
288,
925,
479,
284,
1302,
440,
315,
1642,
327,
5787,
3405,
641,
20941,
2263,
1137,
288,
1642,
59,
382,
902,
61,
275,
413,
267,
372,
1642,
339,
347,
1852,
63,
1302,
8,
277,
12,
286,
12,
1768,
304,
267,
327,
5787,
23038,
642,
1077,
506,
282,
1083,
641,
282,
5516,
402,
11109,
31,
267,
284,
1302,
275,
822,
8,
67,
14,
3512,
9,
267,
340,
1768,
59,
16,
1055,
374,
4468,
837,
288,
327,
13083,
282,
5272,
536,
503,
282,
4310,
1526,
288,
340,
1768,
315,
286,
14,
5155,
18,
1955,
26,
355,
327,
437,
5272,
536,
334,
65,
2222,
13,
12010,
9,
355,
340,
1768,
315,
286,
14,
5155,
18,
1302,
26,
490,
372,
286,
14,
5155,
18,
1302,
59,
1302,
61,
355,
587,
26,
490,
286,
14,
3512,
14,
740,
1332,
67,
14,
5155,
18,
1955,
59,
1302,
467,
488,
430,
490,
286,
14,
5155,
18,
1302,
59,
1302,
61,
275,
284,
1302,
490,
372,
284,
1302,
288,
587,
26,
355,
327,
437,
4310,
1526,
334,
2339,
12,
18122,
12,
18661,
9,
355,
284,
1418,
275,
2519,
8,
1418,
12,
1768,
12,
488,
9,
355,
702,
1228,
8,
390,
2858,
12,
1109,
395,
1768,
355,
702,
284,
1418,
315,
1526,
14,
9305,
63,
354,
12,
1768,
355,
340,
284,
1418,
315,
286,
14,
4504,
26,
490,
372,
286,
14,
4504,
59,
390,
2858,
61,
355,
587,
26,
490,
286,
14,
3512,
14,
740,
1332,
390,
2858,
12,
488,
430,
490,
286,
14,
4504,
59,
390,
2858,
61,
275,
284,
1302,
490,
372,
284,
1302,
267,
587,
26,
288,
327,
13083,
282,
4252,
503,
376,
4182,
288,
702,
1768,
59,
16,
61,
315,
661,
6949,
3546,
1288,
1768,
288,
574,
275,
3468,
8,
1302,
9,
288,
340,
574,
59,
16,
1055,
374,
4468,
837,
355,
327,
437,
4252,
355,
340,
574,
315,
286,
14,
7511,
26,
490,
372,
286,
14,
7511,
59,
585,
61,
355,
587,
26,
490,
286,
14,
3512,
14,
740,
1332,
1418,
14,
2339,
12,
574,
430,
490,
286,
14,
7511,
59,
585,
61,
275,
284,
1302,
490,
372,
284,
1302,
288,
587,
26,
355,
327,
1626,
4182,
334,
1629,
2222,
13,
6677,
1526,
9,
355,
284,
1418,
275,
12528,
14,
411,
1130,
59,
585,
61,
327,
12176,
83,
340,
5809,
1526,
355,
340,
284,
1418,
315,
286,
14,
4504,
26,
490,
372,
286,
14,
4504,
59,
390,
2858,
61,
355,
587,
26,
490,
286,
14,
3512,
14,
740,
1332,
390,
2858,
12,
488,
430,
490,
286,
14,
4504,
59,
390,
2858,
61,
275,
284,
1302,
490,
372,
284,
1302,
339,
347,
1050,
2246,
2193,
8,
277,
304,
267,
1561,
275,
291,
14,
1587,
305,
14,
1612,
342,
267,
1561,
14,
3191,
342,
267,
367,
536,
315,
1561,
26,
288,
340,
536,
440,
315,
291,
14,
2246,
26,
355,
291,
14,
8104,
2246,
8,
354,
9,
288,
327,
1361,
536,
12,
291,
14,
2246,
59,
354,
1055,
1612,
342,
339,
347,
12831,
2246,
8,
277,
12,
536,
304,
267,
366,
667,
275,
291,
14,
1587,
305,
59,
354,
61,
267,
291,
14,
2246,
59,
354,
61,
275,
488,
327,
7283,
370,
9696,
3602,
16189,
267,
1174,
275,
366,
667,
59,
16,
61,
267,
3141,
409,
275,
1052,
267,
15145,
1074,
275,
1052,
267,
367,
1768,
12,
2163,
315,
1174
] |
[
1898,
8353,
13,
9397,
6566,
279,
13863,
12,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
3,
510,
2268,
8925,
199,
504,
1275,
492,
12528,
12,
1526,
12,
13343,
199,
199,
533,
510,
2268,
27119,
8,
15239,
14,
27119,
304,
272,
986,
199,
199,
533,
10191,
7599,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
2547,
29,
403,
304,
267,
4002,
63,
1745,
275,
488,
267,
340,
2547,
365,
488,
26,
288,
2547,
275,
1551,
8,
1501,
9,
288,
4002,
63,
1745,
275,
2547,
14,
1600,
267,
291,
14,
1501,
275,
1788,
267,
291,
14,
1745,
275,
2547,
267,
291,
14,
4679,
275,
13343,
14,
4208,
63,
4504,
8,
1745,
14,
6407,
9,
267,
291,
14,
362,
1418,
342,
327,
11578,
16076,
267,
291,
14,
1587,
305,
12,
291,
14,
928,
5155,
275,
291,
14,
1122,
342,
267,
340,
4002,
63,
1745,
365,
440,
488,
26,
288,
4002,
63,
1745,
342,
267,
291,
14,
2246,
275,
1052,
327,
2341,
687,
5272,
536,
370,
663,
402,
4645,
267,
291,
14,
525,
2246,
2193,
342,
339,
347,
1852,
63,
15239,
8,
277,
304,
267,
286,
275,
510,
2268,
27119,
342,
267,
1561,
275,
291,
14,
1587,
305,
14,
1612,
342,
267,
1561,
14,
3191,
342,
267,
1561,
14,
2168,
8,
277,
14,
928,
5155,
9,
267,
1561,
14,
3176,
8,
16,
12,
291,
14,
928,
5155,
9,
267,
367,
536,
315,
1561,
26,
288,
284,
275,
7633,
435,
822,
8,
67,
14,
5155,
18,
1955,
9,
288,
286,
14,
5155,
18,
1955,
59,
354,
61,
275,
284,
288,
286,
14,
1955,
18,
5155,
59,
73,
61,
275,
536,
267,
367,
536,
315,
1561,
26,
288,
366,
667,
275,
291,
14,
1587,
305,
59,
354,
61,
288,
6363,
275,
942,
288,
367,
1174,
315,
366,
667,
26,
355,
601,
1259,
275,
942,
355,
367,
1768,
12,
2163,
315,
1174,
14,
20672,
14,
4611,
837,
490,
601,
1259,
14,
740,
1332,
277,
14,
1875,
63,
1302,
8,
67,
12,
1768,
395,
366,
667,
14,
1080,
8,
2184,
1724,
355,
340,
1174,
14,
374,
5094,
26,
490,
601,
1259,
14,
740,
1332,
16,
12,
366,
667,
14,
1080,
8,
929,
1724,
355,
6363,
14,
740,
8,
20672,
9,
288,
286,
14,
4981,
14,
740,
8,
4981,
9,
288,
286,
14,
1587,
305,
59,
67,
14,
5155,
18,
1955,
59,
354,
2677,
275,
334,
4981,
12,
291,
14,
1875,
63,
2246,
8,
67,
12,
536,
430,
267,
286,
14,
928,
275,
286,
14,
5155,
18,
1955,
59,
277,
14,
928,
5155,
61,
267,
372,
286,
339,
347,
1852,
63,
2246,
8,
277,
12,
286,
12,
536,
304,
267,
3066,
2246,
275,
291,
14,
2246,
59,
354,
61,
267,
1642,
275,
1052,
267,
367,
1768,
315,
3066,
2246,
26,
288,
284,
1302,
275,
291,
14,
1875,
63,
1302,
8,
67,
12,
1768,
9,
288,
925,
479,
284,
1302,
440,
315,
1642,
327,
5787,
3405,
641,
20941,
2263,
1137,
288,
1642,
59,
382,
902,
61,
275,
413,
267,
372,
1642,
339,
347,
1852,
63,
1302,
8,
277,
12,
286,
12,
1768,
304,
267,
327,
5787,
23038,
642,
1077,
506,
282,
1083,
641,
282,
5516,
402,
11109,
31,
267,
284,
1302,
275,
822,
8,
67,
14,
3512,
9,
267,
340,
1768,
59,
16,
1055,
374,
4468,
837,
288,
327,
13083,
282,
5272,
536,
503,
282,
4310,
1526,
288,
340,
1768,
315,
286,
14,
5155,
18,
1955,
26,
355,
327,
437,
5272,
536,
334,
65,
2222,
13,
12010,
9,
355,
340,
1768,
315,
286,
14,
5155,
18,
1302,
26,
490,
372,
286,
14,
5155,
18,
1302,
59,
1302,
61,
355,
587,
26,
490,
286,
14,
3512,
14,
740,
1332,
67,
14,
5155,
18,
1955,
59,
1302,
467,
488,
430,
490,
286,
14,
5155,
18,
1302,
59,
1302,
61,
275,
284,
1302,
490,
372,
284,
1302,
288,
587,
26,
355,
327,
437,
4310,
1526,
334,
2339,
12,
18122,
12,
18661,
9,
355,
284,
1418,
275,
2519,
8,
1418,
12,
1768,
12,
488,
9,
355,
702,
1228,
8,
390,
2858,
12,
1109,
395,
1768,
355,
702,
284,
1418,
315,
1526,
14,
9305,
63,
354,
12,
1768,
355,
340,
284,
1418,
315,
286,
14,
4504,
26,
490,
372,
286,
14,
4504,
59,
390,
2858,
61,
355,
587,
26,
490,
286,
14,
3512,
14,
740,
1332,
390,
2858,
12,
488,
430,
490,
286,
14,
4504,
59,
390,
2858,
61,
275,
284,
1302,
490,
372,
284,
1302,
267,
587,
26,
288,
327,
13083,
282,
4252,
503,
376,
4182,
288,
702,
1768,
59,
16,
61,
315,
661,
6949,
3546,
1288,
1768,
288,
574,
275,
3468,
8,
1302,
9,
288,
340,
574,
59,
16,
1055,
374,
4468,
837,
355,
327,
437,
4252,
355,
340,
574,
315,
286,
14,
7511,
26,
490,
372,
286,
14,
7511,
59,
585,
61,
355,
587,
26,
490,
286,
14,
3512,
14,
740,
1332,
1418,
14,
2339,
12,
574,
430,
490,
286,
14,
7511,
59,
585,
61,
275,
284,
1302,
490,
372,
284,
1302,
288,
587,
26,
355,
327,
1626,
4182,
334,
1629,
2222,
13,
6677,
1526,
9,
355,
284,
1418,
275,
12528,
14,
411,
1130,
59,
585,
61,
327,
12176,
83,
340,
5809,
1526,
355,
340,
284,
1418,
315,
286,
14,
4504,
26,
490,
372,
286,
14,
4504,
59,
390,
2858,
61,
355,
587,
26,
490,
286,
14,
3512,
14,
740,
1332,
390,
2858,
12,
488,
430,
490,
286,
14,
4504,
59,
390,
2858,
61,
275,
284,
1302,
490,
372,
284,
1302,
339,
347,
1050,
2246,
2193,
8,
277,
304,
267,
1561,
275,
291,
14,
1587,
305,
14,
1612,
342,
267,
1561,
14,
3191,
342,
267,
367,
536,
315,
1561,
26,
288,
340,
536,
440,
315,
291,
14,
2246,
26,
355,
291,
14,
8104,
2246,
8,
354,
9,
288,
327,
1361,
536,
12,
291,
14,
2246,
59,
354,
1055,
1612,
342,
339,
347,
12831,
2246,
8,
277,
12,
536,
304,
267,
366,
667,
275,
291,
14,
1587,
305,
59,
354,
61,
267,
291,
14,
2246,
59,
354,
61,
275,
488,
327,
7283,
370,
9696,
3602,
16189,
267,
1174,
275,
366,
667,
59,
16,
61,
267,
3141,
409,
275,
1052,
267,
15145,
1074,
275,
1052,
267,
367,
1768,
12,
2163,
315,
1174,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
appsembler/mayan_appsembler
|
apps/common/migrations/0003_auto__del_field_autoadminsingleton_original_auto_admin_password__del_f.py
|
6
|
6099
|
# -*- 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):
# Deleting field 'AutoAdminSingleton.original_auto_admin_password'
db.delete_column('common_autoadminsingleton', 'original_auto_admin_password')
# Deleting field 'AutoAdminSingleton.auto_admin'
db.delete_column('common_autoadminsingleton', 'auto_admin_id')
# Adding field 'AutoAdminSingleton.auto_admin_account'
db.add_column('common_autoadminsingleton', 'auto_admin_account',
self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='auto_admin_account', null=True, to=orm['auth.User']),
keep_default=False)
# Adding field 'AutoAdminSingleton.auto_admin_password'
db.add_column('common_autoadminsingleton', 'auto_admin_password',
self.gf('django.db.models.fields.CharField')(max_length=128, null=True, blank=True),
keep_default=False)
def backwards(self, orm):
# Adding field 'AutoAdminSingleton.original_auto_admin_password'
db.add_column('common_autoadminsingleton', 'original_auto_admin_password',
self.gf('django.db.models.fields.BooleanField')(default=True),
keep_default=False)
# Adding field 'AutoAdminSingleton.auto_admin'
db.add_column('common_autoadminsingleton', 'auto_admin',
self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'], null=True, blank=True),
keep_default=False)
# Deleting field 'AutoAdminSingleton.auto_admin_account'
db.delete_column('common_autoadminsingleton', 'auto_admin_account_id')
# Deleting field 'AutoAdminSingleton.auto_admin_password'
db.delete_column('common_autoadminsingleton', 'auto_admin_password')
models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
'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': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'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': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'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': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'common.anonymoususersingleton': {
'Meta': {'object_name': 'AnonymousUserSingleton'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'lock_id': ('django.db.models.fields.CharField', [], {'default': '1', 'unique': 'True', 'max_length': '1'})
},
'common.autoadminsingleton': {
'Meta': {'object_name': 'AutoAdminSingleton'},
'auto_admin_account': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'auto_admin_account'", 'null': 'True', 'to': "orm['auth.User']"}),
'auto_admin_password': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'lock_id': ('django.db.models.fields.CharField', [], {'default': '1', 'unique': 'True', 'max_length': '1'})
},
'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'}),
'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'})
}
}
complete_apps = ['common']
|
gpl-3.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,
15920,
901,
283,
3358,
4880,
28456,
14,
5043,
63,
2495,
63,
2113,
63,
2060,
7,
267,
1592,
14,
1807,
63,
2301,
360,
2330,
63,
2495,
2113,
24675,
297,
283,
5043,
63,
2495,
63,
2113,
63,
2060,
358,
398,
327,
15920,
901,
283,
3358,
4880,
28456,
14,
2495,
63,
2113,
7,
267,
1592,
14,
1807,
63,
2301,
360,
2330,
63,
2495,
2113,
24675,
297,
283,
2495,
63,
2113,
63,
344,
358,
398,
327,
12934,
901,
283,
3358,
4880,
28456,
14,
2495,
63,
2113,
63,
2048,
7,
267,
1592,
14,
525,
63,
2301,
360,
2330,
63,
2495,
2113,
24675,
297,
283,
2495,
63,
2113,
63,
2048,
297,
1993,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
2500,
29,
549,
12,
4048,
63,
354,
534,
2495,
63,
2113,
63,
2048,
297,
2973,
29,
549,
12,
370,
29,
1025,
459,
1178,
14,
1899,
3815,
1993,
4215,
63,
885,
29,
797,
9,
398,
327,
12934,
901,
283,
3358,
4880,
28456,
14,
2495,
63,
2113,
63,
2060,
7,
267,
1592,
14,
525,
63,
2301,
360,
2330,
63,
2495,
2113,
24675,
297,
283,
2495,
63,
2113,
63,
2060,
297,
1993,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
988,
63,
1267,
29,
3933,
12,
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,
12934,
901,
283,
3358,
4880,
28456,
14,
5043,
63,
2495,
63,
2113,
63,
2060,
7,
267,
1592,
14,
525,
63,
2301,
360,
2330,
63,
2495,
2113,
24675,
297,
283,
5043,
63,
2495,
63,
2113,
63,
2060,
297,
1993,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
7533,
885,
29,
549,
395,
1993,
4215,
63,
885,
29,
797,
9,
398,
327,
12934,
901,
283,
3358,
4880,
28456,
14,
2495,
63,
2113,
7,
267,
1592,
14,
525,
63,
2301,
360,
2330,
63,
2495,
2113,
24675,
297,
283,
2495,
63,
2113,
297,
1993,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
475,
29,
1025,
459,
1178,
14,
1899,
995,
2973,
29,
549,
12,
4596,
29,
549,
395,
1993,
4215,
63,
885,
29,
797,
9,
398,
327,
15920,
901,
283,
3358,
4880,
28456,
14,
2495,
63,
2113,
63,
2048,
7,
267,
1592,
14,
1807,
63,
2301,
360,
2330,
63,
2495,
2113,
24675,
297,
283,
2495,
63,
2113,
63,
2048,
63,
344,
358,
398,
327,
15920,
901,
283,
3358,
4880,
28456,
14,
2495,
63,
2113,
63,
2060,
7,
267,
1592,
14,
1807,
63,
2301,
360,
2330,
63,
2495,
2113,
24675,
297,
283,
2495,
63,
2113,
63,
2060,
358,
2378,
1709,
275,
469,
267,
283,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
283,
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,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
283,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
1317,
63,
466,
363,
571,
63,
1302,
297,
283,
1317,
63,
466,
363,
1238,
297,
283,
11879,
18106,
283,
3235,
63,
6314,
356,
9510,
1317,
63,
466,
297,
283,
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,
298,
1025,
459,
10778,
14,
11282,
6097,
288,
283,
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,
283,
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,
298,
1025,
459,
1178,
14,
2448,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
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
] |
[
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,
15920,
901,
283,
3358,
4880,
28456,
14,
5043,
63,
2495,
63,
2113,
63,
2060,
7,
267,
1592,
14,
1807,
63,
2301,
360,
2330,
63,
2495,
2113,
24675,
297,
283,
5043,
63,
2495,
63,
2113,
63,
2060,
358,
398,
327,
15920,
901,
283,
3358,
4880,
28456,
14,
2495,
63,
2113,
7,
267,
1592,
14,
1807,
63,
2301,
360,
2330,
63,
2495,
2113,
24675,
297,
283,
2495,
63,
2113,
63,
344,
358,
398,
327,
12934,
901,
283,
3358,
4880,
28456,
14,
2495,
63,
2113,
63,
2048,
7,
267,
1592,
14,
525,
63,
2301,
360,
2330,
63,
2495,
2113,
24675,
297,
283,
2495,
63,
2113,
63,
2048,
297,
1993,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
2500,
29,
549,
12,
4048,
63,
354,
534,
2495,
63,
2113,
63,
2048,
297,
2973,
29,
549,
12,
370,
29,
1025,
459,
1178,
14,
1899,
3815,
1993,
4215,
63,
885,
29,
797,
9,
398,
327,
12934,
901,
283,
3358,
4880,
28456,
14,
2495,
63,
2113,
63,
2060,
7,
267,
1592,
14,
525,
63,
2301,
360,
2330,
63,
2495,
2113,
24675,
297,
283,
2495,
63,
2113,
63,
2060,
297,
1993,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
988,
63,
1267,
29,
3933,
12,
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,
12934,
901,
283,
3358,
4880,
28456,
14,
5043,
63,
2495,
63,
2113,
63,
2060,
7,
267,
1592,
14,
525,
63,
2301,
360,
2330,
63,
2495,
2113,
24675,
297,
283,
5043,
63,
2495,
63,
2113,
63,
2060,
297,
1993,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
7533,
885,
29,
549,
395,
1993,
4215,
63,
885,
29,
797,
9,
398,
327,
12934,
901,
283,
3358,
4880,
28456,
14,
2495,
63,
2113,
7,
267,
1592,
14,
525,
63,
2301,
360,
2330,
63,
2495,
2113,
24675,
297,
283,
2495,
63,
2113,
297,
1993,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
475,
29,
1025,
459,
1178,
14,
1899,
995,
2973,
29,
549,
12,
4596,
29,
549,
395,
1993,
4215,
63,
885,
29,
797,
9,
398,
327,
15920,
901,
283,
3358,
4880,
28456,
14,
2495,
63,
2113,
63,
2048,
7,
267,
1592,
14,
1807,
63,
2301,
360,
2330,
63,
2495,
2113,
24675,
297,
283,
2495,
63,
2113,
63,
2048,
63,
344,
358,
398,
327,
15920,
901,
283,
3358,
4880,
28456,
14,
2495,
63,
2113,
63,
2060,
7,
267,
1592,
14,
1807,
63,
2301,
360,
2330,
63,
2495,
2113,
24675,
297,
283,
2495,
63,
2113,
63,
2060,
358,
2378,
1709,
275,
469,
267,
283,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
283,
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,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
283,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
1317,
63,
466,
363,
571,
63,
1302,
297,
283,
1317,
63,
466,
363,
1238,
297,
283,
11879,
18106,
283,
3235,
63,
6314,
356,
9510,
1317,
63,
466,
297,
283,
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,
298,
1025,
459,
10778,
14,
11282,
6097,
288,
283,
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,
283,
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,
298,
1025,
459,
1178,
14,
2448,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sustainingtechnologies/django-guardian
|
guardian/testapp/models.py
|
13
|
1400
|
from __future__ import unicode_literals
from datetime import datetime
from django.db import models
from django.contrib.admin.models import LogEntry
from guardian.models import UserObjectPermissionBase, GroupObjectPermissionBase
class DynamicAccessor(object):
def __init__(self):
pass
def __getattr__(self, key):
return DynamicAccessor()
class ProjectUserObjectPermission(UserObjectPermissionBase):
content_object = models.ForeignKey('Project')
class ProjectGroupObjectPermission(GroupObjectPermissionBase):
content_object = models.ForeignKey('Project')
class Project(models.Model):
name = models.CharField(max_length=128, unique=True)
created_at = models.DateTimeField(default=datetime.now)
class Meta:
get_latest_by = 'created_at'
def __unicode__(self):
return self.name
Project.not_a_relation_descriptor = DynamicAccessor()
class MixedGroupObjectPermission(GroupObjectPermissionBase):
content_object = models.ForeignKey('Mixed')
class Mixed(models.Model):
"""
Model for tests obj perms checks with generic user object permissions model
and direct group object permissions model.
"""
name = models.CharField(max_length=128, unique=True)
def __unicode__(self):
return self.name
class LogEntryWithGroup(LogEntry):
group = models.ForeignKey('auth.Group', null=True, blank=True)
|
bsd-2-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
2197,
492,
2197,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
2828,
14,
2113,
14,
992,
492,
5297,
3900,
199,
504,
8129,
31186,
14,
992,
492,
2876,
1692,
7980,
1563,
12,
5611,
1692,
7980,
1563,
421,
199,
533,
21907,
5742,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
986,
339,
347,
636,
5675,
721,
277,
12,
790,
304,
267,
372,
21907,
5742,
342,
421,
199,
533,
7290,
1899,
1692,
7980,
8,
1899,
1692,
7980,
1563,
304,
272,
1564,
63,
785,
275,
1709,
14,
3190,
360,
4761,
358,
421,
199,
533,
7290,
2448,
1692,
7980,
8,
2448,
1692,
7980,
1563,
304,
272,
1564,
63,
785,
275,
1709,
14,
3190,
360,
4761,
358,
421,
199,
533,
7290,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
3933,
12,
3747,
29,
549,
9,
272,
2737,
63,
292,
275,
1709,
14,
4626,
8,
885,
29,
2083,
14,
2131,
9,
339,
1021,
6288,
26,
267,
664,
63,
7410,
63,
991,
275,
283,
3966,
63,
292,
7,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
291,
14,
354,
199,
199,
4761,
14,
1397,
63,
65,
63,
5690,
63,
4120,
275,
21907,
5742,
342,
421,
199,
533,
21203,
2448,
1692,
7980,
8,
2448,
1692,
7980,
1563,
304,
272,
1564,
63,
785,
275,
1709,
14,
3190,
360,
17899,
358,
421,
199,
533,
21203,
8,
992,
14,
1685,
304,
272,
408,
272,
5822,
367,
2295,
1559,
17340,
5920,
543,
7809,
922,
909,
3443,
1402,
272,
436,
4125,
1572,
909,
3443,
1402,
14,
272,
408,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
3933,
12,
3747,
29,
549,
9,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
533,
5297,
3900,
3007,
2448,
8,
2445,
3900,
304,
272,
1572,
275,
1709,
14,
3190,
360,
1178,
14,
2448,
297,
2973,
29,
549,
12,
4596,
29,
549,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
2197,
492,
2197,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
2828,
14,
2113,
14,
992,
492,
5297,
3900,
199,
504,
8129,
31186,
14,
992,
492,
2876,
1692,
7980,
1563,
12,
5611,
1692,
7980,
1563,
421,
199,
533,
21907,
5742,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
986,
339,
347,
636,
5675,
721,
277,
12,
790,
304,
267,
372,
21907,
5742,
342,
421,
199,
533,
7290,
1899,
1692,
7980,
8,
1899,
1692,
7980,
1563,
304,
272,
1564,
63,
785,
275,
1709,
14,
3190,
360,
4761,
358,
421,
199,
533,
7290,
2448,
1692,
7980,
8,
2448,
1692,
7980,
1563,
304,
272,
1564,
63,
785,
275,
1709,
14,
3190,
360,
4761,
358,
421,
199,
533,
7290,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
3933,
12,
3747,
29,
549,
9,
272,
2737,
63,
292,
275,
1709,
14,
4626,
8,
885,
29,
2083,
14,
2131,
9,
339,
1021,
6288,
26,
267,
664,
63,
7410,
63,
991,
275,
283,
3966,
63,
292,
7,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
291,
14,
354,
199,
199,
4761,
14,
1397,
63,
65,
63,
5690,
63,
4120,
275,
21907,
5742,
342,
421,
199,
533,
21203,
2448,
1692,
7980,
8,
2448,
1692,
7980,
1563,
304,
272,
1564,
63,
785,
275,
1709,
14,
3190,
360,
17899,
358,
421,
199,
533,
21203,
8,
992,
14,
1685,
304,
272,
408,
272,
5822,
367,
2295,
1559,
17340,
5920,
543,
7809,
922,
909,
3443,
1402,
272,
436,
4125,
1572,
909,
3443,
1402,
14,
272,
408,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
3933,
12,
3747,
29,
549,
9,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
533,
5297,
3900,
3007,
2448,
8,
2445,
3900,
304,
272,
1572,
275,
1709,
14,
3190,
360,
1178,
14,
2448,
297,
2973,
29,
549,
12,
4596,
29,
549,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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yp/pylib/gyp/generator/xcode.py
|
426
|
56534
|
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import filecmp
import gyp.common
import gyp.xcodeproj_file
import gyp.xcode_ninja
import errno
import os
import sys
import posixpath
import re
import shutil
import subprocess
import tempfile
# Project files generated by this module will use _intermediate_var as a
# custom Xcode setting whose value is a DerivedSources-like directory that's
# project-specific and configuration-specific. The normal choice,
# DERIVED_FILE_DIR, is target-specific, which is thought to be too restrictive
# as it is likely that multiple targets within a single project file will want
# to access the same set of generated files. The other option,
# PROJECT_DERIVED_FILE_DIR, is unsuitable because while it is project-specific,
# it is not configuration-specific. INTERMEDIATE_DIR is defined as
# $(PROJECT_DERIVED_FILE_DIR)/$(CONFIGURATION).
_intermediate_var = 'INTERMEDIATE_DIR'
# SHARED_INTERMEDIATE_DIR is the same, except that it is shared among all
# targets that share the same BUILT_PRODUCTS_DIR.
_shared_intermediate_var = 'SHARED_INTERMEDIATE_DIR'
_library_search_paths_var = 'LIBRARY_SEARCH_PATHS'
generator_default_variables = {
'EXECUTABLE_PREFIX': '',
'EXECUTABLE_SUFFIX': '',
'STATIC_LIB_PREFIX': 'lib',
'SHARED_LIB_PREFIX': 'lib',
'STATIC_LIB_SUFFIX': '.a',
'SHARED_LIB_SUFFIX': '.dylib',
# INTERMEDIATE_DIR is a place for targets to build up intermediate products.
# It is specific to each build environment. It is only guaranteed to exist
# and be constant within the context of a project, corresponding to a single
# input file. Some build environments may allow their intermediate directory
# to be shared on a wider scale, but this is not guaranteed.
'INTERMEDIATE_DIR': '$(%s)' % _intermediate_var,
'OS': 'mac',
'PRODUCT_DIR': '$(BUILT_PRODUCTS_DIR)',
'LIB_DIR': '$(BUILT_PRODUCTS_DIR)',
'RULE_INPUT_ROOT': '$(INPUT_FILE_BASE)',
'RULE_INPUT_EXT': '$(INPUT_FILE_SUFFIX)',
'RULE_INPUT_NAME': '$(INPUT_FILE_NAME)',
'RULE_INPUT_PATH': '$(INPUT_FILE_PATH)',
'RULE_INPUT_DIRNAME': '$(INPUT_FILE_DIRNAME)',
'SHARED_INTERMEDIATE_DIR': '$(%s)' % _shared_intermediate_var,
'CONFIGURATION_NAME': '$(CONFIGURATION)',
}
# The Xcode-specific sections that hold paths.
generator_additional_path_sections = [
'mac_bundle_resources',
'mac_framework_headers',
'mac_framework_private_headers',
# 'mac_framework_dirs', input already handles _dirs endings.
]
# The Xcode-specific keys that exist on targets and aren't moved down to
# configurations.
generator_additional_non_configuration_keys = [
'ios_app_extension',
'ios_watch_app',
'ios_watchkit_extension',
'mac_bundle',
'mac_bundle_resources',
'mac_framework_headers',
'mac_framework_private_headers',
'mac_xctest_bundle',
'xcode_create_dependents_test_runner',
]
# We want to let any rules apply to files that are resources also.
generator_extra_sources_for_rules = [
'mac_bundle_resources',
'mac_framework_headers',
'mac_framework_private_headers',
]
# Xcode's standard set of library directories, which don't need to be duplicated
# in LIBRARY_SEARCH_PATHS. This list is not exhaustive, but that's okay.
xcode_standard_library_dirs = frozenset([
'$(SDKROOT)/usr/lib',
'$(SDKROOT)/usr/local/lib',
])
def CreateXCConfigurationList(configuration_names):
xccl = gyp.xcodeproj_file.XCConfigurationList({'buildConfigurations': []})
if len(configuration_names) == 0:
configuration_names = ['Default']
for configuration_name in configuration_names:
xcbc = gyp.xcodeproj_file.XCBuildConfiguration({
'name': configuration_name})
xccl.AppendProperty('buildConfigurations', xcbc)
xccl.SetProperty('defaultConfigurationName', configuration_names[0])
return xccl
class XcodeProject(object):
def __init__(self, gyp_path, path, build_file_dict):
self.gyp_path = gyp_path
self.path = path
self.project = gyp.xcodeproj_file.PBXProject(path=path)
projectDirPath = gyp.common.RelativePath(
os.path.dirname(os.path.abspath(self.gyp_path)),
os.path.dirname(path) or '.')
self.project.SetProperty('projectDirPath', projectDirPath)
self.project_file = \
gyp.xcodeproj_file.XCProjectFile({'rootObject': self.project})
self.build_file_dict = build_file_dict
# TODO(mark): add destructor that cleans up self.path if created_dir is
# True and things didn't complete successfully. Or do something even
# better with "try"?
self.created_dir = False
try:
os.makedirs(self.path)
self.created_dir = True
except OSError, e:
if e.errno != errno.EEXIST:
raise
def Finalize1(self, xcode_targets, serialize_all_tests):
# Collect a list of all of the build configuration names used by the
# various targets in the file. It is very heavily advised to keep each
# target in an entire project (even across multiple project files) using
# the same set of configuration names.
configurations = []
for xct in self.project.GetProperty('targets'):
xccl = xct.GetProperty('buildConfigurationList')
xcbcs = xccl.GetProperty('buildConfigurations')
for xcbc in xcbcs:
name = xcbc.GetProperty('name')
if name not in configurations:
configurations.append(name)
# Replace the XCConfigurationList attached to the PBXProject object with
# a new one specifying all of the configuration names used by the various
# targets.
try:
xccl = CreateXCConfigurationList(configurations)
self.project.SetProperty('buildConfigurationList', xccl)
except:
sys.stderr.write("Problem with gyp file %s\n" % self.gyp_path)
raise
# The need for this setting is explained above where _intermediate_var is
# defined. The comments below about wanting to avoid project-wide build
# settings apply here too, but this needs to be set on a project-wide basis
# so that files relative to the _intermediate_var setting can be displayed
# properly in the Xcode UI.
#
# Note that for configuration-relative files such as anything relative to
# _intermediate_var, for the purposes of UI tree view display, Xcode will
# only resolve the configuration name once, when the project file is
# opened. If the active build configuration is changed, the project file
# must be closed and reopened if it is desired for the tree view to update.
# This is filed as Apple radar 6588391.
xccl.SetBuildSetting(_intermediate_var,
'$(PROJECT_DERIVED_FILE_DIR)/$(CONFIGURATION)')
xccl.SetBuildSetting(_shared_intermediate_var,
'$(SYMROOT)/DerivedSources/$(CONFIGURATION)')
# Set user-specified project-wide build settings and config files. This
# is intended to be used very sparingly. Really, almost everything should
# go into target-specific build settings sections. The project-wide
# settings are only intended to be used in cases where Xcode attempts to
# resolve variable references in a project context as opposed to a target
# context, such as when resolving sourceTree references while building up
# the tree tree view for UI display.
# Any values set globally are applied to all configurations, then any
# per-configuration values are applied.
for xck, xcv in self.build_file_dict.get('xcode_settings', {}).iteritems():
xccl.SetBuildSetting(xck, xcv)
if 'xcode_config_file' in self.build_file_dict:
config_ref = self.project.AddOrGetFileInRootGroup(
self.build_file_dict['xcode_config_file'])
xccl.SetBaseConfiguration(config_ref)
build_file_configurations = self.build_file_dict.get('configurations', {})
if build_file_configurations:
for config_name in configurations:
build_file_configuration_named = \
build_file_configurations.get(config_name, {})
if build_file_configuration_named:
xcc = xccl.ConfigurationNamed(config_name)
for xck, xcv in build_file_configuration_named.get('xcode_settings',
{}).iteritems():
xcc.SetBuildSetting(xck, xcv)
if 'xcode_config_file' in build_file_configuration_named:
config_ref = self.project.AddOrGetFileInRootGroup(
build_file_configurations[config_name]['xcode_config_file'])
xcc.SetBaseConfiguration(config_ref)
# Sort the targets based on how they appeared in the input.
# TODO(mark): Like a lot of other things here, this assumes internal
# knowledge of PBXProject - in this case, of its "targets" property.
# ordinary_targets are ordinary targets that are already in the project
# file. run_test_targets are the targets that run unittests and should be
# used for the Run All Tests target. support_targets are the action/rule
# targets used by GYP file targets, just kept for the assert check.
ordinary_targets = []
run_test_targets = []
support_targets = []
# targets is full list of targets in the project.
targets = []
# does the it define it's own "all"?
has_custom_all = False
# targets_for_all is the list of ordinary_targets that should be listed
# in this project's "All" target. It includes each non_runtest_target
# that does not have suppress_wildcard set.
targets_for_all = []
for target in self.build_file_dict['targets']:
target_name = target['target_name']
toolset = target['toolset']
qualified_target = gyp.common.QualifiedTarget(self.gyp_path, target_name,
toolset)
xcode_target = xcode_targets[qualified_target]
# Make sure that the target being added to the sorted list is already in
# the unsorted list.
assert xcode_target in self.project._properties['targets']
targets.append(xcode_target)
ordinary_targets.append(xcode_target)
if xcode_target.support_target:
support_targets.append(xcode_target.support_target)
targets.append(xcode_target.support_target)
if not int(target.get('suppress_wildcard', False)):
targets_for_all.append(xcode_target)
if target_name.lower() == 'all':
has_custom_all = True;
# If this target has a 'run_as' attribute, add its target to the
# targets, and add it to the test targets.
if target.get('run_as'):
# Make a target to run something. It should have one
# dependency, the parent xcode target.
xccl = CreateXCConfigurationList(configurations)
run_target = gyp.xcodeproj_file.PBXAggregateTarget({
'name': 'Run ' + target_name,
'productName': xcode_target.GetProperty('productName'),
'buildConfigurationList': xccl,
},
parent=self.project)
run_target.AddDependency(xcode_target)
command = target['run_as']
script = ''
if command.get('working_directory'):
script = script + 'cd "%s"\n' % \
gyp.xcodeproj_file.ConvertVariablesToShellSyntax(
command.get('working_directory'))
if command.get('environment'):
script = script + "\n".join(
['export %s="%s"' %
(key, gyp.xcodeproj_file.ConvertVariablesToShellSyntax(val))
for (key, val) in command.get('environment').iteritems()]) + "\n"
# Some test end up using sockets, files on disk, etc. and can get
# confused if more then one test runs at a time. The generator
# flag 'xcode_serialize_all_test_runs' controls the forcing of all
# tests serially. It defaults to True. To get serial runs this
# little bit of python does the same as the linux flock utility to
# make sure only one runs at a time.
command_prefix = ''
if serialize_all_tests:
command_prefix = \
"""python -c "import fcntl, subprocess, sys
file = open('$TMPDIR/GYP_serialize_test_runs', 'a')
fcntl.flock(file.fileno(), fcntl.LOCK_EX)
sys.exit(subprocess.call(sys.argv[1:]))" """
# If we were unable to exec for some reason, we want to exit
# with an error, and fixup variable references to be shell
# syntax instead of xcode syntax.
script = script + 'exec ' + command_prefix + '%s\nexit 1\n' % \
gyp.xcodeproj_file.ConvertVariablesToShellSyntax(
gyp.common.EncodePOSIXShellList(command.get('action')))
ssbp = gyp.xcodeproj_file.PBXShellScriptBuildPhase({
'shellScript': script,
'showEnvVarsInLog': 0,
})
run_target.AppendProperty('buildPhases', ssbp)
# Add the run target to the project file.
targets.append(run_target)
run_test_targets.append(run_target)
xcode_target.test_runner = run_target
# Make sure that the list of targets being replaced is the same length as
# the one replacing it, but allow for the added test runner targets.
assert len(self.project._properties['targets']) == \
len(ordinary_targets) + len(support_targets)
self.project._properties['targets'] = targets
# Get rid of unnecessary levels of depth in groups like the Source group.
self.project.RootGroupsTakeOverOnlyChildren(True)
# Sort the groups nicely. Do this after sorting the targets, because the
# Products group is sorted based on the order of the targets.
self.project.SortGroups()
# Create an "All" target if there's more than one target in this project
# file and the project didn't define its own "All" target. Put a generated
# "All" target first so that people opening up the project for the first
# time will build everything by default.
if len(targets_for_all) > 1 and not has_custom_all:
xccl = CreateXCConfigurationList(configurations)
all_target = gyp.xcodeproj_file.PBXAggregateTarget(
{
'buildConfigurationList': xccl,
'name': 'All',
},
parent=self.project)
for target in targets_for_all:
all_target.AddDependency(target)
# TODO(mark): This is evil because it relies on internal knowledge of
# PBXProject._properties. It's important to get the "All" target first,
# though.
self.project._properties['targets'].insert(0, all_target)
# The same, but for run_test_targets.
if len(run_test_targets) > 1:
xccl = CreateXCConfigurationList(configurations)
run_all_tests_target = gyp.xcodeproj_file.PBXAggregateTarget(
{
'buildConfigurationList': xccl,
'name': 'Run All Tests',
},
parent=self.project)
for run_test_target in run_test_targets:
run_all_tests_target.AddDependency(run_test_target)
# Insert after the "All" target, which must exist if there is more than
# one run_test_target.
self.project._properties['targets'].insert(1, run_all_tests_target)
def Finalize2(self, xcode_targets, xcode_target_to_target_dict):
# Finalize2 needs to happen in a separate step because the process of
# updating references to other projects depends on the ordering of targets
# within remote project files. Finalize1 is responsible for sorting duty,
# and once all project files are sorted, Finalize2 can come in and update
# these references.
# To support making a "test runner" target that will run all the tests
# that are direct dependents of any given target, we look for
# xcode_create_dependents_test_runner being set on an Aggregate target,
# and generate a second target that will run the tests runners found under
# the marked target.
for bf_tgt in self.build_file_dict['targets']:
if int(bf_tgt.get('xcode_create_dependents_test_runner', 0)):
tgt_name = bf_tgt['target_name']
toolset = bf_tgt['toolset']
qualified_target = gyp.common.QualifiedTarget(self.gyp_path,
tgt_name, toolset)
xcode_target = xcode_targets[qualified_target]
if isinstance(xcode_target, gyp.xcodeproj_file.PBXAggregateTarget):
# Collect all the run test targets.
all_run_tests = []
pbxtds = xcode_target.GetProperty('dependencies')
for pbxtd in pbxtds:
pbxcip = pbxtd.GetProperty('targetProxy')
dependency_xct = pbxcip.GetProperty('remoteGlobalIDString')
if hasattr(dependency_xct, 'test_runner'):
all_run_tests.append(dependency_xct.test_runner)
# Directly depend on all the runners as they depend on the target
# that builds them.
if len(all_run_tests) > 0:
run_all_target = gyp.xcodeproj_file.PBXAggregateTarget({
'name': 'Run %s Tests' % tgt_name,
'productName': tgt_name,
},
parent=self.project)
for run_test_target in all_run_tests:
run_all_target.AddDependency(run_test_target)
# Insert the test runner after the related target.
idx = self.project._properties['targets'].index(xcode_target)
self.project._properties['targets'].insert(idx + 1, run_all_target)
# Update all references to other projects, to make sure that the lists of
# remote products are complete. Otherwise, Xcode will fill them in when
# it opens the project file, which will result in unnecessary diffs.
# TODO(mark): This is evil because it relies on internal knowledge of
# PBXProject._other_pbxprojects.
for other_pbxproject in self.project._other_pbxprojects.keys():
self.project.AddOrGetProjectReference(other_pbxproject)
self.project.SortRemoteProductReferences()
# Give everything an ID.
self.project_file.ComputeIDs()
# Make sure that no two objects in the project file have the same ID. If
# multiple objects wind up with the same ID, upon loading the file, Xcode
# will only recognize one object (the last one in the file?) and the
# results are unpredictable.
self.project_file.EnsureNoIDCollisions()
def Write(self):
# Write the project file to a temporary location first. Xcode watches for
# changes to the project file and presents a UI sheet offering to reload
# the project when it does change. However, in some cases, especially when
# multiple projects are open or when Xcode is busy, things don't work so
# seamlessly. Sometimes, Xcode is able to detect that a project file has
# changed but can't unload it because something else is referencing it.
# To mitigate this problem, and to avoid even having Xcode present the UI
# sheet when an open project is rewritten for inconsequential changes, the
# project file is written to a temporary file in the xcodeproj directory
# first. The new temporary file is then compared to the existing project
# file, if any. If they differ, the new file replaces the old; otherwise,
# the new project file is simply deleted. Xcode properly detects a file
# being renamed over an open project file as a change and so it remains
# able to present the "project file changed" sheet under this system.
# Writing to a temporary file first also avoids the possible problem of
# Xcode rereading an incomplete project file.
(output_fd, new_pbxproj_path) = \
tempfile.mkstemp(suffix='.tmp', prefix='project.pbxproj.gyp.',
dir=self.path)
try:
output_file = os.fdopen(output_fd, 'wb')
self.project_file.Print(output_file)
output_file.close()
pbxproj_path = os.path.join(self.path, 'project.pbxproj')
same = False
try:
same = filecmp.cmp(pbxproj_path, new_pbxproj_path, False)
except OSError, e:
if e.errno != errno.ENOENT:
raise
if same:
# The new file is identical to the old one, just get rid of the new
# one.
os.unlink(new_pbxproj_path)
else:
# The new file is different from the old one, or there is no old one.
# Rename the new file to the permanent name.
#
# tempfile.mkstemp uses an overly restrictive mode, resulting in a
# file that can only be read by the owner, regardless of the umask.
# There's no reason to not respect the umask here, which means that
# an extra hoop is required to fetch it and reset the new file's mode.
#
# No way to get the umask without setting a new one? Set a safe one
# and then set it back to the old value.
umask = os.umask(077)
os.umask(umask)
os.chmod(new_pbxproj_path, 0666 & ~umask)
os.rename(new_pbxproj_path, pbxproj_path)
except Exception:
# Don't leave turds behind. In fact, if this code was responsible for
# creating the xcodeproj directory, get rid of that too.
os.unlink(new_pbxproj_path)
if self.created_dir:
shutil.rmtree(self.path, True)
raise
def AddSourceToTarget(source, type, pbxp, xct):
# TODO(mark): Perhaps source_extensions and library_extensions can be made a
# little bit fancier.
source_extensions = ['c', 'cc', 'cpp', 'cxx', 'm', 'mm', 's', 'swift']
# .o is conceptually more of a "source" than a "library," but Xcode thinks
# of "sources" as things to compile and "libraries" (or "frameworks") as
# things to link with. Adding an object file to an Xcode target's frameworks
# phase works properly.
library_extensions = ['a', 'dylib', 'framework', 'o']
basename = posixpath.basename(source)
(root, ext) = posixpath.splitext(basename)
if ext:
ext = ext[1:].lower()
if ext in source_extensions and type != 'none':
xct.SourcesPhase().AddFile(source)
elif ext in library_extensions and type != 'none':
xct.FrameworksPhase().AddFile(source)
else:
# Files that aren't added to a sources or frameworks build phase can still
# go into the project file, just not as part of a build phase.
pbxp.AddOrGetFileInRootGroup(source)
def AddResourceToTarget(resource, pbxp, xct):
# TODO(mark): Combine with AddSourceToTarget above? Or just inline this call
# where it's used.
xct.ResourcesPhase().AddFile(resource)
def AddHeaderToTarget(header, pbxp, xct, is_public):
# TODO(mark): Combine with AddSourceToTarget above? Or just inline this call
# where it's used.
settings = '{ATTRIBUTES = (%s, ); }' % ('Private', 'Public')[is_public]
xct.HeadersPhase().AddFile(header, settings)
_xcode_variable_re = re.compile(r'(\$\((.*?)\))')
def ExpandXcodeVariables(string, expansions):
"""Expands Xcode-style $(VARIABLES) in string per the expansions dict.
In some rare cases, it is appropriate to expand Xcode variables when a
project file is generated. For any substring $(VAR) in string, if VAR is a
key in the expansions dict, $(VAR) will be replaced with expansions[VAR].
Any $(VAR) substring in string for which VAR is not a key in the expansions
dict will remain in the returned string.
"""
matches = _xcode_variable_re.findall(string)
if matches == None:
return string
matches.reverse()
for match in matches:
(to_replace, variable) = match
if not variable in expansions:
continue
replacement = expansions[variable]
string = re.sub(re.escape(to_replace), replacement, string)
return string
_xcode_define_re = re.compile(r'([\\\"\' ])')
def EscapeXcodeDefine(s):
"""We must escape the defines that we give to XCode so that it knows not to
split on spaces and to respect backslash and quote literals. However, we
must not quote the define, or Xcode will incorrectly intepret variables
especially $(inherited)."""
return re.sub(_xcode_define_re, r'\\\1', s)
def PerformBuild(data, configurations, params):
options = params['options']
for build_file, build_file_dict in data.iteritems():
(build_file_root, build_file_ext) = os.path.splitext(build_file)
if build_file_ext != '.gyp':
continue
xcodeproj_path = build_file_root + options.suffix + '.xcodeproj'
if options.generator_output:
xcodeproj_path = os.path.join(options.generator_output, xcodeproj_path)
for config in configurations:
arguments = ['xcodebuild', '-project', xcodeproj_path]
arguments += ['-configuration', config]
print "Building [%s]: %s" % (config, arguments)
subprocess.check_call(arguments)
def GenerateOutput(target_list, target_dicts, data, params):
# Optionally configure each spec to use ninja as the external builder.
ninja_wrapper = params.get('flavor') == 'ninja'
if ninja_wrapper:
(target_list, target_dicts, data) = \
gyp.xcode_ninja.CreateWrapper(target_list, target_dicts, data, params)
options = params['options']
generator_flags = params.get('generator_flags', {})
parallel_builds = generator_flags.get('xcode_parallel_builds', True)
serialize_all_tests = \
generator_flags.get('xcode_serialize_all_test_runs', True)
skip_excluded_files = \
not generator_flags.get('xcode_list_excluded_files', True)
xcode_projects = {}
for build_file, build_file_dict in data.iteritems():
(build_file_root, build_file_ext) = os.path.splitext(build_file)
if build_file_ext != '.gyp':
continue
xcodeproj_path = build_file_root + options.suffix + '.xcodeproj'
if options.generator_output:
xcodeproj_path = os.path.join(options.generator_output, xcodeproj_path)
xcp = XcodeProject(build_file, xcodeproj_path, build_file_dict)
xcode_projects[build_file] = xcp
pbxp = xcp.project
if parallel_builds:
pbxp.SetProperty('attributes',
{'BuildIndependentTargetsInParallel': 'YES'})
# Add gyp/gypi files to project
if not generator_flags.get('standalone'):
main_group = pbxp.GetProperty('mainGroup')
build_group = gyp.xcodeproj_file.PBXGroup({'name': 'Build'})
main_group.AppendChild(build_group)
for included_file in build_file_dict['included_files']:
build_group.AddOrGetFileByPath(included_file, False)
xcode_targets = {}
xcode_target_to_target_dict = {}
for qualified_target in target_list:
[build_file, target_name, toolset] = \
gyp.common.ParseQualifiedTarget(qualified_target)
spec = target_dicts[qualified_target]
if spec['toolset'] != 'target':
raise Exception(
'Multiple toolsets not supported in xcode build (target %s)' %
qualified_target)
configuration_names = [spec['default_configuration']]
for configuration_name in sorted(spec['configurations'].keys()):
if configuration_name not in configuration_names:
configuration_names.append(configuration_name)
xcp = xcode_projects[build_file]
pbxp = xcp.project
# Set up the configurations for the target according to the list of names
# supplied.
xccl = CreateXCConfigurationList(configuration_names)
# Create an XCTarget subclass object for the target. The type with
# "+bundle" appended will be used if the target has "mac_bundle" set.
# loadable_modules not in a mac_bundle are mapped to
# com.googlecode.gyp.xcode.bundle, a pseudo-type that xcode.py interprets
# to create a single-file mh_bundle.
_types = {
'executable': 'com.apple.product-type.tool',
'loadable_module': 'com.googlecode.gyp.xcode.bundle',
'shared_library': 'com.apple.product-type.library.dynamic',
'static_library': 'com.apple.product-type.library.static',
'executable+bundle': 'com.apple.product-type.application',
'loadable_module+bundle': 'com.apple.product-type.bundle',
'loadable_module+xctest': 'com.apple.product-type.bundle.unit-test',
'shared_library+bundle': 'com.apple.product-type.framework',
'executable+extension+bundle': 'com.apple.product-type.app-extension',
'executable+watch+extension+bundle':
'com.apple.product-type.watchkit-extension',
'executable+watch+bundle': 'com.apple.product-type.application.watchapp',
}
target_properties = {
'buildConfigurationList': xccl,
'name': target_name,
}
type = spec['type']
is_xctest = int(spec.get('mac_xctest_bundle', 0))
is_bundle = int(spec.get('mac_bundle', 0)) or is_xctest
is_app_extension = int(spec.get('ios_app_extension', 0))
is_watchkit_extension = int(spec.get('ios_watchkit_extension', 0))
is_watch_app = int(spec.get('ios_watch_app', 0))
if type != 'none':
type_bundle_key = type
if is_xctest:
type_bundle_key += '+xctest'
assert type == 'loadable_module', (
'mac_xctest_bundle targets must have type loadable_module '
'(target %s)' % target_name)
elif is_app_extension:
assert is_bundle, ('ios_app_extension flag requires mac_bundle '
'(target %s)' % target_name)
type_bundle_key += '+extension+bundle'
elif is_watchkit_extension:
assert is_bundle, ('ios_watchkit_extension flag requires mac_bundle '
'(target %s)' % target_name)
type_bundle_key += '+watch+extension+bundle'
elif is_watch_app:
assert is_bundle, ('ios_watch_app flag requires mac_bundle '
'(target %s)' % target_name)
type_bundle_key += '+watch+bundle'
elif is_bundle:
type_bundle_key += '+bundle'
xctarget_type = gyp.xcodeproj_file.PBXNativeTarget
try:
target_properties['productType'] = _types[type_bundle_key]
except KeyError, e:
gyp.common.ExceptionAppend(e, "-- unknown product type while "
"writing target %s" % target_name)
raise
else:
xctarget_type = gyp.xcodeproj_file.PBXAggregateTarget
assert not is_bundle, (
'mac_bundle targets cannot have type none (target "%s")' %
target_name)
assert not is_xctest, (
'mac_xctest_bundle targets cannot have type none (target "%s")' %
target_name)
target_product_name = spec.get('product_name')
if target_product_name is not None:
target_properties['productName'] = target_product_name
xct = xctarget_type(target_properties, parent=pbxp,
force_outdir=spec.get('product_dir'),
force_prefix=spec.get('product_prefix'),
force_extension=spec.get('product_extension'))
pbxp.AppendProperty('targets', xct)
xcode_targets[qualified_target] = xct
xcode_target_to_target_dict[xct] = spec
spec_actions = spec.get('actions', [])
spec_rules = spec.get('rules', [])
# Xcode has some "issues" with checking dependencies for the "Compile
# sources" step with any source files/headers generated by actions/rules.
# To work around this, if a target is building anything directly (not
# type "none"), then a second target is used to run the GYP actions/rules
# and is made a dependency of this target. This way the work is done
# before the dependency checks for what should be recompiled.
support_xct = None
# The Xcode "issues" don't affect xcode-ninja builds, since the dependency
# logic all happens in ninja. Don't bother creating the extra targets in
# that case.
if type != 'none' and (spec_actions or spec_rules) and not ninja_wrapper:
support_xccl = CreateXCConfigurationList(configuration_names);
support_target_suffix = generator_flags.get(
'support_target_suffix', ' Support')
support_target_properties = {
'buildConfigurationList': support_xccl,
'name': target_name + support_target_suffix,
}
if target_product_name:
support_target_properties['productName'] = \
target_product_name + ' Support'
support_xct = \
gyp.xcodeproj_file.PBXAggregateTarget(support_target_properties,
parent=pbxp)
pbxp.AppendProperty('targets', support_xct)
xct.AddDependency(support_xct)
# Hang the support target off the main target so it can be tested/found
# by the generator during Finalize.
xct.support_target = support_xct
prebuild_index = 0
# Add custom shell script phases for "actions" sections.
for action in spec_actions:
# There's no need to write anything into the script to ensure that the
# output directories already exist, because Xcode will look at the
# declared outputs and automatically ensure that they exist for us.
# Do we have a message to print when this action runs?
message = action.get('message')
if message:
message = 'echo note: ' + gyp.common.EncodePOSIXShellArgument(message)
else:
message = ''
# Turn the list into a string that can be passed to a shell.
action_string = gyp.common.EncodePOSIXShellList(action['action'])
# Convert Xcode-type variable references to sh-compatible environment
# variable references.
message_sh = gyp.xcodeproj_file.ConvertVariablesToShellSyntax(message)
action_string_sh = gyp.xcodeproj_file.ConvertVariablesToShellSyntax(
action_string)
script = ''
# Include the optional message
if message_sh:
script += message_sh + '\n'
# Be sure the script runs in exec, and that if exec fails, the script
# exits signalling an error.
script += 'exec ' + action_string_sh + '\nexit 1\n'
ssbp = gyp.xcodeproj_file.PBXShellScriptBuildPhase({
'inputPaths': action['inputs'],
'name': 'Action "' + action['action_name'] + '"',
'outputPaths': action['outputs'],
'shellScript': script,
'showEnvVarsInLog': 0,
})
if support_xct:
support_xct.AppendProperty('buildPhases', ssbp)
else:
# TODO(mark): this assumes too much knowledge of the internals of
# xcodeproj_file; some of these smarts should move into xcodeproj_file
# itself.
xct._properties['buildPhases'].insert(prebuild_index, ssbp)
prebuild_index = prebuild_index + 1
# TODO(mark): Should verify that at most one of these is specified.
if int(action.get('process_outputs_as_sources', False)):
for output in action['outputs']:
AddSourceToTarget(output, type, pbxp, xct)
if int(action.get('process_outputs_as_mac_bundle_resources', False)):
for output in action['outputs']:
AddResourceToTarget(output, pbxp, xct)
# tgt_mac_bundle_resources holds the list of bundle resources so
# the rule processing can check against it.
if is_bundle:
tgt_mac_bundle_resources = spec.get('mac_bundle_resources', [])
else:
tgt_mac_bundle_resources = []
# Add custom shell script phases driving "make" for "rules" sections.
#
# Xcode's built-in rule support is almost powerful enough to use directly,
# but there are a few significant deficiencies that render them unusable.
# There are workarounds for some of its inadequacies, but in aggregate,
# the workarounds added complexity to the generator, and some workarounds
# actually require input files to be crafted more carefully than I'd like.
# Consequently, until Xcode rules are made more capable, "rules" input
# sections will be handled in Xcode output by shell script build phases
# performed prior to the compilation phase.
#
# The following problems with Xcode rules were found. The numbers are
# Apple radar IDs. I hope that these shortcomings are addressed, I really
# liked having the rules handled directly in Xcode during the period that
# I was prototyping this.
#
# 6588600 Xcode compiles custom script rule outputs too soon, compilation
# fails. This occurs when rule outputs from distinct inputs are
# interdependent. The only workaround is to put rules and their
# inputs in a separate target from the one that compiles the rule
# outputs. This requires input file cooperation and it means that
# process_outputs_as_sources is unusable.
# 6584932 Need to declare that custom rule outputs should be excluded from
# compilation. A possible workaround is to lie to Xcode about a
# rule's output, giving it a dummy file it doesn't know how to
# compile. The rule action script would need to touch the dummy.
# 6584839 I need a way to declare additional inputs to a custom rule.
# A possible workaround is a shell script phase prior to
# compilation that touches a rule's primary input files if any
# would-be additional inputs are newer than the output. Modifying
# the source tree - even just modification times - feels dirty.
# 6564240 Xcode "custom script" build rules always dump all environment
# variables. This is a low-prioroty problem and is not a
# show-stopper.
rules_by_ext = {}
for rule in spec_rules:
rules_by_ext[rule['extension']] = rule
# First, some definitions:
#
# A "rule source" is a file that was listed in a target's "sources"
# list and will have a rule applied to it on the basis of matching the
# rule's "extensions" attribute. Rule sources are direct inputs to
# rules.
#
# Rule definitions may specify additional inputs in their "inputs"
# attribute. These additional inputs are used for dependency tracking
# purposes.
#
# A "concrete output" is a rule output with input-dependent variables
# resolved. For example, given a rule with:
# 'extension': 'ext', 'outputs': ['$(INPUT_FILE_BASE).cc'],
# if the target's "sources" list contained "one.ext" and "two.ext",
# the "concrete output" for rule input "two.ext" would be "two.cc". If
# a rule specifies multiple outputs, each input file that the rule is
# applied to will have the same number of concrete outputs.
#
# If any concrete outputs are outdated or missing relative to their
# corresponding rule_source or to any specified additional input, the
# rule action must be performed to generate the concrete outputs.
# concrete_outputs_by_rule_source will have an item at the same index
# as the rule['rule_sources'] that it corresponds to. Each item is a
# list of all of the concrete outputs for the rule_source.
concrete_outputs_by_rule_source = []
# concrete_outputs_all is a flat list of all concrete outputs that this
# rule is able to produce, given the known set of input files
# (rule_sources) that apply to it.
concrete_outputs_all = []
# messages & actions are keyed by the same indices as rule['rule_sources']
# and concrete_outputs_by_rule_source. They contain the message and
# action to perform after resolving input-dependent variables. The
# message is optional, in which case None is stored for each rule source.
messages = []
actions = []
for rule_source in rule.get('rule_sources', []):
rule_source_dirname, rule_source_basename = \
posixpath.split(rule_source)
(rule_source_root, rule_source_ext) = \
posixpath.splitext(rule_source_basename)
# These are the same variable names that Xcode uses for its own native
# rule support. Because Xcode's rule engine is not being used, they
# need to be expanded as they are written to the makefile.
rule_input_dict = {
'INPUT_FILE_BASE': rule_source_root,
'INPUT_FILE_SUFFIX': rule_source_ext,
'INPUT_FILE_NAME': rule_source_basename,
'INPUT_FILE_PATH': rule_source,
'INPUT_FILE_DIRNAME': rule_source_dirname,
}
concrete_outputs_for_this_rule_source = []
for output in rule.get('outputs', []):
# Fortunately, Xcode and make both use $(VAR) format for their
# variables, so the expansion is the only transformation necessary.
# Any remaning $(VAR)-type variables in the string can be given
# directly to make, which will pick up the correct settings from
# what Xcode puts into the environment.
concrete_output = ExpandXcodeVariables(output, rule_input_dict)
concrete_outputs_for_this_rule_source.append(concrete_output)
# Add all concrete outputs to the project.
pbxp.AddOrGetFileInRootGroup(concrete_output)
concrete_outputs_by_rule_source.append( \
concrete_outputs_for_this_rule_source)
concrete_outputs_all.extend(concrete_outputs_for_this_rule_source)
# TODO(mark): Should verify that at most one of these is specified.
if int(rule.get('process_outputs_as_sources', False)):
for output in concrete_outputs_for_this_rule_source:
AddSourceToTarget(output, type, pbxp, xct)
# If the file came from the mac_bundle_resources list or if the rule
# is marked to process outputs as bundle resource, do so.
was_mac_bundle_resource = rule_source in tgt_mac_bundle_resources
if was_mac_bundle_resource or \
int(rule.get('process_outputs_as_mac_bundle_resources', False)):
for output in concrete_outputs_for_this_rule_source:
AddResourceToTarget(output, pbxp, xct)
# Do we have a message to print when this rule runs?
message = rule.get('message')
if message:
message = gyp.common.EncodePOSIXShellArgument(message)
message = ExpandXcodeVariables(message, rule_input_dict)
messages.append(message)
# Turn the list into a string that can be passed to a shell.
action_string = gyp.common.EncodePOSIXShellList(rule['action'])
action = ExpandXcodeVariables(action_string, rule_input_dict)
actions.append(action)
if len(concrete_outputs_all) > 0:
# TODO(mark): There's a possibilty for collision here. Consider
# target "t" rule "A_r" and target "t_A" rule "r".
makefile_name = '%s.make' % re.sub(
'[^a-zA-Z0-9_]', '_' , '%s_%s' % (target_name, rule['rule_name']))
makefile_path = os.path.join(xcode_projects[build_file].path,
makefile_name)
# TODO(mark): try/close? Write to a temporary file and swap it only
# if it's got changes?
makefile = open(makefile_path, 'wb')
# make will build the first target in the makefile by default. By
# convention, it's called "all". List all (or at least one)
# concrete output for each rule source as a prerequisite of the "all"
# target.
makefile.write('all: \\\n')
for concrete_output_index in \
xrange(0, len(concrete_outputs_by_rule_source)):
# Only list the first (index [0]) concrete output of each input
# in the "all" target. Otherwise, a parallel make (-j > 1) would
# attempt to process each input multiple times simultaneously.
# Otherwise, "all" could just contain the entire list of
# concrete_outputs_all.
concrete_output = \
concrete_outputs_by_rule_source[concrete_output_index][0]
if concrete_output_index == len(concrete_outputs_by_rule_source) - 1:
eol = ''
else:
eol = ' \\'
makefile.write(' %s%s\n' % (concrete_output, eol))
for (rule_source, concrete_outputs, message, action) in \
zip(rule['rule_sources'], concrete_outputs_by_rule_source,
messages, actions):
makefile.write('\n')
# Add a rule that declares it can build each concrete output of a
# rule source. Collect the names of the directories that are
# required.
concrete_output_dirs = []
for concrete_output_index in xrange(0, len(concrete_outputs)):
concrete_output = concrete_outputs[concrete_output_index]
if concrete_output_index == 0:
bol = ''
else:
bol = ' '
makefile.write('%s%s \\\n' % (bol, concrete_output))
concrete_output_dir = posixpath.dirname(concrete_output)
if (concrete_output_dir and
concrete_output_dir not in concrete_output_dirs):
concrete_output_dirs.append(concrete_output_dir)
makefile.write(' : \\\n')
# The prerequisites for this rule are the rule source itself and
# the set of additional rule inputs, if any.
prerequisites = [rule_source]
prerequisites.extend(rule.get('inputs', []))
for prerequisite_index in xrange(0, len(prerequisites)):
prerequisite = prerequisites[prerequisite_index]
if prerequisite_index == len(prerequisites) - 1:
eol = ''
else:
eol = ' \\'
makefile.write(' %s%s\n' % (prerequisite, eol))
# Make sure that output directories exist before executing the rule
# action.
if len(concrete_output_dirs) > 0:
makefile.write('\t@mkdir -p "%s"\n' %
'" "'.join(concrete_output_dirs))
# The rule message and action have already had the necessary variable
# substitutions performed.
if message:
# Mark it with note: so Xcode picks it up in build output.
makefile.write('\t@echo note: %s\n' % message)
makefile.write('\t%s\n' % action)
makefile.close()
# It might be nice to ensure that needed output directories exist
# here rather than in each target in the Makefile, but that wouldn't
# work if there ever was a concrete output that had an input-dependent
# variable anywhere other than in the leaf position.
# Don't declare any inputPaths or outputPaths. If they're present,
# Xcode will provide a slight optimization by only running the script
# phase if any output is missing or outdated relative to any input.
# Unfortunately, it will also assume that all outputs are touched by
# the script, and if the outputs serve as files in a compilation
# phase, they will be unconditionally rebuilt. Since make might not
# rebuild everything that could be declared here as an output, this
# extra compilation activity is unnecessary. With inputPaths and
# outputPaths not supplied, make will always be called, but it knows
# enough to not do anything when everything is up-to-date.
# To help speed things up, pass -j COUNT to make so it does some work
# in parallel. Don't use ncpus because Xcode will build ncpus targets
# in parallel and if each target happens to have a rules step, there
# would be ncpus^2 things going. With a machine that has 2 quad-core
# Xeons, a build can quickly run out of processes based on
# scheduling/other tasks, and randomly failing builds are no good.
script = \
"""JOB_COUNT="$(/usr/sbin/sysctl -n hw.ncpu)"
if [ "${JOB_COUNT}" -gt 4 ]; then
JOB_COUNT=4
fi
exec xcrun make -f "${PROJECT_FILE_PATH}/%s" -j "${JOB_COUNT}"
exit 1
""" % makefile_name
ssbp = gyp.xcodeproj_file.PBXShellScriptBuildPhase({
'name': 'Rule "' + rule['rule_name'] + '"',
'shellScript': script,
'showEnvVarsInLog': 0,
})
if support_xct:
support_xct.AppendProperty('buildPhases', ssbp)
else:
# TODO(mark): this assumes too much knowledge of the internals of
# xcodeproj_file; some of these smarts should move into xcodeproj_file
# itself.
xct._properties['buildPhases'].insert(prebuild_index, ssbp)
prebuild_index = prebuild_index + 1
# Extra rule inputs also go into the project file. Concrete outputs were
# already added when they were computed.
groups = ['inputs', 'inputs_excluded']
if skip_excluded_files:
groups = [x for x in groups if not x.endswith('_excluded')]
for group in groups:
for item in rule.get(group, []):
pbxp.AddOrGetFileInRootGroup(item)
# Add "sources".
for source in spec.get('sources', []):
(source_root, source_extension) = posixpath.splitext(source)
if source_extension[1:] not in rules_by_ext:
# AddSourceToTarget will add the file to a root group if it's not
# already there.
AddSourceToTarget(source, type, pbxp, xct)
else:
pbxp.AddOrGetFileInRootGroup(source)
# Add "mac_bundle_resources" and "mac_framework_private_headers" if
# it's a bundle of any type.
if is_bundle:
for resource in tgt_mac_bundle_resources:
(resource_root, resource_extension) = posixpath.splitext(resource)
if resource_extension[1:] not in rules_by_ext:
AddResourceToTarget(resource, pbxp, xct)
else:
pbxp.AddOrGetFileInRootGroup(resource)
for header in spec.get('mac_framework_private_headers', []):
AddHeaderToTarget(header, pbxp, xct, False)
# Add "mac_framework_headers". These can be valid for both frameworks
# and static libraries.
if is_bundle or type == 'static_library':
for header in spec.get('mac_framework_headers', []):
AddHeaderToTarget(header, pbxp, xct, True)
# Add "copies".
pbxcp_dict = {}
for copy_group in spec.get('copies', []):
dest = copy_group['destination']
if dest[0] not in ('/', '$'):
# Relative paths are relative to $(SRCROOT).
dest = '$(SRCROOT)/' + dest
code_sign = int(copy_group.get('xcode_code_sign', 0))
settings = (None, '{ATTRIBUTES = (CodeSignOnCopy, ); }')[code_sign];
# Coalesce multiple "copies" sections in the same target with the same
# "destination" property into the same PBXCopyFilesBuildPhase, otherwise
# they'll wind up with ID collisions.
pbxcp = pbxcp_dict.get(dest, None)
if pbxcp is None:
pbxcp = gyp.xcodeproj_file.PBXCopyFilesBuildPhase({
'name': 'Copy to ' + copy_group['destination']
},
parent=xct)
pbxcp.SetDestination(dest)
# TODO(mark): The usual comment about this knowing too much about
# gyp.xcodeproj_file internals applies.
xct._properties['buildPhases'].insert(prebuild_index, pbxcp)
pbxcp_dict[dest] = pbxcp
for file in copy_group['files']:
pbxcp.AddFile(file, settings)
# Excluded files can also go into the project file.
if not skip_excluded_files:
for key in ['sources', 'mac_bundle_resources', 'mac_framework_headers',
'mac_framework_private_headers']:
excluded_key = key + '_excluded'
for item in spec.get(excluded_key, []):
pbxp.AddOrGetFileInRootGroup(item)
# So can "inputs" and "outputs" sections of "actions" groups.
groups = ['inputs', 'inputs_excluded', 'outputs', 'outputs_excluded']
if skip_excluded_files:
groups = [x for x in groups if not x.endswith('_excluded')]
for action in spec.get('actions', []):
for group in groups:
for item in action.get(group, []):
# Exclude anything in BUILT_PRODUCTS_DIR. They're products, not
# sources.
if not item.startswith('$(BUILT_PRODUCTS_DIR)/'):
pbxp.AddOrGetFileInRootGroup(item)
for postbuild in spec.get('postbuilds', []):
action_string_sh = gyp.common.EncodePOSIXShellList(postbuild['action'])
script = 'exec ' + action_string_sh + '\nexit 1\n'
# Make the postbuild step depend on the output of ld or ar from this
# target. Apparently putting the script step after the link step isn't
# sufficient to ensure proper ordering in all cases. With an input
# declared but no outputs, the script step should run every time, as
# desired.
ssbp = gyp.xcodeproj_file.PBXShellScriptBuildPhase({
'inputPaths': ['$(BUILT_PRODUCTS_DIR)/$(EXECUTABLE_PATH)'],
'name': 'Postbuild "' + postbuild['postbuild_name'] + '"',
'shellScript': script,
'showEnvVarsInLog': 0,
})
xct.AppendProperty('buildPhases', ssbp)
# Add dependencies before libraries, because adding a dependency may imply
# adding a library. It's preferable to keep dependencies listed first
# during a link phase so that they can override symbols that would
# otherwise be provided by libraries, which will usually include system
# libraries. On some systems, ld is finicky and even requires the
# libraries to be ordered in such a way that unresolved symbols in
# earlier-listed libraries may only be resolved by later-listed libraries.
# The Mac linker doesn't work that way, but other platforms do, and so
# their linker invocations need to be constructed in this way. There's
# no compelling reason for Xcode's linker invocations to differ.
if 'dependencies' in spec:
for dependency in spec['dependencies']:
xct.AddDependency(xcode_targets[dependency])
# The support project also gets the dependencies (in case they are
# needed for the actions/rules to work).
if support_xct:
support_xct.AddDependency(xcode_targets[dependency])
if 'libraries' in spec:
for library in spec['libraries']:
xct.FrameworksPhase().AddFile(library)
# Add the library's directory to LIBRARY_SEARCH_PATHS if necessary.
# I wish Xcode handled this automatically.
library_dir = posixpath.dirname(library)
if library_dir not in xcode_standard_library_dirs and (
not xct.HasBuildSetting(_library_search_paths_var) or
library_dir not in xct.GetBuildSetting(_library_search_paths_var)):
xct.AppendBuildSetting(_library_search_paths_var, library_dir)
for configuration_name in configuration_names:
configuration = spec['configurations'][configuration_name]
xcbc = xct.ConfigurationNamed(configuration_name)
for include_dir in configuration.get('mac_framework_dirs', []):
xcbc.AppendBuildSetting('FRAMEWORK_SEARCH_PATHS', include_dir)
for include_dir in configuration.get('include_dirs', []):
xcbc.AppendBuildSetting('HEADER_SEARCH_PATHS', include_dir)
for library_dir in configuration.get('library_dirs', []):
if library_dir not in xcode_standard_library_dirs and (
not xcbc.HasBuildSetting(_library_search_paths_var) or
library_dir not in xcbc.GetBuildSetting(_library_search_paths_var)):
xcbc.AppendBuildSetting(_library_search_paths_var, library_dir)
if 'defines' in configuration:
for define in configuration['defines']:
set_define = EscapeXcodeDefine(define)
xcbc.AppendBuildSetting('GCC_PREPROCESSOR_DEFINITIONS', set_define)
if 'xcode_settings' in configuration:
for xck, xcv in configuration['xcode_settings'].iteritems():
xcbc.SetBuildSetting(xck, xcv)
if 'xcode_config_file' in configuration:
config_ref = pbxp.AddOrGetFileInRootGroup(
configuration['xcode_config_file'])
xcbc.SetBaseConfiguration(config_ref)
build_files = []
for build_file, build_file_dict in data.iteritems():
if build_file.endswith('.gyp'):
build_files.append(build_file)
for build_file in build_files:
xcode_projects[build_file].Finalize1(xcode_targets, serialize_all_tests)
for build_file in build_files:
xcode_projects[build_file].Finalize2(xcode_targets,
xcode_target_to_target_dict)
for build_file in build_files:
xcode_projects[build_file].Write()
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
570,
5730,
199,
646,
4902,
14,
2330,
199,
646,
4902,
14,
29286,
63,
493,
199,
646,
4902,
14,
8701,
63,
8675,
199,
646,
7554,
199,
646,
747,
199,
646,
984,
199,
646,
15454,
199,
646,
295,
199,
646,
5145,
199,
646,
3873,
199,
646,
5549,
421,
199,
3,
7290,
1584,
4046,
701,
642,
859,
911,
675,
485,
15940,
63,
1391,
465,
282,
199,
3,
3537,
10602,
4260,
7447,
574,
365,
282,
27731,
13959,
13,
2930,
2082,
626,
1159,
199,
3,
2199,
13,
6100,
436,
2897,
13,
6100,
14,
221,
710,
3293,
7141,
12,
199,
3,
577,
540,
30487,
63,
3817,
63,
3022,
12,
365,
1347,
13,
6100,
12,
1314,
365,
32463,
370,
506,
4634,
7213,
6648,
199,
3,
465,
652,
365,
12060,
626,
3663,
4545,
4453,
282,
2849,
2199,
570,
911,
2934,
199,
3,
370,
2879,
314,
2011,
663,
402,
4046,
1584,
14,
221,
710,
1163,
945,
12,
199,
3,
21915,
63,
11733,
30487,
63,
3817,
63,
3022,
12,
365,
625,
83,
10020,
2952,
1830,
652,
365,
2199,
13,
6100,
12,
199,
3,
652,
365,
440,
2897,
13,
6100,
14,
221,
8729,
19464,
63,
3022,
365,
3247,
465,
199,
3,
7714,
10797,
63,
11733,
30487,
63,
3817,
63,
3022,
2447,
6629,
22212,
680,
199,
63,
15940,
63,
1391,
275,
283,
23227,
63,
3022,
7,
199,
199,
3,
4410,
689,
1149,
63,
23227,
63,
3022,
365,
314,
2011,
12,
871,
626,
652,
365,
5709,
16885,
1006,
199,
3,
4545,
626,
8663,
314,
2011,
16331,
1193,
52,
63,
14853,
51,
63,
3022,
14,
199,
63,
5555,
63,
15940,
63,
1391,
275,
283,
13772,
63,
23227,
63,
3022,
7,
199,
199,
63,
4342,
63,
1733,
63,
3771,
63,
1391,
275,
283,
16983,
63,
15962,
63,
20202,
7,
199,
199,
4679,
63,
885,
63,
3669,
275,
469,
523,
283,
21623,
63,
6351,
356,
3260,
523,
283,
21623,
63,
12273,
356,
3260,
523,
283,
10449,
63,
5617,
63,
6351,
356,
283,
773,
297,
523,
283,
13772,
63,
5617,
63,
6351,
356,
283,
773,
297,
523,
283,
10449,
63,
5617,
63,
12273,
356,
1987,
65,
297,
523,
283,
13772,
63,
5617,
63,
12273,
356,
1987,
22305,
297,
523,
327,
8729,
19464,
63,
3022,
365,
282,
4192,
367,
4545,
370,
1900,
1536,
13197,
7585,
14,
523,
327,
2779,
365,
2488,
370,
1924,
1900,
3734,
14,
221,
2779,
365,
1454,
17334,
370,
2187,
523,
327,
436,
506,
4413,
4453,
314,
1067,
402,
282,
2199,
12,
5226,
370,
282,
2849,
523,
327,
1324,
570,
14,
221,
6601,
1900,
22196,
1443,
2040,
3932,
13197,
2082,
523,
327,
370,
506,
5709,
641,
282,
26038,
424,
4666,
12,
1325,
642,
365,
440,
17334,
14,
523,
283,
23227,
63,
3022,
356,
4505,
4042,
83,
3171,
450,
485,
15940,
63,
1391,
12,
523,
283,
3100,
356,
283,
3088,
297,
523,
283,
14853,
63,
3022,
356,
9774,
18637,
52,
63,
14853,
51,
63,
3022,
3196,
523,
283,
5617,
63,
3022,
356,
9774,
18637,
52,
63,
14853,
51,
63,
3022,
3196,
523,
283,
13578,
63,
7321,
63,
5441,
356,
9774,
7321,
63,
3817,
63,
5825,
3196,
523,
283,
13578,
63,
7321,
63,
2472,
356,
9774,
7321,
63,
3817,
63,
12273,
3196,
523,
283,
13578,
63,
7321,
63,
2339,
356,
9774,
7321,
63,
3817,
63,
2339,
3196,
523,
283,
13578,
63,
7321,
63,
3243,
356,
9774,
7321,
63,
3817,
63,
3243,
3196,
523,
283,
13578,
63,
7321,
63,
3022,
2339,
356,
9774,
7321,
63,
3817,
63,
3022,
2339,
3196,
523,
283,
13772,
63,
23227,
63,
3022,
356,
4505,
4042,
83,
3171,
450,
485,
5555,
63,
15940,
63,
1391,
12,
523,
283,
22212,
63,
2339,
356,
9774,
22212,
3196,
199,
93,
199,
199,
3,
710,
10602,
13,
6100,
10189,
626,
10266,
3792,
14,
199,
4679,
63,
8460,
63,
515,
63,
7786,
275,
359,
523,
283,
3088,
63,
6469,
63,
4435,
297,
523,
283,
3088,
63,
4857,
63,
2139,
297,
523,
283,
3088,
63,
4857,
63,
4239,
63,
2139,
297,
523,
327,
283,
3088,
63,
4857,
63,
3220,
297,
1324,
2575,
10022,
485,
3220,
1284,
780,
14,
199,
61,
199,
199,
3,
710,
10602,
13,
6100,
2883,
626,
2187,
641,
4545,
436,
10621,
1133,
12155,
3224,
370,
199,
3,
13422,
14,
199,
4679,
63,
8460,
63,
2865,
63,
4758,
63,
1612,
275,
359,
523,
283,
9207,
63,
571,
63,
3435,
297,
523,
283,
9207,
63,
6821,
63,
571,
297,
523,
283,
9207,
63,
6821,
6065,
63,
3435,
297,
523,
283,
3088,
63,
6469,
297,
523,
283,
3088,
63,
6469,
63,
4435,
297,
523,
283,
3088,
63,
4857,
63,
2139,
297,
523,
283,
3088,
63,
4857,
63,
4239,
63,
2139,
297,
523,
283,
3088,
63,
1812,
396,
63,
6469,
297,
523,
283,
8701,
63,
981,
63,
32333,
63,
396,
63,
5933,
297,
199,
61,
199,
199,
3,
2136,
2934,
370,
4691,
1263,
4713,
4838,
370,
1584,
626,
787,
5944,
2597,
14,
199,
4679,
63,
2911,
63,
4553,
63,
509,
63,
4423,
275,
359,
523,
283,
3088,
63,
6469,
63,
4435,
297,
523,
283,
3088,
63,
4857,
63,
2139,
297,
523,
283,
3088,
63,
4857,
63,
4239,
63,
2139,
297,
199,
61,
199,
199,
3,
10602,
1159,
4465,
663,
402,
3555,
6602,
12,
1314,
2793,
1133,
1929,
370,
506,
21747,
199,
3,
315,
25764,
50,
4392,
63,
15962,
63,
20202,
14,
961,
769,
365,
440,
21354,
833,
1912,
12,
1325,
626,
1159,
5849,
14,
199,
8701,
63,
6807,
63,
4342,
63,
3220,
275,
9522,
779,
523,
9774,
14939,
5441,
2447,
2647,
15,
773,
297,
523,
9774,
14939,
5441,
2447,
2647,
15,
1832,
15,
773,
297,
199,
566,
199,
199,
318,
2790,
20770,
26454,
8,
4758,
63,
1247,
304,
523,
20399,
429,
275,
4902,
14,
29286,
63,
493,
14,
20770,
26454,
3252,
1506,
25808,
356,
942,
1552,
523,
340,
822,
8,
4758,
63,
1247,
9,
508,
378,
26,
272,
2897,
63,
1247,
275,
788,
2698,
418,
523,
367,
2897,
63,
354,
315,
2897,
63,
1247,
26,
272,
671,
19279,
275,
4902,
14,
29286,
63,
493,
14,
20770,
3425,
5688,
2561,
267,
283,
354,
356
] |
[
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
570,
5730,
199,
646,
4902,
14,
2330,
199,
646,
4902,
14,
29286,
63,
493,
199,
646,
4902,
14,
8701,
63,
8675,
199,
646,
7554,
199,
646,
747,
199,
646,
984,
199,
646,
15454,
199,
646,
295,
199,
646,
5145,
199,
646,
3873,
199,
646,
5549,
421,
199,
3,
7290,
1584,
4046,
701,
642,
859,
911,
675,
485,
15940,
63,
1391,
465,
282,
199,
3,
3537,
10602,
4260,
7447,
574,
365,
282,
27731,
13959,
13,
2930,
2082,
626,
1159,
199,
3,
2199,
13,
6100,
436,
2897,
13,
6100,
14,
221,
710,
3293,
7141,
12,
199,
3,
577,
540,
30487,
63,
3817,
63,
3022,
12,
365,
1347,
13,
6100,
12,
1314,
365,
32463,
370,
506,
4634,
7213,
6648,
199,
3,
465,
652,
365,
12060,
626,
3663,
4545,
4453,
282,
2849,
2199,
570,
911,
2934,
199,
3,
370,
2879,
314,
2011,
663,
402,
4046,
1584,
14,
221,
710,
1163,
945,
12,
199,
3,
21915,
63,
11733,
30487,
63,
3817,
63,
3022,
12,
365,
625,
83,
10020,
2952,
1830,
652,
365,
2199,
13,
6100,
12,
199,
3,
652,
365,
440,
2897,
13,
6100,
14,
221,
8729,
19464,
63,
3022,
365,
3247,
465,
199,
3,
7714,
10797,
63,
11733,
30487,
63,
3817,
63,
3022,
2447,
6629,
22212,
680,
199,
63,
15940,
63,
1391,
275,
283,
23227,
63,
3022,
7,
199,
199,
3,
4410,
689,
1149,
63,
23227,
63,
3022,
365,
314,
2011,
12,
871,
626,
652,
365,
5709,
16885,
1006,
199,
3,
4545,
626,
8663,
314,
2011,
16331,
1193,
52,
63,
14853,
51,
63,
3022,
14,
199,
63,
5555,
63,
15940,
63,
1391,
275,
283,
13772,
63,
23227,
63,
3022,
7,
199,
199,
63,
4342,
63,
1733,
63,
3771,
63,
1391,
275,
283,
16983,
63,
15962,
63,
20202,
7,
199,
199,
4679,
63,
885,
63,
3669,
275,
469,
523,
283,
21623,
63,
6351,
356,
3260,
523,
283,
21623,
63,
12273,
356,
3260,
523,
283,
10449,
63,
5617,
63,
6351,
356,
283,
773,
297,
523,
283,
13772,
63,
5617,
63,
6351,
356,
283,
773,
297,
523,
283,
10449,
63,
5617,
63,
12273,
356,
1987,
65,
297,
523,
283,
13772,
63,
5617,
63,
12273,
356,
1987,
22305,
297,
523,
327,
8729,
19464,
63,
3022,
365,
282,
4192,
367,
4545,
370,
1900,
1536,
13197,
7585,
14,
523,
327,
2779,
365,
2488,
370,
1924,
1900,
3734,
14,
221,
2779,
365,
1454,
17334,
370,
2187,
523,
327,
436,
506,
4413,
4453,
314,
1067,
402,
282,
2199,
12,
5226,
370,
282,
2849,
523,
327,
1324,
570,
14,
221,
6601,
1900,
22196,
1443,
2040,
3932,
13197,
2082,
523,
327,
370,
506,
5709,
641,
282,
26038,
424,
4666,
12,
1325,
642,
365,
440,
17334,
14,
523,
283,
23227,
63,
3022,
356,
4505,
4042,
83,
3171,
450,
485,
15940,
63,
1391,
12,
523,
283,
3100,
356,
283,
3088,
297,
523,
283,
14853,
63,
3022,
356,
9774,
18637,
52,
63,
14853,
51,
63,
3022,
3196,
523,
283,
5617,
63,
3022,
356,
9774,
18637,
52,
63,
14853,
51,
63,
3022,
3196,
523,
283,
13578,
63,
7321,
63,
5441,
356,
9774,
7321,
63,
3817,
63,
5825,
3196,
523,
283,
13578,
63,
7321,
63,
2472,
356,
9774,
7321,
63,
3817,
63,
12273,
3196,
523,
283,
13578,
63,
7321,
63,
2339,
356,
9774,
7321,
63,
3817,
63,
2339,
3196,
523,
283,
13578,
63,
7321,
63,
3243,
356,
9774,
7321,
63,
3817,
63,
3243,
3196,
523,
283,
13578,
63,
7321,
63,
3022,
2339,
356,
9774,
7321,
63,
3817,
63,
3022,
2339,
3196,
523,
283,
13772,
63,
23227,
63,
3022,
356,
4505,
4042,
83,
3171,
450,
485,
5555,
63,
15940,
63,
1391,
12,
523,
283,
22212,
63,
2339,
356,
9774,
22212,
3196,
199,
93,
199,
199,
3,
710,
10602,
13,
6100,
10189,
626,
10266,
3792,
14,
199,
4679,
63,
8460,
63,
515,
63,
7786,
275,
359,
523,
283,
3088,
63,
6469,
63,
4435,
297,
523,
283,
3088,
63,
4857,
63,
2139,
297,
523,
283,
3088,
63,
4857,
63,
4239,
63,
2139,
297,
523,
327,
283,
3088,
63,
4857,
63,
3220,
297,
1324,
2575,
10022,
485,
3220,
1284,
780,
14,
199,
61,
199,
199,
3,
710,
10602,
13,
6100,
2883,
626,
2187,
641,
4545,
436,
10621,
1133,
12155,
3224,
370,
199,
3,
13422,
14,
199,
4679,
63,
8460,
63,
2865,
63,
4758,
63,
1612,
275,
359,
523,
283,
9207,
63,
571,
63,
3435,
297,
523,
283,
9207,
63,
6821,
63,
571,
297,
523,
283,
9207,
63,
6821,
6065,
63,
3435,
297,
523,
283,
3088,
63,
6469,
297,
523,
283,
3088,
63,
6469,
63,
4435,
297,
523,
283,
3088,
63,
4857,
63,
2139,
297,
523,
283,
3088,
63,
4857,
63,
4239,
63,
2139,
297,
523,
283,
3088,
63,
1812,
396,
63,
6469,
297,
523,
283,
8701,
63,
981,
63,
32333,
63,
396,
63,
5933,
297,
199,
61,
199,
199,
3,
2136,
2934,
370,
4691,
1263,
4713,
4838,
370,
1584,
626,
787,
5944,
2597,
14,
199,
4679,
63,
2911,
63,
4553,
63,
509,
63,
4423,
275,
359,
523,
283,
3088,
63,
6469,
63,
4435,
297,
523,
283,
3088,
63,
4857,
63,
2139,
297,
523,
283,
3088,
63,
4857,
63,
4239,
63,
2139,
297,
199,
61,
199,
199,
3,
10602,
1159,
4465,
663,
402,
3555,
6602,
12,
1314,
2793,
1133,
1929,
370,
506,
21747,
199,
3,
315,
25764,
50,
4392,
63,
15962,
63,
20202,
14,
961,
769,
365,
440,
21354,
833,
1912,
12,
1325,
626,
1159,
5849,
14,
199,
8701,
63,
6807,
63,
4342,
63,
3220,
275,
9522,
779,
523,
9774,
14939,
5441,
2447,
2647,
15,
773,
297,
523,
9774,
14939,
5441,
2447,
2647,
15,
1832,
15,
773,
297,
199,
566,
199,
199,
318,
2790,
20770,
26454,
8,
4758,
63,
1247,
304,
523,
20399,
429,
275,
4902,
14,
29286,
63,
493,
14,
20770,
26454,
3252,
1506,
25808,
356,
942,
1552,
523,
340,
822,
8,
4758,
63,
1247,
9,
508,
378,
26,
272,
2897,
63,
1247,
275,
788,
2698,
418,
523,
367,
2897,
63,
354,
315,
2897,
63,
1247,
26,
272,
671,
19279,
275,
4902,
14,
29286,
63,
493,
14,
20770,
3425,
5688,
2561,
267,
283,
354,
356,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
switchkiller/ProjDjanko
|
lib/python2.7/site-packages/pip/_vendor/requests/packages/chardet/mbcharsetprober.py
|
2924
|
3268
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Universal charset detector code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 2001
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - port to Python
# Shy Shalom - original C code
# Proofpoint, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
import sys
from . import constants
from .charsetprober import CharSetProber
class MultiByteCharSetProber(CharSetProber):
def __init__(self):
CharSetProber.__init__(self)
self._mDistributionAnalyzer = None
self._mCodingSM = None
self._mLastChar = [0, 0]
def reset(self):
CharSetProber.reset(self)
if self._mCodingSM:
self._mCodingSM.reset()
if self._mDistributionAnalyzer:
self._mDistributionAnalyzer.reset()
self._mLastChar = [0, 0]
def get_charset_name(self):
pass
def feed(self, aBuf):
aLen = len(aBuf)
for i in range(0, aLen):
codingState = self._mCodingSM.next_state(aBuf[i])
if codingState == constants.eError:
if constants._debug:
sys.stderr.write(self.get_charset_name()
+ ' prober hit error at byte ' + str(i)
+ '\n')
self._mState = constants.eNotMe
break
elif codingState == constants.eItsMe:
self._mState = constants.eFoundIt
break
elif codingState == constants.eStart:
charLen = self._mCodingSM.get_current_charlen()
if i == 0:
self._mLastChar[1] = aBuf[0]
self._mDistributionAnalyzer.feed(self._mLastChar, charLen)
else:
self._mDistributionAnalyzer.feed(aBuf[i - 1:i + 1],
charLen)
self._mLastChar[0] = aBuf[aLen - 1]
if self.get_state() == constants.eDetecting:
if (self._mDistributionAnalyzer.got_enough_data() and
(self.get_confidence() > constants.SHORTCUT_THRESHOLD)):
self._mState = constants.eFoundIt
return self.get_state()
def get_confidence(self):
return self._mDistributionAnalyzer.get_confidence()
|
gpl-2.0
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
29347,
5960,
17842,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
12521,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
257,
428,
3577,
5244,
279,
676,
446,
3379,
445,
1233,
199,
3,
257,
2165,
1618,
1403,
12,
3277,
14,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
646,
984,
199,
504,
1275,
492,
5262,
199,
504,
1275,
6043,
19903,
492,
31727,
421,
199,
533,
6879,
21312,
8,
15159,
304,
272,
347,
636,
826,
721,
277,
304,
267,
31727,
855,
826,
721,
277,
9,
267,
291,
423,
77,
8580,
17606,
275,
488,
267,
291,
423,
29633,
275,
488,
267,
291,
423,
30875,
275,
359,
16,
12,
378,
61,
339,
347,
5305,
8,
277,
304,
267,
31727,
14,
3958,
8,
277,
9,
267,
340,
291,
423,
29633,
26,
288,
291,
423,
29633,
14,
3958,
342,
267,
340,
291,
423,
77,
8580,
17606,
26,
288,
291,
423,
77,
8580,
17606,
14,
3958,
342,
267,
291,
423,
30875,
275,
359,
16,
12,
378,
61,
339,
347,
664,
63,
6043,
63,
354,
8,
277,
304,
267,
986,
339,
347,
4733,
8,
277,
12,
17407,
304,
267,
282,
3166,
275,
822,
8,
22353,
9,
267,
367,
284,
315,
1425,
8,
16,
12,
282,
3166,
304,
288,
2803,
2223,
275,
291,
423,
29633,
14,
2184,
63,
929,
8,
22353,
59,
73,
566,
288,
340,
2803,
2223,
508,
5262,
14,
6259,
26,
355,
340,
5262,
423,
1757,
26,
490,
984,
14,
3083,
14,
952,
8,
277,
14,
362,
63,
6043,
63,
354,
342,
3660,
435,
283,
16118,
9793,
1125,
737,
3696,
283,
435,
620,
8,
73,
9,
3660,
435,
1557,
78,
358,
355,
291,
423,
31984,
275,
5262,
14,
69,
1763,
1352,
355,
2059,
288,
916,
2803,
2223,
508,
5262,
14,
13241,
26,
355,
291,
423,
31984,
275,
5262,
14,
69,
3601,
7940,
355,
2059,
288,
916,
2803,
2223,
508,
5262,
14,
11724,
26,
355,
29205,
275,
291,
423,
29633,
14,
362,
63,
1818,
63,
1560,
552,
342,
355,
340,
284,
508,
378,
26,
490,
291,
423,
30875,
59,
17,
61,
275,
17407,
59,
16,
61,
490,
291,
423,
77,
8580,
17606,
14,
3871,
8,
277,
423,
30875,
12,
29205,
9,
355,
587,
26,
490,
291,
423,
77,
8580,
17606,
14,
3871,
8,
22353,
59,
73,
446,
413,
26,
73,
435,
413,
467,
9349,
29205,
9,
398,
291,
423,
30875,
59,
16,
61,
275,
17407,
59,
65,
3166,
446,
413,
61,
398,
340,
291,
14,
362,
63,
929,
342,
508,
5262,
14,
69,
20064,
316,
26,
288,
340,
334,
277,
423,
77,
8580,
17606,
14,
7808,
63,
30881,
63,
576,
342,
436,
490,
334,
277,
14,
362,
63,
13969,
342,
690,
5262,
14,
13003,
24678,
63,
19307,
2298,
355,
291,
423,
31984,
275,
5262,
14,
69,
3601,
7940,
398,
372,
291,
14,
362,
63,
929,
342,
339,
347,
664,
63,
13969,
8,
277,
304,
267,
372,
291,
423,
77,
8580,
17606,
14,
362,
63,
13969,
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
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
29347,
5960,
17842,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
12521,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
257,
428,
3577,
5244,
279,
676,
446,
3379,
445,
1233,
199,
3,
257,
2165,
1618,
1403,
12,
3277,
14,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
646,
984,
199,
504,
1275,
492,
5262,
199,
504,
1275,
6043,
19903,
492,
31727,
421,
199,
533,
6879,
21312,
8,
15159,
304,
272,
347,
636,
826,
721,
277,
304,
267,
31727,
855,
826,
721,
277,
9,
267,
291,
423,
77,
8580,
17606,
275,
488,
267,
291,
423,
29633,
275,
488,
267,
291,
423,
30875,
275,
359,
16,
12,
378,
61,
339,
347,
5305,
8,
277,
304,
267,
31727,
14,
3958,
8,
277,
9,
267,
340,
291,
423,
29633,
26,
288,
291,
423,
29633,
14,
3958,
342,
267,
340,
291,
423,
77,
8580,
17606,
26,
288,
291,
423,
77,
8580,
17606,
14,
3958,
342,
267,
291,
423,
30875,
275,
359,
16,
12,
378,
61,
339,
347,
664,
63,
6043,
63,
354,
8,
277,
304,
267,
986,
339,
347,
4733,
8,
277,
12,
17407,
304,
267,
282,
3166,
275,
822,
8,
22353,
9,
267,
367,
284,
315,
1425,
8,
16,
12,
282,
3166,
304,
288,
2803,
2223,
275,
291,
423,
29633,
14,
2184,
63,
929,
8,
22353,
59,
73,
566,
288,
340,
2803,
2223,
508,
5262,
14,
6259,
26,
355,
340,
5262,
423,
1757,
26,
490,
984,
14,
3083,
14,
952,
8,
277,
14,
362,
63,
6043,
63,
354,
342,
3660,
435,
283,
16118,
9793,
1125,
737,
3696,
283,
435,
620,
8,
73,
9,
3660,
435,
1557,
78,
358,
355,
291,
423,
31984,
275,
5262,
14,
69,
1763,
1352,
355,
2059,
288,
916,
2803,
2223,
508,
5262,
14,
13241,
26,
355,
291,
423,
31984,
275,
5262,
14,
69,
3601,
7940,
355,
2059,
288,
916,
2803,
2223,
508,
5262,
14,
11724,
26,
355,
29205,
275,
291,
423,
29633,
14,
362,
63,
1818,
63,
1560,
552,
342,
355,
340,
284,
508,
378,
26,
490,
291,
423,
30875,
59,
17,
61,
275,
17407,
59,
16,
61,
490,
291,
423,
77,
8580,
17606,
14,
3871,
8,
277,
423,
30875,
12,
29205,
9,
355,
587,
26,
490,
291,
423,
77,
8580,
17606,
14,
3871,
8,
22353,
59,
73,
446,
413,
26,
73,
435,
413,
467,
9349,
29205,
9,
398,
291,
423,
30875,
59,
16,
61,
275,
17407,
59,
65,
3166,
446,
413,
61,
398,
340,
291,
14,
362,
63,
929,
342,
508,
5262,
14,
69,
20064,
316,
26,
288,
340,
334,
277,
423,
77,
8580,
17606,
14,
7808,
63,
30881,
63,
576,
342,
436,
490,
334,
277,
14,
362,
63,
13969,
342,
690,
5262,
14,
13003,
24678,
63,
19307,
2298,
355,
291,
423,
31984,
275,
5262,
14,
69,
3601,
7940,
398,
372,
291,
14,
362,
63,
929,
342,
339,
347,
664,
63,
13969,
8,
277,
304,
267,
372,
291,
423,
77,
8580,
17606,
14,
362,
63,
13969,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tboyce021/home-assistant
|
tests/components/google_assistant/test_http.py
|
13
|
6469
|
"""Test Google http services."""
from datetime import datetime, timedelta, timezone
from homeassistant.components.google_assistant import GOOGLE_ASSISTANT_SCHEMA
from homeassistant.components.google_assistant.const import (
HOMEGRAPH_TOKEN_URL,
REPORT_STATE_BASE_URL,
)
from homeassistant.components.google_assistant.http import (
GoogleConfig,
_get_homegraph_jwt,
_get_homegraph_token,
)
from tests.async_mock import ANY, patch
DUMMY_CONFIG = GOOGLE_ASSISTANT_SCHEMA(
{
"project_id": "1234",
"service_account": {
"private_key": "-----BEGIN PRIVATE KEY-----\nMIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKYscIlwm7soDsHAz6L6YvUkCvkrX19rS6yeYOmovvhoK5WeYGWUsd8V72zmsyHB7XO94YgJVjvxfzn5K8bLePjFzwoSJjZvhBJ/ZQ05d8VmbvgyWUoPdG9oEa4fZ/lCYrXoaFdTot2xcJvrb/ZuiRl4s4eZpNeFYvVK/Am7UeFPAgMBAAECgYAUetOfzLYUudofvPCaKHu7tKZ5kQPfEa0w6BAPnBF1Mfl1JiDBRDMryFtKs6AOIAVwx00dY/Ex0BCbB3+Cr58H7t4NaPTJxCpmR09pK7o17B7xAdQv8+SynFNud9/5vQ5AEXMOLNwKiU7wpXT6Z7ZIibUBOR7ewsWgsHCDpN1iqQJBAOMODPTPSiQMwRAUHIc6GPleFSJnIz2PAoG3JOG9KFAL6RtIc19lob2ZXdbQdzKtjSkWo+O5W20WDNAl1k32h6MCQQC7W4ZCIY67mPbL6CxXfHjpSGF4Dr9VWJ7ZrKHr6XUoOIcEvsn/pHvWonjMdy93rQMSfOE8BKd/I1+GHRmNVgplAkAnSo4paxmsZVyfeKt7Jy2dMY+8tVZe17maUuQaAE7Sk00SgJYegwrbMYgQnWCTL39HBfj0dmYA2Zj8CCAuu6O7AkEAryFiYjaUAO9+4iNoL27+ZrFtypeeadyov7gKs0ZKaQpNyzW8A+Zwi7TbTeSqzic/E+z/bOa82q7p/6b7141xsQJBANCAcIwMcVb6KVCHlQbOtKspo5Eh4ZQi8bGl+IcwbQ6JSxeTx915IfAldgbuU047wOB04dYCFB2yLDiUGVXTifU=\n-----END PRIVATE KEY-----\n",
"client_email": "dummy@dummy.iam.gserviceaccount.com",
},
}
)
MOCK_TOKEN = {"access_token": "dummtoken", "expires_in": 3600}
MOCK_JSON = {"devices": {}}
MOCK_URL = "https://dummy"
MOCK_HEADER = {
"Authorization": f"Bearer {MOCK_TOKEN['access_token']}",
"X-GFE-SSL": "yes",
}
async def test_get_jwt(hass):
"""Test signing of key."""
jwt = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJkdW1teUBkdW1teS5pYW0uZ3NlcnZpY2VhY2NvdW50LmNvbSIsInNjb3BlIjoiaHR0cHM6Ly93d3cuZ29vZ2xlYXBpcy5jb20vYXV0aC9ob21lZ3JhcGgiLCJhdWQiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20vby9vYXV0aDIvdG9rZW4iLCJpYXQiOjE1NzEwMTEyMDAsImV4cCI6MTU3MTAxNDgwMH0.gG06SmY-zSvFwSrdFfqIdC6AnC22rwz-d2F2UDeWbywjdmFL_1zceL-OOLBwjD8MJr6nR0kmN_Osu7ml9-EzzZjJqsRUxMjGn2G8nSYHbv16R4FYIp62Ibvt6Jj_wdFobEPoy_5OJ28P5Hdu0giGMlFBJMy0Tc6MgEDZA-cwOBw"
res = _get_homegraph_jwt(
datetime(2019, 10, 14, tzinfo=timezone.utc),
DUMMY_CONFIG["service_account"]["client_email"],
DUMMY_CONFIG["service_account"]["private_key"],
)
assert res == jwt
async def test_get_access_token(hass, aioclient_mock):
"""Test the function to get access token."""
jwt = "dummyjwt"
aioclient_mock.post(
HOMEGRAPH_TOKEN_URL,
status=200,
json={"access_token": "1234", "expires_in": 3600},
)
await _get_homegraph_token(hass, jwt)
assert aioclient_mock.call_count == 1
assert aioclient_mock.mock_calls[0][3] == {
"Authorization": f"Bearer {jwt}",
"Content-Type": "application/x-www-form-urlencoded",
}
async def test_update_access_token(hass):
"""Test the function to update access token when expired."""
jwt = "dummyjwt"
config = GoogleConfig(hass, DUMMY_CONFIG)
await config.async_initialize()
base_time = datetime(2019, 10, 14, tzinfo=timezone.utc)
with patch(
"homeassistant.components.google_assistant.http._get_homegraph_token"
) as mock_get_token, patch(
"homeassistant.components.google_assistant.http._get_homegraph_jwt"
) as mock_get_jwt, patch(
"homeassistant.core.dt_util.utcnow"
) as mock_utcnow:
mock_utcnow.return_value = base_time
mock_get_jwt.return_value = jwt
mock_get_token.return_value = MOCK_TOKEN
await config._async_update_token()
mock_get_token.assert_called_once()
mock_get_token.reset_mock()
mock_utcnow.return_value = base_time + timedelta(seconds=3600)
await config._async_update_token()
mock_get_token.assert_not_called()
mock_get_token.reset_mock()
mock_utcnow.return_value = base_time + timedelta(seconds=3601)
await config._async_update_token()
mock_get_token.assert_called_once()
async def test_call_homegraph_api(hass, aioclient_mock, hass_storage):
"""Test the function to call the homegraph api."""
config = GoogleConfig(hass, DUMMY_CONFIG)
await config.async_initialize()
with patch(
"homeassistant.components.google_assistant.http._get_homegraph_token"
) as mock_get_token:
mock_get_token.return_value = MOCK_TOKEN
aioclient_mock.post(MOCK_URL, status=200, json={})
res = await config.async_call_homegraph_api(MOCK_URL, MOCK_JSON)
assert res == 200
assert mock_get_token.call_count == 1
assert aioclient_mock.call_count == 1
call = aioclient_mock.mock_calls[0]
assert call[2] == MOCK_JSON
assert call[3] == MOCK_HEADER
async def test_call_homegraph_api_retry(hass, aioclient_mock, hass_storage):
"""Test the that the calls get retried with new token on 401."""
config = GoogleConfig(hass, DUMMY_CONFIG)
await config.async_initialize()
with patch(
"homeassistant.components.google_assistant.http._get_homegraph_token"
) as mock_get_token:
mock_get_token.return_value = MOCK_TOKEN
aioclient_mock.post(MOCK_URL, status=401, json={})
await config.async_call_homegraph_api(MOCK_URL, MOCK_JSON)
assert mock_get_token.call_count == 2
assert aioclient_mock.call_count == 2
call = aioclient_mock.mock_calls[0]
assert call[2] == MOCK_JSON
assert call[3] == MOCK_HEADER
call = aioclient_mock.mock_calls[1]
assert call[2] == MOCK_JSON
assert call[3] == MOCK_HEADER
async def test_report_state(hass, aioclient_mock, hass_storage):
"""Test the report state function."""
agent_user_id = "user"
config = GoogleConfig(hass, DUMMY_CONFIG)
await config.async_initialize()
await config.async_connect_agent_user(agent_user_id)
message = {"devices": {}}
with patch.object(config, "async_call_homegraph_api") as mock_call:
await config.async_report_state(message, agent_user_id)
mock_call.assert_called_once_with(
REPORT_STATE_BASE_URL,
{"requestId": ANY, "agentUserId": agent_user_id, "payload": message},
)
|
apache-2.0
|
[
624,
774,
4475,
1455,
8500,
1041,
199,
504,
2197,
492,
2197,
12,
6871,
12,
7137,
199,
199,
504,
8846,
14,
4608,
14,
3098,
63,
7310,
492,
9173,
12827,
63,
16435,
840,
1441,
63,
10926,
199,
504,
8846,
14,
4608,
14,
3098,
63,
7310,
14,
1297,
492,
334,
272,
7781,
3635,
25302,
63,
8803,
63,
2632,
12,
272,
27357,
63,
6689,
63,
5825,
63,
2632,
12,
199,
9,
199,
504,
8846,
14,
4608,
14,
3098,
63,
7310,
14,
1014,
492,
334,
272,
4475,
2028,
12,
272,
485,
362,
63,
4219,
2180,
63,
30033,
12,
272,
485,
362,
63,
4219,
2180,
63,
1418,
12,
199,
9,
199,
199,
504,
2295,
14,
4146,
63,
1805,
492,
1821,
12,
3371,
199,
199,
26778,
63,
5569,
275,
9173,
12827,
63,
16435,
840,
1441,
63,
10926,
8,
272,
469,
267,
298,
1715,
63,
344,
582,
298,
4321,
401,
267,
298,
1364,
63,
2048,
582,
469,
288,
298,
4239,
63,
498,
582,
298,
9858,
15947,
28644,
1951,
9301,
375,
2696,
78,
10709,
948,
10772,
2100,
1554,
879,
23571,
75,
81,
72,
8810,
39,
25,
87,
16,
4134,
31668,
2078,
1179,
3263,
77,
37,
87,
2721,
42,
68,
5676,
37,
2276,
79,
39,
4134,
32640,
551,
27965,
16240,
23,
1152,
26606,
6294,
90,
22,
44,
22,
57,
86,
53,
75,
35,
86,
16779,
56,
1167,
82,
51,
22,
8048,
57,
47,
573,
8958,
526,
43,
21,
6004,
57,
19674,
53,
3893,
24,
54,
2819,
90,
706,
89,
25262,
23,
56,
47,
2635,
57,
71,
42,
54,
24989,
1949,
31591,
21,
43,
24,
66,
2553,
48,
74,
38,
90,
2027,
51,
42,
74,
58,
20369,
16262,
15,
58,
49,
1717,
68,
24,
54,
887,
86,
4312,
55,
53,
79,
48,
28929,
25,
79,
37,
65,
20,
70,
58,
15,
76,
15068,
82,
56,
20047,
38,
19772,
357,
18,
1812,
42,
86,
4848,
15,
58,
1907,
50,
76,
20,
83,
20,
69,
58,
80,
4698,
18114,
86,
19327,
15,
24566,
23,
53,
69,
17095,
5676,
4567,
2276,
4220,
71,
57,
9331,
386,
3466,
90,
6084,
53,
5916,
13692,
48,
3630,
43,
25542,
23,
84,
43,
58,
21,
75,
31208,
70,
37,
65,
16,
87,
22,
34,
1282,
78,
12659,
17,
45,
2327,
17,
16911,
2846,
15543,
45,
651,
38,
84,
43,
83,
22,
23320,
41,
6087,
6323,
383,
68,
57,
15,
920,
16,
6265,
66,
34,
19,
11,
17345,
2010,
40,
23,
84,
20,
8565,
4189,
42,
8163,
7073,
50,
1643,
80,
43,
23,
79,
1196,
34,
23,
88,
2767,
49,
86,
24,
11,
17746,
4963,
1181,
25,
15,
21,
86,
49,
21,
33,
1438,
45,
2228,
46,
87,
32198,
53,
23,
14649,
18926,
22,
58,
23,
58,
41,
1892,
2533,
726,
23,
546,
83,
55,
458,
40,
7695,
80,
46,
17,
9962,
49,
42,
4134,
47,
8816,
4189,
5067,
73,
49,
45,
87,
2847,
53,
11183,
67,
22,
8225,
274,
7079,
42,
29726,
90,
18,
8470,
79,
39,
19,
42,
14008,
25,
17706,
748,
22,
50,
84,
41,
67,
1167,
1191,
18,
15473,
697,
49,
17019,
43,
84,
74,
14194,
26724,
11,
47,
21,
55,
1165,
55,
10872,
2439,
17,
75,
708,
72,
22,
7608,
12917,
35,
23,
55,
20,
58,
3553,
57,
1822,
77,
48,
66,
44,
22,
35,
24110,
70,
40,
11538,
4254,
38,
20,
21733,
25,
54,
55,
42,
23,
58,
82,
30392,
82,
22,
56,
53,
79,
47,
41,
67,
37,
3122,
78,
15,
80,
40,
86,
55,
265,
74,
45,
8161,
3129,
82,
49,
3053,
70,
27588,
24,
17672,
68,
15,
41,
17,
11,
39,
14784,
77,
7312,
11692,
33,
75,
2493,
5158,
20,
25355,
706,
58,
32098,
771,
43,
84,
23,
16608,
18,
68,
12339,
11,
24,
84,
54,
58,
69,
1196,
391,
53,
85,
49,
65,
12500,
23,
14194,
383,
51,
71,
42,
57,
5902,
87,
4848,
12339,
71,
49,
78,
55,
23745,
1355,
25262,
70,
74,
16,
6428,
57,
33,
18,
58,
74,
24,
2571,
15900,
85,
22,
47,
23,
33,
75,
11765,
651,
9047,
57,
3387,
21659,
47,
25,
11,
20,
73,
1944,
44,
1465,
11,
58,
82,
38,
466,
69,
350,
89,
8822,
23,
71,
43,
83,
16,
58,
26133,
49,
80,
46,
19873,
55,
24,
33,
11,
58,
14249,
23,
52,
66,
6301,
51,
17156,
530,
15,
37,
11,
90,
15,
66,
47,
65,
2564,
81,
23,
80,
15,
22,
66,
23,
12735,
7977,
49,
42,
34,
879,
35,
1945,
41,
87,
45,
67,
54,
66,
22,
43,
54,
1244,
76,
49,
66,
47,
84,
43,
22522,
21,
37,
72,
20,
58,
19910,
24,
66,
17541,
11,
41,
67,
6603,
49,
22,
11378,
1845,
8052,
32532,
3917,
33,
1447,
71,
464,
53,
12931,
87,
5488,
966,
68,
57,
5487,
34,
18,
89,
44,
1341,
10134,
54,
18926,
692,
53,
9529,
78,
9858,
3902,
28644,
1951,
9301,
375,
2696,
78,
401,
288,
298,
1258,
63,
2123,
582,
298,
5869,
32,
5869,
14,
17741,
14,
71,
1364,
2048,
14,
957,
401,
267,
1660,
272,
789,
199,
9,
199,
17749,
63,
8803,
275,
2420,
2732,
63,
1418,
582,
298,
27512,
77,
1418,
401,
298,
12342,
63,
262,
582,
15751,
93,
199,
17749,
63,
6243,
275,
2420,
6410,
582,
24312,
199,
17749,
63,
2632,
275,
298,
2859,
921,
5869,
2,
199,
17749,
63,
7311,
275,
469,
272,
298,
11626,
582,
289,
2,
3655,
21462,
469,
17749,
63,
8803,
459,
2732,
63,
1418,
418,
10750,
272,
298,
56,
13,
39,
5100,
13,
5413,
582,
298,
5066,
401,
199,
93,
421,
199,
4146,
347,
511,
63,
362,
63,
30033,
8,
5387,
304,
272,
408,
774,
18057,
402,
790,
1041,
339,
1335,
9115,
275,
298,
14655,
42,
16,
69,
56,
28960,
47,
73,
25575,
54,
17,
19910,
7027,
42,
16168,
39,
559,
47,
73,
42,
6195,
90,
41,
17,
20959,
42,
25,
14,
14655,
42,
2352,
19,
14738,
47,
73,
42,
25606,
55,
17,
266,
2533,
25606,
55,
17,
266,
51,
21,
80,
20207,
16,
30127,
19,
25940,
6413,
58,
80,
57,
18,
54,
72,
57,
18,
46,
11549,
55,
1400,
23041,
46,
18708,
51,
1831,
607,
23827,
66,
19,
24613,
41,
743,
4674,
14784,
16,
67,
27699,
22,
27480,
3129,
68,
19,
15140,
58,
1398,
86,
58,
18,
15455,
16936,
34,
80,
1480,
21,
26257,
1165,
86,
16936
] |
[
774,
4475,
1455,
8500,
1041,
199,
504,
2197,
492,
2197,
12,
6871,
12,
7137,
199,
199,
504,
8846,
14,
4608,
14,
3098,
63,
7310,
492,
9173,
12827,
63,
16435,
840,
1441,
63,
10926,
199,
504,
8846,
14,
4608,
14,
3098,
63,
7310,
14,
1297,
492,
334,
272,
7781,
3635,
25302,
63,
8803,
63,
2632,
12,
272,
27357,
63,
6689,
63,
5825,
63,
2632,
12,
199,
9,
199,
504,
8846,
14,
4608,
14,
3098,
63,
7310,
14,
1014,
492,
334,
272,
4475,
2028,
12,
272,
485,
362,
63,
4219,
2180,
63,
30033,
12,
272,
485,
362,
63,
4219,
2180,
63,
1418,
12,
199,
9,
199,
199,
504,
2295,
14,
4146,
63,
1805,
492,
1821,
12,
3371,
199,
199,
26778,
63,
5569,
275,
9173,
12827,
63,
16435,
840,
1441,
63,
10926,
8,
272,
469,
267,
298,
1715,
63,
344,
582,
298,
4321,
401,
267,
298,
1364,
63,
2048,
582,
469,
288,
298,
4239,
63,
498,
582,
298,
9858,
15947,
28644,
1951,
9301,
375,
2696,
78,
10709,
948,
10772,
2100,
1554,
879,
23571,
75,
81,
72,
8810,
39,
25,
87,
16,
4134,
31668,
2078,
1179,
3263,
77,
37,
87,
2721,
42,
68,
5676,
37,
2276,
79,
39,
4134,
32640,
551,
27965,
16240,
23,
1152,
26606,
6294,
90,
22,
44,
22,
57,
86,
53,
75,
35,
86,
16779,
56,
1167,
82,
51,
22,
8048,
57,
47,
573,
8958,
526,
43,
21,
6004,
57,
19674,
53,
3893,
24,
54,
2819,
90,
706,
89,
25262,
23,
56,
47,
2635,
57,
71,
42,
54,
24989,
1949,
31591,
21,
43,
24,
66,
2553,
48,
74,
38,
90,
2027,
51,
42,
74,
58,
20369,
16262,
15,
58,
49,
1717,
68,
24,
54,
887,
86,
4312,
55,
53,
79,
48,
28929,
25,
79,
37,
65,
20,
70,
58,
15,
76,
15068,
82,
56,
20047,
38,
19772,
357,
18,
1812,
42,
86,
4848,
15,
58,
1907,
50,
76,
20,
83,
20,
69,
58,
80,
4698,
18114,
86,
19327,
15,
24566,
23,
53,
69,
17095,
5676,
4567,
2276,
4220,
71,
57,
9331,
386,
3466,
90,
6084,
53,
5916,
13692,
48,
3630,
43,
25542,
23,
84,
43,
58,
21,
75,
31208,
70,
37,
65,
16,
87,
22,
34,
1282,
78,
12659,
17,
45,
2327,
17,
16911,
2846,
15543,
45,
651,
38,
84,
43,
83,
22,
23320,
41,
6087,
6323,
383,
68,
57,
15,
920,
16,
6265,
66,
34,
19,
11,
17345,
2010,
40,
23,
84,
20,
8565,
4189,
42,
8163,
7073,
50,
1643,
80,
43,
23,
79,
1196,
34,
23,
88,
2767,
49,
86,
24,
11,
17746,
4963,
1181,
25,
15,
21,
86,
49,
21,
33,
1438,
45,
2228,
46,
87,
32198,
53,
23,
14649,
18926,
22,
58,
23,
58,
41,
1892,
2533,
726,
23,
546,
83,
55,
458,
40,
7695,
80,
46,
17,
9962,
49,
42,
4134,
47,
8816,
4189,
5067,
73,
49,
45,
87,
2847,
53,
11183,
67,
22,
8225,
274,
7079,
42,
29726,
90,
18,
8470,
79,
39,
19,
42,
14008,
25,
17706,
748,
22,
50,
84,
41,
67,
1167,
1191,
18,
15473,
697,
49,
17019,
43,
84,
74,
14194,
26724,
11,
47,
21,
55,
1165,
55,
10872,
2439,
17,
75,
708,
72,
22,
7608,
12917,
35,
23,
55,
20,
58,
3553,
57,
1822,
77,
48,
66,
44,
22,
35,
24110,
70,
40,
11538,
4254,
38,
20,
21733,
25,
54,
55,
42,
23,
58,
82,
30392,
82,
22,
56,
53,
79,
47,
41,
67,
37,
3122,
78,
15,
80,
40,
86,
55,
265,
74,
45,
8161,
3129,
82,
49,
3053,
70,
27588,
24,
17672,
68,
15,
41,
17,
11,
39,
14784,
77,
7312,
11692,
33,
75,
2493,
5158,
20,
25355,
706,
58,
32098,
771,
43,
84,
23,
16608,
18,
68,
12339,
11,
24,
84,
54,
58,
69,
1196,
391,
53,
85,
49,
65,
12500,
23,
14194,
383,
51,
71,
42,
57,
5902,
87,
4848,
12339,
71,
49,
78,
55,
23745,
1355,
25262,
70,
74,
16,
6428,
57,
33,
18,
58,
74,
24,
2571,
15900,
85,
22,
47,
23,
33,
75,
11765,
651,
9047,
57,
3387,
21659,
47,
25,
11,
20,
73,
1944,
44,
1465,
11,
58,
82,
38,
466,
69,
350,
89,
8822,
23,
71,
43,
83,
16,
58,
26133,
49,
80,
46,
19873,
55,
24,
33,
11,
58,
14249,
23,
52,
66,
6301,
51,
17156,
530,
15,
37,
11,
90,
15,
66,
47,
65,
2564,
81,
23,
80,
15,
22,
66,
23,
12735,
7977,
49,
42,
34,
879,
35,
1945,
41,
87,
45,
67,
54,
66,
22,
43,
54,
1244,
76,
49,
66,
47,
84,
43,
22522,
21,
37,
72,
20,
58,
19910,
24,
66,
17541,
11,
41,
67,
6603,
49,
22,
11378,
1845,
8052,
32532,
3917,
33,
1447,
71,
464,
53,
12931,
87,
5488,
966,
68,
57,
5487,
34,
18,
89,
44,
1341,
10134,
54,
18926,
692,
53,
9529,
78,
9858,
3902,
28644,
1951,
9301,
375,
2696,
78,
401,
288,
298,
1258,
63,
2123,
582,
298,
5869,
32,
5869,
14,
17741,
14,
71,
1364,
2048,
14,
957,
401,
267,
1660,
272,
789,
199,
9,
199,
17749,
63,
8803,
275,
2420,
2732,
63,
1418,
582,
298,
27512,
77,
1418,
401,
298,
12342,
63,
262,
582,
15751,
93,
199,
17749,
63,
6243,
275,
2420,
6410,
582,
24312,
199,
17749,
63,
2632,
275,
298,
2859,
921,
5869,
2,
199,
17749,
63,
7311,
275,
469,
272,
298,
11626,
582,
289,
2,
3655,
21462,
469,
17749,
63,
8803,
459,
2732,
63,
1418,
418,
10750,
272,
298,
56,
13,
39,
5100,
13,
5413,
582,
298,
5066,
401,
199,
93,
421,
199,
4146,
347,
511,
63,
362,
63,
30033,
8,
5387,
304,
272,
408,
774,
18057,
402,
790,
1041,
339,
1335,
9115,
275,
298,
14655,
42,
16,
69,
56,
28960,
47,
73,
25575,
54,
17,
19910,
7027,
42,
16168,
39,
559,
47,
73,
42,
6195,
90,
41,
17,
20959,
42,
25,
14,
14655,
42,
2352,
19,
14738,
47,
73,
42,
25606,
55,
17,
266,
2533,
25606,
55,
17,
266,
51,
21,
80,
20207,
16,
30127,
19,
25940,
6413,
58,
80,
57,
18,
54,
72,
57,
18,
46,
11549,
55,
1400,
23041,
46,
18708,
51,
1831,
607,
23827,
66,
19,
24613,
41,
743,
4674,
14784,
16,
67,
27699,
22,
27480,
3129,
68,
19,
15140,
58,
1398,
86,
58,
18,
15455,
16936,
34,
80,
1480,
21,
26257,
1165,
86,
16936,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
metasmile/scripts
|
gitler/gitler.py
|
2
|
4412
|
"""
Line endings resolver for git
Copyright (c) 2015 metasmile cyrano905@gmail.com (github.com/metasmile)
"""
import time, os, sys, re, textwrap, argparse, pprint, subprocess
from os.path import expanduser
parser = argparse.ArgumentParser(description='Line endings resolver for git.')
parser.add_argument('-c','--config-only', help='Confiture git and generate(or modify) ".gitattributes" only.', required=False, default=False, nargs='?')
parser.add_argument('-s','--stash', help='Stash all current contents before start.(Default=True)', required=False, default=True, nargs='?')
parser.add_argument('-o','--overwrite-attr', help='Overwrite .gitattributes.(Default=False - "Append")', required=False, default=False, nargs='?')
args = vars(parser.parse_args())
def main():
start = time.time()
perform_stash = args['stash'] is not False
performed_stash = False
if perform_stash:
performed_stash = subprocess.call('git stash --include-untracked', shell=True)==0
print '> Configure git ...'
resolve_global()
print '> Configure .gitattributes ...'
print write_attributes(make_attributes())
if args['config_only'] is False:
print '> Now commit working content safely and clean ...'
resolve_current_repo()
print 'done.', (time.time() - start)
print '(i) : Your uncommited changes is been stashed safely.\nPlease excute "git stash pop" to restore.'
def check_ignore(file):
return not os.path.isfile(file) or 1 > os.path.getsize(file)
def resolve_global():
subprocess.check_call('git config --global core.autocrlf true', shell=True)
def resolve_current_repo():
subprocess.call('git add . -u', shell=True)
subprocess.call('git commit -m "Saving files before refreshing line endings"', shell=True)
subprocess.call('git rm --cached -r .', shell=True)
subprocess.call('git reset --hard', shell=True)
subprocess.call('git add .', shell=True)
subprocess.call('git commit -m "Normalize all the line endings (configured .gitattributes)"', shell=True)
# references from : https://help.github.com/articles/dealing-with-line-endings/
def make_attributes():
exts = {}
for dir, dirs, files in os.walk(expanduser('./'), topdown=True):
for file in files:
_file = os.path.join(dir, file)
if not check_ignore(_file):
try:
ext = os.path.splitext(file)[1][1:]
if ext and not ext in exts:
exts[ext] = 'text' if istextfile(open(_file)) else 'binary'
except IOError, e:
continue
#pre-defines
result = textwrap.dedent(
"""\
* text=auto
""")
#configure gitattributes by extension
for ext in sorted(exts, key=exts.get):
result += textwrap.dedent(
"""\
*.{0} {1}
"""\
.format(ext, exts[ext]))
return result
def write_attributes(content):
path = os.path.join(expanduser('./'), '.gitattributes')
f = open(path, 'a' if args['overwrite_attr'] is False else 'w')
f.write(content)
f.close()
return content
'''
http://eli.thegreenplace.net/2011/10/19/perls-guess-if-file-is-text-or-binary-implemented-in-python
# A function that takes an integer in the 8-bit range and returns
# a single-character byte object in py3 / a single-character string
# in py2.
'''
PY3 = sys.version_info[0] == 3
int2byte = (lambda x: bytes((x,))) if PY3 else chr
_text_characters = (
b''.join(int2byte(i) for i in range(32, 127)) +
b'\n\r\t\f\b')
def istextfile(fileobj, blocksize=512):
""" Uses heuristics to guess whether the given file is text or binary,
by reading a single block of bytes from the file.
If more than 30% of the chars in the block are non-text, or there
are NUL ('\x00') bytes in the block, assume this is a binary file.
"""
block = fileobj.read(blocksize)
if b'\x00' in block:
# Files with null bytes are binary
return False
elif not block:
# An empty file is considered a valid text file
return True
# Use translate's 'deletechars' argument to efficiently remove all
# occurrences of _text_characters from the block
nontext = block.translate(None, _text_characters)
return float(len(nontext)) / len(block) <= 0.30
if __name__ == "__main__":
main()
|
mit
|
[
624,
199,
3049,
1284,
780,
15611,
367,
6135,
199,
199,
7384,
334,
67,
9,
6900,
7647,
11374,
441,
6325,
1312,
79,
29888,
32,
6799,
14,
957,
334,
5031,
14,
957,
15,
10207,
11374,
441,
9,
199,
624,
199,
199,
646,
900,
12,
747,
12,
984,
12,
295,
12,
13390,
12,
7534,
12,
10933,
12,
3873,
199,
504,
747,
14,
515,
492,
6544,
751,
199,
199,
2087,
275,
7534,
14,
10730,
8,
1802,
534,
3049,
1284,
780,
15611,
367,
6135,
2659,
199,
2087,
14,
525,
63,
2094,
3654,
67,
28280,
888,
13,
2118,
297,
1720,
534,
714,
3269,
608,
6135,
436,
3550,
8,
269,
2811,
9,
3680,
3187,
2987,
2,
1454,
3130,
1415,
29,
797,
12,
849,
29,
797,
12,
9237,
534,
18478,
199,
2087,
14,
525,
63,
2094,
3654,
83,
28280,
27145,
297,
1720,
534,
933,
1119,
1006,
1453,
4072,
2544,
1343,
14,
8,
2698,
29,
549,
3196,
1415,
29,
797,
12,
849,
29,
549,
12,
9237,
534,
18478,
199,
2087,
14,
525,
63,
2094,
3654,
79,
28280,
14658,
13,
962,
297,
1720,
534,
5674,
952,
1275,
3187,
2987,
14,
8,
2698,
29,
797,
446,
298,
8310,
30901,
1415,
29,
797,
12,
849,
29,
797,
12,
9237,
534,
18478,
199,
589,
275,
6802,
8,
2087,
14,
1122,
63,
589,
1012,
199,
199,
318,
2446,
837,
272,
1343,
275,
900,
14,
521,
342,
339,
5147,
63,
27145,
275,
1249,
459,
27145,
418,
365,
440,
756,
272,
10585,
63,
27145,
275,
756,
272,
340,
5147,
63,
27145,
26,
267,
10585,
63,
27145,
275,
3873,
14,
1250,
360,
3187,
410,
1119,
1553,
2613,
13,
638,
8085,
379,
297,
5218,
29,
549,
12694,
16,
339,
870,
12696,
15453,
6135,
2263,
7,
272,
7512,
63,
2966,
342,
339,
870,
12696,
15453,
1275,
3187,
2987,
2263,
7,
272,
870,
2218,
63,
2987,
8,
1875,
63,
2987,
1012,
339,
340,
1249,
459,
888,
63,
2118,
418,
365,
756,
26,
267,
870,
12696,
7356,
5532,
6449,
1564,
19353,
436,
3633,
2263,
7,
267,
7512,
63,
1818,
63,
3417,
342,
339,
870,
283,
4456,
3130,
334,
521,
14,
521,
342,
446,
1343,
9,
272,
870,
8189,
73,
9,
520,
19519,
625,
1404,
5703,
4493,
365,
2757,
410,
21189,
19353,
3134,
78,
8254,
3178,
938,
298,
3187,
410,
1119,
4560,
2,
370,
9066,
3530,
199,
199,
318,
1104,
63,
4247,
8,
493,
304,
272,
372,
440,
747,
14,
515,
14,
6292,
8,
493,
9,
503,
413,
690,
747,
14,
515,
14,
20733,
8,
493,
9,
199,
199,
318,
7512,
63,
2966,
837,
272,
3873,
14,
1074,
63,
1250,
360,
3187,
1101,
1553,
2966,
6170,
14,
6898,
679,
82,
276,
2549,
297,
5218,
29,
549,
9,
199,
199,
318,
7512,
63,
1818,
63,
3417,
837,
272,
3873,
14,
1250,
360,
3187,
1050,
1275,
446,
85,
297,
5218,
29,
549,
9,
272,
3873,
14,
1250,
360,
3187,
5532,
446,
77,
298,
30125,
1584,
2544,
9236,
316,
1004,
1284,
780,
6949,
5218,
29,
549,
9,
272,
3873,
14,
1250,
360,
3187,
14267,
1553,
5245,
446,
82,
1275,
297,
5218,
29,
549,
9,
272,
3873,
14,
1250,
360,
3187,
5305,
1553,
8726,
297,
5218,
29,
549,
9,
272,
3873,
14,
1250,
360,
3187,
1050,
1275,
297,
5218,
29,
549,
9,
272,
3873,
14,
1250,
360,
3187,
5532,
446,
77,
298,
22580,
1006,
314,
1004,
1284,
780,
334,
11786,
1275,
3187,
2987,
32691,
5218,
29,
549,
9,
199,
199,
3,
6941,
687,
520,
4178,
921,
3437,
14,
5031,
14,
957,
15,
19813,
15,
21245,
316,
13,
1045,
13,
604,
13,
500,
780,
15,
199,
318,
1852,
63,
2987,
837,
272,
27688,
275,
1052,
272,
367,
2935,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
12131,
17371,
659,
2746,
2110,
29,
549,
304,
267,
367,
570,
315,
1584,
26,
288,
485,
493,
275,
747,
14,
515,
14,
904,
8,
694,
12,
570,
9,
288,
340,
440,
1104,
63,
4247,
1547,
493,
304,
355,
862,
26,
490,
1599,
275,
747,
14,
515,
14,
7973,
8,
493,
2788,
17,
1527,
17,
2938,
490,
340,
1599,
436,
440,
1599,
315,
27688,
26,
717,
27688,
59,
832,
61,
275,
283,
505,
7,
340,
365,
505,
493,
8,
1490,
1547,
493,
430,
587,
283,
3008,
7,
355,
871,
5925,
12,
325,
26,
490,
1980,
339,
327,
657,
13,
14334,
272,
754,
275,
13390,
14,
14674,
8,
267,
9638,
267,
627,
1318,
29,
2495,
398,
7857,
272,
327,
6472,
6135,
2987,
701,
3329,
272,
367,
1599,
315,
3355,
8,
25752,
12,
790,
29,
25752,
14,
362,
304,
267,
754,
847,
13390,
14,
14674,
8,
288,
9638,
288,
627,
23379,
16,
93,
469,
17,
93,
288,
9638,
267,
1275,
908,
8,
832,
12,
27688,
59,
832,
2459,
339,
372,
754,
199,
199,
318,
2218,
63,
2987,
8,
1317,
304,
272,
931,
275,
747,
14,
515,
14,
904,
8,
12131,
17371,
659,
1987,
3187,
2987,
358,
272,
289,
275,
1551,
8,
515,
12,
283,
65,
7,
340,
1249,
459,
14658,
63,
962,
418,
365,
756,
587,
283,
87,
358,
272,
289,
14,
952,
8,
1317,
9,
272,
289,
14,
1600,
342,
272,
372,
1564,
199,
199,
2344,
199,
1014,
921,
18865,
14,
1589,
7731,
2778,
14,
846,
15,
8128,
15,
709,
15,
1167,
15,
529,
478,
13,
11636,
13,
692,
13,
493,
13,
374,
13,
505,
13,
269,
13,
3008,
13,
13825,
13,
262,
13,
1548,
199,
199,
3,
437,
805,
626,
6181,
376,
3000,
315,
314,
1695,
13,
2075,
1425,
436,
2529,
199,
3,
282,
2849,
13,
10856,
3696,
909,
315,
1134,
19,
1182,
282,
2849,
13,
10856,
1059,
199,
3,
315,
1134,
18,
14,
199,
2344,
199,
4521,
19,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
650,
199,
199,
442,
18,
4414,
275,
334,
2734,
671,
26,
2783,
1332,
88,
20097,
340,
7843,
19,
587,
8678,
199,
199,
63,
505,
63,
16516,
275,
334,
267,
330,
17067,
904,
8,
442,
18,
4414,
8,
73,
9,
367,
284,
315,
1425,
8,
708,
12,
12792,
430,
435,
267,
330,
1154,
78,
60,
82,
60,
84,
60,
70,
60,
66,
358,
199,
199,
318,
365,
505,
493,
8,
9234,
12,
27461,
29,
7736,
304,
272,
408,
14911,
946,
300,
631,
2932,
370,
9519,
3775,
314,
1627,
570,
365,
1318,
503,
3366,
12,
267,
701,
7664
] |
[
199,
3049,
1284,
780,
15611,
367,
6135,
199,
199,
7384,
334,
67,
9,
6900,
7647,
11374,
441,
6325,
1312,
79,
29888,
32,
6799,
14,
957,
334,
5031,
14,
957,
15,
10207,
11374,
441,
9,
199,
624,
199,
199,
646,
900,
12,
747,
12,
984,
12,
295,
12,
13390,
12,
7534,
12,
10933,
12,
3873,
199,
504,
747,
14,
515,
492,
6544,
751,
199,
199,
2087,
275,
7534,
14,
10730,
8,
1802,
534,
3049,
1284,
780,
15611,
367,
6135,
2659,
199,
2087,
14,
525,
63,
2094,
3654,
67,
28280,
888,
13,
2118,
297,
1720,
534,
714,
3269,
608,
6135,
436,
3550,
8,
269,
2811,
9,
3680,
3187,
2987,
2,
1454,
3130,
1415,
29,
797,
12,
849,
29,
797,
12,
9237,
534,
18478,
199,
2087,
14,
525,
63,
2094,
3654,
83,
28280,
27145,
297,
1720,
534,
933,
1119,
1006,
1453,
4072,
2544,
1343,
14,
8,
2698,
29,
549,
3196,
1415,
29,
797,
12,
849,
29,
549,
12,
9237,
534,
18478,
199,
2087,
14,
525,
63,
2094,
3654,
79,
28280,
14658,
13,
962,
297,
1720,
534,
5674,
952,
1275,
3187,
2987,
14,
8,
2698,
29,
797,
446,
298,
8310,
30901,
1415,
29,
797,
12,
849,
29,
797,
12,
9237,
534,
18478,
199,
589,
275,
6802,
8,
2087,
14,
1122,
63,
589,
1012,
199,
199,
318,
2446,
837,
272,
1343,
275,
900,
14,
521,
342,
339,
5147,
63,
27145,
275,
1249,
459,
27145,
418,
365,
440,
756,
272,
10585,
63,
27145,
275,
756,
272,
340,
5147,
63,
27145,
26,
267,
10585,
63,
27145,
275,
3873,
14,
1250,
360,
3187,
410,
1119,
1553,
2613,
13,
638,
8085,
379,
297,
5218,
29,
549,
12694,
16,
339,
870,
12696,
15453,
6135,
2263,
7,
272,
7512,
63,
2966,
342,
339,
870,
12696,
15453,
1275,
3187,
2987,
2263,
7,
272,
870,
2218,
63,
2987,
8,
1875,
63,
2987,
1012,
339,
340,
1249,
459,
888,
63,
2118,
418,
365,
756,
26,
267,
870,
12696,
7356,
5532,
6449,
1564,
19353,
436,
3633,
2263,
7,
267,
7512,
63,
1818,
63,
3417,
342,
339,
870,
283,
4456,
3130,
334,
521,
14,
521,
342,
446,
1343,
9,
272,
870,
8189,
73,
9,
520,
19519,
625,
1404,
5703,
4493,
365,
2757,
410,
21189,
19353,
3134,
78,
8254,
3178,
938,
298,
3187,
410,
1119,
4560,
2,
370,
9066,
3530,
199,
199,
318,
1104,
63,
4247,
8,
493,
304,
272,
372,
440,
747,
14,
515,
14,
6292,
8,
493,
9,
503,
413,
690,
747,
14,
515,
14,
20733,
8,
493,
9,
199,
199,
318,
7512,
63,
2966,
837,
272,
3873,
14,
1074,
63,
1250,
360,
3187,
1101,
1553,
2966,
6170,
14,
6898,
679,
82,
276,
2549,
297,
5218,
29,
549,
9,
199,
199,
318,
7512,
63,
1818,
63,
3417,
837,
272,
3873,
14,
1250,
360,
3187,
1050,
1275,
446,
85,
297,
5218,
29,
549,
9,
272,
3873,
14,
1250,
360,
3187,
5532,
446,
77,
298,
30125,
1584,
2544,
9236,
316,
1004,
1284,
780,
6949,
5218,
29,
549,
9,
272,
3873,
14,
1250,
360,
3187,
14267,
1553,
5245,
446,
82,
1275,
297,
5218,
29,
549,
9,
272,
3873,
14,
1250,
360,
3187,
5305,
1553,
8726,
297,
5218,
29,
549,
9,
272,
3873,
14,
1250,
360,
3187,
1050,
1275,
297,
5218,
29,
549,
9,
272,
3873,
14,
1250,
360,
3187,
5532,
446,
77,
298,
22580,
1006,
314,
1004,
1284,
780,
334,
11786,
1275,
3187,
2987,
32691,
5218,
29,
549,
9,
199,
199,
3,
6941,
687,
520,
4178,
921,
3437,
14,
5031,
14,
957,
15,
19813,
15,
21245,
316,
13,
1045,
13,
604,
13,
500,
780,
15,
199,
318,
1852,
63,
2987,
837,
272,
27688,
275,
1052,
272,
367,
2935,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
12131,
17371,
659,
2746,
2110,
29,
549,
304,
267,
367,
570,
315,
1584,
26,
288,
485,
493,
275,
747,
14,
515,
14,
904,
8,
694,
12,
570,
9,
288,
340,
440,
1104,
63,
4247,
1547,
493,
304,
355,
862,
26,
490,
1599,
275,
747,
14,
515,
14,
7973,
8,
493,
2788,
17,
1527,
17,
2938,
490,
340,
1599,
436,
440,
1599,
315,
27688,
26,
717,
27688,
59,
832,
61,
275,
283,
505,
7,
340,
365,
505,
493,
8,
1490,
1547,
493,
430,
587,
283,
3008,
7,
355,
871,
5925,
12,
325,
26,
490,
1980,
339,
327,
657,
13,
14334,
272,
754,
275,
13390,
14,
14674,
8,
267,
9638,
267,
627,
1318,
29,
2495,
398,
7857,
272,
327,
6472,
6135,
2987,
701,
3329,
272,
367,
1599,
315,
3355,
8,
25752,
12,
790,
29,
25752,
14,
362,
304,
267,
754,
847,
13390,
14,
14674,
8,
288,
9638,
288,
627,
23379,
16,
93,
469,
17,
93,
288,
9638,
267,
1275,
908,
8,
832,
12,
27688,
59,
832,
2459,
339,
372,
754,
199,
199,
318,
2218,
63,
2987,
8,
1317,
304,
272,
931,
275,
747,
14,
515,
14,
904,
8,
12131,
17371,
659,
1987,
3187,
2987,
358,
272,
289,
275,
1551,
8,
515,
12,
283,
65,
7,
340,
1249,
459,
14658,
63,
962,
418,
365,
756,
587,
283,
87,
358,
272,
289,
14,
952,
8,
1317,
9,
272,
289,
14,
1600,
342,
272,
372,
1564,
199,
199,
2344,
199,
1014,
921,
18865,
14,
1589,
7731,
2778,
14,
846,
15,
8128,
15,
709,
15,
1167,
15,
529,
478,
13,
11636,
13,
692,
13,
493,
13,
374,
13,
505,
13,
269,
13,
3008,
13,
13825,
13,
262,
13,
1548,
199,
199,
3,
437,
805,
626,
6181,
376,
3000,
315,
314,
1695,
13,
2075,
1425,
436,
2529,
199,
3,
282,
2849,
13,
10856,
3696,
909,
315,
1134,
19,
1182,
282,
2849,
13,
10856,
1059,
199,
3,
315,
1134,
18,
14,
199,
2344,
199,
4521,
19,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
650,
199,
199,
442,
18,
4414,
275,
334,
2734,
671,
26,
2783,
1332,
88,
20097,
340,
7843,
19,
587,
8678,
199,
199,
63,
505,
63,
16516,
275,
334,
267,
330,
17067,
904,
8,
442,
18,
4414,
8,
73,
9,
367,
284,
315,
1425,
8,
708,
12,
12792,
430,
435,
267,
330,
1154,
78,
60,
82,
60,
84,
60,
70,
60,
66,
358,
199,
199,
318,
365,
505,
493,
8,
9234,
12,
27461,
29,
7736,
304,
272,
408,
14911,
946,
300,
631,
2932,
370,
9519,
3775,
314,
1627,
570,
365,
1318,
503,
3366,
12,
267,
701,
7664,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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test_co_realise_cubes.py
|
4
|
2957
|
# (C) British Crown Copyright 2018, Met Office
#
# This file is part of Iris.
#
# Iris is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Iris is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Iris. If not, see <http://www.gnu.org/licenses/>.
"""Test function :func:`iris._lazy data.co_realise_cubes`."""
from __future__ import (absolute_import, division, print_function)
from six.moves import (filter, input, map, range, zip) # noqa
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests
from mock import MagicMock
import numpy as np
from iris.cube import Cube
from iris._lazy_data import as_lazy_data
from iris._lazy_data import co_realise_cubes
class ArrayAccessCounter(object):
def __init__(self, array):
self.dtype = array.dtype
self.shape = array.shape
self._array = array
self.access_count = 0
def __getitem__(self, keys):
self.access_count += 1
return self._array[keys]
class Test_co_realise_cubes(tests.IrisTest):
def test_empty(self):
# Ensure that 'no args' case does not raise an error.
co_realise_cubes()
def test_basic(self):
real_data = np.arange(3.)
cube = Cube(as_lazy_data(real_data))
co_realise_cubes(cube)
self.assertFalse(cube.has_lazy_data())
self.assertArrayAllClose(cube.core_data(), real_data)
def test_multi(self):
real_data = np.arange(3.)
cube_base = Cube(as_lazy_data(real_data))
cube_inner = cube_base + 1
result_a = cube_base + 1
result_b = cube_inner + 1
co_realise_cubes(result_a, result_b)
# Check that target cubes were realised.
self.assertFalse(result_a.has_lazy_data())
self.assertFalse(result_b.has_lazy_data())
# Check that other cubes referenced remain lazy.
self.assertTrue(cube_base.has_lazy_data())
self.assertTrue(cube_inner.has_lazy_data())
def test_combined_access(self):
wrapped_array = ArrayAccessCounter(np.arange(3.))
lazy_array = as_lazy_data(wrapped_array)
derived_a = lazy_array + 1
derived_b = lazy_array + 2
cube_a = Cube(derived_a)
cube_b = Cube(derived_b)
co_realise_cubes(cube_a, cube_b)
# Though used twice, the source data should only get fetched once.
self.assertEqual(wrapped_array.access_count, 1)
if __name__ == '__main__':
tests.main()
|
lgpl-3.0
|
[
3,
334,
35,
9,
699,
322,
23184,
445,
18406,
1898,
14894,
12,
10072,
593,
11286,
301,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
473,
5719,
14,
199,
3,
199,
3,
473,
5719,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
314,
199,
3,
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,
473,
5719,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
473,
5719,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
624,
774,
805,
520,
1532,
1705,
11885,
423,
6395,
666,
14,
331,
63,
3093,
572,
63,
18455,
397,
17105,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
504,
3816,
14,
4912,
492,
334,
1541,
12,
1324,
12,
2341,
12,
1425,
12,
3482,
9,
221,
327,
8151,
199,
199,
3,
3161,
12192,
14,
2219,
1642,
880,
626,
2005,
7645,
883,
506,
2536,
9096,
2544,
199,
3,
16306,
7003,
587,
14,
199,
646,
12192,
14,
2219,
465,
2295,
199,
199,
504,
1683,
492,
10079,
199,
646,
2680,
465,
980,
199,
199,
504,
12192,
14,
11477,
492,
445,
3375,
199,
504,
12192,
423,
6395,
63,
576,
492,
465,
63,
6395,
63,
576,
199,
199,
504,
12192,
423,
6395,
63,
576,
492,
512,
63,
3093,
572,
63,
18455,
397,
421,
199,
533,
8725,
3946,
11348,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1625,
304,
267,
291,
14,
2271,
275,
1625,
14,
2271,
267,
291,
14,
1392,
275,
1625,
14,
1392,
267,
291,
423,
1144,
275,
1625,
267,
291,
14,
2732,
63,
835,
275,
378,
339,
347,
636,
6095,
721,
277,
12,
2883,
304,
267,
291,
14,
2732,
63,
835,
847,
413,
267,
372,
291,
423,
1144,
59,
1612,
61,
421,
199,
533,
1379,
63,
331,
63,
3093,
572,
63,
18455,
397,
8,
2219,
14,
41,
5719,
774,
304,
272,
347,
511,
63,
1667,
8,
277,
304,
267,
327,
7523,
626,
283,
889,
1249,
7,
1930,
1630,
440,
746,
376,
1125,
14,
267,
512,
63,
3093,
572,
63,
18455,
397,
342,
339,
347,
511,
63,
4316,
8,
277,
304,
267,
3363,
63,
576,
275,
980,
14,
5605,
8,
19,
4959,
267,
15681,
275,
445,
3375,
8,
305,
63,
6395,
63,
576,
8,
3093,
63,
576,
430,
267,
512,
63,
3093,
572,
63,
18455,
397,
8,
11477,
9,
267,
291,
14,
3334,
8,
11477,
14,
1989,
63,
6395,
63,
576,
1012,
267,
291,
14,
479,
3836,
2422,
4724,
8,
11477,
14,
1018,
63,
576,
1062,
3363,
63,
576,
9,
339,
347,
511,
63,
3029,
8,
277,
304,
267,
3363,
63,
576,
275,
980,
14,
5605,
8,
19,
4959,
267,
15681,
63,
1095,
275,
445,
3375,
8,
305,
63,
6395,
63,
576,
8,
3093,
63,
576,
430,
267,
15681,
63,
5216,
275,
15681,
63,
1095,
435,
413,
267,
754,
63,
65,
275,
15681,
63,
1095,
435,
413,
267,
754,
63,
66,
275,
15681,
63,
5216,
435,
413,
267,
512,
63,
3093,
572,
63,
18455,
397,
8,
1099,
63,
65,
12,
754,
63,
66,
9,
267,
327,
2670,
626,
1347,
22217,
397,
4898,
3363,
9096,
14,
267,
291,
14,
3334,
8,
1099,
63,
65,
14,
1989,
63,
6395,
63,
576,
1012,
267,
291,
14,
3334,
8,
1099,
63,
66,
14,
1989,
63,
6395,
63,
576,
1012,
267,
327,
2670,
626,
1163,
22217,
397,
11812,
5706,
9617,
14,
267,
291,
14,
1815,
8,
11477,
63,
1095,
14,
1989,
63,
6395,
63,
576,
1012,
267,
291,
14,
1815,
8,
11477,
63,
5216,
14,
1989,
63,
6395,
63,
576,
1012,
339,
347,
511,
63,
17583,
63,
2732,
8,
277,
304,
267,
8072,
63,
1144,
275,
8725,
3946,
11348,
8,
1590,
14,
5605,
8,
19,
26273,
267,
9617,
63,
1144,
275,
465,
63,
6395,
63,
576,
8,
9130,
63,
1144,
9,
267,
7131,
63,
65,
275,
9617,
63,
1144,
435,
413,
267,
7131,
63,
66,
275,
9617,
63,
1144,
435,
499,
267,
15681,
63,
65,
275,
445,
3375,
8,
19588,
63,
65,
9,
267,
15681,
63,
66,
275,
445,
3375,
8,
19588,
63,
66,
9,
267,
512,
63,
3093,
572,
63,
18455,
397,
8,
11477,
63,
65,
12,
15681,
63,
66,
9,
267,
327,
18049,
3080,
1202,
13373,
12,
314,
1350,
666,
1077,
1454,
664,
19251,
5403,
14,
267,
291,
14,
629,
8,
9130,
63,
1144,
14,
2732,
63,
835,
12,
413,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2295,
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
] |
[
334,
35,
9,
699,
322,
23184,
445,
18406,
1898,
14894,
12,
10072,
593,
11286,
301,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
473,
5719,
14,
199,
3,
199,
3,
473,
5719,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
314,
199,
3,
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,
473,
5719,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
473,
5719,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
624,
774,
805,
520,
1532,
1705,
11885,
423,
6395,
666,
14,
331,
63,
3093,
572,
63,
18455,
397,
17105,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
504,
3816,
14,
4912,
492,
334,
1541,
12,
1324,
12,
2341,
12,
1425,
12,
3482,
9,
221,
327,
8151,
199,
199,
3,
3161,
12192,
14,
2219,
1642,
880,
626,
2005,
7645,
883,
506,
2536,
9096,
2544,
199,
3,
16306,
7003,
587,
14,
199,
646,
12192,
14,
2219,
465,
2295,
199,
199,
504,
1683,
492,
10079,
199,
646,
2680,
465,
980,
199,
199,
504,
12192,
14,
11477,
492,
445,
3375,
199,
504,
12192,
423,
6395,
63,
576,
492,
465,
63,
6395,
63,
576,
199,
199,
504,
12192,
423,
6395,
63,
576,
492,
512,
63,
3093,
572,
63,
18455,
397,
421,
199,
533,
8725,
3946,
11348,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1625,
304,
267,
291,
14,
2271,
275,
1625,
14,
2271,
267,
291,
14,
1392,
275,
1625,
14,
1392,
267,
291,
423,
1144,
275,
1625,
267,
291,
14,
2732,
63,
835,
275,
378,
339,
347,
636,
6095,
721,
277,
12,
2883,
304,
267,
291,
14,
2732,
63,
835,
847,
413,
267,
372,
291,
423,
1144,
59,
1612,
61,
421,
199,
533,
1379,
63,
331,
63,
3093,
572,
63,
18455,
397,
8,
2219,
14,
41,
5719,
774,
304,
272,
347,
511,
63,
1667,
8,
277,
304,
267,
327,
7523,
626,
283,
889,
1249,
7,
1930,
1630,
440,
746,
376,
1125,
14,
267,
512,
63,
3093,
572,
63,
18455,
397,
342,
339,
347,
511,
63,
4316,
8,
277,
304,
267,
3363,
63,
576,
275,
980,
14,
5605,
8,
19,
4959,
267,
15681,
275,
445,
3375,
8,
305,
63,
6395,
63,
576,
8,
3093,
63,
576,
430,
267,
512,
63,
3093,
572,
63,
18455,
397,
8,
11477,
9,
267,
291,
14,
3334,
8,
11477,
14,
1989,
63,
6395,
63,
576,
1012,
267,
291,
14,
479,
3836,
2422,
4724,
8,
11477,
14,
1018,
63,
576,
1062,
3363,
63,
576,
9,
339,
347,
511,
63,
3029,
8,
277,
304,
267,
3363,
63,
576,
275,
980,
14,
5605,
8,
19,
4959,
267,
15681,
63,
1095,
275,
445,
3375,
8,
305,
63,
6395,
63,
576,
8,
3093,
63,
576,
430,
267,
15681,
63,
5216,
275,
15681,
63,
1095,
435,
413,
267,
754,
63,
65,
275,
15681,
63,
1095,
435,
413,
267,
754,
63,
66,
275,
15681,
63,
5216,
435,
413,
267,
512,
63,
3093,
572,
63,
18455,
397,
8,
1099,
63,
65,
12,
754,
63,
66,
9,
267,
327,
2670,
626,
1347,
22217,
397,
4898,
3363,
9096,
14,
267,
291,
14,
3334,
8,
1099,
63,
65,
14,
1989,
63,
6395,
63,
576,
1012,
267,
291,
14,
3334,
8,
1099,
63,
66,
14,
1989,
63,
6395,
63,
576,
1012,
267,
327,
2670,
626,
1163,
22217,
397,
11812,
5706,
9617,
14,
267,
291,
14,
1815,
8,
11477,
63,
1095,
14,
1989,
63,
6395,
63,
576,
1012,
267,
291,
14,
1815,
8,
11477,
63,
5216,
14,
1989,
63,
6395,
63,
576,
1012,
339,
347,
511,
63,
17583,
63,
2732,
8,
277,
304,
267,
8072,
63,
1144,
275,
8725,
3946,
11348,
8,
1590,
14,
5605,
8,
19,
26273,
267,
9617,
63,
1144,
275,
465,
63,
6395,
63,
576,
8,
9130,
63,
1144,
9,
267,
7131,
63,
65,
275,
9617,
63,
1144,
435,
413,
267,
7131,
63,
66,
275,
9617,
63,
1144,
435,
499,
267,
15681,
63,
65,
275,
445,
3375,
8,
19588,
63,
65,
9,
267,
15681,
63,
66,
275,
445,
3375,
8,
19588,
63,
66,
9,
267,
512,
63,
3093,
572,
63,
18455,
397,
8,
11477,
63,
65,
12,
15681,
63,
66,
9,
267,
327,
18049,
3080,
1202,
13373,
12,
314,
1350,
666,
1077,
1454,
664,
19251,
5403,
14,
267,
291,
14,
629,
8,
9130,
63,
1144,
14,
2732,
63,
835,
12,
413,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2295,
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,
32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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Jorge-Rodriguez/ansible
|
test/units/modules/messaging/rabbitmq/test_rabbimq_user.py
|
55
|
6653
|
# -*- coding: utf-8 -*-
from ansible.modules.messaging.rabbitmq import rabbitmq_user
from units.compat.mock import patch
from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
class TestRabbitMQUserModule(ModuleTestCase):
def setUp(self):
super(TestRabbitMQUserModule, self).setUp()
self.module = rabbitmq_user
def tearDown(self):
super(TestRabbitMQUserModule, self).tearDown()
def _assert(self, exc, attribute, expected_value, msg=""):
value = exc.message[attribute] if hasattr(exc, attribute) else exc.args[0][attribute]
assert value == expected_value, msg
def test_without_required_parameters(self):
"""Failure must occurs when all parameters are missing"""
with self.assertRaises(AnsibleFailJson):
set_module_args({})
self.module.main()
def test_permissions_with_same_vhost(self):
set_module_args({
'user': 'someuser',
'password': 'somepassword',
'state': 'present',
'permissions': [{'vhost': '/'}, {'vhost': '/'}],
})
with patch('ansible.module_utils.basic.AnsibleModule.get_bin_path') as get_bin_path:
get_bin_path.return_value = '/rabbitmqctl'
try:
self.module.main()
except AnsibleFailJson as e:
self._assert(e, 'failed', True)
self._assert(e, 'msg',
"Error parsing permissions: You can't have two permission dicts for the same vhost")
@patch('ansible.module_utils.basic.AnsibleModule.get_bin_path')
@patch('ansible.modules.messaging.rabbitmq.rabbitmq_user.RabbitMqUser.get')
@patch('ansible.modules.messaging.rabbitmq.rabbitmq_user.RabbitMqUser.check_password')
@patch('ansible.modules.messaging.rabbitmq.rabbitmq_user.RabbitMqUser.has_tags_modifications')
@patch('ansible.modules.messaging.rabbitmq.rabbitmq_user.RabbitMqUser.has_permissions_modifications')
def test_password_changes_only_when_needed(self, has_permissions_modifications, has_tags_modifications,
check_password, get, get_bin_path):
set_module_args({
'user': 'someuser',
'password': 'somepassword',
'state': 'present',
'update_password': 'always',
})
get.return_value = True
get_bin_path.return_value = '/rabbitmqctl'
check_password.return_value = True
has_tags_modifications.return_value = False
has_permissions_modifications.return_value = False
try:
self.module.main()
except AnsibleExitJson as e:
self._assert(e, 'changed', False)
self._assert(e, 'state', 'present')
@patch('ansible.module_utils.basic.AnsibleModule.get_bin_path')
@patch('ansible.modules.messaging.rabbitmq.rabbitmq_user.RabbitMqUser._exec')
@patch('ansible.modules.messaging.rabbitmq.rabbitmq_user.RabbitMqUser._get_permissions')
@patch('ansible.modules.messaging.rabbitmq.rabbitmq_user.RabbitMqUser.has_tags_modifications')
def test_same_permissions_not_changing(self, has_tags_modifications, _get_permissions, _exec, get_bin_path):
set_module_args({
'user': 'someuser',
'password': 'somepassword',
'state': 'present',
'permissions': [{'vhost': '/', 'configure_priv': '.*', 'write_priv': '.*', 'read_priv': '.*'}],
})
_get_permissions.return_value = [{'vhost': '/', 'configure_priv': '.*', 'write_priv': '.*', 'read_priv': '.*'}]
_exec.return_value = ['someuser\t[]']
get_bin_path.return_value = '/rabbitmqctl'
has_tags_modifications.return_value = False
try:
self.module.main()
except AnsibleExitJson as e:
self._assert(e, 'changed', False)
self._assert(e, 'state', 'present')
@patch('ansible.module_utils.basic.AnsibleModule.get_bin_path')
@patch('ansible.modules.messaging.rabbitmq.rabbitmq_user.RabbitMqUser._exec')
@patch('ansible.modules.messaging.rabbitmq.rabbitmq_user.RabbitMqUser._get_permissions')
@patch('ansible.modules.messaging.rabbitmq.rabbitmq_user.RabbitMqUser.set_permissions')
@patch('ansible.modules.messaging.rabbitmq.rabbitmq_user.RabbitMqUser.has_tags_modifications')
def test_permissions_are_fixed(self, has_tags_modifications, set_permissions, _get_permissions, _exec, get_bin_path):
set_module_args({
'user': 'someuser',
'password': 'somepassword',
'state': 'present',
'permissions': [{'vhost': '/', 'configure_priv': '.*', 'write_priv': '.*', 'read_priv': '.*'}],
})
set_permissions.return_value = None
_get_permissions.return_value = []
_exec.return_value = ['someuser\t[]']
get_bin_path.return_value = '/rabbitmqctl'
has_tags_modifications.return_value = False
try:
self.module.main()
except AnsibleExitJson as e:
self._assert(e, 'changed', True)
self._assert(e, 'state', 'present')
assert set_permissions.call_count == 1
@patch('ansible.module_utils.basic.AnsibleModule.get_bin_path')
@patch('ansible.modules.messaging.rabbitmq.rabbitmq_user.RabbitMqUser._exec')
@patch('ansible.modules.messaging.rabbitmq.rabbitmq_user.RabbitMqUser._get_permissions')
@patch('ansible.modules.messaging.rabbitmq.rabbitmq_user.RabbitMqUser.set_permissions')
@patch('ansible.modules.messaging.rabbitmq.rabbitmq_user.RabbitMqUser.has_tags_modifications')
def test_permissions_are_fixed_with_different_host(self, has_tags_modifications, set_permissions, _get_permissions,
_exec, get_bin_path):
set_module_args({
'user': 'someuser',
'password': 'somepassword',
'state': 'present',
'permissions': [{'vhost': '/', 'configure_priv': '.*', 'write_priv': '.*', 'read_priv': '.*'}],
})
set_permissions.return_value = None
_get_permissions.return_value = [{'vhost': 'monitoring', 'configure_priv': '.*', 'write_priv': '.*', 'read_priv': '.*'}]
_exec.return_value = ['someuser\t[]']
get_bin_path.return_value = '/rabbitmqctl'
has_tags_modifications.return_value = False
try:
self.module.main()
except AnsibleExitJson as e:
self._assert(e, 'changed', True)
self._assert(e, 'state', 'present')
assert set_permissions.call_count == 1
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
3242,
14,
3112,
14,
27782,
14,
14411,
29490,
492,
29773,
29490,
63,
751,
199,
504,
6204,
14,
5819,
14,
1805,
492,
3371,
199,
504,
6204,
14,
3112,
14,
1208,
492,
2622,
6699,
9653,
12,
2622,
4874,
9653,
12,
5673,
1746,
12,
663,
63,
578,
63,
589,
421,
199,
533,
1379,
50,
371,
2075,
14449,
1899,
2377,
8,
2377,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
50,
371,
2075,
14449,
1899,
2377,
12,
291,
680,
5996,
342,
267,
291,
14,
578,
275,
29773,
29490,
63,
751,
339,
347,
6766,
8,
277,
304,
267,
1613,
8,
774,
50,
371,
2075,
14449,
1899,
2377,
12,
291,
680,
12336,
342,
339,
347,
485,
479,
8,
277,
12,
3178,
12,
2225,
12,
1420,
63,
585,
12,
1499,
17364,
267,
574,
275,
3178,
14,
1188,
59,
3215,
61,
340,
2688,
8,
2804,
12,
2225,
9,
587,
3178,
14,
589,
59,
16,
1527,
3215,
61,
267,
702,
574,
508,
1420,
63,
585,
12,
1499,
339,
347,
511,
63,
7395,
63,
2427,
63,
3214,
8,
277,
304,
267,
408,
6782,
1471,
11058,
1380,
1006,
2633,
787,
4124,
624,
267,
543,
291,
14,
1855,
8,
10047,
4874,
9653,
304,
288,
663,
63,
578,
63,
589,
14079,
288,
291,
14,
578,
14,
973,
342,
339,
347,
511,
63,
6060,
63,
1045,
63,
7191,
63,
32071,
8,
277,
304,
267,
663,
63,
578,
63,
589,
2561,
288,
283,
751,
356,
283,
3972,
751,
297,
288,
283,
2060,
356,
283,
3972,
2060,
297,
288,
283,
929,
356,
283,
1881,
297,
288,
283,
6060,
356,
9016,
32071,
356,
1994,
2267,
791,
32071,
356,
1994,
24371,
267,
3828,
267,
543,
3371,
360,
4853,
14,
578,
63,
1208,
14,
4316,
14,
10047,
2377,
14,
362,
63,
1393,
63,
515,
358,
465,
664,
63,
1393,
63,
515,
26,
288,
664,
63,
1393,
63,
515,
14,
1107,
63,
585,
275,
1994,
14411,
29490,
8077,
7,
288,
862,
26,
355,
291,
14,
578,
14,
973,
342,
288,
871,
2622,
4874,
9653,
465,
325,
26,
355,
291,
423,
479,
8,
69,
12,
283,
4892,
297,
715,
9,
355,
291,
423,
479,
8,
69,
12,
283,
1328,
297,
2490,
298,
547,
6057,
3443,
26,
2047,
883,
1133,
1172,
2877,
4983,
10809,
367,
314,
2011,
373,
1102,
531,
339,
768,
2068,
360,
4853,
14,
578,
63,
1208,
14,
4316,
14,
10047,
2377,
14,
362,
63,
1393,
63,
515,
358,
272,
768,
2068,
360,
4853,
14,
3112,
14,
27782,
14,
14411,
29490,
14,
14411,
29490,
63,
751,
14,
50,
371,
2075,
45,
81,
1899,
14,
362,
358,
272,
768,
2068,
360,
4853,
14,
3112,
14,
27782,
14,
14411,
29490,
14,
14411,
29490,
63,
751,
14,
50,
371,
2075,
45,
81,
1899,
14,
1074,
63,
2060,
358,
272,
768,
2068,
360,
4853,
14,
3112,
14,
27782,
14,
14411,
29490,
14,
14411,
29490,
63,
751,
14,
50,
371,
2075,
45,
81,
1899,
14,
1989,
63,
2969,
63,
20945,
83,
358,
272,
768,
2068,
360,
4853,
14,
3112,
14,
27782,
14,
14411,
29490,
14,
14411,
29490,
63,
751,
14,
50,
371,
2075,
45,
81,
1899,
14,
1989,
63,
6060,
63,
20945,
83,
358,
272,
347,
511,
63,
2060,
63,
6627,
63,
2118,
63,
6526,
63,
11368,
8,
277,
12,
965,
63,
6060,
63,
20945,
83,
12,
965,
63,
2969,
63,
20945,
83,
12,
6901,
1104,
63,
2060,
12,
664,
12,
664,
63,
1393,
63,
515,
304,
267,
663,
63,
578,
63,
589,
2561,
288,
283,
751,
356,
283,
3972,
751,
297,
288,
283,
2060,
356,
283,
3972,
2060,
297,
288,
283,
929,
356,
283,
1881,
297,
288,
283,
873,
63,
2060,
356,
283,
9223,
297,
267,
3828,
267,
664,
14,
1107,
63,
585,
275,
715,
267,
664,
63,
1393,
63,
515,
14,
1107,
63,
585,
275,
1994,
14411,
29490,
8077,
7,
267,
1104,
63,
2060,
14,
1107,
63,
585,
275,
715,
267,
965,
63,
2969,
63,
20945,
83,
14,
1107,
63,
585,
275,
756,
267,
965,
63,
6060,
63,
20945,
83,
14,
1107,
63,
585,
275,
756,
267,
862,
26,
288,
291,
14,
578,
14,
973,
342,
267,
871,
2622,
6699,
9653,
465,
325,
26,
288,
291,
423,
479,
8,
69,
12,
283,
2489,
297,
756,
9,
288,
291,
423,
479,
8,
69,
12,
283,
929,
297,
283,
1881,
358,
339,
768,
2068,
360,
4853,
14,
578,
63,
1208,
14,
4316,
14,
10047,
2377,
14,
362,
63,
1393,
63,
515,
358,
272,
768,
2068,
360,
4853,
14,
3112,
14,
27782,
14,
14411,
29490,
14,
14411,
29490,
63,
751,
14,
50,
371,
2075,
45,
81,
1899,
423,
1628,
358,
272,
768,
2068,
360,
4853,
14,
3112,
14,
27782,
14,
14411,
29490,
14,
14411,
29490,
63,
751,
14,
50,
371,
2075,
45,
81,
1899,
423,
362,
63,
6060,
358,
272,
768,
2068,
360,
4853,
14,
3112,
14,
27782,
14,
14411,
29490,
14,
14411,
29490,
63,
751,
14,
50,
371,
2075,
45,
81,
1899,
14,
1989,
63,
2969,
63,
20945,
83,
358,
272,
347,
511,
63,
7191,
63,
6060,
63,
1397,
63,
29131,
8,
277,
12,
965,
63,
2969,
63,
20945,
83,
12,
485,
362,
63,
6060,
12,
485,
1628,
12,
664,
63,
1393,
63,
515,
304,
267,
663,
63,
578,
63,
589,
2561,
288,
283,
751,
356,
283,
3972,
751,
297,
288,
283,
2060,
356,
283,
3972,
2060,
297,
288,
283,
929,
356,
283,
1881,
297,
288,
283,
6060,
356,
9016,
32071,
356,
17220,
283,
6472,
63,
10605,
356,
1987,
7693,
283,
952,
63,
10605,
356,
1987,
7693,
283,
739,
63,
10605,
356,
1987,
10,
24371,
267,
3828,
267,
485,
362,
63,
6060,
14,
1107,
63,
585,
275,
9016,
32071,
356,
17220,
283,
6472,
63,
10605,
356,
1987,
7693,
283,
952,
63,
10605,
356,
1987,
7693,
283,
739,
63,
10605,
356,
1987,
10,
20623,
267,
485,
1628,
14,
1107,
63,
585,
275,
788,
3972,
751,
60,
84,
8607,
418,
267,
664,
63,
1393,
63,
515,
14,
1107,
63,
585,
275,
1994,
14411,
29490,
8077,
7,
267,
965,
63,
2969,
63,
20945,
83,
14,
1107,
63,
585,
275,
756,
267,
862,
26,
288,
291,
14,
578,
14,
973,
342,
267,
871,
2622,
6699,
9653,
465,
325,
26,
288,
291,
423,
479,
8,
69,
12,
283,
2489
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
3242,
14,
3112,
14,
27782,
14,
14411,
29490,
492,
29773,
29490,
63,
751,
199,
504,
6204,
14,
5819,
14,
1805,
492,
3371,
199,
504,
6204,
14,
3112,
14,
1208,
492,
2622,
6699,
9653,
12,
2622,
4874,
9653,
12,
5673,
1746,
12,
663,
63,
578,
63,
589,
421,
199,
533,
1379,
50,
371,
2075,
14449,
1899,
2377,
8,
2377,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
50,
371,
2075,
14449,
1899,
2377,
12,
291,
680,
5996,
342,
267,
291,
14,
578,
275,
29773,
29490,
63,
751,
339,
347,
6766,
8,
277,
304,
267,
1613,
8,
774,
50,
371,
2075,
14449,
1899,
2377,
12,
291,
680,
12336,
342,
339,
347,
485,
479,
8,
277,
12,
3178,
12,
2225,
12,
1420,
63,
585,
12,
1499,
17364,
267,
574,
275,
3178,
14,
1188,
59,
3215,
61,
340,
2688,
8,
2804,
12,
2225,
9,
587,
3178,
14,
589,
59,
16,
1527,
3215,
61,
267,
702,
574,
508,
1420,
63,
585,
12,
1499,
339,
347,
511,
63,
7395,
63,
2427,
63,
3214,
8,
277,
304,
267,
408,
6782,
1471,
11058,
1380,
1006,
2633,
787,
4124,
624,
267,
543,
291,
14,
1855,
8,
10047,
4874,
9653,
304,
288,
663,
63,
578,
63,
589,
14079,
288,
291,
14,
578,
14,
973,
342,
339,
347,
511,
63,
6060,
63,
1045,
63,
7191,
63,
32071,
8,
277,
304,
267,
663,
63,
578,
63,
589,
2561,
288,
283,
751,
356,
283,
3972,
751,
297,
288,
283,
2060,
356,
283,
3972,
2060,
297,
288,
283,
929,
356,
283,
1881,
297,
288,
283,
6060,
356,
9016,
32071,
356,
1994,
2267,
791,
32071,
356,
1994,
24371,
267,
3828,
267,
543,
3371,
360,
4853,
14,
578,
63,
1208,
14,
4316,
14,
10047,
2377,
14,
362,
63,
1393,
63,
515,
358,
465,
664,
63,
1393,
63,
515,
26,
288,
664,
63,
1393,
63,
515,
14,
1107,
63,
585,
275,
1994,
14411,
29490,
8077,
7,
288,
862,
26,
355,
291,
14,
578,
14,
973,
342,
288,
871,
2622,
4874,
9653,
465,
325,
26,
355,
291,
423,
479,
8,
69,
12,
283,
4892,
297,
715,
9,
355,
291,
423,
479,
8,
69,
12,
283,
1328,
297,
2490,
298,
547,
6057,
3443,
26,
2047,
883,
1133,
1172,
2877,
4983,
10809,
367,
314,
2011,
373,
1102,
531,
339,
768,
2068,
360,
4853,
14,
578,
63,
1208,
14,
4316,
14,
10047,
2377,
14,
362,
63,
1393,
63,
515,
358,
272,
768,
2068,
360,
4853,
14,
3112,
14,
27782,
14,
14411,
29490,
14,
14411,
29490,
63,
751,
14,
50,
371,
2075,
45,
81,
1899,
14,
362,
358,
272,
768,
2068,
360,
4853,
14,
3112,
14,
27782,
14,
14411,
29490,
14,
14411,
29490,
63,
751,
14,
50,
371,
2075,
45,
81,
1899,
14,
1074,
63,
2060,
358,
272,
768,
2068,
360,
4853,
14,
3112,
14,
27782,
14,
14411,
29490,
14,
14411,
29490,
63,
751,
14,
50,
371,
2075,
45,
81,
1899,
14,
1989,
63,
2969,
63,
20945,
83,
358,
272,
768,
2068,
360,
4853,
14,
3112,
14,
27782,
14,
14411,
29490,
14,
14411,
29490,
63,
751,
14,
50,
371,
2075,
45,
81,
1899,
14,
1989,
63,
6060,
63,
20945,
83,
358,
272,
347,
511,
63,
2060,
63,
6627,
63,
2118,
63,
6526,
63,
11368,
8,
277,
12,
965,
63,
6060,
63,
20945,
83,
12,
965,
63,
2969,
63,
20945,
83,
12,
6901,
1104,
63,
2060,
12,
664,
12,
664,
63,
1393,
63,
515,
304,
267,
663,
63,
578,
63,
589,
2561,
288,
283,
751,
356,
283,
3972,
751,
297,
288,
283,
2060,
356,
283,
3972,
2060,
297,
288,
283,
929,
356,
283,
1881,
297,
288,
283,
873,
63,
2060,
356,
283,
9223,
297,
267,
3828,
267,
664,
14,
1107,
63,
585,
275,
715,
267,
664,
63,
1393,
63,
515,
14,
1107,
63,
585,
275,
1994,
14411,
29490,
8077,
7,
267,
1104,
63,
2060,
14,
1107,
63,
585,
275,
715,
267,
965,
63,
2969,
63,
20945,
83,
14,
1107,
63,
585,
275,
756,
267,
965,
63,
6060,
63,
20945,
83,
14,
1107,
63,
585,
275,
756,
267,
862,
26,
288,
291,
14,
578,
14,
973,
342,
267,
871,
2622,
6699,
9653,
465,
325,
26,
288,
291,
423,
479,
8,
69,
12,
283,
2489,
297,
756,
9,
288,
291,
423,
479,
8,
69,
12,
283,
929,
297,
283,
1881,
358,
339,
768,
2068,
360,
4853,
14,
578,
63,
1208,
14,
4316,
14,
10047,
2377,
14,
362,
63,
1393,
63,
515,
358,
272,
768,
2068,
360,
4853,
14,
3112,
14,
27782,
14,
14411,
29490,
14,
14411,
29490,
63,
751,
14,
50,
371,
2075,
45,
81,
1899,
423,
1628,
358,
272,
768,
2068,
360,
4853,
14,
3112,
14,
27782,
14,
14411,
29490,
14,
14411,
29490,
63,
751,
14,
50,
371,
2075,
45,
81,
1899,
423,
362,
63,
6060,
358,
272,
768,
2068,
360,
4853,
14,
3112,
14,
27782,
14,
14411,
29490,
14,
14411,
29490,
63,
751,
14,
50,
371,
2075,
45,
81,
1899,
14,
1989,
63,
2969,
63,
20945,
83,
358,
272,
347,
511,
63,
7191,
63,
6060,
63,
1397,
63,
29131,
8,
277,
12,
965,
63,
2969,
63,
20945,
83,
12,
485,
362,
63,
6060,
12,
485,
1628,
12,
664,
63,
1393,
63,
515,
304,
267,
663,
63,
578,
63,
589,
2561,
288,
283,
751,
356,
283,
3972,
751,
297,
288,
283,
2060,
356,
283,
3972,
2060,
297,
288,
283,
929,
356,
283,
1881,
297,
288,
283,
6060,
356,
9016,
32071,
356,
17220,
283,
6472,
63,
10605,
356,
1987,
7693,
283,
952,
63,
10605,
356,
1987,
7693,
283,
739,
63,
10605,
356,
1987,
10,
24371,
267,
3828,
267,
485,
362,
63,
6060,
14,
1107,
63,
585,
275,
9016,
32071,
356,
17220,
283,
6472,
63,
10605,
356,
1987,
7693,
283,
952,
63,
10605,
356,
1987,
7693,
283,
739,
63,
10605,
356,
1987,
10,
20623,
267,
485,
1628,
14,
1107,
63,
585,
275,
788,
3972,
751,
60,
84,
8607,
418,
267,
664,
63,
1393,
63,
515,
14,
1107,
63,
585,
275,
1994,
14411,
29490,
8077,
7,
267,
965,
63,
2969,
63,
20945,
83,
14,
1107,
63,
585,
275,
756,
267,
862,
26,
288,
291,
14,
578,
14,
973,
342,
267,
871,
2622,
6699,
9653,
465,
325,
26,
288,
291,
423,
479,
8,
69,
12,
283,
2489,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pcm17/tensorflow
|
tensorflow/contrib/training/python/training/failure_tolerator_test.py
|
54
|
4445
|
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for tf.contrib.training.failure_tolerator."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import time
from tensorflow.contrib.training.python.training import failure_tolerator
from tensorflow.python.platform import test
class ForgiveMe(Exception):
pass
class Unforgivable(Exception):
pass
class FailureToleratorTest(test.TestCase):
# Tests for the FailureTolerator helper
def testHandledExceptions(self):
tolerator = failure_tolerator.FailureTolerator(
init_delay=0.0, handled_exceptions=[ForgiveMe])
with tolerator.forgive():
raise ForgiveMe()
with self.assertRaises(Unforgivable):
with tolerator.forgive():
raise Unforgivable()
def testLimit(self):
tolerator = failure_tolerator.FailureTolerator(
init_delay=0.0, limit=3, handled_exceptions=[ForgiveMe])
with tolerator.forgive():
raise ForgiveMe()
with tolerator.forgive():
raise ForgiveMe()
with self.assertRaises(ForgiveMe):
with tolerator.forgive():
raise ForgiveMe()
def testDelaysExponentially(self):
# Tests that delays are appropriate, with exponential backoff.
tolerator = failure_tolerator.FailureTolerator(
init_delay=1.0, backoff_factor=1.5, handled_exceptions=[ForgiveMe])
with test.mock.patch.object(time, 'sleep') as mock_sleep:
with tolerator.forgive():
raise ForgiveMe()
with tolerator.forgive():
raise ForgiveMe()
with tolerator.forgive():
raise ForgiveMe()
with tolerator.forgive():
raise ForgiveMe()
mock_sleep.assert_has_calls(
[test.mock.call(1.0), test.mock.call(1.5), test.mock.call(2.25)],
any_order=False)
self.assertEquals(3, mock_sleep.call_count)
def testForgivesSuccessfully(self):
# Tests that exceptions are forgiven after forgive_after_seconds
tolerator = failure_tolerator.FailureTolerator(
limit=3,
init_delay=0.0,
backoff_factor=1.0, # no exponential backoff
forgive_after_seconds=10.0,
handled_exceptions=[ForgiveMe])
cur_time = 10.0
with test.mock.patch.object(time, 'time') as mock_time:
mock_time.side_effect = lambda: cur_time
with tolerator.forgive():
raise ForgiveMe()
cur_time = 15.0
with tolerator.forgive():
raise ForgiveMe()
cur_time = 20.1 # advance more than forgive_after_seconds
with tolerator.forgive():
raise ForgiveMe() # should not be raised
cur_time = 24.0
with self.assertRaises(ForgiveMe):
with tolerator.forgive():
raise ForgiveMe() # third exception in < 10secs (t=15, 20.1, 24)
def testForgivesDoesNotCountDelays(self):
tolerator = failure_tolerator.FailureTolerator(
limit=3,
init_delay=1.0,
backoff_factor=1.0, # no exponential backoff
forgive_after_seconds=10.0,
handled_exceptions=[ForgiveMe])
cur_time = [10.0]
def _sleep(x):
cur_time[0] += x
with test.mock.patch.object(time, 'sleep') as mock_sleep:
with test.mock.patch.object(time, 'time') as mock_time:
mock_time.side_effect = lambda: cur_time[0]
mock_sleep.side_effect = _sleep
with tolerator.forgive():
raise ForgiveMe()
cur_time[0] += 1.0
with tolerator.forgive():
raise ForgiveMe()
self.assertEquals(12.0, time.time()) # ensure there was a sleep
cur_time[0] = 20.1 # 10.1 seconds after the first failure!
with self.assertRaises(ForgiveMe):
with tolerator.forgive():
raise ForgiveMe()
if __name__ == '__main__':
test.main()
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
2833,
14,
2828,
14,
7588,
14,
5328,
63,
475,
1435,
707,
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,
900,
199,
199,
504,
3228,
14,
2828,
14,
7588,
14,
1548,
14,
7588,
492,
5988,
63,
475,
1435,
707,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
481,
1308,
1912,
1352,
8,
1726,
304,
523,
986,
421,
199,
533,
1910,
509,
71,
1003,
461,
8,
1726,
304,
523,
986,
421,
199,
533,
20367,
1378,
1435,
707,
774,
8,
396,
14,
1746,
304,
523,
327,
6496,
367,
314,
20367,
1378,
1435,
707,
5922,
819,
347,
511,
5940,
68,
16836,
8,
277,
304,
272,
370,
1435,
707,
275,
5988,
63,
475,
1435,
707,
14,
6782,
1378,
1435,
707,
8,
267,
4205,
63,
5814,
29,
16,
14,
16,
12,
8860,
63,
3924,
1524,
38,
1308,
1912,
1352,
566,
339,
543,
370,
1435,
707,
14,
509,
26035,
837,
489,
746,
481,
1308,
1912,
1352,
342,
339,
543,
291,
14,
1855,
8,
1358,
509,
71,
1003,
461,
304,
489,
543,
370,
1435,
707,
14,
509,
26035,
837,
267,
746,
1910,
509,
71,
1003,
461,
342,
819,
347,
511,
8407,
8,
277,
304,
272,
370,
1435,
707,
275,
5988,
63,
475,
1435,
707,
14,
6782,
1378,
1435,
707,
8,
267,
4205,
63,
5814,
29,
16,
14,
16,
12,
2304,
29,
19,
12,
8860,
63,
3924,
1524,
38,
1308,
1912,
1352,
566,
339,
543,
370,
1435,
707,
14,
509,
26035,
837,
489,
746,
481,
1308,
1912,
1352,
342,
272,
543,
370,
1435,
707,
14,
509,
26035,
837,
489,
746,
481,
1308,
1912,
1352,
342,
339,
543,
291,
14,
1855,
8,
38,
1308,
1912,
1352,
304,
489,
543,
370,
1435,
707,
14,
509,
26035,
837,
267,
746,
481,
1308,
1912,
1352,
342,
819,
347,
511,
6994,
5758,
920,
10995,
9406,
8,
277,
304,
272,
327,
6496,
626,
477,
9316,
787,
5827,
12,
543,
23160,
22735,
14,
272,
370,
1435,
707,
275,
5988,
63,
475,
1435,
707,
14,
6782,
1378,
1435,
707,
8,
267,
4205,
63,
5814,
29,
17,
14,
16,
12,
22735,
63,
4778,
29,
17,
14,
21,
12,
8860,
63,
3924,
1524,
38,
1308,
1912,
1352,
566,
339,
543,
511,
14,
1805,
14,
2068,
14,
785,
8,
521,
12,
283,
4532,
358,
465,
1683,
63,
4532,
26,
489,
543,
370,
1435,
707,
14,
509,
26035,
837,
267,
746,
481,
1308,
1912,
1352,
342,
2541,
543,
370,
1435,
707,
14,
509,
26035,
837,
267,
746,
481,
1308,
1912,
1352,
342,
2541,
543,
370,
1435,
707,
14,
509,
26035,
837,
267,
746,
481,
1308,
1912,
1352,
342,
2541,
543,
370,
1435,
707,
14,
509,
26035,
837,
267,
746,
481,
1308,
1912,
1352,
342,
2541,
1683,
63,
4532,
14,
479,
63,
1989,
63,
5352,
8,
881,
359,
396,
14,
1805,
14,
1250,
8,
17,
14,
16,
395,
511,
14,
1805,
14,
1250,
8,
17,
14,
21,
395,
511,
14,
1805,
14,
1250,
8,
18,
14,
821,
4360,
881,
1263,
63,
1648,
29,
797,
9,
489,
291,
14,
2947,
8,
19,
12,
1683,
63,
4532,
14,
1250,
63,
835,
9,
819,
347,
511,
38,
1308,
7602,
25001,
8,
277,
304,
272,
327,
6496,
626,
4967,
787,
367,
11809,
2410,
367,
26035,
63,
4399,
63,
4515,
272,
370,
1435,
707,
275,
5988,
63,
475,
1435,
707,
14,
6782,
1378,
1435,
707,
8,
267,
2304,
29,
19,
12,
267,
4205,
63,
5814,
29,
16,
14,
16,
12,
267,
22735,
63,
4778,
29,
17,
14,
16,
12,
221,
327,
949,
23160,
22735,
267,
367,
26035,
63,
4399,
63,
4515,
29,
709,
14,
16,
12,
267,
8860,
63,
3924,
1524,
38,
1308,
1912,
1352,
566,
339,
1094,
63,
521,
275,
1616,
14,
16,
339,
543,
511,
14,
1805,
14,
2068,
14,
785,
8,
521,
12,
283,
521,
358,
465,
1683,
63,
521,
26,
489,
1683,
63,
521,
14,
2441,
63,
5881,
275,
2400,
26,
1094,
63,
521,
2541,
543,
370,
1435,
707,
14,
509,
26035,
837,
267,
746,
481,
1308,
1912,
1352,
342,
489,
1094,
63,
521,
275,
4114,
14,
16,
489,
543,
370,
1435,
707,
14,
509,
26035,
837,
267,
746,
481,
1308,
1912,
1352,
342,
2541,
1094,
63,
521,
275,
3388,
14,
17,
221,
327,
18695,
1655,
2419,
367,
26035,
63,
4399,
63,
4515,
2541,
543,
370,
1435,
707,
14,
509,
26035,
837,
267,
746,
481,
1308,
1912,
1352,
342,
221,
327,
1077,
440,
506,
4915,
2541,
1094,
63,
521,
275,
5504,
14,
16,
2541,
543,
291,
14,
1855,
8,
38,
1308,
1912,
1352,
304,
267,
543,
370,
1435,
707,
14,
509,
26035,
837,
881,
746,
481,
1308,
1912,
1352,
342,
221,
327,
10919,
1919,
315,
665,
1616,
4855,
334,
84,
29,
1046,
12,
3388,
14,
17,
12,
5504,
9,
819,
347,
511,
38,
1308,
7602,
7193,
2353,
6994,
5758,
8,
277,
304,
272,
370,
1435,
707,
275,
5988,
63,
475,
1435,
707,
14,
6782,
1378,
1435,
707,
8,
267,
2304,
29,
19,
12,
267,
4205,
63,
5814,
29,
17,
14,
16,
12,
267,
22735,
63,
4778,
29,
17,
14,
16,
12,
221,
327,
949,
23160,
22735,
267,
367,
26035,
63,
4399,
63,
4515,
29,
709,
14,
16,
12,
267,
8860,
63,
3924,
1524,
38,
1308,
1912,
1352,
566,
339,
1094,
63,
521
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
2833,
14,
2828,
14,
7588,
14,
5328,
63,
475,
1435,
707,
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,
900,
199,
199,
504,
3228,
14,
2828,
14,
7588,
14,
1548,
14,
7588,
492,
5988,
63,
475,
1435,
707,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
481,
1308,
1912,
1352,
8,
1726,
304,
523,
986,
421,
199,
533,
1910,
509,
71,
1003,
461,
8,
1726,
304,
523,
986,
421,
199,
533,
20367,
1378,
1435,
707,
774,
8,
396,
14,
1746,
304,
523,
327,
6496,
367,
314,
20367,
1378,
1435,
707,
5922,
819,
347,
511,
5940,
68,
16836,
8,
277,
304,
272,
370,
1435,
707,
275,
5988,
63,
475,
1435,
707,
14,
6782,
1378,
1435,
707,
8,
267,
4205,
63,
5814,
29,
16,
14,
16,
12,
8860,
63,
3924,
1524,
38,
1308,
1912,
1352,
566,
339,
543,
370,
1435,
707,
14,
509,
26035,
837,
489,
746,
481,
1308,
1912,
1352,
342,
339,
543,
291,
14,
1855,
8,
1358,
509,
71,
1003,
461,
304,
489,
543,
370,
1435,
707,
14,
509,
26035,
837,
267,
746,
1910,
509,
71,
1003,
461,
342,
819,
347,
511,
8407,
8,
277,
304,
272,
370,
1435,
707,
275,
5988,
63,
475,
1435,
707,
14,
6782,
1378,
1435,
707,
8,
267,
4205,
63,
5814,
29,
16,
14,
16,
12,
2304,
29,
19,
12,
8860,
63,
3924,
1524,
38,
1308,
1912,
1352,
566,
339,
543,
370,
1435,
707,
14,
509,
26035,
837,
489,
746,
481,
1308,
1912,
1352,
342,
272,
543,
370,
1435,
707,
14,
509,
26035,
837,
489,
746,
481,
1308,
1912,
1352,
342,
339,
543,
291,
14,
1855,
8,
38,
1308,
1912,
1352,
304,
489,
543,
370,
1435,
707,
14,
509,
26035,
837,
267,
746,
481,
1308,
1912,
1352,
342,
819,
347,
511,
6994,
5758,
920,
10995,
9406,
8,
277,
304,
272,
327,
6496,
626,
477,
9316,
787,
5827,
12,
543,
23160,
22735,
14,
272,
370,
1435,
707,
275,
5988,
63,
475,
1435,
707,
14,
6782,
1378,
1435,
707,
8,
267,
4205,
63,
5814,
29,
17,
14,
16,
12,
22735,
63,
4778,
29,
17,
14,
21,
12,
8860,
63,
3924,
1524,
38,
1308,
1912,
1352,
566,
339,
543,
511,
14,
1805,
14,
2068,
14,
785,
8,
521,
12,
283,
4532,
358,
465,
1683,
63,
4532,
26,
489,
543,
370,
1435,
707,
14,
509,
26035,
837,
267,
746,
481,
1308,
1912,
1352,
342,
2541,
543,
370,
1435,
707,
14,
509,
26035,
837,
267,
746,
481,
1308,
1912,
1352,
342,
2541,
543,
370,
1435,
707,
14,
509,
26035,
837,
267,
746,
481,
1308,
1912,
1352,
342,
2541,
543,
370,
1435,
707,
14,
509,
26035,
837,
267,
746,
481,
1308,
1912,
1352,
342,
2541,
1683,
63,
4532,
14,
479,
63,
1989,
63,
5352,
8,
881,
359,
396,
14,
1805,
14,
1250,
8,
17,
14,
16,
395,
511,
14,
1805,
14,
1250,
8,
17,
14,
21,
395,
511,
14,
1805,
14,
1250,
8,
18,
14,
821,
4360,
881,
1263,
63,
1648,
29,
797,
9,
489,
291,
14,
2947,
8,
19,
12,
1683,
63,
4532,
14,
1250,
63,
835,
9,
819,
347,
511,
38,
1308,
7602,
25001,
8,
277,
304,
272,
327,
6496,
626,
4967,
787,
367,
11809,
2410,
367,
26035,
63,
4399,
63,
4515,
272,
370,
1435,
707,
275,
5988,
63,
475,
1435,
707,
14,
6782,
1378,
1435,
707,
8,
267,
2304,
29,
19,
12,
267,
4205,
63,
5814,
29,
16,
14,
16,
12,
267,
22735,
63,
4778,
29,
17,
14,
16,
12,
221,
327,
949,
23160,
22735,
267,
367,
26035,
63,
4399,
63,
4515,
29,
709,
14,
16,
12,
267,
8860,
63,
3924,
1524,
38,
1308,
1912,
1352,
566,
339,
1094,
63,
521,
275,
1616,
14,
16,
339,
543,
511,
14,
1805,
14,
2068,
14,
785,
8,
521,
12,
283,
521,
358,
465,
1683,
63,
521,
26,
489,
1683,
63,
521,
14,
2441,
63,
5881,
275,
2400,
26,
1094,
63,
521,
2541,
543,
370,
1435,
707,
14,
509,
26035,
837,
267,
746,
481,
1308,
1912,
1352,
342,
489,
1094,
63,
521,
275,
4114,
14,
16,
489,
543,
370,
1435,
707,
14,
509,
26035,
837,
267,
746,
481,
1308,
1912,
1352,
342,
2541,
1094,
63,
521,
275,
3388,
14,
17,
221,
327,
18695,
1655,
2419,
367,
26035,
63,
4399,
63,
4515,
2541,
543,
370,
1435,
707,
14,
509,
26035,
837,
267,
746,
481,
1308,
1912,
1352,
342,
221,
327,
1077,
440,
506,
4915,
2541,
1094,
63,
521,
275,
5504,
14,
16,
2541,
543,
291,
14,
1855,
8,
38,
1308,
1912,
1352,
304,
267,
543,
370,
1435,
707,
14,
509,
26035,
837,
881,
746,
481,
1308,
1912,
1352,
342,
221,
327,
10919,
1919,
315,
665,
1616,
4855,
334,
84,
29,
1046,
12,
3388,
14,
17,
12,
5504,
9,
819,
347,
511,
38,
1308,
7602,
7193,
2353,
6994,
5758,
8,
277,
304,
272,
370,
1435,
707,
275,
5988,
63,
475,
1435,
707,
14,
6782,
1378,
1435,
707,
8,
267,
2304,
29,
19,
12,
267,
4205,
63,
5814,
29,
17,
14,
16,
12,
267,
22735,
63,
4778,
29,
17,
14,
16,
12,
221,
327,
949,
23160,
22735,
267,
367,
26035,
63,
4399,
63,
4515,
29,
709,
14,
16,
12,
267,
8860,
63,
3924,
1524,
38,
1308,
1912,
1352,
566,
339,
1094,
63,
521,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
seanwestfall/django
|
tests/check_framework/test_model_field_deprecation.py
|
322
|
2584
|
from django.core import checks
from django.db import models
from django.test import SimpleTestCase
from .tests import IsolateModelsMixin
class TestDeprecatedField(IsolateModelsMixin, SimpleTestCase):
def test_default_details(self):
class MyField(models.Field):
system_check_deprecated_details = {}
class Model(models.Model):
name = MyField()
model = Model()
self.assertEqual(model.check(), [
checks.Warning(
msg='MyField has been deprecated.',
hint=None,
obj=Model._meta.get_field('name'),
id='fields.WXXX',
)
])
def test_user_specified_details(self):
class MyField(models.Field):
system_check_deprecated_details = {
'msg': 'This field is deprecated and will be removed soon.',
'hint': 'Use something else.',
'id': 'fields.W999',
}
class Model(models.Model):
name = MyField()
model = Model()
self.assertEqual(model.check(), [
checks.Warning(
msg='This field is deprecated and will be removed soon.',
hint='Use something else.',
obj=Model._meta.get_field('name'),
id='fields.W999',
)
])
class TestRemovedField(IsolateModelsMixin, SimpleTestCase):
def test_default_details(self):
class MyField(models.Field):
system_check_removed_details = {}
class Model(models.Model):
name = MyField()
model = Model()
self.assertEqual(model.check(), [
checks.Error(
msg='MyField has been removed except for support in historical migrations.',
hint=None,
obj=Model._meta.get_field('name'),
id='fields.EXXX',
)
])
def test_user_specified_details(self):
class MyField(models.Field):
system_check_removed_details = {
'msg': 'Support for this field is gone.',
'hint': 'Use something else.',
'id': 'fields.E999',
}
class Model(models.Model):
name = MyField()
model = Model()
self.assertEqual(model.check(), [
checks.Error(
msg='Support for this field is gone.',
hint='Use something else.',
obj=Model._meta.get_field('name'),
id='fields.E999',
)
])
|
bsd-3-clause
|
[
504,
1639,
14,
1018,
492,
5920,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
396,
492,
24424,
199,
199,
504,
1275,
2219,
492,
6596,
16288,
20474,
4256,
421,
199,
533,
1379,
19727,
792,
8,
1831,
16288,
20474,
4256,
12,
24424,
304,
272,
347,
511,
63,
885,
63,
5087,
8,
277,
304,
267,
1021,
4932,
792,
8,
992,
14,
792,
304,
288,
2656,
63,
1074,
63,
6667,
63,
5087,
275,
1052,
398,
1021,
5822,
8,
992,
14,
1685,
304,
288,
536,
275,
4932,
792,
342,
398,
1402,
275,
5822,
342,
267,
291,
14,
629,
8,
1238,
14,
1074,
1062,
359,
288,
5920,
14,
3849,
8,
355,
1499,
534,
5713,
792,
965,
2757,
5906,
3130,
355,
8328,
29,
403,
12,
355,
1559,
29,
1685,
423,
2024,
14,
362,
63,
698,
360,
354,
659,
355,
1305,
534,
955,
14,
55,
13933,
297,
288,
776,
267,
4794,
339,
347,
511,
63,
751,
63,
10085,
63,
5087,
8,
277,
304,
267,
1021,
4932,
792,
8,
992,
14,
792,
304,
288,
2656,
63,
1074,
63,
6667,
63,
5087,
275,
469,
355,
283,
1328,
356,
283,
2765,
901,
365,
5906,
436,
911,
506,
4829,
18930,
3130,
355,
283,
6479,
356,
283,
6119,
6020,
587,
3130,
355,
283,
344,
356,
283,
955,
14,
55,
5637,
297,
288,
789,
398,
1021,
5822,
8,
992,
14,
1685,
304,
288,
536,
275,
4932,
792,
342,
398,
1402,
275,
5822,
342,
267,
291,
14,
629,
8,
1238,
14,
1074,
1062,
359,
288,
5920,
14,
3849,
8,
355,
1499,
534,
2765,
901,
365,
5906,
436,
911,
506,
4829,
18930,
3130,
355,
8328,
534,
6119,
6020,
587,
3130,
355,
1559,
29,
1685,
423,
2024,
14,
362,
63,
698,
360,
354,
659,
355,
1305,
534,
955,
14,
55,
5637,
297,
288,
776,
267,
4794,
421,
199,
533,
1379,
23407,
792,
8,
1831,
16288,
20474,
4256,
12,
24424,
304,
272,
347,
511,
63,
885,
63,
5087,
8,
277,
304,
267,
1021,
4932,
792,
8,
992,
14,
792,
304,
288,
2656,
63,
1074,
63,
10649,
63,
5087,
275,
1052,
398,
1021,
5822,
8,
992,
14,
1685,
304,
288,
536,
275,
4932,
792,
342,
398,
1402,
275,
5822,
342,
267,
291,
14,
629,
8,
1238,
14,
1074,
1062,
359,
288,
5920,
14,
547,
8,
355,
1499,
534,
5713,
792,
965,
2757,
4829,
871,
367,
2291,
315,
32530,
6180,
3130,
355,
8328,
29,
403,
12,
355,
1559,
29,
1685,
423,
2024,
14,
362,
63,
698,
360,
354,
659,
355,
1305,
534,
955,
14,
1438,
2483,
297,
288,
776,
267,
4794,
339,
347,
511,
63,
751,
63,
10085,
63,
5087,
8,
277,
304,
267,
1021,
4932,
792,
8,
992,
14,
792,
304,
288,
2656,
63,
1074,
63,
10649,
63,
5087,
275,
469,
355,
283,
1328,
356,
283,
11532,
367,
642,
901,
365,
21737,
3130,
355,
283,
6479,
356,
283,
6119,
6020,
587,
3130,
355,
283,
344,
356,
283,
955,
14,
37,
5637,
297,
288,
789,
398,
1021,
5822,
8,
992,
14,
1685,
304,
288,
536,
275,
4932,
792,
342,
398,
1402,
275,
5822,
342,
267,
291,
14,
629,
8,
1238,
14,
1074,
1062,
359,
288,
5920,
14,
547,
8,
355,
1499,
534,
11532,
367,
642,
901,
365,
21737,
3130,
355,
8328,
534,
6119,
6020,
587,
3130,
355,
1559,
29,
1685,
423,
2024,
14,
362,
63,
698,
360,
354,
659,
355,
1305,
534,
955,
14,
37,
5637,
297,
288,
776,
267,
4794,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
1018,
492,
5920,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
396,
492,
24424,
199,
199,
504,
1275,
2219,
492,
6596,
16288,
20474,
4256,
421,
199,
533,
1379,
19727,
792,
8,
1831,
16288,
20474,
4256,
12,
24424,
304,
272,
347,
511,
63,
885,
63,
5087,
8,
277,
304,
267,
1021,
4932,
792,
8,
992,
14,
792,
304,
288,
2656,
63,
1074,
63,
6667,
63,
5087,
275,
1052,
398,
1021,
5822,
8,
992,
14,
1685,
304,
288,
536,
275,
4932,
792,
342,
398,
1402,
275,
5822,
342,
267,
291,
14,
629,
8,
1238,
14,
1074,
1062,
359,
288,
5920,
14,
3849,
8,
355,
1499,
534,
5713,
792,
965,
2757,
5906,
3130,
355,
8328,
29,
403,
12,
355,
1559,
29,
1685,
423,
2024,
14,
362,
63,
698,
360,
354,
659,
355,
1305,
534,
955,
14,
55,
13933,
297,
288,
776,
267,
4794,
339,
347,
511,
63,
751,
63,
10085,
63,
5087,
8,
277,
304,
267,
1021,
4932,
792,
8,
992,
14,
792,
304,
288,
2656,
63,
1074,
63,
6667,
63,
5087,
275,
469,
355,
283,
1328,
356,
283,
2765,
901,
365,
5906,
436,
911,
506,
4829,
18930,
3130,
355,
283,
6479,
356,
283,
6119,
6020,
587,
3130,
355,
283,
344,
356,
283,
955,
14,
55,
5637,
297,
288,
789,
398,
1021,
5822,
8,
992,
14,
1685,
304,
288,
536,
275,
4932,
792,
342,
398,
1402,
275,
5822,
342,
267,
291,
14,
629,
8,
1238,
14,
1074,
1062,
359,
288,
5920,
14,
3849,
8,
355,
1499,
534,
2765,
901,
365,
5906,
436,
911,
506,
4829,
18930,
3130,
355,
8328,
534,
6119,
6020,
587,
3130,
355,
1559,
29,
1685,
423,
2024,
14,
362,
63,
698,
360,
354,
659,
355,
1305,
534,
955,
14,
55,
5637,
297,
288,
776,
267,
4794,
421,
199,
533,
1379,
23407,
792,
8,
1831,
16288,
20474,
4256,
12,
24424,
304,
272,
347,
511,
63,
885,
63,
5087,
8,
277,
304,
267,
1021,
4932,
792,
8,
992,
14,
792,
304,
288,
2656,
63,
1074,
63,
10649,
63,
5087,
275,
1052,
398,
1021,
5822,
8,
992,
14,
1685,
304,
288,
536,
275,
4932,
792,
342,
398,
1402,
275,
5822,
342,
267,
291,
14,
629,
8,
1238,
14,
1074,
1062,
359,
288,
5920,
14,
547,
8,
355,
1499,
534,
5713,
792,
965,
2757,
4829,
871,
367,
2291,
315,
32530,
6180,
3130,
355,
8328,
29,
403,
12,
355,
1559,
29,
1685,
423,
2024,
14,
362,
63,
698,
360,
354,
659,
355,
1305,
534,
955,
14,
1438,
2483,
297,
288,
776,
267,
4794,
339,
347,
511,
63,
751,
63,
10085,
63,
5087,
8,
277,
304,
267,
1021,
4932,
792,
8,
992,
14,
792,
304,
288,
2656,
63,
1074,
63,
10649,
63,
5087,
275,
469,
355,
283,
1328,
356,
283,
11532,
367,
642,
901,
365,
21737,
3130,
355,
283,
6479,
356,
283,
6119,
6020,
587,
3130,
355,
283,
344,
356,
283,
955,
14,
37,
5637,
297,
288,
789,
398,
1021,
5822,
8,
992,
14,
1685,
304,
288,
536,
275,
4932,
792,
342,
398,
1402,
275,
5822,
342,
267,
291,
14,
629,
8,
1238,
14,
1074,
1062,
359,
288,
5920,
14,
547,
8,
355,
1499,
534,
11532,
367,
642,
901,
365,
21737,
3130,
355,
8328,
534,
6119,
6020,
587,
3130,
355,
1559,
29,
1685,
423,
2024,
14,
362,
63,
698,
360,
354,
659,
355,
1305,
534,
955,
14,
37,
5637,
297,
288,
776,
267,
4794,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
kirichoi/tellurium
|
tellurium/plotting/engine_plotly.py
|
1
|
8252
|
"""
Plotly implementation of the plotting engine.
"""
from __future__ import print_function, absolute_import
from .engine import PlottingEngine, PlottingFigure, PlottingLayout, filterWithSelections, TiledFigure, LowerTriFigure
import numpy as np
import plotly
from plotly.graph_objs import Scatter, Scatter3d, Layout, Data
from plotly import tools
class PlotlyEngine(PlottingEngine):
""" PlottingEngine using plotly. """
def __init__(self):
PlottingEngine.__init__(self)
def __str__(self):
return "<PlotlyEngine>"
def newFigure(self, title=None, logX=False, logY=False, layout=PlottingLayout(), xtitle=None, ytitle=None):
""" Returns a figure object."""
return PlotlyFigure(title=title, layout=layout, xtitle=xtitle, ytitle=ytitle)
def newStackedFigure(self, title=None, logX=False, logY=False, layout=PlottingLayout()):
""" Returns a figure object."""
return PlotlyStackedFigure(title=title, layout=layout)
def newTiledFigure(self, title=None, rows=None, cols=None):
return PlotlyTiledFigure(engine=self, rows=rows, cols=cols)
def newLowerTriFigure(self, title=None, rows=None, cols=None):
return PlotlyLowerTriFigure(engine=self, rows=rows, cols=cols)
class PlotlyFigure(PlottingFigure):
""" PlotlyFigure. """
def __init__(self, title=None, layout=PlottingLayout(), logx=False, logy=False, save_to_pdf=False, xtitle=None, ytitle=None):
super(PlotlyFigure, self).__init__(title=title, layout=layout, logx=logx, xtitle=xtitle, logy=logy, ytitle=ytitle)
def getArgsForDataset(self, dataset):
kwargs = {}
if 'name' in dataset and dataset['name'] is not None:
kwargs['name'] = dataset['name']
else:
kwargs['showlegend'] = False
if 'alpha' in dataset and dataset['alpha'] is not None:
kwargs['opacity'] = dataset['alpha']
# lines/markers (lines by default)
if 'mode' in dataset and dataset['mode'] is not None:
kwargs['mode'] = dataset['mode']
else:
kwargs['mode'] = 'lines'
# override mode via scatter
if 'scatter' in dataset and dataset['scatter'] == True:
kwargs['mode'] = 'markers'
if 'error_y_pos' in dataset and dataset['error_y_pos'] is not None and 'error_y_neg' in dataset and dataset['error_y_neg'] is not None:
kwargs['error_y'] = dict(
type='data',
symmetric=False,
array=dataset['error_y_pos'],
arrayminus=dataset['error_y_neg'],
visible=True,
)
return kwargs
def getScatterGOs(self):
for dataset in self.getDatasets():
yield Scatter(
x = dataset['x'],
y = dataset['y'],
**self.getArgsForDataset(dataset)
)
def render(self):
""" Plot the figure. Call this last."""
traces = list(self.getScatterGOs())
data = Data(traces)
plotly.offline.iplot({
'data': data,
'layout': self.makeLayout()
})
def save(self, filename, format):
# FIXME: implement
raise NotImplementedError
def makeLayout(self):
kwargs = {}
if self.title is not None:
kwargs['title'] = self.title
if self.logx:
kwargs['xaxis'] = {
'type': 'log',
'autorange': True,
}
if self.xtitle:
if not 'xaxis' in kwargs:
kwargs['xaxis'] = {}
kwargs['xaxis']['title'] = self.xtitle
if self.logy:
kwargs['yaxis'] = {
'type': 'log',
'autorange': True,
}
if self.ytitle:
if not 'yaxis' in kwargs:
kwargs['yaxis'] = {}
kwargs['yaxis']['title'] = self.ytitle
if not self.grid_enabled:
kwargs['xaxis']['showgrid'] = False
kwargs['xaxis']['showline'] = False
kwargs['yaxis']['showgrid'] = False
kwargs['yaxis']['showline'] = False
return Layout(**kwargs)
class PlotlyStackedFigure(PlotlyFigure):
""" Stacked figure."""
def __init__(self, title=None, layout=PlottingLayout(), logx=False, logy=False):
super(PlotlyStackedFigure, self).__init__(title=title, layout=layout, logx=logx, logy=logy)
self.zindex = 0
def render(self):
""" Plot the figure. Call this last."""
traces = []
for dataset in self.xy_datasets:
kwargs = {}
if 'name' in dataset and dataset['name'] is not None:
kwargs['name'] = dataset['name']
self.zindex = kwargs['name']
else:
kwargs['showlegend'] = False
zvals = np.full(np.size(dataset['x']), self.zindex)
traces.append(Scatter3d(
x = dataset['x'],
z = dataset['y'],
y = zvals,
mode = 'lines',
**kwargs
))
if not isinstance(self.zindex, str):
self.zindex += 1
data = Data(traces)
plotly.offline.iplot({
'data': data,
'layout': self.makeLayout()
})
class PlotlyTiledFigure(TiledFigure):
def __init__(self, engine, rows, cols):
self.rows = rows
self.rowmarker = 0
self.cols = cols
self.colmarker = 0
self.engine = engine
#self.fig = None
self.figures = []
def nextFigure(self, *args, **kwargs):
self.cycleMarker()
fig = self.engine.newFigure(*args, **kwargs)
self.figures.append(fig)
return fig
def renderIfExhausted(self):
if not self.isExhausted():
return False
fig = tools.make_subplots(self.rows, self.cols, subplot_titles=tuple(f.title for f in self.figures), print_grid=False)
row = 1
col = 1
n = 1
for f in self.figures:
for trace in f.getScatterGOs():
fig.append_trace(trace, row, col)
if f.logx:
fig['layout']['xaxis'+str(n)]['type'] = 'log'
fig['layout']['xaxis'+str(n)]['autorange'] = True
if f.logy:
fig['layout']['yaxis'+str(n)]['type'] = 'log'
fig['layout']['yaxis'+str(n)]['autorange'] = True
col += 1
n += 1
if col > self.cols:
col = 1
row += 1
if row > self.rows:
row = self.rows
plotly.offline.iplot(fig)
return True
class PlotlyLowerTriFigure(PlotlyTiledFigure,LowerTriFigure):
def makeTitles(self):
row = 1
col = 1
for f in self.figures:
yield f.title
col += 1
if col > row:
while col <= self.cols:
col += 1
yield ''
col = 1
row += 1
if row > self.rows:
return;
def renderIfExhausted(self):
if not self.isExhausted():
return False
fig = tools.make_subplots(self.rows, self.cols, subplot_titles=tuple(self.makeTitles()), print_grid=False)
row = 1
col = 1
n = 1
for f in self.figures:
for trace in f.getScatterGOs():
fig.append_trace(trace, row, col)
col += 1
n += 1
if col > row:
while col <= self.cols:
for key in ('xaxis'+str(n), 'yaxis'+str(n)):
fig['layout'][key]['showgrid'] = False
fig['layout'][key]['showline'] = False
fig['layout'][key]['showticklabels'] = False
fig['layout'][key]['ticks'] = ''
fig['layout'][key]['zeroline'] = False
n+=1
col+=1
col = 1
row += 1
if row > self.rows:
row = self.rows
plotly.offline.iplot(fig)
return True
|
apache-2.0
|
[
624,
199,
10711,
590,
4514,
402,
314,
25174,
6869,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
3679,
63,
646,
199,
199,
504,
1275,
3908,
492,
14794,
1337,
8524,
12,
14794,
1337,
25590,
12,
14794,
1337,
4798,
12,
2457,
3007,
7713,
83,
12,
377,
1672,
25590,
12,
29893,
6948,
25590,
199,
646,
2680,
465,
980,
199,
646,
5137,
590,
199,
504,
5137,
590,
14,
2180,
63,
8718,
492,
428,
20569,
12,
428,
20569,
19,
68,
12,
25604,
12,
3918,
199,
504,
5137,
590,
492,
7249,
421,
199,
533,
14794,
590,
8524,
8,
10711,
1337,
8524,
304,
272,
408,
14794,
1337,
8524,
1808,
5137,
590,
14,
408,
339,
347,
636,
826,
721,
277,
304,
267,
14794,
1337,
8524,
855,
826,
721,
277,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
3886,
10711,
590,
8524,
4335,
339,
347,
892,
25590,
8,
277,
12,
2538,
29,
403,
12,
943,
56,
29,
797,
12,
943,
57,
29,
797,
12,
7054,
29,
10711,
1337,
4798,
1062,
671,
1213,
29,
403,
12,
612,
1213,
29,
403,
304,
267,
408,
1803,
282,
9658,
909,
1041,
267,
372,
14794,
590,
25590,
8,
1213,
29,
1213,
12,
7054,
29,
4209,
12,
671,
1213,
29,
88,
1213,
12,
612,
1213,
29,
89,
1213,
9,
339,
347,
892,
4851,
379,
25590,
8,
277,
12,
2538,
29,
403,
12,
943,
56,
29,
797,
12,
943,
57,
29,
797,
12,
7054,
29,
10711,
1337,
4798,
5109,
267,
408,
1803,
282,
9658,
909,
1041,
267,
372,
14794,
590,
4851,
379,
25590,
8,
1213,
29,
1213,
12,
7054,
29,
4209,
9,
339,
347,
892,
52,
1672,
25590,
8,
277,
12,
2538,
29,
403,
12,
4730,
29,
403,
12,
8850,
29,
403,
304,
267,
372,
14794,
590,
52,
1672,
25590,
8,
3908,
29,
277,
12,
4730,
29,
3838,
12,
8850,
29,
4574,
9,
339,
347,
892,
17846,
6948,
25590,
8,
277,
12,
2538,
29,
403,
12,
4730,
29,
403,
12,
8850,
29,
403,
304,
267,
372,
14794,
590,
17846,
6948,
25590,
8,
3908,
29,
277,
12,
4730,
29,
3838,
12,
8850,
29,
4574,
9,
421,
199,
533,
14794,
590,
25590,
8,
10711,
1337,
25590,
304,
272,
408,
14794,
590,
25590,
14,
408,
339,
347,
636,
826,
721,
277,
12,
2538,
29,
403,
12,
7054,
29,
10711,
1337,
4798,
1062,
943,
88,
29,
797,
12,
943,
89,
29,
797,
12,
3354,
63,
475,
63,
5607,
29,
797,
12,
671,
1213,
29,
403,
12,
612,
1213,
29,
403,
304,
267,
1613,
8,
10711,
590,
25590,
12,
291,
2843,
826,
721,
1213,
29,
1213,
12,
7054,
29,
4209,
12,
943,
88,
29,
793,
88,
12,
671,
1213,
29,
88,
1213,
12,
943,
89,
29,
4956,
12,
612,
1213,
29,
89,
1213,
9,
339,
347,
664,
6213,
1858,
9271,
8,
277,
12,
4789,
304,
267,
2074,
275,
1052,
267,
340,
283,
354,
7,
315,
4789,
436,
4789,
459,
354,
418,
365,
440,
488,
26,
288,
2074,
459,
354,
418,
275,
4789,
459,
354,
418,
267,
587,
26,
288,
2074,
459,
2384,
10231,
418,
275,
756,
267,
340,
283,
4468,
7,
315,
4789,
436,
4789,
459,
4468,
418,
365,
440,
488,
26,
288,
2074,
459,
21861,
418,
275,
4789,
459,
4468,
418,
267,
327,
2385,
15,
16835,
334,
1278,
701,
849,
9,
267,
340,
283,
632,
7,
315,
4789,
436,
4789,
459,
632,
418,
365,
440,
488,
26,
288,
2074,
459,
632,
418,
275,
4789,
459,
632,
418,
267,
587,
26,
288,
2074,
459,
632,
418,
275,
283,
1278,
7,
267,
327,
4278,
818,
4799,
28618,
267,
340,
283,
13512,
7,
315,
4789,
436,
4789,
459,
13512,
418,
508,
715,
26,
288,
2074,
459,
632,
418,
275,
283,
16835,
7,
267,
340,
283,
705,
63,
89,
63,
1712,
7,
315,
4789,
436,
4789,
459,
705,
63,
89,
63,
1712,
418,
365,
440,
488,
436,
283,
705,
63,
89,
63,
8705,
7,
315,
4789,
436,
4789,
459,
705,
63,
89,
63,
8705,
418,
365,
440,
488,
26,
288,
2074,
459,
705,
63,
89,
418,
275,
1211,
8,
355,
730,
534,
576,
297,
355,
16371,
29,
797,
12,
355,
1625,
29,
5214,
459,
705,
63,
89,
63,
1712,
995,
355,
1625,
13084,
29,
5214,
459,
705,
63,
89,
63,
8705,
995,
355,
8917,
29,
549,
12,
288,
776,
267,
372,
2074,
339,
347,
664,
51,
20569,
13160,
83,
8,
277,
304,
267,
367,
4789,
315,
291,
14,
29276,
2193,
837,
288,
1995,
428,
20569,
8,
355,
671,
275,
4789,
459,
88,
995,
355,
612,
275,
4789,
459,
89,
995,
355,
1011,
277,
14,
362,
6213,
1858,
9271,
8,
5214,
9,
288,
776,
2378,
347,
3795,
8,
277,
304,
267,
408,
14794,
314,
9658,
14,
6523,
642,
2061,
1041,
267,
26365,
275,
769,
8,
277,
14,
362,
51,
20569,
13160,
83,
1012,
398,
666,
275,
3918,
8,
28388,
9,
267,
5137,
590,
14,
18430,
14,
711,
1653,
2561,
288,
283,
576,
356,
666,
12,
288,
283,
4209,
356,
291,
14,
1875,
4798,
342,
267,
3828,
339,
347,
3354,
8,
277,
12,
1788,
12,
1475,
304,
267,
327,
7600,
26,
5669,
267,
746,
4279,
339,
347,
1852,
4798,
8,
277,
304,
267,
2074,
275,
1052,
267,
340,
291,
14,
1213,
365,
440,
488,
26,
288,
2074,
459,
1213,
418,
275,
291,
14,
1213,
267,
340,
291,
14,
793,
88,
26,
288,
2074,
459,
21854,
418,
275,
469,
355,
283,
466,
356,
283,
793,
297,
355,
283,
65,
4139,
618,
356,
715,
12,
288,
789,
267,
340,
291,
14,
88,
1213,
26,
288,
340,
440,
283,
21854,
7,
315,
2074,
26,
355,
2074,
459,
21854,
418,
275,
1052,
288,
2074,
459,
21854,
2545,
1213,
418,
275,
291,
14,
88,
1213,
267,
340,
291,
14,
4956,
26,
288,
2074,
459,
23876,
418,
275,
469,
355,
283,
466,
356,
283,
793,
297,
355,
283,
65,
4139,
618,
356,
715,
12,
288,
789,
267,
340,
291,
14,
89,
1213,
26,
288,
340,
440,
283,
23876,
7,
315,
2074,
26,
355,
2074,
459,
23876,
418,
275,
1052,
288,
2074,
459,
23876,
2545,
1213,
418,
275,
291,
14,
89,
1213,
267,
340,
440,
291,
14,
3825,
63,
3827,
26,
288,
2074,
459,
21854,
2545,
2384,
3825,
418,
275,
756,
288,
2074,
459,
21854,
2545,
2384,
604,
418,
275
] |
[
199,
10711,
590,
4514,
402,
314,
25174,
6869,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
3679,
63,
646,
199,
199,
504,
1275,
3908,
492,
14794,
1337,
8524,
12,
14794,
1337,
25590,
12,
14794,
1337,
4798,
12,
2457,
3007,
7713,
83,
12,
377,
1672,
25590,
12,
29893,
6948,
25590,
199,
646,
2680,
465,
980,
199,
646,
5137,
590,
199,
504,
5137,
590,
14,
2180,
63,
8718,
492,
428,
20569,
12,
428,
20569,
19,
68,
12,
25604,
12,
3918,
199,
504,
5137,
590,
492,
7249,
421,
199,
533,
14794,
590,
8524,
8,
10711,
1337,
8524,
304,
272,
408,
14794,
1337,
8524,
1808,
5137,
590,
14,
408,
339,
347,
636,
826,
721,
277,
304,
267,
14794,
1337,
8524,
855,
826,
721,
277,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
3886,
10711,
590,
8524,
4335,
339,
347,
892,
25590,
8,
277,
12,
2538,
29,
403,
12,
943,
56,
29,
797,
12,
943,
57,
29,
797,
12,
7054,
29,
10711,
1337,
4798,
1062,
671,
1213,
29,
403,
12,
612,
1213,
29,
403,
304,
267,
408,
1803,
282,
9658,
909,
1041,
267,
372,
14794,
590,
25590,
8,
1213,
29,
1213,
12,
7054,
29,
4209,
12,
671,
1213,
29,
88,
1213,
12,
612,
1213,
29,
89,
1213,
9,
339,
347,
892,
4851,
379,
25590,
8,
277,
12,
2538,
29,
403,
12,
943,
56,
29,
797,
12,
943,
57,
29,
797,
12,
7054,
29,
10711,
1337,
4798,
5109,
267,
408,
1803,
282,
9658,
909,
1041,
267,
372,
14794,
590,
4851,
379,
25590,
8,
1213,
29,
1213,
12,
7054,
29,
4209,
9,
339,
347,
892,
52,
1672,
25590,
8,
277,
12,
2538,
29,
403,
12,
4730,
29,
403,
12,
8850,
29,
403,
304,
267,
372,
14794,
590,
52,
1672,
25590,
8,
3908,
29,
277,
12,
4730,
29,
3838,
12,
8850,
29,
4574,
9,
339,
347,
892,
17846,
6948,
25590,
8,
277,
12,
2538,
29,
403,
12,
4730,
29,
403,
12,
8850,
29,
403,
304,
267,
372,
14794,
590,
17846,
6948,
25590,
8,
3908,
29,
277,
12,
4730,
29,
3838,
12,
8850,
29,
4574,
9,
421,
199,
533,
14794,
590,
25590,
8,
10711,
1337,
25590,
304,
272,
408,
14794,
590,
25590,
14,
408,
339,
347,
636,
826,
721,
277,
12,
2538,
29,
403,
12,
7054,
29,
10711,
1337,
4798,
1062,
943,
88,
29,
797,
12,
943,
89,
29,
797,
12,
3354,
63,
475,
63,
5607,
29,
797,
12,
671,
1213,
29,
403,
12,
612,
1213,
29,
403,
304,
267,
1613,
8,
10711,
590,
25590,
12,
291,
2843,
826,
721,
1213,
29,
1213,
12,
7054,
29,
4209,
12,
943,
88,
29,
793,
88,
12,
671,
1213,
29,
88,
1213,
12,
943,
89,
29,
4956,
12,
612,
1213,
29,
89,
1213,
9,
339,
347,
664,
6213,
1858,
9271,
8,
277,
12,
4789,
304,
267,
2074,
275,
1052,
267,
340,
283,
354,
7,
315,
4789,
436,
4789,
459,
354,
418,
365,
440,
488,
26,
288,
2074,
459,
354,
418,
275,
4789,
459,
354,
418,
267,
587,
26,
288,
2074,
459,
2384,
10231,
418,
275,
756,
267,
340,
283,
4468,
7,
315,
4789,
436,
4789,
459,
4468,
418,
365,
440,
488,
26,
288,
2074,
459,
21861,
418,
275,
4789,
459,
4468,
418,
267,
327,
2385,
15,
16835,
334,
1278,
701,
849,
9,
267,
340,
283,
632,
7,
315,
4789,
436,
4789,
459,
632,
418,
365,
440,
488,
26,
288,
2074,
459,
632,
418,
275,
4789,
459,
632,
418,
267,
587,
26,
288,
2074,
459,
632,
418,
275,
283,
1278,
7,
267,
327,
4278,
818,
4799,
28618,
267,
340,
283,
13512,
7,
315,
4789,
436,
4789,
459,
13512,
418,
508,
715,
26,
288,
2074,
459,
632,
418,
275,
283,
16835,
7,
267,
340,
283,
705,
63,
89,
63,
1712,
7,
315,
4789,
436,
4789,
459,
705,
63,
89,
63,
1712,
418,
365,
440,
488,
436,
283,
705,
63,
89,
63,
8705,
7,
315,
4789,
436,
4789,
459,
705,
63,
89,
63,
8705,
418,
365,
440,
488,
26,
288,
2074,
459,
705,
63,
89,
418,
275,
1211,
8,
355,
730,
534,
576,
297,
355,
16371,
29,
797,
12,
355,
1625,
29,
5214,
459,
705,
63,
89,
63,
1712,
995,
355,
1625,
13084,
29,
5214,
459,
705,
63,
89,
63,
8705,
995,
355,
8917,
29,
549,
12,
288,
776,
267,
372,
2074,
339,
347,
664,
51,
20569,
13160,
83,
8,
277,
304,
267,
367,
4789,
315,
291,
14,
29276,
2193,
837,
288,
1995,
428,
20569,
8,
355,
671,
275,
4789,
459,
88,
995,
355,
612,
275,
4789,
459,
89,
995,
355,
1011,
277,
14,
362,
6213,
1858,
9271,
8,
5214,
9,
288,
776,
2378,
347,
3795,
8,
277,
304,
267,
408,
14794,
314,
9658,
14,
6523,
642,
2061,
1041,
267,
26365,
275,
769,
8,
277,
14,
362,
51,
20569,
13160,
83,
1012,
398,
666,
275,
3918,
8,
28388,
9,
267,
5137,
590,
14,
18430,
14,
711,
1653,
2561,
288,
283,
576,
356,
666,
12,
288,
283,
4209,
356,
291,
14,
1875,
4798,
342,
267,
3828,
339,
347,
3354,
8,
277,
12,
1788,
12,
1475,
304,
267,
327,
7600,
26,
5669,
267,
746,
4279,
339,
347,
1852,
4798,
8,
277,
304,
267,
2074,
275,
1052,
267,
340,
291,
14,
1213,
365,
440,
488,
26,
288,
2074,
459,
1213,
418,
275,
291,
14,
1213,
267,
340,
291,
14,
793,
88,
26,
288,
2074,
459,
21854,
418,
275,
469,
355,
283,
466,
356,
283,
793,
297,
355,
283,
65,
4139,
618,
356,
715,
12,
288,
789,
267,
340,
291,
14,
88,
1213,
26,
288,
340,
440,
283,
21854,
7,
315,
2074,
26,
355,
2074,
459,
21854,
418,
275,
1052,
288,
2074,
459,
21854,
2545,
1213,
418,
275,
291,
14,
88,
1213,
267,
340,
291,
14,
4956,
26,
288,
2074,
459,
23876,
418,
275,
469,
355,
283,
466,
356,
283,
793,
297,
355,
283,
65,
4139,
618,
356,
715,
12,
288,
789,
267,
340,
291,
14,
89,
1213,
26,
288,
340,
440,
283,
23876,
7,
315,
2074,
26,
355,
2074,
459,
23876,
418,
275,
1052,
288,
2074,
459,
23876,
2545,
1213,
418,
275,
291,
14,
89,
1213,
267,
340,
440,
291,
14,
3825,
63,
3827,
26,
288,
2074,
459,
21854,
2545,
2384,
3825,
418,
275,
756,
288,
2074,
459,
21854,
2545,
2384,
604,
418,
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,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ademuk/django-oscar
|
tests/functional/customer/order_status_tests.py
|
53
|
1274
|
from django.utils.six.moves import http_client
from django.core.urlresolvers import reverse
from oscar.test.factories import create_order
from oscar.test.testcases import WebTestCase
class TestAnAnonymousUser(WebTestCase):
def test_gets_a_404_when_requesting_an_unknown_order(self):
path = reverse('customer:anon-order', kwargs={'order_number': 1000,
'hash': '1231231232'})
response = self.app.get(path, status="*")
self.assertEqual(http_client.NOT_FOUND, response.status_code)
def test_can_see_order_status(self):
order = create_order()
path = reverse('customer:anon-order',
kwargs={'order_number': order.number,
'hash': order.verification_hash()})
response = self.app.get(path)
self.assertEqual(http_client.OK, response.status_code)
def test_gets_404_when_using_incorrect_hash(self):
order = create_order()
path = reverse('customer:anon-order',
kwargs={'order_number': order.number,
'hash': 'bad'})
response = self.app.get(path, status="*")
self.assertEqual(http_client.NOT_FOUND, response.status_code)
|
bsd-3-clause
|
[
504,
1639,
14,
1208,
14,
4174,
14,
4912,
492,
1455,
63,
1258,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
199,
504,
312,
22707,
14,
396,
14,
15406,
492,
1218,
63,
1648,
199,
504,
312,
22707,
14,
396,
14,
396,
9403,
492,
6001,
1746,
421,
199,
533,
1379,
2493,
23902,
1899,
8,
5926,
1746,
304,
339,
347,
511,
63,
24894,
63,
65,
63,
5188,
63,
6526,
63,
1069,
316,
63,
290,
63,
5187,
63,
1648,
8,
277,
304,
267,
931,
275,
3837,
360,
10178,
26,
21009,
13,
1648,
297,
2074,
3713,
1648,
63,
1955,
356,
5198,
12,
10028,
283,
2227,
356,
283,
4288,
4288,
713,
708,
3071,
267,
1177,
275,
291,
14,
571,
14,
362,
8,
515,
12,
2004,
32103,
531,
267,
291,
14,
629,
8,
1014,
63,
1258,
14,
4609,
63,
13945,
12,
1177,
14,
1205,
63,
600,
9,
339,
347,
511,
63,
2425,
63,
3239,
63,
1648,
63,
1205,
8,
277,
304,
267,
1865,
275,
1218,
63,
1648,
342,
267,
931,
275,
3837,
360,
10178,
26,
21009,
13,
1648,
297,
2432,
2074,
3713,
1648,
63,
1955,
356,
1865,
14,
1955,
12,
3044,
283,
2227,
356,
1865,
14,
16257,
63,
2227,
22804,
267,
1177,
275,
291,
14,
571,
14,
362,
8,
515,
9,
267,
291,
14,
629,
8,
1014,
63,
1258,
14,
3593,
12,
1177,
14,
1205,
63,
600,
9,
339,
347,
511,
63,
24894,
63,
5188,
63,
6526,
63,
4941,
63,
15448,
63,
2227,
8,
277,
304,
267,
1865,
275,
1218,
63,
1648,
342,
267,
931,
275,
3837,
360,
10178,
26,
21009,
13,
1648,
297,
2432,
2074,
3713,
1648,
63,
1955,
356,
1865,
14,
1955,
12,
3044,
283,
2227,
356,
283,
4087,
3071,
267,
1177,
275,
291,
14,
571,
14,
362,
8,
515,
12,
2004,
32103,
531,
267,
291,
14,
629,
8,
1014,
63,
1258,
14,
4609,
63,
13945,
12,
1177,
14,
1205,
63,
600,
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
] |
[
1639,
14,
1208,
14,
4174,
14,
4912,
492,
1455,
63,
1258,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
199,
504,
312,
22707,
14,
396,
14,
15406,
492,
1218,
63,
1648,
199,
504,
312,
22707,
14,
396,
14,
396,
9403,
492,
6001,
1746,
421,
199,
533,
1379,
2493,
23902,
1899,
8,
5926,
1746,
304,
339,
347,
511,
63,
24894,
63,
65,
63,
5188,
63,
6526,
63,
1069,
316,
63,
290,
63,
5187,
63,
1648,
8,
277,
304,
267,
931,
275,
3837,
360,
10178,
26,
21009,
13,
1648,
297,
2074,
3713,
1648,
63,
1955,
356,
5198,
12,
10028,
283,
2227,
356,
283,
4288,
4288,
713,
708,
3071,
267,
1177,
275,
291,
14,
571,
14,
362,
8,
515,
12,
2004,
32103,
531,
267,
291,
14,
629,
8,
1014,
63,
1258,
14,
4609,
63,
13945,
12,
1177,
14,
1205,
63,
600,
9,
339,
347,
511,
63,
2425,
63,
3239,
63,
1648,
63,
1205,
8,
277,
304,
267,
1865,
275,
1218,
63,
1648,
342,
267,
931,
275,
3837,
360,
10178,
26,
21009,
13,
1648,
297,
2432,
2074,
3713,
1648,
63,
1955,
356,
1865,
14,
1955,
12,
3044,
283,
2227,
356,
1865,
14,
16257,
63,
2227,
22804,
267,
1177,
275,
291,
14,
571,
14,
362,
8,
515,
9,
267,
291,
14,
629,
8,
1014,
63,
1258,
14,
3593,
12,
1177,
14,
1205,
63,
600,
9,
339,
347,
511,
63,
24894,
63,
5188,
63,
6526,
63,
4941,
63,
15448,
63,
2227,
8,
277,
304,
267,
1865,
275,
1218,
63,
1648,
342,
267,
931,
275,
3837,
360,
10178,
26,
21009,
13,
1648,
297,
2432,
2074,
3713,
1648,
63,
1955,
356,
1865,
14,
1955,
12,
3044,
283,
2227,
356,
283,
4087,
3071,
267,
1177,
275,
291,
14,
571,
14,
362,
8,
515,
12,
2004,
32103,
531,
267,
291,
14,
629,
8,
1014,
63,
1258,
14,
4609,
63,
13945,
12,
1177,
14,
1205,
63,
600,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mqeizi/WinObjC
|
deps/3rdparty/icu/icu/source/tools/icu-svnprops-check.py
|
388
|
9251
|
#! /usr/bin/python
# Copyright (C) 2009-2011, International Business Machines Corporation, Google and Others.
# All rights reserved.
#
# Script to check and fix svn property settings for ICU source files.
# Also check for the correct line endings on files with svn:eol-style = native
#
# THIS SCRIPT DOES NOT WORK ON WINDOWS
# It only works correctly on platforms where the native line ending is a plain \n
#
# usage:
# icu-svnprops-check.py [options]
#
# options:
# -f | --fix Fix any problems that are found
# -h | --help Print a usage line and exit.
#
# The tool operates recursively on the directory from which it is run.
# Only files from the svn repository are checked.
# No changes are made to the repository; only the working copy will be altered.
import sys
import os
import os.path
import re
import getopt
#
# svn autoprops definitions.
# Copy and paste here the ICU recommended auto-props from
# http://icu-project.org/docs/subversion_howto/index.html
#
# This program will parse this autoprops string, and verify that files in
# the repository have the recommeded properties set.
#
svn_auto_props = """
### Section for configuring automatic properties.
[auto-props]
### The format of the entries is:
### file-name-pattern = propname[=value][;propname[=value]...]
### The file-name-pattern can contain wildcards (such as '*' and
### '?'). All entries which match will be applied to the file.
### Note that auto-props functionality must be enabled, which
### is typically done by setting the 'enable-auto-props' option.
*.c = svn:eol-style=native
*.cc = svn:eol-style=native
*.cpp = svn:eol-style=native
*.h = svn:eol-style=native
*.rc = svn:eol-style=native
*.dsp = svn:eol-style=native
*.dsw = svn:eol-style=native
*.sln = svn:eol-style=native
*.vcproj = svn:eol-style=native
configure = svn:eol-style=native;svn:executable
*.sh = svn:eol-style=native;svn:executable
*.pl = svn:eol-style=native;svn:executable
*.py = svn:eol-style=native;svn:executable
*.txt = svn:mime-type=text/plain;svn:eol-style=native
*.java = svn:eol-style=native;svn:mime-type=text/plain;;charset=utf-8
*.ucm = svn:eol-style=native
*.html = svn:eol-style=native;svn:mime-type=text/html
*.htm = svn:eol-style=native;svn:mime-type=text/html
*.xml = svn:eol-style=native
Makefile = svn:eol-style=native
*.in = svn:eol-style=native
*.mak = svn:eol-style=native
*.mk = svn:eol-style=native
*.png = svn:mime-type=image/png
*.jpeg = svn:mime-type=image/jpeg
*.jpg = svn:mime-type=image/jpeg
*.bin = svn:mime-type=application/octet-stream
*.brk = svn:mime-type=application/octet-stream
*.cnv = svn:mime-type=application/octet-stream
*.dat = svn:mime-type=application/octet-stream
*.icu = svn:mime-type=application/octet-stream
*.res = svn:mime-type=application/octet-stream
*.spp = svn:mime-type=application/octet-stream
# new additions 2007-dec-5 srl
*.rtf = mime-type=text/rtf
*.pdf = mime-type=application/pdf
# changed 2008-04-08: modified .txt, above, adding mime-type
# changed 2010-11-09: modified .java, adding mime-type
# Note: The escape syntax for semicolon (";;") is supported since subversion 1.6.1
"""
# file_types: The parsed form of the svn auto-props specification.
# A list of file types - .cc, .cpp, .txt, etc.
# each element is a [type, proplist]
# "type" is a regular expression string that will match a file name
# prop list is another list, one element per property.
# Each property item is a two element list, [prop name, prop value]
file_types = list()
def parse_auto_props():
aprops = svn_auto_props.splitlines()
for propline in aprops:
if re.match("\s*(#.*)?$", propline): # Match comment and blank lines
continue
if re.match("\s*\[auto-props\]", propline): # Match the [auto-props] line.
continue
if not re.match("\s*[^\s]+\s*=", propline): # minimal syntax check for <file-type> =
print "Bad line from autoprops definitions: " + propline
continue
file_type, string_proplist = propline.split("=", 1)
#transform the file type expression from autoprops into a normal regular expression.
# e.g. "*.cpp" ==> ".*\.cpp$"
file_type = file_type.strip()
file_type = file_type.replace(".", "\.")
file_type = file_type.replace("*", ".*")
file_type = file_type + "$"
# example string_proplist at this point: " svn:eol-style=native;svn:executable"
# split on ';' into a list of properties. The negative lookahead and lookbehind
# in the split regexp are to prevent matching on ';;', which is an escaped ';'
# within a property value.
string_proplist = re.split("(?<!;);(?!;)", string_proplist)
proplist = list()
for prop in string_proplist:
if prop.find("=") >= 0:
prop_name, prop_val = prop.split("=", 1)
else:
# properties with no explicit value, e.g. svn:executable
prop_name, prop_val = prop, ""
prop_name = prop_name.strip()
prop_val = prop_val.strip()
# unescape any ";;" in a property value, e.g. the mime-type from
# *.java = svn:eol-style=native;svn:mime-type=text/plain;;charset=utf-8
prop_val = prop_val.replace(";;", ";");
proplist.append((prop_name, prop_val))
file_types.append((file_type, proplist))
# print file_types
def runCommand(cmd):
output_file = os.popen(cmd);
output_text = output_file.read();
exit_status = output_file.close();
if exit_status:
print >>sys.stderr, '"', cmd, '" failed. Exiting.'
sys.exit(exit_status)
return output_text
def usage():
print "usage: " + sys.argv[0] + " [-f | --fix] [-h | --help]"
#
# UTF-8 file check. For text files, add a charset to the mime-type if their contents are UTF-8
# file_name: name of a text file.
# base_mime_type: svn:mime-type property value from the auto-props file (no charset= part)
# actual_mime_type: existing svn:mime-type property value for the file.
# return: svn:mime-type property value, with charset added when appropriate.
#
def check_utf8(file_name, base_mime_type, actual_mime_type):
# If the file already has a charset in its mime-type, don't make any change.
if actual_mime_type.find("charset=") > 0:
return actual_mime_type;
f = open(file_name, 'r')
bytes = f.read()
f.close()
if all(ord(byte) < 128 for byte in bytes):
# pure ASCII.
# print "Pure ASCII " + file_name
return base_mime_type
try:
bytes.decode("UTF-8")
except UnicodeDecodeError:
print "warning: %s: not ASCII, not UTF-8" % file_name
return base_mime_type
if ord(bytes[0]) != 0xef:
print "UTF-8 file with no BOM: " + file_name
# Append charset=utf-8.
return base_mime_type + ';charset=utf-8'
def main(argv):
fix_problems = False;
try:
opts, args = getopt.getopt(argv, "fh", ("fix", "help"))
except getopt.GetoptError:
print "unrecognized option: " + argv[0]
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
sys.exit()
if opt in ("-f", "--fix"):
fix_problems = True
if args:
print "unexpected command line argument"
usage()
sys.exit()
parse_auto_props()
output = runCommand("svn ls -R ");
file_list = output.splitlines()
for f in file_list:
if os.path.isdir(f):
# print "Skipping dir " + f
continue
if not os.path.isfile(f):
print "Repository file not in working copy: " + f
continue;
for file_pattern, props in file_types:
if re.match(file_pattern, f):
# print "doing " + f
for propname, propval in props:
actual_propval = runCommand("svn propget --strict " + propname + " " + f)
#print propname + ": " + actual_propval
if propname == "svn:mime-type" and propval.find("text/") == 0:
# check for UTF-8 text files, should have svn:mime-type=text/something; charset=utf8
propval = check_utf8(f, propval, actual_propval)
if not (propval == actual_propval or (propval == "" and actual_propval == "*")):
print "svn propset %s '%s' %s" % (propname, propval, f)
if fix_problems:
os.system("svn propset %s '%s' %s" % (propname, propval, f))
if propname == "svn:eol-style" and propval == "native":
if os.system("grep -q -v \r " + f):
if fix_problems:
print f + ": Removing DOS CR characters."
os.system("sed -i s/\r// " + f);
else:
print f + " contains DOS CR characters."
if __name__ == "__main__":
main(sys.argv[1:])
|
mit
|
[
3168,
1182,
2647,
15,
1393,
15,
1548,
199,
199,
3,
1898,
334,
35,
9,
8937,
13,
8128,
12,
28220,
23813,
30611,
3746,
11098,
12,
4475,
436,
5439,
83,
14,
199,
3,
2900,
4481,
4644,
14,
199,
199,
3,
199,
3,
221,
14914,
370,
1104,
436,
5325,
11327,
3324,
2202,
367,
473,
35,
53,
1350,
1584,
14,
199,
3,
221,
6121,
1104,
367,
314,
3211,
1004,
1284,
780,
641,
1584,
543,
11327,
26,
20470,
13,
2487,
275,
5438,
199,
3,
199,
3,
221,
5749,
30203,
3506,
654,
2845,
29557,
43,
5258,
20896,
1649,
5035,
199,
3,
258,
2779,
1454,
5419,
6657,
641,
10677,
2382,
314,
5438,
1004,
13401,
365,
282,
8971,
971,
78,
199,
3,
199,
3,
221,
4503,
26,
199,
3,
258,
284,
15140,
13,
6836,
6750,
13,
1074,
14,
647,
221,
359,
1419,
61,
199,
3,
199,
3,
221,
1511,
26,
199,
3,
258,
446,
70,
1204,
1553,
970,
258,
14811,
1263,
8826,
626,
787,
1911,
199,
3,
258,
446,
72,
1204,
1553,
3437,
259,
9101,
282,
4503,
1004,
436,
4458,
14,
199,
3,
199,
3,
221,
710,
4744,
1758,
2335,
15035,
641,
314,
2082,
687,
1314,
652,
365,
1255,
14,
199,
3,
221,
5972,
1584,
687,
314,
11327,
7611,
787,
7923,
14,
199,
3,
221,
3091,
4493,
787,
6326,
370,
314,
7611,
27,
1454,
314,
6449,
1331,
911,
506,
29815,
14,
199,
199,
646,
984,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
12733,
199,
199,
3,
199,
3,
221,
11327,
6384,
11340,
1190,
10269,
14,
199,
3,
420,
11247,
436,
20901,
2348,
314,
473,
35,
53,
14318,
2599,
13,
6750,
687,
199,
3,
420,
1455,
921,
530,
85,
13,
1715,
14,
1308,
15,
4757,
15,
954,
1023,
63,
21232,
15,
1080,
14,
1360,
199,
3,
199,
3,
221,
961,
2240,
911,
2198,
642,
6384,
11340,
1190,
1059,
12,
436,
4911,
626,
1584,
315,
199,
3,
221,
314,
7611,
1172,
314,
295,
957,
278,
770,
4382,
663,
14,
199,
3,
199,
6836,
63,
2495,
63,
6750,
275,
408,
199,
5680,
15247,
367,
1101,
4039,
4834,
4382,
14,
199,
59,
2495,
13,
6750,
61,
199,
5680,
710,
1475,
402,
314,
4811,
365,
26,
199,
5680,
257,
570,
13,
354,
13,
3401,
275,
5931,
354,
59,
29,
585,
1527,
27,
4469,
354,
59,
29,
585,
61,
18737,
199,
5680,
710,
570,
13,
354,
13,
3401,
883,
1395,
24952,
334,
10180,
465,
13626,
436,
199,
5680,
8720,
1959,
221,
2900,
4811,
1314,
1336,
911,
506,
6781,
370,
314,
570,
14,
199,
5680,
3390,
626,
2599,
13,
6750,
9330,
1471,
506,
5223,
12,
1314,
199,
5680,
365,
13609,
4224,
701,
4260,
314,
283,
4296,
13,
2495,
13,
6750,
7,
945,
14,
199,
4856,
67,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
2055,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
5910,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
72,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
1195,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
68,
681,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
795,
87,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
29938,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
6737,
5468,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
6472,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
27,
6836,
26,
5904,
199,
4856,
609,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
27,
6836,
26,
5904,
199,
4856,
1168,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
27,
6836,
26,
5904,
199,
4856,
647,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
27,
6836,
26,
5904,
199,
4856,
2424,
275,
11327,
26,
7626,
13,
466,
29,
505,
15,
6104,
27,
6836,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
6138,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
27,
6836,
26,
7626,
13,
466,
29,
505,
15,
6104,
15661,
6043,
29,
1624,
13,
24,
199,
4856,
947,
77,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
1360,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
27,
6836,
26,
7626,
13,
466,
29,
505,
15,
1360,
199,
4856,
15575,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
27,
6836,
26,
7626,
13,
466,
29,
505,
15,
1360,
199,
4856,
1652,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
19878,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
262,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
22191,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
3880,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
4524,
275,
11327,
26,
7626,
13,
466,
29,
1569,
15,
4524,
199,
4856,
14230,
275,
11327,
26,
7626,
13,
466,
29,
1569,
15,
14230,
199,
4856,
8476,
275,
11327,
26,
7626,
13,
466,
29,
1569,
15,
14230,
199,
4856,
1393,
275,
11327,
26,
7626,
13,
466,
29,
3578,
15,
18162,
13,
1745,
199,
4856,
3289,
75,
275,
11327,
26,
7626,
13,
466,
29,
3578,
15,
18162,
13,
1745,
199,
4856,
6413,
86,
275,
11327,
26,
7626,
13,
466,
29,
3578,
15,
18162,
13,
1745,
199,
4856,
4616,
275,
11327,
26,
7626,
13,
466,
29,
3578,
15,
18162,
13,
1745,
199,
4856,
530,
85,
275,
11327,
26,
7626,
13,
466,
29,
3578,
15,
18162,
13,
1745,
199,
4856,
470,
275,
11327,
26,
7626,
13,
466,
29,
3578,
15,
18162,
13,
1745,
199,
4856,
681,
80,
275,
11327,
26,
7626,
13,
466,
29,
3578,
15,
18162,
13,
1745,
199,
3,
892,
32113,
10219,
13,
7778,
13,
21,
308,
4308,
199,
4856,
2591,
70,
275,
6660,
13,
466,
29,
505,
15,
2591,
70,
199,
4856,
5607,
275,
6660,
13,
466,
29,
3578,
15,
5607,
199,
3,
2896,
9079,
13,
966,
13,
2036,
26,
6042,
1275,
2424,
12,
3432,
12,
7791,
6660,
13,
466,
199,
3,
2896,
7129,
13,
845,
13,
1643,
26,
6042,
1275,
6138,
12,
7791,
6660,
13,
466,
199,
3,
3390,
26,
710,
4772,
6302,
367,
18734,
12167,
1689,
27,
15027,
365,
3748,
3967,
1007,
1023,
413,
14,
22,
14,
17,
199,
624,
421,
199,
3,
570,
63,
1313,
26,
221,
710,
4565,
1824,
402,
314,
11327,
2599,
13,
6750,
8929,
14
] |
[
1182,
2647,
15,
1393,
15,
1548,
199,
199,
3,
1898,
334,
35,
9,
8937,
13,
8128,
12,
28220,
23813,
30611,
3746,
11098,
12,
4475,
436,
5439,
83,
14,
199,
3,
2900,
4481,
4644,
14,
199,
199,
3,
199,
3,
221,
14914,
370,
1104,
436,
5325,
11327,
3324,
2202,
367,
473,
35,
53,
1350,
1584,
14,
199,
3,
221,
6121,
1104,
367,
314,
3211,
1004,
1284,
780,
641,
1584,
543,
11327,
26,
20470,
13,
2487,
275,
5438,
199,
3,
199,
3,
221,
5749,
30203,
3506,
654,
2845,
29557,
43,
5258,
20896,
1649,
5035,
199,
3,
258,
2779,
1454,
5419,
6657,
641,
10677,
2382,
314,
5438,
1004,
13401,
365,
282,
8971,
971,
78,
199,
3,
199,
3,
221,
4503,
26,
199,
3,
258,
284,
15140,
13,
6836,
6750,
13,
1074,
14,
647,
221,
359,
1419,
61,
199,
3,
199,
3,
221,
1511,
26,
199,
3,
258,
446,
70,
1204,
1553,
970,
258,
14811,
1263,
8826,
626,
787,
1911,
199,
3,
258,
446,
72,
1204,
1553,
3437,
259,
9101,
282,
4503,
1004,
436,
4458,
14,
199,
3,
199,
3,
221,
710,
4744,
1758,
2335,
15035,
641,
314,
2082,
687,
1314,
652,
365,
1255,
14,
199,
3,
221,
5972,
1584,
687,
314,
11327,
7611,
787,
7923,
14,
199,
3,
221,
3091,
4493,
787,
6326,
370,
314,
7611,
27,
1454,
314,
6449,
1331,
911,
506,
29815,
14,
199,
199,
646,
984,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
12733,
199,
199,
3,
199,
3,
221,
11327,
6384,
11340,
1190,
10269,
14,
199,
3,
420,
11247,
436,
20901,
2348,
314,
473,
35,
53,
14318,
2599,
13,
6750,
687,
199,
3,
420,
1455,
921,
530,
85,
13,
1715,
14,
1308,
15,
4757,
15,
954,
1023,
63,
21232,
15,
1080,
14,
1360,
199,
3,
199,
3,
221,
961,
2240,
911,
2198,
642,
6384,
11340,
1190,
1059,
12,
436,
4911,
626,
1584,
315,
199,
3,
221,
314,
7611,
1172,
314,
295,
957,
278,
770,
4382,
663,
14,
199,
3,
199,
6836,
63,
2495,
63,
6750,
275,
408,
199,
5680,
15247,
367,
1101,
4039,
4834,
4382,
14,
199,
59,
2495,
13,
6750,
61,
199,
5680,
710,
1475,
402,
314,
4811,
365,
26,
199,
5680,
257,
570,
13,
354,
13,
3401,
275,
5931,
354,
59,
29,
585,
1527,
27,
4469,
354,
59,
29,
585,
61,
18737,
199,
5680,
710,
570,
13,
354,
13,
3401,
883,
1395,
24952,
334,
10180,
465,
13626,
436,
199,
5680,
8720,
1959,
221,
2900,
4811,
1314,
1336,
911,
506,
6781,
370,
314,
570,
14,
199,
5680,
3390,
626,
2599,
13,
6750,
9330,
1471,
506,
5223,
12,
1314,
199,
5680,
365,
13609,
4224,
701,
4260,
314,
283,
4296,
13,
2495,
13,
6750,
7,
945,
14,
199,
4856,
67,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
2055,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
5910,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
72,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
1195,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
68,
681,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
795,
87,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
29938,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
6737,
5468,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
6472,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
27,
6836,
26,
5904,
199,
4856,
609,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
27,
6836,
26,
5904,
199,
4856,
1168,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
27,
6836,
26,
5904,
199,
4856,
647,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
27,
6836,
26,
5904,
199,
4856,
2424,
275,
11327,
26,
7626,
13,
466,
29,
505,
15,
6104,
27,
6836,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
6138,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
27,
6836,
26,
7626,
13,
466,
29,
505,
15,
6104,
15661,
6043,
29,
1624,
13,
24,
199,
4856,
947,
77,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
1360,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
27,
6836,
26,
7626,
13,
466,
29,
505,
15,
1360,
199,
4856,
15575,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
27,
6836,
26,
7626,
13,
466,
29,
505,
15,
1360,
199,
4856,
1652,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
19878,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
262,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
22191,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
3880,
275,
11327,
26,
20470,
13,
2487,
29,
6106,
199,
4856,
4524,
275,
11327,
26,
7626,
13,
466,
29,
1569,
15,
4524,
199,
4856,
14230,
275,
11327,
26,
7626,
13,
466,
29,
1569,
15,
14230,
199,
4856,
8476,
275,
11327,
26,
7626,
13,
466,
29,
1569,
15,
14230,
199,
4856,
1393,
275,
11327,
26,
7626,
13,
466,
29,
3578,
15,
18162,
13,
1745,
199,
4856,
3289,
75,
275,
11327,
26,
7626,
13,
466,
29,
3578,
15,
18162,
13,
1745,
199,
4856,
6413,
86,
275,
11327,
26,
7626,
13,
466,
29,
3578,
15,
18162,
13,
1745,
199,
4856,
4616,
275,
11327,
26,
7626,
13,
466,
29,
3578,
15,
18162,
13,
1745,
199,
4856,
530,
85,
275,
11327,
26,
7626,
13,
466,
29,
3578,
15,
18162,
13,
1745,
199,
4856,
470,
275,
11327,
26,
7626,
13,
466,
29,
3578,
15,
18162,
13,
1745,
199,
4856,
681,
80,
275,
11327,
26,
7626,
13,
466,
29,
3578,
15,
18162,
13,
1745,
199,
3,
892,
32113,
10219,
13,
7778,
13,
21,
308,
4308,
199,
4856,
2591,
70,
275,
6660,
13,
466,
29,
505,
15,
2591,
70,
199,
4856,
5607,
275,
6660,
13,
466,
29,
3578,
15,
5607,
199,
3,
2896,
9079,
13,
966,
13,
2036,
26,
6042,
1275,
2424,
12,
3432,
12,
7791,
6660,
13,
466,
199,
3,
2896,
7129,
13,
845,
13,
1643,
26,
6042,
1275,
6138,
12,
7791,
6660,
13,
466,
199,
3,
3390,
26,
710,
4772,
6302,
367,
18734,
12167,
1689,
27,
15027,
365,
3748,
3967,
1007,
1023,
413,
14,
22,
14,
17,
199,
624,
421,
199,
3,
570,
63,
1313,
26,
221,
710,
4565,
1824,
402,
314,
11327,
2599,
13,
6750,
8929,
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,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Simran-B/arangodb
|
3rdParty/V8-4.3.61/third_party/python_26/Lib/test/sortperf.py
|
232
|
4746
|
"""Sort performance test.
See main() for command line syntax.
See tabulate() for output format.
"""
import sys
import time
import random
import marshal
import tempfile
import os
td = tempfile.gettempdir()
def randfloats(n):
"""Return a list of n random floats in [0, 1)."""
# Generating floats is expensive, so this writes them out to a file in
# a temp directory. If the file already exists, it just reads them
# back in and shuffles them a bit.
fn = os.path.join(td, "rr%06d" % n)
try:
fp = open(fn, "rb")
except IOError:
r = random.random
result = [r() for i in xrange(n)]
try:
try:
fp = open(fn, "wb")
marshal.dump(result, fp)
fp.close()
fp = None
finally:
if fp:
try:
os.unlink(fn)
except os.error:
pass
except IOError, msg:
print "can't write", fn, ":", msg
else:
result = marshal.load(fp)
fp.close()
# Shuffle it a bit...
for i in range(10):
i = random.randrange(n)
temp = result[:i]
del result[:i]
temp.reverse()
result.extend(temp)
del temp
assert len(result) == n
return result
def flush():
sys.stdout.flush()
def doit(L):
t0 = time.clock()
L.sort()
t1 = time.clock()
print "%6.2f" % (t1-t0),
flush()
def tabulate(r):
"""Tabulate sort speed for lists of various sizes.
The sizes are 2**i for i in r (the argument, a list).
The output displays i, 2**i, and the time to sort arrays of 2**i
floating point numbers with the following properties:
*sort: random data
\sort: descending data
/sort: ascending data
3sort: ascending, then 3 random exchanges
+sort: ascending, then 10 random at the end
%sort: ascending, then randomly replace 1% of the elements w/ random values
~sort: many duplicates
=sort: all equal
!sort: worst case scenario
"""
cases = tuple([ch + "sort" for ch in r"*\/3+%~=!"])
fmt = ("%2s %7s" + " %6s"*len(cases))
print fmt % (("i", "2**i") + cases)
for i in r:
n = 1 << i
L = randfloats(n)
print "%2d %7d" % (i, n),
flush()
doit(L) # *sort
L.reverse()
doit(L) # \sort
doit(L) # /sort
# Do 3 random exchanges.
for dummy in range(3):
i1 = random.randrange(n)
i2 = random.randrange(n)
L[i1], L[i2] = L[i2], L[i1]
doit(L) # 3sort
# Replace the last 10 with random floats.
if n >= 10:
L[-10:] = [random.random() for dummy in range(10)]
doit(L) # +sort
# Replace 1% of the elements at random.
for dummy in xrange(n // 100):
L[random.randrange(n)] = random.random()
doit(L) # %sort
# Arrange for lots of duplicates.
if n > 4:
del L[4:]
L = L * (n // 4)
# Force the elements to be distinct objects, else timings can be
# artificially low.
L = map(lambda x: --x, L)
doit(L) # ~sort
del L
# All equal. Again, force the elements to be distinct objects.
L = map(abs, [-0.5] * n)
doit(L) # =sort
del L
# This one looks like [3, 2, 1, 0, 0, 1, 2, 3]. It was a bad case
# for an older implementation of quicksort, which used the median
# of the first, last and middle elements as the pivot.
half = n // 2
L = range(half - 1, -1, -1)
L.extend(range(half))
# Force to float, so that the timings are comparable. This is
# significantly faster if we leave tham as ints.
L = map(float, L)
doit(L) # !sort
print
def main():
"""Main program when invoked as a script.
One argument: tabulate a single row.
Two arguments: tabulate a range (inclusive).
Extra arguments are used to seed the random generator.
"""
# default range (inclusive)
k1 = 15
k2 = 20
if sys.argv[1:]:
# one argument: single point
k1 = k2 = int(sys.argv[1])
if sys.argv[2:]:
# two arguments: specify range
k2 = int(sys.argv[2])
if sys.argv[3:]:
# derive random seed from remaining arguments
x = 1
for a in sys.argv[3:]:
x = 69069 * x + hash(a)
random.seed(x)
r = range(k1, k2+1) # include the end point
tabulate(r)
if __name__ == '__main__':
main()
|
apache-2.0
|
[
624,
14376,
10238,
511,
14,
199,
199,
9295,
2446,
342,
367,
1414,
1004,
6302,
14,
199,
9295,
5174,
5434,
342,
367,
1072,
1475,
14,
199,
199,
624,
199,
199,
646,
984,
199,
646,
900,
199,
646,
2196,
199,
646,
21985,
199,
646,
5549,
199,
646,
747,
199,
199,
2076,
275,
5549,
14,
31572,
342,
199,
199,
318,
10261,
1609,
83,
8,
78,
304,
272,
408,
1767,
282,
769,
402,
302,
2196,
15657,
315,
359,
16,
12,
413,
10477,
272,
327,
1464,
1958,
15657,
365,
23133,
12,
880,
642,
14511,
3062,
734,
370,
282,
570,
315,
272,
327,
282,
2388,
2082,
14,
221,
982,
314,
570,
2575,
3495,
12,
652,
2951,
11597,
3062,
272,
327,
1771,
315,
436,
28126,
2978,
3062,
282,
4546,
14,
272,
4325,
275,
747,
14,
515,
14,
904,
8,
2076,
12,
298,
9734,
5,
1690,
68,
2,
450,
302,
9,
272,
862,
26,
267,
4090,
275,
1551,
8,
2324,
12,
298,
4848,
531,
272,
871,
5925,
26,
267,
519,
275,
2196,
14,
2355,
267,
754,
275,
359,
82,
342,
367,
284,
315,
4945,
8,
78,
1874,
267,
862,
26,
288,
862,
26,
355,
4090,
275,
1551,
8,
2324,
12,
298,
6603,
531,
355,
21985,
14,
2724,
8,
1099,
12,
4090,
9,
355,
4090,
14,
1600,
342,
355,
4090,
275,
488,
288,
3753,
26,
355,
340,
4090,
26,
490,
862,
26,
717,
747,
14,
7162,
8,
2324,
9,
490,
871,
747,
14,
705,
26,
717,
986,
267,
871,
5925,
12,
1499,
26,
288,
870,
298,
2425,
1133,
2218,
401,
4325,
12,
298,
6783,
1499,
272,
587,
26,
267,
754,
275,
21985,
14,
912,
8,
3997,
9,
267,
4090,
14,
1600,
342,
267,
327,
5244,
6817,
652,
282,
4546,
1396,
267,
367,
284,
315,
1425,
8,
709,
304,
288,
284,
275,
2196,
14,
20539,
8,
78,
9,
288,
2388,
275,
754,
1491,
73,
61,
288,
2150,
754,
1491,
73,
61,
288,
2388,
14,
4471,
342,
288,
754,
14,
2880,
8,
808,
9,
288,
2150,
2388,
272,
702,
822,
8,
1099,
9,
508,
302,
272,
372,
754,
199,
199,
318,
8976,
837,
272,
984,
14,
2703,
14,
4939,
342,
199,
199,
318,
886,
390,
8,
44,
304,
272,
307,
16,
275,
900,
14,
9597,
342,
272,
491,
14,
3191,
342,
272,
307,
17,
275,
900,
14,
9597,
342,
272,
870,
2071,
22,
14,
18,
70,
2,
450,
334,
84,
17,
13,
84,
16,
395,
272,
8976,
342,
199,
199,
318,
5174,
5434,
8,
82,
304,
272,
408,
7690,
5434,
4069,
8112,
367,
5548,
402,
7750,
10627,
14,
339,
710,
10627,
787,
499,
538,
73,
367,
284,
315,
519,
334,
1589,
1423,
12,
282,
769,
680,
339,
710,
1072,
17561,
284,
12,
499,
538,
73,
12,
436,
314,
900,
370,
4069,
6572,
402,
499,
538,
73,
272,
8402,
2376,
5579,
543,
314,
2569,
4382,
26,
339,
627,
3191,
26,
2196,
666,
272,
971,
3191,
26,
27524,
666,
272,
1182,
3191,
26,
24525,
666,
272,
650,
3191,
26,
24525,
12,
2066,
650,
2196,
444,
6627,
272,
435,
3191,
26,
24525,
12,
2066,
1616,
2196,
737,
314,
1284,
272,
450,
3191,
26,
24525,
12,
2066,
19311,
3350,
413,
5,
402,
314,
4008,
336,
15,
2196,
1338,
272,
6146,
3191,
26,
5002,
15755,
272,
275,
3191,
26,
1006,
4472,
272,
8546,
3191,
26,
1319,
270,
1930,
15728,
339,
408,
272,
5560,
275,
2008,
779,
335,
435,
298,
3191,
2,
367,
682,
315,
519,
2,
7590,
15,
19,
25389,
94,
29,
1,
3135,
272,
7104,
275,
19426,
18,
83,
450,
23,
83,
2,
435,
298,
450,
22,
83,
31761,
552,
8,
9403,
430,
272,
870,
7104,
450,
19110,
73,
401,
298,
18,
538,
73,
531,
435,
5560,
9,
272,
367,
284,
315,
519,
26,
267,
302,
275,
413,
5213,
284,
267,
491,
275,
10261,
1609,
83,
8,
78,
9,
267,
870,
2071,
18,
68,
450,
23,
68,
2,
450,
334,
73,
12,
302,
395,
267,
8976,
342,
267,
886,
390,
8,
44,
9,
327,
627,
3191,
267,
491,
14,
4471,
342,
267,
886,
390,
8,
44,
9,
327,
971,
3191,
267,
886,
390,
8,
44,
9,
327,
1182,
3191,
398,
327,
4226,
650,
2196,
444,
6627,
14,
267,
367,
7283,
315,
1425,
8,
19,
304,
288,
284,
17,
275,
2196,
14,
20539,
8,
78,
9,
288,
284,
18,
275,
2196,
14,
20539,
8,
78,
9,
288,
491,
59,
73,
17,
467,
491,
59,
73,
18,
61,
275,
491,
59,
73,
18,
467,
491,
59,
73,
17,
61,
267,
886,
390,
8,
44,
9,
327,
650,
3191,
398,
327,
14402,
314,
2061,
1616,
543,
2196,
15657,
14,
267,
340,
302,
2356,
1616,
26,
288,
491,
1988,
709,
2938,
275,
359,
2355,
14,
2355,
342,
367,
7283,
315,
1425,
8,
709,
1874,
267,
886,
390,
8,
44,
9,
327,
435,
3191,
398,
327,
14402,
413,
5,
402,
314,
4008,
737,
2196,
14,
267,
367,
7283,
315,
4945,
8,
78,
5001,
2948,
304,
288,
491,
59,
2355,
14,
20539,
8,
78,
1874,
275,
2196,
14,
2355,
342,
267,
886,
390,
8,
44,
9,
327,
450,
3191,
398,
327,
1952,
1842,
367,
24213,
402,
15755,
14,
267,
340,
302,
690,
841,
26,
288,
2150,
491,
59,
20,
2938,
288,
491,
275,
491,
627,
334,
78,
5001,
841,
9,
288,
327,
18771,
314,
4008,
370,
506,
15392,
2251,
12,
587,
221,
27337,
883,
506,
288,
327,
601,
1428,
559,
1183,
6465,
14,
288,
491,
275,
2341,
8,
2734,
671,
26,
1553,
88,
12,
491,
9,
267,
886,
390,
8,
44,
9,
327,
6146,
3191,
267,
2150,
491,
398,
327,
2900,
4472,
14,
221,
437,
13020,
12,
3542,
314,
4008,
370,
506,
15392,
2251,
14,
267,
491,
275,
2341,
8,
2101,
12,
5243,
16,
14,
21,
61,
627,
302,
9,
267,
886,
390,
8,
44,
9,
327,
275,
3191,
267,
2150,
491,
398,
327,
961,
1373,
10734,
2839,
359,
19,
12,
499,
12,
413,
12,
378,
12,
378,
12,
413,
12,
499,
12,
650,
1055,
221,
2779,
1990,
282,
4875,
1930,
267,
327,
367,
376,
12731,
4514,
402,
12530,
3191,
12,
1314,
1202,
314,
17312,
267,
327,
402,
314,
1642,
12,
2061,
436,
12180,
4008,
465,
314,
22292,
14,
267,
12995,
275,
302,
5001,
499,
267,
491,
275,
1425,
8,
10220,
446,
413,
12,
446
] |
[
14376,
10238,
511,
14,
199,
199,
9295,
2446,
342,
367,
1414,
1004,
6302,
14,
199,
9295,
5174,
5434,
342,
367,
1072,
1475,
14,
199,
199,
624,
199,
199,
646,
984,
199,
646,
900,
199,
646,
2196,
199,
646,
21985,
199,
646,
5549,
199,
646,
747,
199,
199,
2076,
275,
5549,
14,
31572,
342,
199,
199,
318,
10261,
1609,
83,
8,
78,
304,
272,
408,
1767,
282,
769,
402,
302,
2196,
15657,
315,
359,
16,
12,
413,
10477,
272,
327,
1464,
1958,
15657,
365,
23133,
12,
880,
642,
14511,
3062,
734,
370,
282,
570,
315,
272,
327,
282,
2388,
2082,
14,
221,
982,
314,
570,
2575,
3495,
12,
652,
2951,
11597,
3062,
272,
327,
1771,
315,
436,
28126,
2978,
3062,
282,
4546,
14,
272,
4325,
275,
747,
14,
515,
14,
904,
8,
2076,
12,
298,
9734,
5,
1690,
68,
2,
450,
302,
9,
272,
862,
26,
267,
4090,
275,
1551,
8,
2324,
12,
298,
4848,
531,
272,
871,
5925,
26,
267,
519,
275,
2196,
14,
2355,
267,
754,
275,
359,
82,
342,
367,
284,
315,
4945,
8,
78,
1874,
267,
862,
26,
288,
862,
26,
355,
4090,
275,
1551,
8,
2324,
12,
298,
6603,
531,
355,
21985,
14,
2724,
8,
1099,
12,
4090,
9,
355,
4090,
14,
1600,
342,
355,
4090,
275,
488,
288,
3753,
26,
355,
340,
4090,
26,
490,
862,
26,
717,
747,
14,
7162,
8,
2324,
9,
490,
871,
747,
14,
705,
26,
717,
986,
267,
871,
5925,
12,
1499,
26,
288,
870,
298,
2425,
1133,
2218,
401,
4325,
12,
298,
6783,
1499,
272,
587,
26,
267,
754,
275,
21985,
14,
912,
8,
3997,
9,
267,
4090,
14,
1600,
342,
267,
327,
5244,
6817,
652,
282,
4546,
1396,
267,
367,
284,
315,
1425,
8,
709,
304,
288,
284,
275,
2196,
14,
20539,
8,
78,
9,
288,
2388,
275,
754,
1491,
73,
61,
288,
2150,
754,
1491,
73,
61,
288,
2388,
14,
4471,
342,
288,
754,
14,
2880,
8,
808,
9,
288,
2150,
2388,
272,
702,
822,
8,
1099,
9,
508,
302,
272,
372,
754,
199,
199,
318,
8976,
837,
272,
984,
14,
2703,
14,
4939,
342,
199,
199,
318,
886,
390,
8,
44,
304,
272,
307,
16,
275,
900,
14,
9597,
342,
272,
491,
14,
3191,
342,
272,
307,
17,
275,
900,
14,
9597,
342,
272,
870,
2071,
22,
14,
18,
70,
2,
450,
334,
84,
17,
13,
84,
16,
395,
272,
8976,
342,
199,
199,
318,
5174,
5434,
8,
82,
304,
272,
408,
7690,
5434,
4069,
8112,
367,
5548,
402,
7750,
10627,
14,
339,
710,
10627,
787,
499,
538,
73,
367,
284,
315,
519,
334,
1589,
1423,
12,
282,
769,
680,
339,
710,
1072,
17561,
284,
12,
499,
538,
73,
12,
436,
314,
900,
370,
4069,
6572,
402,
499,
538,
73,
272,
8402,
2376,
5579,
543,
314,
2569,
4382,
26,
339,
627,
3191,
26,
2196,
666,
272,
971,
3191,
26,
27524,
666,
272,
1182,
3191,
26,
24525,
666,
272,
650,
3191,
26,
24525,
12,
2066,
650,
2196,
444,
6627,
272,
435,
3191,
26,
24525,
12,
2066,
1616,
2196,
737,
314,
1284,
272,
450,
3191,
26,
24525,
12,
2066,
19311,
3350,
413,
5,
402,
314,
4008,
336,
15,
2196,
1338,
272,
6146,
3191,
26,
5002,
15755,
272,
275,
3191,
26,
1006,
4472,
272,
8546,
3191,
26,
1319,
270,
1930,
15728,
339,
408,
272,
5560,
275,
2008,
779,
335,
435,
298,
3191,
2,
367,
682,
315,
519,
2,
7590,
15,
19,
25389,
94,
29,
1,
3135,
272,
7104,
275,
19426,
18,
83,
450,
23,
83,
2,
435,
298,
450,
22,
83,
31761,
552,
8,
9403,
430,
272,
870,
7104,
450,
19110,
73,
401,
298,
18,
538,
73,
531,
435,
5560,
9,
272,
367,
284,
315,
519,
26,
267,
302,
275,
413,
5213,
284,
267,
491,
275,
10261,
1609,
83,
8,
78,
9,
267,
870,
2071,
18,
68,
450,
23,
68,
2,
450,
334,
73,
12,
302,
395,
267,
8976,
342,
267,
886,
390,
8,
44,
9,
327,
627,
3191,
267,
491,
14,
4471,
342,
267,
886,
390,
8,
44,
9,
327,
971,
3191,
267,
886,
390,
8,
44,
9,
327,
1182,
3191,
398,
327,
4226,
650,
2196,
444,
6627,
14,
267,
367,
7283,
315,
1425,
8,
19,
304,
288,
284,
17,
275,
2196,
14,
20539,
8,
78,
9,
288,
284,
18,
275,
2196,
14,
20539,
8,
78,
9,
288,
491,
59,
73,
17,
467,
491,
59,
73,
18,
61,
275,
491,
59,
73,
18,
467,
491,
59,
73,
17,
61,
267,
886,
390,
8,
44,
9,
327,
650,
3191,
398,
327,
14402,
314,
2061,
1616,
543,
2196,
15657,
14,
267,
340,
302,
2356,
1616,
26,
288,
491,
1988,
709,
2938,
275,
359,
2355,
14,
2355,
342,
367,
7283,
315,
1425,
8,
709,
1874,
267,
886,
390,
8,
44,
9,
327,
435,
3191,
398,
327,
14402,
413,
5,
402,
314,
4008,
737,
2196,
14,
267,
367,
7283,
315,
4945,
8,
78,
5001,
2948,
304,
288,
491,
59,
2355,
14,
20539,
8,
78,
1874,
275,
2196,
14,
2355,
342,
267,
886,
390,
8,
44,
9,
327,
450,
3191,
398,
327,
1952,
1842,
367,
24213,
402,
15755,
14,
267,
340,
302,
690,
841,
26,
288,
2150,
491,
59,
20,
2938,
288,
491,
275,
491,
627,
334,
78,
5001,
841,
9,
288,
327,
18771,
314,
4008,
370,
506,
15392,
2251,
12,
587,
221,
27337,
883,
506,
288,
327,
601,
1428,
559,
1183,
6465,
14,
288,
491,
275,
2341,
8,
2734,
671,
26,
1553,
88,
12,
491,
9,
267,
886,
390,
8,
44,
9,
327,
6146,
3191,
267,
2150,
491,
398,
327,
2900,
4472,
14,
221,
437,
13020,
12,
3542,
314,
4008,
370,
506,
15392,
2251,
14,
267,
491,
275,
2341,
8,
2101,
12,
5243,
16,
14,
21,
61,
627,
302,
9,
267,
886,
390,
8,
44,
9,
327,
275,
3191,
267,
2150,
491,
398,
327,
961,
1373,
10734,
2839,
359,
19,
12,
499,
12,
413,
12,
378,
12,
378,
12,
413,
12,
499,
12,
650,
1055,
221,
2779,
1990,
282,
4875,
1930,
267,
327,
367,
376,
12731,
4514,
402,
12530,
3191,
12,
1314,
1202,
314,
17312,
267,
327,
402,
314,
1642,
12,
2061,
436,
12180,
4008,
465,
314,
22292,
14,
267,
12995,
275,
302,
5001,
499,
267,
491,
275,
1425,
8,
10220,
446,
413,
12,
446,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
rui-castro/Sick-Beard
|
lib/html5lib/sanitizer.py
|
100
|
14472
|
import re
from xml.sax.saxutils import escape, unescape
from tokenizer import HTMLTokenizer
from constants import tokenTypes
class HTMLSanitizerMixin(object):
""" sanitization of XHTML+MathML+SVG and of inline style attributes."""
acceptable_elements = ['a', 'abbr', 'acronym', 'address', 'area',
'article', 'aside', 'audio', 'b', 'big', 'blockquote', 'br', 'button',
'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup',
'command', 'datagrid', 'datalist', 'dd', 'del', 'details', 'dfn',
'dialog', 'dir', 'div', 'dl', 'dt', 'em', 'event-source', 'fieldset',
'figcaption', 'figure', 'footer', 'font', 'form', 'header', 'h1',
'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'input', 'ins',
'keygen', 'kbd', 'label', 'legend', 'li', 'm', 'map', 'menu', 'meter',
'multicol', 'nav', 'nextid', 'ol', 'output', 'optgroup', 'option',
'p', 'pre', 'progress', 'q', 's', 'samp', 'section', 'select',
'small', 'sound', 'source', 'spacer', 'span', 'strike', 'strong',
'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'time', 'tfoot',
'th', 'thead', 'tr', 'tt', 'u', 'ul', 'var', 'video']
mathml_elements = ['maction', 'math', 'merror', 'mfrac', 'mi',
'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom',
'mprescripts', 'mroot', 'mrow', 'mspace', 'msqrt', 'mstyle', 'msub',
'msubsup', 'msup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder',
'munderover', 'none']
svg_elements = ['a', 'animate', 'animateColor', 'animateMotion',
'animateTransform', 'clipPath', 'circle', 'defs', 'desc', 'ellipse',
'font-face', 'font-face-name', 'font-face-src', 'g', 'glyph', 'hkern',
'linearGradient', 'line', 'marker', 'metadata', 'missing-glyph',
'mpath', 'path', 'polygon', 'polyline', 'radialGradient', 'rect',
'set', 'stop', 'svg', 'switch', 'text', 'title', 'tspan', 'use']
acceptable_attributes = ['abbr', 'accept', 'accept-charset', 'accesskey',
'action', 'align', 'alt', 'autocomplete', 'autofocus', 'axis',
'background', 'balance', 'bgcolor', 'bgproperties', 'border',
'bordercolor', 'bordercolordark', 'bordercolorlight', 'bottompadding',
'cellpadding', 'cellspacing', 'ch', 'challenge', 'char', 'charoff',
'choff', 'charset', 'checked', 'cite', 'class', 'clear', 'color',
'cols', 'colspan', 'compact', 'contenteditable', 'controls', 'coords',
'data', 'datafld', 'datapagesize', 'datasrc', 'datetime', 'default',
'delay', 'dir', 'disabled', 'draggable', 'dynsrc', 'enctype', 'end',
'face', 'for', 'form', 'frame', 'galleryimg', 'gutter', 'headers',
'height', 'hidefocus', 'hidden', 'high', 'href', 'hreflang', 'hspace',
'icon', 'id', 'inputmode', 'ismap', 'keytype', 'label', 'leftspacing',
'lang', 'list', 'longdesc', 'loop', 'loopcount', 'loopend',
'loopstart', 'low', 'lowsrc', 'max', 'maxlength', 'media', 'method',
'min', 'multiple', 'name', 'nohref', 'noshade', 'nowrap', 'open',
'optimum', 'pattern', 'ping', 'point-size', 'prompt', 'pqg',
'radiogroup', 'readonly', 'rel', 'repeat-max', 'repeat-min',
'replace', 'required', 'rev', 'rightspacing', 'rows', 'rowspan',
'rules', 'scope', 'selected', 'shape', 'size', 'span', 'src', 'start',
'step', 'style', 'summary', 'suppress', 'tabindex', 'target',
'template', 'title', 'toppadding', 'type', 'unselectable', 'usemap',
'urn', 'valign', 'value', 'variable', 'volume', 'vspace', 'vrml',
'width', 'wrap', 'xml:lang']
mathml_attributes = ['actiontype', 'align', 'columnalign', 'columnalign',
'columnalign', 'columnlines', 'columnspacing', 'columnspan', 'depth',
'display', 'displaystyle', 'equalcolumns', 'equalrows', 'fence',
'fontstyle', 'fontweight', 'frame', 'height', 'linethickness', 'lspace',
'mathbackground', 'mathcolor', 'mathvariant', 'mathvariant', 'maxsize',
'minsize', 'other', 'rowalign', 'rowalign', 'rowalign', 'rowlines',
'rowspacing', 'rowspan', 'rspace', 'scriptlevel', 'selection',
'separator', 'stretchy', 'width', 'width', 'xlink:href', 'xlink:show',
'xlink:type', 'xmlns', 'xmlns:xlink']
svg_attributes = ['accent-height', 'accumulate', 'additive', 'alphabetic',
'arabic-form', 'ascent', 'attributeName', 'attributeType',
'baseProfile', 'bbox', 'begin', 'by', 'calcMode', 'cap-height',
'class', 'clip-path', 'color', 'color-rendering', 'content', 'cx',
'cy', 'd', 'dx', 'dy', 'descent', 'display', 'dur', 'end', 'fill',
'fill-opacity', 'fill-rule', 'font-family', 'font-size',
'font-stretch', 'font-style', 'font-variant', 'font-weight', 'from',
'fx', 'fy', 'g1', 'g2', 'glyph-name', 'gradientUnits', 'hanging',
'height', 'horiz-adv-x', 'horiz-origin-x', 'id', 'ideographic', 'k',
'keyPoints', 'keySplines', 'keyTimes', 'lang', 'marker-end',
'marker-mid', 'marker-start', 'markerHeight', 'markerUnits',
'markerWidth', 'mathematical', 'max', 'min', 'name', 'offset',
'opacity', 'orient', 'origin', 'overline-position',
'overline-thickness', 'panose-1', 'path', 'pathLength', 'points',
'preserveAspectRatio', 'r', 'refX', 'refY', 'repeatCount',
'repeatDur', 'requiredExtensions', 'requiredFeatures', 'restart',
'rotate', 'rx', 'ry', 'slope', 'stemh', 'stemv', 'stop-color',
'stop-opacity', 'strikethrough-position', 'strikethrough-thickness',
'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap',
'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity',
'stroke-width', 'systemLanguage', 'target', 'text-anchor', 'to',
'transform', 'type', 'u1', 'u2', 'underline-position',
'underline-thickness', 'unicode', 'unicode-range', 'units-per-em',
'values', 'version', 'viewBox', 'visibility', 'width', 'widths', 'x',
'x-height', 'x1', 'x2', 'xlink:actuate', 'xlink:arcrole',
'xlink:href', 'xlink:role', 'xlink:show', 'xlink:title', 'xlink:type',
'xml:base', 'xml:lang', 'xml:space', 'xmlns', 'xmlns:xlink', 'y',
'y1', 'y2', 'zoomAndPan']
attr_val_is_uri = ['href', 'src', 'cite', 'action', 'longdesc',
'xlink:href', 'xml:base']
svg_attr_val_allows_ref = ['clip-path', 'color-profile', 'cursor', 'fill',
'filter', 'marker', 'marker-start', 'marker-mid', 'marker-end',
'mask', 'stroke']
svg_allow_local_href = ['altGlyph', 'animate', 'animateColor',
'animateMotion', 'animateTransform', 'cursor', 'feImage', 'filter',
'linearGradient', 'pattern', 'radialGradient', 'textpath', 'tref',
'set', 'use']
acceptable_css_properties = ['azimuth', 'background-color',
'border-bottom-color', 'border-collapse', 'border-color',
'border-left-color', 'border-right-color', 'border-top-color', 'clear',
'color', 'cursor', 'direction', 'display', 'elevation', 'float', 'font',
'font-family', 'font-size', 'font-style', 'font-variant', 'font-weight',
'height', 'letter-spacing', 'line-height', 'overflow', 'pause',
'pause-after', 'pause-before', 'pitch', 'pitch-range', 'richness',
'speak', 'speak-header', 'speak-numeral', 'speak-punctuation',
'speech-rate', 'stress', 'text-align', 'text-decoration', 'text-indent',
'unicode-bidi', 'vertical-align', 'voice-family', 'volume',
'white-space', 'width']
acceptable_css_keywords = ['auto', 'aqua', 'black', 'block', 'blue',
'bold', 'both', 'bottom', 'brown', 'center', 'collapse', 'dashed',
'dotted', 'fuchsia', 'gray', 'green', '!important', 'italic', 'left',
'lime', 'maroon', 'medium', 'none', 'navy', 'normal', 'nowrap', 'olive',
'pointer', 'purple', 'red', 'right', 'solid', 'silver', 'teal', 'top',
'transparent', 'underline', 'white', 'yellow']
acceptable_svg_properties = [ 'fill', 'fill-opacity', 'fill-rule',
'stroke', 'stroke-width', 'stroke-linecap', 'stroke-linejoin',
'stroke-opacity']
acceptable_protocols = [ 'ed2k', 'ftp', 'http', 'https', 'irc',
'mailto', 'news', 'gopher', 'nntp', 'telnet', 'webcal',
'xmpp', 'callto', 'feed', 'urn', 'aim', 'rsync', 'tag',
'ssh', 'sftp', 'rtsp', 'afs' ]
# subclasses may define their own versions of these constants
allowed_elements = acceptable_elements + mathml_elements + svg_elements
allowed_attributes = acceptable_attributes + mathml_attributes + svg_attributes
allowed_css_properties = acceptable_css_properties
allowed_css_keywords = acceptable_css_keywords
allowed_svg_properties = acceptable_svg_properties
allowed_protocols = acceptable_protocols
# Sanitize the +html+, escaping all elements not in ALLOWED_ELEMENTS, and
# stripping out all # attributes not in ALLOWED_ATTRIBUTES. Style
# attributes are parsed, and a restricted set, # specified by
# ALLOWED_CSS_PROPERTIES and ALLOWED_CSS_KEYWORDS, are allowed through.
# attributes in ATTR_VAL_IS_URI are scanned, and only URI schemes specified
# in ALLOWED_PROTOCOLS are allowed.
#
# sanitize_html('<script> do_nasty_stuff() </script>')
# => <script> do_nasty_stuff() </script>
# sanitize_html('<a href="javascript: sucker();">Click here for $100</a>')
# => <a>Click here for $100</a>
def sanitize_token(self, token):
# accommodate filters which use token_type differently
token_type = token["type"]
if token_type in tokenTypes.keys():
token_type = tokenTypes[token_type]
if token_type in (tokenTypes["StartTag"], tokenTypes["EndTag"],
tokenTypes["EmptyTag"]):
if token["name"] in self.allowed_elements:
if token.has_key("data"):
attrs = dict([(name,val) for name,val in
token["data"][::-1]
if name in self.allowed_attributes])
for attr in self.attr_val_is_uri:
if not attrs.has_key(attr):
continue
val_unescaped = re.sub("[`\000-\040\177-\240\s]+", '',
unescape(attrs[attr])).lower()
#remove replacement characters from unescaped characters
val_unescaped = val_unescaped.replace(u"\ufffd", "")
if (re.match("^[a-z0-9][-+.a-z0-9]*:",val_unescaped) and
(val_unescaped.split(':')[0] not in
self.allowed_protocols)):
del attrs[attr]
for attr in self.svg_attr_val_allows_ref:
if attr in attrs:
attrs[attr] = re.sub(r'url\s*\(\s*[^#\s][^)]+?\)',
' ',
unescape(attrs[attr]))
if (token["name"] in self.svg_allow_local_href and
'xlink:href' in attrs and re.search('^\s*[^#\s].*',
attrs['xlink:href'])):
del attrs['xlink:href']
if attrs.has_key('style'):
attrs['style'] = self.sanitize_css(attrs['style'])
token["data"] = [[name,val] for name,val in attrs.items()]
return token
else:
if token_type == tokenTypes["EndTag"]:
token["data"] = "</%s>" % token["name"]
elif token["data"]:
attrs = ''.join([' %s="%s"' % (k,escape(v)) for k,v in token["data"]])
token["data"] = "<%s%s>" % (token["name"],attrs)
else:
token["data"] = "<%s>" % token["name"]
if token.get("selfClosing"):
token["data"]=token["data"][:-1] + "/>"
if token["type"] in tokenTypes.keys():
token["type"] = "Characters"
else:
token["type"] = tokenTypes["Characters"]
del token["name"]
return token
elif token_type == tokenTypes["Comment"]:
pass
else:
return token
def sanitize_css(self, style):
# disallow urls
style=re.compile('url\s*\(\s*[^\s)]+?\s*\)\s*').sub(' ',style)
# gauntlet
if not re.match("""^([:,;#%.\sa-zA-Z0-9!]|\w-\w|'[\s\w]+'|"[\s\w]+"|\([\d,\s]+\))*$""", style): return ''
if not re.match("^\s*([-\w]+\s*:[^:;]*(;\s*|$))*$", style): return ''
clean = []
for prop,value in re.findall("([-\w]+)\s*:\s*([^:;]*)",style):
if not value: continue
if prop.lower() in self.allowed_css_properties:
clean.append(prop + ': ' + value + ';')
elif prop.split('-')[0].lower() in ['background','border','margin',
'padding']:
for keyword in value.split():
if not keyword in self.acceptable_css_keywords and \
not re.match("^(#[0-9a-f]+|rgb\(\d+%?,\d*%?,?\d*%?\)?|\d{0,2}\.?\d{0,2}(cm|em|ex|in|mm|pc|pt|px|%|,|\))?)$",keyword):
break
else:
clean.append(prop + ': ' + value + ';')
elif prop.lower() in self.allowed_svg_properties:
clean.append(prop + ': ' + value + ';')
return ' '.join(clean)
class HTMLSanitizer(HTMLTokenizer, HTMLSanitizerMixin):
def __init__(self, stream, encoding=None, parseMeta=True, useChardet=True,
lowercaseElementName=False, lowercaseAttrName=False, parser=None):
#Change case matching defaults as we only output lowercase html anyway
#This solution doesn't seem ideal...
HTMLTokenizer.__init__(self, stream, encoding, parseMeta, useChardet,
lowercaseElementName, lowercaseAttrName, parser=parser)
def __iter__(self):
for token in HTMLTokenizer.__iter__(self):
token = self.sanitize_token(token)
if token:
yield token
|
gpl-3.0
|
[
646,
295,
199,
504,
2748,
14,
14338,
14,
14338,
1208,
492,
4772,
12,
22221,
199,
199,
504,
14803,
492,
4163,
21782,
199,
504,
5262,
492,
10042,
199,
199,
533,
4163,
51,
9385,
2282,
4256,
8,
785,
304,
272,
408,
25092,
13362,
402,
26223,
11,
18568,
1698,
11,
19366,
436,
402,
8308,
3449,
3004,
1041,
339,
14712,
63,
5527,
275,
788,
65,
297,
283,
20787,
297,
283,
645,
2641,
12828,
297,
283,
1562,
297,
283,
6789,
297,
267,
283,
6934,
297,
283,
28135,
297,
283,
8130,
297,
283,
66,
297,
283,
5076,
297,
283,
28623,
297,
283,
3289,
297,
283,
3887,
297,
267,
283,
7682,
297,
283,
13410,
297,
283,
4218,
297,
283,
25171,
297,
283,
600,
297,
283,
761,
297,
283,
761,
923,
297,
267,
283,
1531,
297,
283,
576,
3825,
297,
283,
4616,
26279,
297,
283,
617,
297,
283,
2264,
297,
283,
5087,
297,
283,
1587,
78,
297,
267,
283,
7196,
297,
283,
694,
297,
283,
3015,
297,
283,
5030,
297,
283,
3583,
297,
283,
5633,
297,
283,
1430,
13,
1365,
297,
283,
698,
409,
297,
267,
283,
592,
13410,
297,
283,
8941,
297,
283,
12781,
297,
283,
4246,
297,
283,
964,
297,
283,
1291,
297,
283,
72,
17,
297,
267,
283,
72,
18,
297,
283,
72,
19,
297,
283,
72,
20,
297,
283,
72,
21,
297,
283,
72,
22,
297,
283,
6271,
297,
283,
73,
297,
283,
4060,
297,
283,
1210,
297,
283,
3617,
297,
267,
283,
498,
2268,
297,
283,
75,
3691,
297,
283,
1302,
297,
283,
10231,
297,
283,
317,
297,
283,
77,
297,
283,
1130,
297,
283,
4470,
297,
283,
10011,
297,
267,
283,
3029,
761,
297,
283,
10927,
297,
283,
14743,
5700,
297,
283,
393,
297,
283,
1199,
297,
283,
2992,
923,
297,
283,
1422,
297,
267,
283,
80,
297,
283,
657,
297,
283,
5734,
297,
283,
81,
297,
283,
83,
297,
283,
16557,
297,
283,
2792,
297,
283,
2416,
297,
267,
283,
7241,
297,
283,
14990,
297,
283,
1365,
297,
283,
3770,
2247,
297,
283,
3751,
297,
283,
26845,
297,
283,
9370,
297,
267,
283,
954,
297,
283,
1961,
297,
283,
1224,
297,
283,
17847,
297,
283,
2076,
297,
283,
20895,
297,
283,
521,
297,
283,
84,
11407,
297,
267,
283,
273,
297,
283,
21519,
297,
283,
454,
297,
283,
6215,
297,
283,
85,
297,
283,
348,
297,
283,
1391,
297,
283,
3722,
418,
2126,
272,
3473,
757,
63,
5527,
275,
788,
391,
414,
297,
283,
3442,
297,
283,
2626,
451,
297,
283,
77,
10865,
297,
283,
2664,
297,
267,
283,
596,
1141,
6429,
297,
283,
10344,
297,
283,
573,
297,
283,
573,
422,
297,
283,
311,
3270,
297,
283,
311,
19262,
3151,
297,
267,
283,
311,
470,
1669,
83,
297,
283,
77,
1231,
297,
283,
77,
1143,
297,
283,
706,
1142,
297,
283,
706,
81,
2591,
297,
283,
77,
2487,
297,
283,
706,
456,
297,
267,
283,
706,
456,
1961,
297,
283,
706,
384,
297,
283,
77,
1224,
297,
283,
2037,
68,
297,
283,
77,
505,
297,
283,
77,
454,
297,
283,
77,
7138,
297,
267,
283,
32368,
271,
293,
422,
297,
283,
3592,
418,
2126,
272,
21218,
63,
5527,
275,
788,
65,
297,
283,
27062,
297,
283,
27062,
4117,
297,
283,
27062,
24875,
297,
267,
283,
27062,
6939,
297,
283,
7548,
2042,
297,
283,
11001,
297,
283,
8710,
297,
283,
3257,
297,
283,
16514,
261,
297,
267,
283,
4246,
13,
1409,
297,
283,
4246,
13,
1409,
13,
354,
297,
283,
4246,
13,
1409,
13,
2164,
297,
283,
71,
297,
283,
13723,
297,
283,
72,
30136,
297,
267,
283,
6676,
9942,
297,
283,
604,
297,
283,
4211,
297,
283,
2343,
297,
283,
4752,
13,
13723,
297,
267,
283,
8075,
297,
283,
515,
297,
283,
16295,
297,
283,
6023,
604,
297,
283,
12841,
279,
9942,
297,
283,
1201,
297,
267,
283,
409,
297,
283,
2379,
297,
283,
10273,
297,
283,
5656,
297,
283,
505,
297,
283,
1213,
297,
283,
84,
3751,
297,
283,
1180,
418,
5493,
14712,
63,
2987,
275,
788,
20787,
297,
283,
5694,
297,
283,
5694,
13,
6043,
297,
283,
2732,
498,
297,
267,
283,
1287,
297,
283,
5743,
297,
283,
4478,
297,
283,
29695,
297,
283,
2495,
12283,
297,
283,
3127,
297,
267,
283,
7451,
297,
283,
7358,
297,
283,
28710,
297,
283,
6856,
3282,
297,
283,
8665,
297,
267,
283,
8665,
2326,
297,
283,
8665,
761,
2181,
1096,
297,
283,
8665,
2326,
4040,
297,
283,
3018,
475,
311,
4095,
297,
267,
283,
3890,
8358,
297,
283,
9041,
29277,
297,
283,
335,
297,
283,
13911,
297,
283,
1560,
297,
283,
1560,
1997,
297,
267,
283,
335,
1997,
297,
283,
6043,
297,
283,
10718,
297,
283,
25171,
297,
283,
533,
297,
283,
3584,
297,
283,
2326,
297,
267,
283,
4574,
297,
283,
4574,
10384,
297,
283,
23046,
297,
283,
388,
724,
266,
328,
1224,
297,
283,
13658,
297,
283,
8032,
297,
267,
283,
576,
297,
283,
576,
17511,
297,
283,
576,
1606,
890,
297,
283,
11563,
1195,
297,
283,
2083,
297,
283,
885,
297,
267,
283,
5814,
297,
283,
694,
297,
283,
7011,
297,
283,
14479,
16725,
297,
283,
8161,
561,
1195,
297,
283,
287,
3667,
297,
283,
500,
297,
267,
283,
1409,
297,
283,
509,
297,
283,
964,
297,
283,
1943,
297,
283,
25372,
4060,
297,
283,
71,
18404,
297,
283,
2139,
297,
267,
283,
3333,
297,
283,
5812,
318,
10763,
297,
283,
5642,
297,
283,
6260,
297,
283,
6399,
297,
283,
6399,
4159,
297,
283,
72,
2638,
297,
267,
283,
4677,
297,
283,
344,
297,
283,
1210,
632,
297,
283,
374,
1130,
297,
283,
498,
466,
297,
283,
1302,
297,
283,
3039,
15880,
297,
267,
283,
4159,
297,
283,
513,
297,
283,
2809,
3257,
297,
283,
3813,
297,
283,
3813,
835,
297,
283,
3813,
500,
297,
267,
283,
3813,
928,
297,
283,
674,
297,
283,
674,
2164,
297,
283,
988,
297,
283,
988,
1267,
297,
283,
4603,
297,
283,
765,
297,
267,
283,
827,
297,
283,
6048,
297,
283,
354,
297,
283,
889,
6399,
297,
283,
889,
31170,
297,
283,
2131,
1330,
297,
283,
1490,
297,
267,
283,
6433,
453,
297,
283,
3401,
297,
283,
4073,
297,
283,
1403,
13,
890,
297,
283,
7650,
297,
283,
26295,
71,
297,
267,
283,
11905,
923
] |
[
295,
199,
504,
2748,
14,
14338,
14,
14338,
1208,
492,
4772,
12,
22221,
199,
199,
504,
14803,
492,
4163,
21782,
199,
504,
5262,
492,
10042,
199,
199,
533,
4163,
51,
9385,
2282,
4256,
8,
785,
304,
272,
408,
25092,
13362,
402,
26223,
11,
18568,
1698,
11,
19366,
436,
402,
8308,
3449,
3004,
1041,
339,
14712,
63,
5527,
275,
788,
65,
297,
283,
20787,
297,
283,
645,
2641,
12828,
297,
283,
1562,
297,
283,
6789,
297,
267,
283,
6934,
297,
283,
28135,
297,
283,
8130,
297,
283,
66,
297,
283,
5076,
297,
283,
28623,
297,
283,
3289,
297,
283,
3887,
297,
267,
283,
7682,
297,
283,
13410,
297,
283,
4218,
297,
283,
25171,
297,
283,
600,
297,
283,
761,
297,
283,
761,
923,
297,
267,
283,
1531,
297,
283,
576,
3825,
297,
283,
4616,
26279,
297,
283,
617,
297,
283,
2264,
297,
283,
5087,
297,
283,
1587,
78,
297,
267,
283,
7196,
297,
283,
694,
297,
283,
3015,
297,
283,
5030,
297,
283,
3583,
297,
283,
5633,
297,
283,
1430,
13,
1365,
297,
283,
698,
409,
297,
267,
283,
592,
13410,
297,
283,
8941,
297,
283,
12781,
297,
283,
4246,
297,
283,
964,
297,
283,
1291,
297,
283,
72,
17,
297,
267,
283,
72,
18,
297,
283,
72,
19,
297,
283,
72,
20,
297,
283,
72,
21,
297,
283,
72,
22,
297,
283,
6271,
297,
283,
73,
297,
283,
4060,
297,
283,
1210,
297,
283,
3617,
297,
267,
283,
498,
2268,
297,
283,
75,
3691,
297,
283,
1302,
297,
283,
10231,
297,
283,
317,
297,
283,
77,
297,
283,
1130,
297,
283,
4470,
297,
283,
10011,
297,
267,
283,
3029,
761,
297,
283,
10927,
297,
283,
14743,
5700,
297,
283,
393,
297,
283,
1199,
297,
283,
2992,
923,
297,
283,
1422,
297,
267,
283,
80,
297,
283,
657,
297,
283,
5734,
297,
283,
81,
297,
283,
83,
297,
283,
16557,
297,
283,
2792,
297,
283,
2416,
297,
267,
283,
7241,
297,
283,
14990,
297,
283,
1365,
297,
283,
3770,
2247,
297,
283,
3751,
297,
283,
26845,
297,
283,
9370,
297,
267,
283,
954,
297,
283,
1961,
297,
283,
1224,
297,
283,
17847,
297,
283,
2076,
297,
283,
20895,
297,
283,
521,
297,
283,
84,
11407,
297,
267,
283,
273,
297,
283,
21519,
297,
283,
454,
297,
283,
6215,
297,
283,
85,
297,
283,
348,
297,
283,
1391,
297,
283,
3722,
418,
2126,
272,
3473,
757,
63,
5527,
275,
788,
391,
414,
297,
283,
3442,
297,
283,
2626,
451,
297,
283,
77,
10865,
297,
283,
2664,
297,
267,
283,
596,
1141,
6429,
297,
283,
10344,
297,
283,
573,
297,
283,
573,
422,
297,
283,
311,
3270,
297,
283,
311,
19262,
3151,
297,
267,
283,
311,
470,
1669,
83,
297,
283,
77,
1231,
297,
283,
77,
1143,
297,
283,
706,
1142,
297,
283,
706,
81,
2591,
297,
283,
77,
2487,
297,
283,
706,
456,
297,
267,
283,
706,
456,
1961,
297,
283,
706,
384,
297,
283,
77,
1224,
297,
283,
2037,
68,
297,
283,
77,
505,
297,
283,
77,
454,
297,
283,
77,
7138,
297,
267,
283,
32368,
271,
293,
422,
297,
283,
3592,
418,
2126,
272,
21218,
63,
5527,
275,
788,
65,
297,
283,
27062,
297,
283,
27062,
4117,
297,
283,
27062,
24875,
297,
267,
283,
27062,
6939,
297,
283,
7548,
2042,
297,
283,
11001,
297,
283,
8710,
297,
283,
3257,
297,
283,
16514,
261,
297,
267,
283,
4246,
13,
1409,
297,
283,
4246,
13,
1409,
13,
354,
297,
283,
4246,
13,
1409,
13,
2164,
297,
283,
71,
297,
283,
13723,
297,
283,
72,
30136,
297,
267,
283,
6676,
9942,
297,
283,
604,
297,
283,
4211,
297,
283,
2343,
297,
283,
4752,
13,
13723,
297,
267,
283,
8075,
297,
283,
515,
297,
283,
16295,
297,
283,
6023,
604,
297,
283,
12841,
279,
9942,
297,
283,
1201,
297,
267,
283,
409,
297,
283,
2379,
297,
283,
10273,
297,
283,
5656,
297,
283,
505,
297,
283,
1213,
297,
283,
84,
3751,
297,
283,
1180,
418,
5493,
14712,
63,
2987,
275,
788,
20787,
297,
283,
5694,
297,
283,
5694,
13,
6043,
297,
283,
2732,
498,
297,
267,
283,
1287,
297,
283,
5743,
297,
283,
4478,
297,
283,
29695,
297,
283,
2495,
12283,
297,
283,
3127,
297,
267,
283,
7451,
297,
283,
7358,
297,
283,
28710,
297,
283,
6856,
3282,
297,
283,
8665,
297,
267,
283,
8665,
2326,
297,
283,
8665,
761,
2181,
1096,
297,
283,
8665,
2326,
4040,
297,
283,
3018,
475,
311,
4095,
297,
267,
283,
3890,
8358,
297,
283,
9041,
29277,
297,
283,
335,
297,
283,
13911,
297,
283,
1560,
297,
283,
1560,
1997,
297,
267,
283,
335,
1997,
297,
283,
6043,
297,
283,
10718,
297,
283,
25171,
297,
283,
533,
297,
283,
3584,
297,
283,
2326,
297,
267,
283,
4574,
297,
283,
4574,
10384,
297,
283,
23046,
297,
283,
388,
724,
266,
328,
1224,
297,
283,
13658,
297,
283,
8032,
297,
267,
283,
576,
297,
283,
576,
17511,
297,
283,
576,
1606,
890,
297,
283,
11563,
1195,
297,
283,
2083,
297,
283,
885,
297,
267,
283,
5814,
297,
283,
694,
297,
283,
7011,
297,
283,
14479,
16725,
297,
283,
8161,
561,
1195,
297,
283,
287,
3667,
297,
283,
500,
297,
267,
283,
1409,
297,
283,
509,
297,
283,
964,
297,
283,
1943,
297,
283,
25372,
4060,
297,
283,
71,
18404,
297,
283,
2139,
297,
267,
283,
3333,
297,
283,
5812,
318,
10763,
297,
283,
5642,
297,
283,
6260,
297,
283,
6399,
297,
283,
6399,
4159,
297,
283,
72,
2638,
297,
267,
283,
4677,
297,
283,
344,
297,
283,
1210,
632,
297,
283,
374,
1130,
297,
283,
498,
466,
297,
283,
1302,
297,
283,
3039,
15880,
297,
267,
283,
4159,
297,
283,
513,
297,
283,
2809,
3257,
297,
283,
3813,
297,
283,
3813,
835,
297,
283,
3813,
500,
297,
267,
283,
3813,
928,
297,
283,
674,
297,
283,
674,
2164,
297,
283,
988,
297,
283,
988,
1267,
297,
283,
4603,
297,
283,
765,
297,
267,
283,
827,
297,
283,
6048,
297,
283,
354,
297,
283,
889,
6399,
297,
283,
889,
31170,
297,
283,
2131,
1330,
297,
283,
1490,
297,
267,
283,
6433,
453,
297,
283,
3401,
297,
283,
4073,
297,
283,
1403,
13,
890,
297,
283,
7650,
297,
283,
26295,
71,
297,
267,
283,
11905,
923,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tailorian/Sick-Beard
|
lib/unidecode/x0d6.py
|
253
|
4765
|
data = (
'hyeo', # 0x00
'hyeog', # 0x01
'hyeogg', # 0x02
'hyeogs', # 0x03
'hyeon', # 0x04
'hyeonj', # 0x05
'hyeonh', # 0x06
'hyeod', # 0x07
'hyeol', # 0x08
'hyeolg', # 0x09
'hyeolm', # 0x0a
'hyeolb', # 0x0b
'hyeols', # 0x0c
'hyeolt', # 0x0d
'hyeolp', # 0x0e
'hyeolh', # 0x0f
'hyeom', # 0x10
'hyeob', # 0x11
'hyeobs', # 0x12
'hyeos', # 0x13
'hyeoss', # 0x14
'hyeong', # 0x15
'hyeoj', # 0x16
'hyeoc', # 0x17
'hyeok', # 0x18
'hyeot', # 0x19
'hyeop', # 0x1a
'hyeoh', # 0x1b
'hye', # 0x1c
'hyeg', # 0x1d
'hyegg', # 0x1e
'hyegs', # 0x1f
'hyen', # 0x20
'hyenj', # 0x21
'hyenh', # 0x22
'hyed', # 0x23
'hyel', # 0x24
'hyelg', # 0x25
'hyelm', # 0x26
'hyelb', # 0x27
'hyels', # 0x28
'hyelt', # 0x29
'hyelp', # 0x2a
'hyelh', # 0x2b
'hyem', # 0x2c
'hyeb', # 0x2d
'hyebs', # 0x2e
'hyes', # 0x2f
'hyess', # 0x30
'hyeng', # 0x31
'hyej', # 0x32
'hyec', # 0x33
'hyek', # 0x34
'hyet', # 0x35
'hyep', # 0x36
'hyeh', # 0x37
'ho', # 0x38
'hog', # 0x39
'hogg', # 0x3a
'hogs', # 0x3b
'hon', # 0x3c
'honj', # 0x3d
'honh', # 0x3e
'hod', # 0x3f
'hol', # 0x40
'holg', # 0x41
'holm', # 0x42
'holb', # 0x43
'hols', # 0x44
'holt', # 0x45
'holp', # 0x46
'holh', # 0x47
'hom', # 0x48
'hob', # 0x49
'hobs', # 0x4a
'hos', # 0x4b
'hoss', # 0x4c
'hong', # 0x4d
'hoj', # 0x4e
'hoc', # 0x4f
'hok', # 0x50
'hot', # 0x51
'hop', # 0x52
'hoh', # 0x53
'hwa', # 0x54
'hwag', # 0x55
'hwagg', # 0x56
'hwags', # 0x57
'hwan', # 0x58
'hwanj', # 0x59
'hwanh', # 0x5a
'hwad', # 0x5b
'hwal', # 0x5c
'hwalg', # 0x5d
'hwalm', # 0x5e
'hwalb', # 0x5f
'hwals', # 0x60
'hwalt', # 0x61
'hwalp', # 0x62
'hwalh', # 0x63
'hwam', # 0x64
'hwab', # 0x65
'hwabs', # 0x66
'hwas', # 0x67
'hwass', # 0x68
'hwang', # 0x69
'hwaj', # 0x6a
'hwac', # 0x6b
'hwak', # 0x6c
'hwat', # 0x6d
'hwap', # 0x6e
'hwah', # 0x6f
'hwae', # 0x70
'hwaeg', # 0x71
'hwaegg', # 0x72
'hwaegs', # 0x73
'hwaen', # 0x74
'hwaenj', # 0x75
'hwaenh', # 0x76
'hwaed', # 0x77
'hwael', # 0x78
'hwaelg', # 0x79
'hwaelm', # 0x7a
'hwaelb', # 0x7b
'hwaels', # 0x7c
'hwaelt', # 0x7d
'hwaelp', # 0x7e
'hwaelh', # 0x7f
'hwaem', # 0x80
'hwaeb', # 0x81
'hwaebs', # 0x82
'hwaes', # 0x83
'hwaess', # 0x84
'hwaeng', # 0x85
'hwaej', # 0x86
'hwaec', # 0x87
'hwaek', # 0x88
'hwaet', # 0x89
'hwaep', # 0x8a
'hwaeh', # 0x8b
'hoe', # 0x8c
'hoeg', # 0x8d
'hoegg', # 0x8e
'hoegs', # 0x8f
'hoen', # 0x90
'hoenj', # 0x91
'hoenh', # 0x92
'hoed', # 0x93
'hoel', # 0x94
'hoelg', # 0x95
'hoelm', # 0x96
'hoelb', # 0x97
'hoels', # 0x98
'hoelt', # 0x99
'hoelp', # 0x9a
'hoelh', # 0x9b
'hoem', # 0x9c
'hoeb', # 0x9d
'hoebs', # 0x9e
'hoes', # 0x9f
'hoess', # 0xa0
'hoeng', # 0xa1
'hoej', # 0xa2
'hoec', # 0xa3
'hoek', # 0xa4
'hoet', # 0xa5
'hoep', # 0xa6
'hoeh', # 0xa7
'hyo', # 0xa8
'hyog', # 0xa9
'hyogg', # 0xaa
'hyogs', # 0xab
'hyon', # 0xac
'hyonj', # 0xad
'hyonh', # 0xae
'hyod', # 0xaf
'hyol', # 0xb0
'hyolg', # 0xb1
'hyolm', # 0xb2
'hyolb', # 0xb3
'hyols', # 0xb4
'hyolt', # 0xb5
'hyolp', # 0xb6
'hyolh', # 0xb7
'hyom', # 0xb8
'hyob', # 0xb9
'hyobs', # 0xba
'hyos', # 0xbb
'hyoss', # 0xbc
'hyong', # 0xbd
'hyoj', # 0xbe
'hyoc', # 0xbf
'hyok', # 0xc0
'hyot', # 0xc1
'hyop', # 0xc2
'hyoh', # 0xc3
'hu', # 0xc4
'hug', # 0xc5
'hugg', # 0xc6
'hugs', # 0xc7
'hun', # 0xc8
'hunj', # 0xc9
'hunh', # 0xca
'hud', # 0xcb
'hul', # 0xcc
'hulg', # 0xcd
'hulm', # 0xce
'hulb', # 0xcf
'huls', # 0xd0
'hult', # 0xd1
'hulp', # 0xd2
'hulh', # 0xd3
'hum', # 0xd4
'hub', # 0xd5
'hubs', # 0xd6
'hus', # 0xd7
'huss', # 0xd8
'hung', # 0xd9
'huj', # 0xda
'huc', # 0xdb
'huk', # 0xdc
'hut', # 0xdd
'hup', # 0xde
'huh', # 0xdf
'hweo', # 0xe0
'hweog', # 0xe1
'hweogg', # 0xe2
'hweogs', # 0xe3
'hweon', # 0xe4
'hweonj', # 0xe5
'hweonh', # 0xe6
'hweod', # 0xe7
'hweol', # 0xe8
'hweolg', # 0xe9
'hweolm', # 0xea
'hweolb', # 0xeb
'hweols', # 0xec
'hweolt', # 0xed
'hweolp', # 0xee
'hweolh', # 0xef
'hweom', # 0xf0
'hweob', # 0xf1
'hweobs', # 0xf2
'hweos', # 0xf3
'hweoss', # 0xf4
'hweong', # 0xf5
'hweoj', # 0xf6
'hweoc', # 0xf7
'hweok', # 0xf8
'hweot', # 0xf9
'hweop', # 0xfa
'hweoh', # 0xfb
'hwe', # 0xfc
'hweg', # 0xfd
'hwegg', # 0xfe
'hwegs', # 0xff
)
|
gpl-3.0
|
[
576,
275,
334,
199,
7,
3577,
20805,
297,
259,
327,
378,
88,
383,
199,
7,
3577,
69,
974,
297,
259,
327,
378,
88,
614,
199,
7,
3577,
69,
24798,
297,
259,
327,
378,
88,
996,
199,
7,
3577,
20805,
458,
297,
259,
327,
378,
88,
1644,
199,
7,
3577,
69,
265,
297,
259,
327,
378,
88,
966,
199,
7,
3577,
69,
265,
74,
297,
259,
327,
378,
88,
1717,
199,
7,
3577,
69,
265,
72,
297,
259,
327,
378,
88,
1690,
199,
7,
3577,
69,
364,
297,
259,
327,
378,
88,
1780,
199,
7,
3577,
20470,
297,
259,
327,
378,
88,
2036,
199,
7,
3577,
20470,
71,
297,
259,
327,
378,
88,
1643,
199,
7,
3577,
20470,
77,
297,
259,
327,
378,
88,
16,
65,
199,
7,
3577,
20470,
66,
297,
259,
327,
378,
88,
16,
66,
199,
7,
3577,
69,
1446,
297,
259,
327,
378,
88,
16,
67,
199,
7,
3577,
20470,
84,
297,
259,
327,
378,
88,
16,
68,
199,
7,
3577,
20470,
80,
297,
259,
327,
378,
88,
16,
69,
199,
7,
3577,
20470,
72,
297,
259,
327,
378,
88,
16,
70,
199,
7,
3577,
69,
676,
297,
259,
327,
378,
88,
709,
199,
7,
3577,
69,
2873,
297,
259,
327,
378,
88,
845,
199,
7,
3577,
69,
11226,
297,
259,
327,
378,
88,
713,
199,
7,
3577,
24909,
297,
259,
327,
378,
88,
969,
199,
7,
3577,
20805,
385,
297,
259,
327,
378,
88,
1079,
199,
7,
3577,
69,
951,
297,
259,
327,
378,
88,
1046,
199,
7,
3577,
20805,
74,
297,
259,
327,
378,
88,
975,
199,
7,
3577,
69,
679,
297,
259,
327,
378,
88,
1196,
199,
7,
3577,
69,
745,
297,
259,
327,
378,
88,
1085,
199,
7,
3577,
69,
357,
297,
259,
327,
378,
88,
1167,
199,
7,
3577,
69,
411,
297,
259,
327,
378,
88,
17,
65,
199,
7,
3577,
69,
19194,
297,
259,
327,
378,
88,
17,
66,
199,
7,
3577,
69,
297,
259,
327,
378,
88,
17,
67,
199,
7,
3577,
5902,
297,
259,
327,
378,
88,
17,
68,
199,
7,
3577,
5799,
297,
259,
327,
378,
88,
17,
69,
199,
7,
3577,
69,
458,
297,
259,
327,
378,
88,
17,
70,
199,
7,
3577,
287,
297,
259,
327,
378,
88,
1165,
199,
7,
3577,
287,
74,
297,
259,
327,
378,
88,
2025,
199,
7,
3577,
287,
72,
297,
259,
327,
378,
88,
1081,
199,
7,
3577,
379,
297,
259,
327,
378,
88,
1789,
199,
7,
3577,
352,
297,
259,
327,
378,
88,
1194,
199,
7,
3577,
352,
71,
297,
259,
327,
378,
88,
821,
199,
7,
3577,
21226,
297,
259,
327,
378,
88,
1479,
199,
7,
3577,
17778,
297,
259,
327,
378,
88,
1465,
199,
7,
3577,
18099,
297,
259,
327,
378,
88,
1651,
199,
7,
3577,
15330,
297,
259,
327,
378,
88,
1398,
199,
7,
3577,
1357,
297,
259,
327,
378,
88,
18,
65,
199,
7,
3577,
352,
72,
297,
259,
327,
378,
88,
18,
66,
199,
7,
3577,
5633,
297,
259,
327,
378,
88,
18,
67,
199,
7,
3577,
2871,
297,
259,
327,
378,
88,
18,
68,
199,
7,
3577,
69,
1533,
297,
259,
327,
378,
88,
18,
69,
199,
7,
3577,
397,
297,
259,
327,
378,
88,
18,
70,
199,
7,
3577,
16709,
297,
259,
327,
378,
88,
1216,
199,
7,
3577,
7420,
297,
259,
327,
378,
88,
2192,
199,
7,
3577,
69,
74,
297,
259,
327,
378,
88,
708,
199,
7,
3577,
825,
297,
259,
327,
378,
88,
1153,
199,
7,
3577,
5711,
297,
259,
327,
378,
88,
1082,
199,
7,
3577,
386,
297,
259,
327,
378,
88,
1276,
199,
7,
3577,
1545,
297,
259,
327,
378,
88,
1344,
199,
7,
3577,
24528,
297,
259,
327,
378,
88,
1401,
199,
7,
526,
297,
259,
327,
378,
88,
1703,
199,
7,
526,
71,
297,
259,
327,
378,
88,
1355,
199,
7,
526,
2721,
297,
259,
327,
378,
88,
19,
65,
199,
7,
526,
458,
297,
259,
327,
378,
88,
19,
66,
199,
7,
72,
265,
297,
259,
327,
378,
88,
19,
67,
199,
7,
72,
265,
74,
297,
259,
327,
378,
88,
19,
68,
199,
7,
72,
265,
72,
297,
259,
327,
378,
88,
19,
69,
199,
7,
72,
364,
297,
259,
327,
378,
88,
19,
70,
199,
7,
24588,
297,
259,
327,
378,
88,
2167,
199,
7,
24588,
71,
297,
259,
327,
378,
88,
2953,
199,
7,
24588,
77,
297,
259,
327,
378,
88,
2260,
199,
7,
24588,
66,
297,
259,
327,
378,
88,
2824,
199,
7,
72,
1446,
297,
259,
327,
378,
88,
1602,
199,
7,
24588,
84,
297,
259,
327,
378,
88,
2322,
199,
7,
24588,
80,
297,
259,
327,
378,
88,
2466,
199,
7,
24588,
72,
297,
259,
327,
378,
88,
2417,
199,
7,
526,
77,
297,
259,
327,
378,
88,
2006,
199,
7,
526,
66,
297,
259,
327,
378,
88,
1887,
199,
7,
526,
1533,
297,
259,
327,
378,
88,
20,
65,
199,
7,
526,
83,
297,
259,
327,
378,
88,
20,
66,
199,
7,
526,
385,
297,
259,
327,
378,
88,
20,
67,
199,
7,
72,
951,
297,
259,
327,
378,
88,
20,
68,
199,
7,
526,
74,
297,
259,
327,
378,
88,
20,
69,
199,
7,
20402,
297,
259,
327,
378,
88,
20,
70,
199,
7,
526,
75,
297,
259,
327,
378,
88,
1400,
199,
7,
8885,
297,
259,
327,
378,
88,
2869,
199,
7,
13376,
297,
259,
327,
378,
88,
2528,
199,
7,
526,
72,
297,
259,
327,
378,
88,
2481,
199,
7,
72,
758,
297,
259,
327,
378,
88,
1477,
199,
7,
8090,
643,
297,
259,
327,
378,
88,
1229,
199,
7,
8090,
13452,
297,
259,
327,
378,
88,
1367,
199,
7,
72,
758,
458,
297,
259,
327,
378,
88,
1641,
199,
7,
8090,
290,
297,
259,
327,
378,
88,
2010,
199,
7,
8090,
290,
74,
297,
259,
327,
378,
88,
1427,
199,
7,
8090,
290,
72,
297,
259,
327,
378,
88,
21,
65,
199,
7,
8090,
350,
297,
259,
327,
378,
88,
21,
66,
199,
7,
8090,
279,
297,
259,
327,
378,
88,
21,
67,
199,
7,
8090,
6731,
297,
259,
327,
378,
88,
21,
68,
199,
7,
8090,
279,
77,
297,
259,
327,
378,
88,
21,
69,
199
] |
[
275,
334,
199,
7,
3577,
20805,
297,
259,
327,
378,
88,
383,
199,
7,
3577,
69,
974,
297,
259,
327,
378,
88,
614,
199,
7,
3577,
69,
24798,
297,
259,
327,
378,
88,
996,
199,
7,
3577,
20805,
458,
297,
259,
327,
378,
88,
1644,
199,
7,
3577,
69,
265,
297,
259,
327,
378,
88,
966,
199,
7,
3577,
69,
265,
74,
297,
259,
327,
378,
88,
1717,
199,
7,
3577,
69,
265,
72,
297,
259,
327,
378,
88,
1690,
199,
7,
3577,
69,
364,
297,
259,
327,
378,
88,
1780,
199,
7,
3577,
20470,
297,
259,
327,
378,
88,
2036,
199,
7,
3577,
20470,
71,
297,
259,
327,
378,
88,
1643,
199,
7,
3577,
20470,
77,
297,
259,
327,
378,
88,
16,
65,
199,
7,
3577,
20470,
66,
297,
259,
327,
378,
88,
16,
66,
199,
7,
3577,
69,
1446,
297,
259,
327,
378,
88,
16,
67,
199,
7,
3577,
20470,
84,
297,
259,
327,
378,
88,
16,
68,
199,
7,
3577,
20470,
80,
297,
259,
327,
378,
88,
16,
69,
199,
7,
3577,
20470,
72,
297,
259,
327,
378,
88,
16,
70,
199,
7,
3577,
69,
676,
297,
259,
327,
378,
88,
709,
199,
7,
3577,
69,
2873,
297,
259,
327,
378,
88,
845,
199,
7,
3577,
69,
11226,
297,
259,
327,
378,
88,
713,
199,
7,
3577,
24909,
297,
259,
327,
378,
88,
969,
199,
7,
3577,
20805,
385,
297,
259,
327,
378,
88,
1079,
199,
7,
3577,
69,
951,
297,
259,
327,
378,
88,
1046,
199,
7,
3577,
20805,
74,
297,
259,
327,
378,
88,
975,
199,
7,
3577,
69,
679,
297,
259,
327,
378,
88,
1196,
199,
7,
3577,
69,
745,
297,
259,
327,
378,
88,
1085,
199,
7,
3577,
69,
357,
297,
259,
327,
378,
88,
1167,
199,
7,
3577,
69,
411,
297,
259,
327,
378,
88,
17,
65,
199,
7,
3577,
69,
19194,
297,
259,
327,
378,
88,
17,
66,
199,
7,
3577,
69,
297,
259,
327,
378,
88,
17,
67,
199,
7,
3577,
5902,
297,
259,
327,
378,
88,
17,
68,
199,
7,
3577,
5799,
297,
259,
327,
378,
88,
17,
69,
199,
7,
3577,
69,
458,
297,
259,
327,
378,
88,
17,
70,
199,
7,
3577,
287,
297,
259,
327,
378,
88,
1165,
199,
7,
3577,
287,
74,
297,
259,
327,
378,
88,
2025,
199,
7,
3577,
287,
72,
297,
259,
327,
378,
88,
1081,
199,
7,
3577,
379,
297,
259,
327,
378,
88,
1789,
199,
7,
3577,
352,
297,
259,
327,
378,
88,
1194,
199,
7,
3577,
352,
71,
297,
259,
327,
378,
88,
821,
199,
7,
3577,
21226,
297,
259,
327,
378,
88,
1479,
199,
7,
3577,
17778,
297,
259,
327,
378,
88,
1465,
199,
7,
3577,
18099,
297,
259,
327,
378,
88,
1651,
199,
7,
3577,
15330,
297,
259,
327,
378,
88,
1398,
199,
7,
3577,
1357,
297,
259,
327,
378,
88,
18,
65,
199,
7,
3577,
352,
72,
297,
259,
327,
378,
88,
18,
66,
199,
7,
3577,
5633,
297,
259,
327,
378,
88,
18,
67,
199,
7,
3577,
2871,
297,
259,
327,
378,
88,
18,
68,
199,
7,
3577,
69,
1533,
297,
259,
327,
378,
88,
18,
69,
199,
7,
3577,
397,
297,
259,
327,
378,
88,
18,
70,
199,
7,
3577,
16709,
297,
259,
327,
378,
88,
1216,
199,
7,
3577,
7420,
297,
259,
327,
378,
88,
2192,
199,
7,
3577,
69,
74,
297,
259,
327,
378,
88,
708,
199,
7,
3577,
825,
297,
259,
327,
378,
88,
1153,
199,
7,
3577,
5711,
297,
259,
327,
378,
88,
1082,
199,
7,
3577,
386,
297,
259,
327,
378,
88,
1276,
199,
7,
3577,
1545,
297,
259,
327,
378,
88,
1344,
199,
7,
3577,
24528,
297,
259,
327,
378,
88,
1401,
199,
7,
526,
297,
259,
327,
378,
88,
1703,
199,
7,
526,
71,
297,
259,
327,
378,
88,
1355,
199,
7,
526,
2721,
297,
259,
327,
378,
88,
19,
65,
199,
7,
526,
458,
297,
259,
327,
378,
88,
19,
66,
199,
7,
72,
265,
297,
259,
327,
378,
88,
19,
67,
199,
7,
72,
265,
74,
297,
259,
327,
378,
88,
19,
68,
199,
7,
72,
265,
72,
297,
259,
327,
378,
88,
19,
69,
199,
7,
72,
364,
297,
259,
327,
378,
88,
19,
70,
199,
7,
24588,
297,
259,
327,
378,
88,
2167,
199,
7,
24588,
71,
297,
259,
327,
378,
88,
2953,
199,
7,
24588,
77,
297,
259,
327,
378,
88,
2260,
199,
7,
24588,
66,
297,
259,
327,
378,
88,
2824,
199,
7,
72,
1446,
297,
259,
327,
378,
88,
1602,
199,
7,
24588,
84,
297,
259,
327,
378,
88,
2322,
199,
7,
24588,
80,
297,
259,
327,
378,
88,
2466,
199,
7,
24588,
72,
297,
259,
327,
378,
88,
2417,
199,
7,
526,
77,
297,
259,
327,
378,
88,
2006,
199,
7,
526,
66,
297,
259,
327,
378,
88,
1887,
199,
7,
526,
1533,
297,
259,
327,
378,
88,
20,
65,
199,
7,
526,
83,
297,
259,
327,
378,
88,
20,
66,
199,
7,
526,
385,
297,
259,
327,
378,
88,
20,
67,
199,
7,
72,
951,
297,
259,
327,
378,
88,
20,
68,
199,
7,
526,
74,
297,
259,
327,
378,
88,
20,
69,
199,
7,
20402,
297,
259,
327,
378,
88,
20,
70,
199,
7,
526,
75,
297,
259,
327,
378,
88,
1400,
199,
7,
8885,
297,
259,
327,
378,
88,
2869,
199,
7,
13376,
297,
259,
327,
378,
88,
2528,
199,
7,
526,
72,
297,
259,
327,
378,
88,
2481,
199,
7,
72,
758,
297,
259,
327,
378,
88,
1477,
199,
7,
8090,
643,
297,
259,
327,
378,
88,
1229,
199,
7,
8090,
13452,
297,
259,
327,
378,
88,
1367,
199,
7,
72,
758,
458,
297,
259,
327,
378,
88,
1641,
199,
7,
8090,
290,
297,
259,
327,
378,
88,
2010,
199,
7,
8090,
290,
74,
297,
259,
327,
378,
88,
1427,
199,
7,
8090,
290,
72,
297,
259,
327,
378,
88,
21,
65,
199,
7,
8090,
350,
297,
259,
327,
378,
88,
21,
66,
199,
7,
8090,
279,
297,
259,
327,
378,
88,
21,
67,
199,
7,
8090,
6731,
297,
259,
327,
378,
88,
21,
68,
199,
7,
8090,
279,
77,
297,
259,
327,
378,
88,
21,
69,
199,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
GaZ3ll3/scikit-image
|
skimage/feature/tests/test_canny.py
|
15
|
2877
|
import unittest
import numpy as np
from scipy.ndimage import binary_dilation, binary_erosion
import skimage.feature as F
class TestCanny(unittest.TestCase):
def test_00_00_zeros(self):
'''Test that the Canny filter finds no points for a blank field'''
result = F.canny(np.zeros((20, 20)), 4, 0, 0, np.ones((20, 20), bool))
self.assertFalse(np.any(result))
def test_00_01_zeros_mask(self):
'''Test that the Canny filter finds no points in a masked image'''
result = (F.canny(np.random.uniform(size=(20, 20)), 4, 0, 0,
np.zeros((20, 20), bool)))
self.assertFalse(np.any(result))
def test_01_01_circle(self):
'''Test that the Canny filter finds the outlines of a circle'''
i, j = np.mgrid[-200:200, -200:200].astype(float) / 200
c = np.abs(np.sqrt(i * i + j * j) - .5) < .02
result = F.canny(c.astype(float), 4, 0, 0, np.ones(c.shape, bool))
#
# erode and dilate the circle to get rings that should contain the
# outlines
#
cd = binary_dilation(c, iterations=3)
ce = binary_erosion(c, iterations=3)
cde = np.logical_and(cd, np.logical_not(ce))
self.assertTrue(np.all(cde[result]))
#
# The circle has a radius of 100. There are two rings here, one
# for the inside edge and one for the outside. So that's
# 100 * 2 * 2 * 3 for those places where pi is still 3.
# The edge contains both pixels if there's a tie, so we
# bump the count a little.
point_count = np.sum(result)
self.assertTrue(point_count > 1200)
self.assertTrue(point_count < 1600)
def test_01_02_circle_with_noise(self):
'''Test that the Canny filter finds the circle outlines
in a noisy image'''
np.random.seed(0)
i, j = np.mgrid[-200:200, -200:200].astype(float) / 200
c = np.abs(np.sqrt(i * i + j * j) - .5) < .02
cf = c.astype(float) * .5 + np.random.uniform(size=c.shape) * .5
result = F.canny(cf, 4, .1, .2, np.ones(c.shape, bool))
#
# erode and dilate the circle to get rings that should contain the
# outlines
#
cd = binary_dilation(c, iterations=4)
ce = binary_erosion(c, iterations=4)
cde = np.logical_and(cd, np.logical_not(ce))
self.assertTrue(np.all(cde[result]))
point_count = np.sum(result)
self.assertTrue(point_count > 1200)
self.assertTrue(point_count < 1600)
def test_image_shape(self):
self.assertRaises(ValueError, F.canny, np.zeros((20, 20, 20)), 4, 0, 0)
def test_mask_none(self):
result1 = F.canny(np.zeros((20, 20)), 4, 0, 0, np.ones((20, 20), bool))
result2 = F.canny(np.zeros((20, 20)), 4, 0, 0)
self.assertTrue(np.all(result1 == result2))
|
bsd-3-clause
|
[
646,
2882,
199,
646,
2680,
465,
980,
199,
504,
7026,
14,
78,
23335,
492,
3366,
63,
328,
2212,
12,
3366,
63,
3478,
438,
199,
646,
2386,
1569,
14,
4445,
465,
481,
421,
199,
533,
1379,
35,
1189,
89,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
383,
63,
383,
63,
4250,
8,
277,
304,
267,
1449,
774,
626,
314,
445,
1189,
89,
2457,
17651,
949,
4501,
367,
282,
4596,
901,
2344,
267,
754,
275,
481,
14,
67,
1189,
89,
8,
1590,
14,
4250,
1332,
1165,
12,
3388,
1826,
841,
12,
378,
12,
378,
12,
980,
14,
4548,
1332,
1165,
12,
3388,
395,
2155,
430,
267,
291,
14,
3334,
8,
1590,
14,
1629,
8,
1099,
430,
339,
347,
511,
63,
383,
63,
614,
63,
4250,
63,
2629,
8,
277,
304,
267,
1449,
774,
626,
314,
445,
1189,
89,
2457,
17651,
949,
4501,
315,
282,
9742,
1834,
2344,
267,
754,
275,
334,
38,
14,
67,
1189,
89,
8,
1590,
14,
2355,
14,
8830,
8,
890,
2687,
1165,
12,
3388,
1826,
841,
12,
378,
12,
378,
12,
2079,
980,
14,
4250,
1332,
1165,
12,
3388,
395,
2155,
1724,
267,
291,
14,
3334,
8,
1590,
14,
1629,
8,
1099,
430,
339,
347,
511,
63,
614,
63,
614,
63,
11001,
8,
277,
304,
267,
1449,
774,
626,
314,
445,
1189,
89,
2457,
17651,
314,
734,
1278,
402,
282,
17990,
2344,
267,
284,
12,
1335,
275,
980,
14,
77,
3825,
1988,
1840,
26,
1840,
12,
446,
1840,
26,
1840,
1055,
6041,
8,
1609,
9,
1182,
1926,
267,
286,
275,
980,
14,
2101,
8,
1590,
14,
5079,
8,
73,
627,
284,
435,
1335,
627,
1335,
9,
446,
1275,
21,
9,
665,
1275,
996,
267,
754,
275,
481,
14,
67,
1189,
89,
8,
67,
14,
6041,
8,
1609,
395,
841,
12,
378,
12,
378,
12,
980,
14,
4548,
8,
67,
14,
1392,
12,
2155,
430,
267,
327,
267,
327,
9266,
380,
436,
487,
750,
314,
17990,
370,
664,
519,
780,
626,
1077,
1395,
314,
267,
327,
734,
1278,
267,
327,
267,
12829,
275,
3366,
63,
328,
2212,
8,
67,
12,
10615,
29,
19,
9,
267,
10142,
275,
3366,
63,
3478,
438,
8,
67,
12,
10615,
29,
19,
9,
267,
286,
271,
275,
980,
14,
7954,
63,
460,
8,
2866,
12,
980,
14,
7954,
63,
1397,
8,
301,
430,
267,
291,
14,
1815,
8,
1590,
14,
452,
8,
31414,
59,
1099,
2459,
267,
327,
267,
327,
710,
17990,
965,
282,
9362,
402,
2948,
14,
6006,
787,
2877,
519,
780,
2348,
12,
1373,
267,
327,
367,
314,
6272,
6275,
436,
1373,
367,
314,
9682,
14,
2002,
626,
1159,
267,
327,
2948,
627,
499,
627,
499,
627,
650,
367,
5204,
9825,
2382,
6682,
365,
5139,
650,
14,
267,
327,
710,
6275,
3509,
3865,
11094,
340,
2337,
1159,
282,
3367,
69,
12,
880,
781,
267,
327,
28108,
314,
2338,
282,
12050,
14,
267,
2376,
63,
835,
275,
980,
14,
1838,
8,
1099,
9,
267,
291,
14,
1815,
8,
1403,
63,
835,
690,
413,
1840,
9,
267,
291,
14,
1815,
8,
1403,
63,
835,
665,
3193,
383,
9,
339,
347,
511,
63,
614,
63,
996,
63,
11001,
63,
1045,
63,
11838,
8,
277,
304,
267,
1449,
774,
626,
314,
445,
1189,
89,
2457,
17651,
314,
17990,
734,
1278,
268,
315,
282,
949,
19765,
1834,
2344,
267,
980,
14,
2355,
14,
5176,
8,
16,
9,
267,
284,
12,
1335,
275,
980,
14,
77,
3825,
1988,
1840,
26,
1840,
12,
446,
1840,
26,
1840,
1055,
6041,
8,
1609,
9,
1182,
1926,
267,
286,
275,
980,
14,
2101,
8,
1590,
14,
5079,
8,
73,
627,
284,
435,
1335,
627,
1335,
9,
446,
1275,
21,
9,
665,
1275,
996,
267,
3980,
275,
286,
14,
6041,
8,
1609,
9,
627,
1275,
21,
435,
980,
14,
2355,
14,
8830,
8,
890,
29,
67,
14,
1392,
9,
627,
1275,
21,
267,
754,
275,
481,
14,
67,
1189,
89,
8,
2177,
12,
841,
12,
1275,
17,
12,
1275,
18,
12,
980,
14,
4548,
8,
67,
14,
1392,
12,
2155,
430,
267,
327,
267,
327,
9266,
380,
436,
487,
750,
314,
17990,
370,
664,
519,
780,
626,
1077,
1395,
314,
267,
327,
734,
1278,
267,
327,
267,
12829,
275,
3366,
63,
328,
2212,
8,
67,
12,
10615,
29,
20,
9,
267,
10142,
275,
3366,
63,
3478,
438,
8,
67,
12,
10615,
29,
20,
9,
267,
286,
271,
275,
980,
14,
7954,
63,
460,
8,
2866,
12,
980,
14,
7954,
63,
1397,
8,
301,
430,
267,
291,
14,
1815,
8,
1590,
14,
452,
8,
31414,
59,
1099,
2459,
267,
2376,
63,
835,
275,
980,
14,
1838,
8,
1099,
9,
267,
291,
14,
1815,
8,
1403,
63,
835,
690,
413,
1840,
9,
267,
291,
14,
1815,
8,
1403,
63,
835,
665,
3193,
383,
9,
339,
347,
511,
63,
1569,
63,
1392,
8,
277,
304,
267,
291,
14,
1855,
8,
3393,
12,
481,
14,
67,
1189,
89,
12,
980,
14,
4250,
1332,
1165,
12,
3388,
12,
3388,
1826,
841,
12,
378,
12,
378,
9,
339,
347,
511,
63,
2629,
63,
3592,
8,
277,
304,
267,
754,
17,
275,
481,
14,
67,
1189,
89,
8,
1590,
14,
4250,
1332,
1165,
12,
3388,
1826,
841,
12,
378,
12,
378,
12,
980,
14,
4548,
1332,
1165,
12,
3388,
395,
2155,
430,
267,
754,
18,
275,
481,
14,
67,
1189,
89,
8,
1590,
14,
4250,
1332,
1165,
12,
3388,
1826,
841,
12,
378,
12,
378,
9,
267,
291,
14,
1815,
8,
1590,
14,
452,
8,
1099,
17,
508,
754,
18,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2882,
199,
646,
2680,
465,
980,
199,
504,
7026,
14,
78,
23335,
492,
3366,
63,
328,
2212,
12,
3366,
63,
3478,
438,
199,
646,
2386,
1569,
14,
4445,
465,
481,
421,
199,
533,
1379,
35,
1189,
89,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
383,
63,
383,
63,
4250,
8,
277,
304,
267,
1449,
774,
626,
314,
445,
1189,
89,
2457,
17651,
949,
4501,
367,
282,
4596,
901,
2344,
267,
754,
275,
481,
14,
67,
1189,
89,
8,
1590,
14,
4250,
1332,
1165,
12,
3388,
1826,
841,
12,
378,
12,
378,
12,
980,
14,
4548,
1332,
1165,
12,
3388,
395,
2155,
430,
267,
291,
14,
3334,
8,
1590,
14,
1629,
8,
1099,
430,
339,
347,
511,
63,
383,
63,
614,
63,
4250,
63,
2629,
8,
277,
304,
267,
1449,
774,
626,
314,
445,
1189,
89,
2457,
17651,
949,
4501,
315,
282,
9742,
1834,
2344,
267,
754,
275,
334,
38,
14,
67,
1189,
89,
8,
1590,
14,
2355,
14,
8830,
8,
890,
2687,
1165,
12,
3388,
1826,
841,
12,
378,
12,
378,
12,
2079,
980,
14,
4250,
1332,
1165,
12,
3388,
395,
2155,
1724,
267,
291,
14,
3334,
8,
1590,
14,
1629,
8,
1099,
430,
339,
347,
511,
63,
614,
63,
614,
63,
11001,
8,
277,
304,
267,
1449,
774,
626,
314,
445,
1189,
89,
2457,
17651,
314,
734,
1278,
402,
282,
17990,
2344,
267,
284,
12,
1335,
275,
980,
14,
77,
3825,
1988,
1840,
26,
1840,
12,
446,
1840,
26,
1840,
1055,
6041,
8,
1609,
9,
1182,
1926,
267,
286,
275,
980,
14,
2101,
8,
1590,
14,
5079,
8,
73,
627,
284,
435,
1335,
627,
1335,
9,
446,
1275,
21,
9,
665,
1275,
996,
267,
754,
275,
481,
14,
67,
1189,
89,
8,
67,
14,
6041,
8,
1609,
395,
841,
12,
378,
12,
378,
12,
980,
14,
4548,
8,
67,
14,
1392,
12,
2155,
430,
267,
327,
267,
327,
9266,
380,
436,
487,
750,
314,
17990,
370,
664,
519,
780,
626,
1077,
1395,
314,
267,
327,
734,
1278,
267,
327,
267,
12829,
275,
3366,
63,
328,
2212,
8,
67,
12,
10615,
29,
19,
9,
267,
10142,
275,
3366,
63,
3478,
438,
8,
67,
12,
10615,
29,
19,
9,
267,
286,
271,
275,
980,
14,
7954,
63,
460,
8,
2866,
12,
980,
14,
7954,
63,
1397,
8,
301,
430,
267,
291,
14,
1815,
8,
1590,
14,
452,
8,
31414,
59,
1099,
2459,
267,
327,
267,
327,
710,
17990,
965,
282,
9362,
402,
2948,
14,
6006,
787,
2877,
519,
780,
2348,
12,
1373,
267,
327,
367,
314,
6272,
6275,
436,
1373,
367,
314,
9682,
14,
2002,
626,
1159,
267,
327,
2948,
627,
499,
627,
499,
627,
650,
367,
5204,
9825,
2382,
6682,
365,
5139,
650,
14,
267,
327,
710,
6275,
3509,
3865,
11094,
340,
2337,
1159,
282,
3367,
69,
12,
880,
781,
267,
327,
28108,
314,
2338,
282,
12050,
14,
267,
2376,
63,
835,
275,
980,
14,
1838,
8,
1099,
9,
267,
291,
14,
1815,
8,
1403,
63,
835,
690,
413,
1840,
9,
267,
291,
14,
1815,
8,
1403,
63,
835,
665,
3193,
383,
9,
339,
347,
511,
63,
614,
63,
996,
63,
11001,
63,
1045,
63,
11838,
8,
277,
304,
267,
1449,
774,
626,
314,
445,
1189,
89,
2457,
17651,
314,
17990,
734,
1278,
268,
315,
282,
949,
19765,
1834,
2344,
267,
980,
14,
2355,
14,
5176,
8,
16,
9,
267,
284,
12,
1335,
275,
980,
14,
77,
3825,
1988,
1840,
26,
1840,
12,
446,
1840,
26,
1840,
1055,
6041,
8,
1609,
9,
1182,
1926,
267,
286,
275,
980,
14,
2101,
8,
1590,
14,
5079,
8,
73,
627,
284,
435,
1335,
627,
1335,
9,
446,
1275,
21,
9,
665,
1275,
996,
267,
3980,
275,
286,
14,
6041,
8,
1609,
9,
627,
1275,
21,
435,
980,
14,
2355,
14,
8830,
8,
890,
29,
67,
14,
1392,
9,
627,
1275,
21,
267,
754,
275,
481,
14,
67,
1189,
89,
8,
2177,
12,
841,
12,
1275,
17,
12,
1275,
18,
12,
980,
14,
4548,
8,
67,
14,
1392,
12,
2155,
430,
267,
327,
267,
327,
9266,
380,
436,
487,
750,
314,
17990,
370,
664,
519,
780,
626,
1077,
1395,
314,
267,
327,
734,
1278,
267,
327,
267,
12829,
275,
3366,
63,
328,
2212,
8,
67,
12,
10615,
29,
20,
9,
267,
10142,
275,
3366,
63,
3478,
438,
8,
67,
12,
10615,
29,
20,
9,
267,
286,
271,
275,
980,
14,
7954,
63,
460,
8,
2866,
12,
980,
14,
7954,
63,
1397,
8,
301,
430,
267,
291,
14,
1815,
8,
1590,
14,
452,
8,
31414,
59,
1099,
2459,
267,
2376,
63,
835,
275,
980,
14,
1838,
8,
1099,
9,
267,
291,
14,
1815,
8,
1403,
63,
835,
690,
413,
1840,
9,
267,
291,
14,
1815,
8,
1403,
63,
835,
665,
3193,
383,
9,
339,
347,
511,
63,
1569,
63,
1392,
8,
277,
304,
267,
291,
14,
1855,
8,
3393,
12,
481,
14,
67,
1189,
89,
12,
980,
14,
4250,
1332,
1165,
12,
3388,
12,
3388,
1826,
841,
12,
378,
12,
378,
9,
339,
347,
511,
63,
2629,
63,
3592,
8,
277,
304,
267,
754,
17,
275,
481,
14,
67,
1189,
89,
8,
1590,
14,
4250,
1332,
1165,
12,
3388,
1826,
841,
12,
378,
12,
378,
12,
980,
14,
4548,
1332,
1165,
12,
3388,
395,
2155,
430,
267,
754,
18,
275,
481,
14,
67,
1189,
89,
8,
1590,
14,
4250,
1332,
1165,
12,
3388,
1826,
841,
12,
378,
12,
378,
9,
267,
291,
14,
1815,
8,
1590,
14,
452,
8,
1099,
17,
508,
754,
18,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Jonekee/chromium.src
|
tools/findit/svn_repository_parser.py
|
74
|
9178
|
# Copyright (c) 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import xml.dom.minidom as minidom
from xml.parsers.expat import ExpatError
import crash_utils
from repository_parser_interface import ParserInterface
# This number is 6 because each linediff page in src.chromium.org should
# contain the following tables: table with revision number, table with actual
# diff, table with dropdown menu, table with legend, a border table and a table
# containing page information.
NUM_TABLES_IN_LINEDIFF_PAGE = 6
# Each of the linediff info should contain 3 tds, one for changed line number,
# and two for line contents before/after.
NUM_TDS_IN_LINEDIFF_PAGE = 3
class SVNParser(ParserInterface):
"""Parser for SVN repository using chromium.org, for components in config.
Attributes:
url_map: A map from component to the urls, where urls are for changelog,
revision, line diff and annotation.
"""
def __init__(self, url_map):
self.component_to_urls_map = url_map
def ParseChangelog(self, component, range_start, range_end):
file_to_revision_map = {}
revision_map = {}
# Check if the current component is supported by reading the components
# parsed from config file. If it is not, fail.
url_map = self.component_to_urls_map.get(component)
if not url_map:
return (revision_map, file_to_revision_map)
# Retrieve data from the url, return empty map if fails.
revision_range_str = '%s:%s' % (range_start, range_end)
url = url_map['changelog_url'] % revision_range_str
response = crash_utils.GetDataFromURL(url)
if not response:
return (revision_map, file_to_revision_map)
# Parse xml out of the returned string. If it fails, return empty map.
try:
xml_revisions = minidom.parseString(response)
except ExpatError:
return (revision_map, file_to_revision_map)
# Iterate through the returned XML object.
revisions = xml_revisions.getElementsByTagName('logentry')
for revision in revisions:
# Create new revision object for each of the revision.
revision_object = {}
# Set author of the CL.
revision_object['author'] = revision.getElementsByTagName(
'author')[0].firstChild.nodeValue
# Get the revision number from xml.
revision_number = int(revision.getAttribute('revision'))
# Iterate through the changed paths in the CL.
paths = revision.getElementsByTagName('paths')
if paths:
for changed_path in paths[0].getElementsByTagName('path'):
# Get path and file change type from the xml.
file_path = changed_path.firstChild.nodeValue
file_change_type = changed_path.getAttribute('action')
if file_path.startswith('/trunk/'):
file_path = file_path[len('/trunk/'):]
# Add file to the map.
if file_path not in file_to_revision_map:
file_to_revision_map[file_path] = []
file_to_revision_map[file_path].append(
(revision_number, file_change_type))
# Set commit message of the CL.
revision_object['message'] = revision.getElementsByTagName('msg')[
0].firstChild.nodeValue
# Set url of this CL.
revision_url = url_map['revision_url'] % revision_number
revision_object['url'] = revision_url
# Add this CL to the revision map.
revision_map[revision_number] = revision_object
return (revision_map, file_to_revision_map)
def ParseLineDiff(self, path, component, file_change_type, revision_number):
changed_line_numbers = []
changed_line_contents = []
url_map = self.component_to_urls_map.get(component)
if not url_map:
return (None, None, None)
# If the file is added (not modified), treat it as if it is not changed.
backup_url = url_map['revision_url'] % revision_number
if file_change_type == 'A':
return (backup_url, changed_line_numbers, changed_line_contents)
# Retrieve data from the url. If no data is retrieved, return empty lists.
url = url_map['diff_url'] % (path, revision_number - 1,
revision_number, revision_number)
data = crash_utils.GetDataFromURL(url)
if not data:
return (backup_url, changed_line_numbers, changed_line_contents)
line_diff_html = minidom.parseString(data)
tables = line_diff_html.getElementsByTagName('table')
# If there are not NUM_TABLES tables in the html page, there should be an
# error in the html page.
if len(tables) != NUM_TABLES_IN_LINEDIFF_PAGE:
return (backup_url, changed_line_numbers, changed_line_contents)
# Diff content is in the second table. Each line of the diff content
# is in <tr>.
trs = tables[1].getElementsByTagName('tr')
prefix_len = len('vc_diff_')
# Filter trs so that it only contains diff chunk with contents.
filtered_trs = []
for tr in trs:
tr_class = tr.getAttribute('class')
# Check for the classes of the <tr>s.
if tr_class:
tr_class = tr_class[prefix_len:]
# Do not have to add header.
if tr_class == 'header' or tr_class == 'chunk_header':
continue
# If the class of tr is empty, this page does not have any change.
if tr_class == 'empty':
return (backup_url, changed_line_numbers, changed_line_contents)
filtered_trs.append(tr)
# Iterate through filtered trs, and grab line diff information.
for tr in filtered_trs:
tds = tr.getElementsByTagName('td')
# If there aren't 3 tds, this line does should not contain line diff.
if len(tds) != NUM_TDS_IN_LINEDIFF_PAGE:
continue
# If line number information is not in hyperlink, ignore this line.
try:
line_num = tds[0].getElementsByTagName('a')[0].firstChild.nodeValue
left_diff_type = tds[1].getAttribute('class')[prefix_len:]
right_diff_type = tds[2].getAttribute('class')[prefix_len:]
except IndexError:
continue
# Treat the line as modified only if both left and right diff has type
# changed or both have different change type, and if the change is not
# deletion.
if (left_diff_type != right_diff_type) or (
left_diff_type == 'change' and right_diff_type == 'change'):
# Check if the line content is not empty.
try:
new_line = tds[2].firstChild.nodeValue
except AttributeError:
new_line = ''
if not (left_diff_type == 'remove' and right_diff_type == 'empty'):
changed_line_numbers.append(int(line_num))
changed_line_contents.append(new_line.strip())
return (url, changed_line_numbers, changed_line_contents)
def ParseBlameInfo(self, component, file_path, line, revision):
url_map = self.component_to_urls_map.get(component)
if not url_map:
return None
# Retrieve blame data from url, return None if fails.
url = url_map['blame_url'] % (file_path, revision, revision)
data = crash_utils.GetDataFromURL(url)
if not data:
return None
blame_html = minidom.parseString(data)
title = blame_html.getElementsByTagName('title')
# If the returned html page is an exception page, return None.
if title[0].firstChild.nodeValue == 'ViewVC Exception':
return None
# Each of the blame result is in <tr>.
blame_results = blame_html.getElementsByTagName('tr')
try:
blame_result = blame_results[line]
except IndexError:
return None
# There must be 4 <td> for each <tr>. If not, this page is wrong.
tds = blame_result.getElementsByTagName('td')
if len(tds) != 4:
return None
# The third <td> has the line content, separated by <span>s. Combine
# those to get a string of changed line. If it has nothing, the line
# is empty.
line_content = ''
if tds[3].hasChildNodes():
contents = tds[3].childNodes
for content in contents:
# Nodetype 3 means it is text node.
if content.nodeType == minidom.Node.TEXT_NODE:
line_content += content.nodeValue
else:
line_content += content.firstChild.nodeValue
line_content = line_content.strip()
# If the current line has the same author/revision as the previous lines,
# the result is not shown. Propagate up until we find the line with info.
while not tds[1].firstChild:
line -= 1
blame_result = blame_results[line]
tds = blame_result.getElementsByTagName('td')
author = tds[1].firstChild.nodeValue
# Revision can either be in hyperlink or plain text.
try:
revision = tds[2].getElementsByTagName('a')[0].firstChild.nodeValue
except IndexError:
revision = tds[2].firstChild.nodeValue
(revision_info, _) = self.ParseChangelog(component, revision, revision)
message = revision_info[int(revision)]['message']
# Return the parsed information.
revision_url = url_map['revision_url'] % int(revision)
return (line_content, revision, author, revision_url, message)
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
2748,
14,
4556,
14,
21827,
465,
19165,
199,
504,
2748,
14,
11531,
14,
27098,
492,
7910,
292,
547,
199,
199,
646,
12420,
63,
1208,
199,
504,
7611,
63,
2087,
63,
3266,
492,
10191,
4267,
421,
199,
3,
961,
1329,
365,
1227,
2952,
1924,
1004,
3028,
2034,
315,
2928,
14,
13211,
14,
1308,
1077,
199,
3,
1395,
314,
2569,
6716,
26,
1817,
543,
6974,
1329,
12,
1817,
543,
3503,
199,
3,
3915,
12,
1817,
543,
5978,
2110,
6269,
12,
1817,
543,
15906,
12,
282,
9162,
1817,
436,
282,
1817,
199,
3,
3035,
2034,
2556,
14,
199,
7125,
63,
10129,
11344,
63,
568,
63,
6143,
7458,
1665,
63,
12898,
275,
1227,
199,
3,
7048,
402,
314,
1004,
3028,
2256,
1077,
1395,
650,
307,
795,
12,
1373,
367,
2896,
1004,
1329,
12,
199,
3,
436,
2877,
367,
1004,
4072,
2544,
15,
4399,
14,
199,
7125,
63,
52,
3177,
63,
568,
63,
6143,
7458,
1665,
63,
12898,
275,
650,
421,
199,
533,
24639,
2842,
8,
2842,
4267,
304,
523,
408,
2842,
367,
24639,
7611,
1808,
682,
7419,
14,
1308,
12,
367,
7323,
315,
1101,
14,
819,
9382,
26,
272,
1166,
63,
1130,
26,
437,
2341,
687,
3931,
370,
314,
8187,
12,
2382,
8187,
787,
367,
1570,
793,
12,
1467,
6974,
12,
1004,
3915,
436,
11262,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
1166,
63,
1130,
304,
272,
291,
14,
3173,
63,
475,
63,
3603,
63,
1130,
275,
1166,
63,
1130,
819,
347,
6077,
4001,
793,
8,
277,
12,
3931,
12,
1425,
63,
928,
12,
1425,
63,
500,
304,
272,
570,
63,
475,
63,
5792,
63,
1130,
275,
1052,
272,
6974,
63,
1130,
275,
1052,
339,
327,
2670,
340,
314,
1453,
3931,
365,
3748,
701,
7664,
314,
7323,
272,
327,
4565,
687,
1101,
570,
14,
982,
652,
365,
440,
12,
2449,
14,
339,
1166,
63,
1130,
275,
291,
14,
3173,
63,
475,
63,
3603,
63,
1130,
14,
362,
8,
3173,
9,
272,
340,
440,
1166,
63,
1130,
26,
489,
372,
334,
5792,
63,
1130,
12,
570,
63,
475,
63,
5792,
63,
1130,
9,
339,
327,
13939,
666,
687,
314,
1166,
12,
372,
2701,
2341,
340,
6918,
14,
272,
6974,
63,
1842,
63,
495,
275,
1543,
83,
2689,
83,
7,
450,
334,
1842,
63,
928,
12,
1425,
63,
500,
9,
272,
1166,
275,
1166,
63,
1130,
459,
23436,
63,
633,
418,
450,
6974,
63,
1842,
63,
495,
272,
1177,
275,
12420,
63,
1208,
14,
25702,
2532,
2632,
8,
633,
9,
272,
340,
440,
1177,
26,
489,
372,
334,
5792,
63,
1130,
12,
570,
63,
475,
63,
5792,
63,
1130,
9,
339,
327,
6077,
2748,
734,
402,
314,
2138,
1059,
14,
982,
652,
6918,
12,
372,
2701,
2341,
14,
272,
862,
26,
489,
2748,
63,
23449,
275,
19165,
14,
14934,
8,
1310,
9,
272,
871,
7910,
292,
547,
26,
489,
372,
334,
5792,
63,
1130,
12,
570,
63,
475,
63,
5792,
63,
1130,
9,
339,
327,
23989,
4012,
314,
2138,
4692,
909,
14,
272,
22164,
275,
2748,
63,
23449,
14,
15045,
360,
793,
2373,
358,
272,
367,
6974,
315,
22164,
26,
489,
327,
2790,
892,
6974,
909,
367,
1924,
402,
314,
6974,
14,
489,
6974,
63,
785,
275,
1052,
2541,
327,
2494,
4132,
402,
314,
13354,
14,
489,
6974,
63,
785,
459,
2502,
418,
275,
6974,
14,
15045,
8,
881,
283,
2502,
5832,
16,
1055,
22262,
14,
17240,
2541,
327,
2372,
314,
6974,
1329,
687,
2748,
14,
489,
6974,
63,
1955,
275,
1109,
8,
5792,
14,
12956,
360,
5792,
1333,
2541,
327,
23989,
4012,
314,
2896,
3792,
315,
314,
13354,
14,
489,
3792,
275,
6974,
14,
15045,
360,
3771,
358,
489,
340,
3792,
26,
267,
367,
2896,
63,
515,
315,
3792,
59,
16,
1055,
15045,
360,
515,
735,
881,
327,
2372,
931,
436,
570,
1570,
730,
687,
314,
2748,
14,
881,
570,
63,
515,
275,
2896,
63,
515,
14,
22262,
14,
17240,
881,
570,
63,
1461,
63,
466,
275,
2896,
63,
515,
14,
12956,
360,
1287,
358,
8592,
340,
570,
63,
515,
14,
2460,
2336,
13409,
26985,
288,
570,
63,
515,
275,
570,
63,
515,
59,
552,
2336,
13409,
26985,
61,
8592,
327,
2654,
570,
370,
314,
2341,
14,
881,
340,
570,
63,
515,
440,
315,
570,
63,
475,
63,
5792,
63,
1130,
26,
288,
570,
63,
475,
63,
5792,
63,
1130,
59,
493,
63,
515,
61,
275,
942,
881,
570,
63,
475,
63,
5792,
63,
1130,
59,
493,
63,
515,
1055,
740,
8,
1598,
334,
5792,
63,
1955,
12,
570,
63,
1461,
63,
466,
430,
2541,
327,
2494,
5532,
1245,
402,
314,
13354,
14,
489,
6974,
63,
785,
459,
1188,
418,
275,
6974,
14,
15045,
360,
1328,
5832,
881,
378,
1055,
22262,
14,
17240,
2541,
327,
2494,
1166,
402,
642,
13354,
14,
489,
6974,
63,
633,
275,
1166,
63,
1130,
459,
5792,
63,
633,
418,
450,
6974,
63,
1955,
489,
6974,
63,
785,
459,
633,
418,
275,
6974,
63,
633,
2541,
327,
2654,
642,
13354,
370,
314,
6974,
2341,
14,
489,
6974,
63,
1130,
59,
5792,
63,
1955,
61,
275,
6974,
63,
785,
339,
372,
334,
5792,
63,
1130,
12,
570,
63,
475,
63,
5792,
63,
1130,
9,
819,
347,
6077,
3049,
10746,
8,
277,
12,
931,
12,
3931,
12,
570,
63,
1461,
63,
466,
12,
6974,
63,
1955,
304,
272,
2896,
63,
604,
63,
10548,
275,
942,
272,
2896,
63,
604,
63,
4407,
275,
942,
339,
1166,
63,
1130,
275,
291,
14,
3173,
63,
475,
63,
3603,
63,
1130,
14,
362,
8,
3173,
9,
272,
340,
440,
1166,
63,
1130,
26,
489,
372,
334,
403,
12,
488,
12,
488,
9,
339,
327,
982,
314,
570,
365,
3483,
334,
1397,
6042,
395,
14312,
652,
465,
340,
652,
365,
440,
2896,
14,
272,
6902,
63,
633,
275,
1166,
63,
1130,
459,
5792,
63,
633,
418,
450,
6974,
63,
1955,
272,
340,
570,
63,
1461,
63,
466,
508,
283,
33,
356,
489,
372,
334,
5751,
63,
633,
12,
2896,
63,
604,
63,
10548,
12,
2896,
63
] |
[
1898,
334,
67,
9,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
2748,
14,
4556,
14,
21827,
465,
19165,
199,
504,
2748,
14,
11531,
14,
27098,
492,
7910,
292,
547,
199,
199,
646,
12420,
63,
1208,
199,
504,
7611,
63,
2087,
63,
3266,
492,
10191,
4267,
421,
199,
3,
961,
1329,
365,
1227,
2952,
1924,
1004,
3028,
2034,
315,
2928,
14,
13211,
14,
1308,
1077,
199,
3,
1395,
314,
2569,
6716,
26,
1817,
543,
6974,
1329,
12,
1817,
543,
3503,
199,
3,
3915,
12,
1817,
543,
5978,
2110,
6269,
12,
1817,
543,
15906,
12,
282,
9162,
1817,
436,
282,
1817,
199,
3,
3035,
2034,
2556,
14,
199,
7125,
63,
10129,
11344,
63,
568,
63,
6143,
7458,
1665,
63,
12898,
275,
1227,
199,
3,
7048,
402,
314,
1004,
3028,
2256,
1077,
1395,
650,
307,
795,
12,
1373,
367,
2896,
1004,
1329,
12,
199,
3,
436,
2877,
367,
1004,
4072,
2544,
15,
4399,
14,
199,
7125,
63,
52,
3177,
63,
568,
63,
6143,
7458,
1665,
63,
12898,
275,
650,
421,
199,
533,
24639,
2842,
8,
2842,
4267,
304,
523,
408,
2842,
367,
24639,
7611,
1808,
682,
7419,
14,
1308,
12,
367,
7323,
315,
1101,
14,
819,
9382,
26,
272,
1166,
63,
1130,
26,
437,
2341,
687,
3931,
370,
314,
8187,
12,
2382,
8187,
787,
367,
1570,
793,
12,
1467,
6974,
12,
1004,
3915,
436,
11262,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
1166,
63,
1130,
304,
272,
291,
14,
3173,
63,
475,
63,
3603,
63,
1130,
275,
1166,
63,
1130,
819,
347,
6077,
4001,
793,
8,
277,
12,
3931,
12,
1425,
63,
928,
12,
1425,
63,
500,
304,
272,
570,
63,
475,
63,
5792,
63,
1130,
275,
1052,
272,
6974,
63,
1130,
275,
1052,
339,
327,
2670,
340,
314,
1453,
3931,
365,
3748,
701,
7664,
314,
7323,
272,
327,
4565,
687,
1101,
570,
14,
982,
652,
365,
440,
12,
2449,
14,
339,
1166,
63,
1130,
275,
291,
14,
3173,
63,
475,
63,
3603,
63,
1130,
14,
362,
8,
3173,
9,
272,
340,
440,
1166,
63,
1130,
26,
489,
372,
334,
5792,
63,
1130,
12,
570,
63,
475,
63,
5792,
63,
1130,
9,
339,
327,
13939,
666,
687,
314,
1166,
12,
372,
2701,
2341,
340,
6918,
14,
272,
6974,
63,
1842,
63,
495,
275,
1543,
83,
2689,
83,
7,
450,
334,
1842,
63,
928,
12,
1425,
63,
500,
9,
272,
1166,
275,
1166,
63,
1130,
459,
23436,
63,
633,
418,
450,
6974,
63,
1842,
63,
495,
272,
1177,
275,
12420,
63,
1208,
14,
25702,
2532,
2632,
8,
633,
9,
272,
340,
440,
1177,
26,
489,
372,
334,
5792,
63,
1130,
12,
570,
63,
475,
63,
5792,
63,
1130,
9,
339,
327,
6077,
2748,
734,
402,
314,
2138,
1059,
14,
982,
652,
6918,
12,
372,
2701,
2341,
14,
272,
862,
26,
489,
2748,
63,
23449,
275,
19165,
14,
14934,
8,
1310,
9,
272,
871,
7910,
292,
547,
26,
489,
372,
334,
5792,
63,
1130,
12,
570,
63,
475,
63,
5792,
63,
1130,
9,
339,
327,
23989,
4012,
314,
2138,
4692,
909,
14,
272,
22164,
275,
2748,
63,
23449,
14,
15045,
360,
793,
2373,
358,
272,
367,
6974,
315,
22164,
26,
489,
327,
2790,
892,
6974,
909,
367,
1924,
402,
314,
6974,
14,
489,
6974,
63,
785,
275,
1052,
2541,
327,
2494,
4132,
402,
314,
13354,
14,
489,
6974,
63,
785,
459,
2502,
418,
275,
6974,
14,
15045,
8,
881,
283,
2502,
5832,
16,
1055,
22262,
14,
17240,
2541,
327,
2372,
314,
6974,
1329,
687,
2748,
14,
489,
6974,
63,
1955,
275,
1109,
8,
5792,
14,
12956,
360,
5792,
1333,
2541,
327,
23989,
4012,
314,
2896,
3792,
315,
314,
13354,
14,
489,
3792,
275,
6974,
14,
15045,
360,
3771,
358,
489,
340,
3792,
26,
267,
367,
2896,
63,
515,
315,
3792,
59,
16,
1055,
15045,
360,
515,
735,
881,
327,
2372,
931,
436,
570,
1570,
730,
687,
314,
2748,
14,
881,
570,
63,
515,
275,
2896,
63,
515,
14,
22262,
14,
17240,
881,
570,
63,
1461,
63,
466,
275,
2896,
63,
515,
14,
12956,
360,
1287,
358,
8592,
340,
570,
63,
515,
14,
2460,
2336,
13409,
26985,
288,
570,
63,
515,
275,
570,
63,
515,
59,
552,
2336,
13409,
26985,
61,
8592,
327,
2654,
570,
370,
314,
2341,
14,
881,
340,
570,
63,
515,
440,
315,
570,
63,
475,
63,
5792,
63,
1130,
26,
288,
570,
63,
475,
63,
5792,
63,
1130,
59,
493,
63,
515,
61,
275,
942,
881,
570,
63,
475,
63,
5792,
63,
1130,
59,
493,
63,
515,
1055,
740,
8,
1598,
334,
5792,
63,
1955,
12,
570,
63,
1461,
63,
466,
430,
2541,
327,
2494,
5532,
1245,
402,
314,
13354,
14,
489,
6974,
63,
785,
459,
1188,
418,
275,
6974,
14,
15045,
360,
1328,
5832,
881,
378,
1055,
22262,
14,
17240,
2541,
327,
2494,
1166,
402,
642,
13354,
14,
489,
6974,
63,
633,
275,
1166,
63,
1130,
459,
5792,
63,
633,
418,
450,
6974,
63,
1955,
489,
6974,
63,
785,
459,
633,
418,
275,
6974,
63,
633,
2541,
327,
2654,
642,
13354,
370,
314,
6974,
2341,
14,
489,
6974,
63,
1130,
59,
5792,
63,
1955,
61,
275,
6974,
63,
785,
339,
372,
334,
5792,
63,
1130,
12,
570,
63,
475,
63,
5792,
63,
1130,
9,
819,
347,
6077,
3049,
10746,
8,
277,
12,
931,
12,
3931,
12,
570,
63,
1461,
63,
466,
12,
6974,
63,
1955,
304,
272,
2896,
63,
604,
63,
10548,
275,
942,
272,
2896,
63,
604,
63,
4407,
275,
942,
339,
1166,
63,
1130,
275,
291,
14,
3173,
63,
475,
63,
3603,
63,
1130,
14,
362,
8,
3173,
9,
272,
340,
440,
1166,
63,
1130,
26,
489,
372,
334,
403,
12,
488,
12,
488,
9,
339,
327,
982,
314,
570,
365,
3483,
334,
1397,
6042,
395,
14312,
652,
465,
340,
652,
365,
440,
2896,
14,
272,
6902,
63,
633,
275,
1166,
63,
1130,
459,
5792,
63,
633,
418,
450,
6974,
63,
1955,
272,
340,
570,
63,
1461,
63,
466,
508,
283,
33,
356,
489,
372,
334,
5751,
63,
633,
12,
2896,
63,
604,
63,
10548,
12,
2896,
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,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
megaumi/django
|
tests/model_regress/tests.py
|
326
|
8962
|
from __future__ import unicode_literals
import datetime
from operator import attrgetter
from django.core.exceptions import ValidationError
from django.db import router
from django.db.models.sql import InsertQuery
from django.test import TestCase, skipUnlessDBFeature
from django.utils import six
from django.utils.timezone import get_fixed_timezone
from .models import (
Article, BrokenUnicodeMethod, Department, Event, Model1, Model2, Model3,
NonAutoPK, Party, Worker,
)
class ModelTests(TestCase):
# The bug is that the following queries would raise:
# "TypeError: Related Field has invalid lookup: gte"
def test_related_gte_lookup(self):
"""
Regression test for #10153: foreign key __gte lookups.
"""
Worker.objects.filter(department__gte=0)
def test_related_lte_lookup(self):
"""
Regression test for #10153: foreign key __lte lookups.
"""
Worker.objects.filter(department__lte=0)
def test_sql_insert_compiler_return_id_attribute(self):
"""
Regression test for #14019: SQLInsertCompiler.as_sql() failure
"""
db = router.db_for_write(Party)
query = InsertQuery(Party)
query.insert_values([Party._meta.fields[0]], [], raw=False)
# this line will raise an AttributeError without the accompanying fix
query.get_compiler(using=db).as_sql()
def test_empty_choice(self):
# NOTE: Part of the regression test here is merely parsing the model
# declaration. The verbose_name, in particular, did not always work.
a = Article.objects.create(
headline="Look at me!", pub_date=datetime.datetime.now()
)
# An empty choice field should return None for the display name.
self.assertIs(a.get_status_display(), None)
# Empty strings should be returned as Unicode
a = Article.objects.get(pk=a.pk)
self.assertEqual(a.misc_data, '')
self.assertIs(type(a.misc_data), six.text_type)
def test_long_textfield(self):
# TextFields can hold more than 4000 characters (this was broken in
# Oracle).
a = Article.objects.create(
headline="Really, really big",
pub_date=datetime.datetime.now(),
article_text="ABCDE" * 1000
)
a = Article.objects.get(pk=a.pk)
self.assertEqual(len(a.article_text), 5000)
def test_long_unicode_textfield(self):
# TextFields can hold more than 4000 bytes also when they are
# less than 4000 characters
a = Article.objects.create(
headline="Really, really big",
pub_date=datetime.datetime.now(),
article_text='\u05d0\u05d1\u05d2' * 1000
)
a = Article.objects.get(pk=a.pk)
self.assertEqual(len(a.article_text), 3000)
def test_date_lookup(self):
# Regression test for #659
Party.objects.create(when=datetime.datetime(1999, 12, 31))
Party.objects.create(when=datetime.datetime(1998, 12, 31))
Party.objects.create(when=datetime.datetime(1999, 1, 1))
Party.objects.create(when=datetime.datetime(1, 3, 3))
self.assertQuerysetEqual(
Party.objects.filter(when__month=2), []
)
self.assertQuerysetEqual(
Party.objects.filter(when__month=1), [
datetime.date(1999, 1, 1)
],
attrgetter("when")
)
self.assertQuerysetEqual(
Party.objects.filter(when__month=12), [
datetime.date(1999, 12, 31),
datetime.date(1998, 12, 31),
],
attrgetter("when"),
ordered=False
)
self.assertQuerysetEqual(
Party.objects.filter(when__year=1998), [
datetime.date(1998, 12, 31),
],
attrgetter("when")
)
# Regression test for #8510
self.assertQuerysetEqual(
Party.objects.filter(when__day="31"), [
datetime.date(1999, 12, 31),
datetime.date(1998, 12, 31),
],
attrgetter("when"),
ordered=False
)
self.assertQuerysetEqual(
Party.objects.filter(when__month="12"), [
datetime.date(1999, 12, 31),
datetime.date(1998, 12, 31),
],
attrgetter("when"),
ordered=False
)
self.assertQuerysetEqual(
Party.objects.filter(when__year="1998"), [
datetime.date(1998, 12, 31),
],
attrgetter("when")
)
# Regression test for #18969
self.assertQuerysetEqual(
Party.objects.filter(when__year=1), [
datetime.date(1, 3, 3),
],
attrgetter("when")
)
self.assertQuerysetEqual(
Party.objects.filter(when__year='1'), [
datetime.date(1, 3, 3),
],
attrgetter("when")
)
def test_date_filter_null(self):
# Date filtering was failing with NULL date values in SQLite
# (regression test for #3501, among other things).
Party.objects.create(when=datetime.datetime(1999, 1, 1))
Party.objects.create()
p = Party.objects.filter(when__month=1)[0]
self.assertEqual(p.when, datetime.date(1999, 1, 1))
self.assertQuerysetEqual(
Party.objects.filter(pk=p.pk).dates("when", "month"), [
1
],
attrgetter("month")
)
def test_get_next_prev_by_field(self):
# Check that get_next_by_FIELD and get_previous_by_FIELD don't crash
# when we have usecs values stored on the database
#
# It crashed after the Field.get_db_prep_* refactor, because on most
# backends DateTimeFields supports usecs, but DateTimeField.to_python
# didn't recognize them. (Note that
# Model._get_next_or_previous_by_FIELD coerces values to strings)
Event.objects.create(when=datetime.datetime(2000, 1, 1, 16, 0, 0))
Event.objects.create(when=datetime.datetime(2000, 1, 1, 6, 1, 1))
Event.objects.create(when=datetime.datetime(2000, 1, 1, 13, 1, 1))
e = Event.objects.create(when=datetime.datetime(2000, 1, 1, 12, 0, 20, 24))
self.assertEqual(
e.get_next_by_when().when, datetime.datetime(2000, 1, 1, 13, 1, 1)
)
self.assertEqual(
e.get_previous_by_when().when, datetime.datetime(2000, 1, 1, 6, 1, 1)
)
def test_primary_key_foreign_key_types(self):
# Check Department and Worker (non-default PK type)
d = Department.objects.create(id=10, name="IT")
w = Worker.objects.create(department=d, name="Full-time")
self.assertEqual(six.text_type(w), "Full-time")
def test_broken_unicode(self):
# Models with broken unicode methods should still have a printable repr
b = BrokenUnicodeMethod.objects.create(name="Jerry")
self.assertEqual(repr(b), "<BrokenUnicodeMethod: [Bad Unicode data]>")
@skipUnlessDBFeature("supports_timezones")
def test_timezones(self):
# Saving an updating with timezone-aware datetime Python objects.
# Regression test for #10443.
# The idea is that all these creations and saving should work without
# crashing. It's not rocket science.
dt1 = datetime.datetime(2008, 8, 31, 16, 20, tzinfo=get_fixed_timezone(600))
dt2 = datetime.datetime(2008, 8, 31, 17, 20, tzinfo=get_fixed_timezone(600))
obj = Article.objects.create(
headline="A headline", pub_date=dt1, article_text="foo"
)
obj.pub_date = dt2
obj.save()
self.assertEqual(
Article.objects.filter(headline="A headline").update(pub_date=dt1),
1
)
def test_chained_fks(self):
"""
Regression for #18432: Chained foreign keys with to_field produce incorrect query
"""
m1 = Model1.objects.create(pkey=1000)
m2 = Model2.objects.create(model1=m1)
m3 = Model3.objects.create(model2=m2)
# this is the actual test for #18432
m3 = Model3.objects.get(model2=1000)
m3.model2
class ModelValidationTest(TestCase):
def test_pk_validation(self):
NonAutoPK.objects.create(name="one")
again = NonAutoPK(name="one")
self.assertRaises(ValidationError, again.validate_unique)
class EvaluateMethodTest(TestCase):
"""
Regression test for #13640: cannot filter by objects with 'evaluate' attr
"""
def test_model_with_evaluate_method(self):
"""
Ensures that you can filter by objects that have an 'evaluate' attr
"""
dept = Department.objects.create(pk=1, name='abc')
dept.evaluate = 'abc'
Worker.objects.filter(department=dept)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2197,
199,
504,
4182,
492,
21829,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
8505,
199,
504,
1639,
14,
697,
492,
6197,
199,
504,
1639,
14,
697,
14,
992,
14,
3009,
492,
15496,
3227,
199,
504,
1639,
14,
396,
492,
7640,
12,
3372,
5524,
18093,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
7145,
492,
664,
63,
5964,
63,
7145,
199,
199,
504,
1275,
992,
492,
334,
272,
8281,
12,
23804,
7087,
3767,
12,
1487,
12493,
12,
6763,
12,
5822,
17,
12,
5822,
18,
12,
5822,
19,
12,
272,
10172,
3358,
8884,
12,
2235,
369,
12,
23886,
12,
199,
9,
421,
199,
533,
5822,
2925,
8,
1746,
304,
272,
327,
710,
6519,
365,
626,
314,
2569,
9212,
3955,
746,
26,
272,
327,
298,
4333,
26,
20116,
5024,
965,
3866,
4237,
26,
486,
266,
2,
272,
347,
511,
63,
2407,
63,
19586,
63,
3892,
8,
277,
304,
267,
408,
267,
13262,
511,
367,
327,
4893,
2481,
26,
11608,
790,
636,
19586,
16807,
14,
267,
408,
267,
23886,
14,
1462,
14,
1541,
8,
19623,
363,
19586,
29,
16,
9,
339,
347,
511,
63,
2407,
63,
20740,
63,
3892,
8,
277,
304,
267,
408,
267,
13262,
511,
367,
327,
4893,
2481,
26,
11608,
790,
636,
20740,
16807,
14,
267,
408,
267,
23886,
14,
1462,
14,
1541,
8,
19623,
363,
20740,
29,
16,
9,
339,
347,
511,
63,
3009,
63,
3176,
63,
5772,
63,
1107,
63,
344,
63,
3215,
8,
277,
304,
267,
408,
267,
13262,
511,
367,
327,
1079,
12512,
26,
5385,
9971,
9131,
14,
305,
63,
3009,
342,
5988,
267,
408,
267,
1592,
275,
6197,
14,
697,
63,
509,
63,
952,
8,
25233,
9,
267,
1827,
275,
15496,
3227,
8,
25233,
9,
267,
1827,
14,
3176,
63,
1459,
779,
25233,
423,
2024,
14,
955,
59,
16,
2365,
990,
3066,
29,
797,
9,
267,
327,
642,
1004,
911,
746,
376,
4281,
1928,
314,
23073,
5325,
267,
1827,
14,
362,
63,
5772,
8,
4941,
29,
697,
680,
305,
63,
3009,
342,
339,
347,
511,
63,
1667,
63,
5095,
8,
277,
304,
267,
327,
6944,
26,
14320,
402,
314,
10864,
511,
2348,
365,
562,
264,
590,
6057,
314,
1402,
267,
327,
12560,
14,
710,
3376,
63,
354,
12,
315,
6770,
12,
8103,
440,
3544,
1736,
14,
267,
282,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
628,
20926,
737,
562,
17716,
7974,
63,
602,
29,
2083,
14,
2083,
14,
2131,
342,
267,
776,
267,
327,
1626,
2701,
7141,
901,
1077,
372,
488,
367,
314,
2929,
536,
14,
267,
291,
14,
3436,
8,
65,
14,
362,
63,
1205,
63,
2918,
1062,
488,
9,
398,
327,
9630,
3326,
1077,
506,
2138,
465,
6140,
267,
282,
275,
8281,
14,
1462,
14,
362,
8,
2051,
29,
65,
14,
2051,
9,
267,
291,
14,
629,
8,
65,
14,
9923,
63,
576,
12,
4074,
267,
291,
14,
3436,
8,
466,
8,
65,
14,
9923,
63,
576,
395,
3816,
14,
505,
63,
466,
9,
339,
347,
511,
63,
2809,
63,
505,
698,
8,
277,
304,
267,
327,
4516,
7304,
883,
10266,
1655,
2419,
31092,
4110,
334,
3749,
1990,
10529,
315,
267,
327,
15309,
680,
267,
282,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
628,
497,
1183,
12,
7710,
7282,
401,
288,
7974,
63,
602,
29,
2083,
14,
2083,
14,
2131,
1062,
288,
9772,
63,
505,
628,
8390,
1093,
2,
627,
5198,
267,
776,
267,
282,
275,
8281,
14,
1462,
14,
362,
8,
2051,
29,
65,
14,
2051,
9,
267,
291,
14,
629,
8,
552,
8,
65,
14,
6934,
63,
505,
395,
22369,
9,
339,
347,
511,
63,
2809,
63,
2975,
63,
505,
698,
8,
277,
304,
267,
327,
4516,
7304,
883,
10266,
1655,
2419,
31092,
2783,
2597,
1380,
2985,
787,
267,
327,
6656,
2419,
31092,
4110,
267,
282,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
628,
497,
1183,
12,
7710,
7282,
401,
288,
7974,
63,
602,
29,
2083,
14,
2083,
14,
2131,
1062,
288,
9772,
63,
505,
17115,
85,
1717,
68,
16,
60,
85,
1717,
68,
17,
60,
85,
1717,
68,
18,
7,
627,
5198,
267,
776,
267,
282,
275,
8281,
14,
1462,
14,
362,
8,
2051,
29,
65,
14,
2051,
9,
267,
291,
14,
629,
8,
552,
8,
65,
14,
6934,
63,
505,
395,
29664,
9,
339,
347,
511,
63,
602,
63,
3892,
8,
277,
304,
267,
327,
13262,
511,
367,
327,
31485,
267,
2235,
369,
14,
1462,
14,
981,
8,
6526,
29,
2083,
14,
2083,
8,
16278,
12,
3144,
12,
7105,
430,
267,
2235,
369,
14,
1462,
14,
981,
8,
6526,
29,
2083,
14,
2083,
8,
23756,
12,
3144,
12,
7105,
430,
267,
2235,
369,
14,
1462,
14,
981,
8,
6526,
29,
2083,
14,
2083,
8,
16278,
12,
413,
12,
413,
430,
267,
2235,
369,
14,
1462,
14,
981,
8,
6526,
29,
2083,
14,
2083,
8,
17,
12,
650,
12,
650,
430,
267,
291,
14,
7108,
8,
288,
2235,
369,
14,
1462,
14,
1541,
8,
6526,
363,
4482,
29,
18,
395,
942,
267,
776,
267,
291,
14,
7108,
8,
288,
2235,
369,
14,
1462,
14,
1541,
8,
6526,
363,
4482,
29,
17,
395,
359,
355,
2197,
14,
602,
8,
16278,
12,
413,
12,
413,
9,
288,
2156,
288,
21829,
480,
6526,
531,
267,
776,
267,
291,
14,
7108,
8,
288,
2235,
369,
14,
1462,
14,
1541,
8,
6526,
363,
4482,
29,
713,
395,
359,
355,
2197,
14,
602,
8,
16278,
12,
3144,
12,
7105,
395,
355,
2197,
14,
602,
8,
23756,
12,
3144,
12,
7105,
395,
288,
2156,
288,
21829,
480,
6526,
1288,
288,
7741,
29,
797,
267,
776,
267,
291,
14,
7108,
8,
288,
2235,
369,
14,
1462,
14,
1541,
8,
6526,
363,
3403,
29,
23756,
395,
359,
355,
2197,
14,
602,
8,
23756,
12,
3144,
12,
7105,
395,
288,
2156,
288,
21829,
480,
6526,
531,
267,
776,
267,
327,
13262,
511,
367,
327,
2426,
709,
267,
291,
14,
7108,
8,
288,
2235,
369,
14,
1462,
14,
1541,
8,
6526,
363,
2977,
628,
2192,
1288,
359,
355,
2197,
14,
602,
8,
16278,
12,
3144,
12,
7105,
395,
355,
2197,
14,
602,
8,
23756,
12,
3144,
12,
7105,
395,
288,
2156,
288
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2197,
199,
504,
4182,
492,
21829,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
8505,
199,
504,
1639,
14,
697,
492,
6197,
199,
504,
1639,
14,
697,
14,
992,
14,
3009,
492,
15496,
3227,
199,
504,
1639,
14,
396,
492,
7640,
12,
3372,
5524,
18093,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
7145,
492,
664,
63,
5964,
63,
7145,
199,
199,
504,
1275,
992,
492,
334,
272,
8281,
12,
23804,
7087,
3767,
12,
1487,
12493,
12,
6763,
12,
5822,
17,
12,
5822,
18,
12,
5822,
19,
12,
272,
10172,
3358,
8884,
12,
2235,
369,
12,
23886,
12,
199,
9,
421,
199,
533,
5822,
2925,
8,
1746,
304,
272,
327,
710,
6519,
365,
626,
314,
2569,
9212,
3955,
746,
26,
272,
327,
298,
4333,
26,
20116,
5024,
965,
3866,
4237,
26,
486,
266,
2,
272,
347,
511,
63,
2407,
63,
19586,
63,
3892,
8,
277,
304,
267,
408,
267,
13262,
511,
367,
327,
4893,
2481,
26,
11608,
790,
636,
19586,
16807,
14,
267,
408,
267,
23886,
14,
1462,
14,
1541,
8,
19623,
363,
19586,
29,
16,
9,
339,
347,
511,
63,
2407,
63,
20740,
63,
3892,
8,
277,
304,
267,
408,
267,
13262,
511,
367,
327,
4893,
2481,
26,
11608,
790,
636,
20740,
16807,
14,
267,
408,
267,
23886,
14,
1462,
14,
1541,
8,
19623,
363,
20740,
29,
16,
9,
339,
347,
511,
63,
3009,
63,
3176,
63,
5772,
63,
1107,
63,
344,
63,
3215,
8,
277,
304,
267,
408,
267,
13262,
511,
367,
327,
1079,
12512,
26,
5385,
9971,
9131,
14,
305,
63,
3009,
342,
5988,
267,
408,
267,
1592,
275,
6197,
14,
697,
63,
509,
63,
952,
8,
25233,
9,
267,
1827,
275,
15496,
3227,
8,
25233,
9,
267,
1827,
14,
3176,
63,
1459,
779,
25233,
423,
2024,
14,
955,
59,
16,
2365,
990,
3066,
29,
797,
9,
267,
327,
642,
1004,
911,
746,
376,
4281,
1928,
314,
23073,
5325,
267,
1827,
14,
362,
63,
5772,
8,
4941,
29,
697,
680,
305,
63,
3009,
342,
339,
347,
511,
63,
1667,
63,
5095,
8,
277,
304,
267,
327,
6944,
26,
14320,
402,
314,
10864,
511,
2348,
365,
562,
264,
590,
6057,
314,
1402,
267,
327,
12560,
14,
710,
3376,
63,
354,
12,
315,
6770,
12,
8103,
440,
3544,
1736,
14,
267,
282,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
628,
20926,
737,
562,
17716,
7974,
63,
602,
29,
2083,
14,
2083,
14,
2131,
342,
267,
776,
267,
327,
1626,
2701,
7141,
901,
1077,
372,
488,
367,
314,
2929,
536,
14,
267,
291,
14,
3436,
8,
65,
14,
362,
63,
1205,
63,
2918,
1062,
488,
9,
398,
327,
9630,
3326,
1077,
506,
2138,
465,
6140,
267,
282,
275,
8281,
14,
1462,
14,
362,
8,
2051,
29,
65,
14,
2051,
9,
267,
291,
14,
629,
8,
65,
14,
9923,
63,
576,
12,
4074,
267,
291,
14,
3436,
8,
466,
8,
65,
14,
9923,
63,
576,
395,
3816,
14,
505,
63,
466,
9,
339,
347,
511,
63,
2809,
63,
505,
698,
8,
277,
304,
267,
327,
4516,
7304,
883,
10266,
1655,
2419,
31092,
4110,
334,
3749,
1990,
10529,
315,
267,
327,
15309,
680,
267,
282,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
628,
497,
1183,
12,
7710,
7282,
401,
288,
7974,
63,
602,
29,
2083,
14,
2083,
14,
2131,
1062,
288,
9772,
63,
505,
628,
8390,
1093,
2,
627,
5198,
267,
776,
267,
282,
275,
8281,
14,
1462,
14,
362,
8,
2051,
29,
65,
14,
2051,
9,
267,
291,
14,
629,
8,
552,
8,
65,
14,
6934,
63,
505,
395,
22369,
9,
339,
347,
511,
63,
2809,
63,
2975,
63,
505,
698,
8,
277,
304,
267,
327,
4516,
7304,
883,
10266,
1655,
2419,
31092,
2783,
2597,
1380,
2985,
787,
267,
327,
6656,
2419,
31092,
4110,
267,
282,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
628,
497,
1183,
12,
7710,
7282,
401,
288,
7974,
63,
602,
29,
2083,
14,
2083,
14,
2131,
1062,
288,
9772,
63,
505,
17115,
85,
1717,
68,
16,
60,
85,
1717,
68,
17,
60,
85,
1717,
68,
18,
7,
627,
5198,
267,
776,
267,
282,
275,
8281,
14,
1462,
14,
362,
8,
2051,
29,
65,
14,
2051,
9,
267,
291,
14,
629,
8,
552,
8,
65,
14,
6934,
63,
505,
395,
29664,
9,
339,
347,
511,
63,
602,
63,
3892,
8,
277,
304,
267,
327,
13262,
511,
367,
327,
31485,
267,
2235,
369,
14,
1462,
14,
981,
8,
6526,
29,
2083,
14,
2083,
8,
16278,
12,
3144,
12,
7105,
430,
267,
2235,
369,
14,
1462,
14,
981,
8,
6526,
29,
2083,
14,
2083,
8,
23756,
12,
3144,
12,
7105,
430,
267,
2235,
369,
14,
1462,
14,
981,
8,
6526,
29,
2083,
14,
2083,
8,
16278,
12,
413,
12,
413,
430,
267,
2235,
369,
14,
1462,
14,
981,
8,
6526,
29,
2083,
14,
2083,
8,
17,
12,
650,
12,
650,
430,
267,
291,
14,
7108,
8,
288,
2235,
369,
14,
1462,
14,
1541,
8,
6526,
363,
4482,
29,
18,
395,
942,
267,
776,
267,
291,
14,
7108,
8,
288,
2235,
369,
14,
1462,
14,
1541,
8,
6526,
363,
4482,
29,
17,
395,
359,
355,
2197,
14,
602,
8,
16278,
12,
413,
12,
413,
9,
288,
2156,
288,
21829,
480,
6526,
531,
267,
776,
267,
291,
14,
7108,
8,
288,
2235,
369,
14,
1462,
14,
1541,
8,
6526,
363,
4482,
29,
713,
395,
359,
355,
2197,
14,
602,
8,
16278,
12,
3144,
12,
7105,
395,
355,
2197,
14,
602,
8,
23756,
12,
3144,
12,
7105,
395,
288,
2156,
288,
21829,
480,
6526,
1288,
288,
7741,
29,
797,
267,
776,
267,
291,
14,
7108,
8,
288,
2235,
369,
14,
1462,
14,
1541,
8,
6526,
363,
3403,
29,
23756,
395,
359,
355,
2197,
14,
602,
8,
23756,
12,
3144,
12,
7105,
395,
288,
2156,
288,
21829,
480,
6526,
531,
267,
776,
267,
327,
13262,
511,
367,
327,
2426,
709,
267,
291,
14,
7108,
8,
288,
2235,
369,
14,
1462,
14,
1541,
8,
6526,
363,
2977,
628,
2192,
1288,
359,
355,
2197,
14,
602,
8,
16278,
12,
3144,
12,
7105,
395,
355,
2197,
14,
602,
8,
23756,
12,
3144,
12,
7105,
395,
288,
2156,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
calebfoss/tensorflow
|
tensorflow/contrib/learn/python/learn/learn_io/graph_io_test.py
|
17
|
26385
|
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for learn.io.graph_io."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import base64
import os
import random
import sys
import tempfile
# TODO: #6568 Remove this hack that makes dlopen() not crash.
if hasattr(sys, "getdlopenflags") and hasattr(sys, "setdlopenflags"):
import ctypes
sys.setdlopenflags(sys.getdlopenflags() | ctypes.RTLD_GLOBAL)
from six.moves import xrange # pylint: disable=redefined-builtin
from tensorflow.contrib.learn.python.learn.learn_io import graph_io
from tensorflow.contrib.learn.python.learn.learn_io.graph_io import _read_keyed_batch_examples_shared_queue
from tensorflow.python.client import session as session_lib
from tensorflow.python.framework import dtypes as dtypes_lib
from tensorflow.python.framework import errors
from tensorflow.python.framework import ops
from tensorflow.python.framework import test_util
from tensorflow.python.ops import io_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import parsing_ops
from tensorflow.python.ops import variables
from tensorflow.python.platform import gfile
from tensorflow.python.platform import test
from tensorflow.python.training import coordinator
from tensorflow.python.training import queue_runner_impl
from tensorflow.python.training import server_lib
_VALID_FILE_PATTERN = "VALID"
_FILE_NAMES = [b"abc", b"def", b"ghi", b"jkl"]
_INVALID_FILE_PATTERN = "INVALID"
class GraphIOTest(test.TestCase):
def _mock_glob(self, pattern):
if _VALID_FILE_PATTERN == pattern:
return _FILE_NAMES
self.assertEqual(_INVALID_FILE_PATTERN, pattern)
return []
def setUp(self):
super(GraphIOTest, self).setUp()
random.seed(42)
self._orig_glob = gfile.Glob
gfile.Glob = self._mock_glob
def tearDown(self):
gfile.Glob = self._orig_glob
super(GraphIOTest, self).tearDown()
def test_dequeue_batch_value_errors(self):
default_batch_size = 17
queue_capacity = 1234
num_threads = 3
name = "my_batch"
self.assertRaisesRegexp(
ValueError,
"No files match",
graph_io.read_batch_examples,
_INVALID_FILE_PATTERN,
default_batch_size,
io_ops.TFRecordReader,
False,
num_epochs=None,
queue_capacity=queue_capacity,
num_threads=num_threads,
name=name)
self.assertRaisesRegexp(
ValueError,
"Invalid batch_size",
graph_io.read_batch_examples,
_VALID_FILE_PATTERN,
None,
io_ops.TFRecordReader,
False,
num_epochs=None,
queue_capacity=queue_capacity,
num_threads=num_threads,
name=name)
self.assertRaisesRegexp(
ValueError,
"Invalid batch_size",
graph_io.read_batch_examples,
_VALID_FILE_PATTERN,
-1,
io_ops.TFRecordReader,
False,
num_epochs=None,
queue_capacity=queue_capacity,
num_threads=num_threads,
name=name)
self.assertRaisesRegexp(
ValueError,
"Invalid queue_capacity",
graph_io.read_batch_examples,
_VALID_FILE_PATTERN,
default_batch_size,
io_ops.TFRecordReader,
False,
num_epochs=None,
queue_capacity=None,
num_threads=num_threads,
name=name)
self.assertRaisesRegexp(
ValueError,
"Invalid num_threads",
graph_io.read_batch_examples,
_VALID_FILE_PATTERN,
default_batch_size,
io_ops.TFRecordReader,
False,
num_epochs=None,
queue_capacity=queue_capacity,
num_threads=None,
name=name)
self.assertRaisesRegexp(
ValueError,
"Invalid num_threads",
graph_io.read_batch_examples,
_VALID_FILE_PATTERN,
default_batch_size,
io_ops.TFRecordReader,
False,
num_epochs=None,
queue_capacity=queue_capacity,
num_threads=-1,
name=name)
self.assertRaisesRegexp(
ValueError,
"Invalid batch_size",
graph_io.read_batch_examples,
_VALID_FILE_PATTERN,
queue_capacity + 1,
io_ops.TFRecordReader,
False,
num_epochs=None,
queue_capacity=queue_capacity,
num_threads=1,
name=name)
self.assertRaisesRegexp(
ValueError,
"Invalid num_epochs",
graph_io.read_batch_examples,
_VALID_FILE_PATTERN,
default_batch_size,
io_ops.TFRecordReader,
False,
num_epochs=-1,
queue_capacity=queue_capacity,
num_threads=1,
name=name)
self.assertRaisesRegexp(
ValueError,
"Invalid read_batch_size",
graph_io.read_batch_examples,
_VALID_FILE_PATTERN,
default_batch_size,
io_ops.TFRecordReader,
False,
num_epochs=None,
queue_capacity=queue_capacity,
num_threads=1,
read_batch_size=0,
name=name)
def test_batch_record_features(self):
batch_size = 17
queue_capacity = 1234
name = "my_batch"
shape = (0,)
features = {
"feature":
parsing_ops.FixedLenFeature(
shape=shape, dtype=dtypes_lib.float32)
}
with ops.Graph().as_default() as g, self.test_session(graph=g) as sess:
features = graph_io.read_batch_record_features(
_VALID_FILE_PATTERN,
batch_size,
features,
randomize_input=False,
queue_capacity=queue_capacity,
reader_num_threads=2,
name=name)
self.assertTrue("feature" in features,
"'feature' missing from %s." % features.keys())
feature = features["feature"]
self.assertEqual("%s/fifo_queue_1_Dequeue:0" % name, feature.name)
self.assertAllEqual((batch_size,) + shape, feature.get_shape().as_list())
file_name_queue_name = "%s/file_name_queue" % name
file_names_name = "%s/input" % file_name_queue_name
example_queue_name = "%s/fifo_queue" % name
parse_example_queue_name = "%s/fifo_queue" % name
op_nodes = test_util.assert_ops_in_graph({
file_names_name: "Const",
file_name_queue_name: "FIFOQueueV2",
"%s/read/TFRecordReaderV2" % name: "TFRecordReaderV2",
example_queue_name: "FIFOQueueV2",
parse_example_queue_name: "FIFOQueueV2",
name: "QueueDequeueManyV2"
}, g)
self.assertAllEqual(_FILE_NAMES, sess.run(["%s:0" % file_names_name])[0])
self.assertEqual(queue_capacity,
op_nodes[example_queue_name].attr["capacity"].i)
def test_one_epoch(self):
batch_size = 17
queue_capacity = 1234
name = "my_batch"
with ops.Graph().as_default() as g, self.test_session(graph=g) as sess:
inputs = graph_io.read_batch_examples(
_VALID_FILE_PATTERN,
batch_size,
reader=io_ops.TFRecordReader,
randomize_input=True,
num_epochs=1,
queue_capacity=queue_capacity,
name=name)
self.assertAllEqual((None,), inputs.get_shape().as_list())
self.assertEqual("%s:1" % name, inputs.name)
file_name_queue_name = "%s/file_name_queue" % name
file_name_queue_limit_name = ("%s/limit_epochs/epochs" %
file_name_queue_name)
file_names_name = "%s/input" % file_name_queue_name
example_queue_name = "%s/random_shuffle_queue" % name
op_nodes = test_util.assert_ops_in_graph({
file_names_name: "Const",
file_name_queue_name: "FIFOQueueV2",
"%s/read/TFRecordReaderV2" % name: "TFRecordReaderV2",
example_queue_name: "RandomShuffleQueueV2",
name: "QueueDequeueUpToV2",
file_name_queue_limit_name: "VariableV2"
}, g)
self.assertEqual(
set(_FILE_NAMES), set(sess.run(["%s:0" % file_names_name])[0]))
self.assertEqual(queue_capacity,
op_nodes[example_queue_name].attr["capacity"].i)
def test_batch_randomized(self):
batch_size = 17
queue_capacity = 1234
name = "my_batch"
with ops.Graph().as_default() as g, self.test_session(graph=g) as sess:
inputs = graph_io.read_batch_examples(
_VALID_FILE_PATTERN,
batch_size,
reader=io_ops.TFRecordReader,
randomize_input=True,
queue_capacity=queue_capacity,
name=name)
self.assertAllEqual((batch_size,), inputs.get_shape().as_list())
self.assertEqual("%s:1" % name, inputs.name)
file_name_queue_name = "%s/file_name_queue" % name
file_names_name = "%s/input" % file_name_queue_name
example_queue_name = "%s/random_shuffle_queue" % name
op_nodes = test_util.assert_ops_in_graph({
file_names_name: "Const",
file_name_queue_name: "FIFOQueueV2",
"%s/read/TFRecordReaderV2" % name: "TFRecordReaderV2",
example_queue_name: "RandomShuffleQueueV2",
name: "QueueDequeueManyV2"
}, g)
self.assertEqual(
set(_FILE_NAMES), set(sess.run(["%s:0" % file_names_name])[0]))
self.assertEqual(queue_capacity,
op_nodes[example_queue_name].attr["capacity"].i)
def _create_temp_file(self, lines):
tempdir = tempfile.mkdtemp()
filename = os.path.join(tempdir, "temp_file")
gfile.Open(filename, "w").write(lines)
return filename
def _create_sorted_temp_files(self, lines_list):
tempdir = tempfile.mkdtemp()
filenames = []
for i, lines in enumerate(lines_list):
filename = os.path.join(tempdir, "temp_file%05d" % i)
gfile.Open(filename, "w").write(lines)
filenames.append(filename)
return filenames
def test_read_text_lines(self):
gfile.Glob = self._orig_glob
filename = self._create_temp_file("ABC\nDEF\nGHK\n")
batch_size = 1
queue_capacity = 5
name = "my_batch"
with ops.Graph().as_default() as g, self.test_session(graph=g) as session:
inputs = graph_io.read_batch_examples(
filename,
batch_size,
reader=io_ops.TextLineReader,
randomize_input=False,
num_epochs=1,
queue_capacity=queue_capacity,
name=name)
self.assertAllEqual((None,), inputs.get_shape().as_list())
session.run(variables.local_variables_initializer())
coord = coordinator.Coordinator()
threads = queue_runner_impl.start_queue_runners(session, coord=coord)
self.assertAllEqual(session.run(inputs), [b"ABC"])
self.assertAllEqual(session.run(inputs), [b"DEF"])
self.assertAllEqual(session.run(inputs), [b"GHK"])
with self.assertRaises(errors.OutOfRangeError):
session.run(inputs)
coord.request_stop()
coord.join(threads)
def test_read_text_lines_large(self):
gfile.Glob = self._orig_glob
sequence_prefix = "abcdefghijklmnopqrstuvwxyz123456789"
num_records = 49999
lines = [
"".join([sequence_prefix, str(l)]).encode("ascii")
for l in xrange(num_records)
]
json_lines = [
"".join([
'{"features": { "feature": { "sequence": {',
'"bytes_list": { "value": ["', base64.b64encode(l).decode("ascii"),
'"]}}}}}\n'
]) for l in lines
]
filename = self._create_temp_file("".join(json_lines))
batch_size = 10000
queue_capacity = 10000
name = "my_large_batch"
features = {"sequence": parsing_ops.FixedLenFeature([], dtypes_lib.string)}
with ops.Graph().as_default() as g, self.test_session(graph=g) as session:
keys, result = graph_io.read_keyed_batch_features(
filename,
batch_size,
features,
io_ops.TextLineReader,
randomize_input=False,
num_epochs=1,
queue_capacity=queue_capacity,
num_enqueue_threads=2,
parse_fn=parsing_ops.decode_json_example,
name=name)
self.assertAllEqual((None,), keys.get_shape().as_list())
self.assertEqual(1, len(result))
self.assertAllEqual((None,), result["sequence"].get_shape().as_list())
session.run(variables.local_variables_initializer())
coord = coordinator.Coordinator()
threads = queue_runner_impl.start_queue_runners(session, coord=coord)
data = []
try:
while not coord.should_stop():
data.append(session.run(result))
except errors.OutOfRangeError:
pass
finally:
coord.request_stop()
coord.join(threads)
parsed_records = [
item for sublist in [d["sequence"] for d in data] for item in sublist
]
# Check that the number of records matches expected and all records
# are present.
self.assertEqual(len(parsed_records), num_records)
self.assertEqual(set(parsed_records), set(lines))
def test_read_text_lines_multifile(self):
gfile.Glob = self._orig_glob
filenames = self._create_sorted_temp_files(["ABC\n", "DEF\nGHK\n"])
batch_size = 1
queue_capacity = 5
name = "my_batch"
with ops.Graph().as_default() as g, self.test_session(graph=g) as session:
inputs = graph_io.read_batch_examples(
filenames,
batch_size,
reader=io_ops.TextLineReader,
randomize_input=False,
num_epochs=1,
queue_capacity=queue_capacity,
name=name)
self.assertAllEqual((None,), inputs.get_shape().as_list())
session.run(variables.local_variables_initializer())
coord = coordinator.Coordinator()
threads = queue_runner_impl.start_queue_runners(session, coord=coord)
self.assertEqual("%s:1" % name, inputs.name)
file_name_queue_name = "%s/file_name_queue" % name
file_names_name = "%s/input" % file_name_queue_name
example_queue_name = "%s/fifo_queue" % name
test_util.assert_ops_in_graph({
file_names_name: "Const",
file_name_queue_name: "FIFOQueueV2",
"%s/read/TextLineReaderV2" % name: "TextLineReaderV2",
example_queue_name: "FIFOQueueV2",
name: "QueueDequeueUpToV2"
}, g)
self.assertAllEqual(session.run(inputs), [b"ABC"])
self.assertAllEqual(session.run(inputs), [b"DEF"])
self.assertAllEqual(session.run(inputs), [b"GHK"])
with self.assertRaises(errors.OutOfRangeError):
session.run(inputs)
coord.request_stop()
coord.join(threads)
def test_read_text_lines_multifile_with_shared_queue(self):
gfile.Glob = self._orig_glob
filenames = self._create_sorted_temp_files(["ABC\n", "DEF\nGHK\n"])
batch_size = 1
queue_capacity = 5
name = "my_batch"
with ops.Graph().as_default() as g, self.test_session(graph=g) as session:
keys, inputs = _read_keyed_batch_examples_shared_queue(
filenames,
batch_size,
reader=io_ops.TextLineReader,
randomize_input=False,
num_epochs=1,
queue_capacity=queue_capacity,
name=name)
self.assertAllEqual((None,), keys.get_shape().as_list())
self.assertAllEqual((None,), inputs.get_shape().as_list())
session.run([
variables.local_variables_initializer(),
variables.global_variables_initializer()
])
coord = coordinator.Coordinator()
threads = queue_runner_impl.start_queue_runners(session, coord=coord)
self.assertEqual("%s:1" % name, inputs.name)
example_queue_name = "%s/fifo_queue" % name
worker_file_name_queue_name = "%s/file_name_queue/fifo_queue" % name
test_util.assert_ops_in_graph({
"%s/read/TextLineReaderV2" % name: "TextLineReaderV2",
example_queue_name: "FIFOQueueV2",
worker_file_name_queue_name: "FIFOQueueV2",
name: "QueueDequeueUpToV2"
}, g)
self.assertAllEqual(session.run(inputs), [b"ABC"])
self.assertAllEqual(session.run(inputs), [b"DEF"])
self.assertAllEqual(session.run(inputs), [b"GHK"])
with self.assertRaises(errors.OutOfRangeError):
session.run(inputs)
coord.request_stop()
coord.join(threads)
def _get_qr(self, name):
for qr in ops.get_collection(ops.GraphKeys.QUEUE_RUNNERS):
if qr.name == name:
return qr
def _run_queue(self, name, session):
qr = self._get_qr(name)
for op in qr.enqueue_ops:
session.run(op)
def test_multiple_workers_with_shared_queue(self):
gfile.Glob = self._orig_glob
filenames = self._create_sorted_temp_files([
"ABC\n", "DEF\n", "GHI\n", "JKL\n", "MNO\n", "PQR\n", "STU\n", "VWX\n",
"YZ\n"
])
batch_size = 1
queue_capacity = 5
name = "my_batch"
example_queue_name = "%s/fifo_queue" % name
worker_file_name_queue_name = "%s/file_name_queue/fifo_queue" % name
server = server_lib.Server.create_local_server()
with ops.Graph().as_default() as g1, session_lib.Session(
server.target, graph=g1) as session:
keys, inputs = _read_keyed_batch_examples_shared_queue(
filenames,
batch_size,
reader=io_ops.TextLineReader,
randomize_input=False,
num_epochs=1,
queue_capacity=queue_capacity,
name=name)
self.assertAllEqual((None,), keys.get_shape().as_list())
self.assertAllEqual((None,), inputs.get_shape().as_list())
session.run([
variables.local_variables_initializer(),
variables.global_variables_initializer()
])
# Run the two queues once manually.
self._run_queue(worker_file_name_queue_name, session)
self._run_queue(example_queue_name, session)
self.assertAllEqual(session.run(inputs), [b"ABC"])
# Run the worker and the example queue.
self._run_queue(worker_file_name_queue_name, session)
self._run_queue(example_queue_name, session)
self.assertAllEqual(session.run(inputs), [b"DEF"])
with ops.Graph().as_default() as g2, session_lib.Session(
server.target, graph=g2) as session:
keys, inputs = _read_keyed_batch_examples_shared_queue(
filenames,
batch_size,
reader=io_ops.TextLineReader,
randomize_input=False,
num_epochs=1,
queue_capacity=queue_capacity,
name=name)
self.assertAllEqual((None,), keys.get_shape().as_list())
self.assertAllEqual((None,), inputs.get_shape().as_list())
# Run the worker and the example queue.
self._run_queue(worker_file_name_queue_name, session)
self._run_queue(example_queue_name, session)
self.assertAllEqual(session.run(inputs), [b"GHI"])
self.assertTrue(g1 is not g2)
def test_batch_text_lines(self):
gfile.Glob = self._orig_glob
filename = self._create_temp_file("A\nB\nC\nD\nE\n")
batch_size = 3
queue_capacity = 10
name = "my_batch"
with ops.Graph().as_default() as g, self.test_session(graph=g) as session:
inputs = graph_io.read_batch_examples(
[filename],
batch_size,
reader=io_ops.TextLineReader,
randomize_input=False,
num_epochs=1,
queue_capacity=queue_capacity,
read_batch_size=10,
name=name)
self.assertAllEqual((None,), inputs.get_shape().as_list())
session.run(variables.local_variables_initializer())
coord = coordinator.Coordinator()
threads = queue_runner_impl.start_queue_runners(session, coord=coord)
self.assertAllEqual(session.run(inputs), [b"A", b"B", b"C"])
self.assertAllEqual(session.run(inputs), [b"D", b"E"])
with self.assertRaises(errors.OutOfRangeError):
session.run(inputs)
coord.request_stop()
coord.join(threads)
def test_keyed_read_text_lines(self):
gfile.Glob = self._orig_glob
filename = self._create_temp_file("ABC\nDEF\nGHK\n")
batch_size = 1
queue_capacity = 5
name = "my_batch"
with ops.Graph().as_default() as g, self.test_session(graph=g) as session:
keys, inputs = graph_io.read_keyed_batch_examples(
filename,
batch_size,
reader=io_ops.TextLineReader,
randomize_input=False,
num_epochs=1,
queue_capacity=queue_capacity,
name=name)
self.assertAllEqual((None,), keys.get_shape().as_list())
self.assertAllEqual((None,), inputs.get_shape().as_list())
session.run(variables.local_variables_initializer())
coord = coordinator.Coordinator()
threads = queue_runner_impl.start_queue_runners(session, coord=coord)
self.assertAllEqual(
session.run([keys, inputs]),
[[filename.encode("utf-8") + b":1"], [b"ABC"]])
self.assertAllEqual(
session.run([keys, inputs]),
[[filename.encode("utf-8") + b":2"], [b"DEF"]])
self.assertAllEqual(
session.run([keys, inputs]),
[[filename.encode("utf-8") + b":3"], [b"GHK"]])
with self.assertRaises(errors.OutOfRangeError):
session.run(inputs)
coord.request_stop()
coord.join(threads)
def test_keyed_parse_json(self):
gfile.Glob = self._orig_glob
filename = self._create_temp_file(
'{"features": {"feature": {"age": {"int64_list": {"value": [0]}}}}}\n'
'{"features": {"feature": {"age": {"int64_list": {"value": [1]}}}}}\n'
'{"features": {"feature": {"age": {"int64_list": {"value": [2]}}}}}\n')
batch_size = 1
queue_capacity = 5
name = "my_batch"
with ops.Graph().as_default() as g, self.test_session(graph=g) as session:
dtypes = {"age": parsing_ops.FixedLenFeature([1], dtypes_lib.int64)}
parse_fn = lambda example: parsing_ops.parse_single_example( # pylint: disable=g-long-lambda
parsing_ops.decode_json_example(example), dtypes)
keys, inputs = graph_io.read_keyed_batch_examples(
filename,
batch_size,
reader=io_ops.TextLineReader,
randomize_input=False,
num_epochs=1,
queue_capacity=queue_capacity,
parse_fn=parse_fn,
name=name)
self.assertAllEqual((None,), keys.get_shape().as_list())
self.assertEqual(1, len(inputs))
self.assertAllEqual((None, 1), inputs["age"].get_shape().as_list())
session.run(variables.local_variables_initializer())
coord = coordinator.Coordinator()
threads = queue_runner_impl.start_queue_runners(session, coord=coord)
key, age = session.run([keys, inputs["age"]])
self.assertAllEqual(age, [[0]])
self.assertAllEqual(key, [filename.encode("utf-8") + b":1"])
key, age = session.run([keys, inputs["age"]])
self.assertAllEqual(age, [[1]])
self.assertAllEqual(key, [filename.encode("utf-8") + b":2"])
key, age = session.run([keys, inputs["age"]])
self.assertAllEqual(age, [[2]])
self.assertAllEqual(key, [filename.encode("utf-8") + b":3"])
with self.assertRaises(errors.OutOfRangeError):
session.run(inputs)
coord.request_stop()
coord.join(threads)
def test_keyed_features_filter(self):
gfile.Glob = self._orig_glob
lines = [
'{"features": {"feature": {"age": {"int64_list": {"value": [2]}}}}}',
'{"features": {"feature": {"age": {"int64_list": {"value": [0]}}}}}',
'{"features": {"feature": {"age": {"int64_list": {"value": [1]}}}}}',
'{"features": {"feature": {"age": {"int64_list": {"value": [0]}}}}}',
'{"features": {"feature": {"age": {"int64_list": {"value": [3]}}}}}',
'{"features": {"feature": {"age": {"int64_list": {"value": [5]}}}}}'
]
filename = self._create_temp_file("\n".join(lines))
batch_size = 2
queue_capacity = 4
name = "my_batch"
features = {"age": parsing_ops.FixedLenFeature([], dtypes_lib.int64)}
def filter_fn(keys, examples_json):
del keys
serialized = parsing_ops.decode_json_example(examples_json)
examples = parsing_ops.parse_example(serialized, features)
return math_ops.less(examples["age"], 2)
with ops.Graph().as_default() as g, self.test_session(graph=g) as session:
keys, inputs = graph_io._read_keyed_batch_examples_helper(
filename,
batch_size,
reader=io_ops.TextLineReader,
randomize_input=False,
num_epochs=1,
read_batch_size=batch_size,
queue_capacity=queue_capacity,
filter_fn=filter_fn,
name=name)
self.assertAllEqual((None,), keys.get_shape().as_list())
self.assertAllEqual((None,), inputs.get_shape().as_list())
session.run(variables.local_variables_initializer())
coord = coordinator.Coordinator()
threads = queue_runner_impl.start_queue_runners(session, coord=coord)
# First batch of two filtered examples.
out_keys, out_vals = session.run((keys, inputs))
self.assertAllEqual(
[filename.encode("utf-8") + b":2", filename.encode("utf-8") + b":3"],
out_keys)
self.assertAllEqual([lines[1].encode("utf-8"), lines[2].encode("utf-8")],
out_vals)
# Second batch will only have one filtered example as that's the only
# remaining example that satisfies the filtering criterion.
out_keys, out_vals = session.run((keys, inputs))
self.assertAllEqual([filename.encode("utf-8") + b":4"], out_keys)
self.assertAllEqual([lines[3].encode("utf-8")], out_vals)
# Exhausted input.
with self.assertRaises(errors.OutOfRangeError):
session.run((keys, inputs))
coord.request_stop()
coord.join(threads)
if __name__ == "__main__":
test.main()
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
12537,
14,
2308,
14,
2180,
63,
2308,
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,
1300,
772,
199,
646,
747,
199,
646,
2196,
199,
646,
984,
199,
646,
5549,
199,
199,
3,
3254,
26,
327,
22,
15085,
5852,
642,
11176,
626,
7704,
366,
8329,
342,
440,
12420,
14,
199,
692,
2688,
8,
1274,
12,
298,
362,
68,
8329,
2469,
531,
436,
2688,
8,
1274,
12,
298,
409,
68,
8329,
2469,
2349,
523,
492,
5577,
523,
984,
14,
409,
68,
8329,
2469,
8,
1274,
14,
362,
68,
8329,
2469,
342,
1204,
5577,
14,
11876,
6533,
63,
13808,
9,
199,
199,
504,
3816,
14,
4912,
492,
4945,
221,
327,
4287,
26,
3507,
29,
27913,
13,
5351,
199,
199,
504,
3228,
14,
2828,
14,
4643,
14,
1548,
14,
4643,
14,
4643,
63,
2308,
492,
3343,
63,
2308,
199,
504,
3228,
14,
2828,
14,
4643,
14,
1548,
14,
4643,
14,
4643,
63,
2308,
14,
2180,
63,
2308,
492,
485,
739,
63,
498,
379,
63,
2912,
63,
8589,
63,
5555,
63,
1825,
199,
504,
3228,
14,
1548,
14,
1258,
492,
2351,
465,
2351,
63,
773,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
465,
6674,
63,
773,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2552,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
492,
5890,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
6057,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
26532,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
7588,
492,
29186,
199,
504,
3228,
14,
1548,
14,
7588,
492,
4126,
63,
5933,
63,
5472,
199,
504,
3228,
14,
1548,
14,
7588,
492,
1654,
63,
773,
199,
199,
63,
5600,
63,
3817,
63,
10764,
275,
298,
5600,
2,
199,
63,
3817,
63,
14546,
275,
359,
66,
2,
3175,
401,
330,
2,
318,
401,
330,
2,
3561,
73,
401,
330,
2,
74,
9503,
937,
199,
63,
9692,
63,
3817,
63,
10764,
275,
298,
9692,
2,
421,
199,
533,
11513,
2090,
774,
8,
396,
14,
1746,
304,
819,
347,
485,
1805,
63,
6463,
8,
277,
12,
3851,
304,
272,
340,
485,
5600,
63,
3817,
63,
10764,
508,
3851,
26,
489,
372,
485,
3817,
63,
14546,
272,
291,
14,
629,
1547,
9692,
63,
3817,
63,
10764,
12,
3851,
9,
272,
372,
942,
819,
347,
3613,
8,
277,
304,
272,
1613,
8,
4578,
2090,
774,
12,
291,
680,
5996,
342,
272,
2196,
14,
5176,
8,
2260,
9,
272,
291,
423,
2981,
63,
6463,
275,
26532,
14,
25954,
272,
26532,
14,
25954,
275,
291,
423,
1805,
63,
6463,
819,
347,
6766,
8,
277,
304,
272,
26532,
14,
25954,
275,
291,
423,
2981,
63,
6463,
272,
1613,
8,
4578,
2090,
774,
12,
291,
680,
12336,
342,
819,
347,
511,
63,
18522,
63,
2912,
63,
585,
63,
2550,
8,
277,
304,
272,
849,
63,
2912,
63,
890,
275,
5557,
272,
4126,
63,
10457,
275,
14763,
272,
1967,
63,
6962,
275,
650,
272,
536,
275,
298,
1662,
63,
2912,
2,
339,
291,
14,
10835,
8,
267,
1722,
12,
267,
298,
1944,
1584,
1336,
401,
267,
3343,
63,
2308,
14,
739,
63,
2912,
63,
8589,
12,
267,
485,
9692,
63,
3817,
63,
10764,
12,
267,
849,
63,
2912,
63,
890,
12,
267,
5890,
63,
1483,
14,
6145,
5433,
5929,
12,
267,
756,
12,
267,
1967,
63,
13161,
29,
403,
12,
267,
4126,
63,
10457,
29,
1825,
63,
10457,
12,
267,
1967,
63,
6962,
29,
1507,
63,
6962,
12,
267,
536,
29,
354,
9,
272,
291,
14,
10835,
8,
267,
1722,
12,
267,
298,
3364,
3522,
63,
890,
401,
267,
3343,
63,
2308,
14,
739,
63,
2912,
63,
8589,
12,
267,
485,
5600,
63,
3817,
63,
10764,
12,
267,
488,
12,
267,
5890,
63,
1483,
14,
6145,
5433,
5929,
12,
267,
756,
12,
267,
1967,
63,
13161,
29,
403,
12,
267,
4126,
63,
10457,
29,
1825,
63,
10457,
12,
267,
1967,
63,
6962,
29,
1507,
63,
6962,
12,
267,
536,
29,
354,
9,
272,
291,
14,
10835,
8,
267,
1722,
12,
267,
298,
3364,
3522,
63,
890,
401,
267,
3343,
63,
2308,
14,
739,
63,
2912,
63,
8589,
12,
267,
485,
5600,
63,
3817,
63,
10764,
12,
267,
446,
17,
12,
267,
5890,
63,
1483,
14,
6145,
5433,
5929,
12,
267,
756,
12,
267,
1967,
63,
13161,
29,
403,
12,
267,
4126,
63,
10457,
29,
1825,
63,
10457,
12,
267,
1967,
63,
6962,
29,
1507,
63,
6962,
12,
267,
536,
29,
354,
9,
272,
291,
14,
10835,
8,
267,
1722,
12,
267,
298,
3364,
4126,
63,
10457,
401,
267,
3343,
63,
2308,
14,
739,
63,
2912,
63,
8589,
12,
267,
485,
5600,
63,
3817,
63,
10764,
12,
267,
849,
63,
2912,
63,
890,
12,
267,
5890,
63,
1483,
14,
6145,
5433,
5929,
12,
267,
756,
12,
267,
1967,
63,
13161,
29,
403,
12,
267,
4126,
63,
10457,
29,
403,
12,
267,
1967,
63,
6962,
29,
1507,
63,
6962,
12,
267,
536,
29,
354,
9
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
12537,
14,
2308,
14,
2180,
63,
2308,
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,
1300,
772,
199,
646,
747,
199,
646,
2196,
199,
646,
984,
199,
646,
5549,
199,
199,
3,
3254,
26,
327,
22,
15085,
5852,
642,
11176,
626,
7704,
366,
8329,
342,
440,
12420,
14,
199,
692,
2688,
8,
1274,
12,
298,
362,
68,
8329,
2469,
531,
436,
2688,
8,
1274,
12,
298,
409,
68,
8329,
2469,
2349,
523,
492,
5577,
523,
984,
14,
409,
68,
8329,
2469,
8,
1274,
14,
362,
68,
8329,
2469,
342,
1204,
5577,
14,
11876,
6533,
63,
13808,
9,
199,
199,
504,
3816,
14,
4912,
492,
4945,
221,
327,
4287,
26,
3507,
29,
27913,
13,
5351,
199,
199,
504,
3228,
14,
2828,
14,
4643,
14,
1548,
14,
4643,
14,
4643,
63,
2308,
492,
3343,
63,
2308,
199,
504,
3228,
14,
2828,
14,
4643,
14,
1548,
14,
4643,
14,
4643,
63,
2308,
14,
2180,
63,
2308,
492,
485,
739,
63,
498,
379,
63,
2912,
63,
8589,
63,
5555,
63,
1825,
199,
504,
3228,
14,
1548,
14,
1258,
492,
2351,
465,
2351,
63,
773,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
465,
6674,
63,
773,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2552,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
492,
5890,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
6057,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
26532,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
7588,
492,
29186,
199,
504,
3228,
14,
1548,
14,
7588,
492,
4126,
63,
5933,
63,
5472,
199,
504,
3228,
14,
1548,
14,
7588,
492,
1654,
63,
773,
199,
199,
63,
5600,
63,
3817,
63,
10764,
275,
298,
5600,
2,
199,
63,
3817,
63,
14546,
275,
359,
66,
2,
3175,
401,
330,
2,
318,
401,
330,
2,
3561,
73,
401,
330,
2,
74,
9503,
937,
199,
63,
9692,
63,
3817,
63,
10764,
275,
298,
9692,
2,
421,
199,
533,
11513,
2090,
774,
8,
396,
14,
1746,
304,
819,
347,
485,
1805,
63,
6463,
8,
277,
12,
3851,
304,
272,
340,
485,
5600,
63,
3817,
63,
10764,
508,
3851,
26,
489,
372,
485,
3817,
63,
14546,
272,
291,
14,
629,
1547,
9692,
63,
3817,
63,
10764,
12,
3851,
9,
272,
372,
942,
819,
347,
3613,
8,
277,
304,
272,
1613,
8,
4578,
2090,
774,
12,
291,
680,
5996,
342,
272,
2196,
14,
5176,
8,
2260,
9,
272,
291,
423,
2981,
63,
6463,
275,
26532,
14,
25954,
272,
26532,
14,
25954,
275,
291,
423,
1805,
63,
6463,
819,
347,
6766,
8,
277,
304,
272,
26532,
14,
25954,
275,
291,
423,
2981,
63,
6463,
272,
1613,
8,
4578,
2090,
774,
12,
291,
680,
12336,
342,
819,
347,
511,
63,
18522,
63,
2912,
63,
585,
63,
2550,
8,
277,
304,
272,
849,
63,
2912,
63,
890,
275,
5557,
272,
4126,
63,
10457,
275,
14763,
272,
1967,
63,
6962,
275,
650,
272,
536,
275,
298,
1662,
63,
2912,
2,
339,
291,
14,
10835,
8,
267,
1722,
12,
267,
298,
1944,
1584,
1336,
401,
267,
3343,
63,
2308,
14,
739,
63,
2912,
63,
8589,
12,
267,
485,
9692,
63,
3817,
63,
10764,
12,
267,
849,
63,
2912,
63,
890,
12,
267,
5890,
63,
1483,
14,
6145,
5433,
5929,
12,
267,
756,
12,
267,
1967,
63,
13161,
29,
403,
12,
267,
4126,
63,
10457,
29,
1825,
63,
10457,
12,
267,
1967,
63,
6962,
29,
1507,
63,
6962,
12,
267,
536,
29,
354,
9,
272,
291,
14,
10835,
8,
267,
1722,
12,
267,
298,
3364,
3522,
63,
890,
401,
267,
3343,
63,
2308,
14,
739,
63,
2912,
63,
8589,
12,
267,
485,
5600,
63,
3817,
63,
10764,
12,
267,
488,
12,
267,
5890,
63,
1483,
14,
6145,
5433,
5929,
12,
267,
756,
12,
267,
1967,
63,
13161,
29,
403,
12,
267,
4126,
63,
10457,
29,
1825,
63,
10457,
12,
267,
1967,
63,
6962,
29,
1507,
63,
6962,
12,
267,
536,
29,
354,
9,
272,
291,
14,
10835,
8,
267,
1722,
12,
267,
298,
3364,
3522,
63,
890,
401,
267,
3343,
63,
2308,
14,
739,
63,
2912,
63,
8589,
12,
267,
485,
5600,
63,
3817,
63,
10764,
12,
267,
446,
17,
12,
267,
5890,
63,
1483,
14,
6145,
5433,
5929,
12,
267,
756,
12,
267,
1967,
63,
13161,
29,
403,
12,
267,
4126,
63,
10457,
29,
1825,
63,
10457,
12,
267,
1967,
63,
6962,
29,
1507,
63,
6962,
12,
267,
536,
29,
354,
9,
272,
291,
14,
10835,
8,
267,
1722,
12,
267,
298,
3364,
4126,
63,
10457,
401,
267,
3343,
63,
2308,
14,
739,
63,
2912,
63,
8589,
12,
267,
485,
5600,
63,
3817,
63,
10764,
12,
267,
849,
63,
2912,
63,
890,
12,
267,
5890,
63,
1483,
14,
6145,
5433,
5929,
12,
267,
756,
12,
267,
1967,
63,
13161,
29,
403,
12,
267,
4126,
63,
10457,
29,
403,
12,
267,
1967,
63,
6962,
29,
1507,
63,
6962,
12,
267,
536,
29,
354,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
andreadean5/python-hpOneView
|
examples/scripts/get-volume-template.py
|
2
|
4915
|
#!/usr/bin/env python
###
# (C) Copyright (2012-2015) Hewlett Packard Enterprise Development LP
#
# 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 __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
from builtins import range
from future import standard_library
standard_library.install_aliases()
import sys
PYTHON_VERSION = sys.version_info[:3]
PY2 = (PYTHON_VERSION[0] == 2)
if PY2:
if PYTHON_VERSION < (2, 7, 9):
raise Exception('Must use Python 2.7.9 or later')
elif PYTHON_VERSION < (3, 4):
raise Exception('Must use Python 3.4 or later')
import hpOneView as hpov
from pprint import pprint
def acceptEULA(con):
# See if we need to accept the EULA before we try to log in
con.get_eula_status()
try:
if con.get_eula_status() is True:
print('EULA display needed')
con.set_eula('no')
except Exception as e:
print('EXCEPTION:')
print(e)
def login(con, credential):
# Login with givin credentials
try:
con.login(credential)
except:
print('Login failed')
def get_vol_template_by_name(sto, name):
templates = sto.get_storage_volume_templates()
for template in templates['members']:
if template['name'] == name:
print('Getting Storage Volume Template: ', template['name'])
pprint(template)
return
print('Volume Template: ', name, ' not found')
def get_all_vol_templates(sto):
templates = sto.get_storage_volume_templates()
for template in templates['members']:
print('Getting Storage Volume Template: ', template['name'])
pprint(template)
print()
def main():
parser = argparse.ArgumentParser(add_help=True,
formatter_class=argparse.RawTextHelpFormatter,
description='''
Display Volume Templates
Usage: ''')
parser.add_argument('-a', dest='host', required=True,
help='''
HPE OneView Appliance hostname or IP address''')
parser.add_argument('-u', dest='user', required=False,
default='Administrator',
help='''
HPE OneView Username''')
parser.add_argument('-p', dest='passwd', required=True,
help='''
HPE OneView Password''')
parser.add_argument('-c', dest='cert', required=False,
help='''
Trusted SSL Certificate Bundle in PEM (Base64 Encoded DER) Format''')
parser.add_argument('-y', dest='proxy', required=False,
help='''
Proxy (host:port format''')
parser.add_argument('-j', dest='domain', required=False,
default='Local',
help='''
HPE OneView Authorized Login Domain''')
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-n', dest='name',
help='''
Name of the storage volume template''')
group.add_argument('-g', dest='get_all',
action='store_true',
help='''
Get all storage volume templates''')
args = parser.parse_args()
credential = {'authLoginDomain': args.domain.upper(), 'userName': args.user, 'password': args.passwd}
con = hpov.connection(args.host)
sto = hpov.storage(con)
if args.proxy:
con.set_proxy(args.proxy.split(':')[0], args.proxy.split(':')[1])
if args.cert:
con.set_trusted_ssl_bundle(args.cert)
login(con, credential)
acceptEULA(con)
if args.get_all:
get_all_vol_templates(sto)
sys.exit()
get_vol_template_by_name(sto, args.name)
if __name__ == '__main__':
import sys
import argparse
sys.exit(main())
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
5680,
199,
3,
334,
35,
9,
1898,
334,
7409,
13,
7806,
9,
27849,
9954,
1005,
29949,
15290,
21738,
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,
199,
3,
2334,
4141,
14,
199,
5680,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
12963,
492,
1425,
199,
504,
6466,
492,
4465,
63,
4342,
199,
6807,
63,
4342,
14,
3174,
63,
8602,
342,
199,
646,
984,
199,
199,
11720,
63,
4612,
275,
984,
14,
1023,
63,
815,
1491,
19,
61,
199,
4521,
18,
275,
334,
11720,
63,
4612,
59,
16,
61,
508,
499,
9,
199,
692,
7843,
18,
26,
272,
340,
18280,
63,
4612,
665,
334,
18,
12,
1520,
12,
1749,
304,
267,
746,
2186,
360,
13757,
675,
2018,
499,
14,
23,
14,
25,
503,
2945,
358,
199,
4164,
18280,
63,
4612,
665,
334,
19,
12,
841,
304,
272,
746,
2186,
360,
13757,
675,
2018,
650,
14,
20,
503,
2945,
358,
199,
199,
646,
20962,
4395,
2768,
465,
394,
555,
86,
199,
504,
10933,
492,
10933,
421,
199,
318,
4729,
37,
1293,
33,
8,
388,
304,
272,
327,
1666,
340,
781,
1929,
370,
4729,
314,
662,
1293,
33,
2544,
781,
862,
370,
943,
315,
272,
406,
14,
362,
63,
69,
7586,
63,
1205,
342,
272,
862,
26,
267,
340,
406,
14,
362,
63,
69,
7586,
63,
1205,
342,
365,
715,
26,
288,
870,
360,
37,
1293,
33,
2929,
4346,
358,
288,
406,
14,
409,
63,
69,
7586,
360,
889,
358,
272,
871,
2186,
465,
325,
26,
267,
870,
360,
15375,
10993,
267,
870,
8,
69,
9,
421,
199,
318,
4676,
8,
388,
12,
16338,
304,
272,
327,
16430,
543,
486,
1003,
262,
6235,
272,
862,
26,
267,
406,
14,
2886,
8,
15591,
9,
272,
871,
26,
267,
870,
360,
8880,
3405,
358,
421,
199,
318,
664,
63,
5650,
63,
1160,
63,
991,
63,
354,
8,
14308,
12,
536,
304,
272,
7009,
275,
26123,
14,
362,
63,
3494,
63,
2405,
63,
5876,
342,
272,
367,
1978,
315,
7009,
459,
6334,
2565,
267,
340,
1978,
459,
354,
418,
508,
536,
26,
288,
870,
360,
28277,
10533,
15018,
5458,
26,
1656,
1978,
459,
354,
1105,
288,
10933,
8,
1160,
9,
288,
372,
272,
870,
360,
6464,
5458,
26,
1656,
536,
12,
283,
440,
1911,
358,
421,
199,
318,
664,
63,
452,
63,
5650,
63,
5876,
8,
14308,
304,
272,
7009,
275,
26123,
14,
362,
63,
3494,
63,
2405,
63,
5876,
342,
272,
367,
1978,
315,
7009,
459,
6334,
2565,
267,
870,
360,
28277,
10533,
15018,
5458,
26,
1656,
1978,
459,
354,
1105,
267,
10933,
8,
1160,
9,
267,
870,
342,
421,
199,
318,
2446,
837,
272,
1798,
275,
7534,
14,
10730,
8,
525,
63,
3437,
29,
549,
12,
717,
9698,
63,
533,
29,
18978,
14,
7963,
1872,
22779,
12,
3660,
1369,
19938,
272,
12175,
15018,
31273,
339,
11028,
26,
21464,
272,
1798,
14,
525,
63,
2094,
3654,
65,
297,
2053,
534,
1102,
297,
1415,
29,
549,
12,
717,
1720,
19938,
272,
869,
1510,
7309,
2768,
4693,
3636,
6246,
503,
3531,
2287,
12310,
272,
1798,
14,
525,
63,
2094,
3654,
85,
297,
2053,
534,
751,
297,
1415,
29,
797,
12,
717,
849,
534,
31972,
297,
717,
1720,
19938,
272,
869,
1510,
7309,
2768,
29739,
12310,
272,
1798,
14,
525,
63,
2094,
3654,
80,
297,
2053,
534,
12671,
297,
1415,
29,
549,
12,
717,
1720,
19938,
272,
869,
1510,
7309,
2768,
13635,
12310,
272,
1798,
14,
525,
63,
2094,
3654,
67,
297,
2053,
534,
4736,
297,
1415,
29,
797,
12,
717,
1720,
19938,
272,
28814,
7274,
7799,
12904,
29311,
315,
25957,
334,
1563,
772,
3447,
15282,
577,
540,
9,
9701,
12310,
272,
1798,
14,
525,
63,
2094,
3654,
89,
297,
2053,
534,
3280,
297,
1415,
29,
797,
12,
717,
1720,
19938,
272,
12373,
334,
1102,
26,
719,
1475,
12310,
272,
1798,
14,
525,
63,
2094,
3654,
74,
297,
2053,
534,
2261,
297,
1415,
29,
797,
12,
717,
849,
534,
5339,
297,
717,
1720,
19938,
272,
869,
1510,
7309,
2768,
6529,
1759,
16430,
14061,
12310,
272,
1572,
275,
1798,
14,
525,
63,
25024,
63,
12730,
63,
923,
8,
2427,
29,
549,
9,
272,
1572,
14,
525,
63,
2094,
3654,
78,
297,
2053,
534,
354,
297,
2432,
1720,
19938,
272,
2812,
402,
314,
4887,
3301,
1978,
12310,
272,
1572,
14,
525,
63,
2094,
3654,
71,
297,
2053,
534,
362,
63,
452,
297,
2432,
1595,
534,
1617,
63,
2052,
297,
2432,
1720,
19938,
272,
2372,
1006,
4887,
3301,
7009,
12310,
339,
1249,
275,
1798,
14,
1122,
63,
589,
342,
272,
16338,
275,
791,
1178,
8880,
7705,
356,
1249,
14,
2261,
14,
4142,
1062,
283,
751,
985,
356,
1249,
14,
751,
12,
283,
2060,
356,
1249,
14,
12671,
93,
339,
406,
275,
394,
555
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
5680,
199,
3,
334,
35,
9,
1898,
334,
7409,
13,
7806,
9,
27849,
9954,
1005,
29949,
15290,
21738,
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,
199,
3,
2334,
4141,
14,
199,
5680,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
12963,
492,
1425,
199,
504,
6466,
492,
4465,
63,
4342,
199,
6807,
63,
4342,
14,
3174,
63,
8602,
342,
199,
646,
984,
199,
199,
11720,
63,
4612,
275,
984,
14,
1023,
63,
815,
1491,
19,
61,
199,
4521,
18,
275,
334,
11720,
63,
4612,
59,
16,
61,
508,
499,
9,
199,
692,
7843,
18,
26,
272,
340,
18280,
63,
4612,
665,
334,
18,
12,
1520,
12,
1749,
304,
267,
746,
2186,
360,
13757,
675,
2018,
499,
14,
23,
14,
25,
503,
2945,
358,
199,
4164,
18280,
63,
4612,
665,
334,
19,
12,
841,
304,
272,
746,
2186,
360,
13757,
675,
2018,
650,
14,
20,
503,
2945,
358,
199,
199,
646,
20962,
4395,
2768,
465,
394,
555,
86,
199,
504,
10933,
492,
10933,
421,
199,
318,
4729,
37,
1293,
33,
8,
388,
304,
272,
327,
1666,
340,
781,
1929,
370,
4729,
314,
662,
1293,
33,
2544,
781,
862,
370,
943,
315,
272,
406,
14,
362,
63,
69,
7586,
63,
1205,
342,
272,
862,
26,
267,
340,
406,
14,
362,
63,
69,
7586,
63,
1205,
342,
365,
715,
26,
288,
870,
360,
37,
1293,
33,
2929,
4346,
358,
288,
406,
14,
409,
63,
69,
7586,
360,
889,
358,
272,
871,
2186,
465,
325,
26,
267,
870,
360,
15375,
10993,
267,
870,
8,
69,
9,
421,
199,
318,
4676,
8,
388,
12,
16338,
304,
272,
327,
16430,
543,
486,
1003,
262,
6235,
272,
862,
26,
267,
406,
14,
2886,
8,
15591,
9,
272,
871,
26,
267,
870,
360,
8880,
3405,
358,
421,
199,
318,
664,
63,
5650,
63,
1160,
63,
991,
63,
354,
8,
14308,
12,
536,
304,
272,
7009,
275,
26123,
14,
362,
63,
3494,
63,
2405,
63,
5876,
342,
272,
367,
1978,
315,
7009,
459,
6334,
2565,
267,
340,
1978,
459,
354,
418,
508,
536,
26,
288,
870,
360,
28277,
10533,
15018,
5458,
26,
1656,
1978,
459,
354,
1105,
288,
10933,
8,
1160,
9,
288,
372,
272,
870,
360,
6464,
5458,
26,
1656,
536,
12,
283,
440,
1911,
358,
421,
199,
318,
664,
63,
452,
63,
5650,
63,
5876,
8,
14308,
304,
272,
7009,
275,
26123,
14,
362,
63,
3494,
63,
2405,
63,
5876,
342,
272,
367,
1978,
315,
7009,
459,
6334,
2565,
267,
870,
360,
28277,
10533,
15018,
5458,
26,
1656,
1978,
459,
354,
1105,
267,
10933,
8,
1160,
9,
267,
870,
342,
421,
199,
318,
2446,
837,
272,
1798,
275,
7534,
14,
10730,
8,
525,
63,
3437,
29,
549,
12,
717,
9698,
63,
533,
29,
18978,
14,
7963,
1872,
22779,
12,
3660,
1369,
19938,
272,
12175,
15018,
31273,
339,
11028,
26,
21464,
272,
1798,
14,
525,
63,
2094,
3654,
65,
297,
2053,
534,
1102,
297,
1415,
29,
549,
12,
717,
1720,
19938,
272,
869,
1510,
7309,
2768,
4693,
3636,
6246,
503,
3531,
2287,
12310,
272,
1798,
14,
525,
63,
2094,
3654,
85,
297,
2053,
534,
751,
297,
1415,
29,
797,
12,
717,
849,
534,
31972,
297,
717,
1720,
19938,
272,
869,
1510,
7309,
2768,
29739,
12310,
272,
1798,
14,
525,
63,
2094,
3654,
80,
297,
2053,
534,
12671,
297,
1415,
29,
549,
12,
717,
1720,
19938,
272,
869,
1510,
7309,
2768,
13635,
12310,
272,
1798,
14,
525,
63,
2094,
3654,
67,
297,
2053,
534,
4736,
297,
1415,
29,
797,
12,
717,
1720,
19938,
272,
28814,
7274,
7799,
12904,
29311,
315,
25957,
334,
1563,
772,
3447,
15282,
577,
540,
9,
9701,
12310,
272,
1798,
14,
525,
63,
2094,
3654,
89,
297,
2053,
534,
3280,
297,
1415,
29,
797,
12,
717,
1720,
19938,
272,
12373,
334,
1102,
26,
719,
1475,
12310,
272,
1798,
14,
525,
63,
2094,
3654,
74,
297,
2053,
534,
2261,
297,
1415,
29,
797,
12,
717,
849,
534,
5339,
297,
717,
1720,
19938,
272,
869,
1510,
7309,
2768,
6529,
1759,
16430,
14061,
12310,
272,
1572,
275,
1798,
14,
525,
63,
25024,
63,
12730,
63,
923,
8,
2427,
29,
549,
9,
272,
1572,
14,
525,
63,
2094,
3654,
78,
297,
2053,
534,
354,
297,
2432,
1720,
19938,
272,
2812,
402,
314,
4887,
3301,
1978,
12310,
272,
1572,
14,
525,
63,
2094,
3654,
71,
297,
2053,
534,
362,
63,
452,
297,
2432,
1595,
534,
1617,
63,
2052,
297,
2432,
1720,
19938,
272,
2372,
1006,
4887,
3301,
7009,
12310,
339,
1249,
275,
1798,
14,
1122,
63,
589,
342,
272,
16338,
275,
791,
1178,
8880,
7705,
356,
1249,
14,
2261,
14,
4142,
1062,
283,
751,
985,
356,
1249,
14,
751,
12,
283,
2060,
356,
1249,
14,
12671,
93,
339,
406,
275,
394,
555,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
2013
|
from django.conf.urls import url
from oscar.core.application import Application
from oscar.core.loading import get_class
class OrdersDashboardApplication(Application):
name = None
default_permissions = ['is_staff', ]
permissions_map = {
'order-list': (['is_staff'], ['partner.dashboard_access']),
'order-stats': (['is_staff'], ['partner.dashboard_access']),
'order-detail': (['is_staff'], ['partner.dashboard_access']),
'order-detail-note': (['is_staff'], ['partner.dashboard_access']),
'order-line-detail': (['is_staff'], ['partner.dashboard_access']),
'order-shipping-address': (['is_staff'], ['partner.dashboard_access']),
}
order_list_view = get_class('dashboard.orders.views', 'OrderListView')
order_detail_view = get_class('dashboard.orders.views', 'OrderDetailView')
shipping_address_view = get_class('dashboard.orders.views',
'ShippingAddressUpdateView')
line_detail_view = get_class('dashboard.orders.views', 'LineDetailView')
order_stats_view = get_class('dashboard.orders.views', 'OrderStatsView')
def get_urls(self):
urls = [
url(r'^$', self.order_list_view.as_view(), name='order-list'),
url(r'^statistics/$', self.order_stats_view.as_view(),
name='order-stats'),
url(r'^(?P<number>[-\w]+)/$',
self.order_detail_view.as_view(), name='order-detail'),
url(r'^(?P<number>[-\w]+)/notes/(?P<note_id>\d+)/$',
self.order_detail_view.as_view(), name='order-detail-note'),
url(r'^(?P<number>[-\w]+)/lines/(?P<line_id>\d+)/$',
self.line_detail_view.as_view(), name='order-line-detail'),
url(r'^(?P<number>[-\w]+)/shipping-address/$',
self.shipping_address_view.as_view(),
name='order-shipping-address'),
]
return self.post_process_urls(urls)
application = OrdersDashboardApplication()
|
bsd-3-clause
|
[
504,
1639,
14,
2190,
14,
3603,
492,
1166,
199,
199,
504,
312,
22707,
14,
1018,
14,
3578,
492,
13515,
199,
504,
312,
22707,
14,
1018,
14,
8786,
492,
664,
63,
533,
421,
199,
533,
4236,
7735,
30122,
5039,
8,
5039,
304,
272,
536,
275,
488,
272,
849,
63,
6060,
275,
788,
374,
63,
7018,
297,
1622,
272,
3443,
63,
1130,
275,
469,
267,
283,
1648,
13,
513,
356,
21022,
374,
63,
7018,
995,
788,
3899,
14,
9743,
63,
2732,
3815,
267,
283,
1648,
13,
3200,
356,
21022,
374,
63,
7018,
995,
788,
3899,
14,
9743,
63,
2732,
3815,
267,
283,
1648,
13,
5506,
356,
21022,
374,
63,
7018,
995,
788,
3899,
14,
9743,
63,
2732,
3815,
267,
283,
1648,
13,
5506,
13,
4610,
356,
21022,
374,
63,
7018,
995,
788,
3899,
14,
9743,
63,
2732,
3815,
267,
283,
1648,
13,
604,
13,
5506,
356,
21022,
374,
63,
7018,
995,
788,
3899,
14,
9743,
63,
2732,
3815,
267,
283,
1648,
13,
17801,
13,
1562,
356,
21022,
374,
63,
7018,
995,
788,
3899,
14,
9743,
63,
2732,
3815,
272,
789,
339,
1865,
63,
513,
63,
1345,
275,
664,
63,
533,
360,
9743,
14,
14387,
14,
4196,
297,
283,
4738,
23239,
358,
272,
1865,
63,
5506,
63,
1345,
275,
664,
63,
533,
360,
9743,
14,
14387,
14,
4196,
297,
283,
4738,
28539,
358,
272,
27490,
63,
1562,
63,
1345,
275,
664,
63,
533,
360,
9743,
14,
14387,
14,
4196,
297,
4228,
283,
30707,
4073,
1476,
4152,
2768,
358,
272,
1004,
63,
5506,
63,
1345,
275,
664,
63,
533,
360,
9743,
14,
14387,
14,
4196,
297,
283,
3049,
28539,
358,
272,
1865,
63,
3200,
63,
1345,
275,
664,
63,
533,
360,
9743,
14,
14387,
14,
4196,
297,
283,
4738,
8257,
2768,
358,
339,
347,
664,
63,
3603,
8,
277,
304,
267,
8187,
275,
359,
288,
1166,
8,
82,
4289,
4268,
291,
14,
1648,
63,
513,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
1648,
13,
513,
659,
288,
1166,
8,
82,
4289,
13724,
10884,
291,
14,
1648,
63,
3200,
63,
1345,
14,
305,
63,
1345,
1062,
355,
536,
534,
1648,
13,
3200,
659,
288,
1166,
8,
82,
24550,
48,
28,
1955,
30,
1988,
60,
87,
24598,
4268,
355,
291,
14,
1648,
63,
5506,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
1648,
13,
5506,
659,
288,
1166,
8,
82,
24550,
48,
28,
1955,
30,
1988,
60,
87,
24598,
5983,
9448,
48,
28,
4610,
63,
344,
3072,
68,
18830,
4268,
355,
291,
14,
1648,
63,
5506,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
1648,
13,
5506,
13,
4610,
659,
288,
1166,
8,
82,
24550,
48,
28,
1955,
30,
1988,
60,
87,
24598,
1278,
9448,
48,
28,
604,
63,
344,
3072,
68,
18830,
4268,
355,
291,
14,
604,
63,
5506,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
1648,
13,
604,
13,
5506,
659,
288,
1166,
8,
82,
24550,
48,
28,
1955,
30,
1988,
60,
87,
24598,
17801,
13,
1562,
10884,
355,
291,
14,
17801,
63,
1562,
63,
1345,
14,
305,
63,
1345,
1062,
355,
536,
534,
1648,
13,
17801,
13,
1562,
659,
267,
1622,
267,
372,
291,
14,
1932,
63,
1412,
63,
3603,
8,
3603,
9,
421,
199,
3578,
275,
4236,
7735,
30122,
5039,
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
] |
[
1639,
14,
2190,
14,
3603,
492,
1166,
199,
199,
504,
312,
22707,
14,
1018,
14,
3578,
492,
13515,
199,
504,
312,
22707,
14,
1018,
14,
8786,
492,
664,
63,
533,
421,
199,
533,
4236,
7735,
30122,
5039,
8,
5039,
304,
272,
536,
275,
488,
272,
849,
63,
6060,
275,
788,
374,
63,
7018,
297,
1622,
272,
3443,
63,
1130,
275,
469,
267,
283,
1648,
13,
513,
356,
21022,
374,
63,
7018,
995,
788,
3899,
14,
9743,
63,
2732,
3815,
267,
283,
1648,
13,
3200,
356,
21022,
374,
63,
7018,
995,
788,
3899,
14,
9743,
63,
2732,
3815,
267,
283,
1648,
13,
5506,
356,
21022,
374,
63,
7018,
995,
788,
3899,
14,
9743,
63,
2732,
3815,
267,
283,
1648,
13,
5506,
13,
4610,
356,
21022,
374,
63,
7018,
995,
788,
3899,
14,
9743,
63,
2732,
3815,
267,
283,
1648,
13,
604,
13,
5506,
356,
21022,
374,
63,
7018,
995,
788,
3899,
14,
9743,
63,
2732,
3815,
267,
283,
1648,
13,
17801,
13,
1562,
356,
21022,
374,
63,
7018,
995,
788,
3899,
14,
9743,
63,
2732,
3815,
272,
789,
339,
1865,
63,
513,
63,
1345,
275,
664,
63,
533,
360,
9743,
14,
14387,
14,
4196,
297,
283,
4738,
23239,
358,
272,
1865,
63,
5506,
63,
1345,
275,
664,
63,
533,
360,
9743,
14,
14387,
14,
4196,
297,
283,
4738,
28539,
358,
272,
27490,
63,
1562,
63,
1345,
275,
664,
63,
533,
360,
9743,
14,
14387,
14,
4196,
297,
4228,
283,
30707,
4073,
1476,
4152,
2768,
358,
272,
1004,
63,
5506,
63,
1345,
275,
664,
63,
533,
360,
9743,
14,
14387,
14,
4196,
297,
283,
3049,
28539,
358,
272,
1865,
63,
3200,
63,
1345,
275,
664,
63,
533,
360,
9743,
14,
14387,
14,
4196,
297,
283,
4738,
8257,
2768,
358,
339,
347,
664,
63,
3603,
8,
277,
304,
267,
8187,
275,
359,
288,
1166,
8,
82,
4289,
4268,
291,
14,
1648,
63,
513,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
1648,
13,
513,
659,
288,
1166,
8,
82,
4289,
13724,
10884,
291,
14,
1648,
63,
3200,
63,
1345,
14,
305,
63,
1345,
1062,
355,
536,
534,
1648,
13,
3200,
659,
288,
1166,
8,
82,
24550,
48,
28,
1955,
30,
1988,
60,
87,
24598,
4268,
355,
291,
14,
1648,
63,
5506,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
1648,
13,
5506,
659,
288,
1166,
8,
82,
24550,
48,
28,
1955,
30,
1988,
60,
87,
24598,
5983,
9448,
48,
28,
4610,
63,
344,
3072,
68,
18830,
4268,
355,
291,
14,
1648,
63,
5506,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
1648,
13,
5506,
13,
4610,
659,
288,
1166,
8,
82,
24550,
48,
28,
1955,
30,
1988,
60,
87,
24598,
1278,
9448,
48,
28,
604,
63,
344,
3072,
68,
18830,
4268,
355,
291,
14,
604,
63,
5506,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
1648,
13,
604,
13,
5506,
659,
288,
1166,
8,
82,
24550,
48,
28,
1955,
30,
1988,
60,
87,
24598,
17801,
13,
1562,
10884,
355,
291,
14,
17801,
63,
1562,
63,
1345,
14,
305,
63,
1345,
1062,
355,
536,
534,
1648,
13,
17801,
13,
1562,
659,
267,
1622,
267,
372,
291,
14,
1932,
63,
1412,
63,
3603,
8,
3603,
9,
421,
199,
3578,
275,
4236,
7735,
30122,
5039,
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,
32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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
windelbouwman/ppci-mirror
|
tools/compile_libmad.py
|
1
|
2909
|
""" Helper script to build libmad
Version: libmad-0.15.1b
Usage:
- Download the libmad sourcecode.
- Unzip the sourcecode
- Set the environment variable LIBMAD_FOLDER to the unzipped dir
- Run this script
"""
import sys
import os
import logging
import time
try:
from powertb import print_exc
except ImportError:
from traceback import print_exc
from ppci.api import cc, link
from ppci.lang.c import COptions
from ppci.common import CompilerError, logformat
from ppci.utils.reporting import HtmlReportGenerator
def do_compile(filename, include_paths, arch, reporter):
coptions = COptions()
coptions.add_include_paths(include_paths)
coptions.add_define("FPM_DEFAULT", "1")
with open(filename, "r") as f:
obj = cc(f, arch, coptions=coptions, reporter=reporter)
return obj
def main():
environment_variable = "LIBMAD_FOLDER"
if environment_variable in os.environ:
libmad_folder = os.environ[environment_variable]
else:
logging.error(
"Please define %s to point to the libmad source folder",
environment_variable,
)
return
this_dir = os.path.abspath(os.path.dirname(__file__))
report_filename = os.path.join(this_dir, "report_libmad.html")
libc_includes = os.path.join(this_dir, "..", "librt", "libc")
include_paths = [libc_includes, libmad_folder]
arch = "x86_64"
t1 = time.time()
failed = 0
passed = 0
sources = [
"layer3.c",
"version.c",
"fixed.c",
"bit.c",
"timer.c",
"stream.c",
"frame.c",
"synth.c",
"decoder.c",
"layer12.c",
"huffman.c",
]
objs = []
with open(report_filename, "w") as f, HtmlReportGenerator(f) as reporter:
for filename in sources:
filename = os.path.join(libmad_folder, filename)
print(" ======================")
print(" ========================")
print(" ==> Compiling", filename)
try:
obj = do_compile(filename, include_paths, arch, reporter)
objs.append(obj)
except CompilerError as ex:
print("Error:", ex.msg, ex.loc)
ex.print()
print_exc()
failed += 1
# except Exception as ex:
# print("General exception:", ex)
# print_exc()
# failed += 1
else:
print("Great success!")
passed += 1
t2 = time.time()
elapsed = t2 - t1
print("Passed:", passed, "failed:", failed, "in", elapsed, "seconds")
obj = link(objs)
print(obj)
if __name__ == "__main__":
verbose = "-v" in sys.argv
if verbose:
level = logging.DEBUG
else:
level = logging.INFO
logging.basicConfig(level=level, format=logformat)
main()
|
bsd-2-clause
|
[
624,
11642,
2884,
370,
1900,
1973,
77,
350,
199,
199,
3353,
26,
1973,
77,
350,
13,
16,
14,
1046,
14,
17,
66,
199,
199,
7692,
26,
199,
199,
13,
17955,
314,
1973,
77,
350,
25468,
14,
199,
13,
1910,
3065,
314,
25468,
199,
13,
2494,
314,
3734,
1750,
25764,
45,
1554,
63,
19041,
370,
314,
29379,
1915,
2935,
199,
13,
3378,
642,
2884,
199,
199,
624,
199,
199,
646,
984,
199,
646,
747,
199,
646,
2050,
199,
646,
900,
199,
199,
893,
26,
272,
687,
7074,
5842,
492,
870,
63,
2804,
199,
2590,
3545,
26,
272,
687,
5190,
492,
870,
63,
2804,
199,
199,
504,
11618,
559,
14,
1246,
492,
7429,
12,
2142,
199,
504,
11618,
559,
14,
4159,
14,
67,
492,
445,
4558,
199,
504,
11618,
559,
14,
2330,
492,
27154,
547,
12,
943,
908,
199,
504,
11618,
559,
14,
1208,
14,
28071,
492,
20880,
7457,
7599,
421,
199,
318,
886,
63,
2014,
8,
1501,
12,
2387,
63,
3771,
12,
3819,
12,
17663,
304,
272,
286,
1419,
275,
445,
4558,
342,
272,
286,
1419,
14,
525,
63,
2613,
63,
3771,
8,
2613,
63,
3771,
9,
272,
286,
1419,
14,
525,
63,
4640,
480,
38,
10793,
63,
3472,
401,
298,
17,
531,
272,
543,
1551,
8,
1501,
12,
298,
82,
531,
465,
289,
26,
267,
1559,
275,
7429,
8,
70,
12,
3819,
12,
286,
1419,
29,
331,
494,
83,
12,
17663,
29,
12222,
9,
272,
372,
1559,
421,
199,
318,
2446,
837,
272,
3734,
63,
1975,
275,
298,
5617,
45,
1554,
63,
19041,
2,
272,
340,
3734,
63,
1975,
315,
747,
14,
2314,
26,
267,
1973,
77,
350,
63,
3741,
275,
747,
14,
2314,
59,
5418,
63,
1975,
61,
272,
587,
26,
267,
2050,
14,
705,
8,
288,
298,
8254,
5627,
450,
83,
370,
2376,
370,
314,
1973,
77,
350,
1350,
4922,
401,
288,
3734,
63,
1975,
12,
267,
776,
267,
372,
339,
642,
63,
694,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
272,
3622,
63,
1501,
275,
747,
14,
515,
14,
904,
8,
3749,
63,
694,
12,
298,
3070,
63,
773,
77,
350,
14,
1360,
531,
272,
1973,
67,
63,
9441,
275,
747,
14,
515,
14,
904,
8,
3749,
63,
694,
12,
21777,
401,
298,
773,
2591,
401,
298,
20217,
531,
272,
2387,
63,
3771,
275,
359,
20217,
63,
9441,
12,
1973,
77,
350,
63,
3741,
61,
272,
3819,
275,
298,
88,
1184,
63,
772,
2,
339,
307,
17,
275,
900,
14,
521,
342,
272,
3405,
275,
378,
272,
3032,
275,
378,
272,
5274,
275,
359,
267,
298,
1897,
19,
14,
67,
401,
267,
298,
1023,
14,
67,
401,
267,
298,
5964,
14,
67,
401,
267,
298,
2075,
14,
67,
401,
267,
298,
7414,
14,
67,
401,
267,
298,
1745,
14,
67,
401,
267,
298,
1943,
14,
67,
401,
267,
298,
9466,
273,
14,
67,
401,
267,
298,
8813,
14,
67,
401,
267,
298,
1897,
713,
14,
67,
401,
267,
298,
72,
3043,
1237,
14,
67,
401,
272,
1622,
272,
13474,
275,
942,
272,
543,
1551,
8,
3070,
63,
1501,
12,
298,
87,
531,
465,
289,
12,
20880,
7457,
7599,
8,
70,
9,
465,
17663,
26,
267,
367,
1788,
315,
5274,
26,
288,
1788,
275,
747,
14,
515,
14,
904,
8,
773,
77,
350,
63,
3741,
12,
1788,
9,
288,
870,
480,
420,
16248,
19989,
531,
288,
870,
480,
259,
16248,
18673,
531,
288,
870,
480,
221,
25375,
3599,
5662,
401,
1788,
9,
288,
862,
26,
355,
1559,
275,
886,
63,
2014,
8,
1501,
12,
2387,
63,
3771,
12,
3819,
12,
17663,
9,
355,
13474,
14,
740,
8,
1113,
9,
288,
871,
27154,
547,
465,
444,
26,
355,
870,
480,
547,
6783,
444,
14,
1328,
12,
444,
14,
2102,
9,
355,
444,
14,
1361,
342,
355,
870,
63,
2804,
342,
355,
3405,
847,
413,
288,
327,
871,
2186,
465,
444,
26,
288,
327,
259,
870,
480,
14109,
1919,
6783,
444,
9,
288,
327,
259,
870,
63,
2804,
342,
288,
327,
259,
3405,
847,
413,
288,
587,
26,
355,
870,
480,
39,
8319,
3182,
9124,
355,
3032,
847,
413,
339,
307,
18,
275,
900,
14,
521,
342,
272,
14439,
275,
307,
18,
446,
307,
17,
272,
870,
480,
48,
2744,
6783,
3032,
12,
298,
4892,
6783,
3405,
12,
298,
262,
401,
14439,
12,
298,
4515,
531,
272,
1559,
275,
2142,
8,
8718,
9,
272,
870,
8,
1113,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
3376,
275,
3905,
86,
2,
315,
984,
14,
3020,
272,
340,
3376,
26,
267,
2166,
275,
2050,
14,
5287,
272,
587,
26,
267,
2166,
275,
2050,
14,
4531,
272,
2050,
14,
19602,
8,
1896,
29,
1896,
12,
1475,
29,
793,
908,
9,
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
] |
[
11642,
2884,
370,
1900,
1973,
77,
350,
199,
199,
3353,
26,
1973,
77,
350,
13,
16,
14,
1046,
14,
17,
66,
199,
199,
7692,
26,
199,
199,
13,
17955,
314,
1973,
77,
350,
25468,
14,
199,
13,
1910,
3065,
314,
25468,
199,
13,
2494,
314,
3734,
1750,
25764,
45,
1554,
63,
19041,
370,
314,
29379,
1915,
2935,
199,
13,
3378,
642,
2884,
199,
199,
624,
199,
199,
646,
984,
199,
646,
747,
199,
646,
2050,
199,
646,
900,
199,
199,
893,
26,
272,
687,
7074,
5842,
492,
870,
63,
2804,
199,
2590,
3545,
26,
272,
687,
5190,
492,
870,
63,
2804,
199,
199,
504,
11618,
559,
14,
1246,
492,
7429,
12,
2142,
199,
504,
11618,
559,
14,
4159,
14,
67,
492,
445,
4558,
199,
504,
11618,
559,
14,
2330,
492,
27154,
547,
12,
943,
908,
199,
504,
11618,
559,
14,
1208,
14,
28071,
492,
20880,
7457,
7599,
421,
199,
318,
886,
63,
2014,
8,
1501,
12,
2387,
63,
3771,
12,
3819,
12,
17663,
304,
272,
286,
1419,
275,
445,
4558,
342,
272,
286,
1419,
14,
525,
63,
2613,
63,
3771,
8,
2613,
63,
3771,
9,
272,
286,
1419,
14,
525,
63,
4640,
480,
38,
10793,
63,
3472,
401,
298,
17,
531,
272,
543,
1551,
8,
1501,
12,
298,
82,
531,
465,
289,
26,
267,
1559,
275,
7429,
8,
70,
12,
3819,
12,
286,
1419,
29,
331,
494,
83,
12,
17663,
29,
12222,
9,
272,
372,
1559,
421,
199,
318,
2446,
837,
272,
3734,
63,
1975,
275,
298,
5617,
45,
1554,
63,
19041,
2,
272,
340,
3734,
63,
1975,
315,
747,
14,
2314,
26,
267,
1973,
77,
350,
63,
3741,
275,
747,
14,
2314,
59,
5418,
63,
1975,
61,
272,
587,
26,
267,
2050,
14,
705,
8,
288,
298,
8254,
5627,
450,
83,
370,
2376,
370,
314,
1973,
77,
350,
1350,
4922,
401,
288,
3734,
63,
1975,
12,
267,
776,
267,
372,
339,
642,
63,
694,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
272,
3622,
63,
1501,
275,
747,
14,
515,
14,
904,
8,
3749,
63,
694,
12,
298,
3070,
63,
773,
77,
350,
14,
1360,
531,
272,
1973,
67,
63,
9441,
275,
747,
14,
515,
14,
904,
8,
3749,
63,
694,
12,
21777,
401,
298,
773,
2591,
401,
298,
20217,
531,
272,
2387,
63,
3771,
275,
359,
20217,
63,
9441,
12,
1973,
77,
350,
63,
3741,
61,
272,
3819,
275,
298,
88,
1184,
63,
772,
2,
339,
307,
17,
275,
900,
14,
521,
342,
272,
3405,
275,
378,
272,
3032,
275,
378,
272,
5274,
275,
359,
267,
298,
1897,
19,
14,
67,
401,
267,
298,
1023,
14,
67,
401,
267,
298,
5964,
14,
67,
401,
267,
298,
2075,
14,
67,
401,
267,
298,
7414,
14,
67,
401,
267,
298,
1745,
14,
67,
401,
267,
298,
1943,
14,
67,
401,
267,
298,
9466,
273,
14,
67,
401,
267,
298,
8813,
14,
67,
401,
267,
298,
1897,
713,
14,
67,
401,
267,
298,
72,
3043,
1237,
14,
67,
401,
272,
1622,
272,
13474,
275,
942,
272,
543,
1551,
8,
3070,
63,
1501,
12,
298,
87,
531,
465,
289,
12,
20880,
7457,
7599,
8,
70,
9,
465,
17663,
26,
267,
367,
1788,
315,
5274,
26,
288,
1788,
275,
747,
14,
515,
14,
904,
8,
773,
77,
350,
63,
3741,
12,
1788,
9,
288,
870,
480,
420,
16248,
19989,
531,
288,
870,
480,
259,
16248,
18673,
531,
288,
870,
480,
221,
25375,
3599,
5662,
401,
1788,
9,
288,
862,
26,
355,
1559,
275,
886,
63,
2014,
8,
1501,
12,
2387,
63,
3771,
12,
3819,
12,
17663,
9,
355,
13474,
14,
740,
8,
1113,
9,
288,
871,
27154,
547,
465,
444,
26,
355,
870,
480,
547,
6783,
444,
14,
1328,
12,
444,
14,
2102,
9,
355,
444,
14,
1361,
342,
355,
870,
63,
2804,
342,
355,
3405,
847,
413,
288,
327,
871,
2186,
465,
444,
26,
288,
327,
259,
870,
480,
14109,
1919,
6783,
444,
9,
288,
327,
259,
870,
63,
2804,
342,
288,
327,
259,
3405,
847,
413,
288,
587,
26,
355,
870,
480,
39,
8319,
3182,
9124,
355,
3032,
847,
413,
339,
307,
18,
275,
900,
14,
521,
342,
272,
14439,
275,
307,
18,
446,
307,
17,
272,
870,
480,
48,
2744,
6783,
3032,
12,
298,
4892,
6783,
3405,
12,
298,
262,
401,
14439,
12,
298,
4515,
531,
272,
1559,
275,
2142,
8,
8718,
9,
272,
870,
8,
1113,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
3376,
275,
3905,
86,
2,
315,
984,
14,
3020,
272,
340,
3376,
26,
267,
2166,
275,
2050,
14,
5287,
272,
587,
26,
267,
2166,
275,
2050,
14,
4531,
272,
2050,
14,
19602,
8,
1896,
29,
1896,
12,
1475,
29,
793,
908,
9,
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,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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
] |
aaryani/CoreTardis
|
tardis/apps/hpctardis/metadata.py
|
3
|
42999
|
# -*- coding: utf-8 -*-
#
# Copyright (c) 2011-2012, RMIT e-Research Office
# (RMIT University, Australia)
# Copyright (c) 2010-2011, Monash e-Research Centre
# (Monash University, Australia)
# 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 RMIT, the RMIT members, 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 REGENTS 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 REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
"""
metadata.py
.. moduleauthor:: Ian Thomas <Ian.Edward.Thomas@rmit.edu.au>
"""
from os import path
import re
import itertools
import logging
from django.conf import settings
from django.core.management.base import BaseCommand
from tardis.tardis_portal.models import Dataset_File
from tardis.tardis_portal.models import Dataset
from tardis.tardis_portal.models import DatafileParameter
from tardis.tardis_portal.models import DatafileParameterSet
from tardis.tardis_portal.models import ParameterName
from tardis.tardis_portal.models import Schema
from tardis.tardis_portal.models import DatasetParameter
from tardis.tardis_portal.models import DatasetParameterSet
from tardis.tardis_portal.models import Experiment
logger = logging.getLogger(__name__)
number = "[+-]?((\d+)(\.\d*)?)|(\d+\.\d+)([eE][+-]?[0-9]+)?"
rulesets = {
#: This ruleset will produce a Schema entry called "general 1.0" in the namespace
#: 'http://tardis.edu.au/schemas/general/1'
('http://tardis.edu.au/schemas/general/1','general 1.0'):
# This rule matches any files matching metadata\..* filenames and will extract
# to a parmeter called project.
(('Project',("metadata\..*$",),
# call the get_file_regex function, which returns back (value,unit) tuple.
# get_file_regex function finds first line of file that has Project followed
# by arbitrary characters. These characters are matched into value group
# and unit group is empty in this case.
"get_file_regex(context,'Project~\s+(?P<value>.+)(?P<unit>)',False)"),
# This rule matches HPC output files which have a dot followed by o in them
('Number Of CPUs',("^.*[_0-9]*\.o(\d+)$",),
"get_file_regex(context,'Number of cpus:\s+(?P<value>.+)(?P<unit>)',True)"),
('Maximum virtual memory',("^.*[_0-9]*\.o(\d+)$",),
"get_file_regex(context,'Max virtual memory:\s+(?P<value>[0-9]+)(?P<unit>(M|G|K)B)',True)"),
('Max jobfs disk use',("^.*[_0-9]*\.o(\d+)$",),
"get_file_regex(context,'Max jobfs disk use:\s+(?P<value>.*)(?P<unit>(M|G|K)B)',True)"),
('Walltime',("^.*[_0-9]*\.o(\d+)$",),
# True below indicates that if multiple files in dataset match file regex, then choose
# the one of the largest value in filename suffix number
"get_file_regex(context,'Elapsed time:\s+(?P<value>[\w:]+)(?P<unit>)',True)")
),
# This schema captures specific information for VASP output
('http://tardis.edu.au/schemas/vasp/1','vasp 1.0'):
# The presense of KPOINTS files in dataset triggers creaton of this schema. Note
# That if tardis ingests the same file multiple times, it adds number prefix
# as above, so all patterns should account for this in the regex.
(('kpoint_grid',("KPOINTS[_0-9]*",),
# slurp the KPOINT file, then get the relative linenumber
"get_file_line(context,-3)"),
('kpoint_grid_offset',("KPOINTS[_0-9]*",),
"get_file_line(context,-2)"),
# TODO: remove number as can cause bad matches
('ENCUT',("OUTCAR[_0-9]*",),
"get_file_regex(context,'\s+ENCUT\s*=\s*(?P<value>%s)\s+(?P<unit>eV)',False)" % number),
('NIONS',("OUTCAR[_0-9]*",),
"get_file_regex(context,'\s+NIONS\s*\=\s*(?P<value>%s)(?P<unit>)',False)" % number),
('NELECT',("OUTCAR[_0-9]*",),
"get_file_regex(context,'\s+NELECT\s*\=\s*(?P<value>%s)\s+(?P<unit>.*)$',False)" % number),
('ISIF',("OUTCAR[_0-9]*",),
"get_file_regex(context,'\s+ISIF\s+\=\s+(?P<value>%s)\s+(?P<unit>.*)$',False)" % number),
('ISPIN',("OUTCAR[0-9]*",),
"get_file_regex(context,'\s+ISPIN\s+\=\s+(?P<value>%s)\s+(?P<unit>.*)$',False)" % number),
('NSW',("OUTCAR[_0-9]*",),
"get_file_regex(context,'NSW\s*\=\s*(?P<value>%s)\s*(?P<unit>.*)$',False)" % number),
('IBRION',("OUTCAR[_0-9]*",),
"get_file_regex(context,'IBRION\s*\=\s*(?P<value>%s)\s+(?P<unit>.*)$',False)" % number),
('ISMEAR',("OUTCAR[_0-9]*",),
"get_file_regex(context,'ISMEAR\s*\=\s*(?P<value>%s)(?P<unit>)',False)" % number),
('POTIM',("OUTCAR[_0-9]*",),
"get_file_regex(context,'POTIM\s*\=\s*(?P<value>%s)(?P<unit>)',False)" % number),
#('MAGMOM',("POSCAR[_0-9]*",),
#"get_file_lines(context,1,4)"),
('Descriptor Line',("INCAR[_0-9]*",),
"get_file_regex(context,'System = (?P<value>.*)(?P<unit>)',False)"),
('EDIFF',("OUTCAR[_0-9]*",),
"get_file_regex(context,'EDIFF\s*\=\s*(?P<value>[^\s]+)(?P<unit>)',False)"),
('EDIFFG',("OUTCAR[_0-9]*",),
"get_file_regex(context,'EDIFFG\s*\=\s*(?P<value>[^\s]+)(?P<unit>)',False)"),
('NELM',("OUTCAR[_0-9]*",),
"get_file_regex(context,'NELM\s*\=\s*(?P<value>[^;\s]+)(?P<unit>)',False)"),
('ISTART',("INCAR[_0-9]*",),
"get_file_regex(context,'ISTART\s*\=\s*(?P<value>[^;\s]+)(?P<unit>)',False)"),
('TEBEG',("OUTCAR[_0-9]*",),
"get_file_regex(context,'TEBEG\s*\=\s*(?P<value>[^;\s]+)(?P<unit>)',False)"),
('TEEND',("OUTCAR[_0-9]*",),
"get_file_regex(context,'TEEND\s*\=\s*(?P<value>[^;\s]+)(?P<unit>.*)',False)"),
('SMASS',("OUTCAR[_0-9]*",),
"get_file_regex(context,'SMASS\s*\=\s*(?P<value>[^\s]+)(?P<unit>.*)',False)"),
('Final Iteration',("OSZICAR[_0-9]*",),
"get_final_iteration(context)"),
('TITEL',("OUTCAR[_0-9]*",),
# find all lines which match regex and into multiline string
"('\\n '.join(get_file_regex_all(context,'TITEL\s+\=\s+(?P<value>.*)$')),'')"),
('LEXCH',("OUTCAR[_0-9]*",),
"('\\n '.join(get_file_regex_all(context,'LEXCH\s+\=\s+(?P<value>[^\s]+)')),'')"),
('Cell Scaling',("POSCAR[_0-9]*",),
"get_file_line(context,1)"),
('Cell Parameter1',("POSCAR[_0-9]*",),
"get_file_line(context,2)"),
('Cell Parameter2',("POSCAR[_0-9]*",),
"get_file_line(context,3)"),
('Cell Parameter3',("POSCAR[_0-9]*",),
"get_file_line(context,4)")
),
('http://tardis.edu.au/schemas/siesta/1','siesta 1.0'):
(('SystemName',("input[_0-9]*\.fdf",),
"get_file_regex(context,'SystemName\s+(?P<value>.*)(?P<unit>)',False)"),
('MeshCutoff',("input[_0-9]*\.fdf",),
"get_file_regex(context,'MeshCutoff\s+(?P<value>[^\s]+)(?P<unit>.*)',False)"),
('ElectronicTemperature',("input[_0-9]*\.fdf",),
"get_file_regex(context,'ElectronicTemperature\s+(?P<value>[^\s]+)(?P<unit>.*)',False)"),
#('k-grid',("input\.fdf",),
# "get_regex_lines(context,'\%block k_grid_Monkhorst_Pack','\%endblock k_grid_Monkhorst_Pack')"),
('k-grid',("input[_0-9]*\.fdf",),
"get_regex_lines(context,'\%block kgridMonkhorstPack','\%endblock kgridMonkhorstPack')"),
('PAO.Basis',("input[_0-9]*\.fdf",),
# return all lines between the first and second regex
"get_regex_lines(context,'\%block PAO.Basis','\%endblock PAO.Basis')"),
('MD.TypeOfRun',('input[_0-9]*\.fdf',),
"get_file_regex(context,'(?<!\#)MD\.TypeOfRun\s+(?P<value>.*)(?P<unit>)',False)"),
('MD.NumCGsteps',('input[_0-9]*\.fdf',),
"get_file_regex(context,'(?<!\#)MD\.NumCGsteps\s+(?P<value>[^\s]+)(?P<unit>)',False)"),
('iscf',('output[_0-9]*',),
"(get_regex_lines_vallist(context,'siesta\:\siscf','^$')[-1],'')"),
('E_KS',('output[_0-9]*',),
"get_file_regex(context,'^siesta:\s+E\_KS\(eV\)\s+\=\s+(?P<value>.*)(?P<unit>)',False)"),
('Occupation Function',('input[_0-9]*\.fdf',),
"get_file_regex(context,'(?<!\#)OccupationFunction\s+(?P<value>.*)(?P<unit>)',False)"),
('OccupationMPOrder',('input[_0-9]*\.fdf',),
"get_file_regex(context,'(?<!\#)OccupationMPOrder\s+(?P<value>.*)(?P<unit>)',False)"),
('MD.MaxForceTol',('input[_0-9]*\.fdf',),
"get_file_regex(context,'(?<!\#)MD\.MaxForceTol\s+(?P<value>[^\s]+)\s+(?P<unit>.*)',False)")
),
('http://tardis.edu.au/schemas/gulp/1','gulp 1.0'):
(('Run Type',("optiexample[_0-9]*\.gin",),
"(get_file_line(context,0)[0].split(' ')[0],'')"),
('Run Keyword',("optiexample[_0-9]*\.gin",),
"(' '.join(get_file_line(context,0)[0].split(' ')[1:]).rstrip(),'')"),
('Library',("optiexample[_0-9]*\.gin",),
"(get_file_regex(context,'(?<!\#)library\s+(?P<value>.*)(?P<unit>)',False)[0].rstrip(),'')"),
('CoordinateFile',("optiexample[_0-9]*\.gin",),
# This is just python: get two matching strings, reverse them and joint into string with dot between.
"('.'.join(get_file_regex(context,'(?<!\#)output\s+(?P<value>\S+)\s+(?P<unit>\S+)',False)[::-1]),'')"),
('Formula',("optiexample[_0-9]*\.gout",),
# strip may be needed to remove leading newlines from strings
"(get_file_regex(context,'(?<!\#)\s*Formula\s+\=\s+(?P<value>.*)(?P<unit>)',False)[0].strip(),'')"),
('Total number atoms/shell',("optiexample[_0-9]*\.gout",),
"(get_file_regex(context,'(?<!\#)\s*Total number atoms\/shells\s+\=\s+(?P<value>.*)(?P<unit>)',False)[0].strip(),'')")
),
('http://tardis.edu.au/schemas/gulp/2','gulp2 1.0'):
(('Run Type',("mdexample[_0-9]*\.gin",),
"(get_file_regex(context,'(?<!#)(?P<value>\w+)\s+(?P<unit>\w+)',False)[0],'')"),
('Run Keyword',("mdexample[_0-9]*\.gin",),
"(' '.join(get_file_regex(context,'(?<!#)(?P<value>\w+)\s+(?P<unit>\w+)',False)[1:]).rstrip(),'')"),
('Library',("mdexample[_0-9]*\.gin",),
"(get_file_regex(context,'(?<!\#)library\s+(?P<value>.*)(?P<unit>)',False)[0].rstrip(),'')"),
('Formula',("mdexample[_0-9]*\.gout",),
"(get_file_regex(context,'(?<!\#)\s*Formula\s+\=\s+(?P<value>.*)(?P<unit>)',False)[0].strip(),'')")
),
('http://tardis.edu.au/schemas/crystal/1','crystal 1.0'):
(('Experiment name',("INPUT[_0-9]*",),
"get_file_line(context,0)"),
('Calculation type',("INPUT[_0-9]*",),
"get_file_line(context,1)"),
('Space/layer/rod/point group',("INPUT[_0-9]*",),
"get_file_line(context,3) if (get_file_line(context,1)[0].strip() == 'CRYSTAL') else get_file_line(context,2)"),
('Lattice parameter',("INPUT[_0-9]*",),
"get_file_line(context,4) if (get_file_line(context,1)[0].strip() == 'CRYSTAL') else get_file_line(context,3)"),
('SLABCUT',("INPUT[_0-9]*",),
"('yes','') if (get_file_regex(context,'^(?P<value>SLABCUT)(?P<unit>)',False)[0].strip() == 'SLABCUT') else ('no','')"),
('OPTGEOM',("INPUT[_0-9]*",),
"('yes','') if (get_file_regex(context,'^(?P<value>OPTGEOM)(?P<unit>)',False)[0].strip() == 'OPTGEOM') else ('no','')"),
('TESTGEOM',("INPUT[_0-9]*",),
"('yes','') if (get_file_regex(context,'^(?P<value>TESTGEOM)(?P<unit>)',False)[0].strip() == 'TESTGEOM') else ('no','')"),
('UHF',("INPUT[_0-9]*",),
"('yes','') if (get_file_regex(context,'^(?P<value>UHF)(?P<unit>)',False)[0].strip() == 'UHF') else ('no','')"),
('DFT',("INPUT[_0-9]*",),
"('yes','') if (get_file_regex(context,'^(?P<value>DFT)(?P<unit>)',False)[0].strip() == 'DFT') else ('no','')"),
('SHRINK',("INPUT[_0-9]*",),
"(get_file_regex(context,'^(?P<value>SHRINK)(?P<unit>)',False,nextline=True)[0].strip(),'')"),
('MAXCYCLE',("INPUT[_0-9]*",),
"(get_file_regex(context,'^(?P<value>MAXCYCLE)(?P<unit>)',False,nextline=True)[0].strip(),'')"),
('FMIXING',("INPUT[_0-9]*",),
"(get_file_regex(context,'^(?P<value>FMIXING)(?P<unit>)',False,nextline=True)[0].strip(),'')"),
('BROYDEN',("INPUT[_0-9]*",),
"(get_file_regex(context,'^(?P<value>BROYDEN)(?P<unit>)',False,nextline=True)[0].strip(),'')")
),
('http://tardis.edu.au/schemas/test/1',''):
(('Test',("R-2-2.tif",),
"get_constant(context,'99','foobars')"),
('Test2',("R-2-2.tif","R-2-5.tif"),
"get_constant(context,'hello','')")
)
}
def _get_file_handle(context, filename):
datafile = context['ready'][filename]
url = datafile.get_download_url()
file_handle = None
if datafile.protocol == 'tardis' or datafile.url.startswith('tardis'):
raw_path = url.partition('//')[2]
file_path = path.join(settings.FILE_STORE_PATH,
str(context['expid']),
str(datafile.dataset.id),
raw_path,datafile.url.partition('//')[2])
logger.debug("file_path=%s" % file_path)
file_handle = open(file_path,"r")
return file_handle
def get_final_iteration(context):
""" Returns the final iteration number from a VASP run
:param context: package of parameter data
:returns: value unit tuple
"""
fileregex = context['fileregex'][0]
filename = _get_file_from_regex(fileregex,context['ready'],False)
logger.debug("filename=%s" % filename)
if not filename or filename not in context['ready']:
logger.debug("found None")
return ("","")
else:
logger.debug("found ready %s" % filename)
try:
fp = _get_file_handle(context, filename)
except Exception:
return ("","")
if fp:
regex = "RMM\:\s*(?P<value>\d+)\s*"
regx = re.compile(regex)
max_value = 0
for line in fp:
logger.debug("line=%s" % line)
match = regx.search(line)
if match:
val = match.group('value')
try:
value = int(val)
except ValueError:
value = 0
logger.debug("value=%s" % value)
if value > max_value:
max_value = value
fp.close()
logger.debug("max_value = %s" % max_value)
return (str(max_value),"")
else:
return ("","")
def _get_file_from_regex(regex,context, return_max):
"""Returns the single key from ready dict which matches the regex.
If return_max, then only use file which the largest group match in regex
"""
regx = re.compile(regex)
logger.debug("return_max=%s" % return_max)
key = None
max_match = ""
max_value = 0
logger.debug("regex=%s" % regex)
for key in dict(context):
logger.debug("key=%s" % key)
match = regx.match(key)
logger.debug("match=%s" % match)
if return_max:
logger.debug("return_max")
if match:
logger.debug("match=%s" % match)
matched_groups = match.groups()
if matched_groups:
if len(matched_groups) == 1:
if matched_groups[0] > max_value:
max_match = key
max_value=matched_groups[0]
else:
if match:
logger.debug("matched to %s" % str(match.group(0)))
return match.group(0)
logger.debug("max_match=%s" % max_match)
return max_match
def get_file_lines(context, linestart,lineend):
""" Returns the content of file in the line range.
Returns no unit value and only works for smallish local files
:param context: package of parameter data
:param linestart: the begin of the range of lines to extract
:param lineend: the end of the range of lines to extract
:returns: value unit tuple, where value is newline separated string
"""
# match fileregex to available files
#regx = re.compile(fileregex)
#filename = None
#for key in context['ready']:
# match = regx.match(key)
# if match:
# filename = key
# break
fileregex = context['fileregex'][0]
filename = _get_file_from_regex(fileregex,context['ready'],False)
if filename not in context['ready']:
return (None,'')
else:
try:
fp = _get_file_handle(context, filename)
except Exception:
return ('','')
if fp:
res = []
for i,line in enumerate(fp):
if i in range(linestart,lineend):
res.append(line)
return ("\n".join(res),'')
return ('','')
def get_file_line(context,lineno):
""" Returns the content of relative linenumber.
Assumes no unit value and only works for smallish files
:param context: package of parameter data
:param lineno: the line number of the file to extract
:returns: value unit tuple
"""
# match fileregex to available files
#regx = re.compile(fileregex)
#filename = None
#for key in context['ready']:
#match = regx.match(key)
#if match:
#filename = key
#break
fileregex = context['fileregex'][0]
filename = _get_file_from_regex(fileregex,context['ready'],False)
if filename not in context['ready']:
return (None,'')
else:
try:
fp = _get_file_handle(context, filename)
except Exception:
return ("","")
if fp:
line_list = fp.readlines()
fp.close()
logger.debug(line_list)
return (str(line_list[lineno]),'')
return ('','')
def get_regex_lines(context, startregex,endregex):
""" Returns the file content of lines that match between two matching
regular expressions.
Returns blank unit value and only works for smallish files
:param context: package of parameter data
:param startregex: starting regex for extraction
:param endregex: ending regex for extraction
:returns: value unit tuple
"""
fileregex = context['fileregex'][0]
filename = _get_file_from_regex(fileregex,context['ready'],False)
if not filename or filename not in context['ready']:
logger.debug("found None")
return ('','')
else:
try:
fp = _get_file_handle(context, filename)
except Exception:
return ('','')
if fp:
startreg = re.compile(startregex)
endreg = re.compile(endregex)
res = []
in_region = False
for line in fp:
start_match = startreg.search(line)
end_match = endreg.search(line)
if start_match:
in_region = True
continue
if end_match:
in_region = False
continue
if in_region:
res.append(line)
fp.close()
return ("".join(res),'')
def get_regex_lines_vallist(context, startregex,endregex):
""" Returns the file content of lines that match between two matching
regular expressions as a list of lines
:param context: package of parameter data
:param startregex: starting regex for extraction
:param endregex: ending regex for extraction
:returns: list of strings
"""
fileregex = context['fileregex'][0]
filename = _get_file_from_regex(fileregex,context['ready'],False)
if not filename or filename not in context['ready']:
logger.debug("found None")
return ['']
else:
try:
fp = _get_file_handle(context, filename)
except Exception:
return ['']
if fp:
startreg = re.compile(startregex)
endreg = re.compile(endregex)
res = []
in_region = False
for line in fp:
start_match = startreg.search(line)
end_match = endreg.search(line)
if start_match:
in_region = True
continue
if end_match:
in_region = False
continue
if in_region:
res.append(line)
fp.close()
return res
def get_file_regex(context,regex,return_max,**kwargs):
""" Returns the content of the file that matches regex as value, unit pair
:param context: package of parameter data
:param regex: regex with named groups value and unit
:param return_max: if true, context filename regex must contain single group. If multiple files match this group, then only one with largest numeric is used.
:param kwargs: if 'nextline' in kwargs and true then return whole line after matching regex
:returns: value unit tuple
"""
# match fileregex to available files
#regx = re.compile(fileregex)
#filename = None
#for key in context['ready']:
# match = regx.match(key)
# if match:
# filename = key
# break
# FIXME: only handles single file pattern
fileregex = context['fileregex'][0]
filename = _get_file_from_regex(fileregex,context['ready'],return_max)
if not filename or filename not in context['ready']:
logger.debug("found None")
return ('','')
else:
try:
fp = _get_file_handle(context, filename)
except Exception,e:
logger.error("problem with filehandle %s" % e)
return ('','')
if fp:
regx = re.compile(regex)
for line in fp:
match = regx.search(line)
if match:
value = match.group('value')
unit = str(match.group('unit'))
if not unit:
unit = ''
logger.debug("value=%s unit=%s" % (value,unit))
if 'nextline' in kwargs and kwargs['nextline']:
next_line = fp.next()
res = (next_line, '')
fp.close()
return res
else:
fp.close()
res = (value,unit)
for g in res:
logger.debug("final matched %s" % g)
return res
else:
logger.debug("no filehandle")
fp.close()
return ('','')
def get_file_regex_all(context,regex):
""" Returns the content of the file that matches regex as a list of
value, unit pairs
:param context: package of parameter data
:param regex: regex with named groups value and unit
:returns: list of <value,unit> tuples
"""
# match fileregex to available files
#regx = re.compile(fileregex)
#filename = None
#for key in context['ready']:
# match = regx.match(key)
# if match:
# filename = key
# break
# FIXME: only handles single file pattern
logger.debug("get_file_regex_all")
fileregex = context['fileregex'][0]
logger.debug("fileregex=%s" % fileregex)
filename = _get_file_from_regex(fileregex,context['ready'],False)
logger.debug("filename=%s" % filename)
final_res = []
if not filename or filename not in context['ready']:
logger.debug("found None")
return []
else:
try:
fp = _get_file_handle(context, filename)
except Exception:
logger.error("bad file handle")
return []
if fp:
regx = re.compile(regex)
for line in fp:
match = regx.search(line)
if match:
value = match.group('value')
logger.debug("value=%s" % value)
final_res.append(value.rstrip())
fp.close()
logger.debug("final_res=%s" % final_res)
return final_res
def get_constant(context,val,unit):
""" Create a constant value unit pair
:param val: value of the constant
:param unit: the unit of the constant
:returns: value unit tuple
"""
return (val,unit)
aux_functions = {
"get_file_line":get_file_line,
"get_file_lines":get_file_lines,
"get_file_regex":get_file_regex,
"get_file_regex_all":get_file_regex_all,
"get_regex_lines":get_regex_lines,
"get_regex_lines_vallist":get_regex_lines_vallist,
"get_final_iteration":get_final_iteration,
"get_constant":get_constant}
def _process_experiments(ruleset):
"""
"""
#TODO: missing values default to STRING, but later
# could be numeric when have value.
metadatas = {}
for exp in Experiment.objects.all():
logger.debug("exp=%s\n" % exp)
metadatas = process_experiment(metadatas, exp, ruleset)
#metadatas = _process_datasets(metadatas,exp,ruleset)
return metadatas
def _process_datasets(metadatas,exp,ruleset):
"""
"""
for dataset in Dataset.objects.filter(experiment=exp):
logger.debug("\tdataset=%s\n" % dataset)
meta = _process_datafiles(exp,dataset,ruleset)
logger.debug("meta=%s\n" % meta)
metadatas[dataset] = meta
logger.debug("metadatas=%s\n" % metadatas)
return metadatas
def _process_datafiles(exp,dataset,ruleset):
"""
"""
from collections import defaultdict
ready = defaultdict()
meta = {}
for datafile in Dataset_File.objects.filter(dataset=dataset):
logger.debug("\t\tdatafile=%s\n" % str(datafile))
ready[datafile.filename] = datafile
if datafile not in ready:
logger.debug(datafile.md5sum + "\n")
try:
datafile._set_md5sum()
except IOError:
pass
except OSError:
pass
logger.debug("hello from %s\n" % datafile)
#if (datafile.md5sum == datafile.expectedmd5):
# ready[datafile] = True
logger.debug("ready=%s\n" % ready)
try:
for tagname,file_patterns,code in ruleset:
logger.debug("file_patterns=%s,code=%s\n" % (file_patterns,code))
# check whether we have all files available.
# f could have _number regex
count = 0
for file_pattern in file_patterns:
import re
rule_file_regx = re.compile(file_pattern)
filename = None
# ready files could have _number prefix
for datafilename in ready:
match = rule_file_regx.match(datafilename)
if match:
logger.debug("matched % s" % datafilename)
filename = datafilename
break
logger.debug("filename=%s\n" % filename)
if filename in ready:
count += 1
logger.debug("count=%d" % count)
if count == len(file_patterns):
logger.debug("ready to start extracting on %s files\n" % count)
data_context = {'expid':exp.id,
'ready':ready,
'fileregex':file_patterns}
logger.debug("data_context=%s" % data_context)
try:
(value,unit) = eval(code,{},
{"get_file_line":get_file_line,
"get_file_lines":get_file_lines,
"get_file_regex":get_file_regex,
"get_file_regex_all":get_file_regex_all,
"get_regex_lines":get_regex_lines,
"get_regex_lines_vallist":get_regex_lines_vallist,
"get_final_iteration":get_final_iteration,
"get_constant":get_constant,
'context':data_context})
except Exception,e:
logger.error("Exception %s" % e)
logger.debug("value,unit=%s %s" % (value,unit))
meta[tagname] = (value,unit)
except ValueError:
logger.error("ruleset = %s" % ruleset )
raise
return meta
def _get_metadata(ruleset):
""" Extracts metadata tags and values for each datafile in experiments
:param ruleset: rules that define the extraction of metadata
:returns: dict from datafile to dict of tagname/tagvalue pairs
"""
# TODO: handle files that have not arrived yet
expectedmd5 = None
metadatas = _process_experiments(ruleset)
logger.debug("metadatas=%s\n" % metadatas)
return metadatas
def _get_schema(schema,name):
"""Return the schema object that the paramaterset will use.
"""
try:
sch = Schema.objects.get(namespace__exact=schema)
logger.debug("found %s %s" % (sch.namespace, sch.name))
return sch
except Schema.DoesNotExist:
schema = Schema(namespace=schema, name=name,
type=Schema.DATASET)
schema.save()
logger.debug("creating %s %s " % (schema,name))
return schema
def _get_parameters(schema,metadata):
""" Returns set of parameters from schema matched to elements in
metadata, or creates them based on the metadata values. Types
are based on seen values, favouring numerics over strings.
"""
param_objects = ParameterName.objects.filter(schema=schema)
logger.debug("param_objects=%s\n" % param_objects)
parameters = []
for p in metadata.keys():
logger.debug("pp=%s\n" % p)
logger.debug("metadata[pp][0] = %s" % metadata[p][0])
logger.debug("metadata[pp][1] = %s" % metadata[p][1])
parameter = filter(lambda x: x.name == p,param_objects)
logger.debug("pparameter=%s\n" % parameter)
if parameter:
parameters.append(parameter[0])
continue
# work out the best type from the value
datatype = ParameterName.STRING
units = None
try:
int(metadata[p][0])
except (ValueError,TypeError):
pass
else:
datatype = ParameterName.NUMERIC
units = str(metadata[p][1])
try:
float(metadata[p][0])
except (ValueError,TypeError):
pass
else:
datatype = ParameterName.NUMERIC
units = str(metadata[p][1])
logger.debug("units=%s" % str(metadata[p][1]))
if units:
new_param = ParameterName(schema=schema,
name=p,
full_name=p,
data_type=datatype,
units=units)
else:
new_param = ParameterName(schema=schema,
name=p,
full_name=p,
data_type=datatype)
new_param.save()
logger.debug("new_param=%s" % new_param)
logger.debug("datatype=%s" % datatype)
parameters.append(new_param)
return parameters
def _save_metadata(instance,schema,metadataset):
""" Creates schema from the metadataset and associates it
with the instance. If metadata value is empty, then
existing value is unchanged.
"""
parameters = _get_parameters(schema, metadataset)
logger.debug("parameters=%s" % parameters)
if not parameters:
return None
try:
ps = DatasetParameterSet.objects.get(schema=schema,
dataset=instance)
except DatasetParameterSet.DoesNotExist:
ps = DatasetParameterSet(schema=schema,dataset=instance)
ps.save()
logger.debug("ps=%s\n" % ps)
logger.debug("metadata2=%s\n" % metadataset)
for p in parameters:
logger.debug("p=%s\n" % p)
if p.name in metadataset:
logger.debug("found p =%s %s\n" % (p.name,p.units))
if p.isNumeric():
val = metadataset[p.name][0]
if val:
dfp = DatasetParameter.objects.filter(parameterset=ps,
name=p)
if not dfp:
dfp = DatasetParameter(parameterset=ps,
name=p)
dfp.numerical_value = val
logger.debug("new numeric")
dfp.save()
else:
for dp in dfp:
dp.numerical_value = val
dp.save()
logger.debug("numeric")
else:
val = metadataset[p.name][0]
logger.debug("val=%s" % val)
if val:
dfp = DatasetParameter.objects.filter(parameterset=ps,
name=p)
if not dfp:
dfp = DatasetParameter(parameterset=ps,
name=p)
dfp.string_value = metadataset[p.name][0]
dfp.save()
logger.debug("new string")
else:
for dp in dfp:
dp.string_value = metadataset[p.name][0]
dp.save()
logger.debug("string")
logger.debug("done")
def process_datafile(datafile, ruleset):
"""Extract metadata using given rules on a specific datafile
:param datafile: the file to analyse
:param ruleset: the set of rules to use
:returns: the metadata extracted
"""
from collections import defaultdict
ready = defaultdict()
meta = {}
logger.debug("ready=%s\n" % ready)
try:
regex_cache = {}
ready[datafile.filename] = datafile
for tagname,file_patterns,code in ruleset:
#logger.debug("file_patterns=%s,code=%s\n" % (file_patterns,code))
# check whether we have all files available.
# f could have _number regex
# This is a potential performance bottleneck
count = 0
for file_pattern in file_patterns:
# cache the reges
if file_pattern in regex_cache:
rule_file_regx = regex_cache[file_pattern]
else:
rule_file_regx = re.compile(file_pattern)
regex_cache[file_pattern] = rule_file_regx
filename= None
for datafilename in ready:
match = rule_file_regx.match(datafilename)
if match:
#logger.debug("matched % s" % datafilename)
filename = datafilename
break
#logger.debug("filename=%s\n" % filename)
if filename in ready:
count += 1
if count == len(file_patterns):
data_context = {'expid':datafile.dataset.experiment.id,
'ready':ready,
'fileregex':file_patterns}
logger.debug("data_context=%s" % data_context)
aux_context = aux_functions
aux_context['context'] = data_context
try:
(value,unit) = eval(code,{},aux_context)
except Exception,e:
logger.error("Exception %s" % e)
logger.debug("value,unit=%s %s" % (value,unit))
meta[tagname] = (value,unit)
except ValueError:
logger.error("ruleset = %s" % ruleset )
raise
return meta
def process_experiment(metadatas, exp, ruleset):
""" process all datasets for a given experiement using the ruleset
and return metadatas
:param metadata: initial parameter value structure
:param exp: the experiment to analyse
:param ruleset: The specific ruleset to apply
:returns: updated paramter value structure
"""
metadatas = _process_datasets(metadatas,exp,ruleset)
return metadatas
def process_experimentX(exp):
""" Process all the datasets for the given experiment
:param exp: the experiment to extract metadata for
"""
for schemainfo in rulesets:
metadataset = {}
metadataset = process_experiment(metadataset, exp,
rulesets[schemainfo])
logger.debug("extracted metadataset = %s" % metadataset)
schema = _get_schema(schemainfo[0],schemainfo[1])
logger.debug("schema = %s" % schema)
for datafile in metadataset:
_save_metadata(datafile,schema,metadataset[datafile])
def process_all_experiments():
""" Perform metadata extraction on all experiments in the system.
Warning: will override any local changes
"""
for schemainfo in rulesets:
metadataset = _get_metadata(rulesets[schemainfo])
logger.debug("metadatas=%s\n" % metadataset)
schema = _get_schema(schemainfo[0],schemainfo[1])
for datafile in metadataset:
_save_metadata(datafile,schema,metadataset[datafile])
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
7760,
13,
7409,
12,
820,
13965,
325,
13,
497,
1733,
593,
11286,
301,
199,
3,
257,
334,
11026,
649,
15904,
12,
437,
22306,
9,
199,
3,
1898,
334,
67,
9,
7129,
13,
8128,
12,
10953,
1119,
325,
13,
497,
1733,
30610,
264,
199,
3,
257,
334,
6671,
1119,
15904,
12,
437,
22306,
9,
199,
3,
2900,
4481,
4644,
14,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
259,
627,
221,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
221,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
755,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
259,
627,
221,
11443,
314,
536,
402,
314,
820,
13965,
12,
314,
820,
13965,
7556,
12,
6590,
314,
199,
3,
755,
1561,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
199,
3,
755,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
14142,
1309,
51,
2401,
6483,
1124,
1179,
2281,
891,
2401,
1821,
199,
3,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
199,
3,
9706,
14,
1621,
4825,
6461,
7000,
2334,
14142,
1309,
51,
2401,
6483,
6262,
7024,
2381,
1821,
199,
3,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
199,
3,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
199,
3,
5258,
1821,
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,
1634,
5749,
199,
3,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
199,
624,
199,
2343,
14,
647,
199,
199,
703,
28966,
447,
473,
290,
27864,
665,
41,
290,
14,
8751,
3079,
14,
52,
526,
5892,
32,
82,
1147,
14,
8654,
14,
3844,
30,
199,
199,
624,
257,
199,
504,
747,
492,
931,
199,
646,
295,
199,
646,
7975,
199,
646,
2050,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
199,
199,
504,
5330,
2297,
14,
5369,
2297,
63,
8707,
14,
992,
492,
20284,
63,
1173,
199,
504,
5330,
2297,
14,
5369,
2297,
63,
8707,
14,
992,
492,
20284,
199,
504,
5330,
2297,
14,
5369,
2297,
63,
8707,
14,
992,
492,
3918,
493,
4720,
199,
504,
5330,
2297,
14,
5369,
2297,
63,
8707,
14,
992,
492,
3918,
493,
4720,
1084,
199,
504,
5330,
2297,
14,
5369,
2297,
63,
8707,
14,
992,
492,
12009,
985,
199,
504,
5330,
2297,
14,
5369,
2297,
63,
8707,
14,
992,
492,
13268,
199,
504,
5330,
2297,
14,
5369,
2297,
63,
8707,
14,
992,
492,
20284,
4720,
199,
504,
5330,
2297,
14,
5369,
2297,
63,
8707,
14,
992,
492,
20284,
4720,
1084,
199,
504,
5330,
2297,
14,
5369,
2297,
63,
8707,
14,
992,
492,
23997,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
1955,
275,
7369,
16341,
11843,
1332,
60,
68,
27860,
3134,
68,
10,
5547,
8636,
2961,
68,
23294,
68,
8771,
779,
20565,
1527,
16341,
21852,
16,
13,
25,
23763,
2,
4388,
199,
2200,
2193,
275,
469,
288,
6079,
961,
2332,
409,
911,
7389,
282,
13268,
2397,
2797,
298,
10706,
413,
14,
16,
2,
315,
314,
3231,
288,
6079,
283,
1014,
921,
5369,
2297,
14,
8654,
14,
3844,
15,
9482,
15,
10706,
15,
17,
7,
7205,
661,
1014,
921,
5369,
2297,
14,
8654,
14,
3844,
15,
9482,
15,
10706,
15,
17,
1673,
10706,
413,
14,
16,
735,
463,
355,
327,
221,
961,
2332,
4450,
1263,
1584,
4877,
3341,
60,
703,
10,
6203,
436,
911,
5536,
355,
327,
370,
282,
623,
10011,
2797,
2199,
14,
355,
13636,
4761,
297,
480,
2343,
60,
703,
10,
11918,
395,
490,
327,
1240,
314,
664,
63,
493,
63,
3821,
805,
12,
1314,
2529,
1771,
334,
585,
12,
3248,
9,
2008,
14,
490,
327,
664,
63,
493,
63,
3821,
805,
17651,
1642,
1004,
402,
570,
626,
965,
7290,
9437,
490,
327,
701,
9697,
4110,
14,
5723,
4110,
787,
7838,
1901,
574,
1572,
490,
327,
436,
4137,
1572,
365,
2701,
315,
642,
1930,
14,
12793,
490,
298,
362,
63,
493,
63,
3821,
8,
1100,
2584,
4761,
94,
60,
83,
11,
2229,
48,
28,
585,
31411,
18168,
48,
28,
3248,
30,
3196,
797,
13185,
673,
355,
327,
961,
2332,
4450,
869,
4222,
1072,
1584,
1314,
1172,
282,
6308,
9437,
701,
312,
315,
3062,
355,
661,
3259,
24545,
28504,
297,
18523,
2795,
13040,
16,
13,
25,
3672,
4537,
79,
2961,
68,
8771,
11918,
395,
12793,
490,
298,
362,
63,
493,
63,
3821,
8,
1100,
2584,
3259,
402,
24174,
3427,
83,
11,
2229,
48,
28,
585,
31411,
18168,
48,
28,
3248,
30,
3196,
549,
13185,
355,
661,
10915,
5791,
4402,
297,
18523,
2795,
13040,
16,
13,
25,
3672,
4537,
79,
2961,
68,
8771,
11918,
395,
490,
298,
362,
63,
493,
63,
3821,
8,
1100,
2584,
4261,
5791,
4402,
3427,
83,
11,
2229,
48,
28,
585,
9514,
16,
13,
25,
11896,
2229,
48,
28,
3248,
13661,
45,
92,
39,
92,
43,
9,
34,
3196,
549,
13185,
355,
661,
4261,
3906,
2319,
4543,
675,
297,
18523,
2795,
13040,
16,
13,
25,
3672,
4537,
79,
2961,
68,
8771,
11918,
395,
490,
298,
362,
63,
493,
63,
3821,
8,
1100,
2584,
4261,
3906,
2319,
4543,
675,
3427,
83,
11,
2229,
48,
28,
585,
26343,
2229,
48,
28,
3248,
13661,
45,
92,
39,
92,
43,
9,
34,
3196,
549,
13185,
355,
661,
18018,
521,
297,
18523,
2795,
13040
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
7760,
13,
7409,
12,
820,
13965,
325,
13,
497,
1733,
593,
11286,
301,
199,
3,
257,
334,
11026,
649,
15904,
12,
437,
22306,
9,
199,
3,
1898,
334,
67,
9,
7129,
13,
8128,
12,
10953,
1119,
325,
13,
497,
1733,
30610,
264,
199,
3,
257,
334,
6671,
1119,
15904,
12,
437,
22306,
9,
199,
3,
2900,
4481,
4644,
14,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
259,
627,
221,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
221,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
755,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
259,
627,
221,
11443,
314,
536,
402,
314,
820,
13965,
12,
314,
820,
13965,
7556,
12,
6590,
314,
199,
3,
755,
1561,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
199,
3,
755,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
14142,
1309,
51,
2401,
6483,
1124,
1179,
2281,
891,
2401,
1821,
199,
3,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
199,
3,
9706,
14,
1621,
4825,
6461,
7000,
2334,
14142,
1309,
51,
2401,
6483,
6262,
7024,
2381,
1821,
199,
3,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
199,
3,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
199,
3,
5258,
1821,
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,
1634,
5749,
199,
3,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
199,
624,
199,
2343,
14,
647,
199,
199,
703,
28966,
447,
473,
290,
27864,
665,
41,
290,
14,
8751,
3079,
14,
52,
526,
5892,
32,
82,
1147,
14,
8654,
14,
3844,
30,
199,
199,
624,
257,
199,
504,
747,
492,
931,
199,
646,
295,
199,
646,
7975,
199,
646,
2050,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
199,
199,
504,
5330,
2297,
14,
5369,
2297,
63,
8707,
14,
992,
492,
20284,
63,
1173,
199,
504,
5330,
2297,
14,
5369,
2297,
63,
8707,
14,
992,
492,
20284,
199,
504,
5330,
2297,
14,
5369,
2297,
63,
8707,
14,
992,
492,
3918,
493,
4720,
199,
504,
5330,
2297,
14,
5369,
2297,
63,
8707,
14,
992,
492,
3918,
493,
4720,
1084,
199,
504,
5330,
2297,
14,
5369,
2297,
63,
8707,
14,
992,
492,
12009,
985,
199,
504,
5330,
2297,
14,
5369,
2297,
63,
8707,
14,
992,
492,
13268,
199,
504,
5330,
2297,
14,
5369,
2297,
63,
8707,
14,
992,
492,
20284,
4720,
199,
504,
5330,
2297,
14,
5369,
2297,
63,
8707,
14,
992,
492,
20284,
4720,
1084,
199,
504,
5330,
2297,
14,
5369,
2297,
63,
8707,
14,
992,
492,
23997,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
1955,
275,
7369,
16341,
11843,
1332,
60,
68,
27860,
3134,
68,
10,
5547,
8636,
2961,
68,
23294,
68,
8771,
779,
20565,
1527,
16341,
21852,
16,
13,
25,
23763,
2,
4388,
199,
2200,
2193,
275,
469,
288,
6079,
961,
2332,
409,
911,
7389,
282,
13268,
2397,
2797,
298,
10706,
413,
14,
16,
2,
315,
314,
3231,
288,
6079,
283,
1014,
921,
5369,
2297,
14,
8654,
14,
3844,
15,
9482,
15,
10706,
15,
17,
7,
7205,
661,
1014,
921,
5369,
2297,
14,
8654,
14,
3844,
15,
9482,
15,
10706,
15,
17,
1673,
10706,
413,
14,
16,
735,
463,
355,
327,
221,
961,
2332,
4450,
1263,
1584,
4877,
3341,
60,
703,
10,
6203,
436,
911,
5536,
355,
327,
370,
282,
623,
10011,
2797,
2199,
14,
355,
13636,
4761,
297,
480,
2343,
60,
703,
10,
11918,
395,
490,
327,
1240,
314,
664,
63,
493,
63,
3821,
805,
12,
1314,
2529,
1771,
334,
585,
12,
3248,
9,
2008,
14,
490,
327,
664,
63,
493,
63,
3821,
805,
17651,
1642,
1004,
402,
570,
626,
965,
7290,
9437,
490,
327,
701,
9697,
4110,
14,
5723,
4110,
787,
7838,
1901,
574,
1572,
490,
327,
436,
4137,
1572,
365,
2701,
315,
642,
1930,
14,
12793,
490,
298,
362,
63,
493,
63,
3821,
8,
1100,
2584,
4761,
94,
60,
83,
11,
2229,
48,
28,
585,
31411,
18168,
48,
28,
3248,
30,
3196,
797,
13185,
673,
355,
327,
961,
2332,
4450,
869,
4222,
1072,
1584,
1314,
1172,
282,
6308,
9437,
701,
312,
315,
3062,
355,
661,
3259,
24545,
28504,
297,
18523,
2795,
13040,
16,
13,
25,
3672,
4537,
79,
2961,
68,
8771,
11918,
395,
12793,
490,
298,
362,
63,
493,
63,
3821,
8,
1100,
2584,
3259,
402,
24174,
3427,
83,
11,
2229,
48,
28,
585,
31411,
18168,
48,
28,
3248,
30,
3196,
549,
13185,
355,
661,
10915,
5791,
4402,
297,
18523,
2795,
13040,
16,
13,
25,
3672,
4537,
79,
2961,
68,
8771,
11918,
395,
490,
298,
362,
63,
493,
63,
3821,
8,
1100,
2584,
4261,
5791,
4402,
3427,
83,
11,
2229,
48,
28,
585,
9514,
16,
13,
25,
11896,
2229,
48,
28,
3248,
13661,
45,
92,
39,
92,
43,
9,
34,
3196,
549,
13185,
355,
661,
4261,
3906,
2319,
4543,
675,
297,
18523,
2795,
13040,
16,
13,
25,
3672,
4537,
79,
2961,
68,
8771,
11918,
395,
490,
298,
362,
63,
493,
63,
3821,
8,
1100,
2584,
4261,
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