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
|
|---|---|---|---|---|---|---|---|---|
txomon/SpockBot
|
spock/mcp/mcpacket.py
|
1
|
4216
|
try:
basestring
except NameError:
basestring = str
import copy
import logging
import zlib
from time import gmtime, strftime
from spock import utils
from spock.mcp import datautils, mcdata
from spock.mcp.mcdata import MC_VARINT
from spock.mcp.mcpacket_extensions import hashed_extensions
logger = logging.getLogger('spock')
class PacketDecodeFailure(Exception):
def __init__(self, packet, pbuff, underflow=False):
self.packet = packet
self.pbuff = pbuff
self.underflow = underflow
class Packet(object):
def __init__(self,
ident=[mcdata.HANDSHAKE_STATE, mcdata.CLIENT_TO_SERVER, 0x00],
data=None
):
if isinstance(ident, basestring):
ident = mcdata.packet_str2ident[ident]
self.__ident = list(ident)
# Quick hack to fake default ident
if len(self.__ident) == 2:
self.__ident.append(0x00)
self.ident = tuple(self.__ident)
self.str_ident = mcdata.packet_ident2str[self.ident]
self.data = data if data else {}
def clone(self):
return Packet(self.ident, copy.deepcopy(self.data))
def new_ident(self, ident):
self.__init__(ident, self.data)
def decode(self, bbuff, proto_comp_state):
self.data = {}
if proto_comp_state == mcdata.PROTO_COMP_ON:
packet_length = datautils.unpack(MC_VARINT, bbuff)
start = bbuff.tell()
data_length = datautils.unpack(MC_VARINT, bbuff)
packet_data = bbuff.recv(packet_length - (bbuff.tell() - start))
if data_length:
packet_data = zlib.decompress(packet_data, zlib.MAX_WBITS)
elif proto_comp_state == mcdata.PROTO_COMP_OFF:
packet_data = bbuff.recv(datautils.unpack(MC_VARINT, bbuff))
else:
return None
pbuff = utils.BoundBuffer(packet_data)
try:
# Ident
self.__ident[2] = datautils.unpack(MC_VARINT, pbuff)
self.ident = tuple(self.__ident)
self.str_ident = mcdata.packet_ident2str[self.ident]
# Payload
for dtype, name in mcdata.hashed_structs[self.ident]:
self.data[name] = datautils.unpack(dtype, pbuff)
# Extension
if self.ident in hashed_extensions:
hashed_extensions[self.ident].decode_extra(self, pbuff)
if pbuff.buff:
raise PacketDecodeFailure(self, pbuff)
except utils.BufferUnderflowException:
raise PacketDecodeFailure(self, pbuff, True)
return self
def encode(self, proto_comp_state, proto_comp_threshold, comp_level=6):
# Ident
o = datautils.pack(MC_VARINT, self.ident[2])
# Payload
for dtype, name in mcdata.hashed_structs[self.ident]:
o += datautils.pack(dtype, self.data[name])
# Extension
if self.ident in hashed_extensions:
o += hashed_extensions[self.ident].encode_extra(self)
if proto_comp_state == mcdata.PROTO_COMP_ON:
uncompressed_len = len(o)
if uncompressed_len < proto_comp_threshold:
header = datautils.pack(MC_VARINT, uncompressed_len + 1)
header += datautils.pack(MC_VARINT, 0)
elif uncompressed_len >= proto_comp_threshold:
o = zlib.compress(o, comp_level)
ulen_varint = datautils.pack(MC_VARINT, uncompressed_len)
header = datautils.pack(MC_VARINT,
uncompressed_len + len(ulen_varint))
header += ulen_varint
return header + o
elif proto_comp_state == mcdata.PROTO_COMP_OFF:
return datautils.pack(MC_VARINT, len(o)) + o
else:
return None
def __repr__(self):
s = ('<<<', '>>>')[self.ident[1]]
f = "[%s] %s (0x%02X, 0x%02X): %-" + str(
max([len(i) for i in mcdata.hashed_names.values()]) + 1) + "s%s"
return f % (
strftime("%H:%M:%S", gmtime()), s, self.ident[0], self.ident[2],
mcdata.hashed_names[self.ident],
str(self.data)
)
|
mit
|
[
893,
26,
272,
7116,
199,
2590,
12746,
26,
272,
7116,
275,
620,
199,
199,
646,
1331,
199,
646,
2050,
199,
646,
12472,
199,
504,
900,
492,
486,
8180,
12,
14053,
199,
199,
504,
25664,
346,
492,
3778,
199,
504,
25664,
346,
14,
77,
1850,
492,
666,
1208,
12,
333,
15892,
199,
504,
25664,
346,
14,
77,
1850,
14,
5466,
576,
492,
32685,
63,
5568,
2919,
199,
504,
25664,
346,
14,
77,
1850,
14,
5466,
6253,
63,
5359,
492,
19871,
63,
5359,
421,
199,
2921,
275,
2050,
14,
5572,
360,
22522,
346,
358,
421,
199,
533,
31782,
9400,
6782,
8,
1726,
304,
272,
347,
636,
826,
721,
277,
12,
3644,
12,
299,
16830,
12,
1334,
1659,
29,
797,
304,
267,
291,
14,
6253,
275,
3644,
267,
291,
14,
80,
16830,
275,
299,
16830,
267,
291,
14,
7138,
1659,
275,
1334,
1659,
421,
199,
533,
31782,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
326,
12893,
1524,
5466,
576,
14,
40,
20033,
6294,
2430,
63,
6689,
12,
333,
15892,
14,
9901,
63,
2566,
63,
6613,
12,
378,
88,
383,
467,
326,
666,
29,
403,
326,
3461,
267,
340,
1228,
8,
5425,
12,
7116,
304,
288,
12893,
275,
333,
15892,
14,
6253,
63,
495,
18,
5425,
59,
5425,
61,
267,
291,
855,
5425,
275,
769,
8,
5425,
9,
267,
327,
27534,
11176,
370,
4026,
849,
12893,
267,
340,
822,
8,
277,
855,
5425,
9,
508,
499,
26,
288,
291,
855,
5425,
14,
740,
8,
16,
88,
383,
9,
267,
291,
14,
5425,
275,
2008,
8,
277,
855,
5425,
9,
267,
291,
14,
495,
63,
5425,
275,
333,
15892,
14,
6253,
63,
5425,
18,
495,
59,
277,
14,
5425,
61,
267,
291,
14,
576,
275,
666,
340,
666,
587,
1052,
339,
347,
7289,
8,
277,
304,
267,
372,
31782,
8,
277,
14,
5425,
12,
1331,
14,
8293,
8,
277,
14,
576,
430,
339,
347,
892,
63,
5425,
8,
277,
12,
12893,
304,
267,
291,
855,
826,
721,
5425,
12,
291,
14,
576,
9,
339,
347,
4849,
8,
277,
12,
330,
16830,
12,
4104,
63,
863,
63,
929,
304,
267,
291,
14,
576,
275,
1052,
267,
340,
4104,
63,
863,
63,
929,
508,
333,
15892,
14,
7459,
63,
6790,
63,
615,
26,
288,
3644,
63,
1267,
275,
666,
1208,
14,
5301,
8,
7608,
63,
5568,
2919,
12,
330,
16830,
9,
288,
1343,
275,
330,
16830,
14,
9974,
342,
288,
666,
63,
1267,
275,
666,
1208,
14,
5301,
8,
7608,
63,
5568,
2919,
12,
330,
16830,
9,
288,
3644,
63,
576,
275,
330,
16830,
14,
7637,
8,
6253,
63,
1267,
446,
334,
66,
16830,
14,
9974,
342,
446,
1343,
430,
288,
340,
666,
63,
1267,
26,
355,
3644,
63,
576,
275,
12472,
14,
14954,
8,
6253,
63,
576,
12,
12472,
14,
4283,
63,
55,
14662,
9,
267,
916,
4104,
63,
863,
63,
929,
508,
333,
15892,
14,
7459,
63,
6790,
63,
7517,
26,
288,
3644,
63,
576,
275,
330,
16830,
14,
7637,
8,
576,
1208,
14,
5301,
8,
7608,
63,
5568,
2919,
12,
330,
16830,
430,
267,
587,
26,
288,
372,
488,
267,
299,
16830,
275,
3778,
14,
8934,
3299,
8,
6253,
63,
576,
9,
398,
862,
26,
288,
327,
473,
1326,
288,
291,
855,
5425,
59,
18,
61,
275,
666,
1208,
14,
5301,
8,
7608,
63,
5568,
2919,
12,
299,
16830,
9,
288,
291,
14,
5425,
275,
2008,
8,
277,
855,
5425,
9,
288,
291,
14,
495,
63,
5425,
275,
333,
15892,
14,
6253,
63,
5425,
18,
495,
59,
277,
14,
5425,
61,
288,
327,
15911,
912,
288,
367,
2152,
12,
536,
315,
333,
15892,
14,
26368,
63,
23253,
59,
277,
14,
5425,
2189,
355,
291,
14,
576,
59,
354,
61,
275,
666,
1208,
14,
5301,
8,
2271,
12,
299,
16830,
9,
288,
327,
13282,
288,
340,
291,
14,
5425,
315,
19871,
63,
5359,
26,
355,
19871,
63,
5359,
59,
277,
14,
5425,
1055,
2708,
63,
2911,
8,
277,
12,
299,
16830,
9,
288,
340,
299,
16830,
14,
16830,
26,
355,
746,
31782,
9400,
6782,
8,
277,
12,
299,
16830,
9,
267,
871,
3778,
14,
3299,
16001,
1659,
1726,
26,
288,
746,
31782,
9400,
6782,
8,
277,
12,
299,
16830,
12,
715,
9,
267,
372,
291,
339,
347,
3752,
8,
277,
12,
4104,
63,
863,
63,
929,
12,
4104,
63,
863,
63,
7227,
12,
1013,
63,
1896,
29,
22,
304,
267,
327,
473,
1326,
267,
312,
275,
666,
1208,
14,
1389,
8,
7608,
63,
5568,
2919,
12,
291,
14,
5425,
59,
18,
566,
267,
327,
15911,
912,
267,
367,
2152,
12,
536,
315,
333,
15892,
14,
26368,
63,
23253,
59,
277,
14,
5425,
2189,
288,
312,
847,
666,
1208,
14,
1389,
8,
2271,
12,
291,
14,
576,
59,
354,
566,
267,
327,
13282,
267,
340,
291,
14,
5425,
315,
19871,
63,
5359,
26,
288,
312,
847,
19871,
63,
5359,
59,
277,
14,
5425,
1055,
2143,
63,
2911,
8,
277,
9,
398,
340,
4104,
63,
863,
63,
929,
508,
333,
15892,
14,
7459,
63,
6790,
63,
615,
26,
288,
25904,
63,
552,
275,
822,
8,
79,
9,
288,
340,
25904,
63,
552,
665,
4104,
63,
863,
63,
7227,
26,
355,
1406,
275,
666,
1208,
14,
1389,
8,
7608,
63,
5568,
2919,
12,
25904,
63,
552,
435,
413,
9,
355,
1406,
847,
666,
1208,
14,
1389,
8,
7608,
63,
5568,
2919,
12,
378,
9,
288,
916,
25904,
63,
552,
2356,
4104,
63,
863,
63,
7227,
26,
355,
312,
275,
12472,
14,
6447,
8,
79,
12,
1013,
63,
1896,
9,
355,
399,
552,
63,
1391,
442,
275,
666,
1208,
14,
1389,
8,
7608,
63,
5568,
2919,
12,
25904,
63,
552,
9,
355,
1406,
275,
666,
1208,
14,
1389,
8,
7608,
63,
5568,
2919,
12,
3147,
25904,
63,
552,
435,
822,
8,
443,
78,
63,
1391,
442,
430,
355,
1406,
847,
399,
552,
63,
1391,
442,
288,
372,
1406,
435,
312,
267,
916,
4104,
63,
863,
63,
929,
508,
333,
15892,
14,
7459,
63,
6790,
63,
7517,
26,
288,
372,
666,
1208,
14,
1389,
8,
7608,
63,
5568,
2919,
12,
822,
8,
79,
430,
435,
312,
267,
587,
26,
288,
372,
488,
339,
347,
636,
2722,
721,
277,
304,
267,
308,
275,
661,
8999,
28,
297,
283,
6071,
5832,
277,
14
] |
[
26,
272,
7116,
199,
2590,
12746,
26,
272,
7116,
275,
620,
199,
199,
646,
1331,
199,
646,
2050,
199,
646,
12472,
199,
504,
900,
492,
486,
8180,
12,
14053,
199,
199,
504,
25664,
346,
492,
3778,
199,
504,
25664,
346,
14,
77,
1850,
492,
666,
1208,
12,
333,
15892,
199,
504,
25664,
346,
14,
77,
1850,
14,
5466,
576,
492,
32685,
63,
5568,
2919,
199,
504,
25664,
346,
14,
77,
1850,
14,
5466,
6253,
63,
5359,
492,
19871,
63,
5359,
421,
199,
2921,
275,
2050,
14,
5572,
360,
22522,
346,
358,
421,
199,
533,
31782,
9400,
6782,
8,
1726,
304,
272,
347,
636,
826,
721,
277,
12,
3644,
12,
299,
16830,
12,
1334,
1659,
29,
797,
304,
267,
291,
14,
6253,
275,
3644,
267,
291,
14,
80,
16830,
275,
299,
16830,
267,
291,
14,
7138,
1659,
275,
1334,
1659,
421,
199,
533,
31782,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
326,
12893,
1524,
5466,
576,
14,
40,
20033,
6294,
2430,
63,
6689,
12,
333,
15892,
14,
9901,
63,
2566,
63,
6613,
12,
378,
88,
383,
467,
326,
666,
29,
403,
326,
3461,
267,
340,
1228,
8,
5425,
12,
7116,
304,
288,
12893,
275,
333,
15892,
14,
6253,
63,
495,
18,
5425,
59,
5425,
61,
267,
291,
855,
5425,
275,
769,
8,
5425,
9,
267,
327,
27534,
11176,
370,
4026,
849,
12893,
267,
340,
822,
8,
277,
855,
5425,
9,
508,
499,
26,
288,
291,
855,
5425,
14,
740,
8,
16,
88,
383,
9,
267,
291,
14,
5425,
275,
2008,
8,
277,
855,
5425,
9,
267,
291,
14,
495,
63,
5425,
275,
333,
15892,
14,
6253,
63,
5425,
18,
495,
59,
277,
14,
5425,
61,
267,
291,
14,
576,
275,
666,
340,
666,
587,
1052,
339,
347,
7289,
8,
277,
304,
267,
372,
31782,
8,
277,
14,
5425,
12,
1331,
14,
8293,
8,
277,
14,
576,
430,
339,
347,
892,
63,
5425,
8,
277,
12,
12893,
304,
267,
291,
855,
826,
721,
5425,
12,
291,
14,
576,
9,
339,
347,
4849,
8,
277,
12,
330,
16830,
12,
4104,
63,
863,
63,
929,
304,
267,
291,
14,
576,
275,
1052,
267,
340,
4104,
63,
863,
63,
929,
508,
333,
15892,
14,
7459,
63,
6790,
63,
615,
26,
288,
3644,
63,
1267,
275,
666,
1208,
14,
5301,
8,
7608,
63,
5568,
2919,
12,
330,
16830,
9,
288,
1343,
275,
330,
16830,
14,
9974,
342,
288,
666,
63,
1267,
275,
666,
1208,
14,
5301,
8,
7608,
63,
5568,
2919,
12,
330,
16830,
9,
288,
3644,
63,
576,
275,
330,
16830,
14,
7637,
8,
6253,
63,
1267,
446,
334,
66,
16830,
14,
9974,
342,
446,
1343,
430,
288,
340,
666,
63,
1267,
26,
355,
3644,
63,
576,
275,
12472,
14,
14954,
8,
6253,
63,
576,
12,
12472,
14,
4283,
63,
55,
14662,
9,
267,
916,
4104,
63,
863,
63,
929,
508,
333,
15892,
14,
7459,
63,
6790,
63,
7517,
26,
288,
3644,
63,
576,
275,
330,
16830,
14,
7637,
8,
576,
1208,
14,
5301,
8,
7608,
63,
5568,
2919,
12,
330,
16830,
430,
267,
587,
26,
288,
372,
488,
267,
299,
16830,
275,
3778,
14,
8934,
3299,
8,
6253,
63,
576,
9,
398,
862,
26,
288,
327,
473,
1326,
288,
291,
855,
5425,
59,
18,
61,
275,
666,
1208,
14,
5301,
8,
7608,
63,
5568,
2919,
12,
299,
16830,
9,
288,
291,
14,
5425,
275,
2008,
8,
277,
855,
5425,
9,
288,
291,
14,
495,
63,
5425,
275,
333,
15892,
14,
6253,
63,
5425,
18,
495,
59,
277,
14,
5425,
61,
288,
327,
15911,
912,
288,
367,
2152,
12,
536,
315,
333,
15892,
14,
26368,
63,
23253,
59,
277,
14,
5425,
2189,
355,
291,
14,
576,
59,
354,
61,
275,
666,
1208,
14,
5301,
8,
2271,
12,
299,
16830,
9,
288,
327,
13282,
288,
340,
291,
14,
5425,
315,
19871,
63,
5359,
26,
355,
19871,
63,
5359,
59,
277,
14,
5425,
1055,
2708,
63,
2911,
8,
277,
12,
299,
16830,
9,
288,
340,
299,
16830,
14,
16830,
26,
355,
746,
31782,
9400,
6782,
8,
277,
12,
299,
16830,
9,
267,
871,
3778,
14,
3299,
16001,
1659,
1726,
26,
288,
746,
31782,
9400,
6782,
8,
277,
12,
299,
16830,
12,
715,
9,
267,
372,
291,
339,
347,
3752,
8,
277,
12,
4104,
63,
863,
63,
929,
12,
4104,
63,
863,
63,
7227,
12,
1013,
63,
1896,
29,
22,
304,
267,
327,
473,
1326,
267,
312,
275,
666,
1208,
14,
1389,
8,
7608,
63,
5568,
2919,
12,
291,
14,
5425,
59,
18,
566,
267,
327,
15911,
912,
267,
367,
2152,
12,
536,
315,
333,
15892,
14,
26368,
63,
23253,
59,
277,
14,
5425,
2189,
288,
312,
847,
666,
1208,
14,
1389,
8,
2271,
12,
291,
14,
576,
59,
354,
566,
267,
327,
13282,
267,
340,
291,
14,
5425,
315,
19871,
63,
5359,
26,
288,
312,
847,
19871,
63,
5359,
59,
277,
14,
5425,
1055,
2143,
63,
2911,
8,
277,
9,
398,
340,
4104,
63,
863,
63,
929,
508,
333,
15892,
14,
7459,
63,
6790,
63,
615,
26,
288,
25904,
63,
552,
275,
822,
8,
79,
9,
288,
340,
25904,
63,
552,
665,
4104,
63,
863,
63,
7227,
26,
355,
1406,
275,
666,
1208,
14,
1389,
8,
7608,
63,
5568,
2919,
12,
25904,
63,
552,
435,
413,
9,
355,
1406,
847,
666,
1208,
14,
1389,
8,
7608,
63,
5568,
2919,
12,
378,
9,
288,
916,
25904,
63,
552,
2356,
4104,
63,
863,
63,
7227,
26,
355,
312,
275,
12472,
14,
6447,
8,
79,
12,
1013,
63,
1896,
9,
355,
399,
552,
63,
1391,
442,
275,
666,
1208,
14,
1389,
8,
7608,
63,
5568,
2919,
12,
25904,
63,
552,
9,
355,
1406,
275,
666,
1208,
14,
1389,
8,
7608,
63,
5568,
2919,
12,
3147,
25904,
63,
552,
435,
822,
8,
443,
78,
63,
1391,
442,
430,
355,
1406,
847,
399,
552,
63,
1391,
442,
288,
372,
1406,
435,
312,
267,
916,
4104,
63,
863,
63,
929,
508,
333,
15892,
14,
7459,
63,
6790,
63,
7517,
26,
288,
372,
666,
1208,
14,
1389,
8,
7608,
63,
5568,
2919,
12,
822,
8,
79,
430,
435,
312,
267,
587,
26,
288,
372,
488,
339,
347,
636,
2722,
721,
277,
304,
267,
308,
275,
661,
8999,
28,
297,
283,
6071,
5832,
277,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
anyweez/regis
|
face/offline/Terms/Term.py
|
2
|
1150
|
class BaseTerm(object):
def __init__(self):
# TODO: Move term_focus code into constructors in Terms.
self.user = None
self.template = None
def execute(self, params):
raise NotImplementedError
'''
Some library functions that can be used by other terms.
'''
# get_contents fetches the contents of a file from the
# appropriate directory.
def get_full_file(self, filename):
directory = '../resources/full'
fp = open('%s/%s' % (directory, filename))
lines = fp.readlines()
fp.close()
return lines
# def get_user_file(self, tid):
# directory = '../resources/user'
# fp = open('%s/%s.%s.txt' % (directory, str(uid), str(tid))
# lines = fp.readlines()
# fp.close()
# return lines
# make_sets takes a list of lines (read from a file) and
# converts them into sets. This is currently determined
# by the presence of an empty line between sets.
def make_sets(self, lines):
sets = []
current = []
for line in lines:
if len(line) is 0:
sets.append(current)
current = []
else:
current.append(line.strip())
return sets
|
gpl-2.0
|
[
199,
533,
3523,
21676,
8,
785,
304,
523,
347,
636,
826,
721,
277,
304,
272,
327,
3254,
26,
14171,
6707,
63,
12283,
1233,
1901,
31604,
315,
13861,
706,
14,
272,
291,
14,
751,
275,
488,
272,
291,
14,
1160,
275,
488,
686,
523,
347,
5341,
8,
277,
12,
1862,
304,
272,
746,
4279,
819,
1449,
523,
6601,
3555,
3423,
626,
883,
506,
1202,
701,
1163,
2895,
14,
523,
1449,
257,
819,
327,
664,
63,
4407,
28053,
314,
4072,
402,
282,
570,
687,
314,
523,
327,
5827,
2082,
14,
523,
347,
664,
63,
2861,
63,
493,
8,
277,
12,
1788,
304,
272,
2082,
275,
20644,
4435,
15,
2861,
7,
339,
4090,
275,
1551,
3508,
83,
3149,
83,
7,
450,
334,
3619,
12,
1788,
430,
272,
2385,
275,
4090,
14,
9684,
342,
272,
4090,
14,
1600,
342,
339,
372,
2385,
199,
199,
3,
221,
347,
664,
63,
751,
63,
493,
8,
277,
12,
11559,
304,
199,
3,
259,
2082,
275,
20644,
4435,
15,
751,
7,
199,
199,
3,
259,
4090,
275,
1551,
3508,
83,
3149,
83,
4111,
83,
14,
2424,
7,
450,
334,
3619,
12,
620,
8,
1535,
395,
620,
8,
5700,
430,
199,
3,
259,
2385,
275,
4090,
14,
9684,
342,
199,
3,
259,
4090,
14,
1600,
342,
199,
199,
3,
259,
372,
2385,
819,
327,
1852,
63,
2193,
6181,
282,
769,
402,
2385,
334,
739,
687,
282,
570,
9,
436,
523,
327,
15373,
3062,
1901,
5951,
14,
221,
961,
365,
5544,
12037,
523,
327,
701,
314,
20024,
402,
376,
2701,
1004,
3382,
5951,
14,
523,
347,
1852,
63,
2193,
8,
277,
12,
2385,
304,
272,
5951,
275,
942,
272,
1453,
275,
942,
339,
367,
1004,
315,
2385,
26,
489,
340,
822,
8,
604,
9,
365,
378,
26,
267,
5951,
14,
740,
8,
1818,
9,
267,
1453,
275,
942,
489,
587,
26,
267,
1453,
14,
740,
8,
604,
14,
1913,
1012,
339,
372,
5951,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
533,
3523,
21676,
8,
785,
304,
523,
347,
636,
826,
721,
277,
304,
272,
327,
3254,
26,
14171,
6707,
63,
12283,
1233,
1901,
31604,
315,
13861,
706,
14,
272,
291,
14,
751,
275,
488,
272,
291,
14,
1160,
275,
488,
686,
523,
347,
5341,
8,
277,
12,
1862,
304,
272,
746,
4279,
819,
1449,
523,
6601,
3555,
3423,
626,
883,
506,
1202,
701,
1163,
2895,
14,
523,
1449,
257,
819,
327,
664,
63,
4407,
28053,
314,
4072,
402,
282,
570,
687,
314,
523,
327,
5827,
2082,
14,
523,
347,
664,
63,
2861,
63,
493,
8,
277,
12,
1788,
304,
272,
2082,
275,
20644,
4435,
15,
2861,
7,
339,
4090,
275,
1551,
3508,
83,
3149,
83,
7,
450,
334,
3619,
12,
1788,
430,
272,
2385,
275,
4090,
14,
9684,
342,
272,
4090,
14,
1600,
342,
339,
372,
2385,
199,
199,
3,
221,
347,
664,
63,
751,
63,
493,
8,
277,
12,
11559,
304,
199,
3,
259,
2082,
275,
20644,
4435,
15,
751,
7,
199,
199,
3,
259,
4090,
275,
1551,
3508,
83,
3149,
83,
4111,
83,
14,
2424,
7,
450,
334,
3619,
12,
620,
8,
1535,
395,
620,
8,
5700,
430,
199,
3,
259,
2385,
275,
4090,
14,
9684,
342,
199,
3,
259,
4090,
14,
1600,
342,
199,
199,
3,
259,
372,
2385,
819,
327,
1852,
63,
2193,
6181,
282,
769,
402,
2385,
334,
739,
687,
282,
570,
9,
436,
523,
327,
15373,
3062,
1901,
5951,
14,
221,
961,
365,
5544,
12037,
523,
327,
701,
314,
20024,
402,
376,
2701,
1004,
3382,
5951,
14,
523,
347,
1852,
63,
2193,
8,
277,
12,
2385,
304,
272,
5951,
275,
942,
272,
1453,
275,
942,
339,
367,
1004,
315,
2385,
26,
489,
340,
822,
8,
604,
9,
365,
378,
26,
267,
5951,
14,
740,
8,
1818,
9,
267,
1453,
275,
942,
489,
587,
26,
267,
1453,
14,
740,
8,
604,
14,
1913,
1012,
339,
372,
5951,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
fedorpatlin/ansible
|
lib/ansible/modules/cloud/ovirt/ovirt_templates.py
|
26
|
11499
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 Red Hat, Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: ovirt_templates
short_description: Module to manage virtual machine templates in oVirt
version_added: "2.3"
author: "Ondra Machacek (@machacekondra)"
description:
- "Module to manage virtual machine templates in oVirt."
options:
name:
description:
- "Name of the the template to manage."
required: true
state:
description:
- "Should the template be present/absent/exported/imported"
choices: ['present', 'absent', 'exported', 'imported']
default: present
vm:
description:
- "Name of the VM, which will be used to create template."
description:
description:
- "Description of the template."
cpu_profile:
description:
- "CPU profile to be set to template."
cluster:
description:
- "Name of the cluster, where template should be created/imported."
exclusive:
description:
- "When C(state) is I(exported) this parameter indicates if the existing templates with the
same name should be overwritten."
export_domain:
description:
- "When C(state) is I(exported) or I(imported) this parameter specifies the name of the
export storage domain."
image_provider:
description:
- "When C(state) is I(imported) this parameter specifies the name of the image provider to be used."
image_disk:
description:
- "When C(state) is I(imported) and C(image_provider) is used this parameter specifies the name of disk
to be imported as template."
storage_domain:
description:
- "When C(state) is I(imported) this parameter specifies the name of the destination data storage domain."
clone_permissions:
description:
- "If I(True) then the permissions of the VM (only the direct ones, not the inherited ones)
will be copied to the created template."
- "This parameter is used only when C(state) I(present)."
default: False
extends_documentation_fragment: ovirt
'''
EXAMPLES = '''
# Examples don't contain auth parameter for simplicity,
# look at ovirt_auth module to see how to reuse authentication:
# Create template from vm
- ovirt_templates:
cluster: Default
name: mytemplate
vm: rhel7
cpu_profile: Default
description: Test
# Import template
- ovirt_templates:
state: imported
name: mytemplate
export_domain: myexport
storage_domain: mystorage
cluster: mycluster
# Remove template
- ovirt_templates:
state: absent
name: mytemplate
'''
RETURN = '''
id:
description: ID of the template which is managed
returned: On success if template is found.
type: str
sample: 7de90f31-222c-436c-a1ca-7e655bd5b60c
template:
description: "Dictionary of all the template attributes. Template attributes can be found on your oVirt instance
at following url: https://ovirt.example.com/ovirt-engine/api/model#types/template."
returned: On success if template is found.
'''
import time
import traceback
try:
import ovirtsdk4.types as otypes
except ImportError:
pass
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ovirt import (
BaseModule,
check_sdk,
create_connection,
equal,
get_dict_of_struct,
get_link_name,
ovirt_full_argument_spec,
search_by_attributes,
search_by_name,
)
class TemplatesModule(BaseModule):
def build_entity(self):
return otypes.Template(
name=self._module.params['name'],
cluster=otypes.Cluster(
name=self._module.params['cluster']
) if self._module.params['cluster'] else None,
vm=otypes.Vm(
name=self._module.params['vm']
) if self._module.params['vm'] else None,
description=self._module.params['description'],
cpu_profile=otypes.CpuProfile(
id=search_by_name(
self._connection.system_service().cpu_profiles_service(),
self._module.params['cpu_profile'],
).id
) if self._module.params['cpu_profile'] else None,
)
def update_check(self, entity):
return (
equal(self._module.params.get('cluster'), get_link_name(self._connection, entity.cluster)) and
equal(self._module.params.get('description'), entity.description) and
equal(self._module.params.get('cpu_profile'), get_link_name(self._connection, entity.cpu_profile))
)
def _get_export_domain_service(self):
provider_name = self._module.params['export_domain'] or self._module.params['image_provider']
export_sds_service = self._connection.system_service().storage_domains_service()
export_sd = search_by_name(export_sds_service, provider_name)
if export_sd is None:
raise ValueError(
"Export storage domain/Image Provider '%s' wasn't found." % provider_name
)
return export_sds_service.service(export_sd.id)
def post_export_action(self, entity):
self._service = self._get_export_domain_service().templates_service()
def post_import_action(self, entity):
self._service = self._connection.system_service().templates_service()
def wait_for_import(module, templates_service):
if module.params['wait']:
start = time.time()
timeout = module.params['timeout']
poll_interval = module.params['poll_interval']
while time.time() < start + timeout:
template = search_by_name(templates_service, module.params['name'])
if template:
return template
time.sleep(poll_interval)
def main():
argument_spec = ovirt_full_argument_spec(
state=dict(
choices=['present', 'absent', 'exported', 'imported'],
default='present',
),
name=dict(default=None, required=True),
vm=dict(default=None),
description=dict(default=None),
cluster=dict(default=None),
cpu_profile=dict(default=None),
disks=dict(default=[], type='list'),
clone_permissions=dict(type='bool'),
export_domain=dict(default=None),
storage_domain=dict(default=None),
exclusive=dict(type='bool'),
image_provider=dict(default=None),
image_disk=dict(default=None),
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
)
check_sdk(module)
try:
auth = module.params.pop('auth')
connection = create_connection(auth)
templates_service = connection.system_service().templates_service()
templates_module = TemplatesModule(
connection=connection,
module=module,
service=templates_service,
)
state = module.params['state']
if state == 'present':
ret = templates_module.create(
result_state=otypes.TemplateStatus.OK,
clone_permissions=module.params['clone_permissions'],
)
elif state == 'absent':
ret = templates_module.remove()
elif state == 'exported':
template = templates_module.search_entity()
export_service = templates_module._get_export_domain_service()
export_template = search_by_attributes(export_service.templates_service(), id=template.id)
ret = templates_module.action(
entity=template,
action='export',
action_condition=lambda t: export_template is None,
wait_condition=lambda t: t is not None,
post_action=templates_module.post_export_action,
storage_domain=otypes.StorageDomain(id=export_service.get().id),
exclusive=module.params['exclusive'],
)
elif state == 'imported':
template = templates_module.search_entity()
if template:
ret = templates_module.create(
result_state=otypes.TemplateStatus.OK,
)
else:
kwargs = {}
if module.params['image_provider']:
kwargs.update(
disk=otypes.Disk(
name=module.params['image_disk']
),
template=otypes.Template(
name=module.params['name'],
),
import_as_template=True,
)
if module.params['image_disk']:
# We need to refresh storage domain to get list of images:
templates_module._get_export_domain_service().images_service().list()
glance_service = connection.system_service().openstack_image_providers_service()
image_provider = search_by_name(glance_service, module.params['image_provider'])
images_service = glance_service.service(image_provider.id).images_service()
else:
images_service = templates_module._get_export_domain_service().templates_service()
template_name = module.params['image_disk'] or module.params['name']
entity = search_by_name(images_service, template_name)
if entity is None:
raise Exception("Image/template '%s' was not found." % template_name)
images_service.service(entity.id).import_(
storage_domain=otypes.StorageDomain(
name=module.params['storage_domain']
) if module.params['storage_domain'] else None,
cluster=otypes.Cluster(
name=module.params['cluster']
) if module.params['cluster'] else None,
**kwargs
)
template = wait_for_import(module, templates_service)
ret = {
'changed': True,
'id': template.id,
'template': get_dict_of_struct(template),
}
module.exit_json(**ret)
except Exception as e:
module.fail_json(msg=str(e), exception=traceback.format_exc())
finally:
connection.close(logout=auth.get('token') is None)
if __name__ == "__main__":
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
7800,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
21353,
63,
5876,
199,
3612,
63,
1802,
26,
5673,
370,
9635,
5791,
6844,
7009,
315,
312,
17146,
199,
1023,
63,
3270,
26,
298,
18,
14,
19,
2,
199,
2502,
26,
298,
47,
977,
345,
30611,
7984,
75,
8593,
14121,
7984,
75,
7835,
345,
2924,
199,
1802,
26,
272,
446,
298,
2377,
370,
9635,
5791,
6844,
7009,
315,
312,
17146,
2122,
199,
1419,
26,
272,
536,
26,
267,
1369,
26,
288,
446,
298,
985,
402,
314,
314,
1978,
370,
9635,
2122,
267,
1415,
26,
2549,
272,
1174,
26,
267,
1369,
26,
288,
446,
298,
11408,
314,
1978,
506,
3451,
15,
5575,
15,
23028,
15,
17932,
2,
267,
3415,
26,
788,
1881,
297,
283,
5575,
297,
283,
23028,
297,
283,
17932,
418,
267,
849,
26,
3451,
272,
4169,
26,
267,
1369,
26,
288,
446,
298,
985,
402,
314,
7525,
12,
1314,
911,
506,
1202,
370,
1218,
1978,
2122,
272,
1369,
26,
267,
1369,
26,
288,
446,
298,
5831,
402,
314,
1978,
2122,
272,
5033,
63,
2913,
26,
267,
1369,
26,
288,
446,
298,
11011,
4690,
370,
506,
663,
370,
1978,
2122,
272,
4350,
26,
267,
1369,
26,
288,
446,
298,
985,
402,
314,
4350,
12,
2382,
1978,
1077,
506,
2737,
15,
17932,
2122,
272,
13914,
26,
267,
1369,
26,
288,
446,
298,
11423,
445,
8,
929,
9,
365,
473,
8,
23028,
9,
642,
2725,
9126,
340,
314,
3411,
7009,
543,
314,
2049,
2011,
536,
1077,
506,
20200,
2122,
272,
4843,
63,
2261,
26,
267,
1369,
26,
288,
446,
298,
11423,
445,
8,
929,
9,
365,
473,
8,
23028,
9,
503,
473,
8,
17932,
9,
642,
2725,
9314,
314,
536,
402,
314,
2049,
4843,
4887,
2881,
2122,
272,
1834,
63,
3780,
26,
267,
1369,
26,
288,
446,
298,
11423,
445,
8,
929,
9,
365,
473,
8,
17932,
9,
642,
2725,
9314,
314,
536,
402,
314,
1834,
5022,
370,
506,
1202,
2122,
272,
1834,
63,
4032,
26,
267,
1369,
26,
288,
446,
298,
11423,
445,
8,
929,
9,
365,
473,
8,
17932,
9,
436,
445,
8,
1569,
63,
3780,
9,
365,
1202,
642,
2725,
9314,
314,
536,
402,
4543,
2049,
370,
506,
8439,
465,
1978,
2122,
272,
4887,
63,
2261,
26,
267,
1369,
26,
288,
446,
298,
11423,
445,
8,
929,
9,
365,
473,
8,
17932,
9,
642,
2725,
9314,
314,
536,
402,
314,
5724,
666,
4887,
2881,
2122,
272,
7289,
63,
6060,
26,
267,
1369,
26,
288,
446,
298,
3917,
473,
8,
549,
9,
2066,
314,
3443,
402,
314,
7525,
334,
2118,
314,
4125,
7869,
12,
440,
314,
12623,
7869,
9,
288,
911,
506,
8876,
370,
314,
2737,
1978,
2122,
288,
446,
298,
2765,
2725,
365,
1202,
1454,
1380,
445,
8,
929,
9,
473,
8,
1881,
17617,
267,
849,
26,
756,
199,
11036,
63,
9970,
63,
7677,
26,
21353,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
6058,
2793,
1133,
1395,
1790,
2725,
367,
17553,
3690,
12,
199,
3,
3648,
737,
21353,
63,
1178,
859,
370,
1937,
4212,
370,
12598,
6299,
26,
199,
199,
3,
2790,
1978,
687,
4169,
199,
13,
21353,
63,
5876,
26,
272,
4350,
26,
3758,
272,
536,
26,
3002,
1160,
272,
4169,
26,
26006,
352,
23,
272,
5033,
63,
2913,
26,
3758,
272,
1369,
26,
1379,
199,
199,
3,
3161,
1978,
199,
13,
21353,
63,
5876,
26,
523,
1174,
26,
8439,
523,
536,
26,
3002,
1160,
523,
4843,
63,
2261,
26,
3002,
3790,
523,
4887,
63,
2261,
26,
3002,
3494,
523,
4350,
26,
3002,
4201,
199,
199,
3,
5852,
1978,
199,
13,
21353,
63,
5876,
26,
272,
1174,
26,
9552,
272,
536,
26,
3002,
1160,
199,
2344,
199,
199,
9677,
275,
1449,
199,
344,
26,
272,
1369,
26,
2870,
402,
314,
1978,
1314,
365,
12883,
272,
2138,
26,
4068,
3182,
340,
1978,
365,
1911,
14,
272,
730,
26,
620,
272,
2690,
26,
1520,
271,
2710,
70,
2192,
13,
9485,
67,
13,
26319,
67,
13,
65,
17,
696,
13,
23,
69,
10027,
3691,
21,
66,
2259,
67,
199,
1160,
26,
272,
1369,
26,
298,
11728,
402,
1006,
314,
1978,
3004,
14,
5458,
3004,
883,
506,
1911,
641,
2195,
312,
17146,
1256,
2116,
737,
2569,
1166,
26,
4178,
921,
23334,
14,
2694,
14,
957,
15,
23334,
13,
3908,
15,
1246,
15,
1238,
3,
1313,
15,
1160,
2122,
272,
2138,
26,
4068,
3182,
340,
1978,
365,
1911,
14,
199,
2344,
199,
199,
646,
900,
199,
646,
5190,
199,
199,
893,
26,
272,
492,
312,
1042,
1086,
6341,
20,
14,
1313,
465,
312,
1313,
199,
2590,
3545,
26,
272,
986,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
23334,
492,
334,
272,
3523,
2377,
12,
272,
1104,
63,
9277,
12,
272,
1218,
63,
2105,
12,
272,
4472,
12,
272,
664,
63,
807,
63,
1618,
63,
1820,
12,
272,
664,
63,
1073,
63,
354
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
7800,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
21353,
63,
5876,
199,
3612,
63,
1802,
26,
5673,
370,
9635,
5791,
6844,
7009,
315,
312,
17146,
199,
1023,
63,
3270,
26,
298,
18,
14,
19,
2,
199,
2502,
26,
298,
47,
977,
345,
30611,
7984,
75,
8593,
14121,
7984,
75,
7835,
345,
2924,
199,
1802,
26,
272,
446,
298,
2377,
370,
9635,
5791,
6844,
7009,
315,
312,
17146,
2122,
199,
1419,
26,
272,
536,
26,
267,
1369,
26,
288,
446,
298,
985,
402,
314,
314,
1978,
370,
9635,
2122,
267,
1415,
26,
2549,
272,
1174,
26,
267,
1369,
26,
288,
446,
298,
11408,
314,
1978,
506,
3451,
15,
5575,
15,
23028,
15,
17932,
2,
267,
3415,
26,
788,
1881,
297,
283,
5575,
297,
283,
23028,
297,
283,
17932,
418,
267,
849,
26,
3451,
272,
4169,
26,
267,
1369,
26,
288,
446,
298,
985,
402,
314,
7525,
12,
1314,
911,
506,
1202,
370,
1218,
1978,
2122,
272,
1369,
26,
267,
1369,
26,
288,
446,
298,
5831,
402,
314,
1978,
2122,
272,
5033,
63,
2913,
26,
267,
1369,
26,
288,
446,
298,
11011,
4690,
370,
506,
663,
370,
1978,
2122,
272,
4350,
26,
267,
1369,
26,
288,
446,
298,
985,
402,
314,
4350,
12,
2382,
1978,
1077,
506,
2737,
15,
17932,
2122,
272,
13914,
26,
267,
1369,
26,
288,
446,
298,
11423,
445,
8,
929,
9,
365,
473,
8,
23028,
9,
642,
2725,
9126,
340,
314,
3411,
7009,
543,
314,
2049,
2011,
536,
1077,
506,
20200,
2122,
272,
4843,
63,
2261,
26,
267,
1369,
26,
288,
446,
298,
11423,
445,
8,
929,
9,
365,
473,
8,
23028,
9,
503,
473,
8,
17932,
9,
642,
2725,
9314,
314,
536,
402,
314,
2049,
4843,
4887,
2881,
2122,
272,
1834,
63,
3780,
26,
267,
1369,
26,
288,
446,
298,
11423,
445,
8,
929,
9,
365,
473,
8,
17932,
9,
642,
2725,
9314,
314,
536,
402,
314,
1834,
5022,
370,
506,
1202,
2122,
272,
1834,
63,
4032,
26,
267,
1369,
26,
288,
446,
298,
11423,
445,
8,
929,
9,
365,
473,
8,
17932,
9,
436,
445,
8,
1569,
63,
3780,
9,
365,
1202,
642,
2725,
9314,
314,
536,
402,
4543,
2049,
370,
506,
8439,
465,
1978,
2122,
272,
4887,
63,
2261,
26,
267,
1369,
26,
288,
446,
298,
11423,
445,
8,
929,
9,
365,
473,
8,
17932,
9,
642,
2725,
9314,
314,
536,
402,
314,
5724,
666,
4887,
2881,
2122,
272,
7289,
63,
6060,
26,
267,
1369,
26,
288,
446,
298,
3917,
473,
8,
549,
9,
2066,
314,
3443,
402,
314,
7525,
334,
2118,
314,
4125,
7869,
12,
440,
314,
12623,
7869,
9,
288,
911,
506,
8876,
370,
314,
2737,
1978,
2122,
288,
446,
298,
2765,
2725,
365,
1202,
1454,
1380,
445,
8,
929,
9,
473,
8,
1881,
17617,
267,
849,
26,
756,
199,
11036,
63,
9970,
63,
7677,
26,
21353,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
6058,
2793,
1133,
1395,
1790,
2725,
367,
17553,
3690,
12,
199,
3,
3648,
737,
21353,
63,
1178,
859,
370,
1937,
4212,
370,
12598,
6299,
26,
199,
199,
3,
2790,
1978,
687,
4169,
199,
13,
21353,
63,
5876,
26,
272,
4350,
26,
3758,
272,
536,
26,
3002,
1160,
272,
4169,
26,
26006,
352,
23,
272,
5033,
63,
2913,
26,
3758,
272,
1369,
26,
1379,
199,
199,
3,
3161,
1978,
199,
13,
21353,
63,
5876,
26,
523,
1174,
26,
8439,
523,
536,
26,
3002,
1160,
523,
4843,
63,
2261,
26,
3002,
3790,
523,
4887,
63,
2261,
26,
3002,
3494,
523,
4350,
26,
3002,
4201,
199,
199,
3,
5852,
1978,
199,
13,
21353,
63,
5876,
26,
272,
1174,
26,
9552,
272,
536,
26,
3002,
1160,
199,
2344,
199,
199,
9677,
275,
1449,
199,
344,
26,
272,
1369,
26,
2870,
402,
314,
1978,
1314,
365,
12883,
272,
2138,
26,
4068,
3182,
340,
1978,
365,
1911,
14,
272,
730,
26,
620,
272,
2690,
26,
1520,
271,
2710,
70,
2192,
13,
9485,
67,
13,
26319,
67,
13,
65,
17,
696,
13,
23,
69,
10027,
3691,
21,
66,
2259,
67,
199,
1160,
26,
272,
1369,
26,
298,
11728,
402,
1006,
314,
1978,
3004,
14,
5458,
3004,
883,
506,
1911,
641,
2195,
312,
17146,
1256,
2116,
737,
2569,
1166,
26,
4178,
921,
23334,
14,
2694,
14,
957,
15,
23334,
13,
3908,
15,
1246,
15,
1238,
3,
1313,
15,
1160,
2122,
272,
2138,
26,
4068,
3182,
340,
1978,
365,
1911,
14,
199,
2344,
199,
199,
646,
900,
199,
646,
5190,
199,
199,
893,
26,
272,
492,
312,
1042,
1086,
6341,
20,
14,
1313,
465,
312,
1313,
199,
2590,
3545,
26,
272,
986,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
23334,
492,
334,
272,
3523,
2377,
12,
272,
1104,
63,
9277,
12,
272,
1218,
63,
2105,
12,
272,
4472,
12,
272,
664,
63,
807,
63,
1618,
63,
1820,
12,
272,
664,
63,
1073,
63,
354,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
thinkopensolutions/tkobr-addons
|
unported/tko_partner_sequence/__openerp__.py
|
2
|
1846
|
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# ThinkOpen Solutions Brasil
# Copyright (C) Thinkopen Solutions <http://www.tkobr.com>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Partner Sequence Unique Number',
'version': '0.001',
'category': 'Localisation',
'sequence': 2,
'complexity': 'normal',
'description': '''This module adds an automatic sequencial number to every partner.''',
'author': 'ThinkOpen Solutions Brasil',
'license': 'AGPL-3',
'website': 'http://www.tkobr.com',
'depends': [
'base',
],
'data': [
'partner_sequence.xml',
'res_partner_view.xml',
],
'init': [],
'demo': [],
'update': [],
'test': [], # YAML files with tests
'installable': True,
'application': False,
# If it's True, the modules will be auto-installed when all dependencies
# are installed
'auto_install': False,
'certificate': '',
}
|
agpl-3.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
3868,
2292,
4299,
17991,
8653,
699,
6360,
382,
199,
3,
259,
1898,
334,
35,
9,
3868,
2292,
1490,
17991,
8653,
665,
1014,
921,
1544,
14,
2663,
2873,
82,
14,
957,
10827,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
91,
272,
283,
354,
356,
283,
24120,
10975,
18276,
4860,
297,
272,
283,
1023,
356,
283,
16,
14,
4587,
297,
272,
283,
3710,
356,
283,
5339,
19914,
297,
272,
283,
4041,
356,
499,
12,
272,
283,
5254,
1209,
356,
283,
3302,
297,
272,
283,
1802,
356,
1449,
2765,
859,
9584,
376,
4834,
542,
1514,
7180,
1329,
370,
4036,
5854,
14,
18108,
272,
283,
2502,
356,
283,
2719,
2292,
4299,
17991,
8653,
699,
6360,
382,
297,
272,
283,
1682,
356,
283,
1254,
2749,
13,
19,
297,
272,
283,
7360,
356,
283,
1014,
921,
1544,
14,
2663,
2873,
82,
14,
957,
297,
272,
283,
8912,
356,
359,
267,
283,
1095,
297,
272,
2156,
339,
283,
576,
356,
359,
267,
283,
3899,
63,
4041,
14,
1652,
297,
267,
283,
470,
63,
3899,
63,
1345,
14,
1652,
297,
272,
2156,
272,
283,
826,
356,
990,
272,
283,
8768,
356,
990,
272,
283,
873,
356,
990,
272,
283,
396,
356,
990,
221,
327,
18916,
1584,
543,
2295,
272,
283,
21762,
356,
715,
12,
272,
283,
3578,
356,
756,
12,
272,
327,
982,
652,
1159,
715,
12,
314,
4621,
911,
506,
2599,
13,
7657,
1380,
1006,
5124,
272,
327,
787,
4903,
272,
283,
2495,
63,
3174,
356,
756,
12,
272,
283,
6999,
356,
3260,
199,
93,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
3868,
2292,
4299,
17991,
8653,
699,
6360,
382,
199,
3,
259,
1898,
334,
35,
9,
3868,
2292,
1490,
17991,
8653,
665,
1014,
921,
1544,
14,
2663,
2873,
82,
14,
957,
10827,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
91,
272,
283,
354,
356,
283,
24120,
10975,
18276,
4860,
297,
272,
283,
1023,
356,
283,
16,
14,
4587,
297,
272,
283,
3710,
356,
283,
5339,
19914,
297,
272,
283,
4041,
356,
499,
12,
272,
283,
5254,
1209,
356,
283,
3302,
297,
272,
283,
1802,
356,
1449,
2765,
859,
9584,
376,
4834,
542,
1514,
7180,
1329,
370,
4036,
5854,
14,
18108,
272,
283,
2502,
356,
283,
2719,
2292,
4299,
17991,
8653,
699,
6360,
382,
297,
272,
283,
1682,
356,
283,
1254,
2749,
13,
19,
297,
272,
283,
7360,
356,
283,
1014,
921,
1544,
14,
2663,
2873,
82,
14,
957,
297,
272,
283,
8912,
356,
359,
267,
283,
1095,
297,
272,
2156,
339,
283,
576,
356,
359,
267,
283,
3899,
63,
4041,
14,
1652,
297,
267,
283,
470,
63,
3899,
63,
1345,
14,
1652,
297,
272,
2156,
272,
283,
826,
356,
990,
272,
283,
8768,
356,
990,
272,
283,
873,
356,
990,
272,
283,
396,
356,
990,
221,
327,
18916,
1584,
543,
2295,
272,
283,
21762,
356,
715,
12,
272,
283,
3578,
356,
756,
12,
272,
327,
982,
652,
1159,
715,
12,
314,
4621,
911,
506,
2599,
13,
7657,
1380,
1006,
5124,
272,
327,
787,
4903,
272,
283,
2495,
63,
3174,
356,
756,
12,
272,
283,
6999,
356,
3260,
199,
93,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
elmerdpadilla/iv
|
addons/mrp_repair/__init__.py
|
380
|
1087
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import mrp_repair
import wizard
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
199,
646,
333,
4599,
63,
25279,
199,
646,
12262,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
199,
646,
333,
4599,
63,
25279,
199,
646,
12262,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
jfelectron/python-driver
|
tests/unit/test_host_connection_pool.py
|
7
|
10033
|
# Copyright 2013-2015 DataStax, 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.
try:
import unittest2 as unittest
except ImportError:
import unittest # noqa
from mock import Mock, NonCallableMagicMock
from threading import Thread, Event, Lock
from cassandra.cluster import Session
from cassandra.connection import Connection
from cassandra.pool import Host, HostConnectionPool, NoConnectionsAvailable
from cassandra.policies import HostDistance, SimpleConvictionPolicy
class HostConnectionPoolTests(unittest.TestCase):
def make_session(self):
session = NonCallableMagicMock(spec=Session, keyspace='foobarkeyspace')
session.cluster.get_core_connections_per_host.return_value = 1
session.cluster.get_max_requests_per_connection.return_value = 1
session.cluster.get_max_connections_per_host.return_value = 1
return session
def test_borrow_and_return(self):
host = Mock(spec=Host, address='ip1')
session = self.make_session()
conn = NonCallableMagicMock(spec=Connection, in_flight=0, is_defunct=False, is_closed=False, max_request_id=100)
session.cluster.connection_factory.return_value = conn
pool = HostConnectionPool(host, HostDistance.LOCAL, session)
session.cluster.connection_factory.assert_called_once_with(host.address)
c, request_id = pool.borrow_connection(timeout=0.01)
self.assertIs(c, conn)
self.assertEqual(1, conn.in_flight)
conn.set_keyspace_blocking.assert_called_once_with('foobarkeyspace')
pool.return_connection(conn)
self.assertEqual(0, conn.in_flight)
self.assertNotIn(conn, pool._trash)
def test_failed_wait_for_connection(self):
host = Mock(spec=Host, address='ip1')
session = self.make_session()
conn = NonCallableMagicMock(spec=Connection, in_flight=0, is_defunct=False, is_closed=False, max_request_id=100)
session.cluster.connection_factory.return_value = conn
pool = HostConnectionPool(host, HostDistance.LOCAL, session)
session.cluster.connection_factory.assert_called_once_with(host.address)
pool.borrow_connection(timeout=0.01)
self.assertEqual(1, conn.in_flight)
conn.in_flight = conn.max_request_id
# we're already at the max number of requests for this connection,
# so we this should fail
self.assertRaises(NoConnectionsAvailable, pool.borrow_connection, 0)
def test_successful_wait_for_connection(self):
host = Mock(spec=Host, address='ip1')
session = self.make_session()
conn = NonCallableMagicMock(spec=Connection, in_flight=0, is_defunct=False, is_closed=False, max_request_id=100, lock=Lock())
session.cluster.connection_factory.return_value = conn
pool = HostConnectionPool(host, HostDistance.LOCAL, session)
session.cluster.connection_factory.assert_called_once_with(host.address)
pool.borrow_connection(timeout=0.01)
self.assertEqual(1, conn.in_flight)
def get_second_conn():
c, request_id = pool.borrow_connection(1.0)
self.assertIs(conn, c)
pool.return_connection(c)
t = Thread(target=get_second_conn)
t.start()
pool.return_connection(conn)
t.join()
self.assertEqual(0, conn.in_flight)
def test_all_connections_trashed(self):
host = Mock(spec=Host, address='ip1')
session = self.make_session()
conn = NonCallableMagicMock(spec=Connection, in_flight=0, is_defunct=False, is_closed=False, max_request_id=100, lock=Lock())
session.cluster.connection_factory.return_value = conn
session.cluster.get_core_connections_per_host.return_value = 1
# manipulate the core connection setting so that we can
# trash the only connection
pool = HostConnectionPool(host, HostDistance.LOCAL, session)
session.cluster.get_core_connections_per_host.return_value = 0
pool._maybe_trash_connection(conn)
session.cluster.get_core_connections_per_host.return_value = 1
submit_called = Event()
def fire_event(*args, **kwargs):
submit_called.set()
session.submit.side_effect = fire_event
def get_conn():
conn.reset_mock()
c, request_id = pool.borrow_connection(1.0)
self.assertIs(conn, c)
self.assertEqual(1, conn.in_flight)
conn.set_keyspace_blocking.assert_called_once_with('foobarkeyspace')
pool.return_connection(c)
t = Thread(target=get_conn)
t.start()
submit_called.wait()
self.assertEqual(1, pool._scheduled_for_creation)
session.submit.assert_called_once_with(pool._create_new_connection)
# now run the create_new_connection call
pool._create_new_connection()
t.join()
self.assertEqual(0, conn.in_flight)
def test_spawn_when_at_max(self):
host = Mock(spec=Host, address='ip1')
session = self.make_session()
conn = NonCallableMagicMock(spec=Connection, in_flight=0, is_defunct=False, is_closed=False, max_request_id=100)
conn.max_request_id = 100
session.cluster.connection_factory.return_value = conn
# core conns = 1, max conns = 2
session.cluster.get_max_connections_per_host.return_value = 2
pool = HostConnectionPool(host, HostDistance.LOCAL, session)
session.cluster.connection_factory.assert_called_once_with(host.address)
pool.borrow_connection(timeout=0.01)
self.assertEqual(1, conn.in_flight)
# make this conn full
conn.in_flight = conn.max_request_id
# we don't care about making this borrow_connection call succeed for the
# purposes of this test, as long as it results in a new connection
# creation being scheduled
self.assertRaises(NoConnectionsAvailable, pool.borrow_connection, 0)
session.submit.assert_called_once_with(pool._create_new_connection)
def test_return_defunct_connection(self):
host = Mock(spec=Host, address='ip1')
session = self.make_session()
conn = NonCallableMagicMock(spec=Connection, in_flight=0, is_defunct=False, is_closed=False, max_request_id=100)
session.cluster.connection_factory.return_value = conn
pool = HostConnectionPool(host, HostDistance.LOCAL, session)
session.cluster.connection_factory.assert_called_once_with(host.address)
pool.borrow_connection(timeout=0.01)
conn.is_defunct = True
session.cluster.signal_connection_failure.return_value = False
pool.return_connection(conn)
# the connection should be closed a new creation scheduled
conn.close.assert_called_once()
session.submit.assert_called_once()
self.assertFalse(pool.is_shutdown)
def test_return_defunct_connection_on_down_host(self):
host = Mock(spec=Host, address='ip1')
session = self.make_session()
conn = NonCallableMagicMock(spec=Connection, in_flight=0, is_defunct=False, is_closed=False, max_request_id=100, signaled_error=False)
session.cluster.connection_factory.return_value = conn
pool = HostConnectionPool(host, HostDistance.LOCAL, session)
session.cluster.connection_factory.assert_called_once_with(host.address)
pool.borrow_connection(timeout=0.01)
conn.is_defunct = True
session.cluster.signal_connection_failure.return_value = True
pool.return_connection(conn)
# the connection should be closed a new creation scheduled
session.cluster.signal_connection_failure.assert_called_once()
conn.close.assert_called_once()
self.assertFalse(session.submit.called)
self.assertTrue(pool.is_shutdown)
def test_return_closed_connection(self):
host = Mock(spec=Host, address='ip1')
session = self.make_session()
conn = NonCallableMagicMock(spec=Connection, in_flight=0, is_defunct=False, is_closed=True, max_request_id=100)
session.cluster.connection_factory.return_value = conn
pool = HostConnectionPool(host, HostDistance.LOCAL, session)
session.cluster.connection_factory.assert_called_once_with(host.address)
pool.borrow_connection(timeout=0.01)
conn.is_closed = True
session.cluster.signal_connection_failure.return_value = False
pool.return_connection(conn)
# a new creation should be scheduled
session.submit.assert_called_once()
self.assertFalse(pool.is_shutdown)
def test_host_instantiations(self):
"""
Ensure Host fails if not initialized properly
"""
self.assertRaises(ValueError, Host, None, None)
self.assertRaises(ValueError, Host, '127.0.0.1', None)
self.assertRaises(ValueError, Host, None, SimpleConvictionPolicy)
def test_host_equality(self):
"""
Test host equality has correct logic
"""
a = Host('127.0.0.1', SimpleConvictionPolicy)
b = Host('127.0.0.1', SimpleConvictionPolicy)
c = Host('127.0.0.2', SimpleConvictionPolicy)
self.assertEqual(a, b, 'Two Host instances should be equal when sharing.')
self.assertNotEqual(a, c, 'Two Host instances should NOT be equal when using two different addresses.')
self.assertNotEqual(b, c, 'Two Host instances should NOT be equal when using two different addresses.')
|
apache-2.0
|
[
3,
1898,
6171,
13,
7806,
3918,
3391,
88,
12,
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,
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,
893,
26,
272,
492,
2882,
18,
465,
2882,
199,
2590,
3545,
26,
272,
492,
2882,
327,
8151,
199,
199,
504,
1683,
492,
4420,
12,
10172,
16410,
11988,
199,
504,
5796,
492,
11086,
12,
6763,
12,
15536,
199,
199,
504,
286,
22388,
14,
4201,
492,
8596,
199,
504,
286,
22388,
14,
2105,
492,
8113,
199,
504,
286,
22388,
14,
2293,
492,
10891,
12,
10891,
23929,
12,
3091,
22122,
11464,
199,
504,
286,
22388,
14,
11767,
492,
10891,
10076,
12,
5870,
714,
433,
414,
4845,
421,
199,
533,
10891,
23929,
2925,
8,
2796,
14,
1746,
304,
339,
347,
1852,
63,
1730,
8,
277,
304,
267,
2351,
275,
10172,
16410,
11988,
8,
1650,
29,
4434,
12,
27710,
534,
9664,
16365,
358,
267,
2351,
14,
4201,
14,
362,
63,
1018,
63,
7995,
63,
529,
63,
1102,
14,
1107,
63,
585,
275,
413,
267,
2351,
14,
4201,
14,
362,
63,
988,
63,
6615,
63,
529,
63,
2105,
14,
1107,
63,
585,
275,
413,
267,
2351,
14,
4201,
14,
362,
63,
988,
63,
7995,
63,
529,
63,
1102,
14,
1107,
63,
585,
275,
413,
267,
372,
2351,
339,
347,
511,
63,
66,
19598,
63,
460,
63,
1107,
8,
277,
304,
267,
1591,
275,
4420,
8,
1650,
29,
4965,
12,
2287,
534,
711,
17,
358,
267,
2351,
275,
291,
14,
1875,
63,
1730,
342,
267,
2557,
275,
10172,
16410,
11988,
8,
1650,
29,
3225,
12,
315,
63,
28807,
29,
16,
12,
365,
63,
318,
4638,
29,
797,
12,
365,
63,
5938,
29,
797,
12,
1390,
63,
1069,
63,
344,
29,
1960,
9,
267,
2351,
14,
4201,
14,
2105,
63,
3702,
14,
1107,
63,
585,
275,
2557,
398,
4203,
275,
10891,
23929,
8,
1102,
12,
10891,
10076,
14,
7486,
12,
2351,
9,
267,
2351,
14,
4201,
14,
2105,
63,
3702,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
1102,
14,
1562,
9,
398,
286,
12,
1056,
63,
344,
275,
4203,
14,
66,
19598,
63,
2105,
8,
2593,
29,
16,
14,
614,
9,
267,
291,
14,
3436,
8,
67,
12,
2557,
9,
267,
291,
14,
629,
8,
17,
12,
2557,
14,
262,
63,
28807,
9,
267,
2557,
14,
409,
63,
16365,
63,
13091,
14,
479,
63,
3527,
63,
5089,
63,
1045,
360,
9664,
16365,
358,
398,
4203,
14,
1107,
63,
2105,
8,
1631,
9,
267,
291,
14,
629,
8,
16,
12,
2557,
14,
262,
63,
28807,
9,
267,
291,
14,
8795,
8,
1631,
12,
4203,
423,
28272,
9,
339,
347,
511,
63,
4892,
63,
2573,
63,
509,
63,
2105,
8,
277,
304,
267,
1591,
275,
4420,
8,
1650,
29,
4965,
12,
2287,
534,
711,
17,
358,
267,
2351,
275,
291,
14,
1875,
63,
1730,
342,
267,
2557,
275,
10172,
16410,
11988,
8,
1650,
29,
3225,
12,
315,
63,
28807,
29,
16,
12,
365,
63,
318,
4638,
29,
797,
12,
365,
63,
5938,
29,
797,
12,
1390,
63,
1069,
63,
344,
29,
1960,
9,
267,
2351,
14,
4201,
14,
2105,
63,
3702,
14,
1107,
63,
585,
275,
2557,
398,
4203,
275,
10891,
23929,
8,
1102,
12,
10891,
10076,
14,
7486,
12,
2351,
9,
267,
2351,
14,
4201,
14,
2105,
63,
3702,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
1102,
14,
1562,
9,
398,
4203,
14,
66,
19598,
63,
2105,
8,
2593,
29,
16,
14,
614,
9,
267,
291,
14,
629,
8,
17,
12,
2557,
14,
262,
63,
28807,
9,
398,
2557,
14,
262,
63,
28807,
275,
2557,
14,
988,
63,
1069,
63,
344,
398,
327,
781,
3984,
2575,
737,
314,
1390,
1329,
402,
4145,
367,
642,
1950,
12,
267,
327,
880,
781,
642,
1077,
2449,
267,
291,
14,
1855,
8,
1944,
22122,
11464,
12,
4203,
14,
66,
19598,
63,
2105,
12,
378,
9,
339,
347,
511,
63,
18157,
63,
2573,
63,
509,
63,
2105,
8,
277,
304,
267,
1591,
275,
4420,
8,
1650,
29,
4965,
12,
2287,
534,
711,
17,
358,
267,
2351,
275,
291,
14,
1875,
63,
1730,
342,
267,
2557,
275,
10172,
16410,
11988,
8,
1650,
29,
3225,
12,
315,
63,
28807,
29,
16,
12,
365,
63,
318,
4638,
29,
797,
12,
365,
63,
5938,
29,
797,
12,
1390,
63,
1069,
63,
344,
29,
1960,
12,
4650,
29,
6432,
1012,
267,
2351,
14,
4201,
14,
2105,
63,
3702,
14,
1107,
63,
585,
275,
2557,
398,
4203,
275,
10891,
23929,
8,
1102,
12,
10891,
10076,
14,
7486,
12,
2351,
9,
267,
2351,
14,
4201,
14,
2105,
63,
3702,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
1102,
14,
1562,
9,
398,
4203,
14,
66,
19598,
63,
2105,
8,
2593,
29,
16,
14,
614,
9,
267,
291,
14,
629,
8,
17,
12,
2557,
14,
262,
63,
28807,
9,
398,
347,
664,
63,
4375,
63,
1631,
837,
288,
286,
12,
1056,
63,
344,
275,
4203,
14,
66,
19598,
63,
2105,
8,
17,
14,
16,
9,
288,
291,
14,
3436,
8,
1631,
12,
286,
9,
288,
4203,
14,
1107,
63,
2105,
8,
67,
9,
398,
307,
275,
11086,
8,
1375,
29,
362,
63,
4375,
63,
1631,
9,
267,
307,
14,
928,
342,
398,
4203,
14,
1107,
63,
2105,
8,
1631,
9,
267,
307,
14,
904,
342,
267,
291,
14,
629,
8,
16,
12,
2557,
14,
262,
63,
28807,
9,
339,
347,
511,
63,
452,
63,
7995,
63,
454,
21189,
8,
277,
304,
267,
1591,
275,
4420,
8,
1650,
29,
4965,
12,
2287,
534,
711,
17,
358,
267,
2351,
275
] |
[
1898,
6171,
13,
7806,
3918,
3391,
88,
12,
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,
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,
893,
26,
272,
492,
2882,
18,
465,
2882,
199,
2590,
3545,
26,
272,
492,
2882,
327,
8151,
199,
199,
504,
1683,
492,
4420,
12,
10172,
16410,
11988,
199,
504,
5796,
492,
11086,
12,
6763,
12,
15536,
199,
199,
504,
286,
22388,
14,
4201,
492,
8596,
199,
504,
286,
22388,
14,
2105,
492,
8113,
199,
504,
286,
22388,
14,
2293,
492,
10891,
12,
10891,
23929,
12,
3091,
22122,
11464,
199,
504,
286,
22388,
14,
11767,
492,
10891,
10076,
12,
5870,
714,
433,
414,
4845,
421,
199,
533,
10891,
23929,
2925,
8,
2796,
14,
1746,
304,
339,
347,
1852,
63,
1730,
8,
277,
304,
267,
2351,
275,
10172,
16410,
11988,
8,
1650,
29,
4434,
12,
27710,
534,
9664,
16365,
358,
267,
2351,
14,
4201,
14,
362,
63,
1018,
63,
7995,
63,
529,
63,
1102,
14,
1107,
63,
585,
275,
413,
267,
2351,
14,
4201,
14,
362,
63,
988,
63,
6615,
63,
529,
63,
2105,
14,
1107,
63,
585,
275,
413,
267,
2351,
14,
4201,
14,
362,
63,
988,
63,
7995,
63,
529,
63,
1102,
14,
1107,
63,
585,
275,
413,
267,
372,
2351,
339,
347,
511,
63,
66,
19598,
63,
460,
63,
1107,
8,
277,
304,
267,
1591,
275,
4420,
8,
1650,
29,
4965,
12,
2287,
534,
711,
17,
358,
267,
2351,
275,
291,
14,
1875,
63,
1730,
342,
267,
2557,
275,
10172,
16410,
11988,
8,
1650,
29,
3225,
12,
315,
63,
28807,
29,
16,
12,
365,
63,
318,
4638,
29,
797,
12,
365,
63,
5938,
29,
797,
12,
1390,
63,
1069,
63,
344,
29,
1960,
9,
267,
2351,
14,
4201,
14,
2105,
63,
3702,
14,
1107,
63,
585,
275,
2557,
398,
4203,
275,
10891,
23929,
8,
1102,
12,
10891,
10076,
14,
7486,
12,
2351,
9,
267,
2351,
14,
4201,
14,
2105,
63,
3702,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
1102,
14,
1562,
9,
398,
286,
12,
1056,
63,
344,
275,
4203,
14,
66,
19598,
63,
2105,
8,
2593,
29,
16,
14,
614,
9,
267,
291,
14,
3436,
8,
67,
12,
2557,
9,
267,
291,
14,
629,
8,
17,
12,
2557,
14,
262,
63,
28807,
9,
267,
2557,
14,
409,
63,
16365,
63,
13091,
14,
479,
63,
3527,
63,
5089,
63,
1045,
360,
9664,
16365,
358,
398,
4203,
14,
1107,
63,
2105,
8,
1631,
9,
267,
291,
14,
629,
8,
16,
12,
2557,
14,
262,
63,
28807,
9,
267,
291,
14,
8795,
8,
1631,
12,
4203,
423,
28272,
9,
339,
347,
511,
63,
4892,
63,
2573,
63,
509,
63,
2105,
8,
277,
304,
267,
1591,
275,
4420,
8,
1650,
29,
4965,
12,
2287,
534,
711,
17,
358,
267,
2351,
275,
291,
14,
1875,
63,
1730,
342,
267,
2557,
275,
10172,
16410,
11988,
8,
1650,
29,
3225,
12,
315,
63,
28807,
29,
16,
12,
365,
63,
318,
4638,
29,
797,
12,
365,
63,
5938,
29,
797,
12,
1390,
63,
1069,
63,
344,
29,
1960,
9,
267,
2351,
14,
4201,
14,
2105,
63,
3702,
14,
1107,
63,
585,
275,
2557,
398,
4203,
275,
10891,
23929,
8,
1102,
12,
10891,
10076,
14,
7486,
12,
2351,
9,
267,
2351,
14,
4201,
14,
2105,
63,
3702,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
1102,
14,
1562,
9,
398,
4203,
14,
66,
19598,
63,
2105,
8,
2593,
29,
16,
14,
614,
9,
267,
291,
14,
629,
8,
17,
12,
2557,
14,
262,
63,
28807,
9,
398,
2557,
14,
262,
63,
28807,
275,
2557,
14,
988,
63,
1069,
63,
344,
398,
327,
781,
3984,
2575,
737,
314,
1390,
1329,
402,
4145,
367,
642,
1950,
12,
267,
327,
880,
781,
642,
1077,
2449,
267,
291,
14,
1855,
8,
1944,
22122,
11464,
12,
4203,
14,
66,
19598,
63,
2105,
12,
378,
9,
339,
347,
511,
63,
18157,
63,
2573,
63,
509,
63,
2105,
8,
277,
304,
267,
1591,
275,
4420,
8,
1650,
29,
4965,
12,
2287,
534,
711,
17,
358,
267,
2351,
275,
291,
14,
1875,
63,
1730,
342,
267,
2557,
275,
10172,
16410,
11988,
8,
1650,
29,
3225,
12,
315,
63,
28807,
29,
16,
12,
365,
63,
318,
4638,
29,
797,
12,
365,
63,
5938,
29,
797,
12,
1390,
63,
1069,
63,
344,
29,
1960,
12,
4650,
29,
6432,
1012,
267,
2351,
14,
4201,
14,
2105,
63,
3702,
14,
1107,
63,
585,
275,
2557,
398,
4203,
275,
10891,
23929,
8,
1102,
12,
10891,
10076,
14,
7486,
12,
2351,
9,
267,
2351,
14,
4201,
14,
2105,
63,
3702,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
1102,
14,
1562,
9,
398,
4203,
14,
66,
19598,
63,
2105,
8,
2593,
29,
16,
14,
614,
9,
267,
291,
14,
629,
8,
17,
12,
2557,
14,
262,
63,
28807,
9,
398,
347,
664,
63,
4375,
63,
1631,
837,
288,
286,
12,
1056,
63,
344,
275,
4203,
14,
66,
19598,
63,
2105,
8,
17,
14,
16,
9,
288,
291,
14,
3436,
8,
1631,
12,
286,
9,
288,
4203,
14,
1107,
63,
2105,
8,
67,
9,
398,
307,
275,
11086,
8,
1375,
29,
362,
63,
4375,
63,
1631,
9,
267,
307,
14,
928,
342,
398,
4203,
14,
1107,
63,
2105,
8,
1631,
9,
267,
307,
14,
904,
342,
267,
291,
14,
629,
8,
16,
12,
2557,
14,
262,
63,
28807,
9,
339,
347,
511,
63,
452,
63,
7995,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
tensorflow/models
|
research/object_detection/inference/detection_inference.py
|
2
|
5516
|
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Utility functions for detection inference."""
from __future__ import division
import tensorflow.compat.v1 as tf
from object_detection.core import standard_fields
def build_input(tfrecord_paths):
"""Builds the graph's input.
Args:
tfrecord_paths: List of paths to the input TFRecords
Returns:
serialized_example_tensor: The next serialized example. String scalar Tensor
image_tensor: The decoded image of the example. Uint8 tensor,
shape=[1, None, None,3]
"""
filename_queue = tf.train.string_input_producer(
tfrecord_paths, shuffle=False, num_epochs=1)
tf_record_reader = tf.TFRecordReader()
_, serialized_example_tensor = tf_record_reader.read(filename_queue)
features = tf.parse_single_example(
serialized_example_tensor,
features={
standard_fields.TfExampleFields.image_encoded:
tf.FixedLenFeature([], tf.string),
})
encoded_image = features[standard_fields.TfExampleFields.image_encoded]
image_tensor = tf.image.decode_image(encoded_image, channels=3)
image_tensor.set_shape([None, None, 3])
image_tensor = tf.expand_dims(image_tensor, 0)
return serialized_example_tensor, image_tensor
def build_inference_graph(image_tensor, inference_graph_path):
"""Loads the inference graph and connects it to the input image.
Args:
image_tensor: The input image. uint8 tensor, shape=[1, None, None, 3]
inference_graph_path: Path to the inference graph with embedded weights
Returns:
detected_boxes_tensor: Detected boxes. Float tensor,
shape=[num_detections, 4]
detected_scores_tensor: Detected scores. Float tensor,
shape=[num_detections]
detected_labels_tensor: Detected labels. Int64 tensor,
shape=[num_detections]
"""
with tf.gfile.Open(inference_graph_path, 'rb') as graph_def_file:
graph_content = graph_def_file.read()
graph_def = tf.GraphDef()
graph_def.MergeFromString(graph_content)
tf.import_graph_def(
graph_def, name='', input_map={'image_tensor': image_tensor})
g = tf.get_default_graph()
num_detections_tensor = tf.squeeze(
g.get_tensor_by_name('num_detections:0'), 0)
num_detections_tensor = tf.cast(num_detections_tensor, tf.int32)
detected_boxes_tensor = tf.squeeze(
g.get_tensor_by_name('detection_boxes:0'), 0)
detected_boxes_tensor = detected_boxes_tensor[:num_detections_tensor]
detected_scores_tensor = tf.squeeze(
g.get_tensor_by_name('detection_scores:0'), 0)
detected_scores_tensor = detected_scores_tensor[:num_detections_tensor]
detected_labels_tensor = tf.squeeze(
g.get_tensor_by_name('detection_classes:0'), 0)
detected_labels_tensor = tf.cast(detected_labels_tensor, tf.int64)
detected_labels_tensor = detected_labels_tensor[:num_detections_tensor]
return detected_boxes_tensor, detected_scores_tensor, detected_labels_tensor
def infer_detections_and_add_to_example(
serialized_example_tensor, detected_boxes_tensor, detected_scores_tensor,
detected_labels_tensor, discard_image_pixels):
"""Runs the supplied tensors and adds the inferred detections to the example.
Args:
serialized_example_tensor: Serialized TF example. Scalar string tensor
detected_boxes_tensor: Detected boxes. Float tensor,
shape=[num_detections, 4]
detected_scores_tensor: Detected scores. Float tensor,
shape=[num_detections]
detected_labels_tensor: Detected labels. Int64 tensor,
shape=[num_detections]
discard_image_pixels: If true, discards the image from the result
Returns:
The de-serialized TF example augmented with the inferred detections.
"""
tf_example = tf.train.Example()
(serialized_example, detected_boxes, detected_scores,
detected_classes) = tf.get_default_session().run([
serialized_example_tensor, detected_boxes_tensor, detected_scores_tensor,
detected_labels_tensor
])
detected_boxes = detected_boxes.T
tf_example.ParseFromString(serialized_example)
feature = tf_example.features.feature
feature[standard_fields.TfExampleFields.
detection_score].float_list.value[:] = detected_scores
feature[standard_fields.TfExampleFields.
detection_bbox_ymin].float_list.value[:] = detected_boxes[0]
feature[standard_fields.TfExampleFields.
detection_bbox_xmin].float_list.value[:] = detected_boxes[1]
feature[standard_fields.TfExampleFields.
detection_bbox_ymax].float_list.value[:] = detected_boxes[2]
feature[standard_fields.TfExampleFields.
detection_bbox_xmax].float_list.value[:] = detected_boxes[3]
feature[standard_fields.TfExampleFields.
detection_class_label].int64_list.value[:] = detected_classes
if discard_image_pixels:
del feature[standard_fields.TfExampleFields.image_encoded]
return tf_example
|
apache-2.0
|
[
3,
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
17505,
3423,
367,
15212,
17353,
1041,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
3228,
14,
5819,
14,
86,
17,
465,
2833,
199,
199,
504,
909,
63,
11934,
14,
1018,
492,
4465,
63,
955,
421,
199,
318,
1900,
63,
1210,
8,
3249,
3059,
63,
3771,
304,
523,
408,
27856,
314,
3343,
1159,
1324,
14,
819,
3033,
26,
272,
2833,
3059,
63,
3771,
26,
3820,
402,
3792,
370,
314,
1324,
21721,
14941,
819,
1803,
26,
272,
6380,
63,
2694,
63,
3128,
26,
710,
2163,
6380,
2893,
14,
2624,
6917,
5878,
272,
1834,
63,
3128,
26,
710,
11203,
1834,
402,
314,
2893,
14,
27310,
24,
2345,
12,
267,
2215,
1524,
17,
12,
488,
12,
488,
12,
19,
61,
523,
408,
523,
1788,
63,
1825,
275,
2833,
14,
2834,
14,
875,
63,
1210,
63,
16376,
8,
489,
2833,
3059,
63,
3771,
12,
13031,
29,
797,
12,
1967,
63,
13161,
29,
17,
9,
819,
2833,
63,
3059,
63,
5503,
275,
2833,
14,
6145,
5433,
5929,
342,
523,
5501,
6380,
63,
2694,
63,
3128,
275,
2833,
63,
3059,
63,
5503,
14,
739,
8,
1501,
63,
1825,
9,
523,
4534,
275,
2833,
14,
1122,
63,
4780,
63,
2694,
8,
489,
6380,
63,
2694,
63,
3128,
12,
489,
4534,
3126,
881,
4465,
63,
955,
14,
52,
70,
9846,
7304,
14,
1569,
63,
8167,
26,
1598,
2833,
14,
9515,
28556,
8798,
2833,
14,
875,
395,
489,
3828,
523,
5737,
63,
1569,
275,
4534,
59,
6807,
63,
955,
14,
52,
70,
9846,
7304,
14,
1569,
63,
8167,
61,
523,
1834,
63,
3128,
275,
2833,
14,
1569,
14,
2708,
63,
1569,
8,
8167,
63,
1569,
12,
9245,
29,
19,
9,
523,
1834,
63,
3128,
14,
409,
63,
1392,
779,
403,
12,
488,
12,
650,
566,
523,
1834,
63,
3128,
275,
2833,
14,
4441,
63,
5380,
8,
1569,
63,
3128,
12,
378,
9,
819,
372,
6380,
63,
2694,
63,
3128,
12,
1834,
63,
3128,
421,
199,
318,
1900,
63,
20580,
63,
2180,
8,
1569,
63,
3128,
12,
17353,
63,
2180,
63,
515,
304,
523,
408,
30777,
314,
17353,
3343,
436,
4907,
83,
652,
370,
314,
1324,
1834,
14,
819,
3033,
26,
272,
1834,
63,
3128,
26,
710,
1324,
1834,
14,
3152,
24,
2345,
12,
2215,
1524,
17,
12,
488,
12,
488,
12,
650,
61,
272,
17353,
63,
2180,
63,
515,
26,
6912,
370,
314,
17353,
3343,
543,
12169,
4931,
819,
1803,
26,
272,
10501,
63,
12922,
63,
3128,
26,
1487,
4530,
17193,
14,
11140,
2345,
12,
267,
2215,
1524,
1507,
63,
271,
266,
2452,
12,
841,
61,
272,
10501,
63,
7107,
63,
3128,
26,
1487,
4530,
9342,
14,
11140,
2345,
12,
267,
2215,
1524,
1507,
63,
271,
266,
2452,
61,
272,
10501,
63,
3512,
63,
3128,
26,
1487,
4530,
3628,
14,
9805,
772,
2345,
12,
267,
2215,
1524,
1507,
63,
271,
266,
2452,
61,
523,
408,
523,
543,
2833,
14,
30325,
14,
4299,
8,
20580,
63,
2180,
63,
515,
12,
283,
4848,
358,
465,
3343,
63,
318,
63,
493,
26,
272,
3343,
63,
1317,
275,
3343,
63,
318,
63,
493,
14,
739,
342,
523,
3343,
63,
318,
275,
2833,
14,
31725,
342,
523,
3343,
63,
318,
14,
11359,
7671,
8,
2180,
63,
1317,
9,
819,
2833,
14,
646,
63,
2180,
63,
318,
8,
489,
3343,
63,
318,
12,
536,
4581,
1324,
63,
1130,
3713,
1569,
63,
3128,
356,
1834,
63,
3128,
1552,
819,
486,
275,
2833,
14,
362,
63,
885,
63,
2180,
342,
819,
1967,
63,
271,
266,
2452,
63,
3128,
275,
2833,
14,
16597,
8,
489,
486,
14,
362,
63,
3128,
63,
991,
63,
354,
360,
1507,
63,
271,
266,
2452,
26,
16,
659,
378,
9,
523,
1967,
63,
271,
266,
2452,
63,
3128,
275,
2833,
14,
2931,
8,
1507,
63,
271,
266,
2452,
63,
3128,
12,
2833,
14,
442,
708,
9,
819,
10501,
63,
12922,
63,
3128,
275,
2833,
14,
16597,
8,
489,
486,
14,
362,
63,
3128,
63,
991,
63,
354,
360,
11934,
63,
12922,
26,
16,
659,
378,
9,
523,
10501,
63,
12922,
63,
3128,
275,
10501,
63,
12922,
63,
3128,
1491,
1507,
63,
271,
266,
2452,
63,
3128,
61,
819,
10501,
63,
7107,
63,
3128,
275,
2833,
14,
16597,
8,
489,
486,
14,
362,
63,
3128,
63,
991,
63,
354,
360,
11934,
63,
7107,
26,
16,
659,
378,
9,
523,
10501,
63,
7107,
63,
3128,
275,
10501,
63,
7107,
63,
3128,
1491,
1507,
63,
271,
266,
2452,
63,
3128,
61,
819,
10501,
63,
3512,
63,
3128,
275,
2833,
14,
16597,
8,
489,
486,
14,
362,
63,
3128,
63,
991,
63,
354,
360,
11934,
63,
2888,
26,
16,
659,
378,
9,
523,
10501,
63,
3512,
63,
3128,
275,
2833,
14,
2931,
8,
25577,
63,
3512,
63,
3128,
12,
2833,
14,
442,
772,
9,
523,
10501,
63,
3512,
63,
3128,
275,
10501,
63,
3512,
63,
3128,
1491,
1507,
63,
271,
266,
2452,
63,
3128,
61,
819,
372,
10501,
63,
12922,
63,
3128,
12,
10501,
63,
7107,
63,
3128,
12,
10501,
63,
3512,
63,
3128,
421,
199,
318,
18538,
63,
271,
266,
2452,
63,
460,
63,
525,
63,
475,
63,
2694,
8,
272,
6380,
63,
2694,
63,
3128,
12,
10501,
63,
12922,
63,
3128,
12,
10501,
63,
7107,
63,
3128,
12,
272,
10501,
63,
3512,
63,
3128,
12,
16895,
63,
1569,
63,
15727,
304,
523,
408,
16291,
314,
6841,
10519,
436,
9584,
314,
22515
] |
[
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
17505,
3423,
367,
15212,
17353,
1041,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
3228,
14,
5819,
14,
86,
17,
465,
2833,
199,
199,
504,
909,
63,
11934,
14,
1018,
492,
4465,
63,
955,
421,
199,
318,
1900,
63,
1210,
8,
3249,
3059,
63,
3771,
304,
523,
408,
27856,
314,
3343,
1159,
1324,
14,
819,
3033,
26,
272,
2833,
3059,
63,
3771,
26,
3820,
402,
3792,
370,
314,
1324,
21721,
14941,
819,
1803,
26,
272,
6380,
63,
2694,
63,
3128,
26,
710,
2163,
6380,
2893,
14,
2624,
6917,
5878,
272,
1834,
63,
3128,
26,
710,
11203,
1834,
402,
314,
2893,
14,
27310,
24,
2345,
12,
267,
2215,
1524,
17,
12,
488,
12,
488,
12,
19,
61,
523,
408,
523,
1788,
63,
1825,
275,
2833,
14,
2834,
14,
875,
63,
1210,
63,
16376,
8,
489,
2833,
3059,
63,
3771,
12,
13031,
29,
797,
12,
1967,
63,
13161,
29,
17,
9,
819,
2833,
63,
3059,
63,
5503,
275,
2833,
14,
6145,
5433,
5929,
342,
523,
5501,
6380,
63,
2694,
63,
3128,
275,
2833,
63,
3059,
63,
5503,
14,
739,
8,
1501,
63,
1825,
9,
523,
4534,
275,
2833,
14,
1122,
63,
4780,
63,
2694,
8,
489,
6380,
63,
2694,
63,
3128,
12,
489,
4534,
3126,
881,
4465,
63,
955,
14,
52,
70,
9846,
7304,
14,
1569,
63,
8167,
26,
1598,
2833,
14,
9515,
28556,
8798,
2833,
14,
875,
395,
489,
3828,
523,
5737,
63,
1569,
275,
4534,
59,
6807,
63,
955,
14,
52,
70,
9846,
7304,
14,
1569,
63,
8167,
61,
523,
1834,
63,
3128,
275,
2833,
14,
1569,
14,
2708,
63,
1569,
8,
8167,
63,
1569,
12,
9245,
29,
19,
9,
523,
1834,
63,
3128,
14,
409,
63,
1392,
779,
403,
12,
488,
12,
650,
566,
523,
1834,
63,
3128,
275,
2833,
14,
4441,
63,
5380,
8,
1569,
63,
3128,
12,
378,
9,
819,
372,
6380,
63,
2694,
63,
3128,
12,
1834,
63,
3128,
421,
199,
318,
1900,
63,
20580,
63,
2180,
8,
1569,
63,
3128,
12,
17353,
63,
2180,
63,
515,
304,
523,
408,
30777,
314,
17353,
3343,
436,
4907,
83,
652,
370,
314,
1324,
1834,
14,
819,
3033,
26,
272,
1834,
63,
3128,
26,
710,
1324,
1834,
14,
3152,
24,
2345,
12,
2215,
1524,
17,
12,
488,
12,
488,
12,
650,
61,
272,
17353,
63,
2180,
63,
515,
26,
6912,
370,
314,
17353,
3343,
543,
12169,
4931,
819,
1803,
26,
272,
10501,
63,
12922,
63,
3128,
26,
1487,
4530,
17193,
14,
11140,
2345,
12,
267,
2215,
1524,
1507,
63,
271,
266,
2452,
12,
841,
61,
272,
10501,
63,
7107,
63,
3128,
26,
1487,
4530,
9342,
14,
11140,
2345,
12,
267,
2215,
1524,
1507,
63,
271,
266,
2452,
61,
272,
10501,
63,
3512,
63,
3128,
26,
1487,
4530,
3628,
14,
9805,
772,
2345,
12,
267,
2215,
1524,
1507,
63,
271,
266,
2452,
61,
523,
408,
523,
543,
2833,
14,
30325,
14,
4299,
8,
20580,
63,
2180,
63,
515,
12,
283,
4848,
358,
465,
3343,
63,
318,
63,
493,
26,
272,
3343,
63,
1317,
275,
3343,
63,
318,
63,
493,
14,
739,
342,
523,
3343,
63,
318,
275,
2833,
14,
31725,
342,
523,
3343,
63,
318,
14,
11359,
7671,
8,
2180,
63,
1317,
9,
819,
2833,
14,
646,
63,
2180,
63,
318,
8,
489,
3343,
63,
318,
12,
536,
4581,
1324,
63,
1130,
3713,
1569,
63,
3128,
356,
1834,
63,
3128,
1552,
819,
486,
275,
2833,
14,
362,
63,
885,
63,
2180,
342,
819,
1967,
63,
271,
266,
2452,
63,
3128,
275,
2833,
14,
16597,
8,
489,
486,
14,
362,
63,
3128,
63,
991,
63,
354,
360,
1507,
63,
271,
266,
2452,
26,
16,
659,
378,
9,
523,
1967,
63,
271,
266,
2452,
63,
3128,
275,
2833,
14,
2931,
8,
1507,
63,
271,
266,
2452,
63,
3128,
12,
2833,
14,
442,
708,
9,
819,
10501,
63,
12922,
63,
3128,
275,
2833,
14,
16597,
8,
489,
486,
14,
362,
63,
3128,
63,
991,
63,
354,
360,
11934,
63,
12922,
26,
16,
659,
378,
9,
523,
10501,
63,
12922,
63,
3128,
275,
10501,
63,
12922,
63,
3128,
1491,
1507,
63,
271,
266,
2452,
63,
3128,
61,
819,
10501,
63,
7107,
63,
3128,
275,
2833,
14,
16597,
8,
489,
486,
14,
362,
63,
3128,
63,
991,
63,
354,
360,
11934,
63,
7107,
26,
16,
659,
378,
9,
523,
10501,
63,
7107,
63,
3128,
275,
10501,
63,
7107,
63,
3128,
1491,
1507,
63,
271,
266,
2452,
63,
3128,
61,
819,
10501,
63,
3512,
63,
3128,
275,
2833,
14,
16597,
8,
489,
486,
14,
362,
63,
3128,
63,
991,
63,
354,
360,
11934,
63,
2888,
26,
16,
659,
378,
9,
523,
10501,
63,
3512,
63,
3128,
275,
2833,
14,
2931,
8,
25577,
63,
3512,
63,
3128,
12,
2833,
14,
442,
772,
9,
523,
10501,
63,
3512,
63,
3128,
275,
10501,
63,
3512,
63,
3128,
1491,
1507,
63,
271,
266,
2452,
63,
3128,
61,
819,
372,
10501,
63,
12922,
63,
3128,
12,
10501,
63,
7107,
63,
3128,
12,
10501,
63,
3512,
63,
3128,
421,
199,
318,
18538,
63,
271,
266,
2452,
63,
460,
63,
525,
63,
475,
63,
2694,
8,
272,
6380,
63,
2694,
63,
3128,
12,
10501,
63,
12922,
63,
3128,
12,
10501,
63,
7107,
63,
3128,
12,
272,
10501,
63,
3512,
63,
3128,
12,
16895,
63,
1569,
63,
15727,
304,
523,
408,
16291,
314,
6841,
10519,
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1,
1,
1,
1,
1,
1,
1
] |
Salat-Cx65/python-for-android
|
python3-alpha/python3-src/Lib/test/test_pep263.py
|
62
|
1846
|
# -*- coding: koi8-r -*-
import unittest
from test import support
class PEP263Test(unittest.TestCase):
def test_pep263(self):
self.assertEqual(
"ðÉÔÏÎ".encode("utf-8"),
b'\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd'
)
self.assertEqual(
"\ð".encode("utf-8"),
b'\\\xd0\x9f'
)
def test_compilestring(self):
# see #1882
c = compile(b"\n# coding: utf-8\nu = '\xc3\xb3'\n", "dummy", "exec")
d = {}
exec(c, d)
self.assertEqual(d['u'], '\xf3')
def test_issue2301(self):
try:
compile(b"# coding: cp932\nprint '\x94\x4e'", "dummy", "exec")
except SyntaxError as v:
self.assertEqual(v.text, "print '\u5e74'\n")
else:
self.fail()
def test_issue4626(self):
c = compile("# coding=latin-1\n\u00c6 = '\u00c6'", "dummy", "exec")
d = {}
exec(c, d)
self.assertEqual(d['\xc6'], '\xc6')
def test_issue3297(self):
c = compile("a, b = '\U0001010F', '\\U0001010F'", "dummy", "exec")
d = {}
exec(c, d)
self.assertEqual(d['a'], d['b'])
self.assertEqual(len(d['a']), len(d['b']))
self.assertEqual(ascii(d['a']), ascii(d['b']))
def test_issue7820(self):
# Ensure that check_bom() restores all bytes in the right order if
# check_bom() fails in pydebug mode: a buffer starts with the first
# byte of a valid BOM, but next bytes are different
# one byte in common with the UTF-16-LE BOM
self.assertRaises(SyntaxError, eval, b'\xff\x20')
# two bytes in common with the UTF-8 BOM
self.assertRaises(SyntaxError, eval, b'\xef\xbb\x20')
def test_main():
support.run_unittest(PEP263Test)
if __name__=="__main__":
test_main()
|
apache-2.0
|
[
3,
1882,
2803,
26,
1022,
16142,
24,
13,
82,
1882,
199,
199,
646,
2882,
199,
504,
511,
492,
2291,
199,
199,
533,
13663,
14622,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
12636,
14622,
8,
277,
304,
267,
291,
14,
629,
8,
288,
298,
29769,
128,
232,
128,
243,
128,
238,
128,
237,
1674,
2143,
480,
1624,
13,
24,
1288,
288,
330,
1154,
2207,
16,
60,
88,
25,
70,
60,
2207,
16,
60,
1774,
24,
60,
2207,
17,
60,
88,
2564,
60,
2207,
16,
60,
9957,
60,
2207,
16,
60,
9826,
7,
267,
776,
267,
291,
14,
629,
8,
288,
1867,
29769,
1674,
2143,
480,
1624,
13,
24,
1288,
288,
330,
32190,
2207,
16,
60,
88,
25,
70,
7,
267,
776,
339,
347,
511,
63,
2014,
875,
8,
277,
304,
267,
327,
1937,
327,
1085,
2564,
267,
286,
275,
6555,
8,
66,
3212,
78,
3,
2803,
26,
2774,
13,
24,
60,
4850,
275,
1557,
1812,
19,
60,
1774,
19,
1154,
78,
401,
298,
5869,
401,
298,
1628,
531,
267,
366,
275,
1052,
267,
2146,
8,
67,
12,
366,
9,
267,
291,
14,
629,
8,
68,
459,
85,
995,
1557,
1949,
19,
358,
339,
347,
511,
63,
5237,
1789,
614,
8,
277,
304,
267,
862,
26,
288,
6555,
8,
66,
2,
3,
2803,
26,
7667,
27251,
60,
78,
1361,
1557,
88,
2635,
60,
88,
20,
69,
4662,
298,
5869,
401,
298,
1628,
531,
267,
871,
12053,
465,
373,
26,
288,
291,
14,
629,
8,
86,
14,
505,
12,
298,
1361,
1557,
85,
21,
69,
1342,
1154,
78,
531,
267,
587,
26,
288,
291,
14,
1633,
342,
339,
347,
511,
63,
5237,
2466,
1479,
8,
277,
304,
267,
286,
275,
6555,
10064,
2803,
29,
10378,
13,
17,
60,
78,
60,
85,
383,
67,
22,
275,
1557,
85,
383,
67,
22,
4662,
298,
5869,
401,
298,
1628,
531,
267,
366,
275,
1052,
267,
2146,
8,
67,
12,
366,
9,
267,
291,
14,
629,
8,
68,
459,
60,
1812,
22,
995,
1557,
1812,
22,
358,
339,
347,
511,
63,
5237,
708,
2576,
8,
277,
304,
267,
286,
275,
6555,
480,
65,
12,
330,
275,
1557,
53,
4183,
9523,
38,
297,
6468,
53,
4183,
9523,
38,
4662,
298,
5869,
401,
298,
1628,
531,
267,
366,
275,
1052,
267,
2146,
8,
67,
12,
366,
9,
267,
291,
14,
629,
8,
68,
459,
65,
995,
366,
459,
66,
1105,
267,
291,
14,
629,
8,
552,
8,
68,
459,
65,
3815,
822,
8,
68,
459,
66,
5156,
267,
291,
14,
629,
8,
4371,
8,
68,
459,
65,
3815,
13294,
8,
68,
459,
66,
5156,
339,
347,
511,
63,
5237,
2277,
1165,
8,
277,
304,
267,
327,
7523,
626,
1104,
63,
16302,
342,
4618,
7944,
1006,
2783,
315,
314,
2451,
1865,
340,
267,
327,
1104,
63,
16302,
342,
6918,
315,
1134,
1757,
818,
26,
282,
3335,
9174,
543,
314,
1642,
267,
327,
3696,
402,
282,
1686,
17720,
12,
1325,
2163,
2783,
787,
3365,
398,
327,
1373,
3696,
315,
2863,
543,
314,
9094,
13,
975,
13,
906,
17720,
267,
291,
14,
1855,
8,
9294,
12,
3468,
12,
330,
1154,
3581,
60,
88,
1165,
358,
398,
327,
2877,
2783,
315,
2863,
543,
314,
9094,
13,
24,
17720,
267,
291,
14,
1855,
8,
9294,
12,
3468,
12,
330,
1154,
9532,
60,
9932,
60,
88,
1165,
358,
199,
199,
318,
511,
63,
973,
837,
272,
2291,
14,
1065,
63,
2796,
8,
25633,
14622,
774,
9,
199,
199,
692,
636,
354,
363,
11800,
363,
973,
5727,
272,
511,
63,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
1022,
16142,
24,
13,
82,
1882,
199,
199,
646,
2882,
199,
504,
511,
492,
2291,
199,
199,
533,
13663,
14622,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
12636,
14622,
8,
277,
304,
267,
291,
14,
629,
8,
288,
298,
29769,
128,
232,
128,
243,
128,
238,
128,
237,
1674,
2143,
480,
1624,
13,
24,
1288,
288,
330,
1154,
2207,
16,
60,
88,
25,
70,
60,
2207,
16,
60,
1774,
24,
60,
2207,
17,
60,
88,
2564,
60,
2207,
16,
60,
9957,
60,
2207,
16,
60,
9826,
7,
267,
776,
267,
291,
14,
629,
8,
288,
1867,
29769,
1674,
2143,
480,
1624,
13,
24,
1288,
288,
330,
32190,
2207,
16,
60,
88,
25,
70,
7,
267,
776,
339,
347,
511,
63,
2014,
875,
8,
277,
304,
267,
327,
1937,
327,
1085,
2564,
267,
286,
275,
6555,
8,
66,
3212,
78,
3,
2803,
26,
2774,
13,
24,
60,
4850,
275,
1557,
1812,
19,
60,
1774,
19,
1154,
78,
401,
298,
5869,
401,
298,
1628,
531,
267,
366,
275,
1052,
267,
2146,
8,
67,
12,
366,
9,
267,
291,
14,
629,
8,
68,
459,
85,
995,
1557,
1949,
19,
358,
339,
347,
511,
63,
5237,
1789,
614,
8,
277,
304,
267,
862,
26,
288,
6555,
8,
66,
2,
3,
2803,
26,
7667,
27251,
60,
78,
1361,
1557,
88,
2635,
60,
88,
20,
69,
4662,
298,
5869,
401,
298,
1628,
531,
267,
871,
12053,
465,
373,
26,
288,
291,
14,
629,
8,
86,
14,
505,
12,
298,
1361,
1557,
85,
21,
69,
1342,
1154,
78,
531,
267,
587,
26,
288,
291,
14,
1633,
342,
339,
347,
511,
63,
5237,
2466,
1479,
8,
277,
304,
267,
286,
275,
6555,
10064,
2803,
29,
10378,
13,
17,
60,
78,
60,
85,
383,
67,
22,
275,
1557,
85,
383,
67,
22,
4662,
298,
5869,
401,
298,
1628,
531,
267,
366,
275,
1052,
267,
2146,
8,
67,
12,
366,
9,
267,
291,
14,
629,
8,
68,
459,
60,
1812,
22,
995,
1557,
1812,
22,
358,
339,
347,
511,
63,
5237,
708,
2576,
8,
277,
304,
267,
286,
275,
6555,
480,
65,
12,
330,
275,
1557,
53,
4183,
9523,
38,
297,
6468,
53,
4183,
9523,
38,
4662,
298,
5869,
401,
298,
1628,
531,
267,
366,
275,
1052,
267,
2146,
8,
67,
12,
366,
9,
267,
291,
14,
629,
8,
68,
459,
65,
995,
366,
459,
66,
1105,
267,
291,
14,
629,
8,
552,
8,
68,
459,
65,
3815,
822,
8,
68,
459,
66,
5156,
267,
291,
14,
629,
8,
4371,
8,
68,
459,
65,
3815,
13294,
8,
68,
459,
66,
5156,
339,
347,
511,
63,
5237,
2277,
1165,
8,
277,
304,
267,
327,
7523,
626,
1104,
63,
16302,
342,
4618,
7944,
1006,
2783,
315,
314,
2451,
1865,
340,
267,
327,
1104,
63,
16302,
342,
6918,
315,
1134,
1757,
818,
26,
282,
3335,
9174,
543,
314,
1642,
267,
327,
3696,
402,
282,
1686,
17720,
12,
1325,
2163,
2783,
787,
3365,
398,
327,
1373,
3696,
315,
2863,
543,
314,
9094,
13,
975,
13,
906,
17720,
267,
291,
14,
1855,
8,
9294,
12,
3468,
12,
330,
1154,
3581,
60,
88,
1165,
358,
398,
327,
2877,
2783,
315,
2863,
543,
314,
9094,
13,
24,
17720,
267,
291,
14,
1855,
8,
9294,
12,
3468,
12,
330,
1154,
9532,
60,
9932,
60,
88,
1165,
358,
199,
199,
318,
511,
63,
973,
837,
272,
2291,
14,
1065,
63,
2796,
8,
25633,
14622,
774,
9,
199,
199,
692,
636,
354,
363,
11800,
363,
973,
5727,
272,
511,
63,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
TopherGopher/aws-infra.jenkins-scripts
|
s3trim.py
|
1
|
7063
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Example usage:
# python s3trim.py --count 14 --key=AWS_KEY --secret=AWS_SECRET_KEY nmdarchive christest/production
import argparse
import logging
import operator
import re
import time
from collections import OrderedDict as Dict
from boto.s3.connection import S3Connection
import sys
debug = False
parser = argparse.ArgumentParser(description="Prune all files in S3. Note: Staging and _Default environments will only retain a single back-up.", prog="s3trim")
parser.add_argument("bucket", help="S3 bucket.")
parser.add_argument("-c", "--count", help="Number of days of files to leave in production.", dest='aws_bucket_count')
parser.add_argument("-k", "--key", help="Your amazon access key.", dest='aws_access_key')
parser.add_argument("-sk", "--secret", help="Your amazon secret key.", dest='aws_secret_key')
parser.add_argument("-l", "--log", help="Sets the log level. Defaults to INFO.", default='INFO')
def main(bucket, aws_access_key='', aws_secret_key='', log='info', aws_bucket_count=5):
global aws_key
aws_key = aws_access_key
global aws_secret
aws_secret = aws_secret_key
s3 = S3Connection(aws_key, aws_secret)
bucket = s3.get_bucket(bucket)
sorted_results = get_results(bucket)
trim_by_day(bucket, sorted_results, aws_bucket_count)
#trim_by_count(bucket, sorted_results)
def trim_by_count(bucket, sorted_results):
for env, bags in sorted_results.items():
logger.info("Working on the {env} environment.".format(env=env))
for name, bag in bags.items():
logger.info("Working on the {name} bag.".format(name=name))
if env in ['_default', 'staging']:
logger.info("This is a {env} environment, overriding retention to a single back-up.".format(env=env))
removal_count = len(bag) - 1
else:
removal_count = len(bag) - int(aws_bucket_count)
count = 0
for timestamp, file_name in bag:
if count >= removal_count:
logger.info("Previous file count: {count}".format(count=len(bag)))
logger.info("Removed files: {total}".format(total=count))
logger.info("New file count: {count}".format(count=(len(bag)-count)))
logger.info("")
break
count+=1
if not debug:
bucket.delete_key(file_name)
logger.info("Removed %s" % (file_name))
# Retain 2 weeks of S3 data in prod and the most recent back-up in staging and sefault
def trim_by_day(bucket,sorted_results,aws_bucket_count):
now = int(time.time())
num_days = aws_bucket_count
num_secs = int(num_days) * 24 * 60 * 60
oldest_timestamp = int(now - num_secs)
total_removed_files = 0
total_files = 0
#counts = {e:0 for e in sorted_results.keys()}
for env, bags in sorted_results.items():
logger.info("Working on the {env} environment.".format(env=env))
for name, bag in bags.items():
logger.info("Working on the {name} bag.".format(name=name))
# Setup the counters
if env in ['_default', 'staging']:
logger.info("This is a {env} environment, overriding retention to a single back-up.".format(env=env))
removal_count = len(bag) - 1
else:
removal_count = len(bag) - int(aws_bucket_count) # Set a boundary in case there's less backups than days
count = 0
if len(bag) == 1:
continue
for timestamp, file_name in bag:
# If the timestamp on the file is older than our limit
# Majority of cases will fall here
if int(timestamp) < oldest_timestamp:
# If there's only our removal count left, bail, keep these always always
if count >= removal_count:
break
count+=1
if not debug:
bucket.delete_key(file_name)
logger.info("Removed %s" % (file_name))
continue
# If we've got an entry from a non-prod env, we need to wipe out all but 1
if env in ['_default', 'staging'] and count < removal_count:
count+=1
if not debug:
bucket.delete_key(file_name)
logger.info("S Removed %s" % (file_name))
continue
total_removed_files+=count
total_files+=len(bag)
logger.info("Previous file count: {count}".format(count=len(bag)))
logger.info("Removed files: {total}".format(total=count))
logger.info("New file count: {count}".format(count=(len(bag)-count)))
logger.info("")
if len(bag)-count <= 0:
logger.error("There were 0 files remaining on this removal. Something went wrong here. Bailing.")
sys.exit(1)
logger.info("Previous total file count: %d" % total_files)
logger.info("Total removed files: %d" % total_removed_files)
logger.info("New total file count: %d" % (total_files-total_removed_files))
def get_results(bucket):
# christest/production-christest-1474858852.tar.gz
# bag/env-bag-time.tar.gz
#bucket_list = bucket.list(prefix)
bucket_list = bucket.list()
logger.info("Pulled file list from nmdarchive")
structured_list = {}
pattern = '(?P<bag>[a-zA-Z0-9]+)/(?P<env>[a-zA-Z0-9]+)-(?P<bag2>[a-zA-Z0-9]+)-(?P<timestamp>\d+)\.tar\.gz'
regex = re.compile(pattern)
results = {}
count = 0
logger.info("Scanning for valid archive files... (This will take a while).")
for item in bucket_list:
match = regex.match(item.name)
if not match:
continue
bag = match.group('bag')
env = match.group('env')
bag2 = match.group('bag2')
timestamp = match.group('timestamp')
# Sanity check to make sure that the bags match
if bag != bag2:
logger.info("It looks like {name} is a malformed back-up entry. Consider deleting.".format(name=item))
continue
if env not in results:
results[env] = {}
if bag not in results[env]:
results[env][bag] = {}
results[env][bag][timestamp] = item
sorted_results = {e: {b: Dict() for b in results[e].keys()} for e in results.keys()}
for env, bags in results.items():
for name, bag in bags.items():
# Sort by timestamp
sorted_results[env][name] = sorted(bag.items(), key=operator.itemgetter(1))
# Now that everything is sorted, the first items are the oldest and the last items are newest
return sorted_results
if __name__ == "__main__":
args = parser.parse_args()
logging.basicConfig(filename='s3trim_dryrun.log',level=logging.INFO)
logger = logging.getLogger()
exec("logger.setLevel(logging." + args.log.upper() + ")")
handler = logging.StreamHandler()
exec("handler.setLevel(logging." + args.log.upper() + ")")
formatter = logging.Formatter("[%(levelname)s %(filename)s:%(lineno)s %(funcName)s()] %(message)s")
handler.setFormatter(formatter)
logger.addHandler(handler)
arg_dict = vars(args)
logging.debug("CLI args: %s" % args)
main(**arg_dict)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
5679,
4503,
26,
199,
3,
2366,
308,
19,
12263,
14,
647,
1553,
835,
4329,
1553,
498,
29,
13226,
63,
3078,
1553,
4731,
29,
13226,
63,
12961,
63,
3078,
302,
1064,
6404,
682,
5719,
396,
15,
10777,
199,
199,
646,
7534,
199,
646,
2050,
199,
646,
4182,
199,
646,
295,
199,
646,
900,
199,
504,
5055,
492,
8773,
465,
7448,
199,
504,
6055,
14,
83,
19,
14,
2105,
492,
428,
19,
3225,
199,
646,
984,
199,
199,
1757,
275,
756,
199,
199,
2087,
275,
7534,
14,
10730,
8,
1802,
628,
48,
14780,
1006,
1584,
315,
428,
19,
14,
3390,
26,
428,
1450,
316,
436,
485,
2698,
22196,
911,
1454,
8074,
282,
2849,
1771,
13,
384,
4765,
13205,
628,
83,
19,
12263,
531,
199,
2087,
14,
525,
63,
2094,
480,
4623,
401,
1720,
628,
51,
19,
5315,
2685,
199,
2087,
14,
525,
63,
2094,
6096,
67,
401,
4320,
835,
401,
1720,
628,
3259,
402,
7609,
402,
1584,
370,
10137,
315,
9920,
4765,
2053,
534,
7231,
63,
4623,
63,
835,
358,
199,
2087,
14,
525,
63,
2094,
6096,
75,
401,
4320,
498,
401,
1720,
628,
14398,
282,
8872,
2879,
790,
4765,
2053,
534,
7231,
63,
2732,
63,
498,
358,
199,
2087,
14,
525,
63,
2094,
6096,
1339,
401,
4320,
4731,
401,
1720,
628,
14398,
282,
8872,
7565,
790,
4765,
2053,
534,
7231,
63,
4731,
63,
498,
358,
199,
2087,
14,
525,
63,
2094,
6096,
76,
401,
4320,
793,
401,
1720,
628,
9899,
314,
943,
2166,
14,
7827,
370,
24008,
4765,
849,
534,
4531,
358,
199,
318,
2446,
8,
4623,
12,
11488,
63,
2732,
63,
498,
4581,
11488,
63,
4731,
63,
498,
4581,
943,
534,
815,
297,
11488,
63,
4623,
63,
835,
29,
21,
304,
272,
2288,
11488,
63,
498,
272,
11488,
63,
498,
275,
11488,
63,
2732,
63,
498,
339,
2288,
11488,
63,
4731,
272,
11488,
63,
4731,
275,
11488,
63,
4731,
63,
498,
339,
308,
19,
275,
428,
19,
3225,
8,
7231,
63,
498,
12,
11488,
63,
4731,
9,
272,
5315,
275,
308,
19,
14,
362,
63,
4623,
8,
4623,
9,
339,
3355,
63,
2604,
275,
664,
63,
2604,
8,
4623,
9,
339,
11639,
63,
991,
63,
2977,
8,
4623,
12,
3355,
63,
2604,
12,
11488,
63,
4623,
63,
835,
9,
272,
327,
12263,
63,
991,
63,
835,
8,
4623,
12,
3355,
63,
2604,
9,
16872,
199,
318,
11639,
63,
991,
63,
835,
8,
4623,
12,
3355,
63,
2604,
304,
272,
367,
2589,
12,
330,
7391,
315,
3355,
63,
2604,
14,
1744,
837,
489,
2512,
14,
815,
480,
18356,
641,
314,
469,
1813,
93,
3734,
15848,
908,
8,
1813,
29,
1813,
430,
489,
367,
536,
12,
330,
643,
315,
330,
7391,
14,
1744,
837,
267,
2512,
14,
815,
480,
18356,
641,
314,
469,
354,
93,
330,
643,
15848,
908,
8,
354,
29,
354,
430,
267,
340,
2589,
315,
4044,
885,
297,
283,
26840,
2565,
881,
2512,
14,
815,
480,
2765,
365,
282,
469,
1813,
93,
3734,
12,
18972,
295,
9553,
370,
282,
2849,
1771,
13,
384,
15848,
908,
8,
1813,
29,
1813,
430,
881,
20055,
63,
835,
275,
822,
8,
19430,
9,
446,
413,
267,
587,
26,
881,
20055,
63,
835,
275,
822,
8,
19430,
9,
446,
1109,
8,
7231,
63,
4623,
63,
835,
9,
267,
2338,
275,
378,
267,
367,
4913,
12,
570,
63,
354,
315,
330,
643,
26,
881,
340,
2338,
2356,
20055,
63,
835,
26,
288,
2512,
14,
815,
480,
18021,
570,
2338,
26,
469,
835,
5469,
908,
8,
835,
29,
552,
8,
19430,
1724,
288,
2512,
14,
815,
480,
23407,
1584,
26,
469,
2923,
5469,
908,
8,
2923,
29,
835,
430,
288,
2512,
14,
815,
480,
4665,
570,
2338,
26,
469,
835,
5469,
908,
8,
835,
2687,
552,
8,
19430,
7216,
835,
1724,
288,
2512,
14,
815,
10804,
288,
2059,
881,
2338,
10365,
17,
881,
340,
440,
3105,
26,
288,
5315,
14,
1807,
63,
498,
8,
493,
63,
354,
9,
881,
2512,
14,
815,
480,
23407,
450,
83,
2,
450,
334,
493,
63,
354,
430,
2126,
199,
199,
3,
8747,
1581,
499,
29540,
402,
428,
19,
666,
315,
12441,
436,
314,
4750,
8058,
1771,
13,
384,
315,
28512,
436,
542,
1879,
199,
318,
11639,
63,
991,
63,
2977,
8,
4623,
12,
5917,
63,
2604,
12,
7231,
63,
4623,
63,
835,
304,
272,
3063,
275,
1109,
8,
521,
14,
521,
1012,
272,
1967,
63,
4899,
275,
11488,
63,
4623,
63,
835,
272,
1967,
63,
4855,
275,
1109,
8,
1507,
63,
4899,
9,
627,
5504,
627,
5212,
627,
5212,
272,
29493,
63,
3954,
275,
1109,
8,
2131,
446,
1967,
63,
4855,
9,
272,
3141,
63,
10649,
63,
1725,
275,
378,
272,
3141,
63,
1725,
275,
378,
272,
327,
6851,
275,
469,
69,
26,
16,
367,
325,
315,
3355,
63,
2604,
14,
1612,
12737,
2286,
367,
2589,
12,
330,
7391,
315,
3355,
63,
2604,
14,
1744,
837,
489,
2512,
14,
815,
480,
18356,
641,
314,
469,
1813,
93,
3734,
15848,
908,
8,
1813,
29,
1813,
430,
2541,
367,
536,
12,
330,
643,
315,
330,
7391,
14,
1744,
837,
267,
2512,
14,
815,
480,
18356,
641,
314,
469,
354,
93,
330,
643,
15848,
908,
8,
354,
29,
354,
430,
2728,
327,
12439,
314,
21272,
267,
340,
2589,
315,
4044,
885,
297,
283,
26840,
2565,
881,
2512,
14,
815,
480,
2765,
365,
282,
469,
1813,
93,
3734,
12,
18972,
295,
9553,
370,
282,
2849,
1771,
13,
384,
15848,
908,
8,
1813,
29,
1813,
430,
881,
20055,
63,
835,
275,
822,
8,
19430,
9,
446,
413,
267,
587,
26,
881,
20055,
63,
835,
275,
822,
8,
19430,
9,
446,
1109,
8,
7231,
63,
4623,
63,
835,
9,
327,
2494,
282,
8424,
315,
1930,
2337,
1159,
6656,
6902,
83,
2419,
7609,
267,
2338,
275,
378,
398,
340,
822,
8,
19430,
9,
508,
413,
26,
881,
1980,
267,
367,
4913,
12,
570,
63,
354,
315,
330,
643,
26,
881,
327,
982,
314,
4913,
641,
314,
570,
365,
12731,
2419,
4154,
2304,
881,
327,
603,
9091,
3822,
402,
5560,
911,
11264,
2348,
881,
340,
1109,
8,
3954,
9,
665,
29493,
63,
3954,
26,
288,
327,
982,
2337,
1159,
1454,
4154,
20055,
2338,
3602
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
5679,
4503,
26,
199,
3,
2366,
308,
19,
12263,
14,
647,
1553,
835,
4329,
1553,
498,
29,
13226,
63,
3078,
1553,
4731,
29,
13226,
63,
12961,
63,
3078,
302,
1064,
6404,
682,
5719,
396,
15,
10777,
199,
199,
646,
7534,
199,
646,
2050,
199,
646,
4182,
199,
646,
295,
199,
646,
900,
199,
504,
5055,
492,
8773,
465,
7448,
199,
504,
6055,
14,
83,
19,
14,
2105,
492,
428,
19,
3225,
199,
646,
984,
199,
199,
1757,
275,
756,
199,
199,
2087,
275,
7534,
14,
10730,
8,
1802,
628,
48,
14780,
1006,
1584,
315,
428,
19,
14,
3390,
26,
428,
1450,
316,
436,
485,
2698,
22196,
911,
1454,
8074,
282,
2849,
1771,
13,
384,
4765,
13205,
628,
83,
19,
12263,
531,
199,
2087,
14,
525,
63,
2094,
480,
4623,
401,
1720,
628,
51,
19,
5315,
2685,
199,
2087,
14,
525,
63,
2094,
6096,
67,
401,
4320,
835,
401,
1720,
628,
3259,
402,
7609,
402,
1584,
370,
10137,
315,
9920,
4765,
2053,
534,
7231,
63,
4623,
63,
835,
358,
199,
2087,
14,
525,
63,
2094,
6096,
75,
401,
4320,
498,
401,
1720,
628,
14398,
282,
8872,
2879,
790,
4765,
2053,
534,
7231,
63,
2732,
63,
498,
358,
199,
2087,
14,
525,
63,
2094,
6096,
1339,
401,
4320,
4731,
401,
1720,
628,
14398,
282,
8872,
7565,
790,
4765,
2053,
534,
7231,
63,
4731,
63,
498,
358,
199,
2087,
14,
525,
63,
2094,
6096,
76,
401,
4320,
793,
401,
1720,
628,
9899,
314,
943,
2166,
14,
7827,
370,
24008,
4765,
849,
534,
4531,
358,
199,
318,
2446,
8,
4623,
12,
11488,
63,
2732,
63,
498,
4581,
11488,
63,
4731,
63,
498,
4581,
943,
534,
815,
297,
11488,
63,
4623,
63,
835,
29,
21,
304,
272,
2288,
11488,
63,
498,
272,
11488,
63,
498,
275,
11488,
63,
2732,
63,
498,
339,
2288,
11488,
63,
4731,
272,
11488,
63,
4731,
275,
11488,
63,
4731,
63,
498,
339,
308,
19,
275,
428,
19,
3225,
8,
7231,
63,
498,
12,
11488,
63,
4731,
9,
272,
5315,
275,
308,
19,
14,
362,
63,
4623,
8,
4623,
9,
339,
3355,
63,
2604,
275,
664,
63,
2604,
8,
4623,
9,
339,
11639,
63,
991,
63,
2977,
8,
4623,
12,
3355,
63,
2604,
12,
11488,
63,
4623,
63,
835,
9,
272,
327,
12263,
63,
991,
63,
835,
8,
4623,
12,
3355,
63,
2604,
9,
16872,
199,
318,
11639,
63,
991,
63,
835,
8,
4623,
12,
3355,
63,
2604,
304,
272,
367,
2589,
12,
330,
7391,
315,
3355,
63,
2604,
14,
1744,
837,
489,
2512,
14,
815,
480,
18356,
641,
314,
469,
1813,
93,
3734,
15848,
908,
8,
1813,
29,
1813,
430,
489,
367,
536,
12,
330,
643,
315,
330,
7391,
14,
1744,
837,
267,
2512,
14,
815,
480,
18356,
641,
314,
469,
354,
93,
330,
643,
15848,
908,
8,
354,
29,
354,
430,
267,
340,
2589,
315,
4044,
885,
297,
283,
26840,
2565,
881,
2512,
14,
815,
480,
2765,
365,
282,
469,
1813,
93,
3734,
12,
18972,
295,
9553,
370,
282,
2849,
1771,
13,
384,
15848,
908,
8,
1813,
29,
1813,
430,
881,
20055,
63,
835,
275,
822,
8,
19430,
9,
446,
413,
267,
587,
26,
881,
20055,
63,
835,
275,
822,
8,
19430,
9,
446,
1109,
8,
7231,
63,
4623,
63,
835,
9,
267,
2338,
275,
378,
267,
367,
4913,
12,
570,
63,
354,
315,
330,
643,
26,
881,
340,
2338,
2356,
20055,
63,
835,
26,
288,
2512,
14,
815,
480,
18021,
570,
2338,
26,
469,
835,
5469,
908,
8,
835,
29,
552,
8,
19430,
1724,
288,
2512,
14,
815,
480,
23407,
1584,
26,
469,
2923,
5469,
908,
8,
2923,
29,
835,
430,
288,
2512,
14,
815,
480,
4665,
570,
2338,
26,
469,
835,
5469,
908,
8,
835,
2687,
552,
8,
19430,
7216,
835,
1724,
288,
2512,
14,
815,
10804,
288,
2059,
881,
2338,
10365,
17,
881,
340,
440,
3105,
26,
288,
5315,
14,
1807,
63,
498,
8,
493,
63,
354,
9,
881,
2512,
14,
815,
480,
23407,
450,
83,
2,
450,
334,
493,
63,
354,
430,
2126,
199,
199,
3,
8747,
1581,
499,
29540,
402,
428,
19,
666,
315,
12441,
436,
314,
4750,
8058,
1771,
13,
384,
315,
28512,
436,
542,
1879,
199,
318,
11639,
63,
991,
63,
2977,
8,
4623,
12,
5917,
63,
2604,
12,
7231,
63,
4623,
63,
835,
304,
272,
3063,
275,
1109,
8,
521,
14,
521,
1012,
272,
1967,
63,
4899,
275,
11488,
63,
4623,
63,
835,
272,
1967,
63,
4855,
275,
1109,
8,
1507,
63,
4899,
9,
627,
5504,
627,
5212,
627,
5212,
272,
29493,
63,
3954,
275,
1109,
8,
2131,
446,
1967,
63,
4855,
9,
272,
3141,
63,
10649,
63,
1725,
275,
378,
272,
3141,
63,
1725,
275,
378,
272,
327,
6851,
275,
469,
69,
26,
16,
367,
325,
315,
3355,
63,
2604,
14,
1612,
12737,
2286,
367,
2589,
12,
330,
7391,
315,
3355,
63,
2604,
14,
1744,
837,
489,
2512,
14,
815,
480,
18356,
641,
314,
469,
1813,
93,
3734,
15848,
908,
8,
1813,
29,
1813,
430,
2541,
367,
536,
12,
330,
643,
315,
330,
7391,
14,
1744,
837,
267,
2512,
14,
815,
480,
18356,
641,
314,
469,
354,
93,
330,
643,
15848,
908,
8,
354,
29,
354,
430,
2728,
327,
12439,
314,
21272,
267,
340,
2589,
315,
4044,
885,
297,
283,
26840,
2565,
881,
2512,
14,
815,
480,
2765,
365,
282,
469,
1813,
93,
3734,
12,
18972,
295,
9553,
370,
282,
2849,
1771,
13,
384,
15848,
908,
8,
1813,
29,
1813,
430,
881,
20055,
63,
835,
275,
822,
8,
19430,
9,
446,
413,
267,
587,
26,
881,
20055,
63,
835,
275,
822,
8,
19430,
9,
446,
1109,
8,
7231,
63,
4623,
63,
835,
9,
327,
2494,
282,
8424,
315,
1930,
2337,
1159,
6656,
6902,
83,
2419,
7609,
267,
2338,
275,
378,
398,
340,
822,
8,
19430,
9,
508,
413,
26,
881,
1980,
267,
367,
4913,
12,
570,
63,
354,
315,
330,
643,
26,
881,
327,
982,
314,
4913,
641,
314,
570,
365,
12731,
2419,
4154,
2304,
881,
327,
603,
9091,
3822,
402,
5560,
911,
11264,
2348,
881,
340,
1109,
8,
3954,
9,
665,
29493,
63,
3954,
26,
288,
327,
982,
2337,
1159,
1454,
4154,
20055,
2338,
3602,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
andersinno/foosball
|
config/settings/common.py
|
1
|
9129
|
# -*- coding: utf-8 -*-
"""
Django settings for foosball project.
For more information on this file, see
https://docs.djangoproject.com/en/dev/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/dev/ref/settings/
"""
from __future__ import absolute_import, unicode_literals
import os
import environ
from django_jinja.builtins import DEFAULT_EXTENSIONS
ROOT_DIR = environ.Path(__file__) - 3 # (/a/b/myfile.py - 3 = /)
APPS_DIR = ROOT_DIR.path('foosball')
# Include locales from the main foosball folder
LOCALE_PATHS = [
os.path.join(str(APPS_DIR), "locale")
]
env = environ.Env()
# If the project root contains a .env file, read it
if os.path.isfile(str(ROOT_DIR + '.env')):
environ.Env.read_env(str(ROOT_DIR + '.env'))
# APP CONFIGURATION
# ------------------------------------------------------------------------------
DJANGO_APPS = (
# Default Django apps:
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Useful template tags:
# 'django.contrib.humanize',
# Admin
'django.contrib.admin',
)
THIRD_PARTY_APPS = (
'django_jinja',
'crispy_forms', # Form layouts
'allauth', # registration
'allauth.account', # registration
'allauth.socialaccount', # registration
'rest_framework', # REST API
'django_superform',
'django_select2',
)
# Apps specific for this project go here.
LOCAL_APPS = (
'foosball.users',
'foosball.games',
)
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
# MIDDLEWARE CONFIGURATION
# ------------------------------------------------------------------------------
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
# MIGRATIONS CONFIGURATION
# ------------------------------------------------------------------------------
MIGRATION_MODULES = {
'sites': 'foosball.contrib.sites.migrations'
}
# DEBUG
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = env.bool("DJANGO_DEBUG", False)
# FIXTURE CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
FIXTURE_DIRS = (
str(APPS_DIR.path('fixtures')),
)
# EMAIL CONFIGURATION
# ------------------------------------------------------------------------------
EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.smtp.EmailBackend')
# MANAGER CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
ADMINS = ()
# See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
MANAGERS = ADMINS
# DATABASE CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
# Raises ImproperlyConfigured exception if DATABASE_URL not in os.environ
'default': env.db("DATABASE_URL", default="sqlite:///{0}/foosball.sqlite".format(ROOT_DIR)),
}
DATABASES['default']['ATOMIC_REQUESTS'] = True
# GENERAL CONFIGURATION
# ------------------------------------------------------------------------------
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'Europe/Helsinki'
# See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
LANGUAGE_CODE = 'en-us'
# See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id
SITE_ID = 1
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
USE_I18N = True
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
USE_L10N = True
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
USE_TZ = True
# TEMPLATE CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#templates
_TEMPLATE_CONTEXT_PROCESSORS = [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
]
TEMPLATES = [
{
'BACKEND': "django_jinja.backend.Jinja2",
'APP_DIRS': True,
'DIRS': [
str(APPS_DIR.path('templates')),
],
'OPTIONS': {
'match_extension': '.jinja',
'context_processors': _TEMPLATE_CONTEXT_PROCESSORS,
'auto_reload': DEBUG,
'extensions': DEFAULT_EXTENSIONS + [
# Your extensions here...
]
},
},
{
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
'BACKEND': 'django.template.backends.django.DjangoTemplates',
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
'DIRS': [
str(APPS_DIR.path('templates')),
],
'OPTIONS': {
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
'debug': DEBUG,
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
# https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
'context_processors': _TEMPLATE_CONTEXT_PROCESSORS,
},
},
]
# See: http://django-crispy-forms.readthedocs.org/en/latest/install.html#template-packs
CRISPY_TEMPLATE_PACK = 'bootstrap3'
# STATIC FILE CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root
STATIC_ROOT = str(ROOT_DIR('staticfiles'))
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
STATIC_URL = '/static/'
# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
STATICFILES_DIRS = (
str(APPS_DIR.path('static')),
)
# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
# MEDIA CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
MEDIA_ROOT = str(APPS_DIR('media'))
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
MEDIA_URL = '/media/'
# URL Configuration
# ------------------------------------------------------------------------------
ROOT_URLCONF = 'config.urls'
# See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
WSGI_APPLICATION = 'config.wsgi.application'
# AUTHENTICATION CONFIGURATION
# ------------------------------------------------------------------------------
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
# Some really nice defaults
ACCOUNT_AUTHENTICATION_METHOD = 'username'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_ALLOW_REGISTRATION = env.bool("DJANGO_ACCOUNT_ALLOW_REGISTRATION", True)
ACCOUNT_ADAPTER = 'foosball.users.adapters.AccountAdapter'
SOCIALACCOUNT_ADAPTER = 'foosball.users.adapters.SocialAccountAdapter'
ACCOUNT_LOGOUT_ON_GET = True
# Custom user app defaults
# Select the correct user model
AUTH_USER_MODEL = 'users.User'
LOGIN_REDIRECT_URL = 'users:redirect'
LOGIN_URL = 'account_login'
# SLUGLIFIER
AUTOSLUG_SLUGIFY_FUNCTION = 'slugify.slugify'
# Location of root django.contrib.admin URL, use {% url 'admin:index' %}
ADMIN_URL = r'^admin/'
# REST API
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissions'
]
}
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
9323,
2202,
367,
7090,
736,
8571,
2199,
14,
199,
199,
1858,
1655,
2556,
641,
642,
570,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
11299,
15,
1751,
15,
199,
199,
1858,
314,
2615,
769,
402,
2202,
436,
3932,
1338,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
15,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
199,
646,
747,
199,
199,
646,
6160,
199,
504,
1639,
63,
12264,
14,
10372,
492,
6186,
63,
18451,
199,
199,
5441,
63,
3022,
275,
6160,
14,
2042,
3460,
493,
3368,
446,
650,
221,
327,
334,
15,
65,
15,
66,
15,
29384,
14,
647,
446,
650,
275,
1182,
9,
199,
14219,
63,
3022,
275,
16547,
63,
3022,
14,
515,
360,
545,
736,
8571,
358,
199,
199,
3,
15783,
24847,
687,
314,
2446,
7090,
736,
8571,
4922,
199,
20828,
63,
20202,
275,
359,
272,
747,
14,
515,
14,
904,
8,
495,
8,
14219,
63,
3022,
395,
298,
5508,
531,
199,
61,
199,
199,
1813,
275,
6160,
14,
7744,
342,
199,
3,
982,
314,
2199,
1738,
3509,
282,
1275,
1813,
570,
12,
1586,
652,
199,
692,
747,
14,
515,
14,
6292,
8,
495,
8,
5441,
63,
3022,
435,
1987,
1813,
8109,
272,
6160,
14,
7744,
14,
739,
63,
1813,
8,
495,
8,
5441,
63,
3022,
435,
1987,
1813,
1333,
199,
199,
3,
19525,
15869,
15301,
199,
3,
5620,
10965,
199,
22848,
63,
14219,
275,
334,
272,
327,
3758,
5634,
8686,
26,
272,
283,
1176,
14,
2828,
14,
1178,
297,
272,
283,
1176,
14,
2828,
14,
10778,
297,
272,
283,
1176,
14,
2828,
14,
11676,
297,
272,
283,
1176,
14,
2828,
14,
8619,
297,
272,
283,
1176,
14,
2828,
14,
3431,
297,
272,
283,
1176,
14,
2828,
14,
18373,
297,
339,
327,
18491,
1978,
3762,
26,
272,
327,
283,
1176,
14,
2828,
14,
14864,
794,
297,
339,
327,
9516,
272,
283,
1176,
14,
2828,
14,
2113,
297,
199,
9,
199,
2080,
3927,
36,
63,
4014,
2099,
63,
14219,
275,
334,
272,
283,
1176,
63,
12264,
297,
272,
283,
1408,
15252,
63,
3351,
297,
221,
327,
8204,
7054,
83,
272,
283,
29339,
762,
297,
221,
327,
10991,
272,
283,
29339,
762,
14,
2048,
297,
221,
327,
10991,
272,
283,
29339,
762,
14,
31932,
297,
221,
327,
10991,
272,
283,
3911,
63,
4857,
297,
221,
327,
14880,
3261,
272,
283,
1176,
63,
4792,
964,
297,
272,
283,
1176,
63,
2416,
18,
297,
199,
9,
199,
199,
3,
4693,
83,
2488,
367,
642,
2199,
2621,
2348,
14,
199,
7486,
63,
14219,
275,
334,
272,
283,
545,
736,
8571,
14,
3707,
297,
272,
283,
545,
736,
8571,
14,
28129,
297,
199,
9,
199,
199,
3,
1666,
26,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
12645,
7657,
13,
5181,
199,
15942,
63,
14219,
275,
577,
42,
18822,
63,
14219,
435,
4221,
3927,
36,
63,
4014,
2099,
63,
14219,
435,
20639,
63,
14219,
199,
199,
3,
30718,
15869,
15301,
199,
3,
5620,
10965,
199,
19987,
63,
13748,
275,
334,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
5754,
14,
5508,
14,
20342,
6608,
297,
272,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
272,
283,
1176,
14,
5754,
14,
10088,
14,
13912,
25322,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
297,
272,
283,
1176,
14,
2828,
14,
3431,
14,
5754,
14,
2209,
6608,
297,
272,
283,
1176,
14,
5754,
14,
4891,
19193,
316,
14,
56,
3160,
4558,
6608,
297,
199,
9,
199,
199,
3,
603,
1277,
50,
12969,
15869,
15301,
199,
3,
5620,
10965,
199,
22487,
23743,
63,
21194,
275,
469,
272,
283,
8619,
356,
283,
545,
736,
8571,
14,
2828,
14,
8619,
14,
7685,
7,
199,
93,
199,
199,
3,
10990,
199,
3,
5620,
10965,
199,
3,
1666,
26,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
12645,
1757,
199,
5287,
275,
2589,
14,
2245,
480,
22848,
63,
5287,
401,
756,
9,
199,
199,
3,
7333,
52,
3942,
15869,
15301,
199,
3,
5620,
10965,
199,
3,
1666,
26,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
12645,
1516,
26,
6031,
13,
5192,
52,
3942,
63,
14455,
199,
5192,
52,
3942,
63,
14455,
275,
334,
272,
620,
8,
14219,
63,
3022,
14,
515,
360,
8769,
3855,
199,
9,
199,
199,
3,
32320,
15869,
15301,
199,
3,
5620,
10965,
199,
10089,
63,
18145,
275,
2589,
360,
22848,
63,
10089,
63,
18145,
297,
849,
534,
1176,
14,
1018,
14,
1198,
14,
7765,
14,
15592,
14,
7035,
8447,
358,
199,
199,
3,
26688,
1254,
540,
15869,
15301,
199,
3,
5620,
10965,
199,
3,
1666,
26,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
12645,
23121,
199,
14288,
51,
275,
6248,
199,
199,
3,
1666,
26,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
12645,
16259,
199,
20600,
3960,
275,
29948,
51,
199,
199,
3,
31705,
15869,
15301,
199,
3,
5620,
10965,
199,
3,
1666,
26,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
12645,
17439,
199,
27260,
275,
469,
272,
327,
6218,
11897,
1919,
340,
31705,
63,
2632,
440,
315,
747,
14,
2314,
272,
283,
885,
356,
2589,
14,
697,
480,
17873,
63,
2632,
401,
849,
628,
10659,
921,
5321,
16,
5995,
545,
736,
8571,
14,
10659,
1674,
908,
8,
5441,
63,
3022,
1826,
199,
93,
199,
27260,
459,
885,
2545,
22479,
948,
63,
6780,
51,
418,
275,
715,
421,
199,
3,
29087,
748,
15869,
15301,
199,
3,
5620,
10965,
199,
3,
10111,
900,
5718,
367,
642,
12096,
14,
8802,
2370,
883,
506,
1911,
2348,
26,
199,
3,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
1296,
63,
1618,
63,
3903,
63,
13325,
63,
991,
63,
354,
199,
3,
22160,
440,
1006,
3415,
1443,
506,
2808,
641,
1006,
17406,
10460,
14,
199,
3
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
9323,
2202,
367,
7090,
736,
8571,
2199,
14,
199,
199,
1858,
1655,
2556,
641,
642,
570,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
11299,
15,
1751,
15,
199,
199,
1858,
314,
2615,
769,
402,
2202,
436,
3932,
1338,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
15,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
199,
646,
747,
199,
199,
646,
6160,
199,
504,
1639,
63,
12264,
14,
10372,
492,
6186,
63,
18451,
199,
199,
5441,
63,
3022,
275,
6160,
14,
2042,
3460,
493,
3368,
446,
650,
221,
327,
334,
15,
65,
15,
66,
15,
29384,
14,
647,
446,
650,
275,
1182,
9,
199,
14219,
63,
3022,
275,
16547,
63,
3022,
14,
515,
360,
545,
736,
8571,
358,
199,
199,
3,
15783,
24847,
687,
314,
2446,
7090,
736,
8571,
4922,
199,
20828,
63,
20202,
275,
359,
272,
747,
14,
515,
14,
904,
8,
495,
8,
14219,
63,
3022,
395,
298,
5508,
531,
199,
61,
199,
199,
1813,
275,
6160,
14,
7744,
342,
199,
3,
982,
314,
2199,
1738,
3509,
282,
1275,
1813,
570,
12,
1586,
652,
199,
692,
747,
14,
515,
14,
6292,
8,
495,
8,
5441,
63,
3022,
435,
1987,
1813,
8109,
272,
6160,
14,
7744,
14,
739,
63,
1813,
8,
495,
8,
5441,
63,
3022,
435,
1987,
1813,
1333,
199,
199,
3,
19525,
15869,
15301,
199,
3,
5620,
10965,
199,
22848,
63,
14219,
275,
334,
272,
327,
3758,
5634,
8686,
26,
272,
283,
1176,
14,
2828,
14,
1178,
297,
272,
283,
1176,
14,
2828,
14,
10778,
297,
272,
283,
1176,
14,
2828,
14,
11676,
297,
272,
283,
1176,
14,
2828,
14,
8619,
297,
272,
283,
1176,
14,
2828,
14,
3431,
297,
272,
283,
1176,
14,
2828,
14,
18373,
297,
339,
327,
18491,
1978,
3762,
26,
272,
327,
283,
1176,
14,
2828,
14,
14864,
794,
297,
339,
327,
9516,
272,
283,
1176,
14,
2828,
14,
2113,
297,
199,
9,
199,
2080,
3927,
36,
63,
4014,
2099,
63,
14219,
275,
334,
272,
283,
1176,
63,
12264,
297,
272,
283,
1408,
15252,
63,
3351,
297,
221,
327,
8204,
7054,
83,
272,
283,
29339,
762,
297,
221,
327,
10991,
272,
283,
29339,
762,
14,
2048,
297,
221,
327,
10991,
272,
283,
29339,
762,
14,
31932,
297,
221,
327,
10991,
272,
283,
3911,
63,
4857,
297,
221,
327,
14880,
3261,
272,
283,
1176,
63,
4792,
964,
297,
272,
283,
1176,
63,
2416,
18,
297,
199,
9,
199,
199,
3,
4693,
83,
2488,
367,
642,
2199,
2621,
2348,
14,
199,
7486,
63,
14219,
275,
334,
272,
283,
545,
736,
8571,
14,
3707,
297,
272,
283,
545,
736,
8571,
14,
28129,
297,
199,
9,
199,
199,
3,
1666,
26,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
12645,
7657,
13,
5181,
199,
15942,
63,
14219,
275,
577,
42,
18822,
63,
14219,
435,
4221,
3927,
36,
63,
4014,
2099,
63,
14219,
435,
20639,
63,
14219,
199,
199,
3,
30718,
15869,
15301,
199,
3,
5620,
10965,
199,
19987,
63,
13748,
275,
334,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
5754,
14,
5508,
14,
20342,
6608,
297,
272,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
272,
283,
1176,
14,
5754,
14,
10088,
14,
13912,
25322,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
297,
272,
283,
1176,
14,
2828,
14,
3431,
14,
5754,
14,
2209,
6608,
297,
272,
283,
1176,
14,
5754,
14,
4891,
19193,
316,
14,
56,
3160,
4558,
6608,
297,
199,
9,
199,
199,
3,
603,
1277,
50,
12969,
15869,
15301,
199,
3,
5620,
10965,
199,
22487,
23743,
63,
21194,
275,
469,
272,
283,
8619,
356,
283,
545,
736,
8571,
14,
2828,
14,
8619,
14,
7685,
7,
199,
93,
199,
199,
3,
10990,
199,
3,
5620,
10965,
199,
3,
1666,
26,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
12645,
1757,
199,
5287,
275,
2589,
14,
2245,
480,
22848,
63,
5287,
401,
756,
9,
199,
199,
3,
7333,
52,
3942,
15869,
15301,
199,
3,
5620,
10965,
199,
3,
1666,
26,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
12645,
1516,
26,
6031,
13,
5192,
52,
3942,
63,
14455,
199,
5192,
52,
3942,
63,
14455,
275,
334,
272,
620,
8,
14219,
63,
3022,
14,
515,
360,
8769,
3855,
199,
9,
199,
199,
3,
32320,
15869,
15301,
199,
3,
5620,
10965,
199,
10089,
63,
18145,
275,
2589,
360,
22848,
63,
10089,
63,
18145,
297,
849,
534,
1176,
14,
1018,
14,
1198,
14,
7765,
14,
15592,
14,
7035,
8447,
358,
199,
199,
3,
26688,
1254,
540,
15869,
15301,
199,
3,
5620,
10965,
199,
3,
1666,
26,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
12645,
23121,
199,
14288,
51,
275,
6248,
199,
199,
3,
1666,
26,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
12645,
16259,
199,
20600,
3960,
275,
29948,
51,
199,
199,
3,
31705,
15869,
15301,
199,
3,
5620,
10965,
199,
3,
1666,
26,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
12645,
17439,
199,
27260,
275,
469,
272,
327,
6218,
11897,
1919,
340,
31705,
63,
2632,
440,
315,
747,
14,
2314,
272,
283,
885,
356,
2589,
14,
697,
480,
17873,
63,
2632,
401,
849,
628,
10659,
921,
5321,
16,
5995,
545,
736,
8571,
14,
10659,
1674,
908,
8,
5441,
63,
3022,
1826,
199,
93,
199,
27260,
459,
885,
2545,
22479,
948,
63,
6780,
51,
418,
275,
715,
421,
199,
3,
29087,
748,
15869,
15301,
199,
3,
5620,
10965,
199,
3,
10111,
900,
5718,
367,
642,
12096,
14,
8802,
2370,
883,
506,
1911,
2348,
26,
199,
3,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
1296,
63,
1618,
63,
3903,
63,
13325,
63,
991,
63,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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
cyb0/volatility
|
contrib/plugins/scanprof.py
|
55
|
1965
|
# Volatility
#
# Authors:
# Mike Auty <mike.auty@gmail.com>
#
# This file is part of Volatility.
#
# Volatility 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.
#
# Volatility 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 Volatility. If not, see <http://www.gnu.org/licenses/>.
#
import sys
import itertools
import timeit
class ScanProfInstance(object):
def __init__(self, func, *args):
self.func = func
self.args = args
self.results = []
def __call__(self):
self.results = self.func(*self.args)
def permscan(self, address_space, offset = 0, maxlen = None):
times = []
# Run a warm-up scan to ensure the file is cached as much as possible
self.oldscan(address_space, offset, maxlen)
perms = list(itertools.permutations(self.checks))
for i in range(len(perms)):
self.checks = perms[i]
print "Running scan {0}/{1}...".format(i + 1, len(perms))
profobj = ScanProfInstance(self.oldscan, address_space, offset, maxlen)
value = timeit.timeit(profobj, number = self.repeats)
times.append((value, len(list(profobj.results)), i))
print "Scan results"
print "{0:20} | {1:7} | {2:6} | {3}".format("Time", "Results", "Perm #", "Ordering")
for val, l, ordering in sorted(times):
print "{0:20} | {1:7} | {2:6} | {3}".format(val, l, ordering, perms[ordering])
sys.exit(1)
def ScanProfiler(cls, repeats = 3):
cls.repeats = repeats
cls.oldscan = cls.scan
cls.scan = permscan
return cls
|
gpl-2.0
|
[
3,
28367,
199,
3,
199,
3,
6642,
26,
199,
3,
603,
7455,
437,
19974,
665,
2664,
415,
14,
6898,
89,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28367,
14,
199,
3,
199,
3,
28367,
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,
28367,
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,
28367,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
646,
984,
199,
646,
7975,
199,
646,
900,
390,
199,
199,
533,
24833,
919,
70,
3244,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
2562,
12,
627,
589,
304,
267,
291,
14,
1532,
275,
2562,
267,
291,
14,
589,
275,
1249,
267,
291,
14,
2604,
275,
942,
339,
347,
636,
1250,
721,
277,
304,
267,
291,
14,
2604,
275,
291,
14,
1532,
2031,
277,
14,
589,
9,
199,
199,
318,
10869,
6282,
8,
277,
12,
2287,
63,
2638,
12,
3268,
275,
378,
12,
21037,
275,
488,
304,
272,
5431,
275,
942,
272,
327,
3378,
282,
20060,
13,
384,
8000,
370,
4868,
314,
570,
365,
6328,
465,
8298,
465,
3962,
272,
291,
14,
1753,
6282,
8,
1562,
63,
2638,
12,
3268,
12,
21037,
9,
339,
17340,
275,
769,
8,
17691,
14,
28237,
8,
277,
14,
8625,
430,
272,
367,
284,
315,
1425,
8,
552,
8,
12068,
2298,
267,
291,
14,
8625,
275,
17340,
59,
73,
61,
267,
870,
298,
9602,
8000,
469,
16,
16152,
17,
93,
1396,
1674,
908,
8,
73,
435,
413,
12,
822,
8,
12068,
430,
267,
557,
32755,
275,
24833,
919,
70,
3244,
8,
277,
14,
1753,
6282,
12,
2287,
63,
2638,
12,
3268,
12,
21037,
9,
267,
574,
275,
900,
390,
14,
521,
390,
8,
496,
32755,
12,
1329,
275,
291,
14,
32547,
9,
267,
5431,
14,
740,
1332,
585,
12,
822,
8,
513,
8,
496,
32755,
14,
2604,
1826,
284,
430,
339,
870,
298,
15936,
2058,
2,
272,
870,
5310,
16,
26,
1165,
93,
1204,
469,
17,
26,
23,
93,
1204,
469,
18,
26,
22,
93,
1204,
469,
19,
5469,
908,
480,
1366,
401,
298,
6579,
401,
298,
23554,
327,
401,
298,
4738,
316,
531,
272,
367,
1139,
12,
634,
12,
7794,
315,
3355,
8,
4508,
304,
267,
870,
5310,
16,
26,
1165,
93,
1204,
469,
17,
26,
23,
93,
1204,
469,
18,
26,
22,
93,
1204,
469,
19,
5469,
908,
8,
637,
12,
634,
12,
7794,
12,
17340,
59,
7128,
566,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
318,
24833,
5736,
82,
8,
1886,
12,
28908,
275,
650,
304,
272,
843,
14,
32547,
275,
28908,
272,
843,
14,
1753,
6282,
275,
843,
14,
6282,
272,
843,
14,
6282,
275,
10869,
6282,
272,
372,
843,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
28367,
199,
3,
199,
3,
6642,
26,
199,
3,
603,
7455,
437,
19974,
665,
2664,
415,
14,
6898,
89,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28367,
14,
199,
3,
199,
3,
28367,
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,
28367,
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,
28367,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
646,
984,
199,
646,
7975,
199,
646,
900,
390,
199,
199,
533,
24833,
919,
70,
3244,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
2562,
12,
627,
589,
304,
267,
291,
14,
1532,
275,
2562,
267,
291,
14,
589,
275,
1249,
267,
291,
14,
2604,
275,
942,
339,
347,
636,
1250,
721,
277,
304,
267,
291,
14,
2604,
275,
291,
14,
1532,
2031,
277,
14,
589,
9,
199,
199,
318,
10869,
6282,
8,
277,
12,
2287,
63,
2638,
12,
3268,
275,
378,
12,
21037,
275,
488,
304,
272,
5431,
275,
942,
272,
327,
3378,
282,
20060,
13,
384,
8000,
370,
4868,
314,
570,
365,
6328,
465,
8298,
465,
3962,
272,
291,
14,
1753,
6282,
8,
1562,
63,
2638,
12,
3268,
12,
21037,
9,
339,
17340,
275,
769,
8,
17691,
14,
28237,
8,
277,
14,
8625,
430,
272,
367,
284,
315,
1425,
8,
552,
8,
12068,
2298,
267,
291,
14,
8625,
275,
17340,
59,
73,
61,
267,
870,
298,
9602,
8000,
469,
16,
16152,
17,
93,
1396,
1674,
908,
8,
73,
435,
413,
12,
822,
8,
12068,
430,
267,
557,
32755,
275,
24833,
919,
70,
3244,
8,
277,
14,
1753,
6282,
12,
2287,
63,
2638,
12,
3268,
12,
21037,
9,
267,
574,
275,
900,
390,
14,
521,
390,
8,
496,
32755,
12,
1329,
275,
291,
14,
32547,
9,
267,
5431,
14,
740,
1332,
585,
12,
822,
8,
513,
8,
496,
32755,
14,
2604,
1826,
284,
430,
339,
870,
298,
15936,
2058,
2,
272,
870,
5310,
16,
26,
1165,
93,
1204,
469,
17,
26,
23,
93,
1204,
469,
18,
26,
22,
93,
1204,
469,
19,
5469,
908,
480,
1366,
401,
298,
6579,
401,
298,
23554,
327,
401,
298,
4738,
316,
531,
272,
367,
1139,
12,
634,
12,
7794,
315,
3355,
8,
4508,
304,
267,
870,
5310,
16,
26,
1165,
93,
1204,
469,
17,
26,
23,
93,
1204,
469,
18,
26,
22,
93,
1204,
469,
19,
5469,
908,
8,
637,
12,
634,
12,
7794,
12,
17340,
59,
7128,
566,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
318,
24833,
5736,
82,
8,
1886,
12,
28908,
275,
650,
304,
272,
843,
14,
32547,
275,
28908,
272,
843,
14,
1753,
6282,
275,
843,
14,
6282,
272,
843,
14,
6282,
275,
10869,
6282,
272,
372,
843,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
quentinlautischer/291MiniProject2
|
lib/python3.5/site-packages/pip/_vendor/requests/packages/urllib3/filepost.py
|
551
|
2512
|
# urllib3/filepost.py
# Copyright 2008-2013 Andrey Petrov and contributors (see CONTRIBUTORS.txt)
#
# This module is part of urllib3 and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
import codecs
import mimetypes
from uuid import uuid4
from io import BytesIO
from .packages import six
from .packages.six import b
from .fields import RequestField
writer = codecs.lookup('utf-8')[3]
def choose_boundary():
"""
Our embarassingly-simple replacement for mimetools.choose_boundary.
"""
return uuid4().hex
def iter_field_objects(fields):
"""
Iterate over fields.
Supports list of (k, v) tuples and dicts, and lists of
:class:`~urllib3.fields.RequestField`.
"""
if isinstance(fields, dict):
i = six.iteritems(fields)
else:
i = iter(fields)
for field in i:
if isinstance(field, RequestField):
yield field
else:
yield RequestField.from_tuples(*field)
def iter_fields(fields):
"""
.. deprecated:: 1.6
Iterate over fields.
The addition of :class:`~urllib3.fields.RequestField` makes this function
obsolete. Instead, use :func:`iter_field_objects`, which returns
:class:`~urllib3.fields.RequestField` objects.
Supports list of (k, v) tuples and dicts.
"""
if isinstance(fields, dict):
return ((k, v) for k, v in six.iteritems(fields))
return ((k, v) for k, v in fields)
def encode_multipart_formdata(fields, boundary=None):
"""
Encode a dictionary of ``fields`` using the multipart/form-data MIME format.
:param fields:
Dictionary of fields or list of (key, :class:`~urllib3.fields.RequestField`).
:param boundary:
If not specified, then a random boundary will be generated using
:func:`mimetools.choose_boundary`.
"""
body = BytesIO()
if boundary is None:
boundary = choose_boundary()
for field in iter_field_objects(fields):
body.write(b('--%s\r\n' % (boundary)))
writer(body).write(field.render_headers())
data = field.data
if isinstance(data, int):
data = str(data) # Backwards compatibility
if isinstance(data, six.text_type):
writer(body).write(data)
else:
body.write(data)
body.write(b'\r\n')
body.write(b('--%s--\r\n' % (boundary)))
content_type = str('multipart/form-data; boundary=%s' % boundary)
return body.getvalue(), content_type
|
apache-2.0
|
[
3,
4011,
19,
15,
493,
1932,
14,
647,
199,
3,
1898,
9079,
13,
6965,
6061,
17885,
31449,
293,
86,
436,
8417,
334,
3239,
6483,
14,
2424,
9,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
4011,
19,
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,
646,
6010,
199,
646,
13290,
199,
199,
504,
5377,
492,
5377,
20,
199,
504,
5890,
492,
11808,
199,
199,
504,
1275,
5154,
492,
3816,
199,
504,
1275,
5154,
14,
4174,
492,
330,
199,
504,
1275,
955,
492,
4784,
792,
199,
199,
5491,
275,
6010,
14,
3892,
360,
1624,
13,
24,
5832,
19,
61,
421,
199,
318,
11496,
63,
9891,
837,
272,
408,
272,
25119,
25316,
285,
405,
316,
590,
13,
4129,
8343,
367,
6660,
2537,
14,
16143,
63,
9891,
14,
272,
408,
272,
372,
5377,
20,
1252,
4097,
421,
199,
318,
2740,
63,
698,
63,
1462,
8,
955,
304,
272,
408,
272,
23989,
1806,
1504,
14,
339,
32090,
769,
402,
334,
75,
12,
373,
9,
6346,
436,
10809,
12,
436,
5548,
402,
272,
520,
533,
6054,
4078,
19,
14,
955,
14,
2017,
792,
2313,
339,
408,
272,
340,
1228,
8,
955,
12,
1211,
304,
267,
284,
275,
3816,
14,
4611,
8,
955,
9,
272,
587,
26,
267,
284,
275,
2740,
8,
955,
9,
339,
367,
901,
315,
284,
26,
489,
340,
1228,
8,
698,
12,
4784,
792,
304,
267,
1995,
901,
489,
587,
26,
267,
1995,
4784,
792,
14,
504,
63,
11760,
2031,
698,
9,
421,
199,
318,
2740,
63,
955,
8,
955,
304,
272,
408,
272,
2508,
5906,
447,
413,
14,
22,
339,
23989,
1806,
1504,
14,
339,
710,
10234,
402,
520,
533,
6054,
4078,
19,
14,
955,
14,
2017,
792,
64,
7704,
642,
805,
272,
24985,
14,
15345,
12,
675,
520,
1532,
1705,
1661,
63,
698,
63,
1462,
3559,
1314,
2529,
272,
520,
533,
6054,
4078,
19,
14,
955,
14,
2017,
792,
64,
2251,
14,
339,
32090,
769,
402,
334,
75,
12,
373,
9,
6346,
436,
10809,
14,
272,
408,
272,
340,
1228,
8,
955,
12,
1211,
304,
267,
372,
3666,
75,
12,
373,
9,
367,
1022,
12,
373,
315,
3816,
14,
4611,
8,
955,
430,
339,
372,
3666,
75,
12,
373,
9,
367,
1022,
12,
373,
315,
1504,
9,
421,
199,
318,
3752,
63,
10123,
63,
30942,
8,
955,
12,
8424,
29,
403,
304,
272,
408,
272,
19244,
282,
2600,
402,
1124,
955,
1040,
1808,
314,
15193,
15,
964,
13,
576,
14735,
1475,
14,
339,
520,
635,
1504,
26,
267,
11932,
402,
1504,
503,
769,
402,
334,
498,
12,
520,
533,
6054,
4078,
19,
14,
955,
14,
2017,
792,
14963,
339,
520,
635,
8424,
26,
267,
982,
440,
2013,
12,
2066,
282,
2196,
8424,
911,
506,
4046,
1808,
267,
520,
1532,
1705,
7626,
2537,
14,
16143,
63,
9891,
2313,
272,
408,
272,
2396,
275,
11808,
342,
272,
340,
8424,
365,
488,
26,
267,
8424,
275,
11496,
63,
9891,
342,
339,
367,
901,
315,
2740,
63,
698,
63,
1462,
8,
955,
304,
267,
2396,
14,
952,
8,
66,
4517,
5,
83,
60,
82,
60,
78,
7,
450,
334,
9891,
1724,
398,
7060,
8,
2030,
680,
952,
8,
698,
14,
3352,
63,
2139,
1012,
267,
666,
275,
901,
14,
576,
398,
340,
1228,
8,
576,
12,
1109,
304,
288,
666,
275,
620,
8,
576,
9,
221,
327,
10257,
4751,
7163,
398,
340,
1228,
8,
576,
12,
3816,
14,
505,
63,
466,
304,
288,
7060,
8,
2030,
680,
952,
8,
576,
9,
267,
587,
26,
288,
2396,
14,
952,
8,
576,
9,
398,
2396,
14,
952,
8,
66,
1154,
82,
60,
78,
358,
339,
2396,
14,
952,
8,
66,
4517,
5,
83,
306,
60,
82,
60,
78,
7,
450,
334,
9891,
1724,
339,
1564,
63,
466,
275,
620,
360,
10123,
15,
964,
13,
576,
27,
8424,
2458,
83,
7,
450,
8424,
9,
339,
372,
2396,
14,
7150,
1062,
1564,
63,
466,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4011,
19,
15,
493,
1932,
14,
647,
199,
3,
1898,
9079,
13,
6965,
6061,
17885,
31449,
293,
86,
436,
8417,
334,
3239,
6483,
14,
2424,
9,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
4011,
19,
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,
646,
6010,
199,
646,
13290,
199,
199,
504,
5377,
492,
5377,
20,
199,
504,
5890,
492,
11808,
199,
199,
504,
1275,
5154,
492,
3816,
199,
504,
1275,
5154,
14,
4174,
492,
330,
199,
504,
1275,
955,
492,
4784,
792,
199,
199,
5491,
275,
6010,
14,
3892,
360,
1624,
13,
24,
5832,
19,
61,
421,
199,
318,
11496,
63,
9891,
837,
272,
408,
272,
25119,
25316,
285,
405,
316,
590,
13,
4129,
8343,
367,
6660,
2537,
14,
16143,
63,
9891,
14,
272,
408,
272,
372,
5377,
20,
1252,
4097,
421,
199,
318,
2740,
63,
698,
63,
1462,
8,
955,
304,
272,
408,
272,
23989,
1806,
1504,
14,
339,
32090,
769,
402,
334,
75,
12,
373,
9,
6346,
436,
10809,
12,
436,
5548,
402,
272,
520,
533,
6054,
4078,
19,
14,
955,
14,
2017,
792,
2313,
339,
408,
272,
340,
1228,
8,
955,
12,
1211,
304,
267,
284,
275,
3816,
14,
4611,
8,
955,
9,
272,
587,
26,
267,
284,
275,
2740,
8,
955,
9,
339,
367,
901,
315,
284,
26,
489,
340,
1228,
8,
698,
12,
4784,
792,
304,
267,
1995,
901,
489,
587,
26,
267,
1995,
4784,
792,
14,
504,
63,
11760,
2031,
698,
9,
421,
199,
318,
2740,
63,
955,
8,
955,
304,
272,
408,
272,
2508,
5906,
447,
413,
14,
22,
339,
23989,
1806,
1504,
14,
339,
710,
10234,
402,
520,
533,
6054,
4078,
19,
14,
955,
14,
2017,
792,
64,
7704,
642,
805,
272,
24985,
14,
15345,
12,
675,
520,
1532,
1705,
1661,
63,
698,
63,
1462,
3559,
1314,
2529,
272,
520,
533,
6054,
4078,
19,
14,
955,
14,
2017,
792,
64,
2251,
14,
339,
32090,
769,
402,
334,
75,
12,
373,
9,
6346,
436,
10809,
14,
272,
408,
272,
340,
1228,
8,
955,
12,
1211,
304,
267,
372,
3666,
75,
12,
373,
9,
367,
1022,
12,
373,
315,
3816,
14,
4611,
8,
955,
430,
339,
372,
3666,
75,
12,
373,
9,
367,
1022,
12,
373,
315,
1504,
9,
421,
199,
318,
3752,
63,
10123,
63,
30942,
8,
955,
12,
8424,
29,
403,
304,
272,
408,
272,
19244,
282,
2600,
402,
1124,
955,
1040,
1808,
314,
15193,
15,
964,
13,
576,
14735,
1475,
14,
339,
520,
635,
1504,
26,
267,
11932,
402,
1504,
503,
769,
402,
334,
498,
12,
520,
533,
6054,
4078,
19,
14,
955,
14,
2017,
792,
14963,
339,
520,
635,
8424,
26,
267,
982,
440,
2013,
12,
2066,
282,
2196,
8424,
911,
506,
4046,
1808,
267,
520,
1532,
1705,
7626,
2537,
14,
16143,
63,
9891,
2313,
272,
408,
272,
2396,
275,
11808,
342,
272,
340,
8424,
365,
488,
26,
267,
8424,
275,
11496,
63,
9891,
342,
339,
367,
901,
315,
2740,
63,
698,
63,
1462,
8,
955,
304,
267,
2396,
14,
952,
8,
66,
4517,
5,
83,
60,
82,
60,
78,
7,
450,
334,
9891,
1724,
398,
7060,
8,
2030,
680,
952,
8,
698,
14,
3352,
63,
2139,
1012,
267,
666,
275,
901,
14,
576,
398,
340,
1228,
8,
576,
12,
1109,
304,
288,
666,
275,
620,
8,
576,
9,
221,
327,
10257,
4751,
7163,
398,
340,
1228,
8,
576,
12,
3816,
14,
505,
63,
466,
304,
288,
7060,
8,
2030,
680,
952,
8,
576,
9,
267,
587,
26,
288,
2396,
14,
952,
8,
576,
9,
398,
2396,
14,
952,
8,
66,
1154,
82,
60,
78,
358,
339,
2396,
14,
952,
8,
66,
4517,
5,
83,
306,
60,
82,
60,
78,
7,
450,
334,
9891,
1724,
339,
1564,
63,
466,
275,
620,
360,
10123,
15,
964,
13,
576,
27,
8424,
2458,
83,
7,
450,
8424,
9,
339,
372,
2396,
14,
7150,
1062,
1564,
63,
466,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
switchboardOp/ansible
|
lib/ansible/module_utils/_text.py
|
23
|
12327
|
# This code is part of Ansible, but is an independent component.
# This particular file snippet, and this file snippet only, is BSD licensed.
# Modules you write using this snippet, which is embedded dynamically by Ansible
# still belong to the author of the module, and may assign their own license
# to the complete work.
#
# Copyright (c), Toshio Kuratomi <a.badger@gmail.com>, 2016
#
# 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.
#
# 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 HOLDER 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.
#
"""
.. warn:: This module_util is currently internal implementation.
We want to evaluate this code for stability and API suitability before
making backwards compatibility guarantees. The API may change between
releases. Do not use this unless you are willing to port your module code.
"""
import codecs
from ansible.module_utils.six import PY3, text_type, binary_type
try:
codecs.lookup_error('surrogateescape')
HAS_SURROGATEESCAPE = True
except LookupError:
HAS_SURROGATEESCAPE = False
_COMPOSED_ERROR_HANDLERS = frozenset((None, 'surrogate_or_escape',
'surrogate_or_strict',
'surrogate_then_replace'))
def to_bytes(obj, encoding='utf-8', errors=None, nonstring='simplerepr'):
"""Make sure that a string is a byte string
:arg obj: An object to make sure is a byte string. In most cases this
will be either a text string or a byte string. However, with
``nonstring='simplerepr'``, this can be used as a traceback-free
version of ``str(obj)``.
:kwarg encoding: The encoding to use to transform from a text string to
a byte string. Defaults to using 'utf-8'.
:kwarg errors: The error handler to use if the text string is not
encodable using the specified encoding. Any valid `codecs error
handler <https://docs.python.org/2/library/codecs.html#codec-base-classes>`_
may be specified. There are three additional error strategies
specifically aimed at helping people to port code. The first two are:
:surrogate_or_strict: Will use ``surrogateescape`` if it is a valid
handler, otherwise it will use ``strict``
:surrogate_or_replace: Will use ``surrogateescape`` if it is a valid
handler, otherwise it will use ``replace``.
Because ``surrogateescape`` was added in Python3 this usually means that
Python3 will use ``surrogateescape`` and Python2 will use the fallback
error handler. Note that the code checks for ``surrogateescape`` when the
module is imported. If you have a backport of ``surrogateescape`` for
Python2, be sure to register the error handler prior to importing this
module.
The last error handler is:
:surrogate_then_replace: Will use ``surrogateescape`` if it is a valid
handler. If encoding with ``surrogateescape`` would traceback,
surrogates are first replaced with a replacement characters
and then the string is encoded using ``replace`` (which replaces
the rest of the nonencodable bytes). If ``surrogateescape`` is
not present it will simply use ``replace``. (Added in Ansible 2.3)
This strategy is designed to never traceback when it attempts
to encode a string.
The default until Ansible-2.2 was ``surrogate_or_replace``
From Ansible-2.3 onwards, the default is ``surrogate_then_replace``.
:kwarg nonstring: The strategy to use if a nonstring is specified in
``obj``. Default is 'simplerepr'. Valid values are:
:simplerepr: The default. This takes the ``str`` of the object and
then returns the bytes version of that string.
:empty: Return an empty byte string
:passthru: Return the object passed in
:strict: Raise a :exc:`TypeError`
:returns: Typically this returns a byte string. If a nonstring object is
passed in this may be a different type depending on the strategy
specified by nonstring. This will never return a text string.
.. note:: If passed a byte string, this function does not check that the
string is valid in the specified encoding. If it's important that the
byte string is in the specified encoding do::
encoded_string = to_bytes(to_text(input_string, 'latin-1'), 'utf-8')
.. version_changed:: 2.3
Added the ``surrogate_then_replace`` error handler and made it the default error handler.
"""
if isinstance(obj, binary_type):
return obj
# We're given a text string
# If it has surrogates, we know because it will decode
original_errors = errors
if errors in _COMPOSED_ERROR_HANDLERS:
if HAS_SURROGATEESCAPE:
errors = 'surrogateescape'
elif errors == 'surrogate_or_strict':
errors = 'strict'
else:
errors = 'replace'
if isinstance(obj, text_type):
try:
# Try this first as it's the fastest
return obj.encode(encoding, errors)
except UnicodeEncodeError:
if original_errors in (None, 'surrogate_then_replace'):
# Slow but works
return_string = obj.encode('utf-8', 'surrogateescape')
return_string = return_string.decode('utf-8', 'replace')
return return_string.encode(encoding, 'replace')
raise
# Note: We do these last even though we have to call to_bytes again on the
# value because we're optimizing the common case
if nonstring == 'simplerepr':
try:
value = str(obj)
except UnicodeError:
try:
value = repr(obj)
except UnicodeError:
# Giving up
return to_bytes('')
elif nonstring == 'passthru':
return obj
elif nonstring == 'empty':
# python2.4 doesn't have b''
return to_bytes('')
elif nonstring == 'strict':
raise TypeError('obj must be a string type')
else:
raise TypeError('Invalid value %s for to_bytes\' nonstring parameter' % nonstring)
return to_bytes(value, encoding, errors)
def to_text(obj, encoding='utf-8', errors=None, nonstring='simplerepr'):
"""Make sure that a string is a text string
:arg obj: An object to make sure is a text string. In most cases this
will be either a text string or a byte string. However, with
``nonstring='simplerepr'``, this can be used as a traceback-free
version of ``str(obj)``.
:kwarg encoding: The encoding to use to transform from a byte string to
a text string. Defaults to using 'utf-8'.
:kwarg errors: The error handler to use if the byte string is not
decodable using the specified encoding. Any valid `codecs error
handler <https://docs.python.org/2/library/codecs.html#codec-base-classes>`_
may be specified. We support three additional error strategies
specifically aimed at helping people to port code:
:surrogate_or_strict: Will use surrogateescape if it is a valid
handler, otherwise it will use strict
:surrogate_or_replace: Will use surrogateescape if it is a valid
handler, otherwise it will use replace.
:surrogate_then_replace: Does the same as surrogate_or_replace but
`was added for symmetry with the error handlers in
:func:`ansible.module_utils._text.to_bytes` (Added in Ansible 2.3)
Because surrogateescape was added in Python3 this usually means that
Python3 will use `surrogateescape` and Python2 will use the fallback
error handler. Note that the code checks for surrogateescape when the
module is imported. If you have a backport of `surrogateescape` for
python2, be sure to register the error handler prior to importing this
module.
The default until Ansible-2.2 was `surrogate_or_replace`
In Ansible-2.3 this defaults to `surrogate_then_replace` for symmetry
with :func:`ansible.module_utils._text.to_bytes` .
:kwarg nonstring: The strategy to use if a nonstring is specified in
``obj``. Default is 'simplerepr'. Valid values are:
:simplerepr: The default. This takes the ``str`` of the object and
then returns the text version of that string.
:empty: Return an empty text string
:passthru: Return the object passed in
:strict: Raise a :exc:`TypeError`
:returns: Typically this returns a text string. If a nonstring object is
passed in this may be a different type depending on the strategy
specified by nonstring. This will never return a byte string.
From Ansible-2.3 onwards, the default is `surrogate_then_replace`.
.. version_changed:: 2.3
Added the surrogate_then_replace error handler and made it the default error handler.
"""
if isinstance(obj, text_type):
return obj
if errors in _COMPOSED_ERROR_HANDLERS:
if HAS_SURROGATEESCAPE:
errors = 'surrogateescape'
elif errors == 'surrogate_or_strict':
errors = 'strict'
else:
errors = 'replace'
if isinstance(obj, binary_type):
# Note: We don't need special handling for surrogate_then_replace
# because all bytes will either be made into surrogates or are valid
# to decode.
return obj.decode(encoding, errors)
# Note: We do these last even though we have to call to_text again on the
# value because we're optimizing the common case
if nonstring == 'simplerepr':
try:
value = str(obj)
except UnicodeError:
try:
value = repr(obj)
except UnicodeError:
# Giving up
return u''
elif nonstring == 'passthru':
return obj
elif nonstring == 'empty':
return u''
elif nonstring == 'strict':
raise TypeError('obj must be a string type')
else:
raise TypeError('Invalid value %s for to_text\'s nonstring parameter' % nonstring)
return to_text(value, encoding, errors)
#: :py:func:`to_native`
#: Transform a variable into the native str type for the python version
#:
#: On Python2, this is an alias for
#: :func:`~ansible.module_utils.to_bytes`. On Python3 it is an alias for
#: :func:`~ansible.module_utils.to_text`. It makes it easier to
#: transform a variable into the native str type for the python version
#: the code is running on. Use this when constructing the message to
#: send to exceptions or when dealing with an API that needs to take
#: a native string. Example::
#:
#: try:
#: 1//0
#: except ZeroDivisionError as e:
#: raise MyException('Encountered and error: %s' % to_native(e))
if PY3:
to_native = to_text
else:
to_native = to_bytes
|
gpl-3.0
|
[
3,
961,
1233,
365,
1777,
402,
2622,
12,
1325,
365,
376,
12717,
3931,
14,
199,
3,
961,
6770,
570,
17440,
12,
436,
642,
570,
17440,
1454,
12,
365,
6289,
18233,
14,
199,
3,
18167,
1265,
2218,
1808,
642,
17440,
12,
1314,
365,
12169,
18774,
701,
2622,
199,
3,
5139,
13511,
370,
314,
4132,
402,
314,
859,
12,
436,
1443,
5090,
3932,
5705,
4190,
199,
3,
370,
314,
4890,
1736,
14,
199,
3,
199,
3,
1898,
334,
67,
395,
4005,
609,
2308,
1804,
300,
4188,
73,
665,
65,
14,
4087,
836,
32,
6799,
14,
957,
6244,
7800,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
420,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
420,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
420,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
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,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
199,
3,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
199,
624,
199,
703,
7987,
447,
961,
859,
63,
1974,
365,
5544,
5007,
4514,
14,
272,
2136,
2934,
370,
9352,
642,
1233,
367,
410,
3616,
436,
3261,
308,
4993,
3616,
2544,
272,
10663,
8552,
7163,
12072,
397,
14,
221,
710,
3261,
1443,
1570,
3382,
272,
19015,
14,
221,
4226,
440,
675,
642,
7444,
1265,
787,
911,
316,
370,
1844,
2195,
859,
1233,
14,
199,
624,
199,
646,
6010,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
7843,
19,
12,
1318,
63,
466,
12,
3366,
63,
466,
421,
199,
893,
26,
272,
6010,
14,
3892,
63,
705,
360,
16380,
3765,
358,
272,
7509,
63,
51,
1230,
1092,
26624,
28879,
275,
715,
199,
2590,
19021,
26,
272,
7509,
63,
51,
1230,
1092,
26624,
28879,
275,
756,
421,
199,
63,
11265,
3064,
36,
63,
3170,
63,
10854,
28778,
275,
9522,
1332,
403,
12,
283,
16380,
63,
269,
63,
3765,
297,
4228,
283,
16380,
63,
269,
63,
4768,
297,
4228,
283,
16380,
63,
12726,
63,
1814,
1333,
421,
199,
318,
370,
63,
2394,
8,
1113,
12,
2644,
534,
1624,
13,
24,
297,
2552,
29,
403,
12,
2222,
875,
534,
4129,
2722,
735,
272,
408,
5483,
3238,
626,
282,
1059,
365,
282,
3696,
1059,
339,
520,
1273,
1559,
26,
1626,
909,
370,
1852,
3238,
365,
282,
3696,
1059,
14,
221,
1010,
4750,
5560,
642,
267,
911,
506,
1902,
282,
1318,
1059,
503,
282,
3696,
1059,
14,
221,
9738,
12,
543,
267,
1124,
2865,
875,
534,
4129,
2722,
31638,
642,
883,
506,
1202,
465,
282,
5190,
13,
4624,
267,
1015,
402,
1124,
495,
8,
1113,
20642,
272,
520,
12745,
2644,
26,
710,
2644,
370,
675,
370,
5793,
687,
282,
1318,
1059,
370,
267,
282,
3696,
1059,
14,
221,
7827,
370,
1808,
283,
1624,
13,
24,
1370,
272,
520,
12745,
2552,
26,
710,
1125,
3016,
370,
675,
340,
314,
1318,
1059,
365,
440,
267,
655,
7889,
461,
1808,
314,
2013,
2644,
14,
221,
6184,
1686,
658,
8933,
1125,
267,
3016,
665,
2859,
921,
4757,
14,
1548,
14,
1308,
15,
18,
15,
4342,
15,
8933,
14,
1360,
3,
9276,
13,
1095,
13,
2888,
18740,
267,
1443,
506,
2013,
14,
6006,
787,
7795,
4722,
1125,
32647,
267,
22543,
282,
21538,
737,
1720,
316,
13135,
370,
1844,
1233,
14,
221,
710,
1642,
2877,
787,
26,
953,
520,
16380,
63,
269,
63,
4768,
26,
12823,
675,
1124,
16380,
3765,
1040,
340,
652,
365,
282,
1686,
355,
3016,
12,
4257,
652,
911,
675,
1124,
4768,
1040,
288,
520,
16380,
63,
269,
63,
1814,
26,
12823,
675,
1124,
16380,
3765,
1040,
340,
652,
365,
282,
1686,
355,
3016,
12,
4257,
652,
911,
675,
1124,
1814,
4345,
398,
13821,
1124,
16380,
3765,
1040,
1990,
3483,
315,
2018,
19,
642,
9987,
4910,
626,
267,
2018,
19,
911,
675,
1124,
16380,
3765,
1040,
436,
2018,
18,
911,
675,
314,
9567,
267,
1125,
3016,
14,
3390,
626,
314,
1233,
5920,
367,
1124,
16380,
3765,
1040,
1380,
314,
267,
859,
365,
8439,
14,
221,
982,
1265,
1172,
282,
1771,
719,
402,
1124,
16380,
3765,
1040,
367,
267,
2018,
18,
12,
506,
3238,
370,
2274,
314,
1125,
3016,
6791,
370,
16306,
642,
267,
859,
14,
398,
710,
2061,
1125,
3016,
365,
26,
953,
520,
16380,
63,
12726,
63,
1814,
26,
12823,
675,
1124,
16380,
3765,
1040,
340,
652,
365,
282,
1686,
355,
3016,
14,
221,
982,
2644,
543,
1124,
16380,
3765,
1040,
3955,
5190,
12,
355,
6296,
19029,
2335,
787,
1642,
8717,
543,
282,
8343,
4110,
355,
436,
2066,
314,
1059,
365,
5737,
1808,
1124,
1814,
1040,
334,
6777,
19058,
355,
314,
4618,
402,
314,
2222,
287,
7889,
461,
2783,
680,
221,
982,
1124,
16380,
3765,
1040,
365,
355,
440,
3451,
652,
911,
9329,
675,
1124,
1814,
4345,
221,
334,
20201,
315,
2622,
499,
14,
19,
9,
355,
961,
10054,
365,
19829,
370,
7078,
5190,
1380,
652,
12454,
355,
370,
3752,
282,
1059,
14,
398,
710,
849,
5133,
2622,
13,
18,
14,
18,
1990,
1124,
16380,
63,
269,
63,
1814,
1040,
267,
11606,
2622,
13,
18,
14,
19
] |
[
961,
1233,
365,
1777,
402,
2622,
12,
1325,
365,
376,
12717,
3931,
14,
199,
3,
961,
6770,
570,
17440,
12,
436,
642,
570,
17440,
1454,
12,
365,
6289,
18233,
14,
199,
3,
18167,
1265,
2218,
1808,
642,
17440,
12,
1314,
365,
12169,
18774,
701,
2622,
199,
3,
5139,
13511,
370,
314,
4132,
402,
314,
859,
12,
436,
1443,
5090,
3932,
5705,
4190,
199,
3,
370,
314,
4890,
1736,
14,
199,
3,
199,
3,
1898,
334,
67,
395,
4005,
609,
2308,
1804,
300,
4188,
73,
665,
65,
14,
4087,
836,
32,
6799,
14,
957,
6244,
7800,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
420,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
420,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
420,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
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,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
199,
3,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
199,
624,
199,
703,
7987,
447,
961,
859,
63,
1974,
365,
5544,
5007,
4514,
14,
272,
2136,
2934,
370,
9352,
642,
1233,
367,
410,
3616,
436,
3261,
308,
4993,
3616,
2544,
272,
10663,
8552,
7163,
12072,
397,
14,
221,
710,
3261,
1443,
1570,
3382,
272,
19015,
14,
221,
4226,
440,
675,
642,
7444,
1265,
787,
911,
316,
370,
1844,
2195,
859,
1233,
14,
199,
624,
199,
646,
6010,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
7843,
19,
12,
1318,
63,
466,
12,
3366,
63,
466,
421,
199,
893,
26,
272,
6010,
14,
3892,
63,
705,
360,
16380,
3765,
358,
272,
7509,
63,
51,
1230,
1092,
26624,
28879,
275,
715,
199,
2590,
19021,
26,
272,
7509,
63,
51,
1230,
1092,
26624,
28879,
275,
756,
421,
199,
63,
11265,
3064,
36,
63,
3170,
63,
10854,
28778,
275,
9522,
1332,
403,
12,
283,
16380,
63,
269,
63,
3765,
297,
4228,
283,
16380,
63,
269,
63,
4768,
297,
4228,
283,
16380,
63,
12726,
63,
1814,
1333,
421,
199,
318,
370,
63,
2394,
8,
1113,
12,
2644,
534,
1624,
13,
24,
297,
2552,
29,
403,
12,
2222,
875,
534,
4129,
2722,
735,
272,
408,
5483,
3238,
626,
282,
1059,
365,
282,
3696,
1059,
339,
520,
1273,
1559,
26,
1626,
909,
370,
1852,
3238,
365,
282,
3696,
1059,
14,
221,
1010,
4750,
5560,
642,
267,
911,
506,
1902,
282,
1318,
1059,
503,
282,
3696,
1059,
14,
221,
9738,
12,
543,
267,
1124,
2865,
875,
534,
4129,
2722,
31638,
642,
883,
506,
1202,
465,
282,
5190,
13,
4624,
267,
1015,
402,
1124,
495,
8,
1113,
20642,
272,
520,
12745,
2644,
26,
710,
2644,
370,
675,
370,
5793,
687,
282,
1318,
1059,
370,
267,
282,
3696,
1059,
14,
221,
7827,
370,
1808,
283,
1624,
13,
24,
1370,
272,
520,
12745,
2552,
26,
710,
1125,
3016,
370,
675,
340,
314,
1318,
1059,
365,
440,
267,
655,
7889,
461,
1808,
314,
2013,
2644,
14,
221,
6184,
1686,
658,
8933,
1125,
267,
3016,
665,
2859,
921,
4757,
14,
1548,
14,
1308,
15,
18,
15,
4342,
15,
8933,
14,
1360,
3,
9276,
13,
1095,
13,
2888,
18740,
267,
1443,
506,
2013,
14,
6006,
787,
7795,
4722,
1125,
32647,
267,
22543,
282,
21538,
737,
1720,
316,
13135,
370,
1844,
1233,
14,
221,
710,
1642,
2877,
787,
26,
953,
520,
16380,
63,
269,
63,
4768,
26,
12823,
675,
1124,
16380,
3765,
1040,
340,
652,
365,
282,
1686,
355,
3016,
12,
4257,
652,
911,
675,
1124,
4768,
1040,
288,
520,
16380,
63,
269,
63,
1814,
26,
12823,
675,
1124,
16380,
3765,
1040,
340,
652,
365,
282,
1686,
355,
3016,
12,
4257,
652,
911,
675,
1124,
1814,
4345,
398,
13821,
1124,
16380,
3765,
1040,
1990,
3483,
315,
2018,
19,
642,
9987,
4910,
626,
267,
2018,
19,
911,
675,
1124,
16380,
3765,
1040,
436,
2018,
18,
911,
675,
314,
9567,
267,
1125,
3016,
14,
3390,
626,
314,
1233,
5920,
367,
1124,
16380,
3765,
1040,
1380,
314,
267,
859,
365,
8439,
14,
221,
982,
1265,
1172,
282,
1771,
719,
402,
1124,
16380,
3765,
1040,
367,
267,
2018,
18,
12,
506,
3238,
370,
2274,
314,
1125,
3016,
6791,
370,
16306,
642,
267,
859,
14,
398,
710,
2061,
1125,
3016,
365,
26,
953,
520,
16380,
63,
12726,
63,
1814,
26,
12823,
675,
1124,
16380,
3765,
1040,
340,
652,
365,
282,
1686,
355,
3016,
14,
221,
982,
2644,
543,
1124,
16380,
3765,
1040,
3955,
5190,
12,
355,
6296,
19029,
2335,
787,
1642,
8717,
543,
282,
8343,
4110,
355,
436,
2066,
314,
1059,
365,
5737,
1808,
1124,
1814,
1040,
334,
6777,
19058,
355,
314,
4618,
402,
314,
2222,
287,
7889,
461,
2783,
680,
221,
982,
1124,
16380,
3765,
1040,
365,
355,
440,
3451,
652,
911,
9329,
675,
1124,
1814,
4345,
221,
334,
20201,
315,
2622,
499,
14,
19,
9,
355,
961,
10054,
365,
19829,
370,
7078,
5190,
1380,
652,
12454,
355,
370,
3752,
282,
1059,
14,
398,
710,
849,
5133,
2622,
13,
18,
14,
18,
1990,
1124,
16380,
63,
269,
63,
1814,
1040,
267,
11606,
2622,
13,
18,
14,
19,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jrversteegh/softsailor
|
deps/scipy-0.10.0b2/scipy/fftpack/tests/test_basic.py
|
5
|
29597
|
#!/usr/bin/env python
# Created by Pearu Peterson, September 2002
""" Test functions for fftpack.basic module
"""
__usage__ = """
Build fftpack:
python setup_fftpack.py build
Run tests if scipy is installed:
python -c 'import scipy;scipy.fftpack.test()'
Run tests if fftpack is not installed:
python tests/test_basic.py
"""
from numpy.testing import assert_, assert_equal, assert_array_almost_equal, \
assert_array_almost_equal_nulp, assert_raises, run_module_suite, \
TestCase, dec
from scipy.fftpack import ifft,fft,fftn,ifftn,rfft,irfft, fft2
from scipy.fftpack import _fftpack as fftpack
from numpy import arange, add, array, asarray, zeros, dot, exp, pi,\
swapaxes, double, cdouble
import numpy as np
import numpy.fft
# "large" composite numbers supported by FFTPACK
LARGE_COMPOSITE_SIZES = [
2**13,
2**5 * 3**5,
2**3 * 3**3 * 5**2,
]
SMALL_COMPOSITE_SIZES = [
2,
2*3*5,
2*2*3*3,
]
# prime
LARGE_PRIME_SIZES = [
2011
]
SMALL_PRIME_SIZES = [
29
]
from numpy.random import rand
def random(size):
return rand(*size)
def get_mat(n):
data = arange(n)
data = add.outer(data,data)
return data
def direct_dft(x):
x = asarray(x)
n = len(x)
y = zeros(n,dtype=cdouble)
w = -arange(n)*(2j*pi/n)
for i in range(n):
y[i] = dot(exp(i*w),x)
return y
def direct_idft(x):
x = asarray(x)
n = len(x)
y = zeros(n,dtype=cdouble)
w = arange(n)*(2j*pi/n)
for i in range(n):
y[i] = dot(exp(i*w),x)/n
return y
def direct_dftn(x):
x = asarray(x)
for axis in range(len(x.shape)):
x = fft(x,axis=axis)
return x
def direct_idftn(x):
x = asarray(x)
for axis in range(len(x.shape)):
x = ifft(x,axis=axis)
return x
def direct_rdft(x):
x = asarray(x)
n = len(x)
w = -arange(n)*(2j*pi/n)
r = zeros(n,dtype=double)
for i in range(int(n/2+1)):
y = dot(exp(i*w),x)
if i:
r[2*i-1] = y.real
if 2*i<n:
r[2*i] = y.imag
else:
r[0] = y.real
return r
def direct_irdft(x):
x = asarray(x)
n = len(x)
x1 = zeros(n,dtype=cdouble)
for i in range(int(n/2+1)):
if i:
if 2*i<n:
x1[i] = x[2*i-1] + 1j* x[2*i]
x1[n-i] = x[2*i-1] - 1j* x[2*i]
else:
x1[i] = x[2*i-1]
else:
x1[0] = x[0]
return direct_idft(x1).real
class _TestFFTBase(TestCase):
def setUp(self):
self.cdt = None
self.rdt = None
np.random.seed(1234)
def test_definition(self):
x = np.array([1,2,3,4+1j,1,2,3,4+2j], dtype = self.cdt)
y = fft(x)
self.assertTrue(y.dtype == self.cdt,
"Output dtype is %s, expected %s" % (y.dtype, self.cdt))
y1 = direct_dft(x)
assert_array_almost_equal(y,y1)
x = np.array([1,2,3,4+0j,5], dtype = self.cdt)
assert_array_almost_equal(fft(x),direct_dft(x))
def test_n_argument_real(self):
x1 = np.array([1,2,3,4], dtype=self.rdt)
x2 = np.array([1,2,3,4], dtype=self.rdt)
y = fft([x1,x2],n=4)
self.assertTrue(y.dtype == self.cdt,
"Output dtype is %s, expected %s" % (y.dtype, self.cdt))
assert_equal(y.shape,(2,4))
assert_array_almost_equal(y[0],direct_dft(x1))
assert_array_almost_equal(y[1],direct_dft(x2))
def _test_n_argument_complex(self):
x1 = np.array([1,2,3,4+1j], dtype=self.cdt)
x2 = np.array([1,2,3,4+1j], dtype=self.cdt)
y = fft([x1,x2],n=4)
self.assertTrue(y.dtype == self.cdt,
"Output dtype is %s, expected %s" % (y.dtype, self.cdt))
assert_equal(y.shape,(2,4))
assert_array_almost_equal(y[0],direct_dft(x1))
assert_array_almost_equal(y[1],direct_dft(x2))
def test_djbfft(self):
for i in range(2,14):
n = 2**i
x = range(n)
y = fftpack.zfft(x)
y2 = numpy.fft.fft(x)
assert_array_almost_equal(y,y2)
y = fftpack.zrfft(x)
assert_array_almost_equal(y,y2)
class TestDoubleFFT(_TestFFTBase):
def setUp(self):
self.cdt = np.cdouble
self.rdt = np.double
class TestSingleFFT(_TestFFTBase):
def setUp(self):
self.cdt = np.complex64
self.rdt = np.float32
@dec.knownfailureif(True, "single-precision FFT implementation is partially disabled, until accuracy issues with large prime powers are resolved")
def test_notice(self):
pass
class _TestIFFTBase(TestCase):
def setUp(self):
np.random.seed(1234)
def test_definition(self):
x = np.array([1,2,3,4+1j,1,2,3,4+2j], self.cdt)
y = ifft(x)
y1 = direct_idft(x)
self.assertTrue(y.dtype == self.cdt,
"Output dtype is %s, expected %s" % (y.dtype, self.cdt))
assert_array_almost_equal(y,y1)
x = np.array([1,2,3,4+0j,5], self.cdt)
assert_array_almost_equal(ifft(x),direct_idft(x))
def test_definition_real(self):
x = np.array([1,2,3,4,1,2,3,4], self.rdt)
y = ifft(x)
self.assertTrue(y.dtype == self.cdt,
"Output dtype is %s, expected %s" % (y.dtype, self.cdt))
y1 = direct_idft(x)
assert_array_almost_equal(y,y1)
x = np.array([1,2,3,4,5], dtype=self.rdt)
self.assertTrue(y.dtype == self.cdt,
"Output dtype is %s, expected %s" % (y.dtype, self.cdt))
assert_array_almost_equal(ifft(x),direct_idft(x))
def test_djbfft(self):
for i in range(2,14):
n = 2**i
x = range(n)
y = fftpack.zfft(x,direction=-1)
y2 = numpy.fft.ifft(x)
assert_array_almost_equal(y,y2)
y = fftpack.zrfft(x,direction=-1)
assert_array_almost_equal(y,y2)
def test_random_complex(self):
for size in [1,51,111,100,200,64,128,256,1024]:
x = random([size]).astype(self.cdt)
x = random([size]).astype(self.cdt) +1j*x
y1 = ifft(fft(x))
y2 = fft(ifft(x))
self.assertTrue(y1.dtype == self.cdt,
"Output dtype is %s, expected %s" % (y1.dtype, self.cdt))
self.assertTrue(y2.dtype == self.cdt,
"Output dtype is %s, expected %s" % (y2.dtype, self.cdt))
assert_array_almost_equal (y1, x)
assert_array_almost_equal (y2, x)
def test_random_real(self):
for size in [1,51,111,100,200,64,128,256,1024]:
x = random([size]).astype(self.rdt)
y1 = ifft(fft(x))
y2 = fft(ifft(x))
self.assertTrue(y1.dtype == self.cdt,
"Output dtype is %s, expected %s" % (y1.dtype, self.cdt))
self.assertTrue(y2.dtype == self.cdt,
"Output dtype is %s, expected %s" % (y2.dtype, self.cdt))
assert_array_almost_equal (y1, x)
assert_array_almost_equal (y2, x)
def test_size_accuracy(self):
# Sanity check for the accuracy for prime and non-prime sized inputs
if self.rdt == np.float32:
rtol = 1e-5
elif self.rdt == np.float64:
rtol = 1e-10
for size in LARGE_COMPOSITE_SIZES + LARGE_PRIME_SIZES:
np.random.seed(1234)
x = np.random.rand(size).astype(self.rdt)
y = ifft(fft(x))
self.failUnless(np.linalg.norm(x - y) < rtol*np.linalg.norm(x),
(size, self.rdt))
y = fft(ifft(x))
self.failUnless(np.linalg.norm(x - y) < rtol*np.linalg.norm(x),
(size, self.rdt))
x = (x + 1j*np.random.rand(size)).astype(self.cdt)
y = ifft(fft(x))
self.failUnless(np.linalg.norm(x - y) < rtol*np.linalg.norm(x),
(size, self.rdt))
y = fft(ifft(x))
self.failUnless(np.linalg.norm(x - y) < rtol*np.linalg.norm(x),
(size, self.rdt))
class TestDoubleIFFT(_TestIFFTBase):
def setUp(self):
self.cdt = np.cdouble
self.rdt = np.double
class TestSingleIFFT(_TestIFFTBase):
def setUp(self):
self.cdt = np.complex64
self.rdt = np.float32
class _TestRFFTBase(TestCase):
def setUp(self):
np.random.seed(1234)
def test_definition(self):
for t in [[1, 2, 3, 4, 1, 2, 3, 4], [1, 2, 3, 4, 1, 2, 3, 4, 5]]:
x = np.array(t, dtype=self.rdt)
y = rfft(x)
y1 = direct_rdft(x)
assert_array_almost_equal(y,y1)
self.assertTrue(y.dtype == self.rdt,
"Output dtype is %s, expected %s" % (y.dtype, self.rdt))
def test_djbfft(self):
from numpy.fft import fft as numpy_fft
for i in range(2,14):
n = 2**i
x = range(n)
y2 = numpy_fft(x)
y1 = zeros((n,),dtype=double)
y1[0] = y2[0].real
y1[-1] = y2[n/2].real
for k in range(1, int(n/2)):
y1[2*k-1] = y2[k].real
y1[2*k] = y2[k].imag
y = fftpack.drfft(x)
assert_array_almost_equal(y,y1)
class TestRFFTDouble(_TestRFFTBase):
def setUp(self):
self.cdt = np.cdouble
self.rdt = np.double
class TestRFFTSingle(_TestRFFTBase):
def setUp(self):
self.cdt = np.complex64
self.rdt = np.float32
class _TestIRFFTBase(TestCase):
def setUp(self):
np.random.seed(1234)
def test_definition(self):
x1 = [1,2,3,4,1,2,3,4]
x1_1 = [1,2+3j,4+1j,2+3j,4,2-3j,4-1j,2-3j]
x2= [1,2,3,4,1,2,3,4,5]
x2_1 = [1,2+3j,4+1j,2+3j,4+5j,4-5j,2-3j,4-1j,2-3j]
def _test(x, xr):
y = irfft(np.array(x, dtype=self.rdt))
y1 = direct_irdft(x)
self.assertTrue(y.dtype == self.rdt,
"Output dtype is %s, expected %s" % (y.dtype, self.rdt))
assert_array_almost_equal(y,y1, decimal=self.ndec)
assert_array_almost_equal(y,ifft(xr), decimal=self.ndec)
_test(x1, x1_1)
_test(x2, x2_1)
def test_djbfft(self):
from numpy.fft import ifft as numpy_ifft
for i in range(2,14):
n = 2**i
x = range(n)
x1 = zeros((n,),dtype=cdouble)
x1[0] = x[0]
for k in range(1, int(n/2)):
x1[k] = x[2*k-1]+1j*x[2*k]
x1[n-k] = x[2*k-1]-1j*x[2*k]
x1[n/2] = x[-1]
y1 = numpy_ifft(x1)
y = fftpack.drfft(x,direction=-1)
assert_array_almost_equal(y,y1)
def test_random_real(self):
for size in [1,51,111,100,200,64,128,256,1024]:
x = random([size]).astype(self.rdt)
y1 = irfft(rfft(x))
y2 = rfft(irfft(x))
self.assertTrue(y1.dtype == self.rdt,
"Output dtype is %s, expected %s" % (y1.dtype, self.rdt))
self.assertTrue(y2.dtype == self.rdt,
"Output dtype is %s, expected %s" % (y2.dtype, self.rdt))
assert_array_almost_equal (y1, x, decimal=self.ndec,
err_msg="size=%d" % size)
assert_array_almost_equal (y2, x, decimal=self.ndec,
err_msg="size=%d" % size)
def test_size_accuracy(self):
# Sanity check for the accuracy for prime and non-prime sized inputs
if self.rdt == np.float32:
rtol = 1e-5
elif self.rdt == np.float64:
rtol = 1e-10
for size in LARGE_COMPOSITE_SIZES + LARGE_PRIME_SIZES:
np.random.seed(1234)
x = np.random.rand(size).astype(self.rdt)
y = irfft(rfft(x))
self.failUnless(np.linalg.norm(x - y) < rtol*np.linalg.norm(x),
(size, self.rdt))
y = rfft(irfft(x))
self.failUnless(np.linalg.norm(x - y) < rtol*np.linalg.norm(x),
(size, self.rdt))
# self.ndec is bogus; we should have a assert_array_approx_equal for number of
# significant digits
class TestIRFFTDouble(_TestIRFFTBase):
def setUp(self):
self.cdt = np.cdouble
self.rdt = np.double
self.ndec = 14
class TestIRFFTSingle(_TestIRFFTBase):
def setUp(self):
self.cdt = np.complex64
self.rdt = np.float32
self.ndec = 5
class Testfft2(TestCase):
def setUp(self):
np.random.seed(1234)
def test_regression_244(self):
"""fft returns wrong result with axes parameter."""
# fftn (and hence fft2) used to break when both axes and shape were
# used
x = numpy.ones((4,4,2))
y = fft2(x, shape=(8,8), axes=(-3,-2))
y_r = numpy.fft.fftn(x, s=(8, 8), axes=(-3, -2))
assert_array_almost_equal(y, y_r)
class TestFftnSingle(TestCase):
def setUp(self):
np.random.seed(1234)
def test_definition(self):
x = [[1,2,3],[4,5,6],[7,8,9]]
y = fftn(np.array(x, np.float32))
if not y.dtype == np.complex64:
raise ValueError("double precision output with single precision")
y_r = np.array(fftn(x), np.complex64)
assert_array_almost_equal_nulp(y, y_r)
def test_size_accuracy(self):
for size in SMALL_COMPOSITE_SIZES + SMALL_PRIME_SIZES:
np.random.seed(1234)
x = np.random.rand(size, size) + 1j*np.random.rand(size, size)
y1 = fftn(x.real.astype(np.float32))
y2 = fftn(x.real.astype(np.float64)).astype(np.complex64)
self.failUnless(y1.dtype == np.complex64)
assert_array_almost_equal_nulp(y1, y2, 2000)
for size in LARGE_COMPOSITE_SIZES + LARGE_PRIME_SIZES:
np.random.seed(1234)
x = np.random.rand(size, 3) + 1j*np.random.rand(size, 3)
y1 = fftn(x.real.astype(np.float32))
y2 = fftn(x.real.astype(np.float64)).astype(np.complex64)
self.failUnless(y1.dtype == np.complex64)
assert_array_almost_equal_nulp(y1, y2, 2000)
class TestFftn(TestCase):
def setUp(self):
np.random.seed(1234)
def test_definition(self):
x = [[1,2,3],[4,5,6],[7,8,9]]
y = fftn(x)
assert_array_almost_equal(y,direct_dftn(x))
x = random((20,26))
assert_array_almost_equal(fftn(x),direct_dftn(x))
x = random((5,4,3,20))
assert_array_almost_equal(fftn(x),direct_dftn(x))
def test_axes_argument(self):
#plane == ji_plane, x== kji_space
plane1 = [[1,2,3],[4,5,6],[7,8,9]]
plane2 = [[10,11,12],[13,14,15],[16,17,18]]
plane3 = [[19,20,21],[22,23,24],[25,26,27]]
ki_plane1 = [[1,2,3],[10,11,12],[19,20,21]]
ki_plane2 = [[4,5,6],[13,14,15],[22,23,24]]
ki_plane3 = [[7,8,9],[16,17,18],[25,26,27]]
jk_plane1 = [[1,10,19],[4,13,22],[7,16,25]]
jk_plane2 = [[2,11,20],[5,14,23],[8,17,26]]
jk_plane3 = [[3,12,21],[6,15,24],[9,18,27]]
kj_plane1 = [[1,4,7],[10,13,16],[19,22,25]]
kj_plane2 = [[2,5,8],[11,14,17],[20,23,26]]
kj_plane3 = [[3,6,9],[12,15,18],[21,24,27]]
ij_plane1 = [[1,4,7],[2,5,8],[3,6,9]]
ij_plane2 = [[10,13,16],[11,14,17],[12,15,18]]
ij_plane3 = [[19,22,25],[20,23,26],[21,24,27]]
ik_plane1 = [[1,10,19],[2,11,20],[3,12,21]]
ik_plane2 = [[4,13,22],[5,14,23],[6,15,24]]
ik_plane3 = [[7,16,25],[8,17,26],[9,18,27]]
ijk_space = [jk_plane1,jk_plane2,jk_plane3]
ikj_space = [kj_plane1,kj_plane2,kj_plane3]
jik_space = [ik_plane1,ik_plane2,ik_plane3]
jki_space = [ki_plane1,ki_plane2,ki_plane3]
kij_space = [ij_plane1,ij_plane2,ij_plane3]
x = array([plane1,plane2,plane3])
assert_array_almost_equal(fftn(x),fftn(x,axes=(-3,-2,-1))) # kji_space
assert_array_almost_equal(fftn(x),fftn(x,axes=(0,1,2)))
y = fftn(x,axes=(2,1,0)) # ijk_space
assert_array_almost_equal(swapaxes(y,-1,-3),fftn(ijk_space))
y = fftn(x,axes=(2,0,1)) # ikj_space
assert_array_almost_equal(swapaxes(swapaxes(y,-1,-3),
-1,-2)
,fftn(ikj_space))
y = fftn(x,axes=(1,2,0)) # jik_space
assert_array_almost_equal(swapaxes(swapaxes(y,-1,-3),
-3,-2)
,fftn(jik_space))
y = fftn(x,axes=(1,0,2)) # jki_space
assert_array_almost_equal(swapaxes(y,-2,-3),fftn(jki_space))
y = fftn(x,axes=(0,2,1)) # kij_space
assert_array_almost_equal(swapaxes(y,-2,-1),
fftn(kij_space))
y = fftn(x,axes=(-2,-1)) # ji_plane
assert_array_almost_equal(fftn(plane1),y[0])
assert_array_almost_equal(fftn(plane2),y[1])
assert_array_almost_equal(fftn(plane3),y[2])
y = fftn(x,axes=(1,2)) # ji_plane
assert_array_almost_equal(fftn(plane1),y[0])
assert_array_almost_equal(fftn(plane2),y[1])
assert_array_almost_equal(fftn(plane3),y[2])
y = fftn(x,axes=(-3,-2)) # kj_plane
assert_array_almost_equal(fftn(x[:,:,0]),y[:,:,0])
assert_array_almost_equal(fftn(x[:,:,1]),y[:,:,1])
assert_array_almost_equal(fftn(x[:,:,2]),y[:,:,2])
y = fftn(x,axes=(-3,-1)) # ki_plane
assert_array_almost_equal(fftn(x[:,0,:]),y[:,0,:])
assert_array_almost_equal(fftn(x[:,1,:]),y[:,1,:])
assert_array_almost_equal(fftn(x[:,2,:]),y[:,2,:])
y = fftn(x,axes=(-1,-2)) # ij_plane
assert_array_almost_equal(fftn(ij_plane1),swapaxes(y[0],-2,-1))
assert_array_almost_equal(fftn(ij_plane2),swapaxes(y[1],-2,-1))
assert_array_almost_equal(fftn(ij_plane3),swapaxes(y[2],-2,-1))
y = fftn(x,axes=(-1,-3)) # ik_plane
assert_array_almost_equal(fftn(ik_plane1),swapaxes(y[:,0,:],-1,-2))
assert_array_almost_equal(fftn(ik_plane2),swapaxes(y[:,1,:],-1,-2))
assert_array_almost_equal(fftn(ik_plane3),swapaxes(y[:,2,:],-1,-2))
y = fftn(x,axes=(-2,-3)) # jk_plane
assert_array_almost_equal(fftn(jk_plane1),swapaxes(y[:,:,0],-1,-2))
assert_array_almost_equal(fftn(jk_plane2),swapaxes(y[:,:,1],-1,-2))
assert_array_almost_equal(fftn(jk_plane3),swapaxes(y[:,:,2],-1,-2))
y = fftn(x,axes=(-1,)) # i_line
for i in range(3):
for j in range(3):
assert_array_almost_equal(fft(x[i,j,:]),y[i,j,:])
y = fftn(x,axes=(-2,)) # j_line
for i in range(3):
for j in range(3):
assert_array_almost_equal(fft(x[i,:,j]),y[i,:,j])
y = fftn(x,axes=(0,)) # k_line
for i in range(3):
for j in range(3):
assert_array_almost_equal(fft(x[:,i,j]),y[:,i,j])
y = fftn(x,axes=()) # point
assert_array_almost_equal(y,x)
def test_shape_argument(self):
small_x = [[1,2,3],[4,5,6]]
large_x1 = [[1,2,3,0],[4,5,6,0],[0,0,0,0],[0,0,0,0]]
y = fftn(small_x,shape=(4,4))
assert_array_almost_equal (y,fftn(large_x1))
y = fftn(small_x,shape=(3,4))
assert_array_almost_equal (y,fftn(large_x1[:-1]))
def test_shape_axes_argument(self):
small_x = [[1,2,3],[4,5,6],[7,8,9]]
large_x1 = array([[1,2,3,0],
[4,5,6,0],
[7,8,9,0],
[0,0,0,0]])
# Disable tests with shape and axes of different lengths
#y = fftn(small_x,shape=(4,4),axes=(-1,))
#for i in range(4):
# assert_array_almost_equal (y[i],fft(large_x1[i]))
#y = fftn(small_x,shape=(4,4),axes=(-2,))
#for i in range(4):
# assert_array_almost_equal (y[:,i],fft(large_x1[:,i]))
y = fftn(small_x,shape=(4,4),axes=(-2,-1))
assert_array_almost_equal (y,fftn(large_x1))
y = fftn(small_x,shape=(4,4),axes=(-1,-2))
assert_array_almost_equal (y,swapaxes(\
fftn(swapaxes(large_x1,-1,-2)),-1,-2))
def test_shape_axes_argument2(self):
# Change shape of the last axis
x = numpy.random.random((10, 5, 3, 7))
y = fftn(x, axes=(-1,), shape=(8,))
assert_array_almost_equal(y, fft(x, axis=-1, n=8))
# Change shape of an arbitrary axis which is not the last one
x = numpy.random.random((10, 5, 3, 7))
y = fftn(x, axes=(-2,), shape=(8,))
assert_array_almost_equal(y, fft(x, axis=-2, n=8))
# Change shape of axes: cf #244, where shape and axes were mixed up
x = numpy.random.random((4,4,2))
y = fftn(x, axes=(-3,-2), shape=(8,8))
assert_array_almost_equal(y, numpy.fft.fftn(x, axes=(-3, -2), s=(8, 8)))
def test_shape_argument_more(self):
"""Test that fftn raises ValueError when s.shape is longer than x.shape"""
x = zeros((4, 4, 2))
assert_raises(ValueError, fftn, x, shape=(8, 8, 2, 1))
class _TestIfftn(TestCase):
dtype = None
cdtype = None
def setUp(self):
np.random.seed(1234)
def test_definition(self):
x = np.array([[1,2,3],[4,5,6],[7,8,9]], dtype=self.dtype)
y = ifftn(x)
assert_(y.dtype == self.cdtype)
assert_array_almost_equal_nulp(y,direct_idftn(x),self.maxnlp)
x = random((20,26))
assert_array_almost_equal_nulp(ifftn(x),direct_idftn(x),self.maxnlp)
x = random((5,4,3,20))
assert_array_almost_equal_nulp(ifftn(x),direct_idftn(x),self.maxnlp)
def test_random_complex(self):
for size in [1,2,51,32,64,92]:
x = random([size,size]) + 1j*random([size,size])
assert_array_almost_equal_nulp(ifftn(fftn(x)),x,self.maxnlp)
assert_array_almost_equal_nulp(fftn(ifftn(x)),x,self.maxnlp)
class TestIfftnDouble(_TestIfftn):
dtype = np.float64
cdtype = np.complex128
maxnlp = 2000
class TestIfftnSingle(_TestIfftn):
dtype = np.float32
cdtype = np.complex64
maxnlp = 3500
class TestLongDoubleFailure(TestCase):
def setUp(self):
np.random.seed(1234)
def test_complex(self):
if np.dtype(np.longcomplex).itemsize == np.dtype(np.complex).itemsize:
# longdouble == double; so fft is supported
return
x = np.random.randn(10).astype(np.longdouble) + \
1j * np.random.randn(10).astype(np.longdouble)
for f in [fft, ifft]:
try:
f(x)
raise AssertionError("Type %r not supported but does not fail" % \
np.longcomplex)
except ValueError:
pass
def test_real(self):
if np.dtype(np.longdouble).itemsize == np.dtype(np.double).itemsize:
# longdouble == double; so fft is supported
return
x = np.random.randn(10).astype(np.longcomplex)
for f in [fft, ifft]:
try:
f(x)
raise AssertionError("Type %r not supported but does not fail" % \
np.longcomplex)
except ValueError:
pass
class FakeArray(object):
def __init__(self, data):
self._data = data
self.__array_interface__ = data.__array_interface__
class FakeArray2(object):
def __init__(self, data):
self._data = data
def __array__(self):
return self._data
class TestOverwrite(object):
"""
Check input overwrite behavior of the FFT functions
"""
real_dtypes = [np.float32, np.float64]
dtypes = real_dtypes + [np.complex64, np.complex128]
def _check(self, x, routine, fftsize, axis, overwrite_x, should_overwrite):
x2 = x.copy()
for fake in [lambda x: x, FakeArray, FakeArray2]:
y = routine(fake(x2), fftsize, axis, overwrite_x=overwrite_x)
sig = "%s(%s%r, %r, axis=%r, overwrite_x=%r)" % (
routine.__name__, x.dtype, x.shape, fftsize, axis, overwrite_x)
if not should_overwrite:
assert_equal(x2, x, err_msg="spurious overwrite in %s" % sig)
else:
if (x2 == x).all():
raise AssertionError("no overwrite in %s" % sig)
def _check_1d(self, routine, dtype, shape, axis, overwritable_dtypes):
np.random.seed(1234)
if np.issubdtype(dtype, np.complexfloating):
data = np.random.randn(*shape) + 1j*np.random.randn(*shape)
else:
data = np.random.randn(*shape)
data = data.astype(dtype)
for fftsize in [8, 16, 32]:
for overwrite_x in [True, False]:
should_overwrite = (overwrite_x
and dtype in overwritable_dtypes
and fftsize <= shape[axis]
and (len(shape) == 1 or
(axis % len(shape) == len(shape)-1
and fftsize == shape[axis])))
self._check(data, routine, fftsize, axis,
overwrite_x=overwrite_x,
should_overwrite=should_overwrite)
def test_fft(self):
overwritable = (np.complex128, np.complex64)
for dtype in self.dtypes:
self._check_1d(fft, dtype, (16,), -1, overwritable)
self._check_1d(fft, dtype, (16, 2), 0, overwritable)
self._check_1d(fft, dtype, (2, 16), 1, overwritable)
def test_ifft(self):
overwritable = (np.complex128, np.complex64)
for dtype in self.dtypes:
self._check_1d(ifft, dtype, (16,), -1, overwritable)
self._check_1d(ifft, dtype, (16, 2), 0, overwritable)
self._check_1d(ifft, dtype, (2, 16), 1, overwritable)
def test_rfft(self):
overwritable = self.real_dtypes
for dtype in self.real_dtypes:
self._check_1d(rfft, dtype, (16,), -1, overwritable)
self._check_1d(rfft, dtype, (16, 2), 0, overwritable)
self._check_1d(rfft, dtype, (2, 16), 1, overwritable)
def test_irfft(self):
overwritable = self.real_dtypes
for dtype in self.real_dtypes:
self._check_1d(irfft, dtype, (16,), -1, overwritable)
self._check_1d(irfft, dtype, (16, 2), 0, overwritable)
self._check_1d(irfft, dtype, (2, 16), 1, overwritable)
def _check_nd_one(self, routine, dtype, shape, axes, overwritable_dtypes):
np.random.seed(1234)
if np.issubdtype(dtype, np.complexfloating):
data = np.random.randn(*shape) + 1j*np.random.randn(*shape)
else:
data = np.random.randn(*shape)
data = data.astype(dtype)
def fftshape_iter(shp):
if len(shp) <= 0:
yield ()
else:
for j in (shp[0]//2, shp[0], shp[0]*2):
for rest in fftshape_iter(shp[1:]):
yield (j,) + rest
if axes is None:
part_shape = shape
else:
part_shape = tuple(np.take(shape, axes))
for overwrite_x in [True, False]:
for fftshape in fftshape_iter(part_shape):
should_overwrite = (overwrite_x
and data.ndim == 1
and np.all([x < y for x, y in zip(fftshape, part_shape)])
and dtype in overwritable_dtypes)
self._check(data, routine, fftshape, axes,
overwrite_x=overwrite_x,
should_overwrite=should_overwrite)
if data.ndim > 1:
# check fortran order: it never overwrites
self._check(data.T, routine, fftshape, axes,
overwrite_x=overwrite_x,
should_overwrite=False)
def _check_nd(self, routine, dtype, overwritable):
self._check_nd_one(routine, dtype, (16,), None, overwritable)
self._check_nd_one(routine, dtype, (16,), (0,), overwritable)
self._check_nd_one(routine, dtype, (16, 2), (0,), overwritable)
self._check_nd_one(routine, dtype, (2, 16), (1,), overwritable)
self._check_nd_one(routine, dtype, (8, 16), None, overwritable)
self._check_nd_one(routine, dtype, (8, 16), (0, 1), overwritable)
self._check_nd_one(routine, dtype, (8, 16, 2), (0, 1), overwritable)
self._check_nd_one(routine, dtype, (8, 16, 2), (1, 2), overwritable)
self._check_nd_one(routine, dtype, (8, 16, 2), (0,), overwritable)
self._check_nd_one(routine, dtype, (8, 16, 2), (1,), overwritable)
self._check_nd_one(routine, dtype, (8, 16, 2), (2,), overwritable)
self._check_nd_one(routine, dtype, (8, 16, 2), None, overwritable)
self._check_nd_one(routine, dtype, (8, 16, 2), (0,1,2), overwritable)
def test_fftn(self):
overwritable = (np.complex128, np.complex64)
for dtype in self.dtypes:
self._check_nd(fftn, dtype, overwritable)
def test_ifftn(self):
overwritable = (np.complex128, np.complex64)
for dtype in self.dtypes:
self._check_nd(ifftn, dtype, overwritable)
if __name__ == "__main__":
run_module_suite()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
18208,
701,
510,
2210,
85,
22912,
834,
12,
428,
1545,
31575,
14790,
199,
624,
1379,
3423,
367,
18160,
1389,
14,
4316,
859,
199,
624,
199,
363,
3807,
363,
275,
408,
199,
3425,
18160,
1389,
26,
523,
2366,
3272,
63,
9996,
1389,
14,
647,
1900,
199,
2540,
2295,
340,
7026,
365,
4903,
26,
523,
2366,
446,
67,
283,
646,
7026,
27,
14248,
14,
9996,
1389,
14,
396,
11716,
199,
2540,
2295,
340,
18160,
1389,
365,
440,
4903,
26,
523,
2366,
2295,
15,
396,
63,
4316,
14,
647,
199,
624,
199,
199,
504,
2680,
14,
4776,
492,
702,
3131,
702,
63,
1452,
12,
702,
63,
1144,
63,
4398,
63,
1452,
12,
971,
267,
702,
63,
1144,
63,
4398,
63,
1452,
63,
78,
15513,
12,
702,
63,
3536,
12,
1255,
63,
578,
63,
5768,
12,
971,
267,
7640,
12,
9700,
199,
504,
7026,
14,
9996,
1389,
492,
340,
856,
12,
9996,
12,
556,
5889,
12,
15126,
5889,
12,
82,
9996,
12,
723,
9996,
12,
18160,
18,
199,
504,
7026,
14,
9996,
1389,
492,
485,
9996,
1389,
465,
18160,
1389,
199,
199,
504,
2680,
492,
20461,
12,
1050,
12,
1625,
12,
24144,
12,
10136,
12,
6308,
12,
1437,
12,
6682,
4202,
1362,
308,
758,
387,
12908,
12,
4270,
12,
286,
3157,
199,
646,
2680,
465,
980,
199,
646,
2680,
14,
9996,
199,
199,
3,
298,
9629,
2,
19306,
5579,
3748,
701,
29484,
6961,
199,
15806,
63,
11265,
1512,
7917,
63,
2684,
58,
654,
275,
359,
272,
499,
538,
969,
12,
272,
499,
538,
21,
627,
650,
538,
21,
12,
272,
499,
538,
19,
627,
650,
538,
19,
627,
959,
538,
18,
12,
199,
61,
199,
28570,
63,
11265,
1512,
7917,
63,
2684,
58,
654,
275,
359,
272,
499,
12,
272,
499,
10,
19,
10,
21,
12,
272,
499,
10,
18,
10,
19,
10,
19,
12,
199,
61,
199,
3,
21619,
199,
15806,
63,
3311,
3465,
63,
2684,
58,
654,
275,
359,
272,
7760,
199,
61,
199,
28570,
63,
3311,
3465,
63,
2684,
58,
654,
275,
359,
272,
7349,
199,
61,
199,
199,
504,
2680,
14,
2355,
492,
10261,
199,
318,
2196,
8,
890,
304,
272,
372,
10261,
2031,
890,
9,
199,
199,
318,
664,
63,
569,
8,
78,
304,
272,
666,
275,
20461,
8,
78,
9,
272,
666,
275,
1050,
14,
7837,
8,
576,
12,
576,
9,
272,
372,
666,
199,
199,
318,
4125,
63,
68,
856,
8,
88,
304,
272,
671,
275,
24144,
8,
88,
9,
272,
302,
275,
822,
8,
88,
9,
272,
612,
275,
10136,
8,
78,
12,
2271,
29,
67,
3157,
9,
272,
336,
275,
446,
5605,
8,
78,
14397,
18,
74,
10,
1038,
15,
78,
9,
272,
367,
284,
315,
1425,
8,
78,
304,
267,
612,
59,
73,
61,
275,
6308,
8,
1474,
8,
73,
10,
87,
395,
88,
9,
272,
372,
612,
199,
199,
318,
4125,
63,
344,
856,
8,
88,
304,
272,
671,
275,
24144,
8,
88,
9,
272,
302,
275,
822,
8,
88,
9,
272,
612,
275,
10136,
8,
78,
12,
2271,
29,
67,
3157,
9,
272,
336,
275,
20461,
8,
78,
14397,
18,
74,
10,
1038,
15,
78,
9,
272,
367,
284,
315,
1425,
8,
78,
304,
267,
612,
59,
73,
61,
275,
6308,
8,
1474,
8,
73,
10,
87,
395,
88,
2447,
78,
272,
372,
612,
199,
199,
318,
4125,
63,
68,
856,
78,
8,
88,
304,
272,
671,
275,
24144,
8,
88,
9,
272,
367,
3114,
315,
1425,
8,
552,
8,
88,
14,
1392,
2298,
267,
671,
275,
18160,
8,
88,
12,
3127,
29,
3127,
9,
272,
372,
671,
199,
199,
318,
4125,
63,
344,
856,
78,
8,
88,
304,
272,
671,
275,
24144,
8,
88,
9,
272,
367,
3114,
315,
1425,
8,
552,
8,
88,
14,
1392,
2298,
267,
671,
275,
340,
856,
8,
88,
12,
3127,
29,
3127,
9,
272,
372,
671,
199,
199,
318,
4125,
63,
6883,
856,
8,
88,
304,
272,
671,
275,
24144,
8,
88,
9,
272,
302,
275,
822,
8,
88,
9,
272,
336,
275,
446,
5605,
8,
78,
14397,
18,
74,
10,
1038,
15,
78,
9,
272,
519,
275,
10136,
8,
78,
12,
2271,
29,
3157,
9,
272,
367,
284,
315,
1425,
8,
442,
8,
78,
15,
18,
11,
17,
2298,
267,
612,
275,
6308,
8,
1474,
8,
73,
10,
87,
395,
88,
9,
267,
340,
284,
26,
288,
519,
59,
18,
10,
73,
13,
17,
61,
275,
612,
14,
3093,
288,
340,
499,
10,
73,
28,
78,
26,
355,
519,
59,
18,
10,
73,
61,
275,
612,
14,
14688,
267,
587,
26,
288,
519,
59,
16,
61,
275,
612,
14,
3093,
272,
372,
519,
199,
199,
318,
4125,
63,
5428,
856,
8,
88,
304,
272,
671,
275,
24144,
8,
88,
9,
272,
302,
275,
822,
8,
88,
9,
272,
671,
17,
275,
10136,
8,
78,
12,
2271,
29,
67,
3157,
9,
272,
367,
284,
315,
1425,
8,
442,
8,
78,
15,
18,
11,
17,
2298,
267,
340,
284,
26,
288,
340,
499,
10,
73,
28,
78,
26,
355,
671,
17,
59,
73,
61,
275,
671,
59,
18,
10,
73,
13,
17,
61,
435,
413,
74,
10,
671,
59,
18,
10,
73,
61,
355,
671,
17,
59,
78,
13,
73,
61,
275,
671,
59,
18,
10,
73,
13,
17,
61,
446,
413,
74,
10,
671,
59,
18,
10,
73,
61,
288,
587,
26,
355,
671,
17,
59,
73,
61,
275,
671,
59,
18,
10,
73,
13,
17,
61,
267,
587,
26,
288,
671,
17,
59,
16,
61,
275,
671,
59,
16,
61,
272,
372,
4125,
63,
344,
856,
8,
88,
17,
680,
3093,
199,
199,
533,
485,
774,
1665,
52,
1563,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
2866,
84,
275,
488,
267,
291,
14,
82,
3583,
275,
488,
267,
980,
14,
2355,
14,
5176,
8,
4321,
9,
339,
347,
511,
63,
7463,
8,
277,
304,
267,
671,
275,
980,
14,
1144,
779,
17,
12,
18,
12,
19,
12,
20,
11,
17,
74,
12,
17,
12,
18,
12,
19,
12,
20,
11,
18,
74,
467,
2152,
275,
291,
14,
2866,
84,
9,
267,
612,
275,
18160,
8,
88,
9,
267,
291,
14,
1815,
8,
89,
14
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
18208,
701,
510,
2210,
85,
22912,
834,
12,
428,
1545,
31575,
14790,
199,
624,
1379,
3423,
367,
18160,
1389,
14,
4316,
859,
199,
624,
199,
363,
3807,
363,
275,
408,
199,
3425,
18160,
1389,
26,
523,
2366,
3272,
63,
9996,
1389,
14,
647,
1900,
199,
2540,
2295,
340,
7026,
365,
4903,
26,
523,
2366,
446,
67,
283,
646,
7026,
27,
14248,
14,
9996,
1389,
14,
396,
11716,
199,
2540,
2295,
340,
18160,
1389,
365,
440,
4903,
26,
523,
2366,
2295,
15,
396,
63,
4316,
14,
647,
199,
624,
199,
199,
504,
2680,
14,
4776,
492,
702,
3131,
702,
63,
1452,
12,
702,
63,
1144,
63,
4398,
63,
1452,
12,
971,
267,
702,
63,
1144,
63,
4398,
63,
1452,
63,
78,
15513,
12,
702,
63,
3536,
12,
1255,
63,
578,
63,
5768,
12,
971,
267,
7640,
12,
9700,
199,
504,
7026,
14,
9996,
1389,
492,
340,
856,
12,
9996,
12,
556,
5889,
12,
15126,
5889,
12,
82,
9996,
12,
723,
9996,
12,
18160,
18,
199,
504,
7026,
14,
9996,
1389,
492,
485,
9996,
1389,
465,
18160,
1389,
199,
199,
504,
2680,
492,
20461,
12,
1050,
12,
1625,
12,
24144,
12,
10136,
12,
6308,
12,
1437,
12,
6682,
4202,
1362,
308,
758,
387,
12908,
12,
4270,
12,
286,
3157,
199,
646,
2680,
465,
980,
199,
646,
2680,
14,
9996,
199,
199,
3,
298,
9629,
2,
19306,
5579,
3748,
701,
29484,
6961,
199,
15806,
63,
11265,
1512,
7917,
63,
2684,
58,
654,
275,
359,
272,
499,
538,
969,
12,
272,
499,
538,
21,
627,
650,
538,
21,
12,
272,
499,
538,
19,
627,
650,
538,
19,
627,
959,
538,
18,
12,
199,
61,
199,
28570,
63,
11265,
1512,
7917,
63,
2684,
58,
654,
275,
359,
272,
499,
12,
272,
499,
10,
19,
10,
21,
12,
272,
499,
10,
18,
10,
19,
10,
19,
12,
199,
61,
199,
3,
21619,
199,
15806,
63,
3311,
3465,
63,
2684,
58,
654,
275,
359,
272,
7760,
199,
61,
199,
28570,
63,
3311,
3465,
63,
2684,
58,
654,
275,
359,
272,
7349,
199,
61,
199,
199,
504,
2680,
14,
2355,
492,
10261,
199,
318,
2196,
8,
890,
304,
272,
372,
10261,
2031,
890,
9,
199,
199,
318,
664,
63,
569,
8,
78,
304,
272,
666,
275,
20461,
8,
78,
9,
272,
666,
275,
1050,
14,
7837,
8,
576,
12,
576,
9,
272,
372,
666,
199,
199,
318,
4125,
63,
68,
856,
8,
88,
304,
272,
671,
275,
24144,
8,
88,
9,
272,
302,
275,
822,
8,
88,
9,
272,
612,
275,
10136,
8,
78,
12,
2271,
29,
67,
3157,
9,
272,
336,
275,
446,
5605,
8,
78,
14397,
18,
74,
10,
1038,
15,
78,
9,
272,
367,
284,
315,
1425,
8,
78,
304,
267,
612,
59,
73,
61,
275,
6308,
8,
1474,
8,
73,
10,
87,
395,
88,
9,
272,
372,
612,
199,
199,
318,
4125,
63,
344,
856,
8,
88,
304,
272,
671,
275,
24144,
8,
88,
9,
272,
302,
275,
822,
8,
88,
9,
272,
612,
275,
10136,
8,
78,
12,
2271,
29,
67,
3157,
9,
272,
336,
275,
20461,
8,
78,
14397,
18,
74,
10,
1038,
15,
78,
9,
272,
367,
284,
315,
1425,
8,
78,
304,
267,
612,
59,
73,
61,
275,
6308,
8,
1474,
8,
73,
10,
87,
395,
88,
2447,
78,
272,
372,
612,
199,
199,
318,
4125,
63,
68,
856,
78,
8,
88,
304,
272,
671,
275,
24144,
8,
88,
9,
272,
367,
3114,
315,
1425,
8,
552,
8,
88,
14,
1392,
2298,
267,
671,
275,
18160,
8,
88,
12,
3127,
29,
3127,
9,
272,
372,
671,
199,
199,
318,
4125,
63,
344,
856,
78,
8,
88,
304,
272,
671,
275,
24144,
8,
88,
9,
272,
367,
3114,
315,
1425,
8,
552,
8,
88,
14,
1392,
2298,
267,
671,
275,
340,
856,
8,
88,
12,
3127,
29,
3127,
9,
272,
372,
671,
199,
199,
318,
4125,
63,
6883,
856,
8,
88,
304,
272,
671,
275,
24144,
8,
88,
9,
272,
302,
275,
822,
8,
88,
9,
272,
336,
275,
446,
5605,
8,
78,
14397,
18,
74,
10,
1038,
15,
78,
9,
272,
519,
275,
10136,
8,
78,
12,
2271,
29,
3157,
9,
272,
367,
284,
315,
1425,
8,
442,
8,
78,
15,
18,
11,
17,
2298,
267,
612,
275,
6308,
8,
1474,
8,
73,
10,
87,
395,
88,
9,
267,
340,
284,
26,
288,
519,
59,
18,
10,
73,
13,
17,
61,
275,
612,
14,
3093,
288,
340,
499,
10,
73,
28,
78,
26,
355,
519,
59,
18,
10,
73,
61,
275,
612,
14,
14688,
267,
587,
26,
288,
519,
59,
16,
61,
275,
612,
14,
3093,
272,
372,
519,
199,
199,
318,
4125,
63,
5428,
856,
8,
88,
304,
272,
671,
275,
24144,
8,
88,
9,
272,
302,
275,
822,
8,
88,
9,
272,
671,
17,
275,
10136,
8,
78,
12,
2271,
29,
67,
3157,
9,
272,
367,
284,
315,
1425,
8,
442,
8,
78,
15,
18,
11,
17,
2298,
267,
340,
284,
26,
288,
340,
499,
10,
73,
28,
78,
26,
355,
671,
17,
59,
73,
61,
275,
671,
59,
18,
10,
73,
13,
17,
61,
435,
413,
74,
10,
671,
59,
18,
10,
73,
61,
355,
671,
17,
59,
78,
13,
73,
61,
275,
671,
59,
18,
10,
73,
13,
17,
61,
446,
413,
74,
10,
671,
59,
18,
10,
73,
61,
288,
587,
26,
355,
671,
17,
59,
73,
61,
275,
671,
59,
18,
10,
73,
13,
17,
61,
267,
587,
26,
288,
671,
17,
59,
16,
61,
275,
671,
59,
16,
61,
272,
372,
4125,
63,
344,
856,
8,
88,
17,
680,
3093,
199,
199,
533,
485,
774,
1665,
52,
1563,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
2866,
84,
275,
488,
267,
291,
14,
82,
3583,
275,
488,
267,
980,
14,
2355,
14,
5176,
8,
4321,
9,
339,
347,
511,
63,
7463,
8,
277,
304,
267,
671,
275,
980,
14,
1144,
779,
17,
12,
18,
12,
19,
12,
20,
11,
17,
74,
12,
17,
12,
18,
12,
19,
12,
20,
11,
18,
74,
467,
2152,
275,
291,
14,
2866,
84,
9,
267,
612,
275,
18160,
8,
88,
9,
267,
291,
14,
1815,
8,
89,
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,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
bolkedebruin/airflow
|
airflow/providers/apache/spark/hooks/spark_jdbc.py
|
1
|
11610
|
# -*- coding: utf-8 -*-
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
import os
from airflow.exceptions import AirflowException
from airflow.providers.apache.spark.hooks.spark_submit import SparkSubmitHook
class SparkJDBCHook(SparkSubmitHook):
"""
This hook extends the SparkSubmitHook specifically for performing data
transfers to/from JDBC-based databases with Apache Spark.
:param spark_app_name: Name of the job (default airflow-spark-jdbc)
:type spark_app_name: str
:param spark_conn_id: Connection id as configured in Airflow administration
:type spark_conn_id: str
:param spark_conf: Any additional Spark configuration properties
:type spark_conf: dict
:param spark_py_files: Additional python files used (.zip, .egg, or .py)
:type spark_py_files: str
:param spark_files: Additional files to upload to the container running the job
:type spark_files: str
:param spark_jars: Additional jars to upload and add to the driver and
executor classpath
:type spark_jars: str
:param num_executors: number of executor to run. This should be set so as to manage
the number of connections made with the JDBC database
:type num_executors: int
:param executor_cores: Number of cores per executor
:type executor_cores: int
:param executor_memory: Memory per executor (e.g. 1000M, 2G)
:type executor_memory: str
:param driver_memory: Memory allocated to the driver (e.g. 1000M, 2G)
:type driver_memory: str
:param verbose: Whether to pass the verbose flag to spark-submit for debugging
:type verbose: bool
:param keytab: Full path to the file that contains the keytab
:type keytab: str
:param principal: The name of the kerberos principal used for keytab
:type principal: str
:param cmd_type: Which way the data should flow. 2 possible values:
spark_to_jdbc: data written by spark from metastore to jdbc
jdbc_to_spark: data written by spark from jdbc to metastore
:type cmd_type: str
:param jdbc_table: The name of the JDBC table
:type jdbc_table: str
:param jdbc_conn_id: Connection id used for connection to JDBC database
:type jdbc_conn_id: str
:param jdbc_driver: Name of the JDBC driver to use for the JDBC connection. This
driver (usually a jar) should be passed in the 'jars' parameter
:type jdbc_driver: str
:param metastore_table: The name of the metastore table,
:type metastore_table: str
:param jdbc_truncate: (spark_to_jdbc only) Whether or not Spark should truncate or
drop and recreate the JDBC table. This only takes effect if
'save_mode' is set to Overwrite. Also, if the schema is
different, Spark cannot truncate, and will drop and recreate
:type jdbc_truncate: bool
:param save_mode: The Spark save-mode to use (e.g. overwrite, append, etc.)
:type save_mode: str
:param save_format: (jdbc_to_spark-only) The Spark save-format to use (e.g. parquet)
:type save_format: str
:param batch_size: (spark_to_jdbc only) The size of the batch to insert per round
trip to the JDBC database. Defaults to 1000
:type batch_size: int
:param fetch_size: (jdbc_to_spark only) The size of the batch to fetch per round trip
from the JDBC database. Default depends on the JDBC driver
:type fetch_size: int
:param num_partitions: The maximum number of partitions that can be used by Spark
simultaneously, both for spark_to_jdbc and jdbc_to_spark
operations. This will also cap the number of JDBC connections
that can be opened
:type num_partitions: int
:param partition_column: (jdbc_to_spark-only) A numeric column to be used to
partition the metastore table by. If specified, you must
also specify:
num_partitions, lower_bound, upper_bound
:type partition_column: str
:param lower_bound: (jdbc_to_spark-only) Lower bound of the range of the numeric
partition column to fetch. If specified, you must also specify:
num_partitions, partition_column, upper_bound
:type lower_bound: int
:param upper_bound: (jdbc_to_spark-only) Upper bound of the range of the numeric
partition column to fetch. If specified, you must also specify:
num_partitions, partition_column, lower_bound
:type upper_bound: int
:param create_table_column_types: (spark_to_jdbc-only) The database column data types
to use instead of the defaults, when creating the
table. Data type information should be specified in
the same format as CREATE TABLE columns syntax
(e.g: "name CHAR(64), comments VARCHAR(1024)").
The specified types should be valid spark sql data
types.
"""
def __init__(self,
spark_app_name='airflow-spark-jdbc',
spark_conn_id='spark-default',
spark_conf=None,
spark_py_files=None,
spark_files=None,
spark_jars=None,
num_executors=None,
executor_cores=None,
executor_memory=None,
driver_memory=None,
verbose=False,
principal=None,
keytab=None,
cmd_type='spark_to_jdbc',
jdbc_table=None,
jdbc_conn_id='jdbc-default',
jdbc_driver=None,
metastore_table=None,
jdbc_truncate=False,
save_mode=None,
save_format=None,
batch_size=None,
fetch_size=None,
num_partitions=None,
partition_column=None,
lower_bound=None,
upper_bound=None,
create_table_column_types=None,
*args,
**kwargs
):
super().__init__(*args, **kwargs)
self._name = spark_app_name
self._conn_id = spark_conn_id
self._conf = spark_conf
self._py_files = spark_py_files
self._files = spark_files
self._jars = spark_jars
self._num_executors = num_executors
self._executor_cores = executor_cores
self._executor_memory = executor_memory
self._driver_memory = driver_memory
self._verbose = verbose
self._keytab = keytab
self._principal = principal
self._cmd_type = cmd_type
self._jdbc_table = jdbc_table
self._jdbc_conn_id = jdbc_conn_id
self._jdbc_driver = jdbc_driver
self._metastore_table = metastore_table
self._jdbc_truncate = jdbc_truncate
self._save_mode = save_mode
self._save_format = save_format
self._batch_size = batch_size
self._fetch_size = fetch_size
self._num_partitions = num_partitions
self._partition_column = partition_column
self._lower_bound = lower_bound
self._upper_bound = upper_bound
self._create_table_column_types = create_table_column_types
self._jdbc_connection = self._resolve_jdbc_connection()
def _resolve_jdbc_connection(self):
conn_data = {'url': '',
'schema': '',
'conn_prefix': '',
'user': '',
'password': ''
}
try:
conn = self.get_connection(self._jdbc_conn_id)
if conn.port:
conn_data['url'] = "{}:{}".format(conn.host, conn.port)
else:
conn_data['url'] = conn.host
conn_data['schema'] = conn.schema
conn_data['user'] = conn.login
conn_data['password'] = conn.password
extra = conn.extra_dejson
conn_data['conn_prefix'] = extra.get('conn_prefix', '')
except AirflowException:
self.log.debug(
"Could not load jdbc connection string %s, defaulting to %s",
self._jdbc_conn_id, ""
)
return conn_data
def _build_jdbc_application_arguments(self, jdbc_conn):
arguments = []
arguments += ["-cmdType", self._cmd_type]
if self._jdbc_connection['url']:
arguments += ['-url', "{0}{1}/{2}".format(
jdbc_conn['conn_prefix'], jdbc_conn['url'], jdbc_conn['schema']
)]
if self._jdbc_connection['user']:
arguments += ['-user', self._jdbc_connection['user']]
if self._jdbc_connection['password']:
arguments += ['-password', self._jdbc_connection['password']]
if self._metastore_table:
arguments += ['-metastoreTable', self._metastore_table]
if self._jdbc_table:
arguments += ['-jdbcTable', self._jdbc_table]
if self._jdbc_truncate:
arguments += ['-jdbcTruncate', str(self._jdbc_truncate)]
if self._jdbc_driver:
arguments += ['-jdbcDriver', self._jdbc_driver]
if self._batch_size:
arguments += ['-batchsize', str(self._batch_size)]
if self._fetch_size:
arguments += ['-fetchsize', str(self._fetch_size)]
if self._num_partitions:
arguments += ['-numPartitions', str(self._num_partitions)]
if (self._partition_column and self._lower_bound and
self._upper_bound and self._num_partitions):
# these 3 parameters need to be used all together to take effect.
arguments += ['-partitionColumn', self._partition_column,
'-lowerBound', self._lower_bound,
'-upperBound', self._upper_bound]
if self._save_mode:
arguments += ['-saveMode', self._save_mode]
if self._save_format:
arguments += ['-saveFormat', self._save_format]
if self._create_table_column_types:
arguments += ['-createTableColumnTypes', self._create_table_column_types]
return arguments
def submit_jdbc_job(self):
self._application_args = \
self._build_jdbc_application_arguments(self._jdbc_connection)
self.submit(application=os.path.dirname(os.path.abspath(__file__)) +
"/spark_jdbc_script.py")
def get_conn(self):
pass
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
3,
199,
646,
747,
199,
199,
504,
16321,
14,
3924,
492,
31040,
1726,
199,
504,
16321,
14,
9710,
14,
3796,
14,
9852,
14,
7922,
14,
9852,
63,
7275,
492,
13932,
17187,
8481,
421,
199,
533,
13932,
42,
2846,
1244,
6992,
8,
27110,
17187,
8481,
304,
272,
408,
272,
961,
5759,
16879,
314,
13932,
17187,
8481,
22543,
367,
19203,
666,
272,
28183,
1192,
370,
15,
504,
1603,
23317,
13,
6788,
16219,
543,
3668,
13932,
14,
339,
520,
635,
15442,
63,
571,
63,
354,
26,
2812,
402,
314,
3906,
334,
885,
16321,
13,
9852,
13,
29791,
9,
272,
520,
466,
15442,
63,
571,
63,
354,
26,
620,
272,
520,
635,
15442,
63,
1631,
63,
344,
26,
8113,
1305,
465,
7526,
315,
31040,
4628,
4633,
272,
520,
466,
15442,
63,
1631,
63,
344,
26,
620,
272,
520,
635,
15442,
63,
2190,
26,
6184,
4722,
13932,
2897,
4382,
272,
520,
466,
15442,
63,
2190,
26,
1211,
272,
520,
635,
15442,
63,
647,
63,
1725,
26,
10961,
2366,
1584,
1202,
17048,
3065,
12,
1275,
5799,
12,
503,
1275,
647,
9,
272,
520,
466,
15442,
63,
647,
63,
1725,
26,
620,
272,
520,
635,
15442,
63,
1725,
26,
10961,
1584,
370,
5802,
370,
314,
3970,
3879,
314,
3906,
272,
520,
466,
15442,
63,
1725,
26,
620,
272,
520,
635,
15442,
63,
32262,
26,
10961,
1335,
4291,
370,
5802,
436,
1050,
370,
314,
5253,
436,
2432,
13270,
1021,
515,
272,
520,
466,
15442,
63,
32262,
26,
620,
272,
520,
635,
1967,
63,
1628,
6622,
26,
1329,
402,
13270,
370,
1255,
14,
961,
1077,
506,
663,
880,
465,
370,
9635,
2079,
314,
1329,
402,
6947,
6326,
543,
314,
1603,
23317,
3050,
272,
520,
466,
1967,
63,
1628,
6622,
26,
1109,
272,
520,
635,
13270,
63,
4630,
26,
4860,
402,
23857,
1126,
13270,
272,
520,
466,
13270,
63,
4630,
26,
1109,
272,
520,
635,
13270,
63,
4844,
26,
15825,
1126,
13270,
334,
69,
14,
71,
14,
5198,
45,
12,
499,
39,
9,
272,
520,
466,
13270,
63,
4844,
26,
620,
272,
520,
635,
5253,
63,
4844,
26,
15825,
17659,
370,
314,
5253,
334,
69,
14,
71,
14,
5198,
45,
12,
499,
39,
9,
272,
520,
466,
5253,
63,
4844,
26,
620,
272,
520,
635,
3376,
26,
7480,
370,
986,
314,
3376,
3305,
370,
15442,
13,
7275,
367,
10201,
272,
520,
466,
3376,
26,
2155,
272,
520,
635,
790,
2902,
26,
16579,
931,
370,
314,
570,
626,
3509,
314,
790,
2902,
272,
520,
466,
790,
2902,
26,
620,
272,
520,
635,
21646,
26,
710,
536,
402,
314,
4303,
23920,
21646,
1202,
367,
790,
2902,
272,
520,
466,
21646,
26,
620,
272,
520,
635,
2088,
63,
466,
26,
26058,
4340,
314,
666,
1077,
6369,
14,
499,
3962,
1338,
26,
2151,
15442,
63,
475,
63,
29791,
26,
666,
5313,
701,
15442,
687,
3404,
1617,
370,
1335,
16845,
2151,
1335,
16845,
63,
475,
63,
9852,
26,
666,
5313,
701,
15442,
687,
1335,
16845,
370,
3404,
1617,
272,
520,
466,
2088,
63,
466,
26,
620,
272,
520,
635,
1335,
16845,
63,
1224,
26,
710,
536,
402,
314,
1603,
23317,
1817,
272,
520,
466,
1335,
16845,
63,
1224,
26,
620,
272,
520,
635,
1335,
16845,
63,
1631,
63,
344,
26,
8113,
1305,
1202,
367,
1950,
370,
1603,
23317,
3050,
272,
520,
466,
1335,
16845,
63,
1631,
63,
344,
26,
620,
272,
520,
635,
1335,
16845,
63,
3090,
26,
2812,
402,
314,
1603,
23317,
5253,
370,
675,
367,
314,
1603,
23317,
1950,
14,
961,
717,
5253,
334,
25118,
282,
16290,
9,
1077,
506,
3032,
315,
314,
283,
32262,
7,
2725,
272,
520,
466,
1335,
16845,
63,
3090,
26,
620,
272,
520,
635,
3404,
1617,
63,
1224,
26,
710,
536,
402,
314,
3404,
1617,
1817,
12,
272,
520,
466,
3404,
1617,
63,
1224,
26,
620,
272,
520,
635,
1335,
16845,
63,
12517,
26,
334,
9852,
63,
475,
63,
29791,
1454,
9,
7480,
503,
440,
13932,
1077,
14547,
503,
586,
5978,
436,
23959,
314,
1603,
23317,
1817,
14,
961,
1454,
6181,
7763,
340,
586,
283,
2117,
63,
632,
7,
365,
663,
370,
7259,
952,
14,
6121,
12,
340,
314,
4177,
365,
586,
3365,
12,
13932,
3913,
14547,
12,
436,
911,
5978,
436,
23959,
272,
520,
466,
1335,
16845,
63,
12517,
26,
2155,
272,
520,
635,
3354,
63,
632,
26,
710,
13932,
3354,
13,
632,
370,
675,
334,
69,
14,
71,
14,
8970,
12,
5666,
12,
5423,
4959,
272,
520,
466,
3354,
63,
632,
26,
620,
272,
520,
635,
3354,
63,
908,
26,
334,
29791,
63,
475,
63,
9852,
13,
2118,
9,
710,
13932,
3354,
13,
908,
370,
675,
334,
69,
14,
71,
14,
623,
17917,
9,
272,
520,
466,
3354,
63,
908,
26,
620,
272,
520,
635,
3522,
63,
890,
26,
334,
9852,
63,
475,
63,
29791,
1454,
9,
710,
1568,
402,
314,
3522,
370,
5518,
1126,
6168,
2432,
18038,
370,
314,
1603,
23317,
3050,
14,
7827,
370,
5198,
272,
520,
466,
3522,
63,
890,
26,
1109,
272,
520,
635,
5267,
63,
890,
26,
334,
29791,
63,
475,
63,
9852,
1454,
9,
710,
1568,
402,
314,
3522,
370,
5267,
1126
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
3,
199,
646,
747,
199,
199,
504,
16321,
14,
3924,
492,
31040,
1726,
199,
504,
16321,
14,
9710,
14,
3796,
14,
9852,
14,
7922,
14,
9852,
63,
7275,
492,
13932,
17187,
8481,
421,
199,
533,
13932,
42,
2846,
1244,
6992,
8,
27110,
17187,
8481,
304,
272,
408,
272,
961,
5759,
16879,
314,
13932,
17187,
8481,
22543,
367,
19203,
666,
272,
28183,
1192,
370,
15,
504,
1603,
23317,
13,
6788,
16219,
543,
3668,
13932,
14,
339,
520,
635,
15442,
63,
571,
63,
354,
26,
2812,
402,
314,
3906,
334,
885,
16321,
13,
9852,
13,
29791,
9,
272,
520,
466,
15442,
63,
571,
63,
354,
26,
620,
272,
520,
635,
15442,
63,
1631,
63,
344,
26,
8113,
1305,
465,
7526,
315,
31040,
4628,
4633,
272,
520,
466,
15442,
63,
1631,
63,
344,
26,
620,
272,
520,
635,
15442,
63,
2190,
26,
6184,
4722,
13932,
2897,
4382,
272,
520,
466,
15442,
63,
2190,
26,
1211,
272,
520,
635,
15442,
63,
647,
63,
1725,
26,
10961,
2366,
1584,
1202,
17048,
3065,
12,
1275,
5799,
12,
503,
1275,
647,
9,
272,
520,
466,
15442,
63,
647,
63,
1725,
26,
620,
272,
520,
635,
15442,
63,
1725,
26,
10961,
1584,
370,
5802,
370,
314,
3970,
3879,
314,
3906,
272,
520,
466,
15442,
63,
1725,
26,
620,
272,
520,
635,
15442,
63,
32262,
26,
10961,
1335,
4291,
370,
5802,
436,
1050,
370,
314,
5253,
436,
2432,
13270,
1021,
515,
272,
520,
466,
15442,
63,
32262,
26,
620,
272,
520,
635,
1967,
63,
1628,
6622,
26,
1329,
402,
13270,
370,
1255,
14,
961,
1077,
506,
663,
880,
465,
370,
9635,
2079,
314,
1329,
402,
6947,
6326,
543,
314,
1603,
23317,
3050,
272,
520,
466,
1967,
63,
1628,
6622,
26,
1109,
272,
520,
635,
13270,
63,
4630,
26,
4860,
402,
23857,
1126,
13270,
272,
520,
466,
13270,
63,
4630,
26,
1109,
272,
520,
635,
13270,
63,
4844,
26,
15825,
1126,
13270,
334,
69,
14,
71,
14,
5198,
45,
12,
499,
39,
9,
272,
520,
466,
13270,
63,
4844,
26,
620,
272,
520,
635,
5253,
63,
4844,
26,
15825,
17659,
370,
314,
5253,
334,
69,
14,
71,
14,
5198,
45,
12,
499,
39,
9,
272,
520,
466,
5253,
63,
4844,
26,
620,
272,
520,
635,
3376,
26,
7480,
370,
986,
314,
3376,
3305,
370,
15442,
13,
7275,
367,
10201,
272,
520,
466,
3376,
26,
2155,
272,
520,
635,
790,
2902,
26,
16579,
931,
370,
314,
570,
626,
3509,
314,
790,
2902,
272,
520,
466,
790,
2902,
26,
620,
272,
520,
635,
21646,
26,
710,
536,
402,
314,
4303,
23920,
21646,
1202,
367,
790,
2902,
272,
520,
466,
21646,
26,
620,
272,
520,
635,
2088,
63,
466,
26,
26058,
4340,
314,
666,
1077,
6369,
14,
499,
3962,
1338,
26,
2151,
15442,
63,
475,
63,
29791,
26,
666,
5313,
701,
15442,
687,
3404,
1617,
370,
1335,
16845,
2151,
1335,
16845,
63,
475,
63,
9852,
26,
666,
5313,
701,
15442,
687,
1335,
16845,
370,
3404,
1617,
272,
520,
466,
2088,
63,
466,
26,
620,
272,
520,
635,
1335,
16845,
63,
1224,
26,
710,
536,
402,
314,
1603,
23317,
1817,
272,
520,
466,
1335,
16845,
63,
1224,
26,
620,
272,
520,
635,
1335,
16845,
63,
1631,
63,
344,
26,
8113,
1305,
1202,
367,
1950,
370,
1603,
23317,
3050,
272,
520,
466,
1335,
16845,
63,
1631,
63,
344,
26,
620,
272,
520,
635,
1335,
16845,
63,
3090,
26,
2812,
402,
314,
1603,
23317,
5253,
370,
675,
367,
314,
1603,
23317,
1950,
14,
961,
717,
5253,
334,
25118,
282,
16290,
9,
1077,
506,
3032,
315,
314,
283,
32262,
7,
2725,
272,
520,
466,
1335,
16845,
63,
3090,
26,
620,
272,
520,
635,
3404,
1617,
63,
1224,
26,
710,
536,
402,
314,
3404,
1617,
1817,
12,
272,
520,
466,
3404,
1617,
63,
1224,
26,
620,
272,
520,
635,
1335,
16845,
63,
12517,
26,
334,
9852,
63,
475,
63,
29791,
1454,
9,
7480,
503,
440,
13932,
1077,
14547,
503,
586,
5978,
436,
23959,
314,
1603,
23317,
1817,
14,
961,
1454,
6181,
7763,
340,
586,
283,
2117,
63,
632,
7,
365,
663,
370,
7259,
952,
14,
6121,
12,
340,
314,
4177,
365,
586,
3365,
12,
13932,
3913,
14547,
12,
436,
911,
5978,
436,
23959,
272,
520,
466,
1335,
16845,
63,
12517,
26,
2155,
272,
520,
635,
3354,
63,
632,
26,
710,
13932,
3354,
13,
632,
370,
675,
334,
69,
14,
71,
14,
8970,
12,
5666,
12,
5423,
4959,
272,
520,
466,
3354,
63,
632,
26,
620,
272,
520,
635,
3354,
63,
908,
26,
334,
29791,
63,
475,
63,
9852,
13,
2118,
9,
710,
13932,
3354,
13,
908,
370,
675,
334,
69,
14,
71,
14,
623,
17917,
9,
272,
520,
466,
3354,
63,
908,
26,
620,
272,
520,
635,
3522,
63,
890,
26,
334,
9852,
63,
475,
63,
29791,
1454,
9,
710,
1568,
402,
314,
3522,
370,
5518,
1126,
6168,
2432,
18038,
370,
314,
1603,
23317,
3050,
14,
7827,
370,
5198,
272,
520,
466,
3522,
63,
890,
26,
1109,
272,
520,
635,
5267,
63,
890,
26,
334,
29791,
63,
475,
63,
9852,
1454,
9,
710,
1568,
402,
314,
3522,
370,
5267,
1126,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
arantebillywilson/python-snippets
|
microblog/flask/lib/python3.5/site-packages/sqlalchemy/testing/util.py
|
15
|
7540
|
# testing/util.py
# Copyright (C) 2005-2017 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
from ..util import jython, pypy, defaultdict, decorator, py2k
import decimal
import gc
import time
import random
import sys
import types
if jython:
def jython_gc_collect(*args):
"""aggressive gc.collect for tests."""
gc.collect()
time.sleep(0.1)
gc.collect()
gc.collect()
return 0
# "lazy" gc, for VM's that don't GC on refcount == 0
gc_collect = lazy_gc = jython_gc_collect
elif pypy:
def pypy_gc_collect(*args):
gc.collect()
gc.collect()
gc_collect = lazy_gc = pypy_gc_collect
else:
# assume CPython - straight gc.collect, lazy_gc() is a pass
gc_collect = gc.collect
def lazy_gc():
pass
def picklers():
picklers = set()
if py2k:
try:
import cPickle
picklers.add(cPickle)
except ImportError:
pass
import pickle
picklers.add(pickle)
# yes, this thing needs this much testing
for pickle_ in picklers:
for protocol in -1, 0, 1, 2:
yield pickle_.loads, lambda d: pickle_.dumps(d, protocol)
def round_decimal(value, prec):
if isinstance(value, float):
return round(value, prec)
# can also use shift() here but that is 2.6 only
return (value * decimal.Decimal("1" + "0" * prec)
).to_integral(decimal.ROUND_FLOOR) / \
pow(10, prec)
class RandomSet(set):
def __iter__(self):
l = list(set.__iter__(self))
random.shuffle(l)
return iter(l)
def pop(self):
index = random.randint(0, len(self) - 1)
item = list(set.__iter__(self))[index]
self.remove(item)
return item
def union(self, other):
return RandomSet(set.union(self, other))
def difference(self, other):
return RandomSet(set.difference(self, other))
def intersection(self, other):
return RandomSet(set.intersection(self, other))
def copy(self):
return RandomSet(self)
def conforms_partial_ordering(tuples, sorted_elements):
"""True if the given sorting conforms to the given partial ordering."""
deps = defaultdict(set)
for parent, child in tuples:
deps[parent].add(child)
for i, node in enumerate(sorted_elements):
for n in sorted_elements[i:]:
if node in deps[n]:
return False
else:
return True
def all_partial_orderings(tuples, elements):
edges = defaultdict(set)
for parent, child in tuples:
edges[child].add(parent)
def _all_orderings(elements):
if len(elements) == 1:
yield list(elements)
else:
for elem in elements:
subset = set(elements).difference([elem])
if not subset.intersection(edges[elem]):
for sub_ordering in _all_orderings(subset):
yield [elem] + sub_ordering
return iter(_all_orderings(elements))
def function_named(fn, name):
"""Return a function with a given __name__.
Will assign to __name__ and return the original function if possible on
the Python implementation, otherwise a new function will be constructed.
This function should be phased out as much as possible
in favor of @decorator. Tests that "generate" many named tests
should be modernized.
"""
try:
fn.__name__ = name
except TypeError:
fn = types.FunctionType(fn.__code__, fn.__globals__, name,
fn.__defaults__, fn.__closure__)
return fn
def run_as_contextmanager(ctx, fn, *arg, **kw):
"""Run the given function under the given contextmanager,
simulating the behavior of 'with' to support older
Python versions.
This is not necessary anymore as we have placed 2.6
as minimum Python version, however some tests are still using
this structure.
"""
obj = ctx.__enter__()
try:
result = fn(obj, *arg, **kw)
ctx.__exit__(None, None, None)
return result
except:
exc_info = sys.exc_info()
raise_ = ctx.__exit__(*exc_info)
if not raise_:
raise
else:
return raise_
def rowset(results):
"""Converts the results of sql execution into a plain set of column tuples.
Useful for asserting the results of an unordered query.
"""
return set([tuple(row) for row in results])
def fail(msg):
assert False, msg
@decorator
def provide_metadata(fn, *args, **kw):
"""Provide bound MetaData for a single test, dropping afterwards."""
from . import config
from . import engines
from sqlalchemy import schema
metadata = schema.MetaData(config.db)
self = args[0]
prev_meta = getattr(self, 'metadata', None)
self.metadata = metadata
try:
return fn(*args, **kw)
finally:
engines.drop_all_tables(metadata, config.db)
self.metadata = prev_meta
def force_drop_names(*names):
"""Force the given table names to be dropped after test complete,
isolating for foreign key cycles
"""
from . import config
from sqlalchemy import inspect
@decorator
def go(fn, *args, **kw):
try:
return fn(*args, **kw)
finally:
drop_all_tables(
config.db, inspect(config.db), include_names=names)
return go
class adict(dict):
"""Dict keys available as attributes. Shadows."""
def __getattribute__(self, key):
try:
return self[key]
except KeyError:
return dict.__getattribute__(self, key)
def __call__(self, *keys):
return tuple([self[key] for key in keys])
get_all = __call__
def drop_all_tables(engine, inspector, schema=None, include_names=None):
from sqlalchemy import Column, Table, Integer, MetaData, \
ForeignKeyConstraint
from sqlalchemy.schema import DropTable, DropConstraint
if include_names is not None:
include_names = set(include_names)
with engine.connect() as conn:
for tname, fkcs in reversed(
inspector.get_sorted_table_and_fkc_names(schema=schema)):
if tname:
if include_names is not None and tname not in include_names:
continue
conn.execute(DropTable(
Table(tname, MetaData(), schema=schema)
))
elif fkcs:
if not engine.dialect.supports_alter:
continue
for tname, fkc in fkcs:
if include_names is not None and \
tname not in include_names:
continue
tb = Table(
tname, MetaData(),
Column('x', Integer),
Column('y', Integer),
schema=schema
)
conn.execute(DropConstraint(
ForeignKeyConstraint(
[tb.c.x], [tb.c.y], name=fkc)
))
def teardown_events(event_cls):
@decorator
def decorate(fn, *arg, **kw):
try:
return fn(*arg, **kw)
finally:
event_cls._clear()
return decorate
|
mit
|
[
3,
5343,
15,
1974,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
13,
10680,
314,
14303,
11462,
436,
8417,
199,
3,
665,
3239,
10610,
570,
30,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
504,
2508,
1974,
492,
1335,
11361,
12,
1134,
647,
12,
10018,
12,
7531,
12,
1134,
18,
75,
199,
646,
6107,
199,
646,
9486,
199,
646,
900,
199,
646,
2196,
199,
646,
984,
199,
646,
2943,
199,
199,
692,
1335,
11361,
26,
272,
347,
1335,
11361,
63,
9493,
63,
7112,
2031,
589,
304,
267,
408,
643,
25787,
9486,
14,
7112,
367,
2295,
1041,
267,
9486,
14,
7112,
342,
267,
900,
14,
4532,
8,
16,
14,
17,
9,
267,
9486,
14,
7112,
342,
267,
9486,
14,
7112,
342,
267,
372,
378,
339,
327,
298,
6395,
2,
9486,
12,
367,
7525,
1159,
626,
2793,
1133,
31555,
641,
2984,
835,
508,
378,
272,
9486,
63,
7112,
275,
9617,
63,
9493,
275,
1335,
11361,
63,
9493,
63,
7112,
199,
4164,
1134,
647,
26,
272,
347,
1134,
647,
63,
9493,
63,
7112,
2031,
589,
304,
267,
9486,
14,
7112,
342,
267,
9486,
14,
7112,
342,
272,
9486,
63,
7112,
275,
9617,
63,
9493,
275,
1134,
647,
63,
9493,
63,
7112,
199,
2836,
26,
272,
327,
5534,
25654,
446,
23669,
9486,
14,
7112,
12,
9617,
63,
9493,
342,
365,
282,
986,
272,
9486,
63,
7112,
275,
9486,
14,
7112,
339,
347,
9617,
63,
9493,
837,
267,
986,
421,
199,
318,
3732,
29099,
837,
272,
3732,
29099,
275,
663,
342,
272,
340,
1134,
18,
75,
26,
267,
862,
26,
288,
492,
17572,
288,
3732,
29099,
14,
525,
8,
67,
12755,
9,
267,
871,
3545,
26,
288,
986,
339,
492,
5927,
272,
3732,
29099,
14,
525,
8,
8092,
9,
339,
327,
9456,
12,
642,
8377,
4839,
642,
8298,
5343,
272,
367,
5927,
63,
315,
3732,
29099,
26,
267,
367,
4113,
315,
446,
17,
12,
378,
12,
413,
12,
499,
26,
288,
1995,
5927,
3754,
3640,
12,
2400,
366,
26,
5927,
3754,
4180,
8,
68,
12,
4113,
9,
421,
199,
318,
6168,
63,
6355,
8,
585,
12,
13826,
304,
272,
340,
1228,
8,
585,
12,
2069,
304,
267,
372,
6168,
8,
585,
12,
13826,
9,
339,
327,
883,
2597,
675,
7706,
342,
2348,
1325,
626,
365,
499,
14,
22,
1454,
272,
372,
334,
585,
627,
6107,
14,
6745,
480,
17,
2,
435,
298,
16,
2,
627,
13826,
9,
288,
7092,
475,
63,
24705,
8,
6355,
14,
16848,
63,
38,
1484,
726,
9,
1182,
971,
267,
13131,
8,
709,
12,
13826,
9,
421,
199,
533,
9571,
1084,
8,
409,
304,
272,
347,
636,
1661,
721,
277,
304,
267,
634,
275,
769,
8,
409,
855,
1661,
721,
277,
430,
267,
2196,
14,
11777,
8,
76,
9,
267,
372,
2740,
8,
76,
9,
339,
347,
4560,
8,
277,
304,
267,
1478,
275,
2196,
14,
8393,
8,
16,
12,
822,
8,
277,
9,
446,
413,
9,
267,
1242,
275,
769,
8,
409,
855,
1661,
721,
277,
11515,
1080,
61,
267,
291,
14,
2168,
8,
1053,
9,
267,
372,
1242,
339,
347,
13629,
8,
277,
12,
1163,
304,
267,
372,
9571,
1084,
8,
409,
14,
8888,
8,
277,
12,
1163,
430,
339,
347,
8865,
8,
277,
12,
1163,
304,
267,
372,
9571,
1084,
8,
409,
14,
9196,
8,
277,
12,
1163,
430,
339,
347,
16223,
8,
277,
12,
1163,
304,
267,
372,
9571,
1084,
8,
409,
14,
12569,
8,
277,
12,
1163,
430,
339,
347,
1331,
8,
277,
304,
267,
372,
9571,
1084,
8,
277,
9,
421,
199,
318,
406,
3351,
63,
6672,
63,
7128,
8,
11760,
12,
3355,
63,
5527,
304,
272,
408,
549,
340,
314,
1627,
13351,
406,
3351,
370,
314,
1627,
7417,
7794,
1041,
339,
10140,
275,
10018,
8,
409,
9,
272,
367,
1676,
12,
1982,
315,
6346,
26,
267,
10140,
59,
1708,
1055,
525,
8,
1739,
9,
272,
367,
284,
12,
1031,
315,
3874,
8,
5917,
63,
5527,
304,
267,
367,
302,
315,
3355,
63,
5527,
59,
73,
10688,
288,
340,
1031,
315,
10140,
59,
78,
2189,
355,
372,
756,
272,
587,
26,
267,
372,
715,
421,
199,
318,
1006,
63,
6672,
63,
1648,
780,
8,
11760,
12,
4008,
304,
272,
8207,
275,
10018,
8,
409,
9,
272,
367,
1676,
12,
1982,
315,
6346,
26,
267,
8207,
59,
1739,
1055,
525,
8,
1708,
9,
339,
347,
485,
452,
63,
1648,
780,
8,
5527,
304,
398,
340,
822,
8,
5527,
9,
508,
413,
26,
288,
1995,
769,
8,
5527,
9,
267,
587,
26,
288,
367,
6193,
315,
4008,
26,
355,
10026,
275,
663,
8,
5527,
680,
9196,
779,
6086,
566,
355,
340,
440,
10026,
14,
12569,
8,
6929,
59,
6086,
4682,
490,
367,
1007,
63,
7128,
315,
485,
452,
63,
1648,
780,
8,
9401,
304,
717,
1995,
359,
6086,
61,
435,
1007,
63,
7128,
339,
372,
2740,
1547,
452,
63,
1648,
780,
8,
5527,
430,
421,
199,
318,
805,
63,
4579,
8,
2324,
12,
536,
304,
272,
408,
1767,
282,
805,
543,
282,
1627,
636,
354,
4343,
339,
12823,
5090,
370,
636,
354,
363,
436,
372,
314,
3379,
805,
340,
3962,
641,
272,
314,
2018,
4514,
12,
4257,
282,
892,
805,
911,
506,
14701,
14,
339,
961,
805,
1077,
506,
7669,
68,
734,
465,
8298,
465,
3962,
272,
315,
17914,
402,
768,
11547,
14,
257,
6496,
626,
298,
4208,
2,
5002,
4310,
2295,
272,
1077,
506,
818,
11641,
1759,
14,
339,
408,
272,
862,
26,
267,
4325,
855,
354,
363,
275,
536,
272,
871,
3146,
26,
267,
4325,
275,
2943,
14,
26371,
8,
2324,
855,
600,
3108,
4325,
855,
8473,
3108,
536,
12,
1816,
4325,
855,
4322,
3108,
4325,
855,
13008,
3368,
272,
372,
4325,
421,
199,
318,
1255,
63,
305,
63,
14237,
8,
3799,
12,
4325,
12,
627,
1273,
12,
1011,
829,
304,
272,
408,
2540,
314,
1627,
805,
1334,
314,
1627,
27608,
12,
272,
4389,
20529,
314,
5953,
402,
283,
1045,
7,
370,
2291,
12731,
272,
2018,
5459,
14,
339,
961,
365,
440,
5784,
20827,
465,
781,
1172,
15090,
499,
14,
22,
272,
465,
7481,
2018,
1015,
12,
13432,
2005
] |
[
5343,
15,
1974,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
13,
10680,
314,
14303,
11462,
436,
8417,
199,
3,
665,
3239,
10610,
570,
30,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
504,
2508,
1974,
492,
1335,
11361,
12,
1134,
647,
12,
10018,
12,
7531,
12,
1134,
18,
75,
199,
646,
6107,
199,
646,
9486,
199,
646,
900,
199,
646,
2196,
199,
646,
984,
199,
646,
2943,
199,
199,
692,
1335,
11361,
26,
272,
347,
1335,
11361,
63,
9493,
63,
7112,
2031,
589,
304,
267,
408,
643,
25787,
9486,
14,
7112,
367,
2295,
1041,
267,
9486,
14,
7112,
342,
267,
900,
14,
4532,
8,
16,
14,
17,
9,
267,
9486,
14,
7112,
342,
267,
9486,
14,
7112,
342,
267,
372,
378,
339,
327,
298,
6395,
2,
9486,
12,
367,
7525,
1159,
626,
2793,
1133,
31555,
641,
2984,
835,
508,
378,
272,
9486,
63,
7112,
275,
9617,
63,
9493,
275,
1335,
11361,
63,
9493,
63,
7112,
199,
4164,
1134,
647,
26,
272,
347,
1134,
647,
63,
9493,
63,
7112,
2031,
589,
304,
267,
9486,
14,
7112,
342,
267,
9486,
14,
7112,
342,
272,
9486,
63,
7112,
275,
9617,
63,
9493,
275,
1134,
647,
63,
9493,
63,
7112,
199,
2836,
26,
272,
327,
5534,
25654,
446,
23669,
9486,
14,
7112,
12,
9617,
63,
9493,
342,
365,
282,
986,
272,
9486,
63,
7112,
275,
9486,
14,
7112,
339,
347,
9617,
63,
9493,
837,
267,
986,
421,
199,
318,
3732,
29099,
837,
272,
3732,
29099,
275,
663,
342,
272,
340,
1134,
18,
75,
26,
267,
862,
26,
288,
492,
17572,
288,
3732,
29099,
14,
525,
8,
67,
12755,
9,
267,
871,
3545,
26,
288,
986,
339,
492,
5927,
272,
3732,
29099,
14,
525,
8,
8092,
9,
339,
327,
9456,
12,
642,
8377,
4839,
642,
8298,
5343,
272,
367,
5927,
63,
315,
3732,
29099,
26,
267,
367,
4113,
315,
446,
17,
12,
378,
12,
413,
12,
499,
26,
288,
1995,
5927,
3754,
3640,
12,
2400,
366,
26,
5927,
3754,
4180,
8,
68,
12,
4113,
9,
421,
199,
318,
6168,
63,
6355,
8,
585,
12,
13826,
304,
272,
340,
1228,
8,
585,
12,
2069,
304,
267,
372,
6168,
8,
585,
12,
13826,
9,
339,
327,
883,
2597,
675,
7706,
342,
2348,
1325,
626,
365,
499,
14,
22,
1454,
272,
372,
334,
585,
627,
6107,
14,
6745,
480,
17,
2,
435,
298,
16,
2,
627,
13826,
9,
288,
7092,
475,
63,
24705,
8,
6355,
14,
16848,
63,
38,
1484,
726,
9,
1182,
971,
267,
13131,
8,
709,
12,
13826,
9,
421,
199,
533,
9571,
1084,
8,
409,
304,
272,
347,
636,
1661,
721,
277,
304,
267,
634,
275,
769,
8,
409,
855,
1661,
721,
277,
430,
267,
2196,
14,
11777,
8,
76,
9,
267,
372,
2740,
8,
76,
9,
339,
347,
4560,
8,
277,
304,
267,
1478,
275,
2196,
14,
8393,
8,
16,
12,
822,
8,
277,
9,
446,
413,
9,
267,
1242,
275,
769,
8,
409,
855,
1661,
721,
277,
11515,
1080,
61,
267,
291,
14,
2168,
8,
1053,
9,
267,
372,
1242,
339,
347,
13629,
8,
277,
12,
1163,
304,
267,
372,
9571,
1084,
8,
409,
14,
8888,
8,
277,
12,
1163,
430,
339,
347,
8865,
8,
277,
12,
1163,
304,
267,
372,
9571,
1084,
8,
409,
14,
9196,
8,
277,
12,
1163,
430,
339,
347,
16223,
8,
277,
12,
1163,
304,
267,
372,
9571,
1084,
8,
409,
14,
12569,
8,
277,
12,
1163,
430,
339,
347,
1331,
8,
277,
304,
267,
372,
9571,
1084,
8,
277,
9,
421,
199,
318,
406,
3351,
63,
6672,
63,
7128,
8,
11760,
12,
3355,
63,
5527,
304,
272,
408,
549,
340,
314,
1627,
13351,
406,
3351,
370,
314,
1627,
7417,
7794,
1041,
339,
10140,
275,
10018,
8,
409,
9,
272,
367,
1676,
12,
1982,
315,
6346,
26,
267,
10140,
59,
1708,
1055,
525,
8,
1739,
9,
272,
367,
284,
12,
1031,
315,
3874,
8,
5917,
63,
5527,
304,
267,
367,
302,
315,
3355,
63,
5527,
59,
73,
10688,
288,
340,
1031,
315,
10140,
59,
78,
2189,
355,
372,
756,
272,
587,
26,
267,
372,
715,
421,
199,
318,
1006,
63,
6672,
63,
1648,
780,
8,
11760,
12,
4008,
304,
272,
8207,
275,
10018,
8,
409,
9,
272,
367,
1676,
12,
1982,
315,
6346,
26,
267,
8207,
59,
1739,
1055,
525,
8,
1708,
9,
339,
347,
485,
452,
63,
1648,
780,
8,
5527,
304,
398,
340,
822,
8,
5527,
9,
508,
413,
26,
288,
1995,
769,
8,
5527,
9,
267,
587,
26,
288,
367,
6193,
315,
4008,
26,
355,
10026,
275,
663,
8,
5527,
680,
9196,
779,
6086,
566,
355,
340,
440,
10026,
14,
12569,
8,
6929,
59,
6086,
4682,
490,
367,
1007,
63,
7128,
315,
485,
452,
63,
1648,
780,
8,
9401,
304,
717,
1995,
359,
6086,
61,
435,
1007,
63,
7128,
339,
372,
2740,
1547,
452,
63,
1648,
780,
8,
5527,
430,
421,
199,
318,
805,
63,
4579,
8,
2324,
12,
536,
304,
272,
408,
1767,
282,
805,
543,
282,
1627,
636,
354,
4343,
339,
12823,
5090,
370,
636,
354,
363,
436,
372,
314,
3379,
805,
340,
3962,
641,
272,
314,
2018,
4514,
12,
4257,
282,
892,
805,
911,
506,
14701,
14,
339,
961,
805,
1077,
506,
7669,
68,
734,
465,
8298,
465,
3962,
272,
315,
17914,
402,
768,
11547,
14,
257,
6496,
626,
298,
4208,
2,
5002,
4310,
2295,
272,
1077,
506,
818,
11641,
1759,
14,
339,
408,
272,
862,
26,
267,
4325,
855,
354,
363,
275,
536,
272,
871,
3146,
26,
267,
4325,
275,
2943,
14,
26371,
8,
2324,
855,
600,
3108,
4325,
855,
8473,
3108,
536,
12,
1816,
4325,
855,
4322,
3108,
4325,
855,
13008,
3368,
272,
372,
4325,
421,
199,
318,
1255,
63,
305,
63,
14237,
8,
3799,
12,
4325,
12,
627,
1273,
12,
1011,
829,
304,
272,
408,
2540,
314,
1627,
805,
1334,
314,
1627,
27608,
12,
272,
4389,
20529,
314,
5953,
402,
283,
1045,
7,
370,
2291,
12731,
272,
2018,
5459,
14,
339,
961,
365,
440,
5784,
20827,
465,
781,
1172,
15090,
499,
14,
22,
272,
465,
7481,
2018,
1015,
12,
13432,
2005,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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 nova websocketproxy."""
import mock
from nova.console import websocketproxy
from nova import exception
from nova import test
from oslo_config import cfg
CONF = cfg.CONF
class NovaProxyRequestHandlerBaseTestCase(test.NoDBTestCase):
def setUp(self):
super(NovaProxyRequestHandlerBaseTestCase, self).setUp()
self.wh = websocketproxy.NovaProxyRequestHandlerBase()
self.wh.socket = mock.MagicMock()
self.wh.msg = mock.MagicMock()
self.wh.do_proxy = mock.MagicMock()
self.wh.headers = mock.MagicMock()
def _fake_getheader(self, header):
if header == 'cookie':
return 'token="123-456-789"'
elif header == 'Origin':
return 'https://example.net:6080'
elif header == 'Host':
return 'example.net:6080'
else:
return
def _fake_getheader_ipv6(self, header):
if header == 'cookie':
return 'token="123-456-789"'
elif header == 'Origin':
return 'https://[2001:db8::1]:6080'
elif header == 'Host':
return '[2001:db8::1]:6080'
else:
return
def _fake_getheader_bad_token(self, header):
if header == 'cookie':
return 'token="XXX"'
elif header == 'Origin':
return 'https://example.net:6080'
elif header == 'Host':
return 'example.net:6080'
else:
return
def _fake_getheader_bad_origin(self, header):
if header == 'cookie':
return 'token="123-456-789"'
elif header == 'Origin':
return 'https://bad-origin-example.net:6080'
elif header == 'Host':
return 'example.net:6080'
else:
return
def _fake_getheader_blank_origin(self, header):
if header == 'cookie':
return 'token="123-456-789"'
elif header == 'Origin':
return ''
elif header == 'Host':
return 'example.net:6080'
else:
return
def _fake_getheader_no_origin(self, header):
if header == 'cookie':
return 'token="123-456-789"'
elif header == 'Origin':
return None
elif header == 'Host':
return 'any-example.net:6080'
else:
return
def _fake_getheader_http(self, header):
if header == 'cookie':
return 'token="123-456-789"'
elif header == 'Origin':
return 'http://example.net:6080'
elif header == 'Host':
return 'example.net:6080'
else:
return
@mock.patch('nova.consoleauth.rpcapi.ConsoleAuthAPI.check_token')
def test_new_websocket_client(self, check_token):
check_token.return_value = {
'host': 'node1',
'port': '10000',
'console_type': 'novnc',
'access_url': 'https://example.net:6080'
}
self.wh.socket.return_value = '<socket>'
self.wh.path = "http://127.0.0.1/?token=123-456-789"
self.wh.headers.getheader = self._fake_getheader
self.wh.new_websocket_client()
check_token.assert_called_with(mock.ANY, token="123-456-789")
self.wh.socket.assert_called_with('node1', 10000, connect=True)
self.wh.do_proxy.assert_called_with('<socket>')
@mock.patch('nova.consoleauth.rpcapi.ConsoleAuthAPI.check_token')
def test_new_websocket_client_ipv6_url(self, check_token):
check_token.return_value = {
'host': 'node1',
'port': '10000',
'console_type': 'novnc',
'access_url': 'https://[2001:db8::1]:6080'
}
self.wh.socket.return_value = '<socket>'
self.wh.path = "http://[2001:db8::1]/?token=123-456-789"
self.wh.headers.getheader = self._fake_getheader_ipv6
self.wh.new_websocket_client()
check_token.assert_called_with(mock.ANY, token="123-456-789")
self.wh.socket.assert_called_with('node1', 10000, connect=True)
self.wh.do_proxy.assert_called_with('<socket>')
@mock.patch('nova.consoleauth.rpcapi.ConsoleAuthAPI.check_token')
def test_new_websocket_client_token_invalid(self, check_token):
check_token.return_value = False
self.wh.path = "http://127.0.0.1/?token=XXX"
self.wh.headers.getheader = self._fake_getheader_bad_token
self.assertRaises(exception.InvalidToken,
self.wh.new_websocket_client)
check_token.assert_called_with(mock.ANY, token="XXX")
@mock.patch('nova.consoleauth.rpcapi.ConsoleAuthAPI.check_token')
def test_new_websocket_client_internal_access_path(self, check_token):
check_token.return_value = {
'host': 'node1',
'port': '10000',
'internal_access_path': 'vmid',
'console_type': 'novnc',
'access_url': 'https://example.net:6080'
}
tsock = mock.MagicMock()
tsock.recv.return_value = "HTTP/1.1 200 OK\r\n\r\n"
self.wh.socket.return_value = tsock
self.wh.path = "http://127.0.0.1/?token=123-456-789"
self.wh.headers.getheader = self._fake_getheader
self.wh.new_websocket_client()
check_token.assert_called_with(mock.ANY, token="123-456-789")
self.wh.socket.assert_called_with('node1', 10000, connect=True)
self.wh.do_proxy.assert_called_with(tsock)
@mock.patch('nova.consoleauth.rpcapi.ConsoleAuthAPI.check_token')
def test_new_websocket_client_internal_access_path_err(self, check_token):
check_token.return_value = {
'host': 'node1',
'port': '10000',
'internal_access_path': 'xxx',
'console_type': 'novnc',
'access_url': 'https://example.net:6080'
}
tsock = mock.MagicMock()
tsock.recv.return_value = "HTTP/1.1 500 Internal Server Error\r\n\r\n"
self.wh.socket.return_value = tsock
self.wh.path = "http://127.0.0.1/?token=123-456-789"
self.wh.headers.getheader = self._fake_getheader
self.assertRaises(exception.InvalidConnectionInfo,
self.wh.new_websocket_client)
check_token.assert_called_with(mock.ANY, token="123-456-789")
@mock.patch('sys.version_info')
@mock.patch('nova.consoleauth.rpcapi.ConsoleAuthAPI.check_token')
def test_new_websocket_client_py273_good_scheme(
self, check_token, version_info):
version_info.return_value = (2, 7, 3)
check_token.return_value = {
'host': 'node1',
'port': '10000',
'console_type': 'novnc',
'access_url': 'https://example.net:6080'
}
self.wh.socket.return_value = '<socket>'
self.wh.path = "http://127.0.0.1/?token=123-456-789"
self.wh.headers.getheader = self._fake_getheader
self.wh.new_websocket_client()
check_token.assert_called_with(mock.ANY, token="123-456-789")
self.wh.socket.assert_called_with('node1', 10000, connect=True)
self.wh.do_proxy.assert_called_with('<socket>')
@mock.patch('sys.version_info')
@mock.patch('nova.consoleauth.rpcapi.ConsoleAuthAPI.check_token')
def test_new_websocket_client_py273_special_scheme(
self, check_token, version_info):
version_info.return_value = (2, 7, 3)
check_token.return_value = {
'host': 'node1',
'port': '10000',
'console_type': 'novnc'
}
self.wh.socket.return_value = '<socket>'
self.wh.path = "ws://127.0.0.1/?token=123-456-789"
self.wh.headers.getheader = self._fake_getheader
self.assertRaises(exception.NovaException,
self.wh.new_websocket_client)
@mock.patch('socket.getfqdn')
def test_address_string_doesnt_do_reverse_dns_lookup(self, getfqdn):
request_mock = mock.MagicMock()
request_mock.makefile().readline.side_effect = [
'GET /vnc.html?token=123-456-789 HTTP/1.1\r\n',
''
]
server_mock = mock.MagicMock()
client_address = ('8.8.8.8', 54321)
handler = websocketproxy.NovaProxyRequestHandler(
request_mock, client_address, server_mock)
handler.log_message('log message using client address context info')
self.assertFalse(getfqdn.called) # no reverse dns look up
self.assertEqual(handler.address_string(), '8.8.8.8') # plain address
@mock.patch('nova.consoleauth.rpcapi.ConsoleAuthAPI.check_token')
def test_new_websocket_client_novnc_bad_origin_header(self, check_token):
check_token.return_value = {
'host': 'node1',
'port': '10000',
'console_type': 'novnc'
}
self.wh.path = "http://127.0.0.1/"
self.wh.headers.getheader = self._fake_getheader_bad_origin
self.assertRaises(exception.ValidationError,
self.wh.new_websocket_client)
@mock.patch('nova.consoleauth.rpcapi.ConsoleAuthAPI.check_token')
def test_new_websocket_client_novnc_blank_origin_header(self, check_token):
check_token.return_value = {
'host': 'node1',
'port': '10000',
'console_type': 'novnc'
}
self.wh.path = "http://127.0.0.1/"
self.wh.headers.getheader = self._fake_getheader_blank_origin
self.assertRaises(exception.ValidationError,
self.wh.new_websocket_client)
@mock.patch('nova.consoleauth.rpcapi.ConsoleAuthAPI.check_token')
def test_new_websocket_client_novnc_no_origin_header(self, check_token):
check_token.return_value = {
'host': 'node1',
'port': '10000',
'console_type': 'novnc'
}
self.wh.socket.return_value = '<socket>'
self.wh.path = "http://127.0.0.1/"
self.wh.headers.getheader = self._fake_getheader_no_origin
self.wh.new_websocket_client()
check_token.assert_called_with(mock.ANY, token="123-456-789")
self.wh.socket.assert_called_with('node1', 10000, connect=True)
self.wh.do_proxy.assert_called_with('<socket>')
@mock.patch('nova.consoleauth.rpcapi.ConsoleAuthAPI.check_token')
def test_new_websocket_client_novnc_https_origin_proto_http(self,
check_token):
check_token.return_value = {
'host': 'node1',
'port': '10000',
'console_type': 'novnc',
'access_url': 'http://example.net:6080'
}
self.wh.path = "https://127.0.0.1/"
self.wh.headers.getheader = self._fake_getheader
self.assertRaises(exception.ValidationError,
self.wh.new_websocket_client)
@mock.patch('nova.consoleauth.rpcapi.ConsoleAuthAPI.check_token')
def test_new_websocket_client_novnc_https_origin_proto_ws(self,
check_token):
check_token.return_value = {
'host': 'node1',
'port': '10000',
'console_type': 'serial',
'access_url': 'ws://example.net:6080'
}
self.wh.path = "https://127.0.0.1/"
self.wh.headers.getheader = self._fake_getheader
self.assertRaises(exception.ValidationError,
self.wh.new_websocket_client)
@mock.patch('nova.consoleauth.rpcapi.ConsoleAuthAPI.check_token')
def test_new_websocket_client_novnc_bad_console_type(self, check_token):
check_token.return_value = {
'host': 'node1',
'port': '10000',
'console_type': 'bad-console-type'
}
self.wh.path = "http://127.0.0.1/"
self.wh.headers.getheader = self._fake_getheader
self.assertRaises(exception.ValidationError,
self.wh.new_websocket_client)
|
apache-2.0
|
[
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
624,
2925,
367,
5913,
24897,
3280,
1041,
421,
199,
646,
1683,
199,
199,
504,
5913,
14,
6614,
492,
24897,
3280,
199,
504,
5913,
492,
1919,
199,
504,
5913,
492,
511,
199,
504,
11258,
63,
888,
492,
4810,
199,
199,
3103,
275,
4810,
14,
3103,
421,
199,
533,
28184,
4936,
11149,
20760,
8,
396,
14,
32437,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
19884,
4936,
11149,
20760,
12,
291,
680,
5996,
342,
398,
291,
14,
2191,
275,
24897,
3280,
14,
19884,
4936,
11149,
1563,
342,
267,
291,
14,
2191,
14,
3450,
275,
1683,
14,
11988,
342,
267,
291,
14,
2191,
14,
1328,
275,
1683,
14,
11988,
342,
267,
291,
14,
2191,
14,
1117,
63,
3280,
275,
1683,
14,
11988,
342,
267,
291,
14,
2191,
14,
2139,
275,
1683,
14,
11988,
342,
339,
347,
485,
3183,
63,
19958,
8,
277,
12,
1406,
304,
267,
340,
1406,
508,
283,
5306,
356,
288,
372,
283,
1418,
628,
4288,
13,
11419,
13,
24407,
4507,
267,
916,
1406,
508,
283,
12834,
356,
288,
372,
283,
2859,
921,
2694,
14,
846,
26,
2259,
1257,
7,
267,
916,
1406,
508,
283,
4965,
356,
288,
372,
283,
2694,
14,
846,
26,
2259,
1257,
7,
267,
587,
26,
288,
372,
339,
347,
485,
3183,
63,
19958,
63,
4774,
22,
8,
277,
12,
1406,
304,
267,
340,
1406,
508,
283,
5306,
356,
288,
372,
283,
1418,
628,
4288,
13,
11419,
13,
24407,
4507,
267,
916,
1406,
508,
283,
12834,
356,
288,
372,
283,
2859,
921,
59,
8339,
26,
697,
24,
447,
17,
2189,
2259,
1257,
7,
267,
916,
1406,
508,
283,
4965,
356,
288,
372,
6730,
8339,
26,
697,
24,
447,
17,
2189,
2259,
1257,
7,
267,
587,
26,
288,
372,
339,
347,
485,
3183,
63,
19958,
63,
4087,
63,
1418,
8,
277,
12,
1406,
304,
267,
340,
1406,
508,
283,
5306,
356,
288,
372,
283,
1418,
628,
13933,
4507,
267,
916,
1406,
508,
283,
12834,
356,
288,
372,
283,
2859,
921,
2694,
14,
846,
26,
2259,
1257,
7,
267,
916,
1406,
508,
283,
4965,
356,
288,
372,
283,
2694,
14,
846,
26,
2259,
1257,
7,
267,
587,
26,
288,
372,
339,
347,
485,
3183,
63,
19958,
63,
4087,
63,
6493,
8,
277,
12,
1406,
304,
267,
340,
1406,
508,
283,
5306,
356,
288,
372,
283,
1418,
628,
4288,
13,
11419,
13,
24407,
4507,
267,
916,
1406,
508,
283,
12834,
356,
288,
372,
283,
2859,
921,
4087,
13,
6493,
13,
2694,
14,
846,
26,
2259,
1257,
7,
267,
916,
1406,
508,
283,
4965,
356,
288,
372,
283,
2694,
14,
846,
26,
2259,
1257,
7,
267,
587,
26,
288,
372,
339,
347,
485,
3183,
63,
19958,
63,
2500,
63,
6493,
8,
277,
12,
1406,
304,
267,
340,
1406,
508,
283,
5306,
356,
288,
372,
283,
1418,
628,
4288,
13,
11419,
13,
24407,
4507,
267,
916,
1406,
508,
283,
12834,
356,
288,
372,
2125,
267,
916,
1406,
508,
283,
4965,
356,
288,
372,
283,
2694,
14,
846,
26,
2259,
1257,
7,
267,
587,
26,
288,
372,
339,
347,
485,
3183,
63,
19958,
63,
889,
63,
6493,
8,
277,
12,
1406,
304,
267,
340,
1406,
508,
283,
5306,
356,
288,
372,
283,
1418,
628,
4288,
13,
11419,
13,
24407,
4507,
267,
916,
1406,
508,
283,
12834,
356,
288,
372,
488,
267,
916,
1406,
508,
283,
4965,
356,
288,
372,
283,
1629,
13,
2694,
14,
846,
26,
2259,
1257,
7,
267,
587,
26,
288,
372,
339,
347,
485,
3183,
63,
19958,
63,
1014,
8,
277,
12,
1406,
304,
267,
340,
1406,
508,
283,
5306,
356,
288,
372,
283,
1418,
628,
4288,
13,
11419,
13,
24407,
4507,
267,
916,
1406,
508,
283,
12834,
356,
288,
372,
283,
1014,
921,
2694,
14,
846,
26,
2259,
1257,
7,
267,
916,
1406,
508,
283,
4965,
356,
288,
372,
283,
2694,
14,
846,
26,
2259,
1257,
7,
267,
587,
26,
288,
372,
339,
768,
1805,
14,
2068,
360,
6765,
14,
6614,
1178,
14,
20776,
14,
9270,
2817,
3735,
14,
1074,
63,
1418,
358,
272,
347,
511,
63,
1222,
63,
13508,
63,
1258,
8,
277,
12,
1104,
63,
1418,
304,
267,
1104,
63,
1418,
14,
1107,
63,
585,
275,
469,
288,
283,
1102,
356,
283,
932,
17,
297,
288,
283,
719,
356,
283,
9943,
297,
288,
283,
6614,
63,
466,
356,
283,
889,
24093,
297,
288,
283,
2732,
63,
633,
356,
283,
2859,
921,
2694,
14,
846,
26,
2259,
1257,
7,
267,
789,
267,
291,
14,
2191,
14,
3450,
14,
1107,
63,
585,
275,
2650,
3450,
3524,
267,
291,
14,
2191,
14,
515,
275,
298,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
10197,
1418,
29,
4288,
13,
11419,
13,
24407,
2,
267,
291,
14,
2191,
14,
2139,
14,
19958,
275,
291,
423,
3183,
63,
19958,
398,
291,
14,
2191,
14,
1222,
63,
13508,
63,
1258,
342,
398,
1104,
63,
1418,
14,
479,
63,
3527,
63,
1045,
8,
1805,
14,
8974,
12,
1526,
628,
4288,
13,
11419,
13,
24407,
531,
267,
291,
14,
2191,
14,
3450,
14,
479,
63,
3527,
63,
1045,
360,
932,
17,
297,
11630,
12,
4907,
29,
549,
9,
267,
291,
14,
2191,
14,
1117,
63,
3280,
14,
479,
63,
3527,
63,
1045,
4827,
3450,
5971,
339,
768,
1805,
14,
2068,
360,
6765,
14,
6614,
1178,
14,
20776,
14,
9270,
2817,
3735,
14,
1074,
63,
1418,
358,
272,
347,
511,
63,
1222
] |
[
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
624,
2925,
367,
5913,
24897,
3280,
1041,
421,
199,
646,
1683,
199,
199,
504,
5913,
14,
6614,
492,
24897,
3280,
199,
504,
5913,
492,
1919,
199,
504,
5913,
492,
511,
199,
504,
11258,
63,
888,
492,
4810,
199,
199,
3103,
275,
4810,
14,
3103,
421,
199,
533,
28184,
4936,
11149,
20760,
8,
396,
14,
32437,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
19884,
4936,
11149,
20760,
12,
291,
680,
5996,
342,
398,
291,
14,
2191,
275,
24897,
3280,
14,
19884,
4936,
11149,
1563,
342,
267,
291,
14,
2191,
14,
3450,
275,
1683,
14,
11988,
342,
267,
291,
14,
2191,
14,
1328,
275,
1683,
14,
11988,
342,
267,
291,
14,
2191,
14,
1117,
63,
3280,
275,
1683,
14,
11988,
342,
267,
291,
14,
2191,
14,
2139,
275,
1683,
14,
11988,
342,
339,
347,
485,
3183,
63,
19958,
8,
277,
12,
1406,
304,
267,
340,
1406,
508,
283,
5306,
356,
288,
372,
283,
1418,
628,
4288,
13,
11419,
13,
24407,
4507,
267,
916,
1406,
508,
283,
12834,
356,
288,
372,
283,
2859,
921,
2694,
14,
846,
26,
2259,
1257,
7,
267,
916,
1406,
508,
283,
4965,
356,
288,
372,
283,
2694,
14,
846,
26,
2259,
1257,
7,
267,
587,
26,
288,
372,
339,
347,
485,
3183,
63,
19958,
63,
4774,
22,
8,
277,
12,
1406,
304,
267,
340,
1406,
508,
283,
5306,
356,
288,
372,
283,
1418,
628,
4288,
13,
11419,
13,
24407,
4507,
267,
916,
1406,
508,
283,
12834,
356,
288,
372,
283,
2859,
921,
59,
8339,
26,
697,
24,
447,
17,
2189,
2259,
1257,
7,
267,
916,
1406,
508,
283,
4965,
356,
288,
372,
6730,
8339,
26,
697,
24,
447,
17,
2189,
2259,
1257,
7,
267,
587,
26,
288,
372,
339,
347,
485,
3183,
63,
19958,
63,
4087,
63,
1418,
8,
277,
12,
1406,
304,
267,
340,
1406,
508,
283,
5306,
356,
288,
372,
283,
1418,
628,
13933,
4507,
267,
916,
1406,
508,
283,
12834,
356,
288,
372,
283,
2859,
921,
2694,
14,
846,
26,
2259,
1257,
7,
267,
916,
1406,
508,
283,
4965,
356,
288,
372,
283,
2694,
14,
846,
26,
2259,
1257,
7,
267,
587,
26,
288,
372,
339,
347,
485,
3183,
63,
19958,
63,
4087,
63,
6493,
8,
277,
12,
1406,
304,
267,
340,
1406,
508,
283,
5306,
356,
288,
372,
283,
1418,
628,
4288,
13,
11419,
13,
24407,
4507,
267,
916,
1406,
508,
283,
12834,
356,
288,
372,
283,
2859,
921,
4087,
13,
6493,
13,
2694,
14,
846,
26,
2259,
1257,
7,
267,
916,
1406,
508,
283,
4965,
356,
288,
372,
283,
2694,
14,
846,
26,
2259,
1257,
7,
267,
587,
26,
288,
372,
339,
347,
485,
3183,
63,
19958,
63,
2500,
63,
6493,
8,
277,
12,
1406,
304,
267,
340,
1406,
508,
283,
5306,
356,
288,
372,
283,
1418,
628,
4288,
13,
11419,
13,
24407,
4507,
267,
916,
1406,
508,
283,
12834,
356,
288,
372,
2125,
267,
916,
1406,
508,
283,
4965,
356,
288,
372,
283,
2694,
14,
846,
26,
2259,
1257,
7,
267,
587,
26,
288,
372,
339,
347,
485,
3183,
63,
19958,
63,
889,
63,
6493,
8,
277,
12,
1406,
304,
267,
340,
1406,
508,
283,
5306,
356,
288,
372,
283,
1418,
628,
4288,
13,
11419,
13,
24407,
4507,
267,
916,
1406,
508,
283,
12834,
356,
288,
372,
488,
267,
916,
1406,
508,
283,
4965,
356,
288,
372,
283,
1629,
13,
2694,
14,
846,
26,
2259,
1257,
7,
267,
587,
26,
288,
372,
339,
347,
485,
3183,
63,
19958,
63,
1014,
8,
277,
12,
1406,
304,
267,
340,
1406,
508,
283,
5306,
356,
288,
372,
283,
1418,
628,
4288,
13,
11419,
13,
24407,
4507,
267,
916,
1406,
508,
283,
12834,
356,
288,
372,
283,
1014,
921,
2694,
14,
846,
26,
2259,
1257,
7,
267,
916,
1406,
508,
283,
4965,
356,
288,
372,
283,
2694,
14,
846,
26,
2259,
1257,
7,
267,
587,
26,
288,
372,
339,
768,
1805,
14,
2068,
360,
6765,
14,
6614,
1178,
14,
20776,
14,
9270,
2817,
3735,
14,
1074,
63,
1418,
358,
272,
347,
511,
63,
1222,
63,
13508,
63,
1258,
8,
277,
12,
1104,
63,
1418,
304,
267,
1104,
63,
1418,
14,
1107,
63,
585,
275,
469,
288,
283,
1102,
356,
283,
932,
17,
297,
288,
283,
719,
356,
283,
9943,
297,
288,
283,
6614,
63,
466,
356,
283,
889,
24093,
297,
288,
283,
2732,
63,
633,
356,
283,
2859,
921,
2694,
14,
846,
26,
2259,
1257,
7,
267,
789,
267,
291,
14,
2191,
14,
3450,
14,
1107,
63,
585,
275,
2650,
3450,
3524,
267,
291,
14,
2191,
14,
515,
275,
298,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
10197,
1418,
29,
4288,
13,
11419,
13,
24407,
2,
267,
291,
14,
2191,
14,
2139,
14,
19958,
275,
291,
423,
3183,
63,
19958,
398,
291,
14,
2191,
14,
1222,
63,
13508,
63,
1258,
342,
398,
1104,
63,
1418,
14,
479,
63,
3527,
63,
1045,
8,
1805,
14,
8974,
12,
1526,
628,
4288,
13,
11419,
13,
24407,
531,
267,
291,
14,
2191,
14,
3450,
14,
479,
63,
3527,
63,
1045,
360,
932,
17,
297,
11630,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
maciekcc/tensorflow
|
tensorflow/python/estimator/canned/parsing_utils_test.py
|
74
|
8522
|
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for parsing_utils.py."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.python.estimator.canned import parsing_utils
from tensorflow.python.feature_column import feature_column as fc
from tensorflow.python.framework import dtypes
from tensorflow.python.ops import parsing_ops
from tensorflow.python.platform import test
class ClassifierParseExampleSpec(test.TestCase):
"""Tests tf.estimator.classifier_parse_example_spec."""
def test_defaults(self):
parsing_spec = parsing_utils.classifier_parse_example_spec(
feature_columns=[fc.numeric_column('a')], label_key='b')
expected_spec = {
'a': parsing_ops.FixedLenFeature((1,), dtype=dtypes.float32),
'b': parsing_ops.FixedLenFeature((1,), dtype=dtypes.int64),
}
self.assertDictEqual(expected_spec, parsing_spec)
def test_string(self):
parsing_spec = parsing_utils.classifier_parse_example_spec(
feature_columns=[fc.numeric_column('a')],
label_key='b',
label_dtype=dtypes.string)
expected_spec = {
'a': parsing_ops.FixedLenFeature((1,), dtype=dtypes.float32),
'b': parsing_ops.FixedLenFeature((1,), dtype=dtypes.string),
}
self.assertDictEqual(expected_spec, parsing_spec)
# TODO(ispir): test label_default_value compatibility with label_dtype
def test_label_default_value(self):
parsing_spec = parsing_utils.classifier_parse_example_spec(
feature_columns=[fc.numeric_column('a')],
label_key='b',
label_default=0)
expected_spec = {
'a':
parsing_ops.FixedLenFeature((1,), dtype=dtypes.float32),
'b':
parsing_ops.FixedLenFeature(
(1,), dtype=dtypes.int64, default_value=0),
}
self.assertDictEqual(expected_spec, parsing_spec)
def test_weight_column_as_string(self):
parsing_spec = parsing_utils.classifier_parse_example_spec(
feature_columns=[fc.numeric_column('a')],
label_key='b',
weight_column='c')
expected_spec = {
'a': parsing_ops.FixedLenFeature((1,), dtype=dtypes.float32),
'b': parsing_ops.FixedLenFeature((1,), dtype=dtypes.int64),
'c': parsing_ops.FixedLenFeature((1,), dtype=dtypes.float32),
}
self.assertDictEqual(expected_spec, parsing_spec)
def test_weight_column_as_numeric_column(self):
parsing_spec = parsing_utils.classifier_parse_example_spec(
feature_columns=[fc.numeric_column('a')],
label_key='b',
weight_column=fc.numeric_column('c'))
expected_spec = {
'a': parsing_ops.FixedLenFeature((1,), dtype=dtypes.float32),
'b': parsing_ops.FixedLenFeature((1,), dtype=dtypes.int64),
'c': parsing_ops.FixedLenFeature((1,), dtype=dtypes.float32),
}
self.assertDictEqual(expected_spec, parsing_spec)
def test_label_key_should_not_be_used_as_feature(self):
with self.assertRaisesRegexp(ValueError,
'label should not be used as feature'):
parsing_utils.classifier_parse_example_spec(
feature_columns=[fc.numeric_column('a')], label_key='a')
def test_weight_column_should_not_be_used_as_feature(self):
with self.assertRaisesRegexp(ValueError,
'weight_column should not be used as feature'):
parsing_utils.classifier_parse_example_spec(
feature_columns=[fc.numeric_column('a')],
label_key='b',
weight_column=fc.numeric_column('a'))
def test_weight_column_should_be_a_numeric_column(self):
with self.assertRaisesRegexp(ValueError,
'tf.feature_column.numeric_column'):
not_a_numeric_column = 3
parsing_utils.classifier_parse_example_spec(
feature_columns=[fc.numeric_column('a')],
label_key='b',
weight_column=not_a_numeric_column)
class RegressorParseExampleSpec(test.TestCase):
"""Tests tf.estimator.classifier_parse_example_spec."""
def test_defaults(self):
parsing_spec = parsing_utils.regressor_parse_example_spec(
feature_columns=[fc.numeric_column('a')], label_key='b')
expected_spec = {
'a': parsing_ops.FixedLenFeature((1,), dtype=dtypes.float32),
'b': parsing_ops.FixedLenFeature((1,), dtype=dtypes.float32),
}
self.assertDictEqual(expected_spec, parsing_spec)
def test_int64(self):
parsing_spec = parsing_utils.regressor_parse_example_spec(
feature_columns=[fc.numeric_column('a')],
label_key='b',
label_dtype=dtypes.int64)
expected_spec = {
'a': parsing_ops.FixedLenFeature((1,), dtype=dtypes.float32),
'b': parsing_ops.FixedLenFeature((1,), dtype=dtypes.int64),
}
self.assertDictEqual(expected_spec, parsing_spec)
def test_label_default_value(self):
parsing_spec = parsing_utils.regressor_parse_example_spec(
feature_columns=[fc.numeric_column('a')],
label_key='b',
label_default=0.)
expected_spec = {
'a':
parsing_ops.FixedLenFeature((1,), dtype=dtypes.float32),
'b':
parsing_ops.FixedLenFeature(
(1,), dtype=dtypes.float32, default_value=0.),
}
self.assertDictEqual(expected_spec, parsing_spec)
def test_label_dimension(self):
parsing_spec = parsing_utils.regressor_parse_example_spec(
feature_columns=[fc.numeric_column('a')],
label_key='b',
label_dimension=3)
expected_spec = {
'a': parsing_ops.FixedLenFeature((1,), dtype=dtypes.float32),
'b': parsing_ops.FixedLenFeature((3,), dtype=dtypes.float32),
}
self.assertDictEqual(expected_spec, parsing_spec)
def test_weight_column_as_string(self):
parsing_spec = parsing_utils.regressor_parse_example_spec(
feature_columns=[fc.numeric_column('a')],
label_key='b',
weight_column='c')
expected_spec = {
'a': parsing_ops.FixedLenFeature((1,), dtype=dtypes.float32),
'b': parsing_ops.FixedLenFeature((1,), dtype=dtypes.float32),
'c': parsing_ops.FixedLenFeature((1,), dtype=dtypes.float32),
}
self.assertDictEqual(expected_spec, parsing_spec)
def test_weight_column_as_numeric_column(self):
parsing_spec = parsing_utils.regressor_parse_example_spec(
feature_columns=[fc.numeric_column('a')],
label_key='b',
weight_column=fc.numeric_column('c'))
expected_spec = {
'a': parsing_ops.FixedLenFeature((1,), dtype=dtypes.float32),
'b': parsing_ops.FixedLenFeature((1,), dtype=dtypes.float32),
'c': parsing_ops.FixedLenFeature((1,), dtype=dtypes.float32),
}
self.assertDictEqual(expected_spec, parsing_spec)
def test_label_key_should_not_be_used_as_feature(self):
with self.assertRaisesRegexp(ValueError,
'label should not be used as feature'):
parsing_utils.regressor_parse_example_spec(
feature_columns=[fc.numeric_column('a')], label_key='a')
def test_weight_column_should_not_be_used_as_feature(self):
with self.assertRaisesRegexp(ValueError,
'weight_column should not be used as feature'):
parsing_utils.regressor_parse_example_spec(
feature_columns=[fc.numeric_column('a')],
label_key='b',
weight_column=fc.numeric_column('a'))
def test_weight_column_should_be_a_numeric_column(self):
with self.assertRaisesRegexp(ValueError,
'tf.feature_column.numeric_column'):
not_a_numeric_column = 3
parsing_utils.regressor_parse_example_spec(
feature_columns=[fc.numeric_column('a')],
label_key='b',
weight_column=not_a_numeric_column)
if __name__ == '__main__':
test.main()
|
apache-2.0
|
[
3,
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
6057,
63,
1208,
14,
647,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
8627,
14,
31126,
492,
6057,
63,
1208,
199,
504,
3228,
14,
1548,
14,
4445,
63,
2301,
492,
3878,
63,
2301,
465,
10821,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
1483,
492,
6057,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
8465,
5541,
4003,
9846,
5307,
8,
396,
14,
1746,
304,
523,
408,
2925,
2833,
14,
8627,
14,
14720,
63,
1122,
63,
2694,
63,
1650,
1041,
819,
347,
511,
63,
4322,
8,
277,
304,
272,
6057,
63,
1650,
275,
6057,
63,
1208,
14,
14720,
63,
1122,
63,
2694,
63,
1650,
8,
267,
3878,
63,
3406,
1524,
3003,
14,
6677,
63,
2301,
360,
65,
2665,
1768,
63,
498,
534,
66,
358,
272,
1420,
63,
1650,
275,
469,
267,
283,
65,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
1609,
708,
395,
267,
283,
66,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
442,
772,
395,
272,
789,
272,
291,
14,
19512,
8,
2062,
63,
1650,
12,
6057,
63,
1650,
9,
819,
347,
511,
63,
875,
8,
277,
304,
272,
6057,
63,
1650,
275,
6057,
63,
1208,
14,
14720,
63,
1122,
63,
2694,
63,
1650,
8,
267,
3878,
63,
3406,
1524,
3003,
14,
6677,
63,
2301,
360,
65,
2665,
267,
1768,
63,
498,
534,
66,
297,
267,
1768,
63,
2271,
29,
5717,
14,
875,
9,
272,
1420,
63,
1650,
275,
469,
267,
283,
65,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
1609,
708,
395,
267,
283,
66,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
875,
395,
272,
789,
272,
291,
14,
19512,
8,
2062,
63,
1650,
12,
6057,
63,
1650,
9,
819,
327,
3254,
8,
27474,
723,
304,
511,
1768,
63,
885,
63,
585,
7163,
543,
1768,
63,
2271,
523,
347,
511,
63,
1302,
63,
885,
63,
585,
8,
277,
304,
272,
6057,
63,
1650,
275,
6057,
63,
1208,
14,
14720,
63,
1122,
63,
2694,
63,
1650,
8,
267,
3878,
63,
3406,
1524,
3003,
14,
6677,
63,
2301,
360,
65,
2665,
267,
1768,
63,
498,
534,
66,
297,
267,
1768,
63,
885,
29,
16,
9,
272,
1420,
63,
1650,
275,
469,
267,
283,
65,
356,
288,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
1609,
708,
395,
267,
283,
66,
356,
288,
6057,
63,
1483,
14,
9515,
28556,
8,
355,
334,
17,
4706,
2152,
29,
5717,
14,
442,
772,
12,
849,
63,
585,
29,
16,
395,
272,
789,
272,
291,
14,
19512,
8,
2062,
63,
1650,
12,
6057,
63,
1650,
9,
819,
347,
511,
63,
3463,
63,
2301,
63,
305,
63,
875,
8,
277,
304,
272,
6057,
63,
1650,
275,
6057,
63,
1208,
14,
14720,
63,
1122,
63,
2694,
63,
1650,
8,
267,
3878,
63,
3406,
1524,
3003,
14,
6677,
63,
2301,
360,
65,
2665,
267,
1768,
63,
498,
534,
66,
297,
267,
5401,
63,
2301,
534,
67,
358,
272,
1420,
63,
1650,
275,
469,
267,
283,
65,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
1609,
708,
395,
267,
283,
66,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
442,
772,
395,
267,
283,
67,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
1609,
708,
395,
272,
789,
272,
291,
14,
19512,
8,
2062,
63,
1650,
12,
6057,
63,
1650,
9,
819,
347,
511,
63,
3463,
63,
2301,
63,
305,
63,
6677,
63,
2301,
8,
277,
304,
272,
6057,
63,
1650,
275,
6057,
63,
1208,
14,
14720,
63,
1122,
63,
2694,
63,
1650,
8,
267,
3878,
63,
3406,
1524,
3003,
14,
6677,
63,
2301,
360,
65,
2665,
267,
1768,
63,
498,
534,
66,
297,
267,
5401,
63,
2301,
29,
3003,
14,
6677,
63,
2301,
360,
67,
1333,
272,
1420,
63,
1650,
275,
469,
267,
283,
65,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
1609,
708,
395,
267,
283,
66,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
442,
772,
395,
267,
283,
67,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
1609,
708,
395,
272,
789,
272,
291,
14,
19512,
8,
2062,
63,
1650,
12,
6057,
63,
1650,
9,
819,
347,
511,
63,
1302,
63,
498,
63,
5626,
63,
1397,
63,
1235,
63,
2972,
63,
305,
63,
4445,
8,
277,
304,
272,
543,
291,
14,
10835,
8,
3393,
12,
639,
283,
1302,
1077,
440,
506,
1202,
465,
3878,
735,
489,
6057,
63,
1208,
14,
14720,
63,
1122,
63,
2694,
63,
1650,
8,
881,
3878,
63,
3406,
1524,
3003,
14,
6677,
63,
2301,
360,
65,
2665,
1768,
63,
498,
534,
65,
358,
819,
347,
511,
63,
3463,
63,
2301,
63,
5626,
63,
1397,
63,
1235,
63,
2972,
63,
305,
63,
4445,
8,
277,
304,
272,
543,
291,
14,
10835,
8,
3393,
12,
639,
283,
3463,
63,
2301
] |
[
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
6057,
63,
1208,
14,
647,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
8627,
14,
31126,
492,
6057,
63,
1208,
199,
504,
3228,
14,
1548,
14,
4445,
63,
2301,
492,
3878,
63,
2301,
465,
10821,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
1483,
492,
6057,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
8465,
5541,
4003,
9846,
5307,
8,
396,
14,
1746,
304,
523,
408,
2925,
2833,
14,
8627,
14,
14720,
63,
1122,
63,
2694,
63,
1650,
1041,
819,
347,
511,
63,
4322,
8,
277,
304,
272,
6057,
63,
1650,
275,
6057,
63,
1208,
14,
14720,
63,
1122,
63,
2694,
63,
1650,
8,
267,
3878,
63,
3406,
1524,
3003,
14,
6677,
63,
2301,
360,
65,
2665,
1768,
63,
498,
534,
66,
358,
272,
1420,
63,
1650,
275,
469,
267,
283,
65,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
1609,
708,
395,
267,
283,
66,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
442,
772,
395,
272,
789,
272,
291,
14,
19512,
8,
2062,
63,
1650,
12,
6057,
63,
1650,
9,
819,
347,
511,
63,
875,
8,
277,
304,
272,
6057,
63,
1650,
275,
6057,
63,
1208,
14,
14720,
63,
1122,
63,
2694,
63,
1650,
8,
267,
3878,
63,
3406,
1524,
3003,
14,
6677,
63,
2301,
360,
65,
2665,
267,
1768,
63,
498,
534,
66,
297,
267,
1768,
63,
2271,
29,
5717,
14,
875,
9,
272,
1420,
63,
1650,
275,
469,
267,
283,
65,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
1609,
708,
395,
267,
283,
66,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
875,
395,
272,
789,
272,
291,
14,
19512,
8,
2062,
63,
1650,
12,
6057,
63,
1650,
9,
819,
327,
3254,
8,
27474,
723,
304,
511,
1768,
63,
885,
63,
585,
7163,
543,
1768,
63,
2271,
523,
347,
511,
63,
1302,
63,
885,
63,
585,
8,
277,
304,
272,
6057,
63,
1650,
275,
6057,
63,
1208,
14,
14720,
63,
1122,
63,
2694,
63,
1650,
8,
267,
3878,
63,
3406,
1524,
3003,
14,
6677,
63,
2301,
360,
65,
2665,
267,
1768,
63,
498,
534,
66,
297,
267,
1768,
63,
885,
29,
16,
9,
272,
1420,
63,
1650,
275,
469,
267,
283,
65,
356,
288,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
1609,
708,
395,
267,
283,
66,
356,
288,
6057,
63,
1483,
14,
9515,
28556,
8,
355,
334,
17,
4706,
2152,
29,
5717,
14,
442,
772,
12,
849,
63,
585,
29,
16,
395,
272,
789,
272,
291,
14,
19512,
8,
2062,
63,
1650,
12,
6057,
63,
1650,
9,
819,
347,
511,
63,
3463,
63,
2301,
63,
305,
63,
875,
8,
277,
304,
272,
6057,
63,
1650,
275,
6057,
63,
1208,
14,
14720,
63,
1122,
63,
2694,
63,
1650,
8,
267,
3878,
63,
3406,
1524,
3003,
14,
6677,
63,
2301,
360,
65,
2665,
267,
1768,
63,
498,
534,
66,
297,
267,
5401,
63,
2301,
534,
67,
358,
272,
1420,
63,
1650,
275,
469,
267,
283,
65,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
1609,
708,
395,
267,
283,
66,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
442,
772,
395,
267,
283,
67,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
1609,
708,
395,
272,
789,
272,
291,
14,
19512,
8,
2062,
63,
1650,
12,
6057,
63,
1650,
9,
819,
347,
511,
63,
3463,
63,
2301,
63,
305,
63,
6677,
63,
2301,
8,
277,
304,
272,
6057,
63,
1650,
275,
6057,
63,
1208,
14,
14720,
63,
1122,
63,
2694,
63,
1650,
8,
267,
3878,
63,
3406,
1524,
3003,
14,
6677,
63,
2301,
360,
65,
2665,
267,
1768,
63,
498,
534,
66,
297,
267,
5401,
63,
2301,
29,
3003,
14,
6677,
63,
2301,
360,
67,
1333,
272,
1420,
63,
1650,
275,
469,
267,
283,
65,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
1609,
708,
395,
267,
283,
66,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
442,
772,
395,
267,
283,
67,
356,
6057,
63,
1483,
14,
9515,
28556,
1332,
17,
4706,
2152,
29,
5717,
14,
1609,
708,
395,
272,
789,
272,
291,
14,
19512,
8,
2062,
63,
1650,
12,
6057,
63,
1650,
9,
819,
347,
511,
63,
1302,
63,
498,
63,
5626,
63,
1397,
63,
1235,
63,
2972,
63,
305,
63,
4445,
8,
277,
304,
272,
543,
291,
14,
10835,
8,
3393,
12,
639,
283,
1302,
1077,
440,
506,
1202,
465,
3878,
735,
489,
6057,
63,
1208,
14,
14720,
63,
1122,
63,
2694,
63,
1650,
8,
881,
3878,
63,
3406,
1524,
3003,
14,
6677,
63,
2301,
360,
65,
2665,
1768,
63,
498,
534,
65,
358,
819,
347,
511,
63,
3463,
63,
2301,
63,
5626,
63,
1397,
63,
1235,
63,
2972,
63,
305,
63,
4445,
8,
277,
304,
272,
543,
291,
14,
10835,
8,
3393,
12,
639,
283,
3463,
63,
2301,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
a-veitch/grpc
|
tools/buildgen/bunch.py
|
44
|
2469
|
# Copyright 2015, 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.
"""Allows dot-accessible dictionaries."""
class Bunch(dict):
def __init__(self, d):
dict.__init__(self, d)
self.__dict__.update(d)
# Converts any kind of variable to a Bunch
def to_bunch(var):
if isinstance(var, list):
return [to_bunch(i) for i in var]
if isinstance(var, dict):
ret = {}
for k, v in var.items():
if isinstance(v, (list, dict)):
v = to_bunch(v)
ret[k] = v
return Bunch(ret)
else:
return var
# Merges JSON 'add' into JSON 'dst'
def merge_json(dst, add):
if isinstance(dst, dict) and isinstance(add, dict):
for k, v in add.items():
if k in dst:
if k == '#': continue
merge_json(dst[k], v)
else:
dst[k] = v
elif isinstance(dst, list) and isinstance(add, list):
dst.extend(add)
else:
raise Exception('Tried to merge incompatible objects %s %s\n\n%r\n\n%r' % (type(dst).__name__, type(add).__name__, dst, add))
|
bsd-3-clause
|
[
3,
1898,
6900,
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,
19780,
6308,
13,
24669,
11196,
1041,
421,
199,
533,
699,
4689,
8,
807,
304,
819,
347,
636,
826,
721,
277,
12,
366,
304,
272,
1211,
855,
826,
721,
277,
12,
366,
9,
272,
291,
855,
807,
4343,
873,
8,
68,
9,
421,
199,
3,
19107,
1263,
4928,
402,
1750,
370,
282,
699,
4689,
199,
318,
370,
63,
66,
4689,
8,
1391,
304,
523,
340,
1228,
8,
1391,
12,
769,
304,
272,
372,
359,
475,
63,
66,
4689,
8,
73,
9,
367,
284,
315,
2729,
61,
523,
340,
1228,
8,
1391,
12,
1211,
304,
272,
2203,
275,
1052,
272,
367,
1022,
12,
373,
315,
2729,
14,
1744,
837,
489,
340,
1228,
8,
86,
12,
334,
513,
12,
1211,
2298,
267,
373,
275,
370,
63,
66,
4689,
8,
86,
9,
489,
2203,
59,
75,
61,
275,
373,
272,
372,
699,
4689,
8,
3292,
9,
523,
587,
26,
272,
372,
2729,
421,
199,
3,
18880,
3389,
4840,
283,
525,
7,
1901,
4840,
283,
5119,
7,
199,
318,
5389,
63,
1001,
8,
5119,
12,
1050,
304,
523,
340,
1228,
8,
5119,
12,
1211,
9,
436,
1228,
8,
525,
12,
1211,
304,
272,
367,
1022,
12,
373,
315,
1050,
14,
1744,
837,
489,
340,
1022,
315,
5042,
26,
267,
340,
1022,
508,
32326,
1980,
267,
5389,
63,
1001,
8,
5119,
59,
75,
467,
373,
9,
489,
587,
26,
267,
5042,
59,
75,
61,
275,
373,
523,
916,
1228,
8,
5119,
12,
769,
9,
436,
1228,
8,
525,
12,
769,
304,
272,
5042,
14,
2880,
8,
525,
9,
523,
587,
26,
272,
746,
2186,
360,
6948,
379,
370,
5389,
18457,
2251,
450,
83,
450,
83,
60,
78,
60,
78,
5,
82,
60,
78,
60,
78,
5,
82,
7,
450,
334,
466,
8,
5119,
2843,
354,
3108,
730,
8,
525,
2843,
354,
3108,
5042,
12,
1050,
430,
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
] |
[
1898,
6900,
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,
19780,
6308,
13,
24669,
11196,
1041,
421,
199,
533,
699,
4689,
8,
807,
304,
819,
347,
636,
826,
721,
277,
12,
366,
304,
272,
1211,
855,
826,
721,
277,
12,
366,
9,
272,
291,
855,
807,
4343,
873,
8,
68,
9,
421,
199,
3,
19107,
1263,
4928,
402,
1750,
370,
282,
699,
4689,
199,
318,
370,
63,
66,
4689,
8,
1391,
304,
523,
340,
1228,
8,
1391,
12,
769,
304,
272,
372,
359,
475,
63,
66,
4689,
8,
73,
9,
367,
284,
315,
2729,
61,
523,
340,
1228,
8,
1391,
12,
1211,
304,
272,
2203,
275,
1052,
272,
367,
1022,
12,
373,
315,
2729,
14,
1744,
837,
489,
340,
1228,
8,
86,
12,
334,
513,
12,
1211,
2298,
267,
373,
275,
370,
63,
66,
4689,
8,
86,
9,
489,
2203,
59,
75,
61,
275,
373,
272,
372,
699,
4689,
8,
3292,
9,
523,
587,
26,
272,
372,
2729,
421,
199,
3,
18880,
3389,
4840,
283,
525,
7,
1901,
4840,
283,
5119,
7,
199,
318,
5389,
63,
1001,
8,
5119,
12,
1050,
304,
523,
340,
1228,
8,
5119,
12,
1211,
9,
436,
1228,
8,
525,
12,
1211,
304,
272,
367,
1022,
12,
373,
315,
1050,
14,
1744,
837,
489,
340,
1022,
315,
5042,
26,
267,
340,
1022,
508,
32326,
1980,
267,
5389,
63,
1001,
8,
5119,
59,
75,
467,
373,
9,
489,
587,
26,
267,
5042,
59,
75,
61,
275,
373,
523,
916,
1228,
8,
5119,
12,
769,
9,
436,
1228,
8,
525,
12,
769,
304,
272,
5042,
14,
2880,
8,
525,
9,
523,
587,
26,
272,
746,
2186,
360,
6948,
379,
370,
5389,
18457,
2251,
450,
83,
450,
83,
60,
78,
60,
78,
5,
82,
60,
78,
60,
78,
5,
82,
7,
450,
334,
466,
8,
5119,
2843,
354,
3108,
730,
8,
525,
2843,
354,
3108,
5042,
12,
1050,
430,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
a10networks/a10sdk-python
|
a10sdk/core/A10_file/file_geo_location_oper.py
|
2
|
2101
|
from a10sdk.common.A10BaseClass import A10BaseClass
class FileList(A10BaseClass):
"""This class does not support CRUD Operations please use parent.
:param file: {"type": "string", "format": "string"}
:param DeviceProxy: The device proxy for REST operations and session handling. Refer to `common/device_proxy.py`
"""
def __init__(self, **kwargs):
self.ERROR_MSG = ""
self.b_key = "file-list"
self.DeviceProxy = ""
self.A10WW_file = ""
for keys, value in kwargs.items():
setattr(self,keys, value)
class Oper(A10BaseClass):
"""This class does not support CRUD Operations please use parent.
:param file_list: {"minItems": 1, "items": {"type": "object"}, "uniqueItems": true, "type": "array", "array": [{"properties": {"optional": true, "file": {"type": "string", "format": "string"}}}]}
:param DeviceProxy: The device proxy for REST operations and session handling. Refer to `common/device_proxy.py`
"""
def __init__(self, **kwargs):
self.ERROR_MSG = ""
self.b_key = "oper"
self.DeviceProxy = ""
self.file_list = []
for keys, value in kwargs.items():
setattr(self,keys, value)
class GeoLocation(A10BaseClass):
"""Class Description::
Operational Status for the object geo-location.
Class geo-location supports CRUD Operations and inherits from `common/A10BaseClass`.
This class is the `"PARENT"` class for this module.`
:param DeviceProxy: The device proxy for REST operations and session handling. Refer to `common/device_proxy.py`
URL for this object::
`https://<Hostname|Ip address>//axapi/v3/file/geo-location/oper`.
"""
def __init__(self, **kwargs):
self.ERROR_MSG = ""
self.required=[]
self.b_key = "geo-location"
self.a10_url="/axapi/v3/file/geo-location/oper"
self.DeviceProxy = ""
self.oper = {}
for keys, value in kwargs.items():
setattr(self,keys, value)
|
apache-2.0
|
[
504,
282,
709,
9277,
14,
2330,
14,
33,
709,
1563,
2543,
492,
437,
709,
1563,
2543,
421,
199,
533,
3814,
1296,
8,
33,
709,
1563,
2543,
304,
2286,
408,
2765,
1021,
1630,
440,
2291,
17101,
3383,
29474,
8749,
675,
1676,
14,
339,
520,
635,
570,
26,
2420,
466,
582,
298,
875,
401,
298,
908,
582,
298,
875,
3570,
272,
520,
635,
12272,
4936,
26,
710,
2243,
4566,
367,
14880,
5331,
436,
2351,
7252,
14,
21751,
370,
658,
2330,
15,
1782,
63,
3280,
14,
647,
64,
10813,
25979,
408,
272,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
291,
14,
3170,
63,
9740,
275,
3087,
2728,
291,
14,
66,
63,
498,
275,
298,
493,
13,
513,
2,
267,
291,
14,
2510,
4936,
275,
3087,
267,
291,
14,
33,
709,
11178,
63,
493,
275,
3087,
398,
367,
2883,
12,
574,
315,
2074,
14,
1744,
837,
288,
5371,
8,
277,
12,
1612,
12,
574,
9,
421,
199,
533,
6654,
8,
33,
709,
1563,
2543,
304,
2286,
408,
2765,
1021,
1630,
440,
2291,
17101,
3383,
29474,
8749,
675,
1676,
14,
339,
520,
635,
570,
63,
513,
26,
2420,
827,
7412,
582,
413,
12,
298,
1744,
582,
2420,
466,
582,
298,
785,
6018,
298,
3235,
7412,
582,
2549,
12,
298,
466,
582,
298,
1144,
401,
298,
1144,
582,
16870,
3282,
582,
2420,
4144,
582,
2549,
12,
298,
493,
582,
2420,
466,
582,
298,
875,
401,
298,
908,
582,
298,
875,
3570,
4863,
9420,
272,
520,
635,
12272,
4936,
26,
710,
2243,
4566,
367,
14880,
5331,
436,
2351,
7252,
14,
21751,
370,
658,
2330,
15,
1782,
63,
3280,
14,
647,
64,
10813,
25979,
408,
272,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
291,
14,
3170,
63,
9740,
275,
3087,
2728,
291,
14,
66,
63,
498,
275,
298,
2262,
2,
267,
291,
14,
2510,
4936,
275,
3087,
267,
291,
14,
493,
63,
513,
275,
942,
398,
367,
2883,
12,
574,
315,
2074,
14,
1744,
837,
288,
5371,
8,
277,
12,
1612,
12,
574,
9,
421,
199,
533,
8875,
6592,
8,
33,
709,
1563,
2543,
304,
2286,
408,
2543,
11994,
447,
272,
6654,
6279,
9795,
367,
314,
909,
8509,
13,
1985,
14,
339,
8089,
8509,
13,
1985,
5171,
17101,
3383,
29474,
436,
21592,
687,
658,
2330,
15,
33,
709,
1563,
2543,
2313,
272,
961,
1021,
365,
314,
28531,
20562,
2,
64,
1021,
367,
642,
859,
14,
64,
339,
520,
635,
12272,
4936,
26,
710,
2243,
4566,
367,
14880,
5331,
436,
2351,
7252,
14,
21751,
370,
658,
2330,
15,
1782,
63,
3280,
14,
647,
64,
10813,
339,
2851,
367,
642,
909,
447,
272,
658,
2859,
921,
28,
25680,
92,
6583,
2287,
30,
501,
1219,
1246,
15,
86,
19,
15,
493,
15,
6721,
13,
1985,
15,
2262,
2313,
10813,
25979,
408,
272,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
291,
14,
3170,
63,
9740,
275,
3087,
267,
291,
14,
2427,
9811,
267,
291,
14,
66,
63,
498,
275,
298,
6721,
13,
1985,
2,
267,
291,
14,
65,
709,
63,
633,
9555,
1219,
1246,
15,
86,
19,
15,
493,
15,
6721,
13,
1985,
15,
2262,
2,
267,
291,
14,
2510,
4936,
275,
3087,
267,
291,
14,
2262,
275,
1052,
398,
367,
2883,
12,
574,
315,
2074,
14,
1744,
837,
288,
5371,
8,
277,
12,
1612,
12,
574,
9,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
282,
709,
9277,
14,
2330,
14,
33,
709,
1563,
2543,
492,
437,
709,
1563,
2543,
421,
199,
533,
3814,
1296,
8,
33,
709,
1563,
2543,
304,
2286,
408,
2765,
1021,
1630,
440,
2291,
17101,
3383,
29474,
8749,
675,
1676,
14,
339,
520,
635,
570,
26,
2420,
466,
582,
298,
875,
401,
298,
908,
582,
298,
875,
3570,
272,
520,
635,
12272,
4936,
26,
710,
2243,
4566,
367,
14880,
5331,
436,
2351,
7252,
14,
21751,
370,
658,
2330,
15,
1782,
63,
3280,
14,
647,
64,
10813,
25979,
408,
272,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
291,
14,
3170,
63,
9740,
275,
3087,
2728,
291,
14,
66,
63,
498,
275,
298,
493,
13,
513,
2,
267,
291,
14,
2510,
4936,
275,
3087,
267,
291,
14,
33,
709,
11178,
63,
493,
275,
3087,
398,
367,
2883,
12,
574,
315,
2074,
14,
1744,
837,
288,
5371,
8,
277,
12,
1612,
12,
574,
9,
421,
199,
533,
6654,
8,
33,
709,
1563,
2543,
304,
2286,
408,
2765,
1021,
1630,
440,
2291,
17101,
3383,
29474,
8749,
675,
1676,
14,
339,
520,
635,
570,
63,
513,
26,
2420,
827,
7412,
582,
413,
12,
298,
1744,
582,
2420,
466,
582,
298,
785,
6018,
298,
3235,
7412,
582,
2549,
12,
298,
466,
582,
298,
1144,
401,
298,
1144,
582,
16870,
3282,
582,
2420,
4144,
582,
2549,
12,
298,
493,
582,
2420,
466,
582,
298,
875,
401,
298,
908,
582,
298,
875,
3570,
4863,
9420,
272,
520,
635,
12272,
4936,
26,
710,
2243,
4566,
367,
14880,
5331,
436,
2351,
7252,
14,
21751,
370,
658,
2330,
15,
1782,
63,
3280,
14,
647,
64,
10813,
25979,
408,
272,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
291,
14,
3170,
63,
9740,
275,
3087,
2728,
291,
14,
66,
63,
498,
275,
298,
2262,
2,
267,
291,
14,
2510,
4936,
275,
3087,
267,
291,
14,
493,
63,
513,
275,
942,
398,
367,
2883,
12,
574,
315,
2074,
14,
1744,
837,
288,
5371,
8,
277,
12,
1612,
12,
574,
9,
421,
199,
533,
8875,
6592,
8,
33,
709,
1563,
2543,
304,
2286,
408,
2543,
11994,
447,
272,
6654,
6279,
9795,
367,
314,
909,
8509,
13,
1985,
14,
339,
8089,
8509,
13,
1985,
5171,
17101,
3383,
29474,
436,
21592,
687,
658,
2330,
15,
33,
709,
1563,
2543,
2313,
272,
961,
1021,
365,
314,
28531,
20562,
2,
64,
1021,
367,
642,
859,
14,
64,
339,
520,
635,
12272,
4936,
26,
710,
2243,
4566,
367,
14880,
5331,
436,
2351,
7252,
14,
21751,
370,
658,
2330,
15,
1782,
63,
3280,
14,
647,
64,
10813,
339,
2851,
367,
642,
909,
447,
272,
658,
2859,
921,
28,
25680,
92,
6583,
2287,
30,
501,
1219,
1246,
15,
86,
19,
15,
493,
15,
6721,
13,
1985,
15,
2262,
2313,
10813,
25979,
408,
272,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
291,
14,
3170,
63,
9740,
275,
3087,
267,
291,
14,
2427,
9811,
267,
291,
14,
66,
63,
498,
275,
298,
6721,
13,
1985,
2,
267,
291,
14,
65,
709,
63,
633,
9555,
1219,
1246,
15,
86,
19,
15,
493,
15,
6721,
13,
1985,
15,
2262,
2,
267,
291,
14,
2510,
4936,
275,
3087,
267,
291,
14,
2262,
275,
1052,
398,
367,
2883,
12,
574,
315,
2074,
14,
1744,
837,
288,
5371,
8,
277,
12,
1612,
12,
574,
9,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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ingLiangRoad',
extensions=['gif', 'jpg', 'png']):
request_html = urllib2.Request(html_url)
try:
response = urllib2.urlopen(request_html)
html = response.read()
r1 = r'<img.+src=\".+?\"'
r2 = r'<img.+src=\"(.+?)\"'
results = []
imgs = []
p = re.compile(r1)
for m in p.finditer(html):
results.append(m.group())
for result in results:
compile_result = re.compile(r2)
imgs.append(compile_result.sub(r'\1', result))
if not os.path.exists(folder_name):
os.makedirs(folder_name)
for img in imgs:
filename = str(uuid.uuid1())
ex = ''
for extension in extensions:
if '.%s' % extension in img:
ex = '.%s' % extension
if ex is '':
continue
filename += ex
try:
urllib.urlretrieve(img, os.path.join(folder_name, filename))
print 'Image save at %s' % output.name
except Exception, ex:
print ex
except Exception, e:
print e
get_images()
# japanese girls
get_images(html_url='http://tieba.baidu.com/p/2166231880', folder_name='jp')
|
mit
|
[
646,
4011,
18,
199,
646,
4011,
199,
646,
295,
199,
646,
747,
199,
646,
5377,
421,
199,
318,
664,
63,
4782,
8,
1360,
63,
633,
534,
1014,
921,
89,
18499,
14,
957,
15,
1932,
15,
3624,
19,
85,
20,
90,
85,
297,
2049,
4922,
63,
354,
534,
8047,
13297,
63,
11486,
63,
22638,
13009,
621,
3863,
350,
297,
2049,
5478,
2968,
14513,
297,
283,
8476,
297,
283,
4524,
9090,
272,
1056,
63,
1360,
275,
4011,
18,
14,
2017,
8,
1360,
63,
633,
9,
272,
862,
26,
267,
1177,
275,
4011,
18,
14,
10890,
8,
1069,
63,
1360,
9,
267,
3517,
275,
1177,
14,
739,
342,
267,
519,
17,
275,
519,
7601,
4060,
6977,
2164,
9529,
1674,
23778,
4451,
7,
267,
519,
18,
275,
519,
7601,
4060,
6977,
2164,
8178,
28149,
2862,
4507,
267,
2058,
275,
942,
267,
3416,
458,
275,
942,
267,
299,
275,
295,
14,
2014,
8,
82,
17,
9,
267,
367,
333,
315,
299,
14,
19373,
8,
1360,
304,
288,
2058,
14,
740,
8,
77,
14,
923,
1012,
267,
367,
754,
315,
2058,
26,
288,
6555,
63,
1099,
275,
295,
14,
2014,
8,
82,
18,
9,
288,
3416,
458,
14,
740,
8,
2014,
63,
1099,
14,
954,
8,
82,
1154,
17,
297,
754,
430,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
3741,
63,
354,
304,
288,
747,
14,
8347,
8,
3741,
63,
354,
9,
267,
367,
6050,
315,
3416,
458,
26,
288,
1788,
275,
620,
8,
2580,
14,
2580,
17,
1012,
288,
444,
275,
2125,
288,
367,
3329,
315,
5478,
26,
355,
340,
1987,
5,
83,
7,
450,
3329,
315,
6050,
26,
490,
444,
275,
1987,
5,
83,
7,
450,
3329,
288,
340,
444,
365,
8061,
355,
1980,
288,
1788,
847,
444,
288,
862,
26,
355,
4011,
14,
633,
14270,
8,
4060,
12,
747,
14,
515,
14,
904,
8,
3741,
63,
354,
12,
1788,
430,
355,
870,
283,
3491,
3354,
737,
450,
83,
7,
450,
1072,
14,
354,
288,
871,
2186,
12,
444,
26,
355,
870,
444,
272,
871,
2186,
12,
325,
26,
267,
870,
325,
199,
199,
362,
63,
4782,
342,
199,
3,
1335,
30699,
486,
723,
478,
199,
362,
63,
4782,
8,
1360,
63,
633,
534,
1014,
921,
23958,
2470,
14,
2470,
344,
85,
14,
957,
15,
80,
15,
9669,
31353,
1085,
1257,
297,
4922,
63,
354,
534,
11538,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4011,
18,
199,
646,
4011,
199,
646,
295,
199,
646,
747,
199,
646,
5377,
421,
199,
318,
664,
63,
4782,
8,
1360,
63,
633,
534,
1014,
921,
89,
18499,
14,
957,
15,
1932,
15,
3624,
19,
85,
20,
90,
85,
297,
2049,
4922,
63,
354,
534,
8047,
13297,
63,
11486,
63,
22638,
13009,
621,
3863,
350,
297,
2049,
5478,
2968,
14513,
297,
283,
8476,
297,
283,
4524,
9090,
272,
1056,
63,
1360,
275,
4011,
18,
14,
2017,
8,
1360,
63,
633,
9,
272,
862,
26,
267,
1177,
275,
4011,
18,
14,
10890,
8,
1069,
63,
1360,
9,
267,
3517,
275,
1177,
14,
739,
342,
267,
519,
17,
275,
519,
7601,
4060,
6977,
2164,
9529,
1674,
23778,
4451,
7,
267,
519,
18,
275,
519,
7601,
4060,
6977,
2164,
8178,
28149,
2862,
4507,
267,
2058,
275,
942,
267,
3416,
458,
275,
942,
267,
299,
275,
295,
14,
2014,
8,
82,
17,
9,
267,
367,
333,
315,
299,
14,
19373,
8,
1360,
304,
288,
2058,
14,
740,
8,
77,
14,
923,
1012,
267,
367,
754,
315,
2058,
26,
288,
6555,
63,
1099,
275,
295,
14,
2014,
8,
82,
18,
9,
288,
3416,
458,
14,
740,
8,
2014,
63,
1099,
14,
954,
8,
82,
1154,
17,
297,
754,
430,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
3741,
63,
354,
304,
288,
747,
14,
8347,
8,
3741,
63,
354,
9,
267,
367,
6050,
315,
3416,
458,
26,
288,
1788,
275,
620,
8,
2580,
14,
2580,
17,
1012,
288,
444,
275,
2125,
288,
367,
3329,
315,
5478,
26,
355,
340,
1987,
5,
83,
7,
450,
3329,
315,
6050,
26,
490,
444,
275,
1987,
5,
83,
7,
450,
3329,
288,
340,
444,
365,
8061,
355,
1980,
288,
1788,
847,
444,
288,
862,
26,
355,
4011,
14,
633,
14270,
8,
4060,
12,
747,
14,
515,
14,
904,
8,
3741,
63,
354,
12,
1788,
430,
355,
870,
283,
3491,
3354,
737,
450,
83,
7,
450,
1072,
14,
354,
288,
871,
2186,
12,
444,
26,
355,
870,
444,
272,
871,
2186,
12,
325,
26,
267,
870,
325,
199,
199,
362,
63,
4782,
342,
199,
3,
1335,
30699,
486,
723,
478,
199,
362,
63,
4782,
8,
1360,
63,
633,
534,
1014,
921,
23958,
2470,
14,
2470,
344,
85,
14,
957,
15,
80,
15,
9669,
31353,
1085,
1257,
297,
4922,
63,
354,
534,
11538,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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
# Copyright (C) 2004-2010 Federico Di Gregorio <fog@debian.org>
#
# psycopg2 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.
#
# psycopg2 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.
import time
from datetime import timedelta
import psycopg2
import psycopg2.extras
from testutils import unittest, ConnectingTestCase, skip_before_postgres
from testutils import skip_if_no_namedtuple
class ExtrasDictCursorTests(ConnectingTestCase):
"""Test if DictCursor extension class works."""
def setUp(self):
ConnectingTestCase.setUp(self)
curs = self.conn.cursor()
curs.execute("CREATE TEMPORARY TABLE ExtrasDictCursorTests (foo text)")
curs.execute("INSERT INTO ExtrasDictCursorTests VALUES ('bar')")
self.conn.commit()
def testDictConnCursorArgs(self):
self.conn.close()
self.conn = self.connect(connection_factory=psycopg2.extras.DictConnection)
cur = self.conn.cursor()
self.assert_(isinstance(cur, psycopg2.extras.DictCursor))
self.assertEqual(cur.name, None)
# overridable
cur = self.conn.cursor('foo',
cursor_factory=psycopg2.extras.NamedTupleCursor)
self.assertEqual(cur.name, 'foo')
self.assert_(isinstance(cur, psycopg2.extras.NamedTupleCursor))
def testDictCursorWithPlainCursorFetchOne(self):
self._testWithPlainCursor(lambda curs: curs.fetchone())
def testDictCursorWithPlainCursorFetchMany(self):
self._testWithPlainCursor(lambda curs: curs.fetchmany(100)[0])
def testDictCursorWithPlainCursorFetchManyNoarg(self):
self._testWithPlainCursor(lambda curs: curs.fetchmany()[0])
def testDictCursorWithPlainCursorFetchAll(self):
self._testWithPlainCursor(lambda curs: curs.fetchall()[0])
def testDictCursorWithPlainCursorIter(self):
def getter(curs):
for row in curs:
return row
self._testWithPlainCursor(getter)
def testUpdateRow(self):
row = self._testWithPlainCursor(lambda curs: curs.fetchone())
row['foo'] = 'qux'
self.failUnless(row['foo'] == 'qux')
self.failUnless(row[0] == 'qux')
@skip_before_postgres(8, 0)
def testDictCursorWithPlainCursorIterRowNumber(self):
curs = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
self._testIterRowNumber(curs)
def _testWithPlainCursor(self, getter):
curs = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
curs.execute("SELECT * FROM ExtrasDictCursorTests")
row = getter(curs)
self.failUnless(row['foo'] == 'bar')
self.failUnless(row[0] == 'bar')
return row
def testDictCursorWithPlainCursorRealFetchOne(self):
self._testWithPlainCursorReal(lambda curs: curs.fetchone())
def testDictCursorWithPlainCursorRealFetchMany(self):
self._testWithPlainCursorReal(lambda curs: curs.fetchmany(100)[0])
def testDictCursorWithPlainCursorRealFetchManyNoarg(self):
self._testWithPlainCursorReal(lambda curs: curs.fetchmany()[0])
def testDictCursorWithPlainCursorRealFetchAll(self):
self._testWithPlainCursorReal(lambda curs: curs.fetchall()[0])
def testDictCursorWithPlainCursorRealIter(self):
def getter(curs):
for row in curs:
return row
self._testWithPlainCursorReal(getter)
@skip_before_postgres(8, 0)
def testDictCursorWithPlainCursorRealIterRowNumber(self):
curs = self.conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
self._testIterRowNumber(curs)
def _testWithPlainCursorReal(self, getter):
curs = self.conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
curs.execute("SELECT * FROM ExtrasDictCursorTests")
row = getter(curs)
self.failUnless(row['foo'] == 'bar')
def testDictCursorWithNamedCursorFetchOne(self):
self._testWithNamedCursor(lambda curs: curs.fetchone())
def testDictCursorWithNamedCursorFetchMany(self):
self._testWithNamedCursor(lambda curs: curs.fetchmany(100)[0])
def testDictCursorWithNamedCursorFetchManyNoarg(self):
self._testWithNamedCursor(lambda curs: curs.fetchmany()[0])
def testDictCursorWithNamedCursorFetchAll(self):
self._testWithNamedCursor(lambda curs: curs.fetchall()[0])
def testDictCursorWithNamedCursorIter(self):
def getter(curs):
for row in curs:
return row
self._testWithNamedCursor(getter)
@skip_before_postgres(8, 2)
def testDictCursorWithNamedCursorNotGreedy(self):
curs = self.conn.cursor('tmp', cursor_factory=psycopg2.extras.DictCursor)
self._testNamedCursorNotGreedy(curs)
@skip_before_postgres(8, 0)
def testDictCursorWithNamedCursorIterRowNumber(self):
curs = self.conn.cursor('tmp', cursor_factory=psycopg2.extras.DictCursor)
self._testIterRowNumber(curs)
def _testWithNamedCursor(self, getter):
curs = self.conn.cursor('aname', cursor_factory=psycopg2.extras.DictCursor)
curs.execute("SELECT * FROM ExtrasDictCursorTests")
row = getter(curs)
self.failUnless(row['foo'] == 'bar')
self.failUnless(row[0] == 'bar')
def testDictCursorRealWithNamedCursorFetchOne(self):
self._testWithNamedCursorReal(lambda curs: curs.fetchone())
def testDictCursorRealWithNamedCursorFetchMany(self):
self._testWithNamedCursorReal(lambda curs: curs.fetchmany(100)[0])
def testDictCursorRealWithNamedCursorFetchManyNoarg(self):
self._testWithNamedCursorReal(lambda curs: curs.fetchmany()[0])
def testDictCursorRealWithNamedCursorFetchAll(self):
self._testWithNamedCursorReal(lambda curs: curs.fetchall()[0])
def testDictCursorRealWithNamedCursorIter(self):
def getter(curs):
for row in curs:
return row
self._testWithNamedCursorReal(getter)
@skip_before_postgres(8, 2)
def testDictCursorRealWithNamedCursorNotGreedy(self):
curs = self.conn.cursor('tmp', cursor_factory=psycopg2.extras.RealDictCursor)
self._testNamedCursorNotGreedy(curs)
@skip_before_postgres(8, 0)
def testDictCursorRealWithNamedCursorIterRowNumber(self):
curs = self.conn.cursor('tmp', cursor_factory=psycopg2.extras.RealDictCursor)
self._testIterRowNumber(curs)
def _testWithNamedCursorReal(self, getter):
curs = self.conn.cursor('aname',
cursor_factory=psycopg2.extras.RealDictCursor)
curs.execute("SELECT * FROM ExtrasDictCursorTests")
row = getter(curs)
self.failUnless(row['foo'] == 'bar')
def _testNamedCursorNotGreedy(self, curs):
curs.itersize = 2
curs.execute("""select clock_timestamp() as ts from generate_series(1,3)""")
recs = []
for t in curs:
time.sleep(0.01)
recs.append(t)
# check that the dataset was not fetched in a single gulp
self.assert_(recs[1]['ts'] - recs[0]['ts'] < timedelta(seconds=0.005))
self.assert_(recs[2]['ts'] - recs[1]['ts'] > timedelta(seconds=0.0099))
def _testIterRowNumber(self, curs):
# Only checking for dataset < itersize:
# see CursorTests.test_iter_named_cursor_rownumber
curs.itersize = 20
curs.execute("""select * from generate_series(1,10)""")
for i, r in enumerate(curs):
self.assertEqual(i + 1, curs.rownumber)
def testPickleDictRow(self):
import pickle
curs = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
curs.execute("select 10 as a, 20 as b")
r = curs.fetchone()
d = pickle.dumps(r)
r1 = pickle.loads(d)
self.assertEqual(r, r1)
self.assertEqual(r[0], r1[0])
self.assertEqual(r[1], r1[1])
self.assertEqual(r['a'], r1['a'])
self.assertEqual(r['b'], r1['b'])
self.assertEqual(r._index, r1._index)
def testPickleRealDictRow(self):
import pickle
curs = self.conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
curs.execute("select 10 as a, 20 as b")
r = curs.fetchone()
d = pickle.dumps(r)
r1 = pickle.loads(d)
self.assertEqual(r, r1)
self.assertEqual(r['a'], r1['a'])
self.assertEqual(r['b'], r1['b'])
self.assertEqual(r._column_mapping, r1._column_mapping)
class NamedTupleCursorTest(ConnectingTestCase):
def setUp(self):
ConnectingTestCase.setUp(self)
from psycopg2.extras import NamedTupleConnection
try:
from collections import namedtuple # noqa
except ImportError:
return
self.conn = self.connect(connection_factory=NamedTupleConnection)
curs = self.conn.cursor()
curs.execute("CREATE TEMPORARY TABLE nttest (i int, s text)")
curs.execute("INSERT INTO nttest VALUES (1, 'foo')")
curs.execute("INSERT INTO nttest VALUES (2, 'bar')")
curs.execute("INSERT INTO nttest VALUES (3, 'baz')")
self.conn.commit()
@skip_if_no_namedtuple
def test_cursor_args(self):
cur = self.conn.cursor('foo', cursor_factory=psycopg2.extras.DictCursor)
self.assertEqual(cur.name, 'foo')
self.assert_(isinstance(cur, psycopg2.extras.DictCursor))
@skip_if_no_namedtuple
def test_fetchone(self):
curs = self.conn.cursor()
curs.execute("select * from nttest order by 1")
t = curs.fetchone()
self.assertEqual(t[0], 1)
self.assertEqual(t.i, 1)
self.assertEqual(t[1], 'foo')
self.assertEqual(t.s, 'foo')
self.assertEqual(curs.rownumber, 1)
self.assertEqual(curs.rowcount, 3)
@skip_if_no_namedtuple
def test_fetchmany_noarg(self):
curs = self.conn.cursor()
curs.arraysize = 2
curs.execute("select * from nttest order by 1")
res = curs.fetchmany()
self.assertEqual(2, len(res))
self.assertEqual(res[0].i, 1)
self.assertEqual(res[0].s, 'foo')
self.assertEqual(res[1].i, 2)
self.assertEqual(res[1].s, 'bar')
self.assertEqual(curs.rownumber, 2)
self.assertEqual(curs.rowcount, 3)
@skip_if_no_namedtuple
def test_fetchmany(self):
curs = self.conn.cursor()
curs.execute("select * from nttest order by 1")
res = curs.fetchmany(2)
self.assertEqual(2, len(res))
self.assertEqual(res[0].i, 1)
self.assertEqual(res[0].s, 'foo')
self.assertEqual(res[1].i, 2)
self.assertEqual(res[1].s, 'bar')
self.assertEqual(curs.rownumber, 2)
self.assertEqual(curs.rowcount, 3)
@skip_if_no_namedtuple
def test_fetchall(self):
curs = self.conn.cursor()
curs.execute("select * from nttest order by 1")
res = curs.fetchall()
self.assertEqual(3, len(res))
self.assertEqual(res[0].i, 1)
self.assertEqual(res[0].s, 'foo')
self.assertEqual(res[1].i, 2)
self.assertEqual(res[1].s, 'bar')
self.assertEqual(res[2].i, 3)
self.assertEqual(res[2].s, 'baz')
self.assertEqual(curs.rownumber, 3)
self.assertEqual(curs.rowcount, 3)
@skip_if_no_namedtuple
def test_executemany(self):
curs = self.conn.cursor()
curs.executemany("delete from nttest where i = %s",
[(1,), (2,)])
curs.execute("select * from nttest order by 1")
res = curs.fetchall()
self.assertEqual(1, len(res))
self.assertEqual(res[0].i, 3)
self.assertEqual(res[0].s, 'baz')
@skip_if_no_namedtuple
def test_iter(self):
curs = self.conn.cursor()
curs.execute("select * from nttest order by 1")
i = iter(curs)
self.assertEqual(curs.rownumber, 0)
t = i.next()
self.assertEqual(t.i, 1)
self.assertEqual(t.s, 'foo')
self.assertEqual(curs.rownumber, 1)
self.assertEqual(curs.rowcount, 3)
t = i.next()
self.assertEqual(t.i, 2)
self.assertEqual(t.s, 'bar')
self.assertEqual(curs.rownumber, 2)
self.assertEqual(curs.rowcount, 3)
t = i.next()
self.assertEqual(t.i, 3)
self.assertEqual(t.s, 'baz')
self.assertRaises(StopIteration, i.next)
self.assertEqual(curs.rownumber, 3)
self.assertEqual(curs.rowcount, 3)
def test_error_message(self):
try:
from collections import namedtuple # noqa
except ImportError:
# an import error somewhere
from psycopg2.extras import NamedTupleConnection
try:
self.conn = self.connect(
connection_factory=NamedTupleConnection)
curs = self.conn.cursor()
curs.execute("select 1")
curs.fetchone()
except ImportError:
pass
else:
self.fail("expecting ImportError")
else:
return self.skipTest("namedtuple available")
@skip_if_no_namedtuple
def test_record_updated(self):
curs = self.conn.cursor()
curs.execute("select 1 as foo;")
r = curs.fetchone()
self.assertEqual(r.foo, 1)
curs.execute("select 2 as bar;")
r = curs.fetchone()
self.assertEqual(r.bar, 2)
self.assertRaises(AttributeError, getattr, r, 'foo')
@skip_if_no_namedtuple
def test_no_result_no_surprise(self):
curs = self.conn.cursor()
curs.execute("update nttest set s = s")
self.assertRaises(psycopg2.ProgrammingError, curs.fetchone)
curs.execute("update nttest set s = s")
self.assertRaises(psycopg2.ProgrammingError, curs.fetchall)
@skip_if_no_namedtuple
def test_minimal_generation(self):
# Instrument the class to verify it gets called the minimum number of times.
from psycopg2.extras import NamedTupleCursor
f_orig = NamedTupleCursor._make_nt
calls = [0]
def f_patched(self_):
calls[0] += 1
return f_orig(self_)
NamedTupleCursor._make_nt = f_patched
try:
curs = self.conn.cursor()
curs.execute("select * from nttest order by 1")
curs.fetchone()
curs.fetchone()
curs.fetchone()
self.assertEqual(1, calls[0])
curs.execute("select * from nttest order by 1")
curs.fetchone()
curs.fetchall()
self.assertEqual(2, calls[0])
curs.execute("select * from nttest order by 1")
curs.fetchone()
curs.fetchmany(1)
self.assertEqual(3, calls[0])
finally:
NamedTupleCursor._make_nt = f_orig
@skip_if_no_namedtuple
@skip_before_postgres(8, 0)
def test_named(self):
curs = self.conn.cursor('tmp')
curs.execute("""select i from generate_series(0,9) i""")
recs = []
recs.extend(curs.fetchmany(5))
recs.append(curs.fetchone())
recs.extend(curs.fetchall())
self.assertEqual(range(10), [t.i for t in recs])
@skip_if_no_namedtuple
def test_named_fetchone(self):
curs = self.conn.cursor('tmp')
curs.execute("""select 42 as i""")
t = curs.fetchone()
self.assertEqual(t.i, 42)
@skip_if_no_namedtuple
def test_named_fetchmany(self):
curs = self.conn.cursor('tmp')
curs.execute("""select 42 as i""")
recs = curs.fetchmany(10)
self.assertEqual(recs[0].i, 42)
@skip_if_no_namedtuple
def test_named_fetchall(self):
curs = self.conn.cursor('tmp')
curs.execute("""select 42 as i""")
recs = curs.fetchall()
self.assertEqual(recs[0].i, 42)
@skip_if_no_namedtuple
@skip_before_postgres(8, 2)
def test_not_greedy(self):
curs = self.conn.cursor('tmp')
curs.itersize = 2
curs.execute("""select clock_timestamp() as ts from generate_series(1,3)""")
recs = []
for t in curs:
time.sleep(0.01)
recs.append(t)
# check that the dataset was not fetched in a single gulp
self.assert_(recs[1].ts - recs[0].ts < timedelta(seconds=0.005))
self.assert_(recs[2].ts - recs[1].ts > timedelta(seconds=0.0099))
@skip_if_no_namedtuple
@skip_before_postgres(8, 0)
def test_named_rownumber(self):
curs = self.conn.cursor('tmp')
# Only checking for dataset < itersize:
# see CursorTests.test_iter_named_cursor_rownumber
curs.itersize = 4
curs.execute("""select * from generate_series(1,3)""")
for i, t in enumerate(curs):
self.assertEqual(i + 1, curs.rownumber)
def test_suite():
return unittest.TestLoader().loadTestsFromName(__name__)
if __name__ == "__main__":
unittest.main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
13751,
63,
807,
3937,
446,
511,
340,
7448,
8993,
3329,
1021,
5419,
199,
3,
199,
3,
1898,
334,
35,
9,
8353,
13,
6542,
7949,
9910,
331,
3757,
29096,
269,
2308,
221,
665,
545,
71,
32,
23204,
14,
1308,
30,
199,
3,
199,
3,
15492,
18,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
3,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
199,
3,
701,
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,
15492,
18,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
199,
3,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
367,
1655,
2436,
14,
199,
199,
646,
900,
199,
504,
2197,
492,
6871,
199,
646,
15492,
18,
199,
646,
15492,
18,
14,
9975,
199,
504,
511,
1208,
492,
2882,
12,
15175,
316,
1746,
12,
3372,
63,
5182,
63,
10675,
199,
504,
511,
1208,
492,
3372,
63,
692,
63,
889,
63,
18921,
421,
199,
533,
7255,
6360,
2141,
8993,
2925,
8,
32000,
1746,
304,
272,
408,
774,
340,
7448,
8993,
3329,
1021,
5419,
1041,
339,
347,
3613,
8,
277,
304,
267,
15175,
316,
1746,
14,
5996,
8,
277,
9,
267,
18809,
275,
291,
14,
1631,
14,
3937,
342,
267,
18809,
14,
2526,
480,
8366,
24314,
726,
4392,
9934,
7255,
6360,
2141,
8993,
2925,
334,
1421,
1318,
6320,
267,
18809,
14,
2526,
480,
10258,
12872,
7255,
6360,
2141,
8993,
2925,
13992,
661,
1700,
26530,
267,
291,
14,
1631,
14,
3543,
342,
339,
347,
511,
2141,
6805,
8993,
6213,
8,
277,
304,
267,
291,
14,
1631,
14,
1600,
342,
267,
291,
14,
1631,
275,
291,
14,
2242,
8,
2105,
63,
3702,
29,
20270,
18,
14,
9975,
14,
2141,
3225,
9,
267,
1094,
275,
291,
14,
1631,
14,
3937,
342,
267,
291,
14,
479,
2531,
6074,
8,
895,
12,
15492,
18,
14,
9975,
14,
2141,
8993,
430,
267,
291,
14,
629,
8,
895,
14,
354,
12,
488,
9,
267,
327,
1806,
1677,
461,
267,
1094,
275,
291,
14,
1631,
14,
3937,
360,
1421,
297,
288,
3920,
63,
3702,
29,
20270,
18,
14,
9975,
14,
7989,
7075,
8993,
9,
267,
291,
14,
629,
8,
895,
14,
354,
12,
283,
1421,
358,
267,
291,
14,
479,
2531,
6074,
8,
895,
12,
15492,
18,
14,
9975,
14,
7989,
7075,
8993,
430,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
11135,
4395,
8,
277,
304,
267,
291,
423,
396,
3007,
20711,
8993,
8,
2734,
18809,
26,
18809,
14,
11591,
1012,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
11135,
4089,
8,
277,
304,
267,
291,
423,
396,
3007,
20711,
8993,
8,
2734,
18809,
26,
18809,
14,
3535,
3479,
8,
1960,
2788,
16,
566,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
11135,
4089,
1944,
1273,
8,
277,
304,
267,
291,
423,
396,
3007,
20711,
8993,
8,
2734,
18809,
26,
18809,
14,
3535,
3479,
3430,
16,
566,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
11135,
2422,
8,
277,
304,
267,
291,
423,
396,
3007,
20711,
8993,
8,
2734,
18809,
26,
18809,
14,
10174,
3430,
16,
566,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
3315,
8,
277,
304,
267,
347,
15917,
8,
17255,
304,
288,
367,
1962,
315,
18809,
26,
355,
372,
1962,
267,
291,
423,
396,
3007,
20711,
8993,
8,
7416,
9,
339,
347,
511,
4152,
5810,
8,
277,
304,
267,
1962,
275,
291,
423,
396,
3007,
20711,
8993,
8,
2734,
18809,
26,
18809,
14,
11591,
1012,
267,
1962,
459,
1421,
418,
275,
283,
27519,
7,
267,
291,
14,
7589,
8,
1143,
459,
1421,
418,
508,
283,
27519,
358,
267,
291,
14,
7589,
8,
1143,
59,
16,
61,
508,
283,
27519,
358,
339,
768,
2759,
63,
5182,
63,
10675,
8,
24,
12,
378,
9,
272,
347,
511,
2141,
8993,
3007,
20711,
8993,
3315,
5810,
3259,
8,
277,
304,
267,
18809,
275,
291,
14,
1631,
14,
3937,
8,
3937,
63,
3702,
29,
20270,
18,
14,
9975,
14,
2141,
8993,
9,
267,
291,
423,
396,
3315,
5810,
3259,
8,
17255,
9,
339,
347,
485,
396,
3007,
20711,
8993,
8,
277,
12,
15917,
304,
267,
18809,
275,
291,
14,
1631,
14,
3937,
8,
3937,
63,
3702,
29,
20270,
18,
14,
9975,
14,
2141,
8993,
9,
267,
18809,
14,
2526,
480,
4859,
627,
4442,
7255,
6360,
2141,
8993,
2925,
531,
267,
1962,
275,
15917,
8,
17255,
9,
267,
291,
14,
7589,
8,
1143,
459,
1421,
418,
508,
283,
1700,
358,
267,
291,
14,
7589,
8,
1143,
59,
16,
61,
508,
283,
1700,
358,
267,
372,
1962,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
10099,
11135,
4395,
8,
277,
304,
267,
291,
423,
396,
3007,
20711,
8993,
10099,
8,
2734,
18809,
26,
18809,
14,
11591,
1012,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
10099,
11135,
4089,
8,
277,
304,
267,
291,
423,
396,
3007,
20711,
8993,
10099,
8,
2734,
18809,
26,
18809,
14,
3535,
3479,
8,
1960,
2788,
16,
566,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
10099,
11135,
4089,
1944,
1273,
8,
277,
304,
267,
291,
423,
396,
3007,
20711,
8993,
10099,
8,
2734,
18809,
26,
18809,
14,
3535,
3479,
3430,
16,
566,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
10099,
11135,
2422,
8,
277,
304,
267,
291,
423,
396,
3007,
20711,
8993,
10099,
8,
2734,
18809,
26,
18809,
14,
10174,
3430,
16,
566,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
10099,
3315,
8,
277,
304,
267,
347,
15917,
8,
17255,
304,
288,
367,
1962,
315,
18809,
26,
355,
372,
1962,
267,
291,
423,
396,
3007,
20711,
8993,
10099,
8,
7416,
9,
339,
768,
2759,
63,
5182,
63,
10675,
8,
24,
12,
378,
9,
272,
347,
511,
2141,
8993,
3007,
20711,
8993,
10099,
3315,
5810,
3259,
8,
277,
304,
267,
18809,
275,
291,
14,
1631,
14,
3937,
8,
3937,
63,
3702,
29,
20270,
18,
14,
9975,
14,
10099,
2141,
8993,
9,
267,
291,
423,
396,
3315,
5810,
3259,
8,
17255
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
13751,
63,
807,
3937,
446,
511,
340,
7448,
8993,
3329,
1021,
5419,
199,
3,
199,
3,
1898,
334,
35,
9,
8353,
13,
6542,
7949,
9910,
331,
3757,
29096,
269,
2308,
221,
665,
545,
71,
32,
23204,
14,
1308,
30,
199,
3,
199,
3,
15492,
18,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
3,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
199,
3,
701,
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,
15492,
18,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
199,
3,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
367,
1655,
2436,
14,
199,
199,
646,
900,
199,
504,
2197,
492,
6871,
199,
646,
15492,
18,
199,
646,
15492,
18,
14,
9975,
199,
504,
511,
1208,
492,
2882,
12,
15175,
316,
1746,
12,
3372,
63,
5182,
63,
10675,
199,
504,
511,
1208,
492,
3372,
63,
692,
63,
889,
63,
18921,
421,
199,
533,
7255,
6360,
2141,
8993,
2925,
8,
32000,
1746,
304,
272,
408,
774,
340,
7448,
8993,
3329,
1021,
5419,
1041,
339,
347,
3613,
8,
277,
304,
267,
15175,
316,
1746,
14,
5996,
8,
277,
9,
267,
18809,
275,
291,
14,
1631,
14,
3937,
342,
267,
18809,
14,
2526,
480,
8366,
24314,
726,
4392,
9934,
7255,
6360,
2141,
8993,
2925,
334,
1421,
1318,
6320,
267,
18809,
14,
2526,
480,
10258,
12872,
7255,
6360,
2141,
8993,
2925,
13992,
661,
1700,
26530,
267,
291,
14,
1631,
14,
3543,
342,
339,
347,
511,
2141,
6805,
8993,
6213,
8,
277,
304,
267,
291,
14,
1631,
14,
1600,
342,
267,
291,
14,
1631,
275,
291,
14,
2242,
8,
2105,
63,
3702,
29,
20270,
18,
14,
9975,
14,
2141,
3225,
9,
267,
1094,
275,
291,
14,
1631,
14,
3937,
342,
267,
291,
14,
479,
2531,
6074,
8,
895,
12,
15492,
18,
14,
9975,
14,
2141,
8993,
430,
267,
291,
14,
629,
8,
895,
14,
354,
12,
488,
9,
267,
327,
1806,
1677,
461,
267,
1094,
275,
291,
14,
1631,
14,
3937,
360,
1421,
297,
288,
3920,
63,
3702,
29,
20270,
18,
14,
9975,
14,
7989,
7075,
8993,
9,
267,
291,
14,
629,
8,
895,
14,
354,
12,
283,
1421,
358,
267,
291,
14,
479,
2531,
6074,
8,
895,
12,
15492,
18,
14,
9975,
14,
7989,
7075,
8993,
430,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
11135,
4395,
8,
277,
304,
267,
291,
423,
396,
3007,
20711,
8993,
8,
2734,
18809,
26,
18809,
14,
11591,
1012,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
11135,
4089,
8,
277,
304,
267,
291,
423,
396,
3007,
20711,
8993,
8,
2734,
18809,
26,
18809,
14,
3535,
3479,
8,
1960,
2788,
16,
566,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
11135,
4089,
1944,
1273,
8,
277,
304,
267,
291,
423,
396,
3007,
20711,
8993,
8,
2734,
18809,
26,
18809,
14,
3535,
3479,
3430,
16,
566,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
11135,
2422,
8,
277,
304,
267,
291,
423,
396,
3007,
20711,
8993,
8,
2734,
18809,
26,
18809,
14,
10174,
3430,
16,
566,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
3315,
8,
277,
304,
267,
347,
15917,
8,
17255,
304,
288,
367,
1962,
315,
18809,
26,
355,
372,
1962,
267,
291,
423,
396,
3007,
20711,
8993,
8,
7416,
9,
339,
347,
511,
4152,
5810,
8,
277,
304,
267,
1962,
275,
291,
423,
396,
3007,
20711,
8993,
8,
2734,
18809,
26,
18809,
14,
11591,
1012,
267,
1962,
459,
1421,
418,
275,
283,
27519,
7,
267,
291,
14,
7589,
8,
1143,
459,
1421,
418,
508,
283,
27519,
358,
267,
291,
14,
7589,
8,
1143,
59,
16,
61,
508,
283,
27519,
358,
339,
768,
2759,
63,
5182,
63,
10675,
8,
24,
12,
378,
9,
272,
347,
511,
2141,
8993,
3007,
20711,
8993,
3315,
5810,
3259,
8,
277,
304,
267,
18809,
275,
291,
14,
1631,
14,
3937,
8,
3937,
63,
3702,
29,
20270,
18,
14,
9975,
14,
2141,
8993,
9,
267,
291,
423,
396,
3315,
5810,
3259,
8,
17255,
9,
339,
347,
485,
396,
3007,
20711,
8993,
8,
277,
12,
15917,
304,
267,
18809,
275,
291,
14,
1631,
14,
3937,
8,
3937,
63,
3702,
29,
20270,
18,
14,
9975,
14,
2141,
8993,
9,
267,
18809,
14,
2526,
480,
4859,
627,
4442,
7255,
6360,
2141,
8993,
2925,
531,
267,
1962,
275,
15917,
8,
17255,
9,
267,
291,
14,
7589,
8,
1143,
459,
1421,
418,
508,
283,
1700,
358,
267,
291,
14,
7589,
8,
1143,
59,
16,
61,
508,
283,
1700,
358,
267,
372,
1962,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
10099,
11135,
4395,
8,
277,
304,
267,
291,
423,
396,
3007,
20711,
8993,
10099,
8,
2734,
18809,
26,
18809,
14,
11591,
1012,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
10099,
11135,
4089,
8,
277,
304,
267,
291,
423,
396,
3007,
20711,
8993,
10099,
8,
2734,
18809,
26,
18809,
14,
3535,
3479,
8,
1960,
2788,
16,
566,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
10099,
11135,
4089,
1944,
1273,
8,
277,
304,
267,
291,
423,
396,
3007,
20711,
8993,
10099,
8,
2734,
18809,
26,
18809,
14,
3535,
3479,
3430,
16,
566,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
10099,
11135,
2422,
8,
277,
304,
267,
291,
423,
396,
3007,
20711,
8993,
10099,
8,
2734,
18809,
26,
18809,
14,
10174,
3430,
16,
566,
339,
347,
511,
2141,
8993,
3007,
20711,
8993,
10099,
3315,
8,
277,
304,
267,
347,
15917,
8,
17255,
304,
288,
367,
1962,
315,
18809,
26,
355,
372,
1962,
267,
291,
423,
396,
3007,
20711,
8993,
10099,
8,
7416,
9,
339,
768,
2759,
63,
5182,
63,
10675,
8,
24,
12,
378,
9,
272,
347,
511,
2141,
8993,
3007,
20711,
8993,
10099,
3315,
5810,
3259,
8,
277,
304,
267,
18809,
275,
291,
14,
1631,
14,
3937,
8,
3937,
63,
3702,
29,
20270,
18,
14,
9975,
14,
10099,
2141,
8993,
9,
267,
291,
423,
396,
3315,
5810,
3259,
8,
17255,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
arborh/tensorflow
|
tensorflow/python/keras/distribute/multi_worker_testing_utils.py
|
11
|
3136
|
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Utilities for testing multi-worker distribution strategies with Keras."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.python import keras
from tensorflow.python.data.ops import dataset_ops
from tensorflow.python.framework import dtypes
from tensorflow.python.keras.optimizer_v2 import gradient_descent
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import random_ops
def mnist_synthetic_dataset(batch_size, steps_per_epoch):
"""Generate synthetic MNIST dataset for testing."""
# train dataset
x_train = array_ops.ones([batch_size * steps_per_epoch, 28, 28, 1],
dtype=dtypes.float32)
y_train = array_ops.ones([batch_size * steps_per_epoch, 1],
dtype=dtypes.int32)
train_ds = dataset_ops.Dataset.from_tensor_slices((x_train, y_train))
train_ds = train_ds.repeat()
# train_ds = train_ds.shuffle(100)
train_ds = train_ds.batch(64, drop_remainder=True)
# eval dataset
x_test = random_ops.random_uniform([10000, 28, 28, 1], dtype=dtypes.float32)
y_test = random_ops.random_uniform([10000, 1],
minval=0,
maxval=9,
dtype=dtypes.int32)
eval_ds = dataset_ops.Dataset.from_tensor_slices((x_test, y_test))
eval_ds = eval_ds.repeat()
eval_ds = eval_ds.batch(64, drop_remainder=True)
return train_ds, eval_ds
def get_mnist_model(input_shape):
"""Define a deterministically-initialized CNN model for MNIST testing."""
model = keras.models.Sequential()
model.add(
keras.layers.Conv2D(
32,
kernel_size=(3, 3),
activation="relu",
input_shape=input_shape,
kernel_initializer=keras.initializers.TruncatedNormal(seed=99)))
model.add(keras.layers.BatchNormalization())
model.add(keras.layers.Flatten())
model.add(
keras.layers.Dense(
10,
activation="softmax",
kernel_initializer=keras.initializers.TruncatedNormal(seed=99)))
# TODO(yuefengz): optimizer with slot variables doesn't work because of
# optimizer's bug.
# TODO(yuefengz): we should not allow non-v2 optimizer.
model.compile(
loss=keras.losses.sparse_categorical_crossentropy,
optimizer=gradient_descent.SGD(learning_rate=0.001),
metrics=["accuracy"])
return model
|
apache-2.0
|
[
3,
1898,
20312,
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,
22905,
367,
5343,
3510,
13,
6599,
4084,
32647,
543,
1804,
30037,
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,
504,
3228,
14,
1548,
492,
11708,
199,
504,
3228,
14,
1548,
14,
576,
14,
1483,
492,
4789,
63,
1483,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
8811,
14,
12290,
63,
86,
18,
492,
6709,
63,
26269,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2196,
63,
1483,
421,
199,
318,
21945,
631,
63,
9466,
21231,
63,
5214,
8,
2912,
63,
890,
12,
7124,
63,
529,
63,
7367,
304,
523,
408,
6864,
9560,
21231,
603,
25392,
4789,
367,
5343,
1041,
523,
327,
3560,
4789,
523,
671,
63,
2834,
275,
1625,
63,
1483,
14,
4548,
779,
2912,
63,
890,
627,
7124,
63,
529,
63,
7367,
12,
7294,
12,
7294,
12,
413,
467,
2574,
2152,
29,
5717,
14,
1609,
708,
9,
523,
612,
63,
2834,
275,
1625,
63,
1483,
14,
4548,
779,
2912,
63,
890,
627,
7124,
63,
529,
63,
7367,
12,
413,
467,
2574,
2152,
29,
5717,
14,
442,
708,
9,
523,
3560,
63,
795,
275,
4789,
63,
1483,
14,
9271,
14,
504,
63,
3128,
63,
14865,
1332,
88,
63,
2834,
12,
612,
63,
2834,
430,
523,
3560,
63,
795,
275,
3560,
63,
795,
14,
8755,
342,
523,
327,
3560,
63,
795,
275,
3560,
63,
795,
14,
11777,
8,
1960,
9,
523,
3560,
63,
795,
275,
3560,
63,
795,
14,
2912,
8,
772,
12,
5978,
63,
23850,
29,
549,
9,
819,
327,
3468,
4789,
523,
671,
63,
396,
275,
2196,
63,
1483,
14,
2355,
63,
8830,
779,
9943,
12,
7294,
12,
7294,
12,
413,
467,
2152,
29,
5717,
14,
1609,
708,
9,
523,
612,
63,
396,
275,
2196,
63,
1483,
14,
2355,
63,
8830,
779,
9943,
12,
413,
467,
3660,
30135,
29,
16,
12,
3660,
23291,
29,
25,
12,
3660,
2152,
29,
5717,
14,
442,
708,
9,
523,
3468,
63,
795,
275,
4789,
63,
1483,
14,
9271,
14,
504,
63,
3128,
63,
14865,
1332,
88,
63,
396,
12,
612,
63,
396,
430,
523,
3468,
63,
795,
275,
3468,
63,
795,
14,
8755,
342,
523,
3468,
63,
795,
275,
3468,
63,
795,
14,
2912,
8,
772,
12,
5978,
63,
23850,
29,
549,
9,
819,
372,
3560,
63,
795,
12,
3468,
63,
795,
421,
199,
318,
664,
63,
32164,
63,
1238,
8,
1210,
63,
1392,
304,
523,
408,
16213,
282,
25286,
1183,
13,
12486,
445,
7178,
1402,
367,
603,
25392,
5343,
1041,
523,
1402,
275,
11708,
14,
992,
14,
18509,
342,
523,
1402,
14,
525,
8,
489,
11708,
14,
4359,
14,
11596,
18,
36,
8,
881,
4337,
12,
881,
5114,
63,
890,
2687,
19,
12,
650,
395,
881,
10361,
628,
12833,
401,
881,
1324,
63,
1392,
29,
1210,
63,
1392,
12,
881,
5114,
63,
6498,
29,
8811,
14,
2747,
6315,
14,
20460,
3153,
6241,
8,
5176,
29,
1020,
1724,
523,
1402,
14,
525,
8,
8811,
14,
4359,
14,
8842,
29169,
1012,
523,
1402,
14,
525,
8,
8811,
14,
4359,
14,
29302,
1012,
523,
1402,
14,
525,
8,
489,
11708,
14,
4359,
14,
15327,
8,
881,
1616,
12,
881,
10361,
628,
16395,
401,
881,
5114,
63,
6498,
29,
8811,
14,
2747,
6315,
14,
20460,
3153,
6241,
8,
5176,
29,
1020,
1724,
819,
327,
3254,
8,
89,
11116,
287,
6838,
304,
10736,
543,
9348,
2860,
3181,
1133,
1736,
2952,
402,
523,
327,
10736,
1159,
6519,
14,
523,
327,
3254,
8,
89,
11116,
287,
6838,
304,
781,
1077,
440,
2040,
2222,
13,
86,
18,
10736,
14,
523,
1402,
14,
2014,
8,
489,
5621,
29,
8811,
14,
17865,
14,
4421,
63,
16810,
63,
20363,
1150,
7537,
12,
489,
10736,
29,
7490,
63,
26269,
14,
4254,
36,
8,
10546,
63,
1866,
29,
16,
14,
4587,
395,
489,
7186,
6270,
13374,
3135,
523,
372,
1402,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
20312,
710,
9134,
6642,
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,
22905,
367,
5343,
3510,
13,
6599,
4084,
32647,
543,
1804,
30037,
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,
504,
3228,
14,
1548,
492,
11708,
199,
504,
3228,
14,
1548,
14,
576,
14,
1483,
492,
4789,
63,
1483,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
8811,
14,
12290,
63,
86,
18,
492,
6709,
63,
26269,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2196,
63,
1483,
421,
199,
318,
21945,
631,
63,
9466,
21231,
63,
5214,
8,
2912,
63,
890,
12,
7124,
63,
529,
63,
7367,
304,
523,
408,
6864,
9560,
21231,
603,
25392,
4789,
367,
5343,
1041,
523,
327,
3560,
4789,
523,
671,
63,
2834,
275,
1625,
63,
1483,
14,
4548,
779,
2912,
63,
890,
627,
7124,
63,
529,
63,
7367,
12,
7294,
12,
7294,
12,
413,
467,
2574,
2152,
29,
5717,
14,
1609,
708,
9,
523,
612,
63,
2834,
275,
1625,
63,
1483,
14,
4548,
779,
2912,
63,
890,
627,
7124,
63,
529,
63,
7367,
12,
413,
467,
2574,
2152,
29,
5717,
14,
442,
708,
9,
523,
3560,
63,
795,
275,
4789,
63,
1483,
14,
9271,
14,
504,
63,
3128,
63,
14865,
1332,
88,
63,
2834,
12,
612,
63,
2834,
430,
523,
3560,
63,
795,
275,
3560,
63,
795,
14,
8755,
342,
523,
327,
3560,
63,
795,
275,
3560,
63,
795,
14,
11777,
8,
1960,
9,
523,
3560,
63,
795,
275,
3560,
63,
795,
14,
2912,
8,
772,
12,
5978,
63,
23850,
29,
549,
9,
819,
327,
3468,
4789,
523,
671,
63,
396,
275,
2196,
63,
1483,
14,
2355,
63,
8830,
779,
9943,
12,
7294,
12,
7294,
12,
413,
467,
2152,
29,
5717,
14,
1609,
708,
9,
523,
612,
63,
396,
275,
2196,
63,
1483,
14,
2355,
63,
8830,
779,
9943,
12,
413,
467,
3660,
30135,
29,
16,
12,
3660,
23291,
29,
25,
12,
3660,
2152,
29,
5717,
14,
442,
708,
9,
523,
3468,
63,
795,
275,
4789,
63,
1483,
14,
9271,
14,
504,
63,
3128,
63,
14865,
1332,
88,
63,
396,
12,
612,
63,
396,
430,
523,
3468,
63,
795,
275,
3468,
63,
795,
14,
8755,
342,
523,
3468,
63,
795,
275,
3468,
63,
795,
14,
2912,
8,
772,
12,
5978,
63,
23850,
29,
549,
9,
819,
372,
3560,
63,
795,
12,
3468,
63,
795,
421,
199,
318,
664,
63,
32164,
63,
1238,
8,
1210,
63,
1392,
304,
523,
408,
16213,
282,
25286,
1183,
13,
12486,
445,
7178,
1402,
367,
603,
25392,
5343,
1041,
523,
1402,
275,
11708,
14,
992,
14,
18509,
342,
523,
1402,
14,
525,
8,
489,
11708,
14,
4359,
14,
11596,
18,
36,
8,
881,
4337,
12,
881,
5114,
63,
890,
2687,
19,
12,
650,
395,
881,
10361,
628,
12833,
401,
881,
1324,
63,
1392,
29,
1210,
63,
1392,
12,
881,
5114,
63,
6498,
29,
8811,
14,
2747,
6315,
14,
20460,
3153,
6241,
8,
5176,
29,
1020,
1724,
523,
1402,
14,
525,
8,
8811,
14,
4359,
14,
8842,
29169,
1012,
523,
1402,
14,
525,
8,
8811,
14,
4359,
14,
29302,
1012,
523,
1402,
14,
525,
8,
489,
11708,
14,
4359,
14,
15327,
8,
881,
1616,
12,
881,
10361,
628,
16395,
401,
881,
5114,
63,
6498,
29,
8811,
14,
2747,
6315,
14,
20460,
3153,
6241,
8,
5176,
29,
1020,
1724,
819,
327,
3254,
8,
89,
11116,
287,
6838,
304,
10736,
543,
9348,
2860,
3181,
1133,
1736,
2952,
402,
523,
327,
10736,
1159,
6519,
14,
523,
327,
3254,
8,
89,
11116,
287,
6838,
304,
781,
1077,
440,
2040,
2222,
13,
86,
18,
10736,
14,
523,
1402,
14,
2014,
8,
489,
5621,
29,
8811,
14,
17865,
14,
4421,
63,
16810,
63,
20363,
1150,
7537,
12,
489,
10736,
29,
7490,
63,
26269,
14,
4254,
36,
8,
10546,
63,
1866,
29,
16,
14,
4587,
395,
489,
7186,
6270,
13374,
3135,
523,
372,
1402,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
datacommonsorg/data
|
scripts/india_census/common/generic_base.py
|
1
|
5322
|
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import json
import csv
import copy
import pandas as pd
CENSUS_DATA_COLUMN_START = 7
class CensusGenericDataLoaderBase(object):
GENERIC_TEMPLATE_STAT_VAR = """Node: {StatisticalVariable}
description: "{description}"
typeOf: dcs:StatisticalVariable
populationType: schema:Person
measuredProperty: {measuredProperty}
"""
GENERIC_TEMPLATE_TMCF = """Node: E:IndiaCensus{year}_{dataset_name}->E0
typeOf: dcs:StatVarObservation
variableMeasured: C:IndiaCensus{year}_{dataset_name}->StatisticalVariable
observationDate: C:IndiaCensus{year}_{dataset_name}->Year
observationAbout: E:IndiaCensus{year}_{dataset_name}->E1
value: C:IndiaCensus{year}_{dataset_name}->Value
Node: E:IndiaCensus{year}_{dataset_name}->E1
typeOf: schema:Place
indianCensusAreaCode{year}: C:IndiaCensus{year}_{dataset_name}->census_location_id"""
"""An object that represents Census Data and its variables.
Attributes:
census_columns (list): It will have all the data column names of a dataset
census_year : Census year
csv_file_path : Path where cleaned csv file will be saved
data_file_path : Input XLS file from Census of India. Can be url or local path.
dataset_name : Census dataset name. Eg:Primary_Abstract_Data
existing_stat_var (list): List of existing stat vars that we don't need to generate
mcf (list): Description
mcf_file_path : Description
metadata_file_path : Description
raw_df : Raw census data as dataframe
stat_var_index (dict): local storage for census column name and corresponding statvar
tmcf_file_path : Path where generated tmcf file will be saved
"""
def __init__(self, data_file_path, metadata_file_path, mcf_file_path,
tmcf_file_path, csv_file_path, existing_stat_var, census_year,
dataset_name):
"""
Constructor
Args:
data_file_path : Input XLS file from Census of India. Can be url or local path
metadata_file_path : Meta data csv file which has attribute details
mcf_file_path : Path where generated mcf file will be saved
tmcf_file_path : Path where generated tmcf file will be saved
csv_file_path : Path where cleaned csv file will be saved
existing_stat_var : List of existing stat vars that we don't need to generate
census_year : Census Year
dataset_name : Census dataset name. Eg:Primary_Abstract_Data
"""
self.data_file_path = data_file_path
self.metadata_file_path = metadata_file_path
self.mcf_file_path = mcf_file_path
self.csv_file_path = csv_file_path
self.tmcf_file_path = tmcf_file_path
self.existing_stat_var = existing_stat_var
self.census_year = census_year
self.dataset_name = dataset_name
self.raw_df = None
self.stat_var_index = {}
self.census_columns = []
def _download_and_standardize(self):
dtype = {
'State': str,
'District': str,
'Subdistt': str,
"Town/Village": str
}
self.raw_df = pd.read_excel(self.data_file_path, dtype=dtype)
self.census_columns = self.raw_df.columns[CENSUS_DATA_COLUMN_START:]
def _format_location(self, row):
# In this specific format there is no Level defined.
# A non zero location code from the lowest administration area
# takes the precedence.
if row["Town/Village"] != "000000":
return row["Town/Village"]
elif row["Subdistt"] != "00000":
return row["Subdistt"]
elif row["District"] != "000":
return row["District"]
elif row["State"] != "00":
return row["State"]
else:
# This is india level location
return "0"
def _format_data(self):
# This function is overridden in the child class
pass
def _get_base_name(self, row):
# This function is overridden in the child class
name = "Count_"
return name
def _create_variable(self, data_row, **kwargs):
# This function is overridden in the child class
pass
def _create_mcf(self):
# This function is overridden in the child class
pass
def _create_tmcf(self):
with open(self.tmcf_file_path, 'w+', newline='') as f_out:
f_out.write(
self.GENERIC_TEMPLATE_TMCF.format(
year=self.census_year, dataset_name=self.dataset_name))
def process(self):
self._download_and_standardize()
self._create_mcf()
self._create_tmcf()
self._format_data()
|
apache-2.0
|
[
3,
1898,
25455,
4475,
20376,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
4178,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
747,
199,
646,
2022,
199,
646,
7392,
199,
646,
1331,
199,
646,
10634,
465,
6454,
199,
199,
35,
8456,
1668,
63,
3998,
63,
21436,
63,
7363,
275,
1520,
421,
199,
533,
445,
8764,
527,
9417,
1451,
5455,
1563,
8,
785,
304,
272,
22813,
18082,
63,
7433,
63,
4315,
63,
5568,
275,
408,
1716,
26,
469,
3391,
30364,
2773,
93,
199,
1802,
26,
5310,
1802,
7063,
199,
466,
3466,
26,
366,
1259,
26,
3391,
30364,
2773,
199,
16003,
804,
26,
4177,
26,
7344,
199,
19116,
3297,
3697,
26,
469,
19116,
3297,
3697,
93,
199,
199,
624,
339,
22813,
18082,
63,
7433,
63,
20690,
5487,
275,
408,
1716,
26,
662,
26,
607,
2391,
35,
8764,
527,
91,
3403,
26738,
5214,
63,
354,
93,
5118,
37,
16,
199,
466,
3466,
26,
366,
1259,
26,
11232,
5894,
11394,
8213,
199,
1975,
1352,
305,
3297,
26,
445,
26,
607,
2391,
35,
8764,
527,
91,
3403,
26738,
5214,
63,
354,
93,
5118,
3391,
30364,
2773,
199,
24299,
2506,
26,
445,
26,
607,
2391,
35,
8764,
527,
91,
3403,
26738,
5214,
63,
354,
93,
5118,
15731,
199,
24299,
18816,
26,
662,
26,
607,
2391,
35,
8764,
527,
91,
3403,
26738,
5214,
63,
354,
93,
5118,
37,
17,
199,
585,
26,
445,
26,
607,
2391,
35,
8764,
527,
91,
3403,
26738,
5214,
63,
354,
93,
5118,
1110,
199,
199,
1716,
26,
662,
26,
607,
2391,
35,
8764,
527,
91,
3403,
26738,
5214,
63,
354,
93,
5118,
37,
17,
199,
466,
3466,
26,
4177,
26,
11613,
199,
3558,
290,
35,
8764,
527,
11043,
3034,
91,
3403,
9160,
445,
26,
607,
2391,
35,
8764,
527,
91,
3403,
26738,
5214,
63,
354,
93,
5118,
2497,
25253,
63,
1985,
63,
344,
624,
272,
408,
2493,
909,
626,
8469,
445,
8764,
527,
3918,
436,
2399,
2860,
14,
2286,
9382,
26,
267,
286,
8764,
527,
63,
3406,
334,
513,
304,
2779,
911,
1172,
1006,
314,
666,
2763,
1561,
402,
282,
4789,
267,
286,
8764,
527,
63,
3403,
520,
445,
8764,
527,
5361,
267,
7392,
63,
493,
63,
515,
520,
6912,
2382,
12364,
7392,
570,
911,
506,
6290,
267,
666,
63,
493,
63,
515,
520,
6924,
1323,
5296,
570,
687,
445,
8764,
527,
402,
1010,
2391,
14,
6855,
506,
1166,
503,
2257,
931,
14,
267,
4789,
63,
354,
520,
445,
8764,
527,
4789,
536,
14,
662,
71,
26,
14908,
63,
8458,
63,
1451,
267,
3411,
63,
3736,
63,
1391,
334,
513,
304,
3820,
402,
3411,
5672,
6802,
626,
781,
2793,
1133,
1929,
370,
3550,
267,
333,
2177,
334,
513,
304,
11994,
267,
333,
2177,
63,
493,
63,
515,
520,
11994,
267,
3341,
63,
493,
63,
515,
520,
11994,
267,
3066,
63,
1587,
520,
13480,
286,
8764,
527,
666,
465,
27168,
267,
5672,
63,
1391,
63,
1080,
334,
807,
304,
2257,
4887,
367,
286,
8764,
527,
2763,
536,
436,
5226,
5672,
1391,
267,
7352,
2177,
63,
493,
63,
515,
520,
6912,
2382,
4046,
7352,
2177,
570,
911,
506,
6290,
272,
408,
339,
347,
636,
826,
721,
277,
12,
666,
63,
493,
63,
515,
12,
3341,
63,
493,
63,
515,
12,
333,
2177,
63,
493,
63,
515,
12,
326,
7352,
2177,
63,
493,
63,
515,
12,
7392,
63,
493,
63,
515,
12,
3411,
63,
3736,
63,
1391,
12,
286,
8764,
527,
63,
3403,
12,
326,
4789,
63,
354,
304,
267,
408,
267,
20297,
2728,
3033,
26,
288,
666,
63,
493,
63,
515,
520,
221,
6924,
1323,
5296,
570,
687,
445,
8764,
527,
402,
1010,
2391,
14,
6855,
506,
1166,
503,
2257,
931,
288,
3341,
63,
493,
63,
515,
520,
6288,
666,
7392,
570,
1314,
965,
2225,
2436,
288,
333,
2177,
63,
493,
63,
515,
520,
6912,
2382,
4046,
333,
2177,
570,
911,
506,
6290,
288,
7352,
2177,
63,
493,
63,
515,
520,
6912,
2382,
4046,
7352,
2177,
570,
911,
506,
6290,
288,
7392,
63,
493,
63,
515,
520,
6912,
2382,
12364,
7392,
570,
911,
506,
6290,
288,
3411,
63,
3736,
63,
1391,
520,
3820,
402,
3411,
5672,
6802,
626,
781,
2793,
1133,
1929,
370,
3550,
288,
286,
8764,
527,
63,
3403,
520,
445,
8764,
527,
28497,
288,
4789,
63,
354,
520,
445,
8764,
527,
4789,
536,
14,
662,
71,
26,
14908,
63,
8458,
63,
1451,
267,
408,
267,
291,
14,
576,
63,
493,
63,
515,
275,
666,
63,
493,
63,
515,
267,
291,
14,
2343,
63,
493,
63,
515,
275,
3341,
63,
493,
63,
515,
267,
291,
14,
77,
2177,
63,
493,
63,
515,
275,
333,
2177,
63,
493,
63,
515,
267,
291,
14,
4737,
63,
493,
63,
515,
275,
7392,
63,
493,
63,
515,
267,
291,
14,
7574,
2177,
63,
493,
63,
515,
275,
7352,
2177,
63,
493,
63,
515,
267,
291,
14,
5952,
63,
3736,
63,
1391,
275,
3411,
63,
3736,
63,
1391,
267,
291,
14,
2497,
25253,
63,
3403,
275,
286,
8764,
527,
63,
3403,
267,
291,
14,
5214,
63,
354,
275,
4789,
63,
354,
267,
291,
14,
1773,
63,
1587,
275,
488,
267,
291,
14,
3736,
63,
1391,
63,
1080,
275,
1052,
267,
291,
14,
2497,
25253,
63,
3406,
275,
942,
339,
347,
485,
4249,
63,
460,
63,
7935,
18980,
806,
8,
277,
304,
267,
2152,
275,
469,
288,
283,
2223,
356,
620,
12,
288,
283,
36,
5230,
319,
356,
620,
12,
288,
283,
2610,
2686,
84,
356,
620,
12,
288,
298,
52,
944,
15,
54,
30138,
582,
620,
267,
789,
267,
291,
14,
1773,
63,
1587,
275
] |
[
1898,
25455,
4475,
20376,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
4178,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
747,
199,
646,
2022,
199,
646,
7392,
199,
646,
1331,
199,
646,
10634,
465,
6454,
199,
199,
35,
8456,
1668,
63,
3998,
63,
21436,
63,
7363,
275,
1520,
421,
199,
533,
445,
8764,
527,
9417,
1451,
5455,
1563,
8,
785,
304,
272,
22813,
18082,
63,
7433,
63,
4315,
63,
5568,
275,
408,
1716,
26,
469,
3391,
30364,
2773,
93,
199,
1802,
26,
5310,
1802,
7063,
199,
466,
3466,
26,
366,
1259,
26,
3391,
30364,
2773,
199,
16003,
804,
26,
4177,
26,
7344,
199,
19116,
3297,
3697,
26,
469,
19116,
3297,
3697,
93,
199,
199,
624,
339,
22813,
18082,
63,
7433,
63,
20690,
5487,
275,
408,
1716,
26,
662,
26,
607,
2391,
35,
8764,
527,
91,
3403,
26738,
5214,
63,
354,
93,
5118,
37,
16,
199,
466,
3466,
26,
366,
1259,
26,
11232,
5894,
11394,
8213,
199,
1975,
1352,
305,
3297,
26,
445,
26,
607,
2391,
35,
8764,
527,
91,
3403,
26738,
5214,
63,
354,
93,
5118,
3391,
30364,
2773,
199,
24299,
2506,
26,
445,
26,
607,
2391,
35,
8764,
527,
91,
3403,
26738,
5214,
63,
354,
93,
5118,
15731,
199,
24299,
18816,
26,
662,
26,
607,
2391,
35,
8764,
527,
91,
3403,
26738,
5214,
63,
354,
93,
5118,
37,
17,
199,
585,
26,
445,
26,
607,
2391,
35,
8764,
527,
91,
3403,
26738,
5214,
63,
354,
93,
5118,
1110,
199,
199,
1716,
26,
662,
26,
607,
2391,
35,
8764,
527,
91,
3403,
26738,
5214,
63,
354,
93,
5118,
37,
17,
199,
466,
3466,
26,
4177,
26,
11613,
199,
3558,
290,
35,
8764,
527,
11043,
3034,
91,
3403,
9160,
445,
26,
607,
2391,
35,
8764,
527,
91,
3403,
26738,
5214,
63,
354,
93,
5118,
2497,
25253,
63,
1985,
63,
344,
624,
272,
408,
2493,
909,
626,
8469,
445,
8764,
527,
3918,
436,
2399,
2860,
14,
2286,
9382,
26,
267,
286,
8764,
527,
63,
3406,
334,
513,
304,
2779,
911,
1172,
1006,
314,
666,
2763,
1561,
402,
282,
4789,
267,
286,
8764,
527,
63,
3403,
520,
445,
8764,
527,
5361,
267,
7392,
63,
493,
63,
515,
520,
6912,
2382,
12364,
7392,
570,
911,
506,
6290,
267,
666,
63,
493,
63,
515,
520,
6924,
1323,
5296,
570,
687,
445,
8764,
527,
402,
1010,
2391,
14,
6855,
506,
1166,
503,
2257,
931,
14,
267,
4789,
63,
354,
520,
445,
8764,
527,
4789,
536,
14,
662,
71,
26,
14908,
63,
8458,
63,
1451,
267,
3411,
63,
3736,
63,
1391,
334,
513,
304,
3820,
402,
3411,
5672,
6802,
626,
781,
2793,
1133,
1929,
370,
3550,
267,
333,
2177,
334,
513,
304,
11994,
267,
333,
2177,
63,
493,
63,
515,
520,
11994,
267,
3341,
63,
493,
63,
515,
520,
11994,
267,
3066,
63,
1587,
520,
13480,
286,
8764,
527,
666,
465,
27168,
267,
5672,
63,
1391,
63,
1080,
334,
807,
304,
2257,
4887,
367,
286,
8764,
527,
2763,
536,
436,
5226,
5672,
1391,
267,
7352,
2177,
63,
493,
63,
515,
520,
6912,
2382,
4046,
7352,
2177,
570,
911,
506,
6290,
272,
408,
339,
347,
636,
826,
721,
277,
12,
666,
63,
493,
63,
515,
12,
3341,
63,
493,
63,
515,
12,
333,
2177,
63,
493,
63,
515,
12,
326,
7352,
2177,
63,
493,
63,
515,
12,
7392,
63,
493,
63,
515,
12,
3411,
63,
3736,
63,
1391,
12,
286,
8764,
527,
63,
3403,
12,
326,
4789,
63,
354,
304,
267,
408,
267,
20297,
2728,
3033,
26,
288,
666,
63,
493,
63,
515,
520,
221,
6924,
1323,
5296,
570,
687,
445,
8764,
527,
402,
1010,
2391,
14,
6855,
506,
1166,
503,
2257,
931,
288,
3341,
63,
493,
63,
515,
520,
6288,
666,
7392,
570,
1314,
965,
2225,
2436,
288,
333,
2177,
63,
493,
63,
515,
520,
6912,
2382,
4046,
333,
2177,
570,
911,
506,
6290,
288,
7352,
2177,
63,
493,
63,
515,
520,
6912,
2382,
4046,
7352,
2177,
570,
911,
506,
6290,
288,
7392,
63,
493,
63,
515,
520,
6912,
2382,
12364,
7392,
570,
911,
506,
6290,
288,
3411,
63,
3736,
63,
1391,
520,
3820,
402,
3411,
5672,
6802,
626,
781,
2793,
1133,
1929,
370,
3550,
288,
286,
8764,
527,
63,
3403,
520,
445,
8764,
527,
28497,
288,
4789,
63,
354,
520,
445,
8764,
527,
4789,
536,
14,
662,
71,
26,
14908,
63,
8458,
63,
1451,
267,
408,
267,
291,
14,
576,
63,
493,
63,
515,
275,
666,
63,
493,
63,
515,
267,
291,
14,
2343,
63,
493,
63,
515,
275,
3341,
63,
493,
63,
515,
267,
291,
14,
77,
2177,
63,
493,
63,
515,
275,
333,
2177,
63,
493,
63,
515,
267,
291,
14,
4737,
63,
493,
63,
515,
275,
7392,
63,
493,
63,
515,
267,
291,
14,
7574,
2177,
63,
493,
63,
515,
275,
7352,
2177,
63,
493,
63,
515,
267,
291,
14,
5952,
63,
3736,
63,
1391,
275,
3411,
63,
3736,
63,
1391,
267,
291,
14,
2497,
25253,
63,
3403,
275,
286,
8764,
527,
63,
3403,
267,
291,
14,
5214,
63,
354,
275,
4789,
63,
354,
267,
291,
14,
1773,
63,
1587,
275,
488,
267,
291,
14,
3736,
63,
1391,
63,
1080,
275,
1052,
267,
291,
14,
2497,
25253,
63,
3406,
275,
942,
339,
347,
485,
4249,
63,
460,
63,
7935,
18980,
806,
8,
277,
304,
267,
2152,
275,
469,
288,
283,
2223,
356,
620,
12,
288,
283,
36,
5230,
319,
356,
620,
12,
288,
283,
2610,
2686,
84,
356,
620,
12,
288,
298,
52,
944,
15,
54,
30138,
582,
620,
267,
789,
267,
291,
14,
1773,
63,
1587,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
AlphaSmartDog/DeepLearningNotes
|
Note-1 RNN-DNC择时/Note-1-2 PonderingDNCore L2正则化示例/DNCore.py
|
3
|
46187
|
# coding: utf-8
# # DNCore
#
# #### Hybrid computing using a neural network with dynamic external memory
# #### differentiable neural computer
#
# ##### 2017-09-02 DNCore封装
# - calculate 该模块不参与时序间传递
# - update 该模块参与时序间传递,需要上一时刻模块状态
# In[ ]:
import numpy as np
import tensorflow as tf
from sonnet.python.modules.base import AbstractModule
from sonnet.python.modules.basic import BatchApply, Linear, BatchFlatten
from sonnet.python.modules.rnn_core import RNNCore
from sonnet.python.modules.gated_rnn import LSTM
from sonnet.python.modules.basic_rnn import DeepRNN
# ## Access
# ### Memory Addressing
# #### 基于内容寻址机制 Content-based addressing
# - 使用余弦相似性处理外存储器Access 记忆矩阵中数值相似性
# - 读头控制和写头控制寻址机制组成模块
# In[ ]:
# Content-based addressing
class calculate_Content_based_addressing(AbstractModule):
"""
查询计算记忆矩阵每行内容记忆之间的余弦相似度,
使用softmax返回一个数值大小嵌入[0,1]区间tensor。
"""
def __init__(self,
num_heads,
word_size,
epsilon = 1e-6,
name='content_based_addressing'):
"""
Initializes the module.
Args:
num_heads: number of memory write heads or read heads.
word_size: memory word size.
epsilon: 鲁棒性功能添加
name: module name (default 'content_based_addressing')
"""
super().__init__(name=name) # 调用父类初始化
self._num_heads = num_heads
self._word_size = word_size
self._epsilon = epsilon
def _clip_L2_norm(self, tensor, axis=2):
"""
计算L2范数,余弦相似度公式分母,
这里进行数值平稳化处理
memory: A 3-D tensor of shape [batch_size, memory_size, word_size]
keys: A 3-D tensor of shape [batch_size, num_heads, word_size]
"""
quadratic_sum = tf.reduce_sum(tf.multiply(tensor, tensor), axis=axis, keep_dims=True)
return tf.sqrt(quadratic_sum + self._epsilon)
def _calculate_cosine_similarity(self, keys, memory):
"""
计算余弦相似度
Args:
memory: A 3-D tensor of shape [batch_size, memory_size, word_size]
keys: A 3-D tensor of shape [batch_size, num_heads, word_size]
Returns:
cosine_similarity: A 3-D tensor of shape `[batch_size, num_heads, memory_size]`.
"""
# 分子
matmul = tf.matmul(keys, memory, adjoint_b=True)
# 分母
memory_norm = self._clip_L2_norm(memory, axis=2)
keys_norm = self._clip_L2_norm(keys, axis=2)
# 余弦相似度计算, 添加epsilon消除极值影响;
cosine_similarity = matmul / (tf.matmul(keys_norm, memory_norm, adjoint_b=True) + self._epsilon)
return cosine_similarity
def _build(self, memory, keys, strengths):
"""
Connects the CosineWeights module into the graph.
计算余弦相似度
使用write strength或者read strength 适度缩放余弦相似度。
提高不同读写头的读头控制、写头控制区分度。
Args:
memory: A 3-D tensor of shape `[batch_size, memory_size, word_size]`.
keys: A 3-D tensor of shape `[batch_size, num_heads, word_size]`.
strengths: A 2-D tensor of shape `[batch_size, num_heads]`.
Returns:
cosine_similarity: A 3-D tensor of shape `[batch_size, num_heads, memory_size]`.
content_weighting: Weights tensor of shape `[batch_size, num_heads, memory_size]`.
"""
cosine_similarity = self._calculate_cosine_similarity(keys=keys, memory=memory)
transformed_strengths = tf.expand_dims(strengths, axis=-1)
sharp_activations = cosine_similarity * transformed_strengths
softmax = BatchApply(module_or_op=tf.nn.softmax)
return softmax(sharp_activations)
# #### 动态内存允许 Dynamic memory allocation
# - To allow the controller to free and allocate memory as needed,
# - we developed a differentiable analogue of the ‘free list’ memory allocation scheme,
# - whereby a list of available memory locations is maintained
# - by adding to and removing addresses from a linked list.
#
# In[ ]:
#Dynamic_memory_allocation
class update_Dynamic_memory_allocation(RNNCore):
"""
Memory usage that is increased by writing and decreased by reading.
This module is a pseudo-RNNCore whose state is a tensor with values in
the range [0, 1] indicating the usage of each of `memory_size` memory slots.
The usage is:
* Increased by writing, where usage is increased towards 1 at the write
addresses.
* Decreased by reading, where usage is decreased after reading from a
location when free_gates is close to 1.
"""
def __init__(
self,
memory_size,
epsilon = 1e-6,
name='dynamic_memory_allocation'):
"""Creates a module for dynamic memory allocation.
Args:
memory_size: Number of memory slots.
name: Name of the module.
"""
super().__init__(name=name)
self._memory_size = memory_size
self._epsilon = epsilon
def _build(
self,
prev_usage,
prev_write_weightings,
free_gates,
prev_read_weightings,
write_gates,
num_writes):
# 更新记忆矩阵每行的使用程度,区间[0,1]
# 程度数值随写入行为提高,读取行为降低
usage = self._update_usage_vector(
prev_usage,
prev_write_weightings,
free_gates,
prev_read_weightings)
# 记忆矩阵行位置释放
allocation_weightings = self._update_allocation_weightings(
usage, write_gates, num_writes)
return usage, allocation_weightings
def _update_usage_vector(
self,
prev_usage,
prev_write_weightings,
free_gates,
prev_read_weightings):
"""
The usage is:
* Increased by writing, where usage is increased towards 1 at the write
addresses.
* Decreased by reading, where usage is decreased after reading from a
location when free_gates is close to 1.
Args:
prev_usage: tensor of shape `[batch_size, memory_size]` giving
usage u_{t - 1} at the previous time step, with entries in range [0, 1].
prev_write_weightings: tensor of shape `[batch_size, num_writes, memory_size]`
giving write weights at previous time step.
free_gates: tensor of shape `[batch_size, num_reads]` which indicates
which read heads read memory that can now be freed.
prev_read_weightings: tensor of shape `[batch_size, num_reads, memory_size]`
giving read weights at previous time step.
Returns:
usage: tensor of shape `[batch_size, memory_size]` representing updated memory usage.
"""
prev_write_weightings = tf.stop_gradient(prev_write_weightings)
usage = self._calculate_usage_vector(prev_usage, prev_write_weightings)
retention = self._calculate_retention_vector(free_gates, prev_read_weightings)
return usage * retention
def _calculate_usage_vector(
self,
prev_usage,
prev_write_weightings):
"""
注意这里usage更新使用上一个时间步的数据
这个函数是特别添加处理多个写头写头控制情况,
这个函数计算在写头操作之后记忆矩阵的使用情况usage
Calcualtes the new usage after writing to memory.
Args:
prev_usage: tensor of shape `[batch_size, memory_size]`.
write_weightings: tensor of shape `[batch_size, num_writes, memory_size]`.
Returns:
New usage, a tensor of shape `[batch_size, memory_size]`.
"""
with tf.name_scope('usage_after_write'):
# Calculate the aggregated effect of all write heads
fit_prev_write_weightings = 1 - tf.reduce_prod(1 - prev_write_weightings, axis=[1])
usage_without_free = prev_usage + fit_prev_write_weightings - prev_usage * fit_prev_write_weightings
return usage_without_free
def _calculate_retention_vector(
self,
free_gates,
prev_read_weightings):
"""
The memory retention vector phi_t represents by how much each location
will not be freed by the gates.
Args:
free_gates: tensor of shape `[batch_size, num_reads]` with entries in the
range [0, 1] indicating the amount that locations read from can be
freed.
prev_write_weightings: tensor of shape `[batch_size, num_writes, memory_size]`.
Returns:
retention vector: [batch_size, memory_size]
"""
with tf.name_scope('usage_after_read'):
free_gates = tf.expand_dims(free_gates, axis=-1)
retention_vector = tf.reduce_prod(
1 - free_gates * prev_read_weightings,
axis=[1], name='retention')
return retention_vector
def _update_allocation_weightings(
self,
usage,
write_gates,
num_writes):
"""
Calculates freeness-based locations for writing to.
This finds unused memory by ranking the memory locations by usage, for each
write head. (For more than one write head, we use a "simulated new usage"
which takes into account the fact that the previous write head will increase
the usage in that area of the memory.)
Args:
usage: A tensor of shape `[batch_size, memory_size]` representing
current memory usage.
write_gates: A tensor of shape `[batch_size, num_writes]` with values in
the range [0, 1] indicating how much each write head does writing
based on the address returned here (and hence how much usage
increases).
num_writes: The number of write heads to calculate write weights for.
Returns:
tensor of shape `[batch_size, num_writes, memory_size]` containing the
freeness-based write locations. Note that this isn't scaled by `write_gate`;
this scaling must be applied externally.
"""
with tf.name_scope('update_allocation'):
write_gates = tf.expand_dims(write_gates, axis=-1)
allocation_weightings = []
for i in range(num_writes):
allocation_weightings.append(
self._calculate_allocation_weighting(usage))
# update usage to take into account writing to this new allocation
usage += ((1-usage) * write_gates[:,i,:] * allocation_weightings[i])
return tf.stack(allocation_weightings, axis=1)
def _calculate_allocation_weighting(self, usage):
"""
Computes allocation by sorting `usage`.
This corresponds to the value a = a_t[\phi_t[j]] in the paper.
Args:
usage: tensor of shape `[batch_size, memory_size]` indicating current
memory usage. This is equal to u_t in the paper when we only have one
write head, but for multiple write heads, one should update the usage
while iterating through the write heads to take into account the
allocation returned by this function.
Returns:
Tensor of shape `[batch_size, memory_size]` corresponding to allocation.
"""
with tf.name_scope('allocation'):
# Ensure values are not too small prior to cumprod.
usage = self._epsilon + (1 - self._epsilon) * usage
non_usage = 1 - usage
sorted_non_usage, indices = tf.nn.top_k(
non_usage, k = self._memory_size, name='sort')
sorted_usage = 1 - sorted_non_usage
prod_sorted_usage = tf.cumprod(sorted_usage, axis=1, exclusive=True)
sorted_allocation_weighting = sorted_non_usage * prod_sorted_usage
# This final line "unsorts" sorted_allocation, so that the indexing
# corresponds to the original indexing of `usage`.
inverse_indices = self._batch_invert_permutation(indices)
allocation_weighting = self._batch_gather(
sorted_allocation_weighting, inverse_indices)
return allocation_weighting
def _batch_invert_permutation(self, permutations):
"""
Returns batched `tf.invert_permutation` for every row in `permutations`.
"""
with tf.name_scope('batch_invert_permutation', values=[permutations]):
unpacked = tf.unstack(permutations, axis=0)
inverses = [tf.invert_permutation(permutation) for permutation in unpacked]
return tf.stack(inverses, axis=0)
def _batch_gather(self, values, indices):
"""Returns batched `tf.gather` for every row in the input."""
with tf.name_scope('batch_gather', values=[values, indices]):
unpacked = zip(tf.unstack(values), tf.unstack(indices))
result = [tf.gather(value, index) for value, index in unpacked]
return tf.stack(result)
@property
def state_size(self):
pass
@property
def output_size(self):
pass
# #### 基于读写行为顺序头控制 Temporal memory linkage
# In[ ]:
#Temporal_memory_linkage
class update_Temporal_memory_linkage(RNNCore):
"""
Keeps track of write order for forward and backward addressing.
This is a pseudo-RNNCore module, whose state is a pair `(link,
precedence_weights)`, where `link` is a (collection of) graphs for (possibly
multiple) write heads (represented by a tensor with values in the range
[0, 1]), and `precedence_weights` records the "previous write locations" used
to build the link graphs.
The function `directional_read_weights` computes addresses following the
forward and backward directions in the link graphs.
"""
def __init__(self,
memory_size,
num_writes,
name='temporal_memory_linkage'):
"""
Construct a TemporalLinkage module.
Args:
memory_size: The number of memory slots.
num_writes: The number of write heads.
name: Name of the module.
"""
super().__init__(name=name)
self._memory_size = memory_size
self._num_writes = num_writes
def _build(self,
prev_link,
prev_precedence_weightings,
prev_read_weightings,
write_weightings):
"""
calculate the updated linkage state given the write weights.
Args:
prev_links: A tensor of shape `[batch_size, num_writes, memory_size, memory_size]`
representing the previous link graphs for each write head.
prev_precedence_weightings: A tensor of shape `[batch_size, num_writes, memory_size]`
containing the previous precedence weights.
write_weightings: A tensor of shape `[batch_size, num_writes, memory_size]`
containing the memory addresses of the different write heads.
Returns:
link: A tensor of shape `[batch_size, num_writes, memory_size, memory_size]`
precedence_weightings: A tensor of shape `[batch_size, num_writes, memory_size]`
"""
link = self._update_link_matrix(
prev_link, prev_precedence_weightings, write_weightings)
precedence_weightings = self._update_precedence_weightings(
prev_precedence_weightings, write_weightings)
forward_weightings = self._calculate_directional_read_weightings(
link, prev_read_weightings, forward=True)
backward_weightings = self._calculate_directional_read_weightings(
link, prev_read_weightings, forward=False)
return link, precedence_weightings, forward_weightings, backward_weightings
def _update_link_matrix(self,
prev_link,
prev_precedence_weightings,
write_weightings):
"""
calculates the new link graphs.
For each write head, the link is a directed graph (represented by a matrix
with entries in range [0, 1]) whose vertices are the memory locations, and
an edge indicates temporal ordering of writes.
Args:
prev_links: A tensor of shape `[batch_size, num_writes, memory_size, memory_size]`
representing the previous link graphs for each write head.
prev_precedence_weights: A tensor of shape `[batch_size, num_writes, memory_size]`
which is the previous "aggregated" write weights for each write head.
write_weightings: A tensor of shape `[batch_size, num_writes, memory_size]`
containing the new locations in memory written to.
Returns:
A tensor of shape `[batch_size, num_writes, memory_size, memory_size]`
containing the new link graphs for each write head.
"""
with tf.name_scope('link'):
write_weightings_i = tf.expand_dims(write_weightings, axis=3)
write_weightings_j = tf.expand_dims(write_weightings, axis=2)
prev_link_scale = 1 - write_weightings_i - write_weightings_j
remove_old_link = prev_link_scale * prev_link
prev_precedence_weightings_j = tf.expand_dims(
prev_precedence_weightings, axis=2)
add_new_link = write_weightings_i * prev_precedence_weightings_j
link = remove_old_link + add_new_link
#Return the link with the diagonal set to zero, to remove self-looping edges.
batch_size = prev_link.get_shape()[0].value
mask = tf.zeros(shape=[batch_size, self._num_writes, self._memory_size],
dtype=prev_link.dtype)
fit_link = tf.matrix_set_diag(link, diagonal=mask)
return fit_link
def _update_precedence_weightings(self,
prev_precedence_weightings,
write_weightings):
"""
calculates the new precedence weights given the current write weights.
The precedence weights are the "aggregated write weights" for each write
head, where write weights with sum close to zero will leave the precedence
weights unchanged, but with sum close to one will replace the precedence
weights.
Args:
prev_precedence_weightings: A tensor of shape `[batch_size, num_writes, memory_size]`
containing the previous precedence weights.
write_weightings: A tensor of shape `[batch_size, num_writes, memory_size]`
containing the new write weights.
Returns:
A tensor of shape `[batch_size, num_writes, memory_size]`
containing the new precedence weights.
"""
with tf.name_scope('precedence_weightings'):
sum_writing = tf.reduce_sum(write_weightings, axis=2, keep_dims=True)
precedence_weightings = (1 - sum_writing) * prev_precedence_weightings + write_weightings
return precedence_weightings
def _calculate_directional_read_weightings(self,
link,
prev_read_weightings,
forward):
"""
calculates the forward or the backward read weightings.
For each read head (at a given address), there are `num_writes` link graphs to follow.
Thus this function computes a read address for each of the
`num_reads * num_writes` pairs of read and write heads.
Args:
link: tensor of shape `[batch_size, num_writes, memory_size, memory_size]`
representing the link graphs L_t.
prev_read_weightsing: tensor of shape `[batch_size, num_reads, memory_size]`
containing the previous read weights w_{t-1}^r.
forward: Boolean indicating whether to follow the "future" direction in
the link graph (True) or the "past" direction (False).
Returns:
tensor of shape `[batch_size, num_reads, num_writes, memory_size]`
Note: We calculate the forward and backward directions for each pair of
read and write heads; hence we need to tile the read weights and do a
sort of "outer product" to get this.
"""
with tf.name_scope('directional_read_weightings'):
# We calculate the forward and backward directions for each pair of
# read and write heads; hence we need to tile the read weights and do a
# sort of "outer product" to get this.
expanded_read_weightings = tf.stack([prev_read_weightings] * self._num_writes, axis=1)
directional_weightings = tf.matmul(expanded_read_weightings, link, adjoint_b=forward)
# Swap dimensions 1, 2 so order is [batch, reads, writes, memory]:
return tf.transpose(directional_weightings, perm=[0,2,1,3])
# ### Access
# In[ ]:
# MemoryAccess
class MemoryAccess(RNNCore):
"""
Access module of the Differentiable Neural Computer.
This memory module supports multiple read and write heads. It makes use of:
* `update_Temporal_memory_linkage` to track the temporal
ordering of writes in memory for each write head.
* `update_Dynamic_memory_allocation` for keeping track of
memory usage, where usage increase when a memory location is
written to, and decreases when memory is read from that
the controller says can be freed.
Write-address selection is done by an interpolation between content-based
lookup and using unused memory.
Read-address selection is done by an interpolation of content-based lookup
and following the link graph in the forward or backwards read direction.
"""
def __init__(self,
memory_size = 128,
word_size = 20,
num_reads = 1,
num_writes = 1,
name='memory_access'):
"""
Creates a MemoryAccess module.
Args:
memory_size: The number of memory slots (N in the DNC paper).
word_size: The width of each memory slot (W in the DNC paper)
num_reads: The number of read heads (R in the DNC paper).
num_writes: The number of write heads (fixed at 1 in the paper).
name: The name of the module.
"""
super().__init__(name=name)
self._memory_size = memory_size
self._word_size = word_size
self._num_reads = num_reads
self._num_writes = num_writes
self._write_content_mod = calculate_Content_based_addressing(
num_heads = self._num_writes,
word_size = self._word_size,
name = 'write_content_based_addressing')
self._read_content_mod = calculate_Content_based_addressing(
num_heads = self._num_reads,
word_size = self._word_size,
name = 'read_content_based_addressing')
self._temporal_linkage = update_Temporal_memory_linkage(
memory_size = self._memory_size,
num_writes = self._num_writes)
self._dynamic_allocation = update_Dynamic_memory_allocation(
memory_size = self._memory_size)
def _build(self, interface_vector, prev_state):
"""
Connects the MemoryAccess module into the graph.
Args:
inputs: tensor of shape `[batch_size, input_size]`.
This is used to control this access module.
prev_state: Instance of `AccessState` containing the previous state.
Returns:
A tuple `(output, next_state)`, where `output` is a tensor of shape
`[batch_size, num_reads, word_size]`, and `next_state` is the new
`AccessState` named tuple at the current time t.
"""
tape = self._Calculate_interface_parameters(interface_vector)
prev_memory, prev_read_weightings, prev_write_weightings, prev_precedence_weightings, prev_link, prev_usage = prev_state
# 更新写头
write_weightings, usage = self._update_write_weightings(tape,
prev_memory,
prev_usage,
prev_write_weightings,
prev_read_weightings)
# 更新记忆
memory = self._update_memory(prev_memory,
write_weightings,
tape['erase_vectors'],
tape['write_vectors'])
# 更新读头
read_weightings, link, precedence_weightings= self._update_read_weightings(tape,
memory,
write_weightings,
prev_read_weightings,
prev_precedence_weightings,
prev_link)
read_vectors = tf.matmul(read_weightings, memory)
state = (memory,
read_weightings,
write_weightings,
precedence_weightings,
link,
usage)
return read_vectors, state
def _update_write_weightings(self,
tape,
prev_memory,
prev_usage,
prev_write_weightings,
prev_read_weightings):
"""
Calculates the memory locations to write to.
This uses a combination of content-based lookup and finding an unused
location in memory, for each write head.
Args:
tape: Collection of inputs to the access module, including controls for
how to chose memory writing, such as the content to look-up and the
weighting between content-based and allocation-based addressing.
memory: A tensor of shape `[batch_size, memory_size, word_size]`
containing the current memory contents.
usage: Current memory usage, which is a tensor of shape
`[batch_size, memory_size]`, used for allocation-based addressing.
Returns:
tensor of shape `[batch_size, num_writes, memory_size]`
indicating where to write to (if anywhere) for each write head.
"""
with tf.name_scope('update_write_weightings', values=[tape, prev_memory, prev_usage]):
write_content_weightings = self._write_content_mod(
prev_memory,
tape['write_content_keys'],
tape['write_content_strengths'])
usage, write_allocation_weightings = self._dynamic_allocation(
prev_usage,
prev_write_weightings,
tape['free_gates'],
prev_read_weightings,
tape['write_gates'],
self._num_writes)
allocation_gates = tf.expand_dims(tape['allocation_gates'], axis=-1)
write_gates = tf.expand_dims(tape['write_gates'], axis=-1)
write_weightings = write_gates * (allocation_gates * write_allocation_weightings + (1 - allocation_gates) * write_content_weightings)
return write_weightings, usage
def _update_memory(self,
prev_memory,
write_weightings,
erase_vectors,
write_vectors):
"""
Args:
prev_memory: 3-D tensor of shape `[batch_size, memory_size, word_size]`.
write_weightings: 3-D tensor `[batch_size, num_writes, memory_size]`.
erase_vectors: 3-D tensor `[batch_size, num_writes, word_size]`.
write_vectors: 3-D tensor `[batch_size, num_writes, word_size]`.
Returns:
memory: 3-D tensor of shape `[batch_size, num_writes, word_size]`.
"""
with tf.name_scope('erase_old_memory', values=[prev_memory,
write_weightings,
erase_vectors]):
expand_write_weightings = tf.expand_dims(write_weightings, axis=3)
expand_erase_vectors = tf.expand_dims(erase_vectors, axis=2)
# 这里有多个写头,需要使用累成处理多个写头
erase_gates = expand_write_weightings * expand_erase_vectors
retention_gate = tf.reduce_prod(1 - erase_gates, axis=[1])
retention_memory = prev_memory * retention_gate
with tf.name_scope('additive_new_memory', values=[retention_memory,
write_weightings,
write_vectors]):
memory = retention_memory + tf.matmul(write_weightings, write_vectors, adjoint_a=True)
return memory
def _Calculate_interface_parameters(self, interface_vector):
"""
Interface parameters.
Before being used to parameterize the memory interactions,
the individual components are then processed with various
functions to ensure that they lie in the correct domain.
"""
# read_keys: [batch_size, num_reads, word_size]
read_keys = Linear(
output_size= self._num_reads * self._word_size,
name='read_keys')(interface_vector)
read_keys = tf.reshape(
read_keys, shape=[-1, self._num_reads, self._word_size])
# write_keys: [batch_size, num_writes, word_size]
write_keys = Linear(
output_size= self._num_writes * self._word_size,
name= 'write_keys')(interface_vector)
write_keys = tf.reshape(
write_keys, shape=[-1, self._num_writes, self._word_size])
# read_strengths: [batch_size, num_reads]
read_strengths = Linear(
output_size= self._num_reads,
name= 'read_strengths')(interface_vector)
read_strengths = 1 + tf.nn.softplus(read_strengths)
# write_strengths: [batch_size, num_writes]
write_strengths = Linear(
output_size= self._num_writes,
name='write_strengths')(interface_vector)
write_strengths = 1 + tf.nn.softplus(write_strengths)
# earse_vector: [batch_size, num_writes * word_size]
erase_vectors = Linear(
output_size= self._num_writes * self._word_size,
name='erase_vectors')(interface_vector)
erase_vectors = tf.reshape(
erase_vectors, shape=[-1, self._num_writes, self._word_size])
erase_vectors = tf.nn.sigmoid(erase_vectors)
# write_vectors: [batch_size, num_writes * word_size]
write_vectors = Linear(
output_size= self._num_writes * self._word_size,
name='write_vectors')(interface_vector)
write_vectors = tf.reshape(
write_vectors, shape=[-1, self._num_writes, self._word_size])
# free_gates: [batch_size, num_reads]
free_gates = Linear(
output_size= self._num_reads,
name='free_gates')(interface_vector)
free_gates = tf.nn.sigmoid(free_gates)
# allocation_gates: [batch_size, num_writes]
allocation_gates = Linear(
output_size= self._num_writes,
name='allocation_gates')(interface_vector)
allocation_gates = tf.nn.sigmoid(allocation_gates)
# write_gates: [batch_size, num_writes]
write_gates = Linear(
output_size= self._num_writes,
name='write_gates')(interface_vector)
write_gates = tf.nn.sigmoid(write_gates)
# read_modes: [batch_size, (1 + 2 * num_writes) * num_reads]
num_read_modes = 1 + 2 * self._num_writes
read_modes = Linear(
output_size= self._num_reads * num_read_modes,
name='read_modes')(interface_vector)
read_modes = tf.reshape(
read_modes, shape=[-1, self._num_reads, num_read_modes])
read_modes = BatchApply(tf.nn.softmax)(read_modes)
tape = {
'read_content_keys': read_keys,
'read_content_strengths': read_strengths,
'write_content_keys': write_keys,
'write_content_strengths': write_strengths,
'write_vectors': write_vectors,
'erase_vectors': erase_vectors,
'free_gates': free_gates,
'allocation_gates': allocation_gates,
'write_gates': write_gates,
'read_modes': read_modes,
}
return tape
def _update_read_weightings(self,
tape,
memory,
write_weightings,
prev_read_weightings,
prev_precedence_weightings,
prev_link):
"""
Calculates read weights for each read head.
The read weights are a combination of following the link graphs in the
forward or backward directions from the previous read position, and doing
content-based lookup. The interpolation between these different modes is
done by `inputs['read_mode']`.
Args:
inputs: Controls for this access module.
This contains the content-based keys to lookup,
and the weightings for the different read modes.
memory: A tensor of shape `[batch_size, memory_size, word_size]`
containing the current memory contents to do content-based lookup.
prev_read_weights: A tensor of shape `[batch_size, num_reads, memory_size]`
containing the previous read locations.
link: A tensor of shape `[batch_size, num_writes, memory_size, memory_size]`
containing the temporal write transition graphs.
Returns:
A tensor of shape `[batch_size, num_reads, memory_size]`
containing the read weights for each read head.
"""
with tf.name_scope(
'update_read_weightings',
values=[tape,
memory,
prev_read_weightings,
prev_precedence_weightings,
prev_link]):
read_content_weightings = self._read_content_mod(
memory,
tape['read_content_keys'],
tape['read_content_strengths'])
link, precedence_weightings, forward_weightings, backward_weightings = self._temporal_linkage(
prev_link,
prev_precedence_weightings,
prev_read_weightings,
write_weightings)
backward_mode = tape['read_modes'][:, :, :self._num_writes]
forward_mode = tape['read_modes'][:, :, self._num_writes:2 * self._num_writes]
content_mode = tape['read_modes'][:, :, 2 * self._num_writes]
backward_ = tf.expand_dims(backward_mode, axis=3) * backward_weightings
backward_ = tf.reduce_sum(backward_, axis=2)
forward_ = tf.expand_dims(forward_mode, axis=3) * forward_weightings
forward_ = tf.reduce_sum(forward_, axis=2)
content_ = tf.expand_dims(content_mode, axis=2) * read_content_weightings
read_weightings = backward_ + forward_ + content_
return read_weightings, link, precedence_weightings
@property
def state_size(self):
"""Returns a tuple of the shape of the state tensors."""
memory = tf.TensorShape([self._memory_size, self._word_size])
read_weightings = tf.TensorShape([self._num_reads, self._memory_size])
write_weightings = tf.TensorShape([self._num_writes, self._memory_size])
link = tf.TensorShape([self._num_writes, self._memory_size, self._memory_size])
precedence_weightings = tf.TensorShape([self._num_writes, self._memory_size])
usage = tf.TensorShape([self._memory_size])
return (memory,
read_weightings,
write_weightings,
precedence_weightings,
link,
usage)
@property
def output_size(self):
"""
Returns the output shape.
"""
return tf.TensorShape([self._num_reads, self._word_size])
# # DNCore 封装
# #### LSTM
# In[ ]:
class DNCoreLSTM(RNNCore):
"""
单层LSTM控制器DNCore
"""
def __init__(
self,
dnc_output_size,
hidden_size= 128,
forget_bias=1.0,
initializers=None,
partitioners=None,
regularizers=None,
use_peepholes=False,
use_layer_norm=False,
hidden_clip_value=None,
cell_clip_value=None,
custom_getter=None,
memory_size= 256,
word_size= 128,
num_read_heads= 3,
num_write_heads= 1,
name='DNCoreLSTM'):
super().__init__(name=name) # 调用父类初始化
with self._enter_variable_scope():
controller = LSTM(
hidden_size=hidden_size,
forget_bias=forget_bias,
initializers=initializers,
partitioners=partitioners,
regularizers=regularizers,
use_peepholes=use_peepholes,
use_layer_norm=use_layer_norm,
hidden_clip_value=hidden_clip_value,
cell_clip_value=cell_clip_value,
custom_getter=custom_getter)
self._controller = controller
self._access = MemoryAccess(
memory_size= memory_size,
word_size= word_size,
num_reads= num_read_heads,
num_writes= num_write_heads)
self._dnc_output_size = dnc_output_size
self._num_read_heads = num_read_heads
self._word_size = word_size
def _build(self, inputs, prev_tape):
prev_controller_state, prev_access_state, prev_read_vectors = prev_tape
batch_flatten = BatchFlatten()
controller_input = tf.concat(
[batch_flatten(inputs), batch_flatten(prev_read_vectors)], axis= 1)
# 控制器处理数据
controller_output, controller_state = self._controller(controller_input, prev_controller_state)
# 外存储器交互
read_vectors, access_state = self._access(controller_output, prev_access_state)
# DNC 输出
dnc_output = tf.concat(
[controller_output, batch_flatten(read_vectors)], axis= 1)
dnc_output = Linear(
self._dnc_output_size, name='dnc_output')(dnc_output)
return dnc_output, (controller_state, access_state, read_vectors)
def initial_state(self, batch_size, dtype=tf.float32):
controller_state= self._controller.initial_state(batch_size, dtype)
access_state= self._access.initial_state(batch_size, dtype)
read_vectors= tf.zeros([batch_size, self._num_read_heads, self._word_size], dtype=dtype)
return (controller_state, access_state, read_vectors)
@property
def state_size(self):
controller_state= self._controller.state_size
access_state= self._access.state_size
read_vectors= tf.TensorShape([self._num_read_heads, self._word_size])
return (controller_state, access_state, read_vectors)
@property
def output_size(self):
return tf.TensorShape([self._dnc_output_size])
# #### DeepRNN
# In[ ]:
class DNCoreDeepLSTM(RNNCore):
def __init__(
self,
dnc_output_size,
hidden_size= 128,
forget_bias=1.0,
initializers=None,
partitioners=None,
regularizers=None,
use_peepholes=False,
use_layer_norm=False,
hidden_clip_value=None,
cell_clip_value=None,
custom_getter=None,
memory_size= 256,
word_size= 128,
num_read_heads= 3,
num_write_heads= 1,
name='DNCoreDeepLSTM'):
super().__init__(name=name) # 调用父类初始化
with self._enter_variable_scope():
layer_1 = LSTM(
hidden_size=hidden_size,
forget_bias=forget_bias,
initializers=initializers,
partitioners=partitioners,
regularizers=regularizers,
use_peepholes=use_peepholes,
use_layer_norm=use_layer_norm,
hidden_clip_value=hidden_clip_value,
cell_clip_value=cell_clip_value,
custom_getter=custom_getter)
layer_2 = LSTM(
hidden_size=hidden_size,
forget_bias=forget_bias,
initializers=initializers,
partitioners=partitioners,
regularizers=regularizers,
use_peepholes=use_peepholes,
use_layer_norm=use_layer_norm,
hidden_clip_value=hidden_clip_value,
cell_clip_value=cell_clip_value,
custom_getter=custom_getter)
layer_3 = LSTM(
hidden_size=hidden_size,
forget_bias=forget_bias,
initializers=initializers,
partitioners=partitioners,
regularizers=regularizers,
use_peepholes=use_peepholes,
use_layer_norm=use_layer_norm,
hidden_clip_value=hidden_clip_value,
cell_clip_value=cell_clip_value,
custom_getter=custom_getter)
self._controller = DeepRNN([layer_1, layer_2, layer_3])
self._access = MemoryAccess(
memory_size= memory_size,
word_size= word_size,
num_reads= num_read_heads,
num_writes= num_write_heads)
self._dnc_output_size = dnc_output_size
self._num_read_heads = num_read_heads
self._word_size = word_size
def _build(self, inputs, prev_tape):
prev_controller_state, prev_access_state, prev_read_vectors = prev_tape
batch_flatten = BatchFlatten()
controller_input = tf.concat(
[batch_flatten(inputs), batch_flatten(prev_read_vectors)], axis= 1)
# 控制器处理数据
controller_output, controller_state = self._controller(controller_input, prev_controller_state)
# 外存储器交互
read_vectors, access_state = self._access(controller_output, prev_access_state)
# DNC 输出
dnc_output = tf.concat(
[controller_output, batch_flatten(read_vectors)], axis= 1)
dnc_output = Linear(
self._dnc_output_size, name='dnc_output')(dnc_output)
return dnc_output, (controller_state, access_state, read_vectors)
def initial_state(self, batch_size, dtype=tf.float32):
controller_state= self._controller.initial_state(batch_size, dtype)
access_state= self._access.initial_state(batch_size, dtype)
read_vectors= tf.zeros([batch_size, self._num_read_heads, self._word_size], dtype=dtype)
return (controller_state, access_state, read_vectors)
@property
def state_size(self):
controller_state= self._controller.state_size
access_state= self._access.state_size
read_vectors= tf.TensorShape([self._num_read_heads, self._word_size])
return (controller_state, access_state, read_vectors)
@property
def output_size(self):
return tf.TensorShape([self._dnc_output_size])
|
mit
|
[
199,
3,
2803,
26,
2774,
13,
24,
199,
199,
3,
327,
24842,
5402,
199,
3,
221,
199,
3,
14055,
29591,
14601,
17226,
1808,
282,
1279,
4889,
2784,
543,
8336,
5957,
4402,
199,
3,
14055,
26796,
461,
1279,
4889,
24189,
199,
3,
221,
199,
3,
22906,
9708,
13,
1643,
13,
996,
24842,
5402,
15348,
224,
29655,
228,
199,
3,
446,
8671,
221,
8400,
99,
29887,
30899,
246,
19594,
32549,
4344,
237,
20494,
15013,
238,
24831,
17848,
255,
14333,
241,
199,
3,
446,
1678,
221,
8400,
99,
29887,
30899,
246,
32549,
4344,
237,
20494,
15013,
238,
24831,
17848,
255,
14333,
241,
12356,
166,
251,
223,
22274,
22661,
9372,
20494,
9051,
120,
29887,
30899,
246,
30729,
199,
199,
3,
1010,
59,
16246,
199,
199,
646,
2680,
465,
980,
199,
646,
3228,
465,
2833,
199,
199,
504,
27970,
846,
14,
1548,
14,
3112,
14,
1095,
492,
11836,
2377,
199,
504,
27970,
846,
14,
1548,
14,
3112,
14,
4316,
492,
17206,
16581,
12,
12489,
12,
17206,
29302,
199,
504,
27970,
846,
14,
1548,
14,
3112,
14,
12845,
63,
1018,
492,
26009,
5402,
199,
504,
27970,
846,
14,
1548,
14,
3112,
14,
71,
972,
63,
12845,
492,
491,
16644,
199,
504,
27970,
846,
14,
1548,
14,
3112,
14,
4316,
63,
12845,
492,
577,
7840,
24124,
421,
199,
3,
925,
11003,
199,
3,
6754,
15825,
9906,
316,
9948,
199,
3,
14055,
7094,
254,
119,
6923,
237,
17950,
228,
10270,
118,
15150,
8698,
252,
223,
25138,
9051,
115,
6646,
13,
6788,
2287,
316,
199,
3,
446,
221,
30026,
11046,
248,
12586,
100,
15545,
117,
17848,
121,
17182,
101,
11546,
227,
24946,
11546,
245,
29846,
162,
225,
102,
162,
248,
102,
3946,
9065,
107,
109,
16989,
229,
164,
254,
103,
166,
247,
114,
17088,
12211,
32678,
15545,
117,
17848,
121,
17182,
101,
199,
3,
446,
221,
8400,
8698,
98,
113,
17797,
101,
9051,
115,
30557,
17950,
248,
11546,
113,
17797,
101,
9051,
115,
15150,
8698,
252,
223,
25138,
9051,
115,
32061,
16888,
29887,
30899,
246,
199,
199,
3,
1010,
59,
16246,
199,
199,
3,
6646,
13,
6788,
2287,
316,
199,
533,
8671,
63,
2714,
63,
6788,
63,
1562,
316,
8,
8458,
2377,
304,
272,
408,
272,
8853,
18304,
23179,
14082,
95,
21895,
14082,
109,
16989,
229,
164,
254,
103,
166,
247,
114,
28285,
238,
12609,
17950,
228,
10270,
118,
14082,
109,
16989,
229,
17837,
234,
24831,
8106,
11046,
248,
12586,
100,
15545,
117,
17848,
121,
32413,
12356,
272,
221,
30026,
16395,
13201,
243,
22234,
12033,
12211,
32678,
28232,
15348,
238,
162,
114,
235,
18236,
59,
16,
12,
17,
61,
21018,
119,
24831,
3128,
20061,
2286,
408,
2286,
347,
636,
826,
721,
277,
12,
355,
1967,
63,
17033,
12,
8892,
4349,
63,
890,
12,
355,
14030,
275,
413,
69,
13,
22,
12,
355,
536,
534,
1317,
63,
6788,
63,
1562,
316,
735,
267,
408,
267,
6026,
6491,
314,
859,
14,
398,
3033,
26,
881,
1967,
63,
17033,
26,
1329,
402,
4402,
2218,
25362,
503,
1586,
25362,
14,
881,
4349,
63,
890,
26,
4402,
4349,
1568,
14,
881,
14030,
26,
10469,
111,
224,
163,
97,
241,
17182,
101,
12163,
254,
28371,
163,
116,
8698,
233,
255,
881,
536,
26,
859,
536,
334,
885,
283,
1317,
63,
6788,
63,
1562,
316,
358,
267,
408,
267,
1613,
11027,
826,
721,
354,
29,
354,
9,
327,
9065,
109,
226,
11428,
164,
231,
115,
10100,
231,
252,
25712,
234,
21018,
245,
267,
291,
423,
1507,
63,
17033,
275,
1967,
63,
17033,
267,
291,
423,
1027,
63,
890,
275,
4349,
63,
890,
267,
291,
423,
15761,
275,
14030,
268,
339,
347,
485,
7548,
63,
44,
18,
63,
4791,
8,
277,
12,
2345,
12,
3114,
29,
18,
304,
267,
408,
267,
9065,
107,
95,
21895,
44,
18,
165,
235,
226,
12211,
12356,
11046,
248,
12586,
100,
15545,
117,
17848,
121,
32413,
19150,
21041,
21514,
28285,
236,
12356,
267,
9065,
124,
248,
10770,
235,
13201,
250,
12609,
12211,
32678,
25274,
25203,
112,
21018,
245,
11546,
227,
24946,
267,
4402,
26,
437,
650,
13,
36,
2345,
402,
2215,
359,
2912,
63,
890,
12,
4402,
63,
890,
12,
4349,
63,
890,
61,
267,
2883,
26,
437,
650,
13,
36,
2345,
402,
2215,
359,
2912,
63,
890,
12,
1967,
63,
17033,
12,
4349,
63,
890,
61,
27439,
408,
267,
16744,
19826,
63,
1838,
275,
2833,
14,
5270,
63,
1838,
8,
3249,
14,
13710,
8,
3128,
12,
2345,
395,
3114,
29,
3127,
12,
4215,
63,
5380,
29,
549,
9,
27144,
372,
2833,
14,
5079,
8,
14567,
19826,
63,
1838,
435,
291,
423,
15761,
9,
17635,
347,
485,
12063,
63,
28485,
63,
21965,
8,
277,
12,
2883,
12,
4402,
304,
2728,
408,
267,
9065,
107,
95,
21895,
11046,
248,
12586,
100,
15545,
117,
17848,
121,
32413,
267,
3033,
26,
755,
288,
4402,
26,
437,
650,
13,
36,
2345,
402,
2215,
359,
2912,
63,
890,
12,
4402,
63,
890,
12,
4349,
63,
890,
61,
288,
2883,
26,
437,
650,
13,
36,
2345,
402,
2215,
359,
2912,
63,
890,
12,
1967,
63,
17033,
12,
4349,
63,
890,
61,
27439,
1803,
26,
288,
28188,
63,
21965,
26,
437,
650,
13,
36,
2345,
402,
2215,
14505,
2912,
63,
890,
12,
1967,
63,
17033,
12,
4402,
63,
890,
20336,
267,
408,
267,
327,
7094,
231,
229,
14651,
239,
267,
2530,
3703,
275,
2833,
14,
14465,
8,
1612,
12,
4402,
12,
24132,
63,
66,
29,
549,
9,
267,
327,
7094,
231,
229,
28285,
236,
267,
4402,
63,
4791,
275,
291,
423,
7548,
63,
44,
18,
63,
4791,
8,
4844,
12,
3114,
29,
18,
9,
267,
2883,
63,
4791,
275,
291,
423,
7548,
63,
44,
18,
63,
4791,
8,
1612,
12,
3114,
29,
18,
9,
267,
327,
221,
11046,
248,
12586,
100,
15545,
117,
17848,
121,
32413,
14082,
95,
21895,
12356,
8853,
116,
8698,
233,
255,
15761,
163,
115,
231,
31459,
19349,
224,
32678,
22918,
110,
22747,
236,
8454,
250,
267,
28188,
63,
21965,
275,
2530,
3703,
1182,
334,
3249,
14,
14465,
8,
1612,
63,
4791,
12,
4402,
63,
4791,
12,
24132,
63,
66,
29,
549,
9,
435,
291,
423,
15761,
9,
267,
372,
28188,
63,
21965,
17635,
347,
485,
1506,
8,
277,
12,
4402,
12,
2883,
12,
410,
15796,
83,
304,
267,
408,
267,
15175,
83,
314,
445,
736,
1132,
23885,
859,
1901
] |
[
3,
2803,
26,
2774,
13,
24,
199,
199,
3,
327,
24842,
5402,
199,
3,
221,
199,
3,
14055,
29591,
14601,
17226,
1808,
282,
1279,
4889,
2784,
543,
8336,
5957,
4402,
199,
3,
14055,
26796,
461,
1279,
4889,
24189,
199,
3,
221,
199,
3,
22906,
9708,
13,
1643,
13,
996,
24842,
5402,
15348,
224,
29655,
228,
199,
3,
446,
8671,
221,
8400,
99,
29887,
30899,
246,
19594,
32549,
4344,
237,
20494,
15013,
238,
24831,
17848,
255,
14333,
241,
199,
3,
446,
1678,
221,
8400,
99,
29887,
30899,
246,
32549,
4344,
237,
20494,
15013,
238,
24831,
17848,
255,
14333,
241,
12356,
166,
251,
223,
22274,
22661,
9372,
20494,
9051,
120,
29887,
30899,
246,
30729,
199,
199,
3,
1010,
59,
16246,
199,
199,
646,
2680,
465,
980,
199,
646,
3228,
465,
2833,
199,
199,
504,
27970,
846,
14,
1548,
14,
3112,
14,
1095,
492,
11836,
2377,
199,
504,
27970,
846,
14,
1548,
14,
3112,
14,
4316,
492,
17206,
16581,
12,
12489,
12,
17206,
29302,
199,
504,
27970,
846,
14,
1548,
14,
3112,
14,
12845,
63,
1018,
492,
26009,
5402,
199,
504,
27970,
846,
14,
1548,
14,
3112,
14,
71,
972,
63,
12845,
492,
491,
16644,
199,
504,
27970,
846,
14,
1548,
14,
3112,
14,
4316,
63,
12845,
492,
577,
7840,
24124,
421,
199,
3,
925,
11003,
199,
3,
6754,
15825,
9906,
316,
9948,
199,
3,
14055,
7094,
254,
119,
6923,
237,
17950,
228,
10270,
118,
15150,
8698,
252,
223,
25138,
9051,
115,
6646,
13,
6788,
2287,
316,
199,
3,
446,
221,
30026,
11046,
248,
12586,
100,
15545,
117,
17848,
121,
17182,
101,
11546,
227,
24946,
11546,
245,
29846,
162,
225,
102,
162,
248,
102,
3946,
9065,
107,
109,
16989,
229,
164,
254,
103,
166,
247,
114,
17088,
12211,
32678,
15545,
117,
17848,
121,
17182,
101,
199,
3,
446,
221,
8400,
8698,
98,
113,
17797,
101,
9051,
115,
30557,
17950,
248,
11546,
113,
17797,
101,
9051,
115,
15150,
8698,
252,
223,
25138,
9051,
115,
32061,
16888,
29887,
30899,
246,
199,
199,
3,
1010,
59,
16246,
199,
199,
3,
6646,
13,
6788,
2287,
316,
199,
533,
8671,
63,
2714,
63,
6788,
63,
1562,
316,
8,
8458,
2377,
304,
272,
408,
272,
8853,
18304,
23179,
14082,
95,
21895,
14082,
109,
16989,
229,
164,
254,
103,
166,
247,
114,
28285,
238,
12609,
17950,
228,
10270,
118,
14082,
109,
16989,
229,
17837,
234,
24831,
8106,
11046,
248,
12586,
100,
15545,
117,
17848,
121,
32413,
12356,
272,
221,
30026,
16395,
13201,
243,
22234,
12033,
12211,
32678,
28232,
15348,
238,
162,
114,
235,
18236,
59,
16,
12,
17,
61,
21018,
119,
24831,
3128,
20061,
2286,
408,
2286,
347,
636,
826,
721,
277,
12,
355,
1967,
63,
17033,
12,
8892,
4349,
63,
890,
12,
355,
14030,
275,
413,
69,
13,
22,
12,
355,
536,
534,
1317,
63,
6788,
63,
1562,
316,
735,
267,
408,
267,
6026,
6491,
314,
859,
14,
398,
3033,
26,
881,
1967,
63,
17033,
26,
1329,
402,
4402,
2218,
25362,
503,
1586,
25362,
14,
881,
4349,
63,
890,
26,
4402,
4349,
1568,
14,
881,
14030,
26,
10469,
111,
224,
163,
97,
241,
17182,
101,
12163,
254,
28371,
163,
116,
8698,
233,
255,
881,
536,
26,
859,
536,
334,
885,
283,
1317,
63,
6788,
63,
1562,
316,
358,
267,
408,
267,
1613,
11027,
826,
721,
354,
29,
354,
9,
327,
9065,
109,
226,
11428,
164,
231,
115,
10100,
231,
252,
25712,
234,
21018,
245,
267,
291,
423,
1507,
63,
17033,
275,
1967,
63,
17033,
267,
291,
423,
1027,
63,
890,
275,
4349,
63,
890,
267,
291,
423,
15761,
275,
14030,
268,
339,
347,
485,
7548,
63,
44,
18,
63,
4791,
8,
277,
12,
2345,
12,
3114,
29,
18,
304,
267,
408,
267,
9065,
107,
95,
21895,
44,
18,
165,
235,
226,
12211,
12356,
11046,
248,
12586,
100,
15545,
117,
17848,
121,
32413,
19150,
21041,
21514,
28285,
236,
12356,
267,
9065,
124,
248,
10770,
235,
13201,
250,
12609,
12211,
32678,
25274,
25203,
112,
21018,
245,
11546,
227,
24946,
267,
4402,
26,
437,
650,
13,
36,
2345,
402,
2215,
359,
2912,
63,
890,
12,
4402,
63,
890,
12,
4349,
63,
890,
61,
267,
2883,
26,
437,
650,
13,
36,
2345,
402,
2215,
359,
2912,
63,
890,
12,
1967,
63,
17033,
12,
4349,
63,
890,
61,
27439,
408,
267,
16744,
19826,
63,
1838,
275,
2833,
14,
5270,
63,
1838,
8,
3249,
14,
13710,
8,
3128,
12,
2345,
395,
3114,
29,
3127,
12,
4215,
63,
5380,
29,
549,
9,
27144,
372,
2833,
14,
5079,
8,
14567,
19826,
63,
1838,
435,
291,
423,
15761,
9,
17635,
347,
485,
12063,
63,
28485,
63,
21965,
8,
277,
12,
2883,
12,
4402,
304,
2728,
408,
267,
9065,
107,
95,
21895,
11046,
248,
12586,
100,
15545,
117,
17848,
121,
32413,
267,
3033,
26,
755,
288,
4402,
26,
437,
650,
13,
36,
2345,
402,
2215,
359,
2912,
63,
890,
12,
4402,
63,
890,
12,
4349,
63,
890,
61,
288,
2883,
26,
437,
650,
13,
36,
2345,
402,
2215,
359,
2912,
63,
890,
12,
1967,
63,
17033,
12,
4349,
63,
890,
61,
27439,
1803,
26,
288,
28188,
63,
21965,
26,
437,
650,
13,
36,
2345,
402,
2215,
14505,
2912,
63,
890,
12,
1967,
63,
17033,
12,
4402,
63,
890,
20336,
267,
408,
267,
327,
7094,
231,
229,
14651,
239,
267,
2530,
3703,
275,
2833,
14,
14465,
8,
1612,
12,
4402,
12,
24132,
63,
66,
29,
549,
9,
267,
327,
7094,
231,
229,
28285,
236,
267,
4402,
63,
4791,
275,
291,
423,
7548,
63,
44,
18,
63,
4791,
8,
4844,
12,
3114,
29,
18,
9,
267,
2883,
63,
4791,
275,
291,
423,
7548,
63,
44,
18,
63,
4791,
8,
1612,
12,
3114,
29,
18,
9,
267,
327,
221,
11046,
248,
12586,
100,
15545,
117,
17848,
121,
32413,
14082,
95,
21895,
12356,
8853,
116,
8698,
233,
255,
15761,
163,
115,
231,
31459,
19349,
224,
32678,
22918,
110,
22747,
236,
8454,
250,
267,
28188,
63,
21965,
275,
2530,
3703,
1182,
334,
3249,
14,
14465,
8,
1612,
63,
4791,
12,
4402,
63,
4791,
12,
24132,
63,
66,
29,
549,
9,
435,
291,
423,
15761,
9,
267,
372,
28188,
63,
21965,
17635,
347,
485,
1506,
8,
277,
12,
4402,
12,
2883,
12,
410,
15796,
83,
304,
267,
408,
267,
15175,
83,
314,
445,
736,
1132,
23885,
859,
1901,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kchodorow/tensorflow
|
tensorflow/python/training/optimizer_test.py
|
74
|
8790
|
# 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.
# ==============================================================================
"""Functional test for optimizer."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import gradients_impl
from tensorflow.python.ops import state_ops
from tensorflow.python.ops import variables
from tensorflow.python.platform import test
from tensorflow.python.training import gradient_descent
class OptimizerTest(test.TestCase):
def testBasic(self):
for dtype in [dtypes.half, dtypes.float32, dtypes.float64]:
with self.test_session():
var0 = variables.Variable([1.0, 2.0], dtype=dtype)
var1 = variables.Variable([3.0, 4.0], dtype=dtype)
cost = 5 * var0 + 3 * var1
global_step = variables.Variable(
array_ops.zeros([], dtypes.int64), name='global_step')
sgd_op = gradient_descent.GradientDescentOptimizer(3.0)
opt_op = sgd_op.minimize(cost, global_step, [var0, var1])
variables.global_variables_initializer().run()
# Fetch params to validate initial values
self.assertAllClose([1.0, 2.0], var0.eval())
self.assertAllClose([3.0, 4.0], var1.eval())
# Run 1 step of sgd through optimizer
opt_op.run()
# Validate updated params
self.assertAllClose([-14., -13.], var0.eval())
self.assertAllClose([-6., -5.], var1.eval())
def testAggregationMethod(self):
for dtype in [dtypes.half, dtypes.float32, dtypes.float64]:
with self.test_session():
var0 = variables.Variable([1.0, 2.0], dtype=dtype)
var1 = variables.Variable([3.0, 4.0], dtype=dtype)
cost = 5 * var0 + 3 * var1
global_step = variables.Variable(
array_ops.zeros([], dtypes.int64), name='global_step')
sgd_op = gradient_descent.GradientDescentOptimizer(3.0)
opt_op = sgd_op.minimize(
cost,
global_step, [var0, var1],
aggregation_method=gradients_impl.AggregationMethod.
EXPERIMENTAL_ACCUMULATE_N)
variables.global_variables_initializer().run()
# Fetch params to validate initial values
self.assertAllClose([1.0, 2.0], var0.eval())
self.assertAllClose([3.0, 4.0], var1.eval())
# Run 1 step of sgd through optimizer
opt_op.run()
# Validate updated params
self.assertAllClose([-14., -13.], var0.eval())
self.assertAllClose([-6., -5.], var1.eval())
def testPrecomputedGradient(self):
for dtype in [dtypes.half, dtypes.float32, dtypes.float64]:
with self.test_session():
var0 = variables.Variable([1.0, 2.0], dtype=dtype)
var1 = variables.Variable([3.0, 4.0], dtype=dtype)
cost = 5 * var0 + 3 * var1
grad_loss = constant_op.constant([42, -42], dtype=dtype)
global_step = variables.Variable(
array_ops.zeros([], dtypes.int64), name='global_step')
sgd_op = gradient_descent.GradientDescentOptimizer(3.0)
opt_op = sgd_op.minimize(
cost, global_step, [var0, var1], grad_loss=grad_loss)
variables.global_variables_initializer().run()
# Fetch params to validate initial values
self.assertAllClose([1.0, 2.0], var0.eval())
self.assertAllClose([3.0, 4.0], var1.eval())
# Run 1 step of sgd through optimizer
opt_op.run()
# Validate updated params
self.assertAllClose([1.0 - 3 * 5 * 42.0, 2.0 - 3 * 5 * (-42.0)],
var0.eval())
self.assertAllClose([3.0 - 3 * 3 * 42.0, 4.0 - 3 * 3 * (-42.0)],
var1.eval())
def testNoVariables(self):
for dtype in [dtypes.half, dtypes.float32, dtypes.float64]:
with self.test_session():
var0 = variables.Variable([1.0, 2.0], dtype=dtype, trainable=False)
var1 = variables.Variable([3.0, 4.0], dtype=dtype, trainable=False)
cost = 5 * var0 + var1
sgd_op = gradient_descent.GradientDescentOptimizer(3.0)
with self.assertRaisesRegexp(ValueError, 'No variables'):
sgd_op.minimize(cost)
def testNoGradients(self):
for dtype in [dtypes.half, dtypes.float32, dtypes.float64]:
with self.test_session():
var0 = variables.Variable([1.0, 2.0], dtype=dtype)
var1 = variables.Variable([3.0, 4.0], dtype=dtype)
cost = 5 * var0
global_step = variables.Variable(
array_ops.zeros([], dtypes.int64), name='global_step')
sgd_op = gradient_descent.GradientDescentOptimizer(3.0)
with self.assertRaisesRegexp(ValueError, 'No gradients'):
# var1 has no gradient
sgd_op.minimize(cost, global_step, [var1])
def testNoGradientsForAnyVariables_Minimize(self):
for dtype in [dtypes.half, dtypes.float32, dtypes.float64]:
with self.test_session():
var0 = variables.Variable([1.0, 2.0], dtype=dtype)
var1 = variables.Variable([3.0, 4.0], dtype=dtype)
cost = constant_op.constant(5.0)
global_step = variables.Variable(
array_ops.zeros([], dtypes.int64), name='global_step')
sgd_op = gradient_descent.GradientDescentOptimizer(3.0)
with self.assertRaisesRegexp(ValueError,
'No gradients provided for any variable'):
sgd_op.minimize(cost, global_step, [var0, var1])
def testNoGradientsForAnyVariables_ApplyGradients(self):
for dtype in [dtypes.half, dtypes.float32, dtypes.float64]:
with self.test_session():
var0 = variables.Variable([1.0, 2.0], dtype=dtype)
var1 = variables.Variable([3.0, 4.0], dtype=dtype)
sgd_op = gradient_descent.GradientDescentOptimizer(3.0)
with self.assertRaisesRegexp(ValueError,
'No gradients provided for any variable'):
sgd_op.apply_gradients([(None, var0), (None, var1)])
def testGradientsAsVariables(self):
for dtype in [dtypes.half, dtypes.float32, dtypes.float64]:
with self.test_session() as sess:
var0 = variables.Variable([1.0, 2.0], dtype=dtype)
var1 = variables.Variable([3.0, 4.0], dtype=dtype)
cost = 5 * var0 + 3 * var1
global_step = variables.Variable(
array_ops.zeros([], dtypes.int64), name='global_step')
sgd_op = gradient_descent.GradientDescentOptimizer(3.0)
grads_and_vars = sgd_op.compute_gradients(cost, [var0, var1])
# Convert gradients to tf.Variables
converted_grads = [
variables.Variable(array_ops.zeros([2], dtype))
for i in grads_and_vars
]
convert_ops = [
state_ops.assign(converted_grads[i], gv[0])
for i, gv in enumerate(grads_and_vars)
]
converted_grads_and_vars = list(zip(converted_grads, [var0, var1]))
opt_op = sgd_op.apply_gradients(converted_grads_and_vars, global_step)
variables.global_variables_initializer().run()
# Run convert_ops to achieve the gradietns converting
sess.run(convert_ops)
# Fetch params to validate initial values
self.assertAllClose([1.0, 2.0], var0.eval())
self.assertAllClose([3.0, 4.0], var1.eval())
# Run 1 step of sgd through optimizer
opt_op.run()
# Validate updated params
self.assertAllClose([-14., -13.], var0.eval())
self.assertAllClose([-6., -5.], var1.eval())
def testTrainOp(self):
with self.test_session():
var0 = variables.Variable([1.0, 2.0])
var1 = variables.Variable([3.0, 4.0])
cost = 5 * var0 + 3 * var1
global_step = variables.Variable(
array_ops.zeros([], dtypes.int64), name='global_step')
sgd_op = gradient_descent.GradientDescentOptimizer(3.0)
opt_op = sgd_op.minimize(cost, global_step, [var0, var1])
self.assertTrue(opt_op in ops.get_collection(ops.GraphKeys.TRAIN_OP))
if __name__ == '__main__':
test.main()
|
apache-2.0
|
[
3,
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
3481,
279,
511,
367,
10736,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
12661,
63,
5472,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1174,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
7588,
492,
6709,
63,
26269,
421,
199,
533,
19246,
1793,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
6845,
8,
277,
304,
272,
367,
2152,
315,
359,
5717,
14,
10220,
12,
6674,
14,
1609,
708,
12,
6674,
14,
1609,
772,
2189,
489,
543,
291,
14,
396,
63,
1730,
837,
267,
2729,
16,
275,
2860,
14,
2773,
779,
17,
14,
16,
12,
499,
14,
16,
467,
2152,
29,
2271,
9,
267,
2729,
17,
275,
2860,
14,
2773,
779,
19,
14,
16,
12,
841,
14,
16,
467,
2152,
29,
2271,
9,
267,
7918,
275,
959,
627,
2729,
16,
435,
650,
627,
2729,
17,
267,
2288,
63,
2926,
275,
2860,
14,
2773,
8,
288,
1625,
63,
1483,
14,
4250,
8798,
6674,
14,
442,
772,
395,
536,
534,
2966,
63,
2926,
358,
267,
308,
7136,
63,
411,
275,
6709,
63,
26269,
14,
9942,
26232,
13946,
8,
19,
14,
16,
9,
267,
2450,
63,
411,
275,
308,
7136,
63,
411,
14,
19333,
8,
6336,
12,
2288,
63,
2926,
12,
359,
1391,
16,
12,
2729,
17,
566,
398,
2860,
14,
2966,
63,
3669,
63,
6498,
1252,
1065,
342,
267,
327,
16347,
1862,
370,
4107,
2536,
1338,
267,
291,
14,
7260,
779,
17,
14,
16,
12,
499,
14,
16,
467,
2729,
16,
14,
2579,
1012,
267,
291,
14,
7260,
779,
19,
14,
16,
12,
841,
14,
16,
467,
2729,
17,
14,
2579,
1012,
267,
327,
3378,
413,
3650,
402,
308,
7136,
4012,
10736,
267,
2450,
63,
411,
14,
1065,
342,
267,
327,
12134,
4588,
1862,
267,
291,
14,
7260,
11468,
1079,
2020,
446,
969,
8333,
2729,
16,
14,
2579,
1012,
267,
291,
14,
7260,
11468,
22,
2020,
446,
21,
8333,
2729,
17,
14,
2579,
1012,
819,
347,
511,
31345,
3767,
8,
277,
304,
272,
367,
2152,
315,
359,
5717,
14,
10220,
12,
6674,
14,
1609,
708,
12,
6674,
14,
1609,
772,
2189,
489,
543,
291,
14,
396,
63,
1730,
837,
267,
2729,
16,
275,
2860,
14,
2773,
779,
17,
14,
16,
12,
499,
14,
16,
467,
2152,
29,
2271,
9,
267,
2729,
17,
275,
2860,
14,
2773,
779,
19,
14,
16,
12,
841,
14,
16,
467,
2152,
29,
2271,
9,
267,
7918,
275,
959,
627,
2729,
16,
435,
650,
627,
2729,
17,
267,
2288,
63,
2926,
275,
2860,
14,
2773,
8,
288,
1625,
63,
1483,
14,
4250,
8798,
6674,
14,
442,
772,
395,
536,
534,
2966,
63,
2926,
358,
267,
308,
7136,
63,
411,
275,
6709,
63,
26269,
14,
9942,
26232,
13946,
8,
19,
14,
16,
9,
267,
2450,
63,
411,
275,
308,
7136,
63,
411,
14,
19333,
8,
288,
7918,
12,
288,
2288,
63,
2926,
12,
359,
1391,
16,
12,
2729,
17,
467,
288,
18384,
63,
765,
29,
13065,
63,
5472,
14,
31345,
3767,
14,
288,
3651,
25731,
1309,
748,
63,
1348,
5497,
1293,
1951,
63,
46,
9,
398,
2860,
14,
2966,
63,
3669,
63,
6498,
1252,
1065,
342,
267,
327,
16347,
1862,
370,
4107,
2536,
1338,
267,
291,
14,
7260,
779,
17,
14,
16,
12,
499,
14,
16,
467,
2729,
16,
14,
2579,
1012,
267,
291,
14,
7260,
779,
19,
14,
16,
12,
841,
14,
16,
467,
2729,
17,
14,
2579,
1012,
267,
327,
3378,
413,
3650,
402,
308,
7136,
4012,
10736,
267,
2450,
63,
411,
14,
1065,
342,
267,
327,
12134,
4588,
1862,
267,
291,
14,
7260,
11468,
1079,
2020,
446,
969,
8333,
2729,
16,
14,
2579,
1012,
267,
291,
14,
7260,
11468,
22,
2020,
446,
21,
8333,
2729,
17,
14,
2579,
1012,
819,
347,
511,
2398,
14378,
9942,
8,
277,
304,
272,
367,
2152,
315,
359,
5717,
14,
10220,
12,
6674,
14,
1609,
708,
12,
6674,
14,
1609,
772,
2189,
489,
543,
291,
14,
396,
63,
1730,
837,
267,
2729,
16,
275,
2860,
14,
2773,
779,
17,
14,
16,
12,
499,
14,
16,
467,
2152,
29,
2271,
9,
267,
2729,
17,
275,
2860,
14,
2773,
779,
19,
14,
16,
12,
841,
14,
16,
467,
2152,
29,
2271,
9,
267,
7918,
275,
959,
627,
2729,
16,
435,
650,
627,
2729,
17,
267,
7659,
63,
4358,
275,
4413,
63,
411,
14,
4083,
779,
2260,
12,
446,
2260,
467,
2152,
29,
2271,
9,
267,
2288,
63,
2926,
275,
2860,
14,
2773,
8,
288,
1625,
63,
1483,
14,
4250,
8798,
6674,
14,
442,
772,
395,
536,
534,
2966,
63,
2926,
358,
267,
308,
7136,
63,
411,
275,
6709,
63,
26269,
14,
9942,
26232,
13946,
8,
19,
14,
16,
9,
267,
2450,
63,
411,
275,
308,
7136,
63,
411,
14,
19333,
8,
288,
7918,
12,
2288,
63,
2926,
12,
359,
1391,
16,
12,
2729,
17,
467,
7659,
63,
4358,
29,
6017,
63,
4358,
9,
398
] |
[
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,
3481,
279,
511,
367,
10736,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
12661,
63,
5472,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1174,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
7588,
492,
6709,
63,
26269,
421,
199,
533,
19246,
1793,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
6845,
8,
277,
304,
272,
367,
2152,
315,
359,
5717,
14,
10220,
12,
6674,
14,
1609,
708,
12,
6674,
14,
1609,
772,
2189,
489,
543,
291,
14,
396,
63,
1730,
837,
267,
2729,
16,
275,
2860,
14,
2773,
779,
17,
14,
16,
12,
499,
14,
16,
467,
2152,
29,
2271,
9,
267,
2729,
17,
275,
2860,
14,
2773,
779,
19,
14,
16,
12,
841,
14,
16,
467,
2152,
29,
2271,
9,
267,
7918,
275,
959,
627,
2729,
16,
435,
650,
627,
2729,
17,
267,
2288,
63,
2926,
275,
2860,
14,
2773,
8,
288,
1625,
63,
1483,
14,
4250,
8798,
6674,
14,
442,
772,
395,
536,
534,
2966,
63,
2926,
358,
267,
308,
7136,
63,
411,
275,
6709,
63,
26269,
14,
9942,
26232,
13946,
8,
19,
14,
16,
9,
267,
2450,
63,
411,
275,
308,
7136,
63,
411,
14,
19333,
8,
6336,
12,
2288,
63,
2926,
12,
359,
1391,
16,
12,
2729,
17,
566,
398,
2860,
14,
2966,
63,
3669,
63,
6498,
1252,
1065,
342,
267,
327,
16347,
1862,
370,
4107,
2536,
1338,
267,
291,
14,
7260,
779,
17,
14,
16,
12,
499,
14,
16,
467,
2729,
16,
14,
2579,
1012,
267,
291,
14,
7260,
779,
19,
14,
16,
12,
841,
14,
16,
467,
2729,
17,
14,
2579,
1012,
267,
327,
3378,
413,
3650,
402,
308,
7136,
4012,
10736,
267,
2450,
63,
411,
14,
1065,
342,
267,
327,
12134,
4588,
1862,
267,
291,
14,
7260,
11468,
1079,
2020,
446,
969,
8333,
2729,
16,
14,
2579,
1012,
267,
291,
14,
7260,
11468,
22,
2020,
446,
21,
8333,
2729,
17,
14,
2579,
1012,
819,
347,
511,
31345,
3767,
8,
277,
304,
272,
367,
2152,
315,
359,
5717,
14,
10220,
12,
6674,
14,
1609,
708,
12,
6674,
14,
1609,
772,
2189,
489,
543,
291,
14,
396,
63,
1730,
837,
267,
2729,
16,
275,
2860,
14,
2773,
779,
17,
14,
16,
12,
499,
14,
16,
467,
2152,
29,
2271,
9,
267,
2729,
17,
275,
2860,
14,
2773,
779,
19,
14,
16,
12,
841,
14,
16,
467,
2152,
29,
2271,
9,
267,
7918,
275,
959,
627,
2729,
16,
435,
650,
627,
2729,
17,
267,
2288,
63,
2926,
275,
2860,
14,
2773,
8,
288,
1625,
63,
1483,
14,
4250,
8798,
6674,
14,
442,
772,
395,
536,
534,
2966,
63,
2926,
358,
267,
308,
7136,
63,
411,
275,
6709,
63,
26269,
14,
9942,
26232,
13946,
8,
19,
14,
16,
9,
267,
2450,
63,
411,
275,
308,
7136,
63,
411,
14,
19333,
8,
288,
7918,
12,
288,
2288,
63,
2926,
12,
359,
1391,
16,
12,
2729,
17,
467,
288,
18384,
63,
765,
29,
13065,
63,
5472,
14,
31345,
3767,
14,
288,
3651,
25731,
1309,
748,
63,
1348,
5497,
1293,
1951,
63,
46,
9,
398,
2860,
14,
2966,
63,
3669,
63,
6498,
1252,
1065,
342,
267,
327,
16347,
1862,
370,
4107,
2536,
1338,
267,
291,
14,
7260,
779,
17,
14,
16,
12,
499,
14,
16,
467,
2729,
16,
14,
2579,
1012,
267,
291,
14,
7260,
779,
19,
14,
16,
12,
841,
14,
16,
467,
2729,
17,
14,
2579,
1012,
267,
327,
3378,
413,
3650,
402,
308,
7136,
4012,
10736,
267,
2450,
63,
411,
14,
1065,
342,
267,
327,
12134,
4588,
1862,
267,
291,
14,
7260,
11468,
1079,
2020,
446,
969,
8333,
2729,
16,
14,
2579,
1012,
267,
291,
14,
7260,
11468,
22,
2020,
446,
21,
8333,
2729,
17,
14,
2579,
1012,
819,
347,
511,
2398,
14378,
9942,
8,
277,
304,
272,
367,
2152,
315,
359,
5717,
14,
10220,
12,
6674,
14,
1609,
708,
12,
6674,
14,
1609,
772,
2189,
489,
543,
291,
14,
396,
63,
1730,
837,
267,
2729,
16,
275,
2860,
14,
2773,
779,
17,
14,
16,
12,
499,
14,
16,
467,
2152,
29,
2271,
9,
267,
2729,
17,
275,
2860,
14,
2773,
779,
19,
14,
16,
12,
841,
14,
16,
467,
2152,
29,
2271,
9,
267,
7918,
275,
959,
627,
2729,
16,
435,
650,
627,
2729,
17,
267,
7659,
63,
4358,
275,
4413,
63,
411,
14,
4083,
779,
2260,
12,
446,
2260,
467,
2152,
29,
2271,
9,
267,
2288,
63,
2926,
275,
2860,
14,
2773,
8,
288,
1625,
63,
1483,
14,
4250,
8798,
6674,
14,
442,
772,
395,
536,
534,
2966,
63,
2926,
358,
267,
308,
7136,
63,
411,
275,
6709,
63,
26269,
14,
9942,
26232,
13946,
8,
19,
14,
16,
9,
267,
2450,
63,
411,
275,
308,
7136,
63,
411,
14,
19333,
8,
288,
7918,
12,
2288,
63,
2926,
12,
359,
1391,
16,
12,
2729,
17,
467,
7659,
63,
4358,
29,
6017,
63,
4358,
9,
398,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
fxcebx/sumatrapdf
|
scripts/gen_settings_html.py
|
14
|
9864
|
#!/usr/bin/env python
import os
import util2
import gen_settingsstructs
import trans_langs
"""
TODO:
* for gen_langs_html, show languages that don't have enough translations
in a separate table
"""
g_version = util2.get_sumatrapdf_version()
html_tmpl = """\
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Customizing SumatraPDF</title>
<style type=text/css>
body {
font-size: 90%;
background-color: #f5f5f5;
}
.desc {
padding: 0px 10px 0px 10px;
}
.txt1 {
/* bold doesn't look good in the fonts above */
font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace;
font-size: 88%;
color: #800; /* this is brown */
}
.txt2 {
font-family: Verdana, Arial, sans-serif;
font-family: serif;
font-size: 90%;
font-weight: bold;
color: #800; /* this is brown */
}
.txt {
font-family: serif;
font-size: 95%;
font-weight: bold;
color: #800; /* this is brown */
color: #000;
background-color: #ececec;
border: 1px solid #fff;
border-radius: 10px;
-webkit-border-radius: 10px;
box-shadow: rgba(0, 0, 0, .15) 3px 3px 4px;
-webkit-box-shadow: rgba(0, 0, 0, .15) 3px 3px 4px;
padding: 10px 10px 10px 20px;
}
.cm {
color: #800; /* this is brown, a bit aggressive */
color: #8c8c8c; /* this is gray */
color: #555; /* this is darker gray */
font-weight: normal;
}
</style>
</head>
<body>
<div class=desc>
<h2>Customizing SumatraPDF</h2>
<p>You can change the look and behavior of
<a href="http://www.sumatrapdfreader.org/">SumatraPDF</a>
by editing the file <code>SumatraPDF-settings.txt</code>. The file is stored in
<code>%APPDATA%\SumatraPDF</code> directory for the installed version or in the
same directory as <code>SumatraPDF.exe</code> executable for the portable version.</p>
<p>Use the menu item <code>Settings -> Advanced Settings...</code> to open the settings file
with your default text editor.</p>
<p>The file is in a simple text format. Below is an explanation of
what the different settings mean and what their default values are.</p>
<p>Highlighted settings can't be changed from the UI. Modifying other settings
directly in this file is not recommended.</p>
<p>If you add or remove lines with square brackets, <b>make sure to always add/remove
square brackets in pairs</b>! Else you risk losing all the data following them.</p>
</div>
<pre class=txt>
%INSIDE%
</pre>
<div class=desc>
<h3 id="color">Syntax for color values</h3>
<p>
The syntax for colors is: <code>#rrggbb</code>.</p>
<p>The components are hex values (ranging from 00 to FF) and stand for:
<ul>
<li><code>rr</code> : red component</li>
<li><code>gg</code> : green component</li>
<li><code>bb</code> : blue component</li>
</ul>
For example #ff0000 means red color. You can use <a href="http://www.colorpicker.com/">
Color Picker</a> or <a href="http://mudcu.be/sphere/">Sphere</a> or
<a href="http://colorschemedesigner.com/">ColorScheme Designer</a> to pick a color.
</p>
</div>
</body>
</html>
"""
langs_html_tmpl = """\
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Languages supported by SumatraPDF</title>
<style type=text/css>
body {
font-size: 90%;
background-color: #f5f5f5;
}
.txt1 {
/* bold doesn't look good in the fonts above */
font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace;
font-size: 88%;
color: #800; /* this is brown */
}
.txt2 {
font-family: Verdana, Arial, sans-serif;
font-family: serif;
font-size: 90%;
font-weight: bold;
color: #800; /* this is brown */
}
.txt {
font-family: serif;
font-size: 95%;
font-weight: bold;
color: #800; /* this is brown */
color: #000;
background-color: #ececec;
}
.cm {
color: #800; /* this is brown, a bit aggressive */
color: #8c8c8c; /* this is gray */
color: #555; /* this is darker gray */
font-weight: normal;
}
</style>
</head>
<body>
<h2>Languages supported by SumatraPDF</h2>
<p>Languages supported by SumatraPDF. You can use ISO code as a value
of <code>UiLanguage</code> setting in <a href="settings.html">settings file</a>.
</p>
<p>Note: not all languages are fully translated. Help us <a href="http://www.apptranslator.org/app/SumatraPDF">translate SumatraPDF</a>.</p>
<table>
<tr><th>Language name</th><th>ISO code</th></tr>
%INSIDE%
</table>
</body>
</html>
"""
#indent_str = " "
indent_str = " "
# if s in the form: "foo](bar.html)", returns ["foo", "bar.html"].
# otherwise returns ["foo"]
def extract_url(s):
if not s.endswith(")"):
return [s]
word_end = s.find("]")
assert word_end != -1
word = s[:word_end]
assert s[word_end + 1] == "("
url = s[word_end + 2:-1]
return [word, url]
def gen_comment(comment, field_id, start, first=False):
line_len = 100
s = start + '<span class=cm id="%s">' % field_id
if not first:
s = "\n" + s
left = line_len - len(start)
# [foo](bar.html) is turned into <a href="bar.html">foo</a>
href_text = None
for word in comment.split():
if word[0] == "[":
word_url = extract_url(word[1:])
if len(word_url) == 2:
s += '<a href="%s">%s</a>' % (word_url[1], word_url[0])
continue
href_text = word_url[0]
continue
elif href_text != None:
word_url = extract_url(word)
href_text = href_text + " " + word_url[0]
if len(word_url) == 2:
s += '<a href="%s">%s</a> ' % (word_url[1], href_text)
href_text = None
continue
if left < len(word):
s += "\n" + start
left = line_len - len(start)
word += " "
left -= len(word)
if word == "color ":
word = '<a href="#color">color</a> '
elif word == "colors ":
word = '<a href="#color">colors</a> '
s += word
s = s.rstrip()
s += '</span>'
return [s]
def gen_struct(struct, indent="", prerelease=False):
lines = []
first = True
inside_expert = False
for field in struct.default:
if field.internal or type(field) is gen_settingsstructs.Comment or not prerelease and field.prerelease:
continue
start_idx = len(lines)
comment = field.docComment
if field.version != "2.3":
comment += " (introduced in version %s)" % field.version
field_id = struct.name + "_" + field.name if indent else field.name
lines += gen_comment(comment, field_id, indent, first)
if type(field) is gen_settingsstructs.Array:
indent2 = indent + indent_str[:len(indent_str) / 2]
start = "%s%s [\n%s[" % (indent, field.name, indent2)
end = "%s]\n%s]" % (indent2, indent)
inside = gen_struct(field, indent + indent_str, prerelease)
lines += [start, inside, end]
elif type(field) is gen_settingsstructs.Struct:
start = "%s%s [" % (indent, field.name)
end = "%s]" % indent
inside = gen_struct(field, indent + indent_str, prerelease)
lines += [start, inside, end]
else:
s = field.inidefault(commentChar="").lstrip()
lines += [indent + s]
first = False
if field.expert and not inside_expert:
lines[start_idx] = '<div>' + lines[start_idx]
elif not field.expert and inside_expert:
lines[start_idx] = '</div>' + lines[start_idx]
inside_expert = field.expert
return "\n".join(lines)
class Lang(object):
def __init__(self, name, code):
self.name = name
self.code = code
def blog_dir():
script_dir = os.path.realpath(os.path.dirname(__file__))
d = os.path.realpath(
os.path.join(script_dir, "..", "..", "go", "src", "github.com", "kjk", "blog", "www", "software", "sumatrapdf"))
if os.path.exists(d):
return d
print("blog dir '%s' doesn't exist" % d)
return None
def gen_langs_html():
langs = trans_langs.g_langs
langs = [Lang(el[1], el[0]) for el in langs]
lines = []
langs = sorted(langs, key=lambda lang: lang.name)
for l in langs:
s = '<tr><td>%s</td><td>%s</td></tr>' % (l.name, l.code)
lines += [s]
inside = "\n".join(lines)
s = langs_html_tmpl.replace("%INSIDE%", inside)
file_name = "langs.html"
p = os.path.join("scripts", file_name)
open(p, "w").write(s)
if blog_dir() is not None:
p = os.path.join(blog_dir(), file_name)
open(p, "w").write(s)
def gen_html():
prefs = gen_settingsstructs.GlobalPrefs
inside = gen_struct(prefs)
s = html_tmpl.replace("%INSIDE%", inside)
file_name = "settings" + g_version + ".html"
p = os.path.join("scripts", file_name)
open(p, "w").write(s)
if blog_dir() is not None:
p = os.path.join(blog_dir(), file_name)
open(p, "w").write(s)
# also save the latest version as settings.html so that there is a
# permament version we can link from from docs that is independent of
# program version number
p = os.path.join(blog_dir(), "settings.html")
open(p, "w").write(s)
if __name__ == "__main__":
util2.chdir_top()
gen_langs_html()
gen_html()
gen_settingsstructs.main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
2999,
199,
646,
747,
202,
199,
646,
4884,
18,
202,
199,
646,
3805,
63,
1751,
23253,
202,
199,
646,
1752,
63,
28182,
2999,
199,
624,
202,
199,
11768,
26,
1223,
627,
367,
3805,
63,
28182,
63,
1360,
12,
2498,
10815,
626,
2793,
1133,
1172,
8321,
15547,
15497,
315,
282,
7396,
1817,
202,
199,
624,
2999,
199,
71,
63,
1023,
275,
4884,
18,
14,
362,
63,
1838,
292,
1330,
1587,
63,
1023,
342,
2999,
199,
1360,
63,
11510,
275,
9638,
202,
199,
11230,
6356,
3517,
30,
2999,
199,
28,
1360,
30,
202,
199,
28,
2993,
30,
202,
199,
28,
2024,
1455,
13,
20146,
628,
2714,
13,
804,
2,
1564,
628,
505,
15,
1360,
27,
5960,
29,
1624,
13,
24,
2,
7082,
202,
199,
28,
1213,
30,
7223,
9147,
12094,
292,
345,
7638,
1108,
1213,
30,
202,
199,
28,
2487,
730,
29,
505,
15,
3919,
30,
202,
199,
2030,
469,
1128,
5023,
13,
890,
26,
9137,
5,
27,
1128,
8020,
13,
2326,
26,
327,
70,
21,
70,
21,
70,
21,
27,
202,
199,
93,
2999,
199,
14,
3257,
469,
1128,
6273,
26,
378,
5326,
1616,
5326,
378,
5326,
1616,
5326,
27,
202,
199,
93,
2999,
199,
14,
2424,
17,
469,
1128,
13505,
17268,
3181,
1133,
3648,
6954,
315,
314,
26219,
3432,
11589,
1128,
5023,
13,
6606,
26,
10953,
13286,
12,
283,
872,
3387,
32308,
428,
796,
10953,
79,
297,
283,
4734,
1745,
5444,
65,
428,
796,
10953,
79,
297,
283,
44,
947,
29132,
19809,
297,
3485,
17601,
27,
1128,
5023,
13,
890,
26,
10523,
5,
27,
1128,
3164,
26,
327,
6718,
27,
13505,
642,
365,
330,
18406,
11589,
202,
199,
93,
2999,
199,
14,
2424,
18,
469,
1128,
5023,
13,
6606,
26,
5444,
68,
6738,
12,
437,
1383,
12,
308,
796,
13,
24977,
27,
1128,
5023,
13,
6606,
26,
542,
20546,
27,
1128,
5023,
13,
890,
26,
9137,
5,
27,
1128,
5023,
13,
3463,
26,
17268,
27,
1128,
3164,
26,
327,
6718,
27,
13505,
642,
365,
330,
18406,
11589,
202,
199,
93,
2999,
199,
14,
2424,
469,
1128,
5023,
13,
6606,
26,
542,
20546,
27,
1128,
5023,
13,
890,
26,
16102,
5,
27,
1128,
5023,
13,
3463,
26,
17268,
27,
1128,
3164,
26,
327,
6718,
27,
13505,
642,
365,
330,
18406,
11589,
1128,
3164,
26,
327,
1493,
27,
1128,
8020,
13,
2326,
26,
327,
69,
301,
31645,
27,
1128,
9162,
26,
413,
5326,
18609,
327,
18190,
27,
1128,
9162,
13,
8017,
26,
1616,
5326,
27,
1128,
446,
12554,
13,
8665,
13,
8017,
26,
1616,
5326,
27,
1128,
5689,
13,
14714,
26,
23136,
2470,
8,
16,
12,
378,
12,
378,
12,
1275,
1046,
9,
650,
5326,
650,
5326,
841,
5326,
27,
1128,
446,
12554,
13,
1977,
13,
14714,
26,
23136,
2470,
8,
16,
12,
378,
12,
378,
12,
1275,
1046,
9,
650,
5326,
650,
5326,
841,
5326,
27,
1128,
6273,
26,
1616,
5326,
1616,
5326,
1616,
5326,
3388,
5326,
27,
202,
199,
93,
2999,
199,
14,
4400,
469,
1128,
3164,
26,
327,
6718,
27,
257,
13505,
642,
365,
330,
18406,
12,
282,
4546,
1839,
25787,
11589,
1128,
3164,
26,
327,
24,
67,
24,
67,
24,
67,
27,
13505,
642,
365,
21977,
11589,
1128,
3164,
26,
327,
15722,
27,
13505,
642,
365,
23531,
281,
21977,
11589,
1128,
5023,
13,
3463,
26,
3293,
27,
202,
199,
93,
2999,
199,
1108,
2487,
30,
202,
199,
1108,
2993,
30,
2999,
199,
28,
2030,
30,
2999,
199,
28,
3015,
1021,
29,
3257,
30,
2999,
199,
28,
72,
18,
30,
7223,
9147,
12094,
292,
345,
7638,
1108,
72,
18,
30,
2999,
199,
28,
80,
30,
5556,
883,
1570,
314,
3648,
436,
5953,
402,
202,
199,
28,
65,
4369,
628,
1014,
921,
1544,
14,
1838,
292,
1330,
1587,
5503,
14,
1308,
26049,
6959,
292,
345,
7638,
1108,
65,
30,
202,
199,
991,
20401,
314,
570,
665,
600,
30,
6959,
292,
345,
7638,
13,
1751,
14,
2424,
1108,
600,
10827,
710,
570,
365,
5489,
315,
202,
199,
28,
600,
6598,
28057,
27744,
6959,
292,
345,
7638,
1108,
600,
30,
2082,
367,
314,
4903,
1015,
503,
315,
314,
202,
199,
7191,
2082,
465,
665,
600,
30,
6959,
292,
345,
7638,
14,
5803,
1108,
600,
30,
7286,
367,
314,
1844,
461,
1015,
9758,
80,
30,
2999,
199,
28,
80,
30,
6119,
314,
6269,
1242,
665,
600,
30,
5268,
1035,
32445,
13303,
1396,
1108,
600,
30,
370,
1551,
314,
2202,
570,
202,
199,
1045,
2195,
849,
1318,
8823,
9758,
80,
30,
2999,
199,
28,
80,
30,
1918,
570,
365,
315,
282,
3486,
1318,
1475,
14,
6423,
674,
365,
376,
17531,
402,
202,
199,
10058,
314,
3365,
2202,
4615,
436,
4052,
3932,
849,
1338,
787,
9758,
80,
30,
2999,
199,
28,
80,
30,
11688,
27883,
2202,
883,
1133,
506,
2896,
687,
314,
14041,
14,
22520,
316,
1163,
2202,
202,
199,
2275,
590,
315,
642,
570,
365,
440,
14318,
9758,
80,
30,
2999,
199,
28,
80,
30,
3917,
1265,
1050,
503,
2813,
2385,
543,
12386,
21873,
12,
665,
66,
30,
1875,
3238,
370,
3544,
1050,
15,
2168,
202,
199,
9646,
21873,
315,
6342,
1108,
66,
30,
1,
19524,
1265,
22633,
560,
1044,
1006,
314,
666,
2569,
3062,
9758,
80,
30,
2999,
199,
1108,
3015,
30,
2999,
199,
28,
657,
1021,
29,
2424,
30,
202,
199,
5,
10789,
11259,
5,
202,
199,
1108,
657,
30,
2999,
199,
28,
3015,
1021,
29,
3257,
30,
202,
199,
28,
72,
19,
1305,
628,
2326,
1743,
16626,
367,
3164,
1338,
1108,
72,
19,
30,
2999,
199,
28,
80,
30,
202,
199,
1918,
6302,
367,
9229,
365,
26,
665,
600,
30,
3,
9734,
2721,
2501,
1108,
600,
30,
9758,
80,
30,
202,
199,
28,
80,
30,
1918,
7323,
787,
6318,
1338,
334,
82,
8544,
687,
8733,
370,
25046,
9,
436,
10584,
367,
26,
202,
199,
28,
348,
30,
10292,
665,
317,
2535,
600,
30,
9734,
1108,
600,
30,
520,
8992,
3931,
1108,
317,
30,
10292,
665,
317,
2535,
600,
30,
2721,
1108,
600,
30,
520,
12431,
3931,
1108,
317,
30,
10292,
665,
317,
2535,
600,
30,
2501,
1108,
600,
30,
520,
10030,
3931,
1108,
317,
30,
202,
199,
1108,
348,
30,
202,
199,
1858,
2893,
327,
556,
993,
4910,
8992,
3164,
14,
2047,
883,
675,
665,
65,
4369,
628
] |
[
2647,
15,
1393,
15,
1813,
2366,
2999,
199,
646,
747,
202,
199,
646,
4884,
18,
202,
199,
646,
3805,
63,
1751,
23253,
202,
199,
646,
1752,
63,
28182,
2999,
199,
624,
202,
199,
11768,
26,
1223,
627,
367,
3805,
63,
28182,
63,
1360,
12,
2498,
10815,
626,
2793,
1133,
1172,
8321,
15547,
15497,
315,
282,
7396,
1817,
202,
199,
624,
2999,
199,
71,
63,
1023,
275,
4884,
18,
14,
362,
63,
1838,
292,
1330,
1587,
63,
1023,
342,
2999,
199,
1360,
63,
11510,
275,
9638,
202,
199,
11230,
6356,
3517,
30,
2999,
199,
28,
1360,
30,
202,
199,
28,
2993,
30,
202,
199,
28,
2024,
1455,
13,
20146,
628,
2714,
13,
804,
2,
1564,
628,
505,
15,
1360,
27,
5960,
29,
1624,
13,
24,
2,
7082,
202,
199,
28,
1213,
30,
7223,
9147,
12094,
292,
345,
7638,
1108,
1213,
30,
202,
199,
28,
2487,
730,
29,
505,
15,
3919,
30,
202,
199,
2030,
469,
1128,
5023,
13,
890,
26,
9137,
5,
27,
1128,
8020,
13,
2326,
26,
327,
70,
21,
70,
21,
70,
21,
27,
202,
199,
93,
2999,
199,
14,
3257,
469,
1128,
6273,
26,
378,
5326,
1616,
5326,
378,
5326,
1616,
5326,
27,
202,
199,
93,
2999,
199,
14,
2424,
17,
469,
1128,
13505,
17268,
3181,
1133,
3648,
6954,
315,
314,
26219,
3432,
11589,
1128,
5023,
13,
6606,
26,
10953,
13286,
12,
283,
872,
3387,
32308,
428,
796,
10953,
79,
297,
283,
4734,
1745,
5444,
65,
428,
796,
10953,
79,
297,
283,
44,
947,
29132,
19809,
297,
3485,
17601,
27,
1128,
5023,
13,
890,
26,
10523,
5,
27,
1128,
3164,
26,
327,
6718,
27,
13505,
642,
365,
330,
18406,
11589,
202,
199,
93,
2999,
199,
14,
2424,
18,
469,
1128,
5023,
13,
6606,
26,
5444,
68,
6738,
12,
437,
1383,
12,
308,
796,
13,
24977,
27,
1128,
5023,
13,
6606,
26,
542,
20546,
27,
1128,
5023,
13,
890,
26,
9137,
5,
27,
1128,
5023,
13,
3463,
26,
17268,
27,
1128,
3164,
26,
327,
6718,
27,
13505,
642,
365,
330,
18406,
11589,
202,
199,
93,
2999,
199,
14,
2424,
469,
1128,
5023,
13,
6606,
26,
542,
20546,
27,
1128,
5023,
13,
890,
26,
16102,
5,
27,
1128,
5023,
13,
3463,
26,
17268,
27,
1128,
3164,
26,
327,
6718,
27,
13505,
642,
365,
330,
18406,
11589,
1128,
3164,
26,
327,
1493,
27,
1128,
8020,
13,
2326,
26,
327,
69,
301,
31645,
27,
1128,
9162,
26,
413,
5326,
18609,
327,
18190,
27,
1128,
9162,
13,
8017,
26,
1616,
5326,
27,
1128,
446,
12554,
13,
8665,
13,
8017,
26,
1616,
5326,
27,
1128,
5689,
13,
14714,
26,
23136,
2470,
8,
16,
12,
378,
12,
378,
12,
1275,
1046,
9,
650,
5326,
650,
5326,
841,
5326,
27,
1128,
446,
12554,
13,
1977,
13,
14714,
26,
23136,
2470,
8,
16,
12,
378,
12,
378,
12,
1275,
1046,
9,
650,
5326,
650,
5326,
841,
5326,
27,
1128,
6273,
26,
1616,
5326,
1616,
5326,
1616,
5326,
3388,
5326,
27,
202,
199,
93,
2999,
199,
14,
4400,
469,
1128,
3164,
26,
327,
6718,
27,
257,
13505,
642,
365,
330,
18406,
12,
282,
4546,
1839,
25787,
11589,
1128,
3164,
26,
327,
24,
67,
24,
67,
24,
67,
27,
13505,
642,
365,
21977,
11589,
1128,
3164,
26,
327,
15722,
27,
13505,
642,
365,
23531,
281,
21977,
11589,
1128,
5023,
13,
3463,
26,
3293,
27,
202,
199,
93,
2999,
199,
1108,
2487,
30,
202,
199,
1108,
2993,
30,
2999,
199,
28,
2030,
30,
2999,
199,
28,
3015,
1021,
29,
3257,
30,
2999,
199,
28,
72,
18,
30,
7223,
9147,
12094,
292,
345,
7638,
1108,
72,
18,
30,
2999,
199,
28,
80,
30,
5556,
883,
1570,
314,
3648,
436,
5953,
402,
202,
199,
28,
65,
4369,
628,
1014,
921,
1544,
14,
1838,
292,
1330,
1587,
5503,
14,
1308,
26049,
6959,
292,
345,
7638,
1108,
65,
30,
202,
199,
991,
20401,
314,
570,
665,
600,
30,
6959,
292,
345,
7638,
13,
1751,
14,
2424,
1108,
600,
10827,
710,
570,
365,
5489,
315,
202,
199,
28,
600,
6598,
28057,
27744,
6959,
292,
345,
7638,
1108,
600,
30,
2082,
367,
314,
4903,
1015,
503,
315,
314,
202,
199,
7191,
2082,
465,
665,
600,
30,
6959,
292,
345,
7638,
14,
5803,
1108,
600,
30,
7286,
367,
314,
1844,
461,
1015,
9758,
80,
30,
2999,
199,
28,
80,
30,
6119,
314,
6269,
1242,
665,
600,
30,
5268,
1035,
32445,
13303,
1396,
1108,
600,
30,
370,
1551,
314,
2202,
570,
202,
199,
1045,
2195,
849,
1318,
8823,
9758,
80,
30,
2999,
199,
28,
80,
30,
1918,
570,
365,
315,
282,
3486,
1318,
1475,
14,
6423,
674,
365,
376,
17531,
402,
202,
199,
10058,
314,
3365,
2202,
4615,
436,
4052,
3932,
849,
1338,
787,
9758,
80,
30,
2999,
199,
28,
80,
30,
11688,
27883,
2202,
883,
1133,
506,
2896,
687,
314,
14041,
14,
22520,
316,
1163,
2202,
202,
199,
2275,
590,
315,
642,
570,
365,
440,
14318,
9758,
80,
30,
2999,
199,
28,
80,
30,
3917,
1265,
1050,
503,
2813,
2385,
543,
12386,
21873,
12,
665,
66,
30,
1875,
3238,
370,
3544,
1050,
15,
2168,
202,
199,
9646,
21873,
315,
6342,
1108,
66,
30,
1,
19524,
1265,
22633,
560,
1044,
1006,
314,
666,
2569,
3062,
9758,
80,
30,
2999,
199,
1108,
3015,
30,
2999,
199,
28,
657,
1021,
29,
2424,
30,
202,
199,
5,
10789,
11259,
5,
202,
199,
1108,
657,
30,
2999,
199,
28,
3015,
1021,
29,
3257,
30,
202,
199,
28,
72,
19,
1305,
628,
2326,
1743,
16626,
367,
3164,
1338,
1108,
72,
19,
30,
2999,
199,
28,
80,
30,
202,
199,
1918,
6302,
367,
9229,
365,
26,
665,
600,
30,
3,
9734,
2721,
2501,
1108,
600,
30,
9758,
80,
30,
202,
199,
28,
80,
30,
1918,
7323,
787,
6318,
1338,
334,
82,
8544,
687,
8733,
370,
25046,
9,
436,
10584,
367,
26,
202,
199,
28,
348,
30,
10292,
665,
317,
2535,
600,
30,
9734,
1108,
600,
30,
520,
8992,
3931,
1108,
317,
30,
10292,
665,
317,
2535,
600,
30,
2721,
1108,
600,
30,
520,
12431,
3931,
1108,
317,
30,
10292,
665,
317,
2535,
600,
30,
2501,
1108,
600,
30,
520,
10030,
3931,
1108,
317,
30,
202,
199,
1108,
348,
30,
202,
199,
1858,
2893,
327,
556,
993,
4910,
8992,
3164,
14,
2047,
883,
675,
665,
65,
4369,
628,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
peguin40/zulip
|
zerver/views/webhooks/papertrail.py
|
3
|
2157
|
from __future__ import absolute_import
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.lib.validator import check_dict, check_string
from zerver.models import Client, UserProfile
from django.http import HttpRequest, HttpResponse
from six import text_type
from typing import Dict, Any, Iterable, Optional
@api_key_only_webhook_view('Papertrail')
@has_request_variables
def api_papertrail_webhook(request, user_profile, client,
payload=REQ(argument_type='body'),
stream=REQ(default='papertrail'),
topic=REQ(default='logs')):
# type: (HttpRequest, UserProfile, Client, Dict[str, Any], text_type, text_type) -> HttpResponse
# construct the message of the message
try:
message_template = '**"{}"** search found **{}** matches - {}\n```'
message = [message_template.format(payload["saved_search"]["name"],
str(len(payload["events"])),
payload["saved_search"]["html_search_url"])]
for i, event in enumerate(payload["events"]):
event_text = '{} {} {}:\n {}'.format(event["display_received_at"],
event["source_name"],
payload["saved_search"]["query"],
event["message"])
message.append(event_text)
if i >= 3:
message.append('```\n[See more]({})'.format(payload["saved_search"]["html_search_url"]))
break
else:
message.append('```')
post = '\n'.join(message)
except KeyError as e:
return json_error(_("Missing key {} in JSON").format(str(e)))
# send the message
check_send_message(user_profile, client, 'stream', [stream], topic, post)
# return json result
return json_success()
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
19959,
14,
773,
14,
3723,
492,
1104,
63,
2254,
63,
1188,
199,
504,
19959,
14,
773,
14,
1310,
492,
2022,
63,
3742,
12,
2022,
63,
705,
199,
504,
19959,
14,
11547,
492,
5363,
49,
12,
965,
63,
1069,
63,
3669,
12,
2986,
63,
498,
63,
2118,
63,
22944,
63,
1345,
199,
504,
19959,
14,
773,
14,
11034,
492,
1104,
63,
807,
12,
1104,
63,
875,
199,
199,
504,
19959,
14,
992,
492,
6810,
12,
19037,
199,
199,
504,
1639,
14,
1014,
492,
20730,
12,
6183,
199,
504,
3816,
492,
1318,
63,
466,
199,
504,
14090,
492,
7448,
12,
6184,
12,
19937,
12,
4879,
199,
199,
32,
1246,
63,
498,
63,
2118,
63,
22944,
63,
1345,
360,
48,
9804,
15732,
358,
199,
32,
1989,
63,
1069,
63,
3669,
199,
318,
2986,
63,
10443,
15732,
63,
22944,
8,
1069,
12,
922,
63,
2913,
12,
1890,
12,
2574,
4886,
29,
14583,
8,
2094,
63,
466,
534,
2030,
659,
2574,
2547,
29,
14583,
8,
885,
534,
10443,
15732,
659,
2574,
7482,
29,
14583,
8,
885,
534,
7270,
8109,
272,
327,
730,
26,
334,
10441,
12,
19037,
12,
6810,
12,
7448,
59,
495,
12,
6184,
467,
1318,
63,
466,
12,
1318,
63,
466,
9,
1035,
6183,
339,
327,
6982,
314,
1245,
402,
314,
1245,
272,
862,
26,
267,
1245,
63,
1160,
275,
23940,
2,
2440,
2,
538,
2754,
1911,
1011,
2440,
538,
4450,
446,
22902,
78,
1040,
19097,
267,
1245,
275,
359,
1188,
63,
1160,
14,
908,
8,
4749,
905,
8420,
63,
1733,
6611,
354,
2255,
5644,
620,
8,
552,
8,
4749,
905,
4368,
3135,
395,
5644,
4886,
905,
8420,
63,
1733,
6611,
1360,
63,
1733,
63,
633,
3135,
61,
267,
367,
284,
12,
1566,
315,
3874,
8,
4749,
905,
4368,
21473,
288,
1566,
63,
505,
275,
9005,
1052,
1052,
3427,
78,
221,
9499,
908,
8,
1430,
905,
2918,
63,
9226,
63,
292,
2255,
8179,
1566,
905,
1365,
63,
354,
2255,
8179,
4886,
905,
8420,
63,
1733,
6611,
1131,
2255,
8179,
1566,
905,
1188,
3135,
288,
1245,
14,
740,
8,
1430,
63,
505,
9,
288,
340,
284,
2356,
650,
26,
355,
1245,
14,
740,
360,
1040,
25502,
78,
59,
9295,
1655,
61,
14079,
1370,
908,
8,
4749,
905,
8420,
63,
1733,
6611,
1360,
63,
1733,
63,
633,
13045,
355,
2059,
267,
587,
26,
288,
1245,
14,
740,
360,
32323,
358,
267,
2963,
275,
1557,
78,
1370,
904,
8,
1188,
9,
272,
871,
4067,
465,
325,
26,
267,
372,
2022,
63,
705,
6115,
7718,
790,
1052,
315,
4840,
3471,
908,
8,
495,
8,
69,
1724,
339,
327,
3222,
314,
1245,
272,
1104,
63,
2254,
63,
1188,
8,
751,
63,
2913,
12,
1890,
12,
283,
1745,
297,
359,
1745,
467,
7482,
12,
2963,
9,
339,
327,
372,
2022,
754,
272,
372,
2022,
63,
3742,
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
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
19959,
14,
773,
14,
3723,
492,
1104,
63,
2254,
63,
1188,
199,
504,
19959,
14,
773,
14,
1310,
492,
2022,
63,
3742,
12,
2022,
63,
705,
199,
504,
19959,
14,
11547,
492,
5363,
49,
12,
965,
63,
1069,
63,
3669,
12,
2986,
63,
498,
63,
2118,
63,
22944,
63,
1345,
199,
504,
19959,
14,
773,
14,
11034,
492,
1104,
63,
807,
12,
1104,
63,
875,
199,
199,
504,
19959,
14,
992,
492,
6810,
12,
19037,
199,
199,
504,
1639,
14,
1014,
492,
20730,
12,
6183,
199,
504,
3816,
492,
1318,
63,
466,
199,
504,
14090,
492,
7448,
12,
6184,
12,
19937,
12,
4879,
199,
199,
32,
1246,
63,
498,
63,
2118,
63,
22944,
63,
1345,
360,
48,
9804,
15732,
358,
199,
32,
1989,
63,
1069,
63,
3669,
199,
318,
2986,
63,
10443,
15732,
63,
22944,
8,
1069,
12,
922,
63,
2913,
12,
1890,
12,
2574,
4886,
29,
14583,
8,
2094,
63,
466,
534,
2030,
659,
2574,
2547,
29,
14583,
8,
885,
534,
10443,
15732,
659,
2574,
7482,
29,
14583,
8,
885,
534,
7270,
8109,
272,
327,
730,
26,
334,
10441,
12,
19037,
12,
6810,
12,
7448,
59,
495,
12,
6184,
467,
1318,
63,
466,
12,
1318,
63,
466,
9,
1035,
6183,
339,
327,
6982,
314,
1245,
402,
314,
1245,
272,
862,
26,
267,
1245,
63,
1160,
275,
23940,
2,
2440,
2,
538,
2754,
1911,
1011,
2440,
538,
4450,
446,
22902,
78,
1040,
19097,
267,
1245,
275,
359,
1188,
63,
1160,
14,
908,
8,
4749,
905,
8420,
63,
1733,
6611,
354,
2255,
5644,
620,
8,
552,
8,
4749,
905,
4368,
3135,
395,
5644,
4886,
905,
8420,
63,
1733,
6611,
1360,
63,
1733,
63,
633,
3135,
61,
267,
367,
284,
12,
1566,
315,
3874,
8,
4749,
905,
4368,
21473,
288,
1566,
63,
505,
275,
9005,
1052,
1052,
3427,
78,
221,
9499,
908,
8,
1430,
905,
2918,
63,
9226,
63,
292,
2255,
8179,
1566,
905,
1365,
63,
354,
2255,
8179,
4886,
905,
8420,
63,
1733,
6611,
1131,
2255,
8179,
1566,
905,
1188,
3135,
288,
1245,
14,
740,
8,
1430,
63,
505,
9,
288,
340,
284,
2356,
650,
26,
355,
1245,
14,
740,
360,
1040,
25502,
78,
59,
9295,
1655,
61,
14079,
1370,
908,
8,
4749,
905,
8420,
63,
1733,
6611,
1360,
63,
1733,
63,
633,
13045,
355,
2059,
267,
587,
26,
288,
1245,
14,
740,
360,
32323,
358,
267,
2963,
275,
1557,
78,
1370,
904,
8,
1188,
9,
272,
871,
4067,
465,
325,
26,
267,
372,
2022,
63,
705,
6115,
7718,
790,
1052,
315,
4840,
3471,
908,
8,
495,
8,
69,
1724,
339,
327,
3222,
314,
1245,
272,
1104,
63,
2254,
63,
1188,
8,
751,
63,
2913,
12,
1890,
12,
283,
1745,
297,
359,
1745,
467,
7482,
12,
2963,
9,
339,
327,
372,
2022,
754,
272,
372,
2022,
63,
3742,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hryamzik/ansible
|
lib/ansible/modules/network/vyos/vyos_config.py
|
1
|
8948
|
#!/usr/bin/python
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'network'}
DOCUMENTATION = """
---
module: vyos_config
version_added: "2.2"
author: "Nathaniel Case (@qalthos)"
short_description: Manage VyOS configuration on remote device
description:
- This module provides configuration file management of VyOS
devices. It provides arguments for managing both the
configuration file and state of the active configuration. All
configuration statements are based on `set` and `delete` commands
in the device configuration.
extends_documentation_fragment: vyos
notes:
- Tested against VYOS 1.1.7
- Abbreviated commands are NOT idempotent, see
L(Network FAQ,../network/user_guide/faq.html#why-do-the-config-modules-always-return-changed-true-with-abbreviated-commands).
options:
lines:
description:
- The ordered set of configuration lines to be managed and
compared with the existing configuration on the remote
device.
src:
description:
- The C(src) argument specifies the path to the source config
file to load. The source config file can either be in
bracket format or set format. The source file can include
Jinja2 template variables.
match:
description:
- The C(match) argument controls the method used to match
against the current active configuration. By default, the
desired config is matched against the active config and the
deltas are loaded. If the C(match) argument is set to C(none)
the active configuration is ignored and the configuration is
always loaded.
default: line
choices: ['line', 'none']
backup:
description:
- The C(backup) argument will backup the current devices active
configuration to the Ansible control host prior to making any
changes. The backup file will be located in the backup folder
in the playbook root directory or role root directory, if
playbook is part of an ansible role. If the directory does not
exist, it is created.
type: bool
default: 'no'
comment:
description:
- Allows a commit description to be specified to be included
when the configuration is committed. If the configuration is
not changed or committed, this argument is ignored.
default: 'configured by vyos_config'
config:
description:
- The C(config) argument specifies the base configuration to use
to compare against the desired configuration. If this value
is not specified, the module will automatically retrieve the
current active configuration from the remote device.
save:
description:
- The C(save) argument controls whether or not changes made
to the active configuration are saved to disk. This is
independent of committing the config. When set to True, the
active configuration is saved.
type: bool
default: 'no'
"""
EXAMPLES = """
- name: configure the remote device
vyos_config:
lines:
- set system host-name {{ inventory_hostname }}
- set service lldp
- delete service dhcp-server
- name: backup and load from file
vyos_config:
src: vyos.cfg
backup: yes
- name: for idempotency, use full-form commands
vyos_config:
lines:
# - set int eth eth2 description 'OUTSIDE'
- set interface ethernet eth2 description 'OUTSIDE'
"""
RETURN = """
commands:
description: The list of configuration commands sent to the device
returned: always
type: list
sample: ['...', '...']
filtered:
description: The list of configuration commands removed to avoid a load failure
returned: always
type: list
sample: ['...', '...']
backup_path:
description: The full path to the backup file
returned: when backup is yes
type: string
sample: /playbooks/ansible/backup/vyos_config.2016-07-16@22:28:34
"""
import re
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.vyos.vyos import load_config, get_config, run_commands
from ansible.module_utils.network.vyos.vyos import vyos_argument_spec, get_connection
DEFAULT_COMMENT = 'configured by vyos_config'
CONFIG_FILTERS = [
re.compile(r'set system login user \S+ authentication encrypted-password')
]
def get_candidate(module):
contents = module.params['src'] or module.params['lines']
if module.params['src']:
contents = format_commands(contents.splitlines())
contents = '\n'.join(contents)
return contents
def format_commands(commands):
return [line for line in commands if len(line.strip()) > 0]
def diff_config(commands, config):
config = [str(c).replace("'", '') for c in config.splitlines()]
updates = list()
visited = set()
for line in commands:
item = str(line).replace("'", '')
if not item.startswith('set') and not item.startswith('delete'):
raise ValueError('line must start with either `set` or `delete`')
elif item.startswith('set') and item not in config:
updates.append(line)
elif item.startswith('delete'):
if not config:
updates.append(line)
else:
item = re.sub(r'delete', 'set', item)
for entry in config:
if entry.startswith(item) and line not in visited:
updates.append(line)
visited.add(line)
return list(updates)
def sanitize_config(config, result):
result['filtered'] = list()
index_to_filter = list()
for regex in CONFIG_FILTERS:
for index, line in enumerate(list(config)):
if regex.search(line):
result['filtered'].append(line)
index_to_filter.append(index)
# Delete all filtered configs
for filter_index in sorted(index_to_filter, reverse=True):
del config[filter_index]
def run(module, result):
# get the current active config from the node or passed in via
# the config param
config = module.params['config'] or get_config(module)
# create the candidate config object from the arguments
candidate = get_candidate(module)
# create loadable config that includes only the configuration updates
connection = get_connection(module)
response = connection.get_diff(candidate=candidate, running=config, diff_match=module.params['match'])
commands = response.get('config_diff')
sanitize_config(commands, result)
result['commands'] = commands
commit = not module.check_mode
comment = module.params['comment']
diff = None
if commands:
diff = load_config(module, commands, commit=commit, comment=comment)
if result.get('filtered'):
result['warnings'].append('Some configuration commands were '
'removed, please see the filtered key')
result['changed'] = True
if module._diff:
result['diff'] = {'prepared': diff}
def main():
argument_spec = dict(
src=dict(type='path'),
lines=dict(type='list'),
match=dict(default='line', choices=['line', 'none']),
comment=dict(default=DEFAULT_COMMENT),
config=dict(),
backup=dict(type='bool', default=False),
save=dict(type='bool', default=False),
)
argument_spec.update(vyos_argument_spec)
mutually_exclusive = [('lines', 'src')]
module = AnsibleModule(
argument_spec=argument_spec,
mutually_exclusive=mutually_exclusive,
supports_check_mode=True
)
warnings = list()
result = dict(changed=False, warnings=warnings)
if module.params['backup']:
result['__backup__'] = get_config(module=module)
if any((module.params['src'], module.params['lines'])):
run(module, result)
if module.params['save']:
diff = run_commands(module, commands=['configure', 'compare saved'])[1]
if diff != '[edit]':
run_commands(module, commands=['save'])
result['changed'] = True
run_commands(module, commands=['exit'])
module.exit_json(**result)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
1200,
936,
421,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
31766,
736,
63,
888,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
2502,
26,
298,
46,
1619,
290,
14769,
12425,
8593,
81,
6130,
736,
2924,
199,
3612,
63,
1802,
26,
14944,
812,
89,
3100,
2897,
641,
3982,
2243,
199,
1802,
26,
523,
446,
961,
859,
6571,
2897,
570,
10041,
402,
812,
89,
3100,
272,
7256,
14,
221,
2779,
6571,
2368,
367,
28453,
3865,
314,
272,
2897,
570,
436,
1174,
402,
314,
4702,
2897,
14,
257,
2900,
272,
2897,
9834,
787,
4079,
641,
658,
409,
64,
436,
658,
1807,
64,
3718,
272,
315,
314,
2243,
2897,
14,
199,
11036,
63,
9970,
63,
7677,
26,
31766,
736,
199,
5983,
26,
523,
446,
30568,
6169,
812,
57,
3100,
413,
14,
17,
14,
23,
523,
446,
437,
2501,
264,
433,
972,
3718,
787,
2845,
32122,
12,
1937,
272,
491,
8,
4491,
481,
20152,
12,
5093,
1200,
15,
751,
63,
17348,
15,
667,
81,
14,
1360,
3,
26460,
13,
1117,
13,
1589,
13,
888,
13,
3112,
13,
9223,
13,
1107,
13,
2489,
13,
2052,
13,
1045,
13,
371,
23988,
972,
13,
4405,
680,
199,
1419,
26,
523,
2385,
26,
272,
1369,
26,
489,
446,
710,
7741,
663,
402,
2897,
2385,
370,
506,
12883,
436,
267,
13524,
543,
314,
3411,
2897,
641,
314,
3982,
267,
2243,
14,
523,
2928,
26,
272,
1369,
26,
489,
446,
710,
445,
8,
2164,
9,
1423,
9314,
314,
931,
370,
314,
1350,
1101,
267,
570,
370,
2248,
14,
221,
710,
1350,
1101,
570,
883,
1902,
506,
315,
267,
14540,
1475,
503,
663,
1475,
14,
221,
710,
1350,
570,
883,
2387,
267,
17300,
18,
1978,
2860,
14,
523,
1336,
26,
272,
1369,
26,
489,
446,
710,
445,
8,
1431,
9,
1423,
13467,
314,
1083,
1202,
370,
1336,
267,
6169,
314,
1453,
4702,
2897,
14,
221,
4885,
849,
12,
314,
267,
6387,
1101,
365,
7838,
6169,
314,
4702,
1101,
436,
314,
267,
27446,
787,
6511,
14,
221,
982,
314,
445,
8,
1431,
9,
1423,
365,
663,
370,
445,
8,
3592,
9,
267,
314,
4702,
2897,
365,
5525,
436,
314,
2897,
365,
267,
3544,
6511,
14,
272,
849,
26,
1004,
272,
3415,
26,
788,
604,
297,
283,
3592,
418,
523,
6902,
26,
272,
1369,
26,
489,
446,
710,
445,
8,
5751,
9,
1423,
911,
6902,
314,
1453,
7256,
4702,
267,
2897,
370,
314,
2622,
3304,
1591,
6791,
370,
10663,
1263,
267,
4493,
14,
221,
710,
6902,
570,
911,
506,
16180,
315,
314,
6902,
4922,
267,
315,
314,
15695,
1738,
2082,
503,
4719,
1738,
2082,
12,
340,
267,
15695,
365,
1777,
402,
376,
3242,
4719,
14,
982,
314,
2082,
1630,
440,
267,
2187,
12,
652,
365,
2737,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
889,
7,
523,
3721,
26,
272,
1369,
26,
489,
446,
22819,
282,
5532,
1369,
370,
506,
2013,
370,
506,
5120,
267,
1380,
314,
2897,
365,
27659,
14,
221,
982,
314,
2897,
365,
267,
440,
2896,
503,
27659,
12,
642,
1423,
365,
5525,
14,
272,
849,
26,
283,
11786,
701,
31766,
736,
63,
888,
7,
523,
1101,
26,
272,
1369,
26,
489,
446,
710,
445,
8,
888,
9,
1423,
9314,
314,
1300,
2897,
370,
675,
267,
370,
6540,
6169,
314,
6387,
2897,
14,
221,
982,
642,
574,
267,
365,
440,
2013,
12,
314,
859,
911,
5847,
8044,
314,
267,
1453,
4702,
2897,
687,
314,
3982,
2243,
14,
523,
3354,
26,
272,
1369,
26,
489,
446,
710,
445,
8,
2117,
9,
1423,
13467,
3775,
503,
440,
4493,
6326,
267,
370,
314,
4702,
2897,
787,
6290,
370,
4543,
14,
221,
961,
365,
267,
12717,
402,
5532,
1337,
314,
1101,
14,
221,
3979,
663,
370,
715,
12,
314,
267,
4702,
2897,
365,
6290,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
889,
7,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
7908,
314,
3982,
2243,
523,
31766,
736,
63,
888,
26,
272,
2385,
26,
489,
446,
663,
2656,
1591,
13,
354,
8448,
8200,
63,
4269,
3586,
489,
446,
663,
2435,
28768,
489,
446,
3145,
2435,
19064,
13,
1000,
199,
199,
13,
536,
26,
6902,
436,
2248,
687,
570,
523,
31766,
736,
63,
888,
26,
272,
2928,
26,
31766,
736,
14,
4128,
272,
6902,
26,
9456,
199,
199,
13,
536,
26,
367,
9979,
9613,
9447,
12,
675,
2615,
13,
964,
3718,
523,
31766,
736,
63,
888,
26,
272,
2385,
26,
489,
327,
446,
663,
1109,
16227,
16227,
18,
1369,
283,
1877,
28035,
7,
489,
446,
663,
3217,
21944,
16227,
18,
1369,
283,
1877,
28035,
7,
199,
624,
199,
199,
9677,
275,
408,
199,
4405,
26,
523,
1369,
26,
710,
769,
402,
2897,
3718,
4847,
370,
314,
2243,
523,
2138,
26,
3544,
523,
730,
26,
769,
523,
2690,
26,
788,
20833,
24352,
418,
199,
11142,
26,
523,
1369,
26,
710,
769,
402,
2897,
3718,
4829,
370,
5126,
282,
2248,
5988,
523,
2138,
26,
3544,
523,
730,
26,
769,
523,
2690,
26,
788,
20833,
24352,
418,
199,
5751,
63,
515,
26,
523,
1369,
26,
710
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
1200,
936,
421,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
31766,
736,
63,
888,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
2502,
26,
298,
46,
1619,
290,
14769,
12425,
8593,
81,
6130,
736,
2924,
199,
3612,
63,
1802,
26,
14944,
812,
89,
3100,
2897,
641,
3982,
2243,
199,
1802,
26,
523,
446,
961,
859,
6571,
2897,
570,
10041,
402,
812,
89,
3100,
272,
7256,
14,
221,
2779,
6571,
2368,
367,
28453,
3865,
314,
272,
2897,
570,
436,
1174,
402,
314,
4702,
2897,
14,
257,
2900,
272,
2897,
9834,
787,
4079,
641,
658,
409,
64,
436,
658,
1807,
64,
3718,
272,
315,
314,
2243,
2897,
14,
199,
11036,
63,
9970,
63,
7677,
26,
31766,
736,
199,
5983,
26,
523,
446,
30568,
6169,
812,
57,
3100,
413,
14,
17,
14,
23,
523,
446,
437,
2501,
264,
433,
972,
3718,
787,
2845,
32122,
12,
1937,
272,
491,
8,
4491,
481,
20152,
12,
5093,
1200,
15,
751,
63,
17348,
15,
667,
81,
14,
1360,
3,
26460,
13,
1117,
13,
1589,
13,
888,
13,
3112,
13,
9223,
13,
1107,
13,
2489,
13,
2052,
13,
1045,
13,
371,
23988,
972,
13,
4405,
680,
199,
1419,
26,
523,
2385,
26,
272,
1369,
26,
489,
446,
710,
7741,
663,
402,
2897,
2385,
370,
506,
12883,
436,
267,
13524,
543,
314,
3411,
2897,
641,
314,
3982,
267,
2243,
14,
523,
2928,
26,
272,
1369,
26,
489,
446,
710,
445,
8,
2164,
9,
1423,
9314,
314,
931,
370,
314,
1350,
1101,
267,
570,
370,
2248,
14,
221,
710,
1350,
1101,
570,
883,
1902,
506,
315,
267,
14540,
1475,
503,
663,
1475,
14,
221,
710,
1350,
570,
883,
2387,
267,
17300,
18,
1978,
2860,
14,
523,
1336,
26,
272,
1369,
26,
489,
446,
710,
445,
8,
1431,
9,
1423,
13467,
314,
1083,
1202,
370,
1336,
267,
6169,
314,
1453,
4702,
2897,
14,
221,
4885,
849,
12,
314,
267,
6387,
1101,
365,
7838,
6169,
314,
4702,
1101,
436,
314,
267,
27446,
787,
6511,
14,
221,
982,
314,
445,
8,
1431,
9,
1423,
365,
663,
370,
445,
8,
3592,
9,
267,
314,
4702,
2897,
365,
5525,
436,
314,
2897,
365,
267,
3544,
6511,
14,
272,
849,
26,
1004,
272,
3415,
26,
788,
604,
297,
283,
3592,
418,
523,
6902,
26,
272,
1369,
26,
489,
446,
710,
445,
8,
5751,
9,
1423,
911,
6902,
314,
1453,
7256,
4702,
267,
2897,
370,
314,
2622,
3304,
1591,
6791,
370,
10663,
1263,
267,
4493,
14,
221,
710,
6902,
570,
911,
506,
16180,
315,
314,
6902,
4922,
267,
315,
314,
15695,
1738,
2082,
503,
4719,
1738,
2082,
12,
340,
267,
15695,
365,
1777,
402,
376,
3242,
4719,
14,
982,
314,
2082,
1630,
440,
267,
2187,
12,
652,
365,
2737,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
889,
7,
523,
3721,
26,
272,
1369,
26,
489,
446,
22819,
282,
5532,
1369,
370,
506,
2013,
370,
506,
5120,
267,
1380,
314,
2897,
365,
27659,
14,
221,
982,
314,
2897,
365,
267,
440,
2896,
503,
27659,
12,
642,
1423,
365,
5525,
14,
272,
849,
26,
283,
11786,
701,
31766,
736,
63,
888,
7,
523,
1101,
26,
272,
1369,
26,
489,
446,
710,
445,
8,
888,
9,
1423,
9314,
314,
1300,
2897,
370,
675,
267,
370,
6540,
6169,
314,
6387,
2897,
14,
221,
982,
642,
574,
267,
365,
440,
2013,
12,
314,
859,
911,
5847,
8044,
314,
267,
1453,
4702,
2897,
687,
314,
3982,
2243,
14,
523,
3354,
26,
272,
1369,
26,
489,
446,
710,
445,
8,
2117,
9,
1423,
13467,
3775,
503,
440,
4493,
6326,
267,
370,
314,
4702,
2897,
787,
6290,
370,
4543,
14,
221,
961,
365,
267,
12717,
402,
5532,
1337,
314,
1101,
14,
221,
3979,
663,
370,
715,
12,
314,
267,
4702,
2897,
365,
6290,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
889,
7,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
7908,
314,
3982,
2243,
523,
31766,
736,
63,
888,
26,
272,
2385,
26,
489,
446,
663,
2656,
1591,
13,
354,
8448,
8200,
63,
4269,
3586,
489,
446,
663,
2435,
28768,
489,
446,
3145,
2435,
19064,
13,
1000,
199,
199,
13,
536,
26,
6902,
436,
2248,
687,
570,
523,
31766,
736,
63,
888,
26,
272,
2928,
26,
31766,
736,
14,
4128,
272,
6902,
26,
9456,
199,
199,
13,
536,
26,
367,
9979,
9613,
9447,
12,
675,
2615,
13,
964,
3718,
523,
31766,
736,
63,
888,
26,
272,
2385,
26,
489,
327,
446,
663,
1109,
16227,
16227,
18,
1369,
283,
1877,
28035,
7,
489,
446,
663,
3217,
21944,
16227,
18,
1369,
283,
1877,
28035,
7,
199,
624,
199,
199,
9677,
275,
408,
199,
4405,
26,
523,
1369,
26,
710,
769,
402,
2897,
3718,
4847,
370,
314,
2243,
523,
2138,
26,
3544,
523,
730,
26,
769,
523,
2690,
26,
788,
20833,
24352,
418,
199,
11142,
26,
523,
1369,
26,
710,
769,
402,
2897,
3718,
4829,
370,
5126,
282,
2248,
5988,
523,
2138,
26,
3544,
523,
730,
26,
769,
523,
2690,
26,
788,
20833,
24352,
418,
199,
5751,
63,
515,
26,
523,
1369,
26,
710,
0
] |
[
1,
1,
1,
1,
1,
1,
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lib/python2.7/xml/dom/xmlbuilder.py
|
239
|
12337
|
"""Implementation of the DOM Level 3 'LS-Load' feature."""
import copy
import xml.dom
from xml.dom.NodeFilter import NodeFilter
__all__ = ["DOMBuilder", "DOMEntityResolver", "DOMInputSource"]
class Options:
"""Features object that has variables set for each DOMBuilder feature.
The DOMBuilder class uses an instance of this class to pass settings to
the ExpatBuilder class.
"""
# Note that the DOMBuilder class in LoadSave constrains which of these
# values can be set using the DOM Level 3 LoadSave feature.
namespaces = 1
namespace_declarations = True
validation = False
external_parameter_entities = True
external_general_entities = True
external_dtd_subset = True
validate_if_schema = False
validate = False
datatype_normalization = False
create_entity_ref_nodes = True
entities = True
whitespace_in_element_content = True
cdata_sections = True
comments = True
charset_overrides_xml_encoding = True
infoset = False
supported_mediatypes_only = False
errorHandler = None
filter = None
class DOMBuilder:
entityResolver = None
errorHandler = None
filter = None
ACTION_REPLACE = 1
ACTION_APPEND_AS_CHILDREN = 2
ACTION_INSERT_AFTER = 3
ACTION_INSERT_BEFORE = 4
_legal_actions = (ACTION_REPLACE, ACTION_APPEND_AS_CHILDREN,
ACTION_INSERT_AFTER, ACTION_INSERT_BEFORE)
def __init__(self):
self._options = Options()
def _get_entityResolver(self):
return self.entityResolver
def _set_entityResolver(self, entityResolver):
self.entityResolver = entityResolver
def _get_errorHandler(self):
return self.errorHandler
def _set_errorHandler(self, errorHandler):
self.errorHandler = errorHandler
def _get_filter(self):
return self.filter
def _set_filter(self, filter):
self.filter = filter
def setFeature(self, name, state):
if self.supportsFeature(name):
state = state and 1 or 0
try:
settings = self._settings[(_name_xform(name), state)]
except KeyError:
raise xml.dom.NotSupportedErr(
"unsupported feature: %r" % (name,))
else:
for name, value in settings:
setattr(self._options, name, value)
else:
raise xml.dom.NotFoundErr("unknown feature: " + repr(name))
def supportsFeature(self, name):
return hasattr(self._options, _name_xform(name))
def canSetFeature(self, name, state):
key = (_name_xform(name), state and 1 or 0)
return key in self._settings
# This dictionary maps from (feature,value) to a list of
# (option,value) pairs that should be set on the Options object.
# If a (feature,value) setting is not in this dictionary, it is
# not supported by the DOMBuilder.
#
_settings = {
("namespace_declarations", 0): [
("namespace_declarations", 0)],
("namespace_declarations", 1): [
("namespace_declarations", 1)],
("validation", 0): [
("validation", 0)],
("external_general_entities", 0): [
("external_general_entities", 0)],
("external_general_entities", 1): [
("external_general_entities", 1)],
("external_parameter_entities", 0): [
("external_parameter_entities", 0)],
("external_parameter_entities", 1): [
("external_parameter_entities", 1)],
("validate_if_schema", 0): [
("validate_if_schema", 0)],
("create_entity_ref_nodes", 0): [
("create_entity_ref_nodes", 0)],
("create_entity_ref_nodes", 1): [
("create_entity_ref_nodes", 1)],
("entities", 0): [
("create_entity_ref_nodes", 0),
("entities", 0)],
("entities", 1): [
("entities", 1)],
("whitespace_in_element_content", 0): [
("whitespace_in_element_content", 0)],
("whitespace_in_element_content", 1): [
("whitespace_in_element_content", 1)],
("cdata_sections", 0): [
("cdata_sections", 0)],
("cdata_sections", 1): [
("cdata_sections", 1)],
("comments", 0): [
("comments", 0)],
("comments", 1): [
("comments", 1)],
("charset_overrides_xml_encoding", 0): [
("charset_overrides_xml_encoding", 0)],
("charset_overrides_xml_encoding", 1): [
("charset_overrides_xml_encoding", 1)],
("infoset", 0): [],
("infoset", 1): [
("namespace_declarations", 0),
("validate_if_schema", 0),
("create_entity_ref_nodes", 0),
("entities", 0),
("cdata_sections", 0),
("datatype_normalization", 1),
("whitespace_in_element_content", 1),
("comments", 1),
("charset_overrides_xml_encoding", 1)],
("supported_mediatypes_only", 0): [
("supported_mediatypes_only", 0)],
("namespaces", 0): [
("namespaces", 0)],
("namespaces", 1): [
("namespaces", 1)],
}
def getFeature(self, name):
xname = _name_xform(name)
try:
return getattr(self._options, xname)
except AttributeError:
if name == "infoset":
options = self._options
return (options.datatype_normalization
and options.whitespace_in_element_content
and options.comments
and options.charset_overrides_xml_encoding
and not (options.namespace_declarations
or options.validate_if_schema
or options.create_entity_ref_nodes
or options.entities
or options.cdata_sections))
raise xml.dom.NotFoundErr("feature %s not known" % repr(name))
def parseURI(self, uri):
if self.entityResolver:
input = self.entityResolver.resolveEntity(None, uri)
else:
input = DOMEntityResolver().resolveEntity(None, uri)
return self.parse(input)
def parse(self, input):
options = copy.copy(self._options)
options.filter = self.filter
options.errorHandler = self.errorHandler
fp = input.byteStream
if fp is None and options.systemId:
import urllib2
fp = urllib2.urlopen(input.systemId)
return self._parse_bytestream(fp, options)
def parseWithContext(self, input, cnode, action):
if action not in self._legal_actions:
raise ValueError("not a legal action")
raise NotImplementedError("Haven't written this yet...")
def _parse_bytestream(self, stream, options):
import xml.dom.expatbuilder
builder = xml.dom.expatbuilder.makeBuilder(options)
return builder.parseFile(stream)
def _name_xform(name):
return name.lower().replace('-', '_')
class DOMEntityResolver(object):
__slots__ = '_opener',
def resolveEntity(self, publicId, systemId):
assert systemId is not None
source = DOMInputSource()
source.publicId = publicId
source.systemId = systemId
source.byteStream = self._get_opener().open(systemId)
# determine the encoding if the transport provided it
source.encoding = self._guess_media_encoding(source)
# determine the base URI is we can
import posixpath, urlparse
parts = urlparse.urlparse(systemId)
scheme, netloc, path, params, query, fragment = parts
# XXX should we check the scheme here as well?
if path and not path.endswith("/"):
path = posixpath.dirname(path) + "/"
parts = scheme, netloc, path, params, query, fragment
source.baseURI = urlparse.urlunparse(parts)
return source
def _get_opener(self):
try:
return self._opener
except AttributeError:
self._opener = self._create_opener()
return self._opener
def _create_opener(self):
import urllib2
return urllib2.build_opener()
def _guess_media_encoding(self, source):
info = source.byteStream.info()
if "Content-Type" in info:
for param in info.getplist():
if param.startswith("charset="):
return param.split("=", 1)[1].lower()
class DOMInputSource(object):
__slots__ = ('byteStream', 'characterStream', 'stringData',
'encoding', 'publicId', 'systemId', 'baseURI')
def __init__(self):
self.byteStream = None
self.characterStream = None
self.stringData = None
self.encoding = None
self.publicId = None
self.systemId = None
self.baseURI = None
def _get_byteStream(self):
return self.byteStream
def _set_byteStream(self, byteStream):
self.byteStream = byteStream
def _get_characterStream(self):
return self.characterStream
def _set_characterStream(self, characterStream):
self.characterStream = characterStream
def _get_stringData(self):
return self.stringData
def _set_stringData(self, data):
self.stringData = data
def _get_encoding(self):
return self.encoding
def _set_encoding(self, encoding):
self.encoding = encoding
def _get_publicId(self):
return self.publicId
def _set_publicId(self, publicId):
self.publicId = publicId
def _get_systemId(self):
return self.systemId
def _set_systemId(self, systemId):
self.systemId = systemId
def _get_baseURI(self):
return self.baseURI
def _set_baseURI(self, uri):
self.baseURI = uri
class DOMBuilderFilter:
"""Element filter which can be used to tailor construction of
a DOM instance.
"""
# There's really no need for this class; concrete implementations
# should just implement the endElement() and startElement()
# methods as appropriate. Using this makes it easy to only
# implement one of them.
FILTER_ACCEPT = 1
FILTER_REJECT = 2
FILTER_SKIP = 3
FILTER_INTERRUPT = 4
whatToShow = NodeFilter.SHOW_ALL
def _get_whatToShow(self):
return self.whatToShow
def acceptNode(self, element):
return self.FILTER_ACCEPT
def startContainer(self, element):
return self.FILTER_ACCEPT
del NodeFilter
class DocumentLS:
"""Mixin to create documents that conform to the load/save spec."""
async = False
def _get_async(self):
return False
def _set_async(self, async):
if async:
raise xml.dom.NotSupportedErr(
"asynchronous document loading is not supported")
def abort(self):
# What does it mean to "clear" a document? Does the
# documentElement disappear?
raise NotImplementedError(
"haven't figured out what this means yet")
def load(self, uri):
raise NotImplementedError("haven't written this yet")
def loadXML(self, source):
raise NotImplementedError("haven't written this yet")
def saveXML(self, snode):
if snode is None:
snode = self
elif snode.ownerDocument is not self:
raise xml.dom.WrongDocumentErr()
return snode.toxml()
class DOMImplementationLS:
MODE_SYNCHRONOUS = 1
MODE_ASYNCHRONOUS = 2
def createDOMBuilder(self, mode, schemaType):
if schemaType is not None:
raise xml.dom.NotSupportedErr(
"schemaType not yet supported")
if mode == self.MODE_SYNCHRONOUS:
return DOMBuilder()
if mode == self.MODE_ASYNCHRONOUS:
raise xml.dom.NotSupportedErr(
"asynchronous builders are not supported")
raise ValueError("unknown value for mode")
def createDOMWriter(self):
raise NotImplementedError(
"the writer interface hasn't been written yet!")
def createDOMInputSource(self):
return DOMInputSource()
|
gpl-2.0
|
[
624,
7921,
402,
314,
14316,
20400,
650,
283,
5296,
13,
6200,
7,
3878,
1041,
199,
199,
646,
1331,
199,
646,
2748,
14,
4556,
199,
199,
504,
2748,
14,
4556,
14,
1716,
4131,
492,
5013,
4131,
421,
199,
363,
452,
363,
275,
2097,
10462,
6437,
401,
298,
10462,
7302,
12407,
401,
298,
10462,
3205,
2980,
937,
421,
199,
533,
8394,
26,
272,
408,
10807,
909,
626,
965,
2860,
663,
367,
1924,
14316,
6437,
3878,
14,
339,
710,
14316,
6437,
1021,
4440,
376,
1256,
402,
642,
1021,
370,
986,
2202,
370,
272,
314,
7910,
292,
6437,
1021,
14,
272,
408,
339,
327,
3390,
626,
314,
14316,
6437,
1021,
315,
7190,
8229,
950,
345,
3617,
1314,
402,
3520,
272,
327,
1338,
883,
506,
663,
1808,
314,
14316,
20400,
650,
7190,
8229,
3878,
14,
339,
10747,
275,
413,
272,
3231,
63,
21200,
275,
715,
272,
6411,
275,
756,
272,
5957,
63,
5329,
63,
8327,
275,
715,
272,
5957,
63,
10706,
63,
8327,
275,
715,
272,
5957,
63,
15662,
63,
9401,
275,
715,
272,
4107,
63,
692,
63,
3629,
275,
756,
272,
4107,
275,
756,
272,
16048,
63,
22384,
275,
756,
272,
1218,
63,
4502,
63,
1121,
63,
2415,
275,
715,
272,
9045,
275,
715,
272,
8139,
63,
262,
63,
2108,
63,
1317,
275,
715,
272,
286,
576,
63,
7786,
275,
715,
272,
6786,
275,
715,
272,
5960,
63,
12867,
63,
1652,
63,
2991,
275,
715,
272,
2256,
409,
275,
756,
272,
3748,
63,
3700,
8588,
83,
63,
2118,
275,
756,
339,
1125,
2461,
275,
488,
272,
2457,
275,
488,
421,
199,
533,
14316,
6437,
26,
272,
4642,
12407,
275,
488,
272,
1125,
2461,
275,
488,
272,
2457,
275,
488,
339,
9612,
63,
27010,
275,
413,
272,
9612,
63,
25248,
63,
1179,
63,
1244,
1193,
4564,
742,
275,
499,
272,
9612,
63,
10258,
63,
31883,
275,
650,
272,
9612,
63,
10258,
63,
31481,
275,
841,
339,
485,
9666,
63,
3723,
275,
334,
10052,
63,
27010,
12,
9612,
63,
25248,
63,
1179,
63,
1244,
1193,
4564,
742,
12,
1993,
9612,
63,
10258,
63,
31883,
12,
9612,
63,
10258,
63,
31481,
9,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
1419,
275,
8394,
342,
339,
347,
485,
362,
63,
4502,
12407,
8,
277,
304,
267,
372,
291,
14,
4502,
12407,
272,
347,
485,
409,
63,
4502,
12407,
8,
277,
12,
4642,
12407,
304,
267,
291,
14,
4502,
12407,
275,
4642,
12407,
339,
347,
485,
362,
63,
705,
2461,
8,
277,
304,
267,
372,
291,
14,
705,
2461,
272,
347,
485,
409,
63,
705,
2461,
8,
277,
12,
1125,
2461,
304,
267,
291,
14,
705,
2461,
275,
1125,
2461,
339,
347,
485,
362,
63,
1541,
8,
277,
304,
267,
372,
291,
14,
1541,
272,
347,
485,
409,
63,
1541,
8,
277,
12,
2457,
304,
267,
291,
14,
1541,
275,
2457,
339,
347,
663,
5968,
8,
277,
12,
536,
12,
1174,
304,
267,
340,
291,
14,
9823,
5968,
8,
354,
304,
288,
1174,
275,
1174,
436,
413,
503,
378,
288,
862,
26,
355,
2202,
275,
291,
423,
1751,
59,
1547,
354,
63,
24226,
8,
354,
395,
1174,
1874,
288,
871,
4067,
26,
355,
746,
2748,
14,
4556,
14,
26077,
5432,
8,
490,
298,
15267,
3878,
26,
450,
82,
2,
450,
334,
354,
4641,
288,
587,
26,
355,
367,
536,
12,
574,
315,
2202,
26,
490,
5371,
8,
277,
423,
1419,
12,
536,
12,
574,
9,
267,
587,
26,
288,
746,
2748,
14,
4556,
14,
4667,
5432,
480,
5187,
3878,
26,
298,
435,
4700,
8,
354,
430,
339,
347,
5171,
5968,
8,
277,
12,
536,
304,
267,
372,
2688,
8,
277,
423,
1419,
12,
485,
354,
63,
24226,
8,
354,
430,
339,
347,
883,
1084,
5968,
8,
277,
12,
536,
12,
1174,
304,
267,
790,
275,
6110,
354,
63,
24226,
8,
354,
395,
1174,
436,
413,
503,
378,
9,
267,
372,
790,
315,
291,
423,
1751,
339,
327,
961,
2600,
9033,
687,
334,
4445,
12,
585,
9,
370,
282,
769,
402,
272,
327,
334,
1422,
12,
585,
9,
6342,
626,
1077,
506,
663,
641,
314,
8394,
909,
14,
272,
327,
982,
282,
334,
4445,
12,
585,
9,
4260,
365,
440,
315,
642,
2600,
12,
652,
365,
272,
327,
440,
3748,
701,
314,
14316,
6437,
14,
272,
327,
272,
485,
1751,
275,
469,
267,
1689,
3251,
63,
21200,
401,
378,
304,
359,
288,
1689,
3251,
63,
21200,
401,
378,
4360,
267,
1689,
3251,
63,
21200,
401,
413,
304,
359,
288,
1689,
3251,
63,
21200,
401,
413,
4360,
267,
1689,
6136,
401,
378,
304,
359,
288,
1689,
6136,
401,
378,
4360,
267,
1689,
5159,
63,
10706,
63,
8327,
401,
378,
304,
359,
288,
1689,
5159,
63,
10706,
63,
8327,
401,
378,
4360,
267,
1689,
5159,
63,
10706,
63,
8327,
401,
413,
304,
359,
288,
1689,
5159,
63,
10706,
63,
8327,
401,
413,
4360,
267,
1689,
5159,
63,
5329,
63,
8327,
401,
378,
304,
359,
288,
1689,
5159,
63,
5329,
63,
8327,
401,
378,
4360,
267,
1689,
5159,
63,
5329,
63,
8327,
401,
413,
304,
359,
288,
1689,
5159,
63,
5329,
63,
8327,
401,
413,
4360,
267,
1689,
3502,
63,
692,
63,
3629,
401,
378,
304,
359,
288,
1689,
3502,
63,
692,
63,
3629,
401,
378,
4360,
267,
1689,
981,
63,
4502,
63,
1121,
63,
2415,
401,
378,
304,
359,
288,
1689,
981,
63,
4502,
63,
1121,
63,
2415,
401,
378,
4360,
267,
1689,
981,
63,
4502,
63,
1121,
63,
2415,
401,
413,
304,
359,
288,
1689,
981,
63,
4502,
63,
1121,
63,
2415,
401,
413,
4360,
267,
1689,
8327,
401,
378,
304,
359,
288,
1689,
981,
63,
4502,
63,
1121,
63,
2415,
401,
378,
395,
288,
1689,
8327,
401,
378,
4360,
267,
1689,
8327,
401,
413,
304,
359,
288,
1689,
8327,
401,
413,
4360,
267,
1689,
8506,
63,
262,
63,
2108,
63,
1317,
401,
378,
304,
359,
288,
1689,
8506,
63,
262,
63,
2108,
63,
1317,
401,
378,
4360,
267,
1689,
8506,
63,
262,
63,
2108,
63,
1317,
401,
413,
304,
359,
288,
1689,
8506,
63,
262,
63,
2108,
63,
1317,
401,
413,
4360,
267,
1689,
15892,
63,
7786,
401,
378,
304,
359,
288,
1689,
15892,
63,
7786,
401,
378,
4360,
267,
1689,
15892,
63,
7786,
401,
413,
304,
359,
288,
1689,
15892,
63
] |
[
7921,
402,
314,
14316,
20400,
650,
283,
5296,
13,
6200,
7,
3878,
1041,
199,
199,
646,
1331,
199,
646,
2748,
14,
4556,
199,
199,
504,
2748,
14,
4556,
14,
1716,
4131,
492,
5013,
4131,
421,
199,
363,
452,
363,
275,
2097,
10462,
6437,
401,
298,
10462,
7302,
12407,
401,
298,
10462,
3205,
2980,
937,
421,
199,
533,
8394,
26,
272,
408,
10807,
909,
626,
965,
2860,
663,
367,
1924,
14316,
6437,
3878,
14,
339,
710,
14316,
6437,
1021,
4440,
376,
1256,
402,
642,
1021,
370,
986,
2202,
370,
272,
314,
7910,
292,
6437,
1021,
14,
272,
408,
339,
327,
3390,
626,
314,
14316,
6437,
1021,
315,
7190,
8229,
950,
345,
3617,
1314,
402,
3520,
272,
327,
1338,
883,
506,
663,
1808,
314,
14316,
20400,
650,
7190,
8229,
3878,
14,
339,
10747,
275,
413,
272,
3231,
63,
21200,
275,
715,
272,
6411,
275,
756,
272,
5957,
63,
5329,
63,
8327,
275,
715,
272,
5957,
63,
10706,
63,
8327,
275,
715,
272,
5957,
63,
15662,
63,
9401,
275,
715,
272,
4107,
63,
692,
63,
3629,
275,
756,
272,
4107,
275,
756,
272,
16048,
63,
22384,
275,
756,
272,
1218,
63,
4502,
63,
1121,
63,
2415,
275,
715,
272,
9045,
275,
715,
272,
8139,
63,
262,
63,
2108,
63,
1317,
275,
715,
272,
286,
576,
63,
7786,
275,
715,
272,
6786,
275,
715,
272,
5960,
63,
12867,
63,
1652,
63,
2991,
275,
715,
272,
2256,
409,
275,
756,
272,
3748,
63,
3700,
8588,
83,
63,
2118,
275,
756,
339,
1125,
2461,
275,
488,
272,
2457,
275,
488,
421,
199,
533,
14316,
6437,
26,
272,
4642,
12407,
275,
488,
272,
1125,
2461,
275,
488,
272,
2457,
275,
488,
339,
9612,
63,
27010,
275,
413,
272,
9612,
63,
25248,
63,
1179,
63,
1244,
1193,
4564,
742,
275,
499,
272,
9612,
63,
10258,
63,
31883,
275,
650,
272,
9612,
63,
10258,
63,
31481,
275,
841,
339,
485,
9666,
63,
3723,
275,
334,
10052,
63,
27010,
12,
9612,
63,
25248,
63,
1179,
63,
1244,
1193,
4564,
742,
12,
1993,
9612,
63,
10258,
63,
31883,
12,
9612,
63,
10258,
63,
31481,
9,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
1419,
275,
8394,
342,
339,
347,
485,
362,
63,
4502,
12407,
8,
277,
304,
267,
372,
291,
14,
4502,
12407,
272,
347,
485,
409,
63,
4502,
12407,
8,
277,
12,
4642,
12407,
304,
267,
291,
14,
4502,
12407,
275,
4642,
12407,
339,
347,
485,
362,
63,
705,
2461,
8,
277,
304,
267,
372,
291,
14,
705,
2461,
272,
347,
485,
409,
63,
705,
2461,
8,
277,
12,
1125,
2461,
304,
267,
291,
14,
705,
2461,
275,
1125,
2461,
339,
347,
485,
362,
63,
1541,
8,
277,
304,
267,
372,
291,
14,
1541,
272,
347,
485,
409,
63,
1541,
8,
277,
12,
2457,
304,
267,
291,
14,
1541,
275,
2457,
339,
347,
663,
5968,
8,
277,
12,
536,
12,
1174,
304,
267,
340,
291,
14,
9823,
5968,
8,
354,
304,
288,
1174,
275,
1174,
436,
413,
503,
378,
288,
862,
26,
355,
2202,
275,
291,
423,
1751,
59,
1547,
354,
63,
24226,
8,
354,
395,
1174,
1874,
288,
871,
4067,
26,
355,
746,
2748,
14,
4556,
14,
26077,
5432,
8,
490,
298,
15267,
3878,
26,
450,
82,
2,
450,
334,
354,
4641,
288,
587,
26,
355,
367,
536,
12,
574,
315,
2202,
26,
490,
5371,
8,
277,
423,
1419,
12,
536,
12,
574,
9,
267,
587,
26,
288,
746,
2748,
14,
4556,
14,
4667,
5432,
480,
5187,
3878,
26,
298,
435,
4700,
8,
354,
430,
339,
347,
5171,
5968,
8,
277,
12,
536,
304,
267,
372,
2688,
8,
277,
423,
1419,
12,
485,
354,
63,
24226,
8,
354,
430,
339,
347,
883,
1084,
5968,
8,
277,
12,
536,
12,
1174,
304,
267,
790,
275,
6110,
354,
63,
24226,
8,
354,
395,
1174,
436,
413,
503,
378,
9,
267,
372,
790,
315,
291,
423,
1751,
339,
327,
961,
2600,
9033,
687,
334,
4445,
12,
585,
9,
370,
282,
769,
402,
272,
327,
334,
1422,
12,
585,
9,
6342,
626,
1077,
506,
663,
641,
314,
8394,
909,
14,
272,
327,
982,
282,
334,
4445,
12,
585,
9,
4260,
365,
440,
315,
642,
2600,
12,
652,
365,
272,
327,
440,
3748,
701,
314,
14316,
6437,
14,
272,
327,
272,
485,
1751,
275,
469,
267,
1689,
3251,
63,
21200,
401,
378,
304,
359,
288,
1689,
3251,
63,
21200,
401,
378,
4360,
267,
1689,
3251,
63,
21200,
401,
413,
304,
359,
288,
1689,
3251,
63,
21200,
401,
413,
4360,
267,
1689,
6136,
401,
378,
304,
359,
288,
1689,
6136,
401,
378,
4360,
267,
1689,
5159,
63,
10706,
63,
8327,
401,
378,
304,
359,
288,
1689,
5159,
63,
10706,
63,
8327,
401,
378,
4360,
267,
1689,
5159,
63,
10706,
63,
8327,
401,
413,
304,
359,
288,
1689,
5159,
63,
10706,
63,
8327,
401,
413,
4360,
267,
1689,
5159,
63,
5329,
63,
8327,
401,
378,
304,
359,
288,
1689,
5159,
63,
5329,
63,
8327,
401,
378,
4360,
267,
1689,
5159,
63,
5329,
63,
8327,
401,
413,
304,
359,
288,
1689,
5159,
63,
5329,
63,
8327,
401,
413,
4360,
267,
1689,
3502,
63,
692,
63,
3629,
401,
378,
304,
359,
288,
1689,
3502,
63,
692,
63,
3629,
401,
378,
4360,
267,
1689,
981,
63,
4502,
63,
1121,
63,
2415,
401,
378,
304,
359,
288,
1689,
981,
63,
4502,
63,
1121,
63,
2415,
401,
378,
4360,
267,
1689,
981,
63,
4502,
63,
1121,
63,
2415,
401,
413,
304,
359,
288,
1689,
981,
63,
4502,
63,
1121,
63,
2415,
401,
413,
4360,
267,
1689,
8327,
401,
378,
304,
359,
288,
1689,
981,
63,
4502,
63,
1121,
63,
2415,
401,
378,
395,
288,
1689,
8327,
401,
378,
4360,
267,
1689,
8327,
401,
413,
304,
359,
288,
1689,
8327,
401,
413,
4360,
267,
1689,
8506,
63,
262,
63,
2108,
63,
1317,
401,
378,
304,
359,
288,
1689,
8506,
63,
262,
63,
2108,
63,
1317,
401,
378,
4360,
267,
1689,
8506,
63,
262,
63,
2108,
63,
1317,
401,
413,
304,
359,
288,
1689,
8506,
63,
262,
63,
2108,
63,
1317,
401,
413,
4360,
267,
1689,
15892,
63,
7786,
401,
378,
304,
359,
288,
1689,
15892,
63,
7786,
401,
378,
4360,
267,
1689,
15892,
63,
7786,
401,
413,
304,
359,
288,
1689,
15892,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
n0trax/ansible
|
lib/ansible/parsing/metadata.py
|
41
|
10025
|
# (c) 2017, Toshio Kuratomi <tkuratomi@ansible.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import ast
import sys
import yaml
from ansible.module_utils._text import to_text
# There are currently defaults for all metadata fields so we can add it
# automatically if a file doesn't specify it
DEFAULT_METADATA = {'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community'}
class ParseError(Exception):
"""Thrown when parsing a file fails"""
pass
def _seek_end_of_dict(module_data, start_line, start_col, next_node_line, next_node_col):
"""Look for the end of a dict in a set of lines
We know the starting position of the dict and we know the start of the
next code node but in between there may be multiple newlines and comments.
There may also be multiple python statements on the same line (separated
by semicolons)
Examples::
ANSIBLE_METADATA = {[..]}
DOCUMENTATION = [..]
ANSIBLE_METADATA = {[..]} # Optional comments with confusing junk => {}
# Optional comments {}
DOCUMENTATION = [..]
ANSIBLE_METADATA = {
[..]
}
# Optional comments {}
DOCUMENTATION = [..]
ANSIBLE_METADATA = {[..]} ; DOCUMENTATION = [..]
ANSIBLE_METADATA = {}EOF
"""
if next_node_line is None:
# The dict is the last statement in the file
snippet = module_data.splitlines()[start_line:]
next_node_col = 0
# Include the last line in the file
last_line_offset = 0
else:
# It's somewhere in the middle so we need to separate it from the rest
snippet = module_data.splitlines()[start_line:next_node_line]
# Do not include the last line because that's where the next node
# starts
last_line_offset = 1
if next_node_col == 0:
# This handles all variants where there are only comments and blank
# lines between the dict and the next code node
# Step backwards through all the lines in the snippet
for line_idx, line in tuple(reversed(tuple(enumerate(snippet))))[last_line_offset:]:
end_col = None
# Step backwards through all the characters in the line
for col_idx, char in reversed(tuple(enumerate(c for c in line))):
if not isinstance(char, bytes):
# Python3 wart. slicing a byte string yields integers
char = bytes((char,))
if char == b'}' and end_col is None:
# Potentially found the end of the dict
end_col = col_idx
elif char == b'#' and end_col is not None:
# The previous '}' was part of a comment. Keep trying
end_col = None
if end_col is not None:
# Found the end!
end_line = start_line + line_idx
break
else:
raise ParseError('Unable to find the end of dictionary')
else:
# Harder cases involving multiple statements on one line
# Good Ansible Module style doesn't do this so we're just going to
# treat this as an error for now:
raise ParseError('Multiple statements per line confuses the module metadata parser.')
return end_line, end_col
def _seek_end_of_string(module_data, start_line, start_col, next_node_line, next_node_col):
"""
This is much trickier than finding the end of a dict. A dict has only one
ending character, "}". Strings have four potential ending characters. We
have to parse the beginning of the string to determine what the ending
character will be.
Examples:
ANSIBLE_METADATA = '''[..]''' # Optional comment with confusing chars '''
# Optional comment with confusing chars '''
DOCUMENTATION = [..]
ANSIBLE_METADATA = '''
[..]
'''
DOCUMENTATIONS = [..]
ANSIBLE_METADATA = '''[..]''' ; DOCUMENTATION = [..]
SHORT_NAME = ANSIBLE_METADATA = '''[..]''' ; DOCUMENTATION = [..]
String marker variants:
* '[..]'
* "[..]"
* '''[..]'''
* \"\"\"[..]\"\"\"
Each of these come in u, r, and b variants:
* '[..]'
* u'[..]'
* b'[..]'
* r'[..]'
* ur'[..]'
* ru'[..]'
* br'[..]'
* b'[..]'
* rb'[..]'
"""
raise NotImplementedError('Finding end of string not yet implemented')
def extract_metadata(module_ast=None, module_data=None, offsets=False):
"""Extract the metadata from a module
:kwarg module_ast: ast representation of the module. At least one of this
or ``module_data`` must be given. If the code calling
:func:`extract_metadata` has already parsed the module_data into an ast,
giving the ast here will save reparsing it.
:kwarg module_data: Byte string containing a module's code. At least one
of this or ``module_ast`` must be given.
:kwarg offsets: If set to True, offests into the source code will be
returned. This requires that ``module_data`` be set.
:returns: a tuple of metadata (a dict), line the metadata starts on,
column the metadata starts on, line the metadata ends on, column the
metadata ends on, and the names the metadata is assigned to. One of
the names the metadata is assigned to will be ANSIBLE_METADATA. If no
metadata is found, the tuple will be (None, -1, -1, -1, -1, None).
If ``offsets`` is False then the tuple will consist of
(metadata, -1, -1, -1, -1, None).
:raises ansible.parsing.metadata.ParseError: if ``module_data`` does not parse
:raises SyntaxError: if ``module_data`` is needed but does not parse correctly
"""
if offsets and module_data is None:
raise TypeError('If offsets is True then module_data must also be given')
if module_ast is None and module_data is None:
raise TypeError('One of module_ast or module_data must be given')
metadata = None
start_line = -1
start_col = -1
end_line = -1
end_col = -1
targets = None
if module_ast is None:
module_ast = ast.parse(module_data)
for root_idx, child in reversed(list(enumerate(module_ast.body))):
if isinstance(child, ast.Assign):
for target in child.targets:
if target.id == 'ANSIBLE_METADATA':
metadata = ast.literal_eval(child.value)
if not offsets:
continue
try:
# Determine where the next node starts
next_node = module_ast.body[root_idx + 1]
next_lineno = next_node.lineno
next_col_offset = next_node.col_offset
except IndexError:
# Metadata is defined in the last node of the file
next_lineno = None
next_col_offset = None
if isinstance(child.value, ast.Dict):
# Determine where the current metadata ends
end_line, end_col = _seek_end_of_dict(module_data,
child.lineno - 1,
child.col_offset,
next_lineno,
next_col_offset)
elif isinstance(child.value, ast.Str):
metadata = yaml.safe_load(child.value.s)
end_line, end_col = _seek_end_of_string(module_data,
child.lineno - 1,
child.col_offset,
next_lineno,
next_col_offset)
elif isinstance(child.value, ast.Bytes):
metadata = yaml.safe_load(to_text(child.value.s, errors='surrogate_or_strict'))
end_line, end_col = _seek_end_of_string(module_data,
child.lineno - 1,
child.col_offset,
next_lineno,
next_col_offset)
else:
raise ParseError('Ansible plugin metadata must be a dict')
# Do these after the if-else so we don't pollute them in
# case this was a false positive
start_line = child.lineno - 1
start_col = child.col_offset
targets = [t.id for t in child.targets]
break
if metadata is not None:
# Once we've found the metadata we're done
break
return metadata, start_line, start_col, end_line, end_col, targets
|
gpl-3.0
|
[
3,
334,
67,
9,
9708,
12,
4005,
609,
2308,
1804,
300,
4188,
73,
665,
2663,
300,
4188,
73,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
6073,
199,
646,
984,
199,
199,
646,
8864,
199,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
505,
421,
199,
3,
6006,
787,
5544,
4243,
367,
1006,
3341,
1504,
880,
781,
883,
1050,
652,
199,
3,
5847,
340,
282,
570,
3181,
1133,
4165,
652,
199,
3472,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
283,
1205,
356,
788,
7780,
995,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
533,
21743,
8,
1726,
304,
272,
408,
2719,
18406,
1380,
6057,
282,
570,
6918,
624,
272,
986,
421,
199,
318,
485,
5507,
63,
500,
63,
1618,
63,
807,
8,
578,
63,
576,
12,
1343,
63,
604,
12,
1343,
63,
761,
12,
2163,
63,
932,
63,
604,
12,
2163,
63,
932,
63,
761,
304,
272,
408,
20926,
367,
314,
1284,
402,
282,
1211,
315,
282,
663,
402,
2385,
339,
2136,
5715,
314,
6617,
3421,
402,
314,
1211,
436,
781,
5715,
314,
1343,
402,
314,
272,
2163,
1233,
1031,
1325,
315,
3382,
2337,
1443,
506,
3663,
14930,
436,
6786,
14,
272,
6006,
1443,
2597,
506,
3663,
2366,
9834,
641,
314,
2011,
1004,
334,
12794,
272,
701,
18734,
761,
4654,
9,
339,
6058,
447,
267,
32271,
7187,
63,
8314,
275,
469,
59,
703,
9420,
267,
29970,
2594,
275,
359,
703,
61,
398,
32271,
7187,
63,
8314,
275,
469,
59,
703,
9420,
327,
4879,
6786,
543,
3743,
4941,
24605,
9265,
1052,
267,
327,
4879,
6786,
1052,
267,
29970,
2594,
275,
359,
703,
61,
398,
32271,
7187,
63,
8314,
275,
469,
288,
359,
703,
61,
288,
789,
267,
327,
4879,
6786,
1052,
267,
29970,
2594,
275,
359,
703,
61,
398,
32271,
7187,
63,
8314,
275,
469,
59,
703,
9420,
8700,
29970,
2594,
275,
359,
703,
61,
398,
32271,
7187,
63,
8314,
275,
1052,
13178,
272,
408,
272,
340,
2163,
63,
932,
63,
604,
365,
488,
26,
267,
327,
710,
1211,
365,
314,
2061,
5164,
315,
314,
570,
267,
17440,
275,
859,
63,
576,
14,
7644,
3430,
928,
63,
604,
2938,
267,
2163,
63,
932,
63,
761,
275,
378,
267,
327,
15783,
314,
2061,
1004,
315,
314,
570,
267,
2061,
63,
604,
63,
2743,
275,
378,
272,
587,
26,
267,
327,
2779,
1159,
23430,
315,
314,
12180,
880,
781,
1929,
370,
7396,
652,
687,
314,
4618,
267,
17440,
275,
859,
63,
576,
14,
7644,
3430,
928,
63,
604,
26,
2184,
63,
932,
63,
604,
61,
267,
327,
4226,
440,
2387,
314,
2061,
1004,
2952,
626,
1159,
2382,
314,
2163,
1031,
267,
327,
9174,
267,
2061,
63,
604,
63,
2743,
275,
413,
339,
340,
2163,
63,
932,
63,
761,
508,
378,
26,
267,
327,
961,
10022,
1006,
21169,
2382,
2337,
787,
1454,
6786,
436,
4596,
267,
327,
2385,
3382,
314,
1211,
436,
314,
2163,
1233,
1031,
398,
327,
13382,
8552,
4012,
1006,
314,
2385,
315,
314,
17440,
267,
367,
1004,
63,
2996,
12,
1004,
315,
2008,
8,
13501,
8,
2960,
8,
26318,
8,
18547,
7845,
59,
2019,
63,
604,
63,
2743,
10688,
288,
1284,
63,
761,
275,
488,
288,
327,
13382,
8552,
4012,
1006,
314,
4110,
315,
314,
1004,
288,
367,
1048,
63,
2996,
12,
1495,
315,
10822,
8,
2960,
8,
26318,
8,
67,
367,
286,
315,
1004,
15206,
355,
340,
440,
1228,
8,
1560,
12,
2783,
304,
490,
327,
2018,
19,
336,
580,
14,
221,
23647,
282,
3696,
1059,
14801,
9446,
490,
1495,
275,
2783,
1332,
1560,
4641,
355,
340,
1495,
508,
330,
936,
7,
436,
1284,
63,
761,
365,
488,
26,
490,
327,
4376,
17690,
1911,
314,
1284,
402,
314,
1211,
490,
1284,
63,
761,
275,
1048,
63,
2996,
2234,
916,
1495,
508,
330,
11525,
7,
436,
1284,
63,
761,
365,
440,
488,
26,
490,
327,
710,
4136,
23618,
1990,
1777,
402,
282,
3721,
14,
221,
14797,
9936,
490,
1284,
63,
761,
275,
488,
953,
340,
1284,
63,
761,
365,
440,
488,
26,
355,
327,
2643,
314,
1284,
1,
355,
1284,
63,
604,
275,
1343,
63,
604,
435,
1004,
63,
2996,
355,
2059,
267,
587,
26,
288,
746,
21743,
360,
6005,
370,
2342,
314,
1284,
402,
2600,
358,
272,
587,
26,
267,
327,
25378,
424,
5560,
25613,
4007,
3663,
9834,
641,
1373,
1004,
267,
327,
22311,
2622,
5673,
3449,
3181,
1133,
886,
642,
880,
781,
3984,
2951,
9995,
370,
267,
327,
14312,
642,
465,
376,
1125,
367,
3063,
26,
267,
746,
21743,
360,
8433,
9834,
1126,
1004,
3743,
5589,
314,
859,
3341,
1798,
2659,
339,
372,
1284,
63,
604,
12,
1284,
63,
761,
421,
199,
318,
485,
5507,
63,
500,
63,
1618,
63,
875,
8,
578,
63,
576,
12,
1343,
63,
604,
12,
1343,
63,
761,
12,
2163,
63,
932,
63,
604,
12,
2163,
63,
932,
63,
761,
304,
272,
408,
272,
961,
365,
8298,
20907,
4446,
2419,
17196,
314,
1284,
402,
282,
1211,
14,
221,
437,
1211,
965,
1454,
1373,
272,
13401,
4528,
12,
298,
5469,
221,
24361,
1172,
11648,
12330,
13401
] |
[
334,
67,
9,
9708,
12,
4005,
609,
2308,
1804,
300,
4188,
73,
665,
2663,
300,
4188,
73,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
6073,
199,
646,
984,
199,
199,
646,
8864,
199,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
505,
421,
199,
3,
6006,
787,
5544,
4243,
367,
1006,
3341,
1504,
880,
781,
883,
1050,
652,
199,
3,
5847,
340,
282,
570,
3181,
1133,
4165,
652,
199,
3472,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
283,
1205,
356,
788,
7780,
995,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
533,
21743,
8,
1726,
304,
272,
408,
2719,
18406,
1380,
6057,
282,
570,
6918,
624,
272,
986,
421,
199,
318,
485,
5507,
63,
500,
63,
1618,
63,
807,
8,
578,
63,
576,
12,
1343,
63,
604,
12,
1343,
63,
761,
12,
2163,
63,
932,
63,
604,
12,
2163,
63,
932,
63,
761,
304,
272,
408,
20926,
367,
314,
1284,
402,
282,
1211,
315,
282,
663,
402,
2385,
339,
2136,
5715,
314,
6617,
3421,
402,
314,
1211,
436,
781,
5715,
314,
1343,
402,
314,
272,
2163,
1233,
1031,
1325,
315,
3382,
2337,
1443,
506,
3663,
14930,
436,
6786,
14,
272,
6006,
1443,
2597,
506,
3663,
2366,
9834,
641,
314,
2011,
1004,
334,
12794,
272,
701,
18734,
761,
4654,
9,
339,
6058,
447,
267,
32271,
7187,
63,
8314,
275,
469,
59,
703,
9420,
267,
29970,
2594,
275,
359,
703,
61,
398,
32271,
7187,
63,
8314,
275,
469,
59,
703,
9420,
327,
4879,
6786,
543,
3743,
4941,
24605,
9265,
1052,
267,
327,
4879,
6786,
1052,
267,
29970,
2594,
275,
359,
703,
61,
398,
32271,
7187,
63,
8314,
275,
469,
288,
359,
703,
61,
288,
789,
267,
327,
4879,
6786,
1052,
267,
29970,
2594,
275,
359,
703,
61,
398,
32271,
7187,
63,
8314,
275,
469,
59,
703,
9420,
8700,
29970,
2594,
275,
359,
703,
61,
398,
32271,
7187,
63,
8314,
275,
1052,
13178,
272,
408,
272,
340,
2163,
63,
932,
63,
604,
365,
488,
26,
267,
327,
710,
1211,
365,
314,
2061,
5164,
315,
314,
570,
267,
17440,
275,
859,
63,
576,
14,
7644,
3430,
928,
63,
604,
2938,
267,
2163,
63,
932,
63,
761,
275,
378,
267,
327,
15783,
314,
2061,
1004,
315,
314,
570,
267,
2061,
63,
604,
63,
2743,
275,
378,
272,
587,
26,
267,
327,
2779,
1159,
23430,
315,
314,
12180,
880,
781,
1929,
370,
7396,
652,
687,
314,
4618,
267,
17440,
275,
859,
63,
576,
14,
7644,
3430,
928,
63,
604,
26,
2184,
63,
932,
63,
604,
61,
267,
327,
4226,
440,
2387,
314,
2061,
1004,
2952,
626,
1159,
2382,
314,
2163,
1031,
267,
327,
9174,
267,
2061,
63,
604,
63,
2743,
275,
413,
339,
340,
2163,
63,
932,
63,
761,
508,
378,
26,
267,
327,
961,
10022,
1006,
21169,
2382,
2337,
787,
1454,
6786,
436,
4596,
267,
327,
2385,
3382,
314,
1211,
436,
314,
2163,
1233,
1031,
398,
327,
13382,
8552,
4012,
1006,
314,
2385,
315,
314,
17440,
267,
367,
1004,
63,
2996,
12,
1004,
315,
2008,
8,
13501,
8,
2960,
8,
26318,
8,
18547,
7845,
59,
2019,
63,
604,
63,
2743,
10688,
288,
1284,
63,
761,
275,
488,
288,
327,
13382,
8552,
4012,
1006,
314,
4110,
315,
314,
1004,
288,
367,
1048,
63,
2996,
12,
1495,
315,
10822,
8,
2960,
8,
26318,
8,
67,
367,
286,
315,
1004,
15206,
355,
340,
440,
1228,
8,
1560,
12,
2783,
304,
490,
327,
2018,
19,
336,
580,
14,
221,
23647,
282,
3696,
1059,
14801,
9446,
490,
1495,
275,
2783,
1332,
1560,
4641,
355,
340,
1495,
508,
330,
936,
7,
436,
1284,
63,
761,
365,
488,
26,
490,
327,
4376,
17690,
1911,
314,
1284,
402,
314,
1211,
490,
1284,
63,
761,
275,
1048,
63,
2996,
2234,
916,
1495,
508,
330,
11525,
7,
436,
1284,
63,
761,
365,
440,
488,
26,
490,
327,
710,
4136,
23618,
1990,
1777,
402,
282,
3721,
14,
221,
14797,
9936,
490,
1284,
63,
761,
275,
488,
953,
340,
1284,
63,
761,
365,
440,
488,
26,
355,
327,
2643,
314,
1284,
1,
355,
1284,
63,
604,
275,
1343,
63,
604,
435,
1004,
63,
2996,
355,
2059,
267,
587,
26,
288,
746,
21743,
360,
6005,
370,
2342,
314,
1284,
402,
2600,
358,
272,
587,
26,
267,
327,
25378,
424,
5560,
25613,
4007,
3663,
9834,
641,
1373,
1004,
267,
327,
22311,
2622,
5673,
3449,
3181,
1133,
886,
642,
880,
781,
3984,
2951,
9995,
370,
267,
327,
14312,
642,
465,
376,
1125,
367,
3063,
26,
267,
746,
21743,
360,
8433,
9834,
1126,
1004,
3743,
5589,
314,
859,
3341,
1798,
2659,
339,
372,
1284,
63,
604,
12,
1284,
63,
761,
421,
199,
318,
485,
5507,
63,
500,
63,
1618,
63,
875,
8,
578,
63,
576,
12,
1343,
63,
604,
12,
1343,
63,
761,
12,
2163,
63,
932,
63,
604,
12,
2163,
63,
932,
63,
761,
304,
272,
408,
272,
961,
365,
8298,
20907,
4446,
2419,
17196,
314,
1284,
402,
282,
1211,
14,
221,
437,
1211,
965,
1454,
1373,
272,
13401,
4528,
12,
298,
5469,
221,
24361,
1172,
11648,
12330,
13401,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bundgus/python-playground
|
matplotlib-playground/examples/event_handling/looking_glass.py
|
1
|
1280
|
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
x, y = np.random.rand(2, 200)
fig, ax = plt.subplots()
circ = patches.Circle((0.5, 0.5), 0.25, alpha=0.8, fc='yellow')
ax.add_patch(circ)
ax.plot(x, y, alpha=0.2)
line, = ax.plot(x, y, alpha=1.0, clip_path=circ)
class EventHandler(object):
def __init__(self):
fig.canvas.mpl_connect('button_press_event', self.onpress)
fig.canvas.mpl_connect('button_release_event', self.onrelease)
fig.canvas.mpl_connect('motion_notify_event', self.onmove)
self.x0, self.y0 = circ.center
self.pressevent = None
def onpress(self, event):
if event.inaxes != ax:
return
if not circ.contains(event)[0]:
return
self.pressevent = event
def onrelease(self, event):
self.pressevent = None
self.x0, self.y0 = circ.center
def onmove(self, event):
if self.pressevent is None or event.inaxes != self.pressevent.inaxes:
return
dx = event.xdata - self.pressevent.xdata
dy = event.ydata - self.pressevent.ydata
circ.center = self.x0 + dx, self.y0 + dy
line.set_clip_path(circ)
fig.canvas.draw()
handler = EventHandler()
plt.show()
|
mit
|
[
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
8027,
14,
11350,
465,
12385,
199,
88,
12,
612,
275,
980,
14,
2355,
14,
3759,
8,
18,
12,
1926,
9,
199,
199,
592,
12,
2185,
275,
4488,
14,
21430,
342,
199,
6092,
275,
12385,
14,
24587,
1332,
16,
14,
21,
12,
378,
14,
21,
395,
378,
14,
821,
12,
5131,
29,
16,
14,
24,
12,
10821,
534,
14514,
358,
199,
1219,
14,
525,
63,
2068,
8,
6092,
9,
421,
199,
1219,
14,
2798,
8,
88,
12,
612,
12,
5131,
29,
16,
14,
18,
9,
199,
604,
12,
275,
2185,
14,
2798,
8,
88,
12,
612,
12,
5131,
29,
17,
14,
16,
12,
11353,
63,
515,
29,
6092,
9,
421,
199,
533,
6763,
2461,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
6085,
14,
7682,
14,
2421,
63,
2242,
360,
3887,
63,
2915,
63,
1430,
297,
291,
14,
265,
2915,
9,
267,
6085,
14,
7682,
14,
2421,
63,
2242,
360,
3887,
63,
3221,
63,
1430,
297,
291,
14,
265,
3221,
9,
267,
6085,
14,
7682,
14,
2421,
63,
2242,
360,
15335,
63,
6814,
63,
1430,
297,
291,
14,
265,
1185,
9,
267,
291,
14,
88,
16,
12,
291,
14,
89,
16,
275,
9304,
14,
4218,
267,
291,
14,
24919,
261,
782,
275,
488,
339,
347,
641,
2915,
8,
277,
12,
1566,
304,
267,
340,
1566,
14,
262,
6402,
1137,
2185,
26,
288,
372,
398,
340,
440,
9304,
14,
6134,
8,
1430,
2788,
16,
2189,
288,
372,
398,
291,
14,
24919,
261,
782,
275,
1566,
339,
347,
641,
3221,
8,
277,
12,
1566,
304,
267,
291,
14,
24919,
261,
782,
275,
488,
267,
291,
14,
88,
16,
12,
291,
14,
89,
16,
275,
9304,
14,
4218,
339,
347,
641,
1185,
8,
277,
12,
1566,
304,
267,
340,
291,
14,
24919,
261,
782,
365,
488,
503,
1566,
14,
262,
6402,
1137,
291,
14,
24919,
261,
782,
14,
262,
6402,
26,
288,
372,
398,
11868,
275,
1566,
14,
31643,
446,
291,
14,
24919,
261,
782,
14,
31643,
267,
13119,
275,
1566,
14,
89,
576,
446,
291,
14,
24919,
261,
782,
14,
89,
576,
267,
9304,
14,
4218,
275,
291,
14,
88,
16,
435,
11868,
12,
291,
14,
89,
16,
435,
13119,
267,
1004,
14,
409,
63,
7548,
63,
515,
8,
6092,
9,
267,
6085,
14,
7682,
14,
5485,
342,
199,
199,
2232,
275,
6763,
2461,
342,
199,
6003,
14,
2384,
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
] |
[
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
8027,
14,
11350,
465,
12385,
199,
88,
12,
612,
275,
980,
14,
2355,
14,
3759,
8,
18,
12,
1926,
9,
199,
199,
592,
12,
2185,
275,
4488,
14,
21430,
342,
199,
6092,
275,
12385,
14,
24587,
1332,
16,
14,
21,
12,
378,
14,
21,
395,
378,
14,
821,
12,
5131,
29,
16,
14,
24,
12,
10821,
534,
14514,
358,
199,
1219,
14,
525,
63,
2068,
8,
6092,
9,
421,
199,
1219,
14,
2798,
8,
88,
12,
612,
12,
5131,
29,
16,
14,
18,
9,
199,
604,
12,
275,
2185,
14,
2798,
8,
88,
12,
612,
12,
5131,
29,
17,
14,
16,
12,
11353,
63,
515,
29,
6092,
9,
421,
199,
533,
6763,
2461,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
6085,
14,
7682,
14,
2421,
63,
2242,
360,
3887,
63,
2915,
63,
1430,
297,
291,
14,
265,
2915,
9,
267,
6085,
14,
7682,
14,
2421,
63,
2242,
360,
3887,
63,
3221,
63,
1430,
297,
291,
14,
265,
3221,
9,
267,
6085,
14,
7682,
14,
2421,
63,
2242,
360,
15335,
63,
6814,
63,
1430,
297,
291,
14,
265,
1185,
9,
267,
291,
14,
88,
16,
12,
291,
14,
89,
16,
275,
9304,
14,
4218,
267,
291,
14,
24919,
261,
782,
275,
488,
339,
347,
641,
2915,
8,
277,
12,
1566,
304,
267,
340,
1566,
14,
262,
6402,
1137,
2185,
26,
288,
372,
398,
340,
440,
9304,
14,
6134,
8,
1430,
2788,
16,
2189,
288,
372,
398,
291,
14,
24919,
261,
782,
275,
1566,
339,
347,
641,
3221,
8,
277,
12,
1566,
304,
267,
291,
14,
24919,
261,
782,
275,
488,
267,
291,
14,
88,
16,
12,
291,
14,
89,
16,
275,
9304,
14,
4218,
339,
347,
641,
1185,
8,
277,
12,
1566,
304,
267,
340,
291,
14,
24919,
261,
782,
365,
488,
503,
1566,
14,
262,
6402,
1137,
291,
14,
24919,
261,
782,
14,
262,
6402,
26,
288,
372,
398,
11868,
275,
1566,
14,
31643,
446,
291,
14,
24919,
261,
782,
14,
31643,
267,
13119,
275,
1566,
14,
89,
576,
446,
291,
14,
24919,
261,
782,
14,
89,
576,
267,
9304,
14,
4218,
275,
291,
14,
88,
16,
435,
11868,
12,
291,
14,
89,
16,
435,
13119,
267,
1004,
14,
409,
63,
7548,
63,
515,
8,
6092,
9,
267,
6085,
14,
7682,
14,
5485,
342,
199,
199,
2232,
275,
6763,
2461,
342,
199,
6003,
14,
2384,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
cgar/servo
|
tests/wpt/mozilla/tests/mozilla/referrer-policy/generic/tools/common_paths.py
|
238
|
1823
|
import os, sys, json, re
script_directory = os.path.dirname(os.path.abspath(__file__))
generic_directory = os.path.abspath(os.path.join(script_directory, '..'))
template_directory = os.path.abspath(os.path.join(script_directory,
'..',
'template'))
spec_directory = os.path.abspath(os.path.join(script_directory, '..', '..'))
test_root_directory = os.path.abspath(os.path.join(script_directory,
'..', '..', '..'))
spec_filename = os.path.join(spec_directory, "spec.src.json")
generated_spec_json_filename = os.path.join(spec_directory, "spec_json.js")
selection_pattern = '%(delivery_method)s/' + \
'%(origin)s/' + \
'%(source_protocol)s-%(target_protocol)s/' + \
'%(subresource)s/'
test_file_path_pattern = '%(spec_name)s/' + selection_pattern + \
'%(name)s.%(redirection)s.%(source_protocol)s.html'
def get_template(basename):
with open(os.path.join(template_directory, basename)) as f:
return f.read()
def read_nth_line(fp, line_number):
fp.seek(0)
for i, line in enumerate(fp):
if (i + 1) == line_number:
return line
def load_spec_json():
re_error_location = re.compile('line ([0-9]+) column ([0-9]+)')
with open(spec_filename) as f:
try:
spec_json = json.load(f)
except ValueError, ex:
print ex.message
match = re_error_location.search(ex.message)
if match:
line_number, column = int(match.group(1)), int(match.group(2))
print read_nth_line(f, line_number).rstrip()
print " " * (column - 1) + "^"
sys.exit(1)
return spec_json
|
mpl-2.0
|
[
646,
747,
12,
984,
12,
2022,
12,
295,
199,
199,
1579,
63,
3619,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
6767,
63,
3619,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
1579,
63,
3619,
12,
11541,
1333,
199,
199,
1160,
63,
3619,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
1579,
63,
3619,
12,
8179,
19155,
8179,
283,
1160,
1333,
199,
1650,
63,
3619,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
1579,
63,
3619,
12,
19155,
11541,
1333,
199,
396,
63,
1231,
63,
3619,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
1579,
63,
3619,
12,
8962,
19155,
19155,
11541,
1333,
199,
199,
1650,
63,
1501,
275,
747,
14,
515,
14,
904,
8,
1650,
63,
3619,
12,
298,
1650,
14,
2164,
14,
1001,
531,
199,
10176,
63,
1650,
63,
1001,
63,
1501,
275,
747,
14,
515,
14,
904,
8,
1650,
63,
3619,
12,
298,
1650,
63,
1001,
14,
3596,
531,
199,
199,
5592,
63,
3401,
275,
9487,
14564,
63,
765,
9,
83,
4805,
435,
971,
490,
9487,
6493,
9,
83,
4805,
435,
971,
490,
9487,
1365,
63,
3922,
9,
83,
13,
2840,
1375,
63,
3922,
9,
83,
4805,
435,
971,
490,
9487,
954,
1927,
9,
83,
4805,
199,
199,
396,
63,
493,
63,
515,
63,
3401,
275,
9487,
1650,
63,
354,
9,
83,
4805,
435,
7267,
63,
3401,
435,
971,
586,
9487,
354,
9,
83,
31706,
264,
6874,
9,
83,
31706,
1365,
63,
3922,
9,
83,
14,
1360,
7,
421,
199,
318,
664,
63,
1160,
8,
4846,
304,
272,
543,
1551,
8,
736,
14,
515,
14,
904,
8,
1160,
63,
3619,
12,
9593,
430,
465,
289,
26,
267,
372,
289,
14,
739,
342,
421,
199,
318,
1586,
63,
16621,
63,
604,
8,
3997,
12,
1004,
63,
1955,
304,
523,
4090,
14,
5507,
8,
16,
9,
523,
367,
284,
12,
1004,
315,
3874,
8,
3997,
304,
272,
340,
334,
73,
435,
413,
9,
508,
1004,
63,
1955,
26,
489,
372,
1004,
421,
199,
318,
2248,
63,
1650,
63,
1001,
837,
272,
295,
63,
705,
63,
1985,
275,
295,
14,
2014,
360,
604,
7287,
16,
13,
25,
11896,
2763,
7287,
16,
13,
25,
2807,
5942,
272,
543,
1551,
8,
1650,
63,
1501,
9,
465,
289,
26,
267,
862,
26,
881,
3158,
63,
1001,
275,
2022,
14,
912,
8,
70,
9,
267,
871,
1722,
12,
444,
26,
881,
870,
444,
14,
1188,
881,
1336,
275,
295,
63,
705,
63,
1985,
14,
1733,
8,
476,
14,
1188,
9,
881,
340,
1336,
26,
288,
1004,
63,
1955,
12,
2763,
275,
1109,
8,
1431,
14,
923,
8,
17,
1826,
1109,
8,
1431,
14,
923,
8,
18,
430,
288,
870,
1586,
63,
16621,
63,
604,
8,
70,
12,
1004,
63,
1955,
680,
6735,
342,
288,
870,
298,
298,
627,
334,
2301,
446,
413,
9,
435,
18129,
2,
8592,
984,
14,
2224,
8,
17,
9,
398,
372,
3158,
63,
1001,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
12,
984,
12,
2022,
12,
295,
199,
199,
1579,
63,
3619,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
6767,
63,
3619,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
1579,
63,
3619,
12,
11541,
1333,
199,
199,
1160,
63,
3619,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
1579,
63,
3619,
12,
8179,
19155,
8179,
283,
1160,
1333,
199,
1650,
63,
3619,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
1579,
63,
3619,
12,
19155,
11541,
1333,
199,
396,
63,
1231,
63,
3619,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
1579,
63,
3619,
12,
8962,
19155,
19155,
11541,
1333,
199,
199,
1650,
63,
1501,
275,
747,
14,
515,
14,
904,
8,
1650,
63,
3619,
12,
298,
1650,
14,
2164,
14,
1001,
531,
199,
10176,
63,
1650,
63,
1001,
63,
1501,
275,
747,
14,
515,
14,
904,
8,
1650,
63,
3619,
12,
298,
1650,
63,
1001,
14,
3596,
531,
199,
199,
5592,
63,
3401,
275,
9487,
14564,
63,
765,
9,
83,
4805,
435,
971,
490,
9487,
6493,
9,
83,
4805,
435,
971,
490,
9487,
1365,
63,
3922,
9,
83,
13,
2840,
1375,
63,
3922,
9,
83,
4805,
435,
971,
490,
9487,
954,
1927,
9,
83,
4805,
199,
199,
396,
63,
493,
63,
515,
63,
3401,
275,
9487,
1650,
63,
354,
9,
83,
4805,
435,
7267,
63,
3401,
435,
971,
586,
9487,
354,
9,
83,
31706,
264,
6874,
9,
83,
31706,
1365,
63,
3922,
9,
83,
14,
1360,
7,
421,
199,
318,
664,
63,
1160,
8,
4846,
304,
272,
543,
1551,
8,
736,
14,
515,
14,
904,
8,
1160,
63,
3619,
12,
9593,
430,
465,
289,
26,
267,
372,
289,
14,
739,
342,
421,
199,
318,
1586,
63,
16621,
63,
604,
8,
3997,
12,
1004,
63,
1955,
304,
523,
4090,
14,
5507,
8,
16,
9,
523,
367,
284,
12,
1004,
315,
3874,
8,
3997,
304,
272,
340,
334,
73,
435,
413,
9,
508,
1004,
63,
1955,
26,
489,
372,
1004,
421,
199,
318,
2248,
63,
1650,
63,
1001,
837,
272,
295,
63,
705,
63,
1985,
275,
295,
14,
2014,
360,
604,
7287,
16,
13,
25,
11896,
2763,
7287,
16,
13,
25,
2807,
5942,
272,
543,
1551,
8,
1650,
63,
1501,
9,
465,
289,
26,
267,
862,
26,
881,
3158,
63,
1001,
275,
2022,
14,
912,
8,
70,
9,
267,
871,
1722,
12,
444,
26,
881,
870,
444,
14,
1188,
881,
1336,
275,
295,
63,
705,
63,
1985,
14,
1733,
8,
476,
14,
1188,
9,
881,
340,
1336,
26,
288,
1004,
63,
1955,
12,
2763,
275,
1109,
8,
1431,
14,
923,
8,
17,
1826,
1109,
8,
1431,
14,
923,
8,
18,
430,
288,
870,
1586,
63,
16621,
63,
604,
8,
70,
12,
1004,
63,
1955,
680,
6735,
342,
288,
870,
298,
298,
627,
334,
2301,
446,
413,
9,
435,
18129,
2,
8592,
984,
14,
2224,
8,
17,
9,
398,
372,
3158,
63,
1001,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
bask/or-tools
|
examples/python/sendmore.py
|
32
|
1840
|
# Copyright 2010-2014 Google
# 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.
"""Send + more = money.
In this model, we try to solve the following cryptarythm
SEND + MORE = MONEY
Each letter corresponds to one figure and all letters have different values.
"""
from google.apputils import app
import gflags
from ortools.constraint_solver import pywrapcp
FLAGS = gflags.FLAGS
def main(unused_argv):
# Create the solver.
solver = pywrapcp.Solver('SEND + MORE = MONEY')
digits = range(0, 10)
s = solver.IntVar(digits, 's')
e = solver.IntVar(digits, 'e')
n = solver.IntVar(digits, 'n')
d = solver.IntVar(digits, 'd')
m = solver.IntVar(digits, 'm')
o = solver.IntVar(digits, 'o')
r = solver.IntVar(digits, 'r')
y = solver.IntVar(digits, 'y')
letters = [s, e, n, d, m, o, r, y]
solver.Add(
1000 * s + 100 * e + 10 * n + d +
1000 * m + 100 * o + 10 * r + e ==
10000 * m + 1000 * o + 100 * n + 10 * e + y)
# pylint: disable=g-explicit-bool-comparison
solver.Add(s != 0)
solver.Add(m != 0)
solver.Add(solver.AllDifferent(letters))
solver.NewSearch(solver.Phase(letters,
solver.INT_VAR_DEFAULT,
solver.INT_VALUE_DEFAULT))
solver.NextSolution()
print letters
solver.EndSearch()
if __name__ == '__main__':
app.run()
|
apache-2.0
|
[
3,
1898,
7129,
13,
7280,
4475,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
6795,
435,
1655,
275,
333,
13234,
14,
199,
199,
607,
642,
1402,
12,
781,
862,
370,
14241,
314,
2569,
21570,
695,
273,
77,
199,
20469,
435,
603,
5788,
275,
603,
4817,
57,
199,
22321,
8082,
13718,
370,
1373,
9658,
436,
1006,
14435,
1172,
3365,
1338,
14,
199,
624,
4388,
199,
504,
6233,
14,
571,
1208,
492,
1145,
199,
646,
486,
2469,
199,
504,
221,
361,
5998,
14,
5631,
63,
11263,
492,
1134,
3823,
1850,
199,
199,
4831,
275,
486,
2469,
14,
4831,
421,
199,
318,
2446,
8,
8618,
63,
3020,
304,
523,
327,
2790,
314,
10196,
14,
523,
10196,
275,
1134,
3823,
1850,
14,
24755,
360,
20469,
435,
603,
5788,
275,
603,
4817,
57,
358,
819,
7576,
275,
1425,
8,
16,
12,
1616,
9,
523,
308,
275,
10196,
14,
3241,
5894,
8,
7022,
12,
283,
83,
358,
523,
325,
275,
10196,
14,
3241,
5894,
8,
7022,
12,
283,
69,
358,
523,
302,
275,
10196,
14,
3241,
5894,
8,
7022,
12,
283,
78,
358,
523,
366,
275,
10196,
14,
3241,
5894,
8,
7022,
12,
283,
68,
358,
523,
333,
275,
10196,
14,
3241,
5894,
8,
7022,
12,
283,
77,
358,
523,
312,
275,
10196,
14,
3241,
5894,
8,
7022,
12,
283,
79,
358,
523,
519,
275,
10196,
14,
3241,
5894,
8,
7022,
12,
283,
82,
358,
523,
612,
275,
10196,
14,
3241,
5894,
8,
7022,
12,
283,
89,
358,
819,
14435,
275,
359,
83,
12,
325,
12,
302,
12,
366,
12,
333,
12,
312,
12,
519,
12,
612,
61,
819,
10196,
14,
1123,
8,
489,
5198,
627,
308,
435,
2948,
627,
325,
435,
1616,
627,
302,
435,
366,
435,
489,
5198,
627,
333,
435,
2948,
627,
312,
435,
1616,
627,
519,
435,
325,
508,
489,
11630,
627,
333,
435,
5198,
627,
312,
435,
2948,
627,
302,
435,
1616,
627,
325,
435,
612,
9,
819,
327,
4287,
26,
3507,
29,
71,
13,
10306,
13,
2245,
13,
8547,
523,
10196,
14,
1123,
8,
83,
1137,
378,
9,
523,
10196,
14,
1123,
8,
77,
1137,
378,
9,
819,
10196,
14,
1123,
8,
11263,
14,
2422,
31409,
8,
16415,
430,
819,
10196,
14,
4665,
5278,
8,
11263,
14,
10521,
8,
16415,
12,
1816,
10196,
14,
2919,
63,
5568,
63,
3472,
12,
1816,
10196,
14,
2919,
63,
7041,
63,
3472,
430,
523,
10196,
14,
5765,
24277,
342,
523,
870,
14435,
523,
10196,
14,
3005,
5278,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
1145,
14,
1065,
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
] |
[
1898,
7129,
13,
7280,
4475,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
6795,
435,
1655,
275,
333,
13234,
14,
199,
199,
607,
642,
1402,
12,
781,
862,
370,
14241,
314,
2569,
21570,
695,
273,
77,
199,
20469,
435,
603,
5788,
275,
603,
4817,
57,
199,
22321,
8082,
13718,
370,
1373,
9658,
436,
1006,
14435,
1172,
3365,
1338,
14,
199,
624,
4388,
199,
504,
6233,
14,
571,
1208,
492,
1145,
199,
646,
486,
2469,
199,
504,
221,
361,
5998,
14,
5631,
63,
11263,
492,
1134,
3823,
1850,
199,
199,
4831,
275,
486,
2469,
14,
4831,
421,
199,
318,
2446,
8,
8618,
63,
3020,
304,
523,
327,
2790,
314,
10196,
14,
523,
10196,
275,
1134,
3823,
1850,
14,
24755,
360,
20469,
435,
603,
5788,
275,
603,
4817,
57,
358,
819,
7576,
275,
1425,
8,
16,
12,
1616,
9,
523,
308,
275,
10196,
14,
3241,
5894,
8,
7022,
12,
283,
83,
358,
523,
325,
275,
10196,
14,
3241,
5894,
8,
7022,
12,
283,
69,
358,
523,
302,
275,
10196,
14,
3241,
5894,
8,
7022,
12,
283,
78,
358,
523,
366,
275,
10196,
14,
3241,
5894,
8,
7022,
12,
283,
68,
358,
523,
333,
275,
10196,
14,
3241,
5894,
8,
7022,
12,
283,
77,
358,
523,
312,
275,
10196,
14,
3241,
5894,
8,
7022,
12,
283,
79,
358,
523,
519,
275,
10196,
14,
3241,
5894,
8,
7022,
12,
283,
82,
358,
523,
612,
275,
10196,
14,
3241,
5894,
8,
7022,
12,
283,
89,
358,
819,
14435,
275,
359,
83,
12,
325,
12,
302,
12,
366,
12,
333,
12,
312,
12,
519,
12,
612,
61,
819,
10196,
14,
1123,
8,
489,
5198,
627,
308,
435,
2948,
627,
325,
435,
1616,
627,
302,
435,
366,
435,
489,
5198,
627,
333,
435,
2948,
627,
312,
435,
1616,
627,
519,
435,
325,
508,
489,
11630,
627,
333,
435,
5198,
627,
312,
435,
2948,
627,
302,
435,
1616,
627,
325,
435,
612,
9,
819,
327,
4287,
26,
3507,
29,
71,
13,
10306,
13,
2245,
13,
8547,
523,
10196,
14,
1123,
8,
83,
1137,
378,
9,
523,
10196,
14,
1123,
8,
77,
1137,
378,
9,
819,
10196,
14,
1123,
8,
11263,
14,
2422,
31409,
8,
16415,
430,
819,
10196,
14,
4665,
5278,
8,
11263,
14,
10521,
8,
16415,
12,
1816,
10196,
14,
2919,
63,
5568,
63,
3472,
12,
1816,
10196,
14,
2919,
63,
7041,
63,
3472,
430,
523,
10196,
14,
5765,
24277,
342,
523,
870,
14435,
523,
10196,
14,
3005,
5278,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
1145,
14,
1065,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
yatinkumbhare/openstack-nova
|
nova/pci/manager.py
|
26
|
11491
|
# Copyright (c) 2013 Intel, Inc.
# Copyright (c) 2013 OpenStack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import collections
from oslo_log import log as logging
from nova.compute import task_states
from nova.compute import vm_states
from nova import exception
from nova.i18n import _LW
from nova import objects
from nova.pci import device
from nova.pci import stats
from nova.virt import hardware
LOG = logging.getLogger(__name__)
class PciDevTracker(object):
"""Manage pci devices in a compute node.
This class fetches pci passthrough information from hypervisor
and trackes the usage of these devices.
It's called by compute node resource tracker to allocate and free
devices to/from instances, and to update the available pci passthrough
devices information from hypervisor periodically. The devices
information is updated to DB when devices information is changed.
"""
def __init__(self, context, node_id=None):
"""Create a pci device tracker.
If a node_id is passed in, it will fetch pci devices information
from database, otherwise, it will create an empty devices list
and the resource tracker will update the node_id information later.
"""
super(PciDevTracker, self).__init__()
self.stale = {}
self.node_id = node_id
self.stats = stats.PciDeviceStats()
if node_id:
self.pci_devs = list(
objects.PciDeviceList.get_by_compute_node(context, node_id))
else:
self.pci_devs = []
self._initial_instance_usage()
def _initial_instance_usage(self):
self.allocations = collections.defaultdict(list)
self.claims = collections.defaultdict(list)
for dev in self.pci_devs:
uuid = dev['instance_uuid']
if dev['status'] == 'claimed':
self.claims[uuid].append(dev)
elif dev['status'] == 'allocated':
self.allocations[uuid].append(dev)
elif dev['status'] == 'available':
self.stats.add_device(dev)
@property
def all_devs(self):
return self.pci_devs
def save(self, context):
for dev in self.pci_devs:
if dev.obj_what_changed():
with dev.obj_alternate_context(context):
dev.save()
self.pci_devs = [dev for dev in self.pci_devs
if dev['status'] != 'deleted']
@property
def pci_stats(self):
return self.stats
def set_hvdevs(self, devices):
"""Sync the pci device tracker with hypervisor information.
To support pci device hot plug, we sync with the hypervisor
periodically, fetching all devices information from hypervisor,
update the tracker and sync the DB information.
Devices should not be hot-plugged when assigned to a guest,
but possibly the hypervisor has no such guarantee. The best
we can do is to give a warning if a device is changed
or removed while assigned.
"""
exist_addrs = set([dev['address'] for dev in self.pci_devs])
new_addrs = set([dev['address'] for dev in devices])
for existed in self.pci_devs:
if existed['address'] in exist_addrs - new_addrs:
try:
device.remove(existed)
except exception.PciDeviceInvalidStatus as e:
LOG.warning(_LW("Trying to remove device with %(status)s "
"ownership %(instance_uuid)s because of "
"%(pci_exception)s"),
{'status': existed.status,
'instance_uuid': existed.instance_uuid,
'pci_exception': e.format_message()})
# Note(yjiang5): remove the device by force so that
# db entry is cleaned in next sync.
existed.status = 'removed'
else:
# Note(yjiang5): no need to update stats if an assigned
# device is hot removed.
self.stats.remove_device(existed)
else:
new_value = next((dev for dev in devices if
dev['address'] == existed['address']))
new_value['compute_node_id'] = self.node_id
if existed['status'] in ('claimed', 'allocated'):
# Pci properties may change while assigned because of
# hotplug or config changes. Although normally this should
# not happen.
# As the devices have been assigned to a instance, we defer
# the change till the instance is destroyed. We will
# not sync the new properties with database before that.
# TODO(yjiang5): Not sure if this is a right policy, but
# at least it avoids some confusion and, if needed,
# we can add more action like killing the instance
# by force in future.
self.stale[new_value['address']] = new_value
else:
existed.update_device(new_value)
for dev in [dev for dev in devices if
dev['address'] in new_addrs - exist_addrs]:
dev['compute_node_id'] = self.node_id
# NOTE(danms): These devices are created with no context
dev_obj = objects.PciDevice.create(dev)
self.pci_devs.append(dev_obj)
self.stats.add_device(dev_obj)
def _claim_instance(self, context, instance, prefix=''):
pci_requests = objects.InstancePCIRequests.get_by_instance(
context, instance)
if not pci_requests.requests:
return None
instance_numa_topology = hardware.instance_topology_from_instance(
instance)
instance_cells = None
if instance_numa_topology:
instance_cells = instance_numa_topology.cells
devs = self.stats.consume_requests(pci_requests.requests,
instance_cells)
if not devs:
raise exception.PciDeviceRequestFailed(pci_requests)
for dev in devs:
device.claim(dev, instance)
if instance_numa_topology and any(
dev.numa_node is None for dev in devs):
LOG.warning(_LW("Assigning a pci device without numa affinity to"
"instance %(instance)s which has numa topology"),
{'instance': instance['uuid']})
return devs
def _allocate_instance(self, instance, devs):
for dev in devs:
device.allocate(dev, instance)
def _free_device(self, dev, instance=None):
device.free(dev, instance)
stale = self.stale.pop(dev['address'], None)
if stale:
dev.update_device(stale)
self.stats.add_device(dev)
def _free_instance(self, instance):
# Note(yjiang5): When a instance is resized, the devices in the
# destination node are claimed to the instance in prep_resize stage.
# However, the instance contains only allocated devices
# information, not the claimed one. So we can't use
# instance['pci_devices'] to check the devices to be freed.
for dev in self.pci_devs:
if (dev['status'] in ('claimed', 'allocated') and
dev['instance_uuid'] == instance['uuid']):
self._free_device(dev)
def update_pci_for_instance(self, context, instance):
"""Update instance's pci usage information.
The caller should hold the COMPUTE_RESOURCE_SEMAPHORE lock
"""
uuid = instance['uuid']
vm_state = instance['vm_state']
task_state = instance['task_state']
if vm_state == vm_states.DELETED:
if self.allocations.pop(uuid, None):
self._free_instance(instance)
elif self.claims.pop(uuid, None):
self._free_instance(instance)
elif task_state == task_states.RESIZE_MIGRATED:
devs = self.allocations.pop(uuid, None)
if devs:
self._free_instance(instance)
elif task_state == task_states.RESIZE_FINISH:
devs = self.claims.pop(uuid, None)
if devs:
self._allocate_instance(instance, devs)
self.allocations[uuid] = devs
elif (uuid not in self.allocations and
uuid not in self.claims):
devs = self._claim_instance(context, instance)
if devs:
self._allocate_instance(instance, devs)
self.allocations[uuid] = devs
def update_pci_for_migration(self, context, instance, sign=1):
"""Update instance's pci usage information when it is migrated.
The caller should hold the COMPUTE_RESOURCE_SEMAPHORE lock.
:param sign: claim devices for instance when sign is 1, remove
the claims when sign is -1
"""
uuid = instance['uuid']
if sign == 1 and uuid not in self.claims:
devs = self._claim_instance(context, instance, 'new_')
if devs:
self.claims[uuid] = devs
if sign == -1 and uuid in self.claims:
self._free_instance(instance)
def clean_usage(self, instances, migrations, orphans):
"""Remove all usages for instances not passed in the parameter.
The caller should hold the COMPUTE_RESOURCE_SEMAPHORE lock
"""
existed = set(inst['uuid'] for inst in instances)
existed |= set(mig['instance_uuid'] for mig in migrations)
existed |= set(inst['uuid'] for inst in orphans)
for uuid in self.claims.keys():
if uuid not in existed:
devs = self.claims.pop(uuid, [])
for dev in devs:
self._free_device(dev)
for uuid in self.allocations.keys():
if uuid not in existed:
devs = self.allocations.pop(uuid, [])
for dev in devs:
self._free_device(dev)
def get_instance_pci_devs(inst, request_id=None):
"""Get the devices allocated to one or all requests for an instance.
- For generic PCI request, the request id is None.
- For sr-iov networking, the request id is a valid uuid
- There are a couple of cases where all the PCI devices allocated to an
instance need to be returned. Refer to libvirt driver that handles
soft_reboot and hard_boot of 'xen' instances.
"""
pci_devices = inst.pci_devices
return [device for device in pci_devices if
device.request_id == request_id or request_id == 'all']
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6171,
20619,
12,
3277,
14,
199,
3,
1898,
334,
67,
9,
6171,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
5055,
199,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
199,
504,
5913,
14,
3357,
492,
2120,
63,
4981,
199,
504,
5913,
14,
3357,
492,
4169,
63,
4981,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
20145,
199,
504,
5913,
492,
2251,
199,
504,
5913,
14,
12024,
492,
2243,
199,
504,
5913,
14,
12024,
492,
5020,
199,
504,
5913,
14,
4549,
492,
14991,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
510,
559,
12680,
13652,
8,
785,
304,
272,
408,
20588,
19950,
7256,
315,
282,
4526,
1031,
14,
339,
961,
1021,
28053,
19950,
19099,
20887,
2556,
687,
21724,
272,
436,
4426,
397,
314,
4503,
402,
3520,
7256,
14,
339,
2779,
1159,
2797,
701,
4526,
1031,
2073,
15271,
370,
18310,
436,
2867,
272,
7256,
370,
15,
504,
4454,
12,
436,
370,
1678,
314,
2808,
19950,
19099,
20887,
272,
7256,
2556,
687,
21724,
18745,
1183,
14,
710,
7256,
272,
2556,
365,
4588,
370,
6249,
1380,
7256,
2556,
365,
2896,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1067,
12,
1031,
63,
344,
29,
403,
304,
267,
408,
2499,
282,
19950,
2243,
15271,
14,
398,
982,
282,
1031,
63,
344,
365,
3032,
315,
12,
652,
911,
5267,
19950,
7256,
2556,
267,
687,
3050,
12,
4257,
12,
652,
911,
1218,
376,
2701,
7256,
769,
267,
436,
314,
2073,
15271,
911,
1678,
314,
1031,
63,
344,
2556,
2945,
14,
267,
408,
398,
1613,
8,
23246,
12680,
13652,
12,
291,
2843,
826,
4533,
267,
291,
14,
20102,
275,
1052,
267,
291,
14,
932,
63,
344,
275,
1031,
63,
344,
267,
291,
14,
3200,
275,
5020,
14,
23246,
2510,
8257,
342,
267,
340,
1031,
63,
344,
26,
288,
291,
14,
12024,
63,
18804,
275,
769,
8,
355,
2251,
14,
23246,
2510,
1296,
14,
362,
63,
991,
63,
3357,
63,
932,
8,
1100,
12,
1031,
63,
344,
430,
267,
587,
26,
288,
291,
14,
12024,
63,
18804,
275,
942,
267,
291,
423,
2747,
63,
842,
63,
3807,
342,
339,
347,
485,
2747,
63,
842,
63,
3807,
8,
277,
304,
267,
291,
14,
279,
8022,
275,
5055,
14,
21501,
8,
513,
9,
267,
291,
14,
3995,
11171,
275,
5055,
14,
21501,
8,
513,
9,
267,
367,
4866,
315,
291,
14,
12024,
63,
18804,
26,
288,
5377,
275,
4866,
459,
842,
63,
2580,
418,
288,
340,
4866,
459,
1205,
418,
508,
283,
31563,
356,
355,
291,
14,
3995,
11171,
59,
2580,
1055,
740,
8,
2374,
9,
288,
916,
4866,
459,
1205,
418,
508,
283,
19570,
356,
355,
291,
14,
279,
8022,
59,
2580,
1055,
740,
8,
2374,
9,
288,
916,
4866,
459,
1205,
418,
508,
283,
4561,
356,
355,
291,
14,
3200,
14,
525,
63,
1782,
8,
2374,
9,
339,
768,
1829,
272,
347,
1006,
63,
18804,
8,
277,
304,
267,
372,
291,
14,
12024,
63,
18804,
339,
347,
3354,
8,
277,
12,
1067,
304,
267,
367,
4866,
315,
291,
14,
12024,
63,
18804,
26,
288,
340,
4866,
14,
1113,
63,
10058,
63,
2489,
837,
355,
543,
4866,
14,
1113,
63,
17170,
63,
1100,
8,
1100,
304,
490,
4866,
14,
2117,
342,
398,
291,
14,
12024,
63,
18804,
275,
359,
2374,
367,
4866,
315,
291,
14,
12024,
63,
18804,
586,
340,
4866,
459,
1205,
418,
1137,
283,
6062,
418,
339,
768,
1829,
272,
347,
19950,
63,
3200,
8,
277,
304,
267,
372,
291,
14,
3200,
339,
347,
663,
63,
22926,
18804,
8,
277,
12,
7256,
304,
267,
408,
10878,
314,
19950,
2243,
15271,
543,
21724,
2556,
14,
398,
4005,
2291,
19950,
2243,
18469,
14202,
12,
781,
7604,
543,
314,
21724,
267,
18745,
1183,
12,
21239,
1006,
7256,
2556,
687,
21724,
12,
267,
1678,
314,
15271,
436,
7604,
314,
6249,
2556,
14,
398,
12272,
83,
1077,
440,
506,
18469,
13,
13963,
3046,
1380,
7943,
370,
282,
13980,
12,
267,
1325,
12570,
314,
21724,
965,
949,
4066,
24197,
14,
710,
5526,
267,
781,
883,
886,
365,
370,
8120,
282,
5721,
340,
282,
2243,
365,
2896,
267,
503,
4829,
1830,
7943,
14,
267,
408,
398,
2187,
63,
18942,
275,
663,
779,
2374,
459,
1562,
418,
367,
4866,
315,
291,
14,
12024,
63,
18804,
566,
267,
892,
63,
18942,
275,
663,
779,
2374,
459,
1562,
418,
367,
4866,
315,
7256,
566,
398,
367,
30482,
315,
291,
14,
12024,
63,
18804,
26,
288,
340,
30482,
459,
1562,
418,
315,
2187,
63,
18942,
446,
892,
63,
18942,
26,
355,
862,
26,
490,
2243,
14,
2168,
8,
476,
4957,
9,
355,
871,
1919,
14,
23246,
2510,
3364,
3694,
465,
325,
26,
490,
5051,
14,
3764,
1547,
20145,
480,
27693,
370,
2813,
2243,
543,
2818,
1205,
9,
83,
298,
2511,
298,
22495,
2818,
842,
63,
2580,
9,
83,
2952,
402,
298,
2511,
11792,
12024,
63,
1971,
9,
83,
1288,
1816,
791,
1205,
356,
30482,
14,
1205,
12,
639,
283,
842,
63,
2580,
356,
30482,
14,
842,
63,
2580,
12,
639,
283,
12024,
63,
1971,
356,
325,
14,
908,
63,
1188,
22804,
490,
327,
3390,
8,
89,
15899,
21,
304,
2813,
314,
2243,
701,
3542,
880,
626,
490,
327,
1592,
2397,
365,
12364,
315,
2163,
7604,
14,
490,
30482,
14,
1205,
275,
283,
10649,
7,
355,
587,
26,
490,
327,
3390
] |
[
1898,
334,
67,
9,
6171,
20619,
12,
3277,
14,
199,
3,
1898,
334,
67,
9,
6171,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
5055,
199,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
199,
504,
5913,
14,
3357,
492,
2120,
63,
4981,
199,
504,
5913,
14,
3357,
492,
4169,
63,
4981,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
20145,
199,
504,
5913,
492,
2251,
199,
504,
5913,
14,
12024,
492,
2243,
199,
504,
5913,
14,
12024,
492,
5020,
199,
504,
5913,
14,
4549,
492,
14991,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
510,
559,
12680,
13652,
8,
785,
304,
272,
408,
20588,
19950,
7256,
315,
282,
4526,
1031,
14,
339,
961,
1021,
28053,
19950,
19099,
20887,
2556,
687,
21724,
272,
436,
4426,
397,
314,
4503,
402,
3520,
7256,
14,
339,
2779,
1159,
2797,
701,
4526,
1031,
2073,
15271,
370,
18310,
436,
2867,
272,
7256,
370,
15,
504,
4454,
12,
436,
370,
1678,
314,
2808,
19950,
19099,
20887,
272,
7256,
2556,
687,
21724,
18745,
1183,
14,
710,
7256,
272,
2556,
365,
4588,
370,
6249,
1380,
7256,
2556,
365,
2896,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1067,
12,
1031,
63,
344,
29,
403,
304,
267,
408,
2499,
282,
19950,
2243,
15271,
14,
398,
982,
282,
1031,
63,
344,
365,
3032,
315,
12,
652,
911,
5267,
19950,
7256,
2556,
267,
687,
3050,
12,
4257,
12,
652,
911,
1218,
376,
2701,
7256,
769,
267,
436,
314,
2073,
15271,
911,
1678,
314,
1031,
63,
344,
2556,
2945,
14,
267,
408,
398,
1613,
8,
23246,
12680,
13652,
12,
291,
2843,
826,
4533,
267,
291,
14,
20102,
275,
1052,
267,
291,
14,
932,
63,
344,
275,
1031,
63,
344,
267,
291,
14,
3200,
275,
5020,
14,
23246,
2510,
8257,
342,
267,
340,
1031,
63,
344,
26,
288,
291,
14,
12024,
63,
18804,
275,
769,
8,
355,
2251,
14,
23246,
2510,
1296,
14,
362,
63,
991,
63,
3357,
63,
932,
8,
1100,
12,
1031,
63,
344,
430,
267,
587,
26,
288,
291,
14,
12024,
63,
18804,
275,
942,
267,
291,
423,
2747,
63,
842,
63,
3807,
342,
339,
347,
485,
2747,
63,
842,
63,
3807,
8,
277,
304,
267,
291,
14,
279,
8022,
275,
5055,
14,
21501,
8,
513,
9,
267,
291,
14,
3995,
11171,
275,
5055,
14,
21501,
8,
513,
9,
267,
367,
4866,
315,
291,
14,
12024,
63,
18804,
26,
288,
5377,
275,
4866,
459,
842,
63,
2580,
418,
288,
340,
4866,
459,
1205,
418,
508,
283,
31563,
356,
355,
291,
14,
3995,
11171,
59,
2580,
1055,
740,
8,
2374,
9,
288,
916,
4866,
459,
1205,
418,
508,
283,
19570,
356,
355,
291,
14,
279,
8022,
59,
2580,
1055,
740,
8,
2374,
9,
288,
916,
4866,
459,
1205,
418,
508,
283,
4561,
356,
355,
291,
14,
3200,
14,
525,
63,
1782,
8,
2374,
9,
339,
768,
1829,
272,
347,
1006,
63,
18804,
8,
277,
304,
267,
372,
291,
14,
12024,
63,
18804,
339,
347,
3354,
8,
277,
12,
1067,
304,
267,
367,
4866,
315,
291,
14,
12024,
63,
18804,
26,
288,
340,
4866,
14,
1113,
63,
10058,
63,
2489,
837,
355,
543,
4866,
14,
1113,
63,
17170,
63,
1100,
8,
1100,
304,
490,
4866,
14,
2117,
342,
398,
291,
14,
12024,
63,
18804,
275,
359,
2374,
367,
4866,
315,
291,
14,
12024,
63,
18804,
586,
340,
4866,
459,
1205,
418,
1137,
283,
6062,
418,
339,
768,
1829,
272,
347,
19950,
63,
3200,
8,
277,
304,
267,
372,
291,
14,
3200,
339,
347,
663,
63,
22926,
18804,
8,
277,
12,
7256,
304,
267,
408,
10878,
314,
19950,
2243,
15271,
543,
21724,
2556,
14,
398,
4005,
2291,
19950,
2243,
18469,
14202,
12,
781,
7604,
543,
314,
21724,
267,
18745,
1183,
12,
21239,
1006,
7256,
2556,
687,
21724,
12,
267,
1678,
314,
15271,
436,
7604,
314,
6249,
2556,
14,
398,
12272,
83,
1077,
440,
506,
18469,
13,
13963,
3046,
1380,
7943,
370,
282,
13980,
12,
267,
1325,
12570,
314,
21724,
965,
949,
4066,
24197,
14,
710,
5526,
267,
781,
883,
886,
365,
370,
8120,
282,
5721,
340,
282,
2243,
365,
2896,
267,
503,
4829,
1830,
7943,
14,
267,
408,
398,
2187,
63,
18942,
275,
663,
779,
2374,
459,
1562,
418,
367,
4866,
315,
291,
14,
12024,
63,
18804,
566,
267,
892,
63,
18942,
275,
663,
779,
2374,
459,
1562,
418,
367,
4866,
315,
7256,
566,
398,
367,
30482,
315,
291,
14,
12024,
63,
18804,
26,
288,
340,
30482,
459,
1562,
418,
315,
2187,
63,
18942,
446,
892,
63,
18942,
26,
355,
862,
26,
490,
2243,
14,
2168,
8,
476,
4957,
9,
355,
871,
1919,
14,
23246,
2510,
3364,
3694,
465,
325,
26,
490,
5051,
14,
3764,
1547,
20145,
480,
27693,
370,
2813,
2243,
543,
2818,
1205,
9,
83,
298,
2511,
298,
22495,
2818,
842,
63,
2580,
9,
83,
2952,
402,
298,
2511,
11792,
12024,
63,
1971,
9,
83,
1288,
1816,
791,
1205,
356,
30482,
14,
1205,
12,
639,
283,
842,
63,
2580,
356,
30482,
14,
842,
63,
2580,
12,
639,
283,
12024,
63,
1971,
356,
325,
14,
908,
63,
1188,
22804,
490,
327,
3390,
8,
89,
15899,
21,
304,
2813,
314,
2243,
701,
3542,
880,
626,
490,
327,
1592,
2397,
365,
12364,
315,
2163,
7604,
14,
490,
30482,
14,
1205,
275,
283,
10649,
7,
355,
587,
26,
490,
327,
3390,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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ission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
import os
import pandas as pd
import logging
from functools import partial
from zeex.core.compat import QtGui, QtCore
from zeex.core.models.actions import FileViewModel
from zeex.core.ctrls.dataframe import DataFrameModelManager
from zeex.core.ui.actions.merge_purge_ui import Ui_MergePurgeDialog
from zeex.core.utility.collection import DictConfig, SettingsINI
from zeex.core.utility.pandatools import gather_frame_fields
from zeex.core.utility.widgets import create_standard_item_model
from zeex.core.views.basic.map_grid import MapGridDialog
from zeex.core.views.basic.push_grid import PushGridHandler
from zeex.core.ctrls.dataframe import DataFrameModel
class MergePurgeDialog(QtGui.QDialog, Ui_MergePurgeDialog):
"""
This dialog allows a user to do large updates on a given source DataFrameModel.
- Merging other file(s) with the source based on common keys/fields
- Purging records from the source using other file(s) based on common keys/fields
- Sorting the DataFrame by multiple columns/ascending/descending
- Deduplicating the DataFrame based on common keys/fields
Settings can exported to a config.ini file and re-imported at a later time.
"""
signalMergeFileOpened = QtCore.Signal(str) # file path
signalSFileOpened = QtCore.Signal(str) # file path
signalSourcePathSet = QtCore.Signal(str) #file path
signalExecuted = QtCore.Signal(str, str, str) # source_path, dest_path, report_path
def __init__(self, df_manager: DataFrameModelManager, parent=None, source_model=None):
"""
:param df_manager: (DataFrameModelManager)
This will be used to handle reading/updating of DataFrameModels used
in the operation.
:param parent: (QMainWindow)
:param source_model: (DataFrameModel)
An optional source DataFrameModel
"""
self.df_manager = df_manager
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
self.source_model = source_model
self._merge_view_model = FileViewModel()
self._suppress_view_model = FileViewModel()
self._purge_files = {}
self._merge_files = {}
self._field_map_grids = {}
self._field_map_data = {}
self.sortAscHandler = None
self.sortOnHandler = None
self.dedupeOnHandler = None
self.uniqueFieldsHandler = None
self.gatherFieldsHandler = None
self.configure()
if self.source_model is not None:
self.set_source_model(source_model, configure=True)
def configure(self, source_path=None, dest_path=None):
"""
Connects main buttons and actions.
:param source_path: (str, default None)
If this is None there must be a valid path already in the sourcePathLineEdit or an AssertionError raises.
:param dest_path: (str, default None)
Optional custom destination path to be added to the destPathLineEdit.
:return: None
"""
if source_path is None:
source_path = self.sourcePathLineEdit.text()
if os.path.isfile(source_path):
self.set_line_edit_paths(source_path, dest_path=dest_path)
if self.sortAscHandler is None:
self.set_handler_sort_asc()
source_func = partial(self.open_file, model_signal=self.signalSourcePathSet)
self.signalSourcePathSet.connect(self.set_source_model_from_browse)
self.btnBrowseSourcePath.clicked.connect(source_func)
self.btnBrowseDestPath.clicked.connect(self.set_dest_path_from_browse)
self.signalMergeFileOpened.connect(self.add_merge_file)
merge_file_func = partial(self.open_file, model_signal=self.signalMergeFileOpened)
self.btnAddMergeFile.clicked.connect(merge_file_func)
self.btnBrowseMergeFile.clicked.connect(merge_file_func)
self.btnDeleteMergeFile.clicked.connect(partial(self.remove_file, self.mergeFileTable))
self.btnEditMergeFile.clicked.connect(partial(self.open_edit_file_window, self.mergeFileTable, self._merge_files))
self.mergeFileTable.setModel(self._merge_view_model)
self.signalSFileOpened.connect(self.add_purge_file)
sfile_func = partial(self.open_file, model_signal=self.signalSFileOpened)
self.btnEditSFile.clicked.connect(partial(self.open_edit_file_window, self.sFileTable, self._purge_files))
self.btnDeleteSFile.clicked.connect(partial(self.remove_file, self.sFileTable))
self.btnAddSFile.clicked.connect(sfile_func)
self.btnBrowseSFile.clicked.connect(sfile_func)
self.sFileTable.setModel(self._suppress_view_model)
self.btnMapSFields.clicked.connect(partial(self.open_field_map, self.sFileTable, self._purge_files))
self.btnMapMergeFields.clicked.connect(partial(self.open_field_map, self.mergeFileTable, self._merge_files))
self.btnExecute.clicked.connect(self.execute)
self.btnExportTemplate.clicked.connect(self.export_settings)
self.btnImportTemplate.clicked.connect(self.import_settings)
self.btnReset.clicked.connect(self.reset)
def set_source_model_from_browse(self, filepath):
self.set_line_edit_paths(filepath, dest_path=False)
self.set_source_model(configure=True)
def set_dest_path_from_browse(self, filepath=None):
if filepath is None:
try:
dirname = os.path.dirname(self.df_manager.last_path_read)
except:
dirname = ''
filepath = QtGui.QFileDialog.getOpenFileName(self, dir=dirname)[0]
self.destPathLineEdit.setText(filepath)
def set_source_model(self, model=None, configure=True):
"""
Sets the source DataFrameModel for the Dialog.
:param model: (DataFrameModel)
The DataFrameModel to be set.
:param configure:
True re-configures file path line edits and the listviews.
:return:
"""
if not hasattr(model, 'dataFrame'):
if model is None:
model = self.sourcePathLineEdit.text()
if isinstance(model, str) and os.path.exists(model):
model = self.df_manager.read_file(model)
else:
raise Exception("model parameter must be a filepath or a qtpandas.models.DataFrameModel")
if self.source_model is not None:
models_different = model.filePath != self.source_model.filePath
if models_different:
try:
self.source_model.dataFrameChanged.disconnect(self.sync)
except RuntimeError:
pass
else:
models_different = True
if models_different:
self.source_model = model
self.source_model.dataFrameChanged.connect(self.sync)
if configure:
self.sync()
def sync(self):
df = self.source_model.dataFrame()
cols = df.columns.tolist()
if self.dedupeOnHandler is None or self.uniqueFieldsHandler is None:
self.set_push_grid_handlers()
else:
self.dedupeOnHandler.set_model_from_list(cols)
self.gatherFieldsHandler.set_model_from_list(cols)
self.sortOnHandler.set_model_from_list(cols)
self.uniqueFieldsHandler.set_model_from_list(cols)
self.set_primary_key_combo_box()
self.set_line_edit_paths(source_path=self.source_model.filePath)
def set_line_edit_paths(self, source_path=None, dest_path=None):
"""
Sets the source/destination line edits in the Dialog.
:param source_path: (str, default None)
An optional valid filepath for the source DataFrameModel.
If None, :param dest_path cannot be None.
:param dest_path: (str, default None)
An optional destination path. One will be created automatically
if None is given.
False will prevent the destination path from being set at all.
:return: None
"""
assert any([dest_path, source_path]), "source_path or dest_path must be set."
if dest_path is None:
dirname = os.path.dirname(source_path)
base, ext = os.path.splitext(os.path.basename(source_path))
dest_path = os.path.join(dirname, base + "_merged" + ext)
if source_path:
self.sourcePathLineEdit.setText(source_path)
if dest_path:
self.destPathLineEdit.setText(dest_path)
def set_push_grid_handlers(self, column_model=None, sorton_model=None, sortasc_model=None,
dedupe_model=None, gather_model=None, unique_model=None):
"""
Sets all default push grid handlers for the dialog.
:param column_model: (QStandardItemModel, default None)
:param sorton_model: ((QStandardItemModel,list) default None)
:param sortasc_model: ((QStandardItemModel,list) default None)
:param dedupe_model: ((QStandardItemModel,list) default None)
:return:
"""
if column_model is None:
column_model = self.get_source_columns_model()
self.set_handler_sort_on(column_model=None, default_model=sorton_model)
self.set_handler_sort_asc(default_model=sortasc_model)
self.set_handler_dedupe_on(column_model=None, default_model=dedupe_model)
self.set_handler_gather_fields(column_model=None, default_model=gather_model)
self.set_handler_unique_fields(column_model=None, default_model=unique_model)
def set_handler_sort_on(self, column_model=None, default_model=None):
if column_model is None:
column_model = self.get_source_columns_model()
self.sortOnHandler = PushGridHandler(left_model=column_model, left_view=self.sortOnLeftView,
left_button=self.sortOnLeftButton,
left_delete=True, right_model=default_model,
right_view=self.sortOnRightView,
right_button=self.sortOnRightButton)
def set_handler_sort_asc(self, default_model=None, overwrite=False):
if self.sortAscHandler is None or default_model is not None or overwrite:
sort_asc = QtGui.QStandardItemModel()
sort_asc.appendRow(QtGui.QStandardItem('True'))
sort_asc.appendRow(QtGui.QStandardItem('False'))
self.sortAscHandler = PushGridHandler(left_model=sort_asc, left_view=self.sortAscLeftView,
left_button=self.sortAscLeftButton,
left_delete=False, right_model=default_model,
right_view=self.sortAscRightView,
right_button=self.sortAscRightButton)
def set_handler_dedupe_on(self, column_model=None, default_model=None):
if column_model is None:
column_model = self.get_source_columns_model()
self.dedupeOnHandler = PushGridHandler(left_model=column_model, left_view=self.dedupeOnLeftView,
left_button=self.dedupeOnLeftButton,
left_delete=True, right_model=default_model,
right_view=self.dedupeOnRightView,
right_button=self.dedupeOnRightButton)
def set_handler_gather_fields(self, column_model=None, default_model=None):
if column_model is None:
column_model = self.get_source_columns_model()
self.gatherFieldsHandler = PushGridHandler(left_model=column_model,
left_view=self.gatherFieldsListViewLeft,
left_button=self.gatherFieldsButtonLeft,
left_delete=True, right_model=default_model,
right_view=self.gatherFieldsListViewRight,
right_button=self.gatherFieldsButtonRight)
def set_handler_unique_fields(self, column_model=None, default_model=None):
if column_model is None:
column_model = self.get_source_columns_model()
self.uniqueFieldsHandler = PushGridHandler(left_model=column_model,
left_view=self.uniqueFieldsListViewLeft,
left_button=self.uniqueFieldsPushButtonLeft,
left_delete=True, right_model=default_model,
right_view=self.uniqueFieldsListViewRight,
right_button=self.uniqueFieldsPushButtonRight)
def get_source_columns_model(self, raise_on_error=True) -> QtGui.QStandardItemModel:
"""
Quick way to get a QStandardItemModel form the DataFrameModel's columns.
:param raise_on_error: (bool, default True)
Raises an error if the source_model has not yet been set.
:return: (QtGui.QStandardItemModel)
"""
if self.source_model is None:
if raise_on_error:
raise Exception("Cannot get source_columns as source_model is None!")
else:
columns = []
else:
columns = self.source_model.dataFrame().columns.tolist()
return create_standard_item_model(columns)
def open_file(self, file_names: list=None, model_signal=None, allow_multi=True):
"""
Opens a Merge or Purge file (or really any file) and calls the
given model signal after registering the DataFrameModel with the DataFrameModelManager.
:param file_names: (list, default None)
An optional list of filenames to open.
The user must select filenames otherwise.
:param model_signal: (QtCore.Signal)
A signal to be called after successfully reading the DataFrameModel.
:param allow_multi: (bool, default True)
True allows multiple files to be read (and the signal called each time).
False allows only the first file to be read.
:return: None
You can call MergePurgeDialog.df_manager.get_frame(filename) to
retrieve a DataFrameModel.
"""
if file_names is None:
dirname = os.path.dirname(self.sourcePathLineEdit.text())
file_names = QtGui.QFileDialog.getOpenFileNames(parent=self,
dir=dirname)[0]
if isinstance(file_names, str):
file_names = list(file_names)
assert not isinstance(file_names, str) and hasattr(file_names, "__iter__"), "file_names is not list-like!"
if allow_multi is False:
file_names = list(file_names[0])
for f in file_names:
try:
if not isinstance(f, str) and hasattr(f, '__iter__'):
f = f[0]
if os.path.exists(f):
self.df_manager.read_file(f)
if model_signal is not None:
model_signal.emit(f)
logging.info("Emitted signal: {}".format(f))
except Exception as e:
logging.error(e)
@QtCore.Slot(str)
def add_merge_file(self, file_path):
"""
Adds a merge file to the merge view and
also updates the internal dictionary storing the filepath/model.
:param file_path: (str)
The file path to add.
:return: None
"""
model = self.df_manager.get_model(file_path)
model.enableEditing(True)
self._merge_files.update({file_path:model})
self._merge_view_model.append_df_model(model)
self.mergeFileTable.setColumnWidth(0, 500)
self._merge_view_model.setHorizontalHeaderLabels(['filepath', 'count'])
@QtCore.Slot(str)
def add_purge_file(self, file_path):
"""
Adds a purge file to the purge view and
also updates the internal dictionary storing the filepath/model.
:param file_path: (str)
The file path to add.
:return: None
"""
model = self.df_manager.get_model(file_path)
model.enableEditing(True)
self._purge_files.update({file_path:model})
self._suppress_view_model.append_df_model(model)
self.sFileTable.setColumnWidth(0, 500)
self._suppress_view_model.setHorizontalHeaderLabels(['filepath', 'count'])
def remove_file(self, view, indexes=None):
"""
Removes selected file(s) from the given view.
:param view: (QListView)
The view to drop the selected indexes on.
:param indexes: (list, default None)
A list of given indexes to drop.
Otherwise relies on selected indexes in the view.
:return: None
"""
if indexes is None:
indexes = [x.row() for x in view.selectedIndexes()]
model = view.model()
for idx in indexes:
model.takeRow(idx)
def open_field_map(self, view, models):
"""
Connects a MapGridDialog to help the user map field names that
are different between the source DataFrameModel and the
selected merge or suppression DataFrameModel.
:param view: (QtGui.QTableView)
The view that has a selected filepath
:param models: (dict)
The dictionary of {file_path:DataFrameModel} where
dataframe columns can be gathered from.
:return: None
"""
idx = view.selectedIndexes()[0]
view_model = view.model()
view_item = view_model.item(idx.row())
view_item_text = view_item.text()
try:
self._field_map_grids[view_item_text].show()
except KeyError:
dfmodel = models[view_item_text]
colmodel = dfmodel._dataFrame.columns.tolist()
if self.source_model is None:
self.set_source_model()
source_colmodel = self.source_model._dataFrame.columns.tolist()
fmap = MapGridDialog(parent=self)
fmap.load_combo_box(source_colmodel, left=True)
fmap.load_combo_box(colmodel, left=False)
fmap.setWindowTitle("Map Fields")
fmap.labelLeft.setText(os.path.basename(self.source_model.filePath))
fmap.labelRight.setText(os.path.basename(dfmodel.filePath))
fmap.signalNewMapping.connect(lambda x: self._field_map_data.update({dfmodel.filePath: x}))
self._field_map_grids[view_item_text] = fmap
self._field_map_grids[view_item_text].show()
def get_map_grid(self, file_path):
"""
Accessor to the MergePurgeDialog._field_map_grids dictionary.
Contains map grid dialogs.
:param file_path: (str)
The filepath related to the desired MapGridDialog.
:return: (MapGridDialog, None)
"""
return self._field_map_grids.get(file_path, None)
def open_edit_file_window(self, view, models):
"""
Connects a DataFrameModel selected in the view
to a FileTableWindow where the model can be edited.
:param view: (QtGui.QTableView)
The view that has a selected filepath
:param models: (dict)
The dictionary of {file_path:DataFrameModel}
to supply the FileTableWindow
:return: None
"""
try:
idx = view.selectedIndexes()[0]
except IndexError:
raise IndexError("No file selected to open.")
vmodel = view.model()
vitem = vmodel.item(idx.row())
model = models.get(vitem.text())
fp = model.filePath
wdw = self.df_manager.get_fileview_window(fp)
# Prevent wierdos from doing an endless loop of MergePurge windows.
# That would be pretty funny, though..
wdw.actionMergePurge.setVisible(False)
wdw.show()
def execute(self):
"""
Executes the merge_purge based upon the given settings.
:return: None
"""
if self.source_model is None:
self.set_source_model()
suppressed_results = {}
merged_results = {}
source_path = self.sourcePathLineEdit.text()
dest_path = self.destPathLineEdit.text()
source_df = self.source_model.dataFrame().copy()
source_df.loc[:, 'ORIG_IDXER'] = source_df.index
source_size = source_df.index.size
index_label = self.primaryKeyComboBox.currentText()
sort_on = self.sortOnHandler.get_model_list(left=False)
ascending = self.sortAscHandler.get_model_list(left=False)
dedupe_on = self.dedupeOnHandler.get_model_list(left=False)
gather_fields = self.gatherFieldsHandler.get_model_list(left=False)
overwrite_existing = self.gatherFieldsOverWriteCheckBox.isChecked()
# Make sure ascending/sort_on lists are equal.
while len(sort_on) < len(ascending):
ascending.append(False)
while len(sort_on) > len(ascending):
ascending.pop()
# Get all merge models and merge.
# Absorb all rows and columns
for file_path, merge_model in self._merge_files.items():
pre_size = source_df.index.size
other_df = merge_model.dataFrame()
if gather_fields:
assert index_label in other_df.columns, "DataFrameModel for {} missing column {}".format(
merge_model.filePath, index_label)
source_df = gather_frame_fields(source_df, other_df, index_label=index_label,
fields=gather_fields, copy_frames=True,
append_missing=True, overwrite=overwrite_existing)
else:
source_df = pd.concat([source_df, other_df])
merged_results.update({merge_model.filePath: source_df.index.size - pre_size})
# Get all suppression models and suppress.
for file_path, suppress_model in self._purge_files.items():
map_dict = self._field_map_data.get(file_path, {})
sframe = suppress_model.dataFrame().copy()
sframe.drop(['ORIG_IDXER'], axis=1, inplace=True, errors='ignore')
if map_dict:
# A mapping exists - rename the data and get the key_cols
key_cols = list(map_dict.values())
sframe.rename(columns=map_dict, inplace=True)
else:
# No mapping exists - Try to use the dedupe_on cols as key_cols
key_cols = dedupe_on.copy()
missing = [x for x in key_cols if x not in sframe.columns]
if missing:
raise KeyError("Suppression file {} must have a field mapping or \
have the dedupe column labels, it has neither!.".format(
suppress_model.filePath))
sframe = sframe.loc[:, key_cols].drop_duplicates(key_cols)
badframe = pd.merge(source_df, sframe, how='inner', left_on=key_cols, right_on=key_cols)
source_df = source_df.loc[~source_df.index.isin(badframe.loc[:, 'ORIG_IDXER'].tolist()), :]
suppressed_results.update({suppress_model.filePath: badframe.index.size})
# Sort the data
if sort_on and ascending:
source_df.sort_values(sort_on, ascending=ascending, inplace=True)
# Deduplicate the data.
if dedupe_on:
pre_size = source_df.index.size
source_df.drop_duplicates(dedupe_on, inplace=True)
dedupe_lost = pre_size - source_df.index.size
else:
dedupe_lost = 0
# Export the data - done!
source_df.drop(['ORIG_IDXER'], axis=1, inplace=True, errors='ignore')
source_df.to_csv(dest_path, index=False)
logging.info("Exported: {}".format(dest_path))
merge_string = "\n".join("Gained {} merging {}".format(v, k) for k, v in merged_results.items())
suppress_string = "\n".join("Lost {} suppressing {}".format(v, k) for k,v in suppressed_results.items())
report = """
Merge Purge Report
==================
Original Size: {}
Final Size: {}
Source Path: {}
Output Path: {}
Merge:
==================
{}
Purge:
==================
{}
Sort:
==================
SORT BY: {}
SORT ASCENDING: {}
Dedupe:
==================
DEDUPE ON: {}
RECORDS LOST: {}
""".format(source_size, source_df.index.size, source_path,
dest_path, merge_string, suppress_string,
sort_on, ascending, dedupe_on, dedupe_lost)
report_path = os.path.splitext(dest_path)[0] + "_report.txt"
with open(report_path, "w") as fh:
fh.write(report)
self.signalExecuted.emit(source_path, dest_path, report_path)
def get_settings(self, dc:DictConfig = None, section="MERGE_PURGE") -> DictConfig:
"""
Gathers the settings out of the Dialog and
returns a DictConfig object with updated settings.
:param dc (DictConfig, default None)
An optional DictConfig object, one is created if none is given.
:param section (str, default 'MERGE_PURGE')
An optional section name to apply settings to.
A pre-existing section with this name would be overwritten.
:return: (DictConfig)
An updated DictConfig object.
"""
if dc is None:
dc = DictConfig()
if dc.has_section(section):
dc.remove_section(section)
dc.add_section(section)
dc.set_safe(section, 'source_path', self.sourcePathLineEdit.text())
dc.set_safe(section, 'dest_path', self.destPathLineEdit.text())
dc.set_safe(section, 'primary_key', self.primaryKeyComboBox.currentText())
dc.set_safe(section, 'dedupe_on', self.dedupeOnHandler.get_model_list(left=False))
dc.set_safe(section, 'gather_fields', self.gatherFieldsHandler.get_model_list(left=False))
dc.set_safe(section, 'gather_fields_overwrite', self.gatherFieldsOverWriteCheckBox.isChecked())
dc.set_safe(section, 'sort_on', self.sortOnHandler.get_model_list(left=False))
dc.set_safe(section, 'sort_ascending', self.sortAscHandler.get_model_list(left=False))
dc.set_safe(section, 'unique_fields', self.uniqueFieldsHandler.get_model_list(left=False))
dc.set_safe(section, 'field_map_data', self._field_map_data)
dc.set_safe(section, 'merge_files', list(self._merge_files.keys()))
dc.set_safe(section, 'purge_files', list(self._purge_files.keys()))
return dc
def set_settings(self, dc:DictConfig, section="MERGE_PURGE"):
"""
Applies settings from a DictConfig object to the Dialog.
:param dc (DictConfig, default None)
The DictConfig object that contains the settings to be applied.
:param section (str, default 'MERGE_PURGE')
The section name to read settings from.
:return:
"""
source_path = dc.get(section, 'source_path', fallback=self.sourcePathLineEdit.text())
current_path = self.sourcePathLineEdit.text()
if source_path != current_path:
dfm = self.df_manager.read_file(source_path)
dest = dc.get(section, 'dest_path', fallback=None)
self.set_source_model(dfm, configure=False)
self.set_line_edit_paths(source_path, dest_path=dest)
self.primaryKeyComboBox.clear()
self.set_primary_key_combo_box()
key_id = self.primaryKeyComboBox.findText(dc.get(section, 'primary_key',
fallback=self.primaryKeyComboBox.currentText()))
dedupe_on = dc.get_safe(section, 'dedupe_on', fallback=None)
sort_on = dc.get_safe(section, 'sort_on', fallback=None)
gather_fields = dc.get_safe(section, 'gather_fields', fallback=None)
unique_fields = dc.get_safe(section, 'unique_fields', fallback=None)
gather_fields_overwrite = dc.getboolean(section, 'gather_fields_overwrite', fallback=False)
sort_ascending = dc.get_safe(section, 'sort_ascending', fallback=None)
merge_files = dc.get_safe(section, 'merge_files', fallback=[])
purge_files = dc.get_safe(section, 'purge_files', fallback=[])
field_map_data = dc.get_safe(section, 'field_map_data', fallback={})
self.primaryKeyComboBox.setCurrentIndex(key_id)
self.set_push_grid_handlers(column_model=None, sorton_model=sort_on, sortasc_model=sort_ascending,
dedupe_model=dedupe_on, gather_model=gather_fields, unique_model=unique_fields)
self.gatherFieldsOverWriteCheckBox.setChecked(gather_fields_overwrite)
self._field_map_data.update(field_map_data)
self.open_file(file_names=merge_files, model_signal=self.signalMergeFileOpened)
self.open_file(file_names=purge_files, model_signal=self.signalSFileOpened)
def reset(self):
"""
Resets ListViews/CheckBoxes.
The source/dest line edits are left alone
The suppression/merge files are also left alone.
:return: None
"""
self.set_push_grid_handlers()
self.set_handler_sort_asc(overwrite=True)
self.set_primary_key_combo_box(reset=True)
self.gatherFieldsOverWriteCheckBox.setChecked(False)
def set_primary_key_combo_box(self, default=None, reset=False):
"""
Sets the primary key combo box.
:param default: (str, default None)
An optional default field name to select.
:return:
"""
if default is None and reset is False:
current_model = self.primaryKeyComboBox.model()
if current_model:
default = self.primaryKeyComboBox.currentText()
combo_model = create_standard_item_model([''] + self.source_model.dataFrame().columns.tolist(),
editable=False, checkable=True)
self.primaryKeyComboBox.setModel(combo_model)
if default is not None:
self.primaryKeyComboBox.setCurrentIndex(self.primaryKeyComboBox.findText(default))
def import_settings(self, from_path=None):
"""
Imports settings to the Dialog from a file.
:param from_path: (str, default None)
None makes the user enter a file path.
:return:
"""
if from_path is None:
try:
dirname = os.path.dirname(self.sourcePathLineEdit.text())
except:
dirname = ''
from_path = QtGui.QFileDialog.getOpenFileName(self, dir=dirname)[0]
config = SettingsINI(filename=from_path)
self.set_settings(config)
def export_settings(self, to=None):
"""
Exports settings from the Dialog to a file.
:param to: (str, default None)
None makes the user enter a file path.
:return: None
"""
if to is None:
try:
dirname = os.path.dirname(self.sourcePathLineEdit.text())
except:
dirname = ''
to = QtGui.QFileDialog.getSaveFileName(self, dir=dirname)[0]
config = self.get_settings()
config.save_as(to, set_self=True)
|
mit
|
[
624,
199,
13965,
844,
199,
199,
7384,
334,
67,
9,
7800,
3107,
69,
415,
699,
4430,
199,
199,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
1618,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
262,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
475,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
16847,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
70,
13399,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
199,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
199,
16847,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
38,
3061,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
5580,
4149,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
2673,
2477,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
1877,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
26734,
14,
199,
624,
199,
199,
646,
747,
199,
646,
10634,
465,
6454,
199,
646,
2050,
199,
504,
9143,
492,
7417,
199,
504,
29986,
476,
14,
1018,
14,
5819,
492,
5928,
12,
10565,
199,
504,
29986,
476,
14,
1018,
14,
992,
14,
3723,
492,
3814,
2768,
1685,
199,
504,
29986,
476,
14,
1018,
14,
18548,
478,
14,
23878,
492,
10071,
1685,
2988,
199,
504,
29986,
476,
14,
1018,
14,
1907,
14,
3723,
14,
5628,
63,
18254,
63,
1907,
492,
32471,
63,
11359,
14959,
303,
5619,
199,
504,
29986,
476,
14,
1018,
14,
16877,
14,
3627,
492,
7448,
2028,
12,
13303,
568,
41,
199,
504,
29986,
476,
14,
1018,
14,
16877,
14,
80,
460,
292,
5998,
492,
13082,
63,
1943,
63,
955,
199,
504,
29986,
476,
14,
1018,
14,
16877,
14,
8583,
492,
1218,
63,
6807,
63,
1053,
63,
1238,
199,
504,
29986,
476,
14,
1018,
14,
4196,
14,
4316,
14,
1130,
63,
3825,
492,
9672,
7900,
5619,
199,
504,
29986,
476,
14,
1018,
14,
4196,
14,
4316,
14,
5335,
63,
3825,
492,
22643,
7900,
2461,
199,
504,
29986,
476,
14,
1018,
14,
18548,
478,
14,
23878,
492,
10071,
1685,
421,
199,
533,
14076,
14959,
303,
5619,
8,
10604,
14,
30983,
12,
32471,
63,
11359,
14959,
303,
5619,
304,
272,
408,
272,
961,
9592,
6127,
282,
922,
370,
886,
7031,
7029,
641,
282,
1627,
1350,
10071,
1685,
14,
267,
446,
18880,
1540,
1163,
570,
8,
83,
9,
543,
314,
1350,
4079,
641,
2863,
2883,
15,
955,
267,
446,
23177,
1540,
5767,
687,
314,
1350,
1808,
1163,
570,
8,
83,
9,
4079,
641,
2863,
2883,
15,
955,
267,
446,
16722,
316,
314,
10071,
701,
3663,
4362,
15,
10125,
3219,
15,
3257,
3219,
267,
446,
577,
379,
4230,
1958,
314,
10071,
4079,
641,
2863,
2883,
15,
955,
272,
13303,
883,
16629,
370,
282,
1101,
14,
2730,
570,
436,
295,
13,
17932,
737,
282,
2945,
900,
14,
339,
408,
272,
4673,
11359,
1173,
4299,
379,
275,
10565,
14,
11274,
8,
495,
9,
327,
570,
931,
272,
4673,
51,
1173,
4299,
379,
275,
10565,
14,
11274,
8,
495,
9,
327,
570,
931,
272,
4673,
2980,
2042,
1084,
275,
10565,
14,
11274,
8,
495,
9,
327,
493,
931,
272,
4673,
4858,
4241,
275,
10565,
14,
11274,
8,
495,
12,
620,
12,
620,
9,
327,
1350,
63,
515,
12,
2053,
63,
515,
12,
3622,
63,
515,
339,
347,
636,
826,
721,
277,
12,
4051,
63,
2609,
26,
10071,
1685,
2988,
12,
1676,
29,
403,
12,
1350,
63,
1238,
29,
403,
304,
267,
408,
267,
520,
635,
4051,
63,
2609,
26,
334,
9205,
1685,
2988,
9,
288,
961,
911,
506,
1202,
370,
2429,
7664,
15,
28669,
402,
10071,
20474,
1202,
288,
315,
314,
3439,
14,
267,
520,
635,
1676,
26,
334,
49,
16031,
9,
398,
520,
635,
1350,
63,
1238,
26,
334,
9205,
1685,
9,
288,
1626,
2716,
1350,
10071,
1685,
267,
408,
267,
291,
14,
1587,
63,
2609,
275,
4051,
63,
2609,
267,
5928,
14,
30983,
855,
826,
721,
277,
12,
1676,
9,
267,
291,
14,
2758,
18203,
8,
277,
9,
267,
291,
14,
1365,
63,
1238,
275,
1350,
63,
1238,
267,
291,
423,
5628,
63,
1345,
63,
1238,
275,
3814,
2768,
1685,
342,
267,
291,
423,
17381,
63,
1345,
63,
1238,
275,
3814,
2768,
1685,
342,
267,
291,
423,
18254,
63,
1725,
275,
1052,
267,
291,
423,
5628,
63,
1725,
275,
1052,
267,
291,
423,
698,
63,
1130,
63,
7928,
795,
275,
1052,
267,
291,
423,
698,
63,
1130,
63,
576,
275,
1052,
267,
291,
14,
3191,
10534,
2461,
275,
488,
267,
291,
14,
3191,
3314,
2461,
275,
488,
267,
291,
14,
770,
85,
321,
3314,
2461,
275,
488,
267,
291,
14,
3235,
7304,
2461,
275,
488,
267,
291,
14,
13737,
7304,
2461,
275,
488,
267,
291,
14,
6472,
342,
267,
340,
291,
14,
1365,
63,
1238,
365,
440,
488,
26,
288,
291,
14,
409,
63,
1365,
63,
1238,
8,
1365,
63,
1238,
12,
7908,
29,
549,
9,
339,
347,
7908,
8,
277,
12,
1350,
63,
515,
29,
403,
12,
2053,
63,
515,
29,
403,
304,
267,
408,
267,
15175,
83,
2446,
15766,
436,
5445,
14,
267,
520,
635,
1350,
63,
515,
26,
334,
495,
12,
849,
488,
9,
288,
982,
642,
365,
488,
2337,
1471,
506,
282,
1686,
931,
2575,
315,
314,
1350,
2042,
21708,
503,
376,
9070,
6534,
14,
398,
520,
635,
2053,
63,
515,
26,
334,
495,
12,
849,
488,
9,
288,
4879,
3537,
5724,
931,
370,
506,
3483,
370,
314,
2053,
2042,
21708,
14,
267,
520,
1107,
26,
488,
267,
408,
267,
340,
1350,
63,
515,
365,
488,
26,
288,
1350,
63,
515,
275,
291,
14,
1365,
2042,
21708,
14,
505,
342,
267,
340,
747,
14,
515,
14,
6292,
8,
1365,
63,
515,
304,
288,
291,
14,
409,
63,
604,
63,
3773,
63,
3771,
8,
1365
] |
[
199,
13965,
844,
199,
199,
7384,
334,
67,
9,
7800,
3107,
69,
415,
699,
4430,
199,
199,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
1618,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
262,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
475,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
16847,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
70,
13399,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
199,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
199,
16847,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
38,
3061,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
5580,
4149,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
2673,
2477,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
1877,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
26734,
14,
199,
624,
199,
199,
646,
747,
199,
646,
10634,
465,
6454,
199,
646,
2050,
199,
504,
9143,
492,
7417,
199,
504,
29986,
476,
14,
1018,
14,
5819,
492,
5928,
12,
10565,
199,
504,
29986,
476,
14,
1018,
14,
992,
14,
3723,
492,
3814,
2768,
1685,
199,
504,
29986,
476,
14,
1018,
14,
18548,
478,
14,
23878,
492,
10071,
1685,
2988,
199,
504,
29986,
476,
14,
1018,
14,
1907,
14,
3723,
14,
5628,
63,
18254,
63,
1907,
492,
32471,
63,
11359,
14959,
303,
5619,
199,
504,
29986,
476,
14,
1018,
14,
16877,
14,
3627,
492,
7448,
2028,
12,
13303,
568,
41,
199,
504,
29986,
476,
14,
1018,
14,
16877,
14,
80,
460,
292,
5998,
492,
13082,
63,
1943,
63,
955,
199,
504,
29986,
476,
14,
1018,
14,
16877,
14,
8583,
492,
1218,
63,
6807,
63,
1053,
63,
1238,
199,
504,
29986,
476,
14,
1018,
14,
4196,
14,
4316,
14,
1130,
63,
3825,
492,
9672,
7900,
5619,
199,
504,
29986,
476,
14,
1018,
14,
4196,
14,
4316,
14,
5335,
63,
3825,
492,
22643,
7900,
2461,
199,
504,
29986,
476,
14,
1018,
14,
18548,
478,
14,
23878,
492,
10071,
1685,
421,
199,
533,
14076,
14959,
303,
5619,
8,
10604,
14,
30983,
12,
32471,
63,
11359,
14959,
303,
5619,
304,
272,
408,
272,
961,
9592,
6127,
282,
922,
370,
886,
7031,
7029,
641,
282,
1627,
1350,
10071,
1685,
14,
267,
446,
18880,
1540,
1163,
570,
8,
83,
9,
543,
314,
1350,
4079,
641,
2863,
2883,
15,
955,
267,
446,
23177,
1540,
5767,
687,
314,
1350,
1808,
1163,
570,
8,
83,
9,
4079,
641,
2863,
2883,
15,
955,
267,
446,
16722,
316,
314,
10071,
701,
3663,
4362,
15,
10125,
3219,
15,
3257,
3219,
267,
446,
577,
379,
4230,
1958,
314,
10071,
4079,
641,
2863,
2883,
15,
955,
272,
13303,
883,
16629,
370,
282,
1101,
14,
2730,
570,
436,
295,
13,
17932,
737,
282,
2945,
900,
14,
339,
408,
272,
4673,
11359,
1173,
4299,
379,
275,
10565,
14,
11274,
8,
495,
9,
327,
570,
931,
272,
4673,
51,
1173,
4299,
379,
275,
10565,
14,
11274,
8,
495,
9,
327,
570,
931,
272,
4673,
2980,
2042,
1084,
275,
10565,
14,
11274,
8,
495,
9,
327,
493,
931,
272,
4673,
4858,
4241,
275,
10565,
14,
11274,
8,
495,
12,
620,
12,
620,
9,
327,
1350,
63,
515,
12,
2053,
63,
515,
12,
3622,
63,
515,
339,
347,
636,
826,
721,
277,
12,
4051,
63,
2609,
26,
10071,
1685,
2988,
12,
1676,
29,
403,
12,
1350,
63,
1238,
29,
403,
304,
267,
408,
267,
520,
635,
4051,
63,
2609,
26,
334,
9205,
1685,
2988,
9,
288,
961,
911,
506,
1202,
370,
2429,
7664,
15,
28669,
402,
10071,
20474,
1202,
288,
315,
314,
3439,
14,
267,
520,
635,
1676,
26,
334,
49,
16031,
9,
398,
520,
635,
1350,
63,
1238,
26,
334,
9205,
1685,
9,
288,
1626,
2716,
1350,
10071,
1685,
267,
408,
267,
291,
14,
1587,
63,
2609,
275,
4051,
63,
2609,
267,
5928,
14,
30983,
855,
826,
721,
277,
12,
1676,
9,
267,
291,
14,
2758,
18203,
8,
277,
9,
267,
291,
14,
1365,
63,
1238,
275,
1350,
63,
1238,
267,
291,
423,
5628,
63,
1345,
63,
1238,
275,
3814,
2768,
1685,
342,
267,
291,
423,
17381,
63,
1345,
63,
1238,
275,
3814,
2768,
1685,
342,
267,
291,
423,
18254,
63,
1725,
275,
1052,
267,
291,
423,
5628,
63,
1725,
275,
1052,
267,
291,
423,
698,
63,
1130,
63,
7928,
795,
275,
1052,
267,
291,
423,
698,
63,
1130,
63,
576,
275,
1052,
267,
291,
14,
3191,
10534,
2461,
275,
488,
267,
291,
14,
3191,
3314,
2461,
275,
488,
267,
291,
14,
770,
85,
321,
3314,
2461,
275,
488,
267,
291,
14,
3235,
7304,
2461,
275,
488,
267,
291,
14,
13737,
7304,
2461,
275,
488,
267,
291,
14,
6472,
342,
267,
340,
291,
14,
1365,
63,
1238,
365,
440,
488,
26,
288,
291,
14,
409,
63,
1365,
63,
1238,
8,
1365,
63,
1238,
12,
7908,
29,
549,
9,
339,
347,
7908,
8,
277,
12,
1350,
63,
515,
29,
403,
12,
2053,
63,
515,
29,
403,
304,
267,
408,
267,
15175,
83,
2446,
15766,
436,
5445,
14,
267,
520,
635,
1350,
63,
515,
26,
334,
495,
12,
849,
488,
9,
288,
982,
642,
365,
488,
2337,
1471,
506,
282,
1686,
931,
2575,
315,
314,
1350,
2042,
21708,
503,
376,
9070,
6534,
14,
398,
520,
635,
2053,
63,
515,
26,
334,
495,
12,
849,
488,
9,
288,
4879,
3537,
5724,
931,
370,
506,
3483,
370,
314,
2053,
2042,
21708,
14,
267,
520,
1107,
26,
488,
267,
408,
267,
340,
1350,
63,
515,
365,
488,
26,
288,
1350,
63,
515,
275,
291,
14,
1365,
2042,
21708,
14,
505,
342,
267,
340,
747,
14,
515,
14,
6292,
8,
1365,
63,
515,
304,
288,
291,
14,
409,
63,
604,
63,
3773,
63,
3771,
8,
1365,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
touqir14/Cmput_692_project
|
Extract_Context_From_Snippets_Surrounding_6_Words.py
|
1
|
1310
|
from sys import getsizeof
import collections
import pickle
# import timeit
from sys import getsizeof
import time
import csv
import io
output = io.StringIO()
with open('../dictionary_Nikon_Snippet_Surroundings.pickle', 'rb') as f:
d = (pickle.load(f))
with open('/Users/sasa/Dropbox/1-Uni/CMPUT 692/Project/Code/Nikon_Entities.csv', 'rU') as csvfile:
reader = csv.reader(csvfile, dialect=csv.excel_tab)
#with open('/Users/sasa/Dropbox/1-Uni/CMPUT 692/Project/Code/Nikon_context.csv', 'w') as csvfile2:
with open('/Users/sasa/Dropbox/1-Uni/CMPUT 692/Project/Code/Nikon_context.pickle', 'wb') as picklefile:
#writer = csv.writer(csvfile2)
Nikon_Surr={}
for row in reader:
print(row[0])
#excelrow=[row[0]]
excelrow = []
surr={}
#print(d[row[0]])
surr= collections.Counter(d[row[0].lower()])
mc=(surr.most_common(6))
#print(mc)
for value in mc:
excelrow.append(value[0])
Nikon_Surr[str(row[0]).lower()]=excelrow
print(Nikon_Surr[str(row[0]).lower()])
pickle.dump(Nikon_Surr, picklefile)
#writer.writerow((excelrow))
|
apache-2.0
|
[
504,
984,
492,
664,
12590,
199,
646,
5055,
199,
646,
5927,
199,
3,
492,
900,
390,
199,
504,
984,
492,
664,
12590,
199,
646,
900,
199,
646,
7392,
199,
646,
5890,
199,
1199,
275,
5890,
14,
6424,
342,
421,
199,
1045,
1551,
24592,
9086,
63,
46,
3258,
265,
63,
20821,
11088,
63,
11762,
2363,
780,
14,
8092,
297,
283,
4848,
358,
465,
289,
26,
272,
366,
275,
334,
8092,
14,
912,
8,
70,
430,
272,
543,
1551,
2336,
12117,
15,
22601,
65,
15,
11070,
1977,
15,
17,
13,
27921,
15,
23181,
934,
1227,
2942,
15,
4761,
15,
3034,
15,
46,
3258,
265,
63,
24672,
14,
4737,
297,
283,
28978,
358,
465,
7392,
493,
26,
267,
7002,
275,
7392,
14,
5503,
8,
4737,
493,
12,
10982,
29,
4737,
14,
28330,
63,
2902,
9,
267,
327,
1045,
1551,
2336,
12117,
15,
22601,
65,
15,
11070,
1977,
15,
17,
13,
27921,
15,
23181,
934,
1227,
2942,
15,
4761,
15,
3034,
15,
46,
3258,
265,
63,
1100,
14,
4737,
297,
283,
87,
358,
465,
7392,
493,
18,
26,
267,
543,
1551,
2336,
12117,
15,
22601,
65,
15,
11070,
1977,
15,
17,
13,
27921,
15,
23181,
934,
1227,
2942,
15,
4761,
15,
3034,
15,
46,
3258,
265,
63,
1100,
14,
8092,
297,
283,
6603,
358,
465,
5927,
493,
26,
288,
327,
5491,
275,
7392,
14,
5491,
8,
4737,
493,
18,
9,
288,
653,
3258,
265,
63,
11762,
82,
7622,
288,
367,
1962,
315,
7002,
26,
355,
870,
8,
1143,
59,
16,
566,
355,
327,
28330,
1143,
1524,
1143,
59,
16,
2677,
355,
444,
6067,
1143,
275,
942,
355,
6296,
82,
7622,
355,
327,
1361,
8,
68,
59,
1143,
59,
16,
3934,
355,
6296,
82,
29,
5055,
14,
11348,
8,
68,
59,
1143,
59,
16,
1055,
2325,
9383,
355,
16377,
2687,
5105,
82,
14,
2786,
63,
2330,
8,
22,
430,
355,
327,
1361,
8,
5466,
9,
355,
367,
574,
315,
16377,
26,
490,
444,
6067,
1143,
14,
740,
8,
585,
59,
16,
566,
355,
653,
3258,
265,
63,
11762,
82,
59,
495,
8,
1143,
59,
16,
6575,
2325,
5106,
29,
28330,
1143,
355,
870,
8,
46,
3258,
265,
63,
11762,
82,
59,
495,
8,
1143,
59,
16,
6575,
2325,
9383,
288,
5927,
14,
2724,
8,
46,
3258,
265,
63,
11762,
82,
12,
5927,
493,
9,
355,
327,
5491,
14,
22686,
1332,
28330,
1143,
430,
6905,
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
] |
[
984,
492,
664,
12590,
199,
646,
5055,
199,
646,
5927,
199,
3,
492,
900,
390,
199,
504,
984,
492,
664,
12590,
199,
646,
900,
199,
646,
7392,
199,
646,
5890,
199,
1199,
275,
5890,
14,
6424,
342,
421,
199,
1045,
1551,
24592,
9086,
63,
46,
3258,
265,
63,
20821,
11088,
63,
11762,
2363,
780,
14,
8092,
297,
283,
4848,
358,
465,
289,
26,
272,
366,
275,
334,
8092,
14,
912,
8,
70,
430,
272,
543,
1551,
2336,
12117,
15,
22601,
65,
15,
11070,
1977,
15,
17,
13,
27921,
15,
23181,
934,
1227,
2942,
15,
4761,
15,
3034,
15,
46,
3258,
265,
63,
24672,
14,
4737,
297,
283,
28978,
358,
465,
7392,
493,
26,
267,
7002,
275,
7392,
14,
5503,
8,
4737,
493,
12,
10982,
29,
4737,
14,
28330,
63,
2902,
9,
267,
327,
1045,
1551,
2336,
12117,
15,
22601,
65,
15,
11070,
1977,
15,
17,
13,
27921,
15,
23181,
934,
1227,
2942,
15,
4761,
15,
3034,
15,
46,
3258,
265,
63,
1100,
14,
4737,
297,
283,
87,
358,
465,
7392,
493,
18,
26,
267,
543,
1551,
2336,
12117,
15,
22601,
65,
15,
11070,
1977,
15,
17,
13,
27921,
15,
23181,
934,
1227,
2942,
15,
4761,
15,
3034,
15,
46,
3258,
265,
63,
1100,
14,
8092,
297,
283,
6603,
358,
465,
5927,
493,
26,
288,
327,
5491,
275,
7392,
14,
5491,
8,
4737,
493,
18,
9,
288,
653,
3258,
265,
63,
11762,
82,
7622,
288,
367,
1962,
315,
7002,
26,
355,
870,
8,
1143,
59,
16,
566,
355,
327,
28330,
1143,
1524,
1143,
59,
16,
2677,
355,
444,
6067,
1143,
275,
942,
355,
6296,
82,
7622,
355,
327,
1361,
8,
68,
59,
1143,
59,
16,
3934,
355,
6296,
82,
29,
5055,
14,
11348,
8,
68,
59,
1143,
59,
16,
1055,
2325,
9383,
355,
16377,
2687,
5105,
82,
14,
2786,
63,
2330,
8,
22,
430,
355,
327,
1361,
8,
5466,
9,
355,
367,
574,
315,
16377,
26,
490,
444,
6067,
1143,
14,
740,
8,
585,
59,
16,
566,
355,
653,
3258,
265,
63,
11762,
82,
59,
495,
8,
1143,
59,
16,
6575,
2325,
5106,
29,
28330,
1143,
355,
870,
8,
46,
3258,
265,
63,
11762,
82,
59,
495,
8,
1143,
59,
16,
6575,
2325,
9383,
288,
5927,
14,
2724,
8,
46,
3258,
265,
63,
11762,
82,
12,
5927,
493,
9,
355,
327,
5491,
14,
22686,
1332,
28330,
1143,
430,
6905,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sayedmohamed/pomodora-todo
|
pomotodo/mytodo/migrations/0001_initial.py
|
1
|
6658
|
# -*- 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
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding model 'Project'
db.create_table(u'mytodo_project', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('project_title', self.gf('django.db.models.fields.CharField')(max_length=200)),
('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])),
))
db.send_create_signal(u'mytodo', ['Project'])
# Adding model 'Task'
db.create_table(u'mytodo_task', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('task_title', self.gf('django.db.models.fields.CharField')(max_length=200)),
('task_createdAt', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
('task_description', self.gf('django.db.models.fields.TextField')(null=True, blank=True)),
('task_priority', self.gf('django.db.models.fields.IntegerField')(default=2, max_length=1, blank=True)),
('task_dueDate', self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True)),
('task_estimated', self.gf('django.db.models.fields.IntegerField')()),
('project', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['mytodo.Project'])),
('task_pomodori', self.gf('django.db.models.fields.SmallIntegerField')(default=0)),
('task_completed', self.gf('django.db.models.fields.BooleanField')(default=False)),
))
db.send_create_signal(u'mytodo', ['Task'])
def backwards(self, orm):
# Deleting model 'Project'
db.delete_table(u'mytodo_project')
# Deleting model 'Task'
db.delete_table(u'mytodo_task')
models = {
u'auth.group': {
'Meta': {'object_name': 'Group'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
u'auth.permission': {
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Group']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'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'})
},
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'mytodo.project': {
'Meta': {'object_name': 'Project'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'project_title': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"})
},
u'mytodo.task': {
'Meta': {'object_name': 'Task'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'project': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['mytodo.Project']"}),
'task_completed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'task_createdAt': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'task_description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'task_dueDate': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'task_estimated': ('django.db.models.fields.IntegerField', [], {}),
'task_pomodori': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}),
'task_priority': ('django.db.models.fields.IntegerField', [], {'default': '2', 'max_length': '1', 'blank': 'True'}),
'task_title': ('django.db.models.fields.CharField', [], {'max_length': '200'})
}
}
complete_apps = ['mytodo']
|
gpl-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,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
12934,
1402,
283,
4761,
7,
267,
1592,
14,
981,
63,
1224,
8,
85,
6704,
89,
11396,
63,
1715,
297,
334,
288,
334,
85,
7,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
7533,
3327,
63,
498,
29,
549,
1826,
288,
661,
1715,
63,
1213,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
988,
63,
1267,
29,
1840,
1826,
288,
661,
751,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
475,
29,
1025,
459,
1178,
14,
1899,
16607,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
8,
85,
6704,
89,
11396,
297,
788,
4761,
1105,
398,
327,
12934,
1402,
283,
4476,
7,
267,
1592,
14,
981,
63,
1224,
8,
85,
6704,
89,
11396,
63,
1765,
297,
334,
288,
334,
85,
7,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
7533,
3327,
63,
498,
29,
549,
1826,
288,
661,
1765,
63,
1213,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
988,
63,
1267,
29,
1840,
1826,
288,
661,
1765,
63,
32087,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
7533,
2495,
63,
2131,
29,
549,
12,
4596,
29,
549,
1826,
288,
661,
1765,
63,
1802,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
7533,
2307,
29,
549,
12,
4596,
29,
549,
1826,
288,
661,
1765,
63,
6693,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
7533,
885,
29,
18,
12,
1390,
63,
1267,
29,
17,
12,
4596,
29,
549,
1826,
288,
661,
1765,
63,
11933,
2506,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
7533,
2307,
29,
549,
12,
4596,
29,
549,
1826,
288,
661,
1765,
63,
597,
12754,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
358,
4000,
288,
661,
1715,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
475,
29,
1025,
459,
1662,
11396,
14,
4761,
16607,
288,
661,
1765,
63,
555,
1494,
16039,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
14640,
7533,
885,
29,
16,
1826,
288,
661,
1765,
63,
12634,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
7533,
885,
29,
797,
1826,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
8,
85,
6704,
89,
11396,
297,
788,
4476,
1105,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
15920,
1402,
283,
4761,
7,
267,
1592,
14,
1807,
63,
1224,
8,
85,
6704,
89,
11396,
63,
1715,
358,
398,
327,
15920,
1402,
283,
4476,
7,
267,
1592,
14,
1807,
63,
1224,
8,
85,
6704,
89,
11396,
63,
1765,
358,
2378,
1709,
275,
469,
267,
399,
7,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
399,
7,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
7340,
85,
7,
1317,
63,
466,
363,
571,
63,
1302,
297,
399,
7,
1317,
63,
466,
363,
1238,
297,
399,
7,
11879,
18106,
283,
3235,
63,
6314,
356,
298,
1332,
85,
7,
1317,
63,
466,
297,
399,
7,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
10778,
14,
11282,
6097,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
399,
7,
1178,
14,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
988,
63,
1267,
356,
283,
2194,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2634,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
10247,
356,
283,
797,
297,
283,
2407,
63,
354,
356,
298,
85,
7,
751,
63,
409,
4662,
283,
2500,
356,
283,
549,
297,
283,
475,
356,
399,
2,
1025,
459,
1178,
14,
2448,
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,
374
] |
[
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,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
12934,
1402,
283,
4761,
7,
267,
1592,
14,
981,
63,
1224,
8,
85,
6704,
89,
11396,
63,
1715,
297,
334,
288,
334,
85,
7,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
7533,
3327,
63,
498,
29,
549,
1826,
288,
661,
1715,
63,
1213,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
988,
63,
1267,
29,
1840,
1826,
288,
661,
751,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
475,
29,
1025,
459,
1178,
14,
1899,
16607,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
8,
85,
6704,
89,
11396,
297,
788,
4761,
1105,
398,
327,
12934,
1402,
283,
4476,
7,
267,
1592,
14,
981,
63,
1224,
8,
85,
6704,
89,
11396,
63,
1765,
297,
334,
288,
334,
85,
7,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
7533,
3327,
63,
498,
29,
549,
1826,
288,
661,
1765,
63,
1213,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
988,
63,
1267,
29,
1840,
1826,
288,
661,
1765,
63,
32087,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
7533,
2495,
63,
2131,
29,
549,
12,
4596,
29,
549,
1826,
288,
661,
1765,
63,
1802,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
7533,
2307,
29,
549,
12,
4596,
29,
549,
1826,
288,
661,
1765,
63,
6693,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
7533,
885,
29,
18,
12,
1390,
63,
1267,
29,
17,
12,
4596,
29,
549,
1826,
288,
661,
1765,
63,
11933,
2506,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
7533,
2307,
29,
549,
12,
4596,
29,
549,
1826,
288,
661,
1765,
63,
597,
12754,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
358,
4000,
288,
661,
1715,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
475,
29,
1025,
459,
1662,
11396,
14,
4761,
16607,
288,
661,
1765,
63,
555,
1494,
16039,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
14640,
7533,
885,
29,
16,
1826,
288,
661,
1765,
63,
12634,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
7533,
885,
29,
797,
1826,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
8,
85,
6704,
89,
11396,
297,
788,
4476,
1105,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
15920,
1402,
283,
4761,
7,
267,
1592,
14,
1807,
63,
1224,
8,
85,
6704,
89,
11396,
63,
1715,
358,
398,
327,
15920,
1402,
283,
4476,
7,
267,
1592,
14,
1807,
63,
1224,
8,
85,
6704,
89,
11396,
63,
1765,
358,
2378,
1709,
275,
469,
267,
399,
7,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
399,
7,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
7340,
85,
7,
1317,
63,
466,
363,
571,
63,
1302,
297,
399,
7,
1317,
63,
466,
363,
1238,
297,
399,
7,
11879,
18106,
283,
3235,
63,
6314,
356,
298,
1332,
85,
7,
1317,
63,
466,
297,
399,
7,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
10778,
14,
11282,
6097,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
399,
7,
1178,
14,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
988,
63,
1267,
356,
283,
2194,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2634,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
10247,
356,
283,
797,
297,
283,
2407,
63,
354,
356,
298,
85,
7,
751,
63,
409,
4662,
283,
2500,
356,
283,
549,
297,
283,
475,
356,
399,
2,
1025,
459,
1178,
14,
2448,
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,
374,
0
] |
[
1,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daltonsena/eyed3
|
examples/chapters.py
|
2
|
3470
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
# Copyright (C) 2012 Travis Shirk <travis@pobox.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
################################################################################
from __future__ import print_function
import sys
from eyed3.id3.tag import Tag
def printChapter(chapter):
# The element ID is the unique key for this chapter
print("== Chapter '%s'" % chapter.element_id)
# TIT2 sub frame
print("-- Title:", chapter.title)
# TIT3 sub frame
print("-- subtitle:", chapter.subtitle)
# WXXX sub frame
print("-- url:", chapter.user_url)
# Start and end time - tuple
print("-- Start time: %d; End time: %d" % chapter.times)
# Start and end offset - tuple. None is used to set to "no offset"
print("-- Start offset: %s; End offset: %s" %
tuple((str(o) for o in chapter.offsets)))
print("-- Sub frames:", str(list(chapter.sub_frames.keys())))
tag = Tag()
if len(sys.argv) > 1:
tag.parse(sys.argv[1])
for toc in tag.table_of_contents:
print("=== Table of contents:", toc.element_id)
print("--- description:", toc.description)
print("--- toplevel:", toc.toplevel)
print("--- ordered:", toc.ordered)
print("--- child_ids:", toc.child_ids)
tag.chapters.set("a brand new chapter", (16234, 21546))
tag.chapters.set("another brand new chapter", (21567, 30000), (654221, 765543))
tag.chapters.set("final chapter", (40000, 50000))
tag.chapters.set("oops", (21567, 30000), (654221, 765543))
tag.chapters.remove("oops")
chapter_frame = tag.chapters.get("final chapter")
chapter_frame.element_id = b"Final Chapter"
chapter_frame.offsets = (800000, None)
chapter_frame.user_url = "http://example.com/foo"
chapter_frame.user_url = "http://example.com/chapter#final"
chapter_frame.user_url = None
print("-" * 80)
for chap in tag.chapters:
print(chap)
printChapter(chap)
print("-" * 80)
# Given a list of chapter IDs from the table of contents access each chapter
print("+" * 80)
for toc in tag.table_of_contents:
print("toc:", toc.element_id)
for chap_id in toc.child_ids:
print(chap_id)
printChapter(tag.chapters[chap_id])
print("+" * 80)
## Brand new frames
tag = Tag()
toc = tag.table_of_contents.set("toc", toplevel=True,
child_ids=["intro", "chap1", "chap2", "chap3"],
description=u"Table of Contents")
toc2 = tag.table_of_contents.set("toc2")
toc.child_ids.append(toc2.element_id)
chap4 = tag.chapters.set("chap4", times=(100, 200))
toc2.child_ids.append(chap4.element_id)
try:
tag.table_of_contents.set("oops", toplevel=True)
except ValueError as ex:
print("Expected:", ex)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
13289,
199,
3,
221,
1898,
334,
35,
9,
6029,
221,
12643,
5068,
5244,
723,
75,
665,
1239,
5068,
32,
555,
1977,
14,
957,
30,
199,
3,
199,
3,
221,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
221,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
221,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
221,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
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,
221,
1666,
314,
199,
3,
221,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
221,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
221,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
3,
199,
13289,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
984,
199,
504,
325,
89,
379,
19,
14,
344,
19,
14,
1450,
492,
8053,
199,
199,
318,
870,
30791,
8,
11316,
304,
272,
327,
710,
1819,
2870,
365,
314,
3747,
790,
367,
642,
17044,
272,
870,
480,
389,
2799,
4185,
1543,
83,
4065,
450,
17044,
14,
2108,
63,
344,
9,
272,
327,
377,
649,
18,
1007,
2787,
272,
870,
6739,
16881,
6783,
17044,
14,
1213,
9,
272,
327,
377,
649,
19,
1007,
2787,
272,
870,
6739,
18197,
6783,
17044,
14,
14348,
9,
272,
327,
644,
13933,
1007,
2787,
272,
870,
6739,
1166,
6783,
17044,
14,
751,
63,
633,
9,
272,
327,
7707,
436,
1284,
900,
446,
2008,
272,
870,
6739,
7707,
900,
26,
450,
68,
27,
9599,
900,
26,
450,
68,
2,
450,
17044,
14,
4508,
9,
272,
327,
7707,
436,
1284,
3268,
446,
2008,
14,
488,
365,
1202,
370,
663,
370,
298,
889,
3268,
2,
272,
870,
6739,
7707,
3268,
26,
450,
83,
27,
9599,
3268,
26,
450,
83,
2,
450,
881,
2008,
1332,
495,
8,
79,
9,
367,
312,
315,
17044,
14,
14253,
1724,
272,
870,
6739,
4804,
11223,
6783,
620,
8,
513,
8,
11316,
14,
954,
63,
8444,
14,
1612,
16890,
199,
199,
1450,
275,
8053,
342,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
272,
1947,
14,
1122,
8,
1274,
14,
3020,
59,
17,
566,
199,
199,
509,
22021,
315,
1947,
14,
1224,
63,
1618,
63,
4407,
26,
272,
870,
480,
5918,
6957,
402,
4072,
6783,
22021,
14,
2108,
63,
344,
9,
272,
870,
480,
2595,
1369,
6783,
22021,
14,
1802,
9,
272,
870,
480,
2595,
13836,
6783,
22021,
14,
13517,
9,
272,
870,
480,
2595,
7741,
6783,
22021,
14,
8235,
9,
272,
870,
480,
2595,
1982,
63,
1580,
6783,
22021,
14,
1739,
63,
1580,
9,
199,
199,
1450,
14,
335,
12552,
14,
409,
480,
65,
32159,
892,
17044,
401,
334,
975,
5533,
12,
28436,
2466,
430,
199,
1450,
14,
335,
12552,
14,
409,
480,
13565,
32159,
892,
17044,
401,
334,
7842,
1822,
12,
650,
993,
395,
334,
11157,
11564,
12,
1520,
10027,
2824,
430,
199,
1450,
14,
335,
12552,
14,
409,
480,
5094,
17044,
401,
334,
20,
993,
12,
959,
993,
430,
199,
199,
1450,
14,
335,
12552,
14,
409,
480,
79,
1483,
401,
334,
7842,
1822,
12,
650,
993,
395,
334,
11157,
11564,
12,
1520,
10027,
2824,
430,
199,
1450,
14,
335,
12552,
14,
2168,
480,
79,
1483,
531,
199,
199,
11316,
63,
1943,
275,
1947,
14,
335,
12552,
14,
362,
480,
5094,
17044,
531,
199,
11316,
63,
1943,
14,
2108,
63,
344,
275,
330,
2,
12776,
2799,
4185,
2,
199,
11316,
63,
1943,
14,
14253,
275,
334,
24,
5345,
12,
488,
9,
199,
11316,
63,
1943,
14,
751,
63,
633,
275,
298,
1014,
921,
2694,
14,
957,
15,
1421,
2,
199,
11316,
63,
1943,
14,
751,
63,
633,
275,
298,
1014,
921,
2694,
14,
957,
15,
11316,
3,
5094,
2,
199,
11316,
63,
1943,
14,
751,
63,
633,
275,
488,
199,
199,
1361,
6096,
2,
627,
5939,
9,
199,
509,
682,
439,
315,
1947,
14,
335,
12552,
26,
272,
870,
8,
28765,
9,
272,
870,
30791,
8,
28765,
9,
199,
1361,
6096,
2,
627,
5939,
9,
199,
199,
3,
9138,
282,
769,
402,
17044,
11449,
687,
314,
1817,
402,
4072,
2879,
1924,
17044,
199,
1361,
480,
5207,
627,
5939,
9,
199,
509,
22021,
315,
1947,
14,
1224,
63,
1618,
63,
4407,
26,
272,
870,
480,
13255,
6783,
22021,
14,
2108,
63,
344,
9,
272,
367,
682,
439,
63,
344,
315,
22021,
14,
1739,
63,
1580,
26,
267,
870,
8,
28765,
63,
344,
9,
267,
870,
30791,
8,
1450,
14,
335,
12552,
59,
28765,
63,
344,
566,
199,
1361,
480,
5207,
627,
5939,
9,
421,
199,
309,
699,
3759,
892,
11223,
199,
1450,
275,
8053,
342,
199,
13255,
275,
1947,
14,
1224,
63,
1618,
63,
4407,
14,
409,
480,
13255,
401,
13836,
29,
549,
12,
1816,
1982,
63,
1580,
6270,
18206,
401,
298,
28765,
17,
401,
298,
28765,
18,
401,
298,
28765,
19,
2255,
1816,
1369,
29,
85,
2,
3186,
402,
6646,
83,
531,
199,
13255,
18,
275,
1947,
14,
1224,
63,
1618,
63,
4407,
14,
409,
480,
13255,
18,
531,
199,
13255,
14,
1739,
63,
1580,
14,
740,
8,
13255,
18,
14,
2108,
63,
344,
9,
199,
28765,
20,
275,
1947,
14,
335,
12552,
14,
409,
480,
28765,
20,
401,
5431,
2687,
1960,
12,
1926,
430,
199,
13255,
18,
14,
1739,
63,
1580,
14,
740,
8,
28765,
20,
14,
2108,
63,
344,
9,
199,
199,
893,
26,
272,
1947,
14,
1224,
63,
1618,
63,
4407,
14,
409,
480,
79,
1483,
401,
13836,
29,
549,
9,
199,
2590,
1722,
465,
444,
26,
272,
870,
480,
6964,
6783,
444,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
13289,
199,
3,
221,
1898,
334,
35,
9,
6029,
221,
12643,
5068,
5244,
723,
75,
665,
1239,
5068,
32,
555,
1977,
14,
957,
30,
199,
3,
199,
3,
221,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
221,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
221,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
221,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
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,
221,
1666,
314,
199,
3,
221,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
221,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
221,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
3,
199,
13289,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
984,
199,
504,
325,
89,
379,
19,
14,
344,
19,
14,
1450,
492,
8053,
199,
199,
318,
870,
30791,
8,
11316,
304,
272,
327,
710,
1819,
2870,
365,
314,
3747,
790,
367,
642,
17044,
272,
870,
480,
389,
2799,
4185,
1543,
83,
4065,
450,
17044,
14,
2108,
63,
344,
9,
272,
327,
377,
649,
18,
1007,
2787,
272,
870,
6739,
16881,
6783,
17044,
14,
1213,
9,
272,
327,
377,
649,
19,
1007,
2787,
272,
870,
6739,
18197,
6783,
17044,
14,
14348,
9,
272,
327,
644,
13933,
1007,
2787,
272,
870,
6739,
1166,
6783,
17044,
14,
751,
63,
633,
9,
272,
327,
7707,
436,
1284,
900,
446,
2008,
272,
870,
6739,
7707,
900,
26,
450,
68,
27,
9599,
900,
26,
450,
68,
2,
450,
17044,
14,
4508,
9,
272,
327,
7707,
436,
1284,
3268,
446,
2008,
14,
488,
365,
1202,
370,
663,
370,
298,
889,
3268,
2,
272,
870,
6739,
7707,
3268,
26,
450,
83,
27,
9599,
3268,
26,
450,
83,
2,
450,
881,
2008,
1332,
495,
8,
79,
9,
367,
312,
315,
17044,
14,
14253,
1724,
272,
870,
6739,
4804,
11223,
6783,
620,
8,
513,
8,
11316,
14,
954,
63,
8444,
14,
1612,
16890,
199,
199,
1450,
275,
8053,
342,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
272,
1947,
14,
1122,
8,
1274,
14,
3020,
59,
17,
566,
199,
199,
509,
22021,
315,
1947,
14,
1224,
63,
1618,
63,
4407,
26,
272,
870,
480,
5918,
6957,
402,
4072,
6783,
22021,
14,
2108,
63,
344,
9,
272,
870,
480,
2595,
1369,
6783,
22021,
14,
1802,
9,
272,
870,
480,
2595,
13836,
6783,
22021,
14,
13517,
9,
272,
870,
480,
2595,
7741,
6783,
22021,
14,
8235,
9,
272,
870,
480,
2595,
1982,
63,
1580,
6783,
22021,
14,
1739,
63,
1580,
9,
199,
199,
1450,
14,
335,
12552,
14,
409,
480,
65,
32159,
892,
17044,
401,
334,
975,
5533,
12,
28436,
2466,
430,
199,
1450,
14,
335,
12552,
14,
409,
480,
13565,
32159,
892,
17044,
401,
334,
7842,
1822,
12,
650,
993,
395,
334,
11157,
11564,
12,
1520,
10027,
2824,
430,
199,
1450,
14,
335,
12552,
14,
409,
480,
5094,
17044,
401,
334,
20,
993,
12,
959,
993,
430,
199,
199,
1450,
14,
335,
12552,
14,
409,
480,
79,
1483,
401,
334,
7842,
1822,
12,
650,
993,
395,
334,
11157,
11564,
12,
1520,
10027,
2824,
430,
199,
1450,
14,
335,
12552,
14,
2168,
480,
79,
1483,
531,
199,
199,
11316,
63,
1943,
275,
1947,
14,
335,
12552,
14,
362,
480,
5094,
17044,
531,
199,
11316,
63,
1943,
14,
2108,
63,
344,
275,
330,
2,
12776,
2799,
4185,
2,
199,
11316,
63,
1943,
14,
14253,
275,
334,
24,
5345,
12,
488,
9,
199,
11316,
63,
1943,
14,
751,
63,
633,
275,
298,
1014,
921,
2694,
14,
957,
15,
1421,
2,
199,
11316,
63,
1943,
14,
751,
63,
633,
275,
298,
1014,
921,
2694,
14,
957,
15,
11316,
3,
5094,
2,
199,
11316,
63,
1943,
14,
751,
63,
633,
275,
488,
199,
199,
1361,
6096,
2,
627,
5939,
9,
199,
509,
682,
439,
315,
1947,
14,
335,
12552,
26,
272,
870,
8,
28765,
9,
272,
870,
30791,
8,
28765,
9,
199,
1361,
6096,
2,
627,
5939,
9,
199,
199,
3,
9138,
282,
769,
402,
17044,
11449,
687,
314,
1817,
402,
4072,
2879,
1924,
17044,
199,
1361,
480,
5207,
627,
5939,
9,
199,
509,
22021,
315,
1947,
14,
1224,
63,
1618,
63,
4407,
26,
272,
870,
480,
13255,
6783,
22021,
14,
2108,
63,
344,
9,
272,
367,
682,
439,
63,
344,
315,
22021,
14,
1739,
63,
1580,
26,
267,
870,
8,
28765,
63,
344,
9,
267,
870,
30791,
8,
1450,
14,
335,
12552,
59,
28765,
63,
344,
566,
199,
1361,
480,
5207,
627,
5939,
9,
421,
199,
309,
699,
3759,
892,
11223,
199,
1450,
275,
8053,
342,
199,
13255,
275,
1947,
14,
1224,
63,
1618,
63,
4407,
14,
409,
480,
13255,
401,
13836,
29,
549,
12,
1816,
1982,
63,
1580,
6270,
18206,
401,
298,
28765,
17,
401,
298,
28765,
18,
401,
298,
28765,
19,
2255,
1816,
1369,
29,
85,
2,
3186,
402,
6646,
83,
531,
199,
13255,
18,
275,
1947,
14,
1224,
63,
1618,
63,
4407,
14,
409,
480,
13255,
18,
531,
199,
13255,
14,
1739,
63,
1580,
14,
740,
8,
13255,
18,
14,
2108,
63,
344,
9,
199,
28765,
20,
275,
1947,
14,
335,
12552,
14,
409,
480,
28765,
20,
401,
5431,
2687,
1960,
12,
1926,
430,
199,
13255,
18,
14,
1739,
63,
1580,
14,
740,
8,
28765,
20,
14,
2108,
63,
344,
9,
199,
199,
893,
26,
272,
1947,
14,
1224,
63,
1618,
63,
4407,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1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jokkebk/euler
|
p59.py
|
1
|
5359
|
cipher = [79, 59, 12, 2, 79, 35, 8, 28, 20, 2, 3, 68, 8, 9, 68, 45, 0, 12, 9,
67, 68, 4, 7, 5, 23, 27, 1, 21, 79, 85, 78, 79, 85, 71, 38, 10, 71, 27,
12, 2, 79, 6, 2, 8, 13, 9, 1, 13, 9, 8, 68, 19, 7, 1, 71, 56, 11, 21,
11, 68, 6, 3, 22, 2, 14, 0, 30, 79, 1, 31, 6, 23, 19, 10, 0, 73, 79,
44, 2, 79, 19, 6, 28, 68, 16, 6, 16, 15, 79, 35, 8, 11, 72, 71, 14, 10,
3, 79, 12, 2, 79, 19, 6, 28, 68, 32, 0, 0, 73, 79, 86, 71, 39, 1, 71,
24, 5, 20, 79, 13, 9, 79, 16, 15, 10, 68, 5, 10, 3, 14, 1, 10, 14, 1,
3, 71, 24, 13, 19, 7, 68, 32, 0, 0, 73, 79, 87, 71, 39, 1, 71, 12, 22,
2, 14, 16, 2, 11, 68, 2, 25, 1, 21, 22, 16, 15, 6, 10, 0, 79, 16, 15,
10, 22, 2, 79, 13, 20, 65, 68, 41, 0, 16, 15, 6, 10, 0, 79, 1, 31, 6,
23, 19, 28, 68, 19, 7, 5, 19, 79, 12, 2, 79, 0, 14, 11, 10, 64, 27, 68,
10, 14, 15, 2, 65, 68, 83, 79, 40, 14, 9, 1, 71, 6, 16, 20, 10, 8, 1,
79, 19, 6, 28, 68, 14, 1, 68, 15, 6, 9, 75, 79, 5, 9, 11, 68, 19, 7,
13, 20, 79, 8, 14, 9, 1, 71, 8, 13, 17, 10, 23, 71, 3, 13, 0, 7, 16,
71, 27, 11, 71, 10, 18, 2, 29, 29, 8, 1, 1, 73, 79, 81, 71, 59, 12, 2,
79, 8, 14, 8, 12, 19, 79, 23, 15, 6, 10, 2, 28, 68, 19, 7, 22, 8, 26,
3, 15, 79, 16, 15, 10, 68, 3, 14, 22, 12, 1, 1, 20, 28, 72, 71, 14, 10,
3, 79, 16, 15, 10, 68, 3, 14, 22, 12, 1, 1, 20, 28, 68, 4, 14, 10, 71,
1, 1, 17, 10, 22, 71, 10, 28, 19, 6, 10, 0, 26, 13, 20, 7, 68, 14, 27,
74, 71, 89, 68, 32, 0, 0, 71, 28, 1, 9, 27, 68, 45, 0, 12, 9, 79, 16,
15, 10, 68, 37, 14, 20, 19, 6, 23, 19, 79, 83, 71, 27, 11, 71, 27, 1,
11, 3, 68, 2, 25, 1, 21, 22, 11, 9, 10, 68, 6, 13, 11, 18, 27, 68, 19,
7, 1, 71, 3, 13, 0, 7, 16, 71, 28, 11, 71, 27, 12, 6, 27, 68, 2, 25, 1,
21, 22, 11, 9, 10, 68, 10, 6, 3, 15, 27, 68, 5, 10, 8, 14, 10, 18, 2,
79, 6, 2, 12, 5, 18, 28, 1, 71, 0, 2, 71, 7, 13, 20, 79, 16, 2, 28, 16,
14, 2, 11, 9, 22, 74, 71, 87, 68, 45, 0, 12, 9, 79, 12, 14, 2, 23, 2,
3, 2, 71, 24, 5, 20, 79, 10, 8, 27, 68, 19, 7, 1, 71, 3, 13, 0, 7, 16,
92, 79, 12, 2, 79, 19, 6, 28, 68, 8, 1, 8, 30, 79, 5, 71, 24, 13, 19,
1, 1, 20, 28, 68, 19, 0, 68, 19, 7, 1, 71, 3, 13, 0, 7, 16, 73, 79, 93,
71, 59, 12, 2, 79, 11, 9, 10, 68, 16, 7, 11, 71, 6, 23, 71, 27, 12, 2,
79, 16, 21, 26, 1, 71, 3, 13, 0, 7, 16, 75, 79, 19, 15, 0, 68, 0, 6,
18, 2, 28, 68, 11, 6, 3, 15, 27, 68, 19, 0, 68, 2, 25, 1, 21, 22, 11,
9, 10, 72, 71, 24, 5, 20, 79, 3, 8, 6, 10, 0, 79, 16, 8, 79, 7, 8, 2,
1, 71, 6, 10, 19, 0, 68, 19, 7, 1, 71, 24, 11, 21, 3, 0, 73, 79, 85,
87, 79, 38, 18, 27, 68, 6, 3, 16, 15, 0, 17, 0, 7, 68, 19, 7, 1, 71,
24, 11, 21, 3, 0, 71, 24, 5, 20, 79, 9, 6, 11, 1, 71, 27, 12, 21, 0,
17, 0, 7, 68, 15, 6, 9, 75, 79, 16, 15, 10, 68, 16, 0, 22, 11, 11, 68,
3, 6, 0, 9, 72, 16, 71, 29, 1, 4, 0, 3, 9, 6, 30, 2, 79, 12, 14, 2, 68,
16, 7, 1, 9, 79, 12, 2, 79, 7, 6, 2, 1, 73, 79, 85, 86, 79, 33, 17, 10,
10, 71, 6, 10, 71, 7, 13, 20, 79, 11, 16, 1, 68, 11, 14, 10, 3, 79, 5,
9, 11, 68, 6, 2, 11, 9, 8, 68, 15, 6, 23, 71, 0, 19, 9, 79, 20, 2, 0,
20, 11, 10, 72, 71, 7, 1, 71, 24, 5, 20, 79, 10, 8, 27, 68, 6, 12, 7,
2, 31, 16, 2, 11, 74, 71, 94, 86, 71, 45, 17, 19, 79, 16, 8, 79, 5, 11,
3, 68, 16, 7, 11, 71, 13, 1, 11, 6, 1, 17, 10, 0, 71, 7, 13, 10, 79, 5,
9, 11, 68, 6, 12, 7, 2, 31, 16, 2, 11, 68, 15, 6, 9, 75, 79, 12, 2, 79,
3, 6, 25, 1, 71, 27, 12, 2, 79, 22, 14, 8, 12, 19, 79, 16, 8, 79, 6, 2,
12, 11, 10, 10, 68, 4, 7, 13, 11, 11, 22, 2, 1, 68, 8, 9, 68, 32, 0, 0,
73, 79, 85, 84, 79, 48, 15, 10, 29, 71, 14, 22, 2, 79, 22, 2, 13, 11,
21, 1, 69, 71, 59, 12, 14, 28, 68, 14, 28, 68, 9, 0, 16, 71, 14, 68,
23, 7, 29, 20, 6, 7, 6, 3, 68, 5, 6, 22, 19, 7, 68, 21, 10, 23, 18, 3,
16, 14, 1, 3, 71, 9, 22, 8, 2, 68, 15, 26, 9, 6, 1, 68, 23, 14, 23, 20,
6, 11, 9, 79, 11, 21, 79, 20, 11, 14, 10, 75, 79, 16, 15, 6, 23, 71,
29, 1, 5, 6, 22, 19, 7, 68, 4, 0, 9, 2, 28, 68, 1, 29, 11, 10, 79, 35,
8, 11, 74, 86, 91, 68, 52, 0, 68, 19, 7, 1, 71, 56, 11, 21, 11, 68, 5,
10, 7, 6, 2, 1, 71, 7, 17, 10, 14, 10, 71, 14, 10, 3, 79, 8, 14, 25, 1,
3, 79, 12, 2, 29, 1, 71, 0, 10, 71, 10, 5, 21, 27, 12, 71, 14, 9, 8, 1,
3, 71, 26, 23, 73, 79, 44, 2, 79, 19, 6, 28, 68, 1, 26, 8, 11, 79, 11,
1, 79, 17, 9, 9, 5, 14, 3, 13, 9, 8, 68, 11, 0, 18, 2, 79, 5, 9, 11,
68, 1, 14, 13, 19, 7, 2, 18, 3, 10, 2, 28, 23, 73, 79, 37, 9, 11, 68,
16, 10, 68, 15, 14, 18, 2, 79, 23, 2, 10, 10, 71, 7, 13, 20, 79, 3, 11,
0, 22, 30, 67, 68, 19, 7, 1, 71, 8, 8, 8, 29, 29, 71, 0, 2, 71, 27, 12,
2, 79, 11, 9, 3, 29, 71, 60, 11, 9, 79, 11, 1, 79, 16, 15, 10, 68, 33,
14, 16, 15, 10, 22, 73]
best = (0, 0, 0, 0, 0)
for a in range(26):
for b in range(26):
for c in range(26):
key = [a+97,b+97,c+97]
valid = 0
total = 0
for i, ch in enumerate(cipher):
ch ^= key[i%3]
total += ch
if (ch >= 97 and ch <= 122) or (ch >= 65 and ch <= 90):
valid += 1
best = max(best, (valid, total, a, b, c))
print(best)
|
mit
|
[
9231,
275,
359,
1965,
12,
8155,
12,
3144,
12,
499,
12,
13734,
12,
8685,
12,
1695,
12,
7294,
12,
3388,
12,
499,
12,
650,
12,
10851,
12,
1695,
12,
1749,
12,
10851,
12,
10416,
12,
378,
12,
3144,
12,
1749,
12,
267,
13296,
12,
10851,
12,
841,
12,
1520,
12,
959,
12,
6546,
12,
8087,
12,
413,
12,
7829,
12,
13734,
12,
16412,
12,
14679,
12,
13734,
12,
16412,
12,
17245,
12,
10448,
12,
1616,
12,
17245,
12,
8087,
12,
267,
3144,
12,
499,
12,
13734,
12,
1227,
12,
499,
12,
1695,
12,
4944,
12,
1749,
12,
413,
12,
4944,
12,
1749,
12,
1695,
12,
10851,
12,
5851,
12,
1520,
12,
413,
12,
17245,
12,
12001,
12,
4119,
12,
7829,
12,
267,
4119,
12,
10851,
12,
1227,
12,
650,
12,
6928,
12,
499,
12,
4329,
12,
378,
12,
4233,
12,
13734,
12,
413,
12,
7105,
12,
1227,
12,
6546,
12,
5851,
12,
1616,
12,
378,
12,
18525,
12,
13734,
12,
267,
10868,
12,
499,
12,
13734,
12,
5851,
12,
1227,
12,
7294,
12,
10851,
12,
3193,
12,
1227,
12,
3193,
12,
4114,
12,
13734,
12,
8685,
12,
1695,
12,
4119,
12,
15323,
12,
17245,
12,
4329,
12,
1616,
12,
267,
650,
12,
13734,
12,
3144,
12,
499,
12,
13734,
12,
5851,
12,
1227,
12,
7294,
12,
10851,
12,
4337,
12,
378,
12,
378,
12,
18525,
12,
13734,
12,
10300,
12,
17245,
12,
10551,
12,
413,
12,
17245,
12,
267,
5504,
12,
959,
12,
3388,
12,
13734,
12,
4944,
12,
1749,
12,
13734,
12,
3193,
12,
4114,
12,
1616,
12,
10851,
12,
959,
12,
1616,
12,
650,
12,
4329,
12,
413,
12,
1616,
12,
4329,
12,
413,
12,
267,
650,
12,
17245,
12,
5504,
12,
4944,
12,
5851,
12,
1520,
12,
10851,
12,
4337,
12,
378,
12,
378,
12,
18525,
12,
13734,
12,
10513,
12,
17245,
12,
10551,
12,
413,
12,
17245,
12,
3144,
12,
6928,
12,
267,
499,
12,
4329,
12,
3193,
12,
499,
12,
4119,
12,
10851,
12,
499,
12,
5661,
12,
413,
12,
7829,
12,
6928,
12,
3193,
12,
4114,
12,
1227,
12,
1616,
12,
378,
12,
13734,
12,
3193,
12,
4114,
12,
267,
1616,
12,
6928,
12,
499,
12,
13734,
12,
4944,
12,
3388,
12,
11738,
12,
10851,
12,
13385,
12,
378,
12,
3193,
12,
4114,
12,
1227,
12,
1616,
12,
378,
12,
13734,
12,
413,
12,
7105,
12,
1227,
12,
267,
6546,
12,
5851,
12,
7294,
12,
10851,
12,
5851,
12,
1520,
12,
959,
12,
5851,
12,
13734,
12,
3144,
12,
499,
12,
13734,
12,
378,
12,
4329,
12,
4119,
12,
1616,
12,
5049,
12,
8087,
12,
10851,
12,
267,
1616,
12,
4329,
12,
4114,
12,
499,
12,
11738,
12,
10851,
12,
20582,
12,
13734,
12,
6335,
12,
4329,
12,
1749,
12,
413,
12,
17245,
12,
1227,
12,
3193,
12,
3388,
12,
1616,
12,
1695,
12,
413,
12,
267,
13734,
12,
5851,
12,
1227,
12,
7294,
12,
10851,
12,
4329,
12,
413,
12,
10851,
12,
4114,
12,
1227,
12,
1749,
12,
13098,
12,
13734,
12,
959,
12,
1749,
12,
4119,
12,
10851,
12,
5851,
12,
1520,
12,
267,
4944,
12,
3388,
12,
13734,
12,
1695,
12,
4329,
12,
1749,
12,
413,
12,
17245,
12,
1695,
12,
4944,
12,
5557,
12,
1616,
12,
6546,
12,
17245,
12,
650,
12,
4944,
12,
378,
12,
1520,
12,
3193,
12,
267,
17245,
12,
8087,
12,
4119,
12,
17245,
12,
1616,
12,
6155,
12,
499,
12,
7349,
12,
7349,
12,
1695,
12,
413,
12,
413,
12,
18525,
12,
13734,
12,
19071,
12,
17245,
12,
8155,
12,
3144,
12,
499,
12,
267,
13734,
12,
1695,
12,
4329,
12,
1695,
12,
3144,
12,
5851,
12,
13734,
12,
6546,
12,
4114,
12,
1227,
12,
1616,
12,
499,
12,
7294,
12,
10851,
12,
5851,
12,
1520,
12,
6928,
12,
1695,
12,
7875,
12,
267,
650,
12,
4114,
12,
13734,
12,
3193,
12,
4114,
12,
1616,
12,
10851,
12,
650,
12,
4329,
12,
6928,
12,
3144,
12,
413,
12,
413,
12,
3388,
12,
7294,
12,
15323,
12,
17245,
12,
4329,
12,
1616,
12,
267,
650,
12,
13734,
12,
3193,
12,
4114,
12,
1616,
12,
10851,
12,
650,
12,
4329,
12,
6928,
12,
3144,
12,
413,
12,
413,
12,
3388,
12,
7294,
12,
10851,
12,
841,
12,
4329,
12,
1616,
12,
17245,
12,
267,
413,
12,
413,
12,
5557,
12,
1616,
12,
6928,
12,
17245,
12,
1616,
12,
7294,
12,
5851,
12,
1227,
12,
1616,
12,
378,
12,
7875,
12,
4944,
12,
3388,
12,
1520,
12,
10851,
12,
4329,
12,
8087,
12,
267,
9720,
12,
17245,
12,
17838,
12,
10851,
12,
4337,
12,
378,
12,
378,
12,
17245,
12,
7294,
12,
413,
12,
1749,
12,
8087,
12,
10851,
12,
10416,
12,
378,
12,
3144,
12,
1749,
12,
13734,
12,
3193,
12,
267,
4114,
12,
1616,
12,
10851,
12,
6877,
12,
4329,
12,
3388,
12,
5851,
12,
1227,
12,
6546,
12,
5851,
12,
13734,
12,
20582,
12,
17245,
12,
8087,
12,
4119,
12,
17245,
12,
8087,
12,
413,
12,
267,
4119,
12,
650,
12,
10851,
12,
499,
12,
5661,
12,
413,
12,
7829,
12,
6928,
12,
4119,
12,
1749,
12,
1616,
12,
10851,
12,
1227,
12,
4944,
12,
4119,
12,
6155,
12,
8087,
12,
10851,
12,
5851,
12,
267,
1520,
12,
413,
12,
17245,
12,
650,
12,
4944,
12,
378,
12,
1520,
12,
3193,
12,
17245,
12,
7294,
12,
4119,
12,
17245,
12,
8087,
12,
3144,
12,
1227,
12,
8087,
12,
10851,
12,
499,
12,
5661,
12,
413,
12,
267,
7829,
12,
6928,
12,
4119,
12,
1749,
12,
1616,
12,
10851,
12,
1616,
12,
1227,
12,
650,
12,
4114,
12,
8087,
12,
10851,
12,
959,
12,
1616,
12,
1695,
12,
4329,
12,
1616,
12,
6155,
12,
499,
12,
267,
13734,
12,
1227,
12,
499,
12,
3144,
12,
959,
12,
6155,
12,
7294,
12,
413,
12,
17245,
12,
378,
12,
499,
12,
17245,
12,
1520,
12,
4944,
12,
3388,
12,
13734,
12,
3193,
12,
499,
12,
7294,
12,
3193,
12,
267,
4329,
12,
499,
12,
4119,
12,
1749,
12,
6928,
12,
9720,
12,
17245,
12,
10513,
12,
10851,
12,
10416,
12,
378,
12,
3144,
12,
1749,
12,
13734,
12,
3144,
12,
4329,
12,
499,
12,
6546,
12,
499,
12,
267,
650,
12,
499
] |
[
275,
359,
1965,
12,
8155,
12,
3144,
12,
499,
12,
13734,
12,
8685,
12,
1695,
12,
7294,
12,
3388,
12,
499,
12,
650,
12,
10851,
12,
1695,
12,
1749,
12,
10851,
12,
10416,
12,
378,
12,
3144,
12,
1749,
12,
267,
13296,
12,
10851,
12,
841,
12,
1520,
12,
959,
12,
6546,
12,
8087,
12,
413,
12,
7829,
12,
13734,
12,
16412,
12,
14679,
12,
13734,
12,
16412,
12,
17245,
12,
10448,
12,
1616,
12,
17245,
12,
8087,
12,
267,
3144,
12,
499,
12,
13734,
12,
1227,
12,
499,
12,
1695,
12,
4944,
12,
1749,
12,
413,
12,
4944,
12,
1749,
12,
1695,
12,
10851,
12,
5851,
12,
1520,
12,
413,
12,
17245,
12,
12001,
12,
4119,
12,
7829,
12,
267,
4119,
12,
10851,
12,
1227,
12,
650,
12,
6928,
12,
499,
12,
4329,
12,
378,
12,
4233,
12,
13734,
12,
413,
12,
7105,
12,
1227,
12,
6546,
12,
5851,
12,
1616,
12,
378,
12,
18525,
12,
13734,
12,
267,
10868,
12,
499,
12,
13734,
12,
5851,
12,
1227,
12,
7294,
12,
10851,
12,
3193,
12,
1227,
12,
3193,
12,
4114,
12,
13734,
12,
8685,
12,
1695,
12,
4119,
12,
15323,
12,
17245,
12,
4329,
12,
1616,
12,
267,
650,
12,
13734,
12,
3144,
12,
499,
12,
13734,
12,
5851,
12,
1227,
12,
7294,
12,
10851,
12,
4337,
12,
378,
12,
378,
12,
18525,
12,
13734,
12,
10300,
12,
17245,
12,
10551,
12,
413,
12,
17245,
12,
267,
5504,
12,
959,
12,
3388,
12,
13734,
12,
4944,
12,
1749,
12,
13734,
12,
3193,
12,
4114,
12,
1616,
12,
10851,
12,
959,
12,
1616,
12,
650,
12,
4329,
12,
413,
12,
1616,
12,
4329,
12,
413,
12,
267,
650,
12,
17245,
12,
5504,
12,
4944,
12,
5851,
12,
1520,
12,
10851,
12,
4337,
12,
378,
12,
378,
12,
18525,
12,
13734,
12,
10513,
12,
17245,
12,
10551,
12,
413,
12,
17245,
12,
3144,
12,
6928,
12,
267,
499,
12,
4329,
12,
3193,
12,
499,
12,
4119,
12,
10851,
12,
499,
12,
5661,
12,
413,
12,
7829,
12,
6928,
12,
3193,
12,
4114,
12,
1227,
12,
1616,
12,
378,
12,
13734,
12,
3193,
12,
4114,
12,
267,
1616,
12,
6928,
12,
499,
12,
13734,
12,
4944,
12,
3388,
12,
11738,
12,
10851,
12,
13385,
12,
378,
12,
3193,
12,
4114,
12,
1227,
12,
1616,
12,
378,
12,
13734,
12,
413,
12,
7105,
12,
1227,
12,
267,
6546,
12,
5851,
12,
7294,
12,
10851,
12,
5851,
12,
1520,
12,
959,
12,
5851,
12,
13734,
12,
3144,
12,
499,
12,
13734,
12,
378,
12,
4329,
12,
4119,
12,
1616,
12,
5049,
12,
8087,
12,
10851,
12,
267,
1616,
12,
4329,
12,
4114,
12,
499,
12,
11738,
12,
10851,
12,
20582,
12,
13734,
12,
6335,
12,
4329,
12,
1749,
12,
413,
12,
17245,
12,
1227,
12,
3193,
12,
3388,
12,
1616,
12,
1695,
12,
413,
12,
267,
13734,
12,
5851,
12,
1227,
12,
7294,
12,
10851,
12,
4329,
12,
413,
12,
10851,
12,
4114,
12,
1227,
12,
1749,
12,
13098,
12,
13734,
12,
959,
12,
1749,
12,
4119,
12,
10851,
12,
5851,
12,
1520,
12,
267,
4944,
12,
3388,
12,
13734,
12,
1695,
12,
4329,
12,
1749,
12,
413,
12,
17245,
12,
1695,
12,
4944,
12,
5557,
12,
1616,
12,
6546,
12,
17245,
12,
650,
12,
4944,
12,
378,
12,
1520,
12,
3193,
12,
267,
17245,
12,
8087,
12,
4119,
12,
17245,
12,
1616,
12,
6155,
12,
499,
12,
7349,
12,
7349,
12,
1695,
12,
413,
12,
413,
12,
18525,
12,
13734,
12,
19071,
12,
17245,
12,
8155,
12,
3144,
12,
499,
12,
267,
13734,
12,
1695,
12,
4329,
12,
1695,
12,
3144,
12,
5851,
12,
13734,
12,
6546,
12,
4114,
12,
1227,
12,
1616,
12,
499,
12,
7294,
12,
10851,
12,
5851,
12,
1520,
12,
6928,
12,
1695,
12,
7875,
12,
267,
650,
12,
4114,
12,
13734,
12,
3193,
12,
4114,
12,
1616,
12,
10851,
12,
650,
12,
4329,
12,
6928,
12,
3144,
12,
413,
12,
413,
12,
3388,
12,
7294,
12,
15323,
12,
17245,
12,
4329,
12,
1616,
12,
267,
650,
12,
13734,
12,
3193,
12,
4114,
12,
1616,
12,
10851,
12,
650,
12,
4329,
12,
6928,
12,
3144,
12,
413,
12,
413,
12,
3388,
12,
7294,
12,
10851,
12,
841,
12,
4329,
12,
1616,
12,
17245,
12,
267,
413,
12,
413,
12,
5557,
12,
1616,
12,
6928,
12,
17245,
12,
1616,
12,
7294,
12,
5851,
12,
1227,
12,
1616,
12,
378,
12,
7875,
12,
4944,
12,
3388,
12,
1520,
12,
10851,
12,
4329,
12,
8087,
12,
267,
9720,
12,
17245,
12,
17838,
12,
10851,
12,
4337,
12,
378,
12,
378,
12,
17245,
12,
7294,
12,
413,
12,
1749,
12,
8087,
12,
10851,
12,
10416,
12,
378,
12,
3144,
12,
1749,
12,
13734,
12,
3193,
12,
267,
4114,
12,
1616,
12,
10851,
12,
6877,
12,
4329,
12,
3388,
12,
5851,
12,
1227,
12,
6546,
12,
5851,
12,
13734,
12,
20582,
12,
17245,
12,
8087,
12,
4119,
12,
17245,
12,
8087,
12,
413,
12,
267,
4119,
12,
650,
12,
10851,
12,
499,
12,
5661,
12,
413,
12,
7829,
12,
6928,
12,
4119,
12,
1749,
12,
1616,
12,
10851,
12,
1227,
12,
4944,
12,
4119,
12,
6155,
12,
8087,
12,
10851,
12,
5851,
12,
267,
1520,
12,
413,
12,
17245,
12,
650,
12,
4944,
12,
378,
12,
1520,
12,
3193,
12,
17245,
12,
7294,
12,
4119,
12,
17245,
12,
8087,
12,
3144,
12,
1227,
12,
8087,
12,
10851,
12,
499,
12,
5661,
12,
413,
12,
267,
7829,
12,
6928,
12,
4119,
12,
1749,
12,
1616,
12,
10851,
12,
1616,
12,
1227,
12,
650,
12,
4114,
12,
8087,
12,
10851,
12,
959,
12,
1616,
12,
1695,
12,
4329,
12,
1616,
12,
6155,
12,
499,
12,
267,
13734,
12,
1227,
12,
499,
12,
3144,
12,
959,
12,
6155,
12,
7294,
12,
413,
12,
17245,
12,
378,
12,
499,
12,
17245,
12,
1520,
12,
4944,
12,
3388,
12,
13734,
12,
3193,
12,
499,
12,
7294,
12,
3193,
12,
267,
4329,
12,
499,
12,
4119,
12,
1749,
12,
6928,
12,
9720,
12,
17245,
12,
10513,
12,
10851,
12,
10416,
12,
378,
12,
3144,
12,
1749,
12,
13734,
12,
3144,
12,
4329,
12,
499,
12,
6546,
12,
499,
12,
267,
650,
12,
499,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
HTCKernels/One-SV-international-k2u
|
Documentation/networking/cxacru-cf.py
|
14668
|
1626
|
#!/usr/bin/env python
# Copyright 2009 Simon Arlott
#
# 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.
#
# Usage: cxacru-cf.py < cxacru-cf.bin
# Output: values string suitable for the sysfs adsl_config attribute
#
# Warning: cxacru-cf.bin with MD5 hash cdbac2689969d5ed5d4850f117702110
# contains mis-aligned values which will stop the modem from being able
# to make a connection. If the first and last two bytes are removed then
# the values become valid, but the modulation will be forced to ANSI
# T1.413 only which may not be appropriate.
#
# The original binary format is a packed list of le32 values.
import sys
import struct
i = 0
while True:
buf = sys.stdin.read(4)
if len(buf) == 0:
break
elif len(buf) != 4:
sys.stdout.write("\n")
sys.stderr.write("Error: read {0} not 4 bytes\n".format(len(buf)))
sys.exit(1)
if i > 0:
sys.stdout.write(" ")
sys.stdout.write("{0:x}={1}".format(i, struct.unpack("<I", buf)[0]))
i += 1
sys.stdout.write("\n")
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
8937,
10751,
265,
1952,
1653,
84,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
3,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
199,
3,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
199,
3,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
844,
367,
199,
3,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
8155,
199,
3,
15630,
10902,
446,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
12,
8217,
14,
199,
3,
199,
3,
11028,
26,
286,
10104,
6558,
13,
2177,
14,
647,
665,
286,
10104,
6558,
13,
2177,
14,
1393,
199,
3,
7242,
26,
1338,
1059,
11233,
367,
314,
984,
2319,
282,
795,
76,
63,
888,
2225,
199,
3,
199,
3,
15902,
26,
286,
10104,
6558,
13,
2177,
14,
1393,
543,
15830,
21,
2631,
286,
697,
645,
13731,
1020,
1876,
68,
21,
379,
21,
68,
2006,
1400,
70,
845,
1138,
996,
6019,
199,
3,
3509,
3201,
13,
19175,
1338,
1314,
911,
3631,
314,
818,
77,
687,
3769,
7688,
199,
3,
370,
1852,
282,
1950,
14,
982,
314,
1642,
436,
2061,
2877,
2783,
787,
4829,
2066,
199,
3,
314,
1338,
8649,
1686,
12,
1325,
314,
3413,
5332,
911,
506,
19565,
370,
25600,
199,
3,
377,
17,
14,
23663,
1454,
1314,
1443,
440,
506,
5827,
14,
199,
3,
199,
3,
710,
3379,
3366,
1475,
365,
282,
13170,
769,
402,
1026,
708,
1338,
14,
199,
199,
646,
984,
199,
646,
2702,
199,
199,
73,
275,
378,
199,
6710,
715,
26,
199,
198,
1436,
275,
984,
14,
6626,
14,
739,
8,
20,
9,
421,
198,
692,
822,
8,
1436,
9,
508,
378,
26,
507,
198,
4785,
199,
198,
4164,
822,
8,
1436,
9,
1137,
841,
26,
507,
198,
1274,
14,
2703,
14,
952,
4582,
78,
531,
507,
198,
1274,
14,
3083,
14,
952,
480,
547,
26,
1586,
469,
16,
93,
440,
841,
2783,
60,
78,
1674,
908,
8,
552,
8,
1436,
1724,
507,
198,
1274,
14,
2224,
8,
17,
9,
421,
198,
692,
284,
690,
378,
26,
507,
198,
1274,
14,
2703,
14,
952,
480,
6099,
199,
198,
1274,
14,
2703,
14,
952,
13076,
16,
26,
88,
93,
3126,
17,
5469,
908,
8,
73,
12,
2702,
14,
5301,
6757,
41,
401,
4123,
2788,
16,
2459,
199,
198,
73,
847,
413,
199,
199,
1274,
14,
2703,
14,
952,
4582,
78,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
8937,
10751,
265,
1952,
1653,
84,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
3,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
199,
3,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
199,
3,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
844,
367,
199,
3,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
8155,
199,
3,
15630,
10902,
446,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
12,
8217,
14,
199,
3,
199,
3,
11028,
26,
286,
10104,
6558,
13,
2177,
14,
647,
665,
286,
10104,
6558,
13,
2177,
14,
1393,
199,
3,
7242,
26,
1338,
1059,
11233,
367,
314,
984,
2319,
282,
795,
76,
63,
888,
2225,
199,
3,
199,
3,
15902,
26,
286,
10104,
6558,
13,
2177,
14,
1393,
543,
15830,
21,
2631,
286,
697,
645,
13731,
1020,
1876,
68,
21,
379,
21,
68,
2006,
1400,
70,
845,
1138,
996,
6019,
199,
3,
3509,
3201,
13,
19175,
1338,
1314,
911,
3631,
314,
818,
77,
687,
3769,
7688,
199,
3,
370,
1852,
282,
1950,
14,
982,
314,
1642,
436,
2061,
2877,
2783,
787,
4829,
2066,
199,
3,
314,
1338,
8649,
1686,
12,
1325,
314,
3413,
5332,
911,
506,
19565,
370,
25600,
199,
3,
377,
17,
14,
23663,
1454,
1314,
1443,
440,
506,
5827,
14,
199,
3,
199,
3,
710,
3379,
3366,
1475,
365,
282,
13170,
769,
402,
1026,
708,
1338,
14,
199,
199,
646,
984,
199,
646,
2702,
199,
199,
73,
275,
378,
199,
6710,
715,
26,
199,
198,
1436,
275,
984,
14,
6626,
14,
739,
8,
20,
9,
421,
198,
692,
822,
8,
1436,
9,
508,
378,
26,
507,
198,
4785,
199,
198,
4164,
822,
8,
1436,
9,
1137,
841,
26,
507,
198,
1274,
14,
2703,
14,
952,
4582,
78,
531,
507,
198,
1274,
14,
3083,
14,
952,
480,
547,
26,
1586,
469,
16,
93,
440,
841,
2783,
60,
78,
1674,
908,
8,
552,
8,
1436,
1724,
507,
198,
1274,
14,
2224,
8,
17,
9,
421,
198,
692,
284,
690,
378,
26,
507,
198,
1274,
14,
2703,
14,
952,
480,
6099,
199,
198,
1274,
14,
2703,
14,
952,
13076,
16,
26,
88,
93,
3126,
17,
5469,
908,
8,
73,
12,
2702,
14,
5301,
6757,
41,
401,
4123,
2788,
16,
2459,
199,
198,
73,
847,
413,
199,
199,
1274,
14,
2703,
14,
952,
4582,
78,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
splotz90/urh
|
src/urh/models/PluginListModel.py
|
1
|
1635
|
from PyQt5.QtCore import QAbstractListModel, Qt, QModelIndex
from PyQt5.QtGui import QFont
from urh import constants
from urh.plugins import Plugin
class PluginListModel(QAbstractListModel):
def __init__(self, plugins, highlighted_plugins = None, parent=None):
"""
:type plugins: list of Plugin
:type highlighted_plugins: list of Plugin
"""
super().__init__(parent)
self.plugins = plugins
self.highlighted_plugins = highlighted_plugins if highlighted_plugins is not None else []
def rowCount(self, QModelIndex_parent=None, *args, **kwargs):
return len(self.plugins)
def data(self, index: QModelIndex, role=None):
row = index.row()
if role == Qt.DisplayRole:
return self.plugins[row].name
elif role == Qt.CheckStateRole:
return self.plugins[row].enabled
elif role == Qt.TextColorRole and self.plugins[row] in self.highlighted_plugins:
return constants.HIGHLIGHT_TEXT_FOREGROUND_COLOR
elif role == Qt.BackgroundColorRole and self.plugins[row] in self.highlighted_plugins:
return constants.HIGHLIGHT_TEXT_BACKGROUND_COLOR
elif role == Qt.FontRole and self.plugins[row] in self.highlighted_plugins:
font = QFont()
font.setBold(True)
return font
def setData(self, index: QModelIndex, value, role=None):
if role == Qt.CheckStateRole:
self.plugins[index.row()].enabled = value
return True
def flags(self, index):
return Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsUserCheckable
|
gpl-3.0
|
[
504,
14084,
21,
14,
10901,
492,
1413,
8458,
1296,
1685,
12,
3959,
12,
1413,
1685,
2681,
199,
504,
14084,
21,
14,
10604,
492,
1413,
6986,
199,
199,
504,
7629,
72,
492,
5262,
199,
504,
7629,
72,
14,
5265,
492,
11349,
421,
199,
533,
11349,
1296,
1685,
8,
49,
8458,
1296,
1685,
304,
272,
347,
636,
826,
721,
277,
12,
8963,
12,
4721,
27883,
63,
5265,
275,
488,
12,
1676,
29,
403,
304,
267,
408,
267,
520,
466,
8963,
26,
769,
402,
11349,
267,
520,
466,
4721,
27883,
63,
5265,
26,
769,
402,
11349,
267,
408,
267,
1613,
11027,
826,
721,
1708,
9,
267,
291,
14,
5265,
275,
8963,
267,
291,
14,
6260,
27883,
63,
5265,
275,
4721,
27883,
63,
5265,
340,
4721,
27883,
63,
5265,
365,
440,
488,
587,
942,
339,
347,
1962,
2353,
8,
277,
12,
1413,
1685,
2681,
63,
1708,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
267,
372,
822,
8,
277,
14,
5265,
9,
339,
347,
666,
8,
277,
12,
1478,
26,
1413,
1685,
2681,
12,
4719,
29,
403,
304,
267,
1962,
275,
1478,
14,
1143,
342,
267,
340,
4719,
508,
3959,
14,
7687,
7422,
26,
288,
372,
291,
14,
5265,
59,
1143,
1055,
354,
267,
916,
4719,
508,
3959,
14,
1799,
2223,
7422,
26,
288,
372,
291,
14,
5265,
59,
1143,
1055,
3827,
267,
916,
4719,
508,
3959,
14,
1872,
4117,
7422,
436,
291,
14,
5265,
59,
1143,
61,
315,
291,
14,
6260,
27883,
63,
5265,
26,
288,
372,
5262,
14,
17624,
21613,
63,
3876,
63,
2707,
4680,
16848,
63,
7134,
267,
916,
4719,
508,
3959,
14,
14148,
4117,
7422,
436,
291,
14,
5265,
59,
1143,
61,
315,
291,
14,
6260,
27883,
63,
5265,
26,
288,
372,
5262,
14,
17624,
21613,
63,
3876,
63,
7111,
29497,
63,
7134,
267,
916,
4719,
508,
3959,
14,
6986,
7422,
436,
291,
14,
5265,
59,
1143,
61,
315,
291,
14,
6260,
27883,
63,
5265,
26,
288,
5023,
275,
1413,
6986,
342,
288,
5023,
14,
409,
26395,
8,
549,
9,
288,
372,
5023,
339,
347,
663,
1451,
8,
277,
12,
1478,
26,
1413,
1685,
2681,
12,
574,
12,
4719,
29,
403,
304,
267,
340,
4719,
508,
3959,
14,
1799,
2223,
7422,
26,
288,
291,
14,
5265,
59,
1080,
14,
1143,
342,
1055,
3827,
275,
574,
267,
372,
715,
339,
347,
3285,
8,
277,
12,
1478,
304,
267,
372,
3959,
14,
2081,
1831,
6589,
1204,
3959,
14,
2081,
1831,
5446,
461,
1204,
3959,
14,
2081,
1831,
1899,
1799,
461,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
14084,
21,
14,
10901,
492,
1413,
8458,
1296,
1685,
12,
3959,
12,
1413,
1685,
2681,
199,
504,
14084,
21,
14,
10604,
492,
1413,
6986,
199,
199,
504,
7629,
72,
492,
5262,
199,
504,
7629,
72,
14,
5265,
492,
11349,
421,
199,
533,
11349,
1296,
1685,
8,
49,
8458,
1296,
1685,
304,
272,
347,
636,
826,
721,
277,
12,
8963,
12,
4721,
27883,
63,
5265,
275,
488,
12,
1676,
29,
403,
304,
267,
408,
267,
520,
466,
8963,
26,
769,
402,
11349,
267,
520,
466,
4721,
27883,
63,
5265,
26,
769,
402,
11349,
267,
408,
267,
1613,
11027,
826,
721,
1708,
9,
267,
291,
14,
5265,
275,
8963,
267,
291,
14,
6260,
27883,
63,
5265,
275,
4721,
27883,
63,
5265,
340,
4721,
27883,
63,
5265,
365,
440,
488,
587,
942,
339,
347,
1962,
2353,
8,
277,
12,
1413,
1685,
2681,
63,
1708,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
267,
372,
822,
8,
277,
14,
5265,
9,
339,
347,
666,
8,
277,
12,
1478,
26,
1413,
1685,
2681,
12,
4719,
29,
403,
304,
267,
1962,
275,
1478,
14,
1143,
342,
267,
340,
4719,
508,
3959,
14,
7687,
7422,
26,
288,
372,
291,
14,
5265,
59,
1143,
1055,
354,
267,
916,
4719,
508,
3959,
14,
1799,
2223,
7422,
26,
288,
372,
291,
14,
5265,
59,
1143,
1055,
3827,
267,
916,
4719,
508,
3959,
14,
1872,
4117,
7422,
436,
291,
14,
5265,
59,
1143,
61,
315,
291,
14,
6260,
27883,
63,
5265,
26,
288,
372,
5262,
14,
17624,
21613,
63,
3876,
63,
2707,
4680,
16848,
63,
7134,
267,
916,
4719,
508,
3959,
14,
14148,
4117,
7422,
436,
291,
14,
5265,
59,
1143,
61,
315,
291,
14,
6260,
27883,
63,
5265,
26,
288,
372,
5262,
14,
17624,
21613,
63,
3876,
63,
7111,
29497,
63,
7134,
267,
916,
4719,
508,
3959,
14,
6986,
7422,
436,
291,
14,
5265,
59,
1143,
61,
315,
291,
14,
6260,
27883,
63,
5265,
26,
288,
5023,
275,
1413,
6986,
342,
288,
5023,
14,
409,
26395,
8,
549,
9,
288,
372,
5023,
339,
347,
663,
1451,
8,
277,
12,
1478,
26,
1413,
1685,
2681,
12,
574,
12,
4719,
29,
403,
304,
267,
340,
4719,
508,
3959,
14,
1799,
2223,
7422,
26,
288,
291,
14,
5265,
59,
1080,
14,
1143,
342,
1055,
3827,
275,
574,
267,
372,
715,
339,
347,
3285,
8,
277,
12,
1478,
304,
267,
372,
3959,
14,
2081,
1831,
6589,
1204,
3959,
14,
2081,
1831,
5446,
461,
1204,
3959,
14,
2081,
1831,
1899,
1799,
461,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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|
import os
import jinja2
import webapp2
"""
For Unit testing:
https://cloud.google.com/appengine/docs/python/tools/handlertesting
"""
JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'],
autoescape=True)
def prep_template_values():
template_values = {
}
return template_values
class MainHandler(webapp2.RequestHandler):
def get(self):
template_values = prep_template_values()
template = JINJA_ENVIRONMENT.get_template('views/index.html')
self.response.write(template.render(template_values))
class PresentationsHandler(webapp2.RequestHandler):
def get(self):
template_values = prep_template_values()
template = JINJA_ENVIRONMENT.get_template('views/presentations.html')
self.response.write(template.render(template_values))
class ContactHandler(webapp2.RequestHandler):
def get(self):
template_values = prep_template_values()
template = JINJA_ENVIRONMENT.get_template('views/contact.html')
self.response.write(template.render(template_values))
app = webapp2.WSGIApplication([
('/', MainHandler),
('/presentations/', PresentationsHandler),
('/contact/', ContactHandler)
], debug=False)
|
mit
|
[
646,
747,
199,
646,
10321,
18,
199,
646,
24812,
18,
199,
199,
624,
199,
1858,
12008,
5343,
26,
199,
2859,
921,
4091,
14,
3098,
14,
957,
15,
15358,
15,
4757,
15,
1548,
15,
2537,
15,
2232,
4776,
199,
624,
421,
199,
42,
568,
29849,
63,
9984,
31168,
4479,
275,
10321,
18,
14,
8263,
8,
272,
5077,
29,
12264,
18,
14,
17521,
5455,
8,
736,
14,
515,
14,
3475,
3460,
493,
22159,
272,
5478,
2968,
12264,
18,
14,
832,
14,
15818,
995,
272,
19102,
29,
549,
9,
199,
199,
318,
19986,
63,
1160,
63,
1459,
837,
5493,
1978,
63,
1459,
275,
469,
272,
789,
272,
372,
1978,
63,
1459,
258,
2043,
199,
199,
533,
11298,
2461,
8,
22632,
18,
14,
11149,
304,
272,
347,
664,
8,
277,
304,
2728,
1978,
63,
1459,
275,
19986,
63,
1160,
63,
1459,
342,
267,
1978,
275,
1603,
568,
29849,
63,
9984,
31168,
4479,
14,
362,
63,
1160,
360,
4196,
15,
1080,
14,
1360,
358,
267,
291,
14,
1310,
14,
952,
8,
1160,
14,
3352,
8,
1160,
63,
1459,
430,
199,
199,
533,
5543,
1150,
1298,
2461,
8,
22632,
18,
14,
11149,
304,
272,
347,
664,
8,
277,
304,
2728,
1978,
63,
1459,
275,
19986,
63,
1160,
63,
1459,
342,
267,
1978,
275,
1603,
568,
29849,
63,
9984,
31168,
4479,
14,
362,
63,
1160,
360,
4196,
15,
1881,
1298,
14,
1360,
358,
267,
291,
14,
1310,
14,
952,
8,
1160,
14,
3352,
8,
1160,
63,
1459,
430,
199,
199,
533,
18684,
2461,
8,
22632,
18,
14,
11149,
304,
272,
347,
664,
8,
277,
304,
2728,
1978,
63,
1459,
275,
19986,
63,
1160,
63,
1459,
342,
267,
1978,
275,
1603,
568,
29849,
63,
9984,
31168,
4479,
14,
362,
63,
1160,
360,
4196,
15,
7811,
14,
1360,
358,
267,
291,
14,
1310,
14,
952,
8,
1160,
14,
3352,
8,
1160,
63,
1459,
430,
13359,
199,
571,
275,
24812,
18,
14,
16828,
5039,
779,
272,
661,
3678,
11298,
2461,
395,
272,
14606,
1881,
1298,
3678,
5543,
1150,
1298,
2461,
395,
272,
14606,
7811,
3678,
18684,
2461,
9,
199,
467,
3105,
29,
797,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
747,
199,
646,
10321,
18,
199,
646,
24812,
18,
199,
199,
624,
199,
1858,
12008,
5343,
26,
199,
2859,
921,
4091,
14,
3098,
14,
957,
15,
15358,
15,
4757,
15,
1548,
15,
2537,
15,
2232,
4776,
199,
624,
421,
199,
42,
568,
29849,
63,
9984,
31168,
4479,
275,
10321,
18,
14,
8263,
8,
272,
5077,
29,
12264,
18,
14,
17521,
5455,
8,
736,
14,
515,
14,
3475,
3460,
493,
22159,
272,
5478,
2968,
12264,
18,
14,
832,
14,
15818,
995,
272,
19102,
29,
549,
9,
199,
199,
318,
19986,
63,
1160,
63,
1459,
837,
5493,
1978,
63,
1459,
275,
469,
272,
789,
272,
372,
1978,
63,
1459,
258,
2043,
199,
199,
533,
11298,
2461,
8,
22632,
18,
14,
11149,
304,
272,
347,
664,
8,
277,
304,
2728,
1978,
63,
1459,
275,
19986,
63,
1160,
63,
1459,
342,
267,
1978,
275,
1603,
568,
29849,
63,
9984,
31168,
4479,
14,
362,
63,
1160,
360,
4196,
15,
1080,
14,
1360,
358,
267,
291,
14,
1310,
14,
952,
8,
1160,
14,
3352,
8,
1160,
63,
1459,
430,
199,
199,
533,
5543,
1150,
1298,
2461,
8,
22632,
18,
14,
11149,
304,
272,
347,
664,
8,
277,
304,
2728,
1978,
63,
1459,
275,
19986,
63,
1160,
63,
1459,
342,
267,
1978,
275,
1603,
568,
29849,
63,
9984,
31168,
4479,
14,
362,
63,
1160,
360,
4196,
15,
1881,
1298,
14,
1360,
358,
267,
291,
14,
1310,
14,
952,
8,
1160,
14,
3352,
8,
1160,
63,
1459,
430,
199,
199,
533,
18684,
2461,
8,
22632,
18,
14,
11149,
304,
272,
347,
664,
8,
277,
304,
2728,
1978,
63,
1459,
275,
19986,
63,
1160,
63,
1459,
342,
267,
1978,
275,
1603,
568,
29849,
63,
9984,
31168,
4479,
14,
362,
63,
1160,
360,
4196,
15,
7811,
14,
1360,
358,
267,
291,
14,
1310,
14,
952,
8,
1160,
14,
3352,
8,
1160,
63,
1459,
430,
13359,
199,
571,
275,
24812,
18,
14,
16828,
5039,
779,
272,
661,
3678,
11298,
2461,
395,
272,
14606,
1881,
1298,
3678,
5543,
1150,
1298,
2461,
395,
272,
14606,
7811,
3678,
18684,
2461,
9,
199,
467,
3105,
29,
797,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
vesellov/bitdust.devel
|
services/service_my_ip_port.py
|
1
|
1681
|
#!/usr/bin/python
# service_my_ip_port.py
#
# Copyright (C) 2008-2018 Veselin Penev, https://bitdust.io
#
# This file (service_my_ip_port.py) is part of BitDust Software.
#
# BitDust 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.
#
# BitDust Software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with BitDust Software. If not, see <http://www.gnu.org/licenses/>.
#
# Please contact us if you have any questions at bitdust.io@gmail.com
#
#
#
#
"""
..
module:: service_my_ip_port
"""
from __future__ import absolute_import
from services.local_service import LocalService
def create_service():
return MyIPPortService()
class MyIPPortService(LocalService):
service_name = 'service_my_ip_port'
config_path = 'services/my-ip-port/enabled'
def init(self):
self._my_address = None
def dependent_on(self):
return ['service_entangled_dht',
'service_udp_datagrams',
]
def start(self):
from stun import stun_client
from main import settings
stun_client.A('init', settings.getUDPPort())
return True
def stop(self):
from stun import stun_client
stun_client.A('shutdown')
return True
|
agpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
2435,
63,
1662,
63,
711,
63,
719,
14,
647,
199,
3,
199,
3,
1898,
334,
35,
9,
9079,
13,
12682,
25777,
261,
472,
510,
6349,
86,
12,
4178,
921,
2075,
68,
833,
14,
2308,
199,
3,
199,
3,
961,
570,
334,
1364,
63,
1662,
63,
711,
63,
719,
14,
647,
9,
365,
1777,
402,
10199,
36,
833,
2290,
14,
199,
3,
199,
3,
10199,
36,
833,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
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,
10199,
36,
833,
2290,
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,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
10199,
36,
833,
2290,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
7754,
8966,
2739,
340,
1265,
1172,
1263,
23071,
737,
4546,
68,
833,
14,
2308,
32,
6799,
14,
957,
199,
3,
199,
3,
199,
3,
199,
3,
199,
199,
624,
199,
703,
199,
199,
578,
447,
2435,
63,
1662,
63,
711,
63,
719,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
8500,
14,
1832,
63,
1364,
492,
10111,
3167,
421,
199,
318,
1218,
63,
1364,
837,
272,
372,
4932,
1772,
4313,
3167,
342,
421,
199,
533,
4932,
1772,
4313,
3167,
8,
5339,
3167,
304,
339,
2435,
63,
354,
275,
283,
1364,
63,
1662,
63,
711,
63,
719,
7,
272,
1101,
63,
515,
275,
283,
5950,
15,
1662,
13,
711,
13,
719,
15,
3827,
7,
339,
347,
4205,
8,
277,
304,
267,
291,
423,
1662,
63,
1562,
275,
488,
339,
347,
11410,
63,
265,
8,
277,
304,
267,
372,
788,
1364,
63,
484,
22183,
63,
68,
517,
297,
355,
283,
1364,
63,
15036,
63,
576,
9292,
297,
355,
1622,
339,
347,
1343,
8,
277,
304,
267,
687,
410,
324,
492,
410,
324,
63,
1258,
267,
687,
2446,
492,
2202,
267,
410,
324,
63,
1258,
14,
33,
360,
826,
297,
2202,
14,
362,
17457,
4313,
1012,
267,
372,
715,
339,
347,
3631,
8,
277,
304,
267,
687,
410,
324,
492,
410,
324,
63,
1258,
267,
410,
324,
63,
1258,
14,
33,
360,
8831,
358,
267,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
2435,
63,
1662,
63,
711,
63,
719,
14,
647,
199,
3,
199,
3,
1898,
334,
35,
9,
9079,
13,
12682,
25777,
261,
472,
510,
6349,
86,
12,
4178,
921,
2075,
68,
833,
14,
2308,
199,
3,
199,
3,
961,
570,
334,
1364,
63,
1662,
63,
711,
63,
719,
14,
647,
9,
365,
1777,
402,
10199,
36,
833,
2290,
14,
199,
3,
199,
3,
10199,
36,
833,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
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,
10199,
36,
833,
2290,
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,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
10199,
36,
833,
2290,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
7754,
8966,
2739,
340,
1265,
1172,
1263,
23071,
737,
4546,
68,
833,
14,
2308,
32,
6799,
14,
957,
199,
3,
199,
3,
199,
3,
199,
3,
199,
199,
624,
199,
703,
199,
199,
578,
447,
2435,
63,
1662,
63,
711,
63,
719,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
8500,
14,
1832,
63,
1364,
492,
10111,
3167,
421,
199,
318,
1218,
63,
1364,
837,
272,
372,
4932,
1772,
4313,
3167,
342,
421,
199,
533,
4932,
1772,
4313,
3167,
8,
5339,
3167,
304,
339,
2435,
63,
354,
275,
283,
1364,
63,
1662,
63,
711,
63,
719,
7,
272,
1101,
63,
515,
275,
283,
5950,
15,
1662,
13,
711,
13,
719,
15,
3827,
7,
339,
347,
4205,
8,
277,
304,
267,
291,
423,
1662,
63,
1562,
275,
488,
339,
347,
11410,
63,
265,
8,
277,
304,
267,
372,
788,
1364,
63,
484,
22183,
63,
68,
517,
297,
355,
283,
1364,
63,
15036,
63,
576,
9292,
297,
355,
1622,
339,
347,
1343,
8,
277,
304,
267,
687,
410,
324,
492,
410,
324,
63,
1258,
267,
687,
2446,
492,
2202,
267,
410,
324,
63,
1258,
14,
33,
360,
826,
297,
2202,
14,
362,
17457,
4313,
1012,
267,
372,
715,
339,
347,
3631,
8,
277,
304,
267,
687,
410,
324,
492,
410,
324,
63,
1258,
267,
410,
324,
63,
1258,
14,
33,
360,
8831,
358,
267,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
lliendo/PyZ80
|
pyz80/tests/test_cpu.py
|
1
|
1256
|
# -*- coding: utf-8 -*-
"""
This file is part of PyZ80.
PyZ80 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.
PyZ80 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
Lesser GNU General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with PyZ80. If not, see <http://www.gnu.org/licenses/>.
Copyright 2014 Lucas Liendo.
"""
from unittest import TestCase
from ..cpu import Z80
class TestZ80(TestCase):
def setUp(self):
self._z80 = Z80()
def test_8_bit_register_properties(self):
registers = [
'a', 'b', 'c', 'd', 'e', 'f', 'h', 'l',
'i', 'r', 'ixl', 'ixh', 'iyl', 'iyh'
]
[self.assertTrue(hasattr(self._z80, r)) for r in registers]
def test_16_bit_register_properties(self):
registers = ['bc', 'de', 'hl', 'sp', 'pc', 'ix', 'iy']
[self.assertTrue(hasattr(self._z80, r)) for r in registers]
|
lgpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
2765,
570,
365,
1777,
402,
1611,
58,
1257,
14,
199,
199,
2713,
58,
1257,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
2713,
58,
1257,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
44,
6350,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
6401,
1664,
1696,
1684,
844,
199,
21632,
543,
1611,
58,
1257,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
7384,
6927,
491,
947,
305,
24157,
500,
79,
14,
199,
624,
199,
199,
504,
2882,
492,
7640,
199,
504,
2508,
3541,
492,
3107,
1257,
421,
199,
533,
1379,
58,
1257,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
423,
90,
1257,
275,
3107,
1257,
342,
339,
347,
511,
63,
24,
63,
2075,
63,
2683,
63,
3282,
8,
277,
304,
267,
24493,
275,
359,
288,
283,
65,
297,
283,
66,
297,
283,
67,
297,
283,
68,
297,
283,
69,
297,
283,
70,
297,
283,
72,
297,
283,
76,
297,
288,
283,
73,
297,
283,
82,
297,
283,
1148,
76,
297,
283,
1148,
72,
297,
283,
31256,
76,
297,
283,
31256,
72,
7,
267,
1622,
267,
359,
277,
14,
1815,
8,
11161,
8,
277,
423,
90,
1257,
12,
519,
430,
367,
519,
315,
24493,
61,
339,
347,
511,
63,
975,
63,
2075,
63,
2683,
63,
3282,
8,
277,
304,
267,
24493,
275,
788,
3776,
297,
283,
271,
297,
283,
15544,
297,
283,
681,
297,
283,
2352,
297,
283,
1148,
297,
283,
31256,
418,
267,
359,
277,
14,
1815,
8,
11161,
8,
277,
423,
90,
1257,
12,
519,
430,
367,
519,
315,
24493,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
2765,
570,
365,
1777,
402,
1611,
58,
1257,
14,
199,
199,
2713,
58,
1257,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
2713,
58,
1257,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
44,
6350,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
6401,
1664,
1696,
1684,
844,
199,
21632,
543,
1611,
58,
1257,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
7384,
6927,
491,
947,
305,
24157,
500,
79,
14,
199,
624,
199,
199,
504,
2882,
492,
7640,
199,
504,
2508,
3541,
492,
3107,
1257,
421,
199,
533,
1379,
58,
1257,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
423,
90,
1257,
275,
3107,
1257,
342,
339,
347,
511,
63,
24,
63,
2075,
63,
2683,
63,
3282,
8,
277,
304,
267,
24493,
275,
359,
288,
283,
65,
297,
283,
66,
297,
283,
67,
297,
283,
68,
297,
283,
69,
297,
283,
70,
297,
283,
72,
297,
283,
76,
297,
288,
283,
73,
297,
283,
82,
297,
283,
1148,
76,
297,
283,
1148,
72,
297,
283,
31256,
76,
297,
283,
31256,
72,
7,
267,
1622,
267,
359,
277,
14,
1815,
8,
11161,
8,
277,
423,
90,
1257,
12,
519,
430,
367,
519,
315,
24493,
61,
339,
347,
511,
63,
975,
63,
2075,
63,
2683,
63,
3282,
8,
277,
304,
267,
24493,
275,
788,
3776,
297,
283,
271,
297,
283,
15544,
297,
283,
681,
297,
283,
2352,
297,
283,
1148,
297,
283,
31256,
418,
267,
359,
277,
14,
1815,
8,
11161,
8,
277,
423,
90,
1257,
12,
519,
430,
367,
519,
315,
24493,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
dangillet/cocos
|
tools/view_skeleton.py
|
6
|
1215
|
from __future__ import division, print_function, unicode_literals
# This code is so you can run the samples without installing the package
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
#
import imp
## import all the stuff we need from cocos
import cocos
from cocos.director import director
from cocos.sprite import Sprite
class TestLayer(cocos.layer.Layer):
def __init__(self):
super( TestLayer, self ).__init__()
x,y = director.get_window_size()
# create a ColorSkin for our skeleton
sk_file = imp.load_source("user_skeleton", sys.argv[1])
self.skin = cocos.skeleton.ColorSkin(sk_file.skeleton,
(255,0,0,255))
# add the skin to the scene
self.add( self.skin )
x, y = director.get_window_size()
self.skin.position = x // 2, y // 2
if __name__ == "__main__":
# usual cocos setup
director.init()
test_layer = TestLayer()
bg_layer = cocos.layer.ColorLayer(255,255,255,255)
main_scene = cocos.scene.Scene()
main_scene.add(bg_layer, z=-10)
main_scene.add(test_layer, z=10)
director.run(main_scene)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
3,
961,
1233,
365,
880,
1265,
883,
1255,
314,
5845,
1928,
22200,
314,
2559,
199,
646,
984,
199,
646,
747,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
11541,
1333,
199,
3,
199,
199,
646,
1742,
199,
199,
309,
492,
1006,
314,
8292,
781,
1929,
687,
512,
5197,
199,
646,
512,
5197,
199,
504,
512,
5197,
14,
24712,
492,
487,
14521,
199,
504,
512,
5197,
14,
15972,
492,
8360,
752,
421,
199,
533,
1379,
5003,
8,
331,
5197,
14,
1897,
14,
5003,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
1379,
5003,
12,
291,
221,
2843,
826,
4533,
398,
671,
12,
89,
275,
487,
14521,
14,
362,
63,
3806,
63,
890,
342,
2728,
327,
1218,
282,
11581,
14194,
262,
367,
4154,
30537,
267,
2386,
63,
493,
275,
1742,
14,
912,
63,
1365,
480,
751,
63,
29250,
401,
984,
14,
3020,
59,
17,
566,
267,
291,
14,
16409,
275,
512,
5197,
14,
29250,
14,
4117,
14194,
262,
8,
1339,
63,
493,
14,
29250,
12,
3147,
334,
2299,
12,
16,
12,
16,
12,
2299,
430,
2728,
327,
1050,
314,
28337,
370,
314,
13856,
267,
291,
14,
525,
8,
291,
14,
16409,
776,
267,
671,
12,
612,
275,
487,
14521,
14,
362,
63,
3806,
63,
890,
342,
267,
291,
14,
16409,
14,
3124,
275,
671,
5001,
499,
12,
612,
5001,
499,
272,
1362,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
327,
20195,
512,
5197,
3272,
272,
487,
14521,
14,
826,
342,
272,
511,
63,
1897,
275,
1379,
5003,
342,
272,
12994,
63,
1897,
275,
512,
5197,
14,
1897,
14,
4117,
5003,
8,
2299,
12,
2299,
12,
2299,
12,
2299,
9,
272,
2446,
63,
10436,
275,
512,
5197,
14,
10436,
14,
14216,
342,
272,
2446,
63,
10436,
14,
525,
8,
6856,
63,
1897,
12,
1315,
4022,
709,
9,
272,
2446,
63,
10436,
14,
525,
8,
396,
63,
1897,
12,
1315,
29,
709,
9,
272,
487,
14521,
14,
1065,
8,
973,
63,
10436,
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
] |
[
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
3,
961,
1233,
365,
880,
1265,
883,
1255,
314,
5845,
1928,
22200,
314,
2559,
199,
646,
984,
199,
646,
747,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
11541,
1333,
199,
3,
199,
199,
646,
1742,
199,
199,
309,
492,
1006,
314,
8292,
781,
1929,
687,
512,
5197,
199,
646,
512,
5197,
199,
504,
512,
5197,
14,
24712,
492,
487,
14521,
199,
504,
512,
5197,
14,
15972,
492,
8360,
752,
421,
199,
533,
1379,
5003,
8,
331,
5197,
14,
1897,
14,
5003,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
1379,
5003,
12,
291,
221,
2843,
826,
4533,
398,
671,
12,
89,
275,
487,
14521,
14,
362,
63,
3806,
63,
890,
342,
2728,
327,
1218,
282,
11581,
14194,
262,
367,
4154,
30537,
267,
2386,
63,
493,
275,
1742,
14,
912,
63,
1365,
480,
751,
63,
29250,
401,
984,
14,
3020,
59,
17,
566,
267,
291,
14,
16409,
275,
512,
5197,
14,
29250,
14,
4117,
14194,
262,
8,
1339,
63,
493,
14,
29250,
12,
3147,
334,
2299,
12,
16,
12,
16,
12,
2299,
430,
2728,
327,
1050,
314,
28337,
370,
314,
13856,
267,
291,
14,
525,
8,
291,
14,
16409,
776,
267,
671,
12,
612,
275,
487,
14521,
14,
362,
63,
3806,
63,
890,
342,
267,
291,
14,
16409,
14,
3124,
275,
671,
5001,
499,
12,
612,
5001,
499,
272,
1362,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
327,
20195,
512,
5197,
3272,
272,
487,
14521,
14,
826,
342,
272,
511,
63,
1897,
275,
1379,
5003,
342,
272,
12994,
63,
1897,
275,
512,
5197,
14,
1897,
14,
4117,
5003,
8,
2299,
12,
2299,
12,
2299,
12,
2299,
9,
272,
2446,
63,
10436,
275,
512,
5197,
14,
10436,
14,
14216,
342,
272,
2446,
63,
10436,
14,
525,
8,
6856,
63,
1897,
12,
1315,
4022,
709,
9,
272,
2446,
63,
10436,
14,
525,
8,
396,
63,
1897,
12,
1315,
29,
709,
9,
272,
487,
14521,
14,
1065,
8,
973,
63,
10436,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Alexanau/table
|
table.py
|
1
|
1041
|
#!/usr/bin/python
import getopt as g
import sys
optlist, args = g.getopt(sys.argv[1:],'d:')
delim = ','
for o,a in optlist:
if o == '-d':
delim = a
max_width = [0]
with open(args[0],'r') as fh:
for line in fh:
line = line.rstrip()
fields = line.split(delim)
for idx,field in enumerate(fields):
field = field.strip()
if len(max_width) <= idx :
max_width.append(len(field))
elif max_width[idx] < len(field):
max_width[idx] = len(field)
lb = ['']
for width in max_width:
lb.append('-'*(width+2))
lb.append('')
linebreak = '+'.join(lb)
fh.seek(0,0)
print linebreak
for line in fh:
line = line.rstrip()
fields = line.split(delim)
out = ['']
for idx,width in enumerate(max_width):
if(len(fields)<=idx):
out .append( '| ' + ' '*width + ' ')
else:
field = fields[idx].strip()
out .append( '| '+field + ' '*(width-len(field)) + ' ')
out.append( '|')
print ''.join(out)
print linebreak
field = field.strip()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
646,
12733,
465,
486,
199,
646,
984,
199,
199,
2992,
513,
12,
1249,
275,
486,
14,
18907,
8,
1274,
14,
3020,
59,
17,
8429,
7,
68,
10993,
199,
15966,
275,
13647,
199,
509,
312,
12,
65,
315,
2450,
513,
26,
523,
340,
312,
508,
2475,
68,
356,
272,
21799,
275,
282,
199,
199,
988,
63,
2063,
275,
359,
16,
61,
199,
199,
1045,
1551,
8,
589,
59,
16,
26801,
82,
358,
465,
11155,
26,
523,
367,
1004,
315,
11155,
26,
272,
1004,
275,
1004,
14,
6735,
342,
272,
1504,
275,
1004,
14,
1294,
8,
15966,
9,
272,
367,
4280,
12,
698,
315,
3874,
8,
955,
304,
489,
901,
275,
901,
14,
1913,
342,
489,
340,
822,
8,
988,
63,
2063,
9,
2695,
4280,
520,
267,
1390,
63,
2063,
14,
740,
8,
552,
8,
698,
430,
489,
916,
1390,
63,
2063,
59,
2996,
61,
665,
822,
8,
698,
304,
267,
1390,
63,
2063,
59,
2996,
61,
275,
822,
8,
698,
9,
819,
11104,
275,
24506,
523,
367,
3462,
315,
1390,
63,
2063,
26,
272,
11104,
14,
740,
3654,
7,
5830,
2063,
11,
18,
430,
523,
11104,
14,
740,
8355,
523,
1004,
4785,
275,
6681,
1370,
904,
8,
6374,
9,
523,
11155,
14,
5507,
8,
16,
12,
16,
9,
523,
870,
1004,
4785,
523,
367,
1004,
315,
11155,
26,
272,
1004,
275,
1004,
14,
6735,
342,
272,
1504,
275,
1004,
14,
1294,
8,
15966,
9,
272,
734,
275,
24506,
272,
367,
4280,
12,
2063,
315,
3874,
8,
988,
63,
2063,
304,
489,
340,
8,
552,
8,
955,
9,
12932,
2996,
304,
267,
734,
1275,
740,
8,
11280,
283,
435,
283,
6438,
2063,
435,
283,
5320,
489,
587,
26,
267,
901,
275,
1504,
59,
2996,
1055,
1913,
342,
267,
734,
1275,
740,
8,
11280,
6681,
698,
435,
283,
283,
5830,
2063,
13,
552,
8,
698,
430,
435,
283,
5320,
272,
734,
14,
740,
8,
11280,
358,
272,
870,
6522,
904,
8,
548,
9,
272,
870,
1004,
4785,
4388,
199,
698,
275,
901,
14,
1913,
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
] |
[
2647,
15,
1393,
15,
1548,
199,
646,
12733,
465,
486,
199,
646,
984,
199,
199,
2992,
513,
12,
1249,
275,
486,
14,
18907,
8,
1274,
14,
3020,
59,
17,
8429,
7,
68,
10993,
199,
15966,
275,
13647,
199,
509,
312,
12,
65,
315,
2450,
513,
26,
523,
340,
312,
508,
2475,
68,
356,
272,
21799,
275,
282,
199,
199,
988,
63,
2063,
275,
359,
16,
61,
199,
199,
1045,
1551,
8,
589,
59,
16,
26801,
82,
358,
465,
11155,
26,
523,
367,
1004,
315,
11155,
26,
272,
1004,
275,
1004,
14,
6735,
342,
272,
1504,
275,
1004,
14,
1294,
8,
15966,
9,
272,
367,
4280,
12,
698,
315,
3874,
8,
955,
304,
489,
901,
275,
901,
14,
1913,
342,
489,
340,
822,
8,
988,
63,
2063,
9,
2695,
4280,
520,
267,
1390,
63,
2063,
14,
740,
8,
552,
8,
698,
430,
489,
916,
1390,
63,
2063,
59,
2996,
61,
665,
822,
8,
698,
304,
267,
1390,
63,
2063,
59,
2996,
61,
275,
822,
8,
698,
9,
819,
11104,
275,
24506,
523,
367,
3462,
315,
1390,
63,
2063,
26,
272,
11104,
14,
740,
3654,
7,
5830,
2063,
11,
18,
430,
523,
11104,
14,
740,
8355,
523,
1004,
4785,
275,
6681,
1370,
904,
8,
6374,
9,
523,
11155,
14,
5507,
8,
16,
12,
16,
9,
523,
870,
1004,
4785,
523,
367,
1004,
315,
11155,
26,
272,
1004,
275,
1004,
14,
6735,
342,
272,
1504,
275,
1004,
14,
1294,
8,
15966,
9,
272,
734,
275,
24506,
272,
367,
4280,
12,
2063,
315,
3874,
8,
988,
63,
2063,
304,
489,
340,
8,
552,
8,
955,
9,
12932,
2996,
304,
267,
734,
1275,
740,
8,
11280,
283,
435,
283,
6438,
2063,
435,
283,
5320,
489,
587,
26,
267,
901,
275,
1504,
59,
2996,
1055,
1913,
342,
267,
734,
1275,
740,
8,
11280,
6681,
698,
435,
283,
283,
5830,
2063,
13,
552,
8,
698,
430,
435,
283,
5320,
272,
734,
14,
740,
8,
11280,
358,
272,
870,
6522,
904,
8,
548,
9,
272,
870,
1004,
4785,
4388,
199,
698,
275,
901,
14,
1913,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
SDSG-Invenio/invenio
|
invenio/modules/formatter/format_elements/bfe_photos.py
|
13
|
5832
|
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2008, 2009, 2010, 2011, 2014 CERN.
#
# Invenio is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Invenio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invenio; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""BibFormat element - Print photos of the record (if bibdoc file)
"""
import cgi
from invenio.legacy.bibdocfile.api import BibRecDocs
from invenio.utils.url import (create_html_link,
get_relative_url)
def format_element(bfo, separator=" ", style='', img_style='', text_style='font-size:small',
print_links='yes', max_photos='', show_comment='yes',
img_max_width='250px', display_all_version_links='yes'):
"""
Lists the photos of a record. Display the icon version, linked to
its original version.
This element works for photos appended to a record as BibDoc
files, for which a preview icon has been generated. If there are
several formats for one photo, use the first one found.
@param separator: separator between each photo
@param print_links: if 'yes', print links to the original photo
@param style: style attributes of the whole image block. Eg: "padding:2px;border:1px"
@param img_style: style attributes of the images. Eg: "width:50px;border:none"
@param text_style: style attributes of the text. Eg: "font-size:small"
@param max_photos: the maximum number of photos to display
@param show_comment: if 'yes', display the comment of each photo
@param display_all_version_links: if 'yes', print links to additional (sub)formats
"""
photos = []
bibarchive = BibRecDocs(bfo.recID)
bibdocs = bibarchive.list_bibdocs()
if max_photos.isdigit():
max_photos = int(max_photos)
else:
max_photos = len(bibdocs)
for doc in bibdocs[:max_photos]:
found_icons = []
found_url = ''
for docfile in doc.list_latest_files():
if docfile.is_icon():
found_icons.append((
docfile.get_size(),
get_relative_url(docfile.get_url())
))
else:
found_url = get_relative_url(docfile.get_url())
found_icons.sort()
if found_icons:
additional_links = ''
name = bibarchive.get_docname(doc.id)
comment = doc.list_latest_files()[0].get_comment()
preview_url = None
if len(found_icons) > 1:
preview_url = get_relative_url(found_icons[1][1])
additional_urls = [(docfile.get_size(), get_relative_url(docfile.get_url()), \
docfile.get_superformat(), docfile.get_subformat()) \
for docfile in doc.list_latest_files() if not docfile.is_icon()]
additional_urls.sort()
additional_links = [create_html_link(url, urlargd={}, \
linkattrd={'style': 'font-size:x-small'}, \
link_label="%s %s (%s)" % (format.strip('.').upper(), subformat, format_size(size))) \
for (size, url, format, subformat) in additional_urls]
img = '<img src="%(icon_url)s" alt="%(name)s" style="max-width:%(img_max_width)s;_width:%(img_max_width)s;%(img_style)s" />' % \
{'icon_url': cgi.escape(get_relative_url(found_icons[0][1]), True),
'name': cgi.escape(name, True),
'img_style': img_style,
'img_max_width': img_max_width}
if print_links.lower() == 'yes':
img = '<a href="%s">%s</a>' % (cgi.escape(preview_url or found_url, True), img)
if display_all_version_links.lower() == 'yes' and additional_links:
img += '<br />' + ' '.join(additional_links) + '<br />'
if show_comment.lower() == 'yes' and comment:
img += '<div style="margin-auto;text-align:center;%(text_style)s">%(comment)s</div>' % \
{'comment': comment.replace('\n', '<br/>'),
'text_style': text_style}
img = '<div style="vertical-align: middle;text-align:center;display:inline-block;display: -moz-inline-stack;zoom: 1;*display: inline;max-width:%(img_max_width)s;_width:%(img_max_width)s;text-align:center;%(style)s">%(img)s</div>' % \
{'img_max_width': img_max_width,
'style': style,
'img': img}
photos.append(img)
return '<div>' + separator.join(photos) + '</div>'
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
def format_size(size):
"""
Get human-readable string for the given size in Bytes
"""
if size < 1024:
return "%d byte%s" % (size, size != 1 and 's' or '')
elif size < 1024 * 1024:
return "%.1f KB" % (size / 1024)
elif size < 1024 * 1024 * 1024:
return "%.1f MB" % (size / (1024 * 1024))
else:
return "%.1f GB" % (size / (1024 * 1024 * 1024))
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
9079,
12,
8937,
12,
7129,
12,
7760,
12,
6927,
24354,
14,
199,
3,
199,
3,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
624,
25217,
3484,
1819,
446,
9101,
3945,
17278,
402,
314,
2777,
334,
692,
23682,
570,
9,
199,
624,
199,
199,
646,
16004,
199,
504,
13640,
14,
10000,
14,
26415,
493,
14,
1246,
492,
21949,
21561,
27858,
199,
504,
13640,
14,
1208,
14,
633,
492,
334,
981,
63,
1360,
63,
1073,
12,
2892,
664,
63,
6188,
63,
633,
9,
421,
199,
318,
1475,
63,
2108,
8,
66,
545,
12,
9432,
628,
3872,
3449,
4581,
6050,
63,
2487,
4581,
1318,
63,
2487,
534,
4246,
13,
890,
26,
7241,
297,
673,
870,
63,
4614,
534,
5066,
297,
1390,
63,
25211,
4581,
2498,
63,
3349,
534,
5066,
297,
673,
6050,
63,
988,
63,
2063,
534,
7991,
5326,
297,
2929,
63,
452,
63,
1023,
63,
4614,
534,
5066,
735,
272,
408,
272,
31289,
314,
3945,
17278,
402,
282,
2777,
14,
12175,
314,
7016,
1015,
12,
10632,
370,
272,
2399,
3379,
1015,
14,
339,
961,
1819,
5419,
367,
3945,
17278,
11544,
370,
282,
2777,
465,
21949,
3768,
272,
1584,
12,
367,
1314,
282,
19653,
7016,
965,
2757,
4046,
14,
982,
2337,
787,
272,
9978,
6752,
367,
1373,
19397,
12,
675,
314,
1642,
1373,
1911,
14,
339,
768,
635,
9432,
26,
9432,
3382,
1924,
19397,
272,
768,
635,
870,
63,
4614,
26,
340,
283,
5066,
297,
870,
6220,
370,
314,
3379,
19397,
272,
768,
635,
3449,
26,
3449,
3004,
402,
314,
8852,
1834,
1853,
14,
662,
71,
26,
298,
8358,
26,
18,
5326,
27,
8665,
26,
17,
5326,
2,
272,
768,
635,
6050,
63,
2487,
26,
3449,
3004,
402,
314,
5935,
14,
662,
71,
26,
298,
2063,
26,
1400,
5326,
27,
8665,
26,
3592,
2,
272,
768,
635,
1318,
63,
2487,
26,
3449,
3004,
402,
314,
1318,
14,
662,
71,
26,
298,
4246,
13,
890,
26,
7241,
2,
272,
768,
635,
1390,
63,
25211,
26,
314,
5696,
1329,
402,
3945,
17278,
370,
2929,
272,
768,
635,
2498,
63,
3349,
26,
340,
283,
5066,
297,
2929,
314,
3721,
402,
1924,
19397,
272,
768,
635,
2929,
63,
452,
63,
1023,
63,
4614,
26,
340,
283,
5066,
297,
870,
6220,
370,
4722,
334,
954,
9,
6321,
272,
408,
272,
3945,
17278,
275,
942,
272,
11314,
6404,
275,
21949,
21561,
27858,
8,
66,
545,
14,
2761,
998,
9,
272,
11314,
4757,
275,
11314,
6404,
14,
513,
63,
8804,
4757,
342,
339,
340,
1390,
63,
25211,
14,
13896,
837,
267,
1390,
63,
25211,
275,
1109,
8,
988,
63,
25211,
9,
272,
587,
26,
267,
1390,
63,
25211,
275,
822,
8,
8804,
4757,
9,
339,
367,
1382,
315,
11314,
4757,
1491,
988,
63,
25211,
2189,
267,
1911,
63,
16471,
275,
942,
267,
1911,
63,
633,
275,
2125,
267,
367,
1382,
493,
315,
1382,
14,
513,
63,
7410,
63,
1725,
837,
288,
340,
1382,
493,
14,
374,
63,
4677,
837,
355,
1911,
63,
16471,
14,
740,
1332,
3521,
1382,
493,
14,
362,
63,
890,
1062,
3521,
664,
63,
6188,
63,
633,
8,
1301,
493,
14,
362,
63,
633,
1012,
3303,
5082,
288,
587,
26,
355,
1911,
63,
633,
275,
664,
63,
6188,
63,
633,
8,
1301,
493,
14,
362,
63,
633,
1012,
267,
1911,
63,
16471,
14,
3191,
342,
398,
340,
1911,
63,
16471,
26,
288,
4722,
63,
4614,
275,
2125,
288,
536,
275,
11314,
6404,
14,
362,
63,
21828,
8,
1301,
14,
344,
9,
288,
3721,
275,
1382,
14,
513,
63,
7410,
63,
1725,
3430,
16,
1055,
362,
63,
3349,
342,
953,
19653,
63,
633,
275,
488,
288,
340,
822,
8,
4214,
63,
16471,
9,
690,
413,
26,
355,
19653,
63,
633,
275,
664,
63,
6188,
63,
633,
8,
4214,
63,
16471,
59,
17,
1527,
17,
566,
355,
4722,
63,
3603,
275,
3842,
1301,
493,
14,
362,
63,
890,
1062,
664,
63,
6188,
63,
633,
8,
1301,
493,
14,
362,
63,
633,
4000,
971,
2511,
1382,
493,
14,
362,
63,
4792,
908,
1062,
1382,
493,
14,
362,
63,
954,
908,
1012,
971,
3521,
367,
1382,
493,
315,
1382,
14,
513,
63,
7410,
63,
1725,
342,
340,
440,
1382,
493,
14,
374,
63,
4677,
5106,
355,
4722,
63,
3603,
14,
3191,
342,
355,
4722,
63,
4614,
275,
359,
981,
63,
1360,
63,
1073,
8,
633,
12,
1166,
26282,
10324,
971,
9349,
2142,
962,
68,
3713,
2487,
356,
283,
4246,
13,
890,
26,
88,
13,
7241,
2267,
971,
9349,
2142,
63,
1302,
5961,
83,
450,
83,
4366,
83,
2924,
450,
334,
908,
14,
1913,
5175,
1959,
4142,
1062,
1007,
908,
12,
1475,
63,
890,
8,
890,
1724,
971,
2511,
367,
334,
890,
12,
1166,
12,
1475,
12,
1007,
908,
9,
315,
4722,
63,
3603,
61,
288,
6050,
275,
2650,
4060,
2928,
17662,
4677,
63,
633,
9,
83,
2,
8791,
17662,
354,
9,
83,
2,
3449,
628,
988,
13,
2063,
19648,
4060,
63,
988,
63,
2063,
9,
83,
27,
63,
2063,
19648,
4060,
63,
988,
63,
2063,
9,
83,
27,
2840,
4060,
63,
2487,
9,
83,
2,
22294,
450,
971,
2116,
791,
4677,
63,
633,
356,
16004,
14,
3765,
8,
362,
63,
6188,
63,
633,
8,
4214,
63,
16471,
59,
16
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
9079,
12,
8937,
12,
7129,
12,
7760,
12,
6927,
24354,
14,
199,
3,
199,
3,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
624,
25217,
3484,
1819,
446,
9101,
3945,
17278,
402,
314,
2777,
334,
692,
23682,
570,
9,
199,
624,
199,
199,
646,
16004,
199,
504,
13640,
14,
10000,
14,
26415,
493,
14,
1246,
492,
21949,
21561,
27858,
199,
504,
13640,
14,
1208,
14,
633,
492,
334,
981,
63,
1360,
63,
1073,
12,
2892,
664,
63,
6188,
63,
633,
9,
421,
199,
318,
1475,
63,
2108,
8,
66,
545,
12,
9432,
628,
3872,
3449,
4581,
6050,
63,
2487,
4581,
1318,
63,
2487,
534,
4246,
13,
890,
26,
7241,
297,
673,
870,
63,
4614,
534,
5066,
297,
1390,
63,
25211,
4581,
2498,
63,
3349,
534,
5066,
297,
673,
6050,
63,
988,
63,
2063,
534,
7991,
5326,
297,
2929,
63,
452,
63,
1023,
63,
4614,
534,
5066,
735,
272,
408,
272,
31289,
314,
3945,
17278,
402,
282,
2777,
14,
12175,
314,
7016,
1015,
12,
10632,
370,
272,
2399,
3379,
1015,
14,
339,
961,
1819,
5419,
367,
3945,
17278,
11544,
370,
282,
2777,
465,
21949,
3768,
272,
1584,
12,
367,
1314,
282,
19653,
7016,
965,
2757,
4046,
14,
982,
2337,
787,
272,
9978,
6752,
367,
1373,
19397,
12,
675,
314,
1642,
1373,
1911,
14,
339,
768,
635,
9432,
26,
9432,
3382,
1924,
19397,
272,
768,
635,
870,
63,
4614,
26,
340,
283,
5066,
297,
870,
6220,
370,
314,
3379,
19397,
272,
768,
635,
3449,
26,
3449,
3004,
402,
314,
8852,
1834,
1853,
14,
662,
71,
26,
298,
8358,
26,
18,
5326,
27,
8665,
26,
17,
5326,
2,
272,
768,
635,
6050,
63,
2487,
26,
3449,
3004,
402,
314,
5935,
14,
662,
71,
26,
298,
2063,
26,
1400,
5326,
27,
8665,
26,
3592,
2,
272,
768,
635,
1318,
63,
2487,
26,
3449,
3004,
402,
314,
1318,
14,
662,
71,
26,
298,
4246,
13,
890,
26,
7241,
2,
272,
768,
635,
1390,
63,
25211,
26,
314,
5696,
1329,
402,
3945,
17278,
370,
2929,
272,
768,
635,
2498,
63,
3349,
26,
340,
283,
5066,
297,
2929,
314,
3721,
402,
1924,
19397,
272,
768,
635,
2929,
63,
452,
63,
1023,
63,
4614,
26,
340,
283,
5066,
297,
870,
6220,
370,
4722,
334,
954,
9,
6321,
272,
408,
272,
3945,
17278,
275,
942,
272,
11314,
6404,
275,
21949,
21561,
27858,
8,
66,
545,
14,
2761,
998,
9,
272,
11314,
4757,
275,
11314,
6404,
14,
513,
63,
8804,
4757,
342,
339,
340,
1390,
63,
25211,
14,
13896,
837,
267,
1390,
63,
25211,
275,
1109,
8,
988,
63,
25211,
9,
272,
587,
26,
267,
1390,
63,
25211,
275,
822,
8,
8804,
4757,
9,
339,
367,
1382,
315,
11314,
4757,
1491,
988,
63,
25211,
2189,
267,
1911,
63,
16471,
275,
942,
267,
1911,
63,
633,
275,
2125,
267,
367,
1382,
493,
315,
1382,
14,
513,
63,
7410,
63,
1725,
837,
288,
340,
1382,
493,
14,
374,
63,
4677,
837,
355,
1911,
63,
16471,
14,
740,
1332,
3521,
1382,
493,
14,
362,
63,
890,
1062,
3521,
664,
63,
6188,
63,
633,
8,
1301,
493,
14,
362,
63,
633,
1012,
3303,
5082,
288,
587,
26,
355,
1911,
63,
633,
275,
664,
63,
6188,
63,
633,
8,
1301,
493,
14,
362,
63,
633,
1012,
267,
1911,
63,
16471,
14,
3191,
342,
398,
340,
1911,
63,
16471,
26,
288,
4722,
63,
4614,
275,
2125,
288,
536,
275,
11314,
6404,
14,
362,
63,
21828,
8,
1301,
14,
344,
9,
288,
3721,
275,
1382,
14,
513,
63,
7410,
63,
1725,
3430,
16,
1055,
362,
63,
3349,
342,
953,
19653,
63,
633,
275,
488,
288,
340,
822,
8,
4214,
63,
16471,
9,
690,
413,
26,
355,
19653,
63,
633,
275,
664,
63,
6188,
63,
633,
8,
4214,
63,
16471,
59,
17,
1527,
17,
566,
355,
4722,
63,
3603,
275,
3842,
1301,
493,
14,
362,
63,
890,
1062,
664,
63,
6188,
63,
633,
8,
1301,
493,
14,
362,
63,
633,
4000,
971,
2511,
1382,
493,
14,
362,
63,
4792,
908,
1062,
1382,
493,
14,
362,
63,
954,
908,
1012,
971,
3521,
367,
1382,
493,
315,
1382,
14,
513,
63,
7410,
63,
1725,
342,
340,
440,
1382,
493,
14,
374,
63,
4677,
5106,
355,
4722,
63,
3603,
14,
3191,
342,
355,
4722,
63,
4614,
275,
359,
981,
63,
1360,
63,
1073,
8,
633,
12,
1166,
26282,
10324,
971,
9349,
2142,
962,
68,
3713,
2487,
356,
283,
4246,
13,
890,
26,
88,
13,
7241,
2267,
971,
9349,
2142,
63,
1302,
5961,
83,
450,
83,
4366,
83,
2924,
450,
334,
908,
14,
1913,
5175,
1959,
4142,
1062,
1007,
908,
12,
1475,
63,
890,
8,
890,
1724,
971,
2511,
367,
334,
890,
12,
1166,
12,
1475,
12,
1007,
908,
9,
315,
4722,
63,
3603,
61,
288,
6050,
275,
2650,
4060,
2928,
17662,
4677,
63,
633,
9,
83,
2,
8791,
17662,
354,
9,
83,
2,
3449,
628,
988,
13,
2063,
19648,
4060,
63,
988,
63,
2063,
9,
83,
27,
63,
2063,
19648,
4060,
63,
988,
63,
2063,
9,
83,
27,
2840,
4060,
63,
2487,
9,
83,
2,
22294,
450,
971,
2116,
791,
4677,
63,
633,
356,
16004,
14,
3765,
8,
362,
63,
6188,
63,
633,
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1,
1,
1,
1,
1,
1,
1,
1,
1
] |
heliazandi/volttron-applications
|
pnnl/PGnE/pgne/agent.py
|
3
|
12179
|
# -*- coding: utf-8 -*- {{{
# vim: set fenc=utf-8 ft=python sw=4 ts=4 sts=4 et:
# Copyright (c) 2016, Battelle Memorial Institute
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# 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.
#
# The views and conclusions contained in the software and documentation
# are those of the authors and should not be interpreted as representing
# official policies, either expressed or implied, of the FreeBSD
# Project.
#
# This material was prepared as an account of work sponsored by an
# agency of the United States Government. Neither the United States
# Government nor the United States Department of Energy, nor Battelle,
# nor any of their employees, nor any jurisdiction or organization that
# has cooperated in the development of these materials, makes any
# warranty, express or implied, or assumes any legal liability or
# responsibility for the accuracy, completeness, or usefulness or any
# information, apparatus, product, software, or process disclosed, or
# represents that its use would not infringe privately owned rights.
#
# Reference herein to any specific commercial product, process, or
# service by trade name, trademark, manufacturer, or otherwise does not
# necessarily constitute or imply its endorsement, recommendation, or
# favoring by the United States Government or any agency thereof, or
# Battelle Memorial Institute. The views and opinions of authors
# expressed herein do not necessarily state or reflect those of the
# United States Government or any agency thereof.
#
# PACIFIC NORTHWEST NATIONAL LABORATORY
# operated by BATTELLE for the UNITED STATES DEPARTMENT OF ENERGY
# under Contract DE-AC05-76RL01830
# }}}
import os
import sys
import logging
import datetime
from dateutil import parser
from volttron.platform.vip.agent import Agent, Core, PubSub, RPC, compat
from volttron.platform.agent import utils
from volttron.platform.agent.utils import (get_aware_utc_now,
format_timestamp)
import pandas as pd
import statsmodels.formula.api as sm
utils.setup_logging()
_log = logging.getLogger(__name__)
class PGnEAgent(Agent):
def __init__(self, config_path, **kwargs):
super(PGnEAgent, self).__init__(**kwargs)
self.config = utils.load_config(config_path)
self.site = self.config.get('campus')
self.building = self.config.get('building')
self.temp_unit = self.config.get('temp_unit')
self.power_unit = self.config.get('power_unit')
self.out_temp_name = self.config.get('out_temp_name')
self.power_name = self.config.get('power_name')
self.aggregate_in_min = self.config.get('aggregate_in_min')
self.aggregate_freq = str(self.aggregate_in_min) + 'Min'
self.ts_name = self.config.get('ts_name')
self.window_size_in_day = int(self.config.get('window_size_in_day'))
self.min_required_window_size_in_percent = float(self.config.get('min_required_window_size_in_percent'))
self.interval_in_min = int(self.config.get('interval_in_min'))
self.no_of_recs_needed = 10 # self.window_size_in_day * 24 * (60 / self.interval_in_min)
self.min_no_of_records_needed_after_aggr = int(self.min_required_window_size_in_percent/100 *
self.no_of_recs_needed/self.aggregate_in_min)
self.schedule_run_in_sec = int(self.config.get('schedule_run_in_hr')) * 3600
# Testing
#self.no_of_recs_needed = 200
#self.min_no_of_records_needed_after_aggr = self.no_of_recs_needed/self.aggregate_in_min
@Core.receiver('onstart')
def onstart(self, sender, **kwargs):
self.core.periodic(self.schedule_run_in_sec, self.calculate_latest_coeffs)
def calculate_latest_coeffs(self):
unit_topic_tmpl = "{campus}/{building}/{unit}/{point}"
unit_points = [self.power_name]
df = None
#Get data
unit = self.temp_unit
for point in unit_points:
if point == self.power_name:
unit = self.power_unit
unit_topic = unit_topic_tmpl.format(campus=self.site,
building=self.building,
unit=unit,
point=point)
result = self.vip.rpc.call('platform.historian',
'query',
topic=unit_topic,
count=self.no_of_recs_needed,
order="LAST_TO_FIRST").get(timeout=10000)
df2 = pd.DataFrame(result['values'], columns=[self.ts_name, point])
df2[self.ts_name] = pd.to_datetime(df2[self.ts_name])
df2 = df2.groupby([pd.TimeGrouper(key=self.ts_name, freq=self.aggregate_freq)]).mean()
# df2[self.ts_name] = df2[self.ts_name].apply(lambda dt: dt.replace(second=0, microsecond=0))
df = df2 if df is None else pd.merge(df, df2, how='outer', left_index=True, right_index=True)
#Calculate coefficients
result_df = self.calculate_coeffs(df)
# Publish coeffs to store
#if coeffs is not None:
# self.save_coeffs(coeffs, subdevice)
def convert_units_to_SI(self, df, point, unit):
if unit == 'degreesFahrenheit':
df[point] = (df[point]-32) * 5/9
# Air state assumption: http://www.remak.eu/en/mass-air-flow-rate-unit-converter
# 1cfm ~ 0.00055kg/s
if unit == 'cubicFeetPerMinute':
df[point] = df[point] * 0.00055
def calculate_coeffs(self, dP):
dP['time'] = dP['posttime']
dP = dP.set_index(['posttime'])
dP.index = pd.to_datetime(dP.index)
dP['time'] = pd.to_datetime(dP['time'])
#### Delete the weekend
dP.columns = ["Tout", "wbe", "Weekday", "time"]
dP['year'] = dP.index.year
dP['month'] = dP.index.month
dP['hour'] = dP.index.hour
dP['day'] = dP.index.day
dP = dP[dP.Weekday != 'Sun']
dP = dP[dP.Weekday != 'Sat']
#### Hourly average value
df = dP.resample('60min').mean()
dP2 = dP.resample('60min').mean()
dP = dP[dP.Tout < 150]
dP = dP[dP.Tout > 20]
dP = dP.dropna()
df = df.pivot_table(index=["year", "month", "day"], columns=["hour"], values=["wbe", "Tout"])
# ### Average using high five outdoor temperature data based on 10 day moving windows
leng = len(df.index)
for i in range(0, leng):
for j in range(0, 24):
df['power', j] = df.ix[i:i + 10, :].sort([('Tout', j)], ascending=False).head(5).ix[:,
j + 24:j + 25].mean()
for i in range(0, leng):
for j in range(0, 24):
df['power', j][i:i + 1] = df.ix[i:i + 10, :].sort([('Tout', j)], ascending=False).head(5).ix[:,
j + 24:j + 25].mean()
# ### Average based on 10 day moving windows
for i in range(0, 24):
df['Tout_avg', i] = df.ix[:, i:i + 1].rolling(window=10, min_periods=10).mean()
for i in range(0, 24):
df['Pow_avg', i] = df.ix[:, i + 24:i + 25].rolling(window=10, min_periods=10).mean()
df = df.stack(level=['hour'])
df.power = df.power.shift(216)
df = df.dropna()
dq = df.reset_index()
dq['Data'] = pd.to_datetime(
dq.year.astype(int).apply(str) + '/' + dq.month.astype(int).apply(str) + '/' + dq.day.astype(int).apply(
str) + ' ' + dq.hour.astype(int).apply(str) + ":00", format='%Y/%m/%d %H:%M')
dq = dq.set_index(['Data'])
dq = dq.drop(['year', 'month', 'day', 'hour'], axis=1)
dk = dq
### Adjusted average using high five outdoor temperature data based on 10 day moving windows
lengnth = len(dq.index)
lengnth = lengnth - 4
dq["Adj"] = 1.0
for i in range(0, lengnth):
dq['Adj'][i + 4] = (dq['wbe'][i:i + 4].mean()) / (dq['Pow_avg'][i:i + 4].mean())
dq['Pow_adj'] = dq['Pow_avg'] * dq['Adj']
#### Adjusted average based on 10 day moving windows
lengnth = len(dq.index)
lengnth = lengnth - 4
dq["Adj2"] = 1.0
for i in range(0, lengnth):
dq['Adj2'][i + 4] = (dq['wbe'][i:i + 4].mean()) / (dq['power'][i:i + 4].mean())
dq['Adj2'] = dq.Adj2.shift(2)
dq['power_adj'] = dq['power'] * dq['Adj2']
return dq
def save_coeffs(self, coeffs, subdevice):
topic_tmpl = "analysis/TCM/{campus}/{building}/{unit}/{subdevice}/"
topic = topic_tmpl.format(campus=self.site,
building=self.building,
unit=self.unit,
subdevice=subdevice)
T_coeffs = coeffs["T_fit"]
Q_coeffs = coeffs["Q_fit"]
headers = {'Date': format_timestamp(get_aware_utc_now())}
for idx in xrange(0,5):
T_topic = topic + "T_c" + str(idx)
Q_topic = topic + "Q_c" + str(idx)
self.vip.pubsub.publish(
'pubsub', T_topic, headers, T_coeffs.params[idx])
self.vip.pubsub.publish(
'pubsub', Q_topic, headers, Q_coeffs.params[idx])
_log.debug(T_coeffs.params)
_log.debug(Q_coeffs.params)
def main(argv=sys.argv):
'''Main method called by the eggsecutable.'''
try:
utils.vip_main(PGnEAgent)
except Exception as e:
_log.exception('unhandled exception')
def test_ols():
'''To compare result of pandas and R's linear regression'''
import os
test_csv = '../test_data/tcm_ZONE_VAV_150_data.csv'
df = pd.read_csv(test_csv)
config_path = os.environ.get('AGENT_CONFIG')
tcm = PGnEAgent(config_path)
coeffs = tcm.calculate_coeffs(df)
if coeffs is not None:
T_coeffs = coeffs["T_fit"]
Q_coeffs = coeffs["Q_fit"]
_log.debug(T_coeffs.params)
_log.debug(Q_coeffs.params)
def test_api():
'''To test Volttron APIs'''
import os
topic_tmpl = "{campus}/{building}/{unit}/{subdevice}/{point}"
tcm = PGnEAgent(os.environ.get('AGENT_CONFIG'))
topic1 = topic_tmpl.format(campus='PNNL',
building='SEB',
unit='AHU1',
subdevice='VAV123A',
point='MaximumZoneAirFlow')
result = tcm.vip.rpc.call('platform.historian',
'query',
topic=topic1,
count=20,
order="LAST_TO_FIRST").get(timeout=100)
assert result is not None
if __name__ == '__main__':
# Entry point for script
sys.exit(main())
#test_api()
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
469,
3638,
199,
3,
6695,
26,
663,
289,
10945,
29,
1624,
13,
24,
18133,
29,
1548,
5584,
29,
20,
6714,
29,
20,
23014,
29,
20,
10844,
26,
199,
199,
3,
1898,
334,
67,
9,
7800,
12,
699,
292,
14146,
274,
3194,
12416,
2380,
1010,
25585,
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,
199,
3,
787,
7647,
26,
199,
3,
199,
3,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
199,
3,
259,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
259,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
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,
710,
6858,
436,
406,
18540,
10470,
315,
314,
2032,
436,
3794,
199,
3,
787,
5204,
402,
314,
11462,
436,
1077,
440,
506,
11922,
465,
6144,
199,
3,
25410,
14118,
12,
1902,
19147,
503,
2478,
12,
402,
314,
2868,
15400,
199,
3,
7290,
14,
199,
3,
199,
3,
961,
6285,
1990,
16318,
465,
376,
2933,
402,
1736,
308,
678,
1152,
581,
701,
376,
199,
3,
1839,
9501,
402,
314,
1910,
5703,
24230,
598,
27639,
14,
221,
11443,
314,
1910,
5703,
24230,
199,
3,
598,
27639,
6590,
314,
1910,
5703,
24230,
1487,
12493,
402,
662,
1372,
4312,
12,
6590,
699,
292,
14146,
274,
12,
199,
3,
6590,
1263,
402,
3932,
9052,
18149,
12,
6590,
1263,
1335,
17656,
26382,
503,
13237,
626,
199,
3,
965,
512,
2262,
972,
315,
314,
16367,
402,
3520,
8418,
12,
7704,
1263,
199,
3,
3750,
12,
4056,
503,
2478,
12,
503,
15194,
1263,
18393,
1212,
3616,
503,
199,
3,
9163,
4783,
367,
314,
12862,
12,
4890,
4171,
12,
503,
2997,
4171,
503,
1263,
199,
3,
2556,
12,
2771,
462,
896,
12,
3336,
12,
2032,
12,
503,
2112,
4339,
320,
939,
12,
503,
199,
3,
8469,
626,
2399,
675,
3955,
440,
315,
4391,
17081,
5726,
590,
23191,
4481,
14,
199,
3,
199,
3,
10944,
2348,
262,
370,
1263,
2488,
2414,
23012,
3336,
12,
2112,
12,
503,
199,
3,
2435,
701,
21032,
536,
12,
21032,
1657,
12,
2169,
21087,
12,
503,
4257,
1630,
440,
199,
3,
20513,
950,
390,
938,
503,
1742,
590,
2399,
10692,
434,
12,
295,
22105,
12,
503,
199,
3,
289,
1214,
6854,
701,
314,
1910,
5703,
24230,
598,
27639,
503,
1263,
1839,
9501,
2337,
1618,
12,
503,
199,
3,
699,
292,
14146,
274,
3194,
12416,
2380,
1010,
25585,
14,
710,
6858,
436,
1687,
262,
15293,
402,
11462,
199,
3,
19147,
2348,
262,
886,
440,
20513,
1174,
503,
16806,
5204,
402,
314,
199,
3,
1910,
5703,
24230,
598,
27639,
503,
1263,
1839,
9501,
2337,
1618,
14,
199,
3,
199,
3,
510,
1348,
14456,
653,
726,
2080,
55,
1719,
653,
2594,
748,
491,
1217,
726,
619,
5347,
199,
3,
1758,
972,
701,
699,
11712,
2901,
906,
367,
314,
25836,
1149,
13146,
654,
3265,
14848,
4479,
1634,
21466,
199,
3,
1334,
1448,
6908,
3265,
13,
1348,
1717,
13,
2114,
2431,
12549,
1216,
199,
199,
3,
3586,
93,
199,
646,
747,
199,
646,
984,
199,
646,
2050,
199,
646,
2197,
199,
504,
22208,
492,
1798,
199,
199,
504,
5236,
84,
454,
265,
14,
3246,
14,
18607,
14,
4054,
492,
19866,
12,
11672,
12,
510,
456,
2610,
12,
11785,
12,
8434,
199,
504,
5236,
84,
454,
265,
14,
3246,
14,
4054,
492,
3778,
199,
504,
5236,
84,
454,
265,
14,
3246,
14,
4054,
14,
1208,
492,
334,
362,
63,
14600,
63,
5834,
63,
2131,
12,
5644,
1475,
63,
3954,
9,
199,
199,
646,
10634,
465,
6454,
199,
646,
5020,
992,
14,
16798,
14,
1246,
465,
4383,
199,
199,
1208,
14,
2758,
63,
4806,
342,
199,
63,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
26595,
78,
37,
7788,
8,
7788,
304,
272,
347,
636,
826,
721,
277,
12,
1101,
63,
515,
12,
1011,
958,
304,
267,
1613,
8,
11115,
78,
37,
7788,
12,
291,
2843,
826,
14155,
958,
9,
267,
291,
14,
888,
275,
3778,
14,
912,
63,
888,
8,
888,
63,
515,
9,
267,
291,
14,
2124,
275,
291,
14,
888,
14,
362,
360,
20290,
527,
358,
267,
291,
14,
17952,
275,
291,
14,
888,
14,
362,
360,
17952,
358,
267,
291,
14,
808,
63,
3248,
275,
291,
14,
888,
14,
362,
360,
808,
63,
3248,
358,
267,
291,
14,
5652,
63,
3248,
275,
291,
14,
888,
14,
362,
360,
5652,
63,
3248,
358,
267,
291,
14,
548,
63,
808,
63,
354,
275,
291,
14,
888,
14,
362,
360,
548,
63,
808,
63,
354,
358,
267,
291,
14,
5652,
63,
354,
275,
291,
14,
888,
14,
362,
360,
5652,
63,
354,
358,
267,
291,
14,
7516,
63,
262,
63,
827,
275,
291,
14,
888,
14,
362,
360,
7516,
63,
262,
63,
827,
358,
267,
291,
14,
7516,
63,
5646,
275,
620,
8,
277,
14,
7516,
63,
262,
63,
827,
9,
435,
283,
4649,
7,
267,
291
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
469,
3638,
199,
3,
6695,
26,
663,
289,
10945,
29,
1624,
13,
24,
18133,
29,
1548,
5584,
29,
20,
6714,
29,
20,
23014,
29,
20,
10844,
26,
199,
199,
3,
1898,
334,
67,
9,
7800,
12,
699,
292,
14146,
274,
3194,
12416,
2380,
1010,
25585,
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,
199,
3,
787,
7647,
26,
199,
3,
199,
3,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
199,
3,
259,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
259,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
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,
710,
6858,
436,
406,
18540,
10470,
315,
314,
2032,
436,
3794,
199,
3,
787,
5204,
402,
314,
11462,
436,
1077,
440,
506,
11922,
465,
6144,
199,
3,
25410,
14118,
12,
1902,
19147,
503,
2478,
12,
402,
314,
2868,
15400,
199,
3,
7290,
14,
199,
3,
199,
3,
961,
6285,
1990,
16318,
465,
376,
2933,
402,
1736,
308,
678,
1152,
581,
701,
376,
199,
3,
1839,
9501,
402,
314,
1910,
5703,
24230,
598,
27639,
14,
221,
11443,
314,
1910,
5703,
24230,
199,
3,
598,
27639,
6590,
314,
1910,
5703,
24230,
1487,
12493,
402,
662,
1372,
4312,
12,
6590,
699,
292,
14146,
274,
12,
199,
3,
6590,
1263,
402,
3932,
9052,
18149,
12,
6590,
1263,
1335,
17656,
26382,
503,
13237,
626,
199,
3,
965,
512,
2262,
972,
315,
314,
16367,
402,
3520,
8418,
12,
7704,
1263,
199,
3,
3750,
12,
4056,
503,
2478,
12,
503,
15194,
1263,
18393,
1212,
3616,
503,
199,
3,
9163,
4783,
367,
314,
12862,
12,
4890,
4171,
12,
503,
2997,
4171,
503,
1263,
199,
3,
2556,
12,
2771,
462,
896,
12,
3336,
12,
2032,
12,
503,
2112,
4339,
320,
939,
12,
503,
199,
3,
8469,
626,
2399,
675,
3955,
440,
315,
4391,
17081,
5726,
590,
23191,
4481,
14,
199,
3,
199,
3,
10944,
2348,
262,
370,
1263,
2488,
2414,
23012,
3336,
12,
2112,
12,
503,
199,
3,
2435,
701,
21032,
536,
12,
21032,
1657,
12,
2169,
21087,
12,
503,
4257,
1630,
440,
199,
3,
20513,
950,
390,
938,
503,
1742,
590,
2399,
10692,
434,
12,
295,
22105,
12,
503,
199,
3,
289,
1214,
6854,
701,
314,
1910,
5703,
24230,
598,
27639,
503,
1263,
1839,
9501,
2337,
1618,
12,
503,
199,
3,
699,
292,
14146,
274,
3194,
12416,
2380,
1010,
25585,
14,
710,
6858,
436,
1687,
262,
15293,
402,
11462,
199,
3,
19147,
2348,
262,
886,
440,
20513,
1174,
503,
16806,
5204,
402,
314,
199,
3,
1910,
5703,
24230,
598,
27639,
503,
1263,
1839,
9501,
2337,
1618,
14,
199,
3,
199,
3,
510,
1348,
14456,
653,
726,
2080,
55,
1719,
653,
2594,
748,
491,
1217,
726,
619,
5347,
199,
3,
1758,
972,
701,
699,
11712,
2901,
906,
367,
314,
25836,
1149,
13146,
654,
3265,
14848,
4479,
1634,
21466,
199,
3,
1334,
1448,
6908,
3265,
13,
1348,
1717,
13,
2114,
2431,
12549,
1216,
199,
199,
3,
3586,
93,
199,
646,
747,
199,
646,
984,
199,
646,
2050,
199,
646,
2197,
199,
504,
22208,
492,
1798,
199,
199,
504,
5236,
84,
454,
265,
14,
3246,
14,
18607,
14,
4054,
492,
19866,
12,
11672,
12,
510,
456,
2610,
12,
11785,
12,
8434,
199,
504,
5236,
84,
454,
265,
14,
3246,
14,
4054,
492,
3778,
199,
504,
5236,
84,
454,
265,
14,
3246,
14,
4054,
14,
1208,
492,
334,
362,
63,
14600,
63,
5834,
63,
2131,
12,
5644,
1475,
63,
3954,
9,
199,
199,
646,
10634,
465,
6454,
199,
646,
5020,
992,
14,
16798,
14,
1246,
465,
4383,
199,
199,
1208,
14,
2758,
63,
4806,
342,
199,
63,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
26595,
78,
37,
7788,
8,
7788,
304,
272,
347,
636,
826,
721,
277,
12,
1101,
63,
515,
12,
1011,
958,
304,
267,
1613,
8,
11115,
78,
37,
7788,
12,
291,
2843,
826,
14155,
958,
9,
267,
291,
14,
888,
275,
3778,
14,
912,
63,
888,
8,
888,
63,
515,
9,
267,
291,
14,
2124,
275,
291,
14,
888,
14,
362,
360,
20290,
527,
358,
267,
291,
14,
17952,
275,
291,
14,
888,
14,
362,
360,
17952,
358,
267,
291,
14,
808,
63,
3248,
275,
291,
14,
888,
14,
362,
360,
808,
63,
3248,
358,
267,
291,
14,
5652,
63,
3248,
275,
291,
14,
888,
14,
362,
360,
5652,
63,
3248,
358,
267,
291,
14,
548,
63,
808,
63,
354,
275,
291,
14,
888,
14,
362,
360,
548,
63,
808,
63,
354,
358,
267,
291,
14,
5652,
63,
354,
275,
291,
14,
888,
14,
362,
360,
5652,
63,
354,
358,
267,
291,
14,
7516,
63,
262,
63,
827,
275,
291,
14,
888,
14,
362,
360,
7516,
63,
262,
63,
827,
358,
267,
291,
14,
7516,
63,
5646,
275,
620,
8,
277,
14,
7516,
63,
262,
63,
827,
9,
435,
283,
4649,
7,
267,
291,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nazavode/automaton
|
src/automaton.py
|
2
|
24218
|
# -*- coding: utf-8 -*-
#
# Copyright 2015 Federico Ficarelli
#
# 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.
"""
A minimal finite-state machine implementation.
"""
import re
from weakref import WeakKeyDictionary
from itertools import chain, product, filterfalse
from collections import namedtuple, Iterable
import tabulate as tabulator
import networkx as nx
###################################################
__author__ = 'Federico Ficarelli'
__copyright__ = 'Copyright (c) 2015 Federico Ficarelli'
__license__ = 'Apache License Version 2.0'
__version__ = '1.3.1'
VERSION = __version__
# bumpversion can only search for {current_version}
# so we have to parse the version here.
version_info_t = namedtuple('version_info_t', 'major minor patch') # pylint: disable=invalid-name
VERSION_INFO = version_info_t(*(int(part) for part in re.match(r'(\d+)\.(\d+).(\d+)', __version__).groups()))
###################################################
__all__ = (
"Event",
"Automaton",
"AutomatonError",
"DefinitionError",
"InvalidTransitionError",
"transitiontable",
"stategraph",
"get_table",
)
class AutomatonError(Exception):
""" Exception representing a generic error occurred in the automaton. """
pass
class DefinitionError(AutomatonError):
""" Exception representing an error occurred during the automaton definition. """
pass
class InvalidTransitionError(AutomatonError):
""" Exception representing an invalid transition. """
pass
EventBase = namedtuple("Event", ("source_states", "dest_state"))
def unique_everseen(iterable, key=None): # pragma: no cover
"""List unique elements, preserving order. Remember all elements ever seen.
>>> list(unique_everseen('AAAABBBCCDAABBB'))
['A', 'B', 'C', 'D']
>>> list(unique_everseen('ABBCcAD', str.lower))
['A', 'B', 'C', 'D']
.. note::
Recipe taken from: https://docs.python.org/3.6/library/itertools.html
"""
seen = set()
seen_add = seen.add
if key is None:
for element in filterfalse(seen.__contains__, iterable):
seen_add(element)
yield element
else:
for element in iterable:
k = key(element)
if k not in seen:
seen_add(k)
yield element
class _EventProxy(object): # pylint: disable=too-few-public-methods
""" Proxy class to access :class:`~automaton.Event`
attributes.
Forwards every attribute access to the underlying proxied
:class:`~automaton.Event`.
.. important:
Unlike :class:`~automaton.Event`, instances of this type
are callables that trigger event transition in the proxied
:class:`~automaton.Automaton` instance.
"""
def __init__(self, event, automaton):
self.__event = event
self.__automaton = automaton
def __getattr__(self, name):
return getattr(self.__event, name)
def __call__(self):
return self.__automaton.event(self.name)
class Event(EventBase):
""" Class that represents a state transition.
.. important::
This is a read-only data descriptor type.
Parameters
----------
source_states : any
The transition source state.
dest_state : any
The transition destination state.
"""
def __new__(cls, source_states, dest_state):
# Fix source states:
if isinstance(source_states, str) or not isinstance(source_states, Iterable):
source_states = (source_states,)
instance = super().__new__(cls, source_states, dest_state)
instance._event_name = None # pylint: disable=protected-access
instance._event_delegate = None # pylint: disable=protected-access
return instance
@property
def name(self):
""" The actual user-defined name of the event as an
:class:`~automaton.Automaton` class member.
If None, the Event isn't bounded to any specific
:class:`~automaton.Automaton` subclass. """
return self._event_name
def edges(self, data=False):
""" Provides all the single transition edges associated
to this event.
.. note::
Since an event can have multiple source states,
in graph terms it represents a set of state-to-state
edges.
Parameters
----------
data : bool, optional
If set, data associated to the corresponding edge
will be added to the edge tuple. Defaults to `False`.
Yields
------
(any, any) or (any, any, dict)
All the `(source, dest)` tuples representing the graph
edges associated to the event. If `data` parameter is set,
each tuple will be appended with the `dict` containing
edge data (by default the `'event'` key containing the
event name).
"""
components = [self.source_states, (self.dest_state, )]
if data:
components.append((dict(event=self.name), ))
yield from product(*components)
def _bind(self, name):
""" Binds the :class:`~automaton.Event` instance
to a particular event name.
.. warning::
This method is intended to be called by the automaton
definition mechanics.
Parameters
----------
name : str
The event name to be bounded.
"""
self._event_name = name
def __get__(self, instance, owner):
""" Enables the descriptor semantics on
:class:`~automaton.Event` instances. """
if instance is None:
return self
else:
if not hasattr(self, '__bound_instances'):
# pylint: disable=attribute-defined-outside-init
self.__bound_instances = WeakKeyDictionary()
if instance not in self.__bound_instances:
self.__bound_instances[instance] = _EventProxy(event=self, automaton=instance)
return self.__bound_instances[instance]
def __set__(self, instance, value):
""" Enables the descriptor semantics on
:class:`~automaton.Event` instances.
Raises
------
AttributeError
To enforce read-only data descriptor semantics.
"""
raise AttributeError("Can't set attribute")
class AutomatonMeta(type):
""" The metaclass that must be applied on the ``automaton``-enabled classes'
hierarchy.
The :meth:`~automaton.AutomatonMeta.__new__` method builds the
actual finite-state machine based on the user-provided events definition.
Raises
------
DefinitionError
If the states graph isn't connected (that is leads to unreachable states).
"""
def __new__(mcs, class_name, class_bases, class_dict):
cls = super().__new__(mcs, class_name, class_bases, class_dict)
events = {}
states = set()
for attr in dir(cls):
value = getattr(cls, attr)
if isinstance(value, Event):
# Important: bind event to its name as a class member
value._bind(attr) # pylint: disable=protected-access
# Collect states
states.update(value[0]) # Iterable of sources states, let's update the set
states.add(value[1])
# Collect events
events[attr] = value
if len(states) != 0: # if we are dealing with an automaton definition class...
# 1. Setup class members:
cls.__states__ = states
cls.__events__ = events
if cls.__default_initial_state__ is not None \
and cls.__default_initial_state__ not in cls.__states__:
raise DefinitionError("Default initial state '{}' unknown.".format(cls.__default_initial_state__))
if cls.__default_accepting_states__ is not None:
for state in cls.__default_accepting_states__:
if state not in cls.__states__:
raise DefinitionError("Default accepting state '{}' unknown.".format(state))
# 2. Build graph
graph = nx.MultiDiGraph()
graph.add_nodes_from(states)
graph.add_edges_from(chain.from_iterable(list(event.edges(data=True)) for event in events.values()))
# 3. Check states graph consistency:
if not nx.is_weakly_connected(graph):
components = list(nx.weakly_connected_component_subgraphs(graph))
raise DefinitionError(
"The state graph contains {} connected components: {}".format(
len(components), ", ".join("{}".format(c.nodes()) for c in components))
)
# 4. Save
cls.__graph__ = nx.freeze(graph)
# 5. Docstring substitution
if cls.__doc__:
cls.__doc__ = cls.__doc__.format(automaton=cls)
return cls
def __format__(cls, fmt):
return __automaton_format__(cls, fmt)
class Automaton(metaclass=AutomatonMeta):
""" Base class for automaton types.
In order to define an automaton, this class must be the base for the
provided machine definition:
>>> class MyClass(Automaton):
... transition = Event("state_a", "state_b")
Parameters
----------
initial_state : any, optional
The initial state for this automaton instance. Defaults to None.
Note that if automaton type has no default initial state
(specified via :attr:`~automaton.__default_initial_state__`),
this argument must be specified.
initial_event : any, optional
The initial event to be fired to deduce the initial state.
Defaults to `None`. Please note that `initial_state` and
and `initial_event` arguments *are mutually exclusive*,
specifying both of them will raise a `TypeError`.
.. note::
Since the *destination state* of an event is a *single state*
and due to the fact that events are class attributes
(so each event name is unique), *deducing the initial state
through a initial event is a well defined operation*.
accepting_states : iterable, optional
The accepting states for this automaton instance. Defaults to None.
Note that if automaton type has default accepting states
(specified via :attr:`~automaton.__default_accepting_states__`),
this argument takes precedence over that.
Raises
------
DefinitionError
The automaton type has no default initial state while no
custom initial state specified during construction *or* the
specified initial state is unknown.
TypeError
Both `initial_state` and `initial_event` arguments have been
specified while they are mutually exclusive.
"""
__default_initial_state__ = None
"""any: The default initial state for the automaton type."""
__default_accepting_states__ = None
"""iterable: The default accepting states for the automaton type."""
def __init__(self, initial_state=None, initial_event=None, accepting_states=None):
#
# 0. Initial event setup
#
if initial_event:
if initial_state:
raise TypeError("'initial_state' and 'initial_event' parameters can't be specified together")
if initial_event not in self.__events__: # pylint: disable=no-member
raise InvalidTransitionError("Unrecognized event '{}'.".format(initial_event))
initial_state = getattr(self, initial_event).dest_state
#
# 1. Initial state setup
#
if initial_state is None:
if self.__default_initial_state__ is None:
raise DefinitionError(
"No default initial state defined for '{}', must be specified "
"in costruction.".format(self.__class__)
)
else:
initial_state = self.__default_initial_state__
# Check initial state correctness
if initial_state not in self.__states__: # pylint: disable=no-member
raise DefinitionError("Initial state '{}' unknown.".format(initial_state))
# ...and finally set initial state.
self._state = initial_state
#
# 2. Accepting states setup
#
if accepting_states is None:
if self.__default_accepting_states__ is None:
accepting_states = ()
else:
accepting_states = self.__default_accepting_states__
for state in accepting_states:
if state not in self.__states__: # pylint: disable=no-member
raise DefinitionError("Accepting state '{}' unknown.".format(state))
# ...and finally set accepting states.
self._accepting_states = frozenset(accepting_states)
@property
def state(self):
""" Gets the current state of the automaton instance.
Returns
-------
any
The current state.
"""
return self._state
@property
def is_accepted(self):
""" Gets the current automaton's acceptance state.
Returns
-------
bool
True if the current state is an accepting state, False otherwise.
"""
return self._state in self._accepting_states
def event(self, event_name):
""" Signals the occurrence of an event and evolves the automaton
to the destination state.
Parameters
----------
do_event : any
The event to be performed on the automaton.
Raises
------
InvalidTransitionError
The specified event is unknown.
"""
if event_name not in self.__events__: # pylint: disable=no-member
raise InvalidTransitionError("Unrecognized event '{}'.".format(event_name))
transition = self.__events__[event_name] # pylint: disable=no-member
if self._state not in transition.source_states:
raise InvalidTransitionError(
"The specified event '{}' is invalid in current state '{}'.".format(transition, self._state))
self._state = transition.dest_state
@classmethod
def _get_cut(cls, *states, inbound=True):
""" Retrieves all the events that form a cut for the
specified subgraphs.
Parameters
----------
states : tuple(any)
The states subset.
inbound : bool
If set, the inbound events will be returned,
outbound otherwise. Defaults to `True`.
Raises
------
KeyError
When an unknown state is found while iterating.
Yields
------
any
All the inbound or outbound events.
"""
unknown = set(states) - cls.__states__ # pylint: disable=no-member
if unknown:
raise KeyError("Unknown states: {}".format(unknown))
edges_getter = \
cls.__graph__.in_edges if inbound else cls.__graph__.out_edges # pylint: disable=no-member
yield from unique_everseen(
edge[2]['event'] for edge in edges_getter(states, data=True)
)
@classmethod
def states(cls):
""" Gives the automaton state set.
Yields
------
any
The iterator over the state set.
"""
yield from cls.__states__ # pylint: disable=no-member
@classmethod
def events(cls):
""" Gives the automaton events set.
Yields
------
any
The iterator over the events set.
"""
yield from cls.__events__ # pylint: disable=no-member
@classmethod
def in_events(cls, *states):
""" Retrieves all the inbound events entering the
specified states with no duplicates.
Parameters
----------
states : tuple(any)
The states subset.
Raises
------
KeyError
When an unknown state is found while iterating.
Yields
------
any
The events entering the specified states.
"""
yield from cls._get_cut(*states, inbound=True)
@classmethod
def out_events(cls, *states):
""" Retrieves all the outbound events leaving the
specified states with no duplicates.
Raises
------
KeyError
When an unknown state is found while iterating.
Parameters
----------
states : tuple(any)
The states subset.
Yields
------
any
The events that exit the specified states.
"""
yield from cls._get_cut(*states, inbound=False)
@classmethod
def get_default_initial_state(cls):
""" Gives the automaton default initial state.
Returns
-------
any
The automaton default initial state.
"""
return cls.__default_initial_state__
def __str__(self):
return '<{}@{}>'.format(self.__class__.__name__, self.state)
def __format__(self, fmt):
return __automaton_format__(self, fmt)
#########################################################################
# Rendering stuff, everything beyond this point is formatting for humans.
def __automaton_format__(automaton, fmt):
""" Support for custom format specifiers.
Parameters
----------
automaton : :class:`~automaton.Automaton`
The automaton to be formatted. It can be both an
instance or a class.
fmt : str
The format specifier.
Returns
-------
str
The string representation according to the rquested
format specifier.
"""
cls = automaton.__class__ if isinstance(automaton, Automaton) else automaton
if fmt in stategraph.SUPPORTED_FORMATS:
return stategraph(cls, fmt=fmt)
elif fmt in transitiontable.SUPPORTED_FORMATS:
return transitiontable(cls, fmt=fmt)
else:
return str(automaton)
def get_table(automaton, traversal=None):
""" Build the transition table of the given automaton.
Parameters
----------
automaton : :class:`~automaton.Automaton`
The automaton to be rendered. It can be both
a class and an instance.
traversal : callable(graph), optional
An optional callable used to yield the
edges of the graph representation of the
automaton. It must accept a `networkx.MultiDiGraph`
as the first positional argument
and yield one edge at a time as a tuple in the
form ``(source_state, destination_state)``. The default
traversal sorts the states in ascending order by
inbound grade (number of incoming events).
Yields
------
tuple(source, dest, event)
Yields one row at a time as a tuple containing
the source and destination node of the edge and
the name of the event associated with the edge.
"""
graph = automaton.__graph__
if not traversal:
traversal = lambda G: sorted(G.edges(), key=lambda e: len(G.in_edges(e[0])))
# Retrieve event names since networkx traversal
# functions lack data retrieval
events = nx.get_edge_attributes(graph, 'event') # -> (source, dest, key==0): event
# Build raw data table to be rendered
for source, dest in traversal(graph):
yield (source, dest, events[source, dest, 0])
def stategraph(automaton, fmt=None, traversal=None): # pylint: disable=unused-argument
""" Render an automaton's state-transition graph.
A simple example will be formatted as follows:
>>> class TrafficLight(Automaton):
... go = Event('red', 'green')
... slowdown = Event('green', 'yellow')
... stop = Event('yellow', 'red')
>>> print( plantuml(TrafficLight) ) # doctest: +SKIP
::
@startuml
green --> yellow : slowdown
yellow --> red : stop
red --> green : go
@enduml
Parameters
----------
automaton : :class:`~automaton.Automaton`
The automaton to be rendered. It can be both
a class and an instance.
fmt : str, optional
Specifies the output format for the graph.
Currently, the only supported format is
`PlantUML <http://plantuml.com/state-diagram>`_.
Defaults to ``plantuml``, unknown format specifiers
are ignored.
traversal : callable(graph), optional
An optional callable used to sort the events.
It has the same meaning as the ``traversal``
parameter of `automaton.transition_table`.
Returns
-------
str
Returns the formatted state graph.
"""
graph = automaton.__graph__
source_nodes = filter(lambda n: not graph.in_edges(n), graph.nodes())
sink_nodes = filter(lambda n: not graph.out_edges(n), graph.nodes())
sources = [('[*]', node) for node in source_nodes]
sinks = [(node, '[*]') for node in sink_nodes]
table = get_table(automaton, traversal=traversal)
return """@startuml
{}
{}
{}
@enduml""".format('\n'.join([' {} --> {}'.format(*row) for row in sources]),
'\n'.join([' {} --> {} : {}'.format(*row) for row in table]),
'\n'.join([' {} --> {}'.format(*row) for row in sinks]))
stategraph.SUPPORTED_FORMATS = frozenset([
'plantuml',
])
def transitiontable(automaton, header=None, fmt=None, traversal=None):
""" Render an automaton's transition table in
text format.
The transition table has three columns: source node,
destination node and the name of the event.
A simple example will be formatted as follows:
>>> class TrafficLight(Automaton):
... go = Event('red', 'green')
... slowdown = Event('green', 'yellow')
... stop = Event('yellow', 'red')
>>> tabulate(TrafficLight) # doctest: +SKIP
::
======== ====== ========
Source Dest Event
======== ====== ========
green yellow slowdown
yellow red stop
red green go
======== ====== ========
Parameters
----------
automaton : :class:`~automaton.Automaton`
The automaton to be rendered. It can be both
a class and an instance.
header : list[str, str, str]
An optional list of fields to be used as table
headers. Defaults to a predefined header.
fmt str, optional
Specifies the output format for the table.
All formats supported by
`tabulate <https://pypi.python.org/pypi/tabulate>`_
package are supported (e.g.: ``rst`` for
reStructuredText, ``pipe`` for Markdown).
Defaults to ``rst``.
traversal : callable(graph), optional
An optional callable used to sort the events.
It has the same meaning as the ``traversal``
parameter of `automaton.transition_table`.
Returns
-------
str
Returns the formatted transition table.
"""
header = header or ['Source', 'Dest', 'Event']
fmt = fmt or 'rst'
table = get_table(automaton=automaton, traversal=traversal)
return tabulator.tabulate(table, header, tablefmt=fmt)
transitiontable.SUPPORTED_FORMATS = frozenset([
'plain', 'simple', 'grid', 'fancy_grid', 'pipe', 'orgtbl',
'jira', 'psql', 'rst', 'mediawiki', 'moinmoin', 'html', 'latex',
'latex_booktabs', 'textile'
])
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
6900,
7949,
9910,
331,
481,
530,
1530,
13876,
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,
624,
199,
33,
13460,
21837,
13,
929,
6844,
4514,
14,
199,
624,
199,
199,
646,
295,
199,
504,
13852,
492,
28224,
1197,
11728,
199,
504,
7975,
492,
6036,
12,
3336,
12,
2457,
3910,
199,
504,
5055,
492,
12863,
12,
19937,
199,
199,
646,
5174,
5434,
465,
5174,
6109,
199,
646,
24313,
465,
8484,
421,
199,
22529,
5680,
199,
363,
2502,
363,
275,
283,
3456,
9910,
331,
481,
530,
1530,
13876,
7,
199,
363,
7307,
363,
275,
283,
7384,
334,
67,
9,
6900,
7949,
9910,
331,
481,
530,
1530,
13876,
7,
199,
363,
1682,
363,
275,
283,
28993,
844,
3394,
499,
14,
16,
7,
199,
363,
1023,
363,
275,
283,
17,
14,
19,
14,
17,
7,
199,
199,
4612,
275,
636,
1023,
363,
199,
3,
28108,
1023,
883,
1454,
2754,
367,
469,
1818,
63,
1023,
93,
199,
3,
880,
781,
1172,
370,
2198,
314,
1015,
2348,
14,
199,
1023,
63,
815,
63,
84,
275,
12863,
360,
1023,
63,
815,
63,
84,
297,
283,
8452,
12612,
3371,
358,
221,
327,
4287,
26,
3507,
29,
3197,
13,
354,
199,
4612,
63,
4531,
275,
1015,
63,
815,
63,
84,
29316,
442,
8,
2064,
9,
367,
1777,
315,
295,
14,
1431,
8,
82,
13445,
68,
13439,
14,
2961,
68,
11,
680,
2961,
68,
14705,
636,
1023,
28634,
2634,
4059,
199,
22529,
5680,
421,
199,
363,
452,
363,
275,
334,
272,
298,
2390,
401,
272,
298,
3358,
569,
265,
401,
272,
298,
3358,
569,
265,
547,
401,
272,
298,
10701,
547,
401,
272,
298,
3364,
21881,
547,
401,
272,
298,
14143,
1224,
401,
272,
298,
929,
2180,
401,
272,
298,
362,
63,
1224,
401,
199,
9,
421,
199,
533,
9195,
569,
265,
547,
8,
1726,
304,
272,
408,
2186,
6144,
282,
7809,
1125,
8920,
315,
314,
2599,
569,
265,
14,
408,
272,
986,
421,
199,
533,
29398,
547,
8,
3358,
569,
265,
547,
304,
272,
408,
2186,
6144,
376,
1125,
8920,
5309,
314,
2599,
569,
265,
5492,
14,
408,
272,
986,
421,
199,
533,
6378,
21881,
547,
8,
3358,
569,
265,
547,
304,
272,
408,
2186,
6144,
376,
3866,
14116,
14,
408,
272,
986,
421,
199,
2390,
1563,
275,
12863,
480,
2390,
401,
1689,
1365,
63,
4981,
401,
298,
2614,
63,
929,
2237,
421,
199,
318,
3747,
63,
69,
2077,
287,
8,
8147,
12,
790,
29,
403,
304,
221,
327,
11942,
26,
949,
8486,
272,
408,
1296,
3747,
4008,
12,
876,
14717,
1865,
14,
31859,
1006,
4008,
14433,
6775,
14,
398,
1306,
769,
8,
3235,
63,
69,
2077,
287,
360,
10985,
1217,
5342,
2571,
8980,
1217,
5342,
1333,
267,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
418,
267,
1306,
769,
8,
3235,
63,
69,
2077,
287,
360,
1217,
6265,
67,
1554,
297,
620,
14,
2325,
430,
267,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
418,
339,
2508,
5317,
447,
267,
799,
8233,
9394,
687,
26,
4178,
921,
4757,
14,
1548,
14,
1308,
15,
19,
14,
22,
15,
4342,
15,
17691,
14,
1360,
272,
408,
272,
6775,
275,
663,
342,
272,
6775,
63,
525,
275,
6775,
14,
525,
272,
340,
790,
365,
488,
26,
267,
367,
1819,
315,
2457,
3910,
8,
8606,
855,
6134,
3108,
6076,
304,
288,
6775,
63,
525,
8,
2108,
9,
288,
1995,
1819,
272,
587,
26,
267,
367,
1819,
315,
6076,
26,
288,
1022,
275,
790,
8,
2108,
9,
288,
340,
1022,
440,
315,
6775,
26,
355,
6775,
63,
525,
8,
75,
9,
355,
1995,
1819,
421,
199,
533,
485,
2390,
4936,
8,
785,
304,
221,
327,
4287,
26,
3507,
29,
7354,
13,
70,
546,
13,
3455,
13,
2474,
272,
408,
12373,
1021,
370,
2879,
520,
533,
6054,
2495,
569,
265,
14,
2390,
64,
272,
3004,
14,
339,
2104,
4751,
4036,
2225,
2879,
370,
314,
8793,
10645,
5299,
272,
520,
533,
6054,
2495,
569,
265,
14,
2390,
2313,
339,
2508,
11012,
26,
267,
25059,
520,
533,
6054,
2495,
569,
265,
14,
2390,
3559,
4454,
402,
642,
730,
267,
787,
28041,
626,
6804,
1566,
14116,
315,
314,
10645,
5299,
267,
520,
533,
6054,
2495,
569,
265,
14,
3358,
569,
265,
64,
1256,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1566,
12,
2599,
569,
265,
304,
267,
291,
855,
1430,
275,
1566,
267,
291,
855,
2495,
569,
265,
275,
2599,
569,
265,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
372,
2519,
8,
277,
855,
1430,
12,
536,
9,
339,
347,
636,
1250,
721,
277,
304,
267,
372,
291,
855,
2495,
569,
265,
14,
1430,
8,
277,
14,
354,
9,
421,
199,
533,
6763,
8,
2390,
1563,
304,
272,
408,
8089,
626,
8469,
282,
1174,
14116,
14,
339,
2508,
11012,
447,
267,
961,
365,
282,
1586,
13,
2118,
666,
5872,
730,
14,
339,
3897,
272,
4143,
272,
1350,
63,
4981,
520,
1263,
267,
710,
14116,
1350,
1174,
14,
272,
2053,
63,
929,
520,
1263,
267,
710,
14116,
5724,
1174,
14,
272,
408,
339,
347,
636,
1222,
721,
1886,
12,
1350,
63,
4981,
12,
2053,
63,
929,
304,
267,
327,
14811,
1350,
6363,
26,
267,
340,
1228,
8,
1365,
63,
4981,
12,
620,
9,
503,
440,
1228,
8,
1365,
63,
4981,
12,
19937,
304,
288,
1350,
63,
4981,
275,
334,
1365,
63,
4981,
4258,
267,
1256,
275,
1613,
11027,
1222,
721,
1886,
12,
1350
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
6900,
7949,
9910,
331,
481,
530,
1530,
13876,
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,
624,
199,
33,
13460,
21837,
13,
929,
6844,
4514,
14,
199,
624,
199,
199,
646,
295,
199,
504,
13852,
492,
28224,
1197,
11728,
199,
504,
7975,
492,
6036,
12,
3336,
12,
2457,
3910,
199,
504,
5055,
492,
12863,
12,
19937,
199,
199,
646,
5174,
5434,
465,
5174,
6109,
199,
646,
24313,
465,
8484,
421,
199,
22529,
5680,
199,
363,
2502,
363,
275,
283,
3456,
9910,
331,
481,
530,
1530,
13876,
7,
199,
363,
7307,
363,
275,
283,
7384,
334,
67,
9,
6900,
7949,
9910,
331,
481,
530,
1530,
13876,
7,
199,
363,
1682,
363,
275,
283,
28993,
844,
3394,
499,
14,
16,
7,
199,
363,
1023,
363,
275,
283,
17,
14,
19,
14,
17,
7,
199,
199,
4612,
275,
636,
1023,
363,
199,
3,
28108,
1023,
883,
1454,
2754,
367,
469,
1818,
63,
1023,
93,
199,
3,
880,
781,
1172,
370,
2198,
314,
1015,
2348,
14,
199,
1023,
63,
815,
63,
84,
275,
12863,
360,
1023,
63,
815,
63,
84,
297,
283,
8452,
12612,
3371,
358,
221,
327,
4287,
26,
3507,
29,
3197,
13,
354,
199,
4612,
63,
4531,
275,
1015,
63,
815,
63,
84,
29316,
442,
8,
2064,
9,
367,
1777,
315,
295,
14,
1431,
8,
82,
13445,
68,
13439,
14,
2961,
68,
11,
680,
2961,
68,
14705,
636,
1023,
28634,
2634,
4059,
199,
22529,
5680,
421,
199,
363,
452,
363,
275,
334,
272,
298,
2390,
401,
272,
298,
3358,
569,
265,
401,
272,
298,
3358,
569,
265,
547,
401,
272,
298,
10701,
547,
401,
272,
298,
3364,
21881,
547,
401,
272,
298,
14143,
1224,
401,
272,
298,
929,
2180,
401,
272,
298,
362,
63,
1224,
401,
199,
9,
421,
199,
533,
9195,
569,
265,
547,
8,
1726,
304,
272,
408,
2186,
6144,
282,
7809,
1125,
8920,
315,
314,
2599,
569,
265,
14,
408,
272,
986,
421,
199,
533,
29398,
547,
8,
3358,
569,
265,
547,
304,
272,
408,
2186,
6144,
376,
1125,
8920,
5309,
314,
2599,
569,
265,
5492,
14,
408,
272,
986,
421,
199,
533,
6378,
21881,
547,
8,
3358,
569,
265,
547,
304,
272,
408,
2186,
6144,
376,
3866,
14116,
14,
408,
272,
986,
421,
199,
2390,
1563,
275,
12863,
480,
2390,
401,
1689,
1365,
63,
4981,
401,
298,
2614,
63,
929,
2237,
421,
199,
318,
3747,
63,
69,
2077,
287,
8,
8147,
12,
790,
29,
403,
304,
221,
327,
11942,
26,
949,
8486,
272,
408,
1296,
3747,
4008,
12,
876,
14717,
1865,
14,
31859,
1006,
4008,
14433,
6775,
14,
398,
1306,
769,
8,
3235,
63,
69,
2077,
287,
360,
10985,
1217,
5342,
2571,
8980,
1217,
5342,
1333,
267,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
418,
267,
1306,
769,
8,
3235,
63,
69,
2077,
287,
360,
1217,
6265,
67,
1554,
297,
620,
14,
2325,
430,
267,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
418,
339,
2508,
5317,
447,
267,
799,
8233,
9394,
687,
26,
4178,
921,
4757,
14,
1548,
14,
1308,
15,
19,
14,
22,
15,
4342,
15,
17691,
14,
1360,
272,
408,
272,
6775,
275,
663,
342,
272,
6775,
63,
525,
275,
6775,
14,
525,
272,
340,
790,
365,
488,
26,
267,
367,
1819,
315,
2457,
3910,
8,
8606,
855,
6134,
3108,
6076,
304,
288,
6775,
63,
525,
8,
2108,
9,
288,
1995,
1819,
272,
587,
26,
267,
367,
1819,
315,
6076,
26,
288,
1022,
275,
790,
8,
2108,
9,
288,
340,
1022,
440,
315,
6775,
26,
355,
6775,
63,
525,
8,
75,
9,
355,
1995,
1819,
421,
199,
533,
485,
2390,
4936,
8,
785,
304,
221,
327,
4287,
26,
3507,
29,
7354,
13,
70,
546,
13,
3455,
13,
2474,
272,
408,
12373,
1021,
370,
2879,
520,
533,
6054,
2495,
569,
265,
14,
2390,
64,
272,
3004,
14,
339,
2104,
4751,
4036,
2225,
2879,
370,
314,
8793,
10645,
5299,
272,
520,
533,
6054,
2495,
569,
265,
14,
2390,
2313,
339,
2508,
11012,
26,
267,
25059,
520,
533,
6054,
2495,
569,
265,
14,
2390,
3559,
4454,
402,
642,
730,
267,
787,
28041,
626,
6804,
1566,
14116,
315,
314,
10645,
5299,
267,
520,
533,
6054,
2495,
569,
265,
14,
3358,
569,
265,
64,
1256,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1566,
12,
2599,
569,
265,
304,
267,
291,
855,
1430,
275,
1566,
267,
291,
855,
2495,
569,
265,
275,
2599,
569,
265,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
372,
2519,
8,
277,
855,
1430,
12,
536,
9,
339,
347,
636,
1250,
721,
277,
304,
267,
372,
291,
855,
2495,
569,
265,
14,
1430,
8,
277,
14,
354,
9,
421,
199,
533,
6763,
8,
2390,
1563,
304,
272,
408,
8089,
626,
8469,
282,
1174,
14116,
14,
339,
2508,
11012,
447,
267,
961,
365,
282,
1586,
13,
2118,
666,
5872,
730,
14,
339,
3897,
272,
4143,
272,
1350,
63,
4981,
520,
1263,
267,
710,
14116,
1350,
1174,
14,
272,
2053,
63,
929,
520,
1263,
267,
710,
14116,
5724,
1174,
14,
272,
408,
339,
347,
636,
1222,
721,
1886,
12,
1350,
63,
4981,
12,
2053,
63,
929,
304,
267,
327,
14811,
1350,
6363,
26,
267,
340,
1228,
8,
1365,
63,
4981,
12,
620,
9,
503,
440,
1228,
8,
1365,
63,
4981,
12,
19937,
304,
288,
1350,
63,
4981,
275,
334,
1365,
63,
4981,
4258,
267,
1256,
275,
1613,
11027,
1222,
721,
1886,
12,
1350,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
LaynePeng/magnum
|
magnum/db/sqlalchemy/migration.py
|
8
|
3663
|
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import alembic
from alembic import config as alembic_config
import alembic.migration as alembic_migration
from oslo_db import exception as db_exc
from magnum.db.sqlalchemy import api as sqla_api
from magnum.db.sqlalchemy import models
def _alembic_config():
path = os.path.join(os.path.dirname(__file__), 'alembic.ini')
config = alembic_config.Config(path)
return config
def version(config=None, engine=None):
"""Current database version.
:returns: Database version
:rtype: string
"""
if engine is None:
engine = sqla_api.get_engine()
with engine.connect() as conn:
context = alembic_migration.MigrationContext.configure(conn)
return context.get_current_revision()
def upgrade(revision, config=None):
"""Used for upgrading database.
:param version: Desired database version
:type version: string
"""
revision = revision or 'head'
config = config or _alembic_config()
alembic.command.upgrade(config, revision or 'head')
def create_schema(config=None, engine=None):
"""Create database schema from models description.
Can be used for initial installation instead of upgrade('head').
"""
if engine is None:
engine = sqla_api.get_engine()
# NOTE(viktors): If we will use metadata.create_all() for non empty db
# schema, it will only add the new tables, but leave
# existing as is. So we should avoid of this situation.
if version(engine=engine) is not None:
raise db_exc.DbMigrationError("DB schema is already under version"
" control. Use upgrade() instead")
models.Base.metadata.create_all(engine)
stamp('head', config=config)
def downgrade(revision, config=None):
"""Used for downgrading database.
:param version: Desired database version
:type version: string
"""
revision = revision or 'base'
config = config or _alembic_config()
return alembic.command.downgrade(config, revision)
def stamp(revision, config=None):
"""Stamps database with provided revision.
Don't run any migrations.
:param revision: Should match one from repository or head - to stamp
database with most recent revision
:type revision: string
"""
config = config or _alembic_config()
return alembic.command.stamp(config, revision=revision)
def revision(message=None, autogenerate=False, config=None):
"""Creates template for migration.
:param message: Text that will be used for migration title
:type message: string
:param autogenerate: If True - generates diff based on current database
state
:type autogenerate: bool
"""
config = config or _alembic_config()
return alembic.command.revision(config, message=message,
autogenerate=autogenerate)
|
apache-2.0
|
[
3,
1898,
7129,
1910,
5703,
24230,
598,
27639,
465,
11159,
701,
314,
199,
3,
30660,
402,
314,
20548,
437,
281,
265,
3844,
7769,
436,
19326,
9516,
4633,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
747,
199,
199,
646,
30960,
20596,
199,
504,
30960,
20596,
492,
1101,
465,
30960,
20596,
63,
888,
199,
646,
30960,
20596,
14,
8998,
465,
30960,
20596,
63,
8998,
199,
504,
11258,
63,
697,
492,
1919,
465,
1592,
63,
2804,
199,
199,
504,
15916,
453,
14,
697,
14,
14536,
492,
2986,
465,
5295,
416,
63,
1246,
199,
504,
15916,
453,
14,
697,
14,
14536,
492,
1709,
421,
199,
318,
485,
1895,
20596,
63,
888,
837,
272,
931,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
1895,
20596,
14,
2730,
358,
272,
1101,
275,
30960,
20596,
63,
888,
14,
2028,
8,
515,
9,
272,
372,
1101,
421,
199,
318,
1015,
8,
888,
29,
403,
12,
6869,
29,
403,
304,
272,
408,
5639,
3050,
1015,
14,
339,
520,
5808,
26,
8692,
1015,
272,
520,
4500,
26,
1059,
272,
408,
272,
340,
6869,
365,
488,
26,
267,
6869,
275,
5295,
416,
63,
1246,
14,
362,
63,
3908,
342,
272,
543,
6869,
14,
2242,
342,
465,
2557,
26,
267,
1067,
275,
30960,
20596,
63,
8998,
14,
9816,
2998,
14,
6472,
8,
1631,
9,
267,
372,
1067,
14,
362,
63,
1818,
63,
5792,
342,
421,
199,
318,
10754,
8,
5792,
12,
1101,
29,
403,
304,
272,
408,
9167,
367,
1536,
16050,
3050,
14,
339,
520,
635,
1015,
26,
1487,
5381,
3050,
1015,
272,
520,
466,
1015,
26,
1059,
272,
408,
272,
6974,
275,
6974,
503,
283,
2993,
7,
272,
1101,
275,
1101,
503,
485,
1895,
20596,
63,
888,
342,
339,
30960,
20596,
14,
1531,
14,
9375,
8,
888,
12,
6974,
503,
283,
2993,
358,
421,
199,
318,
1218,
63,
3629,
8,
888,
29,
403,
12,
6869,
29,
403,
304,
272,
408,
2499,
3050,
4177,
687,
1709,
1369,
14,
339,
6855,
506,
1202,
367,
2536,
12096,
3140,
402,
10754,
360,
2993,
1959,
272,
408,
272,
340,
6869,
365,
488,
26,
267,
6869,
275,
5295,
416,
63,
1246,
14,
362,
63,
3908,
342,
339,
327,
6944,
8,
433,
5973,
1384,
304,
982,
781,
911,
675,
3341,
14,
981,
63,
452,
342,
367,
2222,
2701,
1592,
272,
327,
4483,
4177,
12,
652,
911,
1454,
1050,
314,
892,
6716,
12,
1325,
10137,
272,
327,
4483,
3411,
465,
365,
14,
2002,
781,
1077,
5126,
402,
642,
25781,
14,
272,
340,
1015,
8,
3908,
29,
3908,
9,
365,
440,
488,
26,
267,
746,
1592,
63,
2804,
14,
8882,
9816,
547,
480,
2846,
4177,
365,
2575,
1334,
1015,
2,
4228,
298,
3304,
14,
3645,
10754,
342,
3140,
531,
339,
1709,
14,
1563,
14,
2343,
14,
981,
63,
452,
8,
3908,
9,
272,
16206,
360,
2993,
297,
1101,
29,
888,
9,
421,
199,
318,
32498,
8,
5792,
12,
1101,
29,
403,
304,
272,
408,
9167,
367,
3224,
16050,
3050,
14,
339,
520,
635,
1015,
26,
1487,
5381,
3050,
1015,
272,
520,
466,
1015,
26,
1059,
272,
408,
272,
6974,
275,
6974,
503,
283,
1095,
7,
272,
1101,
275,
1101,
503,
485,
1895,
20596,
63,
888,
342,
272,
372,
30960,
20596,
14,
1531,
14,
2110,
4523,
8,
888,
12,
6974,
9,
421,
199,
318,
16206,
8,
5792,
12,
1101,
29,
403,
304,
272,
408,
3391,
13408,
3050,
543,
2741,
6974,
14,
339,
7529,
1133,
1255,
1263,
6180,
14,
339,
520,
635,
6974,
26,
7719,
1336,
1373,
687,
7611,
503,
4854,
446,
370,
16206,
2151,
3050,
543,
4750,
8058,
6974,
272,
520,
466,
6974,
26,
1059,
272,
408,
272,
1101,
275,
1101,
503,
485,
1895,
20596,
63,
888,
342,
272,
372,
30960,
20596,
14,
1531,
14,
2359,
8,
888,
12,
6974,
29,
5792,
9,
421,
199,
318,
6974,
8,
1188,
29,
403,
12,
6384,
974,
22978,
29,
797,
12,
1101,
29,
403,
304,
272,
408,
10607,
1978,
367,
8367,
14,
339,
520,
635,
1245,
26,
4516,
626,
911,
506,
1202,
367,
8367,
2538,
272,
520,
466,
1245,
26,
1059,
272,
520,
635,
6384,
974,
22978,
26,
982,
715,
446,
12821,
3915,
4079,
641,
1453,
3050,
586,
1174,
272,
520,
466,
6384,
974,
22978,
26,
2155,
272,
408,
272,
1101,
275,
1101,
503,
485,
1895,
20596,
63,
888,
342,
272,
372,
30960,
20596,
14,
1531,
14,
5792,
8,
888,
12,
1245,
29,
1188,
12,
2511,
6384,
974,
22978,
29,
6898,
974,
22978,
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
] |
[
1898,
7129,
1910,
5703,
24230,
598,
27639,
465,
11159,
701,
314,
199,
3,
30660,
402,
314,
20548,
437,
281,
265,
3844,
7769,
436,
19326,
9516,
4633,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
747,
199,
199,
646,
30960,
20596,
199,
504,
30960,
20596,
492,
1101,
465,
30960,
20596,
63,
888,
199,
646,
30960,
20596,
14,
8998,
465,
30960,
20596,
63,
8998,
199,
504,
11258,
63,
697,
492,
1919,
465,
1592,
63,
2804,
199,
199,
504,
15916,
453,
14,
697,
14,
14536,
492,
2986,
465,
5295,
416,
63,
1246,
199,
504,
15916,
453,
14,
697,
14,
14536,
492,
1709,
421,
199,
318,
485,
1895,
20596,
63,
888,
837,
272,
931,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
1895,
20596,
14,
2730,
358,
272,
1101,
275,
30960,
20596,
63,
888,
14,
2028,
8,
515,
9,
272,
372,
1101,
421,
199,
318,
1015,
8,
888,
29,
403,
12,
6869,
29,
403,
304,
272,
408,
5639,
3050,
1015,
14,
339,
520,
5808,
26,
8692,
1015,
272,
520,
4500,
26,
1059,
272,
408,
272,
340,
6869,
365,
488,
26,
267,
6869,
275,
5295,
416,
63,
1246,
14,
362,
63,
3908,
342,
272,
543,
6869,
14,
2242,
342,
465,
2557,
26,
267,
1067,
275,
30960,
20596,
63,
8998,
14,
9816,
2998,
14,
6472,
8,
1631,
9,
267,
372,
1067,
14,
362,
63,
1818,
63,
5792,
342,
421,
199,
318,
10754,
8,
5792,
12,
1101,
29,
403,
304,
272,
408,
9167,
367,
1536,
16050,
3050,
14,
339,
520,
635,
1015,
26,
1487,
5381,
3050,
1015,
272,
520,
466,
1015,
26,
1059,
272,
408,
272,
6974,
275,
6974,
503,
283,
2993,
7,
272,
1101,
275,
1101,
503,
485,
1895,
20596,
63,
888,
342,
339,
30960,
20596,
14,
1531,
14,
9375,
8,
888,
12,
6974,
503,
283,
2993,
358,
421,
199,
318,
1218,
63,
3629,
8,
888,
29,
403,
12,
6869,
29,
403,
304,
272,
408,
2499,
3050,
4177,
687,
1709,
1369,
14,
339,
6855,
506,
1202,
367,
2536,
12096,
3140,
402,
10754,
360,
2993,
1959,
272,
408,
272,
340,
6869,
365,
488,
26,
267,
6869,
275,
5295,
416,
63,
1246,
14,
362,
63,
3908,
342,
339,
327,
6944,
8,
433,
5973,
1384,
304,
982,
781,
911,
675,
3341,
14,
981,
63,
452,
342,
367,
2222,
2701,
1592,
272,
327,
4483,
4177,
12,
652,
911,
1454,
1050,
314,
892,
6716,
12,
1325,
10137,
272,
327,
4483,
3411,
465,
365,
14,
2002,
781,
1077,
5126,
402,
642,
25781,
14,
272,
340,
1015,
8,
3908,
29,
3908,
9,
365,
440,
488,
26,
267,
746,
1592,
63,
2804,
14,
8882,
9816,
547,
480,
2846,
4177,
365,
2575,
1334,
1015,
2,
4228,
298,
3304,
14,
3645,
10754,
342,
3140,
531,
339,
1709,
14,
1563,
14,
2343,
14,
981,
63,
452,
8,
3908,
9,
272,
16206,
360,
2993,
297,
1101,
29,
888,
9,
421,
199,
318,
32498,
8,
5792,
12,
1101,
29,
403,
304,
272,
408,
9167,
367,
3224,
16050,
3050,
14,
339,
520,
635,
1015,
26,
1487,
5381,
3050,
1015,
272,
520,
466,
1015,
26,
1059,
272,
408,
272,
6974,
275,
6974,
503,
283,
1095,
7,
272,
1101,
275,
1101,
503,
485,
1895,
20596,
63,
888,
342,
272,
372,
30960,
20596,
14,
1531,
14,
2110,
4523,
8,
888,
12,
6974,
9,
421,
199,
318,
16206,
8,
5792,
12,
1101,
29,
403,
304,
272,
408,
3391,
13408,
3050,
543,
2741,
6974,
14,
339,
7529,
1133,
1255,
1263,
6180,
14,
339,
520,
635,
6974,
26,
7719,
1336,
1373,
687,
7611,
503,
4854,
446,
370,
16206,
2151,
3050,
543,
4750,
8058,
6974,
272,
520,
466,
6974,
26,
1059,
272,
408,
272,
1101,
275,
1101,
503,
485,
1895,
20596,
63,
888,
342,
272,
372,
30960,
20596,
14,
1531,
14,
2359,
8,
888,
12,
6974,
29,
5792,
9,
421,
199,
318,
6974,
8,
1188,
29,
403,
12,
6384,
974,
22978,
29,
797,
12,
1101,
29,
403,
304,
272,
408,
10607,
1978,
367,
8367,
14,
339,
520,
635,
1245,
26,
4516,
626,
911,
506,
1202,
367,
8367,
2538,
272,
520,
466,
1245,
26,
1059,
272,
520,
635,
6384,
974,
22978,
26,
982,
715,
446,
12821,
3915,
4079,
641,
1453,
3050,
586,
1174,
272,
520,
466,
6384,
974,
22978,
26,
2155,
272,
408,
272,
1101,
275,
1101,
503,
485,
1895,
20596,
63,
888,
342,
272,
372,
30960,
20596,
14,
1531,
14,
5792,
8,
888,
12,
1245,
29,
1188,
12,
2511,
6384,
974,
22978,
29,
6898,
974,
22978,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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c) 2011-2014, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder 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 HOLDER 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 re
import sys
import copy
# For Python 2.x/3.x compatibility
try:
from itertools import izip as zip
from itertools import imap as map
except:
pass
# =====================================================================
""" Context classes, used during propagation and the "to PFW script" step """
# =====================================================================
class PropagationContextItem(list) :
"""Handle an item during the propagation step"""
def __copy__(self):
"""C.__copy__() -> a shallow copy of C"""
return self.__class__(self)
class PropagationContextElement(PropagationContextItem) :
"""Handle an Element during the propagation step"""
def getElementsFromName(self, name):
matchingElements = []
for element in self :
if element.getName() == name :
matchingElements.append(element)
return matchingElements
class PropagationContextOption(PropagationContextItem) :
"""Handle an Option during the propagation step"""
def getOptionItems (self, itemName):
items = []
for options in self :
items.append(options.getOption(itemName))
return items
class PropagationContext() :
"""Handle the context during the propagation step"""
def __init__(self, propagationContext=None) :
if propagationContext == None :
self._context = {
"DomainOptions" : PropagationContextOption() ,
"Configurations" : PropagationContextElement() ,
"ConfigurationOptions" : PropagationContextOption() ,
"Rules" : PropagationContextElement() ,
"PathOptions" : PropagationContextOption() ,
}
else :
self._context = propagationContext
def copy(self):
"""return a copy of the context"""
contextCopy = self._context.copy()
for key in iter(self._context) :
contextCopy[key] = contextCopy[key].__copy__()
return self.__class__(contextCopy)
def getDomainOptions (self):
return self._context["DomainOptions"]
def getConfigurations (self):
return self._context["Configurations"]
def getConfigurationOptions (self):
return self._context["ConfigurationOptions"]
def getRules (self):
return self._context["Rules"]
def getPathOptions (self):
return self._context["PathOptions"]
# =====================================================
"""Element option container"""
# =====================================================
class Options () :
"""handle element options"""
def __init__(self, options=[], optionNames=[]) :
self.options = dict(zip(optionNames, options))
# print(options,optionNames,self.options)
def __str__(self) :
ops2str = []
for name, argument in list(self.options.items()) :
ops2str.append(str(name) + "=\"" + str(argument) + "\"")
return " ".join(ops2str)
def getOption(self, name):
"""get option by its name, if it does not exist return empty string"""
return self.options.get(name, "")
def setOption(self, name, newOption):
"""set option by its name"""
self.options[name] = newOption
def copy (self):
"""D.copy() -> a shallow copy of D"""
copy = Options()
copy.options = self.options.copy()
return copy
# ====================================================
"""Definition of all element class"""
# ====================================================
class Element(object):
""" implement a basic element
It is the class base for all other elements as Domain, Configuration..."""
tag = "unknown"
optionNames = ["Name"]
childWhiteList = []
optionDelimiter = " "
def __init__(self, line=None) :
if line == None :
self.option = Options([], self.optionNames)
else :
self.option = self.optionFromLine(line)
self.children = []
def optionFromLine(self, line) :
# get ride of spaces
line = line.strip()
options = self.extractOptions(line)
return Options(options, self.optionNames)
def extractOptions(self, line) :
"""return the line splited by the optionDelimiter atribute
Option list length is less or equal to the optionNames list length
"""
options = line.split(self.optionDelimiter, len(self.optionNames) - 1)
# get ride of leftover spaces
optionsStrip = list(map(str.strip, options))
return optionsStrip
def addChild(self, child, append=True) :
""" A.addChid(B) -> add B to A child list if B class name is in A white List"""
try:
# Will raise an exception if this child is not in the white list
self.childWhiteList.index(child.__class__.__name__)
# If no exception was raised, add child to child list
if append :
self.children.append(child)
else :
self.children.insert(0, child)
except ValueError:
# the child class is not in the white list
raise ChildNotPermitedError("", self, child)
def addChildren(self, children, append=True) :
"""Add a list of child"""
if append:
# Add children at the end of the child list
self.children.extend(children)
else:
# Add children at the begining of the child list
self.children = children + self.children
def childrenToString(self, prefix=""):
"""return raw printed children """
body = ""
for child in self.children :
body = body + child.__str__(prefix)
return body
def __str__(self, prefix="") :
"""return raw printed element"""
selfToString = prefix + " " + self.tag + " " + str(self.option)
return selfToString + "\n" + self.childrenToString(prefix + "\t")
def extractChildrenByClass(self, classTypeList) :
"""return all children whose class is in the list argument
return a list of all children whose class in the list "classTypeList" (second arguments)"""
selectedChildren = []
for child in self.children :
for classtype in classTypeList :
if child.__class__ == classtype :
selectedChildren.append(child)
break
return selectedChildren
def propagate (self, context=PropagationContext()):
"""call the propagate method of all children"""
for child in self.children :
child.propagate(context)
def getName(self):
"""return name option value. If none return "" """
return self.option.getOption("Name")
def setName(self, name):
self.option.setOption("Name", name)
def translate(self, translator):
for child in self.children:
child.translate(translator)
# ----------------------------------------------------------
class ElementWithTag (Element):
"""Element of this class are declared with a tag => line == "tag: .*" """
def extractOptions(self, line) :
lineWithoutTag = line.split(":", 1)[-1].strip()
options = super(ElementWithTag, self).extractOptions(lineWithoutTag)
return options
# ----------------------------------------------------------
class ElementWithInheritance(Element):
def propagate (self, context=PropagationContext) :
"""propagate some proprieties to children"""
# copy the context so that everything that hapend next will only affect
# children
contextCopy = context.copy()
# check for inheritance
self.Inheritance(contextCopy)
# call the propagate method of all children
super(ElementWithInheritance, self).propagate(contextCopy)
class ElementWithRuleInheritance(ElementWithInheritance):
"""class that will give to its children its rules"""
def ruleInheritance(self, context):
"""Add its rules to the context and get context rules"""
# extract all children rule and operator
childRules = self.extractChildrenByClass([Operator, Rule])
# get context rules
contextRules = context.getRules()
# adopt rules of the beginning of the context
self.addChildren(contextRules, append=False)
# add previously extract rules to the context
contextRules += childRules
# ----------------------------------------------------------
class EmptyLine (Element) :
"""This class represents an empty line.
Will raise "EmptyLineWarning" exception at instanciation."""
tag = "emptyLine"
match = re.compile(r"[ \t]*\n?$").match
def __init__ (self, line):
raise EmptyLineWarning(line)
# ----------------------------------------------------------
class Commentary(Element):
"""This class represents a commentary.
Will raise "CommentWarning" exception at instanciation."""
tag = "commentary"
optionNames = ["comment"]
match = re.compile(r"#").match
def __init__ (self, line):
raise CommentWarning(line)
# ----------------------------------------------------------
class Path (ElementWithInheritance) :
"""class implementing the "path = value" concept"""
tag = "path"
optionNames = ["Name", "value"]
match = re.compile(r".+=").match
optionDelimiter = "="
def translate(self, translator):
translator.setParameter(self.getName(), self.option.getOption("value"))
def Inheritance (self, context) :
"""check for path name inheritance"""
self.OptionsInheritance(context)
def OptionsInheritance (self, context) :
"""make configuration name inheritance """
context.getPathOptions().append(self.option.copy())
self.setName("/".join(context.getPathOptions().getOptionItems("Name")))
class GroupPath (Path, ElementWithTag) :
tag = "component"
match = re.compile(tag + r" *:").match
optionNames = ["Name"]
childWhiteList = ["Path", "GroupPath"]
def getPathNames (self) :
"""Return the list of all path child name"""
pathNames = []
paths = self.extractChildrenByClass([Path])
for path in paths :
pathNames.append(path.getName())
groupPaths = self.extractChildrenByClass([GroupPath])
for groupPath in groupPaths :
pathNames += groupPath.getPathNames()
return pathNames
def translate(self, translator):
for child in self.extractChildrenByClass([Path, GroupPath]):
child.translate(translator)
# ----------------------------------------------------------
class Rule (Element) :
"""class implementing the rule concept
A rule is composed of a criterion, a rule type and an criterion state.
It should not have any child and is propagated to all configuration in parent descendants.
"""
tag = "rule"
optionNames = ["criterion", "type", "element"]
match = re.compile(r"[a-zA-Z0-9_.]+ +(Is|IsNot|Includes|Excludes) +[a-zA-Z0-9_.]+").match
childWhiteList = []
def PFWSyntax (self, prefix=""):
script = prefix + \
self.option.getOption("criterion") + " " + \
self.option.getOption("type") + " " + \
self.option.getOption("element")
return script
class Operator (Rule) :
"""class implementing the operator concept
An operator contains rules and other operators
It is as rules propagated to all configuration children in parent descendants.
It should only have the name ANY or ALL to be understood by PFW.
"""
tag = "operator"
optionNames = ["Name"]
match = re.compile(r"ANY|ALL").match
childWhiteList = ["Rule", "Operator"]
syntax = { "ANY" : "Any" , "ALL" : "All"}
def PFWSyntax (self, prefix=""):
""" return a pfw rule (ex : "Any{criterion1 is state1}") generated from "self" and its children options"""
script = ""
script += prefix + \
self.syntax[self.getName()] + "{ "
rules = self.extractChildrenByClass([Rule, Operator])
PFWRules = []
for rule in rules :
PFWRules.append(rule.PFWSyntax(prefix + " "))
script += (" , ").join(PFWRules)
script += prefix + " }"
return script
# ----------------------------------------------------------
class Configuration (ElementWithRuleInheritance, ElementWithTag) :
tag = "configuration"
optionNames = ["Name"]
match = re.compile(r"conf *:").match
childWhiteList = ["Rule", "Operator", "Path", "GroupPath"]
def composition (self, context):
"""make all needed composition
Composition is the fact that group configuration with the same name defined
in a parent will give their rule children to this configuration
"""
name = self.getName()
sameNameConf = context.getConfigurations().getElementsFromName(name)
sameNameConf.reverse()
for configuration in sameNameConf :
# add same name configuration rule children to self child list
self.addChildren(configuration.extractChildrenByClass([Operator, Rule]), append=False)
def propagate (self, context=PropagationContext) :
"""propagate proprieties to children
make needed compositions, join ancestor name to its name,
and add rules previously defined rules"""
# make all needed composition
self.composition(context)
super(Configuration, self).propagate(context)
def Inheritance (self, context) :
"""make configuration name and rule inheritance"""
# check for configuration name inheritance
self.OptionsInheritance(context)
# check for rule inheritance
self.ruleInheritance(context)
def OptionsInheritance (self, context) :
"""make configuration name inheritance """
context.getConfigurationOptions().append(self.option.copy())
self.setName(".".join(context.getConfigurationOptions().getOptionItems("Name")))
def getRootPath (self) :
paths = self.extractChildrenByClass([Path, GroupPath])
rootPath = GroupPath()
rootPath.addChildren(paths)
return rootPath
def getConfigurableElements (self) :
"""return all path name defined in this configuration"""
return self.getRootPath().getPathNames()
def getRuleString(self):
"""Output this configuration's rule as a string"""
# Create a rootRule
ruleChildren = self.extractChildrenByClass([Rule, Operator])
# Do not create a root rule if there is only one fist level Operator rule
if len(ruleChildren) == 1 and ruleChildren[0].__class__ == Operator :
ruleroot = ruleChildren[0]
else :
ruleroot = Operator()
ruleroot.setName("ALL")
ruleroot.addChildren(ruleChildren)
return ruleroot.PFWSyntax()
def translate(self, translator):
translator.createConfiguration(self.getName())
translator.setRule(self.getRuleString())
paths = self.extractChildrenByClass([Path, GroupPath])
translator.setElementSequence(self.getConfigurableElements())
for path in paths:
path.translate(translator)
def copy (self) :
"""return a shallow copy of the configuration"""
# create configuration or subclass copy
confCopy = self.__class__()
# add children
confCopy.children = list(self.children)
# add option
confCopy.option = self.option.copy()
return confCopy
class GroupConfiguration (Configuration) :
tag = "GroupConfiguration"
optionNames = ["Name"]
match = re.compile(r"(supConf|confGroup|confType) *:").match
childWhiteList = ["Rule", "Operator", "GroupConfiguration", "Configuration", "GroupPath"]
def composition (self, context) :
"""add itself in context for configuration composition
Composition is the fact that group configuration with the same name defined
in a parent will give their rule children to this configuration
"""
# copyItself
selfCopy = self.copy()
# make all needed composition
super(GroupConfiguration, self).composition(context)
# add the copy in context for futur configuration composition
context.getConfigurations().append(selfCopy)
def getConfigurableElements (self) :
"""return a list. Each elements consist of a list of configurable element of a configuration
return a list consisting of all configurable elements for each configuration.
These configurable elements are organized in a list"""
configurableElements = []
configurations = self.extractChildrenByClass([Configuration])
for configuration in configurations :
configurableElements.append(configuration.getConfigurableElements())
groudeConfigurations = self.extractChildrenByClass([GroupConfiguration])
for groudeConfiguration in groudeConfigurations :
configurableElements += groudeConfiguration.getConfigurableElements()
return configurableElements
def translate(self, translator):
for child in self.extractChildrenByClass([Configuration, GroupConfiguration]):
child.translate(translator)
# ----------------------------------------------------------
class Domain (ElementWithRuleInheritance, ElementWithTag) :
tag = "domain"
sequenceAwareKeyword = "sequenceAware"
match = re.compile(r"domain *:").match
optionNames = ["Name", sequenceAwareKeyword]
childWhiteList = ["Configuration", "GroupConfiguration", "Rule", "Operator"]
def propagate (self, context=PropagationContext) :
""" propagate name, sequenceAwareness and rule to children"""
# call the propagate method of all children
super(Domain, self).propagate(context)
self.checkConfigurableElementUnicity()
def Inheritance (self, context) :
"""check for domain name, sequence awarness and rules inheritance"""
# check for domain name and sequence awarness inheritance
self.OptionsInheritance(context)
# check for rule inheritance
self.ruleInheritance(context)
def OptionsInheritance(self, context) :
""" make domain name and sequence awareness inheritance
join to the domain name all domain names defined in context and
if any domain in context is sequence aware, set sequenceAwareness to True"""
# add domain options to context
context.getDomainOptions().append(self.option.copy())
# set name to the junction of all domain name in context
self.setName(".".join(context.getDomainOptions().getOptionItems("Name")))
# get sequenceAwareness of all domains in context
sequenceAwareList = context.getDomainOptions().getOptionItems(self.sequenceAwareKeyword)
# or operation on all booleans in sequenceAwareList
sequenceAwareness = False
for sequenceAware in sequenceAwareList :
sequenceAwareness = sequenceAwareness or sequenceAware
# current domain sequenceAwareness = sequenceAwareness
self.option.setOption(self.sequenceAwareKeyword, sequenceAwareness)
def extractOptions(self, line) :
"""Extract options from the definition line"""
options = super(Domain, self).extractOptions(line)
sequenceAwareIndex = self.optionNames.index(self.sequenceAwareKeyword)
# translate the keyword self.sequenceAwareKeyword if specified to boolean True,
# to False otherwise
try :
if options[sequenceAwareIndex] == self.sequenceAwareKeyword :
options[sequenceAwareIndex] = True
else:
options[sequenceAwareIndex] = False
except IndexError :
options = options + [None] * (sequenceAwareIndex - len(options)) + [False]
return options
def getRootConfiguration (self) :
"""return the root configuration group"""
configurations = self.extractChildrenByClass([Configuration, GroupConfiguration])
configurationRoot = GroupConfiguration()
configurationRoot.addChildren(configurations)
return configurationRoot
# TODO: don't do that in the parser, let the PFW tell you that
def checkConfigurableElementUnicity (self):
""" check that all configurable elements defined in child configuration are the sames"""
# get a list. Each elements of is the configurable element list of a configuration
configurableElementsList = self.getRootConfiguration().getConfigurableElements()
# if at least two configurations in the domain
if len(configurableElementsList) > 1 :
# get first configuration configurable element list sort
configurableElementsList0 = list(configurableElementsList[0])
configurableElementsList0.sort()
for configurableElements in configurableElementsList :
# sort current configurable element list
auxConfigurableElements = list(configurableElements)
auxConfigurableElements.sort()
if auxConfigurableElements != configurableElementsList0 :
# if different, 2 configurations those not have the same configurable element list
# => one or more configurable element is missing in one of the 2 configuration
raise UndefinedParameter(self.getName())
def translate(self, translator):
sequence_aware = self.option.getOption(self.sequenceAwareKeyword)
translator.createDomain(self.getName(), sequence_aware)
configurations = self.getRootConfiguration()
configurableElementsList = configurations.getConfigurableElements()
# add configurable elements
if len(configurableElementsList) != 0 :
for configurableElement in configurableElementsList[0] :
translator.addElement(configurableElement)
configurations.translate(translator)
class GroupDomain (Domain) :
tag = "groupDomain"
match = re.compile(r"(supDomain|domainGroup) *:").match
childWhiteList = ["GroupDomain", "Domain", "GroupConfiguration", "Rule", "Operator"]
def translate(self, translator):
for child in self.extractChildrenByClass([Domain, GroupDomain]):
child.translate(translator)
# ----------------------------------------------------------
class Root(Element):
tag = "root"
childWhiteList = ["Domain", "GroupDomain"]
# ===========================================
""" Syntax error Exceptions"""
# ===========================================
class MySyntaxProblems(SyntaxError) :
comment = "syntax error in %(line)s "
def __init__(self, line=None, num=None):
self.setLine(line, num)
def __str__(self):
if self.line :
self.comment = self.comment % {"line" : repr(self.line)}
if self.num :
self.comment = "Line " + str(self.num) + ", " + self.comment
return self.comment
def setLine (self, line, num):
self.line = str(line)
self.num = num
# ---------------------------------------------------------
class MyPropagationError(MySyntaxProblems) :
""" Syntax error Exceptions used in the propagation step"""
pass
class UndefinedParameter(MyPropagationError) :
comment = "Configurations in domain '%(domainName)s' do not all set the same parameters "
def __init__ (self, domainName):
self.domainName = domainName
def __str__ (self):
return self.comment % { "domainName" : self.domainName }
# -----------------------------------------------------
""" Syntax error Exceptions used by parser"""
class MySyntaxError(MySyntaxProblems) :
""" Syntax error Exceptions used by parser"""
pass
class MySyntaxWarning(MySyntaxProblems) :
""" Syntax warning Exceptions used by parser"""
pass
class IndentationSyntaxError(MySyntaxError) :
comment = """syntax error in %(line)s has no father element.
You can only increment indentation by one tabutation per line")"""
class EmptyLineWarning(MySyntaxWarning):
comment = "warning : %(line)s is an empty line and has been ommited"
class CommentWarning(MySyntaxWarning):
comment = "warning : %(line)s is a commentary and has been ommited"
class ChildNotPermitedError(MySyntaxError):
def __init__(self, line, fatherElement, childElement):
self.comment = "syntax error in %(line)s, " + fatherElement.tag + " should not have a " + childElement.tag + " child."
super(ChildNotPermitedError, self).__init__(line)
class UnknownElementTypeError(MySyntaxError):
comment = " error in line %(line)s , not known element type were matched "
class SpaceInIndentationError(MySyntaxError):
comment = " error in ,%(line)s space is not permited in indentation"
# ============================================
"""Class creating the DOM elements from a stream"""
# ============================================
class ElementsFactory(object) :
"""Element factory, return an instance of the first matching element
Test each element list in elementClass and instanciate it if it's methode match returns True
The method match is called with input line as argument
"""
def __init__ (self):
self.elementClass = [
EmptyLine ,
Commentary,
GroupDomain,
Domain,
Path,
GroupConfiguration,
Configuration,
Operator,
Rule,
GroupPath
]
def createElementFromLine (self, line) :
"""return an instance of the first matching element
Test each element list in elementClass and instanciate it if it's methode match returns True
The method match is called with the argument line.
Raise UnknownElementTypeError if no element matched.
"""
for element in self.elementClass :
if element.match(line) :
# print (line + element.__class__.__name__)
return element(line)
# if we have not find any
raise UnknownElementTypeError(line)
#------------------------------------------------------
class Parser(object) :
"""Class implementing the parser"""
def __init__(self):
self.rankPattern = re.compile(r"^([\t ]*)(.*)")
self.elementFactory = ElementsFactory()
self.previousRank = 0
def __parseLine__(self, line):
rank, rest = self.__getRank__(line)
# instanciate the coresponding element
element = self.elementFactory.createElementFromLine(rest)
self.__checkIndentation__(rank)
return rank, element
def __getRank__(self, line):
"""return the rank, the name and the option of the input line
the rank is the number of tabulation (\t) at the line beginning.
the rest is the rest of the line."""
# split line in rank and rest
rank = self.rankPattern.match(line)
if rank :
rank, rest = rank.group(1, 2)
else :
raise MySyntaxError(line)
# check for empty line
if rest == "" :
raise EmptyLineWarning(line)
# check for space in indentation
if rank.find(" ") > -1 :
raise SpaceInIndentationError(line)
rank = len (rank) + 1 # rank starts at 1
return rank, rest
def __checkIndentation__(self, rank):
"""check if indentation > previous indentation + 1. If so, raise IndentationSyntaxError"""
if (rank > self.previousRank + 1) :
raise IndentationSyntaxError()
self.previousRank = rank
def parse(self, stream, verbose=False):
"""parse a stream, usually a opened file"""
myroot = Root("root")
context = [myroot] # root is element of rank 0
warnings = ""
for num, line in enumerate(stream):
try:
rank, myelement = self.__parseLine__(line)
while len(context) > rank :
context.pop()
context.append(myelement)
context[-2].addChild(myelement)
except MySyntaxWarning as ex:
ex.setLine(line, num + 1)
if verbose :
sys.stderr.write("{}\n".format(ex))
except MySyntaxErro as ex :
ex.setLine(line, num + 1)
raise
return myroot
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
18,
199,
3,
1882,
1523,
26,
1624,
13,
24,
446,
10,
199,
199,
3,
1898,
334,
67,
9,
7760,
13,
7280,
12,
20619,
11098,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
642,
199,
3,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
436,
15,
269,
199,
3,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
650,
14,
11443,
314,
536,
402,
314,
4248,
16712,
6590,
314,
1561,
402,
2399,
8417,
199,
3,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
1928,
199,
3,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
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,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
199,
3,
1821,
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,
5258,
199,
3,
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,
4388,
199,
646,
295,
199,
646,
984,
199,
646,
1331,
199,
3,
2104,
2018,
499,
14,
88,
15,
19,
14,
88,
7163,
199,
893,
26,
272,
687,
7975,
492,
28697,
465,
3482,
272,
687,
7975,
492,
23646,
465,
2341,
199,
2590,
26,
272,
986,
199,
199,
3,
7819,
532,
199,
624,
9470,
3992,
12,
1202,
5309,
17012,
436,
314,
298,
475,
17689,
55,
2884,
2,
3650,
408,
199,
3,
7819,
532,
199,
199,
533,
2165,
6861,
2998,
2081,
8,
513,
9,
520,
272,
408,
5940,
376,
1242,
5309,
314,
17012,
3650,
624,
272,
347,
636,
1574,
721,
277,
304,
267,
408,
35,
855,
1574,
4533,
1035,
282,
23834,
1331,
402,
445,
624,
267,
372,
291,
855,
533,
721,
277,
9,
199,
199,
533,
2165,
6861,
2998,
2162,
8,
11376,
2998,
2081,
9,
520,
272,
408,
5940,
376,
6566,
5309,
314,
17012,
3650,
624,
272,
347,
664,
6255,
2532,
985,
8,
277,
12,
536,
304,
267,
4877,
6255,
275,
942,
267,
367,
1819,
315,
291,
520,
288,
340,
1819,
14,
16405,
342,
508,
536,
520,
355,
4877,
6255,
14,
740,
8,
2108,
9,
267,
372,
4877,
6255,
421,
199,
533,
2165,
6861,
2998,
2602,
8,
11376,
2998,
2081,
9,
520,
272,
408,
5940,
376,
3207,
5309,
314,
17012,
3650,
624,
272,
347,
664,
2602,
7412,
334,
277,
12,
1242,
985,
304,
267,
2974,
275,
942,
267,
367,
1511,
315,
291,
520,
288,
2974,
14,
740,
8,
1419,
14,
362,
2602,
8,
1053,
985,
430,
267,
372,
2974,
421,
199,
533,
2165,
6861,
2998,
342,
520,
272,
408,
5940,
314,
1067,
5309,
314,
17012,
3650,
624,
272,
347,
636,
826,
721,
277,
12,
17012,
2998,
29,
403,
9,
520,
398,
340,
17012,
2998,
508,
488,
520,
288,
291,
423,
1100,
275,
469,
355,
298,
7705,
4558,
2,
520,
2165,
6861,
2998,
2602,
342,
2360,
355,
298,
25808,
2,
520,
2165,
6861,
2998,
2162,
342,
2360,
355,
298,
5688,
4558,
2,
520,
2165,
6861,
2998,
2602,
342,
2360,
355,
298,
12920,
2,
520,
2165,
6861,
2998,
2162,
342,
2360,
355,
298,
2042,
4558,
2,
520,
2165,
6861,
2998,
2602,
342,
2360,
267,
789,
267,
587,
520,
288,
291,
423,
1100,
275,
17012,
2998,
339,
347,
1331,
8,
277,
304,
267,
408,
1107,
282,
1331,
402,
314,
1067,
624,
267,
1067,
5116,
275,
291,
423,
1100,
14,
1574,
342,
398,
367,
790,
315,
2740,
8,
277,
423,
1100,
9,
520,
288,
1067,
5116,
59,
498,
61,
275,
1067,
5116,
59,
498,
17979,
1574,
4533,
398,
372,
291,
855,
533,
721,
1100,
5116,
9,
339,
347,
664,
7705,
4558,
334,
277,
304,
267,
372,
291,
423,
1100,
905,
7705,
4558,
937,
339,
347,
664,
25808,
334,
277,
304,
267,
372,
291,
423,
1100,
905,
25808,
937,
339,
347,
664,
5688,
4558,
334,
277,
304,
267,
372,
291,
423,
1100,
905,
5688,
4558,
937,
339,
347,
664,
12920,
334,
277,
304,
267,
372,
291,
423,
1100,
905,
12920,
937,
339,
347,
664,
2042,
4558,
334,
277,
304,
267,
372,
291,
423,
1100,
905,
2042,
4558,
937,
421,
199,
3,
19691,
532,
199,
624,
2162,
945,
3970,
624,
199,
3,
19691,
532,
199,
199,
533,
8394,
6248,
520,
272,
408,
2479,
1819,
1511,
624,
272,
347,
636,
826,
721,
277,
12,
1511,
6034,
945,
5866,
14285,
520,
267,
291,
14,
1419,
275,
1211,
8,
3065,
8,
1422,
5866,
12,
1511,
430,
267,
327,
870,
8,
1419,
12,
1422,
5866,
12,
277,
14,
1419,
9,
2378,
347,
636,
495,
721,
277,
9,
520,
267,
4156,
18,
495,
275,
942,
267,
367,
536,
12,
1423,
315,
769,
8,
277,
14,
1419,
14,
1744,
1012,
520,
288,
4156,
18,
495,
14,
740,
8,
495,
8,
354,
9,
435,
298,
9529,
341,
435,
620,
8,
2094,
9,
435,
1867,
7230,
398,
372,
298,
3680,
904,
8,
1483,
18,
495,
9,
339,
347,
664,
2602,
8,
277,
12,
536,
304,
267,
408,
362,
945,
701,
2399,
536,
12,
340,
652,
1630,
440,
2187,
372,
2701,
1059,
624,
267,
372,
291,
14,
1419,
14,
362,
8,
354,
12,
6899,
339,
347,
663,
2602,
8,
277,
12,
536,
12,
892,
2602,
304,
267,
408,
409,
945,
701
] |
[
2647,
15,
1393,
15,
1548,
18,
199,
3,
1882,
1523,
26,
1624,
13,
24,
446,
10,
199,
199,
3,
1898,
334,
67,
9,
7760,
13,
7280,
12,
20619,
11098,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
642,
199,
3,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
436,
15,
269,
199,
3,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
650,
14,
11443,
314,
536,
402,
314,
4248,
16712,
6590,
314,
1561,
402,
2399,
8417,
199,
3,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
1928,
199,
3,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
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,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
199,
3,
1821,
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,
5258,
199,
3,
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,
4388,
199,
646,
295,
199,
646,
984,
199,
646,
1331,
199,
3,
2104,
2018,
499,
14,
88,
15,
19,
14,
88,
7163,
199,
893,
26,
272,
687,
7975,
492,
28697,
465,
3482,
272,
687,
7975,
492,
23646,
465,
2341,
199,
2590,
26,
272,
986,
199,
199,
3,
7819,
532,
199,
624,
9470,
3992,
12,
1202,
5309,
17012,
436,
314,
298,
475,
17689,
55,
2884,
2,
3650,
408,
199,
3,
7819,
532,
199,
199,
533,
2165,
6861,
2998,
2081,
8,
513,
9,
520,
272,
408,
5940,
376,
1242,
5309,
314,
17012,
3650,
624,
272,
347,
636,
1574,
721,
277,
304,
267,
408,
35,
855,
1574,
4533,
1035,
282,
23834,
1331,
402,
445,
624,
267,
372,
291,
855,
533,
721,
277,
9,
199,
199,
533,
2165,
6861,
2998,
2162,
8,
11376,
2998,
2081,
9,
520,
272,
408,
5940,
376,
6566,
5309,
314,
17012,
3650,
624,
272,
347,
664,
6255,
2532,
985,
8,
277,
12,
536,
304,
267,
4877,
6255,
275,
942,
267,
367,
1819,
315,
291,
520,
288,
340,
1819,
14,
16405,
342,
508,
536,
520,
355,
4877,
6255,
14,
740,
8,
2108,
9,
267,
372,
4877,
6255,
421,
199,
533,
2165,
6861,
2998,
2602,
8,
11376,
2998,
2081,
9,
520,
272,
408,
5940,
376,
3207,
5309,
314,
17012,
3650,
624,
272,
347,
664,
2602,
7412,
334,
277,
12,
1242,
985,
304,
267,
2974,
275,
942,
267,
367,
1511,
315,
291,
520,
288,
2974,
14,
740,
8,
1419,
14,
362,
2602,
8,
1053,
985,
430,
267,
372,
2974,
421,
199,
533,
2165,
6861,
2998,
342,
520,
272,
408,
5940,
314,
1067,
5309,
314,
17012,
3650,
624,
272,
347,
636,
826,
721,
277,
12,
17012,
2998,
29,
403,
9,
520,
398,
340,
17012,
2998,
508,
488,
520,
288,
291,
423,
1100,
275,
469,
355,
298,
7705,
4558,
2,
520,
2165,
6861,
2998,
2602,
342,
2360,
355,
298,
25808,
2,
520,
2165,
6861,
2998,
2162,
342,
2360,
355,
298,
5688,
4558,
2,
520,
2165,
6861,
2998,
2602,
342,
2360,
355,
298,
12920,
2,
520,
2165,
6861,
2998,
2162,
342,
2360,
355,
298,
2042,
4558,
2,
520,
2165,
6861,
2998,
2602,
342,
2360,
267,
789,
267,
587,
520,
288,
291,
423,
1100,
275,
17012,
2998,
339,
347,
1331,
8,
277,
304,
267,
408,
1107,
282,
1331,
402,
314,
1067,
624,
267,
1067,
5116,
275,
291,
423,
1100,
14,
1574,
342,
398,
367,
790,
315,
2740,
8,
277,
423,
1100,
9,
520,
288,
1067,
5116,
59,
498,
61,
275,
1067,
5116,
59,
498,
17979,
1574,
4533,
398,
372,
291,
855,
533,
721,
1100,
5116,
9,
339,
347,
664,
7705,
4558,
334,
277,
304,
267,
372,
291,
423,
1100,
905,
7705,
4558,
937,
339,
347,
664,
25808,
334,
277,
304,
267,
372,
291,
423,
1100,
905,
25808,
937,
339,
347,
664,
5688,
4558,
334,
277,
304,
267,
372,
291,
423,
1100,
905,
5688,
4558,
937,
339,
347,
664,
12920,
334,
277,
304,
267,
372,
291,
423,
1100,
905,
12920,
937,
339,
347,
664,
2042,
4558,
334,
277,
304,
267,
372,
291,
423,
1100,
905,
2042,
4558,
937,
421,
199,
3,
19691,
532,
199,
624,
2162,
945,
3970,
624,
199,
3,
19691,
532,
199,
199,
533,
8394,
6248,
520,
272,
408,
2479,
1819,
1511,
624,
272,
347,
636,
826,
721,
277,
12,
1511,
6034,
945,
5866,
14285,
520,
267,
291,
14,
1419,
275,
1211,
8,
3065,
8,
1422,
5866,
12,
1511,
430,
267,
327,
870,
8,
1419,
12,
1422,
5866,
12,
277,
14,
1419,
9,
2378,
347,
636,
495,
721,
277,
9,
520,
267,
4156,
18,
495,
275,
942,
267,
367,
536,
12,
1423,
315,
769,
8,
277,
14,
1419,
14,
1744,
1012,
520,
288,
4156,
18,
495,
14,
740,
8,
495,
8,
354,
9,
435,
298,
9529,
341,
435,
620,
8,
2094,
9,
435,
1867,
7230,
398,
372,
298,
3680,
904,
8,
1483,
18,
495,
9,
339,
347,
664,
2602,
8,
277,
12,
536,
304,
267,
408,
362,
945,
701,
2399,
536,
12,
340,
652,
1630,
440,
2187,
372,
2701,
1059,
624,
267,
372,
291,
14,
1419,
14,
362,
8,
354,
12,
6899,
339,
347,
663,
2602,
8,
277,
12,
536,
12,
892,
2602,
304,
267,
408,
409,
945,
701,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
philsch/ansible
|
lib/ansible/module_utils/splitter.py
|
197
|
9433
|
# This code is part of Ansible, but is an independent component.
# This particular file snippet, and this file snippet only, is BSD licensed.
# Modules you write using this snippet, which is embedded dynamically by Ansible
# still belong to the author of the module, and may assign their own license
# to the complete work.
#
# Copyright (c), Michael DeHaan <michael.dehaan@gmail.com>, 2012-2013
# 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.
#
# 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 HOLDER 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.
def _get_quote_state(token, quote_char):
'''
the goal of this block is to determine if the quoted string
is unterminated in which case it needs to be put back together
'''
# the char before the current one, used to see if
# the current character is escaped
prev_char = None
for idx, cur_char in enumerate(token):
if idx > 0:
prev_char = token[idx - 1]
if cur_char in '"\'' and prev_char != '\\':
if quote_char:
if cur_char == quote_char:
quote_char = None
else:
quote_char = cur_char
return quote_char
def _count_jinja2_blocks(token, cur_depth, open_token, close_token):
'''
this function counts the number of opening/closing blocks for a
given opening/closing type and adjusts the current depth for that
block based on the difference
'''
num_open = token.count(open_token)
num_close = token.count(close_token)
if num_open != num_close:
cur_depth += (num_open - num_close)
if cur_depth < 0:
cur_depth = 0
return cur_depth
def split_args(args):
'''
Splits args on whitespace, but intelligently reassembles
those that may have been split over a jinja2 block or quotes.
When used in a remote module, we won't ever have to be concerned about
jinja2 blocks, however this function is/will be used in the
core portions as well before the args are templated.
example input: a=b c="foo bar"
example output: ['a=b', 'c="foo bar"']
Basically this is a variation shlex that has some more intelligence for
how Ansible needs to use it.
'''
# the list of params parsed out of the arg string
# this is going to be the result value when we are donei
params = []
# here we encode the args, so we have a uniform charset to
# work with, and split on white space
args = args.strip()
try:
args = args.encode('utf-8')
do_decode = True
except UnicodeDecodeError:
do_decode = False
items = args.split('\n')
# iterate over the tokens, and reassemble any that may have been
# split on a space inside a jinja2 block.
# ex if tokens are "{{", "foo", "}}" these go together
# These variables are used
# to keep track of the state of the parsing, since blocks and quotes
# may be nested within each other.
quote_char = None
inside_quotes = False
print_depth = 0 # used to count nested jinja2 {{ }} blocks
block_depth = 0 # used to count nested jinja2 {% %} blocks
comment_depth = 0 # used to count nested jinja2 {# #} blocks
# now we loop over each split chunk, coalescing tokens if the white space
# split occurred within quotes or a jinja2 block of some kind
for itemidx, item in enumerate(items):
# we split on spaces and newlines separately, so that we
# can tell which character we split on for reassembly
# inside quotation characters
tokens = item.strip().split(' ')
line_continuation = False
for idx, token in enumerate(tokens):
# if we hit a line continuation character, but
# we're not inside quotes, ignore it and continue
# on to the next token while setting a flag
if token == '\\' and not inside_quotes:
line_continuation = True
continue
# store the previous quoting state for checking later
was_inside_quotes = inside_quotes
quote_char = _get_quote_state(token, quote_char)
inside_quotes = quote_char is not None
# multiple conditions may append a token to the list of params,
# so we keep track with this flag to make sure it only happens once
# append means add to the end of the list, don't append means concatenate
# it to the end of the last token
appended = False
# if we're inside quotes now, but weren't before, append the token
# to the end of the list, since we'll tack on more to it later
# otherwise, if we're inside any jinja2 block, inside quotes, or we were
# inside quotes (but aren't now) concat this token to the last param
if inside_quotes and not was_inside_quotes:
params.append(token)
appended = True
elif print_depth or block_depth or comment_depth or inside_quotes or was_inside_quotes:
if idx == 0 and not inside_quotes and was_inside_quotes:
params[-1] = "%s%s" % (params[-1], token)
elif len(tokens) > 1:
spacer = ''
if idx > 0:
spacer = ' '
params[-1] = "%s%s%s" % (params[-1], spacer, token)
else:
spacer = ''
if not params[-1].endswith('\n') and idx == 0:
spacer = '\n'
params[-1] = "%s%s%s" % (params[-1], spacer, token)
appended = True
# if the number of paired block tags is not the same, the depth has changed, so we calculate that here
# and may append the current token to the params (if we haven't previously done so)
prev_print_depth = print_depth
print_depth = _count_jinja2_blocks(token, print_depth, "{{", "}}")
if print_depth != prev_print_depth and not appended:
params.append(token)
appended = True
prev_block_depth = block_depth
block_depth = _count_jinja2_blocks(token, block_depth, "{%", "%}")
if block_depth != prev_block_depth and not appended:
params.append(token)
appended = True
prev_comment_depth = comment_depth
comment_depth = _count_jinja2_blocks(token, comment_depth, "{#", "#}")
if comment_depth != prev_comment_depth and not appended:
params.append(token)
appended = True
# finally, if we're at zero depth for all blocks and not inside quotes, and have not
# yet appended anything to the list of params, we do so now
if not (print_depth or block_depth or comment_depth) and not inside_quotes and not appended and token != '':
params.append(token)
# if this was the last token in the list, and we have more than
# one item (meaning we split on newlines), add a newline back here
# to preserve the original structure
if len(items) > 1 and itemidx != len(items) - 1 and not line_continuation:
if not params[-1].endswith('\n') or item == '':
params[-1] += '\n'
# always clear the line continuation flag
line_continuation = False
# If we're done and things are not at zero depth or we're still inside quotes,
# raise an error to indicate that the args were unbalanced
if print_depth or block_depth or comment_depth or inside_quotes:
raise Exception("error while splitting arguments, either an unbalanced jinja2 block or quotes")
# finally, we decode each param back to the unicode it was in the arg string
if do_decode:
params = [x.decode('utf-8') for x in params]
return params
def is_quoted(data):
return len(data) > 0 and (data[0] == '"' and data[-1] == '"' or data[0] == "'" and data[-1] == "'")
def unquote(data):
''' removes first and last quotes from a string, if the string starts and ends with the same quotes '''
if is_quoted(data):
return data[1:-1]
return data
|
gpl-3.0
|
[
3,
961,
1233,
365,
1777,
402,
2622,
12,
1325,
365,
376,
12717,
3931,
14,
199,
3,
961,
6770,
570,
17440,
12,
436,
642,
570,
17440,
1454,
12,
365,
6289,
18233,
14,
199,
3,
18167,
1265,
2218,
1808,
642,
17440,
12,
1314,
365,
12169,
18774,
701,
2622,
199,
3,
5139,
13511,
370,
314,
4132,
402,
314,
859,
12,
436,
1443,
5090,
3932,
5705,
4190,
199,
3,
370,
314,
4890,
1736,
14,
199,
3,
199,
3,
1898,
334,
67,
395,
16922,
22453,
665,
22333,
14,
24247,
32,
6799,
14,
957,
6244,
6029,
13,
6965,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
420,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
420,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
420,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
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,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
199,
3,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
421,
199,
318,
485,
362,
63,
3513,
63,
929,
8,
1418,
12,
6313,
63,
1560,
304,
272,
1449,
272,
314,
14850,
402,
642,
1853,
365,
370,
6705,
340,
314,
10999,
1059,
272,
365,
625,
18375,
315,
1314,
1930,
652,
4839,
370,
506,
5324,
1771,
10451,
272,
1449,
272,
327,
314,
1495,
2544,
314,
1453,
1373,
12,
1202,
370,
1937,
340,
272,
327,
314,
1453,
4528,
365,
11077,
272,
5071,
63,
1560,
275,
488,
272,
367,
4280,
12,
1094,
63,
1560,
315,
3874,
8,
1418,
304,
267,
340,
4280,
690,
378,
26,
288,
5071,
63,
1560,
275,
1526,
59,
2996,
446,
413,
61,
267,
340,
1094,
63,
1560,
315,
283,
3212,
891,
436,
5071,
63,
1560,
1137,
29082,
288,
340,
6313,
63,
1560,
26,
355,
340,
1094,
63,
1560,
508,
6313,
63,
1560,
26,
490,
6313,
63,
1560,
275,
488,
288,
587,
26,
355,
6313,
63,
1560,
275,
1094,
63,
1560,
272,
372,
6313,
63,
1560,
421,
199,
318,
485,
835,
63,
12264,
18,
63,
4166,
8,
1418,
12,
1094,
63,
4631,
12,
1551,
63,
1418,
12,
4002,
63,
1418,
304,
272,
1449,
272,
642,
805,
8242,
314,
1329,
402,
13618,
15,
11707,
5664,
367,
282,
272,
1627,
13618,
15,
11707,
730,
436,
11311,
83,
314,
1453,
5818,
367,
626,
272,
1853,
4079,
641,
314,
8865,
272,
1449,
272,
1967,
63,
1490,
275,
1526,
14,
835,
8,
1490,
63,
1418,
9,
272,
1967,
63,
1600,
275,
1526,
14,
835,
8,
1600,
63,
1418,
9,
272,
340,
1967,
63,
1490,
1137,
1967,
63,
1600,
26,
267,
1094,
63,
4631,
847,
334,
1507,
63,
1490,
446,
1967,
63,
1600,
9,
267,
340,
1094,
63,
4631,
665,
378,
26,
288,
1094,
63,
4631,
275,
378,
272,
372,
1094,
63,
4631,
421,
199,
318,
3715,
63,
589,
8,
589,
304,
272,
1449,
272,
11740,
83,
1249,
641,
8139,
12,
1325,
4661,
24024,
590,
295,
21263,
83,
272,
5204,
626,
1443,
1172,
2757,
3715,
1806,
282,
10321,
18,
1853,
503,
9344,
14,
339,
3979,
1202,
315,
282,
3982,
859,
12,
781,
7859,
1133,
14433,
1172,
370,
506,
406,
2247,
7439,
3595,
272,
10321,
18,
5664,
12,
13432,
642,
805,
365,
15,
14117,
506,
1202,
315,
314,
272,
6170,
12468,
465,
5521,
2544,
314,
1249,
787,
27960,
14,
339,
2893,
1324,
26,
282,
29,
66,
286,
628,
1421,
4681,
2,
272,
2893,
1072,
26,
788,
65,
29,
66,
297,
283,
67,
628,
1421,
4681,
2,
418,
339,
10082,
1183,
642,
365,
282,
29844,
16701,
626,
965,
2005,
1655,
4661,
31566,
367,
272,
4212,
2622,
4839,
370,
675,
652,
14,
272,
1449,
339,
327,
314,
769,
402,
1862,
4565,
734,
402,
314,
1680,
1059,
272,
327,
642,
365,
9995,
370,
506,
314,
754,
574,
1380,
781,
787,
4224,
73,
272,
1862,
275,
942,
339,
327,
2348,
781,
3752,
314,
1249,
12,
880,
781,
1172,
282,
14818,
5960,
370,
272,
327,
1736,
543,
12,
436,
3715,
641,
10424,
4601,
272,
1249,
275,
1249,
14,
1913,
342,
272,
862,
26,
267,
1249,
275,
1249,
14,
2143,
360,
1624,
13,
24,
358,
267,
886,
63,
2708,
275,
715,
272,
871,
18965,
26,
267,
886,
63,
2708,
275,
756,
272,
2974,
275,
1249,
14,
1294,
2258,
78,
358,
339,
327,
13974,
1806,
314,
4645,
12,
436,
295,
21263,
1263,
626,
1443,
1172,
2757,
272,
327,
3715,
641,
282,
4601,
6272,
282,
10321,
18,
1853,
14,
272,
327,
444,
340,
4645,
787,
7370,
401,
298,
1421,
401,
298,
30618,
3520,
2621,
10451,
339,
327,
5723,
2860,
787,
1202,
272,
327,
370,
4215,
4426,
402,
314,
1174,
402,
314,
6057,
12,
3967,
5664,
436,
9344,
272,
327,
1443,
506,
6032,
4453,
1924,
1163,
14,
339,
6313,
63,
1560,
275,
488,
272,
6272,
63,
14005,
275,
756,
272,
870,
63,
4631,
275,
378,
221,
327,
1202,
370,
2338,
6032,
10321,
18,
8448,
3586,
5664,
272,
1853,
63,
4631,
275,
378,
221,
327,
1202,
370,
2338,
6032,
10321,
18,
7749,
3674,
5664,
272,
3721,
63,
4631,
275,
378,
221,
327,
1202,
370,
2338,
6032,
10321,
18,
469,
3,
327
] |
[
961,
1233,
365,
1777,
402,
2622,
12,
1325,
365,
376,
12717,
3931,
14,
199,
3,
961,
6770,
570,
17440,
12,
436,
642,
570,
17440,
1454,
12,
365,
6289,
18233,
14,
199,
3,
18167,
1265,
2218,
1808,
642,
17440,
12,
1314,
365,
12169,
18774,
701,
2622,
199,
3,
5139,
13511,
370,
314,
4132,
402,
314,
859,
12,
436,
1443,
5090,
3932,
5705,
4190,
199,
3,
370,
314,
4890,
1736,
14,
199,
3,
199,
3,
1898,
334,
67,
395,
16922,
22453,
665,
22333,
14,
24247,
32,
6799,
14,
957,
6244,
6029,
13,
6965,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
420,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
420,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
420,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
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,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
199,
3,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
421,
199,
318,
485,
362,
63,
3513,
63,
929,
8,
1418,
12,
6313,
63,
1560,
304,
272,
1449,
272,
314,
14850,
402,
642,
1853,
365,
370,
6705,
340,
314,
10999,
1059,
272,
365,
625,
18375,
315,
1314,
1930,
652,
4839,
370,
506,
5324,
1771,
10451,
272,
1449,
272,
327,
314,
1495,
2544,
314,
1453,
1373,
12,
1202,
370,
1937,
340,
272,
327,
314,
1453,
4528,
365,
11077,
272,
5071,
63,
1560,
275,
488,
272,
367,
4280,
12,
1094,
63,
1560,
315,
3874,
8,
1418,
304,
267,
340,
4280,
690,
378,
26,
288,
5071,
63,
1560,
275,
1526,
59,
2996,
446,
413,
61,
267,
340,
1094,
63,
1560,
315,
283,
3212,
891,
436,
5071,
63,
1560,
1137,
29082,
288,
340,
6313,
63,
1560,
26,
355,
340,
1094,
63,
1560,
508,
6313,
63,
1560,
26,
490,
6313,
63,
1560,
275,
488,
288,
587,
26,
355,
6313,
63,
1560,
275,
1094,
63,
1560,
272,
372,
6313,
63,
1560,
421,
199,
318,
485,
835,
63,
12264,
18,
63,
4166,
8,
1418,
12,
1094,
63,
4631,
12,
1551,
63,
1418,
12,
4002,
63,
1418,
304,
272,
1449,
272,
642,
805,
8242,
314,
1329,
402,
13618,
15,
11707,
5664,
367,
282,
272,
1627,
13618,
15,
11707,
730,
436,
11311,
83,
314,
1453,
5818,
367,
626,
272,
1853,
4079,
641,
314,
8865,
272,
1449,
272,
1967,
63,
1490,
275,
1526,
14,
835,
8,
1490,
63,
1418,
9,
272,
1967,
63,
1600,
275,
1526,
14,
835,
8,
1600,
63,
1418,
9,
272,
340,
1967,
63,
1490,
1137,
1967,
63,
1600,
26,
267,
1094,
63,
4631,
847,
334,
1507,
63,
1490,
446,
1967,
63,
1600,
9,
267,
340,
1094,
63,
4631,
665,
378,
26,
288,
1094,
63,
4631,
275,
378,
272,
372,
1094,
63,
4631,
421,
199,
318,
3715,
63,
589,
8,
589,
304,
272,
1449,
272,
11740,
83,
1249,
641,
8139,
12,
1325,
4661,
24024,
590,
295,
21263,
83,
272,
5204,
626,
1443,
1172,
2757,
3715,
1806,
282,
10321,
18,
1853,
503,
9344,
14,
339,
3979,
1202,
315,
282,
3982,
859,
12,
781,
7859,
1133,
14433,
1172,
370,
506,
406,
2247,
7439,
3595,
272,
10321,
18,
5664,
12,
13432,
642,
805,
365,
15,
14117,
506,
1202,
315,
314,
272,
6170,
12468,
465,
5521,
2544,
314,
1249,
787,
27960,
14,
339,
2893,
1324,
26,
282,
29,
66,
286,
628,
1421,
4681,
2,
272,
2893,
1072,
26,
788,
65,
29,
66,
297,
283,
67,
628,
1421,
4681,
2,
418,
339,
10082,
1183,
642,
365,
282,
29844,
16701,
626,
965,
2005,
1655,
4661,
31566,
367,
272,
4212,
2622,
4839,
370,
675,
652,
14,
272,
1449,
339,
327,
314,
769,
402,
1862,
4565,
734,
402,
314,
1680,
1059,
272,
327,
642,
365,
9995,
370,
506,
314,
754,
574,
1380,
781,
787,
4224,
73,
272,
1862,
275,
942,
339,
327,
2348,
781,
3752,
314,
1249,
12,
880,
781,
1172,
282,
14818,
5960,
370,
272,
327,
1736,
543,
12,
436,
3715,
641,
10424,
4601,
272,
1249,
275,
1249,
14,
1913,
342,
272,
862,
26,
267,
1249,
275,
1249,
14,
2143,
360,
1624,
13,
24,
358,
267,
886,
63,
2708,
275,
715,
272,
871,
18965,
26,
267,
886,
63,
2708,
275,
756,
272,
2974,
275,
1249,
14,
1294,
2258,
78,
358,
339,
327,
13974,
1806,
314,
4645,
12,
436,
295,
21263,
1263,
626,
1443,
1172,
2757,
272,
327,
3715,
641,
282,
4601,
6272,
282,
10321,
18,
1853,
14,
272,
327,
444,
340,
4645,
787,
7370,
401,
298,
1421,
401,
298,
30618,
3520,
2621,
10451,
339,
327,
5723,
2860,
787,
1202,
272,
327,
370,
4215,
4426,
402,
314,
1174,
402,
314,
6057,
12,
3967,
5664,
436,
9344,
272,
327,
1443,
506,
6032,
4453,
1924,
1163,
14,
339,
6313,
63,
1560,
275,
488,
272,
6272,
63,
14005,
275,
756,
272,
870,
63,
4631,
275,
378,
221,
327,
1202,
370,
2338,
6032,
10321,
18,
8448,
3586,
5664,
272,
1853,
63,
4631,
275,
378,
221,
327,
1202,
370,
2338,
6032,
10321,
18,
7749,
3674,
5664,
272,
3721,
63,
4631,
275,
378,
221,
327,
1202,
370,
2338,
6032,
10321,
18,
469,
3,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
AmrnotAmr/zato
|
code/zato-web-admin/src/zato/admin/web/forms/scheduler.py
|
7
|
2074
|
# -*- coding: utf-8 -*-
"""
Copyright (C) 2010 Dariusz Suchojad <dsuch at zato.io>
Licensed under LGPLv3, see LICENSE.txt for terms and conditions.
"""
from __future__ import absolute_import, division, print_function, unicode_literals
# Django
from django import forms
# Zato
from zato.admin.web.forms import add_services
class _Base(forms.Form):
id = forms.CharField(widget=forms.HiddenInput())
name = forms.CharField(widget=forms.TextInput(attrs={'class':'required', 'style':'width:100%'}))
is_active = forms.BooleanField(required=False, widget=forms.CheckboxInput(attrs={'checked':'checked'}))
service = forms.ChoiceField(widget=forms.Select(attrs={'class':'required', 'style':'width:100%'}))
extra = forms.CharField(widget=forms.Textarea(attrs={'style':'width:100%'}))
start_date = forms.CharField(widget=forms.TextInput(attrs={'class':'required', 'style':'width:30%; height:19px'}))
def __init__(self, prefix, req):
super(_Base, self).__init__(prefix=prefix)
add_services(self, req)
class OneTimeSchedulerJobForm(_Base):
pass
class IntervalBasedSchedulerJobForm(_Base):
# Attributes specific to interval-based jobs.
weeks = forms.CharField(widget=forms.TextInput(attrs={'class':'validate-digits', 'style':'width:8%'}))
days = forms.CharField(widget=forms.TextInput(attrs={'class':'validate-digits', 'style':'width:8%'}))
hours = forms.CharField(widget=forms.TextInput(attrs={'class':'validate-digits', 'style':'width:8%'}))
minutes = forms.CharField(widget=forms.TextInput(attrs={'class':'validate-digits', 'style':'width:8%'}))
seconds = forms.CharField(widget=forms.TextInput(attrs={'class':'validate-digits', 'style':'width:8%'}))
start_date = forms.CharField(widget=forms.TextInput(attrs={'class':'required', 'style':'width:30%; height:19px'}))
repeats = forms.CharField(widget=forms.TextInput(attrs={'style':'width:8%'}))
class CronStyleSchedulerJobForm(_Base):
cron_definition = forms.CharField(widget=forms.TextInput(attrs={'class':'required', 'style':'width:100%'}))
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
7384,
334,
35,
9,
7129,
577,
759,
527,
90,
32753,
79,
74,
350,
665,
795,
2133,
737,
1315,
11318,
14,
2308,
30,
199,
199,
31661,
1334,
491,
28863,
19,
12,
1937,
5113,
14,
2424,
367,
2895,
436,
3704,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
3,
5634,
199,
504,
1639,
492,
4513,
199,
199,
3,
3107,
11318,
199,
504,
1315,
11318,
14,
2113,
14,
2520,
14,
3351,
492,
1050,
63,
5950,
199,
199,
533,
485,
1563,
8,
3351,
14,
2821,
304,
272,
1305,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
25419,
1012,
272,
536,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
533,
5242,
2427,
297,
283,
2487,
5242,
2063,
26,
1960,
5,
20219,
272,
365,
63,
2682,
275,
4513,
14,
5036,
8,
2427,
29,
797,
12,
3938,
29,
3351,
14,
26366,
3205,
8,
3288,
3713,
10718,
5242,
10718,
20219,
272,
2435,
275,
4513,
14,
15792,
8,
3440,
29,
3351,
14,
5446,
8,
3288,
3713,
533,
5242,
2427,
297,
283,
2487,
5242,
2063,
26,
1960,
5,
20219,
272,
2402,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
1872,
6789,
8,
3288,
3713,
2487,
5242,
2063,
26,
1960,
5,
20219,
272,
1343,
63,
602,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
533,
5242,
2427,
297,
283,
2487,
5242,
2063,
26,
1216,
5,
27,
4569,
26,
1167,
5326,
20219,
339,
347,
636,
826,
721,
277,
12,
2403,
12,
2648,
304,
267,
1613,
1547,
1563,
12,
291,
2843,
826,
721,
1861,
29,
1861,
9,
267,
1050,
63,
5950,
8,
277,
12,
2648,
9,
199,
199,
533,
7309,
1366,
11251,
6694,
2821,
1547,
1563,
304,
272,
986,
199,
199,
533,
18766,
20409,
11251,
6694,
2821,
1547,
1563,
304,
272,
327,
9382,
2488,
370,
6252,
13,
6788,
9643,
14,
272,
29540,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
533,
5242,
3502,
13,
7022,
297,
283,
2487,
5242,
2063,
26,
24,
5,
20219,
272,
7609,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
533,
5242,
3502,
13,
7022,
297,
283,
2487,
5242,
2063,
26,
24,
5,
20219,
272,
10857,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
533,
5242,
3502,
13,
7022,
297,
283,
2487,
5242,
2063,
26,
24,
5,
20219,
272,
9395,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
533,
5242,
3502,
13,
7022,
297,
283,
2487,
5242,
2063,
26,
24,
5,
20219,
272,
4696,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
533,
5242,
3502,
13,
7022,
297,
283,
2487,
5242,
2063,
26,
24,
5,
20219,
272,
1343,
63,
602,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
533,
5242,
2427,
297,
283,
2487,
5242,
2063,
26,
1216,
5,
27,
4569,
26,
1167,
5326,
20219,
272,
28908,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
2487,
5242,
2063,
26,
24,
5,
20219,
199,
199,
533,
445,
2641,
6609,
11251,
6694,
2821,
1547,
1563,
304,
272,
19818,
63,
7463,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
533,
5242,
2427,
297,
283,
2487,
5242,
2063,
26,
1960,
5,
20219,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
7384,
334,
35,
9,
7129,
577,
759,
527,
90,
32753,
79,
74,
350,
665,
795,
2133,
737,
1315,
11318,
14,
2308,
30,
199,
199,
31661,
1334,
491,
28863,
19,
12,
1937,
5113,
14,
2424,
367,
2895,
436,
3704,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
3,
5634,
199,
504,
1639,
492,
4513,
199,
199,
3,
3107,
11318,
199,
504,
1315,
11318,
14,
2113,
14,
2520,
14,
3351,
492,
1050,
63,
5950,
199,
199,
533,
485,
1563,
8,
3351,
14,
2821,
304,
272,
1305,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
25419,
1012,
272,
536,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
533,
5242,
2427,
297,
283,
2487,
5242,
2063,
26,
1960,
5,
20219,
272,
365,
63,
2682,
275,
4513,
14,
5036,
8,
2427,
29,
797,
12,
3938,
29,
3351,
14,
26366,
3205,
8,
3288,
3713,
10718,
5242,
10718,
20219,
272,
2435,
275,
4513,
14,
15792,
8,
3440,
29,
3351,
14,
5446,
8,
3288,
3713,
533,
5242,
2427,
297,
283,
2487,
5242,
2063,
26,
1960,
5,
20219,
272,
2402,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
1872,
6789,
8,
3288,
3713,
2487,
5242,
2063,
26,
1960,
5,
20219,
272,
1343,
63,
602,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
533,
5242,
2427,
297,
283,
2487,
5242,
2063,
26,
1216,
5,
27,
4569,
26,
1167,
5326,
20219,
339,
347,
636,
826,
721,
277,
12,
2403,
12,
2648,
304,
267,
1613,
1547,
1563,
12,
291,
2843,
826,
721,
1861,
29,
1861,
9,
267,
1050,
63,
5950,
8,
277,
12,
2648,
9,
199,
199,
533,
7309,
1366,
11251,
6694,
2821,
1547,
1563,
304,
272,
986,
199,
199,
533,
18766,
20409,
11251,
6694,
2821,
1547,
1563,
304,
272,
327,
9382,
2488,
370,
6252,
13,
6788,
9643,
14,
272,
29540,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
533,
5242,
3502,
13,
7022,
297,
283,
2487,
5242,
2063,
26,
24,
5,
20219,
272,
7609,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
533,
5242,
3502,
13,
7022,
297,
283,
2487,
5242,
2063,
26,
24,
5,
20219,
272,
10857,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
533,
5242,
3502,
13,
7022,
297,
283,
2487,
5242,
2063,
26,
24,
5,
20219,
272,
9395,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
533,
5242,
3502,
13,
7022,
297,
283,
2487,
5242,
2063,
26,
24,
5,
20219,
272,
4696,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
533,
5242,
3502,
13,
7022,
297,
283,
2487,
5242,
2063,
26,
24,
5,
20219,
272,
1343,
63,
602,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
533,
5242,
2427,
297,
283,
2487,
5242,
2063,
26,
1216,
5,
27,
4569,
26,
1167,
5326,
20219,
272,
28908,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
2487,
5242,
2063,
26,
24,
5,
20219,
199,
199,
533,
445,
2641,
6609,
11251,
6694,
2821,
1547,
1563,
304,
272,
19818,
63,
7463,
275,
4513,
14,
2183,
8,
3440,
29,
3351,
14,
18362,
8,
3288,
3713,
533,
5242,
2427,
297,
283,
2487,
5242,
2063,
26,
1960,
5,
20219,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
pquentin/django
|
tests/expressions_case/models.py
|
14
|
2855
|
from __future__ import unicode_literals
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
try:
from PIL import Image
except ImportError:
Image = None
@python_2_unicode_compatible
class CaseTestModel(models.Model):
integer = models.IntegerField()
integer2 = models.IntegerField(null=True)
string = models.CharField(max_length=100, default='')
big_integer = models.BigIntegerField(null=True)
binary = models.BinaryField(default=b'')
boolean = models.BooleanField(default=False)
comma_separated_integer = models.CommaSeparatedIntegerField(max_length=100, default='')
date = models.DateField(null=True, db_column='date_field')
date_time = models.DateTimeField(null=True)
decimal = models.DecimalField(max_digits=2, decimal_places=1, null=True, db_column='decimal_field')
duration = models.DurationField(null=True)
email = models.EmailField(default='')
file = models.FileField(null=True, db_column='file_field')
file_path = models.FilePathField(null=True)
float = models.FloatField(null=True, db_column='float_field')
if Image:
image = models.ImageField(null=True)
ip_address = models.IPAddressField(null=True)
generic_ip_address = models.GenericIPAddressField(null=True)
null_boolean = models.NullBooleanField()
positive_integer = models.PositiveIntegerField(null=True)
positive_small_integer = models.PositiveSmallIntegerField(null=True)
slug = models.SlugField(default='')
small_integer = models.SmallIntegerField(null=True)
text = models.TextField(default='')
time = models.TimeField(null=True, db_column='time_field')
url = models.URLField(default='')
uuid = models.UUIDField(null=True)
fk = models.ForeignKey('self', null=True)
def __str__(self):
return "%i, %s" % (self.integer, self.string)
@python_2_unicode_compatible
class O2OCaseTestModel(models.Model):
o2o = models.OneToOneField(CaseTestModel, related_name='o2o_rel')
integer = models.IntegerField()
def __str__(self):
return "%i, %s" % (self.id, self.o2o)
@python_2_unicode_compatible
class FKCaseTestModel(models.Model):
fk = models.ForeignKey(CaseTestModel, related_name='fk_rel')
integer = models.IntegerField()
def __str__(self):
return "%i, %s" % (self.id, self.fk)
@python_2_unicode_compatible
class Client(models.Model):
REGULAR = 'R'
GOLD = 'G'
PLATINUM = 'P'
ACCOUNT_TYPE_CHOICES = (
(REGULAR, 'Regular'),
(GOLD, 'Gold'),
(PLATINUM, 'Platinum'),
)
name = models.CharField(max_length=50)
registered_on = models.DateField()
account_type = models.CharField(
max_length=1,
choices=ACCOUNT_TYPE_CHOICES,
default=REGULAR,
)
def __str__(self):
return self.name
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
199,
199,
893,
26,
272,
687,
14937,
492,
6047,
199,
2590,
3545,
26,
272,
6047,
275,
488,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
12425,
18282,
8,
992,
14,
1685,
304,
272,
3000,
275,
1709,
14,
3901,
342,
272,
3000,
18,
275,
1709,
14,
3901,
8,
2307,
29,
549,
9,
272,
1059,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
849,
13275,
339,
7282,
63,
4115,
275,
1709,
14,
25175,
8,
2307,
29,
549,
9,
272,
3366,
275,
1709,
14,
6636,
792,
8,
885,
29,
66,
17483,
272,
5046,
275,
1709,
14,
5036,
8,
885,
29,
797,
9,
272,
10029,
63,
12794,
63,
4115,
275,
1709,
14,
25732,
20727,
3901,
8,
988,
63,
1267,
29,
1960,
12,
849,
13275,
272,
1434,
275,
1709,
14,
14071,
8,
2307,
29,
549,
12,
1592,
63,
2301,
534,
602,
63,
698,
358,
272,
1434,
63,
521,
275,
1709,
14,
4626,
8,
2307,
29,
549,
9,
272,
6107,
275,
1709,
14,
15975,
8,
988,
63,
7022,
29,
18,
12,
6107,
63,
10696,
29,
17,
12,
2973,
29,
549,
12,
1592,
63,
2301,
534,
6355,
63,
698,
358,
272,
7373,
275,
1709,
14,
13283,
792,
8,
2307,
29,
549,
9,
272,
3031,
275,
1709,
14,
16577,
8,
885,
13275,
272,
570,
275,
1709,
14,
23252,
8,
2307,
29,
549,
12,
1592,
63,
2301,
534,
493,
63,
698,
358,
272,
570,
63,
515,
275,
1709,
14,
14225,
792,
8,
2307,
29,
549,
9,
272,
2069,
275,
1709,
14,
13019,
8,
2307,
29,
549,
12,
1592,
63,
2301,
534,
1609,
63,
698,
358,
272,
340,
6047,
26,
267,
1834,
275,
1709,
14,
21910,
8,
2307,
29,
549,
9,
272,
3384,
63,
1562,
275,
1709,
14,
26969,
8,
2307,
29,
549,
9,
272,
7809,
63,
711,
63,
1562,
275,
1709,
14,
9417,
26969,
8,
2307,
29,
549,
9,
272,
2973,
63,
4871,
275,
1709,
14,
29068,
342,
272,
7317,
63,
4115,
275,
1709,
14,
8591,
8,
2307,
29,
549,
9,
272,
7317,
63,
7241,
63,
4115,
275,
1709,
14,
25197,
8,
2307,
29,
549,
9,
272,
8889,
275,
1709,
14,
17315,
8,
885,
13275,
272,
7425,
63,
4115,
275,
1709,
14,
14640,
8,
2307,
29,
549,
9,
272,
1318,
275,
1709,
14,
6254,
8,
885,
13275,
272,
900,
275,
1709,
14,
27115,
8,
2307,
29,
549,
12,
1592,
63,
2301,
534,
521,
63,
698,
358,
272,
1166,
275,
1709,
14,
17363,
8,
885,
13275,
272,
5377,
275,
1709,
14,
8757,
792,
8,
2307,
29,
549,
9,
272,
14830,
275,
1709,
14,
3190,
360,
277,
297,
2973,
29,
549,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
73,
12,
450,
83,
2,
450,
334,
277,
14,
4115,
12,
291,
14,
875,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
593,
18,
47,
1538,
18282,
8,
992,
14,
1685,
304,
272,
312,
18,
79,
275,
1709,
14,
14298,
8,
1538,
18282,
12,
4048,
63,
354,
534,
79,
18,
79,
63,
3369,
358,
272,
3000,
275,
1709,
14,
3901,
342,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
73,
12,
450,
83,
2,
450,
334,
277,
14,
344,
12,
291,
14,
79,
18,
79,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
18821,
1538,
18282,
8,
992,
14,
1685,
304,
272,
14830,
275,
1709,
14,
3190,
8,
1538,
18282,
12,
4048,
63,
354,
534,
9010,
63,
3369,
358,
272,
3000,
275,
1709,
14,
3901,
342,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
73,
12,
450,
83,
2,
450,
334,
277,
14,
344,
12,
291,
14,
9010,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
6810,
8,
992,
14,
1685,
304,
272,
14142,
3038,
275,
283,
50,
7,
272,
598,
5104,
275,
283,
39,
7,
272,
10092,
1934,
2639,
275,
283,
48,
7,
272,
6570,
8760,
63,
2711,
63,
16236,
275,
334,
267,
334,
5616,
3038,
12,
283,
16038,
659,
267,
334,
39,
5104,
12,
283,
39,
1753,
659,
267,
334,
2749,
1934,
2639,
12,
283,
3714,
14667,
453,
659,
272,
776,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
272,
7264,
63,
265,
275,
1709,
14,
14071,
342,
272,
2933,
63,
466,
275,
1709,
14,
2183,
8,
267,
1390,
63,
1267,
29,
17,
12,
267,
3415,
29,
18928,
63,
2711,
63,
16236,
12,
267,
849,
29,
5616,
3038,
12,
272,
776,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
199,
199,
893,
26,
272,
687,
14937,
492,
6047,
199,
2590,
3545,
26,
272,
6047,
275,
488,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
12425,
18282,
8,
992,
14,
1685,
304,
272,
3000,
275,
1709,
14,
3901,
342,
272,
3000,
18,
275,
1709,
14,
3901,
8,
2307,
29,
549,
9,
272,
1059,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
849,
13275,
339,
7282,
63,
4115,
275,
1709,
14,
25175,
8,
2307,
29,
549,
9,
272,
3366,
275,
1709,
14,
6636,
792,
8,
885,
29,
66,
17483,
272,
5046,
275,
1709,
14,
5036,
8,
885,
29,
797,
9,
272,
10029,
63,
12794,
63,
4115,
275,
1709,
14,
25732,
20727,
3901,
8,
988,
63,
1267,
29,
1960,
12,
849,
13275,
272,
1434,
275,
1709,
14,
14071,
8,
2307,
29,
549,
12,
1592,
63,
2301,
534,
602,
63,
698,
358,
272,
1434,
63,
521,
275,
1709,
14,
4626,
8,
2307,
29,
549,
9,
272,
6107,
275,
1709,
14,
15975,
8,
988,
63,
7022,
29,
18,
12,
6107,
63,
10696,
29,
17,
12,
2973,
29,
549,
12,
1592,
63,
2301,
534,
6355,
63,
698,
358,
272,
7373,
275,
1709,
14,
13283,
792,
8,
2307,
29,
549,
9,
272,
3031,
275,
1709,
14,
16577,
8,
885,
13275,
272,
570,
275,
1709,
14,
23252,
8,
2307,
29,
549,
12,
1592,
63,
2301,
534,
493,
63,
698,
358,
272,
570,
63,
515,
275,
1709,
14,
14225,
792,
8,
2307,
29,
549,
9,
272,
2069,
275,
1709,
14,
13019,
8,
2307,
29,
549,
12,
1592,
63,
2301,
534,
1609,
63,
698,
358,
272,
340,
6047,
26,
267,
1834,
275,
1709,
14,
21910,
8,
2307,
29,
549,
9,
272,
3384,
63,
1562,
275,
1709,
14,
26969,
8,
2307,
29,
549,
9,
272,
7809,
63,
711,
63,
1562,
275,
1709,
14,
9417,
26969,
8,
2307,
29,
549,
9,
272,
2973,
63,
4871,
275,
1709,
14,
29068,
342,
272,
7317,
63,
4115,
275,
1709,
14,
8591,
8,
2307,
29,
549,
9,
272,
7317,
63,
7241,
63,
4115,
275,
1709,
14,
25197,
8,
2307,
29,
549,
9,
272,
8889,
275,
1709,
14,
17315,
8,
885,
13275,
272,
7425,
63,
4115,
275,
1709,
14,
14640,
8,
2307,
29,
549,
9,
272,
1318,
275,
1709,
14,
6254,
8,
885,
13275,
272,
900,
275,
1709,
14,
27115,
8,
2307,
29,
549,
12,
1592,
63,
2301,
534,
521,
63,
698,
358,
272,
1166,
275,
1709,
14,
17363,
8,
885,
13275,
272,
5377,
275,
1709,
14,
8757,
792,
8,
2307,
29,
549,
9,
272,
14830,
275,
1709,
14,
3190,
360,
277,
297,
2973,
29,
549,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
73,
12,
450,
83,
2,
450,
334,
277,
14,
4115,
12,
291,
14,
875,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
593,
18,
47,
1538,
18282,
8,
992,
14,
1685,
304,
272,
312,
18,
79,
275,
1709,
14,
14298,
8,
1538,
18282,
12,
4048,
63,
354,
534,
79,
18,
79,
63,
3369,
358,
272,
3000,
275,
1709,
14,
3901,
342,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
73,
12,
450,
83,
2,
450,
334,
277,
14,
344,
12,
291,
14,
79,
18,
79,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
18821,
1538,
18282,
8,
992,
14,
1685,
304,
272,
14830,
275,
1709,
14,
3190,
8,
1538,
18282,
12,
4048,
63,
354,
534,
9010,
63,
3369,
358,
272,
3000,
275,
1709,
14,
3901,
342,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
73,
12,
450,
83,
2,
450,
334,
277,
14,
344,
12,
291,
14,
9010,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
6810,
8,
992,
14,
1685,
304,
272,
14142,
3038,
275,
283,
50,
7,
272,
598,
5104,
275,
283,
39,
7,
272,
10092,
1934,
2639,
275,
283,
48,
7,
272,
6570,
8760,
63,
2711,
63,
16236,
275,
334,
267,
334,
5616,
3038,
12,
283,
16038,
659,
267,
334,
39,
5104,
12,
283,
39,
1753,
659,
267,
334,
2749,
1934,
2639,
12,
283,
3714,
14667,
453,
659,
272,
776,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
272,
7264,
63,
265,
275,
1709,
14,
14071,
342,
272,
2933,
63,
466,
275,
1709,
14,
2183,
8,
267,
1390,
63,
1267,
29,
17,
12,
267,
3415,
29,
18928,
63,
2711,
63,
16236,
12,
267,
849,
29,
5616,
3038,
12,
272,
776,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mlperf/training_results_v0.7
|
Fujitsu/benchmarks/resnet/implementations/implementation_open/mxnet/3rdparty/tvm/python/tvm/autotvm/database.py
|
1
|
6064
|
# 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.
# pylint: disable=consider-using-enumerate,invalid-name
"""
Database of MeasureInput/MeasureResult pair.
This can be used for replaying measurement.
"""
import os
from .record import encode, decode, measure_str_key
class Database(object):
"""
Base class for a record database object.
"""
def load(self, inp, get_all=False):
"""
Load a result based on an input's string key
Parameters
----------
inp: MeasureInput
to be translated into key for RedisDB
get_all: bool, optional
Whether the latest result (or all matching results) should be returned
Returns
-------
rec: MeasureResult if previously saved, otherwise None
"""
raise NotImplementedError()
def save(self, inp, res, extend=False):
"""
Save a result based on an input's string key
Parameters
----------
inp: MeasureInput
to be translated into key for RedisDB
res: MeasureResult
to associate with key
extend:
Whether to extend existing MeasureResults if they exist
"""
raise NotImplementedError()
def filter_inputs(db, measure_inputs, retry=False):
"""
Filter a measure_inputs batch based on saved db results
Parameters
----------
db: Database
database object
measure_inputs: Array of MeasureInput
measure_inputs as expected in measure_batch
retry: bool
whether to retry if the saved result is a failure
Returns
-------
partial_results: Array of MeasureResult
a full list of result, where None denotes no corresponding saved result
unsaved: Array of MeasureInput
a list that only contains unsaved inputs
"""
partial_results = list()
unsaved = list()
for inp in measure_inputs:
res = db.load(inp)
if res is None or (retry and res.error_no != 0):
unsaved.append(inp)
partial_results.append(None)
else:
partial_results.append(res)
return partial_results, unsaved
class RedisDatabase(Database):
"""
Redis version of record database
"""
REDIS_PROD = 15
REDIS_LOCA = 14
REDIS_TEST = 13 # for unit test
REDIS_NIGHT_TEMP = 12 # for nightly report (will be flushed after every workload)
MAGIC_SPLIT = "$"
def __init__(self, db_index=REDIS_PROD):
import redis
if db_index == RedisDatabase.REDIS_TEST:
host = 'localhost'
else:
host = os.environ.get('TVM_FLEET_HOST')
self.db = redis.StrictRedis(host=host, port=6379, db=db_index)
self.db_index = db_index
def set(self, key, value):
self.db.set(key, value)
def get(self, key):
return self.db.get(key)
def load(self, inp, get_all=False):
current = self.get(measure_str_key(inp))
if current is not None:
current = str(current)
records = [decode(x) for x in current.split(RedisDatabase.MAGIC_SPLIT)]
results = [rec[1] for rec in records]
if get_all:
return results
return max(results, key=lambda result: result.timestamp)
return current
def save(self, inp, res, extend=False):
current = self.get(measure_str_key(inp))
if not extend or current is None:
self.set(measure_str_key(inp),
RedisDatabase.MAGIC_SPLIT.join([encode(inp, res)]))
else:
current = current.split(RedisDatabase.MAGIC_SPLIT)
self.set(measure_str_key(inp),
RedisDatabase.MAGIC_SPLIT.join(current + [encode(inp, res)]))
def filter(self, func):
"""
Dump all of the records for a particular target
Parameters
----------
func: callable
The signature of the function is bool (MeasureInput, Array of MeasureResult)
Returns
-------
list of records (inp, result) matching the target
Examples
--------
get records for a target
>>> db.filter(lambda inp, resulst: "cuda" in inp.target.keys)
"""
matched_records = list()
# may consider filtering in iterator in the future
for key in self.db:
current = self.get(key)
try:
records = [decode(x) for x in current.spilt(RedisDatabase.MAGIC_SPLIT)]
except TypeError: # got a badly formatted/old format record
continue
inps, results = zip(*records)
inp = inps[0]
if not func(inp, results):
continue
result = max(results, key=lambda res: res.timestamp)
matched_records.append((inp, result))
return matched_records
def flush(self):
self.db.flushdb()
class DummyDatabase(RedisDatabase):
"""
A database based on python dictionary for testing.
"""
def __init__(self):
# pylint: disable=super-init-not-called
self.db = {}
def set(self, key, value):
self.db[key] = value
def get(self, key):
return self.db.get(key)
def flush(self):
self.db = {}
|
apache-2.0
|
[
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
3,
4287,
26,
3507,
29,
388,
16994,
13,
4941,
13,
26318,
12,
3197,
13,
354,
199,
624,
199,
7243,
402,
22933,
3205,
15,
18611,
2889,
4092,
14,
199,
2765,
883,
506,
1202,
367,
24331,
316,
18216,
14,
199,
624,
199,
646,
747,
199,
199,
504,
1275,
3059,
492,
3752,
12,
4849,
12,
9775,
63,
495,
63,
498,
421,
199,
533,
8692,
8,
785,
304,
272,
408,
272,
3523,
1021,
367,
282,
2777,
3050,
909,
14,
272,
408,
272,
347,
2248,
8,
277,
12,
10702,
12,
664,
63,
452,
29,
797,
304,
267,
408,
267,
7190,
282,
754,
4079,
641,
376,
1324,
1159,
1059,
790,
398,
3897,
267,
4143,
267,
10702,
26,
22933,
3205,
288,
370,
506,
14598,
1901,
790,
367,
25496,
2846,
267,
664,
63,
452,
26,
2155,
12,
2716,
288,
7480,
314,
8839,
754,
334,
269,
1006,
4877,
2058,
9,
1077,
506,
2138,
398,
1803,
267,
5514,
267,
6488,
26,
22933,
2889,
340,
10889,
6290,
12,
4257,
488,
267,
408,
267,
746,
4279,
342,
339,
347,
3354,
8,
277,
12,
10702,
12,
522,
12,
12247,
29,
797,
304,
267,
408,
267,
11063,
282,
754,
4079,
641,
376,
1324,
1159,
1059,
790,
398,
3897,
267,
4143,
267,
10702,
26,
22933,
3205,
288,
370,
506,
14598,
1901,
790,
367,
25496,
2846,
267,
522,
26,
22933,
2889,
288,
370,
20133,
543,
790,
267,
12247,
26,
288,
7480,
370,
12247,
3411,
22933,
6579,
340,
2985,
2187,
267,
408,
267,
746,
4279,
342,
421,
199,
318,
2457,
63,
3711,
8,
697,
12,
9775,
63,
3711,
12,
7269,
29,
797,
304,
272,
408,
272,
9388,
282,
9775,
63,
3711,
3522,
4079,
641,
6290,
1592,
2058,
339,
3897,
272,
4143,
272,
1592,
26,
8692,
267,
3050,
909,
272,
9775,
63,
3711,
26,
8725,
402,
22933,
3205,
267,
9775,
63,
3711,
465,
1420,
315,
9775,
63,
2912,
272,
7269,
26,
2155,
267,
3775,
370,
7269,
340,
314,
6290,
754,
365,
282,
5988,
339,
1803,
272,
5514,
272,
7417,
63,
2604,
26,
8725,
402,
22933,
2889,
267,
282,
2615,
769,
402,
754,
12,
2382,
488,
477,
5983,
949,
5226,
6290,
754,
272,
625,
8420,
26,
8725,
402,
22933,
3205,
267,
282,
769,
626,
1454,
3509,
625,
8420,
4153,
272,
408,
272,
7417,
63,
2604,
275,
769,
342,
272,
625,
8420,
275,
769,
342,
272,
367,
10702,
315,
9775,
63,
3711,
26,
267,
522,
275,
1592,
14,
912,
8,
11416,
9,
267,
340,
522,
365,
488,
503,
334,
7154,
436,
522,
14,
705,
63,
889,
1137,
378,
304,
288,
625,
8420,
14,
740,
8,
11416,
9,
288,
7417,
63,
2604,
14,
740,
8,
403,
9,
267,
587,
26,
288,
7417,
63,
2604,
14,
740,
8,
470,
9,
272,
372,
7417,
63,
2604,
12,
625,
8420,
199,
199,
533,
25496,
7243,
8,
7243,
304,
272,
408,
272,
25496,
1015,
402,
2777,
3050,
272,
408,
272,
23443,
1311,
63,
2514,
36,
275,
4114,
272,
23443,
1311,
63,
1484,
3263,
275,
4329,
272,
23443,
1311,
63,
2864,
275,
4944,
263,
327,
367,
4137,
511,
272,
23443,
1311,
63,
46,
2830,
63,
12510,
275,
3144,
221,
327,
367,
302,
1070,
590,
3622,
334,
14117,
506,
8976,
379,
2410,
4036,
1736,
912,
9,
339,
23336,
63,
30538,
275,
7880,
2,
339,
347,
636,
826,
721,
277,
12,
1592,
63,
1080,
29,
907,
6178,
63,
2514,
36,
304,
267,
492,
16967,
398,
340,
1592,
63,
1080,
508,
25496,
7243,
14,
907,
6178,
63,
2864,
26,
288,
1591,
275,
283,
5967,
7,
267,
587,
26,
288,
1591,
275,
747,
14,
2314,
14,
362,
360,
52,
6849,
63,
38,
906,
775,
63,
5449,
358,
267,
291,
14,
697,
275,
16967,
14,
18625,
29605,
8,
1102,
29,
1102,
12,
1844,
29,
22,
12015,
12,
1592,
29,
697,
63,
1080,
9,
267,
291,
14,
697,
63,
1080,
275,
1592,
63,
1080,
339,
347,
663,
8,
277,
12,
790,
12,
574,
304,
267,
291,
14,
697,
14,
409,
8,
498,
12,
574,
9,
339,
347,
664,
8,
277,
12,
790,
304,
267,
372,
291,
14,
697,
14,
362,
8,
498,
9,
339,
347,
2248,
8,
277,
12,
10702,
12,
664,
63,
452,
29,
797,
304,
267,
1453,
275,
291,
14,
362,
8,
9580,
63,
495,
63,
498,
8,
11416,
430,
267,
340,
1453,
365,
440,
488,
26,
288,
1453,
275,
620,
8,
1818,
9,
288,
5767,
275,
359,
2708,
8,
88,
9,
367,
671,
315,
1453,
14,
1294,
8,
29605,
7243,
14,
19973,
63,
30538,
1874,
288,
2058,
275,
359,
2761,
59,
17,
61,
367,
6488,
315,
5767,
61,
288,
340,
664,
63,
452,
26,
355,
372,
2058,
288,
372,
1390,
8,
2604,
12,
790,
29,
2734,
754,
26,
754,
14,
3954,
9,
267,
372,
1453,
339,
347,
3354,
8,
277,
12,
10702,
12,
522,
12,
12247,
29,
797,
304,
267,
1453,
275,
291,
14,
362,
8,
9580,
63,
495,
63,
498,
8,
11416,
430,
267,
340,
440,
12247,
503,
1453,
365,
488,
26,
288,
291,
14,
409,
8,
9580,
63,
495,
63,
498,
8,
11416,
395,
2151,
25496,
7243,
14,
19973,
63,
30538,
14,
904,
779,
2143,
8,
11416,
12,
522,
19563,
267,
587,
26,
288,
1453,
275,
1453,
14,
1294,
8
] |
[
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
3,
4287,
26,
3507,
29,
388,
16994,
13,
4941,
13,
26318,
12,
3197,
13,
354,
199,
624,
199,
7243,
402,
22933,
3205,
15,
18611,
2889,
4092,
14,
199,
2765,
883,
506,
1202,
367,
24331,
316,
18216,
14,
199,
624,
199,
646,
747,
199,
199,
504,
1275,
3059,
492,
3752,
12,
4849,
12,
9775,
63,
495,
63,
498,
421,
199,
533,
8692,
8,
785,
304,
272,
408,
272,
3523,
1021,
367,
282,
2777,
3050,
909,
14,
272,
408,
272,
347,
2248,
8,
277,
12,
10702,
12,
664,
63,
452,
29,
797,
304,
267,
408,
267,
7190,
282,
754,
4079,
641,
376,
1324,
1159,
1059,
790,
398,
3897,
267,
4143,
267,
10702,
26,
22933,
3205,
288,
370,
506,
14598,
1901,
790,
367,
25496,
2846,
267,
664,
63,
452,
26,
2155,
12,
2716,
288,
7480,
314,
8839,
754,
334,
269,
1006,
4877,
2058,
9,
1077,
506,
2138,
398,
1803,
267,
5514,
267,
6488,
26,
22933,
2889,
340,
10889,
6290,
12,
4257,
488,
267,
408,
267,
746,
4279,
342,
339,
347,
3354,
8,
277,
12,
10702,
12,
522,
12,
12247,
29,
797,
304,
267,
408,
267,
11063,
282,
754,
4079,
641,
376,
1324,
1159,
1059,
790,
398,
3897,
267,
4143,
267,
10702,
26,
22933,
3205,
288,
370,
506,
14598,
1901,
790,
367,
25496,
2846,
267,
522,
26,
22933,
2889,
288,
370,
20133,
543,
790,
267,
12247,
26,
288,
7480,
370,
12247,
3411,
22933,
6579,
340,
2985,
2187,
267,
408,
267,
746,
4279,
342,
421,
199,
318,
2457,
63,
3711,
8,
697,
12,
9775,
63,
3711,
12,
7269,
29,
797,
304,
272,
408,
272,
9388,
282,
9775,
63,
3711,
3522,
4079,
641,
6290,
1592,
2058,
339,
3897,
272,
4143,
272,
1592,
26,
8692,
267,
3050,
909,
272,
9775,
63,
3711,
26,
8725,
402,
22933,
3205,
267,
9775,
63,
3711,
465,
1420,
315,
9775,
63,
2912,
272,
7269,
26,
2155,
267,
3775,
370,
7269,
340,
314,
6290,
754,
365,
282,
5988,
339,
1803,
272,
5514,
272,
7417,
63,
2604,
26,
8725,
402,
22933,
2889,
267,
282,
2615,
769,
402,
754,
12,
2382,
488,
477,
5983,
949,
5226,
6290,
754,
272,
625,
8420,
26,
8725,
402,
22933,
3205,
267,
282,
769,
626,
1454,
3509,
625,
8420,
4153,
272,
408,
272,
7417,
63,
2604,
275,
769,
342,
272,
625,
8420,
275,
769,
342,
272,
367,
10702,
315,
9775,
63,
3711,
26,
267,
522,
275,
1592,
14,
912,
8,
11416,
9,
267,
340,
522,
365,
488,
503,
334,
7154,
436,
522,
14,
705,
63,
889,
1137,
378,
304,
288,
625,
8420,
14,
740,
8,
11416,
9,
288,
7417,
63,
2604,
14,
740,
8,
403,
9,
267,
587,
26,
288,
7417,
63,
2604,
14,
740,
8,
470,
9,
272,
372,
7417,
63,
2604,
12,
625,
8420,
199,
199,
533,
25496,
7243,
8,
7243,
304,
272,
408,
272,
25496,
1015,
402,
2777,
3050,
272,
408,
272,
23443,
1311,
63,
2514,
36,
275,
4114,
272,
23443,
1311,
63,
1484,
3263,
275,
4329,
272,
23443,
1311,
63,
2864,
275,
4944,
263,
327,
367,
4137,
511,
272,
23443,
1311,
63,
46,
2830,
63,
12510,
275,
3144,
221,
327,
367,
302,
1070,
590,
3622,
334,
14117,
506,
8976,
379,
2410,
4036,
1736,
912,
9,
339,
23336,
63,
30538,
275,
7880,
2,
339,
347,
636,
826,
721,
277,
12,
1592,
63,
1080,
29,
907,
6178,
63,
2514,
36,
304,
267,
492,
16967,
398,
340,
1592,
63,
1080,
508,
25496,
7243,
14,
907,
6178,
63,
2864,
26,
288,
1591,
275,
283,
5967,
7,
267,
587,
26,
288,
1591,
275,
747,
14,
2314,
14,
362,
360,
52,
6849,
63,
38,
906,
775,
63,
5449,
358,
267,
291,
14,
697,
275,
16967,
14,
18625,
29605,
8,
1102,
29,
1102,
12,
1844,
29,
22,
12015,
12,
1592,
29,
697,
63,
1080,
9,
267,
291,
14,
697,
63,
1080,
275,
1592,
63,
1080,
339,
347,
663,
8,
277,
12,
790,
12,
574,
304,
267,
291,
14,
697,
14,
409,
8,
498,
12,
574,
9,
339,
347,
664,
8,
277,
12,
790,
304,
267,
372,
291,
14,
697,
14,
362,
8,
498,
9,
339,
347,
2248,
8,
277,
12,
10702,
12,
664,
63,
452,
29,
797,
304,
267,
1453,
275,
291,
14,
362,
8,
9580,
63,
495,
63,
498,
8,
11416,
430,
267,
340,
1453,
365,
440,
488,
26,
288,
1453,
275,
620,
8,
1818,
9,
288,
5767,
275,
359,
2708,
8,
88,
9,
367,
671,
315,
1453,
14,
1294,
8,
29605,
7243,
14,
19973,
63,
30538,
1874,
288,
2058,
275,
359,
2761,
59,
17,
61,
367,
6488,
315,
5767,
61,
288,
340,
664,
63,
452,
26,
355,
372,
2058,
288,
372,
1390,
8,
2604,
12,
790,
29,
2734,
754,
26,
754,
14,
3954,
9,
267,
372,
1453,
339,
347,
3354,
8,
277,
12,
10702,
12,
522,
12,
12247,
29,
797,
304,
267,
1453,
275,
291,
14,
362,
8,
9580,
63,
495,
63,
498,
8,
11416,
430,
267,
340,
440,
12247,
503,
1453,
365,
488,
26,
288,
291,
14,
409,
8,
9580,
63,
495,
63,
498,
8,
11416,
395,
2151,
25496,
7243,
14,
19973,
63,
30538,
14,
904,
779,
2143,
8,
11416,
12,
522,
19563,
267,
587,
26,
288,
1453,
275,
1453,
14,
1294,
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,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
b3j0f/schema
|
b3j0f/schema/utils.py
|
1
|
13398
|
# -*- coding: utf-8 -*-
# --------------------------------------------------------------------
# The MIT License (MIT)
#
# Copyright (c) 2016 Jonathan Labéjof <jonathan.labejof@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# --------------------------------------------------------------------
"""Schema utilities package."""
from six import iteritems, add_metaclass
from inspect import getmembers
from .registry import getbydatatype, register
from .lang.factory import build, getschemacls
from .base import Schema, DynamicValue
__all__ = [
'DynamicValue', 'data2schema', 'MetaRegisteredSchema', 'ThisSchema',
'updatecontent', 'validate', 'dump', 'RegisteredSchema',
'datatype2schemacls', 'RefSchema', 'data2schemacls', 'AnySchema'
]
class AnySchema(Schema):
"""Schema for any data."""
def _validate(*args, **kwargs):
pass
def datatype2schemacls(
_datatype, _registry=None, _factory=None, _force=True,
_besteffort=True, **kwargs
):
"""Get a schema class which has been associated to input data type by the
registry or the factory in this order.
:param type datatype: data type from where get associated schema.
:param SchemaRegisgry _registry: registry from where call the getbydatatype
. Default is the global registry.
:param SchemaFactory _factory: factory from where call the getschemacls if
getbydatatype returns None. Default is the global factory.
:param bool _force: if true (default), force the building of schema class
if no schema is associated to input data type.
:param bool _besteffort: if True (default), try to resolve schema by
inheritance.
:param dict kwargs: factory builder kwargs.
:rtype: type
:return: Schema associated to input registry or factory. None if no
association found.
"""
result = None
gdbt = getbydatatype if _registry is None else _registry.getbydatatype
result = gdbt(_datatype, besteffort=_besteffort)
if result is None:
gscls = getschemacls if _factory is None else _factory.getschemacls
result = gscls(_datatype, besteffort=_besteffort)
if result is None and _force:
_build = build if _factory is None else _factory.build
result = _build(_resource=_datatype, **kwargs)
return result
def data2schema(
_data=None, _force=False, _besteffort=True, _registry=None,
_factory=None, _buildkwargs=None, **kwargs
):
"""Get the schema able to instanciate input data.
The default value of schema will be data.
Can be used such as a decorator:
..code-block:: python
@data2schema
def example(): pass # return a function schema
@data2schema(_registry=myregistry)
def example(): pass # return a function schema with specific registry
..warning::
return this function id _data is None.
:param _data: data possibly generated by a schema. Required but in case of
decorator.
:param bool _force: if True (False by default), create the data schema
on the fly if it does not exist.
:param bool _besteffort: if True (default), find a schema class able to
validate data class by inheritance.
:param SchemaRegistry _registry: default registry to use. Global by
default.
:param SchemaFactory factory: default factory to use. Global by default.
:param dict _buildkwargs: factory builder kwargs.
:param kwargs: schema class kwargs.
:return: Schema.
:rtype: Schema.
"""
if _data is None:
return lambda _data: data2schema(
_data, _force=False, _besteffort=True, _registry=None,
_factory=None, _buildkwargs=None, **kwargs
)
result = None
fdata = _data() if isinstance(_data, DynamicValue) else _data
datatype = type(fdata)
content = getattr(fdata, '__dict__', {})
if _buildkwargs:
content.udpate(_buildkwargs)
schemacls = datatype2schemacls(
_datatype=datatype, _registry=_registry, _factory=_factory,
_force=_force, _besteffort=_besteffort, **content
)
if schemacls is not None:
result = schemacls(default=_data, **kwargs)
for attrname in dir(_data):
if not hasattr(schemacls, attrname):
attr = getattr(_data, attrname)
if attr is not None:
setattr(result, attrname, attr)
if result is None and _data is None:
result = AnySchema()
return result
def data2schemacls(_data, **kwargs):
"""Convert a data to a schema cls.
:param data: object or dictionary from where get a schema cls.
:return: schema class.
:rtype: type
"""
content = {}
for key in list(kwargs): # fill kwargs
kwargs[key] = data2schema(kwargs[key])
if isinstance(_data, dict):
datacontent = iteritems(_data)
else:
datacontent = getmembers(_data)
for name, value in datacontent:
if name[0] == '_':
continue
if isinstance(value, dict):
schema = data2schemacls(value)()
else:
schema = data2schema(value)
content[name] = schema
content.update(kwargs) # update content
result = type('GeneratedSchema', (Schema,), content)
return result
class ThisSchema(object):
"""Tool Used to set inner schemas with the same type with specific arguments
.
ThisSchema one might be use at the condition instanciation methods must not
reference the class.
..example::
class Test(Schema):
# contain an inner schema nullable 'test' of type Test.
test = ThisSchema(nullable=False)
def __init__(self, *args, **kwargs):
# old style call because when the schema will be automatically
# updated, the class Test does not exist in the scope
Schema.__init__(self, *args, **kwargs)
:param args: schema class vargs to use.
:param kwargs: schema class kwargs to use.
:return: input args and kwargs.
:rtype: tuple
"""
def __init__(self, *args, **kwargs):
super(ThisSchema, self).__init__()
self.args = args
self.kwargs = kwargs
def validate(schema, data, owner=None):
"""Validate input data with input schema.
:param Schema schema: schema able to validate input data.
:param data: data to validate.
:param Schema owner: input schema parent schema.
:raises: Exception if the data is not validated.
"""
schema._validate(data=data, owner=owner)
def dump(schema):
"""Get a serialized value of input schema.
:param Schema schema: schema to serialize.
:rtype: dict
"""
result = {}
for name, _ in iteritems(schema.getschemas()):
if hasattr(schema, name):
val = getattr(schema, name)
if isinstance(val, DynamicValue):
val = val()
if isinstance(val, Schema):
val = dump(val)
result[name] = val
return result
class RefSchema(Schema):
"""Schema which references another schema."""
ref = Schema(name='ref') #: the reference must be a schema.
def __init__(self, ref=None, *args, **kwargs):
"""
:param Schema ref: refereed schema.
"""
super(RefSchema, self).__init__(*args, **kwargs)
if ref is not None:
if self.default is None:
self.default = ref.default
self.ref = ref
def _validate(self, data, owner=None, *args, **kwargs):
ref = owner if self.ref is None else self.ref
if ref is not self:
ref._validate(data=data, owner=owner, *args, **kwargs)
def _setvalue(self, schema, value, *args, **kwargs):
super(RefSchema, self)._setvalue(schema, value, *args, **kwargs)
if schema.name == 'ref' and value is not None:
if self.default is None and not value.nullable:
self.default = value.default
value._validate(self.default)
def updatecontent(schemacls=None, updateparents=True, exclude=None):
"""Transform all schema class attributes to schemas.
It can be used such as a decorator in order to ensure to update attributes
with the decorated schema but take care to the limitation to use old style
method call for overidden methods.
.. example:
@updatecontent # update content at the end of its definition.
class Test(Schema):
this = ThisSchema() # instance of Test.
def __init__(self, *args, **kwargs):
Test.__init__(self, *args, **kwargs) # old style method call.
:param type schemacls: sub class of Schema.
:param bool updateparents: if True (default), update parent content.
:param list exclude: attribute names to exclude from updating.
:return: schemacls.
"""
if schemacls is None:
return lambda schemacls: updatecontent(
schemacls=schemacls, updateparents=updateparents, exclude=exclude
)
if updateparents and hasattr(schemacls, 'mro'):
schemaclasses = reversed(list(schemacls.mro()))
else:
schemaclasses = [schemacls]
for schemaclass in schemaclasses:
for name, member in iteritems(getattr(schemaclass, '__dict__', {})):
# transform only public members
if name[0] != '_' and (exclude is None or name not in exclude):
toset = False # flag for setting schemas
fmember = member
if isinstance(fmember, DynamicValue):
fmember = fmember()
toset = True
if isinstance(fmember, Schema):
schema = fmember
if not schema.name:
schema.name = name
else:
toset = True
data = member
if name == 'default':
if isinstance(fmember, ThisSchema):
data = schemaclass(*fmember.args, **fmember.kwargs)
schema = RefSchema(default=data, name=name)
elif isinstance(fmember, ThisSchema):
schema = schemaclass(
name=name, *fmember.args, **fmember.kwargs
)
elif member is None:
schema = AnySchema(name=name)
else:
schema = data2schema(_data=data, name=name)
if isinstance(schema, Schema) and toset:
try:
setattr(schemaclass, name, schema)
except (AttributeError, TypeError):
break
return schemacls
updatecontent(RefSchema)
class MetaRegisteredSchema(type):
"""Automatically register schemas."""
def __new__(mcs, *args, **kwargs):
result = super(MetaRegisteredSchema, mcs).__new__(mcs, *args, **kwargs)
# update all sub schemas related to values
if result.__update_content__:
updatecontent(schemacls=result)
return result
def __call__(cls, *args, **kwargs):
result = super(MetaRegisteredSchema, cls).__call__(*args, **kwargs)
if result.__register__: # register all new schema
register(schema=result)
return result
# use metaRegisteredschema such as the schema metaclass
@add_metaclass(MetaRegisteredSchema)
class RegisteredSchema(Schema):
"""Ease auto-registering of schemas and auto-updating content."""
#: Register instances in the registry if True (False by default).
__register__ = False
"""update automatically the content if True (default).
If True, take care to not having called the class in overidden methods.
In such case, take a look to the using of the class ThisSchema which
recommands to use old style method call for overriden methods.
..example:
class Test(Schema):
__udpate_content__ = True # set update content to True
test = ThisSchema()
def __init__(self, *args, **kwargs):
Schema.__init__(self, *args, **kwargs) # old style call.
"""
__update_content__ = True
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
23567,
199,
3,
710,
10697,
844,
334,
13965,
9,
199,
3,
199,
3,
1898,
334,
67,
9,
7800,
1603,
265,
1619,
290,
16871,
5741,
743,
70,
665,
74,
265,
1619,
290,
14,
19879,
743,
70,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
3,
23567,
199,
199,
624,
6700,
15841,
2559,
1041,
199,
199,
504,
3816,
492,
10849,
12,
1050,
63,
6577,
199,
199,
504,
6485,
492,
664,
6334,
199,
199,
504,
1275,
5189,
492,
664,
991,
14184,
12,
2274,
199,
504,
1275,
4159,
14,
3702,
492,
1900,
12,
664,
3629,
1886,
199,
504,
1275,
1095,
492,
13268,
12,
21907,
1110,
199,
199,
363,
452,
363,
275,
359,
272,
283,
14451,
1110,
297,
283,
576,
18,
3629,
297,
283,
3396,
20341,
6700,
297,
283,
2765,
6700,
297,
272,
283,
873,
1317,
297,
283,
3502,
297,
283,
2724,
297,
283,
20341,
6700,
297,
272,
283,
14184,
18,
3629,
1886,
297,
283,
2891,
6700,
297,
283,
576,
18,
3629,
1886,
297,
283,
9874,
6700,
7,
199,
61,
421,
199,
533,
6184,
6700,
8,
6700,
304,
272,
408,
6700,
367,
1263,
666,
1041,
339,
347,
485,
3502,
2031,
589,
12,
1011,
958,
304,
267,
986,
421,
199,
318,
16048,
18,
3629,
1886,
8,
267,
485,
14184,
12,
485,
5189,
29,
403,
12,
485,
3702,
29,
403,
12,
485,
3990,
29,
549,
12,
267,
485,
11562,
266,
556,
361,
29,
549,
12,
1011,
958,
199,
304,
272,
408,
1002,
282,
4177,
1021,
1314,
965,
2757,
4568,
370,
1324,
666,
730,
701,
314,
272,
7086,
503,
314,
6434,
315,
642,
1865,
14,
339,
520,
635,
730,
16048,
26,
666,
730,
687,
2382,
664,
4568,
4177,
14,
272,
520,
635,
13268,
2872,
374,
71,
651,
485,
5189,
26,
7086,
687,
2382,
1240,
314,
664,
991,
14184,
267,
1275,
3758,
365,
314,
2288,
7086,
14,
272,
520,
635,
13268,
2927,
485,
3702,
26,
6434,
687,
2382,
1240,
314,
664,
3629,
1886,
340,
267,
664,
991,
14184,
2529,
488,
14,
3758,
365,
314,
2288,
6434,
14,
272,
520,
635,
2155,
485,
3990,
26,
340,
2549,
334,
885,
395,
3542,
314,
10015,
402,
4177,
1021,
267,
340,
949,
4177,
365,
4568,
370,
1324,
666,
730,
14,
272,
520,
635,
2155,
485,
11562,
266,
556,
361,
26,
340,
715,
334,
885,
395,
862,
370,
7512,
4177,
701,
267,
15433,
14,
272,
520,
635,
1211,
2074,
26,
6434,
6545,
2074,
14,
272,
520,
4500,
26,
730,
272,
520,
1107,
26,
13268,
4568,
370,
1324,
7086,
503,
6434,
14,
488,
340,
949,
267,
20640,
1911,
14,
272,
408,
272,
754,
275,
488,
339,
12124,
84,
275,
664,
991,
14184,
340,
485,
5189,
365,
488,
587,
485,
5189,
14,
362,
991,
14184,
339,
754,
275,
12124,
84,
1547,
14184,
12,
330,
397,
266,
556,
361,
3699,
11562,
266,
556,
361,
9,
339,
340,
754,
365,
488,
26,
267,
8763,
1886,
275,
664,
3629,
1886,
340,
485,
3702,
365,
488,
587,
485,
3702,
14,
362,
3629,
1886,
267,
754,
275,
8763,
1886,
1547,
14184,
12,
330,
397,
266,
556,
361,
3699,
11562,
266,
556,
361,
9,
339,
340,
754,
365,
488,
436,
485,
3990,
26,
267,
485,
1506,
275,
1900,
340,
485,
3702,
365,
488,
587,
485,
3702,
14,
1506,
398,
754,
275,
485,
1506,
1547,
1927,
3699,
14184,
12,
1011,
958,
9,
339,
372,
754,
421,
199,
318,
666,
18,
3629,
8,
267,
485,
576,
29,
403,
12,
485,
3990,
29,
797,
12,
485,
11562,
266,
556,
361,
29,
549,
12,
485,
5189,
29,
403,
12,
267,
485,
3702,
29,
403,
12,
485,
1506,
958,
29,
403,
12,
1011,
958,
199,
304,
272,
408,
1002,
314,
4177,
7688,
370,
2727,
290,
559,
323,
1324,
666,
14,
339,
710,
849,
574,
402,
4177,
911,
506,
666,
14,
339,
6855,
506,
1202,
4066,
465,
282,
7531,
26,
339,
2508,
600,
13,
1457,
447,
2366,
398,
768,
576,
18,
3629,
267,
347,
2893,
837,
986,
221,
327,
372,
282,
805,
4177,
398,
768,
576,
18,
3629,
1547,
5189,
29,
1662,
5189,
9,
267,
347,
2893,
837,
986,
221,
327,
372,
282,
805,
4177,
543,
2488,
7086,
339,
2508,
3764,
447,
398,
372,
642,
805,
1305,
485,
576,
365,
488,
14,
339,
520,
635,
485,
576,
26,
666,
12570,
4046,
701,
282,
4177,
14,
11105,
1325,
315,
1930,
402,
267,
7531,
14,
272,
520,
635,
2155,
485,
3990,
26,
340,
715,
334,
797,
701,
849,
395,
1218,
314,
666,
4177,
267,
641,
314,
23158,
340,
652,
1630,
440,
2187,
14,
272,
520,
635,
2155,
485,
11562,
266,
556,
361,
26,
340,
715,
334,
885,
395,
2342,
282,
4177,
1021,
7688,
370,
267,
4107,
666,
1021,
701,
15433,
14,
272,
520,
635,
13268,
10899,
485,
5189,
26,
849,
7086,
370,
675,
14,
13641,
701,
267,
849,
14,
272,
520,
635,
13268,
2927,
6434,
26
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
23567,
199,
3,
710,
10697,
844,
334,
13965,
9,
199,
3,
199,
3,
1898,
334,
67,
9,
7800,
1603,
265,
1619,
290,
16871,
5741,
743,
70,
665,
74,
265,
1619,
290,
14,
19879,
743,
70,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
3,
23567,
199,
199,
624,
6700,
15841,
2559,
1041,
199,
199,
504,
3816,
492,
10849,
12,
1050,
63,
6577,
199,
199,
504,
6485,
492,
664,
6334,
199,
199,
504,
1275,
5189,
492,
664,
991,
14184,
12,
2274,
199,
504,
1275,
4159,
14,
3702,
492,
1900,
12,
664,
3629,
1886,
199,
504,
1275,
1095,
492,
13268,
12,
21907,
1110,
199,
199,
363,
452,
363,
275,
359,
272,
283,
14451,
1110,
297,
283,
576,
18,
3629,
297,
283,
3396,
20341,
6700,
297,
283,
2765,
6700,
297,
272,
283,
873,
1317,
297,
283,
3502,
297,
283,
2724,
297,
283,
20341,
6700,
297,
272,
283,
14184,
18,
3629,
1886,
297,
283,
2891,
6700,
297,
283,
576,
18,
3629,
1886,
297,
283,
9874,
6700,
7,
199,
61,
421,
199,
533,
6184,
6700,
8,
6700,
304,
272,
408,
6700,
367,
1263,
666,
1041,
339,
347,
485,
3502,
2031,
589,
12,
1011,
958,
304,
267,
986,
421,
199,
318,
16048,
18,
3629,
1886,
8,
267,
485,
14184,
12,
485,
5189,
29,
403,
12,
485,
3702,
29,
403,
12,
485,
3990,
29,
549,
12,
267,
485,
11562,
266,
556,
361,
29,
549,
12,
1011,
958,
199,
304,
272,
408,
1002,
282,
4177,
1021,
1314,
965,
2757,
4568,
370,
1324,
666,
730,
701,
314,
272,
7086,
503,
314,
6434,
315,
642,
1865,
14,
339,
520,
635,
730,
16048,
26,
666,
730,
687,
2382,
664,
4568,
4177,
14,
272,
520,
635,
13268,
2872,
374,
71,
651,
485,
5189,
26,
7086,
687,
2382,
1240,
314,
664,
991,
14184,
267,
1275,
3758,
365,
314,
2288,
7086,
14,
272,
520,
635,
13268,
2927,
485,
3702,
26,
6434,
687,
2382,
1240,
314,
664,
3629,
1886,
340,
267,
664,
991,
14184,
2529,
488,
14,
3758,
365,
314,
2288,
6434,
14,
272,
520,
635,
2155,
485,
3990,
26,
340,
2549,
334,
885,
395,
3542,
314,
10015,
402,
4177,
1021,
267,
340,
949,
4177,
365,
4568,
370,
1324,
666,
730,
14,
272,
520,
635,
2155,
485,
11562,
266,
556,
361,
26,
340,
715,
334,
885,
395,
862,
370,
7512,
4177,
701,
267,
15433,
14,
272,
520,
635,
1211,
2074,
26,
6434,
6545,
2074,
14,
272,
520,
4500,
26,
730,
272,
520,
1107,
26,
13268,
4568,
370,
1324,
7086,
503,
6434,
14,
488,
340,
949,
267,
20640,
1911,
14,
272,
408,
272,
754,
275,
488,
339,
12124,
84,
275,
664,
991,
14184,
340,
485,
5189,
365,
488,
587,
485,
5189,
14,
362,
991,
14184,
339,
754,
275,
12124,
84,
1547,
14184,
12,
330,
397,
266,
556,
361,
3699,
11562,
266,
556,
361,
9,
339,
340,
754,
365,
488,
26,
267,
8763,
1886,
275,
664,
3629,
1886,
340,
485,
3702,
365,
488,
587,
485,
3702,
14,
362,
3629,
1886,
267,
754,
275,
8763,
1886,
1547,
14184,
12,
330,
397,
266,
556,
361,
3699,
11562,
266,
556,
361,
9,
339,
340,
754,
365,
488,
436,
485,
3990,
26,
267,
485,
1506,
275,
1900,
340,
485,
3702,
365,
488,
587,
485,
3702,
14,
1506,
398,
754,
275,
485,
1506,
1547,
1927,
3699,
14184,
12,
1011,
958,
9,
339,
372,
754,
421,
199,
318,
666,
18,
3629,
8,
267,
485,
576,
29,
403,
12,
485,
3990,
29,
797,
12,
485,
11562,
266,
556,
361,
29,
549,
12,
485,
5189,
29,
403,
12,
267,
485,
3702,
29,
403,
12,
485,
1506,
958,
29,
403,
12,
1011,
958,
199,
304,
272,
408,
1002,
314,
4177,
7688,
370,
2727,
290,
559,
323,
1324,
666,
14,
339,
710,
849,
574,
402,
4177,
911,
506,
666,
14,
339,
6855,
506,
1202,
4066,
465,
282,
7531,
26,
339,
2508,
600,
13,
1457,
447,
2366,
398,
768,
576,
18,
3629,
267,
347,
2893,
837,
986,
221,
327,
372,
282,
805,
4177,
398,
768,
576,
18,
3629,
1547,
5189,
29,
1662,
5189,
9,
267,
347,
2893,
837,
986,
221,
327,
372,
282,
805,
4177,
543,
2488,
7086,
339,
2508,
3764,
447,
398,
372,
642,
805,
1305,
485,
576,
365,
488,
14,
339,
520,
635,
485,
576,
26,
666,
12570,
4046,
701,
282,
4177,
14,
11105,
1325,
315,
1930,
402,
267,
7531,
14,
272,
520,
635,
2155,
485,
3990,
26,
340,
715,
334,
797,
701,
849,
395,
1218,
314,
666,
4177,
267,
641,
314,
23158,
340,
652,
1630,
440,
2187,
14,
272,
520,
635,
2155,
485,
11562,
266,
556,
361,
26,
340,
715,
334,
885,
395,
2342,
282,
4177,
1021,
7688,
370,
267,
4107,
666,
1021,
701,
15433,
14,
272,
520,
635,
13268,
10899,
485,
5189,
26,
849,
7086,
370,
675,
14,
13641,
701,
267,
849,
14,
272,
520,
635,
13268,
2927,
6434,
26,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
getbraincloud/braincloud-cpp
|
tests/gtest-1.7.0/test/gtest_filter_unittest.py
|
2826
|
21261
|
#!/usr/bin/env python
#
# Copyright 2005 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.
"""Unit test for Google Test test filters.
A user can specify which test(s) in a Google Test program to run via either
the GTEST_FILTER environment variable or the --gtest_filter flag.
This script tests such functionality by invoking
gtest_filter_unittest_ (a program written with Google Test) with different
environments and command line flags.
Note that test sharding may also influence which tests are filtered. Therefore,
we test that here also.
"""
__author__ = 'wan@google.com (Zhanyong Wan)'
import os
import re
import sets
import sys
import gtest_test_utils
# Constants.
# Checks if this platform can pass empty environment variables to child
# processes. We set an env variable to an empty string and invoke a python
# script in a subprocess to print whether the variable is STILL in
# os.environ. We then use 'eval' to parse the child's output so that an
# exception is thrown if the input is anything other than 'True' nor 'False'.
os.environ['EMPTY_VAR'] = ''
child = gtest_test_utils.Subprocess(
[sys.executable, '-c', 'import os; print \'EMPTY_VAR\' in os.environ'])
CAN_PASS_EMPTY_ENV = eval(child.output)
# Check if this platform can unset environment variables in child processes.
# We set an env variable to a non-empty string, unset it, and invoke
# a python script in a subprocess to print whether the variable
# is NO LONGER in os.environ.
# We use 'eval' to parse the child's output so that an exception
# is thrown if the input is neither 'True' nor 'False'.
os.environ['UNSET_VAR'] = 'X'
del os.environ['UNSET_VAR']
child = gtest_test_utils.Subprocess(
[sys.executable, '-c', 'import os; print \'UNSET_VAR\' not in os.environ'])
CAN_UNSET_ENV = eval(child.output)
# Checks if we should test with an empty filter. This doesn't
# make sense on platforms that cannot pass empty env variables (Win32)
# and on platforms that cannot unset variables (since we cannot tell
# the difference between "" and NULL -- Borland and Solaris < 5.10)
CAN_TEST_EMPTY_FILTER = (CAN_PASS_EMPTY_ENV and CAN_UNSET_ENV)
# The environment variable for specifying the test filters.
FILTER_ENV_VAR = 'GTEST_FILTER'
# The environment variables for test sharding.
TOTAL_SHARDS_ENV_VAR = 'GTEST_TOTAL_SHARDS'
SHARD_INDEX_ENV_VAR = 'GTEST_SHARD_INDEX'
SHARD_STATUS_FILE_ENV_VAR = 'GTEST_SHARD_STATUS_FILE'
# The command line flag for specifying the test filters.
FILTER_FLAG = 'gtest_filter'
# The command line flag for including disabled tests.
ALSO_RUN_DISABED_TESTS_FLAG = 'gtest_also_run_disabled_tests'
# Command to run the gtest_filter_unittest_ program.
COMMAND = gtest_test_utils.GetTestExecutablePath('gtest_filter_unittest_')
# Regex for determining whether parameterized tests are enabled in the binary.
PARAM_TEST_REGEX = re.compile(r'/ParamTest')
# Regex for parsing test case names from Google Test's output.
TEST_CASE_REGEX = re.compile(r'^\[\-+\] \d+ tests? from (\w+(/\w+)?)')
# Regex for parsing test names from Google Test's output.
TEST_REGEX = re.compile(r'^\[\s*RUN\s*\].*\.(\w+(/\w+)?)')
# The command line flag to tell Google Test to output the list of tests it
# will run.
LIST_TESTS_FLAG = '--gtest_list_tests'
# Indicates whether Google Test supports death tests.
SUPPORTS_DEATH_TESTS = 'HasDeathTest' in gtest_test_utils.Subprocess(
[COMMAND, LIST_TESTS_FLAG]).output
# Full names of all tests in gtest_filter_unittests_.
PARAM_TESTS = [
'SeqP/ParamTest.TestX/0',
'SeqP/ParamTest.TestX/1',
'SeqP/ParamTest.TestY/0',
'SeqP/ParamTest.TestY/1',
'SeqQ/ParamTest.TestX/0',
'SeqQ/ParamTest.TestX/1',
'SeqQ/ParamTest.TestY/0',
'SeqQ/ParamTest.TestY/1',
]
DISABLED_TESTS = [
'BarTest.DISABLED_TestFour',
'BarTest.DISABLED_TestFive',
'BazTest.DISABLED_TestC',
'DISABLED_FoobarTest.Test1',
'DISABLED_FoobarTest.DISABLED_Test2',
'DISABLED_FoobarbazTest.TestA',
]
if SUPPORTS_DEATH_TESTS:
DEATH_TESTS = [
'HasDeathTest.Test1',
'HasDeathTest.Test2',
]
else:
DEATH_TESTS = []
# All the non-disabled tests.
ACTIVE_TESTS = [
'FooTest.Abc',
'FooTest.Xyz',
'BarTest.TestOne',
'BarTest.TestTwo',
'BarTest.TestThree',
'BazTest.TestOne',
'BazTest.TestA',
'BazTest.TestB',
] + DEATH_TESTS + PARAM_TESTS
param_tests_present = None
# Utilities.
environ = os.environ.copy()
def SetEnvVar(env_var, value):
"""Sets the env variable to 'value'; unsets it when 'value' is None."""
if value is not None:
environ[env_var] = value
elif env_var in environ:
del environ[env_var]
def RunAndReturnOutput(args = None):
"""Runs the test program and returns its output."""
return gtest_test_utils.Subprocess([COMMAND] + (args or []),
env=environ).output
def RunAndExtractTestList(args = None):
"""Runs the test program and returns its exit code and a list of tests run."""
p = gtest_test_utils.Subprocess([COMMAND] + (args or []), env=environ)
tests_run = []
test_case = ''
test = ''
for line in p.output.split('\n'):
match = TEST_CASE_REGEX.match(line)
if match is not None:
test_case = match.group(1)
else:
match = TEST_REGEX.match(line)
if match is not None:
test = match.group(1)
tests_run.append(test_case + '.' + test)
return (tests_run, p.exit_code)
def InvokeWithModifiedEnv(extra_env, function, *args, **kwargs):
"""Runs the given function and arguments in a modified environment."""
try:
original_env = environ.copy()
environ.update(extra_env)
return function(*args, **kwargs)
finally:
environ.clear()
environ.update(original_env)
def RunWithSharding(total_shards, shard_index, command):
"""Runs a test program shard and returns exit code and a list of tests run."""
extra_env = {SHARD_INDEX_ENV_VAR: str(shard_index),
TOTAL_SHARDS_ENV_VAR: str(total_shards)}
return InvokeWithModifiedEnv(extra_env, RunAndExtractTestList, command)
# The unit test.
class GTestFilterUnitTest(gtest_test_utils.TestCase):
"""Tests the env variable or the command line flag to filter tests."""
# Utilities.
def AssertSetEqual(self, lhs, rhs):
"""Asserts that two sets are equal."""
for elem in lhs:
self.assert_(elem in rhs, '%s in %s' % (elem, rhs))
for elem in rhs:
self.assert_(elem in lhs, '%s in %s' % (elem, lhs))
def AssertPartitionIsValid(self, set_var, list_of_sets):
"""Asserts that list_of_sets is a valid partition of set_var."""
full_partition = []
for slice_var in list_of_sets:
full_partition.extend(slice_var)
self.assertEqual(len(set_var), len(full_partition))
self.assertEqual(sets.Set(set_var), sets.Set(full_partition))
def AdjustForParameterizedTests(self, tests_to_run):
"""Adjust tests_to_run in case value parameterized tests are disabled."""
global param_tests_present
if not param_tests_present:
return list(sets.Set(tests_to_run) - sets.Set(PARAM_TESTS))
else:
return tests_to_run
def RunAndVerify(self, gtest_filter, tests_to_run):
"""Checks that the binary runs correct set of tests for a given filter."""
tests_to_run = self.AdjustForParameterizedTests(tests_to_run)
# First, tests using the environment variable.
# Windows removes empty variables from the environment when passing it
# to a new process. This means it is impossible to pass an empty filter
# into a process using the environment variable. However, we can still
# test the case when the variable is not supplied (i.e., gtest_filter is
# None).
# pylint: disable-msg=C6403
if CAN_TEST_EMPTY_FILTER or gtest_filter != '':
SetEnvVar(FILTER_ENV_VAR, gtest_filter)
tests_run = RunAndExtractTestList()[0]
SetEnvVar(FILTER_ENV_VAR, None)
self.AssertSetEqual(tests_run, tests_to_run)
# pylint: enable-msg=C6403
# Next, tests using the command line flag.
if gtest_filter is None:
args = []
else:
args = ['--%s=%s' % (FILTER_FLAG, gtest_filter)]
tests_run = RunAndExtractTestList(args)[0]
self.AssertSetEqual(tests_run, tests_to_run)
def RunAndVerifyWithSharding(self, gtest_filter, total_shards, tests_to_run,
args=None, check_exit_0=False):
"""Checks that binary runs correct tests for the given filter and shard.
Runs all shards of gtest_filter_unittest_ with the given filter, and
verifies that the right set of tests were run. The union of tests run
on each shard should be identical to tests_to_run, without duplicates.
Args:
gtest_filter: A filter to apply to the tests.
total_shards: A total number of shards to split test run into.
tests_to_run: A set of tests expected to run.
args : Arguments to pass to the to the test binary.
check_exit_0: When set to a true value, make sure that all shards
return 0.
"""
tests_to_run = self.AdjustForParameterizedTests(tests_to_run)
# Windows removes empty variables from the environment when passing it
# to a new process. This means it is impossible to pass an empty filter
# into a process using the environment variable. However, we can still
# test the case when the variable is not supplied (i.e., gtest_filter is
# None).
# pylint: disable-msg=C6403
if CAN_TEST_EMPTY_FILTER or gtest_filter != '':
SetEnvVar(FILTER_ENV_VAR, gtest_filter)
partition = []
for i in range(0, total_shards):
(tests_run, exit_code) = RunWithSharding(total_shards, i, args)
if check_exit_0:
self.assertEqual(0, exit_code)
partition.append(tests_run)
self.AssertPartitionIsValid(tests_to_run, partition)
SetEnvVar(FILTER_ENV_VAR, None)
# pylint: enable-msg=C6403
def RunAndVerifyAllowingDisabled(self, gtest_filter, tests_to_run):
"""Checks that the binary runs correct set of tests for the given filter.
Runs gtest_filter_unittest_ with the given filter, and enables
disabled tests. Verifies that the right set of tests were run.
Args:
gtest_filter: A filter to apply to the tests.
tests_to_run: A set of tests expected to run.
"""
tests_to_run = self.AdjustForParameterizedTests(tests_to_run)
# Construct the command line.
args = ['--%s' % ALSO_RUN_DISABED_TESTS_FLAG]
if gtest_filter is not None:
args.append('--%s=%s' % (FILTER_FLAG, gtest_filter))
tests_run = RunAndExtractTestList(args)[0]
self.AssertSetEqual(tests_run, tests_to_run)
def setUp(self):
"""Sets up test case.
Determines whether value-parameterized tests are enabled in the binary and
sets the flags accordingly.
"""
global param_tests_present
if param_tests_present is None:
param_tests_present = PARAM_TEST_REGEX.search(
RunAndReturnOutput()) is not None
def testDefaultBehavior(self):
"""Tests the behavior of not specifying the filter."""
self.RunAndVerify(None, ACTIVE_TESTS)
def testDefaultBehaviorWithShards(self):
"""Tests the behavior without the filter, with sharding enabled."""
self.RunAndVerifyWithSharding(None, 1, ACTIVE_TESTS)
self.RunAndVerifyWithSharding(None, 2, ACTIVE_TESTS)
self.RunAndVerifyWithSharding(None, len(ACTIVE_TESTS) - 1, ACTIVE_TESTS)
self.RunAndVerifyWithSharding(None, len(ACTIVE_TESTS), ACTIVE_TESTS)
self.RunAndVerifyWithSharding(None, len(ACTIVE_TESTS) + 1, ACTIVE_TESTS)
def testEmptyFilter(self):
"""Tests an empty filter."""
self.RunAndVerify('', [])
self.RunAndVerifyWithSharding('', 1, [])
self.RunAndVerifyWithSharding('', 2, [])
def testBadFilter(self):
"""Tests a filter that matches nothing."""
self.RunAndVerify('BadFilter', [])
self.RunAndVerifyAllowingDisabled('BadFilter', [])
def testFullName(self):
"""Tests filtering by full name."""
self.RunAndVerify('FooTest.Xyz', ['FooTest.Xyz'])
self.RunAndVerifyAllowingDisabled('FooTest.Xyz', ['FooTest.Xyz'])
self.RunAndVerifyWithSharding('FooTest.Xyz', 5, ['FooTest.Xyz'])
def testUniversalFilters(self):
"""Tests filters that match everything."""
self.RunAndVerify('*', ACTIVE_TESTS)
self.RunAndVerify('*.*', ACTIVE_TESTS)
self.RunAndVerifyWithSharding('*.*', len(ACTIVE_TESTS) - 3, ACTIVE_TESTS)
self.RunAndVerifyAllowingDisabled('*', ACTIVE_TESTS + DISABLED_TESTS)
self.RunAndVerifyAllowingDisabled('*.*', ACTIVE_TESTS + DISABLED_TESTS)
def testFilterByTestCase(self):
"""Tests filtering by test case name."""
self.RunAndVerify('FooTest.*', ['FooTest.Abc', 'FooTest.Xyz'])
BAZ_TESTS = ['BazTest.TestOne', 'BazTest.TestA', 'BazTest.TestB']
self.RunAndVerify('BazTest.*', BAZ_TESTS)
self.RunAndVerifyAllowingDisabled('BazTest.*',
BAZ_TESTS + ['BazTest.DISABLED_TestC'])
def testFilterByTest(self):
"""Tests filtering by test name."""
self.RunAndVerify('*.TestOne', ['BarTest.TestOne', 'BazTest.TestOne'])
def testFilterDisabledTests(self):
"""Select only the disabled tests to run."""
self.RunAndVerify('DISABLED_FoobarTest.Test1', [])
self.RunAndVerifyAllowingDisabled('DISABLED_FoobarTest.Test1',
['DISABLED_FoobarTest.Test1'])
self.RunAndVerify('*DISABLED_*', [])
self.RunAndVerifyAllowingDisabled('*DISABLED_*', DISABLED_TESTS)
self.RunAndVerify('*.DISABLED_*', [])
self.RunAndVerifyAllowingDisabled('*.DISABLED_*', [
'BarTest.DISABLED_TestFour',
'BarTest.DISABLED_TestFive',
'BazTest.DISABLED_TestC',
'DISABLED_FoobarTest.DISABLED_Test2',
])
self.RunAndVerify('DISABLED_*', [])
self.RunAndVerifyAllowingDisabled('DISABLED_*', [
'DISABLED_FoobarTest.Test1',
'DISABLED_FoobarTest.DISABLED_Test2',
'DISABLED_FoobarbazTest.TestA',
])
def testWildcardInTestCaseName(self):
"""Tests using wildcard in the test case name."""
self.RunAndVerify('*a*.*', [
'BarTest.TestOne',
'BarTest.TestTwo',
'BarTest.TestThree',
'BazTest.TestOne',
'BazTest.TestA',
'BazTest.TestB', ] + DEATH_TESTS + PARAM_TESTS)
def testWildcardInTestName(self):
"""Tests using wildcard in the test name."""
self.RunAndVerify('*.*A*', ['FooTest.Abc', 'BazTest.TestA'])
def testFilterWithoutDot(self):
"""Tests a filter that has no '.' in it."""
self.RunAndVerify('*z*', [
'FooTest.Xyz',
'BazTest.TestOne',
'BazTest.TestA',
'BazTest.TestB',
])
def testTwoPatterns(self):
"""Tests filters that consist of two patterns."""
self.RunAndVerify('Foo*.*:*A*', [
'FooTest.Abc',
'FooTest.Xyz',
'BazTest.TestA',
])
# An empty pattern + a non-empty one
self.RunAndVerify(':*A*', ['FooTest.Abc', 'BazTest.TestA'])
def testThreePatterns(self):
"""Tests filters that consist of three patterns."""
self.RunAndVerify('*oo*:*A*:*One', [
'FooTest.Abc',
'FooTest.Xyz',
'BarTest.TestOne',
'BazTest.TestOne',
'BazTest.TestA',
])
# The 2nd pattern is empty.
self.RunAndVerify('*oo*::*One', [
'FooTest.Abc',
'FooTest.Xyz',
'BarTest.TestOne',
'BazTest.TestOne',
])
# The last 2 patterns are empty.
self.RunAndVerify('*oo*::', [
'FooTest.Abc',
'FooTest.Xyz',
])
def testNegativeFilters(self):
self.RunAndVerify('*-BazTest.TestOne', [
'FooTest.Abc',
'FooTest.Xyz',
'BarTest.TestOne',
'BarTest.TestTwo',
'BarTest.TestThree',
'BazTest.TestA',
'BazTest.TestB',
] + DEATH_TESTS + PARAM_TESTS)
self.RunAndVerify('*-FooTest.Abc:BazTest.*', [
'FooTest.Xyz',
'BarTest.TestOne',
'BarTest.TestTwo',
'BarTest.TestThree',
] + DEATH_TESTS + PARAM_TESTS)
self.RunAndVerify('BarTest.*-BarTest.TestOne', [
'BarTest.TestTwo',
'BarTest.TestThree',
])
# Tests without leading '*'.
self.RunAndVerify('-FooTest.Abc:FooTest.Xyz:BazTest.*', [
'BarTest.TestOne',
'BarTest.TestTwo',
'BarTest.TestThree',
] + DEATH_TESTS + PARAM_TESTS)
# Value parameterized tests.
self.RunAndVerify('*/*', PARAM_TESTS)
# Value parameterized tests filtering by the sequence name.
self.RunAndVerify('SeqP/*', [
'SeqP/ParamTest.TestX/0',
'SeqP/ParamTest.TestX/1',
'SeqP/ParamTest.TestY/0',
'SeqP/ParamTest.TestY/1',
])
# Value parameterized tests filtering by the test name.
self.RunAndVerify('*/0', [
'SeqP/ParamTest.TestX/0',
'SeqP/ParamTest.TestY/0',
'SeqQ/ParamTest.TestX/0',
'SeqQ/ParamTest.TestY/0',
])
def testFlagOverridesEnvVar(self):
"""Tests that the filter flag overrides the filtering env. variable."""
SetEnvVar(FILTER_ENV_VAR, 'Foo*')
args = ['--%s=%s' % (FILTER_FLAG, '*One')]
tests_run = RunAndExtractTestList(args)[0]
SetEnvVar(FILTER_ENV_VAR, None)
self.AssertSetEqual(tests_run, ['BarTest.TestOne', 'BazTest.TestOne'])
def testShardStatusFileIsCreated(self):
"""Tests that the shard file is created if specified in the environment."""
shard_status_file = os.path.join(gtest_test_utils.GetTempDir(),
'shard_status_file')
self.assert_(not os.path.exists(shard_status_file))
extra_env = {SHARD_STATUS_FILE_ENV_VAR: shard_status_file}
try:
InvokeWithModifiedEnv(extra_env, RunAndReturnOutput)
finally:
self.assert_(os.path.exists(shard_status_file))
os.remove(shard_status_file)
def testShardStatusFileIsCreatedWithListTests(self):
"""Tests that the shard file is created with the "list_tests" flag."""
shard_status_file = os.path.join(gtest_test_utils.GetTempDir(),
'shard_status_file2')
self.assert_(not os.path.exists(shard_status_file))
extra_env = {SHARD_STATUS_FILE_ENV_VAR: shard_status_file}
try:
output = InvokeWithModifiedEnv(extra_env,
RunAndReturnOutput,
[LIST_TESTS_FLAG])
finally:
# This assertion ensures that Google Test enumerated the tests as
# opposed to running them.
self.assert_('[==========]' not in output,
'Unexpected output during test enumeration.\n'
'Please ensure that LIST_TESTS_FLAG is assigned the\n'
'correct flag value for listing Google Test tests.')
self.assert_(os.path.exists(shard_status_file))
os.remove(shard_status_file)
if SUPPORTS_DEATH_TESTS:
def testShardingWorksWithDeathTests(self):
"""Tests integration with death tests and sharding."""
gtest_filter = 'HasDeathTest.*:SeqP/*'
expected_tests = [
'HasDeathTest.Test1',
'HasDeathTest.Test2',
'SeqP/ParamTest.TestX/0',
'SeqP/ParamTest.TestX/1',
'SeqP/ParamTest.TestY/0',
'SeqP/ParamTest.TestY/1',
]
for flag in ['--gtest_death_test_style=threadsafe',
'--gtest_death_test_style=fast']:
self.RunAndVerifyWithSharding(gtest_filter, 3, expected_tests,
check_exit_0=True, args=[flag])
self.RunAndVerifyWithSharding(gtest_filter, 5, expected_tests,
check_exit_0=True, args=[flag])
if __name__ == '__main__':
gtest_test_utils.Main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
11811,
4475,
3277,
14,
2900,
5924,
5702,
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,
5072,
511,
367,
4475,
1379,
511,
4766,
14,
199,
199,
33,
922,
883,
4165,
1314,
511,
8,
83,
9,
315,
282,
4475,
1379,
2240,
370,
1255,
4799,
1902,
199,
1589,
18652,
63,
9905,
3734,
1750,
503,
314,
1553,
8385,
63,
1541,
3305,
14,
199,
2765,
2884,
2295,
4066,
9330,
701,
26750,
199,
8385,
63,
1541,
63,
2796,
63,
334,
65,
2240,
5313,
543,
4475,
1379,
9,
543,
3365,
199,
26411,
436,
1414,
1004,
3285,
14,
199,
199,
7443,
626,
511,
11814,
316,
1443,
2597,
315,
24585,
1314,
2295,
787,
9806,
14,
21039,
12,
199,
1129,
511,
626,
2348,
2597,
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,
5951,
199,
646,
984,
199,
199,
646,
9088,
63,
396,
63,
1208,
199,
199,
3,
22296,
14,
199,
199,
3,
13813,
340,
642,
4298,
883,
986,
2701,
3734,
2860,
370,
1982,
199,
3,
10358,
14,
221,
2136,
663,
376,
2589,
1750,
370,
376,
2701,
1059,
436,
12677,
282,
2366,
199,
3,
2884,
315,
282,
3873,
370,
870,
3775,
314,
1750,
365,
4384,
14961,
315,
199,
3,
747,
14,
2314,
14,
221,
2136,
2066,
675,
283,
2579,
7,
370,
2198,
314,
1982,
1159,
1072,
880,
626,
376,
199,
3,
1919,
365,
14031,
340,
314,
1324,
365,
7003,
1163,
2419,
283,
549,
7,
6590,
283,
797,
1370,
199,
736,
14,
2314,
459,
13993,
63,
5568,
418,
275,
2125,
199,
1739,
275,
9088,
63,
396,
63,
1208,
14,
22299,
8,
272,
359,
1274,
14,
5904,
12,
2475,
67,
297,
283,
646,
747,
27,
870,
8891,
13993,
63,
5568,
3985,
315,
747,
14,
2314,
1105,
199,
18988,
63,
6909,
63,
13993,
63,
9984,
275,
3468,
8,
1739,
14,
1199,
9,
421,
199,
3,
2670,
340,
642,
4298,
883,
15376,
3734,
2860,
315,
1982,
10358,
14,
199,
3,
2136,
663,
376,
2589,
1750,
370,
282,
2222,
13,
1667,
1059,
12,
15376,
652,
12,
436,
12677,
199,
3,
282,
2366,
2884,
315,
282,
3873,
370,
870,
3775,
314,
1750,
199,
3,
365,
4825,
26594,
540,
315,
747,
14,
2314,
14,
199,
3,
2136,
675,
283,
2579,
7,
370,
2198,
314,
1982,
1159,
1072,
880,
626,
376,
1919,
199,
3,
365,
14031,
340,
314,
1324,
365,
15564,
283,
549,
7,
6590,
283,
797,
1370,
199,
736,
14,
2314,
459,
1734,
3597,
63,
5568,
418,
275,
283,
56,
7,
199,
2264,
747,
14,
2314,
459,
1734,
3597,
63,
5568,
418,
199,
1739,
275,
9088,
63,
396,
63,
1208,
14,
22299,
8,
272,
359,
1274,
14,
5904,
12,
2475,
67,
297,
283,
646,
747,
27,
870,
8891,
1734,
3597,
63,
5568,
3985,
440,
315,
747,
14,
2314,
1105,
199,
18988,
63,
1734,
3597,
63,
9984,
275,
3468,
8,
1739,
14,
1199,
9,
421,
199,
3,
13813,
340,
781,
1077,
511,
543,
376,
2701,
2457,
14,
961,
3181,
1133,
199,
3,
1852,
12249,
641,
10677,
626,
3913,
986,
2701,
2589,
2860,
334,
8886,
708,
9,
199,
3,
436,
641,
10677,
626,
3913,
15376,
2860,
334,
8585,
781,
3913,
11480,
199,
3,
314,
8865,
3382,
3087,
436,
5962,
1553,
699,
269,
9688,
436,
17991,
4663,
665,
959,
14,
709,
9,
199,
18988,
63,
2864,
63,
13993,
63,
9905,
275,
334,
18988,
63,
6909,
63,
13993,
63,
9984,
436,
29661,
63,
1734,
3597,
63,
9984,
9,
421,
199,
3,
710,
3734,
1750,
367,
9176,
314,
511,
4766,
14,
199,
9905,
63,
9984,
63,
5568,
275,
283,
16151,
63,
9905,
7,
199,
199,
3,
710,
3734,
2860,
367,
511,
11814,
316,
14,
199,
15386,
63,
11152,
3177,
63,
9984,
63,
5568,
275,
283,
16151,
63,
15386,
63,
11152,
3177,
7,
199,
3234,
7816,
63,
10215,
63,
9984,
63,
5568,
275,
283,
16151,
63,
3234,
7816,
63,
10215,
7,
199,
3234,
7816,
63,
6305,
63,
3817,
63,
9984,
63,
5568,
275,
283,
16151,
63,
3234,
7816,
63,
6305,
63,
3817,
7,
199,
199,
3,
710,
1414,
1004,
3305,
367,
9176,
314,
511,
4766,
14,
199,
9905,
63,
3719,
275,
283,
8385,
63,
1541,
7,
199,
199,
3,
710,
1414,
1004,
3305,
367,
5893,
6980,
2295,
14,
199,
748,
4118,
63,
9390,
63,
6178,
1217,
1149,
63,
7569,
63
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
11811,
4475,
3277,
14,
2900,
5924,
5702,
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,
5072,
511,
367,
4475,
1379,
511,
4766,
14,
199,
199,
33,
922,
883,
4165,
1314,
511,
8,
83,
9,
315,
282,
4475,
1379,
2240,
370,
1255,
4799,
1902,
199,
1589,
18652,
63,
9905,
3734,
1750,
503,
314,
1553,
8385,
63,
1541,
3305,
14,
199,
2765,
2884,
2295,
4066,
9330,
701,
26750,
199,
8385,
63,
1541,
63,
2796,
63,
334,
65,
2240,
5313,
543,
4475,
1379,
9,
543,
3365,
199,
26411,
436,
1414,
1004,
3285,
14,
199,
199,
7443,
626,
511,
11814,
316,
1443,
2597,
315,
24585,
1314,
2295,
787,
9806,
14,
21039,
12,
199,
1129,
511,
626,
2348,
2597,
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,
5951,
199,
646,
984,
199,
199,
646,
9088,
63,
396,
63,
1208,
199,
199,
3,
22296,
14,
199,
199,
3,
13813,
340,
642,
4298,
883,
986,
2701,
3734,
2860,
370,
1982,
199,
3,
10358,
14,
221,
2136,
663,
376,
2589,
1750,
370,
376,
2701,
1059,
436,
12677,
282,
2366,
199,
3,
2884,
315,
282,
3873,
370,
870,
3775,
314,
1750,
365,
4384,
14961,
315,
199,
3,
747,
14,
2314,
14,
221,
2136,
2066,
675,
283,
2579,
7,
370,
2198,
314,
1982,
1159,
1072,
880,
626,
376,
199,
3,
1919,
365,
14031,
340,
314,
1324,
365,
7003,
1163,
2419,
283,
549,
7,
6590,
283,
797,
1370,
199,
736,
14,
2314,
459,
13993,
63,
5568,
418,
275,
2125,
199,
1739,
275,
9088,
63,
396,
63,
1208,
14,
22299,
8,
272,
359,
1274,
14,
5904,
12,
2475,
67,
297,
283,
646,
747,
27,
870,
8891,
13993,
63,
5568,
3985,
315,
747,
14,
2314,
1105,
199,
18988,
63,
6909,
63,
13993,
63,
9984,
275,
3468,
8,
1739,
14,
1199,
9,
421,
199,
3,
2670,
340,
642,
4298,
883,
15376,
3734,
2860,
315,
1982,
10358,
14,
199,
3,
2136,
663,
376,
2589,
1750,
370,
282,
2222,
13,
1667,
1059,
12,
15376,
652,
12,
436,
12677,
199,
3,
282,
2366,
2884,
315,
282,
3873,
370,
870,
3775,
314,
1750,
199,
3,
365,
4825,
26594,
540,
315,
747,
14,
2314,
14,
199,
3,
2136,
675,
283,
2579,
7,
370,
2198,
314,
1982,
1159,
1072,
880,
626,
376,
1919,
199,
3,
365,
14031,
340,
314,
1324,
365,
15564,
283,
549,
7,
6590,
283,
797,
1370,
199,
736,
14,
2314,
459,
1734,
3597,
63,
5568,
418,
275,
283,
56,
7,
199,
2264,
747,
14,
2314,
459,
1734,
3597,
63,
5568,
418,
199,
1739,
275,
9088,
63,
396,
63,
1208,
14,
22299,
8,
272,
359,
1274,
14,
5904,
12,
2475,
67,
297,
283,
646,
747,
27,
870,
8891,
1734,
3597,
63,
5568,
3985,
440,
315,
747,
14,
2314,
1105,
199,
18988,
63,
1734,
3597,
63,
9984,
275,
3468,
8,
1739,
14,
1199,
9,
421,
199,
3,
13813,
340,
781,
1077,
511,
543,
376,
2701,
2457,
14,
961,
3181,
1133,
199,
3,
1852,
12249,
641,
10677,
626,
3913,
986,
2701,
2589,
2860,
334,
8886,
708,
9,
199,
3,
436,
641,
10677,
626,
3913,
15376,
2860,
334,
8585,
781,
3913,
11480,
199,
3,
314,
8865,
3382,
3087,
436,
5962,
1553,
699,
269,
9688,
436,
17991,
4663,
665,
959,
14,
709,
9,
199,
18988,
63,
2864,
63,
13993,
63,
9905,
275,
334,
18988,
63,
6909,
63,
13993,
63,
9984,
436,
29661,
63,
1734,
3597,
63,
9984,
9,
421,
199,
3,
710,
3734,
1750,
367,
9176,
314,
511,
4766,
14,
199,
9905,
63,
9984,
63,
5568,
275,
283,
16151,
63,
9905,
7,
199,
199,
3,
710,
3734,
2860,
367,
511,
11814,
316,
14,
199,
15386,
63,
11152,
3177,
63,
9984,
63,
5568,
275,
283,
16151,
63,
15386,
63,
11152,
3177,
7,
199,
3234,
7816,
63,
10215,
63,
9984,
63,
5568,
275,
283,
16151,
63,
3234,
7816,
63,
10215,
7,
199,
3234,
7816,
63,
6305,
63,
3817,
63,
9984,
63,
5568,
275,
283,
16151,
63,
3234,
7816,
63,
6305,
63,
3817,
7,
199,
199,
3,
710,
1414,
1004,
3305,
367,
9176,
314,
511,
4766,
14,
199,
9905,
63,
3719,
275,
283,
8385,
63,
1541,
7,
199,
199,
3,
710,
1414,
1004,
3305,
367,
5893,
6980,
2295,
14,
199,
748,
4118,
63,
9390,
63,
6178,
1217,
1149,
63,
7569,
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,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
iuliat/nova
|
nova/consoleauth/manager.py
|
58
|
5302
|
#!/usr/bin/env python
# Copyright (c) 2012 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.
"""Auth Components for Consoles."""
import time
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging as messaging
from oslo_serialization import jsonutils
from nova.cells import rpcapi as cells_rpcapi
from nova.compute import rpcapi as compute_rpcapi
from nova.i18n import _LI, _LW
from nova import manager
from nova import objects
from nova.openstack.common import memorycache
LOG = logging.getLogger(__name__)
consoleauth_opts = [
cfg.IntOpt('console_token_ttl',
default=600,
help='How many seconds before deleting tokens')
]
CONF = cfg.CONF
CONF.register_opts(consoleauth_opts)
CONF.import_opt('enable', 'nova.cells.opts', group='cells')
class ConsoleAuthManager(manager.Manager):
"""Manages token based authentication."""
target = messaging.Target(version='2.1')
def __init__(self, scheduler_driver=None, *args, **kwargs):
super(ConsoleAuthManager, self).__init__(service_name='consoleauth',
*args, **kwargs)
self.mc = memorycache.get_client()
self.compute_rpcapi = compute_rpcapi.ComputeAPI()
self.cells_rpcapi = cells_rpcapi.CellsAPI()
def _get_tokens_for_instance(self, instance_uuid):
tokens_str = self.mc.get(instance_uuid.encode('UTF-8'))
if not tokens_str:
tokens = []
else:
tokens = jsonutils.loads(tokens_str)
return tokens
def authorize_console(self, context, token, console_type, host, port,
internal_access_path, instance_uuid,
access_url=None):
token_dict = {'token': token,
'instance_uuid': instance_uuid,
'console_type': console_type,
'host': host,
'port': port,
'internal_access_path': internal_access_path,
'access_url': access_url,
'last_activity_at': time.time()}
data = jsonutils.dumps(token_dict)
# We need to log the warning message if the token is not cached
# successfully, because the failure will cause the console for
# instance to not be usable.
if not self.mc.set(token.encode('UTF-8'),
data, CONF.console_token_ttl):
LOG.warning(_LW("Token: %(token)s failed to save into memcached."),
{'token': token})
tokens = self._get_tokens_for_instance(instance_uuid)
# Remove the expired tokens from cache.
tokens = [tok for tok in tokens if self.mc.get(tok.encode('UTF-8'))]
tokens.append(token)
if not self.mc.set(instance_uuid.encode('UTF-8'),
jsonutils.dumps(tokens)):
LOG.warning(_LW("Instance: %(instance_uuid)s failed to save "
"into memcached"),
{'instance_uuid': instance_uuid})
LOG.info(_LI("Received Token: %(token)s, %(token_dict)s"),
{'token': token, 'token_dict': token_dict})
def _validate_token(self, context, token):
instance_uuid = token['instance_uuid']
if instance_uuid is None:
return False
# NOTE(comstud): consoleauth was meant to run in API cells. So,
# if cells is enabled, we must call down to the child cell for
# the instance.
if CONF.cells.enable:
return self.cells_rpcapi.validate_console_port(context,
instance_uuid, token['port'], token['console_type'])
instance = objects.Instance.get_by_uuid(context, instance_uuid)
return self.compute_rpcapi.validate_console_port(context,
instance,
token['port'],
token['console_type'])
def check_token(self, context, token):
token_str = self.mc.get(token.encode('UTF-8'))
token_valid = (token_str is not None)
LOG.info(_LI("Checking Token: %(token)s, %(token_valid)s"),
{'token': token, 'token_valid': token_valid})
if token_valid:
token = jsonutils.loads(token_str)
if self._validate_token(context, token):
return token
def delete_tokens_for_instance(self, context, instance_uuid):
tokens = self._get_tokens_for_instance(instance_uuid)
for token in tokens:
self.mc.delete(token.encode('UTF-8'))
self.mc.delete(instance_uuid.encode('UTF-8'))
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6029,
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,
199,
3,
259,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
259,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
263,
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,
199,
3,
259,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
259,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
259,
4204,
1334,
314,
844,
14,
199,
199,
624,
2817,
17823,
367,
1448,
1152,
2978,
1041,
199,
199,
646,
900,
199,
199,
504,
11258,
63,
888,
492,
4810,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
646,
11258,
63,
27782,
465,
30429,
199,
504,
11258,
63,
12161,
492,
18705,
199,
199,
504,
5913,
14,
9041,
492,
8985,
1246,
465,
10106,
63,
20776,
199,
504,
5913,
14,
3357,
492,
8985,
1246,
465,
4526,
63,
20776,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
2673,
12,
485,
20145,
199,
504,
5913,
492,
5256,
199,
504,
5913,
492,
2251,
199,
504,
5913,
14,
8512,
14,
2330,
492,
4402,
1637,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
6614,
1178,
63,
3291,
275,
359,
272,
4810,
14,
3241,
9985,
360,
6614,
63,
1418,
63,
12130,
297,
2049,
849,
29,
6683,
12,
2049,
1720,
534,
18335,
5002,
4696,
2544,
13794,
4645,
358,
272,
1622,
199,
199,
3103,
275,
4810,
14,
3103,
199,
3103,
14,
2683,
63,
3291,
8,
6614,
1178,
63,
3291,
9,
199,
3103,
14,
646,
63,
2992,
360,
4296,
297,
283,
6765,
14,
9041,
14,
3291,
297,
1572,
534,
9041,
358,
421,
199,
533,
19809,
2817,
2988,
8,
2609,
14,
2988,
304,
272,
408,
2395,
7441,
1526,
4079,
6299,
1041,
339,
1347,
275,
30429,
14,
4277,
8,
1023,
534,
18,
14,
17,
358,
339,
347,
636,
826,
721,
277,
12,
11899,
63,
3090,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
9270,
2817,
2988,
12,
291,
2843,
826,
721,
1364,
63,
354,
534,
6614,
1178,
297,
1740,
627,
589,
12,
1011,
958,
9,
267,
291,
14,
5466,
275,
4402,
1637,
14,
362,
63,
1258,
342,
267,
291,
14,
3357,
63,
20776,
275,
4526,
63,
20776,
14,
8564,
3735,
342,
267,
291,
14,
9041,
63,
20776,
275,
10106,
63,
20776,
14,
16852,
3735,
342,
339,
347,
485,
362,
63,
4504,
63,
509,
63,
842,
8,
277,
12,
1256,
63,
2580,
304,
267,
4645,
63,
495,
275,
291,
14,
5466,
14,
362,
8,
842,
63,
2580,
14,
2143,
360,
6610,
13,
24,
1333,
267,
340,
440,
4645,
63,
495,
26,
288,
4645,
275,
942,
267,
587,
26,
288,
4645,
275,
18705,
14,
3640,
8,
4504,
63,
495,
9,
267,
372,
4645,
339,
347,
20210,
63,
6614,
8,
277,
12,
1067,
12,
1526,
12,
8559,
63,
466,
12,
1591,
12,
1844,
12,
2079,
5007,
63,
2732,
63,
515,
12,
1256,
63,
2580,
12,
2079,
2879,
63,
633,
29,
403,
304,
398,
1526,
63,
807,
275,
791,
1418,
356,
1526,
12,
1993,
283,
842,
63,
2580,
356,
1256,
63,
2580,
12,
1993,
283,
6614,
63,
466,
356,
8559,
63,
466,
12,
1993,
283,
1102,
356,
1591,
12,
1993,
283,
719,
356,
1844,
12,
1993,
283,
4672,
63,
2732,
63,
515,
356,
5007,
63,
2732,
63,
515,
12,
1993,
283,
2732,
63,
633,
356,
2879,
63,
633,
12,
1993,
283,
2019,
63,
8240,
63,
292,
356,
900,
14,
521,
12737,
267,
666,
275,
18705,
14,
4180,
8,
1418,
63,
807,
9,
398,
327,
2136,
1929,
370,
943,
314,
5721,
1245,
340,
314,
1526,
365,
440,
6328,
267,
327,
8792,
12,
2952,
314,
5988,
911,
7675,
314,
8559,
367,
267,
327,
1256,
370,
440,
506,
18025,
14,
267,
340,
440,
291,
14,
5466,
14,
409,
8,
1418,
14,
2143,
360,
6610,
13,
24,
659,
2574,
666,
12,
6392,
14,
6614,
63,
1418,
63,
12130,
304,
288,
5051,
14,
3764,
1547,
20145,
480,
3264,
26,
2818,
1418,
9,
83,
3405,
370,
3354,
1901,
7573,
5245,
7651,
717,
791,
1418,
356,
1526,
1552,
267,
4645,
275,
291,
423,
362,
63,
4504,
63,
509,
63,
842,
8,
842,
63,
2580,
9,
398,
327,
5852,
314,
14721,
4645,
687,
2581,
14,
267,
4645,
275,
359,
9305,
367,
8431,
315,
4645,
340,
291,
14,
5466,
14,
362,
8,
9305,
14,
2143,
360,
6610,
13,
24,
27738,
267,
4645,
14,
740,
8,
1418,
9,
398,
340,
440,
291,
14,
5466,
14,
409,
8,
842,
63,
2580,
14,
2143,
360,
6610,
13,
24,
659,
2574,
18705,
14,
4180,
8,
4504,
2298,
288,
5051,
14,
3764,
1547,
20145,
480,
3244,
26,
2818,
842,
63,
2580,
9,
83,
3405,
370,
3354,
298,
1169,
298,
9924,
7573,
5245,
1288,
717,
791,
842,
63,
2580,
356,
1256,
63,
2580,
1552,
398,
5051,
14,
815,
1547,
2673,
480,
9392,
8767,
26,
2818,
1418,
9,
83,
12,
2818,
1418,
63,
807,
9,
83,
1288,
2116,
791,
1418,
356,
1526,
12,
283,
1418,
63,
807,
356,
1526,
63,
807,
1552,
339,
347,
485,
3502,
63,
1418,
8,
277,
12,
1067,
12,
1526,
304,
267,
1256,
63,
2580,
275,
1526,
459,
842,
63,
2580,
418,
267,
340,
1256,
63,
2580,
365,
488,
26,
288,
372,
756,
398,
327,
6944,
8,
957,
270,
1181,
304,
8559,
1178,
1990,
18329,
370,
1255,
315,
3261,
10106,
14,
221,
2002,
12,
267,
327,
340,
10106,
365,
5223,
12,
781,
1471,
1240,
3224,
370,
314,
1982,
4917,
367,
267,
327,
314,
1256,
14,
267,
340,
6392,
14,
9041,
14,
4296,
26,
288,
372,
291,
14,
9041,
63,
20776,
14,
3502,
63,
6614,
63,
719,
8,
1100,
12,
490,
1256,
63,
2580,
12,
1526,
459,
719,
995,
1526,
459,
6614,
63,
466,
1105,
398,
1256,
275,
2251,
14
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6029,
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,
199,
3,
259,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
259,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
263,
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,
199,
3,
259,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
259,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
259,
4204,
1334,
314,
844,
14,
199,
199,
624,
2817,
17823,
367,
1448,
1152,
2978,
1041,
199,
199,
646,
900,
199,
199,
504,
11258,
63,
888,
492,
4810,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
646,
11258,
63,
27782,
465,
30429,
199,
504,
11258,
63,
12161,
492,
18705,
199,
199,
504,
5913,
14,
9041,
492,
8985,
1246,
465,
10106,
63,
20776,
199,
504,
5913,
14,
3357,
492,
8985,
1246,
465,
4526,
63,
20776,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
2673,
12,
485,
20145,
199,
504,
5913,
492,
5256,
199,
504,
5913,
492,
2251,
199,
504,
5913,
14,
8512,
14,
2330,
492,
4402,
1637,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
6614,
1178,
63,
3291,
275,
359,
272,
4810,
14,
3241,
9985,
360,
6614,
63,
1418,
63,
12130,
297,
2049,
849,
29,
6683,
12,
2049,
1720,
534,
18335,
5002,
4696,
2544,
13794,
4645,
358,
272,
1622,
199,
199,
3103,
275,
4810,
14,
3103,
199,
3103,
14,
2683,
63,
3291,
8,
6614,
1178,
63,
3291,
9,
199,
3103,
14,
646,
63,
2992,
360,
4296,
297,
283,
6765,
14,
9041,
14,
3291,
297,
1572,
534,
9041,
358,
421,
199,
533,
19809,
2817,
2988,
8,
2609,
14,
2988,
304,
272,
408,
2395,
7441,
1526,
4079,
6299,
1041,
339,
1347,
275,
30429,
14,
4277,
8,
1023,
534,
18,
14,
17,
358,
339,
347,
636,
826,
721,
277,
12,
11899,
63,
3090,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
9270,
2817,
2988,
12,
291,
2843,
826,
721,
1364,
63,
354,
534,
6614,
1178,
297,
1740,
627,
589,
12,
1011,
958,
9,
267,
291,
14,
5466,
275,
4402,
1637,
14,
362,
63,
1258,
342,
267,
291,
14,
3357,
63,
20776,
275,
4526,
63,
20776,
14,
8564,
3735,
342,
267,
291,
14,
9041,
63,
20776,
275,
10106,
63,
20776,
14,
16852,
3735,
342,
339,
347,
485,
362,
63,
4504,
63,
509,
63,
842,
8,
277,
12,
1256,
63,
2580,
304,
267,
4645,
63,
495,
275,
291,
14,
5466,
14,
362,
8,
842,
63,
2580,
14,
2143,
360,
6610,
13,
24,
1333,
267,
340,
440,
4645,
63,
495,
26,
288,
4645,
275,
942,
267,
587,
26,
288,
4645,
275,
18705,
14,
3640,
8,
4504,
63,
495,
9,
267,
372,
4645,
339,
347,
20210,
63,
6614,
8,
277,
12,
1067,
12,
1526,
12,
8559,
63,
466,
12,
1591,
12,
1844,
12,
2079,
5007,
63,
2732,
63,
515,
12,
1256,
63,
2580,
12,
2079,
2879,
63,
633,
29,
403,
304,
398,
1526,
63,
807,
275,
791,
1418,
356,
1526,
12,
1993,
283,
842,
63,
2580,
356,
1256,
63,
2580,
12,
1993,
283,
6614,
63,
466,
356,
8559,
63,
466,
12,
1993,
283,
1102,
356,
1591,
12,
1993,
283,
719,
356,
1844,
12,
1993,
283,
4672,
63,
2732,
63,
515,
356,
5007,
63,
2732,
63,
515,
12,
1993,
283,
2732,
63,
633,
356,
2879,
63,
633,
12,
1993,
283,
2019,
63,
8240,
63,
292,
356,
900,
14,
521,
12737,
267,
666,
275,
18705,
14,
4180,
8,
1418,
63,
807,
9,
398,
327,
2136,
1929,
370,
943,
314,
5721,
1245,
340,
314,
1526,
365,
440,
6328,
267,
327,
8792,
12,
2952,
314,
5988,
911,
7675,
314,
8559,
367,
267,
327,
1256,
370,
440,
506,
18025,
14,
267,
340,
440,
291,
14,
5466,
14,
409,
8,
1418,
14,
2143,
360,
6610,
13,
24,
659,
2574,
666,
12,
6392,
14,
6614,
63,
1418,
63,
12130,
304,
288,
5051,
14,
3764,
1547,
20145,
480,
3264,
26,
2818,
1418,
9,
83,
3405,
370,
3354,
1901,
7573,
5245,
7651,
717,
791,
1418,
356,
1526,
1552,
267,
4645,
275,
291,
423,
362,
63,
4504,
63,
509,
63,
842,
8,
842,
63,
2580,
9,
398,
327,
5852,
314,
14721,
4645,
687,
2581,
14,
267,
4645,
275,
359,
9305,
367,
8431,
315,
4645,
340,
291,
14,
5466,
14,
362,
8,
9305,
14,
2143,
360,
6610,
13,
24,
27738,
267,
4645,
14,
740,
8,
1418,
9,
398,
340,
440,
291,
14,
5466,
14,
409,
8,
842,
63,
2580,
14,
2143,
360,
6610,
13,
24,
659,
2574,
18705,
14,
4180,
8,
4504,
2298,
288,
5051,
14,
3764,
1547,
20145,
480,
3244,
26,
2818,
842,
63,
2580,
9,
83,
3405,
370,
3354,
298,
1169,
298,
9924,
7573,
5245,
1288,
717,
791,
842,
63,
2580,
356,
1256,
63,
2580,
1552,
398,
5051,
14,
815,
1547,
2673,
480,
9392,
8767,
26,
2818,
1418,
9,
83,
12,
2818,
1418,
63,
807,
9,
83,
1288,
2116,
791,
1418,
356,
1526,
12,
283,
1418,
63,
807,
356,
1526,
63,
807,
1552,
339,
347,
485,
3502,
63,
1418,
8,
277,
12,
1067,
12,
1526,
304,
267,
1256,
63,
2580,
275,
1526,
459,
842,
63,
2580,
418,
267,
340,
1256,
63,
2580,
365,
488,
26,
288,
372,
756,
398,
327,
6944,
8,
957,
270,
1181,
304,
8559,
1178,
1990,
18329,
370,
1255,
315,
3261,
10106,
14,
221,
2002,
12,
267,
327,
340,
10106,
365,
5223,
12,
781,
1471,
1240,
3224,
370,
314,
1982,
4917,
367,
267,
327,
314,
1256,
14,
267,
340,
6392,
14,
9041,
14,
4296,
26,
288,
372,
291,
14,
9041,
63,
20776,
14,
3502,
63,
6614,
63,
719,
8,
1100,
12,
490,
1256,
63,
2580,
12,
1526,
459,
719,
995,
1526,
459,
6614,
63,
466,
1105,
398,
1256,
275,
2251,
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,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
kittiu/odoo
|
addons/auth_ldap/__init__.py
|
442
|
1049
|
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import users_ldap
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
199,
646,
4390,
63,
9642,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
199,
646,
4390,
63,
9642,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
csrocha/OpenUpgrade
|
addons/crm_helpdesk/report/crm_helpdesk_report.py
|
309
|
4633
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields,osv
from openerp import tools
AVAILABLE_STATES = [
('draft','Draft'),
('open','Open'),
('cancel', 'Cancelled'),
('done', 'Closed'),
('pending','Pending')
]
class crm_helpdesk_report(osv.osv):
""" Helpdesk report after Sales Services """
_name = "crm.helpdesk.report"
_description = "Helpdesk report after Sales Services"
_auto = False
_columns = {
'date': fields.datetime('Date', readonly=True),
'user_id':fields.many2one('res.users', 'User', readonly=True),
'section_id':fields.many2one('crm.case.section', 'Section', readonly=True),
'nbr': fields.integer('# of Requests', readonly=True), # TDE FIXME master: rename into nbr_requests
'state': fields.selection(AVAILABLE_STATES, 'Status', readonly=True),
'delay_close': fields.float('Delay to Close',digits=(16,2),readonly=True, group_operator="avg"),
'partner_id': fields.many2one('res.partner', 'Partner' , readonly=True),
'company_id': fields.many2one('res.company', 'Company', readonly=True),
'date_deadline': fields.date('Deadline', select=True),
'priority': fields.selection([('5', 'Lowest'), ('4', 'Low'), \
('3', 'Normal'), ('2', 'High'), ('1', 'Highest')], 'Priority'),
'channel_id': fields.many2one('crm.tracking.medium', 'Channel'),
'categ_id': fields.many2one('crm.case.categ', 'Category', \
domain="[('section_id','=',section_id),\
('object_id.model', '=', 'crm.helpdesk')]"),
'planned_cost': fields.float('Planned Costs'),
'create_date': fields.datetime('Creation Date' , readonly=True, select=True),
'date_closed': fields.datetime('Close Date', readonly=True, select=True),
'delay_expected': fields.float('Overpassed Deadline',digits=(16,2),readonly=True, group_operator="avg"),
'email': fields.integer('# Emails', size=128, readonly=True),
}
def init(self, cr):
"""
Display Deadline ,Responsible user, partner ,Department
@param cr: the current row, from the database cursor
"""
tools.drop_view_if_exists(cr, 'crm_helpdesk_report')
cr.execute("""
create or replace view crm_helpdesk_report as (
select
min(c.id) as id,
c.date as date,
c.create_date,
c.date_closed,
c.state,
c.user_id,
c.section_id,
c.partner_id,
c.company_id,
c.priority,
c.date_deadline,
c.categ_id,
c.channel_id,
c.planned_cost,
count(*) as nbr,
extract('epoch' from (c.date_closed-c.create_date))/(3600*24) as delay_close,
(SELECT count(id) FROM mail_message WHERE model='crm.helpdesk' AND res_id=c.id AND type = 'email') AS email,
abs(avg(extract('epoch' from (c.date_deadline - c.date_closed)))/(3600*24)) as delay_expected
from
crm_helpdesk c
where c.active = 'true'
group by c.date,\
c.state, c.user_id,c.section_id,c.priority,\
c.partner_id,c.company_id,c.date_deadline,c.create_date,c.date,c.date_closed,\
c.categ_id,c.channel_id,c.planned_cost,c.id
)""")
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
4795,
199,
504,
5166,
492,
7249,
421,
199,
17377,
63,
23162,
275,
359,
272,
661,
7185,
1673,
18332,
659,
272,
661,
1490,
1673,
4299,
659,
272,
661,
6406,
297,
283,
22127,
659,
272,
661,
4456,
297,
283,
15190,
659,
272,
661,
6455,
1673,
15960,
358,
199,
61,
199,
199,
533,
2467,
77,
63,
3437,
10368,
63,
3070,
8,
4795,
14,
4795,
304,
272,
408,
15456,
10368,
3622,
2410,
428,
7098,
21813,
408,
339,
485,
354,
275,
298,
15213,
14,
3437,
10368,
14,
3070,
2,
272,
485,
1802,
275,
298,
8673,
10368,
3622,
2410,
428,
7098,
21813,
2,
272,
485,
2495,
275,
756,
339,
485,
3406,
275,
469,
267,
283,
602,
356,
1504,
14,
2083,
360,
2506,
297,
6863,
29,
549,
395,
267,
283,
751,
63,
344,
356,
955,
14,
3479,
18,
368,
360,
470,
14,
3707,
297,
283,
1899,
297,
6863,
29,
549,
395,
267,
283,
2792,
63,
344,
356,
955,
14,
3479,
18,
368,
360,
15213,
14,
2546,
14,
2792,
297,
283,
8660,
297,
6863,
29,
549,
395,
267,
283,
23299,
356,
1504,
14,
4115,
7863,
402,
20260,
297,
6863,
29,
549,
395,
221,
327,
377,
1093,
7600,
5288,
26,
11441,
1901,
31646,
63,
6615,
267,
283,
929,
356,
1504,
14,
5592,
8,
17377,
63,
23162,
12,
283,
3694,
297,
6863,
29,
549,
395,
267,
283,
5814,
63,
1600,
356,
1504,
14,
1609,
360,
10796,
370,
15524,
297,
7022,
2687,
975,
12,
18,
395,
6753,
29,
549,
12,
1572,
63,
3856,
628,
8595,
1288,
267,
283,
3899,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
3899,
297,
283,
24120,
7,
2360,
6863,
29,
549,
395,
267,
283,
4627,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
4627,
297,
283,
16063,
297,
6863,
29,
549,
395,
267,
283,
602,
63,
22357,
356,
1504,
14,
602,
360,
22147,
604,
297,
3504,
29,
549,
395,
267,
283,
6693,
356,
1504,
14,
5592,
8318,
21,
297,
283,
10281,
597,
659,
661,
20,
297,
283,
10281,
659,
971,
490,
661,
19,
297,
283,
6241,
659,
661,
18,
297,
283,
11688,
659,
661,
17,
297,
283,
40,
12527,
2665,
283,
14354,
659,
267,
283,
2775,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
15213,
14,
14428,
14,
14345,
297,
283,
5358,
659,
267,
283,
3533,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
15213,
14,
2546,
14,
3533,
297,
283,
7841,
297,
971,
1169,
2881,
628,
19412,
2792,
63,
344,
18937,
2792,
63,
344,
26323,
1169,
661,
785,
63,
344,
14,
1238,
297,
6291,
283,
15213,
14,
3437,
10368,
5440,
1288,
267,
283,
20235,
63,
6336,
356,
1504,
14,
1609,
360,
3714,
9386,
24681,
83,
659,
267,
283,
981,
63,
602,
356,
1504,
14,
2083,
360,
13921,
6148,
7,
2360,
6863,
29,
549,
12,
3504,
29,
549,
395,
267,
283,
602,
63,
5938,
356,
1504,
14,
2083,
360,
4724,
6148,
297,
6863,
29,
549,
12,
3504,
29,
549,
395,
267,
283,
5814,
63,
2062,
356,
1504,
14,
1609,
360,
5674,
12070,
1487,
350,
604,
297,
7022,
2687,
975,
12,
18,
395,
6753,
29,
549,
12,
1572,
63,
3856,
628,
8595,
1288,
267,
283,
2123,
356,
1504,
14,
4115,
7863,
11426,
83,
297,
1568,
29,
3933,
12,
6863,
29,
549,
395,
272,
789,
339,
347,
4205,
8,
277,
12,
2467,
304,
398,
408,
288,
12175,
1487,
350,
604,
2360,
1322,
678,
1164,
922,
12,
5854,
2360,
872,
12493,
288,
768,
635,
2467,
26,
314,
1453,
1962,
12,
687,
314,
3050,
3920,
267,
408,
398,
7249,
14,
4824,
63,
1345,
63,
692,
63,
2444,
8,
1556,
12,
283,
15213,
63,
3437,
10368,
63,
3070,
358,
267,
2467,
14,
2526,
4852,
288,
1218,
503,
3350,
2455,
2467,
77,
63,
3437,
10368,
63,
3070,
465,
334,
355,
3504,
490,
1748,
8,
67,
14,
344,
9,
465,
1305,
12,
490,
286,
14,
602,
465,
1434,
12,
490,
286,
14,
981,
63,
602,
12,
490,
286,
14,
602,
63,
5938,
12,
490,
286,
14,
929,
12,
490,
286,
14,
751,
63,
344,
12,
490,
286,
14,
2792,
63,
344,
12,
490,
286,
14,
3899,
63,
344,
12,
490,
286,
14,
4627,
63,
344,
12,
490,
286,
14,
6693,
12,
490,
286,
14,
602,
63,
22357,
12,
490,
286,
14,
3533,
63,
344,
12,
490,
286,
14,
2775,
63,
344,
12,
490,
286,
14,
20235,
63,
6336,
12,
490,
2338,
21565,
465,
31646,
12,
490,
5536,
360,
7367,
7,
687,
334,
67,
14,
602,
63,
5938,
13,
67,
14,
981,
63,
602,
430,
7985,
11035,
10,
1194,
9,
465,
221,
7339,
63,
1600,
12,
490,
334,
4859,
2338,
8,
344,
9,
4442,
6016,
63,
1188,
6038,
1402,
534,
15213,
14,
3437,
10368,
7,
2401,
522,
63,
344,
29,
67,
14,
344,
2401,
730,
275,
283,
2123,
358,
4319,
3031,
12,
490,
2853,
8,
8595,
8,
5005,
360,
7367,
7,
687,
334,
67,
14,
602,
63,
22357,
446,
286,
14,
602,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
4795,
199,
504,
5166,
492,
7249,
421,
199,
17377,
63,
23162,
275,
359,
272,
661,
7185,
1673,
18332,
659,
272,
661,
1490,
1673,
4299,
659,
272,
661,
6406,
297,
283,
22127,
659,
272,
661,
4456,
297,
283,
15190,
659,
272,
661,
6455,
1673,
15960,
358,
199,
61,
199,
199,
533,
2467,
77,
63,
3437,
10368,
63,
3070,
8,
4795,
14,
4795,
304,
272,
408,
15456,
10368,
3622,
2410,
428,
7098,
21813,
408,
339,
485,
354,
275,
298,
15213,
14,
3437,
10368,
14,
3070,
2,
272,
485,
1802,
275,
298,
8673,
10368,
3622,
2410,
428,
7098,
21813,
2,
272,
485,
2495,
275,
756,
339,
485,
3406,
275,
469,
267,
283,
602,
356,
1504,
14,
2083,
360,
2506,
297,
6863,
29,
549,
395,
267,
283,
751,
63,
344,
356,
955,
14,
3479,
18,
368,
360,
470,
14,
3707,
297,
283,
1899,
297,
6863,
29,
549,
395,
267,
283,
2792,
63,
344,
356,
955,
14,
3479,
18,
368,
360,
15213,
14,
2546,
14,
2792,
297,
283,
8660,
297,
6863,
29,
549,
395,
267,
283,
23299,
356,
1504,
14,
4115,
7863,
402,
20260,
297,
6863,
29,
549,
395,
221,
327,
377,
1093,
7600,
5288,
26,
11441,
1901,
31646,
63,
6615,
267,
283,
929,
356,
1504,
14,
5592,
8,
17377,
63,
23162,
12,
283,
3694,
297,
6863,
29,
549,
395,
267,
283,
5814,
63,
1600,
356,
1504,
14,
1609,
360,
10796,
370,
15524,
297,
7022,
2687,
975,
12,
18,
395,
6753,
29,
549,
12,
1572,
63,
3856,
628,
8595,
1288,
267,
283,
3899,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
3899,
297,
283,
24120,
7,
2360,
6863,
29,
549,
395,
267,
283,
4627,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
4627,
297,
283,
16063,
297,
6863,
29,
549,
395,
267,
283,
602,
63,
22357,
356,
1504,
14,
602,
360,
22147,
604,
297,
3504,
29,
549,
395,
267,
283,
6693,
356,
1504,
14,
5592,
8318,
21,
297,
283,
10281,
597,
659,
661,
20,
297,
283,
10281,
659,
971,
490,
661,
19,
297,
283,
6241,
659,
661,
18,
297,
283,
11688,
659,
661,
17,
297,
283,
40,
12527,
2665,
283,
14354,
659,
267,
283,
2775,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
15213,
14,
14428,
14,
14345,
297,
283,
5358,
659,
267,
283,
3533,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
15213,
14,
2546,
14,
3533,
297,
283,
7841,
297,
971,
1169,
2881,
628,
19412,
2792,
63,
344,
18937,
2792,
63,
344,
26323,
1169,
661,
785,
63,
344,
14,
1238,
297,
6291,
283,
15213,
14,
3437,
10368,
5440,
1288,
267,
283,
20235,
63,
6336,
356,
1504,
14,
1609,
360,
3714,
9386,
24681,
83,
659,
267,
283,
981,
63,
602,
356,
1504,
14,
2083,
360,
13921,
6148,
7,
2360,
6863,
29,
549,
12,
3504,
29,
549,
395,
267,
283,
602,
63,
5938,
356,
1504,
14,
2083,
360,
4724,
6148,
297,
6863,
29,
549,
12,
3504,
29,
549,
395,
267,
283,
5814,
63,
2062,
356,
1504,
14,
1609,
360,
5674,
12070,
1487,
350,
604,
297,
7022,
2687,
975,
12,
18,
395,
6753,
29,
549,
12,
1572,
63,
3856,
628,
8595,
1288,
267,
283,
2123,
356,
1504,
14,
4115,
7863,
11426,
83,
297,
1568,
29,
3933,
12,
6863,
29,
549,
395,
272,
789,
339,
347,
4205,
8,
277,
12,
2467,
304,
398,
408,
288,
12175,
1487,
350,
604,
2360,
1322,
678,
1164,
922,
12,
5854,
2360,
872,
12493,
288,
768,
635,
2467,
26,
314,
1453,
1962,
12,
687,
314,
3050,
3920,
267,
408,
398,
7249,
14,
4824,
63,
1345,
63,
692,
63,
2444,
8,
1556,
12,
283,
15213,
63,
3437,
10368,
63,
3070,
358,
267,
2467,
14,
2526,
4852,
288,
1218,
503,
3350,
2455,
2467,
77,
63,
3437,
10368,
63,
3070,
465,
334,
355,
3504,
490,
1748,
8,
67,
14,
344,
9,
465,
1305,
12,
490,
286,
14,
602,
465,
1434,
12,
490,
286,
14,
981,
63,
602,
12,
490,
286,
14,
602,
63,
5938,
12,
490,
286,
14,
929,
12,
490,
286,
14,
751,
63,
344,
12,
490,
286,
14,
2792,
63,
344,
12,
490,
286,
14,
3899,
63,
344,
12,
490,
286,
14,
4627,
63,
344,
12,
490,
286,
14,
6693,
12,
490,
286,
14,
602,
63,
22357,
12,
490,
286,
14,
3533,
63,
344,
12,
490,
286,
14,
2775,
63,
344,
12,
490,
286,
14,
20235,
63,
6336,
12,
490,
2338,
21565,
465,
31646,
12,
490,
5536,
360,
7367,
7,
687,
334,
67,
14,
602,
63,
5938,
13,
67,
14,
981,
63,
602,
430,
7985,
11035,
10,
1194,
9,
465,
221,
7339,
63,
1600,
12,
490,
334,
4859,
2338,
8,
344,
9,
4442,
6016,
63,
1188,
6038,
1402,
534,
15213,
14,
3437,
10368,
7,
2401,
522,
63,
344,
29,
67,
14,
344,
2401,
730,
275,
283,
2123,
358,
4319,
3031,
12,
490,
2853,
8,
8595,
8,
5005,
360,
7367,
7,
687,
334,
67,
14,
602,
63,
22357,
446,
286,
14,
602,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
pombredanne/ghost-tree
|
ghosttree/silva/tests/test_filter.py
|
1
|
3455
|
# ----------------------------------------------------------------------------
# Copyright (c) 2015--, ghost-tree development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the LICENSE file, distributed with this software.
# ----------------------------------------------------------------------------
import unittest
from StringIO import StringIO
from skbio import BiologicalSequence
from ghosttree.silva.filter import fungi_from_fasta
class TestFungiFromFasta(unittest.TestCase):
def setUp(self):
self.fasta_no_fungi = StringIO(fasta_no_fungi)
self.fasta_with_fungi = StringIO(fasta_with_fungi)
self.fasta_many_fungi = StringIO(fasta_many_fungi)
self.accession = StringIO(accession)
self.accession_with_duplicates = StringIO(accession_with_duplicates)
self.taxonomy_no_fungi = StringIO(taxonomy_no_fungi)
self.taxonomy_with_fungi = StringIO(taxonomy_with_fungi)
self.taxonomy_with_duplicates = StringIO(taxonomy_with_duplicates)
def test_fasta_no_fungi(self):
result = fungi_from_fasta(self.fasta_no_fungi,
self.accession,
self.taxonomy_no_fungi)
self.assertEqual(list(result), [])
def test_fasta_with_fungi(self):
result = fungi_from_fasta(self.fasta_with_fungi,
self.accession,
self.taxonomy_with_fungi)
self.assertEqual(list(result),
[BiologicalSequence("ATCG", id="AB21",
description="Fungi")])
def test_fasta_with_many_fungi(self):
result = fungi_from_fasta(self.fasta_many_fungi,
self.accession,
self.taxonomy_with_fungi)
self.assertEqual(list(result), [
BiologicalSequence("GGGG", id="AB123", description="Fungi"),
BiologicalSequence("CCCC", id="AB125", description="Fungi"),
BiologicalSequence("AAAA", id="AB126", description="Fungi"),
])
def test_duplicate_accession_numbers(self):
with self.assertRaises(ValueError):
list(fungi_from_fasta(self.fasta_with_fungi,
self.accession_with_duplicates,
self.taxonomy_with_fungi))
def test_duplicate_map_numbers(self):
with self.assertRaises(ValueError):
list(fungi_from_fasta(self.fasta_with_fungi,
self.accession,
self.taxonomy_with_duplicates))
fasta_many_fungi = """>AB123 Fungi
GGGG
>AB124 Bacteria
TTTT
>AB125 Fungi
CCCC
>AB126 Fungi
AAAA
>AB100 Fungi
ATAC
"""
fasta_no_fungi = """>AB21 Bacteria
ATCG
"""
fasta_with_fungi = """>AB21 Fungi
ATCG
"""
taxonomy_with_fungi = """Fungi\t123\tgenus\t\t
Eukaryote;Fungi;Fungal Species\t456\tgenus\t\t
Fungi;Fungal species\t789\tgenus\t\t
Bacteria;bacterial species\t111\tgenus\t\t
Fungi;cladosporium\t100\tdomain\t\t
"""
taxonomy_no_fungi = "Bacteria\t123\tdomain\t\t"
taxonomy_with_duplicates = """Fungi\t123\tgenus\t\t
Fungi\t123\tgenus\t\t
Fungi\t122\tgenus\t\t
"""
accession = """AB21\t123
AB123\t456
AB124\t111
AB125\t789
AB126\t123
AB100\t100
"""
accession_with_duplicates = """AB21\t123
AC33\t456
AC33\t789
"""
if __name__ == "__main__":
unittest.main()
|
bsd-3-clause
|
[
3,
27103,
199,
3,
1898,
334,
67,
9,
6900,
306,
12,
486,
1102,
13,
2350,
16367,
8099,
14,
199,
3,
199,
3,
17484,
1334,
314,
2895,
402,
314,
22016,
6289,
844,
14,
199,
3,
199,
3,
710,
2615,
4190,
365,
315,
314,
5113,
570,
12,
1854,
543,
642,
2032,
14,
199,
3,
27103,
199,
646,
2882,
199,
504,
5228,
492,
5228,
199,
199,
504,
11448,
2308,
492,
699,
2308,
7954,
5826,
199,
199,
504,
486,
1102,
2350,
14,
20329,
3042,
14,
1541,
492,
9627,
6153,
63,
504,
63,
20309,
421,
199,
533,
1379,
19941,
6153,
2532,
1906,
1207,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
20309,
63,
889,
63,
7036,
6153,
275,
5228,
8,
20309,
63,
889,
63,
7036,
6153,
9,
267,
291,
14,
20309,
63,
1045,
63,
7036,
6153,
275,
5228,
8,
20309,
63,
1045,
63,
7036,
6153,
9,
267,
291,
14,
20309,
63,
3479,
63,
7036,
6153,
275,
5228,
8,
20309,
63,
3479,
63,
7036,
6153,
9,
267,
291,
14,
645,
823,
438,
275,
5228,
8,
645,
823,
438,
9,
267,
291,
14,
645,
823,
438,
63,
1045,
63,
18563,
275,
5228,
8,
645,
823,
438,
63,
1045,
63,
18563,
9,
267,
291,
14,
20243,
63,
889,
63,
7036,
6153,
275,
5228,
8,
20243,
63,
889,
63,
7036,
6153,
9,
267,
291,
14,
20243,
63,
1045,
63,
7036,
6153,
275,
5228,
8,
20243,
63,
1045,
63,
7036,
6153,
9,
267,
291,
14,
20243,
63,
1045,
63,
18563,
275,
5228,
8,
20243,
63,
1045,
63,
18563,
9,
339,
347,
511,
63,
20309,
63,
889,
63,
7036,
6153,
8,
277,
304,
267,
754,
275,
9627,
6153,
63,
504,
63,
20309,
8,
277,
14,
20309,
63,
889,
63,
7036,
6153,
12,
3303,
291,
14,
645,
823,
438,
12,
3303,
291,
14,
20243,
63,
889,
63,
7036,
6153,
9,
267,
291,
14,
629,
8,
513,
8,
1099,
395,
3073,
339,
347,
511,
63,
20309,
63,
1045,
63,
7036,
6153,
8,
277,
304,
267,
754,
275,
9627,
6153,
63,
504,
63,
20309,
8,
277,
14,
20309,
63,
1045,
63,
7036,
6153,
12,
3303,
291,
14,
645,
823,
438,
12,
3303,
291,
14,
20243,
63,
1045,
63,
7036,
6153,
9,
267,
291,
14,
629,
8,
513,
8,
1099,
395,
586,
359,
34,
2308,
7954,
5826,
480,
19859,
401,
1305,
628,
1217,
2025,
401,
6163,
1369,
628,
19941,
6153,
13403,
339,
347,
511,
63,
20309,
63,
1045,
63,
3479,
63,
7036,
6153,
8,
277,
304,
267,
754,
275,
9627,
6153,
63,
504,
63,
20309,
8,
277,
14,
20309,
63,
3479,
63,
7036,
6153,
12,
3303,
291,
14,
645,
823,
438,
12,
3303,
291,
14,
20243,
63,
1045,
63,
7036,
6153,
9,
267,
291,
14,
629,
8,
513,
8,
1099,
395,
359,
288,
699,
2308,
7954,
5826,
480,
2916,
2916,
401,
1305,
628,
1217,
4288,
401,
1369,
628,
19941,
6153,
1288,
288,
699,
2308,
7954,
5826,
480,
27994,
401,
1305,
628,
1217,
6889,
401,
1369,
628,
19941,
6153,
1288,
288,
699,
2308,
7954,
5826,
480,
6151,
401,
1305,
628,
1217,
7957,
401,
1369,
628,
19941,
6153,
1288,
267,
4794,
339,
347,
511,
63,
11081,
63,
645,
823,
438,
63,
10548,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
3393,
304,
288,
769,
8,
7036,
6153,
63,
504,
63,
20309,
8,
277,
14,
20309,
63,
1045,
63,
7036,
6153,
12,
3303,
291,
14,
645,
823,
438,
63,
1045,
63,
18563,
12,
3303,
291,
14,
20243,
63,
1045,
63,
7036,
6153,
430,
339,
347,
511,
63,
11081,
63,
1130,
63,
10548,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
3393,
304,
288,
769,
8,
7036,
6153,
63,
504,
63,
20309,
8,
277,
14,
20309,
63,
1045,
63,
7036,
6153,
12,
3303,
291,
14,
645,
823,
438,
12,
3303,
291,
14,
20243,
63,
1045,
63,
18563,
430,
421,
199,
20309,
63,
3479,
63,
7036,
6153,
275,
408,
30,
1217,
4288,
481,
324,
6153,
199,
2916,
2916,
199,
30,
1217,
7214,
699,
22265,
199,
21939,
199,
30,
1217,
6889,
481,
324,
6153,
199,
27994,
199,
30,
1217,
7957,
481,
324,
6153,
199,
6151,
199,
30,
1217,
1960,
481,
324,
6153,
199,
619,
1348,
199,
624,
199,
199,
20309,
63,
889,
63,
7036,
6153,
275,
408,
30,
1217,
2025,
699,
22265,
199,
19859,
199,
624,
199,
20309,
63,
1045,
63,
7036,
6153,
275,
408,
30,
1217,
2025,
481,
324,
6153,
199,
19859,
199,
624,
199,
20243,
63,
1045,
63,
7036,
6153,
275,
408,
19941,
6153,
60,
84,
4288,
60,
84,
2268,
527,
60,
84,
60,
84,
199,
37,
3210,
695,
1583,
27,
19941,
6153,
27,
38,
10335,
279,
5367,
397,
60,
84,
11419,
60,
84,
2268,
527,
60,
84,
60,
84,
199,
19941,
6153,
27,
38,
10335,
279,
20340,
60,
84,
24407,
60,
84,
2268,
527,
60,
84,
60,
84,
199,
23955,
27,
28150,
266,
1383,
20340,
60,
84,
6673,
60,
84,
2268,
527,
60,
84,
60,
84,
199,
19941,
6153,
27,
429,
5129,
681,
269,
5170,
60,
84,
1960,
60,
84,
2261,
60,
84,
60,
84,
199,
624,
199,
20243,
63,
889,
63,
7036,
6153,
275,
298,
23955,
60,
84,
4288,
60,
84,
2261,
60,
84,
60,
84,
2,
199,
20243,
63,
1045,
63,
18563,
275,
408,
19941,
6153,
60,
84,
4288,
60,
84,
2268,
527,
60,
84,
60,
84,
199,
19941,
6153,
60,
84,
4288,
60,
84,
2268,
527,
60,
84,
60,
84,
199,
19941,
6153,
60,
84,
7507,
60,
84,
2268,
527,
60,
84,
60,
84,
199,
624,
199,
645,
823,
438,
275,
408,
1217,
2025,
60,
84,
4288,
199,
1217,
4288,
60,
84,
11419,
199,
1217,
7214,
60,
84,
6673,
199,
1217,
6889,
60,
84,
24407,
199,
1217,
7957,
60,
84,
4288,
199,
1217,
1960,
60,
84,
1960,
199,
624,
199,
645,
823,
438,
63,
1045,
63,
18563,
275,
408,
1217,
2025,
60,
84,
4288,
199,
1348,
1153,
60,
84,
11419,
199,
1348,
1153,
60,
84,
24407,
199,
624,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
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
] |
[
27103,
199,
3,
1898,
334,
67,
9,
6900,
306,
12,
486,
1102,
13,
2350,
16367,
8099,
14,
199,
3,
199,
3,
17484,
1334,
314,
2895,
402,
314,
22016,
6289,
844,
14,
199,
3,
199,
3,
710,
2615,
4190,
365,
315,
314,
5113,
570,
12,
1854,
543,
642,
2032,
14,
199,
3,
27103,
199,
646,
2882,
199,
504,
5228,
492,
5228,
199,
199,
504,
11448,
2308,
492,
699,
2308,
7954,
5826,
199,
199,
504,
486,
1102,
2350,
14,
20329,
3042,
14,
1541,
492,
9627,
6153,
63,
504,
63,
20309,
421,
199,
533,
1379,
19941,
6153,
2532,
1906,
1207,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
20309,
63,
889,
63,
7036,
6153,
275,
5228,
8,
20309,
63,
889,
63,
7036,
6153,
9,
267,
291,
14,
20309,
63,
1045,
63,
7036,
6153,
275,
5228,
8,
20309,
63,
1045,
63,
7036,
6153,
9,
267,
291,
14,
20309,
63,
3479,
63,
7036,
6153,
275,
5228,
8,
20309,
63,
3479,
63,
7036,
6153,
9,
267,
291,
14,
645,
823,
438,
275,
5228,
8,
645,
823,
438,
9,
267,
291,
14,
645,
823,
438,
63,
1045,
63,
18563,
275,
5228,
8,
645,
823,
438,
63,
1045,
63,
18563,
9,
267,
291,
14,
20243,
63,
889,
63,
7036,
6153,
275,
5228,
8,
20243,
63,
889,
63,
7036,
6153,
9,
267,
291,
14,
20243,
63,
1045,
63,
7036,
6153,
275,
5228,
8,
20243,
63,
1045,
63,
7036,
6153,
9,
267,
291,
14,
20243,
63,
1045,
63,
18563,
275,
5228,
8,
20243,
63,
1045,
63,
18563,
9,
339,
347,
511,
63,
20309,
63,
889,
63,
7036,
6153,
8,
277,
304,
267,
754,
275,
9627,
6153,
63,
504,
63,
20309,
8,
277,
14,
20309,
63,
889,
63,
7036,
6153,
12,
3303,
291,
14,
645,
823,
438,
12,
3303,
291,
14,
20243,
63,
889,
63,
7036,
6153,
9,
267,
291,
14,
629,
8,
513,
8,
1099,
395,
3073,
339,
347,
511,
63,
20309,
63,
1045,
63,
7036,
6153,
8,
277,
304,
267,
754,
275,
9627,
6153,
63,
504,
63,
20309,
8,
277,
14,
20309,
63,
1045,
63,
7036,
6153,
12,
3303,
291,
14,
645,
823,
438,
12,
3303,
291,
14,
20243,
63,
1045,
63,
7036,
6153,
9,
267,
291,
14,
629,
8,
513,
8,
1099,
395,
586,
359,
34,
2308,
7954,
5826,
480,
19859,
401,
1305,
628,
1217,
2025,
401,
6163,
1369,
628,
19941,
6153,
13403,
339,
347,
511,
63,
20309,
63,
1045,
63,
3479,
63,
7036,
6153,
8,
277,
304,
267,
754,
275,
9627,
6153,
63,
504,
63,
20309,
8,
277,
14,
20309,
63,
3479,
63,
7036,
6153,
12,
3303,
291,
14,
645,
823,
438,
12,
3303,
291,
14,
20243,
63,
1045,
63,
7036,
6153,
9,
267,
291,
14,
629,
8,
513,
8,
1099,
395,
359,
288,
699,
2308,
7954,
5826,
480,
2916,
2916,
401,
1305,
628,
1217,
4288,
401,
1369,
628,
19941,
6153,
1288,
288,
699,
2308,
7954,
5826,
480,
27994,
401,
1305,
628,
1217,
6889,
401,
1369,
628,
19941,
6153,
1288,
288,
699,
2308,
7954,
5826,
480,
6151,
401,
1305,
628,
1217,
7957,
401,
1369,
628,
19941,
6153,
1288,
267,
4794,
339,
347,
511,
63,
11081,
63,
645,
823,
438,
63,
10548,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
3393,
304,
288,
769,
8,
7036,
6153,
63,
504,
63,
20309,
8,
277,
14,
20309,
63,
1045,
63,
7036,
6153,
12,
3303,
291,
14,
645,
823,
438,
63,
1045,
63,
18563,
12,
3303,
291,
14,
20243,
63,
1045,
63,
7036,
6153,
430,
339,
347,
511,
63,
11081,
63,
1130,
63,
10548,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
3393,
304,
288,
769,
8,
7036,
6153,
63,
504,
63,
20309,
8,
277,
14,
20309,
63,
1045,
63,
7036,
6153,
12,
3303,
291,
14,
645,
823,
438,
12,
3303,
291,
14,
20243,
63,
1045,
63,
18563,
430,
421,
199,
20309,
63,
3479,
63,
7036,
6153,
275,
408,
30,
1217,
4288,
481,
324,
6153,
199,
2916,
2916,
199,
30,
1217,
7214,
699,
22265,
199,
21939,
199,
30,
1217,
6889,
481,
324,
6153,
199,
27994,
199,
30,
1217,
7957,
481,
324,
6153,
199,
6151,
199,
30,
1217,
1960,
481,
324,
6153,
199,
619,
1348,
199,
624,
199,
199,
20309,
63,
889,
63,
7036,
6153,
275,
408,
30,
1217,
2025,
699,
22265,
199,
19859,
199,
624,
199,
20309,
63,
1045,
63,
7036,
6153,
275,
408,
30,
1217,
2025,
481,
324,
6153,
199,
19859,
199,
624,
199,
20243,
63,
1045,
63,
7036,
6153,
275,
408,
19941,
6153,
60,
84,
4288,
60,
84,
2268,
527,
60,
84,
60,
84,
199,
37,
3210,
695,
1583,
27,
19941,
6153,
27,
38,
10335,
279,
5367,
397,
60,
84,
11419,
60,
84,
2268,
527,
60,
84,
60,
84,
199,
19941,
6153,
27,
38,
10335,
279,
20340,
60,
84,
24407,
60,
84,
2268,
527,
60,
84,
60,
84,
199,
23955,
27,
28150,
266,
1383,
20340,
60,
84,
6673,
60,
84,
2268,
527,
60,
84,
60,
84,
199,
19941,
6153,
27,
429,
5129,
681,
269,
5170,
60,
84,
1960,
60,
84,
2261,
60,
84,
60,
84,
199,
624,
199,
20243,
63,
889,
63,
7036,
6153,
275,
298,
23955,
60,
84,
4288,
60,
84,
2261,
60,
84,
60,
84,
2,
199,
20243,
63,
1045,
63,
18563,
275,
408,
19941,
6153,
60,
84,
4288,
60,
84,
2268,
527,
60,
84,
60,
84,
199,
19941,
6153,
60,
84,
4288,
60,
84,
2268,
527,
60,
84,
60,
84,
199,
19941,
6153,
60,
84,
7507,
60,
84,
2268,
527,
60,
84,
60,
84,
199,
624,
199,
645,
823,
438,
275,
408,
1217,
2025,
60,
84,
4288,
199,
1217,
4288,
60,
84,
11419,
199,
1217,
7214,
60,
84,
6673,
199,
1217,
6889,
60,
84,
24407,
199,
1217,
7957,
60,
84,
4288,
199,
1217,
1960,
60,
84,
1960,
199,
624,
199,
645,
823,
438,
63,
1045,
63,
18563,
275,
408,
1217,
2025,
60,
84,
4288,
199,
1348,
1153,
60,
84,
11419,
199,
1348,
1153,
60,
84,
24407,
199,
624,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
199,
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
] |
mattvick/phantomjs
|
src/qt/qtwebkit/Source/WebCore/inspector/compile-front-end.py
|
116
|
15388
|
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os
import os.path
import generate_protocol_externs
import shutil
import sys
import tempfile
inspector_path = "Source/WebCore/inspector"
inspector_frontend_path = inspector_path + "/front-end"
protocol_externs_path = inspector_frontend_path + "/protocol-externs.js"
generate_protocol_externs.generate_protocol_externs(protocol_externs_path, inspector_path + "/Inspector.json")
jsmodule_name_prefix = "jsmodule_"
modules = [
{
"name": "common",
"dependencies": [],
"sources": [
"Color.js",
"DOMExtension.js",
"Object.js",
"ParsedURL.js",
"Progress.js",
"Settings.js",
"UIString.js",
"UserMetrics.js",
"utilities.js",
]
},
{
"name": "sdk",
"dependencies": ["common"],
"sources": [
"ApplicationCacheModel.js",
"CompilerScriptMapping.js",
"ConsoleModel.js",
"ContentProvider.js",
"ContentProviderBasedProjectDelegate.js",
"ContentProviders.js",
"CookieParser.js",
"CSSMetadata.js",
"CSSStyleModel.js",
"BreakpointManager.js",
"Database.js",
"DOMAgent.js",
"DOMStorage.js",
"DebuggerModel.js",
"DebuggerScriptMapping.js",
"FileManager.js",
"FileMapping.js",
"FileSystemMapping.js",
"FileSystemModel.js",
"FileSystemProjectDelegate.js",
"FileUtils.js",
"HAREntry.js",
"IndexedDBModel.js",
"InspectorBackend.js",
"IsolatedFileSystemManager.js",
"IsolatedFileSystem.js",
"Linkifier.js",
"NetworkLog.js",
"NetworkUISourceCodeProvider.js",
"PresentationConsoleMessageHelper.js",
"RuntimeModel.js",
"SASSSourceMapping.js",
"Script.js",
"ScriptFormatter.js",
"ScriptSnippetModel.js",
"SimpleWorkspaceProvider.js",
"SnippetStorage.js",
"SourceMapping.js",
"StylesSourceMapping.js",
"TimelineManager.js",
"RemoteObject.js",
"Resource.js",
"DefaultScriptMapping.js",
"ResourceScriptMapping.js",
"LiveEditSupport.js",
"ResourceTreeModel.js",
"ResourceType.js",
"ResourceUtils.js",
"SourceMap.js",
"NetworkManager.js",
"NetworkRequest.js",
"UISourceCode.js",
"UserAgentSupport.js",
"Workspace.js",
"protocol-externs.js",
]
},
{
"name": "ui",
"dependencies": ["common"],
"sources": [
"Checkbox.js",
"ContextMenu.js",
"DOMSyntaxHighlighter.js",
"DataGrid.js",
"DefaultTextEditor.js",
"Dialog.js",
"DockController.js",
"Drawer.js",
"EmptyView.js",
"GoToLineDialog.js",
"HelpScreen.js",
"InspectorView.js",
"KeyboardShortcut.js",
"OverviewGrid.js",
"Panel.js",
"PanelEnablerView.js",
"Placard.js",
"Popover.js",
"ProgressIndicator.js",
"PropertiesSection.js",
"SearchController.js",
"Section.js",
"SidebarPane.js",
"SidebarTreeElement.js",
"ShortcutsScreen.js",
"ShowMoreDataGridNode.js",
"SidebarOverlay.js",
"SoftContextMenu.js",
"SourceTokenizer.js",
"Spectrum.js",
"SplitView.js",
"SidebarView.js",
"StatusBarButton.js",
"SuggestBox.js",
"TabbedPane.js",
"TextEditor.js",
"TextEditorHighlighter.js",
"TextEditorModel.js",
"TextPrompt.js",
"TextUtils.js",
"TimelineGrid.js",
"Toolbar.js",
"UIUtils.js",
"View.js",
"ViewportControl.js",
"treeoutline.js",
]
},
{
"name": "components",
"dependencies": ["sdk", "ui"],
"sources": [
"AdvancedSearchController.js",
"HandlerRegistry.js",
"ConsoleMessage.js",
"CookiesTable.js",
"DOMBreakpointsSidebarPane.js",
"DOMPresentationUtils.js",
"ElementsTreeOutline.js",
"FontView.js",
"ImageView.js",
"NativeBreakpointsSidebarPane.js",
"InspectElementModeController.js",
"ObjectPopoverHelper.js",
"ObjectPropertiesSection.js",
"SourceFrame.js",
"ResourceView.js",
]
},
{
"name": "elements",
"dependencies": ["components"],
"sources": [
"CSSNamedFlowCollectionsView.js",
"CSSNamedFlowView.js",
"ElementsPanel.js",
"ElementsPanelDescriptor.js",
"EventListenersSidebarPane.js",
"MetricsSidebarPane.js",
"PropertiesSidebarPane.js",
"StylesSidebarPane.js",
]
},
{
"name": "network",
"dependencies": ["components"],
"sources": [
"NetworkItemView.js",
"RequestCookiesView.js",
"RequestHeadersView.js",
"RequestHTMLView.js",
"RequestJSONView.js",
"RequestPreviewView.js",
"RequestResponseView.js",
"RequestTimingView.js",
"RequestView.js",
"ResourceWebSocketFrameView.js",
"NetworkPanel.js",
"NetworkPanelDescriptor.js",
]
},
{
"name": "resources",
"dependencies": ["components"],
"sources": [
"ApplicationCacheItemsView.js",
"CookieItemsView.js",
"DatabaseQueryView.js",
"DatabaseTableView.js",
"DirectoryContentView.js",
"DOMStorageItemsView.js",
"FileContentView.js",
"FileSystemView.js",
"IndexedDBViews.js",
"ResourcesPanel.js",
]
},
{
"name": "workers",
"dependencies": ["components"],
"sources": [
"WorkerManager.js",
]
},
{
"name": "scripts",
"dependencies": ["components", "workers"],
"sources": [
"BreakpointsSidebarPane.js",
"CallStackSidebarPane.js",
"FilteredItemSelectionDialog.js",
"JavaScriptSourceFrame.js",
"NavigatorOverlayController.js",
"NavigatorView.js",
"RevisionHistoryView.js",
"ScopeChainSidebarPane.js",
"ScriptsNavigator.js",
"ScriptsPanel.js",
"ScriptsPanelDescriptor.js",
"ScriptsSearchScope.js",
"SnippetJavaScriptSourceFrame.js",
"StyleSheetOutlineDialog.js",
"TabbedEditorContainer.js",
"UISourceCodeFrame.js",
"WatchExpressionsSidebarPane.js",
"WorkersSidebarPane.js",
]
},
{
"name": "console",
"dependencies": ["components"],
"sources": [
"ConsoleView.js",
"ConsolePanel.js",
]
},
{
"name": "timeline",
"dependencies": ["components"],
"sources": [
"DOMCountersGraph.js",
"MemoryStatistics.js",
"NativeMemoryGraph.js",
"TimelineModel.js",
"TimelineOverviewPane.js",
"TimelinePanel.js",
"TimelinePanelDescriptor.js",
"TimelinePresentationModel.js",
"TimelineFrameController.js"
]
},
{
"name": "audits",
"dependencies": ["components"],
"sources": [
"AuditCategories.js",
"AuditController.js",
"AuditFormatters.js",
"AuditLauncherView.js",
"AuditResultView.js",
"AuditRules.js",
"AuditsPanel.js",
]
},
{
"name": "extensions",
"dependencies": ["components"],
"sources": [
"ExtensionAPI.js",
"ExtensionAuditCategory.js",
"ExtensionPanel.js",
"ExtensionRegistryStub.js",
"ExtensionServer.js",
"ExtensionView.js",
]
},
{
"name": "settings",
"dependencies": ["components", "extensions"],
"sources": [
"SettingsScreen.js",
"OverridesView.js",
]
},
{
"name": "tests",
"dependencies": ["components"],
"sources": [
"TestController.js",
]
},
{
"name": "profiler",
"dependencies": ["components", "workers"],
"sources": [
"BottomUpProfileDataGridTree.js",
"CPUProfileView.js",
"CSSSelectorProfileView.js",
"FlameChart.js",
"HeapSnapshot.js",
"HeapSnapshotDataGrids.js",
"HeapSnapshotGridNodes.js",
"HeapSnapshotLoader.js",
"HeapSnapshotProxy.js",
"HeapSnapshotView.js",
"HeapSnapshotWorker.js",
"HeapSnapshotWorkerDispatcher.js",
"JSHeapSnapshot.js",
"NativeHeapSnapshot.js",
"ProfileDataGridTree.js",
"ProfilesPanel.js",
"ProfilesPanelDescriptor.js",
"ProfileLauncherView.js",
"TopDownProfileDataGridTree.js",
"CanvasProfileView.js",
]
},
{
"name": "host_stub",
"dependencies": ["components", "profiler", "timeline"],
"sources": [
"InspectorFrontendAPI.js",
"InspectorFrontendHostStub.js",
]
}
]
modules_by_name = {}
for module in modules:
modules_by_name[module["name"]] = module
def dump_module(name, recursively, processed_modules):
if name in processed_modules:
return ""
processed_modules[name] = True
module = modules_by_name[name]
command = ""
if recursively:
for dependency in module["dependencies"]:
command += dump_module(dependency, recursively, processed_modules)
command += " \\\n --module " + jsmodule_name_prefix + module["name"] + ":"
command += str(len(module["sources"]))
firstDependency = True
for dependency in module["dependencies"]:
if firstDependency:
command += ":"
else:
command += ","
firstDependency = False
command += jsmodule_name_prefix + dependency
for script in module["sources"]:
command += " \\\n --js " + inspector_frontend_path + "/" + script
return command
modules_dir = tempfile.mkdtemp()
compiler_command = "java -jar ~/closure/compiler.jar --summary_detail_level 3 --compilation_level SIMPLE_OPTIMIZATIONS --warning_level VERBOSE --language_in ECMASCRIPT5 --accept_const_keyword --module_output_path_prefix %s/ \\\n" % modules_dir
process_recursively = len(sys.argv) > 1
if process_recursively:
module_name = sys.argv[1]
if module_name != "all":
modules = []
for i in range(1, len(sys.argv)):
modules.append(modules_by_name[sys.argv[i]])
for module in modules:
command = compiler_command
command += " --externs " + inspector_frontend_path + "/externs.js"
command += dump_module(module["name"], True, {})
print "Compiling \"" + module["name"] + "\""
os.system(command)
else:
command = compiler_command
command += " --externs " + inspector_frontend_path + "/externs.js"
for module in modules:
command += dump_module(module["name"], False, {})
os.system(command)
if not process_recursively:
print "Compiling InjectedScriptSource.js..."
os.system("echo \"var injectedScriptValue = \" > " + inspector_path + "/" + "InjectedScriptSourceTmp.js")
os.system("cat " + inspector_path + "/" + "InjectedScriptSource.js" + " >> " + inspector_path + "/" + "InjectedScriptSourceTmp.js")
command = compiler_command
command += " --externs " + inspector_path + "/" + "InjectedScriptExterns.js" + " \\\n"
command += " --externs " + protocol_externs_path + " \\\n"
command += " --module " + jsmodule_name_prefix + "injected_script" + ":" + "1" + " \\\n"
command += " --js " + inspector_path + "/" + "InjectedScriptSourceTmp.js" + " \\\n"
command += "\n"
os.system(command)
os.system("rm " + inspector_path + "/" + "InjectedScriptSourceTmp.js")
print "Compiling InjectedScriptCanvasModuleSource.js..."
os.system("echo \"var injectedScriptCanvasModuleValue = \" > " + inspector_path + "/" + "InjectedScriptCanvasModuleSourceTmp.js")
os.system("cat " + inspector_path + "/" + "InjectedScriptCanvasModuleSource.js" + " >> " + inspector_path + "/" + "InjectedScriptCanvasModuleSourceTmp.js")
command = compiler_command
command += " --externs " + inspector_path + "/" + "InjectedScriptExterns.js" + " \\\n"
command += " --externs " + protocol_externs_path + " \\\n"
command += " --module " + jsmodule_name_prefix + "injected_script" + ":" + "1" + " \\\n"
command += " --js " + inspector_path + "/" + "InjectedScriptCanvasModuleSourceTmp.js" + " \\\n"
command += "\n"
os.system(command)
os.system("rm " + inspector_path + "/" + "InjectedScriptCanvasModuleSourceTmp.js")
shutil.rmtree(modules_dir)
#os.system("rm " + protocol_externs_path)
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6029,
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,
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,
646,
747,
199,
646,
747,
14,
515,
199,
646,
3550,
63,
3922,
63,
476,
351,
561,
199,
646,
5145,
199,
646,
984,
199,
646,
5549,
199,
199,
26047,
63,
515,
275,
298,
2980,
15,
5926,
5402,
15,
26047,
2,
199,
26047,
63,
18062,
63,
515,
275,
5261,
15152,
63,
515,
435,
3286,
14708,
13,
500,
2,
199,
3922,
63,
476,
351,
561,
63,
515,
275,
5261,
15152,
63,
18062,
63,
515,
435,
3286,
3922,
13,
476,
351,
561,
14,
3596,
2,
199,
199,
4208,
63,
3922,
63,
476,
351,
561,
14,
4208,
63,
3922,
63,
476,
351,
561,
8,
3922,
63,
476,
351,
561,
63,
515,
12,
5261,
15152,
63,
515,
435,
3286,
13962,
15152,
14,
1001,
531,
199,
199,
3596,
578,
63,
354,
63,
1861,
275,
298,
3596,
578,
12172,
199,
3112,
275,
359,
272,
469,
267,
298,
354,
582,
298,
2330,
401,
267,
298,
5714,
582,
990,
267,
298,
4553,
582,
359,
288,
298,
4117,
14,
3596,
401,
288,
298,
10462,
6382,
14,
3596,
401,
288,
298,
1692,
14,
3596,
401,
288,
298,
1262,
939,
2632,
14,
3596,
401,
288,
298,
11504,
14,
3596,
401,
288,
298,
5268,
14,
3596,
401,
288,
298,
53,
1311,
1232,
14,
3596,
401,
288,
298,
1899,
17213,
14,
3596,
401,
288,
298,
16355,
14,
3596,
401,
267,
1622,
272,
1660,
272,
469,
267,
298,
354,
582,
298,
9277,
401,
267,
298,
5714,
582,
2097,
2330,
2255,
267,
298,
4553,
582,
359,
288,
298,
5039,
4437,
1685,
14,
3596,
401,
288,
298,
9131,
5229,
7674,
14,
3596,
401,
288,
298,
9270,
1685,
14,
3596,
401,
288,
298,
2714,
6663,
14,
3596,
401,
288,
298,
2714,
6663,
20409,
4761,
21553,
14,
3596,
401,
288,
298,
2714,
6663,
83,
14,
3596,
401,
288,
298,
7810,
2842,
14,
3596,
401,
288,
298,
14391,
5142,
14,
3596,
401,
288,
298,
14391,
6609,
1685,
14,
3596,
401,
288,
298,
28944,
2988,
14,
3596,
401,
288,
298,
7243,
14,
3596,
401,
288,
298,
1649,
2054,
12069,
14,
3596,
401,
288,
298,
10462,
6408,
14,
3596,
401,
288,
298,
31521,
1685,
14,
3596,
401,
288,
298,
31521,
5229,
7674,
14,
3596,
401,
288,
298,
1173,
2988,
14,
3596,
401,
288,
298,
1173,
7674,
14,
3596,
401,
288,
298,
17521,
7674,
14,
3596,
401,
288,
298,
17521,
1685,
14,
3596,
401,
288,
298,
17521,
4761,
21553,
14,
3596,
401,
288,
298,
1173,
7535,
14,
3596,
401,
288,
298,
30958,
3900,
14,
3596,
401,
288,
298,
19067,
2846,
1685,
14,
3596,
401,
288,
298,
13962,
15152,
8447,
14,
3596,
401,
288,
298,
1831,
12918,
17521,
2988,
14,
3596,
401,
288,
298,
1831,
12918,
17521,
14,
3596,
401,
288,
298,
3834,
9893,
14,
3596,
401,
288,
298,
4491,
2445,
14,
3596,
401,
288,
298,
4491,
53,
1311,
616,
3034,
6663,
14,
3596,
401,
288,
298,
19794,
425,
9270,
2209,
4433,
14,
3596,
401,
288,
298,
14357,
1685,
14,
3596,
401,
288,
298,
15319,
2300,
616,
7674,
14,
3596,
401,
288,
298,
5229,
14,
3596,
401,
288,
298,
5229,
7772,
14,
3596,
401,
288,
298,
5229,
20821,
11088,
1685,
14,
3596,
401,
288,
298,
3184,
21058,
6663,
14,
3596,
401,
288,
298,
20821,
11088,
6408,
14,
3596,
401,
288,
298,
2980,
7674,
14,
3596,
401,
288,
298,
30349,
2980,
7674,
14,
3596,
401,
288,
298,
27097,
2988,
14,
3596,
401,
288,
298,
6713,
1692,
14,
3596,
401,
288,
298,
4031,
14,
3596,
401,
288,
298,
2698,
5229,
7674,
14,
3596,
401,
288,
298,
4031,
5229,
7674,
14,
3596,
401,
288,
298,
17458,
4685,
11532,
14,
3596,
401,
288,
298,
4031,
3987,
1685,
14,
3596,
401,
288,
298,
4031,
804,
14,
3596,
401,
288,
298,
4031,
7535,
14,
3596,
401,
288,
298,
2980,
2956,
14,
3596,
401,
288,
298,
4491,
2988,
14,
3596,
401,
288,
298,
4491,
2017,
14,
3596,
401,
288,
298,
53,
1311,
616,
3034,
14,
3596,
401,
288,
298,
1899,
7788,
11532,
14,
3596,
401,
288,
298,
21058,
14,
3596,
401,
288,
298,
3922,
13,
476,
351,
561,
14,
3596,
401,
267,
1622,
272,
1660,
272,
469,
267,
298,
354,
582,
298,
1907,
401,
267,
298,
5714,
582,
2097,
2330,
2255,
267,
298,
4553,
582,
359,
288,
298,
26366,
14,
3596,
401,
288,
298,
2998,
5977
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6029,
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,
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,
646,
747,
199,
646,
747,
14,
515,
199,
646,
3550,
63,
3922,
63,
476,
351,
561,
199,
646,
5145,
199,
646,
984,
199,
646,
5549,
199,
199,
26047,
63,
515,
275,
298,
2980,
15,
5926,
5402,
15,
26047,
2,
199,
26047,
63,
18062,
63,
515,
275,
5261,
15152,
63,
515,
435,
3286,
14708,
13,
500,
2,
199,
3922,
63,
476,
351,
561,
63,
515,
275,
5261,
15152,
63,
18062,
63,
515,
435,
3286,
3922,
13,
476,
351,
561,
14,
3596,
2,
199,
199,
4208,
63,
3922,
63,
476,
351,
561,
14,
4208,
63,
3922,
63,
476,
351,
561,
8,
3922,
63,
476,
351,
561,
63,
515,
12,
5261,
15152,
63,
515,
435,
3286,
13962,
15152,
14,
1001,
531,
199,
199,
3596,
578,
63,
354,
63,
1861,
275,
298,
3596,
578,
12172,
199,
3112,
275,
359,
272,
469,
267,
298,
354,
582,
298,
2330,
401,
267,
298,
5714,
582,
990,
267,
298,
4553,
582,
359,
288,
298,
4117,
14,
3596,
401,
288,
298,
10462,
6382,
14,
3596,
401,
288,
298,
1692,
14,
3596,
401,
288,
298,
1262,
939,
2632,
14,
3596,
401,
288,
298,
11504,
14,
3596,
401,
288,
298,
5268,
14,
3596,
401,
288,
298,
53,
1311,
1232,
14,
3596,
401,
288,
298,
1899,
17213,
14,
3596,
401,
288,
298,
16355,
14,
3596,
401,
267,
1622,
272,
1660,
272,
469,
267,
298,
354,
582,
298,
9277,
401,
267,
298,
5714,
582,
2097,
2330,
2255,
267,
298,
4553,
582,
359,
288,
298,
5039,
4437,
1685,
14,
3596,
401,
288,
298,
9131,
5229,
7674,
14,
3596,
401,
288,
298,
9270,
1685,
14,
3596,
401,
288,
298,
2714,
6663,
14,
3596,
401,
288,
298,
2714,
6663,
20409,
4761,
21553,
14,
3596,
401,
288,
298,
2714,
6663,
83,
14,
3596,
401,
288,
298,
7810,
2842,
14,
3596,
401,
288,
298,
14391,
5142,
14,
3596,
401,
288,
298,
14391,
6609,
1685,
14,
3596,
401,
288,
298,
28944,
2988,
14,
3596,
401,
288,
298,
7243,
14,
3596,
401,
288,
298,
1649,
2054,
12069,
14,
3596,
401,
288,
298,
10462,
6408,
14,
3596,
401,
288,
298,
31521,
1685,
14,
3596,
401,
288,
298,
31521,
5229,
7674,
14,
3596,
401,
288,
298,
1173,
2988,
14,
3596,
401,
288,
298,
1173,
7674,
14,
3596,
401,
288,
298,
17521,
7674,
14,
3596,
401,
288,
298,
17521,
1685,
14,
3596,
401,
288,
298,
17521,
4761,
21553,
14,
3596,
401,
288,
298,
1173,
7535,
14,
3596,
401,
288,
298,
30958,
3900,
14,
3596,
401,
288,
298,
19067,
2846,
1685,
14,
3596,
401,
288,
298,
13962,
15152,
8447,
14,
3596,
401,
288,
298,
1831,
12918,
17521,
2988,
14,
3596,
401,
288,
298,
1831,
12918,
17521,
14,
3596,
401,
288,
298,
3834,
9893,
14,
3596,
401,
288,
298,
4491,
2445,
14,
3596,
401,
288,
298,
4491,
53,
1311,
616,
3034,
6663,
14,
3596,
401,
288,
298,
19794,
425,
9270,
2209,
4433,
14,
3596,
401,
288,
298,
14357,
1685,
14,
3596,
401,
288,
298,
15319,
2300,
616,
7674,
14,
3596,
401,
288,
298,
5229,
14,
3596,
401,
288,
298,
5229,
7772,
14,
3596,
401,
288,
298,
5229,
20821,
11088,
1685,
14,
3596,
401,
288,
298,
3184,
21058,
6663,
14,
3596,
401,
288,
298,
20821,
11088,
6408,
14,
3596,
401,
288,
298,
2980,
7674,
14,
3596,
401,
288,
298,
30349,
2980,
7674,
14,
3596,
401,
288,
298,
27097,
2988,
14,
3596,
401,
288,
298,
6713,
1692,
14,
3596,
401,
288,
298,
4031,
14,
3596,
401,
288,
298,
2698,
5229,
7674,
14,
3596,
401,
288,
298,
4031,
5229,
7674,
14,
3596,
401,
288,
298,
17458,
4685,
11532,
14,
3596,
401,
288,
298,
4031,
3987,
1685,
14,
3596,
401,
288,
298,
4031,
804,
14,
3596,
401,
288,
298,
4031,
7535,
14,
3596,
401,
288,
298,
2980,
2956,
14,
3596,
401,
288,
298,
4491,
2988,
14,
3596,
401,
288,
298,
4491,
2017,
14,
3596,
401,
288,
298,
53,
1311,
616,
3034,
14,
3596,
401,
288,
298,
1899,
7788,
11532,
14,
3596,
401,
288,
298,
21058,
14,
3596,
401,
288,
298,
3922,
13,
476,
351,
561,
14,
3596,
401,
267,
1622,
272,
1660,
272,
469,
267,
298,
354,
582,
298,
1907,
401,
267,
298,
5714,
582,
2097,
2330,
2255,
267,
298,
4553,
582,
359,
288,
298,
26366,
14,
3596,
401,
288,
298,
2998,
5977,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sserrot/champion_relationships
|
venv/Lib/site-packages/setuptools/_distutils/command/check.py
|
28
|
5637
|
"""distutils.command.check
Implements the Distutils 'check' command.
"""
from distutils.core import Command
from distutils.errors import DistutilsSetupError
try:
# docutils is installed
from docutils.utils import Reporter
from docutils.parsers.rst import Parser
from docutils import frontend
from docutils import nodes
class SilentReporter(Reporter):
def __init__(self, source, report_level, halt_level, stream=None,
debug=0, encoding='ascii', error_handler='replace'):
self.messages = []
Reporter.__init__(self, source, report_level, halt_level, stream,
debug, encoding, error_handler)
def system_message(self, level, message, *children, **kwargs):
self.messages.append((level, message, children, kwargs))
return nodes.system_message(message, level=level,
type=self.levels[level],
*children, **kwargs)
HAS_DOCUTILS = True
except Exception:
# Catch all exceptions because exceptions besides ImportError probably
# indicate that docutils is not ported to Py3k.
HAS_DOCUTILS = False
class check(Command):
"""This command checks the meta-data of the package.
"""
description = ("perform some checks on the package")
user_options = [('metadata', 'm', 'Verify meta-data'),
('restructuredtext', 'r',
('Checks if long string meta-data syntax '
'are reStructuredText-compliant')),
('strict', 's',
'Will exit with an error if a check fails')]
boolean_options = ['metadata', 'restructuredtext', 'strict']
def initialize_options(self):
"""Sets default values for options."""
self.restructuredtext = 0
self.metadata = 1
self.strict = 0
self._warnings = 0
def finalize_options(self):
pass
def warn(self, msg):
"""Counts the number of warnings that occurs."""
self._warnings += 1
return Command.warn(self, msg)
def run(self):
"""Runs the command."""
# perform the various tests
if self.metadata:
self.check_metadata()
if self.restructuredtext:
if HAS_DOCUTILS:
self.check_restructuredtext()
elif self.strict:
raise DistutilsSetupError('The docutils package is needed.')
# let's raise an error in strict mode, if we have at least
# one warning
if self.strict and self._warnings > 0:
raise DistutilsSetupError('Please correct your package.')
def check_metadata(self):
"""Ensures that all required elements of meta-data are supplied.
Required fields:
name, version, URL
Recommended fields:
(author and author_email) or (maintainer and maintainer_email))
Warns if any are missing.
"""
metadata = self.distribution.metadata
missing = []
for attr in ('name', 'version', 'url'):
if not (hasattr(metadata, attr) and getattr(metadata, attr)):
missing.append(attr)
if missing:
self.warn("missing required meta-data: %s" % ', '.join(missing))
if metadata.author:
if not metadata.author_email:
self.warn("missing meta-data: if 'author' supplied, " +
"'author_email' should be supplied too")
elif metadata.maintainer:
if not metadata.maintainer_email:
self.warn("missing meta-data: if 'maintainer' supplied, " +
"'maintainer_email' should be supplied too")
else:
self.warn("missing meta-data: either (author and author_email) " +
"or (maintainer and maintainer_email) " +
"should be supplied")
def check_restructuredtext(self):
"""Checks if the long string fields are reST-compliant."""
data = self.distribution.get_long_description()
for warning in self._check_rst_data(data):
line = warning[-1].get('line')
if line is None:
warning = warning[1]
else:
warning = '%s (line %s)' % (warning[1], line)
self.warn(warning)
def _check_rst_data(self, data):
"""Returns warnings when the provided data doesn't compile."""
# the include and csv_table directives need this to be a path
source_path = self.distribution.script_name or 'setup.py'
parser = Parser()
settings = frontend.OptionParser(components=(Parser,)).get_default_values()
settings.tab_width = 4
settings.pep_references = None
settings.rfc_references = None
reporter = SilentReporter(source_path,
settings.report_level,
settings.halt_level,
stream=settings.warning_stream,
debug=settings.debug,
encoding=settings.error_encoding,
error_handler=settings.error_encoding_error_handler)
document = nodes.document(settings, reporter, source=source_path)
document.note_source(source_path, -1)
try:
parser.parse(data, document)
except AttributeError as e:
reporter.messages.append(
(-1, 'Could not finish the parsing: %s.' % e, '', {}))
return reporter.messages
|
mit
|
[
624,
13350,
14,
1531,
14,
1074,
199,
199,
29452,
314,
12577,
283,
1074,
7,
1414,
14,
199,
624,
199,
504,
7065,
14,
1018,
492,
5817,
199,
504,
7065,
14,
2550,
492,
12577,
30221,
199,
199,
893,
26,
272,
327,
18382,
365,
4903,
272,
687,
18382,
14,
1208,
492,
23786,
272,
687,
18382,
14,
11531,
14,
8332,
492,
10191,
272,
687,
18382,
492,
22523,
272,
687,
18382,
492,
3380,
339,
1021,
428,
441,
343,
15891,
8,
15891,
304,
398,
347,
636,
826,
721,
277,
12,
1350,
12,
3622,
63,
1896,
12,
394,
4478,
63,
1896,
12,
2547,
29,
403,
12,
2151,
3105,
29,
16,
12,
2644,
534,
4371,
297,
1125,
63,
2232,
534,
1814,
735,
288,
291,
14,
3431,
275,
942,
288,
23786,
855,
826,
721,
277,
12,
1350,
12,
3622,
63,
1896,
12,
394,
4478,
63,
1896,
12,
2547,
12,
2892,
3105,
12,
2644,
12,
1125,
63,
2232,
9,
398,
347,
2656,
63,
1188,
8,
277,
12,
2166,
12,
1245,
12,
627,
3223,
12,
1011,
958,
304,
288,
291,
14,
3431,
14,
740,
1332,
1896,
12,
1245,
12,
4978,
12,
2074,
430,
288,
372,
3380,
14,
2253,
63,
1188,
8,
1188,
12,
2166,
29,
1896,
12,
3147,
730,
29,
277,
14,
11402,
59,
1896,
467,
3147,
627,
3223,
12,
1011,
958,
9,
339,
7509,
63,
16618,
29076,
51,
275,
715,
199,
2590,
2186,
26,
272,
327,
32754,
1006,
4967,
2952,
4967,
506,
19564,
3545,
8646,
272,
327,
6623,
626,
18382,
365,
440,
299,
1376,
370,
1611,
19,
75,
14,
272,
7509,
63,
16618,
29076,
51,
275,
756,
199,
199,
533,
1104,
8,
3110,
304,
272,
408,
2765,
1414,
5920,
314,
3404,
13,
576,
402,
314,
2559,
14,
272,
408,
272,
1369,
275,
1689,
15795,
2005,
5920,
641,
314,
2559,
531,
272,
922,
63,
1419,
275,
4274,
2343,
297,
283,
77,
297,
283,
7496,
3404,
13,
576,
659,
490,
661,
26854,
297,
283,
82,
297,
2151,
661,
11834,
340,
1846,
1059,
3404,
13,
576,
6302,
283,
1993,
283,
1530,
295,
27486,
1872,
13,
863,
22676,
3855,
490,
661,
4768,
297,
283,
83,
297,
2151,
283,
20326,
4458,
543,
376,
1125,
340,
282,
1104,
6918,
5440,
339,
5046,
63,
1419,
275,
788,
2343,
297,
283,
26854,
297,
283,
4768,
418,
339,
347,
8265,
63,
1419,
8,
277,
304,
267,
408,
9899,
849,
1338,
367,
1511,
1041,
267,
291,
14,
26854,
275,
378,
267,
291,
14,
2343,
275,
413,
267,
291,
14,
4768,
275,
378,
267,
291,
423,
5451,
275,
378,
339,
347,
17284,
63,
1419,
8,
277,
304,
267,
986,
339,
347,
7987,
8,
277,
12,
1499,
304,
267,
408,
23209,
314,
1329,
402,
3598,
626,
11058,
1041,
267,
291,
423,
5451,
847,
413,
267,
372,
5817,
14,
4050,
8,
277,
12,
1499,
9,
339,
347,
1255,
8,
277,
304,
267,
408,
16291,
314,
1414,
1041,
267,
327,
5147,
314,
7750,
2295,
267,
340,
291,
14,
2343,
26,
288,
291,
14,
1074,
63,
2343,
342,
267,
340,
291,
14,
26854,
26,
288,
340,
7509,
63,
16618,
29076,
51,
26,
355,
291,
14,
1074,
63,
26854,
342,
288,
916,
291,
14,
4768,
26,
355,
746,
12577,
30221,
360,
1918,
18382,
2559,
365,
4346,
2659,
398,
327,
4691,
1159,
746,
376,
1125,
315,
7478,
818,
12,
340,
781,
1172,
737,
5210,
267,
327,
1373,
5721,
267,
340,
291,
14,
4768,
436,
291,
423,
5451,
690,
378,
26,
288,
746,
12577,
30221,
360,
8254,
3211,
2195,
2559,
2659,
339,
347,
1104,
63,
2343,
8,
277,
304,
267,
408,
37,
561,
1482,
626,
1006,
1415,
4008,
402,
3404,
13,
576,
787,
6841,
14,
398,
11105,
1504,
26,
288,
536,
12,
1015,
12,
2851,
398,
799,
11902,
1504,
26,
288,
334,
2502,
436,
4132,
63,
2123,
9,
503,
334,
26665,
436,
11075,
281,
63,
2123,
430,
398,
644,
22476,
340,
1263,
787,
4124,
14,
267,
408,
267,
3341,
275,
291,
14,
4972,
14,
2343,
398,
4124,
275,
942,
267,
367,
1921,
315,
661,
354,
297,
283,
1023,
297,
283,
633,
735,
288,
340,
440,
334,
11161,
8,
2343,
12,
1921,
9,
436,
2519,
8,
2343,
12,
1921,
2298,
355,
4124,
14,
740,
8,
962,
9,
398,
340,
4124,
26,
288,
291,
14,
4050,
480,
4752,
1415,
3404,
13,
576,
26,
450,
83,
2,
221,
450,
1656,
1987,
904,
8,
4752,
430,
267,
340,
3341,
14,
2502,
26,
288,
340,
440,
3341,
14,
2502,
63,
2123,
26,
355,
291,
14,
4050,
480,
4752,
3404,
13,
576,
26,
340,
283,
2502,
7,
6841,
12,
298,
435,
2079,
3546,
2502,
63,
2123,
7,
1077,
506,
6841,
4634,
531,
267,
916,
3341,
14,
26665,
26,
288,
340,
440,
3341,
14,
26665,
63,
2123,
26,
355,
291,
14,
4050,
480,
4752,
3404,
13,
576,
26,
340,
283,
26665,
7,
6841,
12,
298,
435,
2079,
3546,
26665,
63,
2123,
7,
1077,
506,
6841,
4634,
531,
267,
587,
26,
288,
291,
14,
4050,
480,
4752,
3404,
13,
576,
26,
1902,
334,
2502,
436,
4132,
63,
2123,
9,
298,
435,
1993,
298,
269,
334,
26665,
436,
11075,
281,
63,
2123,
9,
298,
435,
1993,
298,
5626,
506,
6841,
531,
339,
347,
1104,
63,
26854,
8,
277,
304,
267,
408,
11834,
340,
314,
1846,
1059,
1504,
787,
20883,
13,
863,
22676,
1041,
267,
666,
275,
291,
14,
4972,
14,
362,
63,
2809,
63,
1802,
342,
267,
367,
5721,
315,
291,
423,
1074,
63,
8332,
63,
576,
8,
576,
304,
288,
1004,
275,
5721,
1988,
17,
1055,
362,
360,
604,
358,
288,
340,
1004,
365,
488,
26,
355,
5721,
275,
5721,
59,
17,
61,
288,
587,
26,
355,
5721,
275,
1543,
83,
334,
604,
450,
83,
3171,
450,
334,
3764,
59,
17,
467,
1004,
9,
288,
291,
14,
4050,
8,
3764,
9,
339,
347,
485,
1074,
63,
8332,
63,
576,
8,
277,
12,
666,
304,
267,
408,
3407,
3598,
1380,
314,
2741,
666,
3181,
1133,
6555,
1041,
267,
327,
314,
2387,
436,
7392,
63,
1224,
13502,
1929,
642,
370,
506,
282,
931,
267,
1350,
63,
515,
275,
291,
14,
4972,
14,
1579,
63,
354,
503,
283,
2758,
14,
647,
7,
267,
1798,
275,
10191,
342,
267,
2202,
275,
22523,
14,
14553,
8,
4608,
2687,
2842,
4641,
14,
362,
63,
885,
63,
1459,
342,
267,
2202,
14,
2902,
63,
2063,
275,
841
] |
[
13350,
14,
1531,
14,
1074,
199,
199,
29452,
314,
12577,
283,
1074,
7,
1414,
14,
199,
624,
199,
504,
7065,
14,
1018,
492,
5817,
199,
504,
7065,
14,
2550,
492,
12577,
30221,
199,
199,
893,
26,
272,
327,
18382,
365,
4903,
272,
687,
18382,
14,
1208,
492,
23786,
272,
687,
18382,
14,
11531,
14,
8332,
492,
10191,
272,
687,
18382,
492,
22523,
272,
687,
18382,
492,
3380,
339,
1021,
428,
441,
343,
15891,
8,
15891,
304,
398,
347,
636,
826,
721,
277,
12,
1350,
12,
3622,
63,
1896,
12,
394,
4478,
63,
1896,
12,
2547,
29,
403,
12,
2151,
3105,
29,
16,
12,
2644,
534,
4371,
297,
1125,
63,
2232,
534,
1814,
735,
288,
291,
14,
3431,
275,
942,
288,
23786,
855,
826,
721,
277,
12,
1350,
12,
3622,
63,
1896,
12,
394,
4478,
63,
1896,
12,
2547,
12,
2892,
3105,
12,
2644,
12,
1125,
63,
2232,
9,
398,
347,
2656,
63,
1188,
8,
277,
12,
2166,
12,
1245,
12,
627,
3223,
12,
1011,
958,
304,
288,
291,
14,
3431,
14,
740,
1332,
1896,
12,
1245,
12,
4978,
12,
2074,
430,
288,
372,
3380,
14,
2253,
63,
1188,
8,
1188,
12,
2166,
29,
1896,
12,
3147,
730,
29,
277,
14,
11402,
59,
1896,
467,
3147,
627,
3223,
12,
1011,
958,
9,
339,
7509,
63,
16618,
29076,
51,
275,
715,
199,
2590,
2186,
26,
272,
327,
32754,
1006,
4967,
2952,
4967,
506,
19564,
3545,
8646,
272,
327,
6623,
626,
18382,
365,
440,
299,
1376,
370,
1611,
19,
75,
14,
272,
7509,
63,
16618,
29076,
51,
275,
756,
199,
199,
533,
1104,
8,
3110,
304,
272,
408,
2765,
1414,
5920,
314,
3404,
13,
576,
402,
314,
2559,
14,
272,
408,
272,
1369,
275,
1689,
15795,
2005,
5920,
641,
314,
2559,
531,
272,
922,
63,
1419,
275,
4274,
2343,
297,
283,
77,
297,
283,
7496,
3404,
13,
576,
659,
490,
661,
26854,
297,
283,
82,
297,
2151,
661,
11834,
340,
1846,
1059,
3404,
13,
576,
6302,
283,
1993,
283,
1530,
295,
27486,
1872,
13,
863,
22676,
3855,
490,
661,
4768,
297,
283,
83,
297,
2151,
283,
20326,
4458,
543,
376,
1125,
340,
282,
1104,
6918,
5440,
339,
5046,
63,
1419,
275,
788,
2343,
297,
283,
26854,
297,
283,
4768,
418,
339,
347,
8265,
63,
1419,
8,
277,
304,
267,
408,
9899,
849,
1338,
367,
1511,
1041,
267,
291,
14,
26854,
275,
378,
267,
291,
14,
2343,
275,
413,
267,
291,
14,
4768,
275,
378,
267,
291,
423,
5451,
275,
378,
339,
347,
17284,
63,
1419,
8,
277,
304,
267,
986,
339,
347,
7987,
8,
277,
12,
1499,
304,
267,
408,
23209,
314,
1329,
402,
3598,
626,
11058,
1041,
267,
291,
423,
5451,
847,
413,
267,
372,
5817,
14,
4050,
8,
277,
12,
1499,
9,
339,
347,
1255,
8,
277,
304,
267,
408,
16291,
314,
1414,
1041,
267,
327,
5147,
314,
7750,
2295,
267,
340,
291,
14,
2343,
26,
288,
291,
14,
1074,
63,
2343,
342,
267,
340,
291,
14,
26854,
26,
288,
340,
7509,
63,
16618,
29076,
51,
26,
355,
291,
14,
1074,
63,
26854,
342,
288,
916,
291,
14,
4768,
26,
355,
746,
12577,
30221,
360,
1918,
18382,
2559,
365,
4346,
2659,
398,
327,
4691,
1159,
746,
376,
1125,
315,
7478,
818,
12,
340,
781,
1172,
737,
5210,
267,
327,
1373,
5721,
267,
340,
291,
14,
4768,
436,
291,
423,
5451,
690,
378,
26,
288,
746,
12577,
30221,
360,
8254,
3211,
2195,
2559,
2659,
339,
347,
1104,
63,
2343,
8,
277,
304,
267,
408,
37,
561,
1482,
626,
1006,
1415,
4008,
402,
3404,
13,
576,
787,
6841,
14,
398,
11105,
1504,
26,
288,
536,
12,
1015,
12,
2851,
398,
799,
11902,
1504,
26,
288,
334,
2502,
436,
4132,
63,
2123,
9,
503,
334,
26665,
436,
11075,
281,
63,
2123,
430,
398,
644,
22476,
340,
1263,
787,
4124,
14,
267,
408,
267,
3341,
275,
291,
14,
4972,
14,
2343,
398,
4124,
275,
942,
267,
367,
1921,
315,
661,
354,
297,
283,
1023,
297,
283,
633,
735,
288,
340,
440,
334,
11161,
8,
2343,
12,
1921,
9,
436,
2519,
8,
2343,
12,
1921,
2298,
355,
4124,
14,
740,
8,
962,
9,
398,
340,
4124,
26,
288,
291,
14,
4050,
480,
4752,
1415,
3404,
13,
576,
26,
450,
83,
2,
221,
450,
1656,
1987,
904,
8,
4752,
430,
267,
340,
3341,
14,
2502,
26,
288,
340,
440,
3341,
14,
2502,
63,
2123,
26,
355,
291,
14,
4050,
480,
4752,
3404,
13,
576,
26,
340,
283,
2502,
7,
6841,
12,
298,
435,
2079,
3546,
2502,
63,
2123,
7,
1077,
506,
6841,
4634,
531,
267,
916,
3341,
14,
26665,
26,
288,
340,
440,
3341,
14,
26665,
63,
2123,
26,
355,
291,
14,
4050,
480,
4752,
3404,
13,
576,
26,
340,
283,
26665,
7,
6841,
12,
298,
435,
2079,
3546,
26665,
63,
2123,
7,
1077,
506,
6841,
4634,
531,
267,
587,
26,
288,
291,
14,
4050,
480,
4752,
3404,
13,
576,
26,
1902,
334,
2502,
436,
4132,
63,
2123,
9,
298,
435,
1993,
298,
269,
334,
26665,
436,
11075,
281,
63,
2123,
9,
298,
435,
1993,
298,
5626,
506,
6841,
531,
339,
347,
1104,
63,
26854,
8,
277,
304,
267,
408,
11834,
340,
314,
1846,
1059,
1504,
787,
20883,
13,
863,
22676,
1041,
267,
666,
275,
291,
14,
4972,
14,
362,
63,
2809,
63,
1802,
342,
267,
367,
5721,
315,
291,
423,
1074,
63,
8332,
63,
576,
8,
576,
304,
288,
1004,
275,
5721,
1988,
17,
1055,
362,
360,
604,
358,
288,
340,
1004,
365,
488,
26,
355,
5721,
275,
5721,
59,
17,
61,
288,
587,
26,
355,
5721,
275,
1543,
83,
334,
604,
450,
83,
3171,
450,
334,
3764,
59,
17,
467,
1004,
9,
288,
291,
14,
4050,
8,
3764,
9,
339,
347,
485,
1074,
63,
8332,
63,
576,
8,
277,
12,
666,
304,
267,
408,
3407,
3598,
1380,
314,
2741,
666,
3181,
1133,
6555,
1041,
267,
327,
314,
2387,
436,
7392,
63,
1224,
13502,
1929,
642,
370,
506,
282,
931,
267,
1350,
63,
515,
275,
291,
14,
4972,
14,
1579,
63,
354,
503,
283,
2758,
14,
647,
7,
267,
1798,
275,
10191,
342,
267,
2202,
275,
22523,
14,
14553,
8,
4608,
2687,
2842,
4641,
14,
362,
63,
885,
63,
1459,
342,
267,
2202,
14,
2902,
63,
2063,
275,
841,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
lxybox1/MissionPlanner
|
Lib/logging/handlers.py
|
53
|
46301
|
# Copyright 2001-2010 by Vinay Sajip. All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of Vinay Sajip
# not be used in advertising or publicity pertaining to distribution
# of the software without specific, written prior permission.
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
"""
Additional handlers for the logging package for Python. The core package is
based on PEP 282 and comments thereto in comp.lang.python, and influenced by
Apache's log4j system.
Copyright (C) 2001-2010 Vinay Sajip. All Rights Reserved.
To use, simply 'import logging.handlers' and log away!
"""
import logging, socket, os, cPickle, struct, time, re
from stat import ST_DEV, ST_INO, ST_MTIME
try:
import codecs
except ImportError:
codecs = None
try:
unicode
_unicode = True
except NameError:
_unicode = False
#
# Some constants...
#
DEFAULT_TCP_LOGGING_PORT = 9020
DEFAULT_UDP_LOGGING_PORT = 9021
DEFAULT_HTTP_LOGGING_PORT = 9022
DEFAULT_SOAP_LOGGING_PORT = 9023
SYSLOG_UDP_PORT = 514
SYSLOG_TCP_PORT = 514
_MIDNIGHT = 24 * 60 * 60 # number of seconds in a day
class BaseRotatingHandler(logging.FileHandler):
"""
Base class for handlers that rotate log files at a certain point.
Not meant to be instantiated directly. Instead, use RotatingFileHandler
or TimedRotatingFileHandler.
"""
def __init__(self, filename, mode, encoding=None, delay=0):
"""
Use the specified filename for streamed logging
"""
if codecs is None:
encoding = None
logging.FileHandler.__init__(self, filename, mode, encoding, delay)
self.mode = mode
self.encoding = encoding
def emit(self, record):
"""
Emit a record.
Output the record to the file, catering for rollover as described
in doRollover().
"""
try:
if self.shouldRollover(record):
self.doRollover()
logging.FileHandler.emit(self, record)
except (KeyboardInterrupt, SystemExit):
raise
except:
self.handleError(record)
class RotatingFileHandler(BaseRotatingHandler):
"""
Handler for logging to a set of files, which switches from one file
to the next when the current file reaches a certain size.
"""
def __init__(self, filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=0):
"""
Open the specified file and use it as the stream for logging.
By default, the file grows indefinitely. You can specify particular
values of maxBytes and backupCount to allow the file to rollover at
a predetermined size.
Rollover occurs whenever the current log file is nearly maxBytes in
length. If backupCount is >= 1, the system will successively create
new files with the same pathname as the base file, but with extensions
".1", ".2" etc. appended to it. For example, with a backupCount of 5
and a base file name of "app.log", you would get "app.log",
"app.log.1", "app.log.2", ... through to "app.log.5". The file being
written to is always "app.log" - when it gets filled up, it is closed
and renamed to "app.log.1", and if files "app.log.1", "app.log.2" etc.
exist, then they are renamed to "app.log.2", "app.log.3" etc.
respectively.
If maxBytes is zero, rollover never occurs.
"""
# If rotation/rollover is wanted, it doesn't make sense to use another
# mode. If for example 'w' were specified, then if there were multiple
# runs of the calling application, the logs from previous runs would be
# lost if the 'w' is respected, because the log file would be truncated
# on each run.
if maxBytes > 0:
mode = 'a'
BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
self.maxBytes = maxBytes
self.backupCount = backupCount
def doRollover(self):
"""
Do a rollover, as described in __init__().
"""
if self.stream:
self.stream.close()
self.stream = None
if self.backupCount > 0:
for i in range(self.backupCount - 1, 0, -1):
sfn = "%s.%d" % (self.baseFilename, i)
dfn = "%s.%d" % (self.baseFilename, i + 1)
if os.path.exists(sfn):
#print "%s -> %s" % (sfn, dfn)
if os.path.exists(dfn):
os.remove(dfn)
os.rename(sfn, dfn)
dfn = self.baseFilename + ".1"
if os.path.exists(dfn):
os.remove(dfn)
os.rename(self.baseFilename, dfn)
#print "%s -> %s" % (self.baseFilename, dfn)
self.mode = 'w'
self.stream = self._open()
def shouldRollover(self, record):
"""
Determine if rollover should occur.
Basically, see if the supplied record would cause the file to exceed
the size limit we have.
"""
if self.stream is None: # delay was set...
self.stream = self._open()
if self.maxBytes > 0: # are we rolling over?
msg = "%s\n" % self.format(record)
self.stream.seek(0, 2) #due to non-posix-compliant Windows feature
if self.stream.tell() + len(msg) >= self.maxBytes:
return 1
return 0
class TimedRotatingFileHandler(BaseRotatingHandler):
"""
Handler for logging to a file, rotating the log file at certain timed
intervals.
If backupCount is > 0, when rollover is done, no more than backupCount
files are kept - the oldest ones are deleted.
"""
def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None, delay=False, utc=False):
BaseRotatingHandler.__init__(self, filename, 'a', encoding, delay)
self.when = when.upper()
self.backupCount = backupCount
self.utc = utc
# Calculate the real rollover interval, which is just the number of
# seconds between rollovers. Also set the filename suffix used when
# a rollover occurs. Current 'when' events supported:
# S - Seconds
# M - Minutes
# H - Hours
# D - Days
# midnight - roll over at midnight
# W{0-6} - roll over on a certain day; 0 - Monday
#
# Case of the 'when' specifier is not important; lower or upper case
# will work.
if self.when == 'S':
self.interval = 1 # one second
self.suffix = "%Y-%m-%d_%H-%M-%S"
self.extMatch = r"^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}$"
elif self.when == 'M':
self.interval = 60 # one minute
self.suffix = "%Y-%m-%d_%H-%M"
self.extMatch = r"^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}$"
elif self.when == 'H':
self.interval = 60 * 60 # one hour
self.suffix = "%Y-%m-%d_%H"
self.extMatch = r"^\d{4}-\d{2}-\d{2}_\d{2}$"
elif self.when == 'D' or self.when == 'MIDNIGHT':
self.interval = 60 * 60 * 24 # one day
self.suffix = "%Y-%m-%d"
self.extMatch = r"^\d{4}-\d{2}-\d{2}$"
elif self.when.startswith('W'):
self.interval = 60 * 60 * 24 * 7 # one week
if len(self.when) != 2:
raise ValueError("You must specify a day for weekly rollover from 0 to 6 (0 is Monday): %s" % self.when)
if self.when[1] < '0' or self.when[1] > '6':
raise ValueError("Invalid day specified for weekly rollover: %s" % self.when)
self.dayOfWeek = int(self.when[1])
self.suffix = "%Y-%m-%d"
self.extMatch = r"^\d{4}-\d{2}-\d{2}$"
else:
raise ValueError("Invalid rollover interval specified: %s" % self.when)
self.extMatch = re.compile(self.extMatch)
self.interval = self.interval * interval # multiply by units requested
if os.path.exists(filename):
t = os.stat(filename)[ST_MTIME]
else:
t = int(time.time())
self.rolloverAt = self.computeRollover(t)
def computeRollover(self, currentTime):
"""
Work out the rollover time based on the specified time.
"""
result = currentTime + self.interval
# If we are rolling over at midnight or weekly, then the interval is already known.
# What we need to figure out is WHEN the next interval is. In other words,
# if you are rolling over at midnight, then your base interval is 1 day,
# but you want to start that one day clock at midnight, not now. So, we
# have to fudge the rolloverAt value in order to trigger the first rollover
# at the right time. After that, the regular interval will take care of
# the rest. Note that this code doesn't care about leap seconds. :)
if self.when == 'MIDNIGHT' or self.when.startswith('W'):
# This could be done with less code, but I wanted it to be clear
if self.utc:
t = time.gmtime(currentTime)
else:
t = time.localtime(currentTime)
currentHour = t[3]
currentMinute = t[4]
currentSecond = t[5]
# r is the number of seconds left between now and midnight
r = _MIDNIGHT - ((currentHour * 60 + currentMinute) * 60 +
currentSecond)
result = currentTime + r
# If we are rolling over on a certain day, add in the number of days until
# the next rollover, but offset by 1 since we just calculated the time
# until the next day starts. There are three cases:
# Case 1) The day to rollover is today; in this case, do nothing
# Case 2) The day to rollover is further in the interval (i.e., today is
# day 2 (Wednesday) and rollover is on day 6 (Sunday). Days to
# next rollover is simply 6 - 2 - 1, or 3.
# Case 3) The day to rollover is behind us in the interval (i.e., today
# is day 5 (Saturday) and rollover is on day 3 (Thursday).
# Days to rollover is 6 - 5 + 3, or 4. In this case, it's the
# number of days left in the current week (1) plus the number
# of days in the next week until the rollover day (3).
# The calculations described in 2) and 3) above need to have a day added.
# This is because the above time calculation takes us to midnight on this
# day, i.e. the start of the next day.
if self.when.startswith('W'):
day = t[6] # 0 is Monday
if day != self.dayOfWeek:
if day < self.dayOfWeek:
daysToWait = self.dayOfWeek - day
else:
daysToWait = 6 - day + self.dayOfWeek + 1
newRolloverAt = result + (daysToWait * (60 * 60 * 24))
if not self.utc:
dstNow = t[-1]
dstAtRollover = time.localtime(newRolloverAt)[-1]
if dstNow != dstAtRollover:
if not dstNow: # DST kicks in before next rollover, so we need to deduct an hour
newRolloverAt = newRolloverAt - 3600
else: # DST bows out before next rollover, so we need to add an hour
newRolloverAt = newRolloverAt + 3600
result = newRolloverAt
return result
def shouldRollover(self, record):
"""
Determine if rollover should occur.
record is not used, as we are just comparing times, but it is needed so
the method signatures are the same
"""
t = int(time.time())
if t >= self.rolloverAt:
return 1
#print "No need to rollover: %d, %d" % (t, self.rolloverAt)
return 0
def getFilesToDelete(self):
"""
Determine the files to delete when rolling over.
More specific than the earlier method, which just used glob.glob().
"""
dirName, baseName = os.path.split(self.baseFilename)
fileNames = os.listdir(dirName)
result = []
prefix = baseName + "."
plen = len(prefix)
for fileName in fileNames:
if fileName[:plen] == prefix:
suffix = fileName[plen:]
if self.extMatch.match(suffix):
result.append(os.path.join(dirName, fileName))
result.sort()
if len(result) < self.backupCount:
result = []
else:
result = result[:len(result) - self.backupCount]
return result
def doRollover(self):
"""
do a rollover; in this case, a date/time stamp is appended to the filename
when the rollover happens. However, you want the file to be named for the
start of the interval, not the current time. If there is a backup count,
then we have to get a list of matching filenames, sort them and remove
the one with the oldest suffix.
"""
if self.stream:
self.stream.close()
self.stream = None
# get the time that this sequence started at and make it a TimeTuple
t = self.rolloverAt - self.interval
if self.utc:
timeTuple = time.gmtime(t)
else:
timeTuple = time.localtime(t)
dfn = self.baseFilename + "." + time.strftime(self.suffix, timeTuple)
if os.path.exists(dfn):
os.remove(dfn)
os.rename(self.baseFilename, dfn)
if self.backupCount > 0:
# find the oldest log file and delete it
#s = glob.glob(self.baseFilename + ".20*")
#if len(s) > self.backupCount:
# s.sort()
# os.remove(s[0])
for s in self.getFilesToDelete():
os.remove(s)
#print "%s -> %s" % (self.baseFilename, dfn)
self.mode = 'w'
self.stream = self._open()
currentTime = int(time.time())
newRolloverAt = self.computeRollover(currentTime)
while newRolloverAt <= currentTime:
newRolloverAt = newRolloverAt + self.interval
#If DST changes and midnight or weekly rollover, adjust for this.
if (self.when == 'MIDNIGHT' or self.when.startswith('W')) and not self.utc:
dstNow = time.localtime(currentTime)[-1]
dstAtRollover = time.localtime(newRolloverAt)[-1]
if dstNow != dstAtRollover:
if not dstNow: # DST kicks in before next rollover, so we need to deduct an hour
newRolloverAt = newRolloverAt - 3600
else: # DST bows out before next rollover, so we need to add an hour
newRolloverAt = newRolloverAt + 3600
self.rolloverAt = newRolloverAt
class WatchedFileHandler(logging.FileHandler):
"""
A handler for logging to a file, which watches the file
to see if it has changed while in use. This can happen because of
usage of programs such as newsyslog and logrotate which perform
log file rotation. This handler, intended for use under Unix,
watches the file to see if it has changed since the last emit.
(A file has changed if its device or inode have changed.)
If it has changed, the old file stream is closed, and the file
opened to get a new stream.
This handler is not appropriate for use under Windows, because
under Windows open files cannot be moved or renamed - logging
opens the files with exclusive locks - and so there is no need
for such a handler. Furthermore, ST_INO is not supported under
Windows; stat always returns zero for this value.
This handler is based on a suggestion and patch by Chad J.
Schroeder.
"""
def __init__(self, filename, mode='a', encoding=None, delay=0):
logging.FileHandler.__init__(self, filename, mode, encoding, delay)
if not os.path.exists(self.baseFilename):
self.dev, self.ino = -1, -1
else:
stat = os.stat(self.baseFilename)
self.dev, self.ino = stat[ST_DEV], stat[ST_INO]
def emit(self, record):
"""
Emit a record.
First check if the underlying file has changed, and if it
has, close the old stream and reopen the file to get the
current stream.
"""
if not os.path.exists(self.baseFilename):
stat = None
changed = 1
else:
stat = os.stat(self.baseFilename)
changed = (stat[ST_DEV] != self.dev) or (stat[ST_INO] != self.ino)
if changed and self.stream is not None:
self.stream.flush()
self.stream.close()
self.stream = self._open()
if stat is None:
stat = os.stat(self.baseFilename)
self.dev, self.ino = stat[ST_DEV], stat[ST_INO]
logging.FileHandler.emit(self, record)
class SocketHandler(logging.Handler):
"""
A handler class which writes logging records, in pickle format, to
a streaming socket. The socket is kept open across logging calls.
If the peer resets it, an attempt is made to reconnect on the next call.
The pickle which is sent is that of the LogRecord's attribute dictionary
(__dict__), so that the receiver does not need to have the logging module
installed in order to process the logging event.
To unpickle the record at the receiving end into a LogRecord, use the
makeLogRecord function.
"""
def __init__(self, host, port):
"""
Initializes the handler with a specific host address and port.
The attribute 'closeOnError' is set to 1 - which means that if
a socket error occurs, the socket is silently closed and then
reopened on the next logging call.
"""
logging.Handler.__init__(self)
self.host = host
self.port = port
self.sock = None
self.closeOnError = 0
self.retryTime = None
#
# Exponential backoff parameters.
#
self.retryStart = 1.0
self.retryMax = 30.0
self.retryFactor = 2.0
def makeSocket(self, timeout=1):
"""
A factory method which allows subclasses to define the precise
type of socket they want.
"""
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if hasattr(s, 'settimeout'):
s.settimeout(timeout)
s.connect((self.host, self.port))
return s
def createSocket(self):
"""
Try to create a socket, using an exponential backoff with
a max retry time. Thanks to Robert Olson for the original patch
(SF #815911) which has been slightly refactored.
"""
now = time.time()
# Either retryTime is None, in which case this
# is the first time back after a disconnect, or
# we've waited long enough.
if self.retryTime is None:
attempt = 1
else:
attempt = (now >= self.retryTime)
if attempt:
try:
self.sock = self.makeSocket()
self.retryTime = None # next time, no delay before trying
except socket.error:
#Creation failed, so set the retry time and return.
if self.retryTime is None:
self.retryPeriod = self.retryStart
else:
self.retryPeriod = self.retryPeriod * self.retryFactor
if self.retryPeriod > self.retryMax:
self.retryPeriod = self.retryMax
self.retryTime = now + self.retryPeriod
def send(self, s):
"""
Send a pickled string to the socket.
This function allows for partial sends which can happen when the
network is busy.
"""
if self.sock is None:
self.createSocket()
#self.sock can be None either because we haven't reached the retry
#time yet, or because we have reached the retry time and retried,
#but are still unable to connect.
if self.sock:
try:
if hasattr(self.sock, "sendall"):
self.sock.sendall(s)
else:
sentsofar = 0
left = len(s)
while left > 0:
sent = self.sock.send(s[sentsofar:])
sentsofar = sentsofar + sent
left = left - sent
except socket.error:
self.sock.close()
self.sock = None # so we can call createSocket next time
def makePickle(self, record):
"""
Pickles the record in binary format with a length prefix, and
returns it ready for transmission across the socket.
"""
ei = record.exc_info
if ei:
dummy = self.format(record) # just to get traceback text into record.exc_text
record.exc_info = None # to avoid Unpickleable error
s = cPickle.dumps(record.__dict__, 1)
if ei:
record.exc_info = ei # for next handler
slen = struct.pack(">L", len(s))
return slen + s
def handleError(self, record):
"""
Handle an error during logging.
An error has occurred during logging. Most likely cause -
connection lost. Close the socket so that we can retry on the
next event.
"""
if self.closeOnError and self.sock:
self.sock.close()
self.sock = None #try to reconnect next time
else:
logging.Handler.handleError(self, record)
def emit(self, record):
"""
Emit a record.
Pickles the record and writes it to the socket in binary format.
If there is an error with the socket, silently drop the packet.
If there was a problem with the socket, re-establishes the
socket.
"""
try:
s = self.makePickle(record)
self.send(s)
except (KeyboardInterrupt, SystemExit):
raise
except:
self.handleError(record)
def close(self):
"""
Closes the socket.
"""
if self.sock:
self.sock.close()
self.sock = None
logging.Handler.close(self)
class DatagramHandler(SocketHandler):
"""
A handler class which writes logging records, in pickle format, to
a datagram socket. The pickle which is sent is that of the LogRecord's
attribute dictionary (__dict__), so that the receiver does not need to
have the logging module installed in order to process the logging event.
To unpickle the record at the receiving end into a LogRecord, use the
makeLogRecord function.
"""
def __init__(self, host, port):
"""
Initializes the handler with a specific host address and port.
"""
SocketHandler.__init__(self, host, port)
self.closeOnError = 0
def makeSocket(self):
"""
The factory method of SocketHandler is here overridden to create
a UDP socket (SOCK_DGRAM).
"""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return s
def send(self, s):
"""
Send a pickled string to a socket.
This function no longer allows for partial sends which can happen
when the network is busy - UDP does not guarantee delivery and
can deliver packets out of sequence.
"""
if self.sock is None:
self.createSocket()
self.sock.sendto(s, (self.host, self.port))
class SysLogHandler(logging.Handler):
"""
A handler class which sends formatted logging records to a syslog
server. Based on Sam Rushing's syslog module:
http://www.nightmare.com/squirl/python-ext/misc/syslog.py
Contributed by Nicolas Untz (after which minor refactoring changes
have been made).
"""
# from <linux/sys/syslog.h>:
# ======================================================================
# priorities/facilities are encoded into a single 32-bit quantity, where
# the bottom 3 bits are the priority (0-7) and the top 28 bits are the
# facility (0-big number). Both the priorities and the facilities map
# roughly one-to-one to strings in the syslogd(8) source code. This
# mapping is included in this file.
#
# priorities (these are ordered)
LOG_EMERG = 0 # system is unusable
LOG_ALERT = 1 # action must be taken immediately
LOG_CRIT = 2 # critical conditions
LOG_ERR = 3 # error conditions
LOG_WARNING = 4 # warning conditions
LOG_NOTICE = 5 # normal but significant condition
LOG_INFO = 6 # informational
LOG_DEBUG = 7 # debug-level messages
# facility codes
LOG_KERN = 0 # kernel messages
LOG_USER = 1 # random user-level messages
LOG_MAIL = 2 # mail system
LOG_DAEMON = 3 # system daemons
LOG_AUTH = 4 # security/authorization messages
LOG_SYSLOG = 5 # messages generated internally by syslogd
LOG_LPR = 6 # line printer subsystem
LOG_NEWS = 7 # network news subsystem
LOG_UUCP = 8 # UUCP subsystem
LOG_CRON = 9 # clock daemon
LOG_AUTHPRIV = 10 # security/authorization messages (private)
LOG_FTP = 11 # FTP daemon
# other codes through 15 reserved for system use
LOG_LOCAL0 = 16 # reserved for local use
LOG_LOCAL1 = 17 # reserved for local use
LOG_LOCAL2 = 18 # reserved for local use
LOG_LOCAL3 = 19 # reserved for local use
LOG_LOCAL4 = 20 # reserved for local use
LOG_LOCAL5 = 21 # reserved for local use
LOG_LOCAL6 = 22 # reserved for local use
LOG_LOCAL7 = 23 # reserved for local use
priority_names = {
"alert": LOG_ALERT,
"crit": LOG_CRIT,
"critical": LOG_CRIT,
"debug": LOG_DEBUG,
"emerg": LOG_EMERG,
"err": LOG_ERR,
"error": LOG_ERR, # DEPRECATED
"info": LOG_INFO,
"notice": LOG_NOTICE,
"panic": LOG_EMERG, # DEPRECATED
"warn": LOG_WARNING, # DEPRECATED
"warning": LOG_WARNING,
}
facility_names = {
"auth": LOG_AUTH,
"authpriv": LOG_AUTHPRIV,
"cron": LOG_CRON,
"daemon": LOG_DAEMON,
"ftp": LOG_FTP,
"kern": LOG_KERN,
"lpr": LOG_LPR,
"mail": LOG_MAIL,
"news": LOG_NEWS,
"security": LOG_AUTH, # DEPRECATED
"syslog": LOG_SYSLOG,
"user": LOG_USER,
"uucp": LOG_UUCP,
"local0": LOG_LOCAL0,
"local1": LOG_LOCAL1,
"local2": LOG_LOCAL2,
"local3": LOG_LOCAL3,
"local4": LOG_LOCAL4,
"local5": LOG_LOCAL5,
"local6": LOG_LOCAL6,
"local7": LOG_LOCAL7,
}
#The map below appears to be trivially lowercasing the key. However,
#there's more to it than meets the eye - in some locales, lowercasing
#gives unexpected results. See SF #1524081: in the Turkish locale,
#"INFO".lower() != "info"
priority_map = {
"DEBUG" : "debug",
"INFO" : "info",
"WARNING" : "warning",
"ERROR" : "error",
"CRITICAL" : "critical"
}
def __init__(self, address=('localhost', SYSLOG_UDP_PORT),
facility=LOG_USER, socktype=socket.SOCK_DGRAM):
"""
Initialize a handler.
If address is specified as a string, a UNIX socket is used. To log to a
local syslogd, "SysLogHandler(address="/dev/log")" can be used.
If facility is not specified, LOG_USER is used.
"""
logging.Handler.__init__(self)
self.address = address
self.facility = facility
self.socktype = socktype
if isinstance(address, basestring):
self.unixsocket = 1
self._connect_unixsocket(address)
else:
self.unixsocket = 0
self.socket = socket.socket(socket.AF_INET, socktype)
if socktype == socket.SOCK_STREAM:
self.socket.connect(address)
self.formatter = None
def _connect_unixsocket(self, address):
self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
# syslog may require either DGRAM or STREAM sockets
try:
self.socket.connect(address)
except socket.error:
self.socket.close()
self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.socket.connect(address)
# curious: when talking to the unix-domain '/dev/log' socket, a
# zero-terminator seems to be required. this string is placed
# into a class variable so that it can be overridden if
# necessary.
log_format_string = '<%d>%s\000'
def encodePriority(self, facility, priority):
"""
Encode the facility and priority. You can pass in strings or
integers - if strings are passed, the facility_names and
priority_names mapping dictionaries are used to convert them to
integers.
"""
if isinstance(facility, basestring):
facility = self.facility_names[facility]
if isinstance(priority, basestring):
priority = self.priority_names[priority]
return (facility << 3) | priority
def close (self):
"""
Closes the socket.
"""
if self.unixsocket:
self.socket.close()
logging.Handler.close(self)
def mapPriority(self, levelName):
"""
Map a logging level name to a key in the priority_names map.
This is useful in two scenarios: when custom levels are being
used, and in the case where you can't do a straightforward
mapping by lowercasing the logging level name because of locale-
specific issues (see SF #1524081).
"""
return self.priority_map.get(levelName, "warning")
def emit(self, record):
"""
Emit a record.
The record is formatted, and then sent to the syslog server. If
exception information is present, it is NOT sent to the server.
"""
msg = self.format(record) + '\000'
"""
We need to convert record level to lowercase, maybe this will
change in the future.
"""
prio = '<%d>' % self.encodePriority(self.facility,
self.mapPriority(record.levelname))
# Message is a string. Convert to bytes as required by RFC 5424
if type(msg) is unicode:
msg = msg.encode('utf-8')
if codecs:
msg = codecs.BOM_UTF8 + msg
msg = prio + msg
try:
if self.unixsocket:
try:
self.socket.send(msg)
except socket.error:
self._connect_unixsocket(self.address)
self.socket.send(msg)
elif self.socktype == socket.SOCK_DGRAM:
self.socket.sendto(msg, self.address)
else:
self.socket.sendall(msg)
except (KeyboardInterrupt, SystemExit):
raise
except:
self.handleError(record)
class SMTPHandler(logging.Handler):
"""
A handler class which sends an SMTP email for each logging event.
"""
def __init__(self, mailhost, fromaddr, toaddrs, subject,
credentials=None, secure=None):
"""
Initialize the handler.
Initialize the instance with the from and to addresses and subject
line of the email. To specify a non-standard SMTP port, use the
(host, port) tuple format for the mailhost argument. To specify
authentication credentials, supply a (username, password) tuple
for the credentials argument. To specify the use of a secure
protocol (TLS), pass in a tuple for the secure argument. This will
only be used when authentication credentials are supplied. The tuple
will be either an empty tuple, or a single-value tuple with the name
of a keyfile, or a 2-value tuple with the names of the keyfile and
certificate file. (This tuple is passed to the `starttls` method).
"""
logging.Handler.__init__(self)
if isinstance(mailhost, tuple):
self.mailhost, self.mailport = mailhost
else:
self.mailhost, self.mailport = mailhost, None
if isinstance(credentials, tuple):
self.username, self.password = credentials
else:
self.username = None
self.fromaddr = fromaddr
if isinstance(toaddrs, basestring):
toaddrs = [toaddrs]
self.toaddrs = toaddrs
self.subject = subject
self.secure = secure
def getSubject(self, record):
"""
Determine the subject for the email.
If you want to specify a subject line which is record-dependent,
override this method.
"""
return self.subject
def emit(self, record):
"""
Emit a record.
Format the record and send it to the specified addressees.
"""
try:
import smtplib
from email.utils import formatdate
port = self.mailport
if not port:
port = smtplib.SMTP_PORT
smtp = smtplib.SMTP(self.mailhost, port)
msg = self.format(record)
msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\nDate: %s\r\n\r\n%s" % (
self.fromaddr,
",".join(self.toaddrs),
self.getSubject(record),
formatdate(), msg)
if self.username:
if self.secure is not None:
smtp.ehlo()
smtp.starttls(*self.secure)
smtp.ehlo()
smtp.login(self.username, self.password)
smtp.sendmail(self.fromaddr, self.toaddrs, msg)
smtp.quit()
except (KeyboardInterrupt, SystemExit):
raise
except:
self.handleError(record)
class NTEventLogHandler(logging.Handler):
"""
A handler class which sends events to the NT Event Log. Adds a
registry entry for the specified application name. If no dllname is
provided, win32service.pyd (which contains some basic message
placeholders) is used. Note that use of these placeholders will make
your event logs big, as the entire message source is held in the log.
If you want slimmer logs, you have to pass in the name of your own DLL
which contains the message definitions you want to use in the event log.
"""
def __init__(self, appname, dllname=None, logtype="Application"):
logging.Handler.__init__(self)
try:
import win32evtlogutil, win32evtlog
self.appname = appname
self._welu = win32evtlogutil
if not dllname:
dllname = os.path.split(self._welu.__file__)
dllname = os.path.split(dllname[0])
dllname = os.path.join(dllname[0], r'win32service.pyd')
self.dllname = dllname
self.logtype = logtype
self._welu.AddSourceToRegistry(appname, dllname, logtype)
self.deftype = win32evtlog.EVENTLOG_ERROR_TYPE
self.typemap = {
logging.DEBUG : win32evtlog.EVENTLOG_INFORMATION_TYPE,
logging.INFO : win32evtlog.EVENTLOG_INFORMATION_TYPE,
logging.WARNING : win32evtlog.EVENTLOG_WARNING_TYPE,
logging.ERROR : win32evtlog.EVENTLOG_ERROR_TYPE,
logging.CRITICAL: win32evtlog.EVENTLOG_ERROR_TYPE,
}
except ImportError:
print("The Python Win32 extensions for NT (service, event "\
"logging) appear not to be available.")
self._welu = None
def getMessageID(self, record):
"""
Return the message ID for the event record. If you are using your
own messages, you could do this by having the msg passed to the
logger being an ID rather than a formatting string. Then, in here,
you could use a dictionary lookup to get the message ID. This
version returns 1, which is the base message ID in win32service.pyd.
"""
return 1
def getEventCategory(self, record):
"""
Return the event category for the record.
Override this if you want to specify your own categories. This version
returns 0.
"""
return 0
def getEventType(self, record):
"""
Return the event type for the record.
Override this if you want to specify your own types. This version does
a mapping using the handler's typemap attribute, which is set up in
__init__() to a dictionary which contains mappings for DEBUG, INFO,
WARNING, ERROR and CRITICAL. If you are using your own levels you will
either need to override this method or place a suitable dictionary in
the handler's typemap attribute.
"""
return self.typemap.get(record.levelno, self.deftype)
def emit(self, record):
"""
Emit a record.
Determine the message ID, event category and event type. Then
log the message in the NT event log.
"""
if self._welu:
try:
id = self.getMessageID(record)
cat = self.getEventCategory(record)
type = self.getEventType(record)
msg = self.format(record)
self._welu.ReportEvent(self.appname, id, cat, type, [msg])
except (KeyboardInterrupt, SystemExit):
raise
except:
self.handleError(record)
def close(self):
"""
Clean up this handler.
You can remove the application name from the registry as a
source of event log entries. However, if you do this, you will
not be able to see the events as you intended in the Event Log
Viewer - it needs to be able to access the registry to get the
DLL name.
"""
#self._welu.RemoveSourceFromRegistry(self.appname, self.logtype)
logging.Handler.close(self)
class HTTPHandler(logging.Handler):
"""
A class which sends records to a Web server, using either GET or
POST semantics.
"""
def __init__(self, host, url, method="GET"):
"""
Initialize the instance with the host, the request URL, and the method
("GET" or "POST")
"""
logging.Handler.__init__(self)
method = method.upper()
if method not in ["GET", "POST"]:
raise ValueError("method must be GET or POST")
self.host = host
self.url = url
self.method = method
def mapLogRecord(self, record):
"""
Default implementation of mapping the log record into a dict
that is sent as the CGI data. Overwrite in your class.
Contributed by Franz Glasner.
"""
return record.__dict__
def emit(self, record):
"""
Emit a record.
Send the record to the Web server as a percent-encoded dictionary
"""
try:
import httplib, urllib
host = self.host
h = httplib.HTTP(host)
url = self.url
data = urllib.urlencode(self.mapLogRecord(record))
if self.method == "GET":
if (url.find('?') >= 0):
sep = '&'
else:
sep = '?'
url = url + "%c%s" % (sep, data)
h.putrequest(self.method, url)
# support multiple hosts on one IP address...
# need to strip optional :port from host, if present
i = host.find(":")
if i >= 0:
host = host[:i]
h.putheader("Host", host)
if self.method == "POST":
h.putheader("Content-type",
"application/x-www-form-urlencoded")
h.putheader("Content-length", str(len(data)))
h.endheaders(data if self.method == "POST" else None)
h.getreply() #can't do anything with the result
except (KeyboardInterrupt, SystemExit):
raise
except:
self.handleError(record)
class BufferingHandler(logging.Handler):
"""
A handler class which buffers logging records in memory. Whenever each
record is added to the buffer, a check is made to see if the buffer should
be flushed. If it should, then flush() is expected to do what's needed.
"""
def __init__(self, capacity):
"""
Initialize the handler with the buffer size.
"""
logging.Handler.__init__(self)
self.capacity = capacity
self.buffer = []
def shouldFlush(self, record):
"""
Should the handler flush its buffer?
Returns true if the buffer is up to capacity. This method can be
overridden to implement custom flushing strategies.
"""
return (len(self.buffer) >= self.capacity)
def emit(self, record):
"""
Emit a record.
Append the record. If shouldFlush() tells us to, call flush() to process
the buffer.
"""
self.buffer.append(record)
if self.shouldFlush(record):
self.flush()
def flush(self):
"""
Override to implement custom flushing behaviour.
This version just zaps the buffer to empty.
"""
self.buffer = []
def close(self):
"""
Close the handler.
This version just flushes and chains to the parent class' close().
"""
self.flush()
logging.Handler.close(self)
class MemoryHandler(BufferingHandler):
"""
A handler class which buffers logging records in memory, periodically
flushing them to a target handler. Flushing occurs whenever the buffer
is full, or when an event of a certain severity or greater is seen.
"""
def __init__(self, capacity, flushLevel=logging.ERROR, target=None):
"""
Initialize the handler with the buffer size, the level at which
flushing should occur and an optional target.
Note that without a target being set either here or via setTarget(),
a MemoryHandler is no use to anyone!
"""
BufferingHandler.__init__(self, capacity)
self.flushLevel = flushLevel
self.target = target
def shouldFlush(self, record):
"""
Check for buffer full or a record at the flushLevel or higher.
"""
return (len(self.buffer) >= self.capacity) or \
(record.levelno >= self.flushLevel)
def setTarget(self, target):
"""
Set the target handler for this handler.
"""
self.target = target
def flush(self):
"""
For a MemoryHandler, flushing means just sending the buffered
records to the target, if there is one. Override if you want
different behaviour.
"""
if self.target:
for record in self.buffer:
self.target.handle(record)
self.buffer = []
def close(self):
"""
Flush, set the target to None and lose the buffer.
"""
self.flush()
self.target = None
BufferingHandler.close(self)
|
gpl-3.0
|
[
3,
1898,
12521,
13,
6542,
701,
28882,
1187,
428,
9091,
711,
14,
2900,
5924,
5702,
14,
202,
199,
3,
202,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
436,
2399,
202,
199,
3,
3794,
367,
1263,
12016,
436,
1928,
14751,
365,
11882,
10009,
12,
202,
199,
3,
2741,
626,
314,
3432,
4248,
4245,
7468,
315,
1006,
6866,
436,
626,
202,
199,
3,
3865,
626,
4248,
4245,
436,
642,
4983,
4245,
7468,
315,
202,
199,
3,
21038,
3794,
12,
436,
626,
314,
536,
402,
28882,
1187,
428,
9091,
711,
202,
199,
3,
440,
506,
1202,
315,
19613,
1044,
503,
7974,
20976,
1126,
24522,
370,
4084,
202,
199,
3,
402,
314,
2032,
1928,
2488,
12,
5313,
6791,
4983,
14,
202,
199,
3,
812,
568,
3448,
13950,
42,
1772,
8990,
51,
11727,
2990,
1663,
14142,
7816,
2296,
5749,
4141,
12,
6931,
202,
199,
3,
11727,
5292,
2990,
1634,
3169,
2401,
3092,
14,
1621,
4825,
6461,
7000,
202,
199,
3,
812,
568,
3448,
13950,
42,
1772,
6262,
7024,
2381,
1821,
8820,
12,
9168,
1549,
9110,
6736,
1549,
202,
199,
3,
1821,
6736,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
7061,
202,
199,
3,
1621,
1261,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
9612,
12,
7043,
5738,
202,
199,
3,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
2999,
199,
624,
202,
199,
8824,
8297,
367,
314,
2050,
2559,
367,
2018,
14,
710,
6170,
2559,
365,
202,
199,
6788,
641,
13663,
499,
2564,
436,
6786,
2337,
475,
315,
1013,
14,
4159,
14,
1548,
12,
436,
315,
24585,
68,
701,
202,
199,
28993,
1159,
943,
20,
74,
2656,
14,
2999,
199,
7384,
334,
35,
9,
12521,
13,
6542,
28882,
1187,
428,
9091,
711,
14,
2900,
5924,
5702,
14,
2999,
199,
1378,
675,
12,
9329,
283,
646,
2050,
14,
5586,
7,
436,
943,
13437,
1,
202,
199,
624,
2999,
199,
646,
2050,
12,
2838,
12,
747,
12,
17572,
12,
2702,
12,
900,
12,
295,
202,
199,
504,
5672,
492,
4384,
63,
13260,
12,
4384,
63,
568,
47,
12,
4384,
63,
45,
4961,
2999,
199,
893,
26,
1128,
492,
6010,
202,
199,
2590,
3545,
26,
1128,
6010,
275,
488,
202,
199,
893,
26,
1128,
2649,
1128,
485,
2975,
275,
715,
202,
199,
2590,
12746,
26,
1128,
485,
2975,
275,
756,
2999,
199,
3,
202,
199,
3,
6601,
5262,
1396,
202,
199,
3,
2999,
199,
3472,
63,
9735,
63,
27896,
63,
3657,
259,
275,
1749,
10173,
202,
199,
3472,
63,
17457,
63,
27896,
63,
3657,
259,
275,
1749,
15385,
202,
199,
3472,
63,
2856,
63,
27896,
63,
3657,
257,
275,
1749,
16348,
202,
199,
3472,
63,
4118,
1282,
63,
27896,
63,
3657,
257,
275,
1749,
16771,
202,
199,
13326,
4947,
63,
17457,
63,
3657,
3777,
275,
959,
1079,
202,
199,
13326,
4947,
63,
9735,
63,
3657,
3777,
275,
959,
1079,
2999,
199,
63,
45,
998,
46,
2830,
275,
5504,
627,
5212,
627,
5212,
221,
327,
1329,
402,
4696,
315,
282,
5382,
2999,
199,
533,
3523,
14728,
1958,
2461,
8,
4806,
14,
21982,
304,
1128,
408,
1128,
3523,
1021,
367,
8297,
626,
20071,
943,
1584,
737,
282,
9842,
2376,
14,
1128,
2832,
18329,
370,
506,
17544,
5370,
14,
221,
15345,
12,
675,
20423,
1958,
21982,
1128,
503,
4703,
68,
14728,
1958,
21982,
14,
1128,
408,
1128,
347,
636,
826,
721,
277,
12,
1788,
12,
818,
12,
2644,
29,
403,
12,
7339,
29,
16,
304,
1039,
408,
1039,
3645,
314,
2013,
1788,
367,
410,
19308,
68,
2050,
1039,
408,
1039,
340,
6010,
365,
488,
26,
1675,
2644,
275,
488,
1039,
2050,
14,
21982,
855,
826,
721,
277,
12,
1788,
12,
818,
12,
2644,
12,
7339,
9,
1039,
291,
14,
632,
275,
818,
1039,
291,
14,
2991,
275,
2644,
2958,
347,
8689,
8,
277,
12,
2777,
304,
1039,
408,
1039,
662,
1147,
282,
2777,
14,
4341,
7242,
314,
2777,
370,
314,
570,
12,
286,
323,
5985,
367,
20182,
21960,
465,
11736,
1039,
315,
886,
50,
393,
21960,
1252,
1039,
408,
1039,
862,
26,
1675,
340,
291,
14,
5626,
50,
393,
21960,
8,
3059,
304,
2628,
291,
14,
1117,
50,
393,
21960,
342,
1675,
2050,
14,
21982,
14,
8159,
8,
277,
12,
2777,
9,
1039,
871,
334,
31538,
12,
14838,
304,
1675,
746,
1039,
871,
26,
1675,
291,
14,
2479,
547,
8,
3059,
9,
2999,
199,
533,
20423,
1958,
21982,
8,
1563,
14728,
1958,
2461,
304,
1128,
408,
1128,
18599,
367,
2050,
370,
282,
663,
402,
1584,
12,
1314,
24563,
687,
1373,
570,
1128,
370,
314,
2163,
1380,
314,
1453,
570,
12276,
397,
282,
9842,
1568,
14,
1128,
408,
1128,
347,
636,
826,
721,
277,
12,
1788,
12,
818,
534,
65,
297,
1390,
5571,
29,
16,
12,
6902,
2353,
29,
16,
12,
2644,
29,
403,
12,
7339,
29,
16,
304,
1039,
408,
1039,
3232,
314,
2013,
570,
436,
675,
652,
465,
314,
2547,
367,
2050,
14,
4341,
4885,
849,
12,
314,
570,
486,
3838,
315,
23442,
590,
14,
2047,
883,
4165,
6770,
1039,
1338,
402,
1390,
5571,
436,
6902,
2353,
370,
2040,
314,
570,
370,
20182,
21960,
737,
1039,
282,
876,
27248,
1568,
14,
4341,
820,
393,
21960,
11058,
18119,
314,
1453,
943,
570,
365,
17429,
590,
1390,
5571,
315,
1039,
2582,
14,
982,
6902,
2353,
365,
2356,
413,
12,
314,
2656,
911,
27028,
9840,
1218,
1039,
892,
1584,
543,
314,
2011,
11776,
465,
314,
1300,
570,
12,
1325,
543,
5478,
1039,
3680,
17,
401,
3680,
18,
2,
5423,
14,
11544,
370,
652,
14,
2104,
2893,
12,
543,
282,
6902,
2353,
402,
959,
1039,
436,
282,
1300,
570,
536,
402,
298,
571,
14,
793,
401,
1265,
3955,
664,
298,
571,
14,
793,
401,
1039,
298,
571,
14,
793,
14,
17,
401,
298,
571,
14,
793,
14,
18,
401,
2263,
4012,
370,
298,
571,
14,
793,
14,
21,
1674,
710,
570,
3769,
1039,
5313,
370,
365,
3544,
298,
571,
14,
793,
2,
446,
1380,
652,
7545,
13457,
1536,
12,
652,
365,
6876,
1039,
436,
17864,
370,
298,
571,
14,
793,
14,
17,
401,
436,
340,
1584,
298,
571,
14,
793,
14,
17,
401,
298,
571,
14,
793,
14,
18,
2,
5423,
14,
1039,
2187,
12,
2066,
2985
] |
[
1898,
12521,
13,
6542,
701,
28882,
1187,
428,
9091,
711,
14,
2900,
5924,
5702,
14,
202,
199,
3,
202,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
436,
2399,
202,
199,
3,
3794,
367,
1263,
12016,
436,
1928,
14751,
365,
11882,
10009,
12,
202,
199,
3,
2741,
626,
314,
3432,
4248,
4245,
7468,
315,
1006,
6866,
436,
626,
202,
199,
3,
3865,
626,
4248,
4245,
436,
642,
4983,
4245,
7468,
315,
202,
199,
3,
21038,
3794,
12,
436,
626,
314,
536,
402,
28882,
1187,
428,
9091,
711,
202,
199,
3,
440,
506,
1202,
315,
19613,
1044,
503,
7974,
20976,
1126,
24522,
370,
4084,
202,
199,
3,
402,
314,
2032,
1928,
2488,
12,
5313,
6791,
4983,
14,
202,
199,
3,
812,
568,
3448,
13950,
42,
1772,
8990,
51,
11727,
2990,
1663,
14142,
7816,
2296,
5749,
4141,
12,
6931,
202,
199,
3,
11727,
5292,
2990,
1634,
3169,
2401,
3092,
14,
1621,
4825,
6461,
7000,
202,
199,
3,
812,
568,
3448,
13950,
42,
1772,
6262,
7024,
2381,
1821,
8820,
12,
9168,
1549,
9110,
6736,
1549,
202,
199,
3,
1821,
6736,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
7061,
202,
199,
3,
1621,
1261,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
9612,
12,
7043,
5738,
202,
199,
3,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
2999,
199,
624,
202,
199,
8824,
8297,
367,
314,
2050,
2559,
367,
2018,
14,
710,
6170,
2559,
365,
202,
199,
6788,
641,
13663,
499,
2564,
436,
6786,
2337,
475,
315,
1013,
14,
4159,
14,
1548,
12,
436,
315,
24585,
68,
701,
202,
199,
28993,
1159,
943,
20,
74,
2656,
14,
2999,
199,
7384,
334,
35,
9,
12521,
13,
6542,
28882,
1187,
428,
9091,
711,
14,
2900,
5924,
5702,
14,
2999,
199,
1378,
675,
12,
9329,
283,
646,
2050,
14,
5586,
7,
436,
943,
13437,
1,
202,
199,
624,
2999,
199,
646,
2050,
12,
2838,
12,
747,
12,
17572,
12,
2702,
12,
900,
12,
295,
202,
199,
504,
5672,
492,
4384,
63,
13260,
12,
4384,
63,
568,
47,
12,
4384,
63,
45,
4961,
2999,
199,
893,
26,
1128,
492,
6010,
202,
199,
2590,
3545,
26,
1128,
6010,
275,
488,
202,
199,
893,
26,
1128,
2649,
1128,
485,
2975,
275,
715,
202,
199,
2590,
12746,
26,
1128,
485,
2975,
275,
756,
2999,
199,
3,
202,
199,
3,
6601,
5262,
1396,
202,
199,
3,
2999,
199,
3472,
63,
9735,
63,
27896,
63,
3657,
259,
275,
1749,
10173,
202,
199,
3472,
63,
17457,
63,
27896,
63,
3657,
259,
275,
1749,
15385,
202,
199,
3472,
63,
2856,
63,
27896,
63,
3657,
257,
275,
1749,
16348,
202,
199,
3472,
63,
4118,
1282,
63,
27896,
63,
3657,
257,
275,
1749,
16771,
202,
199,
13326,
4947,
63,
17457,
63,
3657,
3777,
275,
959,
1079,
202,
199,
13326,
4947,
63,
9735,
63,
3657,
3777,
275,
959,
1079,
2999,
199,
63,
45,
998,
46,
2830,
275,
5504,
627,
5212,
627,
5212,
221,
327,
1329,
402,
4696,
315,
282,
5382,
2999,
199,
533,
3523,
14728,
1958,
2461,
8,
4806,
14,
21982,
304,
1128,
408,
1128,
3523,
1021,
367,
8297,
626,
20071,
943,
1584,
737,
282,
9842,
2376,
14,
1128,
2832,
18329,
370,
506,
17544,
5370,
14,
221,
15345,
12,
675,
20423,
1958,
21982,
1128,
503,
4703,
68,
14728,
1958,
21982,
14,
1128,
408,
1128,
347,
636,
826,
721,
277,
12,
1788,
12,
818,
12,
2644,
29,
403,
12,
7339,
29,
16,
304,
1039,
408,
1039,
3645,
314,
2013,
1788,
367,
410,
19308,
68,
2050,
1039,
408,
1039,
340,
6010,
365,
488,
26,
1675,
2644,
275,
488,
1039,
2050,
14,
21982,
855,
826,
721,
277,
12,
1788,
12,
818,
12,
2644,
12,
7339,
9,
1039,
291,
14,
632,
275,
818,
1039,
291,
14,
2991,
275,
2644,
2958,
347,
8689,
8,
277,
12,
2777,
304,
1039,
408,
1039,
662,
1147,
282,
2777,
14,
4341,
7242,
314,
2777,
370,
314,
570,
12,
286,
323,
5985,
367,
20182,
21960,
465,
11736,
1039,
315,
886,
50,
393,
21960,
1252,
1039,
408,
1039,
862,
26,
1675,
340,
291,
14,
5626,
50,
393,
21960,
8,
3059,
304,
2628,
291,
14,
1117,
50,
393,
21960,
342,
1675,
2050,
14,
21982,
14,
8159,
8,
277,
12,
2777,
9,
1039,
871,
334,
31538,
12,
14838,
304,
1675,
746,
1039,
871,
26,
1675,
291,
14,
2479,
547,
8,
3059,
9,
2999,
199,
533,
20423,
1958,
21982,
8,
1563,
14728,
1958,
2461,
304,
1128,
408,
1128,
18599,
367,
2050,
370,
282,
663,
402,
1584,
12,
1314,
24563,
687,
1373,
570,
1128,
370,
314,
2163,
1380,
314,
1453,
570,
12276,
397,
282,
9842,
1568,
14,
1128,
408,
1128,
347,
636,
826,
721,
277,
12,
1788,
12,
818,
534,
65,
297,
1390,
5571,
29,
16,
12,
6902,
2353,
29,
16,
12,
2644,
29,
403,
12,
7339,
29,
16,
304,
1039,
408,
1039,
3232,
314,
2013,
570,
436,
675,
652,
465,
314,
2547,
367,
2050,
14,
4341,
4885,
849,
12,
314,
570,
486,
3838,
315,
23442,
590,
14,
2047,
883,
4165,
6770,
1039,
1338,
402,
1390,
5571,
436,
6902,
2353,
370,
2040,
314,
570,
370,
20182,
21960,
737,
1039,
282,
876,
27248,
1568,
14,
4341,
820,
393,
21960,
11058,
18119,
314,
1453,
943,
570,
365,
17429,
590,
1390,
5571,
315,
1039,
2582,
14,
982,
6902,
2353,
365,
2356,
413,
12,
314,
2656,
911,
27028,
9840,
1218,
1039,
892,
1584,
543,
314,
2011,
11776,
465,
314,
1300,
570,
12,
1325,
543,
5478,
1039,
3680,
17,
401,
3680,
18,
2,
5423,
14,
11544,
370,
652,
14,
2104,
2893,
12,
543,
282,
6902,
2353,
402,
959,
1039,
436,
282,
1300,
570,
536,
402,
298,
571,
14,
793,
401,
1265,
3955,
664,
298,
571,
14,
793,
401,
1039,
298,
571,
14,
793,
14,
17,
401,
298,
571,
14,
793,
14,
18,
401,
2263,
4012,
370,
298,
571,
14,
793,
14,
21,
1674,
710,
570,
3769,
1039,
5313,
370,
365,
3544,
298,
571,
14,
793,
2,
446,
1380,
652,
7545,
13457,
1536,
12,
652,
365,
6876,
1039,
436,
17864,
370,
298,
571,
14,
793,
14,
17,
401,
436,
340,
1584,
298,
571,
14,
793,
14,
17,
401,
298,
571,
14,
793,
14,
18,
2,
5423,
14,
1039,
2187,
12,
2066,
2985,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hdoria/namcap
|
Namcap/perllocal.py
|
2
|
1251
|
#
# namcap rules - perllocal
# Copyright (C) 2003-2007 Jason Chu <jason@archlinux.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
#
import tarfile
class package:
def short_name(self):
return "perllocal"
def long_name(self):
return "Verifies the absence of perllocal.pod."
def prereq(self):
return "tar"
def analyze(self, pkginfo, tar):
ret = [[],[],[]]
j = 'perllocal.pod'
for i in tar.getnames():
if i[-len(j):] == j:
ret[0].append(("perllocal-pod-present %s", i))
return ret
def type(self):
return "tarball"
# vim: set ts=4 sw=4 noet:
|
gpl-2.0
|
[
3,
221,
199,
3,
302,
455,
2874,
4713,
446,
1126,
76,
1832,
199,
3,
1898,
334,
35,
9,
13004,
13,
9488,
1603,
2660,
2799,
85,
665,
74,
2660,
32,
1047,
5135,
14,
1308,
30,
199,
3,
221,
199,
3,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
257,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
257,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
257,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
257,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
257,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
3,
9948,
199,
646,
13608,
199,
199,
533,
2559,
26,
199,
198,
318,
3974,
63,
354,
8,
277,
304,
507,
198,
1107,
298,
22805,
1832,
2,
199,
198,
318,
1846,
63,
354,
8,
277,
304,
507,
198,
1107,
298,
21168,
314,
2236,
14073,
402,
1126,
76,
1832,
14,
12656,
2122,
199,
198,
318,
876,
2103,
8,
277,
304,
507,
198,
1107,
298,
5369,
2,
199,
198,
318,
19897,
8,
277,
12,
5496,
815,
12,
5330,
304,
507,
198,
3292,
275,
3474,
6922,
6922,
2677,
507,
198,
74,
275,
283,
22805,
1832,
14,
12656,
7,
507,
198,
509,
284,
315,
5330,
14,
362,
1247,
837,
686,
198,
692,
284,
1988,
552,
8,
74,
15405,
508,
1335,
26,
1585,
198,
3292,
59,
16,
1055,
740,
9313,
22805,
1832,
13,
12656,
13,
1881,
450,
83,
401,
284,
430,
507,
198,
1107,
2203,
199,
198,
318,
730,
8,
277,
304,
507,
198,
1107,
298,
18829,
2,
199,
3,
6695,
26,
663,
6714,
29,
20,
5584,
29,
20,
949,
386,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
221,
199,
3,
302,
455,
2874,
4713,
446,
1126,
76,
1832,
199,
3,
1898,
334,
35,
9,
13004,
13,
9488,
1603,
2660,
2799,
85,
665,
74,
2660,
32,
1047,
5135,
14,
1308,
30,
199,
3,
221,
199,
3,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
257,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
257,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
257,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
257,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
257,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
3,
9948,
199,
646,
13608,
199,
199,
533,
2559,
26,
199,
198,
318,
3974,
63,
354,
8,
277,
304,
507,
198,
1107,
298,
22805,
1832,
2,
199,
198,
318,
1846,
63,
354,
8,
277,
304,
507,
198,
1107,
298,
21168,
314,
2236,
14073,
402,
1126,
76,
1832,
14,
12656,
2122,
199,
198,
318,
876,
2103,
8,
277,
304,
507,
198,
1107,
298,
5369,
2,
199,
198,
318,
19897,
8,
277,
12,
5496,
815,
12,
5330,
304,
507,
198,
3292,
275,
3474,
6922,
6922,
2677,
507,
198,
74,
275,
283,
22805,
1832,
14,
12656,
7,
507,
198,
509,
284,
315,
5330,
14,
362,
1247,
837,
686,
198,
692,
284,
1988,
552,
8,
74,
15405,
508,
1335,
26,
1585,
198,
3292,
59,
16,
1055,
740,
9313,
22805,
1832,
13,
12656,
13,
1881,
450,
83,
401,
284,
430,
507,
198,
1107,
2203,
199,
198,
318,
730,
8,
277,
304,
507,
198,
1107,
298,
18829,
2,
199,
3,
6695,
26,
663,
6714,
29,
20,
5584,
29,
20,
949,
386,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
interaktiviti/cookiecutter-django
|
{{cookiecutter.repo_name}}/docs/conf.py
|
38
|
8103
|
# -*- coding: utf-8 -*-
#
# {{ cookiecutter.project_name }} documentation build configuration file, created by
# sphinx-quickstart.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import os
import sys
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
# sys.path.insert(0, os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
# needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = []
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
# source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'{{ cookiecutter.project_name }}'
copyright = u"{{ cookiecutter.year }}, {{ cookiecutter.author_name }}"
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.1'
# The full version, including alpha/beta/rc tags.
release = '0.1'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
# language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
# today = ''
# Else, today_fmt is used as the format for a strftime call.
# today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
# default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
# add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
# add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
# show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
# html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
# html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
# html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
# html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
# html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
# html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
# html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
# html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
# html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
# html_additional_pages = {}
# If false, no module index is generated.
# html_domain_indices = True
# If false, no index is generated.
# html_use_index = True
# If true, the index is split into individual pages for each letter.
# html_split_index = False
# If true, links to the reST sources are added to the pages.
# html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
# html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
# html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
# html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
# html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = '{{ cookiecutter.repo_name }}doc'
# -- Options for LaTeX output --------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
# 'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index',
'{{ cookiecutter.repo_name }}.tex',
u'{{ cookiecutter.project_name }} Documentation',
u"{{ cookiecutter.author_name }}", 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
# latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
# latex_use_parts = False
# If true, show page references after internal links.
# latex_show_pagerefs = False
# If true, show URL addresses after external links.
# latex_show_urls = False
# Documents to append as an appendix to all manuals.
# latex_appendices = []
# If false, no module index is generated.
# latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', '{{ cookiecutter.repo_name }}', u'{{ cookiecutter.project_name }} Documentation',
[u"{{ cookiecutter.author_name }}"], 1)
]
# If true, show URL addresses after external links.
# man_show_urls = False
# -- Options for Texinfo output ------------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', '{{ cookiecutter.repo_name }}', u'{{ cookiecutter.project_name }} Documentation',
u"{{ cookiecutter.author_name }}", '{{ cookiecutter.project_name }}',
'{{ cookiecutter.description }}', 'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
# texinfo_appendices = []
# If false, no module index is generated.
# texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
# texinfo_show_urls = 'footnote'
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
8448,
512,
745,
73,
825,
18404,
14,
1715,
63,
354,
3586,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
984,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24535,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
4839,
63,
8008,
275,
283,
17,
14,
16,
7,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
942,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1350,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
3638,
512,
745,
73,
825,
18404,
14,
1715,
63,
354,
16339,
199,
7307,
275,
399,
2,
3638,
512,
745,
73,
825,
18404,
14,
3403,
789,
1386,
8448,
512,
745,
73,
825,
18404,
14,
2502,
63,
354,
7820,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
16,
14,
17,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
16,
14,
17,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
2637,
275,
488,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
11168,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
11168,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
7970,
12,
3847,
370,
1350,
2082,
12,
626,
1336,
1584,
436,
199,
3,
6602,
370,
3686,
1380,
10023,
367,
1350,
1584,
14,
199,
5473,
63,
7435,
275,
4044,
1506,
418,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
849,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
1050,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
1050,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2498,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
3413,
1080,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
1666,
314,
3794,
367,
199,
3,
282,
769,
402,
6762,
17915,
14,
199,
1360,
63,
7915,
275,
283,
885,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
3517,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
3517,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
3517,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
3517,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
3517,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370,
675,
465,
29139,
402,
314,
199,
3,
9149,
14,
221,
961,
570,
1077,
506,
282,
5417,
7016,
570,
17048,
12802,
9,
3769
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
8448,
512,
745,
73,
825,
18404,
14,
1715,
63,
354,
3586,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
984,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24535,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
4839,
63,
8008,
275,
283,
17,
14,
16,
7,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
942,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1350,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
3638,
512,
745,
73,
825,
18404,
14,
1715,
63,
354,
16339,
199,
7307,
275,
399,
2,
3638,
512,
745,
73,
825,
18404,
14,
3403,
789,
1386,
8448,
512,
745,
73,
825,
18404,
14,
2502,
63,
354,
7820,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
16,
14,
17,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
16,
14,
17,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
2637,
275,
488,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
11168,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
11168,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
7970,
12,
3847,
370,
1350,
2082,
12,
626,
1336,
1584,
436,
199,
3,
6602,
370,
3686,
1380,
10023,
367,
1350,
1584,
14,
199,
5473,
63,
7435,
275,
4044,
1506,
418,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
849,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
1050,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
1050,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2498,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
3413,
1080,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
1666,
314,
3794,
367,
199,
3,
282,
769,
402,
6762,
17915,
14,
199,
1360,
63,
7915,
275,
283,
885,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
3517,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
3517,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
3517,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
3517,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
3517,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370,
675,
465,
29139,
402,
314,
199,
3,
9149,
14,
221,
961,
570,
1077,
506,
282,
5417,
7016,
570,
17048,
12802,
9,
3769,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Sarah-Alsinan/muypicky
|
lib/python3.6/site-packages/django/views/generic/base.py
|
115
|
7583
|
from __future__ import unicode_literals
import logging
from functools import update_wrapper
from django import http
from django.core.exceptions import ImproperlyConfigured
from django.template.response import TemplateResponse
from django.urls import NoReverseMatch, reverse
from django.utils import six
from django.utils.decorators import classonlymethod
logger = logging.getLogger('django.request')
class ContextMixin(object):
"""
A default context mixin that passes the keyword arguments received by
get_context_data as the template context.
"""
def get_context_data(self, **kwargs):
if 'view' not in kwargs:
kwargs['view'] = self
return kwargs
class View(object):
"""
Intentionally simple parent class for all views. Only implements
dispatch-by-method and simple sanity checking.
"""
http_method_names = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace']
def __init__(self, **kwargs):
"""
Constructor. Called in the URLconf; can contain helpful extra
keyword arguments, and other things.
"""
# Go through keyword arguments, and either save their values to our
# instance, or raise an error.
for key, value in six.iteritems(kwargs):
setattr(self, key, value)
@classonlymethod
def as_view(cls, **initkwargs):
"""
Main entry point for a request-response process.
"""
for key in initkwargs:
if key in cls.http_method_names:
raise TypeError("You tried to pass in the %s method name as a "
"keyword argument to %s(). Don't do that."
% (key, cls.__name__))
if not hasattr(cls, key):
raise TypeError("%s() received an invalid keyword %r. as_view "
"only accepts arguments that are already "
"attributes of the class." % (cls.__name__, key))
def view(request, *args, **kwargs):
self = cls(**initkwargs)
if hasattr(self, 'get') and not hasattr(self, 'head'):
self.head = self.get
self.request = request
self.args = args
self.kwargs = kwargs
return self.dispatch(request, *args, **kwargs)
view.view_class = cls
view.view_initkwargs = initkwargs
# take name and docstring from class
update_wrapper(view, cls, updated=())
# and possible attributes set by decorators
# like csrf_exempt from dispatch
update_wrapper(view, cls.dispatch, assigned=())
return view
def dispatch(self, request, *args, **kwargs):
# Try to dispatch to the right method; if a method doesn't exist,
# defer to the error handler. Also defer to the error handler if the
# request method isn't on the approved list.
if request.method.lower() in self.http_method_names:
handler = getattr(self, request.method.lower(), self.http_method_not_allowed)
else:
handler = self.http_method_not_allowed
return handler(request, *args, **kwargs)
def http_method_not_allowed(self, request, *args, **kwargs):
logger.warning(
'Method Not Allowed (%s): %s', request.method, request.path,
extra={'status_code': 405, 'request': request}
)
return http.HttpResponseNotAllowed(self._allowed_methods())
def options(self, request, *args, **kwargs):
"""
Handles responding to requests for the OPTIONS HTTP verb.
"""
response = http.HttpResponse()
response['Allow'] = ', '.join(self._allowed_methods())
response['Content-Length'] = '0'
return response
def _allowed_methods(self):
return [m.upper() for m in self.http_method_names if hasattr(self, m)]
class TemplateResponseMixin(object):
"""
A mixin that can be used to render a template.
"""
template_name = None
template_engine = None
response_class = TemplateResponse
content_type = None
def render_to_response(self, context, **response_kwargs):
"""
Returns a response, using the `response_class` for this
view, with a template rendered with the given context.
If any keyword arguments are provided, they will be
passed to the constructor of the response class.
"""
response_kwargs.setdefault('content_type', self.content_type)
return self.response_class(
request=self.request,
template=self.get_template_names(),
context=context,
using=self.template_engine,
**response_kwargs
)
def get_template_names(self):
"""
Returns a list of template names to be used for the request. Must return
a list. May not be called if render_to_response is overridden.
"""
if self.template_name is None:
raise ImproperlyConfigured(
"TemplateResponseMixin requires either a definition of "
"'template_name' or an implementation of 'get_template_names()'")
else:
return [self.template_name]
class TemplateView(TemplateResponseMixin, ContextMixin, View):
"""
A view that renders a template. This view will also pass into the context
any keyword arguments passed by the URLconf.
"""
def get(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
return self.render_to_response(context)
class RedirectView(View):
"""
A view that provides a redirect on any GET request.
"""
permanent = False
url = None
pattern_name = None
query_string = False
def get_redirect_url(self, *args, **kwargs):
"""
Return the URL redirect to. Keyword arguments from the
URL pattern match generating the redirect request
are provided as kwargs to this method.
"""
if self.url:
url = self.url % kwargs
elif self.pattern_name:
try:
url = reverse(self.pattern_name, args=args, kwargs=kwargs)
except NoReverseMatch:
return None
else:
return None
args = self.request.META.get('QUERY_STRING', '')
if args and self.query_string:
url = "%s?%s" % (url, args)
return url
def get(self, request, *args, **kwargs):
url = self.get_redirect_url(*args, **kwargs)
if url:
if self.permanent:
return http.HttpResponsePermanentRedirect(url)
else:
return http.HttpResponseRedirect(url)
else:
logger.warning(
'Gone: %s', request.path,
extra={'status_code': 410, 'request': request}
)
return http.HttpResponseGone()
def head(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)
def options(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)
def delete(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)
def put(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)
def patch(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)
|
mit
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2050,
199,
504,
9143,
492,
1678,
63,
5029,
199,
199,
504,
1639,
492,
1455,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1160,
14,
1310,
492,
29264,
199,
504,
1639,
14,
3603,
492,
32036,
12,
3837,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1021,
2118,
765,
199,
199,
2921,
275,
2050,
14,
5572,
360,
1176,
14,
1069,
358,
421,
199,
533,
9470,
4256,
8,
785,
304,
272,
408,
272,
437,
849,
1067,
20048,
626,
14933,
314,
4252,
2368,
3086,
701,
272,
664,
63,
1100,
63,
576,
465,
314,
1978,
1067,
14,
272,
408,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
340,
283,
1345,
7,
440,
315,
2074,
26,
288,
2074,
459,
1345,
418,
275,
291,
267,
372,
2074,
421,
199,
533,
10935,
8,
785,
304,
272,
408,
272,
1010,
9553,
1183,
3486,
1676,
1021,
367,
1006,
6858,
14,
5972,
9031,
272,
7634,
13,
991,
13,
765,
436,
3486,
16740,
7907,
14,
272,
408,
339,
1455,
63,
765,
63,
1247,
275,
788,
362,
297,
283,
1932,
297,
283,
524,
297,
283,
2068,
297,
283,
1807,
297,
283,
2993,
297,
283,
1419,
297,
283,
3446,
418,
339,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
408,
267,
20297,
14,
12295,
315,
314,
2851,
2190,
27,
883,
1395,
24606,
2402,
267,
4252,
2368,
12,
436,
1163,
7645,
14,
267,
408,
267,
327,
3971,
4012,
4252,
2368,
12,
436,
1902,
3354,
3932,
1338,
370,
4154,
267,
327,
1256,
12,
503,
746,
376,
1125,
14,
267,
367,
790,
12,
574,
315,
3816,
14,
4611,
8,
958,
304,
288,
5371,
8,
277,
12,
790,
12,
574,
9,
339,
768,
533,
2118,
765,
272,
347,
465,
63,
1345,
8,
1886,
12,
1011,
826,
958,
304,
267,
408,
267,
11298,
2397,
2376,
367,
282,
1056,
13,
1310,
2112,
14,
267,
408,
267,
367,
790,
315,
4205,
958,
26,
288,
340,
790,
315,
843,
14,
1014,
63,
765,
63,
1247,
26,
355,
746,
3146,
480,
5556,
16416,
370,
986,
315,
314,
450,
83,
1083,
536,
465,
282,
298,
1816,
298,
6691,
1423,
370,
450,
83,
1252,
7529,
1133,
886,
626,
2122,
1816,
450,
334,
498,
12,
843,
855,
354,
8964,
288,
340,
440,
2688,
8,
1886,
12,
790,
304,
355,
746,
3146,
3647,
83,
342,
3086,
376,
3866,
4252,
450,
82,
14,
465,
63,
1345,
298,
1816,
298,
2118,
11479,
2368,
626,
787,
2575,
298,
1816,
298,
2987,
402,
314,
1021,
2122,
450,
334,
1886,
855,
354,
3108,
790,
430,
398,
347,
2455,
8,
1069,
12,
627,
589,
12,
1011,
958,
304,
288,
291,
275,
843,
3682,
826,
958,
9,
288,
340,
2688,
8,
277,
12,
283,
362,
358,
436,
440,
2688,
8,
277,
12,
283,
2993,
735,
355,
291,
14,
2993,
275,
291,
14,
362,
288,
291,
14,
1069,
275,
1056,
288,
291,
14,
589,
275,
1249,
288,
291,
14,
958,
275,
2074,
288,
372,
291,
14,
6052,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
267,
2455,
14,
1345,
63,
533,
275,
843,
267,
2455,
14,
1345,
63,
826,
958,
275,
4205,
958,
398,
327,
5452,
536,
436,
9214,
687,
1021,
267,
1678,
63,
5029,
8,
1345,
12,
843,
12,
4588,
29,
1012,
398,
327,
436,
3962,
3004,
663,
701,
20419,
267,
327,
2839,
19213,
63,
25254,
687,
7634,
267,
1678,
63,
5029,
8,
1345,
12,
843,
14,
6052,
12,
7943,
29,
1012,
267,
372,
2455,
339,
347,
7634,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
327,
7649,
370,
7634,
370,
314,
2451,
1083,
27,
340,
282,
1083,
3181,
1133,
2187,
12,
267,
327,
10133,
370,
314,
1125,
3016,
14,
6121,
10133,
370,
314,
1125,
3016,
340,
314,
267,
327,
1056,
1083,
5712,
1133,
641,
314,
30055,
769,
14,
267,
340,
1056,
14,
765,
14,
2325,
342,
315,
291,
14,
1014,
63,
765,
63,
1247,
26,
288,
3016,
275,
2519,
8,
277,
12,
1056,
14,
765,
14,
2325,
1062,
291,
14,
1014,
63,
765,
63,
1397,
63,
6541,
9,
267,
587,
26,
288,
3016,
275,
291,
14,
1014,
63,
765,
63,
1397,
63,
6541,
267,
372,
3016,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
1455,
63,
765,
63,
1397,
63,
6541,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
2512,
14,
3764,
8,
288,
283,
3767,
2832,
27301,
4366,
83,
304,
450,
83,
297,
1056,
14,
765,
12,
1056,
14,
515,
12,
288,
2402,
3713,
1205,
63,
600,
356,
25766,
12,
283,
1069,
356,
1056,
93,
267,
776,
267,
372,
1455,
14,
16287,
29967,
8,
277,
423,
6541,
63,
2474,
1012,
339,
347,
1511,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
267,
23873,
9163,
1098,
370,
4145,
367,
314,
23860,
3101,
16041,
14,
267,
408,
267,
1177,
275,
1455,
14,
16287,
342,
267,
1177,
459,
7852,
418,
275,
1656,
1987,
904,
8,
277,
423,
6541,
63,
2474,
1012,
267,
1177,
459,
2714,
13,
4625,
418,
275,
283,
16,
7,
267,
372,
1177,
339,
347,
485,
6541,
63,
2474,
8,
277,
304,
267,
372,
359,
77,
14,
4142,
342,
367,
333,
315,
291,
14,
1014,
63,
765,
63,
1247,
340,
2688,
8,
277,
12,
333,
1874,
421,
199,
533,
29264,
4256,
8,
785,
304,
272,
408,
272,
437,
20048,
626,
883,
506,
1202,
370,
3795,
282,
1978,
14,
272,
408,
272,
1978,
63,
354,
275,
488,
272,
1978,
63,
3908,
275,
488,
272,
1177,
63,
533,
275,
29264,
272,
1564,
63,
466,
275,
488,
339,
347,
3795,
63,
475,
63,
1310,
8,
277,
12,
1067,
12,
1011,
1310,
63,
958,
304,
267,
408,
267,
1803,
282,
1177,
12,
1808,
314,
658,
1310,
63,
533,
64,
367,
642,
267,
2455,
12,
543,
282,
1978,
8018,
543,
314,
1627,
1067,
14,
398,
982,
1263,
4252,
2368,
787,
2741,
12,
2985,
911,
506,
267,
3032,
370,
314,
3787,
402,
314,
1177,
1021,
14,
267,
408,
267,
1177,
63,
958,
14,
5486,
360,
1317,
63,
466,
297,
291,
14,
1317,
63,
466,
9,
267,
372,
291,
14,
1310,
63,
533,
8,
288,
1056
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2050,
199,
504,
9143,
492,
1678,
63,
5029,
199,
199,
504,
1639,
492,
1455,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1160,
14,
1310,
492,
29264,
199,
504,
1639,
14,
3603,
492,
32036,
12,
3837,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1021,
2118,
765,
199,
199,
2921,
275,
2050,
14,
5572,
360,
1176,
14,
1069,
358,
421,
199,
533,
9470,
4256,
8,
785,
304,
272,
408,
272,
437,
849,
1067,
20048,
626,
14933,
314,
4252,
2368,
3086,
701,
272,
664,
63,
1100,
63,
576,
465,
314,
1978,
1067,
14,
272,
408,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
340,
283,
1345,
7,
440,
315,
2074,
26,
288,
2074,
459,
1345,
418,
275,
291,
267,
372,
2074,
421,
199,
533,
10935,
8,
785,
304,
272,
408,
272,
1010,
9553,
1183,
3486,
1676,
1021,
367,
1006,
6858,
14,
5972,
9031,
272,
7634,
13,
991,
13,
765,
436,
3486,
16740,
7907,
14,
272,
408,
339,
1455,
63,
765,
63,
1247,
275,
788,
362,
297,
283,
1932,
297,
283,
524,
297,
283,
2068,
297,
283,
1807,
297,
283,
2993,
297,
283,
1419,
297,
283,
3446,
418,
339,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
408,
267,
20297,
14,
12295,
315,
314,
2851,
2190,
27,
883,
1395,
24606,
2402,
267,
4252,
2368,
12,
436,
1163,
7645,
14,
267,
408,
267,
327,
3971,
4012,
4252,
2368,
12,
436,
1902,
3354,
3932,
1338,
370,
4154,
267,
327,
1256,
12,
503,
746,
376,
1125,
14,
267,
367,
790,
12,
574,
315,
3816,
14,
4611,
8,
958,
304,
288,
5371,
8,
277,
12,
790,
12,
574,
9,
339,
768,
533,
2118,
765,
272,
347,
465,
63,
1345,
8,
1886,
12,
1011,
826,
958,
304,
267,
408,
267,
11298,
2397,
2376,
367,
282,
1056,
13,
1310,
2112,
14,
267,
408,
267,
367,
790,
315,
4205,
958,
26,
288,
340,
790,
315,
843,
14,
1014,
63,
765,
63,
1247,
26,
355,
746,
3146,
480,
5556,
16416,
370,
986,
315,
314,
450,
83,
1083,
536,
465,
282,
298,
1816,
298,
6691,
1423,
370,
450,
83,
1252,
7529,
1133,
886,
626,
2122,
1816,
450,
334,
498,
12,
843,
855,
354,
8964,
288,
340,
440,
2688,
8,
1886,
12,
790,
304,
355,
746,
3146,
3647,
83,
342,
3086,
376,
3866,
4252,
450,
82,
14,
465,
63,
1345,
298,
1816,
298,
2118,
11479,
2368,
626,
787,
2575,
298,
1816,
298,
2987,
402,
314,
1021,
2122,
450,
334,
1886,
855,
354,
3108,
790,
430,
398,
347,
2455,
8,
1069,
12,
627,
589,
12,
1011,
958,
304,
288,
291,
275,
843,
3682,
826,
958,
9,
288,
340,
2688,
8,
277,
12,
283,
362,
358,
436,
440,
2688,
8,
277,
12,
283,
2993,
735,
355,
291,
14,
2993,
275,
291,
14,
362,
288,
291,
14,
1069,
275,
1056,
288,
291,
14,
589,
275,
1249,
288,
291,
14,
958,
275,
2074,
288,
372,
291,
14,
6052,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
267,
2455,
14,
1345,
63,
533,
275,
843,
267,
2455,
14,
1345,
63,
826,
958,
275,
4205,
958,
398,
327,
5452,
536,
436,
9214,
687,
1021,
267,
1678,
63,
5029,
8,
1345,
12,
843,
12,
4588,
29,
1012,
398,
327,
436,
3962,
3004,
663,
701,
20419,
267,
327,
2839,
19213,
63,
25254,
687,
7634,
267,
1678,
63,
5029,
8,
1345,
12,
843,
14,
6052,
12,
7943,
29,
1012,
267,
372,
2455,
339,
347,
7634,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
327,
7649,
370,
7634,
370,
314,
2451,
1083,
27,
340,
282,
1083,
3181,
1133,
2187,
12,
267,
327,
10133,
370,
314,
1125,
3016,
14,
6121,
10133,
370,
314,
1125,
3016,
340,
314,
267,
327,
1056,
1083,
5712,
1133,
641,
314,
30055,
769,
14,
267,
340,
1056,
14,
765,
14,
2325,
342,
315,
291,
14,
1014,
63,
765,
63,
1247,
26,
288,
3016,
275,
2519,
8,
277,
12,
1056,
14,
765,
14,
2325,
1062,
291,
14,
1014,
63,
765,
63,
1397,
63,
6541,
9,
267,
587,
26,
288,
3016,
275,
291,
14,
1014,
63,
765,
63,
1397,
63,
6541,
267,
372,
3016,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
1455,
63,
765,
63,
1397,
63,
6541,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
2512,
14,
3764,
8,
288,
283,
3767,
2832,
27301,
4366,
83,
304,
450,
83,
297,
1056,
14,
765,
12,
1056,
14,
515,
12,
288,
2402,
3713,
1205,
63,
600,
356,
25766,
12,
283,
1069,
356,
1056,
93,
267,
776,
267,
372,
1455,
14,
16287,
29967,
8,
277,
423,
6541,
63,
2474,
1012,
339,
347,
1511,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
267,
23873,
9163,
1098,
370,
4145,
367,
314,
23860,
3101,
16041,
14,
267,
408,
267,
1177,
275,
1455,
14,
16287,
342,
267,
1177,
459,
7852,
418,
275,
1656,
1987,
904,
8,
277,
423,
6541,
63,
2474,
1012,
267,
1177,
459,
2714,
13,
4625,
418,
275,
283,
16,
7,
267,
372,
1177,
339,
347,
485,
6541,
63,
2474,
8,
277,
304,
267,
372,
359,
77,
14,
4142,
342,
367,
333,
315,
291,
14,
1014,
63,
765,
63,
1247,
340,
2688,
8,
277,
12,
333,
1874,
421,
199,
533,
29264,
4256,
8,
785,
304,
272,
408,
272,
437,
20048,
626,
883,
506,
1202,
370,
3795,
282,
1978,
14,
272,
408,
272,
1978,
63,
354,
275,
488,
272,
1978,
63,
3908,
275,
488,
272,
1177,
63,
533,
275,
29264,
272,
1564,
63,
466,
275,
488,
339,
347,
3795,
63,
475,
63,
1310,
8,
277,
12,
1067,
12,
1011,
1310,
63,
958,
304,
267,
408,
267,
1803,
282,
1177,
12,
1808,
314,
658,
1310,
63,
533,
64,
367,
642,
267,
2455,
12,
543,
282,
1978,
8018,
543,
314,
1627,
1067,
14,
398,
982,
1263,
4252,
2368,
787,
2741,
12,
2985,
911,
506,
267,
3032,
370,
314,
3787,
402,
314,
1177,
1021,
14,
267,
408,
267,
1177,
63,
958,
14,
5486,
360,
1317,
63,
466,
297,
291,
14,
1317,
63,
466,
9,
267,
372,
291,
14,
1310,
63,
533,
8,
288,
1056,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
zhouxiao-coder/Paddle
|
demo/gan/gan_conf_image.py
|
3
|
8238
|
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from paddle.trainer_config_helpers import *
mode = get_config_arg("mode", str, "generator")
dataSource = get_config_arg("data", str, "mnist")
assert mode in set([
"generator", "discriminator", "generator_training", "discriminator_training"
])
is_generator_training = mode == "generator_training"
is_discriminator_training = mode == "discriminator_training"
is_generator = mode == "generator"
is_discriminator = mode == "discriminator"
# The network structure below follows the dcgan paper
# (https://arxiv.org/abs/1511.06434)
print('mode=%s' % mode)
# the dim of the noise (z) as the input of the generator network
noise_dim = 100
# the number of filters in the layer in generator/discriminator that is
# closet to the image
gf_dim = 64
df_dim = 64
if dataSource == "mnist":
sample_dim = 28 # image dim
c_dim = 1 # image color
else:
sample_dim = 32
c_dim = 3
s2, s4 = int(sample_dim / 2), int(sample_dim / 4),
s8, s16 = int(sample_dim / 8), int(sample_dim / 16)
settings(
batch_size=128,
learning_rate=2e-4,
learning_method=AdamOptimizer(beta1=0.5))
def conv_bn(input,
channels,
imgSize,
num_filters,
output_x,
stride,
name,
param_attr,
bias_attr,
param_attr_bn,
bn,
trans=False,
act=ReluActivation()):
"""
conv_bn is a utility function that constructs a convolution/deconv layer
with an optional batch_norm layer
:param bn: whether to use batch_norm_layer
:type bn: bool
:param trans: whether to use conv (False) or deconv (True)
:type trans: bool
"""
# calculate the filter_size and padding size based on the given
# imgSize and ouput size
tmp = imgSize - (output_x - 1) * stride
if tmp <= 1 or tmp > 5:
raise ValueError("conv input-output dimension does not fit")
elif tmp <= 3:
filter_size = tmp + 2
padding = 1
else:
filter_size = tmp
padding = 0
print(imgSize, output_x, stride, filter_size, padding)
if trans:
nameApx = "_conv"
else:
nameApx = "_convt"
if bn:
conv = img_conv_layer(
input,
filter_size=filter_size,
num_filters=num_filters,
name=name + nameApx,
num_channels=channels,
act=LinearActivation(),
groups=1,
stride=stride,
padding=padding,
bias_attr=bias_attr,
param_attr=param_attr,
shared_biases=True,
layer_attr=None,
filter_size_y=None,
stride_y=None,
padding_y=None,
trans=trans)
conv_bn = batch_norm_layer(
conv,
act=act,
name=name + nameApx + "_bn",
bias_attr=bias_attr,
param_attr=param_attr_bn,
use_global_stats=False)
return conv_bn
else:
conv = img_conv_layer(
input,
filter_size=filter_size,
num_filters=num_filters,
name=name + nameApx,
num_channels=channels,
act=act,
groups=1,
stride=stride,
padding=padding,
bias_attr=bias_attr,
param_attr=param_attr,
shared_biases=True,
layer_attr=None,
filter_size_y=None,
stride_y=None,
padding_y=None,
trans=trans)
return conv
def generator(noise):
"""
generator generates a sample given noise
"""
param_attr = ParamAttr(
is_static=is_discriminator_training, initial_mean=0.0, initial_std=0.02)
bias_attr = ParamAttr(
is_static=is_discriminator_training, initial_mean=0.0, initial_std=0.0)
param_attr_bn = ParamAttr(
is_static=is_discriminator_training, initial_mean=1.0, initial_std=0.02)
h1 = fc_layer(
input=noise,
name="gen_layer_h1",
size=s8 * s8 * gf_dim * 4,
bias_attr=bias_attr,
param_attr=param_attr,
act=LinearActivation())
h1_bn = batch_norm_layer(
h1,
act=ReluActivation(),
name="gen_layer_h1_bn",
bias_attr=bias_attr,
param_attr=param_attr_bn,
use_global_stats=False)
h2_bn = conv_bn(
h1_bn,
channels=gf_dim * 4,
output_x=s8,
num_filters=gf_dim * 2,
imgSize=s4,
stride=2,
name="gen_layer_h2",
param_attr=param_attr,
bias_attr=bias_attr,
param_attr_bn=param_attr_bn,
bn=True,
trans=True)
h3_bn = conv_bn(
h2_bn,
channels=gf_dim * 2,
output_x=s4,
num_filters=gf_dim,
imgSize=s2,
stride=2,
name="gen_layer_h3",
param_attr=param_attr,
bias_attr=bias_attr,
param_attr_bn=param_attr_bn,
bn=True,
trans=True)
return conv_bn(
h3_bn,
channels=gf_dim,
output_x=s2,
num_filters=c_dim,
imgSize=sample_dim,
stride=2,
name="gen_layer_h4",
param_attr=param_attr,
bias_attr=bias_attr,
param_attr_bn=param_attr_bn,
bn=False,
trans=True,
act=TanhActivation())
def discriminator(sample):
"""
discriminator ouputs the probablity of a sample is from generator
or real data.
The output has two dimenstional: dimension 0 is the probablity
of the sample is from generator and dimension 1 is the probabblity
of the sample is from real data.
"""
param_attr = ParamAttr(
is_static=is_generator_training, initial_mean=0.0, initial_std=0.02)
bias_attr = ParamAttr(
is_static=is_generator_training, initial_mean=0.0, initial_std=0.0)
param_attr_bn = ParamAttr(
is_static=is_generator_training, initial_mean=1.0, initial_std=0.02)
h0 = conv_bn(
sample,
channels=c_dim,
imgSize=sample_dim,
num_filters=df_dim,
output_x=s2,
stride=2,
name="dis_h0",
param_attr=param_attr,
bias_attr=bias_attr,
param_attr_bn=param_attr_bn,
bn=False)
h1_bn = conv_bn(
h0,
channels=df_dim,
imgSize=s2,
num_filters=df_dim * 2,
output_x=s4,
stride=2,
name="dis_h1",
param_attr=param_attr,
bias_attr=bias_attr,
param_attr_bn=param_attr_bn,
bn=True)
h2_bn = conv_bn(
h1_bn,
channels=df_dim * 2,
imgSize=s4,
num_filters=df_dim * 4,
output_x=s8,
stride=2,
name="dis_h2",
param_attr=param_attr,
bias_attr=bias_attr,
param_attr_bn=param_attr_bn,
bn=True)
return fc_layer(
input=h2_bn,
name="dis_prob",
size=2,
bias_attr=bias_attr,
param_attr=param_attr,
act=SoftmaxActivation())
if is_generator_training:
noise = data_layer(name="noise", size=noise_dim)
sample = generator(noise)
if is_discriminator_training:
sample = data_layer(name="sample", size=sample_dim * sample_dim * c_dim)
if is_generator_training or is_discriminator_training:
label = data_layer(name="label", size=1)
prob = discriminator(sample)
cost = cross_entropy(input=prob, label=label)
classification_error_evaluator(
input=prob, label=label, name=mode + '_error')
outputs(cost)
if is_generator:
noise = data_layer(name="noise", size=noise_dim)
outputs(generator(noise))
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
7800,
510,
20101,
48,
20101,
6642,
14,
2900,
5924,
5702,
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,
504,
28525,
14,
2834,
281,
63,
888,
63,
7546,
492,
627,
199,
199,
632,
275,
664,
63,
888,
63,
1273,
480,
632,
401,
620,
12,
298,
4679,
531,
199,
576,
2980,
275,
664,
63,
888,
63,
1273,
480,
576,
401,
620,
12,
298,
32164,
531,
199,
479,
818,
315,
663,
779,
272,
298,
4679,
401,
298,
328,
24565,
401,
298,
4679,
63,
7588,
401,
298,
328,
24565,
63,
7588,
2,
199,
566,
199,
199,
374,
63,
4679,
63,
7588,
275,
818,
508,
298,
4679,
63,
7588,
2,
199,
374,
63,
328,
24565,
63,
7588,
275,
818,
508,
298,
328,
24565,
63,
7588,
2,
199,
374,
63,
4679,
275,
818,
508,
298,
4679,
2,
199,
374,
63,
328,
24565,
275,
818,
508,
298,
328,
24565,
2,
199,
199,
3,
710,
2784,
5523,
5084,
11924,
314,
12326,
24975,
15220,
221,
199,
3,
334,
2859,
921,
27290,
14,
1308,
15,
2101,
15,
1046,
845,
14,
17010,
1082,
9,
199,
199,
1361,
360,
632,
2458,
83,
7,
450,
818,
9,
199,
3,
314,
8134,
402,
314,
11145,
334,
90,
9,
465,
314,
1324,
402,
314,
4306,
2784,
199,
11838,
63,
3572,
275,
2948,
199,
3,
314,
1329,
402,
4766,
315,
314,
4045,
315,
4306,
15,
328,
24565,
626,
365,
221,
199,
3,
2463,
409,
370,
314,
1834,
199,
7102,
63,
3572,
275,
5049,
199,
1587,
63,
3572,
275,
5049,
199,
692,
666,
2980,
508,
298,
32164,
582,
272,
2690,
63,
3572,
275,
7294,
221,
327,
1834,
8134,
272,
286,
63,
3572,
275,
413,
221,
327,
1834,
3164,
199,
2836,
26,
272,
2690,
63,
3572,
275,
4337,
272,
286,
63,
3572,
275,
650,
199,
83,
18,
12,
308,
20,
275,
1109,
8,
3271,
63,
3572,
1182,
499,
395,
1109,
8,
3271,
63,
3572,
1182,
841,
395,
199,
83,
24,
12,
308,
975,
275,
1109,
8,
3271,
63,
3572,
1182,
1695,
395,
1109,
8,
3271,
63,
3572,
1182,
3193,
9,
199,
199,
1751,
8,
272,
3522,
63,
890,
29,
3933,
12,
272,
9328,
63,
1866,
29,
18,
69,
13,
20,
12,
272,
9328,
63,
765,
29,
32408,
13946,
8,
5683,
17,
29,
16,
14,
21,
430,
421,
199,
318,
8260,
63,
10472,
8,
1210,
12,
288,
9245,
12,
288,
6050,
2320,
12,
288,
1967,
63,
4273,
12,
288,
1072,
63,
88,
12,
288,
7345,
12,
288,
536,
12,
288,
1215,
63,
962,
12,
288,
10671,
63,
962,
12,
288,
1215,
63,
962,
63,
10472,
12,
288,
21847,
12,
288,
1752,
29,
797,
12,
288,
2454,
29,
5640,
85,
19535,
5109,
272,
408,
272,
8260,
63,
10472,
365,
282,
11420,
805,
626,
21638,
282,
17461,
15,
271,
5598,
4045,
5591,
543,
376,
2716,
3522,
63,
4791,
4045,
339,
520,
635,
21847,
26,
3775,
370,
675,
3522,
63,
4791,
63,
1897,
272,
520,
466,
21847,
26,
2155,
272,
520,
635,
1752,
26,
3775,
370,
675,
8260,
334,
797,
9,
503,
477,
5598,
334,
549,
9,
272,
520,
466,
1752,
26,
2155,
272,
408,
339,
327,
8671,
314,
2457,
63,
890,
436,
6273,
1568,
4079,
641,
314,
1627,
272,
327,
6050,
2320,
436,
312,
384,
337,
1568,
272,
3529,
275,
6050,
2320,
446,
334,
1199,
63,
88,
446,
413,
9,
627,
7345,
272,
340,
3529,
2695,
413,
503,
3529,
690,
959,
26,
267,
746,
1722,
480,
5598,
1324,
13,
1199,
6240,
1630,
440,
5542,
531,
272,
916,
3529,
2695,
650,
26,
267,
2457,
63,
890,
275,
3529,
435,
499,
267,
6273,
275,
413,
272,
587,
26,
267,
2457,
63,
890,
275,
3529,
267,
6273,
275,
378,
339,
870,
8,
4060,
2320,
12,
1072,
63,
88,
12,
7345,
12,
2457,
63,
890,
12,
6273,
9,
339,
340,
1752,
26,
267,
536,
33,
5326,
275,
2668,
5598,
2,
272,
587,
26,
267,
536,
33,
5326,
275,
2668,
5598,
84,
2,
339,
340,
21847,
26,
267,
8260,
275,
6050,
63,
5598,
63,
1897,
8,
288,
1324,
12,
288,
2457,
63,
890,
29,
1541,
63,
890,
12,
288,
1967,
63,
4273,
29,
1507,
63,
4273,
12,
288,
536,
29,
354,
435,
536,
33,
5326,
12,
288,
1967,
63,
6324,
29,
6324,
12,
288,
2454,
29,
10608,
19535,
1062,
288,
4652,
29,
17,
12,
288,
7345,
29,
12318,
12,
288,
6273,
29,
8358,
12,
288,
10671,
63,
962,
29,
8160,
63,
962,
12,
288,
1215,
63,
962,
29,
635,
63,
962,
12,
288,
5709,
63,
20948,
29,
549,
12,
288,
4045,
63,
962,
29,
403,
12,
288,
2457,
63,
890,
63,
89,
29,
403,
12,
288,
7345,
63,
89,
29,
403,
12,
288,
6273,
63,
89,
29,
403,
12,
288,
1752,
29,
1515,
9,
398,
8260,
63,
10472,
275,
3522,
63,
4791,
63,
1897,
8,
288,
8260,
12,
288,
2454,
29,
2442,
12,
288,
536,
29,
354,
435,
536,
33,
5326,
435,
2668,
10472,
401,
288,
10671,
63,
962,
29,
8160,
63,
962,
12,
288,
1215,
63,
962,
29,
635,
63,
962,
63,
10472,
12,
288,
675,
63,
2966,
63,
3200,
29,
797,
9,
398,
372,
8260,
63,
10472,
272,
587,
26,
267,
8260,
275,
6050,
63,
5598,
63,
1897,
8,
288,
1324,
12,
288,
2457,
63,
890,
29,
1541,
63,
890,
12,
288,
1967,
63,
4273,
29,
1507,
63,
4273,
12,
288,
536,
29,
354,
435,
536,
33,
5326,
12,
288,
1967,
63,
6324,
29,
6324,
12,
288,
2454,
29,
2442,
12,
288,
4652,
29,
17,
12,
288,
7345,
29
] |
[
1898,
334,
67,
9,
7800,
510,
20101,
48,
20101,
6642,
14,
2900,
5924,
5702,
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,
504,
28525,
14,
2834,
281,
63,
888,
63,
7546,
492,
627,
199,
199,
632,
275,
664,
63,
888,
63,
1273,
480,
632,
401,
620,
12,
298,
4679,
531,
199,
576,
2980,
275,
664,
63,
888,
63,
1273,
480,
576,
401,
620,
12,
298,
32164,
531,
199,
479,
818,
315,
663,
779,
272,
298,
4679,
401,
298,
328,
24565,
401,
298,
4679,
63,
7588,
401,
298,
328,
24565,
63,
7588,
2,
199,
566,
199,
199,
374,
63,
4679,
63,
7588,
275,
818,
508,
298,
4679,
63,
7588,
2,
199,
374,
63,
328,
24565,
63,
7588,
275,
818,
508,
298,
328,
24565,
63,
7588,
2,
199,
374,
63,
4679,
275,
818,
508,
298,
4679,
2,
199,
374,
63,
328,
24565,
275,
818,
508,
298,
328,
24565,
2,
199,
199,
3,
710,
2784,
5523,
5084,
11924,
314,
12326,
24975,
15220,
221,
199,
3,
334,
2859,
921,
27290,
14,
1308,
15,
2101,
15,
1046,
845,
14,
17010,
1082,
9,
199,
199,
1361,
360,
632,
2458,
83,
7,
450,
818,
9,
199,
3,
314,
8134,
402,
314,
11145,
334,
90,
9,
465,
314,
1324,
402,
314,
4306,
2784,
199,
11838,
63,
3572,
275,
2948,
199,
3,
314,
1329,
402,
4766,
315,
314,
4045,
315,
4306,
15,
328,
24565,
626,
365,
221,
199,
3,
2463,
409,
370,
314,
1834,
199,
7102,
63,
3572,
275,
5049,
199,
1587,
63,
3572,
275,
5049,
199,
692,
666,
2980,
508,
298,
32164,
582,
272,
2690,
63,
3572,
275,
7294,
221,
327,
1834,
8134,
272,
286,
63,
3572,
275,
413,
221,
327,
1834,
3164,
199,
2836,
26,
272,
2690,
63,
3572,
275,
4337,
272,
286,
63,
3572,
275,
650,
199,
83,
18,
12,
308,
20,
275,
1109,
8,
3271,
63,
3572,
1182,
499,
395,
1109,
8,
3271,
63,
3572,
1182,
841,
395,
199,
83,
24,
12,
308,
975,
275,
1109,
8,
3271,
63,
3572,
1182,
1695,
395,
1109,
8,
3271,
63,
3572,
1182,
3193,
9,
199,
199,
1751,
8,
272,
3522,
63,
890,
29,
3933,
12,
272,
9328,
63,
1866,
29,
18,
69,
13,
20,
12,
272,
9328,
63,
765,
29,
32408,
13946,
8,
5683,
17,
29,
16,
14,
21,
430,
421,
199,
318,
8260,
63,
10472,
8,
1210,
12,
288,
9245,
12,
288,
6050,
2320,
12,
288,
1967,
63,
4273,
12,
288,
1072,
63,
88,
12,
288,
7345,
12,
288,
536,
12,
288,
1215,
63,
962,
12,
288,
10671,
63,
962,
12,
288,
1215,
63,
962,
63,
10472,
12,
288,
21847,
12,
288,
1752,
29,
797,
12,
288,
2454,
29,
5640,
85,
19535,
5109,
272,
408,
272,
8260,
63,
10472,
365,
282,
11420,
805,
626,
21638,
282,
17461,
15,
271,
5598,
4045,
5591,
543,
376,
2716,
3522,
63,
4791,
4045,
339,
520,
635,
21847,
26,
3775,
370,
675,
3522,
63,
4791,
63,
1897,
272,
520,
466,
21847,
26,
2155,
272,
520,
635,
1752,
26,
3775,
370,
675,
8260,
334,
797,
9,
503,
477,
5598,
334,
549,
9,
272,
520,
466,
1752,
26,
2155,
272,
408,
339,
327,
8671,
314,
2457,
63,
890,
436,
6273,
1568,
4079,
641,
314,
1627,
272,
327,
6050,
2320,
436,
312,
384,
337,
1568,
272,
3529,
275,
6050,
2320,
446,
334,
1199,
63,
88,
446,
413,
9,
627,
7345,
272,
340,
3529,
2695,
413,
503,
3529,
690,
959,
26,
267,
746,
1722,
480,
5598,
1324,
13,
1199,
6240,
1630,
440,
5542,
531,
272,
916,
3529,
2695,
650,
26,
267,
2457,
63,
890,
275,
3529,
435,
499,
267,
6273,
275,
413,
272,
587,
26,
267,
2457,
63,
890,
275,
3529,
267,
6273,
275,
378,
339,
870,
8,
4060,
2320,
12,
1072,
63,
88,
12,
7345,
12,
2457,
63,
890,
12,
6273,
9,
339,
340,
1752,
26,
267,
536,
33,
5326,
275,
2668,
5598,
2,
272,
587,
26,
267,
536,
33,
5326,
275,
2668,
5598,
84,
2,
339,
340,
21847,
26,
267,
8260,
275,
6050,
63,
5598,
63,
1897,
8,
288,
1324,
12,
288,
2457,
63,
890,
29,
1541,
63,
890,
12,
288,
1967,
63,
4273,
29,
1507,
63,
4273,
12,
288,
536,
29,
354,
435,
536,
33,
5326,
12,
288,
1967,
63,
6324,
29,
6324,
12,
288,
2454,
29,
10608,
19535,
1062,
288,
4652,
29,
17,
12,
288,
7345,
29,
12318,
12,
288,
6273,
29,
8358,
12,
288,
10671,
63,
962,
29,
8160,
63,
962,
12,
288,
1215,
63,
962,
29,
635,
63,
962,
12,
288,
5709,
63,
20948,
29,
549,
12,
288,
4045,
63,
962,
29,
403,
12,
288,
2457,
63,
890,
63,
89,
29,
403,
12,
288,
7345,
63,
89,
29,
403,
12,
288,
6273,
63,
89,
29,
403,
12,
288,
1752,
29,
1515,
9,
398,
8260,
63,
10472,
275,
3522,
63,
4791,
63,
1897,
8,
288,
8260,
12,
288,
2454,
29,
2442,
12,
288,
536,
29,
354,
435,
536,
33,
5326,
435,
2668,
10472,
401,
288,
10671,
63,
962,
29,
8160,
63,
962,
12,
288,
1215,
63,
962,
29,
635,
63,
962,
63,
10472,
12,
288,
675,
63,
2966,
63,
3200,
29,
797,
9,
398,
372,
8260,
63,
10472,
272,
587,
26,
267,
8260,
275,
6050,
63,
5598,
63,
1897,
8,
288,
1324,
12,
288,
2457,
63,
890,
29,
1541,
63,
890,
12,
288,
1967,
63,
4273,
29,
1507,
63,
4273,
12,
288,
536,
29,
354,
435,
536,
33,
5326,
12,
288,
1967,
63,
6324,
29,
6324,
12,
288,
2454,
29,
2442,
12,
288,
4652,
29,
17,
12,
288,
7345,
29,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
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ython3.1.1-20150328-091302/Lib/multiprocessing/process.py
|
694
|
2304
|
#
# Module providing the `Process` class which emulates `threading.Thread`
#
# multiprocessing/process.py
#
# Copyright (c) 2006-2008, R Oudkerk
# Licensed to PSF under a Contributor Agreement.
#
__all__ = ['Process', 'current_process', 'active_children']
#
# Imports
#
import os
import sys
import signal
import itertools
from _weakrefset import WeakSet
#for brython
from _multiprocessing import Process
#
#
#
try:
ORIGINAL_DIR = os.path.abspath(os.getcwd())
except OSError:
ORIGINAL_DIR = None
#
# Public functions
#
def current_process():
'''
Return process object representing the current process
'''
return _current_process
def active_children():
'''
Return list of process objects corresponding to live child processes
'''
_cleanup()
return list(_current_process._children)
#
#
#
def _cleanup():
# check for processes which have finished
for p in list(_current_process._children):
if p._popen.poll() is not None:
_current_process._children.discard(p)
#
# The `Process` class
#
# brython note: class Process is defined in /usr/libs/_multiprocessing.js
#
# We subclass bytes to avoid accidental transmission of auth keys over network
#
class AuthenticationString(bytes):
def __reduce__(self):
from .forking import Popen
if not Popen.thread_is_spawning():
raise TypeError(
'Pickling an AuthenticationString object is '
'disallowed for security reasons'
)
return AuthenticationString, (bytes(self),)
#
# Create object representing the main process
#
class _MainProcess(Process):
def __init__(self):
self._identity = ()
self._daemonic = False
self._name = 'MainProcess'
self._parent_pid = None
self._popen = None
self._counter = itertools.count(1)
self._children = set()
self._authkey = AuthenticationString(os.urandom(32))
self._tempdir = None
_current_process = _MainProcess()
del _MainProcess
#
# Give names to some return codes
#
_exitcode_to_name = {}
for name, signum in list(signal.__dict__.items()):
if name[:3]=='SIG' and '_' not in name:
_exitcode_to_name[-signum] = name
# For debug and leak testing
_dangling = WeakSet()
|
gpl-3.0
|
[
3,
199,
3,
5673,
13070,
314,
658,
3498,
64,
1021,
1314,
17423,
2335,
658,
12562,
14,
4436,
64,
199,
3,
199,
3,
12866,
15,
1412,
14,
647,
199,
3,
199,
3,
1898,
334,
67,
9,
8315,
13,
9300,
12,
820,
593,
1181,
2570,
75,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
3,
199,
199,
363,
452,
363,
275,
788,
3498,
297,
283,
1818,
63,
1412,
297,
283,
2682,
63,
3223,
418,
199,
199,
3,
199,
3,
24339,
199,
3,
199,
199,
646,
747,
199,
646,
984,
199,
646,
4673,
199,
646,
7975,
199,
504,
485,
21330,
409,
492,
28224,
1084,
199,
199,
3,
509,
330,
23196,
199,
504,
485,
25725,
492,
7132,
199,
3,
199,
3,
199,
3,
199,
199,
893,
26,
272,
1549,
1277,
13384,
63,
3022,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
9458,
1012,
199,
2590,
6440,
26,
272,
1549,
1277,
13384,
63,
3022,
275,
488,
199,
199,
3,
199,
3,
1684,
3423,
199,
3,
199,
199,
318,
1453,
63,
1412,
837,
272,
1449,
272,
1432,
2112,
909,
6144,
314,
1453,
2112,
272,
1449,
272,
372,
485,
1818,
63,
1412,
199,
199,
318,
4702,
63,
3223,
837,
272,
1449,
272,
1432,
769,
402,
2112,
2251,
5226,
370,
12166,
1982,
10358,
272,
1449,
272,
485,
7661,
342,
272,
372,
769,
1547,
1818,
63,
1412,
423,
3223,
9,
199,
199,
3,
199,
3,
199,
3,
199,
199,
318,
485,
7661,
837,
272,
327,
1104,
367,
10358,
1314,
1172,
9158,
272,
367,
299,
315,
769,
1547,
1818,
63,
1412,
423,
3223,
304,
267,
340,
299,
423,
12207,
14,
6843,
342,
365,
440,
488,
26,
288,
485,
1818,
63,
1412,
423,
3223,
14,
14394,
8,
80,
9,
199,
199,
3,
199,
3,
710,
658,
3498,
64,
1021,
199,
3,
199,
199,
3,
330,
23196,
5317,
26,
1021,
7132,
365,
3247,
315,
1182,
2647,
15,
8450,
15607,
25725,
14,
3596,
421,
199,
3,
199,
3,
2136,
5516,
2783,
370,
5126,
24634,
279,
1752,
2250,
402,
1790,
2883,
1806,
2784,
199,
3,
199,
199,
533,
15995,
1558,
8,
2394,
304,
272,
347,
636,
5270,
721,
277,
304,
267,
687,
1275,
11796,
316,
492,
13995,
267,
340,
440,
13995,
14,
2671,
63,
374,
63,
3770,
87,
1835,
837,
288,
746,
3146,
8,
355,
283,
8587,
2983,
376,
15995,
1558,
909,
365,
283,
355,
283,
2297,
6541,
367,
6391,
14872,
7,
355,
776,
267,
372,
15995,
1558,
12,
334,
2394,
8,
277,
16945,
199,
199,
3,
199,
3,
2790,
909,
6144,
314,
2446,
2112,
199,
3,
199,
199,
533,
485,
6756,
3498,
8,
3498,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
5582,
275,
6248,
267,
291,
423,
10824,
530,
275,
756,
267,
291,
423,
354,
275,
283,
6756,
3498,
7,
267,
291,
423,
1708,
63,
3150,
275,
488,
267,
291,
423,
12207,
275,
488,
267,
291,
423,
5337,
275,
7975,
14,
835,
8,
17,
9,
267,
291,
423,
3223,
275,
663,
342,
267,
291,
423,
1178,
498,
275,
15995,
1558,
8,
736,
14,
22776,
8,
708,
430,
267,
291,
423,
11567,
275,
488,
199,
199,
63,
1818,
63,
1412,
275,
485,
6756,
3498,
342,
199,
2264,
485,
6756,
3498,
199,
199,
3,
199,
3,
25495,
1561,
370,
2005,
372,
9479,
199,
3,
199,
199,
63,
2224,
600,
63,
475,
63,
354,
275,
1052,
199,
199,
509,
536,
12,
2070,
453,
315,
769,
8,
4653,
855,
807,
4343,
1744,
5109,
272,
340,
536,
1491,
19,
22954,
7864,
7,
436,
14135,
440,
315,
536,
26,
267,
485,
2224,
600,
63,
475,
63,
354,
1988,
1037,
453,
61,
275,
536,
199,
199,
3,
2104,
3105,
436,
25831,
5343,
199,
63,
68,
26896,
275,
28224,
1084,
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
] |
[
199,
3,
5673,
13070,
314,
658,
3498,
64,
1021,
1314,
17423,
2335,
658,
12562,
14,
4436,
64,
199,
3,
199,
3,
12866,
15,
1412,
14,
647,
199,
3,
199,
3,
1898,
334,
67,
9,
8315,
13,
9300,
12,
820,
593,
1181,
2570,
75,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
3,
199,
199,
363,
452,
363,
275,
788,
3498,
297,
283,
1818,
63,
1412,
297,
283,
2682,
63,
3223,
418,
199,
199,
3,
199,
3,
24339,
199,
3,
199,
199,
646,
747,
199,
646,
984,
199,
646,
4673,
199,
646,
7975,
199,
504,
485,
21330,
409,
492,
28224,
1084,
199,
199,
3,
509,
330,
23196,
199,
504,
485,
25725,
492,
7132,
199,
3,
199,
3,
199,
3,
199,
199,
893,
26,
272,
1549,
1277,
13384,
63,
3022,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
9458,
1012,
199,
2590,
6440,
26,
272,
1549,
1277,
13384,
63,
3022,
275,
488,
199,
199,
3,
199,
3,
1684,
3423,
199,
3,
199,
199,
318,
1453,
63,
1412,
837,
272,
1449,
272,
1432,
2112,
909,
6144,
314,
1453,
2112,
272,
1449,
272,
372,
485,
1818,
63,
1412,
199,
199,
318,
4702,
63,
3223,
837,
272,
1449,
272,
1432,
769,
402,
2112,
2251,
5226,
370,
12166,
1982,
10358,
272,
1449,
272,
485,
7661,
342,
272,
372,
769,
1547,
1818,
63,
1412,
423,
3223,
9,
199,
199,
3,
199,
3,
199,
3,
199,
199,
318,
485,
7661,
837,
272,
327,
1104,
367,
10358,
1314,
1172,
9158,
272,
367,
299,
315,
769,
1547,
1818,
63,
1412,
423,
3223,
304,
267,
340,
299,
423,
12207,
14,
6843,
342,
365,
440,
488,
26,
288,
485,
1818,
63,
1412,
423,
3223,
14,
14394,
8,
80,
9,
199,
199,
3,
199,
3,
710,
658,
3498,
64,
1021,
199,
3,
199,
199,
3,
330,
23196,
5317,
26,
1021,
7132,
365,
3247,
315,
1182,
2647,
15,
8450,
15607,
25725,
14,
3596,
421,
199,
3,
199,
3,
2136,
5516,
2783,
370,
5126,
24634,
279,
1752,
2250,
402,
1790,
2883,
1806,
2784,
199,
3,
199,
199,
533,
15995,
1558,
8,
2394,
304,
272,
347,
636,
5270,
721,
277,
304,
267,
687,
1275,
11796,
316,
492,
13995,
267,
340,
440,
13995,
14,
2671,
63,
374,
63,
3770,
87,
1835,
837,
288,
746,
3146,
8,
355,
283,
8587,
2983,
376,
15995,
1558,
909,
365,
283,
355,
283,
2297,
6541,
367,
6391,
14872,
7,
355,
776,
267,
372,
15995,
1558,
12,
334,
2394,
8,
277,
16945,
199,
199,
3,
199,
3,
2790,
909,
6144,
314,
2446,
2112,
199,
3,
199,
199,
533,
485,
6756,
3498,
8,
3498,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
5582,
275,
6248,
267,
291,
423,
10824,
530,
275,
756,
267,
291,
423,
354,
275,
283,
6756,
3498,
7,
267,
291,
423,
1708,
63,
3150,
275,
488,
267,
291,
423,
12207,
275,
488,
267,
291,
423,
5337,
275,
7975,
14,
835,
8,
17,
9,
267,
291,
423,
3223,
275,
663,
342,
267,
291,
423,
1178,
498,
275,
15995,
1558,
8,
736,
14,
22776,
8,
708,
430,
267,
291,
423,
11567,
275,
488,
199,
199,
63,
1818,
63,
1412,
275,
485,
6756,
3498,
342,
199,
2264,
485,
6756,
3498,
199,
199,
3,
199,
3,
25495,
1561,
370,
2005,
372,
9479,
199,
3,
199,
199,
63,
2224,
600,
63,
475,
63,
354,
275,
1052,
199,
199,
509,
536,
12,
2070,
453,
315,
769,
8,
4653,
855,
807,
4343,
1744,
5109,
272,
340,
536,
1491,
19,
22954,
7864,
7,
436,
14135,
440,
315,
536,
26,
267,
485,
2224,
600,
63,
475,
63,
354,
1988,
1037,
453,
61,
275,
536,
199,
199,
3,
2104,
3105,
436,
25831,
5343,
199,
63,
68,
26896,
275,
28224,
1084,
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,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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ashmastaflash/IDCOAS
|
integration/heatmaps/heatmap-2.2.1/build/lib.macosx-10.9-x86_64-2.7/heatmap/colorschemes.py
|
6
|
33688
|
""" color scheme source data """
schemes = {'classic': [(255, 237, 237),
(255, 224, 224),
(255, 209, 209),
(255, 193, 193),
(255, 176, 176),
(255, 159, 159),
(255, 142, 142),
(255, 126, 126),
(255, 110, 110),
(255, 94, 94),
(255, 81, 81),
(255, 67, 67),
(255, 56, 56),
(255, 46, 46),
(255, 37, 37),
(255, 29, 29),
(255, 23, 23),
(255, 18, 18),
(255, 14, 14),
(255, 11, 11),
(255, 8, 8),
(255, 6, 6),
(255, 5, 5),
(255, 3, 3),
(255, 2, 2),
(255, 2, 2),
(255, 1, 1),
(255, 1, 1),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 0, 0),
(255, 1, 0),
(255, 4, 0),
(255, 6, 0),
(255, 10, 0),
(255, 14, 0),
(255, 18, 0),
(255, 22, 0),
(255, 26, 0),
(255, 31, 0),
(255, 36, 0),
(255, 41, 0),
(255, 45, 0),
(255, 51, 0),
(255, 57, 0),
(255, 62, 0),
(255, 68, 0),
(255, 74, 0),
(255, 81, 0),
(255, 86, 0),
(255, 93, 0),
(255, 99, 0),
(255, 105, 0),
(255, 111, 0),
(255, 118, 0),
(255, 124, 0),
(255, 131, 0),
(255, 137, 0),
(255, 144, 0),
(255, 150, 0),
(255, 156, 0),
(255, 163, 0),
(255, 169, 0),
(255, 175, 0),
(255, 181, 0),
(255, 187, 0),
(255, 192, 0),
(255, 198, 0),
(255, 203, 0),
(255, 208, 0),
(255, 213, 0),
(255, 218, 0),
(255, 222, 0),
(255, 227, 0),
(255, 232, 0),
(255, 235, 0),
(255, 238, 0),
(255, 242, 0),
(255, 245, 0),
(255, 247, 0),
(255, 250, 0),
(255, 251, 0),
(253, 252, 0),
(250, 252, 1),
(248, 252, 2),
(244, 252, 2),
(241, 252, 3),
(237, 252, 3),
(233, 252, 3),
(229, 252, 4),
(225, 252, 4),
(220, 252, 5),
(216, 252, 5),
(211, 252, 6),
(206, 252, 7),
(201, 252, 7),
(197, 252, 8),
(191, 251, 8),
(185, 249, 9),
(180, 247, 9),
(174, 246, 10),
(169, 244, 11),
(164, 242, 11),
(158, 240, 12),
(151, 238, 13),
(146, 236, 14),
(140, 233, 14),
(134, 231, 15),
(128, 228, 16),
(122, 226, 17),
(116, 223, 18),
(110, 221, 19),
(105, 218, 20),
(99, 216, 21),
(93, 214, 22),
(88, 211, 23),
(82, 209, 24),
(76, 207, 25),
(71, 204, 26),
(66, 202, 28),
(60, 200, 30),
(55, 198, 31),
(50, 196, 33),
(45, 194, 34),
(40, 191, 35),
(36, 190, 37),
(31, 188, 39),
(27, 187, 40),
(23, 185, 43),
(19, 184, 44),
(15, 183, 46),
(12, 182, 48),
(9, 181, 51),
(6, 181, 53),
(3, 180, 55),
(1, 180, 57),
(0, 180, 60),
(0, 180, 62),
(0, 180, 65),
(0, 181, 68),
(0, 182, 70),
(0, 182, 74),
(0, 183, 77),
(0, 184, 80),
(0, 184, 84),
(0, 186, 88),
(0, 187, 92),
(0, 188, 95),
(0, 190, 99),
(0, 191, 104),
(0, 193, 108),
(0, 194, 112),
(0, 196, 116),
(0, 198, 120),
(0, 200, 125),
(0, 201, 129),
(0, 203, 134),
(0, 205, 138),
(0, 207, 143),
(0, 209, 147),
(0, 211, 151),
(0, 213, 156),
(0, 215, 160),
(0, 216, 165),
(0, 219, 171),
(0, 222, 178),
(0, 224, 184),
(0, 227, 190),
(0, 229, 197),
(0, 231, 203),
(0, 233, 209),
(0, 234, 214),
(0, 234, 220),
(0, 234, 225),
(0, 234, 230),
(0, 234, 234),
(0, 234, 238),
(0, 234, 242),
(0, 234, 246),
(0, 234, 248),
(0, 234, 251),
(0, 234, 254),
(0, 234, 255),
(0, 232, 255),
(0, 228, 255),
(0, 224, 255),
(0, 219, 255),
(0, 214, 254),
(0, 208, 252),
(0, 202, 250),
(0, 195, 247),
(0, 188, 244),
(0, 180, 240),
(0, 173, 236),
(0, 164, 232),
(0, 156, 228),
(0, 147, 222),
(0, 139, 218),
(0, 130, 213),
(0, 122, 208),
(0, 117, 205),
(0, 112, 203),
(0, 107, 199),
(0, 99, 196),
(0, 93, 193),
(0, 86, 189),
(0, 78, 184),
(0, 71, 180),
(0, 65, 175),
(0, 58, 171),
(0, 52, 167),
(0, 46, 162),
(0, 40, 157),
(0, 35, 152),
(0, 30, 147),
(0, 26, 142),
(0, 22, 136),
(0, 18, 131),
(0, 15, 126),
(0, 12, 120),
(0, 9, 115),
(1, 8, 110),
(1, 6, 106),
(1, 5, 101),
(2, 4, 97),
(3, 4, 92),
(4, 5, 89),
(5, 5, 85),
(6, 6, 82),
(7, 7, 79),
(8, 8, 77),
(10, 10, 77),
(12, 12, 77),
(14, 14, 76),
(16, 16, 74),
(19, 19, 73),
(21, 21, 72),
(24, 24, 71),
(26, 26, 69),
(29, 29, 70),
(32, 32, 69),
(35, 35, 68),
(37, 37, 67),
(40, 40, 67),
(42, 42, 65),
(44, 44, 65),
(46, 46, 64),
(48, 48, 63),
(49, 50, 62),
(51, 51, 61),
(53, 52, 61)],
'fire': [(255, 255, 255),
(255, 255, 253),
(255, 255, 250),
(255, 255, 247),
(255, 255, 244),
(255, 255, 241),
(255, 255, 238),
(255, 255, 234),
(255, 255, 231),
(255, 255, 227),
(255, 255, 223),
(255, 255, 219),
(255, 255, 214),
(255, 255, 211),
(255, 255, 206),
(255, 255, 202),
(255, 255, 197),
(255, 255, 192),
(255, 255, 187),
(255, 255, 183),
(255, 255, 178),
(255, 255, 172),
(255, 255, 167),
(255, 255, 163),
(255, 255, 157),
(255, 255, 152),
(255, 255, 147),
(255, 255, 142),
(255, 255, 136),
(255, 255, 132),
(255, 255, 126),
(255, 255, 121),
(255, 255, 116),
(255, 255, 111),
(255, 255, 106),
(255, 255, 102),
(255, 255, 97),
(255, 255, 91),
(255, 255, 87),
(255, 255, 82),
(255, 255, 78),
(255, 255, 74),
(255, 255, 70),
(255, 255, 65),
(255, 255, 61),
(255, 255, 57),
(255, 255, 53),
(255, 255, 50),
(255, 255, 46),
(255, 255, 43),
(255, 255, 39),
(255, 255, 38),
(255, 255, 34),
(255, 255, 31),
(255, 255, 29),
(255, 255, 26),
(255, 255, 25),
(255, 254, 23),
(255, 251, 22),
(255, 250, 22),
(255, 247, 23),
(255, 245, 23),
(255, 242, 24),
(255, 239, 24),
(255, 236, 25),
(255, 232, 25),
(255, 229, 26),
(255, 226, 26),
(255, 222, 27),
(255, 218, 27),
(255, 215, 28),
(255, 210, 28),
(255, 207, 29),
(255, 203, 29),
(255, 199, 30),
(255, 194, 30),
(255, 190, 31),
(255, 186, 31),
(255, 182, 32),
(255, 176, 32),
(255, 172, 33),
(255, 168, 34),
(255, 163, 34),
(255, 159, 35),
(255, 154, 35),
(255, 150, 36),
(255, 145, 36),
(255, 141, 37),
(255, 136, 37),
(255, 132, 38),
(255, 128, 39),
(255, 124, 39),
(255, 119, 40),
(255, 115, 40),
(255, 111, 41),
(255, 107, 41),
(255, 103, 42),
(255, 99, 42),
(255, 95, 43),
(255, 92, 44),
(255, 89, 44),
(255, 85, 45),
(255, 81, 45),
(255, 79, 46),
(255, 76, 47),
(255, 72, 47),
(255, 70, 48),
(255, 67, 48),
(255, 65, 49),
(255, 63, 50),
(255, 60, 50),
(255, 59, 51),
(255, 57, 51),
(255, 55, 52),
(255, 55, 53),
(255, 53, 53),
(253, 54, 54),
(253, 54, 54),
(251, 55, 55),
(250, 56, 56),
(248, 56, 56),
(247, 57, 57),
(246, 57, 57),
(244, 58, 58),
(242, 59, 59),
(240, 59, 59),
(239, 60, 60),
(238, 61, 61),
(235, 61, 61),
(234, 62, 62),
(232, 62, 62),
(229, 63, 63),
(228, 64, 64),
(226, 64, 64),
(224, 65, 65),
(222, 66, 66),
(219, 66, 66),
(218, 67, 67),
(216, 67, 67),
(213, 68, 68),
(211, 69, 69),
(209, 69, 69),
(207, 70, 70),
(205, 71, 71),
(203, 71, 71),
(200, 72, 72),
(199, 73, 73),
(196, 73, 73),
(194, 74, 74),
(192, 74, 74),
(190, 75, 75),
(188, 76, 76),
(186, 76, 76),
(183, 77, 77),
(181, 78, 78),
(179, 78, 78),
(177, 79, 79),
(175, 80, 80),
(173, 80, 80),
(170, 81, 81),
(169, 82, 82),
(166, 82, 82),
(165, 83, 83),
(162, 83, 83),
(160, 84, 84),
(158, 85, 85),
(156, 85, 85),
(154, 86, 86),
(153, 87, 87),
(150, 87, 87),
(149, 88, 88),
(147, 89, 89),
(146, 90, 90),
(144, 91, 91),
(142, 92, 92),
(142, 94, 94),
(141, 95, 95),
(140, 96, 96),
(139, 98, 98),
(138, 99, 99),
(136, 100, 100),
(135, 101, 101),
(135, 103, 103),
(134, 104, 104),
(133, 105, 105),
(133, 107, 107),
(132, 108, 108),
(131, 109, 109),
(132, 111, 111),
(131, 112, 112),
(130, 113, 113),
(130, 114, 114),
(130, 116, 116),
(130, 117, 117),
(130, 118, 118),
(129, 119, 119),
(130, 121, 121),
(130, 122, 122),
(130, 123, 123),
(130, 124, 124),
(131, 126, 126),
(131, 127, 127),
(130, 128, 128),
(131, 129, 129),
(132, 131, 131),
(132, 132, 132),
(133, 133, 133),
(134, 134, 134),
(135, 135, 135),
(136, 136, 136),
(138, 138, 138),
(139, 139, 139),
(140, 140, 140),
(141, 141, 141),
(142, 142, 142),
(143, 143, 143),
(144, 144, 144),
(145, 145, 145),
(147, 147, 147),
(148, 148, 148),
(149, 149, 149),
(150, 150, 150),
(151, 151, 151),
(152, 152, 152),
(153, 153, 153),
(154, 154, 154),
(155, 155, 155),
(156, 156, 156),
(157, 157, 157),
(158, 158, 158),
(159, 159, 159),
(160, 160, 160),
(160, 160, 160),
(161, 161, 161),
(162, 162, 162),
(163, 163, 163),
(164, 164, 164),
(165, 165, 165),
(166, 166, 166),
(167, 167, 167),
(167, 167, 167),
(168, 168, 168),
(169, 169, 169),
(170, 170, 170),
(170, 170, 170),
(171, 171, 171),
(172, 172, 172),
(173, 173, 173),
(173, 173, 173),
(174, 174, 174),
(175, 175, 175),
(175, 175, 175),
(176, 176, 176),
(176, 176, 176),
(177, 177, 177),
(177, 177, 177)],
'omg': [(255, 255, 255),
(255, 254, 254),
(255, 253, 253),
(255, 251, 251),
(255, 250, 250),
(255, 249, 249),
(255, 247, 247),
(255, 246, 246),
(255, 244, 244),
(255, 242, 242),
(255, 241, 241),
(255, 239, 239),
(255, 237, 237),
(255, 235, 235),
(255, 233, 233),
(255, 231, 231),
(255, 229, 229),
(255, 227, 227),
(255, 226, 226),
(255, 224, 224),
(255, 222, 222),
(255, 220, 220),
(255, 217, 217),
(255, 215, 215),
(255, 213, 213),
(255, 210, 210),
(255, 208, 208),
(255, 206, 206),
(255, 204, 204),
(255, 202, 202),
(255, 199, 199),
(255, 197, 197),
(255, 194, 194),
(255, 192, 192),
(255, 189, 189),
(255, 188, 188),
(255, 185, 185),
(255, 183, 183),
(255, 180, 180),
(255, 178, 178),
(255, 176, 176),
(255, 173, 173),
(255, 171, 171),
(255, 169, 169),
(255, 167, 167),
(255, 164, 164),
(255, 162, 162),
(255, 160, 160),
(255, 158, 158),
(255, 155, 155),
(255, 153, 153),
(255, 151, 151),
(255, 149, 149),
(255, 147, 147),
(255, 145, 145),
(255, 143, 143),
(255, 141, 141),
(255, 139, 139),
(255, 137, 137),
(255, 136, 136),
(255, 134, 134),
(255, 132, 132),
(255, 131, 131),
(255, 129, 129),
(255, 128, 128),
(255, 127, 127),
(255, 127, 127),
(255, 126, 126),
(255, 125, 125),
(255, 125, 125),
(255, 124, 124),
(255, 123, 122),
(255, 123, 122),
(255, 122, 121),
(255, 122, 121),
(255, 121, 120),
(255, 120, 119),
(255, 119, 118),
(255, 119, 118),
(255, 118, 116),
(255, 117, 116),
(255, 117, 115),
(255, 115, 114),
(255, 115, 114),
(255, 114, 113),
(255, 114, 112),
(255, 113, 111),
(255, 113, 111),
(255, 112, 110),
(255, 111, 108),
(255, 111, 108),
(255, 110, 107),
(255, 110, 107),
(255, 109, 105),
(255, 109, 105),
(255, 108, 104),
(255, 107, 104),
(255, 107, 102),
(255, 106, 102),
(255, 106, 101),
(255, 105, 101),
(255, 104, 99),
(255, 104, 99),
(255, 103, 98),
(255, 103, 98),
(255, 102, 97),
(255, 102, 96),
(255, 101, 96),
(255, 101, 96),
(255, 100, 94),
(255, 100, 94),
(255, 99, 93),
(255, 99, 92),
(255, 98, 91),
(255, 98, 91),
(255, 97, 90),
(255, 97, 89),
(255, 96, 89),
(255, 96, 89),
(255, 95, 88),
(255, 95, 88),
(255, 94, 86),
(255, 93, 86),
(255, 93, 85),
(255, 93, 85),
(255, 92, 85),
(255, 92, 84),
(255, 91, 83),
(255, 91, 83),
(255, 90, 82),
(255, 90, 82),
(255, 89, 81),
(255, 89, 82),
(255, 89, 80),
(255, 89, 80),
(255, 89, 79),
(255, 89, 79),
(255, 88, 79),
(255, 88, 79),
(255, 87, 78),
(255, 87, 78),
(255, 87, 78),
(255, 87, 77),
(255, 87, 77),
(255, 86, 77),
(255, 86, 77),
(255, 85, 76),
(255, 85, 76),
(255, 85, 75),
(255, 85, 76),
(255, 85, 75),
(255, 85, 76),
(255, 84, 75),
(255, 84, 75),
(255, 84, 75),
(255, 84, 75),
(255, 85, 75),
(255, 84, 75),
(255, 84, 75),
(255, 83, 74),
(255, 83, 75),
(255, 83, 75),
(255, 84, 75),
(255, 83, 75),
(255, 83, 75),
(255, 83, 75),
(255, 83, 75),
(255, 83, 76),
(255, 83, 76),
(255, 83, 76),
(255, 83, 76),
(255, 83, 76),
(255, 83, 76),
(255, 83, 76),
(255, 83, 76),
(255, 83, 77),
(255, 84, 78),
(255, 83, 78),
(255, 84, 79),
(255, 84, 78),
(255, 84, 79),
(255, 83, 79),
(255, 84, 80),
(255, 83, 80),
(255, 84, 81),
(255, 85, 82),
(255, 85, 82),
(255, 85, 83),
(255, 85, 83),
(255, 85, 84),
(255, 85, 84),
(255, 86, 85),
(255, 86, 85),
(255, 87, 87),
(254, 89, 89),
(254, 91, 92),
(253, 92, 93),
(252, 94, 96),
(251, 96, 98),
(251, 97, 100),
(249, 99, 103),
(249, 100, 105),
(248, 102, 108),
(247, 104, 111),
(246, 105, 113),
(245, 107, 116),
(244, 109, 119),
(243, 110, 122),
(242, 112, 125),
(241, 113, 127),
(240, 115, 130),
(239, 117, 134),
(238, 118, 136),
(237, 120, 140),
(236, 121, 142),
(235, 123, 145),
(234, 124, 148),
(233, 126, 151),
(232, 127, 154),
(232, 129, 157),
(230, 130, 159),
(230, 132, 162),
(229, 133, 165),
(228, 135, 168),
(227, 136, 170),
(227, 138, 173),
(226, 139, 176),
(225, 140, 178),
(224, 142, 181),
(223, 143, 183),
(223, 144, 185),
(223, 146, 188),
(222, 147, 190),
(221, 148, 192),
(221, 150, 195),
(220, 151, 197),
(219, 152, 199),
(219, 153, 201),
(219, 154, 202),
(219, 156, 205),
(218, 157, 207),
(217, 158, 208),
(217, 159, 210),
(217, 160, 211),
(217, 161, 213),
(216, 162, 214),
(216, 163, 216),
(216, 164, 217),
(215, 165, 218),
(216, 166, 219),
(215, 166, 220),
(215, 167, 222),
(215, 168, 223),
(215, 169, 223),
(215, 170, 224),
(215, 170, 225)],
'pbj': [(41, 10, 89),
(41, 10, 89),
(42, 10, 89),
(42, 10, 89),
(42, 10, 88),
(43, 10, 88),
(43, 9, 88),
(43, 9, 88),
(44, 9, 88),
(44, 9, 88),
(45, 10, 89),
(46, 10, 88),
(46, 9, 88),
(47, 9, 88),
(47, 9, 88),
(47, 9, 88),
(48, 8, 88),
(48, 8, 87),
(49, 8, 87),
(49, 8, 87),
(49, 7, 87),
(50, 7, 87),
(50, 7, 87),
(51, 7, 86),
(51, 6, 86),
(53, 7, 86),
(53, 7, 86),
(54, 7, 86),
(54, 6, 85),
(55, 6, 85),
(55, 6, 85),
(56, 5, 85),
(56, 5, 85),
(57, 5, 84),
(57, 5, 84),
(58, 4, 84),
(59, 4, 84),
(59, 5, 84),
(60, 4, 84),
(60, 4, 84),
(61, 4, 84),
(61, 4, 83),
(62, 3, 83),
(63, 3, 83),
(63, 3, 83),
(64, 3, 82),
(64, 3, 82),
(65, 3, 82),
(66, 3, 82),
(67, 4, 82),
(68, 4, 82),
(69, 4, 82),
(69, 4, 81),
(70, 4, 81),
(71, 4, 81),
(71, 4, 80),
(72, 4, 80),
(73, 4, 80),
(73, 4, 79),
(75, 5, 80),
(76, 5, 80),
(77, 5, 79),
(77, 5, 79),
(78, 5, 79),
(79, 5, 78),
(80, 5, 78),
(80, 5, 78),
(80, 5, 77),
(81, 5, 77),
(83, 6, 76),
(83, 6, 76),
(84, 6, 76),
(85, 6, 75),
(86, 6, 75),
(87, 6, 74),
(88, 6, 74),
(88, 6, 73),
(89, 6, 73),
(91, 7, 73),
(92, 7, 73),
(93, 7, 72),
(94, 7, 72),
(94, 7, 71),
(95, 7, 71),
(96, 7, 70),
(96, 7, 70),
(97, 7, 69),
(99, 9, 70),
(100, 9, 69),
(101, 10, 69),
(102, 10, 68),
(103, 11, 67),
(104, 11, 67),
(105, 12, 66),
(106, 13, 66),
(107, 14, 66),
(108, 15, 65),
(109, 16, 64),
(110, 16, 64),
(111, 17, 63),
(112, 18, 62),
(113, 18, 61),
(114, 19, 61),
(115, 20, 60),
(118, 22, 60),
(119, 22, 59),
(120, 22, 58),
(120, 23, 58),
(121, 24, 57),
(122, 25, 56),
(124, 26, 55),
(125, 27, 54),
(127, 29, 54),
(128, 30, 54),
(130, 31, 53),
(131, 32, 52),
(132, 33, 51),
(133, 34, 50),
(134, 35, 49),
(135, 36, 48),
(137, 38, 48),
(138, 39, 47),
(140, 40, 46),
(141, 41, 46),
(142, 42, 45),
(143, 42, 44),
(144, 43, 43),
(145, 44, 42),
(146, 45, 42),
(149, 47, 41),
(150, 48, 41),
(151, 49, 40),
(152, 50, 39),
(153, 51, 38),
(154, 52, 38),
(155, 53, 37),
(157, 55, 36),
(159, 57, 36),
(160, 57, 35),
(160, 58, 34),
(162, 59, 33),
(163, 60, 33),
(164, 61, 32),
(165, 62, 31),
(167, 63, 30),
(168, 65, 30),
(169, 66, 29),
(170, 67, 29),
(172, 68, 28),
(173, 69, 27),
(174, 70, 26),
(175, 71, 26),
(176, 71, 25),
(178, 73, 25),
(179, 74, 24),
(180, 75, 24),
(181, 76, 23),
(182, 77, 23),
(183, 78, 23),
(184, 79, 22),
(186, 80, 22),
(187, 81, 21),
(188, 82, 21),
(189, 83, 21),
(190, 83, 20),
(191, 84, 20),
(192, 85, 19),
(192, 86, 19),
(193, 87, 18),
(194, 87, 18),
(196, 89, 18),
(196, 90, 18),
(197, 90, 18),
(198, 90, 18),
(199, 91, 18),
(200, 92, 18),
(201, 93, 18),
(202, 93, 18),
(203, 94, 18),
(204, 96, 19),
(204, 96, 19),
(205, 97, 19),
(206, 98, 19),
(207, 99, 19),
(208, 99, 19),
(209, 100, 19),
(210, 100, 19),
(211, 100, 19),
(212, 102, 20),
(213, 103, 20),
(214, 103, 20),
(214, 104, 20),
(215, 105, 20),
(215, 105, 20),
(216, 106, 20),
(217, 107, 20),
(218, 107, 20),
(219, 108, 20),
(220, 109, 21),
(221, 109, 21),
(222, 110, 21),
(222, 111, 21),
(223, 111, 21),
(224, 112, 21),
(225, 113, 21),
(226, 113, 21),
(227, 114, 21),
(227, 114, 21),
(228, 115, 22),
(229, 116, 22),
(229, 116, 22),
(230, 117, 22),
(231, 117, 22),
(231, 118, 22),
(232, 119, 22),
(233, 119, 22),
(234, 120, 22),
(234, 120, 22),
(235, 121, 22),
(236, 121, 22),
(237, 122, 23),
(237, 122, 23),
(238, 123, 23),
(239, 124, 23),
(239, 124, 23),
(240, 125, 23),
(240, 125, 23),
(241, 126, 23),
(241, 126, 23),
(242, 127, 23),
(243, 127, 23),
(243, 128, 23),
(244, 128, 24),
(244, 128, 24),
(245, 129, 24),
(246, 129, 24),
(246, 130, 24),
(247, 130, 24),
(247, 131, 24),
(248, 131, 24),
(249, 131, 24),
(249, 132, 24),
(250, 132, 24),
(250, 133, 24),
(250, 133, 24),
(250, 133, 24),
(251, 134, 24),
(251, 134, 25),
(252, 135, 25),
(252, 135, 25),
(253, 135, 25),
(253, 136, 25),
(253, 136, 25),
(254, 136, 25),
(254, 136, 25),
(255, 137, 25)],
'pgaitch': [(255, 254, 165),
(255, 254, 164),
(255, 253, 163),
(255, 253, 162),
(255, 253, 161),
(255, 252, 160),
(255, 252, 159),
(255, 252, 157),
(255, 251, 156),
(255, 251, 155),
(255, 251, 153),
(255, 250, 152),
(255, 250, 150),
(255, 250, 149),
(255, 249, 148),
(255, 249, 146),
(255, 249, 145),
(255, 248, 143),
(255, 248, 141),
(255, 248, 139),
(255, 247, 138),
(255, 247, 136),
(255, 246, 134),
(255, 246, 132),
(255, 246, 130),
(255, 245, 129),
(255, 245, 127),
(255, 245, 125),
(255, 244, 123),
(255, 244, 121),
(255, 243, 119),
(255, 243, 117),
(255, 242, 114),
(255, 242, 112),
(255, 241, 111),
(255, 241, 109),
(255, 240, 107),
(255, 240, 105),
(255, 239, 102),
(255, 239, 100),
(255, 238, 99),
(255, 238, 97),
(255, 237, 95),
(255, 237, 92),
(255, 236, 90),
(255, 237, 89),
(255, 236, 87),
(255, 235, 84),
(255, 235, 82),
(255, 234, 80),
(255, 233, 79),
(255, 233, 77),
(255, 232, 74),
(255, 231, 72),
(255, 230, 70),
(255, 230, 69),
(255, 229, 67),
(255, 228, 65),
(255, 227, 63),
(255, 226, 61),
(255, 225, 60),
(255, 225, 58),
(255, 224, 56),
(255, 223, 54),
(255, 222, 52),
(255, 222, 51),
(255, 221, 49),
(255, 220, 47),
(255, 219, 46),
(255, 218, 44),
(255, 216, 43),
(255, 215, 42),
(255, 214, 41),
(255, 213, 39),
(255, 212, 39),
(255, 211, 37),
(255, 209, 36),
(255, 208, 34),
(255, 208, 33),
(255, 206, 33),
(255, 205, 32),
(255, 204, 30),
(255, 202, 29),
(255, 201, 29),
(255, 199, 28),
(254, 199, 28),
(254, 199, 27),
(253, 198, 27),
(252, 197, 27),
(251, 196, 27),
(250, 195, 26),
(249, 195, 26),
(248, 194, 26),
(248, 193, 26),
(247, 192, 26),
(246, 192, 25),
(245, 191, 26),
(244, 190, 26),
(243, 189, 25),
(241, 188, 25),
(240, 187, 25),
(239, 187, 25),
(238, 186, 25),
(236, 185, 25),
(236, 184, 26),
(235, 183, 26),
(233, 182, 25),
(232, 181, 25),
(230, 181, 26),
(229, 180, 26),
(228, 179, 25),
(227, 178, 25),
(226, 177, 26),
(224, 176, 26),
(222, 176, 25),
(221, 175, 25),
(220, 173, 26),
(219, 172, 26),
(217, 171, 25),
(215, 170, 25),
(214, 170, 26),
(212, 169, 26),
(211, 167, 25),
(209, 166, 25),
(208, 166, 26),
(206, 165, 26),
(204, 163, 26),
(203, 162, 26),
(202, 161, 25),
(200, 161, 26),
(198, 159, 26),
(197, 158, 26),
(195, 157, 26),
(193, 157, 27),
(192, 155, 27),
(190, 154, 27),
(189, 153, 27),
(187, 152, 28),
(186, 151, 28),
(184, 150, 28),
(182, 149, 28),
(181, 148, 29),
(179, 147, 29),
(177, 146, 29),
(175, 144, 29),
(174, 144, 30),
(172, 142, 30),
(170, 141, 30),
(169, 140, 30),
(167, 139, 31),
(165, 138, 31),
(164, 137, 31),
(162, 136, 31),
(161, 135, 32),
(159, 134, 32),
(157, 133, 32),
(154, 132, 32),
(153, 131, 33),
(151, 130, 33),
(150, 129, 33),
(148, 127, 33),
(147, 127, 34),
(145, 126, 34),
(143, 124, 34),
(141, 123, 34),
(140, 122, 35),
(139, 121, 35),
(137, 120, 35),
(135, 119, 35),
(134, 118, 36),
(132, 117, 36),
(130, 116, 36),
(129, 115, 36),
(127, 113, 36),
(126, 113, 37),
(124, 112, 37),
(122, 111, 37),
(121, 110, 37),
(120, 109, 38),
(118, 108, 38),
(116, 107, 38),
(115, 105, 38),
(113, 104, 38),
(112, 104, 39),
(110, 103, 39),
(108, 102, 39),
(107, 101, 39),
(106, 100, 40),
(104, 99, 40),
(102, 98, 40),
(101, 96, 40),
(99, 96, 40),
(99, 96, 41),
(97, 94, 41),
(96, 93, 41),
(94, 92, 41),
(92, 91, 41),
(92, 90, 42),
(90, 90, 42),
(89, 89, 42),
(87, 87, 42),
(86, 86, 42),
(85, 86, 43),
(84, 85, 43),
(83, 84, 43),
(81, 83, 43),
(80, 82, 43),
(80, 82, 44),
(78, 80, 44),
(77, 80, 44),
(75, 79, 44),
(75, 78, 44),
(74, 78, 45),
(73, 76, 45),
(71, 75, 45),
(71, 75, 45),
(70, 74, 45),
(69, 74, 46),
(68, 73, 46),
(67, 72, 46),
(66, 71, 46),
(65, 71, 46),
(64, 69, 46),
(64, 69, 47),
(63, 68, 47),
(62, 67, 47),
(61, 67, 47),
(60, 66, 47),
(59, 65, 47),
(59, 65, 48),
(59, 64, 48),
(58, 63, 48),
(57, 63, 48),
(56, 62, 48),
(56, 62, 48),
(55, 61, 48),
(55, 61, 49),
(55, 60, 49),
(55, 60, 49),
(54, 59, 49),
(53, 58, 49),
(53, 57, 49),
(52, 57, 49),
(52, 57, 50),
(52, 56, 50),
(52, 56, 50),
(52, 56, 50),
(52, 55, 50),
(51, 54, 50),
(51, 53, 50),
(51, 53, 50),
(51, 52, 50),
(51, 53, 51),
(51, 53, 51),
(51, 52, 51),
(51, 52, 51)]}
def valid_schemes():
return schemes.keys()
|
gpl-2.0
|
[
624,
3164,
5687,
1350,
666,
408,
199,
199,
26818,
275,
791,
25140,
356,
3842,
2299,
12,
499,
1401,
12,
499,
1401,
395,
1467,
334,
2299,
12,
18565,
12,
18565,
395,
1467,
334,
2299,
12,
499,
1643,
12,
499,
1643,
395,
1467,
334,
2299,
12,
413,
3129,
12,
413,
3129,
395,
1467,
334,
2299,
12,
27827,
12,
27827,
395,
1467,
334,
2299,
12,
413,
1427,
12,
413,
1427,
395,
1467,
334,
2299,
12,
31308,
12,
31308,
395,
1467,
334,
2299,
12,
21572,
12,
21572,
395,
1467,
334,
2299,
12,
16814,
12,
16814,
395,
1467,
334,
2299,
12,
18729,
12,
18729,
395,
1467,
334,
2299,
12,
19071,
12,
19071,
395,
1467,
334,
2299,
12,
13296,
12,
13296,
395,
1467,
334,
2299,
12,
12001,
12,
12001,
395,
1467,
334,
2299,
12,
12426,
12,
12426,
395,
1467,
334,
2299,
12,
6877,
12,
6877,
395,
1467,
334,
2299,
12,
7349,
12,
7349,
395,
1467,
334,
2299,
12,
6546,
12,
6546,
395,
1467,
334,
2299,
12,
6155,
12,
6155,
395,
1467,
334,
2299,
12,
4329,
12,
4329,
395,
1467,
334,
2299,
12,
4119,
12,
4119,
395,
1467,
334,
2299,
12,
1695,
12,
1695,
395,
1467,
334,
2299,
12,
1227,
12,
1227,
395,
1467,
334,
2299,
12,
959,
12,
959,
395,
1467,
334,
2299,
12,
650,
12,
650,
395,
1467,
334,
2299,
12,
499,
12,
499,
395,
1467,
334,
2299,
12,
499,
12,
499,
395,
1467,
334,
2299,
12,
413,
12,
413,
395,
1467,
334,
2299,
12,
413,
12,
413,
395,
1467,
334,
2299,
12,
378,
12,
378,
395,
1467,
334,
2299,
12,
378,
12,
378,
395,
1467,
334,
2299,
12,
378,
12,
378,
395,
1467,
334,
2299,
12,
378,
12,
378,
395,
1467,
334,
2299,
12,
378,
12,
378,
395,
1467,
334,
2299,
12,
378,
12,
378,
395,
1467,
334,
2299,
12,
378,
12,
378,
395,
1467,
334,
2299,
12,
378,
12,
378,
395,
1467,
334,
2299,
12,
413,
12,
378,
395,
1467,
334,
2299,
12,
841,
12,
378,
395,
1467,
334,
2299,
12,
1227,
12,
378,
395,
1467,
334,
2299,
12,
1616,
12,
378,
395,
1467,
334,
2299,
12,
4329,
12,
378,
395,
1467,
334,
2299,
12,
6155,
12,
378,
395,
1467,
334,
2299,
12,
6928,
12,
378,
395,
1467,
334,
2299,
12,
7875,
12,
378,
395,
1467,
334,
2299,
12,
7105,
12,
378,
395,
1467,
334,
2299,
12,
8780,
12,
378,
395,
1467,
334,
2299,
12,
13385,
12,
378,
395,
1467,
334,
2299,
12,
10416,
12,
378,
395,
1467,
334,
2299,
12,
8026,
12,
378,
395,
1467,
334,
2299,
12,
12699,
12,
378,
395,
1467,
334,
2299,
12,
16202,
12,
378,
395,
1467,
334,
2299,
12,
10851,
12,
378,
395,
1467,
334,
2299,
12,
9720,
12,
378,
395,
1467,
334,
2299,
12,
19071,
12,
378,
395,
1467,
334,
2299,
12,
10300,
12,
378,
395,
1467,
334,
2299,
12,
18969,
12,
378,
395,
1467,
334,
2299,
12,
8806,
12,
378,
395,
1467,
334,
2299,
12,
20462,
12,
378,
395,
1467,
334,
2299,
12,
20128,
12,
378,
395,
1467,
334,
2299,
12,
25760,
12,
378,
395,
1467,
334,
2299,
12,
25442,
12,
378,
395,
1467,
334,
2299,
12,
30542,
12,
378,
395,
1467,
334,
2299,
12,
27750,
12,
378,
395,
1467,
334,
2299,
12,
21771,
12,
378,
395,
1467,
334,
2299,
12,
14711,
12,
378,
395,
1467,
334,
2299,
12,
32609,
12,
378,
395,
1467,
334,
2299,
12,
24619,
12,
378,
395,
1467,
334,
2299,
12,
20680,
12,
378,
395,
1467,
334,
2299,
12,
27306,
12,
378,
395,
1467,
334,
2299,
12,
413,
2835,
12,
378,
395,
1467,
334,
2299,
12,
32583,
12,
378,
395,
1467,
334,
2299,
12,
13567,
12,
378,
395,
1467,
334,
2299,
12,
413,
2905,
12,
378,
395,
1467,
334,
2299,
12,
29202,
12,
378,
395,
1467,
334,
2299,
12,
29203,
12,
378,
395,
1467,
334,
2299,
12,
499,
969,
12,
378,
395,
1467,
334,
2299,
12,
32319,
12,
378,
395,
1467,
334,
2299,
12,
26485,
12,
378,
395,
1467,
334,
2299,
12,
499,
1465,
12,
378,
395,
1467,
334,
2299,
12,
499,
708,
12,
378,
395,
1467,
334,
2299,
12,
31071,
12,
378,
395,
1467,
334,
2299,
12,
27077,
12,
378,
395,
1467,
334,
2299,
12,
499,
2260,
12,
378,
395,
1467,
334,
2299,
12,
32102,
12,
378,
395,
1467,
334,
2299,
12,
499,
2417,
12,
378,
395,
1467,
334,
2299,
12,
16074,
12,
378,
395,
1467,
334,
2299,
12,
499,
2869,
12,
378,
395,
1467,
334,
3781,
12,
27210,
12,
378,
395,
1467,
334,
7991,
12,
27210,
12,
413,
395,
1467,
334,
11242,
12,
27210,
12,
499,
395,
1467,
334,
11603,
12,
27210,
12,
499,
395,
1467,
334,
13571,
12,
27210,
12,
650,
395,
1467,
334,
10638,
12,
27210,
12,
650,
395,
1467,
334,
10034,
12,
27210,
12,
650,
395,
1467,
334,
11182,
12,
27210,
12,
841,
395,
1467,
334,
10932,
12,
27210,
12,
841,
395,
1467,
334,
11174,
12,
27210,
12,
959,
395,
1467,
334,
9669,
12,
27210,
12,
959,
395,
1467,
334,
12832,
12,
27210,
12,
1227,
395,
1467,
334,
11089,
12,
27210,
12,
1520,
395,
1467,
334,
1797,
12,
27210,
12,
1520,
395,
1467,
334,
11165,
12,
27210,
12,
1695,
395,
1467,
334,
12632,
12,
499,
2869,
12,
1695,
395,
1467,
334,
10233,
12,
499,
1887,
12,
1749,
395,
1467,
334,
7663,
12,
499,
2417,
12,
1749,
395,
1467,
334,
9892,
12,
499,
2466,
12,
1616,
395,
1467,
334,
10143,
12,
499,
1602,
12,
4119,
395,
1467,
334,
8982,
12,
499,
2260,
12,
4119,
395,
1467,
334,
11240,
12,
21883,
12,
3144,
395,
1467,
334,
12768,
12,
27077,
12,
4944,
395,
1467,
334,
11432,
12,
499,
1344,
12,
4329,
395,
1467,
334,
10037,
12,
499,
1153,
12,
4329,
395,
1467,
334,
7582,
12,
499,
2192,
12,
4114,
395,
1467,
334,
3933,
12,
499,
1651,
12,
3193,
395,
1467,
334,
7507,
12,
32584,
12,
5557,
395,
1467,
334,
7524,
12,
499,
1789,
12,
6155,
395,
1467,
334,
6019,
12,
499,
2025,
12,
5851,
395,
1467,
334,
7320,
12,
32319,
12,
3388,
395,
1467,
334,
1020,
12,
30630,
12,
7829,
395,
1467,
334,
3129,
12,
21237,
12,
6928,
395,
1467,
334,
1299,
12,
30301,
12,
6546,
395,
1467,
334,
2564,
12,
499,
1643,
12,
5504,
395,
1467,
334,
2114,
12,
31533,
12,
5661
] |
[
3164,
5687,
1350,
666,
408,
199,
199,
26818,
275,
791,
25140,
356,
3842,
2299,
12,
499,
1401,
12,
499,
1401,
395,
1467,
334,
2299,
12,
18565,
12,
18565,
395,
1467,
334,
2299,
12,
499,
1643,
12,
499,
1643,
395,
1467,
334,
2299,
12,
413,
3129,
12,
413,
3129,
395,
1467,
334,
2299,
12,
27827,
12,
27827,
395,
1467,
334,
2299,
12,
413,
1427,
12,
413,
1427,
395,
1467,
334,
2299,
12,
31308,
12,
31308,
395,
1467,
334,
2299,
12,
21572,
12,
21572,
395,
1467,
334,
2299,
12,
16814,
12,
16814,
395,
1467,
334,
2299,
12,
18729,
12,
18729,
395,
1467,
334,
2299,
12,
19071,
12,
19071,
395,
1467,
334,
2299,
12,
13296,
12,
13296,
395,
1467,
334,
2299,
12,
12001,
12,
12001,
395,
1467,
334,
2299,
12,
12426,
12,
12426,
395,
1467,
334,
2299,
12,
6877,
12,
6877,
395,
1467,
334,
2299,
12,
7349,
12,
7349,
395,
1467,
334,
2299,
12,
6546,
12,
6546,
395,
1467,
334,
2299,
12,
6155,
12,
6155,
395,
1467,
334,
2299,
12,
4329,
12,
4329,
395,
1467,
334,
2299,
12,
4119,
12,
4119,
395,
1467,
334,
2299,
12,
1695,
12,
1695,
395,
1467,
334,
2299,
12,
1227,
12,
1227,
395,
1467,
334,
2299,
12,
959,
12,
959,
395,
1467,
334,
2299,
12,
650,
12,
650,
395,
1467,
334,
2299,
12,
499,
12,
499,
395,
1467,
334,
2299,
12,
499,
12,
499,
395,
1467,
334,
2299,
12,
413,
12,
413,
395,
1467,
334,
2299,
12,
413,
12,
413,
395,
1467,
334,
2299,
12,
378,
12,
378,
395,
1467,
334,
2299,
12,
378,
12,
378,
395,
1467,
334,
2299,
12,
378,
12,
378,
395,
1467,
334,
2299,
12,
378,
12,
378,
395,
1467,
334,
2299,
12,
378,
12,
378,
395,
1467,
334,
2299,
12,
378,
12,
378,
395,
1467,
334,
2299,
12,
378,
12,
378,
395,
1467,
334,
2299,
12,
378,
12,
378,
395,
1467,
334,
2299,
12,
413,
12,
378,
395,
1467,
334,
2299,
12,
841,
12,
378,
395,
1467,
334,
2299,
12,
1227,
12,
378,
395,
1467,
334,
2299,
12,
1616,
12,
378,
395,
1467,
334,
2299,
12,
4329,
12,
378,
395,
1467,
334,
2299,
12,
6155,
12,
378,
395,
1467,
334,
2299,
12,
6928,
12,
378,
395,
1467,
334,
2299,
12,
7875,
12,
378,
395,
1467,
334,
2299,
12,
7105,
12,
378,
395,
1467,
334,
2299,
12,
8780,
12,
378,
395,
1467,
334,
2299,
12,
13385,
12,
378,
395,
1467,
334,
2299,
12,
10416,
12,
378,
395,
1467,
334,
2299,
12,
8026,
12,
378,
395,
1467,
334,
2299,
12,
12699,
12,
378,
395,
1467,
334,
2299,
12,
16202,
12,
378,
395,
1467,
334,
2299,
12,
10851,
12,
378,
395,
1467,
334,
2299,
12,
9720,
12,
378,
395,
1467,
334,
2299,
12,
19071,
12,
378,
395,
1467,
334,
2299,
12,
10300,
12,
378,
395,
1467,
334,
2299,
12,
18969,
12,
378,
395,
1467,
334,
2299,
12,
8806,
12,
378,
395,
1467,
334,
2299,
12,
20462,
12,
378,
395,
1467,
334,
2299,
12,
20128,
12,
378,
395,
1467,
334,
2299,
12,
25760,
12,
378,
395,
1467,
334,
2299,
12,
25442,
12,
378,
395,
1467,
334,
2299,
12,
30542,
12,
378,
395,
1467,
334,
2299,
12,
27750,
12,
378,
395,
1467,
334,
2299,
12,
21771,
12,
378,
395,
1467,
334,
2299,
12,
14711,
12,
378,
395,
1467,
334,
2299,
12,
32609,
12,
378,
395,
1467,
334,
2299,
12,
24619,
12,
378,
395,
1467,
334,
2299,
12,
20680,
12,
378,
395,
1467,
334,
2299,
12,
27306,
12,
378,
395,
1467,
334,
2299,
12,
413,
2835,
12,
378,
395,
1467,
334,
2299,
12,
32583,
12,
378,
395,
1467,
334,
2299,
12,
13567,
12,
378,
395,
1467,
334,
2299,
12,
413,
2905,
12,
378,
395,
1467,
334,
2299,
12,
29202,
12,
378,
395,
1467,
334,
2299,
12,
29203,
12,
378,
395,
1467,
334,
2299,
12,
499,
969,
12,
378,
395,
1467,
334,
2299,
12,
32319,
12,
378,
395,
1467,
334,
2299,
12,
26485,
12,
378,
395,
1467,
334,
2299,
12,
499,
1465,
12,
378,
395,
1467,
334,
2299,
12,
499,
708,
12,
378,
395,
1467,
334,
2299,
12,
31071,
12,
378,
395,
1467,
334,
2299,
12,
27077,
12,
378,
395,
1467,
334,
2299,
12,
499,
2260,
12,
378,
395,
1467,
334,
2299,
12,
32102,
12,
378,
395,
1467,
334,
2299,
12,
499,
2417,
12,
378,
395,
1467,
334,
2299,
12,
16074,
12,
378,
395,
1467,
334,
2299,
12,
499,
2869,
12,
378,
395,
1467,
334,
3781,
12,
27210,
12,
378,
395,
1467,
334,
7991,
12,
27210,
12,
413,
395,
1467,
334,
11242,
12,
27210,
12,
499,
395,
1467,
334,
11603,
12,
27210,
12,
499,
395,
1467,
334,
13571,
12,
27210,
12,
650,
395,
1467,
334,
10638,
12,
27210,
12,
650,
395,
1467,
334,
10034,
12,
27210,
12,
650,
395,
1467,
334,
11182,
12,
27210,
12,
841,
395,
1467,
334,
10932,
12,
27210,
12,
841,
395,
1467,
334,
11174,
12,
27210,
12,
959,
395,
1467,
334,
9669,
12,
27210,
12,
959,
395,
1467,
334,
12832,
12,
27210,
12,
1227,
395,
1467,
334,
11089,
12,
27210,
12,
1520,
395,
1467,
334,
1797,
12,
27210,
12,
1520,
395,
1467,
334,
11165,
12,
27210,
12,
1695,
395,
1467,
334,
12632,
12,
499,
2869,
12,
1695,
395,
1467,
334,
10233,
12,
499,
1887,
12,
1749,
395,
1467,
334,
7663,
12,
499,
2417,
12,
1749,
395,
1467,
334,
9892,
12,
499,
2466,
12,
1616,
395,
1467,
334,
10143,
12,
499,
1602,
12,
4119,
395,
1467,
334,
8982,
12,
499,
2260,
12,
4119,
395,
1467,
334,
11240,
12,
21883,
12,
3144,
395,
1467,
334,
12768,
12,
27077,
12,
4944,
395,
1467,
334,
11432,
12,
499,
1344,
12,
4329,
395,
1467,
334,
10037,
12,
499,
1153,
12,
4329,
395,
1467,
334,
7582,
12,
499,
2192,
12,
4114,
395,
1467,
334,
3933,
12,
499,
1651,
12,
3193,
395,
1467,
334,
7507,
12,
32584,
12,
5557,
395,
1467,
334,
7524,
12,
499,
1789,
12,
6155,
395,
1467,
334,
6019,
12,
499,
2025,
12,
5851,
395,
1467,
334,
7320,
12,
32319,
12,
3388,
395,
1467,
334,
1020,
12,
30630,
12,
7829,
395,
1467,
334,
3129,
12,
21237,
12,
6928,
395,
1467,
334,
1299,
12,
30301,
12,
6546,
395,
1467,
334,
2564,
12,
499,
1643,
12,
5504,
395,
1467,
334,
2114,
12,
31533,
12,
5661,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
chrber/dcache-docker
|
dcache/deps/.vim/bundle/jedi-vim/jedi/test/completion/descriptors.py
|
13
|
3399
|
class RevealAccess(object):
"""
A data descriptor that sets and returns values
normally and prints a message logging their access.
"""
def __init__(self, initval=None, name='var'):
self.val = initval
self.name = name
def __get__(self, obj, objtype):
print('Retrieving', self.name)
return self.val
def __set__(self, obj, val):
print('Updating', self.name)
self.val = val
def just_a_method(self):
pass
class C(object):
x = RevealAccess(10, 'var "x"')
#? RevealAccess()
x
#? ['just_a_method']
x.just_a_method
y = 5.0
def __init__(self):
#? int()
self.x
#? []
self.just_a_method
#? []
C.just_a_method
m = C()
#? int()
m.x
#? float()
m.y
#? int()
C.x
#? []
m.just_a_method
#? []
C.just_a_method
# -----------------
# properties
# -----------------
class B():
@property
def r(self):
return 1
@r.setter
def r(self, value):
return ''
def t(self):
return ''
p = property(t)
#? []
B().r()
#? int()
B().r
#? str()
B().p
#? []
B().p()
class PropClass():
def __init__(self, a):
self.a = a
@property
def ret(self):
return self.a
@ret.setter
def ret(self, value):
return 1.0
def ret2(self):
return self.a
ret2 = property(ret2)
@property
def nested(self):
""" causes recusions in properties, should work """
return self.ret
@property
def nested2(self):
""" causes recusions in properties, should not work """
return self.nested2
@property
def join1(self):
""" mutual recusion """
return self.join2
@property
def join2(self):
""" mutual recusion """
return self.join1
#? str()
PropClass("").ret
#? []
PropClass().ret.
#? str()
PropClass("").ret2
#?
PropClass().ret2
#? int()
PropClass(1).nested
#? []
PropClass().nested.
#?
PropClass(1).nested2
#? []
PropClass().nested2.
#?
PropClass(1).join1
# -----------------
# staticmethod/classmethod
# -----------------
class E(object):
a = ''
def __init__(self, a):
self.a = a
def f(x):
return x
f = staticmethod(f)
@staticmethod
def g(x):
return x
def s(cls, x):
return x
s = classmethod(s)
@classmethod
def t(cls, x):
return x
@classmethod
def u(cls, x):
return cls.a
e = E(1)
#? int()
e.f(1)
#? int()
E.f(1)
#? int()
e.g(1)
#? int()
E.g(1)
#? int()
e.s(1)
#? int()
E.s(1)
#? int()
e.t(1)
#? int()
E.t(1)
#? str()
e.u(1)
#? str()
E.u(1)
# -----------------
# Conditions
# -----------------
from functools import partial
class Memoize():
def __init__(self, func):
self.func = func
def __get__(self, obj, objtype):
if obj is None:
return self.func
return partial(self, obj)
def __call__(self, *args, **kwargs):
# We don't do caching here, but that's what would normally happen.
return self.func(*args, **kwargs)
class MemoizeTest():
def __init__(self, x):
self.x = x
@Memoize
def some_func(self):
return self.x
#? int()
MemoizeTest(10).some_func()
# Now also call the same function over the class (see if clause above).
#? float()
MemoizeTest.some_func(MemoizeTest(10.0))
|
gpl-3.0
|
[
533,
799,
432,
279,
3946,
8,
785,
304,
272,
408,
272,
437,
666,
5872,
626,
5951,
436,
2529,
1338,
272,
12252,
436,
14767,
282,
1245,
2050,
3932,
2879,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
4205,
637,
29,
403,
12,
536,
534,
1391,
735,
267,
291,
14,
637,
275,
4205,
637,
267,
291,
14,
354,
275,
536,
339,
347,
636,
362,
721,
277,
12,
1559,
12,
1559,
466,
304,
267,
870,
360,
6816,
11317,
4007,
297,
291,
14,
354,
9,
267,
372,
291,
14,
637,
339,
347,
636,
409,
721,
277,
12,
1559,
12,
1139,
304,
267,
870,
360,
24993,
297,
291,
14,
354,
9,
267,
291,
14,
637,
275,
1139,
339,
347,
2951,
63,
65,
63,
765,
8,
277,
304,
267,
986,
199,
199,
533,
445,
8,
785,
304,
272,
671,
275,
799,
432,
279,
3946,
8,
709,
12,
283,
1391,
298,
88,
9008,
272,
327,
31,
799,
432,
279,
3946,
342,
272,
671,
272,
327,
31,
788,
4764,
63,
65,
63,
765,
418,
272,
671,
14,
4764,
63,
65,
63,
765,
272,
612,
275,
959,
14,
16,
272,
347,
636,
826,
721,
277,
304,
267,
327,
31,
1109,
342,
267,
291,
14,
88,
398,
327,
31,
942,
267,
291,
14,
4764,
63,
65,
63,
765,
267,
327,
31,
942,
267,
445,
14,
4764,
63,
65,
63,
765,
199,
199,
77,
275,
445,
342,
199,
3,
31,
1109,
342,
199,
77,
14,
88,
199,
3,
31,
2069,
342,
199,
77,
14,
89,
199,
3,
31,
1109,
342,
199,
35,
14,
88,
199,
199,
3,
31,
942,
199,
77,
14,
4764,
63,
65,
63,
765,
199,
3,
31,
942,
199,
35,
14,
4764,
63,
65,
63,
765,
199,
199,
3,
10652,
13,
199,
3,
4382,
199,
3,
10652,
13,
199,
533,
699,
837,
272,
768,
1829,
272,
347,
519,
8,
277,
304,
267,
372,
413,
272,
768,
82,
14,
8345,
272,
347,
519,
8,
277,
12,
574,
304,
267,
372,
2125,
272,
347,
307,
8,
277,
304,
267,
372,
2125,
272,
299,
275,
3324,
8,
84,
9,
199,
199,
3,
31,
942,
199,
34,
1252,
82,
342,
199,
3,
31,
1109,
342,
199,
34,
1252,
82,
199,
199,
3,
31,
620,
342,
199,
34,
1252,
80,
199,
3,
31,
942,
199,
34,
1252,
80,
342,
199,
199,
533,
2165,
80,
2543,
837,
272,
347,
636,
826,
721,
277,
12,
282,
304,
267,
291,
14,
65,
275,
282,
272,
768,
1829,
272,
347,
2203,
8,
277,
304,
267,
372,
291,
14,
65,
339,
768,
3292,
14,
8345,
272,
347,
2203,
8,
277,
12,
574,
304,
267,
372,
413,
14,
16,
339,
347,
2203,
18,
8,
277,
304,
267,
372,
291,
14,
65,
272,
2203,
18,
275,
3324,
8,
3292,
18,
9,
339,
768,
1829,
272,
347,
6032,
8,
277,
304,
267,
408,
14486,
6488,
85,
1356,
315,
4382,
12,
1077,
1736,
408,
267,
372,
291,
14,
3292,
339,
768,
1829,
272,
347,
6032,
18,
8,
277,
304,
267,
408,
14486,
6488,
85,
1356,
315,
4382,
12,
1077,
440,
1736,
408,
267,
372,
291,
14,
6376,
18,
339,
768,
1829,
272,
347,
4263,
17,
8,
277,
304,
267,
408,
8567,
1061,
6488,
12444,
408,
267,
372,
291,
14,
904,
18,
339,
768,
1829,
272,
347,
4263,
18,
8,
277,
304,
267,
408,
8567,
1061,
6488,
12444,
408,
267,
372,
291,
14,
904,
17,
199,
199,
3,
31,
620,
342,
199,
9955,
2543,
25639,
3292,
199,
3,
31,
942,
199,
9955,
2543,
1252,
3292,
14,
199,
199,
3,
31,
620,
342,
199,
9955,
2543,
25639,
3292,
18,
199,
3,
31,
221,
199,
9955,
2543,
1252,
3292,
18,
199,
199,
3,
31,
1109,
342,
199,
9955,
2543,
8,
17,
680,
6376,
199,
3,
31,
942,
199,
9955,
2543,
1252,
6376,
14,
199,
199,
3,
31,
221,
199,
9955,
2543,
8,
17,
680,
6376,
18,
199,
3,
31,
942,
199,
9955,
2543,
1252,
6376,
18,
14,
199,
199,
3,
31,
221,
199,
9955,
2543,
8,
17,
680,
904,
17,
199,
3,
10652,
13,
199,
3,
12822,
15,
3744,
199,
3,
10652,
13,
199,
199,
533,
662,
8,
785,
304,
272,
282,
275,
2125,
272,
347,
636,
826,
721,
277,
12,
282,
304,
267,
291,
14,
65,
275,
282,
339,
347,
289,
8,
88,
304,
267,
372,
671,
272,
289,
275,
12822,
8,
70,
9,
339,
768,
4639,
272,
347,
486,
8,
88,
304,
267,
372,
671,
339,
347,
308,
8,
1886,
12,
671,
304,
267,
372,
671,
272,
308,
275,
18990,
8,
83,
9,
339,
768,
3744,
272,
347,
307,
8,
1886,
12,
671,
304,
267,
372,
671,
339,
768,
3744,
272,
347,
399,
8,
1886,
12,
671,
304,
267,
372,
843,
14,
65,
199,
199,
69,
275,
662,
8,
17,
9,
199,
3,
31,
1109,
342,
199,
69,
14,
70,
8,
17,
9,
199,
3,
31,
1109,
342,
199,
37,
14,
70,
8,
17,
9,
199,
3,
31,
1109,
342,
199,
69,
14,
71,
8,
17,
9,
199,
3,
31,
1109,
342,
199,
37,
14,
71,
8,
17,
9,
199,
199,
3,
31,
1109,
342,
199,
69,
14,
83,
8,
17,
9,
199,
3,
31,
1109,
342,
199,
37,
14,
83,
8,
17,
9,
199,
3,
31,
1109,
342,
199,
69,
14,
84,
8,
17,
9,
199,
3,
31,
1109,
342,
199,
37,
14,
84,
8,
17,
9,
199,
199,
3,
31,
620,
342,
199,
69,
14,
85,
8,
17,
9,
199,
3,
31,
620,
342,
199,
37,
14,
85,
8,
17,
9,
199,
199,
3,
10652,
13,
199,
3,
1448,
3138,
199,
3,
10652,
13,
199,
199,
504,
9143,
492,
7417,
421,
199,
533,
3194,
573,
794,
837,
272,
347,
636,
826,
721,
277,
12,
2562,
304,
267,
291,
14,
1532,
275,
2562,
339,
347,
636,
362,
721,
277,
12,
1559,
12,
1559,
466,
304,
267,
340,
1559,
365,
488,
26,
288,
372,
291,
14,
1532,
398,
372,
7417,
8,
277,
12,
1559,
9,
339,
347,
636,
1250,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
327,
2136,
2793,
1133,
886,
13627,
2348,
12,
1325,
626,
1159,
4052,
3955,
12252,
5992,
14,
267,
372,
291,
14,
1532,
2031,
589,
12,
1011,
958,
9,
421,
199,
533,
3194,
573,
794,
774,
837,
272
] |
[
799,
432,
279,
3946,
8,
785,
304,
272,
408,
272,
437,
666,
5872,
626,
5951,
436,
2529,
1338,
272,
12252,
436,
14767,
282,
1245,
2050,
3932,
2879,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
4205,
637,
29,
403,
12,
536,
534,
1391,
735,
267,
291,
14,
637,
275,
4205,
637,
267,
291,
14,
354,
275,
536,
339,
347,
636,
362,
721,
277,
12,
1559,
12,
1559,
466,
304,
267,
870,
360,
6816,
11317,
4007,
297,
291,
14,
354,
9,
267,
372,
291,
14,
637,
339,
347,
636,
409,
721,
277,
12,
1559,
12,
1139,
304,
267,
870,
360,
24993,
297,
291,
14,
354,
9,
267,
291,
14,
637,
275,
1139,
339,
347,
2951,
63,
65,
63,
765,
8,
277,
304,
267,
986,
199,
199,
533,
445,
8,
785,
304,
272,
671,
275,
799,
432,
279,
3946,
8,
709,
12,
283,
1391,
298,
88,
9008,
272,
327,
31,
799,
432,
279,
3946,
342,
272,
671,
272,
327,
31,
788,
4764,
63,
65,
63,
765,
418,
272,
671,
14,
4764,
63,
65,
63,
765,
272,
612,
275,
959,
14,
16,
272,
347,
636,
826,
721,
277,
304,
267,
327,
31,
1109,
342,
267,
291,
14,
88,
398,
327,
31,
942,
267,
291,
14,
4764,
63,
65,
63,
765,
267,
327,
31,
942,
267,
445,
14,
4764,
63,
65,
63,
765,
199,
199,
77,
275,
445,
342,
199,
3,
31,
1109,
342,
199,
77,
14,
88,
199,
3,
31,
2069,
342,
199,
77,
14,
89,
199,
3,
31,
1109,
342,
199,
35,
14,
88,
199,
199,
3,
31,
942,
199,
77,
14,
4764,
63,
65,
63,
765,
199,
3,
31,
942,
199,
35,
14,
4764,
63,
65,
63,
765,
199,
199,
3,
10652,
13,
199,
3,
4382,
199,
3,
10652,
13,
199,
533,
699,
837,
272,
768,
1829,
272,
347,
519,
8,
277,
304,
267,
372,
413,
272,
768,
82,
14,
8345,
272,
347,
519,
8,
277,
12,
574,
304,
267,
372,
2125,
272,
347,
307,
8,
277,
304,
267,
372,
2125,
272,
299,
275,
3324,
8,
84,
9,
199,
199,
3,
31,
942,
199,
34,
1252,
82,
342,
199,
3,
31,
1109,
342,
199,
34,
1252,
82,
199,
199,
3,
31,
620,
342,
199,
34,
1252,
80,
199,
3,
31,
942,
199,
34,
1252,
80,
342,
199,
199,
533,
2165,
80,
2543,
837,
272,
347,
636,
826,
721,
277,
12,
282,
304,
267,
291,
14,
65,
275,
282,
272,
768,
1829,
272,
347,
2203,
8,
277,
304,
267,
372,
291,
14,
65,
339,
768,
3292,
14,
8345,
272,
347,
2203,
8,
277,
12,
574,
304,
267,
372,
413,
14,
16,
339,
347,
2203,
18,
8,
277,
304,
267,
372,
291,
14,
65,
272,
2203,
18,
275,
3324,
8,
3292,
18,
9,
339,
768,
1829,
272,
347,
6032,
8,
277,
304,
267,
408,
14486,
6488,
85,
1356,
315,
4382,
12,
1077,
1736,
408,
267,
372,
291,
14,
3292,
339,
768,
1829,
272,
347,
6032,
18,
8,
277,
304,
267,
408,
14486,
6488,
85,
1356,
315,
4382,
12,
1077,
440,
1736,
408,
267,
372,
291,
14,
6376,
18,
339,
768,
1829,
272,
347,
4263,
17,
8,
277,
304,
267,
408,
8567,
1061,
6488,
12444,
408,
267,
372,
291,
14,
904,
18,
339,
768,
1829,
272,
347,
4263,
18,
8,
277,
304,
267,
408,
8567,
1061,
6488,
12444,
408,
267,
372,
291,
14,
904,
17,
199,
199,
3,
31,
620,
342,
199,
9955,
2543,
25639,
3292,
199,
3,
31,
942,
199,
9955,
2543,
1252,
3292,
14,
199,
199,
3,
31,
620,
342,
199,
9955,
2543,
25639,
3292,
18,
199,
3,
31,
221,
199,
9955,
2543,
1252,
3292,
18,
199,
199,
3,
31,
1109,
342,
199,
9955,
2543,
8,
17,
680,
6376,
199,
3,
31,
942,
199,
9955,
2543,
1252,
6376,
14,
199,
199,
3,
31,
221,
199,
9955,
2543,
8,
17,
680,
6376,
18,
199,
3,
31,
942,
199,
9955,
2543,
1252,
6376,
18,
14,
199,
199,
3,
31,
221,
199,
9955,
2543,
8,
17,
680,
904,
17,
199,
3,
10652,
13,
199,
3,
12822,
15,
3744,
199,
3,
10652,
13,
199,
199,
533,
662,
8,
785,
304,
272,
282,
275,
2125,
272,
347,
636,
826,
721,
277,
12,
282,
304,
267,
291,
14,
65,
275,
282,
339,
347,
289,
8,
88,
304,
267,
372,
671,
272,
289,
275,
12822,
8,
70,
9,
339,
768,
4639,
272,
347,
486,
8,
88,
304,
267,
372,
671,
339,
347,
308,
8,
1886,
12,
671,
304,
267,
372,
671,
272,
308,
275,
18990,
8,
83,
9,
339,
768,
3744,
272,
347,
307,
8,
1886,
12,
671,
304,
267,
372,
671,
339,
768,
3744,
272,
347,
399,
8,
1886,
12,
671,
304,
267,
372,
843,
14,
65,
199,
199,
69,
275,
662,
8,
17,
9,
199,
3,
31,
1109,
342,
199,
69,
14,
70,
8,
17,
9,
199,
3,
31,
1109,
342,
199,
37,
14,
70,
8,
17,
9,
199,
3,
31,
1109,
342,
199,
69,
14,
71,
8,
17,
9,
199,
3,
31,
1109,
342,
199,
37,
14,
71,
8,
17,
9,
199,
199,
3,
31,
1109,
342,
199,
69,
14,
83,
8,
17,
9,
199,
3,
31,
1109,
342,
199,
37,
14,
83,
8,
17,
9,
199,
3,
31,
1109,
342,
199,
69,
14,
84,
8,
17,
9,
199,
3,
31,
1109,
342,
199,
37,
14,
84,
8,
17,
9,
199,
199,
3,
31,
620,
342,
199,
69,
14,
85,
8,
17,
9,
199,
3,
31,
620,
342,
199,
37,
14,
85,
8,
17,
9,
199,
199,
3,
10652,
13,
199,
3,
1448,
3138,
199,
3,
10652,
13,
199,
199,
504,
9143,
492,
7417,
421,
199,
533,
3194,
573,
794,
837,
272,
347,
636,
826,
721,
277,
12,
2562,
304,
267,
291,
14,
1532,
275,
2562,
339,
347,
636,
362,
721,
277,
12,
1559,
12,
1559,
466,
304,
267,
340,
1559,
365,
488,
26,
288,
372,
291,
14,
1532,
398,
372,
7417,
8,
277,
12,
1559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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
michelts/lettuce
|
tests/integration/lib/Django-1.2.5/django/conf/locale/no/formats.py
|
236
|
1277
|
DATE_FORMAT = 'j. F Y'
TIME_FORMAT = 'H:i'
DATETIME_FORMAT = 'j. F Y H:i'
YEAR_MONTH_FORMAT = 'F Y'
MONTH_DAY_FORMAT = 'j. F'
SHORT_DATE_FORMAT = 'd.m.Y'
SHORT_DATETIME_FORMAT = 'd.m.Y H:i'
FIRST_DAY_OF_WEEK = 1 # Monday
DATE_INPUT_FORMATS = (
'%Y-%m-%d', '%j.%m.%Y', '%j.%m.%y', # '2006-10-25', '25.10.2006', '25.10.06'
'%Y-%m-%j', # '2006-10-25',
# '%j. %b %Y', '%j %b %Y', # '25. okt 2006', '25 okt 2006'
# '%j. %b. %Y', '%j %b. %Y', # '25. okt. 2006', '25 okt. 2006'
# '%j. %B %Y', '%j %B %Y', # '25. oktober 2006', '25 oktober 2006'
)
TIME_INPUT_FORMATS = (
'%H:%M:%S', # '14:30:59'
'%H:%M', # '14:30'
)
DATETIME_INPUT_FORMATS = (
'%Y-%m-%d %H:%M:%S', # '2006-10-25 14:30:59'
'%Y-%m-%d %H:%M', # '2006-10-25 14:30'
'%Y-%m-%d', # '2006-10-25'
'%Y-%m-%j', # '2006-10-25'
'%j.%m.%Y %H:%M:%S', # '25.10.2006 14:30:59'
'%j.%m.%Y %H:%M', # '25.10.2006 14:30'
'%j.%m.%Y', # '25.10.2006'
'%j.%m.%y %H:%M:%S', # '25.10.06 14:30:59'
'%j.%m.%y %H:%M', # '25.10.06 14:30'
'%j.%m.%y', # '25.10.06'
)
DECIMAL_SEPARATOR = ','
THOUSAND_SEPARATOR = ' '
NUMBER_GROUPING = 3
|
gpl-3.0
|
[
5390,
63,
4807,
275,
283,
74,
14,
481,
1488,
7,
199,
4961,
63,
4807,
275,
283,
40,
26,
73,
7,
199,
12488,
63,
4807,
275,
283,
74,
14,
481,
1488,
869,
26,
73,
7,
199,
19216,
63,
16413,
63,
4807,
275,
283,
38,
1488,
7,
199,
16413,
63,
11655,
63,
4807,
275,
283,
74,
14,
481,
7,
199,
13003,
63,
5390,
63,
4807,
275,
283,
68,
14,
77,
14,
57,
7,
199,
13003,
63,
12488,
63,
4807,
275,
283,
68,
14,
77,
14,
57,
869,
26,
73,
7,
199,
12903,
63,
11655,
63,
3359,
63,
24929,
275,
413,
327,
32740,
199,
5390,
63,
7321,
63,
14019,
275,
334,
272,
1543,
57,
3295,
77,
3295,
68,
297,
1543,
74,
4111,
77,
4111,
57,
297,
1543,
74,
4111,
77,
4111,
89,
297,
327,
283,
7968,
13,
709,
13,
821,
297,
283,
821,
14,
709,
14,
7968,
297,
283,
821,
14,
709,
14,
1690,
7,
272,
1543,
57,
3295,
77,
3295,
74,
297,
12793,
327,
283,
7968,
13,
709,
13,
821,
297,
272,
327,
1543,
74,
14,
450,
66,
450,
57,
297,
1543,
74,
450,
66,
450,
57,
297,
3322,
327,
283,
821,
14,
4112,
84,
8315,
297,
283,
821,
4112,
84,
8315,
7,
272,
327,
1543,
74,
14,
450,
66,
14,
450,
57,
297,
1543,
74,
450,
66,
14,
450,
57,
297,
3515,
327,
283,
821,
14,
4112,
84,
14,
8315,
297,
283,
821,
4112,
84,
14,
8315,
7,
272,
327,
1543,
74,
14,
450,
34,
450,
57,
297,
1543,
74,
450,
34,
450,
57,
297,
3322,
327,
283,
821,
14,
4112,
475,
605,
8315,
297,
283,
821,
4112,
475,
605,
8315,
7,
199,
9,
199,
4961,
63,
7321,
63,
14019,
275,
334,
272,
1543,
40,
2689,
45,
2689,
51,
297,
258,
327,
283,
1079,
26,
1216,
26,
1427,
7,
272,
1543,
40,
2689,
45,
297,
258,
327,
283,
1079,
26,
1216,
7,
199,
9,
199,
12488,
63,
7321,
63,
14019,
275,
334,
272,
1543,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
297,
258,
327,
283,
7968,
13,
709,
13,
821,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
297,
263,
327,
283,
7968,
13,
709,
13,
821,
4329,
26,
1216,
7,
272,
1543,
57,
3295,
77,
3295,
68,
297,
4519,
327,
283,
7968,
13,
709,
13,
821,
7,
272,
1543,
57,
3295,
77,
3295,
74,
297,
4519,
327,
283,
7968,
13,
709,
13,
821,
7,
272,
1543,
74,
4111,
77,
4111,
57,
450,
40,
2689,
45,
2689,
51,
297,
258,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
74,
4111,
77,
4111,
57,
450,
40,
2689,
45,
297,
263,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
7,
272,
1543,
74,
4111,
77,
4111,
57,
297,
4519,
327,
283,
821,
14,
709,
14,
7968,
7,
272,
1543,
74,
4111,
77,
4111,
89,
450,
40,
2689,
45,
2689,
51,
297,
258,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
74,
4111,
77,
4111,
89,
450,
40,
2689,
45,
297,
263,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
7,
272,
1543,
74,
4111,
77,
4111,
89,
297,
4519,
327,
283,
821,
14,
709,
14,
1690,
7,
199,
9,
199,
23925,
63,
15828,
275,
13647,
199,
28714,
63,
15828,
275,
283,
283,
199,
9190,
63,
7823,
1206,
275,
650,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
63,
4807,
275,
283,
74,
14,
481,
1488,
7,
199,
4961,
63,
4807,
275,
283,
40,
26,
73,
7,
199,
12488,
63,
4807,
275,
283,
74,
14,
481,
1488,
869,
26,
73,
7,
199,
19216,
63,
16413,
63,
4807,
275,
283,
38,
1488,
7,
199,
16413,
63,
11655,
63,
4807,
275,
283,
74,
14,
481,
7,
199,
13003,
63,
5390,
63,
4807,
275,
283,
68,
14,
77,
14,
57,
7,
199,
13003,
63,
12488,
63,
4807,
275,
283,
68,
14,
77,
14,
57,
869,
26,
73,
7,
199,
12903,
63,
11655,
63,
3359,
63,
24929,
275,
413,
327,
32740,
199,
5390,
63,
7321,
63,
14019,
275,
334,
272,
1543,
57,
3295,
77,
3295,
68,
297,
1543,
74,
4111,
77,
4111,
57,
297,
1543,
74,
4111,
77,
4111,
89,
297,
327,
283,
7968,
13,
709,
13,
821,
297,
283,
821,
14,
709,
14,
7968,
297,
283,
821,
14,
709,
14,
1690,
7,
272,
1543,
57,
3295,
77,
3295,
74,
297,
12793,
327,
283,
7968,
13,
709,
13,
821,
297,
272,
327,
1543,
74,
14,
450,
66,
450,
57,
297,
1543,
74,
450,
66,
450,
57,
297,
3322,
327,
283,
821,
14,
4112,
84,
8315,
297,
283,
821,
4112,
84,
8315,
7,
272,
327,
1543,
74,
14,
450,
66,
14,
450,
57,
297,
1543,
74,
450,
66,
14,
450,
57,
297,
3515,
327,
283,
821,
14,
4112,
84,
14,
8315,
297,
283,
821,
4112,
84,
14,
8315,
7,
272,
327,
1543,
74,
14,
450,
34,
450,
57,
297,
1543,
74,
450,
34,
450,
57,
297,
3322,
327,
283,
821,
14,
4112,
475,
605,
8315,
297,
283,
821,
4112,
475,
605,
8315,
7,
199,
9,
199,
4961,
63,
7321,
63,
14019,
275,
334,
272,
1543,
40,
2689,
45,
2689,
51,
297,
258,
327,
283,
1079,
26,
1216,
26,
1427,
7,
272,
1543,
40,
2689,
45,
297,
258,
327,
283,
1079,
26,
1216,
7,
199,
9,
199,
12488,
63,
7321,
63,
14019,
275,
334,
272,
1543,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
297,
258,
327,
283,
7968,
13,
709,
13,
821,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
297,
263,
327,
283,
7968,
13,
709,
13,
821,
4329,
26,
1216,
7,
272,
1543,
57,
3295,
77,
3295,
68,
297,
4519,
327,
283,
7968,
13,
709,
13,
821,
7,
272,
1543,
57,
3295,
77,
3295,
74,
297,
4519,
327,
283,
7968,
13,
709,
13,
821,
7,
272,
1543,
74,
4111,
77,
4111,
57,
450,
40,
2689,
45,
2689,
51,
297,
258,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
74,
4111,
77,
4111,
57,
450,
40,
2689,
45,
297,
263,
327,
283,
821,
14,
709,
14,
7968,
4329,
26,
1216,
7,
272,
1543,
74,
4111,
77,
4111,
57,
297,
4519,
327,
283,
821,
14,
709,
14,
7968,
7,
272,
1543,
74,
4111,
77,
4111,
89,
450,
40,
2689,
45,
2689,
51,
297,
258,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
74,
4111,
77,
4111,
89,
450,
40,
2689,
45,
297,
263,
327,
283,
821,
14,
709,
14,
1690,
4329,
26,
1216,
7,
272,
1543,
74,
4111,
77,
4111,
89,
297,
4519,
327,
283,
821,
14,
709,
14,
1690,
7,
199,
9,
199,
23925,
63,
15828,
275,
13647,
199,
28714,
63,
15828,
275,
283,
283,
199,
9190,
63,
7823,
1206,
275,
650,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Juanvulcano/zulip
|
bots/jabber_mirror.py
|
21
|
2196
|
#!/usr/bin/env python
# Copyright (C) 2014 Zulip, Inc.
#
# 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
import sys
import subprocess
import os
import traceback
import signal
from types import FrameType
from typing import Any
from zulip import RandomExponentialBackoff
def die(signal, frame):
# type: (int, FrameType) -> None
"""We actually want to exit, so run os._exit (so as not to be caught and restarted)"""
os._exit(1)
signal.signal(signal.SIGINT, die)
args = [os.path.join(os.path.dirname(sys.argv[0]), "jabber_mirror_backend.py")]
args.extend(sys.argv[1:])
backoff = RandomExponentialBackoff(timeout_success_equivalent=300)
while backoff.keep_going():
print("Starting Jabber mirroring bot")
try:
ret = subprocess.call(args)
except:
traceback.print_exc()
else:
if ret == 2:
# Don't try again on initial configuration errors
sys.exit(ret)
backoff.fail()
print("")
print("")
print("ERROR: The Jabber mirroring bot is unable to continue mirroring Jabber.")
print("Please contact zulip-devel@googlegroups.com if you need assistance.")
print("")
sys.exit(1)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
35,
9,
6927,
3107,
11294,
12,
3277,
14,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
199,
3,
12408,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
199,
3,
334,
1589,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
199,
3,
5893,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
199,
3,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
199,
3,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
199,
3,
5420,
370,
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,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
199,
3,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
199,
3,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
199,
3,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
199,
3,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
984,
199,
646,
3873,
199,
646,
747,
199,
646,
5190,
199,
646,
4673,
199,
504,
2943,
492,
11726,
804,
199,
504,
14090,
492,
6184,
199,
504,
1315,
11294,
492,
9571,
21079,
4540,
1997,
199,
199,
318,
18833,
8,
4653,
12,
2787,
304,
272,
327,
730,
26,
334,
442,
12,
11726,
804,
9,
1035,
488,
272,
408,
6004,
5965,
2934,
370,
4458,
12,
880,
1255,
747,
423,
2224,
334,
1152,
465,
440,
370,
506,
15604,
436,
32277,
9471,
272,
747,
423,
2224,
8,
17,
9,
199,
199,
4653,
14,
4653,
8,
4653,
14,
21223,
12,
18833,
9,
199,
199,
589,
275,
359,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
2522,
298,
25075,
63,
12324,
63,
4620,
14,
647,
11323,
199,
589,
14,
2880,
8,
1274,
14,
3020,
59,
17,
5728,
199,
199,
21061,
275,
9571,
21079,
4540,
1997,
8,
2593,
63,
3742,
63,
24179,
29,
5863,
9,
199,
6710,
22735,
14,
3250,
63,
10947,
837,
272,
870,
480,
14139,
1603,
20280,
15216,
316,
5888,
531,
272,
862,
26,
267,
2203,
275,
3873,
14,
1250,
8,
589,
9,
272,
871,
26,
267,
5190,
14,
1361,
63,
2804,
342,
272,
587,
26,
267,
340,
2203,
508,
499,
26,
288,
327,
7529,
1133,
862,
4020,
641,
2536,
2897,
2552,
288,
984,
14,
2224,
8,
3292,
9,
339,
22735,
14,
1633,
342,
199,
199,
1361,
10804,
199,
1361,
10804,
199,
1361,
480,
3170,
26,
710,
1603,
20280,
15216,
316,
5888,
365,
17329,
370,
1980,
15216,
316,
1603,
20280,
2685,
199,
1361,
480,
8254,
8966,
1315,
11294,
13,
27870,
32,
3098,
2634,
14,
957,
340,
1265,
1929,
465,
338,
611,
2685,
199,
1361,
10804,
199,
1274,
14,
2224,
8,
17,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
35,
9,
6927,
3107,
11294,
12,
3277,
14,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
199,
3,
12408,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
199,
3,
334,
1589,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
199,
3,
5893,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
199,
3,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
199,
3,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
199,
3,
5420,
370,
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,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
199,
3,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
199,
3,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
199,
3,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
199,
3,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
984,
199,
646,
3873,
199,
646,
747,
199,
646,
5190,
199,
646,
4673,
199,
504,
2943,
492,
11726,
804,
199,
504,
14090,
492,
6184,
199,
504,
1315,
11294,
492,
9571,
21079,
4540,
1997,
199,
199,
318,
18833,
8,
4653,
12,
2787,
304,
272,
327,
730,
26,
334,
442,
12,
11726,
804,
9,
1035,
488,
272,
408,
6004,
5965,
2934,
370,
4458,
12,
880,
1255,
747,
423,
2224,
334,
1152,
465,
440,
370,
506,
15604,
436,
32277,
9471,
272,
747,
423,
2224,
8,
17,
9,
199,
199,
4653,
14,
4653,
8,
4653,
14,
21223,
12,
18833,
9,
199,
199,
589,
275,
359,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
2522,
298,
25075,
63,
12324,
63,
4620,
14,
647,
11323,
199,
589,
14,
2880,
8,
1274,
14,
3020,
59,
17,
5728,
199,
199,
21061,
275,
9571,
21079,
4540,
1997,
8,
2593,
63,
3742,
63,
24179,
29,
5863,
9,
199,
6710,
22735,
14,
3250,
63,
10947,
837,
272,
870,
480,
14139,
1603,
20280,
15216,
316,
5888,
531,
272,
862,
26,
267,
2203,
275,
3873,
14,
1250,
8,
589,
9,
272,
871,
26,
267,
5190,
14,
1361,
63,
2804,
342,
272,
587,
26,
267,
340,
2203,
508,
499,
26,
288,
327,
7529,
1133,
862,
4020,
641,
2536,
2897,
2552,
288,
984,
14,
2224,
8,
3292,
9,
339,
22735,
14,
1633,
342,
199,
199,
1361,
10804,
199,
1361,
10804,
199,
1361,
480,
3170,
26,
710,
1603,
20280,
15216,
316,
5888,
365,
17329,
370,
1980,
15216,
316,
1603,
20280,
2685,
199,
1361,
480,
8254,
8966,
1315,
11294,
13,
27870,
32,
3098,
2634,
14,
957,
340,
1265,
1929,
465,
338,
611,
2685,
199,
1361,
10804,
199,
1274,
14,
2224,
8,
17,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Immortalin/python-for-android
|
python-modules/twisted/twisted/protocols/stateful.py
|
61
|
1722
|
# -*- test-case-name: twisted.test.test_stateful -*-
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
# See LICENSE for details.
from twisted.internet import protocol
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
class StatefulProtocol(protocol.Protocol):
"""A Protocol that stores state for you.
state is a pair (function, num_bytes). When num_bytes bytes of data arrives
from the network, function is called. It is expected to return the next
state or None to keep same state. Initial state is returned by
getInitialState (override it).
"""
_sful_data = None, None, 0
def makeConnection(self, transport):
protocol.Protocol.makeConnection(self, transport)
self._sful_data = self.getInitialState(), StringIO(), 0
def getInitialState(self):
raise NotImplementedError
def dataReceived(self, data):
state, buffer, offset = self._sful_data
buffer.seek(0, 2)
buffer.write(data)
blen = buffer.tell() # how many bytes total is in the buffer
buffer.seek(offset)
while blen - offset >= state[1]:
d = buffer.read(state[1])
offset += state[1]
next = state[0](d)
if self.transport.disconnecting: # XXX: argh stupid hack borrowed right from LineReceiver
return # dataReceived won't be called again, so who cares about consistent state
if next:
state = next
if offset != 0:
b = buffer.read()
buffer.seek(0)
buffer.truncate()
buffer.write(b)
offset = 0
self._sful_data = state, buffer, offset
|
apache-2.0
|
[
3,
1882,
511,
13,
2546,
13,
354,
26,
7390,
14,
396,
14,
396,
63,
929,
1893,
1882,
199,
199,
3,
1898,
334,
67,
9,
12521,
13,
15431,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
421,
199,
504,
7390,
14,
4901,
492,
4113,
199,
199,
893,
26,
272,
687,
15073,
492,
5228,
199,
2590,
3545,
26,
272,
687,
5228,
492,
5228,
199,
199,
533,
8511,
1893,
3658,
8,
3922,
14,
3658,
304,
272,
408,
33,
11557,
626,
14086,
1174,
367,
1265,
14,
339,
1174,
365,
282,
4092,
334,
1593,
12,
1967,
63,
2394,
680,
3979,
1967,
63,
2394,
2783,
402,
666,
601,
322,
2310,
272,
687,
314,
2784,
12,
805,
365,
2797,
14,
2779,
365,
1420,
370,
372,
314,
2163,
272,
1174,
503,
488,
370,
4215,
2011,
1174,
14,
6026,
1174,
365,
2138,
701,
272,
664,
5733,
2223,
334,
4415,
652,
680,
272,
408,
272,
485,
83,
1893,
63,
576,
275,
488,
12,
488,
12,
378,
339,
347,
1852,
3225,
8,
277,
12,
7773,
304,
267,
4113,
14,
3658,
14,
1875,
3225,
8,
277,
12,
7773,
9,
267,
291,
423,
83,
1893,
63,
576,
275,
291,
14,
362,
5733,
2223,
1062,
5228,
1062,
378,
339,
347,
664,
5733,
2223,
8,
277,
304,
267,
746,
4279,
339,
347,
666,
9392,
8,
277,
12,
666,
304,
267,
1174,
12,
3335,
12,
3268,
275,
291,
423,
83,
1893,
63,
576,
267,
3335,
14,
5507,
8,
16,
12,
499,
9,
267,
3335,
14,
952,
8,
576,
9,
267,
330,
552,
275,
3335,
14,
9974,
342,
327,
4212,
5002,
2783,
3141,
365,
315,
314,
3335,
267,
3335,
14,
5507,
8,
2743,
9,
267,
1830,
330,
552,
446,
3268,
2356,
1174,
59,
17,
2189,
288,
366,
275,
3335,
14,
739,
8,
929,
59,
17,
566,
288,
3268,
847,
1174,
59,
17,
61,
288,
2163,
275,
1174,
59,
16,
8738,
68,
9,
288,
340,
291,
14,
5545,
14,
10673,
316,
26,
327,
5787,
26,
1680,
72,
410,
31596,
11176,
330,
19598,
379,
2451,
687,
7030,
21800,
355,
372,
327,
666,
9392,
7859,
1133,
506,
2797,
4020,
12,
880,
3963,
1704,
470,
3595,
12137,
1174,
288,
340,
2163,
26,
355,
1174,
275,
2163,
267,
340,
3268,
1137,
378,
26,
288,
330,
275,
3335,
14,
739,
342,
288,
3335,
14,
5507,
8,
16,
9,
288,
3335,
14,
12517,
342,
288,
3335,
14,
952,
8,
66,
9,
288,
3268,
275,
378,
267,
291,
423,
83,
1893,
63,
576,
275,
1174,
12,
3335,
12,
3268,
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
] |
[
1882,
511,
13,
2546,
13,
354,
26,
7390,
14,
396,
14,
396,
63,
929,
1893,
1882,
199,
199,
3,
1898,
334,
67,
9,
12521,
13,
15431,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
421,
199,
504,
7390,
14,
4901,
492,
4113,
199,
199,
893,
26,
272,
687,
15073,
492,
5228,
199,
2590,
3545,
26,
272,
687,
5228,
492,
5228,
199,
199,
533,
8511,
1893,
3658,
8,
3922,
14,
3658,
304,
272,
408,
33,
11557,
626,
14086,
1174,
367,
1265,
14,
339,
1174,
365,
282,
4092,
334,
1593,
12,
1967,
63,
2394,
680,
3979,
1967,
63,
2394,
2783,
402,
666,
601,
322,
2310,
272,
687,
314,
2784,
12,
805,
365,
2797,
14,
2779,
365,
1420,
370,
372,
314,
2163,
272,
1174,
503,
488,
370,
4215,
2011,
1174,
14,
6026,
1174,
365,
2138,
701,
272,
664,
5733,
2223,
334,
4415,
652,
680,
272,
408,
272,
485,
83,
1893,
63,
576,
275,
488,
12,
488,
12,
378,
339,
347,
1852,
3225,
8,
277,
12,
7773,
304,
267,
4113,
14,
3658,
14,
1875,
3225,
8,
277,
12,
7773,
9,
267,
291,
423,
83,
1893,
63,
576,
275,
291,
14,
362,
5733,
2223,
1062,
5228,
1062,
378,
339,
347,
664,
5733,
2223,
8,
277,
304,
267,
746,
4279,
339,
347,
666,
9392,
8,
277,
12,
666,
304,
267,
1174,
12,
3335,
12,
3268,
275,
291,
423,
83,
1893,
63,
576,
267,
3335,
14,
5507,
8,
16,
12,
499,
9,
267,
3335,
14,
952,
8,
576,
9,
267,
330,
552,
275,
3335,
14,
9974,
342,
327,
4212,
5002,
2783,
3141,
365,
315,
314,
3335,
267,
3335,
14,
5507,
8,
2743,
9,
267,
1830,
330,
552,
446,
3268,
2356,
1174,
59,
17,
2189,
288,
366,
275,
3335,
14,
739,
8,
929,
59,
17,
566,
288,
3268,
847,
1174,
59,
17,
61,
288,
2163,
275,
1174,
59,
16,
8738,
68,
9,
288,
340,
291,
14,
5545,
14,
10673,
316,
26,
327,
5787,
26,
1680,
72,
410,
31596,
11176,
330,
19598,
379,
2451,
687,
7030,
21800,
355,
372,
327,
666,
9392,
7859,
1133,
506,
2797,
4020,
12,
880,
3963,
1704,
470,
3595,
12137,
1174,
288,
340,
2163,
26,
355,
1174,
275,
2163,
267,
340,
3268,
1137,
378,
26,
288,
330,
275,
3335,
14,
739,
342,
288,
3335,
14,
5507,
8,
16,
9,
288,
3335,
14,
12517,
342,
288,
3335,
14,
952,
8,
66,
9,
288,
3268,
275,
378,
267,
291,
423,
83,
1893,
63,
576,
275,
1174,
12,
3335,
12,
3268,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Denisolt/Tensorflow_Chat_Bot
|
local/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/random_forest_test.py
|
15
|
2949
|
# 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 TensorForestTrainer."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import tensorflow as tf
class TensorForestTrainerTests(tf.test.TestCase):
def testClassification(self):
"""Tests multi-class classification using matrix data as input."""
hparams = tf.contrib.tensor_forest.python.tensor_forest.ForestHParams(
num_trees=3, max_nodes=1000, num_classes=3, num_features=4,
split_after_samples=20)
classifier = tf.contrib.learn.TensorForestEstimator(hparams.fill())
iris = tf.contrib.learn.datasets.load_iris()
data = iris.data.astype(np.float32)
labels = iris.target.astype(np.float32)
classifier.fit(x=data, y=labels, steps=100, batch_size=50)
classifier.evaluate(x=data, y=labels, steps=10)
def testClassificationTrainingLoss(self):
"""Tests multi-class classification using matrix data as input."""
hparams = tf.contrib.tensor_forest.python.tensor_forest.ForestHParams(
num_trees=3, max_nodes=1000, num_classes=3, num_features=4)
classifier = tf.contrib.learn.TensorForestEstimator(
hparams, graph_builder_class=(
tf.contrib.tensor_forest.python.tensor_forest.TrainingLossForest))
iris = tf.contrib.learn.datasets.load_iris()
data = iris.data.astype(np.float32)
labels = iris.target.astype(np.float32)
monitors = [tf.contrib.learn.TensorForestLossHook(10)]
classifier.fit(x=data, y=labels, steps=100, monitors=monitors)
classifier.evaluate(x=data, y=labels, steps=10)
def testRegression(self):
"""Tests multi-class classification using matrix data as input."""
hparams = tf.contrib.tensor_forest.python.tensor_forest.ForestHParams(
num_trees=3, max_nodes=1000, num_classes=1, num_features=13,
regression=True, split_after_samples=20)
regressor = tf.contrib.learn.TensorForestEstimator(hparams.fill())
boston = tf.contrib.learn.datasets.load_boston()
data = boston.data.astype(np.float32)
labels = boston.target.astype(np.float32)
regressor.fit(x=data, y=labels, steps=100, batch_size=50)
regressor.evaluate(x=data, y=labels, steps=10)
if __name__ == '__main__':
tf.test.main()
|
gpl-3.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
199,
624,
2925,
367,
5878,
21668,
2437,
16187,
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,
646,
3228,
465,
2833,
421,
199,
533,
5878,
21668,
2437,
16187,
2925,
8,
3249,
14,
396,
14,
1746,
304,
819,
347,
511,
28362,
8,
277,
304,
272,
408,
2925,
3510,
13,
533,
12505,
1808,
3634,
666,
465,
1324,
1041,
272,
394,
1162,
275,
2833,
14,
2828,
14,
3128,
63,
25736,
14,
1548,
14,
3128,
63,
25736,
14,
21668,
40,
6007,
8,
267,
1967,
63,
14635,
29,
19,
12,
1390,
63,
2415,
29,
5279,
12,
1967,
63,
2888,
29,
19,
12,
1967,
63,
3179,
29,
20,
12,
267,
3715,
63,
4399,
63,
3356,
29,
1165,
9,
272,
12429,
275,
2833,
14,
2828,
14,
4643,
14,
3861,
21668,
13183,
8,
72,
1162,
14,
4498,
1012,
339,
12192,
275,
2833,
14,
2828,
14,
4643,
14,
12281,
14,
912,
63,
11885,
342,
272,
666,
275,
12192,
14,
576,
14,
6041,
8,
1590,
14,
1609,
708,
9,
272,
3628,
275,
12192,
14,
1375,
14,
6041,
8,
1590,
14,
1609,
708,
9,
339,
12429,
14,
3269,
8,
88,
29,
576,
12,
612,
29,
3512,
12,
7124,
29,
1960,
12,
3522,
63,
890,
29,
1400,
9,
272,
12429,
14,
7383,
8,
88,
29,
576,
12,
612,
29,
3512,
12,
7124,
29,
709,
9,
819,
347,
511,
28362,
20463,
8610,
8,
277,
304,
272,
408,
2925,
3510,
13,
533,
12505,
1808,
3634,
666,
465,
1324,
1041,
272,
394,
1162,
275,
2833,
14,
2828,
14,
3128,
63,
25736,
14,
1548,
14,
3128,
63,
25736,
14,
21668,
40,
6007,
8,
267,
1967,
63,
14635,
29,
19,
12,
1390,
63,
2415,
29,
5279,
12,
1967,
63,
2888,
29,
19,
12,
1967,
63,
3179,
29,
20,
9,
272,
12429,
275,
2833,
14,
2828,
14,
4643,
14,
3861,
21668,
13183,
8,
267,
394,
1162,
12,
3343,
63,
5649,
63,
533,
2687,
288,
2833,
14,
2828,
14,
3128,
63,
25736,
14,
1548,
14,
3128,
63,
25736,
14,
20463,
8610,
21668,
430,
339,
12192,
275,
2833,
14,
2828,
14,
4643,
14,
12281,
14,
912,
63,
11885,
342,
272,
666,
275,
12192,
14,
576,
14,
6041,
8,
1590,
14,
1609,
708,
9,
272,
3628,
275,
12192,
14,
1375,
14,
6041,
8,
1590,
14,
1609,
708,
9,
339,
26862,
275,
359,
3249,
14,
2828,
14,
4643,
14,
3861,
21668,
8610,
8481,
8,
709,
1874,
272,
12429,
14,
3269,
8,
88,
29,
576,
12,
612,
29,
3512,
12,
7124,
29,
1960,
12,
26862,
29,
24048,
9,
272,
12429,
14,
7383,
8,
88,
29,
576,
12,
612,
29,
3512,
12,
7124,
29,
709,
9,
819,
347,
511,
13013,
8,
277,
304,
272,
408,
2925,
3510,
13,
533,
12505,
1808,
3634,
666,
465,
1324,
1041,
339,
394,
1162,
275,
2833,
14,
2828,
14,
3128,
63,
25736,
14,
1548,
14,
3128,
63,
25736,
14,
21668,
40,
6007,
8,
267,
1967,
63,
14635,
29,
19,
12,
1390,
63,
2415,
29,
5279,
12,
1967,
63,
2888,
29,
17,
12,
1967,
63,
3179,
29,
969,
12,
267,
10864,
29,
549,
12,
3715,
63,
4399,
63,
3356,
29,
1165,
9,
339,
1295,
11686,
275,
2833,
14,
2828,
14,
4643,
14,
3861,
21668,
13183,
8,
72,
1162,
14,
4498,
1012,
339,
330,
7797,
275,
2833,
14,
2828,
14,
4643,
14,
12281,
14,
912,
63,
28275,
342,
272,
666,
275,
330,
7797,
14,
576,
14,
6041,
8,
1590,
14,
1609,
708,
9,
272,
3628,
275,
330,
7797,
14,
1375,
14,
6041,
8,
1590,
14,
1609,
708,
9,
339,
1295,
11686,
14,
3269,
8,
88,
29,
576,
12,
612,
29,
3512,
12,
7124,
29,
1960,
12,
3522,
63,
890,
29,
1400,
9,
272,
1295,
11686,
14,
7383,
8,
88,
29,
576,
12,
612,
29,
3512,
12,
7124,
29,
709,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2833,
14,
396,
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
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
199,
624,
2925,
367,
5878,
21668,
2437,
16187,
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,
646,
3228,
465,
2833,
421,
199,
533,
5878,
21668,
2437,
16187,
2925,
8,
3249,
14,
396,
14,
1746,
304,
819,
347,
511,
28362,
8,
277,
304,
272,
408,
2925,
3510,
13,
533,
12505,
1808,
3634,
666,
465,
1324,
1041,
272,
394,
1162,
275,
2833,
14,
2828,
14,
3128,
63,
25736,
14,
1548,
14,
3128,
63,
25736,
14,
21668,
40,
6007,
8,
267,
1967,
63,
14635,
29,
19,
12,
1390,
63,
2415,
29,
5279,
12,
1967,
63,
2888,
29,
19,
12,
1967,
63,
3179,
29,
20,
12,
267,
3715,
63,
4399,
63,
3356,
29,
1165,
9,
272,
12429,
275,
2833,
14,
2828,
14,
4643,
14,
3861,
21668,
13183,
8,
72,
1162,
14,
4498,
1012,
339,
12192,
275,
2833,
14,
2828,
14,
4643,
14,
12281,
14,
912,
63,
11885,
342,
272,
666,
275,
12192,
14,
576,
14,
6041,
8,
1590,
14,
1609,
708,
9,
272,
3628,
275,
12192,
14,
1375,
14,
6041,
8,
1590,
14,
1609,
708,
9,
339,
12429,
14,
3269,
8,
88,
29,
576,
12,
612,
29,
3512,
12,
7124,
29,
1960,
12,
3522,
63,
890,
29,
1400,
9,
272,
12429,
14,
7383,
8,
88,
29,
576,
12,
612,
29,
3512,
12,
7124,
29,
709,
9,
819,
347,
511,
28362,
20463,
8610,
8,
277,
304,
272,
408,
2925,
3510,
13,
533,
12505,
1808,
3634,
666,
465,
1324,
1041,
272,
394,
1162,
275,
2833,
14,
2828,
14,
3128,
63,
25736,
14,
1548,
14,
3128,
63,
25736,
14,
21668,
40,
6007,
8,
267,
1967,
63,
14635,
29,
19,
12,
1390,
63,
2415,
29,
5279,
12,
1967,
63,
2888,
29,
19,
12,
1967,
63,
3179,
29,
20,
9,
272,
12429,
275,
2833,
14,
2828,
14,
4643,
14,
3861,
21668,
13183,
8,
267,
394,
1162,
12,
3343,
63,
5649,
63,
533,
2687,
288,
2833,
14,
2828,
14,
3128,
63,
25736,
14,
1548,
14,
3128,
63,
25736,
14,
20463,
8610,
21668,
430,
339,
12192,
275,
2833,
14,
2828,
14,
4643,
14,
12281,
14,
912,
63,
11885,
342,
272,
666,
275,
12192,
14,
576,
14,
6041,
8,
1590,
14,
1609,
708,
9,
272,
3628,
275,
12192,
14,
1375,
14,
6041,
8,
1590,
14,
1609,
708,
9,
339,
26862,
275,
359,
3249,
14,
2828,
14,
4643,
14,
3861,
21668,
8610,
8481,
8,
709,
1874,
272,
12429,
14,
3269,
8,
88,
29,
576,
12,
612,
29,
3512,
12,
7124,
29,
1960,
12,
26862,
29,
24048,
9,
272,
12429,
14,
7383,
8,
88,
29,
576,
12,
612,
29,
3512,
12,
7124,
29,
709,
9,
819,
347,
511,
13013,
8,
277,
304,
272,
408,
2925,
3510,
13,
533,
12505,
1808,
3634,
666,
465,
1324,
1041,
339,
394,
1162,
275,
2833,
14,
2828,
14,
3128,
63,
25736,
14,
1548,
14,
3128,
63,
25736,
14,
21668,
40,
6007,
8,
267,
1967,
63,
14635,
29,
19,
12,
1390,
63,
2415,
29,
5279,
12,
1967,
63,
2888,
29,
17,
12,
1967,
63,
3179,
29,
969,
12,
267,
10864,
29,
549,
12,
3715,
63,
4399,
63,
3356,
29,
1165,
9,
339,
1295,
11686,
275,
2833,
14,
2828,
14,
4643,
14,
3861,
21668,
13183,
8,
72,
1162,
14,
4498,
1012,
339,
330,
7797,
275,
2833,
14,
2828,
14,
4643,
14,
12281,
14,
912,
63,
28275,
342,
272,
666,
275,
330,
7797,
14,
576,
14,
6041,
8,
1590,
14,
1609,
708,
9,
272,
3628,
275,
330,
7797,
14,
1375,
14,
6041,
8,
1590,
14,
1609,
708,
9,
339,
1295,
11686,
14,
3269,
8,
88,
29,
576,
12,
612,
29,
3512,
12,
7124,
29,
1960,
12,
3522,
63,
890,
29,
1400,
9,
272,
1295,
11686,
14,
7383,
8,
88,
29,
576,
12,
612,
29,
3512,
12,
7124,
29,
709,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2833,
14,
396,
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,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
jmighion/ansible
|
test/units/modules/network/junos/test_junos_config.py
|
7
|
7467
|
#
# (c) 2017 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.compat.tests.mock import patch
from ansible.modules.network.junos import junos_config
from .junos_module import TestJunosModule, load_fixture, set_module_args
class TestJunosConfigModule(TestJunosModule):
module = junos_config
def setUp(self):
self.mock_get_config = patch('ansible.modules.network.junos.junos_config.get_configuration')
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch('ansible.modules.network.junos.junos_config.load_config')
self.load_config = self.mock_load_config.start()
self.mock_load_configuration = patch('ansible.modules.network.junos.junos_config.load_configuration')
self.load_configuration = self.mock_load_configuration.start()
self.mock_lock_configuration = patch('ansible.module_utils.junos.lock_configuration')
self.lock_configuration = self.mock_lock_configuration.start()
self.mock_unlock_configuration = patch('ansible.module_utils.junos.unlock_configuration')
self.unlock_configuration = self.mock_unlock_configuration.start()
self.mock_commit_configuration = patch('ansible.modules.network.junos.junos_config.commit_configuration')
self.commit_configuration = self.mock_commit_configuration.start()
self.mock_get_diff = patch('ansible.modules.network.junos.junos_config.get_diff')
self.get_diff = self.mock_get_diff.start()
self.mock_send_request = patch('ansible.modules.network.junos.junos_config.send_request')
self.send_request = self.mock_send_request.start()
def tearDown(self):
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_lock_configuration.stop()
self.mock_unlock_configuration.stop()
self.mock_commit_configuration.stop()
self.mock_get_diff.stop()
self.mock_send_request.stop()
self.load_configuration.stop()
def load_fixtures(self, commands=None, format='text', changed=False):
self.get_config.return_value = load_fixture('get_configuration_rpc_reply.txt')
if changed:
self.load_config.return_value = load_fixture('get_configuration_rpc_reply_diff.txt')
else:
self.load_config.return_value = None
def test_junos_config_unchanged(self):
src = load_fixture('junos_config.set', content='str')
set_module_args(dict(src=src))
self.execute_module()
def test_junos_config_src_set(self):
src = load_fixture('junos_config.set', content='str')
set_module_args(dict(src=src))
self.execute_module(changed=True)
args, kwargs = self.load_config.call_args
self.assertEqual(kwargs['action'], 'set')
self.assertEqual(kwargs['format'], 'text')
def test_junos_config_backup(self):
set_module_args(dict(backup=True))
result = self.execute_module()
self.assertIn('__backup__', result)
def test_junos_config_lines(self):
set_module_args(dict(lines=['delete interfaces ae11', 'set interfaces ae11 unit 0 description Test']))
self.execute_module(changed=True)
args, kwargs = self.load_config.call_args
self.assertEqual(args[1][0], 'set interfaces ae11 unit 0 description Test')
self.assertEqual(kwargs['action'], 'set')
self.assertEqual(kwargs['format'], 'text')
def test_junos_config_confirm(self):
src = load_fixture('junos_config.set', content='str')
set_module_args(dict(src=src, confirm=40))
self.execute_module(changed=True)
args, kwargs = self.commit_configuration.call_args
self.assertEqual(kwargs['confirm_timeout'], 40)
def test_junos_config_rollback(self):
rollback = 10
set_module_args(dict(rollback=rollback))
self.execute_module(changed=True)
self.assertEqual(self.get_diff.call_count, 1)
self.assertEqual(self.load_configuration.call_count, 1)
self.assertEqual(self.commit_configuration.call_count, 1)
load_configuration_args = self.load_configuration.call_args
self.assertEqual(rollback, load_configuration_args[1].get('rollback'))
def test_junos_config_src_text(self):
src = load_fixture('junos_config.text', content='str')
set_module_args(dict(src=src))
self.execute_module(changed=True)
args, kwargs = self.load_config.call_args
self.assertEqual(kwargs['action'], 'merge')
self.assertEqual(kwargs['format'], 'text')
def test_junos_config_src_xml(self):
src = load_fixture('junos_config.xml', content='str')
set_module_args(dict(src=src))
self.execute_module(changed=True)
args, kwargs = self.load_config.call_args
self.assertEqual(kwargs['action'], 'merge')
self.assertEqual(kwargs['format'], 'xml')
def test_junos_config_src_json(self):
src = load_fixture('junos_config.json', content='str')
set_module_args(dict(src=src))
self.execute_module(changed=True)
args, kwargs = self.load_config.call_args
self.assertEqual(kwargs['action'], 'merge')
self.assertEqual(kwargs['format'], 'json')
def test_junos_config_update_override(self):
src = load_fixture('junos_config.xml', content='str')
set_module_args(dict(src=src, update='override'))
self.execute_module()
args, kwargs = self.load_config.call_args
self.assertEqual(kwargs['action'], 'override')
self.assertEqual(kwargs['format'], 'xml')
def test_junos_config_update_replace(self):
src = load_fixture('junos_config.json', content='str')
set_module_args(dict(src=src, update='replace'))
self.execute_module()
args, kwargs = self.load_config.call_args
self.assertEqual(kwargs['action'], 'replace')
self.assertEqual(kwargs['format'], 'json')
def test_junos_config_zeroize(self):
src = load_fixture('junos_config.json', content='str')
set_module_args(dict(zeroize='yes'))
self.execute_module(changed=True)
self.assertEqual(self.send_request.call_count, 1)
def test_junos_config_src_format_xml(self):
src = load_fixture('junos_config.json', content='str')
set_module_args(dict(src=src, src_format='xml'))
self.execute_module()
args, kwargs = self.load_config.call_args
self.assertEqual(kwargs['format'], 'xml')
def test_junos_config_confirm_commit(self):
set_module_args(dict(confirm_commit=True))
self.execute_module(changed=True)
self.assertEqual(self.commit_configuration.call_count, 1)
|
gpl-3.0
|
[
3,
199,
3,
334,
67,
9,
9708,
9572,
13002,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
14,
5819,
14,
2219,
14,
1805,
492,
3371,
199,
504,
3242,
14,
3112,
14,
1200,
14,
31959,
492,
1335,
21003,
63,
888,
199,
504,
1275,
31959,
63,
578,
492,
1379,
42,
21003,
2377,
12,
2248,
63,
5997,
12,
663,
63,
578,
63,
589,
421,
199,
533,
1379,
42,
21003,
2028,
2377,
8,
774,
42,
21003,
2377,
304,
339,
859,
275,
1335,
21003,
63,
888,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1805,
63,
362,
63,
888,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
31959,
14,
31959,
63,
888,
14,
362,
63,
4758,
358,
267,
291,
14,
362,
63,
888,
275,
291,
14,
1805,
63,
362,
63,
888,
14,
928,
342,
398,
291,
14,
1805,
63,
912,
63,
888,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
31959,
14,
31959,
63,
888,
14,
912,
63,
888,
358,
267,
291,
14,
912,
63,
888,
275,
291,
14,
1805,
63,
912,
63,
888,
14,
928,
342,
398,
291,
14,
1805,
63,
912,
63,
4758,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
31959,
14,
31959,
63,
888,
14,
912,
63,
4758,
358,
267,
291,
14,
912,
63,
4758,
275,
291,
14,
1805,
63,
912,
63,
4758,
14,
928,
342,
398,
291,
14,
1805,
63,
831,
63,
4758,
275,
3371,
360,
4853,
14,
578,
63,
1208,
14,
31959,
14,
831,
63,
4758,
358,
267,
291,
14,
831,
63,
4758,
275,
291,
14,
1805,
63,
831,
63,
4758,
14,
928,
342,
398,
291,
14,
1805,
63,
17966,
63,
4758,
275,
3371,
360,
4853,
14,
578,
63,
1208,
14,
31959,
14,
17966,
63,
4758,
358,
267,
291,
14,
17966,
63,
4758,
275,
291,
14,
1805,
63,
17966,
63,
4758,
14,
928,
342,
398,
291,
14,
1805,
63,
3543,
63,
4758,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
31959,
14,
31959,
63,
888,
14,
3543,
63,
4758,
358,
267,
291,
14,
3543,
63,
4758,
275,
291,
14,
1805,
63,
3543,
63,
4758,
14,
928,
342,
398,
291,
14,
1805,
63,
362,
63,
3028,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
31959,
14,
31959,
63,
888,
14,
362,
63,
3028,
358,
267,
291,
14,
362,
63,
3028,
275,
291,
14,
1805,
63,
362,
63,
3028,
14,
928,
342,
398,
291,
14,
1805,
63,
2254,
63,
1069,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
31959,
14,
31959,
63,
888,
14,
2254,
63,
1069,
358,
267,
291,
14,
2254,
63,
1069,
275,
291,
14,
1805,
63,
2254,
63,
1069,
14,
928,
342,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
1805,
63,
362,
63,
888,
14,
2379,
342,
267,
291,
14,
1805,
63,
912,
63,
888,
14,
2379,
342,
267,
291,
14,
1805,
63,
831,
63,
4758,
14,
2379,
342,
267,
291,
14,
1805,
63,
17966,
63,
4758,
14,
2379,
342,
267,
291,
14,
1805,
63,
3543,
63,
4758,
14,
2379,
342,
267,
291,
14,
1805,
63,
362,
63,
3028,
14,
2379,
342,
267,
291,
14,
1805,
63,
2254,
63,
1069,
14,
2379,
342,
267,
291,
14,
912,
63,
4758,
14,
2379,
342,
339,
347,
2248,
63,
8769,
8,
277,
12,
3718,
29,
403,
12,
1475,
534,
505,
297,
2896,
29,
797,
304,
267,
291,
14,
362,
63,
888,
14,
1107,
63,
585,
275,
2248,
63,
5997,
360,
362,
63,
4758,
63,
4354,
63,
8102,
14,
2424,
358,
267,
340,
2896,
26,
288,
291,
14,
912,
63,
888,
14,
1107,
63,
585,
275,
2248,
63,
5997,
360,
362,
63,
4758,
63,
4354,
63,
8102,
63,
3028,
14,
2424,
358,
267,
587,
26,
288,
291,
14,
912,
63,
888,
14,
1107,
63,
585,
275,
488,
339,
347,
511,
63,
31959,
63,
888,
63,
16914,
8,
277,
304,
267,
2928,
275,
2248,
63,
5997,
360,
31959,
63,
888,
14,
409,
297,
1564,
534,
495,
358,
267,
663,
63,
578,
63,
589,
8,
807,
8,
2164,
29,
2164,
430,
267,
291,
14,
2526,
63,
578,
342,
339,
347,
511,
63,
31959,
63,
888,
63,
2164,
63,
409,
8,
277,
304,
267,
2928,
275,
2248,
63,
5997,
360,
31959,
63,
888,
14,
409,
297,
1564,
534,
495,
358,
267,
663,
63,
578,
63,
589,
8,
807,
8,
2164,
29,
2164,
430,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
9,
267,
1249,
12,
2074,
275,
291,
14,
912,
63,
888,
14,
1250,
63,
589,
267,
291,
14,
629,
8,
958,
459,
1287,
995,
283,
409,
358,
267,
291,
14,
629,
8,
958,
459,
908,
995,
283,
505,
358,
339,
347,
511,
63,
31959,
63,
888,
63,
5751,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
5751,
29,
549,
430,
267,
754,
275,
291,
14,
2526,
63,
578,
342,
267,
291,
14,
4080,
10714,
5751,
7500,
754,
9,
339,
347,
511,
63,
31959,
63,
888,
63,
1278,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
1278,
2968,
1807,
8386,
16951,
845,
297,
283,
409,
8386,
16951,
845,
4137,
378,
1369
] |
[
199,
3,
334,
67,
9,
9708,
9572,
13002,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
14,
5819,
14,
2219,
14,
1805,
492,
3371,
199,
504,
3242,
14,
3112,
14,
1200,
14,
31959,
492,
1335,
21003,
63,
888,
199,
504,
1275,
31959,
63,
578,
492,
1379,
42,
21003,
2377,
12,
2248,
63,
5997,
12,
663,
63,
578,
63,
589,
421,
199,
533,
1379,
42,
21003,
2028,
2377,
8,
774,
42,
21003,
2377,
304,
339,
859,
275,
1335,
21003,
63,
888,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1805,
63,
362,
63,
888,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
31959,
14,
31959,
63,
888,
14,
362,
63,
4758,
358,
267,
291,
14,
362,
63,
888,
275,
291,
14,
1805,
63,
362,
63,
888,
14,
928,
342,
398,
291,
14,
1805,
63,
912,
63,
888,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
31959,
14,
31959,
63,
888,
14,
912,
63,
888,
358,
267,
291,
14,
912,
63,
888,
275,
291,
14,
1805,
63,
912,
63,
888,
14,
928,
342,
398,
291,
14,
1805,
63,
912,
63,
4758,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
31959,
14,
31959,
63,
888,
14,
912,
63,
4758,
358,
267,
291,
14,
912,
63,
4758,
275,
291,
14,
1805,
63,
912,
63,
4758,
14,
928,
342,
398,
291,
14,
1805,
63,
831,
63,
4758,
275,
3371,
360,
4853,
14,
578,
63,
1208,
14,
31959,
14,
831,
63,
4758,
358,
267,
291,
14,
831,
63,
4758,
275,
291,
14,
1805,
63,
831,
63,
4758,
14,
928,
342,
398,
291,
14,
1805,
63,
17966,
63,
4758,
275,
3371,
360,
4853,
14,
578,
63,
1208,
14,
31959,
14,
17966,
63,
4758,
358,
267,
291,
14,
17966,
63,
4758,
275,
291,
14,
1805,
63,
17966,
63,
4758,
14,
928,
342,
398,
291,
14,
1805,
63,
3543,
63,
4758,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
31959,
14,
31959,
63,
888,
14,
3543,
63,
4758,
358,
267,
291,
14,
3543,
63,
4758,
275,
291,
14,
1805,
63,
3543,
63,
4758,
14,
928,
342,
398,
291,
14,
1805,
63,
362,
63,
3028,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
31959,
14,
31959,
63,
888,
14,
362,
63,
3028,
358,
267,
291,
14,
362,
63,
3028,
275,
291,
14,
1805,
63,
362,
63,
3028,
14,
928,
342,
398,
291,
14,
1805,
63,
2254,
63,
1069,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
31959,
14,
31959,
63,
888,
14,
2254,
63,
1069,
358,
267,
291,
14,
2254,
63,
1069,
275,
291,
14,
1805,
63,
2254,
63,
1069,
14,
928,
342,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
1805,
63,
362,
63,
888,
14,
2379,
342,
267,
291,
14,
1805,
63,
912,
63,
888,
14,
2379,
342,
267,
291,
14,
1805,
63,
831,
63,
4758,
14,
2379,
342,
267,
291,
14,
1805,
63,
17966,
63,
4758,
14,
2379,
342,
267,
291,
14,
1805,
63,
3543,
63,
4758,
14,
2379,
342,
267,
291,
14,
1805,
63,
362,
63,
3028,
14,
2379,
342,
267,
291,
14,
1805,
63,
2254,
63,
1069,
14,
2379,
342,
267,
291,
14,
912,
63,
4758,
14,
2379,
342,
339,
347,
2248,
63,
8769,
8,
277,
12,
3718,
29,
403,
12,
1475,
534,
505,
297,
2896,
29,
797,
304,
267,
291,
14,
362,
63,
888,
14,
1107,
63,
585,
275,
2248,
63,
5997,
360,
362,
63,
4758,
63,
4354,
63,
8102,
14,
2424,
358,
267,
340,
2896,
26,
288,
291,
14,
912,
63,
888,
14,
1107,
63,
585,
275,
2248,
63,
5997,
360,
362,
63,
4758,
63,
4354,
63,
8102,
63,
3028,
14,
2424,
358,
267,
587,
26,
288,
291,
14,
912,
63,
888,
14,
1107,
63,
585,
275,
488,
339,
347,
511,
63,
31959,
63,
888,
63,
16914,
8,
277,
304,
267,
2928,
275,
2248,
63,
5997,
360,
31959,
63,
888,
14,
409,
297,
1564,
534,
495,
358,
267,
663,
63,
578,
63,
589,
8,
807,
8,
2164,
29,
2164,
430,
267,
291,
14,
2526,
63,
578,
342,
339,
347,
511,
63,
31959,
63,
888,
63,
2164,
63,
409,
8,
277,
304,
267,
2928,
275,
2248,
63,
5997,
360,
31959,
63,
888,
14,
409,
297,
1564,
534,
495,
358,
267,
663,
63,
578,
63,
589,
8,
807,
8,
2164,
29,
2164,
430,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
9,
267,
1249,
12,
2074,
275,
291,
14,
912,
63,
888,
14,
1250,
63,
589,
267,
291,
14,
629,
8,
958,
459,
1287,
995,
283,
409,
358,
267,
291,
14,
629,
8,
958,
459,
908,
995,
283,
505,
358,
339,
347,
511,
63,
31959,
63,
888,
63,
5751,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
5751,
29,
549,
430,
267,
754,
275,
291,
14,
2526,
63,
578,
342,
267,
291,
14,
4080,
10714,
5751,
7500,
754,
9,
339,
347,
511,
63,
31959,
63,
888,
63,
1278,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
1278,
2968,
1807,
8386,
16951,
845,
297,
283,
409,
8386,
16951,
845,
4137,
378,
1369,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
WASPACDC/hmdsm.repository
|
plugin.video.playlistLoader/resources/lib/chardet/big5prober.py
|
2931
|
1684
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Communicator client code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - port to Python
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
from .mbcharsetprober import MultiByteCharSetProber
from .codingstatemachine import CodingStateMachine
from .chardistribution import Big5DistributionAnalysis
from .mbcssm import Big5SMModel
class Big5Prober(MultiByteCharSetProber):
def __init__(self):
MultiByteCharSetProber.__init__(self)
self._mCodingSM = CodingStateMachine(Big5SMModel)
self._mDistributionAnalyzer = Big5DistributionAnalysis()
self.reset()
def get_charset_name(self):
return "Big5"
|
gpl-2.0
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
1275,
887,
6043,
19903,
492,
6879,
21312,
199,
504,
1275,
1523,
929,
6744,
492,
30539,
199,
504,
1275,
1560,
4972,
492,
13123,
21,
24906,
199,
504,
1275,
887,
3919,
77,
492,
13123,
21,
25335,
421,
199,
533,
13123,
21,
8029,
8,
3947,
21312,
304,
272,
347,
636,
826,
721,
277,
304,
267,
6879,
21312,
855,
826,
721,
277,
9,
267,
291,
423,
29633,
275,
30539,
8,
7279,
21,
25335,
9,
267,
291,
423,
77,
8580,
17606,
275,
13123,
21,
24906,
342,
267,
291,
14,
3958,
342,
339,
347,
664,
63,
6043,
63,
354,
8,
277,
304,
267,
372,
298,
7279,
21,
2,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
1275,
887,
6043,
19903,
492,
6879,
21312,
199,
504,
1275,
1523,
929,
6744,
492,
30539,
199,
504,
1275,
1560,
4972,
492,
13123,
21,
24906,
199,
504,
1275,
887,
3919,
77,
492,
13123,
21,
25335,
421,
199,
533,
13123,
21,
8029,
8,
3947,
21312,
304,
272,
347,
636,
826,
721,
277,
304,
267,
6879,
21312,
855,
826,
721,
277,
9,
267,
291,
423,
29633,
275,
30539,
8,
7279,
21,
25335,
9,
267,
291,
423,
77,
8580,
17606,
275,
13123,
21,
24906,
342,
267,
291,
14,
3958,
342,
339,
347,
664,
63,
6043,
63,
354,
8,
277,
304,
267,
372,
298,
7279,
21,
2,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
edxzw/edx-platform
|
cms/djangoapps/contentstore/views/library.py
|
36
|
9259
|
"""
Views related to content libraries.
A content library is a structure containing XBlocks which can be re-used in the
multiple courses.
"""
from __future__ import absolute_import
import json
import logging
from contentstore.views.item import create_xblock_info
from contentstore.utils import reverse_library_url, add_instructor
from django.http import HttpResponseNotAllowed, Http404
from django.contrib.auth.decorators import login_required
from django.core.exceptions import PermissionDenied
from django.conf import settings
from django.utils.translation import ugettext as _
from django.views.decorators.http import require_http_methods
from django.views.decorators.csrf import ensure_csrf_cookie
from edxmako.shortcuts import render_to_response
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.locator import LibraryLocator, LibraryUsageLocator
from xmodule.modulestore.exceptions import DuplicateCourseError
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore
from .user import user_with_role
from .component import get_component_templates, CONTAINER_TEMPLATES
from student.auth import (
STUDIO_VIEW_USERS, STUDIO_EDIT_ROLES, get_user_permissions, has_studio_read_access, has_studio_write_access
)
from student.roles import CourseInstructorRole, CourseStaffRole, LibraryUserRole
from util.json_request import expect_json, JsonResponse, JsonResponseBadRequest
__all__ = ['library_handler', 'manage_library_users']
log = logging.getLogger(__name__)
LIBRARIES_ENABLED = settings.FEATURES.get('ENABLE_CONTENT_LIBRARIES', False)
@login_required
@ensure_csrf_cookie
@require_http_methods(('GET', 'POST'))
def library_handler(request, library_key_string=None):
"""
RESTful interface to most content library related functionality.
"""
if not LIBRARIES_ENABLED:
log.exception("Attempted to use the content library API when the libraries feature is disabled.")
raise Http404 # Should never happen because we test the feature in urls.py also
if library_key_string is not None and request.method == 'POST':
return HttpResponseNotAllowed(("POST",))
if request.method == 'POST':
return _create_library(request)
# request method is get, since only GET and POST are allowed by @require_http_methods(('GET', 'POST'))
if library_key_string:
return _display_library(library_key_string, request)
return _list_libraries(request)
def _display_library(library_key_string, request):
"""
Displays single library
"""
library_key = CourseKey.from_string(library_key_string)
if not isinstance(library_key, LibraryLocator):
log.exception("Non-library key passed to content libraries API.") # Should never happen due to url regex
raise Http404 # This is not a library
if not has_studio_read_access(request.user, library_key):
log.exception(
u"User %s tried to access library %s without permission",
request.user.username, unicode(library_key)
)
raise PermissionDenied()
library = modulestore().get_library(library_key)
if library is None:
log.exception(u"Library %s not found", unicode(library_key))
raise Http404
response_format = 'html'
if (
request.REQUEST.get('format', 'html') == 'json' or
'application/json' in request.META.get('HTTP_ACCEPT', 'text/html')
):
response_format = 'json'
return library_blocks_view(library, request.user, response_format)
def _list_libraries(request):
"""
List all accessible libraries
"""
lib_info = [
{
"display_name": lib.display_name,
"library_key": unicode(lib.location.library_key),
}
for lib in modulestore().get_libraries()
if has_studio_read_access(request.user, lib.location.library_key)
]
return JsonResponse(lib_info)
@expect_json
def _create_library(request):
"""
Helper method for creating a new library.
"""
display_name = None
try:
display_name = request.json['display_name']
org = request.json['org']
library = request.json.get('number', None)
if library is None:
library = request.json['library']
store = modulestore()
with store.default_store(ModuleStoreEnum.Type.split):
new_lib = store.create_library(
org=org,
library=library,
user_id=request.user.id,
fields={"display_name": display_name},
)
# Give the user admin ("Instructor") role for this library:
add_instructor(new_lib.location.library_key, request.user, request.user)
except KeyError as error:
log.exception("Unable to create library - missing required JSON key.")
return JsonResponseBadRequest({
"ErrMsg": _("Unable to create library - missing required field '{field}'").format(field=error.message)
})
except InvalidKeyError as error:
log.exception("Unable to create library - invalid key.")
return JsonResponseBadRequest({
"ErrMsg": _("Unable to create library '{name}'.\n\n{err}").format(name=display_name, err=error.message)
})
except DuplicateCourseError:
log.exception("Unable to create library - one already exists with the same key.")
return JsonResponseBadRequest({
'ErrMsg': _(
'There is already a library defined with the same '
'organization and library code. Please '
'change your library code so that it is unique within your organization.'
)
})
lib_key_str = unicode(new_lib.location.library_key)
return JsonResponse({
'url': reverse_library_url('library_handler', lib_key_str),
'library_key': lib_key_str,
})
def library_blocks_view(library, user, response_format):
"""
The main view of a course's content library.
Shows all the XBlocks in the library, and allows adding/editing/deleting
them.
Can be called with response_format="json" to get a JSON-formatted list of
the XBlocks in the library along with library metadata.
Assumes that read permissions have been checked before calling this.
"""
assert isinstance(library.location.library_key, LibraryLocator)
assert isinstance(library.location, LibraryUsageLocator)
children = library.children
if response_format == "json":
# The JSON response for this request is short and sweet:
prev_version = library.runtime.course_entry.structure['previous_version']
return JsonResponse({
"display_name": library.display_name,
"library_id": unicode(library.location.library_key),
"version": unicode(library.runtime.course_entry.course_key.version),
"previous_version": unicode(prev_version) if prev_version else None,
"blocks": [unicode(x) for x in children],
})
can_edit = has_studio_write_access(user, library.location.library_key)
xblock_info = create_xblock_info(library, include_ancestor_info=False, graders=[])
component_templates = get_component_templates(library, library=True) if can_edit else []
return render_to_response('library.html', {
'can_edit': can_edit,
'context_library': library,
'component_templates': component_templates,
'xblock_info': xblock_info,
'templates': CONTAINER_TEMPLATES,
})
def manage_library_users(request, library_key_string):
"""
Studio UI for editing the users within a library.
Uses the /course_team/:library_key/:user_email/ REST API to make changes.
"""
library_key = CourseKey.from_string(library_key_string)
if not isinstance(library_key, LibraryLocator):
raise Http404 # This is not a library
user_perms = get_user_permissions(request.user, library_key)
if not user_perms & STUDIO_VIEW_USERS:
raise PermissionDenied()
library = modulestore().get_library(library_key)
if library is None:
raise Http404
# Segment all the users explicitly associated with this library, ensuring each user only has one role listed:
instructors = set(CourseInstructorRole(library_key).users_with_role())
staff = set(CourseStaffRole(library_key).users_with_role()) - instructors
users = set(LibraryUserRole(library_key).users_with_role()) - instructors - staff
formatted_users = []
for user in instructors:
formatted_users.append(user_with_role(user, 'instructor'))
for user in staff:
formatted_users.append(user_with_role(user, 'staff'))
for user in users:
formatted_users.append(user_with_role(user, 'library_user'))
return render_to_response('manage_users_lib.html', {
'context_library': library,
'users': formatted_users,
'allow_actions': bool(user_perms & STUDIO_EDIT_ROLES),
'library_key': unicode(library_key),
'lib_users_url': reverse_library_url('manage_library_users', library_key_string),
'show_children_previews': library.show_children_previews
})
|
agpl-3.0
|
[
624,
199,
21180,
4048,
370,
1564,
8363,
14,
199,
33,
1564,
3555,
365,
282,
5523,
3035,
15398,
83,
1314,
883,
506,
295,
13,
2972,
315,
314,
199,
6048,
13588,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2022,
199,
646,
2050,
199,
199,
504,
23061,
14,
4196,
14,
1053,
492,
1218,
63,
11283,
63,
815,
199,
504,
23061,
14,
1208,
492,
3837,
63,
4342,
63,
633,
12,
1050,
63,
14891,
199,
504,
1639,
14,
1014,
492,
6183,
29967,
12,
4760,
5188,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
1018,
14,
3924,
492,
23724,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1014,
492,
4409,
63,
1014,
63,
2474,
199,
504,
1639,
14,
4196,
14,
11582,
14,
10088,
492,
4868,
63,
10088,
63,
5306,
199,
504,
22435,
19491,
14,
17469,
492,
3795,
63,
475,
63,
1310,
199,
504,
15058,
63,
1612,
492,
6378,
10230,
199,
504,
15058,
63,
1612,
14,
8268,
14,
1612,
492,
22574,
199,
504,
15058,
63,
1612,
14,
8268,
14,
6354,
492,
11243,
10725,
12,
11243,
7692,
10725,
199,
504,
9872,
14,
10012,
14,
3924,
492,
23942,
6979,
547,
199,
504,
9872,
14,
10012,
492,
23431,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
1275,
751,
492,
922,
63,
1045,
63,
3756,
199,
199,
504,
1275,
3173,
492,
664,
63,
3173,
63,
5876,
12,
1868,
6166,
568,
540,
63,
25437,
199,
504,
6474,
14,
1178,
492,
334,
272,
4384,
53,
19283,
63,
12058,
63,
28164,
12,
4384,
53,
19283,
63,
17929,
63,
6245,
654,
12,
664,
63,
751,
63,
6060,
12,
965,
63,
19806,
63,
739,
63,
2732,
12,
965,
63,
19806,
63,
952,
63,
2732,
199,
9,
199,
504,
6474,
14,
8050,
492,
5531,
30742,
7422,
12,
5531,
18963,
7422,
12,
11243,
1899,
7422,
199,
504,
4884,
14,
1001,
63,
1069,
492,
4282,
63,
1001,
12,
21072,
12,
21072,
12380,
199,
199,
363,
452,
363,
275,
788,
4342,
63,
2232,
297,
283,
9053,
63,
4342,
63,
3707,
418,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
32723,
63,
15704,
275,
2202,
14,
13313,
14,
362,
360,
8898,
63,
9663,
63,
32723,
297,
756,
9,
421,
199,
32,
2886,
63,
2427,
199,
32,
7505,
63,
10088,
63,
5306,
199,
32,
4365,
63,
1014,
63,
2474,
4725,
2970,
297,
283,
4030,
1333,
199,
318,
3555,
63,
2232,
8,
1069,
12,
3555,
63,
498,
63,
875,
29,
403,
304,
272,
408,
272,
14880,
1893,
3217,
370,
4750,
1564,
3555,
4048,
9330,
14,
272,
408,
272,
340,
440,
25764,
50,
25244,
63,
15704,
26,
267,
943,
14,
1971,
480,
15322,
471,
370,
675,
314,
1564,
3555,
3261,
1380,
314,
8363,
3878,
365,
6980,
2685,
267,
746,
4760,
5188,
221,
327,
7719,
7078,
5992,
2952,
781,
511,
314,
3878,
315,
8187,
14,
647,
2597,
339,
340,
3555,
63,
498,
63,
875,
365,
440,
488,
436,
1056,
14,
765,
508,
283,
4030,
356,
267,
372,
6183,
29967,
9313,
4030,
401,
430,
339,
340,
1056,
14,
765,
508,
283,
4030,
356,
267,
372,
485,
981,
63,
4342,
8,
1069,
9,
339,
327,
1056,
1083,
365,
664,
12,
3967,
1454,
9576,
436,
8761,
787,
4370,
701,
768,
4365,
63,
1014,
63,
2474,
4725,
2970,
297,
283,
4030,
1333,
272,
340,
3555,
63,
498,
63,
875,
26,
267,
372,
485,
2918,
63,
4342,
8,
4342,
63,
498,
63,
875,
12,
1056,
9,
339,
372,
485,
513,
63,
10159,
8,
1069,
9,
421,
199,
318,
485,
2918,
63,
4342,
8,
4342,
63,
498,
63,
875,
12,
1056,
304,
272,
408,
272,
28750,
2849,
3555,
272,
408,
272,
3555,
63,
498,
275,
22574,
14,
504,
63,
875,
8,
4342,
63,
498,
63,
875,
9,
272,
340,
440,
1228,
8,
4342,
63,
498,
12,
11243,
10725,
304,
267,
943,
14,
1971,
480,
6932,
13,
4342,
790,
3032,
370,
1564,
8363,
3261,
2685,
221,
327,
7719,
7078,
5992,
7037,
370,
1166,
5163,
267,
746,
4760,
5188,
221,
327,
961,
365,
440,
282,
3555,
272,
340,
440,
965,
63,
19806,
63,
739,
63,
2732,
8,
1069,
14,
751,
12,
3555,
63,
498,
304,
267,
943,
14,
1971,
8,
288,
399,
2,
1899,
450,
83,
16416,
370,
2879,
3555,
450,
83,
1928,
4983,
401,
288,
1056,
14,
751,
14,
2473,
12,
2649,
8,
4342,
63,
498,
9,
267,
776,
267,
746,
23724,
342,
339,
3555,
275,
10996,
1252,
362,
63,
4342,
8,
4342,
63,
498,
9,
272,
340,
3555,
365,
488,
26,
267,
943,
14,
1971,
8,
85,
2,
7424,
450,
83,
440,
1911,
401,
2649,
8,
4342,
63,
498,
430,
267,
746,
4760,
5188,
339,
1177,
63,
908,
275,
283,
1360,
7,
272,
340,
334,
288,
1056,
14,
6780,
14,
362,
360,
908,
297,
283,
1360,
358,
508,
283,
1001,
7,
503,
288,
283,
3578,
15,
1001,
7,
315,
1056,
14,
10614,
14,
362,
360,
2856,
63,
13089,
297,
283,
505,
15,
1360,
358,
272,
3461,
267,
1177,
63,
908,
275,
283,
1001,
7,
339,
372,
3555,
63,
4166,
63,
1345,
8,
4342,
12,
1056,
14,
751,
12,
1177,
63,
908,
9,
421,
199,
318,
485,
513,
63,
10159,
8,
1069,
304,
272,
408,
272,
3820,
1006,
17909,
8363,
272,
408,
272,
1973,
63,
815,
275,
359,
267,
469,
288,
298,
2918,
63,
354,
582,
1973,
14,
2918,
63,
354,
12,
288,
298,
4342,
63,
498,
582,
2649,
8,
773,
14,
1985,
14,
4342,
63,
498,
395,
267,
789,
267,
367,
1973,
315,
10996,
1252,
362,
63,
10159,
342,
267,
340,
965,
63,
19806,
63,
739,
63,
2732,
8,
1069,
14,
751,
12,
1973,
14,
1985,
14,
4342,
63,
498,
9,
272,
1622,
272,
372,
21072,
8,
773,
63,
815,
9,
421,
199,
32,
4921,
63,
1001,
199,
318,
485,
981,
63,
4342,
8,
1069,
304,
272,
408,
272,
11642,
1083,
367,
6425,
282,
892,
3555,
14,
272,
408,
272,
2929,
63,
354,
275,
488,
272,
862,
26,
267,
2929,
63,
354,
275,
1056,
14,
1001,
459,
2918,
63,
354,
418,
267,
5981,
275,
1056,
14,
1001,
459,
1308,
418,
267,
3555,
275
] |
[
199,
21180,
4048,
370,
1564,
8363,
14,
199,
33,
1564,
3555,
365,
282,
5523,
3035,
15398,
83,
1314,
883,
506,
295,
13,
2972,
315,
314,
199,
6048,
13588,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2022,
199,
646,
2050,
199,
199,
504,
23061,
14,
4196,
14,
1053,
492,
1218,
63,
11283,
63,
815,
199,
504,
23061,
14,
1208,
492,
3837,
63,
4342,
63,
633,
12,
1050,
63,
14891,
199,
504,
1639,
14,
1014,
492,
6183,
29967,
12,
4760,
5188,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
1018,
14,
3924,
492,
23724,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1014,
492,
4409,
63,
1014,
63,
2474,
199,
504,
1639,
14,
4196,
14,
11582,
14,
10088,
492,
4868,
63,
10088,
63,
5306,
199,
504,
22435,
19491,
14,
17469,
492,
3795,
63,
475,
63,
1310,
199,
504,
15058,
63,
1612,
492,
6378,
10230,
199,
504,
15058,
63,
1612,
14,
8268,
14,
1612,
492,
22574,
199,
504,
15058,
63,
1612,
14,
8268,
14,
6354,
492,
11243,
10725,
12,
11243,
7692,
10725,
199,
504,
9872,
14,
10012,
14,
3924,
492,
23942,
6979,
547,
199,
504,
9872,
14,
10012,
492,
23431,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
1275,
751,
492,
922,
63,
1045,
63,
3756,
199,
199,
504,
1275,
3173,
492,
664,
63,
3173,
63,
5876,
12,
1868,
6166,
568,
540,
63,
25437,
199,
504,
6474,
14,
1178,
492,
334,
272,
4384,
53,
19283,
63,
12058,
63,
28164,
12,
4384,
53,
19283,
63,
17929,
63,
6245,
654,
12,
664,
63,
751,
63,
6060,
12,
965,
63,
19806,
63,
739,
63,
2732,
12,
965,
63,
19806,
63,
952,
63,
2732,
199,
9,
199,
504,
6474,
14,
8050,
492,
5531,
30742,
7422,
12,
5531,
18963,
7422,
12,
11243,
1899,
7422,
199,
504,
4884,
14,
1001,
63,
1069,
492,
4282,
63,
1001,
12,
21072,
12,
21072,
12380,
199,
199,
363,
452,
363,
275,
788,
4342,
63,
2232,
297,
283,
9053,
63,
4342,
63,
3707,
418,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
32723,
63,
15704,
275,
2202,
14,
13313,
14,
362,
360,
8898,
63,
9663,
63,
32723,
297,
756,
9,
421,
199,
32,
2886,
63,
2427,
199,
32,
7505,
63,
10088,
63,
5306,
199,
32,
4365,
63,
1014,
63,
2474,
4725,
2970,
297,
283,
4030,
1333,
199,
318,
3555,
63,
2232,
8,
1069,
12,
3555,
63,
498,
63,
875,
29,
403,
304,
272,
408,
272,
14880,
1893,
3217,
370,
4750,
1564,
3555,
4048,
9330,
14,
272,
408,
272,
340,
440,
25764,
50,
25244,
63,
15704,
26,
267,
943,
14,
1971,
480,
15322,
471,
370,
675,
314,
1564,
3555,
3261,
1380,
314,
8363,
3878,
365,
6980,
2685,
267,
746,
4760,
5188,
221,
327,
7719,
7078,
5992,
2952,
781,
511,
314,
3878,
315,
8187,
14,
647,
2597,
339,
340,
3555,
63,
498,
63,
875,
365,
440,
488,
436,
1056,
14,
765,
508,
283,
4030,
356,
267,
372,
6183,
29967,
9313,
4030,
401,
430,
339,
340,
1056,
14,
765,
508,
283,
4030,
356,
267,
372,
485,
981,
63,
4342,
8,
1069,
9,
339,
327,
1056,
1083,
365,
664,
12,
3967,
1454,
9576,
436,
8761,
787,
4370,
701,
768,
4365,
63,
1014,
63,
2474,
4725,
2970,
297,
283,
4030,
1333,
272,
340,
3555,
63,
498,
63,
875,
26,
267,
372,
485,
2918,
63,
4342,
8,
4342,
63,
498,
63,
875,
12,
1056,
9,
339,
372,
485,
513,
63,
10159,
8,
1069,
9,
421,
199,
318,
485,
2918,
63,
4342,
8,
4342,
63,
498,
63,
875,
12,
1056,
304,
272,
408,
272,
28750,
2849,
3555,
272,
408,
272,
3555,
63,
498,
275,
22574,
14,
504,
63,
875,
8,
4342,
63,
498,
63,
875,
9,
272,
340,
440,
1228,
8,
4342,
63,
498,
12,
11243,
10725,
304,
267,
943,
14,
1971,
480,
6932,
13,
4342,
790,
3032,
370,
1564,
8363,
3261,
2685,
221,
327,
7719,
7078,
5992,
7037,
370,
1166,
5163,
267,
746,
4760,
5188,
221,
327,
961,
365,
440,
282,
3555,
272,
340,
440,
965,
63,
19806,
63,
739,
63,
2732,
8,
1069,
14,
751,
12,
3555,
63,
498,
304,
267,
943,
14,
1971,
8,
288,
399,
2,
1899,
450,
83,
16416,
370,
2879,
3555,
450,
83,
1928,
4983,
401,
288,
1056,
14,
751,
14,
2473,
12,
2649,
8,
4342,
63,
498,
9,
267,
776,
267,
746,
23724,
342,
339,
3555,
275,
10996,
1252,
362,
63,
4342,
8,
4342,
63,
498,
9,
272,
340,
3555,
365,
488,
26,
267,
943,
14,
1971,
8,
85,
2,
7424,
450,
83,
440,
1911,
401,
2649,
8,
4342,
63,
498,
430,
267,
746,
4760,
5188,
339,
1177,
63,
908,
275,
283,
1360,
7,
272,
340,
334,
288,
1056,
14,
6780,
14,
362,
360,
908,
297,
283,
1360,
358,
508,
283,
1001,
7,
503,
288,
283,
3578,
15,
1001,
7,
315,
1056,
14,
10614,
14,
362,
360,
2856,
63,
13089,
297,
283,
505,
15,
1360,
358,
272,
3461,
267,
1177,
63,
908,
275,
283,
1001,
7,
339,
372,
3555,
63,
4166,
63,
1345,
8,
4342,
12,
1056,
14,
751,
12,
1177,
63,
908,
9,
421,
199,
318,
485,
513,
63,
10159,
8,
1069,
304,
272,
408,
272,
3820,
1006,
17909,
8363,
272,
408,
272,
1973,
63,
815,
275,
359,
267,
469,
288,
298,
2918,
63,
354,
582,
1973,
14,
2918,
63,
354,
12,
288,
298,
4342,
63,
498,
582,
2649,
8,
773,
14,
1985,
14,
4342,
63,
498,
395,
267,
789,
267,
367,
1973,
315,
10996,
1252,
362,
63,
10159,
342,
267,
340,
965,
63,
19806,
63,
739,
63,
2732,
8,
1069,
14,
751,
12,
1973,
14,
1985,
14,
4342,
63,
498,
9,
272,
1622,
272,
372,
21072,
8,
773,
63,
815,
9,
421,
199,
32,
4921,
63,
1001,
199,
318,
485,
981,
63,
4342,
8,
1069,
304,
272,
408,
272,
11642,
1083,
367,
6425,
282,
892,
3555,
14,
272,
408,
272,
2929,
63,
354,
275,
488,
272,
862,
26,
267,
2929,
63,
354,
275,
1056,
14,
1001,
459,
2918,
63,
354,
418,
267,
5981,
275,
1056,
14,
1001,
459,
1308,
418,
267,
3555,
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,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
devs1991/test_edx_docmode
|
openedx/core/djangoapps/user_api/course_tag/tests/test_api.py
|
14
|
1402
|
"""
Test the user course tag API.
"""
from django.test import TestCase
from student.tests.factories import UserFactory
from nose.plugins.attrib import attr
from openedx.core.djangoapps.user_api.course_tag import api as course_tag_api
from opaque_keys.edx.locations import SlashSeparatedCourseKey
@attr('shard_2')
class TestCourseTagAPI(TestCase):
"""
Test the user service
"""
def setUp(self):
super(TestCourseTagAPI, self).setUp()
self.user = UserFactory.create()
self.course_id = SlashSeparatedCourseKey('test_org', 'test_course_number', 'test_run')
self.test_key = 'test_key'
def test_get_set_course_tag(self):
# get a tag that doesn't exist
tag = course_tag_api.get_course_tag(self.user, self.course_id, self.test_key)
self.assertIsNone(tag)
# test setting a new key
test_value = 'value'
course_tag_api.set_course_tag(self.user, self.course_id, self.test_key, test_value)
tag = course_tag_api.get_course_tag(self.user, self.course_id, self.test_key)
self.assertEqual(tag, test_value)
#test overwriting an existing key
test_value = 'value2'
course_tag_api.set_course_tag(self.user, self.course_id, self.test_key, test_value)
tag = course_tag_api.get_course_tag(self.user, self.course_id, self.test_key)
self.assertEqual(tag, test_value)
|
agpl-3.0
|
[
624,
199,
774,
314,
922,
2518,
1947,
3261,
14,
199,
624,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
6474,
14,
2219,
14,
15406,
492,
16047,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
504,
22709,
14,
1018,
14,
16432,
14,
751,
63,
1246,
14,
1972,
63,
1450,
492,
2986,
465,
2518,
63,
1450,
63,
1246,
199,
504,
15058,
63,
1612,
14,
8268,
14,
8022,
492,
30687,
421,
199,
32,
962,
360,
10810,
63,
18,
358,
199,
533,
1379,
6979,
1931,
3735,
8,
1746,
304,
272,
408,
272,
1379,
314,
922,
2435,
272,
408,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
6979,
1931,
3735,
12,
291,
680,
5996,
342,
267,
291,
14,
751,
275,
16047,
14,
981,
342,
267,
291,
14,
1972,
63,
344,
275,
30687,
360,
396,
63,
1308,
297,
283,
396,
63,
1972,
63,
1955,
297,
283,
396,
63,
1065,
358,
267,
291,
14,
396,
63,
498,
275,
283,
396,
63,
498,
7,
339,
347,
511,
63,
362,
63,
409,
63,
1972,
63,
1450,
8,
277,
304,
267,
327,
664,
282,
1947,
626,
3181,
1133,
2187,
267,
1947,
275,
2518,
63,
1450,
63,
1246,
14,
362,
63,
1972,
63,
1450,
8,
277,
14,
751,
12,
291,
14,
1972,
63,
344,
12,
291,
14,
396,
63,
498,
9,
267,
291,
14,
7702,
8,
1450,
9,
398,
327,
511,
4260,
282,
892,
790,
267,
511,
63,
585,
275,
283,
585,
7,
267,
2518,
63,
1450,
63,
1246,
14,
409,
63,
1972,
63,
1450,
8,
277,
14,
751,
12,
291,
14,
1972,
63,
344,
12,
291,
14,
396,
63,
498,
12,
511,
63,
585,
9,
267,
1947,
275,
2518,
63,
1450,
63,
1246,
14,
362,
63,
1972,
63,
1450,
8,
277,
14,
751,
12,
291,
14,
1972,
63,
344,
12,
291,
14,
396,
63,
498,
9,
267,
291,
14,
629,
8,
1450,
12,
511,
63,
585,
9,
398,
327,
396,
32592,
376,
3411,
790,
267,
511,
63,
585,
275,
283,
585,
18,
7,
267,
2518,
63,
1450,
63,
1246,
14,
409,
63,
1972,
63,
1450,
8,
277,
14,
751,
12,
291,
14,
1972,
63,
344,
12,
291,
14,
396,
63,
498,
12,
511,
63,
585,
9,
267,
1947,
275,
2518,
63,
1450,
63,
1246,
14,
362,
63,
1972,
63,
1450,
8,
277,
14,
751,
12,
291,
14,
1972,
63,
344,
12,
291,
14,
396,
63,
498,
9,
267,
291,
14,
629,
8,
1450,
12,
511,
63,
585,
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
] |
[
199,
774,
314,
922,
2518,
1947,
3261,
14,
199,
624,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
6474,
14,
2219,
14,
15406,
492,
16047,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
504,
22709,
14,
1018,
14,
16432,
14,
751,
63,
1246,
14,
1972,
63,
1450,
492,
2986,
465,
2518,
63,
1450,
63,
1246,
199,
504,
15058,
63,
1612,
14,
8268,
14,
8022,
492,
30687,
421,
199,
32,
962,
360,
10810,
63,
18,
358,
199,
533,
1379,
6979,
1931,
3735,
8,
1746,
304,
272,
408,
272,
1379,
314,
922,
2435,
272,
408,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
6979,
1931,
3735,
12,
291,
680,
5996,
342,
267,
291,
14,
751,
275,
16047,
14,
981,
342,
267,
291,
14,
1972,
63,
344,
275,
30687,
360,
396,
63,
1308,
297,
283,
396,
63,
1972,
63,
1955,
297,
283,
396,
63,
1065,
358,
267,
291,
14,
396,
63,
498,
275,
283,
396,
63,
498,
7,
339,
347,
511,
63,
362,
63,
409,
63,
1972,
63,
1450,
8,
277,
304,
267,
327,
664,
282,
1947,
626,
3181,
1133,
2187,
267,
1947,
275,
2518,
63,
1450,
63,
1246,
14,
362,
63,
1972,
63,
1450,
8,
277,
14,
751,
12,
291,
14,
1972,
63,
344,
12,
291,
14,
396,
63,
498,
9,
267,
291,
14,
7702,
8,
1450,
9,
398,
327,
511,
4260,
282,
892,
790,
267,
511,
63,
585,
275,
283,
585,
7,
267,
2518,
63,
1450,
63,
1246,
14,
409,
63,
1972,
63,
1450,
8,
277,
14,
751,
12,
291,
14,
1972,
63,
344,
12,
291,
14,
396,
63,
498,
12,
511,
63,
585,
9,
267,
1947,
275,
2518,
63,
1450,
63,
1246,
14,
362,
63,
1972,
63,
1450,
8,
277,
14,
751,
12,
291,
14,
1972,
63,
344,
12,
291,
14,
396,
63,
498,
9,
267,
291,
14,
629,
8,
1450,
12,
511,
63,
585,
9,
398,
327,
396,
32592,
376,
3411,
790,
267,
511,
63,
585,
275,
283,
585,
18,
7,
267,
2518,
63,
1450,
63,
1246,
14,
409,
63,
1972,
63,
1450,
8,
277,
14,
751,
12,
291,
14,
1972,
63,
344,
12,
291,
14,
396,
63,
498,
12,
511,
63,
585,
9,
267,
1947,
275,
2518,
63,
1450,
63,
1246,
14,
362,
63,
1972,
63,
1450,
8,
277,
14,
751,
12,
291,
14,
1972,
63,
344,
12,
291,
14,
396,
63,
498,
9,
267,
291,
14,
629,
8,
1450,
12,
511,
63,
585,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jwiegley/offlineimap
|
offlineimap/folder/Maildir.py
|
2
|
12410
|
# Maildir folder support
# Copyright (C) 2002 - 2007 John Goerzen
# <jgoerzen@complete.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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import socket
import time
import re
import os
from Base import BaseFolder
from threading import Lock
try:
from hashlib import md5
except ImportError:
from md5 import md5
from offlineimap import OfflineImapError
uidmatchre = re.compile(',U=(\d+)')
timestampmatchre = re.compile('(\d+)');
timeseq = 0
lasttime = long(0)
timelock = Lock()
def gettimeseq():
global lasttime, timeseq, timelock
timelock.acquire()
try:
thistime = long(time.time())
if thistime == lasttime:
timeseq += 1
return (thistime, timeseq)
else:
lasttime = thistime
timeseq = 0
return (thistime, timeseq)
finally:
timelock.release()
class MaildirFolder(BaseFolder):
def __init__(self, root, name, sep, repository, accountname, config):
self.name = name
self.config = config
self.dofsync = config.getdefaultboolean("general", "fsync", True)
self.root = root
self.sep = sep
self.messagelist = None
self.repository = repository
self.accountname = accountname
self.wincompatible = self.config.getdefaultboolean(
"Account "+self.accountname, "maildir-windows-compatible", False)
if self.wincompatible == False:
self.infosep = ':'
else:
self.infosep = '!'
self.flagmatchre = re.compile(self.infosep + '.*2,([A-Z]+)')
BaseFolder.__init__(self)
#self.ui is set in BaseFolder.init()
# Cache the full folder path, as we use getfullname() very often
self._fullname = os.path.join(self.getroot(), self.getname())
def getaccountname(self):
return self.accountname
def getfullname(self):
"""Return the absolute file path to the Maildir folder (sans cur|new)"""
return self._fullname
def getuidvalidity(self):
"""Maildirs have no notion of uidvalidity, so we just return a magic
token."""
return 42
#Checks to see if the given message is within the maximum age according
#to the maildir name which should begin with a timestamp
def _iswithinmaxage(self, messagename, maxage):
#In order to have the same behaviour as SINCE in an IMAP search
#we must convert this to the oldest time and then strip off hrs/mins
#from that day
oldest_time_utc = time.time() - (60*60*24*maxage)
oldest_time_struct = time.gmtime(oldest_time_utc)
oldest_time_today_seconds = ((oldest_time_struct[3] * 3600) \
+ (oldest_time_struct[4] * 60) \
+ oldest_time_struct[5])
oldest_time_utc -= oldest_time_today_seconds
timestampmatch = timestampmatchre.search(messagename)
timestampstr = timestampmatch.group()
timestamplong = long(timestampstr)
if(timestamplong < oldest_time_utc):
return False
else:
return True
def _scanfolder(self):
"""Cache the message list. Maildir flags are:
R (replied)
S (seen)
T (trashed)
D (draft)
F (flagged)
and must occur in ASCII order."""
retval = {}
files = []
nouidcounter = -1 # Messages without UIDs get
# negative UID numbers.
foldermd5 = md5(self.getvisiblename()).hexdigest()
folderstr = ',FMD5=' + foldermd5
for dirannex in ['new', 'cur']:
fulldirname = os.path.join(self.getfullname(), dirannex)
files.extend(os.path.join(fulldirname, filename) for
filename in os.listdir(fulldirname))
for file in files:
messagename = os.path.basename(file)
#check if there is a parameter for maxage / maxsize - then see if this
#message should be considered or not
maxage = self.config.getdefaultint("Account " + self.accountname, "maxage", -1)
maxsize = self.config.getdefaultint("Account " + self.accountname, "maxsize", -1)
if(maxage != -1):
isnewenough = self._iswithinmaxage(messagename, maxage)
if(isnewenough != True):
#this message is older than we should consider....
continue
#Check and see if the message is too big if the maxsize for this account is set
if(maxsize != -1):
filesize = os.path.getsize(file)
if(filesize > maxsize):
continue
foldermatch = messagename.find(folderstr) != -1
if not foldermatch:
# If there is no folder MD5 specified, or if it mismatches,
# assume it is a foreign (new) message and generate a
# negative uid for it
uid = nouidcounter
nouidcounter -= 1
else: # It comes from our folder.
uidmatch = uidmatchre.search(messagename)
uid = None
if not uidmatch:
uid = nouidcounter
nouidcounter -= 1
else:
uid = long(uidmatch.group(1))
flagmatch = self.flagmatchre.search(messagename)
flags = []
if flagmatch:
flags = [x for x in flagmatch.group(1)]
flags.sort()
retval[uid] = {'uid': uid,
'flags': flags,
'filename': file}
return retval
def quickchanged(self, statusfolder):
"""Returns True if the Maildir has changed"""
self.cachemessagelist()
# Folder has different uids than statusfolder => TRUE
if sorted(self.getmessageuidlist()) != \
sorted(statusfolder.getmessageuidlist()):
return True
# Also check for flag changes, it's quick on a Maildir
for (uid, message) in self.getmessagelist().iteritems():
if message['flags'] != statusfolder.getmessageflags(uid):
return True
return False #Nope, nothing changed
def cachemessagelist(self):
if self.messagelist is None:
self.messagelist = self._scanfolder()
def getmessagelist(self):
return self.messagelist
def getmessage(self, uid):
"""Return the content of the message"""
filename = self.messagelist[uid]['filename']
filepath = os.path.join(self.getfullname(), filename)
file = open(filepath, 'rt')
retval = file.read()
file.close()
#TODO: WHY are we replacing \r\n with \n here? And why do we
# read it as text?
return retval.replace("\r\n", "\n")
def getmessagetime( self, uid ):
filename = self.messagelist[uid]['filename']
filepath = os.path.join(self.getfullname(), filename)
st = os.stat(filepath)
return st.st_mtime
def savemessage(self, uid, content, flags, rtime):
# This function only ever saves to tmp/,
# but it calls savemessageflags() to actually save to cur/ or new/.
self.ui.debug('maildir', 'savemessage: called to write with flags %s '
'and content %s' % (repr(flags), repr(content)))
if uid < 0:
# We cannot assign a new uid.
return uid
if uid in self.messagelist:
# We already have it, just update flags.
self.savemessageflags(uid, flags)
return uid
# Otherwise, save the message in tmp/ and then call savemessageflags()
# to give it a permanent home.
tmpdir = os.path.join(self.getfullname(), 'tmp')
timeval, timeseq = gettimeseq()
messagename = '%d_%d.%d.%s,U=%d,FMD5=%s' % \
(timeval,
timeseq,
os.getpid(),
socket.gethostname(),
uid,
md5(self.getvisiblename()).hexdigest())
# open file and write it out
try:
fd = os.open(os.path.join(tmpdir, messagename),
os.O_EXCL|os.O_CREAT|os.O_WRONLY)
except OSError, e:
if e.errno == 17:
#FILE EXISTS ALREADY
severity = OfflineImapError.ERROR.MESSAGE
raise OfflineImapError("Unique filename %s already existing." %\
messagename, severity)
else:
raise
file = os.fdopen(fd, 'wt')
file.write(content)
# Make sure the data hits the disk
file.flush()
if self.dofsync:
os.fsync(fd)
file.close()
if rtime != None:
os.utime(os.path.join(tmpdir, messagename), (rtime, rtime))
self.messagelist[uid] = {'uid': uid, 'flags': [],
'filename': os.path.join('tmp', messagename)}
# savemessageflags moves msg to 'cur' or 'new' as appropriate
self.savemessageflags(uid, flags)
self.ui.debug('maildir', 'savemessage: returning uid %d' % uid)
return uid
def getmessageflags(self, uid):
return self.messagelist[uid]['flags']
def savemessageflags(self, uid, flags):
oldfilename = self.messagelist[uid]['filename']
dir_prefix, newname = os.path.split(oldfilename)
tmpdir = os.path.join(self.getfullname(), 'tmp')
if 'S' in flags:
# If a message has been seen, it goes into the cur
# directory. CR debian#152482
dir_prefix = 'cur'
else:
dir_prefix = 'new'
infostr = self.infosep
infomatch = re.search('(' + self.infosep + '.*)$', newname)
if infomatch: # If the info string is present..
infostr = infomatch.group(1)
newname = newname.split(self.infosep)[0] # Strip off the info string.
infostr = re.sub('2,[A-Z]*', '', infostr)
flags.sort()
infostr += '2,' + ''.join(flags)
newname += infostr
newfilename = os.path.join(dir_prefix, newname)
if (newfilename != oldfilename):
os.rename(os.path.join(self.getfullname(), oldfilename),
os.path.join(self.getfullname(), newfilename))
self.messagelist[uid]['flags'] = flags
self.messagelist[uid]['filename'] = newfilename
# By now, the message had better not be in tmp/ land!
final_dir, final_name = os.path.split(self.messagelist[uid]['filename'])
assert final_dir != 'tmp'
def deletemessage(self, uid):
"""Unlinks a message file from the Maildir.
:param uid: UID of a mail message
:type uid: String
:return: Nothing, or an Exception if UID but no corresponding file
found.
"""
if not self.uidexists(uid):
return
filename = self.messagelist[uid]['filename']
filepath = os.path.join(self.getfullname(), filename)
try:
os.unlink(filepath)
except OSError:
# Can't find the file -- maybe already deleted?
newmsglist = self._scanfolder()
if uid in newmsglist: # Nope, try new filename.
filename = newmsglist[uid]['filename']
filepath = os.path.join(self.getfullname(), filename)
os.unlink(filepath)
# Yep -- return.
del(self.messagelist[uid])
|
gpl-2.0
|
[
3,
18027,
694,
4922,
2291,
199,
3,
1898,
334,
35,
9,
14790,
446,
10219,
17815,
3971,
281,
5193,
199,
3,
665,
74,
1939,
281,
5193,
32,
4883,
14,
1308,
30,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
259,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
8217,
199,
199,
646,
2838,
199,
646,
900,
199,
646,
295,
199,
646,
747,
199,
504,
3523,
492,
3523,
7850,
199,
504,
5796,
492,
15536,
199,
199,
893,
26,
272,
687,
8337,
492,
6128,
21,
199,
2590,
3545,
26,
272,
687,
6128,
21,
492,
6128,
21,
199,
199,
504,
26302,
15311,
492,
28856,
604,
41,
1130,
547,
199,
199,
1535,
1431,
264,
275,
295,
14,
2014,
5102,
53,
2687,
60,
68,
11,
5942,
199,
3954,
1431,
264,
275,
295,
14,
2014,
360,
2961,
68,
11,
5942,
27,
199,
199,
521,
3610,
275,
378,
199,
2019,
521,
275,
1846,
8,
16,
9,
199,
521,
831,
275,
15536,
342,
199,
199,
318,
664,
521,
3610,
837,
272,
2288,
2061,
521,
12,
900,
3610,
12,
900,
831,
272,
900,
831,
14,
8174,
342,
272,
862,
26,
267,
294,
631,
1036,
275,
1846,
8,
521,
14,
521,
1012,
267,
340,
294,
631,
1036,
508,
2061,
521,
26,
288,
900,
3610,
847,
413,
288,
372,
334,
273,
631,
1036,
12,
900,
3610,
9,
267,
587,
26,
288,
2061,
521,
275,
294,
631,
1036,
288,
900,
3610,
275,
378,
288,
372,
334,
273,
631,
1036,
12,
900,
3610,
9,
272,
3753,
26,
267,
900,
831,
14,
3221,
342,
199,
199,
533,
18027,
694,
7850,
8,
1563,
7850,
304,
272,
347,
636,
826,
721,
277,
12,
1738,
12,
536,
12,
7375,
12,
7611,
12,
2933,
354,
12,
1101,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
888,
275,
1101,
267,
291,
14,
1117,
2319,
1870,
275,
1101,
14,
362,
885,
4871,
480,
10706,
401,
298,
2319,
1870,
401,
715,
9,
267,
291,
14,
1231,
275,
1738,
267,
291,
14,
4127,
275,
7375,
267,
291,
14,
1188,
513,
275,
488,
267,
291,
14,
8421,
275,
7611,
267,
291,
14,
2048,
354,
275,
2933,
354,
398,
291,
14,
2676,
6490,
275,
291,
14,
888,
14,
362,
885,
4871,
8,
288,
298,
6009,
7210,
277,
14,
2048,
354,
12,
298,
1198,
694,
13,
8258,
13,
6490,
401,
756,
9,
398,
340,
291,
14,
2676,
6490,
508,
756,
26,
288,
291,
14,
815,
4127,
275,
10871,
267,
587,
26,
288,
291,
14,
815,
4127,
275,
29376,
398,
291,
14,
4173,
1431,
264,
275,
295,
14,
2014,
8,
277,
14,
815,
4127,
435,
1987,
10,
18,
12,
779,
33,
13,
58,
2807,
5942,
398,
3523,
7850,
855,
826,
721,
277,
9,
267,
327,
277,
14,
1907,
365,
663,
315,
3523,
7850,
14,
826,
342,
267,
327,
11977,
314,
2615,
4922,
931,
12,
465,
781,
675,
664,
9930,
342,
7437,
14115,
267,
291,
423,
9930,
275,
747,
14,
515,
14,
904,
8,
277,
14,
24544,
1062,
291,
14,
362,
354,
1012,
339,
347,
664,
2048,
354,
8,
277,
304,
267,
372,
291,
14,
2048,
354,
339,
347,
664,
9930,
8,
277,
304,
267,
408,
1767,
314,
3679,
570,
931,
370,
314,
18027,
694,
4922,
334,
26052,
1094,
92,
1222,
9471,
267,
372,
291,
423,
9930,
339,
347,
664,
1535,
31901,
8,
277,
304,
267,
408,
13681,
3220,
1172,
949,
949,
296,
402,
1747,
31901,
12,
880,
781,
2951,
372,
282,
10628,
267,
1526,
1041,
267,
372,
5685,
339,
327,
11834,
370,
1937,
340,
314,
1627,
1245,
365,
4453,
314,
5696,
11437,
7182,
272,
327,
475,
314,
6016,
694,
536,
1314,
1077,
5386,
543,
282,
4913,
272,
347,
485,
374,
12541,
988,
474,
8,
277,
12,
15634,
643,
17604,
12,
1390,
474,
304,
267,
327,
607,
1865,
370,
1172,
314,
2011,
13942,
465,
428,
568,
2089,
315,
376,
31011,
2754,
267,
327,
1129,
1471,
3957,
642,
370,
314,
29493,
900,
436,
2066,
6202,
2331,
394,
2393,
15,
29361,
267,
327,
504,
626,
5382,
267,
29493,
63,
521,
63,
5834,
275,
900,
14,
521,
342,
446,
334,
2259,
10,
2259,
10,
1194,
10,
988,
474,
9,
267,
29493,
63,
521,
63,
1820,
275,
900,
14,
22227,
8,
393,
2614,
63,
521,
63,
5834,
9,
267,
29493,
63,
521,
63,
8136,
63,
4515,
275,
3666,
393,
2614,
63,
521,
63,
1820,
59,
19,
61,
627,
15751,
9,
971,
288,
435,
334,
393,
2614,
63,
521,
63,
1820,
59,
20,
61,
627,
5212,
9,
971,
288,
435,
29493,
63,
521,
63,
1820,
59,
21,
566,
267,
29493,
63,
521,
63,
5834,
4862,
29493,
63,
521,
63,
8136,
63,
4515,
398,
4913,
1431,
275,
4913,
1431,
264,
14,
1733,
8,
17091,
643,
17604,
9,
267,
4913,
495,
275,
4913,
1431,
14,
923,
342,
267,
4913,
2809,
275,
1846,
8,
3954,
495,
9,
267,
340,
8,
3954,
2809,
665,
29493,
63,
521,
63,
5834,
304,
288,
372,
756,
267,
587,
26,
288,
372,
715,
2378,
347,
485,
6282,
3741,
8,
277,
304,
267,
408,
4437,
314,
1245,
769,
14,
221,
18027,
694,
3285,
787,
26,
267,
820,
334,
1155,
1857,
9,
267,
428,
334,
8606,
9,
267,
377,
334,
454,
21189,
9,
267,
577,
334,
7185,
9,
267,
481,
334,
4173,
3046,
9,
267,
436,
1471,
4781,
315,
10485,
1865,
1041,
267,
9151,
275,
1052,
267,
1584
] |
[
18027,
694,
4922,
2291,
199,
3,
1898,
334,
35,
9,
14790,
446,
10219,
17815,
3971,
281,
5193,
199,
3,
665,
74,
1939,
281,
5193,
32,
4883,
14,
1308,
30,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
259,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
8217,
199,
199,
646,
2838,
199,
646,
900,
199,
646,
295,
199,
646,
747,
199,
504,
3523,
492,
3523,
7850,
199,
504,
5796,
492,
15536,
199,
199,
893,
26,
272,
687,
8337,
492,
6128,
21,
199,
2590,
3545,
26,
272,
687,
6128,
21,
492,
6128,
21,
199,
199,
504,
26302,
15311,
492,
28856,
604,
41,
1130,
547,
199,
199,
1535,
1431,
264,
275,
295,
14,
2014,
5102,
53,
2687,
60,
68,
11,
5942,
199,
3954,
1431,
264,
275,
295,
14,
2014,
360,
2961,
68,
11,
5942,
27,
199,
199,
521,
3610,
275,
378,
199,
2019,
521,
275,
1846,
8,
16,
9,
199,
521,
831,
275,
15536,
342,
199,
199,
318,
664,
521,
3610,
837,
272,
2288,
2061,
521,
12,
900,
3610,
12,
900,
831,
272,
900,
831,
14,
8174,
342,
272,
862,
26,
267,
294,
631,
1036,
275,
1846,
8,
521,
14,
521,
1012,
267,
340,
294,
631,
1036,
508,
2061,
521,
26,
288,
900,
3610,
847,
413,
288,
372,
334,
273,
631,
1036,
12,
900,
3610,
9,
267,
587,
26,
288,
2061,
521,
275,
294,
631,
1036,
288,
900,
3610,
275,
378,
288,
372,
334,
273,
631,
1036,
12,
900,
3610,
9,
272,
3753,
26,
267,
900,
831,
14,
3221,
342,
199,
199,
533,
18027,
694,
7850,
8,
1563,
7850,
304,
272,
347,
636,
826,
721,
277,
12,
1738,
12,
536,
12,
7375,
12,
7611,
12,
2933,
354,
12,
1101,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
888,
275,
1101,
267,
291,
14,
1117,
2319,
1870,
275,
1101,
14,
362,
885,
4871,
480,
10706,
401,
298,
2319,
1870,
401,
715,
9,
267,
291,
14,
1231,
275,
1738,
267,
291,
14,
4127,
275,
7375,
267,
291,
14,
1188,
513,
275,
488,
267,
291,
14,
8421,
275,
7611,
267,
291,
14,
2048,
354,
275,
2933,
354,
398,
291,
14,
2676,
6490,
275,
291,
14,
888,
14,
362,
885,
4871,
8,
288,
298,
6009,
7210,
277,
14,
2048,
354,
12,
298,
1198,
694,
13,
8258,
13,
6490,
401,
756,
9,
398,
340,
291,
14,
2676,
6490,
508,
756,
26,
288,
291,
14,
815,
4127,
275,
10871,
267,
587,
26,
288,
291,
14,
815,
4127,
275,
29376,
398,
291,
14,
4173,
1431,
264,
275,
295,
14,
2014,
8,
277,
14,
815,
4127,
435,
1987,
10,
18,
12,
779,
33,
13,
58,
2807,
5942,
398,
3523,
7850,
855,
826,
721,
277,
9,
267,
327,
277,
14,
1907,
365,
663,
315,
3523,
7850,
14,
826,
342,
267,
327,
11977,
314,
2615,
4922,
931,
12,
465,
781,
675,
664,
9930,
342,
7437,
14115,
267,
291,
423,
9930,
275,
747,
14,
515,
14,
904,
8,
277,
14,
24544,
1062,
291,
14,
362,
354,
1012,
339,
347,
664,
2048,
354,
8,
277,
304,
267,
372,
291,
14,
2048,
354,
339,
347,
664,
9930,
8,
277,
304,
267,
408,
1767,
314,
3679,
570,
931,
370,
314,
18027,
694,
4922,
334,
26052,
1094,
92,
1222,
9471,
267,
372,
291,
423,
9930,
339,
347,
664,
1535,
31901,
8,
277,
304,
267,
408,
13681,
3220,
1172,
949,
949,
296,
402,
1747,
31901,
12,
880,
781,
2951,
372,
282,
10628,
267,
1526,
1041,
267,
372,
5685,
339,
327,
11834,
370,
1937,
340,
314,
1627,
1245,
365,
4453,
314,
5696,
11437,
7182,
272,
327,
475,
314,
6016,
694,
536,
1314,
1077,
5386,
543,
282,
4913,
272,
347,
485,
374,
12541,
988,
474,
8,
277,
12,
15634,
643,
17604,
12,
1390,
474,
304,
267,
327,
607,
1865,
370,
1172,
314,
2011,
13942,
465,
428,
568,
2089,
315,
376,
31011,
2754,
267,
327,
1129,
1471,
3957,
642,
370,
314,
29493,
900,
436,
2066,
6202,
2331,
394,
2393,
15,
29361,
267,
327,
504,
626,
5382,
267,
29493,
63,
521,
63,
5834,
275,
900,
14,
521,
342,
446,
334,
2259,
10,
2259,
10,
1194,
10,
988,
474,
9,
267,
29493,
63,
521,
63,
1820,
275,
900,
14,
22227,
8,
393,
2614,
63,
521,
63,
5834,
9,
267,
29493,
63,
521,
63,
8136,
63,
4515,
275,
3666,
393,
2614,
63,
521,
63,
1820,
59,
19,
61,
627,
15751,
9,
971,
288,
435,
334,
393,
2614,
63,
521,
63,
1820,
59,
20,
61,
627,
5212,
9,
971,
288,
435,
29493,
63,
521,
63,
1820,
59,
21,
566,
267,
29493,
63,
521,
63,
5834,
4862,
29493,
63,
521,
63,
8136,
63,
4515,
398,
4913,
1431,
275,
4913,
1431,
264,
14,
1733,
8,
17091,
643,
17604,
9,
267,
4913,
495,
275,
4913,
1431,
14,
923,
342,
267,
4913,
2809,
275,
1846,
8,
3954,
495,
9,
267,
340,
8,
3954,
2809,
665,
29493,
63,
521,
63,
5834,
304,
288,
372,
756,
267,
587,
26,
288,
372,
715,
2378,
347,
485,
6282,
3741,
8,
277,
304,
267,
408,
4437,
314,
1245,
769,
14,
221,
18027,
694,
3285,
787,
26,
267,
820,
334,
1155,
1857,
9,
267,
428,
334,
8606,
9,
267,
377,
334,
454,
21189,
9,
267,
577,
334,
7185,
9,
267,
481,
334,
4173,
3046,
9,
267,
436,
1471,
4781,
315,
10485,
1865,
1041,
267,
9151,
275,
1052,
267,
1584,
0
] |
[
1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
joelbrock/NOFC_CORE
|
documentation/Reference Code/Wedge/installation/install_server.py
|
10
|
1189
|
#!/usr/bin/env python
import warnings
from installers import *
def install_server_db(username, password, sample_data=False):
import MySQLdb
connection = MySQLdb.connect("localhost", username, password)
exec_script(connection, "script/create_server_db.sql")
warnings.filterwarnings("ignore", "^Unknown table '.*'$")
exec_scripts(connection, 'is4c_log/tables/*.table')
exec_scripts(connection, 'is4c_log/views/*.viw', first_paths=[
'is4c_log/views/dlog.viw',
'is4c_log/views/tendertape.viw',
])
exec_scripts(connection, 'is4c_op/tables/*.table')
exec_scripts(connection, 'is4c_op/views/*.viw')
if sample_data:
warnings.filterwarnings("ignore", "^Data (?:too long|truncated) for column '(?:description|subdept_name)' at row \d+$")
exec_scripts(connection, 'is4c_op/data/*.insert')
warnings.resetwarnings()
exec_script(connection, "script/create_server_acct.sql")
remove_bind_restriction_prompt()
if __name__ == "__main__":
user_input = get_user_input()
if user_input:
install_server_db(*user_input)
print "Done"
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
8065,
199,
646,
3598,
2999,
199,
504,
18535,
83,
492,
627,
8065,
199,
318,
3907,
63,
1000,
63,
697,
8,
2473,
12,
2505,
12,
2690,
63,
576,
29,
797,
304,
1128,
492,
25709,
1128,
1950,
275,
25709,
14,
2242,
480,
5967,
401,
3434,
12,
2505,
9,
2958,
2146,
63,
1579,
8,
2105,
12,
298,
1579,
15,
981,
63,
1000,
63,
697,
14,
3009,
531,
2958,
3598,
14,
23945,
480,
4247,
401,
18129,
5912,
1817,
1987,
10223,
22550,
2958,
2146,
63,
6429,
8,
2105,
12,
283,
374,
20,
67,
63,
793,
15,
5987,
20362,
1224,
358,
1128,
2146,
63,
6429,
8,
2105,
12,
283,
374,
20,
67,
63,
793,
15,
4196,
20362,
433,
87,
297,
1642,
63,
3771,
1524,
1675,
283,
374,
20,
67,
63,
793,
15,
4196,
15,
68,
793,
14,
433,
87,
297,
1675,
283,
374,
20,
67,
63,
793,
15,
4196,
15,
724,
424,
502,
321,
14,
433,
87,
297,
1675,
4794,
2958,
2146,
63,
6429,
8,
2105,
12,
283,
374,
20,
67,
63,
411,
15,
5987,
20362,
1224,
358,
1128,
2146,
63,
6429,
8,
2105,
12,
283,
374,
20,
67,
63,
411,
15,
4196,
20362,
433,
87,
358,
2958,
340,
2690,
63,
576,
26,
1039,
3598,
14,
23945,
480,
4247,
401,
18129,
1451,
16697,
7354,
1846,
92,
19347,
9,
367,
2763,
283,
5169,
1802,
92,
954,
271,
541,
63,
354,
3171,
737,
1962,
971,
68,
11,
22550,
1039,
2146,
63,
6429,
8,
2105,
12,
283,
374,
20,
67,
63,
411,
15,
576,
20362,
3176,
358,
2958,
3598,
14,
3958,
5451,
342,
2958,
2146,
63,
1579,
8,
2105,
12,
298,
1579,
15,
981,
63,
1000,
63,
23015,
14,
3009,
531,
2958,
2813,
63,
3409,
63,
23423,
63,
7650,
342,
8065,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
1128,
922,
63,
1210,
275,
664,
63,
751,
63,
1210,
342,
1128,
340,
922,
63,
1210,
26,
1039,
3907,
63,
1000,
63,
697,
2031,
751,
63,
1210,
9,
1039,
870,
298,
10759,
2,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
8065,
199,
646,
3598,
2999,
199,
504,
18535,
83,
492,
627,
8065,
199,
318,
3907,
63,
1000,
63,
697,
8,
2473,
12,
2505,
12,
2690,
63,
576,
29,
797,
304,
1128,
492,
25709,
1128,
1950,
275,
25709,
14,
2242,
480,
5967,
401,
3434,
12,
2505,
9,
2958,
2146,
63,
1579,
8,
2105,
12,
298,
1579,
15,
981,
63,
1000,
63,
697,
14,
3009,
531,
2958,
3598,
14,
23945,
480,
4247,
401,
18129,
5912,
1817,
1987,
10223,
22550,
2958,
2146,
63,
6429,
8,
2105,
12,
283,
374,
20,
67,
63,
793,
15,
5987,
20362,
1224,
358,
1128,
2146,
63,
6429,
8,
2105,
12,
283,
374,
20,
67,
63,
793,
15,
4196,
20362,
433,
87,
297,
1642,
63,
3771,
1524,
1675,
283,
374,
20,
67,
63,
793,
15,
4196,
15,
68,
793,
14,
433,
87,
297,
1675,
283,
374,
20,
67,
63,
793,
15,
4196,
15,
724,
424,
502,
321,
14,
433,
87,
297,
1675,
4794,
2958,
2146,
63,
6429,
8,
2105,
12,
283,
374,
20,
67,
63,
411,
15,
5987,
20362,
1224,
358,
1128,
2146,
63,
6429,
8,
2105,
12,
283,
374,
20,
67,
63,
411,
15,
4196,
20362,
433,
87,
358,
2958,
340,
2690,
63,
576,
26,
1039,
3598,
14,
23945,
480,
4247,
401,
18129,
1451,
16697,
7354,
1846,
92,
19347,
9,
367,
2763,
283,
5169,
1802,
92,
954,
271,
541,
63,
354,
3171,
737,
1962,
971,
68,
11,
22550,
1039,
2146,
63,
6429,
8,
2105,
12,
283,
374,
20,
67,
63,
411,
15,
576,
20362,
3176,
358,
2958,
3598,
14,
3958,
5451,
342,
2958,
2146,
63,
1579,
8,
2105,
12,
298,
1579,
15,
981,
63,
1000,
63,
23015,
14,
3009,
531,
2958,
2813,
63,
3409,
63,
23423,
63,
7650,
342,
8065,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
1128,
922,
63,
1210,
275,
664,
63,
751,
63,
1210,
342,
1128,
340,
922,
63,
1210,
26,
1039,
3907,
63,
1000,
63,
697,
2031,
751,
63,
1210,
9,
1039,
870,
298,
10759,
2,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
esten/StoriTell
|
StoriTell/tastypie/http.py
|
2
|
1162
|
"""
The various HTTP responses for use in returning proper HTTP codes.
"""
from django.http import HttpResponse
class HttpCreated(HttpResponse):
status_code = 201
def __init__(self, *args, **kwargs):
if 'location' in kwargs:
location = kwargs['location']
del(kwargs['location'])
super(HttpCreated, self).__init__(*args, **kwargs)
self['Location'] = location
class HttpAccepted(HttpResponse):
status_code = 204
class HttpMultipleChoices(HttpResponse):
status_code = 300
class HttpSeeOther(HttpResponse):
status_code = 303
class HttpNotModified(HttpResponse):
status_code = 304
class HttpBadRequest(HttpResponse):
status_code = 400
class HttpUnauthorized(HttpResponse):
status_code = 401
class HttpForbidden(HttpResponse):
status_code = 403
class HttpMethodNotAllowed(HttpResponse):
status_code = 405
class HttpConflict(HttpResponse):
status_code = 409
class HttpGone(HttpResponse):
status_code = 410
class HttpApplicationError(HttpResponse):
status_code = 500
class HttpNotImplemented(HttpResponse):
status_code = 501
|
bsd-3-clause
|
[
624,
199,
1918,
7750,
3101,
9320,
367,
675,
315,
8152,
5576,
3101,
9479,
14,
199,
624,
199,
504,
1639,
14,
1014,
492,
6183,
421,
199,
533,
4760,
10502,
8,
16287,
304,
272,
2004,
63,
600,
275,
1784,
2286,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
283,
1985,
7,
315,
2074,
26,
288,
2909,
275,
2074,
459,
1985,
418,
288,
2150,
8,
958,
459,
1985,
1105,
2728,
1613,
8,
5779,
10502,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
459,
6592,
418,
275,
2909,
421,
199,
533,
4760,
1945,
7203,
8,
16287,
304,
272,
2004,
63,
600,
275,
14785,
421,
199,
533,
4760,
8433,
30806,
8,
16287,
304,
272,
2004,
63,
600,
275,
9601,
421,
199,
533,
4760,
9295,
8632,
8,
16287,
304,
272,
2004,
63,
600,
275,
25989,
421,
199,
533,
4760,
1763,
11911,
8,
16287,
304,
272,
2004,
63,
600,
275,
20398,
421,
199,
533,
4760,
12380,
8,
16287,
304,
272,
2004,
63,
600,
275,
8290,
421,
199,
533,
4760,
28290,
8,
16287,
304,
272,
2004,
63,
600,
275,
13952,
421,
199,
533,
4760,
17454,
8,
16287,
304,
272,
2004,
63,
600,
275,
13269,
421,
199,
533,
4760,
3767,
29967,
8,
16287,
304,
272,
2004,
63,
600,
275,
25766,
421,
199,
533,
4760,
15919,
8,
16287,
304,
272,
2004,
63,
600,
275,
21292,
421,
199,
533,
4760,
39,
368,
8,
16287,
304,
272,
2004,
63,
600,
275,
32321,
421,
199,
533,
4760,
5039,
547,
8,
16287,
304,
272,
2004,
63,
600,
275,
6891,
421,
199,
533,
4760,
14278,
8,
16287,
304,
272,
2004,
63,
600,
275,
28606,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
1918,
7750,
3101,
9320,
367,
675,
315,
8152,
5576,
3101,
9479,
14,
199,
624,
199,
504,
1639,
14,
1014,
492,
6183,
421,
199,
533,
4760,
10502,
8,
16287,
304,
272,
2004,
63,
600,
275,
1784,
2286,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
283,
1985,
7,
315,
2074,
26,
288,
2909,
275,
2074,
459,
1985,
418,
288,
2150,
8,
958,
459,
1985,
1105,
2728,
1613,
8,
5779,
10502,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
459,
6592,
418,
275,
2909,
421,
199,
533,
4760,
1945,
7203,
8,
16287,
304,
272,
2004,
63,
600,
275,
14785,
421,
199,
533,
4760,
8433,
30806,
8,
16287,
304,
272,
2004,
63,
600,
275,
9601,
421,
199,
533,
4760,
9295,
8632,
8,
16287,
304,
272,
2004,
63,
600,
275,
25989,
421,
199,
533,
4760,
1763,
11911,
8,
16287,
304,
272,
2004,
63,
600,
275,
20398,
421,
199,
533,
4760,
12380,
8,
16287,
304,
272,
2004,
63,
600,
275,
8290,
421,
199,
533,
4760,
28290,
8,
16287,
304,
272,
2004,
63,
600,
275,
13952,
421,
199,
533,
4760,
17454,
8,
16287,
304,
272,
2004,
63,
600,
275,
13269,
421,
199,
533,
4760,
3767,
29967,
8,
16287,
304,
272,
2004,
63,
600,
275,
25766,
421,
199,
533,
4760,
15919,
8,
16287,
304,
272,
2004,
63,
600,
275,
21292,
421,
199,
533,
4760,
39,
368,
8,
16287,
304,
272,
2004,
63,
600,
275,
32321,
421,
199,
533,
4760,
5039,
547,
8,
16287,
304,
272,
2004,
63,
600,
275,
6891,
421,
199,
533,
4760,
14278,
8,
16287,
304,
272,
2004,
63,
600,
275,
28606,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
openlabs/nereid-project
|
__init__.py
|
2
|
1518
|
# -*- coding: utf-8 -*-
'''
nereid_project
:copyright: (c) 2010-2014 by Openlabs Technologies & Consulting (P) Ltd.
:license: GPLv3, see LICENSE for more details
'''
from trytond.pool import Pool
from website import WebSite
from project import (
ProjectWorkMember, ProjectInvitation, ProjectWorkInvitation,
Project, ProjectHistory, ProjectWorkCommit
)
from activity import Activity
from attachment import Attachment
from timesheet import TimesheetEmployeeDay, TimesheetLine
from tag import Tag, TaskTags
from company import Company, CompanyProjectAdmins
from user import NereidUser
from configuration import Configuration
from task import TaskUsers, Task
from iteration import Iteration, IterationBacklog, CloseIterationAsk, \
CloseIteration
def register():
"""This function will register trytond module nereid_project
"""
Pool.register(
WebSite,
Company,
CompanyProjectAdmins,
TaskUsers,
Iteration,
ProjectWorkMember,
ProjectInvitation,
TimesheetEmployeeDay,
ProjectWorkInvitation,
Project,
Tag,
TaskTags,
ProjectHistory,
ProjectWorkCommit,
Task,
TimesheetLine,
Activity,
NereidUser,
Attachment,
Configuration,
IterationBacklog,
CloseIterationAsk,
module='nereid_project', type_='model',
)
Pool.register(
CloseIteration,
module='nereid_project', type_='wizard',
)
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
2344,
272,
1279,
264,
344,
63,
1715,
339,
520,
7307,
26,
334,
67,
9,
7129,
13,
7280,
701,
3232,
76,
2101,
19215,
1253,
1448,
83,
427,
316,
334,
48,
9,
12126,
14,
272,
520,
1682,
26,
14629,
86,
19,
12,
1937,
5113,
367,
1655,
2436,
199,
199,
2344,
199,
504,
862,
1860,
68,
14,
2293,
492,
15553,
199,
199,
504,
10691,
492,
6001,
8972,
199,
504,
2199,
492,
334,
272,
7290,
6517,
7021,
12,
7290,
14883,
5314,
12,
7290,
6517,
14883,
5314,
12,
272,
7290,
12,
7290,
12114,
12,
7290,
6517,
11421,
199,
9,
199,
504,
10679,
492,
21885,
199,
504,
12193,
492,
21328,
434,
199,
504,
900,
5069,
492,
4703,
5069,
22635,
12631,
12,
4703,
5069,
3049,
199,
504,
1947,
492,
8053,
12,
8495,
9440,
199,
504,
7233,
492,
15878,
12,
15878,
4761,
4880,
83,
199,
504,
922,
492,
5612,
264,
344,
1899,
199,
504,
2897,
492,
11595,
199,
504,
2120,
492,
8495,
12117,
12,
8495,
199,
504,
8494,
492,
473,
5388,
12,
473,
5388,
4540,
793,
12,
15524,
8666,
25525,
12,
971,
272,
15524,
8666,
421,
199,
318,
2274,
837,
272,
408,
2765,
805,
911,
2274,
862,
1860,
68,
859,
1279,
264,
344,
63,
1715,
272,
408,
272,
15553,
14,
2683,
8,
267,
6001,
8972,
12,
267,
15878,
12,
267,
15878,
4761,
4880,
83,
12,
267,
8495,
12117,
12,
267,
473,
5388,
12,
267,
7290,
6517,
7021,
12,
267,
7290,
14883,
5314,
12,
267,
4703,
5069,
22635,
12631,
12,
267,
7290,
6517,
14883,
5314,
12,
267,
7290,
12,
267,
8053,
12,
267,
8495,
9440,
12,
267,
7290,
12114,
12,
267,
7290,
6517,
11421,
12,
267,
8495,
12,
267,
4703,
5069,
3049,
12,
267,
21885,
12,
267,
5612,
264,
344,
1899,
12,
267,
21328,
434,
12,
267,
11595,
12,
267,
473,
5388,
4540,
793,
12,
267,
15524,
8666,
25525,
12,
267,
859,
534,
685,
264,
344,
63,
1715,
297,
730,
7993,
1238,
297,
272,
776,
272,
15553,
14,
2683,
8,
267,
15524,
8666,
12,
267,
859,
534,
685,
264,
344,
63,
1715,
297,
730,
7993,
9819,
297,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
2344,
272,
1279,
264,
344,
63,
1715,
339,
520,
7307,
26,
334,
67,
9,
7129,
13,
7280,
701,
3232,
76,
2101,
19215,
1253,
1448,
83,
427,
316,
334,
48,
9,
12126,
14,
272,
520,
1682,
26,
14629,
86,
19,
12,
1937,
5113,
367,
1655,
2436,
199,
199,
2344,
199,
504,
862,
1860,
68,
14,
2293,
492,
15553,
199,
199,
504,
10691,
492,
6001,
8972,
199,
504,
2199,
492,
334,
272,
7290,
6517,
7021,
12,
7290,
14883,
5314,
12,
7290,
6517,
14883,
5314,
12,
272,
7290,
12,
7290,
12114,
12,
7290,
6517,
11421,
199,
9,
199,
504,
10679,
492,
21885,
199,
504,
12193,
492,
21328,
434,
199,
504,
900,
5069,
492,
4703,
5069,
22635,
12631,
12,
4703,
5069,
3049,
199,
504,
1947,
492,
8053,
12,
8495,
9440,
199,
504,
7233,
492,
15878,
12,
15878,
4761,
4880,
83,
199,
504,
922,
492,
5612,
264,
344,
1899,
199,
504,
2897,
492,
11595,
199,
504,
2120,
492,
8495,
12117,
12,
8495,
199,
504,
8494,
492,
473,
5388,
12,
473,
5388,
4540,
793,
12,
15524,
8666,
25525,
12,
971,
272,
15524,
8666,
421,
199,
318,
2274,
837,
272,
408,
2765,
805,
911,
2274,
862,
1860,
68,
859,
1279,
264,
344,
63,
1715,
272,
408,
272,
15553,
14,
2683,
8,
267,
6001,
8972,
12,
267,
15878,
12,
267,
15878,
4761,
4880,
83,
12,
267,
8495,
12117,
12,
267,
473,
5388,
12,
267,
7290,
6517,
7021,
12,
267,
7290,
14883,
5314,
12,
267,
4703,
5069,
22635,
12631,
12,
267,
7290,
6517,
14883,
5314,
12,
267,
7290,
12,
267,
8053,
12,
267,
8495,
9440,
12,
267,
7290,
12114,
12,
267,
7290,
6517,
11421,
12,
267,
8495,
12,
267,
4703,
5069,
3049,
12,
267,
21885,
12,
267,
5612,
264,
344,
1899,
12,
267,
21328,
434,
12,
267,
11595,
12,
267,
473,
5388,
4540,
793,
12,
267,
15524,
8666,
25525,
12,
267,
859,
534,
685,
264,
344,
63,
1715,
297,
730,
7993,
1238,
297,
272,
776,
272,
15553,
14,
2683,
8,
267,
15524,
8666,
12,
267,
859,
534,
685,
264,
344,
63,
1715,
297,
730,
7993,
9819,
297,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
davits/ycmd
|
ycmd/tests/typescript/debug_info_test.py
|
4
|
1812
|
# Copyright (C) 2016-2020 ycmd contributors
#
# This file is part of ycmd.
#
# ycmd 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.
#
# ycmd 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 ycmd. If not, see <http://www.gnu.org/licenses/>.
from hamcrest import ( any_of,
assert_that,
contains_exactly,
has_entries,
has_entry,
instance_of )
from ycmd.tests.typescript import SharedYcmd
from ycmd.tests.test_utils import BuildRequest
@SharedYcmd
def DebugInfo_test( app ):
request_data = BuildRequest( filetype = 'typescript' )
assert_that(
app.post_json( '/debug_info', request_data ).json,
has_entry( 'completer', has_entries( {
'name': 'TypeScript',
'servers': contains_exactly( has_entries( {
'name': 'TSServer',
'is_running': True,
'executable': instance_of( str ),
'pid': instance_of( int ),
'address': None,
'port': None,
'logfiles': contains_exactly( instance_of( str ) ),
'extras': contains_exactly( has_entries( {
'key': 'version',
'value': any_of( None, instance_of( str ) )
} ) )
} ) )
} ) )
)
def Dummy_test():
# Workaround for https://github.com/pytest-dev/pytest-rerunfailures/issues/51
assert True
|
gpl-3.0
|
[
3,
1898,
334,
35,
9,
7800,
13,
13934,
612,
1760,
8417,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
612,
1760,
14,
199,
3,
199,
3,
612,
1760,
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,
612,
1760,
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,
612,
1760,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
24868,
1353,
270,
492,
334,
1263,
63,
1618,
12,
2432,
702,
63,
9099,
12,
2432,
3509,
63,
7327,
590,
12,
2432,
965,
63,
3189,
12,
2432,
965,
63,
2373,
12,
2432,
1256,
63,
1618,
776,
199,
199,
504,
612,
1760,
14,
2219,
14,
466,
1579,
492,
23752,
57,
1760,
199,
504,
612,
1760,
14,
2219,
14,
396,
63,
1208,
492,
6516,
2017,
421,
199,
32,
12197,
57,
1760,
199,
318,
14245,
2354,
63,
396,
8,
1145,
3461,
523,
1056,
63,
576,
275,
6516,
2017,
8,
26245,
275,
283,
466,
1579,
7,
776,
523,
702,
63,
9099,
8,
272,
1145,
14,
1932,
63,
1001,
8,
1994,
1757,
63,
815,
297,
1056,
63,
576,
7092,
1001,
12,
272,
965,
63,
2373,
8,
283,
18452,
297,
965,
63,
3189,
8,
469,
489,
283,
354,
356,
283,
804,
5229,
297,
489,
283,
5871,
356,
3509,
63,
7327,
590,
8,
965,
63,
3189,
8,
469,
267,
283,
354,
356,
283,
9730,
3120,
297,
267,
283,
374,
63,
5720,
356,
715,
12,
267,
283,
5904,
356,
1256,
63,
1618,
8,
620,
2318,
267,
283,
3150,
356,
1256,
63,
1618,
8,
1109,
2318,
267,
283,
1562,
356,
488,
12,
267,
283,
719,
356,
488,
12,
267,
283,
793,
1725,
356,
3509,
63,
7327,
590,
8,
1256,
63,
1618,
8,
620,
776,
2318,
267,
283,
9975,
356,
3509,
63,
7327,
590,
8,
965,
63,
3189,
8,
469,
881,
283,
498,
356,
283,
1023,
297,
881,
283,
585,
356,
1263,
63,
1618,
8,
488,
12,
1256,
63,
1618,
8,
620,
776,
776,
267,
789,
776,
776,
489,
789,
776,
776,
272,
789,
776,
776,
523,
776,
421,
199,
318,
9762,
63,
396,
837,
523,
327,
9361,
11659,
367,
4178,
921,
5031,
14,
957,
15,
4462,
13,
2374,
15,
4462,
13,
264,
1065,
9968,
15,
10115,
15,
2869,
523,
702,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
7800,
13,
13934,
612,
1760,
8417,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
612,
1760,
14,
199,
3,
199,
3,
612,
1760,
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,
612,
1760,
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,
612,
1760,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
24868,
1353,
270,
492,
334,
1263,
63,
1618,
12,
2432,
702,
63,
9099,
12,
2432,
3509,
63,
7327,
590,
12,
2432,
965,
63,
3189,
12,
2432,
965,
63,
2373,
12,
2432,
1256,
63,
1618,
776,
199,
199,
504,
612,
1760,
14,
2219,
14,
466,
1579,
492,
23752,
57,
1760,
199,
504,
612,
1760,
14,
2219,
14,
396,
63,
1208,
492,
6516,
2017,
421,
199,
32,
12197,
57,
1760,
199,
318,
14245,
2354,
63,
396,
8,
1145,
3461,
523,
1056,
63,
576,
275,
6516,
2017,
8,
26245,
275,
283,
466,
1579,
7,
776,
523,
702,
63,
9099,
8,
272,
1145,
14,
1932,
63,
1001,
8,
1994,
1757,
63,
815,
297,
1056,
63,
576,
7092,
1001,
12,
272,
965,
63,
2373,
8,
283,
18452,
297,
965,
63,
3189,
8,
469,
489,
283,
354,
356,
283,
804,
5229,
297,
489,
283,
5871,
356,
3509,
63,
7327,
590,
8,
965,
63,
3189,
8,
469,
267,
283,
354,
356,
283,
9730,
3120,
297,
267,
283,
374,
63,
5720,
356,
715,
12,
267,
283,
5904,
356,
1256,
63,
1618,
8,
620,
2318,
267,
283,
3150,
356,
1256,
63,
1618,
8,
1109,
2318,
267,
283,
1562,
356,
488,
12,
267,
283,
719,
356,
488,
12,
267,
283,
793,
1725,
356,
3509,
63,
7327,
590,
8,
1256,
63,
1618,
8,
620,
776,
2318,
267,
283,
9975,
356,
3509,
63,
7327,
590,
8,
965,
63,
3189,
8,
469,
881,
283,
498,
356,
283,
1023,
297,
881,
283,
585,
356,
1263,
63,
1618,
8,
488,
12,
1256,
63,
1618,
8,
620,
776,
776,
267,
789,
776,
776,
489,
789,
776,
776,
272,
789,
776,
776,
523,
776,
421,
199,
318,
9762,
63,
396,
837,
523,
327,
9361,
11659,
367,
4178,
921,
5031,
14,
957,
15,
4462,
13,
2374,
15,
4462,
13,
264,
1065,
9968,
15,
10115,
15,
2869,
523,
702,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
uskudnik/ggrc-core
|
src/ggrc_basic_permissions/migrations/versions/20131116190735_18bf74925b9_public_programs_are_.py
|
2
|
1885
|
"""Public programs are ownable.
Revision ID: 18bf74925b9
Revises: 4148ce155e54
Create Date: 2013-11-16 19:07:35.284837
"""
# revision identifiers, used by Alembic.
revision = '18bf74925b9'
down_revision = '4148ce155e54'
import json
import sqlalchemy as sa
from alembic import op
from datetime import datetime
from sqlalchemy.sql import table, column
roles_table = table('roles',
column('id', sa.Integer),
column('name', sa.String),
column('permissions_json', sa.Text),
column('description', sa.Text),
column('modified_by_id', sa.Integer),
column('created_at', sa.DateTime),
column('updated_at', sa.DateTime),
column('context_id', sa.Integer),
)
def upgrade():
op.execute(roles_table.update()\
.values(
permissions_json=json.dumps({
"create": ["Program"],
"read": ["Program"],
"update": [
{
"type": "Program",
"terms": {
"list_property": "owners",
"value": "$current_user"
},
"condition": "contains"
},
],
"delete": [
{
"type": "Program",
"terms": {
"list_property": "owners",
"value": "$current_user"
},
"condition": "contains"
},
],
"view_object_page": ["__GGRC_ALL__"],
}))\
.where(roles_table.c.name=='ProgramCreator'))
def downgrade():
op.execute(roles_table.update()\
.values(
permissions_json=json.dumps({
"create": ["Program"],
"view_object_page": ["__GGRC_ALL__"],
}))\
.where(roles_table.c.name=='ProgramCreator'))
|
apache-2.0
|
[
199,
624,
9885,
18572,
787,
5705,
461,
14,
199,
199,
12714,
2870,
26,
6155,
4361,
15971,
821,
66,
25,
199,
497,
433,
874,
26,
841,
10834,
301,
11520,
69,
1477,
199,
2499,
6148,
26,
6171,
13,
845,
13,
975,
5851,
26,
1780,
26,
1276,
14,
10681,
24,
1401,
199,
199,
624,
199,
199,
3,
6974,
14154,
12,
1202,
701,
6832,
20596,
14,
199,
5792,
275,
283,
1085,
4361,
15971,
821,
66,
25,
7,
199,
2110,
63,
5792,
275,
283,
20,
10834,
301,
11520,
69,
1477,
7,
199,
199,
646,
2022,
199,
646,
8335,
465,
2937,
199,
504,
30960,
20596,
492,
1687,
199,
504,
2197,
492,
2197,
199,
504,
8335,
14,
3009,
492,
1817,
12,
2763,
199,
199,
8050,
63,
1224,
275,
1817,
360,
8050,
297,
272,
2763,
360,
344,
297,
2937,
14,
2674,
395,
272,
2763,
360,
354,
297,
2937,
14,
1558,
395,
272,
2763,
360,
6060,
63,
1001,
297,
2937,
14,
1872,
395,
272,
2763,
360,
1802,
297,
2937,
14,
1872,
395,
272,
2763,
360,
5540,
63,
991,
63,
344,
297,
2937,
14,
2674,
395,
272,
2763,
360,
3966,
63,
292,
297,
2937,
14,
3926,
395,
272,
2763,
360,
5334,
63,
292,
297,
2937,
14,
3926,
395,
272,
2763,
360,
1100,
63,
344,
297,
2937,
14,
2674,
395,
272,
776,
199,
199,
318,
10754,
837,
272,
1687,
14,
2526,
8,
8050,
63,
1224,
14,
873,
17158,
267,
1275,
1459,
8,
881,
3443,
63,
1001,
29,
1001,
14,
4180,
2561,
288,
298,
981,
582,
2097,
9184,
2255,
288,
298,
739,
582,
2097,
9184,
2255,
288,
298,
873,
582,
359,
355,
469,
490,
298,
466,
582,
298,
9184,
401,
490,
298,
9187,
582,
469,
717,
298,
513,
63,
1829,
582,
298,
27169,
401,
717,
298,
585,
582,
7880,
1818,
63,
751,
2,
490,
1660,
490,
298,
5394,
582,
298,
6134,
2,
355,
1660,
1598,
2156,
288,
298,
1807,
582,
359,
355,
469,
490,
298,
466,
582,
298,
9184,
401,
490,
298,
9187,
582,
469,
717,
298,
513,
63,
1829,
582,
298,
27169,
401,
717,
298,
585,
582,
7880,
1818,
63,
751,
2,
490,
1660,
490,
298,
5394,
582,
298,
6134,
2,
355,
1660,
1598,
2156,
288,
298,
1345,
63,
785,
63,
1606,
582,
2097,
363,
2916,
8205,
63,
1761,
363,
2255,
288,
23451,
60,
267,
1275,
4509,
8,
8050,
63,
1224,
14,
67,
14,
354,
6803,
9184,
17523,
1333,
199,
199,
318,
32498,
837,
272,
1687,
14,
2526,
8,
8050,
63,
1224,
14,
873,
17158,
267,
1275,
1459,
8,
881,
3443,
63,
1001,
29,
1001,
14,
4180,
2561,
288,
298,
981,
582,
2097,
9184,
2255,
288,
298,
1345,
63,
785,
63,
1606,
582,
2097,
363,
2916,
8205,
63,
1761,
363,
2255,
288,
23451,
60,
267,
1275,
4509,
8,
8050,
63,
1224,
14,
67,
14,
354,
6803,
9184,
17523,
1333,
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
] |
[
624,
9885,
18572,
787,
5705,
461,
14,
199,
199,
12714,
2870,
26,
6155,
4361,
15971,
821,
66,
25,
199,
497,
433,
874,
26,
841,
10834,
301,
11520,
69,
1477,
199,
2499,
6148,
26,
6171,
13,
845,
13,
975,
5851,
26,
1780,
26,
1276,
14,
10681,
24,
1401,
199,
199,
624,
199,
199,
3,
6974,
14154,
12,
1202,
701,
6832,
20596,
14,
199,
5792,
275,
283,
1085,
4361,
15971,
821,
66,
25,
7,
199,
2110,
63,
5792,
275,
283,
20,
10834,
301,
11520,
69,
1477,
7,
199,
199,
646,
2022,
199,
646,
8335,
465,
2937,
199,
504,
30960,
20596,
492,
1687,
199,
504,
2197,
492,
2197,
199,
504,
8335,
14,
3009,
492,
1817,
12,
2763,
199,
199,
8050,
63,
1224,
275,
1817,
360,
8050,
297,
272,
2763,
360,
344,
297,
2937,
14,
2674,
395,
272,
2763,
360,
354,
297,
2937,
14,
1558,
395,
272,
2763,
360,
6060,
63,
1001,
297,
2937,
14,
1872,
395,
272,
2763,
360,
1802,
297,
2937,
14,
1872,
395,
272,
2763,
360,
5540,
63,
991,
63,
344,
297,
2937,
14,
2674,
395,
272,
2763,
360,
3966,
63,
292,
297,
2937,
14,
3926,
395,
272,
2763,
360,
5334,
63,
292,
297,
2937,
14,
3926,
395,
272,
2763,
360,
1100,
63,
344,
297,
2937,
14,
2674,
395,
272,
776,
199,
199,
318,
10754,
837,
272,
1687,
14,
2526,
8,
8050,
63,
1224,
14,
873,
17158,
267,
1275,
1459,
8,
881,
3443,
63,
1001,
29,
1001,
14,
4180,
2561,
288,
298,
981,
582,
2097,
9184,
2255,
288,
298,
739,
582,
2097,
9184,
2255,
288,
298,
873,
582,
359,
355,
469,
490,
298,
466,
582,
298,
9184,
401,
490,
298,
9187,
582,
469,
717,
298,
513,
63,
1829,
582,
298,
27169,
401,
717,
298,
585,
582,
7880,
1818,
63,
751,
2,
490,
1660,
490,
298,
5394,
582,
298,
6134,
2,
355,
1660,
1598,
2156,
288,
298,
1807,
582,
359,
355,
469,
490,
298,
466,
582,
298,
9184,
401,
490,
298,
9187,
582,
469,
717,
298,
513,
63,
1829,
582,
298,
27169,
401,
717,
298,
585,
582,
7880,
1818,
63,
751,
2,
490,
1660,
490,
298,
5394,
582,
298,
6134,
2,
355,
1660,
1598,
2156,
288,
298,
1345,
63,
785,
63,
1606,
582,
2097,
363,
2916,
8205,
63,
1761,
363,
2255,
288,
23451,
60,
267,
1275,
4509,
8,
8050,
63,
1224,
14,
67,
14,
354,
6803,
9184,
17523,
1333,
199,
199,
318,
32498,
837,
272,
1687,
14,
2526,
8,
8050,
63,
1224,
14,
873,
17158,
267,
1275,
1459,
8,
881,
3443,
63,
1001,
29,
1001,
14,
4180,
2561,
288,
298,
981,
582,
2097,
9184,
2255,
288,
298,
1345,
63,
785,
63,
1606,
582,
2097,
363,
2916,
8205,
63,
1761,
363,
2255,
288,
23451,
60,
267,
1275,
4509,
8,
8050,
63,
1224,
14,
67,
14,
354,
6803,
9184,
17523,
1333,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
SrNetoChan/QGIS
|
tests/src/python/test_qgslocaldefaultsettings.py
|
36
|
2306
|
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLocalDefaultSettings.
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = 'Nyall Dawson'
__date__ = '09/01/2020'
__copyright__ = 'Copyright 2020, The QGIS Project'
import qgis # NOQA
from qgis.core import (QgsSettings,
QgsLocalDefaultSettings,
QgsBearingNumericFormat)
from qgis.PyQt.QtCore import QCoreApplication
from qgis.testing import start_app, unittest
from utilities import (unitTestDataPath)
TEST_DATA_DIR = unitTestDataPath()
class TestQgsLocalDefaultSettings(unittest.TestCase):
@classmethod
def setUpClass(cls):
"""Run before all tests"""
QCoreApplication.setOrganizationName("QGIS_Test")
QCoreApplication.setOrganizationDomain("TestPyQgsWFSProvider.com")
QCoreApplication.setApplicationName("TestPyQgsWFSProvider")
QgsSettings().clear()
start_app()
def testBearingFormat(self):
s = QgsLocalDefaultSettings()
format = QgsBearingNumericFormat()
format.setNumberDecimalPlaces(9)
format.setDirectionFormat(QgsBearingNumericFormat.UseRange0To360)
s.setBearingFormat(format)
self.assertEqual(s.bearingFormat().numberDecimalPlaces(), 9)
self.assertEqual(s.bearingFormat().directionFormat(), QgsBearingNumericFormat.UseRange0To360)
format = QgsBearingNumericFormat()
format.setNumberDecimalPlaces(3)
format.setDirectionFormat(QgsBearingNumericFormat.UseRangeNegative180ToPositive180)
s.setBearingFormat(format)
self.assertEqual(s.bearingFormat().numberDecimalPlaces(), 3)
self.assertEqual(s.bearingFormat().directionFormat(), QgsBearingNumericFormat.UseRangeNegative180ToPositive180)
# new settings object, should persist.
s2 = QgsLocalDefaultSettings()
self.assertEqual(s2.bearingFormat().numberDecimalPlaces(), 3)
self.assertEqual(s2.bearingFormat().directionFormat(), QgsBearingNumericFormat.UseRangeNegative180ToPositive180)
if __name__ == '__main__':
unittest.main()
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
31329,
12008,
2295,
367,
4888,
5339,
2698,
5268,
14,
199,
199,
703,
5317,
447,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
624,
199,
363,
2502,
363,
275,
283,
22781,
452,
577,
10084,
834,
7,
199,
363,
602,
363,
275,
283,
1643,
15,
614,
15,
13934,
7,
199,
363,
7307,
363,
275,
283,
7384,
25455,
12,
710,
27024,
7290,
7,
199,
199,
646,
15640,
221,
327,
20432,
199,
199,
504,
15640,
14,
1018,
492,
334,
7350,
5268,
12,
2432,
4888,
5339,
2698,
5268,
12,
2432,
4888,
30860,
316,
14687,
3484,
9,
199,
199,
504,
15640,
14,
24107,
14,
10901,
492,
1413,
29263,
199,
199,
504,
15640,
14,
4776,
492,
1343,
63,
571,
12,
2882,
199,
504,
15841,
492,
334,
3248,
16550,
2042,
9,
199,
199,
2864,
63,
3998,
63,
3022,
275,
4137,
16550,
2042,
342,
421,
199,
533,
1379,
7350,
5339,
2698,
5268,
8,
2796,
14,
1746,
304,
339,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
408,
2540,
2544,
1006,
2295,
624,
398,
1413,
29263,
14,
409,
15928,
985,
480,
31329,
63,
774,
531,
267,
1413,
29263,
14,
409,
15928,
7705,
480,
774,
2713,
7350,
55,
7079,
6663,
14,
957,
531,
267,
1413,
29263,
14,
409,
5039,
985,
480,
774,
2713,
7350,
55,
7079,
6663,
531,
267,
4888,
5268,
1252,
3584,
342,
267,
1343,
63,
571,
342,
339,
347,
511,
30860,
316,
3484,
8,
277,
304,
267,
308,
275,
4888,
5339,
2698,
5268,
342,
398,
1475,
275,
4888,
30860,
316,
14687,
3484,
342,
267,
1475,
14,
409,
3259,
6745,
48,
5862,
8,
25,
9,
267,
1475,
14,
409,
17015,
3484,
8,
7350,
30860,
316,
14687,
3484,
14,
6119,
4709,
16,
1378,
11197,
9,
398,
308,
14,
409,
30860,
316,
3484,
8,
908,
9,
267,
291,
14,
629,
8,
83,
14,
1235,
9332,
3484,
1252,
1955,
6745,
48,
5862,
1062,
1749,
9,
267,
291,
14,
629,
8,
83,
14,
1235,
9332,
3484,
1252,
6874,
3484,
1062,
4888,
30860,
316,
14687,
3484,
14,
6119,
4709,
16,
1378,
11197,
9,
398,
1475,
275,
4888,
30860,
316,
14687,
3484,
342,
267,
1475,
14,
409,
3259,
6745,
48,
5862,
8,
19,
9,
267,
1475,
14,
409,
17015,
3484,
8,
7350,
30860,
316,
14687,
3484,
14,
6119,
4709,
15562,
7663,
1378,
6951,
7663,
9,
267,
308,
14,
409,
30860,
316,
3484,
8,
908,
9,
267,
291,
14,
629,
8,
83,
14,
1235,
9332,
3484,
1252,
1955,
6745,
48,
5862,
1062,
650,
9,
267,
291,
14,
629,
8,
83,
14,
1235,
9332,
3484,
1252,
6874,
3484,
1062,
4888,
30860,
316,
14687,
3484,
14,
6119,
4709,
15562,
7663,
1378,
6951,
7663,
9,
398,
327,
892,
2202,
909,
12,
1077,
22400,
14,
267,
308,
18,
275,
4888,
5339,
2698,
5268,
342,
267,
291,
14,
629,
8,
83,
18,
14,
1235,
9332,
3484,
1252,
1955,
6745,
48,
5862,
1062,
650,
9,
267,
291,
14,
629,
8,
83,
18,
14,
1235,
9332,
3484,
1252,
6874,
3484,
1062,
4888,
30860,
316,
14687,
3484,
14,
6119,
4709,
15562,
7663,
1378,
6951,
7663,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
31329,
12008,
2295,
367,
4888,
5339,
2698,
5268,
14,
199,
199,
703,
5317,
447,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
624,
199,
363,
2502,
363,
275,
283,
22781,
452,
577,
10084,
834,
7,
199,
363,
602,
363,
275,
283,
1643,
15,
614,
15,
13934,
7,
199,
363,
7307,
363,
275,
283,
7384,
25455,
12,
710,
27024,
7290,
7,
199,
199,
646,
15640,
221,
327,
20432,
199,
199,
504,
15640,
14,
1018,
492,
334,
7350,
5268,
12,
2432,
4888,
5339,
2698,
5268,
12,
2432,
4888,
30860,
316,
14687,
3484,
9,
199,
199,
504,
15640,
14,
24107,
14,
10901,
492,
1413,
29263,
199,
199,
504,
15640,
14,
4776,
492,
1343,
63,
571,
12,
2882,
199,
504,
15841,
492,
334,
3248,
16550,
2042,
9,
199,
199,
2864,
63,
3998,
63,
3022,
275,
4137,
16550,
2042,
342,
421,
199,
533,
1379,
7350,
5339,
2698,
5268,
8,
2796,
14,
1746,
304,
339,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
408,
2540,
2544,
1006,
2295,
624,
398,
1413,
29263,
14,
409,
15928,
985,
480,
31329,
63,
774,
531,
267,
1413,
29263,
14,
409,
15928,
7705,
480,
774,
2713,
7350,
55,
7079,
6663,
14,
957,
531,
267,
1413,
29263,
14,
409,
5039,
985,
480,
774,
2713,
7350,
55,
7079,
6663,
531,
267,
4888,
5268,
1252,
3584,
342,
267,
1343,
63,
571,
342,
339,
347,
511,
30860,
316,
3484,
8,
277,
304,
267,
308,
275,
4888,
5339,
2698,
5268,
342,
398,
1475,
275,
4888,
30860,
316,
14687,
3484,
342,
267,
1475,
14,
409,
3259,
6745,
48,
5862,
8,
25,
9,
267,
1475,
14,
409,
17015,
3484,
8,
7350,
30860,
316,
14687,
3484,
14,
6119,
4709,
16,
1378,
11197,
9,
398,
308,
14,
409,
30860,
316,
3484,
8,
908,
9,
267,
291,
14,
629,
8,
83,
14,
1235,
9332,
3484,
1252,
1955,
6745,
48,
5862,
1062,
1749,
9,
267,
291,
14,
629,
8,
83,
14,
1235,
9332,
3484,
1252,
6874,
3484,
1062,
4888,
30860,
316,
14687,
3484,
14,
6119,
4709,
16,
1378,
11197,
9,
398,
1475,
275,
4888,
30860,
316,
14687,
3484,
342,
267,
1475,
14,
409,
3259,
6745,
48,
5862,
8,
19,
9,
267,
1475,
14,
409,
17015,
3484,
8,
7350,
30860,
316,
14687,
3484,
14,
6119,
4709,
15562,
7663,
1378,
6951,
7663,
9,
267,
308,
14,
409,
30860,
316,
3484,
8,
908,
9,
267,
291,
14,
629,
8,
83,
14,
1235,
9332,
3484,
1252,
1955,
6745,
48,
5862,
1062,
650,
9,
267,
291,
14,
629,
8,
83,
14,
1235,
9332,
3484,
1252,
6874,
3484,
1062,
4888,
30860,
316,
14687,
3484,
14,
6119,
4709,
15562,
7663,
1378,
6951,
7663,
9,
398,
327,
892,
2202,
909,
12,
1077,
22400,
14,
267,
308,
18,
275,
4888,
5339,
2698,
5268,
342,
267,
291,
14,
629,
8,
83,
18,
14,
1235,
9332,
3484,
1252,
1955,
6745,
48,
5862,
1062,
650,
9,
267,
291,
14,
629,
8,
83,
18,
14,
1235,
9332,
3484,
1252,
6874,
3484,
1062,
4888,
30860,
316,
14687,
3484,
14,
6119,
4709,
15562,
7663,
1378,
6951,
7663,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mindriot101/bokeh
|
tests/integration/tools/test_poly_draw_tool.py
|
5
|
9020
|
#-----------------------------------------------------------------------------
# Copyright (c) 2012 - 2017, Anaconda, Inc. All rights reserved.
#
# Powered by the Bokeh Development Team.
#
# The full license is in the file LICENSE.txt, distributed with this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Boilerplate
#-----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function, unicode_literals
import pytest ; pytest
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
# Standard library imports
import time
# External imports
# Bokeh imports
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, CustomAction, CustomJS, Plot, Range1d, MultiLine, Circle, PolyDrawTool, Div
from bokeh._testing.util.compare import cds_data_almost_equal
from bokeh._testing.util.selenium import RECORD
#-----------------------------------------------------------------------------
# Tests
#-----------------------------------------------------------------------------
pytest_plugins = (
"bokeh._testing.plugins.bokeh",
)
def _make_plot(num_objects=0, drag=True, vertices=False):
source = ColumnDataSource(dict(xs=[[1, 2]], ys=[[1, 1]]))
plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 3), y_range=Range1d(0, 3), min_border=0)
renderer = plot.add_glyph(source, MultiLine(xs='xs', ys='ys'))
tool = PolyDrawTool(num_objects=num_objects, drag=drag, renderers=[renderer])
if vertices:
psource = ColumnDataSource(dict(x=[], y=[]))
prenderer = plot.add_glyph(psource, Circle(x='x', y='y', size=10))
tool.vertex_renderer = prenderer
plot.add_tools(tool)
plot.toolbar.active_multi = tool
code = RECORD("xs", "source.data.xs") + RECORD("ys", "source.data.ys")
plot.add_tools(CustomAction(callback=CustomJS(args=dict(source=source), code=code)))
plot.toolbar_sticky = False
return plot
def _make_server_plot(expected):
def modify_doc(doc):
source = ColumnDataSource(dict(xs=[[1, 2]], ys=[[1, 1]]))
plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 3), y_range=Range1d(0, 3), min_border=0)
renderer = plot.add_glyph(source, MultiLine(xs='xs', ys='ys'))
tool = PolyDrawTool(renderers=[renderer])
plot.add_tools(tool)
plot.toolbar.active_multi = tool
div = Div(text='False')
def cb(attr, old, new):
if cds_data_almost_equal(new, expected):
div.text = 'True'
source.on_change('data', cb)
code = RECORD("matches", "div.text")
plot.add_tools(CustomAction(callback=CustomJS(args=dict(div=div), code=code)))
doc.add_root(column(plot, div))
return modify_doc
@pytest.mark.integration
@pytest.mark.selenium
class Test_PolyDrawTool(object):
def test_selected_by_default(self, single_plot_page):
plot = _make_plot()
page = single_plot_page(plot)
button = page.get_toolbar_button('poly-draw')
assert 'active' in button.get_attribute('class')
assert page.has_no_console_errors()
def test_can_be_deselected_and_selected(self, single_plot_page):
plot = _make_plot()
page = single_plot_page(plot)
# Check is active
button = page.get_toolbar_button('poly-draw')
assert 'active' in button.get_attribute('class')
# Click and check is not active
button = page.get_toolbar_button('poly-draw')
button.click()
assert 'active' not in button.get_attribute('class')
# Click again and check is active
button = page.get_toolbar_button('poly-draw')
button.click()
assert 'active' in button.get_attribute('class')
assert page.has_no_console_errors()
def test_double_click_triggers_draw(self, single_plot_page):
plot = _make_plot()
page = single_plot_page(plot)
# ensure double clicking adds a poly
page.double_click_canvas_at_position(200, 200)
page.double_click_canvas_at_position(300, 300)
time.sleep(0.5)
page.click_custom_action()
expected = {"xs": [[1, 2], [1.6216216216216217, 2.4324324324324325]],
"ys": [[1, 1], [1.5, 0.75]]}
assert cds_data_almost_equal(page.results, expected)
assert page.has_no_console_errors()
def test_click_snaps_to_vertex(self, single_plot_page):
plot = _make_plot(vertices=True)
page = single_plot_page(plot)
# ensure double clicking adds a poly
page.double_click_canvas_at_position(200, 200)
page.click_canvas_at_position(300, 300)
time.sleep(0.5)
page.double_click_canvas_at_position(201, 201)
time.sleep(0.5)
page.click_custom_action()
expected = {"xs": [[1, 2], [1.6216216216216217, 2.4324324324324325, 1.6216216216216217]],
"ys": [[1, 1], [1.5, 0.75, 1.5]]}
assert cds_data_almost_equal(page.results, expected)
assert page.has_no_console_errors()
def test_drag_moves_multi_line(self, single_plot_page):
plot = _make_plot()
page = single_plot_page(plot)
# ensure clicking adds a point
page.double_click_canvas_at_position(200, 200)
page.double_click_canvas_at_position(300, 300)
time.sleep(0.4) # hammerJS click timeout
page.drag_canvas_at_position(200, 200, 70, 50)
page.click_custom_action()
expected = {"xs": [[1, 2], [2.1891891891891895, 3]],
"ys": [[1, 1], [1.125, 0.375]]}
assert cds_data_almost_equal(page.results, expected)
assert page.has_no_console_errors()
def test_drag_does_not_move_multi_line(self, single_plot_page):
plot = _make_plot(drag=False)
page = single_plot_page(plot)
# ensure clicking adds a point
page.double_click_canvas_at_position(200, 200)
page.double_click_canvas_at_position(300, 300)
time.sleep(0.4) # hammerJS click timeout
page.drag_canvas_at_position(200, 200, 70, 53)
page.click_custom_action()
expected = {"xs": [[1, 2], [1.6216216216216217, 2.4324324324324325]],
"ys": [[1, 1], [1.5, 0.75]] }
assert cds_data_almost_equal(page.results, expected)
assert page.has_no_console_errors()
def test_num_object_limits_multi_lines(self, single_plot_page):
plot = _make_plot(num_objects=1)
page = single_plot_page(plot)
# ensure clicking adds a point
page.double_click_canvas_at_position(200, 200)
page.double_click_canvas_at_position(300, 300)
time.sleep(0.4) # hammerJS click timeout
page.drag_canvas_at_position(200, 200, 70, 50)
page.click_custom_action()
expected = {"xs": [[2.1891891891891895, 3]],
"ys": [[1.125, 0.375]]}
assert cds_data_almost_equal(page.results, expected)
assert page.has_no_console_errors()
def test_poly_draw_syncs_to_server(self, bokeh_server_page):
expected = {"xs": [[1, 2], [1.6216216216216217, 2.4324324324324325]],
"ys": [[1, 1], [1.5, 0.75]]}
page = bokeh_server_page(_make_server_plot(expected))
# ensure double clicking adds a poly
page.double_click_canvas_at_position(200, 200)
page.double_click_canvas_at_position(300, 300)
time.sleep(0.5)
page.click_custom_action()
assert page.results == {"matches": "True"}
def test_poly_drag_syncs_to_server(self, bokeh_server_page):
expected = {"xs": [[1, 2], [2.1891891891891895, 3]],
"ys": [[1, 1], [1.125, 0.375]]}
page = bokeh_server_page(_make_server_plot(expected))
# ensure dragging move multi_line
page.double_click_canvas_at_position(200, 200)
page.double_click_canvas_at_position(300, 300)
time.sleep(0.4) # hammerJS click timeout
page.drag_canvas_at_position(200, 200, 70, 50)
page.click_custom_action()
assert page.results == {"matches": "True"}
def test_poly_delete_syncs_to_server(self, bokeh_server_page):
expected = {"xs": [[1, 2]],
"ys": [[1, 1]]}
page = bokeh_server_page(_make_server_plot(expected))
page.double_click_canvas_at_position(200, 200)
page.double_click_canvas_at_position(300, 300)
time.sleep(0.4) # hammerJS click timeout
page.click_canvas_at_position(200, 200)
time.sleep(0.4) # hammerJS click timeout
page.send_keys(u'\ue003') # Backspace
time.sleep(0.4) # hammerJS click timeout
page.click_custom_action()
assert page.results == {"matches": "True"}
|
bsd-3-clause
|
[
18045,
199,
3,
1898,
334,
67,
9,
6029,
446,
9708,
12,
1626,
16928,
983,
12,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
510,
583,
16179,
701,
314,
5088,
16610,
15290,
11682,
14,
199,
3,
199,
3,
710,
2615,
4190,
365,
315,
314,
570,
5113,
14,
2424,
12,
1854,
543,
642,
2032,
14,
199,
18045,
199,
199,
18045,
199,
3,
5088,
27025,
199,
18045,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
646,
4613,
8700,
4613,
199,
199,
18045,
199,
3,
24339,
199,
18045,
199,
199,
3,
9739,
3555,
8925,
199,
646,
900,
199,
199,
3,
18802,
8925,
199,
199,
3,
5088,
16610,
8925,
199,
504,
25214,
14,
4209,
83,
492,
2763,
199,
504,
25214,
14,
992,
492,
4996,
16693,
12,
8388,
3310,
12,
8388,
11378,
12,
14794,
12,
13114,
17,
68,
12,
6879,
3049,
12,
445,
12571,
12,
16869,
9654,
5157,
12,
32077,
199,
504,
25214,
423,
4776,
14,
1974,
14,
5785,
492,
286,
795,
63,
576,
63,
4398,
63,
1452,
199,
504,
25214,
423,
4776,
14,
1974,
14,
15041,
492,
24973,
199,
199,
18045,
199,
3,
6496,
199,
18045,
199,
199,
4462,
63,
5265,
275,
334,
272,
298,
656,
16610,
423,
4776,
14,
5265,
14,
656,
16610,
401,
199,
9,
199,
199,
318,
485,
1875,
63,
2798,
8,
1507,
63,
1462,
29,
16,
12,
18981,
29,
549,
12,
14971,
29,
797,
304,
272,
1350,
275,
4996,
16693,
8,
807,
8,
7977,
16025,
17,
12,
499,
2365,
19205,
16025,
17,
12,
413,
17723,
272,
5137,
275,
14794,
8,
2798,
63,
3333,
29,
5303,
12,
5137,
63,
2063,
29,
5303,
12,
671,
63,
1842,
29,
4709,
17,
68,
8,
16,
12,
650,
395,
612,
63,
1842,
29,
4709,
17,
68,
8,
16,
12,
650,
395,
1748,
63,
8665,
29,
16,
9,
272,
11889,
275,
5137,
14,
525,
63,
13723,
8,
1365,
12,
6879,
3049,
8,
7977,
534,
7977,
297,
19205,
534,
588,
1333,
272,
4744,
275,
16869,
9654,
5157,
8,
1507,
63,
1462,
29,
1507,
63,
1462,
12,
18981,
29,
14479,
12,
2903,
26529,
1524,
12471,
566,
272,
340,
14971,
26,
267,
299,
1365,
275,
4996,
16693,
8,
807,
8,
88,
6034,
612,
1524,
2459,
267,
299,
12471,
275,
5137,
14,
525,
63,
13723,
8,
1190,
616,
12,
445,
12571,
8,
88,
534,
88,
297,
612,
534,
89,
297,
1568,
29,
709,
430,
267,
4744,
14,
11417,
63,
12471,
275,
299,
12471,
272,
5137,
14,
525,
63,
2537,
8,
3557,
9,
272,
5137,
14,
13951,
14,
2682,
63,
3029,
275,
4744,
272,
1233,
275,
24973,
480,
7977,
401,
298,
1365,
14,
576,
14,
7977,
531,
435,
24973,
480,
588,
401,
298,
1365,
14,
576,
14,
588,
531,
272,
5137,
14,
525,
63,
2537,
8,
7223,
3310,
8,
3058,
29,
7223,
11378,
8,
589,
29,
807,
8,
1365,
29,
1365,
395,
1233,
29,
600,
1724,
272,
5137,
14,
13951,
63,
27364,
275,
756,
272,
372,
5137,
199,
199,
318,
485,
1875,
63,
1000,
63,
2798,
8,
2062,
304,
272,
347,
2811,
63,
1301,
8,
1301,
304,
267,
1350,
275,
4996,
16693,
8,
807,
8,
7977,
16025,
17,
12,
499,
2365,
19205,
16025,
17,
12,
413,
17723,
267,
5137,
275,
14794,
8,
2798,
63,
3333,
29,
5303,
12,
5137,
63,
2063,
29,
5303,
12,
671,
63,
1842,
29,
4709,
17,
68,
8,
16,
12,
650,
395,
612,
63,
1842,
29,
4709,
17,
68,
8,
16,
12,
650,
395,
1748,
63,
8665,
29,
16,
9,
267,
11889,
275,
5137,
14,
525,
63,
13723,
8,
1365,
12,
6879,
3049,
8,
7977,
534,
7977,
297,
19205,
534,
588,
1333,
267,
4744,
275,
16869,
9654,
5157,
8,
828,
26529,
1524,
12471,
566,
267,
5137,
14,
525,
63,
2537,
8,
3557,
9,
267,
5137,
14,
13951,
14,
2682,
63,
3029,
275,
4744,
267,
9073,
275,
32077,
8,
505,
534,
797,
358,
267,
347,
7434,
8,
962,
12,
2269,
12,
892,
304,
288,
340,
286,
795,
63,
576,
63,
4398,
63,
1452,
8,
1222,
12,
1420,
304,
355,
9073,
14,
505,
275,
283,
549,
7,
267,
1350,
14,
265,
63,
1461,
360,
576,
297,
7434,
9,
267,
1233,
275,
24973,
480,
6742,
401,
298,
3015,
14,
505,
531,
267,
5137,
14,
525,
63,
2537,
8,
7223,
3310,
8,
3058,
29,
7223,
11378,
8,
589,
29,
807,
8,
3015,
29,
3015,
395,
1233,
29,
600,
1724,
267,
1382,
14,
525,
63,
1231,
8,
2301,
8,
2798,
12,
9073,
430,
272,
372,
2811,
63,
1301,
421,
199,
32,
4462,
14,
1657,
14,
15092,
199,
32,
4462,
14,
1657,
14,
15041,
199,
533,
1379,
63,
12747,
9654,
5157,
8,
785,
304,
339,
347,
511,
63,
5511,
63,
991,
63,
885,
8,
277,
12,
2849,
63,
2798,
63,
1606,
304,
267,
5137,
275,
485,
1875,
63,
2798,
342,
398,
2034,
275,
2849,
63,
2798,
63,
1606,
8,
2798,
9,
398,
5528,
275,
2034,
14,
362,
63,
13951,
63,
3887,
360,
6023,
13,
5485,
358,
267,
702,
283,
2682,
7,
315,
5528,
14,
362,
63,
3215,
360,
533,
358,
398,
702,
2034,
14,
1989,
63,
889,
63,
6614,
63,
2550,
342,
339,
347,
511,
63,
2425,
63,
1235,
63,
271,
5511,
63,
460,
63,
5511,
8,
277,
12,
2849,
63,
2798,
63,
1606,
304,
267,
5137,
275,
485,
1875,
63,
2798,
342,
398,
2034,
275,
2849,
63,
2798,
63,
1606,
8,
2798,
9,
398,
327,
2670,
365,
4702,
267,
5528,
275,
2034,
14,
362,
63,
13951,
63,
3887,
360,
6023,
13,
5485,
358,
267,
702,
283,
2682,
7,
315,
5528,
14,
362,
63,
3215,
360,
533,
358,
398,
327,
26147,
436,
1104,
365,
440,
4702,
267,
5528,
275,
2034,
14,
362,
63,
13951,
63,
3887,
360,
6023,
13,
5485,
358,
267,
5528,
14,
4891,
342,
267,
702,
283,
2682,
7,
440,
315,
5528,
14,
362,
63,
3215,
360,
533,
358,
398,
327,
26147,
4020,
436,
1104,
365,
4702,
267,
5528,
275,
2034,
14,
362,
63,
13951,
63,
3887,
360,
6023,
13,
5485,
358,
267,
5528,
14,
4891,
342,
267,
702,
283,
2682,
7,
315,
5528,
14,
362,
63,
3215,
360,
533,
358,
398,
702,
2034,
14,
1989,
63,
889,
63,
6614,
63,
2550,
342,
339,
347,
511,
63,
3157,
63,
4891,
63
] |
[
199,
3,
1898,
334,
67,
9,
6029,
446,
9708,
12,
1626,
16928,
983,
12,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
510,
583,
16179,
701,
314,
5088,
16610,
15290,
11682,
14,
199,
3,
199,
3,
710,
2615,
4190,
365,
315,
314,
570,
5113,
14,
2424,
12,
1854,
543,
642,
2032,
14,
199,
18045,
199,
199,
18045,
199,
3,
5088,
27025,
199,
18045,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
646,
4613,
8700,
4613,
199,
199,
18045,
199,
3,
24339,
199,
18045,
199,
199,
3,
9739,
3555,
8925,
199,
646,
900,
199,
199,
3,
18802,
8925,
199,
199,
3,
5088,
16610,
8925,
199,
504,
25214,
14,
4209,
83,
492,
2763,
199,
504,
25214,
14,
992,
492,
4996,
16693,
12,
8388,
3310,
12,
8388,
11378,
12,
14794,
12,
13114,
17,
68,
12,
6879,
3049,
12,
445,
12571,
12,
16869,
9654,
5157,
12,
32077,
199,
504,
25214,
423,
4776,
14,
1974,
14,
5785,
492,
286,
795,
63,
576,
63,
4398,
63,
1452,
199,
504,
25214,
423,
4776,
14,
1974,
14,
15041,
492,
24973,
199,
199,
18045,
199,
3,
6496,
199,
18045,
199,
199,
4462,
63,
5265,
275,
334,
272,
298,
656,
16610,
423,
4776,
14,
5265,
14,
656,
16610,
401,
199,
9,
199,
199,
318,
485,
1875,
63,
2798,
8,
1507,
63,
1462,
29,
16,
12,
18981,
29,
549,
12,
14971,
29,
797,
304,
272,
1350,
275,
4996,
16693,
8,
807,
8,
7977,
16025,
17,
12,
499,
2365,
19205,
16025,
17,
12,
413,
17723,
272,
5137,
275,
14794,
8,
2798,
63,
3333,
29,
5303,
12,
5137,
63,
2063,
29,
5303,
12,
671,
63,
1842,
29,
4709,
17,
68,
8,
16,
12,
650,
395,
612,
63,
1842,
29,
4709,
17,
68,
8,
16,
12,
650,
395,
1748,
63,
8665,
29,
16,
9,
272,
11889,
275,
5137,
14,
525,
63,
13723,
8,
1365,
12,
6879,
3049,
8,
7977,
534,
7977,
297,
19205,
534,
588,
1333,
272,
4744,
275,
16869,
9654,
5157,
8,
1507,
63,
1462,
29,
1507,
63,
1462,
12,
18981,
29,
14479,
12,
2903,
26529,
1524,
12471,
566,
272,
340,
14971,
26,
267,
299,
1365,
275,
4996,
16693,
8,
807,
8,
88,
6034,
612,
1524,
2459,
267,
299,
12471,
275,
5137,
14,
525,
63,
13723,
8,
1190,
616,
12,
445,
12571,
8,
88,
534,
88,
297,
612,
534,
89,
297,
1568,
29,
709,
430,
267,
4744,
14,
11417,
63,
12471,
275,
299,
12471,
272,
5137,
14,
525,
63,
2537,
8,
3557,
9,
272,
5137,
14,
13951,
14,
2682,
63,
3029,
275,
4744,
272,
1233,
275,
24973,
480,
7977,
401,
298,
1365,
14,
576,
14,
7977,
531,
435,
24973,
480,
588,
401,
298,
1365,
14,
576,
14,
588,
531,
272,
5137,
14,
525,
63,
2537,
8,
7223,
3310,
8,
3058,
29,
7223,
11378,
8,
589,
29,
807,
8,
1365,
29,
1365,
395,
1233,
29,
600,
1724,
272,
5137,
14,
13951,
63,
27364,
275,
756,
272,
372,
5137,
199,
199,
318,
485,
1875,
63,
1000,
63,
2798,
8,
2062,
304,
272,
347,
2811,
63,
1301,
8,
1301,
304,
267,
1350,
275,
4996,
16693,
8,
807,
8,
7977,
16025,
17,
12,
499,
2365,
19205,
16025,
17,
12,
413,
17723,
267,
5137,
275,
14794,
8,
2798,
63,
3333,
29,
5303,
12,
5137,
63,
2063,
29,
5303,
12,
671,
63,
1842,
29,
4709,
17,
68,
8,
16,
12,
650,
395,
612,
63,
1842,
29,
4709,
17,
68,
8,
16,
12,
650,
395,
1748,
63,
8665,
29,
16,
9,
267,
11889,
275,
5137,
14,
525,
63,
13723,
8,
1365,
12,
6879,
3049,
8,
7977,
534,
7977,
297,
19205,
534,
588,
1333,
267,
4744,
275,
16869,
9654,
5157,
8,
828,
26529,
1524,
12471,
566,
267,
5137,
14,
525,
63,
2537,
8,
3557,
9,
267,
5137,
14,
13951,
14,
2682,
63,
3029,
275,
4744,
267,
9073,
275,
32077,
8,
505,
534,
797,
358,
267,
347,
7434,
8,
962,
12,
2269,
12,
892,
304,
288,
340,
286,
795,
63,
576,
63,
4398,
63,
1452,
8,
1222,
12,
1420,
304,
355,
9073,
14,
505,
275,
283,
549,
7,
267,
1350,
14,
265,
63,
1461,
360,
576,
297,
7434,
9,
267,
1233,
275,
24973,
480,
6742,
401,
298,
3015,
14,
505,
531,
267,
5137,
14,
525,
63,
2537,
8,
7223,
3310,
8,
3058,
29,
7223,
11378,
8,
589,
29,
807,
8,
3015,
29,
3015,
395,
1233,
29,
600,
1724,
267,
1382,
14,
525,
63,
1231,
8,
2301,
8,
2798,
12,
9073,
430,
272,
372,
2811,
63,
1301,
421,
199,
32,
4462,
14,
1657,
14,
15092,
199,
32,
4462,
14,
1657,
14,
15041,
199,
533,
1379,
63,
12747,
9654,
5157,
8,
785,
304,
339,
347,
511,
63,
5511,
63,
991,
63,
885,
8,
277,
12,
2849,
63,
2798,
63,
1606,
304,
267,
5137,
275,
485,
1875,
63,
2798,
342,
398,
2034,
275,
2849,
63,
2798,
63,
1606,
8,
2798,
9,
398,
5528,
275,
2034,
14,
362,
63,
13951,
63,
3887,
360,
6023,
13,
5485,
358,
267,
702,
283,
2682,
7,
315,
5528,
14,
362,
63,
3215,
360,
533,
358,
398,
702,
2034,
14,
1989,
63,
889,
63,
6614,
63,
2550,
342,
339,
347,
511,
63,
2425,
63,
1235,
63,
271,
5511,
63,
460,
63,
5511,
8,
277,
12,
2849,
63,
2798,
63,
1606,
304,
267,
5137,
275,
485,
1875,
63,
2798,
342,
398,
2034,
275,
2849,
63,
2798,
63,
1606,
8,
2798,
9,
398,
327,
2670,
365,
4702,
267,
5528,
275,
2034,
14,
362,
63,
13951,
63,
3887,
360,
6023,
13,
5485,
358,
267,
702,
283,
2682,
7,
315,
5528,
14,
362,
63,
3215,
360,
533,
358,
398,
327,
26147,
436,
1104,
365,
440,
4702,
267,
5528,
275,
2034,
14,
362,
63,
13951,
63,
3887,
360,
6023,
13,
5485,
358,
267,
5528,
14,
4891,
342,
267,
702,
283,
2682,
7,
440,
315,
5528,
14,
362,
63,
3215,
360,
533,
358,
398,
327,
26147,
4020,
436,
1104,
365,
4702,
267,
5528,
275,
2034,
14,
362,
63,
13951,
63,
3887,
360,
6023,
13,
5485,
358,
267,
5528,
14,
4891,
342,
267,
702,
283,
2682,
7,
315,
5528,
14,
362,
63,
3215,
360,
533,
358,
398,
702,
2034,
14,
1989,
63,
889,
63,
6614,
63,
2550,
342,
339,
347,
511,
63,
3157,
63,
4891,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
argivaitv/argivaitv
|
repo/plugin.video.phstreams/resources/lib/sources/onlinemoviesv2_mv.py
|
7
|
3174
|
# -*- coding: utf-8 -*-
'''
Genesis Add-on
Copyright (C) 2015 lambda
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import re,urllib,urlparse
from resources.lib.libraries import cleantitle
from resources.lib.libraries import cloudflare
from resources.lib.libraries import client
from resources.lib.resolvers import openload
from resources.lib import resolvers
class source:
def __init__(self):
self.base_link = 'http://onlinemovies.is'
self.search_link = '/?s=%s'
def get_movie(self, imdb, title, year):
try:
url = title.replace('\'', '')
url = re.sub(r'[^a-zA-Z0-9\s]+', ' ', url).lower().strip()
url = re.sub('\s\s+' , ' ', url)
url = url.replace(' ' , '-')
url = '/%s-%s/' % (url, year)
url = client.replaceHTMLCodes(url)
url = url.encode('utf-8')
return url
except:
return
def get_sources(self, url, hosthdDict, hostDict, locDict):
try:
sources = []
if url == None: return sources
url = urlparse.urljoin(self.base_link, url)
result = cloudflare.source(url)
quality = re.compile('>Quality:(.+?)\n').findall(result)[0]
if 'CAM' in quality or 'TS' in quality: quality = 'CAM'
elif 'SCREENER' in quality: quality = 'SCR'
else: quality = 'HD'
try:
url = client.parseDOM(result, 'iframe', ret='src')
url = [i for i in url if 'videomega' in i.lower()][0]
url = re.compile('[ref|hashkey]=([\w]+)').findall(url)
url = 'http://videomega.tv/cdn.php?ref=%s' % url[0]
url = resolvers.request(url)
if url == None: raise Exception()
sources.append({'source': 'Videomega', 'quality': quality, 'provider': 'Onlinemoviesv2', 'url': url})
except:
pass
try:
url = client.parseDOM(result, 'iframe', ret='src')
url = [i for i in url if 'openload' in i.lower()][0]
if openload.check(url) == False: raise Exception()
sources.append({'source': 'Openload', 'quality': quality, 'provider': 'Onlinemoviesv2', 'url': url})
except:
pass
return sources
except:
return sources
def resolve(self, url):
try:
url = resolvers.request(url)
return url
except:
return
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
2344,
272,
598,
6349,
2316,
2654,
13,
265,
272,
1898,
334,
35,
9,
6900,
2400,
339,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
272,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
272,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
272,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
2344,
421,
199,
646,
295,
12,
4078,
12,
10290,
199,
199,
504,
5944,
14,
773,
14,
10159,
492,
3633,
1213,
199,
504,
5944,
14,
773,
14,
10159,
492,
8002,
14163,
264,
199,
504,
5944,
14,
773,
14,
10159,
492,
1890,
199,
504,
5944,
14,
773,
14,
12640,
492,
1551,
912,
199,
504,
5944,
14,
773,
492,
15611,
83,
421,
199,
533,
1350,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1095,
63,
1073,
275,
283,
1014,
921,
15178,
20888,
14,
374,
7,
267,
291,
14,
1733,
63,
1073,
275,
1994,
31,
83,
2458,
83,
7,
2378,
347,
664,
63,
10888,
8,
277,
12,
18232,
12,
2538,
12,
5361,
304,
267,
862,
26,
288,
1166,
275,
2538,
14,
1814,
2258,
6448,
4074,
288,
1166,
275,
295,
14,
954,
8,
82,
16122,
65,
13,
6353,
13,
58,
16,
13,
25,
60,
83,
11529,
283,
1656,
1166,
680,
2325,
1252,
1913,
342,
288,
1166,
275,
295,
14,
954,
2258,
83,
60,
83,
4786,
2360,
283,
1656,
1166,
9,
288,
1166,
275,
1166,
14,
1814,
360,
283,
2360,
26942,
288,
1166,
275,
1994,
5,
83,
3295,
83,
4805,
450,
334,
633,
12,
5361,
9,
953,
1166,
275,
1890,
14,
1814,
4943,
14060,
8,
633,
9,
288,
1166,
275,
1166,
14,
2143,
360,
1624,
13,
24,
358,
288,
372,
1166,
267,
871,
26,
288,
372,
2378,
347,
664,
63,
4553,
8,
277,
12,
1166,
12,
1591,
7952,
2141,
12,
1591,
2141,
12,
4355,
2141,
304,
267,
862,
26,
288,
5274,
275,
942,
953,
340,
1166,
508,
488,
26,
372,
5274,
953,
1166,
275,
7097,
14,
17755,
8,
277,
14,
1095,
63,
1073,
12,
1166,
9,
953,
754,
275,
8002,
14163,
264,
14,
1365,
8,
633,
9,
953,
11030,
275,
295,
14,
2014,
16099,
19436,
20334,
11198,
2862,
78,
1959,
6452,
8,
1099,
2788,
16,
61,
953,
340,
283,
29932,
7,
315,
11030,
503,
283,
9730,
7,
315,
11030,
26,
11030,
275,
283,
29932,
7,
288,
916,
283,
25070,
540,
7,
315,
11030,
26,
11030,
275,
283,
51,
2944,
7,
288,
587,
26,
11030,
275,
283,
14903,
7,
953,
862,
26,
355,
1166,
275,
1890,
14,
24438,
8,
1099,
12,
283,
20052,
297,
2203,
534,
2164,
358,
355,
1166,
275,
359,
73,
367,
284,
315,
1166,
340,
283,
5624,
23524,
7,
315,
284,
14,
2325,
342,
1527,
16,
61,
355,
1166,
275,
295,
14,
2014,
11894,
1121,
92,
2227,
498,
10404,
16510,
87,
11896,
1959,
6452,
8,
633,
9,
355,
1166,
275,
283,
1014,
921,
5624,
23524,
14,
6993,
15,
23982,
14,
8624,
31,
1121,
2458,
83,
7,
450,
1166,
59,
16,
61,
355,
1166,
275,
15611,
83,
14,
1069,
8,
633,
9,
355,
340,
1166,
508,
488,
26,
746,
2186,
342,
355,
5274,
14,
740,
3252,
1365,
356,
283,
2201,
271,
23524,
297,
283,
9161,
356,
11030,
12,
283,
3780,
356,
283,
28587,
20888,
86,
18,
297,
283,
633,
356,
1166,
1552,
288,
871,
26,
355,
986,
953,
862,
26,
355,
1166,
275,
1890,
14,
24438,
8,
1099,
12,
283,
20052,
297,
2203,
534,
2164,
358,
355,
1166,
275,
359,
73,
367,
284,
315,
1166,
340,
283,
1490,
912,
7,
315,
284,
14,
2325,
342,
1527,
16,
61,
355,
340,
1551,
912,
14,
1074,
8,
633,
9,
508,
756,
26,
746,
2186,
342,
355,
5274,
14,
740,
3252,
1365,
356,
283,
4299,
912,
297,
283,
9161,
356,
11030,
12,
283,
3780,
356,
283,
28587,
20888,
86,
18,
297,
283,
633,
356,
1166,
1552,
288,
871,
26,
355,
986,
953,
372,
5274,
267,
871,
26,
288,
372,
5274,
2378,
347,
7512,
8,
277,
12,
1166,
304,
267,
862,
26,
288,
1166,
275,
15611,
83,
14,
1069,
8,
633,
9,
288,
372,
1166,
267,
871,
26,
288,
372,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
2344,
272,
598,
6349,
2316,
2654,
13,
265,
272,
1898,
334,
35,
9,
6900,
2400,
339,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
272,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
272,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
272,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
2344,
421,
199,
646,
295,
12,
4078,
12,
10290,
199,
199,
504,
5944,
14,
773,
14,
10159,
492,
3633,
1213,
199,
504,
5944,
14,
773,
14,
10159,
492,
8002,
14163,
264,
199,
504,
5944,
14,
773,
14,
10159,
492,
1890,
199,
504,
5944,
14,
773,
14,
12640,
492,
1551,
912,
199,
504,
5944,
14,
773,
492,
15611,
83,
421,
199,
533,
1350,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1095,
63,
1073,
275,
283,
1014,
921,
15178,
20888,
14,
374,
7,
267,
291,
14,
1733,
63,
1073,
275,
1994,
31,
83,
2458,
83,
7,
2378,
347,
664,
63,
10888,
8,
277,
12,
18232,
12,
2538,
12,
5361,
304,
267,
862,
26,
288,
1166,
275,
2538,
14,
1814,
2258,
6448,
4074,
288,
1166,
275,
295,
14,
954,
8,
82,
16122,
65,
13,
6353,
13,
58,
16,
13,
25,
60,
83,
11529,
283,
1656,
1166,
680,
2325,
1252,
1913,
342,
288,
1166,
275,
295,
14,
954,
2258,
83,
60,
83,
4786,
2360,
283,
1656,
1166,
9,
288,
1166,
275,
1166,
14,
1814,
360,
283,
2360,
26942,
288,
1166,
275,
1994,
5,
83,
3295,
83,
4805,
450,
334,
633,
12,
5361,
9,
953,
1166,
275,
1890,
14,
1814,
4943,
14060,
8,
633,
9,
288,
1166,
275,
1166,
14,
2143,
360,
1624,
13,
24,
358,
288,
372,
1166,
267,
871,
26,
288,
372,
2378,
347,
664,
63,
4553,
8,
277,
12,
1166,
12,
1591,
7952,
2141,
12,
1591,
2141,
12,
4355,
2141,
304,
267,
862,
26,
288,
5274,
275,
942,
953,
340,
1166,
508,
488,
26,
372,
5274,
953,
1166,
275,
7097,
14,
17755,
8,
277,
14,
1095,
63,
1073,
12,
1166,
9,
953,
754,
275,
8002,
14163,
264,
14,
1365,
8,
633,
9,
953,
11030,
275,
295,
14,
2014,
16099,
19436,
20334,
11198,
2862,
78,
1959,
6452,
8,
1099,
2788,
16,
61,
953,
340,
283,
29932,
7,
315,
11030,
503,
283,
9730,
7,
315,
11030,
26,
11030,
275,
283,
29932,
7,
288,
916,
283,
25070,
540,
7,
315,
11030,
26,
11030,
275,
283,
51,
2944,
7,
288,
587,
26,
11030,
275,
283,
14903,
7,
953,
862,
26,
355,
1166,
275,
1890,
14,
24438,
8,
1099,
12,
283,
20052,
297,
2203,
534,
2164,
358,
355,
1166,
275,
359,
73,
367,
284,
315,
1166,
340,
283,
5624,
23524,
7,
315,
284,
14,
2325,
342,
1527,
16,
61,
355,
1166,
275,
295,
14,
2014,
11894,
1121,
92,
2227,
498,
10404,
16510,
87,
11896,
1959,
6452,
8,
633,
9,
355,
1166,
275,
283,
1014,
921,
5624,
23524,
14,
6993,
15,
23982,
14,
8624,
31,
1121,
2458,
83,
7,
450,
1166,
59,
16,
61,
355,
1166,
275,
15611,
83,
14,
1069,
8,
633,
9,
355,
340,
1166,
508,
488,
26,
746,
2186,
342,
355,
5274,
14,
740,
3252,
1365,
356,
283,
2201,
271,
23524,
297,
283,
9161,
356,
11030,
12,
283,
3780,
356,
283,
28587,
20888,
86,
18,
297,
283,
633,
356,
1166,
1552,
288,
871,
26,
355,
986,
953,
862,
26,
355,
1166,
275,
1890,
14,
24438,
8,
1099,
12,
283,
20052,
297,
2203,
534,
2164,
358,
355,
1166,
275,
359,
73,
367,
284,
315,
1166,
340,
283,
1490,
912,
7,
315,
284,
14,
2325,
342,
1527,
16,
61,
355,
340,
1551,
912,
14,
1074,
8,
633,
9,
508,
756,
26,
746,
2186,
342,
355,
5274,
14,
740,
3252,
1365,
356,
283,
4299,
912,
297,
283,
9161,
356,
11030,
12,
283,
3780,
356,
283,
28587,
20888,
86,
18,
297,
283,
633,
356,
1166,
1552,
288,
871,
26,
355,
986,
953,
372,
5274,
267,
871,
26,
288,
372,
5274,
2378,
347,
7512,
8,
277,
12,
1166,
304,
267,
862,
26,
288,
1166,
275,
15611,
83,
14,
1069,
8,
633,
9,
288,
372,
1166,
267,
871,
26,
288,
372,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
antb/TPT----My-old-mod
|
src/python/stdlib/encodings/cp852.py
|
593
|
35258
|
""" Python Character Mapping Codec generated from 'VENDORS/MICSFT/PC/CP852.TXT' with gencodec.py.
"""#"
import codecs
### Codec APIs
class Codec(codecs.Codec):
def encode(self,input,errors='strict'):
return codecs.charmap_encode(input,errors,encoding_map)
def decode(self,input,errors='strict'):
return codecs.charmap_decode(input,errors,decoding_table)
class IncrementalEncoder(codecs.IncrementalEncoder):
def encode(self, input, final=False):
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
class IncrementalDecoder(codecs.IncrementalDecoder):
def decode(self, input, final=False):
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
class StreamWriter(Codec,codecs.StreamWriter):
pass
class StreamReader(Codec,codecs.StreamReader):
pass
### encodings module API
def getregentry():
return codecs.CodecInfo(
name='cp852',
encode=Codec().encode,
decode=Codec().decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
)
### Decoding Map
decoding_map = codecs.make_identity_dict(range(256))
decoding_map.update({
0x0080: 0x00c7, # LATIN CAPITAL LETTER C WITH CEDILLA
0x0081: 0x00fc, # LATIN SMALL LETTER U WITH DIAERESIS
0x0082: 0x00e9, # LATIN SMALL LETTER E WITH ACUTE
0x0083: 0x00e2, # LATIN SMALL LETTER A WITH CIRCUMFLEX
0x0084: 0x00e4, # LATIN SMALL LETTER A WITH DIAERESIS
0x0085: 0x016f, # LATIN SMALL LETTER U WITH RING ABOVE
0x0086: 0x0107, # LATIN SMALL LETTER C WITH ACUTE
0x0087: 0x00e7, # LATIN SMALL LETTER C WITH CEDILLA
0x0088: 0x0142, # LATIN SMALL LETTER L WITH STROKE
0x0089: 0x00eb, # LATIN SMALL LETTER E WITH DIAERESIS
0x008a: 0x0150, # LATIN CAPITAL LETTER O WITH DOUBLE ACUTE
0x008b: 0x0151, # LATIN SMALL LETTER O WITH DOUBLE ACUTE
0x008c: 0x00ee, # LATIN SMALL LETTER I WITH CIRCUMFLEX
0x008d: 0x0179, # LATIN CAPITAL LETTER Z WITH ACUTE
0x008e: 0x00c4, # LATIN CAPITAL LETTER A WITH DIAERESIS
0x008f: 0x0106, # LATIN CAPITAL LETTER C WITH ACUTE
0x0090: 0x00c9, # LATIN CAPITAL LETTER E WITH ACUTE
0x0091: 0x0139, # LATIN CAPITAL LETTER L WITH ACUTE
0x0092: 0x013a, # LATIN SMALL LETTER L WITH ACUTE
0x0093: 0x00f4, # LATIN SMALL LETTER O WITH CIRCUMFLEX
0x0094: 0x00f6, # LATIN SMALL LETTER O WITH DIAERESIS
0x0095: 0x013d, # LATIN CAPITAL LETTER L WITH CARON
0x0096: 0x013e, # LATIN SMALL LETTER L WITH CARON
0x0097: 0x015a, # LATIN CAPITAL LETTER S WITH ACUTE
0x0098: 0x015b, # LATIN SMALL LETTER S WITH ACUTE
0x0099: 0x00d6, # LATIN CAPITAL LETTER O WITH DIAERESIS
0x009a: 0x00dc, # LATIN CAPITAL LETTER U WITH DIAERESIS
0x009b: 0x0164, # LATIN CAPITAL LETTER T WITH CARON
0x009c: 0x0165, # LATIN SMALL LETTER T WITH CARON
0x009d: 0x0141, # LATIN CAPITAL LETTER L WITH STROKE
0x009e: 0x00d7, # MULTIPLICATION SIGN
0x009f: 0x010d, # LATIN SMALL LETTER C WITH CARON
0x00a0: 0x00e1, # LATIN SMALL LETTER A WITH ACUTE
0x00a1: 0x00ed, # LATIN SMALL LETTER I WITH ACUTE
0x00a2: 0x00f3, # LATIN SMALL LETTER O WITH ACUTE
0x00a3: 0x00fa, # LATIN SMALL LETTER U WITH ACUTE
0x00a4: 0x0104, # LATIN CAPITAL LETTER A WITH OGONEK
0x00a5: 0x0105, # LATIN SMALL LETTER A WITH OGONEK
0x00a6: 0x017d, # LATIN CAPITAL LETTER Z WITH CARON
0x00a7: 0x017e, # LATIN SMALL LETTER Z WITH CARON
0x00a8: 0x0118, # LATIN CAPITAL LETTER E WITH OGONEK
0x00a9: 0x0119, # LATIN SMALL LETTER E WITH OGONEK
0x00aa: 0x00ac, # NOT SIGN
0x00ab: 0x017a, # LATIN SMALL LETTER Z WITH ACUTE
0x00ac: 0x010c, # LATIN CAPITAL LETTER C WITH CARON
0x00ad: 0x015f, # LATIN SMALL LETTER S WITH CEDILLA
0x00ae: 0x00ab, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
0x00af: 0x00bb, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
0x00b0: 0x2591, # LIGHT SHADE
0x00b1: 0x2592, # MEDIUM SHADE
0x00b2: 0x2593, # DARK SHADE
0x00b3: 0x2502, # BOX DRAWINGS LIGHT VERTICAL
0x00b4: 0x2524, # BOX DRAWINGS LIGHT VERTICAL AND LEFT
0x00b5: 0x00c1, # LATIN CAPITAL LETTER A WITH ACUTE
0x00b6: 0x00c2, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX
0x00b7: 0x011a, # LATIN CAPITAL LETTER E WITH CARON
0x00b8: 0x015e, # LATIN CAPITAL LETTER S WITH CEDILLA
0x00b9: 0x2563, # BOX DRAWINGS DOUBLE VERTICAL AND LEFT
0x00ba: 0x2551, # BOX DRAWINGS DOUBLE VERTICAL
0x00bb: 0x2557, # BOX DRAWINGS DOUBLE DOWN AND LEFT
0x00bc: 0x255d, # BOX DRAWINGS DOUBLE UP AND LEFT
0x00bd: 0x017b, # LATIN CAPITAL LETTER Z WITH DOT ABOVE
0x00be: 0x017c, # LATIN SMALL LETTER Z WITH DOT ABOVE
0x00bf: 0x2510, # BOX DRAWINGS LIGHT DOWN AND LEFT
0x00c0: 0x2514, # BOX DRAWINGS LIGHT UP AND RIGHT
0x00c1: 0x2534, # BOX DRAWINGS LIGHT UP AND HORIZONTAL
0x00c2: 0x252c, # BOX DRAWINGS LIGHT DOWN AND HORIZONTAL
0x00c3: 0x251c, # BOX DRAWINGS LIGHT VERTICAL AND RIGHT
0x00c4: 0x2500, # BOX DRAWINGS LIGHT HORIZONTAL
0x00c5: 0x253c, # BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL
0x00c6: 0x0102, # LATIN CAPITAL LETTER A WITH BREVE
0x00c7: 0x0103, # LATIN SMALL LETTER A WITH BREVE
0x00c8: 0x255a, # BOX DRAWINGS DOUBLE UP AND RIGHT
0x00c9: 0x2554, # BOX DRAWINGS DOUBLE DOWN AND RIGHT
0x00ca: 0x2569, # BOX DRAWINGS DOUBLE UP AND HORIZONTAL
0x00cb: 0x2566, # BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL
0x00cc: 0x2560, # BOX DRAWINGS DOUBLE VERTICAL AND RIGHT
0x00cd: 0x2550, # BOX DRAWINGS DOUBLE HORIZONTAL
0x00ce: 0x256c, # BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL
0x00cf: 0x00a4, # CURRENCY SIGN
0x00d0: 0x0111, # LATIN SMALL LETTER D WITH STROKE
0x00d1: 0x0110, # LATIN CAPITAL LETTER D WITH STROKE
0x00d2: 0x010e, # LATIN CAPITAL LETTER D WITH CARON
0x00d3: 0x00cb, # LATIN CAPITAL LETTER E WITH DIAERESIS
0x00d4: 0x010f, # LATIN SMALL LETTER D WITH CARON
0x00d5: 0x0147, # LATIN CAPITAL LETTER N WITH CARON
0x00d6: 0x00cd, # LATIN CAPITAL LETTER I WITH ACUTE
0x00d7: 0x00ce, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX
0x00d8: 0x011b, # LATIN SMALL LETTER E WITH CARON
0x00d9: 0x2518, # BOX DRAWINGS LIGHT UP AND LEFT
0x00da: 0x250c, # BOX DRAWINGS LIGHT DOWN AND RIGHT
0x00db: 0x2588, # FULL BLOCK
0x00dc: 0x2584, # LOWER HALF BLOCK
0x00dd: 0x0162, # LATIN CAPITAL LETTER T WITH CEDILLA
0x00de: 0x016e, # LATIN CAPITAL LETTER U WITH RING ABOVE
0x00df: 0x2580, # UPPER HALF BLOCK
0x00e0: 0x00d3, # LATIN CAPITAL LETTER O WITH ACUTE
0x00e1: 0x00df, # LATIN SMALL LETTER SHARP S
0x00e2: 0x00d4, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX
0x00e3: 0x0143, # LATIN CAPITAL LETTER N WITH ACUTE
0x00e4: 0x0144, # LATIN SMALL LETTER N WITH ACUTE
0x00e5: 0x0148, # LATIN SMALL LETTER N WITH CARON
0x00e6: 0x0160, # LATIN CAPITAL LETTER S WITH CARON
0x00e7: 0x0161, # LATIN SMALL LETTER S WITH CARON
0x00e8: 0x0154, # LATIN CAPITAL LETTER R WITH ACUTE
0x00e9: 0x00da, # LATIN CAPITAL LETTER U WITH ACUTE
0x00ea: 0x0155, # LATIN SMALL LETTER R WITH ACUTE
0x00eb: 0x0170, # LATIN CAPITAL LETTER U WITH DOUBLE ACUTE
0x00ec: 0x00fd, # LATIN SMALL LETTER Y WITH ACUTE
0x00ed: 0x00dd, # LATIN CAPITAL LETTER Y WITH ACUTE
0x00ee: 0x0163, # LATIN SMALL LETTER T WITH CEDILLA
0x00ef: 0x00b4, # ACUTE ACCENT
0x00f0: 0x00ad, # SOFT HYPHEN
0x00f1: 0x02dd, # DOUBLE ACUTE ACCENT
0x00f2: 0x02db, # OGONEK
0x00f3: 0x02c7, # CARON
0x00f4: 0x02d8, # BREVE
0x00f5: 0x00a7, # SECTION SIGN
0x00f6: 0x00f7, # DIVISION SIGN
0x00f7: 0x00b8, # CEDILLA
0x00f8: 0x00b0, # DEGREE SIGN
0x00f9: 0x00a8, # DIAERESIS
0x00fa: 0x02d9, # DOT ABOVE
0x00fb: 0x0171, # LATIN SMALL LETTER U WITH DOUBLE ACUTE
0x00fc: 0x0158, # LATIN CAPITAL LETTER R WITH CARON
0x00fd: 0x0159, # LATIN SMALL LETTER R WITH CARON
0x00fe: 0x25a0, # BLACK SQUARE
0x00ff: 0x00a0, # NO-BREAK SPACE
})
### Decoding Table
decoding_table = (
u'\x00' # 0x0000 -> NULL
u'\x01' # 0x0001 -> START OF HEADING
u'\x02' # 0x0002 -> START OF TEXT
u'\x03' # 0x0003 -> END OF TEXT
u'\x04' # 0x0004 -> END OF TRANSMISSION
u'\x05' # 0x0005 -> ENQUIRY
u'\x06' # 0x0006 -> ACKNOWLEDGE
u'\x07' # 0x0007 -> BELL
u'\x08' # 0x0008 -> BACKSPACE
u'\t' # 0x0009 -> HORIZONTAL TABULATION
u'\n' # 0x000a -> LINE FEED
u'\x0b' # 0x000b -> VERTICAL TABULATION
u'\x0c' # 0x000c -> FORM FEED
u'\r' # 0x000d -> CARRIAGE RETURN
u'\x0e' # 0x000e -> SHIFT OUT
u'\x0f' # 0x000f -> SHIFT IN
u'\x10' # 0x0010 -> DATA LINK ESCAPE
u'\x11' # 0x0011 -> DEVICE CONTROL ONE
u'\x12' # 0x0012 -> DEVICE CONTROL TWO
u'\x13' # 0x0013 -> DEVICE CONTROL THREE
u'\x14' # 0x0014 -> DEVICE CONTROL FOUR
u'\x15' # 0x0015 -> NEGATIVE ACKNOWLEDGE
u'\x16' # 0x0016 -> SYNCHRONOUS IDLE
u'\x17' # 0x0017 -> END OF TRANSMISSION BLOCK
u'\x18' # 0x0018 -> CANCEL
u'\x19' # 0x0019 -> END OF MEDIUM
u'\x1a' # 0x001a -> SUBSTITUTE
u'\x1b' # 0x001b -> ESCAPE
u'\x1c' # 0x001c -> FILE SEPARATOR
u'\x1d' # 0x001d -> GROUP SEPARATOR
u'\x1e' # 0x001e -> RECORD SEPARATOR
u'\x1f' # 0x001f -> UNIT SEPARATOR
u' ' # 0x0020 -> SPACE
u'!' # 0x0021 -> EXCLAMATION MARK
u'"' # 0x0022 -> QUOTATION MARK
u'#' # 0x0023 -> NUMBER SIGN
u'$' # 0x0024 -> DOLLAR SIGN
u'%' # 0x0025 -> PERCENT SIGN
u'&' # 0x0026 -> AMPERSAND
u"'" # 0x0027 -> APOSTROPHE
u'(' # 0x0028 -> LEFT PARENTHESIS
u')' # 0x0029 -> RIGHT PARENTHESIS
u'*' # 0x002a -> ASTERISK
u'+' # 0x002b -> PLUS SIGN
u',' # 0x002c -> COMMA
u'-' # 0x002d -> HYPHEN-MINUS
u'.' # 0x002e -> FULL STOP
u'/' # 0x002f -> SOLIDUS
u'0' # 0x0030 -> DIGIT ZERO
u'1' # 0x0031 -> DIGIT ONE
u'2' # 0x0032 -> DIGIT TWO
u'3' # 0x0033 -> DIGIT THREE
u'4' # 0x0034 -> DIGIT FOUR
u'5' # 0x0035 -> DIGIT FIVE
u'6' # 0x0036 -> DIGIT SIX
u'7' # 0x0037 -> DIGIT SEVEN
u'8' # 0x0038 -> DIGIT EIGHT
u'9' # 0x0039 -> DIGIT NINE
u':' # 0x003a -> COLON
u';' # 0x003b -> SEMICOLON
u'<' # 0x003c -> LESS-THAN SIGN
u'=' # 0x003d -> EQUALS SIGN
u'>' # 0x003e -> GREATER-THAN SIGN
u'?' # 0x003f -> QUESTION MARK
u'@' # 0x0040 -> COMMERCIAL AT
u'A' # 0x0041 -> LATIN CAPITAL LETTER A
u'B' # 0x0042 -> LATIN CAPITAL LETTER B
u'C' # 0x0043 -> LATIN CAPITAL LETTER C
u'D' # 0x0044 -> LATIN CAPITAL LETTER D
u'E' # 0x0045 -> LATIN CAPITAL LETTER E
u'F' # 0x0046 -> LATIN CAPITAL LETTER F
u'G' # 0x0047 -> LATIN CAPITAL LETTER G
u'H' # 0x0048 -> LATIN CAPITAL LETTER H
u'I' # 0x0049 -> LATIN CAPITAL LETTER I
u'J' # 0x004a -> LATIN CAPITAL LETTER J
u'K' # 0x004b -> LATIN CAPITAL LETTER K
u'L' # 0x004c -> LATIN CAPITAL LETTER L
u'M' # 0x004d -> LATIN CAPITAL LETTER M
u'N' # 0x004e -> LATIN CAPITAL LETTER N
u'O' # 0x004f -> LATIN CAPITAL LETTER O
u'P' # 0x0050 -> LATIN CAPITAL LETTER P
u'Q' # 0x0051 -> LATIN CAPITAL LETTER Q
u'R' # 0x0052 -> LATIN CAPITAL LETTER R
u'S' # 0x0053 -> LATIN CAPITAL LETTER S
u'T' # 0x0054 -> LATIN CAPITAL LETTER T
u'U' # 0x0055 -> LATIN CAPITAL LETTER U
u'V' # 0x0056 -> LATIN CAPITAL LETTER V
u'W' # 0x0057 -> LATIN CAPITAL LETTER W
u'X' # 0x0058 -> LATIN CAPITAL LETTER X
u'Y' # 0x0059 -> LATIN CAPITAL LETTER Y
u'Z' # 0x005a -> LATIN CAPITAL LETTER Z
u'[' # 0x005b -> LEFT SQUARE BRACKET
u'\\' # 0x005c -> REVERSE SOLIDUS
u']' # 0x005d -> RIGHT SQUARE BRACKET
u'^' # 0x005e -> CIRCUMFLEX ACCENT
u'_' # 0x005f -> LOW LINE
u'`' # 0x0060 -> GRAVE ACCENT
u'a' # 0x0061 -> LATIN SMALL LETTER A
u'b' # 0x0062 -> LATIN SMALL LETTER B
u'c' # 0x0063 -> LATIN SMALL LETTER C
u'd' # 0x0064 -> LATIN SMALL LETTER D
u'e' # 0x0065 -> LATIN SMALL LETTER E
u'f' # 0x0066 -> LATIN SMALL LETTER F
u'g' # 0x0067 -> LATIN SMALL LETTER G
u'h' # 0x0068 -> LATIN SMALL LETTER H
u'i' # 0x0069 -> LATIN SMALL LETTER I
u'j' # 0x006a -> LATIN SMALL LETTER J
u'k' # 0x006b -> LATIN SMALL LETTER K
u'l' # 0x006c -> LATIN SMALL LETTER L
u'm' # 0x006d -> LATIN SMALL LETTER M
u'n' # 0x006e -> LATIN SMALL LETTER N
u'o' # 0x006f -> LATIN SMALL LETTER O
u'p' # 0x0070 -> LATIN SMALL LETTER P
u'q' # 0x0071 -> LATIN SMALL LETTER Q
u'r' # 0x0072 -> LATIN SMALL LETTER R
u's' # 0x0073 -> LATIN SMALL LETTER S
u't' # 0x0074 -> LATIN SMALL LETTER T
u'u' # 0x0075 -> LATIN SMALL LETTER U
u'v' # 0x0076 -> LATIN SMALL LETTER V
u'w' # 0x0077 -> LATIN SMALL LETTER W
u'x' # 0x0078 -> LATIN SMALL LETTER X
u'y' # 0x0079 -> LATIN SMALL LETTER Y
u'z' # 0x007a -> LATIN SMALL LETTER Z
u'{' # 0x007b -> LEFT CURLY BRACKET
u'|' # 0x007c -> VERTICAL LINE
u'}' # 0x007d -> RIGHT CURLY BRACKET
u'~' # 0x007e -> TILDE
u'\x7f' # 0x007f -> DELETE
u'\xc7' # 0x0080 -> LATIN CAPITAL LETTER C WITH CEDILLA
u'\xfc' # 0x0081 -> LATIN SMALL LETTER U WITH DIAERESIS
u'\xe9' # 0x0082 -> LATIN SMALL LETTER E WITH ACUTE
u'\xe2' # 0x0083 -> LATIN SMALL LETTER A WITH CIRCUMFLEX
u'\xe4' # 0x0084 -> LATIN SMALL LETTER A WITH DIAERESIS
u'\u016f' # 0x0085 -> LATIN SMALL LETTER U WITH RING ABOVE
u'\u0107' # 0x0086 -> LATIN SMALL LETTER C WITH ACUTE
u'\xe7' # 0x0087 -> LATIN SMALL LETTER C WITH CEDILLA
u'\u0142' # 0x0088 -> LATIN SMALL LETTER L WITH STROKE
u'\xeb' # 0x0089 -> LATIN SMALL LETTER E WITH DIAERESIS
u'\u0150' # 0x008a -> LATIN CAPITAL LETTER O WITH DOUBLE ACUTE
u'\u0151' # 0x008b -> LATIN SMALL LETTER O WITH DOUBLE ACUTE
u'\xee' # 0x008c -> LATIN SMALL LETTER I WITH CIRCUMFLEX
u'\u0179' # 0x008d -> LATIN CAPITAL LETTER Z WITH ACUTE
u'\xc4' # 0x008e -> LATIN CAPITAL LETTER A WITH DIAERESIS
u'\u0106' # 0x008f -> LATIN CAPITAL LETTER C WITH ACUTE
u'\xc9' # 0x0090 -> LATIN CAPITAL LETTER E WITH ACUTE
u'\u0139' # 0x0091 -> LATIN CAPITAL LETTER L WITH ACUTE
u'\u013a' # 0x0092 -> LATIN SMALL LETTER L WITH ACUTE
u'\xf4' # 0x0093 -> LATIN SMALL LETTER O WITH CIRCUMFLEX
u'\xf6' # 0x0094 -> LATIN SMALL LETTER O WITH DIAERESIS
u'\u013d' # 0x0095 -> LATIN CAPITAL LETTER L WITH CARON
u'\u013e' # 0x0096 -> LATIN SMALL LETTER L WITH CARON
u'\u015a' # 0x0097 -> LATIN CAPITAL LETTER S WITH ACUTE
u'\u015b' # 0x0098 -> LATIN SMALL LETTER S WITH ACUTE
u'\xd6' # 0x0099 -> LATIN CAPITAL LETTER O WITH DIAERESIS
u'\xdc' # 0x009a -> LATIN CAPITAL LETTER U WITH DIAERESIS
u'\u0164' # 0x009b -> LATIN CAPITAL LETTER T WITH CARON
u'\u0165' # 0x009c -> LATIN SMALL LETTER T WITH CARON
u'\u0141' # 0x009d -> LATIN CAPITAL LETTER L WITH STROKE
u'\xd7' # 0x009e -> MULTIPLICATION SIGN
u'\u010d' # 0x009f -> LATIN SMALL LETTER C WITH CARON
u'\xe1' # 0x00a0 -> LATIN SMALL LETTER A WITH ACUTE
u'\xed' # 0x00a1 -> LATIN SMALL LETTER I WITH ACUTE
u'\xf3' # 0x00a2 -> LATIN SMALL LETTER O WITH ACUTE
u'\xfa' # 0x00a3 -> LATIN SMALL LETTER U WITH ACUTE
u'\u0104' # 0x00a4 -> LATIN CAPITAL LETTER A WITH OGONEK
u'\u0105' # 0x00a5 -> LATIN SMALL LETTER A WITH OGONEK
u'\u017d' # 0x00a6 -> LATIN CAPITAL LETTER Z WITH CARON
u'\u017e' # 0x00a7 -> LATIN SMALL LETTER Z WITH CARON
u'\u0118' # 0x00a8 -> LATIN CAPITAL LETTER E WITH OGONEK
u'\u0119' # 0x00a9 -> LATIN SMALL LETTER E WITH OGONEK
u'\xac' # 0x00aa -> NOT SIGN
u'\u017a' # 0x00ab -> LATIN SMALL LETTER Z WITH ACUTE
u'\u010c' # 0x00ac -> LATIN CAPITAL LETTER C WITH CARON
u'\u015f' # 0x00ad -> LATIN SMALL LETTER S WITH CEDILLA
u'\xab' # 0x00ae -> LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
u'\xbb' # 0x00af -> RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
u'\u2591' # 0x00b0 -> LIGHT SHADE
u'\u2592' # 0x00b1 -> MEDIUM SHADE
u'\u2593' # 0x00b2 -> DARK SHADE
u'\u2502' # 0x00b3 -> BOX DRAWINGS LIGHT VERTICAL
u'\u2524' # 0x00b4 -> BOX DRAWINGS LIGHT VERTICAL AND LEFT
u'\xc1' # 0x00b5 -> LATIN CAPITAL LETTER A WITH ACUTE
u'\xc2' # 0x00b6 -> LATIN CAPITAL LETTER A WITH CIRCUMFLEX
u'\u011a' # 0x00b7 -> LATIN CAPITAL LETTER E WITH CARON
u'\u015e' # 0x00b8 -> LATIN CAPITAL LETTER S WITH CEDILLA
u'\u2563' # 0x00b9 -> BOX DRAWINGS DOUBLE VERTICAL AND LEFT
u'\u2551' # 0x00ba -> BOX DRAWINGS DOUBLE VERTICAL
u'\u2557' # 0x00bb -> BOX DRAWINGS DOUBLE DOWN AND LEFT
u'\u255d' # 0x00bc -> BOX DRAWINGS DOUBLE UP AND LEFT
u'\u017b' # 0x00bd -> LATIN CAPITAL LETTER Z WITH DOT ABOVE
u'\u017c' # 0x00be -> LATIN SMALL LETTER Z WITH DOT ABOVE
u'\u2510' # 0x00bf -> BOX DRAWINGS LIGHT DOWN AND LEFT
u'\u2514' # 0x00c0 -> BOX DRAWINGS LIGHT UP AND RIGHT
u'\u2534' # 0x00c1 -> BOX DRAWINGS LIGHT UP AND HORIZONTAL
u'\u252c' # 0x00c2 -> BOX DRAWINGS LIGHT DOWN AND HORIZONTAL
u'\u251c' # 0x00c3 -> BOX DRAWINGS LIGHT VERTICAL AND RIGHT
u'\u2500' # 0x00c4 -> BOX DRAWINGS LIGHT HORIZONTAL
u'\u253c' # 0x00c5 -> BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL
u'\u0102' # 0x00c6 -> LATIN CAPITAL LETTER A WITH BREVE
u'\u0103' # 0x00c7 -> LATIN SMALL LETTER A WITH BREVE
u'\u255a' # 0x00c8 -> BOX DRAWINGS DOUBLE UP AND RIGHT
u'\u2554' # 0x00c9 -> BOX DRAWINGS DOUBLE DOWN AND RIGHT
u'\u2569' # 0x00ca -> BOX DRAWINGS DOUBLE UP AND HORIZONTAL
u'\u2566' # 0x00cb -> BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL
u'\u2560' # 0x00cc -> BOX DRAWINGS DOUBLE VERTICAL AND RIGHT
u'\u2550' # 0x00cd -> BOX DRAWINGS DOUBLE HORIZONTAL
u'\u256c' # 0x00ce -> BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL
u'\xa4' # 0x00cf -> CURRENCY SIGN
u'\u0111' # 0x00d0 -> LATIN SMALL LETTER D WITH STROKE
u'\u0110' # 0x00d1 -> LATIN CAPITAL LETTER D WITH STROKE
u'\u010e' # 0x00d2 -> LATIN CAPITAL LETTER D WITH CARON
u'\xcb' # 0x00d3 -> LATIN CAPITAL LETTER E WITH DIAERESIS
u'\u010f' # 0x00d4 -> LATIN SMALL LETTER D WITH CARON
u'\u0147' # 0x00d5 -> LATIN CAPITAL LETTER N WITH CARON
u'\xcd' # 0x00d6 -> LATIN CAPITAL LETTER I WITH ACUTE
u'\xce' # 0x00d7 -> LATIN CAPITAL LETTER I WITH CIRCUMFLEX
u'\u011b' # 0x00d8 -> LATIN SMALL LETTER E WITH CARON
u'\u2518' # 0x00d9 -> BOX DRAWINGS LIGHT UP AND LEFT
u'\u250c' # 0x00da -> BOX DRAWINGS LIGHT DOWN AND RIGHT
u'\u2588' # 0x00db -> FULL BLOCK
u'\u2584' # 0x00dc -> LOWER HALF BLOCK
u'\u0162' # 0x00dd -> LATIN CAPITAL LETTER T WITH CEDILLA
u'\u016e' # 0x00de -> LATIN CAPITAL LETTER U WITH RING ABOVE
u'\u2580' # 0x00df -> UPPER HALF BLOCK
u'\xd3' # 0x00e0 -> LATIN CAPITAL LETTER O WITH ACUTE
u'\xdf' # 0x00e1 -> LATIN SMALL LETTER SHARP S
u'\xd4' # 0x00e2 -> LATIN CAPITAL LETTER O WITH CIRCUMFLEX
u'\u0143' # 0x00e3 -> LATIN CAPITAL LETTER N WITH ACUTE
u'\u0144' # 0x00e4 -> LATIN SMALL LETTER N WITH ACUTE
u'\u0148' # 0x00e5 -> LATIN SMALL LETTER N WITH CARON
u'\u0160' # 0x00e6 -> LATIN CAPITAL LETTER S WITH CARON
u'\u0161' # 0x00e7 -> LATIN SMALL LETTER S WITH CARON
u'\u0154' # 0x00e8 -> LATIN CAPITAL LETTER R WITH ACUTE
u'\xda' # 0x00e9 -> LATIN CAPITAL LETTER U WITH ACUTE
u'\u0155' # 0x00ea -> LATIN SMALL LETTER R WITH ACUTE
u'\u0170' # 0x00eb -> LATIN CAPITAL LETTER U WITH DOUBLE ACUTE
u'\xfd' # 0x00ec -> LATIN SMALL LETTER Y WITH ACUTE
u'\xdd' # 0x00ed -> LATIN CAPITAL LETTER Y WITH ACUTE
u'\u0163' # 0x00ee -> LATIN SMALL LETTER T WITH CEDILLA
u'\xb4' # 0x00ef -> ACUTE ACCENT
u'\xad' # 0x00f0 -> SOFT HYPHEN
u'\u02dd' # 0x00f1 -> DOUBLE ACUTE ACCENT
u'\u02db' # 0x00f2 -> OGONEK
u'\u02c7' # 0x00f3 -> CARON
u'\u02d8' # 0x00f4 -> BREVE
u'\xa7' # 0x00f5 -> SECTION SIGN
u'\xf7' # 0x00f6 -> DIVISION SIGN
u'\xb8' # 0x00f7 -> CEDILLA
u'\xb0' # 0x00f8 -> DEGREE SIGN
u'\xa8' # 0x00f9 -> DIAERESIS
u'\u02d9' # 0x00fa -> DOT ABOVE
u'\u0171' # 0x00fb -> LATIN SMALL LETTER U WITH DOUBLE ACUTE
u'\u0158' # 0x00fc -> LATIN CAPITAL LETTER R WITH CARON
u'\u0159' # 0x00fd -> LATIN SMALL LETTER R WITH CARON
u'\u25a0' # 0x00fe -> BLACK SQUARE
u'\xa0' # 0x00ff -> NO-BREAK SPACE
)
### Encoding Map
encoding_map = {
0x0000: 0x0000, # NULL
0x0001: 0x0001, # START OF HEADING
0x0002: 0x0002, # START OF TEXT
0x0003: 0x0003, # END OF TEXT
0x0004: 0x0004, # END OF TRANSMISSION
0x0005: 0x0005, # ENQUIRY
0x0006: 0x0006, # ACKNOWLEDGE
0x0007: 0x0007, # BELL
0x0008: 0x0008, # BACKSPACE
0x0009: 0x0009, # HORIZONTAL TABULATION
0x000a: 0x000a, # LINE FEED
0x000b: 0x000b, # VERTICAL TABULATION
0x000c: 0x000c, # FORM FEED
0x000d: 0x000d, # CARRIAGE RETURN
0x000e: 0x000e, # SHIFT OUT
0x000f: 0x000f, # SHIFT IN
0x0010: 0x0010, # DATA LINK ESCAPE
0x0011: 0x0011, # DEVICE CONTROL ONE
0x0012: 0x0012, # DEVICE CONTROL TWO
0x0013: 0x0013, # DEVICE CONTROL THREE
0x0014: 0x0014, # DEVICE CONTROL FOUR
0x0015: 0x0015, # NEGATIVE ACKNOWLEDGE
0x0016: 0x0016, # SYNCHRONOUS IDLE
0x0017: 0x0017, # END OF TRANSMISSION BLOCK
0x0018: 0x0018, # CANCEL
0x0019: 0x0019, # END OF MEDIUM
0x001a: 0x001a, # SUBSTITUTE
0x001b: 0x001b, # ESCAPE
0x001c: 0x001c, # FILE SEPARATOR
0x001d: 0x001d, # GROUP SEPARATOR
0x001e: 0x001e, # RECORD SEPARATOR
0x001f: 0x001f, # UNIT SEPARATOR
0x0020: 0x0020, # SPACE
0x0021: 0x0021, # EXCLAMATION MARK
0x0022: 0x0022, # QUOTATION MARK
0x0023: 0x0023, # NUMBER SIGN
0x0024: 0x0024, # DOLLAR SIGN
0x0025: 0x0025, # PERCENT SIGN
0x0026: 0x0026, # AMPERSAND
0x0027: 0x0027, # APOSTROPHE
0x0028: 0x0028, # LEFT PARENTHESIS
0x0029: 0x0029, # RIGHT PARENTHESIS
0x002a: 0x002a, # ASTERISK
0x002b: 0x002b, # PLUS SIGN
0x002c: 0x002c, # COMMA
0x002d: 0x002d, # HYPHEN-MINUS
0x002e: 0x002e, # FULL STOP
0x002f: 0x002f, # SOLIDUS
0x0030: 0x0030, # DIGIT ZERO
0x0031: 0x0031, # DIGIT ONE
0x0032: 0x0032, # DIGIT TWO
0x0033: 0x0033, # DIGIT THREE
0x0034: 0x0034, # DIGIT FOUR
0x0035: 0x0035, # DIGIT FIVE
0x0036: 0x0036, # DIGIT SIX
0x0037: 0x0037, # DIGIT SEVEN
0x0038: 0x0038, # DIGIT EIGHT
0x0039: 0x0039, # DIGIT NINE
0x003a: 0x003a, # COLON
0x003b: 0x003b, # SEMICOLON
0x003c: 0x003c, # LESS-THAN SIGN
0x003d: 0x003d, # EQUALS SIGN
0x003e: 0x003e, # GREATER-THAN SIGN
0x003f: 0x003f, # QUESTION MARK
0x0040: 0x0040, # COMMERCIAL AT
0x0041: 0x0041, # LATIN CAPITAL LETTER A
0x0042: 0x0042, # LATIN CAPITAL LETTER B
0x0043: 0x0043, # LATIN CAPITAL LETTER C
0x0044: 0x0044, # LATIN CAPITAL LETTER D
0x0045: 0x0045, # LATIN CAPITAL LETTER E
0x0046: 0x0046, # LATIN CAPITAL LETTER F
0x0047: 0x0047, # LATIN CAPITAL LETTER G
0x0048: 0x0048, # LATIN CAPITAL LETTER H
0x0049: 0x0049, # LATIN CAPITAL LETTER I
0x004a: 0x004a, # LATIN CAPITAL LETTER J
0x004b: 0x004b, # LATIN CAPITAL LETTER K
0x004c: 0x004c, # LATIN CAPITAL LETTER L
0x004d: 0x004d, # LATIN CAPITAL LETTER M
0x004e: 0x004e, # LATIN CAPITAL LETTER N
0x004f: 0x004f, # LATIN CAPITAL LETTER O
0x0050: 0x0050, # LATIN CAPITAL LETTER P
0x0051: 0x0051, # LATIN CAPITAL LETTER Q
0x0052: 0x0052, # LATIN CAPITAL LETTER R
0x0053: 0x0053, # LATIN CAPITAL LETTER S
0x0054: 0x0054, # LATIN CAPITAL LETTER T
0x0055: 0x0055, # LATIN CAPITAL LETTER U
0x0056: 0x0056, # LATIN CAPITAL LETTER V
0x0057: 0x0057, # LATIN CAPITAL LETTER W
0x0058: 0x0058, # LATIN CAPITAL LETTER X
0x0059: 0x0059, # LATIN CAPITAL LETTER Y
0x005a: 0x005a, # LATIN CAPITAL LETTER Z
0x005b: 0x005b, # LEFT SQUARE BRACKET
0x005c: 0x005c, # REVERSE SOLIDUS
0x005d: 0x005d, # RIGHT SQUARE BRACKET
0x005e: 0x005e, # CIRCUMFLEX ACCENT
0x005f: 0x005f, # LOW LINE
0x0060: 0x0060, # GRAVE ACCENT
0x0061: 0x0061, # LATIN SMALL LETTER A
0x0062: 0x0062, # LATIN SMALL LETTER B
0x0063: 0x0063, # LATIN SMALL LETTER C
0x0064: 0x0064, # LATIN SMALL LETTER D
0x0065: 0x0065, # LATIN SMALL LETTER E
0x0066: 0x0066, # LATIN SMALL LETTER F
0x0067: 0x0067, # LATIN SMALL LETTER G
0x0068: 0x0068, # LATIN SMALL LETTER H
0x0069: 0x0069, # LATIN SMALL LETTER I
0x006a: 0x006a, # LATIN SMALL LETTER J
0x006b: 0x006b, # LATIN SMALL LETTER K
0x006c: 0x006c, # LATIN SMALL LETTER L
0x006d: 0x006d, # LATIN SMALL LETTER M
0x006e: 0x006e, # LATIN SMALL LETTER N
0x006f: 0x006f, # LATIN SMALL LETTER O
0x0070: 0x0070, # LATIN SMALL LETTER P
0x0071: 0x0071, # LATIN SMALL LETTER Q
0x0072: 0x0072, # LATIN SMALL LETTER R
0x0073: 0x0073, # LATIN SMALL LETTER S
0x0074: 0x0074, # LATIN SMALL LETTER T
0x0075: 0x0075, # LATIN SMALL LETTER U
0x0076: 0x0076, # LATIN SMALL LETTER V
0x0077: 0x0077, # LATIN SMALL LETTER W
0x0078: 0x0078, # LATIN SMALL LETTER X
0x0079: 0x0079, # LATIN SMALL LETTER Y
0x007a: 0x007a, # LATIN SMALL LETTER Z
0x007b: 0x007b, # LEFT CURLY BRACKET
0x007c: 0x007c, # VERTICAL LINE
0x007d: 0x007d, # RIGHT CURLY BRACKET
0x007e: 0x007e, # TILDE
0x007f: 0x007f, # DELETE
0x00a0: 0x00ff, # NO-BREAK SPACE
0x00a4: 0x00cf, # CURRENCY SIGN
0x00a7: 0x00f5, # SECTION SIGN
0x00a8: 0x00f9, # DIAERESIS
0x00ab: 0x00ae, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
0x00ac: 0x00aa, # NOT SIGN
0x00ad: 0x00f0, # SOFT HYPHEN
0x00b0: 0x00f8, # DEGREE SIGN
0x00b4: 0x00ef, # ACUTE ACCENT
0x00b8: 0x00f7, # CEDILLA
0x00bb: 0x00af, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
0x00c1: 0x00b5, # LATIN CAPITAL LETTER A WITH ACUTE
0x00c2: 0x00b6, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX
0x00c4: 0x008e, # LATIN CAPITAL LETTER A WITH DIAERESIS
0x00c7: 0x0080, # LATIN CAPITAL LETTER C WITH CEDILLA
0x00c9: 0x0090, # LATIN CAPITAL LETTER E WITH ACUTE
0x00cb: 0x00d3, # LATIN CAPITAL LETTER E WITH DIAERESIS
0x00cd: 0x00d6, # LATIN CAPITAL LETTER I WITH ACUTE
0x00ce: 0x00d7, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX
0x00d3: 0x00e0, # LATIN CAPITAL LETTER O WITH ACUTE
0x00d4: 0x00e2, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX
0x00d6: 0x0099, # LATIN CAPITAL LETTER O WITH DIAERESIS
0x00d7: 0x009e, # MULTIPLICATION SIGN
0x00da: 0x00e9, # LATIN CAPITAL LETTER U WITH ACUTE
0x00dc: 0x009a, # LATIN CAPITAL LETTER U WITH DIAERESIS
0x00dd: 0x00ed, # LATIN CAPITAL LETTER Y WITH ACUTE
0x00df: 0x00e1, # LATIN SMALL LETTER SHARP S
0x00e1: 0x00a0, # LATIN SMALL LETTER A WITH ACUTE
0x00e2: 0x0083, # LATIN SMALL LETTER A WITH CIRCUMFLEX
0x00e4: 0x0084, # LATIN SMALL LETTER A WITH DIAERESIS
0x00e7: 0x0087, # LATIN SMALL LETTER C WITH CEDILLA
0x00e9: 0x0082, # LATIN SMALL LETTER E WITH ACUTE
0x00eb: 0x0089, # LATIN SMALL LETTER E WITH DIAERESIS
0x00ed: 0x00a1, # LATIN SMALL LETTER I WITH ACUTE
0x00ee: 0x008c, # LATIN SMALL LETTER I WITH CIRCUMFLEX
0x00f3: 0x00a2, # LATIN SMALL LETTER O WITH ACUTE
0x00f4: 0x0093, # LATIN SMALL LETTER O WITH CIRCUMFLEX
0x00f6: 0x0094, # LATIN SMALL LETTER O WITH DIAERESIS
0x00f7: 0x00f6, # DIVISION SIGN
0x00fa: 0x00a3, # LATIN SMALL LETTER U WITH ACUTE
0x00fc: 0x0081, # LATIN SMALL LETTER U WITH DIAERESIS
0x00fd: 0x00ec, # LATIN SMALL LETTER Y WITH ACUTE
0x0102: 0x00c6, # LATIN CAPITAL LETTER A WITH BREVE
0x0103: 0x00c7, # LATIN SMALL LETTER A WITH BREVE
0x0104: 0x00a4, # LATIN CAPITAL LETTER A WITH OGONEK
0x0105: 0x00a5, # LATIN SMALL LETTER A WITH OGONEK
0x0106: 0x008f, # LATIN CAPITAL LETTER C WITH ACUTE
0x0107: 0x0086, # LATIN SMALL LETTER C WITH ACUTE
0x010c: 0x00ac, # LATIN CAPITAL LETTER C WITH CARON
0x010d: 0x009f, # LATIN SMALL LETTER C WITH CARON
0x010e: 0x00d2, # LATIN CAPITAL LETTER D WITH CARON
0x010f: 0x00d4, # LATIN SMALL LETTER D WITH CARON
0x0110: 0x00d1, # LATIN CAPITAL LETTER D WITH STROKE
0x0111: 0x00d0, # LATIN SMALL LETTER D WITH STROKE
0x0118: 0x00a8, # LATIN CAPITAL LETTER E WITH OGONEK
0x0119: 0x00a9, # LATIN SMALL LETTER E WITH OGONEK
0x011a: 0x00b7, # LATIN CAPITAL LETTER E WITH CARON
0x011b: 0x00d8, # LATIN SMALL LETTER E WITH CARON
0x0139: 0x0091, # LATIN CAPITAL LETTER L WITH ACUTE
0x013a: 0x0092, # LATIN SMALL LETTER L WITH ACUTE
0x013d: 0x0095, # LATIN CAPITAL LETTER L WITH CARON
0x013e: 0x0096, # LATIN SMALL LETTER L WITH CARON
0x0141: 0x009d, # LATIN CAPITAL LETTER L WITH STROKE
0x0142: 0x0088, # LATIN SMALL LETTER L WITH STROKE
0x0143: 0x00e3, # LATIN CAPITAL LETTER N WITH ACUTE
0x0144: 0x00e4, # LATIN SMALL LETTER N WITH ACUTE
0x0147: 0x00d5, # LATIN CAPITAL LETTER N WITH CARON
0x0148: 0x00e5, # LATIN SMALL LETTER N WITH CARON
0x0150: 0x008a, # LATIN CAPITAL LETTER O WITH DOUBLE ACUTE
0x0151: 0x008b, # LATIN SMALL LETTER O WITH DOUBLE ACUTE
0x0154: 0x00e8, # LATIN CAPITAL LETTER R WITH ACUTE
0x0155: 0x00ea, # LATIN SMALL LETTER R WITH ACUTE
0x0158: 0x00fc, # LATIN CAPITAL LETTER R WITH CARON
0x0159: 0x00fd, # LATIN SMALL LETTER R WITH CARON
0x015a: 0x0097, # LATIN CAPITAL LETTER S WITH ACUTE
0x015b: 0x0098, # LATIN SMALL LETTER S WITH ACUTE
0x015e: 0x00b8, # LATIN CAPITAL LETTER S WITH CEDILLA
0x015f: 0x00ad, # LATIN SMALL LETTER S WITH CEDILLA
0x0160: 0x00e6, # LATIN CAPITAL LETTER S WITH CARON
0x0161: 0x00e7, # LATIN SMALL LETTER S WITH CARON
0x0162: 0x00dd, # LATIN CAPITAL LETTER T WITH CEDILLA
0x0163: 0x00ee, # LATIN SMALL LETTER T WITH CEDILLA
0x0164: 0x009b, # LATIN CAPITAL LETTER T WITH CARON
0x0165: 0x009c, # LATIN SMALL LETTER T WITH CARON
0x016e: 0x00de, # LATIN CAPITAL LETTER U WITH RING ABOVE
0x016f: 0x0085, # LATIN SMALL LETTER U WITH RING ABOVE
0x0170: 0x00eb, # LATIN CAPITAL LETTER U WITH DOUBLE ACUTE
0x0171: 0x00fb, # LATIN SMALL LETTER U WITH DOUBLE ACUTE
0x0179: 0x008d, # LATIN CAPITAL LETTER Z WITH ACUTE
0x017a: 0x00ab, # LATIN SMALL LETTER Z WITH ACUTE
0x017b: 0x00bd, # LATIN CAPITAL LETTER Z WITH DOT ABOVE
0x017c: 0x00be, # LATIN SMALL LETTER Z WITH DOT ABOVE
0x017d: 0x00a6, # LATIN CAPITAL LETTER Z WITH CARON
0x017e: 0x00a7, # LATIN SMALL LETTER Z WITH CARON
0x02c7: 0x00f3, # CARON
0x02d8: 0x00f4, # BREVE
0x02d9: 0x00fa, # DOT ABOVE
0x02db: 0x00f2, # OGONEK
0x02dd: 0x00f1, # DOUBLE ACUTE ACCENT
0x2500: 0x00c4, # BOX DRAWINGS LIGHT HORIZONTAL
0x2502: 0x00b3, # BOX DRAWINGS LIGHT VERTICAL
0x250c: 0x00da, # BOX DRAWINGS LIGHT DOWN AND RIGHT
0x2510: 0x00bf, # BOX DRAWINGS LIGHT DOWN AND LEFT
0x2514: 0x00c0, # BOX DRAWINGS LIGHT UP AND RIGHT
0x2518: 0x00d9, # BOX DRAWINGS LIGHT UP AND LEFT
0x251c: 0x00c3, # BOX DRAWINGS LIGHT VERTICAL AND RIGHT
0x2524: 0x00b4, # BOX DRAWINGS LIGHT VERTICAL AND LEFT
0x252c: 0x00c2, # BOX DRAWINGS LIGHT DOWN AND HORIZONTAL
0x2534: 0x00c1, # BOX DRAWINGS LIGHT UP AND HORIZONTAL
0x253c: 0x00c5, # BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL
0x2550: 0x00cd, # BOX DRAWINGS DOUBLE HORIZONTAL
0x2551: 0x00ba, # BOX DRAWINGS DOUBLE VERTICAL
0x2554: 0x00c9, # BOX DRAWINGS DOUBLE DOWN AND RIGHT
0x2557: 0x00bb, # BOX DRAWINGS DOUBLE DOWN AND LEFT
0x255a: 0x00c8, # BOX DRAWINGS DOUBLE UP AND RIGHT
0x255d: 0x00bc, # BOX DRAWINGS DOUBLE UP AND LEFT
0x2560: 0x00cc, # BOX DRAWINGS DOUBLE VERTICAL AND RIGHT
0x2563: 0x00b9, # BOX DRAWINGS DOUBLE VERTICAL AND LEFT
0x2566: 0x00cb, # BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL
0x2569: 0x00ca, # BOX DRAWINGS DOUBLE UP AND HORIZONTAL
0x256c: 0x00ce, # BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL
0x2580: 0x00df, # UPPER HALF BLOCK
0x2584: 0x00dc, # LOWER HALF BLOCK
0x2588: 0x00db, # FULL BLOCK
0x2591: 0x00b0, # LIGHT SHADE
0x2592: 0x00b1, # MEDIUM SHADE
0x2593: 0x00b2, # DARK SHADE
0x25a0: 0x00fe, # BLACK SQUARE
}
|
gpl-2.0
|
[
624,
2018,
17660,
12340,
13732,
4046,
687,
283,
27839,
4149,
15,
17233,
51,
2161,
15,
4222,
15,
2890,
22719,
14,
17715,
7,
543,
486,
2143,
67,
14,
647,
14,
199,
199,
624,
23662,
199,
199,
646,
6010,
199,
199,
5680,
13732,
15913,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
2550,
12,
2991,
63,
1130,
9,
339,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
2550,
12,
12796,
63,
1224,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
277,
14,
2550,
12,
2991,
63,
1130,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
277,
14,
2550,
12,
12796,
63,
1224,
2788,
16,
61,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
1850,
22719,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
199,
199,
5680,
27368,
9672,
199,
199,
12796,
63,
1130,
275,
6010,
14,
1875,
63,
5582,
63,
807,
8,
1842,
8,
3912,
430,
199,
12796,
63,
1130,
14,
873,
2561,
272,
378,
88,
23686,
26,
378,
88,
383,
67,
23,
12,
258,
327,
221,
1948,
2678,
1578,
445,
1663,
15609,
272,
378,
88,
383,
2835,
26,
378,
88,
383,
3003,
12,
258,
327,
221,
1948,
2516,
1578,
738,
1663,
9680,
272,
378,
88,
383,
2564,
26,
378,
88,
383,
69,
25,
12,
258,
327,
221,
1948,
2516,
1578,
662,
1663,
8123,
272,
378,
88,
383,
2658,
26,
378,
88,
383,
69,
18,
12,
258,
327,
221,
1948,
2516,
1578,
437,
1663,
10040,
272,
378,
88,
30935,
26,
378,
88,
383,
69,
20,
12,
258,
327,
221,
1948,
2516,
1578,
437,
1663,
9680,
272,
378,
88,
383,
2426,
26,
378,
88,
10882,
70,
12,
258,
327,
221,
1948,
2516,
1578,
738,
1663,
24809,
16054,
272,
378,
88,
31743,
26,
378,
88,
32586,
12,
258,
327,
221,
1948,
2516,
1578,
445,
1663,
8123,
272,
378,
88,
383,
1555,
26,
378,
88,
383,
69,
23,
12,
258,
327,
221,
1948,
2516,
1578,
445,
1663,
15609,
272,
378,
88,
31419,
26,
378,
88,
29556,
12,
258,
327,
221,
1948,
2516,
1578,
491,
1663,
22755,
272,
378,
88,
383,
1407,
26,
378,
88,
383,
2871,
12,
258,
327,
221,
1948,
2516,
1578,
662,
1663,
9680,
272,
378,
88,
8662,
65,
26,
378,
88,
614,
1400,
12,
258,
327,
221,
1948,
2678,
1578,
593,
1663,
5681,
8123,
272,
378,
88,
8662,
66,
26,
378,
88,
614,
2869,
12,
258,
327,
221,
1948,
2516,
1578,
593,
1663,
5681,
8123,
272,
378,
88,
8662,
67,
26,
378,
88,
383,
1024,
12,
258,
327,
221,
1948,
2516,
1578,
473,
1663,
10040,
272,
378,
88,
8662,
68,
26,
378,
88,
614,
1965,
12,
258,
327,
221,
1948,
2678,
1578,
3107,
1663,
8123,
272,
378,
88,
8662,
69,
26,
378,
88,
383,
67,
20,
12,
258,
327,
221,
1948,
2678,
1578,
437,
1663,
9680,
272,
378,
88,
8662,
70,
26,
378,
88,
614,
1690,
12,
258,
327,
221,
1948,
2678,
1578,
445,
1663,
8123,
272,
378,
88,
28875,
26,
378,
88,
383,
67,
25,
12,
258,
327,
221,
1948,
2678,
1578,
662,
1663,
8123,
272,
378,
88,
383,
3328,
26,
378,
88,
614,
1355,
12,
258,
327,
221,
1948,
2678,
1578,
491,
1663,
8123,
272,
378,
88,
383,
2942,
26,
378,
88,
13264,
65,
12,
258,
327,
221,
1948,
2516,
1578,
491,
1663,
8123,
272,
378,
88,
383,
3129,
26,
378,
88,
383,
70,
20,
12,
258,
327,
221,
1948,
2516,
1578,
593,
1663,
10040,
272,
378,
88,
383,
2635,
26,
378,
88,
383,
70,
22,
12,
258,
327,
221,
1948,
2516,
1578,
593,
1663,
9680,
272,
378,
88,
383,
2720,
26,
378,
88,
13264,
68,
12,
258,
327,
221,
1948,
2678,
1578,
491,
1663,
17913,
272,
378,
88,
383,
2534,
26,
378,
88,
13264,
69,
12,
258,
327,
221,
1948,
2516,
1578,
491,
1663,
17913,
272,
378,
88,
383,
2576,
26,
378,
88,
11164,
65,
12,
258,
327,
221,
1948,
2678,
1578,
428,
1663,
8123,
272,
378,
88,
383,
2905,
26,
378,
88,
11164,
66,
12,
258,
327,
221,
1948,
2516,
1578,
428,
1663,
8123,
272,
378,
88,
29660,
26,
378,
88,
383,
68,
22,
12,
258,
327,
221,
1948,
2678,
1578,
593,
1663,
9680,
272,
378,
88,
8581,
65,
26,
378,
88,
383,
3833,
12,
258,
327,
221,
1948,
2678,
1578,
738,
1663,
9680,
272,
378,
88,
8581,
66,
26,
378,
88,
614,
772,
12,
258,
327,
221,
1948,
2678,
1578,
377,
1663,
17913,
272,
378,
88,
8581,
67,
26,
378,
88,
614,
2182,
12,
258,
327,
221,
1948,
2516,
1578,
377,
1663,
17913,
272,
378,
88,
8581,
68,
26,
378,
88,
614,
2953,
12,
258,
327,
221,
1948,
2678,
1578,
491,
1663,
22755,
272,
378,
88,
8581,
69,
26,
378,
88,
383,
68,
23,
12,
258,
327,
221,
24895,
1772,
17939,
5056,
272,
378,
88,
8581,
70,
26,
378,
88,
9523,
68,
12,
258,
327,
221,
1948,
2516,
1578,
445,
1663,
17913,
272,
378,
88,
383,
65,
16,
26,
378,
88,
383,
69,
17,
12,
258,
327,
221,
1948,
2516,
1578,
437,
1663,
8123,
272,
378,
88,
383,
65,
17,
26,
378,
88,
383,
379,
12,
258,
327,
221,
1948,
2516,
1578,
473,
1663,
8123,
272,
378,
88,
383,
65,
18,
26,
378,
88,
383,
70,
19,
12,
258,
327,
221,
1948,
2516,
1578,
593,
1663,
8123,
272,
378,
88,
383,
65,
19,
26,
378,
88,
383,
667
] |
[
2018,
17660,
12340,
13732,
4046,
687,
283,
27839,
4149,
15,
17233,
51,
2161,
15,
4222,
15,
2890,
22719,
14,
17715,
7,
543,
486,
2143,
67,
14,
647,
14,
199,
199,
624,
23662,
199,
199,
646,
6010,
199,
199,
5680,
13732,
15913,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
2550,
12,
2991,
63,
1130,
9,
339,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
2550,
12,
12796,
63,
1224,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
277,
14,
2550,
12,
2991,
63,
1130,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
277,
14,
2550,
12,
12796,
63,
1224,
2788,
16,
61,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
1850,
22719,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
199,
199,
5680,
27368,
9672,
199,
199,
12796,
63,
1130,
275,
6010,
14,
1875,
63,
5582,
63,
807,
8,
1842,
8,
3912,
430,
199,
12796,
63,
1130,
14,
873,
2561,
272,
378,
88,
23686,
26,
378,
88,
383,
67,
23,
12,
258,
327,
221,
1948,
2678,
1578,
445,
1663,
15609,
272,
378,
88,
383,
2835,
26,
378,
88,
383,
3003,
12,
258,
327,
221,
1948,
2516,
1578,
738,
1663,
9680,
272,
378,
88,
383,
2564,
26,
378,
88,
383,
69,
25,
12,
258,
327,
221,
1948,
2516,
1578,
662,
1663,
8123,
272,
378,
88,
383,
2658,
26,
378,
88,
383,
69,
18,
12,
258,
327,
221,
1948,
2516,
1578,
437,
1663,
10040,
272,
378,
88,
30935,
26,
378,
88,
383,
69,
20,
12,
258,
327,
221,
1948,
2516,
1578,
437,
1663,
9680,
272,
378,
88,
383,
2426,
26,
378,
88,
10882,
70,
12,
258,
327,
221,
1948,
2516,
1578,
738,
1663,
24809,
16054,
272,
378,
88,
31743,
26,
378,
88,
32586,
12,
258,
327,
221,
1948,
2516,
1578,
445,
1663,
8123,
272,
378,
88,
383,
1555,
26,
378,
88,
383,
69,
23,
12,
258,
327,
221,
1948,
2516,
1578,
445,
1663,
15609,
272,
378,
88,
31419,
26,
378,
88,
29556,
12,
258,
327,
221,
1948,
2516,
1578,
491,
1663,
22755,
272,
378,
88,
383,
1407,
26,
378,
88,
383,
2871,
12,
258,
327,
221,
1948,
2516,
1578,
662,
1663,
9680,
272,
378,
88,
8662,
65,
26,
378,
88,
614,
1400,
12,
258,
327,
221,
1948,
2678,
1578,
593,
1663,
5681,
8123,
272,
378,
88,
8662,
66,
26,
378,
88,
614,
2869,
12,
258,
327,
221,
1948,
2516,
1578,
593,
1663,
5681,
8123,
272,
378,
88,
8662,
67,
26,
378,
88,
383,
1024,
12,
258,
327,
221,
1948,
2516,
1578,
473,
1663,
10040,
272,
378,
88,
8662,
68,
26,
378,
88,
614,
1965,
12,
258,
327,
221,
1948,
2678,
1578,
3107,
1663,
8123,
272,
378,
88,
8662,
69,
26,
378,
88,
383,
67,
20,
12,
258,
327,
221,
1948,
2678,
1578,
437,
1663,
9680,
272,
378,
88,
8662,
70,
26,
378,
88,
614,
1690,
12,
258,
327,
221,
1948,
2678,
1578,
445,
1663,
8123,
272,
378,
88,
28875,
26,
378,
88,
383,
67,
25,
12,
258,
327,
221,
1948,
2678,
1578,
662,
1663,
8123,
272,
378,
88,
383,
3328,
26,
378,
88,
614,
1355,
12,
258,
327,
221,
1948,
2678,
1578,
491,
1663,
8123,
272,
378,
88,
383,
2942,
26,
378,
88,
13264,
65,
12,
258,
327,
221,
1948,
2516,
1578,
491,
1663,
8123,
272,
378,
88,
383,
3129,
26,
378,
88,
383,
70,
20,
12,
258,
327,
221,
1948,
2516,
1578,
593,
1663,
10040,
272,
378,
88,
383,
2635,
26,
378,
88,
383,
70,
22,
12,
258,
327,
221,
1948,
2516,
1578,
593,
1663,
9680,
272,
378,
88,
383,
2720,
26,
378,
88,
13264,
68,
12,
258,
327,
221,
1948,
2678,
1578,
491,
1663,
17913,
272,
378,
88,
383,
2534,
26,
378,
88,
13264,
69,
12,
258,
327,
221,
1948,
2516,
1578,
491,
1663,
17913,
272,
378,
88,
383,
2576,
26,
378,
88,
11164,
65,
12,
258,
327,
221,
1948,
2678,
1578,
428,
1663,
8123,
272,
378,
88,
383,
2905,
26,
378,
88,
11164,
66,
12,
258,
327,
221,
1948,
2516,
1578,
428,
1663,
8123,
272,
378,
88,
29660,
26,
378,
88,
383,
68,
22,
12,
258,
327,
221,
1948,
2678,
1578,
593,
1663,
9680,
272,
378,
88,
8581,
65,
26,
378,
88,
383,
3833,
12,
258,
327,
221,
1948,
2678,
1578,
738,
1663,
9680,
272,
378,
88,
8581,
66,
26,
378,
88,
614,
772,
12,
258,
327,
221,
1948,
2678,
1578,
377,
1663,
17913,
272,
378,
88,
8581,
67,
26,
378,
88,
614,
2182,
12,
258,
327,
221,
1948,
2516,
1578,
377,
1663,
17913,
272,
378,
88,
8581,
68,
26,
378,
88,
614,
2953,
12,
258,
327,
221,
1948,
2678,
1578,
491,
1663,
22755,
272,
378,
88,
8581,
69,
26,
378,
88,
383,
68,
23,
12,
258,
327,
221,
24895,
1772,
17939,
5056,
272,
378,
88,
8581,
70,
26,
378,
88,
9523,
68,
12,
258,
327,
221,
1948,
2516,
1578,
445,
1663,
17913,
272,
378,
88,
383,
65,
16,
26,
378,
88,
383,
69,
17,
12,
258,
327,
221,
1948,
2516,
1578,
437,
1663,
8123,
272,
378,
88,
383,
65,
17,
26,
378,
88,
383,
379,
12,
258,
327,
221,
1948,
2516,
1578,
473,
1663,
8123,
272,
378,
88,
383,
65,
18,
26,
378,
88,
383,
70,
19,
12,
258,
327,
221,
1948,
2516,
1578,
593,
1663,
8123,
272,
378,
88,
383,
65,
19,
26,
378,
88,
383,
667,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ehashman/oh-mainline
|
vendor/packages/python-social-auth/social/apps/django_app/middleware.py
|
70
|
2285
|
# -*- coding: utf-8 -*-
import six
from django.conf import settings
from django.contrib import messages
from django.contrib.messages.api import MessageFailure
from django.shortcuts import redirect
from django.utils.http import urlquote
from social.exceptions import SocialAuthBaseException
from social.utils import social_logger
class SocialAuthExceptionMiddleware(object):
"""Middleware that handles Social Auth AuthExceptions by providing the user
with a message, logging an error, and redirecting to some next location.
By default, the exception message itself is sent to the user and they are
redirected to the location specified in the SOCIAL_AUTH_LOGIN_ERROR_URL
setting.
This middleware can be extended by overriding the get_message or
get_redirect_uri methods, which each accept request and exception.
"""
def process_exception(self, request, exception):
strategy = getattr(request, 'social_strategy', None)
if strategy is None or self.raise_exception(request, exception):
return
if isinstance(exception, SocialAuthBaseException):
backend = getattr(request, 'backend', None)
backend_name = getattr(backend, 'name', 'unknown-backend')
message = self.get_message(request, exception)
social_logger.error(message)
url = self.get_redirect_uri(request, exception)
try:
messages.error(request, message,
extra_tags='social-auth ' + backend_name)
except MessageFailure:
url += ('?' in url and '&' or '?') + \
'message={0}&backend={1}'.format(urlquote(message),
backend_name)
return redirect(url)
def raise_exception(self, request, exception):
strategy = getattr(request, 'social_strategy', None)
if strategy is not None:
return strategy.setting('RAISE_EXCEPTIONS', settings.DEBUG)
def get_message(self, request, exception):
return six.text_type(exception)
def get_redirect_uri(self, request, exception):
strategy = getattr(request, 'social_strategy', None)
return strategy.setting('LOGIN_ERROR_URL')
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
3816,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
492,
3788,
199,
504,
1639,
14,
2828,
14,
3431,
14,
1246,
492,
6430,
6782,
199,
504,
1639,
14,
17469,
492,
4660,
199,
504,
1639,
14,
1208,
14,
1014,
492,
1166,
3513,
199,
199,
504,
20295,
14,
3924,
492,
2002,
7180,
2817,
29900,
199,
504,
20295,
14,
1208,
492,
20295,
63,
2921,
421,
199,
533,
2002,
7180,
2817,
1726,
6608,
8,
785,
304,
272,
408,
6608,
626,
10022,
2002,
7180,
3590,
3590,
16836,
701,
13070,
314,
922,
272,
543,
282,
1245,
12,
2050,
376,
1125,
12,
436,
4660,
316,
370,
2005,
2163,
2909,
14,
339,
4885,
849,
12,
314,
1919,
1245,
6337,
365,
4847,
370,
314,
922,
436,
2985,
787,
272,
20884,
370,
314,
2909,
2013,
315,
314,
3562,
21212,
63,
5580,
63,
17208,
63,
3170,
63,
2632,
272,
4260,
14,
339,
961,
10816,
883,
506,
9243,
701,
18972,
314,
664,
63,
1188,
503,
272,
664,
63,
4876,
63,
2302,
3102,
12,
1314,
1924,
4729,
1056,
436,
1919,
14,
272,
408,
272,
347,
2112,
63,
1971,
8,
277,
12,
1056,
12,
1919,
304,
267,
10054,
275,
2519,
8,
1069,
12,
283,
13574,
63,
8590,
297,
488,
9,
267,
340,
10054,
365,
488,
503,
291,
14,
3730,
63,
1971,
8,
1069,
12,
1919,
304,
288,
372,
398,
340,
1228,
8,
1971,
12,
2002,
7180,
2817,
29900,
304,
288,
4865,
275,
2519,
8,
1069,
12,
283,
4620,
297,
488,
9,
288,
4865,
63,
354,
275,
2519,
8,
4620,
12,
283,
354,
297,
283,
5187,
13,
4620,
358,
953,
1245,
275,
291,
14,
362,
63,
1188,
8,
1069,
12,
1919,
9,
288,
20295,
63,
2921,
14,
705,
8,
1188,
9,
953,
1166,
275,
291,
14,
362,
63,
4876,
63,
2302,
8,
1069,
12,
1919,
9,
288,
862,
26,
355,
3788,
14,
705,
8,
1069,
12,
1245,
12,
3044,
2402,
63,
2969,
534,
13574,
13,
1178,
283,
435,
4865,
63,
354,
9,
288,
871,
6430,
6782,
26,
355,
1166,
847,
661,
14069,
315,
1166,
436,
29285,
503,
8720,
358,
435,
971,
2432,
283,
1188,
3126,
16,
93,
6,
4620,
3126,
17,
5285,
908,
8,
633,
3513,
8,
1188,
395,
9144,
4865,
63,
354,
9,
288,
372,
4660,
8,
633,
9,
339,
347,
746,
63,
1971,
8,
277,
12,
1056,
12,
1919,
304,
267,
10054,
275,
2519,
8,
1069,
12,
283,
13574,
63,
8590,
297,
488,
9,
267,
340,
10054,
365,
440,
488,
26,
288,
372,
10054,
14,
6031,
360,
2847,
4971,
63,
25054,
297,
2202,
14,
5287,
9,
339,
347,
664,
63,
1188,
8,
277,
12,
1056,
12,
1919,
304,
267,
372,
3816,
14,
505,
63,
466,
8,
1971,
9,
339,
347,
664,
63,
4876,
63,
2302,
8,
277,
12,
1056,
12,
1919,
304,
267,
10054,
275,
2519,
8,
1069,
12,
283,
13574,
63,
8590,
297,
488,
9,
267,
372,
10054,
14,
6031,
360,
17208,
63,
3170,
63,
2632,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
3816,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
492,
3788,
199,
504,
1639,
14,
2828,
14,
3431,
14,
1246,
492,
6430,
6782,
199,
504,
1639,
14,
17469,
492,
4660,
199,
504,
1639,
14,
1208,
14,
1014,
492,
1166,
3513,
199,
199,
504,
20295,
14,
3924,
492,
2002,
7180,
2817,
29900,
199,
504,
20295,
14,
1208,
492,
20295,
63,
2921,
421,
199,
533,
2002,
7180,
2817,
1726,
6608,
8,
785,
304,
272,
408,
6608,
626,
10022,
2002,
7180,
3590,
3590,
16836,
701,
13070,
314,
922,
272,
543,
282,
1245,
12,
2050,
376,
1125,
12,
436,
4660,
316,
370,
2005,
2163,
2909,
14,
339,
4885,
849,
12,
314,
1919,
1245,
6337,
365,
4847,
370,
314,
922,
436,
2985,
787,
272,
20884,
370,
314,
2909,
2013,
315,
314,
3562,
21212,
63,
5580,
63,
17208,
63,
3170,
63,
2632,
272,
4260,
14,
339,
961,
10816,
883,
506,
9243,
701,
18972,
314,
664,
63,
1188,
503,
272,
664,
63,
4876,
63,
2302,
3102,
12,
1314,
1924,
4729,
1056,
436,
1919,
14,
272,
408,
272,
347,
2112,
63,
1971,
8,
277,
12,
1056,
12,
1919,
304,
267,
10054,
275,
2519,
8,
1069,
12,
283,
13574,
63,
8590,
297,
488,
9,
267,
340,
10054,
365,
488,
503,
291,
14,
3730,
63,
1971,
8,
1069,
12,
1919,
304,
288,
372,
398,
340,
1228,
8,
1971,
12,
2002,
7180,
2817,
29900,
304,
288,
4865,
275,
2519,
8,
1069,
12,
283,
4620,
297,
488,
9,
288,
4865,
63,
354,
275,
2519,
8,
4620,
12,
283,
354,
297,
283,
5187,
13,
4620,
358,
953,
1245,
275,
291,
14,
362,
63,
1188,
8,
1069,
12,
1919,
9,
288,
20295,
63,
2921,
14,
705,
8,
1188,
9,
953,
1166,
275,
291,
14,
362,
63,
4876,
63,
2302,
8,
1069,
12,
1919,
9,
288,
862,
26,
355,
3788,
14,
705,
8,
1069,
12,
1245,
12,
3044,
2402,
63,
2969,
534,
13574,
13,
1178,
283,
435,
4865,
63,
354,
9,
288,
871,
6430,
6782,
26,
355,
1166,
847,
661,
14069,
315,
1166,
436,
29285,
503,
8720,
358,
435,
971,
2432,
283,
1188,
3126,
16,
93,
6,
4620,
3126,
17,
5285,
908,
8,
633,
3513,
8,
1188,
395,
9144,
4865,
63,
354,
9,
288,
372,
4660,
8,
633,
9,
339,
347,
746,
63,
1971,
8,
277,
12,
1056,
12,
1919,
304,
267,
10054,
275,
2519,
8,
1069,
12,
283,
13574,
63,
8590,
297,
488,
9,
267,
340,
10054,
365,
440,
488,
26,
288,
372,
10054,
14,
6031,
360,
2847,
4971,
63,
25054,
297,
2202,
14,
5287,
9,
339,
347,
664,
63,
1188,
8,
277,
12,
1056,
12,
1919,
304,
267,
372,
3816,
14,
505,
63,
466,
8,
1971,
9,
339,
347,
664,
63,
4876,
63,
2302,
8,
277,
12,
1056,
12,
1919,
304,
267,
10054,
275,
2519,
8,
1069,
12,
283,
13574,
63,
8590,
297,
488,
9,
267,
372,
10054,
14,
6031,
360,
17208,
63,
3170,
63,
2632,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ssh-odoo/psd-tools
|
tests/test_layer_effects.py
|
5
|
3253
|
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
import pytest
from .utils import decode_psd
from psd_tools.constants import BlendMode
psd = decode_psd('layer_params.psd')
layer_records = psd.layer_and_mask_data.layers.layer_records
EFFECTS_COUNT = (
(1, 7),
(2, 7)
)
EFFECTS_PARAMS = (
(1, 1, 'enabled', True),
(1, 2, 'enabled', False),
(1, 3, 'enabled', False),
(1, 4, 'enabled', False),
(1, 5, 'enabled', True),
(1, 6, 'enabled', False),
(2, 1, 'enabled', True),
(2, 2, 'enabled', False),
(2, 3, 'enabled', True),
(2, 4, 'enabled', False),
(2, 5, 'enabled', False),
(2, 6, 'enabled', False),
(1, 1, 'distance', 65536 * 5),
(2, 1, 'distance', 65536 * 30),
(1, 3, 'blend_mode', BlendMode.SCREEN),
(2, 3, 'blend_mode', BlendMode.HARD_LIGHT),
(1, 3, 'blur', 65536 * 5),
(2, 3, 'blur', 65536 * 40),
(1, 5, 'bevel_style', 4),
(2, 5, 'bevel_style', 2)
)
OBJECT_BASED_EFFECTS_PARAMS = (
(1, b'DrSh', b'Md ', None, b'Nrml'),
(1, b'DrSh', b'Dstn', None, 5.0),
(1, b'DrSh', b'Ckmt', None, 0.0),
(1, b'DrSh', b'blur', None, 5.0),
(1, b'DrSh', b'TrnS', b'Nm ', '$$$/Contours/Defaults/Gaussian=Gaussian'),
(1, b'ebbl', b'bvlS', None, b'PlEb'),
(1, b'ebbl', b'hglM', None, b'Scrn'),
(1, b'ebbl', b'useShape', None, False),
(1, b'ebbl', b'useTexture', None, False),
(1, b'FrFX', b'Sz ', None, 4.0),
(1, b'FrFX', b'PntT', None, b'GrFl'),
(1, b'FrFX', b'Type', None, b'Rdl '),
(1, b'FrFX', b'Algn', None, False),
(1, b'FrFX', b'Scl ', None, 93.0),
(2, b'DrSh', b'Md ', None, b'Nrml'),
(2, b'DrSh', b'Dstn', None, 30.0),
(2, b'DrSh', b'Ckmt', None, 50.0),
(2, b'DrSh', b'blur', None, 5.0),
(2, b'DrSh', b'TrnS', b'Nm ', 'Линейный'),
(2, b'OrGl', b'Md ', None, b'HrdL'),
(2, b'OrGl', b'blur', None, 40.0),
(2, b'OrGl', b'TrnS', b'Nm ', 'Заказная'),
(2, b'OrGl', b'AntA', None, True),
(2, b'OrGl', b'Inpr', None, 43.0)
)
@pytest.mark.parametrize(("layer_num", "count"), EFFECTS_COUNT)
def test_layer_effects_count(layer_num, count):
effects_info = layer_records[layer_num].tagged_blocks[1].data
assert effects_info.effects_count == count
@pytest.mark.parametrize(("layer_num", "effect_num", "param_name", "param_value"), EFFECTS_PARAMS)
def test_layer_effect(layer_num, effect_num, param_name, param_value):
effects_list = layer_records[layer_num].tagged_blocks[1].data.effects_list
effect_info = effects_list[effect_num].effect_info
assert effect_info.__getattribute__(param_name) == param_value
@pytest.mark.parametrize(("layer_num", "effect_key", "param_name", "subparam_name", "param_value"), OBJECT_BASED_EFFECTS_PARAMS)
def test_object_based_layer_effect(layer_num, effect_key, param_name, subparam_name, param_value):
effects_dict = dict(layer_records[layer_num].tagged_blocks[0].data.descriptor.items)
effect_info = dict(effects_dict[effect_key].items)
if subparam_name is None:
assert effect_info[param_name].value == param_value
else:
effect_info = dict(effect_info[param_name].items)
assert effect_info[subparam_name].value == param_value
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
646,
4613,
199,
199,
504,
1275,
1208,
492,
4849,
63,
31600,
199,
504,
299,
3893,
63,
2537,
14,
5559,
492,
699,
12944,
1385,
421,
199,
31600,
275,
4849,
63,
31600,
360,
1897,
63,
1162,
14,
31600,
358,
199,
1897,
63,
6502,
275,
299,
3893,
14,
1897,
63,
460,
63,
2629,
63,
576,
14,
4359,
14,
1897,
63,
6502,
199,
199,
29512,
3582,
51,
63,
8760,
275,
334,
272,
334,
17,
12,
1520,
395,
272,
334,
18,
12,
1520,
9,
199,
9,
199,
199,
29512,
3582,
51,
63,
17978,
275,
334,
272,
334,
17,
12,
413,
12,
283,
3827,
297,
715,
395,
272,
334,
17,
12,
499,
12,
283,
3827,
297,
756,
395,
272,
334,
17,
12,
650,
12,
283,
3827,
297,
756,
395,
272,
334,
17,
12,
841,
12,
283,
3827,
297,
756,
395,
272,
334,
17,
12,
959,
12,
283,
3827,
297,
715,
395,
272,
334,
17,
12,
1227,
12,
283,
3827,
297,
756,
395,
339,
334,
18,
12,
413,
12,
283,
3827,
297,
715,
395,
272,
334,
18,
12,
499,
12,
283,
3827,
297,
756,
395,
272,
334,
18,
12,
650,
12,
283,
3827,
297,
715,
395,
272,
334,
18,
12,
841,
12,
283,
3827,
297,
756,
395,
272,
334,
18,
12,
959,
12,
283,
3827,
297,
756,
395,
272,
334,
18,
12,
1227,
12,
283,
3827,
297,
756,
395,
339,
334,
17,
12,
413,
12,
283,
5590,
297,
25980,
627,
959,
395,
272,
334,
18,
12,
413,
12,
283,
5590,
297,
25980,
627,
4233,
395,
339,
334,
17,
12,
650,
12,
283,
27163,
63,
632,
297,
699,
12944,
1385,
14,
25070,
395,
272,
334,
18,
12,
650,
12,
283,
27163,
63,
632,
297,
699,
12944,
1385,
14,
30322,
63,
21613,
395,
272,
334,
17,
12,
650,
12,
283,
3345,
300,
297,
25980,
627,
959,
395,
272,
334,
18,
12,
650,
12,
283,
3345,
300,
297,
25980,
627,
6335,
395,
339,
334,
17,
12,
959,
12,
283,
1235,
1090,
63,
2487,
297,
841,
395,
272,
334,
18,
12,
959,
12,
283,
1235,
1090,
63,
2487,
297,
499,
9,
199,
9,
199,
199,
9868,
63,
5825,
36,
63,
29512,
3582,
51,
63,
17978,
275,
334,
272,
334,
17,
12,
330,
7,
21733,
2662,
297,
330,
7,
45,
68,
221,
1656,
488,
12,
330,
7,
46,
16300,
659,
272,
334,
17,
12,
330,
7,
21733,
2662,
297,
330,
7,
31413,
78,
297,
488,
12,
959,
14,
16,
395,
272,
334,
17,
12,
330,
7,
21733,
2662,
297,
330,
7,
35,
75,
2037,
297,
488,
12,
378,
14,
16,
395,
272,
334,
17,
12,
330,
7,
21733,
2662,
297,
330,
7,
3345,
300,
297,
488,
12,
959,
14,
16,
395,
272,
334,
17,
12,
330,
7,
21733,
2662,
297,
330,
7,
52,
11641,
51,
297,
330,
7,
46,
77,
221,
1656,
4505,
23174,
15,
714,
10808,
83,
15,
16986,
15,
26756,
29,
26756,
659,
339,
334,
17,
12,
330,
7,
69,
2501,
76,
297,
330,
7,
66,
7300,
51,
297,
488,
12,
330,
7,
3714,
37,
66,
659,
272,
334,
17,
12,
330,
7,
69,
2501,
76,
297,
330,
7,
72,
3528,
45,
297,
488,
12,
330,
7,
51,
1556,
78,
659,
272,
334,
17,
12,
330,
7,
69,
2501,
76,
297,
330,
7,
1180,
7238,
297,
488,
12,
756,
395,
272,
334,
17,
12,
330,
7,
69,
2501,
76,
297,
330,
7,
1180,
17165,
297,
488,
12,
756,
395,
339,
334,
17,
12,
330,
7,
13848,
22322,
297,
330,
7,
51,
90,
221,
1656,
488,
12,
841,
14,
16,
395,
272,
334,
17,
12,
330,
7,
13848,
22322,
297,
330,
7,
48,
343,
52,
297,
488,
12,
330,
7,
23765,
7579,
659,
272,
334,
17,
12,
330,
7,
13848,
22322,
297,
330,
7,
804,
297,
488,
12,
330,
7,
50,
5030,
17748,
272,
334,
17,
12,
330,
7,
13848,
22322,
297,
330,
7,
2439,
784,
297,
488,
12,
756,
395,
272,
334,
17,
12,
330,
7,
13848,
22322,
297,
330,
7,
51,
429,
1656,
488,
12,
18969,
14,
16,
395,
2378,
334,
18,
12,
330,
7,
21733,
2662,
297,
330,
7,
45,
68,
221,
1656,
488,
12,
330,
7,
46,
16300,
659,
272,
334,
18,
12,
330,
7,
21733,
2662,
297,
330,
7,
31413,
78,
297,
488,
12,
4233,
14,
16,
395,
272,
334,
18,
12,
330,
7,
21733,
2662,
297,
330,
7,
35,
75,
2037,
297,
488,
12,
5238,
14,
16,
395,
272,
334,
18,
12,
330,
7,
21733,
2662,
297,
330,
7,
3345,
300,
297,
488,
12,
959,
14,
16,
395,
272,
334,
18,
12,
330,
7,
21733,
2662,
297,
330,
7,
52,
11641,
51,
297,
330,
7,
46,
77,
221,
1656,
283,
141,
250,
27859,
15578,
118,
7592,
17445,
141,
118,
659,
339,
334,
18,
12,
330,
7,
2844,
17541,
297,
330,
7,
45,
68,
221,
1656,
488,
12,
330,
7,
40,
6883,
44,
659,
272,
334,
18,
12,
330,
7,
2844,
17541,
297,
330,
7,
3345,
300,
297,
488,
12,
6335,
14,
16,
395,
272,
334,
18,
12,
330,
7,
2844,
17541,
297,
330,
7,
52,
11641,
51,
297,
330,
7,
46,
77,
221,
1656,
283,
141,
246,
5657,
11487,
13111,
116,
7592,
5657,
14978,
659,
272,
334,
18,
12,
330,
7,
2844,
17541,
297,
330,
7,
31935,
33,
297,
488,
12,
715,
395,
272,
334,
18,
12,
330,
7,
2844,
17541,
297,
330,
7,
607,
2700,
297,
488,
12,
11851,
14,
16,
9,
199,
9,
421,
199,
32,
4462,
14,
1657,
14,
10396,
9313,
1897,
63,
1507,
401,
298,
835,
1288,
662,
1665,
3582,
51,
63,
8760,
9,
199,
318,
511,
63,
1897,
63,
27626,
63,
835,
8,
1897,
63,
1507,
12,
2338,
304,
272,
22414,
63,
815,
275,
4045,
63,
6502,
59,
1897,
63,
1507,
1055,
15679,
63,
4166,
59,
17,
1055,
576,
272,
702,
22414,
63,
815,
14,
27626,
63,
835,
508,
2338,
421,
199,
32,
4462,
14,
1657,
14,
10396,
9313,
1897,
63,
1507,
401,
298,
5881,
63,
1507,
401,
298,
635,
63,
354,
401,
298,
635,
63,
585,
1288,
662,
1665,
3582,
51,
63,
17978,
9,
199,
318,
511,
63,
1897,
63,
5881
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
646,
4613,
199,
199,
504,
1275,
1208,
492,
4849,
63,
31600,
199,
504,
299,
3893,
63,
2537,
14,
5559,
492,
699,
12944,
1385,
421,
199,
31600,
275,
4849,
63,
31600,
360,
1897,
63,
1162,
14,
31600,
358,
199,
1897,
63,
6502,
275,
299,
3893,
14,
1897,
63,
460,
63,
2629,
63,
576,
14,
4359,
14,
1897,
63,
6502,
199,
199,
29512,
3582,
51,
63,
8760,
275,
334,
272,
334,
17,
12,
1520,
395,
272,
334,
18,
12,
1520,
9,
199,
9,
199,
199,
29512,
3582,
51,
63,
17978,
275,
334,
272,
334,
17,
12,
413,
12,
283,
3827,
297,
715,
395,
272,
334,
17,
12,
499,
12,
283,
3827,
297,
756,
395,
272,
334,
17,
12,
650,
12,
283,
3827,
297,
756,
395,
272,
334,
17,
12,
841,
12,
283,
3827,
297,
756,
395,
272,
334,
17,
12,
959,
12,
283,
3827,
297,
715,
395,
272,
334,
17,
12,
1227,
12,
283,
3827,
297,
756,
395,
339,
334,
18,
12,
413,
12,
283,
3827,
297,
715,
395,
272,
334,
18,
12,
499,
12,
283,
3827,
297,
756,
395,
272,
334,
18,
12,
650,
12,
283,
3827,
297,
715,
395,
272,
334,
18,
12,
841,
12,
283,
3827,
297,
756,
395,
272,
334,
18,
12,
959,
12,
283,
3827,
297,
756,
395,
272,
334,
18,
12,
1227,
12,
283,
3827,
297,
756,
395,
339,
334,
17,
12,
413,
12,
283,
5590,
297,
25980,
627,
959,
395,
272,
334,
18,
12,
413,
12,
283,
5590,
297,
25980,
627,
4233,
395,
339,
334,
17,
12,
650,
12,
283,
27163,
63,
632,
297,
699,
12944,
1385,
14,
25070,
395,
272,
334,
18,
12,
650,
12,
283,
27163,
63,
632,
297,
699,
12944,
1385,
14,
30322,
63,
21613,
395,
272,
334,
17,
12,
650,
12,
283,
3345,
300,
297,
25980,
627,
959,
395,
272,
334,
18,
12,
650,
12,
283,
3345,
300,
297,
25980,
627,
6335,
395,
339,
334,
17,
12,
959,
12,
283,
1235,
1090,
63,
2487,
297,
841,
395,
272,
334,
18,
12,
959,
12,
283,
1235,
1090,
63,
2487,
297,
499,
9,
199,
9,
199,
199,
9868,
63,
5825,
36,
63,
29512,
3582,
51,
63,
17978,
275,
334,
272,
334,
17,
12,
330,
7,
21733,
2662,
297,
330,
7,
45,
68,
221,
1656,
488,
12,
330,
7,
46,
16300,
659,
272,
334,
17,
12,
330,
7,
21733,
2662,
297,
330,
7,
31413,
78,
297,
488,
12,
959,
14,
16,
395,
272,
334,
17,
12,
330,
7,
21733,
2662,
297,
330,
7,
35,
75,
2037,
297,
488,
12,
378,
14,
16,
395,
272,
334,
17,
12,
330,
7,
21733,
2662,
297,
330,
7,
3345,
300,
297,
488,
12,
959,
14,
16,
395,
272,
334,
17,
12,
330,
7,
21733,
2662,
297,
330,
7,
52,
11641,
51,
297,
330,
7,
46,
77,
221,
1656,
4505,
23174,
15,
714,
10808,
83,
15,
16986,
15,
26756,
29,
26756,
659,
339,
334,
17,
12,
330,
7,
69,
2501,
76,
297,
330,
7,
66,
7300,
51,
297,
488,
12,
330,
7,
3714,
37,
66,
659,
272,
334,
17,
12,
330,
7,
69,
2501,
76,
297,
330,
7,
72,
3528,
45,
297,
488,
12,
330,
7,
51,
1556,
78,
659,
272,
334,
17,
12,
330,
7,
69,
2501,
76,
297,
330,
7,
1180,
7238,
297,
488,
12,
756,
395,
272,
334,
17,
12,
330,
7,
69,
2501,
76,
297,
330,
7,
1180,
17165,
297,
488,
12,
756,
395,
339,
334,
17,
12,
330,
7,
13848,
22322,
297,
330,
7,
51,
90,
221,
1656,
488,
12,
841,
14,
16,
395,
272,
334,
17,
12,
330,
7,
13848,
22322,
297,
330,
7,
48,
343,
52,
297,
488,
12,
330,
7,
23765,
7579,
659,
272,
334,
17,
12,
330,
7,
13848,
22322,
297,
330,
7,
804,
297,
488,
12,
330,
7,
50,
5030,
17748,
272,
334,
17,
12,
330,
7,
13848,
22322,
297,
330,
7,
2439,
784,
297,
488,
12,
756,
395,
272,
334,
17,
12,
330,
7,
13848,
22322,
297,
330,
7,
51,
429,
1656,
488,
12,
18969,
14,
16,
395,
2378,
334,
18,
12,
330,
7,
21733,
2662,
297,
330,
7,
45,
68,
221,
1656,
488,
12,
330,
7,
46,
16300,
659,
272,
334,
18,
12,
330,
7,
21733,
2662,
297,
330,
7,
31413,
78,
297,
488,
12,
4233,
14,
16,
395,
272,
334,
18,
12,
330,
7,
21733,
2662,
297,
330,
7,
35,
75,
2037,
297,
488,
12,
5238,
14,
16,
395,
272,
334,
18,
12,
330,
7,
21733,
2662,
297,
330,
7,
3345,
300,
297,
488,
12,
959,
14,
16,
395,
272,
334,
18,
12,
330,
7,
21733,
2662,
297,
330,
7,
52,
11641,
51,
297,
330,
7,
46,
77,
221,
1656,
283,
141,
250,
27859,
15578,
118,
7592,
17445,
141,
118,
659,
339,
334,
18,
12,
330,
7,
2844,
17541,
297,
330,
7,
45,
68,
221,
1656,
488,
12,
330,
7,
40,
6883,
44,
659,
272,
334,
18,
12,
330,
7,
2844,
17541,
297,
330,
7,
3345,
300,
297,
488,
12,
6335,
14,
16,
395,
272,
334,
18,
12,
330,
7,
2844,
17541,
297,
330,
7,
52,
11641,
51,
297,
330,
7,
46,
77,
221,
1656,
283,
141,
246,
5657,
11487,
13111,
116,
7592,
5657,
14978,
659,
272,
334,
18,
12,
330,
7,
2844,
17541,
297,
330,
7,
31935,
33,
297,
488,
12,
715,
395,
272,
334,
18,
12,
330,
7,
2844,
17541,
297,
330,
7,
607,
2700,
297,
488,
12,
11851,
14,
16,
9,
199,
9,
421,
199,
32,
4462,
14,
1657,
14,
10396,
9313,
1897,
63,
1507,
401,
298,
835,
1288,
662,
1665,
3582,
51,
63,
8760,
9,
199,
318,
511,
63,
1897,
63,
27626,
63,
835,
8,
1897,
63,
1507,
12,
2338,
304,
272,
22414,
63,
815,
275,
4045,
63,
6502,
59,
1897,
63,
1507,
1055,
15679,
63,
4166,
59,
17,
1055,
576,
272,
702,
22414,
63,
815,
14,
27626,
63,
835,
508,
2338,
421,
199,
32,
4462,
14,
1657,
14,
10396,
9313,
1897,
63,
1507,
401,
298,
5881,
63,
1507,
401,
298,
635,
63,
354,
401,
298,
635,
63,
585,
1288,
662,
1665,
3582,
51,
63,
17978,
9,
199,
318,
511,
63,
1897,
63,
5881,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
javachengwc/hue
|
desktop/core/ext-py/cx_Oracle-5.1.2/test/Cursor.py
|
34
|
11221
|
"""Module for testing cursor objects."""
import cx_Oracle
import sys
class TestCursor(BaseTestCase):
def testExecuteNoArgs(self):
"""test executing a statement without any arguments"""
result = self.cursor.execute("begin null; end;")
self.failUnlessEqual(result, None)
def testExecuteNoStatementWithArgs(self):
"""test executing a None statement with bind variables"""
self.failUnlessRaises(cx_Oracle.ProgrammingError, self.cursor.execute,
None, x = 5)
def testExecuteEmptyKeywordArgs(self):
"""test executing a statement with args and empty keyword args"""
simpleVar = self.cursor.var(cx_Oracle.NUMBER)
args = [simpleVar]
kwArgs = {}
result = self.cursor.execute("begin :1 := 25; end;", args, **kwArgs)
self.failUnlessEqual(result, None)
self.failUnlessEqual(simpleVar.getvalue(), 25)
def testExecuteKeywordArgs(self):
"""test executing a statement with keyword arguments"""
simpleVar = self.cursor.var(cx_Oracle.NUMBER)
result = self.cursor.execute("begin :p_Value := 5; end;",
p_Value = simpleVar)
self.failUnlessEqual(result, None)
self.failUnlessEqual(simpleVar.getvalue(), 5)
def testExecuteDictionaryArg(self):
"""test executing a statement with a dictionary argument"""
simpleVar = self.cursor.var(cx_Oracle.NUMBER)
dictArg = { "p_Value" : simpleVar }
result = self.cursor.execute("begin :p_Value := 10; end;", dictArg)
self.failUnlessEqual(result, None)
self.failUnlessEqual(simpleVar.getvalue(), 10)
def testExecuteMultipleMethod(self):
"""test executing a statement with both a dict arg and keyword args"""
simpleVar = self.cursor.var(cx_Oracle.NUMBER)
dictArg = { "p_Value" : simpleVar }
self.failUnlessRaises(cx_Oracle.InterfaceError, self.cursor.execute,
"begin :p_Value := 15; end;", dictArg, p_Value = simpleVar)
def testExecuteAndModifyArraySize(self):
"""test executing a statement and then changing the array size"""
self.cursor.execute("select IntCol from TestNumbers")
self.cursor.arraysize = 20
self.failUnlessEqual(len(self.cursor.fetchall()), 10)
def testCallProc(self):
"""test executing a stored procedure"""
var = self.cursor.var(cx_Oracle.NUMBER)
results = self.cursor.callproc("proc_Test", ("hi", 5, var))
self.failUnlessEqual(results, ["hi", 10, 2.0])
def testCallProcNoArgs(self):
"""test executing a stored procedure without any arguments"""
results = self.cursor.callproc("proc_TestNoArgs")
self.failUnlessEqual(results, [])
def testCallFunc(self):
"""test executing a stored function"""
results = self.cursor.callfunc("func_Test", cx_Oracle.NUMBER,
("hi", 5))
self.failUnlessEqual(results, 7)
def testCallFuncNoArgs(self):
"""test executing a stored function without any arguments"""
results = self.cursor.callfunc("func_TestNoArgs", cx_Oracle.NUMBER)
self.failUnlessEqual(results, 712)
def testExecuteManyByName(self):
"""test executing a statement multiple times (named args)"""
self.cursor.execute("truncate table TestExecuteMany")
rows = [ { "value" : n } for n in range(250) ]
self.cursor.arraysize = 100
statement = "insert into TestExecuteMany (IntCol) values (:value)"
self.cursor.executemany(statement, rows)
self.connection.commit()
self.cursor.execute("select count(*) from TestExecuteMany")
count, = self.cursor.fetchone()
self.failUnlessEqual(count, len(rows))
def testExecuteManyByPosition(self):
"""test executing a statement multiple times (positional args)"""
self.cursor.execute("truncate table TestExecuteMany")
rows = [ [n] for n in range(230) ]
self.cursor.arraysize = 100
statement = "insert into TestExecuteMany (IntCol) values (:1)"
self.cursor.executemany(statement, rows)
self.connection.commit()
self.cursor.execute("select count(*) from TestExecuteMany")
count, = self.cursor.fetchone()
self.failUnlessEqual(count, len(rows))
def testExecuteManyWithPrepare(self):
"""test executing a statement multiple times (with prepare)"""
self.cursor.execute("truncate table TestExecuteMany")
rows = [ [n] for n in range(225) ]
self.cursor.arraysize = 100
statement = "insert into TestExecuteMany (IntCol) values (:1)"
self.cursor.prepare(statement)
self.cursor.executemany(None, rows)
self.connection.commit()
self.cursor.execute("select count(*) from TestExecuteMany")
count, = self.cursor.fetchone()
self.failUnlessEqual(count, len(rows))
def testExecuteManyWithRebind(self):
"""test executing a statement multiple times (with rebind)"""
self.cursor.execute("truncate table TestExecuteMany")
rows = [ [n] for n in range(235) ]
self.cursor.arraysize = 100
statement = "insert into TestExecuteMany (IntCol) values (:1)"
self.cursor.executemany(statement, rows[:50])
self.cursor.executemany(statement, rows[50:])
self.connection.commit()
self.cursor.execute("select count(*) from TestExecuteMany")
count, = self.cursor.fetchone()
self.failUnlessEqual(count, len(rows))
def testExecuteManyWithResize(self):
"""test executing a statement multiple times (with resize)"""
self.cursor.execute("truncate table TestExecuteMany")
rows = [ ( 1, "First" ),
( 2, "Second" ),
( 3, "Third" ),
( 4, "Fourth" ),
( 5, "Fifth" ),
( 6, "Sixth" ),
( 7, "Seventh" ) ]
self.cursor.bindarraysize = 5
self.cursor.setinputsizes(int, 100)
sql = "insert into TestExecuteMany (IntCol, StringCol) values (:1, :2)"
self.cursor.executemany(sql, rows)
var = self.cursor.bindvars[1]
self.cursor.execute("select count(*) from TestExecuteMany")
count, = self.cursor.fetchone()
self.failUnlessEqual(count, len(rows))
self.failUnlessEqual(var.maxlength,
100 * self.connection.maxBytesPerCharacter)
def testExecuteManyWithExecption(self):
"""test executing a statement multiple times (with exception)"""
self.cursor.execute("truncate table TestExecuteMany")
rows = [ { "p_Value" : n } for n in (1, 2, 3, 2, 5) ]
statement = "insert into TestExecuteMany (IntCol) values (:p_Value)"
self.failUnlessRaises(cx_Oracle.DatabaseError, self.cursor.executemany,
statement, rows)
self.failUnlessEqual(self.cursor.rowcount, 3)
def testPrepare(self):
"""test preparing a statement and executing it multiple times"""
self.failUnlessEqual(self.cursor.statement, None)
statement = "begin :p_Value := :p_Value + 5; end;"
self.cursor.prepare(statement)
var = self.cursor.var(cx_Oracle.NUMBER)
self.failUnlessEqual(self.cursor.statement, statement)
var.setvalue(0, 2)
self.cursor.execute(None, p_Value = var)
self.failUnlessEqual(var.getvalue(), 7)
self.cursor.execute(None, p_Value = var)
self.failUnlessEqual(var.getvalue(), 12)
self.cursor.execute("begin :p_Value2 := 3; end;", p_Value2 = var)
self.failUnlessEqual(var.getvalue(), 3)
def testExceptionOnClose(self):
"confirm an exception is raised after closing a cursor"
self.cursor.close()
self.failUnlessRaises(cx_Oracle.InterfaceError, self.cursor.execute,
"select 1 from dual")
def testIterators(self):
"""test iterators"""
self.cursor.execute("""
select IntCol
from TestNumbers
where IntCol between 1 and 3
order by IntCol""")
rows = []
for row in self.cursor:
rows.append(row[0])
self.failUnlessEqual(rows, [1, 2, 3])
def testIteratorsInterrupted(self):
"""test iterators (with intermediate execute)"""
self.cursor.execute("truncate table TestExecuteMany")
self.cursor.execute("""
select IntCol
from TestNumbers
where IntCol between 1 and 3
order by IntCol""")
testIter = iter(self.cursor)
if sys.version_info[0] >= 3:
value, = next(testIter)
else:
value, = testIter.next()
self.cursor.execute("insert into TestExecuteMany (IntCol) values (1)")
if sys.version_info[0] >= 3:
self.failUnlessRaises(cx_Oracle.InterfaceError, next, testIter)
else:
self.failUnlessRaises(cx_Oracle.InterfaceError, testIter.next)
def testBindNames(self):
"""test that bindnames() works correctly."""
self.failUnlessRaises(cx_Oracle.ProgrammingError,
self.cursor.bindnames)
self.cursor.prepare("begin null; end;")
self.failUnlessEqual(self.cursor.bindnames(), [])
self.cursor.prepare("begin :retval := :inval + 5; end;")
self.failUnlessEqual(self.cursor.bindnames(), ["RETVAL", "INVAL"])
self.cursor.prepare("begin :retval := :a * :a + :b * :b; end;")
self.failUnlessEqual(self.cursor.bindnames(), ["RETVAL", "A", "B"])
self.cursor.prepare("begin :a := :b + :c + :d + :e + :f + :g + " + \
":h + :i + :j + :k + :l; end;")
self.failUnlessEqual(self.cursor.bindnames(),
["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"])
def testBadPrepare(self):
"""test that subsequent executes succeed after bad prepare"""
self.failUnlessRaises(cx_Oracle.DatabaseError,
self.cursor.execute,
"begin raise_application_error(-20000, 'this); end;")
self.cursor.execute("begin null; end;")
def testBadExecute(self):
"""test that subsequent fetches fail after bad execute"""
self.failUnlessRaises(cx_Oracle.DatabaseError,
self.cursor.execute, "select y from dual")
self.failUnlessRaises(cx_Oracle.InterfaceError,
self.cursor.fetchall)
def testSetInputSizesMultipleMethod(self):
"""test setting input sizes with both positional and keyword args"""
self.failUnlessRaises(cx_Oracle.InterfaceError,
self.cursor.setinputsizes, 5, x = 5)
def testSetInputSizesByPosition(self):
"""test setting input sizes with positional args"""
var = self.cursor.var(cx_Oracle.STRING, 100)
self.cursor.setinputsizes(None, 5, None, 10, None, cx_Oracle.NUMBER)
self.cursor.execute("""
begin
:1 := :2 || to_char(:3) || :4 || to_char(:5) || to_char(:6);
end;""", [var, 'test_', 5, '_second_', 3, 7])
self.failUnlessEqual(var.getvalue(), "test_5_second_37")
|
apache-2.0
|
[
624,
2377,
367,
5343,
3920,
2251,
1041,
199,
199,
646,
17280,
63,
21202,
199,
646,
984,
199,
199,
533,
1379,
8993,
8,
20760,
304,
339,
347,
511,
12049,
27099,
8,
277,
304,
267,
408,
396,
14043,
282,
5164,
1928,
1263,
2368,
624,
267,
754,
275,
291,
14,
3937,
14,
2526,
480,
5037,
2973,
27,
1284,
15027,
267,
291,
14,
14247,
8,
1099,
12,
488,
9,
339,
347,
511,
12049,
1944,
15173,
3007,
6213,
8,
277,
304,
267,
408,
396,
14043,
282,
488,
5164,
543,
5398,
2860,
624,
267,
291,
14,
7589,
1811,
8,
11859,
63,
21202,
14,
11411,
547,
12,
291,
14,
3937,
14,
2526,
12,
355,
488,
12,
671,
275,
959,
9,
339,
347,
511,
12049,
4699,
10650,
6213,
8,
277,
304,
267,
408,
396,
14043,
282,
5164,
543,
1249,
436,
2701,
4252,
1249,
624,
267,
3486,
5894,
275,
291,
14,
3937,
14,
1391,
8,
11859,
63,
21202,
14,
9190,
9,
267,
1249,
275,
359,
4129,
5894,
61,
267,
4775,
6213,
275,
1052,
267,
754,
275,
291,
14,
3937,
14,
2526,
480,
5037,
520,
17,
12952,
5661,
27,
1284,
17259,
1249,
12,
1011,
829,
6213,
9,
267,
291,
14,
14247,
8,
1099,
12,
488,
9,
267,
291,
14,
14247,
8,
4129,
5894,
14,
7150,
1062,
5661,
9,
339,
347,
511,
12049,
10650,
6213,
8,
277,
304,
267,
408,
396,
14043,
282,
5164,
543,
4252,
2368,
624,
267,
3486,
5894,
275,
291,
14,
3937,
14,
1391,
8,
11859,
63,
21202,
14,
9190,
9,
267,
754,
275,
291,
14,
3937,
14,
2526,
480,
5037,
520,
80,
63,
1110,
12952,
959,
27,
1284,
17259,
355,
299,
63,
1110,
275,
3486,
5894,
9,
267,
291,
14,
14247,
8,
1099,
12,
488,
9,
267,
291,
14,
14247,
8,
4129,
5894,
14,
7150,
1062,
959,
9,
339,
347,
511,
12049,
11728,
6373,
8,
277,
304,
267,
408,
396,
14043,
282,
5164,
543,
282,
2600,
1423,
624,
267,
3486,
5894,
275,
291,
14,
3937,
14,
1391,
8,
11859,
63,
21202,
14,
9190,
9,
267,
1211,
6373,
275,
469,
298,
80,
63,
1110,
2,
520,
3486,
5894,
789,
267,
754,
275,
291,
14,
3937,
14,
2526,
480,
5037,
520,
80,
63,
1110,
12952,
1616,
27,
1284,
17259,
1211,
6373,
9,
267,
291,
14,
14247,
8,
1099,
12,
488,
9,
267,
291,
14,
14247,
8,
4129,
5894,
14,
7150,
1062,
1616,
9,
339,
347,
511,
12049,
8433,
3767,
8,
277,
304,
267,
408,
396,
14043,
282,
5164,
543,
3865,
282,
1211,
1680,
436,
4252,
1249,
624,
267,
3486,
5894,
275,
291,
14,
3937,
14,
1391,
8,
11859,
63,
21202,
14,
9190,
9,
267,
1211,
6373,
275,
469,
298,
80,
63,
1110,
2,
520,
3486,
5894,
789,
267,
291,
14,
7589,
1811,
8,
11859,
63,
21202,
14,
4267,
547,
12,
291,
14,
3937,
14,
2526,
12,
355,
298,
5037,
520,
80,
63,
1110,
12952,
4114,
27,
1284,
17259,
1211,
6373,
12,
299,
63,
1110,
275,
3486,
5894,
9,
339,
347,
511,
12049,
3325,
18357,
3836,
2320,
8,
277,
304,
267,
408,
396,
14043,
282,
5164,
436,
2066,
13729,
314,
1625,
1568,
624,
267,
291,
14,
3937,
14,
2526,
480,
2416,
9805,
2001,
687,
1379,
22951,
531,
267,
291,
14,
3937,
14,
1144,
890,
275,
3388,
267,
291,
14,
14247,
8,
552,
8,
277,
14,
3937,
14,
10174,
4000,
1616,
9,
339,
347,
511,
2176,
15019,
8,
277,
304,
267,
408,
396,
14043,
282,
5489,
17782,
624,
267,
2729,
275,
291,
14,
3937,
14,
1391,
8,
11859,
63,
21202,
14,
9190,
9,
267,
2058,
275,
291,
14,
3937,
14,
1250,
4687,
480,
4687,
63,
774,
401,
1689,
5812,
401,
959,
12,
2729,
430,
267,
291,
14,
14247,
8,
2604,
12,
2097,
5812,
401,
1616,
12,
499,
14,
16,
566,
339,
347,
511,
2176,
15019,
27099,
8,
277,
304,
267,
408,
396,
14043,
282,
5489,
17782,
1928,
1263,
2368,
624,
267,
2058,
275,
291,
14,
3937,
14,
1250,
4687,
480,
4687,
63,
774,
27099,
531,
267,
291,
14,
14247,
8,
2604,
12,
3073,
339,
347,
511,
2176,
7465,
8,
277,
304,
267,
408,
396,
14043,
282,
5489,
805,
624,
267,
2058,
275,
291,
14,
3937,
14,
915,
276,
1097,
480,
1532,
63,
774,
401,
17280,
63,
21202,
14,
9190,
12,
355,
1689,
5812,
401,
959,
430,
267,
291,
14,
14247,
8,
2604,
12,
1520,
9,
339,
347,
511,
2176,
7465,
27099,
8,
277,
304,
267,
408,
396,
14043,
282,
5489,
805,
1928,
1263,
2368,
624,
267,
2058,
275,
291,
14,
3937,
14,
915,
276,
1097,
480,
1532,
63,
774,
27099,
401,
17280,
63,
21202,
14,
9190,
9,
267,
291,
14,
14247,
8,
2604,
12,
1520,
713,
9,
339,
347,
511,
12049,
4089,
11190,
8,
277,
304,
267,
408,
396,
14043,
282,
5164,
3663,
5431,
334,
4579,
1249,
9471,
267,
291,
14,
3937,
14,
2526,
480,
12517,
1817,
1379,
12049,
4089,
531,
267,
4730,
275,
359,
469,
298,
585,
2,
520,
302,
789,
367,
302,
315,
1425,
8,
7991,
9,
1622,
267,
291,
14,
3937,
14,
1144,
890,
275,
2948,
267,
5164,
275,
298,
3176,
1901,
1379,
12049,
4089,
334,
3241,
2001,
9,
1338,
18479,
585,
2924,
267,
291,
14,
3937,
14,
31162,
8,
6242,
12,
4730,
9,
267,
291,
14,
2105,
14,
3543,
342,
267,
291,
14,
3937,
14,
2526,
480,
2416,
2338,
21565,
687,
1379,
12049,
4089,
531,
267,
2338,
12,
275,
291,
14,
3937,
14,
11591,
342,
267,
291,
14,
14247,
8,
835,
12,
822,
8,
3838,
430,
339,
347,
511,
12049,
4089,
2175,
5625,
8,
277,
304,
267,
408,
396,
14043,
282,
5164,
3663,
5431,
334,
17867,
1249,
9471,
267,
291,
14,
3937,
14,
2526,
480,
12517,
1817,
1379,
12049,
4089,
531,
267,
4730,
275,
359,
359,
78,
61,
367,
302,
315,
1425,
8,
9687,
9,
1622,
267,
291,
14,
3937,
14,
1144,
890,
275,
2948,
267,
5164,
275,
298,
3176,
1901,
1379,
12049,
4089,
334,
3241,
2001,
9,
1338,
18479,
17,
2924,
267,
291,
14,
3937,
14,
31162,
8,
6242,
12,
4730,
9,
267,
291,
14,
2105,
14,
3543,
342,
267,
291,
14,
3937,
14,
2526,
480,
2416,
2338,
21565,
687,
1379,
12049,
4089,
531,
267,
2338,
12,
275,
291,
14,
3937,
14,
11591,
342,
267,
291,
14,
14247,
8,
835,
12,
822,
8,
3838,
430,
339,
347,
511,
12049,
4089
] |
[
2377,
367,
5343,
3920,
2251,
1041,
199,
199,
646,
17280,
63,
21202,
199,
646,
984,
199,
199,
533,
1379,
8993,
8,
20760,
304,
339,
347,
511,
12049,
27099,
8,
277,
304,
267,
408,
396,
14043,
282,
5164,
1928,
1263,
2368,
624,
267,
754,
275,
291,
14,
3937,
14,
2526,
480,
5037,
2973,
27,
1284,
15027,
267,
291,
14,
14247,
8,
1099,
12,
488,
9,
339,
347,
511,
12049,
1944,
15173,
3007,
6213,
8,
277,
304,
267,
408,
396,
14043,
282,
488,
5164,
543,
5398,
2860,
624,
267,
291,
14,
7589,
1811,
8,
11859,
63,
21202,
14,
11411,
547,
12,
291,
14,
3937,
14,
2526,
12,
355,
488,
12,
671,
275,
959,
9,
339,
347,
511,
12049,
4699,
10650,
6213,
8,
277,
304,
267,
408,
396,
14043,
282,
5164,
543,
1249,
436,
2701,
4252,
1249,
624,
267,
3486,
5894,
275,
291,
14,
3937,
14,
1391,
8,
11859,
63,
21202,
14,
9190,
9,
267,
1249,
275,
359,
4129,
5894,
61,
267,
4775,
6213,
275,
1052,
267,
754,
275,
291,
14,
3937,
14,
2526,
480,
5037,
520,
17,
12952,
5661,
27,
1284,
17259,
1249,
12,
1011,
829,
6213,
9,
267,
291,
14,
14247,
8,
1099,
12,
488,
9,
267,
291,
14,
14247,
8,
4129,
5894,
14,
7150,
1062,
5661,
9,
339,
347,
511,
12049,
10650,
6213,
8,
277,
304,
267,
408,
396,
14043,
282,
5164,
543,
4252,
2368,
624,
267,
3486,
5894,
275,
291,
14,
3937,
14,
1391,
8,
11859,
63,
21202,
14,
9190,
9,
267,
754,
275,
291,
14,
3937,
14,
2526,
480,
5037,
520,
80,
63,
1110,
12952,
959,
27,
1284,
17259,
355,
299,
63,
1110,
275,
3486,
5894,
9,
267,
291,
14,
14247,
8,
1099,
12,
488,
9,
267,
291,
14,
14247,
8,
4129,
5894,
14,
7150,
1062,
959,
9,
339,
347,
511,
12049,
11728,
6373,
8,
277,
304,
267,
408,
396,
14043,
282,
5164,
543,
282,
2600,
1423,
624,
267,
3486,
5894,
275,
291,
14,
3937,
14,
1391,
8,
11859,
63,
21202,
14,
9190,
9,
267,
1211,
6373,
275,
469,
298,
80,
63,
1110,
2,
520,
3486,
5894,
789,
267,
754,
275,
291,
14,
3937,
14,
2526,
480,
5037,
520,
80,
63,
1110,
12952,
1616,
27,
1284,
17259,
1211,
6373,
9,
267,
291,
14,
14247,
8,
1099,
12,
488,
9,
267,
291,
14,
14247,
8,
4129,
5894,
14,
7150,
1062,
1616,
9,
339,
347,
511,
12049,
8433,
3767,
8,
277,
304,
267,
408,
396,
14043,
282,
5164,
543,
3865,
282,
1211,
1680,
436,
4252,
1249,
624,
267,
3486,
5894,
275,
291,
14,
3937,
14,
1391,
8,
11859,
63,
21202,
14,
9190,
9,
267,
1211,
6373,
275,
469,
298,
80,
63,
1110,
2,
520,
3486,
5894,
789,
267,
291,
14,
7589,
1811,
8,
11859,
63,
21202,
14,
4267,
547,
12,
291,
14,
3937,
14,
2526,
12,
355,
298,
5037,
520,
80,
63,
1110,
12952,
4114,
27,
1284,
17259,
1211,
6373,
12,
299,
63,
1110,
275,
3486,
5894,
9,
339,
347,
511,
12049,
3325,
18357,
3836,
2320,
8,
277,
304,
267,
408,
396,
14043,
282,
5164,
436,
2066,
13729,
314,
1625,
1568,
624,
267,
291,
14,
3937,
14,
2526,
480,
2416,
9805,
2001,
687,
1379,
22951,
531,
267,
291,
14,
3937,
14,
1144,
890,
275,
3388,
267,
291,
14,
14247,
8,
552,
8,
277,
14,
3937,
14,
10174,
4000,
1616,
9,
339,
347,
511,
2176,
15019,
8,
277,
304,
267,
408,
396,
14043,
282,
5489,
17782,
624,
267,
2729,
275,
291,
14,
3937,
14,
1391,
8,
11859,
63,
21202,
14,
9190,
9,
267,
2058,
275,
291,
14,
3937,
14,
1250,
4687,
480,
4687,
63,
774,
401,
1689,
5812,
401,
959,
12,
2729,
430,
267,
291,
14,
14247,
8,
2604,
12,
2097,
5812,
401,
1616,
12,
499,
14,
16,
566,
339,
347,
511,
2176,
15019,
27099,
8,
277,
304,
267,
408,
396,
14043,
282,
5489,
17782,
1928,
1263,
2368,
624,
267,
2058,
275,
291,
14,
3937,
14,
1250,
4687,
480,
4687,
63,
774,
27099,
531,
267,
291,
14,
14247,
8,
2604,
12,
3073,
339,
347,
511,
2176,
7465,
8,
277,
304,
267,
408,
396,
14043,
282,
5489,
805,
624,
267,
2058,
275,
291,
14,
3937,
14,
915,
276,
1097,
480,
1532,
63,
774,
401,
17280,
63,
21202,
14,
9190,
12,
355,
1689,
5812,
401,
959,
430,
267,
291,
14,
14247,
8,
2604,
12,
1520,
9,
339,
347,
511,
2176,
7465,
27099,
8,
277,
304,
267,
408,
396,
14043,
282,
5489,
805,
1928,
1263,
2368,
624,
267,
2058,
275,
291,
14,
3937,
14,
915,
276,
1097,
480,
1532,
63,
774,
27099,
401,
17280,
63,
21202,
14,
9190,
9,
267,
291,
14,
14247,
8,
2604,
12,
1520,
713,
9,
339,
347,
511,
12049,
4089,
11190,
8,
277,
304,
267,
408,
396,
14043,
282,
5164,
3663,
5431,
334,
4579,
1249,
9471,
267,
291,
14,
3937,
14,
2526,
480,
12517,
1817,
1379,
12049,
4089,
531,
267,
4730,
275,
359,
469,
298,
585,
2,
520,
302,
789,
367,
302,
315,
1425,
8,
7991,
9,
1622,
267,
291,
14,
3937,
14,
1144,
890,
275,
2948,
267,
5164,
275,
298,
3176,
1901,
1379,
12049,
4089,
334,
3241,
2001,
9,
1338,
18479,
585,
2924,
267,
291,
14,
3937,
14,
31162,
8,
6242,
12,
4730,
9,
267,
291,
14,
2105,
14,
3543,
342,
267,
291,
14,
3937,
14,
2526,
480,
2416,
2338,
21565,
687,
1379,
12049,
4089,
531,
267,
2338,
12,
275,
291,
14,
3937,
14,
11591,
342,
267,
291,
14,
14247,
8,
835,
12,
822,
8,
3838,
430,
339,
347,
511,
12049,
4089,
2175,
5625,
8,
277,
304,
267,
408,
396,
14043,
282,
5164,
3663,
5431,
334,
17867,
1249,
9471,
267,
291,
14,
3937,
14,
2526,
480,
12517,
1817,
1379,
12049,
4089,
531,
267,
4730,
275,
359,
359,
78,
61,
367,
302,
315,
1425,
8,
9687,
9,
1622,
267,
291,
14,
3937,
14,
1144,
890,
275,
2948,
267,
5164,
275,
298,
3176,
1901,
1379,
12049,
4089,
334,
3241,
2001,
9,
1338,
18479,
17,
2924,
267,
291,
14,
3937,
14,
31162,
8,
6242,
12,
4730,
9,
267,
291,
14,
2105,
14,
3543,
342,
267,
291,
14,
3937,
14,
2526,
480,
2416,
2338,
21565,
687,
1379,
12049,
4089,
531,
267,
2338,
12,
275,
291,
14,
3937,
14,
11591,
342,
267,
291,
14,
14247,
8,
835,
12,
822,
8,
3838,
430,
339,
347,
511,
12049,
4089,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
lunyang/pylearn2
|
pylearn2/utils/tests/test_pooling.py
|
49
|
4239
|
"""Test pooling-related code in pooling.py"""
import numpy as np
from pylearn2.utils.pooling import pooling_matrix
from pylearn2.testing.skip import skip_if_no_scipy
def test_pooling_no_topology():
mat = pooling_matrix(4, 5)
assert mat.shape == (4, 20)
expected = np.array([[1] * 5 + [0] * 15,
[0] * 5 + [1] * 5 + [0] * 10,
[0] * 10 + [1] * 5 + [0] * 5,
[0] * 15 + [1] * 5])
assert np.all(mat == expected)
skip_if_no_scipy()
spmat = pooling_matrix(4, 5, sparse='csr')
assert np.all(spmat.todense() == expected)
def test_pooling_1d_topology():
mat = pooling_matrix(3, 4, 2)
assert mat.shape == (3, 8)
expected = np.array([[1, 1, 1, 1, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 1, 1, 1, 1]])
assert np.all(mat == expected)
skip_if_no_scipy()
spmat = pooling_matrix(3, 4, 2, sparse='csr')
assert np.all(spmat.todense() == expected)
def test_pooling_1d_topology_tuples():
mat = pooling_matrix((3,), (4,), (2,))
assert mat.shape == (3, 8)
expected = np.array([[1, 1, 1, 1, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 1, 1, 1, 1]])
assert np.all(mat == expected)
skip_if_no_scipy()
spmat = pooling_matrix(3, 4, 2, sparse='csr')
assert np.all(spmat.todense() == expected)
def test_pooling_2d_topology():
mat = pooling_matrix((3, 3), (2, 2), (1, 1))
assert mat.shape == (9, 16)
expected = np.zeros((9, 16))
maps = expected.reshape((3, 3, 4, 4))
maps[0, 0, 0:2, 0:2] = 1.
maps[1, 0, 1:3, 0:2] = 1.
maps[2, 0, 2:4, 0:2] = 1.
maps[0, 1, 0:2, 1:3] = 1.
maps[1, 1, 1:3, 1:3] = 1.
maps[2, 1, 2:4, 1:3] = 1.
maps[0, 2, 0:2, 2:4] = 1.
maps[1, 2, 1:3, 2:4] = 1.
maps[2, 2, 2:4, 2:4] = 1.
assert np.all(mat == expected)
skip_if_no_scipy()
spmat = pooling_matrix((3, 3), (2, 2), (1, 1), sparse='csr')
assert np.all(spmat.todense() == expected)
def test_pooling_2d_topology_stride2():
mat = pooling_matrix((3, 3), (3, 3), (2, 2))
expected = np.zeros((9, 49))
maps = expected.reshape((3, 3, 7, 7))
maps[0, 0, 0:3, 0:3] = 1.
maps[0, 1, 0:3, 2:5] = 1.
maps[0, 2, 0:3, 4:7] = 1.
maps[1, 0, 2:5, 0:3] = 1.
maps[1, 1, 2:5, 2:5] = 1.
maps[1, 2, 2:5, 4:7] = 1.
maps[2, 0, 4:7, 0:3] = 1.
maps[2, 1, 4:7, 2:5] = 1.
maps[2, 2, 4:7, 4:7] = 1.
assert np.all(mat == expected)
skip_if_no_scipy()
spmat = pooling_matrix((3, 3), (3, 3), (2, 2), sparse='csr')
assert np.all(spmat.todense() == expected)
def test_pooling_2d_non_overlapping():
mat = pooling_matrix((3, 3), (3, 3), (3, 3))
assert mat.shape == (9, 81)
expected = np.zeros((9, 81))
maps = expected.reshape((3, 3, 9, 9))
maps[0, 0, 0:3, 0:3] = 1.
maps[0, 1, 0:3, 3:6] = 1.
maps[0, 2, 0:3, 6:9] = 1.
maps[1, 0, 3:6, 0:3] = 1.
maps[1, 1, 3:6, 3:6] = 1.
maps[1, 2, 3:6, 6:9] = 1.
maps[2, 0, 6:9, 0:3] = 1.
maps[2, 1, 6:9, 3:6] = 1.
maps[2, 2, 6:9, 6:9] = 1.
assert np.all(mat == expected)
skip_if_no_scipy()
spmat = pooling_matrix((3, 3), (3, 3), (3, 3), sparse='csr')
assert np.all(spmat.todense() == expected)
def test_exceptions():
def check_raised(exc_type, func, *args, **kwargs):
try:
func(*args, **kwargs)
except exc_type:
return
assert False
yield (check_raised, TypeError, pooling_matrix, 'hello', 2)
yield (check_raised, TypeError, pooling_matrix, 2, 'hello')
yield (check_raised, TypeError, pooling_matrix, 3, 3, 'hello')
yield (check_raised, ValueError, pooling_matrix, 2, (3, 4))
yield (check_raised, ValueError, pooling_matrix, (4, 5), 2)
yield (check_raised, ValueError, pooling_matrix, (4, 5), (5, 6), (3,))
yield (check_raised, ValueError, pooling_matrix, (4, 5, 6), (3, 2))
yield (check_raised, ValueError, pooling_matrix, (3, 3), (2, 2), (5, 5))
yield (check_raised, ValueError, pooling_matrix,
(3, 3, 3), (2, 2, 2), (2, 2, 1))
yield (check_raised, ValueError, pooling_matrix, 5, 2, 1, 'float32', 'abc')
|
bsd-3-clause
|
[
624,
774,
20699,
13,
2407,
1233,
315,
20699,
14,
647,
624,
199,
199,
646,
2680,
465,
980,
199,
504,
27959,
18,
14,
1208,
14,
28624,
492,
20699,
63,
3642,
199,
504,
27959,
18,
14,
4776,
14,
2759,
492,
3372,
63,
692,
63,
889,
63,
14248,
421,
199,
318,
511,
63,
28624,
63,
889,
63,
10775,
837,
272,
2530,
275,
20699,
63,
3642,
8,
20,
12,
959,
9,
272,
702,
2530,
14,
1392,
508,
334,
20,
12,
3388,
9,
272,
1420,
275,
980,
14,
1144,
4038,
17,
61,
627,
959,
435,
359,
16,
61,
627,
4114,
12,
586,
359,
16,
61,
627,
959,
435,
359,
17,
61,
627,
959,
435,
359,
16,
61,
627,
1616,
12,
586,
359,
16,
61,
627,
1616,
435,
359,
17,
61,
627,
959,
435,
359,
16,
61,
627,
959,
12,
586,
359,
16,
61,
627,
4114,
435,
359,
17,
61,
627,
959,
566,
272,
702,
980,
14,
452,
8,
569,
508,
1420,
9,
272,
3372,
63,
692,
63,
889,
63,
14248,
342,
272,
2249,
569,
275,
20699,
63,
3642,
8,
20,
12,
959,
12,
5178,
534,
10101,
358,
272,
702,
980,
14,
452,
8,
681,
569,
14,
23526,
342,
508,
1420,
9,
421,
199,
318,
511,
63,
28624,
63,
17,
68,
63,
10775,
837,
272,
2530,
275,
20699,
63,
3642,
8,
19,
12,
841,
12,
499,
9,
272,
702,
2530,
14,
1392,
508,
334,
19,
12,
1695,
9,
272,
1420,
275,
980,
14,
1144,
4038,
17,
12,
413,
12,
413,
12,
413,
12,
378,
12,
378,
12,
378,
12,
378,
467,
586,
359,
16,
12,
378,
12,
413,
12,
413,
12,
413,
12,
413,
12,
378,
12,
378,
467,
586,
359,
16,
12,
378,
12,
378,
12,
378,
12,
413,
12,
413,
12,
413,
12,
413,
3934,
272,
702,
980,
14,
452,
8,
569,
508,
1420,
9,
272,
3372,
63,
692,
63,
889,
63,
14248,
342,
272,
2249,
569,
275,
20699,
63,
3642,
8,
19,
12,
841,
12,
499,
12,
5178,
534,
10101,
358,
272,
702,
980,
14,
452,
8,
681,
569,
14,
23526,
342,
508,
1420,
9,
421,
199,
318,
511,
63,
28624,
63,
17,
68,
63,
10775,
63,
11760,
837,
272,
2530,
275,
20699,
63,
3642,
1332,
19,
4706,
334,
20,
4706,
334,
18,
4641,
272,
702,
2530,
14,
1392,
508,
334,
19,
12,
1695,
9,
272,
1420,
275,
980,
14,
1144,
4038,
17,
12,
413,
12,
413,
12,
413,
12,
378,
12,
378,
12,
378,
12,
378,
467,
586,
359,
16,
12,
378,
12,
413,
12,
413,
12,
413,
12,
413,
12,
378,
12,
378,
467,
586,
359,
16,
12,
378,
12,
378,
12,
378,
12,
413,
12,
413,
12,
413,
12,
413,
3934,
272,
702,
980,
14,
452,
8,
569,
508,
1420,
9,
272,
3372,
63,
692,
63,
889,
63,
14248,
342,
272,
2249,
569,
275,
20699,
63,
3642,
8,
19,
12,
841,
12,
499,
12,
5178,
534,
10101,
358,
272,
702,
980,
14,
452,
8,
681,
569,
14,
23526,
342,
508,
1420,
9,
421,
199,
318,
511,
63,
28624,
63,
18,
68,
63,
10775,
837,
272,
2530,
275,
20699,
63,
3642,
1332,
19,
12,
650,
395,
334,
18,
12,
499,
395,
334,
17,
12,
413,
430,
272,
702,
2530,
14,
1392,
508,
334,
25,
12,
3193,
9,
272,
1420,
275,
980,
14,
4250,
1332,
25,
12,
3193,
430,
272,
9033,
275,
1420,
14,
5217,
1332,
19,
12,
650,
12,
841,
12,
841,
430,
272,
9033,
59,
16,
12,
378,
12,
378,
26,
18,
12,
378,
26,
18,
61,
275,
413,
14,
272,
9033,
59,
17,
12,
378,
12,
413,
26,
19,
12,
378,
26,
18,
61,
275,
413,
14,
272,
9033,
59,
18,
12,
378,
12,
499,
26,
20,
12,
378,
26,
18,
61,
275,
413,
14,
272,
9033,
59,
16,
12,
413,
12,
378,
26,
18,
12,
413,
26,
19,
61,
275,
413,
14,
272,
9033,
59,
17,
12,
413,
12,
413,
26,
19,
12,
413,
26,
19,
61,
275,
413,
14,
272,
9033,
59,
18,
12,
413,
12,
499,
26,
20,
12,
413,
26,
19,
61,
275,
413,
14,
272,
9033,
59,
16,
12,
499,
12,
378,
26,
18,
12,
499,
26,
20,
61,
275,
413,
14,
272,
9033,
59,
17,
12,
499,
12,
413,
26,
19,
12,
499,
26,
20,
61,
275,
413,
14,
272,
9033,
59,
18,
12,
499,
12,
499,
26,
20,
12,
499,
26,
20,
61,
275,
413,
14,
272,
702,
980,
14,
452,
8,
569,
508,
1420,
9,
272,
3372,
63,
692,
63,
889,
63,
14248,
342,
272,
2249,
569,
275,
20699,
63,
3642,
1332,
19,
12,
650,
395,
334,
18,
12,
499,
395,
334,
17,
12,
413,
395,
5178,
534,
10101,
358,
272,
702,
980,
14,
452,
8,
681,
569,
14,
23526,
342,
508,
1420,
9,
421,
199,
318,
511,
63,
28624,
63,
18,
68,
63,
10775,
63,
12318,
18,
837,
272,
2530,
275,
20699,
63,
3642,
1332,
19,
12,
650,
395,
334,
19,
12,
650,
395,
334,
18,
12,
499,
430,
272,
1420,
275,
980,
14,
4250,
1332,
25,
12,
12260,
430,
272,
9033,
275,
1420,
14,
5217,
1332,
19,
12,
650,
12,
1520,
12,
1520,
430,
272,
9033,
59,
16,
12,
378,
12,
378,
26,
19,
12,
378,
26,
19,
61,
275,
413,
14,
272,
9033,
59,
16,
12,
413,
12,
378,
26,
19,
12,
499,
26,
21,
61,
275,
413,
14,
272,
9033,
59,
16,
12,
499,
12,
378,
26,
19,
12,
841,
26,
23,
61,
275,
413,
14,
272,
9033,
59,
17,
12,
378,
12,
499,
26,
21,
12,
378,
26,
19,
61,
275,
413,
14,
272,
9033,
59,
17,
12,
413,
12,
499,
26,
21,
12,
499,
26,
21,
61,
275,
413,
14,
272,
9033,
59,
17,
12,
499,
12,
499,
26,
21,
12,
841,
26,
23,
61,
275,
413,
14,
272,
9033,
59,
18,
12,
378,
12,
841,
26,
23,
12,
378,
26,
19,
61,
275,
413,
14,
272,
9033,
59,
18,
12,
413,
12,
841,
26,
23,
12,
499,
26,
21,
61,
275,
413,
14,
272,
9033,
59,
18,
12,
499,
12,
841,
26,
23,
12,
841,
26,
23,
61,
275,
413,
14,
272,
702,
980,
14,
452,
8,
569,
508,
1420,
9,
272,
3372,
63,
692,
63,
889,
63
] |
[
774,
20699,
13,
2407,
1233,
315,
20699,
14,
647,
624,
199,
199,
646,
2680,
465,
980,
199,
504,
27959,
18,
14,
1208,
14,
28624,
492,
20699,
63,
3642,
199,
504,
27959,
18,
14,
4776,
14,
2759,
492,
3372,
63,
692,
63,
889,
63,
14248,
421,
199,
318,
511,
63,
28624,
63,
889,
63,
10775,
837,
272,
2530,
275,
20699,
63,
3642,
8,
20,
12,
959,
9,
272,
702,
2530,
14,
1392,
508,
334,
20,
12,
3388,
9,
272,
1420,
275,
980,
14,
1144,
4038,
17,
61,
627,
959,
435,
359,
16,
61,
627,
4114,
12,
586,
359,
16,
61,
627,
959,
435,
359,
17,
61,
627,
959,
435,
359,
16,
61,
627,
1616,
12,
586,
359,
16,
61,
627,
1616,
435,
359,
17,
61,
627,
959,
435,
359,
16,
61,
627,
959,
12,
586,
359,
16,
61,
627,
4114,
435,
359,
17,
61,
627,
959,
566,
272,
702,
980,
14,
452,
8,
569,
508,
1420,
9,
272,
3372,
63,
692,
63,
889,
63,
14248,
342,
272,
2249,
569,
275,
20699,
63,
3642,
8,
20,
12,
959,
12,
5178,
534,
10101,
358,
272,
702,
980,
14,
452,
8,
681,
569,
14,
23526,
342,
508,
1420,
9,
421,
199,
318,
511,
63,
28624,
63,
17,
68,
63,
10775,
837,
272,
2530,
275,
20699,
63,
3642,
8,
19,
12,
841,
12,
499,
9,
272,
702,
2530,
14,
1392,
508,
334,
19,
12,
1695,
9,
272,
1420,
275,
980,
14,
1144,
4038,
17,
12,
413,
12,
413,
12,
413,
12,
378,
12,
378,
12,
378,
12,
378,
467,
586,
359,
16,
12,
378,
12,
413,
12,
413,
12,
413,
12,
413,
12,
378,
12,
378,
467,
586,
359,
16,
12,
378,
12,
378,
12,
378,
12,
413,
12,
413,
12,
413,
12,
413,
3934,
272,
702,
980,
14,
452,
8,
569,
508,
1420,
9,
272,
3372,
63,
692,
63,
889,
63,
14248,
342,
272,
2249,
569,
275,
20699,
63,
3642,
8,
19,
12,
841,
12,
499,
12,
5178,
534,
10101,
358,
272,
702,
980,
14,
452,
8,
681,
569,
14,
23526,
342,
508,
1420,
9,
421,
199,
318,
511,
63,
28624,
63,
17,
68,
63,
10775,
63,
11760,
837,
272,
2530,
275,
20699,
63,
3642,
1332,
19,
4706,
334,
20,
4706,
334,
18,
4641,
272,
702,
2530,
14,
1392,
508,
334,
19,
12,
1695,
9,
272,
1420,
275,
980,
14,
1144,
4038,
17,
12,
413,
12,
413,
12,
413,
12,
378,
12,
378,
12,
378,
12,
378,
467,
586,
359,
16,
12,
378,
12,
413,
12,
413,
12,
413,
12,
413,
12,
378,
12,
378,
467,
586,
359,
16,
12,
378,
12,
378,
12,
378,
12,
413,
12,
413,
12,
413,
12,
413,
3934,
272,
702,
980,
14,
452,
8,
569,
508,
1420,
9,
272,
3372,
63,
692,
63,
889,
63,
14248,
342,
272,
2249,
569,
275,
20699,
63,
3642,
8,
19,
12,
841,
12,
499,
12,
5178,
534,
10101,
358,
272,
702,
980,
14,
452,
8,
681,
569,
14,
23526,
342,
508,
1420,
9,
421,
199,
318,
511,
63,
28624,
63,
18,
68,
63,
10775,
837,
272,
2530,
275,
20699,
63,
3642,
1332,
19,
12,
650,
395,
334,
18,
12,
499,
395,
334,
17,
12,
413,
430,
272,
702,
2530,
14,
1392,
508,
334,
25,
12,
3193,
9,
272,
1420,
275,
980,
14,
4250,
1332,
25,
12,
3193,
430,
272,
9033,
275,
1420,
14,
5217,
1332,
19,
12,
650,
12,
841,
12,
841,
430,
272,
9033,
59,
16,
12,
378,
12,
378,
26,
18,
12,
378,
26,
18,
61,
275,
413,
14,
272,
9033,
59,
17,
12,
378,
12,
413,
26,
19,
12,
378,
26,
18,
61,
275,
413,
14,
272,
9033,
59,
18,
12,
378,
12,
499,
26,
20,
12,
378,
26,
18,
61,
275,
413,
14,
272,
9033,
59,
16,
12,
413,
12,
378,
26,
18,
12,
413,
26,
19,
61,
275,
413,
14,
272,
9033,
59,
17,
12,
413,
12,
413,
26,
19,
12,
413,
26,
19,
61,
275,
413,
14,
272,
9033,
59,
18,
12,
413,
12,
499,
26,
20,
12,
413,
26,
19,
61,
275,
413,
14,
272,
9033,
59,
16,
12,
499,
12,
378,
26,
18,
12,
499,
26,
20,
61,
275,
413,
14,
272,
9033,
59,
17,
12,
499,
12,
413,
26,
19,
12,
499,
26,
20,
61,
275,
413,
14,
272,
9033,
59,
18,
12,
499,
12,
499,
26,
20,
12,
499,
26,
20,
61,
275,
413,
14,
272,
702,
980,
14,
452,
8,
569,
508,
1420,
9,
272,
3372,
63,
692,
63,
889,
63,
14248,
342,
272,
2249,
569,
275,
20699,
63,
3642,
1332,
19,
12,
650,
395,
334,
18,
12,
499,
395,
334,
17,
12,
413,
395,
5178,
534,
10101,
358,
272,
702,
980,
14,
452,
8,
681,
569,
14,
23526,
342,
508,
1420,
9,
421,
199,
318,
511,
63,
28624,
63,
18,
68,
63,
10775,
63,
12318,
18,
837,
272,
2530,
275,
20699,
63,
3642,
1332,
19,
12,
650,
395,
334,
19,
12,
650,
395,
334,
18,
12,
499,
430,
272,
1420,
275,
980,
14,
4250,
1332,
25,
12,
12260,
430,
272,
9033,
275,
1420,
14,
5217,
1332,
19,
12,
650,
12,
1520,
12,
1520,
430,
272,
9033,
59,
16,
12,
378,
12,
378,
26,
19,
12,
378,
26,
19,
61,
275,
413,
14,
272,
9033,
59,
16,
12,
413,
12,
378,
26,
19,
12,
499,
26,
21,
61,
275,
413,
14,
272,
9033,
59,
16,
12,
499,
12,
378,
26,
19,
12,
841,
26,
23,
61,
275,
413,
14,
272,
9033,
59,
17,
12,
378,
12,
499,
26,
21,
12,
378,
26,
19,
61,
275,
413,
14,
272,
9033,
59,
17,
12,
413,
12,
499,
26,
21,
12,
499,
26,
21,
61,
275,
413,
14,
272,
9033,
59,
17,
12,
499,
12,
499,
26,
21,
12,
841,
26,
23,
61,
275,
413,
14,
272,
9033,
59,
18,
12,
378,
12,
841,
26,
23,
12,
378,
26,
19,
61,
275,
413,
14,
272,
9033,
59,
18,
12,
413,
12,
841,
26,
23,
12,
499,
26,
21,
61,
275,
413,
14,
272,
9033,
59,
18,
12,
499,
12,
841,
26,
23,
12,
841,
26,
23,
61,
275,
413,
14,
272,
702,
980,
14,
452,
8,
569,
508,
1420,
9,
272,
3372,
63,
692,
63,
889,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
aio-libs/aiobotocore
|
tests/test_response.py
|
1
|
5549
|
import io
import pytest
from aiobotocore import response
from botocore.exceptions import IncompleteReadError
# https://github.com/boto/botocore/blob/develop/tests/unit/test_response.py
async def assert_lines(line_iterator, expected_lines):
for expected_line in expected_lines:
line = await line_iterator.__anext__()
assert line == expected_line
# We should have exhausted the iterator.
with pytest.raises(StopAsyncIteration):
await line_iterator.__anext__()
class AsyncBytesIO(io.BytesIO):
async def read(self, amt):
if amt == -1: # aiohttp to regular response
amt = None
return super().read(amt)
async def _tolist(aiter):
results = []
async for item in aiter:
results.append(item)
return results
@pytest.mark.moto
@pytest.mark.asyncio
async def test_streaming_wrapper_validates_content_length():
body = AsyncBytesIO(b'1234567890')
stream = response.StreamingBody(body, content_length=10)
assert await stream.read() == b'1234567890'
@pytest.mark.moto
@pytest.mark.asyncio
async def test_streaming_body_with_invalid_length():
body = AsyncBytesIO(b'123456789')
stream = response.StreamingBody(body, content_length=10)
with pytest.raises(IncompleteReadError):
assert await stream.read(9) == b'123456789'
# The next read will have nothing returned and raise
# an IncompleteReadError because we were expectd 10 bytes, not 9.
await stream.read()
@pytest.mark.moto
@pytest.mark.asyncio
async def test_streaming_body_with_zero_read():
body = AsyncBytesIO(b'1234567890')
stream = response.StreamingBody(body, content_length=10)
chunk = await stream.read(0)
assert chunk == b''
assert await stream.read() == b'1234567890'
@pytest.mark.moto
@pytest.mark.asyncio
async def test_streaming_body_with_single_read():
body = AsyncBytesIO(b'123456789')
stream = response.StreamingBody(body, content_length=10)
with pytest.raises(IncompleteReadError):
await stream.read()
@pytest.mark.moto
@pytest.mark.asyncio
async def test_streaming_body_closes():
body = AsyncBytesIO(b'1234567890')
stream = response.StreamingBody(body, content_length=10)
assert body.closed is False
stream.close()
assert body.closed is True
@pytest.mark.moto
@pytest.mark.asyncio
async def test_default_iter_behavior():
body = AsyncBytesIO(b'a' * 2048)
stream = response.StreamingBody(body, content_length=2048)
chunks = await _tolist(stream)
assert len(chunks) == 2
assert chunks, [b'a' * 1024 == b'a' * 1024]
@pytest.mark.moto
@pytest.mark.asyncio
async def test_iter_chunks_single_byte():
body = AsyncBytesIO(b'abcde')
stream = response.StreamingBody(body, content_length=5)
chunks = await _tolist(stream.iter_chunks(chunk_size=1))
assert chunks, [b'a', b'b', b'c', b'd' == b'e']
@pytest.mark.moto
@pytest.mark.asyncio
async def test_iter_chunks_with_leftover():
body = AsyncBytesIO(b'abcde')
stream = response.StreamingBody(body, content_length=5)
chunks = await _tolist(stream.iter_chunks(chunk_size=2))
assert chunks, [b'ab', b'cd' == b'e']
@pytest.mark.moto
@pytest.mark.asyncio
async def test_iter_chunks_single_chunk():
body = AsyncBytesIO(b'abcde')
stream = response.StreamingBody(body, content_length=5)
chunks = await _tolist(stream.iter_chunks(chunk_size=1024))
assert chunks == [b'abcde']
@pytest.mark.moto
@pytest.mark.asyncio
async def test_streaming_line_iterator():
body = AsyncBytesIO(b'1234567890\n1234567890\n12345')
stream = response.StreamingBody(body, content_length=27)
await assert_lines(
stream.iter_lines(),
[b'1234567890', b'1234567890', b'12345'],
)
@pytest.mark.moto
@pytest.mark.asyncio
async def test_streaming_line_iterator_ends_newline():
body = AsyncBytesIO(b'1234567890\n1234567890\n12345\n')
stream = response.StreamingBody(body, content_length=28)
await assert_lines(
stream.iter_lines(),
[b'1234567890', b'1234567890', b'12345'],
)
@pytest.mark.moto
@pytest.mark.asyncio
async def test_streaming_line_iter_chunk_sizes():
for chunk_size in range(1, 30):
body = AsyncBytesIO(b'1234567890\n1234567890\n12345')
stream = response.StreamingBody(body, content_length=27)
await assert_lines(
stream.iter_lines(chunk_size),
[b'1234567890', b'1234567890', b'12345'],
)
@pytest.mark.moto
@pytest.mark.asyncio
async def test_streaming_body_is_an_iterator():
body = AsyncBytesIO(b'a' * 1024 + b'b' * 1024 + b'c' * 2)
stream = response.StreamingBody(body, content_length=2050)
assert b'a' * 1024 == await stream.__anext__()
assert b'b' * 1024 == await stream.__anext__()
assert b'c' * 2 == await stream.__anext__()
with pytest.raises(StopAsyncIteration):
await stream.__anext__()
@pytest.mark.moto
@pytest.mark.asyncio
async def test_streaming_line_abstruse_newline_standard():
for chunk_size in range(1, 30):
body = AsyncBytesIO(b'1234567890\r\n1234567890\r\n12345\r\n')
stream = response.StreamingBody(body, content_length=31)
await assert_lines(
stream.iter_lines(chunk_size),
[b'1234567890', b'1234567890', b'12345'],
)
@pytest.mark.moto
@pytest.mark.asyncio
async def test_streaming_line_empty_body():
stream = response.StreamingBody(
AsyncBytesIO(b''), content_length=0,
)
await assert_lines(stream.iter_lines(), [])
|
apache-2.0
|
[
646,
5890,
199,
199,
646,
4613,
199,
504,
282,
2308,
10914,
1018,
492,
1177,
199,
504,
21199,
14,
3924,
492,
1010,
4883,
3284,
547,
421,
199,
3,
4178,
921,
5031,
14,
957,
15,
10914,
15,
10914,
1018,
15,
6582,
15,
32176,
15,
2219,
15,
3248,
15,
396,
63,
1310,
14,
647,
199,
4146,
347,
702,
63,
1278,
8,
604,
63,
5778,
12,
1420,
63,
1278,
304,
272,
367,
1420,
63,
604,
315,
1420,
63,
1278,
26,
267,
1004,
275,
5517,
1004,
63,
5778,
855,
290,
832,
4533,
267,
702,
1004,
508,
1420,
63,
604,
339,
327,
2136,
1077,
1172,
31103,
314,
6122,
14,
272,
543,
4613,
14,
3536,
8,
6293,
12807,
8666,
304,
267,
5517,
1004,
63,
5778,
855,
290,
832,
4533,
421,
199,
533,
15223,
15466,
8,
2308,
14,
15466,
304,
272,
5316,
347,
1586,
8,
277,
12,
23486,
304,
267,
340,
23486,
508,
446,
17,
26,
221,
327,
30274,
370,
5578,
1177,
288,
23486,
275,
488,
267,
372,
1613,
1252,
739,
8,
19582,
9,
421,
199,
4146,
347,
485,
13633,
8,
65,
1661,
304,
272,
2058,
275,
942,
272,
5316,
367,
1242,
315,
282,
1661,
26,
267,
2058,
14,
740,
8,
1053,
9,
272,
372,
2058,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
12076,
63,
5029,
63,
1078,
2335,
63,
1317,
63,
1267,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
21515,
358,
272,
2547,
275,
1177,
14,
22555,
8173,
8,
2030,
12,
1564,
63,
1267,
29,
709,
9,
272,
702,
5517,
2547,
14,
739,
342,
508,
330,
7,
21515,
7,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
12076,
63,
2030,
63,
1045,
63,
3197,
63,
1267,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
11272,
358,
272,
2547,
275,
1177,
14,
22555,
8173,
8,
2030,
12,
1564,
63,
1267,
29,
709,
9,
272,
543,
4613,
14,
3536,
8,
31962,
3284,
547,
304,
267,
702,
5517,
2547,
14,
739,
8,
25,
9,
508,
330,
7,
11272,
7,
267,
327,
710,
2163,
1586,
911,
1172,
6548,
2138,
436,
746,
267,
327,
376,
1010,
4883,
3284,
547,
2952,
781,
4898,
4282,
68,
1616,
2783,
12,
440,
1749,
14,
267,
5517,
2547,
14,
739,
342,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
12076,
63,
2030,
63,
1045,
63,
4262,
63,
739,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
21515,
358,
272,
2547,
275,
1177,
14,
22555,
8173,
8,
2030,
12,
1564,
63,
1267,
29,
709,
9,
272,
3728,
275,
5517,
2547,
14,
739,
8,
16,
9,
272,
702,
3728,
508,
330,
891,
272,
702,
5517,
2547,
14,
739,
342,
508,
330,
7,
21515,
7,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
12076,
63,
2030,
63,
1045,
63,
4780,
63,
739,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
11272,
358,
272,
2547,
275,
1177,
14,
22555,
8173,
8,
2030,
12,
1564,
63,
1267,
29,
709,
9,
272,
543,
4613,
14,
3536,
8,
31962,
3284,
547,
304,
267,
5517,
2547,
14,
739,
342,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
12076,
63,
2030,
63,
1251,
874,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
21515,
358,
272,
2547,
275,
1177,
14,
22555,
8173,
8,
2030,
12,
1564,
63,
1267,
29,
709,
9,
272,
702,
2396,
14,
5938,
365,
756,
272,
2547,
14,
1600,
342,
272,
702,
2396,
14,
5938,
365,
715,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
885,
63,
1661,
63,
17537,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
65,
7,
627,
18427,
9,
272,
2547,
275,
1177,
14,
22555,
8173,
8,
2030,
12,
1564,
63,
1267,
29,
18343,
9,
272,
8291,
275,
5517,
485,
13633,
8,
1745,
9,
272,
702,
822,
8,
10660,
9,
508,
499,
272,
702,
8291,
12,
359,
66,
7,
65,
7,
627,
6619,
508,
330,
7,
65,
7,
627,
6619,
61,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
1661,
63,
10660,
63,
4780,
63,
4414,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
28109,
358,
272,
2547,
275,
1177,
14,
22555,
8173,
8,
2030,
12,
1564,
63,
1267,
29,
21,
9,
272,
8291,
275,
5517,
485,
13633,
8,
1745,
14,
1661,
63,
10660,
8,
4604,
63,
890,
29,
17,
430,
272,
702,
8291,
12,
359,
66,
7,
65,
297,
330,
7,
66,
297,
330,
7,
67,
297,
330,
5121,
7,
508,
330,
7,
69,
418,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
1661,
63,
10660,
63,
1045,
63,
21491,
25084,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
28109,
358,
272,
2547,
275,
1177,
14,
22555,
8173,
8,
2030,
12,
1564,
63,
1267,
29,
21,
9,
272,
8291,
275,
5517,
485,
13633,
8,
1745,
14,
1661,
63,
10660,
8,
4604,
63,
890,
29,
18,
430,
272,
702,
8291,
12,
359,
66,
7,
371,
297,
330,
7,
2866,
7,
508,
330,
7,
69,
418,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
1661,
63,
10660,
63,
4780,
63,
4604,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
28109,
358,
272,
2547,
275,
1177,
14,
22555,
8173,
8,
2030,
12,
1564,
63,
1267,
29,
21,
9,
272,
8291,
275,
5517,
485,
13633,
8,
1745,
14,
1661,
63,
10660,
8,
4604,
63,
890,
29,
7727,
430,
272,
702,
8291,
508,
359,
66,
7,
28109,
418,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
12076,
63,
604,
63,
5778,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
21515,
60,
78,
21515,
60,
78,
13261
] |
[
5890,
199,
199,
646,
4613,
199,
504,
282,
2308,
10914,
1018,
492,
1177,
199,
504,
21199,
14,
3924,
492,
1010,
4883,
3284,
547,
421,
199,
3,
4178,
921,
5031,
14,
957,
15,
10914,
15,
10914,
1018,
15,
6582,
15,
32176,
15,
2219,
15,
3248,
15,
396,
63,
1310,
14,
647,
199,
4146,
347,
702,
63,
1278,
8,
604,
63,
5778,
12,
1420,
63,
1278,
304,
272,
367,
1420,
63,
604,
315,
1420,
63,
1278,
26,
267,
1004,
275,
5517,
1004,
63,
5778,
855,
290,
832,
4533,
267,
702,
1004,
508,
1420,
63,
604,
339,
327,
2136,
1077,
1172,
31103,
314,
6122,
14,
272,
543,
4613,
14,
3536,
8,
6293,
12807,
8666,
304,
267,
5517,
1004,
63,
5778,
855,
290,
832,
4533,
421,
199,
533,
15223,
15466,
8,
2308,
14,
15466,
304,
272,
5316,
347,
1586,
8,
277,
12,
23486,
304,
267,
340,
23486,
508,
446,
17,
26,
221,
327,
30274,
370,
5578,
1177,
288,
23486,
275,
488,
267,
372,
1613,
1252,
739,
8,
19582,
9,
421,
199,
4146,
347,
485,
13633,
8,
65,
1661,
304,
272,
2058,
275,
942,
272,
5316,
367,
1242,
315,
282,
1661,
26,
267,
2058,
14,
740,
8,
1053,
9,
272,
372,
2058,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
12076,
63,
5029,
63,
1078,
2335,
63,
1317,
63,
1267,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
21515,
358,
272,
2547,
275,
1177,
14,
22555,
8173,
8,
2030,
12,
1564,
63,
1267,
29,
709,
9,
272,
702,
5517,
2547,
14,
739,
342,
508,
330,
7,
21515,
7,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
12076,
63,
2030,
63,
1045,
63,
3197,
63,
1267,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
11272,
358,
272,
2547,
275,
1177,
14,
22555,
8173,
8,
2030,
12,
1564,
63,
1267,
29,
709,
9,
272,
543,
4613,
14,
3536,
8,
31962,
3284,
547,
304,
267,
702,
5517,
2547,
14,
739,
8,
25,
9,
508,
330,
7,
11272,
7,
267,
327,
710,
2163,
1586,
911,
1172,
6548,
2138,
436,
746,
267,
327,
376,
1010,
4883,
3284,
547,
2952,
781,
4898,
4282,
68,
1616,
2783,
12,
440,
1749,
14,
267,
5517,
2547,
14,
739,
342,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
12076,
63,
2030,
63,
1045,
63,
4262,
63,
739,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
21515,
358,
272,
2547,
275,
1177,
14,
22555,
8173,
8,
2030,
12,
1564,
63,
1267,
29,
709,
9,
272,
3728,
275,
5517,
2547,
14,
739,
8,
16,
9,
272,
702,
3728,
508,
330,
891,
272,
702,
5517,
2547,
14,
739,
342,
508,
330,
7,
21515,
7,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
12076,
63,
2030,
63,
1045,
63,
4780,
63,
739,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
11272,
358,
272,
2547,
275,
1177,
14,
22555,
8173,
8,
2030,
12,
1564,
63,
1267,
29,
709,
9,
272,
543,
4613,
14,
3536,
8,
31962,
3284,
547,
304,
267,
5517,
2547,
14,
739,
342,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
12076,
63,
2030,
63,
1251,
874,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
21515,
358,
272,
2547,
275,
1177,
14,
22555,
8173,
8,
2030,
12,
1564,
63,
1267,
29,
709,
9,
272,
702,
2396,
14,
5938,
365,
756,
272,
2547,
14,
1600,
342,
272,
702,
2396,
14,
5938,
365,
715,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
885,
63,
1661,
63,
17537,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
65,
7,
627,
18427,
9,
272,
2547,
275,
1177,
14,
22555,
8173,
8,
2030,
12,
1564,
63,
1267,
29,
18343,
9,
272,
8291,
275,
5517,
485,
13633,
8,
1745,
9,
272,
702,
822,
8,
10660,
9,
508,
499,
272,
702,
8291,
12,
359,
66,
7,
65,
7,
627,
6619,
508,
330,
7,
65,
7,
627,
6619,
61,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
1661,
63,
10660,
63,
4780,
63,
4414,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
28109,
358,
272,
2547,
275,
1177,
14,
22555,
8173,
8,
2030,
12,
1564,
63,
1267,
29,
21,
9,
272,
8291,
275,
5517,
485,
13633,
8,
1745,
14,
1661,
63,
10660,
8,
4604,
63,
890,
29,
17,
430,
272,
702,
8291,
12,
359,
66,
7,
65,
297,
330,
7,
66,
297,
330,
7,
67,
297,
330,
5121,
7,
508,
330,
7,
69,
418,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
1661,
63,
10660,
63,
1045,
63,
21491,
25084,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
28109,
358,
272,
2547,
275,
1177,
14,
22555,
8173,
8,
2030,
12,
1564,
63,
1267,
29,
21,
9,
272,
8291,
275,
5517,
485,
13633,
8,
1745,
14,
1661,
63,
10660,
8,
4604,
63,
890,
29,
18,
430,
272,
702,
8291,
12,
359,
66,
7,
371,
297,
330,
7,
2866,
7,
508,
330,
7,
69,
418,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
1661,
63,
10660,
63,
4780,
63,
4604,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
28109,
358,
272,
2547,
275,
1177,
14,
22555,
8173,
8,
2030,
12,
1564,
63,
1267,
29,
21,
9,
272,
8291,
275,
5517,
485,
13633,
8,
1745,
14,
1661,
63,
10660,
8,
4604,
63,
890,
29,
7727,
430,
272,
702,
8291,
508,
359,
66,
7,
28109,
418,
421,
199,
32,
4462,
14,
1657,
14,
77,
3459,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
12076,
63,
604,
63,
5778,
837,
272,
2396,
275,
15223,
15466,
8,
66,
7,
21515,
60,
78,
21515,
60,
78,
13261,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tomevans/pyphotom
|
photom_class.py
|
1
|
14267
|
import numpy as np
import matplotlib.pyplot as plt
import pdb
import os
import cPickle
import numpy as np
import shutil
from photom import photom_inspect, photom_reduce, photom_absolute, photom_relative, photom_checks, photom_optimise
homestr = os.path.expanduser( '~' )
class photom():
"""
"""
def __init__(self):
"""
Initalise a default photom object.
"""
self.analysis_dir = ''
self.nstars = None
self.image_list = None
self.bias_list = None
self.dark_list = None
self.flat_list = None
self.ccdproc_params = 'default'
self.master_bias = None
self.master_dark = None
self.master_flat = None
self.red_image_list = None
self.nimages_total = None
self.nimages_good = None
self.goodbad_flags = None
self.coords_input_files = None
self.coords_input_type = None
self.photpars = 'default'
self.fitskypars = 'default'
self.centerpars = 'default'
self.datapars = 'default'
self.dat_files = None
self.absphot_file = None
self.relphot_file = None
return None
def set_attributes( self, analysis_dir=None, image_list=None, bias_list=None, dark_list=None, \
flat_list=None, ccdproc_params=None, ap_params=None, master_bias=None, \
master_dark=None, master_flat=None, red_image_list=None, nimages_total=None, \
nimages_good=None, goodbad_flags=None, nstars=None, coords_input_files=None, \
coords_input_type=None, photpars=None, fitskypars=None, centerpars=None, \
datapars=None, dat_files=None, absphot_file=None, relphot_file=None ):
"""
Set photom object parameters.
"""
if analysis_dir!=None: self.analysis_dir = analysis_dir.replace( '~', homestr )
if self.analysis_dir=='': self.analysis_dir = os.getcwd()
if image_list!=None:
if (os.path.dirname(image_list)==''):
self.image_list = str(self.analysis_dir+'/'+image_list).replace('//','/')
else:
self.image_list = image_list
if red_image_list!=None:
if (os.path.dirname(red_image_list)==''):
self.red_image_list = str(self.analysis_dir+'/'+red_image_list).replace('//','/')
else:
self.red_image_list = red_image_list
if bias_list!=None:
if (os.path.dirname(bias_list)==''):
self.bias_list = str(self.analysis_dir+'/'+bias_list).replace('//','/')
else:
self.bias_list = bias_list
if dark_list!=None:
if (os.path.dirname(dark_list)==''):
self.dark_list = str(self.analysis_dir+'/'+dark_list).replace('//','/')
else:
self.dark_list = dark_list
if flat_list!=None:
if (os.path.dirname(flat_list)==''):
self.flat_list = str(self.analysis_dir+'/'+flat_list).replace('//','/')
else:
self.flat_list = flat_list
if coords_input_files!=None:
if np.rank(coords_input_files)==0:
self.coords_input_files = [str(self.analysis_dir+'/'+coords_input_files).replace('//','/')]
else:
self.coords_input_files = []
for coords_input in coords_input_files:
if os.path.dirname(coords_input)=='':
coords_input_full = str(self.analysis_dir+'/'+coords_input).replace('//','/')
else:
coords_input_full = coords_input
self.coords_input_files = self.coords_input_files+[coords_input_full]
if coords_input_type!=None: self.coords_input_type = coords_input_type
if ccdproc_params!=None: self.ccdproc_params = ccdproc_params
if ap_params!=None: self.ap_params = ap_params
if master_bias!=None: self.master_bias = master_bias
if master_dark!=None: self.master_dark = master_dark
if master_flat!=None: self.master_flat = master_flat
if red_image_list!=None: self.red_image_list = red_image_list
if goodbad_flags!=None: self.goodbad_flags = goodbad_flags
if nimages_total!=None: self.nimages_total = nimages_total
if nimages_good!=None: self.nimages_good = nimages_good
if nstars!=None: self.nstars = nstars
if photpars!=None: self.photpars = photpars
if fitskypars!=None: self.fitskypars = fitskypars
if centerpars!=None: self.centerpars = centerpars
if datapars!=None: self.datapars = datapars
if dat_files!=None: self.dat_files = dat_files
if absphot_file!=None: self.absphot_file = absphot_file
if relphot_file!=None: self.relphot_file = relphot_file
self.pickle_obj()
return None
def inspect_images( self, obstime_kw=None, iraf_display_mode='display' ):
"""
"""
photom_inspect.Main( self, obstime_kw=obstime_kw, iraf_display_mode=iraf_display_mode )
self.pickle_obj()
return None
def reduce_images( self, use_previous=False, ccdproc_ccdtype='default', ccdproc_overscan='default', \
ccdproc_trim='default', ccdproc_fixpix='default', ccdproc_illumcor='default', \
ccdproc_fringecor='default', ccdproc_readcor='default', ccdproc_scancor='default', \
ccdproc_interactive='default', ccdproc_biassec='default', ccdproc_trimsec='default' ):
"""
"""
if self.ccdproc_params=='custom':
photom_reduce.custom_ccdproc_params( ccdproc_ccdtype=ccdproc_ccdtype, ccdproc_overscan=ccdproc_overscan, \
ccdproc_trim=ccdproc_trim, ccdproc_fixpix=ccdproc_fixpix, \
ccdproc_illumcor=ccdproc_illumcor, ccdproc_fringecor=ccdproc_fringecor, \
ccdproc_readcor=ccdproc_readcor, ccdproc_scancor=ccdproc_scancor, \
ccdproc_interactive=ccdproc_interactive, ccdproc_biassec=ccdproc_biassec, \
ccdproc_trimsec=ccdproc_trimsec )
elif self.ccdproc_params=='default':
photom_reduce.default_ccdproc_params(self)
if use_previous==False:
photom_reduce.Main(self)
else:
self.self_update()
self.pickle_obj()
return None
def optimise_aperture( self, ap_size_trials, sky_annulus_trials, sky_dannulus, gain_kw=None, readnoise_kw=None, \
exptime_kw=None, obstime_kw=None, airmass_kw=None, ix_target=None, ix_comparisons=None ):
"""
Searches a grid of aperture radii and sky annulus radii for the combination that
minimises the scatter of the relative photometry.
"""
scatter_array = photom_optimise.Main( self, ap_size_trials, sky_annulus_trials, sky_dannulus, datapars_gain=gain_kw, \
datapars_readnoise=readnoise_kw, datapars_exposure=exptime_kw, \
datapars_obstime=obstime_kw, datapars_airmass=airmass_kw, ix_target=ix_target, \
ix_comparisons=ix_comparisons )
return scatter_array
def do_absphot( self, photpars_apertures='default', fitskypars_annulus='default', fitskypars_dannulus='default', \
fitskypars_salgorithm='default', centerpars_maxshift='default', centerpars_cbox='default', \
centerpars_minsnratio='default', datapars_gain='default', datapars_readnoise='default', \
datapars_exposure='default', datapars_obstime='default', datapars_airmass='default', make_plots=True ):
"""
Does absolute photometry for one or more stars given a list of images.
Output is generated in the form of two types of file:
1. starX_absphot.dat for X=0,1,2,... files contain columns with the
more detailed output for each of the stars, with each line
corresponding to a different image.
2. absolute.phot file containing the important numerical columns for
each of the stars; it's supposed to be the most convenient output
for use with numpy and for generating relative photometry.
Summary plots are also generated by default:
Figure 1:
** Top left = traces of xy drift for each of the stars
** Bottom left = airmass versus time
** Top right = absolute flux versus time for each star
** Bottom right = sky annulus value as a function of time for each star
Figure 2:
?? Plots image number versus measured scatter divided by the calculated Poisson noise ??
"""
if self.photpars=='custom':
photom_absolute.custom_photpars( self, photpars_apertures=photpars_apertures )
elif self.photpars=='default':
photom_absolute.default_photpars( self )
if self.fitskypars=='custom':
photom_absolute.custom_fitskypars( self, fitskypars_annulus=fitskypars_annulus, fitskypars_dannulus=fitskypars_dannulus, \
fitskypars_salgorithm=fitskypars_salgorithm )
elif self.fitskypars=='default':
photom_absolute.default_fitskypars( self )
if self.centerpars=='custom':
photom_absolute.custom_centerpars( self, centerpars_maxshift=centerpars_maxshift, centerpars_cbox=centerpars_cbox, \
centerpars_minsnratio=centerpars_minsnratio )
elif self.centerpars=='default':
photom_absolute.default_centerpars( self )
if self.datapars=='custom':
photom_absolute.custom_datapars( self, datapars_gain=datapars_gain, datapars_readnoise=datapars_readnoise, \
datapars_exposure=datapars_exposure, datapars_obstime=datapars_obstime, \
datapars_airmass=datapars_airmass )
elif self.datapars=='default':
photom_absolute.default_datapars( self )
photom_absolute.Main( self, make_plots=make_plots )
self.pickle_obj()
return None
def do_relphot( self, ix_target=None, ix_comparisons=None, make_plots=True ):
"""
Calculates relative fluxes using absolute photometry already stored in the photom object.
Must specify indices for the target star and comparison stars to be used, using the format
0,1,2,... etc where 0 is the first star.
"""
photom_relative.Main( self, ix_target=ix_target, ix_comparisons=ix_comparisons, make_plots=make_plots )
self.pickle_obj()
return None
def check_relphot( self ):
"""
Does two basic checks of the relative photometry in an effort to identify
variable comparison stars. Output is in the form of plots that must be
visually inspected to identify variable stars.
The two types of checks are:
1. All possible pairs of stars that can be made up from the target
and comparisons are checked.
2. A leave-one-out approach is taken, where the relative photometry is
repeated multiple times, with a different comparison star excluded
each time.
"""
photom_checks.comparisons( self )
return None
def update_auxvars( self, headerkws=None ):
"""
Will update the auxiliary variables within the photom object. This is done
using the photometry already contained in the object to calculate the total
sum of all stellar fluxes, as well as extracting header information from
images stored in the red_images_list variable.
"""
photom_checks.auxiliary_variables( self, headerkws=headerkws )
return None
def self_update( self ):
"""
Routine used to generate default values for a few variables, eg. if
a certain analysis step, such as reduce_images(), has already been
performed and so does not need to be repeated.
!!NOTE: This routine is currently pretty ad-hoc and could possibly do with a
rethink plus the addition of various features that have been added to the
overall pipeline since I first wrote this particular routine a while back.
"""
# Count the total number of images:
try:
red_images = np.loadtxt(self.red_image_list, dtype='str')
self.nimages_total = len(red_images)
except:
pass
# Set the goodbad_flags to all be good:
if self.goodbad_flags==None:
try:
self.goodbad_flags = np.ones(self.nimages_total)
except:
pass
# Count the number of good images:
self.nimages_good = int(np.sum(self.goodbad_flags))
self.pickle_obj()
return None
def pickle_obj( self, quiet=False ):
"""
Pickle the photom object in its current state. Saves the output as photom_object.pkl in the
analysis directory.
"""
outfile_name = str( self.analysis_dir + '/photom_object.pkl' ).replace( '//', '/' )
outfile_open = open( outfile_name, 'w' )
cPickle.dump( self, outfile_open )
outfile_open.close()
if quiet==False:
print '\nSaved %s\n' % outfile_name
self.pickled_output = outfile_name
return None
def backup_the_pickle( self ):
"""
Makes a backup of the current photom_object.pkl, saving the backed up version as photom_object.pkl.BACKUP
in the analysis directory.
"""
pkl_name = str( self.analysis_dir + '/photom_object.pkl' ).replace( '//', '/' )
shutil.copyfile( pkl_name, pkl_name + '.BACKUP' )
print '\nBacked up pickled photom object'
return None
|
gpl-2.0
|
[
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
10543,
199,
646,
747,
199,
646,
17572,
199,
646,
2680,
465,
980,
199,
646,
5145,
199,
504,
3945,
357,
676,
492,
3945,
357,
676,
63,
10955,
12,
3945,
357,
676,
63,
5270,
12,
3945,
357,
676,
63,
6116,
12,
3945,
357,
676,
63,
6188,
12,
3945,
357,
676,
63,
8625,
12,
3945,
357,
676,
63,
6433,
572,
199,
199,
4219,
495,
275,
747,
14,
515,
14,
12131,
8,
17352,
7,
776,
199,
199,
533,
3945,
357,
676,
837,
272,
408,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
408,
267,
1010,
6910,
572,
282,
849,
3945,
357,
676,
909,
14,
267,
408,
267,
291,
14,
10466,
63,
694,
275,
2125,
267,
291,
14,
78,
270,
4291,
275,
488,
198,
263,
267,
291,
14,
1569,
63,
513,
275,
488,
420,
267,
291,
14,
8160,
63,
513,
275,
488,
755,
267,
291,
14,
13625,
63,
513,
275,
488,
755,
267,
291,
14,
7088,
63,
513,
275,
488,
755,
267,
291,
14,
30013,
4687,
63,
1162,
275,
283,
885,
7,
267,
291,
14,
4133,
63,
8160,
275,
488,
267,
291,
14,
4133,
63,
13625,
275,
488,
267,
291,
14,
4133,
63,
7088,
275,
488,
267,
291,
14,
581,
63,
1569,
63,
513,
275,
488,
267,
291,
14,
78,
4782,
63,
2923,
275,
488,
267,
291,
14,
78,
4782,
63,
8302,
275,
488,
267,
291,
14,
8302,
4087,
63,
2469,
275,
488,
27439,
291,
14,
8032,
63,
1210,
63,
1725,
275,
488,
267,
291,
14,
8032,
63,
1210,
63,
466,
275,
488,
267,
291,
14,
838,
357,
21152,
275,
283,
885,
7,
267,
291,
14,
14948,
10562,
21152,
275,
283,
885,
7,
267,
291,
14,
4218,
21152,
275,
283,
885,
7,
267,
291,
14,
576,
21152,
275,
283,
885,
7,
267,
291,
14,
4616,
63,
1725,
275,
488,
267,
291,
14,
371,
7616,
357,
63,
493,
275,
488,
27439,
291,
14,
3369,
838,
357,
63,
493,
275,
488,
267,
372,
488,
339,
347,
663,
63,
2987,
8,
291,
12,
11284,
63,
694,
29,
403,
12,
1834,
63,
513,
29,
403,
12,
10671,
63,
513,
29,
403,
12,
23531,
63,
513,
29,
403,
12,
971,
717,
6829,
63,
513,
29,
403,
12,
286,
2866,
4687,
63,
1162,
29,
403,
12,
2771,
63,
1162,
29,
403,
12,
5288,
63,
8160,
29,
403,
12,
971,
717,
5288,
63,
13625,
29,
403,
12,
5288,
63,
7088,
29,
403,
12,
8992,
63,
1569,
63,
513,
29,
403,
12,
302,
4782,
63,
2923,
29,
403,
12,
971,
717,
302,
4782,
63,
8302,
29,
403,
12,
6954,
4087,
63,
2469,
29,
403,
12,
302,
270,
4291,
29,
403,
12,
13259,
63,
1210,
63,
1725,
29,
403,
12,
971,
717,
13259,
63,
1210,
63,
466,
29,
403,
12,
3945,
357,
21152,
29,
403,
12,
5542,
12267,
21152,
29,
403,
12,
8126,
21152,
29,
403,
12,
971,
717,
666,
21152,
29,
403,
12,
6394,
63,
1725,
29,
403,
12,
2236,
7616,
357,
63,
493,
29,
403,
12,
4668,
838,
357,
63,
493,
29,
403,
3461,
267,
408,
267,
2494,
3945,
357,
676,
909,
2633,
14,
267,
408,
267,
340,
11284,
63,
694,
1111,
403,
26,
291,
14,
10466,
63,
694,
275,
11284,
63,
694,
14,
1814,
8,
17352,
297,
5629,
495,
776,
267,
340,
291,
14,
10466,
63,
694,
6803,
356,
291,
14,
10466,
63,
694,
275,
747,
14,
9458,
342,
267,
340,
1834,
63,
513,
1111,
403,
26,
288,
340,
334,
736,
14,
515,
14,
3475,
8,
1569,
63,
513,
9,
6803,
735,
355,
291,
14,
1569,
63,
513,
275,
620,
8,
277,
14,
10466,
63,
694,
4786,
19047,
1569,
63,
513,
680,
1814,
15079,
1673,
6217,
288,
587,
26,
355,
291,
14,
1569,
63,
513,
275,
1834,
63,
513,
267,
340,
8992,
63,
1569,
63,
513,
1111,
403,
26,
288,
340,
334,
736,
14,
515,
14,
3475,
8,
581,
63,
1569,
63,
513,
9,
6803,
735,
355,
291,
14,
581,
63,
1569,
63,
513,
275,
620,
8,
277,
14,
10466,
63,
694,
4786,
19047,
581,
63,
1569,
63,
513,
680,
1814,
15079,
1673,
6217,
288,
587,
26,
355,
291,
14,
581,
63,
1569,
63,
513,
275,
8992,
63,
1569,
63,
513,
267,
340,
10671,
63,
513,
1111,
403,
26,
288,
340,
334,
736,
14,
515,
14,
3475,
8,
8160,
63,
513,
9,
6803,
735,
355,
291,
14,
8160,
63,
513,
275,
620,
8,
277,
14,
10466,
63,
694,
4786,
19047,
8160,
63,
513,
680,
1814,
15079,
1673,
6217,
288,
587,
26,
355,
291,
14,
8160,
63,
513,
275,
10671,
63,
513,
267,
340,
23531,
63,
513,
1111,
403,
26,
288,
340,
334,
736,
14,
515,
14,
3475,
8,
13625,
63,
513,
9,
6803,
735,
355,
291,
14,
13625,
63,
513,
275,
620,
8,
277,
14,
10466,
63,
694,
4786,
19047,
13625,
63,
513,
680,
1814,
15079,
1673,
6217,
288,
587,
26,
355,
291,
14,
13625,
63,
513,
275,
23531,
63,
513,
267,
340,
6829,
63,
513,
1111,
403,
26,
288,
340,
334,
736,
14,
515,
14,
3475,
8,
7088,
63,
513,
9,
6803,
735,
355,
291,
14,
7088,
63,
513,
275,
620,
8,
277,
14,
10466,
63,
694,
4786,
19047,
7088,
63,
513,
680,
1814,
15079,
1673,
6217,
288,
587,
26,
355,
291,
14,
7088,
63,
513,
275,
6829,
63,
513,
267,
340,
13259,
63,
1210,
63,
1725,
1111,
403,
26,
288,
340,
980,
14,
4648,
8,
8032,
63,
1210,
63,
1725,
12694,
16,
26,
355,
291,
14,
8032,
63,
1210,
63,
1725,
275,
359,
495,
8,
277,
14,
10466,
63,
694,
4786,
19047,
8032,
63,
1210,
63,
1725,
680,
1814,
15079,
32381,
5440,
288,
587,
26,
355,
291,
14,
8032,
63,
1210,
63,
1725,
275,
942,
355,
367,
13259,
63,
1210,
315,
13259,
63,
1210,
63,
1725,
26,
490,
340,
747,
14,
515,
14,
3475,
8,
8032,
63,
1210,
9,
6803,
356,
717,
13259,
63,
1210,
63,
2861,
275,
620,
8,
277,
14,
10466,
63,
694,
4786,
19047,
8032,
63,
1210,
680,
1814,
15079,
1673,
6217,
490,
587,
26,
717,
13259,
63,
1210,
63,
2861,
275,
13259,
63,
1210,
490,
291,
14,
8032,
63,
1210,
63,
1725,
275,
291,
14,
8032,
63,
1210,
63,
1725,
21324,
8032,
63,
1210
] |
[
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
10543,
199,
646,
747,
199,
646,
17572,
199,
646,
2680,
465,
980,
199,
646,
5145,
199,
504,
3945,
357,
676,
492,
3945,
357,
676,
63,
10955,
12,
3945,
357,
676,
63,
5270,
12,
3945,
357,
676,
63,
6116,
12,
3945,
357,
676,
63,
6188,
12,
3945,
357,
676,
63,
8625,
12,
3945,
357,
676,
63,
6433,
572,
199,
199,
4219,
495,
275,
747,
14,
515,
14,
12131,
8,
17352,
7,
776,
199,
199,
533,
3945,
357,
676,
837,
272,
408,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
408,
267,
1010,
6910,
572,
282,
849,
3945,
357,
676,
909,
14,
267,
408,
267,
291,
14,
10466,
63,
694,
275,
2125,
267,
291,
14,
78,
270,
4291,
275,
488,
198,
263,
267,
291,
14,
1569,
63,
513,
275,
488,
420,
267,
291,
14,
8160,
63,
513,
275,
488,
755,
267,
291,
14,
13625,
63,
513,
275,
488,
755,
267,
291,
14,
7088,
63,
513,
275,
488,
755,
267,
291,
14,
30013,
4687,
63,
1162,
275,
283,
885,
7,
267,
291,
14,
4133,
63,
8160,
275,
488,
267,
291,
14,
4133,
63,
13625,
275,
488,
267,
291,
14,
4133,
63,
7088,
275,
488,
267,
291,
14,
581,
63,
1569,
63,
513,
275,
488,
267,
291,
14,
78,
4782,
63,
2923,
275,
488,
267,
291,
14,
78,
4782,
63,
8302,
275,
488,
267,
291,
14,
8302,
4087,
63,
2469,
275,
488,
27439,
291,
14,
8032,
63,
1210,
63,
1725,
275,
488,
267,
291,
14,
8032,
63,
1210,
63,
466,
275,
488,
267,
291,
14,
838,
357,
21152,
275,
283,
885,
7,
267,
291,
14,
14948,
10562,
21152,
275,
283,
885,
7,
267,
291,
14,
4218,
21152,
275,
283,
885,
7,
267,
291,
14,
576,
21152,
275,
283,
885,
7,
267,
291,
14,
4616,
63,
1725,
275,
488,
267,
291,
14,
371,
7616,
357,
63,
493,
275,
488,
27439,
291,
14,
3369,
838,
357,
63,
493,
275,
488,
267,
372,
488,
339,
347,
663,
63,
2987,
8,
291,
12,
11284,
63,
694,
29,
403,
12,
1834,
63,
513,
29,
403,
12,
10671,
63,
513,
29,
403,
12,
23531,
63,
513,
29,
403,
12,
971,
717,
6829,
63,
513,
29,
403,
12,
286,
2866,
4687,
63,
1162,
29,
403,
12,
2771,
63,
1162,
29,
403,
12,
5288,
63,
8160,
29,
403,
12,
971,
717,
5288,
63,
13625,
29,
403,
12,
5288,
63,
7088,
29,
403,
12,
8992,
63,
1569,
63,
513,
29,
403,
12,
302,
4782,
63,
2923,
29,
403,
12,
971,
717,
302,
4782,
63,
8302,
29,
403,
12,
6954,
4087,
63,
2469,
29,
403,
12,
302,
270,
4291,
29,
403,
12,
13259,
63,
1210,
63,
1725,
29,
403,
12,
971,
717,
13259,
63,
1210,
63,
466,
29,
403,
12,
3945,
357,
21152,
29,
403,
12,
5542,
12267,
21152,
29,
403,
12,
8126,
21152,
29,
403,
12,
971,
717,
666,
21152,
29,
403,
12,
6394,
63,
1725,
29,
403,
12,
2236,
7616,
357,
63,
493,
29,
403,
12,
4668,
838,
357,
63,
493,
29,
403,
3461,
267,
408,
267,
2494,
3945,
357,
676,
909,
2633,
14,
267,
408,
267,
340,
11284,
63,
694,
1111,
403,
26,
291,
14,
10466,
63,
694,
275,
11284,
63,
694,
14,
1814,
8,
17352,
297,
5629,
495,
776,
267,
340,
291,
14,
10466,
63,
694,
6803,
356,
291,
14,
10466,
63,
694,
275,
747,
14,
9458,
342,
267,
340,
1834,
63,
513,
1111,
403,
26,
288,
340,
334,
736,
14,
515,
14,
3475,
8,
1569,
63,
513,
9,
6803,
735,
355,
291,
14,
1569,
63,
513,
275,
620,
8,
277,
14,
10466,
63,
694,
4786,
19047,
1569,
63,
513,
680,
1814,
15079,
1673,
6217,
288,
587,
26,
355,
291,
14,
1569,
63,
513,
275,
1834,
63,
513,
267,
340,
8992,
63,
1569,
63,
513,
1111,
403,
26,
288,
340,
334,
736,
14,
515,
14,
3475,
8,
581,
63,
1569,
63,
513,
9,
6803,
735,
355,
291,
14,
581,
63,
1569,
63,
513,
275,
620,
8,
277,
14,
10466,
63,
694,
4786,
19047,
581,
63,
1569,
63,
513,
680,
1814,
15079,
1673,
6217,
288,
587,
26,
355,
291,
14,
581,
63,
1569,
63,
513,
275,
8992,
63,
1569,
63,
513,
267,
340,
10671,
63,
513,
1111,
403,
26,
288,
340,
334,
736,
14,
515,
14,
3475,
8,
8160,
63,
513,
9,
6803,
735,
355,
291,
14,
8160,
63,
513,
275,
620,
8,
277,
14,
10466,
63,
694,
4786,
19047,
8160,
63,
513,
680,
1814,
15079,
1673,
6217,
288,
587,
26,
355,
291,
14,
8160,
63,
513,
275,
10671,
63,
513,
267,
340,
23531,
63,
513,
1111,
403,
26,
288,
340,
334,
736,
14,
515,
14,
3475,
8,
13625,
63,
513,
9,
6803,
735,
355,
291,
14,
13625,
63,
513,
275,
620,
8,
277,
14,
10466,
63,
694,
4786,
19047,
13625,
63,
513,
680,
1814,
15079,
1673,
6217,
288,
587,
26,
355,
291,
14,
13625,
63,
513,
275,
23531,
63,
513,
267,
340,
6829,
63,
513,
1111,
403,
26,
288,
340,
334,
736,
14,
515,
14,
3475,
8,
7088,
63,
513,
9,
6803,
735,
355,
291,
14,
7088,
63,
513,
275,
620,
8,
277,
14,
10466,
63,
694,
4786,
19047,
7088,
63,
513,
680,
1814,
15079,
1673,
6217,
288,
587,
26,
355,
291,
14,
7088,
63,
513,
275,
6829,
63,
513,
267,
340,
13259,
63,
1210,
63,
1725,
1111,
403,
26,
288,
340,
980,
14,
4648,
8,
8032,
63,
1210,
63,
1725,
12694,
16,
26,
355,
291,
14,
8032,
63,
1210,
63,
1725,
275,
359,
495,
8,
277,
14,
10466,
63,
694,
4786,
19047,
8032,
63,
1210,
63,
1725,
680,
1814,
15079,
32381,
5440,
288,
587,
26,
355,
291,
14,
8032,
63,
1210,
63,
1725,
275,
942,
355,
367,
13259,
63,
1210,
315,
13259,
63,
1210,
63,
1725,
26,
490,
340,
747,
14,
515,
14,
3475,
8,
8032,
63,
1210,
9,
6803,
356,
717,
13259,
63,
1210,
63,
2861,
275,
620,
8,
277,
14,
10466,
63,
694,
4786,
19047,
8032,
63,
1210,
680,
1814,
15079,
1673,
6217,
490,
587,
26,
717,
13259,
63,
1210,
63,
2861,
275,
13259,
63,
1210,
490,
291,
14,
8032,
63,
1210,
63,
1725,
275,
291,
14,
8032,
63,
1210,
63,
1725,
21324,
8032,
63,
1210,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
taedla01/MissionPlanner
|
Lib/encodings/cp1251.py
|
93
|
13924
|
""" Python Character Mapping Codec cp1251 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1251.TXT' with gencodec.py.
"""#"
import codecs
### Codec APIs
class Codec(codecs.Codec):
def encode(self,input,errors='strict'):
return codecs.charmap_encode(input,errors,encoding_table)
def decode(self,input,errors='strict'):
return codecs.charmap_decode(input,errors,decoding_table)
class IncrementalEncoder(codecs.IncrementalEncoder):
def encode(self, input, final=False):
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
class IncrementalDecoder(codecs.IncrementalDecoder):
def decode(self, input, final=False):
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
class StreamWriter(Codec,codecs.StreamWriter):
pass
class StreamReader(Codec,codecs.StreamReader):
pass
### encodings module API
def getregentry():
return codecs.CodecInfo(
name='cp1251',
encode=Codec().encode,
decode=Codec().decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
)
### Decoding Table
decoding_table = (
u'\x00' # 0x00 -> NULL
u'\x01' # 0x01 -> START OF HEADING
u'\x02' # 0x02 -> START OF TEXT
u'\x03' # 0x03 -> END OF TEXT
u'\x04' # 0x04 -> END OF TRANSMISSION
u'\x05' # 0x05 -> ENQUIRY
u'\x06' # 0x06 -> ACKNOWLEDGE
u'\x07' # 0x07 -> BELL
u'\x08' # 0x08 -> BACKSPACE
u'\t' # 0x09 -> HORIZONTAL TABULATION
u'\n' # 0x0A -> LINE FEED
u'\x0b' # 0x0B -> VERTICAL TABULATION
u'\x0c' # 0x0C -> FORM FEED
u'\r' # 0x0D -> CARRIAGE RETURN
u'\x0e' # 0x0E -> SHIFT OUT
u'\x0f' # 0x0F -> SHIFT IN
u'\x10' # 0x10 -> DATA LINK ESCAPE
u'\x11' # 0x11 -> DEVICE CONTROL ONE
u'\x12' # 0x12 -> DEVICE CONTROL TWO
u'\x13' # 0x13 -> DEVICE CONTROL THREE
u'\x14' # 0x14 -> DEVICE CONTROL FOUR
u'\x15' # 0x15 -> NEGATIVE ACKNOWLEDGE
u'\x16' # 0x16 -> SYNCHRONOUS IDLE
u'\x17' # 0x17 -> END OF TRANSMISSION BLOCK
u'\x18' # 0x18 -> CANCEL
u'\x19' # 0x19 -> END OF MEDIUM
u'\x1a' # 0x1A -> SUBSTITUTE
u'\x1b' # 0x1B -> ESCAPE
u'\x1c' # 0x1C -> FILE SEPARATOR
u'\x1d' # 0x1D -> GROUP SEPARATOR
u'\x1e' # 0x1E -> RECORD SEPARATOR
u'\x1f' # 0x1F -> UNIT SEPARATOR
u' ' # 0x20 -> SPACE
u'!' # 0x21 -> EXCLAMATION MARK
u'"' # 0x22 -> QUOTATION MARK
u'#' # 0x23 -> NUMBER SIGN
u'$' # 0x24 -> DOLLAR SIGN
u'%' # 0x25 -> PERCENT SIGN
u'&' # 0x26 -> AMPERSAND
u"'" # 0x27 -> APOSTROPHE
u'(' # 0x28 -> LEFT PARENTHESIS
u')' # 0x29 -> RIGHT PARENTHESIS
u'*' # 0x2A -> ASTERISK
u'+' # 0x2B -> PLUS SIGN
u',' # 0x2C -> COMMA
u'-' # 0x2D -> HYPHEN-MINUS
u'.' # 0x2E -> FULL STOP
u'/' # 0x2F -> SOLIDUS
u'0' # 0x30 -> DIGIT ZERO
u'1' # 0x31 -> DIGIT ONE
u'2' # 0x32 -> DIGIT TWO
u'3' # 0x33 -> DIGIT THREE
u'4' # 0x34 -> DIGIT FOUR
u'5' # 0x35 -> DIGIT FIVE
u'6' # 0x36 -> DIGIT SIX
u'7' # 0x37 -> DIGIT SEVEN
u'8' # 0x38 -> DIGIT EIGHT
u'9' # 0x39 -> DIGIT NINE
u':' # 0x3A -> COLON
u';' # 0x3B -> SEMICOLON
u'<' # 0x3C -> LESS-THAN SIGN
u'=' # 0x3D -> EQUALS SIGN
u'>' # 0x3E -> GREATER-THAN SIGN
u'?' # 0x3F -> QUESTION MARK
u'@' # 0x40 -> COMMERCIAL AT
u'A' # 0x41 -> LATIN CAPITAL LETTER A
u'B' # 0x42 -> LATIN CAPITAL LETTER B
u'C' # 0x43 -> LATIN CAPITAL LETTER C
u'D' # 0x44 -> LATIN CAPITAL LETTER D
u'E' # 0x45 -> LATIN CAPITAL LETTER E
u'F' # 0x46 -> LATIN CAPITAL LETTER F
u'G' # 0x47 -> LATIN CAPITAL LETTER G
u'H' # 0x48 -> LATIN CAPITAL LETTER H
u'I' # 0x49 -> LATIN CAPITAL LETTER I
u'J' # 0x4A -> LATIN CAPITAL LETTER J
u'K' # 0x4B -> LATIN CAPITAL LETTER K
u'L' # 0x4C -> LATIN CAPITAL LETTER L
u'M' # 0x4D -> LATIN CAPITAL LETTER M
u'N' # 0x4E -> LATIN CAPITAL LETTER N
u'O' # 0x4F -> LATIN CAPITAL LETTER O
u'P' # 0x50 -> LATIN CAPITAL LETTER P
u'Q' # 0x51 -> LATIN CAPITAL LETTER Q
u'R' # 0x52 -> LATIN CAPITAL LETTER R
u'S' # 0x53 -> LATIN CAPITAL LETTER S
u'T' # 0x54 -> LATIN CAPITAL LETTER T
u'U' # 0x55 -> LATIN CAPITAL LETTER U
u'V' # 0x56 -> LATIN CAPITAL LETTER V
u'W' # 0x57 -> LATIN CAPITAL LETTER W
u'X' # 0x58 -> LATIN CAPITAL LETTER X
u'Y' # 0x59 -> LATIN CAPITAL LETTER Y
u'Z' # 0x5A -> LATIN CAPITAL LETTER Z
u'[' # 0x5B -> LEFT SQUARE BRACKET
u'\\' # 0x5C -> REVERSE SOLIDUS
u']' # 0x5D -> RIGHT SQUARE BRACKET
u'^' # 0x5E -> CIRCUMFLEX ACCENT
u'_' # 0x5F -> LOW LINE
u'`' # 0x60 -> GRAVE ACCENT
u'a' # 0x61 -> LATIN SMALL LETTER A
u'b' # 0x62 -> LATIN SMALL LETTER B
u'c' # 0x63 -> LATIN SMALL LETTER C
u'd' # 0x64 -> LATIN SMALL LETTER D
u'e' # 0x65 -> LATIN SMALL LETTER E
u'f' # 0x66 -> LATIN SMALL LETTER F
u'g' # 0x67 -> LATIN SMALL LETTER G
u'h' # 0x68 -> LATIN SMALL LETTER H
u'i' # 0x69 -> LATIN SMALL LETTER I
u'j' # 0x6A -> LATIN SMALL LETTER J
u'k' # 0x6B -> LATIN SMALL LETTER K
u'l' # 0x6C -> LATIN SMALL LETTER L
u'm' # 0x6D -> LATIN SMALL LETTER M
u'n' # 0x6E -> LATIN SMALL LETTER N
u'o' # 0x6F -> LATIN SMALL LETTER O
u'p' # 0x70 -> LATIN SMALL LETTER P
u'q' # 0x71 -> LATIN SMALL LETTER Q
u'r' # 0x72 -> LATIN SMALL LETTER R
u's' # 0x73 -> LATIN SMALL LETTER S
u't' # 0x74 -> LATIN SMALL LETTER T
u'u' # 0x75 -> LATIN SMALL LETTER U
u'v' # 0x76 -> LATIN SMALL LETTER V
u'w' # 0x77 -> LATIN SMALL LETTER W
u'x' # 0x78 -> LATIN SMALL LETTER X
u'y' # 0x79 -> LATIN SMALL LETTER Y
u'z' # 0x7A -> LATIN SMALL LETTER Z
u'{' # 0x7B -> LEFT CURLY BRACKET
u'|' # 0x7C -> VERTICAL LINE
u'}' # 0x7D -> RIGHT CURLY BRACKET
u'~' # 0x7E -> TILDE
u'\x7f' # 0x7F -> DELETE
u'\u0402' # 0x80 -> CYRILLIC CAPITAL LETTER DJE
u'\u0403' # 0x81 -> CYRILLIC CAPITAL LETTER GJE
u'\u201a' # 0x82 -> SINGLE LOW-9 QUOTATION MARK
u'\u0453' # 0x83 -> CYRILLIC SMALL LETTER GJE
u'\u201e' # 0x84 -> DOUBLE LOW-9 QUOTATION MARK
u'\u2026' # 0x85 -> HORIZONTAL ELLIPSIS
u'\u2020' # 0x86 -> DAGGER
u'\u2021' # 0x87 -> DOUBLE DAGGER
u'\u20ac' # 0x88 -> EURO SIGN
u'\u2030' # 0x89 -> PER MILLE SIGN
u'\u0409' # 0x8A -> CYRILLIC CAPITAL LETTER LJE
u'\u2039' # 0x8B -> SINGLE LEFT-POINTING ANGLE QUOTATION MARK
u'\u040a' # 0x8C -> CYRILLIC CAPITAL LETTER NJE
u'\u040c' # 0x8D -> CYRILLIC CAPITAL LETTER KJE
u'\u040b' # 0x8E -> CYRILLIC CAPITAL LETTER TSHE
u'\u040f' # 0x8F -> CYRILLIC CAPITAL LETTER DZHE
u'\u0452' # 0x90 -> CYRILLIC SMALL LETTER DJE
u'\u2018' # 0x91 -> LEFT SINGLE QUOTATION MARK
u'\u2019' # 0x92 -> RIGHT SINGLE QUOTATION MARK
u'\u201c' # 0x93 -> LEFT DOUBLE QUOTATION MARK
u'\u201d' # 0x94 -> RIGHT DOUBLE QUOTATION MARK
u'\u2022' # 0x95 -> BULLET
u'\u2013' # 0x96 -> EN DASH
u'\u2014' # 0x97 -> EM DASH
u'\ufffe' # 0x98 -> UNDEFINED
u'\u2122' # 0x99 -> TRADE MARK SIGN
u'\u0459' # 0x9A -> CYRILLIC SMALL LETTER LJE
u'\u203a' # 0x9B -> SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
u'\u045a' # 0x9C -> CYRILLIC SMALL LETTER NJE
u'\u045c' # 0x9D -> CYRILLIC SMALL LETTER KJE
u'\u045b' # 0x9E -> CYRILLIC SMALL LETTER TSHE
u'\u045f' # 0x9F -> CYRILLIC SMALL LETTER DZHE
u'\xa0' # 0xA0 -> NO-BREAK SPACE
u'\u040e' # 0xA1 -> CYRILLIC CAPITAL LETTER SHORT U
u'\u045e' # 0xA2 -> CYRILLIC SMALL LETTER SHORT U
u'\u0408' # 0xA3 -> CYRILLIC CAPITAL LETTER JE
u'\xa4' # 0xA4 -> CURRENCY SIGN
u'\u0490' # 0xA5 -> CYRILLIC CAPITAL LETTER GHE WITH UPTURN
u'\xa6' # 0xA6 -> BROKEN BAR
u'\xa7' # 0xA7 -> SECTION SIGN
u'\u0401' # 0xA8 -> CYRILLIC CAPITAL LETTER IO
u'\xa9' # 0xA9 -> COPYRIGHT SIGN
u'\u0404' # 0xAA -> CYRILLIC CAPITAL LETTER UKRAINIAN IE
u'\xab' # 0xAB -> LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
u'\xac' # 0xAC -> NOT SIGN
u'\xad' # 0xAD -> SOFT HYPHEN
u'\xae' # 0xAE -> REGISTERED SIGN
u'\u0407' # 0xAF -> CYRILLIC CAPITAL LETTER YI
u'\xb0' # 0xB0 -> DEGREE SIGN
u'\xb1' # 0xB1 -> PLUS-MINUS SIGN
u'\u0406' # 0xB2 -> CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I
u'\u0456' # 0xB3 -> CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I
u'\u0491' # 0xB4 -> CYRILLIC SMALL LETTER GHE WITH UPTURN
u'\xb5' # 0xB5 -> MICRO SIGN
u'\xb6' # 0xB6 -> PILCROW SIGN
u'\xb7' # 0xB7 -> MIDDLE DOT
u'\u0451' # 0xB8 -> CYRILLIC SMALL LETTER IO
u'\u2116' # 0xB9 -> NUMERO SIGN
u'\u0454' # 0xBA -> CYRILLIC SMALL LETTER UKRAINIAN IE
u'\xbb' # 0xBB -> RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
u'\u0458' # 0xBC -> CYRILLIC SMALL LETTER JE
u'\u0405' # 0xBD -> CYRILLIC CAPITAL LETTER DZE
u'\u0455' # 0xBE -> CYRILLIC SMALL LETTER DZE
u'\u0457' # 0xBF -> CYRILLIC SMALL LETTER YI
u'\u0410' # 0xC0 -> CYRILLIC CAPITAL LETTER A
u'\u0411' # 0xC1 -> CYRILLIC CAPITAL LETTER BE
u'\u0412' # 0xC2 -> CYRILLIC CAPITAL LETTER VE
u'\u0413' # 0xC3 -> CYRILLIC CAPITAL LETTER GHE
u'\u0414' # 0xC4 -> CYRILLIC CAPITAL LETTER DE
u'\u0415' # 0xC5 -> CYRILLIC CAPITAL LETTER IE
u'\u0416' # 0xC6 -> CYRILLIC CAPITAL LETTER ZHE
u'\u0417' # 0xC7 -> CYRILLIC CAPITAL LETTER ZE
u'\u0418' # 0xC8 -> CYRILLIC CAPITAL LETTER I
u'\u0419' # 0xC9 -> CYRILLIC CAPITAL LETTER SHORT I
u'\u041a' # 0xCA -> CYRILLIC CAPITAL LETTER KA
u'\u041b' # 0xCB -> CYRILLIC CAPITAL LETTER EL
u'\u041c' # 0xCC -> CYRILLIC CAPITAL LETTER EM
u'\u041d' # 0xCD -> CYRILLIC CAPITAL LETTER EN
u'\u041e' # 0xCE -> CYRILLIC CAPITAL LETTER O
u'\u041f' # 0xCF -> CYRILLIC CAPITAL LETTER PE
u'\u0420' # 0xD0 -> CYRILLIC CAPITAL LETTER ER
u'\u0421' # 0xD1 -> CYRILLIC CAPITAL LETTER ES
u'\u0422' # 0xD2 -> CYRILLIC CAPITAL LETTER TE
u'\u0423' # 0xD3 -> CYRILLIC CAPITAL LETTER U
u'\u0424' # 0xD4 -> CYRILLIC CAPITAL LETTER EF
u'\u0425' # 0xD5 -> CYRILLIC CAPITAL LETTER HA
u'\u0426' # 0xD6 -> CYRILLIC CAPITAL LETTER TSE
u'\u0427' # 0xD7 -> CYRILLIC CAPITAL LETTER CHE
u'\u0428' # 0xD8 -> CYRILLIC CAPITAL LETTER SHA
u'\u0429' # 0xD9 -> CYRILLIC CAPITAL LETTER SHCHA
u'\u042a' # 0xDA -> CYRILLIC CAPITAL LETTER HARD SIGN
u'\u042b' # 0xDB -> CYRILLIC CAPITAL LETTER YERU
u'\u042c' # 0xDC -> CYRILLIC CAPITAL LETTER SOFT SIGN
u'\u042d' # 0xDD -> CYRILLIC CAPITAL LETTER E
u'\u042e' # 0xDE -> CYRILLIC CAPITAL LETTER YU
u'\u042f' # 0xDF -> CYRILLIC CAPITAL LETTER YA
u'\u0430' # 0xE0 -> CYRILLIC SMALL LETTER A
u'\u0431' # 0xE1 -> CYRILLIC SMALL LETTER BE
u'\u0432' # 0xE2 -> CYRILLIC SMALL LETTER VE
u'\u0433' # 0xE3 -> CYRILLIC SMALL LETTER GHE
u'\u0434' # 0xE4 -> CYRILLIC SMALL LETTER DE
u'\u0435' # 0xE5 -> CYRILLIC SMALL LETTER IE
u'\u0436' # 0xE6 -> CYRILLIC SMALL LETTER ZHE
u'\u0437' # 0xE7 -> CYRILLIC SMALL LETTER ZE
u'\u0438' # 0xE8 -> CYRILLIC SMALL LETTER I
u'\u0439' # 0xE9 -> CYRILLIC SMALL LETTER SHORT I
u'\u043a' # 0xEA -> CYRILLIC SMALL LETTER KA
u'\u043b' # 0xEB -> CYRILLIC SMALL LETTER EL
u'\u043c' # 0xEC -> CYRILLIC SMALL LETTER EM
u'\u043d' # 0xED -> CYRILLIC SMALL LETTER EN
u'\u043e' # 0xEE -> CYRILLIC SMALL LETTER O
u'\u043f' # 0xEF -> CYRILLIC SMALL LETTER PE
u'\u0440' # 0xF0 -> CYRILLIC SMALL LETTER ER
u'\u0441' # 0xF1 -> CYRILLIC SMALL LETTER ES
u'\u0442' # 0xF2 -> CYRILLIC SMALL LETTER TE
u'\u0443' # 0xF3 -> CYRILLIC SMALL LETTER U
u'\u0444' # 0xF4 -> CYRILLIC SMALL LETTER EF
u'\u0445' # 0xF5 -> CYRILLIC SMALL LETTER HA
u'\u0446' # 0xF6 -> CYRILLIC SMALL LETTER TSE
u'\u0447' # 0xF7 -> CYRILLIC SMALL LETTER CHE
u'\u0448' # 0xF8 -> CYRILLIC SMALL LETTER SHA
u'\u0449' # 0xF9 -> CYRILLIC SMALL LETTER SHCHA
u'\u044a' # 0xFA -> CYRILLIC SMALL LETTER HARD SIGN
u'\u044b' # 0xFB -> CYRILLIC SMALL LETTER YERU
u'\u044c' # 0xFC -> CYRILLIC SMALL LETTER SOFT SIGN
u'\u044d' # 0xFD -> CYRILLIC SMALL LETTER E
u'\u044e' # 0xFE -> CYRILLIC SMALL LETTER YU
u'\u044f' # 0xFF -> CYRILLIC SMALL LETTER YA
)
### Encoding table
encoding_table=codecs.charmap_build(decoding_table)
|
gpl-3.0
|
[
624,
2018,
17660,
12340,
13732,
7667,
21381,
4046,
687,
283,
32362,
15,
27839,
4149,
15,
17233,
51,
2161,
15,
20509,
15,
2890,
21381,
14,
17715,
7,
543,
486,
2143,
67,
14,
647,
14,
2999,
199,
624,
23662,
2999,
199,
646,
6010,
2999,
199,
5680,
13732,
15913,
2999,
199,
533,
13732,
8,
8933,
14,
8818,
304,
2958,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
1039,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
2550,
12,
2991,
63,
1224,
9,
2958,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
1039,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
2550,
12,
12796,
63,
1224,
9,
2999,
199,
533,
24350,
8,
8933,
14,
17016,
304,
1128,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
1039,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
277,
14,
2550,
12,
2991,
63,
1224,
2788,
16,
61,
2999,
199,
533,
24385,
8,
8933,
14,
16703,
304,
1128,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
1039,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
277,
14,
2550,
12,
12796,
63,
1224,
2788,
16,
61,
2999,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
1128,
986,
2999,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
1128,
986,
2999,
199,
5680,
14134,
859,
3261,
2999,
199,
318,
26116,
837,
1128,
372,
6010,
14,
26375,
8,
1039,
536,
534,
1850,
21381,
297,
1039,
3752,
29,
8818,
1252,
2143,
12,
1039,
4849,
29,
8818,
1252,
2708,
12,
1039,
26329,
29,
17016,
12,
1039,
26317,
29,
16703,
12,
1039,
26101,
29,
16132,
12,
1039,
26112,
29,
16551,
12,
1128,
776,
8065,
199,
5680,
27368,
6957,
2999,
199,
12796,
63,
1224,
275,
334,
1128,
399,
1154,
88,
383,
7,
258,
327,
221,
378,
88,
383,
1035,
5962,
1128,
399,
1154,
88,
614,
7,
258,
327,
221,
378,
88,
614,
1035,
13910,
1634,
32674,
1128,
399,
1154,
88,
996,
7,
258,
327,
221,
378,
88,
996,
1035,
13910,
1634,
11951,
1128,
399,
1154,
88,
1644,
7,
258,
327,
221,
378,
88,
1644,
1035,
7729,
1634,
11951,
1128,
399,
1154,
88,
966,
7,
258,
327,
221,
378,
88,
966,
1035,
7729,
1634,
22499,
1128,
399,
1154,
88,
1717,
7,
258,
327,
221,
378,
88,
1717,
1035,
5070,
31115,
57,
1128,
399,
1154,
88,
1690,
7,
258,
327,
221,
378,
88,
1690,
1035,
22549,
1128,
399,
1154,
88,
1780,
7,
258,
327,
221,
378,
88,
1780,
1035,
699,
14952,
1128,
399,
1154,
88,
2036,
7,
258,
327,
221,
378,
88,
2036,
1035,
22658,
11658,
1128,
399,
1154,
84,
7,
755,
327,
221,
378,
88,
1643,
1035,
8724,
22450,
1128,
399,
1154,
78,
7,
755,
327,
221,
378,
88,
16,
33,
1035,
13587,
21567,
1128,
399,
1154,
88,
16,
66,
7,
258,
327,
221,
378,
88,
16,
34,
1035,
8267,
22450,
1128,
399,
1154,
88,
16,
67,
7,
258,
327,
221,
378,
88,
16,
35,
1035,
11295,
21567,
1128,
399,
1154,
82,
7,
755,
327,
221,
378,
88,
16,
36,
1035,
445,
32622,
24646,
1128,
399,
1154,
88,
16,
69,
7,
258,
327,
221,
378,
88,
16,
37,
1035,
20754,
5738,
1128,
399,
1154,
88,
16,
70,
7,
258,
327,
221,
378,
88,
16,
38,
1035,
20754,
1621,
1128,
399,
1154,
88,
709,
7,
258,
327,
221,
378,
88,
709,
1035,
7126,
19774,
17682,
1128,
399,
1154,
88,
845,
7,
258,
327,
221,
378,
88,
845,
1035,
11643,
8098,
13051,
1128,
399,
1154,
88,
713,
7,
258,
327,
221,
378,
88,
713,
1035,
11643,
8098,
16562,
1128,
399,
1154,
88,
969,
7,
258,
327,
221,
378,
88,
969,
1035,
11643,
8098,
16296,
1128,
399,
1154,
88,
1079,
7,
258,
327,
221,
378,
88,
1079,
1035,
11643,
8098,
14473,
1128,
399,
1154,
88,
1046,
7,
258,
327,
221,
378,
88,
1046,
1035,
29837,
22549,
1128,
399,
1154,
88,
975,
7,
258,
327,
221,
378,
88,
975,
1035,
10046,
30782,
23240,
1128,
399,
1154,
88,
1196,
7,
258,
327,
221,
378,
88,
1196,
1035,
7729,
1634,
22499,
8068,
1128,
399,
1154,
88,
1085,
7,
258,
327,
221,
378,
88,
1085,
1035,
27385,
1128,
399,
1154,
88,
1167,
7,
258,
327,
221,
378,
88,
1167,
1035,
7729,
1634,
22650,
1128,
399,
1154,
88,
17,
65,
7,
258,
327,
221,
378,
88,
17,
33,
1035,
9103,
1128,
399,
1154,
88,
17,
66,
7,
258,
327,
221,
378,
88,
17,
34,
1035,
17682,
1128,
399,
1154,
88,
17,
67,
7,
258,
327,
221,
378,
88,
17,
35,
1035,
13024,
14782,
1128,
399,
1154,
88,
17,
68,
7,
258,
327,
221,
378,
88,
17,
36,
1035,
15443,
14782,
1128,
399,
1154,
88,
17,
69,
7,
258,
327,
221,
378,
88,
17,
37,
1035,
24973,
14782,
1128,
399,
1154,
88,
17,
70,
7,
258,
327,
221,
378,
88,
17,
38,
1035,
25836,
14782,
1128,
399,
7,
283,
263,
327,
221,
378,
88,
1165,
1035,
16796,
1128,
399,
7,
11213,
263,
327,
221,
378,
88,
2025,
1035,
24232,
8132,
1128,
399,
30385,
263,
327,
221,
378,
88,
1081,
1035,
11830,
8132,
1128,
399,
11525,
7,
263,
327,
221,
378,
88,
1789,
1035,
18122,
5056,
1128,
399,
7,
12913,
263,
327,
221,
378,
88,
1194,
1035,
30857,
5056,
1128,
399,
5956,
7,
263,
327,
221,
378,
88,
821,
1035,
26684,
5056,
1128,
399,
21840,
7,
263,
327,
221,
378,
88,
1479,
1035,
30602,
1128,
399,
2,
4065,
263,
327,
221,
378,
88,
1465,
1035,
30876,
1128,
399,
7,
360,
263,
327,
221,
378,
88,
1651,
1035,
6578,
20570,
1128,
399,
358,
7,
263,
327,
221,
378,
88,
1398,
1035,
7052,
20570,
1128,
399,
7,
10223,
263,
327,
221,
378,
88,
18,
33,
1035,
29725,
1128,
399,
30269,
263,
327,
221,
378,
88,
18,
34,
1035,
18807,
5056,
1128,
399,
1673,
263,
327,
221,
378,
88,
18,
35,
1035,
22849,
1128,
399,
12418,
7,
263,
327,
221,
378,
88,
18,
36,
1035,
22553,
13,
18004,
1128,
399,
30484,
263,
327,
221,
378,
88,
18,
37,
1035,
18530,
22348,
1128,
399,
29957,
263,
327,
221,
378,
88,
18,
38,
1035,
20585,
1128,
399,
7,
16,
7,
263,
327,
221,
378,
88,
1216,
1035,
7298,
20348,
1128,
399,
7,
17,
7,
263,
327
] |
[
2018,
17660,
12340,
13732,
7667,
21381,
4046,
687,
283,
32362,
15,
27839,
4149,
15,
17233,
51,
2161,
15,
20509,
15,
2890,
21381,
14,
17715,
7,
543,
486,
2143,
67,
14,
647,
14,
2999,
199,
624,
23662,
2999,
199,
646,
6010,
2999,
199,
5680,
13732,
15913,
2999,
199,
533,
13732,
8,
8933,
14,
8818,
304,
2958,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
1039,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
2550,
12,
2991,
63,
1224,
9,
2958,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
1039,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
2550,
12,
12796,
63,
1224,
9,
2999,
199,
533,
24350,
8,
8933,
14,
17016,
304,
1128,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
1039,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
277,
14,
2550,
12,
2991,
63,
1224,
2788,
16,
61,
2999,
199,
533,
24385,
8,
8933,
14,
16703,
304,
1128,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
1039,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
277,
14,
2550,
12,
12796,
63,
1224,
2788,
16,
61,
2999,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
1128,
986,
2999,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
1128,
986,
2999,
199,
5680,
14134,
859,
3261,
2999,
199,
318,
26116,
837,
1128,
372,
6010,
14,
26375,
8,
1039,
536,
534,
1850,
21381,
297,
1039,
3752,
29,
8818,
1252,
2143,
12,
1039,
4849,
29,
8818,
1252,
2708,
12,
1039,
26329,
29,
17016,
12,
1039,
26317,
29,
16703,
12,
1039,
26101,
29,
16132,
12,
1039,
26112,
29,
16551,
12,
1128,
776,
8065,
199,
5680,
27368,
6957,
2999,
199,
12796,
63,
1224,
275,
334,
1128,
399,
1154,
88,
383,
7,
258,
327,
221,
378,
88,
383,
1035,
5962,
1128,
399,
1154,
88,
614,
7,
258,
327,
221,
378,
88,
614,
1035,
13910,
1634,
32674,
1128,
399,
1154,
88,
996,
7,
258,
327,
221,
378,
88,
996,
1035,
13910,
1634,
11951,
1128,
399,
1154,
88,
1644,
7,
258,
327,
221,
378,
88,
1644,
1035,
7729,
1634,
11951,
1128,
399,
1154,
88,
966,
7,
258,
327,
221,
378,
88,
966,
1035,
7729,
1634,
22499,
1128,
399,
1154,
88,
1717,
7,
258,
327,
221,
378,
88,
1717,
1035,
5070,
31115,
57,
1128,
399,
1154,
88,
1690,
7,
258,
327,
221,
378,
88,
1690,
1035,
22549,
1128,
399,
1154,
88,
1780,
7,
258,
327,
221,
378,
88,
1780,
1035,
699,
14952,
1128,
399,
1154,
88,
2036,
7,
258,
327,
221,
378,
88,
2036,
1035,
22658,
11658,
1128,
399,
1154,
84,
7,
755,
327,
221,
378,
88,
1643,
1035,
8724,
22450,
1128,
399,
1154,
78,
7,
755,
327,
221,
378,
88,
16,
33,
1035,
13587,
21567,
1128,
399,
1154,
88,
16,
66,
7,
258,
327,
221,
378,
88,
16,
34,
1035,
8267,
22450,
1128,
399,
1154,
88,
16,
67,
7,
258,
327,
221,
378,
88,
16,
35,
1035,
11295,
21567,
1128,
399,
1154,
82,
7,
755,
327,
221,
378,
88,
16,
36,
1035,
445,
32622,
24646,
1128,
399,
1154,
88,
16,
69,
7,
258,
327,
221,
378,
88,
16,
37,
1035,
20754,
5738,
1128,
399,
1154,
88,
16,
70,
7,
258,
327,
221,
378,
88,
16,
38,
1035,
20754,
1621,
1128,
399,
1154,
88,
709,
7,
258,
327,
221,
378,
88,
709,
1035,
7126,
19774,
17682,
1128,
399,
1154,
88,
845,
7,
258,
327,
221,
378,
88,
845,
1035,
11643,
8098,
13051,
1128,
399,
1154,
88,
713,
7,
258,
327,
221,
378,
88,
713,
1035,
11643,
8098,
16562,
1128,
399,
1154,
88,
969,
7,
258,
327,
221,
378,
88,
969,
1035,
11643,
8098,
16296,
1128,
399,
1154,
88,
1079,
7,
258,
327,
221,
378,
88,
1079,
1035,
11643,
8098,
14473,
1128,
399,
1154,
88,
1046,
7,
258,
327,
221,
378,
88,
1046,
1035,
29837,
22549,
1128,
399,
1154,
88,
975,
7,
258,
327,
221,
378,
88,
975,
1035,
10046,
30782,
23240,
1128,
399,
1154,
88,
1196,
7,
258,
327,
221,
378,
88,
1196,
1035,
7729,
1634,
22499,
8068,
1128,
399,
1154,
88,
1085,
7,
258,
327,
221,
378,
88,
1085,
1035,
27385,
1128,
399,
1154,
88,
1167,
7,
258,
327,
221,
378,
88,
1167,
1035,
7729,
1634,
22650,
1128,
399,
1154,
88,
17,
65,
7,
258,
327,
221,
378,
88,
17,
33,
1035,
9103,
1128,
399,
1154,
88,
17,
66,
7,
258,
327,
221,
378,
88,
17,
34,
1035,
17682,
1128,
399,
1154,
88,
17,
67,
7,
258,
327,
221,
378,
88,
17,
35,
1035,
13024,
14782,
1128,
399,
1154,
88,
17,
68,
7,
258,
327,
221,
378,
88,
17,
36,
1035,
15443,
14782,
1128,
399,
1154,
88,
17,
69,
7,
258,
327,
221,
378,
88,
17,
37,
1035,
24973,
14782,
1128,
399,
1154,
88,
17,
70,
7,
258,
327,
221,
378,
88,
17,
38,
1035,
25836,
14782,
1128,
399,
7,
283,
263,
327,
221,
378,
88,
1165,
1035,
16796,
1128,
399,
7,
11213,
263,
327,
221,
378,
88,
2025,
1035,
24232,
8132,
1128,
399,
30385,
263,
327,
221,
378,
88,
1081,
1035,
11830,
8132,
1128,
399,
11525,
7,
263,
327,
221,
378,
88,
1789,
1035,
18122,
5056,
1128,
399,
7,
12913,
263,
327,
221,
378,
88,
1194,
1035,
30857,
5056,
1128,
399,
5956,
7,
263,
327,
221,
378,
88,
821,
1035,
26684,
5056,
1128,
399,
21840,
7,
263,
327,
221,
378,
88,
1479,
1035,
30602,
1128,
399,
2,
4065,
263,
327,
221,
378,
88,
1465,
1035,
30876,
1128,
399,
7,
360,
263,
327,
221,
378,
88,
1651,
1035,
6578,
20570,
1128,
399,
358,
7,
263,
327,
221,
378,
88,
1398,
1035,
7052,
20570,
1128,
399,
7,
10223,
263,
327,
221,
378,
88,
18,
33,
1035,
29725,
1128,
399,
30269,
263,
327,
221,
378,
88,
18,
34,
1035,
18807,
5056,
1128,
399,
1673,
263,
327,
221,
378,
88,
18,
35,
1035,
22849,
1128,
399,
12418,
7,
263,
327,
221,
378,
88,
18,
36,
1035,
22553,
13,
18004,
1128,
399,
30484,
263,
327,
221,
378,
88,
18,
37,
1035,
18530,
22348,
1128,
399,
29957,
263,
327,
221,
378,
88,
18,
38,
1035,
20585,
1128,
399,
7,
16,
7,
263,
327,
221,
378,
88,
1216,
1035,
7298,
20348,
1128,
399,
7,
17,
7,
263,
327,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
brunogamacatao/portalsaladeaula
|
django/test/client.py
|
9
|
20915
|
import urllib
from urlparse import urlparse, urlunparse, urlsplit
import sys
import os
import re
import mimetypes
import warnings
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from django.conf import settings
from django.contrib.auth import authenticate, login
from django.core.handlers.base import BaseHandler
from django.core.handlers.wsgi import WSGIRequest
from django.core.signals import got_request_exception
from django.http import SimpleCookie, HttpRequest, QueryDict
from django.template import TemplateDoesNotExist
from django.test import signals
from django.utils.functional import curry
from django.utils.encoding import smart_str
from django.utils.http import urlencode
from django.utils.importlib import import_module
from django.utils.itercompat import is_iterable
from django.db import transaction, close_connection
from django.test.utils import ContextList
__all__ = ('Client', 'RequestFactory', 'encode_file', 'encode_multipart')
BOUNDARY = 'BoUnDaRyStRiNg'
MULTIPART_CONTENT = 'multipart/form-data; boundary=%s' % BOUNDARY
CONTENT_TYPE_RE = re.compile('.*; charset=([\w\d-]+);?')
class FakePayload(object):
"""
A wrapper around StringIO that restricts what can be read since data from
the network can't be seeked and cannot be read outside of its content
length. This makes sure that views can't do anything under the test client
that wouldn't work in Real Life.
"""
def __init__(self, content):
self.__content = StringIO(content)
self.__len = len(content)
def read(self, num_bytes=None):
if num_bytes is None:
num_bytes = self.__len or 1
assert self.__len >= num_bytes, "Cannot read more than the available bytes from the HTTP incoming data."
content = self.__content.read(num_bytes)
self.__len -= num_bytes
return content
class ClientHandler(BaseHandler):
"""
A HTTP Handler that can be used for testing purposes.
Uses the WSGI interface to compose requests, but returns
the raw HttpResponse object
"""
def __init__(self, enforce_csrf_checks=True, *args, **kwargs):
self.enforce_csrf_checks = enforce_csrf_checks
super(ClientHandler, self).__init__(*args, **kwargs)
def __call__(self, environ):
from django.conf import settings
from django.core import signals
# Set up middleware if needed. We couldn't do this earlier, because
# settings weren't available.
if self._request_middleware is None:
self.load_middleware()
signals.request_started.send(sender=self.__class__)
try:
request = WSGIRequest(environ)
# sneaky little hack so that we can easily get round
# CsrfViewMiddleware. This makes life easier, and is probably
# required for backwards compatibility with external tests against
# admin views.
request._dont_enforce_csrf_checks = not self.enforce_csrf_checks
response = self.get_response(request)
finally:
signals.request_finished.disconnect(close_connection)
signals.request_finished.send(sender=self.__class__)
signals.request_finished.connect(close_connection)
return response
def store_rendered_templates(store, signal, sender, template, context, **kwargs):
"""
Stores templates and contexts that are rendered.
"""
store.setdefault('templates', []).append(template)
store.setdefault('context', ContextList()).append(context)
def encode_multipart(boundary, data):
"""
Encodes multipart POST data from a dictionary of form values.
The key will be used as the form data name; the value will be transmitted
as content. If the value is a file, the contents of the file will be sent
as an application/octet-stream; otherwise, str(value) will be sent.
"""
lines = []
to_str = lambda s: smart_str(s, settings.DEFAULT_CHARSET)
# Not by any means perfect, but good enough for our purposes.
is_file = lambda thing: hasattr(thing, "read") and callable(thing.read)
# Each bit of the multipart form data could be either a form value or a
# file, or a *list* of form values and/or files. Remember that HTTP field
# names can be duplicated!
for (key, value) in data.items():
if is_file(value):
lines.extend(encode_file(boundary, key, value))
elif not isinstance(value, basestring) and is_iterable(value):
for item in value:
if is_file(item):
lines.extend(encode_file(boundary, key, item))
else:
lines.extend([
'--' + boundary,
'Content-Disposition: form-data; name="%s"' % to_str(key),
'',
to_str(item)
])
else:
lines.extend([
'--' + boundary,
'Content-Disposition: form-data; name="%s"' % to_str(key),
'',
to_str(value)
])
lines.extend([
'--' + boundary + '--',
'',
])
return '\r\n'.join(lines)
def encode_file(boundary, key, file):
to_str = lambda s: smart_str(s, settings.DEFAULT_CHARSET)
content_type = mimetypes.guess_type(file.name)[0]
if content_type is None:
content_type = 'application/octet-stream'
return [
'--' + boundary,
'Content-Disposition: form-data; name="%s"; filename="%s"' \
% (to_str(key), to_str(os.path.basename(file.name))),
'Content-Type: %s' % content_type,
'',
file.read()
]
class RequestFactory(object):
"""
Class that lets you create mock Request objects for use in testing.
Usage:
rf = RequestFactory()
get_request = rf.get('/hello/')
post_request = rf.post('/submit/', {'foo': 'bar'})
Once you have a request object you can pass it to any view function,
just as if that view had been hooked up using a URLconf.
"""
def __init__(self, **defaults):
self.defaults = defaults
self.cookies = SimpleCookie()
self.errors = StringIO()
def _base_environ(self, **request):
"""
The base environment for a request.
"""
environ = {
'HTTP_COOKIE': self.cookies.output(header='', sep='; '),
'PATH_INFO': '/',
'QUERY_STRING': '',
'REMOTE_ADDR': '127.0.0.1',
'REQUEST_METHOD': 'GET',
'SCRIPT_NAME': '',
'SERVER_NAME': 'testserver',
'SERVER_PORT': '80',
'SERVER_PROTOCOL': 'HTTP/1.1',
'wsgi.version': (1,0),
'wsgi.url_scheme': 'http',
'wsgi.errors': self.errors,
'wsgi.multiprocess': True,
'wsgi.multithread': False,
'wsgi.run_once': False,
}
environ.update(self.defaults)
environ.update(request)
return environ
def request(self, **request):
"Construct a generic request object."
return WSGIRequest(self._base_environ(**request))
def get(self, path, data={}, **extra):
"Construct a GET request"
parsed = urlparse(path)
r = {
'CONTENT_TYPE': 'text/html; charset=utf-8',
'PATH_INFO': urllib.unquote(parsed[2]),
'QUERY_STRING': urlencode(data, doseq=True) or parsed[4],
'REQUEST_METHOD': 'GET',
'wsgi.input': FakePayload('')
}
r.update(extra)
return self.request(**r)
def post(self, path, data={}, content_type=MULTIPART_CONTENT,
**extra):
"Construct a POST request."
if content_type is MULTIPART_CONTENT:
post_data = encode_multipart(BOUNDARY, data)
else:
# Encode the content so that the byte representation is correct.
match = CONTENT_TYPE_RE.match(content_type)
if match:
charset = match.group(1)
else:
charset = settings.DEFAULT_CHARSET
post_data = smart_str(data, encoding=charset)
parsed = urlparse(path)
r = {
'CONTENT_LENGTH': len(post_data),
'CONTENT_TYPE': content_type,
'PATH_INFO': urllib.unquote(parsed[2]),
'QUERY_STRING': parsed[4],
'REQUEST_METHOD': 'POST',
'wsgi.input': FakePayload(post_data),
}
r.update(extra)
return self.request(**r)
def head(self, path, data={}, **extra):
"Construct a HEAD request."
parsed = urlparse(path)
r = {
'CONTENT_TYPE': 'text/html; charset=utf-8',
'PATH_INFO': urllib.unquote(parsed[2]),
'QUERY_STRING': urlencode(data, doseq=True) or parsed[4],
'REQUEST_METHOD': 'HEAD',
'wsgi.input': FakePayload('')
}
r.update(extra)
return self.request(**r)
def options(self, path, data={}, **extra):
"Constrict an OPTIONS request"
parsed = urlparse(path)
r = {
'PATH_INFO': urllib.unquote(parsed[2]),
'QUERY_STRING': urlencode(data, doseq=True) or parsed[4],
'REQUEST_METHOD': 'OPTIONS',
'wsgi.input': FakePayload('')
}
r.update(extra)
return self.request(**r)
def put(self, path, data={}, content_type=MULTIPART_CONTENT,
**extra):
"Construct a PUT request."
if content_type is MULTIPART_CONTENT:
post_data = encode_multipart(BOUNDARY, data)
else:
post_data = data
# Make `data` into a querystring only if it's not already a string. If
# it is a string, we'll assume that the caller has already encoded it.
query_string = None
if not isinstance(data, basestring):
query_string = urlencode(data, doseq=True)
parsed = urlparse(path)
r = {
'CONTENT_LENGTH': len(post_data),
'CONTENT_TYPE': content_type,
'PATH_INFO': urllib.unquote(parsed[2]),
'QUERY_STRING': query_string or parsed[4],
'REQUEST_METHOD': 'PUT',
'wsgi.input': FakePayload(post_data),
}
r.update(extra)
return self.request(**r)
def delete(self, path, data={}, **extra):
"Construct a DELETE request."
parsed = urlparse(path)
r = {
'PATH_INFO': urllib.unquote(parsed[2]),
'QUERY_STRING': urlencode(data, doseq=True) or parsed[4],
'REQUEST_METHOD': 'DELETE',
'wsgi.input': FakePayload('')
}
r.update(extra)
return self.request(**r)
class Client(RequestFactory):
"""
A class that can act as a client for testing purposes.
It allows the user to compose GET and POST requests, and
obtain the response that the server gave to those requests.
The server Response objects are annotated with the details
of the contexts and templates that were rendered during the
process of serving the request.
Client objects are stateful - they will retain cookie (and
thus session) details for the lifetime of the Client instance.
This is not intended as a replacement for Twill/Selenium or
the like - it is here to allow testing against the
contexts and templates produced by a view, rather than the
HTML rendered to the end-user.
"""
def __init__(self, enforce_csrf_checks=False, **defaults):
super(Client, self).__init__(**defaults)
self.handler = ClientHandler(enforce_csrf_checks)
self.exc_info = None
def store_exc_info(self, **kwargs):
"""
Stores exceptions when they are generated by a view.
"""
self.exc_info = sys.exc_info()
def _session(self):
"""
Obtains the current session variables.
"""
if 'django.contrib.sessions' in settings.INSTALLED_APPS:
engine = import_module(settings.SESSION_ENGINE)
cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None)
if cookie:
return engine.SessionStore(cookie.value)
return {}
session = property(_session)
def request(self, **request):
"""
The master request method. Composes the environment dictionary
and passes to the handler, returning the result of the handler.
Assumes defaults for the query environment, which can be overridden
using the arguments to the request.
"""
environ = self._base_environ(**request)
# Curry a data dictionary into an instance of the template renderer
# callback function.
data = {}
on_template_render = curry(store_rendered_templates, data)
signals.template_rendered.connect(on_template_render, dispatch_uid="template-render")
# Capture exceptions created by the handler.
got_request_exception.connect(self.store_exc_info, dispatch_uid="request-exception")
try:
try:
response = self.handler(environ)
except TemplateDoesNotExist, e:
# If the view raises an exception, Django will attempt to show
# the 500.html template. If that template is not available,
# we should ignore the error in favor of re-raising the
# underlying exception that caused the 500 error. Any other
# template found to be missing during view error handling
# should be reported as-is.
if e.args != ('500.html',):
raise
# Look for a signalled exception, clear the current context
# exception data, then re-raise the signalled exception.
# Also make sure that the signalled exception is cleared from
# the local cache!
if self.exc_info:
exc_info = self.exc_info
self.exc_info = None
raise exc_info[1], None, exc_info[2]
# Save the client and request that stimulated the response.
response.client = self
response.request = request
# Add any rendered template detail to the response.
response.templates = data.get("templates", [])
response.context = data.get("context")
# Flatten a single context. Not really necessary anymore thanks to
# the __getattr__ flattening in ContextList, but has some edge-case
# backwards-compatibility implications.
if response.context and len(response.context) == 1:
response.context = response.context[0]
# Provide a backwards-compatible (but pending deprecation) response.template
def _get_template(self):
warnings.warn("response.template is deprecated; use response.templates instead (which is always a list)",
PendingDeprecationWarning, stacklevel=2)
if not self.templates:
return None
elif len(self.templates) == 1:
return self.templates[0]
return self.templates
response.__class__.template = property(_get_template)
# Update persistent cookie data.
if response.cookies:
self.cookies.update(response.cookies)
return response
finally:
signals.template_rendered.disconnect(dispatch_uid="template-render")
got_request_exception.disconnect(dispatch_uid="request-exception")
def get(self, path, data={}, follow=False, **extra):
"""
Requests a response from the server using GET.
"""
response = super(Client, self).get(path, data=data, **extra)
if follow:
response = self._handle_redirects(response, **extra)
return response
def post(self, path, data={}, content_type=MULTIPART_CONTENT,
follow=False, **extra):
"""
Requests a response from the server using POST.
"""
response = super(Client, self).post(path, data=data, content_type=content_type, **extra)
if follow:
response = self._handle_redirects(response, **extra)
return response
def head(self, path, data={}, follow=False, **extra):
"""
Request a response from the server using HEAD.
"""
response = super(Client, self).head(path, data=data, **extra)
if follow:
response = self._handle_redirects(response, **extra)
return response
def options(self, path, data={}, follow=False, **extra):
"""
Request a response from the server using OPTIONS.
"""
response = super(Client, self).options(path, data=data, **extra)
if follow:
response = self._handle_redirects(response, **extra)
return response
def put(self, path, data={}, content_type=MULTIPART_CONTENT,
follow=False, **extra):
"""
Send a resource to the server using PUT.
"""
response = super(Client, self).put(path, data=data, content_type=content_type, **extra)
if follow:
response = self._handle_redirects(response, **extra)
return response
def delete(self, path, data={}, follow=False, **extra):
"""
Send a DELETE request to the server.
"""
response = super(Client, self).delete(path, data=data, **extra)
if follow:
response = self._handle_redirects(response, **extra)
return response
def login(self, **credentials):
"""
Sets the Factory to appear as if it has successfully logged into a site.
Returns True if login is possible; False if the provided credentials
are incorrect, or the user is inactive, or if the sessions framework is
not available.
"""
user = authenticate(**credentials)
if user and user.is_active \
and 'django.contrib.sessions' in settings.INSTALLED_APPS:
engine = import_module(settings.SESSION_ENGINE)
# Create a fake request to store login details.
request = HttpRequest()
if self.session:
request.session = self.session
else:
request.session = engine.SessionStore()
login(request, user)
# Save the session values.
request.session.save()
# Set the cookie to represent the session.
session_cookie = settings.SESSION_COOKIE_NAME
self.cookies[session_cookie] = request.session.session_key
cookie_data = {
'max-age': None,
'path': '/',
'domain': settings.SESSION_COOKIE_DOMAIN,
'secure': settings.SESSION_COOKIE_SECURE or None,
'expires': None,
}
self.cookies[session_cookie].update(cookie_data)
return True
else:
return False
def logout(self):
"""
Removes the authenticated user's cookies and session object.
Causes the authenticated user to be logged out.
"""
session = import_module(settings.SESSION_ENGINE).SessionStore()
session_cookie = self.cookies.get(settings.SESSION_COOKIE_NAME)
if session_cookie:
session.delete(session_key=session_cookie.value)
self.cookies = SimpleCookie()
def _handle_redirects(self, response, **extra):
"Follows any redirects by requesting responses from the server using GET."
response.redirect_chain = []
while response.status_code in (301, 302, 303, 307):
url = response['Location']
scheme, netloc, path, query, fragment = urlsplit(url)
redirect_chain = response.redirect_chain
redirect_chain.append((url, response.status_code))
if scheme:
extra['wsgi.url_scheme'] = scheme
# The test client doesn't handle external links,
# but since the situation is simulated in test_client,
# we fake things here by ignoring the netloc portion of the
# redirected URL.
response = self.get(path, QueryDict(query), follow=False, **extra)
response.redirect_chain = redirect_chain
# Prevent loops
if response.redirect_chain[-1] in response.redirect_chain[0:-1]:
break
return response
|
bsd-3-clause
|
[
646,
4011,
199,
504,
7097,
492,
7097,
12,
30111,
12,
29596,
199,
646,
984,
199,
646,
747,
199,
646,
295,
199,
646,
13290,
199,
646,
3598,
199,
893,
26,
272,
687,
15073,
492,
5228,
199,
2590,
3545,
26,
272,
687,
5228,
492,
5228,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
492,
12895,
12,
4676,
199,
504,
1639,
14,
1018,
14,
5586,
14,
1095,
492,
3523,
2461,
199,
504,
1639,
14,
1018,
14,
5586,
14,
6508,
492,
9279,
2017,
199,
504,
1639,
14,
1018,
14,
10458,
492,
4788,
63,
1069,
63,
1971,
199,
504,
1639,
14,
1014,
492,
5870,
7810,
12,
20730,
12,
8133,
2141,
199,
504,
1639,
14,
1160,
492,
27193,
199,
504,
1639,
14,
396,
492,
10166,
199,
504,
1639,
14,
1208,
14,
15481,
492,
1094,
651,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
495,
199,
504,
1639,
14,
1208,
14,
1014,
492,
16511,
199,
504,
1639,
14,
1208,
14,
25893,
492,
492,
63,
578,
199,
504,
1639,
14,
1208,
14,
1661,
5819,
492,
365,
63,
8147,
199,
504,
1639,
14,
697,
492,
6008,
12,
4002,
63,
2105,
199,
504,
1639,
14,
396,
14,
1208,
492,
9470,
1296,
199,
199,
363,
452,
363,
275,
661,
3041,
297,
283,
2017,
2927,
297,
283,
2143,
63,
493,
297,
283,
2143,
63,
10123,
358,
421,
199,
21489,
275,
283,
2208,
1358,
25014,
50,
89,
933,
28522,
46,
71,
7,
199,
21894,
2294,
63,
9663,
275,
283,
10123,
15,
964,
13,
576,
27,
8424,
2458,
83,
7,
450,
4367,
6131,
4392,
199,
9663,
63,
2711,
63,
907,
275,
295,
14,
2014,
360,
2795,
27,
5960,
29,
16510,
87,
60,
68,
20253,
2736,
18478,
199,
199,
533,
7777,
17215,
8,
785,
304,
272,
408,
272,
437,
4975,
6818,
5228,
626,
7213,
3021,
4052,
883,
506,
1586,
3967,
666,
687,
272,
314,
2784,
883,
1133,
506,
12005,
379,
436,
3913,
506,
1586,
9682,
402,
2399,
1564,
272,
2582,
14,
961,
7704,
3238,
626,
6858,
883,
1133,
886,
7003,
1334,
314,
511,
1890,
272,
626,
3955,
78,
1133,
1736,
315,
14849,
491,
16839,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1564,
304,
267,
291,
855,
1317,
275,
5228,
8,
1317,
9,
267,
291,
855,
552,
275,
822,
8,
1317,
9,
339,
347,
1586,
8,
277,
12,
1967,
63,
2394,
29,
403,
304,
267,
340,
1967,
63,
2394,
365,
488,
26,
288,
1967,
63,
2394,
275,
291,
855,
552,
503,
413,
267,
702,
291,
855,
552,
2356,
1967,
63,
2394,
12,
298,
6612,
1586,
1655,
2419,
314,
2808,
2783,
687,
314,
3101,
12467,
666,
2122,
267,
1564,
275,
291,
855,
1317,
14,
739,
8,
1507,
63,
2394,
9,
267,
291,
855,
552,
4862,
1967,
63,
2394,
267,
372,
1564,
421,
199,
533,
6810,
2461,
8,
1563,
2461,
304,
272,
408,
272,
437,
3101,
18599,
626,
883,
506,
1202,
367,
5343,
12901,
14,
272,
14911,
314,
9279,
3217,
370,
23366,
4145,
12,
1325,
2529,
272,
314,
3066,
6183,
909,
272,
408,
272,
347,
636,
826,
721,
277,
12,
15814,
63,
10088,
63,
8625,
29,
549,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
19817,
63,
10088,
63,
8625,
275,
15814,
63,
10088,
63,
8625,
267,
1613,
8,
3041,
2461,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
636,
1250,
721,
277,
12,
6160,
304,
267,
687,
1639,
14,
2190,
492,
2202,
267,
687,
1639,
14,
1018,
492,
10166,
398,
327,
2494,
1536,
10816,
340,
4346,
14,
2136,
21554,
1133,
886,
642,
14119,
12,
2952,
267,
327,
2202,
781,
828,
1133,
2808,
14,
267,
340,
291,
423,
1069,
63,
5754,
365,
488,
26,
288,
291,
14,
912,
63,
5754,
342,
398,
10166,
14,
1069,
63,
8924,
14,
2254,
8,
8114,
29,
277,
855,
533,
3368,
267,
862,
26,
288,
1056,
275,
9279,
2017,
8,
2314,
9,
288,
327,
308,
685,
1151,
89,
12050,
11176,
880,
626,
781,
883,
16174,
664,
6168,
288,
327,
22145,
25322,
14,
221,
961,
7704,
15451,
14905,
12,
436,
365,
8646,
288,
327,
1415,
367,
8552,
7163,
543,
5957,
2295,
6169,
288,
327,
4628,
6858,
14,
288,
1056,
423,
18671,
63,
19817,
63,
10088,
63,
8625,
275,
440,
291,
14,
19817,
63,
10088,
63,
8625,
288,
1177,
275,
291,
14,
362,
63,
1310,
8,
1069,
9,
267,
3753,
26,
288,
10166,
14,
1069,
63,
8669,
14,
10673,
8,
1600,
63,
2105,
9,
288,
10166,
14,
1069,
63,
8669,
14,
2254,
8,
8114,
29,
277,
855,
533,
3368,
288,
10166,
14,
1069,
63,
8669,
14,
2242,
8,
1600,
63,
2105,
9,
398,
372,
1177,
199,
199,
318,
3877,
63,
16841,
63,
5876,
8,
1617,
12,
4673,
12,
8904,
12,
1978,
12,
1067,
12,
1011,
958,
304,
272,
408,
272,
31299,
7009,
436,
18191,
626,
787,
8018,
14,
272,
408,
272,
3877,
14,
5486,
360,
5876,
297,
15364,
740,
8,
1160,
9,
272,
3877,
14,
5486,
360,
1100,
297,
9470,
1296,
8801,
740,
8,
1100,
9,
199,
199,
318,
3752,
63,
10123,
8,
9891,
12,
666,
304,
272,
408,
272,
3447,
6021,
15193,
8761,
666,
687,
282,
2600,
402,
1824,
1338,
14,
339,
710,
790,
911,
506,
1202,
465,
314,
1824,
666,
536,
27,
314,
574,
911,
506,
29818,
272,
465,
1564,
14,
982,
314,
574,
365,
282,
570,
12,
314,
4072,
402,
314,
570,
911,
506,
4847,
272,
465,
376,
4223,
15,
18162,
13,
1745,
27,
4257,
12,
620,
8,
585,
9,
911,
506,
4847,
14,
272,
408,
272,
2385,
275,
942,
272,
370,
63,
495,
275,
2400,
308,
26,
11179,
63,
495,
8,
83,
12,
2202,
14,
3472,
63,
23969,
9,
339,
327,
2832,
701,
1263,
4910,
23668,
12,
1325,
6954,
8321,
367,
4154,
12901,
14,
272,
365,
63,
493,
275,
2400,
8377,
26,
2688,
8,
2127,
12,
298,
739,
531,
436,
4550,
8,
2127,
14,
739,
9,
339,
327,
7048,
4546,
402,
314,
15193,
1824,
666,
4293,
506,
1902,
282,
1824,
574,
503,
282,
272,
327,
570,
12,
503,
282,
627,
513,
10,
402,
1824,
1338,
436,
15,
269,
1584,
14,
31859,
626,
3101,
901,
272,
327,
1561,
883,
506,
21747,
1,
272,
367,
334,
498,
12,
574,
9,
315,
666,
14,
1744,
837,
267,
340,
365,
63
] |
[
4011,
199,
504,
7097,
492,
7097,
12,
30111,
12,
29596,
199,
646,
984,
199,
646,
747,
199,
646,
295,
199,
646,
13290,
199,
646,
3598,
199,
893,
26,
272,
687,
15073,
492,
5228,
199,
2590,
3545,
26,
272,
687,
5228,
492,
5228,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
492,
12895,
12,
4676,
199,
504,
1639,
14,
1018,
14,
5586,
14,
1095,
492,
3523,
2461,
199,
504,
1639,
14,
1018,
14,
5586,
14,
6508,
492,
9279,
2017,
199,
504,
1639,
14,
1018,
14,
10458,
492,
4788,
63,
1069,
63,
1971,
199,
504,
1639,
14,
1014,
492,
5870,
7810,
12,
20730,
12,
8133,
2141,
199,
504,
1639,
14,
1160,
492,
27193,
199,
504,
1639,
14,
396,
492,
10166,
199,
504,
1639,
14,
1208,
14,
15481,
492,
1094,
651,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
495,
199,
504,
1639,
14,
1208,
14,
1014,
492,
16511,
199,
504,
1639,
14,
1208,
14,
25893,
492,
492,
63,
578,
199,
504,
1639,
14,
1208,
14,
1661,
5819,
492,
365,
63,
8147,
199,
504,
1639,
14,
697,
492,
6008,
12,
4002,
63,
2105,
199,
504,
1639,
14,
396,
14,
1208,
492,
9470,
1296,
199,
199,
363,
452,
363,
275,
661,
3041,
297,
283,
2017,
2927,
297,
283,
2143,
63,
493,
297,
283,
2143,
63,
10123,
358,
421,
199,
21489,
275,
283,
2208,
1358,
25014,
50,
89,
933,
28522,
46,
71,
7,
199,
21894,
2294,
63,
9663,
275,
283,
10123,
15,
964,
13,
576,
27,
8424,
2458,
83,
7,
450,
4367,
6131,
4392,
199,
9663,
63,
2711,
63,
907,
275,
295,
14,
2014,
360,
2795,
27,
5960,
29,
16510,
87,
60,
68,
20253,
2736,
18478,
199,
199,
533,
7777,
17215,
8,
785,
304,
272,
408,
272,
437,
4975,
6818,
5228,
626,
7213,
3021,
4052,
883,
506,
1586,
3967,
666,
687,
272,
314,
2784,
883,
1133,
506,
12005,
379,
436,
3913,
506,
1586,
9682,
402,
2399,
1564,
272,
2582,
14,
961,
7704,
3238,
626,
6858,
883,
1133,
886,
7003,
1334,
314,
511,
1890,
272,
626,
3955,
78,
1133,
1736,
315,
14849,
491,
16839,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1564,
304,
267,
291,
855,
1317,
275,
5228,
8,
1317,
9,
267,
291,
855,
552,
275,
822,
8,
1317,
9,
339,
347,
1586,
8,
277,
12,
1967,
63,
2394,
29,
403,
304,
267,
340,
1967,
63,
2394,
365,
488,
26,
288,
1967,
63,
2394,
275,
291,
855,
552,
503,
413,
267,
702,
291,
855,
552,
2356,
1967,
63,
2394,
12,
298,
6612,
1586,
1655,
2419,
314,
2808,
2783,
687,
314,
3101,
12467,
666,
2122,
267,
1564,
275,
291,
855,
1317,
14,
739,
8,
1507,
63,
2394,
9,
267,
291,
855,
552,
4862,
1967,
63,
2394,
267,
372,
1564,
421,
199,
533,
6810,
2461,
8,
1563,
2461,
304,
272,
408,
272,
437,
3101,
18599,
626,
883,
506,
1202,
367,
5343,
12901,
14,
272,
14911,
314,
9279,
3217,
370,
23366,
4145,
12,
1325,
2529,
272,
314,
3066,
6183,
909,
272,
408,
272,
347,
636,
826,
721,
277,
12,
15814,
63,
10088,
63,
8625,
29,
549,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
19817,
63,
10088,
63,
8625,
275,
15814,
63,
10088,
63,
8625,
267,
1613,
8,
3041,
2461,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
636,
1250,
721,
277,
12,
6160,
304,
267,
687,
1639,
14,
2190,
492,
2202,
267,
687,
1639,
14,
1018,
492,
10166,
398,
327,
2494,
1536,
10816,
340,
4346,
14,
2136,
21554,
1133,
886,
642,
14119,
12,
2952,
267,
327,
2202,
781,
828,
1133,
2808,
14,
267,
340,
291,
423,
1069,
63,
5754,
365,
488,
26,
288,
291,
14,
912,
63,
5754,
342,
398,
10166,
14,
1069,
63,
8924,
14,
2254,
8,
8114,
29,
277,
855,
533,
3368,
267,
862,
26,
288,
1056,
275,
9279,
2017,
8,
2314,
9,
288,
327,
308,
685,
1151,
89,
12050,
11176,
880,
626,
781,
883,
16174,
664,
6168,
288,
327,
22145,
25322,
14,
221,
961,
7704,
15451,
14905,
12,
436,
365,
8646,
288,
327,
1415,
367,
8552,
7163,
543,
5957,
2295,
6169,
288,
327,
4628,
6858,
14,
288,
1056,
423,
18671,
63,
19817,
63,
10088,
63,
8625,
275,
440,
291,
14,
19817,
63,
10088,
63,
8625,
288,
1177,
275,
291,
14,
362,
63,
1310,
8,
1069,
9,
267,
3753,
26,
288,
10166,
14,
1069,
63,
8669,
14,
10673,
8,
1600,
63,
2105,
9,
288,
10166,
14,
1069,
63,
8669,
14,
2254,
8,
8114,
29,
277,
855,
533,
3368,
288,
10166,
14,
1069,
63,
8669,
14,
2242,
8,
1600,
63,
2105,
9,
398,
372,
1177,
199,
199,
318,
3877,
63,
16841,
63,
5876,
8,
1617,
12,
4673,
12,
8904,
12,
1978,
12,
1067,
12,
1011,
958,
304,
272,
408,
272,
31299,
7009,
436,
18191,
626,
787,
8018,
14,
272,
408,
272,
3877,
14,
5486,
360,
5876,
297,
15364,
740,
8,
1160,
9,
272,
3877,
14,
5486,
360,
1100,
297,
9470,
1296,
8801,
740,
8,
1100,
9,
199,
199,
318,
3752,
63,
10123,
8,
9891,
12,
666,
304,
272,
408,
272,
3447,
6021,
15193,
8761,
666,
687,
282,
2600,
402,
1824,
1338,
14,
339,
710,
790,
911,
506,
1202,
465,
314,
1824,
666,
536,
27,
314,
574,
911,
506,
29818,
272,
465,
1564,
14,
982,
314,
574,
365,
282,
570,
12,
314,
4072,
402,
314,
570,
911,
506,
4847,
272,
465,
376,
4223,
15,
18162,
13,
1745,
27,
4257,
12,
620,
8,
585,
9,
911,
506,
4847,
14,
272,
408,
272,
2385,
275,
942,
272,
370,
63,
495,
275,
2400,
308,
26,
11179,
63,
495,
8,
83,
12,
2202,
14,
3472,
63,
23969,
9,
339,
327,
2832,
701,
1263,
4910,
23668,
12,
1325,
6954,
8321,
367,
4154,
12901,
14,
272,
365,
63,
493,
275,
2400,
8377,
26,
2688,
8,
2127,
12,
298,
739,
531,
436,
4550,
8,
2127,
14,
739,
9,
339,
327,
7048,
4546,
402,
314,
15193,
1824,
666,
4293,
506,
1902,
282,
1824,
574,
503,
282,
272,
327,
570,
12,
503,
282,
627,
513,
10,
402,
1824,
1338,
436,
15,
269,
1584,
14,
31859,
626,
3101,
901,
272,
327,
1561,
883,
506,
21747,
1,
272,
367,
334,
498,
12,
574,
9,
315,
666,
14,
1744,
837,
267,
340,
365,
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,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
OmarIthawi/edx-platform
|
common/djangoapps/course_groups/views.py
|
9
|
8261
|
from django_future.csrf import ensure_csrf_cookie
from django.views.decorators.http import require_POST
from django.contrib.auth.models import User
from django.core.paginator import Paginator, EmptyPage
from django.core.urlresolvers import reverse
from django.http import Http404, HttpResponse, HttpResponseBadRequest
import json
import logging
import re
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from courseware.courses import get_course_with_access
from edxmako.shortcuts import render_to_response
from . import cohorts
from .models import CourseUserGroup
log = logging.getLogger(__name__)
def json_http_response(data):
"""
Return an HttpResponse with the data json-serialized and the right content
type header.
"""
return HttpResponse(json.dumps(data), content_type="application/json")
def split_by_comma_and_whitespace(cstr):
"""
Split a string both by commas and whitespice. Returns a list.
"""
return re.split(r'[\s,]+', cstr)
@ensure_csrf_cookie
def list_cohorts(request, course_key_string):
"""
Return json dump of dict:
{'success': True,
'cohorts': [{'name': name, 'id': id}, ...]}
"""
# this is a string when we get it here
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_key_string)
course = get_course_with_access(request.user, 'staff', course_key)
all_cohorts = [
{
'name': c.name,
'id': c.id,
'user_count': c.users.count(),
'assignment_type': cohorts.CohortAssignmentType.get(c, course)
}
for c in cohorts.get_course_cohorts(course)
]
return json_http_response({'success': True,
'cohorts': all_cohorts})
@ensure_csrf_cookie
@require_POST
def add_cohort(request, course_key_string):
"""
Return json of dict:
{'success': True,
'cohort': {'id': id,
'name': name}}
or
{'success': False,
'msg': error_msg} if there's an error
"""
# this is a string when we get it here
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_key_string)
get_course_with_access(request.user, 'staff', course_key)
name = request.POST.get("name")
if not name:
return json_http_response({'success': False,
'msg': "No name specified"})
try:
cohort = cohorts.add_cohort(course_key, name)
except ValueError as err:
return json_http_response({'success': False,
'msg': str(err)})
return json_http_response({
'success': 'True',
'cohort': {
'id': cohort.id,
'name': cohort.name
}
})
@ensure_csrf_cookie
def users_in_cohort(request, course_key_string, cohort_id):
"""
Return users in the cohort. Show up to 100 per page, and page
using the 'page' GET attribute in the call. Format:
Returns:
Json dump of dictionary in the following format:
{'success': True,
'page': page,
'num_pages': paginator.num_pages,
'users': [{'username': ..., 'email': ..., 'name': ...}]
}
"""
# this is a string when we get it here
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_key_string)
get_course_with_access(request.user, 'staff', course_key)
# this will error if called with a non-int cohort_id. That's ok--it
# shoudn't happen for valid clients.
cohort = cohorts.get_cohort_by_id(course_key, int(cohort_id))
paginator = Paginator(cohort.users.all(), 100)
try:
page = int(request.GET.get('page'))
except (TypeError, ValueError):
# These strings aren't user-facing so don't translate them
return HttpResponseBadRequest('Requested page must be numeric')
else:
if page < 0:
return HttpResponseBadRequest('Requested page must be greater than zero')
try:
users = paginator.page(page)
except EmptyPage:
users = [] # When page > number of pages, return a blank page
user_info = [{'username': u.username,
'email': u.email,
'name': '{0} {1}'.format(u.first_name, u.last_name)}
for u in users]
return json_http_response({'success': True,
'page': page,
'num_pages': paginator.num_pages,
'users': user_info})
@ensure_csrf_cookie
@require_POST
def add_users_to_cohort(request, course_key_string, cohort_id):
"""
Return json dict of:
{'success': True,
'added': [{'username': ...,
'name': ...,
'email': ...}, ...],
'changed': [{'username': ...,
'name': ...,
'email': ...,
'previous_cohort': ...}, ...],
'present': [str1, str2, ...], # already there
'unknown': [str1, str2, ...]}
Raises Http404 if the cohort cannot be found for the given course.
"""
# this is a string when we get it here
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_key_string)
get_course_with_access(request.user, 'staff', course_key)
try:
cohort = cohorts.get_cohort_by_id(course_key, cohort_id)
except CourseUserGroup.DoesNotExist:
raise Http404("Cohort (ID {cohort_id}) not found for {course_key_string}".format(
cohort_id=cohort_id,
course_key_string=course_key_string
))
users = request.POST.get('users', '')
added = []
changed = []
present = []
unknown = []
for username_or_email in split_by_comma_and_whitespace(users):
if not username_or_email:
continue
try:
(user, previous_cohort) = cohorts.add_user_to_cohort(cohort, username_or_email)
info = {
'username': user.username,
'name': user.profile.name,
'email': user.email,
}
if previous_cohort:
info['previous_cohort'] = previous_cohort
changed.append(info)
else:
added.append(info)
except ValueError:
present.append(username_or_email)
except User.DoesNotExist:
unknown.append(username_or_email)
return json_http_response({'success': True,
'added': added,
'changed': changed,
'present': present,
'unknown': unknown})
@ensure_csrf_cookie
@require_POST
def remove_user_from_cohort(request, course_key_string, cohort_id):
"""
Expects 'username': username in POST data.
Return json dict of:
{'success': True} or
{'success': False,
'msg': error_msg}
"""
# this is a string when we get it here
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_key_string)
get_course_with_access(request.user, 'staff', course_key)
username = request.POST.get('username')
if username is None:
return json_http_response({'success': False,
'msg': 'No username specified'})
cohort = cohorts.get_cohort_by_id(course_key, cohort_id)
try:
user = User.objects.get(username=username)
cohort.users.remove(user)
return json_http_response({'success': True})
except User.DoesNotExist:
log.debug('no user')
return json_http_response({'success': False,
'msg': "No user '{0}'".format(username)})
def debug_cohort_mgmt(request, course_key_string):
"""
Debugging view for dev.
"""
# this is a string when we get it here
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_key_string)
# add staff check to make sure it's safe if it's accidentally deployed.
get_course_with_access(request.user, 'staff', course_key)
context = {'cohorts_ajax_url': reverse(
'cohorts',
kwargs={'course_key': course_key.to_deprecated_string()}
)}
return render_to_response('/course_groups/debug.html', context)
|
agpl-3.0
|
[
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,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
1018,
14,
22073,
492,
28006,
8566,
12,
9630,
3276,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
12,
6183,
12,
6183,
12380,
199,
646,
2022,
199,
646,
2050,
199,
646,
295,
199,
199,
504,
15058,
63,
1612,
14,
8268,
14,
8022,
492,
30687,
199,
504,
20736,
14,
11653,
492,
664,
63,
1972,
63,
1045,
63,
2732,
199,
504,
22435,
19491,
14,
17469,
492,
3795,
63,
475,
63,
1310,
199,
199,
504,
1275,
492,
15690,
83,
199,
504,
1275,
992,
492,
5531,
1899,
2448,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
2022,
63,
1014,
63,
1310,
8,
576,
304,
272,
408,
272,
1432,
376,
6183,
543,
314,
666,
2022,
13,
8397,
436,
314,
2451,
1564,
272,
730,
1406,
14,
272,
408,
272,
372,
6183,
8,
1001,
14,
4180,
8,
576,
395,
1564,
63,
466,
628,
3578,
15,
1001,
531,
421,
199,
318,
3715,
63,
991,
63,
13184,
63,
460,
63,
8506,
8,
67,
495,
304,
272,
408,
272,
11740,
282,
1059,
3865,
701,
24476,
436,
10424,
681,
1885,
14,
221,
1803,
282,
769,
14,
272,
408,
272,
372,
295,
14,
1294,
8,
82,
22123,
83,
12,
11529,
286,
495,
9,
421,
199,
32,
7505,
63,
10088,
63,
5306,
199,
318,
769,
63,
10403,
83,
8,
1069,
12,
2518,
63,
498,
63,
875,
304,
272,
408,
272,
1432,
2022,
5461,
402,
1211,
26,
339,
791,
3742,
356,
715,
12,
1362,
283,
10403,
83,
356,
9016,
354,
356,
536,
12,
283,
344,
356,
1305,
1386,
2263,
9420,
272,
408,
339,
327,
642,
365,
282,
1059,
1380,
781,
664,
652,
2348,
272,
2518,
63,
498,
275,
30687,
14,
504,
63,
6667,
63,
875,
8,
1972,
63,
498,
63,
875,
9,
339,
2518,
275,
664,
63,
1972,
63,
1045,
63,
2732,
8,
1069,
14,
751,
12,
283,
7018,
297,
2518,
63,
498,
9,
339,
1006,
63,
10403,
83,
275,
359,
267,
469,
288,
283,
354,
356,
286,
14,
354,
12,
288,
283,
344,
356,
286,
14,
344,
12,
288,
283,
751,
63,
835,
356,
286,
14,
3707,
14,
835,
1062,
288,
283,
10861,
63,
466,
356,
15690,
83,
14,
32512,
19321,
804,
14,
362,
8,
67,
12,
2518,
9,
267,
789,
267,
367,
286,
315,
15690,
83,
14,
362,
63,
1972,
63,
10403,
83,
8,
1972,
9,
272,
1622,
339,
372,
2022,
63,
1014,
63,
1310,
3252,
3742,
356,
715,
12,
3044,
283,
10403,
83,
356,
1006,
63,
10403,
83,
1552,
421,
199,
32,
7505,
63,
10088,
63,
5306,
199,
32,
4365,
63,
4030,
199,
318,
1050,
63,
10403,
8,
1069,
12,
2518,
63,
498,
63,
875,
304,
272,
408,
272,
1432,
2022,
402,
1211,
26,
272,
791,
3742,
356,
715,
12,
1362,
283,
10403,
356,
791,
344,
356,
1305,
12,
355,
283,
354,
356,
536,
4863,
2234,
503,
339,
791,
3742,
356,
756,
12,
1362,
283,
1328,
356,
1125,
63,
1328,
93,
340,
2337,
1159,
376,
1125,
272,
408,
272,
327,
642,
365,
282,
1059,
1380,
781,
664,
652,
2348,
272,
2518,
63,
498,
275,
30687,
14,
504,
63,
6667,
63,
875,
8,
1972,
63,
498,
63,
875,
9,
339,
664,
63,
1972,
63,
1045,
63,
2732,
8,
1069,
14,
751,
12,
283,
7018,
297,
2518,
63,
498,
9,
339,
536,
275,
1056,
14,
4030,
14,
362,
480,
354,
531,
272,
340,
440,
536,
26,
267,
372,
2022,
63,
1014,
63,
1310,
3252,
3742,
356,
756,
12,
3521,
283,
1328,
356,
298,
1944,
536,
2013,
5984,
339,
862,
26,
267,
15690,
275,
15690,
83,
14,
525,
63,
10403,
8,
1972,
63,
498,
12,
536,
9,
272,
871,
1722,
465,
2329,
26,
267,
372,
2022,
63,
1014,
63,
1310,
3252,
3742,
356,
756,
12,
3521,
283,
1328,
356,
620,
8,
1508,
11466,
339,
372,
2022,
63,
1014,
63,
1310,
2561,
267,
283,
3742,
356,
283,
549,
297,
267,
283,
10403,
356,
469,
288,
283,
344,
356,
15690,
14,
344,
12,
288,
283,
354,
356,
15690,
14,
354,
267,
789,
272,
3828,
421,
199,
32,
7505,
63,
10088,
63,
5306,
199,
318,
4390,
63,
262,
63,
10403,
8,
1069,
12,
2518,
63,
498,
63,
875,
12,
15690,
63,
344,
304,
272,
408,
272,
1432,
4390,
315,
314,
15690,
14,
221,
12968,
1536,
370,
2948,
1126,
2034,
12,
436,
2034,
272,
1808,
314,
283,
1606,
7,
9576,
2225,
315,
314,
1240,
14,
221,
9701,
26,
339,
1803,
26,
267,
14587,
5461,
402,
2600,
315,
314,
2569,
1475,
26,
267,
791,
3742,
356,
715,
12,
268,
283,
1606,
356,
2034,
12,
268,
283,
1507,
63,
5856,
356,
21398,
14,
1507,
63,
5856,
12,
268,
283,
3707,
356,
9016,
2473,
356,
14263,
283,
2123,
356,
14263,
283,
354,
356,
2263,
11049,
272,
789,
272,
408,
272,
327,
642,
365,
282,
1059,
1380,
781,
664,
652,
2348,
272,
2518,
63,
498,
275,
30687,
14,
504,
63,
6667,
63,
875,
8,
1972,
63,
498,
63,
875,
9,
339,
664,
63,
1972,
63,
1045,
63,
2732,
8,
1069,
14,
751,
12,
283,
7018,
297,
2518,
63,
498,
9,
339,
327,
642,
911,
1125,
340,
2797,
543,
282,
2222,
13,
442,
15690,
63,
344,
14,
221,
10314,
1159,
4112,
306,
390,
272,
327,
930,
1181,
78,
1133,
5992,
367,
1686,
13431,
14,
272,
15690,
275,
15690,
83,
14,
362,
63,
10403,
63,
991,
63,
344,
8,
1972,
63,
498,
12,
1109,
8,
10403,
63,
344,
430,
339,
21398,
275,
28006,
8566,
8,
10403,
14,
3707,
14,
452,
1062,
2948,
9,
272,
862,
26,
267,
2034,
275,
1109,
8,
1069,
14,
2970,
14,
362,
360,
1606,
1333,
272,
871,
334,
4333,
12,
1722,
304,
267,
327,
5723,
3326,
10621,
1133,
922,
13,
32552,
880,
2793,
1133,
9028,
3062,
267,
372,
6183,
12380,
360,
17935,
2034,
1471,
506,
8950,
358,
272,
587,
26,
267,
340,
2034,
665,
378,
26,
288,
372,
6183,
12380,
360,
17935,
2034,
1471,
506,
8932,
2419,
4697,
358,
339,
862,
26,
267,
4390,
275,
21398,
14,
1606,
8,
1606,
9
] |
[
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,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
1018,
14,
22073,
492,
28006,
8566,
12,
9630,
3276,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
12,
6183,
12,
6183,
12380,
199,
646,
2022,
199,
646,
2050,
199,
646,
295,
199,
199,
504,
15058,
63,
1612,
14,
8268,
14,
8022,
492,
30687,
199,
504,
20736,
14,
11653,
492,
664,
63,
1972,
63,
1045,
63,
2732,
199,
504,
22435,
19491,
14,
17469,
492,
3795,
63,
475,
63,
1310,
199,
199,
504,
1275,
492,
15690,
83,
199,
504,
1275,
992,
492,
5531,
1899,
2448,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
2022,
63,
1014,
63,
1310,
8,
576,
304,
272,
408,
272,
1432,
376,
6183,
543,
314,
666,
2022,
13,
8397,
436,
314,
2451,
1564,
272,
730,
1406,
14,
272,
408,
272,
372,
6183,
8,
1001,
14,
4180,
8,
576,
395,
1564,
63,
466,
628,
3578,
15,
1001,
531,
421,
199,
318,
3715,
63,
991,
63,
13184,
63,
460,
63,
8506,
8,
67,
495,
304,
272,
408,
272,
11740,
282,
1059,
3865,
701,
24476,
436,
10424,
681,
1885,
14,
221,
1803,
282,
769,
14,
272,
408,
272,
372,
295,
14,
1294,
8,
82,
22123,
83,
12,
11529,
286,
495,
9,
421,
199,
32,
7505,
63,
10088,
63,
5306,
199,
318,
769,
63,
10403,
83,
8,
1069,
12,
2518,
63,
498,
63,
875,
304,
272,
408,
272,
1432,
2022,
5461,
402,
1211,
26,
339,
791,
3742,
356,
715,
12,
1362,
283,
10403,
83,
356,
9016,
354,
356,
536,
12,
283,
344,
356,
1305,
1386,
2263,
9420,
272,
408,
339,
327,
642,
365,
282,
1059,
1380,
781,
664,
652,
2348,
272,
2518,
63,
498,
275,
30687,
14,
504,
63,
6667,
63,
875,
8,
1972,
63,
498,
63,
875,
9,
339,
2518,
275,
664,
63,
1972,
63,
1045,
63,
2732,
8,
1069,
14,
751,
12,
283,
7018,
297,
2518,
63,
498,
9,
339,
1006,
63,
10403,
83,
275,
359,
267,
469,
288,
283,
354,
356,
286,
14,
354,
12,
288,
283,
344,
356,
286,
14,
344,
12,
288,
283,
751,
63,
835,
356,
286,
14,
3707,
14,
835,
1062,
288,
283,
10861,
63,
466,
356,
15690,
83,
14,
32512,
19321,
804,
14,
362,
8,
67,
12,
2518,
9,
267,
789,
267,
367,
286,
315,
15690,
83,
14,
362,
63,
1972,
63,
10403,
83,
8,
1972,
9,
272,
1622,
339,
372,
2022,
63,
1014,
63,
1310,
3252,
3742,
356,
715,
12,
3044,
283,
10403,
83,
356,
1006,
63,
10403,
83,
1552,
421,
199,
32,
7505,
63,
10088,
63,
5306,
199,
32,
4365,
63,
4030,
199,
318,
1050,
63,
10403,
8,
1069,
12,
2518,
63,
498,
63,
875,
304,
272,
408,
272,
1432,
2022,
402,
1211,
26,
272,
791,
3742,
356,
715,
12,
1362,
283,
10403,
356,
791,
344,
356,
1305,
12,
355,
283,
354,
356,
536,
4863,
2234,
503,
339,
791,
3742,
356,
756,
12,
1362,
283,
1328,
356,
1125,
63,
1328,
93,
340,
2337,
1159,
376,
1125,
272,
408,
272,
327,
642,
365,
282,
1059,
1380,
781,
664,
652,
2348,
272,
2518,
63,
498,
275,
30687,
14,
504,
63,
6667,
63,
875,
8,
1972,
63,
498,
63,
875,
9,
339,
664,
63,
1972,
63,
1045,
63,
2732,
8,
1069,
14,
751,
12,
283,
7018,
297,
2518,
63,
498,
9,
339,
536,
275,
1056,
14,
4030,
14,
362,
480,
354,
531,
272,
340,
440,
536,
26,
267,
372,
2022,
63,
1014,
63,
1310,
3252,
3742,
356,
756,
12,
3521,
283,
1328,
356,
298,
1944,
536,
2013,
5984,
339,
862,
26,
267,
15690,
275,
15690,
83,
14,
525,
63,
10403,
8,
1972,
63,
498,
12,
536,
9,
272,
871,
1722,
465,
2329,
26,
267,
372,
2022,
63,
1014,
63,
1310,
3252,
3742,
356,
756,
12,
3521,
283,
1328,
356,
620,
8,
1508,
11466,
339,
372,
2022,
63,
1014,
63,
1310,
2561,
267,
283,
3742,
356,
283,
549,
297,
267,
283,
10403,
356,
469,
288,
283,
344,
356,
15690,
14,
344,
12,
288,
283,
354,
356,
15690,
14,
354,
267,
789,
272,
3828,
421,
199,
32,
7505,
63,
10088,
63,
5306,
199,
318,
4390,
63,
262,
63,
10403,
8,
1069,
12,
2518,
63,
498,
63,
875,
12,
15690,
63,
344,
304,
272,
408,
272,
1432,
4390,
315,
314,
15690,
14,
221,
12968,
1536,
370,
2948,
1126,
2034,
12,
436,
2034,
272,
1808,
314,
283,
1606,
7,
9576,
2225,
315,
314,
1240,
14,
221,
9701,
26,
339,
1803,
26,
267,
14587,
5461,
402,
2600,
315,
314,
2569,
1475,
26,
267,
791,
3742,
356,
715,
12,
268,
283,
1606,
356,
2034,
12,
268,
283,
1507,
63,
5856,
356,
21398,
14,
1507,
63,
5856,
12,
268,
283,
3707,
356,
9016,
2473,
356,
14263,
283,
2123,
356,
14263,
283,
354,
356,
2263,
11049,
272,
789,
272,
408,
272,
327,
642,
365,
282,
1059,
1380,
781,
664,
652,
2348,
272,
2518,
63,
498,
275,
30687,
14,
504,
63,
6667,
63,
875,
8,
1972,
63,
498,
63,
875,
9,
339,
664,
63,
1972,
63,
1045,
63,
2732,
8,
1069,
14,
751,
12,
283,
7018,
297,
2518,
63,
498,
9,
339,
327,
642,
911,
1125,
340,
2797,
543,
282,
2222,
13,
442,
15690,
63,
344,
14,
221,
10314,
1159,
4112,
306,
390,
272,
327,
930,
1181,
78,
1133,
5992,
367,
1686,
13431,
14,
272,
15690,
275,
15690,
83,
14,
362,
63,
10403,
63,
991,
63,
344,
8,
1972,
63,
498,
12,
1109,
8,
10403,
63,
344,
430,
339,
21398,
275,
28006,
8566,
8,
10403,
14,
3707,
14,
452,
1062,
2948,
9,
272,
862,
26,
267,
2034,
275,
1109,
8,
1069,
14,
2970,
14,
362,
360,
1606,
1333,
272,
871,
334,
4333,
12,
1722,
304,
267,
327,
5723,
3326,
10621,
1133,
922,
13,
32552,
880,
2793,
1133,
9028,
3062,
267,
372,
6183,
12380,
360,
17935,
2034,
1471,
506,
8950,
358,
272,
587,
26,
267,
340,
2034,
665,
378,
26,
288,
372,
6183,
12380,
360,
17935,
2034,
1471,
506,
8932,
2419,
4697,
358,
339,
862,
26,
267,
4390,
275,
21398,
14,
1606,
8,
1606,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1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/ansible_collections/vyos/vyos/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py
|
47
|
4433
|
#
# -*- coding: utf-8 -*-
# Copyright 2019 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
"""
The vyos interfaces fact class
It is in this file the configuration is collected from the device
for a given resource, parsed, and the facts tree is populated
based on the configuration.
"""
from __future__ import absolute_import, division, print_function
__metaclass__ = type
from re import findall, M
from copy import deepcopy
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
utils,
)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.interfaces.interfaces import (
InterfacesArgs,
)
class InterfacesFacts(object):
""" The vyos interfaces fact class
"""
def __init__(self, module, subspec="config", options="options"):
self._module = module
self.argument_spec = InterfacesArgs.argument_spec
spec = deepcopy(self.argument_spec)
if subspec:
if options:
facts_argument_spec = spec[subspec][options]
else:
facts_argument_spec = spec[subspec]
else:
facts_argument_spec = spec
self.generated_spec = utils.generate_dict(facts_argument_spec)
def populate_facts(self, connection, ansible_facts, data=None):
""" Populate the facts for interfaces
:param connection: the device connection
:param ansible_facts: Facts dictionary
:param data: previously collected conf
:rtype: dictionary
:returns: facts
"""
if not data:
data = connection.get_config(flags=["| grep interfaces"])
objs = []
interface_names = findall(
r"^set interfaces (?:ethernet|bonding|vti|loopback|vxlan) (?:\'*)(\S+)(?:\'*)",
data,
M,
)
if interface_names:
for interface in set(interface_names):
intf_regex = r" %s .+$" % interface.strip("'")
cfg = findall(intf_regex, data, M)
obj = self.render_config(cfg)
obj["name"] = interface.strip("'")
if obj:
objs.append(obj)
facts = {}
if objs:
facts["interfaces"] = []
params = utils.validate_config(
self.argument_spec, {"config": objs}
)
for cfg in params["config"]:
facts["interfaces"].append(utils.remove_empties(cfg))
ansible_facts["ansible_network_resources"].update(facts)
return ansible_facts
def render_config(self, conf):
"""
Render config as dictionary structure and delete keys
from spec for null values
:param spec: The facts tree, generated from the argspec
:param conf: The configuration
:rtype: dictionary
:returns: The generated config
"""
vif_conf = "\n".join(filter(lambda x: ("vif" in x), conf))
eth_conf = "\n".join(filter(lambda x: ("vif" not in x), conf))
config = self.parse_attribs(
["description", "speed", "mtu", "duplex"], eth_conf
)
config["vifs"] = self.parse_vifs(vif_conf)
return utils.remove_empties(config)
def parse_vifs(self, conf):
vif_names = findall(r"vif (?:\'*)(\d+)(?:\'*)", conf, M)
vifs_list = None
if vif_names:
vifs_list = []
for vif in set(vif_names):
vif_regex = r" %s .+$" % vif
cfg = "\n".join(findall(vif_regex, conf, M))
obj = self.parse_attribs(["description", "mtu"], cfg)
obj["vlan_id"] = int(vif)
if obj:
vifs_list.append(obj)
vifs_list = sorted(vifs_list, key=lambda i: i["vlan_id"])
return vifs_list
def parse_attribs(self, attribs, conf):
config = {}
for item in attribs:
value = utils.parse_conf_arg(conf, item)
if value and item == "mtu":
config[item] = int(value.strip("'"))
elif value:
config[item] = value.strip("'")
else:
config[item] = None
if "disable" in conf:
config["enabled"] = False
else:
config["enabled"] = True
return utils.remove_empties(config)
|
gpl-3.0
|
[
3,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
20312,
9572,
13002,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
199,
3,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
624,
199,
1918,
31766,
736,
8386,
10572,
1021,
199,
7940,
365,
315,
642,
570,
314,
2897,
365,
13736,
687,
314,
2243,
199,
509,
282,
1627,
2073,
12,
4565,
12,
436,
314,
9036,
3123,
365,
16460,
199,
6788,
641,
314,
2897,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
363,
6577,
363,
275,
730,
421,
199,
504,
295,
492,
2342,
452,
12,
603,
199,
504,
1331,
492,
14800,
199,
504,
3242,
63,
7882,
14,
4853,
14,
846,
2330,
14,
5265,
14,
578,
63,
1208,
14,
1200,
14,
2330,
492,
334,
272,
3778,
12,
199,
9,
199,
504,
3242,
63,
7882,
14,
16091,
736,
14,
16091,
736,
14,
5265,
14,
578,
63,
1208,
14,
1200,
14,
16091,
736,
14,
15644,
14,
7436,
14,
7436,
492,
334,
272,
6551,
4309,
6213,
12,
199,
9,
421,
199,
533,
6551,
4309,
25821,
8,
785,
304,
272,
408,
710,
31766,
736,
8386,
10572,
1021,
272,
408,
339,
347,
636,
826,
721,
277,
12,
859,
12,
1007,
1650,
628,
888,
401,
1511,
628,
1419,
2349,
267,
291,
423,
578,
275,
859,
267,
291,
14,
2094,
63,
1650,
275,
6551,
4309,
6213,
14,
2094,
63,
1650,
267,
3158,
275,
14800,
8,
277,
14,
2094,
63,
1650,
9,
267,
340,
1007,
1650,
26,
288,
340,
1511,
26,
355,
9036,
63,
2094,
63,
1650,
275,
3158,
59,
954,
1650,
1527,
1419,
61,
288,
587,
26,
355,
9036,
63,
2094,
63,
1650,
275,
3158,
59,
954,
1650,
61,
267,
587,
26,
288,
9036,
63,
2094,
63,
1650,
275,
3158,
398,
291,
14,
10176,
63,
1650,
275,
3778,
14,
4208,
63,
807,
8,
5047,
63,
2094,
63,
1650,
9,
339,
347,
13904,
63,
5047,
8,
277,
12,
1950,
12,
3242,
63,
5047,
12,
666,
29,
403,
304,
267,
408,
31731,
314,
9036,
367,
8386,
267,
520,
635,
1950,
26,
314,
2243,
1950,
267,
520,
635,
3242,
63,
5047,
26,
481,
22282,
2600,
267,
520,
635,
666,
26,
10889,
13736,
3743,
267,
520,
4500,
26,
2600,
267,
520,
5808,
26,
9036,
267,
408,
267,
340,
440,
666,
26,
288,
666,
275,
1950,
14,
362,
63,
888,
8,
2469,
6270,
92,
20595,
8386,
3135,
398,
13474,
275,
942,
267,
3217,
63,
1247,
275,
2342,
452,
8,
288,
519,
16136,
409,
8386,
16697,
20354,
92,
13520,
1098,
92,
86,
280,
92,
23983,
92,
18843,
1502,
9,
7558,
3427,
16804,
10127,
51,
8771,
15840,
16804,
4186,
288,
666,
12,
288,
603,
12,
267,
776,
267,
340,
3217,
63,
1247,
26,
288,
367,
3217,
315,
663,
8,
3266,
63,
1247,
304,
355,
20697,
63,
3821,
275,
519,
2,
450,
83,
1275,
11,
17351,
450,
3217,
14,
1913,
480,
9859,
355,
4810,
275,
2342,
452,
8,
21100,
63,
3821,
12,
666,
12,
603,
9,
355,
1559,
275,
291,
14,
3352,
63,
888,
8,
4128,
9,
355,
1559,
905,
354,
937,
275,
3217,
14,
1913,
480,
9859,
355,
340,
1559,
26,
490,
13474,
14,
740,
8,
1113,
9,
267,
9036,
275,
1052,
267,
340,
13474,
26,
288,
9036,
905,
7436,
937,
275,
942,
288,
1862,
275,
3778,
14,
3502,
63,
888,
8,
355,
291,
14,
2094,
63,
1650,
12,
2420,
888,
582,
13474,
93,
288,
776,
288,
367,
4810,
315,
1862,
905,
888,
6229,
355,
9036,
905,
7436,
4140,
740,
8,
1208,
14,
2168,
63,
2109,
1417,
8,
4128,
430,
398,
3242,
63,
5047,
905,
4853,
63,
1200,
63,
4435,
4140,
873,
8,
5047,
9,
267,
372,
3242,
63,
5047,
339,
347,
3795,
63,
888,
8,
277,
12,
3743,
304,
267,
408,
267,
17769,
1101,
465,
2600,
5523,
436,
3145,
2883,
881,
687,
3158,
367,
2973,
1338,
398,
520,
635,
3158,
26,
710,
9036,
3123,
12,
4046,
687,
314,
26632,
267,
520,
635,
3743,
26,
710,
2897,
267,
520,
4500,
26,
2600,
267,
520,
5808,
26,
710,
4046,
1101,
267,
408,
267,
15205,
63,
2190,
275,
1867,
78,
1674,
904,
8,
1541,
8,
2734,
671,
26,
1689,
14430,
2,
315,
671,
395,
3743,
430,
267,
16227,
63,
2190,
275,
1867,
78,
1674,
904,
8,
1541,
8,
2734,
671,
26,
1689,
14430,
2,
440,
315,
671,
395,
3743,
430,
267,
1101,
275,
291,
14,
1122,
63,
30674,
8,
288,
2097,
1802,
401,
298,
7625,
401,
298,
17696,
401,
298,
68,
26646,
2255,
16227,
63,
2190,
267,
776,
267,
1101,
905,
433,
2319,
937,
275,
291,
14,
1122,
63,
433,
2319,
8,
14430,
63,
2190,
9,
398,
372,
3778,
14,
2168,
63,
2109,
1417,
8,
888,
9,
339,
347,
2198,
63,
433,
2319,
8,
277,
12,
3743,
304,
267,
15205,
63,
1247,
275,
2342,
452,
8,
82,
2,
14430,
7558,
3427,
16804,
10127,
68,
8771,
15840,
16804,
4186,
3743,
12,
603,
9,
267,
15205,
83,
63,
513,
275,
488,
398,
340,
15205,
63,
1247,
26,
288,
15205,
83,
63,
513,
275,
942,
288,
367,
15205,
315,
663,
8,
14430,
63,
1247,
304,
355,
15205,
63,
3821,
275,
519,
2,
450,
83,
1275,
11,
17351,
450,
15205,
355,
4810,
275,
1867,
78,
1674,
904,
8,
6452,
8,
14430,
63,
3821,
12,
3743,
12,
603,
430,
355,
1559,
275,
291,
14,
1122,
63,
30674,
5234,
1802,
401,
298,
17696,
2255,
4810,
9,
355,
1559,
905,
7175,
63,
344,
937,
275,
1109,
8,
14430,
9,
355,
340,
1559,
26,
490,
15205,
83,
63,
513,
14,
740,
8,
1113,
9,
288,
15205,
83,
63,
513,
275,
3355,
8,
433,
2319,
63,
513,
12,
790,
29,
2734,
284,
26,
284,
905,
7175,
63,
344,
3135,
398,
372,
15205,
83,
63,
513,
339,
347,
2198,
63,
30674,
8,
277,
12,
737,
19577,
12,
3743,
304,
267,
1101,
275,
1052,
267,
367,
1242,
315,
737,
19577,
26,
288,
574,
275,
3778,
14,
1122,
63,
2190,
63,
1273,
8,
2190,
12,
1242,
9,
288,
340,
574,
436,
1242,
508,
298,
17696,
582,
355,
1101,
59,
1053,
61,
275,
1109,
8,
585,
14,
1913,
15587,
2237,
288,
916,
574
] |
[
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
20312,
9572,
13002,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
199,
3,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
624,
199,
1918,
31766,
736,
8386,
10572,
1021,
199,
7940,
365,
315,
642,
570,
314,
2897,
365,
13736,
687,
314,
2243,
199,
509,
282,
1627,
2073,
12,
4565,
12,
436,
314,
9036,
3123,
365,
16460,
199,
6788,
641,
314,
2897,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
363,
6577,
363,
275,
730,
421,
199,
504,
295,
492,
2342,
452,
12,
603,
199,
504,
1331,
492,
14800,
199,
504,
3242,
63,
7882,
14,
4853,
14,
846,
2330,
14,
5265,
14,
578,
63,
1208,
14,
1200,
14,
2330,
492,
334,
272,
3778,
12,
199,
9,
199,
504,
3242,
63,
7882,
14,
16091,
736,
14,
16091,
736,
14,
5265,
14,
578,
63,
1208,
14,
1200,
14,
16091,
736,
14,
15644,
14,
7436,
14,
7436,
492,
334,
272,
6551,
4309,
6213,
12,
199,
9,
421,
199,
533,
6551,
4309,
25821,
8,
785,
304,
272,
408,
710,
31766,
736,
8386,
10572,
1021,
272,
408,
339,
347,
636,
826,
721,
277,
12,
859,
12,
1007,
1650,
628,
888,
401,
1511,
628,
1419,
2349,
267,
291,
423,
578,
275,
859,
267,
291,
14,
2094,
63,
1650,
275,
6551,
4309,
6213,
14,
2094,
63,
1650,
267,
3158,
275,
14800,
8,
277,
14,
2094,
63,
1650,
9,
267,
340,
1007,
1650,
26,
288,
340,
1511,
26,
355,
9036,
63,
2094,
63,
1650,
275,
3158,
59,
954,
1650,
1527,
1419,
61,
288,
587,
26,
355,
9036,
63,
2094,
63,
1650,
275,
3158,
59,
954,
1650,
61,
267,
587,
26,
288,
9036,
63,
2094,
63,
1650,
275,
3158,
398,
291,
14,
10176,
63,
1650,
275,
3778,
14,
4208,
63,
807,
8,
5047,
63,
2094,
63,
1650,
9,
339,
347,
13904,
63,
5047,
8,
277,
12,
1950,
12,
3242,
63,
5047,
12,
666,
29,
403,
304,
267,
408,
31731,
314,
9036,
367,
8386,
267,
520,
635,
1950,
26,
314,
2243,
1950,
267,
520,
635,
3242,
63,
5047,
26,
481,
22282,
2600,
267,
520,
635,
666,
26,
10889,
13736,
3743,
267,
520,
4500,
26,
2600,
267,
520,
5808,
26,
9036,
267,
408,
267,
340,
440,
666,
26,
288,
666,
275,
1950,
14,
362,
63,
888,
8,
2469,
6270,
92,
20595,
8386,
3135,
398,
13474,
275,
942,
267,
3217,
63,
1247,
275,
2342,
452,
8,
288,
519,
16136,
409,
8386,
16697,
20354,
92,
13520,
1098,
92,
86,
280,
92,
23983,
92,
18843,
1502,
9,
7558,
3427,
16804,
10127,
51,
8771,
15840,
16804,
4186,
288,
666,
12,
288,
603,
12,
267,
776,
267,
340,
3217,
63,
1247,
26,
288,
367,
3217,
315,
663,
8,
3266,
63,
1247,
304,
355,
20697,
63,
3821,
275,
519,
2,
450,
83,
1275,
11,
17351,
450,
3217,
14,
1913,
480,
9859,
355,
4810,
275,
2342,
452,
8,
21100,
63,
3821,
12,
666,
12,
603,
9,
355,
1559,
275,
291,
14,
3352,
63,
888,
8,
4128,
9,
355,
1559,
905,
354,
937,
275,
3217,
14,
1913,
480,
9859,
355,
340,
1559,
26,
490,
13474,
14,
740,
8,
1113,
9,
267,
9036,
275,
1052,
267,
340,
13474,
26,
288,
9036,
905,
7436,
937,
275,
942,
288,
1862,
275,
3778,
14,
3502,
63,
888,
8,
355,
291,
14,
2094,
63,
1650,
12,
2420,
888,
582,
13474,
93,
288,
776,
288,
367,
4810,
315,
1862,
905,
888,
6229,
355,
9036,
905,
7436,
4140,
740,
8,
1208,
14,
2168,
63,
2109,
1417,
8,
4128,
430,
398,
3242,
63,
5047,
905,
4853,
63,
1200,
63,
4435,
4140,
873,
8,
5047,
9,
267,
372,
3242,
63,
5047,
339,
347,
3795,
63,
888,
8,
277,
12,
3743,
304,
267,
408,
267,
17769,
1101,
465,
2600,
5523,
436,
3145,
2883,
881,
687,
3158,
367,
2973,
1338,
398,
520,
635,
3158,
26,
710,
9036,
3123,
12,
4046,
687,
314,
26632,
267,
520,
635,
3743,
26,
710,
2897,
267,
520,
4500,
26,
2600,
267,
520,
5808,
26,
710,
4046,
1101,
267,
408,
267,
15205,
63,
2190,
275,
1867,
78,
1674,
904,
8,
1541,
8,
2734,
671,
26,
1689,
14430,
2,
315,
671,
395,
3743,
430,
267,
16227,
63,
2190,
275,
1867,
78,
1674,
904,
8,
1541,
8,
2734,
671,
26,
1689,
14430,
2,
440,
315,
671,
395,
3743,
430,
267,
1101,
275,
291,
14,
1122,
63,
30674,
8,
288,
2097,
1802,
401,
298,
7625,
401,
298,
17696,
401,
298,
68,
26646,
2255,
16227,
63,
2190,
267,
776,
267,
1101,
905,
433,
2319,
937,
275,
291,
14,
1122,
63,
433,
2319,
8,
14430,
63,
2190,
9,
398,
372,
3778,
14,
2168,
63,
2109,
1417,
8,
888,
9,
339,
347,
2198,
63,
433,
2319,
8,
277,
12,
3743,
304,
267,
15205,
63,
1247,
275,
2342,
452,
8,
82,
2,
14430,
7558,
3427,
16804,
10127,
68,
8771,
15840,
16804,
4186,
3743,
12,
603,
9,
267,
15205,
83,
63,
513,
275,
488,
398,
340,
15205,
63,
1247,
26,
288,
15205,
83,
63,
513,
275,
942,
288,
367,
15205,
315,
663,
8,
14430,
63,
1247,
304,
355,
15205,
63,
3821,
275,
519,
2,
450,
83,
1275,
11,
17351,
450,
15205,
355,
4810,
275,
1867,
78,
1674,
904,
8,
6452,
8,
14430,
63,
3821,
12,
3743,
12,
603,
430,
355,
1559,
275,
291,
14,
1122,
63,
30674,
5234,
1802,
401,
298,
17696,
2255,
4810,
9,
355,
1559,
905,
7175,
63,
344,
937,
275,
1109,
8,
14430,
9,
355,
340,
1559,
26,
490,
15205,
83,
63,
513,
14,
740,
8,
1113,
9,
288,
15205,
83,
63,
513,
275,
3355,
8,
433,
2319,
63,
513,
12,
790,
29,
2734,
284,
26,
284,
905,
7175,
63,
344,
3135,
398,
372,
15205,
83,
63,
513,
339,
347,
2198,
63,
30674,
8,
277,
12,
737,
19577,
12,
3743,
304,
267,
1101,
275,
1052,
267,
367,
1242,
315,
737,
19577,
26,
288,
574,
275,
3778,
14,
1122,
63,
2190,
63,
1273,
8,
2190,
12,
1242,
9,
288,
340,
574,
436,
1242,
508,
298,
17696,
582,
355,
1101,
59,
1053,
61,
275,
1109,
8,
585,
14,
1913,
15587,
2237,
288,
916,
574,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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